You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.0 KiB
38 lines
1.0 KiB
<?php
|
|
|
|
namespace App\Domains\Billing\Actions\Invoicing;
|
|
|
|
use App\Domains\Billing\DTOs\Invoicing\UpdateInvoiceDetailDTO;
|
|
use App\Domains\Billing\Models\Invoice;
|
|
use Exception;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class UpdateInvoiceDetail
|
|
{
|
|
public function __construct(
|
|
protected AttachItemsToInvoice $attachItemsToInvoice
|
|
)
|
|
{}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function execute(Invoice $invoice, UpdateInvoiceDetailDTO $dto): Invoice
|
|
{
|
|
try {
|
|
return DB::transaction(function() use ($invoice, $dto) {
|
|
$invoice->update(['client_detail' => $dto->client_detail]);
|
|
$invoice->items()->delete();
|
|
|
|
foreach ($dto->items as $item) {
|
|
$this->attachItemsToInvoice->execute(invoiceId: $invoice->id, item: $item);
|
|
}
|
|
|
|
return $invoice;
|
|
});
|
|
} catch (\Throwable $th) {
|
|
info($th->getMessage());
|
|
throw new Exception(__('domains/system.exception.something_wrong'));
|
|
}
|
|
}
|
|
}
|
|
|