From cc8b107f9fd44d183fd8a5bfb5e2a897874557e6 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 15 Aug 2018 15:19:28 +0630 Subject: [PATCH 1/9] update oqs print in cloud --- app/assets/javascripts/OQS.js | 17 ++++++--- app/controllers/oqs/print_controller.rb | 36 +++++++++++++++---- app/models/printer/order_queue_printer.rb | 42 +++++++++++++++++------ app/views/oqs/home/index.html.erb | 5 ++- config/routes.rb | 2 +- 5 files changed, 79 insertions(+), 23 deletions(-) diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index 07fb94f1..378ae434 100755 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -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); + } + } }); }); }); diff --git a/app/controllers/oqs/print_controller.rb b/app/controllers/oqs/print_controller.rb index fc65f2da..6a59025e 100755 --- a/app/controllers/oqs/print_controller.rb +++ b/app/controllers/oqs/print_controller.rb @@ -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 - end + 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 - 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 \ No newline at end of file diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 267772f2..b50d83f9 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -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 diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index ec5e0613..57a4471f 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -176,12 +176,15 @@
reply Back - <% if ENV["SERVER_MODE"] != "cloud" %> + + <% if ENV["SERVER_MODE"] != "cloud" %> <%end%> +"> \ No newline at end of file diff --git a/app/views/inventory/inventory/index.html.erb b/app/views/inventory/inventory/index.html.erb index ee62697c..55c9884a 100755 --- a/app/views/inventory/inventory/index.html.erb +++ b/app/views/inventory/inventory/index.html.erb @@ -12,10 +12,10 @@
- - - +
@@ -27,14 +27,14 @@
list <%= t("views.right_panel.header.button_lists") %>

- 1) <%= t("views.btn.new") + " " + (t :inventory) %> - <%= t("views.right_panel.detail.create_btn_txt") %> <%= t("views.right_panel.detail.inventory") %>
+ 1) <%= (t :track) +" "+ t("views.btn.new") + " " + (t :inventory) %> - <%= t("views.right_panel.detail.create_btn_txt") %> <%= t("views.right_panel.detail.inventory") %>

- 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") %>
+ 2) <%= t("views.right_panel.detail.stock_taking") %> - <%= t("views.right_panel.detail.create_btn_txt") %> <%= t("views.right_panel.detail.stock_taking_txt") %>

-

+

list <%= t("views.right_panel.header.link_lists") %>

1) <%= t("views.right_panel.button.home") %> - <%= t("views.right_panel.detail.home_txt") %>
@@ -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'; -}) + }); diff --git a/app/views/inventory/inventory/show.html.erb b/app/views/inventory/inventory/show.html.erb new file mode 100644 index 00000000..0176928b --- /dev/null +++ b/app/views/inventory/inventory/show.html.erb @@ -0,0 +1,70 @@ +

