Add Void button in Transaction/sales
This commit is contained in:
@@ -237,6 +237,155 @@ class Transactions::SalesController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def overall_void
|
||||||
|
sale_id = params[:sale_id]
|
||||||
|
remark = params[:remark]
|
||||||
|
order_source = params[:type] #tax profile source
|
||||||
|
access_code = params[:access_code]
|
||||||
|
if Sale.exists?(sale_id)
|
||||||
|
sale = Sale.find_by_sale_id(sale_id)
|
||||||
|
|
||||||
|
if sale.discount_type == "member_discount"
|
||||||
|
sale.update_attributes(total_discount: 0)
|
||||||
|
sale.compute_by_sale_items(sale_id, sale.sale_items,0,order_source)
|
||||||
|
end
|
||||||
|
|
||||||
|
# update count for shift sale
|
||||||
|
if(sale.sale_status == "completed")
|
||||||
|
if sale.shift_sale_id != nil
|
||||||
|
shift = ShiftSale.find(sale.shift_sale_id)
|
||||||
|
shift.calculate(sale_id, "void")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# void before sale payment complete
|
||||||
|
if sale.shift_sale_id != nil
|
||||||
|
shift = ShiftSale.find(sale.shift_sale_id)
|
||||||
|
shift.total_void = shift.total_void + sale.grand_total
|
||||||
|
shift.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
sale.rounding_adjustment = 0.0
|
||||||
|
sale.payment_status = 'void'
|
||||||
|
sale.sale_status = 'void'
|
||||||
|
sale.save
|
||||||
|
|
||||||
|
# No Need
|
||||||
|
# bookings = sale.bookings
|
||||||
|
# bookings.each do |booking|
|
||||||
|
# orders = booking.orders
|
||||||
|
# orders.each do |order|
|
||||||
|
# # order.status = 'void'
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
|
if sale.bookings[0].dining_facility_id.to_i > 0
|
||||||
|
table_avaliable = true
|
||||||
|
table_count = 0
|
||||||
|
table = sale.bookings[0].dining_facility
|
||||||
|
table.bookings.each do |booking|
|
||||||
|
if booking.booking_status != 'moved'
|
||||||
|
if booking.sale_id
|
||||||
|
if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' && booking.sale.sale_status != 'spoile' && booking.sale.sale_status != 'waste'
|
||||||
|
table_avaliable = false
|
||||||
|
table_count += 1
|
||||||
|
else
|
||||||
|
table_avaliable = true
|
||||||
|
end
|
||||||
|
else
|
||||||
|
table_avaliable = false
|
||||||
|
table_count += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if table_avaliable && table_count == 0
|
||||||
|
table.status = 'available'
|
||||||
|
table.save
|
||||||
|
end
|
||||||
|
else
|
||||||
|
table = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
# FOr Sale Audit
|
||||||
|
action_by = current_user.name
|
||||||
|
if access_code != "null" && current_user.role == "cashier"
|
||||||
|
action_by = Employee.find_by_emp_id(access_code).name
|
||||||
|
end
|
||||||
|
|
||||||
|
# remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}"
|
||||||
|
sale_audit = SaleAudit.record_audit_for_edit(sale_id,sale.cashier_id, action_by,remark,"SALEVOID" )
|
||||||
|
|
||||||
|
# For Print
|
||||||
|
|
||||||
|
member_info = nil
|
||||||
|
rebate_amount = nil
|
||||||
|
current_balance = nil
|
||||||
|
|
||||||
|
# For Cashier by Zone
|
||||||
|
bookings = Booking.where("sale_id='#{sale_id}'")
|
||||||
|
if bookings.count > 1
|
||||||
|
# for Multiple Booking
|
||||||
|
if bookings[0].dining_facility_id.to_i>0
|
||||||
|
table = DiningFacility.find(bookings[0].dining_facility_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if bookings[0].dining_facility_id.to_i > 0
|
||||||
|
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
|
||||||
|
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
|
||||||
|
else
|
||||||
|
shift = ShiftSale.find(sale.shift_sale_id)
|
||||||
|
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
|
||||||
|
unique_code = "ReceiptBillPdf"
|
||||||
|
customer= Customer.find(sale.customer_id)
|
||||||
|
|
||||||
|
#shop detail
|
||||||
|
shop_details = Shop.find(1)
|
||||||
|
# get member information
|
||||||
|
rebate = MembershipSetting.find_by_rebate(1)
|
||||||
|
if customer.membership_id != nil && rebate
|
||||||
|
member_info = Customer.get_member_account(customer)
|
||||||
|
rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no)
|
||||||
|
# current_balance = SaleAudit.paymal_search(sale_id)
|
||||||
|
current_balance = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
# get printer info
|
||||||
|
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
||||||
|
# Calculate Food and Beverage Total
|
||||||
|
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items)
|
||||||
|
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items)
|
||||||
|
|
||||||
|
printer = Printer::ReceiptPrinter.new(print_settings)
|
||||||
|
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil)
|
||||||
|
result = {
|
||||||
|
:filepath => filename,
|
||||||
|
:printer_model => print_settings.brand_name,
|
||||||
|
:printer_url => print_settings.api_settings
|
||||||
|
}
|
||||||
|
|
||||||
|
# Mobile Print
|
||||||
|
render :json => result.to_json
|
||||||
|
# end
|
||||||
|
|
||||||
|
#end print
|
||||||
|
|
||||||
|
# update complete order items in oqs
|
||||||
|
SaleOrder.where("sale_id = '#{ sale_id }'").find_each do |sodr|
|
||||||
|
AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi|
|
||||||
|
aoi.delivery_status = 1
|
||||||
|
aoi.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_transactions_sale
|
def set_transactions_sale
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<ol class="breadcrumb">
|
<ol class="breadcrumb">
|
||||||
<li class="breadcrumb-item"><a href="<%= dashboard_path %>"><%= t("views.right_panel.button.home") %></a></li>
|
<li class="breadcrumb-item"><a href="<%= dashboard_path %>"><%= t("views.right_panel.button.home") %></a></li>
|
||||||
@@ -36,22 +35,25 @@
|
|||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th><%= t("views.right_panel.detail.receipt_date") %></th>
|
<th><%= t("views.right_panel.detail.receipt_date") %></th>
|
||||||
<th><%= t("views.right_panel.detail.receipt_no") %></th>
|
<th><%= t("views.right_panel.detail.receipt_no") %></th>
|
||||||
<th><%= t :cashier %></th>
|
<th><%= t :cashier %></th>
|
||||||
<th><%= t("views.right_panel.detail.sales_status") %></th>
|
<th><%= t("views.right_panel.detail.sales_status") %></th>
|
||||||
<th><%= t("views.right_panel.detail.receipt_generated_at") %></th>
|
<th><%= t("views.right_panel.detail.receipt_generated_at") %></th>
|
||||||
|
<% if @sale["sale_status"] == "completed" %>
|
||||||
|
<th>
|
||||||
|
<button type="button" class="btn btn-block bg-blue waves-effect" data-toggle="modal" data-target="#voidModal" <%= (can? :overall_void, :void)? ' ': 'disabled=' %> > Void</button>
|
||||||
|
</th>
|
||||||
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= @sale.receipt_date.strftime("%d-%M-%Y") %></td>
|
<td><%= @sale.receipt_date.strftime("%d-%M-%Y") %></td>
|
||||||
<td><%= @sale.receipt_no %></td>
|
<td><%= @sale.receipt_no %></td>
|
||||||
<td><%= @sale.cashier_name rescue '-' %></td>
|
<td><%= @sale.cashier_name rescue '-' %></td>
|
||||||
<td> <%= @sale.sale_status %> </td>
|
<td><%= @sale.sale_status %> </td>
|
||||||
<td colspan="2"> <%= @sale.requested_at.strftime("%m-%d-%Y %H:%M %p") %> </td>
|
<td colspan="2"> <%= @sale.requested_at.strftime("%m-%d-%Y %H:%M %p") %> </td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr style="border-top:2px solid #000">
|
<tr style="border-top:2px solid #000">
|
||||||
@@ -63,7 +65,6 @@
|
|||||||
<th><%= t("views.right_panel.detail.remark") %></th>
|
<th><%= t("views.right_panel.detail.remark") %></th>
|
||||||
</tr>
|
</tr>
|
||||||
<% @sale.sale_items.each do |s| %>
|
<% @sale.sale_items.each do |s| %>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td><%=s.product_name rescue ' '%></td>
|
<td><%=s.product_name rescue ' '%></td>
|
||||||
<td><%=s.qty rescue ' '%></td>
|
<td><%=s.qty rescue ' '%></td>
|
||||||
@@ -101,30 +102,22 @@
|
|||||||
<td><%= t("views.right_panel.detail.total_pay_amount") %></td>
|
<td><%= t("views.right_panel.detail.total_pay_amount") %></td>
|
||||||
<td colspan="3"><%= number_with_precision(@sale.amount_received, :precision => 2, :delimiter => ',') rescue ' '%></td>
|
<td colspan="3"><%= number_with_precision(@sale.amount_received, :precision => 2, :delimiter => ',') rescue ' '%></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<% @sale_receivables.each do |r|%>
|
<% @sale_receivables.each do |r|%>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan=2 style="text-align:center"></td>
|
<td colspan=2 style="text-align:center"></td>
|
||||||
<td> <%= r.payment_method.capitalize rescue ' '%> Payment</td>
|
<td> <%= r.payment_method.capitalize rescue ' '%> Payment</td>
|
||||||
<td colspan="3"><%= number_with_precision(r.payment_amount, :precision => 2, :delimiter => ',') rescue ' '%>
|
<td colspan="3"><%= number_with_precision(r.payment_amount, :precision => 2, :delimiter => ',') rescue ' '%></td>
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan=2 style="text-align:center"></td>
|
<td colspan=2 style="text-align:center"></td>
|
||||||
<td><%= t("views.right_panel.detail.change") %></td>
|
<td><%= t("views.right_panel.detail.change") %></td>
|
||||||
<td colspan="3"><%= number_with_precision(@sale.amount_changed, :precision => 2, :delimiter => ',') rescue ' '%></td>
|
<td colspan="3"><%= number_with_precision(@sale.amount_changed, :precision => 2, :delimiter => ',') rescue ' '%></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="tab-pane" id="booking" role="tabpanel">
|
<div class="tab-pane" id="booking" role="tabpanel">
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
@@ -140,7 +133,6 @@
|
|||||||
<th><%= t("views.right_panel.detail.created_at") %></th>
|
<th><%= t("views.right_panel.detail.created_at") %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @order_items.each do |order_item| %>
|
<% @order_items.each do |order_item| %>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -158,7 +150,6 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="tab-pane" id="customer" role="tabpanel">
|
<div class="tab-pane" id="customer" role="tabpanel">
|
||||||
<br>
|
<br>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
@@ -203,8 +194,7 @@
|
|||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<%
|
<% if @response["status"] == true %>
|
||||||
if @response["status"] == true %>
|
|
||||||
<% @response["data"].each do |transaction| %>
|
<% @response["data"].each do |transaction| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= transaction["date"]%></td>
|
<td><%= transaction["date"]%></td>
|
||||||
@@ -236,27 +226,82 @@
|
|||||||
<th><%= t("views.right_panel.detail.remark") %></th>
|
<th><%= t("views.right_panel.detail.remark") %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
||||||
<% @sale_audits.each do |audit| %>
|
<% @sale_audits.each do |audit| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= audit.action%></td>
|
<td><%= audit.action%></td>
|
||||||
<td><%= audit.action_at.strftime("%m-%d-%Y %H:%M %p")%></td>
|
<td><%= audit.action_at.strftime("%m-%d-%Y %H:%M %p")%></td>
|
||||||
<td><%= audit.approved_by%></td>
|
<td><%= audit.approved_by%></td>
|
||||||
<td><%= audit.remark%></td>
|
<td><%= audit.remark%></td>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="modal fade" id="voidModal" tabindex="-1" role="dialog">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h4 class="modal-title" id="voidModalLabel">Please Enter Reason for Void</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<input type="textarea" name="remark" class="form-control col-md-12 remark" id="remark">
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer ">
|
||||||
|
<div class="row p-r-20">
|
||||||
|
<div class="col-md-5">
|
||||||
|
<button type="button" class="btn btn-link bg-red waves-effect " id="void" active="true">VOID</button>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-5">
|
||||||
|
<button type="button" class="btn btn-link bg-blue waves-effect" data-dismiss="modal">CLOSE</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
$('#void').on('click', function () {
|
||||||
|
var access_code = localStorage.getItem("access_code");
|
||||||
|
if ($(this).attr('active')=== "true") {
|
||||||
|
swal({
|
||||||
|
title: "Alert",
|
||||||
|
text: "Are you sure want to Void?",
|
||||||
|
type: "warning",
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: "#DD6B55",
|
||||||
|
confirmButtonText: "Yes, void it!",
|
||||||
|
closeOnConfirm: false
|
||||||
|
}, function (isConfirm) {
|
||||||
|
if (isConfirm) {
|
||||||
|
var sale_id = "<%= @sale.sale_id %>"
|
||||||
|
console.log(sale_id)
|
||||||
|
var ajax_url = "/transactions/sales/" + sale_id + '/cashier/void';
|
||||||
|
var remark = $("#remark").val();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: ajax_url,
|
||||||
|
data: "remark="+ remark + "&sale_id=" + sale_id+ "&access_code=" + access_code,
|
||||||
|
success: function (result) {
|
||||||
|
// For Server Print - from jade
|
||||||
|
if ($("#server_mode").val() == "cloud") {
|
||||||
|
code2lab.printFile(result.filepath.substr(6), result.printer_url);
|
||||||
|
}
|
||||||
|
window.location.href = '/transactions/sales/';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
swal("Opps","You are not authorized for void","warning")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -431,6 +431,7 @@ scope "(:locale)", locale: /en|mm/ do
|
|||||||
get "/sales/:sale_id/manual_complete_sale" => "manual_sales#manual_complete_sale", :as => "manual_complete_sale"
|
get "/sales/:sale_id/manual_complete_sale" => "manual_sales#manual_complete_sale", :as => "manual_complete_sale"
|
||||||
get "/sales/:sale_id/void" => "manual_sales#void", :as => "void"
|
get "/sales/:sale_id/void" => "manual_sales#void", :as => "void"
|
||||||
post "sales/:sale_id/manual_void_sale", to: "manual_sales#manual_void_sale", :as => "manual_void_sale"
|
post "sales/:sale_id/manual_void_sale", to: "manual_sales#manual_void_sale", :as => "manual_void_sale"
|
||||||
|
post "sales/:sale_id/:type/void" => "sales#overall_void"
|
||||||
end
|
end
|
||||||
|
|
||||||
#--------- Reports Controller Sections ------------#
|
#--------- Reports Controller Sections ------------#
|
||||||
|
|||||||
Reference in New Issue
Block a user