From 83ec17a3df45ef2ba9fd90e0295e0683661fa4ab Mon Sep 17 00:00:00 2001 From: Nweni Date: Mon, 28 Aug 2017 09:37:36 +0630 Subject: [PATCH 1/6] 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 2/6] 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 3/6] 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 4/6] 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 5/6] 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 883f5f575a495160d31b808b0b3b6b99ffb4ec8e Mon Sep 17 00:00:00 2001 From: Phyo Date: Wed, 30 Aug 2017 18:57:35 +0630 Subject: [PATCH 6/6] Promotion by Instance --- app/models/promotion.rb | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/app/models/promotion.rb b/app/models/promotion.rb index d60f25a9..dfab86e9 100644 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -23,7 +23,7 @@ class Promotion < ApplicationRecord end def self.is_between_promo_datetime(current_day,current_time) #database is not local time - promoList = Promotion.where("(date_format(promo_start_date, 'YYYY-MM-DD') <=? AND date_format(promo_end_date, 'YYYY-MM-DD') >=?) AND (promo_start_hour < ? AND promo_end_hour > ?)", current_day, current_day, current_time, current_time) + promoList = Promotion.where("(TO_CHAR(promo_start_date, 'YYYY-MM-DD') <=? AND TO_CHAR(promo_end_date, 'YYYY-MM-DD') >=?) AND (promo_start_hour < ? AND promo_end_hour > ?)", current_day, current_day, current_time, current_time) return promoList end @@ -45,8 +45,8 @@ class Promotion < ApplicationRecord end def self.find_promo_item(promo, orderitem, sale_id) - item_code = OrderItem.find_by_item_instance_code(orderitem[0]).item_code - if promo.original_product.to_s == item_code + # item_code = OrderItem.find_by_item_instance_code(orderitem[0]).item_code + if promo.original_product.to_s == orderitem[0] if promo.min_qty.to_i > orderitem[1].to_i return false else @@ -77,7 +77,7 @@ class Promotion < ApplicationRecord def self.check_giveaway_product(promo, orderitem) promo.promotion_products.each do |promo_product| - if promo_product.item_code == OrderItem.find_by_item_instance_code(orderitem).item_code + if promo_product.item_code == orderitem return true, promo_product else return false, promo_product @@ -113,12 +113,11 @@ class Promotion < ApplicationRecord charge_qty += qty end item = OrderItem.find_by_item_instance_code(orderitem[0]) - byebug - # if promo_product == OrderItem.find_by_item_instance_code(orderitem[0]).item_code - # item = OrderItem.find_by_item_instance_code(orderitem[0]) - # else - # item = OrderItem.find_by_item_code(promo_product) - # end + if promo_product == OrderItem.find_by_item_instance_code(orderitem[0]).item_code + item = OrderItem.find_by_item_instance_code(orderitem[0]) + else + item = OrderItem.find_by_item_code(promo_product) + end update_existing_item(foc_qty, item, sale_id, "promotion", item.price) puts "Charged - " + charge_qty.to_s @@ -127,12 +126,13 @@ class Promotion < ApplicationRecord # AA - 10 # 3 # BB # orderList, #S34345 def self.give_promotion_second_product(orderitem_count, foc_min_qty, promo_product, orderitem, sale_id) puts "..... orderitem_count: " + orderitem_count.to_s + " / foc_min_qty: " + foc_min_qty.to_s + " /promo_product: " + promo_product + " orderitem: " + orderitem.to_s + byebug promotion_qty = orderitem_count.to_i / foc_min_qty.to_i # get foc item qty foc_qty = find_second_item_qty(sale_id, promo_product) if (foc_qty < promotion_qty) promotion_qty = foc_qty end - item = OrderItem.find_by_item_instance_code(promo_product,orderID) + item = OrderItem.find_by_item_instance_code(promo_product) update_existing_item(promotion_qty, item, sale_id, "promotion", item.price) end @@ -152,7 +152,6 @@ class Promotion < ApplicationRecord sale_item.is_taxable = false sale_item.sale_id = sale_id - sale_item.save sale = Sale.find(sale_id) sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount) @@ -163,7 +162,7 @@ class Promotion < ApplicationRecord puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s if same - foc_qty = orderitem[1].to_i / foc_min_qty + foc_qty = orderitem[1].to_i / foc_min_qty item = OrderItem.find_by_item_instance_code(orderitem[0]) update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off) else @@ -213,7 +212,7 @@ class Promotion < ApplicationRecord saleObj = Sale.find_by_sale_id(sale_id) itemList = combine_item(saleObj) itemList.each do |item| - if OrderItem.find_by_item_instance_code(item[0]).item_code == promo_item + if item[0] == promo_item return item[1] end end