diff --git a/app/Factory/CloneQuoteToInvoiceFactory.php b/app/Factory/CloneQuoteToInvoiceFactory.php index 086b6db742c5..b04b8104253d 100644 --- a/app/Factory/CloneQuoteToInvoiceFactory.php +++ b/app/Factory/CloneQuoteToInvoiceFactory.php @@ -29,7 +29,7 @@ class CloneQuoteToInvoiceFactory unset($quote_array['id']); unset($quote_array['invitations']); unset($quote_array['terms']); - unset($quote_array['public_notes']); + // unset($quote_array['public_notes']); unset($quote_array['footer']); unset($quote_array['design_id']); diff --git a/app/Helpers/Invoice/InvoiceSum.php b/app/Helpers/Invoice/InvoiceSum.php index da45f65a7ca8..c48f426567fc 100644 --- a/app/Helpers/Invoice/InvoiceSum.php +++ b/app/Helpers/Invoice/InvoiceSum.php @@ -203,7 +203,7 @@ class InvoiceSum { //Build invoice values here and return Invoice $this->setCalculatedAttributes(); - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } @@ -211,7 +211,7 @@ class InvoiceSum public function getQuote() { $this->setCalculatedAttributes(); - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } @@ -219,7 +219,7 @@ class InvoiceSum public function getCredit() { $this->setCalculatedAttributes(); - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } @@ -230,7 +230,7 @@ class InvoiceSum $this->invoice->total_taxes = $this->getTotalTaxes(); $this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision); - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } diff --git a/app/Helpers/Invoice/InvoiceSumInclusive.php b/app/Helpers/Invoice/InvoiceSumInclusive.php index 49a0b5593da5..fe0b26268be5 100644 --- a/app/Helpers/Invoice/InvoiceSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceSumInclusive.php @@ -191,7 +191,7 @@ class InvoiceSumInclusive $this->invoice->total_taxes = $this->getTotalTaxes(); $this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision); - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } @@ -206,7 +206,7 @@ class InvoiceSumInclusive { //Build invoice values here and return Invoice $this->setCalculatedAttributes(); - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } @@ -215,7 +215,7 @@ class InvoiceSumInclusive { //Build invoice values here and return Invoice $this->setCalculatedAttributes(); - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } @@ -224,7 +224,7 @@ class InvoiceSumInclusive { //Build invoice values here and return Invoice $this->setCalculatedAttributes(); - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } diff --git a/app/Http/Controllers/RecurringInvoiceController.php b/app/Http/Controllers/RecurringInvoiceController.php index f88a07ccabae..03bbe94cfffd 100644 --- a/app/Http/Controllers/RecurringInvoiceController.php +++ b/app/Http/Controllers/RecurringInvoiceController.php @@ -208,7 +208,7 @@ class RecurringInvoiceController extends BaseController $offset = $recurring_invoice->client->timezone_offset(); $recurring_invoice->next_send_date = Carbon::parse($recurring_invoice->next_send_date)->startOfDay()->addSeconds($offset); - $recurring_invoice->save(); + $recurring_invoice->saveQuietly(); $recurring_invoice->service() ->triggeredActions($request) diff --git a/app/Http/Livewire/RecurringInvoices/UpdateAutoBilling.php b/app/Http/Livewire/RecurringInvoices/UpdateAutoBilling.php index dfcd3d771730..3c6424c46c1f 100644 --- a/app/Http/Livewire/RecurringInvoices/UpdateAutoBilling.php +++ b/app/Http/Livewire/RecurringInvoices/UpdateAutoBilling.php @@ -23,7 +23,7 @@ class UpdateAutoBilling extends Component { if ($this->invoice->auto_bill == 'optin' || $this->invoice->auto_bill == 'optout') { $this->invoice->auto_bill_enabled = !$this->invoice->auto_bill_enabled; - $this->invoice->save(); + $this->invoice->saveQuietly(); } } diff --git a/app/Http/Middleware/SetInviteDb.php b/app/Http/Middleware/SetInviteDb.php index 11bea4528342..a86fea3f0f69 100644 --- a/app/Http/Middleware/SetInviteDb.php +++ b/app/Http/Middleware/SetInviteDb.php @@ -13,6 +13,7 @@ namespace App\Http\Middleware; use App\Libraries\MultiDB; use Closure; +use Hashids\Hashids; use Illuminate\Http\Request; use stdClass; @@ -45,6 +46,30 @@ class SetInviteDb if($entity == "pay") $entity = "invoice"; + /* Try and determine the DB from the invitation key STRING*/ + if (config('ninja.db.multi_db_enabled')) { + + // nlog("/ Try and determine the DB from the invitation key /"); + + $hashids = new Hashids(config('ninja.hash_salt'), 10); + $segments = explode('-', $request->route('invitation_key')); + $hashed_db = false; + + if(is_array($segments)){ + $hashed_db = $hashids->decode($segments[0]); + } + + if(is_array($hashed_db)){ + + MultiDB::setDB(MultiDB::DB_PREFIX.str_pad($hashed_db[0], 2, '0', STR_PAD_LEFT)); + + return $next($request); + + } + + } + + /* Attempt to set DB from invitatation key*/ if ($request->getSchemeAndHttpHost() && config('ninja.db.multi_db_enabled') && ! MultiDB::findAndSetDbByInvitation($entity, $request->route('invitation_key'))) { if (request()->json) { return response()->json($error, 403); diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php index f545db11aadb..b7660e7bcb99 100644 --- a/app/Jobs/Entity/CreateEntityPdf.php +++ b/app/Jobs/Entity/CreateEntityPdf.php @@ -101,7 +101,9 @@ class CreateEntityPdf implements ShouldQueue public function handle() { - + $start = microtime(true); + // nlog("Start ". $start); + /* Forget the singleton*/ App::forgetInstance('translator'); @@ -113,6 +115,9 @@ class CreateEntityPdf implements ShouldQueue /* Set customized translations _NOW_ */ $t->replace(Ninja::transformTranslations($this->client->getMergedSettings())); + $translate = microtime(true); + // nlog("Translate ". $translate - $start); + if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') { return (new Phantom)->generate($this->invitation); } @@ -148,6 +153,9 @@ class CreateEntityPdf implements ShouldQueue $html = new HtmlEngine($this->invitation); + $design_time = microtime(true); + // nlog("Design ". $design_time - $translate); + if ($design->is_custom) { $options = [ 'custom_partials' => json_decode(json_encode($design->design), true) @@ -159,6 +167,9 @@ class CreateEntityPdf implements ShouldQueue $variables = $html->generateLabelsAndValues(); + $labels_time = microtime(true); + // nlog("Labels ". $labels_time - $design_time); + $state = [ 'template' => $template->elements([ 'client' => $this->client, @@ -181,6 +192,10 @@ class CreateEntityPdf implements ShouldQueue ->design($template) ->build(); + + $template_time = microtime(true); + // nlog("Template Build ". $template_time - $labels_time); + $pdf = null; try { @@ -201,6 +216,9 @@ class CreateEntityPdf implements ShouldQueue } + $pdf_time = microtime(true); + // nlog("PDF time " . $pdf_time - $template_time); + if ($pdf) { try{ diff --git a/app/Jobs/Quote/CreateQuoteInvitations.php b/app/Jobs/Quote/CreateQuoteInvitations.php deleted file mode 100644 index f55ae6820131..000000000000 --- a/app/Jobs/Quote/CreateQuoteInvitations.php +++ /dev/null @@ -1,68 +0,0 @@ -quote = $quote; - - $this->company = $company; - } - - public function handle() - { - MultiDB::setDB($this->company->db); - - $contacts = $this->quote->client->contacts; - - $contacts->each(function ($contact) { - $invitation = QuoteInvitation::whereCompanyId($this->quote->company_id) - ->whereClientContactId($contact->id) - ->whereQuoteId($this->quote->id) - ->first(); - - if (! $invitation && $contact->send) { - $ii = QuoteInvitationFactory::create($this->quote->company_id, $this->quote->user_id); - $ii->quote_id = $this->quote->id; - $ii->client_contact_id = $contact->id; - $ii->save(); - } elseif ($invitation && ! $contact->send) { - $invitation->delete(); - } - }); - } -} diff --git a/app/Jobs/Util/WebhookHandler.php b/app/Jobs/Util/WebhookHandler.php index 5b5a72019b7f..38cafd03bb4c 100644 --- a/app/Jobs/Util/WebhookHandler.php +++ b/app/Jobs/Util/WebhookHandler.php @@ -43,18 +43,19 @@ class WebhookHandler implements ShouldQueue public $deleteWhenMissingModels = true; - + private string $includes; /** * Create a new job instance. * * @param $event_id * @param $entity */ - public function __construct($event_id, $entity, $company) + public function __construct($event_id, $entity, $company, $includes = '') { $this->event_id = $event_id; $this->entity = $entity; $this->company = $company; + $this->includes = $includes; } /** @@ -90,6 +91,7 @@ class WebhookHandler implements ShouldQueue // generate JSON data $manager = new Manager(); $manager->setSerializer(new ArraySerializer()); + $manager->parseIncludes($this->includes); $class = sprintf('App\\Transformers\\%sTransformer', class_basename($this->entity)); diff --git a/app/Libraries/MultiDB.php b/app/Libraries/MultiDB.php index 48d95d781d61..07d0cd0f7868 100644 --- a/app/Libraries/MultiDB.php +++ b/app/Libraries/MultiDB.php @@ -332,7 +332,7 @@ class MultiDB $current_db = config('database.default'); foreach (self::$dbs as $db) { - if ($invite = $class::on($db)->whereRaw('BINARY `key`= ?', [$invitation_key])->exists()) { + if ($invite = $class::on($db)->where('key', $invitation_key)->exists()) { self::setDb($db); return true; } diff --git a/app/Listeners/Credit/CreateCreditInvitation.php b/app/Listeners/Credit/CreateCreditInvitation.php deleted file mode 100644 index 8e9af99e0dd4..000000000000 --- a/app/Listeners/Credit/CreateCreditInvitation.php +++ /dev/null @@ -1,51 +0,0 @@ -company->db); - - $credit = $event->credit; - - $contacts = $credit->client->contacts; - - $contacts->each(function ($contact) use ($credit) { - $invitation = CreditInvitation::whereCompanyId($credit->company_id) - ->whereClientContactId($contact->id) - ->whereCreditId($credit->id) - ->first(); - - if (! $invitation && $contact->send_credit) { - $ii = CreditInvitationFactory::create($credit->company_id, $credit->user_id); - $ii->credit_id = $credit->id; - $ii->client_contact_id = $contact->id; - $ii->save(); - } elseif ($invitation && ! $contact->send_credit) { - $invitation->delete(); - } - }); - } -} diff --git a/app/Listeners/Invoice/CreateInvoiceInvitation.php b/app/Listeners/Invoice/CreateInvoiceInvitation.php deleted file mode 100644 index d5f5de83e783..000000000000 --- a/app/Listeners/Invoice/CreateInvoiceInvitation.php +++ /dev/null @@ -1,51 +0,0 @@ -company->db); - - $invoice = $event->invoice; - - $contacts = $invoice->client->contacts; - - $contacts->each(function ($contact) use ($invoice) { - $invitation = InvoiceInvitation::whereCompanyId($invoice->company_id) - ->whereClientContactId($contact->id) - ->whereInvoiceId($invoice->id) - ->first(); - - if (! $invitation && $contact->send) { - $ii = InvoiceInvitationFactory::create($invoice->company_id, $invoice->user_id); - $ii->invoice_id = $invoice->id; - $ii->client_contact_id = $contact->id; - $ii->save(); - } elseif ($invitation && ! $contact->send) { - $invitation->delete(); - } - }); - } -} diff --git a/app/Listeners/Quote/CreateQuoteInvitation.php b/app/Listeners/Quote/CreateQuoteInvitation.php index b057e0874eb0..fa71ba6440a2 100644 --- a/app/Listeners/Quote/CreateQuoteInvitation.php +++ b/app/Listeners/Quote/CreateQuoteInvitation.php @@ -14,10 +14,13 @@ namespace App\Listeners\Quote; use App\Factory\QuoteInvitationFactory; use App\Libraries\MultiDB; use App\Models\QuoteInvitation; +use App\Utils\Traits\MakesHash; use Illuminate\Contracts\Queue\ShouldQueue; class CreateQuoteInvitation implements ShouldQueue { + use MakesHash; + /** * Handle the event. * @@ -40,6 +43,7 @@ class CreateQuoteInvitation implements ShouldQueue if (! $invitation && $contact->send_credit) { $ii = QuoteInvitationFactory::create($quote->company_id, $quote->user_id); + $ii->key = $this->createDbHash(config('database.default')); $ii->quote_id = $quote->id; $ii->client_contact_id = $contact->id; $ii->save(); diff --git a/app/Mail/Engine/PaymentEmailEngine.php b/app/Mail/Engine/PaymentEmailEngine.php index b0b7a43dabe2..f2fd269c42d6 100644 --- a/app/Mail/Engine/PaymentEmailEngine.php +++ b/app/Mail/Engine/PaymentEmailEngine.php @@ -239,10 +239,20 @@ class PaymentEmailEngine extends BaseEmailEngine $data['$invoices'] = ['value' => $this->formatInvoices(), 'label' => ctrans('texts.invoices')]; $data['$invoice_references'] = ['value' => $this->formatInvoiceReferences(), 'label' => ctrans('texts.invoices')]; - + $data['$invoice'] = ['value' => $this->formatInvoice(), 'label' => ctrans('texts.invoices')]; return $data; } + private function formatInvoice() + { + $invoice = ''; + + if($this->payment->invoices()->exists()) + $invoice = ctrans('texts.invoice_number_short') . implode(",", $this->payment->invoices->pluck('number')->toArray()); + + return $invoice; + } + private function formatInvoices() { $invoice_list = '

