diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index cc8ec5f8d66b..d76c5033dcdd 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -42,6 +42,8 @@ class AutoBillInvoice extends AbstractService if(!$this->invoice->isPayable()) return $this->invoice; + $this->invoice = $this->invoice->service()->markSent()->save(); + if($this->invoice->balance > 0) $gateway_token = $this->getGateway($this->invoice->balance); else @@ -70,12 +72,12 @@ class AutoBillInvoice extends AbstractService if($payment){ - $this->invoice->service()->toggleFeesPaid()->save(); - + $this->invoice = $this->invoice->service()->toggleFeesPaid()->save(); + } else { - //autobill failed + //TODO autobill failed } diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 40d587733b2a..10b6ba0a8438 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -182,9 +182,11 @@ class InvoiceService { $this->invoice->line_items = collect($this->invoice->line_items) - ->where('type_id',3)->map(function ($item) { + ->map(function ($item) { - $item->type_id=4; + if($item->type_id == 3) + $item->type_id = 4; + return $item; })->toArray(); diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 8ae30079c316..76591becad86 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -42,6 +42,10 @@ class MarkPaid extends AbstractService $this->invoice->service()->markSent(); } + /*Don't double pay*/ + if($this->invoice->statud_id == Invoice::STATUS_PAID) + return $this->invoice; + /* Create Payment */ $payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id); diff --git a/app/Services/Invoice/TriggeredActions.php b/app/Services/Invoice/TriggeredActions.php index e14017fdcc7d..1610c08898b9 100644 --- a/app/Services/Invoice/TriggeredActions.php +++ b/app/Services/Invoice/TriggeredActions.php @@ -45,11 +45,11 @@ class TriggeredActions extends AbstractService { if($this->request->has('auto_bill')) { - $this->invoice->service()->autoBill()->save(); + $this->invoice = $this->invoice->service()->autoBill()->save(); } if($this->request->has('paid') && (bool)$this->request->input('paid') !== false) { - $this->invoice->service()->markPaid()->save(); + $this->invoice = $this->invoice->service()->markPaid()->save(); } if($this->request->has('send_email') && (bool)$this->request->input('send_email') !== false) { diff --git a/app/Utils/Traits/MakesReminders.php b/app/Utils/Traits/MakesReminders.php index 1da4e1c8de5c..4dbab806e75b 100644 --- a/app/Utils/Traits/MakesReminders.php +++ b/app/Utils/Traits/MakesReminders.php @@ -189,7 +189,9 @@ trait MakesReminders $client = $this->client; //if the invoice - if ($client->getSetting('enable_reminder1') !== false && $this->inReminderWindow( + if($this->balance == 0){ + return 'invoice'; + }elseif ($client->getSetting('enable_reminder1') !== false && $this->inReminderWindow( $client->getSetting('schedule_reminder1'), $client->getSetting('num_days_reminder1') )) {