From 850c134ed2c9dfd7f77fe59747c5b53408269d69 Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 29 Mar 2018 11:17:35 +0630 Subject: [PATCH 1/7] check product sale --- app/models/ability.rb | 5 +++++ app/models/sale.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 0b1edcc3..b1930e1b 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -179,6 +179,11 @@ class Ability can :remove_all_discount, :discount can :member_discount, :discount + can :move_dining, :movetable + can :moving, :movetable + + can :move_dining, :moveroom + can :manage, Customer can :manage, DiningQueue diff --git a/app/models/sale.rb b/app/models/sale.rb index 970896bf..ebb32ec3 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -950,7 +950,7 @@ def self.get_menu_item_query(order_by) " LEFT JOIN sale_items si ON si.item_instance_code = mii.item_instance_code" + " LEFT JOIN sales s ON s.sale_id = si.sale_id") .where("(CASE WHEN s.sale_status IS NOT NULL THEN s.sale_status='completed' ELSE 1 END)") - .group("mc.id, (CASE WHEN si.product_name IS NOT NULL THEN si.product_name ELSE mii.item_instance_name END)") + .group("mc.id, (CASE WHEN si.product_name IS NOT NULL THEN si.product_name ELSE CONCAT(menu_items.name,' - ',mii.item_instance_name) END)") .order("si.qty #{order_by}, menu_items.menu_category_id #{order_by}") end #product sale report query From 386c5291a120c63313d7b39328cf414b75cc25dc Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 29 Mar 2018 16:16:19 +0630 Subject: [PATCH 2/7] update waste and spoile --- .../origami/waste_spoile_controller .rb | 130 ++++++++++++++++++ app/models/sale_item.rb | 3 +- app/views/origami/home/show.html.erb | 87 ++++++++++-- config/routes.rb | 6 + 4 files changed, 213 insertions(+), 13 deletions(-) create mode 100755 app/controllers/origami/waste_spoile_controller .rb diff --git a/app/controllers/origami/waste_spoile_controller .rb b/app/controllers/origami/waste_spoile_controller .rb new file mode 100755 index 00000000..72180786 --- /dev/null +++ b/app/controllers/origami/waste_spoile_controller .rb @@ -0,0 +1,130 @@ +class Origami::WasteSpoileController < BaseOrigamiController + def index + + end + def waste_and_spoile + + sale_id = params[:sale_id] + remark = params[:remark] + order_source = params[:type] #tax profile source + if Sale.exists?(sale_id) + sale = Sale.find_by_sale_id(sale_id) + + if sale.discount_type == "member_discount" + sale.update_attributes(total_discount: 0) + sale.compute_by_sale_items(sale_id, sale.sale_items,0,order_source) + end + + sale.payment_status = remark + sale.sale_status = remark + sale.save + + # add to sale item with foc + sale_items = SaleItem.where("sale_id='#{ sale_id }' and status is null") + + sale_items.each do|item| + SaleItem.update_existing_item(item.qty, item, sale_id, remark, item.unit_price, item.price) + end + + if sale.bookings[0].dining_facility_id.to_i > 0 + table_avaliable = true + table_count = 0 + table = sale.bookings[0].dining_facility + table.bookings.each do |booking| + if booking.booking_status != 'moved' + if booking.sale_id + if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' + table_avaliable = false + table_count += 1 + else + table_avaliable = true + end + else + table_avaliable = false + table_count += 1 + end + end + end + + if table_avaliable && table_count == 0 + table.status = 'available' + table.save + end + else + table = nil + end + + # FOr Sale Audit + action_by = current_user.name + # remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}" + sale_audit = SaleAudit.record_audit_for_edit(sale_id,sale.cashier_id, action_by,remark,remark ) + + # For Print + + member_info = nil + rebate_amount = nil + current_balance = nil + + # For Cashier by Zone + bookings = Booking.where("sale_id='#{sale_id}'") + if bookings.count > 1 + # for Multiple Booking + if bookings[0].dining_facility_id.to_i>0 + table = DiningFacility.find(bookings[0].dining_facility_id) + end + end + + if bookings[0].dining_facility_id.to_i > 0 + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + else + shift = ShiftSale.find(sale.shift_sale_id) + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + end + + + # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + unique_code = "ReceiptBillPdf" + customer= Customer.find(sale.customer_id) + + #shop detail + shop_details = Shop.find(1) + # get member information + rebate = MembershipSetting.find_by_rebate(1) + if customer.membership_id != nil && rebate + member_info = Customer.get_member_account(customer) + rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no) + current_balance = SaleAudit.paymal_search(sale_id) + end + + # get printer info + print_settings=PrintSetting.find_by_unique_code(unique_code) + # Calculate Food and Beverage Total + item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items) + discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) + + printer = Printer::ReceiptPrinter.new(print_settings) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil) + result = { + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings + } + + # Mobile Print + render :json => result.to_json + # end + + #end print + + # update complete order items in oqs + SaleOrder.where("sale_id = '#{ sale_id }'").find_each do |sodr| + AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi| + aoi.delivery_status = 1 + aoi.save + end + end + end + end + +end \ No newline at end of file diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 64e0ec73..fc32098f 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -38,7 +38,8 @@ class SaleItem < ApplicationRecord sale_item.product_alt_name = item.product_alt_name sale_item.account_id = item.account_id sale_item.status = type - if type == "foc" || type == "promotion" || type == "void" + sale_item.remark = type + if type == "foc" || type == "promotion" || type == "void" || type == "waste" || type == "spoile" sale_item.qty = qty * (-1) else sale_item.qty = qty diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 7afa2769..8ffe8964 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -488,6 +488,11 @@ + +
+ +
+
+ +
+ + + @@ -737,19 +768,19 @@ }); // click select option icon for add - $(document).on('click', '.payment_btn', function(event){ - active = $(this).hasClass('selected-payment'); - value = $(this).data('value'); - type = $(this).data('type'); - group = $(this).data('group'); - payments = $(".payment_btn"); + $(document).on('click', '.payment_btn', function(event){ + active = $(this).hasClass('selected-payment'); + value = $(this).data('value'); + type = $(this).data('type'); + group = $(this).data('group'); + payments = $(".payment_btn"); - if (active) { - $(this).removeClass('selected-payment'); - }else{ - $(this).addClass('selected-payment'); - } - }); //End selecct attribute buttom + if (active) { + $(this).removeClass('selected-payment'); + }else{ + $(this).addClass('selected-payment'); + } + }); //End selecct attribute buttom $(".choose_payment").on('click', function () { $( "#loading_wrapper").show(); @@ -1014,4 +1045,36 @@ }); return attribute_arr; } + + function waste_and_spoilage(remark) { + swal({ + title: "Alert", + text: "Are you sure want to " + remark +" ?", + type: "warning", + showCancelButton: true, + confirmButtonColor: "#DD6B55", + confirmButtonText: "Yes, " +remark+ " it!", + closeOnConfirm: false + }, function (isConfirm) { + if (isConfirm) { + var sale_id = "<%= @obj_sale.sale_id rescue "" %>" + var url = "/origami/sale/" + sale_id + '/cashier/waste_and_spoilage'; + +console.log(url) + $.ajax({ + type: 'POST', + url: url, + data: "remark="+ remark + "&sale_id=" + sale_id, + success: function (result) { + console.log(result) + // For Server Print - from jade + // if ($("#server_mode").val() == "cloud") { + // code2lab.printFile(result.filepath.substr(6), result.printer_url); + // } + // window.location.href = '/origami/'; + } + }); + } + }); + } diff --git a/config/routes.rb b/config/routes.rb index 4293a341..233d7e04 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -78,6 +78,8 @@ 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 @@ -85,6 +87,7 @@ scope "(:locale)", locale: /en|mm/ do #--------- Cashier ------------# namespace :origami do + get "dashboard" => "dashboard#index" get "quick_service" => "quick_service#index" @@ -192,6 +195,8 @@ scope "(:locale)", locale: /en|mm/ do #---------Void --------------# post 'sale/:sale_id/:type/void' => 'void#overall_void' + + #---------Multiple Invoices --------------# get 'table/:table_id/table_invoices' => "table_invoices#index", :as => "table_invoice_index" get 'table/:table_id/table_invoice/:invoice_id' => "table_invoices#show", :as => "table_invoice_show" @@ -245,6 +250,7 @@ scope "(:locale)", locale: /en|mm/ do resources :second_display #second display routes post '/customer_view' => "second_display#customer_view",:as => "customer_view", :defaults => { :format => 'json' } + end #--------- Waiter/Ordering Station ------------# From 15f0abac21857e053db239666ff60ef2e50f4052 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 29 Mar 2018 16:18:48 +0630 Subject: [PATCH 3/7] update tax migrate --- db/migrate/20170403183755_create_tax_profiles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20170403183755_create_tax_profiles.rb b/db/migrate/20170403183755_create_tax_profiles.rb index f5210bbb..2c96fd0d 100755 --- a/db/migrate/20170403183755_create_tax_profiles.rb +++ b/db/migrate/20170403183755_create_tax_profiles.rb @@ -2,7 +2,7 @@ class CreateTaxProfiles < ActiveRecord::Migration[5.1] def change create_table :tax_profiles do |t| t.string :name, :null => false - t.string :group_type, :null => false + t.string :group_type t.decimal :rate, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.boolean :inclusive, :null => false, :default => false t.integer :order_by, :null => false, :default => 1 From 75f3377d75648b290975f908b176700a86fe2647 Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 29 Mar 2018 19:39:29 +0630 Subject: [PATCH 4/7] change product sale report --- app/views/reports/product_sale/index.html.erb | 38 +++++++++++++------ app/views/reports/product_sale/index.xls.erb | 30 +++++++++++---- 2 files changed, 50 insertions(+), 18 deletions(-) mode change 100755 => 100644 app/views/reports/product_sale/index.html.erb mode change 100755 => 100644 app/views/reports/product_sale/index.xls.erb diff --git a/app/views/reports/product_sale/index.html.erb b/app/views/reports/product_sale/index.html.erb old mode 100755 new mode 100644 index f614fbb9..4670f6b3 --- a/app/views/reports/product_sale/index.html.erb +++ b/app/views/reports/product_sale/index.html.erb @@ -45,41 +45,58 @@ <%= 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.total") %> <% unless @sale_data.blank? %> <% acc_arr = Array.new %> - <% cate_arr = Array.new %> - + <% cate_arr = Array.new %> <% grand_total = 0 %> <% total_qty = 0 %> + <% total_item = {} %> + <% total_data = {} %> + <% @sale_data.each do |sale| + if !total_item.has_key?(sale.item_code) + total_item[sale.item_code] = sale.total_item + total_data[sale.item_code] = sale.grand_total + else + if sale.status_type == "void" + total_item[sale.item_code] += sale.total_item + end + if sale.status_type == "void" || sale.status_type == "Discount" || sale.status_type == "foc" + total_data[sale.item_code] += sale.grand_total + end + end + end %> <% @sale_data.each do |sale| %> <% grand_total += sale.grand_total %> <% if sale.status_type != "Discount" && sale.status_type != "foc" - total_qty += sale.total_item + total_qty += sale.total_item end %> <% if sale.status_type == "foc" && sale.price > 0 total_qty += sale.total_item end %> - <% if !sale.status_type %> + + <% if sale.status_type != "Discount" && sale.price.to_f >= 0 %>   <% if !cate_arr.include?(sale.menu_category_id) %> <%= sale.menu_category_name %> - <% cate_arr.push(sale.menu_category_id) %> + <% cate_arr.push(sale.menu_category_id) %> <% else %> - <% cate_arr = Array.new %> + <% if sale.total_item > 0 %> + <% cate_arr = Array.new %> + <% end %>   <% end %> <%= 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_item[sale.item_code] rescue '-' %> + + <%= number_with_precision(total_data[sale.item_code] , precision:precision.to_i,delimiter:delimiter) rescue '-' %> @@ -89,7 +106,6 @@ Total <%= total_qty %> - <%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %> diff --git a/app/views/reports/product_sale/index.xls.erb b/app/views/reports/product_sale/index.xls.erb old mode 100755 new mode 100644 index eb7f50f8..0ff60964 --- a/app/views/reports/product_sale/index.xls.erb +++ b/app/views/reports/product_sale/index.xls.erb @@ -11,7 +11,7 @@ <%= 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.total") %> @@ -21,6 +21,21 @@ <% cate_arr = Array.new %> <% grand_total = 0 %> <% total_qty = 0 %> + <% total_item = {} %> + <% total_data = {} %> + <% @sale_data.each do |sale| + if !total_item.has_key?(sale.item_code) + total_item[sale.item_code] = sale.total_item + total_data[sale.item_code] = sale.grand_total + else + if sale.status_type == "void" + total_item[sale.item_code] += sale.total_item + end + if sale.status_type == "void" || sale.status_type == "Discount" || sale.status_type == "foc" + total_data[sale.item_code] += sale.grand_total + end + end + end %> <% @sale_data.each do |sale| %> <% grand_total += sale.grand_total %> @@ -31,21 +46,23 @@ total_qty += sale.total_item end %> - <% if !sale.status_type %> + <% if sale.status_type != "Discount" && sale.price.to_f >= 0 %>   <% if !cate_arr.include?(sale.menu_category_id) %> <%= sale.menu_category_name %> <% cate_arr.push(sale.menu_category_id) %> <% else %> - <% cate_arr = Array.new %> + <% if sale.total_item > 0 %> + <% cate_arr = Array.new %> + <% end %>   <% end %> <%= sale.item_code rescue '-' %> <%= sale.product_name rescue '-' %> - <%= sale.total_item rescue ' ' %> - <%= sale.unit_price rescue ' ' %> - <%= sale.grand_total rescue ' ' %> + <%= total_item[sale.item_code] rescue ' ' %> + + <%= total_data[sale.item_code] rescue ' ' %> @@ -55,7 +72,6 @@ Total <%= total_qty rescue ' ' %> - <%= grand_total rescue ' ' %> <% end %> From 5588f40753ec81eec5415c5fa0c524885532c971 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 30 Mar 2018 14:20:47 +0630 Subject: [PATCH 5/7] update waste and spoilage --- app/controllers/origami/home_controller.rb | 2 +- .../origami/payments_controller.rb | 2 - app/controllers/origami/rooms_controller.rb | 3 +- app/controllers/origami/void_controller.rb | 2 +- ...troller .rb => waste_spoile_controller.rb} | 28 +++-- .../reports/waste_and_spoilage_controller.rb | 19 ++++ app/models/sale.rb | 10 ++ app/models/sale_payment.rb | 2 +- app/views/layouts/_left_sidebar.html.erb | 3 + app/views/origami/customers/index.html.erb | 2 +- app/views/origami/home/show.html.erb | 12 +- app/views/origami/rooms/show.html.erb | 65 ++++++++++- .../_shift_sale_report_filter.html.erb | 73 ++++++++++++ .../reports/waste_and_spoilage/index.html.erb | 83 ++++++++++++++ .../reports/waste_and_spoilage/index.xls.erb | 106 ++++++++++++++++++ config/routes.rb | 7 +- 16 files changed, 380 insertions(+), 39 deletions(-) rename app/controllers/origami/{waste_spoile_controller .rb => waste_spoile_controller.rb} (83%) create mode 100755 app/controllers/reports/waste_and_spoilage_controller.rb create mode 100755 app/views/reports/waste_and_spoilage/_shift_sale_report_filter.html.erb create mode 100755 app/views/reports/waste_and_spoilage/index.html.erb create mode 100755 app/views/reports/waste_and_spoilage/index.xls.erb diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index a8e2818c..759cb1b6 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -95,7 +95,7 @@ class Origami::HomeController < BaseOrigamiController @status_order = 'order' else sale = Sale.find(booking.sale_id) - if sale.sale_status != "completed" && sale.sale_status != 'void' + if sale.sale_status != "completed" && sale.sale_status != 'void' && sale.sale_status != 'spoile' && sale.sale_status != 'waste' @sale_array.push(sale) if @status_order == 'order' @status_order = 'sale' diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 5397c7f0..16a79d33 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -113,8 +113,6 @@ class Origami::PaymentsController < BaseOrigamiController end end #end rounding adjustment - puts "sale" - puts saleObj.to_json sale_payment = SalePayment.new sale_payment.process_payment(saleObj, current_user.name, cash, "cash") diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index 11a7f93d..5c0cd454 100755 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -79,8 +79,7 @@ class Origami::RoomsController < BaseOrigamiController @status_order = 'order' else sale = Sale.find(booking.sale_id) - if sale.sale_status != "completed" && sale.sale_status != 'void' - puts "enter" + if sale.sale_status != "completed" && sale.sale_status != 'void' && sale.sale_status != 'spoile' && sale.sale_status != 'waste' @sale_array.push(sale) if @status_order == 'order' @status_order = 'sale' diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 74e495ca..83dce707 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -48,7 +48,7 @@ class Origami::VoidController < BaseOrigamiController table.bookings.each do |booking| if booking.booking_status != 'moved' if booking.sale_id - if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' + if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' && booking.sale.sale_status != 'spoile' && booking.sale.sale_status != 'waste' table_avaliable = false table_count += 1 else diff --git a/app/controllers/origami/waste_spoile_controller .rb b/app/controllers/origami/waste_spoile_controller.rb similarity index 83% rename from app/controllers/origami/waste_spoile_controller .rb rename to app/controllers/origami/waste_spoile_controller.rb index 72180786..c94b33bb 100755 --- a/app/controllers/origami/waste_spoile_controller .rb +++ b/app/controllers/origami/waste_spoile_controller.rb @@ -1,29 +1,28 @@ class Origami::WasteSpoileController < BaseOrigamiController - def index - - end - def waste_and_spoile + def waste_and_spoilage sale_id = params[:sale_id] remark = params[:remark] order_source = params[:type] #tax profile source if Sale.exists?(sale_id) sale = Sale.find_by_sale_id(sale_id) - - if sale.discount_type == "member_discount" - sale.update_attributes(total_discount: 0) - sale.compute_by_sale_items(sale_id, sale.sale_items,0,order_source) + SaleTax.where("sale_id='#{sale_id}'").find_each do |existing_tax| + existing_tax.delete end - + sale.update_attributes(total_discount: 0,total_tax: 0,grand_total: sale.total_amount,rounding_adjustment:0) sale.payment_status = remark sale.sale_status = remark sale.save + # sale.compute_by_sale_items(sale_id, sale.sale_items,0,order_source) # add to sale item with foc - sale_items = SaleItem.where("sale_id='#{ sale_id }' and status is null") + # sale_items = SaleItem.where("sale_id='#{ sale_id }' and status is null") - sale_items.each do|item| - SaleItem.update_existing_item(item.qty, item, sale_id, remark, item.unit_price, item.price) + sale.sale_items.each do|item| + # SaleItem.update_existing_item(item.qty, item, sale_id, remark, item.unit_price, item.price) + item.status = remark + item.remark = remark + item.save end if sale.bookings[0].dining_facility_id.to_i > 0 @@ -33,7 +32,7 @@ class Origami::WasteSpoileController < BaseOrigamiController table.bookings.each do |booking| if booking.booking_status != 'moved' if booking.sale_id - if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' + if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' && booking.sale.sale_status != 'spoile' && booking.sale.sale_status != 'waste' table_avaliable = false table_count += 1 else @@ -45,7 +44,6 @@ class Origami::WasteSpoileController < BaseOrigamiController end end end - if table_avaliable && table_count == 0 table.status = 'available' table.save @@ -104,7 +102,7 @@ class Origami::WasteSpoileController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, remark,current_balance,nil) result = { :filepath => filename, :printer_model => print_settings.brand_name, diff --git a/app/controllers/reports/waste_and_spoilage_controller.rb b/app/controllers/reports/waste_and_spoilage_controller.rb new file mode 100755 index 00000000..369c6860 --- /dev/null +++ b/app/controllers/reports/waste_and_spoilage_controller.rb @@ -0,0 +1,19 @@ +class Reports::WasteAndSpoilageController < BaseReportController +authorize_resource :class => false + def index + from, to = get_date_range_from_params + @sale_type = params[:sale_type] + @sale_data = Sale.get_wastes_and_spoilages(from,to,@sale_type) + @from = from + @to = to + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + + respond_to do |format| + format.html + format.xls + end + end + + +end \ No newline at end of file diff --git a/app/models/sale.rb b/app/models/sale.rb index 970896bf..e25589dc 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1109,6 +1109,16 @@ def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type return all_total,sale_type end +def self.get_wastes_and_spoilages(from,to,status) + if status == "spoile" + type = "and sales.sale_status = 'spoile'" + else + type = "and sales.sale_status = 'waste'" + end + query = Sale.all.where("sales.receipt_date between ? and ? #{type}",from,to) + .group("sales.receipt_no") +end + # def self.get_separate_tax(from,to,payment_method=nil) # query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name") diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 3ff4697e..5a0b22b2 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -418,7 +418,7 @@ class SalePayment < ApplicationRecord bookings.each do |tablebooking| if tablebooking.booking_status != 'moved' if tablebooking.sale_id - if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void' + if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void' && tablebooking.sale.sale_status != 'spoile' && tablebooking.sale.sale_status != 'waste' status = false sale_count += 1 else diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index 63067ec0..ea3a7b61 100644 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -144,6 +144,9 @@
  • Void Sales
  • +
  • + Wastes & Spoilages +
  • Payment Method
  • diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index 2600f3fe..f36ca636 100755 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -26,7 +26,7 @@ <% end %> --> - <% path ="/origami/#{@sale_id}/customers" %> + <% path ="/origami/#{@sale_id}/#{@cashier_type}/customers/#{@page}" %> <%= form_tag path, :id => "filter_form", :method => :get do %>
    diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 8ffe8964..4810cf13 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -598,8 +598,6 @@
    @@ -1059,8 +1057,6 @@ if (isConfirm) { var sale_id = "<%= @obj_sale.sale_id rescue "" %>" var url = "/origami/sale/" + sale_id + '/cashier/waste_and_spoilage'; - -console.log(url) $.ajax({ type: 'POST', url: url, @@ -1068,10 +1064,10 @@ console.log(url) success: function (result) { console.log(result) // For Server Print - from jade - // if ($("#server_mode").val() == "cloud") { - // code2lab.printFile(result.filepath.substr(6), result.printer_url); - // } - // window.location.href = '/origami/'; + if ($("#server_mode").val() == "cloud") { + code2lab.printFile(result.filepath.substr(6), result.printer_url); + } + window.location.href = '/origami/'; } }); } diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 424690ff..e2f04018 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -450,10 +450,11 @@ <% if current_login_employee.role != "waiter" %> - - - + +
    + +
    +
    + +
    + + + + + + + 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 new file mode 100755 index 00000000..3d89a376 --- /dev/null +++ b/app/views/reports/waste_and_spoilage/_shift_sale_report_filter.html.erb @@ -0,0 +1,73 @@ +
    + <%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %> + <% if period_type != false %> +
    +
    + + +
    +
    + + +
    + +
    + + + +
    +
    + + +
    + +
    +
    + +
    +
    + <% 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 6/7] 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 7/7] 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