From ce644e304cc1ee203722d4d5449f11d30ac78c4a Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Thu, 22 Feb 2018 16:43:53 +0630 Subject: [PATCH 001/108] Validate required for reference no: in other payment amount --- app/views/origami/jcb/index.html.erb | 92 +++++++++++---------- app/views/origami/master/index.html.erb | 92 +++++++++++---------- app/views/origami/mpu/index.html.erb | 99 ++++++++++++----------- app/views/origami/unionpay/index.html.erb | 96 ++++++++++++---------- app/views/origami/visa/index.html.erb | 96 ++++++++++++---------- 5 files changed, 257 insertions(+), 218 deletions(-) diff --git a/app/views/origami/jcb/index.html.erb b/app/views/origami/jcb/index.html.erb index 837c9f43..1fe49080 100755 --- a/app/views/origami/jcb/index.html.erb +++ b/app/views/origami/jcb/index.html.erb @@ -51,7 +51,8 @@
- + +

@@ -194,53 +195,60 @@ $(document).on('click', '.cashier_number', function(event){ $('#jcb_pay').on('click',function(){ var amount = $('#amount').text(); + var reference_no = $('#reference_no').val(); var sale_id = "<%= @sale_id %>"; var receipt_no = "<%= @receipt_no %>"; var bank_integration = "<%= @bank_integration %>"; - if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) && amount > 0){ - $(this).off("click"); - //start member discount 5% by pay card - // var sub_total = $('#sub-total').text(); - // var member_id = $('#membership_id').text(); - // var member_discount = $('#member_discount').text(); - // if (member_id && member_discount) { - // $.ajax({ - // type: "POST", - // url: "/origami/" + sale_id + "/member_discount", - // data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, - // success:function(result){ - // } - // }); - // } - //end member discount - if(bank_integration == '1'){ - pay_withBank("SALE", "jcb", amount, sale_id, receipt_no); + $("#reference_no_Err").html(""); + if(reference_no.length > 0){ + if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) && amount > 0){ + $(this).off("click"); + //start member discount 5% by pay card + // var sub_total = $('#sub-total').text(); + // var member_id = $('#membership_id').text(); + // var member_discount = $('#member_discount').text(); + // if (member_id && member_discount) { + // $.ajax({ + // type: "POST", + // url: "/origami/" + sale_id + "/member_discount", + // data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, + // success:function(result){ + // } + // }); + // } + //end member discount + if(bank_integration == '1'){ + $("#reference_no").val(""); + pay_withBank("SALE", "jcb", amount, sale_id, receipt_no); + }else{ + $.ajax({type: "POST", + url: "<%= origami_payment_jcb_path %>", + data: "amount="+ amount + "&sale_id="+ sale_id, + success:function(result){ + if(result){ + swal({ + title: "Information!", + text: "Payment Successfully", + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment"; + }); + } + } + }); + } }else{ - $.ajax({type: "POST", - url: "<%= origami_payment_jcb_path %>", - data: "amount="+ amount + "&sale_id="+ sale_id, - success:function(result){ - if(result){ - swal({ - title: "Information!", - text: "Payment Successfully", - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment"; - }); - } - } - }); + if (amount>0) { + swal ( "Oops" , "Paid Amount is over!" , "error" ); + }else{ + swal ( "Oops" , "Enter Amount!" , "error" ); + } } }else{ - if (amount>0) { - swal ( "Oops" , "Paid Amount is over!" , "error" ); - }else{ - swal ( "Oops" , "Enter Amount!" , "error" ); - } + $("#reference_no_Err").html("can't be blank"); } }) diff --git a/app/views/origami/master/index.html.erb b/app/views/origami/master/index.html.erb index f5c8f06b..2e663b7a 100755 --- a/app/views/origami/master/index.html.erb +++ b/app/views/origami/master/index.html.erb @@ -52,7 +52,8 @@
- + +

@@ -192,53 +193,60 @@ }); $('#master_pay').on('click',function(){ var amount = $('#amount').text(); + var reference_no = $('#reference_no').val(); var sale_id = "<%= @sale_id %>"; var receipt_no = "<%= @receipt_no %>"; var bank_integration = "<%= @bank_integration %>"; - if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) && amount > 0){ - $(this).off("click"); - //start member discount 5% by pay card - // var sub_total = $('#sub-total').text(); - // var member_id = $('#membership_id').text(); - // var member_discount = $('#member_discount').text(); - // if (member_id && member_discount) { - // $.ajax({ - // type: "POST", - // url: "/origami/" + sale_id + "/member_discount", - // data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, - // // success:function(result){ - // // } - // }); - // } - //end member discount - if(bank_integration == '1'){ - pay_withBank("SALE", "master", amount, sale_id, receipt_no); - }else{ - $.ajax({type: "POST", - url: "<%= origami_payment_master_path %>", - data: "amount="+ amount + "&sale_id="+ sale_id, - success:function(result){ - if(result){ - swal({ - title: "Information!", - text: "Payment Successfully", - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment"; - }); + $("#reference_no_Err").html(""); + if(reference_no.length > 0){ + if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) && amount > 0){ + $(this).off("click"); + //start member discount 5% by pay card + // var sub_total = $('#sub-total').text(); + // var member_id = $('#membership_id').text(); + // var member_discount = $('#member_discount').text(); + // if (member_id && member_discount) { + // $.ajax({ + // type: "POST", + // url: "/origami/" + sale_id + "/member_discount", + // data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, + // // success:function(result){ + // // } + // }); + // } + //end member discount + if(bank_integration == '1'){ + $("#reference_no").val(""); + pay_withBank("SALE", "master", amount, sale_id, receipt_no); + }else{ + $.ajax({type: "POST", + url: "<%= origami_payment_master_path %>", + data: "amount="+ amount + "&sale_id="+ sale_id, + success:function(result){ + if(result){ + swal({ + title: "Information!", + text: "Payment Successfully", + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment"; + }); + } } - } - }); + }); + } + }else{ + if (amount>0) { + swal ( "Oops" , "Paid Amount is over!" , "error" ); + }else{ + swal ( "Oops" , "Enter Amount!" , "error" ); + } } }else{ - if (amount>0) { - swal ( "Oops" , "Paid Amount is over!" , "error" ); - }else{ - swal ( "Oops" , "Enter Amount!" , "error" ); - } + $("#reference_no_Err").html("can't be blank"); } }) diff --git a/app/views/origami/mpu/index.html.erb b/app/views/origami/mpu/index.html.erb index f40ce252..f95b3773 100755 --- a/app/views/origami/mpu/index.html.erb +++ b/app/views/origami/mpu/index.html.erb @@ -52,7 +52,8 @@
- + +

@@ -196,56 +197,62 @@ $('#mpu_pay').on('click',function(){ var amount = $('#amount').text(); + var reference_no = $('#reference_no').val(); var sale_id = "<%= @sale_id %>"; var receipt_no = "<%= @receipt_no %>"; var bank_integration = "<%= @bank_integration %>"; var cashier_type = "<%= @cashier_type %>"; - if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) && amount > 0){ - $(this).off("click"); - //start member discount 5% by pay card - // var sub_total = $('#sub-total').text(); - // var member_id = $('#membership_id').text(); - // var member_discount = $('#member_discount').text(); - // if (member_id && member_discount) { - // $.ajax({ - // type: "POST", - // url: "/origami/" + sale_id + "/member_discount", - // data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, - // success:function(result){ - // } - // }); - // } - //end member discount - if(bank_integration == '1'){ - pay_withBank("SALE", "mpu", amount, sale_id, receipt_no); - }else{ - $.ajax({type: "POST", - url: "<%= origami_payment_mpu_path %>", - data: "amount="+ amount + "&sale_id="+ sale_id, - success:function(result){ - if(result){ - swal({ - title: "Information!", - text: "Payment Successfully", - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type+ "/payment"; - }); - } - } - }); - } - - }else{ - if (amount>0) { - swal ( "Oops" , "Paid Amount is over!" , "error" ); + $("#reference_no_Err").html(""); + if(reference_no.length > 0){ + if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) && amount > 0){ + $(this).off("click"); + //start member discount 5% by pay card + // var sub_total = $('#sub-total').text(); + // var member_id = $('#membership_id').text(); + // var member_discount = $('#member_discount').text(); + // if (member_id && member_discount) { + // $.ajax({ + // type: "POST", + // url: "/origami/" + sale_id + "/member_discount", + // data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, + // success:function(result){ + // } + // }); + // } + //end member discount + if(bank_integration == '1'){ + $("#reference_no").val(""); + pay_withBank("SALE", "mpu", amount, sale_id, receipt_no); + }else{ + $.ajax({type: "POST", + url: "<%= origami_payment_mpu_path %>", + data: "amount="+ amount + "&sale_id="+ sale_id, + success:function(result){ + if(result){ + swal({ + title: "Information!", + text: "Payment Successfully", + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type+ "/payment"; + }); + } + } + }); + } }else{ - swal ( "Oops" , "Enter Amount!" , "error" ); + if (amount>0) { + swal ( "Oops" , "Paid Amount is over!" , "error" ); + }else{ + swal ( "Oops" , "Enter Amount!" , "error" ); + } } - } - }) + }else{ + $("#reference_no_Err").html("can't be blank"); + } + }) diff --git a/app/views/origami/unionpay/index.html.erb b/app/views/origami/unionpay/index.html.erb index 5dee20f1..8658f23c 100755 --- a/app/views/origami/unionpay/index.html.erb +++ b/app/views/origami/unionpay/index.html.erb @@ -52,7 +52,8 @@
- + +

@@ -196,54 +197,61 @@ }); $('#unionpay_pay').on('click',function(){ var amount = $('#amount').text(); + var reference_no = $('#reference_no').val(); var sale_id = "<%= @sale_id %>"; var receipt_no = "<%= @receipt_no %>"; - if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) && amount > 0){ - $(this).off("click"); - //start member discount 5% by pay card - // var sub_total = $('#sub-total').text(); - // var member_id = $('#membership_id').text(); - // var member_discount = $('#member_discount').text(); - // if (member_id && member_discount) { - // $.ajax({ - // type: "POST", - // url: "/origami/" + sale_id + "/member_discount", - // data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, - // success:function(result){ - // } - // }); - // } - //end member discount - var bank_integration = "<%= @bank_integration %>"; - if(bank_integration == '1'){ - pay_withBank("SALE", "unionpay", amount, sale_id, receipt_no); - } - else{ - $.ajax({type: "POST", - url: "<%= origami_payment_unionpay_path %>", - data: "amount="+ amount + "&sale_id="+ sale_id, - success:function(result){ - if(result){ - swal({ - title: "Information!", - text: "Payment Successfully", - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment"; - }); + $("#reference_no_Err").html(""); + if(reference_no.length > 0){ + if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) && amount > 0){ + $(this).off("click"); + //start member discount 5% by pay card + // var sub_total = $('#sub-total').text(); + // var member_id = $('#membership_id').text(); + // var member_discount = $('#member_discount').text(); + // if (member_id && member_discount) { + // $.ajax({ + // type: "POST", + // url: "/origami/" + sale_id + "/member_discount", + // data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, + // success:function(result){ + // } + // }); + // } + //end member discount + var bank_integration = "<%= @bank_integration %>"; + if(bank_integration == '1'){ + $("#reference_no").val(""); + pay_withBank("SALE", "unionpay", amount, sale_id, receipt_no); + } + else{ + $.ajax({type: "POST", + url: "<%= origami_payment_unionpay_path %>", + data: "amount="+ amount + "&sale_id="+ sale_id, + success:function(result){ + if(result){ + swal({ + title: "Information!", + text: "Payment Successfully", + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment"; + }); + } } - } - }); + }); + } + }else{ + if (amount>0) { + swal ( "Oops" , "Paid Amount is over!" , "error" ); + }else{ + swal ( "Oops" , "Enter Amount!" , "error" ); + } } }else{ - if (amount>0) { - swal ( "Oops" , "Paid Amount is over!" , "error" ); - }else{ - swal ( "Oops" , "Enter Amount!" , "error" ); - } + $("#reference_no_Err").html("can't be blank"); } }) diff --git a/app/views/origami/visa/index.html.erb b/app/views/origami/visa/index.html.erb index 2970ba44..60f62caa 100755 --- a/app/views/origami/visa/index.html.erb +++ b/app/views/origami/visa/index.html.erb @@ -52,7 +52,8 @@
- + +

@@ -195,56 +196,63 @@ }); $('#visa_pay').on('click',function(){ var amount = $('#amount').text(); + var reference_no = $('#reference_no').val(); var sale_id = "<%= @sale_id %>"; var receipt_no = "<%= @receipt_no %>"; console.log(amount); console.log($("#validamount").attr("value")); - if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) && amount > 0){ - $(this).off("click"); - //start member discount 5% by pay card - // var sub_total = $('#sub-total').text(); - // var member_id = $('#membership_id').text(); - // var member_discount = $('#member_discount').text(); - // if (member_id && member_discount) { - // $.ajax({ - // type: "POST", - // url: "/origami/" + sale_id + "/member_discount", - // data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, - // success:function(result){ - // } - // }); - // } - //end member discount - var bank_integration = "<%= @bank_integration %>"; - if(bank_integration == '1'){ - pay_withBank("SALE", "visa", amount, sale_id, receipt_no); - } - else{ - $.ajax({type: "POST", - url: "<%= origami_payment_visa_path %>", - data: "amount="+ amount + "&sale_id="+ sale_id, - success:function(result){ - if(result){ - swal({ - title: "Information!", - text: "Payment Successfully", - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment"; - }); + $("#reference_no_Err").html(""); + if(reference_no.length > 0){ + if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) && amount > 0){ + $(this).off("click"); + //start member discount 5% by pay card + // var sub_total = $('#sub-total').text(); + // var member_id = $('#membership_id').text(); + // var member_discount = $('#member_discount').text(); + // if (member_id && member_discount) { + // $.ajax({ + // type: "POST", + // url: "/origami/" + sale_id + "/member_discount", + // data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, + // success:function(result){ + // } + // }); + // } + //end member discount + var bank_integration = "<%= @bank_integration %>"; + if(bank_integration == '1'){ + $("#reference_no").val(""); + pay_withBank("SALE", "visa", amount, sale_id, receipt_no); + } + else{ + $.ajax({type: "POST", + url: "<%= origami_payment_visa_path %>", + data: "amount="+ amount + "&sale_id="+ sale_id, + success:function(result){ + if(result){ + swal({ + title: "Information!", + text: "Payment Successfully", + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment"; + }); + } } - } - }); + }); + } + }else{ + if (amount>0) { + swal ( "Oops" , "Paid Amount is over!" , "error" ); + }else{ + swal ( "Oops" , "Enter Amount!" , "error" ); + } } }else{ - if (amount>0) { - swal ( "Oops" , "Paid Amount is over!" , "error" ); - }else{ - swal ( "Oops" , "Enter Amount!" , "error" ); - } + $("#reference_no_Err").html("can't be blank"); } }) From fb35d83bbefd488642d63ed22e52349fc311c3ac Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Thu, 22 Feb 2018 17:21:07 +0630 Subject: [PATCH 002/108] change text 'Total Sale => Sale Revenue', 'Grand Total => Total Sale', 'Total Card => Other Payment' for dashboard 'Sale' box --- app/views/origami/dashboard/index.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/origami/dashboard/index.html.erb b/app/views/origami/dashboard/index.html.erb index 8f432e1e..cd9bd050 100644 --- a/app/views/origami/dashboard/index.html.erb +++ b/app/views/origami/dashboard/index.html.erb @@ -98,7 +98,7 @@ <%= @summ_sale.total_receipt %> - <%= t("views.right_panel.detail.total") %> <%= t :sale %> : + <%= t("views.right_panel.detail.sale") %> <%= t :revenue %> : <%= number_with_precision( @summ_sale.total_amount, precision: precision.to_i ,delimiter: delimiter) %> @@ -110,7 +110,7 @@ <%= number_with_precision( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter)%> - <%= t("views.right_panel.detail.grand_total") %> : + <%= t("views.right_panel.detail.total") %> <%= t :sale %> : <%= number_with_precision( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter)%> @@ -135,7 +135,7 @@ <% total_card = @sale_data.select { |hash| hash["card"]!=nil }.first %> <% if !total_card.nil? %> - <%= t("views.right_panel.detail.card_sale") %> : + <%= t("views.right_panel.detail.other_payment") %> : <%= total_card["card"].to_f %> From 36511c258f23ad55270b9b905c147c55f557a1f9 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Fri, 23 Feb 2018 17:07:25 +0630 Subject: [PATCH 003/108] Add Key Pad in login_dashboard.html.erb --- app/views/layouts/login_dashboard.html.erb | 70 +++++++++++++++++++++- app/views/origami/dashboard/index.html.erb | 4 ++ 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/app/views/layouts/login_dashboard.html.erb b/app/views/layouts/login_dashboard.html.erb index e238953f..24b0f2e5 100755 --- a/app/views/layouts/login_dashboard.html.erb +++ b/app/views/layouts/login_dashboard.html.erb @@ -65,8 +65,46 @@

-
-
+
+
+
+ +
+ +
+
+
+
+
+
1
+
2
+
3
+
+
+
4
+
5
+
6
+
+
+
7
+
8
+
9
+
+
+ +
BACK
+
0
+
CLR
+
+
+
+
+ + +
+
@@ -177,7 +215,9 @@ - \ No newline at end of file diff --git a/app/views/origami/jcb/index.html.erb b/app/views/origami/jcb/index.html.erb index 1fe49080..f7f43812 100755 --- a/app/views/origami/jcb/index.html.erb +++ b/app/views/origami/jcb/index.html.erb @@ -12,7 +12,6 @@
--> -
JCB Payment
diff --git a/app/views/origami/master/index.html.erb b/app/views/origami/master/index.html.erb index 2e663b7a..03d90a07 100755 --- a/app/views/origami/master/index.html.erb +++ b/app/views/origami/master/index.html.erb @@ -12,7 +12,6 @@
--> -
Master Payment
diff --git a/app/views/origami/mpu/index.html.erb b/app/views/origami/mpu/index.html.erb index f95b3773..caa0c9e9 100755 --- a/app/views/origami/mpu/index.html.erb +++ b/app/views/origami/mpu/index.html.erb @@ -12,7 +12,6 @@
--> -
MPU Payment
diff --git a/app/views/origami/redeem_payments/index.html.erb b/app/views/origami/redeem_payments/index.html.erb index 1d29e563..169eb026 100755 --- a/app/views/origami/redeem_payments/index.html.erb +++ b/app/views/origami/redeem_payments/index.html.erb @@ -9,7 +9,6 @@
--> -
Reedem Payment
diff --git a/app/views/origami/visa/index.html.erb b/app/views/origami/visa/index.html.erb index 60f62caa..3cdca7df 100755 --- a/app/views/origami/visa/index.html.erb +++ b/app/views/origami/visa/index.html.erb @@ -12,7 +12,6 @@
--> -
VISA Payment
diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index 8f310dab..3f69a55e 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -18,13 +18,13 @@ class ActionController::Base # redirect_to root_url(:host => request.domain) + "store_error" render :json => [{ status: false, message: 'Invalid Access!'}] end - else - # check for license file - if check_license - current_license(ENV["SX_PROVISION_URL"]) - else - redirect_to activate_path - end + # else + # # check for license file + # if check_license + # current_license(ENV["SX_PROVISION_URL"]) + # else + # redirect_to activate_path + # end end end From 5cc369114b249205c02e05f157cbe10d2b097534 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Tue, 6 Mar 2018 18:31:09 +0630 Subject: [PATCH 012/108] Remove config --- config/initializers/action_controller.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index 3f69a55e..8f310dab 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -18,13 +18,13 @@ class ActionController::Base # redirect_to root_url(:host => request.domain) + "store_error" render :json => [{ status: false, message: 'Invalid Access!'}] end - # else - # # check for license file - # if check_license - # current_license(ENV["SX_PROVISION_URL"]) - # else - # redirect_to activate_path - # end + else + # check for license file + if check_license + current_license(ENV["SX_PROVISION_URL"]) + else + redirect_to activate_path + end end end From 9f29bbef5a03360ed5fb1cb7890445813a27ca3b Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Wed, 7 Mar 2018 12:41:49 +0630 Subject: [PATCH 013/108] To add image field in shop --- app/controllers/settings/shops_controller.rb | 2 +- app/models/shop.rb | 3 + app/uploaders/shop_image_uploader.rb | 59 ++++++++ app/views/settings/products/_form.html.erb | 2 +- app/views/settings/shops/_form.html.erb | 144 +++++++++++-------- app/views/settings/shops/show.html.erb | 6 +- 6 files changed, 149 insertions(+), 67 deletions(-) create mode 100644 app/uploaders/shop_image_uploader.rb diff --git a/app/controllers/settings/shops_controller.rb b/app/controllers/settings/shops_controller.rb index a48bcb9a..f69aaac6 100644 --- a/app/controllers/settings/shops_controller.rb +++ b/app/controllers/settings/shops_controller.rb @@ -71,6 +71,6 @@ class Settings::ShopsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def shop_params - params.require(:shop).permit(:name,:address,:city,:township,:state,:country,:phone_no,:reservation_no,:license,:activated_at,:license_data,:base_currency,:cloud_token,:cloud_url,:owner_token,:id_prefix,:is_rounding_adj,:quick_sale_summary,:calc_tax_order,:show_account_info) + params.require(:shop).permit(:logo, :name,:address,:city,:township,:state,:country,:phone_no,:reservation_no,:license,:activated_at,:license_data,:base_currency,:cloud_token,:cloud_url,:owner_token,:id_prefix,:is_rounding_adj,:quick_sale_summary,:calc_tax_order,:show_account_info) end end diff --git a/app/models/shop.rb b/app/models/shop.rb index c722adc2..0fd9ed0e 100755 --- a/app/models/shop.rb +++ b/app/models/shop.rb @@ -1,3 +1,6 @@ class Shop < ApplicationRecord ShopDetail = Shop.find_by_id(1) + + # Shop Image Uploader + mount_uploader :logo, ShopImageUploader end diff --git a/app/uploaders/shop_image_uploader.rb b/app/uploaders/shop_image_uploader.rb new file mode 100644 index 00000000..63a01c21 --- /dev/null +++ b/app/uploaders/shop_image_uploader.rb @@ -0,0 +1,59 @@ +class ShopImageUploader < CarrierWave::Uploader::Base + + # Include RMagick or MiniMagick support: + # include CarrierWave::RMagick + include CarrierWave::MiniMagick + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + def root + Rails.root.join 'public/' + end + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "image/shop_images" + # "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # def cache_dir + # '/tmp/images' + # end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url(*args) + # # For Rails 3.1+ asset pipeline compatibility: + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process scale: [200, 300] + process :resize_to_fit => [200, 150] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + # version :thumb do + # process resize_to_fit: [50, 50] + # end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + def extension_whitelist + %w(jpg jpeg gif png) + end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end \ No newline at end of file diff --git a/app/views/settings/products/_form.html.erb b/app/views/settings/products/_form.html.erb index f9ad882b..bea0f004 100755 --- a/app/views/settings/products/_form.html.erb +++ b/app/views/settings/products/_form.html.erb @@ -12,7 +12,7 @@ <%= f.input :unit_price %> <%= f.input :description %> <%= f.input :information %> - <%= f.input:taxable %> + <%= f.input :taxable %>
diff --git a/app/views/settings/shops/_form.html.erb b/app/views/settings/shops/_form.html.erb index 5a353b9b..b615d189 100755 --- a/app/views/settings/shops/_form.html.erb +++ b/app/views/settings/shops/_form.html.erb @@ -1,68 +1,86 @@
- <%= simple_form_for([:settings,@settings_shop]) do |f| %> - <%= f.error_notification %> -
- <%= f.input :name ,:input_html=>{:class=>"col-md-10"},:required=>true%> - - <%= f.input :address %> - <%= f.input :city %> - <%= f.input :township %> - <%= f.input :state %> - <%= f.input :phone_no %> - <%= f.input :reservation_no %> - <%= f.input :license %> - <%= f.input :license_data %> - <%= f.input :base_currency %> - <%= f.input :cloud_token %> - <%= f.input :cloud_url %> - <%= f.input :owner_token %> - <%= f.input :id_prefix %> - <%= f.input :is_rounding_adj %> - <%= f.input :quick_sale_summary %> - <%= f.input :calc_tax_order %> - <%= f.input :show_account_info %> +
+
+ <%= simple_form_for([:settings,@settings_shop]) do |f| %> + <%= f.error_notification %> +
+ <%= f.input :name ,:input_html=>{:class=>"col-md-10"},:required=>true%> + <%= f.input :address %> + <%= f.input :city %> + <%= f.input :township %> + <%= f.input :state %> + <%= f.input :phone_no %> + <%= f.input :reservation_no %> + <%= f.input :license %> + <%= f.input :license_data %> + <%= f.input :base_currency %> + <%= f.input :cloud_token %> + <%= f.input :cloud_url %> + <%= f.input :owner_token %> + <%= f.input :id_prefix %> + <%= f.input :is_rounding_adj %> + <%= f.input :quick_sale_summary %> + <%= f.input :calc_tax_order %> + <%= f.input :show_account_info %> +
- -
-
- <%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect' %> -
- <% end %> -
-
-
-
-
view_headline <%= t("views.right_panel.header.page_detail") %>
-

- 1) address - to write shop's address
- 2) city - to write city
- 3) township - to write township
- 4) state - to write state
- 5) phone_no - to write shop's phone_no
- 6) reservation_no - to write shop's reservation_no
- 7) license - to write license
- 8) license_data - to write license data
- 9) base_currency - to write base currency
- 10)cloud_token - to write cloud token
- 11)cloud_url - to write cloud url
- 12)owner_token - to write shop's owner token
- 13)id_prefix - to write id prefix
- 14)is_rounding_adj - to check for calculate rounding adj of shop
- 15)quick_sale_summary - to check for view Quick Sale Summary
- 16)calc_tax_order - to check for tax calculation of shop
- -

