product commission transaction in commissioner

This commit is contained in:
Zin Lin Phyo
2017-08-28 18:17:22 +06:30
parent 36b4b15688
commit 1cbea173df
17 changed files with 460 additions and 350 deletions

View File

@@ -21,6 +21,7 @@
//= require jquery-ui
//= require bootstrap-datepicker
//= require jquery.datetimepicker
//= require dataTables/jquery.dataTables
$(document).on('turbolinks:load', function() {
$('.datepicker').datepicker({

View File

@@ -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 {

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -10,6 +10,10 @@
<%= f.label :commission_id, 'Commission' %><br/>
<%= f.select :commission_id, Commission.all.map {|l| [l.menu_item.name, l.id]}, {prompt: 'Select a Product'}, {class: 'form-control'} %>
<br/>
<%= f.label :joined_date %><br/>
<%= f.text_field :joined_date, {class: 'form-control', id: 'joined_date', readonly: true} %><br/>
<%= f.label :resigned_date %><br/>
<%= f.text_field :resigned_date, {class: 'form-control', id: 'resigned_date', readonly: true} %><br/>
<label><%= f.check_box :is_active %> Active </label>
</div>
<br/>
@@ -20,3 +24,19 @@
</div>
<% end %>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#joined_date').datepicker({
format: 'yyyy-mm-dd',
autoclose: true
});
$('#resigned_date').datepicker({
format: 'yyyy-mm-dd',
autoclose: true
});
});
</script>

View File

@@ -16,8 +16,10 @@
<th>Name</th>
<th>Employee Name</th>
<th>Commission type</th>
<th>Joined Date</th>
<th>Resigned Date</th>
<th>Active</th>
<th colspan="3"></th>
<th colspan="4"></th>
</tr>
</thead>
@@ -29,6 +31,8 @@
<%= commissioner.employee.name rescue '-' %>
</td>
<td><%= commissioner.commission.menu_item.name rescue '-' %></td>
<td><%= commissioner.joined_date.utc.getlocal.strftime('%Y-%b-%d') rescue '-' %></td>
<td><%= commissioner.resigned_date.utc.getlocal.strftime('%Y-%b-%d') rescue '-' %></td>
<td><%= commissioner.is_active %></td>
<td><%= link_to 'Show', settings_commissioner_path(commissioner) %></td>
<td><%= link_to 'Edit', edit_settings_commissioner_path(commissioner) %></td>

View File

@@ -7,41 +7,126 @@
</span>
</ul>
</div>
<div class="card">
<div class="card-block">
<h4 class="card-title">Commissioner</h4>
<table class="table">
<tbody>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#info" role="tab">Info</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#transaction" id="transaction_tab" role="tab">Transaction</a>
</li>
</ul>
<!-- Nav tabs - End -->
<tr>
<td style="width:20%">Name</td>
<td><%= @commissioner.name %></td>
</tr>
<tr>
<td style="width:20%">Employee Name</td>
<td>
<%= @commissioner.employee.name rescue '-' %>
</td>
</tr>
<tr>
<td style="width:20%">Commission Type</td>
<td><%= @commissioner.commission.menu_item.name rescue '-' %></td>
</tr>
<tr>
<td style="width:20%">Active</td>
<td><%= @commissioner.is_active %></td>
</tr>
<tr>
<td style="width:20%">Created By</td>
<td><%= Employee.find(@commissioner.created_by).name %></td>
</tr>
</tbody>
</table>
<%= 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' %>
<div class="tab-content">
<!--- Panel 0 - Info -->
<div class="tab-pane active" id="info" role="tabpanel" style="max-height:670px; overflow:auto">
<div class="card">
<div class="card-block">
<table class="table">
<tbody>
<tr>
<td style="width:20%">Name</td>
<td><%= @commissioner.name %></td>
</tr>
<tr>
<td style="width:20%">Employee Name</td>
<td><%= @commissioner.employee.name rescue '-' %></td>
</tr>
<tr>
<td style="width:20%">Commission Type</td>
<td><%= @commissioner.commission.menu_item.name rescue '-' %></td>
</tr>
<tr>
<td style="width:20%">Joined Date</td>
<td><%= @commissioner.joined_date.utc.getlocal.strftime('%Y-%b-%d') rescue '-' %></td>
</tr>
<tr>
<td style="width:20%">Resigned Date</td>
<td><%= @commissioner.resigned_date.utc.getlocal.strftime('%Y-%b-%d') rescue '-' %></td>
</tr>
<tr>
<td style="width:20%">Active</td>
<td><%= @commissioner.is_active %></td>
</tr>
<tr>
<td style="width:20%">Created By</td>
<td><%= Employee.find(@commissioner.created_by).name %></td>
</tr>
</tbody>
</table>
<%= 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' %>
</div>
</div>
</div>
</div>
<!--- Panel 1 - Transaction -->
<div class="tab-pane" id="transaction" role="tabpanel" style="max-height:670px; overflow:auto">
<div class="card">
<div class="card-block">
<table class="table" id="myTable">
<thead>
<tr>
<th><%= 'Product Type' %></th>
<th><%= 'Product Name' %></th>
<th><%= 'Qty' %></th>
<th><%= 'Price' %></th>
<th><%= 'Amount' %></th>
<th><%= 'Date' %></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<br/>
</div>
<script type="text/javascript">
$(document).ready(function () {
$("#transaction_tab").click(function () {
get_transaction();
});
function get_transaction() {
var commissioner_id = <%= @commissioner.id %>
paramlist = 'commissioner_id=' + commissioner_id ;
$.ajax({
type: 'GET',
url: '<%= settings_get_transaction_by_commissioner_path() %>',
data: paramlist,
success: function (data) {
// $('#myTable').DataTable().destroy();
$('#myTable tbody > tr').remove();
$.each(data, function (i, item) {
tr = "<tr>" + "<td>" + data[i][0].product_type + "</td>" + "<td>" + data[i][1] + "</td>" + "<td>" + data[i][0].qty + "</td>" + "<td>" + data[i][0].price + "</td>" + "<td>" + data[i][0].amount + "</td>" + "<td>" + new Date(data[i][0].updated_at).toISOString().split('T')[0] + "</td>" + "</tr>";
$('#myTable tbody').append(tr);
});
// $('#myTable').DataTable({
// data: data,
// columns: [
// {data: 'product_type'},
// {data: 'product_code'},
// {data: 'commission_id'},
// {data: 'qty'},
// {data: 'price'},
// {data: 'amount'}
// ],
// "order": [[0, "desc"]]
// });
}
});
}
});
</script>

View File

@@ -14,8 +14,8 @@
<thead>
<tr>
<th>Product Name</th>
<th>Commission Type</th>
<th>Amount</th>
<th>Commission type</th>
<th>Active</th>
<th colspan="3"></th>
</tr>
@@ -25,8 +25,8 @@
<% @commissions.each do |commission| %>
<tr>
<td><%= commission.menu_item.name rescue '-' %></td>
<td><%= commission.amount rescue '-' %></td>
<td><%= commission.commission_type rescue '-' %></td>
<td><%= commission.amount rescue '-' %></td>
<td><%= commission.is_active rescue '-' %></td>
<td><%= link_to 'Show', settings_commissions_path(commission) %></td>
<td><%= link_to 'Edit', edit_settings_commission_path(commission) %></td>