diff --git a/.idea/.generators b/.idea/.generators
index 16189766..98526fe7 100644
--- a/.idea/.generators
+++ b/.idea/.generators
@@ -5,4 +5,4 @@ You are allowed to:
2. Remove generators
3. Add installed generators
To add new installed generators automatically delete this file and reload the project.
--->
+-->
diff --git a/.idea/sxrestaurant.iml b/.idea/sxrestaurant.iml
index 6c1240f7..53fef9e5 100644
--- a/.idea/sxrestaurant.iml
+++ b/.idea/sxrestaurant.iml
@@ -52,7 +52,6 @@
-
@@ -66,7 +65,6 @@
-
@@ -82,7 +80,7 @@
-
+
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 1c0d6110..5c3fb862 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -3,10 +3,14 @@
-
-
-
+
+
+
+
+
+
+
@@ -21,7 +25,7 @@
-
+
@@ -48,55 +52,76 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -136,14 +161,6 @@
@@ -211,6 +236,7 @@
+
@@ -258,14 +284,22 @@
-
-
+
+
+
+
+
+
+
+
+
+
@@ -297,6 +331,14 @@
+
+
+
+
+
+
+
+
@@ -702,12 +744,12 @@
-
+
-
+
@@ -719,20 +761,19 @@
-
-
+
-
+
-
+
-
+
-
+
@@ -750,80 +791,11 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -970,14 +942,6 @@
-
-
-
-
-
-
-
-
@@ -994,14 +958,6 @@
-
-
-
-
-
-
-
-
@@ -1079,7 +1035,7 @@
-
+
@@ -1097,31 +1053,11 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1130,14 +1066,6 @@
-
-
-
-
-
-
-
-
@@ -1162,5 +1090,126 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Gemfile b/Gemfile
index 91e29a6e..93b245eb 100644
--- a/Gemfile
+++ b/Gemfile
@@ -34,7 +34,7 @@ gem 'simple_form'
gem 'nested_form'
gem 'bootstrap', '~> 4.0.0.alpha3'
gem 'tether-rails'
-gem "font-awesome-rails"
+gem 'font-awesome-rails', '~> 4.7', '>= 4.7.0.2'
gem 'rack-cors'
# image upload
@@ -53,7 +53,6 @@ gem 'to_xls-rails'
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-ui-rails'
-gem 'jquery-datatables-rails', '~> 3.4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
@@ -112,13 +111,8 @@ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'httparty', '~> 0.15.5'
-gem 'momentjs-rails', :git => 'git://github.com/derekprior/momentjs-rails.git'
-gem 'bootstrap-daterangepicker-rails'
-# # gem 'momentjs-rails', '>= 2.9.0'
-# gem 'bootstrap3-datetimepicker-rails'
-# gem 'momentjs-rails', '>= 2.9.0'
-# gem 'bootstrap3-datetimepicker-rails'
-gem 'datetimepicker-rails', github: 'zpaulovics/datetimepicker-rails', branch: 'master', submodules: true
-gem 'bootstrap-datepicker-rails'
+gem 'momentjs-rails' # for date-range selector
+gem 'bootstrap-daterangepicker-rails' # date-range picker
+gem 'bootstrap-datepicker-rails' # date picker
gem 'jquery-datetimepicker-rails'
-gem 'select2-rails'
+gem 'select2-rails' # for multi-select and auto-complete select box
diff --git a/Gemfile.lock b/Gemfile.lock
index b567932e..b2a6e59c 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,19 +1,3 @@
-GIT
- remote: git://github.com/derekprior/momentjs-rails.git
- revision: ea58a20b7b2c901831dd01f34e0054ef6c75bde8
- specs:
- momentjs-rails (2.17.1)
- railties (>= 3.1)
-
-GIT
- remote: https://github.com/zpaulovics/datetimepicker-rails.git
- revision: 36d21cec5da7f5b214925804f60e63c61c747023
- branch: master
- submodules: true
- specs:
- datetimepicker-rails (4.7.16)
- momentjs-rails (>= 2.9.0)
-
GEM
remote: https://rubygems.org/
specs:
@@ -107,11 +91,6 @@ GEM
jbuilder (2.7.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
- jquery-datatables-rails (3.4.0)
- actionpack (>= 3.1)
- jquery-rails
- railties (>= 3.1)
- sass-rails
jquery-datetimepicker-rails (2.4.1.0)
jquery-rails (4.3.1)
rails-dom-testing (>= 1, < 3)
@@ -144,6 +123,8 @@ GEM
mime-types-data (3.2016.0521)
mini_portile2 (2.2.0)
minitest (5.10.3)
+ momentjs-rails (2.17.1)
+ railties (>= 3.1)
multi_json (1.12.1)
multi_xml (0.6.0)
mysql2 (0.4.6)
@@ -286,20 +267,18 @@ DEPENDENCIES
coffee-rails (~> 4.2)
cups (~> 0.0.7)
database_cleaner
- datetimepicker-rails!
factory_girl_rails (~> 4.0)
faker
filterrific
- font-awesome-rails
+ font-awesome-rails (~> 4.7, >= 4.7.0.2)
httparty (~> 0.15.5)
jbuilder (~> 2.5)
- jquery-datatables-rails (~> 3.4.0)
jquery-datetimepicker-rails
jquery-rails
jquery-ui-rails
kaminari (~> 1.0.1)
listen (~> 3.0.5)
- momentjs-rails!
+ momentjs-rails
mysql2 (>= 0.3.18, < 0.5)
nested_form
pg
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 87ca5d6d..b1879bba 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -20,13 +20,10 @@
//= require settings/processing_items
//= require jquery-ui
//= require bootstrap-datepicker
-//= require jquery.datetimepicker
-//= require dataTables/jquery.dataTables
//= require moment
//= require daterangepicker
//= require select2
-//= require bootstrap-datetimepicker
-//= require pickers
+//= require jquery.datetimepicker
$(document).on('turbolinks:load', function() {
diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss
index 1cc201dd..4aabe81b 100644
--- a/app/assets/stylesheets/application.scss
+++ b/app/assets/stylesheets/application.scss
@@ -4,11 +4,9 @@
@import "theme";
@import "jquery-ui";
@import "bootstrap-datepicker3";
-@import "jquery.datetimepicker";
-@import "dataTables/jquery.dataTables";
@import "daterangepicker-bs3";
@import "select2";
-@import "bootstrap-datetimepicker";
+@import "jquery.datetimepicker";
/* Show it is fixed to the top */
// body {
diff --git a/app/controllers/inventory/inventory_controller.rb b/app/controllers/inventory/inventory_controller.rb
index 525f0277..673cf943 100644
--- a/app/controllers/inventory/inventory_controller.rb
+++ b/app/controllers/inventory/inventory_controller.rb
@@ -1,6 +1,6 @@
class Inventory::InventoryController < BaseInventoryController
def index
-
+ @products = InventoryDefinition.all.active.order('created_at desc')
end
end
diff --git a/app/controllers/inventory/inventory_definitions_controller.rb b/app/controllers/inventory/inventory_definitions_controller.rb
index 8a3f3a40..7a8f17e1 100644
--- a/app/controllers/inventory/inventory_definitions_controller.rb
+++ b/app/controllers/inventory/inventory_definitions_controller.rb
@@ -28,7 +28,7 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController
respond_to do |format|
if @inventory_definition.save
- format.html { redirect_to @inventory_definition, notice: 'Inventory definition was successfully created.' }
+ format.html { redirect_to inventory_path, notice: 'Inventory definition was successfully created.' }
format.json { render :show, status: :created, location: @inventory_definition }
else
format.html { render :new }
@@ -69,6 +69,6 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController
# Never trust parameters from the scary internet, only allow the white list through.
def inventory_definition_params
- params.fetch(:inventory_definition, {})
+ params.require(:inventory_definition).permit(:item_code, :min_order_level, :max_stock_level)
end
end
diff --git a/app/controllers/inventory/stock_check_items_controller.rb b/app/controllers/inventory/stock_check_items_controller.rb
index aec48a04..18980f29 100644
--- a/app/controllers/inventory/stock_check_items_controller.rb
+++ b/app/controllers/inventory/stock_check_items_controller.rb
@@ -1,4 +1,4 @@
-class StockCheckItemsController < ApplicationController
+class Inventory::StockCheckItemsController < BaseInventoryController
before_action :set_stock_check_item, only: [:show, :edit, :update, :destroy]
# GET /stock_check_items
@@ -28,7 +28,7 @@ class StockCheckItemsController < ApplicationController
respond_to do |format|
if @stock_check_item.save
- format.html { redirect_to @stock_check_item, notice: 'Stock check item was successfully created.' }
+ format.html { redirect_to inventory_stock_checks_path, notice: 'Stock check item was successfully created.' }
format.json { render :show, status: :created, location: @stock_check_item }
else
format.html { render :new }
@@ -69,6 +69,6 @@ class StockCheckItemsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def stock_check_item_params
- params.fetch(:stock_check_item, {})
+ params.require(:stock_check_item).permit(:item_code, :stock_count)
end
end
diff --git a/app/controllers/inventory/stock_checks_controller.rb b/app/controllers/inventory/stock_checks_controller.rb
index e8620ca1..f161bc25 100644
--- a/app/controllers/inventory/stock_checks_controller.rb
+++ b/app/controllers/inventory/stock_checks_controller.rb
@@ -1,74 +1,98 @@
-class StockChecksController < ApplicationController
- before_action :set_stock_check, only: [:show, :edit, :update, :destroy]
+class Inventory::StockChecksController < BaseInventoryController
+
+ def index
+ @check = StockCheck.new
+ end
+
+ def create
+ item_list = JSON.parse(params[:stock_item])
+ reason = params[:reason]
+ check = StockCheck.new
+ @check = check.create(current_user, reason, item_list)
+ end
+
+ def show
+ @check = StockCheck.find(params[:id])
+ end
+
+ def save_to_journal
+ check = params[:data]
+ stockCheck = StockCheck.find(check)
+ stockCheck.stock_check_items.each do |item|
+ StockJournal.from_stock_check(item)
+ end
+ end
+
+ # before_action :set_stock_check, only: [:show, :edit, :update, :destroy]
# GET /stock_checks
# GET /stock_checks.json
- def index
- @stock_checks = StockCheck.all
- end
-
- # GET /stock_checks/1
- # GET /stock_checks/1.json
- def show
- end
-
- # GET /stock_checks/new
- def new
- @stock_check = StockCheck.new
- end
-
- # GET /stock_checks/1/edit
- def edit
- end
-
- # POST /stock_checks
- # POST /stock_checks.json
- def create
- @stock_check = StockCheck.new(stock_check_params)
-
- respond_to do |format|
- if @stock_check.save
- format.html { redirect_to @stock_check, notice: 'Stock check was successfully created.' }
- format.json { render :show, status: :created, location: @stock_check }
- else
- format.html { render :new }
- format.json { render json: @stock_check.errors, status: :unprocessable_entity }
- end
- end
- end
-
- # PATCH/PUT /stock_checks/1
- # PATCH/PUT /stock_checks/1.json
- def update
- respond_to do |format|
- if @stock_check.update(stock_check_params)
- format.html { redirect_to @stock_check, notice: 'Stock check was successfully updated.' }
- format.json { render :show, status: :ok, location: @stock_check }
- else
- format.html { render :edit }
- format.json { render json: @stock_check.errors, status: :unprocessable_entity }
- end
- end
- end
-
- # DELETE /stock_checks/1
- # DELETE /stock_checks/1.json
- def destroy
- @stock_check.destroy
- respond_to do |format|
- format.html { redirect_to stock_checks_url, notice: 'Stock check was successfully destroyed.' }
- format.json { head :no_content }
- end
- end
-
- private
- # Use callbacks to share common setup or constraints between actions.
- def set_stock_check
- @stock_check = StockCheck.find(params[:id])
- end
-
- # Never trust parameters from the scary internet, only allow the white list through.
- def stock_check_params
- params.fetch(:stock_check, {})
- end
+# def index
+# @stock_checks = StockCheck.all
+# end
+#
+# # GET /stock_checks/1
+# # GET /stock_checks/1.json
+# def show
+# end
+#
+# # GET /stock_checks/new
+# def new
+# @stock_check = StockCheck.new
+# end
+#
+# # GET /stock_checks/1/edit
+# def edit
+# end
+#
+# # POST /stock_checks
+# # POST /stock_checks.json
+# def create
+# @stock_check = StockCheck.new(stock_check_params)
+#
+# respond_to do |format|
+# if @stock_check.save
+# format.html { redirect_to @stock_check, notice: 'Stock check was successfully created.' }
+# format.json { render :show, status: :created, location: @stock_check }
+# else
+# format.html { render :new }
+# format.json { render json: @stock_check.errors, status: :unprocessable_entity }
+# end
+# end
+# end
+#
+# # PATCH/PUT /stock_checks/1
+# # PATCH/PUT /stock_checks/1.json
+# def update
+# respond_to do |format|
+# if @stock_check.update(stock_check_params)
+# format.html { redirect_to @stock_check, notice: 'Stock check was successfully updated.' }
+# format.json { render :show, status: :ok, location: @stock_check }
+# else
+# format.html { render :edit }
+# format.json { render json: @stock_check.errors, status: :unprocessable_entity }
+# end
+# end
+# end
+#
+# # DELETE /stock_checks/1
+# # DELETE /stock_checks/1.json
+# def destroy
+# @stock_check.destroy
+# respond_to do |format|
+# format.html { redirect_to stock_checks_url, notice: 'Stock check was successfully destroyed.' }
+# format.json { head :no_content }
+# end
+# end
+#
+# private
+# # Use callbacks to share common setup or constraints between actions.
+# def set_stock_check
+# @stock_check = StockCheck.find(params[:id])
+# end
+#
+# # Never trust parameters from the scary internet, only allow the white list through.
+# def stock_check_params
+# params.fetch(:stock_check, {})
+# end
end
diff --git a/app/controllers/origami/in_juties_controller.rb b/app/controllers/origami/in_juties_controller.rb
index 5903ace3..ff76d3b1 100644
--- a/app/controllers/origami/in_juties_controller.rb
+++ b/app/controllers/origami/in_juties_controller.rb
@@ -1,5 +1,5 @@
class Origami::InJutiesController < BaseOrigamiController
- before_action :set_in_juty, only: [:show, :edit, :update, :edit_in_juty, :update_for_in_juty , :destroy ,:destroy_in_juty]
+ before_action :set_in_juty, only: %i[show edit update edit_in_juty update_for_in_juty destroy destroy_in_juty]
# GET /in_juties
# GET /in_juties.json
@@ -8,12 +8,12 @@ class Origami::InJutiesController < BaseOrigamiController
end
def index_in_juty
- @juty_in= InJuty.where("dinning_id=?",params[:table_id])
+ @juty_in = InJuty.where('dinning_id=?', params[:table_id])
@table = DiningFacility.find(params[:table_id])
- @in_juty = InJuty.new
+ @in_juty = InJuty.new
@juties_in = Kaminari.paginate_array(@juty_in).page(params[:page]).per(10)
-
end
+
# GET /in_juties/1
# GET /in_juties/1.json
def show
@@ -21,12 +21,15 @@ class Origami::InJutiesController < BaseOrigamiController
# GET /in_juties/new
def new
+ # this one use for new
@in_juty = InJuty.new
+ @table = DiningFacility.find(params[:table_id])
+ @commissioner = @in_juty.commissioner
+ render partial: 'form'
end
# GET /in_juties/1/edit
def edit
-
end
def edit_in_juty
@@ -34,13 +37,15 @@ class Origami::InJutiesController < BaseOrigamiController
@table = DiningFacility.find(params[:table_id])
@commissioner = @in_juty.commissioner
- render json: {in_juty: @in_juty, commissioner: @commissioner}
+ # render json: {in_juty: @in_juty, commissioner: @commissioner}
+ render partial: 'form'
end
def assign_in_juty
@in_juty = InJuty.new
@table = DiningFacility.find(params[:table_id])
end
+
# POST /in_juties
# POST /in_juties.json
def create
@@ -58,32 +63,53 @@ class Origami::InJutiesController < BaseOrigamiController
end
def create_for_in_juty
+ # this one use for create and update
+ in_juty = in_juty_params
+ in_time = DateTime.new in_juty['in_time(1i)'].to_i, in_juty['in_time(2i)'].to_i, in_juty['in_time(3i)'].to_i, in_juty['in_time(4i)'].to_i, in_juty['in_time(5i)'].to_i
+ in_time = in_time.change(offset: '+06:30')
+ out_time = DateTime.new in_juty['out_time(1i)'].to_i, in_juty['out_time(2i)'].to_i, in_juty['out_time(3i)'].to_i, in_juty['out_time(4i)'].to_i, in_juty['out_time(5i)'].to_i
+ out_time = out_time.change(offset: '+06:30')
@in_juty = InJuty.new
+ in_juty_id = in_juty[:id]
+ unless in_juty_id.nil?
+ @in_juty = InJuty.find(in_juty_id.to_i)
+ end
- @in_juty.dinning_id = in_juty_params[:dinning_id]
- @in_juty.commissioner_ids = in_juty_params[:commissioner_ids]
- @in_juty.in_time = in_juty_params[:in_time]
- @in_juty.out_time = in_juty_params[:out_time]
-
+ @in_juty.dinning_id = in_juty_params[:dinning_id]
+ @in_juty.commissioner_ids = in_juty_params[:commissioner_ids]
+ @in_juty.in_time = in_time
+ @in_juty.out_time = out_time
respond_to do |format|
if @in_juty.save
- format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully created.' }
- format.json { render :show, status: :created, location: @in_juty }
+ if in_juty_id.nil?
+ format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully created.' }
+ format.json { render :show, status: :created, location: @in_juty }
+ else
+ format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully updated.' }
+ format.json { render :show, status: :created, location: @in_juty }
+ end
else
format.html { render :new }
format.json { render json: @in_juty.errors, status: :unprocessable_entity }
end
end
-
end
# PATCH/PUT /in_juties/1
# PATCH/PUT /in_juties/1.json
def update
+ in_juty = in_juty_params
+ in_time = DateTime.new in_juty['in_time(1i)'].to_i, in_juty['in_time(2i)'].to_i, in_juty['in_time(3i)'].to_i, in_juty['in_time(4i)'].to_i, in_juty['in_time(5i)'].to_i
+ in_time = in_time.change(offset: '+06:30')
+ out_time = DateTime.new in_juty['out_time(1i)'].to_i, in_juty['out_time(2i)'].to_i, in_juty['out_time(3i)'].to_i, in_juty['out_time(4i)'].to_i, in_juty['out_time(5i)'].to_i
+ out_time = out_time.change(offset: '+06:30')
+ @in_juty.commissioner_ids = in_juty_params[:commissioner_ids]
+ @in_juty.in_time = in_time
+ @in_juty.out_time = out_time
respond_to do |format|
- if @in_juty.update(in_juty_params)
- format.html { redirect_to origami_in_juty_path(@in_juty), notice: 'In juty was successfully updated.' }
+ if @in_juty.save
+ format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully updated.' }
format.json { render :show, status: :ok, location: @in_juty }
else
format.html { render :edit }
@@ -92,28 +118,32 @@ class Origami::InJutiesController < BaseOrigamiController
end
end
-
- def update_for_in_juty
- @in_juty.commissioner_ids = in_juty_params[:commissioner_ids]
- @in_juty.in_time = in_juty_params[:in_time]
- @in_juty.out_time = in_juty_params[:out_time]
- respond_to do |format|
- if @in_juty.save
- format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully updated.' }
- format.json { render :show, status: :ok, location: @in_juty }
- else
- format.html { render :edit }
- format.json { render json: @in_juty.errors, status: :unprocessable_entity }
- end
- end
+ def update_for_in_juty
+ in_juty = in_juty_params
+ in_time = DateTime.new in_juty['in_time(1i)'].to_i, in_juty['in_time(2i)'].to_i, in_juty['in_time(3i)'].to_i, in_juty['in_time(4i)'].to_i, in_juty['in_time(5i)'].to_i
+ in_time = in_time.change(offset: '+06:30')
+ out_time = DateTime.new in_juty['out_time(1i)'].to_i, in_juty['out_time(2i)'].to_i, in_juty['out_time(3i)'].to_i, in_juty['out_time(4i)'].to_i, in_juty['out_time(5i)'].to_i
+ out_time = out_time.change(offset: '+06:30')
+ @in_juty.commissioner_ids = in_juty_params[:commissioner_ids]
+ @in_juty.in_time = in_time
+ @in_juty.out_time = out_time
+ respond_to do |format|
+ if @in_juty.save
+ format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully updated.' }
+ format.json { render :show, status: :ok, location: @in_juty }
+ else
+ format.html { render :edit }
+ format.json { render json: @in_juty.errors, status: :unprocessable_entity }
+ end
end
+ end
# DELETE /in_juties/1
# DELETE /in_juties/1.json
def destroy
@in_juty.destroy
respond_to do |format|
- format.html { redirect_to origami_in_juties_path, notice: 'In juty was successfully destroyed.' }
+ format.html { redirect_to origami_in_juties_path, notice: 'In juty was successfully removed.' }
format.json { head :no_content }
end
end
@@ -121,21 +151,22 @@ class Origami::InJutiesController < BaseOrigamiController
def destroy_in_juty
@table_id = params[:table_id]
@in_juty.destroy
-
+
respond_to do |format|
- format.html { redirect_to origami_index_in_juty_path(@table_id), notice: 'In juty was successfully destroyed.' }
+ format.html { redirect_to origami_index_in_juty_path(@table_id), notice: 'In juty was successfully removed.' }
format.json { head :no_content }
end
end
private
- # Use callbacks to share common setup or constraints between actions.
- def set_in_juty
- @in_juty = InJuty.find(params[:id])
- end
- # Never trust parameters from the scary internet, only allow the white list through.
- def in_juty_params
- params.require(:in_juty).permit(:id,:dinning_id,:commissioner_ids,:in_time,:out_time)
- end
+ # Use callbacks to share common setup or constraints between actions.
+ def set_in_juty
+ @in_juty = InJuty.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def in_juty_params
+ params.require(:in_juty).permit(:id, :dinning_id, :commissioner_ids, :in_time, :out_time)
+ end
end
diff --git a/app/jobs/inventory_job.rb b/app/jobs/inventory_job.rb
new file mode 100644
index 00000000..a47dd362
--- /dev/null
+++ b/app/jobs/inventory_job.rb
@@ -0,0 +1,9 @@
+class InventoryJob < ApplicationJob
+ queue_as :default
+
+ def perform(sale_id)
+ saleObj = Sale.find(sale_id)
+ InventoryDefinition.calculate_product_count(saleObj)
+ end
+
+end
diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb
index 150ae6a9..91823068 100644
--- a/app/models/inventory_definition.rb
+++ b/app/models/inventory_definition.rb
@@ -1,2 +1,41 @@
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)
+ end
+ end
+ end
+
+ def self.find_product_in_inventory(item)
+ product = InventoryDefinition.find_by_item_code(item.product_code)
+ if product.nil?
+ return false, nil
+ else
+ return true, product
+ end
+ end
+
+ def self.check_balance(item,inventory_definition) # item => saleItemOBj
+ stock = StockJournal.where('item_code=?', item.product_code).order('created_at desc').take
+ unless stock.nil?
+ modify_balance(item, stock, inventory_definition)
+ else
+ StockJournal.add_to_journal(item, 0, "out of stock", inventory_definition)
+ end
+ end
+
+ def self.modify_balance(item, stock, inventory_definition) #saleitemObj
+ if stock.balance.to_i >= item.qty
+ puts ">> stock is greater than orde 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)
+ end
+ end
end
diff --git a/app/models/sale.rb b/app/models/sale.rb
index 79948d1b..6eec518f 100644
--- a/app/models/sale.rb
+++ b/app/models/sale.rb
@@ -118,6 +118,8 @@ class Sale < ApplicationRecord
create_saleitem_diningcharges(charges, diningprice, booking.dining_facility.name, dining_time)
end
+ InventoryJob.perform_now(self.id)
+
return true, self.id
end
diff --git a/app/models/stock_check.rb b/app/models/stock_check.rb
index 71eaef79..7a8f8d65 100644
--- a/app/models/stock_check.rb
+++ b/app/models/stock_check.rb
@@ -1,2 +1,17 @@
class StockCheck < ApplicationRecord
+
+ has_many :stock_check_items
+
+ def create(user, eason, item_list)
+ self.reason = reason
+ self.check_by = user.id
+ self.check_start = Time.now
+ self.check_end = Time.now
+ self.save
+ item_list.each do |item|
+ stockItem = StockCheckItem.new
+ stockItem.create(self.id,item)
+ end
+ return self
+ end
end
diff --git a/app/models/stock_check_item.rb b/app/models/stock_check_item.rb
index 2cbb0e22..e02972a6 100644
--- a/app/models/stock_check_item.rb
+++ b/app/models/stock_check_item.rb
@@ -1,2 +1,36 @@
class StockCheckItem < ApplicationRecord
+
+ belongs_to :stock_check
+
+ def create(stock_id, item)
+ journal_id, balance = StockCheckItem.find_journal(item['sku'])
+ remark, different = StockCheckItem.stock_different(item['qty'], balance )
+ self.stock_check_id = stock_id
+ self.item_code = item['sku']
+ self.stock_count = item['qty']
+ self.stock_journal_id = journal_id
+ self.stock_balance = balance
+ self.different = different
+ self.remark = remark
+ self.save
+ end
+
+ def self.find_journal(item_code)
+ journal = StockJournal.where('item_code=?', item_code).order('created_at desc').take
+ if journal
+ return journal.id, journal.balance
+ else
+ return nil, 0
+ end
+ end
+
+ def self.stock_different(stock_check_qty, journal_balance)
+ if stock_check_qty.to_i == journal_balance.to_i
+ return 'match', stock_check_qty
+ elsif stock_check_qty.to_i > journal_balance.to_i
+ return 'missing order item', stock_check_qty.to_i - journal_balance.to_i
+ elsif stock_check_qty.to_i < journal_balance.to_i
+ return 'missing stock', stock_check_qty.to_i - journal_balance.to_i
+ end
+ end
end
diff --git a/app/models/stock_journal.rb b/app/models/stock_journal.rb
index ee6efe79..22dceaa5 100644
--- a/app/models/stock_journal.rb
+++ b/app/models/stock_journal.rb
@@ -1,2 +1,39 @@
class StockJournal < ApplicationRecord
+
+ SALES_TRANS = "sale"
+ STOCK_CHECK_TRANS = "stock_check"
+
+ def self.add_to_journal(item, balance, stock_message, inventory_definition) # item => saleObj | balance => Stock journal
+
+ balance = calculate_balance(balance, item.qty)
+
+ journal = StockJournal.new
+ journal.item_code = item.product_code
+ journal.inventory_definition_id = inventory_definition.id
+ journal.debit = item.qty
+ journal.balance = balance
+ journal.remark = stock_message
+ journal.trans_ref = item.id
+ journal.trans_type = StockJournal::SALES_TRANS
+ journal.save
+ end
+
+ def self.calculate_balance(balance, qty)
+ return balance.to_i - qty.to_i
+ end
+
+ def self.from_stock_check(item)
+ definition_id = InventoryDefinition.find_by_item_code(item.item_code)
+ journal = StockJournal.new
+ journal.item_code = item.item_code
+ journal.inventory_definition_id = definition_id.id
+ journal.debit = 0
+ journal.credit = item.stock_count
+ journal.balance = item.stock_count
+ journal.remark = StockJournal::STOCK_CHECK_TRANS
+ journal.trans_ref = item.id
+ journal.trans_type = StockJournal::STOCK_CHECK_TRANS
+ journal.save
+ end
+
end
diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb
index 8a922573..83874328 100644
--- a/app/views/home/dashboard.html.erb
+++ b/app/views/home/dashboard.html.erb
@@ -58,7 +58,7 @@
-
+
Inventory
diff --git a/app/views/inventory/inventory/_inventory_list.html.erb b/app/views/inventory/inventory/_inventory_list.html.erb
new file mode 100644
index 00000000..115c80c5
--- /dev/null
+++ b/app/views/inventory/inventory/_inventory_list.html.erb
@@ -0,0 +1,40 @@
+
+
+
Inventoy Product Lists
+
+
+
+
+
+
+
+ | # |
+ Product |
+ Min Order |
+ Max Stock |
+ Created by |
+ Created Time |
+
+ <%
+ count = 0
+ @products.each do |item|
+ count += 1
+ %>
+
+ | <%= count %> |
+ <%= item.item_code rescue ""%> |
+ <%= item.min_order_level %> |
+ <%= item.max_stock_level %> |
+ <%= item.created_by%> |
+ <%= item.created_at%> |
+
+ <% end %>
+
+
+
+
+
diff --git a/app/views/inventory/inventory/index.html.erb b/app/views/inventory/inventory/index.html.erb
index e8826240..7aeb4464 100644
--- a/app/views/inventory/inventory/index.html.erb
+++ b/app/views/inventory/inventory/index.html.erb
@@ -1,17 +1,22 @@
-# Hello Inventory
-
-
+
+
+ <%= render 'inventory_list' %>
-
-
-
-
-
+
<%if current_login_employee.role == "administrator" || current_login_employee.role == "manager" %>
-
+
<%end%>
-
+
+
+
+
diff --git a/app/views/inventory/inventory_definitions/_form.html.erb b/app/views/inventory/inventory_definitions/_form.html.erb
index 4c716bac..36b80822 100644
--- a/app/views/inventory/inventory_definitions/_form.html.erb
+++ b/app/views/inventory/inventory_definitions/_form.html.erb
@@ -1,10 +1,15 @@
-<%= simple_form_for(@inventory_definition) do |f| %>
+
+<%= simple_form_for([:inventory,@inventory_definition]) do |f| %>
<%= f.error_notification %>
+ <%= f.input :item_code %>
+ <%= f.input :min_order_level %>
+ <%= f.input :max_stock_level %>
<%= f.button :submit %>
+
<% end %>
diff --git a/app/views/inventory/inventory_definitions/new.html.erb b/app/views/inventory/inventory_definitions/new.html.erb
index a67b973a..ce290607 100644
--- a/app/views/inventory/inventory_definitions/new.html.erb
+++ b/app/views/inventory/inventory_definitions/new.html.erb
@@ -1,5 +1,11 @@
-
New Inventory Definition
-<%= render 'form', inventory_definition: @inventory_definition %>
-
-<%= link_to 'Back', inventory_definitions_path %>
+
+
+ <%= render 'form', inventory: @inventory_definition %>
+
diff --git a/app/views/inventory/stock_checks/_form.html.erb b/app/views/inventory/stock_checks/_form.html.erb
deleted file mode 100644
index b6bb2ae5..00000000
--- a/app/views/inventory/stock_checks/_form.html.erb
+++ /dev/null
@@ -1,10 +0,0 @@
-<%= simple_form_for(@stock_check) do |f| %>
- <%= f.error_notification %>
-
-
-
-
-
- <%= f.button :submit %>
-
-<% end %>
diff --git a/app/views/inventory/stock_checks/_stock_check.json.jbuilder b/app/views/inventory/stock_checks/_stock_check.json.jbuilder
deleted file mode 100644
index 10634ca9..00000000
--- a/app/views/inventory/stock_checks/_stock_check.json.jbuilder
+++ /dev/null
@@ -1,2 +0,0 @@
-json.extract! stock_check, :id, :created_at, :updated_at
-json.url stock_check_url(stock_check, format: :json)
diff --git a/app/views/inventory/stock_checks/create.json.jbuilder b/app/views/inventory/stock_checks/create.json.jbuilder
new file mode 100644
index 00000000..38bcb274
--- /dev/null
+++ b/app/views/inventory/stock_checks/create.json.jbuilder
@@ -0,0 +1 @@
+json.stock_id @check.id
diff --git a/app/views/inventory/stock_checks/edit.html.erb b/app/views/inventory/stock_checks/edit.html.erb
deleted file mode 100644
index aa821705..00000000
--- a/app/views/inventory/stock_checks/edit.html.erb
+++ /dev/null
@@ -1,6 +0,0 @@
-
Editing Stock Check
-
-<%= render 'form', stock_check: @stock_check %>
-
-<%= link_to 'Show', @stock_check %> |
-<%= link_to 'Back', stock_checks_path %>
diff --git a/app/views/inventory/stock_checks/index.html.erb b/app/views/inventory/stock_checks/index.html.erb
index 05b802eb..812d4409 100644
--- a/app/views/inventory/stock_checks/index.html.erb
+++ b/app/views/inventory/stock_checks/index.html.erb
@@ -1,25 +1,102 @@
-
<%= notice %>
+
+
-
-
-
- |
-
-
+
+
+
+
+
+ | # |
+ Product |
+ Balance |
+
+
+
+
+
+
+
-
- <% @stock_checks.each do |stock_check| %>
-
- | <%= link_to 'Show', stock_check %> |
- <%= link_to 'Edit', edit_stock_check_path(stock_check) %> |
- <%= link_to 'Destroy', stock_check, method: :delete, data: { confirm: 'Are you sure?' } %> |
-
- <% end %>
-
-
+
diff --git a/app/views/inventory/stock_checks/index.json.jbuilder b/app/views/inventory/stock_checks/index.json.jbuilder
deleted file mode 100644
index 23740183..00000000
--- a/app/views/inventory/stock_checks/index.json.jbuilder
+++ /dev/null
@@ -1 +0,0 @@
-json.array! @stock_checks, partial: 'stock_checks/stock_check', as: :stock_check
diff --git a/app/views/inventory/stock_checks/new.html.erb b/app/views/inventory/stock_checks/new.html.erb
deleted file mode 100644
index 503af621..00000000
--- a/app/views/inventory/stock_checks/new.html.erb
+++ /dev/null
@@ -1,5 +0,0 @@
-
New Stock Check
-
-<%= render 'form', stock_check: @stock_check %>
-
-<%= link_to 'Back', stock_checks_path %>
diff --git a/app/views/inventory/stock_checks/show.html.erb b/app/views/inventory/stock_checks/show.html.erb
index 6c306d8d..09ff16b5 100644
--- a/app/views/inventory/stock_checks/show.html.erb
+++ b/app/views/inventory/stock_checks/show.html.erb
@@ -1,4 +1,74 @@
-
<%= notice %>
+
+
+
+
+
+ Check by
+
+
+ <%= @check.check_by %>
+
+
+
+
+ Check At
+
+
+ <%= @check.created_at %>
+
+
+
+ Reason
+
+
+ <%= @check.reason %>
+
+
+
+
+
+
+ | # |
+ Product |
+ Stock Count |
+ Stock Balance |
+ Different |
+ Remark |
+
+ <%
+ count = 0
+ @check.stock_check_items.each do |item|
+ count += 1
+ %>
+
+ | <%= count %> |
+ <%= item.item_code %> |
+ <%= item.stock_count %> |
+ <%= item.stock_balance %> |
+ <%= item.different %> |
+ <%= item.remark %> |
+
+ <% end %>
+
+
+
+
+
+
+
+
+
-<%= link_to 'Edit', edit_stock_check_path(@stock_check) %> |
-<%= link_to 'Back', stock_checks_path %>
+
diff --git a/app/views/inventory/stock_checks/show.json.jbuilder b/app/views/inventory/stock_checks/show.json.jbuilder
deleted file mode 100644
index 1a4ad710..00000000
--- a/app/views/inventory/stock_checks/show.json.jbuilder
+++ /dev/null
@@ -1 +0,0 @@
-json.partial! "stock_checks/stock_check", stock_check: @stock_check
diff --git a/app/views/layouts/inventory.html.erb b/app/views/layouts/inventory.html.erb
index 5bcf7e0a..d6bbf436 100644
--- a/app/views/layouts/inventory.html.erb
+++ b/app/views/layouts/inventory.html.erb
@@ -9,7 +9,7 @@
SmartSales : Restaurant
<%= csrf_meta_tags %>
- <%= stylesheet_link_tag 'inventory', media: 'all', 'data-turbolinks-track': 'reload' %>
+ <%= stylesheet_link_tag 'origami', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_link_tag 'jquery-confirm', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'jquery-confirm', 'data-turbolinks-track': 'reload' %>
diff --git a/app/views/origami/in_juties/_assign_in_juty.html.erb b/app/views/origami/in_juties/_assign_in_juty.html.erb
index 81af7d29..b6363195 100644
--- a/app/views/origami/in_juties/_assign_in_juty.html.erb
+++ b/app/views/origami/in_juties/_assign_in_juty.html.erb
@@ -1,46 +1,43 @@
-<%= simple_form_for @in_juty,:url => origami_index_in_juty_path(@table.id), :method => :post do |f| %>
-
- <%= f.error_notification %>
- <%= f.hidden_field :id, :class => "form-control col-md-6 " %>
-
-
+<%= simple_form_for @in_juty, :url => origami_index_in_juty_path(@table.id), :method => :post do |f| %>
+
+ <%= f.error_notification %>
+ <%= f.hidden_field :id, :class => "form-control col-md-6 " %>
- <%= f.hidden_field :dinning_id,:value => @table.id, :class => "form-control col-md-6 " %>
+
+
+ <%= f.hidden_field :dinning_id, :value => @table.id, :class => "form-control col-md-4 " %>
+
+
+ <%= @table.name %>
+
+
+
+
+ <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %>
+
+
+ <%= f.input :in_time, :placeholder => "From Date", :class => "form-control" %>
+
+ <%= f.input :out_time, :placeholder => "To Date", :class => "form-control" %>
+
+
+
+
+ <%= f.button :submit, "Create", :class => 'btn btn-primary ', :id => 'create' %>
+ <%= f.button :submit, "Update", :class => 'btn btn-primary ', :disabled => '', :id => 'update' %>
+ <%= f.button :button, "Reset", :class => 'btn btn-danger ', :id => 'reset' %>
+
-
- <%= @table.name %>
-
-
-
-
- <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %>
-
- <%= f.input :in_time, :placeholder => "From Date" , :class => "form-control", :as => :datetime_picker%>
-
- <%= f.input :out_time, :placeholder => "From Date" , :class => "form-control", :as => :datetime_picker%>
-
-
-
- <%= f.button :submit, "Create",:class => 'btn btn-primary ', :id => 'create' %>
- <%= f.button :submit, "Update",:class => 'btn btn-primary ', :disabled =>'', :id => 'update' %>
- <%= f.button :button, "Reset",:class => 'btn btn-danger ', :id => 'reset' %>
-
-
<% end %>
\ No newline at end of file
+
diff --git a/app/views/origami/in_juties/_edit_in_juty.html.erb b/app/views/origami/in_juties/_edit_in_juty.html.erb
index 9eaf8353..a297ac65 100644
--- a/app/views/origami/in_juties/_edit_in_juty.html.erb
+++ b/app/views/origami/in_juties/_edit_in_juty.html.erb
@@ -1,13 +1,14 @@
-<%= simple_form_for([:origami,@in_juty]) do |f| %>
- <%= f.error_notification %>
+<%= simple_form_for([:origami, @in_juty]) do |f| %>
+ <%= f.error_notification %>
-
- <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %>
- <%= f.input :in_time %>
- <%= f.input :out_time %>
-
+
+ <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %>
+
+ <%= f.input :in_time %>
+ <%= f.input :out_time %>
+
-
- <%= f.button :submit %>
-
-<% end %>
\ No newline at end of file
+
+ <%= f.button :submit %>
+
+<% end %>
diff --git a/app/views/origami/in_juties/_form.html.erb b/app/views/origami/in_juties/_form.html.erb
index d67df51b..9bed9152 100644
--- a/app/views/origami/in_juties/_form.html.erb
+++ b/app/views/origami/in_juties/_form.html.erb
@@ -1,33 +1,43 @@
-
-<%= simple_form_for([:origami,@in_juty]) do |f| %>
- <%= f.error_notification %>
+<%= simple_form_for @in_juty, :url => origami_index_in_juty_path(@table.id), :method => :post do |f| %>
+
+ <%= f.error_notification %>
+ <%= f.hidden_field :id, :class => "form-control col-md-6 " %>
+
+
+
+ <%= f.hidden_field :dinning_id, :value => @table.id, :class => "form-control col-md-4 " %>
+
+
+ <%= @table.name %>
+
+
+
+
+ <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %>
+
+
+ <%= f.input :in_time, :placeholder => "From Date", :class => "form-control" %>
+
+ <%= f.input :out_time, :placeholder => "To Date", :class => "form-control" %>
+
+
+
+
+ <% f.button :submit, "Create", :class => 'btn btn-primary ', :id => 'create' %>
+ <% f.button :submit, "Update", :class => 'btn btn-primary ', :disabled => '', :id => 'update' %>
+ <% f.button :button, "Reset", :class => 'btn btn-danger ', :id => 'reset' %>
+
+
+ <%= f.button :submit, :class => 'btn btn-primary' %>
+
-
- <%= f.label :dinning_id %>
- <%= f.collection_select :dinning_id, DiningFacility.all, :id, :name, {prompt: 'Select Dining Facilities'}, {class: 'form-control'} %>
- <%= f.label :commissioner_ids %>
- <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %>
-
- <%= f.text_field :in_time, :value=>DateTime.now.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker"%>
-
- <%= f.text_field :out_time, :value=>DateTime.now.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker"%>
-
-
- <%= link_to 'Back', origami_in_juties_path, class: 'btn btn-success' %>
- <%= f.button :submit, class: 'btn btn-info' %>
-
<% end %>
-
+
\ No newline at end of file
+ });
+
+
diff --git a/app/views/origami/in_juties/index.html.erb b/app/views/origami/in_juties/index.html.erb
index 6efeb999..ff5a0fd3 100644
--- a/app/views/origami/in_juties/index.html.erb
+++ b/app/views/origami/in_juties/index.html.erb
@@ -1,38 +1,91 @@
-