tambah laporan lelong dalam admin
This commit is contained in:
@@ -1758,83 +1758,96 @@ class AkaunController extends Controller
|
||||
}
|
||||
|
||||
public function cetak_laporanlelong(Request $request)
|
||||
{
|
||||
$api_url = $request->hostname;
|
||||
$auth_user = Auth::user();
|
||||
$current = Carbon::now();
|
||||
$tarikh_cetak = $current->toDateString();
|
||||
{
|
||||
// dd($request->all());
|
||||
$api_url = $request->hostname;
|
||||
$auth_user = Auth::user();
|
||||
$current = Carbon::now();
|
||||
$tarikh_cetak = $current->toDateString();
|
||||
$batchno = $request->batchno;
|
||||
|
||||
$mula_date = $request->datemula ?? '2017-01-01';
|
||||
$hingga_date = $request->datehingga ?? $current->toDateString();
|
||||
// Get input parameters, including batchno
|
||||
$mula_date = $request->tarikhmula ?? '2017-01-01';
|
||||
// dd($mula_date);
|
||||
$hingga_date = $request->tarikhhingga ?? $current->toDateString();
|
||||
// $batchno = $request->batchno ?? null; // Batch Number from input
|
||||
// dd($request->batchno);
|
||||
|
||||
$lelong = Http::get($request->hostname . 'api/laporan/lelong', [
|
||||
'kodcaw' => $request->kodcaw,
|
||||
'tarikh_mula' => $mula_date,
|
||||
'tarikh_akhir' => $hingga_date
|
||||
])->json();
|
||||
// Fetch lelong report data with batchno filter
|
||||
$lelong = Http::get($request->hostname . '/api/laporan/lelong', [
|
||||
'kodcaw' => $request->kodcaw,
|
||||
'tarikhmula' => $mula_date,
|
||||
'tarikhhingga' => $hingga_date,
|
||||
'batchno' => $request->batchno // Include batch number in API request
|
||||
])->json();
|
||||
// dd($lelong);
|
||||
|
||||
// Initialize variables
|
||||
$bakilelong = 0;
|
||||
$rugilelong = 0;
|
||||
// Initialize totals
|
||||
$bakilelong = 0;
|
||||
$rugilelong = 0;
|
||||
|
||||
// Ensure 'data' key exists before looping
|
||||
if (isset($lelong['data']) && is_array($lelong['data'])) {
|
||||
foreach ($lelong['data'] as $key => $item) {
|
||||
// Check if 'nokp' exists and is not null
|
||||
$lelong['data'][$key]['nama_cust'] = isset($item['nokp']) && !empty($item['nokp'])
|
||||
? Http::get($request->hostname . 'api/customers/' . $item['nokp'])->json()['nama'] ?? 'Unknown'
|
||||
: 'Unknown';
|
||||
// Ensure 'data' key exists before looping
|
||||
if (isset($lelong['data']) && is_array($lelong['data'])) {
|
||||
foreach ($lelong['data'] as $key => $item) {
|
||||
// Fetch customer name if nokp exists
|
||||
$lelong['data'][$key]['nama_cust'] = isset($item['nokp']) && !empty($item['nokp'])
|
||||
? Http::get($request->hostname . '/api/customers/' . $item['nokp'])->json()['nama'] ?? 'Unknown'
|
||||
: 'Unknown';
|
||||
|
||||
// ✅ Accumulate `bakilelong` and `rugilelong` based on `baki`
|
||||
if (isset($item['baki'])) {
|
||||
if ($item['baki'] > 0) {
|
||||
$bakilelong += $item['baki'];
|
||||
} else {
|
||||
$rugilelong += $item['baki'];
|
||||
// Accumulate bakilelong and rugilelong
|
||||
if (isset($item['baki'])) {
|
||||
if ($item['baki'] > 0) {
|
||||
$bakilelong += $item['baki'];
|
||||
} else {
|
||||
$rugilelong += $item['baki'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// dd($lelong);
|
||||
$tlelong = $lelong['tarikh_lelong'];
|
||||
|
||||
// Get totals from API response
|
||||
$total_pinjaman = $lelong['total_pinjaman'] ?? 0;
|
||||
$total_nilaimarhun = $lelong['total_nilaimarhun'] ?? 0;
|
||||
$total_keuntungan = $lelong['total_keuntungan'] ?? 0;
|
||||
$total_onepercent = $lelong['total_onepercent'] ?? 0;
|
||||
$total_ujrah = $lelong['total_ujrah'] ?? 0;
|
||||
$total_cajlelong = $lelong['total_cajlelong'] ?? 0;
|
||||
$total_hargajual = $lelong['total_hargajual'] ?? 0;
|
||||
$total_baki = $lelong['total_baki'] ?? 0;
|
||||
$total_hargaasas = $lelong['total_hargaasas'] ?? 0;
|
||||
// Fetch total values from API response
|
||||
$total_pinjaman = $lelong['totals']['total_pinjaman'] ?? 0;
|
||||
$total_nilaimarhun = $lelong['totals']['total_nilaimarhun'] ?? 0;
|
||||
$total_keuntungan = $lelong['totals']['total_keuntungan'] ?? 0;
|
||||
$total_onepercent = $lelong['totals']['total_onepercent'] ?? 0;
|
||||
$total_ujrah = $lelong['totals']['total_ujrah'] ?? 0;
|
||||
$total_cajlelong = $lelong['totals']['total_cajlelong'] ?? 0;
|
||||
$total_hargajual = $lelong['totals']['total_hargajual'] ?? 0;
|
||||
$total_baki = $lelong['totals']['total_baki'] ?? 0;
|
||||
$total_hargaasas = $lelong['totals']['total_hargaasas'] ?? 0;
|
||||
|
||||
// Fetch cawangan details
|
||||
$cawangan_info = Http::get($request->hostname . '/api/cawangan/'. $request->kodcaw)->json();
|
||||
$cawangan = Http::get($request->hostname . '/api/cawangan/detail/'. $request->kodcaw)->json();
|
||||
$cawangan_detail = $cawangan[0];
|
||||
// Fetch branch details
|
||||
$cawangan_info = Http::get($request->hostname . '/api/cawangan/'. $request->kodcaw)->json();
|
||||
$cawangan = Http::get($request->hostname . '/api/cawangan/detail/'. $request->kodcaw)->json();
|
||||
$cawangan_detail = $cawangan[0];
|
||||
|
||||
$hostname = $request->hostname;
|
||||
$hostname = $request->hostname;
|
||||
|
||||
if (isset($request->jenis) && $request->jenis == 'pdf') {
|
||||
$pdf = PDF::loadView('akaun.laporan_lelong', compact(
|
||||
// Check if the request is for PDF generation
|
||||
if (isset($request->jenis) && $request->jenis == 'pdf') {
|
||||
$pdf = PDF::loadView('akaun.laporan_lelong', compact(
|
||||
'total_pinjaman', 'total_nilaimarhun', 'total_keuntungan', 'total_onepercent',
|
||||
'total_ujrah', 'total_cajlelong', 'total_hargajual', 'total_baki',
|
||||
'total_hargaasas', 'hostname', 'lelong', 'cawangan_detail',
|
||||
'tarikh_cetak', 'mula_date', 'hingga_date', 'api_url',
|
||||
'bakilelong', 'rugilelong', 'batchno','tlelong' // Pass batchno to view
|
||||
))->setPaper('a4', 'landscape');
|
||||
|
||||
return $pdf->download('laporan_lelong_' . $request->kodcaw . '_' . $mula_date . '_' . $hingga_date . '_batch_' . $batchno . '.pdf');
|
||||
}
|
||||
|
||||
// Return the view with batchno included
|
||||
return view('akaun.laporan_lelong', compact(
|
||||
'total_pinjaman', 'total_nilaimarhun', 'total_keuntungan', 'total_onepercent',
|
||||
'total_ujrah', 'total_cajlelong', 'total_hargajual', 'total_baki',
|
||||
'total_hargaasas', 'hostname', 'lelong', 'cawangan_detail',
|
||||
'tarikh_cetak', 'mula_date', 'hingga_date', 'api_url',
|
||||
'bakilelong', 'rugilelong'
|
||||
))->setPaper('a4', 'portrait');
|
||||
|
||||
return $pdf->download('laporan_lelong_' . $request->kodcaw . '_' . $mula_date . '_' . $hingga_date . '.pdf');
|
||||
'bakilelong', 'rugilelong','batchno','tlelong'
|
||||
));
|
||||
}
|
||||
|
||||
return view('akaun.laporan_lelong', compact(
|
||||
'total_pinjaman', 'total_nilaimarhun', 'total_keuntungan', 'total_onepercent',
|
||||
'total_ujrah', 'total_cajlelong', 'total_hargajual', 'total_baki',
|
||||
'total_hargaasas', 'hostname', 'lelong', 'cawangan_detail',
|
||||
'tarikh_cetak', 'mula_date', 'hingga_date', 'api_url',
|
||||
'bakilelong', 'rugilelong'
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user