diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index dbd78bcd..7ed2d0eb 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -28,6 +28,7 @@ _ALIPAY_ = "/   Alipay"; _JUNCTIONPAY_ = "/   JunctionPay"; _PAYMAL_ = "/   PAYMAL"; _DINGA_ = "/   DINGA PAYMENT"; +_GIFT_VOUCHER_ = "/   GIFT VOUCHER"; _OTHER_CHARGES_ = "/   CHARGES"; _OTHER_PAYMENTS_ = "/   OTHER PAYMENT"; _PAYMENTS_ = "/   PAYMENT"; diff --git a/app/controllers/origami/gift_voucher_controller.rb b/app/controllers/origami/gift_voucher_controller.rb new file mode 100644 index 00000000..e52ed339 --- /dev/null +++ b/app/controllers/origami/gift_voucher_controller.rb @@ -0,0 +1,71 @@ +class Origami::GiftVoucherController < BaseOrigamiController + def index + @sale_id = params[:sale_id] + @cashier_type = params[:type] + # limit gift_voucher_amount + sale_data = Sale.find_by_sale_id(@sale_id) + total = 0 + @gift_vouchercount = 0 + @shop = Shop.first + @rounding_adj = 0 + @can_gift_voucher = 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 == "gift_voucher" + @gift_vouchercount = @gift_vouchercount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_gift_voucher = total - @gift_vouchercount - 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 + end + + def create + cash = params[:amount] + sale_id = params[:sale_id] + ref_no = params[:reference_no] + if(Sale.exists?(sale_id)) + saleObj = Sale.find(sale_id) + shop_details = Shop.first + + # 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, "GiftVoucher",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/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 313cc10c..a19d3366 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -234,6 +234,7 @@ class Origami::PaymentsController < BaseOrigamiController @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 = '' @@ -373,6 +374,8 @@ class Origami::PaymentsController < BaseOrigamiController @alipaycount += spay.payment_amount elsif spay.payment_method == "dinga" @dingacount += spay.payment_amount + elsif spay.payment_method == "giftvoucher" + @giftvouchercount += spay.payment_amount end end end diff --git a/app/controllers/reports/payment_method_controller.rb b/app/controllers/reports/payment_method_controller.rb index 97965167..7ac35cdd 100644 --- a/app/controllers/reports/payment_method_controller.rb +++ b/app/controllers/reports/payment_method_controller.rb @@ -6,7 +6,7 @@ class Reports::PaymentMethodController < BaseReportController ["FOC Payment","foc"], ["MPU Payment","mpu"], ["Visa Payment","visa"], ["Master Payment","master"], ["JCB Payment","jcb"],["UnionPay Payment","unionpay"], ["Alipay Payment","alipay"],["Paymal Payment", "paymal"],["Dinga Payment","dinga"], - ["JunctionPay","junctionpay"],["Redeem Payment","paypar"]] + ["JunctionPay","junctionpay"],["Redeem Payment","paypar"],["Gift Voucher","giftvoucher"]] from, to = get_date_range_from_params diff --git a/app/models/sale.rb b/app/models/sale.rb index 979d265c..0075ea43 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -729,6 +729,7 @@ def self.daily_sales_list(from,to) SUM(case when (sale_payments.payment_method='JunctionPay') then sale_payments.payment_amount else 0 end) as junctionpay_amount, SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount, SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount") .joins(" left join sale_payments on sale_payments.sale_id = sales.sale_id") .where("sale_status = ? AND sales.receipt_date between ? and ? ", 'completed', from, to) @@ -771,6 +772,7 @@ def self.daily_sales_list(from,to) :cash_amount => pay.cash_amount, :credit_amount => pay.credit_amount, :foc_amount => pay.foc_amount, + :giftvoucher_amount => pay.giftvoucher_amount, :total_discount => total_discount, :total_change_amount => total_change_amount, :grand_total => grand_total, @@ -928,7 +930,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type) product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount) change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed) - sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay') then (sale_payments.payment_amount) else 0 end) as card_amount, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") @@ -949,7 +951,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type) product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount) change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed) - sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay') then (sale_payments.payment_amount) else 0 end) as card_amount, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") @@ -970,7 +972,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type) product = product.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount) change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed) - sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay') then (sale_payments.payment_amount) else 0 end) as card_amount, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") @@ -1028,7 +1030,7 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_ty payment_type = '' else if payment_type == 'card' - payment_type = " and sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay'" + payment_type = " and sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher'" else payment_type = " and sale_payments.payment_method = '#{payment_type}'" end @@ -1148,6 +1150,7 @@ def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='cash') then sales.amount_changed else 0 end) as total_change_amount, SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount, SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount") .joins("join sales on sales.sale_id = sale_payments.sale_id") @@ -1489,7 +1492,7 @@ end else query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'") end - query = query.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay') THEN 'card' ELSE sp.payment_method END)","e.name") + query = query.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay' or sp.payment_method='giftvoucher') THEN 'card' ELSE sp.payment_method END)","e.name") .order("e.name") else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' @@ -1500,7 +1503,7 @@ end else query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'") end - query = query.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay') THEN 'card' ELSE sp.payment_method END)","e.name") + query = query.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay' or sp.payment_method='giftvoucher') THEN 'card' ELSE sp.payment_method END)","e.name") .order("e.name") else shift = ShiftSale.current_open_shift(current_user.id) @@ -1512,7 +1515,7 @@ end else query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and shift_sale_id='#{shift.id}'") end - query = query.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay') THEN 'card' ELSE sp.payment_method END)","e.name") + query = query.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay' or sp.payment_method='giftvoucher') THEN 'card' ELSE sp.payment_method END)","e.name") .order("e.name") end end @@ -1522,14 +1525,14 @@ end query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id") .where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = '#{today}'") - .group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay') THEN 'card' ELSE sp.payment_method END)","e.name") + .group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay' or sp.payment_method='giftvoucher') THEN 'card' ELSE sp.payment_method END)","e.name") .order("e.name") else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id") .where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = '#{today}'") - .group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay') THEN 'card' ELSE sp.payment_method END)","e.name") + .group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay' or sp.payment_method='giftvoucher') THEN 'card' ELSE sp.payment_method END)","e.name") .order("e.name") else shift = ShiftSale.current_open_shift(current_user.id) @@ -1537,7 +1540,7 @@ end query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id") .where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = '#{today}' and shift_sale_id='#{shift.id}'") - .group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay') THEN 'card' ELSE sp.payment_method END)","e.name") + .group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay' or sp.payment_method='giftvoucher') THEN 'card' ELSE sp.payment_method END)","e.name") .order("e.name") end end @@ -1636,22 +1639,22 @@ end if !from.nil? && !to.nil? if current_user.nil? if !from_time.nil? && !to_time.nil? - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',from,to,from_time,to_time) + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to,from_time,to_time) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .sum("sp.payment_amount") else - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',from,to) + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .sum("sp.payment_amount") end else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' if !from_time.nil? && !to_time.nil? - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',from,to,from_time,to_time) + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to,from_time,to_time) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .sum("sp.payment_amount") else - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',from,to) + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .sum("sp.payment_amount") end @@ -1659,11 +1662,11 @@ end shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? if !from_time.nil? && !to_time.nil? - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay") and shift_sale_id=?',from,to,from_time,to_time,shift.id) + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") and shift_sale_id=?',from,to,from_time,to_time,shift.id) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .sum("sp.payment_amount") else - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay") and shift_sale_id=?',from,to,shift.id) + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") and shift_sale_id=?',from,to,shift.id) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .sum("sp.payment_amount") end @@ -1672,18 +1675,18 @@ end end else if current_user.nil? - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',today,today) + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',today,today) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .sum("sp.payment_amount") else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',today,today) + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',today,today) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .sum("sp.payment_amount") else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay") and shift_sale_id=?',today,today,shift.id) + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") and shift_sale_id=?',today,today,shift.id) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .sum("sp.payment_amount") end @@ -1882,7 +1885,7 @@ end if !from_time.nil? && !to_time.nil? query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if payment_method == 'card' - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method="alipay" or sp.payment_method="paymal" or sp.payment_method="dinga" or sp.payment_method="JunctionPay")',from,to,from_time,to_time) + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method="alipay" or sp.payment_method="paymal" or sp.payment_method="dinga" or sp.payment_method="JunctionPay" or sp.payment_method = "giftvoucher")',from,to,from_time,to_time) else query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) end @@ -1890,7 +1893,7 @@ end else query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if payment_method == 'card' - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',from,to) + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to) else query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ?",from,to) end @@ -1901,7 +1904,7 @@ end if !from_time.nil? && !to_time.nil? query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if payment_method == 'card' - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',from,to,from_time,to_time) + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to,from_time,to_time) else query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) end @@ -1909,7 +1912,7 @@ end else query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if payment_method == 'card' - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to) + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to) else query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ?",from,to) end @@ -1921,7 +1924,7 @@ end if !from_time.nil? && !to_time.nil? query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if payment_method == 'card' - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay") and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) else query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) end @@ -1929,7 +1932,7 @@ end else query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if payment_method == 'card' - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay") and sales.shift_sale_id=?',from,to,shift.id) + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") and sales.shift_sale_id=?',from,to,shift.id) else query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) end @@ -1942,7 +1945,7 @@ end if current_user.nil? query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if payment_method == 'card' - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',today) + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',today) else query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) end @@ -1951,7 +1954,7 @@ end if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if payment_method == 'card' - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',today) + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',today) else query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) end @@ -1961,7 +1964,7 @@ end if !shift.nil? query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if payment_method == 'card' - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay") and sales.shift_sale_id=?',today,shift.id) + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") and sales.shift_sale_id=?',today,shift.id) else query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id) end @@ -2689,6 +2692,7 @@ end SUM(case when (sale_payments.payment_method='JunctionPay') then sale_payments.payment_amount else 0 end) as junctionpay_amount, SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount, + SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount, SUM(case when (sale_items.status='foc') then sale_items.price else 0 end) as item_foc, SUM(case when (sale_items.status='Discount') then sale_items.price else 0 end) as item_discount, SUM(sale_items.qty) as qty, diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 5fbc8c24..34926548 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -58,6 +58,8 @@ class SalePayment < ApplicationRecord payment_status = junction_pay_payment when "dinga" payment_status,membership_data = dinga_payment + when "GiftVoucher" + payment_status = giftvoucher_payment else puts "it was something else" end @@ -485,6 +487,18 @@ class SalePayment < ApplicationRecord end + def giftvoucher_payment + payment_status = false + self.payment_method = "giftvoucher" + self.payment_amount = self.received_amount + self.payment_reference = self.payment_reference + self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f + self.payment_status = "paid" + payment_method = self.save! + sale_update_payment_status(self.received_amount) + return payment_status + end + def sale_update_payment_status(paid_amount,check_foc = false) #update amount_outstanding self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f diff --git a/app/views/origami/gift_voucher/create.json.jbuilder b/app/views/origami/gift_voucher/create.json.jbuilder new file mode 100755 index 00000000..9767a7d8 --- /dev/null +++ b/app/views/origami/gift_voucher/create.json.jbuilder @@ -0,0 +1,5 @@ +if(@status) + json.status @status +else + json.status false +end diff --git a/app/views/origami/gift_voucher/index.html.erb b/app/views/origami/gift_voucher/index.html.erb new file mode 100755 index 00000000..938e6d96 --- /dev/null +++ b/app/views/origami/gift_voucher/index.html.erb @@ -0,0 +1,223 @@ +
+ + +
+
+ + + +
+
+
+ <% if @bank_integration == '1' %> +
+
+ + +
+
+
+ <% end %> +
+
+ + <%@can_gift_voucher = @can_gift_voucher +@rounding_adj%> + +
+
+
+ <% if @gift_vouchercount != 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 f83c1d55..2137d99e 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -174,7 +174,7 @@
Credit
<%= number_with_precision(@credit, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
- <% if @other == 0.0 && @ppamount == 0.0 && @visacount == 0.0 && @jcbcount == 0.0 && @mastercount == 0.0 && @unionpaycount == 0.0 && @alipaycount == 0.0 && @paymalcount == 0.0 && @junctionpaycount == 0.0 && @dingacount == 0.0 %> + <% if @other == 0.0 && @ppamount == 0.0 && @visacount == 0.0 && @jcbcount == 0.0 && @mastercount == 0.0 && @unionpaycount == 0.0 && @alipaycount == 0.0 && @paymalcount == 0.0 && @junctionpaycount == 0.0 && @dingacount == 0.0 && @giftvouchercount == 0.0 %>
Other Payments
<%= number_with_precision(@other, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %>
@@ -298,6 +298,17 @@ <% end %>
+ +
+
+
GIFT VOUCHER
+ <% if @giftvouchercount != 0.0 %> +
<%= number_with_precision(@giftvouchercount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+ <% else %> +
<%= number_with_precision(0, precision: precision.to_i ) %>
+ <% end %> +
+
Balance
<%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
@@ -649,7 +660,8 @@ var customer_name = "<%= @customer.name %>"; parseInt(jQuery.inArray("PAYMAL", payment_type)) != -1 || parseInt(jQuery.inArray("JUNCTIONPAY", payment_type)) != -1 || parseInt(jQuery.inArray("Alipay", payment_type)) != -1 || - parseInt(jQuery.inArray("DINGA", payment_type)) != -1){ + parseInt(jQuery.inArray("DINGA", payment_type)) != -1 || + parseInt(jQuery.inArray("GiftVoucher", payment_type)) != -1){ $("#card_payment").show(); } else{ $("#card_payment").hide(); @@ -729,6 +741,8 @@ var customer_name = "<%= @customer.name %>"; swal("Oops","Please Pay with Paymal Payment","warning"); }else if(parseInt(jQuery.inArray("DINGA", payment_type)) != -1 && $('#dingacount').text()== 0 && sub_total != 0.0 && member){ swal("Oops","Please Pay with Dinga Payment","warning"); + }else if(parseInt(jQuery.inArray("GiftVoucher", payment_type)) != -1 && $('#giftvouchercount').text()== 0 && sub_total != 0.0 && member){ + swal("Oops","Please Pay with Gift Voucher","warning"); }else{ $( "#loading_wrapper").show(); @@ -978,7 +992,8 @@ var customer_name = "<%= @customer.name %>"; var alipay1 = $('#alipaycount').text(); var junctionpay1 = $('#junctionpaycount').text(); var dingapay1 = $('#dingacount').text(); - var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1) + parseFloat(unionpay1) + parseFloat(alipay1) + parseFloat(junctionpay1) + parseFloat(paymal1) + parseFloat(dingapay1); + var giftvoucherpay1 = $('#giftvouchercount').text(); + var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1) + parseFloat(unionpay1) + parseFloat(alipay1) + parseFloat(junctionpay1) + parseFloat(paymal1) + parseFloat(dingapay1) + parseFloat(giftvoucherpay1); var total = $('#amount_due').text(); var amt = 0; <% if precision.to_i > 0 %>; @@ -1010,8 +1025,10 @@ var customer_name = "<%= @customer.name %>"; var alipay = $('#alipaycount').text(); var junctionpay = $('#junctionpaycount').text(); var dinga = $('#dingacount').text(); + var giftvoucher = $('#giftvouchercount').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(alipay) + parseFloat(junctionpay) + parseFloat(paymal) + parseFloat(dinga); + var total = parseFloat(cash) + parseFloat(credit) + parseFloat(card) + parseFloat(paypar) + parseFloat(visa) + parseFloat(jcb) + parseFloat(master) + parseFloat(unionpay) + parseFloat(alipay) + parseFloat(junctionpay) + parseFloat(paymal) + parseFloat(dinga) + parseFloat(giftvoucher); + var result = parseFloat(amount_due) - parseFloat(total); <% if precision.to_i > 0 %> diff --git a/app/views/reports/dailysale/index.html.erb b/app/views/reports/dailysale/index.html.erb index 67f5002e..10f73260 100755 --- a/app/views/reports/dailysale/index.html.erb +++ b/app/views/reports/dailysale/index.html.erb @@ -43,6 +43,7 @@ <%= t("views.right_panel.detail.cash_sales") %> <%= t("views.right_panel.detail.credit_sales") %> <%= t("views.right_panel.detail.foc_sales") %> + <%= t("views.right_panel.detail.giftvoucher_sales") %> (<%= t("views.right_panel.detail.discount") %>) <%= t("views.right_panel.detail.grand_total") %> @@ -75,6 +76,7 @@ <% paymal = 0 %> <% dinga = 0 %> <% junctionpay = 0 %> + <% giftvoucher = 0 %> <% paypar = 0 %> <% cash = 0 %> <% credit = 0 %> @@ -95,6 +97,7 @@ <% paymal += sale[:paymal_amount] %> <% dinga += sale[:dinga_amount] %> <% junctionpay += sale[:junctionpay_amount] %> + <% giftvoucher += sale[:giftvoucher_amount] %> <% paypar += sale[:paypar_amount] %> <% cash += sale[:cash_amount]-sale[:total_change_amount] %> <% credit += sale[:credit_amount] %> @@ -121,6 +124,7 @@ <%= number_with_precision(sale[:cash_amount]-sale[:total_change_amount], precision:precision.to_i, delimiter: delimiter) rescue '-'%> <%= number_with_precision(sale[:credit_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(sale[:foc_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_with_precision(sale[:giftvoucher_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> (<%= number_with_precision(sale[:total_discount], precision:precision,delimiter:delimiter) rescue '-'%>) <%= number_with_precision(sale[:grand_total], precision:precision.to_i,delimiter:delimiter) rescue '-'%> @@ -129,12 +133,11 @@ <% count = count + 1 %> <% end %> - Total <%= number_with_precision(mpu , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(master, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(visa, precision:precision,delimiter:delimiter) rescue '-'%> + <%= number_with_precision(visa, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(jcb, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(unionpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(alipay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> @@ -144,7 +147,8 @@ <%= number_with_precision(paypar, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(cash, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(credit, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(foc, precision:precision,delimiter:delimiter) rescue '-'%> + <%= number_with_precision(foc, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_with_precision(giftvoucher, precision:precision.to_i,delimiter:delimiter) rescue '-'%> (<%= number_with_precision(discount, precision:precision.to_i,delimiter:delimiter) rescue '-'%>) <%= number_with_precision(grand_total, precision:precision.to_i,delimiter:delimiter) rescue '-'%> @@ -157,7 +161,7 @@ <% @tax.each do |tax| total_tax += tax.tax_amount.to_f %> - <%= tax.tax_name rescue '-'%> + <%= tax.tax_name rescue '-'%> <%= number_with_precision(tax.tax_amount, precision:precision.to_i,delimiter:delimiter) rescue '-'%>   @@ -168,7 +172,7 @@ <% net = net - rounding_adj%> <% net = net - total_tax %> - <%= t("views.right_panel.detail.net_amount") %> + <%= t("views.right_panel.detail.net_amount") %> <%= number_with_precision(net, precision:precision.to_i,delimiter:delimiter) rescue '-'%>   diff --git a/app/views/reports/dailysale/index.xls.erb b/app/views/reports/dailysale/index.xls.erb index 8c9cccb6..094e4c80 100755 --- a/app/views/reports/dailysale/index.xls.erb +++ b/app/views/reports/dailysale/index.xls.erb @@ -31,6 +31,7 @@ <%= t("views.right_panel.detail.cash_sales") %> <%= t("views.right_panel.detail.credit_sales") %> <%= t("views.right_panel.detail.foc_sales") %> + <%= t("views.right_panel.detail.giftvoucher_sales") %> (<%= t("views.right_panel.detail.discount") %>) <%= t("views.right_panel.detail.grand_total") %> @@ -63,6 +64,7 @@ <% paymal = 0 %> <% dinga = 0 %> <% junctionpay = 0 %> + <% giftvoucher = 0 %> <% paypar = 0 %> <% cash = 0 %> <% credit = 0 %> @@ -83,6 +85,7 @@ <% paymal += sale[:paymal_amount] %> <% dinga += sale[:dinga_amount] %> <% junctionpay += sale[:junctionpay_amount] %> + <% giftvoucher += sale[:giftvoucher_amount] %> <% paypar += sale[:paypar_amount] %> <% cash += sale[:cash_amount]-sale[:total_change_amount] %> <% credit += sale[:credit_amount] %> @@ -109,6 +112,7 @@ <%= number_with_delimiter(sprintf("%.2f",sale[:cash_amount]-sale[:total_change_amount]), delimiter: delimiter) rescue '-'%> <%= number_with_delimiter(sprintf("%.2f",sale[:credit_amount]),delimiter => ',') rescue '-'%> <%= number_with_delimiter(sprintf("%.2f",sale[:foc_amount]),delimiter => ',') rescue '-'%> + <%= number_with_delimiter(sprintf("%.2f",sale[:giftvoucher_amount]),delimiter => ',') rescue '-'%> (<%= number_with_delimiter(sprintf("%.2f",sale[:total_discount]), delimiter => ',') rescue '-'%>) <%= number_with_delimiter(sprintf("%.2f",sale[:grand_total]),delimiter => ',') rescue '-'%> @@ -133,6 +137,7 @@ <%= number_with_delimiter(sprintf("%.2f",cash),delimiter => ',') rescue '-'%> <%= number_with_delimiter(sprintf("%.2f",credit),delimiter => ',') rescue '-'%> <%= number_with_delimiter(sprintf("%.2f",foc), delimiter => ',') rescue '-'%> + <%= number_with_delimiter(sprintf("%.2f",giftvoucher), delimiter => ',') rescue '-'%> (<%= number_with_delimiter(discount,delimiter => ',') rescue '-'%>) <%= number_with_delimiter(sprintf("%.2f",grand_total),delimiter => ',') rescue '-'%> @@ -145,7 +150,7 @@ <% @tax.each do |tax| total_tax += tax.tax_amount.to_f %> - <%= tax.tax_name rescue '-'%> + <%= tax.tax_name rescue '-'%> <%= number_with_delimiter(sprintf("%.2f",tax.tax_amount),delimiter => ',') rescue '-'%>   @@ -156,7 +161,7 @@ <% net = net - rounding_adj%> <% net = net - total_tax %> - <%= t("views.right_panel.detail.net_amount") %> + <%= t("views.right_panel.detail.net_amount") %> <%= number_with_delimiter(sprintf("%.2f",net),delimiter => ',') rescue '-'%>   diff --git a/app/views/reports/payment_method/index.html.erb b/app/views/reports/payment_method/index.html.erb index c3a00a5d..23480521 100755 --- a/app/views/reports/payment_method/index.html.erb +++ b/app/views/reports/payment_method/index.html.erb @@ -53,6 +53,7 @@ <%= t("views.right_panel.detail.cash_sales") %> <%= t("views.right_panel.detail.credit_sales") %> <%= t("views.right_panel.detail.foc_sales") %> + <%= t("views.right_panel.detail.giftvoucher_sales") %> <% if @print_settings.precision.to_i > 0 @@ -84,6 +85,7 @@ <%= number_with_precision(sale[:cash_amount]-sale[:total_change_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%= number_with_precision(sale[:credit_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%= number_with_precision(sale[:foc_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_with_precision(sale[:giftvoucher_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <% end %> diff --git a/app/views/reports/payment_method/index.xls.erb b/app/views/reports/payment_method/index.xls.erb index 73a53005..fa4ee81e 100755 --- a/app/views/reports/payment_method/index.xls.erb +++ b/app/views/reports/payment_method/index.xls.erb @@ -40,6 +40,7 @@ <%= t("views.right_panel.detail.cash_sales") %> <%= t("views.right_panel.detail.credit_sales") %> <%= t("views.right_panel.detail.foc_sales") %> + <%= t("views.right_panel.detail.giftvoucher_sales") %> <% unless @sale_data.empty? %> @@ -59,6 +60,7 @@ <%= number_with_delimiter(sprintf("%.2f",sale[:cash_amount]-sale[:total_change_amount]), :delimiter => ',') rescue '-'%> <%= number_with_delimiter(sprintf("%.2f",sale[:credit_amount]), :delimiter => ',') rescue '-'%> <%= number_with_delimiter(sprintf("%.2f",sale[:foc_amount]), :delimiter => ',') rescue '-'%> + <%= number_with_delimiter(sprintf("%.2f",sale[:giftvoucher_amount]), :delimiter => ',') rescue '-'%> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 1db778ca..f3596417 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -144,6 +144,7 @@ en: check_in: "Check In" card_settle: "CB CARD SETTLEMENT" + gift_voucher: "GiftVoucher" pagination: first: "« First" @@ -423,6 +424,7 @@ en: paymal_sales: "Paymal Sales" dinga_sales: "Dinga Sales" junctionpay_sales: "JunctionPay Sales" + gift_voucher_sales: "GiftVoucher Sales" redeem_sales: "Redeem Sales" cash_sales: "Cash Sales" credit_sales: "Credit Sales" diff --git a/config/locales/mm.yml b/config/locales/mm.yml index 283a31f2..3f58eac9 100644 --- a/config/locales/mm.yml +++ b/config/locales/mm.yml @@ -138,6 +138,7 @@ mm: exp_to_excel: "Excel သို့ ပို့ပြီးဆက်လက်လုပ်ဆောင်ရန်" card_settle: "CB ကဒ် စာရင်းရှင်းတမ်း" + gift_voucher: "GiftVoucher" pagination: first: "« ပထမ" last: "အဆံုး »" @@ -418,6 +419,7 @@ mm: paymal_sales: "Paymal ရောင်းရငွေ" dinga_sales: "Dinga ရောင်းရငွေ" junctionpay_sales: "JunctionPay ရောင်းရငွေ" + gift_voucher_sales: "GiftVoucher ရောင်းရငွေ" redeem_sales: "ဆုကြေးပြန်သုံးငွေနှင့် ရောင်းရငွေ" cash_sales: "ငွေသား ရောင်းရငွေ" credit_sales: "အကြွေး ရောင်းရငွေ" diff --git a/config/routes.rb b/config/routes.rb index 8e97f8b7..8c6a5e0c 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -199,6 +199,7 @@ scope "(:locale)", locale: /en|mm/ do post 'payment/alipay' => 'alipay#create' post 'payment/junctionpay' => 'junctionpay#create' post 'payment/dinga' => 'dinga#create' + post 'payment/gift_voucher' => 'gift_voucher#create' post 'payment/:type/change_tax' => 'payments#change_tax', :defaults => {:format => 'json'} @@ -215,6 +216,7 @@ scope "(:locale)", locale: /en|mm/ do get 'sale/:sale_id/:type/payment/others_payment/JunctionPay' => "junction_pay#index" get 'sale/:sale_id/:type/payment/others_payment/Alipay' => "alipay#index" get 'sale/:sale_id/:type/payment/others_payment/DINGA' => "dinga#index" + get 'sale/:sale_id/:type/payment/others_payment/GiftVoucher' => "gift_voucher#index" #---------Void --------------# post 'sale/:sale_id/:type/void' => 'void#overall_void'