Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| EnsureDefaultCommissionRuleAction | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| execute | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Financial\Application\Actions; |
| 6 | |
| 7 | use ImovelZapAi\Financial\Domain\Enums\CommissionBasis; |
| 8 | use ImovelZapAi\Financial\Domain\Enums\DealFinanceType; |
| 9 | use ImovelZapAi\Financial\Infrastructure\Persistence\Eloquent\FinancialCommissionRuleModel; |
| 10 | |
| 11 | final class EnsureDefaultCommissionRuleAction |
| 12 | { |
| 13 | public function execute(string $tenantId): FinancialCommissionRuleModel |
| 14 | { |
| 15 | $existing = FinancialCommissionRuleModel::query() |
| 16 | ->where('tenant_id', $tenantId) |
| 17 | ->where('is_default', true) |
| 18 | ->where('is_active', true) |
| 19 | ->first(); |
| 20 | |
| 21 | if ($existing !== null) { |
| 22 | return $existing; |
| 23 | } |
| 24 | |
| 25 | return FinancialCommissionRuleModel::query()->create([ |
| 26 | 'tenant_id' => $tenantId, |
| 27 | 'name' => 'Comissão padrão venda', |
| 28 | 'basis' => CommissionBasis::Percent, |
| 29 | 'value' => 6, |
| 30 | 'deal_type' => DealFinanceType::Sale, |
| 31 | 'split_json' => null, |
| 32 | 'is_default' => true, |
| 33 | 'is_active' => true, |
| 34 | ]); |
| 35 | } |
| 36 | } |