still dev dis
This commit is contained in:
@@ -72,6 +72,7 @@
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
white-space: normal !important;
|
||||
height: 60px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
@@ -168,6 +169,8 @@
|
||||
background-color: blue
|
||||
}
|
||||
|
||||
/* End Colors */
|
||||
|
||||
.left{
|
||||
margin-left:1px;
|
||||
}
|
||||
@@ -175,6 +178,7 @@
|
||||
.bottom{
|
||||
margin-bottom: 1px;
|
||||
}
|
||||
|
||||
/*----- Reset -----*/
|
||||
|
||||
select.form-control {
|
||||
@@ -197,6 +201,7 @@ tr.discount-item-row:hover {
|
||||
.required abbr{
|
||||
color: red !important;
|
||||
}
|
||||
|
||||
/* Jquery Confirm */
|
||||
|
||||
.jconfirm-box-container{
|
||||
|
||||
@@ -29,7 +29,6 @@ class Origami::DiscountsController < BaseOrigamiController
|
||||
if discount_items.length > 0
|
||||
#save sale item for discount
|
||||
discount_items.each do |di|
|
||||
puts di
|
||||
origin_sale_item = SaleItem.find(di["id"])
|
||||
sale_item = SaleItem.new
|
||||
|
||||
@@ -53,6 +52,61 @@ class Origami::DiscountsController < BaseOrigamiController
|
||||
render :json => dining.to_json
|
||||
end
|
||||
|
||||
# Remove selected discount Items
|
||||
def remove_discount_items
|
||||
sale_id = params[:sale_id]
|
||||
discount_items = JSON.parse(params[:discount_items])
|
||||
if Sale.exists?(sale_id)
|
||||
sale = Sale.find(sale_id)
|
||||
table_id = sale.bookings[0].dining_facility_id
|
||||
table_type = DiningFacility.find(table_id).type
|
||||
|
||||
if discount_items.length > 0
|
||||
#destroy sale item for discount
|
||||
discount_items.each do |di|
|
||||
sale_item = SaleItem.find(di["id"])
|
||||
price = (sale_item.price - 0)
|
||||
sale.total_amount = (sale.total_amount + price)
|
||||
sale_item.destroy
|
||||
end
|
||||
end
|
||||
|
||||
sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax;
|
||||
sale.save
|
||||
end
|
||||
|
||||
dining = {:table_id => table_id, :table_type => table_type }
|
||||
|
||||
render :json => dining.to_json
|
||||
end
|
||||
|
||||
# Remove all discount Items
|
||||
def remove_all_discount
|
||||
sale_id = params[:id]
|
||||
|
||||
if Sale.exists?(sale_id)
|
||||
sale = Sale.find(sale_id)
|
||||
table_id = sale.bookings[0].dining_facility_id
|
||||
table_type = DiningFacility.find(table_id).type
|
||||
|
||||
#destroy all discount sale item
|
||||
sale.sale_items.each do |si|
|
||||
if si.remark == "Discount" && si.price < 0
|
||||
price = (si.price - 0)
|
||||
sale.total_amount = (sale.total_amount + price)
|
||||
si.destroy
|
||||
end
|
||||
end
|
||||
|
||||
sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax;
|
||||
sale.save
|
||||
end
|
||||
|
||||
dining = {:table_id => table_id, :table_type => table_type }
|
||||
|
||||
render :json => dining.to_json
|
||||
end
|
||||
|
||||
#discount for selected order
|
||||
# def create
|
||||
# sale_id = params[:sale_id]
|
||||
|
||||
@@ -40,6 +40,8 @@ class Ability
|
||||
|
||||
can :index, :discount
|
||||
can :create, :discount
|
||||
can :remove_discount_items, :discount
|
||||
can :remove_all_discount, :discount
|
||||
|
||||
can :show, :payment
|
||||
can :create, :payment
|
||||
@@ -63,6 +65,8 @@ class Ability
|
||||
|
||||
can :index, :discount
|
||||
can :create, :discount
|
||||
can :remove_discount_items, :discount
|
||||
can :remove_all_discount, :discount
|
||||
|
||||
can :show, :payment
|
||||
can :create, :payment
|
||||
|
||||
@@ -172,7 +172,7 @@
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<button id="net" class="btn btn-warning fluid action-btn">Nett</button>
|
||||
<button id="net" class="btn btn-info fluid action-btn">Nett</button>
|
||||
<button id="percentage" class="btn btn-primary fluid action-btn">Percentage</button>
|
||||
<button id="remove-item" class="btn btn-default fluid action-btn">Remove</button>
|
||||
</div>
|
||||
@@ -187,6 +187,8 @@
|
||||
<!-- Action Panel -->
|
||||
<div>
|
||||
<button type="button" class="btn btn-primary btn-block" onclick="window.location.href = '/origami';"><i class="fa fa-arrow-left"></i> Back </button>
|
||||
<button id="remove-item-discount" class="btn btn-warning btn-block action-btn">Remove Discount</button>
|
||||
<button id="remove-all" class="btn btn-warning btn-block action-btn">Remove All</button>
|
||||
<button id="pay-discount" class="btn btn-danger btn-block action-btn">Enter</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -358,6 +360,55 @@ $(document).ready(function(){
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Remove selected given discount item
|
||||
$("#remove-item-discount").on('click', function(e){
|
||||
e.preventDefault();
|
||||
var sale_id = $('#sale-id').text();
|
||||
var discount_items = [];
|
||||
|
||||
// Selected Items
|
||||
var sale_items = get_selected_sale_items();
|
||||
for(var i=0;i < sale_items.length;i++){
|
||||
if(sale_items[i].price < 0){
|
||||
discount_items.push(sale_items[i]);
|
||||
}
|
||||
}
|
||||
|
||||
var params = { 'sale_id': sale_id, 'discount_items': JSON.stringify(discount_items) };
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/origami/" + sale_id + "/remove_discount_items",
|
||||
data: params,
|
||||
success: function(result){
|
||||
alert('Removed Discount');
|
||||
if(result.table_type == "Table"){
|
||||
window.location.href = "/origami/table/" + result.table_id
|
||||
}
|
||||
else {
|
||||
window.location.href = "/origami/room/" + result.table_id
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#remove-all").on('click', function(e){
|
||||
e.preventDefault();
|
||||
var sale_id = $('#sale-id').text();
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/origami/" + sale_id + "/remove_all_discount",
|
||||
success: function(result){
|
||||
alert('Removed All Discount');
|
||||
if(result.table_type == "Table"){
|
||||
window.location.href = "/origami/table/" + result.table_id
|
||||
}
|
||||
else {
|
||||
window.location.href = "/origami/room/" + result.table_id
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/* Remove Selection */
|
||||
|
||||
@@ -93,6 +93,8 @@ Rails.application.routes.draw do
|
||||
|
||||
get "/:id/discount" => "discounts#index"
|
||||
post "/:id/discount" => "discounts#create"
|
||||
get "/:id/remove_all_discount" => "discounts#remove_all_discount"
|
||||
post "/:id/remove_discount_items" => "discounts#remove_discount_items"
|
||||
|
||||
post "/:id/request_bills" => "request_bills#print",:as => "request_bill" ,:defaults => { :format => 'json' }
|
||||
get '/:sale_id/reprint' => 'payments#reprint' ,:defaults => { :format => 'json' }
|
||||
|
||||
Reference in New Issue
Block a user