|
|
|
|
@@ -1,21 +1,29 @@
|
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
const productSelect = document.getElementById('product');
|
|
|
|
|
const dateInput = document.getElementById('prod-date');
|
|
|
|
|
const nextControlInput = document.getElementById('next-control');
|
|
|
|
|
const totalWeightInput = document.getElementById('total-weight');
|
|
|
|
|
const canisterWeightInput = document.getElementById('canister-weight');
|
|
|
|
|
const canistersPerBoxInput = document.getElementById('canisters-per-box');
|
|
|
|
|
const previewDisplay = document.getElementById('preview-display');
|
|
|
|
|
const form = document.getElementById('order-form');
|
|
|
|
|
|
|
|
|
|
// Default dates
|
|
|
|
|
const today = new Date();
|
|
|
|
|
dateInput.valueAsDate = today;
|
|
|
|
|
|
|
|
|
|
// Default dates (local calendar — valueAsDate is UTC and shifts in +0330)
|
|
|
|
|
function localYmd(d) {
|
|
|
|
|
const y = d.getFullYear();
|
|
|
|
|
const m = String(d.getMonth() + 1).padStart(2, '0');
|
|
|
|
|
const day = String(d.getDate()).padStart(2, '0');
|
|
|
|
|
return `${y}-${m}-${day}`;
|
|
|
|
|
}
|
|
|
|
|
dateInput.value = localYmd(new Date());
|
|
|
|
|
|
|
|
|
|
// Auto calculate +6 months
|
|
|
|
|
function updateNextControl() {
|
|
|
|
|
const d = new Date(dateInput.value);
|
|
|
|
|
if (isNaN(d)) return;
|
|
|
|
|
const [y, m, day] = (dateInput.value || '').split('-').map(Number);
|
|
|
|
|
if (!y) return;
|
|
|
|
|
const d = new Date(y, m - 1, day);
|
|
|
|
|
d.setMonth(d.getMonth() + 6);
|
|
|
|
|
nextControlInput.valueAsDate = d;
|
|
|
|
|
nextControlInput.value = localYmd(d);
|
|
|
|
|
}
|
|
|
|
|
updateNextControl();
|
|
|
|
|
dateInput.addEventListener('change', updateNextControl);
|
|
|
|
|
@@ -74,7 +82,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
showToast(currentLang === 'fa' ? 'سفارش به صف چاپ اضافه شد' : 'Order added to print queue!');
|
|
|
|
|
form.reset();
|
|
|
|
|
dateInput.valueAsDate = today;
|
|
|
|
|
dateInput.value = localYmd(new Date());
|
|
|
|
|
updateNextControl();
|
|
|
|
|
updatePreview();
|
|
|
|
|
setTimeout(() => window.location.reload(), 1000);
|
|
|
|
|
|