From 3d2d18a330a27432cc2e99db11a767d608a84886 Mon Sep 17 00:00:00 2001 From: yarzar_code Date: Thu, 9 Jul 2020 14:46:18 +0630 Subject: [PATCH] payment method changed in report --- app/assets/javascripts/origami.js | 1162 ++++++++++------- app/controllers/foodcourt/void_controller.rb | 108 +- app/controllers/home_controller.rb | 25 +- .../origami/others_payments_controller.rb | 87 +- .../origami/payments_controller.rb | 301 ++--- app/controllers/origami/void_controller.rb | 109 +- .../reports/payment_method_controller.rb | 123 +- .../reports/receipt_no_detail_controller.rb | 119 +- .../reports/shiftsale_controller.rb | 5 +- .../transactions/shift_sales_controller.rb | 11 +- app/models/sale.rb | 262 ++-- app/models/shift_sale.rb | 2 +- app/pdf/receipt_bill_pdf.rb | 2 +- app/views/home/dashboard.html.erb | 46 +- .../others_payments/create.json.jbuilder | 5 + .../origami/others_payments/index.html.erb | 4 +- .../origami/others_payments/new.html.erb | 279 ++++ app/views/origami/payments/show.html.erb | 517 +++----- app/views/reports/dailysale/index.html.erb | 236 +--- app/views/reports/dailysale/index.xls.erb | 162 +-- .../reports/payment_method/index.html.erb | 42 +- .../reports/payment_method/index.xls.erb | 30 +- .../_shift_sale_report_filter.html.erb | 9 +- .../reports/waste_and_spoilage/index.html.erb | 13 +- .../transactions/shift_sales/show.html.erb | 100 +- config/routes.rb | 53 +- 26 files changed, 1836 insertions(+), 1976 deletions(-) create mode 100644 app/views/origami/others_payments/create.json.jbuilder create mode 100644 app/views/origami/others_payments/new.html.erb diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 8c910119..650c81ef 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -17,576 +17,766 @@ //= require custom.js /* Constant Varaibles */ -_CREDIT_PAYMENTS_ = "/   CREDIT PAYMENTS"; -_CUSTOMERS_ = "/   CUSTOMERS"; -_DISCOUNTS_ = "/   DISCOUNTS"; -_IN_DUTIES_ = "/   IN DUTIES"; -_JCB_ = "/   JCB PAYMENT"; -_MASTER_ = "/   MASTER PAYMENT"; -_MPU_ = "/   MPU PAYMENT"; -_ALIPAY_ = "/   Alipay"; -_JUNCTIONPAY_ = "/   JunctionPay"; -_PAYMAL_ = "/   PAYMAL"; -_DINGA_ = "/   DINGA PAYMENT"; -_GIFT_VOUCHER_ = "/   GIFT VOUCHER"; -_OTHER_CHARGES_ = "/   CHARGES"; -_OTHER_PAYMENTS_ = "/   OTHER PAYMENT"; -_PAYMENTS_ = "/   PAYMENT"; -_PAYPAR_PAYMENT_ = "/   PAYPAR PAYMENT"; -_COMMISSIONS_ = "/   COMMISSIONS"; -_REDEEM_PAYMENT_ = "/   REDEEM PAYMENT"; -_SALE_EDIT_ = "/   SALE EDIT"; -_SPLIT_BILL_ = "/   SPLIT BILL"; -_UNION_ = "/   UNION PAYMENT"; -_VISA_ = "/   VISA PAYMENT"; -_VOUCHER_ = "/   VOUCHER"; -_SURVEY_ = "/   SURVEY"; +_CREDIT_PAYMENTS_ = "/   CREDIT PAYMENTS"; +_CUSTOMERS_ = "/   CUSTOMERS"; +_DISCOUNTS_ = "/   DISCOUNTS"; +_IN_DUTIES_ = "/   IN DUTIES"; +_JCB_ = "/   JCB PAYMENT"; +_MASTER_ = "/   MASTER PAYMENT"; +_MPU_ = "/   MPU PAYMENT"; +_ALIPAY_ = "/   Alipay"; +_JUNCTIONPAY_ = "/   JunctionPay"; +_PAYMAL_ = "/   PAYMAL"; +_DINGA_ = "/   DINGA PAYMENT"; +_GIFT_VOUCHER_ = "/   GIFT VOUCHER"; +_OTHER_CHARGES_ = "/   CHARGES"; +_OTHER_PAYMENTS_ = "/   OTHER PAYMENT"; +_PAYMENTS_ = "/   PAYMENT"; +_PAYPAR_PAYMENT_ = "/   PAYPAR PAYMENT"; +_COMMISSIONS_ = "/   COMMISSIONS"; +_REDEEM_PAYMENT_ = "/   REDEEM PAYMENT"; +_SALE_EDIT_ = "/   SALE EDIT"; +_SPLIT_BILL_ = "/   SPLIT BILL"; +_UNION_ = "/   UNION PAYMENT"; +_VISA_ = "/   VISA PAYMENT"; +_VOUCHER_ = "/   VOUCHER"; +_SURVEY_ = "/   SURVEY"; /* Constant Varaibles */ -$(document).on('turbolinks:load', function() { +$(document).on("turbolinks:load", function () { + $("#customer_image_path").fileinput({ + previewFileType: "image", + allowedFileExtensions: ["jpg", "gif", "png"], + browseClass: "btn btn-success", + browseLabel: "Pick Image", + browseIcon: ' ', + removeClass: "btn btn-danger", + removeLabel: "Delete", + removeIcon: ' ', + showUpload: false, + // uploadClass: "btn btn-info", + // uploadLabel: "Upload", + // uploadIcon: " ", + previewTemplates: { + image: + '
\n' + + ' {caption}\n' + + "
\n", + }, + }); - $("#customer_image_path").fileinput({ - previewFileType: "image", - allowedFileExtensions: ["jpg", "gif", "png"], - browseClass: "btn btn-success", - browseLabel: "Pick Image", - browseIcon: " ", - removeClass: "btn btn-danger", - removeLabel: "Delete", - removeIcon: " ", - showUpload: false, - // uploadClass: "btn btn-info", - // uploadLabel: "Upload", - // uploadIcon: " ", - previewTemplates: { - image: '
\n' + - ' {caption}\n' + - '
\n', - } - }); + $(".datetimepicker").bootstrapMaterialDatePicker({ + format: "DD-MM-YYYY - HH:mm", + clearButton: true, + weekStart: 1, + }); - $('.datetimepicker').bootstrapMaterialDatePicker({ - format: 'DD-MM-YYYY - HH:mm', - clearButton: true, - weekStart: 1 - }); + $(".datepicker").bootstrapMaterialDatePicker({ + format: "DD-MM-YYYY", + clearButton: true, + weekStart: 1, + time: false, + }); - $('.datepicker').bootstrapMaterialDatePicker({ - format: 'DD-MM-YYYY', - clearButton: true, - weekStart: 1, - time: false - }); + $(".timepicker").bootstrapMaterialDatePicker({ + format: "HH:mm", + clearButton: true, + date: false, + }); - $('.timepicker').bootstrapMaterialDatePicker({ - format: 'HH:mm', - clearButton: true, - date: false - }); + // For selected order return + var order_status = ""; + order_status = $(".selected-item") + .children() + .find(".orders-order-status") + .text() + .substr(0, 6) + .trim(); - // For selected order return - var order_status = ""; - order_status = $(".selected-item").children().find(".orders-order-status").text().substr(0,6).trim(); + // Enable/Disable Button + //control_button(order_status); - // Enable/Disable Button - //control_button(order_status); + $(".orders").on("click", function () { + $("#order-sub-total").text(""); + // $("#order-food").text(''); + // $("#order-beverage").text(''); + $("#order-discount").text(""); + $("#order-Tax").text(""); + $("#order-grand-total").text(""); - $(".orders").on('click', function(){ - $("#order-sub-total").text(''); + var zone_name = $(this).find(".orders-table").text(); + var receipt_no = $(this).find(".orders-receipt-no").text(); + var unique_id = $(this).find(".orders-id").text(); + var order_status = $(this).find(".orders-order-status").text().trim(); + + // Enable/Disable Button + //control_button(order_status); + + var customer_id = $(this).find(".customer-id").text(); + show_customer_details(customer_id); + + $("#re-print").val(unique_id); + + var cashier = ""; + var receipt_date = ""; + var sub_total = 0.0; + var discount_amount = 0; + var tax_amount = 0; + var grand_total_amount = 0; + + $("#order-title").text("ORDER DETAILS - " + zone_name); + // clear order items + $("#order-items-table").children("tbody").empty(); + + // AJAX call for order + $.ajax({ + type: "POST", + url: "/origami/" + unique_id, + data: { booking_id: unique_id }, + success: function (result) { + for (i = 0; i < result.length; i++) { + var data = JSON.stringify(result[i]); + var parse_data = JSON.parse(data); + var show_date = ""; + + // Receipt Header + receipt_no = result[i].receipt_no; + cashier = result[i].cashier_name; + if (result[i].receipt_date != null) { + receipt_date = new Date(result[i].receipt_date); + show_date = + receipt_date.getDate() + + "-" + + receipt_date.getMonth() + + "-" + + receipt_date.getFullYear() + + " " + + receipt_date.getHours() + + ":" + + receipt_date.getMinutes(); + } + + //Receipt Charges + sub_total += parseFloat(parse_data.price); + + discount_amount = + parse_data.discount_amount == null + ? "0.0" + : parse_data.discount_amount; + tax_amount = parse_data.tax_amount; + grand_total_amount = parse_data.grand_total_amount; + + // Ordered Items + var order_items_rows = + "" + + "" + + parse_data.item_name + + "" + + "" + + parse_data.qty + + "" + + "" + + parse_data.price + + "" + + ""; + + $("#order-items-table").children("tbody").append(order_items_rows); + } + + // Cashier Info + $("#receipt_no").text(receipt_no); + $("#cashier").text(cashier == null ? "" : cashier); + $("#receipt_date").text(show_date); + + // Payment Info + $("#order-sub-total").text(sub_total); // $("#order-food").text(''); // $("#order-beverage").text(''); - $("#order-discount").text(''); - $("#order-Tax").text(''); - $("#order-grand-total").text(''); - - var zone_name=$(this).find(".orders-table").text(); - var receipt_no=$(this).find(".orders-receipt-no").text(); - var unique_id = $(this).find(".orders-id").text(); - var order_status=$(this).find(".orders-order-status").text().trim(); - - // Enable/Disable Button - //control_button(order_status); - - var customer_id=$(this).find(".customer-id").text(); - show_customer_details(customer_id); - - $("#re-print").val(unique_id); - - var cashier=""; - var receipt_date=""; - var sub_total=0.0; - var discount_amount=0; - var tax_amount=0; - var grand_total_amount=0; - - $("#order-title").text("ORDER DETAILS - " + zone_name); - // clear order items - $("#order-items-table").children("tbody").empty(); - - // AJAX call for order - $.ajax({ - type: "POST", - url: "/origami/" + unique_id, - data: { 'booking_id' : unique_id }, - success:function(result){ - for (i = 0; i < result.length; i++) { - var data = JSON.stringify(result[i]); - var parse_data = JSON.parse(data); - var show_date = ""; - - // Receipt Header - receipt_no = result[i].receipt_no; - cashier = result[i].cashier_name; - if(result[i].receipt_date != null){ - receipt_date = new Date(result[i].receipt_date); - show_date = receipt_date.getDate() + "-" + receipt_date.getMonth() + "-" + receipt_date.getFullYear() + ' ' + receipt_date.getHours()+ ':' + receipt_date.getMinutes() - } - - //Receipt Charges - sub_total += parseFloat(parse_data.price); - - discount_amount = parse_data.discount_amount == null? '0.0' : parse_data.discount_amount; - tax_amount = parse_data.tax_amount; - grand_total_amount = parse_data.grand_total_amount; - - // Ordered Items - var order_items_rows = "" + - "" + parse_data.item_name + "" + - "" + parse_data.qty + "" + - "" + parse_data.price + "" + - ""; - - $("#order-items-table").children("tbody").append(order_items_rows); - } - - // Cashier Info - $("#receipt_no").text(receipt_no); - $("#cashier").text(cashier == null ? "" : cashier); - $("#receipt_date").text(show_date); - - // Payment Info - $("#order-sub-total").text(sub_total); - // $("#order-food").text(''); - // $("#order-beverage").text(''); - $("#order-discount").text(discount_amount); - $("#order-Tax").text(tax_amount); - $("#order-grand-total").text(grand_total_amount); - } - }); - // End AJAX Call - - $('.orders').removeClass('selected-item'); - $(this).addClass('selected-item'); - }); - - // Payment for Bill - $('#pay-bill').click(function() { - var sale_id=$(".selected-item").find(".orders-id").text().substr(0,16); - if(sale_id!=""){ - window.location.href = '/origami/sale/'+ sale_id + "/payment" - } - else { - alert("Please select an order!"); - } - - return false; - }); - - $(document).on('click', '.access_modal', function(event){ - type = $(this).data("type"); - $(".ok").attr("data-action",type); - $('#AccessCodeModal').modal('show'); + $("#order-discount").text(discount_amount); + $("#order-Tax").text(tax_amount); + $("#order-grand-total").text(grand_total_amount); + }, }); + // End AJAX Call - $(document).on('click', '.access_number', function(event){ - if(event.handled !== true) { - var original_value = $('#access_code').val(); - var input_type = $(this).attr("data-type"); + $(".orders").removeClass("selected-item"); + $(this).addClass("selected-item"); + }); - switch (input_type) { - case 'num': - var input_value = $(this).attr("data-value"); - if (original_value){ - $('#access_code').val(original_value + input_value); - }else{ - $('#access_code').val(original_value + input_value); - } - break; - case 'ok': - var type = $(this).attr("data-action"); - code = $('#access_code').val(); - check_emp_access_code(code,type) - break; - case 'clr': - $('#access_code').val(""); - break; - } - event.handled = true; - } else { - return false; + // Payment for Bill + $("#pay-bill").click(function () { + var sale_id = $(".selected-item").find(".orders-id").text().substr(0, 16); + if (sale_id != "") { + window.location.href = "/origami/sale/" + sale_id + "/payment"; + } else { + alert("Please select an order!"); + } + + return false; + }); + + $(document).on("click", ".access_modal", function (event) { + type = $(this).data("type"); + $(".ok").attr("data-action", type); + $("#AccessCodeModal").modal("show"); + }); + + $(document).on("click", ".access_number", function (event) { + if (event.handled !== true) { + var original_value = $("#access_code").val(); + var input_type = $(this).attr("data-type"); + + switch (input_type) { + case "num": + var input_value = $(this).attr("data-value"); + if (original_value) { + $("#access_code").val(original_value + input_value); + } else { + $("#access_code").val(original_value + input_value); + } + break; + case "ok": + var type = $(this).attr("data-action"); + code = $("#access_code").val(); + check_emp_access_code(code, type); + break; + case "clr": + $("#access_code").val(""); + break; } - }); + event.handled = true; + } else { + return false; + } + }); - $(document).on("click", ".credit_detail",function(){ - var sale_id = $(this).attr("data-id"); - var cashier_type = $(this).attr("data-type"); - if(cashier_type=='cashier'){ - window.location.href = "/origami/cashier/credit_sales/"+sale_id; - }else{ - window.location.href = "/origami/quick_service/credit_sales/"+sale_id; - } - }); + $(document).on("click", ".credit_detail", function () { + var sale_id = $(this).attr("data-id"); + var cashier_type = $(this).attr("data-type"); + if (cashier_type == "cashier") { + window.location.href = "/origami/cashier/credit_sales/" + sale_id; + } else { + window.location.href = "/origami/quick_service/credit_sales/" + sale_id; + } + }); }); /* start check first bill or not funs: */ -function checkReceiptNoInFirstBillData(receipt_no,payment) { - // localStorage.removeItem('receipt_lists'); - var status = false; - var json_data = []; - if((receipt_no!=undefined) && (receipt_no!="")){ - if(localStorage.hasOwnProperty("receipt_lists")===true){ - var arr_data = JSON.parse(localStorage.getItem("receipt_lists")); - if (payment) { - json_data = arr_data.filter(function(e) { return e.receipt_no == receipt_no }); - }else{ - json_data = arr_data.filter(function(e) { return e.receipt_no !== receipt_no }); - } +function checkReceiptNoInFirstBillData(receipt_no, payment) { + // localStorage.removeItem('receipt_lists'); + var status = false; + var json_data = []; + if (receipt_no != undefined && receipt_no != "") { + if (localStorage.hasOwnProperty("receipt_lists") === true) { + var arr_data = JSON.parse(localStorage.getItem("receipt_lists")); + if (payment) { + json_data = arr_data.filter(function (e) { + return e.receipt_no == receipt_no; + }); + } else { + json_data = arr_data.filter(function (e) { + return e.receipt_no !== receipt_no; + }); + } - if((arr_data.length) > (json_data.length)){ - status = true; - } - } - } - - if (payment) { - if (json_data.length>0) { - return json_data[0]["payment"]; - }else{ - return false; + if (arr_data.length > json_data.length) { + status = true; + } } - }else{ - return status; - } + } + + if (payment) { + if (json_data.length > 0) { + return json_data[0]["payment"]; + } else { + return false; + } + } else { + return status; + } } -function createReceiptNoInFirstBillData(receipt_no,payment) { - var arr_data = []; - var json_data = []; - if(localStorage.hasOwnProperty("receipt_lists") === true){ - arr_data = JSON.parse(localStorage.getItem("receipt_lists")); - json_data = arr_data.filter(function(e) { return e.receipt_no == receipt_no }); - if (payment) { - jdata = arr_data.filter(function(e) { return e.receipt_no !== receipt_no }); - jdata.push({'receipt_no':receipt_no,'payment':payment}); - localStorage.setItem("receipt_lists",JSON.stringify(jdata)); - } - } - if(((arr_data.length == 0) && (json_data.length == 0)) || ((arr_data.length > 0) && (json_data.length == 0))){ - arr_data.push({'receipt_no':receipt_no,'payment':payment}); - localStorage.setItem("receipt_lists",JSON.stringify(arr_data)); - } +function createReceiptNoInFirstBillData(receipt_no, payment) { + var arr_data = []; + var json_data = []; + if (localStorage.hasOwnProperty("receipt_lists") === true) { + arr_data = JSON.parse(localStorage.getItem("receipt_lists")); + json_data = arr_data.filter(function (e) { + return e.receipt_no == receipt_no; + }); + if (payment) { + jdata = arr_data.filter(function (e) { + return e.receipt_no !== receipt_no; + }); + jdata.push({ receipt_no: receipt_no, payment: payment }); + localStorage.setItem("receipt_lists", JSON.stringify(jdata)); + } + } + if ( + (arr_data.length == 0 && json_data.length == 0) || + (arr_data.length > 0 && json_data.length == 0) + ) { + arr_data.push({ receipt_no: receipt_no, payment: payment }); + localStorage.setItem("receipt_lists", JSON.stringify(arr_data)); + } } function deleteReceiptNoInFirstBillData(receipt_no) { - if(localStorage.hasOwnProperty("receipt_lists") ===true ){ - var arr_data = JSON.parse(localStorage.getItem("receipt_lists")); - var json_data = arr_data.filter(function(e) { return e.receipt_no !== receipt_no }); - localStorage.setItem("receipt_lists",JSON.stringify(json_data)); - } + if (localStorage.hasOwnProperty("receipt_lists") === true) { + var arr_data = JSON.parse(localStorage.getItem("receipt_lists")); + var json_data = arr_data.filter(function (e) { + return e.receipt_no !== receipt_no; + }); + localStorage.setItem("receipt_lists", JSON.stringify(json_data)); + } } /* end check first bill or not funs: */ //start CB ECR integration //set CB com port data function setCommPorts(comPortLists) { - var sale_id = $('#sale_id').val(); - $('#com_port_name').html(""); - var jsonPortLists = $.parseJSON(comPortLists); - // alert(jsonPortLists); - if((jsonPortLists!=undefined && jsonPortLists!='') && (jsonPortLists.length > 0)){ - $.each(jsonPortLists,function(key,value){ - $('#com_port_name').append(""); - }); - } - else{ - swal({ - title: 'Oops', - text: 'Payment device has been disconnected! Please plug it in.', - type: 'error', - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type+"/payment/others_payment"; - }); - } + var sale_id = $("#sale_id").val(); + $("#com_port_name").html(""); + var jsonPortLists = $.parseJSON(comPortLists); + // alert(jsonPortLists); + if ( + jsonPortLists != undefined && + jsonPortLists != "" && + jsonPortLists.length > 0 + ) { + $.each(jsonPortLists, function (key, value) { + $("#com_port_name").append( + "" + ); + }); + } else { + swal( + { + title: "Oops", + text: "Payment device has been disconnected! Please plug it in.", + type: "error", + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false, + }, + function () { + window.location.href = + "/origami/sale/" + + sale_id + + "/" + + cashier_type + + "/payment/others_payment"; + } + ); + } } /** pay with CB bank **/ -function pay_withBank(cmd_type, payment_type, bnk_bill_amount,sale_id,receipt_no,cashier_type) { - $("#loading_wrapper").show(); - var com_port = $("#com_port_name").val(); - reqCardSaleTrans(cmd_type, payment_type, bnk_bill_amount, sale_id, receipt_no, com_port,cashier_type); +function pay_withBank( + cmd_type, + payment_type, + bnk_bill_amount, + sale_id, + receipt_no, + cashier_type +) { + $("#loading_wrapper").show(); + var com_port = $("#com_port_name").val(); + reqCardSaleTrans( + cmd_type, + payment_type, + bnk_bill_amount, + sale_id, + receipt_no, + com_port, + cashier_type + ); } //add req data to card_sale_trans table -function reqCardSaleTrans(cmd_type, payment_type, bnk_bill_amount, sale_id, receipt_no, com_port,cashier_type) { - var jobj = {"cmd_type" : cmd_type, "payment_type" : "CARD", "amt" : bnk_bill_amount, "sale_id" : sale_id, "inv_no" : receipt_no, "com_port" : com_port}; +function reqCardSaleTrans( + cmd_type, + payment_type, + bnk_bill_amount, + sale_id, + receipt_no, + com_port, + cashier_type +) { + var jobj = { + cmd_type: cmd_type, + payment_type: "CARD", + amt: bnk_bill_amount, + sale_id: sale_id, + inv_no: receipt_no, + com_port: com_port, + }; $.ajax({ - type: "POST", - url: "/origami/bank_integration/sale_trans", - data: {type:"request", data: jobj}, - dataType: "json", - success: function(data) { - if (data.status == "success"){ - card_sale_trans_id = data.card_sale_trans_id; - resCardSaleTrans(card_sale_trans_id,cmd_type,payment_type, bnk_bill_amount, sale_id, receipt_no,com_port,cashier_type); - } - } - }); + type: "POST", + url: "/origami/bank_integration/sale_trans", + data: { type: "request", data: jobj }, + dataType: "json", + success: function (data) { + if (data.status == "success") { + card_sale_trans_id = data.card_sale_trans_id; + resCardSaleTrans( + card_sale_trans_id, + cmd_type, + payment_type, + bnk_bill_amount, + sale_id, + receipt_no, + com_port, + cashier_type + ); + } + }, + }); } //add res data to card_sale_trans table -function resCardSaleTrans(card_sale_trans_id,cmd_type,payment_type, bnk_bill_amount, sale_id, receipt_no,com_port,cashier_type) { - +function resCardSaleTrans( + card_sale_trans_id, + cmd_type, + payment_type, + bnk_bill_amount, + sale_id, + receipt_no, + com_port, + cashier_type +) { var resMsg = ""; - var card_payment_type=""; - if($("#loading_wrapper").is(":visible")){ - if(payment_type=="mpu" || payment_type=="visa" || payment_type=="master" || payment_type=="jcb" || payment_type=="unionpay"){ - card_payment_type = "CARD"; - } - else if(payment_type == "alipay"){ - card_payment_type = "EWALLET"; + var card_payment_type = ""; + if ($("#loading_wrapper").is(":visible")) { + if ( + payment_type == "mpu" || + payment_type == "visa" || + payment_type == "master" || + payment_type == "jcb" || + payment_type == "unionpay" + ) { + card_payment_type = "CARD"; + } else if (payment_type == "alipay") { + card_payment_type = "EWALLET"; } bnk_bill_amount = parseFloat(bnk_bill_amount); - resMsg = code2lab.reqBankPayment(cmd_type,card_payment_type,bnk_bill_amount,receipt_no,com_port); + resMsg = code2lab.reqBankPayment( + cmd_type, + card_payment_type, + bnk_bill_amount, + receipt_no, + com_port + ); } - if(resMsg.includes("STATUS")){ + if (resMsg.includes("STATUS")) { var jobj = $.parseJSON(resMsg); - $.ajax({ - type: "POST", - url: "/origami/bank_integration/sale_trans", - data: {type:"response", card_sale_trans_id: card_sale_trans_id, data: jobj}, - dataType: "json", - success: function(data) { - if(data.status == "success"){ - resCBPay(resMsg,card_sale_trans_id,cmd_type,payment_type,bnk_bill_amount,sale_id,receipt_no,com_port,cashier_type); - } - } - }); - }else{ - if(payment_type!="master"){ - payment_type = payment_type.toUpperCase(); - }else{ - payment_type = "Master"; - } + $.ajax({ + type: "POST", + url: "/origami/bank_integration/sale_trans", + data: { + type: "response", + card_sale_trans_id: card_sale_trans_id, + data: jobj, + }, + dataType: "json", + success: function (data) { + if (data.status == "success") { + resCBPay( + resMsg, + card_sale_trans_id, + cmd_type, + payment_type, + bnk_bill_amount, + sale_id, + receipt_no, + com_port, + cashier_type + ); + } + }, + }); + } else { + if (payment_type != "master") { + payment_type = payment_type.toUpperCase(); + } else { + payment_type = "Master"; + } - $("#loading_wrapper").hide(); - swal({ - title: 'Oops', - text: resMsg.toString(), - type: 'error', - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - var url_param = "payment"; - if(location.pathname.includes("credit_payment")){ - url_param = "credit_payment"; - } - window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type + "/"+url_param+"/others_payment/"+payment_type; - }); + $("#loading_wrapper").hide(); + swal( + { + title: "Oops", + text: resMsg.toString(), + type: "error", + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false, + }, + function () { + var url_param = "payment"; + if (location.pathname.includes("credit_payment")) { + url_param = "credit_payment"; + } + window.location.href = + "/origami/sale/" + + sale_id + + "/" + + cashier_type + + "/" + + url_param + + "/others_payment/" + + payment_type; + } + ); } } - -function resCBPay(resMsg,card_sale_trans_id,cmd_type,payment_type,bnk_bill_amount,sale_id,receipt_no,com_port,cashier_type) { - $("#loading_wrapper").hide(); - var jobj = $.parseJSON(resMsg); - $("#reference_no").val(jobj.REFNUM); - if(jobj.STATUS == "Approved"){ - $.ajax({type: "POST", - url: "/origami/payment/"+payment_type, - data: "amount="+ bnk_bill_amount + "&sale_id="+ sale_id + "&ref_no=" + jobj.REFNUM, - success:function(result){ - if(result){ - swal({ - title: "Information!", - text: "Payment Successfully", - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - var url_param = "payment"; - if(location.pathname.includes("credit_payment")){ - url_param = "credit_payment"; - } - window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type+"/"+url_param; - }); - } - } - }); - }else{ - if(payment_type!="master"){ - payment_type = payment_type.toUpperCase(); - }else{ - payment_type = "Master"; - } - swal({ - title: 'Oops', - text: "Transaction is " + (jobj.STATUS).toLowerCase(), - type: 'error', - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - var url_param = "payment"; - if(location.pathname.includes("credit_payment")){ - url_param = "credit_payment"; - } - window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type + "/"+url_param+"/others_payment/"+payment_type; - }); +function resCBPay( + resMsg, + card_sale_trans_id, + cmd_type, + payment_type, + bnk_bill_amount, + sale_id, + receipt_no, + com_port, + cashier_type +) { + $("#loading_wrapper").hide(); + var jobj = $.parseJSON(resMsg); + $("#reference_no").val(jobj.REFNUM); + if (jobj.STATUS == "Approved") { + $.ajax({ + type: "POST", + url: "/origami/payment/" + payment_type, + data: + "amount=" + + bnk_bill_amount + + "&sale_id=" + + sale_id + + "&ref_no=" + + jobj.REFNUM, + success: function (result) { + if (result) { + swal( + { + title: "Information!", + text: "Payment Successfully", + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false, + }, + function () { + var url_param = "payment"; + if (location.pathname.includes("credit_payment")) { + url_param = "credit_payment"; + } + window.location.href = + "/origami/sale/" + + sale_id + + "/" + + cashier_type + + "/" + + url_param; + } + ); + } + }, + }); + } else { + if (payment_type != "master") { + payment_type = payment_type.toUpperCase(); + } else { + payment_type = "Master"; } + swal( + { + title: "Oops", + text: "Transaction is " + jobj.STATUS.toLowerCase(), + type: "error", + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false, + }, + function () { + var url_param = "payment"; + if (location.pathname.includes("credit_payment")) { + url_param = "credit_payment"; + } + window.location.href = + "/origami/sale/" + + sale_id + + "/" + + cashier_type + + "/" + + url_param + + "/others_payment/" + + payment_type; + } + ); + } } //end CB ECR integration -function setHeaderBreadCrumb(params){ - $("#others_payment").html(params); +function setHeaderBreadCrumb(params) { + $("#others_payment").html(params); } //show hide nav bar for webview -function showHideNavbar(webview,page){ - if(webview){ - $("nav.navbar").addClass("hidden"); - $("section").addClass("section-margin"); - $(".page-loader-wrapper").addClass("hidden"); - if(page!=undefined){ - $("#back").hide(); - } - }else{ - $("nav.navbar").removeClass("hidden"); - $("section").removeClass("section-margin"); - $(".page-loader-wrapper").removeClass("hidden"); - if(page!=undefined){ - $("#back").show(); - } - } +function showHideNavbar(webview, page) { + if (webview) { + $("nav.navbar").addClass("hidden"); + $("section").addClass("section-margin"); + $(".page-loader-wrapper").addClass("hidden"); + if (page != undefined) { + $("#back").hide(); + } + } else { + $("nav.navbar").removeClass("hidden"); + $("section").removeClass("section-margin"); + $(".page-loader-wrapper").removeClass("hidden"); + if (page != undefined) { + $("#back").show(); + } + } } function createAccessCode(code) { - localStorage.setItem("access_code",code); + localStorage.setItem("access_code", code); } //get menu item cache -function getAllMenu(){ - $.ajax({ - type: "GET", - url: '/origami/get_all_menu', - data: {}, - success:function(result){ - console.log(result) - localStorage.setItem("menus", JSON.stringify(result)); +function getAllMenu() { + $.ajax({ + type: "GET", + url: "/origami/get_all_menu", + data: {}, + success: function (result) { + console.log(result); + localStorage.setItem("menus", JSON.stringify(result)); - var menu = localStorage.getItem("menus"); - if (menu != null ) { - $( "#loading_wrapper").hide(); - } - } - }); + var menu = localStorage.getItem("menus"); + if (menu != null) { + $("#loading_wrapper").hide(); + } + }, + }); } /* String format */ if (!String.prototype.formatUnicorn) { - String.prototype.formatUnicorn=function(){ - var e=this.toString(); - if(!arguments.length){ - return e; - } - var t=typeof arguments[0],n="string"==t||"number"==t?Array.prototype.slice.call(arguments):arguments[0]; - for(var i in n){ - e=e.replace(new RegExp("\\{"+i+"\\}","gi"),n[i]==null?'':n[i]); - } - return e; - }; + String.prototype.formatUnicorn = function () { + var e = this.toString(); + if (!arguments.length) { + return e; + } + var t = typeof arguments[0], + n = + "string" == t || "number" == t + ? Array.prototype.slice.call(arguments) + : arguments[0]; + for (var i in n) { + e = e.replace( + new RegExp("\\{" + i + "\\}", "gi"), + n[i] == null ? "" : n[i] + ); + } + return e; + }; } /* String format */ //credit sales lists -function timeFormat(date){ +function timeFormat(date) { var isPM = date.getHours() >= 12; var isMidday = date.getHours() == 12; - var time = [(date.getHours()>10? date.getHours() : '0'+date.getHours()) - (isPM && !isMidday ? 12 : 0), - (date.getMinutes()>10? date.getMinutes() : '0'+date.getMinutes()) || '00'].join(':') + - (isPM ? ' PM' : ' AM'); + var time = + [ + (date.getHours() > 10 ? date.getHours() : "0" + date.getHours()) - + (isPM && !isMidday ? 12 : 0), + (date.getMinutes() > 10 ? date.getMinutes() : "0" + date.getMinutes()) || + "00", + ].join(":") + (isPM ? " PM" : " AM"); return time; } -function getCreditData(cashier_type){ - var filter = $("#filter").val(); - var customer = $("#sel_customer").val(); +function getCreditData(cashier_type) { + var filter = $("#filter").val(); + var customer = $("#sel_customer").val(); - var receipt_no = ""; - var customer_id = ""; - if((filter!=undefined) && (filter!=null) && (filter!="")){ - receipt_no = filter; - } - if((customer!=undefined) && (customer!=null) && (customer!="")){ - customer_id = customer; - } - getCreditSales(receipt_no, customer_id, cashier_type); + var receipt_no = ""; + var customer_id = ""; + if (filter != undefined && filter != null && filter != "") { + receipt_no = filter; + } + if (customer != undefined && customer != null && customer != "") { + customer_id = customer; + } + getCreditSales(receipt_no, customer_id, cashier_type); } -function getCreditSales(filter, customer, cashier_type){ - // $(".credit_items").hide(); - $(".tbd_credit_lists").empty(); - var html_credit_items = $("#html_credit_items").html(); - var receipt_no = ""; - var customer_id = ""; - if((filter!=undefined) && (filter!=null) && (filter!="")){ - receipt_no = filter; - } - if((customer!=undefined) && (customer!=null) && (customer!="")){ - customer_id = customer; - } - $.ajax({ - type: "POST", - data: {receipt_no: receipt_no, customer_id: customer_id}, - dataType: 'json', - url: "/origami/"+cashier_type+"/credit_sales", - success: function(data){ - // console.log(data); - if(data.status){ - var credit_sales = data.data; - // console.log(credit_sales); - if(credit_sales.length > 0){ - $(".credit_items").show(); - for (var i = 0; i < credit_sales.length ; i++) { - var sale_date = new Date(credit_sales[i].sale_date); - var receipt_date = sale_date.getFullYear() +'-'+ (sale_date.getMonth() > 10 ? (sale_date.getMonth()+1) : '0' + (sale_date.getMonth()+1)) +'-'+ (sale_date.getDate() > 10 ? sale_date.getDate() : '0' + sale_date.getDate()); - $('.tbd_credit_lists').append(html_credit_items.formatUnicorn({ - 'key':i, - 'sale_id':credit_sales[i].sale_id, - 'receipt_date':receipt_date +" "+timeFormat(sale_date), - 'receipt_no':credit_sales[i].receipt_no, - 'cashier_name':credit_sales[i].cashier_name, - 'customer_name':credit_sales[i].customer_name, - 'credit_amount':credit_sales[i].payment_amount, - 'cashier_type':cashier_type - })); - } - } - }else{ - $(".tbd_credit_lists").html(data.message); - } - } - }); +function getCreditSales(filter, customer, cashier_type) { + // $(".credit_items").hide(); + $(".tbd_credit_lists").empty(); + var html_credit_items = $("#html_credit_items").html(); + var receipt_no = ""; + var customer_id = ""; + if (filter != undefined && filter != null && filter != "") { + receipt_no = filter; + } + if (customer != undefined && customer != null && customer != "") { + customer_id = customer; + } + $.ajax({ + type: "POST", + data: { receipt_no: receipt_no, customer_id: customer_id }, + dataType: "json", + url: "/origami/" + cashier_type + "/credit_sales", + success: function (data) { + // console.log(data); + if (data.status) { + var credit_sales = data.data; + // console.log(credit_sales); + if (credit_sales.length > 0) { + $(".credit_items").show(); + for (var i = 0; i < credit_sales.length; i++) { + var sale_date = new Date(credit_sales[i].sale_date); + var receipt_date = + sale_date.getFullYear() + + "-" + + (sale_date.getMonth() > 10 + ? sale_date.getMonth() + 1 + : "0" + (sale_date.getMonth() + 1)) + + "-" + + (sale_date.getDate() > 10 + ? sale_date.getDate() + : "0" + sale_date.getDate()); + $(".tbd_credit_lists").append( + html_credit_items.formatUnicorn({ + key: i, + sale_id: credit_sales[i].sale_id, + receipt_date: receipt_date + " " + timeFormat(sale_date), + receipt_no: credit_sales[i].receipt_no, + cashier_name: credit_sales[i].cashier_name, + customer_name: credit_sales[i].customer_name, + credit_amount: credit_sales[i].payment_amount, + cashier_type: cashier_type, + }) + ); + } + } + } else { + $(".tbd_credit_lists").html(data.message); + } + }, + }); } //End of credit sales function diff --git a/app/controllers/foodcourt/void_controller.rb b/app/controllers/foodcourt/void_controller.rb index 80154300..9317d163 100755 --- a/app/controllers/foodcourt/void_controller.rb +++ b/app/controllers/foodcourt/void_controller.rb @@ -1,7 +1,7 @@ class Foodcourt::VoidController < BaseFoodcourtController - authorize_resource :class => false - def overall_void + authorize_resource :class => false + def overall_void sale_id = params[:sale_id] remark = params[:remark] order_source = params[:type] #tax profile source @@ -33,32 +33,10 @@ class Foodcourt::VoidController < BaseFoodcourtController sale.sale_status = 'void' sale.save - if sale.bookings[0].dining_facility_id.to_i > 0 - table_avaliable = true - table_count = 0 - table = sale.bookings[0].dining_facility - table.bookings.each do |booking| - if booking.booking_status != 'moved' - if booking.sale_id - if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' && booking.sale.sale_status != 'spoile' && booking.sale.sale_status != 'waste' - table_avaliable = false - table_count += 1 - else - table_avaliable = true - end - else - table_avaliable = false - table_count += 1 - end - end + if table = sale.booking.dining_facility + unless table.current_bookings.exists? + table.update_attributes(status: 'available') end - - if table_avaliable && table_count == 0 - table.status = 'available' - table.save - end - else - table = nil end # FOr Sale Audit @@ -100,47 +78,49 @@ class Foodcourt::VoidController < BaseFoodcourtController cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) end - customer= Customer.find(sale.customer_id) + customer= Customer.find(sale.customer_id) - # get member information - rebate = MembershipSetting.find_by_rebate(1) - if customer.membership_id != nil && rebate - member_info = Customer.get_member_account(customer) - rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no) - # current_balance = SaleAudit.paymal_search(sale_id) - current_balance = 0 - end + #shop detail + shop_details = Shop.current_shop + # get member information + rebate = MembershipSetting.find_by_rebate(1) + if customer.membership_id != nil && rebate + member_info = Customer.get_member_account(customer) + rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no) + # current_balance = SaleAudit.paymal_search(sale_id) + current_balance = 0 + end - printer = PrintSetting.all + printer = PrintSetting.all - unique_code="ReceiptBillPdf" - if !printer.empty? - printer.each do |printer_setting| - if printer_setting.unique_code == 'ReceiptBillPdf' - unique_code="ReceiptBillPdf" - elsif printer_setting.unique_code == 'ReceiptBillA5Pdf' - unique_code="ReceiptBillA5Pdf" - elsif printer_setting.unique_code == 'ReceiptBillStarPdf' - unique_code="ReceiptBillStarPdf" - end - end - end - # get printer info - print_settings=PrintSetting.find_by_unique_code(unique_code) - # Calculate Food and Beverage Total - item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items) - discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) - other_amount = SaleItem.calculate_other_charges(sale.sale_items) - printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,current_shop, "VOID",current_balance,nil,other_amount,nil,nil,nil,nil) - result = { - :filepath => filename, - :printer_model => print_settings.brand_name, - :printer_url => print_settings.api_settings - } + unique_code="ReceiptBillPdf" + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'ReceiptBillPdf' + unique_code="ReceiptBillPdf" + elsif printer_setting.unique_code == 'ReceiptBillA5Pdf' + unique_code="ReceiptBillA5Pdf" + elsif printer_setting.unique_code == 'ReceiptBillStarPdf' + unique_code="ReceiptBillStarPdf" + end + end + end + # get printer info + print_settings=PrintSetting.find_by_unique_code(unique_code) + # Calculate Food and Beverage Total + item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items) + discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) + other_amount = SaleItem.calculate_other_charges(sale.sale_items) + printer = Printer::ReceiptPrinter.new(print_settings) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil,other_amount,nil,nil,nil) + result = { + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings + } - # Mobile Print - render :json => result.to_json + # Mobile Print + render :json => result.to_json # end #end print diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 16cab5f1..72b319cc 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -96,22 +96,25 @@ class HomeController < ApplicationController def dashboard @from, @to = get_date_range_from_params + @shop = Shop.current_shop + @orders = Sale.receipt_date_between(@from, @to).where("payment_status = 'new' and sale_status = 'bill'") @sales = Sale.receipt_date_between(@from, @to).completed if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') - if shift = ShiftSale.current_open_shift(current_user) + if shift = ShiftSale.current_open_shift(current_user.id) @orders = @orders.where(shift_sale_id: shift.id) @sales = @sales.where(shift_sale_id: shift.id) end end - - @top_products = Sale.top_bottom_products(current_user,@from,@to,"top",current_shop) - @bottom_products = Sale.top_bottom_products(current_user,@from,@to,"bottom",current_shop) - @hourly_sales = Sale.hourly_sales(current_user,@from,@to,current_shop) - employee_sales = Sale.employee_sales(current_user,@from,@to,current_shop) - + @top_products = Sale.top_bottom_products(current_user,@from,@to,"top") + @bottom_products = Sale.top_bottom_products(current_user,@from,@to,"bottom") + @hourly_sales = Sale.hourly_sales(current_user,@from,@to) + # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') + # .sum(:grand_total) + employee_sales = Sale.employee_sales(current_user,@from,@to) + # .sum("(CASE WHEN sp.payment_method='cash' THEN ((sp.payment_amount) - (sales.amount_changed)) ELSE (sp.payment_amount) END)") @employee_sales = [] if !employee_sales.nil? employee_sales.each do |emp| @@ -123,12 +126,11 @@ class HomeController < ApplicationController end end end - @inventories = StockJournal.inventory_balances(@from,@to).sum(:balance) @total_trans = Sale.total_trans(current_user,@from,@to) @total_card = Sale.total_card_sale(current_user,@from,@to) - @total_credit = Sale.credit_payment(current_user,@from,@to, current_shop) + @total_credit = Sale.credit_payment(current_user,@from,@to) @sale_data = Array.new @total_payment_methods = Sale.total_payment_methods(current_user,@from,@to) @@ -144,12 +146,11 @@ class HomeController < ApplicationController @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(current_user,@from,@to) # @total_other_customer = Sale.total_other_customer(today,current_user) - @total_order = Sale.total_order(current_user,@from,@to, current_shop) + @total_order = Sale.total_order(current_user,@from,@to) @total_accounts = Account.select("accounts.id as account_id, accounts.title as title") @account_data = Array.new if !@total_accounts.nil? @total_accounts.each do |account| - acc = Sale.account_data(account.account_id,current_user,@from,@to) if !acc.nil? && acc.cnt_acc > 0 @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) @@ -162,7 +163,7 @@ class HomeController < ApplicationController @total_foc_items = Sale.total_foc_items(current_user,@from,@to) # get printer info - # @print_settings = get_precision_delimiter + @print_settings = PrintSetting.get_precision_delimiter() end def destroy diff --git a/app/controllers/origami/others_payments_controller.rb b/app/controllers/origami/others_payments_controller.rb index 3d95bbb0..fb75288d 100755 --- a/app/controllers/origami/others_payments_controller.rb +++ b/app/controllers/origami/others_payments_controller.rb @@ -5,7 +5,7 @@ class Origami::OthersPaymentsController < BaseOrigamiController @cashier_type = params[:type] path = request.fullpath if path.include? ("credit_payment") - @payment_method_setting = PaymentMethodSetting.where("LOWER(payment_method) in ('mpu','visa','master','jcb','unionpay','alipay') and is_active='1'") + @payment_method_setting = PaymentMethodSetting.where("is_active='1'") else @payment_method_setting = PaymentMethodSetting.all end @@ -39,7 +39,92 @@ class Origami::OthersPaymentsController < BaseOrigamiController # end end + def new + @sale_id = params[:sale_id] + @cashier_type = params[:type] + payment_methods = PaymentMethodSetting.pluck(:payment_method) + if @payment_method = payment_methods.find { |m| m.parameterize == params[:method] } + path = request.fullpath + # limit master_amount + if path.include? ("credit_payment") + sale_data = Sale.get_sale_data_for_other_payment_credit(@sale_id) + else + sale_data = Sale.find_by_sale_id(@sale_id) + end + total = 0 + @shop = Shop.current_shop + @paid_amount = 0 + @can_paid = 0 + @rounding_adj = 0 + @member_discount = 0 + @sub_total = 0 + @membership_id = nil + @receipt_no = nil + if !sale_data.nil? + total = sale_data.grand_total + + others = 0 + + if @shop.is_rounding_adj + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + else + new_total = sale_data.grand_total + end + + @rounding_adj = new_total-sale_data.grand_total + + if path.include? ("credit_payment") + sale_payment_data = SalePayment.get_sale_payment_for_credit(sale_data) + else + sale_payment_data = sale_data.sale_payments + end + + sale_payment_data.each do |sale_payment| + if sale_payment.payment_method == @payment_method.parameterize + @paid_amount = @paid_amount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_paid = total - @paid_amount - others + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id + #for bank integration + @receipt_no = sale_data.receipt_no + end + bank_integration = Lookup.collection_of('bank_integration') + @bank_integration = 0 + if !bank_integration[0].nil? + @bank_integration = bank_integration[0][1] + end + else + if path.include? ("credit_payment") + redirect_to "sale/#{@sale_id}/#{@cashier_type}/payment/others_payment" + else + redirect_to "sale/#{@sale_id}/#{@cashier_type}/credit_payment/others_payment" + end + end + end + def create + cash = params[:amount] + sale_id = params[:sale_id] + ref_no = params[:ref_no] + payment_method = params[:method] + if PaymentMethodSetting.pluck(:payment_method).map(&:parameterize).include? payment_method + if saleObj = Sale.find(sale_id) + shop_details = Shop.current_shop + + path = request.fullpath + payment_for = false + if path.include? ("credit_payment") + payment_for = true + end + sale_payment = SalePayment.new + @status, @sale = sale_payment.process_payment(saleObj, current_user, cash, payment_method, ref_no, payment_for) + end + end end end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index a008ca63..8f19d713 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -51,7 +51,8 @@ class Origami::PaymentsController < BaseOrigamiController #TODO :: KBZPAY ( QR ) # On/Off setting ( show or not qr ) # qrCode = "00020101021202021110500346KBZ005ab0ed5c1ed09d1c4585ff1313170389160831435294600062000040732kp1e78f7efddca190042638341afb88d50200006KBZPay0106KBZPay5303MMK5802MM62170813PAY_BY_QRCODE64060002my6304FBBD" - kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last + kbz_pay_method = PaymentMethodSetting.where(payment_method: KbzPay::KBZ_PAY, gateway_communication_type: ['api', 'Api'], is_active: true) + .where.not(gateway_url: [nil, ''], auth_token: [nil, ''], merchant_account_id: [nil, '']).last status = false qr = nil @@ -193,7 +194,7 @@ class Origami::PaymentsController < BaseOrigamiController end #card_balance amount for Paymal payment - card_balance_amount,transaction_ref = SaleAudit.getCardBalanceAmount(sale_id) + card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id) # get printer info print_settings = PrintSetting.find_by_unique_code(unique_code) @@ -209,7 +210,7 @@ class Origami::PaymentsController < BaseOrigamiController end printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal, sale_items, saleObj, customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, rebate_amount, current_shop, "Paid", current_balance, card_data, other_amount, latest_order_no, card_balance_amount, nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,current_shop, printed_status,current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil) #end @@ -232,15 +233,29 @@ class Origami::PaymentsController < BaseOrigamiController # end def show + @sale = Sale.find(params[:sale_id]) + @shop = Shop.current_shop + @customer = @sale.customer + @customer_lists = Customer.where(name: ["WALK-IN", "TAKEAWAY"]) + @member_discount = MembershipSetting.find_by_discount(1) + + if dining_facility = @sale.booking.dining_facility + @table_no = dining_facility.type + ' ' + dining_facility.name + @checkin_time = @sale.booking.checkin_at + @dining = dining_facility + end + display_type = Lookup.find_by_lookup_type("display_type") - if !display_type.nil? && display_type.value.to_i ==2 + if !display_type.nil? && display_type.value.to_i ==2 @display_type = display_type.value else @display_type = nil - end + end + path = request.fullpath - sale_id = params[:sale_id] + @trans_flag = true + if params[:type] == "transaction" @trans_flag = false @cashier_type = "cashier" @@ -248,201 +263,111 @@ class Origami::PaymentsController < BaseOrigamiController @cashier_type = params[:type] end - if path.include? ("credit_payment") - @sale_payment = SalePayment.where(sale_id: sale_id, payment_method: 'creditnote').select("SUM(payment_amount) as payment_amount") + if path.include? 'credit_payment' + @sale_payment = false + @amount_due = @sale.sale_payments.where(payment_method: 'creditnote').pluck('SUM(payment_amount)').first + payments = @sale.sale_payments.joins(:sale_audit).group_by(&:payment_method).map { |method, payments| [method == 'paypar' ? 'redeem' : method, payments.sum { |payment| payment.payment_amount }] } + else + @sale_payment = true + @amount_due = @sale.grand_total + payments = @sale.sale_payments.left_joins(:sale_audit).where(sale_audits: {sale_audit_id: nil}).group_by(&:payment_method).map { |method, payments| [method == 'paypar' ? 'redeem' : method, payments.sum { |payment| payment.payment_amount }] } end - @member_discount = MembershipSetting.find_by_discount(1) - @membership_rebate_balance=0 + @payment_methods = PaymentMethodSetting.where(is_active: true).pluck(:payment_method) + @cash = payments.inject(0) { |sum, payment| sum + payment[1] if payment[0] == 'cash' } + @credit = payments.inject(0) { |sum, payment| sum + payment[1] if payment[0] == 'creditnote' } + @other_payments = payments.select { |payment| !['cash', 'creditnote', 'foc'].include? payment[0] }.map { |method, amount| [ @payment_methods.find { |payment_method| payment_method.parameterize == method }, amount ] } + @other_payment = @other_payments.sum { |payment| payment[1] } - if Sale.exists?(sale_id) - @cash = 0.0 - @kbz_pay_amount = 0.0 - @other = 0.0 - @ppamount = 0.0 - @visacount= 0.0 - @jcbcount= 0.0 - @mastercount = 0.0 - @unionpaycount = 0.0 - @alipaycount = 0.0 - @junctionpaycount = 0.0 - @credit = 0.0 - @paymalcount = 0.0 - @dingacount = 0.0 - @giftvouchercount = 0.0 - @sale_data = Sale.find_by_sale_id(sale_id) - @balance = 0 - @accountable_type = '' - @table_no = '' - @dining = '' - @other_payment = 0.0 - @pdf_view = nil - @lookup_pdf = Lookup.find_by_lookup_type("ReceiptPdfView") - if !@lookup_pdf.nil? - @pdf_view = @lookup_pdf.value - end + #total customer with individual total amount + @individual_total = Array.new + if !@sale.equal_persons.nil? + per_person_amount = @sale.grand_total / @sale.equal_persons.to_i + @individual_total.push({'total_customer' => @sale.equal_persons.to_i, 'per_person_amount' => per_person_amount }) + end - amount = SalePayment.get_kbz_pay_amount(sale_id, current_user) - @kbz_pay_amount += amount.to_f - - #for changable on/off - @changable_tax = true - lookup_changable_tax = Lookup.collection_of('changable_tax') - if !lookup_changable_tax.empty? - lookup_changable_tax.each do |changable_tax| - if changable_tax[0].downcase == "change" - if changable_tax[1] == '0' - @changable_tax = false - end + #for changable on/off + @changable_tax = true + lookup_changable_tax = Lookup.collection_of('changable_tax') + if !lookup_changable_tax.empty? + lookup_changable_tax.each do |changable_tax| + if changable_tax[0].downcase == "change" + if changable_tax[1] == '0' + @changable_tax = false end end end + end - # @shop = shop_detail #show shop info + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() - @customer_lists = Customer.where(name: ["WALK-IN", "TAKEAWAY"]) + @pdf_view = nil + @lookup_pdf = Lookup.find_by_lookup_type("ReceiptPdfView") + if !@lookup_pdf.nil? + @pdf_view = @lookup_pdf.value + end - saleObj = Sale.find(sale_id) + # amount = SalePayment.get_kbz_pay_amount(sale_id, current_user) + # @kbz_pay_amount += amount.to_f - #total customer with individual total amount - @individual_total = Array.new - if !saleObj.equal_persons.nil? - per_person_amount = saleObj.grand_total.to_f / saleObj.equal_persons.to_i - @individual_total.push({'total_customer' => saleObj.equal_persons.to_i, 'per_person_amount' => per_person_amount.to_f }) + # rounding adjustment + # if @shop.is_rounding_adj + # a = saleObj.grand_total % 25 # Modulus + # b = saleObj.grand_total / 25 # Division + # #not calculate rounding if modulus is 0 and division is even + # #calculate rounding if modulus is zero or not zero and division are not even + # if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) + # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) + # @rounding_adj = new_total-saleObj.grand_total + # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:@rounding_adj) + # @sale_data.grand_total = new_total + # @sale_data.old_grand_total = saleObj.grand_total + # @sale_data.rounding_adjustment = @rounding_adj + # else + # @rounding_adj = @sale_data.rounding_adjustment + # end + # else + # @rounding_adj = @sale_data.rounding_adjustment + # end + #end rounding adjustment + + # accounts = @customer.tax_profiles + accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC") + @account_arr =[] + @tax_arr =[] + + accounts.each do |acc| + account = TaxProfile.find(acc.id) + # @account_arr.push(account) + @tax_arr.push(account.name) + end + + sale_taxes = @sale.sale_taxes + if !sale_taxes.empty? + sale_taxes.each do |sale_tax| + @account_arr.push(sale_tax) end + end - # rounding adjustment - # if @shop.is_rounding_adj - # a = saleObj.grand_total % 25 # Modulus - # b = saleObj.grand_total / 25 # Division - # #not calculate rounding if modulus is 0 and division is even - # #calculate rounding if modulus is zero or not zero and division are not even - # if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) - # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) - # @rounding_adj = new_total-saleObj.grand_total - # else - # @rounding_adj = @sale_data.rounding_adjustment - # end - # else - # @rounding_adj = @sale_data.rounding_adjustment - # end - #end rounding adjustment + rebate = MembershipSetting.find_by_rebate(1) - # rounding adjustment - if current_shop.is_rounding_adj - a = saleObj.grand_total % 25 # Modulus - b = saleObj.grand_total / 25 # Division - #not calculate rounding if modulus is 0 and division is even - #calculate rounding if modulus is zero or not zero and division are not even - if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) - new_total = Sale.get_rounding_adjustment(saleObj.grand_total) - @rounding_adj = new_total-saleObj.grand_total - saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:@rounding_adj) - @sale_data.grand_total = new_total - @sale_data.old_grand_total = saleObj.grand_total - @sale_data.rounding_adjustment = @rounding_adj - else - @rounding_adj = @sale_data.rounding_adjustment - end - else - @rounding_adj = @sale_data.rounding_adjustment - end - #end rounding adjustment - - # get printer info - @print_settings = PrintSetting.get_precision_delimiter() - - #get customer amount - @customer = Customer.find(@sale_data.customer_id) - # accounts = @customer.tax_profiles - accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC") - @account_arr =[] - @tax_arr =[] - accounts.each do |acc| - account = TaxProfile.find(acc.id) - # @account_arr.push(account) - @tax_arr.push(account.name) - end - sale_taxes = SaleTax.where("sale_id = ?", saleObj.sale_id) - if !sale_taxes.empty? - sale_taxes.each do |sale_tax| - @account_arr.push(sale_tax) - end - end - rebate = MembershipSetting.find_by_rebate(1) - # get member information - if @customer.membership_id != nil && rebate - response = Customer.get_member_account(@customer) - if response["status"]==true - response["account_data"].each do |res| + # get member information + @balance = 0 + @accountable_type = '' + if @customer.membership_id != nil && rebate + response = Customer.get_member_account(@customer) + if response["status"]==true + response["account_data"].each do |res| if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount" @balance = @balance.to_f + res["balance"].to_f # @accountable_type = res["accountable_type"] @accountable_type = "Rebate Balance" end end - end - end - - #end customer amount - - #paymal payment - - @sale_data.bookings.each do |sbk| - if sbk.dining_facility_id.to_i >0 - df = DiningFacility.find(sbk.dining_facility_id) - @table_no = df.type + ' ' + df.name - @checkin_time = sbk.checkin_at - @dining = df - break - else - @table_no = nil - @checkin_time = nil - @dining = nil - end - end - - if path.include? ("credit_payment") - @sale_payment_data = SalePayment.get_sale_payment_for_credit(@sale_data) - else - @sale_payment_data = SalePayment.get_sale_payments(@sale_data) - end - @sale_payment_data.each do |spay| - if spay.payment_method == "cash" - @cash += spay.payment_amount - end - if spay.payment_method !="creditnote" - @other_payment += spay.payment_amount - end - - if spay.payment_method == "mpu" - @other += spay.payment_amount - elsif spay.payment_method == "paypar" - @ppamount += spay.payment_amount - elsif spay.payment_method == "visa" - @visacount += spay.payment_amount - elsif spay.payment_method == "jcb" - @jcbcount += spay.payment_amount - elsif spay.payment_method == "master" - @mastercount += spay.payment_amount - elsif spay.payment_method == "unionpay" - @unionpaycount += spay.payment_amount - elsif spay.payment_method == "JunctionPay" - @junctionpaycount += spay.payment_amount - elsif spay.payment_method == "creditnote" - @credit += spay.payment_amount - elsif spay.payment_method == "paymal" - @paymalcount += spay.payment_amount - elsif spay.payment_method == "alipay" - @alipaycount += spay.payment_amount - elsif spay.payment_method == "dinga" - @dingacount += spay.payment_amount - elsif spay.payment_method == "giftvoucher" - @giftvouchercount += spay.payment_amount - end - end end + #end customer amount end def reprint @@ -465,7 +390,7 @@ class Origami::PaymentsController < BaseOrigamiController # else # table = DiningFacility.find(bookings[0].dining_facility_id) # end - shift = ShiftSale.current_open_shift(current_user) + shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) else @@ -496,7 +421,7 @@ class Origami::PaymentsController < BaseOrigamiController customer= Customer.find(saleObj.customer_id) #shop detail - #shop_detail = @shop + #shop_detail = Shop.current_shop # get member information rebate = MembershipSetting.find_by_rebate(1) if customer.membership_id != nil && rebate @@ -519,7 +444,7 @@ class Origami::PaymentsController < BaseOrigamiController end #card_balance amount for Paymal payment - card_balance_amount,transaction_ref = SaleAudit.getCardBalanceAmount(sale_id) + card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id) # get printer info print_settings=PrintSetting.find_by_unique_code(unique_code) @@ -531,7 +456,7 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount, current_shop, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,current_shop, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil) result = { :status => true, @@ -581,7 +506,7 @@ class Origami::PaymentsController < BaseOrigamiController # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") - shift = ShiftSale.current_open_shift(current_user) + shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) else @@ -603,8 +528,7 @@ class Origami::PaymentsController < BaseOrigamiController customer= Customer.find(saleObj.customer_id) #shop detail - - #shop_detail = @shop + #shop_detail = Shop.current_shop printer = PrintSetting.all unique_code="ReceiptBillPdf" @@ -629,7 +553,7 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,current_shop, "FOC",nil,nil,other_amount,nil,nil,nil,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,current_shop, "FOC",nil,nil,other_amount,nil,nil,nil) result = { :status => true, :filepath => filename, @@ -663,8 +587,9 @@ class Origami::PaymentsController < BaseOrigamiController def rounding_adj saleObj = Sale.find(params[:sale_id]) + @shop = current_shop - if current_shop.is_rounding_adj + if @shop.is_rounding_adj a = saleObj.grand_total % 25 # Modulus b = saleObj.grand_total / 25 # Division #not calculate rounding if modulus is 0 and division is even diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 55ef52f5..4ec5b084 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -1,10 +1,12 @@ class Origami::VoidController < BaseOrigamiController - authorize_resource :class => false + authorize_resource :class => false + def overall_void sale_id = params[:sale_id] remark = params[:remark] order_source = params[:type] #tax profile source access_code = params[:access_code] + if Sale.exists?(sale_id) sale = Sale.find_by_sale_id(sale_id) if sale.discount_type == "member_discount" @@ -41,32 +43,10 @@ class Origami::VoidController < BaseOrigamiController # end # end - if sale.bookings[0].dining_facility_id.to_i > 0 - table_avaliable = true - table_count = 0 - table = sale.bookings[0].dining_facility - table.bookings.each do |booking| - if booking.booking_status != 'moved' - if booking.sale_id - if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' && booking.sale.sale_status != 'spoile' && booking.sale.sale_status != 'waste' - table_avaliable = false - table_count += 1 - else - table_avaliable = true - end - else - table_avaliable = false - table_count += 1 - end - end + if table = sale.booking.dining_facility + unless table.current_bookings.exists? + table.update_attributes(status: 'available') end - - if table_avaliable && table_count == 0 - table.status = 'available' - table.save - end - else - table = nil end # FOr Sale Audit @@ -112,46 +92,49 @@ class Origami::VoidController < BaseOrigamiController # unique_code = 'ReceiptBillStarPdf' # end - customer= Customer.find(sale.customer_id) - # get member information - rebate = MembershipSetting.find_by_rebate(1) - if customer.membership_id != nil && rebate - member_info = Customer.get_member_account(customer) - rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no) - # current_balance = SaleAudit.paymal_search(sale_id) - current_balance = 0 - end + customer= Customer.find(sale.customer_id) - printer = PrintSetting.all + #shop detail + shop_details = Shop.current_shop + # get member information + rebate = MembershipSetting.find_by_rebate(1) + if customer.membership_id != nil && rebate + member_info = Customer.get_member_account(customer) + rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no) + # current_balance = SaleAudit.paymal_search(sale_id) + current_balance = 0 + end - unique_code="ReceiptBillPdf" - if !printer.empty? - printer.each do |printer_setting| - if printer_setting.unique_code == 'ReceiptBillPdf' - unique_code="ReceiptBillPdf" - elsif printer_setting.unique_code == 'ReceiptBillA5Pdf' - unique_code="ReceiptBillA5Pdf" - elsif printer_setting.unique_code == 'ReceiptBillStarPdf' - unique_code="ReceiptBillStarPdf" - end - end - end - # get printer info - print_settings=PrintSetting.find_by_unique_code(unique_code) - # Calculate Food and Beverage Total - item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items) - discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) - other_amount = SaleItem.calculate_other_charges(sale.sale_items) - printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,current_shop, "VOID",current_balance,nil,other_amount,nil,nil,nil,nil) - result = { - :filepath => filename, - :printer_model => print_settings.brand_name, - :printer_url => print_settings.api_settings - } + printer = PrintSetting.all - # Mobile Print - render :json => result.to_json + unique_code="ReceiptBillPdf" + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'ReceiptBillPdf' + unique_code="ReceiptBillPdf" + elsif printer_setting.unique_code == 'ReceiptBillA5Pdf' + unique_code="ReceiptBillA5Pdf" + elsif printer_setting.unique_code == 'ReceiptBillStarPdf' + unique_code="ReceiptBillStarPdf" + end + end + end + # get printer info + print_settings=PrintSetting.find_by_unique_code(unique_code) + # Calculate Food and Beverage Total + item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items) + discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) + other_amount = SaleItem.calculate_other_charges(sale.sale_items) + printer = Printer::ReceiptPrinter.new(print_settings) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil,other_amount,nil,nil,nil) + result = { + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings + } + + # Mobile Print + render :json => result.to_json # end #end print diff --git a/app/controllers/reports/payment_method_controller.rb b/app/controllers/reports/payment_method_controller.rb index c9983b9f..b75a6b34 100644 --- a/app/controllers/reports/payment_method_controller.rb +++ b/app/controllers/reports/payment_method_controller.rb @@ -1,66 +1,69 @@ class Reports::PaymentMethodController < BaseReportController -# authorize_resource :class => false - def index - @payments = [["All Payment",''],["Cash Payment","cash"], ["KBZ Payment", KbzPay::KBZ_PAY], ["Credit Payment","creditnote"], - ["FOC Payment","foc"], ["MPU Payment","mpu"], ["Visa Payment","visa"], - ["Master Payment","master"], ["JCB Payment","jcb"],["UnionPay Payment","unionpay"], - ["Alipay Payment","alipay"],["Card Payment", "paymal"],["Dinga Payment","dinga"], - ["JunctionPay","junctionpay"],["Redeem Payment","paypar"],["Gift Voucher","giftvoucher"]] + # authorize_resource :class => false + def index - from, to = get_date_range_from_params + @payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method") - @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + @payments = [["All",''], ["Cash","cash"], ["Card", "card"], ["Credit","creditnote"], + ["FOC","foc"]] + PaymentMethodSetting.pluck(:payment_method).map { |payment_method| [payment_method, payment_method.parameterize] } - @shift = '' - if params[:shift_name].to_i != 0 - shift_sale = ShiftSale.find(params[:shift_name]) - if to.blank? - @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL",shift_sale.shift_started_at) - else - @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at = ?",shift_sale.shift_started_at, shift_sale.shift_closed_at) - end - end - @payment_type = params[:payment_type] - @sale_data,@pyament_method = Sale.get_payment_method_by_shift(@shift_sale_range,@shift,from,to,@payment_type) - @from = from - @to = to - # get printer info - @print_settings = PrintSetting.get_precision_delimiter() - if @shift.present? - @shift.each do |sh| - @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") - @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") - @shift_data = sh - end - end + # @payment_methods.each do |m| + # @payments.push(["#{m} Payment", m.parameterize]) + # end + + from, to = get_date_range_from_params + + + @shift = '' + if params[:shift_name].to_i != 0 + shift_sale = ShiftSale.find(params[:shift_name]) + if to.blank? + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) + else + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) + end + end + @payment_type = params[:payment_type] + @sale_data,@pyament_method = Sale.get_payment_method_by_shift(@shift,from,to,@payment_type) + @from = from + @to = to + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + if @shift.present? + @shift.each do |sh| + @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_data = sh + end + end + + respond_to do |format| + format.html + format.xls + end + end + + def show + from, to = get_date_range_from_params + + @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) + + date_arr = Array.new + @sale_data.each do |sale| + local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") + local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") + opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc + closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc + shift_id = sale.id.nil? ? '-' : sale.id + str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} + date_arr.push(str) + end + + out = {:status => 'ok', :message => date_arr} + + respond_to do |format| + format.json { render json: out } + end + end - respond_to do |format| - format.html - format.xls - end end - - def show - from, to = get_date_range_from_params - - @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) - - date_arr = Array.new - @sale_data.each do |sale| - local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") - local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") - opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc - closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc - shift_id = sale.id.nil? ? '-' : sale.id - str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} - date_arr.push(str) - end - - out = {:status => 'ok', :message => date_arr} - - respond_to do |format| - format.json { render json: out } - end - end - -end diff --git a/app/controllers/reports/receipt_no_detail_controller.rb b/app/controllers/reports/receipt_no_detail_controller.rb index 2eba9e18..b119b7f9 100755 --- a/app/controllers/reports/receipt_no_detail_controller.rb +++ b/app/controllers/reports/receipt_no_detail_controller.rb @@ -1,72 +1,69 @@ class Reports::ReceiptNoDetailController < BaseReportController -authorize_resource :class => false - def index - @payments = [["All Payment",''], ["Cash Payment","cash"], ["Credit Payment","creditnote"], ["FOC Payment","foc"]] - @payment_method = PaymentMethodSetting.all - from, to = get_date_range_from_params + authorize_resource :class => false + def index + @payment_methods = [["All", ''], ["Cash", "cash"], ["Card", "card"], ["Credit", "creditnote"], ["FOC", "foc"]] + PaymentMethodSetting.pluck(:payment_method).map { |payment_method| [payment_method, payment_method.parameterize] } - @shift_sale_range = '' + from, to = get_date_range_from_params - @shift = '' - if params[:shift_name].to_i != 0 + @shift_sale_range = '' - @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + @shift = '' + if params[:shift_name].to_i != 0 + @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) - @shift_sale = ShiftSale.find(params[:shift_name]) - if to.blank? - @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',@shift_sale.shift_started_at) - else - if @shift_sale.shift_closed_at.blank? - @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL",@shift_sale.shift_started_at) - else - @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at = ?",@shift_sale.shift_started_at, @shift_sale.shift_closed_at) - end - end - end + @shift_sale = ShiftSale.find(params[:shift_name]) + if to.blank? + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',@shift_sale.shift_started_at) + else + if @shift_sale.shift_closed_at.blank? + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',@shift_sale.shift_started_at) + else + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',@shift_sale.shift_started_at, @shift_sale.shift_closed_at) + end + end + end - payment_type = params[:payment_type] + payment_type = params[:payment_type] + @sale_data = Sale.get_shift_sales_by_receipt_no_detail(@shift_sale_range,@shift,from,to,payment_type) - @sale_data = Sale.get_shift_sales_by_receipt_no_detail(@shift_sale_range,@shift,from,to,payment_type) - - - @from = from - @to = to - # get printer info - @print_settings = PrintSetting.get_precision_delimiter() - if @shift.present? - @shift.each do |sh| - @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") - @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") - @shift_data = sh - end - end - respond_to do |format| - format.html - format.xls - end - end - - def show - from, to = get_date_range_from_params - - @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) - - date_arr = Array.new - @sale_data.each do |sale| - local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") - local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") - opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc - closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc - shift_id = sale.id.nil? ? '-' : sale.id - str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} - date_arr.push(str) + @from = from + @to = to + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + if @shift.present? + @shift.each do |sh| + @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_data = sh + end + end + respond_to do |format| + format.html + format.xls + end end - out = {:status => 'ok', :message => date_arr} + def show + from, to = get_date_range_from_params + + @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + + date_arr = Array.new + @sale_data.each do |sale| + local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") + local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") + opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc + closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc + shift_id = sale.id.nil? ? '-' : sale.id + str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} + date_arr.push(str) + end + + out = {:status => 'ok', :message => date_arr} + + respond_to do |format| + format.json { render json: out } + end + end - respond_to do |format| - format.json { render json: out } - end end - -end diff --git a/app/controllers/reports/shiftsale_controller.rb b/app/controllers/reports/shiftsale_controller.rb index be23d412..998842ef 100755 --- a/app/controllers/reports/shiftsale_controller.rb +++ b/app/controllers/reports/shiftsale_controller.rb @@ -26,7 +26,6 @@ class Reports::ShiftsaleController < BaseReportController end def show - from, to = get_date_range_from_params @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @@ -50,7 +49,6 @@ class Reports::ShiftsaleController < BaseReportController end def print_close_receipt - shift_id = params[:id] @shift = ShiftSale.find_by_id(shift_id) shift_obj = ShiftSale.where('id =?',shift_id) @@ -82,6 +80,7 @@ class Reports::ShiftsaleController < BaseReportController @total_spoile = Sale.get_total_spoile(shift_id).sum(:grand_total) #other payment details for mpu or visa like card @other_payment = ShiftSale.get_by_shift_other_payment(@shift) + @payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method") # Calculate price_by_accounts @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') @@ -97,7 +96,7 @@ class Reports::ShiftsaleController < BaseReportController printer = Printer::CashierStationPrinter.new(print_settings) # printer.print_close_cashier(print_settings,cashier_terminal,@shift, nil, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments) - printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, current_shops,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments) + printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments,@payment_methods) respond_to do |format| format.html { redirect_to '/en/reports/shiftsale/', notice: 'Printing Completed.'} diff --git a/app/controllers/transactions/shift_sales_controller.rb b/app/controllers/transactions/shift_sales_controller.rb index dc06c9eb..78af17a4 100644 --- a/app/controllers/transactions/shift_sales_controller.rb +++ b/app/controllers/transactions/shift_sales_controller.rb @@ -4,14 +4,13 @@ class Transactions::ShiftSalesController < ApplicationController before_action :check_user def index - filter = params[:filter] from = params[:from] to = params[:to] if filter.nil? && from.nil? && to.nil? - @shift_sales = ShiftSale.order("id desc") + @shift_sales = ShiftSale.all.order("id desc") @shift_sales = Kaminari.paginate_array(@shift_sales).page(params[:page]).per(20) else shift_sale = ShiftSale.search(filter,from,to) @@ -33,22 +32,20 @@ class Transactions::ShiftSalesController < ApplicationController # GET /transactions/shift_sales/1 # GET /transactions/shift_sales/1.json def show - + @shift = ShiftSale.find(params[:id]) #get tax shift_obj = ShiftSale.where('id =?',@shift.id) @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') #other payment details for mpu or visa like card - @other_payment = ShiftSale.get_by_shift_other_payment(@shift) - + @other_payment = ShiftSale.get_by_shift_other_payment(@shift).first + @payment_methods = PaymentMethodSetting.where(is_active: true).pluck(:payment_method) # Calculate price_by_accounts @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') @total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount') @total_member_discount = ShiftSale.get_total_member_discount(@shift) - - respond_to do |format| format.html # show.html.erb format.json { render json: @shift } diff --git a/app/models/sale.rb b/app/models/sale.rb index e7ace120..1651524a 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -35,7 +35,10 @@ class Sale < ApplicationRecord scope :completed, -> { where(sale_status: 'completed') } scope :receipt_date_between, -> (from, to) { where(receipt_date: from..to) } - scope :along_with_sale_payments_except_void_between, -> (from, to) { joins(sanitize_sql_array(["LEFT JOIN sale_payments ON sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND sale_payments.created_at BETWEEN ? and ?", from, to])) } + scope :sale_payments_with_audit_except_void_between, -> (from, to) do + joins(sanitize_sql_array(["LEFT JOIN sale_payments ON sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND sale_payments.created_at BETWEEN ? and ?", from, to])) + .joins("LEFT JOIN sale_audits ON sale_audits.sale_id = sale_payments.sale_id AND SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id") + end def qty_of(item_instance_code) order_items.select(:order_items_id, :item_instance_code, 'SUM(qty) as qty').where(item_instance_code: item_instance_code).group(:item_instance_code).first @@ -789,65 +792,40 @@ class Sale < ApplicationRecord end def self.daily_sales_list(from,to) - sales = select(" - sales.*, - SUM(case when (sale_payments.payment_method='KBZPay') then sale_payments.payment_amount else 0 end) as kbzpay_amount, - SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount, - SUM(case when (sale_payments.payment_method='master') then sale_payments.payment_amount else 0 end) as master_amount, - SUM(case when (sale_payments.payment_method='visa') then sale_payments.payment_amount else 0 end) as visa_amount, - SUM(case when (sale_payments.payment_method='jcb') then sale_payments.payment_amount else 0 end) as jcb_amount, - SUM(case when (sale_payments.payment_method='paypar') then sale_payments.payment_amount else 0 end) as paypar_amount, - SUM(case when (sale_payments.payment_method='unionpay') then sale_payments.payment_amount else 0 end) as unionpay_amount, - SUM(case when (sale_payments.payment_method='alipay') then sale_payments.payment_amount else 0 end) as alipay_amount, - SUM(case when (sale_payments.payment_method='paymal') then sale_payments.payment_amount else 0 end) as paymal_amount, - SUM(case when (sale_payments.payment_method='dinga') then sale_payments.payment_amount else 0 end) as dinga_amount, - SUM(case when (sale_payments.payment_method='JunctionPay') then sale_payments.payment_amount else 0 end) as junctionpay_amount, - SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount, - CASE WHEN SUM(case when sale_payments.payment_method not in('creditnote') - then sale_payments.payment_amount else 0 end) < sales.grand_total - THEN sales.grand_total - SUM(case when sale_payments.payment_method not in('creditnote') - then sale_payments.payment_amount else 0 end) - ELSE 0 END as credit_amount, - SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount, - SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount") - .along_with_sale_payments_except_void_between(from, to) - .where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to) - .group("sale_id").to_sql + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) + + sales = select(Sale.column_names) + .select("#{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method == 'paypar' ? 'redeem' : method}"}.push('').join(', ')} + SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount, + SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) - + SUM(case when (sale_payments.payment_method not in('creditnote') and sale_audits.sale_audit_id IS NOT NULL) then sale_payments.payment_amount else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount") + .sale_payments_with_audit_except_void_between(from, to) + .where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to) + .group("sale_id").to_sql daily_total = connection.select_all("SELECT - IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total, - IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as total_sale, - IFNULL(SUM(case when (sale_status='completed') then old_grand_total else 0 end),0) as old_grand_total, - IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0) as total_discount, - IFNULL(SUM(case when (sale_status='completed') then amount_changed else 0 end),0) as total_change_amount, - IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount, - IFNULL(SUM(case when (sale_status='completed') then rounding_adjustment else 0 end),0) as rounding_adj, - IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21 as tax, - (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0))-(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21) as net_sale, - (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) + (IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0)) as gross_sale, - CAST((CONVERT_TZ(receipt_date,'+00:00','+06:30')) AS DATE) as sale_date, - SUM(kbzpay_amount) as kbzpay_amount, - SUM(mpu_amount) as mpu_amount, - SUM(master_amount) as master_amount, - SUM(visa_amount) as visa_amount, - SUM(jcb_amount) as jcb_amount, - SUM(paypar_amount) as paypar_amount, - SUM(unionpay_amount) as unionpay_amount, - SUM(alipay_amount) as alipay_amount, - SUM(paymal_amount) as paymal_amount, - SUM(dinga_amount) as dinga_amount, - SUM(junctionpay_amount) as junctionpay_amount, - SUM(cash_amount) as cash_amount, - SUM(credit_amount) as credit_amount, - SUM(giftvoucher_amount) as giftvoucher_amount, - SUM(foc_amount) as foc_amount - FROM ( - #{sales} - ) as s - GROUP BY DATE(CONVERT_TZ(receipt_date,'+00:00','+06:30'))").to_hash.map(&:symbolize_keys) - - return daily_total -end + IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total, + IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as total_sale, + IFNULL(SUM(case when (sale_status='completed') then old_grand_total else 0 end),0) as old_grand_total, + IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0) as total_discount, + IFNULL(SUM(case when (sale_status='completed') then amount_changed else 0 end),0) as total_change_amount, + IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount, + IFNULL(SUM(case when (sale_status='completed') then rounding_adjustment else 0 end),0) as rounding_adj, + IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21 as tax, + (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) - (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21) as net_sale, + (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) + (IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0)) as gross_sale, + CAST((CONVERT_TZ(receipt_date,'+00:00','+06:30')) AS DATE) as sale_date, + #{payment_methods.map { |method| pm = method == 'paypar' ? 'redeem' : method; "SUM(#{pm}) as #{pm}"}.push('').join(', ')} + SUM(cash_amount) as cash_amount, + SUM(credit_amount) as credit_amount, + SUM(foc_amount) as foc_amount + FROM ( + #{sales} + ) as s + GROUP BY DATE(CONVERT_TZ(receipt_date,'+00:00','+06:30'))").to_hash.map(&:symbolize_keys) + return daily_total + end def self.get_by_range_by_saleitems(from,to,status,report_type) query = Sale.select(" @@ -1013,6 +991,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou other_charges = self.get_other_charges() end product = self.get_product_sale() + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) if shift.present? query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift.to_a) @@ -1022,7 +1001,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount) change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed) - sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") @@ -1045,7 +1024,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount) change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed) - sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") @@ -1069,7 +1048,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount) change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed) - sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") @@ -1100,6 +1079,8 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account customer_id = customer_id.to_s customer_id[0] = "" customer_id = customer_id.chomp("]") + else + customer_id = "''" end query = self.get_staff_meal_query() @@ -1116,16 +1097,17 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account # other_charges = self.get_other_charges() # end product = self.get_product_sale() + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) if shift.present? - query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",shift.to_a) + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN (#{customer_id})",shift.to_a) # if type.nil? || type == 'all' || type == "other" # other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) # end product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount) change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed) - sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") @@ -1141,14 +1123,14 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account ### => get all sales range in shift_sales elsif shift_sale_range.present? - query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",shift_sale_range.to_a) + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN (#{customer_id})",shift_sale_range.to_a) # if type.nil? || type == 'all' || type == "other" # other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) # end product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount) change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed) - sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") @@ -1164,7 +1146,7 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f else - query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",from,to) + query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed' and sales.customer_id IN (#{customer_id})",from,to) # if type.nil? || type == 'all' || type == "other" # other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) # end @@ -1172,7 +1154,7 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount) change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed) - sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") @@ -1383,20 +1365,12 @@ def self.get_separate_tax(shift_sale_range=nil,shift,from,to,payment_type) end end -def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type) +def self.get_payment_method_by_shift(shift,from,to,payment_type) + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) + payments_total = SalePayment.select(" sales.receipt_date as sale_date, - SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount, - SUM(case when (sale_payments.payment_method='master') then sale_payments.payment_amount else 0 end) as master_amount, - SUM(case when (sale_payments.payment_method='visa') then sale_payments.payment_amount else 0 end) as visa_amount, - SUM(case when (sale_payments.payment_method='jcb') then sale_payments.payment_amount else 0 end) as jcb_amount, - SUM(case when (sale_payments.payment_method='paypar') then sale_payments.payment_amount else 0 end) as paypar_amount, - SUM(case when (sale_payments.payment_method='unionpay') then sale_payments.payment_amount else 0 end) as unionpay_amount, - SUM(case when (sale_payments.payment_method='alipay') then sale_payments.payment_amount else 0 end) as alipay_amount, - SUM(case when (sale_payments.payment_method='KBZPay') then sale_payments.payment_amount else 0 end) as kbzpay_amount, - SUM(case when (sale_payments.payment_method='paymal') then sale_payments.payment_amount else 0 end) as paymal_amount, - SUM(case when (sale_payments.payment_method='dinga') then sale_payments.payment_amount else 0 end) as dinga_amount, - SUM(case when (sale_payments.payment_method='JunctionPay') then sale_payments.payment_amount else 0 end) as junctionpay_amount, + #{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method == 'paypar' ? 'redeem' : method}"}.join(', ')}, SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='cash') then sales.amount_changed else 0 end) as total_change_amount, @@ -1424,13 +1398,14 @@ def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type if shift.present? payments_total = payments_total.where(sales: {shift_sale_id: shift.to_a}) sale_payment = sale_payment.merge(Sale.where(sales: {shift_sale_id: shift.to_a})) - elsif shift_sale_range.present? - payments_total = payments_total.where(sales: {shift_sale_id: shift_sale_range.to_a}) - sale_payment = sale_payment.merge(Sale.where(sales: {shift_sale_id: shift_sale_range.to_a})) end if payment_type.present? - sale_payment = sale_payment.where(payment_method: payment_type) + if payment_type == 'card' + sale_payment = sale_payment.where(sanitize_sql_array(["payment_method IN (?)", SalePayment::CARD])) + else + sale_payment = sale_payment.where("payment_method = (?)", payment_type) + end end return payments_total, sale_payment @@ -1502,7 +1477,7 @@ end end - def self.top_bottom_products(current_user,from,to,type,current_shop) + def self.top_bottom_products(current_user,from,to,type) query = Sale.joins("JOIN sale_items ON sale_items.sale_id = sales.sale_id") .completed .where("qty > 0 AND price > 0") @@ -1531,7 +1506,7 @@ end end - def self.hourly_sales(current_user,from,to, current_shop) + def self.hourly_sales(current_user,from,to) query = Sale.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '#{Time.zone.formatted_offset}'), '%I %p')") .order('receipt_date').completed @@ -1551,19 +1526,18 @@ end end - def self.employee_sales(current_user,from,to, current_shop) - + def self.employee_sales(current_user,from,to) shift = if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') - ShiftSale.current_open_shift(current_user) + ShiftSale.current_open_shift(current_user.id) end payments_for_credits = SalePayment.joins(:sale_audit).to_sql + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) - - query = employee_sale(shift, from, to, current_shop) + query = employee_sale(shift, from, to) .joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id") .select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount, - CASE WHEN sale_payments.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' + CASE WHEN sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') }) THEN 'card' ELSE sale_payments.payment_method END AS payment_method, employees.name AS e_name") end @@ -1590,18 +1564,18 @@ end def self.total_card_sale(current_user=nil,from=nil,to=nil) + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) query = Sale.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") - .where('sales.sale_status = "completed" and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")') + .where("sales.sale_status = 'completed' and (sp.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') }))") if (!from.nil? && !to.nil?) query = query.receipt_date_between(from, to) - else query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day) end if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') - if shift = ShiftSale.current_open_shift(current_user) + if shift = ShiftSale.current_open_shift(current_user.id) query = query.where("sales.shift_sale_id = ?", shift.id) end end @@ -1610,7 +1584,7 @@ end end - def self.credit_payment(current_user=nil,from=nil,to=nil, current_shop) + def self.credit_payment(current_user=nil,from=nil,to=nil) payments_for_credits = SalePayment.joins(:sale_audit).to_sql @@ -1831,7 +1805,7 @@ end # end - def self.total_order(current_user=nil,from=nil,to=nil, current_shop) + def self.total_order(current_user=nil,from=nil,to=nil) query = Sale.select("count(distinct sale_orders.order_id) as total_order") .joins(:sale_orders) @@ -2054,7 +2028,7 @@ def unique_tax_profiles(order_source, customer_id) end -def self.employee_sale(shift=nil,from=nil,to=nil,from_time=nil,to_time=nil, current_shop) +def self.employee_sale(shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.joins(:cashier) .joins(:sale_payments) @@ -2114,6 +2088,7 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco other_charges = self.get_other_charges() end product = self.get_product_sale() + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) if shift.present? query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift.to_a) @@ -2123,7 +2098,7 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount) change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed) - sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") @@ -2146,7 +2121,7 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount) change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed) - sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") @@ -2170,7 +2145,7 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount) change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed) - sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") @@ -2329,49 +2304,50 @@ def self.get_daily_sale_data(transaction_date) GROUP BY DATE(s.receipt_date)").to_hash end -def self.get_check_sale_data(transaction_date) - sale_receivables_subquery = "SELECT sale_payments.sale_id, - CASE WHEN sale_payments.payment_method = 'mpu' OR sale_payments.payment_method = 'visa' OR sale_payments.payment_method = 'master' OR sale_payments.payment_method = 'jcb' OR sale_payments.payment_method = 'paypar' OR sale_payments.payment_method = 'unionpay' OR sale_payments.payment_method = 'alipay' OR sale_payments.payment_method = 'paymal' OR sale_payments.payment_method = 'dinga' OR sale_payments.payment_method = 'JunctionPay' THEN SUM(sale_payments.payment_amount) ELSE SUM(0) END as credit_card_sales, - CASE WHEN sale_payments.payment_method = 'giftvoucher' THEN SUM(sale_payments.payment_amount) ELSE SUM(0) END as voucher_sales - FROM sale_payments - GROUP BY sale_payments.sale_id, sale_payments.payment_method" - - query = Sale.select(" - sales.receipt_no as check_num, - sales.receipt_date as business_date, - sales.requested_at as check_open_time, - sales.updated_at as check_close_time, - (sales.grand_total + sales.total_discount) as gross_sales, - sales.total_discount as discount_amt, - sales.grand_total as sales, - (sales.grand_total/21) as tax_amt, - 0 as service_charges, - (sales.grand_total - (sales.grand_total/21)) as net_sales, - receivables.credit_card_sales as credit_card_sales, - receivables.voucher_sales as voucher_sales, - 0 as staff_meal_amt, - sales.rounding_adjustment as rounding_amt, - CASE WHEN sales.sale_status='waste' THEN sales.total_amount ELSE 0 END as wastage_amt, - CASE WHEN sales.sale_status='spoile' THEN sales.total_amount ELSE 0 END as spoilage_amt, - 0 as sampling_amt, - SUM(i.qty) as qty, - 0 as no_of_pax, - 0 as no_of_adult, - 0 as no_of_child, - shift_sales.cashier_terminal_id as pos_id, - sales.cashier_id as employee_code, - employees.name as employee_name, - CASE WHEN sales.sale_status='completed' THEN 1 ELSE 0 END is_valid, - 0 as overing, - 0 as cancle, - CONCAT( employees.name, ' Cash&Go receipt generated and completed.') as remarks") - .joins("LEFT JOIN shift_sales ON shift_sales.id = sales.shift_sale_id") - .joins("LEFT JOIN sale_items i ON i.sale_id = sales.sale_id") - .joins("LEFT JOIN (" + sale_receivables_subquery + ") as receivables ON receivables.sale_id = sales.sale_id") - .joins("LEFT JOIN employees ON employees.id = sales.cashier_id") - .where("DATE(sales.receipt_date) = ? AND sales.sale_status != ?", transaction_date, :void) - .group("sales.receipt_no,sales.sale_status") -end + def self.get_check_sale_data(transaction_date) + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) + sale_receivables_subquery = "SELECT sale_payments.sale_id, + SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as credit_card_sales, + CASE WHEN sale_payments.payment_method = 'giftvoucher' THEN SUM(sale_payments.payment_amount) ELSE SUM(0) END as voucher_sales + FROM sale_payments + GROUP BY sale_payments.sale_id, sale_payments.payment_method" + + query = Sale.select(" + sales.receipt_no as check_num, + sales.receipt_date as business_date, + sales.requested_at as check_open_time, + sales.updated_at as check_close_time, + (sales.grand_total + sales.total_discount) as gross_sales, + sales.total_discount as discount_amt, + sales.grand_total as sales, + (sales.grand_total/21) as tax_amt, + 0 as service_charges, + (sales.grand_total - (sales.grand_total/21)) as net_sales, + receivables.credit_card_sales as credit_card_sales, + receivables.voucher_sales as voucher_sales, + 0 as staff_meal_amt, + sales.rounding_adjustment as rounding_amt, + CASE WHEN sales.sale_status='waste' THEN sales.total_amount ELSE 0 END as wastage_amt, + CASE WHEN sales.sale_status='spoile' THEN sales.total_amount ELSE 0 END as spoilage_amt, + 0 as sampling_amt, + SUM(i.qty) as qty, + 0 as no_of_pax, + 0 as no_of_adult, + 0 as no_of_child, + shift_sales.cashier_terminal_id as pos_id, + sales.cashier_id as employee_code, + employees.name as employee_name, + CASE WHEN sales.sale_status='completed' THEN 1 ELSE 0 END is_valid, + 0 as overing, + 0 as cancle, + CONCAT( employees.name, ' Cash&Go receipt generated and completed.') as remarks") + .joins("LEFT JOIN shift_sales ON shift_sales.id = sales.shift_sale_id") + .joins("LEFT JOIN sale_items i ON i.sale_id = sales.sale_id") + .joins("LEFT JOIN (" + sale_receivables_subquery + ") as receivables ON receivables.sale_id = sales.sale_id") + .joins("LEFT JOIN employees ON employees.id = sales.cashier_id") + .where("DATE(sales.receipt_date) = ? AND sales.sale_status != ?", transaction_date, :void) + .group("sales.receipt_no,sales.sale_status") + end def paymal_payment_void membership_setting = MembershipSetting.find_by_membership_type("paypar_url") membership_actions_data = MembershipAction.find_by_membership_type("void") diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 59432f0b..6214005a 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -132,13 +132,13 @@ class ShiftSale < ApplicationRecord self.commercial_taxes = self.commercial_taxes.to_f - tax.to_f self.total_rounding = self.total_rounding - saleobj.rounding_adjustment self.total_void = self.total_void + saleobj.grand_total + if saleobj.customer.customer_type == "Dinein" self.dining_count = self.dining_count - 1 else self.takeaway_count = self.takeaway_count - 1 end - self.save end end diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 349296c3..ea8d1723 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -82,7 +82,7 @@ class ReceiptBillPdf < Prawn::Document end #end card sale trans data #start card blanace amount - if !card_balance_amount.nil? && card_balance_amount >0 + if !card_balance_amount.nil? card_balance_data(card_balance_amount) card_transaction_ref(transaction_ref) end diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index 4cb3bde2..46e5f81e 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -189,9 +189,8 @@ <%= @summ_sale.total_receipt %> - <% revenue = @summ_sale.total_amount - @summ_sale.total_discount%> + <% revenue = @summ_sale.grand_total - @summ_sale.total_discount - @summ_sale.total_tax %> <%= t("views.right_panel.detail.sale") %> <%= t :revenue %> : - <%= number_format( revenue, precision: precision.to_i ,delimiter: delimiter) %> @@ -210,33 +209,36 @@ <% if !(@total_payment_methods.nil?) %> <% @total_payment_methods.each do |payment| %> - - <% if payment.payment_method != 'card' %> - + <% if !@sale_data[0].empty? %> + <% if payment.payment_method != 'mpu' && payment.payment_method != 'visa' && payment.payment_method != 'master' && payment.payment_method != 'jcb' %> + <% if payment.payment_method == 'paypar' %> <% else %> <% end %> - - + + + <% end %> <% end %> <% end %> - <% total_card = @sale_data.find {|x| x.key?("card") } %> - <% if !total_card.nil? %> - - - - + <% total_card = @sale_data.select { |hash| hash["card"]!=nil } %> + <% if !total_card.nil? %> + + + + <% end %> - <% end %>
Redeem Sale : <%= payment.payment_method.to_s.capitalize %> Sale : - <%= number_format(@sale_data.find {|x| x.key?(payment.payment_method) }[payment.payment_method], precision: precision.to_i ,delimiter: delimiter) rescue number_format(0, precision: precision.to_i ,delimiter: delimiter) %> -
+ <% @sale_data.each do |data| %> + <% pay_mth = payment.payment_method %> + <%= data[""+pay_mth+""] %> + <% end %> +
<%= t("views.right_panel.detail.other_payment") %> : - - <%= number_format(total_card["card"], precision: precision.to_i ,delimiter: delimiter) rescue number_format(0, precision: precision.to_i ,delimiter: delimiter) %> - -
<%= t("views.right_panel.detail.other_payment") %> : + <% total_other_amt = 0 %> + <% @sale_data.map { |k,v| k.map{|meth,amt| meth != 'cash' && meth != 'foc' && meth != 'creditnote' ? total_other_amt += amt : meth }} %> + <%= total_other_amt %> +
@@ -347,7 +349,8 @@ <% end %> <% end %> - <% if isMobile.to_s.include? "Mobile" %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' %> + <% if isMobile.include? "Mobile" %>
@@ -369,6 +372,7 @@
<% end %> + <% end %>
diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index f0c63ef6..2ead90c7 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -1,32 +1,32 @@ -
+
-
+
-
Receipt No : <%=@sale_data.receipt_no rescue ' '%>
-
Receipt Date : <%=@sale_data.receipt_date.utc.getlocal.strftime("%d/%m/%Y-%I:%M %p") rescue '-' %>
+
Receipt No : <%=@sale.receipt_no rescue ' '%>
+
Receipt Date : <%=@sale.receipt_date.utc.getlocal.strftime("%d/%m/%Y-%I:%M %p") rescue '-' %>
Table No : <%=@table_no%>
-
Sale ID : <% if @sale_data %><%=@sale_data.sale_id %><% end %>
+
Sale ID : <% if @sale %><%=@sale.sale_id %><% end %>
Customer : <% if @cashier_type == 'quick_service' || @cashier_type == 'food_court' %> - + <% else %> - <%= @sale_data.customer.name%> + <%= @sale.customer.name%> <% end %> - +
Checkin Time : <%if !@checkin_time.nil?%><%= @checkin_time.utc.getlocal.strftime("%I:%M %p") %> <%end%>
@@ -49,7 +49,7 @@
-
+
@@ -57,7 +57,7 @@ <% sub_total = 0 count = 0 %> - <% @sale_data.sale_items.each do |sale_item| + <% @sale.sale_items.each do |sale_item| count += 1 %> @@ -77,17 +77,17 @@
- + - <%if @sale_data.discount_type == 'member_discount'%> + <%if @sale.discount_type == 'member_discount'%> <%else%> <%end%> - + - + - + - + <%if @balance > 0%> @@ -153,25 +153,17 @@
-
+
-
Amount Due <% if !@sale_payment.nil? %>( Credit )<% end %>
+
Amount Due <% if !@sale_payment %>( Credit )<% end %>
- <% if @sale_payment.nil? %> - <%= number_format(@sale_data.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %> - <% else %> - <%= number_format(@sale_payment[0].payment_amount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i)%> - <% end %> + <%= number_format(@amount_due, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i)%>
@@ -183,7 +175,7 @@ <%= number_format(@cash, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% if @sale_payment.nil? && @cashier_type != "food_court" %> + <% if @sale_payment && @cashier_type != "food_court" %>
Credit
<%= number_format(@credit, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
@@ -191,155 +183,25 @@ <% else %> <% end %> - <% if @kbz_pay_amount > 0.0 %> -
-
Other Payments (KBZ Pay)
-
- <%= number_format(@kbz_pay_amount, precision: precision.to_i) rescue number_format(0, precision: precision.to_i) %> +
+
Other Payments
+
+ <%= number_format(@other_payment, precision: precision.to_i) rescue number_format(0, precision: precision.to_i) %>
- <% elsif @other == 0.0 && @ppamount == 0.0 && @visacount == 0.0 && @jcbcount == 0.0 && @mastercount == 0.0 && @unionpaycount == 0.0 && @alipaycount == 0.0 && @paymalcount == 0.0 && @junctionpaycount == 0.0 && @dingacount == 0.0 && @giftvouchercount == 0.0 %> -
-
Other Payments
-
- <%= number_format(@other, precision: precision.to_i) rescue number_format(0, precision: precision.to_i) %> -
-
- <% else %> -
-
Other Payments
-
- <%= number_format(@other_payment, precision: precision.to_i) rescue number_format(0, precision: precision.to_i) %> -
-
- <% end %>
-
- -
-
-
MPU
- <% if @other != 0.0 %> -
<%= number_format(@other, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - -
-
-
Redeem
- <% if @ppamount != 0.0 %> -
<%= number_format(@ppamount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - -
-
-
VISA
- <% if @visacount != 0.0 %> -
<%= number_format(@visacount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - -
-
-
JCB
- <% if @jcbcount != 0.0 %> -
<%= number_format(@jcbcount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - -
-
-
MASTER
- <% if @mastercount != 0.0 %> -
<%= number_format(@mastercount, precision: precision.to_i) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - - -
-
-
UNIONPAY
- <% if @unionpaycount != 0.0 %> -
<%= number_format(@unionpaycount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - -
-
-
Alipay
- <% if @alipaycount != 0.0 %> -
<%= number_format(@alipaycount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - -
-
-
PAYMAL
- <% if @paymalcount != 0.0 %> -
<%= number_format(@paymalcount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- -
-
-
DINGA
- <% if @dingacount != 0.0 %> -
<%= number_format(@dingacount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - -
-
-
JUNCTION PAY
- <% if @junctionpaycount != 0.0 %> -
<%= number_format(@junctionpaycount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - -
-
-
GIFT VOUCHER
- <% if @giftvouchercount != 0.0 %> -
<%= number_format(@giftvouchercount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> +
+ <% @other_payments.each do |payment| %> +
+
<%= payment[0] %>
+
<%= number_format(payment[1], precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
+ <% end %>
Balance
-
<%= number_format(@sale_data.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
+
<%= number_format(@sale.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
@@ -404,30 +266,30 @@ <% if current_login_employee.role == "cashier" %> - <% if @other_payment <= 0 && @sale_payment.nil? %> - <%if @sale_data.total_discount == 0 %> + <% if @other_payment <= 0 && @sale_payment %> + <%if @sale.total_discount == 0 %> FOC <% end %> <%end %> - <% if @sale_payment.nil? %> + <% if @sale_payment %> Void <% if @other_payment <= 0 %> - <%if @sale_data.total_discount == 0 %> + <%if @sale.total_discount == 0 %> Waste Spoile <% end %> <% end %> <% end %> <% else %> - <% if @other_payment <= 0 && @sale_payment.nil?%> - <%if @sale_data.total_discount == 0 %> + <% if @other_payment <= 0 && @sale_payment%> + <%if @sale.total_discount == 0 %> <% end %> @@ -435,7 +297,7 @@ <% end %> <% end %> -<% if (@cashier_type=="quick_service" || @cashier_type=="food_court") && @sale_payment.nil? %> +<% if (@cashier_type=="quick_service" || @cashier_type=="food_court") && @sale_payment %>
@@ -709,10 +571,14 @@ var customer_id = "<%= @customer.id %>"; var customer_name = "<%= @customer.name %>"; var pdf_view = '<%=@pdf_view%>'; var trans_flag = <%= @trans_flag %>; -var paymalcount = <%= @paymalcount %>; +var other_payments = <%= raw @other_payments %>; +var payment_methods = <%= raw @payment_methods %>; + // console.log(pdf_view) $(document).ready(function(){ $("#sxModal").hide(); + + var paymalcount = other_payments.some(x => x[0] == 'paymal') ? other_payments.find(x => x[0] == 'paymal')[1] : 0.0; if(cashier_type == "food_court" && paymalcount == 0.0){ $("#is_paymemberModal").modal({show : true, backdrop : false, keyboard : false}); } @@ -726,45 +592,35 @@ $(document).ready(function(){ } /* replace url type*/ /* start check first bill or not*/ - var member_id = $('#membership_id').text(); - var member_discount = $('#member_discount').text(); - var receipt_no = ""; - if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){ - receipt_no = ($("#receipt_no").html()).trim(); - } + var member_id = $('#membership_id').text(); + var member_discount = $('#member_discount').text(); + var receipt_no = ""; + if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){ + receipt_no = ($("#receipt_no").html()).trim(); + } - payment_type = ''; + // if ($("#server_mode").val() != "cloud") { // first bill not used in cloud + payment_type = checkReceiptNoInFirstBillData(receipt_no,"payment") - // if ($("#server_mode").val() != "cloud") { // first bill not used in cloud - payment_type = checkReceiptNoInFirstBillData(receipt_no,"payment"); - // console.log(payment_type) - // console.log(parseInt(jQuery.inArray("MPU", payment_type))) - if (member_id && member_discount) { - if(parseInt(jQuery.inArray("Credit", payment_type)) == -1){ - $("#credit_payment").hide(); - } else{ - $("#credit_payment").show(); - } - if(parseInt(jQuery.inArray("MPU", payment_type)) != -1 || - parseInt(jQuery.inArray("VISA", payment_type)) != -1 || - parseInt(jQuery.inArray("JCB", payment_type)) != -1 || - parseInt(jQuery.inArray("Master", payment_type)) != -1 || - parseInt(jQuery.inArray("UNIONPAY", payment_type)) != -1 || - parseInt(jQuery.inArray("Redeem", payment_type)) != -1 || - parseInt(jQuery.inArray("PAYMAL", payment_type)) != -1 || - parseInt(jQuery.inArray("JUNCTIONPAY", payment_type)) != -1 || - parseInt(jQuery.inArray("Alipay", payment_type)) != -1 || - parseInt(jQuery.inArray("DINGA", payment_type)) != -1 || - parseInt(jQuery.inArray("GiftVoucher", payment_type)) != -1){ - $("#card_payment").show(); - } else{ - $("#card_payment").hide(); - } - } - // } - /* end check first bill or not*/ + console.log(payment_type) + // console.log(parseInt(jQuery.inArray("MPU", payment_type))) + if (member_id && member_discount) { + if(parseInt(jQuery.inArray("Credit", payment_type)) == -1){ + $("#credit_payment").hide(); + } else{ + $("#credit_payment").show(); + } - var dining_id = "<%= @sale_data.bookings[0].dining_facility_id %>"; + if(payment_type && payment_methods.some(x => payment_type.indexOf(x) >= 0)){ + $("#card_payment").show(); + } else{ + $("#card_payment").hide(); + } + } + // } + /* end check first bill or not*/ + + var dining_id = "<%= @sale.bookings[0].dining_facility_id %>"; $("#back").on('click', function() { localStorage.removeItem('cash'); @@ -787,12 +643,10 @@ $(document).ready(function(){ window.location.reload(); }) - if(localStorage.getItem("cash") == null || localStorage.getItem("cash") == 'null'){ - - } - else { + if (localStorage.getItem("cash") && localStorage.getItem("cash") != 'null') { $('#cash').text(localStorage.getItem("cash")); } + update_balance(); //checkChangableTax checkChangableTax(); @@ -826,126 +680,96 @@ $(document).ready(function(){ $('#pay').click(function() { sub_total = $('#sub-total').text(); member = $('#membership_id').text(); - // console.log(member) - if (parseInt(jQuery.inArray("MPU", payment_type)) != -1 && $('.mpu').text() == 0 && sub_total != 0.0 && member) { - swal("Oops","Please Pay with MPU Payment","warning"); - }else if(parseInt(jQuery.inArray("Redeem", payment_type)) != -1 && $('#ppamount').text()==0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with Redeem Payment","warning"); - }else if(parseInt(jQuery.inArray("VISA", payment_type)) != -1 && $('#visacount').text()== 0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with Visa Payment","warning"); - - }else if(parseInt(jQuery.inArray("JCB", payment_type)) != -1 && $('#jcbcount').text()== 0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with jcb Payment","warning"); - } - else if(parseInt(jQuery.inArray("Master", payment_type)) != -1 && $('#mastercount').text()== 0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with Master Payment","warning"); - } - else if(payment_type == "UNIONPAY" && $('#unionpaycount').text()== 0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with UNIONPAY Payment","warning"); - } - else if(parseInt(jQuery.inArray("Alipay", payment_type)) != -1 && $('#alipaycount').text()== 0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with Alipay Payment","warning"); - } - else if(parseInt(jQuery.inArray("JUNCTIONPAY", payment_type)) != -1 && $('#junctionpaycount').text()==0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with JUNCTIONPAY Payment","warning"); - } - else if(payment_type == "Credit" && $('#credit').text()==0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with Credit Payment","warning"); - }else if(parseInt(jQuery.inArray("PAYMAL", payment_type)) != -1 && $('#paymalcount').text()== 0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with Paymal Payment","warning"); - }else if(parseInt(jQuery.inArray("DINGA", payment_type)) != -1 && $('#dingacount').text()== 0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with Dinga Payment","warning"); - }else if(parseInt(jQuery.inArray("GiftVoucher", payment_type)) != -1 && $('#giftvouchercount').text()== 0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with Gift Voucher","warning"); + if (payment_type && payment_type.length > 0 && !other_payments.some(x => payment_type.indexOf(x[0]) >= 0 && x[1] > 0) && sub_total != 0.0 && member) { + swal("Oops","Please Pay with " + payment_methods.find(x => payment_type.indexOf(x) >= 0) + " Payment","warning"); + } else { + $( "#loading_wrapper").show(); + if($('#balance').text() > 0){ + swal ( "Oops", "Insufficient Amount!" , "error" ); + $("#loading_wrapper").hide(); }else{ + $(this).off("click"); + var sale_id = $('#sale_id').text(); + // var item_row = $('.is_card'); - $( "#loading_wrapper").show(); - if($('#balance').text() > 0){ - swal ( "Oops", "Insufficient Amount!" , "error" ); - $("#loading_wrapper").hide(); - }else{ - $(this).off("click"); - var sale_id = $('#sale_id').text(); - // var item_row = $('.is_card'); + // payment + var cash = $('#cash').text(); + var credit = $('#credit').text(); + var card = $('#card').text(); + var kbz_amt = "<%= @kbz_pay_amount %>"; + var is_kbz = false; + if (kbz_amt > 0) { + is_kbz = true + } - // payment - var cash = $('#cash').text(); - var credit = $('#credit').text(); - var card = $('#card').text(); - var kbz_amt = "<%= @kbz_pay_amount %>"; - var is_kbz = false; - if (kbz_amt > 0) { - is_kbz = true - } + var tax_type = localStorage.getItem("tax_type") ? localStorage.getItem("tax_type") : 'all'; + if (credit <= 0 && (!location.pathname.includes("credit_payment"))) { + calculate_member_discount(sale_id,tax_type); + } - var tax_type = localStorage.getItem("tax_type") ? localStorage.getItem("tax_type") : 'all'; - if (credit <= 0 && (!location.pathname.includes("credit_payment"))) { - calculate_member_discount(sale_id,tax_type); - } + // $("#pdfModal").on('shown.bs.modal', function () { + // $('#pdfModal').focus() }).modal({show : true, backdrop : false, keyboard : false}); + /* check credit payment or not*/ + if(location.pathname.includes("credit_payment")){ + var url = "<%= origami_credit_payment_cash_path %>"; + }else{ + var url = "<%= origami_payment_cash_path %>"; + } - // $("#pdfModal").on('shown.bs.modal', function () { - // $('#pdfModal').focus() }).modal({show : true, backdrop : false, keyboard : false}); - /* check credit payment or not*/ - if(location.pathname.includes("credit_payment")){ - var url = "<%= origami_credit_payment_cash_path %>"; - }else{ - var url = "<%= origami_payment_cash_path %>"; - } + $.ajax({type: "POST", + url: url, + data: "cash="+ cash + "&sale_id=" + sale_id + "&type=" + cashier_type + "&tax_type=" + tax_type + "&is_kbz=" + is_kbz, + success:function(result){ + /* start delete receipt no in first bill*/ + if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){ + var receipt_no = ($("#receipt_no").html()).trim(); + deleteReceiptNoInFirstBillData(receipt_no); + } + /* end delete receipt no in first bill*/ - $.ajax({type: "POST", - url: url, - data: "cash="+ cash + "&sale_id=" + sale_id + "&type=" + cashier_type + "&tax_type=" + tax_type + "&is_kbz=" + is_kbz, - success:function(result){ - /* start delete receipt no in first bill*/ - if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){ - var receipt_no = ($("#receipt_no").html()).trim(); - deleteReceiptNoInFirstBillData(receipt_no); - } - /* end delete receipt no in first bill*/ + localStorage.removeItem("cash"); + if (result.status) { + var msg = result.message; + } + else{ + var msg = ''; + } - localStorage.removeItem("cash"); - if (result.status) { - var msg = result.message; - } - else{ - var msg = ''; + $("#loading_wrapper" ).hide(); + if(location.pathname.includes("credit_payment")){ + payment_success_alert(); + }else{ + //PDF lightbox data + var pdfPath = "/en/pdfjs/minimal?file=" + result.filename.substring(6); + $("#sale_receipt_no").val(result.receipt_no); + $("#filename").val(result.filename); + $("#printer_name").val(result.printer_name); + $("#receipt_pdf").attr("src", pdfPath); + $("#changed_amount").text(""); + if($('#balance').text() < 0){ + <% if precision.to_i > 0 %> + $("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1)).toFixed(<%= precision %>)); + <% else %> + $("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1))); + <% end %> } - $("#loading_wrapper" ).hide(); - if(location.pathname.includes("credit_payment")){ - payment_success_alert(); + if (pdf_view == 1) { + $("#pdfModal").modal({show : true, backdrop : false, keyboard : false}); + $("#pdfModalLabel").text("Sale Completed"); }else{ //PDF lightbox data - var pdfPath = "/en/pdfjs/minimal?file=" + result.filename.substring(6); - $("#sale_receipt_no").val(result.receipt_no); - $("#filename").val(result.filename); - $("#printer_name").val(result.printer_name); - $("#receipt_pdf").attr("src", pdfPath); - $("#changed_amount").text(""); - if($('#balance').text() < 0){ - <% if precision.to_i > 0 %> - $("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1)).toFixed(<%= precision %>)); - <% else %> - $("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1))); - <% end %> - } - - if (pdf_view == 1) { - $("#pdfModal").modal({show : true, backdrop : false, keyboard : false}); - $("#pdfModalLabel").text("Sale Completed"); - }else{ - //PDF lightbox data - print_receipt(); - } + print_receipt(); } } - }); - } - } - var second_display_lookup = $("#display_type").val(); - if ($('#server_mode').val() != "cloud" && second_display_lookup == 2){ - customer_display_view(null,"reload"); + } + }); } + } + var second_display_lookup = $("#display_type").val(); + if ($('#server_mode').val() != "cloud" && second_display_lookup == 2){ + customer_display_view(null,"reload"); + } }); function customer_display_view(data,status) { @@ -1098,18 +922,8 @@ $(document).ready(function(){ break; case 'nett': var credit1 = $('#credit').text(); - var card1 = $('#others').text(); - var paypar1 = $('#ppamount').text(); - var visa1 = $('#visacount').text(); - var jcb1 = $('#jcbcount').text(); - var master1 = $('#mastercount').text(); - var unionpay1 = $('#unionpaycount').text(); - var paymal1 = $('#paymalcount').text(); - var alipay1 = $('#alipaycount').text(); - var junctionpay1 = $('#junctionpaycount').text(); - var dingapay1 = $('#dingacount').text(); - var giftvoucherpay1 = $('#giftvouchercount').text(); - var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1) + parseFloat(unionpay1) + parseFloat(alipay1) + parseFloat(junctionpay1) + parseFloat(paymal1) + parseFloat(dingapay1) + parseFloat(giftvoucherpay1); + var others = other_payments.map(x => x[1]).reduce((acc, v) => acc + v, 0); + var othertotal = parseFloat(credit1) + parseFloat(others); var total = $('#amount_due').text(); var amt = 0; <% if precision.to_i > 0 %>; @@ -1131,19 +945,10 @@ $(document).ready(function(){ function update_balance(){ var cash = $('#cash').text(); var credit = $('#credit').text(); - var card = $('#others').text(); - var paypar = $('#ppamount').text(); - var visa = $('#visacount').text(); - var jcb = $('#jcbcount').text(); - var master = $('#mastercount').text(); - var unionpay = $('#unionpaycount').text(); - var paymal = $('#paymalcount').text(); - var alipay = $('#alipaycount').text(); - var junctionpay = $('#junctionpaycount').text(); - var dinga = $('#dingacount').text(); - var giftvoucher = $('#giftvouchercount').text(); + var others = other_payments.map(x => x[1]).reduce((acc, v) => acc + v, 0); + var amount_due = $('#amount_due').text(); - var total = parseFloat(cash) + parseFloat(credit) + parseFloat(card) + parseFloat(paypar) + parseFloat(visa) + parseFloat(jcb) + parseFloat(master) + parseFloat(unionpay) + parseFloat(alipay) + parseFloat(junctionpay) + parseFloat(paymal) + parseFloat(dinga) + parseFloat(giftvoucher); + var total = parseFloat(cash) + parseFloat(credit) + parseFloat(others); var result = parseFloat(amount_due) - parseFloat(total); @@ -1253,7 +1058,6 @@ $(document).ready(function(){ title: "Payment Successful!", text: text, html: true, - type: 'success', closeOnConfirm: false, closeOnCancel: false, allowOutsideClick: false @@ -1310,6 +1114,7 @@ $(document).ready(function(){ $("#sxModal").show(); setTimeout(function(){ getCardNo(); + $("#sxModal").hide(); customer_mamber_card_no = $("#paypar_account_no").val(); if(sale_id != 0 && customer_mamber_card_no != 0){ @@ -1346,7 +1151,6 @@ $(document).ready(function(){ function setCardNo(cardNo){ if(cardNo.length == 16){ $("#paypar_account_no").val(cardNo); - $("#sxModal").hide(); } } @@ -1477,7 +1281,7 @@ $(document).ready(function(){ $('#AccessCodeModal').modal('hide'); $('#focModal').modal('show'); // overall_foc(); - }else if(type == "change_tax"){ + }else if(type == 'change_tax'){ $('#AccessCodeModal').modal('hide'); $('#change_taxModal').modal('show'); } @@ -1715,6 +1519,7 @@ $(document).ready(function(){ $("#sxModal").show(); setTimeout(function(){ getCardNo(); + $("#sxModal").hide(); customer_mamber_card_no = $("#paypar_account_no").val(); if (customer_mamber_card_no == 0) { customer_mamber_card_no = $("#membership_id").text() || 0; diff --git a/app/views/reports/dailysale/index.html.erb b/app/views/reports/dailysale/index.html.erb index 72f5c9c5..38e815cb 100755 --- a/app/views/reports/dailysale/index.html.erb +++ b/app/views/reports/dailysale/index.html.erb @@ -1,5 +1,13 @@ -<% breadcrumb_add t("views.right_panel.detail.daily_sale_report"), "", dashboard_path %> +
<%= render :partial=>'shift_sale_report_filter', @@ -19,99 +27,25 @@
<% @count = 1 %> - <% @payment_methods.each_slice(10) do |slice| %> - - - - <% end %> - - + + <% if @tax.blank? %> - - + + <% end %> - + + <% @payment_methods.each do |method| %> + + <% end %> - <% if @payment_methods.include? ("MPU") %> - - <% end %> - <% if @payment_methods.include? ("Master") %> - - <% end %> - <% if @payment_methods.include? ("VISA") %> - - <% end %> - <% if @payment_methods.include? ("JCB") %> - - <% end %> - <% if @payment_methods.include? ("UNIONPAY") %> - - <% end %> - <% if @payment_methods.include? ("KBZPay") %> - - <% end %> - <% if @payment_methods.include? ("Alipay") %> - - <% end %> - <% if @payment_methods.include? ("PAYMAL") %> - - <% end %> - <% if @payment_methods.include? ("DINGA") %> - - <% end %> - <% if @payment_methods.include? ("JunctionPay") %> - - <% end %> - <% if @payment_methods.include? ("Redeem") %> - - <% end %> - <% if @payment_methods.include? ("GiftVoucher") %> - - <% end %> @@ -132,22 +66,10 @@ <% unless @sale_data.blank? %> <% void = 0 %> - <% mpu = 0 %> - <% master = 0 %> - <% visa = 0 %> - <% jcb = 0 %> - <% unionpay = 0 %> - <% alipay = 0 %> - <% paymal = 0 %> - <% dinga = 0 %> - <% junctionpay = 0 %> - <% giftvoucher = 0 %> - <% paypar = 0 %> <% cash = 0 %> <% credit = 0 %> <% foc = 0 %> <% discount = 0 %> - <% kbzpay = 0 %> <% total = 0 %> <% grand_total = 0 %> <% old_grand_total = 0 %> @@ -156,24 +78,13 @@ <% tax = 0 %> <% net_sale = 0 %> <% count = 1 %> <% rounding_adj = 0 %> + <% @sale_data.each do |sale| %> <% void += sale[:void_amount] %> - <% mpu += sale[:mpu_amount] %> - <% master += sale[:master_amount] %> - <% visa += sale[:visa_amount] %> - <% jcb += sale[:jcb_amount] %> - <% unionpay += sale[:unionpay_amount] %> - <% alipay += sale[:alipay_amount] %> - <% paymal += sale[:paymal_amount] %> - <% dinga += sale[:dinga_amount] %> - <% junctionpay += sale[:junctionpay_amount] %> - <% giftvoucher += sale[:giftvoucher_amount] %> - <% paypar += sale[:paypar_amount] %> <% cash += sale[:cash_amount]-sale[:total_change_amount] %> <% credit += sale[:credit_amount] %> <% foc += sale[:foc_amount] %> <% discount += sale[:total_discount] %> - <% kbzpay += sale[:kbzpay_amount] %> <% total += sale[:grand_total].to_f + sale[:rounding_adj].to_f %> <% grand_total += sale[:grand_total].to_f %> <% old_grand_total += sale[:old_grand_total].to_f %> @@ -185,41 +96,8 @@ - <% if @payment_methods.include? ("MPU") %> - - <% end %> - <% if @payment_methods.include? ("Master") %> - - <% end %> - <% if @payment_methods.include? ("VISA") %> - - <% end %> - <% if @payment_methods.include? ("JCB") %> - - <% end %> - <% if @payment_methods.include? ("UNIONPAY") %> - - <% end %> - <% if @payment_methods.include? ("Alipay") %> - - <% end %> - <% if @payment_methods.include? ("KBZPay") %> - - <% end %> - <% if @payment_methods.include? ("PAYMAL") %> - - <% end %> - <% if @payment_methods.include? ("DINGA") %> - - <% end %> - <% if @payment_methods.include? ("JunctionPay") %> - - <% end %> - <% if @payment_methods.include? ("Redeem") %> - - <% end %> - <% if @payment_methods.include? ("GiftVoucher") %> - + <% @payment_methods.each do |method| %> + <% end %> @@ -228,7 +106,7 @@ - + <% if @tax.blank? %> @@ -242,75 +120,9 @@ <% colspan = 7 %> - <% if @payment_methods.include? ("MPU") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end%> - <% if @payment_methods.include? ("Master") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end%> - <% if @payment_methods.include? ("VISA") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end%> - <% if @payment_methods.include? ("JCB") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end%> - <% if @payment_methods.include? ("UNIONPAY") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end %> - <% if @payment_methods.include? ("Alipay") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end %> - <% if @payment_methods.include? ("KBZPay") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end %> - <% if @payment_methods.include? ("PAYMAL") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end %> - <% if @payment_methods.include? ("DINGA") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end %> - <% if @payment_methods.include? ("JunctionPay") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end %> - <% if @payment_methods.include? ("Redeem") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end %> - <% if @payment_methods.include? ("GiftVoucher") %> - <% colspan += 1 %> - + <% @payment_methods.each do |method| %> + <% colspan += 1 %> + <% end %> diff --git a/app/views/reports/dailysale/index.xls.erb b/app/views/reports/dailysale/index.xls.erb index f3d0aa2b..cc0eced9 100755 --- a/app/views/reports/dailysale/index.xls.erb +++ b/app/views/reports/dailysale/index.xls.erb @@ -27,41 +27,8 @@ - <% if @payment_methods.include? ("MPU") %> - - <% end %> - <% if @payment_methods.include? ("Master") %> - - <% end %> - <% if @payment_methods.include? ("VISA") %> - - <% end %> - <% if @payment_methods.include? ("JCB") %> - - <% end %> - <% if @payment_methods.include? ("UNIONPAY") %> - - <% end %> - <% if @payment_methods.include? ("KBZPay") %> - - <% end %> - <% if @payment_methods.include? ("Alipay") %> - - <% end %> - <% if @payment_methods.include? ("PAYMAL") %> - - <% end %> - <% if @payment_methods.include? ("DINGA") %> - - <% end %> - <% if @payment_methods.include? ("JunctionPay") %> - - <% end %> - <% if @payment_methods.include? ("Redeem") %> - - <% end %> - <% if @payment_methods.include? ("GiftVoucher") %> - + <% @payment_methods.each do |method| %> + <% end %> @@ -108,22 +75,10 @@ <% count = 1 %> <% rounding_adj = 0 %> <% @sale_data.each do |sale| %> <% void += sale[:void_amount] %> - <% mpu += sale[:mpu_amount] %> - <% master += sale[:master_amount] %> - <% visa += sale[:visa_amount] %> - <% jcb += sale[:jcb_amount] %> - <% unionpay += sale[:unionpay_amount] %> - <% alipay += sale[:alipay_amount] %> - <% paymal += sale[:paymal_amount] %> - <% dinga += sale[:dinga_amount] %> - <% junctionpay += sale[:junctionpay_amount] %> - <% giftvoucher += sale[:giftvoucher_amount] %> - <% paypar += sale[:paypar_amount] %> <% cash += sale[:cash_amount]-sale[:total_change_amount] %> <% credit += sale[:credit_amount] %> <% foc += sale[:foc_amount] %> <% discount += sale[:total_discount] %> - <% kbzpay += sale[:kbzpay_amount] %> <% total += sale[:grand_total].to_f + sale[:rounding_adj].to_f %> <% grand_total += sale[:grand_total].to_f %> <% old_grand_total += sale[:old_grand_total].to_f %> @@ -135,41 +90,8 @@ - <% if @payment_methods.include? ("MPU") %> - - <% end %> - <% if @payment_methods.include? ("Master") %> - - <% end %> - <% if @payment_methods.include? ("VISA") %> - - <% end %> - <% if @payment_methods.include? ("JCB") %> - - <% end %> - <% if @payment_methods.include? ("UNIONPAY") %> - - <% end %> - <% if @payment_methods.include? ("Alipay") %> - - <% end %> - <% if @payment_methods.include? ("KBZPay") %> - - <% end %> - <% if @payment_methods.include? ("PAYMAL") %> - - <% end %> - <% if @payment_methods.include? ("DINGA") %> - - <% end %> - <% if @payment_methods.include? ("JunctionPay") %> - - <% end %> - <% if @payment_methods.include? ("Redeem") %> - - <% end %> - <% if @payment_methods.include? ("GiftVoucher") %> - + <% @payment_methods.each do |method| %> + <% end %> @@ -192,75 +114,9 @@ <% colspan = 7 %> - <% if @payment_methods.include? ("MPU") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end%> - <% if @payment_methods.include? ("Master") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end%> - <% if @payment_methods.include? ("VISA") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end%> - <% if @payment_methods.include? ("JCB") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end%> - <% if @payment_methods.include? ("UNIONPAY") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end %> - <% if @payment_methods.include? ("Alipay") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end %> - <% if @payment_methods.include? ("KBZPay") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end %> - <% if @payment_methods.include? ("PAYMAL") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end %> - <% if @payment_methods.include? ("DINGA") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end %> - <% if @payment_methods.include? ("JunctionPay") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end %> - <% if @payment_methods.include? ("Redeem") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - - <% end %> - <% if @payment_methods.include? ("GiftVoucher") %> - <% colspan += 1 %> - + <% @payment_methods.each do |method| %> + <% colspan += 1 %> + <% end %> @@ -293,12 +149,12 @@ <% net = net - total_tax %> - + <% else %> - + <% end %> diff --git a/app/views/reports/payment_method/index.html.erb b/app/views/reports/payment_method/index.html.erb index 85e61a0a..93f7be28 100755 --- a/app/views/reports/payment_method/index.html.erb +++ b/app/views/reports/payment_method/index.html.erb @@ -1,5 +1,12 @@ -<% breadcrumb_add 'Payment Method Report', "", dashboard_path %> - +
@@ -33,42 +40,25 @@ <% end %>
- - - - - - - - - - - + <% @payment_methods.each do |method| %> + + <% end %> - <% unless @sale_data.empty? %> <% @sale_data.each do |sale| %> - - - - - - - - - - - + <% @payment_methods.each do |method| %> + + <% end %> - + <% end %> diff --git a/app/views/reports/payment_method/index.xls.erb b/app/views/reports/payment_method/index.xls.erb index a6fcf35d..ec4dfbee 100755 --- a/app/views/reports/payment_method/index.xls.erb +++ b/app/views/reports/payment_method/index.xls.erb @@ -27,42 +27,24 @@ <% end %> - - - - - - - - - - - + <% @payment_methods.each do |method| %> + + <% end %> - <% unless @sale_data.empty? %> <% @sale_data.each do |sale| %> - - - - - - - - - - - + <% @payment_methods.each do |method| %> + + <% end %> - <% end %> diff --git a/app/views/reports/receipt_no_detail/_shift_sale_report_filter.html.erb b/app/views/reports/receipt_no_detail/_shift_sale_report_filter.html.erb index 89264e82..ad834e00 100755 --- a/app/views/reports/receipt_no_detail/_shift_sale_report_filter.html.erb +++ b/app/views/reports/receipt_no_detail/_shift_sale_report_filter.html.erb @@ -18,17 +18,14 @@ - <% if defined? payments %> + <% if defined? @payment_methods %>
diff --git a/app/views/reports/waste_and_spoilage/index.html.erb b/app/views/reports/waste_and_spoilage/index.html.erb index b65a804a..714f2e69 100755 --- a/app/views/reports/waste_and_spoilage/index.html.erb +++ b/app/views/reports/waste_and_spoilage/index.html.erb @@ -1,6 +1,13 @@
- <% breadcrumb_add t("views.right_panel.detail.waste_spoilage_report"), "", dashboard_path %> - +
<%= render :partial=>'shift_sale_report_filter', @@ -48,7 +55,7 @@ <% @sale_data.each do |sale| %> <% if !sale.item_instance_code.nil?%> <% waste_and_spoil_item_count += sale.qty.to_i %> - <% grand_total += sale.grand_total.to_i %> + <% grand_total += sale.price.to_i %> <% end %>
<% if !menu_cat_arr.include?(sale.name) %> diff --git a/app/views/transactions/shift_sales/show.html.erb b/app/views/transactions/shift_sales/show.html.erb index d6e8bee4..a1fd7edc 100755 --- a/app/views/transactions/shift_sales/show.html.erb +++ b/app/views/transactions/shift_sales/show.html.erb @@ -1,4 +1,13 @@ -<% breadcrumb_add t('shiftsale'), transactions_shift_sales_path, transactions_shift_sales_path, t('details') %> +
@@ -31,7 +40,7 @@
- + @@ -39,31 +48,31 @@
Sub Total <%=number_format(sub_total, precision: precision.to_i)%>
Member Discount:(Discount)(<%= number_format(@sale_data.total_discount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>)(<%= number_format(@sale.total_discount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>)
@@ -104,23 +104,23 @@ <% else %> No Tax <% end %>
- <%if @sale_payment.nil? && @changable_tax %> + <%if @sale_payment && @changable_tax %> <% if @current_user.role == 'cashier' %> - + <% else %> - + <% end %> <% end %>
<%= number_format(@sale_data.total_tax, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%><%= number_format(@sale.total_tax, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%>
Rounding Adj:<%= number_format(@sale_data.rounding_adjustment, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%><%= number_format(@sale.rounding_adjustment, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%>
Grand Total<%= number_format(@sale_data.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%><%= number_format(@sale.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%>
<%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
Income Outgoinglive_helplive_helplive_helplive_helplive_helplive_helplive_helplive_help
<%= t("views.right_panel.detail.sr") %><%= t("views.right_panel.detail.date") %><%= t("views.righ_panel.detail.date") %><%= t("views.right_panel.detail.#{method}") %><%= t("views.right_panel.detail.mpu_sales") %><%= t("views.right_panel.detail.master_sales") %><%= t("views.right_panel.detail.visa_sales") %><%= t("views.right_panel.detail.jcb_sales") %><%= t("views.right_panel.detail.unionpay_sales") %><%= t("views.right_panel.detail.kbzpay_sales") %><%= t("views.right_panel.detail.alipay_sales") %><%= t("views.right_panel.detail.paymal_sales") %><%= t("views.right_panel.detail.dinga_sales") %><%= t("views.right_panel.detail.junctionpay_sales") %><%= t("views.right_panel.detail.redeem_sales") %><%= t("views.right_panel.detail.giftvoucher_sales") %><%= t("views.right_panel.detail.cash_sales") %> <%= t("views.right_panel.detail.credit_sales") %> <%= t("views.right_panel.detail.void_amount") %>
<%= count %> <%= sale[:sale_date].strftime("#{sale[:sale_date].day.ordinalize} %b") rescue '-' %><%= number_format(sale[:mpu_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:master_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:visa_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:jcb_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:unionpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:alipay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:kbzpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:paymal_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:dinga_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:junctionpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:paypar_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:giftvoucher_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[method.parameterize.to_sym], precision:precision.to_i, delimiter: delimiter) rescue 0 %><%= number_format(sale[:cash_amount]-sale[:total_change_amount], precision:precision.to_i, delimiter: delimiter) rescue '-'%> <%= number_format(sale[:credit_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%>(<%= number_format(sale[:total_discount], precision:precision,delimiter:delimiter) rescue '-'%>) <%= number_format(sale[:rounding_adj].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:rounding_adj], precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(sale[:gross_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(sale[:total_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%>
Total<%= number_format(mpu , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(master, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(visa, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(jcb, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(unionpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(alipay, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(kbzpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(paymal, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(dinga, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(junctionpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(paypar, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(giftvoucher, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(@sale_data.inject(0.0.to_d) { |sum, sale| sum + sale[method.parameterize.to_sym] }, precision:precision.to_i,delimiter:delimiter) rescue 0 %><%= number_format(cash, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(credit, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= t("views.right_panel.detail.sr") %> <%= t("views.right_panel.detail.date") %><%= t("views.right_panel.detail.mpu_sales") %><%= t("views.right_panel.detail.master_sales") %><%= t("views.right_panel.detail.visa_sales") %><%= t("views.right_panel.detail.jcb_sales") %><%= t("views.right_panel.detail.unionpay_sales") %><%= t("views.right_panel.detail.kbzpay_sales") %><%= t("views.right_panel.detail.alipay_sales") %><%= t("views.right_panel.detail.paymal_sales") %><%= t("views.right_panel.detail.dinga_sales") %><%= t("views.right_panel.detail.junctionpay_sales") %><%= t("views.right_panel.detail.redeem_sales") %><%= t("views.right_panel.detail.giftvoucher_sales") %><%= t("views.right_panel.detail.#{method}") %><%= t("views.right_panel.detail.cash_sales") %> <%= t("views.right_panel.detail.credit_sales") %>
<%= count %> <%= sale[:sale_date].strftime("#{sale[:sale_date].day.ordinalize} %b") rescue '-' %><%= number_format(sale[:mpu_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:master_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:visa_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:jcb_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:unionpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:alipay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:kbzpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:paymal_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:dinga_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:junctionpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:paypar_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:giftvoucher_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[method.parameterize.to_sym], precision:precision.to_i, delimiter: delimiter) rescue 0 %><%= number_format(sale[:cash_amount]-sale[:total_change_amount], precision:precision.to_i, delimiter: delimiter) rescue '-'%> <%= number_format(sale[:credit_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%>
Total<%= number_format(mpu , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(master, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(visa, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(jcb, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(unionpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(alipay, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(kbzpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(paymal, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(dinga, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(junctionpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(paypar, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(giftvoucher, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(@sale_data.inject(0.0.to_d) { |sum, sale| sum + sale[method.parameterize.to_sym] }, precision:precision.to_i,delimiter:delimiter) rescue 0 %><%= number_format(cash, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(credit, precision:precision.to_i,delimiter:delimiter) rescue '-'%>
<%= t("views.right_panel.detail.net_amount") %><%= number_format(net, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(net, precision:precision.to_i,delimiter:delimiter) rescue '-'%>
<%= t("views.right_panel.detail.net_amount") %><%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%>
<%= t("views.right_panel.detail.mpu_sales") %><%= t("views.right_panel.detail.master_sales") %><%= t("views.right_panel.detail.visa_sales") %><%= t("views.right_panel.detail.jcb_sales") %><%= t("views.right_panel.detail.unionpay_sales") %><%= t("views.right_panel.detail.alipay_sales") %><%= t("views.right_panel.detail.kbzpay_sales") %><%= t("views.right_panel.detail.dinga_sales") %><%= t("views.right_panel.detail.junctionpay_sales") %><%= t("views.right_panel.detail.redeem_sales") %><%= t("views.right_panel.detail.#{method} Sales") %><%= t("views.right_panel.detail.cash_sales") %> <%= t("views.right_panel.detail.credit_sales") %> <%= t("views.right_panel.detail.foc_sales") %><%= t("views.right_panel.detail.giftvoucher_sales") %>
<%= number_format(sale[:mpu_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:master_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:visa_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:jcb_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:unionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:alipay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:kbzpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:dinga_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:junctionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:paypar_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[method.parameterize.to_sym] , precision: precision.to_i ,delimiter: delimiter) rescue 0 %><%= number_format(sale[:cash_amount]-sale[:total_change_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%= number_format(sale[:credit_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%= number_format(sale[:foc_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:giftvoucher_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %>
<%= t("views.right_panel.detail.mpu_sales") %><%= t("views.right_panel.detail.master_sales") %><%= t("views.right_panel.detail.visa_sales") %><%= t("views.right_panel.detail.jcb_sales") %><%= t("views.right_panel.detail.unionpay_sales") %><%= t("views.right_panel.detail.alipay_sales") %><%= t("views.right_panel.detail.kbzpay_sales") %><%= t("views.right_panel.detail.dinga_sales") %><%= t("views.right_panel.detail.junctionpay_sales") %><%= t("views.right_panel.detail.redeem_sales") %><%= t("views.right_panel.detail.#{method} Sales") %><%= t("views.right_panel.detail.cash_sales") %> <%= t("views.right_panel.detail.credit_sales") %> <%= t("views.right_panel.detail.foc_sales") %><%= t("views.right_panel.detail.giftvoucher_sales") %>
<%= number_format(sale[:mpu_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:master_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:visa_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:jcb_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:unionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:alipay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:kbzpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:dinga_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:junctionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:paypar_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[method.parameterize.to_sym] , precision: precision.to_i ,delimiter: delimiter) rescue 0 %><%= number_format(sale[:cash_amount]-sale[:total_change_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%= number_format(sale[:credit_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%= number_format(sale[:foc_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:giftvoucher_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %>
<%= @shift.total_receipt %> <%= @shift.dining_count %> <%= @shift.takeaway_count %>(<%= @shift.total_void.round(2) %>)(<%= @shift.total_void %>)
<% @total_amount_by_account.each do |amount| %> - + - + <%end%> - + <% @total_discount_by_account.each do |amount| %> - + - + <%end%> <% if !@total_member_discount[0].member_discount.nil? - @member_discount = @total_member_discount[0].member_discount rescue 0.0 + @member_discount = @total_member_discount[0].member_discount rescue 0.0 @overall = @shift.total_discounts - @member_discount %> - + @@ -71,109 +80,82 @@ <%end%> - + - + <% @sale_taxes.each do |tax| %> - + - + <%end%> - + - + - + - + - +
Total <%= amount.account_name %> Amount<%= amount.total_price.round(2) %><%= amount.total_price %>
Net Sales <%=@shift.nett_sales %>
Total <%= amount.account_name %> Discount<%= amount.total_price.round(2) %><%= amount.total_price %>
Total Member Discount <%= @member_discount %>
Total Overall Discount <%= @overall %>
Total Discount <%= @shift.total_discounts %>
<%= tax.tax_name %> <%= tax.st_amount.round(2) %><%= tax.st_amount %>
Total Tax <%=@shift.total_taxes %>
Rounding Adj <%= @shift.total_rounding.round(2) %><%= @shift.total_rounding %>
Grand Total <%= @shift.grand_total.round(2) %><%= @shift.grand_total %>
+ <% total_other_amount = 0 %> - + - + - <% @total_amount = 0 - - @other_payment.each do |other| %> - - - - - <% @total_amount = @total_amount+other.mpu_amount rescue 0.0 %> - - - - - - <% @total_amount = @total_amount+other.visa_amount rescue 0.0 %> - - - - - - <% @total_amount = @total_amount+other.jcb_amount rescue 0.0 %> - - - - - - <% @total_amount = @total_amount+other.master_amount rescue 0.0 %> - - - - - - <% @total_amount = @total_amount+other.paypar_amount rescue 0.0 %> - + <% @payment_methods.each do |method| %> + + + + + <% total_other_amount = total_other_amount + (@other_payment[method.parameterize.to_sym] || 0.0) %> + + <% end %> - - <% @total_amount = @total_amount+other.foc_amount rescue 0.0 %> + - <%end%> - + - + -
Cash Payment <%=@shift.cash_sales %><%= @shift.cash_sales %>
Credit Payment <%=@shift.credit_sales %><%= @shift.credit_sales %>
Other Payment Detail
MPU Payment <%=other.mpu_amount.round(2) rescue 0.0 %>
VISA Payment <%=other.visa_amount.round(2) rescue 0.0 %>
Master Payment <%=other.master_amount.round(2) rescue 0.0 %>
JCB Payment <%=other.jcb_amount.round(2) rescue 0.0 %>
Reedem Payment <%=other.paypar_amount.round(2) rescue 0.0 %>
<%= method %> Payment<%= @other_payment[method.parameterize.to_sym] || 0.0 %>
FOC <%=other.foc_amount.round(2) rescue 0.0 %><%= @other_payment.foc_amount rescue 0.0 %>
Total Other Payment <%=@shift.other_sales %><%= total_other_amount %>
Total Payment <%= @total_amount+@shift.cash_sales+@shift.credit_sales %><%= total_other_amount + @other_payment.foc_amount + @shift.cash_sales + @shift.credit_sales %>
diff --git a/config/routes.rb b/config/routes.rb index 8914aced..b16641e5 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -260,23 +260,26 @@ scope "(:locale)", locale: /en|mm/ do post 'payment/dinga' => 'dinga#create' post 'payment/gift_voucher' => 'gift_voucher#create' post 'payment/credit_payment' => 'credit_payments#create_credit_payment' + post 'payment/:method' => 'others_payments#create', :as => 'payment' post 'payment/:type/change_tax' => 'payments#change_tax', :defaults => {:format => 'json'} get 'sale/:sale_id/:type/payment/credit_payment' => "credit_payments#index" get 'sale/:sale_id/:type/payment/others_payment' => "others_payments#index" - get 'sale/:sale_id/:type/payment/others_payment/MPU' => "mpu#index" - get 'sale/:sale_id/:type/payment/others_payment/VISA' => "visa#index" - get 'sale/:sale_id/:type/payment/others_payment/Master' => "master#index" - get 'sale/:sale_id/:type/payment/others_payment/JCB' => "jcb#index" - get 'sale/:sale_id/:type/payment/others_payment/PAYMAL' => "paymal#index" - get 'sale/:sale_id/:type/payment/others_payment/UNIONPAY' => "unionpay#index" - get 'sale/:sale_id/:type/payment/others_payment/Redeem' => "redeem_payments#index" - get 'sale/:sale_id/:type/payment/others_payment/Voucher' => "voucher#index" - get 'sale/:sale_id/:type/payment/others_payment/JunctionPay' => "junction_pay#index" - get 'sale/:sale_id/:type/payment/others_payment/Alipay' => "alipay#index" - get 'sale/:sale_id/:type/payment/others_payment/DINGA' => "dinga#index" - get 'sale/:sale_id/:type/payment/others_payment/GiftVoucher' => "gift_voucher#index" + get 'sale/:sale_id/:type/payment/others_payment/mpu' => "mpu#index" + get 'sale/:sale_id/:type/payment/others_payment/visa' => "visa#index" + get 'sale/:sale_id/:type/payment/others_payment/master' => "master#index" + get 'sale/:sale_id/:type/payment/others_payment/jcb' => "jcb#index" + get 'sale/:sale_id/:type/payment/others_payment/paymal' => "paymal#index" + get 'sale/:sale_id/:type/payment/others_payment/unionpay' => "unionpay#index" + get 'sale/:sale_id/:type/payment/others_payment/redeem' => "redeem_payments#index" + get 'sale/:sale_id/:type/payment/others_payment/voucher' => "voucher#index" + get 'sale/:sale_id/:type/payment/others_payment/junctionpay' => "junction_pay#index" + get 'sale/:sale_id/:type/payment/others_payment/alipay' => "alipay#index" + get 'sale/:sale_id/:type/payment/others_payment/dinga' => "dinga#index" + get 'sale/:sale_id/:type/payment/others_payment/giftvoucher' => "gift_voucher#index" + get 'sale/:sale_id/:type/payment/others_payment/:method' => 'others_payments#new' + #---------Void --------------# post 'sale/:sale_id/:type/void' => 'void#overall_void' @@ -369,18 +372,20 @@ scope "(:locale)", locale: /en|mm/ do # post 'credit_payment/gift_voucher' => 'gift_voucher#create' get 'sale/:sale_id/:type/credit_payment/others_payment' => "others_payments#index" - get 'sale/:sale_id/:type/credit_payment/others_payment/MPU' => "mpu#index" - get 'sale/:sale_id/:type/credit_payment/others_payment/VISA' => "visa#index" - get 'sale/:sale_id/:type/credit_payment/others_payment/Master' => "master#index" - get 'sale/:sale_id/:type/credit_payment/others_payment/JCB' => "jcb#index" - # get 'sale/:sale_id/:type/credit_payment/others_payment/PAYMAL' => "paymal#index" - get 'sale/:sale_id/:type/credit_payment/others_payment/UNIONPAY' => "unionpay#index" - # get 'sale/:sale_id/:type/credit_payment/others_payment/Redeem' => "redeem_payments#index" - # get 'sale/:sale_id/:type/credit_payment/others_payment/Voucher' => "voucher#index" - # get 'sale/:sale_id/:type/credit_payment/others_payment/JunctionPay' => "junction_pay#index" - get 'sale/:sale_id/:type/credit_payment/others_payment/Alipay' => "alipay#index" - # get 'sale/:sale_id/:type/credit_payment/others_payment/DINGA' => "dinga#index" - # get 'sale/:sale_id/:type/credit_payment/others_payment/GiftVoucher' => "gift_voucher#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/mpu' => "mpu#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/visa' => "visa#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/master' => "master#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/jcb' => "jcb#index" + # get 'sale/:sale_id/:type/credit_payment/others_payment/paymal' => "paymal#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/unionpay' => "unionpay#index" + # get 'sale/:sale_id/:type/credit_payment/others_payment/redeem' => "redeem_payments#index" + # get 'sale/:sale_id/:type/credit_payment/others_payment/voucher' => "voucher#index" + # get 'sale/:sale_id/:type/credit_payment/others_payment/junctionpay' => "junction_pay#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/alipay' => "alipay#index" + # get 'sale/:sale_id/:type/credit_payment/others_payment/dinga' => "dinga#index" + # get 'sale/:sale_id/:type/credit_payment/others_payment/giftvoucher' => "gift_voucher#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/:method' => 'others_payments#new' + #------------- Start Reservation -------------------# resources :reservation