<? global $vis_language;
   $invoice_status = array( 0 => $vis_language['TXTUNPAID'], 1 => $vis_language['TXTPAID'], 2 => $vis_language['TXTCANCELED'], 3 => $vis_language['TXTINPROCESS'] );
?>
<header class="header b-b b-light bg-w clearfix">
                 <section class="row">
                  <div class="col-md-12">
                  	<h3 class="m-b-xs text-black">#<? echo $invoice_info['invoice_hash']; ?></h3>
                  </div>
                  <!-- .breadcrumb -->
                  <ul class="breadcrumb bg-empty no-border m-b-xxs">
                    <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><a class="link" href="#/billing/get_invoices/"<? echo $vis_language['TXTINVOICES'];?>><? echo $vis_language['TXTINVOICES']; ?></a></li>
                    <li class="active"><? echo $invoice_info['invoice_hash']; ?></li>
                  </ul>
                  <!-- / .breadcrumb -->

                  </section>
            </header>
            <section class="scrollable m-t-lg">
                <div class="row">
                    <div class="wrapper">
                       <div class="col-sm-4">
                         <div class="inline m-l">
                           <div class="h4 m-t m-b-xs font-bold text-lt"><? echo $invoice_info['first_name']." ".$invoice_info['last_name']; ?></div>
                           <div class="text-muted m-b"><? echo $invoice_info['email']; ?></div>
                           <p><span class="text-muted"><? echo $vis_language['TXTINVOICEDATE']; ?>: </span><? echo format_datetime($invoice_info['entry_date']); ?></p>
                           <p><span class="text-muted"><? echo $vis_language['TXTDUEDATE']; ?>: </span><? echo format_datetime($invoice_info['due_date']); ?></p>
                           <p><span class="text-muted"><? echo $vis_language['TXTTOTALDUE']; ?>: </span><? echo $invoice_info['total']; ?></p>
                          </div>
                       </div> <!-- /.col-sm-4 -->
                       <div class="col-sm-8">
                         <div class="col-xs-8">
                           <div class="padder text-center">
                               <h3 class="text-danger"><? echo $invoice_status[$invoice_info['invoice_status']]; ?></h3>
                               <? if($invoice_info['invoice_status'] == 1): ?>
									<p><span class="text-muted"><? echo $vis_language['TXTPAIDDATE']; ?>: </span><? echo format_datetime($invoice_info['paid_date']); ?></p>
							   <? else: ?>
									<p><span class="text-muted"><? echo $vis_language['TXTDUEDATE']; ?>: </span><? echo format_datetime($invoice_info['due_date']); ?></p>
							   <? endif; ?>
                               <div class="btn-group">
                                <div class="dropdown">
                                  <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">
                                    Dropdown
                                    <span class="caret"></span>
                                  </button>
                                  <ul class="dropdown-menu text-left" role="menu" aria-labelledby="dropdownMenu1">
                                    <li><a role="menuitem" tabindex="-1" href="#">Action</a></li>
                                    <li><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
                                    <li><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
                                    <li class="divider"></li>
                                    <li><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
                                  </ul>
                                </div>
                               </div>
                               <div class="btn-group">
                                 <button type="submit" class="btn btn-default btn-success"><? echo $vis_language['TXTSENDEMAIL']; ?></button>
                               </div>

                           </div>
                         </div> <!--/ .col-xs-8 -->
                         <div class="col-xs-4">
                            <div class="pull-right padder-v">

							   <? if($invoice_info['invoice_status']==0) {?>
<!--
			   <li><a class="text-primary" href="javascript:void(0);" data-toggle="ajaxModal" data-modal-arguments="vis_module=billing&vis_operation=add_balance&vis_static_area=vis_domain_delete_form&vis_client_id=<? echo $invoice_info['client_id']; ?>&vis_invoice_id=<? echo $invoice_info['invoice_id']; ?>"><?= $vis_language['TXTADDPAYMENT']; ?></a></li>
               <li><a class="text-primary" href="javascript:void(0);" onclick="$(this).visExecution('load_operations',{'vis_module':'billing', 'vis_operation':'update_invoice_status', 'vis_client_id':<? echo $invoice_info['client_id'];?>, 'vis_invoice_id':<? echo $invoice_info['invoice_id'];?>, 'vis_update_id':2})"><?= $vis_language['TXTMARKCANCEL']; ?></a></li>
-->
				<a href="index.php?vis_module=billing&vis_operation=export_invoice&vis_client_id=<? echo $invoice_info['client_id']; ?>&vis_invoice_id=<? echo $invoice_info['invoice_id']; ?>" class="btn btn-sm btn-block btn-danger" target="blank"><? echo $vis_language['TXTPDF']; ?></a>
				<button type="button" class="btn btn-sm btn-block btn-info" data-toggle="ajaxModal" data-modal-arguments="vis_module=billing&vis_operation=add_balance&vis_static_area=vis_domain_delete_form&vis_client_id=<? echo $invoice_info['client_id']; ?>&vis_invoice_id=<? echo $invoice_info['invoice_id']; ?>" ><?= $vis_language['TXTADDPAYMENT']; ?></button>
				<button type="button" class="btn btn-sm btn-block btn-default" onclick="$(this).visExecution('load_operations',{'vis_module':'billing', 'vis_operation':'update_invoice_status', 'vis_client_id':<? echo $invoice_info['client_id'];?>, 'vis_invoice_id':<? echo $invoice_info['invoice_id'];?>, 'vis_update_id':2})"><?= $vis_language['TXTMARKCANCEL']; ?></button>
               <? } elseif($invoice_info['invoice_status']==1) {?>
<!--
               <li><a class="text-primary" href="javascript:void(0);" onclick="$(this).visExecution('load_operations',{'vis_module':'billing','vis_operation':'update_invoice_status', 'vis_client_id':<? echo $invoice_info['client_id'];?>, 'vis_invoice_id':<? echo $invoice_info['invoice_id'];?>, 'vis_update_id':0})"><?= $vis_language['TXTMARKUNPAID']; ?></a></li>
               <li><a class="text-primary" href="javascript:void(0);" onclick="$(this).visExecution('load_operations',{'vis_module':'billing', 'vis_operation':'update_invoice_status', 'vis_client_id':<? echo $invoice_info['client_id'];?>, 'vis_invoice_id':<? echo $invoice_info['invoice_id'];?>, 'vis_update_id':2})"><?= $vis_language['TXTMARKCANCEL']; ?></a></li>
-->
				<a href="index.php?vis_module=billing&vis_operation=export_invoice&vis_client_id=<? echo $invoice_info['client_id']; ?>&vis_invoice_id=<? echo $invoice_info['invoice_id']; ?>" class="btn btn-sm btn-block btn-danger" target="blank"><? echo $vis_language['TXTPDF']; ?></a>
				<button type="button" class="btn btn-sm btn-block btn-success" onclick="$(this).visExecution('load_operations',{'vis_module':'billing','vis_operation':'update_invoice_status', 'vis_client_id':<? echo $invoice_info['client_id'];?>, 'vis_invoice_id':<? echo $invoice_info['invoice_id'];?>, 'vis_update_id':0})"><?= $vis_language['TXTMARKUNPAID']; ?></button>
				<button type="button" class="btn btn-sm btn-block btn-default" onclick="$(this).visExecution('load_operations',{'vis_module':'billing', 'vis_operation':'update_invoice_status', 'vis_client_id':<? echo $invoice_info['client_id'];?>, 'vis_invoice_id':<? echo $invoice_info['invoice_id'];?>, 'vis_update_id':2})"><?= $vis_language['TXTMARKCANCEL']; ?></button>
               <? } elseif($invoice_info['invoice_status']==2) {?>
<!--
               <li><a class="text-primary" href="javascript:void(0);" onclick="$(this).visExecution('load_operations',{'vis_module':'billing','vis_operation':'update_invoice_status', 'vis_client_id':<? echo $invoice_info['client_id'];?>, 'vis_invoice_id':<? echo $invoice_info['invoice_id'];?>, 'vis_update_id':0})"><?= $vis_language['TXTMARKUNPAID']; ?></a></li>
-->
			   <a href="index.php?vis_module=billing&vis_operation=export_invoice&vis_client_id=<? echo $invoice_info['client_id']; ?>&vis_invoice_id=<? echo $invoice_info['invoice_id']; ?>" class="btn btn-sm btn-block btn-danger" target="blank"><? echo $vis_language['TXTPDF']; ?></a>
			   <button type="button" class="btn btn-sm btn-block btn-success" onclick="$(this).visExecution('load_operations',{'vis_module':'billing','vis_operation':'update_invoice_status', 'vis_client_id':<? echo $invoice_info['client_id'];?>, 'vis_invoice_id':<? echo $invoice_info['invoice_id'];?>, 'vis_update_id':0})"><?= $vis_language['TXTMARKUNPAID']; ?></button>
               <? } ?>


                            </div>
                         </div> <!--/ .col-xs-4 -->
                       </div> <!-- /.col-sm-8 -->
                    </div> <!--/ .wrapper -->
                </div> <!-- /.row -->

            	<div class="row">
                  <div class="wrapper">
                	<div class="col-md-12">
                          <section class="panel m-b-n">
                            <header class="panel-heading">
                              <h5 class="font-bold"><? echo $vis_language['TXTINVOICEITEM'];?></h5>
                            </header>

                            <div class="panel-body bg-white">
                              <div class="row">
                                <div class="table-responsive">
							    <form class="form-horizontal" target="vis_hidden_frame" name="vis_invoice_form" id="vis_invoice_form_<? echo $invoice_info['invoice_id']; ?>" method="post" action="index.php">
                                  <table class="table m-t-n m-b-n b-t b-light">
                                    <thead>
                                      <tr>
                                        <th class="text-center"><? echo $vis_language['TXTDESCRIPTIONS'];?></th>
                                        <th class="text-center"><? echo $vis_language['TXTAMOUNT'];?></th>
                                        <th class="text-center"><? echo $vis_language['TXTTAXED'];?></th>
                                      </tr>
                                    </thead>
										<tbody id="vis_new_invoice_form_area_<?= $invoice_info['invoice_id']; ?>">
										  <input type="hidden" name="vis_ticket_id" value="<? echo $invoice_info['ticket_id']; ?>" />
										  <input type="hidden" name="vis_client_id" value="<? echo $invoice_info['client_id']; ?>" />
										  <input type="hidden" name="vis_desc_count" id="vis_desc_count_<? echo $invoice_info['invoice_id']; ?>" value="1" />
										  <input type="hidden" name="vis_desc_tot_count" id="vis_desc_tot_count_<? echo $invoice_info['invoice_id']; ?>" value="1" />
										  <input type="hidden" name="vis_status" value="<? echo $invoice_info['invoice_status']; ?>" /><?
											 if(isset($invoice_info['invoice_id']) && $invoice_info['invoice_id']!=0) echo '<input type="hidden" name="vis_invoice_id" value="'.$invoice_info['invoice_id'].'" />'; ?>
										  <tr>
											<td><textarea class="form-control" rows="1" data-minwords="6" data-required="true" id="vis_inv"></textarea></td>
											<td width="200"><input type="text" class="form-control" id="vis_amt"></td>
											<td width="40"><div class="checkbox text-center i-checks"><label><input type="checkbox" id="vis_tax" value="1"><i></i></label></div></td>
										  </tr>
										  <? //echo '<script>var n=parseInt($("#vis_desc_count_'.$invoice_info['invoice_id'].'").val());$("#vis_inv").attr("name","vis_invoice+n");$("#vis_amt").attr("name","vis_amount+n");$("#vis_tax").attr("name","vis_taxed+n");$("#vis_desc_count_'.$invoice_info['invoice_id'].'").val(n+1);$("#vis_desc_tot_count_'.$invoice_info['invoice_id'].'").val(n+1);</script>'; ?>
										</tbody>
                                    <tfoot>
                                      <tr>
                                        <td colspan="2">&nbsp;</td>
                                        <td><a href="javascript:void(0)" type="button" class="btn btn-success btn-xs" onclick="add_invoice_area('', 0, '')"><? echo $vis_language['TXTADDITEM'];?></a></td>
                                      </tr>
                                      <tr>
                                        <td class="text-right"><strong><? echo $vis_language['TXTSUBTOTAL'];?></strong></td>
                                        <td class="text-center"><? echo $invoice_info['subtotal']; ?></td>
                                        <td>&nbsp;</td>
                                      </tr>
                                      <tr>
                                        <td class="text-right no-border"><strong><? echo $vis_language['TXTTOTALTAX'];?></strong></td>
                                        <td class="text-center"><? echo $invoice_info['tax']; ?></td>
                                        <td>&nbsp;</td>
                                      </tr>
                                      <tr>
                                        <td class="text-right no-border"><strong><? echo $vis_language['TXTCREDIT'];?></strong></td>
                                        <td class="text-center"><? echo $invoice_info['credit']; ?></td>
                                        <td>&nbsp;</td>
                                      </tr>
                                      <tr>
                                        <td class="text-right no-border"><strong><? echo $vis_language['TXTTOTAL'];?></strong></td>
                                        <td class="text-center"><? echo $invoice_info['total']; ?></td>
                                        <td>&nbsp;</td>
                                      </tr>
                                    </tfoot>
                                  </table>
                                  </form>
                                </div>
                              </div>
                            </div>
                            <footer class="panel-footer text-right bg-light lter">
                                <div class="form-group m-t-xs">
                                  <button type="submit" class="btn btn-default"><? echo $vis_language['TXTCANCEL'];?></button>
                                  <button type="submit" class="btn btn-primary" onclick="$(this).visExecution('submit_form',{'vis_module':'billing', 'vis_operation':'update_invoice', 'vis_form':'vis_invoice_form_<? echo $invoice_info['invoice_id']; ?>','vis_invoice_id':'<? echo $invoice_info['invoice_id'];?>','vis_client_id':'<? echo $invoice_info['client_id'];?>', 'vis_org_operation':($('#ticket_details_view #tabs #ticket_details').length)?'ticket_details':''});"><? echo $vis_language['TXTUPDATE'];?></button>
                                </div>
                            </footer>
                          </section>

                          <section class="panel b-t">
                            <header class="panel-heading">
                              <h5 class="font-bold"><? echo $vis_language['TXTTRANSACTIONS'];?></h5>
                            </header>
                            <div class="panel-body">
                              <div class="row">
                                <div class="table-responsive">
                                  <table class="table m-t-n m-b-n b-t b-light">
                                    <thead>
                                      <tr>
                                        <th><? echo $vis_language['TXTTRANSACTIONID'];?></th>
                                        <th><? echo $vis_language['TXTDESCRIPTION'];?></th>
                                        <th><? echo $vis_language['TXTTRANSACTIONDATE'];?></th>
                                        <th><? echo $vis_language['TXTAMOUNT'];?></th>
                                        <th width="20"></th>
                                      </tr>
                                    </thead>
                                    <tbody>
									<? if(is_array($invoice_details)): ?>
									<? foreach($invoice_details as $invoiceItem): ?>
                                      <tr>
                                        <td>#<? echo $invoice_info['invoice_hash']; ?></td>
                                        <td><? echo $invoiceItem['description'] ?></td>
                                        <td><? echo format_datetime($invoiceItem['entry_date']); ?></td>
                                        <td><? echo $invoiceItem['amount'] ?></td>
                                        <td><a title="Delete transaction" href="javascript:void(0)" data-toggle="ajaxModal" data-modal-arguments="vis_module=billing&vis_operation=get_delete_invoice_transaction&vis_transaction_id=<? echo $invoiceItem['invoice_detail_id'] ?>&vis_invoice_id=<? echo $invoiceItem['invoice_id'];?>&vis_client_id=<? echo $invoice_info['client_id'];?>&vis_static_area=vis_invoice_form" ><i class="vh vh-cross text-danger"></i></a></td>
                                      </tr>
                                    <? endforeach; ?>
                                    <? endif; ?>
                                    </tbody>
                                  </table>
                                  </form>
                                </div>
                              </div>
                            </div>
                          </section>

                    </div>
                  </div>
                </div> <!-- /.row -->

            </section>
