tambah laporan lelong dalam admin

This commit is contained in:
BTMS2
2025-02-26 12:24:55 +08:00
parent 6a21d4afbb
commit 74c9fd1a43
3 changed files with 307 additions and 247 deletions
+72 -59
View File
@@ -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'
));
}
}
+176 -117
View File
@@ -1,128 +1,187 @@
<template>
<div class="container">
<div class="container">
<div class="flex w-full">
<div class="xl:w-2/3 2xl:w-1/2 p-8 mx-auto">
<div class="bg-yellow-600 text-gray-200 text-lg px-6 py-4 rounded-t-lg">
<router-link to="/akaunhome">
<i class="fas fa-backspace text-white"></i>
</router-link>
<span class="text-center mx-auto text-white font-bold">Laporan Lelong</span>
</div>
<form method="get" id="formringter" :action="Urlredirect()" target="_blank">
<div class="rounded bg-white shadow p-6">
<div class="pb-6">
<div class="flex justify-center mb-4">
<input :value="jenisgenerate" type="hidden" name="jenis" />
<input :value="this.$kodcaw" name="kodcaw" hidden />
<input :value="this.$hostname" name="hostname" hidden />
<input :value="selectedbatchlel" name="batchno" hidden />
<span class="text-gray-600 border-2 rounded-l px-4 py-2 whitespace-no-wrap">Mula</span>
<input v-model="tarikhmula" id="tarikhmula" name="tarikhmula" class="border-2 border-l-0 rounded-r px-4 py-2 w-80r mr-2" type="date" min="2023-01-01" :max="maxDate"/>
<span class="text-gray-600 border-2 rounded-l px-4 py-2 whitespace-no-wrap">Hingga</span>
<input v-model="tarikhhingga" id="tarikhhingga" name="tarikhhingga" class="border-2 border-l-0 rounded-r px-4 py-2 w-80r mr-2" type="date" min="2023-01-01" :max="maxDate"/>
</div>
<!-- Batch Lelong Selection -->
<select name="batchno" v-model.trim="selectedbatchlel" class="w-full p-2 rounded-md border bg-white border-gray-400 focus:outline-none focus:ring-1 ring-cyan-500 uppercase" :disabled="filteredBatchlel.length === 0">
<option value="" selected disabled hidden>
{{ filteredBatchlel.length === 0 ? 'Tiada Lelongan' : 'Sila Pilih Batch Lelong' }}
</option>
<option v-for="(slt, i) in filteredBatchlel" :key="i" :value="slt.batchno">
Batch No: {{ slt.batchno }} / Tarikh: {{ formatDate(slt.tarikh) }}
</option>
</select>
<div class="flex w-full">
<div class="xl:w-2/3 2xl:w-1/2 p-8 mx-auto">
<div class="bg-yellow-600 text-gray-200 text-lg px-6 py-4 rounded-t-lg">
<router-link to="/akaunhome">
<i class="fas fa-backspace text-white"></i>
</router-link>
<span class="text-center mx-auto text-white font-bold">Laporan Lelong</span>
</div>
<form method="get" id="formringter" :action="Urlredirect()" target="_blank">
<div class="rounded bg-white shadow p-6">
<div class="pb-6">
<div class="flex justify-center mb-4">
<input :value="jenisgenerate" type="hidden" name="jenis" />
<input :value="$kodcaw" name="kodcaw" hidden/>
<input :value="$hostname" name="hostname" hidden/>
<span style="background-color: #F9FAFB" class="text-gray-600 border-2 rounded-l px-4 py-2 whitespace-no-wrap">Mula</span>
<input id="tarikhmula" name="datemula" class="border-2 border-l-0 rounded-r px-4 py-2 w-80r mr-2" type="date" min="2023-01-01" :max="maxDate"/>
<span style="background-color: #F9FAFB" class="text-gray-600 border-2 rounded-l px-4 py-2 whitespace-no-wrap">Hingga</span>
<input id="tarikhhingga" name="datehingga" class="border-2 border-l-0 rounded-r px-4 py-2 w-80r mr-2" type="date" min="2023-01-01" :max="maxDate"/>
</div>
<!-- <select name="sltalasan" v-model.trim="$v.selectedalasan.$model" class="w-full p-2 rounded-md border bg-white border-gray-400 focus:outline-none focus:ring-1 ring-cyan-500 uppercase">
<option value="" selected disabled hidden>Sila Pilih Alasan Anda Anda***</option>
<option v-for="(slt,i) in jenisalasan" :key="i" :value="slt.alasan">{{ slt.alasan }}</option>
<option value="all">Semua Alasan</option>
<!-- Show message if no batch numbers available -->
<p v-if="filteredBatchlel.length === 0" class="text-red-500 font-semibold mt-2">
Tiada Lelongan dalam tarikh yang dipilih.
</p>
</div>
<div class="flex justify-end mt-10">
<button @click.prevent="generatepdf" class="mr-2 border border-yellow-600 text-yellow-600 font-montserrat py-2 px-8 font-medium rounded-xl hover:bg-yellow-600 hover:text-white transition-all duration-300">
<i class="fas fa-file-pdf mr-2"></i>PDF
</button>
<button @click.prevent="generateview" class="border border-yellow-600 text-yellow-600 font-montserrat py-2 px-8 font-medium rounded-xl hover:bg-yellow-600 hover:text-white transition-all duration-300">
<i class="fas fa-eye mr-2"></i>View
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</template>
<script>
import { required } from 'vuelidate/lib/validators'
import axios from 'axios';
export default {
props: {
kodcaw: String // Ensure kodcaw is received
},
data() {
return {
jenisgenerate: 'none',
kodcaw: this.$kodcaw,
maxDate: null,
tarikhmula: '',
tarikhhingga: '',
selectedbatchlel: '',
jenisbatchlel: [],
// hostname: window.location.origin
};
},
mounted() {
this.setMaxDate();
},
created() {
console.log("kodcaw from props:", this.$kodcaw); // Should not be null
this.senaraibatchlel();
},
methods: {
setMaxDate() {
const today = new Date();
today.setDate(today.getDate() - 1);
this.maxDate = today.toISOString().split('T')[0];
},
async generatepdf() {
await this.setJenis('pdf');
Vue.swal({
title: 'Memuatkan...',
allowEscapeKey: false,
allowOutsideClick: false,
showCancelButton: false,
showConfirmButton: false,
timer: 8000,
});
document.getElementById("formringter").submit();
},
async generateview() {
await this.setJenis('view');
Vue.swal({
title: 'Memuatkan...',
allowEscapeKey: false,
allowOutsideClick: false,
showCancelButton: false,
showConfirmButton: false,
timer: 8000,
});
document.getElementById("formringter").submit();
},
Urlredirect() {
return window.route('cetak.laporanlelong');
},
setJenis(value) {
this.jenisgenerate = value;
},
async senaraibatchlel() {
try {
const kodcawValue = this.$kodcaw || ''; // Ensure kodcaw is valid
console.log(`Fetching batch lelong data from: ${this.hostname}/api/lookupbatchlel/${kodcawValue}`);
console.log("kodcaw before API call:", this.$kodcaw);
</select> -->
const response = await axios.get(`${this.$hostname}/api/lookupbatchlel/${kodcawValue}`);
</div>
if (!response.data || response.data.length === 0) {
throw new Error("No data received.");
}
<div class="flex justify-end mt-10">
<button @click.prevent="generatepdf" class=" mr-2 border border-yellow-600 text-yellow-600 font-montserrat py-2 px-8 font-medium rounded-xl hover:bg-yellow-600 hover:text-white transition-all duration-300"><i class="fas fa-file-pdf mr-2"></i>PDF</button>
<button @click.prevent="generateview" class="border border-yellow-600 text-yellow-600 font-montserrat py-2 px-8 font-medium rounded-xl hover:bg-yellow-600 hover:text-white transition-all duration-300"><i class="fas fa-eye mr-2"></i>View</button>
</div>
</div>
</form>
</div>
</div>
</div>
</template>
this.jenisbatchlel = response.data;
} catch (error) {
console.error("Error fetching batch lelong:", error);
Vue.swal({
title: "Error!",
text: "Failed to fetch batch lelong data. Please try again later.",
icon: "error",
});
}
},
formatDate(date) {
const d = new Date(date);
return d.toLocaleDateString('ms-MY', { day: '2-digit', month: '2-digit', year: 'numeric' });
}
},
computed: {
filteredBatchlel() {
if (!Array.isArray(this.jenisbatchlel)) {
console.error("jenisbatchlel is not an array:", this.jenisbatchlel);
return [];
}
<script>
import {
required,
minLength,
between
} from 'vuelidate/lib/validators'
export default {
data(){
return{
jenisgenerate:'none',
kodcaw:'',
maxDate: null,
yesterday: null,
selectedalasan: '',
jenisalasan: {}
// If no date is selected, show all batches
if (!this.tarikhmula && !this.tarikhhingga) {
return this.jenisbatchlel;
}
// Convert input dates to JavaScript Date objects
const fromDate = this.tarikhmula ? new Date(this.tarikhmula) : null;
const toDate = this.tarikhhingga ? new Date(this.tarikhhingga) : null;
return this.jenisbatchlel.filter(batch => {
const batchDate = new Date(batch.tarikh);
let isWithinDateRange = true;
if (fromDate) isWithinDateRange = batchDate >= fromDate;
if (toDate) isWithinDateRange = isWithinDateRange && batchDate <= toDate;
return isWithinDateRange;
});
}
},
mounted() {
this.setMaxDate();
},
created() {
this.senaraiAlasan();
},
methods: {
setMaxDate() {
const today = new Date();
today.setDate(today.getDate() - 1);
this.yesterday = today.toISOString().split('T')[0];
this.maxDate = this.yesterday;
watch: {
tarikhmula() {
this.selectedbatchlel = ''; // Reset batch selection when date changes
},
async generatepdf(){
await this.setJenis('pdf');
Vue.swal({
title: 'Memuatkan...',
allowEscapeKey : false,
allowOutsideClick: false,
showCancelButton: false,
showConfirmButton: false,
timer: 8000,
});
document.getElementById("formringter").submit();
},
async generateview(){
await this.setJenis('view');
Vue.swal({
title: 'Memuatkan...',
allowEscapeKey : false,
allowOutsideClick: false,
showCancelButton: false,
showConfirmButton: false,
timer: 8000,
});
document.getElementById("formringter").submit();
},
Urlredirect: function() {
return window.route('cetak.laporanlelong')
},
setJenis: function(value){
return this.jenisgenerate = value;
},
senaraiAlasan: function () {
this.axios.get(this.$hostname + '/api/lookupalasan').then(response => {
this.jenisalasan = response.data;
});
},
},
validations: {
selectedalasan: {
required
tarikhhingga() {
this.selectedbatchlel = ''; // Reset batch selection when date changes
}
}
}
</script>
};
</script>
+59 -71
View File
@@ -189,7 +189,6 @@
</style>
<body>
<table id="header">
<tr>
<td style="font-size:20px;font-weight:bold;">{{ $cawangan_detail['namacaw'] }}</td>
@@ -197,73 +196,63 @@
</tr>
</tr>
</table>
<br>
<table id="scan">
<table id="scan" style="border-collapse: collapse; width: auto; font-size: 14px;">
<tr>
<th colspan ="5"><b>LAPORAN LELONG</b></th>
<th> </th>
<th> </th>
<th></th>
<th colspan="2" style="text-align: left; padding: 2px 5px;"><b>LAPORAN LELONGAN</b></th>
</tr>
<tr>
<th colspan="5"><b> TARIKH CETAK:</b>
<th style="text-align: left; padding: 2px 5px; white-space: nowrap;">TARIKH CETAK:</th>
<td style="text-align: left; padding: 2px 5px;">
@php
$myDateTime = DateTime::createFromFormat('Y-m-d', $tarikh_cetak);
$formattedweddingdate = $myDateTime->format('d-m-Y');
echo($formattedweddingdate);
echo $myDateTime ? $myDateTime->format('d-m-Y') : '-';
@endphp
</th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</td>
</tr>
<tr>
<th style="width:20px"> <b>TARIKH:</b></th>
<th>@php
$myDateTime = DateTime::createFromFormat('Y-m-d', $mula_date);
$formattedweddingdate = $myDateTime->format('d-m-Y');
echo($formattedweddingdate);
@endphp</th>
<th style="width:20px"> <b>HINGGA:</b></th>
<th>@php
$myDateTime = DateTime::createFromFormat('Y-m-d', $hingga_date);
$formattedweddingdate = $myDateTime->format('d-m-Y');
echo($formattedweddingdate);
@endphp</th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<th style="text-align: left; padding: 2px 5px; white-space: nowrap;">TARIKH LELONG:</th>
<td style="text-align: left; padding: 2px 5px;">
@php
$myDateTime = DateTime::createFromFormat('Y-m-d', $tlelong);
echo $myDateTime ? $myDateTime->format('d-m-Y') : '-';
@endphp
</td>
</tr>
<tr>
<th style="text-align: left; padding: 2px 5px; white-space: nowrap;">BATCH NO:</th>
<td style="text-align: left; padding: 2px 5px;">{{ $batchno }}</td>
</tr>
</table>
<br>
<table cellspacing="0" cellpadding="5" border="0" width="100%" height="80" align="left" id="scan">
<table cellspacing="0" cellpadding="5" border="0" width="100%" height="80" align="left" id="scan">
<thead>
<tr>
<th>No</th>
<th align="left">No Rujukan</th>
<th align="left">Penggadai</th>
<th>Nilai Marhun Asal (RM)</th>
<th>Pembiayaan (RM)</th>
<th>Keuntungan (RM)</th>
<th>1% (RM)</th>
<th>Lain-Lain Caj (RM)</th>
<th>Caj Lelong (RM)</th>
<th>Harga Jual (RM)</th>
<th>Baki (RM)</th>
<th>Harga Asas (RM)</th>
<th align="left">Nama Pembeli</th>
<tr>
<th>No</th>
<th align="left">No Rujukan</th>
<th align="left">Penggadai</th>
<th>Nilai Marhun Asal (RM)</th>
<th>Pembiayaan (RM)</th>
<th>Keuntungan (RM)</th>
<th>1% (RM)</th>
<th>Lain-Lain Caj (RM)</th>
<th>Caj Lelong (RM)</th>
<th>Harga Jual (RM)</th>
<th>Baki (RM)</th>
<th>Harga Asas (RM)</th>
<th align="left">Nama Pembeli</th>
</tr>
</tr>
</thead>
@foreach($lelong['data'] as $sh)
<tr>
@@ -293,22 +282,20 @@
<tr>
<td colspan="3" align="left"><strong>Jumlah Keseluruhan</strong></td>
<td align="right"><strong>{{ number_format($total_nilaimarhun, 2)}}</strong></td>
<td align="right"><strong>{{ number_format($total_pinjaman, 2)}}</strong></td>
<td align="right"><strong>{{ number_format($total_keuntungan, 2)}}</strong></td>
<td align="right"><strong>{{ number_format($total_onepercent, 2)}}</strong></td>
<td align="right"><strong>{{ number_format($total_ujrah, 2)}}</strong></td>
<td align="right"><strong>{{ number_format($total_cajlelong, 2)}}</strong></td>
<td align="right"><strong>{{ number_format($total_hargajual, 2)}}</strong></td>
<td align="right"><strong>{{ number_format($total_baki, 2)}}</strong></td>
<td align="right"><strong>{{ number_format($total_hargaasas, 2)}}</strong></td>
<td></td>
</tr>
<td colspan="3" align="left"><strong>Jumlah Keseluruhan</strong></td>
<td align="right"><strong>{{ number_format($total_nilaimarhun, 2)}}</strong></td>
<td align="right"><strong>{{ number_format($total_pinjaman, 2)}}</strong></td>
<td align="right"><strong>{{ number_format($total_keuntungan, 2)}}</strong></td>
<td align="right"><strong>{{ number_format($total_onepercent, 2)}}</strong></td>
<td align="right"><strong>{{ number_format($total_ujrah, 2)}}</strong></td>
<td align="right"><strong>{{ number_format($total_cajlelong, 2)}}</strong></td>
<td align="right"><strong>{{ number_format($total_hargajual, 2)}}</strong></td>
<td align="right"><strong>{{ number_format($total_baki, 2)}}</strong></td>
<td align="right"><strong>{{ number_format($total_hargaasas, 2)}}</strong></td>
<td></td>
</tr>
</table>
<br><br>
<!-- Table for Jumlah Baki A, Baki B -->
<table class="table-align" cellspacing="0" cellpadding="1" border="0" width="100%" height="80" align="left" id="scan">
@@ -342,14 +329,15 @@
@endif<b>
</td>
</tr>
</tbody>
</table>
</tbody>
<br>
<br>
<br>
<br>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<table id="scan">
<tr>
<td></td>
<td colspan="2"> .................................................................. </td>