From be60470ba1fc708b45e479c410f6746dea002866 Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Tue, 4 Jun 2019 11:46:29 +0630 Subject: [PATCH] fixed foc print --- .../origami/payments_controller.rb | 171 ++++++++++-------- 1 file changed, 92 insertions(+), 79 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 59aaec3a..8004b386 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -8,14 +8,14 @@ class Origami::PaymentsController < BaseOrigamiController sale_data = Sale.find_by_sale_id(sale_id) sale_items = SaleItem.get_all_sale_items(sale_id) member_info = nil - + # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") - # if bookings.count > 1 + # if bookings.count > 1 # # for Multiple Booking # table = DiningFacility.find(bookings[0].dining_facility_id) # else - # table = DiningFacility.find(bookings[0].dining_facility_id) + # table = DiningFacility.find(bookings[0].dining_facility_id) # end shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? @@ -48,7 +48,7 @@ class Origami::PaymentsController < BaseOrigamiController if !receipt_bill_a5_pdf.empty? receipt_bill_a5_pdf.each do |receipt_bilA5| - if receipt_bilA5[0] == 'ReceiptBillA5Pdf' + if receipt_bilA5[0] == 'ReceiptBillA5Pdf' if receipt_bilA5[1] == '1' unique_code = "ReceiptBillA5Pdf" else @@ -59,7 +59,7 @@ class Origami::PaymentsController < BaseOrigamiController end #shop detail - ## shop_detail = Shop.first + ## shop_detail = Shop.first # customer= Customer.where('customer_id=' +.customer_id) customer = Customer.find(sale_data.customer_id) # rounding adjustment @@ -71,14 +71,14 @@ class Origami::PaymentsController < BaseOrigamiController if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) new_total = Sale.get_rounding_adjustment(sale_data.grand_total) rounding_adj = new_total-sale_data.grand_total - sale_data.update_attributes(grand_total: new_total,old_grand_total: sale_data.grand_total,rounding_adjustment:rounding_adj) + sale_data.update_attributes(grand_total: new_total,old_grand_total: sale_data.grand_total,rounding_adjustment:rounding_adj) end end #end rounding adjustment #record for sale audit action_by = current_user.name type = "FIRST_BILL" - + remark = "#{action_by} print out first bill for Receipt No #{sale_data.receipt_no}" sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type ) # get member information @@ -102,12 +102,12 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil,other_amount,nil,nil,nil) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil,other_amount,nil,nil,nil) - result = { - :filepath => filename, - :printer_model => print_settings.brand_name, - :printer_url => print_settings.api_settings + result = { + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings } # Mobile Print @@ -127,7 +127,7 @@ class Origami::PaymentsController < BaseOrigamiController if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) sale_items = SaleItem.get_all_sale_items(sale_id) - #shop_detail = Shop.first + #shop_detail = Shop.first # rounding adjustment if !path.include? ("credit_payment") if shop_detail.is_rounding_adj @@ -138,12 +138,12 @@ class Origami::PaymentsController < BaseOrigamiController if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) new_total = Sale.get_rounding_adjustment(saleObj.grand_total) rounding_adj = new_total-saleObj.grand_total - saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) end end end #end rounding adjustment - + sale_payment = SalePayment.new if path.include? ("credit_payment") sale_payment.process_payment(saleObj, current_user, cash, "cash", nil, true) @@ -166,7 +166,7 @@ class Origami::PaymentsController < BaseOrigamiController table = DiningFacility.find(bookings.dining_facility_id) cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) - + type = 'payment' from = getCloudDomain #get sub domain in cloud mode ActionCable.server.broadcast "order_channel",table: table,type:type,from:from @@ -193,11 +193,11 @@ class Origami::PaymentsController < BaseOrigamiController if !receipt_bill_a5_pdf.empty? receipt_bill_a5_pdf.each do |receipt_bilA5| - if receipt_bilA5[0] == 'ReceiptBillA5Pdf' + if receipt_bilA5[0] == 'ReceiptBillA5Pdf' if receipt_bilA5[1] == '1' unique_code = "ReceiptBillA5Pdf" # else - + end end end @@ -208,16 +208,16 @@ class Origami::PaymentsController < BaseOrigamiController # get member information rebate = MembershipSetting.find_by_rebate(1) credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id,'creditnote') - + if customer.membership_id != nil && rebate && credit_data.nil? member_info = Customer.get_member_account(customer) - + if member_info["status"] == true rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no) current_balance = SaleAudit.paymal_search(sale_id) end end - + #orders print out if params[:type] == "quick_service" booking = Booking.find_by_sale_id(sale_id) @@ -226,7 +226,7 @@ class Origami::PaymentsController < BaseOrigamiController else table_id = 0 end - + latest_order = booking.booking_orders.order("order_id DESC").limit(1).first() if !latest_order.nil? latest_order_no = latest_order.order_id @@ -241,13 +241,13 @@ class Origami::PaymentsController < BaseOrigamiController from = getCloudDomain #get sub domain in cloud mode ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from end - + end #for card sale data card_data = Array.new card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id) - if !card_sale_trans_ref_no.nil? + if !card_sale_trans_ref_no.nil? card_sale_trans_ref_no.each do |cash_sale_trans| card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s @@ -259,7 +259,7 @@ class Origami::PaymentsController < BaseOrigamiController #card_balance amount for Paymal payment card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id) - + # get printer info print_settings=PrintSetting.find_by_unique_code(unique_code) # Calculate Food and Beverage Total @@ -274,7 +274,7 @@ class Origami::PaymentsController < BaseOrigamiController #end end - end + end end def show @@ -287,11 +287,11 @@ class Origami::PaymentsController < BaseOrigamiController else @cashier_type = params[:type] end - + if path.include? ("credit_payment") @sale_payment = SalePayment.get_credit_amount_due_left(sale_id) end - + @member_discount = MembershipSetting.find_by_discount(1) @membership_rebate_balance=0 @@ -326,15 +326,15 @@ class Origami::PaymentsController < BaseOrigamiController lookup_changable_tax = Lookup.collection_of('changable_tax') if !lookup_changable_tax.empty? lookup_changable_tax.each do |changable_tax| - if changable_tax[0].downcase == "change" - if changable_tax[1] == '0' + if changable_tax[0].downcase == "change" + if changable_tax[1] == '0' @changable_tax = false end end end end - - @shop = shop_detail #show shop info + + @shop = shop_detail #show shop info @customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'") @@ -373,7 +373,7 @@ class Origami::PaymentsController < BaseOrigamiController if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) new_total = Sale.get_rounding_adjustment(saleObj.grand_total) @rounding_adj = new_total-saleObj.grand_total - saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:@rounding_adj) + saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:@rounding_adj) @sale_data.grand_total = new_total @sale_data.old_grand_total = saleObj.grand_total @sale_data.rounding_adjustment = @rounding_adj @@ -418,11 +418,11 @@ class Origami::PaymentsController < BaseOrigamiController end end end - end + end #end customer amount - #paymal payment + #paymal payment @sale_data.bookings.each do |sbk| if sbk.dining_facility_id.to_i >0 @@ -444,13 +444,13 @@ class Origami::PaymentsController < BaseOrigamiController @sale_payment_data = SalePayment.get_sale_payments(@sale_data) end @sale_payment_data.each do |spay| - if spay.payment_method == "cash" + if spay.payment_method == "cash" @cash += spay.payment_amount end - if spay.payment_method !="creditnote" + if spay.payment_method !="creditnote" @other_payment += spay.payment_amount end - + if spay.payment_method == "mpu" @other += spay.payment_amount elsif spay.payment_method == "paypar" @@ -485,7 +485,7 @@ class Origami::PaymentsController < BaseOrigamiController member_info = nil latest_order_no = nil saleObj = Sale.find(sale_id) - + # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") @@ -494,11 +494,11 @@ class Origami::PaymentsController < BaseOrigamiController if !latest_order.nil? latest_order_no = latest_order.order_id end - # if bookings.count > 1 + # if bookings.count > 1 # # for Multiple Booking # table = DiningFacility.find(bookings[0].dining_facility_id) # else - # table = DiningFacility.find(bookings[0].dining_facility_id) + # table = DiningFacility.find(bookings[0].dining_facility_id) # end shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? @@ -512,14 +512,14 @@ class Origami::PaymentsController < BaseOrigamiController shift = ShiftSale.find(saleObj.shift_sale_id) cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) end - end + end # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf unique_code = "ReceiptBillPdf" if !receipt_bill_a5_pdf.empty? receipt_bill_a5_pdf.each do |receipt_bilA5| - if receipt_bilA5[0] == 'ReceiptBillA5Pdf' + if receipt_bilA5[0] == 'ReceiptBillA5Pdf' if receipt_bilA5[1] == '1' unique_code = "ReceiptBillA5Pdf" else @@ -531,7 +531,7 @@ class Origami::PaymentsController < BaseOrigamiController customer= Customer.find(saleObj.customer_id) #shop detail - #shop_detail = Shop.first + #shop_detail = Shop.first # get member information rebate = MembershipSetting.find_by_rebate(1) if customer.membership_id != nil && rebate @@ -543,7 +543,7 @@ class Origami::PaymentsController < BaseOrigamiController #for card sale data card_data = Array.new card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id) - if !card_sale_trans_ref_no.nil? + if !card_sale_trans_ref_no.nil? card_sale_trans_ref_no.each do |cash_sale_trans| card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s @@ -566,20 +566,20 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil) - - result = { + + result = { :status => true, - :filepath => filename, - :printer_model => print_settings.brand_name, - :printer_url => print_settings.api_settings + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings } - + # Mobile Print render :json => result.to_json # end end - def foc + def foc cash = params[:cash] sale_id = params[:sale_id] sub_total = params[:sub_total] @@ -598,7 +598,7 @@ class Origami::PaymentsController < BaseOrigamiController saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0) saleObj.compute_by_sale_items(sale_id, saleObj.sale_items,0,order_source) end - + saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0) sale_payment = SalePayment.new @@ -612,7 +612,7 @@ class Origami::PaymentsController < BaseOrigamiController ActionCable.server.broadcast "order_channel",table: table,type:type,from:from end - + # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") @@ -629,18 +629,31 @@ class Origami::PaymentsController < BaseOrigamiController shift = ShiftSale.find(saleObj.shift_sale_id) cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) end - end - + end + # Re-call Sale Data saleObj = Sale.find(sale_id) # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server - unique_code = "ReceiptBillPdf" + # unique_code = "ReceiptBillPdf" customer= Customer.find(saleObj.customer_id) - - #shop detail - #shop_detail = Shop.first + #shop detail + #shop_detail = Shop.first + printer = PrintSetting.all + + unique_code="ReceiptBillPdf" + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'ReceiptBillPdf' + unique_code="ReceiptBillPdf" + elsif printer_setting.unique_code == 'ReceiptBillA5Pdf' + unique_code="ReceiptBillA5Pdf" + elsif printer_setting.unique_code == 'ReceiptBillStarPdf' + unique_code="ReceiptBillStarPdf" + end + end + end # get printer info print_settings=PrintSetting.find_by_unique_code(unique_code) # Calculate Food and Beverage Total @@ -652,11 +665,11 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "FOC",nil,nil,other_amount,nil,nil,nil) - result = { + result = { :status => true, - :filepath => filename, - :printer_model => print_settings.brand_name, - :printer_url => print_settings.api_settings + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings } # Mobile Print @@ -669,26 +682,26 @@ class Origami::PaymentsController < BaseOrigamiController 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 def rounding_adj saleObj = Sale.find(params[:sale_id]) @shop = shop_detail - + if @shop.is_rounding_adj a = saleObj.grand_total % 25 # Modulus - b = saleObj.grand_total / 25 # Division + b = saleObj.grand_total / 25 # Division #not calculate rounding if modulus is 0 and division is even #calculate rounding if modulus is zero or not zero and division are not even - if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) + if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) new_total = Sale.get_rounding_adjustment(saleObj.grand_total) rounding_adj = new_total-saleObj.grand_total saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) @@ -697,12 +710,12 @@ class Origami::PaymentsController < BaseOrigamiController end #print function for receipt - def print + def print filename = params[:filename] receipt_no = params[:receipt_no] printer_name = params[:printer_name] cashier_type = params[:type] - + if cashier_type.strip.downcase == "doemal_order" unique_code = "ReceiptBillOrderPdf" else @@ -720,7 +733,7 @@ class Origami::PaymentsController < BaseOrigamiController end if !receipt_bill_a5_pdf.empty? receipt_bill_a5_pdf.each do |receipt_bilA5| - if receipt_bilA5[0] == 'ReceiptBillA5Pdf' + if receipt_bilA5[0] == 'ReceiptBillA5Pdf' if receipt_bilA5[1] == '1' unique_code = "ReceiptBillA5Pdf" # else @@ -734,12 +747,12 @@ class Origami::PaymentsController < BaseOrigamiController print_settings=PrintSetting.find_by_unique_code(unique_code) printer = Printer::ReceiptPrinter.new(print_settings) printer.print_receipt_pdf(filename,receipt_no,print_settings.print_copies,printer_name) - - result = { + + result = { :status => true, - :filepath => filename, - :printer_model => print_settings.brand_name, - :printer_url => print_settings.api_settings + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings } Rails.logger.debug "$$$$$$$$$ result ::" Rails.logger.debug result @@ -755,7 +768,7 @@ class Origami::PaymentsController < BaseOrigamiController tax_type = params[:tax_type] sale = Sale.find(sale_id) sale.compute_by_sale_items(sale.sale_id, sale.sale_items, sale.total_discount,nil,order_source,tax_type) - + render json: JSON.generate({:status => true}) end @@ -768,4 +781,4 @@ class Origami::PaymentsController < BaseOrigamiController return from end -end \ No newline at end of file +end