add sale items in sale item model

This commit is contained in:
Yan
2017-11-21 19:33:20 +06:30
parent f7cad204af
commit 6ce3f8e044
3 changed files with 24 additions and 3 deletions

View File

@@ -11,6 +11,21 @@ class SaleItem < ApplicationRecord
def compute_item
end
# Add Sale Items
def self.add_sale_items(sale_items, )
sale_items.each do|saleitemObj|
saleitemObj.remark = 'foc'
saleitemObj.save
@newsaleitem = SaleItem.new
@newsaleitem = saleitemObj.dup
@newsaleitem.save
@newsaleitem.qty = saleitemObj.qty * -1
@newsaleitem.price = saleitemObj.price * -1
@newsaleitem.is_taxable = 1
@newsaleitem.product_name = saleitemObj.product_name + ' (FOC)'
@newsaleitem.save
end
end
def self.get_order_items_details(sale_id)
order_details = SaleItem.select("sales.total_tax as tax_amount, sales.grand_total as grand_total_amount , sales.total_discount as discount_amount,sales.receipt_date as receipt_date,

View File

@@ -169,12 +169,18 @@ class SalePayment < ApplicationRecord
def foc_payment
payment_status = false
# add to sale item with foc
sale_items = SaleItem.find_by_sale_id(self.sale)
SaleItem.add_sale_items(sale_items)
self.payment_method = "foc"
self.payment_amount = self.received_amount
self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f
self.payment_status = "paid"
payment_method = self.save!
sale_update_payment_status(self.received_amount)
sale_update_payment_status(self.received_amount)
return payment_status
end

View File

@@ -1,4 +1,4 @@
application_path = Rails.root
application_path = Rails.root #'/home/superuser/Application/production/sxrestaurant'
directory application_path
environment ENV.fetch("RAILS_ENV") { "development" }
daemonize true
@@ -6,5 +6,5 @@ pidfile "#{application_path}/tmp/puma/pid"
state_path "#{application_path}/tmp/puma/state"
stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log"
port ENV.fetch("PORT") { 62158 }
bind 'tcp://0.0.0.0:62158'
workers 2
preload_app!