'
+ oos_header = ''
+ }
row = '
'
- +'
'
+ + oos_item + oos_header
+'
'
+'
';
+
}
$('.menu_items_list').append(row);
diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js
index 4984e371..f3182394 100755
--- a/app/assets/javascripts/origami.js
+++ b/app/assets/javascripts/origami.js
@@ -63,7 +63,7 @@ $(document).on('turbolinks:load', function() {
'

\n' +
'
\n',
}
- });
+ });
$('.datetimepicker').bootstrapMaterialDatePicker({
format: 'DD-MM-YYYY - HH:mm',
@@ -128,11 +128,11 @@ $(document).on('turbolinks:load', function() {
type: "POST",
url: "/origami/" + unique_id,
data: { 'booking_id' : unique_id },
- success:function(result){
+ success:function(result){
for (i = 0; i < result.length; i++) {
var data = JSON.stringify(result[i]);
var parse_data = JSON.parse(data);
- var show_date = "";
+ var show_date = "";
// Receipt Header
receipt_no = result[i].receipt_no;
@@ -140,14 +140,14 @@ $(document).on('turbolinks:load', function() {
if(result[i].receipt_date != null){
receipt_date = new Date(result[i].receipt_date);
show_date = receipt_date.getDate() + "-" + receipt_date.getMonth() + "-" + receipt_date.getFullYear() + ' ' + receipt_date.getHours()+ ':' + receipt_date.getMinutes()
- }
+ }
//Receipt Charges
sub_total += parseFloat(parse_data.price);
discount_amount = parse_data.discount_amount == null? '0.0' : parse_data.discount_amount;
tax_amount = parse_data.tax_amount;
- grand_total_amount = parse_data.grand_total_amount;
+ grand_total_amount = parse_data.grand_total_amount;
// Ordered Items
var order_items_rows = "
" +
@@ -234,7 +234,7 @@ $(document).on('turbolinks:load', function() {
window.location.href = "/origami/cashier/credit_sales/"+sale_id;
}else{
window.location.href = "/origami/quick_service/credit_sales/"+sale_id;
- }
+ }
});
});
@@ -385,7 +385,7 @@ function resCardSaleTrans(card_sale_trans_id,cmd_type,payment_type, bnk_bill_amo
}else{
payment_type = "Master";
}
-
+
$("#loading_wrapper").hide();
swal({
title: 'Oops',
@@ -512,7 +512,7 @@ if (!String.prototype.formatUnicorn) {
}
var t=typeof arguments[0],n="string"==t||"number"==t?Array.prototype.slice.call(arguments):arguments[0];
for(var i in n){
- e=e.replace(new RegExp("\\{"+i+"\\}","gi"),n[i]==null?'':n[i]);
+ e=e.replace(new RegExp("\\{"+i+"\\}","gi"),n[i]==null?'':n[i]);
}
return e;
};
@@ -523,7 +523,7 @@ if (!String.prototype.formatUnicorn) {
function timeFormat(date){
var isPM = date.getHours() >= 12;
var isMidday = date.getHours() == 12;
- var time = [(date.getHours()>10? date.getHours() : '0'+date.getHours()) - (isPM && !isMidday ? 12 : 0),
+ var time = [(date.getHours()>10? date.getHours() : '0'+date.getHours()) - (isPM && !isMidday ? 12 : 0),
(date.getMinutes()>10? date.getMinutes() : '0'+date.getMinutes()) || '00'].join(':') +
(isPM ? ' PM' : ' AM');
return time;
@@ -589,4 +589,4 @@ function getCreditSales(filter, customer, cashier_type){
}
});
}
-//End of credit sales function
\ No newline at end of file
+//End of credit sales function
diff --git a/app/controllers/api/restaurant/out_of_stock_controller.rb b/app/controllers/api/restaurant/out_of_stock_controller.rb
new file mode 100644
index 00000000..f05ed3bd
--- /dev/null
+++ b/app/controllers/api/restaurant/out_of_stock_controller.rb
@@ -0,0 +1,8 @@
+class Api::Restaurant::OutOfStockController < Api::ApiController
+ skip_before_action :authenticate
+
+ def index
+ date = params[:date]
+ @out_of_stock = OutOfStock.where("DATE(date) = ?", date)
+ end
+end
diff --git a/app/controllers/settings/out_of_stock_controller.rb b/app/controllers/settings/out_of_stock_controller.rb
new file mode 100644
index 00000000..303a3f7f
--- /dev/null
+++ b/app/controllers/settings/out_of_stock_controller.rb
@@ -0,0 +1,64 @@
+class Settings::OutOfStockController < ApplicationController
+ def index
+ @menu_items = MenuItem.joins(:menu_item_instances).where(menu_item_instances: {is_out_of_stock: true}).select('menu_item_instances.id, menu_item_instances.item_instance_code, menu_items.name, menu_item_instances.is_out_of_stock')
+ end
+
+ def show
+ end
+
+ def new
+ @menus = Menu.where("shop_code='#{@shop.shop_code}'").order('created_at asc')
+ @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc')
+ end
+
+ def update
+ items_arr = []
+ JSON.parse(params[:item_instance_code]).each { |i|
+ i["item_instance_code"] = i["item_instance_code"].downcase.to_s
+ items = i["item_instance_code"]
+ items_arr.push(items)
+ }
+
+ item_instance = MenuItemInstance.where(item_instance_code: [items_arr])
+ date = DateTime.now
+
+ unless item_instance.nil?
+ item_instance.each do |i|
+ if i.is_out_of_stock.nil?
+ item_instance.update(is_out_of_stock: true)
+ OutOfStock.create_out_of_stock(date,params[:item_code])
+ elsif i.is_out_of_stock?
+ item_instance.update(is_out_of_stock: false)
+ elsif !i.is_out_of_stock?
+ item_instance.update(is_out_of_stock: true)
+ OutOfStock.create_out_of_stock(date,params[:item_code])
+ end
+ end
+ end
+
+ result = {:status=> true, :message => "Out of Stock was created successfully",:data=> item_instance}
+ render :json => result.to_json
+ end
+
+ def destroy
+ item_instance = MenuItemInstance.find_by_id(params[:id])
+ unless item_instance.nil?
+ item_instance.update(is_out_of_stock: false)
+ flash[:message] = 'Out of stock was successfully destroyed.'
+ render :json => {:status=> "Success", :url => settings_out_of_stock_index_url }.to_json
+ end
+ end
+
+ def reset_all
+ item_instance = MenuItemInstance.where(is_out_of_stock: true)
+ item_instance.update(is_out_of_stock: false)
+ flash[:message] = 'Out of stock was successfully destroyed.'
+ render :json => {:status=> "Success", :url => settings_out_of_stock_index_url }.to_json
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_menu_item_instance
+ @item_instance = MenuItemInstance.find_by_item_instance_code(params[:item_code])
+ end
+end
diff --git a/app/models/out_of_stock.rb b/app/models/out_of_stock.rb
new file mode 100644
index 00000000..e3d65fc8
--- /dev/null
+++ b/app/models/out_of_stock.rb
@@ -0,0 +1,8 @@
+class OutOfStock < ApplicationRecord
+ def self.create_out_of_stock(date,item_instance_code)
+ OutOfStock.create(
+ date: date,
+ item_instance_code: item_instance_code
+ )
+ end
+end
diff --git a/app/views/api/restaurant/menu/_menu_item.json.jbuilder b/app/views/api/restaurant/menu/_menu_item.json.jbuilder
index c6cc8468..e8cecca6 100755
--- a/app/views/api/restaurant/menu/_menu_item.json.jbuilder
+++ b/app/views/api/restaurant/menu/_menu_item.json.jbuilder
@@ -1,9 +1,9 @@
# Format for attributes json
attr_format = []
-# Format for attributes json
+# Format for attributes json
if item.is_available
- if item.item_attributes.count > 0
- item.item_attributes.each do|attr_id|
+ if item.item_attributes.count > 0
+ item.item_attributes.each do|attr_id|
menu_attr = MenuItemAttribute.find(attr_id)
if attr_format.count == 0
attr_format.push({ type: menu_attr.attribute_type, values: [menu_attr.name] })
@@ -15,20 +15,20 @@ if item.is_available
if menu_attr.attribute_type == af[:type]
af[:values].push(menu_attr.name)
end
- else
+ else
new_attr = {type: menu_attr.attribute_type, values: [ menu_attr.name ] }
- attr_format.push(new_attr)
- break
- end
+ attr_format.push(new_attr)
+ break
+ end
end
end
end
# Format for option json
opt_format = []
- # Format for attributes json
- if item.item_options.count > 0
- item.item_options.each do|opt|
+ # Format for attributes json
+ if item.item_options.count > 0
+ item.item_options.each do|opt|
menu_opt = MenuItemOption.find(opt)
if opt_format.count == 0
opt_format.push({ type: menu_opt.option_type, values: [menu_opt.name] })
@@ -40,12 +40,12 @@ if item.is_available
if menu_opt.option_type == of[:type]
of[:values].push(menu_opt.name)
end
- else
+ else
new_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] }
- opt_format.push(new_opt)
+ opt_format.push(new_opt)
break
end
- end
+ end
end
end
@@ -68,7 +68,7 @@ if item.is_available
json.is_sub_item item.is_sub_item
json.unit item.unit
- # Item Sets of Menu Item
+ # Item Sets of Menu Item
json.item_sets item.item_sets do |its|
json.id its.id
json.name its.name
@@ -78,7 +78,7 @@ if item.is_available
json.instances its.menu_item_instances do |i|
json.id i.id
end
- end
+ end
json.attributes attr_format
json.options opt_format
@@ -105,7 +105,7 @@ if item.is_available
mItemAttr = MenuItemAttribute.find(ia).name
instance_attr.push(mItemAttr)
end
-
+
json.id is.id
json.code is.item_instance_code
json.name is.item_instance_name
@@ -115,6 +115,7 @@ if item.is_available
json.is_on_promotion is.is_on_promotion
json.promotion_price is.promotion_price
json.values instance_attr
+ json.out_of_stock is.is_out_of_stock
# json.item_sets is.item_sets
end
end
@@ -125,4 +126,4 @@ if item.is_available
# json.partial! 'api/restaurant/menu/menu_item', item: item
# end
# end
-end
\ No newline at end of file
+end
diff --git a/app/views/api/restaurant/out_of_stock/index.json.jbuilder b/app/views/api/restaurant/out_of_stock/index.json.jbuilder
new file mode 100644
index 00000000..997f83e8
--- /dev/null
+++ b/app/views/api/restaurant/out_of_stock/index.json.jbuilder
@@ -0,0 +1,4 @@
+out_of_stock_json = json.array! @out_of_stock do |oos|
+ json.date oos.date
+ json.item_instance_code oos.item_instance_code
+end
diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb
index 1dbb3b98..56c72052 100644
--- a/app/views/layouts/_left_sidebar.html.erb
+++ b/app/views/layouts/_left_sidebar.html.erb
@@ -371,6 +371,12 @@
<% end %>
+
+
+ donut_large
+ <%= t :out_of_stock %>
+
+
<% if can? :menage, Employee %>
diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb
index e7abb58b..b07c8347 100644
--- a/app/views/origami/addorders/detail.html.erb
+++ b/app/views/origami/addorders/detail.html.erb
@@ -122,20 +122,20 @@
<% else %>
<% if @table.get_current_checkout_booking.nil? %>
<% if !menu.code.include? "SPL" %>
-
+
<% end%>
<% end %>
diff --git a/app/views/origami/dashboard/_menu.json.jbuilder b/app/views/origami/dashboard/_menu.json.jbuilder
index 372d521c..19b05aa5 100644
--- a/app/views/origami/dashboard/_menu.json.jbuilder
+++ b/app/views/origami/dashboard/_menu.json.jbuilder
@@ -95,6 +95,7 @@ if (menu.menu_categories)
json.is_default is.is_default
json.is_on_promotion is.is_on_promotion
json.promotion_price is.promotion_price
+ json.out_of_stock is.is_out_of_stock
json.values instance_attr
end
end
diff --git a/app/views/settings/out_of_stock/_form.html.erb b/app/views/settings/out_of_stock/_form.html.erb
new file mode 100644
index 00000000..794b0e57
--- /dev/null
+++ b/app/views/settings/out_of_stock/_form.html.erb
@@ -0,0 +1,742 @@
+<%= stylesheet_link_tag 'addorder', media: 'all', 'data-turbolinks-track': 'reload' %>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | # |
+ Items |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/views/settings/out_of_stock/_out_of_stock_list.html.erb b/app/views/settings/out_of_stock/_out_of_stock_list.html.erb
new file mode 100644
index 00000000..802c5a3b
--- /dev/null
+++ b/app/views/settings/out_of_stock/_out_of_stock_list.html.erb
@@ -0,0 +1,73 @@
+
+
+ | <%= t("views.right_panel.detail.product") %> |
+ <%= t("views.right_panel.detail.status") %> |
+ <%= t("views.right_panel.detail.action") %> |
+
+
+ <% cate_arr = Array.new %>
+ <%
+ count = 0
+ @menu_items.each do |item|
+ count += 1
+ %>
+
+
+ | <%= item.name rescue '-' %> |
+
+ <% if item.is_out_of_stock %>
+ Active
+ <% else %>
+ Inactive
+ <% end %>
+ |
+
+
+
+ Are you sure you want to delete this row ?
+ This action can't be undo.
+
+ |
+
+ <% end %>
+
+
+
diff --git a/app/views/settings/out_of_stock/index.html.erb b/app/views/settings/out_of_stock/index.html.erb
new file mode 100644
index 00000000..758a52a9
--- /dev/null
+++ b/app/views/settings/out_of_stock/index.html.erb
@@ -0,0 +1,45 @@
+
+
+
+
+ <%= form_tag inventory_path, :id => "filter_form", :method => :get do %>
+
+
+
+
+
+
+ <% end %>
+
+
+
+
+
+
+
+
+
+
+ <%= render 'out_of_stock_list' %>
+
+
+
+
+
+
diff --git a/app/views/settings/out_of_stock/new.html.erb b/app/views/settings/out_of_stock/new.html.erb
new file mode 100644
index 00000000..631921de
--- /dev/null
+++ b/app/views/settings/out_of_stock/new.html.erb
@@ -0,0 +1,2 @@
+
+<%= render 'form'%>
diff --git a/config/routes.rb b/config/routes.rb
index 4a13ad5d..b46b73b6 100755
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -57,6 +57,7 @@ scope "(:locale)", locale: /en|mm/ do
resources :menu_item_options, only: [:index]
resources :menu_sold_out, only: [:index]
resources :menu_item_instances, only: [:show]
+ resources :out_of_stock, only: [:index]
get "item_sets" => "item_sets#index"
end
@@ -508,6 +509,9 @@ scope "(:locale)", locale: /en|mm/ do
get '/get_transactions_by_commissioner' => 'commissioners#get_transaction_by_commissioner', as:'get_transaction_by_commissioner'
# get 'menu_item_instances/get_instance/:id' => 'menu_item_instances#get_instance',:as => "show_instance"
+ resources :out_of_stock
+ # post "update_out_of_stock" => 'out_of_stock#update'
+ delete "out_of_stock" => 'out_of_stock#reset_all', as: :reset_all
end
#--------- Transactions Sections ------------#
diff --git a/db/migrate/20191129043601_add_is_out_of_stock_to_menu_item_instaces.rb b/db/migrate/20191129043601_add_is_out_of_stock_to_menu_item_instaces.rb
new file mode 100644
index 00000000..f53ed69b
--- /dev/null
+++ b/db/migrate/20191129043601_add_is_out_of_stock_to_menu_item_instaces.rb
@@ -0,0 +1,5 @@
+class AddIsOutOfStockToMenuItemInstaces < ActiveRecord::Migration[5.1]
+ def change
+ add_column :menu_item_instances, :is_out_of_stock, :boolean
+ end
+end
diff --git a/db/migrate/20191204091822_create_out_of_stocks.rb b/db/migrate/20191204091822_create_out_of_stocks.rb
new file mode 100644
index 00000000..0563e793
--- /dev/null
+++ b/db/migrate/20191204091822_create_out_of_stocks.rb
@@ -0,0 +1,10 @@
+class CreateOutOfStocks < ActiveRecord::Migration[5.1]
+ def change
+ create_table :out_of_stocks do |t|
+ t.datetime :date
+ t.string :item_instance_code
+
+ t.timestamps
+ end
+ end
+end
diff --git a/spec/models/out_of_stock_spec.rb b/spec/models/out_of_stock_spec.rb
new file mode 100644
index 00000000..d352f2ac
--- /dev/null
+++ b/spec/models/out_of_stock_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe OutOfStock, type: :model do
+ pending "add some examples to (or delete) #{__FILE__}"
+end