-
list <%= t("views.right_panel.header.button_lists") %>
-

- 1) <%= t("views.right_panel.button.submit") %> - <%= t("views.right_panel.detail.submit_btn_txt") %> <%= t("views.right_panel.detail.shop_txt") %>
-

-
list <%= t("views.right_panel.header.link_lists") %>
-

- 1) <%= t("views.right_panel.button.home") %> - <%= t("views.right_panel.detail.home_txt") %>
- 2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.shop_txt") %>
-

+ +
+
+ + <%= f.file_field :logo, :class => "img-thumbnail" %> +
+
+ +
+ <%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect' %> +
+ <% end %> +
-
-
+
+ +
+
+
+
view_headline <%= t("views.right_panel.header.page_detail") %>
+

+ 1) address - to write shop's address
+ 2) city - to write city
+ 3) township - to write township
+ 4) state - to write state
+ 5) phone_no - to write shop's phone_no
+ 6) reservation_no - to write shop's reservation_no
+ 7) license - to write license
+ 8) license_data - to write license data
+ 9) base_currency - to write base currency
+ 10)cloud_token - to write cloud token
+ 11)cloud_url - to write cloud url
+ 12)owner_token - to write shop's owner token
+ 13)id_prefix - to write id prefix
+ 14)is_rounding_adj - to check for calculate rounding adj of shop
+ 15)quick_sale_summary - to check for view Quick Sale Summary
+ 16)calc_tax_order - to check for tax calculation of shop
+ +

+
list <%= t("views.right_panel.header.button_lists") %>
+

+ 1) <%= t("views.right_panel.button.submit") %> - <%= t("views.right_panel.detail.submit_btn_txt") %> <%= t("views.right_panel.detail.shop_txt") %>
+

+
list <%= t("views.right_panel.header.link_lists") %>
+

+ 1) <%= t("views.right_panel.button.home") %> - <%= t("views.right_panel.detail.home_txt") %>
+ 2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.shop_txt") %>
+

