fixed conflict
This commit is contained in:
@@ -3,5 +3,7 @@ class Account < ApplicationRecord
|
||||
|
||||
has_many :menu_items
|
||||
# belongs_to :lookup , :class_name => "Lookup"
|
||||
|
||||
def self.collection
|
||||
Account.select("id, title").map { |e| [e.title, e.id] }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
class MenuItem < ApplicationRecord
|
||||
|
||||
#belongs_to :account
|
||||
belongs_to :menu_category, :optional => true
|
||||
has_many :menu_item_instances
|
||||
belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id", :optional => true
|
||||
has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id"
|
||||
belongs_to :account
|
||||
|
||||
validates_presence_of :item_code, :name, :type, :min_qty, :taxable, :min_selectable_item, :max_selectable_item
|
||||
|
||||
|
||||
@@ -218,10 +218,9 @@ class Order < ApplicationRecord
|
||||
left join dining_facilities on dining_facilities.id = bookings.dining_facility_id
|
||||
left join order_items on order_items.order_id = orders.order_id")
|
||||
.where("dining_facilities.type=? and orders.order_type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,"dine_in",true)
|
||||
.group("orders.order_id, order_items.id,dining_facilities.name")
|
||||
|
||||
.group("orders.order_id, order_items.order_items_id,dining_facilities.name")
|
||||
end
|
||||
|
||||
|
||||
def self.get_booking_order_table
|
||||
booking_orders = Booking.select("sales.receipt_no,orders.status as order_status,
|
||||
bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name")
|
||||
@@ -231,9 +230,10 @@ class Order < ApplicationRecord
|
||||
.joins("left join sale_orders on sale_orders.order_id = orders.order_id")
|
||||
.joins("left join sales on sales.sale_id = sale_orders.sale_id")
|
||||
.where("booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,true)
|
||||
.group("bookings.booking_id")
|
||||
.group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status")
|
||||
|
||||
end
|
||||
|
||||
#Origami: Cashier : to view order type Room
|
||||
def self.get_booking_order_rooms
|
||||
booking_rooms = Booking.select("sales.receipt_no,orders.status as order_status,bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as room_name")
|
||||
@@ -243,8 +243,9 @@ class Order < ApplicationRecord
|
||||
.joins("left join sale_orders on sale_orders.order_id = orders.order_id")
|
||||
.joins("left join sales on sales.sale_id = sale_orders.sale_id")
|
||||
.where("booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,true)
|
||||
.group("bookings.booking_id")
|
||||
.group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name")
|
||||
end
|
||||
|
||||
#Origami: Cashier : to view order type Room
|
||||
def self.get_order_rooms
|
||||
order_rooms = Order.select("orders.order_id as order_id,sum(order_items.qty*order_items.price) as total_price,
|
||||
@@ -254,9 +255,10 @@ class Order < ApplicationRecord
|
||||
left join dining_facilities on dining_facilities.id = bookings.dining_facility_id
|
||||
left join order_items on order_items.order_id = orders.order_id")
|
||||
.where("dining_facilities.type=? and orders.order_type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,"dine_in",true)
|
||||
.group("orders.order_id,order_items.id,dining_facilities.name")
|
||||
.group("orders.order_id,order_items.order_items_id,dining_facilities.name,sales.receipt_no")
|
||||
|
||||
end
|
||||
|
||||
#Origami: Cashier : to view orders
|
||||
def self.get_orders
|
||||
from = Time.now.beginning_of_day.utc
|
||||
@@ -265,18 +267,17 @@ class Order < ApplicationRecord
|
||||
.joins("left join booking_orders on booking_orders.order_id = orders.order_id
|
||||
left join bookings on bookings.booking_id = booking_orders.order_id
|
||||
left join dining_facilities on dining_facilities.id = bookings.dining_facility_id
|
||||
|
||||
left join order_items on order_items.order_id = orders.order_id
|
||||
left join sale_orders on sale_orders.order_id = orders.order_id
|
||||
left join sales on sales.sale_id = sale_orders.sale_id")
|
||||
.where("dining_facilities.is_active=? and orders.date between ? and ?",true,from,to)
|
||||
.group("orders.order_id,order_items.order_items_id,dining_facilities.name")
|
||||
|
||||
.group("orders.order_id,order_items.order_items_id,dining_facilities.name,sales.receipt_no,bookings.booking_id,sales.sale_id")
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
private
|
||||
|
||||
def generate_custom_id
|
||||
self.order_id = SeedGenerator.generate_id(self.class.name, "ODR")
|
||||
end
|
||||
|
||||
@@ -29,18 +29,18 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
.joins("left join orders ON orders.order_id = order_items.order_id
|
||||
left join booking_orders AS bo ON bo.order_id=order_items.order_id
|
||||
left join bookings AS b ON b.booking_id = bo.booking_id
|
||||
left join dining_facilities AS df ON df.dining_facility_id = b.dining_facility_id
|
||||
left join dining_facilities AS df ON df.id = b.dining_facility_id
|
||||
left join customers as cus ON cus.customer_id = orders.customer_id")
|
||||
.where("order_items.item_code=" + code)
|
||||
.where("order_items.item_code='" + code + "'")
|
||||
.group("order_items.item_code")
|
||||
else
|
||||
OrderItem.select("order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining")
|
||||
.joins("left join orders ON orders.order_id = order_items.order_id
|
||||
left join booking_orders AS bo ON bo.order_id=order_items.order_id
|
||||
left join bookings AS b ON b.booking_id = bo.booking_id
|
||||
left join dining_facilities AS df ON df.dining_facility_id = b.dining_facility_id
|
||||
left join dining_facilities AS df ON df.id = b.dining_facility_id
|
||||
left join customers as cus ON cus.customer_id = orders.customer_id")
|
||||
.where("orders.order_id=" + code.to_s)
|
||||
.where("orders.order_id='" + code.to_s + "'")
|
||||
.group("order_items.item_code")
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Sale < ApplicationRecord
|
||||
self.primary_key = "sale_id"
|
||||
|
||||
|
||||
#primary key - need to be unique generated for multiple shops
|
||||
before_create :generate_custom_id
|
||||
|
||||
@@ -17,6 +17,7 @@ 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}'") }
|
||||
|
||||
def generate_invoice_from_booking(booking_id, requested_by)
|
||||
puts "get invoice from booking"
|
||||
booking = Booking.find(booking_id)
|
||||
status = false
|
||||
Rails.logger.debug "Booking -> " + booking.id.to_s
|
||||
@@ -32,6 +33,7 @@ class Sale < ApplicationRecord
|
||||
booking.sale_id = sale_id
|
||||
end
|
||||
order = booking.booking_orders.take.order
|
||||
puts "add sale order"
|
||||
link_order_sale(order.id)
|
||||
return status
|
||||
end
|
||||
@@ -68,8 +70,8 @@ class Sale < ApplicationRecord
|
||||
add_item(item)
|
||||
end
|
||||
|
||||
link_order_sale(order.id)
|
||||
|
||||
link_order_sale(order.id)
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -226,9 +228,14 @@ class Sale < ApplicationRecord
|
||||
|
||||
def link_order_sale(order_id)
|
||||
#create if it doesn't exist
|
||||
if (SaleOrder.where("sale_id = #{self.id} and order_id=#{order_id}").nil?)
|
||||
saleOrder = SaleOrder.where("sale_id=? and order_id=?", self.id, order_id).take
|
||||
|
||||
if saleOrder.nil?
|
||||
SaleOrder.create(:sale_id => self.id, :order_id => order_id)
|
||||
end
|
||||
# if (SaleOrder.where("sale_id = #{self.id} and order_id=#{order_id}").nil?)
|
||||
# SaleOrder.create(:sale_id => self.id, :order_id => order_id)
|
||||
# end
|
||||
#dosomrting here
|
||||
#puts Time.now.format(":short")
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class SaleAudit < ApplicationRecord
|
||||
self.primary_key = "sale_audit_id"
|
||||
|
||||
|
||||
#primary key - need to be unique generated for SaleAudit
|
||||
before_create :generate_custom_id
|
||||
|
||||
@@ -44,13 +44,14 @@ class SaleAudit < ApplicationRecord
|
||||
sale_audit.save!
|
||||
end
|
||||
|
||||
def record_payment(sale_id, remark, action_by)
|
||||
def self.record_payment(sale_id, remark, action_by)
|
||||
sale_audit = SaleAudit.new()
|
||||
sale_audit.sale_id = sale_id
|
||||
sale_audit.action = "SALEPAYMENT"
|
||||
sale_audit.action_at = DateTime.now.utc
|
||||
sale_audit.action_by = action_by
|
||||
sale_audit.remark = remark
|
||||
sale_audit.approved_by = Time.now
|
||||
sale_audit.save!
|
||||
end
|
||||
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
class SalePayment < ApplicationRecord
|
||||
self.primary_key = "sale_payment_id"
|
||||
|
||||
|
||||
#primary key - need to be unique generated for multiple shops
|
||||
before_create :generate_custom_id
|
||||
|
||||
belongs_to :sale
|
||||
|
||||
:attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status
|
||||
attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status
|
||||
|
||||
def process_payment(invoice, action_by, cash_amount)
|
||||
|
||||
def process_payment(invoice, action_by)
|
||||
self.sale = invoice
|
||||
|
||||
self.received_amount = cash_amount
|
||||
|
||||
payment_method = "cash"
|
||||
amount_due = invoice.grand_total
|
||||
|
||||
#get all payment for this invoices
|
||||
invoice.sale_payments.each do |payment|
|
||||
if (payment.payment_status == "paid" )
|
||||
@@ -22,32 +26,33 @@ class SalePayment < ApplicationRecord
|
||||
if (amount_due > 0)
|
||||
payment_status = false
|
||||
#route to payment type
|
||||
switch (payment_method)
|
||||
case "cash"
|
||||
case payment_method
|
||||
when "cash"
|
||||
payment_status = cash_payment
|
||||
case "creditnote"
|
||||
payment_status = creditnote_payment
|
||||
case "visa"
|
||||
payment_status = external_terminal_card_payment(:visa)
|
||||
case "master"
|
||||
payment_status = external_terminal_card_payment(:master)
|
||||
case "jcb"
|
||||
payment_status = external_terminal_card_payment(:jcb)
|
||||
case "mpu"
|
||||
payment_status = external_terminal_card_payment(:mpu)
|
||||
case "unionpay"
|
||||
payment_status = external_terminal_card_payment(:unionpay)
|
||||
case "vochure"
|
||||
payment_status = vochure_payment
|
||||
case "giftcard"
|
||||
payment_status = giftcard_payment
|
||||
case "paypar"
|
||||
#TODO: implement paypar implementation
|
||||
when "creditnote"
|
||||
if !self.customer_id.nil?
|
||||
payment_status = creditnote_payment(self.customer_id)
|
||||
end
|
||||
when "visa"
|
||||
payment_status = external_terminal_card_payment(:visa)
|
||||
when "master"
|
||||
payment_status = external_terminal_card_payment(:master)
|
||||
when "jcb"
|
||||
payment_status = external_terminal_card_payment(:jcb)
|
||||
when "mpu"
|
||||
payment_status = external_terminal_card_payment(:mpu)
|
||||
when "unionpay"
|
||||
payment_status = external_terminal_card_payment(:unionpay)
|
||||
when "vochure"
|
||||
payment_status = vochure_payment
|
||||
when "giftcard"
|
||||
payment_status = giftcard_payment
|
||||
when "paypar"
|
||||
payment_status = paypar_payment
|
||||
else
|
||||
puts "it was something else"
|
||||
end
|
||||
|
||||
|
||||
|
||||
#record an payment in sale-audit
|
||||
remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{amount} | Payment Status ->#{payment_status}"
|
||||
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by)
|
||||
@@ -66,10 +71,9 @@ class SalePayment < ApplicationRecord
|
||||
private
|
||||
def cash_payment
|
||||
payment_status = false
|
||||
|
||||
self.payment_method = "cash"
|
||||
self.payment_amount = self.received_amount
|
||||
self.outstanding_amount = self.sale.grand_total - received_amount
|
||||
self.outstanding_amount = self.sale.grand_total - self.received_amount
|
||||
self.payment_status = "paid"
|
||||
payment_method = self.save!
|
||||
|
||||
@@ -78,7 +82,8 @@ class SalePayment < ApplicationRecord
|
||||
return payment_status
|
||||
end
|
||||
|
||||
def creditnote_payment(self.customer_id)
|
||||
def creditnote_payment(customer_id)
|
||||
|
||||
payment_status = false
|
||||
|
||||
self.payment_method = "creditnote"
|
||||
@@ -147,11 +152,12 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
|
||||
def sale_update_payment_status(paid_amount)
|
||||
|
||||
puts "paid_amount"
|
||||
puts paid_amount
|
||||
#update amount_outstanding
|
||||
self.sale.amount_received = self.sale.amount_received + paid_amount
|
||||
self.sale.amount_changed = amount - self.sale.amount_received
|
||||
if (self.sale.grand_total <= self.sale.amount_received && self.sale.amount_changed > 0)
|
||||
self.sale.amount_changed = amount - self.sale.amount_received
|
||||
if (self.sale.grand_total <= self.sale.amount_received && self.sale.amount_changed > 0)
|
||||
self.sale.payment_status = "paid"
|
||||
self.sale.sale_status = "completed"
|
||||
self.sale.save!
|
||||
|
||||
Reference in New Issue
Block a user