class Foodcourt::QrpayController < BaseFoodcourtController require 'rqrcode' def init @cash_exist = PaymentMethodSetting.cash_exist @credit_exist = PaymentMethodSetting.credit_exist display_type = Lookup.find_by_lookup_type("display_type") if !display_type.nil? && display_type.value.to_i == 2 @display_type = display_type.value else @display_type = nil end path = request.fullpath sale_id = params[:sale_id] @trans_flag = true if params[:type] == "transaction" @trans_flag = false @cashier_type = "cashier" 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 if Sale.exists?(sale_id) @cash = 0.0 @kbz_pay_amount = 0.0 @other = 0.0 @ppamount = 0.0 @visacount= 0.0 @jcbcount= 0.0 @mastercount = 0.0 @unionpaycount = 0.0 @alipaycount = 0.0 @junctionpaycount = 0.0 @credit = 0.0 @paymalcount = 0.0 @dingacount = 0.0 @giftvouchercount = 0.0 @sale_data = Sale.find_by_sale_id(sale_id) @balance = 0 @accountable_type = '' @table_no = '' @dining = '' @other_payment = 0.0 @pdf_view = nil @lookup_pdf = Lookup.find_by_lookup_type("ReceiptPdfView") if !@lookup_pdf.nil? @pdf_view = @lookup_pdf.value end amount = SalePayment.get_kbz_pay_amount(sale_id, current_user) @kbz_pay_amount += amount.to_f # @shop = shop_detail #show shop info @customer_lists = Customer.where(name: ["WALK-IN", "TAKEAWAY"]) saleObj = Sale.find(sale_id) #total customer with individual total amount @individual_total = Array.new if !saleObj.equal_persons.nil? per_person_amount = saleObj.grand_total.to_f / saleObj.equal_persons.to_i @individual_total.push({'total_customer' => saleObj.equal_persons.to_i, 'per_person_amount' => per_person_amount.to_f }) end if current_shop.is_rounding_adj a = saleObj.grand_total % 25 # Modulus b = saleObj.grand_total / 25 # Division #not calculate rounding if modulus is 0 and division is even #calculate rounding if modulus is zero or not zero and division are not even if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) new_total = Sale.get_rounding_adjustment(saleObj.grand_total) @rounding_adj = new_total-saleObj.grand_total saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:@rounding_adj) @sale_data.grand_total = new_total @sale_data.old_grand_total = saleObj.grand_total @sale_data.rounding_adjustment = @rounding_adj else @rounding_adj = @sale_data.rounding_adjustment end else @rounding_adj = @sale_data.rounding_adjustment end #end rounding adjustment # get printer info @print_settings = PrintSetting.get_precision_delimiter() #get customer amount @customer = Customer.find(@sale_data.customer_id) # accounts = @customer.tax_profiles accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC") @account_arr =[] @tax_arr =[] accounts.each do |acc| account = TaxProfile.find(acc.id) # @account_arr.push(account) @tax_arr.push(account.name) end sale_taxes = SaleTax.where("sale_id = ?", saleObj.sale_id) if !sale_taxes.empty? sale_taxes.each do |sale_tax| @account_arr.push(sale_tax) end end rebate = MembershipSetting.find_by_rebate(1) # get member information if @customer.membership_id != nil && rebate response = Customer.get_member_account(@customer) if response["status"]==true response["account_data"].each do |res| if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount" @balance = @balance.to_f + res["balance"].to_f # @accountable_type = res["accountable_type"] @accountable_type = "Rebate Balance" end end end end #end customer amount #paymal payment @sale_data.bookings.each do |sbk| if sbk.dining_facility_id.to_i >0 df = DiningFacility.find(sbk.dining_facility_id) @table_no = df.type + ' ' + df.name @checkin_time = sbk.checkin_at @dining = df break else @table_no = nil @checkin_time = nil @dining = nil end end if path.include? ("credit_payment") @sale_payment_data = SalePayment.get_sale_payment_for_credit(@sale_data) else @sale_payment_data = SalePayment.get_sale_payments(@sale_data) end @sale_payment_data.each do |spay| if spay.payment_method == "cash" @cash += spay.payment_amount end if spay.payment_method !="creditnote" @other_payment += spay.payment_amount end if spay.payment_method == "mpu" @other += spay.payment_amount elsif spay.payment_method == "paypar" @ppamount += spay.payment_amount elsif spay.payment_method == "visa" @visacount += spay.payment_amount elsif spay.payment_method == "jcb" @jcbcount += spay.payment_amount elsif spay.payment_method == "master" @mastercount += spay.payment_amount elsif spay.payment_method == "unionpay" @unionpaycount += spay.payment_amount elsif spay.payment_method == "JunctionPay" @junctionpaycount += spay.payment_amount elsif spay.payment_method == "creditnote" @credit += spay.payment_amount elsif spay.payment_method == "paymal" @paymalcount += spay.payment_amount elsif spay.payment_method == "alipay" @alipaycount += spay.payment_amount elsif spay.payment_method == "dinga" @dingacount += spay.payment_amount elsif spay.payment_method == "giftvoucher" @giftvouchercount += spay.payment_amount end end @paymethod = PaymentMethodSetting.find_by(payment_method: "MMQR") @merchant = KbzMerchant.new(@paymethod) @response = @merchant.create_order(amount: @sale_data.grand_total, merch_order_id: @sale_data.receipt_no) @qr_string = @response['qrCode'] qrcode = RQRCode::QRCode.new(@qr_string) @qr_svg = qrcode.as_svg( color: "000", shape_rendering: "crispEdges", module_size: 2, standalone: true, use_path: true ) # png_data = qrcode.as_png( # bit_depth: 1, # border_modules: 4, # color_mode: ChunkyPNG::COLOR_GRAYSCALE, # color: 'black', # file: nil, # fill: 'white', # module_px_size: 8, # Pixel size of each module # resize_exactly_to: false, # resize_gte_to: false, # size: 240 # Approximate size of the image in pixels (e.g., 240x240) # ).to_s ActionCable.server.broadcast('second_display_view_channel', { data: @qr_string, qr_svg: @qr_svg, grand_total: @sale_data.grand_total, invoice_no: @sale_data.receipt_no }) end end end