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/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/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/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/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 3a25b101..d7ccedaf 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -30,6 +30,9 @@
| Item Code | +Name | +Alt Name | +Unit Price | + +Description | +Information | +Taxable | ++ | ||
|---|---|---|---|---|---|---|---|---|---|
| <%= 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?' } %> | +
| 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?' } %> |
<%= notice %>
+ + +| Promotion Code | +Start Date | +End Date | +Start Time | +End Time | +Promotion Day | +Original Product | +Created By | +Created 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 %> + | + <% if Employee.exists?(pro.created_by) %> +<%= Employee.find(pro.created_by).name %> | + <% else %> +<%= pro.created_by %> | + <% end %> +<%= 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?' } %> | +
<%= 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/config/routes.rb b/config/routes.rb index 5a1a8aaa..631f1316 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -244,6 +244,8 @@ Rails.application.routes.draw do resources :menu_item_options #tax_profiles resources :tax_profiles + #products + resources :products #lookups resources :lookups #cashier_terminals @@ -272,6 +274,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..fddf293b --- /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.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]" + 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_settings_products.rb b/db/migrate/20170816042256_settings_products.rb new file mode 100644 index 00000000..69c790fc --- /dev/null +++ b/db/migrate/20170816042256_settings_products.rb @@ -0,0 +1,17 @@ +class SettingsProducts < 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