Fixes for atomic operations

This commit is contained in:
David Bomba 2021-12-17 22:11:36 +11:00
parent c76cb3eb7c
commit c77720672b
17 changed files with 35 additions and 43 deletions

View File

@ -1 +1 @@
5.3.37 5.3.38

View File

@ -382,9 +382,7 @@ class ClientController extends BaseController
/* Set the client country to the company if none is set */ /* Set the client country to the company if none is set */
if(!$client->country_id && strlen($client->company->settings->country_id) > 1){ if(!$client->country_id && strlen($client->company->settings->country_id) > 1){
$client->country_id = $client->company->settings->country_id; $client->update(['country_id' => $client->company->settings->country_id]);
$client->save();
} }

View File

@ -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)); $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(); $offset = $recurring_invoice->client->timezone_offset();
$recurring_invoice->next_send_date = Carbon::parse($recurring_invoice->next_send_date)->startOfDay()->addSeconds($offset); $recurring_invoice->next_send_date = Carbon::parse($recurring_invoice->next_send_date)->startOfDay()->addSeconds($offset);
$recurring_invoice->saveQuietly(); $recurring_invoice->saveQuietly();
@ -214,6 +212,8 @@ class RecurringInvoiceController extends BaseController
->triggeredActions($request) ->triggeredActions($request)
->save(); ->save();
event(new RecurringInvoiceWasCreated($recurring_invoice, $recurring_invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
return $this->itemResponse($recurring_invoice); return $this->itemResponse($recurring_invoice);
} }

View File

