<? global $vis_language; ?>
<? if($operation['vis_summary']!=1 && $operation['vis_invoice']!=1){?>
<section id="breadcrumb" class="row m-b m-l-none m-r-none">
	<div class="col-sm-4">
	  <h3 class="m-b-xs text-black"><? echo $title; ?><span id="total_cnt"> (<? echo $invoice_info['count']; ?>)</span></h3>
	  <div>
		  <ul class="breadcrumb bg-empty no-border m-b-xxs no-padder">
			<li><a class="link" href="#/home/quick_view/<? echo $vis_language['TXTHOME']; ?>"><? echo $vis_language['TXTHOME']; ?></a></li>
			<li><a class="link" href="#/billing/billing_menu/<? echo $vis_language['TXTBILLING'];?>"><? echo $vis_language['TXTBILLING']; ?></a></li>
			<li class="active"><? echo $title; ?></li>
		 </ul>
	  </div>
	</div>
	<div class="col-sm-8 m-t-md pull-right">
		<div class="btn-group pull-right m-l">
			<button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"><i class="vh vh-action text-muted"></i> <b class="caret"></b></button>
     <ul class="dropdown-menu dropdown-menu-right text-left">
           <li><a class="link" href="#/billing/quick_view/<? echo $vis_language['TXTSUMMARY']; ?>" onclick="$('#vis_workpanel_div').visExecution('load_module', '<? echo $vis_language['TXTSUMMARY']; ?>',{'vis_module':'billing', 'vis_operation':'quick_view'});"><? echo $vis_language['TXTSUMMARY']; ?></a></li>
			<li><a class="link" href="#/billing/get_orders/<? echo $vis_language['TXTORDERS']; ?>" onclick="$('#vis_workpanel_div').visExecution('load_module', '<? echo $vis_language['TXTORDERS']; ?>', {'vis_module':'billing', 'vis_operation':'get_orders'});"><? echo $vis_language['TXTORDERS']; ?></a></li>
			<li><a class="link" href="#/billing/get_invoices/<? echo $vis_language['TXTINVOICES']; ?>" onclick="$('#vis_workpanel_div').visExecution('load_module', '<? echo $vis_language['TXTINVOICES']; ?>', {'vis_module':'billing', 'vis_operation':'get_invoices'})"><? echo $vis_language['TXTINVOICES']; ?></a></li>
			<li><a class="link" href="#/billing/get_transactions_list/<? echo $vis_language['TXTTRANSACTIONS']; ?>" onclick="$('#vis_workpanel_div').visExecution('load_module', '<? echo $vis_language['TXTTRANSACTIONS']; ?>', {'vis_module':'billing', 'vis_operation':'get_transactions_list'})"><? echo $vis_language['TXTTRANSACTIONS']; ?></a></li>
         </ul>
   </div>
		<div class="col-sm-6 input-group b-a b-2x rounded pull-right">
			<input class="form-control rounded input-sm no-border" type="text" placeholder="<?php echo $vis_language['TXTSEARCHINVOICE']."...";?>" value="<?php echo (isset($operation['vis_invoice_search']))?htmlentities($operation['vis_invoice_search'], ENT_COMPAT, 'UTF-8'):'';?>" id="search_invoice">
			<span class="input-group-btn rounded b-l b-3x">
			<button class="btn btn-sm btn-rounded bg-white b-white btn-icon" type="button"  onclick=" var inv = $('#search_invoice').val(); if(inv.length>2){ $('#vis_workpanel_div').visExecution('load_module', '<? echo $vis_language['TXTINVOICES']; ?>', {'vis_module':'billing', 'vis_operation':'get_invoices','vis_invoice_search' : inv})} else { $('#vis_global_msg_div').visInterface('load_global_message', '<? echo $vis_language['TXTGLOBALSEARCHERROR'];?>'); }">
			<i class="vh vh-search"></i>
			</button>
			</span>
		</div>
   </div>
</section>
<? }?>
<?
   $paging_list='';
   for($i=0;$i<$view_info['page_count'];$i++) $paging_list.='<option value="'.$i.'" '.(($invoice_info['page']==$i)?'selected="selected"':'').'>'.($i+1).'</option>';
   ?>
