fixed conflict

This commit is contained in:
Nweni
2019-11-18 13:14:01 +06:30
29 changed files with 1699 additions and 1183 deletions

View File

@@ -23,7 +23,20 @@ class InventoryDefinition < ApplicationRecord
end
end
def self.find_product_in_inventory(item)
def self.find_product_in_inventory(item,instance_code)
# unless instance_code.empty?
# instance_code = instance_code.to_s
# instance_code[0] = ""
# instance_code = instance_code.chomp("]")
# else
# instance_code = '"0"'
# end
#
# if prod = InventoryDefinition.where("item_code IN(#{instance_code})")
# puts "found prodcut+++++++++++++++++++++++++++++++++++==="
# puts prod.to_json
# end
if product = InventoryDefinition.find_by_item_code(item.item_instance_code)
if stock_check_item = StockCheckItem.find_by_item_code(item.item_instance_code)
return true, product

View File

@@ -1,7 +1,7 @@
class MenuCategory < ApplicationRecord
class MenuCategory < ApplicationRecord
# before_create :generate_menu_category_code
belongs_to :menu
belongs_to :menu
has_many :children, :class_name => "MenuCategory", foreign_key: "menu_category_id"
belongs_to :parent, :class_name => "MenuCategory", foreign_key: "menu_category_id", optional: true
has_many :menu_items
@@ -38,9 +38,7 @@ class MenuCategory < ApplicationRecord
end
def valid_time
menu_category = MenuCategory.find(self.id)
menu = Menu.find(menu_category.menu_id)
menu = self.menu
from_t = Time.parse(menu.valid_time_from.strftime("%H:%M:%S"))
to_t = Time.parse(menu.valid_time_to.strftime("%H:%M:%S"))
@@ -64,7 +62,7 @@ class MenuCategory < ApplicationRecord
c +=24
current = c*3600 + current_t.min* 60 + current_t.sec
end
end
else # (after) noon
@@ -77,8 +75,8 @@ class MenuCategory < ApplicationRecord
day = Date.today.wday
dayresult = menu.valid_days.include?(day.to_s)
if current.between?(from, to) && menu.valid_days.include?(day.to_s)
return true
else
@@ -104,12 +102,12 @@ class MenuCategory < ApplicationRecord
private
# def generate_menu_category_code
# self.code = SeedGenerator.generate_code(self.class.name, "C")
# def generate_menu_category_code
# self.code = SeedGenerator.generate_code(self.class.name, "C")
# end
def self.to_csv
mc_attributes = %w{id menu_id code name alt_name order_by created_by menu_category_id is_available created_at updated_at}
CSV.generate(headers: true) do |csv|
csv << mc_attributes
@@ -123,7 +121,3 @@ class MenuCategory < ApplicationRecord
end
end

View File

@@ -11,11 +11,11 @@ class MenuItem < ApplicationRecord
belongs_to :account
has_many :menu_item_sets
has_many :item_sets, through: :menu_item_sets
has_and_belongs_to_many :item_sets, join_table: "menu_item_sets"
validates_presence_of :item_code, :name, :type, :min_qty,:account_id
validates_uniqueness_of :item_code
default_scope { order('item_code asc') }
scope :simple_menu_item, -> { where(type: 'SimpleMenuItem') }

View File

@@ -125,8 +125,18 @@ class OrderItem < ApplicationRecord
end
def update_stock_journal
if self.set_menu_items.present?
puts "set menu itemsssssssss???????????????????????????????"
puts items = JSON.parse(self.set_menu_items)
instance_code = Array.new
count = 0
items.each { |i|
instance_code.push(i["item_instance_code"])
}
print instance_code
end
if self.qty != self.qty_before_last_save
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self)
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self,instance_code)
if found
InventoryDefinition.check_balance(self, inventory_definition)
end

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,8 @@ class SaleAudit < ApplicationRecord
belongs_to :sale
belongs_to :credit_payment, -> { where "SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id" }, foreign_key: "sale_id", primary_key: "sale_id", class_name: "SalePayment"
def self.sync_sale_audit_records(sale_audits)
if !sale_audits.nil?
sale_audits.each do |sa|
@@ -163,7 +165,7 @@ class SaleAudit < ApplicationRecord
end
end
end
return card_balance_amount
end

View File

