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 df1e13ce..ccaa538e 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -29,7 +29,8 @@
  • <%= link_to "Accounts", settings_accounts_path, :tabindex =>"-1" %>

  • -
  • <%= link_to "Promotion", settings_promotions_path, :tabindex =>"-1" %>
  • +
  • <%= link_to "Promotion", settings_promotions_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