<? if($operation['vis_summary']==1){?>
<section id="breadcrumb" class="row m-b m-l-none m-r-none">
   <div class="col-sm-6">
      <h3 class="m-b-xs text-black"><? echo $title; ?><span id="total_cnt"> (<? echo $invoice_count; ?>)</span></h3>
      <ul class="breadcrumb bg-empty no-border m-b-xxs no-padder">
         <li><a class="link" href="#/home/quick_view/<? echo $vis_language['TXTHOME']; ?>"><? echo $vis_language['TXTHOME']; ?></a></li>
         <li><a class="link" href="#/billing/billing_menu/<? echo $vis_language['TXTBILLING'];?>"><? echo $vis_language['TXTBILLING']; ?></a></li>
         <li class="active"><? echo $title; ?></li>
      </ul>
   </div>
</section>
<?}?>
    <?if($invoice_count!=0) {
         $invoice_status = array( 0 => $vis_language['TXTUNPAID'], 1 => $vis_language['TXTPAID'], 2 => $vis_language['TXTCANCELED'], 3 => $vis_language['TXTINPROCESS'] );
		$is_ticket_details_tab = (isset($operation['vis_org_operation']) && $operation['vis_org_operation']=='ticket_details' || isset($operation['vis_ticket_id'])) ? 1 : 0;
         ?>
         <? if($operation['vis_invoice']!=1){ ?>
<section class="padder"  id="invoice_listing">
		    <section class="panel panel-default">
   <? } ?>
   <form class="form-horizontal" role="form" id="vis_invoice_list_form" name="vis_invoice_list_form" method="post">
      <div class="row wrapper clr">
		<div class="col-sm-9 tkt_left_menu">
			<? if(isset($operation['vis_draft']) && $operation['vis_draft']==1) { ?>
			<div class="btn-group select">
			  </div>
			<? }
				else { ?>
			<div class="vis_mass_action">
			<div class="btn-group">
			  <button class="btn bg-empty btn-sm dropdown-toggle action_btn" data-toggle="dropdown">
				<i class="vh vh-action"></i> <span class="caret"></span>
			  </button>
				<ul class="dropdown-menu">
					<li><a href="javascript:void(0);" onclick="send_invoice()"><? echo $vis_language['TXTSEND']; ?></a></li>
					<li><a href="javascript:void(0);" id="del_invoice" onclick="delete_invoice();"><? echo $vis_language['TXTDELETE']; ?></a></li>
					<li><a href="javascript:void(0);" id="mark_unpaid" onclick="update_invoice_status(0);"><? echo $vis_language['TXTMARKUNPAID']; ?></a></li>
					<li><a href="javascript:void(0);" id="mark_cancelled" onclick="update_invoice_status(2);"><? echo $vis_language['TXTMARKCANCEL']; ?></a></li>
				</ul>
			</div>
			</div>
			<? }//else ?>
		  </div>
        <div class="col-sm-3 text-right text-center-xs tkt_right_menu" id="paging">
            <? if($operation['vis_invoice'] ==1): ?>
                <select name="pageing" class="form-control input-sm selectpicker pull-right paging v-middle" onchange="$(this).parents('#vis_details_list').visExecution('load_area',{'vis_module':'billing', 'vis_operation':'get_invoices', 'vis_page':this.value ,'vis_client_id':'<? echo $operation['vis_client_id']; ?>','vis_filter':'<? echo $filterSet; ?>','vis_title': '<? echo $title; ?>'})">
			    <? else: ?>
				<select name="pageing" class="form-control input-sm selectpicker pull-right paging v-middle" onchange="$(this).parents('#vis_workpanel_div').visExecution('load_area',{'vis_module':'billing', 'vis_operation':'get_invoices', 'vis_page':this.value,'vis_filter':'<? echo $filterSet; ?>','vis_title': '<? echo $title; ?>'})">
			   	<? endif; ?>
            <? echo $paging_list;?>
            </select>
            <div class="text-muted pull-right label_page"><? echo $vis_language['TXTPAGE']; ?>:</div>
         </div>
      </div>
      <div class="table-responsive scroll-x">
         <table class="table table-hover b-t b-light m-b-none" data-ride="datatables">
            <thead class="table_head">
               <tr>
				  <th>
						<div class="btn-group">
							<label class="checkbox m-n m-r-sm i-checks"  style="float: left;"><input type="checkbox"><i></i></label>
						</div>
				  </th>
                  <th><? echo $vis_language['TXTINVOICE']."#"; ?></th>
                  <th class="txt_nowrap"><? echo $vis_language['TXTCLIENT']; ?></th>
                  <th class="txt_nowrap"><? echo $vis_language['TXTCREATEDATE']; ?></th>
                  <th class="txt_nowrap"><? echo $vis_language['TXTDUEDATE']; ?></th>
                  <th class="txt_nowrap"><? echo $vis_language['TXTPAIDDATE']; ?></th>
                  <th class="txt_nowrap"><? echo $vis_language['TXTTOTAL']; ?></th>
                  <th class="txt_nowrap"><? echo $vis_language['TXTSTATUS']; ?></th>
                  <th></th>
               </tr>
            </thead>
            <tbody>
               <?
                  $total=0;
                  $paid=0;
                  $unpaid=0;
                        for($i=0;$i<$invoice_count;$i++) {
                        echo '<tr>';
                        $lableCol = '';
                        if($invoices[$i]['invoice_status'] == 0)
                        {
							$lableCol = 'vh-danger-bg';
						}
						else if($invoices[$i]['invoice_status'] == 1)
						{
							$lableCol = 'label vh-green-bg';
						}
						else
						{
							$lableCol = 'label label-default';
						}
                        ?>
				<? echo '<td width="30" id="checkbox_data"><label class="checkbox m-n i-checks"><input type="checkbox" name="vis_global_mass_chk_'.$i.'" id="vis_global_mass_chk_'.$i.'" value="'.$invoices[$i]['invoice_id'].'" /><i></i></label></td>';	?>
               <td class="vis-pointer" onclick="$('#vis_workpanel_div').visExecution('load_module','invoices/<?echo $invoices[$i]['invoice_id']?>',{'vis_module':'billing','vis_operation':'edit_invoice', 'vis_invoice_id':<?echo $invoices[$i]['invoice_id']?>})"><? echo $invoices[$i]['invoice_hash'];?></td>
               <td class="vis-pointer"><a  onclick="$('#vis_workpanel_div').visExecution('load_area',{'vis_module':'client','vis_operation':'client_details', 'vis_client_id':<?echo $invoices[$i]['client_id']?>});" ><? echo $invoices[$i]['first_name'].' ('.$invoices[$i]['email'].')'; ?></a></td><? echo'<td>'.format_datetime($invoices[$i]['entry_date']).'</td><td>'.format_datetime($invoices[$i]['due_date']).'</td><td>'.format_datetime($invoices[$i]['paid_date']).'</td><td>'.$invoices[$i]['total'].'</td><td><span class="label '.$lableCol.'">'.$invoice_status[$invoices[$i]['invoice_status']].'</span></td>';
                  if($invoices[$i]['invoice_status']==0) ?>
               <td align="center"><a class="m" href="javascript:void(0);" onclick="$('#vis_global_msg_div').visExecution('load_operations',{'vis_module':'billing','vis_operation':'send_invoice', 'vis_invoice_id':<?echo $invoices[$i]['invoice_id']?>});" title="<? echo $vis_language['TXTSEND']; ?>"><i class="vh vh-mail-forward text-muted"></i></a>
                  <a class="text-muted m"  href="javascript:void(0);"  data-toggle="ajaxModal" data-modal-arguments="vis_module=billing&vis_operation=get_delete_invoice&vis_invoice_id=<? echo $invoices[$i]['invoice_id'];?>&vis_client_id=<? echo $invoices[$i]['client_id'];?>&vis_static_area=vis_ticket_invoice_form&vis_ticket_id=<?= isset($operation['vis_ticket_id'])?$operation['vis_ticket_id']:$invoices[$i]['ticket_id'];?>" title="<? echo $vis_language['TXTDELETE']; ?>"><i class="vh vh-delete-round"></i></a>
                 <input type="hidden" name="vis_ticket_id" value="<? echo $invoices[$i]['ticket_id'];?>">
                 <input type="hidden" name="vis_client_id" value="<? echo $clientId;?>">
               </td>
               <?   } ?>
               </tr>
            </tbody>
         </table>
      </div>
      <footer class="wrapper panel-footer bg-white">
         <div class="row">
            <div class="col-sm-9 tkt_left_menu">
			<? if(isset($operation['vis_draft']) && $operation['vis_draft']==1) { ?>
			<div class="btn-group select">
			  </div>
			<? }
				else { ?>
			<div class="vis_mass_action">
			<div class="btn-group">
			  <button class="btn bg-empty btn-sm dropdown-toggle action_btn" data-toggle="dropdown">
				<i class="vh vh-action"></i> <span class="caret"></span>
			  </button>
				<ul class="dropdown-menu">
					<li><a href="javascript:void(0);" onclick="send_invoice()"><? echo $vis_language['TXTSEND']; ?></a></li>
					<li><a href="javascript:void(0);" id="del_invoice1" onclick="delete_invoice();"><? echo $vis_language['TXTDELETE']; ?></a></li>
					<li><a href="javascript:void(0);" id="mark_unpaid" onclick="update_invoice_status(0);"><? echo $vis_language['TXTMARKUNPAID']; ?></a></li>
					<li><a href="javascript:void(0);" id="mark_cancelled" onclick="update_invoice_status(2);"><? echo $vis_language['TXTMARKCANCEL']; ?></a></li>
				</ul>
			</div>
			</div>
			<? }//else ?>
		  </div>
               <div class="col-sm-3 text-right text-center-xs tkt_right_menu" id="paging">
                <? if($operation['vis_invoice'] ==1): ?>
                <select name="pageing" class="form-control input-sm selectpicker pull-right paging v-middle" onchange="$(this).parents('#vis_details_list').visExecution('load_area',{'vis_module':'billing', 'vis_operation':'get_invoices', 'vis_page':this.value ,'vis_client_id':'<? echo $operation['vis_client_id']; ?>'})">
			    <? else: ?>
				<select name="pageing" class="form-control input-sm selectpicker pull-right paging v-middle" onchange="$(this).parents('#vis_workpanel_div').visExecution('load_area',{'vis_module':'billing', 'vis_operation':'get_invoices', 'vis_page':this.value})">
			   	<? endif; ?>
               <? echo $paging_list;?>
               </select>
               <div class="text-muted pull-right label_page"><? echo $vis_language['TXTPAGE']; ?>:</div>
            </div>
         </div>
      </footer>
   </form>
   <? if($operation['vis_invoice']!=1){ ?>
</section>  </section>
<?  } ?>
 <? }
         else {
            include(VIS_PATH_TEMPLATE.'no_record_yet.php');
         }
         ?>