@@ -225,6 +225,59 @@ class SaleItem < ApplicationRecord
return sale_items
end
# Loader Service SFTP Start
# Detail Sale Data
def self.get_detail_sale_data(transaction_date)
query = SaleItem.select("
sale_items.sale_item_id as id,
sale_items.sale_id as parent_id,
s.receipt_no as check_num,
s.receipt_date as business_date,
s.receipt_date as transaction_date,
'' as item_seq,
sale_items.menu_category_code as category_code,
sale_items.menu_category_name as category_name,
'' as sub_category_code,
'' as sub_category_name,
'' as report_group_code,
'' as report_group_name,
sale_items.product_code as item_id,
sale_items.product_name as item_name,
sale_items.qty as qty,
CASE
WHEN s.sale_status = 'completed' OR s.sale_status = 'void' THEN 'Sales'
WHEN s.sale_status = 'waste' THEN 'Waste'
WHEN s.sale_status = 'spoile' THEN 'Spoil'
END as transaction_type,
sale_items.price as gross_sales,
'' as discount_code,
CASE
WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0
END as discount_amt,
(sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END)) as sales,
((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END))/21) as tax_amt,
'' as service_charges,
((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END)) - ((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END))/21)) as net_sales,
'0' as is_set_item,
'0' as is_staff_meal,
'0' as is_raw_wastage,
'0' as is_semi_wastage,
CASE WHEN s.sale_status = 'waste' THEN 1 ELSE 0 END as is_wastage,
CASE WHEN s.sale_status = 'spoile' THEN 1 ELSE 0 END as is_spoilage,
'0' as is_sampling,
'1' as tax_able,
CASE
WHEN s.sale_status = 'void' THEN 1 ELSE 0
END as is_void
")
.joins("LEFT JOIN sales s ON s.sale_id = sale_items.sale_id")
.joins("LEFT JOIN sale_items i ON sale_items.sale_id = i.sale_id AND sale_items.item_instance_code = i.item_instance_code AND i.status = 'Discount' AND sale_items.qty = abs(i.qty)")
.where("DATE(s.receipt_date) = ? AND s.sale_status != 'void' AND (sale_items.status NOT IN('Discount', 'void','foc') OR sale_items.status IS NULL)", transaction_date)
.order("s.receipt_no")
end
# Loader Service SFTP End
private
def generate_custom_id
if self.sale_item_id.nil?
@@ -293,58 +346,4 @@ class SaleItem < ApplicationRecord
end
end
end
# Loader Service SFTP Start
# Detail Sale Data
def self.get_detail_sale_data(transaction_date)
query = SaleItem.select("
sale_items.sale_item_id as id,
sale_items.sale_id as parent_id,
s.receipt_no as check_num,
s.receipt_date as business_date,
s.receipt_date as transaction_date,
'' as item_seq,
sale_items.menu_category_code as category_code,
sale_items.menu_category_name as category_name,
'' as sub_category_code,
'' as sub_category_name,
'' as report_group_code,
'' as report_group_name,
sale_items.product_code as item_id,
sale_items.product_name as item_name,
sale_items.qty as qty,
CASE
WHEN s.sale_status = 'completed' OR s.sale_status = 'void' THEN 'Sales'
WHEN s.sale_status = 'waste' THEN 'Waste'
WHEN s.sale_status = 'spoile' THEN 'Spoil'
END as transaction_type,
sale_items.price as gross_sales,
'' as discount_code,
CASE
WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0
END as discount_amt,
(sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END)) as sales,
((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END))/21) as tax_amt,
'' as service_charges,
((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END)) - ((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END))/21)) as net_sales,
'0' as is_set_item,
'0' as is_staff_meal,
'0' as is_raw_wastage,
'0' as is_semi_wastage,
CASE WHEN s.sale_status = 'waste' THEN 1 ELSE 0 END as is_wastage,
CASE WHEN s.sale_status = 'spoile' THEN 1 ELSE 0 END as is_spoilage,
'0' as is_sampling,
'1' as tax_able,
CASE
WHEN s.sale_status = 'void' THEN 1 ELSE 0
END as is_void
")
.joins("LEFT JOIN sales s ON s.sale_id = sale_items.sale_id")
.joins("LEFT JOIN sale_items i ON sale_items.sale_id = i.sale_id AND sale_items.item_instance_code = i.item_instance_code AND i.status = 'Discount' AND sale_items.qty = abs(i.qty)")
.where("DATE(s.receipt_date) = ? AND s.sale_status != 'void' AND (sale_items.status NOT IN('Discount', 'void','foc') OR sale_items.status IS NULL)", transaction_date)
.order("s.receipt_no")
end
# Loader Service SFTP End
end

View File

@@ -6,8 +6,13 @@ class SalePayment < ApplicationRecord
belongs_to :sale
has_one :sale_audit, -> { where "SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id" }, foreign_key: "sale_id", primary_key: "sale_id"
attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status,:action_by
scope :credits, -> { where(payment_method: 'creditnote') }
scope :cards, -> { where(payment_method: ['mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher']) }
def self.sync_sale_payment_records(sale_payments)
if !sale_payments.nil?
sale_payments.each do |sp|

View File

