From 5bd1daa152f16afdaac9dd2a238714a7fa0bfaa1 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 22 Dec 2017 17:51:02 +0630 Subject: [PATCH] update payment and memberdiscoun --- app/assets/javascripts/origami.js | 27 +++- app/views/origami/home/show.html.erb | 2 +- app/views/origami/payments/show.html.erb | 151 ++++++++++++++--------- app/views/origami/rooms/show.html.erb | 3 +- 4 files changed, 114 insertions(+), 69 deletions(-) diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index e649f4b4..725e6353 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -145,30 +145,45 @@ $(document).on('turbolinks:load', function() { }); /* start check first bill or not funs: */ -function checkReceiptNoInFirstBillData(receipt_no) { +function checkReceiptNoInFirstBillData(receipt_no,payment=null) { + // localStorage.removeItem('receipt_lists'); var status = false; if((receipt_no!=undefined) && (receipt_no!="")){ if(localStorage.hasOwnProperty("receipt_lists")===true){ var arr_data = JSON.parse(localStorage.getItem("receipt_lists")); - var json_data = arr_data.filter(function(e) { return e.receipt_no !== receipt_no }); + console.log(arr_data) + if (payment) { + var json_data = arr_data.filter(function(e) { return e.receipt_no == receipt_no }); + }else{ + 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; + if (payment) { + return json_data[0]["payment"]; + }else{ + return status; + } } -function createReceiptNoInFirstBillData(receipt_no) { +function createReceiptNoInFirstBillData(receipt_no,payment=null) { var arr_data = []; var json_data = []; if(localStorage.hasOwnProperty("receipt_lists")===true){ arr_data = JSON.parse(localStorage.getItem("receipt_lists")); json_data = arr_data.filter(function(e) { return e.receipt_no == receipt_no }); + if (payment) { + jdata = arr_data.filter(function(e) { return e.receipt_no !== receipt_no }); + jdata.push({'receipt_no':receipt_no,'payment':payment}); + localStorage.setItem("receipt_lists",JSON.stringify(jdata)); + } } if(((arr_data.length == 0) && (json_data.length == 0)) || ((arr_data.length > 0) && (json_data.length == 0))){ - arr_data.push({'receipt_no':receipt_no}); + arr_data.push({'receipt_no':receipt_no,'payment':payment}); localStorage.setItem("receipt_lists",JSON.stringify(arr_data)); } } diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 0fa545a3..5471b5e4 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -596,7 +596,7 @@ $( "#loading_wrapper" ).hide(); receipt_no = ($("#receipt_no").html()).trim(); if((receipt_no!=undefined) && (receipt_no!="")) - createReceiptNoInFirstBillData(receipt_no); + createReceiptNoInFirstBillData(receipt_no,type); location.reload(); } diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 848a0b40..1cf61690 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -290,6 +290,21 @@