<script type="text/javascript">
	$(".selectpicker").selectpicker();
   $(document).ready(function() {
   $('[data-ride="datatables"]').dataTable({
           "bPaginate" : false,
            "aaSorting" : [],
   		"sDom": 't', "bAutoWidth": false,
   		"aoColumns": [
   		{ "bSortable": false },
   		  	null,
   		  	null,
   		  	null,
   		  	null,
   		  	null,
   		  	null,
   		  	null,
   			{ "bSortable": false }
   		]
   	});
   });
   
	function show_access()
	{
		$("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['MSGACCSSDND'];?>");
		return false;
	}
   function delete_invoice()
   {
		var selected = [];
		var selected1 = [];
		var vis_action = "";
		$('#checkbox_data input:checked').each(function() {
		selected.push($(this).attr('name'));
		selected1.push($(this).attr('value'));
		vis_action +=$(this).attr('name')+"="+$(this).attr('value')+",";
		});
		if( selected.length > 0)
		{
			vis_action= vis_action.substring(0, vis_action.length-1);
			$('#del_invoice').attr('data-toggle','ajaxModal');
			$('#del_invoice').attr('data-modal-arguments','vis_module=billing&vis_operation=get_delete_invoice&vis_action='+vis_action+'&vis_static_area=vis_invoice_list_delete_area');
			$('#del_invoice1').attr('data-toggle','ajaxModal');
			$('#del_invoice1').attr('data-modal-arguments','vis_module=billing&vis_operation=get_delete_invoice&vis_action='+vis_action+'&vis_static_area=vis_invoice_list_delete_area');
		}
		 else
		{
			$("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['MSGINVOICENOTSELECTED'];?>");
			return false;
		}
	}
   function send_invoice()
   {
		var selected = [];
		var selected1 = [];
		$('#checkbox_data input:checked').each(function() {
		selected.push($(this).attr('name'));
		selected1.push($(this).attr('value'));
		});
		if( selected.length > 0)
		{
			$("#vis_workpanel_div").visExecution('submit_form',{'vis_module':'billing', 'vis_operation':'send_invoice', 'vis_form':'vis_invoice_list_form', 'vis_page':'<? echo $invoice_info['page']; ?>'})
		}
		 else
		{
			$("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['MSGINVOICENOTSELECTED'];?>");
			return false;
		}
	}
	 function update_invoice_status(id)
   {
		var selected = [];
		var selected1 = [];
		$('#checkbox_data input:checked').each(function() {
		selected.push($(this).attr('name'));
		selected1.push($(this).attr('value'));
		});
		if(selected.length > 0)
		{
			$("#vis_workpanel_div").visExecution('submit_form',{'vis_module':'billing', 'vis_operation':'update_mass_invoice_status', 'vis_form':'vis_invoice_list_form', 'vis_client_id':'<? echo $operation['vis_client_id']; ?>','vis_update_id':id})
		}
		 else
		{
			$("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['MSGINVOICENOTSELECTED'];?>");
			return false;
		}
	}
</script>
