diff --git a/app/Factory/InvoiceFactory.php b/app/Factory/InvoiceFactory.php index 30a3c105e29e..c69ae41e794d 100644 --- a/app/Factory/InvoiceFactory.php +++ b/app/Factory/InvoiceFactory.php @@ -44,6 +44,7 @@ class InvoiceFactory $invoice->custom_value4 = 0; $invoice->amount = 0; $invoice->balance = 0; + $invoice->paid_to_date = 0; $invoice->partial = 0; $invoice->user_id = $user_id; $invoice->company_id = $company_id; diff --git a/app/Factory/InvoiceToRecurringInvoiceFactory.php b/app/Factory/InvoiceToRecurringInvoiceFactory.php index d63565980586..911740fada08 100644 --- a/app/Factory/InvoiceToRecurringInvoiceFactory.php +++ b/app/Factory/InvoiceToRecurringInvoiceFactory.php @@ -50,6 +50,7 @@ class InvoiceToRecurringInvoiceFactory $recurring_invoice->last_sent_date = null; $recurring_invoice->next_send_date = null; $recurring_invoice->remaining_cycles = 0; + $recurring_invoice->paid_to_date = 0; return $recurring_invoice; } diff --git a/app/Factory/QuoteFactory.php b/app/Factory/QuoteFactory.php index f220d022febc..6332ba3af816 100644 --- a/app/Factory/QuoteFactory.php +++ b/app/Factory/QuoteFactory.php @@ -45,6 +45,7 @@ class QuoteFactory $quote->partial = 0; $quote->user_id = $user_id; $quote->company_id = $company_id; + $quote->paid_to_date = 0; return $quote; } diff --git a/app/Factory/RecurringInvoiceFactory.php b/app/Factory/RecurringInvoiceFactory.php index 59399186f100..159fdce4da2a 100644 --- a/app/Factory/RecurringInvoiceFactory.php +++ b/app/Factory/RecurringInvoiceFactory.php @@ -49,6 +49,7 @@ class RecurringInvoiceFactory $invoice->last_sent_date = null; $invoice->next_send_date = null; $invoice->remaining_cycles = 0; + $invoice->paid_to_date = 0; return $invoice; } diff --git a/app/Factory/RecurringInvoiceToInvoiceFactory.php b/app/Factory/RecurringInvoiceToInvoiceFactory.php index 6bcc52add5b8..c16765f640b9 100644 --- a/app/Factory/RecurringInvoiceToInvoiceFactory.php +++ b/app/Factory/RecurringInvoiceToInvoiceFactory.php @@ -50,6 +50,7 @@ class RecurringInvoiceToInvoiceFactory $invoice->recurring_id = $recurring_invoice->id; $invoice->client_id = $client->id; $invoice->auto_bill_enabled = $recurring_invoice->auto_bill_enabled; + $invoice->paid_to_date = 0; return $invoice; } diff --git a/app/Http/Controllers/OpenAPI/CreditSchema.php b/app/Http/Controllers/OpenAPI/CreditSchema.php index 3917f7faa1dc..9b564145416b 100644 --- a/app/Http/Controllers/OpenAPI/CreditSchema.php +++ b/app/Http/Controllers/OpenAPI/CreditSchema.php @@ -30,6 +30,7 @@ * @OA\Property(property="line_items", type="object", example="", description="_________"), * @OA\Property(property="amount", type="number", format="float", example="10.00", description="_________"), * @OA\Property(property="balance", type="number", format="float", example="10.00", description="_________"), + * @OA\Property(property="paid_to_date", type="number", format="float", example="10.00", description="_________"), * @OA\Property(property="discount", type="number", format="float", example="10.00", description="_________"), * @OA\Property(property="partial", type="number", format="float", example="10.00", description="_________"), * @OA\Property(property="is_amount_discount", type="boolean", example=true, description="_________"), diff --git a/app/Http/Controllers/OpenAPI/InvoiceSchema.php b/app/Http/Controllers/OpenAPI/InvoiceSchema.php index 6eb2d0e21e35..e4eda9cd4e3e 100644 --- a/app/Http/Controllers/OpenAPI/InvoiceSchema.php +++ b/app/Http/Controllers/OpenAPI/InvoiceSchema.php @@ -29,6 +29,7 @@ * @OA\Property(property="line_items", type="object", example="", description="_________"), * @OA\Property(property="amount", type="number", format="float", example="10.00", description="_________"), * @OA\Property(property="balance", type="number", format="float", example="10.00", description="_________"), + * @OA\Property(property="paid_to_date", type="number", format="float", example="10.00", description="_________"), * @OA\Property(property="discount", type="number", format="float", example="10.00", description="_________"), * @OA\Property(property="partial", type="number", format="float", example="10.00", description="_________"), * @OA\Property(property="is_amount_discount", type="boolean", example=true, description="_________"), diff --git a/app/Http/Controllers/OpenAPI/QuoteSchema.php b/app/Http/Controllers/OpenAPI/QuoteSchema.php index 10118f74892d..45bf58a6ca8e 100644 --- a/app/Http/Controllers/OpenAPI/QuoteSchema.php +++ b/app/Http/Controllers/OpenAPI/QuoteSchema.php @@ -29,6 +29,7 @@ * @OA\Property(property="line_items", type="object", example="", description="_________"), * @OA\Property(property="amount", type="number", format="float", example="10.00", description="_________"), * @OA\Property(property="balance", type="number", format="float", example="10.00", description="_________"), + * @OA\Property(property="paid_to_date", type="number", format="float", example="10.00", description="_________"), * @OA\Property(property="discount", type="number", format="float", example="10.00", description="_________"), * @OA\Property(property="partial", type="number", format="float", example="10.00", description="_________"), * @OA\Property(property="is_amount_discount", type="boolean", example=true, description="_________"), diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 44fceff86533..49619d97755f 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -435,11 +435,6 @@ class PaymentController extends BaseController */ public function destroy(DestroyPaymentRequest $request, Payment $payment) { - // $payment->service()->deletePayment(); - - // $payment->is_deleted = true; - // $payment->save(); - // $payment->delete(); $this->payment_repo->delete($payment); diff --git a/app/Jobs/Credit/ApplyCreditPayment.php b/app/Jobs/Credit/ApplyCreditPayment.php index 4fa93c17b090..8f8f6b526a9c 100644 --- a/app/Jobs/Credit/ApplyCreditPayment.php +++ b/app/Jobs/Credit/ApplyCreditPayment.php @@ -57,17 +57,31 @@ class ApplyCreditPayment implements ShouldQueue if ($cred->id == $this->credit->id) { $cred->pivot->amount = $this->amount; $cred->pivot->save(); + + $cred->paid_to_date += $this->amount; + $cred->save(); } }); $credit_balance = $this->credit->balance; if ($this->amount == $credit_balance) { //total credit applied. - $this->credit->setStatus(Credit::STATUS_APPLIED); - $this->credit->updateBalance($this->amount * -1); + + $this->credit + ->service() + ->setStatus(Credit::STATUS_APPLIED) + ->updateBalance($this->amount * -1) + ->updatePaidToDate($this->amount) + ->save(); + } elseif ($this->amount < $credit_balance) { //compare number appropriately - $this->credit->setStatus(Credit::STATUS_PARTIAL); - $this->credit->updateBalance($this->amount * -1); + + $this->credit + ->service() + ->setStatus(Credit::STATUS_PARTIAL) + ->updateBalance($this->amount * -1) + ->updatePaidToDate($this->amount) + ->save(); } /* Update Payment Applied Amount*/ diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index b281ccd1fd2a..bc7efa865314 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -896,14 +896,6 @@ class Import implements ShouldQueue ], ]; - //depending on the status, we do a final action. - //s$payment = $this->updatePaymentForStatus($payment, $modified['status_id']); - - // if($modified['is_deleted']) - // $payment->service()->deletePayment(); - - // if(isset($modified['deleted_at'])) - // $payment->delete(); } Payment::reguard(); diff --git a/app/Listeners/Activity/CreditArchivedActivity.php b/app/Listeners/Activity/CreditArchivedActivity.php index c9e1cb18d35b..239082c81f39 100644 --- a/app/Listeners/Activity/CreditArchivedActivity.php +++ b/app/Listeners/Activity/CreditArchivedActivity.php @@ -49,6 +49,6 @@ class CreditArchivedActivity implements ShouldQueue $fields->company_id = $event->credit->company_id; $fields->activity_type_id = Activity::ARCHIVE_CREDIT; - $this->activity_repo->save($fields, $$event->credit, $event->event_vars); + $this->activity_repo->save($fields, $event->credit, $event->event_vars); } } diff --git a/app/Models/Credit.php b/app/Models/Credit.php index e30520c04c64..71a0c0085743 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -261,4 +261,5 @@ class Credit extends BaseModel } }); } + } diff --git a/app/Repositories/Migration/PaymentMigrationRepository.php b/app/Repositories/Migration/PaymentMigrationRepository.php index 0f51098ef9e3..8140b63fea6c 100644 --- a/app/Repositories/Migration/PaymentMigrationRepository.php +++ b/app/Repositories/Migration/PaymentMigrationRepository.php @@ -117,6 +117,10 @@ class PaymentMigrationRepository extends BaseRepository $inv->pivot->amount = $invoice_totals; $inv->pivot->refunded = $refund_totals; $inv->pivot->save(); + + $inv->paid_to_date += $invoice_totals; + $inv->save(); + }); } @@ -130,6 +134,9 @@ class PaymentMigrationRepository extends BaseRepository $payment->credits->each(function ($cre) use ($credit_totals) { $cre->pivot->amount = $credit_totals; $cre->pivot->save(); + + $cre->paid_to_date += $invoice_totals; + $cre->save(); }); } diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 25762ee7f5d4..1afea0c7b0a4 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -118,8 +118,6 @@ class PaymentRepository extends BaseRepository if (array_key_exists('invoices', $data) && is_array($data['invoices']) && count($data['invoices']) > 0) { $invoice_totals = array_sum(array_column($data['invoices'], 'amount')); -nlog("invoice totals = {$invoice_totals}"); - $invoices = Invoice::whereIn('id', array_column($data['invoices'], 'invoice_id'))->get(); $payment->invoices()->saveMany($invoices); diff --git a/app/Services/Client/PaymentMethod.php b/app/Services/Client/PaymentMethod.php index e4ea317bac89..27b3c3457723 100644 --- a/app/Services/Client/PaymentMethod.php +++ b/app/Services/Client/PaymentMethod.php @@ -209,7 +209,7 @@ class PaymentMethod $payment_urls = []; } - $payment_urls[] = [ + $this->payment_urls[] = [ 'label' => ctrans('texts.apply_credit'), 'company_gateway_id' => CompanyGateway::GATEWAY_CREDIT, 'gateway_type_id' => GatewayType::CREDIT, @@ -238,6 +238,5 @@ class PaymentMethod return true; } -} - +} \ No newline at end of file diff --git a/app/Services/Credit/ApplyPayment.php b/app/Services/Credit/ApplyPayment.php index a45a6e925365..6acbefdd583b 100644 --- a/app/Services/Credit/ApplyPayment.php +++ b/app/Services/Credit/ApplyPayment.php @@ -70,6 +70,7 @@ class ApplyPayment } $this->credit->balance -= $this->amount_applied; + $this->credit->paid_to_date += $this->amount_applied; if ((int)$this->credit->balance == 0) { $this->credit->status_id = Credit::STATUS_APPLIED; @@ -110,6 +111,8 @@ class ApplyPayment $this->payment->currency_id = $this->credit->client->getSetting('currency_id'); $this->payment->save(); + $this->payment->service()->applyNumber()->save(); + $this->payment ->invoices() ->attach($this->invoice->id, ['amount' => $this->amount_applied]); diff --git a/app/Services/Credit/CreditService.php b/app/Services/Credit/CreditService.php index a1739b825de4..94a511395ef4 100644 --- a/app/Services/Credit/CreditService.php +++ b/app/Services/Credit/CreditService.php @@ -97,6 +97,12 @@ class CreditService return $this; } + public function updatePaidToDate($adjustment) + { + $this->credit->paid_to_date += $adjustment; + + return $this; + } public function fillDefaults() { diff --git a/app/Services/Invoice/ApplyPayment.php b/app/Services/Invoice/ApplyPayment.php index 33d9e77b48f7..574c638dce5b 100644 --- a/app/Services/Invoice/ApplyPayment.php +++ b/app/Services/Invoice/ApplyPayment.php @@ -104,14 +104,24 @@ class ApplyPayment extends AbstractService ->ledger() ->updatePaymentBalance($amount_paid); - $this->invoice->client->service()->updateBalance($amount_paid)->save(); + $this->invoice + ->client + ->service() + ->updateBalance($amount_paid) + ->save(); /* Update Pivot Record amount */ $this->payment->invoices->each(function ($inv) use($amount_paid){ + if ($inv->id == $this->invoice->id) { + $inv->pivot->amount = ($amount_paid*-1); $inv->pivot->save(); + + $inv->paid_to_date += floatval($amount_paid*-1); + $inv->save(); } + }); $this->invoice->service()->applyNumber()->save(); diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index b588c688c37b..5c5185c6de01 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -59,9 +59,6 @@ class AutoBillInvoice extends AbstractService $this->applyCreditPayment(); } - // info("partial = {$this->invoice->partial}"); - // info("balance = {$this->invoice->balance}"); - /* Determine $amount */ if ($this->invoice->partial > 0) { $amount = $this->invoice->partial; @@ -122,18 +119,24 @@ class AutoBillInvoice extends AbstractService $payment->invoices()->attach($this->invoice->id, ['amount' => $amount]); - $this->invoice->service()->setStatus(Invoice::STATUS_PAID)->save(); + $this->invoice + ->service() + ->setStatus(Invoice::STATUS_PAID) + ->save(); foreach ($this->used_credit as $credit) { $current_credit = Credit::find($credit['credit_id']); - $payment->credits()->attach($current_credit->id, ['amount' => $credit['amount']]); + $payment->credits() + ->attach($current_credit->id, ['amount' => $credit['amount']]); info("adjusting credit balance {$current_credit->balance} by this amount ". $credit['amount']); - $current_credit->balance -= $credit['amount']; + $current_credit->service() + ->updateBalance($credit['amount']*-1) + ->updatePaidToDate($credit['amount']) + ->setCalculatedStatus() + ->save(); - $current_credit->service()->setCalculatedStatus()->save(); - // $this->applyPaymentToCredit($current_credit, $credit['amount']); } $payment->ledger() @@ -153,7 +156,10 @@ class AutoBillInvoice extends AbstractService event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); - return $this->invoice->service()->setCalculatedStatus()->save(); + return $this->invoice + ->service() + ->setCalculatedStatus() + ->save(); } /** @@ -194,6 +200,7 @@ class AutoBillInvoice extends AbstractService $this->used_credit[$key]['credit_id'] = $credit->id; $this->used_credit[$key]['amount'] = $this->invoice->partial; $this->invoice->balance -= $this->invoice->partial; + $this->invoice->paid_to_date += $this->invoice->partial; $this->invoice->partial = 0; break; } else { @@ -201,6 +208,7 @@ class AutoBillInvoice extends AbstractService $this->used_credit[$key]['amount'] = $credit->balance; $this->invoice->partial -= $credit->balance; $this->invoice->balance -= $credit->balance; + $this->invoice->paid_to_date += $credit->balance; } } else { @@ -208,12 +216,15 @@ class AutoBillInvoice extends AbstractService if ($credit->balance >= $this->invoice->balance) { $this->used_credit[$key]['credit_id'] = $credit->id; $this->used_credit[$key]['amount'] = $this->invoice->balance; + $this->invoice->paid_to_date += $this->invoice->balance; $this->invoice->balance = 0; + break; } else { $this->used_credit[$key]['credit_id'] = $credit->id; $this->used_credit[$key]['amount'] = $credit->balance; $this->invoice->balance -= $credit->balance; + $this->invoice->paid_to_date += $credit->balance; } } } diff --git a/app/Services/Invoice/HandleReversal.php b/app/Services/Invoice/HandleReversal.php index 66a8629537d0..169bafb68949 100644 --- a/app/Services/Invoice/HandleReversal.php +++ b/app/Services/Invoice/HandleReversal.php @@ -105,6 +105,9 @@ class HandleReversal extends AbstractService //harvest the credit record and add in the amount for the credit. $paymentable_credit->pivot->amount = $total_paid; $paymentable_credit->pivot->save(); + + $paymentable_credit->paid_to_date += $total_paid; + $paymentable_credit->save(); } /* Set invoice balance to 0 */ diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 5b14d4f8f3c6..543d034feab0 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -112,6 +112,13 @@ class InvoiceService return $this; } + public function updatePaidToDate($adjustment) + { + $this->invoice->paid_to_date += $adjustment; + + return $this; + } + public function createInvitations() { $this->invoice = (new CreateInvitations($this->invoice))->run(); diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 2800e673660d..285287b67ea5 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -70,6 +70,7 @@ class MarkPaid extends AbstractService $this->invoice->service() ->updateBalance($payment->amount * -1) + ->updatePaidToDate($payment->amount) ->setStatus(Invoice::STATUS_PAID) ->applyNumber() ->save(); diff --git a/app/Services/Invoice/UpdateBalance.php b/app/Services/Invoice/UpdateBalance.php index 049538cc85d0..4ae9408c4553 100644 --- a/app/Services/Invoice/UpdateBalance.php +++ b/app/Services/Invoice/UpdateBalance.php @@ -33,7 +33,7 @@ class UpdateBalance extends AbstractService } $this->invoice->balance += floatval($this->balance_adjustment); - + if ($this->invoice->balance == 0) { $this->invoice->status_id = Invoice::STATUS_PAID; } diff --git a/app/Services/Payment/DeletePayment.php b/app/Services/Payment/DeletePayment.php index 3169c51a5733..4c58a11b8c19 100644 --- a/app/Services/Payment/DeletePayment.php +++ b/app/Services/Payment/DeletePayment.php @@ -55,7 +55,6 @@ class DeletePayment private function cleanupPayment() { $this->payment->is_deleted = true; - // $entity->save(); $this->payment->delete(); return $this; @@ -78,10 +77,22 @@ class DeletePayment private function adjustInvoices() { if ($this->payment->invoices()->exists()) { + $this->payment->invoices()->each(function ($paymentable_invoice) { - $paymentable_invoice->service()->updateBalance($paymentable_invoice->pivot->amount)->save(); - $paymentable_invoice->ledger()->updateInvoiceBalance($paymentable_invoice->pivot->amount, "Adjusting invoice {$paymentable_invoice->number} due to deletion of Payment {$this->payment->number}")->save(); - $paymentable_invoice->client->service()->updateBalance($paymentable_invoice->pivot->amount)->save(); + + $paymentable_invoice->service() + ->updateBalance($paymentable_invoice->pivot->amount) + ->updatePaidToDate($paymentable_invoice->pivot->amount * -1) + ->save(); + + $paymentable_invoice->ledger() + ->updateInvoiceBalance($paymentable_invoice->pivot->amount, "Adjusting invoice {$paymentable_invoice->number} due to deletion of Payment {$this->payment->number}") + ->save(); + + $paymentable_invoice->client + ->service() + ->updateBalance($paymentable_invoice->pivot->amount) + ->save(); if ($paymentable_invoice->balance == $paymentable_invoice->amount) { $paymentable_invoice->service()->setStatus(Invoice::STATUS_SENT)->save(); @@ -101,10 +112,12 @@ class DeletePayment { if ($this->payment->credits()->exists()) { $this->payment->credits()->each(function ($paymentable_credit) { - $paymentable_credit->balance += $paymentable_credit->pivot->amount; - $paymentable_credit->setStatus(Credit::STATUS_SENT); - //fire event for this credit - // + + $paymentable_credit->service() + ->updateBalance($paymentable_credit->pivot->amount) + ->updatePaidToDate($paymentable_credit->pivot->amount*-1) + ->setStatus(Credit::STATUS_SENT) + ->save(); }); } diff --git a/app/Services/Payment/PaymentService.php b/app/Services/Payment/PaymentService.php index c0c4f0acbfdd..b896e395cc50 100644 --- a/app/Services/Payment/PaymentService.php +++ b/app/Services/Payment/PaymentService.php @@ -59,11 +59,16 @@ class PaymentService $client = $this->payment->client; $invoices->each(function ($invoice) { + if ($invoice->pivot->amount > 0) { - $invoice->status_id = Invoice::STATUS_SENT; - $invoice->balance = $invoice->pivot->amount; - $invoice->save(); + + $invoice->service() + ->updateBalance($invoice->pivot->amount) + ->updatePaidToDate($invoice->pivot->amount*-1) + ->setStatus(Invoice::STATUS_SENT) + ->save(); } + }); $this->payment diff --git a/app/Services/Payment/RefundPayment.php b/app/Services/Payment/RefundPayment.php index 2bb590f32c1b..19c259ef4827 100644 --- a/app/Services/Payment/RefundPayment.php +++ b/app/Services/Payment/RefundPayment.php @@ -188,18 +188,26 @@ class RefundPayment if ($available_credit > $this->total_refund) { $paymentable_credit->pivot->refunded += $this->total_refund; $paymentable_credit->pivot->save(); - $paymentable_credit->balance += $this->total_refund; - $paymentable_credit->service()->setStatus(Credit::STATUS_SENT)->save(); - //$paymentable_credit->save(); + + $paymentable_credit->service() + ->setStatus(Credit::STATUS_SENT) + ->updateBalance($this->total_refund) + ->updatePaidToDate($this->total_refund*-1) + ->save(); $this->total_refund = 0; + } else { + $paymentable_credit->pivot->refunded += $available_credit; $paymentable_credit->pivot->save(); $paymentable_credit->balance += $available_credit; - $paymentable_credit->service()->setStatus(Credit::STATUS_SENT)->save(); -// $paymentable_credit->save(); + $paymentable_credit->service() + ->setStatus(Credit::STATUS_SENT) + ->updateBalance($available_credit) + ->updatePaidToDate($available_credit*-1) + ->save(); $this->total_refund -= $available_credit; } diff --git a/app/Services/Payment/UpdateInvoicePayment.php b/app/Services/Payment/UpdateInvoicePayment.php index 9df0b53c066a..c81b87bd434d 100644 --- a/app/Services/Payment/UpdateInvoicePayment.php +++ b/app/Services/Payment/UpdateInvoicePayment.php @@ -79,6 +79,7 @@ class UpdateInvoicePayment $invoice->service() //caution what if we amount paid was less than partial - we wipe it! ->clearPartial() ->updateBalance($paid_amount * -1) + ->updatePaidToDate($paid_amount) ->updateStatus() ->save(); diff --git a/app/Transformers/CreditTransformer.php b/app/Transformers/CreditTransformer.php index fba8882918c1..8d48f1b0b264 100644 --- a/app/Transformers/CreditTransformer.php +++ b/app/Transformers/CreditTransformer.php @@ -136,6 +136,7 @@ class CreditTransformer extends EntityTransformer 'line_items' => $credit->line_items ?: (array) [], 'entity_type' => 'credit', 'exchange_rate' => (float) $credit->exchange_rate, + 'paid_to_date' => (float) $credit->paid_to_date, ]; } } diff --git a/app/Transformers/InvoiceTransformer.php b/app/Transformers/InvoiceTransformer.php index ccfdbf62713a..7a31a4b7760c 100644 --- a/app/Transformers/InvoiceTransformer.php +++ b/app/Transformers/InvoiceTransformer.php @@ -140,6 +140,8 @@ class InvoiceTransformer extends EntityTransformer 'reminder2_sent' => $invoice->reminder2_sent ?: '', 'reminder3_sent' => $invoice->reminder3_sent ?: '', 'reminder_last_sent' => $invoice->reminder_last_sent ?: '', + 'paid_to_date' => (float) $invoice->paid_to_date, + ]; } } diff --git a/app/Transformers/QuoteTransformer.php b/app/Transformers/QuoteTransformer.php index eb11187f8c57..ae8cd498c0b9 100644 --- a/app/Transformers/QuoteTransformer.php +++ b/app/Transformers/QuoteTransformer.php @@ -137,6 +137,7 @@ class QuoteTransformer extends EntityTransformer 'line_items' => $quote->line_items ?: (array) [], 'entity_type' => 'quote', 'exchange_rate' => (float) $quote->exchange_rate, + 'paid_to_date' => (float) $quote->paid_to_date, 'project_id' => $this->encodePrimaryKey($quote->project_id), ]; } diff --git a/app/Transformers/RecurringInvoiceTransformer.php b/app/Transformers/RecurringInvoiceTransformer.php index e26d03dc8512..73f4d3f7d8d5 100644 --- a/app/Transformers/RecurringInvoiceTransformer.php +++ b/app/Transformers/RecurringInvoiceTransformer.php @@ -138,6 +138,7 @@ class RecurringInvoiceTransformer extends EntityTransformer 'auto_bill' => (string) $invoice->auto_bill, 'auto_bill_enabled' => (bool) $invoice->auto_bill_enabled, 'due_date_days' => (string) $invoice->due_date_days ?: '', + 'paid_to_date' => (float) $invoice->paid_to_date, ]; } } diff --git a/database/migrations/2021_01_24_052645_add_paid_to_date_column.php b/database/migrations/2021_01_24_052645_add_paid_to_date_column.php new file mode 100644 index 000000000000..614cce02b4a7 --- /dev/null +++ b/database/migrations/2021_01_24_052645_add_paid_to_date_column.php @@ -0,0 +1,42 @@ +decimal('paid_to_date', 20, 6)->default(0); + }); + + Schema::table('quotes', function (Blueprint $table) { + $table->decimal('paid_to_date', 20, 6)->default(0); + }); + + Schema::table('credits', function (Blueprint $table) { + $table->decimal('paid_to_date', 20, 6)->default(0); + }); + + Schema::table('recurring_invoices', function (Blueprint $table) { + $table->decimal('paid_to_date', 20, 6)->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + + } +}