diff --git a/app/Helpers/Invoice/InvoiceItemSum.php b/app/Helpers/Invoice/InvoiceItemSum.php index 4a8348b8c9..829555a44a 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -11,10 +11,15 @@ namespace App\Helpers\Invoice; +use App\Models\Quote; use App\Models\Client; +use App\Models\Credit; use App\Models\Invoice; +use App\Models\PurchaseOrder; +use App\Models\RecurringQuote; use App\DataMapper\InvoiceItem; use App\DataMapper\BaseSettings; +use App\Models\RecurringInvoice; use App\DataMapper\Tax\RuleInterface; use App\Utils\Traits\NumberFormatter; use App\DataMapper\Tax\ZipTax\Response; @@ -59,7 +64,7 @@ class InvoiceItemSum 'AU', // Australia ]; - protected $invoice; + protected RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder | RecurringQuote $invoice; private $items; @@ -91,7 +96,7 @@ class InvoiceItemSum private RuleInterface $rule; - public function __construct($invoice) + public function __construct( RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder | RecurringQuote $invoice) { $this->tax_collection = collect([]); @@ -136,7 +141,7 @@ class InvoiceItemSum private function shouldCalculateTax(): self { - if (!$this->invoice->company?->calculate_taxes) { + if (!$this->invoice->company->calculate_taxes) { $this->calc_tax = false; return $this; } diff --git a/app/Helpers/Invoice/InvoiceSum.php b/app/Helpers/Invoice/InvoiceSum.php index 5097fac0c2..a56e52478f 100644 --- a/app/Helpers/Invoice/InvoiceSum.php +++ b/app/Helpers/Invoice/InvoiceSum.php @@ -55,7 +55,7 @@ class InvoiceSum /** * Constructs the object with Invoice and Settings object. * - * @param \App\Models\RecurringInvoice|\App\Models\Quote|\App\Models\Credit|\App\Models\PurchaseOrder|\App\Models\Invoice $invoice The entity + * @param RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder | RecurringQuote $invoice; */ public function __construct($invoice) { diff --git a/app/Helpers/Invoice/InvoiceSumInclusive.php b/app/Helpers/Invoice/InvoiceSumInclusive.php index 2222d1b113..ceb470d824 100644 --- a/app/Helpers/Invoice/InvoiceSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceSumInclusive.php @@ -11,9 +11,15 @@ namespace App\Helpers\Invoice; +use App\Models\Quote; +use App\Models\Credit; use App\Models\Invoice; -use App\Utils\Traits\NumberFormatter; +use App\Models\PurchaseOrder; +use App\Models\RecurringQuote; +use App\Models\RecurringInvoice; use Illuminate\Support\Collection; +use App\Utils\Traits\NumberFormatter; +use App\Helpers\Invoice\InvoiceItemSumInclusive; class InvoiceSumInclusive { @@ -22,7 +28,7 @@ class InvoiceSumInclusive use Discounter; use NumberFormatter; - protected $invoice; + protected RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder | RecurringQuote $invoice; public $tax_map; @@ -46,7 +52,7 @@ class InvoiceSumInclusive /** * Constructs the object with Invoice and Settings object. * - * @param \App\Models\RecurringInvoice|\App\Models\Quote|\App\Models\Credit|\App\Models\PurchaseOrder|\App\Models\Invoice $invoice The entity + * @param RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder | RecurringQuote $invoice; */ public function __construct($invoice) { diff --git a/app/Models/RecurringInvoice.php b/app/Models/RecurringInvoice.php index 5fef186621..1f17368d9e 100644 --- a/app/Models/RecurringInvoice.php +++ b/app/Models/RecurringInvoice.php @@ -35,30 +35,30 @@ use Laracasts\Presenter\PresentableTrait; * @property int $status_id * @property string|null $number * @property float $discount - * @property int $is_amount_discount + * @property bool $is_amount_discount * @property string|null $po_number * @property string|null $date * @property string|null $due_date - * @property int $is_deleted - * @property object|null $line_items + * @property bool $is_deleted + * @property array|null $line_items * @property object|null $backup * @property string|null $footer * @property string|null $public_notes * @property string|null $private_notes * @property string|null $terms * @property string|null $tax_name1 - * @property string $tax_rate1 + * @property float $tax_rate1 * @property string|null $tax_name2 - * @property string $tax_rate2 + * @property float $tax_rate2 * @property string|null $tax_name3 - * @property string $tax_rate3 - * @property string $total_taxes + * @property float $tax_rate3 + * @property float $total_taxes * @property string|null $custom_value1 * @property string|null $custom_value2 * @property string|null $custom_value3 * @property string|null $custom_value4 - * @property string $amount - * @property string $balance + * @property float $amount + * @property float $balance * @property float|null $partial * @property string|null $last_viewed * @property int $frequency_id @@ -69,17 +69,17 @@ use Laracasts\Presenter\PresentableTrait; * @property int|null $updated_at * @property int|null $deleted_at * @property string $auto_bill - * @property int $auto_bill_enabled + * @property bool $auto_bill_enabled * @property int|null $design_id - * @property int $uses_inclusive_taxes + * @property bool $uses_inclusive_taxes * @property string|null $custom_surcharge1 * @property string|null $custom_surcharge2 * @property string|null $custom_surcharge3 * @property string|null $custom_surcharge4 - * @property int $custom_surcharge_tax1 - * @property int $custom_surcharge_tax2 - * @property int $custom_surcharge_tax3 - * @property int $custom_surcharge_tax4 + * @property bool $custom_surcharge_tax1 + * @property bool $custom_surcharge_tax2 + * @property bool $custom_surcharge_tax3 + * @property bool $custom_surcharge_tax4 * @property string|null $due_date_days * @property string|null $partial_due_date * @property string $exchange_rate @@ -609,22 +609,17 @@ class RecurringInvoice extends BaseModel switch ($status) { case self::STATUS_DRAFT: return '

