sale item report and rebate balance

This commit is contained in:
Aung Myo
2017-06-19 11:54:34 +06:30
parent faa6beb243
commit 675d83c80f
16 changed files with 391 additions and 137 deletions

View File

@@ -16,6 +16,14 @@ class Sale < ApplicationRecord
scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") }
REPORT_TYPE = {
"daily" => 0,
"monthly" => 1,
"yearly" => 2
}
SALE_STATUS_COMPLETED = "completed"
def generate_invoice_from_booking(booking_id, requested_by)
booking = Booking.find(booking_id)
status = false
@@ -328,6 +336,40 @@ class Sale < ApplicationRecord
return daily_total
end
def self.get_by_range_by_saleitems(from,to,status,report_type)
query = Sale.select("
mi.item_code as code,(SUM(i.qty) * i.unit_price) as grand_total,
SUM(i.qty) as total_item," +
" i.unit_price as unit_price,
mi.name as product_name,
mc.name as menu_category_name,
mc.id as menu_category_id ")
.group('mi.id')
.order("mi.menu_category_id")
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id
JOIN menu_items mi ON i.product_code = mi.item_code" +
" JOIN menu_categories mc ON mc.id = mi.menu_category_id
JOIN employees ea ON ea.id = sales.cashier_id")
query = query.where("receipt_date between ? and ? and sale_status=?",from,to,status)
case report_type.to_i
when REPORT_TYPE["daily"]
return query
when REPORT_TYPE["monthly"]
return query.group("MONTH(date)")
when REPORT_TYPE["yearly"]
return query.group("YEAR(date)")
end
end
private
def generate_custom_id