check first bill or not

This commit is contained in:
phyusin
2017-12-21 15:11:11 +06:30
parent 9b037f9daf
commit 11b8466e10
4 changed files with 91 additions and 14 deletions

View File

@@ -15,8 +15,6 @@
//= require BSBMaterial/demo.js
//= require custom.js
var _FIRST_BILL_ = "";
$(document).on('turbolinks:load', function() {
$('.datetimepicker').bootstrapMaterialDatePicker({
format: 'DD-MM-YYYY - HH:mm',
@@ -145,3 +143,42 @@ $(document).on('turbolinks:load', function() {
return false;
});
});
/* start check first bill or not funs: */
function checkReceiptNoInFirstBillData(receipt_no) {
var status = false;
if((receipt_no!=undefined) && (receipt_no!="")){
var arr_data = JSON.parse(localStorage.getItem("receipt_lists"));
if((arr_data!=undefined) && (arr_data!=null)){
var json_data = arr_data.filter(function(e) { return e.receipt_no !== receipt_no });
if((arr_data.length) > (json_data.length)){
status = true;
}
}
}
return status;
}
function createReceiptNoInFirstBillData(receipt_no) {
var arr_data = [];
var json_data = [];
var receipt_lists = localStorage.getItem("receipt_lists");
if((receipt_lists!=undefined) && (receipt_lists!=null) && (receipt_lists!="")){
arr_data = JSON.parse(localStorage.getItem("receipt_lists"));
json_data = arr_data.filter(function(e) { return e.receipt_no == receipt_no });
}
if(((arr_data.length == 0) && (json_data.length == 0)) || ((arr_data.length > 0) && (json_data.length == 0))){
arr_data.push({receipt_no});
localStorage.setItem("receipt_lists",JSON.stringify(arr_data));
}
}
function deleteReceiptNoInFirstBillData(receipt_no) {
var arr_data = JSON.parse(localStorage.getItem("receipt_lists"));
if((arr_data!=undefined) && (arr_data!=null)){
var json_data = arr_data.filter(function(e) { return e.receipt_no !== receipt_no });
localStorage.setItem("receipt_lists",JSON.stringify(json_data));
}
}
/* end check first bill or not funs: */

View File

@@ -156,8 +156,7 @@
<div class="col-lg-6 col-md-6 col-sm-6">
&nbsp; Receipt No: <span id="receipt_no">
<% if @status_sale == 'sale' %>
<%= @sale_array[0].receipt_no rescue '' %>
<%= @sale_array[0].receipt_no rescue '' %>
<% end %>
</span>
<br>
@@ -439,6 +438,18 @@
</div>
<script>
$(document).ready(function () {
/* start check first bill or not*/
var receipt_no = "";
if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){
receipt_no = ($("#receipt_no").html()).trim();
}
// console.log(checkReceiptNoInFirstBillData(receipt_no));
if(checkReceiptNoInFirstBillData(receipt_no)){
$("#pay").show();
}else{
$("#pay").hide();
}
/* end check first bill or not*/
$('.invoicedetails').on('click', function () {
var dining_id = "<%= @dining.id %>";
@@ -555,14 +566,19 @@
// Print for first bill
$("#first_bill").on('click', function () {
var sale_id = $('#sale_id').val();
var ajax_url = "/origami/sale/" + sale_id + "/first_bill";
$.ajax({
type: "GET",
url: ajax_url,
success: function (result) {
location.reload();
}
});
var ajax_url = "/origami/sale/" + sale_id + "/first_bill";
$.ajax({
type: "GET",
url: ajax_url,
success: function (result) {
receipt_no = ($("#receipt_no").html()).trim();
if((receipt_no!=undefined) && (receipt_no!=""))
createReceiptNoInFirstBillData(receipt_no);
location.reload();
}
});
});
$(".choose_payment").on('click', function () {
$( "#loading_wrapper").show();
@@ -625,11 +641,12 @@
url: ajax_url,
// data: 'order_id='+ order_id,
success: function (result) {
if (!result.status) {
swal("Information!", result.error_message);
}
else {
location.reload();
else {
location.reload();
}
}
});

View File

@@ -405,6 +405,12 @@
data: "cash="+ cash + "&sale_id=" + sale_id,
async: false,
success:function(result){
/* start delete receipt no in first bill*/
if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){
var receipt_no = ($("#receipt_no").html()).trim();
deleteReceiptNoInFirstBillData(receipt_no);
}
/* end delete receipt no in first bill*/
localStorage.removeItem("cash");
if (result.status) {

View File

@@ -447,6 +447,19 @@ $(document).ready(function(){
// window.location.href = '/origami/order/' + order_id;
// })
/* start check first bill or not*/
var receipt_no = "";
if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){
receipt_no = ($("#receipt_no").html()).trim();
}
// console.log(checkReceiptNoInFirstBillData(receipt_no));
if(checkReceiptNoInFirstBillData(receipt_no)){
$("#pay").show();
}else{
$("#pay").hide();
}
/* end check first bill or not*/
$('.invoicedetails').on('click',function(){
var dining_id = "<%= @room.id %>";
var sale_id = this.id;
@@ -569,6 +582,10 @@ $("#first_bill").on('click', function(){
type: "GET",
url: ajax_url,
success:function(result){
receipt_no = ($("#receipt_no").html()).trim();
if((receipt_no!=undefined) && (receipt_no!=""))
createReceiptNoInFirstBillData(receipt_no);
location.reload();
}
});