From 021b741e561f99d7992ff8c4f48e29f3ee3b645c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Aug 2020 08:33:58 +1000 Subject: [PATCH 01/16] Tests for gateway fees --- app/Models/CompanyGateway.php | 5 ++-- tests/Feature/CompanyGatewayApiTest.php | 39 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 202c2e2b9c..5c6d1628ca 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -270,8 +270,9 @@ class CompanyGateway extends BaseModel info("fee after adding fee tax 3 = {$fee}"); } - //TODO CALCULATE FEE CAP HERE - + if($fees_and_limits->fee_cap > 0 && ($fee > $fees_and_limits->fee_cap)) + $fee = $fees_and_limits->fee_cap; + return $fee; } diff --git a/tests/Feature/CompanyGatewayApiTest.php b/tests/Feature/CompanyGatewayApiTest.php index a3e7dc3dba..4441a9f1fb 100644 --- a/tests/Feature/CompanyGatewayApiTest.php +++ b/tests/Feature/CompanyGatewayApiTest.php @@ -26,6 +26,7 @@ use Tests\TestCase; /** * @test + * @covers App\Models\CompanyGateway */ class CompanyGatewayApiTest extends TestCase { @@ -352,4 +353,42 @@ class CompanyGatewayApiTest extends TestCase $this->assertEquals(12, $company_gateway->calcGatewayFee(10)); } + + + public function testFeesAndLimitsFeePercentAndAmountAndDoubleTaxCalcuationWithFeeCap() + { + //{"1":{"min_limit":1,"max_limit":1000000,"fee_amount":10,"fee_percent":2,"fee_tax_name1":"","fee_tax_name2":"","fee_tax_name3":"","fee_tax_rate1":0,"fee_tax_rate2":0,"fee_tax_rate3":0,"fee_cap":10,"adjust_fee_percent":true}} + $fee = new FeesAndLimits; + $fee->fee_amount = 10; + // $fee->fee_percent = 2; + $fee->fee_tax_name1 = 'GST'; + $fee->fee_tax_rate1 = '10.0'; + $fee->fee_tax_name2 = 'GST'; + $fee->fee_tax_rate2 = '10.0'; + $fee->fee_cap = 1; + + $fee_arr[1] = (array)$fee; + + $data = [ + 'config' => 'random config', + 'gateway_key' => '3b6621f970ab18887c4f6dca78d3f8bb', + 'fees_and_limits' => $fee_arr, + ]; + + /* POST */ + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token + ])->post('/api/v1/company_gateways', $data); + + + $response->assertStatus(200); + + $arr = $response->json(); + $id = $this->decodePrimaryKey($arr['data']['id']); + + $company_gateway = CompanyGateway::find($id); + + $this->assertEquals(1, $company_gateway->calcGatewayFee(10)); + } } From 089f50e7edae23c0b82106edbd5f6d259c15d92f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Aug 2020 08:46:27 +1000 Subject: [PATCH 02/16] if company gateway set to zero, disable gateways for client --- app/Models/Client.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Models/Client.php b/app/Models/Client.php index e68f50a9a9..2cd5f02506 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -460,7 +460,8 @@ class Client extends BaseModel implements HasLocalePreference $company_gateways = $this->getSetting('company_gateway_ids'); - if ($company_gateways) { + if ($company_gateways || $company_gateways == "0") { + $transformed_ids = $this->transformKeys(explode(",", $company_gateways)); $gateways = $this->company ->company_gateways From 71be5510624e257aa16287735d97439cbfe3e30b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Aug 2020 08:47:05 +1000 Subject: [PATCH 03/16] Fixes for disabling client gateways --- app/Models/Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Models/Client.php b/app/Models/Client.php index 2cd5f02506..ecead74d77 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -460,8 +460,8 @@ class Client extends BaseModel implements HasLocalePreference $company_gateways = $this->getSetting('company_gateway_ids'); - if ($company_gateways || $company_gateways == "0") { - + if ($company_gateways || $company_gateways == "0") { //we need to check for "0" here as we disable a payment gateway for a client with the number "0" + $transformed_ids = $this->transformKeys(explode(",", $company_gateways)); $gateways = $this->company ->company_gateways From 3850c6b516a666d4103893ffc47470415a798348 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Aug 2020 08:51:30 +1000 Subject: [PATCH 04/16] Change to display only --- app/Utils/HtmlEngine.php | 10 +++++++--- app/Utils/Traits/MakesInvoiceValues.php | 9 ++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 5db0a98713..4984ce42b5 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -122,7 +122,9 @@ class HtmlEngine $data['$number'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.invoice_number')]; $data['$entity.terms'] = ['value' => $this->entity->terms ?: ' ', 'label' => ctrans('texts.invoice_terms')]; $data['$terms'] = &$data['$entity.terms']; - $data['$view_link'] = ['value' => ''. ctrans('texts.view_invoice').'', 'label' => ctrans('texts.view_invoice')]; + // $data['$view_link'] = ['value' => ''. ctrans('texts.view_invoice').'', 'label' => ctrans('texts.view_invoice')]; + $data['$view_link'] = ['value' => $invitation->getLink(), 'label' => ctrans('texts.view_invoice')]; + } if ($this->entity_string == 'quote') { @@ -130,7 +132,8 @@ class HtmlEngine $data['$number'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.quote_number')]; $data['$entity.terms'] = ['value' => $this->entity->terms ?: ' ', 'label' => ctrans('texts.quote_terms')]; $data['$terms'] = &$data['$entity.terms']; - $data['$view_link'] = ['value' => ''. ctrans('texts.view_quote').'', 'label' => ctrans('texts.view_quote')]; + // $data['$view_link'] = ['value' => ''. ctrans('texts.view_quote').'', 'label' => ctrans('texts.view_quote')]; + $data['$view_link'] = ['value' => $invitation->getLink(), 'label' => ctrans('texts.view_quote')]; } if ($this->entity_string == 'credit') { @@ -138,7 +141,8 @@ class HtmlEngine $data['$number'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.credit_number')]; $data['$entity.terms'] = ['value' => $this->entity->terms ?: ' ', 'label' => ctrans('texts.credit_terms')]; $data['$terms'] = &$data['$entity.terms']; - $data['$view_link'] = ['value' => ''. ctrans('texts.view_credit').'', 'label' => ctrans('texts.view_credit')]; + // $data['$view_link'] = ['value' => ''. ctrans('texts.view_credit').'', 'label' => ctrans('texts.view_credit')]; + $data['$view_link'] = ['value' => $invitation->getLink(), 'label' => ctrans('texts.view_credit')]; } $data['$entity_number'] = &$data['$number']; diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index 27e0048f96..f0f38c24a7 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -215,7 +215,8 @@ trait MakesInvoiceValues $data['$number'] = ['value' => $this->number ?: ' ', 'label' => ctrans('texts.invoice_number')]; $data['$entity.terms'] = ['value' => $this->terms ?: ' ', 'label' => ctrans('texts.invoice_terms')]; $data['$terms'] = &$data['$entity.terms']; - $data['$view_link'] = ['value' => ''. ctrans('texts.view_invoice').'', 'label' => ctrans('texts.view_invoice')]; + //$data['$view_link'] = ['value' => ''. ctrans('texts.view_invoice').'', 'label' => ctrans('texts.view_invoice')]; + $data['$view_link'] = ['value' => $invitation->getLink(), 'label' => ctrans('texts.view_invoice')]; } if ($this instanceof Quote) { @@ -223,7 +224,8 @@ trait MakesInvoiceValues $data['$number'] = ['value' => $this->number ?: ' ', 'label' => ctrans('texts.quote_number')]; $data['$entity.terms'] = ['value' => $this->terms ?: ' ', 'label' => ctrans('texts.quote_terms')]; $data['$terms'] = &$data['$entity.terms']; - $data['$view_link'] = ['value' => ''. ctrans('texts.view_quote').'', 'label' => ctrans('texts.view_quote')]; + // $data['$view_link'] = ['value' => ''. ctrans('texts.view_quote').'', 'label' => ctrans('texts.view_quote')]; + $data['$view_link'] = ['value' => $invitation->getLink(), 'label' => ctrans('texts.view_quote')]; } if ($this instanceof Credit) { @@ -231,7 +233,8 @@ trait MakesInvoiceValues $data['$number'] = ['value' => $this->number ?: ' ', 'label' => ctrans('texts.credit_number')]; $data['$entity.terms'] = ['value' => $this->terms ?: ' ', 'label' => ctrans('texts.credit_terms')]; $data['$terms'] = &$data['$entity.terms']; - $data['$view_link'] = ['value' => ''. ctrans('texts.view_credit').'', 'label' => ctrans('texts.view_credit')]; + // $data['$view_link'] = ['value' => ''. ctrans('texts.view_credit').'', 'label' => ctrans('texts.view_credit')]; + $data['$view_link'] = ['value' => $invitation->getLink(), 'label' => ctrans('texts.view_credit')]; } $data['$entity_number'] = &$data['$number']; From 05ce11138eb3aac0a2e08a6887acc718cedbf99d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Aug 2020 11:06:19 +1000 Subject: [PATCH 05/16] Fixes for payment number creation for online payments --- app/PaymentDrivers/BasePaymentDriver.php | 2 +- app/PaymentDrivers/StripePaymentDriver.php | 3 +- app/Utils/HtmlEngine.php | 6 +-- database/factories/QuoteInvitationFactory.php | 10 +++++ tests/MockAccountData.php | 42 +++++++++++++++++-- 5 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 database/factories/QuoteInvitationFactory.php diff --git a/app/PaymentDrivers/BasePaymentDriver.php b/app/PaymentDrivers/BasePaymentDriver.php index 6f8ced3a6e..0585aaf2ee 100644 --- a/app/PaymentDrivers/BasePaymentDriver.php +++ b/app/PaymentDrivers/BasePaymentDriver.php @@ -268,7 +268,7 @@ class BasePaymentDriver $payment->currency_id = $this->client->getSetting('currency_id'); $payment->date = Carbon::now(); - return $payment; + return $payment->service()->applyNumber()->save(); } diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 523d9a894d..f441b6a007 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -393,9 +393,8 @@ class StripePaymentDriver extends BasePaymentDriver $payment->date = Carbon::now(); $payment->transaction_reference = $data['transaction_reference']; $payment->amount = $amount; - $payment->client->getNextPaymentNumber($this->client); $payment->save(); - return $payment; + return $payment->service()->applyNumber()->save(); } } diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 4984ce42b5..5ed126eee4 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -123,7 +123,7 @@ class HtmlEngine $data['$entity.terms'] = ['value' => $this->entity->terms ?: ' ', 'label' => ctrans('texts.invoice_terms')]; $data['$terms'] = &$data['$entity.terms']; // $data['$view_link'] = ['value' => ''. ctrans('texts.view_invoice').'', 'label' => ctrans('texts.view_invoice')]; - $data['$view_link'] = ['value' => $invitation->getLink(), 'label' => ctrans('texts.view_invoice')]; + $data['$view_link'] = ['value' => $this->invitation->getLink(), 'label' => ctrans('texts.view_invoice')]; } @@ -133,7 +133,7 @@ class HtmlEngine $data['$entity.terms'] = ['value' => $this->entity->terms ?: ' ', 'label' => ctrans('texts.quote_terms')]; $data['$terms'] = &$data['$entity.terms']; // $data['$view_link'] = ['value' => ''. ctrans('texts.view_quote').'', 'label' => ctrans('texts.view_quote')]; - $data['$view_link'] = ['value' => $invitation->getLink(), 'label' => ctrans('texts.view_quote')]; + $data['$view_link'] = ['value' => $this->invitation->getLink(), 'label' => ctrans('texts.view_quote')]; } if ($this->entity_string == 'credit') { @@ -142,7 +142,7 @@ class HtmlEngine $data['$entity.terms'] = ['value' => $this->entity->terms ?: ' ', 'label' => ctrans('texts.credit_terms')]; $data['$terms'] = &$data['$entity.terms']; // $data['$view_link'] = ['value' => ''. ctrans('texts.view_credit').'', 'label' => ctrans('texts.view_credit')]; - $data['$view_link'] = ['value' => $invitation->getLink(), 'label' => ctrans('texts.view_credit')]; + $data['$view_link'] = ['value' => $this->invitation->getLink(), 'label' => ctrans('texts.view_credit')]; } $data['$entity_number'] = &$data['$number']; diff --git a/database/factories/QuoteInvitationFactory.php b/database/factories/QuoteInvitationFactory.php new file mode 100644 index 0000000000..2cf3b27210 --- /dev/null +++ b/database/factories/QuoteInvitationFactory.php @@ -0,0 +1,10 @@ +define(App\Models\QuoteInvitation::class, function (Faker $faker) { + return [ + 'key' => Str::random(40), + ]; +}); diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php index dc9b397d25..d2a9df1219 100644 --- a/tests/MockAccountData.php +++ b/tests/MockAccountData.php @@ -154,7 +154,7 @@ trait MockAccountData ]); - $contact = factory(\App\Models\ClientContact::class, 1)->create([ + $contact = factory(\App\Models\ClientContact::class)->create([ 'user_id' => $this->user->id, 'client_id' => $this->client->id, 'company_id' => $this->company->id, @@ -162,12 +162,13 @@ trait MockAccountData 'send_email' => true, ]); - $contact2 = factory(\App\Models\ClientContact::class, 1)->create([ + $contact2 = factory(\App\Models\ClientContact::class)->create([ 'user_id' => $this->user->id, 'client_id' => $this->client->id, 'company_id' => $this->company->id, 'send_email' => true ]); + // $rels = collect($contact, $contact2); // $this->client->setRelation('contacts', $rels); @@ -211,7 +212,24 @@ trait MockAccountData $this->invoice->save(); - $this->invoice->service()->createInvitations()->markSent(); + //$this->invoice->service()->createInvitations()->markSent(); + //$this->invoice->service()->createInvitations(); + + factory(\App\Models\InvoiceInvitation::class)->create([ + 'user_id' => $this->user->id, + 'company_id' => $this->company->id, + 'client_contact_id' => $contact->id, + 'invoice_id' => $this->invoice->id, + ]); + + factory(\App\Models\InvoiceInvitation::class)->create([ + 'user_id' => $this->user->id, + 'company_id' => $this->company->id, + 'client_contact_id' => $contact2->id, + 'invoice_id' => $this->invoice->id, + ]); + + $this->invoice->service()->markSent(); $this->quote = factory(\App\Models\Quote::class)->create([ 'user_id' => $this->user->id, @@ -229,8 +247,24 @@ trait MockAccountData $this->quote = $this->quote_calc->getQuote(); + $this->quote->status_id = Quote::STATUS_SENT; $this->quote->number = $this->getNextQuoteNumber($this->client); - $this->quote->service()->createInvitations()->markSent(); + + //$this->quote->service()->createInvitations()->markSent(); + + factory(\App\Models\QuoteInvitation::class)->create([ + 'user_id' => $this->user->id, + 'company_id' => $this->company->id, + 'client_contact_id' => $contact->id, + 'quote_id' => $this->quote->id, + ]); + + factory(\App\Models\QuoteInvitation::class)->create([ + 'user_id' => $this->user->id, + 'company_id' => $this->company->id, + 'client_contact_id' => $contact2->id, + 'quote_id' => $this->quote->id, + ]); $this->quote->setRelation('client', $this->client); $this->quote->setRelation('company', $this->company); From 4a14206e843f956c0ad0200e9875752294751da0 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Aug 2020 11:49:33 +1000 Subject: [PATCH 06/16] Fixes for tests" --- tests/Integration/MultiDBUserTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Integration/MultiDBUserTest.php b/tests/Integration/MultiDBUserTest.php index 91bf4ac66f..29220cdd5c 100644 --- a/tests/Integration/MultiDBUserTest.php +++ b/tests/Integration/MultiDBUserTest.php @@ -204,7 +204,8 @@ class MultiDBUserTest extends TestCase $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, - ])->post('/api/v1/users?include=company_user', $data); + 'X-API-PASSWORD' => 'ALongAndBriliantPassword', + ])->post('/api/v1/users?include=company_user', $data); } catch (ValidationException $e) { \Log::error('in the validator'); $message = json_decode($e->validator->getMessageBag(), 1); From c5d093232c81f0fc21501893ad487c954cb64644 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Aug 2020 12:37:17 +1000 Subject: [PATCH 07/16] Working on payment records from online payments --- app/PaymentDrivers/Stripe/Charge.php | 2 +- app/Repositories/PaymentRepository.php | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/PaymentDrivers/Stripe/Charge.php b/app/PaymentDrivers/Stripe/Charge.php index 38aa4d0b3d..ca3668922e 100644 --- a/app/PaymentDrivers/Stripe/Charge.php +++ b/app/PaymentDrivers/Stripe/Charge.php @@ -160,7 +160,7 @@ class Charge return false; $payment_method_type = $response->charges->data[0]->payment_method_details->card->brand; - info($payment_method_type); + //info($payment_method_type); $data = [ 'gateway_type_id' => $cgt->gateway_type_id, diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 92ef24d248..9e30c9f212 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -71,8 +71,6 @@ class PaymentRepository extends BaseRepository private function applyPayment(array $data, Payment $payment): ?Payment { -info(print_r($data,1)); - //check currencies here and fill the exchange rate data if necessary if (!$payment->id) { $this->processExchangeRates($data, $payment); @@ -149,10 +147,10 @@ info(print_r($data,1)); event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); -/*info("invoice totals = {$invoice_totals}"); -info("credit totals = {$credit_totals}"); -info("applied totals = " . array_sum(array_column($data['invoices'], 'amount'))); -*/ + /*info("invoice totals = {$invoice_totals}"); + info("credit totals = {$credit_totals}"); + info("applied totals = " . array_sum(array_column($data['invoices'], 'amount'))); + */ //$invoice_totals -= $credit_totals; ////$payment->amount = $invoice_totals; //creates problems when setting amount like this. From 7b2e60a0d50a150da3ffbb1443aa366c0e4beae6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Aug 2020 12:44:25 +1000 Subject: [PATCH 08/16] Add amount column to history table --- app/Http/Controllers/MigrationController.php | 2 ++ app/Repositories/ActivityRepository.php | 1 + app/Transformers/CreditTransformer.php | 1 - app/Transformers/QuoteTransformer.php | 1 - ...2020_08_18_140557_add_is_public_to_documents_table.php | 8 +++++--- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/MigrationController.php b/app/Http/Controllers/MigrationController.php index 955e4b3b7a..1e1b363c6d 100644 --- a/app/Http/Controllers/MigrationController.php +++ b/app/Http/Controllers/MigrationController.php @@ -147,6 +147,8 @@ class MigrationController extends BaseController { $company->clients()->delete(); + $company->products()->delete(); + $company->save(); return response()->json(['message' => 'Settings preserved'], 200); diff --git a/app/Repositories/ActivityRepository.php b/app/Repositories/ActivityRepository.php index 0875bcbb87..d66fdca933 100644 --- a/app/Repositories/ActivityRepository.php +++ b/app/Repositories/ActivityRepository.php @@ -69,6 +69,7 @@ class ActivityRepository extends BaseRepository if (get_class($entity) == Invoice::class || get_class($entity) == Quote::class || get_class($entity) == Credit::class){ $contact = $entity->client->primary_contact()->first(); $backup->html_backup = $this->generateEntityHtml($entity->getEntityDesigner(), $entity, $contact); + $backup->amount = $entity->amount; } $backup->activity_id = $activity->id; diff --git a/app/Transformers/CreditTransformer.php b/app/Transformers/CreditTransformer.php index 988e5f1329..f9bf7ff616 100644 --- a/app/Transformers/CreditTransformer.php +++ b/app/Transformers/CreditTransformer.php @@ -27,7 +27,6 @@ class CreditTransformer extends EntityTransformer protected $defaultIncludes = [ 'invitations', 'documents', - 'history', ]; protected $availableIncludes = [ diff --git a/app/Transformers/QuoteTransformer.php b/app/Transformers/QuoteTransformer.php index b20f6f95bf..7621b80d8d 100644 --- a/app/Transformers/QuoteTransformer.php +++ b/app/Transformers/QuoteTransformer.php @@ -27,7 +27,6 @@ class QuoteTransformer extends EntityTransformer protected $defaultIncludes = [ 'invitations', 'documents', - 'history' ]; protected $availableIncludes = [ diff --git a/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php b/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php index f5d7664aef..382ccf679f 100644 --- a/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php +++ b/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php @@ -16,6 +16,10 @@ class AddIsPublicToDocumentsTable extends Migration Schema::table('documents', function (Blueprint $table) { $table->boolean('is_public')->default(false); }); + + Schema::table('backups', function (Blueprint $table) { + $table->decimal('amount', 16, 4); + }); } /** @@ -25,8 +29,6 @@ class AddIsPublicToDocumentsTable extends Migration */ public function down() { - Schema::table('documents', function (Blueprint $table) { - $table->dropColumn('is_public'); - }); + } } From b2d5a8b070aaf01f6e6a69770de64fdd402afbaa Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Aug 2020 12:55:58 +1000 Subject: [PATCH 09/16] Fixes for bulk emailing quotes --- app/Jobs/Quote/EmailQuote.php | 2 +- app/Services/Quote/SendEmail.php | 4 +++- app/Transformers/InvoiceHistoryTransformer.php | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Jobs/Quote/EmailQuote.php b/app/Jobs/Quote/EmailQuote.php index 58a1193e2f..407157a4ad 100644 --- a/app/Jobs/Quote/EmailQuote.php +++ b/app/Jobs/Quote/EmailQuote.php @@ -60,7 +60,7 @@ class EmailQuote implements ShouldQueue return $this->logMailError(Mail::failures()); } - $this->quote_invitation->quote->markSent()->save(); + $this->quote_invitation->quote->service()->markSent()->save(); } diff --git a/app/Services/Quote/SendEmail.php b/app/Services/Quote/SendEmail.php index 7444131368..75203fb6bb 100644 --- a/app/Services/Quote/SendEmail.php +++ b/app/Services/Quote/SendEmail.php @@ -39,7 +39,7 @@ class SendEmail * @param string $this->reminder_template The template name ie reminder1 * @return array */ - public function run(): array + public function run() { if (!$this->reminder_template) { $this->reminder_template = $this->quote->calculateTemplate(); @@ -52,5 +52,7 @@ class SendEmail EmailQuote::dispatchNow($email_builder, $invitation); } }); + + $this->quote->service()->markSent(); } } diff --git a/app/Transformers/InvoiceHistoryTransformer.php b/app/Transformers/InvoiceHistoryTransformer.php index d9f2fa0198..44d2d3574d 100644 --- a/app/Transformers/InvoiceHistoryTransformer.php +++ b/app/Transformers/InvoiceHistoryTransformer.php @@ -35,6 +35,7 @@ class InvoiceHistoryTransformer extends EntityTransformer 'activity_id' => $this->encodePrimaryKey($backup->activity_id), 'json_backup' => (string) $backup->json_backup ?: '', 'html_backup' => (string) $backup->html_backup ?: '', + 'amount' => (float) $backup->amount, 'created_at' => (int)$backup->created_at, 'updated_at' => (int)$backup->updated_at, ]; From 92036b74af203b78226d021e34dac5f9259b7a9e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Aug 2020 13:08:25 +1000 Subject: [PATCH 10/16] Add exchange_rate to entities --- app/Utils/SystemHealth.php | 9 ++++----- ..._18_140557_add_is_public_to_documents_table.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/Utils/SystemHealth.php b/app/Utils/SystemHealth.php index c4cc4e60c1..07aa4d698f 100644 --- a/app/Utils/SystemHealth.php +++ b/app/Utils/SystemHealth.php @@ -82,12 +82,12 @@ class SystemHealth exec('node -v', $foo, $exitCode); if ($exitCode === 0) { - return $foo[0]; + return empty($foo[0]) ? 'Found node, but no version information' : $foo[0]; } } catch (\Exception $e) { - return false; + return false; } } @@ -98,12 +98,11 @@ class SystemHealth exec('npm -v', $foo, $exitCode); if ($exitCode === 0) { - return $foo[0]; + return empty($foo[0]) ? 'Found npm, but no version information' : $foo[0]; } }catch (\Exception $e) { - - return false; + return false; } } diff --git a/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php b/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php index 382ccf679f..61b2b88e07 100644 --- a/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php +++ b/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php @@ -13,6 +13,7 @@ class AddIsPublicToDocumentsTable extends Migration */ public function up() { + Schema::table('documents', function (Blueprint $table) { $table->boolean('is_public')->default(false); }); @@ -20,6 +21,19 @@ class AddIsPublicToDocumentsTable extends Migration Schema::table('backups', function (Blueprint $table) { $table->decimal('amount', 16, 4); }); + + Schema::table('invoices', function (Blueprint $table) { + $table->decimal('exchange_rate', 16, 4); + }); + + Schema::table('quotes', function (Blueprint $table) { + $table->decimal('exchange_rate', 16, 4); + }); + + Schema::table('credits', function (Blueprint $table) { + $table->decimal('exchange_rate', 16, 4); + }); + } /** From 9215f895c2180e67a8dd2bccf0715fe31d5a6c18 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Aug 2020 13:19:55 +1000 Subject: [PATCH 11/16] Fixes for exchange rate --- app/Transformers/CreditTransformer.php | 1 + app/Transformers/InvoiceTransformer.php | 1 + app/Transformers/QuoteTransformer.php | 2 +- ...08_18_140557_add_is_public_to_documents_table.php | 12 ------------ 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/app/Transformers/CreditTransformer.php b/app/Transformers/CreditTransformer.php index f9bf7ff616..b0bc6f720e 100644 --- a/app/Transformers/CreditTransformer.php +++ b/app/Transformers/CreditTransformer.php @@ -135,6 +135,7 @@ class CreditTransformer extends EntityTransformer 'custom_surcharge_tax4' => (bool) $credit->custom_surcharge_tax4, 'line_items' => $credit->line_items ?: (array)[], 'entity_type' => 'credit', + 'exchange_rate' => (float)$credit->exchange_rate, ]; } } diff --git a/app/Transformers/InvoiceTransformer.php b/app/Transformers/InvoiceTransformer.php index eeb7fe76a7..c6737e568e 100644 --- a/app/Transformers/InvoiceTransformer.php +++ b/app/Transformers/InvoiceTransformer.php @@ -135,6 +135,7 @@ class InvoiceTransformer extends EntityTransformer 'custom_surcharge2' => (float)$invoice->custom_surcharge2, 'custom_surcharge3' => (float)$invoice->custom_surcharge3, 'custom_surcharge4' => (float)$invoice->custom_surcharge4, + 'exchange_rate' => (float)$invoice->exchange_rate, 'custom_surcharge_tax1' => (bool) $invoice->custom_surcharge_tax1, 'custom_surcharge_tax2' => (bool) $invoice->custom_surcharge_tax2, 'custom_surcharge_tax3' => (bool) $invoice->custom_surcharge_tax3, diff --git a/app/Transformers/QuoteTransformer.php b/app/Transformers/QuoteTransformer.php index 7621b80d8d..14e5ba270c 100644 --- a/app/Transformers/QuoteTransformer.php +++ b/app/Transformers/QuoteTransformer.php @@ -134,7 +134,7 @@ class QuoteTransformer extends EntityTransformer 'custom_surcharge_taxes' => (bool) $quote->custom_surcharge_taxes, 'line_items' => $quote->line_items ?: (array)[], 'entity_type' => 'quote', - + 'exchange_rate' => (float)$quote->exchange_rate, ]; } } diff --git a/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php b/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php index 61b2b88e07..dd77f31a39 100644 --- a/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php +++ b/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php @@ -22,18 +22,6 @@ class AddIsPublicToDocumentsTable extends Migration $table->decimal('amount', 16, 4); }); - Schema::table('invoices', function (Blueprint $table) { - $table->decimal('exchange_rate', 16, 4); - }); - - Schema::table('quotes', function (Blueprint $table) { - $table->decimal('exchange_rate', 16, 4); - }); - - Schema::table('credits', function (Blueprint $table) { - $table->decimal('exchange_rate', 16, 4); - }); - } /** From 2975adc0e556ccd77d58c215f5ed0055c9ae1f28 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Aug 2020 14:48:37 +1000 Subject: [PATCH 12/16] Reconfigure the way we pass Sentry DSN --- config/ninja.php | 1 + config/sentry.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/config/ninja.php b/config/ninja.php index 358d25949a..47c255d610 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -30,6 +30,7 @@ return [ 'phantomjs_key' => env('PHANTOMJS_KEY', false), 'phantomjs_secret' => env('PHANTOMJS_SECRET', false), + 'sentry_dsn' => env('SENTRY_LARAVEL_DSN', 'https://b36c3ae4f26b45689bc3d4e3774fb303@sentry.invoicing.co/4'), 'environment' => env('NINJA_ENVIRONMENT', 'selfhost'), // 'hosted', 'development', 'selfhost', 'reseller' // Settings used by invoiceninja.com diff --git a/config/sentry.php b/config/sentry.php index e428cbbce5..2669e086fa 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -2,8 +2,8 @@ return [ - 'dsn' => env('SENTRY_LARAVEL_DSN', env('SENTRY_DSN')), - + //'dsn' => env('SENTRY_LARAVEL_DSN', env('SENTRY_DSN')), + 'dsn' => config('ninja.sentry_dsn'), // capture release as git sha // 'release' => trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')), From 14983479d3c29e88f3e8203eb51218677cea5ccc Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Aug 2020 15:24:35 +1000 Subject: [PATCH 13/16] Add auto-bill to company settings " git push --- app/DataMapper/CompanySettings.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index a968cbc5b2..29be490f1f 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -109,6 +109,8 @@ class CompanySettings extends BaseSettings public $reset_counter_date = ''; public $counter_padding = 4; + public $auto_bill = 'off'; //off,always,optin,optout + public $design = 'views/pdf/design1.blade.php'; public $invoice_terms = ''; @@ -237,6 +239,7 @@ class CompanySettings extends BaseSettings public $client_portal_privacy_policy = ''; public static $casts = [ + 'auto_bill' => 'auto_bill', 'lock_invoices' => 'string', 'client_portal_terms' => 'string', 'client_portal_privacy_policy' => 'string', From ca99a66390cf99d4b1a4aecc16ec9acfe8fa205f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Aug 2020 16:09:01 +1000 Subject: [PATCH 14/16] Fixes for tests --- app/DataMapper/CompanySettings.php | 2 +- .../2020_08_18_140557_add_is_public_to_documents_table.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index 29be490f1f..83efe7d0d7 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -239,7 +239,7 @@ class CompanySettings extends BaseSettings public $client_portal_privacy_policy = ''; public static $casts = [ - 'auto_bill' => 'auto_bill', + 'auto_bill' => 'string', 'lock_invoices' => 'string', 'client_portal_terms' => 'string', 'client_portal_privacy_policy' => 'string', diff --git a/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php b/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php index dd77f31a39..dd221a448b 100644 --- a/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php +++ b/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php @@ -22,6 +22,9 @@ class AddIsPublicToDocumentsTable extends Migration $table->decimal('amount', 16, 4); }); + Schema::table('company_gateways', function (Blueprint $table) { + $table->string('token_billing')->default('off'); + }); } /** From 77ecca30355ce69efd3b167cb5ea60f92a68d5cf Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Aug 2020 16:11:57 +1000 Subject: [PATCH 15/16] fixes for tests --- app/Models/CompanyGateway.php | 1 + app/Models/Document.php | 1 + .../2020_08_18_140557_add_is_public_to_documents_table.php | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 5c6d1628ca..3a086b51b1 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -43,6 +43,7 @@ class CompanyGateway extends BaseModel 'custom_value2', 'custom_value3', 'custom_value4', + 'token_billing', ]; public static $credit_cards = [ diff --git a/app/Models/Document.php b/app/Models/Document.php index ed62e2bc75..b0281b95e7 100644 --- a/app/Models/Document.php +++ b/app/Models/Document.php @@ -26,6 +26,7 @@ class Document extends BaseModel */ protected $fillable = [ 'is_default', + 'is_public', ]; diff --git a/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php b/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php index dd221a448b..7cc0fbb260 100644 --- a/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php +++ b/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php @@ -23,7 +23,7 @@ class AddIsPublicToDocumentsTable extends Migration }); Schema::table('company_gateways', function (Blueprint $table) { - $table->string('token_billing')->default('off'); + $table->enum('token_billing', ['off', 'always','optin','optout'])->default('off'); }); } From c1da36477e25bec66ff298ee1b69f9075a0ae8e7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Aug 2020 16:35:35 +1000 Subject: [PATCH 16/16] Exclude some errors from reporting --- app/Exceptions/Handler.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index ba18615979..444bd6fb7a 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -37,6 +37,9 @@ class Handler extends ExceptionHandler */ protected $dontReport = [ \PDOException::class, + \Swift_TransportException::class, + \Illuminate\Queue\MaxAttemptsExceededException::class, + \Symfony\Component\Console\Exception\CommandNotFoundException::class ]; /**