1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-06 03:02:34 +01:00

Fixes for designs in migration:

This commit is contained in:
David Bomba 2020-10-07 10:16:57 +11:00
parent ee67911afb
commit 70a575386c
9 changed files with 39 additions and 24 deletions

View File

@ -230,7 +230,10 @@ class InvoiceItemSum
continue; continue;
} }
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total)); //$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total));
$amount = ( $this->sub_total > 0 ) ? $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total)) : 0;
$item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount); $item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount);
$item_tax += $item_tax_rate1_total; $item_tax += $item_tax_rate1_total;
@ -260,7 +263,8 @@ class InvoiceItemSum
} }
/** /**
* Sets default values for the line_items. * Sets default casts for the values in the line_items.
*
* @return $this * @return $this
*/ */
private function cleanLineItem() private function cleanLineItem()

View File

@ -55,6 +55,9 @@ class UniqueInvoiceNumberRule implements Rule
*/ */
private function checkIfInvoiceNumberUnique() : bool private function checkIfInvoiceNumberUnique() : bool
{ {
if(empty($this->input['number']))
return true;
$invoice = Invoice::where('client_id', $this->input['client_id']) $invoice = Invoice::where('client_id', $this->input['client_id'])
->where('number', $this->input['number']) ->where('number', $this->input['number'])
->withTrashed() ->withTrashed()

View File

@ -37,6 +37,7 @@ class Gateway extends StaticModel
/** /**
* @return mixed * @return mixed
* @deprecated 5.0.17 No longer needs as we are removing omnipay dependence
*/ */
public function getFields() public function getFields()
{ {

View File

@ -44,11 +44,11 @@ class ApplyNumber extends AbstractService
switch ($this->client->getSetting('counter_number_applied')) { switch ($this->client->getSetting('counter_number_applied')) {
case 'when_saved': case 'when_saved':
$this->invoice->number = $this->getNextInvoiceNumber($this->client); $this->invoice->number = $this->getNextInvoiceNumber($this->client, $this->invoice);
break; break;
case 'when_sent': case 'when_sent':
if ($this->invoice->status_id == Invoice::STATUS_SENT) { if ($this->invoice->status_id == Invoice::STATUS_SENT) {
$this->invoice->number = $this->getNextInvoiceNumber($this->client); $this->invoice->number = $this->getNextInvoiceNumber($this->client, $this->invoice);
} }
break; break;

View File

@ -37,7 +37,7 @@ trait GeneratesCounter
* *
* @return string The next invoice number. * @return string The next invoice number.
*/ */
public function getNextInvoiceNumber(Client $client) :string public function getNextInvoiceNumber(Client $client, ?Invoice $invoice) :string
{ {
//Reset counters if enabled //Reset counters if enabled
$this->resetCounters($client); $this->resetCounters($client);
@ -67,6 +67,9 @@ trait GeneratesCounter
$invoice_number = $this->checkEntityNumber(Invoice::class, $client, $counter, $padding, $pattern); $invoice_number = $this->checkEntityNumber(Invoice::class, $client, $counter, $padding, $pattern);
if($invoice && $invoice->recurring_id)
$invoice_number = $this->prefixCounter($invoice_number, $client->getSetting('recurring_number_prefix'));
$this->incrementCounter($counter_entity, 'invoice_number_counter'); $this->incrementCounter($counter_entity, 'invoice_number_counter');
return $invoice_number; return $invoice_number;
@ -140,6 +143,9 @@ trait GeneratesCounter
$quote_number = $this->checkEntityNumber(Quote::class, $client, $counter, $padding, $pattern); $quote_number = $this->checkEntityNumber(Quote::class, $client, $counter, $padding, $pattern);
// if($this->recurring_id)
// $quote_number = $this->prefixCounter($quote_number, $client->getSetting('recurring_number_prefix'));
$this->incrementCounter($counter_entity, $used_counter); $this->incrementCounter($counter_entity, $used_counter);
return $quote_number; return $quote_number;
@ -168,7 +174,7 @@ trait GeneratesCounter
$pattern = ''; $pattern = '';
$padding = $client->getSetting('counter_padding'); $padding = $client->getSetting('counter_padding');
$invoice_number = $this->checkEntityNumber(RecurringInvoice::class, $client, $counter, $padding, $pattern); $invoice_number = $this->checkEntityNumber(RecurringInvoice::class, $client, $counter, $padding, $pattern);
$invoice_number = $this->prefixCounter($invoice_number, $client->getSetting('recurring_number_prefix')); //$invoice_number = $this->prefixCounter($invoice_number, $client->getSetting('recurring_number_prefix'));
//increment the correct invoice_number Counter (company vs client) //increment the correct invoice_number Counter (company vs client)
if ($is_client_counter) { if ($is_client_counter) {

View File

@ -39,6 +39,7 @@ class CompanyFactory extends Factory
'db' => config('database.default'), 'db' => config('database.default'),
'settings' => CompanySettings::defaults(), 'settings' => CompanySettings::defaults(),
'is_large' => false, 'is_large' => false,
'enabled_modules' => config('ninja.enabled_modules'),
'custom_fields' => (object) [ 'custom_fields' => (object) [
//'invoice1' => 'Custom Date|date', //'invoice1' => 'Custom Date|date',
// 'invoice2' => '2|switch', // 'invoice2' => '2|switch',

View File

@ -54,7 +54,7 @@ class InvoiceEmailTest extends TestCase
{ {
$this->invoice->date = now(); $this->invoice->date = now();
$this->invoice->due_date = now()->addDays(7); $this->invoice->due_date = now()->addDays(7);
$this->invoice->number = $this->getNextInvoiceNumber($this->client); $this->invoice->number = $this->getNextInvoiceNumber($this->client, $this->invoice);
$this->invoice->client_id = $this->client->id; $this->invoice->client_id = $this->client->id;
@ -90,7 +90,7 @@ class InvoiceEmailTest extends TestCase
$this->invoice->date = now(); $this->invoice->date = now();
$this->invoice->due_date = now()->addDays(7); $this->invoice->due_date = now()->addDays(7);
$this->invoice->number = $this->getNextInvoiceNumber($this->client); $this->invoice->number = $this->getNextInvoiceNumber($this->client, $this->invoice);
$this->invoice->client_id = $this->client->id; $this->invoice->client_id = $this->client->id;
$this->invoice->setRelation('client', $this->client); $this->invoice->setRelation('client', $this->client);
@ -115,7 +115,7 @@ class InvoiceEmailTest extends TestCase
$this->invoice->date = now(); $this->invoice->date = now();
$this->invoice->due_date = now()->addDays(7); $this->invoice->due_date = now()->addDays(7);
$this->invoice->number = $this->getNextInvoiceNumber($this->client); $this->invoice->number = $this->getNextInvoiceNumber($this->client, $this->invoice);
$this->invoice->client_id = $this->client->id; $this->invoice->client_id = $this->client->id;
@ -145,7 +145,7 @@ class InvoiceEmailTest extends TestCase
$this->invoice->date = now(); $this->invoice->date = now();
$this->invoice->due_date = now()->addDays(7); $this->invoice->due_date = now()->addDays(7);
$this->invoice->number = $this->getNextInvoiceNumber($this->client); $this->invoice->number = $this->getNextInvoiceNumber($this->client, $this->invoice);
$this->invoice->client_id = $this->client->id; $this->invoice->client_id = $this->client->id;
$this->invoice->setRelation('client', $this->client); $this->invoice->setRelation('client', $this->client);

View File

@ -356,7 +356,7 @@ trait MockAccountData
$recurring_invoice->next_send_date = Carbon::now(); $recurring_invoice->next_send_date = Carbon::now();
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client); $recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client, $this->invoice);
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice); $recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
@ -366,7 +366,7 @@ trait MockAccountData
$recurring_invoice->next_send_date = Carbon::now(); $recurring_invoice->next_send_date = Carbon::now();
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client); $recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client, $this->invoice);
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice); $recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
@ -376,7 +376,7 @@ trait MockAccountData
$recurring_invoice->next_send_date = Carbon::now(); $recurring_invoice->next_send_date = Carbon::now();
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client); $recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client, $this->invoice);
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice); $recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
@ -386,7 +386,7 @@ trait MockAccountData
$recurring_invoice->next_send_date = Carbon::now(); $recurring_invoice->next_send_date = Carbon::now();
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client); $recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client, $this->invoice);
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice); $recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
@ -396,7 +396,7 @@ trait MockAccountData
$recurring_invoice->next_send_date = Carbon::now(); $recurring_invoice->next_send_date = Carbon::now();
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client); $recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client, $this->invoice);
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice); $recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
@ -406,7 +406,7 @@ trait MockAccountData
$recurring_invoice->next_send_date = Carbon::now()->addDays(10); $recurring_invoice->next_send_date = Carbon::now()->addDays(10);
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client); $recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client, $this->invoice);
$recurring_invoice->save(); $recurring_invoice->save();
$gs = new GroupSetting; $gs = new GroupSetting;

