Merge branch 'august_spring' of bitbucket.org:code2lab/sxrestaurant

This commit is contained in:
Yan
2017-08-30 11:14:11 +06:30
15 changed files with 376 additions and 377 deletions

View File

@@ -20,13 +20,10 @@
//= require settings/processing_items
//= require jquery-ui
//= require bootstrap-datepicker
//= require jquery.datetimepicker
//= require dataTables/jquery.dataTables
//= require moment
//= require daterangepicker
//= require select2
//= require bootstrap-datetimepicker
//= require pickers
//= require jquery.datetimepicker
$(document).on('turbolinks:load', function() {

View File

@@ -4,11 +4,9 @@
@import "theme";
@import "jquery-ui";
@import "bootstrap-datepicker3";
@import "jquery.datetimepicker";
@import "dataTables/jquery.dataTables";
@import "daterangepicker-bs3";
@import "select2";
@import "bootstrap-datetimepicker";
@import "jquery.datetimepicker";
/* Show it is fixed to the top */
// body {

View File

@@ -12,7 +12,6 @@ class Origami::InJutiesController < BaseOrigamiController
@table = DiningFacility.find(params[:table_id])
@in_juty = InJuty.new
@juties_in = Kaminari.paginate_array(@juty_in).page(params[:page]).per(10)
end
# GET /in_juties/1
# GET /in_juties/1.json
@@ -60,10 +59,10 @@ class Origami::InJutiesController < BaseOrigamiController
def create_for_in_juty
@in_juty = InJuty.new
@in_juty.dinning_id = in_juty_params[:dinning_id]
@in_juty.commissioner_ids = in_juty_params[:commissioner_ids]
@in_juty.in_time = in_juty_params[:in_time]
@in_juty.out_time = in_juty_params[:out_time]
@in_juty.dinning_id = in_juty_params[:dinning_id]
@in_juty.commissioner_ids = in_juty_params[:commissioner_ids]
@in_juty.in_time = in_juty_params[:in_time]
@in_juty.out_time = in_juty_params[:out_time]
respond_to do |format|
@@ -75,7 +74,7 @@ class Origami::InJutiesController < BaseOrigamiController
format.json { render json: @in_juty.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /in_juties/1
@@ -93,9 +92,9 @@ class Origami::InJutiesController < BaseOrigamiController
end
def update_for_in_juty
@in_juty.commissioner_ids = in_juty_params[:commissioner_ids]
@in_juty.in_time = in_juty_params[:in_time]
def update_for_in_juty
@in_juty.commissioner_ids = in_juty_params[:commissioner_ids]
@in_juty.in_time = in_juty_params[:in_time]
@in_juty.out_time = in_juty_params[:out_time]
respond_to do |format|
if @in_juty.save
@@ -121,7 +120,7 @@ class Origami::InJutiesController < BaseOrigamiController
def destroy_in_juty
@table_id = params[:table_id]
@in_juty.destroy
respond_to do |format|
format.html { redirect_to origami_index_in_juty_path(@table_id), notice: 'In juty was successfully destroyed.' }
format.json { head :no_content }

View File

@@ -2,9 +2,15 @@ class Reports::CommissionController < BaseReportController
# authorize_resource :class => false
def index
from_date = Date.parse(params[:daterange].split(' - ')[0]).beginning_of_day.utc.getlocal
to_date = Date.parse(params[:daterange].split(' - ')[1]).end_of_day.utc.getlocal
from_date = DateTime.now.beginning_of_day.utc.getlocal
to_date = DateTime.now.end_of_day.utc.getlocal
unless params[:daterange].blank?
from_date = Date.parse(params[:daterange].split(' - ')[0]).beginning_of_day.utc.getlocal
to_date = Date.parse(params[:daterange].split(' - ')[1]).end_of_day.utc.getlocal
@daterange = params[:daterange]
end
commissioner = params[:commissioner].to_i
@com_id = commissioner
@commissioner = Commissioner.active.all
@transaction = ProductCommission.get_transaction(from_date, to_date, commissioner)

View File

@@ -28,7 +28,8 @@ class Promotion < ApplicationRecord
end
def self.combine_item(saleObj)
itemList = saleObj.sale_items.group(:product_code).sum(:qty)
order_id = saleObj.sale_orders[0].order_id
itemList = OrderItem.where("order_id = ?", order_id).group(:item_instance_code).sum(:qty)
end
def self.is_promo_day(promoList, day, orderitemList, sale_id)
@@ -44,7 +45,8 @@ class Promotion < ApplicationRecord
end
def self.find_promo_item(promo, orderitem, sale_id)
if promo.original_product.to_s == orderitem[0].to_s
item_code = OrderItem.find_by_item_instance_code(orderitem[0]).item_code
if promo.original_product.to_s == item_code
if promo.min_qty.to_i > orderitem[1].to_i
return false
else
@@ -75,7 +77,7 @@ class Promotion < ApplicationRecord
def self.check_giveaway_product(promo, orderitem)
promo.promotion_products.each do |promo_product|
if promo_product.item_code == orderitem
if promo_product.item_code == OrderItem.find_by_item_instance_code(orderitem).item_code
return true, promo_product
else
return false, promo_product
@@ -110,7 +112,13 @@ class Promotion < ApplicationRecord
else
charge_qty += qty
end
item = OrderItem.find_by_item_code(orderitem[0])
item = OrderItem.find_by_item_instance_code(orderitem[0])
byebug
# if promo_product == OrderItem.find_by_item_instance_code(orderitem[0]).item_code
# item = OrderItem.find_by_item_instance_code(orderitem[0])
# else
# item = OrderItem.find_by_item_code(promo_product)
# end
update_existing_item(foc_qty, item, sale_id, "promotion", item.price)
puts "Charged - " + charge_qty.to_s
@@ -124,7 +132,7 @@ class Promotion < ApplicationRecord
if (foc_qty < promotion_qty)
promotion_qty = foc_qty
end
item = OrderItem.find_by_item_code(promo_product)
item = OrderItem.find_by_item_instance_code(promo_product,orderID)
update_existing_item(promotion_qty, item, sale_id, "promotion", item.price)
end
@@ -156,11 +164,11 @@ class Promotion < ApplicationRecord
if same
foc_qty = orderitem[1].to_i / foc_min_qty
item = OrderItem.find_by_item_code(orderitem[0])
item = OrderItem.find_by_item_instance_code(orderitem[0])
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off)
else
foc_qty = find_second_item_qty(sale_id, promo_product.item_code)
item = OrderItem.find_by_item_code(promo_product.item_code)
item = OrderItem.find_by_item_instance_code(promo_product.item_code)
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off)
end
end
@@ -170,12 +178,12 @@ class Promotion < ApplicationRecord
if same
foc_qty = orderitem[1].to_i / foc_min_qty
item = OrderItem.find_by_item_code(orderitem[0]) # need to specify with menu item instance
item = OrderItem.find_by_item_instance_code(orderitem[0]) # need to specify with menu item instance
price = item.price.to_i - promo_product.net_price.to_i
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price)
else
foc_qty = find_second_item_qty(sale_id, promo_product.item_code)
item = OrderItem.find_by_item_code(promo_product.item_code)
item = OrderItem.find_by_item_instance_code(promo_product.item_code)
price = item.price - promo_product.net_price
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price)
end
@@ -186,14 +194,14 @@ class Promotion < ApplicationRecord
if same
foc_qty = orderitem[1].to_i / foc_min_qty
item = OrderItem.find_by_item_code(orderitem[0])
item = OrderItem.find_by_item_instance_code(orderitem[0])
# total = orderitem[1].to_i * item.price
total = item.price
price = calculate_discount(total, promo_product.percentage)
update_existing_item(foc_qty, item, sale_id, "promotion discount", price)
else
foc_qty = find_second_item_qty(sale_id, promo_product.item_code)
item = OrderItem.find_by_item_code(promo_product.item_code)
item = OrderItem.find_by_item_instance_code(promo_product.item_code)
# total = item.price * foc_qty
total = item.price
price = calculate_discount(total, promo_product.percentage)
@@ -205,7 +213,7 @@ class Promotion < ApplicationRecord
saleObj = Sale.find_by_sale_id(sale_id)
itemList = combine_item(saleObj)
itemList.each do |item|
if item[0] == promo_item
if OrderItem.find_by_item_instance_code(item[0]).item_code == promo_item
return item[1]
end
end

