<? global $vis_language;
$orderStatus = array('1' => $vis_language['TXTACTIVE'],'2' => $vis_language['TXTPENDING'],'3' => $vis_language['TXTINCOMPLETE'],'4' => $vis_language['TXTCANCELED']);
$invoice_status = array( 0 => $vis_language['TXTUNPAID'], 1 => $vis_language['TXTPAID'], 2 => $vis_language['TXTCANCELED'], 3 => $vis_language['TXTINPROCESS'] );
    $paging_list='';
    for($i=0;$i<$view_info['page_count'];$i++) $paging_list.='<option value="'.$i.'" '.(($order_info['page']==$i)?'selected="selected"':'').'>'.($i+1).'</option>';
?>
<? if($operation['vis_order']!=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 $vis_language['TXTORDERS']; ?><span id="total_cnt"> (<? echo $order_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 $vis_language['TXTORDERS']; ?></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']))?$operation['vis_invoice_search']:'';?>" 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><? }?>
<?  if($orders!=-1) {?>
	<? if($operation['vis_order']!=1) {?>
<div class="col-lg-12">
      <section class="panel panel-default"> <? }?>
      <form name="vis_order_list_form" id="vis_order_list_form">
         <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);" id="del_order" onclick="delete_order();"><? echo $vis_language['TXTDELETE']; ?></a></li>
				</ul>
			</div>
			</div>
			<? }//else ?>
		  </div>
               <div class="col-sm-3 text-right text-center-xs tkt_right_menu" id="paging">
				 <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_orders', 'vis_page':this.value})">
					<? 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" id="vis_domain_list">
            <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['TXTORDER']."#"; ?></th>
                     <th><? echo $vis_language['TXTINVOICE']."#"; ?></th>
					 <th class="txt_nowrap"><? echo $vis_language['TXTPRODUCT']; ?></th>
					 <th class="txt_nowrap"><? echo $vis_language['TXTCLIENT']; ?></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['TXTAMOUNT']; ?></th>
					 <th class="txt_nowrap"><? echo $vis_language['TXTPAYMENTSTATUS']; ?></th>
					 <th class="txt_nowrap"><? echo $vis_language['TXTSTATUS']; ?></th>
					 <th></th>
                  </tr>
               </thead>
               <tbody>
				   <?
 							$total=0;
							$paid=0;
							$unpaid=0;
							if($orders!=-1)
							for($i=0;$i<count($orders);$i++) {
							$lableCol = '';
							if($orders[$i]['order_status'] == 2)
							{
								$lableCol = 'vh-danger-bg';
							}
							else if($orders[$i]['order_status'] == 1)
							{
								$lableCol = 'label vh-green-bg';
							}
							else
							{
								$lableCol = 'label label-default';
							}
							echo '<tr><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="'.$orders[$i]['order_id'].'" /><i></i></label></td>' ?>
							<td><a href="javascript:void(0);" style="color:#797d87" class="text-muted" data-toggle="ajaxModal" data-modal-arguments="vis_module=billing&vis_operation=get_update_order&vis_order_id=<? echo $orders[$i]['order_id']; ?>&vis_static_area=vis_order_list_form&vis_page=<? echo $view_info['page']; ?>" ><?php echo $orders[$i]['order_hash']; ?></a></td>
							<? if($orders[$i]['invoice_hash'] == '') {  echo '<td>-</td>';} else{ ?>

							<td style="cursor:pointer;" onclick="$('#vis_workpanel_div').visExecution('load_module','invoices/<?echo $orders[$i]['invoice_id']?>',{'vis_module':'billing','vis_operation':'edit_invoice', 'vis_invoice_id':<?echo $orders[$i]['invoice_id']?>})"><? echo $orders[$i]['invoice_hash'];?></td>
							<? } ?>
							<?php echo '<td>'.$orders[$i]['title'].'</td>'?>
							<td style="cursor:pointer;" onclick="$('#vis_workpanel_div').visExecution('load_module','<?php echo $orders[$i]['first_name'].'/'.$orders[$i]['client_id'];?>',{'vis_module':'client','vis_operation':'client_details', 'client_id':<?echo $orders[$i]['client_id']?>});"><?php echo $orders[$i]['first_name'].' ('.$orders[$i]['email'].')</td>'; ?>
							<? echo '<td>'.(($orders[$i]['expiry']==-1)?'-':format_date($orders[$i]['expiry'])).'</td><td>'.format_date($orders[$i]['entry_date']).'</td>'; ?>
							<?php echo '<td>'.$orders[$i]['amount'].'</td>' ?>
							<? if($orders[$i]['invoice_hash'] == '') { echo '<td>'.$vis_language['TXTNOINVOICE'].'</td>';} else{ echo '<td>'.$invoice_status[$orders[$i]['invoice_status']].'</td>';} ?>

							<?php echo '<td><span class="label '.$lableCol.'">'.$orderStatus[$orders[$i]['order_status']].'</span></td>' ?>
							<td> <a href="javascript:void(0);" title="<? echo $vis_language['TXTDELETE']; ?>" class="text-muted" data-toggle="ajaxModal" data-modal-arguments="vis_module=billing&vis_operation=get_delete_order&vis_order_id=<? echo $orders[$i]['order_id']; ?>&vis_static_area=vis_order_list_form&vis_page=<? echo $view_info['page']; ?>" ><i class="vh vh-delete-round"></a></td>
						<?	echo '</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);" id="del_order1" onclick="delete_order();"><? echo $vis_language['TXTDELETE']; ?></a></li>
				</ul>
			</div>
			</div>
			<? }//else ?>
		  </div>
               <div class="col-sm-3 text-right text-center-xs tkt_right_menu" id="paging">
				 <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_orders', 'vis_page':this.value})">
					<? echo $paging_list;?>
				  </select>
				  <div class="text-muted pull-right label_page"><? echo $vis_language['TXTPAGE']; ?>:</div>
			</div>
            </div>
         </footer>
         </form>
         <? if($operation['vis_order']!=1) {?>
      </section>
</div>
<?
}
}
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,
   		  	null,
   		  	null,
   		    { "bSortable": false }
   		]
   	});
   });
   $('#search_invoice').keyup(function(e){
    if(e.keyCode == 13)
    {
        var search_string = $("#search_invoice").val();
		if(search_string.length < 3)
				$("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['TXTGLOBALSEARCHERROR'];?>");
		else
        $.post("index.php?vis_module=billing&vis_operation=get_invoices&vis_tmpst="+new Date().getTime(), {'vis_invoice_search': search_string }, function(data) {
            $("#search_invoice").parent().addClass('open');
            $('#vis_workpanel_div').show().html(data);
        });
    }
});
	function show_access()
	{
		$("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['MSGACCSSDND'];?>");
		return false;
	}
   function delete_order()
   {
		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_order').attr('data-toggle','ajaxModal');
			$('#del_order').attr('data-modal-arguments','vis_module=billing&vis_operation=get_delete_order&vis_action='+vis_action+'&vis_static_area=vis_order_list_delete_area');
			$('#del_order1').attr('data-toggle','ajaxModal');
			$('#del_order1').attr('data-modal-arguments','vis_module=billing&vis_operation=get_delete_order&vis_action='+vis_action+'&vis_static_area=vis_order_list_delete_area');
		}
		 else
		{
			$("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['MSGLGNTSEL'];?>");
			return false;
		}
	}
</script>
