Sale Save

This commit is contained in:
Cherry
2017-06-04 16:02:55 +06:30
parent 7146a1028a
commit e3f9d62bce
8 changed files with 241 additions and 89 deletions

View File

@@ -20,9 +20,9 @@ class Sale < ApplicationRecord
#get all order attached to this booking and combine into 1 invoice
booking.booking_orders.each do |order|
if booking.sale_id
status, sale_id = generate_invoice_from_order(order.order_id, nil, requested_by)
status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by)
else
status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, requested_by)
status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, booking, requested_by)
end
booking.sale_id = sale_id
end
@@ -31,7 +31,7 @@ class Sale < ApplicationRecord
end
end
def generate_invoice_from_order (order_id, sale_id, requested_by)
def generate_invoice_from_order (order_id, sale_id, booking, requested_by)
taxable = true
#if sale_id is exsit and validate
#add order to that invoice
@@ -62,8 +62,8 @@ class Sale < ApplicationRecord
add_item(item)
end
link_order_sale(order.id)
link_order_sale(order.id)
end
@@ -73,6 +73,11 @@ class Sale < ApplicationRecord
#Update the order items that is billed
order.update_items_status_to_billed(nil)
order.status = "billed"
order.save
booking.sale_id = self.id
booking.save
return true, self.id
end