mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-24 15:04:19 +00:00
Merge branch 'dillon/90-e-invoice-e-1' into vapor/staging
This commit is contained in:
@@ -14,6 +14,7 @@ use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundAmount;
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundServiceCharge;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize
|
||||
{
|
||||
@@ -63,7 +64,12 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR
|
||||
|
||||
$startDate = $this->startDate;
|
||||
$endDate = $this->endDate;
|
||||
return Booking::where('status', ApprovalStatus::COMPLETED)
|
||||
return Booking::with([
|
||||
'company',
|
||||
'transactions.transactionDetails',
|
||||
'transactions.voucherRedemption'
|
||||
])
|
||||
->where('status', ApprovalStatus::COMPLETED)
|
||||
->whereHas('transactions', function ($query) use ($startDate, $endDate) {
|
||||
$query->payments()
|
||||
->complete()
|
||||
@@ -82,16 +88,22 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR
|
||||
$averageCurrencyRate = 0;
|
||||
$currencyId = 0;
|
||||
|
||||
$purchaseOrder = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first();
|
||||
$company = $booking->company()->first();
|
||||
$purchaseOrder = $booking->transactions->where('type', TransactionType::PURCHASE_ORDER)->first();
|
||||
$company = $booking->company;
|
||||
|
||||
|
||||
$lastPaymentTransaction = $booking->transactions()->payments()->complete()->latest()->first();
|
||||
$lastPaymentTransaction = $booking->transactions
|
||||
->where('type', TransactionType::PAYMENT)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->sortByDesc('created_at')
|
||||
->first();
|
||||
if(!$lastPaymentTransaction){
|
||||
return $records;
|
||||
}
|
||||
|
||||
$documentDate = $lastPaymentTransaction->created_at;
|
||||
// $documentDate = $lastPaymentTransaction->created_at;
|
||||
$documentDate = Carbon::parse($lastPaymentTransaction->created_at);
|
||||
|
||||
if ($documentDate < $this->startDate || $documentDate > $this->endDate) {
|
||||
return $records;
|
||||
}
|
||||
@@ -100,7 +112,7 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR
|
||||
$documentDate = $documentDate->copy()->endOfMonth();
|
||||
}
|
||||
|
||||
$invoiceTransaction = $booking->transactions()->where('type', TransactionType::INVOICE)->complete()->first();
|
||||
$invoiceTransaction = $booking->transactions->where('type', TransactionType::INVOICE)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->first();
|
||||
|
||||
$currencyId = $booking->fix_currency_id;
|
||||
|
||||
@@ -108,21 +120,19 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR
|
||||
$displayedSubtotal = 0;
|
||||
$totalPayment = 0;
|
||||
$averageCurrencyRate = $invoiceTransaction->currency_rate;
|
||||
$paymentSum = $booking->transactions()
|
||||
$paymentSum = $booking->transactions
|
||||
->where('type', TransactionType::PAYMENT)
|
||||
->where('status', ApprovalStatus::COMPLETED)
|
||||
->get()
|
||||
->sum(function ($transaction) {
|
||||
return round($transaction->amount, 2);
|
||||
});
|
||||
if ($paymentSum){
|
||||
$averageCurrencyRate = $booking->transactions()
|
||||
$averageCurrencyRate = $booking->transactions
|
||||
->where('type', TransactionType::PAYMENT)
|
||||
->where('status', ApprovalStatus::COMPLETED)
|
||||
->get()
|
||||
->sum(function ($transaction) {
|
||||
return $transaction->currency_rate;
|
||||
}) / $booking->transactions()
|
||||
}) / $booking->transactions
|
||||
->where('type', TransactionType::PAYMENT)
|
||||
->where('status', ApprovalStatus::COMPLETED)
|
||||
->count();
|
||||
@@ -178,10 +188,9 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR
|
||||
$serviceCharge = $invoiceTransaction->service_charge;
|
||||
}
|
||||
else {
|
||||
$serviceCharge = $booking->transactions()
|
||||
$serviceCharge = $booking->transactions
|
||||
->where('type', TransactionType::PAYMENT)
|
||||
->where('status', ApprovalStatus::COMPLETED)
|
||||
->get()
|
||||
->sum(function ($transaction) {
|
||||
return $transaction->service_charge;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user