From 83ec17a3df45ef2ba9fd90e0295e0683661fa4ab Mon Sep 17 00:00:00 2001 From: Nweni Date: Mon, 28 Aug 2017 09:37:36 +0630 Subject: [PATCH 01/18] inventory development --- .../inventory/inventory_controller.rb | 2 +- .../inventory_definitions_controller.rb | 4 +- .../inventory/stock_checks_controller.rb | 2 +- app/jobs/inventory_job.rb | 8 ++ app/models/inventory_definition.rb | 37 ++++++++++ app/models/sale.rb | 1 + app/models/stock_journal.rb | 22 ++++++ app/views/home/dashboard.html.erb | 2 +- .../inventory/_inventory_list.html.erb | 40 ++++++++++ app/views/inventory/inventory/index.html.erb | 27 ++++--- .../inventory_definitions/_form.html.erb | 7 +- .../inventory_definitions/new.html.erb | 14 +++- .../inventory/stock_checks/index.html.erb | 74 +++++++++++++------ app/views/layouts/inventory.html.erb | 2 +- config/routes.rb | 2 +- ...0824110103_create_inventory_definitions.rb | 2 + 16 files changed, 200 insertions(+), 46 deletions(-) create mode 100644 app/jobs/inventory_job.rb create mode 100644 app/views/inventory/inventory/_inventory_list.html.erb 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_checks_controller.rb b/app/controllers/inventory/stock_checks_controller.rb index e8620ca1..0e36ee62 100644 --- a/app/controllers/inventory/stock_checks_controller.rb +++ b/app/controllers/inventory/stock_checks_controller.rb @@ -1,4 +1,4 @@ -class StockChecksController < ApplicationController +class Inventory::StockChecksController < BaseInventoryController before_action :set_stock_check, only: [:show, :edit, :update, :destroy] # GET /stock_checks diff --git a/app/jobs/inventory_job.rb b/app/jobs/inventory_job.rb new file mode 100644 index 00000000..0f5b1a51 --- /dev/null +++ b/app/jobs/inventory_job.rb @@ -0,0 +1,8 @@ +class InventoryJob < ApplicationJob + queue_as :default + + def perform(sale_id) + saleObj = Sale.find(sale_id) + end + +end diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb index 150ae6a9..af81c941 100644 --- a/app/models/inventory_definition.rb +++ b/app/models/inventory_definition.rb @@ -1,2 +1,39 @@ class InventoryDefinition < ApplicationRecord + + scope :active, -> {where(:is_active => true)} + + def 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) + stock = StockJournal.where('item_code=?', item.item_code).order('created_at desc').take + unless stock.nil? + modify_balance(item, stock.balance, inventory_definition) + end + end + + def self.modify_balance(item, stock_balance, inventory_definition) + if stock.balance.to_i >= item.qty + puts ">> stock is greater than orde qty" + add_to_journal(item, balance, "ok", inventory_definition) + else + puts " << stock is less than order qty" + add_to_journal(item, balance, "out of stock", inventory_definition) + end + end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 500e28ef..c8ceb696 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -117,6 +117,7 @@ class Sale < ApplicationRecord create_saleitem_diningcharges(charges, diningprice, booking.dining_facility.name, dining_time) end + InventoryJob.perform_later(self.id) return true, self.id end diff --git a/app/models/stock_journal.rb b/app/models/stock_journal.rb index ee6efe79..106a9bf5 100644 --- a/app/models/stock_journal.rb +++ b/app/models/stock_journal.rb @@ -1,2 +1,24 @@ class StockJournal < ApplicationRecord + + SALES_TRANS = "sale" + STOCK_CHECK_TRANS = "stock_check" + + def add_to_journal(item, balance, stock_message, inventory_definition) + + balance = calculate_balance(balance, item.qty) + + journal = StockJournal.new + journal.item_code = item.item_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 + end + + def self.calculate_balance(balance, qty) + return balance.to_i - qty.to_i + 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

+
+
+ +
+
+ + + + + + + + + + <% + count = 0 + @products.each do |item| + count += 1 + %> + + + + + + + + + <% end %> +
#ProductMin OrderMax StockCreated byCreated Time
<%= count %><%= item.item_code rescue ""%><%= item.min_order_level %><%= item.max_stock_level %><%= item.created_by%><%= item.created_at%>
+
+
+ + diff --git a/app/views/inventory/inventory/index.html.erb b/app/views/inventory/inventory/index.html.erb index e8826240..f275a96d 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/index.html.erb b/app/views/inventory/stock_checks/index.html.erb index 05b802eb..f5f8eb9a 100644 --- a/app/views/inventory/stock_checks/index.html.erb +++ b/app/views/inventory/stock_checks/index.html.erb @@ -1,25 +1,53 @@ -

<%= notice %>

+
+
+
+
+ +
+
+
+
+ + + + + + +
#ProductBalance
+
+
+
+
+
+ +
+
+ +
-

Stock Checks

