mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-23 22:44:03 +00:00
fix account statement transaction not tally issue
This commit is contained in:
+52
-20
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Http\Controllers\Exports;
|
||||
|
||||
use App\Classes\Modules\Exports\Services\ExportsCustomersWalletTransactionHistory;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Company;
|
||||
@@ -13,14 +13,13 @@ use App\Models\Wallet;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Excel;
|
||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
|
||||
class ExportCustomersAccountStatementTransactionToPDFController
|
||||
{
|
||||
|
||||
/**
|
||||
* ExportCustomersWalletTransactionToExcelController constructor.
|
||||
* ExportCustomersAccountStatementTransactionToPDFController constructor.
|
||||
* @param Request $request
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
@@ -42,37 +41,48 @@ class ExportCustomersAccountStatementTransactionToPDFController
|
||||
->where('type', TransactionType::PAYMENT)
|
||||
->where('owner_type', Booking::class)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->where('payment_method', '!=', PaymentMethodType::WALLET)
|
||||
->whereHas('booking', function ($q) use ($companyId) {
|
||||
$q->where('company_id', $companyId);
|
||||
});
|
||||
})
|
||||
->orWhere(function ($query) use ($companyId) {
|
||||
$query->whereHas('owner', function ($query) use ($companyId) {
|
||||
$query->where('owner_id', $companyId);
|
||||
$query->where('owner_type', Company::class);
|
||||
$query->whereHas('owner', function ($q) use ($companyId) {
|
||||
$q->where('owner_id', $companyId);
|
||||
$q->where('owner_type', Company::class);
|
||||
})
|
||||
->where('owner_type', Wallet::class)
|
||||
->where('type', '!=', TransactionType::PAYMENT);
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
})
|
||||
->orWhere(function ($query) use ($companyId) {
|
||||
$query
|
||||
->where('type', TransactionType::INVOICE)
|
||||
->where('owner_type', Booking::class)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->whereHas('booking', function ($query) use ($companyId) {
|
||||
$query->where('company_id', $companyId);
|
||||
->where('payment_method', '!=', PaymentMethodType::WALLET)
|
||||
->whereHas('booking', function ($q) use ($companyId) {
|
||||
$q->where('company_id', $companyId);
|
||||
});
|
||||
})
|
||||
->groupBy(
|
||||
DB::raw(
|
||||
'if (transactions.type = 2,transactions.owner_id,transactions.id)'
|
||||
),
|
||||
DB::raw(
|
||||
'if (transactions.type = 2,transactions.type,transactions.id)'
|
||||
)
|
||||
)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
|
||||
$total_incoming = Transaction::where(function ($query) use ($companyId, $transactions) {
|
||||
$query->whereHas('owner', function ($query) use ($companyId) {
|
||||
$query->where('owner_id', $companyId);
|
||||
$query->where('owner_type', Company::class);
|
||||
$total_incoming = Transaction::where(function ($query) use ($companyId) {
|
||||
$query->whereHas('owner', function ($q) use ($companyId) {
|
||||
$q->where('owner_id', $companyId);
|
||||
$q->where('owner_type', Company::class);
|
||||
})
|
||||
->where('owner_type', Wallet::class)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->where('type', '!=', TransactionType::PAYMENT);
|
||||
})
|
||||
->orWhere(function ($query) use ($companyId, $transactions) {
|
||||
@@ -80,25 +90,47 @@ class ExportCustomersAccountStatementTransactionToPDFController
|
||||
->where('type', TransactionType::INVOICE)
|
||||
->where('owner_type', Booking::class)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->whereHas('booking', function ($query) use ($companyId) {
|
||||
$query->where('company_id', $companyId);
|
||||
->where('payment_method', '!=', PaymentMethodType::WALLET)
|
||||
->whereHas('booking', function ($q) use ($companyId) {
|
||||
$q->where('company_id', $companyId);
|
||||
});
|
||||
})
|
||||
->sum(
|
||||
->groupBy(
|
||||
DB::raw(
|
||||
'if (transactions.type = 2,(transactions.amount / transactions.currency_rate + transactions.service_charge),transactions.amount)'
|
||||
'if (transactions.type = 2,transactions.owner_id,transactions.id)'
|
||||
),
|
||||
DB::raw(
|
||||
'if (transactions.type = 2,transactions.type,transactions.id)'
|
||||
)
|
||||
);
|
||||
)->get();
|
||||
|
||||
$total_incoming = $total_incoming->sum(function ($transaction) {
|
||||
if ($transaction->type === TransactionType::INVOICE) {
|
||||
return $transaction->amount / $transaction->currency_rate + $transaction->service_charge;
|
||||
}
|
||||
|
||||
return $transaction->amount;
|
||||
});
|
||||
|
||||
$total_outgoing = Transaction::where(function ($query) use ($companyId) {
|
||||
$query
|
||||
->where('type', TransactionType::PAYMENT)
|
||||
->where('payment_method', '!=', PaymentMethodType::WALLET)
|
||||
->where('owner_type', Booking::class)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->whereHas('booking', function ($query) use ($companyId) {
|
||||
$query->where('company_id', $companyId);
|
||||
->whereHas('booking', function ($q) use ($companyId) {
|
||||
$q->where('company_id', $companyId);
|
||||
});
|
||||
})
|
||||
->orWhere(function ($query) use ($companyId) {
|
||||
$query->whereHas('owner', function ($q) use ($companyId) {
|
||||
$q->where('owner_id', $companyId);
|
||||
$q->where('owner_type', Company::class);
|
||||
})
|
||||
->where('owner_type', Wallet::class)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->where('type', TransactionType::PAYMENT);
|
||||
})
|
||||
->sum('transactions.amount');
|
||||
|
||||
$currentBalance = $total_incoming - $total_outgoing;
|
||||
|
||||
Reference in New Issue
Block a user