1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Fixes for Zoho Import

This commit is contained in:
David Bomba 2022-12-01 08:49:59 +11:00
parent f7bd931c0c
commit 7b073d033a
6 changed files with 275 additions and 268 deletions

View File

@ -46,7 +46,7 @@ class InvoiceTransformer extends BaseTransformer
'due_date' => isset($invoice_data['Due Date']) ? date('Y-m-d', strtotime($invoice_data['Due Date'])) : null,
'po_number' => $this->getString($invoice_data, 'PurchaseOrder'),
'public_notes' => $this->getString($invoice_data, 'Notes'),
'currency_id' => $this->getCurrencyByCode($invoice_data, 'Currency'),
// 'currency_id' => $this->getCurrencyByCode($invoice_data, 'Currency'),
'amount' => $this->getFloat($invoice_data, 'Total'),
'balance' => $this->getFloat($invoice_data, 'Balance'),
'status_id' => $invoiceStatusMap[$status =

View File

@ -102,6 +102,10 @@ class CreateRawPdf implements ShouldQueue
/* Set customized translations _NOW_ */
$t->replace(Ninja::transformTranslations($this->entity->client->getMergedSettings()));
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
return (new Phantom)->generate($this->invitation, true);
}
$entity_design_id = '';
if ($this->entity instanceof Invoice) {

View File

@ -127,7 +127,7 @@ class CreatePurchaseOrderPdf implements ShouldQueue
$t->replace(Ninja::transformTranslations($this->company->settings));
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
return (new Phantom)->generate($this->invitation);
return (new Phantom)->generate($this->invitation, true);
}
$entity_design_id = '';

View File

@ -42,7 +42,7 @@ class Phantom
*
* @param $invitation
*/
public function generate($invitation)
public function generate($invitation, $return_pdf = false)
{
$entity = false;
@ -112,6 +112,9 @@ class Phantom
$instance = Storage::disk(config('filesystems.default'))->put($file_path, $pdf);
if($return_pdf)
return $pdf;
return $file_path;
}

View File

@ -754,7 +754,7 @@ trait GeneratesCounter
$replace[] = $client->id_number;
$search[] = '{$clientIdNumber}';
$replace[] = $client->id_number;
$replace[] = $client->id_number ?: $client->number;
}
return str_replace($search, $replace, $pattern);

View File

