Pull from master

This commit is contained in:
San Wai Lwin
2018-03-29 18:17:10 +06:30
122 changed files with 4008 additions and 1115 deletions

View File

@@ -105,7 +105,7 @@ class Ability
can :show, :home
can :read, Order
can :update, Order
can :menage, Booking
can :manage, Booking
can :manage, OrderQueueStation
can :read, Sale
can :update, Sale

View File

@@ -12,7 +12,7 @@ class InventoryDefinition < ApplicationRecord
end
def self.find_product_in_inventory(item)
product = InventoryDefinition.find_by_item_code(item.product_code)
product = InventoryDefinition.find_by_item_code(item.item_instance_code)
if product.nil?
return false, nil
else
@@ -21,7 +21,7 @@ class InventoryDefinition < ApplicationRecord
end
def self.check_balance(item,inventory_definition) # item => saleItemOBj
stock = StockJournal.where('item_code=?', item.product_code).order('created_at desc').take
stock = StockJournal.where('item_code=?', item.item_instance_code).order('created_at desc').take
unless stock.nil?
modify_balance(item, stock, inventory_definition)
else

View File

@@ -1,7 +1,7 @@
class License
include HTTParty
base_uri "connect.smartsales.dev/api"
base_uri "connect.smartsales.asia/api"
attr_accessor :name, :address_1, :address_2, :township, :city, :country, :email, :phone, :fax, :logo, :subdomain,
:plan_activation_date, :plan_next_renewal_date, :plan_max_products,:plan_max_customers, :plan_active_connections,

View File

