Add feature for online transaction report
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\TransactionOnline;
|
||||
|
||||
class BayaranOnlineController extends Controller
|
||||
{
|
||||
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
$transactionOnlineQuery = TransactionOnline::filter($request);
|
||||
|
||||
$formatMoney = fn($x) => number_format($x, 2, '.', ',');
|
||||
|
||||
$sumTotalPayments = (clone $transactionOnlineQuery)->sum('total_payment');
|
||||
$sumTotalPayments = $formatMoney($sumTotalPayments);
|
||||
$nosPayments = (clone $transactionOnlineQuery)->count('total_payment');
|
||||
|
||||
$transactions = (clone $transactionOnlineQuery)->select('kodcaw', DB::raw('sum(total_payment) as totalCawanganPayment'), DB::raw('count(reference_no) as totalReferenceNo'))
|
||||
->groupBy('kodcaw')
|
||||
->get()
|
||||
->map(function($x) use($formatMoney) {
|
||||
$x['totalCawanganPayment'] = $formatMoney($x['totalCawanganPayment']);
|
||||
return $x;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'nosPayments' => $nosPayments,
|
||||
'sumTotalPayments' => $sumTotalPayments,
|
||||
'transactions' => $transactions,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\TransactionOnline;
|
||||
|
||||
class BayaranOnlineDetailController extends Controller
|
||||
{
|
||||
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
|
||||
$transactionOnlineQuery = TransactionOnline::filter($request);
|
||||
|
||||
$formatMoney = fn($x) => number_format($x, 2, '.', ',');
|
||||
|
||||
$sumTotalPayments = (clone $transactionOnlineQuery)->sum('total_payment');
|
||||
$sumTotalPayments = $formatMoney($sumTotalPayments);
|
||||
$sumPaymentNos = (clone $transactionOnlineQuery)->count('total_payment');
|
||||
|
||||
$transactions = (clone $transactionOnlineQuery)->select('nokp', 'customer_name', 'norujukan', 'reference_no', 'kodcaw', 'total_payment', 'tarikh', 'masa', 'status')
|
||||
->get()
|
||||
->groupBy('nokp')
|
||||
->map(fn($x) => $x->groupBy('cawangan.details_caw'))
|
||||
->map(function ($cawangan) {
|
||||
|
||||
$all_entries = $cawangan->collapse();
|
||||
|
||||
$first = $all_entries->first();
|
||||
|
||||
$payment_details = $cawangan->map(function ($cawangan_payments) {
|
||||
return [
|
||||
'paymentNos' => $cawangan_payments->count(),
|
||||
'paymentSum' => $cawangan_payments->sum('total_payment'),
|
||||
'paymentDetails' => $cawangan_payments->map(function ($x) {
|
||||
|
||||
$payment_details = collect($x)->except('nokp', 'customer_name', 'kodcaw', 'cawangan');
|
||||
|
||||
return $payment_details;
|
||||
}),
|
||||
];
|
||||
});
|
||||
|
||||
return [
|
||||
'customer_name' => $first->customer_name,
|
||||
'nokp' => $first->nokp,
|
||||
'payments' => $payment_details,
|
||||
];
|
||||
})
|
||||
->values();
|
||||
|
||||
|
||||
return response()->json([
|
||||
'sumTotalPayments' => $sumTotalPayments,
|
||||
'sumPaymentNos' => $sumPaymentNos,
|
||||
'transactions' => $transactions,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\QueryBuilders;
|
||||
|
||||
use App\TransactionOnline;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TransactionOnlineBuilder extends Builder
|
||||
{
|
||||
public function filter(Request $request)
|
||||
{
|
||||
return $this->with('cawangan')
|
||||
->whereDatePaidBetween($request)
|
||||
->when($request->filled('kodcaw'), fn($query) => $query->whereCawanganCode($request->kodcaw))
|
||||
->when($request->filled('status'), fn($query) => $query->whereStatus($request->status))
|
||||
->when($request->isNotFilled('status'), fn($query) => $query->whereStatus('PAID'));
|
||||
}
|
||||
|
||||
public function whereDatePaidBetween(Request $request): self
|
||||
{
|
||||
$startDate = $request->filled('startDate') ?
|
||||
Carbon::parse($request->startDate)->startOfDay() :
|
||||
Carbon::now()->startOfDay();
|
||||
|
||||
$endDate = $request->filled('endDate') ?
|
||||
Carbon::parse($request->endDate)->startOfDay() :
|
||||
Carbon::now()->startOfDay();
|
||||
|
||||
return $this->whereBetween('paid_at', [$startDate, $endDate]);
|
||||
}
|
||||
|
||||
public function whereCawanganCode(string $kodcaw): self
|
||||
{
|
||||
return $this->where('kodcaw', $kodcaw);
|
||||
}
|
||||
|
||||
public function whereStatus(string $status): self
|
||||
{
|
||||
return $this->where('status', $status);
|
||||
}
|
||||
|
||||
public function orderBy(string $orderBy): self
|
||||
{
|
||||
return $this->orderBy($orderBy);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\QueryBuilders\TransactionOnlineBuilder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TransactionOnline extends Model
|
||||
@@ -24,4 +25,14 @@ class TransactionOnline extends Model
|
||||
* @var array
|
||||
*/
|
||||
// protected $hidden = [];
|
||||
|
||||
public function cawangan()
|
||||
{
|
||||
return $this->belongsTo(Cawangan::class, 'kodcaw', 'kodcaw');
|
||||
}
|
||||
|
||||
public function newEloquentBuilder($query)
|
||||
{
|
||||
return new TransactionOnlineBuilder($query);
|
||||
}
|
||||
}
|
||||
|
||||
+11
-7
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
use App\TransactionOnline;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
$router->group(['prefix' => 'api/reports'], function () use ($router) {
|
||||
$router->group(['namespace' => 'Reports'], function () use ($router) {
|
||||
$router->get('gadaian', ['uses' => 'GadaianController@getSummaryLaporanGadai']);
|
||||
@@ -21,15 +24,15 @@ $router->group(['prefix' => 'api/reports'], function () use ($router) {
|
||||
$router->get('rounded/ledger/{kod_cawangan}', ['uses' => 'OnePercentController@getRoundedLejerAm']);
|
||||
$router->get('totalrebate', ['uses' => 'OnePercentController@getTotalRebate']);
|
||||
$router->get('getaccrualincome', ['uses' => 'OnePercentController@getAccruedincome']);
|
||||
$router->get('getaccrualincome/all',['uses' => 'OnePercentController@getAllCawanganAccruedIncome']);
|
||||
$router->get('getaccrualincome/all', ['uses' => 'OnePercentController@getAllCawanganAccruedIncome']);
|
||||
$router->get('getTotalCurrentProfit/{kod_cawangan}', ['uses' => 'OnePercentController@getCurrentProfit']);
|
||||
|
||||
$router->get('stokaudit/get',['uses' => 'OnePercentController@getStokAuditBackdate']);
|
||||
$router->get('stokaudit/get', ['uses' => 'OnePercentController@getStokAuditBackdate']);
|
||||
|
||||
$router->get('balancesheets/get',['uses' => 'BalanceSheetsController@getBalanceSheetsList']);
|
||||
$router->get('balancesheets/get', ['uses' => 'BalanceSheetsController@getBalanceSheetsList']);
|
||||
|
||||
$router->get('updateig',['uses' => 'BalanceSheetsController@insertBalanceSheets']);
|
||||
$router->get('updateigall',['uses' => 'BalanceSheetsController@updateIGBalanceSheets']);
|
||||
$router->get('updateig', ['uses' => 'BalanceSheetsController@insertBalanceSheets']);
|
||||
$router->get('updateigall', ['uses' => 'BalanceSheetsController@updateIGBalanceSheets']);
|
||||
|
||||
$router->get('lelongan', ['uses' => 'LelonganController@getSummaryLaporanLelong']);
|
||||
$router->get('lelongan/{kod_cawangan}', ['uses' => 'LelonganController@getLaporanCawangan']);
|
||||
@@ -43,9 +46,10 @@ $router->group(['prefix' => 'api/reports'], function () use ($router) {
|
||||
$router->get('pelangganbaru', ['uses' => 'AnalisaController@getSummaryLaporanPelangganBaru']);
|
||||
|
||||
$router->get('pelangganaktif', ['uses' => 'AnalisaController@getSummaryLaporanPelangganAktif']);
|
||||
|
||||
|
||||
$router->get('bakilelongbelumtuntut', ['uses' => 'LelonganController@getSummaryLaporanBakiLelongBelumTuntut']);
|
||||
$router->get('bakilelongbelumtuntut/{kod_cawangan}', ['uses' => 'LelonganController@getLaporanBakiLelongBelumTuntutCawangan']);
|
||||
|
||||
$router->get('bayaran-online', ['uses' => 'BayaranOnlineController']);
|
||||
$router->get('bayaran-online-detail', ['uses' => 'BayaranOnlineDetailController']);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user