925 disable_pos_form_actions(); 926 927 // DELIVERY FIELDS: form serialize se pehle values synchronize karein 928 if ($('#restaurant_order_type').val() === 'delivery') { 929 $('#shipping_details').val( 930 $('#inline_shipping_details').val() || '' 931 ); 932 933 $('#shipping_address').val( 934 $('#inline_shipping_address').val() || '' 935 ); 936 937 $('#shipping_status').val( 938 $('#inline_shipping_status').val() || '' 939 ); 940 941 $('#delivered_to').val( 942 $('#inline_delivered_to').val() || '' 943 ); 944 945 $('#delivery_person').val( 946 $('#inline_delivery_person').val() || '' 947 ); 948 949 var inlineShippingCharges = 950 $('#inline_shipping_charges').val() || 0; 951 952 $('#shipping_charges').val(inlineShippingCharges); 953 } 954 955 var data = $(form).serialize(); 956 data = data + (is_suspend ? '&status=draft' : '&status=final'); 957 958 // Tell backend ONLY when Edit POS Unpaid Invoice triggered this suspend flow. 959 // Normal Suspend remains unchanged and will not print. 960 if (is_suspend && global_is_unpaid_invoice === true) { 961 data = data + '&is_unpaid_invoice=1'; 962 } 963 var url = $(form).attr('action'); 964 $.ajax({ 965 method: 'POST', 966 url: url, 967 data: data, 968 dataType: 'json', 969 success: function(result) { 970 if (result.success == 1) { 971 if (result.whatsapp_link) { 972 window.open(result.whatsapp_link); 973 } 974 975 $('#modal_payment').modal('hide'); 976 toastr.success(result.msg); 977 978 // UNPAID INVOICE: 979 // one Draft/Suspend save -> standard POS receipt preview -> STOP. 980 if (is_suspend && global_is_unpaid_invoice === true) { 981 global_is_unpaid_invoice = false; 982 global_is_suspend = false; 983 984 if ($('input#is_suspend').length) { 985 $('input#is_suspend').val(0); 986 } 987 988 enable_pos_form_actions(); 989 990 if (result.receipt && result.receipt.is_enabled) { 991 pos_print(result.receipt); 992 } else { 993 toastr.error('Invoice saved, but receipt preview was not returned.'); 994 } 995 996 return; 997 } 998 999 // NORMAL SUSPEND: 1000 // keep original behavior: save draft, no receipt, then leave edit screen. 1001 if (is_suspend) { 1002 global_is_suspend = false; 1003 1004 reset_pos_form(); 1005 enable_pos_form_actions(); 1006 1007 var pos_redirect_url = $('input#pos_redirect_url').val(); 1008 if (pos_redirect_url) { 1009 window.location.href = pos_redirect_url; 1010 } else { 1011 window.location.reload(); 1012 } 1013 return; 1014 } 1015 1016 // Normal final sale. 1017 if (result.receipt && result.receipt.is_enabled) { 1018 pos_print(result.receipt); 1019 } 1020 1021 // ZRX: MAIN / NEW SALE final checkout only. 1022 // After a successful sale, fully clear the current POS form so 1023 // the cashier stays on New Sale with a fresh order. 1024 // Edit POS is intentionally excluded and keeps its own flow below. 1025 if ($('#add_pos_sell_form').length > 0) { 1026 global_is_suspend = false; 1027 global_is_unpaid_invoice = false; 1028 global_edit_cash_checkout = false; 1029 1030 if ($('input#is_suspend').length) { 1031 $('input#is_suspend').val(0); 1032 } 1033 1034 reset_pos_form(); 1035 enable_pos_form_actions(); 1036 1037 // Next restaurant order picker: 1038 // ONLY Create POS pages that actually contain the 1039 // Kitchen-gated restaurant picker can enter this block. 1040 setTimeout(function () {