1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 14:12:44 +01:00

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 */
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]);
}

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));
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);
}

View File

@ -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);
}

View File

@ -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() );

View File

@ -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'))

View File

@ -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})) {

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

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 */
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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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', ''),