Merge branch 'staging' of bitbucket.org:code2lab/sxrestaurant
This commit is contained in:
@@ -517,7 +517,8 @@ def self.get_by_shiftsales(from,to,shift)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.get_by_shift_sale(from,to,status)
|
def self.get_by_shift_sale(from,to,status)
|
||||||
query = ShiftSale.select("shift_sales.id ,shift_started_at AS opening_date,shift_closed_at As closing_date," +
|
query = ShiftSale.select("shift_sales.id ,shift_started_at AS opening_date,
|
||||||
|
shift_closed_at As closing_date," +
|
||||||
" grand_total AS grand_total, cash_sales AS cash," +
|
" grand_total AS grand_total, cash_sales AS cash," +
|
||||||
"total_taxes AS total_tax,total_discounts As total_discount")
|
"total_taxes AS total_tax,total_discounts As total_discount")
|
||||||
.order("shift_sales.id DESC")
|
.order("shift_sales.id DESC")
|
||||||
@@ -551,25 +552,7 @@ def self.get_item_query()
|
|||||||
total_foc_amount = 0
|
total_foc_amount = 0
|
||||||
total_grand_total = 0
|
total_grand_total = 0
|
||||||
|
|
||||||
if shift.blank?
|
if shift.present?
|
||||||
### => get all sales range in shift_sales
|
|
||||||
query = query.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') 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")
|
|
||||||
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
|
||||||
.where("sales.shift_sale_id in (?) and sale_status = 'completed' ", shift_sale_range.to_a)
|
|
||||||
sale_cash.each do |s_c|
|
|
||||||
total_cash_amount += s_c.cash_amount.to_f
|
|
||||||
total_card_amount += s_c.card_amount.to_f
|
|
||||||
total_credit_amount += s_c.credit_amount.to_f
|
|
||||||
total_foc_amount += s_c.foc_amount.to_f
|
|
||||||
end
|
|
||||||
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
|
|
||||||
else
|
|
||||||
query = query.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
|
query = query.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)
|
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)
|
change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed)
|
||||||
@@ -578,7 +561,44 @@ def self.get_item_query()
|
|||||||
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='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='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
|
||||||
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||||
.where("sales.shift_sale_id in (?) and sale_status = 'completed' ", shift.to_a)
|
.where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a)
|
||||||
|
sale_cash.each do |s_c|
|
||||||
|
total_cash_amount += s_c.cash_amount.to_f
|
||||||
|
total_card_amount += s_c.card_amount.to_f
|
||||||
|
total_credit_amount += s_c.credit_amount.to_f
|
||||||
|
total_foc_amount += s_c.foc_amount.to_f
|
||||||
|
end
|
||||||
|
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
|
||||||
|
|
||||||
|
### => get all sales range in shift_sales
|
||||||
|
elsif shift_sale_range.present?
|
||||||
|
query = query.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') 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")
|
||||||
|
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||||
|
.where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a)
|
||||||
|
sale_cash.each do |s_c|
|
||||||
|
total_cash_amount += s_c.cash_amount.to_f
|
||||||
|
total_card_amount += s_c.card_amount.to_f
|
||||||
|
total_credit_amount += s_c.credit_amount.to_f
|
||||||
|
total_foc_amount += s_c.foc_amount.to_f
|
||||||
|
end
|
||||||
|
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
|
||||||
|
|
||||||
|
else
|
||||||
|
query = query.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') 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")
|
||||||
|
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||||
|
.where("sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to)
|
||||||
sale_cash.each do |s_c|
|
sale_cash.each do |s_c|
|
||||||
total_cash_amount += s_c.cash_amount.to_f
|
total_cash_amount += s_c.cash_amount.to_f
|
||||||
total_card_amount += s_c.card_amount.to_f
|
total_card_amount += s_c.card_amount.to_f
|
||||||
@@ -606,13 +626,22 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_ty
|
|||||||
|
|
||||||
query = Sale.all
|
query = Sale.all
|
||||||
if shift.present?
|
if shift.present?
|
||||||
|
|
||||||
query = query.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a)
|
query = query.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a)
|
||||||
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||||
.group("sales.sale_id")
|
.group("sales.sale_id")
|
||||||
else
|
|
||||||
|
elsif shift_sale_range.present?
|
||||||
|
|
||||||
query = query.where("sale_status='completed' #{payment_type} and sale_payments.payment_amount != 0 and sales.shift_sale_id in (?)",shift_sale_range.to_a)
|
query = query.where("sale_status='completed' #{payment_type} and sale_payments.payment_amount != 0 and sales.shift_sale_id in (?)",shift_sale_range.to_a)
|
||||||
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||||
.group("sales.sale_id")
|
.group("sales.sale_id")
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
query = query.where("sale_status='completed' and sales.receipt_date between ? and ? #{payment_type} and sale_payments.payment_amount != 0",from,to)
|
||||||
|
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||||
|
.group("sales.sale_id")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -636,13 +665,20 @@ def self.get_separate_tax(shift_sale_range=nil,shift,from,to,payment_type)
|
|||||||
.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a)
|
.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a)
|
||||||
.group("sale_taxes.tax_name")
|
.group("sale_taxes.tax_name")
|
||||||
.order("sale_taxes.sale_tax_id asc")
|
.order("sale_taxes.sale_tax_id asc")
|
||||||
else
|
elsif shift_sale_range.present?
|
||||||
query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name")
|
query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name")
|
||||||
.joins("LEFT JOIN sales ON sales.sale_id = sale_taxes.sale_id")
|
.joins("LEFT JOIN sales ON sales.sale_id = sale_taxes.sale_id")
|
||||||
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||||
.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", shift_sale_range.to_a)
|
.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", shift_sale_range.to_a)
|
||||||
.group("sale_taxes.tax_name")
|
.group("sale_taxes.tax_name")
|
||||||
.order("sale_taxes.sale_tax_id asc")
|
.order("sale_taxes.sale_tax_id asc")
|
||||||
|
else
|
||||||
|
query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name")
|
||||||
|
.joins("LEFT JOIN sales ON sales.sale_id = sale_taxes.sale_id")
|
||||||
|
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||||
|
.where("sales.receipt_date between ? and ? #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", from,to)
|
||||||
|
.group("sale_taxes.tax_name")
|
||||||
|
.order("sale_taxes.sale_tax_id asc")
|
||||||
end
|
end
|
||||||
|
|
||||||
# query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name")
|
# query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name")
|
||||||
|
|||||||
@@ -143,7 +143,10 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
y_position = cursor
|
y_position = cursor
|
||||||
|
|
||||||
pad_top(15) {
|
pad_top(15) {
|
||||||
text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size , :overflow => :expand
|
bounding_box([0,y_position], :width =>self.item_width) do
|
||||||
|
text "#{product_name}", :size => self.item_font_size,:align => :left
|
||||||
|
end
|
||||||
|
# text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size
|
||||||
text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
|
text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
|
||||||
text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_name_width,y_position], :width => self.qty_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
|
text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_name_width,y_position], :width => self.qty_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
|
||||||
text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[(item_name_width+4),y_position], :width =>self.total_width+3, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
|
text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[(item_name_width+4),y_position], :width =>self.total_width+3, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
|
||||||
|
|||||||
Reference in New Issue
Block a user