Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| PurchaseOrderStoreService | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| store | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\PurchaseOrder\Services; |
| 4 | |
| 5 | use App\Events\ServiceProcessed; |
| 6 | use App\Models\PurchaseOrder\PurchaseOrder; |
| 7 | use App\Models\User; |
| 8 | use Domain\Integration\Services\IntegrationStoreService; |
| 9 | use Domain\PurchaseOrder\DTOs\StorePurchaseOrderDTO; |
| 10 | use Illuminate\Support\Facades\DB; |
| 11 | use Throwable; |
| 12 | |
| 13 | readonly class PurchaseOrderStoreService |
| 14 | { |
| 15 | public function store(StorePurchaseOrderDTO $storePurchaseOrderDTO, User $user): PurchaseOrder |
| 16 | { |
| 17 | try { |
| 18 | DB::beginTransaction(); |
| 19 | |
| 20 | $purchaseOrder = new PurchaseOrder(); |
| 21 | $purchaseOrder->supplier()->associate($storePurchaseOrderDTO->supplier); |
| 22 | $purchaseOrder->save(); |
| 23 | |
| 24 | (new IntegrationStoreService())->store($storePurchaseOrderDTO->integration, $purchaseOrder, $user); |
| 25 | |
| 26 | DB::commit(); |
| 27 | } catch (Throwable $exception) { |
| 28 | DB::rollBack(); |
| 29 | throw $exception; |
| 30 | } |
| 31 | |
| 32 | ServiceProcessed::dispatch(self::class, $user); |
| 33 | return $purchaseOrder; |
| 34 | } |
| 35 | } |