Show New Order dates as dd/mm/yyyy (#13)
Co-authored-by: Cursor <cursoragent@cursor.com> Reviewed-on: #13 Co-authored-by: diaco <dyaco8464@yahoo.com> Co-committed-by: diaco <dyaco8464@yahoo.com>
This commit was merged in pull request #13.
This commit is contained in:
@@ -8,25 +8,36 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
const previewDisplay = document.getElementById('preview-display');
|
const previewDisplay = document.getElementById('preview-display');
|
||||||
const form = document.getElementById('order-form');
|
const form = document.getElementById('order-form');
|
||||||
|
|
||||||
// Default dates (local calendar — valueAsDate is UTC and shifts in +0330)
|
// European display dd/mm/yyyy; API still gets ISO yyyy-mm-dd
|
||||||
function localYmd(d) {
|
function localDmy(d) {
|
||||||
const y = d.getFullYear();
|
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 m = String(d.getMonth() + 1).padStart(2, '0');
|
||||||
const day = String(d.getDate()).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
|
// Auto calculate +6 months
|
||||||
function updateNextControl() {
|
function updateNextControl() {
|
||||||
const [y, m, day] = (dateInput.value || '').split('-').map(Number);
|
const d = parseDmy(dateInput.value);
|
||||||
if (!y) return;
|
if (!d) return;
|
||||||
const d = new Date(y, m - 1, day);
|
|
||||||
d.setMonth(d.getMonth() + 6);
|
d.setMonth(d.getMonth() + 6);
|
||||||
nextControlInput.value = localYmd(d);
|
nextControlInput.value = localDmy(d);
|
||||||
}
|
}
|
||||||
updateNextControl();
|
updateNextControl();
|
||||||
dateInput.addEventListener('change', updateNextControl);
|
dateInput.addEventListener('change', updateNextControl);
|
||||||
|
dateInput.addEventListener('input', updateNextControl);
|
||||||
|
|
||||||
// Auto calculate previews
|
// Auto calculate previews
|
||||||
function updatePreview() {
|
function updatePreview() {
|
||||||
@@ -65,11 +76,18 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
form.addEventListener('submit', async (e) => {
|
form.addEventListener('submit', async (e) => {
|
||||||
e.preventDefault();
|
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 = {
|
const payload = {
|
||||||
product_id: parseInt(productSelect.value),
|
product_id: parseInt(productSelect.value),
|
||||||
batch_number: document.getElementById('batch').value,
|
batch_number: document.getElementById('batch').value,
|
||||||
production_date: dateInput.value,
|
production_date: toYmd(prodDate),
|
||||||
next_control_date: nextControlInput.value,
|
next_control_date: toYmd(nextDate),
|
||||||
total_weight: parseFloat(totalWeightInput.value),
|
total_weight: parseFloat(totalWeightInput.value),
|
||||||
canister_weight: parseFloat(canisterWeightInput.value),
|
canister_weight: parseFloat(canisterWeightInput.value),
|
||||||
canisters_per_box: parseInt(canistersPerBoxInput.value)
|
canisters_per_box: parseInt(canistersPerBoxInput.value)
|
||||||
@@ -85,7 +103,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
showToast(currentLang === 'fa' ? 'سفارش به صف چاپ اضافه شد' : 'Order added to print queue!');
|
showToast(currentLang === 'fa' ? 'سفارش به صف چاپ اضافه شد' : 'Order added to print queue!');
|
||||||
form.reset();
|
form.reset();
|
||||||
dateInput.value = localYmd(new Date());
|
dateInput.value = localDmy(new Date());
|
||||||
updateNextControl();
|
updateNextControl();
|
||||||
updatePreview();
|
updatePreview();
|
||||||
setTimeout(() => window.location.reload(), 1000);
|
setTimeout(() => window.location.reload(), 1000);
|
||||||
|
|||||||
@@ -56,11 +56,11 @@
|
|||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="prod-date" data-i18n="date">Date</label>
|
<label for="prod-date" data-i18n="date">Date</label>
|
||||||
<input type="date" id="prod-date" required>
|
<input type="text" id="prod-date" required placeholder="dd/mm/yyyy" pattern="\d{2}/\d{2}/\d{4}" inputmode="numeric" autocomplete="off">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="next-control" data-i18n="next_control">Next Control Date</label>
|
<label for="next-control" data-i18n="next_control">Next Control Date</label>
|
||||||
<input type="date" id="next-control" required>
|
<input type="text" id="next-control" required placeholder="dd/mm/yyyy" pattern="\d{2}/\d{2}/\d{4}" inputmode="numeric" autocomplete="off">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user