Fix Conflict
This commit is contained in:
76
app/controllers/settings/products_controller.rb
Normal file
76
app/controllers/settings/products_controller.rb
Normal file
@@ -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
|
||||
3
app/models/product.rb
Normal file
3
app/models/product.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Product < ApplicationRecord
|
||||
validates_presence_of :name
|
||||
end
|
||||
@@ -29,7 +29,8 @@
|
||||
<hr class="hr_advance" />
|
||||
<li><%= link_to "Accounts", settings_accounts_path, :tabindex =>"-1" %></li>
|
||||
<hr class="hr_advance" />
|
||||
<li><%= link_to "Promotion", settings_promotions_path, :tabindex =>"-1" %></li>
|
||||
<li><%= link_to "Promotion", settings_promotions_path, :tabindex =>"-1" %></li>]
|
||||
<li><%= link_to "Products", settings_products_path, :tabindex =>"-1" %></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
|
||||
18
app/views/settings/products/_form.html.erb
Normal file
18
app/views/settings/products/_form.html.erb
Normal file
@@ -0,0 +1,18 @@
|
||||
<%= simple_form_for([:settings,@settings_product]) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<div class="form-inputs">
|
||||
<%= 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 %>
|
||||
<label><%= f.check_box :taxable %>Taxable</label>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<%= f.button :submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -0,0 +1,2 @@
|
||||
json.extract! settings_product, :id, :created_at, :updated_at
|
||||
json.url settings_product_url(settings_product, format: :json)
|
||||
10
app/views/settings/products/edit.html.erb
Normal file
10
app/views/settings/products/edit.html.erb
Normal file
@@ -0,0 +1,10 @@
|
||||
<div class="span12">
|
||||
<div class="page-header">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="<%= root_path %>">Home</a></li>
|
||||
<li><a href="<%= settings_products_path %>">Products</a></li>
|
||||
<li>Edit</li>
|
||||
</ul>
|
||||
</div>
|
||||
<%= render 'form', settings_product: @settings_product %>
|
||||
</div>
|
||||
45
app/views/settings/products/index.html.erb
Normal file
45
app/views/settings/products/index.html.erb
Normal file
@@ -0,0 +1,45 @@
|
||||
<div class="page-header">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="<%= %>">Home</a></li>
|
||||
<li>Product</li>
|
||||
<span style="float: right">
|
||||
<%= link_to t('.new', :default => t("helpers.links.new")),new_settings_product_path,:class => 'btn btn-primary btn-sm' %>
|
||||
</span>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<div class="card">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Item Code</th>
|
||||
<th>Name</th>
|
||||
<th>Alt Name</th>
|
||||
<th>Unit Price</th>
|
||||
<!-- <th style="width:20%">image_path</th> -->
|
||||
<th>Description</th>
|
||||
<th>Information</th>
|
||||
<th>Taxable</th>
|
||||
<th colspan="3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @settings_products.each do |settings_product| %>
|
||||
<tr>
|
||||
<td><%= settings_product.item_code %></td>
|
||||
<td><%= settings_product.name %></td>
|
||||
<td><%= settings_product.alt_name %></td>
|
||||
<td><%= settings_product.unit_price %></td>
|
||||
<td><%= settings_product.description %></td>
|
||||
<td><%= settings_product.information %></td>
|
||||
<td><%= settings_product.taxable %></td>
|
||||
<td><%= link_to 'Show', settings_product_path(settings_product) %></td>
|
||||
<td><%= link_to 'Edit', edit_settings_product_path(settings_product) %></td>
|
||||
<td><%= link_to 'Destroy', settings_product_path(settings_product), method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
1
app/views/settings/products/index.json.jbuilder
Normal file
1
app/views/settings/products/index.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
||||
json.array! @settings_products, partial: 'settings_products/settings_product', as: :settings_product
|
||||
26
app/views/settings/products/new.html.erb
Normal file
26
app/views/settings/products/new.html.erb
Normal file
@@ -0,0 +1,26 @@
|
||||
<div class="span12">
|
||||
<div class="page-header">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="<%= root_path %>">Home</a></li>
|
||||
<li><a href="<%= settings_products_path %>">Products</a></li>
|
||||
<li>New</li>
|
||||
</ul>
|
||||
</div>
|
||||
<%= render 'form', settings_product: @settings_product %>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function randomNumber(len) {
|
||||
var sValidCharacters = "01234ABCDEFGHIJabcdefghijk56789lmnKLMNOPQRSTUVWXYZopqrstuvwxyz";
|
||||
var sCharCode = "";
|
||||
|
||||
for (i = 1; i <= len; i++) {
|
||||
sCharCode = sCharCode + sValidCharacters.charAt(parseInt(Math.random() * sValidCharacters.length));
|
||||
if ((i === 4) || (i === 8)) {
|
||||
sCharCode = sCharCode + "-";
|
||||
}
|
||||
}
|
||||
return sCharCode;
|
||||
}
|
||||
document.getElementById("item_code").value = randomNumber(12);
|
||||
</script>
|
||||
33
app/views/settings/products/show.html.erb
Normal file
33
app/views/settings/products/show.html.erb
Normal file
@@ -0,0 +1,33 @@
|
||||
<div class="page-header">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="<%= root_path %>">Home</a></li>
|
||||
<li><a href="<%= settings_products_path %>">Products</a></li>
|
||||
|
||||
<span style="float: right">
|
||||
</span>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-block">
|
||||
<h4 class="card-title">Product</h4>
|
||||
<table class="table">
|
||||
|
||||
<tbody>
|
||||
|
||||
<tr><td style="width:20%">Item code</td><td><%= @settings_product.item_code %></td></tr>
|
||||
<tr><td style="width:20%">Name</td><td><%= @settings_product.name %></td></tr>
|
||||
<tr><td style="width:20%">Alt name</td><td><%= @settings_product.alt_name %></td></tr>
|
||||
<tr><td style="width:20%">Unit price</td><td><%= @settings_product.unit_price %></td></tr>
|
||||
<tr><td style="width:20%">Image path</td><td><%= image_tag @settings_product.image_path, :size => '200x200'%></td></tr>
|
||||
<tr><td style="width:20%">Description</td><td><%= @settings_product.description %></td></tr>
|
||||
<tr><td style="width:20%">Information</td><td><%= @settings_product.information %></td></tr>
|
||||
<tr><td style="width:20%">Taxable</td><td><%= @settings_product.taxable %></td></tr>
|
||||
<tr><td style="width:20%"><%= link_to 'Edit', edit_settings_product_path(@settings_product) %></td><td><%= link_to 'Destroy', settings_product_path(@settings_product), method: :delete, data: { confirm: 'Are you sure?' } %></td></tr>
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
1
app/views/settings/products/show.json.jbuilder
Normal file
1
app/views/settings/products/show.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
||||
json.partial! "settings_products/settings_product", settings_product: @settings_product
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user