@ -354,8 +354,6 @@ class SubscriptionController extends BaseController
event(new SubscriptionWasUpdated($subscription, $subscription->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); event(new SubscriptionWasUpdated($subscription, $subscription->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
nlog($subscription->id);
return $this->itemResponse($subscription); return $this->itemResponse($subscription);
} }

View File

@ -45,8 +45,7 @@ class InvoiceFailedEmailNotification
$first_notification_sent = true; $first_notification_sent = true;
$invoice = $event->invitation->invoice; $invoice = $event->invitation->invoice;
$invoice->last_sent_date = now(); $invoice->update(['last_sent_date' => now()]);
$invoice->save();
$nmo = new NinjaMailerObject; $nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer( (new EntityFailedSendObject($event->invitation, 'invoice', $event->template, $event->message))->build() ); $nmo->mailable = new NinjaMailer( (new EntityFailedSendObject($event->invitation, 'invoice', $event->template, $event->message))->build() );

View File

@ -16,6 +16,7 @@ use App\Models\Company;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable; use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\App;
class DownloadBackup extends Mailable class DownloadBackup extends Mailable
{ {
@ -36,6 +37,8 @@ class DownloadBackup extends Mailable
*/ */
public function build() public function build()
{ {
App::setLocale($this->company->getLocale());
$company = Company::where('company_key', $this->company->company_key)->first(); $company = Company::where('company_key', $this->company->company_key)->first();
return $this->from(config('mail.from.address'), config('mail.from.name')) return $this->from(config('mail.from.address'), config('mail.from.name'))

View File

@ -113,10 +113,10 @@ class BaseModel extends Model
* to persist the new settings we will also need to pass back a * to persist the new settings we will also need to pass back a
* reference to the parent class. * reference to the parent class.
* *
* @param mixes $key The key of property * @param $key The key of property
* @return * @return
*/ */
public function getSettingsByKey(mixes $key) public function getSettingsByKey($key)
{ {
/* Does Setting Exist @ client level */ /* Does Setting Exist @ client level */
if (isset($this->getSettings()->{$key})) { if (isset($this->getSettings()->{$key})) {

View File

@ -204,11 +204,13 @@ class BaseDriver extends AbstractPaymentDriver
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get(); $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get();
$payment->invoices()->sync($invoices); $payment->invoices()->sync($invoices);
$payment->service()->applyNumber()->save();
$invoices->each(function ($invoice) use ($payment) { $invoices->each(function ($invoice) use ($payment) {
event(new InvoiceWasPaid($invoice, $payment, $payment->company, Ninja::eventVars())); 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); 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(); $payment->service()->sendEmail();
//todo //todo

View File

@ -67,14 +67,13 @@ class ClientRepository extends BaseRepository
if (!isset($client->number) || empty($client->number) || strlen($client->number) == 0) { if (!isset($client->number) || empty($client->number) || strlen($client->number) == 0) {
$client->number = $this->getNextClientNumber($client); $client->number = $this->getNextClientNumber($client);
$client->save();
} }
if (empty($data['name'])) { if (empty($data['name'])) {
$data['name'] = $client->present()->name(); $data['name'] = $client->present()->name();
} }
$client->save();
$this->contact_repo->save($data, $client); $this->contact_repo->save($data, $client);
return $client; return $client;

View File

@ -37,8 +37,6 @@ class MarkSent
$this->credit->markInvitationsSent(); $this->credit->markInvitationsSent();
event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
$this->credit $this->credit
->service() ->service()
->setStatus(Credit::STATUS_SENT) ->setStatus(Credit::STATUS_SENT)
@ -47,6 +45,7 @@ class MarkSent
->deletePdf() ->deletePdf()
->save(); ->save();
event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
return $this->credit; return $this->credit;
} }

View File

@ -88,8 +88,6 @@ class ApplyPaymentAmount extends AbstractService
$payment->service()->sendEmail(); $payment->service()->sendEmail();
/* Update Invoice balance */ /* 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() $payment->ledger()
->updatePaymentBalance($payment->amount * -1); ->updatePaymentBalance($payment->amount * -1);
@ -104,7 +102,9 @@ class ApplyPaymentAmount extends AbstractService
$this->invoice->service()->workFlow()->save(); $this->invoice->service()->workFlow()->save();
event('eloquent.created: App\Models\Payment', $payment); 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; return $this->invoice;
} }

View File

@ -175,8 +175,6 @@ class AutoBillInvoice extends AbstractService
} }
event('eloquent.created: App\Models\Payment', $payment);
$payment->ledger() $payment->ledger()
->updatePaymentBalance($amount * -1) ->updatePaymentBalance($amount * -1)
->save(); ->save();
@ -192,7 +190,7 @@ class AutoBillInvoice extends AbstractService
->updateCreditBalance($amount * -1, "Credit {$current_credit->number} used to pay down Invoice {$this->invoice->number}") ->updateCreditBalance($amount * -1, "Credit {$current_credit->number} used to pay down Invoice {$this->invoice->number}")
->save(); ->save();
event('eloquent.created: App\Models\Payment', $payment);
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
return $this->invoice return $this->invoice

View File

@ -91,13 +91,6 @@ class MarkPaid extends AbstractService
->deletePdf() ->deletePdf()
->save(); ->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() $payment->ledger()
->updatePaymentBalance($payment->amount * -1); ->updatePaymentBalance($payment->amount * -1);
@ -113,6 +106,10 @@ class MarkPaid extends AbstractService
->workFlow() ->workFlow()
->save(); ->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; return $this->invoice;
} }

View File

@ -52,8 +52,8 @@ class UpdateInvoicePayment
} }
/* Need to determine here is we have an OVER payment - if YES only apply the max invoice amount */ /* 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) if($paid_amount > $invoice->partial && $paid_amount > $invoice->balance)
$paid_amount = $invoice->balance; $paid_amount = $invoice->balance;
/* Updates the company ledger */ /* Updates the company ledger */
$this->payment $this->payment
@ -95,14 +95,14 @@ class UpdateInvoicePayment
/* Remove the event updater from within the loop to prevent race conditions */ /* Remove the event updater from within the loop to prevent race conditions */
$this->payment->saveQuietly();
$invoices->each(function ($invoice) { $invoices->each(function ($invoice) {
event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
}); });
$this->payment->saveQuietly();
return $this->payment; return $this->payment;
} }
} }

View File

@ -45,8 +45,6 @@ class MarkSent
$this->quote->due_date = Carbon::parse($this->quote->date)->addDays($this->quote->client->getSetting('valid_until')); $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 $this->quote
->service() ->service()
->setStatus(Quote::STATUS_SENT) ->setStatus(Quote::STATUS_SENT)
@ -54,6 +52,8 @@ class MarkSent
->deletePdf() ->deletePdf()
->save(); ->save();
event(new QuoteWasMarkedSent($this->quote, $this->quote->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
return $this->quote; return $this->quote;
} }
} }

View File

@ -110,8 +110,6 @@ class QuoteService
$contact = $this->quote->invitations->first()->contact; $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')) { if ($this->quote->client->getSetting('auto_convert_quote')) {
$this->convert(); $this->convert();
@ -123,6 +121,8 @@ class QuoteService
} }
event(new QuoteWasApproved($contact, $this->quote, $this->quote->company, Ninja::eventVars()));
return $this; return $this;
} }

View File

@ -14,8 +14,8 @@ return [
'require_https' => env('REQUIRE_HTTPS', true), 'require_https' => env('REQUIRE_HTTPS', true),
'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_url' => rtrim(env('APP_URL', ''), '/'),
'app_domain' => env('APP_DOMAIN', 'invoicing.co'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
'app_version' => '5.3.37', 'app_version' => '5.3.38',
'app_tag' => '5.3.37', 'app_tag' => '5.3.38',
'minimum_client_version' => '5.0.16', 'minimum_client_version' => '5.0.16',
'terms_version' => '1.0.1', 'terms_version' => '1.0.1',
'api_secret' => env('API_SECRET', ''), 'api_secret' => env('API_SECRET', ''),