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' +
+ '

\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' +
- '

\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' %>
| Redeem Sale : |
<% else %>
<%= payment.payment_method.to_s.capitalize %> Sale : |
<% end %>
-
- <%= 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 %>
+ |
+
+ <% end %>
<% end %>
<% end %>
- <% total_card = @sale_data.find {|x| x.key?("card") } %>
- <% if !total_card.nil? %>
-
- | <%= 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) %>
-
- |
-
+ <% total_card = @sale_data.select { |hash| hash["card"]!=nil } %>
+ <% if !total_card.nil? %>
+
+ | <%= 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 %>
+ |
+
<% end %>
-
<% end %>
@@ -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" %>
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 @@
-