added db transaction to jobs
This commit is contained in:
@@ -26,12 +26,14 @@ class CancelBill extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->deleteRelationships($this->bill, [
|
||||
'transactions', 'recurring'
|
||||
]);
|
||||
\DB::transaction(function () {
|
||||
$this->deleteRelationships($this->bill, [
|
||||
'transactions', 'recurring'
|
||||
]);
|
||||
|
||||
$this->bill->status = 'cancelled';
|
||||
$this->bill->save();
|
||||
$this->bill->status = 'cancelled';
|
||||
$this->bill->save();
|
||||
});
|
||||
|
||||
return $this->bill;
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ class CreateBill extends Job
|
||||
{
|
||||
use Currencies, DateTime;
|
||||
|
||||
protected $request;
|
||||
|
||||
protected $bill;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@@ -41,20 +41,22 @@ class CreateBill extends Job
|
||||
|
||||
event(new BillCreating($this->request));
|
||||
|
||||
$this->bill = Bill::create($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->bill = Bill::create($this->request->all());
|
||||
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'bills');
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'bills');
|
||||
|
||||
$this->bill->attachMedia($media, 'attachment');
|
||||
}
|
||||
$this->bill->attachMedia($media, 'attachment');
|
||||
}
|
||||
|
||||
$this->createItemsAndTotals();
|
||||
$this->createItemsAndTotals();
|
||||
|
||||
$this->bill->update($this->request->input());
|
||||
$this->bill->update($this->request->input());
|
||||
|
||||
$this->bill->createRecurring();
|
||||
$this->bill->createRecurring();
|
||||
});
|
||||
|
||||
event(new BillCreated($this->bill));
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Jobs\Purchase;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Purchase\Bill;
|
||||
use App\Observers\Transaction;
|
||||
|
||||
class DeleteBill extends Job
|
||||
@@ -29,15 +28,17 @@ class DeleteBill extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
Transaction::mute();
|
||||
\DB::transaction(function () {
|
||||
Transaction::mute();
|
||||
|
||||
$this->deleteRelationships($this->bill, [
|
||||
'items', 'item_taxes', 'histories', 'transactions', 'recurring', 'totals'
|
||||
]);
|
||||
$this->deleteRelationships($this->bill, [
|
||||
'items', 'item_taxes', 'histories', 'transactions', 'recurring', 'totals'
|
||||
]);
|
||||
|
||||
$this->bill->delete();
|
||||
$this->bill->delete();
|
||||
|
||||
Transaction::unmute();
|
||||
Transaction::unmute();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
namespace App\Jobs\Purchase;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Events\Purchase\BillCreated;
|
||||
use App\Models\Purchase\Bill;
|
||||
use App\Models\Purchase\BillHistory;
|
||||
|
||||
class DuplicateBill extends Job
|
||||
{
|
||||
protected $bill;
|
||||
|
||||
protected $clone;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@@ -27,17 +29,12 @@ class DuplicateBill extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$clone = $this->bill->duplicate();
|
||||
\DB::transaction(function () {
|
||||
$this->clone = $this->bill->duplicate();
|
||||
});
|
||||
|
||||
// Add bill history
|
||||
BillHistory::create([
|
||||
'company_id' => session('company_id'),
|
||||
'bill_id' => $clone->id,
|
||||
'status' => 'draft',
|
||||
'notify' => 0,
|
||||
'description' => trans('messages.success.added', ['type' => $clone->bill_number]),
|
||||
]);
|
||||
event(new BillCreated($this->clone));
|
||||
|
||||
return $clone;
|
||||
return $this->clone;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,26 +43,28 @@ class UpdateBill extends Job
|
||||
|
||||
event(new BillUpdating($this->bill, $this->request));
|
||||
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'bills');
|
||||
\DB::transaction(function () {
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'bills');
|
||||
|
||||
$this->bill->attachMedia($media, 'attachment');
|
||||
}
|
||||
$this->bill->attachMedia($media, 'attachment');
|
||||
}
|
||||
|
||||
$this->createItemsAndTotals();
|
||||
$this->createItemsAndTotals();
|
||||
|
||||
$bill_paid = $this->bill->paid;
|
||||
$bill_paid = $this->bill->paid;
|
||||
|
||||
unset($this->bill->reconciled);
|
||||
unset($this->bill->reconciled);
|
||||
|
||||
if (($bill_paid) && $this->request['amount'] > $bill_paid) {
|
||||
$this->request['status'] = 'partial';
|
||||
}
|
||||
if (($bill_paid) && $this->request['amount'] > $bill_paid) {
|
||||
$this->request['status'] = 'partial';
|
||||
}
|
||||
|
||||
$this->bill->update($this->request->input());
|
||||
$this->bill->update($this->request->input());
|
||||
|
||||
$this->bill->updateRecurring();
|
||||
$this->bill->updateRecurring();
|
||||
});
|
||||
|
||||
event(new BillUpdated($this->bill));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user