This commit is contained in:
Aung Myo
2017-07-11 16:50:41 +06:30
24 changed files with 726 additions and 102 deletions

View File

@@ -84,6 +84,7 @@ class Ability
can :create, :discount
can :remove_discount_items, :discount
can :remove_all_discount, :discount
can :member_discount, :discount
can :first_bill, :payment
can :show, :payment

View File

@@ -54,6 +54,7 @@ class Employee < ApplicationRecord
def self.logout(session_token)
if (session_token)
user = Employee.find_by_token_session(session_token)
if user
user.token_session = nil
user.session_expiry = nil

View File

@@ -1,4 +1,7 @@
class MenuCategory < ApplicationRecord
before_create :generate_menu_category_code
belongs_to :menu
has_many :children, :class_name => "MenuCategory", foreign_key: "menu_category_id"
belongs_to :parent, :class_name => "MenuCategory", foreign_key: "menu_category_id", optional: true
@@ -12,7 +15,7 @@ class MenuCategory < ApplicationRecord
# find the sub menu item of current item
sub_menu_cat = MenuCategory.where("menu_category_id=?",menu_category.id)
if sub_menu_cat.length != 0
sub_menu_cat.each do |sub|
sub_menu_cat.each do |sub|
if destroyCategory(sub)
end
end
@@ -20,17 +23,22 @@ class MenuCategory < ApplicationRecord
items = MenuItem.where("menu_category_id=?",menu_category.id)
items.each do |item|
abc = MenuItem.deleteRecursive(item)
end
end
menu_category.destroy
return true
else
items = MenuItem.where("menu_category_id=?",menu_category.id)
items.each do |item|
abc = MenuItem.deleteRecursive(item)
end
end
menu_category.destroy
return false
end
end
private
def generate_menu_category_code
self.code = SeedGenerator.generate_id(self.class.name, "C")
end
end

View File

@@ -1,5 +1,7 @@
class MenuItem < ApplicationRecord
before_create :generate_menu_item_code
belongs_to :menu_category, :optional => true
has_many :menu_item_instances
belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id", :optional => true
@@ -11,7 +13,7 @@ class MenuItem < ApplicationRecord
default_scope { order('item_code asc') }
scope :simple_menu_item, -> { where(type: 'SimpleMenuItem') }
scope :set_menu_item, -> { where(type: 'SetMenuItem') }
scope :set_menu_item, -> { where(type: 'SetMenuItem') }
def self.collection
MenuItem.select("id, name").map { |e| [e.name, e.id] }
@@ -46,7 +48,7 @@ class MenuItem < ApplicationRecord
# find the sub menu item of current item
sub_menu_items = MenuItem.where("menu_item_id=?",menu_item.id)
if sub_menu_items.length != 0
sub_menu_items.each do |subitem|
sub_menu_items.each do |subitem|
if deleteRecursive(subitem)
end
end
@@ -54,17 +56,24 @@ class MenuItem < ApplicationRecord
instances = MenuItemInstance.where("menu_item_id=?",menu_item.id)
instances.each do |instance|
instance.destroy
end
end
menu_item.destroy
return true
else
instances = MenuItemInstance.where("menu_item_id=?",menu_item.id)
instances.each do |instance|
instance.destroy
end
end
menu_item.destroy
return false
end
end
end
private
def generate_menu_item_code
self.item_code = SeedGenerator.generate_id(self.class.name, "I")
end
end

View File

@@ -1,6 +1,7 @@
class MenuItemInstance < ApplicationRecord
belongs_to :menu_item
before_create :generate_menu_item_instance_code
def self.findParentCategory(item)
if item.menu_category_id
return item.menu_category_id
@@ -9,4 +10,10 @@ class MenuItemInstance < ApplicationRecord
findParentCategory(parentitem)
end
end
private
def generate_menu_item_instance_code
self.item_instance_code = SeedGenerator.generate_id(self.class.name, "II")
end
end

View File

