merged crm

This commit is contained in:
Yan
2017-06-06 09:41:06 +06:30
22 changed files with 371 additions and 129 deletions

View File

@@ -25,9 +25,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
@@ -36,7 +36,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
@@ -67,8 +67,8 @@ class Sale < ApplicationRecord
add_item(item)
end
link_order_sale(order.id)
link_order_sale(order.id)
end
@@ -78,6 +78,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