@@ -1,4 +1,6 @@
class Menu < ApplicationRecord
require 'spreadsheet'
has_many :menu_categories, dependent: :destroy
validates_presence_of :name, :valid_days, :valid_time_from, :valid_time_to
@@ -33,27 +35,118 @@ class Menu < ApplicationRecord
end
def self.to_csv
m_attributes = %w{id name is_active valid_days valid_time_from valid_time_to created_by created_at updated_at}
CSV.generate(headers: true) do |csv|
m_attributes = %w{name is_active valid_days valid_time_from valid_time_to created_by created_at updated_at}
CSV.generate(headers: true, row_sep: "\r\n") do |csv|
csv << m_attributes
menu = Menu.all
menu.each do |user|
puts user
csv << m_attributes.map{ |attr| user.send(attr)}
end
end
end
# mc_attributes = %w{id menu_id code name alt_name order_by created_by menu_category_id is_available created_at updated_at}
# CSV.generate(headers: true) do |csv|
# csv << m_attributes
def self.import(file)
spreadsheet = open_spreadsheet(file)
sheet_count = spreadsheet.sheets.count-1
for i in 0..sheet_count do
header = spreadsheet.sheet(i).row(1)
sheet_name = spreadsheet.sheets[i]
# csv << mc_attributes
# MenuCategory.all.each do |user|
# puts user
# csv << mc_attributes.map{ |attr| user.send(attr)}
# end
# end
(2..spreadsheet.sheet(i).last_row).each do |ii|
row = Hash[[header,spreadsheet.sheet(i).row(ii)].transpose]
if sheet_name == "Account"
# Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"])
account = Account.find_by_id(row["id"])
if account
Account.create(title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"])
else
Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"])
end
elsif sheet_name == "Item Set"
# ItemSet.create(id:row["id"], name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty])
item_set = ItemSet.find_by_id(row["id"])
if item_set
ItemSet.create( name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty])
else
ItemSet.create(id:row["id"], name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty])
end
elsif sheet_name == "Menu Item Options"
# MenuItemOption.create(id:row["id"], option_type: row["option_type"],name: row["name"],value: row["value"])
item_options = MenuItemOption.find_by_id(row["id"])
if item_options
MenuItemOption.create( option_type: row["option_type"],name: row["name"],value: row["value"])
else
MenuItemOption.create(id:row["id"], option_type: row["option_type"],name: row["name"],value: row["value"])
end
elsif sheet_name == "Menu Item Attributes"
# MenuItemAttribute.create(id:row["id"], attribute_type: row["attribute_type"],name: row["name"],value: row["value"])
item_attributes = MenuItemAttribute.find_by_id(row["id"])
if item_attributes
MenuItemAttribute.create( attribute_type: row["attribute_type"],name: row["name"],value: row["value"])
else
MenuItemAttribute.create(id:row["id"], attribute_type: row["attribute_type"],name: row["name"],value: row["value"])
end
elsif sheet_name == "Menu"
menu = Menu.find_by_id(row["id"])
if menu
Menu.create(name: row["name"], is_active: row["is_active"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"])
else
Menu.create(id:row["id"], name: row["name"], is_active: row["is_active"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"])
end
elsif sheet_name == "Menu Category"
# MenuCategory.create(id:row["id"], menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"])
menu_category = MenuCategory.find_by_id(row["id"])
if menu_category
MenuCategory.create(menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"])
else
MenuCategory.create(id:row["id"], menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"])
end
elsif sheet_name == "Menu Item"
# MenuItem.create(id:row["id"], item_code: row["item_code"], name: row["name"], alt_name: row["alt_name"], image_path: row["image_path"], description: row["description"], information: row["information"], unit: row["unit"], type: row["type"], menu_category_id: row["menu_category_id"], item_attributes: row["item_attributes"], item_options: row["item_options"], account_id: row["account_id"], min_qty: row["min_qty"], taxable: row["taxable"], is_sub_item: row["is_sub_item"], is_available: row["is_available"], created_by: row["created_by"])
menu_item = MenuItem.find_by_id(row["id"])
if menu_item
MenuItem.create(item_code: row["item_code"], name: row["name"], alt_name: row["alt_name"], image_path: row["image_path"], description: row["description"], information: row["information"], unit: row["unit"], type: row["type"], menu_category_id: row["menu_category_id"], item_attributes: JSON.parse(row["item_attributes"]), item_options: JSON.parse(row["item_options"]), account_id: row["account_id"], min_qty: row["min_qty"], taxable: row["taxable"], is_sub_item: row["is_sub_item"], is_available: row["is_available"], created_by: row["created_by"])
else
MenuItem.create(id:row["id"], item_code: row["item_code"], name: row["name"], alt_name: row["alt_name"], image_path: row["image_path"], description: row["description"], information: row["information"], unit: row["unit"], type: row["type"], menu_category_id: row["menu_category_id"], item_attributes: JSON.parse(row["item_attributes"]), item_options: JSON.parse(row["item_options"]), account_id: row["account_id"], min_qty: row["min_qty"], taxable: row["taxable"], is_sub_item: row["is_sub_item"], is_available: row["is_available"], created_by: row["created_by"])
end
elsif sheet_name == "Menu Item Instance"
# MenuItemInstance.create(id:row["id"], menu_item_id: row["menu_item_id"].to_i, item_instance_code: row["item_instance_code"], item_instance_name: row["item_instance_name"], item_attributes: row["item_attributes"], price: row["price"], is_on_promotion: row["is_on_promotion"], promotion_price: row["promotion_price"], is_available: row["is_available"], is_default: row["is_default"])
item_instance = MenuItemInstance.find_by_id(row["id"])
if item_instance
MenuItemInstance.create(menu_item_id: row["menu_item_id"].to_i, item_instance_code: row["item_instance_code"], item_instance_name: row["item_instance_name"], item_attributes: JSON.parse(row["item_attributes"]), price: row["price"], is_on_promotion: row["is_on_promotion"], promotion_price: row["promotion_price"], is_available: row["is_available"], is_default: row["is_default"])
else
MenuItemInstance.create(id:row["id"], menu_item_id: row["menu_item_id"].to_i, item_instance_code: row["item_instance_code"], item_instance_name: row["item_instance_name"], item_attributes: JSON.parse(row["item_attributes"]), price: row["price"], is_on_promotion: row["is_on_promotion"], promotion_price: row["promotion_price"], is_available: row["is_available"], is_default: row["is_default"])
end
elsif sheet_name == "Menu Instance Item Set"
# MenuInstanceItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"])
menu_instance_set = MenuInstanceItemSet.find_by_id(row["id"])
if menu_instance_set
MenuInstanceItemSet.create(item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"])
else
MenuInstanceItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"])
end
elsif sheet_name == "Menu Item Set"
# MenuItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"])
menu_item_set = MenuItemSet.find_by_id(row["id"])
if menu_item_set
MenuItemSet.create(item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"])
else
MenuItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"])
end
end
end
end
end
def self.open_spreadsheet(file)
case File.extname(file.original_filename)
when ".csv" then Roo::CSV.new(file.path,nil,:ignore)
when ".xls" then Roo::Excel.new(file.path,nil,:ignore)
when ".xlsx" then Roo::Excelx.new(file.path,nil,:ignore)
else raise "Unknown File type: #{original_filename}"
end
end
end

View File

@@ -1,7 +1,7 @@
class MenuCategory < ApplicationRecord
# before_create :generate_menu_category_code
belongs_to :menu
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
has_many :menu_items
@@ -83,4 +83,19 @@ class MenuCategory < ApplicationRecord
# def generate_menu_category_code
# self.code = SeedGenerator.generate_code(self.class.name, "C")
# end
def self.to_csv
mc_attributes = %w{id menu_id code name alt_name order_by created_by menu_category_id is_available created_at updated_at}
CSV.generate(headers: true) do |csv|
csv << mc_attributes
csv << mc_attributes
MenuCategory.all.each do |user|
puts user
csv << mc_attributes.map{ |attr| user.send(attr)}
end
end
end
end

View File

@@ -71,9 +71,9 @@ class Order < ApplicationRecord
BookingOrder.create({:booking_id => booking.booking_id, :order => self})
#Send order to queue one it done!
if self.source != "quick_service"
# if self.source != "quick_service"
process_order_queue
end
# end
#send order to broadcast job
send_order_broadcast(booking)
@@ -297,7 +297,7 @@ class Order < ApplicationRecord
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, self.table_id)
oqs.process_order(order, self.table_id, self.source)
end
assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id)
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
@@ -313,7 +313,7 @@ class Order < ApplicationRecord
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, self.table_id)
oqs.process_order(order, self.table_id, self.source)
end
assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id)
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
@@ -326,7 +326,7 @@ class Order < ApplicationRecord
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, self.table_id)
oqs.process_order(order, self.table_id, self.source)
end
assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id)
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order

View File

@@ -5,7 +5,8 @@ class OrderItem < ApplicationRecord
before_create :generate_custom_id
#Associations
belongs_to :order, autosave: true
belongs_to :order, autosave: true
# belongs_to :order, counter_cache: true
#Validation
validates_presence_of :item_code, :item_name, :qty

View File

@@ -13,7 +13,7 @@ class OrderQueueStation < ApplicationRecord
# validations
validates_presence_of :station_name, :printer_name
def process_order (order, table_id)
def process_order (order, table_id, order_source = nil)
oqs_stations = OrderQueueStation.active
@@ -55,7 +55,7 @@ class OrderQueueStation < ApplicationRecord
end
end
if oqs.auto_print
if oqs.auto_print && order_source != "quick_service"
if oqs_order_items.length > 0
print_slip(oqs, order, oqs_order_items)
is_auto_printed = true
@@ -90,7 +90,81 @@ class OrderQueueStation < ApplicationRecord
end
end
if oqs.auto_print
if oqs.auto_print && order_source != "quick_service"
if oqs_order_items.length > 0
print_slip(oqs, order, oqs_order_items)
is_auto_printed = true
end
end
end
end
end #end else
end
def pay_process_order_queue (order_id, table_id)
oqs_stations = OrderQueueStation.active
order = Order.find(order_id)
order_items = order.order_items
if table_id.to_i > 0
# get dining
dining = DiningFacility.find(table_id)
oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}")
booking = Booking.find_by_dining_facility_id(dining.id)
# ToDo per item per printer
oqs_by_zones.each do |oqpbz|
oqs = OrderQueueStation.find(oqpbz.order_queue_station_id)
is_auto_printed = false
oqs_order_items = []
if oqs.is_active
#Get List of items -
pq_items = JSON.parse(oqs.processing_items)
#Loop through the processing items
pq_items.each do |pq_item|
#Processing through the looping items
order_items.each do |order_item|
if (pq_item == order_item.item_code)
if (order_item.qty > 0)
oqs_order_items.push(order_item)
end
end
end
end
if oqs.auto_print
if oqs_order_items.length > 0
print_slip(oqs, order, oqs_order_items)
is_auto_printed = true
end
end
end
end
else
oqs_stations.each do |oqs|
is_auto_printed = false
oqs_order_items = []
if oqs.is_active
#Get List of items -
pq_items = JSON.parse(oqs.processing_items)
#Loop through the processing items
pq_items.each do |pq_item|
#Processing through the looping items
order_items.each do |order_item|
if (pq_item == order_item.item_code)
if (order_item.qty > 0)
oqs_order_items.push(order_item)
end
end
end
end
if oqs.auto_print
if oqs_order_items.length > 0
print_slip(oqs, order, oqs_order_items)
is_auto_printed = true

View File

@@ -1,6 +1,6 @@
class PrintSetting < ApplicationRecord
# validations
validates_presence_of :name, :unique_code, :printer_name, :page_width, :page_height, :print_copies
validates_presence_of :name, :unique_code, :printer_name, :brand_name, :api_settings, :page_width, :page_height, :print_copies
def self.get_precision_delimiter
PrintSetting.find_by_unique_code("ReceiptBillPdf")

View File

@@ -24,6 +24,11 @@ class Printer::PrinterWorker
end
end
# Options from printer name
def self.printer_options(printer_name)
Cups.options_for(printer_name)
end
def self.printers()
Cups.show_destinations
end

View File

@@ -176,7 +176,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
def print_receipt_bill(printer_settings,cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data)
#Use CUPS service
#Generate PDF
#Print
#Print
pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data)
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
if !receipt_bill_a5_pdf.empty?
@@ -202,14 +202,14 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
begin
if count == 1
filename = "/receipts/receipt_bill_#{sale_data.receipt_no}.pdf"
pdf.render_file directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf"
filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf"
pdf.render_file filename
if printed_status != 'Paid'
self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name)
end
else
filename = "/receipts/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf"
pdf.render_file directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf"
filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf"
pdf.render_file filename
if printed_status != 'Paid'
self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf", cashier_terminal.printer_name)
end
@@ -272,11 +272,11 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
def print_receipt_pdf(filename,receipt_no,print_copies,printer_name)
count = print_copies.to_i
# if count == 0
# self.print("public"+filename, printer_name)
# self.print(filename, printer_name)
# else
begin
if count == 1
self.print("public"+filename, printer_name)
self.print(filename, printer_name)
else
filename = "public/receipts/receipt_bill_#{receipt_no}_#{count}.pdf"
self.print(filename, printer_name)

