payment api

This commit is contained in:
Min Zeya Phyo
2017-04-18 11:01:10 +06:30
parent 6a84a34a9f
commit dbad900cd4
30 changed files with 751 additions and 32 deletions

View File

@@ -9,6 +9,8 @@ class Sale < ApplicationRecord
has_many :sale_payments
has_many :sale_orders
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)
booking = Booking.find(booking_id)
status = false
@@ -48,6 +50,7 @@ class Sale < ApplicationRecord
self.requested_by = requested_by
self.requested_at = DateTime.now.utc
self.customer_id = order.customer_id
order = Order.find(order_no)
Rails.logger.debug "Order -> #{order.id} | order_status -> #{order.status}"
@@ -90,7 +93,7 @@ class Sale < ApplicationRecord
#this will result in multiple orders belonging in multiple invoices - because of spilt invoices.
link_order_sale(item.order_id, taxable)
end
#Update item status as billed
order.update_items_status_to_billed(items)
@@ -134,10 +137,6 @@ class Sale < ApplicationRecord
#save action to sale_audit
end
def accept_payment (payment_method, amount, payment_ref, payment_external_result)
end
def void_sales (void_by, reason, approval_code, request_by)
#save sale_audit
self.sale_status = "void"
@@ -161,7 +160,9 @@ class Sale < ApplicationRecord
apply_tax (total_taxable)
self.total_amount = subtotal_price
self.total_discount = total_discount
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
#compute rounding adjustment
adjust_rounding
self.save!
@@ -218,11 +219,16 @@ class Sale < ApplicationRecord
#puts Time.now.format(":short")
end
def adjust_rounding
self.grand_total
self.rounding_adjustment = 0.00
end
#Generate new Receipt No when it is not assigned
def generate_receipt_no
#Date-Shift-
if self.receipt_no.nil?
prefix = DateTime.now()
prefix = DateTime.now().utc
#self.receipt_no = prefix.to_s + "/" + self.shit_id.to_s + "/" + SeedGenerator.new_receipt_no().to_s
self.receipt_no = prefix.strftime("%Y%m%d") + "/" + SeedGenerator.new_receipt_no().to_s