diff --git a/.idea/workspace.xml b/.idea/workspace.xml index de9b54ce..70f67cc7 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,11 +2,13 @@ + - - - - + + + + + @@ -23,74 +25,41 @@ - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -106,6 +75,13 @@ void red origami + order + orders + table + tables + sale_edit#edit + @saleobj + edit @@ -132,25 +108,35 @@ @@ -161,10 +147,10 @@ DEFINITION_ORDER - @@ -184,8 +170,21 @@ - + + + + + + + + + + @@ -297,11 +296,167 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + @@ -397,6 +539,7 @@ + @@ -732,34 +875,36 @@ - + + + - - + - + - + - + - + - + - + @@ -774,24 +919,6 @@ - - - - - - - - - - - - - - - - - - @@ -805,13 +932,6 @@ - - - - - - - @@ -819,13 +939,6 @@ - - - - - - - @@ -842,14 +955,6 @@ - - - - - - - - @@ -857,27 +962,10 @@ - - - - - - - - - - - - - - - - - @@ -885,15 +973,6 @@ - - - - - - - - - @@ -905,59 +984,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -965,23 +995,6 @@ - - - - - - - - - - - - - - - - - @@ -989,31 +1002,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1021,7 +1009,6 @@ - @@ -1029,7 +1016,6 @@ - @@ -1037,7 +1023,6 @@ - @@ -1045,17 +1030,240 @@ - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 1c5ada90..2db849ab 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -5,7 +5,6 @@ @import "jquery-ui"; @import "bootstrap-datepicker3"; - /* Show it is fixed to the top */ // body { // min-height: 75rem; diff --git a/app/controllers/origami/commissions_controller.rb b/app/controllers/origami/commissions_controller.rb index fdd1bf73..f18bd11e 100644 --- a/app/controllers/origami/commissions_controller.rb +++ b/app/controllers/origami/commissions_controller.rb @@ -15,10 +15,12 @@ class Origami::CommissionsController < BaseOrigamiController # GET /commissions/new def new @commission = Commission.new + @products = MenuItem.all end # GET /commissions/1/edit def edit + @products = MenuItem.all end # POST /commissions @@ -61,6 +63,21 @@ class Origami::CommissionsController < BaseOrigamiController end end + def load_commissioners + sale_id = params[:sale_id] + @table_id = params[:table_id] + @saleobj = Sale.find(sale_id) + + @commissioners = [] + end + + def select_sale_item + byebug + sale_item_id = params[:sale_item_id] + @sale_item = SaleItem.find_by_sale_item_id(sale_item_id) + @commissioners = Commissioner.active.all + end + private # Use callbacks to share common setup or constraints between actions. def set_commission diff --git a/app/models/commission.rb b/app/models/commission.rb index 8d14db70..df11eb24 100644 --- a/app/models/commission.rb +++ b/app/models/commission.rb @@ -1,2 +1,4 @@ class Commission < ApplicationRecord + belongs_to :menu_item, foreign_key: 'product_id' + has_many :commissioners end diff --git a/app/models/commissioner.rb b/app/models/commissioner.rb index c6d4ab4c..ac199468 100644 --- a/app/models/commissioner.rb +++ b/app/models/commissioner.rb @@ -1,3 +1,5 @@ class Commissioner < ApplicationRecord - has_many :employees + belongs_to :employee, foreign_key: 'emp_id' + belongs_to :commission, foreign_key: 'commission_type' + scope :active, -> { where(is_active: true) } end diff --git a/app/models/employee.rb b/app/models/employee.rb index a6b52f21..a12521cb 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -1,7 +1,8 @@ class Employee < ApplicationRecord has_secure_password - belongs_to :commissioner + has_many :commissioners has_many :shit_sales + validates_presence_of :name, :role validates_presence_of :password, :on => [:create] validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 8213ae88..c581a7b0 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -3,6 +3,8 @@ class MenuItem < ApplicationRecord belongs_to :menu_category, :optional => true has_many :menu_item_instances + has_many :commissions + # belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id", :optional => true # has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id" belongs_to :account diff --git a/app/models/product.rb b/app/models/product.rb index 8f6811e2..5aff41f5 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,6 +1,6 @@ class Product < ApplicationRecord validates_presence_of :name - + # Product Image Uploader mount_uploader :image_path, ProductImageUploader end diff --git a/app/views/origami/commissioners/_commissioners_form.html.erb b/app/views/origami/commissioners/_commissioners_form.html.erb new file mode 100644 index 00000000..10637a82 --- /dev/null +++ b/app/views/origami/commissioners/_commissioners_form.html.erb @@ -0,0 +1,16 @@ +
+
+
COMMISSIONERS
+
+
+
+ <% @commissioners.each do |commissioner| %> +
+
+ <%= commissioner.name %> +
+
+ <% end %> +
+
+
diff --git a/app/views/origami/commissioners/_form.html.erb b/app/views/origami/commissioners/_form.html.erb index 4c2a17f8..3923d564 100644 --- a/app/views/origami/commissioners/_form.html.erb +++ b/app/views/origami/commissioners/_form.html.erb @@ -5,8 +5,9 @@
<%= f.input :name %> <%= f.label :emp_id %> - <%= f.collection_select :emp_id, Employee.all.order('name asc'), :emp_id, :name, {prompt: "Select an Employee"}, {class: "form-control"} %>
- <%= f.input :commission_type %> + <%= f.collection_select :emp_id, Employee.all.order('name asc'), :id, :name, {prompt: 'Select an Employee'}, {class: "form-control"} %>
+ <%= f.label :commission_type %> + <%= f.collection_select :commission_type, Commission.all, :id, :product_id, {prompt: 'Select Commission Type'}, class: 'form-control' %>
diff --git a/app/views/origami/commissioners/index.html.erb b/app/views/origami/commissioners/index.html.erb index baadb225..dfef0320 100644 --- a/app/views/origami/commissioners/index.html.erb +++ b/app/views/origami/commissioners/index.html.erb @@ -1,11 +1,11 @@
@@ -23,22 +23,18 @@ <% @commissioners.each do |commissioner| %> - - <%= commissioner.name %> - - <% if Employee.exists? %> - <% employee = Employee.where('emp_id=?',commissioner.emp_id) %> - <%= employee[0].name %> - <% end %> - - - <%= commissioner.commission_type %> - <%= commissioner.is_active %> - <%= link_to 'Show', origami_commissioner_path(commissioner) %> - <%= link_to 'Edit', edit_origami_commissioner_path(commissioner) %> - <%= link_to 'Destroy', origami_commissioner_path(commissioner), method: :delete, data: { confirm: 'Are you sure?' } %> - + + <%= commissioner.name %> + + <%= commissioner.employee.name rescue '-' %> + + <%= commissioner.commission.menu_item.name rescue '-' %> + <%= commissioner.is_active %> + <%= link_to 'Show', origami_commissioner_path(commissioner) %> + <%= link_to 'Edit', edit_origami_commissioner_path(commissioner) %> + <%= link_to 'Destroy', origami_commissioner_path(commissioner), method: :delete, data: {confirm: 'Are you sure?'} %> + <% end %> - + diff --git a/app/views/origami/commissioners/show.html.erb b/app/views/origami/commissioners/show.html.erb index 83d5442b..1f9b2780 100644 --- a/app/views/origami/commissioners/show.html.erb +++ b/app/views/origami/commissioners/show.html.erb @@ -21,16 +21,12 @@ Employee Name - <% if Employee.exists? %> - <% employee = Employee.where('emp_id=?', @commissioner.emp_id) %> - <%= employee[0].name %> - <% end %> - + <%= @commissioner.employee.name rescue '-' %> Commission Type - <%= @commissioner.commission_type %> + <%= @commissioner.commission.product.name rescue '-' %> Active diff --git a/app/views/origami/commissions/_form.html.erb b/app/views/origami/commissions/_form.html.erb index a5c0d2c0..1f7fee4a 100644 --- a/app/views/origami/commissions/_form.html.erb +++ b/app/views/origami/commissions/_form.html.erb @@ -4,11 +4,11 @@
<%= f.label :product_id %> - <%= f.collection_select :product_id, Product.all.order('name asc'), :id, :name, {prompt: "Select a Product"}, {class: "form-control"} %>
+ <%= f.collection_select :product_id, @products, :id, :name, {prompt: 'Select a Product'}, {class: 'form-control'} %>
<%= f.input :amount %> - <%= f.input :commission_type, :collection => [:percentage, :net_amount] %> + <%= f.input :commission_type, :collection => ['Percentage','Net Amount'], prompt: 'Select Commission Type', class: 'form-control' %> -
+
<%= link_to 'Back', origami_commissions_path, class: 'btn btn-success' %> <%= f.button :submit, class: 'btn btn-info' %> diff --git a/app/views/origami/commissions/index.html.erb b/app/views/origami/commissions/index.html.erb index e5a83639..da589347 100644 --- a/app/views/origami/commissions/index.html.erb +++ b/app/views/origami/commissions/index.html.erb @@ -1,11 +1,11 @@
@@ -23,22 +23,16 @@ <% @commissions.each do |commission| %> - - - <% if Product.exists? %> - <% product = Product.find(commission.product_id) %> - <%= product.name %> - <% end %> - - - <%= commission.amount %> - <%= commission.commission_type %> - <%= commission.is_active %> - <%= link_to 'Show', origami_commission_path(commission) %> - <%= link_to 'Edit', edit_origami_commission_path(commission) %> - <%= link_to 'Destroy', origami_commission_path(commission), method: :delete, data: { confirm: 'Are you sure?' } %> - + + <%= commission.menu_item.name rescue '-' %> + <%= commission.amount rescue '-' %> + <%= commission.commission_type rescue '-' %> + <%= commission.is_active rescue '-' %> + <%= link_to 'Show', origami_commission_path(commission) %> + <%= link_to 'Edit', edit_origami_commission_path(commission) %> + <%= link_to 'Destroy', origami_commission_path(commission), method: :delete, data: {confirm: 'Are you sure?'} %> + <% end %> - +
diff --git a/app/views/origami/commissions/load_commissioners.html.erb b/app/views/origami/commissions/load_commissioners.html.erb new file mode 100644 index 00000000..5252b1bd --- /dev/null +++ b/app/views/origami/commissions/load_commissioners.html.erb @@ -0,0 +1,217 @@ +
+ +
+ <%= render 'origami/commissioners/commissioners_form', commissioners: @commissioners %> +
+ + +
+
+
+
INVOICE DETAILS
+
+
+
+
+

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

