$(document).ready(function(){for(var t="",f,r,n=0;n<invoicesArray.length;n++){var u=invoicesArray[n].id,e=invoicesArray[n].date,o=invoicesArray[n].from_date,s=invoicesArray[n].to_date,h=invoicesArray[n].totalAmount,c=invoicesArray[n].amount_currency,l=invoicesArray[n].is_paid,a=invoicesArray[n].is_pending,v=invoicesArray[n].is_declined,y=invoicesArray[n].is_offline,p=invoicesArray[n].dueDate,w=invoicesArray[n].active,i="";i=l==1?y!=1?"<span class='invoice-status paid'>Paid<\/span>":"<span class='invoice-status paid'>Paid Offline<\/span>":"<span class='invoice-status unpaid'>Not Paid<\/span>",a==1&&(i="<span class='invoice-status pending'>Pending<\/span>"),v==1&&(i="<span class='invoice-status declined'>Declined<\/span>"),f="INV-"+invoicesArray[n].date_mysql_format.replace(/-/g,"")+u,t+="<tr invoiceid='"+u+"' startdate='"+invoicesArray[n].startdate+"' enddate='"+invoicesArray[n].enddate+"' clientid='"+invoicesArray[n].client_id+"'>",t+="<td><a class='view-invoice' title='View Invoice' target='_blank' href='billing_log_invoice.php?invoice_id="+invoicesArray[n].date_mysql_format.replace(/-/g,"")+u+"&rkey="+invoicesArray[n].sess_key+"' target='_blank'>"+f+"<\/a><\/td>",t+="<td>"+e+"<\/td>",t+="<td>"+o+"<\/td>",t+="<td>"+s+"<\/td>",t+="<td>"+h+" "+c+"<\/td>",t+="<td>"+i+"<\/td>",t+="<td>"+p+"<\/td>",t+="<td>",w=="1"&&(t+="<a href='#' class='email-invoice-button' title='Email Invoice to Client'><img width='16' src='images/email-icon.gif' /><\/a> ",invoicesArray[n].is_paid!=1&&invoicesArray[n].is_pending!=1&&(t+="<a href='#' class='regenerate-invoice-button' title='Regenerate Invoice'><img width='16' src='images/regenerate.png' /><\/a> ",t+="<a href='#' class='offline-payment-button' title='Click here to mark as Paid Offline'><img width='16' src='images/money_icon.png'/><\/a> "),invoicesArray[n].is_offline==1&&(t+="<a href='#' class='offline-payment-reverse-button' title='Set as not paid'><img width='16' src='images/money_icon_x.png' /><\/a> "),t+="<a href='#' class='delete-invoice-button' title='Delete Invoice'><img src='images/delete.gif' /><\/a>"),t+="<\/td>",t+="<\/tr>"}$("#invoices-table tbody").html(t),$(".delete-invoice-button, .email-invoice-button, .view-invoice, .regenerate-invoice-button, .offline-payment-button, .offline-payment-reverse-button").tooltipster({position:"bottom",theme:".tooltipster-shadow"}),$(".offline-payment-reverse-button").click(function(){if(confirm('Are you sure you want to mark as "Not Paid"?')){var n=$(this),t=n.parents("tr:eq(0)").attr("invoiceid");$.ajax({url:"billing_log.php",type:"POST",dataType:"json",data:{ajaxRequest:"markInvoicePaidOfflineReverse",invoiceId:t},success:function(){window.location="billing_log.php"}})}}),$(".offline-payment-button").click(function(){if(confirm('Are you sure you want to mark the invoice as "Paid Offline"?')){var n=$(this),t=n.parents("tr:eq(0)").attr("invoiceid");$.ajax({url:"billing_log.php",type:"POST",dataType:"json",data:{ajaxRequest:"markInvoicePaidOffline",invoiceId:t},success:function(){window.location="billing_log.php"}})}}),$(".delete-invoice-button").click(function(){if(confirm("Are you sure you want to delete the invoice?")){var n=$(this),t=n.parents("tr:eq(0)").attr("invoiceid");$.ajax({url:"billing_log.php",type:"POST",dataType:"json",data:{ajaxRequest:"deleteInvoice",invoiceId:t},success:function(){window.location="billing_log.php"}})}}),r=!1,$(".regenerate-invoice-button").click(function(){if(r===!0)alert("Please wait while the other process finishes.");else if(confirm("Are you sure you want to regenerate the invoice?")){var n=$(this),t=n.parents("tr:eq(0)").attr("invoiceid"),i=n.parents("tr:eq(0)").attr("clientid"),u=n.parents("tr:eq(0)").attr("startdate"),f=n.parents("tr:eq(0)").attr("enddate");$.ajax({url:"invoice.php",type:"GET",dataType:"json",data:{client_id:i,start_date:u,end_date:f,invoice_id:t},success:function(){r=!1,alert("Finished regenerating invoice!"),window.location="billing_log.php"}}),r=!0}}),$(".email-invoice-button").click(function(){if(confirm("When you click Ok, the invoice will be sent to the client with a button to pay using Paypal.")){var n=$(this),t=n.parents("tr:eq(0)").attr("invoiceid");$.ajax({url:"billing_log.php",type:"POST",dataType:"json",data:{ajaxRequest:"emailInvoice",invoiceId:t},success:function(){alert("Email sent successfully!")}})}}),$("#exportCsvButton").click(function(){var n=$(this).attr("clientid");$.ajax({url:"billing_log.php",type:"POST",dataType:"json",data:{ajaxRequest:"exportCsv",clientId:n},success:function(){}})})})