+
+
+
diff --git a/app/views/settings/shops/show.html.erb b/app/views/settings/shops/show.html.erb index 8fd9c5f0..bea0ab38 100755 --- a/app/views/settings/shops/show.html.erb +++ b/app/views/settings/shops/show.html.erb @@ -96,8 +96,10 @@ <%= @settings_shop.calc_tax_order %> - - + Shop Image + <%= image_tag @settings_shop.logo, :size => '200x200'%> + + <%= link_to t("views.btn.edit"), edit_settings_shop_path(@settings_shop),:class => 'btn btn-primary btn-sm waves-effect' %> From 9ec8c4d18c894622fb729b19e3dff3af63571420 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Wed, 7 Mar 2018 17:50:23 +0630 Subject: [PATCH 014/108] Photo Field in Customer,Employee and Commissionor --- app/assets/javascripts/CRM.js | 23 ++++++- app/assets/javascripts/application.js | 60 +++++++++++++++++++ app/assets/javascripts/origami.js | 25 ++++++++ app/assets/stylesheets/CRM.scss | 1 + app/controllers/crm/customers_controller.rb | 2 +- .../settings/commissioners_controller.rb | 2 +- .../settings/employees_controller.rb | 2 +- app/models/commissioner.rb | 3 + app/models/customer.rb | 3 + app/models/employee.rb | 3 + app/uploaders/commissioner_image_uploader.rb | 59 ++++++++++++++++++ app/uploaders/customer_image_uploader.rb | 59 ++++++++++++++++++ app/uploaders/employee_image_uploader.rb | 59 ++++++++++++++++++ app/views/crm/customers/_new_form.html.erb | 16 +++++ app/views/layouts/_header.html.erb | 6 +- .../settings/commissioners/_form.html.erb | 22 ++++++- .../settings/commissioners/show.html.erb | 4 ++ app/views/settings/employees/_form.html.erb | 16 +++++ app/views/settings/employees/show.html.erb | 4 ++ 19 files changed, 360 insertions(+), 9 deletions(-) create mode 100644 app/uploaders/commissioner_image_uploader.rb create mode 100644 app/uploaders/customer_image_uploader.rb create mode 100644 app/uploaders/employee_image_uploader.rb diff --git a/app/assets/javascripts/CRM.js b/app/assets/javascripts/CRM.js index 03450eb1..b616453c 100755 --- a/app/assets/javascripts/CRM.js +++ b/app/assets/javascripts/CRM.js @@ -23,6 +23,7 @@ //= require bootstrap-notify/bootstrap-notify.js //= require node-waves/waves.js //= require sweetalert/sweetalert.min.js +//= require fileinput.min //= require BSBMaterial/turbolink_admin.js //= require BSBMaterial/demo.js //= require custom.js @@ -34,4 +35,24 @@ $(document).on('turbolinks:load', function() { weekStart: 1, time: false }); -}); \ No newline at end of file + + $("#customer_image_path").fileinput({ + previewFileType: "image", + allowedFileExtensions: ["jpg", "gif", "png"], + browseClass: "btn btn-success", + browseLabel: "Pick Image", + browseIcon: " ", + removeClass: "btn btn-danger", + removeLabel: "Delete", + removeIcon: " ", + showUpload: false, + // uploadClass: "btn btn-info", + // uploadLabel: "Upload", + // uploadIcon: " ", + previewTemplates: { + image: '
\n' + + ' {caption}\n' + + '
\n', + } + }); +}); diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 76341958..590657ef 100755 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -104,6 +104,66 @@ $(document).ready(function() { } }); + $("#shop_logo").fileinput({ + previewFileType: "image", + allowedFileExtensions: ["jpg", "gif", "png"], + browseClass: "btn btn-success", + browseLabel: "Pick Image", + browseIcon: " ", + removeClass: "btn btn-danger", + removeLabel: "Delete", + removeIcon: " ", + showUpload: false, + // uploadClass: "btn btn-info", + // uploadLabel: "Upload", + // uploadIcon: " ", + previewTemplates: { + image: '
\n' + + ' {caption}\n' + + '
\n', + } + }); + + $("#commissioner_image_path").fileinput({ + previewFileType: "image", + allowedFileExtensions: ["jpg", "gif", "png"], + browseClass: "btn btn-success", + browseLabel: "Pick Image", + browseIcon: " ", + removeClass: "btn btn-danger", + removeLabel: "Delete", + removeIcon: " ", + showUpload: false, + // uploadClass: "btn btn-info", + // uploadLabel: "Upload", + // uploadIcon: " ", + previewTemplates: { + image: '
\n' + + ' {caption}\n' + + '
\n', + } + }); + + $("#employee_image_path").fileinput({ + previewFileType: "image", + allowedFileExtensions: ["jpg", "gif", "png"], + browseClass: "btn btn-success", + browseLabel: "Pick Image", + browseIcon: " ", + removeClass: "btn btn-danger", + removeLabel: "Delete", + removeIcon: " ", + showUpload: false, + // uploadClass: "btn btn-info", + // uploadLabel: "Upload", + // uploadIcon: " ", + previewTemplates: { + image: '
\n' + + ' {caption}\n' + + '
\n', + } + }); + // first input focus for all form $('form:first *input[data-behaviour!=datepicker]:input[type!=hidden]:first').focus(); diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index d7afc4db..0f5380a7 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -9,12 +9,37 @@ //= require bootstrap-notify/bootstrap-notify.js //= require node-waves/waves.js //= require sweetalert/sweetalert.min.js +//= require fileinput.min //= require cable //= require turbolinks //= require BSBMaterial/turbolink_admin.js //= require BSBMaterial/demo.js //= require custom.js + +$(document).on('turbolinks:load', function() { + + $("#customer_image_path").fileinput({ + previewFileType: "image", + allowedFileExtensions: ["jpg", "gif", "png"], + browseClass: "btn btn-success", + browseLabel: "Pick Image", + browseIcon: " ", + removeClass: "btn btn-danger", + removeLabel: "Delete", + removeIcon: " ", + showUpload: false, + // uploadClass: "btn btn-info", + // uploadLabel: "Upload", + // uploadIcon: " ", + previewTemplates: { + image: '
\n' + + ' {caption}\n' + + '
\n', + } + }); +}); + $(document).on('turbolinks:load', function() { $('.datetimepicker').bootstrapMaterialDatePicker({ format: 'DD-MM-YYYY - HH:mm', diff --git a/app/assets/stylesheets/CRM.scss b/app/assets/stylesheets/CRM.scss index 8b652eac..5bfab409 100755 --- a/app/assets/stylesheets/CRM.scss +++ b/app/assets/stylesheets/CRM.scss @@ -13,6 +13,7 @@ @import "BSBMaterial/style"; @import "BSBMaterial/themes/all-themes"; @import "reset"; +@import "fileinput.min"; .sx-margin-0 { margin: 0 !important; diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 0168e326..42ea4b2f 100755 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -396,7 +396,7 @@ end def customer_params params.require(:customer).permit(:id, :name, :company, :contact_no, :email, - :date_of_birth,:salutation,:gender,:nrc_no,:address,:card_no, :paypar_account_no, :customer_type) + :date_of_birth,:salutation,:gender,:nrc_no,:address,:card_no, :paypar_account_no, :customer_type, :image_path) end end diff --git a/app/controllers/settings/commissioners_controller.rb b/app/controllers/settings/commissioners_controller.rb index 4f195f43..f8314bcb 100755 --- a/app/controllers/settings/commissioners_controller.rb +++ b/app/controllers/settings/commissioners_controller.rb @@ -91,6 +91,6 @@ class Settings::CommissionersController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def commissioner_params - params.require(:commissioner).permit(:name, :emp_id, :created_by, :commission_id, :joined_date, :resigned_date, :is_active) + params.require(:commissioner).permit(:name, :emp_id, :created_by, :commission_id, :joined_date, :resigned_date, :is_active, :image_path) end end diff --git a/app/controllers/settings/employees_controller.rb b/app/controllers/settings/employees_controller.rb index 2bc81c51..cefb7b9c 100755 --- a/app/controllers/settings/employees_controller.rb +++ b/app/controllers/settings/employees_controller.rb @@ -68,6 +68,6 @@ class Settings::EmployeesController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def employee_params - params.require(:employee).permit(:name, :role, :emp_id, :password) + params.require(:employee).permit(:name, :role, :emp_id, :password, :image_path) end end diff --git a/app/models/commissioner.rb b/app/models/commissioner.rb index 2b262afc..68573460 100755 --- a/app/models/commissioner.rb +++ b/app/models/commissioner.rb @@ -7,4 +7,7 @@ class Commissioner < ApplicationRecord # validations validates_presence_of :name + + # Commissioner Image Uploader + mount_uploader :image_path, CommissionerImageUploader end diff --git a/app/models/customer.rb b/app/models/customer.rb index fcdd7f31..7f5a7a63 100755 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -2,6 +2,9 @@ class Customer < ApplicationRecord #self.primary_key = :customer_id + # Customer Image Uploader + mount_uploader :image_path, CustomerImageUploader + before_create :generate_custom_id has_many :orders has_many :sales diff --git a/app/models/employee.rb b/app/models/employee.rb index a12521cb..c1f985ea 100755 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -8,6 +8,9 @@ class Employee < ApplicationRecord validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true validates :password, numericality: true, length: {in: 3..9}, allow_blank: true + # Employee Image Uploader + mount_uploader :image_path, EmployeeImageUploader + def self.all_emp_except_waiter Employee.where('role!=?','waiter') end diff --git a/app/uploaders/commissioner_image_uploader.rb b/app/uploaders/commissioner_image_uploader.rb new file mode 100644 index 00000000..639ce7d7 --- /dev/null +++ b/app/uploaders/commissioner_image_uploader.rb @@ -0,0 +1,59 @@ +class CommissionerImageUploader < CarrierWave::Uploader::Base + + # Include RMagick or MiniMagick support: + # include CarrierWave::RMagick + include CarrierWave::MiniMagick + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + def root + Rails.root.join 'public/' + end + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "image/commissioner_images" + # "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # def cache_dir + # '/tmp/images' + # end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url(*args) + # # For Rails 3.1+ asset pipeline compatibility: + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process scale: [200, 300] + process :resize_to_fit => [200, 150] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + # version :thumb do + # process resize_to_fit: [50, 50] + # end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + def extension_whitelist + %w(jpg jpeg gif png) + end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end \ No newline at end of file diff --git a/app/uploaders/customer_image_uploader.rb b/app/uploaders/customer_image_uploader.rb new file mode 100644 index 00000000..1de0f3ad --- /dev/null +++ b/app/uploaders/customer_image_uploader.rb @@ -0,0 +1,59 @@ +class CustomerImageUploader < CarrierWave::Uploader::Base + + # Include RMagick or MiniMagick support: + # include CarrierWave::RMagick + include CarrierWave::MiniMagick + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + def root + Rails.root.join 'public/' + end + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "image/customer_images" + # "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # def cache_dir + # '/tmp/images' + # end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url(*args) + # # For Rails 3.1+ asset pipeline compatibility: + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process scale: [200, 300] + process :resize_to_fit => [200, 150] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + # version :thumb do + # process resize_to_fit: [50, 50] + # end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + def extension_whitelist + %w(jpg jpeg gif png) + end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end \ No newline at end of file diff --git a/app/uploaders/employee_image_uploader.rb b/app/uploaders/employee_image_uploader.rb new file mode 100644 index 00000000..fd64db42 --- /dev/null +++ b/app/uploaders/employee_image_uploader.rb @@ -0,0 +1,59 @@ +class EmployeeImageUploader < CarrierWave::Uploader::Base + + # Include RMagick or MiniMagick support: + # include CarrierWave::RMagick + include CarrierWave::MiniMagick + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + def root + Rails.root.join 'public/' + end + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "image/employee_images" + # "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # def cache_dir + # '/tmp/images' + # end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url(*args) + # # For Rails 3.1+ asset pipeline compatibility: + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process scale: [200, 300] + process :resize_to_fit => [200, 150] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + # version :thumb do + # process resize_to_fit: [50, 50] + # end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + def extension_whitelist + %w(jpg jpeg gif png) + end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end \ No newline at end of file diff --git a/app/views/crm/customers/_new_form.html.erb b/app/views/crm/customers/_new_form.html.erb index 2359ad57..3a953e81 100755 --- a/app/views/crm/customers/_new_form.html.erb +++ b/app/views/crm/customers/_new_form.html.erb @@ -90,6 +90,21 @@ <%= f.text_field :date_of_birth, :value=>"01-01-1990",:class=>"datepicker form-control col-md-12"%>
+ +
+ +
+ + <%= f.file_field :image_path, :class => "img-thumbnail" %> +
+
@@ -164,6 +179,7 @@
\ No newline at end of file diff --git a/app/views/settings/commissioners/_form.html.erb b/app/views/settings/commissioners/_form.html.erb index a337e47b..1d0823a5 100755 --- a/app/views/settings/commissioners/_form.html.erb +++ b/app/views/settings/commissioners/_form.html.erb @@ -1,11 +1,27 @@
-
+
<%= simple_form_for([:settings, @commissioner]) do |f| %> <%= f.error_notification %> -
+
<%= f.input :name %> + + +
+
+ + <%= f.file_field :image_path, :class => "img-thumbnail" %> +
+
+ <%= f.label :emp_id, 'Employee' %> <%= f.collection_select :emp_id, Employee.all.order('name asc'), :id, :name, {prompt: 'Select an Employee'}, {class: "form-control"} %> @@ -29,7 +45,7 @@
-
+
view_headline <%= t("views.right_panel.header.page_detail") %>
diff --git a/app/views/settings/commissioners/show.html.erb b/app/views/settings/commissioners/show.html.erb index 49c7f2de..b9df0967 100755 --- a/app/views/settings/commissioners/show.html.erb +++ b/app/views/settings/commissioners/show.html.erb @@ -33,6 +33,10 @@ <%= t("views.right_panel.detail.name") %> <%= @commissioner.name %> + + <%= t("views.right_panel.detail.commissioner_photo") %> + <%= image_tag @commissioner.image_path, :size => '200x200'%> + <%= t("views.right_panel.detail.employee") %> <%= t("views.right_panel.detail.name") %> <%= @commissioner.employee.name rescue '-' %> diff --git a/app/views/settings/employees/_form.html.erb b/app/views/settings/employees/_form.html.erb index 5d5fcb04..0b973416 100755 --- a/app/views/settings/employees/_form.html.erb +++ b/app/views/settings/employees/_form.html.erb @@ -12,6 +12,22 @@ <%= f.input :password %>
+
+ +
+
+ + <%= f.file_field :image_path, :class => "img-thumbnail" %> +
+
+
<%= f.submit t('views.btn.submit'),:class => 'btn btn-primary btn-lg waves-effect' %> diff --git a/app/views/settings/employees/show.html.erb b/app/views/settings/employees/show.html.erb index 0b26b1bf..0e57b032 100755 --- a/app/views/settings/employees/show.html.erb +++ b/app/views/settings/employees/show.html.erb @@ -44,6 +44,10 @@ <%= t("views.right_panel.detail.updated_at") %> <%= @employee.updated_at.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") %> + + <%= t("views.right_panel.detail.employee_photo") %> + <%= image_tag @employee.image_path, :size => '200x200'%> + From f7de959c78548a6ff61bee17f4b248629ad7306b Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 9 Mar 2018 14:23:48 +0630 Subject: [PATCH 015/108] add receipt in .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8489e37c..b404db53 100755 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ capybara-*.html /public/assets/* /public/uploads/* /public/swf/* +/public/receipts /coverage/ /spec/tmp/* *.orig From f051022ab444554be431fd3e056f53ea5df88a05 Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 12 Mar 2018 17:50:51 +0630 Subject: [PATCH 016/108] check reload issue --- app/views/origami/payments/show.html.erb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 8c7ac778..26bd24af 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -609,7 +609,7 @@ var customer_name = "<%= @customer.name %>"; $("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1))); <% end %> } - customer_display_view(null,"reload"); + //PDF lightbox data // if($('#balance').text() < 0){ // swal({ @@ -969,11 +969,12 @@ var customer_name = "<%= @customer.name %>"; data: params, success:function(result){ console.log(result); - if (cashier_type=="cashier") { - window.location.href = '/origami'; - }else{ - window.location.href = '/origami/quick_service'; - } + customer_display_view(null,"reload"); + // if (cashier_type=="cashier") { + // window.location.href = '/origami'; + // }else{ + // window.location.href = '/origami/quick_service'; + // } } }); // } From 5b99a8cf650959911cb867fec82061e16ab80ca3 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 13 Mar 2018 10:26:18 +0630 Subject: [PATCH 017/108] update reload second display --- app/assets/javascripts/addorder.js | 18 ++++++++++-------- .../channels/second_display_view.js | 10 +++++----- .../origami/second_display/index.html.erb | 8 ++++++++ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 1ddde0e4..32054b53 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -776,17 +776,17 @@ $(function() { e.preventDefault(); $("#oqs_loading_wrapper").show(); - type = window.location.href.indexOf("quick_service"); - if (type != -1) { + quick_service = window.location.href.indexOf("quick_service"); + if (quick_service != -1) { type = 'quick_service' - var table_type = $('#table_type').text(); + var table_type = $('#table_type').text(); var table_id = $('#table_id').val(); var customer_id = $('#customer_id').val(); var booking_id = $('#booking_id').text(); var ajax_url = 'addorders/create'; }else{ type = 'cashier' - var table_type = $('#table_type').text(); + var table_type = $('#table_type').text(); var table_id = $('#table_id').text(); var customer_id = $('#customer_id').text(); var booking_id = $('#booking_id').text(); @@ -813,17 +813,19 @@ $(function() { data: params, dataType: "json", success:function(result){ - customer_display_view(null,"reload"); + console.log(type) + console.log(table_type) if (type == "quick_service") { - window.location.href = "/origami/quick_service" + window.location.href = "/origami/quick_service" }else{ if(table_type == "Table"){ - window.location.href = "/origami/table/" + table_id + window.location.href = "/origami/table/" + table_id } else { - window.location.href = "/origami/room/" + table_id + window.location.href = "/origami/room/" + table_id } } + customer_display_view(null,"reload"); } }); // }else{ diff --git a/app/assets/javascripts/channels/second_display_view.js b/app/assets/javascripts/channels/second_display_view.js index 00d4904c..c6ac124c 100644 --- a/app/assets/javascripts/channels/second_display_view.js +++ b/app/assets/javascripts/channels/second_display_view.js @@ -10,10 +10,12 @@ App.checkin = App.cable.subscriptions.create('SecondDisplayViewChannel', { var tax = data.tax_profiles; var status= data.status if (status == "reload") { - window.location.reload(); + jQuery('#s_reload').click(); } - $('#second_display_slider').addClass("hidden") - $('#second_display_items').removeClass("hidden") + $('#second_display_slider').addClass("hidden") + $('#second_display_items').removeClass("hidden") + + // append items if (status == "add") { for(var i in items) { @@ -84,8 +86,6 @@ App.checkin = App.cable.subscriptions.create('SecondDisplayViewChannel', { var attribute_arr = []; var rowCount = $('.second_display_items tbody tr').length+1; for(var i in items) { - - code = items[i].code; item_code = items[i].item_code; name = items[i].name; diff --git a/app/views/origami/second_display/index.html.erb b/app/views/origami/second_display/index.html.erb index ea97b891..1973363c 100644 --- a/app/views/origami/second_display/index.html.erb +++ b/app/views/origami/second_display/index.html.erb @@ -1,4 +1,5 @@
+
<%= render 'slider' %>
@@ -7,5 +8,12 @@ <%= render 'second_display' %>
+ From 30bfb060df261f96a05e10edc53cefb759538f2f Mon Sep 17 00:00:00 2001 From: phyusin Date: Tue, 13 Mar 2018 10:58:06 +0630 Subject: [PATCH 018/108] check payment and ability for split bill --- app/models/ability.rb | 10 ++++++++ app/views/origami/payments/show.html.erb | 29 ++++++++++++------------ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 95c6005f..de43d71f 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -93,6 +93,11 @@ class Ability can :index, :home can :show, :home + #ability for split_bill + can :index, :split_bill + can :create, :split_bill + can :update_sale, :split_bill + elsif user.role == "cashier" # can :overall_void, :void @@ -191,6 +196,11 @@ class Ability can :index, :home can :show, :home + + #ability for split_bill + can :index, :split_bill + can :create, :split_bill + can :update_sale, :split_bill elsif user.role == "waiter" can :index, :home can :show, :home diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 26bd24af..ee006c3a 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -914,14 +914,15 @@ var customer_name = "<%= @customer.name %>"; function customer_display_view(data,status) { $.ajax({ - type: "POST", - url: '../../../customer_view', - data: {"data":data,"status":status}, - dataType: "json", - success:function(result){ - } - }); - } + type: "POST", + url: '../../../customer_view', + data: {"data":data,"status":status}, + dataType: "json", + success:function(result){ + } + }); + } + function calculate_member_discount(sale_id) { var sub_total = $('#sub-total').text(); var member_id = $('#membership_id').text(); @@ -969,12 +970,12 @@ var customer_name = "<%= @customer.name %>"; data: params, success:function(result){ console.log(result); - customer_display_view(null,"reload"); - // if (cashier_type=="cashier") { - // window.location.href = '/origami'; - // }else{ - // window.location.href = '/origami/quick_service'; - // } + if (cashier_type=="cashier") { + window.location.href = '/origami'; + }else{ + window.location.href = '/origami/quick_service'; + customer_display_view(null,"reload"); + } } }); // } From df781395c8780bcf9489e1a62b65ac94e1d3b380 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 13 Mar 2018 11:40:05 +0630 Subject: [PATCH 019/108] update oqs and read me --- README.md | 38 +++++++++++------------- app/models/order.rb | 2 +- app/views/oqs/home/index.html.erb | 3 +- config/initializers/action_controller.rb | 10 +++---- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index ee8846a0..b5d2c62b 100755 --- a/README.md +++ b/README.md @@ -8,28 +8,21 @@ Things you may want to cover: ruby 2.4.1p111 * Membership Details +Osaka => + Auth Token => wu8YvlLmah0CL => New => v3 + => rj0MJ0XI5GsKZehE => Old => v + => code2lab => Old - Osaka + Merchant account => RxzaYyAGzm7VqAZ4hKnv + Campaign Id => {"campaign_type_id": 5} - Auth Token => wu8YvlLmah0CL => New ##note : Old => rj0MJ0XI5GsKZehE +BITP + Auth Token => pZBHXEFbGNj/G => New => V3 + => rj0MJ0XI5GsKZehE => Old => V2 + => code2lab => Old - => code2lab => Old - - Merchant account => RxzaYyAGzm7VqAZ4hKnv - - Campaign Id => {"campaign_type_id": 5} - - - - BITP - - Auth Token => pZBHXEFbGNj/G => New ##note : Old => rj0MJ0XI5GsKZehE - - => code2lab => Old - - Merchant account => vWSsseoZCzxd6xcNf_uS - - Campaign Id => {"campaign_type_id": 1} + Merchant account => vWSsseoZCzxd6xcNf_uS + Campaign Id => {"campaign_type_id": 1} java -jar ~/Documents/Jade.jar http://192.168.1.88:3002 @@ -105,7 +98,12 @@ Change type in mysql For split bill 1) settings/lookups => { type:split_bill, name:SplitBill, value:1 } - + +For Sidekiq + 1) If you want to use sidekiq + => Create New Lookups => lookup_type = sidekiq, Name = sidekiq , Value = 1 or 0 + +For Check CUp status ###please open sudo cat /etc/sudoers ### cope and parse diff --git a/app/models/order.rb b/app/models/order.rb index 3f8ce21a..1508c960 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -290,7 +290,7 @@ class Order < ApplicationRecord cup_status = `#{"sudo service cups status"}` print_status = check_cup_status(cup_status) sidekiq = Lookup.find_by_lookup_type("sidekiq") - + if print_status if !sidekiq.nil? OrderQueueProcessorJob.perform_later(self.id, self.table_id) diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 585f9968..ee73d560 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -1,5 +1,5 @@ -
+
@@ -20,7 +20,6 @@
- + - - + +
<% end %>
@@ -145,7 +145,8 @@ $(function() { $("#qr_code").on('click', function(e){ var code = ""; setTimeout(function(){ - var hi=getQRCode(); + code=getQRCode(); + setQRCode(code); },100); }); diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index 50673b5f..aee947c7 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -228,16 +228,15 @@ <% else %>
<% end %> + <% if !@total_customer.nil? && @total_customer.to_i > 0 %>
<%= t :customer %>
- <% if !@total_customer.nil? %> - <% end %> <% if !@total_dinein.nil? %> @@ -265,6 +264,7 @@
<%= t("views.right_panel.detail.total") %> <%= t :customer %> : <%= @total_customer %>
<%= t("views.right_panel.detail.dine_in") %> :
+ <% end %>
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
@@ -316,9 +316,10 @@
-
-
-
+
+ <% if current_user.role == 'administrator' || current_user.role == 'manager' %> +
+ <% end %> <% end %>
diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 15dfdfbe..e3e7adda 100755 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -16,7 +16,11 @@ <%if current_login_employee.role !="waiter" %> - + <% if current_login_employee.role != "cashier" %> + + <% else %> + + <% end %> <% else %> <%end%> @@ -56,13 +60,11 @@ <% end %>
  • - - -

    +

    exit_to_app Logout

    @@ -79,9 +81,39 @@
  • + \ No newline at end of file diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb old mode 100755 new mode 100644 index 33ee74b7..585f9968 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -1,137 +1,115 @@ -
    -
    +
    +
    - <%= form_tag oqs_root_path, :method => :get do %>
    - - + +
    -
    - +
    + +
    - +
    - <% end %>
    - - -
    - - - -
    - - + + +
    +
    +
    -
    +
    <% @queue_completed_item.each do |qid| %>
    -
    - <%if qid.type.present?%> - <%= qid.type %>-<%= qid.zone %> - <%else%> - - <%end%> - - - <%= qid.order_id %> -
    -

    - - <%= qid.item_name %> - [x - - <%= qid.qty %> - ] - <% if !qid.set_menu_items.nil? %> - <% qid.set_menu_items.each do |item_instance|%> -
    - <%= item_instance %> - - <% end %> - <% end %> -

    - -

    <%= qid.options == "[]"? "" : qid.options %>

    +
    + <%if qid.type.present?%> + <%= qid.type %>-<%= qid.zone %> + <%else%> + + <%end%> - - Order at - - - <%= qid.created_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") %> -
    - Order By - - <%= qid.item_order_by %> - + + <%= qid.order_id %> +
    +

    + + <%= qid.item_name %> + [x + + <%= qid.qty %> + ] + <% if !qid.set_menu_items.nil? %> + <% qid.set_menu_items.each do |item_instance|%> +
    + <%= item_instance %> + + <% end %> + <% end %> +

    + +

    <%= qid.options == "[]"? "" : qid.options %>

    + + + Order at - + + <%= qid.created_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") %> +
    + Order By - + <%= qid.item_order_by %> + +
    - - +
    -
    - <% - end - %> +
    + <% end %>
    -
    +
    - - -
    -
    +
    +
    +
    -
    + - - - + --> + +
    - + -->
    +
    reply Back <% if ENV["SERVER_MODE"] != "cloud" %> +
    + +
    + <% end %> +
    + + + + + + +
    + + +
    +
    + <% + @queue_completed_item.each do |qid| + %> +
    +
    +
    + <%if qid.type.present?%> + <%= qid.type %>-<%= qid.zone %> + <%else%> + + <%end%> + + + <%= qid.order_id %> +
    +

    + + <%= qid.item_name %> + [x + + <%= qid.qty %> + ] + <% if !qid.set_menu_items.nil? %> + <% qid.set_menu_items.each do |item_instance|%> +
    + <%= item_instance %> + + <% end %> + <% end %> +

    + +

    <%= qid.options == "[]"? "" : qid.options %>

    + + + Order at - + + <%= qid.created_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") %> +
    + Order By - + <%= qid.item_order_by %> + +
    +
    + + + + +
    +
    + <% + end + %> +
    +
    + + + + +
    +
    + +
    +
    + + +
    +
    +
    +
    ORDER DETAILS
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + +
    Order ByOrder At
    +
    +
    + + + + + + + + + + +
    ItemsQTY
    +
    +
    +
    +
    + + +
    + + reply Back + <% if ENV["SERVER_MODE"] != "cloud" %> + + <%end%> +
    +
    + + diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index eebaabbf..87ff1144 100755 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -34,12 +34,14 @@
    -
    - -
    + + + + + <% end %> @@ -114,6 +116,8 @@ + + <%if !@dining_facility.nil?%> @@ -262,7 +266,8 @@ \ No newline at end of file diff --git a/app/views/origami/pending_order/show.html.erb b/app/views/origami/pending_order/show.html.erb index d94a81d5..fade7ccb 100644 --- a/app/views/origami/pending_order/show.html.erb +++ b/app/views/origami/pending_order/show.html.erb @@ -153,6 +153,14 @@ <% if current_user.role != "waiter" || @status != "sale"%> <%end%> + <% if current_user.role != "waiter" && @status != "order"%> <%end%> @@ -163,6 +171,7 @@ diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 4cd6a846..1edb07cf 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -50,11 +50,11 @@ <% end %>
    <%= table.name %> - <% if !@order_items_count.nil? %> + billed
    @@ -66,11 +66,11 @@ <% end %>
    <%= table.name %> - <% if !@order_items_count.nil? %> + new
    @@ -97,11 +97,11 @@
    <%= room.name %> - <% if !@order_items_count.nil? %> + billed
    @@ -110,11 +110,11 @@
    <%= room.name %> - <% if !@order_items_count.nil? %> + new
    @@ -193,12 +193,15 @@
    <% if @status_sale == 'sale' %> -
    +
      Receipt No: <%= @obj_sale.receipt_no rescue '' %>
    +
    + Date: <%= @date.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%> +
    <% else %>
      Order No: @@ -206,17 +209,10 @@ <%= @obj_order.order_id rescue '' %>
    - <% end %> - <% if @status_sale == 'sale' %> -
    - Date: <%= @date.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%> -
    - <% else %> -
    +
    Date: <%= @date.utc.getlocal.strftime("%d/%m/%Y") rescue '-'%>
    <% end %> -
    @@ -396,10 +392,7 @@ - <% if current_login_employee.role == "administrator" || current_login_employee.role == "manager" || current_login_employee.role == "supervisor" || current_login_employee.role == "cashier" || current_login_employee.role == "waiter" %> - <% end %> - <% if current_login_employee.role != "waiter" %> <% if @room.bookings.length >= 1 %> <% if @status_order == 'order' && @status_sale != 'sale' %> @@ -423,14 +416,14 @@ <% if current_login_employee.role != "waiter" %> + + @@ -485,11 +478,11 @@ <% end %> <% end %> - <% end %>
    diff --git a/config/routes.rb b/config/routes.rb index 6a4c403d..17b3bb0c 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -165,6 +165,7 @@ scope "(:locale)", locale: /en|mm/ do post 'sale/:sale_id/rounding_adj' => 'payments#rounding_adj', :as => "calculate_rouding_adjs" get 'sale/:sale_id/first_bill' => 'payments#first_bill', :defaults => {:format => 'json'} get 'sale/:sale_id/:type/payment' => 'payments#show' + post 'sale/:sale_id/:type/payment/print' => 'payments#print' #route for print receipt post 'payment/foc' => 'payments#foc', :defaults => {:format => 'json'} post 'payment/cash' => 'payments#create' @@ -198,9 +199,9 @@ scope "(:locale)", locale: /en|mm/ do #---------Add Customer --------------# #resources :customers - get '/:sale_id/:type/customers', to: "customers#add_customer" + get '/:sale_id/:type/customers/:page', to: "customers#add_customer" get '/:customer_id/get_customer' => 'home#get_customer', :as => "show_customer_details" - post '/:sale_id/:type/update_sale', to: "customers#update_sale_by_customer" # update customer id in sale table + post '/:sale_id/:type/customers/update_sale', to: "customers#update_sale_by_customer" # update customer id in sale table post '/:sale_id/get_customer' => "customers#get_customer" diff --git a/db/migrate/20170530072247_create_shops.rb b/db/migrate/20170530072247_create_shops.rb index bd25c970..1c87b505 100755 --- a/db/migrate/20170530072247_create_shops.rb +++ b/db/migrate/20170530072247_create_shops.rb @@ -3,6 +3,9 @@ class CreateShops < ActiveRecord::Migration[5.1] create_table :shops do |t| t.string :logo t.string :name, :null => false + t.string :shop_code, :null => false + t.string :client_name, :null => false + t.string :client_code, :null => false t.string :address, :null => false t.string :township, :null => false t.string :city, :null => false diff --git a/db/migrate/20170628103624_create_print_settings.rb b/db/migrate/20170628103624_create_print_settings.rb index 329d3a7c..672953fc 100755 --- a/db/migrate/20170628103624_create_print_settings.rb +++ b/db/migrate/20170628103624_create_print_settings.rb @@ -6,7 +6,9 @@ class CreatePrintSettings < ActiveRecord::Migration[5.1] t.string :template t.string :font, :default => "" t.string :printer_name, :null => false - t.string :api_settings + t.string :api_settings, + t.string :brand_name + t.string :type t.decimal :page_width, :null => false, :default => 210 t.decimal :page_height, :null => false, :default => 1450 t.integer :print_copies, :null => false, :default => 1 diff --git a/db/migrate/20180306044939_create_receipts.rb b/db/migrate/20180306044939_create_receipts.rb new file mode 100644 index 00000000..22f3b0fa --- /dev/null +++ b/db/migrate/20180306044939_create_receipts.rb @@ -0,0 +1,42 @@ +class CreateReceipts < ActiveRecord::Migration[5.1] + def change + create_table :receipts do |t| + t.string :client_code, :limit => 16, :null => false + t.string :client_name, :null => false + t.string :shop_code, :limit => 16, :null => false + t.string :shop_name, :null => false + t.integer :receipt_no, :limit => 8, :null => false + t.datetime :transaction_time, :null => false + t.datetime :receipt_open_time, :null => false + t.datetime :receipt_close_time, :null => false + t.decimal :gross_sales, :null => false, :default => 0 + t.decimal :discount_amount, :null => false, :default => 0 + t.decimal :sales, :null => false, :default => 0 + t.decimal :tax_amount, :null => false, :default => 0 + t.decimal :service_charges, :null => false, :default => 0 + t.decimal :net_sales, :null => false, :default => 0 + t.decimal :credit_card_sales, :null => false, :default => 0 + t.decimal :voucher_sales, :null => false, :default => 0 + t.decimal :foc_amount, :null => false, :default => 0 + t.decimal :staff_meal_amount, :null => false, :default => 0 + t.decimal :rounding_amount, :null => false, :default => 0 + t.decimal :raw_wastage_amount, :null => false, :default => 0 + t.decimal :semi_wastage_amount, :null => false, :default => 0 + t.decimal :wastage_amount, :null => false, :default => 0 + t.decimal :spoilage_amount, :null => false, :default => 0 + t.decimal :sampling_amount, :null => false, :default => 0 + t.integer :qty, :null => false, :default => 0 + t.integer :no_of_pax, :null => false, :default => 0 + t.integer :no_of_adult, :null => false, :default => 0 + t.integer :no_of_child, :null => false, :default => 0 + t.string :terminal_id, :null => false + t.string :employee_code, :limit => 4, :null => false + t.string :employee_name, :null => false + t.boolean :is_valid, :null => false, :default => false + t.boolean :overing, :null => false, :default => false + t.boolean :cancle, :null => false, :default => false + t.text :remarks + t.timestamps + end + end +end diff --git a/db/migrate/20180306045018_create_receipt_details.rb b/db/migrate/20180306045018_create_receipt_details.rb new file mode 100644 index 00000000..5fd38160 --- /dev/null +++ b/db/migrate/20180306045018_create_receipt_details.rb @@ -0,0 +1,43 @@ +class CreateReceiptDetails < ActiveRecord::Migration[5.1] + def change + create_table :receipt_details do |t| + t.string :client_code, :null => false + t.string :client_name, :null => false + t.string :shop_code, :null => false + t.string :shop_name, :null => false + t.string :receipt_no, :null => false + t.datetime :receipt_date, :null => false + t.datetime :transaction_date, :null => false + t.integer :item_sequence, :null => false + t.string :category_code, :null => false + t.string :category_name, :null => false + t.string :sub_category_code, :null => false + t.string :sub_category_name, :null => false + t.string :report_group_code, :null => false + t.string :report_group_name, :null => false + t.string :item_code, :null => false + t.string :item_name, :null => false + t.integer :qty, :null => false, :default => 0 + t.string :transaction_type, :null => false + t.decimal :gross_sales, :null => false, :default => 0 + t.string :discount_code, :null => false + t.decimal :discount_amount, :null => false, :default => 0 + t.decimal :sales, :null => false, :default => 0 + t.decimal :tax_amount, :null => false, :default => 0 + t.decimal :service_charges, :null => false, :default => 0 + t.decimal :net_sales, :null => false, :default => 0 + t.boolean :is_foc, :null => false, :default => false + t.boolean :is_set_item, :null => false, :default => false + t.boolean :is_staff_meal, :null => false, :default => false + t.boolean :is_raw_wastage, :null => false, :default => false + t.boolean :is_semi_wastage, :null => false, :default => false + t.boolean :is_wastage, :null => false, :default => false + t.boolean :is_spoilage, :null => false, :default => false + t.boolean :is_sampling, :null => false, :default => false + t.boolean :tax_able, :null => false, :default => false + t.boolean :is_void, :null => false, :default => false + t.text :remarks + t.timestamps + end + end +end \ No newline at end of file diff --git a/db/sym_master.sql b/db/sym_master.sql index 89abaf5b..3677fc2f 100755 --- a/db/sym_master.sql +++ b/db/sym_master.sql @@ -88,6 +88,10 @@ delete from sym_node; insert into sym_node_group_link (source_node_group_id, target_node_group_id, data_event_action) values ('cloud', 'sx', 'P'); # Create Trigger for Setting Channel + + insert into sym_trigger + (trigger_id,source_table_name,channel_id,last_update_time,create_time) + values('seed_generators','seed_generators','setting',current_timestamp,current_timestamp); insert into sym_trigger (trigger_id,source_table_name,channel_id,last_update_time,create_time) @@ -119,11 +123,11 @@ delete from sym_node; insert into sym_trigger (trigger_id,source_table_name,channel_id,last_update_time,create_time) - values('tax_profiles','customers','setting',current_timestamp,current_timestamp); + values('tax_profiles','tax_profiles','setting',current_timestamp,current_timestamp); insert into sym_trigger (trigger_id,source_table_name,channel_id,last_update_time,create_time) - values('display_images','customers','setting',current_timestamp,current_timestamp); + values('display_images','display_images','setting',current_timestamp,current_timestamp); # Create Trigger for Dining Channel @@ -339,6 +343,11 @@ delete from sym_node; # Add triggers for tables with router # Setting Channel # From cloud to Master + + insert into sym_trigger_router + (trigger_id,router_id,initial_load_order,last_update_time,create_time) + values('seed_generators','cloud_2_sx', 100, current_timestamp, current_timestamp); + insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) values('lookups','cloud_2_sx', 100, current_timestamp, current_timestamp); @@ -376,6 +385,11 @@ delete from sym_node; values('display_images','cloud_2_sx', 100, current_timestamp, current_timestamp); # Setting Channel # From Master to cloud + + insert into sym_trigger_router + (trigger_id,router_id,initial_load_order,last_update_time,create_time) + values('seed_generators','sx_2_cloud', 100, current_timestamp, current_timestamp); + insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) values('lookups','sx_2_cloud', 100, current_timestamp, current_timestamp); diff --git a/lib/tasks/clear_data.rake b/lib/tasks/clear_data.rake index 17dcde74..43ba291e 100755 --- a/lib/tasks/clear_data.rake +++ b/lib/tasks/clear_data.rake @@ -17,6 +17,7 @@ namespace :clear do Survey.delete_all DiningFacility.update_all(status:'available') CashierTerminal.update_all(is_currently_login: 0) + SeedGenerator.where("id > 1").update(:current => 0, :next => 1) puts "Clear Data Done." end end diff --git a/lib/tasks/receipt.rake b/lib/tasks/receipt.rake new file mode 100644 index 00000000..fa24f481 --- /dev/null +++ b/lib/tasks/receipt.rake @@ -0,0 +1,238 @@ +namespace :consolidate do + desc "Receipt" + task :receipt => :environment do + Receipt.delete_all + sales = Sale.all_receipts + + shop = Shop.find(1) + sales.each do |sale| + receipt = Receipt.new + receipt.client_code = shop.id + receipt.client_name = shop.id + receipt.shop_code = shop.id + receipt.shop_name = shop.id + receipt.receipt_no = sale.receipt_no + receipt.transaction_time = sale.requested_at #requet-at + receipt.receipt_open_time = sale.requested_at #before disco/after tax /after/ser_char + receipt.receipt_close_time = sale.receipt_close_time + receipt.gross_sales = sale.total_amount + sale.total_tax #before disco/after tax /after/ser_char + receipt.discount_amount = sale.total_discount + sale.item_discount + receipt.sales = sale.grand_total #after disco/after tax /after/ser_char /no roundingadn + receipt.tax_amount = sale.total_tax + receipt.service_charges = sale.service_charges + receipt.net_sales = sale.total_amount + sale.total_discount #after disco/before tax / no rounding + receipt.credit_card_sales = sale.mpu_amount + sale.master_amount + sale.visa_amount + sale.jcb_amount + sale.unionpay_amount + sale.credit_amount # + receipt.voucher_sales = 0 + receipt.foc_amount = sale.foc_amount + sale.item_foc + receipt.staff_meal_amount = 0 + receipt.rounding_amount = sale.rounding_adjustment + receipt.raw_wastage_amount = 0 + receipt.semi_wastage_amount = 0 + receipt.wastage_amount = 0 + receipt.spoilage_amount = 0 + receipt.sampling_amount = 0 + receipt.qty = sale.qty + receipt.no_of_pax = 0 + receipt.no_of_adult = (sale.adult) ? sale.adult : 0 + receipt.no_of_child = (sale.child) ? sale.child : 0 + receipt.terminal_id = ShiftSale.find(sale.shift_sale_id).cashier_terminal_id + receipt.employee_code = Employee.find(sale.cashier_id).emp_id + receipt.employee_name = sale.cashier_name + receipt.is_valid = (sale.payment_status=="void") ? false : true #void is false + receipt.overing =false + receipt.cancle = (sale.payment_status=="void") ? false : true # void is cancel + receipt.remarks = sale.remark + receipt.save + end + end + + desc "Receipt Detail" + task :receipt_detail => :environment do + ReceiptDetail.delete_all + sales = Sale.all_receipt_details + + shop = Shop.find(1) + + sale_id = '' + count = 0 + @total_qty = 0 + @total_gross_sales = 0 + @total_sales = 0 + @total_net_sales = 0 +@z =1 + @item_sequence = 1 + sale_count = sales.to_a.count + sales.each do |sale| + + if sale.qty > 0 + + if sale.item_instance_code !=nil + menu_category = MenuCategory.find(MenuItem.find_by_item_code(sale.product_code).menu_category_id) + name = menu_category.name + code = menu_category.code + menu_item = MenuItem.find_by_item_code(sale.product_code) + menu_name = menu_item.name + menu_code = menu_item.item_code + menu_type = menu_item.type + end + if sale.product_code == "Other Charges" && sale.status == "Other Charges" + code = sale.product_code + name = sale.product_code + menu_name = sale.product_code + menu_code = sale.product_code + menu_type = sale.product_code + end + + @receipt_no = sale.receipt_no + @requested_at = sale.requested_at + + if sale_id == sale.sale_id || count == 0 || @z ==0 + @total_qty += sale.qty + @total_gross_sales += sale.price + @total_sales += sale.price + @total_net_sales += sale.taxable_price + end + + if sale_id != sale.sale_id && count !=0 + + receipt = ReceiptDetail.new + receipt.client_code = shop.id + receipt.client_name = shop.id + receipt.shop_code = shop.id + receipt.shop_name = shop.id + receipt.receipt_no = @receipt_no + receipt.receipt_date = @requested_at #requet-at + receipt.transaction_date = @requested_at #before disco/after tax /after/ser_char + receipt.item_sequence = @item_sequence + receipt.category_code = '' + receipt.category_name = '' + receipt.sub_category_code = 0 + receipt.sub_category_name = 0 + receipt.report_group_code = 0 + receipt.report_group_name = 0 + receipt.item_code = '' + receipt.item_name = '' + receipt.qty = @total_qty + receipt.transaction_type = "Tender" + receipt.gross_sales = @total_gross_sales + receipt.discount_code = '' + receipt.discount_amount = 0 + receipt.sales = @total_sales + receipt.tax_amount = 0 + receipt.service_charges = 0 + receipt.net_sales = @total_net_sales + receipt.is_set_item = false + receipt.is_foc = false + receipt.is_staff_meal = false + receipt.is_raw_wastage = false + receipt.is_semi_wastage = false + receipt.is_wastage = false + receipt.is_spoilage = false + receipt.is_sampling = false + receipt.tax_able = false + receipt.is_void = false + receipt.remarks = "" + receipt.save + @type = "Tender" + @item_sequence = 1 + @total_qty = 0 + @total_gross_sales = 0 + @total_sales = 0 + @total_net_sales = 0 + @z = 0 + end + + + discount_amount = (sale.status=="Discount") ? sale.price : 0 + receipt = ReceiptDetail.new + receipt.client_code = shop.id + receipt.client_name = shop.id + receipt.shop_code = shop.id + receipt.shop_name = shop.id + receipt.receipt_no = sale.receipt_no + receipt.receipt_date = sale.requested_at #requet-at + receipt.transaction_date = sale.requested_at #before disco/after tax /after/ser_char + receipt.item_sequence = @item_sequence + receipt.category_code = name + receipt.category_name = code + receipt.sub_category_code = 0 + receipt.sub_category_name = 0 + receipt.report_group_code = 0 + receipt.report_group_name = 0 + receipt.item_code = menu_name + receipt.item_name = menu_code + receipt.qty = sale.qty + receipt.transaction_type = (sale.status==nil) ? "Sales" : sale.status + receipt.gross_sales = sale.price + receipt.discount_code = sale.sale_item_id + receipt.discount_amount = discount_amount + receipt.sales = sale.price + receipt.tax_amount = 0 + receipt.service_charges = 0 + receipt.net_sales = sale.taxable_price + receipt.is_set_item = (menu_type=="SetMenuItem")? true : false + receipt.is_foc = (sale.status=="foc") ? true : false + receipt.is_staff_meal = false + receipt.is_raw_wastage = false + receipt.is_semi_wastage = false + receipt.is_wastage = false + receipt.is_spoilage = false + receipt.is_sampling = false + receipt.tax_able = sale.is_taxable + receipt.is_void = (sale.status=="void")? true : false + receipt.remarks = sale.remark + receipt.save + + end + + @z += 1 + + + count += 1 + @item_sequence += 1 + sale_id = sale.sale_id + end + + if count == sale_count + receipt = ReceiptDetail.new + receipt.client_code = shop.id + receipt.client_name = shop.id + receipt.shop_code = shop.id + receipt.shop_name = shop.id + receipt.receipt_no = @receipt_no + receipt.receipt_date = @requested_at #requet-at + receipt.transaction_date = @requested_at #before disco/after tax /after/ser_char + receipt.item_sequence = @item_sequence + receipt.category_code = '' + receipt.category_name = '' + receipt.sub_category_code = 0 + receipt.sub_category_name = 0 + receipt.report_group_code = 0 + receipt.report_group_name = 0 + receipt.item_code = '' + receipt.item_name = '' + receipt.qty = @total_qty + receipt.transaction_type = "Tender" + receipt.gross_sales = @total_gross_sales + receipt.discount_code = '' + receipt.discount_amount = 0 + receipt.sales = @total_sales + receipt.tax_amount = 0 + receipt.service_charges = 0 + receipt.net_sales = @total_net_sales + receipt.is_set_item = false + receipt.is_foc = false + receipt.is_staff_meal = false + receipt.is_raw_wastage = false + receipt.is_semi_wastage = false + receipt.is_wastage = false + receipt.is_spoilage = false + receipt.is_sampling = false + receipt.tax_able = false + receipt.is_void = false + receipt.remarks = "" + receipt.save + end + end + +end \ No newline at end of file diff --git a/spec/models/receipt_detail_spec.rb b/spec/models/receipt_detail_spec.rb new file mode 100644 index 00000000..017ee888 --- /dev/null +++ b/spec/models/receipt_detail_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ReceiptDetail, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/receipt_spec.rb b/spec/models/receipt_spec.rb new file mode 100644 index 00000000..3b140805 --- /dev/null +++ b/spec/models/receipt_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Receipt, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From bf1b7ecb561334405c8601bdeb9206965604ea8b Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 13 Mar 2018 14:59:23 +0630 Subject: [PATCH 026/108] update payment controller if member --- app/controllers/origami/payments_controller.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 79c084a6..4508c582 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -152,17 +152,10 @@ class Origami::PaymentsController < BaseOrigamiController if customer.membership_id != nil && rebate && credit_data.nil? member_info = Customer.get_member_account(customer) - puts member_info["status"] if member_info["status"] == true rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no) current_balance = SaleAudit.paymal_search(sale_id) - else - rebate_amount = 0 - current_balance = 0 - member_info =nil end - # rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no) - # current_balance = SaleAudit.paymal_search(sale_id) end #for card sale data From 44389d485a4ac3ec4866e7546f523ed51b129eea Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 13 Mar 2018 17:38:25 +0630 Subject: [PATCH 027/108] update request bill reload in quick service --- app/controllers/origami/request_bills_controller.rb | 8 +++++--- app/views/origami/pending_order/show.html.erb | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 409177fe..f6dd4e14 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -8,9 +8,7 @@ class Origami::RequestBillsController < ApplicationController if !ShiftSale.current_shift.nil? order_id = params[:id] # order_id bk_order = BookingOrder.find_by_order_id(order_id) - puts params[:id] - puts bk_order - puts bk_order.booking_id + order = Order.find(order_id) check_booking = Booking.find_by_booking_id(bk_order.booking_id) if check_booking.sale_id.nil? @@ -29,6 +27,10 @@ class Origami::RequestBillsController < ApplicationController # Promotion Activation Promotion.promo_activate(@sale) + if order.source == "quick_service" + result = {:status=> @status, :data => @sale.sale_id } + render :json => result.to_json + end else @status = false @error_message = "No Current Open Shift for This Employee" diff --git a/app/views/origami/pending_order/show.html.erb b/app/views/origami/pending_order/show.html.erb index fade7ccb..d7c929f7 100644 --- a/app/views/origami/pending_order/show.html.erb +++ b/app/views/origami/pending_order/show.html.erb @@ -203,11 +203,12 @@ $(document).ready(function(){ url: ajax_url, // data: 'order_id='+ order_id, success: function (result) { + console.log(result) if (!result.status) { swal("Information!", result.error_message); } else { - location.reload(); + window.location.href = '../pending_order/'+ result.data; } } }); From 84fe089568ad6e81b94af143fdfce3845fe070d6 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Tue, 13 Mar 2018 17:53:04 +0630 Subject: [PATCH 028/108] Active tab in dashboard, Manager Tab, Union Payment --- app/assets/stylesheets/login.scss | 5 ++++ .../origami/unionpay_controller.rb | 1 + app/views/layouts/login_dashboard.html.erb | 29 +++++++++++++++++-- app/views/origami/unionpay/index.html.erb | 1 - 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/login.scss b/app/assets/stylesheets/login.scss index 66252d60..b5f29da6 100755 --- a/app/assets/stylesheets/login.scss +++ b/app/assets/stylesheets/login.scss @@ -8,6 +8,11 @@ background-color: #2790a5; } +.active_tab{ + border-style: solid; + border-color: #2790a5; +} + .login-page { margin: 0% auto; background-color: #2790a5; diff --git a/app/controllers/origami/unionpay_controller.rb b/app/controllers/origami/unionpay_controller.rb index 905a1ffb..707a1022 100644 --- a/app/controllers/origami/unionpay_controller.rb +++ b/app/controllers/origami/unionpay_controller.rb @@ -8,6 +8,7 @@ class Origami::UnionpayController < BaseOrigamiController @unionpaycount = 0 others = 0 + @payment_method_setting_nav = PaymentMethodSetting.all @shop = Shop::ShopDetail if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) diff --git a/app/views/layouts/login_dashboard.html.erb b/app/views/layouts/login_dashboard.html.erb index 54bc8b95..f2f6f958 100755 --- a/app/views/layouts/login_dashboard.html.erb +++ b/app/views/layouts/login_dashboard.html.erb @@ -105,6 +105,14 @@
    +
    @@ -199,7 +201,7 @@
    -
    +
    From a75d3e08df80cdd96d45fe3d8c597a95e551df26 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 23 Mar 2018 16:22:35 +0630 Subject: [PATCH 088/108] update scroll speed --- app/assets/javascripts/custom.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/custom.js b/app/assets/javascripts/custom.js index 7c4c8301..778de553 100644 --- a/app/assets/javascripts/custom.js +++ b/app/assets/javascripts/custom.js @@ -9,7 +9,8 @@ $(document).ready(function() { color: 'rgba(0,0,0,0.5)', alwaysVisible: false, borderRadius: '0', - railBorderRadius: '0' + railBorderRadius: '0', + touchScrollStep : 25 }); $('#order-detail-slimscroll').slimScroll({ @@ -18,7 +19,8 @@ $(document).ready(function() { color: 'rgba(0,0,0,0.5)', alwaysVisible: false, borderRadius: '0', - railBorderRadius: '0' + railBorderRadius: '0', + touchScrollStep : 25 }); $('#menu-slimscroll').slimScroll({ @@ -27,7 +29,8 @@ $(document).ready(function() { color: 'rgba(0,0,0,0.5)', alwaysVisible: false, borderRadius: '0', - railBorderRadius: '0' + railBorderRadius: '0', + touchScrollStep : 25 }); // $('.delete').click(function(){ From 37f80a8ac69542e6193dfab892df0da81a4c1614 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 23 Mar 2018 17:59:28 +0630 Subject: [PATCH 089/108] update sale --- app/models/sale.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index 5fc0c06f..b459f16c 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -799,10 +799,13 @@ def self.get_by_shift_sale(from,to,status) end def self.get_item_query() - query = Sale.select("acc.title as account_name,mi.account_id, i.item_instance_code as item_code,i.account_id as account_id, " + - "SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item,i.qty as qty," + + query = Sale.select("acc.title as account_name,mi.account_id, + i.item_instance_code as item_code,i.account_id as account_id, " + + "SUM(i.qty * i.unit_price) as grand_total, + SUM(i.qty) as total_item,i.qty as qty," + "i.status as status_type,"+ - " i.unit_price,i.price as price,i.product_name as product_name, mc.name as" + + " i.unit_price,i.price as price,i.product_name as product_name, + mc.name as" + " menu_category_name,mc.id as menu_category_id ") query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" + From 2a88bd4409b99e580cd10d4a1812bb18c367015d Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 23 Mar 2018 18:02:41 +0630 Subject: [PATCH 090/108] updae session error --- app/controllers/origami/addorders_controller.rb | 2 +- app/controllers/origami/quick_service_controller.rb | 13 ++++++++++++- app/controllers/origami/request_bills_controller.rb | 8 +++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index f5bb7d37..0e905724 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -1,6 +1,6 @@ class Origami::AddordersController < BaseOrigamiController # before_action :set_dining, only: [:detail] - + def index @tables = Table.all.active.order('zone_id asc').group("zone_id") @rooms = Room.all.active.order('zone_id asc').group("zone_id") diff --git a/app/controllers/origami/quick_service_controller.rb b/app/controllers/origami/quick_service_controller.rb index 44dcfcb8..8abcfcc8 100644 --- a/app/controllers/origami/quick_service_controller.rb +++ b/app/controllers/origami/quick_service_controller.rb @@ -1,6 +1,12 @@ class Origami::QuickServiceController < ApplicationController # before_action :set_dining, only: [:detail] - + before_action :check_user + def check_user + if current_user.nil? + redirect_to root_path + end + end + def index today = DateTime.now day = Date.today.wday @@ -211,6 +217,11 @@ class Origami::QuickServiceController < ApplicationController end end + def check_user + if current_user.nil? + redirect_to root_path + end + end # this can always true def check_order_with_booking(booking) if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new" diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index adfe35a6..e2553a83 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -1,5 +1,11 @@ class Origami::RequestBillsController < ApplicationController - + before_action :check_user + + def check_user + if current_user.nil? + redirect_to root_path + end + end # Print Request Bill and add to sale tables def print @sale = Sale.new From e0fe0ee8ab69dec19a1cb73eac16c30b911d3213 Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 23 Mar 2018 18:06:53 +0630 Subject: [PATCH 091/108] dashboard update --- app/controllers/home_controller.rb | 21 +++++--- app/views/home/dashboard.html.erb | 56 +++++++++++++++++++--- app/views/origami/dashboard/index.html.erb | 4 +- config/locales/en.yml | 2 + config/locales/mm.yml | 2 + 5 files changed, 70 insertions(+), 15 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index f097ba6f..da8695d8 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -80,14 +80,21 @@ class HomeController < ApplicationController end def dashboard - @from, @to = get_date_range_from_params + @from, @to, @from_time, @to_time = get_date_range_from_params @shop = Shop.first today = DateTime.now.strftime('%Y-%m-%d') - @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() - @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() - + if !@from.nil? && !@to.nil? + @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() + else + @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() + end + if !@from.nil? && !@to.nil? + @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() + else + @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() + end @top_products = Sale.top_products(today,@from,@to).sum('i.qty') @bottom_products = Sale.bottom_products(today,@from,@to).sum('i.qty') @hourly_sales = Sale.hourly_sales(today,@from,@to).sum(:grand_total) @@ -190,7 +197,9 @@ class HomeController < ApplicationController def get_date_range_from_params from = params[:from] - to = params[:to] + to = params[:to] + from_time = params[:from_time] + to_time = params[:to_time] if from.present? && to.present? f_date = DateTime.parse(from) @@ -201,7 +210,7 @@ class HomeController < ApplicationController to = t_time.end_of_day.utc.getlocal end - return from, to + return from, to, from_time, to_time end #Shop Name in Navbor diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index aee947c7..6ee68d97 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -68,16 +68,26 @@
    -
    +
    - +
    -
    +
    - +
    +
    + + + +
    +
    + + + +

    @@ -340,21 +350,53 @@ $('.btn_generate').on('click',function(){ var from = $("#from").val(); var to = $("#to").val(); + var from_time = $("#from_time").val(); + var to_time = $("#to_time").val(); + + if(check(from,to,from_time,to_time)){ + var params = '?'; + if((from!='' && to!='') && (from_time!='' && to_time!='')){ + params += 'from='+from+'&to='+to+'&from_time='+from_time+'&to_time='+to_time; + }else{ + params += 'from='+from+'&to='+to; + } + window.location.href = '/dashboard'+params; + } + }); + + function check(from,to,from_time,to_time){ + var status = true; if((from=='') && (to=='')){ + status = false; $('#fromErr').html("can't be blank"); $('#toErr').html("can't be blank"); }else if((from!='') && (to=='')){ + status = false; $('#fromErr').html(""); $('#toErr').html("can't be blank"); }else if((from=='') && (to!='')){ + status = false; $('#fromErr').html("can't be blank"); $('#toErr').html(""); }else{ + status = true; $('#fromErr').html(""); $('#toErr').html(""); } - if((from!='') && (to!='')){ - window.location.href = '/dashboard?from='+from+'&to='+to; + + if(((from_time=='') && (to_time=='')) || ((from_time!='') && (to_time!=''))){ + status = true; + $('#from_timeErr').html(""); + $('#to_timeErr').html(""); + }else if((from_time!='') && (to_time=='')){ + status = false; + $('#from_timeErr').html(""); + $('#to_timeErr').html("can't be blank"); + }else if((from_time=='') && (to_time!='')){ + status = false; + $('#from_timeErr').html("can't be blank"); + $('#to_timeErr').html(""); } - }); + return status; + } \ No newline at end of file diff --git a/app/views/origami/dashboard/index.html.erb b/app/views/origami/dashboard/index.html.erb index 5361ac27..228da935 100644 --- a/app/views/origami/dashboard/index.html.erb +++ b/app/views/origami/dashboard/index.html.erb @@ -22,7 +22,7 @@
    arrow_forward
    -
    Quick Service
    +
    <%= t :quick_service %>
    @@ -30,7 +30,7 @@
    arrow_forward
    -
    Cashier
    +
    <%= t :dine_in_order %>
    diff --git a/config/locales/en.yml b/config/locales/en.yml index da68414c..84a7b03a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -72,6 +72,8 @@ en: payment: "Payment" backend: "Backend" date_time: "DateTime" + dine_in_order: "Dine In Order" + quick_service: "Quick Service" views: btn: diff --git a/config/locales/mm.yml b/config/locales/mm.yml index d3ca2d0f..f18136c4 100644 --- a/config/locales/mm.yml +++ b/config/locales/mm.yml @@ -67,6 +67,8 @@ mm: payment: "ငွေပေးချေမှု" backend: "နောက်ကွယ်" date_time: "ရက်စွဲအချိန်" + dine_in_order: "Dine In Order" + quick_service: "Quick Service" views: btn: From f9aa3310fa3c6d16a1f2ed1c016eda4e2dfa2bb7 Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 23 Mar 2018 19:37:32 +0630 Subject: [PATCH 092/108] check ability in booking --- app/models/ability.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index de43d71f..0b1edcc3 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -105,7 +105,7 @@ class Ability can :show, :home can :read, Order can :update, Order - can :menage, Booking + can :manage, Booking can :manage, OrderQueueStation can :read, Sale can :update, Sale From ac0ee37136a90039b7a7eed7b3f27c5808eb081f Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 26 Mar 2018 15:54:24 +0630 Subject: [PATCH 093/108] add foc , void and discount item in sale item report --- .../reports/saleitem_controller.rb | 6 +- app/models/sale.rb | 33 +- .../_shift_sale_report_filter.html.erb | 33 +- app/views/reports/saleitem/index.html.erb | 94 ++--- app/views/reports/saleitem/index.xls.erb | 188 +++++---- .../reports/saleitem/indexbackup.html.erb | 366 ++++++++++++++++++ 6 files changed, 573 insertions(+), 147 deletions(-) create mode 100644 app/views/reports/saleitem/indexbackup.html.erb diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index 796b02ad..a731cb44 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -15,8 +15,10 @@ class Reports::SaleitemController < BaseReportController shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) end end - @sale_data, @other_charges,@discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED) - + @type = params[:sale_type] + @sale_data, @other_charges,@discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type) +puts @other_charges.to_json +puts "oooooooooooooooooooooooo" @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) @account_cate_count = Hash.new {|hash, key| hash[key] = 0} diff --git a/app/models/sale.rb b/app/models/sale.rb index b459f16c..fb422a73 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -798,15 +798,27 @@ def self.get_by_shift_sale(from,to,status) return query = query.where("shift_sales.shift_started_at >= ?" + " AND shift_sales.shift_closed_at <= ?", from,to) end -def self.get_item_query() +def self.get_item_query(type) + + if type == "revenue" || type.nil? + sale_type = "i.status IS NULL and i.qty >0 " + elsif type == "all" + sale_type = "" + elsif type == "discount" + sale_type = "i.status = 'Discount'" + elsif type == "foc" + sale_type = "i.status = 'foc' and i.qty > 0" + elsif type == "void" + sale_type = "i.status = 'void' and i.qty > 0" + elsif type == "other" + sale_type = "i.item_instance_code IS NULL" + end query = Sale.select("acc.title as account_name,mi.account_id, i.item_instance_code as item_code,i.account_id as account_id, " + "SUM(i.qty * i.unit_price) as grand_total, SUM(i.qty) as total_item,i.qty as qty," + "i.status as status_type,"+ - " i.unit_price,i.price as price,i.product_name as product_name, - mc.name as" + - " menu_category_name,mc.id as menu_category_id ") + "i.unit_price,i.price as price,i.product_name as product_name,mc.name as " +"menu_category_name,mc.id as menu_category_id ") query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" + " JOIN menu_item_instances mii ON i.item_instance_code = mii.item_instance_code" + @@ -815,7 +827,7 @@ def self.get_item_query() " JOIN menu_categories mc ON mc.id = mi.menu_category_id ") # "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ") query = query.joins(" JOIN accounts acc ON acc.id = mi.account_id") - # query = query.where("i.item_instance_code IS NOT NULL") + query = query.where("#{sale_type}") query = query.group("acc.title,mi.account_id,mi.menu_category_id,i.product_name,i.unit_price") .order("acc.title desc, mi.account_id desc, mi.menu_category_id desc, i.unit_price asc") end @@ -830,10 +842,15 @@ def self.get_other_charges() query = query.group("i.sale_item_id") end -def self.get_by_shift_items(shift_sale_range, shift, from, to, status) +def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type) # date_type_selection = get_sql_function_for_report_type(report_type) - query = self.get_item_query() - + if type == "other" + other_charges = self.get_other_charges() + query = self.get_item_query(type) + else + query = self.get_item_query(type) + end + discount_query = 0 total_card_amount = 0 total_cash_amount = 0 diff --git a/app/views/reports/saleitem/_shift_sale_report_filter.html.erb b/app/views/reports/saleitem/_shift_sale_report_filter.html.erb index 88f26c1f..75a331e9 100755 --- a/app/views/reports/saleitem/_shift_sale_report_filter.html.erb +++ b/app/views/reports/saleitem/_shift_sale_report_filter.html.erb @@ -18,13 +18,25 @@ - -
    + +
    + + +
    +
    -
    +
    @@ -52,7 +64,7 @@ $('#frm_report').attr('action',url) $('#frm_report').submit(); // window.location = url; - }); + }); var item = $('#item').val(); var payment_type = $('#payment_type'); @@ -76,17 +88,18 @@ }); <% if params[:shift_name].to_i > 0%> - shift_id = '<%= params[:shift_name] %>' - local_date = '<%= @shift_from %> - <%= @shift_to %> ' - var shift = $('#shift_name'); - str = ''; - shift.append(str); + shift_id = '<%= params[:shift_name] %>' + local_date = '<%= @shift_from %> - <%= @shift_to %> ' + var shift = $('#shift_name'); + str = ''; + shift.append(str); <% end %> $("#from").val("<%=params[:from] rescue '-'%>"); $("#to").val("<%=params[:to] rescue '-'%>"); $("#sel_period").val(<%=params[:period] rescue '-'%>); - $("#sel_sale_type").val(<%=params[:sale_type] rescue '-'%>); + var sale_type = "<%=params[:sale_type]%>"; + $("#sel_sale_type").val(sale_type); <% if params[:period_type] == 1 || params[:period_type] == "1" %> diff --git a/app/views/reports/saleitem/index.html.erb b/app/views/reports/saleitem/index.html.erb index 3c03dec2..531d289b 100644 --- a/app/views/reports/saleitem/index.html.erb +++ b/app/views/reports/saleitem/index.html.erb @@ -57,8 +57,7 @@ delimiter = "" end %> - <% unless @sale_data.blank? %> - <% acc_arr = Array.new %> + <% acc_arr = Array.new %> <% cate_arr = Array.new %> <% sub_qty = 0 %> @@ -75,24 +74,27 @@ <% total_item_foc = 0 %> <% total_item_dis = 0.0 %> <% total_tax = 0 %> - + <% unless @sale_data.blank? %> <% @sale_data.each do |sale| %> + - <% if sale.status_type == "foc" && sale.grand_total < 0 + <% if !acc_arr.include?(sale.account_id) %>
    @@ -151,7 +153,8 @@ <% end %> - <% if @other_charges.present? %> + <% if @type == "other"%> + @@ -191,55 +194,38 @@ <% end %> - - - - - - - - - - - - - - - - - - - - - + <% if @type == "other"%> - <% @sale_taxes.each do |tax| %> - - <% end %> - - - - - - - + + + + + + <% @other_charges.each do |other| %> + <% if other.total_item > 0 + total_qty += other.total_item + end %> + <% grand_total +=other.grand_total%> + + + + + + + + + + + + <% other_sub_total += other.grand_total %> + + <% end %> + + + + + + <%end%>
    <%= sale.account_name %>
    Other Charges  <%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter)%>
     <%= t("views.right_panel.detail.foc_item") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(total_item_foc , precision:precision.to_i,delimiter:delimiter) %>
     <%= t("views.right_panel.detail.item_discount") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(total_item_dis , precision:precision.to_i,delimiter:delimiter) %>
     <%= t("views.right_panel.detail.foc_sales") %> - <%= number_with_precision(@foc_data, precision:precision.to_i, delimiter:delimiter) %> -
     <%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> - - <%= number_with_precision(@discount_data , precision: precision.to_i,delimiter: delimiter) %> - -
     Net Amount<%= number_with_precision(grand_total.to_f - @discount_data.to_f , precision:precision.to_i,delimiter:delimiter)%>
    Other Charges 
     Other Charges<%= other.item_code rescue '-' %><%= other.product_name rescue '-' %><%= other.total_item rescue '-' %> <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     <%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%>
    diff --git a/app/views/reports/saleitem/index.xls.erb b/app/views/reports/saleitem/index.xls.erb index f97edbb8..85c666a5 100755 --- a/app/views/reports/saleitem/index.xls.erb +++ b/app/views/reports/saleitem/index.xls.erb @@ -27,10 +27,22 @@ - <% unless @sale_data.blank? %> - <% acc_arr = Array.new %> + <% if @print_settings.precision.to_i > 0 + precision = @print_settings.precision + else + precision = 0 + end + #check delimiter + if @print_settings.delimiter + delimiter = "," + else + delimiter = "" + end + %> + <% acc_arr = Array.new %> <% cate_arr = Array.new %> + <% sub_qty = 0 %> <% sub_total = 0 %> <% other_sub_total = 0 %> <% count = 0 %> @@ -42,14 +54,29 @@ <% total_amount = 0 %> <% discount = 0 %> <% total_item_foc = 0 %> - <% total_item_dis = 0 %> - + <% total_item_dis = 0.0 %> + <% total_tax = 0 %> + <% unless @sale_data.blank? %> <% @sale_data.each do |sale| %> - - <% if sale.total_item > 0 + + + + <% if !acc_arr.include?(sale.account_id) %> <%= sale.account_name %> @@ -58,7 +85,7 @@ <% @totalByAccount.each do |account, total| %> <% if sale.account_id == account %> - <%= total %> + <%= number_with_precision(total, precision:precision.to_i,delimiter:delimiter) %> <% grand_total += total %> <% end %> <% end %> @@ -77,95 +104,110 @@ <%= sale.item_code rescue '-' %> <%= sale.product_name rescue '-' %> <%= sale.total_item rescue '-' %> - <%= sale.unit_price rescue '-' %> - <%= sale.grand_total rescue '-' %> + <%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% @menu_cate_count.each do |key,value| %> - <% if sale.menu_category_id == key %> + <% @menu_cate_count.each do |key,value| %> + <% if sale.account_id == key %> <% count = count + 1 %> <% sub_total += sale.grand_total %> + <% #sub_qty += sale.total_item %> + <% if sale.status_type!="Discount" && (!sale.product_name.include? "FOC") + sub_qty += sale.total_item + end %> + <% if count == value %> -   +   + Total <%= sale.account_name %> Qty + <%= sub_qty %> <%= t("views.right_panel.detail.sub_total") %> - <%= sub_total %> + <%= number_with_precision(sub_total , precision:precision.to_i,delimiter:delimiter)%> - <% if sale.status_type === "foc" - total_item_foc += sale.grand_total - end %> - - <% if sale.status_type === "Discount" - total_item_dis += sale.grand_total - end %> <% sub_total = 0.0%> + <% sub_qty = 0 %> <% count = 0%> <% end %> - <% end %> <% end %> + <% end %> - <% end %> + <% end %> - - Other Charges -   - - - <% @other_charges.each do |other| %> - <% if other.total_item > 0 - total_qty += other.total_item - end %> - <% grand_total +=other.grand_total%> - -   - Other Charges - <%= other.item_code rescue '-' %> - <%= other.product_name rescue '-' %> - <%= other.total_item rescue '-' %> - <%= other.unit_price rescue '-' %> - <%= other.grand_total rescue '-' %> + <% if @type == "other"%> + + + Other Charges +   + - - - <% other_sub_total += other.grand_total %> - - <% end %> - -   - <%= t("views.right_panel.detail.sub_total") %> - <%= other_sub_total %> - + <% @other_charges.each do |other| %> + <% if other.total_item > 0 + total_qty += other.total_item + end %> + <% grand_total +=other.grand_total%> + +   + Other Charges + <%= other.item_code rescue '-' %> + <%= other.product_name rescue '-' %> + <%= other.total_item rescue '-' %> + <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + + + + <% other_sub_total += other.grand_total %> + + <% end %> + +   + <%= t("views.right_panel.detail.sub_total") %> + <%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%> + + <%end%>   <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %> <%= total_qty%> - <%= t("views.right_panel.detail.net_amount") %> - <%= grand_total%> + <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %> + <%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter)%> <% end %> - - -   - <%= t("views.right_panel.detail.foc_item") %> <%= t("views.right_panel.detail.amount") %> - <%= total_item_foc %> - - -   - <%= t("views.right_panel.detail.item_discount") %> <%= t("views.right_panel.detail.amount") %> - <%= total_item_dis %> - - -   - <%= t("views.right_panel.detail.foc_sales") %> - <%= @foc_data %> - - -   - <%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> - <%= @discount_data %> - + <% if @type == "other"%> + + + Other Charges +   + + + <% @other_charges.each do |other| %> + <% if other.total_item > 0 + total_qty += other.total_item + end %> + <% grand_total +=other.grand_total%> + +   + Other Charges + <%= other.item_code rescue '-' %> + <%= other.product_name rescue '-' %> + <%= other.total_item rescue '-' %> + <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + + + + <% other_sub_total += other.grand_total %> + + <% end %> + +   + <%= t("views.right_panel.detail.sub_total") %> + <%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%> + + <%end%>
    diff --git a/app/views/reports/saleitem/indexbackup.html.erb b/app/views/reports/saleitem/indexbackup.html.erb new file mode 100644 index 00000000..3c03dec2 --- /dev/null +++ b/app/views/reports/saleitem/indexbackup.html.erb @@ -0,0 +1,366 @@ + +
    +
    + <%= render :partial=>'shift_sale_report_filter', + :locals=>{ :period_type => true, :shift_name => true, :report_path =>reports_saleitem_index_path} %> + +
    + + + +
    +
    +
    + + + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + + + + <% if @print_settings.precision.to_i > 0 + precision = @print_settings.precision + else + precision = 0 + end + #check delimiter + if @print_settings.delimiter + delimiter = "," + else + delimiter = "" + end + %> + <% unless @sale_data.blank? %> + <% acc_arr = Array.new %> + <% cate_arr = Array.new %> + + <% sub_qty = 0 %> + <% sub_total = 0 %> + <% other_sub_total = 0 %> + <% count = 0 %> + <% total_price = 0 %> + <% cate_count = 0 %> + <% acc_count = 0 %> + <% grand_total = 0 %> + <% total_qty = 0 %> + <% total_amount = 0 %> + <% discount = 0 %> + <% total_item_foc = 0 %> + <% total_item_dis = 0.0 %> + <% total_tax = 0 %> + + <% @sale_data.each do |sale| %> + + <% if sale.status_type != "Discount" && sale.status_type != "foc" + total_qty += sale.total_item + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + end %> + + <% if sale.status_type == "foc" && sale.grand_total < 0 + total_item_foc += sale.grand_total*(-1) + end %> + + <% if sale.status_type == "Discount" && sale.grand_total < 0 + total_item_dis += sale.grand_total*(-1) + end %> + + <% if !acc_arr.include?(sale.account_id) %> + + + + + + + <% acc_arr.push(sale.account_id) %> + <% end %> + + + <% if !cate_arr.include?(sale.menu_category_id) %> + + <% cate_arr.push(sale.menu_category_id) %> + <% else %> + + <% end %> + + + + + + + + + <% @menu_cate_count.each do |key,value| %> + <% if sale.account_id == key %> + <% count = count + 1 %> + <% sub_total += sale.grand_total %> + <% #sub_qty += sale.total_item %> + <% if sale.status_type!="Discount" && (!sale.product_name.include? "FOC") + sub_qty += sale.total_item + end %> + + <% if count == value %> + + + + + + + + <% sub_total = 0.0%> + <% sub_qty = 0 %> + <% count = 0%> + <% end %> + <% end %> + <% end %> + + <% end %> + + <% if @other_charges.present? %> + + + + + + <% @other_charges.each do |other| %> + <% if other.total_item > 0 + total_qty += other.total_item + end %> + <% grand_total +=other.grand_total%> + + + + + + + + + + + + <% other_sub_total += other.grand_total %> + + <% end %> + + + + + + <%end%> + + + + + + + + + <% end %> + + + + + + + + + + + + + + + + + + + + + + + <% @sale_taxes.each do |tax| %> + + <% end %> + + + + + + + + +
    <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
    <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
     <%= t("views.right_panel.header.menu_category") %><%= t("views.right_panel.detail.code") %><%= t("views.right_panel.detail.product") %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.revenue") %>
    <%= sale.account_name %> <%= t("views.right_panel.detail.total_price_by") %> <%= sale.account_name %> + <% @totalByAccount.each do |account, total| %> + <% if sale.account_id == account %> + <%= number_with_precision(total, precision:precision.to_i,delimiter:delimiter) %> + <% grand_total += total %> + <% end %> + <% end %> +
     <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     Total <%= sale.account_name %> Qty <%= sub_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(sub_total , precision:precision.to_i,delimiter:delimiter)%>
    Other Charges 
     Other Charges<%= other.item_code rescue '-' %><%= other.product_name rescue '-' %><%= other.total_item rescue '-' %> <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     <%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%>
     <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= total_qty%><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter)%>
     <%= t("views.right_panel.detail.foc_item") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(total_item_foc , precision:precision.to_i,delimiter:delimiter) %>
     <%= t("views.right_panel.detail.item_discount") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(total_item_dis , precision:precision.to_i,delimiter:delimiter) %>
     <%= t("views.right_panel.detail.foc_sales") %> + <%= number_with_precision(@foc_data, precision:precision.to_i, delimiter:delimiter) %> +
     <%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> + + <%= number_with_precision(@discount_data , precision: precision.to_i,delimiter: delimiter) %> + +
     Net Amount<%= number_with_precision(grand_total.to_f - @discount_data.to_f , precision:precision.to_i,delimiter:delimiter)%>
    +
    +
    +
    +
    +
    + + \ No newline at end of file From 4b78de3f9a5635964c03d3bd8188a2a46cf265da Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 26 Mar 2018 16:42:17 +0630 Subject: [PATCH 094/108] add filter in dashboard and Transaction/Sale --- app/controllers/home_controller.rb | 75 +- .../transactions/sales_controller.rb | 93 +- app/models/sale.rb | 850 ++++++++++++++---- app/models/stock_journal.rb | 10 +- app/views/home/dashboard.html.erb | 30 +- app/views/transactions/sales/index.html.erb | 144 ++- 6 files changed, 972 insertions(+), 230 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index da8695d8..d2b0ad36 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -86,64 +86,72 @@ class HomeController < ApplicationController today = DateTime.now.strftime('%Y-%m-%d') if !@from.nil? && !@to.nil? - @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() + if !@from_time.nil? && @to_time.nil? + @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count() + else + @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() + end else @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() end if !@from.nil? && !@to.nil? - @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() + if !@from_time.nil? && @to_time.nil? + @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count() + else + @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() + end else @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() end - @top_products = Sale.top_products(today,@from,@to).sum('i.qty') - @bottom_products = Sale.bottom_products(today,@from,@to).sum('i.qty') - @hourly_sales = Sale.hourly_sales(today,@from,@to).sum(:grand_total) + @top_products = Sale.top_products(today,current_user,@from,@to,@from_time,@to_time).sum('i.qty') + @bottom_products = Sale.bottom_products(today,current_user,@from,@to,@from_time,@to_time).sum('i.qty') + @hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time).sum(:grand_total) # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') # .sum(:grand_total) - @employee_sales = Sale.employee_sales(today,@from,@to) + @employee_sales = Sale.employee_sales(today,current_user,@from,@to,@from_time,@to_time) .sum('(CASE WHEN sp.payment_method="cash" THEN (sp.payment_amount - sales.amount_changed) ELSE sp.payment_amount END)') - @inventories = StockJournal.inventory_balances(today,@from,@to).sum(:balance) + @inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time).sum(:balance) - @total_sale = Sale.total_sale(today,current_user,@from,@to) - @total_count = Sale.total_count(today,current_user,@from,@to) - @total_card = Sale.total_card_sale(today,current_user,@from,@to) - @total_credit = Sale.credit_payment(today,current_user,@from,@to) + @total_sale = Sale.total_sale(today,current_user,@from,@to,@from_time,@to_time) + @total_count = Sale.total_count(today,current_user,@from,@to,@from_time,@to_time) + @total_card = Sale.total_card_sale(today,current_user,@from,@to,@from_time,@to_time) + @total_credit = Sale.credit_payment(today,current_user,@from,@to,@from_time,@to_time) @sale_data = Array.new - @total_payment_methods = Sale.total_payment_methods(today,current_user,@from,@to) + @total_payment_methods = Sale.total_payment_methods(today,current_user,@from,@to,@from_time,@to_time) if !@total_payment_methods.nil? @total_payment_methods.each do |payment| - if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" - pay = Sale.payment_sale('card', today, current_user,@from,@to) + if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay" + pay = Sale.payment_sale('card', today, current_user,@from,@to,@from_time,@to_time) @sale_data.push({'card' => pay.payment_amount}) else - pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to) + pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to,@from_time,@to_time) @sale_data.push({payment.payment_method => pay.payment_amount}) end end end - @summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to) - @total_customer = Sale.total_customer(today,current_user,@from,@to) - @total_dinein = Sale.total_dinein(today,current_user,@from,@to) - @total_takeaway = Sale.total_takeaway(today,current_user,@from,@to) - @total_other_customer = Sale.total_other_customer(today,current_user,@from,@to) - @total_membership = Sale.total_membership(today,current_user,@from,@to) + @summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to,@from_time,@to_time) + @total_customer = Sale.total_customer(today,current_user,@from,@to,@from_time,@to_time) + @total_dinein = Sale.total_dinein(today,current_user,@from,@to,@from_time,@to_time) + @total_takeaway = Sale.total_takeaway(today,current_user,@from,@to,@from_time,@to_time) + @total_other_customer = Sale.total_other_customer(today,current_user,@from,@to,@from_time,@to_time) + @total_membership = Sale.total_membership(today,current_user,@from,@to,@from_time,@to_time) - @total_order = Sale.total_order(today,current_user,@from,@to) - @total_accounts = Sale.total_account(today,current_user,@from,@to) + @total_order = Sale.total_order(today,current_user,@from,@to,@from_time,@to_time) + @total_accounts = Sale.total_account(today,current_user,@from,@to,@from_time,@to_time) @account_data = Array.new if !@total_accounts.nil? @total_accounts.each do |account| - acc = Sale.account_data(account.account_id, today,current_user,@from,@to) + acc = Sale.account_data(account.account_id, today,current_user,@from,@to,@from_time,@to_time) if !acc.nil? @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) end end end - @top_items = Sale.top_items(today,current_user,@from,@to) - @total_foc_items = Sale.total_foc_items(today,current_user,@from,@to) + @top_items = Sale.top_items(today,current_user,@from,@to,@from_time,@to_time) + @total_foc_items = Sale.total_foc_items(today,current_user,@from,@to,@from_time,@to_time) # get printer info @print_settings = PrintSetting.get_precision_delimiter() @@ -202,12 +210,15 @@ class HomeController < ApplicationController to_time = params[:to_time] if from.present? && to.present? - f_date = DateTime.parse(from) - t_date = DateTime.parse(to) - f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) - t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) - from = f_time.beginning_of_day.utc.getlocal - to = t_time.end_of_day.utc.getlocal + # f_date = DateTime.parse(from) + # t_date = DateTime.parse(to) + # f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) + # t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) + # from = f_time.beginning_of_day.utc.getlocal + # to = t_time.end_of_day.utc.getlocal + + from = DateTime.parse(from).utc.getlocal.strftime('%Y-%m-%d') + to = DateTime.parse(to).utc.getlocal.strftime('%Y-%m-%d') end return from, to, from_time, to_time diff --git a/app/controllers/transactions/sales_controller.rb b/app/controllers/transactions/sales_controller.rb index bae9c353..be370371 100755 --- a/app/controllers/transactions/sales_controller.rb +++ b/app/controllers/transactions/sales_controller.rb @@ -8,14 +8,23 @@ class Transactions::SalesController < ApplicationController def index receipt_no = params[:receipt_no] - from = params[:from] - to = params[:to] + # from = params[:from] + # to = params[:to] + from, to = get_date_range_from_params + @shift = '' + if params[:shift_name].to_i != 0 + @shift = ShiftSale.find(params[:shift_name]) + end if receipt_no.nil? && from.nil? && to.nil? - @sales = Sale.where("NOT sale_status='new'").order("sale_id desc") + if @shift.blank? + @sales = Sale.where("NOT sale_status='new'").order("sale_id desc") + else + @sales = Sale.where("NOT sale_status='new' and shift_sale_id ='#{@shift.id}'").order("sale_id desc") + end @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20) else - sale = Sale.search(receipt_no,from,to) + sale = Sale.search(receipt_no,from,to,@shift) if sale.count > 0 @sales = sale @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20) @@ -26,6 +35,12 @@ class Transactions::SalesController < ApplicationController @receipt_no = receipt_no @from = from @to = to + + if @shift.present? + @shift_from = @shift.shift_started_at.nil? ? '-' : @shift.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_to = @shift.shift_closed_at.nil? ? '-' : @shift.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_data = @shift + end # if receipt_no.nil? && search_date.nil? # @sales = Sale.where("NOT sale_status = 'void' " ).order("sale_id desc").limit(500) @@ -48,7 +63,7 @@ class Transactions::SalesController < ApplicationController @sale_audits = [] @sale_item_audits = [] - if !@sales.nil? + if @sales != 0 @sales.each do |sale| sale_audit = SaleAudit.where("(action = 'SALEPAYMENT' or action = 'SALEVOID') and sale_id = ? and remark IS NOT NULL",sale.sale_id) if !sale_audit.nil? @@ -148,6 +163,74 @@ class Transactions::SalesController < ApplicationController end end + # date range + PERIOD = { + "today" => 0, + "yesterday" => 1, + "this_week" => 2, + "last_week" => 3, + "last_7" => 4, + "this_month" => 5, + "last_month" => 6, + "last_30" => 7, + "this_year" => 8, + "last_year" => 9 + } + + def get_date_range_from_params + period_type = params[:period_type] + period = params[:period] + from = params[:from] + to = params[:to] + day_ref = Time.now.utc.getlocal + + if from.present? && to.present? + f_date = DateTime.parse(from) + t_date = DateTime.parse(to) + f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) + t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) + from = f_time.beginning_of_day.utc.getlocal + to = t_time.end_of_day.utc.getlocal + else + case period.to_i + when PERIOD["today"] + from = day_ref.beginning_of_day.utc + to = day_ref.end_of_day.utc + + when PERIOD["yesterday"] + from = (day_ref - 1.day).beginning_of_day.utc + to = (day_ref - 1.day).end_of_day.utc + + when PERIOD["this_week"] + from = Time.now.beginning_of_week.utc + to = Time.now.utc + when PERIOD["last_week"] + from = (day_ref - 7.day).beginning_of_week.utc + to = (day_ref - 7.day).end_of_week.utc + when PERIOD["last_7"] + from = (day_ref - 7.day).utc + to = Time.now.utc + when PERIOD["this_month"] + from = Time.now.beginning_of_month.utc + to = Time.now.utc + when PERIOD["last_month"] + from = (day_ref - 1.month).beginning_of_month.utc + to = (day_ref - 1.month).end_of_month.utc + when PERIOD["last_30"] + from = (day_ref - 30.day).utc + to = Time.now.utc + when PERIOD["this_year"] + from = Time.now.beginning_of_year.utc + to = Time.now.utc + when PERIOD["last_year"] + from = (day_ref - 1.year).beginning_of_year.utc + to = (day_ref - 1.year).end_of_year.utc + end + end + + return from, to + end + def check_user if current_user.nil? redirect_to root_path diff --git a/app/models/sale.rb b/app/models/sale.rb index 5fc0c06f..a997e27f 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -598,7 +598,7 @@ class Sale < ApplicationRecord end end - def self.search(filter,from,to) + def self.search(filter,from,to,shift) if filter.blank? keyword = '' else @@ -606,10 +606,18 @@ class Sale < ApplicationRecord end if from.present? && to.present? - sale = Sale.where("DATE_FORMAT(receipt_date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(receipt_date,'%d-%m-%Y') <= ? and NOT sale_status = 'new' ", from,to) - query = sale.where(keyword) + if shift.blank? + sale = Sale.where("DATE_FORMAT(receipt_date,'%Y-%m-%d') >= ?" + " AND DATE_FORMAT(receipt_date,'%Y-%m-%d') <= ? and NOT sale_status = 'new' ", from,to) + else + sale = Sale.where("DATE_FORMAT(receipt_date,'%Y-%m-%d') >= ?" + " AND DATE_FORMAT(receipt_date,'%Y-%m-%d') <= ? and NOT sale_status = 'new' and shift_sale_id = '#{shift.id}'", from,to) + end + query = sale.where(keyword) else + if shift.blank? where("receipt_no LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}'","%#{filter}%","%#{filter}%") + else + where("receipt_no LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}' and shift_sale_id = ?","%#{filter}%","%#{filter}%",shift.id) + end end end @@ -1134,88 +1142,319 @@ end return tax end - def self.top_products(today,from,to) + def self.top_products(today,current_user,from,to,from_time,to_time) if !from.nil? && !to.nil? - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + if current_user.nil? + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + " i.price as unit_price,mi.name as product_name") + .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") + if !from_time.nil? && !to_time.nil? + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") + else + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and sale_status= 'completed'") + end + query = query.group('mi.name') + .order("SUM(i.qty) DESC").limit(20) + else + if current_user.role == 'administrator' || current_user.role == 'manager' + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + " i.price as unit_price,mi.name as product_name") .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") - .where("(i.qty > 0 and i.price > 0) and receipt_date between '#{from}' and '#{to}'"+ - "and sale_status= 'completed'") - .group('mi.name') - .order("SUM(i.qty) DESC").limit(20) + if !from_time.nil? && !to_time.nil? + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") + else + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and sale_status= 'completed'") + end + query = query.group('mi.name') + .order("SUM(i.qty) DESC").limit(20) + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + " i.price as unit_price,mi.name as product_name") + .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") + if !from_time.nil? && !to_time.nil? + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed' and shift_sale_id='#{shift.id}'") + else + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and sale_status= 'completed' and shift_sale_id='#{shift.id}'") + end + query = query.group('mi.name') + .order("SUM(i.qty) DESC").limit(20) + end + end + end else - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + if current_user.nil? + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + " i.price as unit_price,mi.name as product_name") .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ - "and sale_status= 'completed'") + " and sale_status= 'completed'") .group('mi.name') .order("SUM(i.qty) DESC").limit(20) + else + if current_user.role == 'administrator' || current_user.role == 'manager' + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + " i.price as unit_price,mi.name as product_name") + .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") + .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ + " and sale_status= 'completed'") + .group('mi.name') + .order("SUM(i.qty) DESC").limit(20) + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + " i.price as unit_price,mi.name as product_name") + .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") + .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ + " and sale_status= 'completed' and shift_sale_id='#{shift.id}'") + .group('mi.name') + .order("SUM(i.qty) DESC").limit(20) + end + end + end end end - def self.bottom_products(today,from,to) + def self.bottom_products(today,current_user,from,to,from_time,to_time) if !from.nil? && !to.nil? - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + - " i.price as unit_price,mi.name as product_name") - .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") - .where("(i.qty > 0 and i.price > 0) and receipt_date between '#{from}' and '#{to}'"+ - "and sale_status= 'completed'") - .group('mi.name') + if current_user.nil? + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + " i.price as unit_price,mi.name as product_name") + .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") + if !from_time.nil? && !to_time.nil? + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") + else + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and sale_status= 'completed'") + end + query = query.group('mi.name') .order("SUM(i.qty) ASC").limit(20) + else + if current_user.role == 'administrator' || current_user.role == 'manager' + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + " i.price as unit_price,mi.name as product_name") + .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") + if !from_time.nil? && !to_time.nil? + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") + else + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and sale_status= 'completed'") + end + query = query.group('mi.name') + .order("SUM(i.qty) ASC").limit(20) + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + " i.price as unit_price,mi.name as product_name") + .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") + if !from_time.nil? && !to_time.nil? + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed' and shift_sale_id='#{shift.id}'") + else + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30') between '#{from}' and '#{to}'"+ + " and sale_status= 'completed' and shift_sale_id='#{shift.id}'") + end + query = query.group('mi.name') + .order("SUM(i.qty) ASC").limit(20) + end + end + end else - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + if current_user.nil? + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + " i.price as unit_price,mi.name as product_name") .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ "and sale_status= 'completed'") .group('mi.name') .order("SUM(i.qty) ASC").limit(20) + else + if current_user.role == 'administrator' || current_user.role == 'manager' + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + " i.price as unit_price,mi.name as product_name") + .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") + .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ + "and sale_status= 'completed'") + .group('mi.name') + .order("SUM(i.qty) ASC").limit(20) + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + " i.price as unit_price,mi.name as product_name") + .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") + .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ + " and sale_status= 'completed' and shift_sale_id=#{shift.id}") + .group('mi.name') + .order("SUM(i.qty) ASC").limit(20) + end + end + end end end - def self.hourly_sales(today,from,to) + def self.hourly_sales(today,current_user,from,to,from_time,to_time) if !from.nil? && !to.nil? - query= Sale.select("grand_total") - .where('sale_status = "completed" and receipt_date between ? and ?',from,to) - .group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") - .order('receipt_date') + if current_user.nil? + query = Sale.select("grand_total") + if !from_time.nil? && !to_time.nil? + query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) + else + query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + end + query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + .order('receipt_date') + else + if current_user.role == 'administrator' || current_user.role == 'manager' + query = Sale.select("grand_total") + if !from_time.nil? && !to_time.nil? + query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) + else + query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + end + query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + .order('receipt_date') + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("grand_total") + if !from_time.nil? && !to_time.nil? + query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) + else + query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id) + end + query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + .order('receipt_date') + end + end + end else - query= Sale.select("grand_total") + if current_user.nil? + query = Sale.select("grand_total") .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) .group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") .order('receipt_date') + else + if current_user.role == 'administrator' || current_user.role == 'manager' + query = Sale.select("grand_total") + .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) + .group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + .order('receipt_date') + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("grand_total") + .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id) + .group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + .order('receipt_date') + end + end + end end end - def self.employee_sales(today,from,to) + def self.employee_sales(today,current_user,from,to,from_time,to_time) if !from.nil? && !to.nil? - query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") + if current_user.nil? + query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") + .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id") + if !from_time.nil? && !to_time.nil? + query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'") + else + query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'") + end + query = query.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name") + .order("e.name") + else + if current_user.role == 'administrator' || current_user.role == 'manager' + query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id") - .where("sales.payment_status='paid' and sales.sale_status = 'completed' and sales.receipt_date between '#{from}' and '#{to}'") - .group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name") - .order("e.name") + if !from_time.nil? && !to_time.nil? + query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'") + else + query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'") + end + query = query.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name") + .order("e.name") + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") + .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id") + if !from_time.nil? && !to_time.nil? + query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and shift_sale_id='#{shift.id}'") + else + query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and shift_sale_id='#{shift.id}'") + end + query = query.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name") + .order("e.name") + end + end + end else - query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") + if current_user.nil? + query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id") .where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = '#{today}'") .group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name") .order("e.name") - end - end - - def self.total_sale(today,current_user=nil,from=nil,to=nil) - if !from.nil? && !to.nil? - if current_user.nil? - total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).sum("grand_total") else if current_user.role == 'administrator' || current_user.role == 'manager' - total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).sum("grand_total") + query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") + .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id") + .where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = '#{today}'") + .group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name") + .order("e.name") else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? - total = Sale.where('sale_status = "completed" and sales.receipt_date between ? and ? and shift_sale_id=?',from,to,shift.id) + query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") + .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id") + .where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = '#{today}' and shift_sale_id='#{shift.id}'") + .group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name") + .order("e.name") + end + end + end + end + end + + def self.total_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + if !from.nil? && !to.nil? + if current_user.nil? + if !from_time.nil? && !to_time.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time).sum("grand_total") + else + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to).sum("grand_total") + end + else + if current_user.role == 'administrator' || current_user.role == 'manager' + if !from_time.nil? && !to_time.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time).sum("grand_total") + else + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to).sum("grand_total") + end + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + if !from_time.nil? && !to_time.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) .sum("grand_total") + else + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id) + .sum("grand_total") + end end end end @@ -1236,17 +1475,29 @@ end end end - def self.total_count(today,current_user=nil,from=nil,to=nil) + def self.total_count(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? - total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).count + if !from_time.nil? && !to_time.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time).count + else + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to).count + end else if current_user.role == 'administrator' || current_user.role == 'manager' - total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).count + if !from_time.nil? && !to_time.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time).count + else + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to).count + end else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? - total = Sale.where('sale_status = "completed" and receipt_date between ? and ? and shift_sale_id = ?',from,to,shift.id).count + if !from_time.nil? && !to_time.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ? and shift_sale_id = ?',from,to,from_time,to_time,shift.id).count + else + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id = ?',from,to,shift.id).count + end end end end @@ -1266,23 +1517,41 @@ end end end - def self.total_card_sale(today,current_user=nil,from=nil,to=nil) + def self.total_card_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? - query = Sale.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? 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")',from,to) - .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") - .sum("sp.payment_amount") - else - if current_user.role == 'administrator' || current_user.role == 'manager' - query = Sale.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? 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")',from,to) + if !from_time.nil? && !to_time.nil? + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? 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")',from,to,from_time,to_time) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .sum("sp.payment_amount") else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = Sale.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? 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") and shift_sale_id=?',from,to,shift.id) + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? 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")',from,to) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .sum("sp.payment_amount") + end + else + if current_user.role == 'administrator' || current_user.role == 'manager' + if !from_time.nil? && !to_time.nil? + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? 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")',from,to,from_time,to_time) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") + .sum("sp.payment_amount") + else + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? 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")',from,to) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") + .sum("sp.payment_amount") + end + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + if !from_time.nil? && !to_time.nil? + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? 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") and shift_sale_id=?',from,to,from_time,to_time,shift.id) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") + .sum("sp.payment_amount") + else + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? 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") and shift_sale_id=?',from,to,shift.id) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") + .sum("sp.payment_amount") + end end end end @@ -1308,23 +1577,41 @@ end end end - def self.credit_payment(today,current_user=nil,from=nil,to=nil) + def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and s.receipt_date between ? and ?',from,to) - .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") - .sum("payment_amount") - else - if current_user.role == 'administrator' || current_user.role == 'manager' - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and s.receipt_date between ? and ?',from,to) + if !from_time.nil? && !to_time.nil? + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and s.receipt_date between ? and ? and s.shift_sale_id=?',from,to,shift.id) + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") + end + else + if current_user.role == 'administrator' || current_user.role == 'manager' + if !from_time.nil? && !to_time.nil? + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) + .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") + .sum("payment_amount") + else + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") + .sum("payment_amount") + end + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + if !from_time.nil? && !to_time.nil? + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and s.shift_sale_id=?',from,to,from_time,to_time,shift.id) + .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") + .sum("payment_amount") + else + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and s.shift_sale_id=?',from,to,shift.id) + .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") + .sum("payment_amount") + end end end end @@ -1350,23 +1637,41 @@ end end end - def self.summary_sale_receipt(today,current_user=nil,from=nil,to=nil) + def self.summary_sale_receipt(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? - query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') - .where('sale_status = "completed" and receipt_date between ? and ?',from,to) + if !from_time.nil? && !to_time.nil? + query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') + .where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) .first() + else + query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') + .where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + .first() + end else if current_user.role == 'administrator' || current_user.role == 'manager' - query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') - .where('sale_status = "completed" and receipt_date between ? and ?',from,to) - .first() + if !from_time.nil? && !to_time.nil? + query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') + .where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) + .first() + else + query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') + .where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + .first() + end else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? - query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') - .where('sale_status = "completed" and receipt_date between ? and ? and shift_sale_id=?',from,to,shift.id) - .first() + if !from_time.nil? && !to_time.nil? + query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') + .where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) + .first() + else + query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') + .where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id) + .first() + end end end end @@ -1392,23 +1697,41 @@ end end end - def self.total_payment_methods(today,current_user=nil,from=nil,to=nil) + def self.total_payment_methods(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? - query = Sale.select("distinct sp.payment_method") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to) + if !from_time.nil? && !to_time.nil? + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + else + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to) + .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + end else if current_user.role == 'administrator' || current_user.role == 'manager' - query = Sale.select("distinct sp.payment_method") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to) + if !from_time.nil? && !to_time.nil? + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + else + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to) + .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + end else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? - query = Sale.select("distinct sp.payment_method") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and sales.shift_sale_id=?',from,to,shift.id) - .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + if !from_time.nil? && !to_time.nil? + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) + .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + else + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id) + .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + end end end end @@ -1434,35 +1757,69 @@ end end end - def self.payment_sale(payment_method, today, current_user=nil,from=nil,to=nil) + def self.payment_sale(payment_method, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + time_query = '' + if !from_time.nil? && !to_time.nil? + time_query = " and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'" + end if !from.nil? && !to.nil? if current_user.nil? - query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") - if payment_method == 'card' - query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? 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")',from,to) - else - query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and sales.receipt_date between ? and ?",from,to) - end - query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() - else - if current_user.role == 'administrator' || current_user.role == 'manager' + if !from_time.nil? && !to_time.nil? query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if payment_method == 'card' - query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? 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")',from,to) + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ? 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")',from,to,from_time,to_time) else - query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and sales.receipt_date between ? and ?",from,to) + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time) end query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? + query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + if payment_method == 'card' + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? 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")',from,to) + else + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ?",from,to) + end + query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() + end + else + if current_user.role == 'administrator' || current_user.role == 'manager' + if !from_time.nil? && !to_time.nil? query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if payment_method == 'card' - query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? 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") and sales.shift_sale_id=?',from,to,shift.id) + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ? 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")',from,to,from_time,to_time) else - query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and sales.receipt_date between ? and ? and sales.shift_sale_id=?",from,to,shift.id) + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time) end query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() + else + query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + if payment_method == 'card' + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? 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")',from,to) + else + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ?",from,to) + end + query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() + end + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + if !from_time.nil? && !to_time.nil? + query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + if payment_method == 'card' + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ? 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") and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) + else + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%M') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) + end + query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() + else + query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + if payment_method == 'card' + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? 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") and sales.shift_sale_id=?',from,to,shift.id) + else + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) + end + query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() + end end end end @@ -1500,10 +1857,10 @@ end end end - def self.total_customer(today,current_user=nil,from=nil,to=nil) - dinein_cnt = self.total_dinein(today,current_user,from,to) - takeaway_cnt = self.total_takeaway(today,current_user,from,to) - membership_cnt = self.total_membership(today,current_user,from,to) + def self.total_customer(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + dinein_cnt = self.total_dinein(today,current_user,from,to,from_time,to_time) + takeaway_cnt = self.total_takeaway(today,current_user,from,to,from_time,to_time) + membership_cnt = self.total_membership(today,current_user,from,to,from_time,to_time) total_cus = 0 if !dinein_cnt.nil? || !takeaway_cnt.nil? || !membership_cnt.nil? @@ -1513,26 +1870,47 @@ end return total_cus end - def self.total_dinein(today,current_user=nil,from=nil,to=nil) + def self.total_dinein(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? - query = Sale.select("count(sales.customer_id) as total_dinein_cus") + if !from_time.nil? && !to_time.nil? + query = Sale.select("count(sales.customer_id) as total_dinein_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to,from_time,to_time) .first() + else + query = Sale.select("count(sales.customer_id) as total_dinein_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to) + .first() + end else if current_user.role == 'administrator' || current_user.role == 'manager' - query = Sale.select("count(sales.customer_id) as total_dinein_cus") + if !from_time.nil? && !to_time.nil? + query = Sale.select("count(sales.customer_id) as total_dinein_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to,from_time,to_time) .first() + else + query = Sale.select("count(sales.customer_id) as total_dinein_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to) + .first() + end else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? - query = Sale.select("count(sales.customer_id) as total_dinein_cus") + if !from_time.nil? && !to_time.nil? + query = Sale.select("count(sales.customer_id) as total_dinein_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) .first() + else + query = Sale.select("count(sales.customer_id) as total_dinein_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id) + .first() + end end end end @@ -1561,26 +1939,47 @@ end end end - def self.total_takeaway(today,current_user=nil,from=nil,to=nil) + def self.total_takeaway(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? - query = Sale.select("count(sales.customer_id) as total_take_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to) - .first() - else - if current_user.role == 'administrator' || current_user.role == 'manager' + if !from_time.nil? && !to_time.nil? query = Sale.select("count(sales.customer_id) as total_take_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZsales.receipt_date,"%H:%M") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to,from_time,to_time) .first() + else + query = Sale.select("count(sales.customer_id) as total_take_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to) + .first() + end + else + if current_user.role == 'administrator' || current_user.role == 'manager' + if !from_time.nil? && !to_time.nil? + query = Sale.select("count(sales.customer_id) as total_take_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to,from_time,to_time) + .first() + else + query = Sale.select("count(sales.customer_id) as total_take_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to) + .first() + end else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? - query = Sale.select("count(sales.customer_id) as total_take_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id) - .first() + if !from_time.nil? && !to_time.nil? + query = Sale.select("count(sales.customer_id) as total_take_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) + .first() + else + query = Sale.select("count(sales.customer_id) as total_take_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id) + .first() + end end end end @@ -1609,26 +2008,43 @@ end end end - def self.total_membership(today,current_user=nil,from=nil,to=nil) + def self.total_membership(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? - query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to) - .first() - else - if current_user.role == 'administrator' || current_user.role == 'manager' + if !from_time.nil? && !to_time.nil? query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to,from_time,to_time) .first() + else + query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to) + .first() + end + else + if current_user.role == 'administrator' || current_user.role == 'manager' + if !from_time.nil? && !to_time.nil? + query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to,from_time,to_time) + .first() + else + query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to) + .first() + end else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null)) and sales.shift_sale_id=?',from,to,shift.id) - .first() + if !from_time.nil? && !to_time.nil? + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null)) and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id).first() + else + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null)) and sales.shift_sale_id=?',from,to,shift.id).first() + end end end end @@ -1657,26 +2073,41 @@ end end end - def self.total_other_customer(today,current_user=nil,from=nil,to=nil) + def self.total_other_customer(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? query = Sale.select("count(sales.customer_id) as total_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type is null and c.membership_id is null',from,to) - .first() + if !from_time.nil? && !to_time.nil? + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type is null and c.membership_id is null',from,to,from_time,to_time) + .first() + else + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type is null and c.membership_id is null',from,to) + .first() + end else if current_user.role == 'administrator' || current_user.role == 'manager' query = Sale.select("count(sales.customer_id) as total_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type is null and c.membership_id is null',from,to) - .first() + if !from_time.nil? && !to_time.nil? + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type is null and c.membership_id is null',from,to,from_time,to_time) + .first() + else + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type is null and c.membership_id is null',from,to) + .first() + end else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? query = Sale.select("count(sales.customer_id) as total_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id) - .first() + if !from_time.nil? && !to_time.nil? + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) + .first() + else + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id) + .first() + end end end end @@ -1705,29 +2136,44 @@ end end end - def self.total_order(today,current_user=nil,from=nil,to=nil) + def self.total_order(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? query = Sale.select("count(distinct a.order_id) as total_order") .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") .joins("JOIN orders as b ON b.order_id = a.order_id") - .where('b.status = "billed" and sales.receipt_date between ? and ?',from,to) - .first() + if !from_time.nil? && !to_time.nil? + query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) + .first() + else + query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + .first() + end else if current_user.role == 'administrator' || current_user.role == 'manager' query = Sale.select("count(distinct a.order_id) as total_order") .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") .joins("JOIN orders as b ON b.order_id = a.order_id") - .where('b.status = "billed" and sales.receipt_date between ? and ?',from,to) - .first() + if !from_time.nil? && !to_time.nil? + query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) + .first() + else + query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + .first() + end else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? query = Sale.select("count(distinct a.order_id) as total_order") .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") .joins("JOIN orders as b ON b.order_id = a.order_id") - .where('b.status = "billed" and sales.receipt_date between ? and ? and sales.shift_sale_id=?',from,to,shift.id) - .first() + if !from_time.nil? && !to_time.nil? + query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) + .first() + else + query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id) + .first() + end end end end @@ -1759,26 +2205,38 @@ end end end - def self.total_account(today,current_user=nil,from=nil,to=nil) + def self.total_account(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? query = Sale.select("distinct b.id as account_id, b.title as title") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .joins("JOIN accounts as b ON b.id = a.account_id") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to) + if !from_time.nil? && !to_time.nil? + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to,from_time,to_time) + else + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + end else if current_user.role == 'administrator' || current_user.role == 'manager' query = Sale.select("distinct b.id as account_id, b.title as title") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .joins("JOIN accounts as b ON b.id = a.account_id") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to) + if !from_time.nil? && !to_time.nil? + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) + else + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + end else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? query = Sale.select("distinct b.id as account_id, b.title as title") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .joins("JOIN accounts as b ON b.id = a.account_id") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and sales.shift_sale_id=?',from,to,shift.id) + if !from_time.nil? && !to_time.nil? + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) + else + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id) + end end end end @@ -1807,26 +2265,41 @@ end end end - def self.account_data(account_id, today, current_user=nil,from=nil,to=nil) + def self.account_data(account_id, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and sales.receipt_date between ? and ?",from,to) - .first() + if !from_time.nil? && !to_time.nil? + query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time) + .first() + else + query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) + .first() + end else if current_user.role == 'administrator' || current_user.role == 'manager' query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and sales.receipt_date between ? and ?",from,to) - .first() + if !from_time.nil? && !to_time.nil? + query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time) + .first() + else + query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) + .first() + end else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and sales.receipt_date between ? and ? and sales.shift_sale_id=?",from,to,shift.id) - .first() + if !from_time.nil? && !to_time.nil? + query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) + .first() + else + query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) + .first() + end end end end @@ -1855,32 +2328,44 @@ end end end - def self.top_items(today,current_user=nil,from=nil,to=nil) + def self.top_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and sales.receipt_date between ? and ?",from,to) - .group("a.product_code") - .order("SUM(a.qty) DESC") - .first() + if !from_time.nil? && !to_time.nil? + query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time) + else + query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) + end + query = query.group("a.product_code") + .order("SUM(a.qty) DESC") + .first() else if current_user.role == 'administrator' || current_user.role == 'manager' query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and sales.receipt_date between ? and ?",from,to) - .group("a.product_code") - .order("SUM(a.qty) DESC") - .first() + if !from_time.nil? && !to_time.nil? + query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time) + else + query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) + end + query = query.group("a.product_code") + .order("SUM(a.qty) DESC") + .first() else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and sales.receipt_date between ? and ? and sales.shift_sale_id=?",from,to,shift.id) - .group("a.product_code") - .order("SUM(a.qty) DESC") - .first() + if !from_time.nil? && !to_time.nil? + query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) + else + query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) + end + query = query.group("a.product_code") + .order("SUM(a.qty) DESC") + .first() end end end @@ -1915,23 +2400,38 @@ end end end - def self.total_foc_items(today,current_user=nil,from=nil,to=nil) + def self.total_foc_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and sales.receipt_date between ? and ?",from,to) - .sum("a.qty") + if !from_time.nil? && !to_time.nil? + query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time) + .sum("a.qty") + else + query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) + .sum("a.qty") + end else if current_user.role == 'administrator' || current_user.role == 'manager' query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and sales.receipt_date between ? and ?",from,to) - .sum("a.qty") + if !from_time.nil? && !to_time.nil? + query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time) + .sum("a.qty") + else + query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) + .sum("a.qty") + end else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and sales.receipt_date between ? and ? and sales.shift_sale_id=?",from,to,shift.id) - .sum("a.qty") + if !from_time.nil? && !to_time.nil? + query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) + .sum("a.qty") + else + query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) + .sum("a.qty") + end end end end diff --git a/app/models/stock_journal.rb b/app/models/stock_journal.rb index c2a12f4a..f2904b13 100755 --- a/app/models/stock_journal.rb +++ b/app/models/stock_journal.rb @@ -36,12 +36,16 @@ class StockJournal < ApplicationRecord journal.save end - def self.inventory_balances(today,from,to) + def self.inventory_balances(today,from,to,from_time,to_time) if !from.nil? && !to.nil? query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") .joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code") - .where("stock_journals.created_at between '#{from}' and '#{to}'") - .group("mii.item_instance_name") + if !from_time.nil? && !to_time.nil? + query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'") + else + query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'") + end + query = query.group("mii.item_instance_name") .order("mii.item_instance_name ASC") else query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index 6ee68d97..865202b0 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -68,24 +68,46 @@
    + <% + if !@from.nil? + from_date = DateTime.parse(@from).utc.getlocal.strftime("%d-%m-%Y") + else + from_date = Time.now.utc.getlocal.strftime('%d-%m-%Y') + end + if !@to.nil? + to_date = DateTime.parse(@to).utc.getlocal.strftime("%d-%m-%Y") + else + to_date = Time.now.utc.getlocal.strftime('%d-%m-%Y') + end + if !@from_time.nil? + from_time = @from_time + else + from_time = '' + end + if !@to_time.nil? + to_time = @to_time + else + to_time = '' + end + %>
    - +
    - +
    - +
    - +
    diff --git a/app/views/transactions/sales/index.html.erb b/app/views/transactions/sales/index.html.erb index 5bfc4e61..26fbbcc5 100644 --- a/app/views/transactions/sales/index.html.erb +++ b/app/views/transactions/sales/index.html.erb @@ -17,17 +17,41 @@ <%= form_tag transactions_sales_path, :method => :get do %>
    -
    +
    - +
    -
    - - + +
    + +
    -
    + +
    + + +
    +
    - + +
    + +
    + +
    @@ -98,7 +122,7 @@ <% end %> <% else %> -

    There is no data for search....

    +

    There is no data for search....

    <% end %> @@ -116,9 +140,107 @@ From f126d2faf601dcad552025ca0264d5169a9c2504 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 28 Mar 2018 09:29:54 +0630 Subject: [PATCH 095/108] update print file.substring for jade --- app/views/origami/home/show.html.erb | 8 ++++---- app/views/origami/payments/show.html.erb | 6 +++--- app/views/origami/rooms/show.html.erb | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 4922c1df..7afa2769 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -726,9 +726,9 @@ // For Server Print - from jade if ($("#server_mode").val() == "cloud") { - code2lab.printFile(result.filepath, result.printer_url); + code2lab.printFile(result.filepath.substr(6), result.printer_url); } - + // console.log(result); // code2lab.printBill(result.filepath, result.printer_model, result.printer_url); location.reload(); @@ -776,7 +776,7 @@ createReceiptNoInFirstBillData(receipt_no,type); // For Server Print - from jade if ($("#server_mode").val() == "cloud") { - code2lab.printFile(result.filepath, result.printer_url); + code2lab.printFile(result.filepath.substr(6), result.printer_url); } location.reload(); } @@ -942,7 +942,7 @@ success: function (result) { // For Server Print - from jade if ($("#server_mode").val() == "cloud") { - code2lab.printFile(result.filepath, result.printer_url); + code2lab.printFile(result.filepath.substr(6), result.printer_url); } window.location.href = '/origami/'; } diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 001adc53..eb3eefe3 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -725,7 +725,7 @@ var customer_name = "<%= @customer.name %>"; customer_display_view(null,"reload"); // For Server Print - from jade if ($("#server_mode").val() == "cloud") { - code2lab.printFile(result.filepath, result.printer_url); + code2lab.printFile(result.filepath.substr(6), result.printer_url); } if (cashier_type=="cashier") { window.location.href = '/origami'; @@ -939,7 +939,7 @@ var customer_name = "<%= @customer.name %>"; }, function () { // For Server Print - from jade if ($("#server_mode").val() == "cloud") { - code2lab.printFile(result.filepath, result.printer_url); + code2lab.printFile(result.filepath.substr(6), result.printer_url); } if (cashier_type=="cashier") { window.location.href = '/origami'; @@ -1018,7 +1018,7 @@ var customer_name = "<%= @customer.name %>"; console.log(result); // For Server Print - from jade if ($("#server_mode").val() == "cloud") { - code2lab.printFile(result.filepath, result.printer_url); + code2lab.printFile(result.filepath.substr(6), result.printer_url); } if (cashier_type=="cashier") { window.location.href = '/origami'; diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 1b034655..424690ff 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -705,7 +705,7 @@ $("#first_bill").on('click', function(){ createReceiptNoInFirstBillData(receipt_no,""); // For Server Print - from jade if ($("#server_mode").val() == "cloud") { - code2lab.printFile(result.filepath, result.printer_url); + code2lab.printFile(result.filepath.substr(6), result.printer_url); } location.reload(); } @@ -739,7 +739,7 @@ $(".choose_payment").on('click', function () { // For Server Print - from jade if ($("#server_mode").val() == "cloud") { - code2lab.printFile(result.filepath, result.printer_url); + code2lab.printFile(result.filepath.substr(6), result.printer_url); } location.reload(); From 1873633ab27c58e027404d1c7a5c56fe0833620c Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 28 Mar 2018 11:07:48 +0630 Subject: [PATCH 096/108] check inventory --- app/controllers/origami/payments_controller.rb | 14 +------------- app/models/inventory_definition.rb | 4 ++-- app/models/stock_journal.rb | 2 +- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index f034aa57..5397c7f0 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -208,19 +208,7 @@ class Origami::PaymentsController < BaseOrigamiController render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error ", :filename => filename, :receipt_no => sale_receipt_no, :printer_name => printer_name}) - if params[:type] == "quick_service" - booking = Booking.find_by_sale_id(sale_id) - if booking.dining_facility_id.to_i>0 - table_id = booking.dining_facility_id - else - table_id = 0 - end - - booking.booking_orders.each do |order| - Order.pay_process_order_queue(order.order_id,table_id) - end - # end - end + #end end end diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb index 91823068..4634ff73 100755 --- a/app/models/inventory_definition.rb +++ b/app/models/inventory_definition.rb @@ -12,7 +12,7 @@ class InventoryDefinition < ApplicationRecord end def self.find_product_in_inventory(item) - product = InventoryDefinition.find_by_item_code(item.product_code) + product = InventoryDefinition.find_by_item_code(item.item_instance_code) if product.nil? return false, nil else @@ -21,7 +21,7 @@ class InventoryDefinition < ApplicationRecord end def self.check_balance(item,inventory_definition) # item => saleItemOBj - stock = StockJournal.where('item_code=?', item.product_code).order('created_at desc').take + stock = StockJournal.where('item_code=?', item.item_instance_code).order('created_at desc').take unless stock.nil? modify_balance(item, stock, inventory_definition) else diff --git a/app/models/stock_journal.rb b/app/models/stock_journal.rb index f2904b13..fa4bd285 100755 --- a/app/models/stock_journal.rb +++ b/app/models/stock_journal.rb @@ -8,7 +8,7 @@ class StockJournal < ApplicationRecord balance = calculate_balance(balance, item.qty) journal = StockJournal.new - journal.item_code = item.product_code + journal.item_code = item.item_instance_code journal.inventory_definition_id = inventory_definition.id journal.debit = item.qty journal.balance = balance From 204f622876241bf5221cfbacb0865af2cd588daa Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 28 Mar 2018 11:10:37 +0630 Subject: [PATCH 097/108] update sale item report --- .../reports/saleitem_controller.rb | 3 +-- .../_shift_sale_report_filter.html.erb | 2 +- app/views/reports/saleitem/index.html.erb | 23 +++++++++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index a731cb44..24c812eb 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -17,8 +17,7 @@ class Reports::SaleitemController < BaseReportController end @type = params[:sale_type] @sale_data, @other_charges,@discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type) -puts @other_charges.to_json -puts "oooooooooooooooooooooooo" + @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) @account_cate_count = Hash.new {|hash, key| hash[key] = 0} diff --git a/app/views/reports/saleitem/_shift_sale_report_filter.html.erb b/app/views/reports/saleitem/_shift_sale_report_filter.html.erb index 75a331e9..068a3f58 100755 --- a/app/views/reports/saleitem/_shift_sale_report_filter.html.erb +++ b/app/views/reports/saleitem/_shift_sale_report_filter.html.erb @@ -22,7 +22,7 @@
    + <%if @sale_type=="waste" %> + + <% else %> + + <% end %> + <%if @sale_type=="spoile" %> + + <% else %> + + <% end %> + +
    +
    + + +
    + +
    + + + +
    +
    + + +
    + +
    +
    + +
    +
    + <% end %> + + <% end %> +
    + + diff --git a/app/views/reports/waste_and_spoilage/index.html.erb b/app/views/reports/waste_and_spoilage/index.html.erb new file mode 100755 index 00000000..9b279c83 --- /dev/null +++ b/app/views/reports/waste_and_spoilage/index.html.erb @@ -0,0 +1,83 @@ + +
    +
    + + + <%= render :partial=>'shift_sale_report_filter', + :locals=>{ :period_type => true, :shift_name => true,:payments => true, :report_path =>reports_waste_and_spoilage_index_path} %> +
    + + + + + + + + +
    +
    + + +
    Report For <%= @sale_type? @sale_type : 'Waste' %>
    + <% @sale_data.each do |sale| %> + <% waste_and_spoil_item_count = 0%> + + + + + + + + + + + + + + + + + <% sale.sale_items.each do |item| %> + <% if !item.item_instance_code.nil?%> + <% waste_and_spoil_item_count += item.qty.to_i%> + + + + + + + + <% end %> + <% end %> + + + + + + + + + <% end %> +
    + Receipt No :<%= sale.receipt_no %> + Date : <%= sale.created_at.utc.getlocal.strftime("%e,%b %Y %I:%M %p") %>
    ProductCodeQtyPriceTotal Price
    <%= item.product_name %><%= item.product_code %><%= item.qty %><%= item.price %><%= item.price %>
    Total Qty: + <%= waste_and_spoil_item_count %> + Grand Total: + + <%= sale.grand_total %> + +
    +
    +
    +
    +
    diff --git a/app/views/reports/waste_and_spoilage/index.xls.erb b/app/views/reports/waste_and_spoilage/index.xls.erb new file mode 100755 index 00000000..c8521b0d --- /dev/null +++ b/app/views/reports/waste_and_spoilage/index.xls.erb @@ -0,0 +1,106 @@ + +
    +
    +
    +
    + + + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + <% @tax_profiles.each do |tax| %> + + <% end %> + + + + + + + + <% grand_total = 0 %> + <% old_grand_total = 0 %> + <% total_tax = 0 %> + <% guest_count = 0 %> + <% total_sum = 0 %> + <% discount_amt = 0 %> + <% other_amt = 0 %> + <% total_nett = 0 %> + <% rounding_adj = 0%> <% gov_tax = 0 %> <% service_charge = 0 %> + <%if @sale_data %> + <% @sale_data.each do |result| %> + + <% grand_total = grand_total.to_f + result.grand_total.to_f %> + <% old_grand_total = old_grand_total.to_f + result.old_grand_total.to_f %> + <% total_tax += result.total_tax.to_f %> + <% total_sum += result.total_amount.to_f %> + <% discount_amt += result.total_discount.to_f %> + <% rounding_adj += result.rounding_adjustment.to_f %> + + + + + + + + <%if result.customer.customer_type == "Takeaway"%> + + <%end%> + <% result.sale_taxes.each do |tax| %> + + <%end%> + + + + + + + <% end %> + + + + + <% @sale_taxes.each do |tax| %> + + <% end %> + + + + + + + + + + <% @tax_profiles.each do |tax| %> + + <% end %> + + + + + <%end%> + +
    <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
    <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
    <%= t("views.right_panel.detail.receipt_no") %><%= t :cashier %> <%= t("views.right_panel.detail.name") %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> <%= tax.name %><%= t("views.right_panel.detail.grand_total") %><%= t("views.right_panel.detail.rnd_adj_sh") %><%= t("views.right_panel.detail.grand_total") %> +
    + <%= t("views.right_panel.detail.rnd_adj_sh") %> +
    <%= result.receipt_no rescue '-' %> <%= result.cashier_name rescue '-' %><%= result.total_amount rescue '-' %><%= result.total_discount rescue '-' %>0.0<%= tax.tax_payable_amount rescue '-' %><%= result.grand_total %><%= result.rounding_adjustment.to_f rescue '-' %><%= result.grand_total_after_rounding() rescue '-'%>
     <%= total_sum rescue '-'%><%= discount_amt rescue '-'%><%= tax.st_amount.round(2) %><%= grand_total.to_f.round(2) rescue '-'%><%= rounding_adj rescue '-'%><%= grand_total.to_f.round + rounding_adj %>
     <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %><%= tax.name %><%= t("views.right_panel.detail.grand_total") %><%= t("views.right_panel.detail.rnd_adj_sh") %><%= t("views.right_panel.detail.grand_total") %> +
    + <%= t("views.right_panel.detail.rnd_adj_sh") %> +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 233d7e04..4448b75f 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -78,15 +78,13 @@ scope "(:locale)", locale: /en|mm/ do post "check_in" => "check_in_process#check_in_process" post "request_time" => "check_in_process#request_time" post "call_waiter" => "call_waiters#index" - #---------Waste and Spoile --------------# - post 'sale/:sale_id/:type/waste_and_spoilage' => 'waste_spoile#waste_and_spoilage' end end #--------- Cashier ------------# - namespace :origami do + namespace :origami do get "dashboard" => "dashboard#index" @@ -195,7 +193,7 @@ scope "(:locale)", locale: /en|mm/ do #---------Void --------------# post 'sale/:sale_id/:type/void' => 'void#overall_void' - + post 'sale/:sale_id/:type/waste_and_spoilage' => "waste_spoile#waste_and_spoilage" #---------Multiple Invoices --------------# get 'table/:table_id/table_invoices' => "table_invoices#index", :as => "table_invoice_index" @@ -404,6 +402,7 @@ scope "(:locale)", locale: /en|mm/ do resources :shiftsale, :only => [:index, :show] resources :credit_payment, :only => [:index, :show] resources :void_sale, :only => [:index, :show] + resources :waste_and_spoilage, :only => [:index, :show] resources :commission, :only => [:index, :show] resources :stock_check, :only => [:index, :show] resources :payment_method From 4faf1083d1a6bc6dc9be3453cd5c30561a49f1f2 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 30 Mar 2018 14:42:58 +0630 Subject: [PATCH 107/108] update waste and spoilage --- .../_shift_sale_report_filter.html.erb | 4 +- .../reports/waste_and_spoilage/index.html.erb | 148 +++++++++--------- .../reports/waste_and_spoilage/index.xls.erb | 126 +++++---------- 3 files changed, 111 insertions(+), 167 deletions(-) diff --git a/app/views/reports/waste_and_spoilage/_shift_sale_report_filter.html.erb b/app/views/reports/waste_and_spoilage/_shift_sale_report_filter.html.erb index 3d89a376..1c403afc 100755 --- a/app/views/reports/waste_and_spoilage/_shift_sale_report_filter.html.erb +++ b/app/views/reports/waste_and_spoilage/_shift_sale_report_filter.html.erb @@ -34,12 +34,12 @@
    -
    +
    -
    +
    diff --git a/app/views/reports/waste_and_spoilage/index.html.erb b/app/views/reports/waste_and_spoilage/index.html.erb index 9b279c83..f74f99e0 100755 --- a/app/views/reports/waste_and_spoilage/index.html.erb +++ b/app/views/reports/waste_and_spoilage/index.html.erb @@ -1,83 +1,75 @@ - -
    -
    - - - <%= render :partial=>'shift_sale_report_filter', - :locals=>{ :period_type => true, :shift_name => true,:payments => true, :report_path =>reports_waste_and_spoilage_index_path} %> -
    - - - - +
    + +
    +
    + <%= render :partial=>'shift_sale_report_filter', + :locals=>{ :period_type => true, :shift_name => true,:payments => true, :report_path =>reports_waste_and_spoilage_index_path} %> +
    - - - -
    -
    - - -
    Report For <%= @sale_type? @sale_type : 'Waste' %>
    - <% @sale_data.each do |sale| %> - <% waste_and_spoil_item_count = 0%> - - - - - - - - - - - - - - - - - <% sale.sale_items.each do |item| %> - <% if !item.item_instance_code.nil?%> - <% waste_and_spoil_item_count += item.qty.to_i%> - - - - - - - - <% end %> - <% end %> - - - - - - - - - <% end %> -
    - Receipt No :<%= sale.receipt_no %> - Date : <%= sale.created_at.utc.getlocal.strftime("%e,%b %Y %I:%M %p") %>
    ProductCodeQtyPriceTotal Price
    <%= item.product_name %><%= item.product_code %><%= item.qty %><%= item.price %><%= item.price %>
    Total Qty: - <%= waste_and_spoil_item_count %> - Grand Total: - - <%= sale.grand_total %> - -
    +
    +
    +
    + + +
    Report For <%= @sale_type? @sale_type : 'Waste' %>
    + <% @sale_data.each do |sale| %> + <% waste_and_spoil_item_count = 0%> + + + + + + + + + + + + + + + + + <% sale.sale_items.each do |item| %> + <% if !item.item_instance_code.nil?%> + <% waste_and_spoil_item_count += item.qty.to_i%> + + + + + + + + <% end %> + <% end %> + + + + + + + + <% end %> +
    + Receipt No :<%= sale.receipt_no %> + Date : <%= sale.created_at.utc.getlocal.strftime("%e,%b %Y %I:%M %p") %>
    Item NameItem CodeQtyPriceTotal Price
    <%= item.product_name %><%= item.product_code %><%= item.qty %><%= item.price %><%= item.price %>
    Total Qty: + <%= waste_and_spoil_item_count %> + Grand Total: + + <%= sale.grand_total %> + +
    +
    -
    +
    \ No newline at end of file diff --git a/app/views/reports/waste_and_spoilage/index.xls.erb b/app/views/reports/waste_and_spoilage/index.xls.erb index c8521b0d..4b4fa0a3 100755 --- a/app/views/reports/waste_and_spoilage/index.xls.erb +++ b/app/views/reports/waste_and_spoilage/index.xls.erb @@ -1,104 +1,56 @@ -
    + - +
    Report For <%= @sale_type? @sale_type : 'Waste' %>
    + <% @sale_data.each do |sale| %> + <% waste_and_spoil_item_count = 0%> + - - - <% if @shift_from %> - - <% if @shift_data.employee %> - <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> - <% end %> - - - <% end %> - - - - - - - <% @tax_profiles.each do |tax| %> - - <% end %> - - - - + + + - <% grand_total = 0 %> - <% old_grand_total = 0 %> - <% total_tax = 0 %> - <% guest_count = 0 %> - <% total_sum = 0 %> - <% discount_amt = 0 %> - <% other_amt = 0 %> - <% total_nett = 0 %> - <% rounding_adj = 0%> <% gov_tax = 0 %> <% service_charge = 0 %> - <%if @sale_data %> - <% @sale_data.each do |result| %> - - <% grand_total = grand_total.to_f + result.grand_total.to_f %> - <% old_grand_total = old_grand_total.to_f + result.old_grand_total.to_f %> - <% total_tax += result.total_tax.to_f %> - <% total_sum += result.total_amount.to_f %> - <% discount_amt += result.total_discount.to_f %> - <% rounding_adj += result.rounding_adjustment.to_f %> - - - - - - - <%if result.customer.customer_type == "Takeaway"%> - - <%end%> - <% result.sale_taxes.each do |tax| %> - - <%end%> - - - - + + + + + - + + <% sale.sale_items.each do |item| %> + <% if !item.item_instance_code.nil?%> + <% waste_and_spoil_item_count += item.qty.to_i%> + + + + + + + + <% end %> <% end %> - - - - - <% @sale_taxes.each do |tax| %> - - <% end %> - - - - - - - - - <% @tax_profiles.each do |tax| %> - - <% end %> - - - + + + - - <%end%> - + + + <% end %>
    <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
    <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
    <%= t("views.right_panel.detail.receipt_no") %><%= t :cashier %> <%= t("views.right_panel.detail.name") %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> <%= tax.name %><%= t("views.right_panel.detail.grand_total") %><%= t("views.right_panel.detail.rnd_adj_sh") %><%= t("views.right_panel.detail.grand_total") %> +
    - <%= t("views.right_panel.detail.rnd_adj_sh") %> -
    + Receipt No :<%= sale.receipt_no %> + Date : <%= sale.created_at.utc.getlocal.strftime("%e,%b %Y %I:%M %p") %>
    <%= result.receipt_no rescue '-' %> <%= result.cashier_name rescue '-' %><%= result.total_amount rescue '-' %><%= result.total_discount rescue '-' %>0.0<%= tax.tax_payable_amount rescue '-' %><%= result.grand_total %><%= result.rounding_adjustment.to_f rescue '-' %><%= result.grand_total_after_rounding() rescue '-'%>Item NameItem CodeQtyPriceTotal Price
    <%= item.product_name %><%= item.product_code %><%= item.qty %><%= item.price %><%= item.price %>
     <%= total_sum rescue '-'%><%= discount_amt rescue '-'%><%= tax.st_amount.round(2) %><%= grand_total.to_f.round(2) rescue '-'%><%= rounding_adj rescue '-'%><%= grand_total.to_f.round + rounding_adj %>
     <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %><%= tax.name %><%= t("views.right_panel.detail.grand_total") %><%= t("views.right_panel.detail.rnd_adj_sh") %><%= t("views.right_panel.detail.grand_total") %> +
    - <%= t("views.right_panel.detail.rnd_adj_sh") %> +
    Total Qty: + <%= waste_and_spoil_item_count %> + Grand Total: + + <%= sale.grand_total %> +
    From 6a9fd67bff40d8fd8489f127e0da05d0009efc9a Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 30 Mar 2018 15:24:51 +0630 Subject: [PATCH 108/108] check payment method --- app/assets/javascripts/origami.js | 2 +- app/controllers/api/payments_controller.rb | 11 + app/controllers/origami/alipay_controller.rb | 77 ++++++ app/controllers/origami/jcb_controller.rb | 3 +- app/controllers/origami/master_controller.rb | 3 +- app/controllers/origami/mpu_controller.rb | 3 +- .../origami/payments_controller.rb | 3 + .../origami/unionpay_controller.rb | 3 +- app/controllers/origami/visa_controller.rb | 3 +- app/models/sale_payment.rb | 4 +- app/views/origami/alipay/create.json.jbuilder | 5 + app/views/origami/alipay/index.html.erb | 258 ++++++++++++++++++ app/views/origami/payments/show.html.erb | 119 ++++---- config/locales/en.yml | 3 + config/locales/mm.yml | 3 + config/routes.rb | 4 + .../origami/alipay_controller_spec.rb | 5 + 17 files changed, 456 insertions(+), 53 deletions(-) create mode 100644 app/controllers/origami/alipay_controller.rb create mode 100755 app/views/origami/alipay/create.json.jbuilder create mode 100755 app/views/origami/alipay/index.html.erb create mode 100644 spec/controllers/origami/alipay_controller_spec.rb diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 7388529b..f2219711 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -323,7 +323,7 @@ function resCBPay(resMsg,card_sale_trans_id,cmd_type,payment_type,bnk_bill_amoun if(jobj.STATUS == "Approved"){ $.ajax({type: "POST", url: "/origami/payment/"+payment_type, - data: "amount="+ bnk_bill_amount + "&sale_id="+ sale_id, + data: "amount="+ bnk_bill_amount + "&sale_id="+ sale_id + "&ref_no=" + jobj.REFNUM, success:function(result){ if(result){ swal({ diff --git a/app/controllers/api/payments_controller.rb b/app/controllers/api/payments_controller.rb index 39219c6b..459589ed 100755 --- a/app/controllers/api/payments_controller.rb +++ b/app/controllers/api/payments_controller.rb @@ -84,6 +84,17 @@ class Api::PaymentsController < ActionController::API sale_payment.payment_reference = params[:payment_reference] #TODO: implement paypar implementation @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name) + when "JunctionPay" + sale_payment.payment_method = "JunctionPay" + sale_payment.received_amount = params[:amount] + sale_payment.customer_id = params[:customer_id] + sale_payment.payment_reference = params[:vochure_no] + @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name) + when "alipay" + sale_payment.payment_method = "alipay" + sale_payment.received_amount = params[:amount] + sale_payment.payment_reference = params[:payment_reference] + @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name) end end end diff --git a/app/controllers/origami/alipay_controller.rb b/app/controllers/origami/alipay_controller.rb new file mode 100644 index 00000000..3f449856 --- /dev/null +++ b/app/controllers/origami/alipay_controller.rb @@ -0,0 +1,77 @@ +class Origami::AlipayController < BaseOrigamiController + def index + @sale_id = params[:sale_id] + @cashier_type = params[:type] + # limit alipay_amount + sale_data = Sale.find_by_sale_id(@sale_id) + total = 0 + @alipaycount = 0 + @shop = Shop::ShopDetail + @rounding_adj = 0 + @can_alipay = 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 + + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "alipay" + @alipaycount = @alipaycount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_alipay = total - @alipaycount - 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 + end + + def create + cash = params[:amount] + sale_id = params[:sale_id] + ref_no = params[:ref_no] + if(Sale.exists?(sale_id)) + saleObj = Sale.find(sale_id) + shop_details = Shop::ShopDetail + + # rounding adjustment + # if shop_details.is_rounding_adj + # 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) + # end + + # saleObj = Sale.find(sale_id) + sale_payment = SalePayment.new + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "alipay",ref_no) + end + end + + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end +end diff --git a/app/controllers/origami/jcb_controller.rb b/app/controllers/origami/jcb_controller.rb index 5c06f9fe..315af34a 100644 --- a/app/controllers/origami/jcb_controller.rb +++ b/app/controllers/origami/jcb_controller.rb @@ -52,6 +52,7 @@ class Origami::JcbController < BaseOrigamiController def create cash = params[:amount] sale_id = params[:sale_id] + ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop::ShopDetail @@ -65,7 +66,7 @@ class Origami::JcbController < BaseOrigamiController # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "jcb") + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "jcb",ref_no) end end diff --git a/app/controllers/origami/master_controller.rb b/app/controllers/origami/master_controller.rb index 858d0125..dc3a83d9 100644 --- a/app/controllers/origami/master_controller.rb +++ b/app/controllers/origami/master_controller.rb @@ -50,6 +50,7 @@ class Origami::MasterController < BaseOrigamiController def create cash = params[:amount] sale_id = params[:sale_id] + ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop::ShopDetail @@ -63,7 +64,7 @@ class Origami::MasterController < BaseOrigamiController # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "master") + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "master",ref_no) end end diff --git a/app/controllers/origami/mpu_controller.rb b/app/controllers/origami/mpu_controller.rb index 1b125bda..7d3ded34 100644 --- a/app/controllers/origami/mpu_controller.rb +++ b/app/controllers/origami/mpu_controller.rb @@ -51,6 +51,7 @@ class Origami::MpuController < BaseOrigamiController def create cash = params[:amount] sale_id = params[:sale_id] + ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop::ShopDetail @@ -64,7 +65,7 @@ class Origami::MpuController < BaseOrigamiController # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "mpu") + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "alipay",ref_no) end end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 5397c7f0..c31dd44d 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -226,6 +226,7 @@ class Origami::PaymentsController < BaseOrigamiController @jcbcount= 0.0 @mastercount = 0.0 @unionpaycount = 0.0 + @alipaycount = 0.0 @junctionpaycount = 0.0 @credit = 0.0 @sale_data = Sale.find_by_sale_id(sale_id) @@ -346,6 +347,8 @@ class Origami::PaymentsController < BaseOrigamiController @junctionpaycount += spay.payment_amount elsif spay.payment_method == "creditnote" @credit += spay.payment_amount + elsif spay.payment_method == "alipay" + @alipaycount += spay.payment_amount end end end diff --git a/app/controllers/origami/unionpay_controller.rb b/app/controllers/origami/unionpay_controller.rb index 7213af6d..ec941a20 100644 --- a/app/controllers/origami/unionpay_controller.rb +++ b/app/controllers/origami/unionpay_controller.rb @@ -48,6 +48,7 @@ class Origami::UnionpayController < BaseOrigamiController def create cash = params[:amount] sale_id = params[:sale_id] + ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop::ShopDetail @@ -62,7 +63,7 @@ class Origami::UnionpayController < BaseOrigamiController # saleObj = Sale.find(sale_id) #end rounding adjustment sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "unionpay") + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "unionpay",ref_no) end end diff --git a/app/controllers/origami/visa_controller.rb b/app/controllers/origami/visa_controller.rb index 346b66d1..8cc2bbe3 100644 --- a/app/controllers/origami/visa_controller.rb +++ b/app/controllers/origami/visa_controller.rb @@ -48,6 +48,7 @@ class Origami::VisaController < BaseOrigamiController def create cash = params[:amount] sale_id = params[:sale_id] + ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop::ShopDetail @@ -62,7 +63,7 @@ class Origami::VisaController < BaseOrigamiController # saleObj = Sale.find(sale_id) #end rounding adjustment sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "visa") + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "visa",ref_no) end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 3ff4697e..6b08a9fa 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -51,6 +51,8 @@ class SalePayment < ApplicationRecord payment_status = foc_payment when "JunctionPay" payment_status = junction_pay_payment + when "alipay" + payment_status = external_terminal_card_payment(:alipay) else puts "it was something else" end @@ -230,7 +232,7 @@ class SalePayment < ApplicationRecord payment_status = false self.payment_method = method self.payment_amount = self.received_amount - self.payment_reference = self.card_payment_reference + # self.payment_reference = self.card_payment_reference self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f self.payment_status = "paid" payment_method = self.save! diff --git a/app/views/origami/alipay/create.json.jbuilder b/app/views/origami/alipay/create.json.jbuilder new file mode 100755 index 00000000..9767a7d8 --- /dev/null +++ b/app/views/origami/alipay/create.json.jbuilder @@ -0,0 +1,5 @@ +if(@status) + json.status @status +else + json.status false +end diff --git a/app/views/origami/alipay/index.html.erb b/app/views/origami/alipay/index.html.erb new file mode 100755 index 00000000..a9959512 --- /dev/null +++ b/app/views/origami/alipay/index.html.erb @@ -0,0 +1,258 @@ +
    + + +
    +
    + + + +
    +
    +
    + <% if @bank_integration == '1' %> +
    +
    + + +
    +
    +
    + <% end %> +
    +
    + + <%@can_alipay = @can_alipay +@rounding_adj%> + +
    +
    +
    + <% if @alipaycount != 0 %> +
    +
    + + +
    +
    +
    + <% end %> +
    +
    + + +
    +
    +
    +
    +
    +
    + +
    0.0
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    1
    +
    2
    +
    3
    +
    +
    +
    4
    +
    5
    +
    6
    +
    +
    +
    7
    +
    8
    +
    9
    +
    +
    +
    0
    +
    .
    +
    00
    +
    +
    +
    Nett
    +
    Del
    +
    Clr
    +
    +
    +
    +
    +
    1000
    +
    3000
    +
    +
    +
    5000
    +
    10000
    +
    +
    +
    Pay
    +
    +
    +
    +
    +
    + +
    + + +
    +
    +
    + + diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index eb3eefe3..c33b6493 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -182,103 +182,125 @@
    <% if @other != 0.0 %> -
    -
    -
    MPU
    -
    <%= number_with_precision(@other, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    -
    +
    <% else %> - + <% if @ppamount != 0.0 %>
    -
    -
    Redeem
    -
    <%= number_with_precision(@ppamount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    -
    <% else %> - <% end %> + <% if @visacount != 0.0 %>
    -
    -
    VISA
    -
    <%= number_with_precision(@visacount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    -
    <% else %> - <% end %> + <% if @jcbcount != 0.0 %>
    -
    -
    JCB
    -
    <%= number_with_precision(@jcbcount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    -
    <% else %> - <% end %> + <% if @mastercount != 0.0 %>
    -
    -
    MASTER
    -
    <%= number_with_precision(@mastercount, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i ) %>
    -
    <% else %> - <% end %> + <% if @unionpaycount != 0.0 %>
    -
    -
    UNIONPAY
    -
    <%= number_with_precision(@unionpaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    -
    <% else %> + + + <% if @alipaycount != 0.0 %> +
    + <% else %> + + <% if @junctionpaycount != 0.0 %>
    -
    -
    JUNCTION PAY
    -
    <%= number_with_precision(@junctionpaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    -
    <% else %> - <% end %> + +
    Balance
    <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    @@ -584,6 +606,9 @@ var customer_name = "<%= @customer.name %>"; else if(payment_type == "UNIONPAY" && $('#unionpaycount').text()==0 && sub_total != 0.0){ swal("Oops","Please Pay with UNIONPAY Payment","warning"); } + else if(payment_type == "Alipay" && $('#alipaycount').text()==0 && sub_total != 0.0){ + swal("Oops","Please Pay with Alipay Payment","warning"); + } else if(payment_type == "JUNCTIONPAY" && $('#junctionpaycount').text()==0 && sub_total != 0.0){ swal("Oops","Please Pay with JUNCTIONPAY Payment","warning"); } @@ -866,8 +891,9 @@ var customer_name = "<%= @customer.name %>"; var jcb1 = $('#jcbcount').text(); var master1 = $('#mastercount').text(); var unionpay1 = $('#unionpaycount').text(); + var alipay1 = $('#alipaycount').text(); var junctionpay1 = $('#junctionpaycount').text(); - var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1) + parseFloat(unionpay1) + parseFloat(junctionpay1); + var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1) + parseFloat(unionpay1) + parseFloat(alipay1) + parseFloat(junctionpay1); var total = $('#amount_due').text(); var amt = 0; <% if precision.to_i > 0 %>; @@ -895,9 +921,10 @@ var customer_name = "<%= @customer.name %>"; var jcb = $('#jcbcount').text(); var master = $('#mastercount').text(); var unionpay = $('#unionpaycount').text(); + var alipay = $('#alipaycount').text(); var junctionpay = $('#junctionpaycount').text(); var amount_due = $('#amount_due').text(); - var total = parseFloat(cash) + parseFloat(credit) + parseFloat(card) + parseFloat(paypar) + parseFloat(visa) + parseFloat(jcb) + parseFloat(master) + parseFloat(unionpay) + parseFloat(junctionpay) + var total = parseFloat(cash) + parseFloat(credit) + parseFloat(card) + parseFloat(paypar) + parseFloat(visa) + parseFloat(jcb) + parseFloat(master) + parseFloat(unionpay) + parseFloat(alipay) + parseFloat(junctionpay) var result = parseFloat(amount_due) - parseFloat(total); <% if precision.to_i > 0 %> $('#balance').text(parseFloat(result).toFixed(<%= precision %>)); diff --git a/config/locales/en.yml b/config/locales/en.yml index 84a7b03a..dba88aee 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -122,6 +122,8 @@ en: mpu: "MPU" jcb: "JCB" visa: "VISA" + master: "MASTER" + alipay: "Alipay" credit: "CREDIT" other_payment: "Other Payment" percentage: "PERCENTAGE" @@ -412,6 +414,7 @@ en: redeem_sales: "Redeem Sales" cash_sales: "Cash Sales" credit_sales: "Credit Sales" + alipay_sales: "Alipay Sales" foc_sales: "FOC Sales" foc_item: "Item FOC" net_amount: "Net Amount" diff --git a/config/locales/mm.yml b/config/locales/mm.yml index f18136c4..e06733e9 100644 --- a/config/locales/mm.yml +++ b/config/locales/mm.yml @@ -117,6 +117,8 @@ mm: mpu: "MPU" jcb: "JCB" visa: "VISA" + master: "MASTER" + alipay: "Alipay" credit: "အကြွေး" other_payment: "အခြားငွေပေးဆောင်မှုများ" percentage: "ရာခိုင်နှုန်း" @@ -404,6 +406,7 @@ mm: master_sales: "Master ရောင်းရငွေ" visa_sales: "Visa ရောင်းရငွေ" jcb_sales: "JCB ရောင်းရငွေ" + alipay_sales: "Alipay ရောင်းရငွေ" redeem_sales: "ဆုကြေးပြန်သုံးငွေနှင့် ရောင်းရငွေ" cash_sales: "ငွေသား ရောင်းရငွေ" credit_sales: "အကြွေး ရောင်းရငွေ" diff --git a/config/routes.rb b/config/routes.rb index 233d7e04..6416f236 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -181,6 +181,8 @@ scope "(:locale)", locale: /en|mm/ do post 'payment/paypar' => 'paypar_payments#create' post 'payment/credit' => 'credit_payments#create' post 'payment/voucher' => 'voucher_payments#create' + post 'payment/alipay' => 'alipay#create' + post 'payment/junctionpay' => 'junctionpay#create' get 'sale/:sale_id/:type/payment/credit_payment' => "credit_payments#index" get 'sale/:sale_id/:type/payment/others_payment' => "others_payments#index" @@ -191,6 +193,8 @@ scope "(:locale)", locale: /en|mm/ do get 'sale/:sale_id/:type/payment/others_payment/UNIONPAY' => "unionpay#index" get 'sale/:sale_id/:type/payment/others_payment/Redeem' => "redeem_payments#index" get 'sale/:sale_id/:type/payment/others_payment/Voucher' => "voucher#index" + get 'sale/:sale_id/:type/payment/others_payment/JunctionPay' => "junction_pay#index" + get 'sale/:sale_id/:type/payment/others_payment/Alipay' => "alipay#index" #---------Void --------------# post 'sale/:sale_id/:type/void' => 'void#overall_void' diff --git a/spec/controllers/origami/alipay_controller_spec.rb b/spec/controllers/origami/alipay_controller_spec.rb new file mode 100644 index 00000000..5994c9fa --- /dev/null +++ b/spec/controllers/origami/alipay_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Origami::AlipayController, type: :controller do + +end