fixed conflic when pull master item remark

This commit is contained in:
Aung Myo
2018-02-26 17:02:46 +06:30
13 changed files with 147 additions and 83 deletions

View File

@@ -97,7 +97,6 @@ class Sale < ApplicationRecord
else
self.shift_sale_id = current_shift.id
end
else
self.cashier_id = current_shift.employee_id
self.cashier_name = Employee.find(current_shift.employee_id).name
@@ -232,7 +231,7 @@ class Sale < ApplicationRecord
sale_item.product_name = item.item_name
sale_item.product_alt_name = item.alt_name
sale_item.account_id = item.account_id
sale_item.remark = item.remark
sale_item.status = item.remark
sale_item.qty = item.qty
sale_item.unit_price = item.price
@@ -260,7 +259,7 @@ class Sale < ApplicationRecord
sale_item.product_name = instance.item_instance_name
sale_item.product_alt_name = menu_item.alt_name
sale_item.account_id = menu_item.account_id
sale_item.remark = nil
sale_item.status = nil
sale_item.qty = item["quantity"]
sale_item.unit_price = item["price"]
@@ -386,7 +385,7 @@ class Sale < ApplicationRecord
rounding_adjustment = 0
sales_items.each do |item|
if item.remark != 'void' && item.remark != 'foc'
if item.status != 'void' && item.status != 'foc'
#compute each item and added to total
subtotal_price = subtotal_price + item.price
@@ -422,35 +421,36 @@ class Sale < ApplicationRecord
tax_profiles = TaxProfile.all.order("order_by asc")
customer = Customer.find(sale.customer_id)
# #Creat new tax records
tax_profiles.each do |tax|
customer.tax_profiles.each do |cus_tax|
if cus_tax.to_i == tax.id
sale_tax = SaleTax.new(:sale => sale)
sale_tax.tax_name = tax.name
sale_tax.tax_rate = tax.rate
if sale.payment_status != 'foc'
tax_profiles.each do |tax|
customer.tax_profiles.each do |cus_tax|
if cus_tax.to_i == tax.id
sale_tax = SaleTax.new(:sale => sale)
sale_tax.tax_name = tax.name
sale_tax.tax_rate = tax.rate
# substract , to give after discount
total_tax = total_taxable - total_discount
#include or execulive
if tax.inclusive
rate = tax.rate
divided_value = (100 + rate)/rate
sale_tax.tax_payable_amount = total_tax / divided_value
else
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
end
#new taxable amount is standard rule for step by step
if shop.calc_tax_order
total_taxable = total_taxable + sale_tax.tax_payable_amount
end
# substract , to give after discount
total_tax = total_taxable - total_discount
#include or execulive
if tax.inclusive
rate = tax.rate
divided_value = (100 + rate)/rate
sale_tax.tax_payable_amount = total_tax / divided_value
else
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
end
#new taxable amount is standard rule for step by step
if shop.calc_tax_order
total_taxable = total_taxable + sale_tax.tax_payable_amount
end
sale_tax.inclusive = tax.inclusive
sale_tax.save
sale_tax.inclusive = tax.inclusive
sale_tax.save
end
end
end
end
sale.total_tax = total_tax_amount
end
@@ -762,7 +762,7 @@ end
def self.get_item_query()
query = Sale.select("acc.title as account_name,mi.account_id, i.item_instance_code as item_code,i.account_id as account_id, " +
"SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item,i.qty as qty," +
"i.remark as status_type,"+
"i.status as status_type,"+
" i.unit_price,i.price as price,i.product_name as product_name, mc.name as" +
" menu_category_name,mc.id as menu_category_id ")
@@ -781,7 +781,7 @@ end
def self.get_other_charges()
query = Sale.select("i.account_id as account_id, " +
"SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," +
"i.remark as status_type,"+
"i.status as status_type,"+
" i.unit_price as unit_price,i.product_name as product_name")
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id")
query = query.where("i.item_instance_code IS NULL AND i.product_code = 'Other Charges'")
@@ -1232,7 +1232,7 @@ end
def self.total_foc_items(today)
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
.where("sales.sale_status = 'completed' and a.status='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
.sum("a.qty")
end

View File

@@ -28,7 +28,7 @@ class SaleItem < ApplicationRecord
def self.update_existing_item(qty, item, sale_id, type, item_price, price)
# Original Item to add remark
item.remark = type
item.status = type
item.save
sale_item = SaleItem.new
@@ -37,7 +37,7 @@ class SaleItem < ApplicationRecord
sale_item.product_name = item.product_name + " (#{type.upcase})"
sale_item.product_alt_name = item.product_alt_name
sale_item.account_id = item.account_id
sale_item.remark = type
sale_item.status = type
if type == "foc" || type == "promotion" || type == "void"
sale_item.qty = qty * (-1)
else
@@ -99,7 +99,7 @@ class SaleItem < ApplicationRecord
discount_account = {:name => a.title, :price => 0}
# Check for actual sale items
sale_items.where("remark = 'Discount'").find_each do |si|
sale_items.where("status = 'Discount'").find_each do |si|
if si.account_id == a.id
discount_account[:price] = (discount_account[:price].abs + si.price.abs) * (1)
end

View File

@@ -194,7 +194,7 @@ class SalePayment < ApplicationRecord
payment_status = false
# add to sale item with foc
sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }' and remark is null")
sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }' and status is null")
sale_items.each do|item|
SaleItem.update_existing_item(item.qty, item, self.sale.sale_id, "foc", item.unit_price, item.price)