+
+
+

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 + %> + + + + + + + <% + end + end + %> + +
#ItemsQTY + + Price + +
<%= count %> + <%= sale_item.product_name %> + + <%= sale_item.qty %> + + <%= sale_item.unit_price %> +
+
+ +
+
+
+ + +
+ + + +
+
+ diff --git a/app/views/origami/commissions/show.html.erb b/app/views/origami/commissions/show.html.erb index da04710e..439e2c45 100644 --- a/app/views/origami/commissions/show.html.erb +++ b/app/views/origami/commissions/show.html.erb @@ -16,12 +16,7 @@ Product Name - - <% if Product.exists? %> - <% product = Product.find(@commission.product_id) %> - <%= product.name %> - <% end %> - + <%= @commission.menu_item.name rescue '-' %> Amount diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index a79c1ce1..1e39bd8d 100644 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -572,6 +572,12 @@ window.location.href = '/origami/table/' + dining_id + "/sale/" + sale_id + "/edit"; }); + $('#commissions').on('click', function () { + var dining_id = "<%= @dining.id %>" + var sale_id = "<%= @obj_sale.sale_id rescue "" %>" + window.location.href = '/origami/table/' + dining_id + "/sale/" + sale_id + "/load_commissioners"; + }); + $('#void').on('click', function () { var sure = confirm("Are you sure want to Void"); if (sure == true) { diff --git a/config/routes.rb b/config/routes.rb index 7276e31f..8277e58f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -86,6 +86,9 @@ Rails.application.routes.draw do post 'item_void_cancel' => "sale_edit#item_void_cancel" post 'cancel_all_void' => 'sale_edit#cancel_all_void' post 'apply_void' => 'sale_edit#apply_void' + # commissions + get '/table/:table_id/sale/:sale_id/load_commissioners' => 'commissions#load_commissioners', as: 'load_commissioners' + post 'select_sale_item' => 'commissions#select_sale_item' get 'table/:dining_id/movetable' => "movetable#move_dining" get 'table/:dining_id/moveroom' => "moveroom#move_dining"