item void
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
class Origami::SaleEditController < BaseOrigamiController
|
||||
|
||||
# Index for sale item void OR edit
|
||||
def edit
|
||||
sale_id = params[:sale_id]
|
||||
@table_id = params[:table_id]
|
||||
@saleobj = Sale.find(sale_id)
|
||||
end
|
||||
|
||||
# create item void. make duplicate old record and update qty and price
|
||||
def item_void
|
||||
saleitemId = params[:sale_item_id]
|
||||
saleitemObj = SaleItem.find(saleitemId)
|
||||
@@ -19,4 +21,36 @@ class Origami::SaleEditController < BaseOrigamiController
|
||||
@newsaleitem.product_name = saleitemObj.product_name + " - void"
|
||||
@newsaleitem.save
|
||||
end
|
||||
|
||||
# make cancel void item
|
||||
def item_void_cancel
|
||||
saleitemId = params[:sale_item_id]
|
||||
saleitemObj = SaleItem.find(saleitemId)
|
||||
both = SaleItem.where('product_code=?',saleitemObj.product_code)
|
||||
both.each do |item|
|
||||
if item.qty.to_i > 0
|
||||
item.remark = nil
|
||||
item.save
|
||||
end
|
||||
end
|
||||
saleitemObj.destroy
|
||||
end
|
||||
|
||||
# remove all void items
|
||||
def cancel_all_void
|
||||
sale_id = params[:sale_id]
|
||||
saleobj = Sale.find(sale_id)
|
||||
saleobj.sale_items.each do |item|
|
||||
if item.qty.to_i < 0
|
||||
item.destroy
|
||||
else
|
||||
item.remark = nil
|
||||
end
|
||||
item.save
|
||||
end
|
||||
end
|
||||
|
||||
def apply_void
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
json.status true
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="row">
|
||||
<!-- Column Two -->
|
||||
<div class="col-lg-11 col-md-11 col-sm-11">
|
||||
<div class="col-lg-10 col-md-10 col-sm-10">
|
||||
<div class="card" >
|
||||
<div class="card-header">
|
||||
<div><strong id="order-title">INVOICE DETAILS </strong></div>
|
||||
@@ -13,7 +13,7 @@
|
||||
</span></p>
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-6 text-right">
|
||||
<p>Date: <span id="receipt_date"><%= @saleobj.created_at.utc.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%></span></p>
|
||||
<p>Date: <span id="receipt_date"><%= @saleobj.created_at.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%></span></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-title row customer_detail hide">
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
</div>
|
||||
<div class="card-text">
|
||||
<table class="table table-striped" id="order-items-table">
|
||||
<table class="table " id="order-items-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
@@ -49,13 +49,23 @@
|
||||
<tr>
|
||||
<td><%= count %></td>
|
||||
<td class='item-name'><%= sale_item.product_name %></td>
|
||||
<% if sale_item.remark != 'void' %>
|
||||
<td class='item-attr-edit'><input data-id ="<%= sale_item.id %>" type="text" value="<%= sale_item.qty %>" /></td>
|
||||
<td class='item-attr-edit'><input data-id ="<%= sale_item.id %>" type="text" value="<%= sale_item.price %>" /></td>
|
||||
<% if sale_item.remark != 'void' || sale_item.qty.to_i > 0 %>
|
||||
<td class='item-attr'>
|
||||
<button data-id ="<%= sale_item.id %>" class='btn btn-primary btn-sm update'>Update</button>
|
||||
<button data-id ="<%= sale_item.id %>" class='btn btn-danger btn-sm void'>Void</button></td>
|
||||
</td>
|
||||
<% elsif sale_item.qty.to_i < 0 %>
|
||||
<td class='item-attr-edit'><input data-id ="<%= sale_item.id %>" type="text" value="<%= sale_item.qty %>" disabled/></td>
|
||||
<td class='item-attr-edit'><input data-id ="<%= sale_item.id %>" type="text" value="<%= sale_item.price %>" disabled/></td>
|
||||
<td class='item-attr'>
|
||||
<button data-id ="<%= sale_item.id %>" class='btn btn-primary btn-sm cancel'>Cancel Void</button>
|
||||
</td>
|
||||
<% else %>
|
||||
<td class='item-attr-edit'><input data-id ="<%= sale_item.id %>" type="text" value="<%= sale_item.qty %>" disabled/></td>
|
||||
<td class='item-attr-edit'><input data-id ="<%= sale_item.id %>" type="text" value="<%= sale_item.price %>" disabled/></td>
|
||||
<td></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<%
|
||||
@@ -70,18 +80,6 @@
|
||||
<tr>
|
||||
<td class="charges-name"><strong>Sub Total:</strong></td>
|
||||
<td class="item-attr"><strong id="order-sub-total"><%= sub_total %></strong></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="charges-name"><strong>Discount:</strong></td>
|
||||
<td class="item-attr"><strong id="order-discount">(<%= @saleobj.total_discount rescue 0%>)</strong></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="charges-name"><strong>Tax:</strong></td>
|
||||
<td class="item-attr"><strong id="order-Tax"><%= @saleobj.total_tax rescue 0%></strong></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="charges-name"><strong>Grand Total:</strong></td>
|
||||
<td class="item-attr"><strong id="order-grand-total"><%= @saleobj.grand_total rescue 0%></strong></td>
|
||||
</tr>
|
||||
<tr class="rebate_amount"></tr>
|
||||
</table>
|
||||
@@ -91,9 +89,11 @@
|
||||
</div>
|
||||
|
||||
<!-- Column Three -->
|
||||
<div class="col-lg-1 col-md-1 col-sm-1">
|
||||
<div class="col-lg-2 col-md-2 col-sm-2">
|
||||
<!-- Waiter Buttons -->
|
||||
<button type="button" class="btn btn-primary btn-block" id='back' >Back</button>
|
||||
<button type="button" class="btn btn-primary btn-block" id='cancel_all_void' >Cancel All Void</button>
|
||||
<button type="button" class="btn btn-primary btn-block" id='apply' >Apply</button>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
@@ -125,10 +125,51 @@ $(document).ready(function(){
|
||||
});
|
||||
})
|
||||
|
||||
$('.cancel').on('click',function(){
|
||||
var sale_item_id = $(this).attr('data-id');
|
||||
var ajax_url = "/origami/item_void_cancel";
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajax_url,
|
||||
data: 'sale_item_id='+ sale_item_id,
|
||||
success:function(result){
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
|
||||
$('#back').on('click',function(){
|
||||
var table_id = '<%= @table_id %>'
|
||||
window.location.href = '/origami/table/'+ table_id;
|
||||
})
|
||||
|
||||
$('#cancel_all_void').on('click',function(){
|
||||
var sale_id = "<%= @saleobj.sale_id %>"
|
||||
var ajax_url = "/origami/cancel_all_void";
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajax_url,
|
||||
data: 'sale_id='+ sale_id,
|
||||
success:function(result){
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
$('#apply').on('click',function(){
|
||||
var sale_id = "<%= @saleobj.sale_id %>"
|
||||
var ajax_url = "/origami/apply_void";
|
||||
var table_id = '<%= @table_id %>'
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajax_url,
|
||||
data: 'sale_id='+ sale_id,
|
||||
success:function(result){
|
||||
window.location.href = '/origami/table/'+ table_id ;
|
||||
}
|
||||
});
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
json.status true
|
||||
@@ -78,6 +78,10 @@ Rails.application.routes.draw do
|
||||
post 'moving' => "movetable#moving"
|
||||
get "/table/:table_id/sale/:sale_id/edit" => "sale_edit#edit"
|
||||
post 'item_void' => "sale_edit#item_void"
|
||||
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'
|
||||
|
||||
get 'table/:dining_id/movetable' => "movetable#move_dining"
|
||||
get 'table/:dining_id/moveroom' => "moveroom#move_dining"
|
||||
get 'sale/:sale_id' => 'sales#show'
|
||||
|
||||
Reference in New Issue
Block a user