'.ctrans('texts.draft').'

'; - break; case self::STATUS_PENDING: return '

'.ctrans('texts.pending').'

'; - break; case self::STATUS_ACTIVE: return '

'.ctrans('texts.active').'

'; - break; case self::STATUS_COMPLETED: return '

'.ctrans('texts.status_completed').'

'; - break; case self::STATUS_PAUSED: return '

'.ctrans('texts.paused').'

'; - break; default: - // code... - break; + return '

'.ctrans('texts.pending').'

'; + } } @@ -633,22 +628,17 @@ class RecurringInvoice extends BaseModel switch ($status) { case self::STATUS_DRAFT: return ctrans('texts.draft'); - break; case self::STATUS_PENDING: return ctrans('texts.pending'); - break; case self::STATUS_ACTIVE: return ctrans('texts.active'); - break; case self::STATUS_COMPLETED: return ctrans('texts.status_completed'); - break; case self::STATUS_PAUSED: return ctrans('texts.paused'); - break; default: - // code... - break; + return ctrans('texts.pending'); + } } @@ -657,43 +647,30 @@ class RecurringInvoice extends BaseModel switch ($frequency_id) { case self::FREQUENCY_DAILY: return ctrans('texts.freq_daily'); - break; case self::FREQUENCY_WEEKLY: return ctrans('texts.freq_weekly'); - break; case self::FREQUENCY_TWO_WEEKS: return ctrans('texts.freq_two_weeks'); - break; case self::FREQUENCY_FOUR_WEEKS: return ctrans('texts.freq_four_weeks'); - break; case self::FREQUENCY_MONTHLY: return ctrans('texts.freq_monthly'); - break; case self::FREQUENCY_TWO_MONTHS: return ctrans('texts.freq_two_months'); - break; case self::FREQUENCY_THREE_MONTHS: return ctrans('texts.freq_three_months'); - break; case self::FREQUENCY_FOUR_MONTHS: return ctrans('texts.freq_four_months'); - break; case self::FREQUENCY_SIX_MONTHS: return ctrans('texts.freq_six_months'); - break; case self::FREQUENCY_ANNUALLY: return ctrans('texts.freq_annually'); - break; case self::FREQUENCY_TWO_YEARS: return ctrans('texts.freq_two_years'); - break; case self::FREQUENCY_THREE_YEARS: return ctrans('texts.freq_three_years'); - break; default: return ''; - break; } } @@ -774,15 +751,12 @@ class RecurringInvoice extends BaseModel case '': case '0': return $this->calculateDateFromTerms($date); - break; case 'on_receipt': return Carbon::parse($date)->copy(); - break; default: return $this->setDayOfMonth($date, $this->due_date_days); - break; } } diff --git a/app/Models/RecurringQuote.php b/app/Models/RecurringQuote.php index 2ed560f202..76d90a1da7 100644 --- a/app/Models/RecurringQuote.php +++ b/app/Models/RecurringQuote.php @@ -543,22 +543,16 @@ class RecurringQuote extends BaseModel switch ($status) { case self::STATUS_DRAFT: return '

