diff --git a/.idea/workspace.xml b/.idea/workspace.xml index de9b54ce..feb2e6c0 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,10 +3,16 @@ - - - + + + + + + + + + @@ -23,74 +29,91 @@ - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - - + + - - + + + + + + + + + + + + @@ -106,6 +129,13 @@ void red origami + order + orders + table + tables + sale_edit#edit + @saleobj + edit @@ -132,25 +162,31 @@ @@ -161,10 +197,10 @@ DEFINITION_ORDER - @@ -184,8 +220,21 @@ - + + + + + + + + + + @@ -297,11 +346,167 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + @@ -397,6 +589,7 @@ + @@ -732,35 +925,37 @@ - + + + - - + - + - + - - + - + - - + + - + + @@ -774,14 +969,6 @@ - - - - - - - - @@ -805,13 +992,6 @@ - - - - - - - @@ -819,13 +999,6 @@ - - - - - - - @@ -842,14 +1015,6 @@ - - - - - - - - @@ -857,27 +1022,10 @@ - - - - - - - - - - - - - - - - - @@ -885,15 +1033,6 @@ - - - - - - - - - @@ -905,59 +1044,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -965,7 +1055,6 @@ - @@ -973,7 +1062,6 @@ - @@ -981,7 +1069,6 @@ - @@ -989,31 +1076,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1021,7 +1083,6 @@ - @@ -1029,7 +1090,6 @@ - @@ -1037,7 +1097,6 @@ - @@ -1045,17 +1104,185 @@ - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/controllers/origami/commissions_controller.rb b/app/controllers/origami/commissions_controller.rb index fdd1bf73..a10e59c6 100644 --- a/app/controllers/origami/commissions_controller.rb +++ b/app/controllers/origami/commissions_controller.rb @@ -61,6 +61,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..48f73f87 100644 --- a/app/models/commission.rb +++ b/app/models/commission.rb @@ -1,2 +1,4 @@ class Commission < ApplicationRecord + belongs_to :product, 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/product.rb b/app/models/product.rb index 8f6811e2..fed8ee97 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,6 +1,7 @@ class Product < ApplicationRecord validates_presence_of :name - + has_many :commissions + # 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..cf06ed6d 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.product.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/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/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"