mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Working on invoice deletion
This commit is contained in:
parent
bc0a925f39
commit
bcb21fb234
@ -43,6 +43,7 @@ class MarkSent
|
||||
->service()
|
||||
->setStatus(Credit::STATUS_SENT)
|
||||
->applyNumber()
|
||||
->adjustBalance($this->credit->amount)
|
||||
->save();
|
||||
|
||||
|
||||
|
@ -21,6 +21,8 @@ class MarkInvoiceDeleted extends AbstractService
|
||||
|
||||
private $invoice;
|
||||
|
||||
private $adjustment_amount = 0;
|
||||
|
||||
public function __construct(Invoice $invoice)
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
@ -28,7 +30,36 @@ class MarkInvoiceDeleted extends AbstractService
|
||||
|
||||
public function run()
|
||||
{
|
||||
if($this->invoice->is_deleted)
|
||||
return $this->invoice;
|
||||
|
||||
// if(in_array($this->invoice->status_id, ['currencies', 'industries', 'languages', 'countries', 'banks']))
|
||||
// return $this->
|
||||
|
||||
$this->cleanup()
|
||||
->setAdjustmentAmount()
|
||||
->deletePaymentables();
|
||||
}
|
||||
|
||||
|
||||
private function setAdjustmentAmount()
|
||||
{
|
||||
|
||||
foreach ($this->invoice->payments as $payment) {
|
||||
$this->adjustment_amount += $payment->paymentables
|
||||
->where('paymentable_type', '=', 'invoices')
|
||||
->where('paymentable_id', $this->invoice->id)
|
||||
->sum(DB::raw('amount'));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function cleanup()
|
||||
{
|
||||
|
||||
$check = false;
|
||||
|
||||
$x=0;
|
||||
|
||||
do {
|
||||
@ -43,10 +74,10 @@ class MarkInvoiceDeleted extends AbstractService
|
||||
$this->invoice->tasks()->update(['invoice_id' => null]);
|
||||
$this->invoice->expenses()->update(['invoice_id' => null]);
|
||||
|
||||
return $this->invoice;
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function calcNumber($x)
|
||||
{
|
||||
if ($x==0) {
|
||||
@ -57,4 +88,19 @@ class MarkInvoiceDeleted extends AbstractService
|
||||
|
||||
return $number;
|
||||
}
|
||||
|
||||
|
||||
private function deletePaymentables()
|
||||
{
|
||||
|
||||
$this->invoice->payments->each(function ($payment){
|
||||
$payment->paymentables()
|
||||
->where('paymentable_type', '=', 'invoices')
|
||||
->where('paymentable_id', $this->invoice->id)
|
||||
->update(['deleted_at' => now()]);
|
||||
});
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user