1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00

Fixes for recurring invoice schema - auto_bill_enabled

This commit is contained in:
David Bomba 2020-09-17 09:26:23 +10:00
parent 7f825f9ed0
commit 24104509b3
4 changed files with 19 additions and 14 deletions

View File

@ -31,13 +31,15 @@ class RecurringInvoiceToInvoiceFactory
$invoice->public_notes = $recurring_invoice->public_notes;
$invoice->private_notes = $recurring_invoice->private_notes;
$invoice->date = date_create()->format($client->date_format());
$invoice->due_date = $recurring_invoice->due_date; //todo calculate based on terms
$invoice->due_date = $recurring_invoice->calculateDueDate($recurring_invoice->next_send_date);
$invoice->is_deleted = $recurring_invoice->is_deleted;
$invoice->line_items = $recurring_invoice->line_items;
$invoice->tax_name1 = $recurring_invoice->tax_name1;
$invoice->tax_rate1 = $recurring_invoice->tax_rate1;
$invoice->tax_name2 = $recurring_invoice->tax_name2;
$invoice->tax_rate2 = $recurring_invoice->tax_rate2;
$invoice->tax_name3 = $recurring_invoice->tax_name3;
$invoice->tax_rate3 = $recurring_invoice->tax_rate3;
$invoice->custom_value1 = $recurring_invoice->custom_value1;
$invoice->custom_value2 = $recurring_invoice->custom_value2;
$invoice->custom_value3 = $recurring_invoice->custom_value3;
@ -45,10 +47,12 @@ class RecurringInvoiceToInvoiceFactory
$invoice->amount = $recurring_invoice->amount;
$invoice->balance = $recurring_invoice->balance;
$invoice->user_id = $recurring_invoice->user_id;
$invoice->assigned_user_id = $recurring_invoice->assigned_user_id;
$invoice->company_id = $recurring_invoice->company_id;
$invoice->recurring_id = $recurring_invoice->id;
$invoice->client_id = $client->id;
$invoice->auto_bill_enabled = $recurring_invoice->auto_bill_enabled;
return $invoice;
}
}

View File

@ -62,7 +62,7 @@ class SendRecurring implements ShouldQueue
->createInvitations()
->save();
$invoice->invitations->each(function ($invitation) use ($invoice) {
$invoice->invitations->each(function ($invitation) use ($invoice) {
$email_builder = (new InvoiceEmail())->build($invitation);
@ -72,6 +72,9 @@ class SendRecurring implements ShouldQueue
});
if($invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $this->recurring_invoice->auto_bill_enabled)
$invoice->service()->autoBill()->save();
/* Set next date here to prevent a recurring loop forming */
$this->recurring_invoice->next_send_date = $this->recurring_invoice->nextSendDate()->format('Y-m-d');
$this->recurring_invoice->remaining_cycles = $this->recurring_invoice->remainingCycles();
@ -86,10 +89,6 @@ class SendRecurring implements ShouldQueue
if ($invoice->invitations->count() > 0)
event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars()));
// Fire Payment if auto-bill is enabled
if ($this->recurring_invoice->auto_bill)
$invoice->service()->autoBill()->save();
}
}

View File

@ -46,7 +46,7 @@ class AutoBillInvoice extends AbstractService
$this->invoice = $this->invoice->service()->markSent()->save();
if ($this->invoice->balance > 0) {
$gateway_token = $this->getGateway($this->invoice->balance);
$gateway_token = $this->getGateway($this->invoice->balance); //todo what if it is only a partial amount?
} else {
return $this->invoice->service()->markPaid()->save();
}

View File

@ -60,20 +60,22 @@ class AddIsPublicToDocumentsTable extends Migration
$table->boolean('custom_surcharge_tax2')->default(false);
$table->boolean('custom_surcharge_tax3')->default(false);
$table->boolean('custom_surcharge_tax4')->default(false);
$table->integer('remaining_cycles')->nullable()->change();
$table->dropColumn('start_date');
$table->string('due_date_days')->nullable();
$table->date('partial_due_date')->nullable();
$table->decimal('exchange_rate', 13, 6)->default(1);
});
Schema::table('invoices', function ($table) {
$table->boolean('auto_bill_enabled')->default(0);
});
Schema::table('companies', function ($table) {
$table->enum('default_auto_bill', ['off', 'always', 'optin', 'optout'])->default('off');
});
Schema::table('recurring_invoices', function (Blueprint $table) {
$table->integer('remaining_cycles')->nullable()->change();
$table->dropColumn('start_date');
$table->string('due_date_days')->nullable();
$table->date('partial_due_date')->nullable();
});
}
/**