Show New Order dates as dd/mm/yyyy
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -8,25 +8,36 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const previewDisplay = document.getElementById('preview-display');
|
||||
const form = document.getElementById('order-form');
|
||||
|
||||
// Default dates (local calendar — valueAsDate is UTC and shifts in +0330)
|
||||
function localYmd(d) {
|
||||
const y = d.getFullYear();
|
||||
// European display dd/mm/yyyy; API still gets ISO yyyy-mm-dd
|
||||
function localDmy(d) {
|
||||
const day = String(d.getDate()).padStart(2, '0');
|
||||
const m = String(d.getMonth() + 1).padStart(2, '0');
|
||||
return `${day}/${m}/${d.getFullYear()}`;
|
||||
}
|
||||
function parseDmy(s) {
|
||||
const m = /^(\d{2})\/(\d{2})\/(\d{4})$/.exec((s || '').trim());
|
||||
if (!m) return null;
|
||||
const d = new Date(+m[3], +m[2] - 1, +m[1]);
|
||||
if (d.getFullYear() !== +m[3] || d.getMonth() !== +m[2] - 1 || d.getDate() !== +m[1]) return null;
|
||||
return d;
|
||||
}
|
||||
function toYmd(d) {
|
||||
const m = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(d.getDate()).padStart(2, '0');
|
||||
return `${y}-${m}-${day}`;
|
||||
return `${d.getFullYear()}-${m}-${day}`;
|
||||
}
|
||||
dateInput.value = localYmd(new Date());
|
||||
dateInput.value = localDmy(new Date());
|
||||
|
||||
// Auto calculate +6 months
|
||||
function updateNextControl() {
|
||||
const [y, m, day] = (dateInput.value || '').split('-').map(Number);
|
||||
if (!y) return;
|
||||
const d = new Date(y, m - 1, day);
|
||||
const d = parseDmy(dateInput.value);
|
||||
if (!d) return;
|
||||
d.setMonth(d.getMonth() + 6);
|
||||
nextControlInput.value = localYmd(d);
|
||||
nextControlInput.value = localDmy(d);
|
||||
}
|
||||
updateNextControl();
|
||||
dateInput.addEventListener('change', updateNextControl);
|
||||
dateInput.addEventListener('input', updateNextControl);
|
||||
|
||||
// Auto calculate previews
|
||||
function updatePreview() {
|
||||
@@ -65,11 +76,18 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
form.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const prodDate = parseDmy(dateInput.value);
|
||||
const nextDate = parseDmy(nextControlInput.value);
|
||||
if (!prodDate || !nextDate) {
|
||||
showToast(currentLang === 'fa' ? 'تاریخ را به صورت روز/ماه/سال وارد کنید' : 'Use date format dd/mm/yyyy', true);
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
product_id: parseInt(productSelect.value),
|
||||
batch_number: document.getElementById('batch').value,
|
||||
production_date: dateInput.value,
|
||||
next_control_date: nextControlInput.value,
|
||||
production_date: toYmd(prodDate),
|
||||
next_control_date: toYmd(nextDate),
|
||||
total_weight: parseFloat(totalWeightInput.value),
|
||||
canister_weight: parseFloat(canisterWeightInput.value),
|
||||
canisters_per_box: parseInt(canistersPerBoxInput.value)
|
||||
@@ -85,7 +103,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if (res.ok) {
|
||||
showToast(currentLang === 'fa' ? 'سفارش به صف چاپ اضافه شد' : 'Order added to print queue!');
|
||||
form.reset();
|
||||
dateInput.value = localYmd(new Date());
|
||||
dateInput.value = localDmy(new Date());
|
||||
updateNextControl();
|
||||
updatePreview();
|
||||
setTimeout(() => window.location.reload(), 1000);
|
||||
|
||||
Reference in New Issue
Block a user