E-Invoice - Update Sales Invoice Report to have paid and unpaid invoices in the report

This commit is contained in:
Dillon Ngo
2025-10-23 18:17:56 +08:00
parent 35932e5351
commit c7f00a7ce2
@@ -73,39 +73,6 @@ class ExportsSalesInvoicesReport implements FromQuery, WithHeadings, WithHeading
]);
// if($this->isUnpaid){
// $approvalStatus = ApprovalStatus::COMPLETED;
// $query->whereIn('type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])
// ->whereNotIn('status', [$approvalStatus])
// ->whereBetween('created_at', [$start_date, $end_date]);
// }
// else{
// $approvalStatus = ApprovalStatus::COMPLETED;
// $query->whereIn('type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])
// ->where('status', $approvalStatus);
// if ($start_date && $end_date) {
// $query->whereHas('transactions', function($transaction) use ($start_date, $end_date) {
// $transaction->where('type', TransactionType::PAYMENT)
// ->whereBetween('updated_at', [$start_date, $end_date])
// ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
// });
// } elseif ($start_date) {
// $query->whereHas('transactions', function($transaction) use ($start_date) {
// $transaction->where('type', TransactionType::PAYMENT)
// ->where('updated_at', '>=', $start_date)
// ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
// });
// } elseif ($end_date) {
// $query->whereHas('transactions', function($transaction) use ($end_date) {
// $transaction->where('type', TransactionType::PAYMENT)
// ->where('updated_at', '<=', $end_date)
// ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
// });
// }
// }
if($this->isUnpaid){
$approvalStatus = ApprovalStatus::COMPLETED;
$query->whereIn('type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])
@@ -113,54 +80,85 @@ class ExportsSalesInvoicesReport implements FromQuery, WithHeadings, WithHeading
->whereBetween('created_at', [$start_date, $end_date]);
}
else{
//This will query everything both paid and unpaid unlike previously paid only
// $query->whereIn('type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])
// ->whereBetween('created_at', [$start_date, $end_date]);
$approvalStatus = ApprovalStatus::COMPLETED;
$invoiceTypes = [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE];
$query->whereIn('type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])
->where('status', $approvalStatus);
$query->whereIn('type', $invoiceTypes)
->where(function ($q) use ($approvalStatus, $start_date, $end_date) {
$q->where(function ($sub) use ($approvalStatus, $start_date, $end_date) {
$sub->where('status', $approvalStatus);
if ($start_date && $end_date) {
$sub->whereHas('transactions', function($transaction) use ($start_date, $end_date) {
$transaction->where('type', TransactionType::PAYMENT)
->whereBetween('updated_at', [$start_date, $end_date])
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
});
} elseif ($start_date) {
$sub->whereHas('transactions', function($transaction) use ($start_date) {
$transaction->where('type', TransactionType::PAYMENT)
->where('updated_at', '>=', $start_date)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
});
} elseif ($end_date) {
$sub->whereHas('transactions', function($transaction) use ($end_date) {
$transaction->where('type', TransactionType::PAYMENT)
->where('updated_at', '<=', $end_date)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
});
}
if ($start_date && $end_date) {
$query->whereHas('transactions', function($transaction) use ($start_date, $end_date) {
$transaction->where('type', TransactionType::PAYMENT)
->whereBetween('updated_at', [$start_date, $end_date])
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
});
// ->orWhere(function ($sub) use ($approvalStatus, $start_date, $end_date) {
// $sub->whereNotIn('status', [$approvalStatus])
// ->whereBetween('created_at', [$start_date, $end_date]);
// });
});
} elseif ($start_date) {
$query->whereHas('transactions', function($transaction) use ($start_date) {
$transaction->where('type', TransactionType::PAYMENT)
->where('updated_at', '>=', $start_date)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
});
} elseif ($end_date) {
$query->whereHas('transactions', function($transaction) use ($end_date) {
$transaction->where('type', TransactionType::PAYMENT)
->where('updated_at', '<=', $end_date)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
});
}
}
// if($this->isUnpaid){
// $approvalStatus = ApprovalStatus::COMPLETED;
// $query->whereIn('type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])
// ->whereNotIn('status', [$approvalStatus])
// ->whereBetween('created_at', [$start_date, $end_date]);
// }
// else{
// //This will query everything both paid and unpaid unlike previously paid only
// // $query->whereIn('type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])
// // ->whereBetween('created_at', [$start_date, $end_date]);
// $approvalStatus = ApprovalStatus::COMPLETED;
// $invoiceTypes = [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE];
// $query->whereIn('type', $invoiceTypes)
// ->where(function ($q) use ($approvalStatus, $start_date, $end_date) {
// $q->where(function ($sub) use ($approvalStatus, $start_date, $end_date) {
// $sub->where('status', $approvalStatus);
// if ($start_date && $end_date) {
// $sub->whereHas('transactions', function($transaction) use ($start_date, $end_date) {
// $transaction->where('type', TransactionType::PAYMENT)
// ->whereBetween('updated_at', [$start_date, $end_date])
// ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
// });
// } elseif ($start_date) {
// $sub->whereHas('transactions', function($transaction) use ($start_date) {
// $transaction->where('type', TransactionType::PAYMENT)
// ->where('updated_at', '>=', $start_date)
// ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
// });
// } elseif ($end_date) {
// $sub->whereHas('transactions', function($transaction) use ($end_date) {
// $transaction->where('type', TransactionType::PAYMENT)
// ->where('updated_at', '<=', $end_date)
// ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
// });
// }
// });
// // ->orWhere(function ($sub) use ($approvalStatus, $start_date, $end_date) {
// // $sub->whereNotIn('status', [$approvalStatus])
// // ->whereBetween('created_at', [$start_date, $end_date]);
// // });
// });
// }
return $query;
}
public function map($transaction): array
{
Log::info('Transaction: ' . json_encode($transaction));
$container = $transaction->owner ? $transaction->owner->containers->first() : null;
$packingList = $transaction->owner;
if(!$packingList) return[];