@@ -26,9 +26,13 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker
#Use CUPS service
#Generate PDF
#Print
cashier = shift_sale.employee.name
shift_name = shift_sale.shift_started_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + "_" + shift_sale.shift_closed_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p")
pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details)
pdf.render_file "tmp/print_close_cashier.pdf"
self.print("tmp/print_close_cashier.pdf")
filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf"
pdf.render_file filename
self.print(filename)
end

View File

@@ -6,7 +6,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
#Print
order_item = print_query('order_item', item_code) #OrderItem.find_by_item_code(item_code)
filename = "tmp/order_item_#{order_item[0].item_name}" + ".pdf"
filename = "tmp/order_item.pdf"
# check for item not to show
if order_item[0].price != 0
@@ -35,7 +35,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
# For Print Per Item
if oqs.cut_per_item
order.each do|odi|
filename = "tmp/order_item_#{odi.item_name}" + ".pdf"
filename = "tmp/order_item.pdf"
# For Item Options
options = odi.options == "[]"? "" : odi.options
@@ -54,7 +54,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
end
# For Print Order Summary
else
filename = "tmp/order_summary_#{ order_id }" + ".pdf"
filename = "tmp/order_summary.pdf"
pdf = OrderSummaryPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name)
pdf.render_file filename
if oqs.print_copy
@@ -75,7 +75,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
# For Print Per Item
if oqs.cut_per_item
order.each do|odi|
filename = "tmp/order_item_#{odi.item_name}" + ".pdf"
filename = "tmp/order_item.pdf"
# For Item Options
options = odi.options == "[]"? "" : odi.options
@@ -97,7 +97,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
end
# For Print Order Summary
else
filename = "tmp/booking_summary_#{ booking_id }" + ".pdf"
filename = "tmp/booking_summary.pdf"
pdf = OrderSummaryPdf.new(print_settings,order, print_status,oqs.use_alternate_name)
pdf.render_file filename
if oqs.print_copy

View File

@@ -75,8 +75,14 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
# print as print copies in printer setting
count = printer_settings.print_copies
begin
pdf.render_file "tmp/receipt_bill.pdf"
self.print("tmp/receipt_bill.pdf")
if count == 1
pdf.render_file "tmp/receipt_bill_#{sale_data.receipt_no}.pdf"
self.print("tmp/receipt_bill_#{sale_data.receipt_no}.pdf")
else
pdf.render_file "tmp/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf"
self.print("tmp/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf")
end
count -= 1
end until count == 0
end

View File

@@ -208,7 +208,7 @@ class Sale < ApplicationRecord
end
#compute - invoice total
def compute_by_sale_items(sale_id, sale_itemss, total_discount)
def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil)
sale = Sale.find(sale_id)
sales_items = sale_itemss
@@ -227,6 +227,9 @@ class Sale < ApplicationRecord
sale.total_amount = subtotal_price
sale.total_discount = total_discount
sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax
if discount_type == "member_discount"
sale.discount_type = discount_type
end
#compute rounding adjustment
# adjust_rounding
@@ -427,7 +430,7 @@ class Sale < ApplicationRecord
SUM(case when (sale_payments.payment_method='jcb') then sale_payments.payment_amount else 0 end) as jcb_amount,
SUM(case when (sale_payments.payment_method='paypar') then sale_payments.payment_amount else 0 end) as paypar_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='credit') 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")
.joins("join (select * from sale_payments group by sale_payments.sale_id, sale_payments.payment_method) sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sale_status = ? AND sales.receipt_date between ? and ? AND total_amount != 0", 'completed', from, to)
@@ -682,7 +685,7 @@ def self.get_separate_tax(from,to,payment_method=nil)
end
def grand_total_after_rounding
return self.grand_total.to_f + self.rounding_adjustment.to_f
return self.old_grand_total.to_f + self.rounding_adjustment.to_f
end
def get_cash_amount

View File

@@ -57,7 +57,7 @@ class SaleItem < ApplicationRecord
# Check for actual sale items
sale_items.where("is_taxable = false AND remark = 'Discount'").find_each do |si|
if si.account_id == a.id
discount_account[:price] = (discount_account[:price] + si.price) * -1
discount_account[:price] = (discount_account[:price].abs + si.price.abs) * -1
end
end
discount_accounts.push(discount_account)