+ + +
+
+ + + + + + + + + + + + + + <% total_credit = 0 %> + <% total_debit = 0 %> + <% total_balance = 0 %> + + <% if !@stock_journals.nil? && !@stock_journals.empty? %> + <% @stock_journals.each do |result| %> + + + + + + + + + + <% !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 %> + + + <% else %> + + + + <% end %> + +
<%= t("views.right_panel.detail.date") %><%= t("views.right_panel.detail.type") %><%= t("views.right_panel.detail.item") %> <%= t("views.right_panel.detail.name") %><%= t :credit %><%= t :debit %><%= t("views.right_panel.detail.balance") %><%= t("views.right_panel.detail.remark") %>
<%= result.created_at.strftime('%e %b %Y %I:%M %p') rescue '-' %><%= result.trans_type rescue '-' %> + <% 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 %> + <%= result.credit rescue '-' %><%= result.debit rescue '-' %><%= result.balance rescue '-' %><%= result.remark rescue '-' %>
There is no record...
+
+
\ No newline at end of file diff --git a/app/views/inventory/stock_checks/index.html.erb b/app/views/inventory/stock_checks/index.html.erb index 20633b22..667a172e 100755 --- a/app/views/inventory/stock_checks/index.html.erb +++ b/app/views/inventory/stock_checks/index.html.erb @@ -101,14 +101,25 @@
\ No newline at end of file +
+
+
+ \ No newline at end of file diff --git a/app/views/reports/stock_check/index.xls.erb b/app/views/reports/stock_check/index.xls.erb index 6ec88072..ea90c8af 100755 --- a/app/views/reports/stock_check/index.xls.erb +++ b/app/views/reports/stock_check/index.xls.erb @@ -14,44 +14,60 @@ From Date : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - To Date : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - Commissioner Name - Product Name - Qty - Commission Price - Commission Amount - Date + <%= t("views.right_panel.detail.item") %> <%= t("views.right_panel.detail.name") %> + <%= t("views.right_panel.detail.stock_count") %> + <%= t("views.right_panel.detail.stock_balance") %> + <%= t("views.right_panel.detail.different") %> + <%= t("views.right_panel.detail.remark") %> + <%= t("views.right_panel.detail.checked_by") %> + <%= t("views.right_panel.detail.stock_check") %> <%= t("views.right_panel.detail.reason") %> - <% 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| %> + + + <% 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 %> +   + <% 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 %> +   + <% end %> + <% end %> + + <%= result.stock_count rescue '-' %> + <%= result.stock_balance rescue '-' %> + <%= result.different rescue '-' %> + <%= result.remark rescue '-' %> + <%= Employee.find(result.stock_check.check_by).name rescue '-' %> + <%= result.stock_check.reason rescue '-' %> + + <% !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 %> - <% @transaction.each do |result| %> - - - <%= result.commissioner.name rescue '-' %> - - - <%= result.commission.menu_item.name rescue '-' %> - - <%= sprintf "%.2f", result.qty.to_f.to_d rescue '-' %> - <%= sprintf "%.2f", result.price.to_f.to_d rescue '-' %> - <%= sprintf "%.2f", result.amount.to_f.to_d rescue '-' %> - <%= result.updated_at.strftime("%e %b %Y %I:%M%p") rescue '-' %> - - <% total_qty += result.qty.to_f %> - <% total_price += result.price.to_f %> - <% total_amount += result.amount.to_f %> - <% end %> - - - - <%= sprintf("%.2f", total_qty) rescue '-' %> - <%= sprintf("%.2f", total_price) rescue '-' %> - <%= sprintf("%.2f", total_amount) rescue '-' %> - - + diff --git a/config/locales/en.yml b/config/locales/en.yml index 3d99a17d..b089780f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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" diff --git a/config/locales/mm.yml b/config/locales/mm.yml index 10e105d1..45166af2 100644 --- a/config/locales/mm.yml +++ b/config/locales/mm.yml @@ -79,7 +79,9 @@ mm: processed: "Processed" delivery_details: "Delivery Details" credits: "အကြွေးများ" - + track: "Track" + debit: "Debit" + views: btn: create: "အသစ်တည်ဆောက်ရန်" @@ -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: "ကောက်ခံသည်" diff --git a/config/routes.rb b/config/routes.rb index 4d4585eb..d955f75a 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' From b91ad06f35814dae4bd30bb73c48aa565cfbc5a8 Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 16 Aug 2018 17:40:49 +0630 Subject: [PATCH 5/9] change query for inventory --- .../inventory/inventory_controller.rb | 17 +++++++++++++---- app/views/reports/stock_check/index.html.erb | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/controllers/inventory/inventory_controller.rb b/app/controllers/inventory/inventory_controller.rb index 966872a4..4d6d733c 100755 --- a/app/controllers/inventory/inventory_controller.rb +++ b/app/controllers/inventory/inventory_controller.rb @@ -1,12 +1,21 @@ class Inventory::InventoryController < BaseInventoryController load_and_authorize_resource def index + 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 balance > 0 + 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 '-' ELSE sj.credit END) as credit, - (CASE WHEN sj.debit IS NULL THEN '-' ELSE sj.debit END) as debit, - (CASE WHEN sj.balance IS NULL THEN '-' ELSE sj.balance END) as balance") + (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") - .where("(CASE WHEN sj.balance > 0 THEN sj.balance=(SELECT MIN(balance) FROM stock_journals WHERE stock_journals.item_code = inventory_definitions.item_code ORDER BY created_at DESC) ELSE 1 END)") .group("inventory_definitions.item_code") .order("(CASE WHEN sj.balance > 0 THEN MIN(sj.balance) ELSE NULL END )") diff --git a/app/views/reports/stock_check/index.html.erb b/app/views/reports/stock_check/index.html.erb index 574d2946..2235459d 100755 --- a/app/views/reports/stock_check/index.html.erb +++ b/app/views/reports/stock_check/index.html.erb @@ -82,7 +82,7 @@ <% end %> <%= result.stock_count rescue '-' %> - <%= number_with_precision(result.stock_balance, precision:precision.to_i,delimiter:delimiter) rescue '-' %> + <%= result.stock_balance rescue '-' %> <%= result.different rescue '-' %> <%= result.remark rescue '-' %> <%= Employee.find(result.stock_check.check_by).name rescue '-' %> From a704decb836b127625875844b50dab5028824494 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 17 Aug 2018 15:11:43 +0630 Subject: [PATCH 6/9] update readme and delivery status for oqs assign item --- README.md | 3 +++ app/models/order_queue_station.rb | 4 ++-- app/models/sale_payment.rb | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bdaec79e..363d0be3 100755 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index e9cbfd26..2f0b947d 100755 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -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 diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 8b6bb646..97ee07a7 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -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 From dee3c89ad370e2c9b2411e0324306a45ad0c3dab Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 17 Aug 2018 17:57:13 +0630 Subject: [PATCH 7/9] change query and some func: in inv: --- app/controllers/inventory/inventory_controller.rb | 2 +- app/models/inventory_definition.rb | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/controllers/inventory/inventory_controller.rb b/app/controllers/inventory/inventory_controller.rb index 4d6d733c..368ad122 100755 --- a/app/controllers/inventory/inventory_controller.rb +++ b/app/controllers/inventory/inventory_controller.rb @@ -4,7 +4,7 @@ class Inventory::InventoryController < BaseInventoryController 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 balance > 0 + 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 diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb index 6b197bfc..0a73976e 100755 --- a/app/models/inventory_definition.rb +++ b/app/models/inventory_definition.rb @@ -45,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 From 0ca0252fedbbe7a2eea51f11d759e636415d2e3f Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 20 Aug 2018 11:23:47 +0630 Subject: [PATCH 8/9] change text to string for sale_audits migrate --- .gitignore | 1 + db/migrate/20170403174111_create_sale_audits.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index df5bf8ff..80f629c7 100755 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ capybara-*.html /public/uploads/* /public/swf/* /public/receipts/ +/public/orders_* /public/*.mp3 /coverage/ /spec/tmp/* diff --git a/db/migrate/20170403174111_create_sale_audits.rb b/db/migrate/20170403174111_create_sale_audits.rb index 427cd74f..7e7f0b8c 100755 --- a/db/migrate/20170403174111_create_sale_audits.rb +++ b/db/migrate/20170403174111_create_sale_audits.rb @@ -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] From 49fd42722569262f77fc3bb0eed76195fd6cfe9d Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 20 Aug 2018 11:56:47 +0630 Subject: [PATCH 9/9] change inv query --- app/controllers/inventory/inventory_controller.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/controllers/inventory/inventory_controller.rb b/app/controllers/inventory/inventory_controller.rb index 368ad122..e411acea 100755 --- a/app/controllers/inventory/inventory_controller.rb +++ b/app/controllers/inventory/inventory_controller.rb @@ -1,15 +1,13 @@ class Inventory::InventoryController < BaseInventoryController load_and_authorize_resource def index - 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 + least_stock = "SELECT (CASE WHEN stock_journals.remark != '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" + WHERE stock_journals.item_code = inventory_definitions.item_code AND stock_journals.remark != 'out of stock' + ORDER BY stock_journals.created_at DESC LIMIT 1" @inventory_definitions = InventoryDefinition.select("inventory_definitions.*, (CASE WHEN sj.credit IS NULL THEN 0 ELSE sj.credit END) as credit,