File diff suppressed because it is too large Load Diff

View File

@@ -11,6 +11,7 @@ class SalePayment < ApplicationRecord
def process_payment(invoice, action_by, cash_amount, payment_method,remark=nil)
self.sale = invoice
self.received_amount = cash_amount
self.payment_reference = remark
amount_due = invoice.grand_total
#get all payment for this invoices
@@ -48,6 +49,8 @@ class SalePayment < ApplicationRecord
payment_status = paypar_payment
when "foc"
payment_status = foc_payment
when "JunctionPay"
payment_status = junction_pay_payment
else
puts "it was something else"
end
@@ -205,8 +208,7 @@ class SalePayment < ApplicationRecord
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)
sale_update_payment_status(self.received_amount)
return payment_status
end
@@ -297,6 +299,22 @@ class SalePayment < ApplicationRecord
end
def junction_pay_payment
payment_status = false
#Next time - validate if the vochure number is valid - within
self.payment_method = "JunctionPay"
self.payment_amount = self.received_amount
# self.payment_reference = self.payment_reference
self.outstanding_amount = self.sale.grand_total- self.received_amount
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
@@ -306,6 +324,7 @@ class SalePayment < ApplicationRecord
sObj = Sale.find(self.sale_id)
is_credit = 0
is_foc = 0
method_status = false
sObj.sale_payments.each do |spay|
all_received_amount += spay.payment_amount.to_f
if spay.payment_method == "creditnote"
@@ -314,8 +333,12 @@ class SalePayment < ApplicationRecord
if spay.payment_method == "foc"
is_foc = 1
end
if spay.payment_method == "cash" || spay.payment_method == "foc" || spay.payment_method == "creditnote"
method_status = true
end
end
if (self.sale.grand_total <= all_received_amount)
if (self.sale.grand_total <= all_received_amount) && method_status
if is_credit == 0
self.sale.payment_status = "paid"
else
@@ -355,11 +378,15 @@ class SalePayment < ApplicationRecord
end
self.sale.save!
table_update_status(sObj)
if check_foc
table_update_status(sObj)
update_shift
elsif paid_amount.to_f > 0 #|| paid_amount != "0.0"
table_update_status(sObj)
update_shift
elsif method_status && paid_amount.to_f == 0
table_update_status(sObj)
update_shift
end
end

