fixed conflict

This commit is contained in:
Aung Myo
2017-06-11 18:09:00 +06:30
42 changed files with 610 additions and 431 deletions

View File

@@ -15,9 +15,10 @@ class Customer < ApplicationRecord
def self.get_member_group
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("get_all_member_group")
app_token = membership.auth_token.to_s
url = membership.gateway_url.to_s + "/api/get_all_member_group".to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
response = HTTParty.get(url,
:body => { app_token: app_token}.to_json,
:headers => {

View File

@@ -0,0 +1,2 @@
class MembershipAction < ApplicationRecord
end

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
@@ -17,7 +16,6 @@ class Sale < ApplicationRecord
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)
puts "get invoice from booking"
booking = Booking.find(booking_id)
status = false
Rails.logger.debug "Booking -> " + booking.id.to_s
@@ -33,7 +31,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 +228,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 +259,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,22 @@ 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
self.class.name
saleOrderId = SeedGenerator.generate_id(self.class.name, "SOI")
self.sale_order_id = saleOrderId
end
end

View File

@@ -78,11 +78,11 @@ class SalePayment < ApplicationRecord
end
def self.redeem(paypar_url,token,membership_id,received_amount,sale_id,campaign_type_id)
membership_actions_data = Settings::MembershipAction.find_by_membership_type("redeem_url");
def self.redeem(paypar_url,token,membership_id,received_amount,sale_id)
membership_actions_data = MembershipAction.find_by_membership_type("redeem");
if !membership_actions_data.nil?
url = paypar_url.to_s + membership_actions_data.gateway_url.to_s
campaign_type_id = 1
campaign_type_id = membership_actions_data.additional_parameter["campaign_type_id"]
response = HTTParty.post(url,
:body => { generic_customer_id:membership_id,total_amount:received_amount,receipet_no:sale_id,campaign_type_id:campaign_type_id,account_no:""}.to_json,
:headers => {
@@ -93,7 +93,7 @@ class SalePayment < ApplicationRecord
else
response =false;
end
puts response.to_json
return response;
end
@@ -106,7 +106,6 @@ class SalePayment < ApplicationRecord
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)
return payment_status
@@ -134,7 +133,7 @@ class SalePayment < ApplicationRecord
self.payment_method = method
self.payment_amount = self.received_amount
self.payment_reference = self.card_payment_reference
self.outstanding_amount = self.sale.grand_total- 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!
@@ -188,10 +187,9 @@ class SalePayment < ApplicationRecord
self.payment_status = "pending"
payment_method = self.save!
campaign_type_id =1;
customer_data = Customer.find_by_customer_id(self.sale.customer_id)
membership_setting = MembershipSetting.find_by_membership_type("paypar_url")
membership_data = SalePayment.redeem(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id,campaign_type_id)
membership_data = SalePayment.redeem(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id)
if membership_data["status"]==true
SalePayment.where(:sale_payment_id => self.sale_payment_id).update_all(:payment_status => 'paid')
sale_update_payment_status(self.received_amount.to_f)
@@ -207,15 +205,26 @@ 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.to_f - self.sale.amount_received
if (self.sale.grand_total <= self.sale.amount_received.to_f && self.sale.amount_changed.to_f > 0)
self.sale.amount_changed = paid_amount.to_f - self.sale.amount_received.to_f
all_received_amount = 0.0
sObj = Sale.find(self.sale_id)
sObj.sale_payments.each do |spay|
all_received_amount += spay.payment_amount.to_f
end
if (self.sale.grand_total <= all_received_amount)
self.sale.payment_status = "paid"
self.sale.sale_status = "completed"
self.sale.save!
rebat()
end
end
def rebat
end
private
def generate_custom_id
self.sale_payment_id = SeedGenerator.generate_id(self.class.name, "SPI")

View File

@@ -1,7 +1,9 @@
class SeedGenerator < ApplicationRecord
def self.generate_id(model, prefix)
seed = SeedGenerator.find_by_model(model)
new_receipt_no = 0
if (seed.nil?)
seed = SeedGenerator.new()
seed.model = model
@@ -16,8 +18,8 @@ class SeedGenerator < ApplicationRecord
end
padding_len = 15 - prefix.length
return prefix +"-"+ seed.current.to_s.to_s.rjust((14-prefix.length)+1,'0')
saleOrderId = prefix +"-"+ seed.current.to_s.to_s.rjust((14-prefix.length)+1,'0')
return saleOrderId
end

View File

@@ -1,2 +0,0 @@
class Settings::MembershipAction < ApplicationRecord
end