From 3b99016f80fdffcb60f2b8356533e5c7a5b7b3d3 Mon Sep 17 00:00:00 2001 From: Phyo Date: Wed, 14 Jun 2017 17:13:43 +0630 Subject: [PATCH 1/2] Limit paid amount for JCB, Visa and Master Card --- app/controllers/origami/jcb_controller.rb | 15 +++ app/controllers/origami/master_controller.rb | 14 +++ app/controllers/origami/mpu_controller.rb | 15 +++ .../origami/payments_controller.rb | 9 ++ app/controllers/origami/visa_controller.rb | 14 +++ app/views/origami/jcb/index.html.erb | 43 ++++++--- app/views/origami/master/index.html.erb | 23 ++++- app/views/origami/mpu/index.html.erb | 43 ++++++--- app/views/origami/payments/show.html.erb | 91 +++++++++++++++---- .../origami/redeem_payments/index.html.erb | 22 ++++- app/views/origami/visa/index.html.erb | 23 ++++- 11 files changed, 264 insertions(+), 48 deletions(-) diff --git a/app/controllers/origami/jcb_controller.rb b/app/controllers/origami/jcb_controller.rb index b13790c3..5bed3470 100644 --- a/app/controllers/origami/jcb_controller.rb +++ b/app/controllers/origami/jcb_controller.rb @@ -2,6 +2,21 @@ class Origami::JcbController < BaseOrigamiController def index @sale_id = params[:sale_id] + + # limit jcb_amount + sale_data = Sale.find_by_sale_id(@sale_id) + total = sale_data.grand_total + @jcbcount = 0 + others = 0 + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "jcb" + @jcbcount = @jcbcount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_jcb = total - @jcbcount - others + end def create diff --git a/app/controllers/origami/master_controller.rb b/app/controllers/origami/master_controller.rb index 714d4b6a..67107167 100644 --- a/app/controllers/origami/master_controller.rb +++ b/app/controllers/origami/master_controller.rb @@ -2,6 +2,20 @@ class Origami::MasterController < BaseOrigamiController def index @sale_id = params[:sale_id] + + # limit master_amount + sale_data = Sale.find_by_sale_id(@sale_id) + total = sale_data.grand_total + @mastercount = 0 + others = 0 + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "master" + @mastercount = @mastercount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_master = total - @mastercount - others end def create diff --git a/app/controllers/origami/mpu_controller.rb b/app/controllers/origami/mpu_controller.rb index 263e55f7..3707d1f4 100644 --- a/app/controllers/origami/mpu_controller.rb +++ b/app/controllers/origami/mpu_controller.rb @@ -2,6 +2,21 @@ class Origami::MpuController < BaseOrigamiController def index @sale_id = params[:sale_id] + + # limit mpu_amount + sale_data = Sale.find_by_sale_id(@sale_id) + total = sale_data.grand_total + @mpucount = 0 + others = 0 + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "mpu" + @mpucount = @mpucount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_mpu = total - @mpucount - others + end def create diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 97d08547..7eb93d92 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -20,6 +20,9 @@ class Origami::PaymentsController < BaseOrigamiController @cash = 0.0 @other = 0.0 @ppamount = 0.0 + @visacount= 0.0 + @jcbcount= 0.0 + @mastercount = 0.0 @sale_data = Sale.find_by_sale_id(sale_id) #get customer amount @@ -60,6 +63,12 @@ class Origami::PaymentsController < BaseOrigamiController @other += spay.payment_amount elsif spay.payment_method == "paypar" @ppamount += spay.payment_amount + elsif spay.payment_method == "visa" + @visacount += spay.payment_amount + elsif spay.payment_method == "jcb" + @jcbcount += spay.payment_amount + elsif spay.payment_method == "master" + @mastercount += spay.payment_amount end end end diff --git a/app/controllers/origami/visa_controller.rb b/app/controllers/origami/visa_controller.rb index 05f475a9..3cb8cabb 100644 --- a/app/controllers/origami/visa_controller.rb +++ b/app/controllers/origami/visa_controller.rb @@ -2,6 +2,20 @@ class Origami::VisaController < BaseOrigamiController def index @sale_id = params[:sale_id] + + # limit visa_amount + sale_data = Sale.find_by_sale_id(@sale_id) + total = sale_data.grand_total + @visacount = 0 + others = 0 + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "visa" + @visacount = @visacount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_visa = total - @visacount - others end def create diff --git a/app/views/origami/jcb/index.html.erb b/app/views/origami/jcb/index.html.erb index a1a5a2cd..6d08b25a 100644 --- a/app/views/origami/jcb/index.html.erb +++ b/app/views/origami/jcb/index.html.erb @@ -9,6 +9,22 @@
+
+
+ + +
+
+
+ <% if @jcbcount != 0 %> +
+
+ + +
+
+
+ <% end %>
@@ -75,7 +91,7 @@
- +
@@ -125,16 +141,19 @@ $(document).on('click', '.cashier_number', function(event){ $('#jcb_pay').on('click',function(){ var amount = $('#amount').text(); var sale_id = "<%= @sale_id %>"; - - $.ajax({type: "POST", - url: "<%= origami_payment_jcb_path %>", - data: "amount="+ amount + "&sale_id="+ sale_id, - success:function(result){ - if(result){ - alert("Payment success") - window.location.href = '/origami/sale/'+ sale_id + "/payment"; - } - } - }); + if(parseFloat(amount) <= "<%= @can_jcb %>"){ + $.ajax({type: "POST", + url: "<%= origami_payment_jcb_path %>", + data: "amount="+ amount + "&sale_id="+ sale_id, + success:function(result){ + if(result){ + alert("Payment success") + window.location.href = '/origami/sale/'+ sale_id + "/payment"; + } + } + }); + }else{ + alert("Paid Amount is over!"); + } }) diff --git a/app/views/origami/master/index.html.erb b/app/views/origami/master/index.html.erb index da481022..5767ad0f 100644 --- a/app/views/origami/master/index.html.erb +++ b/app/views/origami/master/index.html.erb @@ -9,6 +9,22 @@
+
+
+ + +
+
+
+ <% if @mastercount != 0 %> +
+
+ + +
+
+
+ <% end %>
@@ -75,7 +91,7 @@
- +
@@ -122,7 +138,7 @@ $(document).on('click', '.cashier_number', function(event){ $('#master_pay').on('click',function(){ var amount = $('#amount').text(); var sale_id = "<%= @sale_id %>"; - + if(parseFloat(amount) <= "<%= @can_master %>"){ $.ajax({type: "POST", url: "<%= origami_payment_master_path %>", data: "amount="+ amount + "&sale_id="+ sale_id, @@ -133,5 +149,8 @@ $(document).on('click', '.cashier_number', function(event){ } } }); + }else{ + alert("Paid Amount is over!"); + } }) diff --git a/app/views/origami/mpu/index.html.erb b/app/views/origami/mpu/index.html.erb index 10caf0b3..f58ca552 100644 --- a/app/views/origami/mpu/index.html.erb +++ b/app/views/origami/mpu/index.html.erb @@ -9,6 +9,22 @@
+
+
+ + +
+
+
+ <% if @mpucount != 0 %> +
+
+ + +
+
+
+ <% end %>
@@ -75,7 +91,7 @@
- +
@@ -122,16 +138,19 @@ $(document).on('click', '.cashier_number', function(event){ $('#mpu_pay').on('click',function(){ var amount = $('#amount').text(); var sale_id = "<%= @sale_id %>"; - - $.ajax({type: "POST", - url: "<%= origami_payment_mpu_path %>", - data: "amount="+ amount + "&sale_id="+ sale_id, - success:function(result){ - if(result){ - alert("Payment success") - window.location.href = '/origami/sale/'+ sale_id + "/payment"; - } - } - }); + if(parseFloat(amount) <= "<%= @can_mpu %>"){ + $.ajax({type: "POST", + url: "<%= origami_payment_mpu_path %>", + data: "amount="+ amount + "&sale_id="+ sale_id, + success:function(result){ + if(result){ + alert("Payment success") + window.location.href = '/origami/sale/'+ sale_id + "/payment"; + } + } + }); + }else{ + alert("Paid Amount is over!") + } }) diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index b9c2fdbf..eb5d3c67 100644 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -102,23 +102,76 @@

-
- <% if @other != 0.0 %> -
-
MPU
-
<%= @other %>
+
Other Payment
+
+
+ + <% if @other != 0.0 %> +
+
MPU
+
<%= @other %>
+
+ <% else %> + + <% end %> + + <% if @ppamount != 0.0 %> +
+
Paypar
+
<%= @ppamount %>
+
+ <% else %> + + <% end %> + + <% if @visacount != 0.0 %> +
+
Visa
+
<%= @visacount %>
+
+ <% else %> + + <% end %> + + <% if @jcbcount != 0.0 %> +
+
JCB
+
<%= @jcbcount %>
+
+ <% else %> + + <% end %> + + <% if @mastercount != 0.0 %> +
+
Master
+
<%= @mastercount %>
+
+ <% else %> + + <% end %> + <% if @other == 0.0 && @ppamount == 0.0 %> +
+
+
<%= @ppamount %>
+
+ <% end %>
- <% elsif @ppamount != 0.0 %> -
-
Paypar
-
<%= @ppamount %>
-
- <% else %> -
-
Others Payment
-
<%= @ppamount %>
-
- <% end %>

@@ -275,8 +328,12 @@ function update_balance(){ var cash = $('#cash').text(); var credit = $('#credit').text(); var card = $('#others').text(); + var paypar = $('#ppamount').text(); + var visa = $('#visacount').text(); + var jcb = $('#jcbcount').text(); + var master = $('#mastercount').text(); var amount_due = $('#amount_due').text(); - var total = parseFloat(cash) + parseFloat(credit) + parseFloat(card) + var total = parseFloat(cash) + parseFloat(credit) + parseFloat(card) + parseFloat(paypar) + parseFloat(visa) + parseFloat(jcb) + parseFloat(master) var result = amount_due - total; $('#balance').text(result.toFixed(2)); } diff --git a/app/views/origami/redeem_payments/index.html.erb b/app/views/origami/redeem_payments/index.html.erb index 4d0ab223..0991e562 100644 --- a/app/views/origami/redeem_payments/index.html.erb +++ b/app/views/origami/redeem_payments/index.html.erb @@ -5,7 +5,23 @@
- + + +
+
+
+ <% if @payparcount > 0 %> +
+
+ + +
+
+
+ <% end %> +
+
+

@@ -19,10 +35,10 @@
- <% if @payparcount > 0 %> +
diff --git a/app/views/origami/visa/index.html.erb b/app/views/origami/visa/index.html.erb index 72cd94aa..e01ca696 100644 --- a/app/views/origami/visa/index.html.erb +++ b/app/views/origami/visa/index.html.erb @@ -9,6 +9,22 @@
+
+
+ + +
+
+
+ <% if @visacount != 0 %> +
+
+ + +
+
+
+ <% end %>
@@ -75,7 +91,7 @@
- +
@@ -122,7 +138,7 @@ $(document).on('click', '.cashier_number', function(event){ $('#visa_pay').on('click',function(){ var amount = $('#amount').text(); var sale_id = "<%= @sale_id %>"; - + if(parseFloat(amount) <= "<%= @can_visa %>"){ $.ajax({type: "POST", url: "<%= origami_payment_visa_path %>", data: "amount="+ amount + "&sale_id="+ sale_id, @@ -133,5 +149,8 @@ $(document).on('click', '.cashier_number', function(event){ } } }); + }else{ + alert("Paid Amount is over!"); + } }) From 109d1b643523811d5655ea1baa8de45f9af1f86f Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 14 Jun 2017 18:56:11 +0630 Subject: [PATCH 2/2] update --- app/forms/shop_form.rb | 8 ++++---- app/pdf/receipt_bill_pdf.rb | 14 ++++++-------- app/reports/menu_report.rb | 10 +++++----- app/views/kaminari/_paginator.html.erb | 12 ++++++------ 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/app/forms/shop_form.rb b/app/forms/shop_form.rb index 19af84a5..179e73fd 100644 --- a/app/forms/shop_form.rb +++ b/app/forms/shop_form.rb @@ -1,7 +1,7 @@ #Form object to use during the installation process - will handle creation of shop model into db after verification from the cloud #provising service through license verification -class ShopForm < ActiveModel - :attr_accessor :logo, :name, :address, :township, :city, :state, :country, :license, :base_currency, :password, :password_confirmation - -end +# class ShopForm < ActiveModel +# # attr_accessor :logo, :name, :address, :township, :city, :state, :country, :license, :base_currency, :password, :password_confirmation +# +# end diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index dbaea572..c03e7791 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -8,9 +8,9 @@ class ReceiptBillPdf < Prawn::Document self.qty_width = 20 self.total_width = 40 self.item_width = self.page_width - ((self.price_width + self.qty_width + self.total_width)+(self.margin*4)) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=80 + self.label_width=80 # @item_width = self.page_width.to_i / 2 # @qty_width = @item_width.to_i / 3 @@ -31,7 +31,7 @@ class ReceiptBillPdf < Prawn::Document cashier_info(sale_data, customer_name) line_items(sale_items, food_total, beverage_total) - all_total(sale_data) + all_total(sale_data) footer end @@ -96,7 +96,7 @@ class ReceiptBillPdf < Prawn::Document stroke_horizontal_rule add_line_item_row(sale_items, food_total, beverage_total) - + end def add_line_item_row(sale_items, food_total, beverage_total) @@ -110,17 +110,15 @@ class ReceiptBillPdf < Prawn::Document total_price = item.qty*item.unit_price price = item.unit_price product_name = item.product_name - + y_position = cursor pad_top(15) { - # @item_width.to_i + @half_qty.to_i text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :overflow => :shrink_to_fix, :size => self.item_font_size, :overflow => :shrink_to_fix text_box "#{price}", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix text_box "#{qty.to_i}", :at =>[item_name_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix text_box "#{total_price}", :at =>[(item_name_width+2),y_position], :width =>self.total_width+2, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - } move_down 3 end @@ -151,7 +149,7 @@ class ReceiptBillPdf < Prawn::Document end def all_total(sale_data) - item_name_width = self.item_width + item_name_width = self.item_width move_down 5 y_position = cursor diff --git a/app/reports/menu_report.rb b/app/reports/menu_report.rb index ca430f0a..2a17e851 100644 --- a/app/reports/menu_report.rb +++ b/app/reports/menu_report.rb @@ -1,5 +1,5 @@ -class MenuReport < Compendium::Report - query :list, collect: :active_record do |params| - Menu.all - end -end +# class MenuReport < Compendium::Report +# query :list, collect: :active_record do |params| +# Menu.all +# end +# end diff --git a/app/views/kaminari/_paginator.html.erb b/app/views/kaminari/_paginator.html.erb index 4fb445fd..c52381e2 100644 --- a/app/views/kaminari/_paginator.html.erb +++ b/app/views/kaminari/_paginator.html.erb @@ -10,14 +10,14 @@ -<% end -%> +<% end %>