- Introduce CreateRecordTransactionsAction to handle transaction creation for any model - Introduce SyncAccountsAction to encapsulate account synchronization logic - Refactor CreateSaleAction to use new actions and handle full sale creation flow - Simplify CreateExpense and CreateSale pages by delegating to actions - Ensure proper transaction handling with database rollback on failure
31 lines
795 B
PHP
31 lines
795 B
PHP
<?php
|
|
|
|
namespace App\Actions\Transactions;
|
|
|
|
use App\DataObjects\CreateTransactionDTO;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Pipeline;
|
|
|
|
class CreateRecordTransactionsAction
|
|
{
|
|
public function __invoke(Model $record, array $transactions): void
|
|
{
|
|
foreach ($transactions as $transaction) {
|
|
$tData = [
|
|
'branch_id' => $record->branch_id,
|
|
'happened_on' => $record->happened_on,
|
|
...$transaction,
|
|
];
|
|
|
|
$payload = new CreateTransactionDTO(data: $tData, transactionable: $record);
|
|
|
|
Pipeline::send(passable: $payload)->through(
|
|
[
|
|
CreateTransactionAction::class,
|
|
]
|
|
)->thenReturn();
|
|
}
|
|
}
|
|
}
|
|
|