|
|
@@ -4,7 +4,6 @@
|
|
|
|
|
|
use App\Enums\ReceivableStatus;
|
|
|
use App\Models\FranchiseeAccountReceive;
|
|
|
-use App\Models\StudentContractInstallment;
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
@@ -55,17 +54,11 @@ public function handle(): void
|
|
|
$type = 'unknown';
|
|
|
|
|
|
if ($externalReference) {
|
|
|
- // Se for um recebível de Franquia
|
|
|
+ // Recebível de Franquia (TBR) cobrado pela conta da Matriz.
|
|
|
if (str_starts_with($externalReference, 'TBR_')) {
|
|
|
$id = str_replace('TBR_', '', $externalReference);
|
|
|
$receive = FranchiseeAccountReceive::find($id);
|
|
|
$type = 'FranchiseeAccountReceive';
|
|
|
- }
|
|
|
- // Se for parcela de aluno
|
|
|
- elseif (str_starts_with($externalReference, 'STU_')) {
|
|
|
- $id = str_replace('STU_', '', $externalReference);
|
|
|
- $receive = StudentContractInstallment::find($id);
|
|
|
- $type = 'StudentContractInstallment';
|
|
|
}
|
|
|
// Backward compatibility para faturas de teste geradas antes do prefixo
|
|
|
elseif (is_numeric($externalReference)) {
|
|
|
@@ -77,14 +70,9 @@ public function handle(): void
|
|
|
// Fallback por asaas_id caso externalReference venha nulo
|
|
|
if (!$receive && $asaasId) {
|
|
|
$receive = FranchiseeAccountReceive::where('asaas_id', $asaasId)->first();
|
|
|
-
|
|
|
+
|
|
|
if ($receive) {
|
|
|
$type = 'FranchiseeAccountReceive (by asaas_id)';
|
|
|
- } else {
|
|
|
- $receive = StudentContractInstallment::where('asaas_id', $asaasId)->first();
|
|
|
- if ($receive) {
|
|
|
- $type = 'StudentContractInstallment (by asaas_id)';
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -97,8 +85,7 @@ public function handle(): void
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // Conversão de status: se a model usa string (como StudentContractInstallment)
|
|
|
- // Precisamos comparar de forma segura
|
|
|
+ // Comparação segura de status (a model pode expor enum ou string).
|
|
|
$currentStatus = $receive->status instanceof ReceivableStatus ? $receive->status->value : $receive->status;
|
|
|
$newStatusValue = $newStatus instanceof ReceivableStatus ? $newStatus->value : $newStatus;
|
|
|
|
|
|
@@ -115,7 +102,6 @@ public function handle(): void
|
|
|
|
|
|
if ($newStatusValue === ReceivableStatus::PAID->value) {
|
|
|
$updateData['payment_date'] = $payment['paymentDate'] ?? $payment['confirmedDate'] ?? now();
|
|
|
- // A tabela do Aluno usa 'paid_value', a tabela da Franquia também.
|
|
|
$updateData['paid_value'] = $payment['value'] ?? $receive->value;
|
|
|
}
|
|
|
|