@ -67,26 +67,26 @@ class PaymentTest extends TestCase
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_Taxes = false;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_Taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$invoice = $invoice_calc->getInvoice();
$data = [
'amount' => $this->invoice->amount,
'amount' => $invoice->amount,
'client_id' => $client->hashed_id,
'invoices' => [
[
'invoice_id' => $this->invoice->hashed_id,
'amount' => $this->invoice->amount,
'invoice_id' => $invoice->hashed_id,
'amount' => $invoice->amount,
],
],
'date' => '2020/12/11',
@ -175,25 +175,25 @@ class PaymentTest extends TestCase
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_Taxes = false;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_Taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$invoice = $invoice_calc->getInvoice();
$data = [
'amount' => $this->invoice->amount,
'amount' => $invoice->amount,
'invoices' => [
[
'invoice_id' => $this->invoice->hashed_id,
'amount' => $this->invoice->amount,
'invoice_id' => $invoice->hashed_id,
'amount' => $invoice->amount,
],
],
'date' => '2020/12/11',
@ -226,10 +226,10 @@ class PaymentTest extends TestCase
$invoice->save();
$invoice_calc = new InvoiceSum($this->invoice);
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$invoice = $this->invoice_calc->getInvoice();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
$data = [
@ -277,23 +277,23 @@ class PaymentTest extends TestCase
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$this->invoice->status_id = Invoice::STATUS_SENT;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$invoice->status_id = Invoice::STATUS_SENT;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_taxes = false;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
$data = [
'amount' => $this->invoice->amount,
'amount' => $invoice->amount,
'client_id' => $client->hashed_id,
'invoices' => '',
'date' => '2020/12/12',
@ -319,7 +319,7 @@ class PaymentTest extends TestCase
public function testPartialPaymentAmount()
{
$this->invoice = null;
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
@ -331,28 +331,28 @@ class PaymentTest extends TestCase
'is_primary' => true,
]);
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$this->invoice->partial = 2.0;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_taxes = false;
$invoice->partial = 2.0;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$this->invoice->service()->markSent()->createInvitations()->save();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
$invoice->service()->markSent()->createInvitations()->save();
$data = [
'amount' => 2.0,
'client_id' => $client->hashed_id,
'invoices' => [
[
'invoice_id' => $this->invoice->hashed_id,
'invoice_id' => $invoice->hashed_id,
'amount' => 2.0,
],
],
@ -394,7 +394,7 @@ class PaymentTest extends TestCase
public function testPaymentGreaterThanPartial()
{
$this->invoice = null;
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->setRelation('company', $this->company);
@ -409,32 +409,32 @@ class PaymentTest extends TestCase
$client->setRelation('contacts', $client_contact);
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$this->invoice->partial = 5.0;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_taxes = false;
$invoice->partial = 5.0;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->company->setRelation('company', $this->company);
$this->invoice->company->setRelation('client', $client);
$this->invoice->save();
$this->invoice->service()->markSent()->createInvitations()->save();
$this->invoice->is_deleted = false;
$this->invoice->save();
$invoice = $invoice_calc->getInvoice();
$invoice->company->setRelation('company', $this->company);
$invoice->company->setRelation('client', $client);
$invoice->save();
$invoice->service()->markSent()->createInvitations()->save();
$invoice->is_deleted = false;
$invoice->save();
$data = [
'amount' => 6.0,
'client_id' => $client->hashed_id,
'invoices' => [
[
'invoice_id' => $this->invoice->hashed_id,
'invoice_id' => $invoice->hashed_id,
'amount' => 6.0,
],
],
@ -471,7 +471,7 @@ class PaymentTest extends TestCase
public function testPaymentLessThanPartialAmount()
{
$this->invoice = null;
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
@ -491,28 +491,28 @@ class PaymentTest extends TestCase
'send_email' => true,
]);
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$this->invoice->partial = 5.0;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_taxes = false;
$invoice->partial = 5.0;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$this->invoice->service()->markSent()->createInvitations()->save();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
$invoice->service()->markSent()->createInvitations()->save();
$data = [
'amount' => 2.0,
'client_id' => $client->hashed_id,
'invoices' => [
[
'invoice_id' => $this->invoice->hashed_id,
'invoice_id' => $invoice->hashed_id,
'amount' => 2.0,
],
],
@ -543,7 +543,7 @@ class PaymentTest extends TestCase
public function testPaymentValidationAmount()
{
$this->invoice = null;
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
@ -565,30 +565,30 @@ class PaymentTest extends TestCase
$client->setRelation('contact', $contact);
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$this->invoice->partial = 5.0;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_taxes = false;
$invoice->partial = 5.0;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$this->invoice->service()->markSent()->createInvitations()->save();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
$invoice->service()->markSent()->createInvitations()->save();
$this->invoice->setRelation('client', $client);
$invoice->setRelation('client', $client);
$data = [
'amount' => 1.0,
'client_id' => $client->hashed_id,
'invoices' => [
[
'invoice_id' => $this->invoice->hashed_id,
'invoice_id' => $invoice->hashed_id,
'amount' => 2.0,
],
],
@ -609,32 +609,32 @@ class PaymentTest extends TestCase
public function testPaymentChangesBalancesCorrectly()
{
$this->invoice = null;
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_taxes = false;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$this->invoice->service()->markSent()->createInvitations()->save();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
$invoice->service()->markSent()->createInvitations()->save();
$data = [
'amount' => 2.0,
'client_id' => $client->hashed_id,
'invoices' => [
[
'invoice_id' => $this->invoice->hashed_id,
'invoice_id' => $invoice->hashed_id,
'amount' => 2.0,
],
],
@ -657,7 +657,7 @@ class PaymentTest extends TestCase
if ($response) {
$response->assertStatus(200);
$invoice = Invoice::find($this->decodePrimaryKey($this->invoice->hashed_id));
$invoice = Invoice::find($this->decodePrimaryKey($invoice->hashed_id));
$this->assertEquals($invoice->balance, 8);
@ -669,25 +669,25 @@ class PaymentTest extends TestCase
public function testUpdatePaymentValidationWorks()
{
$this->invoice = null;
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_taxes = false;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$this->invoice->service()->markSent()->createInvitations()->save();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
$invoice->service()->markSent()->createInvitations()->save();
$payment = PaymentFactory::create($this->company->id, $this->user->id);
$payment->amount = 10;
@ -722,25 +722,25 @@ class PaymentTest extends TestCase
public function testUpdatePaymentValidationPasses()
{
$this->invoice = null;
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_taxes = false;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$this->invoice->service()->markSent()->createInvitations()->save();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
$invoice->service()->markSent()->createInvitations()->save();
$payment = PaymentFactory::create($this->company->id, $this->user->id);
$payment->amount = 10;
@ -754,7 +754,7 @@ class PaymentTest extends TestCase
'client_id' => $this->encodePrimaryKey($client->id),
'invoices' => [
[
'invoice_id' => $this->encodePrimaryKey($this->invoice->id),
'invoice_id' => $this->encodePrimaryKey($invoice->id),
'amount' => 10,
],
],
@ -782,32 +782,32 @@ class PaymentTest extends TestCase
public function testDoublePaymentTestWithInvalidAmounts()
{
$this->invoice = null;
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_taxes = false;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$this->invoice->service()->markSent()->createInvitations()->save();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
$invoice->service()->markSent()->createInvitations()->save();
$data = [
'amount' => 15.0,
'client_id' => $this->encodePrimaryKey($client->id),
'invoices' => [
[
'invoice_id' => $this->encodePrimaryKey($this->invoice->id),
'invoice_id' => $this->encodePrimaryKey($invoice->id),
'amount' => 10,
],
],
@ -837,28 +837,28 @@ class PaymentTest extends TestCase
$this->assertEquals($payment->amount, 15);
$this->assertEquals($payment->applied, 10);
$this->invoice = null;
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$invoice = null;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_taxes = false;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$this->invoice->service()->markSent()->createInvitations()->save();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
$invoice->service()->markSent()->createInvitations()->save();
$data = [
'amount' => 15.0,
'client_id' => $this->encodePrimaryKey($client->id),
'invoices' => [
[
'invoice_id' => $this->encodePrimaryKey($this->invoice->id),
'invoice_id' => $this->encodePrimaryKey($invoice->id),
'amount' => 10,
],
],
@ -881,32 +881,32 @@ class PaymentTest extends TestCase
public function testDoublePaymentTestWithValidAmounts()
{
$this->invoice = null;
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_taxes = false;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$this->invoice->service()->markSent()->createInvitations()->save();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
$invoice->service()->markSent()->createInvitations()->save();
$data = [
'amount' => 20.0,
'client_id' => $this->encodePrimaryKey($client->id),
'invoices' => [
[
'invoice_id' => $this->encodePrimaryKey($this->invoice->id),
'invoice_id' => $this->encodePrimaryKey($invoice->id),
'amount' => 10,
],
],
@ -929,28 +929,28 @@ class PaymentTest extends TestCase
$this->assertEquals($payment->amount, 20);
$this->assertEquals($payment->applied, 10);
// $this->invoice = null;
// $this->invoice = InvoiceFactory::create($this->company->id, $this->user->id);//stub the company and user_id
// $this->invoice->client_id = $client->id;
// $invoice = null;
// $invoice = InvoiceFactory::create($this->company->id, $this->user->id);//stub the company and user_id
// $invoice->client_id = $client->id;
// $this->invoice->line_items = $this->buildLineItems();
// $this->invoice->uses_inclusive_taxes = false;
// $invoice->line_items = $this->buildLineItems();
// $invoice->uses_inclusive_taxes = false;
// $this->invoice->save();
// $invoice->save();
// $this->invoice_calc = new InvoiceSum($this->invoice);
// $this->invoice_calc->build();
// $invoice_calc = new InvoiceSum($invoice);
// $invoice_calc->build();
// $this->invoice = $this->invoice_calc->getInvoice();
// $this->invoice->save();
// $this->invoice->service()->markSent()->createInvitations()->save();
// $invoice = $invoice_calc->getInvoice();
// $invoice->save();
// $invoice->service()->markSent()->createInvitations()->save();
// $data = [
// 'amount' => 20.0,
// 'client_id' => $this->encodePrimaryKey($client->id),
// 'invoices' => [
// [
// 'invoice_id' => $this->encodePrimaryKey($this->invoice->id),
// 'invoice_id' => $this->encodePrimaryKey($invoice->id),
// 'amount' => 10,
// ]
// ],
@ -983,27 +983,27 @@ class PaymentTest extends TestCase
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$this->invoice->status_id = Invoice::STATUS_SENT;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$invoice->status_id = Invoice::STATUS_SENT;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_Taxes = false;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_Taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
$data = [
'client_id' => $client->hashed_id,
'invoices' => [
[
'invoice_id' => $this->invoice->hashed_id,
'amount' => $this->invoice->amount,
'invoice_id' => $invoice->hashed_id,
'amount' => $invoice->amount,
],
],
'date' => '2020/12/12',
@ -1028,7 +1028,7 @@ class PaymentTest extends TestCase
$payment_id = $arr['data']['id'];
$this->assertEquals($this->invoice->amount, $arr['data']['amount']);
$this->assertEquals($invoice->amount, $arr['data']['amount']);
$payment = Payment::whereId($this->decodePrimaryKey($payment_id))->first();
@ -1043,28 +1043,28 @@ class PaymentTest extends TestCase
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$this->invoice->status_id = Invoice::STATUS_SENT;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$invoice->status_id = Invoice::STATUS_SENT;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_Taxes = false;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_Taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
$data = [
'amount' => 0,
'client_id' => $client->hashed_id,
'invoices' => [
[
'invoice_id' => $this->invoice->hashed_id,
'amount' => $this->invoice->amount,
'invoice_id' => $invoice->hashed_id,
'amount' => $invoice->amount,
],
],
'date' => '2020/12/12',
@ -1087,9 +1087,9 @@ class PaymentTest extends TestCase
$payment_id = $arr['data']['id'];
$payment = Payment::whereId($this->decodePrimaryKey($payment_id))->first();
$this->assertEquals(round($payment->amount, 2), $this->invoice->amount);
$this->assertEquals(round($payment->amount, 2), $invoice->amount);
$this->assertEquals(round($payment->applied, 2), $this->invoice->amount);
$this->assertEquals(round($payment->applied, 2), $invoice->amount);
}
public function testPaymentForInvoicesFromDifferentClients()
@ -1215,20 +1215,20 @@ class PaymentTest extends TestCase
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$this->invoice->status_id = Invoice::STATUS_SENT;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$invoice->status_id = Invoice::STATUS_SENT;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_taxes = false;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
$credit = CreditFactory::create($this->company->id, $this->user->id);
$credit->client_id = $client->id;
@ -1246,11 +1246,11 @@ class PaymentTest extends TestCase
$credit->save(); //$10 credit
$data = [
'amount' => $this->invoice->amount,
'amount' => $invoice->amount,
'client_id' => $client->hashed_id,
'invoices' => [
[
'invoice_id' => $this->invoice->hashed_id,
'invoice_id' => $invoice->hashed_id,
'amount' => 5,
],
],
@ -1299,28 +1299,28 @@ class PaymentTest extends TestCase
$client->settings = $settings;
$client->save();
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$this->invoice->status_id = Invoice::STATUS_SENT;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$invoice->status_id = Invoice::STATUS_SENT;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_Taxes = false;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_Taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
$data = [
'amount' => $this->invoice->amount,
'amount' => $invoice->amount,
'client_id' => $client->hashed_id,
'invoices' => [
[
'invoice_id' => $this->invoice->hashed_id,
'amount' => $this->invoice->amount,
'invoice_id' => $invoice->hashed_id,
'amount' => $invoice->amount,
],
],
'date' => '2020/12/12',
@ -1357,32 +1357,32 @@ class PaymentTest extends TestCase
public function testPaymentActionArchive()
{
$this->invoice = null;
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_taxes = false;
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$this->invoice->service()->markSent()->createInvitations()->save();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
$invoice->service()->markSent()->createInvitations()->save();
$data = [
'amount' => 20.0,
'client_id' => $this->encodePrimaryKey($client->id),
'invoices' => [
[
'invoice_id' => $this->encodePrimaryKey($this->invoice->id),
'invoice_id' => $this->encodePrimaryKey($invoice->id),
'amount' => 10,
],
],
@ -1436,13 +1436,13 @@ class PaymentTest extends TestCase
public function testDeleteRefundedPayment()
{
$this->invoice = null;
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$this->invoice->client_id = $client->id;
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$item = InvoiceItemFactory::create();
$item->quantity = 1;
@ -1456,29 +1456,29 @@ class PaymentTest extends TestCase
$line_items[] = $item;
$this->invoice->line_items = $line_items;
$this->invoice->uses_inclusive_taxes = false;
$invoice->line_items = $line_items;
$invoice->uses_inclusive_taxes = false;
$this->invoice->save();
$invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$this->invoice->service()->markSent()->createInvitations()->save();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
$invoice->service()->markSent()->createInvitations()->save();
$this->assertEquals(10, $this->invoice->balance);
$this->assertEquals(10, $this->invoice->client->fresh()->balance);
$this->assertEquals(10, $invoice->balance);
$this->assertEquals(10, $invoice->client->fresh()->balance);
$this->invoice = $this->invoice->service()->markPaid()->save();
$invoice = $invoice->service()->markPaid()->save();
$this->assertEquals(0, $this->invoice->balance);
$this->assertEquals(0, $this->invoice->client->balance);
$this->assertEquals(0, $invoice->balance);
$this->assertEquals(0, $invoice->client->balance);
$this->assertTrue($this->invoice->payments()->exists());
$this->assertTrue($invoice->payments()->exists());
$payment = $this->invoice->payments()->first();
$payment = $invoice->payments()->first();
$data = [
'id' => $this->encodePrimaryKey($payment->id),
@ -1486,7 +1486,7 @@ class PaymentTest extends TestCase
'date' => '2021/12/12',
'invoices' => [
[
'invoice_id' => $this->invoice->hashed_id,
'invoice_id' => $invoice->hashed_id,
'amount' => 10,
],
],
@ -1508,8 +1508,8 @@ class PaymentTest extends TestCase
$response->assertStatus(200);
$this->assertEquals(10, $this->invoice->fresh()->balance);
$this->assertEquals(10, $this->invoice->fresh()->balance);
$this->assertEquals(10, $invoice->fresh()->balance);
$this->assertEquals(10, $invoice->fresh()->balance);
$data = [
'ids' => [$this->encodePrimaryKey($payment->id)],
@ -1520,14 +1520,14 @@ class PaymentTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments/bulk?action=delete', $data);
$this->assertEquals(10, $this->invoice->fresh()->balance);
$this->assertEquals(10, $this->invoice->fresh()->balance);
$this->assertEquals(10, $invoice->fresh()->balance);
$this->assertEquals(10, $invoice->fresh()->balance);
}
public function testUniquePaymentNumbers()
{
$data = [
'amount' => $this->invoice->amount,
'amount' => $invoice->amount,
'client_id' => $this->client->hashed_id,
'date' => '2020/12/12',
'number' => 'duplicate',