update sale order talble

This commit is contained in:
Nweni
2017-06-09 13:13:20 +06:30
parent 6171b00dc7
commit 56ffd1f063
9 changed files with 34 additions and 23 deletions

View File

@@ -3,7 +3,6 @@ class Sale < ApplicationRecord
#primary key - need to be unique generated for multiple shops
before_create :generate_custom_id
#before_create :generate_receipt_no
belongs_to :cashier, :optional => true
belongs_to :customer, :optional => true
@@ -33,7 +32,6 @@ 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, sale_id
end
@@ -231,9 +229,10 @@ class Sale < ApplicationRecord
def link_order_sale(order_id)
#create if it doesn't exist
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)
sale_order = SaleOrder.new
sale_order.create_sale_order(self.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)
@@ -261,6 +260,7 @@ class Sale < ApplicationRecord
end
private
def generate_custom_id
self.sale_id = SeedGenerator.generate_id(self.class.name, "SAL")
end

View File

@@ -2,13 +2,25 @@ class SaleOrder < ApplicationRecord
self.primary_key = "sale_order_id"
#primary key - need to be unique generated for multiple shops
before_create :generate_custom_id
before_create :generate_sale_order_id
belongs_to :sale
belongs_to :order
def create_sale_order(sale, order)
self.sale_id = sale
self.order_id = order
self.save
end
private
def generate_custom_id
self.sale_order_id = SeedGenerator.generate_id(self.class.name, "SOI")
def generate_sale_order_id
puts "create slae order id"
self.class.name
saleOrderId = SeedGenerator.generate_id(self.class.name, "SOI")
puts saleOrderId
self.sale_order_id = saleOrderId
puts "create sale order id"
end
end

View File

@@ -207,7 +207,7 @@ class SalePayment < ApplicationRecord
def sale_update_payment_status(paid_amount)
#update amount_outstanding
self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f
self.sale.amount_changed = paid_amount - self.sale.amount_received
self.sale.amount_changed = paid_amount.to_f - self.sale.amount_received.to_f
if (self.sale.grand_total <= self.sale.amount_received.to_f && self.sale.amount_changed.to_f > 0)
self.sale.payment_status = "paid"
self.sale.sale_status = "completed"

View File

@@ -1,14 +1,20 @@
class SeedGenerator < ApplicationRecord
def self.generate_id(model, prefix)
seed = SeedGenerator.find_by_model(model)
puts "found seed"
puts seed
new_receipt_no = 0
if (seed.nil?)
puts "seed is null"
seed = SeedGenerator.new()
seed.model = model
new_receipt_no = seed.next
seed.save
else
puts "seed is not null"
current_no = seed.next
seed.next = seed.next + seed.increase_by
seed.current = current_no
@@ -16,8 +22,10 @@ class SeedGenerator < ApplicationRecord
end
padding_len = 15 - prefix.length
return prefix +"-"+ seed.current.to_s.to_s.rjust((14-prefix.length)+1,'0')
puts prefix +"-"+ seed.current.to_s.to_s.rjust((14-prefix.length)+1,'0')
puts "this is actural sale orde"
saleOrderId = prefix +"-"+ seed.current.to_s.to_s.rjust((14-prefix.length)+1,'0')
return saleOrderId
end

View File

@@ -13,6 +13,7 @@ class CreateOrderItems < ActiveRecord::Migration[5.1]
t.string :options
t.json :set_menu_items #this parameter is require to route the items correctly
t.boolean :taxable, :null => false, :default => true
t.string :completed_by
t.timestamps
end
end

View File

@@ -7,7 +7,7 @@ class CreatePaymentMethodSettings < ActiveRecord::Migration[5.1]
t.string :gateway_url
t.string :auth_token
t.string :merchant_account_id
t.string :additional_parameters
t.timestamps
end
end

View File

@@ -1,8 +1,8 @@
class CreateSaleOrders < ActiveRecord::Migration[5.1]
def change
create_table :sale_orders, :id => false do |t|
t.primary_key :sale_order_id #custom primary key - to ensure consistence for cloud syncing
t.string :sale_order_id, :limit => 16, :primary_key => true
t.string :sale_id, foreign_key: true,:limit => 16
t.string :order_id, foreign_key: true, :limit => 16

View File

@@ -1,5 +0,0 @@
class AddCompanyAddressEmail < ActiveRecord::Migration[5.1]
def change
add_column :order_items, :completed_by, :string
end
end

View File

@@ -1,5 +0,0 @@
class Additionparametertopaymentsettings < ActiveRecord::Migration[5.1]
def change
add_column :payment_method_settings, :additional_parameters, :string
end
end