Merge branch 'master' of bitbucket.org:code2lab/sxrestaurant into adminbsb_ui_changes
This commit is contained in:
@@ -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
|
||||
@@ -34,7 +36,7 @@ class Menu < ApplicationRecord
|
||||
|
||||
def self.to_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) do |csv|
|
||||
CSV.generate(headers: true, row_sep: "\r\n") do |csv|
|
||||
csv << m_attributes
|
||||
menu = Menu.all
|
||||
menu.each do |user|
|
||||
@@ -44,9 +46,39 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.import(file)
|
||||
CSV.foreach(file.path, headers:true) do |row|
|
||||
Menu.create! row.to_hash
|
||||
end
|
||||
spreadsheet = Roo::Spreadsheet.open(file.path)
|
||||
|
||||
spreadsheet = Roo::Excelx.new(file.path)
|
||||
|
||||
# Use the extension option if the extension is ambiguous.
|
||||
spreadsheet = Roo::Spreadsheet.open(file.path, extension: :xlsx)
|
||||
|
||||
puts spreadsheet.info
|
||||
|
||||
header = spreadsheet.row(1)
|
||||
|
||||
(2..spreadsheet.last_row).each do |i|
|
||||
|
||||
row = Hash[[header,spreadsheet.row(i)].transpose]
|
||||
|
||||
menu = Menu.new
|
||||
menu.name = row["name"]
|
||||
menu.is_active = row["is_active"]
|
||||
menu.valid_days = row["valid_days"]
|
||||
menu.valid_time_from = row["valid_time_from"]
|
||||
menu.valid_time_to = row["valid_time_to"]
|
||||
menu.created_by = row["created_by"]
|
||||
menu.save
|
||||
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
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -297,6 +300,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
|
||||
|
||||
Reference in New Issue
Block a user