From 74b15465f7eff2cf87793018769c79ea52dcac33 Mon Sep 17 00:00:00 2001 From: Zin Lin Phyo Date: Tue, 15 Aug 2017 15:13:44 +0630 Subject: [PATCH 1/5] item foc in sale edit --- .gitignore | 2 +- .idea/workspace.xml | 660 ++++-------------- .../origami/sale_edit_controller.rb | 159 +++-- app/models/sale.rb | 2 +- app/views/origami/sale_edit/edit.html.erb | 415 +++++------ config/routes.rb | 1 + 6 files changed, 430 insertions(+), 809 deletions(-) diff --git a/.gitignore b/.gitignore index 3d6c48d5..42a48b40 100644 --- a/.gitignore +++ b/.gitignore @@ -53,4 +53,4 @@ dump.rdb public/fonts/* # Ruby-Mine IDE folder -.idea +/.idea diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4cdbe61f..f494bdeb 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,27 +2,11 @@ - + - - - - - - - - - - - - - - - - - - - + + + @@ -39,45 +23,41 @@ - - + + - - + + - - - - - - - - - - - - - - - + - - + + - - + + - - + + + + + + + + + + + + @@ -86,54 +66,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -147,6 +81,7 @@ table_invoice sale_id oqs + void @@ -155,7 +90,6 @@ @@ -183,8 +121,8 @@ @@ -205,6 +143,21 @@ + + + + + + + + + + + @@ -217,46 +170,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -676,21 +556,22 @@ + - - + - + - + - + @@ -717,279 +598,42 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1004,112 +648,50 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + - - + + - + - - - - - - - + + + + + + + + + + + - - - - - - - - - - + + diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb index 209ec4c0..900b0431 100644 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -1,31 +1,50 @@ class Origami::SaleEditController < BaseOrigamiController authorize_resource :class => false - # Index for sale item void OR edit - def edit - sale_id = params[:sale_id] - @table_id = params[:table_id] - @saleobj = Sale.find(sale_id) - end + # Index for sale item void OR edit + def edit + sale_id = params[:sale_id] + @table_id = params[:table_id] + @saleobj = Sale.find(sale_id) + end - # create item void. make duplicate old record and update qty and price - def item_void - saleitemId = params[:sale_item_id] - saleitemObj = SaleItem.find(saleitemId) - saleitemObj.remark = 'void' - saleitemObj.save - @newsaleitem = SaleItem.new - @newsaleitem = saleitemObj.dup - @newsaleitem.save - @newsaleitem.qty = saleitemObj.qty * -1 - @newsaleitem.price = saleitemObj.price * -1 - @newsaleitem.is_taxable = 1 - @newsaleitem.product_name = saleitemObj.product_name + " - void" - @newsaleitem.save + # create item void. make duplicate old record and update qty and price + def item_void + saleitemId = params[:sale_item_id] + saleitemObj = SaleItem.find(saleitemId) + saleitemObj.remark = 'void' + saleitemObj.save + @newsaleitem = SaleItem.new + @newsaleitem = saleitemObj.dup + @newsaleitem.save + @newsaleitem.qty = saleitemObj.qty * -1 + @newsaleitem.price = saleitemObj.price * -1 + @newsaleitem.is_taxable = 1 + @newsaleitem.product_name = saleitemObj.product_name + " - void" + @newsaleitem.save - # re-calc tax - saleObj = Sale.find(saleitemObj.sale_id) - saleObj.compute_without_void - end + # re-calc tax + saleObj = Sale.find(saleitemObj.sale_id) + saleObj.compute_without_void + end + + def item_foc + saleitemId = params[:sale_item_id] + saleitemObj = SaleItem.find(saleitemId) + saleitemObj.remark = 'foc' + saleitemObj.save + @newsaleitem = SaleItem.new + @newsaleitem = saleitemObj.dup + @newsaleitem.save + @newsaleitem.qty = saleitemObj.qty * -1 + @newsaleitem.price = saleitemObj.price * -1 + @newsaleitem.is_taxable = 1 + @newsaleitem.product_name = saleitemObj.product_name + ' foc' + @newsaleitem.save + + # re-calc tax + saleObj = Sale.find(saleitemObj.sale_id) + saleObj.compute_without_void + end # def item_edit # saleitemId = params[:sale_item_id] @@ -48,63 +67,63 @@ class Origami::SaleEditController < BaseOrigamiController # end def item_edit - saleitemId = params[:sale_item_id] - update_qty = params[:update_qty] + saleitemId = params[:sale_item_id] + update_qty = params[:update_qty] update_price = params[:update_price] - saleitemObj = SaleItem.find(saleitemId) + saleitemObj = SaleItem.find(saleitemId) - saleitemObj.qty = update_qty - saleitemObj.price = update_qty.to_f * update_price.to_f - saleitemObj.unit_price = update_price + saleitemObj.qty = update_qty + saleitemObj.price = update_qty.to_f * update_price.to_f + saleitemObj.unit_price = update_price saleitemObj.taxable_price = update_qty.to_f * update_price.to_f # saleitemObj.remark = 'edit' - saleitemObj.product_name = saleitemObj.product_name + " - updated" + saleitemObj.product_name = saleitemObj.product_name + " - updated" saleitemObj.save - # re-calc tax - saleObj = Sale.find(saleitemObj.sale_id) - saleObj.compute_without_void + # re-calc tax + saleObj = Sale.find(saleitemObj.sale_id) + saleObj.compute_without_void end - # make cancel void item - def item_void_cancel - saleitemId = params[:sale_item_id] - saleitemObj = SaleItem.find(saleitemId) - both = SaleItem.where('product_code=?',saleitemObj.product_code) - both.each do |item| - if item.qty.to_i > 0 - item.remark = nil - item.save - end - end - saleitemObj.destroy + # make cancel void item + def item_void_cancel + saleitemId = params[:sale_item_id] + saleitemObj = SaleItem.find(saleitemId) + both = SaleItem.where('product_code=?', saleitemObj.product_code) + both.each do |item| + if item.qty.to_i > 0 + item.remark = nil + item.save + end + end + saleitemObj.destroy - # re-calc tax - saleObj = Sale.find(saleitemObj.sale_id) - saleObj.compute_without_void - end + # re-calc tax + saleObj = Sale.find(saleitemObj.sale_id) + saleObj.compute_without_void + end - # remove all void items - def cancel_all_void - sale_id = params[:sale_id] - saleObj = Sale.find(sale_id) - saleObj.sale_items.each do |item| - if item.qty.to_i < 0 - item.destroy - else - item.remark = nil - end - item.save - end + # remove all void items + def cancel_all_void + sale_id = params[:sale_id] + saleObj = Sale.find(sale_id) + saleObj.sale_items.each do |item| + if item.qty.to_i < 0 + item.destroy + else + item.remark = nil + end + item.save + end - # re-calc tax - saleObj.compute_without_void - end + # re-calc tax + saleObj.compute_without_void + end - def apply_void - sale_id = params[:sale_id] - saleObj = Sale.find(sale_id) - saleObj.compute_without_void - end + def apply_void + sale_id = params[:sale_id] + saleObj = Sale.find(sale_id) + saleObj.compute_without_void + end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 133b2dfe..b19aef3d 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -267,7 +267,7 @@ class Sale < ApplicationRecord rounding_adjustment = 0 sales_items.each do |item| - if item.remark != 'void' + if item.remark != 'void' && item.remark != 'foc' #compute each item and added to total subtotal_price = subtotal_price + item.price total_taxable = total_taxable + item.price diff --git a/app/views/origami/sale_edit/edit.html.erb b/app/views/origami/sale_edit/edit.html.erb index 6ba861a8..bdcf2069 100644 --- a/app/views/origami/sale_edit/edit.html.erb +++ b/app/views/origami/sale_edit/edit.html.erb @@ -1,216 +1,235 @@
- +
-
-
-
INVOICE DETAILS
-
-
-
-
-

Receipt No: +

+
+
INVOICE DETAILS
+
+
+
+
+

Receipt No: <%= @saleobj.receipt_no rescue '' %>

-
-
-

Date: <%= @saleobj.created_at.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>

-
-
-
-
-

Customer :

-
+
+
+

Date: + <%= @saleobj.created_at.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-' %> +

+
+
+
+
+

Customer :

+
-
-
- - - - - - - - - - <% - count = 0 - sub_total = 0 - @saleobj.sale_items.each do |sale_item| - count += 1 - sub_total = sub_total + sale_item.price - %> - - <% - # Can't check for discount - unless sale_item.price == 0 + +
+
#ItemsQTY - Price - - Action
+ + + + + + + + + <% + count = 0 + sub_total = 0 + @saleobj.sale_items.each do |sale_item| + count += 1 + sub_total = sub_total + sale_item.price + %> + + <% + # Can't check for discount + unless sale_item.price == 0 %> - - - - <% if sale_item.remark != 'void' && sale_item.remark != 'edit' %> - - - - + - <% elsif sale_item.qty.to_i < 0 || sale_item.remark == 'edit' %> - - - - - <% else %> - - - - <% end %> - - <% - end - end - %> - -
#ItemsQTY + + Price + + + Action
<%= count %> - <%= sale_item.product_name %> - - - - - - - - + + + + - - - - - - - - - -
-
- -
-
+ + + + <% else %> + + + + + + + + <% end %> + + <% + end + end + %> + + +
+ +
+
- -
- - - - -
+ +
+ + + + +
diff --git a/config/routes.rb b/config/routes.rb index 9e62023c..35cd6233 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -80,6 +80,7 @@ Rails.application.routes.draw do post 'moving' => "movetable#moving" get "/table/:table_id/sale/:sale_id/edit" => "sale_edit#edit" post 'item_void' => "sale_edit#item_void" + post 'item_foc' => "sale_edit#item_foc" post 'item_edit' => "sale_edit#item_edit" post 'item_void_cancel' => "sale_edit#item_void_cancel" post 'cancel_all_void' => 'sale_edit#cancel_all_void' From 3e9b9c6b8b3a428818b16da5be0c50d99947489b Mon Sep 17 00:00:00 2001 From: yamin Date: Wed, 16 Aug 2017 10:46:03 +0630 Subject: [PATCH 2/5] CalculatePriceInDiningCharges --- .../settings/dining_charges_controller.rb | 2 +- .../settings/dining_charges/_form.html.erb | 43 +++++++++++++++++-- .../settings/dining_charges/new.html.erb | 6 +-- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/app/controllers/settings/dining_charges_controller.rb b/app/controllers/settings/dining_charges_controller.rb index 31763b02..854354c2 100644 --- a/app/controllers/settings/dining_charges_controller.rb +++ b/app/controllers/settings/dining_charges_controller.rb @@ -97,6 +97,6 @@ class Settings::DiningChargesController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def dining_charge_params # params.fetch(:dining_charge, {}) - params.require(:dining_charge).permit(:item_code, :unit_price, :taxable, :charge_type,:minimum_free_time ,:charge_block,:time_rounding,:time_rounding_block, :zone_id) + params.require(:dining_charge).permit(:item_code, :unit_price, :taxable, :charge_type,:minimum_free_time ,:charge_block,:time_rounding,:time_rounding_block, :zone_id, :time_rounding_block_price) end end diff --git a/app/views/settings/dining_charges/_form.html.erb b/app/views/settings/dining_charges/_form.html.erb index 2349025a..5cc25062 100644 --- a/app/views/settings/dining_charges/_form.html.erb +++ b/app/views/settings/dining_charges/_form.html.erb @@ -3,13 +3,14 @@
<%= f.input :item_code, :input_html => { :id => 'item_code' } %> - <%= f.input :unit_price %> + <%= f.input :unit_price, :input_html => { :id => 'unit_price'} %> <%= f.input :taxable %> <%= f.input :charge_type, :collection => [:hr, :day] %> <%= f.input :minimum_free_time %> - <%= f.input :charge_block %> + <%= f.input :charge_block, :input_html => { :id => 'charge_block'} %> <%= f.input :time_rounding %> - <%= f.input :time_rounding_block %> + <%= f.input :time_rounding_block, :input_html => { :id => 'time_rounding_block'} %> + <%= f.input :time_rounding_block_price, :input_html => { :id => 'time_rounding_block_price'} %>
@@ -17,3 +18,39 @@
<% end %> + diff --git a/app/views/settings/dining_charges/new.html.erb b/app/views/settings/dining_charges/new.html.erb index 2aa13a4b..bece2a2e 100644 --- a/app/views/settings/dining_charges/new.html.erb +++ b/app/views/settings/dining_charges/new.html.erb @@ -16,8 +16,9 @@ <%= render 'form', dining_charge: @dining_charge %> + \ No newline at end of file From db43ae186c45812bc9213e58f320ca5fae1d15e1 Mon Sep 17 00:00:00 2001 From: Phyo Date: Wed, 16 Aug 2017 11:00:37 +0630 Subject: [PATCH 3/5] DB for promtion, promotion product,product --- config/routes.rb | 3 +++ db/migrate/20170815044557_create_promotion.rb | 18 ++++++++++++++++++ .../20170815051517_create_promotion_product.rb | 13 +++++++++++++ db/migrate/20170816042256_create_product.rb | 17 +++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 db/migrate/20170815044557_create_promotion.rb create mode 100644 db/migrate/20170815051517_create_promotion_product.rb create mode 100644 db/migrate/20170816042256_create_product.rb diff --git a/config/routes.rb b/config/routes.rb index 9e62023c..241c3826 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -264,6 +264,9 @@ Rails.application.routes.draw do end end + #promotion + resources :promotions + end #--------- Transactions Sections ------------# diff --git a/db/migrate/20170815044557_create_promotion.rb b/db/migrate/20170815044557_create_promotion.rb new file mode 100644 index 00000000..124ad8d9 --- /dev/null +++ b/db/migrate/20170815044557_create_promotion.rb @@ -0,0 +1,18 @@ +class CreatePromotion < ActiveRecord::Migration[5.1] + def change + create_table :promotions do |t| + t.string :promo_code, :limit => 16 + + t.datetime :promo_start_date, :null => false + t.datetime :promo_end_date, :null => false + t.time :promo_start_hour, :null => false + t.time :promo_end_hour, :null => false + t.string :promo_day, :null => false, :default => "[0,1,2,3,4,5,6]" + t.string :promo_type, :null => false, :default => "Quantity" + t.string :original_product + t.integer :min_qty + t.string :created_by, :null => false + t.timestamps + end + end +end diff --git a/db/migrate/20170815051517_create_promotion_product.rb b/db/migrate/20170815051517_create_promotion_product.rb new file mode 100644 index 00000000..dbbc198a --- /dev/null +++ b/db/migrate/20170815051517_create_promotion_product.rb @@ -0,0 +1,13 @@ +class CreatePromotionProduct < ActiveRecord::Migration[5.1] + def change + create_table :promotion_products do |t| + t.references :promotion, foreign_key: true + t.string :item_code, :null => false + t.integer :min_qty + t.integer :net_off + t.integer :net_price + t.integer :percentage + t.timestamps + end + end +end diff --git a/db/migrate/20170816042256_create_product.rb b/db/migrate/20170816042256_create_product.rb new file mode 100644 index 00000000..a329d69b --- /dev/null +++ b/db/migrate/20170816042256_create_product.rb @@ -0,0 +1,17 @@ +class CreateProduct < ActiveRecord::Migration[5.1] + def change + create_table :products do |t| + t.string :item_code, :limit => 16 + + t.string :name, :null => false + t.string :alt_name + t.integer :unit_price + t.string :image_path + t.string :description + t.string :information + t.boolean :taxable + t.string :created_by, :null => false + t.timestamps + end + end +end From 4fc748e877512213d373b132e292fe70c8807994 Mon Sep 17 00:00:00 2001 From: yamin Date: Wed, 16 Aug 2017 18:19:20 +0630 Subject: [PATCH 4/5] CRUDforProducts --- .../settings/products_controller.rb | 76 +++++++++++++++++++ app/models/product.rb | 3 + app/views/layouts/_header.html.erb | 2 + app/views/settings/products/_form.html.erb | 18 +++++ .../products/_settings_product.json.jbuilder | 2 + app/views/settings/products/edit.html.erb | 10 +++ app/views/settings/products/index.html.erb | 45 +++++++++++ .../settings/products/index.json.jbuilder | 1 + app/views/settings/products/new.html.erb | 26 +++++++ app/views/settings/products/show.html.erb | 33 ++++++++ .../settings/products/show.json.jbuilder | 1 + config/routes.rb | 2 + ...rb => 20170816042256_settings_products.rb} | 2 +- 13 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 app/controllers/settings/products_controller.rb create mode 100644 app/models/product.rb create mode 100644 app/views/settings/products/_form.html.erb create mode 100644 app/views/settings/products/_settings_product.json.jbuilder create mode 100644 app/views/settings/products/edit.html.erb create mode 100644 app/views/settings/products/index.html.erb create mode 100644 app/views/settings/products/index.json.jbuilder create mode 100644 app/views/settings/products/new.html.erb create mode 100644 app/views/settings/products/show.html.erb create mode 100644 app/views/settings/products/show.json.jbuilder rename db/migrate/{20170816042256_create_product.rb => 20170816042256_settings_products.rb} (87%) diff --git a/app/controllers/settings/products_controller.rb b/app/controllers/settings/products_controller.rb new file mode 100644 index 00000000..0c2fa15d --- /dev/null +++ b/app/controllers/settings/products_controller.rb @@ -0,0 +1,76 @@ +class Settings::ProductsController < ApplicationController + before_action :set_settings_product, only: [:show, :edit, :update, :destroy] + + # GET /settings/products + # GET /settings/products.json + def index + @settings_products = Product.all + end + + # GET /settings/products/1 + # GET /settings/products/1.json + def show + end + + # GET /settings/products/new + def new + @settings_product = Product.new + end + + # GET /settings/products/1/edit + def edit + end + + # POST /settings/products + # POST /settings/products.json + def create + + @settings_product = Product.new(settings_product_params) + @settings_product.created_by = current_user.name + respond_to do |format| + if @settings_product.save + format.html { redirect_to settings_products_path, notice: 'Product was successfully created.' } + format.json { render :show, status: :created, location: @settings_product } + else + format.html { render :new } + format.json { render json: @settings_product.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /settings/products/1 + # PATCH/PUT /settings/products/1.json + def update + respond_to do |format| + if @settings_product.update(settings_product_params) + format.html { redirect_to settings_product_path, notice: 'Product was successfully updated.' } + format.json { render :show, status: :ok, location: @settings_product } + else + format.html { render :edit } + format.json { render json: @settings_product.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /settings/products/1 + # DELETE /settings/products/1.json + def destroy + @settings_product.destroy + respond_to do |format| + format.html { redirect_to settings_products_path, notice: 'Product was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_settings_product + @settings_product = Product.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def settings_product_params + params.require(:product).permit(:item_code, :name, :alt_name, :unit_price, :image_path, :description, :information, :taxable,:created_by) + end + +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 00000000..042e1730 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,3 @@ +class Product < ApplicationRecord + validates_presence_of :name +end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index bc5ce498..441cfe91 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -28,6 +28,8 @@
  • <%= link_to "Employees", settings_employees_path, :tabindex =>"-1" %>

  • <%= link_to "Accounts", settings_accounts_path, :tabindex =>"-1" %>
  • +
    +
  • <%= link_to "Products", settings_products_path, :tabindex =>"-1" %>
  • diff --git a/app/views/settings/products/_form.html.erb b/app/views/settings/products/_form.html.erb new file mode 100644 index 00000000..37a049c6 --- /dev/null +++ b/app/views/settings/products/_form.html.erb @@ -0,0 +1,18 @@ +<%= simple_form_for([:settings,@settings_product]) do |f| %> + <%= f.error_notification %> + +
    + <%= f.input :item_code, :input_html => { :id => 'item_code' } %> + <%= f.input :name %> + <%= f.input :alt_name %> + <%= f.input :unit_price %> + <%= f.input :image_path %> + <%= f.input :description %> + <%= f.input :information %> + +
    + +
    + <%= f.button :submit %> +
    +<% end %> diff --git a/app/views/settings/products/_settings_product.json.jbuilder b/app/views/settings/products/_settings_product.json.jbuilder new file mode 100644 index 00000000..608fdefb --- /dev/null +++ b/app/views/settings/products/_settings_product.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! settings_product, :id, :created_at, :updated_at +json.url settings_product_url(settings_product, format: :json) diff --git a/app/views/settings/products/edit.html.erb b/app/views/settings/products/edit.html.erb new file mode 100644 index 00000000..634381df --- /dev/null +++ b/app/views/settings/products/edit.html.erb @@ -0,0 +1,10 @@ +
    + + <%= render 'form', settings_product: @settings_product %> +
    diff --git a/app/views/settings/products/index.html.erb b/app/views/settings/products/index.html.erb new file mode 100644 index 00000000..3f49a401 --- /dev/null +++ b/app/views/settings/products/index.html.erb @@ -0,0 +1,45 @@ + + +
    +
    + + + + + + + + + + + + + + + + + <% @settings_products.each do |settings_product| %> + + + + + + + + + + + + + <% end %> + +
    Item CodeNameAlt NameUnit PriceDescriptionInformationTaxable
    <%= settings_product.item_code %><%= settings_product.name %><%= settings_product.alt_name %><%= settings_product.unit_price %><%= settings_product.description %><%= settings_product.information %><%= settings_product.taxable %><%= link_to 'Show', settings_product_path(settings_product) %><%= link_to 'Edit', edit_settings_product_path(settings_product) %><%= link_to 'Destroy', settings_product_path(settings_product), method: :delete, data: { confirm: 'Are you sure?' } %>
    +
    diff --git a/app/views/settings/products/index.json.jbuilder b/app/views/settings/products/index.json.jbuilder new file mode 100644 index 00000000..bc08f2a7 --- /dev/null +++ b/app/views/settings/products/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @settings_products, partial: 'settings_products/settings_product', as: :settings_product diff --git a/app/views/settings/products/new.html.erb b/app/views/settings/products/new.html.erb new file mode 100644 index 00000000..e971f70d --- /dev/null +++ b/app/views/settings/products/new.html.erb @@ -0,0 +1,26 @@ +
    + + <%= render 'form', settings_product: @settings_product %> +
    + + diff --git a/app/views/settings/products/show.html.erb b/app/views/settings/products/show.html.erb new file mode 100644 index 00000000..f16b5426 --- /dev/null +++ b/app/views/settings/products/show.html.erb @@ -0,0 +1,33 @@ + +
    +
    +

    Product

    + + + + + + + + + + + + + + + + +
    Item code<%= @settings_product.item_code %>
    Name<%= @settings_product.name %>
    Alt name<%= @settings_product.alt_name %>
    Unit price<%= @settings_product.unit_price %>
    Image path<%= image_tag @settings_product.image_path, :size => '200x200'%>
    Description<%= @settings_product.description %>
    Information<%= @settings_product.information %>
    Taxable<%= @settings_product.taxable %>
    <%= link_to 'Edit', edit_settings_product_path(@settings_product) %><%= link_to 'Destroy', settings_product_path(@settings_product), method: :delete, data: { confirm: 'Are you sure?' } %>
    +
    +
    + + diff --git a/app/views/settings/products/show.json.jbuilder b/app/views/settings/products/show.json.jbuilder new file mode 100644 index 00000000..aef1705d --- /dev/null +++ b/app/views/settings/products/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "settings_products/settings_product", settings_product: @settings_product diff --git a/config/routes.rb b/config/routes.rb index 51431474..93a7985a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -237,6 +237,8 @@ Rails.application.routes.draw do resources :menu_item_options #tax_profiles resources :tax_profiles + #products + resources :products #lookups resources :lookups #cashier_terminals diff --git a/db/migrate/20170816042256_create_product.rb b/db/migrate/20170816042256_settings_products.rb similarity index 87% rename from db/migrate/20170816042256_create_product.rb rename to db/migrate/20170816042256_settings_products.rb index a329d69b..69c790fc 100644 --- a/db/migrate/20170816042256_create_product.rb +++ b/db/migrate/20170816042256_settings_products.rb @@ -1,4 +1,4 @@ -class CreateProduct < ActiveRecord::Migration[5.1] +class SettingsProducts < ActiveRecord::Migration[5.1] def change create_table :products do |t| t.string :item_code, :limit => 16 From fc2927b341a7a55d8bd24f1bbbbaaa6a5ce51468 Mon Sep 17 00:00:00 2001 From: Phyo Date: Wed, 16 Aug 2017 18:36:23 +0630 Subject: [PATCH 5/5] Promotion CRUD --- .../settings/promotions_controller.rb | 76 +++++++++++++++++++ app/helpers/settings/promotions_helper.rb | 2 + app/models/promotion.rb | 2 + app/views/layouts/_header.html.erb | 2 + app/views/settings/promotions/_form.html.erb | 48 ++++++++++++ .../promotions/_promotion.json.jbuilder | 2 + app/views/settings/promotions/edit.html.erb | 10 +++ app/views/settings/promotions/index.html.erb | 58 ++++++++++++++ .../settings/promotions/index.json.jbuilder | 1 + app/views/settings/promotions/new.html.erb | 17 +++++ app/views/settings/promotions/show.html.erb | 4 + .../settings/promotions/show.json.jbuilder | 1 + db/migrate/20170815044557_create_promotion.rb | 4 +- 13 files changed, 225 insertions(+), 2 deletions(-) create mode 100644 app/controllers/settings/promotions_controller.rb create mode 100644 app/helpers/settings/promotions_helper.rb create mode 100644 app/models/promotion.rb create mode 100644 app/views/settings/promotions/_form.html.erb create mode 100644 app/views/settings/promotions/_promotion.json.jbuilder create mode 100644 app/views/settings/promotions/edit.html.erb create mode 100644 app/views/settings/promotions/index.html.erb create mode 100644 app/views/settings/promotions/index.json.jbuilder create mode 100644 app/views/settings/promotions/new.html.erb create mode 100644 app/views/settings/promotions/show.html.erb create mode 100644 app/views/settings/promotions/show.json.jbuilder diff --git a/app/controllers/settings/promotions_controller.rb b/app/controllers/settings/promotions_controller.rb new file mode 100644 index 00000000..277cf62d --- /dev/null +++ b/app/controllers/settings/promotions_controller.rb @@ -0,0 +1,76 @@ +class Settings::PromotionsController < ApplicationController + before_action :set_promotion, only: [:show, :edit, :update, :destroy] + + # GET /promotions + # GET /promotions.json + def index + @promotions = Promotion.all + end + + # GET /promotions/1 + # GET /promotions/1.json + def show + end + + # GET /promotions/new + def new + @promotion = Promotion.new + @promotion.promo_start_date = DateTime.now + @promotion.promo_end_date = DateTime.now + end + + # GET /promotions/1/edit + def edit + end + + # POST /promotions + # POST /promotions.json + def create + @promotion = Promotion.new(promotion_params) + @promotion.created_by = current_login_employee.id + respond_to do |format| + if @promotion.save + format.html { redirect_to settings_promotions_path, notice: 'Promotion was successfully created.' } + format.json { render :show, status: :created, location: @promotion } + else + format.html { render :new } + format.json { render json: @promotion.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /promotions/1 + # PATCH/PUT /promotions/1.json + def update + respond_to do |format| + if @promotion.update(promotion_params) + format.html { redirect_to settings_promotions_path, notice: 'Promotion was successfully updated.' } + format.json { render :show, status: :ok, location: @promotion } + else + format.html { render :edit } + format.json { render json: @promotion.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /promotions/1 + # DELETE /promotions/1.json + def destroy + @promotion.destroy + respond_to do |format| + format.html { redirect_to settings_promotions_path, notice: 'Promotion was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_promotion + @promotion = Promotion.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def promotion_params + params.require(:promotion).permit(:promo_code, :promo_start_date, :promo_end_date, :promo_start_hour,:promo_end_hour ,:promo_day, :promo_type,:original_product ,:min_qty ,:created_by) + end +end diff --git a/app/helpers/settings/promotions_helper.rb b/app/helpers/settings/promotions_helper.rb new file mode 100644 index 00000000..787c2194 --- /dev/null +++ b/app/helpers/settings/promotions_helper.rb @@ -0,0 +1,2 @@ +module Settings::PromotionsHelper +end diff --git a/app/models/promotion.rb b/app/models/promotion.rb new file mode 100644 index 00000000..9b5c4c12 --- /dev/null +++ b/app/models/promotion.rb @@ -0,0 +1,2 @@ +class Promotion < ApplicationRecord +end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index bc5ce498..df1e13ce 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -28,6 +28,8 @@
  • <%= link_to "Employees", settings_employees_path, :tabindex =>"-1" %>

  • <%= link_to "Accounts", settings_accounts_path, :tabindex =>"-1" %>
  • +
    +
  • <%= link_to "Promotion", settings_promotions_path, :tabindex =>"-1" %>
  • diff --git a/app/views/settings/promotions/_form.html.erb b/app/views/settings/promotions/_form.html.erb new file mode 100644 index 00000000..98dbb7fe --- /dev/null +++ b/app/views/settings/promotions/_form.html.erb @@ -0,0 +1,48 @@ +<%= simple_form_for([:settings,@promotion]) do |f| %> + <%= f.error_notification %> + +
    +
    +
    +
    <%= f.input :promo_code %>
    +
    +
    +
    +
    + Promo Start Date + <%= f.date_field :promo_start_date, :placeholder => "From Date" , :class => "form-control"%> +
    +
    +
    + Promo End Date + <%= f.date_field :promo_end_date ,:placeholder => "To Date" , :class => "form-control"%> +
    +
    +
    +
    + <%= f.input :promo_start_hour %> + +
    +
    <%= f.input :promo_end_hour %>
    +
    +
    +
    <%= f.input :promo_day %>
    +
    +
    +
    + <%= f.input :promo_type,input_html: { class: "" }, + collection: %w{Quantity Net_off Net_price Percentage},:class => 'form-control' ,:label => "" %> +
    +
    +
    +
    <%= f.input :original_product,collection: MenuItem.order("name desc"),input_html: { selected: 2 } %>
    +
    <%= f.input :min_qty %>
    +
    +
    +
    + +
    + <%= f.button :submit %> +
    +<% end %> diff --git a/app/views/settings/promotions/_promotion.json.jbuilder b/app/views/settings/promotions/_promotion.json.jbuilder new file mode 100644 index 00000000..d9b08aef --- /dev/null +++ b/app/views/settings/promotions/_promotion.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! promotion, :id, :created_at, :updated_at +json.url promotion_url(promotion, format: :json) diff --git a/app/views/settings/promotions/edit.html.erb b/app/views/settings/promotions/edit.html.erb new file mode 100644 index 00000000..47a01b80 --- /dev/null +++ b/app/views/settings/promotions/edit.html.erb @@ -0,0 +1,10 @@ +
    + + <%= render 'form', promotion: @promotion %> +
    diff --git a/app/views/settings/promotions/index.html.erb b/app/views/settings/promotions/index.html.erb new file mode 100644 index 00000000..606b138b --- /dev/null +++ b/app/views/settings/promotions/index.html.erb @@ -0,0 +1,58 @@ +

    <%= notice %>

    + + + + +
    +
    + + + + + + + + + + + + + + + + + + <% @promotions.each do |pro| %> + + + + + + + + + <% if Employee.exists?(pro.created_by) %> + + <% else %> + + <% end %> + + + + + <% end %> + +
    Promotion CodeStart DateEnd DateStart TimeEnd TimePromotion DayOriginal ProductCreated ByCreated At
    <%= link_to pro.promo_code, settings_promotion_path(pro) %><%= pro.promo_start_date %><%= pro.promo_end_date %><%= pro.promo_start_hour.strftime("%I:%M %P") rescue "-" %><%= pro.promo_end_hour.strftime("%I:%M %P") rescue "-" %><%= pro.promo_day %> + <% if MenuItem.exists?(pro.original_product) %> + <%= MenuItem.find(pro.original_product).name %> + <% end %> + <%= Employee.find(pro.created_by).name %><%= pro.created_by %><%= pro.created_at.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") %><%= link_to 'Edit', edit_settings_promotion_path(pro) %><%= link_to 'Destroy', settings_promotion_path(pro), method: :delete, data: { confirm: 'Are you sure?' } %>
    +
    diff --git a/app/views/settings/promotions/index.json.jbuilder b/app/views/settings/promotions/index.json.jbuilder new file mode 100644 index 00000000..1c9c5f97 --- /dev/null +++ b/app/views/settings/promotions/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @promotions, partial: 'promotions/promotion', as: :promotion diff --git a/app/views/settings/promotions/new.html.erb b/app/views/settings/promotions/new.html.erb new file mode 100644 index 00000000..c7748bb6 --- /dev/null +++ b/app/views/settings/promotions/new.html.erb @@ -0,0 +1,17 @@ + +
    + + <%= render 'form', promotion: @promotion %> +
    + diff --git a/app/views/settings/promotions/show.html.erb b/app/views/settings/promotions/show.html.erb new file mode 100644 index 00000000..4dd7e593 --- /dev/null +++ b/app/views/settings/promotions/show.html.erb @@ -0,0 +1,4 @@ +

    <%= notice %>

    + +<%= link_to 'Edit', edit_promotion_path(@promotion) %> | +<%= link_to 'Back', promotions_path %> diff --git a/app/views/settings/promotions/show.json.jbuilder b/app/views/settings/promotions/show.json.jbuilder new file mode 100644 index 00000000..52507108 --- /dev/null +++ b/app/views/settings/promotions/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "promotions/promotion", promotion: @promotion diff --git a/db/migrate/20170815044557_create_promotion.rb b/db/migrate/20170815044557_create_promotion.rb index 124ad8d9..fddf293b 100644 --- a/db/migrate/20170815044557_create_promotion.rb +++ b/db/migrate/20170815044557_create_promotion.rb @@ -3,8 +3,8 @@ class CreatePromotion < ActiveRecord::Migration[5.1] create_table :promotions do |t| t.string :promo_code, :limit => 16 - t.datetime :promo_start_date, :null => false - t.datetime :promo_end_date, :null => false + t.date :promo_start_date, :null => false + t.date :promo_end_date, :null => false t.time :promo_start_hour, :null => false t.time :promo_end_hour, :null => false t.string :promo_day, :null => false, :default => "[0,1,2,3,4,5,6]"