shop code

This commit is contained in:
Myat Zin Wai Maw
2019-11-22 18:24:02 +06:30
parent 5a3f328789
commit d1ab2c194d
106 changed files with 834 additions and 895 deletions

View File

@@ -34,9 +34,9 @@ class SalePayment < ApplicationRecord
end
end
def self.get_kbz_pay_amount(sale_id, current_user)
def self.get_kbz_pay_amount(sale_id, current_user,shop)
amount = 0
kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last
kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY,:shop_code => shop.shop_code).last
sale_payment = SalePayment.where('sale_id=? and payment_method=? and payment_status!=?', sale_id, KbzPay::KBZ_PAY, 'dead').last
if !sale_payment.nil? and !kbz_pay_method.nil?
if sale_payment.payment_status == 'pending'
@@ -136,11 +136,12 @@ class SalePayment < ApplicationRecord
#record an payment in sale-audit
remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}"
if payment_for
shift = ShiftSale.current_open_shift(self.sale.cashier_id)
current_shift_user =Employee.find_by_id(self.sale.cashier_id)
shift = ShiftSale.current_open_shift(current_shift_user)
if !shift.nil?
shift_sale_id = shift.id
else
shift = ShiftSale.current_shift
shift = ShiftSale.current_shift(self.sale.shop_code)
shift_sale_id = shift.id
end
@@ -726,11 +727,12 @@ class SalePayment < ApplicationRecord
# update for cashier shift
def update_shift
shift = ShiftSale.current_open_shift(self.action_by.id)
current_shift_user = Employee.find_by_id(self.action_by.id)
shift = ShiftSale.current_open_shift(current_shift_user)
if shift.nil?
shift = ShiftSale.current_open_shift(self.sale.cashier_id)
current_shift_user = Employee.find_by_id(self.sale.cashier_id)
shift = ShiftSale.current_open_shift(current_shift_user)
end
if !shift.nil?
@@ -740,7 +742,7 @@ class SalePayment < ApplicationRecord
self.sale.cashier_name = Employee.find(shift.employee_id).name
self.sale.save
else
shift = ShiftSale.current_shift
shift = ShiftSale.current_shift(self.sale.shop_code)
shift.update(self.sale)
self.sale.shift_sale_id = shift.id
self.sale.cashier_id = shift.employee_id
@@ -972,7 +974,7 @@ class SalePayment < ApplicationRecord
end
#credit payment query
def self.get_credit_sales(params)
def self.get_credit_sales(params,shop_code)
receipt_no = ""
customer = ""
if !params["receipt_no"].blank?
@@ -1001,7 +1003,7 @@ class SalePayment < ApplicationRecord
else
query = query.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' AND #{order_source_query}='#{params[:type]}' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}")
end
query = query.group("s.receipt_no")
query = query.where("s.shop_code='#{shop_code}'").group("s.receipt_no")
.order("s.receipt_date ASC, s.receipt_no ASC")
return query
end