<script>
	function add_invoice_area(amount, tax, content)
	{
		var n=parseInt($("#vis_desc_count_<? echo $invoice_info['invoice_id']; ?>").val());
		var temp = '<tr><td><textarea class="form-control" rows="1" data-minwords="6" data-required="true" name="vis_invoice'+n+'"></textarea></td><td width="200"><input type="text" class="form-control" name="vis_amount'+n+'"></td><td width="40"><div class="checkbox text-center i-checks"><label><input type="checkbox" name="vis_taxed'+n+'" value="1"><i></i></label></div></td></tr>';
		$("#vis_new_invoice_form_area_<? echo $invoice_info['invoice_id']; ?>").append(temp);
        $("#vis_desc_count_<? echo $invoice_info['invoice_id']; ?>").val(n+1);
        $("#vis_desc_tot_count_<? echo $invoice_info['invoice_id']; ?>").val(n+1);
	}
	   function add_new_invoice_area(amount, tax, content) {
		var n=parseInt($("#vis_desc_count_<? echo $invoice_info['invoice_id']; ?>").val());
		var tax_check=(tax!=0)?' checked="checked"':'';
		var temp = '<tr style="display:none;"><td><textarea class="form-control" rows="1" data-minwords="6" data-required="true" name="vis_invoice'+n+'">'+(content.replace(/<br>/g, "\n"))+'</textarea></td><td width="200"><input type="text" class="form-control" name="vis_amount'+n+'" value='+amount+'></td><td width="40"><div class="checkbox text-center i-checks"><label><input type="checkbox" name="vis_taxed'+n+'" value='+tax+' '+tax_check+'><i></i></label></div></td></tr>';
		$("#vis_new_invoice_form_area_<? echo $invoice_info['invoice_id']; ?>").append(temp);
        $("#vis_desc_count_<? echo $invoice_info['invoice_id']; ?>").val(n+1);
        $("#vis_desc_tot_count_<? echo $invoice_info['invoice_id']; ?>").val(n+1);
		} <?
      for($i=0;$i<$invoice_info['count'];$i++) { ?>
       add_new_invoice_area("<? echo $invoice_details[$i]['amount']; ?>", "<? echo $invoice_details[$i]['tax']; ?>", "<? echo str_replace(array("\n", "\r"), array('<br>', ''), addslashes($invoice_details[$i]['description'])); ?>"); <?
      }
      ?>
   function close_invoice(n)
   {
   $('#vis_invoice_subitem_'+n).remove();
   if($("#vis_desc_tot_count_<? echo $invoice_info['invoice_id']; ?>").val()>1)
   {
   num=$("#vis_desc_tot_count_<? echo $invoice_info['invoice_id']; ?>").val()-1;
   $("#vis_desc_tot_count_<? echo $invoice_info['invoice_id']; ?>").val(num);
   }
   }
   var n=parseInt($("#vis_desc_count_<? echo $invoice_info['invoice_id']; ?>").val());
   $("#vis_inv").attr("name","vis_invoice"+n);
   $("#vis_amt").attr("name","vis_amount"+n);
   $("#vis_tax").attr("name","vis_taxed"+n);
$("#vis_desc_count_<? echo $invoice_info['invoice_id']; ?>").val(n+1);
        $("#vis_desc_tot_count_<? echo $invoice_info['invoice_id']; ?>").val(n+1);
</script>