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

1
.gitignore vendored
View File

@@ -28,6 +28,7 @@ capybara-*.html
/public/uploads/*
/public/swf/*
/public/receipts/
/public/orders_*
/public/*.mp3
/coverage/
/spec/tmp/*

View File

@@ -2,7 +2,8 @@ FROM ruby:2.4.1
RUN apt-get update -qq && apt-get install -y build-essential libmysqlclient-dev libcups2-dev libpq-dev nodejs
RUN mkdir /sxrestaurant
RUN mkdir -p /sxrestaurant/tmp/puma
ENV RAILS_ENV production
ENV RAILS_ENV staging
ENV RACK_ENV staging
WORKDIR /sxrestaurant
COPY Gemfile /sxrestaurant/Gemfile
COPY Gemfile.lock /sxrestaurant/Gemfile.lock
@@ -10,4 +11,5 @@ RUN bundle install --without development test
RUN echo "Asia/Rangoon" > /etc/timezone
RUN dpkg-reconfigure -f noninteractive tzdata
COPY . /sxrestaurant
RUN bundle exec rails assets:precompile
RUN bundle exec rake assets:precompile
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]

View File

@@ -254,6 +254,9 @@ For Customer Settings On/Off
For TaxProfiles On/Off
1) settings/lookups => {type:changable_tax, name:change, value: {1 or 0}}
For Add Kitchen Role
1) settings/lookups => {type:employee_roles, name:Kitchen, value:kitchen}
* ToDo list
1. Migration

View File

@@ -354,12 +354,16 @@ $(document).on('turbolinks:load', function() {
var assigned_item_id = $('.selected-item').children('.card-block').children('.assigned-order-item').text();
var options = $('.selected-item').children('.card-block').find('.item-options').text();
var params = { 'options':options };
$.ajax({
type: 'POST',
type: 'GET',
url: '/oqs/print/print/'+assigned_item_id,
data: params,
success: function(data){ }
success: function(result){
// For Server Print - from jade
if ($("#server_mode").val() == "cloud") {
code2lab.printFile(result.filepath.substr(6), result.printer_url);
}
}
});
});
@@ -374,7 +378,12 @@ $(document).on('turbolinks:load', function() {
type: 'GET',
url: '/oqs/print/print_order_summary/'+assigned_item_id,
data: params,
success: function(data){ }
success: function(result){
// For Server Print - from jade
if ($("#server_mode").val() == "cloud") {
code2lab.printFile(result.filepath.substr(6), result.printer_url);
}
}
});
});
});

View File

@@ -1,7 +1,35 @@
class Inventory::InventoryController < BaseInventoryController
load_and_authorize_resource
def index
@products = InventoryDefinition.all.active.order('created_at desc')
least_stock = "SELECT (CASE WHEN SIGN(MIN(stock_journals.balance)) > 0
THEN MIN(stock_journals.balance) WHEN stock_journals.remark NOT LIKE '%out of stock%'
THEN (SELECT balance FROM stock_journals
WHERE item_code = inventory_definitions.item_code
AND remark NOT LIKE '%out of stock%'
ORDER BY created_at DESC LIMIT 1) ELSE 0 END)
FROM stock_journals
WHERE stock_journals.item_code = inventory_definitions.item_code
ORDER BY stock_journals.created_at DESC"
@inventory_definitions = InventoryDefinition.select("inventory_definitions.*,
(CASE WHEN sj.credit IS NULL THEN 0 ELSE sj.credit END) as credit,
(CASE WHEN sj.debit IS NULL THEN 0 ELSE sj.debit END) as debit,
(#{least_stock}) as balance")
.joins(" LEFT JOIN stock_journals sj ON sj.inventory_definition_id=inventory_definitions.id")
.group("inventory_definitions.item_code")
.order("(CASE WHEN sj.balance > 0 THEN MIN(sj.balance) ELSE NULL END )")
end
def show
inventory_definition_id = params[:inventory_definition_id]
inventory = InventoryDefinition.find(inventory_definition_id)
@stock_journals = StockJournal.where(item_code: inventory.item_code)
respond_to do |format|
format.html
format.xls
end
end
#Shop Name in Navbor

View File

@@ -24,7 +24,14 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController
# POST /inventory_definitions
# POST /inventory_definitions.json
def create
inventory = InventoryDefinition.find_by_item_code(inventory_definition_params[:item_code])
if inventory.nil?
@inventory_definition = InventoryDefinition.new(inventory_definition_params)
else
@inventory_definition = InventoryDefinition.find(inventory.id)
@inventory_definition.min_order_level = inventory_definition_params[:min_order_level]
@inventory_definition.max_stock_level = inventory.max_stock_level.to_i + inventory_definition_params[:max_stock_level].to_i
end
@inventory_definition.created_by = current_user.id
respond_to do |format|
if @inventory_definition.save

View File

@@ -2,7 +2,7 @@ class Oqs::PrintController < ApplicationController
authorize_resource :class => false
# Print Order Item
def print
if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf
printer = PrintSetting.all
unique_code="OrderItemPdf"
@@ -41,19 +41,30 @@ class Oqs::PrintController < ApplicationController
# print when complete click
print_settings = PrintSetting.find_by_unique_code(unique_code)
order_queue_printer = Printer::OrderQueuePrinter.new(print_settings)
order_queue_printer.print_order_item(print_settings,oqs, assigned_item.order_id, order_item.order_items_id, print_status, "", options )
filename, receipt_no, cashier_printer = order_queue_printer.print_order_item(print_settings,oqs, assigned_item.order_id, order_item.order_items_id, print_status, "", options )
# update print status for completed same order items
assigned_items.each do |ai|
ai.print_status=true
ai.save
end
# filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil,other_amount)
if ENV["SERVER_MODE"] == "cloud"
result = {
:filepath => filename,
:printer_model => print_settings.brand_name,
:printer_url => print_settings.api_settings
}
# Mobile Print
render :json => result.to_json
end
# end
end
# Print Order Details with booking id
def print_order_summary
if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf
printer = PrintSetting.all
unique_code="OrderSummaryPdf"
@@ -98,14 +109,25 @@ class Oqs::PrintController < ApplicationController
# print when complete click
print_settings = PrintSetting.find_by_unique_code(unique_code)
order_queue_printer = Printer::OrderQueuePrinter.new(print_settings)
order_queue_printer.print_booking_summary(print_settings,oqs, booking_id, print_status)
filename, receipt_no, cashier_printer = order_queue_printer.print_booking_summary(print_settings,oqs, booking_id, print_status)
# update print status for completed same order items
assigned_items.each do |ai|
ai.print_status = true
ai.save
end
# filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil,other_amount)
if ENV["SERVER_MODE"] == "cloud"
result = {
:filepath => filename,
:printer_model => print_settings.brand_name,
:printer_url => print_settings.api_settings
}
# Mobile Print
render :json => result.to_json
end
# end
end
end

View File

@@ -26,6 +26,7 @@ class Origami::SalesController < BaseOrigamiController
dining = params[:dining_id]
sale_id = params[:sale_id]
tax_type = params[:tax_type]
sale_data = []
table = DiningFacility.find(dining)
existing_booking = Booking.find_by_sale_id(sale_id)
table.bookings.each do |booking|
@@ -49,6 +50,7 @@ class Origami::SalesController < BaseOrigamiController
if !orer_item.set_menu_items.nil?
saleobj.add_sub_item(orer_item.set_menu_items)
end
sale_data.push(orer_item)
end
# Re-compute for add
@@ -75,6 +77,10 @@ class Origami::SalesController < BaseOrigamiController
end
end
end
if !sale_data.empty?
# InventoryJob.perform_now(self.id)
InventoryDefinition.calculate_product_count(nil,sale_data)
end
end
end

View File

@@ -2,23 +2,37 @@ class InventoryDefinition < ApplicationRecord
scope :active, -> {where(:is_active => true)}
def self.calculate_product_count(saleObj)
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
def self.find_product_in_inventory(item)
product = InventoryDefinition.find_by_item_code(item.item_instance_code)
if product.nil?
return false, nil
else
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
def self.check_balance(item,inventory_definition) # item => saleItemOBj
stock = StockJournal.where('item_code=?', item.item_instance_code).order('created_at desc').take
@@ -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
@@ -57,6 +60,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
self.print(filename, oqs.printer_name)
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"
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

View File

@@ -5,12 +5,14 @@
<th><%= t("views.right_panel.detail.product") %></th>
<th><%= t("views.right_panel.detail.min_order") %></th>
<th><%= t("views.right_panel.detail.max_stock") %></th>
<th><%= t("views.right_panel.detail.created_by") %></th>
<th><%= t("views.right_panel.detail.created_time") %></th>
<th><%= t("views.right_panel.detail.balance") %></th>
<th><%= t("views.right_panel.detail.action") %></th>
<!-- <th><%= t("views.right_panel.detail.created_by") %></th>
<th><%= t("views.right_panel.detail.created_time") %></th> -->
</tr>
<%
count = 0
@products.each do |item|
@inventory_definitions.each do |item|
count += 1
%>
<tr>
@@ -26,9 +28,20 @@
</td>
<td><%= item.min_order_level %></td>
<td><%= item.max_stock_level %></td>
<td><%= Employee.find(item.created_by).name rescue '-' %></td>
<td><%= item.created_at.utc.getlocal.strftime("%e %b %Y %I:%M %p") rescue '-' %></td>
<td><%= item.balance rescue '0' %></td>
<td>
<button type="button" data-value="<%= item.id %>" class="btn bg-blue waves-effect btn-link show_track"><%= t("views.btn.show") %> <%= t("views.right_panel.detail.stock_check") %></button>
</td>
<!-- <td><%= Employee.find(item.created_by).name rescue '-' %></td>
<td><%= item.created_at.utc.getlocal.strftime("%e %b %Y %I:%M %p") rescue '-' %></td> -->
</tr>
<% end %>
</table>
<script>
$('.show_track').on('click', function () {
var ID = $(this).attr("data-value");
window.location.href = '/inventory/'+ID+'/show';
});
</script>

View File

@@ -12,10 +12,10 @@
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-9 col-lg-9">
<div class="m-b-10 clearfix">
<button id="stock_check_report" type="button" class="btn bg-blue float-right waves-effect" style='margin-left:5px;'> <%= t("views.btn.stock_check_report") %>
</button>
<button id="stock_taking" type="button" class="btn bg-blue float-right waves-effect" style='margin-left:5px;'> <%= t("views.btn.new_stock_taking") %></button>
<button id='new_inventory_product' class='btn btn-primary float-right waves-effect' style='margin-left:5px;'><%= t("views.btn.new") + " " + (t :inventory) %>
<!-- <button id="stock_check_report" type="button" class="btn bg-blue float-right waves-effect" style='margin-left:5px;'> <%= t("views.btn.stock_check_report") %>
</button> -->
<button id="stock_taking" type="button" class="btn bg-blue float-right waves-effect" style='margin-left:5px;'> <%= t("views.btn.stock_taking") %></button>
<button id='new_inventory_product' class='btn btn-primary float-right waves-effect' style='margin-left:5px;'><%= (t :track) +" "+ t("views.btn.new") + " " + (t :inventory) %>
</button>
</div>
<div class="card">
@@ -27,14 +27,14 @@
<div class="body">
<h5><i class="material-icons md-18">list <%= t("views.right_panel.header.button_lists") %></i> </h5>
<p>
1) <%= t("views.btn.new") + " " + (t :inventory) %> - <%= t("views.right_panel.detail.create_btn_txt") %> <%= t("views.right_panel.detail.inventory") %> <br>
1) <%= (t :track) +" "+ t("views.btn.new") + " " + (t :inventory) %> - <%= t("views.right_panel.detail.create_btn_txt") %> <%= t("views.right_panel.detail.inventory") %> <br>
</p>
<p>
2) <%= t("views.btn.new") + " " + t("views.right_panel.detail.stock_taking") %> - <%= t("views.right_panel.detail.create_btn_txt") %> <%= t("views.right_panel.detail.stock_taking_txt") %> <br>
2) <%= t("views.right_panel.detail.stock_taking") %> - <%= t("views.right_panel.detail.create_btn_txt") %> <%= t("views.right_panel.detail.stock_taking_txt") %> <br>
</p>
<p>
<!-- <p>
3) <%= t("views.right_panel.detail.stock_check_report") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.stock_check_report_txt") %> <br>
</p>
</p> -->
<h5><i class="material-icons md-18">list <%= t("views.right_panel.header.link_lists") %></i> </h5>
<p>
1) <%= t("views.right_panel.button.home") %> - <%= t("views.right_panel.detail.home_txt") %> <br>
@@ -51,12 +51,12 @@
window.location.href = '<%= inventory_stock_checks_path %>';
});
$('#stock_check_report').on('click', function () {
window.location.href = '<%= reports_stock_check_index_path %>';
});
// $('#stock_check_report').on('click', function () {
// window.location.href = '<%= reports_stock_check_index_path %>';
// });
$('#new_inventory_product').on('click',function(){
window.location.href = '/inventory/inventory_definitions/new';
})
});
</script>

View File

@@ -0,0 +1,70 @@
<div class="page-header">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="<%= dashboard_path %>"><%= t("views.right_panel.button.home") %></a></li>
<li class="breadcrumb-item active"><%= t :inventory %></li>
<span class="float-right">
<%= link_to t('.back', :default => t("views.btn.back")), inventory_path %>
</span>
</ol>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<table class="table table-responsive table-striped table-hover">
<thead>
<tr>
<th><%= t("views.right_panel.detail.date") %></th>
<th><%= t("views.right_panel.detail.type") %></th>
<th><%= t("views.right_panel.detail.item") %> <%= t("views.right_panel.detail.name") %></th>
<th><%= t :credit %></th>
<th><%= t :debit %></th>
<th><%= t("views.right_panel.detail.balance") %></th>
<th><%= t("views.right_panel.detail.remark") %></th>
</tr>
</thead>
<tbody>
<% total_credit = 0 %>
<% total_debit = 0 %>
<% total_balance = 0 %>
<% if !@stock_journals.nil? && !@stock_journals.empty? %>
<% @stock_journals.each do |result| %>
<tr>
<td><%= result.created_at.strftime('%e %b %Y %I:%M %p') rescue '-' %></td>
<td><%= result.trans_type rescue '-' %></td>
<td>
<% menu_item = MenuItemInstance.find_by_item_instance_code(result.item_code)%>
<% if menu_item.nil? %>
<%= Product.find_by_item_code(result.item_code).name rescue "-" %>
<% else %>
<%= menu_item.menu_item.name rescue "-" %>
- <%= menu_item.item_instance_name rescue "-" %>
<% end %>
</td>
<td><%= result.credit rescue '-' %></td>
<td><%= result.debit rescue '-' %></td>
<td><%= result.balance rescue '-' %></td>
<td><%= result.remark rescue '-' %></td>
</tr>
<% !result.credit.nil? ? total_credit += result.credit : total_credit += 0 %>
<% !result.debit.nil? ? total_debit += result.debit : total_debit += 0 %>
<% !result.balance.nil? ? total_balance += result.balance : total_balance += 0 %>
<% end %>
<!-- <tr style="border-top: 3px solid grey;">
<td colspan="3"></td>
<td><b><%= total_credit rescue '-' %></b></td>
<td><b><%= total_debit rescue '-' %></b></td>
<td><b><%= total_balance rescue '-' %></b></td>
<td colspan="2"></td>
</tr> -->
<% else %>
<tr>
<td colspan="8" class="text-center">There is no record...</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>

View File

@@ -101,14 +101,25 @@
</div>
<script>
var count = 0;
$(document).ready(function(){
clearFormData();
});
function clearFormData(){
$('#stock_check_reason').val("");
$('#product_qty').val("");
$('#product_sku').val("");
}
$('#save_to_stock_check').on('click', function () {
count += 1;
product_sku = $('#product_sku').val();
product_qty = $('#product_qty').val();
product_name = $("#product_sku").find("option:selected").text();
// clearFormData();
var tr = '<tr>'
//+ '<td>' + count + '</td>'
+ '<td><input type=hidden value="' + product_sku + '" id="item_sku_' + count + '" name=' + count + '/>'

View File

@@ -176,12 +176,15 @@
<!-- OQS Buttons -->
<br>
<a href="<%= dashboard_path %>" class="btn btn-sm btn-block btn-default waves-effect" role="button" aria-haspopup="true"><i class="material-icons">reply</i> Back </a>
<% if ENV["SERVER_MODE"] != "cloud" %>
<button type="button" title="Print Order Item" id="print_order_item" class="btn bg-blue btn-block btn-lg waves-effect">Print</a>
<button type="button" class="btn bg-blue btn-block btn-lg waves-effect" id="print_order_summary">Print <br/>Order<br/>Summary</button>
<% if ENV["SERVER_MODE"] != "cloud" %>
<%end%>
</div>
</div>
<input type="hidden" id="server_mode" value="<%=ENV["SERVER_MODE"]%>">
<script type="text/javascript">
$(document).on('turbolinks:load', function() {

View File

@@ -21,9 +21,9 @@
<input data-behaviour='datepicker' class="form-control datepicker m-t-3" name="to" id="to" type="text" placeholder="To date" style="height: 32px;">
</div>
<div class="form-group col-md-4">
<label class="font-14">Definition Item</label>
<label class="font-14">Select Item</label>
<select class="form-control" name="item_code" id="item_code">
<option value="">Select Product</option>
<option value="">Select Item</option>
<% @inventory_definitions.each do |id| %>
<option value="<%= id.item_code %>">
<% menu_item = MenuItemInstance.find_by_item_instance_code(id.item_code) %>

View File

@@ -8,7 +8,7 @@
</ol>
</div>
<div class="row">
<div class="col-md-12">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<!-- <div class="container"> -->
<%= render :partial => 'stock_check_report_filter',
@@ -46,59 +46,64 @@
<th colspan="8"><i> From Date </i>: <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <i>To Date</i> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %></th>
</tr>
<tr>
<th>Stock Check Reason</th>
<th>Checked By</th>
<th>Item Name</th>
<th>Stock Count</th>
<th>Stock Balance</th>
<th>Different</th>
<th>Remark</th>
<th>Date</th>
<th><%= t("views.right_panel.detail.item") %> <%= t("views.right_panel.detail.name") %></th>
<th><%= t("views.right_panel.detail.stock_count") %></th>
<th><%= t("views.right_panel.detail.stock_balance") %></th>
<th><%= t("views.right_panel.detail.different") %></th>
<th><%= t("views.right_panel.detail.remark") %></th>
<th><%= t("views.right_panel.detail.checked_by") %></th>
<th><%= t("views.right_panel.detail.stock_check") %> <%= t("views.right_panel.detail.reason") %></th>
</tr>
</thead>
<tbody>
<% total_stock_count = 0 %>
<% total_stock_balance = 0 %>
<% total_different = 0 %>
<% arr_item_code = [] %>
<% @transaction.each do |result| %>
<tr>
<td><%= result.stock_check.reason rescue '-' %></td>
<td><%= Employee.find(result.stock_check.check_by).name rescue '-' %></td>
<td>
<% menu_item = MenuItemInstance.find_by_item_instance_code(result.item_code)%>
<% if menu_item.nil? %>
<% if !arr_item_code.include?(result.item_code) %>
<%= Product.find_by_item_code(result.item_code).name rescue "-" %>
<% arr_item_code.push(result.item_code) %>
<% else %>
&nbsp;
<% end %>
<% else %>
<% if !arr_item_code.include?(result.item_code) %>
<%= menu_item.menu_item.name rescue "-" %>
- <%= menu_item.item_instance_name rescue "-" %>
<% arr_item_code.push(result.item_code) %>
<% else %>
&nbsp;
<% end %>
<% end %>
</td>
<td><%= result.stock_count rescue '-' %></td>
<td><%= number_with_precision(result.stock_balance, precision:precision.to_i,delimiter:delimiter) rescue '-' %></td>
<td><%= result.stock_balance rescue '-' %></td>
<td><%= result.different rescue '-' %></td>
<td><%= result.remark rescue '-' %></td>
<td><%= result.created_at.strftime('%e %b %Y %I:%M %p') rescue '-' %></td>
<td><%= Employee.find(result.stock_check.check_by).name rescue '-' %></td>
<td><%= result.stock_check.reason rescue '-' %></td>
</tr>
<% !result.stock_count.nil? ? total_stock_count += result.stock_count : total_stock_count += 0 %>
<% !result.stock_balance.nil? ? total_stock_balance += result.stock_balance : total_stock_balance += 0 %>
<% !result.different.nil? ? total_different += result.different : total_different += 0 %>
<% end %>
<tr style="border-top: 3px solid grey;">
<!-- <tr style="border-top: 3px solid grey;">
<td colspan="3"></td>
<td><b><%= total_stock_count rescue '-' %></b></td>
<td><b><%= number_with_precision(total_stock_balance, precision:precision.to_i,delimiter:delimiter) rescue '-' %></b></td>
<td><b><%= total_different rescue '-' %></b></td>
<td colspan="2"></td>
</tr>
<td></td>
</tr> -->
</tbody>
</table>
</div>
</div>
</div>
<script>
$(function () {
});
</script>
</div>
</div>

View File

@@ -14,44 +14,60 @@
<th colspan="7"> From Date : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - To Date : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %></th>
</tr>
<tr>
<th>Commissioner Name</th>
<th>Product Name</th>
<th>Qty</th>
<th>Commission Price</th>
<th>Commission Amount</th>
<th>Date</th>
<th><%= t("views.right_panel.detail.item") %> <%= t("views.right_panel.detail.name") %></th>
<th><%= t("views.right_panel.detail.stock_count") %></th>
<th><%= t("views.right_panel.detail.stock_balance") %></th>
<th><%= t("views.right_panel.detail.different") %></th>
<th><%= t("views.right_panel.detail.remark") %></th>
<th><%= t("views.right_panel.detail.checked_by") %></th>
<th><%= t("views.right_panel.detail.stock_check") %> <%= t("views.right_panel.detail.reason") %></th>
</tr>
</thead>
<tbody>
<% total_qty = 0 %>
<% total_price = 0 %>
<% total_amount = 0 %>
<% total_stock_count = 0 %>
<% total_stock_balance = 0 %>
<% total_different = 0 %>
<% arr_item_code = [] %>
<% @transaction.each do |result| %>
<tr>
<td>
<%= result.commissioner.name rescue '-' %>
<% menu_item = MenuItemInstance.find_by_item_instance_code(result.item_code)%>
<% if menu_item.nil? %>
<% if !arr_item_code.include?(result.item_code) %>
<%= Product.find_by_item_code(result.item_code).name rescue "-" %>
<% arr_item_code.push(result.item_code) %>
<% else %>
&nbsp;
<% end %>
<% else %>
<% if !arr_item_code.include?(result.item_code) %>
<%= menu_item.menu_item.name rescue "-" %>
- <%= menu_item.item_instance_name rescue "-" %>
<% arr_item_code.push(result.item_code) %>
<% else %>
&nbsp;
<% end %>
<% end %>
</td>
<td>
<%= result.commission.menu_item.name rescue '-' %>
</td>
<td><%= sprintf "%.2f", result.qty.to_f.to_d rescue '-' %></td>
<td><%= sprintf "%.2f", result.price.to_f.to_d rescue '-' %></td>
<td><%= sprintf "%.2f", result.amount.to_f.to_d rescue '-' %></td>
<td><%= result.updated_at.strftime("%e %b %Y %I:%M%p") rescue '-' %></td>
<td><%= result.stock_count rescue '-' %></td>
<td><%= result.stock_balance rescue '-' %></td>
<td><%= result.different rescue '-' %></td>
<td><%= result.remark rescue '-' %></td>
<td><%= Employee.find(result.stock_check.check_by).name rescue '-' %></td>
<td><%= result.stock_check.reason rescue '-' %></td>
</tr>
<% total_qty += result.qty.to_f %>
<% total_price += result.price.to_f %>
<% total_amount += result.amount.to_f %>
<% !result.stock_count.nil? ? total_stock_count += result.stock_count : total_stock_count += 0 %>
<% !result.stock_balance.nil? ? total_stock_balance += result.stock_balance : total_stock_balance += 0 %>
<% !result.different.nil? ? total_different += result.different : total_different += 0 %>
<% end %>
<tr style="border-top: 3px solid grey;">
<td colspan="2"></td>
<td><b><%= sprintf("%.2f", total_qty) rescue '-' %></b></td>
<td><b><%= sprintf("%.2f", total_price) rescue '-' %></b></td>
<td><b><%= sprintf("%.2f", total_amount) rescue '-' %></b></td>
<!-- <tr style="border-top: 3px solid grey;">
<td colspan="3"></td>
<td><b><%= total_stock_count rescue '-' %></b></td>
<td><b><%= number_with_precision(total_stock_balance, precision:precision.to_i,delimiter:delimiter) rescue '-' %></b></td>
<td><b><%= total_different rescue '-' %></b></td>
<td></td>
</tr>
</tr> -->
</tbody>
</table>
</div>

View File

@@ -84,6 +84,8 @@ en:
processed: "Processed"
delivery_details: "Delivery Details"
credits: "Credits"
track: "Track"
debit: "Debit"
views:
btn:
@@ -494,6 +496,7 @@ en:
in_time: "In Time"
out_time: "Out Time"
transaction_fee: "Transaction Fee"
checked_by: "Checked By"
code_txt: "code "
charge_txt: "charge"

View File

@@ -79,6 +79,8 @@ mm:
processed: "Processed"
delivery_details: "Delivery Details"
credits: "အကြွေးများ"
track: "Track"
debit: "Debit"
views:
btn:
@@ -488,6 +490,7 @@ mm:
in_time: "In Time"
out_time: "Out Time"
transaction_fee: "Transaction Fee"
checked_by: "Checked By"
code_txt: "ကုတ်ဒ် "
charge_txt: "ကောက်ခံသည်"

View File

@@ -357,7 +357,7 @@ scope "(:locale)", locale: /en|mm/ do
post "/:id", to: "edit#update"
# Pass assigned_order_item_id
post 'print/print/:id', to: "print#print"
get 'print/print/:id', to: "print#print"
get 'print/print_order_summary/:id', to: "print#print_order_summary"
get "/get_items/:id" => "home#get_items_by_oqs", :as => "get_order_items_by_oqs"
@@ -513,6 +513,7 @@ scope "(:locale)", locale: /en|mm/ do
# resources :stock_checks
resources :stock_journals
resources :inventory_definitions
get ':inventory_definition_id/show' => 'inventory#show'
end
#mount_compendium at: '/report' #, controller: 'reports'

View File

@@ -9,7 +9,7 @@ class CreateSaleAudits < ActiveRecord::Migration[5.1]
t.string :action_by, :null => false
t.string :approved_by, :null => true
t.datetime :approved_at, :null => true
t.text :remark, :index => true
t.string :remark, :index => true
t.timestamps
end
add_index :sale_audits, [:sale_id, :action, :action_at, :remark]

View File

@@ -1,16 +1,17 @@
version: '3'
services:
code2lab:
build: .
build:
context: .
dockerfile: ./Dockerfile
links:
- redis
command: bundle exec puma -C config/puma.rb
volumes:
- .:/sxrestaurant
env_file:
- .code2lab.env
ports:
- '8081:62158'
- '8082:62158'
environment:
- REDIS_URL=redis://redis:6379/0
sidekiq:
@@ -22,10 +23,9 @@ services:
- .:/sxrestaurant
environment:
- REDIS_URL=redis://redis:6379/0
redis:
image: redis
ports:
- '6379:6379'
- '6380:6379'
volumes:
- ../data/redis:/data