mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-28 17:03:59 +00:00
fix account statement transaction not tally issue
This commit is contained in:
+92
-33
@@ -7,6 +7,7 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Http\Resources\PaymentTransactionResource;
|
||||
use App\Models\Booking;
|
||||
@@ -45,37 +46,49 @@ class FetchCompanyTransactionStatementLogic extends AbstractControllerLogic
|
||||
->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]);
|
||||
// ->where('type', '!=', TransactionType::PAYMENT);
|
||||
})
|
||||
->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')
|
||||
->paginate($filterArray->per_page);
|
||||
|
||||
$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);
|
||||
$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) {
|
||||
@@ -83,64 +96,110 @@ class FetchCompanyTransactionStatementLogic extends AbstractControllerLogic
|
||||
->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, $transactions) {
|
||||
$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, $transactions) {
|
||||
$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;
|
||||
|
||||
$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);
|
||||
$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)
|
||||
->where('id', '>', $transactions->first()->id);
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->where('id', '>', $transactions->first()->id)
|
||||
->where('type', '!=', TransactionType::PAYMENT);
|
||||
})
|
||||
->orWhere(function ($query) use ($companyId, $transactions) {
|
||||
$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('id', '>', $transactions->first()->id);
|
||||
->where('payment_method', '!=', PaymentMethodType::WALLET)
|
||||
->where('id', '>', $transactions->first()->id)
|
||||
->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();
|
||||
|
||||
$incoming = $incoming->sum(function ($transaction) {
|
||||
if ($transaction->type === TransactionType::INVOICE) {
|
||||
return $transaction->amount / $transaction->currency_rate + $transaction->service_charge;
|
||||
}
|
||||
|
||||
return $transaction->amount;
|
||||
});
|
||||
|
||||
$outgoing = Transaction::where(function ($query) use ($companyId, $transactions) {
|
||||
$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);
|
||||
})
|
||||
->where('id', '>', $transactions->first()->id);
|
||||
->where('id', '>', $transactions->first()->id)
|
||||
->whereHas('booking', function ($q) use ($companyId) {
|
||||
$q->where('company_id', $companyId);
|
||||
});
|
||||
})
|
||||
->orWhere(function ($query) use ($companyId, $transactions) {
|
||||
$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('id', '>', $transactions->first()->id)
|
||||
->where('type', TransactionType::PAYMENT);
|
||||
})
|
||||
->sum('transactions.amount');
|
||||
|
||||
$runningBalanceInReverse = $currentBalance - $incoming + $outgoing;
|
||||
|
||||
+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;
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Resources;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Transaction;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Wallet;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
@@ -21,10 +22,19 @@ class PaymentTransactionResource extends JsonResource
|
||||
|
||||
$booking = in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND])? $this->owner->owner : $this->owner;
|
||||
$current_running_balance = $request['running_balance'];
|
||||
$booking_marking = '';
|
||||
|
||||
switch((int) $this->type){
|
||||
case 1:
|
||||
$request['running_balance'] = bcadd($request['running_balance'], $this->amount, 7);
|
||||
switch ($this->owner_type) {
|
||||
case Booking::class:
|
||||
$booking_marking = $booking->marking;
|
||||
break;
|
||||
case Wallet::class:
|
||||
$booking_marking = Transaction::where('payment_reference', $this->bill_no)->first()->owner->marking;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
$request['running_balance'] = bcsub($request['running_balance'], $this->amount / $this->currency_rate + $this->service_charge, 7);
|
||||
@@ -37,16 +47,6 @@ class PaymentTransactionResource extends JsonResource
|
||||
break;
|
||||
}
|
||||
|
||||
$booking_marking = '';
|
||||
switch ($this->owner_type) {
|
||||
case Booking::class:
|
||||
$booking_marking = $booking->marking;
|
||||
break;
|
||||
case Wallet::class:
|
||||
$booking_marking = $this->booking->marking;
|
||||
break;
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'booking_marking' => $booking_marking,
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="row bg-white padding-10 m-b-10 rounded align-datas-center">
|
||||
<div class="col-2 fs-12">{{data.created_at}}</div>
|
||||
<div class="col-3 fs-12">{{ convertTransactionType(data.type) }} {{ data.payment_reference ? ' - ' + data.payment_reference : '' }} <a target=”_blank” v-if="[9,11].includes(data.type) " :href="route('transaction.credit_note.download', data.id)"><i class="fa fa-download fs-11 m-l-5 text-secondary hover-primary"></i></a></div>
|
||||
<div class="col-3 fs-12">{{ convertTransactionType(data.type) }} {{ data.payment_reference ? ' - ' + data.payment_reference : ' - ' + data.bill_no }} <a target=”_blank” v-if="[9,11].includes(data.type) " :href="route('transaction.credit_note.download', data.id)"><i class="fa fa-download fs-11 m-l-5 text-secondary hover-primary"></i></a></div>
|
||||
<div class="col fs-12"><a :href="route('booking.details', data.booking_marking)">{{data.booking_marking}}</a></div>
|
||||
<div class="col-2 text-success text-center" v-if="parseFloat(data.type) !== 2">{{[5, 9].includes(parseFloat(data.type)) ? formatValue(data.amount) : ''}}</div>
|
||||
<div class="col-2 text-success text-center" v-if="parseFloat(data.type) === 2">{{formatValue((parseFloat(data.amount) / parseFloat(data.currency_rate) + parseFloat(data.service_charge)))}}</div>
|
||||
|
||||
@@ -67,13 +67,18 @@
|
||||
|
||||
switch ($transaction->type) {
|
||||
case 1:
|
||||
$description = "Payment - " . $transaction->payment_reference;
|
||||
if ($transaction->owner_type === "App\Models\Booking") {
|
||||
$description = "Payment - " . $transaction->bill_no;
|
||||
$marking = $transaction->owner->marking;
|
||||
} else {
|
||||
$description = "Payment - " . $transaction->bill_no;
|
||||
$marking = App\Models\Transaction::where('payment_reference', $transaction->bill_no)->first()->owner->marking;
|
||||
}
|
||||
$outgoing = number_format($transaction->amount, $roundOff);
|
||||
$runningBalance = bcadd($runningBalance, $transaction->amount, 7);
|
||||
$marking = $transaction->owner->marking;
|
||||
break;
|
||||
case 2:
|
||||
$description = "Invoice";
|
||||
$description = "Invoice - " . $transaction->bill_no;
|
||||
$incoming = number_format(($transaction->amount / $transaction->currency_rate + $transaction->service_charge), $roundOff);
|
||||
$runningBalance = bcsub($runningBalance, ($transaction->amount / $transaction->currency_rate + $transaction->service_charge), 7);
|
||||
$marking = $transaction->owner->marking;
|
||||
|
||||
Reference in New Issue
Block a user