From 3d507fad686b5c729b9b65993a9c17bfc1bc50a6 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 10 Jan 2017 10:49:41 +0200 Subject: [PATCH] Check invoice is set to is_public in the API --- app/Http/Controllers/InvoiceApiController.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/InvoiceApiController.php b/app/Http/Controllers/InvoiceApiController.php index 5e40dfc95f..320c07184b 100644 --- a/app/Http/Controllers/InvoiceApiController.php +++ b/app/Http/Controllers/InvoiceApiController.php @@ -158,13 +158,23 @@ class InvoiceApiController extends BaseAPIController $data = self::prepareData($data, $client); $data['client_id'] = $client->id; + + // in these cases the invoice needs to be set as public + $isAutoBill = isset($data['auto_bill']) && filter_var($data['auto_bill'], FILTER_VALIDATE_BOOLEAN); + $isEmailInvoice = isset($data['email_invoice']) && filter_var($data['email_invoice'], FILTER_VALIDATE_BOOLEAN); + $isPaid = isset($data['paid']) && floatval($data['paid']); + + if ($isAutoBill || $isPaid || $isEmailInvoice) { + $data['is_public'] = true; + } + $invoice = $this->invoiceService->save($data); $payment = false; if ($invoice->isInvoice()) { - if (isset($data['auto_bill']) && boolval($data['auto_bill'])) { + if ($isAutoBill) { $payment = $this->paymentService->autoBillInvoice($invoice); - } else if (isset($data['paid']) && $data['paid']) { + } else if ($isPaid) { $payment = $this->paymentRepo->save([ 'invoice_id' => $invoice->id, 'client_id' => $client->id, @@ -173,7 +183,7 @@ class InvoiceApiController extends BaseAPIController } } - if (isset($data['email_invoice']) && $data['email_invoice']) { + if ($isEmailInvoice) { if ($payment) { $this->mailer->sendPaymentConfirmation($payment); } elseif ( ! $invoice->is_recurring) {