added sale order
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user