View File

@@ -1,46 +1,43 @@
<%= simple_form_for @in_juty,:url => origami_index_in_juty_path(@table.id), :method => :post do |f| %>
<span class="patch_method"></span>
<%= f.error_notification %>
<%= f.hidden_field :id, :class => "form-control col-md-6 " %>
<div class="form-inputs">
<%= simple_form_for @in_juty, :url => origami_index_in_juty_path(@table.id), :method => :post do |f| %>
<span class="patch_method"></span>
<%= f.error_notification %>
<%= f.hidden_field :id, :class => "form-control col-md-6 " %>
<%= f.hidden_field :dinning_id,:value => @table.id, :class => "form-control col-md-6 " %>
<div class="form-inputs">
<%= f.hidden_field :dinning_id, :value => @table.id, :class => "form-control col-md-4 " %>
<label>Dining Name:</label>
<%= @table.name %>
<br/>
<br/>
<label>Commissioner Name:</label>
<%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %>
<br/><br/>
<%= f.input :in_time, :placeholder => "From Date", :class => "form-control" %>
<%= f.input :out_time, :placeholder => "From Date", :class => "form-control" %>
</div><br>
<div class="form-group">
<%= f.button :submit, "Create", :class => 'btn btn-primary ', :id => 'create' %>
<%= f.button :submit, "Update", :class => 'btn btn-primary ', :disabled => '', :id => 'update' %>
<%= f.button :button, "Reset", :class => 'btn btn-danger ', :id => 'reset' %>
</div>
<label>Dining Name:</label>
<%= @table.name %>
<br/>
<br/>
<label>Commissioner Name:</label>
<%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %><br/><br/>
<%= f.input :in_time, :placeholder => "From Date" , :class => "form-control", :as => :datetime_picker%>
<%= f.input :out_time, :placeholder => "From Date" , :class => "form-control", :as => :datetime_picker%>
</div><br>
<div class="form-group">
<%= f.button :submit, "Create",:class => 'btn btn-primary ', :id => 'create' %>
<%= f.button :submit, "Update",:class => 'btn btn-primary ', :disabled =>'', :id => 'update' %>
<%= f.button :button, "Reset",:class => 'btn btn-danger ', :id => 'reset' %>
</div>
<% end %>
<script type="text/javascript">
$(document).ready(function(){
// $('#in_juty_in_time').datetimepicker();
// $('#in_juty_out_time').datetimepicker();
$('#reset').click(function() {
$(document).ready(function () {
$('#reset').click(function () {
location.reload();
return false;
});
});
// window.location.href = '/origami/assign_in_juty/'+ table_id;
location.reload();
return false;
});
});
</script>
</script>

