Pull from master

This commit is contained in:
San Wai Lwin
2018-08-20 11:26:07 +06:30
parent 3c2faf5970
commit d1852d24c3
28 changed files with 464 additions and 216 deletions

View File

@@ -2,11 +2,20 @@ class InventoryDefinition < ApplicationRecord
scope :active, -> {where(:is_active => true)}
def self.calculate_product_count(saleObj)
saleObj.sale_items.each do |item|
found, inventory_definition = find_product_in_inventory(item)
if found
check_balance(item,inventory_definition)
def self.calculate_product_count(saleObj=nil,saleobj_after_req_bill=nil)
if !saleObj.nil?
saleObj.sale_items.each do |item|
found, inventory_definition = find_product_in_inventory(item)
if found
check_balance(item,inventory_definition)
end
end
else
saleobj_after_req_bill.each do |item|
found, inventory_definition = find_product_in_inventory(item)
if found
check_balance(item,inventory_definition)
end
end
end
end
@@ -16,7 +25,12 @@ class InventoryDefinition < ApplicationRecord
if product.nil?
return false, nil
else
return true, product
stock_check_item = StockCheckItem.find_by_item_code(item.item_instance_code)
if stock_check_item.nil?
return false, nil
else
return true, product
end
end
end
@@ -31,11 +45,19 @@ class InventoryDefinition < ApplicationRecord
def self.modify_balance(item, stock, inventory_definition) #saleitemObj
if stock.balance.to_i >= item.qty
puts ">> stock is greater than orde qty"
puts ">> stock is greater than order qty"
StockJournal.add_to_journal(item, stock.balance, "ok", inventory_definition)
else
puts " << stock is less than order qty"
StockJournal.add_to_journal(item, stock.balance, "out of stock", inventory_definition)
item_data = item
if stock.balance.to_i > 0
item_data.qty = item.qty.to_i - stock.balance.to_i
StockJournal.add_to_journal(item_data, stock.balance, "out of stock", inventory_definition)
item.qty = stock.balance.to_i
StockJournal.add_to_journal(item, stock.balance, "ok", inventory_definition)
else
StockJournal.add_to_journal(item_data, stock.balance, "out of stock", inventory_definition)
end
end
end
end

View File

@@ -234,7 +234,7 @@ class OrderQueueStation < ApplicationRecord
order_queue_printer.print_order_summary(print_settings, oqs,order.order_id, order_items, print_status="")
assigned =AssignedOrderItem.where("order_id = '#{ order.order_id }'").pluck(:assigned_order_item_id)
AssignedOrderItem.where({ order_id: '#{assigned}'}).update_all(print_status: true)
AssignedOrderItem.where('assigned_order_item_id IN (?)', assigned).update_all(print_status: true)
# assigned_items =AssignedOrderItem.where("order_id = '#{ order.order_id }'")
# assigned_items.each do |ai|
@@ -283,6 +283,6 @@ class OrderQueueStation < ApplicationRecord
# ai.save
# end
assigned =AssignedOrderItem.where("order_id = '#{ order.order_id }'").pluck(:assigned_order_item_id)
AssignedOrderItem.where({ order_id: '#{assigned}'}).update_all(print_status: true)
AssignedOrderItem.where('assigned_order_item_id IN (?)', assigned).update_all(print_status: true)
end
end

View File

