Merged in izzati-hotfix-laporan-stok-audit (pull request #157)
tambah function untuk stok audit semasa
This commit is contained in:
@@ -25,38 +25,53 @@ class StokAuditController extends Controller
|
|||||||
|
|
||||||
public function show(Request $request)
|
public function show(Request $request)
|
||||||
{
|
{
|
||||||
|
$tarikh_cetak = Carbon::now()->toDateString(); // tarikh cetak
|
||||||
|
|
||||||
|
if ($request->dateOption === 'current') {
|
||||||
|
$date = Carbon::now();
|
||||||
|
$tebus_date = $date->format('d-m-Y'); // tarikh semasa
|
||||||
|
$monthName = $date->translatedFormat('F'); // bulan semasa
|
||||||
|
} else {
|
||||||
$validated = $request->validate(
|
$validated = $request->validate(
|
||||||
['monthYear' => 'required'],
|
['monthYear' => 'required'],
|
||||||
['monthYear.required' => 'Sila isi tarikh sebelum hantar',
|
['monthYear.required' => 'Sila isi tarikh sebelum hantar',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$current = Carbon::now();
|
|
||||||
$tarikh_cetak = $current->toDateString();
|
|
||||||
$tokens = explode('-', $validated['monthYear']);
|
$tokens = explode('-', $validated['monthYear']);
|
||||||
$month = ltrim($tokens[0], '0');
|
$month = ltrim($tokens[0], '0');
|
||||||
$year = $tokens[1];
|
$year = $tokens[1];
|
||||||
|
|
||||||
// Set the locale to Malaysian
|
$date = Carbon::createFromDate($year, $month, 1); // set day = 1
|
||||||
App::setLocale('ms');
|
|
||||||
|
|
||||||
// Create a Carbon instance representing the date
|
|
||||||
$date = Carbon::createFromDate($year, $month, 1); // Set the day to 1st of the month
|
|
||||||
|
|
||||||
// Get the name of the month in Malaysian local
|
|
||||||
$monthName = $date->translatedFormat('F');
|
$monthName = $date->translatedFormat('F');
|
||||||
|
$tebus_date = $monthName . ' ' . $year;
|
||||||
|
}
|
||||||
|
|
||||||
|
$month = $date->month;
|
||||||
|
$year = $date->year;
|
||||||
|
|
||||||
$request->hostname = config('api.url');
|
$request->hostname = config('api.url');
|
||||||
|
|
||||||
$stokAudit = Http::get($request->hostname . '/api/reports/stok-audit', [
|
$stokAudit = Http::get($request->hostname . '/api/reports/stok-audit', [
|
||||||
'month' => $month,
|
'month' => $month,
|
||||||
'year' => $year,
|
'year' => $year,
|
||||||
|
'dateOption' => $request->dateOption
|
||||||
])->json();
|
])->json();
|
||||||
|
|
||||||
$tebus_date = $monthName . ' ' . $year;
|
$file_title = sprintf(
|
||||||
$file_title = sprintf("Laporan-StokAudit %s (%s - %s).xlsx", 'Semua cawanangan', $monthName, $year);
|
"Laporan-StokAudit %s (%s).xlsx",
|
||||||
|
'Semua cawangan',
|
||||||
|
$tebus_date
|
||||||
|
);
|
||||||
|
|
||||||
if ($request->generateType === 'pdf') {
|
if ($request->generateType === 'pdf') {
|
||||||
return view('reports.stok-audit.show', compact('tebus_date', 'tarikh_cetak', 'stokAudit', 'month', 'year'));
|
return view('reports.stok-audit.show', compact(
|
||||||
|
'stokAudit',
|
||||||
|
'month',
|
||||||
|
'year',
|
||||||
|
'monthName',
|
||||||
|
'tarikh_cetak',
|
||||||
|
'tebus_date'
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
return Excel::download(new StokAuditExport($stokAudit), $file_title);
|
return Excel::download(new StokAuditExport($stokAudit), $file_title);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,7 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
<div id="error-alert" class="flex justify-center">
|
<div id="error-alert" class="flex justify-center">
|
||||||
<div id="alert-border-2" class="flex items-center p-4 text-red-800 border-t-4 border-red-300 bg-red-50 dark:text-red-400 dark:bg-gray-800 dark:border-red-800 px-10" role="alert">
|
<div class="flex items-center p-4 text-red-800 border-t-4 border-red-300 bg-red-50 px-10" role="alert">
|
||||||
<svg class="flex-shrink-0 w-4 h-4" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
|
|
||||||
<path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z"/>
|
|
||||||
</svg>
|
|
||||||
<div class="ms-3 text-sm font-medium ml-2 ">
|
<div class="ms-3 text-sm font-medium ml-2 ">
|
||||||
@foreach ($errors->all() as $error)
|
@foreach ($errors->all() as $error)
|
||||||
{{ $error }}
|
{{ $error }}
|
||||||
@@ -29,58 +26,75 @@
|
|||||||
@endif
|
@endif
|
||||||
<div class="flex w-full">
|
<div class="flex w-full">
|
||||||
<div class="xl:w-2/3 2xl:w-1/2 p-8 mx-auto">
|
<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"><a href="/reports"
|
<div class="bg-yellow-600 text-gray-200 text-lg px-6 py-4 rounded-t-lg">
|
||||||
class="router-link-active"><i class="fas fa-backspace text-white"></i></a> <span
|
<a href="/reports">
|
||||||
class="text-center mx-auto text-white font-bold">Laporan Stok Audit</span></div>
|
<i class="fas fa-backspace text-white"></i>
|
||||||
|
</a>
|
||||||
|
<span class="text-center mx-auto text-white font-bold">
|
||||||
|
Laporan Stok Audit
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<form method="get" id="formStokAudit" action="{{ route('reports.stok-audit.show') }}">
|
<form method="get" id="formStokAudit" action="{{ route('reports.stok-audit.show') }}">
|
||||||
<div class="rounded bg-white shadow p-6">
|
<div class="rounded bg-white shadow p-6">
|
||||||
<div class="pb-6"><label for="username"
|
|
||||||
class="font-semibold text-gray-700 block pb-1">Tarikh</label>
|
{{-- PILIHAN TARIKH --}}
|
||||||
|
<div class="pb-4">
|
||||||
|
<label class="font-semibold text-gray-700 block pb-1">
|
||||||
|
Pilihan Tarikh
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div class="flex items-center space-x-6 mb-3">
|
||||||
|
<label class="flex items-center">
|
||||||
|
<input type="radio" name="dateOption" value="manual" checked class="mr-2">
|
||||||
|
Pilih Tarikh
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="flex items-center">
|
||||||
|
<input type="radio" name="dateOption" value="current" class="mr-2">
|
||||||
|
Tarikh Semasa (Hari Ini)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label class="font-semibold text-gray-700 block pb-1">
|
||||||
|
Tarikh
|
||||||
|
</label>
|
||||||
|
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<span
|
<span
|
||||||
class="text-gray-600 border border-2 rounded-l px-4 py-2 whitespace-no-wrap"
|
class="text-gray-600 border border-2 rounded-l px-4 py-2"
|
||||||
style="background-color: rgb(249, 250, 251);">Mula</span>
|
style="background-color: rgb(249, 250, 251);">
|
||||||
<input id="stock_audit_monthYear" name="monthYear" value=""
|
Pilih
|
||||||
class="border border-2 border-l-0 rounded-r px-4 py-2 w-80r mr-2">
|
</span>
|
||||||
|
|
||||||
|
<input type="date"
|
||||||
|
id="stock_audit_monthYear"
|
||||||
|
name="monthYear"
|
||||||
|
value=""
|
||||||
|
class="border border-2 border-l-0 rounded-r px-4 py-2 w-80 mr-2">
|
||||||
|
|
||||||
<div class="hidden">
|
<div class="hidden">
|
||||||
<input type="radio" name="generateType" id="generateTypePdf"
|
<input type="radio" name="generateType" id="generateTypePdf" value="pdf">
|
||||||
value="pdf">
|
<input type="radio" name="generateType" id="generateTypeExcel" value="excel">
|
||||||
<input type="radio" name="generateType" id="generateTypeExcel"
|
|
||||||
value="excel">
|
|
||||||
</div>
|
</div>
|
||||||
<button id="generateExcel"
|
<button id="generateExcel"
|
||||||
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 ml-5"
|
class="border border-yellow-600 text-yellow-600 py-2 px-8 rounded-xl hover:bg-yellow-600 hover:text-white transition-all duration-300 ml-5"
|
||||||
type="button">
|
type="button">
|
||||||
<i class="fas fa-file-excel mr-2"></i>Excel
|
<i class="fas fa-file-excel mr-2"></i>Excel
|
||||||
</button>
|
</button>
|
||||||
<button id="generatePdf"
|
<button id="generatePdf"
|
||||||
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 ml-5"
|
class="border border-yellow-600 text-yellow-600 py-2 px-8 rounded-xl hover:bg-yellow-600 hover:text-white transition-all duration-300 ml-5"
|
||||||
type="button">
|
type="button">
|
||||||
<i class="fas fa-eye mr-2"></i>View
|
<i class="fas fa-eye mr-2"></i>View
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div kodcaw="operasi">
|
|
||||||
<div>
|
|
||||||
<!---->
|
|
||||||
<!---->
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<!---->
|
|
||||||
<!---->
|
|
||||||
</div>
|
|
||||||
<div class="flex justify-between mb-2">
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
@include('layouts.footer')
|
@include('layouts.footer')
|
||||||
@@ -90,30 +104,58 @@
|
|||||||
|
|
||||||
@push('additional_scripts')
|
@push('additional_scripts')
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function(event) {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
|
||||||
let form = document.querySelector('#formStokAudit')
|
let form = document.querySelector('#formStokAudit');
|
||||||
|
|
||||||
document.querySelector('button#generatePdf').addEventListener("click", function(event) {
|
// ===== BUTTON PDF =====
|
||||||
|
document.querySelector('#generatePdf').addEventListener("click", function() {
|
||||||
document.querySelector('#generateTypePdf').checked = true;
|
document.querySelector('#generateTypePdf').checked = true;
|
||||||
form.submit();
|
form.submit();
|
||||||
})
|
});
|
||||||
|
|
||||||
document.querySelector('button#generateExcel').addEventListener("click", function(event) {
|
// ===== BUTTON EXCEL =====
|
||||||
|
document.querySelector('#generateExcel').addEventListener("click", function() {
|
||||||
document.querySelector('#generateTypeExcel').checked = true;
|
document.querySelector('#generateTypeExcel').checked = true;
|
||||||
form.submit();
|
form.submit();
|
||||||
})
|
});
|
||||||
|
|
||||||
|
// ===== TARIKH OPTION =====
|
||||||
|
const dateInput = document.getElementById('stock_audit_monthYear');
|
||||||
|
const dateOptions = document.querySelectorAll('input[name="dateOption"]');
|
||||||
|
|
||||||
|
dateOptions.forEach(option => {
|
||||||
|
option.addEventListener('change', function () {
|
||||||
|
|
||||||
|
if (this.value === 'current') {
|
||||||
|
|
||||||
|
let today = new Date();
|
||||||
|
let day = String(today.getDate()).padStart(2, '0');
|
||||||
|
let month = String(today.getMonth() + 1).padStart(2, '0');
|
||||||
|
let year = today.getFullYear();
|
||||||
|
|
||||||
|
dateInput.value = year + '-' + month + '-' + day;
|
||||||
|
|
||||||
|
// Ganti readOnly dengan disable
|
||||||
|
dateInput.disabled = true;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
dateInput.disabled = false;
|
||||||
|
dateInput.value = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ===== AUTO HIDE ERROR =====
|
||||||
const errorAlert = document.getElementById("error-alert");
|
const errorAlert = document.getElementById("error-alert");
|
||||||
|
|
||||||
if (errorAlert) {
|
if (errorAlert) {
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
errorAlert.classList.add = "opacity-0";
|
errorAlert.classList.add("opacity-0");
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
errorAlert.style.display = "none";
|
errorAlert.style.display = "none";
|
||||||
}, 500)
|
}, 500);
|
||||||
}, 5000); // 5000 milliseconds = 5 seconds
|
}, 5000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user