Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
DeleteAddItemConferenceInvoiceService
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 delete
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
 processActivetyLog
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Domain\Invoice\Services;
4
5use App\Events\ServiceProcessed;
6use App\Models\Invoice\Invoice;
7use App\Models\Invoice\InvoiceVerification;
8use App\Models\User;
9use Domain\Invoice\DTOs\StoreInvoiceActivityLogDTO;
10use Domain\Invoice\Enums\InvoiceActivetyLogOperationEnum;
11use Illuminate\Support\Facades\DB;
12use Throwable;
13
14readonly class DeleteAddItemConferenceInvoiceService
15{
16    /**
17     * @param Invoice $invoice
18     * @param User $user
19     * @throws Throwable
20     */
21    public function delete(InvoiceVerification $invoiceVerification, User $user): void
22    {
23        try {
24            DB::beginTransaction();
25
26            $invoiceVerificationOld = $invoiceVerification->getAttributes();
27            $invoice = $invoiceVerification->invoice;
28
29            $invoiceVerification->delete();
30
31            $this->processActivetyLog($invoice, $user, $invoiceVerificationOld);
32
33            DB::commit();
34        } catch (Throwable $exception) {
35            DB::rollBack();
36            throw $exception;
37        }
38
39        ServiceProcessed::dispatch(self::class, $user);
40    }
41
42    /**
43     * @param InvoiceVerification $invoiceVerification
44     * @param User $user
45     * @param array $details
46     */
47    private function processActivetyLog(Invoice $invoice, User $user, array $details)
48    {
49        $invoiceActivityLogDTO = new StoreInvoiceActivityLogDTO([
50            'entity_type' => InvoiceVerification::class,
51            'entity_id'   => $details['id'],
52            'operation'   => InvoiceActivetyLogOperationEnum::DELETE,
53            'user'        => $user,
54            'detail'      => json_encode($details),
55            'observation' => 'Removido item adicional da conferĂȘncia.'
56        ]);
57
58        (new InvoiceActivityLogStoreService())->store($invoiceActivityLogDTO, $invoice, $user);
59    }
60}