@@ -1,9 +1,6 @@
class Printer::OrderQueuePrinter < Printer::PrinterWorker
def print_order_item(print_settings,oqs, order_id, order_item_id, print_status, before_updated_qty="", options="")
#Use CUPS service
#Generate PDF
#Print
# Must be one print
if print_settings.print_copies == 0
print_settings.print_copies = 1
@@ -12,7 +9,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
order_item = print_query('order_item', order_item_id) #OrderItem.find_by_item_code(item_code)
filename = "tmp/order_item_#{order_id}_#{order_item_id}" + ".pdf"
# filename = "tmp/order_item_#{order_id}_#{order_item_id}" + ".pdf"
pdf = OrderItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
print_setting = PrintSetting.all
@@ -39,6 +36,12 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
end
# end
shop = Shop.first
directory_name = 'public/orders_'+shop.shop_code
Dir.mkdir(directory_name) unless File.exists?(directory_name)
filename = directory_name + "/order_item_#{order_id}_#{order_item_id}" + ".pdf"
pdf.render_file filename
if oqs.print_copy
@@ -56,7 +59,9 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
if ENV["SERVER_MODE"] != "cloud"
self.print(filename, oqs.printer_name)
end
end
end
return filename, order_id, oqs.printer_name
end
# Query for per order
@@ -72,12 +77,19 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
print_setting = PrintSetting.all.order("id ASC")
order=print_query('order_summary', order_id)
shop = Shop.first
directory_name = 'public/orders_'+shop.shop_code
Dir.mkdir(directory_name) unless File.exists?(directory_name)
# For Print Per Item
if oqs.cut_per_item
order_items.each do|odi|
odi_item=print_query('order_item', odi.order_items_id)
filename = "tmp/order_item_#{order_id}" + ".pdf"
odi_item=print_query('order_item', odi.order_items_id)
filename = directory_name + "/order_item_#{order_id}" + ".pdf"
# filename = "tmp/order_item_#{order_id}" + ".pdf"
# For Item Options
options = odi.options == "[]"? "" : odi.options
@@ -122,7 +134,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
end
# For Print Order Summary
else
filename = "tmp/order_summary_#{order_id}" + ".pdf"
filename = directory_name + "/order_summary_#{order_id}" + ".pdf"
# filename = "tmp/order_summary_#{order_id}" + ".pdf"
pdf = OrderSummaryPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty)
if !print_setting.empty?
print_setting.each do |print_settings|
@@ -160,6 +173,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
end
end
end
return filename, order_id, oqs.printer_name
end
# Print for orders in booking
@@ -173,10 +187,16 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
print_setting = PrintSetting.all.order("id ASC")
order=print_query('booking_summary', booking_id)
shop = Shop.first
directory_name = 'public/orders_'+shop.shop_code
Dir.mkdir(directory_name) unless File.exists?(directory_name)
# For Print Per Item
if oqs.cut_per_item
order.each do|odi|
filename = "tmp/order_item_#{booking_id}" + ".pdf"
# filename = "tmp/order_item_#{booking_id}" + ".pdf"
filename = directory_name + "/order_item_#{booking_id}" + ".pdf"
# For Item Options
options = odi.options == "[]"? "" : odi.options
@@ -222,7 +242,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
end
# For Print Order Summary
else
filename = "tmp/booking_summary_#{booking_id}" + ".pdf"
# filename = "tmp/booking_summary_#{booking_id}" + ".pdf"
filename = directory_name + "/booking_summary_#{booking_id}" + ".pdf"
pdf = OrderSummaryPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
if !print_setting.empty?
@@ -261,6 +282,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
end
end
end
return filename, booking_id, oqs.printer_name
end
# Query for OQS with status

View File

@@ -2125,7 +2125,7 @@ end
else
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time)
end
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) + (#{outstanding_query})) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
else
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
if payment_method == 'card'
@@ -2133,7 +2133,7 @@ end
else
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ?",from,to)
end
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) + (#{outstanding_query})) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
end
else
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
@@ -2144,7 +2144,7 @@ end
else
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time)
end
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) + (#{outstanding_query})) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
else
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
if payment_method == 'card'
@@ -2152,7 +2152,7 @@ end
else
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ?",from,to)
end
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) + (#{outstanding_query})) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
end
else
shift = ShiftSale.current_open_shift(current_user.id)
@@ -2164,7 +2164,7 @@ end
else
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id)
end
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) + (#{outstanding_query})) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
else
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
if payment_method == 'card'
@@ -2172,7 +2172,7 @@ end
else
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id)
end
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) + (#{outstanding_query})) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
end
end
end
@@ -2185,7 +2185,7 @@ end
else
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
end
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) + (#{outstanding_query})) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
else
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
@@ -2194,7 +2194,7 @@ end
else
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
end
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) + (#{outstanding_query})) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
@@ -2204,7 +2204,7 @@ end
else
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id)
end
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) + (#{outstanding_query})) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
end
end
end

View File

@@ -98,7 +98,7 @@ class SalePayment < ApplicationRecord
booking = Booking.find_by_sale_id(sale_id)
booking.booking_orders.each do |sodr|
assigned =AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").pluck(:assigned_order_item_id)
AssignedOrderItem.where({ order_id: '#{assigned}'}).update_all(print_status: true)
AssignedOrderItem.where('assigned_order_item_id IN (?)', assigned).update_all(delivery_status: true)
# AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi|
# aoi.delivery_status = 1
# aoi.save

View File

@@ -36,10 +36,10 @@ class StockCheckItem < ApplicationRecord
def self.get_transaction(from, to, item_code)
transaction = all
if !from.nil? && !to.nil?
transaction = transaction.where('created_at between ? and ?', from, to)
transaction = transaction.where('created_at between ? and ?', from, to).order("item_code asc, different desc")
end
if item_code.present?
transaction = transaction.where(item_code: item_code)
transaction = transaction.where(item_code: item_code).order("item_code asc, different desc")
end
transaction
end

View File

@@ -4,10 +4,11 @@ class StockJournal < ApplicationRecord
STOCK_CHECK_TRANS = "stock_check"
def self.add_to_journal(item, balance, stock_message, inventory_definition) # item => saleObj | balance => Stock journal
journal = StockJournal.new
journal.credit = balance
balance = calculate_balance(balance, item.qty)
journal = StockJournal.new
journal.item_code = item.item_instance_code
journal.inventory_definition_id = inventory_definition.id
journal.debit = item.qty