View File

@@ -1,5 +1,5 @@
<div class="row">
<div class="col-md-8">
<table class="table table-striped">
<thead>
@@ -16,74 +16,67 @@
<tbody>
<% @juties_in.each do |in_juty| %>
<tr class="injuty_tr" data-ref="<%= in_juty.id %>">
<td>
<input type="radio" style="width:20px;" name="checkbox" class="checkbox_check" ></td>
<td>
<input type="radio" style="width:20px;" name="checkbox" class="checkbox_check"></td>
<td><%= in_juty.dining_facility.name rescue '-' %></td>
<td><%= in_juty.commissioner.name rescue '-' %></td>
<td><%= in_juty.in_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %></td>
<td><%= in_juty.out_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %></td>
<td><%= link_to 'Destroy', origami_destroy_in_juty_path(in_juty.dining_facility.id,in_juty),method: :delete, data: {confirm: 'Are you sure?'} %></td>
<td><%= link_to 'Destroy', origami_destroy_in_juty_path(in_juty.dining_facility.id, in_juty), method: :delete, data: {confirm: 'Are you sure?'} %></td>
</tr>
<% end %>
</tbody>
</table>
<%= paginate @juties_in %>
</div>
<div class="col-md-4">
<%= render 'assign_in_juty', in_juty: @in_juty ,table: @table %>
<%= render 'assign_in_juty', in_juty: @in_juty, table: @table %>
</div>
</div>
<div class="col-md-1">
<button type="button" class="btn btn-primary btn-block" id='back'>Back</button>
<button type="button" class="btn btn-primary btn-block" id='back'>Back</button>
</div>
<script type="text/javascript">
$(document).on('click',".injuty_tr",function(){
// if(this.checked){
$(this).closest('tr').find('.checkbox_check').prop( "checked", true );
//$( "#checkbox_check" ).prop( "checked", true );
var in_juty_id = $(this).attr('data-ref');
var table_id = "<%= @table.id %>";
var url = "/origami/assign_in_juty/table/" + table_id + "/in_juty/" + in_juty_id + "/edit";
$.ajax({
type: "GET",
url: url,
data: {},
success: function(data) {
// Selected for Taxes
$('#in_juty_id').val(data.in_juty.id);
$('#in_juty_commissioner_ids').val(data.commissioner.id);
$('#in_juty_in_time').val(data.in_juty.in_time.split('T')[0]);
$('#in_juty_out_time').val(data.in_juty.out_time.split('T')[0]);
$(document).on('click', ".injuty_tr", function () {
$('#update').removeAttr('disabled').val('');
$('#update').attr('value', 'Update');
$('#create').attr('disabled','disabled');
$(this).closest('tr').find('.checkbox_check').prop("checked", true);
$("#new_in_juty").attr('class', 'simple_form edit_in_juty');
var id = "edit_in_juty_" + in_juty_id;
$("#new_in_juty").attr('id', id);
var in_juty_id = $(this).attr('data-ref');
var table_id = "<%= @table.id %>";
var url = "/origami/assign_in_juty/table/" + table_id + "/in_juty/" + in_juty_id + "/edit";
$(".edit_in_juty").attr('id', id);
$(".edit_in_juty").attr('action', '/origami/edit_in_juty/' + $('#in_juty_id').val());
$(".edit_in_juty").attr('action', '/origami/edit_in_juty/' + $('#in_juty_id').val());
$(".patch_method").html('<input type="hidden" name="_method" value="patch">');
}
});
// }else{
$.ajax({
type: "GET",
url: url,
data: {},
// }
})
success: function (data) {
$('#in_juty_id').val(data.in_juty.id);
$('#in_juty_commissioner_ids').val(data.commissioner.id);
$('#in_juty_in_time').val(data.in_juty.in_time);
$('#in_juty_out_time').val(data.in_juty.out_time);
$('#back').on('click', function () {
window.location.href = '/origami/table/'+ "<%= @table.id %>";
$('#update').removeAttr('disabled').val('');
$('#update').attr('value', 'Update');
$('#create').attr('disabled', 'disabled');
$("#new_in_juty").attr('class', 'simple_form edit_in_juty');
var id = "edit_in_juty_" + in_juty_id;
$("#new_in_juty").attr('id', id);
$(".edit_in_juty").attr('id', id);
$(".edit_in_juty").attr('action', '/origami/edit_in_juty/' + $('#in_juty_id').val());
$(".edit_in_juty").attr('action', '/origami/edit_in_juty/' + $('#in_juty_id').val());
$(".patch_method").html('<input type="hidden" name="_method" value="patch">');
}
});
});
$('#back').on('click', function () {
window.location.href = '/origami/table/' + "<%= @table.id %>";
})
</script>
</script>

View File

@@ -6,20 +6,31 @@
<div class="form-group col-md-3">
<label class="">Select Date Range</label>
<input class="form-control" name="daterange" id="daterange" type="text" placeholder="Date Range" readonly="true">
<% if @daterange %>
<input class="form-control" name="daterange" id="daterange" value="<%= @daterange %>" type="text" placeholder="Date Range" readonly="true">
<% else %>
<input class="form-control" name="daterange" id="daterange" type="text" placeholder="Date Range" readonly="true">
<% end %>
</div>
<div class="form-group col-md-3">
<label class="">Commissioner</label>
<select class="form-control" name="commissioner" id="commissioner">
<option value=""></option>
<% @commissioner.each do |c| %>
<option value="<%= c.id %>"><%= c.name %></option>
<% if @com_id == c.id %>
<option value="<%= c.id %>" selected><%= c.name %></option>
<% else %>
<option value="<%= c.id %>"><%= c.name %></option>
<% end %> %>
<% end %>
</select>
</div>
<div class="form-group col-md-2 margin-top-20">
<input type="submit" value="Generate Report" class='btn btn-primary'>
</div>
<div class="form-group col-md-2 margin-top-20">
<input type="button" value="Clear Filter" id="clear_filter" class='btn btn-danger'>
</div>
</div>
<% end %>
@@ -35,21 +46,26 @@
placeholder: 'Select Commissioner'
});
$('#clear_filter').click(function () {
$('#daterange').val('');
$('#commissioner').val('').text('');
});
$('input[name="daterange"]').daterangepicker({
autoUpdateInput: false,
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
autoUpdateInput: false,
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
},
locale: {
format: 'YYYY-MM-DD'
}
},
locale: {
format: 'YYYY-MM-DD'
}
},
function(start, end, label) {
function (start, end, label) {
$('input[name="daterange"]').val(start.format('YYYY-MM-DD') + ' - ' + end.format('YYYY-MM-DD'));
});

View File

@@ -13,5 +13,4 @@
$("#promotion_promo_code").val(Math.random().toString(36).slice(5) + Math.random().toString(36).slice(5));
// $( "#fromtime" ).timepicker();
// $( "#totime" ).timepicker({ 'scrollDefault': 'now' });
$('#scrollDefaultExample').timepicker({ 'scrollDefault': 'now' });
</script>