Account and Shipment Changes
This commit is contained in:
@@ -1413,31 +1413,39 @@ tr:hover td{ background:#fbfdff; }
|
||||
<input type="text" id="edit_description" name="description" required class="input" placeholder="Entry description">
|
||||
</div>
|
||||
<div>
|
||||
<label>Order Quantity</label>
|
||||
<input
|
||||
type="number"
|
||||
id="edit_order_quantity"
|
||||
name="order_quantity"
|
||||
min="0"
|
||||
class="input"
|
||||
placeholder="Order quantity"
|
||||
readonly
|
||||
style="cursor:pointer;"
|
||||
onclick="openEntryOrdersModal(document.getElementById('edit_entry_no').value)"
|
||||
>
|
||||
<small class="helper-note">
|
||||
Click on quantity to view associated orders.
|
||||
</small>
|
||||
<label>
|
||||
Order Quantity
|
||||
<span style="font-size:12px; color:#6b7280; margin-left:4px;">
|
||||
(Auto Update)
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<input
|
||||
type="number"
|
||||
id="edit_order_quantity"
|
||||
name="order_quantity"
|
||||
min="0"
|
||||
class="input"
|
||||
placeholder="Order quantity"
|
||||
readonly
|
||||
style="cursor:pointer;"
|
||||
onclick="openEntryOrdersModal(document.getElementById('edit_entry_no').value)"
|
||||
>
|
||||
|
||||
<small class="helper-note">
|
||||
Click on quantity to view associated orders.
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
<!-- <div>
|
||||
<label>Payment Status</label>
|
||||
<select id="edit_payment_status" name="payment_status" class="input">
|
||||
<option value="unpaid">Unpaid</option>
|
||||
<option value="paid">Paid</option>
|
||||
<option value="pending">Pending</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>-->
|
||||
<div>
|
||||
<label>Region</label>
|
||||
<select id="edit_region" name="region" class="input" required>
|
||||
@@ -2182,10 +2190,23 @@ function renderPaymentTable(list){
|
||||
|
||||
|
||||
body.appendChild(tr);
|
||||
|
||||
const btn = tr.querySelector('.toggle-switch-btn');
|
||||
setToggleVisual(btn, Number(entry.toggle_pos));
|
||||
btn.addEventListener('click', () => cycleToggle(btn));
|
||||
btn.dataset.entry = entry.entry_no; // entry_no from API
|
||||
btn.dataset.pos = entry.toggle_pos ?? 0;
|
||||
setToggleVisual(btn, Number(btn.dataset.pos));
|
||||
btn.addEventListener('click', () => cycleToggle(btn));
|
||||
|
||||
|
||||
const actions = tr.querySelector('.action-btns');
|
||||
if (actions) {
|
||||
if (entry.payment_status.toLowerCase() === 'paid') {
|
||||
actions.style.display = 'none';
|
||||
} else {
|
||||
actions.style.display = 'flex';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (canActions) {
|
||||
const editBtn = tr.querySelector('.edit-btn');
|
||||
@@ -2196,8 +2217,71 @@ function renderPaymentTable(list){
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function cycleToggle(btn) {
|
||||
// वर्तमान position घेऊन पुढचा स्टेट कॅल्क्युलेट करा
|
||||
let pos = parseInt(btn.dataset.pos || '0', 10); // 0 = unpaid, 1 = pending, 2 = paid
|
||||
pos = (pos + 1) % 3;
|
||||
btn.dataset.pos = pos;
|
||||
setToggleVisual(btn, pos); // रंग वगैरे अपडेट
|
||||
|
||||
const entryNo = btn.dataset.entry;
|
||||
|
||||
jsonFetch('/admin/account/toggle-payment', {
|
||||
method: 'POST',
|
||||
body: {
|
||||
entry_no: entryNo, // controller मध्ये जी नावे आहेत तीच
|
||||
toggle_pos: pos
|
||||
}
|
||||
}).then(res => {
|
||||
if (!res.success) {
|
||||
alert(res.message || 'Failed to update payment status');
|
||||
|
||||
// error असेल तर UI परत जुन्या स्टेटला ने
|
||||
pos = (pos + 2) % 3;
|
||||
btn.dataset.pos = pos;
|
||||
setToggleVisual(btn, pos);
|
||||
return;
|
||||
}
|
||||
|
||||
// 1) global entries array update करा (dashboard data)
|
||||
if (Array.isArray(entries)) {
|
||||
const idx = entries.findIndex(e => e.entry_no === entryNo);
|
||||
if (idx !== -1) {
|
||||
entries[idx].toggle_pos = res.entry.toggle_pos;
|
||||
entries[idx].payment_status = res.entry.payment_status;
|
||||
}
|
||||
}
|
||||
|
||||
// 2) current row मधला status badge आणि actions अपडेट करा
|
||||
const row = btn.closest('tr');
|
||||
if (row) {
|
||||
// status badge
|
||||
const statusCell = row.querySelector('.status-badge');
|
||||
if (statusCell) {
|
||||
statusCell.textContent = res.entry.payment_status;
|
||||
statusCell.className = 'status-badge ' + statusClass(res.entry.payment_status);
|
||||
}
|
||||
|
||||
// paid झाल्यावर edit/delete लपवा
|
||||
const actions = row.querySelector('.action-btns');
|
||||
if (actions) {
|
||||
if (res.entry.payment_status.toLowerCase() === 'paid') {
|
||||
actions.style.display = 'none';
|
||||
} else {
|
||||
actions.style.display = 'flex'; // किंवा तुझा default layout
|
||||
}
|
||||
}
|
||||
}
|
||||
}).catch(() => {
|
||||
alert('Network error while updating payment status');
|
||||
|
||||
// network error – UI मागे घे
|
||||
pos = (pos + 2) % 3;
|
||||
btn.dataset.pos = pos;
|
||||
setToggleVisual(btn, pos);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function renderOrderTable(list){
|
||||
const body = document.getElementById('orderTableBody');
|
||||
@@ -2336,7 +2420,7 @@ function openEditModal(entry) {
|
||||
document.getElementById('edit_entry_no').value = entry.entry_no;
|
||||
document.getElementById('edit_description').value = entry.description || '';
|
||||
document.getElementById('edit_order_quantity').value = entry.order_quantity || '';
|
||||
document.getElementById('edit_payment_status').value = entry.payment_status || 'unpaid';
|
||||
// document.getElementById('edit_payment_status').value = entry.payment_status || 'unpaid';
|
||||
document.getElementById('edit_region').value = entry.region || 'China';
|
||||
document.getElementById('edit_amount').value = entry.amount || '';
|
||||
|
||||
@@ -2470,7 +2554,7 @@ async function submitEditEntry(e) {
|
||||
entry_no: form.entry_no.value,
|
||||
description: form.description.value.trim(),
|
||||
order_quantity: Number(form.order_quantity.value) || 0,
|
||||
payment_status: form.payment_status.value,
|
||||
// payment_status: form.payment_status.value,
|
||||
region: form.region.value,
|
||||
amount: Number(form.amount.value) || 0
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user