credit payment function

This commit is contained in:
phyusin
2018-07-10 18:12:25 +06:30
parent d0118d2cfc
commit bf0f76ebc7
29 changed files with 879 additions and 462 deletions

View File

@@ -118,7 +118,9 @@
<% else %>
No Tax
<% end %></strong><br>
<button class="btn btn-link waves-effect bg-info change_tax">Change Tax</button>
<%if @sale_payment.nil? %>
<button class="btn btn-link waves-effect bg-info change_tax">Change Tax</button>
<% end %>
</td>
<td class="item-attr"><strong><span id="total_tax"><%= number_with_precision(@sale_data.total_tax, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%></span></strong></td>
</tr>
@@ -164,21 +166,21 @@
<div class="card">
<div class="card-header">
<div class="row m-l-5 m-r-5">
<div class="col-md-8"><strong>Amount Due</strong></div>
<div class="col-md-8"><strong>Amount Due <% if !@sale_payment.nil? %>( Credit )<% end %></strong></div>
<div class="col-md-4">
<strong>
<span id="grand_total" class="hidden">
<% if @sale_payment.nil? %>
<%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i)%>
<% else %>
<%= number_with_precision(@sale_payment.payment_amount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i)%>
<%= number_with_precision(@sale_payment[0].payment_amount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i)%>
<% end %>
</span>
<span id="amount_due">
<% if @sale_payment.nil? %>
<%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
<% else %>
<%= number_with_precision(@sale_payment.payment_amount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i)%>
<%= number_with_precision(@sale_payment[0].payment_amount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i)%>
<% end %>
</span>
</strong>
@@ -206,12 +208,16 @@
<% if @other == 0.0 && @ppamount == 0.0 && @visacount == 0.0 && @jcbcount == 0.0 && @mastercount == 0.0 && @unionpaycount == 0.0 && @alipaycount == 0.0 && @paymalcount == 0.0 && @junctionpaycount == 0.0 && @dingacount == 0.0 && @giftvouchercount == 0.0 %>
<div class="row payment other-payment-color" id="card_payment" >
<div class="col-md-8">Other Payments</div>
<div class="col-md-4" id="others"><%= number_with_precision(@other, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %></div>
<div class="col-md-4" id="others">
<%= number_with_precision(@other, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %>
</div>
</div>
<% else %>
<div class="row payment other-payment-color" id="card_payment" >
<div class="col-md-8">Other Payments</div>
<div class="col-md-4" id="other_payment_amount"><%= number_with_precision(@other_payment, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %></div>
<div class="col-md-4" id="other_payment_amount">
<%= number_with_precision(@other_payment, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %>
</div>
</div>
<% end %>
</div>
@@ -399,22 +405,26 @@
</button>
<!-- -->
<% if current_login_employee.role == "cashier" %>
<% if @other_payment <= 0%>
<% if @other_payment <= 0 && @sale_payment.nil? %>
<a class="btn btn-block bg-deep-purple waves-effect access_modal" data-toggle="modal" data-type="foc"> FOC</a>
<%end %>
<a class="btn btn-block bg-red waves-effect access_modal" data-toggle="modal" data-type="void"> Void</a>
<a class="btn btn-block bg-deep-purple waves-effect access_modal" data-toggle="modal" data-type="waste"> Waste</a>
<a class="btn btn-block bg-deep-purple waves-effect access_modal" data-toggle="modal" data-type="spoile"> Spoile</a>
<% if @sale_payment.nil? %>
<a class="btn btn-block bg-red waves-effect access_modal" data-toggle="modal" data-type="void"> Void</a>
<a class="btn btn-block bg-deep-purple waves-effect access_modal" data-toggle="modal" data-type="waste"> Waste</a>
<a class="btn btn-block bg-deep-purple waves-effect access_modal" data-toggle="modal" data-type="spoile"> Spoile</a>
<% end %>
<% else %>
<% if @other_payment <= 0%>
<% if @other_payment <= 0 && @sale_payment.nil?%>
<button type="button" class="btn bg-deep-purple btn-block" data-toggle="modal" data-target="#focModal" <%= (can? :foc, :payment)? ' ': 'disabled=' %> active="true"> FOC </button>
<%end %>
<button type="button" class="btn bg-red btn-block" data-toggle="modal" data-target="#voidModal" <%= (can? :overall_void, :void)? ' ': 'disabled=' %> > Void </button>
<button type="button" class="btn btn-block bg-deep-purple waves-effect " data-status="waste" value="waste" id="btn_waste" onclick="waste_and_spoilage('waste')">Waste</button>
<button type="button" class="btn btn-block bg-deep-purple waves-effect " data-status="spoile" value="spoile" id="btn_spoile" onclick="waste_and_spoilage('spoile')">Spoile</button>
<% if @sale_payment.nil? %>
<button type="button" class="btn bg-red btn-block" data-toggle="modal" data-target="#voidModal" <%= (can? :overall_void, :void)? ' ': 'disabled=' %> > Void </button>
<button type="button" class="btn btn-block bg-deep-purple waves-effect " data-status="waste" value="waste" id="btn_waste" onclick="waste_and_spoilage('waste')">Waste</button>
<button type="button" class="btn btn-block bg-deep-purple waves-effect " data-status="spoile" value="spoile" id="btn_spoile" onclick="waste_and_spoilage('spoile')">Spoile</button>
<% end %>
<% end %>
<% if @cashier_type=="quick_service" %>
<% if @cashier_type=="quick_service" && @sale_payment.nil? %>
<hr>
<button type="button" id="survey" class="btn btn-block bg-blue waves-effect"><%= t("views.right_panel.detail.survey") %></button>
@@ -710,7 +720,7 @@ var pdf_view = '<%=@pdf_view%>';
customer_display_view(null,"reload");
var sale_id = $('#sale_id').text();
if (cashier_type=="cashier") {
window.location.href = '/origami/table/'+ dining_id;
window.location.href = '/origami/table/'+ dining_id;
}else{
window.location.href = '/origami/quick_service/pending_order/'+sale_id;
}
@@ -738,7 +748,11 @@ var pdf_view = '<%=@pdf_view%>';
$('#card_payment').click(function() {
localStorage.setItem("cash",$('#cash').text() );
var sale_id = $('#sale_id').text();
window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment/others_payment"
var url_param = "payment";
if(location.pathname.includes("credit_payment")){
url_param = "credit_payment";
}
window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/"+url_param+"/others_payment";
return false;
});
@@ -799,8 +813,15 @@ var pdf_view = '<%=@pdf_view%>';
// $("#pdfModal").on('shown.bs.modal', function () {
// $('#pdfModal').focus() }).modal({show : true, backdrop : false, keyboard : false});
/* check credit payment or not*/
if(location.pathname.includes("credit_payment")){
var url = "<%= origami_credit_payment_cash_path %>";
}else{
var url = "<%= origami_payment_cash_path %>";
}
$.ajax({type: "POST",
url: "<%= origami_payment_cash_path %>",
url: url,
data: "cash="+ cash + "&sale_id=" + sale_id + "&type=" + cashier_type + "&tax_type=" + tax_type,
success:function(result){
/* start delete receipt no in first bill*/
@@ -819,28 +840,31 @@ var pdf_view = '<%=@pdf_view%>';
}
$("#loading_wrapper" ).hide();
//PDF lightbox data
var pdfPath = "/en/pdfjs/minimal?file=" + result.filename.substring(6);
$("#sale_receipt_no").val(result.receipt_no);
$("#filename").val(result.filename);
$("#printer_name").val(result.printer_name);
$("#receipt_pdf").attr("src", pdfPath);
$("#changed_amount").text("");
if($('#balance').text() < 0){
<% if precision.to_i > 0 %>
$("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1)).toFixed(<%= precision %>));
<% else %>
$("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1)));
<% end %>
}
if (pdf_view == 1) {
$("#pdfModal").modal({show : true, backdrop : false, keyboard : false});
$("#pdfModalLabel").text("Sale Completed");
if(location.pathname.includes("credit_payment")){
payment_success_alert();
}else{
//PDF lightbox data
print_receipt();
//PDF lightbox data
var pdfPath = "/en/pdfjs/minimal?file=" + result.filename.substring(6);
$("#sale_receipt_no").val(result.receipt_no);
$("#filename").val(result.filename);
$("#printer_name").val(result.printer_name);
$("#receipt_pdf").attr("src", pdfPath);
$("#changed_amount").text("");
if($('#balance').text() < 0){
<% if precision.to_i > 0 %>
$("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1)).toFixed(<%= precision %>));
<% else %>
$("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1)));
<% end %>
}
if (pdf_view == 1) {
$("#pdfModal").modal({show : true, backdrop : false, keyboard : false});
$("#pdfModalLabel").text("Sale Completed");
}else{
//PDF lightbox data
print_receipt();
}
}
}
});
@@ -948,7 +972,7 @@ var pdf_view = '<%=@pdf_view%>';
$(document).on('click', '.cashier_number', function(event){
if(event.handled !== true) {
var original_value;
original_value = $('#cash').text();
original_value = parseFloat($('#cash').text());
var input_type = $(this).attr("data-type");
@@ -1110,33 +1134,37 @@ var pdf_view = '<%=@pdf_view%>';
customer_display_view(null,"reload");
}
}else{
var title = "Payment Successful!";
if($('#balance').text() < 0){
var text = 'Changed amount ' + $('#balance').text() * (-1);
}else{
$('#pay').text("Pay");
var text = 'Thank You !';
}
swal({
title: "Payment Successful!",
text: text,
html: true,
closeOnConfirm: false,
closeOnCancel: false,
allowOutsideClick: false
}, function () {
if (cashier_type=="cashier") {
window.location.href = '/origami';
}else{
window.location.href = '/origami/quick_service';
customer_display_view(null,"reload");
}
});
payment_success_alert();
}
}
});
}
function payment_success_alert(){
var title = "Payment Successful!";
if($('#balance').text() < 0){
var text = 'Changed amount ' + $('#balance').text() * (-1);
}else{
$('#pay').text("Pay");
var text = 'Thank You !';
}
swal({
title: "Payment Successful!",
text: text,
html: true,
closeOnConfirm: false,
closeOnCancel: false,
allowOutsideClick: false
}, function () {
if (cashier_type=="cashier") {
window.location.href = '/origami';
}else{
window.location.href = '/origami/quick_service';
customer_display_view(null,"reload");
}
});
}
$(".btn_pdf_close").on('click',function(){