+
+
+
diff --git a/Gemfile b/Gemfile
index 44a85e51..c0783d50 100644
--- a/Gemfile
+++ b/Gemfile
@@ -53,6 +53,7 @@ gem 'to_xls-rails'
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-ui-rails'
+gem 'jquery-datatables-rails', '~> 3.4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
diff --git a/Gemfile.lock b/Gemfile.lock
index f2d875dd..8fca836c 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -89,6 +89,11 @@ GEM
jbuilder (2.7.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
+ jquery-datatables-rails (3.4.0)
+ actionpack (>= 3.1)
+ jquery-rails
+ railties (>= 3.1)
+ sass-rails
jquery-datetimepicker-rails (2.4.1.0)
jquery-rails (4.3.1)
rails-dom-testing (>= 1, < 3)
@@ -266,6 +271,7 @@ DEPENDENCIES
font-awesome-rails
httparty (~> 0.15.5)
jbuilder (~> 2.5)
+ jquery-datatables-rails (~> 3.4.0)
jquery-datetimepicker-rails
jquery-rails
jquery-ui-rails
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 675bca2e..89f95729 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -21,6 +21,7 @@
//= require jquery-ui
//= require bootstrap-datepicker
//= require jquery.datetimepicker
+//= require dataTables/jquery.dataTables
$(document).on('turbolinks:load', function() {
$('.datepicker').datepicker({
diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss
index 6ff7113c..6cd24771 100644
--- a/app/assets/stylesheets/application.scss
+++ b/app/assets/stylesheets/application.scss
@@ -5,6 +5,7 @@
@import "jquery-ui";
@import "bootstrap-datepicker3";
@import "jquery.datetimepicker";
+@import "dataTables/jquery.dataTables";
/* Show it is fixed to the top */
// body {
diff --git a/app/controllers/settings/commissioners_controller.rb b/app/controllers/settings/commissioners_controller.rb
index 26560c01..d4d1fa53 100644
--- a/app/controllers/settings/commissioners_controller.rb
+++ b/app/controllers/settings/commissioners_controller.rb
@@ -27,13 +27,19 @@ class Settings::CommissionersController < ApplicationController
def create
@commissioner = Commissioner.new(commissioner_params)
@commissioner.created_by = current_user.id
+ unless @commissioner.joined_date.nil?
+ @commissioner.joined_date = @commissioner.joined_date.utc.getlocal.strftime('%Y-%b-%d')
+ end
+ unless @commissioner.resigned_date.nil?
+ @commissioner.resigned_date = @commissioner.resigned_date.utc.getlocal.strftime('%Y-%b-%d')
+ end
respond_to do |format|
if @commissioner.save
- format.html { redirect_to settings_commissioners_path , notice: 'Commissioner was successfully created.' }
- format.json { render :show, status: :created, location: @commissioner }
+ format.html {redirect_to settings_commissioners_path, notice: 'Commissioner was successfully created.'}
+ format.json {render :show, status: :created, location: @commissioner}
else
- format.html { render :new }
- format.json { render json: @commissioner.errors, status: :unprocessable_entity }
+ format.html {render :new}
+ format.json {render json: @commissioner.errors, status: :unprocessable_entity}
end
end
end
@@ -43,11 +49,11 @@ class Settings::CommissionersController < ApplicationController
def update
respond_to do |format|
if @commissioner.update(commissioner_params)
- format.html { redirect_to settings_commissioner_path(@commissioner) , notice: 'Commissioner was successfully updated.' }
- format.json { render :show, status: :ok, location: @commissioner }
+ format.html {redirect_to settings_commissioner_path(@commissioner), notice: 'Commissioner was successfully updated.'}
+ format.json {render :show, status: :ok, location: @commissioner}
else
- format.html { render :edit }
- format.json { render json: @commissioner.errors, status: :unprocessable_entity }
+ format.html {render :edit}
+ format.json {render json: @commissioner.errors, status: :unprocessable_entity}
end
end
end
@@ -57,19 +63,31 @@ class Settings::CommissionersController < ApplicationController
def destroy
@commissioner.destroy
respond_to do |format|
- format.html { redirect_to settings_commissioners_path , notice: 'Commissioner was successfully destroyed.' }
- format.json { head :no_content }
+ format.html {redirect_to settings_commissioners_path, notice: 'Commissioner was successfully destroyed.'}
+ format.json {head :no_content}
end
end
- private
- # Use callbacks to share common setup or constraints between actions.
- def set_commissioner
- @commissioner = Commissioner.find(params[:id])
+ def get_transaction_by_commissioner
+ commissioner_id = params[:commissioner_id]
+ @transactions = []
+ @product_commissions = ProductCommission.where(commissioner_id: commissioner_id).order('updated_at desc')
+ @product_commissions.each_with_index do |p, i|
+ @transactions[i] = []
+ @transactions[i] << p
+ @transactions[i] << p.commission.menu_item.name
end
+ render json: @transactions
+ end
- # Never trust parameters from the scary internet, only allow the white list through.
- def commissioner_params
- params.require(:commissioner).permit(:name,:emp_id,:created_by,:commission_id,:joined_date,:resigned_date, :is_active)
- end
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_commissioner
+ @commissioner = Commissioner.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def commissioner_params
+ params.require(:commissioner).permit(:name, :emp_id, :created_by, :commission_id, :joined_date, :resigned_date, :is_active)
+ end
end
diff --git a/app/models/commission.rb b/app/models/commission.rb
index 2a724d7e..055d9618 100644
--- a/app/models/commission.rb
+++ b/app/models/commission.rb
@@ -1,5 +1,16 @@
class Commission < ApplicationRecord
+ self.primary_key = 'commission_id'
+
+ # primary key - need to be unique
+ before_create :generate_custom_id
+
belongs_to :menu_item, foreign_key: 'product_code'
has_many :commissioners
has_many :product_commissions
+
+ private
+
+ def generate_custom_id
+ self.commission_id = SeedGenerator.generate_id(self.class.name, 'COM')
+ end
end
diff --git a/app/models/product_commission.rb b/app/models/product_commission.rb
index 59e64b79..1f3b6423 100644
--- a/app/models/product_commission.rb
+++ b/app/models/product_commission.rb
@@ -5,7 +5,5 @@ class ProductCommission < ApplicationRecord
belongs_to :sale_item, foreign_key: 'sale_item_id'
belongs_to :sale, foreign_key: 'sale_id'
- def self.check_product_commission(sale_item_id)
- end
end
diff --git a/app/views/settings/commissioners/_form.html.erb b/app/views/settings/commissioners/_form.html.erb
index c17e59a3..e2d9d120 100644
--- a/app/views/settings/commissioners/_form.html.erb
+++ b/app/views/settings/commissioners/_form.html.erb
@@ -10,6 +10,10 @@
<%= f.label :commission_id, 'Commission' %>
<%= f.select :commission_id, Commission.all.map {|l| [l.menu_item.name, l.id]}, {prompt: 'Select a Product'}, {class: 'form-control'} %>
+ <%= f.label :joined_date %>
+ <%= f.text_field :joined_date, {class: 'form-control', id: 'joined_date', readonly: true} %>
+ <%= f.label :resigned_date %>
+ <%= f.text_field :resigned_date, {class: 'form-control', id: 'resigned_date', readonly: true} %>
@@ -20,3 +24,19 @@
<% end %>
+
+
diff --git a/app/views/settings/commissioners/index.html.erb b/app/views/settings/commissioners/index.html.erb
index f0229432..e6c1fdc9 100644
--- a/app/views/settings/commissioners/index.html.erb
+++ b/app/views/settings/commissioners/index.html.erb
@@ -16,8 +16,10 @@
Name |
Employee Name |
Commission type |
+ Joined Date |
+ Resigned Date |
Active |
- |
+ |
@@ -29,6 +31,8 @@
<%= commissioner.employee.name rescue '-' %>
<%= commissioner.commission.menu_item.name rescue '-' %> |
+ <%= commissioner.joined_date.utc.getlocal.strftime('%Y-%b-%d') rescue '-' %> |
+ <%= commissioner.resigned_date.utc.getlocal.strftime('%Y-%b-%d') rescue '-' %> |
<%= commissioner.is_active %> |
<%= link_to 'Show', settings_commissioner_path(commissioner) %> |
<%= link_to 'Edit', edit_settings_commissioner_path(commissioner) %> |
diff --git a/app/views/settings/commissioners/show.html.erb b/app/views/settings/commissioners/show.html.erb
index 5af55c54..7f2005c6 100644
--- a/app/views/settings/commissioners/show.html.erb
+++ b/app/views/settings/commissioners/show.html.erb
@@ -7,41 +7,126 @@
-
-
-
Commissioner
-
-
+
+
+
-
- | Name |
- <%= @commissioner.name %> |
-
-
- | Employee Name |
-
- <%= @commissioner.employee.name rescue '-' %>
- |
-
-
- | Commission Type |
- <%= @commissioner.commission.menu_item.name rescue '-' %> |
-
-
- | Active |
- <%= @commissioner.is_active %> |
-
-
- | Created By |
- <%= Employee.find(@commissioner.created_by).name %> |
-
-
-
- <%= link_to 'Back', settings_commissioners_path, class: 'btn btn-success' %>
- <%= link_to 'Edit', edit_settings_commissioner_path(@commissioner), class: 'btn btn-info' %>
- <%= link_to 'Destroy', settings_commissioner_path(@commissioner), method: :delete, data: {confirm: 'Are you sure?'}, class: 'btn btn-danger' %>
+
+
+
+
+
+
+
+
+ | Name |
+ <%= @commissioner.name %> |
+
+
+ | Employee Name |
+ <%= @commissioner.employee.name rescue '-' %> |
+
+
+ | Commission Type |
+ <%= @commissioner.commission.menu_item.name rescue '-' %> |
+
+
+ | Joined Date |
+ <%= @commissioner.joined_date.utc.getlocal.strftime('%Y-%b-%d') rescue '-' %> |
+
+
+ | Resigned Date |
+ <%= @commissioner.resigned_date.utc.getlocal.strftime('%Y-%b-%d') rescue '-' %> |
+
+
+ | Active |
+ <%= @commissioner.is_active %> |
+
+
+ | Created By |
+ <%= Employee.find(@commissioner.created_by).name %> |
+
+
+
+ <%= link_to 'Back', settings_commissioners_path, class: 'btn btn-success' %>
+ <%= link_to 'Edit', edit_settings_commissioner_path(@commissioner), class: 'btn btn-info' %>
+ <%= link_to 'Destroy', settings_commissioner_path(@commissioner), method: :delete, data: {confirm: 'Are you sure?'}, class: 'btn btn-danger' %>
+
+
-
+
+
+
+
+
+
+
+
+ | <%= 'Product Type' %> |
+ <%= 'Product Name' %> |
+ <%= 'Qty' %> |
+ <%= 'Price' %> |
+ <%= 'Amount' %> |
+ <%= 'Date' %> |
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/views/settings/commissions/index.html.erb b/app/views/settings/commissions/index.html.erb
index 63304d2f..a30fda08 100644
--- a/app/views/settings/commissions/index.html.erb
+++ b/app/views/settings/commissions/index.html.erb
@@ -14,8 +14,8 @@
| Product Name |
+ Commission Type |
Amount |
- Commission type |
Active |
|
@@ -25,8 +25,8 @@
<% @commissions.each do |commission| %>
| <%= commission.menu_item.name rescue '-' %> |
- <%= commission.amount rescue '-' %> |
<%= commission.commission_type rescue '-' %> |
+ <%= commission.amount rescue '-' %> |
<%= commission.is_active rescue '-' %> |
<%= link_to 'Show', settings_commissions_path(commission) %> |
<%= link_to 'Edit', edit_settings_commission_path(commission) %> |
diff --git a/config/routes.rb b/config/routes.rb
index 7008cc47..3b88e88e 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -296,6 +296,8 @@ Rails.application.routes.draw do
resources :commissions
resources :commissioners
+ get '/get_transactions_by_commissioner' => 'commissioners#get_transaction_by_commissioner', as:'get_transaction_by_commissioner'
+
end
# commissions
diff --git a/db/migrate/20170825034141_create_product_commissions.rb b/db/migrate/20170825034141_create_product_commissions.rb
index d8686b69..f083bf68 100644
--- a/db/migrate/20170825034141_create_product_commissions.rb
+++ b/db/migrate/20170825034141_create_product_commissions.rb
@@ -4,7 +4,7 @@ class CreateProductCommissions < ActiveRecord::Migration[5.1]
create_table :product_commissions do |t|
t.string :product_type
t.string :product_code
- t.integer :commission_id
+ t.string :commission_id
t.integer :commissioner_id
t.decimal :qty, precision: 10, scale: 2, default: 0.00
t.string :sale_id
diff --git a/db/migrate/20170825090115_create_commissioners.rb b/db/migrate/20170825090115_create_commissioners.rb
index fe32a35a..1794b5c7 100644
--- a/db/migrate/20170825090115_create_commissioners.rb
+++ b/db/migrate/20170825090115_create_commissioners.rb
@@ -5,7 +5,7 @@ class CreateCommissioners < ActiveRecord::Migration[5.1]
t.string :name
t.string :emp_id
t.string :created_by
- t.integer :commission_id
+ t.string :commission_id
t.datetime :joined_date
t.datetime :resigned_date
t.boolean :is_active, default: true
diff --git a/db/migrate/20170825093252_create_commissions.rb b/db/migrate/20170825093252_create_commissions.rb
index 74706f3a..8c344fbc 100644
--- a/db/migrate/20170825093252_create_commissions.rb
+++ b/db/migrate/20170825093252_create_commissions.rb
@@ -1,7 +1,9 @@
class CreateCommissions < ActiveRecord::Migration[5.1]
# rake db:migrate:down VERSION=20170825093252
def change
- create_table :commissions do |t|
+ create_table :commissions, id: false do |t|
+ t.string :commission_id, limit: 16, primary_key: true # custom primary key
+
t.string :product_type
t.string :product_code
t.string :commission_type