accounting modules
This commit is contained in:
@@ -8,11 +8,20 @@
|
||||
$data['items'] = json_decode($data['items'] ?? '[]', true) ?: [];
|
||||
|
||||
try {
|
||||
$new_id = null;
|
||||
$new_id = null;
|
||||
$quotation_id = (int)($data['quotation_id'] ?? 0);
|
||||
|
||||
dbTransaction($pdo2, function($pdo) use ($data, $company_id, $logging, &$new_id) {
|
||||
dbTransaction($pdo2, function($pdo) use ($data, $company_id, $logging, $quotation_id, &$new_id) {
|
||||
$order = new OrderManager($pdo, $company_id);
|
||||
$new_id = $order->saveOrder($data, $logging);
|
||||
|
||||
// On new order created from a quotation: link both records
|
||||
if ($new_id && $quotation_id > 0) {
|
||||
$pdo->prepare(
|
||||
"UPDATE ac_quotation SET order_id = :order_id, status = 5
|
||||
WHERE id = :id AND company_id = :cid AND status = 2"
|
||||
)->execute([':order_id' => $new_id, ':id' => $quotation_id, ':cid' => $company_id]);
|
||||
}
|
||||
});
|
||||
|
||||
$answer['success'] = 1;
|
||||
|
||||
@@ -244,6 +244,7 @@
|
||||
// ── Status helpers ────────────────────────────────────────────────────────
|
||||
function order_status_badge(status) {
|
||||
const map = {
|
||||
'-2': '<span class="badge bg-danger">Pending — Awaiting Warehouse</span>',
|
||||
'-1': '<span class="badge bg-secondary">Cancelled</span>',
|
||||
'0': '<span class="badge bg-warning text-dark">Draft</span>',
|
||||
'1': '<span class="badge bg-info text-white">Confirmed</span>',
|
||||
@@ -380,19 +381,26 @@
|
||||
has_active_invoice = has_active_invoice || false;
|
||||
returnable_count = returnable_count ?? 1;
|
||||
fulfillment_status = parseInt(fulfillment_status) || 0;
|
||||
var is_pending = status === -2;
|
||||
var is_draft = status === 0;
|
||||
var can_confirm = status === 0;
|
||||
var can_cancel = status === 0 || status === 1;
|
||||
var is_editable = is_pending || is_draft; // both Pending and Draft are editable
|
||||
var can_confirm = status === 0; // only Draft can be confirmed (not Pending)
|
||||
var can_cancel = status === -2 || status === 0 || status === 1;
|
||||
var is_cancelled = status === -1;
|
||||
var is_completed = status === 3;
|
||||
var can_fulfill = status >= 1 && !is_cancelled && !is_completed;
|
||||
|
||||
// Edit controls
|
||||
$('#btn_add_item, #contact, #order_date, #notes, #discount, #tax, #shipping_fee')
|
||||
.prop('disabled', !is_draft);
|
||||
$('#shipping_tracking_number').prop('disabled', !(is_draft || can_fulfill));
|
||||
$('.item_sku, .item_qty, .item_price, .item_warehouse').prop('disabled', !is_draft);
|
||||
$('a[onclick^="remove_item"]').toggleClass('d-none', !is_draft);
|
||||
.prop('disabled', !is_editable);
|
||||
$('#shipping_tracking_number').prop('disabled', !(is_editable || can_fulfill));
|
||||
$('.item_sku, .item_qty, .item_price, .item_warehouse').prop('disabled', !is_editable);
|
||||
$('a[onclick^="remove_item"]').toggleClass('d-none', !is_editable);
|
||||
|
||||
// Pending hint
|
||||
if (is_pending) {
|
||||
$('#page_subtitle').text('Assign a warehouse for each item, then save to move this order to Draft.');
|
||||
}
|
||||
|
||||
// Action buttons
|
||||
set_btn_state('#btn_save', is_draft, 'Only draft orders can be edited');
|
||||
|
||||
+3
-1
@@ -104,6 +104,7 @@
|
||||
<div class="col-lg-3">
|
||||
<select id="filter_status" class="form-select">
|
||||
<option value="">All Status</option>
|
||||
<option value="-2">Pending</option>
|
||||
<option value="-1">Cancelled</option>
|
||||
<option value="0">Draft</option>
|
||||
<option value="1">Confirmed</option>
|
||||
@@ -169,13 +170,14 @@
|
||||
function order_status_badge(status) {
|
||||
status = parseInt(status);
|
||||
const map = {
|
||||
'-2': '<span class="badge bg-danger">Pending</span>',
|
||||
'-1': '<span class="badge bg-secondary">Cancelled</span>',
|
||||
'0': '<span class="badge bg-warning text-dark">Draft</span>',
|
||||
'1': '<span class="badge bg-info text-white">Confirmed</span>',
|
||||
'2': '<span class="badge bg-primary">Processing</span>',
|
||||
'3': '<span class="badge bg-success">Completed</span>',
|
||||
};
|
||||
return map[status] ?? '<span class="badge bg-light text-dark">—</span>';
|
||||
return map[String(status)] ?? '<span class="badge bg-light text-dark">—</span>';
|
||||
}
|
||||
|
||||
function payment_status_badge(status) {
|
||||
|
||||
Reference in New Issue
Block a user