@@ -15,6 +15,7 @@
class ShiftSale < ApplicationRecord
belongs_to :cashier_terminal
belongs_to :employee, :foreign_key => 'employee_id'
has_many :sales
def self.current_shift
# today_date = DateTime.now.strftime("%Y-%m-%d")
@@ -25,7 +26,7 @@ class ShiftSale < ApplicationRecord
def self.current_open_shift(current_user)
#if current_user
#find open shift where is open today and is not closed and login by current cashier
#DATE(shift_started_at)=? and
#DATE(shift_started_at)=? and
today_date = DateTime.now.strftime("%Y-%m-%d")
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}").take
return shift
@@ -43,7 +44,7 @@ class ShiftSale < ApplicationRecord
# status = 'updated'
if shift_sale.nil?
shift_sale = ShiftSale.new
# status = 'created'
# status = 'created'
end
shift_sale.id = ss['id']
@@ -118,7 +119,7 @@ class ShiftSale < ApplicationRecord
credit = saleobj.get_credit_amount
other_sales = saleobj.get_other_amount
tax = saleobj.get_commerical_tax
if type == "void"
self.total_revenue = self.total_revenue.to_f - saleobj.total_amount.to_f
self.total_discounts = self.total_discounts - saleobj.total_discount
@@ -137,7 +138,7 @@ class ShiftSale < ApplicationRecord
self.takeaway_count = self.takeaway_count - 1
end
self.save
end
end
@@ -149,11 +150,11 @@ class ShiftSale < ApplicationRecord
end
def self.get_by_shift_other_payment(shift)
other_payment = Sale.select("sale_payments.payment_method as name,
SUM(case when (sale_payments.payment_method='mpu') then (sale_payments.payment_amount) else 0 end) as mpu_amount,
SUM(case when (sale_payments.payment_method='visa') then (sale_payments.payment_amount) else 0 end) as visa_amount,
SUM(case when (sale_payments.payment_method='master') then (sale_payments.payment_amount) else 0 end) as master_amount,
SUM(case when (sale_payments.payment_method='mpu') then (sale_payments.payment_amount) else 0 end) as mpu_amount,
SUM(case when (sale_payments.payment_method='visa') then (sale_payments.payment_amount) else 0 end) as visa_amount,
SUM(case when (sale_payments.payment_method='master') then (sale_payments.payment_amount) else 0 end) as master_amount,
SUM(case when (sale_payments.payment_method='jcb') then (sale_payments.payment_amount) else 0 end) as jcb_amount,
SUM(case when (sale_payments.payment_method='unionpay') then (sale_payments.payment_amount) else 0 end) as unionpay_amount,
SUM(case when (sale_payments.payment_method='alipay') then (sale_payments.payment_amount) else 0 end) as alipay_amount,
@@ -161,19 +162,19 @@ class ShiftSale < ApplicationRecord
SUM(case when (sale_payments.payment_method='dinga') then (sale_payments.payment_amount) else 0 end) as dinga_amount,
SUM(case when (sale_payments.payment_method='giftvoucher') then (sale_payments.payment_amount) else 0 end) as giftvoucher_amount,
SUM(case when (sale_payments.payment_method='JunctionPay') then (sale_payments.payment_amount) else 0 end) as junctionpay_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount,
SUM(case when (sale_payments.payment_method='paymal') then (sale_payments.payment_amount) else 0 end) as paymal_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount,
SUM(case when (sale_payments.payment_method='paymal') then (sale_payments.payment_amount) else 0 end) as paymal_amount,
SUM(case when (sale_payments.payment_method='paypar') then (sale_payments.payment_amount) else 0 end) as paypar_amount")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.shift_sale_id =? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.id)
end
def self.calculate_total_price_by_accounts(shift,type)
query = Sale.select("acc.title as account_name," +
query = Sale.select("acc.title as account_name," +
"SUM(case when (acc.id=i.account_id) then (i.price) else 0 end) as total_price")
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id "+
"JOIN accounts acc ON acc.id = i.account_id" +
"JOIN accounts acc ON acc.id = i.account_id" +
" JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id")
if type == 'discount'
query = query.where("sales.shift_sale_id =? and sale_status = 'completed' and i.remark = 'Discount'", shift.id)
@@ -187,17 +188,17 @@ class ShiftSale < ApplicationRecord
def self.get_total_member_discount(shift)
query = Sale.select("SUM(sales.total_discount) as member_discount")
.where("shift_sale_id =? and sale_status = 'completed' and discount_type = 'member_discount'", shift.id)
end
def self.get_total_dinein(shift)
end
def self.get_total_dinein(shift)
query = Sale.select("sum(sales.grand_total) as total_dinein_amount")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('shift_sale_id =? and sales.sale_status = "completed" and c.customer_type = "Dinein" and c.membership_id is null',shift.id)
.first()
end
end
def self.get_total_takeway(shift)
def self.get_total_takeway(shift)
query = Sale.select("sum(sales.grand_total) as total_takeway_amount")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('shift_sale_id =? and sales.sale_status = "completed" and c.customer_type = "Takeaway" and c.membership_id is null',shift.id)
@@ -211,12 +212,12 @@ class ShiftSale < ApplicationRecord
# .where('s.sale_status = "completed" and sale_items.product_code = "Other Charges" and sale_items.item_instance_code is null and s.receipt_date between ? and ?',from, to)
# end
def self.get_total_other_charges(shift)
def self.get_total_other_charges(shift)
query = SaleItem.select("sum(sale_items.qty * sale_items.unit_price) as total_other_charges_amount")
.joins("JOIN sales as s ON s.sale_id = sale_items.sale_id")
.where('shift_sale_id =? and s.sale_status = "completed" and sale_items.product_code = "Other Charges" and sale_items.item_instance_code is null',shift.id)
.first()
end
end
def self.search(filter,from,to)
if filter.blank?