+
+ +
+
+
- - - - - - - - - <% @stock_checks.each do |stock_check| %> - - - - - - <% end %> - -
<%= 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?' } %>
- -
- -<%= link_to 'New Stock Check', new_stock_check_path %> +
+
+
+ + + + + + + +
#ProductBalanceDifferent
+
+
+
+
+ +
+
+
+
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/config/routes.rb b/config/routes.rb index 3e8caa28..980980cb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -327,7 +327,7 @@ Rails.application.routes.draw do # ----------- Inventory --------------------------- namespace :inventory do - get 'inventory' => 'inventory#index' + get '/' => 'inventory#index' resources :stock_check_items resources :stock_checks resources :stock_journals diff --git a/db/migrate/20170824110103_create_inventory_definitions.rb b/db/migrate/20170824110103_create_inventory_definitions.rb index 4278ce89..c73fd0bd 100644 --- a/db/migrate/20170824110103_create_inventory_definitions.rb +++ b/db/migrate/20170824110103_create_inventory_definitions.rb @@ -4,6 +4,8 @@ class CreateInventoryDefinitions < ActiveRecord::Migration[5.1] t.string :item_code t.integer :min_order_level, :default => 0 t.integer :max_stock_level, :default => 0 + t.integer :created_by + t.boolean :is_active, :default => true t.timestamps end end From cabc78c373e3d90c75c9e13748787d7d939b7329 Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 30 Aug 2017 14:19:24 +0630 Subject: [PATCH 02/18] inventory --- .../inventory/stock_check_items_controller.rb | 6 +- .../inventory/stock_checks_controller.rb | 162 ++++++++++-------- app/jobs/inventory_job.rb | 3 +- app/models/inventory_definition.rb | 16 +- app/models/sale.rb | 3 +- app/models/stock_check.rb | 15 ++ app/models/stock_check_item.rb | 34 ++++ app/models/stock_journal.rb | 19 +- app/views/inventory/inventory/index.html.erb | 2 +- .../inventory/stock_checks/_form.html.erb | 10 -- .../stock_checks/_stock_check.json.jbuilder | 2 - .../stock_checks/create.json.jbuilder | 1 + .../inventory/stock_checks/edit.html.erb | 6 - .../inventory/stock_checks/index.html.erb | 95 +++++++--- .../stock_checks/index.json.jbuilder | 1 - app/views/inventory/stock_checks/new.html.erb | 5 - .../inventory/stock_checks/show.html.erb | 76 +++++++- .../inventory/stock_checks/show.json.jbuilder | 1 - config/routes.rb | 7 +- ...20170824110130_create_stock_check_items.rb | 2 +- dump.rdb | Bin 616 -> 723 bytes 21 files changed, 328 insertions(+), 138 deletions(-) delete mode 100644 app/views/inventory/stock_checks/_form.html.erb delete mode 100644 app/views/inventory/stock_checks/_stock_check.json.jbuilder create mode 100644 app/views/inventory/stock_checks/create.json.jbuilder delete mode 100644 app/views/inventory/stock_checks/edit.html.erb delete mode 100644 app/views/inventory/stock_checks/index.json.jbuilder delete mode 100644 app/views/inventory/stock_checks/new.html.erb delete mode 100644 app/views/inventory/stock_checks/show.json.jbuilder 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 0e36ee62..f161bc25 100644 --- a/app/controllers/inventory/stock_checks_controller.rb +++ b/app/controllers/inventory/stock_checks_controller.rb @@ -1,74 +1,98 @@ class Inventory::StockChecksController < BaseInventoryController - before_action :set_stock_check, only: [:show, :edit, :update, :destroy] + + 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/jobs/inventory_job.rb b/app/jobs/inventory_job.rb index 0f5b1a51..a47dd362 100644 --- a/app/jobs/inventory_job.rb +++ b/app/jobs/inventory_job.rb @@ -3,6 +3,7 @@ class InventoryJob < ApplicationJob 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 af81c941..91823068 100644 --- a/app/models/inventory_definition.rb +++ b/app/models/inventory_definition.rb @@ -2,7 +2,7 @@ class InventoryDefinition < ApplicationRecord scope :active, -> {where(:is_active => true)} - def calculate_product_count(saleObj) + def self.calculate_product_count(saleObj) saleObj.sale_items.each do |item| found, inventory_definition = find_product_in_inventory(item) if found @@ -20,20 +20,22 @@ class InventoryDefinition < ApplicationRecord end end - def self.check_balance(item,inventory_definition) - stock = StockJournal.where('item_code=?', item.item_code).order('created_at desc').take + 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.balance, inventory_definition) + 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_balance, inventory_definition) + def self.modify_balance(item, stock, inventory_definition) #saleitemObj if stock.balance.to_i >= item.qty puts ">> stock is greater than orde qty" - add_to_journal(item, balance, "ok", inventory_definition) + StockJournal.add_to_journal(item, stock.balance, "ok", inventory_definition) else puts " << stock is less than order qty" - add_to_journal(item, balance, "out of stock", inventory_definition) + 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 8c89195e..6eec518f 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -118,7 +118,8 @@ class Sale < ApplicationRecord create_saleitem_diningcharges(charges, diningprice, booking.dining_facility.name, dining_time) end - InventoryJob.perform_later(self.id) + 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 106a9bf5..22dceaa5 100644 --- a/app/models/stock_journal.rb +++ b/app/models/stock_journal.rb @@ -3,22 +3,37 @@ class StockJournal < ApplicationRecord SALES_TRANS = "sale" STOCK_CHECK_TRANS = "stock_check" - def add_to_journal(item, balance, stock_message, inventory_definition) + 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.item_code + 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/inventory/inventory/index.html.erb b/app/views/inventory/inventory/index.html.erb index f275a96d..7aeb4464 100644 --- a/app/views/inventory/inventory/index.html.erb +++ b/app/views/inventory/inventory/index.html.erb @@ -7,7 +7,7 @@ <%if current_login_employee.role == "administrator" || current_login_employee.role == "manager" %> <%end%> - +
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 f5f8eb9a..812d4409 100644 --- a/app/views/inventory/stock_checks/index.html.erb +++ b/app/views/inventory/stock_checks/index.html.erb @@ -2,52 +2,101 @@
- +
- - - - - - -
#ProductBalance
+ +
+
+
+
+
+
+ Product +
+
+
-
+
-
- -
-
- -
- +
- + Qty +
+
+ +
+
+
+
+
+
+
-
+
- +
-
# Product BalanceDifferent
+
+
-
- -
+
+ + 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 %> +
+
+
+
+ + + + + + + + + + <% + count = 0 + @check.stock_check_items.each do |item| + count += 1 + %> + + + + + + + + + <% end %> +
#ProductStock CountStock BalanceDifferentRemark
<%= count %><%= item.item_code %><%= item.stock_count %><%= item.stock_balance %><%= item.different %><%= item.remark %>
+
+
+
+ + + +
+
-<%= 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/config/routes.rb b/config/routes.rb index fb384fed..add37c76 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -328,8 +328,11 @@ Rails.application.routes.draw do namespace :inventory do get '/' => 'inventory#index' - resources :stock_check_items - resources :stock_checks + get '/stock_checks' => 'stock_checks#index' + post 'save_stock' => 'stock_checks#create', as:'stock_check_save' + get '/stock_checks/:id' => 'stock_checks#show' + post 'save_to_journal' => 'stock_checks#save_to_journal', as: 'save_to_journal' + # resources :stock_checks resources :stock_journals resources :inventory_definitions end diff --git a/db/migrate/20170824110130_create_stock_check_items.rb b/db/migrate/20170824110130_create_stock_check_items.rb index c8908a1d..578ca893 100644 --- a/db/migrate/20170824110130_create_stock_check_items.rb +++ b/db/migrate/20170824110130_create_stock_check_items.rb @@ -1,7 +1,7 @@ class CreateStockCheckItems < ActiveRecord::Migration[5.1] def change create_table :stock_check_items do |t| - t.integer :stock_check_id, :null => false + t.integer :stock_check_id t.string :item_code, :null => false t.integer :stock_count, :default => 0 t.integer :stock_journal_id diff --git a/dump.rdb b/dump.rdb index 6e3e4bdb58d80e5ac055cb301f0b9693f2a197d4..b16f7012708a9124be23d231143fadff83c2af99 100644 GIT binary patch literal 723 zcmaKq&uY|A6vi`SrrH)-D5waPhKq=cB;4FdawkDBf-bu0LRTWT+(}M4m*&s({?QI9 zxbhi%0$;&xsJ?_dpJNm?ZK_z9aeIH9WcAsL5>3mf{#-;NT#9-(W*PE|( z4`Z%mlgtOH;w79Ol^>tYuW1RHQ$l$ki`Uh)WIWXh?~2{ zt#dLJbqccmcLAwGaAPco;Zk@mJ6t>vlg8+;{+T6v+k3CTE$WmNF$q2D$GI1V5D*;D z$X_JU+4`~haGUJ+48#1dfN73_sVy(SKBf`Dp^HO8qllQi%InX`r{v4dYc#2)s#pmq zMt|KP8?{#v3bLI8rcm5Tj64##QHX;mveA@h=*;vA^=+isp>_X?JP}~|rWUMH)`PXQ zu2L-oRO!sRw-wmvSc3+M;^!!XoarLDbA7@OCkIo(Yr)kFy|7Wi#?S(5-Q*cmD!KWs z|KXk3xO5owc5tjYs6oyO3FcVKS)0cCKM605b>y@WENlaHywTE3FW`a_wSk;fVdHX% X8o$5NZQHxr?W%rh*n9JS_v`*|$nM|# delta 415 zcmY*VJxjw-6n%-Q6_pNx)ncLH4NgtXi%rsI$|$-x`hnOfR#s1A`b-N*x;Y0?%0sR5Kv5M3pPsT+n?sgjyWsx`^; zo57=fW8atd@J_(EPuqYkoSwvG%s34>xSNz?i%bs0#H?4BDrzdNn)7Ac@mza4o4zh% zPPb)qi0y_T>rxa_pUZa134A9CL-3s*wluwrf8$_l9S;Jb_(hnV*^1>Oxt058AMZV1FN?*6pIT5ZwZ^SZ7&ySv3KIe42a_iCTHsomN=!vH6;exg$Nn%0 O`Z~XUT`YcF+ Date: Wed, 30 Aug 2017 14:37:50 +0630 Subject: [PATCH 03/18] Update --- dump.rdb | Bin 723 -> 721 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/dump.rdb b/dump.rdb index b16f7012708a9124be23d231143fadff83c2af99..b3eee5c5784606ee9f1e7bc544f57f54acb83d48 100644 GIT binary patch delta 92 zcmV-i0HgoY1G?BSp19PY@lNtdj5fCvo yFf=eYFf=hTE-^PaH8itU0b&6gH39~4b!ByBa{&irWoBV@Y;^xUZAy+{F&dhdD;>B1 delta 94 zcmcb}dYN^CflzktvdCW?rNyZ!y1A*jhYBiWCpwie8c*CA$IS02Gg*pJQ&`B*)WF2R y+|tOvOwYi~$lTJ>Xmbc-5~H*U6I)?vYH4aQBYR3}T4HHV$^X(+znV7Bn{fcGkRD+G From 675ebd56a77a5957f00436c811f73de83137642f Mon Sep 17 00:00:00 2001 From: Zin Lin Phyo Date: Wed, 30 Aug 2017 15:57:15 +0630 Subject: [PATCH 04/18] assign in_juty in sale edit --- .idea/workspace.xml | 258 +++++++++--------- .../origami/in_juties_controller.rb | 106 ++++--- .../in_juties/_assign_in_juty.html.erb | 2 +- .../origami/in_juties/_edit_in_juty.html.erb | 23 +- app/views/origami/in_juties/_form.html.erb | 64 +++-- app/views/origami/in_juties/index.html.erb | 119 +++++--- .../origami/in_juties/index_in_juty.html.erb | 66 +++-- app/views/origami/in_juties/new.html.erb | 2 +- dump.rdb | Bin 797 -> 797 bytes 9 files changed, 374 insertions(+), 266 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 705b1a97..5c3fb862 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,17 +3,14 @@ - - - - - - + + + - + @@ -28,7 +25,7 @@ - + @@ -55,41 +52,51 @@ - + - - + + - - + + - - + + - + - - + + - - + + - - + + + + + + + + + + + + @@ -98,42 +105,23 @@ - - - - - - - - - - - - - - - - - - - - - - + + - - - + + + + - - + + - - + + @@ -173,10 +161,6 @@ @@ -756,12 +744,12 @@ - + - @@ -774,7 +762,6 @@ - @@ -784,9 +771,9 @@ - + - + @@ -804,51 +791,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1088,7 +1035,7 @@ - + @@ -1106,7 +1053,7 @@ - + @@ -1151,18 +1098,18 @@ - + - - + + - + - - + + @@ -1179,42 +1126,87 @@ - + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + diff --git a/app/controllers/origami/in_juties_controller.rb b/app/controllers/origami/in_juties_controller.rb index 6ac04659..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,11 +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 @@ -20,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 @@ -33,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 @@ -57,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.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 } @@ -91,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 @@ -122,19 +153,20 @@ class Origami::InJutiesController < BaseOrigamiController @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/views/origami/in_juties/_assign_in_juty.html.erb b/app/views/origami/in_juties/_assign_in_juty.html.erb index 62531529..b6363195 100644 --- a/app/views/origami/in_juties/_assign_in_juty.html.erb +++ b/app/views/origami/in_juties/_assign_in_juty.html.erb @@ -18,7 +18,7 @@ <%= f.input :in_time, :placeholder => "From Date", :class => "form-control" %> - <%= f.input :out_time, :placeholder => "From Date", :class => "form-control" %> + <%= f.input :out_time, :placeholder => "To Date", :class => "form-control" %>

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 @@ - -
-
- - - - - - - - - - - - - <% @in_juties.each do |in_juty| %> - - - - - - - - - - <% end %> - -
Dining Facility NameCommissioner IdsIn timeOut time
<%= in_juty.dining_facility.name rescue '-' %><%= in_juty.commissioner.name rescue '-' %><%= in_juty.in_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %><%= in_juty.out_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %><%= link_to 'Show', origami_in_juty_path(in_juty) %><%= link_to 'Edit', edit_origami_in_juty_path(in_juty) %><%= link_to 'Destroy', origami_in_juty_path(in_juty), method: :delete, data: {confirm: 'Are you sure?'} %>
+
+
+ + + diff --git a/app/views/origami/in_juties/index_in_juty.html.erb b/app/views/origami/in_juties/index_in_juty.html.erb index bbb9912b..52d79c89 100644 --- a/app/views/origami/in_juties/index_in_juty.html.erb +++ b/app/views/origami/in_juties/index_in_juty.html.erb @@ -22,7 +22,7 @@ <%= in_juty.commissioner.name rescue '-' %> <%= in_juty.in_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %> <%= in_juty.out_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %> - <%= link_to 'Destroy', origami_destroy_in_juty_path(in_juty.dining_facility.id, in_juty), method: :delete, data: {confirm: 'Are you sure?'} %> + <%= link_to 'Remove', origami_destroy_in_juty_path(in_juty.dining_facility.id, in_juty), method: :delete, data: {confirm: 'Are you sure?'} %> <% end %> @@ -30,13 +30,14 @@ <%= paginate @juties_in %>
-
- <%= render 'assign_in_juty', in_juty: @in_juty, table: @table %> +
+ <%= render 'form', in_juty: @in_juty, table: @table %>
-
- +
+      +
diff --git a/app/views/origami/in_juties/new.html.erb b/app/views/origami/in_juties/new.html.erb index eb34f01c..f59ff6fd 100644 --- a/app/views/origami/in_juties/new.html.erb +++ b/app/views/origami/in_juties/new.html.erb @@ -6,5 +6,5 @@
  • New
  • - <%= render 'form', in_juty: @in_juty %> + <%= render 'form', in_juty: @in_juty, table: @table %>
    diff --git a/dump.rdb b/dump.rdb index 332310c7de18a2a63f99b8eafc63674d6ba26c52..c5350a135cafb3a36ab94837ae372b8c4e343ffa 100644 GIT binary patch delta 70 zcmV-M0J;C22Au|wFc=<$rdj$3b#rB8Ep26O!f@dg0R8~`5do2$8nI%N0R&a|bTYH~ c0S^HcI5jXaIW9OkGB`Cg|D3(96aWZdT&QgsAOHXW delta 70 zcmV-M0J;C22Au|wFc|$irdj$3b#rB8Ep26O!m#`u0R8~`5do2$8nI%N0R%8CTQRfw c0S^HcHa0aiGA=SVF*Y(c|1I=AZ{h1@H^Y4zS^xk5 From bf9f0cdbe7ddf1f8bdc2820e5acca4bc8204c49c Mon Sep 17 00:00:00 2001 From: Phyo Date: Wed, 30 Aug 2017 18:22:22 +0630 Subject: [PATCH 05/18] CRUD Update for Promotion --- .../settings/promotions_controller.rb | 11 ++ app/models/menu_item.rb | 1 + app/views/settings/promotions/_form.html.erb | 114 ++++++++++++++++-- config/routes.rb | 1 + 4 files changed, 119 insertions(+), 8 deletions(-) diff --git a/app/controllers/settings/promotions_controller.rb b/app/controllers/settings/promotions_controller.rb index ef972df9..af8bedc1 100644 --- a/app/controllers/settings/promotions_controller.rb +++ b/app/controllers/settings/promotions_controller.rb @@ -76,6 +76,17 @@ class Settings::PromotionsController < ApplicationController end end + def find_item_instance + item = MenuItem.find_by_item_code(params[:item_code]) + if item.nil? + product = Product.where("item_code = ?",params[:item_code]).pluck(:name,:item_code) + render json: product + else + menu_instance = MenuItemInstance.where("menu_item_id = ?",item.id).pluck(:item_instance_name,:item_instance_code) + render json: menu_instance + end + end + private # Use callbacks to share common setup or constraints between actions. def set_promotion diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index e7f53dcd..7ea5c3ad 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -19,6 +19,7 @@ class MenuItem < ApplicationRecord scope :simple_menu_item, -> { where(type: 'SimpleMenuItem') } scope :set_menu_item, -> { where(type: 'SetMenuItem') } + scope :active, -> { where(is_available: true) } # Item Image Uploader mount_uploader :image_path, MenuItemImageUploader diff --git a/app/views/settings/promotions/_form.html.erb b/app/views/settings/promotions/_form.html.erb index 1e4a3f86..7ac413d0 100644 --- a/app/views/settings/promotions/_form.html.erb +++ b/app/views/settings/promotions/_form.html.erb @@ -49,32 +49,79 @@
    -
    <%= f.input :original_product,collection: MenuItem.order("name desc").pluck(:name,:item_code),input_html: { selected: 2 } %>
    + <% arr = MenuItem.active.order("name desc").pluck(:name,:item_code) %> + <% Product.order("name desc").pluck(:name,:item_code).each do |p| %> + <% arr.push(p) %> + <% end %> +
    + + + +
    + + <% sample = [] %> + <% if !@promotion.original_product.nil? %> + <% if !MenuItemInstance.find_by_item_instance_code(@promotion.original_product).nil? %> + <% sample = MenuItemInstance.where("item_instance_code=?",@promotion.original_product).pluck(:item_instance_name,:item_instance_code)%> + <% else %> + <% sample = Product.where("item_code=?",@promotion.original_product).pluck(:name,:item_code)%> + <% end %> + <% end %> +
    <%= f.input :original_product,collection: sample %>
    +
    <%= f.input :min_qty %>

    -
    Item Code
    +
    Item Code
    Min Qty
    Net off
    Net Price
    -
    Percentage
    -
    +
    Percentage
    +
    <%= f.fields_for :promotion_products do |pro| %>
    -
    <%= pro.input :item_code, label: false,collection: MenuItem.order("name desc").pluck(:name,:item_code)%>
    + <% arr = MenuItem.active.order("name desc").pluck(:name,:item_code) %> + <% Product.order("name desc").pluck(:name,:item_code).each do |p| %> + <% arr.push(p) %> + <% end %> +
    + +
    + <% sample = [] %> +
    <%= pro.input :item_code, :class => 'promoproduct', collection: sample,input_html: { selected: 2 }, label: false %>
    <%= pro.input :min_qty , label: false%>
    <%= pro.input :net_off , label: false %>
    <%= pro.input :net_price , label: false %>
    -
    <%= pro.input :percentage , label: false %>
    -
    <%= pro.link_to_remove "X" %>
    +
    <%= pro.input :percentage , label: false %>
    +
    <%= pro.link_to_remove "X" %>
    <% end %>
    -
    <%= f.link_to_add "Add Product", :promotion_products, :class => 'btn btn-primary' %>
    +
    <%= f.link_to_add "Add Product", :promotion_products, :class => 'btn btn-primary addProduct' %>
    @@ -103,5 +150,56 @@ $(document).ready(function(){ datepicker:false, format:'H:m' }); + $("#promotion_original_product").select2(); + $(".item_code_place").select2(); + $(".item_code_place").on('change', function(event) { + var ajax_url = "<%= settings_find_item_instance_path %>"; + var item_code = this.value; + $.ajax({ + type: "GET", + url: ajax_url, + data: 'item_code=' + item_code, + success: function (result) { + $("#promotion_original_product").empty(); + var itemlist; + for (var i = 0; i < result.length; i++) { + itemlist += "" + } + $("#promotion_original_product").append(itemlist); + $("#promotion_original_product").select2(); + } + }); + }); + $(".promotion_promotion_products_item_code select").select2(); + $(".item_code_place1").select2(); + callforpromoproduct(); + $(".addProduct").on('click', function(event) { + setTimeout(function(){ + $(".promotion_promotion_products_item_code select").select2(); + callforpromoproduct(); + }, 0); + }); + function callforpromoproduct(){ + $(".item_code_place1").select2(); + $(".item_code_place1").on('change', function(event) { + id = $(this).parent().next().find("select").attr("id"); + var ajax_url = "<%= settings_find_item_instance_path %>"; + var item_code = this.value; + $.ajax({ + type: "GET", + url: ajax_url, + data: 'item_code=' + item_code, + success: function (result) { + $("#"+id).empty(); + var itemlist; + for (var i = 0; i < result.length; i++) { + itemlist += "" + } + $("#"+id).append(itemlist); + $("#"+id).select2(); + } + }); + }); + } }); diff --git a/config/routes.rb b/config/routes.rb index 1130bf36..b095e099 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -292,6 +292,7 @@ Rails.application.routes.draw do resources :promotions do resources :promotion_products end + get '/find_item_instance' => 'promotions#find_item_instance', as:'find_item_instance' # commission resources :commissions From 84d483cad23dd2295754bd6e9606330ce68a11f4 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 30 Aug 2017 18:41:54 +0630 Subject: [PATCH 06/18] update addorder --- app/assets/javascripts/addorder.js | 169 ++++++++++++++---- app/assets/stylesheets/addorder.scss | 41 ++++- .../menu_item_instances_controller.rb | 9 + .../origami/addorders_controller.rb | 1 + .../menu_item_instances/show.json.jbuilder | 39 ++++ app/views/origami/addorders/detail.html.erb | 30 ++-- .../get_instance.json.jbuilder | 26 +++ config/routes.rb | 3 +- 8 files changed, 265 insertions(+), 53 deletions(-) create mode 100644 app/controllers/api/restaurant/menu_item_instances_controller.rb create mode 100644 app/views/api/restaurant/menu_item_instances/show.json.jbuilder diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 54b1c7b6..158246d4 100644 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -12,6 +12,12 @@ $(function(){ qty = $(this).val(); price = $("#unit_price").text(); $("#total_price").text(qty*price); + }); + + $("#set_change_qty").change(function(){ + qty = $(this).val(); + price = $("#set_total_price").text(); + $("#set_total_price").text(qty*price); }); //show menu item list when click menu category @@ -98,23 +104,13 @@ $(function(){ //end Ajax } //end show list function - //click item row for add order + //click item row for item set $(document).on('click', '.set_item_box', function(event){ $(".instance-list").empty(); + $(".options-list").empty(); + data = $(this).parent().children().children('.add_icon'); - item_options = $(this).data('option'); - for(var field in item_options) { - value = item_options[field]["values"]; - type = item_options[field]["type"]; - row = "

    "+type+"

    " - $(value).each(function(i){ - row +=""; - }); - $(".opt-list").append(row); - } - instances = $(this).data('instance'); item_sets = $(this).data('item-sets'); @@ -123,21 +119,25 @@ $(function(){ $(value).each(function(i){ $.ajax({ type: "GET", - url: '../../settings/menu_item_instances/get_instance/'+value[i]["id"], + url: '../../api/restaurant/menu_item_instances/'+value[i]["id"], data: {id:value[i]}, - success:function(result){ - // var image_path = "" - console.log(result) - row = '
    ' - +'
    ' + success:function(result){ + + row = '
    ' + +"
    " +'
    ' +''+result["name"]+'' +'
    ' +'
    ' - +'' + +'' +'
    ' +'' +'
    ' +'
    ' @@ -146,16 +146,97 @@ $(function(){ } }); }); - } - $('#change_qty').val(1); - $('#item_instances').text(instances); - $('#title_name').text(data.attr('data-name')); - $('#item_code').text(data.attr('data-item-code')); - $('#total_price').text(data.attr('data-price')); - $('#unit_price').text(data.attr('data-price')); + $('#set_change_qty').val(1); + $('#set_item_instances').text(instances); + $('#set_name').text(data.attr('data-name')); + $('#set_item_code').text(data.attr('data-item-code')); + $('#set_total_price').text(data.attr('data-price')); + $('#set_unit_price').text(data.attr('data-price')); }); + // click instance for add item set + $(document).on('click', '.instance_box', function(event){ + + $(".options-list").empty(); + + item_options = $(this).data('option'); + code = $(this).data('code'); + + for(var field in item_options) { + value = item_options[field]["values"]; + type = item_options[field]["type"]; + row = "

    "+type+"

    " + $(value).each(function(i){ + row +=""; + }); + $(".options-list").append(row); + } + + if($(this).hasClass('selected-instance') == true){ + sub_total = $('#set_total_price').text(); + name = $(this).data('name'); + price = $(this).data('price'); + qty = $('#set_change_qty').val(); + total = qty*price; + var total_price = +sub_total - +total; + $(this).removeClass('selected-instance'); + $(".options-list").empty(); + $(this).removeAttr('data-options'); + $('#instance_option').text('') + }else { + sub_total = $('#set_total_price').text(); + name = $(this).data('name'); + price = $(this).data('price'); + qty = $('#set_change_qty').val(); + total = qty*price; + var total_price = +sub_total + +total; + $(this).addClass('selected-instance'); + } + $('#set_total_price').text(total_price); + }); //End selecct attribute buttom + + // click add order + $(document).on('click', '.set_order', function(event){ + total_price = $('#set_total_price').text(); + qty = parseInt($('#set_change_qty').val()); + item_code = $('#set_item_code').text(); + item_name = $('#set_name').text(); + + var items = $('.selected-instance'); + + attribute_arr = [] + option_arr = [] + var rowCount = $('.summary-items tbody tr').length+1; + $(items).each(function(i){ + code = $(items[i]).attr('data-code'); + name = $(items[i]).attr('data-name'); + price = $(items[i]).attr('data-price'); + option = $(items[i]).attr('data-options'); + total = qty * price ; + option_arr.push(option); + row ="" + +''+rowCount+'' + +'' + item_name+ ' ' + name +'' + +'' + qty + '' + +'' + + parseFloat(total).toFixed(2) + +'' + +''; + $(".summary-items tbody").append(row); + rowCount = rowCount + 1; + }); + calculate_sub_total(); + + }); //End add order Click + //click item row for add order $(document).on('click', '.menu_item_box', function(event){ $('.attributes-list').empty(); @@ -214,8 +295,8 @@ $(function(){ type = item_options[field]["type"]; row = "

    "+type+"

    " $(value).each(function(i){ - row +=""; + row +=""; }); $(".options-list").append(row); } @@ -271,13 +352,27 @@ $(function(){ $(document).on('click', '.option_btn', function(event){ value = $(this).data('value'); type = $(this).data('type'); - options = $(".option_btn"); + group = $(this).data('group'); + options = $(".option_btn"); $(options).each(function(i){ if ($(options[i]).attr('data-type')==type){ $('.'+type).removeClass("selected-option"); } }); $(this).addClass('selected-option'); + + if(group == "set_menu"){ + code = $(this).data('code'); + value = $(this).data('value'); + + instance = $(".selected-instance"); + $(instance).each(function(i){ + if ($(instance[i]).attr('data-code')==code){ + $(instance[i]).attr('data-options',value); + $(instance[i]).children().children('#instance_option').text(value); + } + }); + } }); //End selecct attribute buttom @@ -310,7 +405,7 @@ $(function(){ show_item_detail(item_data); calculate_sub_total(); - }); //End Add Icon Click + }); //End add order Click // click plus icon for add $(document).on('click', '.add_icon', function(event){ @@ -320,6 +415,7 @@ $(function(){ }); //End Add Icon Click function show_item_detail(data){ + console.log(data) qty = parseInt(data.attr('data-qty')); append = 0; price = parseFloat(data.attr('data-price')).toFixed(2); @@ -376,11 +472,11 @@ $(function(){ // Pay Discount for Payment $("#create_order").on('click', function(e){ e.preventDefault(); - $( "#loading_wrapper" ).show(); + $("#loading_wrapper").show(); var table_id = $('#table_id').text(); var booking_id = $('#booking_id').text(); if (!booking_id.length > 0) { - console.log("hi") + var params = {'order_source': "cashier", 'order_type': "dine_in", 'customer_id': "", 'guest_info': "",'booking_id':booking_id, 'table_id': table_id, @@ -390,7 +486,7 @@ $(function(){ var order_items = JSON.stringify(get_order_item_rows()); var ajax_url = '../addorders/create'; - console.log(ajax_url) + var params = {'order_source': "cashier", 'order_type': "dine_in", 'customer_id': "", 'guest_info': "", @@ -403,10 +499,10 @@ $(function(){ data: params, dataType: "json", success:function(result){ - $( "#loading_wrapper" ).show(); + $("#loading_wrapper").hide(); $.confirm({ title: 'Infomation!', - content: "result.status", + content: "Order has been successfully created", buttons: { confirm: { text: 'Ok', @@ -501,6 +597,7 @@ $(function(){ var item_row = $('.summary-items tbody tr'); $(item_row).each(function(i){ var order_item = {}; + console.log($(item_row[i]).attr('data-options')); order_item.order_item_id = $(item_row[i]).attr('data-row'); order_item.item_instance_code = $(item_row[i]).attr('data-instance-code'); order_item.quantity = $(item_row[i]).children('#item_qty').text(); diff --git a/app/assets/stylesheets/addorder.scss b/app/assets/stylesheets/addorder.scss index 29ca7156..b819b47d 100644 --- a/app/assets/stylesheets/addorder.scss +++ b/app/assets/stylesheets/addorder.scss @@ -87,9 +87,16 @@ element.style { color: #fff !important; background-color: green !important; } +.card { + border: 2px solid rgba(0, 0, 0, 0.125) !important; + } +.selected-instance { + border: 2px solid #7a62d3 !important; +} + .attribute_btn { white-space: normal !important; - height: 40px; + /*width: 80px;*/ margin-bottom: 5px; margin-right: 5px; @@ -97,7 +104,7 @@ element.style { .option_btn { white-space: normal !important; - height: 40px; + /*width: 80px;*/ margin-bottom: 5px; margin-right: 5px; @@ -115,4 +122,34 @@ element.style { height: 80px; border: 1px solid #54A5AF; padding: 10px; +} + +.card-footer{ + padding:0.35rem 1.25rem !important; +} + +/*Loading gif for payment*/ + +#loading_wrapper{ + + position: fixed; + background-color: #C8C8C8 ; + height: 100%; + width: 100%; + left: 0; + opacity: 0.6; + top: 0; + z-index: 9999999; +} +#loading{ + position: relative; + height: 100%; + width: 100%; + background-image: url('../../../image/loading-ajax.gif'); + background-position: center center; + background-repeat: no-repeat; + opacity: 1; + filter: alpha(opacity=100); /* ie */ + -moz-opacity: 1; /* mozilla */ + } \ No newline at end of file diff --git a/app/controllers/api/restaurant/menu_item_instances_controller.rb b/app/controllers/api/restaurant/menu_item_instances_controller.rb new file mode 100644 index 00000000..be38f782 --- /dev/null +++ b/app/controllers/api/restaurant/menu_item_instances_controller.rb @@ -0,0 +1,9 @@ +class Api::Restaurant::MenuItemInstancesController < Api::ApiController + skip_before_action :authenticate + #Description + # Pull the default menu details and also other available (active) menus + # Input Params - order_id + def show + @id = MenuItemInstance.find(params[:id]) + end +end diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 23a7bc26..1f9d70f3 100644 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -37,6 +37,7 @@ class Origami::AddordersController < BaseOrigamiController def create Rails.logger.debug "Order Source - " + params[:order_source].to_s Rails.logger.debug "Table ID - " + params[:table_id].to_s + puts params[:order_items] items_arr = [] JSON.parse(params[:order_items]).each { |i| items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": i["options"]} diff --git a/app/views/api/restaurant/menu_item_instances/show.json.jbuilder b/app/views/api/restaurant/menu_item_instances/show.json.jbuilder new file mode 100644 index 00000000..69302b8e --- /dev/null +++ b/app/views/api/restaurant/menu_item_instances/show.json.jbuilder @@ -0,0 +1,39 @@ +if(@id) + menu_item = MenuItem.find(@id.menu_item_id) + # Format for option json + opt_format = [] + # Format for attributes json + menu_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] }) + next + end + + opt_format.each do |of| + if menu_opt.option_type.in? opt_format.map {|k| k[:type]} + if menu_opt.option_type == of[:type] + of[:values].push(menu_opt.name) + end + else + new_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] } + opt_format.push(new_opt) + break + end + end + end + + json.success true + json.id @id.id + json.name @id.item_instance_name + json.code @id.item_instance_code + + json.item_id @id.menu_item_id + json.attributes @id.item_attributes + json.price @id.price + json.is_default @id.is_default + + json.options opt_format +else + json.success false +end diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index b7f0cf1d..a1bd22dc 100644 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -147,39 +147,41 @@ +
    <%= f.input :promo_type,input_html: { class: "" }, @@ -86,6 +95,8 @@
    <% end %> From 0584530224253e3a79290e61b728b9e6ede7a541 Mon Sep 17 00:00:00 2001 From: Zin Lin Phyo Date: Thu, 31 Aug 2017 18:06:13 +0630 Subject: [PATCH 17/18] for pull --- .idea/workspace.xml | 116 ++++++++++++++++++++++++-------------------- dump.rdb | Bin 852 -> 851 bytes 2 files changed, 64 insertions(+), 52 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 81ac8297..b429350c 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,12 +2,7 @@ - - - - - @@ -52,18 +47,28 @@ - - + + - - + + - - + + + + + + + + + + + + @@ -72,14 +77,14 @@ - - + + - + @@ -270,6 +275,14 @@ + + + + + + + + @@ -711,12 +724,12 @@ - + - @@ -729,7 +742,6 @@ - @@ -737,12 +749,12 @@ - + - + - + @@ -800,22 +812,6 @@ - - - - - - - - - - - - - - - - @@ -896,14 +892,6 @@ - - - - - - - - @@ -1189,10 +1177,10 @@ - + - - + + @@ -1207,16 +1195,40 @@ - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dump.rdb b/dump.rdb index fa93236711ad0fb9f5095d373d33b9920349dcfe..29aafb9ab913e1ac292d9318acde28e4749120a9 100644 GIT binary patch delta 75 zcmV-R0JQ(q2Ga(RFc^mPr&;<4b#rB8Ep26O!XWDy0R8~`69JL%6tP^;0R#dB6gaam h0to>c5HU3{G%+_hGcq|YG&C|YGXF>KMQ*w;QvoU|8B+iN delta 76 zcmV-S0JHzo2Gjd5ivC|G%+?cG&nOZG%`3cGd2HIq+2Vi8WT!$tr}wh From e6ee2c43df67a9f0beec56c65c86adea3257a882 Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 4 Sep 2017 18:01:48 +0630 Subject: [PATCH 18/18] add public/image to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 98acc705..b6d9a051 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ capybara-*.html /db/*.sqlite3 /db/schema.rb /db/structure.sql +/public/image /public/system/* /public/assets/* /public/uploads/*