diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index ddd8958bd6..6c18e366f5 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -59,6 +59,10 @@ class ContactMailer extends Mailer */ public function sendInvoice(Invoice $invoice, $reminder = false, $pdfString = false) { + if ($invoice->is_recurring) { + return false; + } + $invoice->load('invitations', 'client.language', 'account'); $entityType = $invoice->getEntityType(); diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index fa64ed5b54..85d9f3ac3a 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -366,15 +366,15 @@ class InvoiceRepository extends BaseRepository } if ($invoice->is_recurring) { - if ($invoice->start_date && $invoice->start_date != Utils::toSqlDate($data['start_date'])) { + if (isset($data['start_date']) && $invoice->start_date && $invoice->start_date != Utils::toSqlDate($data['start_date'])) { $invoice->last_sent_date = null; } - $invoice->frequency_id = $data['frequency_id'] ? $data['frequency_id'] : 0; - $invoice->start_date = Utils::toSqlDate($data['start_date']); - $invoice->end_date = Utils::toSqlDate($data['end_date']); + $invoice->frequency_id = array_get($data, 'frequency_id', 0); + $invoice->start_date = Utils::toSqlDate(array_get($data, 'start_date')); + $invoice->end_date = Utils::toSqlDate(array_get($data, 'end_date')); $invoice->client_enable_auto_bill = isset($data['client_enable_auto_bill']) && $data['client_enable_auto_bill'] ? true : false; - $invoice->auto_bill = isset($data['auto_bill']) ? intval($data['auto_bill']) : AUTO_BILL_OFF; + $invoice->auto_bill = array_get($data, 'auto_bill_id') ?: array_get($data, 'auto_bill', AUTO_BILL_OFF); if ($invoice->auto_bill < AUTO_BILL_OFF || $invoice->auto_bill > AUTO_BILL_ALWAYS ) { $invoice->auto_bill = AUTO_BILL_OFF; diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index 73438c95c7..36b6c96c24 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -45,6 +45,10 @@ class PaymentService extends BaseService */ public function autoBillInvoice(Invoice $invoice) { + if ( ! $invoice->canBePaid()) { + return false; + } + /** @var \App\Models\Client $client */ $client = $invoice->client;