View File

@@ -8,7 +8,7 @@ class StockJournal < ApplicationRecord
balance = calculate_balance(balance, item.qty)
journal = StockJournal.new
journal.item_code = item.product_code
journal.item_code = item.item_instance_code
journal.inventory_definition_id = inventory_definition.id
journal.debit = item.qty
journal.balance = balance
@@ -36,12 +36,16 @@ class StockJournal < ApplicationRecord
journal.save
end
def self.inventory_balances(today,from,to)
def self.inventory_balances(today,from,to,from_time,to_time)
if !from.nil? && !to.nil?
query = StockJournal.select("mii.item_instance_name as item_instance_name,balance")
.joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code")
.where("stock_journals.created_at between '#{from}' and '#{to}'")
.group("mii.item_instance_name")
if !from_time.nil? && !to_time.nil?
query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'")
else
query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'")
end
query = query.group("mii.item_instance_name")
.order("mii.item_instance_name ASC")
else
query = StockJournal.select("mii.item_instance_name as item_instance_name,balance")

View File

@@ -1,2 +1,17 @@
class Survey < ApplicationRecord
def self.search(filter,from,to)
if filter.blank?
keyword = ''
else
keyword = "dining_name LIKE ?","%#{filter}%"
end
if from.present? && to.present?
survey = Survey.where("DATE_FORMAT(created_at,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(created_at,'%d-%m-%Y') <= ?", from,to)
query = survey.where(keyword)
else
where("dining_name LIKE ?", "%#{filter}%")
end
end
end

View File

@@ -1,5 +1,5 @@
class TaxProfile < ApplicationRecord
default_scope { order('order_by asc') }
# validations
validates_presence_of :name, :rate
validates_presence_of :name, :rate, :group_type
end