Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| InvoiceStoreService | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| store | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| populateInvoiceActivetyLogDTO | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Invoice\Services; |
| 4 | |
| 5 | use Carbon\Carbon; |
| 6 | |
| 7 | use Domain\Integration\Services\IntegrationStoreService; |
| 8 | use Domain\Invoice\DTOs\StoreInvoiceActivityLogDTO; |
| 9 | use Domain\Invoice\DTOs\StoreInvoiceDTO; |
| 10 | use Domain\Invoice\Enums\InvoiceActivetyLogOperationEnum; |
| 11 | |
| 12 | use App\Events\ServiceProcessed; |
| 13 | use App\Helper\AppHelper; |
| 14 | use App\Models\Invoice\Invoice; |
| 15 | use App\Models\User; |
| 16 | |
| 17 | readonly class InvoiceStoreService |
| 18 | { |
| 19 | public function store(StoreInvoiceDTO $storeInvoiceDTO, User $user): Invoice |
| 20 | { |
| 21 | $invoice = new Invoice(); |
| 22 | $invoice->fill($storeInvoiceDTO->toArray()); |
| 23 | $invoice->issue_date = Carbon::createFromFormat('d/m/Y', $storeInvoiceDTO->issue_date)->format('Y-m-d'); |
| 24 | $invoice->supplier()->associate($storeInvoiceDTO->supplier); |
| 25 | $invoice->save(); |
| 26 | |
| 27 | (new IntegrationStoreService())->store($storeInvoiceDTO->integration, $invoice, $user); |
| 28 | |
| 29 | (new InvoiceActivityLogStoreService())->store($this->populateInvoiceActivetyLogDTO($invoice), $invoice, $user); |
| 30 | |
| 31 | ServiceProcessed::dispatch(self::class, $user); |
| 32 | return $invoice; |
| 33 | } |
| 34 | |
| 35 | private function populateInvoiceActivetyLogDTO(Invoice $invoice): StoreInvoiceActivityLogDTO |
| 36 | { |
| 37 | return new StoreInvoiceActivityLogDTO([ |
| 38 | 'entity_type' => Invoice::class, |
| 39 | 'entity_id' => $invoice->getKey(), |
| 40 | 'operation' => InvoiceActivetyLogOperationEnum::INSERT, |
| 41 | 'user' => AppHelper::systemUser(), |
| 42 | 'detail' => json_encode($invoice->getAttributes()), |
| 43 | 'observation' => 'Inserido pelo Job de sincronização automática' |
| 44 | ]); |
| 45 | } |
| 46 | } |