'.ctrans('texts.draft').'

'; - break; case self::STATUS_PENDING: return '

'.ctrans('texts.pending').'

'; - break; case self::STATUS_ACTIVE: return '

'.ctrans('texts.active').'

'; - break; case self::STATUS_COMPLETED: return '

'.ctrans('texts.status_completed').'

'; - break; case self::STATUS_PAUSED: return '

'.ctrans('texts.paused').'

'; - break; default: - // code... - break; + return '

'.ctrans('texts.pending').'

'; } } @@ -567,55 +561,43 @@ class RecurringQuote extends BaseModel switch ($frequency_id) { case self::FREQUENCY_DAILY: return ctrans('texts.freq_daily'); - break; case self::FREQUENCY_WEEKLY: return ctrans('texts.freq_weekly'); - break; case self::FREQUENCY_TWO_WEEKS: return ctrans('texts.freq_two_weeks'); - break; case self::FREQUENCY_FOUR_WEEKS: return ctrans('texts.freq_four_weeks'); - break; case self::FREQUENCY_MONTHLY: return ctrans('texts.freq_monthly'); - break; case self::FREQUENCY_TWO_MONTHS: return ctrans('texts.freq_two_months'); - break; case self::FREQUENCY_THREE_MONTHS: return ctrans('texts.freq_three_months'); - break; case self::FREQUENCY_FOUR_MONTHS: return ctrans('texts.freq_four_months'); - break; case self::FREQUENCY_SIX_MONTHS: return ctrans('texts.freq_six_months'); - break; case self::FREQUENCY_ANNUALLY: return ctrans('texts.freq_annually'); - break; case self::FREQUENCY_TWO_YEARS: return ctrans('texts.freq_two_years'); - break; default: - // code... - break; + return ctrans('texts.freq_weekly'); + } } /** * Access the invoice calculator object. - * * @return InvoiceSumInclusive | InvoiceSum The invoice calculator object getters */ public function calc(): InvoiceSumInclusive | InvoiceSum { $invoice_calc = null; - if ($this->uses_inclusive_taxes) { + if ($this->uses_inclusive_taxes) { $invoice_calc = new InvoiceSumInclusive($this); - } else { + } else { $invoice_calc = new InvoiceSum($this); } @@ -679,10 +661,8 @@ class RecurringQuote extends BaseModel switch ($this->due_date_days) { case 'terms': return $this->calculateDateFromTerms($date); - break; default: return $this->setDayOfMonth($date, $this->due_date_days); - break; } } @@ -707,6 +687,7 @@ class RecurringQuote extends BaseModel /** * Service entry points. + * @return RecurringService */ public function service() :RecurringService { diff --git a/app/Services/Recurring/RecurringService.php b/app/Services/Recurring/RecurringService.php index e9c81b870d..c962b5f45f 100644 --- a/app/Services/Recurring/RecurringService.php +++ b/app/Services/Recurring/RecurringService.php @@ -11,15 +11,16 @@ namespace App\Services\Recurring; -use App\Jobs\RecurringInvoice\SendRecurring; use App\Jobs\Util\UnlinkFile; +use App\Models\RecurringQuote; +use Illuminate\Support\Carbon; use App\Models\RecurringExpense; use App\Models\RecurringInvoice; -use Illuminate\Support\Carbon; +use App\Jobs\RecurringInvoice\SendRecurring; class RecurringService { - public function __construct(public RecurringInvoice | RecurringExpense $recurring_entity) + public function __construct(public RecurringInvoice | RecurringExpense | RecurringQuote $recurring_entity) { } diff --git a/tests/Feature/RecurringQuoteTest.php b/tests/Feature/RecurringQuoteTest.php index d795b5cf03..eabcd39741 100644 --- a/tests/Feature/RecurringQuoteTest.php +++ b/tests/Feature/RecurringQuoteTest.php @@ -30,6 +30,8 @@ class RecurringQuoteTest extends TestCase use DatabaseTransactions; use MockAccountData; + public $faker; + protected function setUp() :void { parent::setUp();