'; diff --git a/app/Models/Presenters/CompanyPresenter.php b/app/Models/Presenters/CompanyPresenter.php index 44dd0572275b..371c2312bcbf 100644 --- a/app/Models/Presenters/CompanyPresenter.php +++ b/app/Models/Presenters/CompanyPresenter.php @@ -72,7 +72,6 @@ class CompanyPresenter extends EntityPresenter else return "data:image/png;base64, ". base64_encode(file_get_contents(asset('images/new_logo.png'), false, stream_context_create($context_options))); - } public function address($settings = null) diff --git a/app/Observers/InvoiceObserver.php b/app/Observers/InvoiceObserver.php index f58e1018f26a..d38e1509edfb 100644 --- a/app/Observers/InvoiceObserver.php +++ b/app/Observers/InvoiceObserver.php @@ -35,10 +35,8 @@ class InvoiceObserver ->exists(); if ($subscriptions) { - - $invoice->load('client'); - WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company); + WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company, 'client'); } } @@ -50,17 +48,14 @@ class InvoiceObserver */ public function updated(Invoice $invoice) { + $subscriptions = Webhook::where('company_id', $invoice->company_id) ->where('event_id', Webhook::EVENT_UPDATE_INVOICE) ->exists(); - - if ($subscriptions) { - - $invoice->load('client'); - - WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company); + + WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company, 'client'); } @@ -80,9 +75,7 @@ class InvoiceObserver if ($subscriptions) { - $invoice->load('client'); - - WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice, $invoice->company); + WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice, $invoice->company, 'client'); } } diff --git a/app/Observers/PaymentObserver.php b/app/Observers/PaymentObserver.php index 976d261c3e1c..ad2a6f7b8215 100644 --- a/app/Observers/PaymentObserver.php +++ b/app/Observers/PaymentObserver.php @@ -29,11 +29,8 @@ class PaymentObserver ->where('event_id', Webhook::EVENT_CREATE_PAYMENT) ->exists(); - if($payment->invoices()->exists()) - $payment->load('invoices'); - if ($subscriptions) { - WebhookHandler::dispatch(Webhook::EVENT_CREATE_PAYMENT, $payment, $payment->company); + WebhookHandler::dispatch(Webhook::EVENT_CREATE_PAYMENT, $payment, $payment->company, 'invoices'); } } @@ -60,7 +57,7 @@ class PaymentObserver ->exists(); if ($subscriptions) { - WebhookHandler::dispatch(Webhook::EVENT_DELETE_PAYMENT, $payment, $payment->company); + WebhookHandler::dispatch(Webhook::EVENT_DELETE_PAYMENT, $payment, $payment->company, 'invoices'); } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index ca9b7e809930..495ed33f2242 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -12,36 +12,8 @@ namespace App\Providers; use App\Http\Middleware\SetDomainNameDb; -use App\Models\Account; -use App\Models\Client; -use App\Models\Company; -use App\Models\CompanyGateway; -use App\Models\CompanyToken; -use App\Models\Credit; -use App\Models\Expense; use App\Models\Invoice; -use App\Models\Payment; -use App\Models\Product; use App\Models\Proposal; -use App\Models\Quote; -use App\Models\Subscription; -use App\Models\Task; -use App\Models\User; -use App\Observers\AccountObserver; -use App\Observers\ClientObserver; -use App\Observers\CompanyGatewayObserver; -use App\Observers\CompanyObserver; -use App\Observers\CompanyTokenObserver; -use App\Observers\CreditObserver; -use App\Observers\ExpenseObserver; -use App\Observers\InvoiceObserver; -use App\Observers\PaymentObserver; -use App\Observers\ProductObserver; -use App\Observers\ProposalObserver; -use App\Observers\QuoteObserver; -use App\Observers\SubscriptionObserver; -use App\Observers\TaskObserver; -use App\Observers\UserObserver; use App\Utils\Ninja; use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Database\Eloquent\Relations\Relation; @@ -80,23 +52,6 @@ class AppServiceProvider extends ServiceProvider Schema::defaultStringLength(191); - Account::observe(AccountObserver::class); - Subscription::observe(SubscriptionObserver::class); - Client::observe(ClientObserver::class); - Company::observe(CompanyObserver::class); - CompanyGateway::observe(CompanyGatewayObserver::class); - CompanyToken::observe(CompanyTokenObserver::class); - Credit::observe(CreditObserver::class); - Expense::observe(ExpenseObserver::class); - Invoice::observe(InvoiceObserver::class); - Payment::observe(PaymentObserver::class); - Product::observe(ProductObserver::class); - Proposal::observe(ProposalObserver::class); - Quote::observe(QuoteObserver::class); - Task::observe(TaskObserver::class); - User::observe(UserObserver::class); - - /* Handles setting the correct database with livewire classes */ if(Ninja::isHosted()) { diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index cee0ce7eaa40..52b15e64ba81 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -202,6 +202,36 @@ use App\Listeners\User\DeletedUserActivity; use App\Listeners\User\RestoredUserActivity; use App\Listeners\User\UpdateUserLastLogin; use App\Listeners\User\UpdatedUserActivity; +use App\Models\Account; +use App\Models\Client; +use App\Models\Company; +use App\Models\CompanyGateway; +use App\Models\CompanyToken; +use App\Models\Credit; +use App\Models\Expense; +use App\Models\Invoice; +use App\Models\Payment; +use App\Models\Product; +use App\Models\Proposal; +use App\Models\Quote; +use App\Models\Subscription; +use App\Models\Task; +use App\Models\User; +use App\Observers\AccountObserver; +use App\Observers\ClientObserver; +use App\Observers\CompanyGatewayObserver; +use App\Observers\CompanyObserver; +use App\Observers\CompanyTokenObserver; +use App\Observers\CreditObserver; +use App\Observers\ExpenseObserver; +use App\Observers\InvoiceObserver; +use App\Observers\PaymentObserver; +use App\Observers\ProductObserver; +use App\Observers\ProposalObserver; +use App\Observers\QuoteObserver; +use App\Observers\SubscriptionObserver; +use App\Observers\TaskObserver; +use App\Observers\UserObserver; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Illuminate\Mail\Events\MessageSending; use Illuminate\Mail\Events\MessageSent; @@ -542,5 +572,21 @@ class EventServiceProvider extends ServiceProvider public function boot() { parent::boot(); + + Account::observe(AccountObserver::class); + Subscription::observe(SubscriptionObserver::class); + Client::observe(ClientObserver::class); + Company::observe(CompanyObserver::class); + CompanyGateway::observe(CompanyGatewayObserver::class); + CompanyToken::observe(CompanyTokenObserver::class); + Credit::observe(CreditObserver::class); + Expense::observe(ExpenseObserver::class); + Invoice::observe(InvoiceObserver::class); + Payment::observe(PaymentObserver::class); + Product::observe(ProductObserver::class); + Proposal::observe(ProposalObserver::class); + Quote::observe(QuoteObserver::class); + Task::observe(TaskObserver::class); + User::observe(UserObserver::class); } } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index b4e11a655cdf..ac8c453ed81d 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -239,7 +239,7 @@ class BaseRepository /* Get array of Keys which have been removed from the invitations array and soft delete each invitation */ $model->invitations->pluck('key')->diff($invitations->pluck('key'))->each(function ($invitation) use ($resource) { $invitation_class = sprintf('App\\Models\\%sInvitation', $resource); - $invitation = $invitation_class::whereRaw('BINARY `key`= ?', [$invitation])->first(); + $invitation = $invitation_class::where('key', $invitation)->first(); if ($invitation) $invitation->delete(); @@ -276,6 +276,7 @@ class BaseRepository $new_invitation = $invitation_factory_class::create($model->company_id, $model->user_id); $new_invitation->{$lcfirst_resource_id} = $model->id; $new_invitation->client_contact_id = $contact->id; + $new_invitation->key = $this->createDbHash(config('database.default')); $new_invitation->save(); } @@ -326,6 +327,8 @@ class BaseRepository if($this->new_model) event('eloquent.created: App\Models\Invoice', $model); + else + event('eloquent.updated: App\Models\Invoice', $model); } @@ -339,6 +342,9 @@ class BaseRepository if($this->new_model) event('eloquent.created: App\Models\Credit', $model); + else + event('eloquent.updated: App\Models\Credit', $model); + } if ($model instanceof Quote) { @@ -351,7 +357,8 @@ class BaseRepository if($this->new_model) event('eloquent.created: App\Models\Quote', $model); - + else + event('eloquent.updated: App\Models\Quote', $model); } if ($model instanceof RecurringInvoice) { @@ -364,6 +371,8 @@ class BaseRepository if($this->new_model) event('eloquent.created: App\Models\RecurringInvoice', $model); + else + event('eloquent.updated: App\Models\RecurringInvoice', $model); } $model->save(); diff --git a/app/Services/Credit/CreateInvitations.php b/app/Services/Credit/CreateInvitations.php index cadc297a4b80..498ba051c99d 100644 --- a/app/Services/Credit/CreateInvitations.php +++ b/app/Services/Credit/CreateInvitations.php @@ -16,10 +16,13 @@ use App\Factory\CreditInvitationFactory; use App\Models\Credit; use App\Models\CreditInvitation; use App\Services\AbstractService; +use App\Utils\Traits\MakesHash; use Illuminate\Support\Str; class CreateInvitations extends AbstractService { + use MakesHash; + private $credit; public function __construct(Credit $credit) @@ -46,6 +49,7 @@ class CreateInvitations extends AbstractService if (! $invitation) { $ii = CreditInvitationFactory::create($this->credit->company_id, $this->credit->user_id); + $ii->key = $this->createDbHash(config('database.default')); $ii->credit_id = $this->credit->id; $ii->client_contact_id = $contact->id; $ii->save(); diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 5bbb7352c4b4..7b6bef89196b 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -356,9 +356,9 @@ class AutoBillInvoice extends AbstractService $items[] = $item; $this->invoice->line_items = $items; - $this->invoice->save(); + $this->invoice->saveQuietly(); - $this->invoice = $this->invoice->calc()->getInvoice()->save(); + $this->invoice = $this->invoice->calc()->getInvoice()->saveQuietly(); if ($starting_amount != $this->invoice->amount && $this->invoice->status_id != Invoice::STATUS_DRAFT) { $this->invoice->client->service()->updateBalance($this->invoice->amount - $starting_amount)->save(); diff --git a/app/Services/Invoice/CreateInvitations.php b/app/Services/Invoice/CreateInvitations.php index 68955711aa66..00d45257c268 100644 --- a/app/Services/Invoice/CreateInvitations.php +++ b/app/Services/Invoice/CreateInvitations.php @@ -16,10 +16,13 @@ use App\Factory\InvoiceInvitationFactory; use App\Models\Invoice; use App\Models\InvoiceInvitation; use App\Services\AbstractService; +use App\Utils\Traits\MakesHash; use Illuminate\Support\Str; class CreateInvitations extends AbstractService { + use MakesHash; + private $invoice; public function __construct(Invoice $invoice) @@ -48,6 +51,7 @@ class CreateInvitations extends AbstractService if (! $invitation && $contact->send_email) { $ii = InvoiceInvitationFactory::create($this->invoice->company_id, $this->invoice->user_id); + $ii->key = $this->createDbHash(config('database.default')); $ii->invoice_id = $this->invoice->id; $ii->client_contact_id = $contact->id; $ii->save(); @@ -61,6 +65,7 @@ class CreateInvitations extends AbstractService $contact = $this->createBlankContact(); $ii = InvoiceInvitationFactory::create($this->invoice->company_id, $this->invoice->user_id); + $ii->key = $this->createDbHash(config('database.default')); $ii->invoice_id = $this->invoice->id; $ii->client_contact_id = $contact->id; $ii->save(); diff --git a/app/Services/Invoice/HandleCancellation.php b/app/Services/Invoice/HandleCancellation.php index 872697666bb8..e380d69f7549 100644 --- a/app/Services/Invoice/HandleCancellation.php +++ b/app/Services/Invoice/HandleCancellation.php @@ -75,7 +75,7 @@ class HandleCancellation extends AbstractService $backup = $this->invoice->backup; unset($backup->cancellation); $this->invoice->backup = $backup; - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } @@ -101,6 +101,6 @@ class HandleCancellation extends AbstractService $invoice_backup->cancellation = $cancellation; $this->invoice->backup = $invoice_backup; - $this->invoice->save(); + $this->invoice->saveQuietly(); } } diff --git a/app/Services/Invoice/HandleRestore.php b/app/Services/Invoice/HandleRestore.php index e1615b3ab16f..14216f2751f1 100644 --- a/app/Services/Invoice/HandleRestore.php +++ b/app/Services/Invoice/HandleRestore.php @@ -129,7 +129,7 @@ nlog("second payment_amount = {$payment_amount}"); else $this->invoice->number = $new_invoice_number; - $this->invoice->save(); + $this->invoice->saveQuietly(); } catch (\Exception $e) { nlog("I could not wind back the invoice number"); diff --git a/app/Services/Invoice/UpdateReminder.php b/app/Services/Invoice/UpdateReminder.php index e693da6f6d21..01c9ba30549a 100644 --- a/app/Services/Invoice/UpdateReminder.php +++ b/app/Services/Invoice/UpdateReminder.php @@ -37,7 +37,7 @@ class UpdateReminder extends AbstractService if (! $this->invoice->isPayable()) { $this->invoice->next_send_date = null; - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; //exit early } diff --git a/app/Services/Payment/RefundPayment.php b/app/Services/Payment/RefundPayment.php index 6d9f8a76e1eb..2b44eae951e8 100644 --- a/app/Services/Payment/RefundPayment.php +++ b/app/Services/Payment/RefundPayment.php @@ -250,7 +250,7 @@ class RefundPayment $invoice->service()->setStatus(Invoice::STATUS_PARTIAL); } - $invoice->save(); + $invoice->saveQuietly(); $client = $invoice->client; diff --git a/app/Services/PdfMaker/PdfMaker.php b/app/Services/PdfMaker/PdfMaker.php index 55c600fe4480..ec492cf8e5a3 100644 --- a/app/Services/PdfMaker/PdfMaker.php +++ b/app/Services/PdfMaker/PdfMaker.php @@ -83,7 +83,7 @@ class PdfMaker /** * Final method to get compiled HTML. * - * @param bool $final @deprecated + * @param bool $final @deprecated // is it? i still see it being called elsewhere * @return mixed */ public function getCompiledHTML($final = false) diff --git a/app/Services/Quote/CreateInvitations.php b/app/Services/Quote/CreateInvitations.php index b2e42395e088..e5da296d758c 100644 --- a/app/Services/Quote/CreateInvitations.php +++ b/app/Services/Quote/CreateInvitations.php @@ -15,10 +15,13 @@ use App\Factory\ClientContactFactory; use App\Factory\QuoteInvitationFactory; use App\Models\Quote; use App\Models\QuoteInvitation; +use App\Utils\Traits\MakesHash; use Illuminate\Support\Str; class CreateInvitations { + use MakesHash; + public $quote; public function __construct(Quote $quote) @@ -47,6 +50,7 @@ class CreateInvitations if (! $invitation && $contact->send_email) { $ii = QuoteInvitationFactory::create($this->quote->company_id, $this->quote->user_id); + $ii->key = $this->createDbHash(config('database.default')); $ii->quote_id = $this->quote->id; $ii->client_contact_id = $contact->id; $ii->save(); diff --git a/app/Services/Recurring/CreateRecurringInvitations.php b/app/Services/Recurring/CreateRecurringInvitations.php index 4fe32521c05e..ae2692214a6c 100644 --- a/app/Services/Recurring/CreateRecurringInvitations.php +++ b/app/Services/Recurring/CreateRecurringInvitations.php @@ -12,11 +12,14 @@ namespace App\Services\Recurring; use App\Services\AbstractService; +use App\Utils\Traits\MakesHash; use Exception; use Illuminate\Support\Str; class CreateRecurringInvitations extends AbstractService { + use MakesHash; + private $entity; private $entity_name; @@ -48,6 +51,7 @@ class CreateRecurringInvitations extends AbstractService if (! $invitation && $contact->send_email) { $ii = $this->invitation_factory::create($this->entity->company_id, $this->entity->user_id); + $ii->key = $this->createDbHash(config('database.default')); $ii->{$this->entity_id_name} = $this->entity->id; $ii->client_contact_id = $contact->id; $ii->save(); diff --git a/app/Utils/Traits/MakesHash.php b/app/Utils/Traits/MakesHash.php index f453fc7bb34e..8995366405af 100644 --- a/app/Utils/Traits/MakesHash.php +++ b/app/Utils/Traits/MakesHash.php @@ -37,7 +37,10 @@ trait MakesHash */ public function createDbHash($db) : string { - return $this->getDbCode($db).'-'. Str::random(config('ninja.key_length')); + if(config('ninja.db.multi_db_enabled')) + return $this->getDbCode($db).'-'. Str::random(config('ninja.key_length')); + + return Str::random(config('ninja.key_length')); } /** diff --git a/app/Utils/Traits/MakesReminders.php b/app/Utils/Traits/MakesReminders.php index 9905379574bf..acd9a519ba31 100644 --- a/app/Utils/Traits/MakesReminders.php +++ b/app/Utils/Traits/MakesReminders.php @@ -77,9 +77,9 @@ trait MakesReminders private function checkEndlessReminder($last_sent_date, $endless_reminder_frequency_id) :bool { - nlog("endless date match = ".$this->addTimeInterval($last_sent_date, $endless_reminder_frequency_id)); - nlog("Endless reminder bool = "); - nlog(Carbon::now()->startOfDay()->eq($this->addTimeInterval($last_sent_date, $endless_reminder_frequency_id))); + // nlog("endless date match = ".$this->addTimeInterval($last_sent_date, $endless_reminder_frequency_id)); + // nlog("Endless reminder bool = "); + // nlog(Carbon::now()->startOfDay()->eq($this->addTimeInterval($last_sent_date, $endless_reminder_frequency_id))); if (Carbon::now()->startOfDay()->eq($this->addTimeInterval($last_sent_date, $endless_reminder_frequency_id))) { return true; diff --git a/config/ninja.php b/config/ninja.php index f79b4b746fc6..a6fc87778173 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -21,7 +21,7 @@ return [ 'api_secret' => env('API_SECRET', ''), 'google_maps_api_key' => env('GOOGLE_MAPS_API_KEY'), 'google_analytics_url' => env('GOOGLE_ANALYTICS_URL', 'https://www.google-analytics.com/collect'), - 'key_length' => 64, + 'key_length' => 32, 'date_format' => 'Y-m-d', 'date_time_format' => 'Y-m-d H:i', 'daily_email_limit' => 300, diff --git a/database/seeders/RandomDataSeeder.php b/database/seeders/RandomDataSeeder.php index bfe3f30c4c47..167f1b0ee4e4 100644 --- a/database/seeders/RandomDataSeeder.php +++ b/database/seeders/RandomDataSeeder.php @@ -15,8 +15,6 @@ use App\DataMapper\CompanySettings; use App\Events\Payment\PaymentWasCreated; use App\Helpers\Invoice\InvoiceSum; use App\Helpers\Invoice\InvoiceSumInclusive; -use App\Listeners\Credit\CreateCreditInvitation; -use App\Listeners\Invoice\CreateInvoiceInvitation; use App\Models\Account; use App\Models\Client; use App\Models\ClientContact; @@ -203,8 +201,6 @@ class RandomDataSeeder extends Seeder $invoice->save(); - //event(new CreateInvoiceInvitation($invoice)); - $invoice->service()->createInvitations()->markSent()->save(); $invoice->ledger()->updateInvoiceBalance($invoice->balance); @@ -257,7 +253,6 @@ class RandomDataSeeder extends Seeder $credit->save(); - //event(new CreateCreditInvitation($credit)); $credit->service()->createInvitations()->markSent()->save(); //$invoice->markSent()->save(); diff --git a/tests/Feature/InvitationTest.php b/tests/Feature/InvitationTest.php index fe3eca5784a8..ccf4d5ea68bd 100644 --- a/tests/Feature/InvitationTest.php +++ b/tests/Feature/InvitationTest.php @@ -113,6 +113,7 @@ class InvitationTest extends TestCase $this->assertNotNull($invoice->client->primary_contact); $i = InvoiceInvitationFactory::create($invoice->company_id, $invoice->user_id); + $i->key = $this->createDbHash(config('database.default')); $i->client_contact_id = $client->primary_contact->first()->id; $i->invoice_id = $invoice->id; $i->save(); diff --git a/tests/Feature/Payments/CreditPaymentTest.php b/tests/Feature/Payments/CreditPaymentTest.php index 7414001a6fcb..edc2b7b87b0b 100644 --- a/tests/Feature/Payments/CreditPaymentTest.php +++ b/tests/Feature/Payments/CreditPaymentTest.php @@ -8,7 +8,7 @@ * * @license https://opensource.org/licenses/AAL */ -namespace Tests\Feature; +namespace Tests\Feature\Payments; use App\DataMapper\ClientSettings; use App\Factory\ClientFactory; diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php index e6c955aa0b47..5c2fd1066bc2 100644 --- a/tests/MockAccountData.php +++ b/tests/MockAccountData.php @@ -487,6 +487,7 @@ trait MockAccountData if (! $invitation && $contact->send_email) { $ii = InvoiceInvitationFactory::create($this->invoice->company_id, $this->invoice->user_id); + $ii->key = $this->createDbHash(config('database.default')); $ii->invoice_id = $this->invoice->id; $ii->client_contact_id = $contact->id; $ii->save(); diff --git a/tests/Unit/InvitationTest.php b/tests/Unit/InvitationTest.php index f5a0fbd01f5f..e8dcdb96f34e 100644 --- a/tests/Unit/InvitationTest.php +++ b/tests/Unit/InvitationTest.php @@ -12,6 +12,7 @@ namespace Tests\Unit; use App\Factory\InvoiceInvitationFactory; use App\Models\CompanyToken; +use App\Utils\Traits\MakesHash; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Routing\Middleware\ThrottleRequests; use Illuminate\Validation\ValidationException; @@ -22,7 +23,8 @@ class InvitationTest extends TestCase { use MockAccountData; use DatabaseTransactions; - + use MakesHash; + public function setUp() :void { parent::setUp(); @@ -79,6 +81,7 @@ class InvitationTest extends TestCase $new_invite = InvoiceInvitationFactory::create($this->invoice->company_id, $this->invoice->user_id); $new_invite->client_contact_id = $contact->hashed_id; + $new_invite->key = $this->createDbHash(config('database.default')); $invitations = $this->invoice->invitations()->get();