diff --git a/VERSION.txt b/VERSION.txt index 0c37012d2c18..7422b58bc085 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.3.37 \ No newline at end of file +5.3.38 \ No newline at end of file diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index 631819765c22..c46fbef9fe84 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -382,9 +382,7 @@ class ClientController extends BaseController /* Set the client country to the company if none is set */ if(!$client->country_id && strlen($client->company->settings->country_id) > 1){ - $client->country_id = $client->company->settings->country_id; - - $client->save(); + $client->update(['country_id' => $client->company->settings->country_id]); } diff --git a/app/Http/Controllers/RecurringInvoiceController.php b/app/Http/Controllers/RecurringInvoiceController.php index 03bbe94cfffd..16e217c0af4c 100644 --- a/app/Http/Controllers/RecurringInvoiceController.php +++ b/app/Http/Controllers/RecurringInvoiceController.php @@ -204,8 +204,6 @@ class RecurringInvoiceController extends BaseController { $recurring_invoice = $this->recurring_invoice_repo->save($request->all(), RecurringInvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id)); - event(new RecurringInvoiceWasCreated($recurring_invoice, $recurring_invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); - $offset = $recurring_invoice->client->timezone_offset(); $recurring_invoice->next_send_date = Carbon::parse($recurring_invoice->next_send_date)->startOfDay()->addSeconds($offset); $recurring_invoice->saveQuietly(); @@ -214,6 +212,8 @@ class RecurringInvoiceController extends BaseController ->triggeredActions($request) ->save(); + event(new RecurringInvoiceWasCreated($recurring_invoice, $recurring_invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + return $this->itemResponse($recurring_invoice); } diff --git a/app/Http/Controllers/SubscriptionController.php b/app/Http/Controllers/SubscriptionController.php index 0cf6233a9c21..051156343a96 100644 --- a/app/Http/Controllers/SubscriptionController.php +++ b/app/Http/Controllers/SubscriptionController.php @@ -354,8 +354,6 @@ class SubscriptionController extends BaseController event(new SubscriptionWasUpdated($subscription, $subscription->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); -nlog($subscription->id); - return $this->itemResponse($subscription); } diff --git a/app/Listeners/Invoice/InvoiceFailedEmailNotification.php b/app/Listeners/Invoice/InvoiceFailedEmailNotification.php index 5603e9450a8d..fbaba6e97be3 100644 --- a/app/Listeners/Invoice/InvoiceFailedEmailNotification.php +++ b/app/Listeners/Invoice/InvoiceFailedEmailNotification.php @@ -45,8 +45,7 @@ class InvoiceFailedEmailNotification $first_notification_sent = true; $invoice = $event->invitation->invoice; - $invoice->last_sent_date = now(); - $invoice->save(); + $invoice->update(['last_sent_date' => now()]); $nmo = new NinjaMailerObject; $nmo->mailable = new NinjaMailer( (new EntityFailedSendObject($event->invitation, 'invoice', $event->template, $event->message))->build() ); diff --git a/app/Mail/DownloadBackup.php b/app/Mail/DownloadBackup.php index b3f287c45000..b70cb90b8dbe 100644 --- a/app/Mail/DownloadBackup.php +++ b/app/Mail/DownloadBackup.php @@ -16,6 +16,7 @@ use App\Models\Company; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; +use Illuminate\Support\Facades\App; class DownloadBackup extends Mailable { @@ -36,6 +37,8 @@ class DownloadBackup extends Mailable */ public function build() { + App::setLocale($this->company->getLocale()); + $company = Company::where('company_key', $this->company->company_key)->first(); return $this->from(config('mail.from.address'), config('mail.from.name')) diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index bddc4ad0e537..2f82e3561b4b 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -113,10 +113,10 @@ class BaseModel extends Model * to persist the new settings we will also need to pass back a * reference to the parent class. * - * @param mixes $key The key of property + * @param $key The key of property * @return */ - public function getSettingsByKey(mixes $key) + public function getSettingsByKey($key) { /* Does Setting Exist @ client level */ if (isset($this->getSettings()->{$key})) { diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 0a52575631f0..1a5a1b837ee3 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -204,11 +204,13 @@ class BaseDriver extends AbstractPaymentDriver $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get(); $payment->invoices()->sync($invoices); + $payment->service()->applyNumber()->save(); + $invoices->each(function ($invoice) use ($payment) { event(new InvoiceWasPaid($invoice, $payment, $payment->company, Ninja::eventVars())); }); - return $payment->service()->applyNumber()->save(); + return $payment; } /** @@ -263,8 +265,7 @@ class BaseDriver extends AbstractPaymentDriver event('eloquent.created: App\Models\Payment', $payment); - if ($this->client->getSetting('client_online_payment_notification') && in_array($status, [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING - ])) + if ($this->client->getSetting('client_online_payment_notification') && in_array($status, [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING])) $payment->service()->sendEmail(); //todo diff --git a/app/Repositories/ClientRepository.php b/app/Repositories/ClientRepository.php index 4765256cde03..cdf6305cb17d 100644 --- a/app/Repositories/ClientRepository.php +++ b/app/Repositories/ClientRepository.php @@ -67,14 +67,13 @@ class ClientRepository extends BaseRepository if (!isset($client->number) || empty($client->number) || strlen($client->number) == 0) { $client->number = $this->getNextClientNumber($client); + $client->save(); } if (empty($data['name'])) { $data['name'] = $client->present()->name(); } - $client->save(); - $this->contact_repo->save($data, $client); return $client; diff --git a/app/Services/Credit/MarkSent.php b/app/Services/Credit/MarkSent.php index 0c062eb8a3f6..b02e85e50dec 100644 --- a/app/Services/Credit/MarkSent.php +++ b/app/Services/Credit/MarkSent.php @@ -37,8 +37,6 @@ class MarkSent $this->credit->markInvitationsSent(); - event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); - $this->credit ->service() ->setStatus(Credit::STATUS_SENT) @@ -47,6 +45,7 @@ class MarkSent ->deletePdf() ->save(); + event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); return $this->credit; } diff --git a/app/Services/Invoice/ApplyPaymentAmount.php b/app/Services/Invoice/ApplyPaymentAmount.php index 1250bb506c4f..ee6a0f657ec0 100644 --- a/app/Services/Invoice/ApplyPaymentAmount.php +++ b/app/Services/Invoice/ApplyPaymentAmount.php @@ -88,8 +88,6 @@ class ApplyPaymentAmount extends AbstractService $payment->service()->sendEmail(); /* Update Invoice balance */ - event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); - event(new InvoiceWasPaid($this->invoice, $payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); $payment->ledger() ->updatePaymentBalance($payment->amount * -1); @@ -104,7 +102,9 @@ class ApplyPaymentAmount extends AbstractService $this->invoice->service()->workFlow()->save(); event('eloquent.created: App\Models\Payment', $payment); - + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + event(new InvoiceWasPaid($this->invoice, $payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + return $this->invoice; } diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 646bbad5a12d..2771c3409a2a 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -175,8 +175,6 @@ class AutoBillInvoice extends AbstractService } - event('eloquent.created: App\Models\Payment', $payment); - $payment->ledger() ->updatePaymentBalance($amount * -1) ->save(); @@ -192,7 +190,7 @@ class AutoBillInvoice extends AbstractService ->updateCreditBalance($amount * -1, "Credit {$current_credit->number} used to pay down Invoice {$this->invoice->number}") ->save(); - + event('eloquent.created: App\Models\Payment', $payment); event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); return $this->invoice diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index a9b45ef1fa86..3178eba97862 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -91,13 +91,6 @@ class MarkPaid extends AbstractService ->deletePdf() ->save(); - // if ($this->invoice->client->getSetting('client_manual_payment_notification')) - // $payment->service()->sendEmail(); - - /* Update Invoice balance */ - event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); - event(new InvoiceWasPaid($this->invoice, $payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); - $payment->ledger() ->updatePaymentBalance($payment->amount * -1); @@ -113,6 +106,10 @@ class MarkPaid extends AbstractService ->workFlow() ->save(); + /* Update Invoice balance */ + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + event(new InvoiceWasPaid($this->invoice, $payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + return $this->invoice; } diff --git a/app/Services/Payment/UpdateInvoicePayment.php b/app/Services/Payment/UpdateInvoicePayment.php index 4357077196ed..ca5534245416 100644 --- a/app/Services/Payment/UpdateInvoicePayment.php +++ b/app/Services/Payment/UpdateInvoicePayment.php @@ -52,8 +52,8 @@ class UpdateInvoicePayment } /* Need to determine here is we have an OVER payment - if YES only apply the max invoice amount */ - if($paid_amount > $invoice->partial && $paid_amount > $invoice->balance) - $paid_amount = $invoice->balance; + if($paid_amount > $invoice->partial && $paid_amount > $invoice->balance) + $paid_amount = $invoice->balance; /* Updates the company ledger */ $this->payment @@ -95,14 +95,14 @@ class UpdateInvoicePayment /* Remove the event updater from within the loop to prevent race conditions */ + $this->payment->saveQuietly(); + $invoices->each(function ($invoice) { event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); - + }); - $this->payment->saveQuietly(); - return $this->payment; } } diff --git a/app/Services/Quote/MarkSent.php b/app/Services/Quote/MarkSent.php index a21a2d6b817c..31cb5b9ac5ed 100644 --- a/app/Services/Quote/MarkSent.php +++ b/app/Services/Quote/MarkSent.php @@ -45,8 +45,6 @@ class MarkSent $this->quote->due_date = Carbon::parse($this->quote->date)->addDays($this->quote->client->getSetting('valid_until')); } - event(new QuoteWasMarkedSent($this->quote, $this->quote->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); - $this->quote ->service() ->setStatus(Quote::STATUS_SENT) @@ -54,6 +52,8 @@ class MarkSent ->deletePdf() ->save(); + event(new QuoteWasMarkedSent($this->quote, $this->quote->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + return $this->quote; } } diff --git a/app/Services/Quote/QuoteService.php b/app/Services/Quote/QuoteService.php index b5b208857940..77b134103abe 100644 --- a/app/Services/Quote/QuoteService.php +++ b/app/Services/Quote/QuoteService.php @@ -110,8 +110,6 @@ class QuoteService $contact = $this->quote->invitations->first()->contact; } - event(new QuoteWasApproved($contact, $this->quote, $this->quote->company, Ninja::eventVars())); - if ($this->quote->client->getSetting('auto_convert_quote')) { $this->convert(); @@ -123,6 +121,8 @@ class QuoteService } + event(new QuoteWasApproved($contact, $this->quote, $this->quote->company, Ninja::eventVars())); + return $this; } diff --git a/config/ninja.php b/config/ninja.php index 27066a5c4862..4557bc9b8417 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -14,8 +14,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.3.37', - 'app_tag' => '5.3.37', + 'app_version' => '5.3.38', + 'app_tag' => '5.3.38', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''),