Set flags for recurring invoices and quote terms

This commit is contained in:
David Bomba 2022-05-17 17:36:28 +10:00
parent d32184a3d7
commit 14b5770a0a
5 changed files with 30 additions and 5 deletions

View File

@ -30,7 +30,8 @@ class CloneQuoteToInvoiceFactory
unset($quote_array['invitations']); unset($quote_array['invitations']);
//preserve terms if they exist on Quotes //preserve terms if they exist on Quotes
if(array_key_exists('terms', $quote_array) && strlen($quote_array['terms']) < 2) //if(array_key_exists('terms', $quote_array) && strlen($quote_array['terms']) < 2)
if(!$quote->company->use_quote_terms_on_conversion)
unset($quote_array['terms']); unset($quote_array['terms']);
// unset($quote_array['public_notes']); // unset($quote_array['public_notes']);
@ -38,7 +39,6 @@ class CloneQuoteToInvoiceFactory
unset($quote_array['design_id']); unset($quote_array['design_id']);
unset($quote_array['user']); unset($quote_array['user']);
foreach ($quote_array as $key => $value) { foreach ($quote_array as $key => $value) {
$invoice->{$key} = $value; $invoice->{$key} = $value;
} }

View File

@ -67,11 +67,23 @@ class RecurringInvoicesCron
nlog("Trying to send {$recurring_invoice->number}"); nlog("Trying to send {$recurring_invoice->number}");
/* Special check if we should generate another invoice is the previous one is yet to be paid */
if($recurring_invoice->company->stop_on_unpaid_recurring && $recurring_invoice->invoices()->whereIn('status_id', [2,3])->where('is_deleted', 0)->where('balance', '>', 0)->exists()) {
nlog("Existing invoice exists, skipping");
return;
}
try{ try{
SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db); SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db);
} }
catch(\Exception $e){ catch(\Exception $e){
nlog("Unable to sending recurring invoice {$recurring_invoice->id} ". $e->getMessage()); nlog("Unable to sending recurring invoice {$recurring_invoice->id} ". $e->getMessage());
} }
}); });
@ -103,6 +115,13 @@ class RecurringInvoicesCron
nlog("Trying to send {$recurring_invoice->number}"); nlog("Trying to send {$recurring_invoice->number}");
if($recurring_invoice->company->stop_on_unpaid_recurring) {
if($recurring_invoice->invoices()->whereIn('status_id', [2,3])->where('is_deleted', 0)->where('balance', '>', 0)->exists())
return;
}
try{ try{
SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db); SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db);
} }

View File

@ -100,6 +100,8 @@ class Company extends BaseModel
'client_registration_fields', 'client_registration_fields',
'convert_rate_to_client', 'convert_rate_to_client',
'markdown_email_enabled', 'markdown_email_enabled',
'stop_on_unpaid_recurring',
'use_quote_terms_on_conversion',
]; ];
protected $hidden = [ protected $hidden = [

View File

@ -168,6 +168,7 @@ class CompanyTransformer extends EntityTransformer
'client_registration_fields' => (array) $company->client_registration_fields, 'client_registration_fields' => (array) $company->client_registration_fields,
'convert_rate_to_client' => (bool) $company->convert_rate_to_client, 'convert_rate_to_client' => (bool) $company->convert_rate_to_client,
'markdown_email_enabled' => (bool) $company->markdown_email_enabled, 'markdown_email_enabled' => (bool) $company->markdown_email_enabled,
'stop_on_unpaid_recurring' => (bool) $company->stop_on_unpaid_recurring,
]; ];
} }

View File

@ -16,6 +16,11 @@ class AddAutoBillTriesToInvoicesTable extends Migration
Schema::table('invoices', function (Blueprint $table) { Schema::table('invoices', function (Blueprint $table) {
$table->smallInteger('auto_bill_tries')->default(0); $table->smallInteger('auto_bill_tries')->default(0);
}); });
Schema::table('companies', function (Blueprint $table) {
$table->boolean('stop_on_unpaid_recurring')->default(0);
$table->boolean('use_quote_terms_on_conversion')->default(0);
});
} }
/** /**
@ -25,8 +30,6 @@ class AddAutoBillTriesToInvoicesTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::table('invoices', function (Blueprint $table) {
$table->dropColumn('auto_bill_tries');
});
} }
} }