added db transaction to jobs
This commit is contained in:
@@ -26,12 +26,14 @@ class CancelInvoice extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->deleteRelationships($this->invoice, [
|
||||
'transactions', 'recurring'
|
||||
]);
|
||||
\DB::transaction(function () {
|
||||
$this->deleteRelationships($this->invoice, [
|
||||
'transactions', 'recurring'
|
||||
]);
|
||||
|
||||
$this->invoice->status = 'cancelled';
|
||||
$this->invoice->save();
|
||||
$this->invoice->status = 'cancelled';
|
||||
$this->invoice->save();
|
||||
});
|
||||
|
||||
return $this->invoice;
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ class CreateInvoice extends Job
|
||||
{
|
||||
use Currencies, DateTime;
|
||||
|
||||
protected $request;
|
||||
|
||||
protected $invoice;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@@ -41,20 +41,22 @@ class CreateInvoice extends Job
|
||||
|
||||
event(new InvoiceCreating($this->request));
|
||||
|
||||
$this->invoice = Invoice::create($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->invoice = Invoice::create($this->request->all());
|
||||
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'invoices');
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'invoices');
|
||||
|
||||
$this->invoice->attachMedia($media, 'attachment');
|
||||
}
|
||||
$this->invoice->attachMedia($media, 'attachment');
|
||||
}
|
||||
|
||||
$this->createItemsAndTotals();
|
||||
$this->createItemsAndTotals();
|
||||
|
||||
$this->invoice->update($this->request->all());
|
||||
$this->invoice->update($this->request->all());
|
||||
|
||||
$this->invoice->createRecurring();
|
||||
$this->invoice->createRecurring();
|
||||
});
|
||||
|
||||
event(new InvoiceCreated($this->invoice));
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Jobs\Sale;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Sale\Invoice;
|
||||
use App\Observers\Transaction;
|
||||
|
||||
class DeleteInvoice extends Job
|
||||
@@ -29,15 +28,17 @@ class DeleteInvoice extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
Transaction::mute();
|
||||
\DB::transaction(function () {
|
||||
Transaction::mute();
|
||||
|
||||
$this->deleteRelationships($this->invoice, [
|
||||
'items', 'item_taxes', 'histories', 'transactions', 'recurring', 'totals'
|
||||
]);
|
||||
$this->deleteRelationships($this->invoice, [
|
||||
'items', 'item_taxes', 'histories', 'transactions', 'recurring', 'totals'
|
||||
]);
|
||||
|
||||
$this->invoice->delete();
|
||||
$this->invoice->delete();
|
||||
|
||||
Transaction::unmute();
|
||||
Transaction::unmute();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ class DuplicateInvoice extends Job
|
||||
{
|
||||
protected $invoice;
|
||||
|
||||
protected $clone;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@@ -27,10 +29,12 @@ class DuplicateInvoice extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$clone = $this->invoice->duplicate();
|
||||
\DB::transaction(function () {
|
||||
$this->clone = $this->invoice->duplicate();
|
||||
});
|
||||
|
||||
event(new InvoiceCreated($clone));
|
||||
event(new InvoiceCreated($this->clone));
|
||||
|
||||
return $clone;
|
||||
return $this->clone;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,26 +43,28 @@ class UpdateInvoice extends Job
|
||||
|
||||
event(new InvoiceUpdating($this->invoice, $this->request));
|
||||
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'invoices');
|
||||
\DB::transaction(function () {
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'invoices');
|
||||
|
||||
$this->invoice->attachMedia($media, 'attachment');
|
||||
}
|
||||
$this->invoice->attachMedia($media, 'attachment');
|
||||
}
|
||||
|
||||
$this->createItemsAndTotals();
|
||||
$this->createItemsAndTotals();
|
||||
|
||||
$invoice_paid = $this->invoice->paid;
|
||||
$invoice_paid = $this->invoice->paid;
|
||||
|
||||
unset($this->invoice->reconciled);
|
||||
unset($this->invoice->reconciled);
|
||||
|
||||
if (($invoice_paid) && $this->request['amount'] > $invoice_paid) {
|
||||
$this->request['status'] = 'partial';
|
||||
}
|
||||
if (($invoice_paid) && $this->request['amount'] > $invoice_paid) {
|
||||
$this->request['status'] = 'partial';
|
||||
}
|
||||
|
||||
$this->invoice->update($this->request->all());
|
||||
$this->invoice->update($this->request->all());
|
||||
|
||||
$this->invoice->updateRecurring();
|
||||
$this->invoice->updateRecurring();
|
||||
});
|
||||
|
||||
event(new InvoiceUpdated($this->invoice, $this->request));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user