Delete pdf when deleting invoice

This commit is contained in:
David Bomba 2022-10-21 15:00:33 +11:00
parent cc84f9eb2e
commit ab71be42a0
4 changed files with 23 additions and 10 deletions

View File

@ -23,6 +23,7 @@ use App\Utils\Helpers;
use App\Utils\Ninja; use App\Utils\Ninja;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use App\Utils\Traits\SavesDocuments; use App\Utils\Traits\SavesDocuments;
use Google\Service\Vision\Property;
use ReflectionClass; use ReflectionClass;
class BaseRepository class BaseRepository
@ -185,15 +186,17 @@ class BaseRepository
if(!$model->id){ if(!$model->id){
$this->new_model = true; $this->new_model = true;
$model->line_items = (collect($model->line_items))->map(function ($item) use($model,$client) {
$item->notes = Helpers::processReservedKeywords($item->notes, $client); if(is_array($model->line_items))
{
$model->line_items = (collect($model->line_items))->map(function ($item) use($model,$client) {
return $item; $item->notes = Helpers::processReservedKeywords($item->notes, $client);
}); return $item;
});
}
} }
$model->saveQuietly(); $model->saveQuietly();

View File

@ -218,6 +218,7 @@ class InvoiceService
public function markDeleted() public function markDeleted()
{ {
$this->removeUnpaidGatewayFees(); $this->removeUnpaidGatewayFees();
$this->deletePdf();
$this->invoice = (new MarkInvoiceDeleted($this->invoice))->run(); $this->invoice = (new MarkInvoiceDeleted($this->invoice))->run();
@ -298,6 +299,9 @@ class InvoiceService
} elseif ($this->invoice->balance > 0 && $this->invoice->balance < $this->invoice->amount) { } elseif ($this->invoice->balance > 0 && $this->invoice->balance < $this->invoice->amount) {
$this->setStatus(Invoice::STATUS_PARTIAL); $this->setStatus(Invoice::STATUS_PARTIAL);
} }
elseif($this->invoice->balance < 0) {
$this->setStatus(Invoice::STATUS_PARTIAL);
}
return $this; return $this;
} }

View File

@ -71,10 +71,6 @@ class MarkInvoiceDeleted extends AbstractService
private function adjustPaidToDateAndBalance() private function adjustPaidToDateAndBalance()
{ {
// $client = $this->invoice->client->fresh();
// $client->paid_to_date += $this->adjustment_amount * -1;
// $client->balance += $this->balance_adjustment * -1;
// $client->save();
// 06-09-2022 // 06-09-2022
$this->invoice $this->invoice

View File

@ -65,7 +65,17 @@ trait ClientGroupSettingsSaver
} }
$entity->settings = $entity_settings; $entity->settings = $entity_settings;
$entity->save();
try{
$entity->save();
}
catch(\Exception $e){
nlog("client settings failure");
nlog($entity_settings);
nlog($e->getMessage());
}
return $entity_settings; return $entity_settings;
} }