View File

@ -79,11 +79,11 @@ class GeneratesCounterTest extends TestCase
public function testInvoiceNumberValue() public function testInvoiceNumberValue()
{ {
$invoice_number = $this->getNextInvoiceNumber($this->client); $invoice_number = $this->getNextInvoiceNumber($this->client, $this->invoice);
$this->assertEquals($invoice_number, '0008'); $this->assertEquals($invoice_number, '0008');
$invoice_number = $this->getNextInvoiceNumber($this->client); $invoice_number = $this->getNextInvoiceNumber($this->client, $this->invoice);
$this->assertEquals($invoice_number, '0009'); $this->assertEquals($invoice_number, '0009');
} }
@ -112,8 +112,8 @@ class GeneratesCounterTest extends TestCase
$this->client->save(); $this->client->save();
$this->client->fresh(); $this->client->fresh();
$invoice_number = $this->getNextInvoiceNumber($this->client); $invoice_number = $this->getNextInvoiceNumber($this->client, $this->invoice);
$invoice_number2 = $this->getNextInvoiceNumber($this->client); $invoice_number2 = $this->getNextInvoiceNumber($this->client, $this->invoice);
$this->assertEquals($invoice_number, date('Y').'-0001'); $this->assertEquals($invoice_number, date('Y').'-0001');
$this->assertEquals($invoice_number2, date('Y').'-0002'); $this->assertEquals($invoice_number2, date('Y').'-0002');
@ -203,7 +203,7 @@ class GeneratesCounterTest extends TestCase
$cliz = ClientFactory::create($this->company->id, $this->user->id); $cliz = ClientFactory::create($this->company->id, $this->user->id);
$cliz->settings = ClientSettings::defaults(); $cliz->settings = ClientSettings::defaults();
$cliz->save(); $cliz->save();
$invoice_number = $this->getNextInvoiceNumber($cliz); $invoice_number = $this->getNextInvoiceNumber($cliz, $this->invoice);
$this->assertEquals($cliz->getSetting('counter_padding'), 5); $this->assertEquals($cliz->getSetting('counter_padding'), 5);
$this->assertEquals($invoice_number, '00007'); $this->assertEquals($invoice_number, '00007');
@ -218,7 +218,7 @@ class GeneratesCounterTest extends TestCase
$cliz->settings = ClientSettings::defaults(); $cliz->settings = ClientSettings::defaults();
$cliz->save(); $cliz->save();
$invoice_number = $this->getNextInvoiceNumber($cliz); $invoice_number = $this->getNextInvoiceNumber($cliz, $this->invoice);
$this->assertEquals($cliz->getSetting('counter_padding'), 10); $this->assertEquals($cliz->getSetting('counter_padding'), 10);
$this->assertEquals(strlen($invoice_number), 10); $this->assertEquals(strlen($invoice_number), 10);
@ -235,11 +235,11 @@ class GeneratesCounterTest extends TestCase
$cliz->settings = ClientSettings::defaults(); $cliz->settings = ClientSettings::defaults();
$cliz->save(); $cliz->save();
$invoice_number = $this->getNextInvoiceNumber($cliz); $invoice_number = $this->getNextInvoiceNumber($cliz, $this->invoice);
$this->assertEquals($invoice_number, '0008'); $this->assertEquals($invoice_number, '0008');
$invoice_number = $this->getNextInvoiceNumber($cliz); $invoice_number = $this->getNextInvoiceNumber($cliz, $this->invoice);
$this->assertEquals($invoice_number, '0009'); $this->assertEquals($invoice_number, '0009');
} }