From 02e8e6e000e8669c9fde0f522d7008aefda0d70d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 7 Sep 2021 13:57:55 +1000 Subject: [PATCH] Fixes for amounts when formatted with comma's --- .../Controllers/ClientPortal/InvoiceController.php | 10 ++++++++-- app/Jobs/Cron/AutoBillCron.php | 14 +++++++++----- app/Jobs/RecurringInvoice/SendRecurring.php | 2 ++ app/Repositories/BaseRepository.php | 3 ++- app/Repositories/PaymentRepository.php | 8 ++++---- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index bb8ca40832bb..6094b85fc6cc 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -20,7 +20,9 @@ use App\Utils\Number; use App\Utils\TempFile; use App\Utils\Traits\MakesDates; use App\Utils\Traits\MakesHash; +use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\View\View; use ZipStream\Option\Archive; use ZipStream\ZipStream; @@ -86,6 +88,10 @@ class InvoiceController extends Controller ->with('message', ctrans('texts.no_action_provided')); } + /** + * @param array $ids + * @return Factory|View|RedirectResponse + */ private function makePayment(array $ids) { $invoices = Invoice::whereIn('id', $ids) @@ -119,8 +125,8 @@ class InvoiceController extends Controller //format data $invoices->map(function ($invoice) { $invoice->service()->removeUnpaidGatewayFees()->save(); - $invoice->balance = Number::formatValue($invoice->balance, $invoice->client->currency()); - $invoice->partial = Number::formatValue($invoice->partial, $invoice->client->currency()); + $invoice->balance = $invoice->balance > 0 ? Number::formatValue($invoice->balance, $invoice->client->currency()) : 0; + $invoice->partial = $invoice->partial > 0 ? Number::formatValue($invoice->partial, $invoice->client->currency()) : 0; return $invoice; }); diff --git a/app/Jobs/Cron/AutoBillCron.php b/app/Jobs/Cron/AutoBillCron.php index f3918e9fffb2..0b852cb4806b 100644 --- a/app/Jobs/Cron/AutoBillCron.php +++ b/app/Jobs/Cron/AutoBillCron.php @@ -56,8 +56,8 @@ class AutoBillCron nlog($auto_bill_partial_invoices->count(). " partial invoices to auto bill"); - $auto_bill_partial_invoices->cursor()->each(function ($invoice) use($db){ - $this->runAutoBiller($invoice, $db); + $auto_bill_partial_invoices->cursor()->each(function ($invoice){ + $this->runAutoBiller($invoice, false); }); $auto_bill_invoices = Invoice::whereDate('due_date', '<=', now()) @@ -69,8 +69,8 @@ class AutoBillCron nlog($auto_bill_invoices->count(). " full invoices to auto bill"); - $auto_bill_invoices->cursor()->each(function ($invoice) use($db){ - $this->runAutoBiller($invoice, $db); + $auto_bill_invoices->cursor()->each(function ($invoice){ + $this->runAutoBiller($invoice, false); }); @@ -115,8 +115,12 @@ class AutoBillCron info("Firing autobill for {$invoice->company_id} - {$invoice->number}"); try{ - MultiDB::setDB($db); + + if($db) + MultiDB::setDB($db); + $invoice->service()->autoBill()->save(); + } catch(\Exception $e) { nlog("Failed to capture payment for {$invoice->company_id} - {$invoice->number} ->" . $e->getMessage()); diff --git a/app/Jobs/RecurringInvoice/SendRecurring.php b/app/Jobs/RecurringInvoice/SendRecurring.php index ba4cd3a0a717..de7ab9bfc359 100644 --- a/app/Jobs/RecurringInvoice/SendRecurring.php +++ b/app/Jobs/RecurringInvoice/SendRecurring.php @@ -147,6 +147,8 @@ class SendRecurring implements ShouldQueue } + //important catch all here - we should never leave contacts send_email to false incase they are permanently set to false in the future. + $this->recurring_invoice->client->contacts()->update(['send_email' => true]); } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index fae747d85452..18970695e2eb 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -28,7 +28,8 @@ class BaseRepository { use MakesHash; use SavesDocuments; - public $import_mode = false; + + public $import_mode = false; /** * @param $entity diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 8a83d29e8124..ebcb5add517b 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -170,10 +170,10 @@ class PaymentRepository extends BaseRepository { event( new PaymentWasCreated( $payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null) ) ); } - nlog("payment amount = {$payment->amount}"); - nlog("payment applied = {$payment->applied}"); - nlog("invoice totals = {$invoice_totals}"); - nlog("credit totals = {$credit_totals}"); + // nlog("payment amount = {$payment->amount}"); + // nlog("payment applied = {$payment->applied}"); + // nlog("invoice totals = {$invoice_totals}"); + // nlog("credit totals = {$credit_totals}"); $payment->applied += ($invoice_totals - $credit_totals); //wont work because - check tests // $payment->applied += $invoice_totals; //wont work because - check tests