<html>
<head>
  <title><?php echo $menu_label ?></title>
  <link rel="stylesheet" type="text/css" href="<?php echo base_url()?>assets/custom/css/print_new.css">
</head>
<style type="text/css">
  @media print {
    .noPrint { display: none; }
  }
</style>
<body>
  <div class="easyui-layout" data-options="fit:true,border:false">
      <!-- Top view-->
      <div id="form-header" data-options="region:'north',border:false">
          <div id="form-header-wrapper">
              <table cellpadding="0" cellspacing="0" width="100%">
              <tr>
                  <td align="left" valign="middle">
                      <a href="#" class="easyui-linkbutton noPrint" data-options="plain:true,iconCls:'icon-print'" onClick="print_detail()" <?= in_array($detail->TransStatus,array(1,2,3,9))? "":"disabled" ?>>Print</a>
                      <a href="#" class="easyui-linkbutton noPrint" data-options="plain:true,iconCls:'icon-excel'" onClick="modal_open('Import New Account','dlg_importfile');" >Export File</a>
                    <input type="checkbox" name="c_sono" id="so_no" value="so_no" onClick="ShowHide(this.value)" checked="true">SO No <input type="checkbox" name="c_sodate" id="so_date" value="so_date" onClick="ShowHide(this.value)" checked="true">SO Date
                    <!-- <input type="checkbox" name="c_sqno" id="sq_no" value="sq_no" onclick="ShowHide(this.value)">SQ No <input type="checkbox" name="c_sqdate" id="sq_date" value="sq_date" onclick="ShowHide(this.value)">SQ Date -->
                    <input type="checkbox" name="c_custpo" id="cust_po" value="cust_po" onClick="ShowHide(this.value)" checked="true">C.PO No <input type="checkbox" name="c_custpodate" id="cust_podate" value="cust_podate" onClick="ShowHide(this.value)" checked="true">C.PO Date
                    <input type="checkbox" name="c_fbo" id="fob" value="fob" onClick="ShowHide(this.value)" checked="true">FOB <input type="checkbox" name="c_terms" id="terms" value="terms" onClick="ShowHide(this.value)" checked="true">Terms
                    <input type="checkbox" name="c_shipvia" id="ship_via" value="ship_via" onClick="ShowHide(this.value)" checked="true">Ship Via
                  </td>             
              </tr>
              </table>  
          </div>      
      </div>
      <br><br>
      <!-- Header -->
      <div id="print-container">
        <?php
          $CountList = count($list); // Count total item
          if($CountList <=12):
            $MaxList = 12;
            
        ?>
      <!-- Start Item <=8 -->
      <table class="header">
        <tr>
             <td colspan="2" class="bdr-left bdr-right bdr-top bdr-bottom head-left">
              <span class="small_bold span_block" ><?php echo $detail->CustomerName;?></span>
                  <span class="small_bold span_block" > <?php echo preg_replace( "/\r|\n/", "", $detail->CustomerAddress ); ?> - &nbsp;&nbsp; <?php echo $detail->PhoneNumber;?></span>
            </td>
            <td colspan="2" class="bdr-right bdr-top bdr-bottom head-right">
              <h2>SALES INVOICE</h2>
            </td>
        </tr>
        <tr>
            <td class="bdr-left bdr-right bdr-bottom head-left-bottom-1">
            	<span class="small_bold span_block" >Billing Address : </span>
	            
	            <span class="small_bold span_block" ><?php echo preg_replace( "/\r|\n/", "", $detail->BillingAddress ); ?></span>
               
            </td>
            <td class="bdr-right bdr-bottom head-left-bottom-2">
                   <span class="small_bold span_block" >Shipping To :</span>
	               
	               <span class="small_bold span_block" ><?php echo preg_replace( "/\r|\n/", "", $detail->ShippingAddress ); ?></span>
            </td>
            <td class="bdr-right bdr-bottom head-right-bottom">
              <p><label class="lbl-a" >SInv No</label><label class="lbl-b">:</label><label class="lbl-c"><?php echo $detail->SInvNumber;?></label></p>
              <p><label class="lbl-a" >CPO </label><label class="lbl-b">:</label><label class="lbl-c"><?php echo $detail->CustPONumber;?></label></p>
              <p><label class="lbl-a" >FOB </label><label class="lbl-b">:</label><label class="lbl-c"><?php echo $detail->FOB;?></label></p>
              <p><label class="lbl-a" >Ship Via </label><label class="lbl-b">:</label><label class="lbl-c"><?php echo $detail->ShipmentName;?></label></p>
              <p><label class="lbl-a" >Fsc. Rate </label><label class="lbl-b">:</label><label class="lbl-c"><?=($detail->CurrencyCode=='IDR')?'1,00':number_format($detail->FiscalRate,"2",",",".");?></label></p>
            </td>
            <td class="bdr-right bdr-bottom head-right-bottom" valign="top">
              <p><label class="lbl-a" >SInv Date</label><label class="lbl-b">:</label><label class="lbl-cbon"><?php echo date("d-m-Y", strtotime($detail->SInvDate));?></label></p>
              <p><label class="lbl-a" >Terms </label><label class="lbl-b">:</label><label class="lbl-cbon"><?php echo $detail->TermDesc;?> Day</label></p>
              <p><label class="lbl-a" >Ship Date</label><label class="lbl-b">:</label><label class="lbl-cbon"><?php echo date("d-m-Y", strtotime($detail->ShipDate));?></label></p>
              <p><label class="lbl-a" >Currency </label><label class="lbl-b">:</label><label class="lbl-cbon"><?php echo $detail->CurrencyCode;?></label></p>
              <p><label class="lbl-a" >Rate </label><label class="lbl-b">:</label><label class="lbl-cbon"><?=($detail->CurrencyCode=='IDR')?'1,00':number_format($detail->CurrencyRate,"2",",",".");?></label></p>
            </td>
        </tr>
      </table>
      
      
      <!-- Detail Item -->
      <table class="content">
      	<tr class="content-top">
          <th class="bdr-left bdr-right bdr-top bdr-bottom list-number"><span class="normal_bold">DOrd No</span></th>
          <th class="bdr-top bdr-bottom list-number bdr-right"><span class="normal_bold">Item</span></th>
          <th class="bdr-right bdr-top bdr-bottom list-name"><span class="normal_bold">Description</span></th>
          <th class="bdr-right bdr-top bdr-bottom list-desc" ><span class="normal_bold">Qty</span></th>
          <th class="bdr-right bdr-top bdr-bottom list-qty text-center" ><span class="normal_bold">Unit</span></th>
          <th class="bdr-right bdr-top bdr-bottom list-number"><span class="normal_bold">Price</span></th>
          <th class="bdr-right bdr-top bdr-bottom list-desc"><span class="normal_bold">Disc %</span></th>
          <th  class="bdr-left bdr-right bdr-top bdr-bottom list-desc"><span class="normal_bold">Amount</span></th>
          
        </tr>
        <?php for($x = 0; $x < $CountList; $x++):?>
        <tr class="content-middle">
          <td  class="text-left bdr-left" ><span class="small_bold txt_do_number"><?php echo $detail->DOrdNumber; ?></span></td>
          <td  class="text-left" ><span class="small_bold txt_item_code" id="txt_item_code_<?=$x;?>" onClick="open_master_item('<?=$list[$x]['ItemCode'];?>','<?php echo $list[$x]['ItemType']; ?>')"><?php echo $list[$x]['ItemCode']; ?></span></td>
          <td  class="text-left" ><span class="small_bold"><?php echo substr($list[$x]['ItemDesc'],0,30); ?></span></td>
          <td  class="text-center"><span class="small_bold"><?php echo number_format($list[$x]['ItemQty'],"2",",","."); ?></span></td>
          <td  class="text-center" ><span class="small_bold"><?php echo $list[$x]['ItemUnit']; ?></span></td>
          <td  class="text-right text-top" soClass="<?=$x;?>" onMouseOver="open_sotrans(event)"><span class="small_bold SOTrans easyui-tooltip"><?php echo number_format($list[$x]['ItemPrice'],"2",",","."); ?></span><span style="display:none" class="so_trans_<?=$x;?>"><?= $detail->SOrdNumber;?></span></td>
          <td  class="text-center" ><span class="small_bold"><?php echo number_format($list[$x]['ItemDiscPcnt'],"2",",","."); ?></span></td>
          <td  class="item_no_border bdr-right text-right" ><span class="small_bold"><?php echo number_format($list[$x]['ItemAmount'],"2",",","."); ?></span></td>
        </tr>
        
        <?php endfor; ?>
          <?php

          // Count Last Item
          if($CountList < $MaxList):

            $ListDiff   = $MaxList - $CountList; // Variabel Count Last Item

            for($xi = 0; $xi < $ListDiff; $xi++):
          ?>
        <tr class="content-middle no-item">
            <td  class="bdr-left" ><span class="small_bold">&nbsp;</span></td>
            <td  class="" ><span class="small_bold">&nbsp;</span></td>
            <td  class="" ><span class="small_bold">&nbsp;</span></td>
            <td  class="" ><span class="small_bold">&nbsp;</span></td>
            <td  class="" ><span class="small_bold">&nbsp;</span></td>
            <td  class="" ><span class="small_bold">&nbsp;</span></td>
            <td  class="" ><span class="small_bold">&nbsp;</span></td>
            <td  class="bdr-right" ><span class="small_bold">&nbsp;</span></td>
        </tr>
        <?php endfor;?>
        <?php endif;?>
        <!-- Description -->
        <tr class="content-bottom">
          <td colspan="5" class="bdr-left bdr-right bdr-top bdr-bottom description-so" valign="top">
              <span class="normal_bold">Description :</span>
              <?php if($detail->SInvDesc != ""):?>
              <span class="small_bold span_block">
              <?php echo preg_replace( "/\r|\n/", "", character_limiter($detail->SInvDesc, 225) ); ?>
              </span>
              <?php else:?>
              <span class="normal_bold span_block">&nbsp;</span>
              <?php endif;?>
          </td>
          <td class="bdr-right bdr-top bdr-bottom content-bottom-amount" colspan="3">
              <table>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">SubTotal </span></td>
                    <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value"> <span class="small_bold"> <?php echo number_format($detail->SInvSubTotal,"2",",","."); ?></span></td>
                </tr>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">Discount </span></td>
                     <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value"> <span class="small_bold"><?php echo number_format($detail->SInvDiscount,"2",",","."); ?></span></td>
                </tr>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">PPN (10%)</span></td>
                     <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value"> <span class="small_bold"> <?php echo number_format($detail->SInvPPNOut,"2",",","."); ?></span></td>
                </tr>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">PPh 23 (<?php echo $detail->SOrdPPh23Pcnt;?>% ) </span></td>
                     <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value"> <span class="small_bold"> <?php echo number_format($detail->SInvPPH23,"2",",","."); ?></span></td>
                </tr>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">Down Payment</span></td>
                     <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value"> <span class="small_bold"><?php echo number_format($detail->SRecTotalDP,"2",",","."); ?></span></td>
                </tr>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">Total Amount</span></td>
                     <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value">
                      <span class="small_bold"> 
                      <?php
                        //$total_amount = ($detail->SOrdSubTotal + $detail->SOrdTaxes) - $detail->SOrdTotalDP;
                        echo number_format($detail->SInvTotalAmount,"2",",",".");
                      ?>
                      </span>
                    </td>
                </tr>
              </table>
          </td>
        </tr>             
      </table>
      <!-- Footer Form -->
      
      <div class="footer">
          <div class="footer-top">
              <div class="footer-paraf-div">
                  <div class="footer-paraf-by normal_bold">Elektronik Prepared By</div>
                  <?php if($detail->nm_prepared !=""):?>
                  <span class="text-underline text-center footer-paraf-name"><?php echo $detail->nm_prepared;?></span>
                      <?php else:?>
                  <span class="normal_bold span_block footer-paraf-name">____________</span>
                  <?php endif;?>
              </div>       
              <div class="footer-paraf-div">
                  <div class="footer-paraf-by normal_bold">Elektronik Approved By</div>
                  <?php if($detail->nm_manager  !=""):?>
                  <span class="text-underline text-center footer-paraf-name"><?php echo $detail->nm_manager;?></span>
                      <?php else:?>
                  <span class="text-underline normal_bold span_block footer-paraf-name">____________</span>
                  <?php endif;?>
              </div>    
              <div class="footer-paraf-div">
                  <div class="footer-paraf-by normal_bold">Elektronik Customer By</div>
                  <?php if($detail->CustomerName  !=""):?>
                  <span class="text-underline text-center footer-paraf-name"><?php echo $detail->CustomerName;?></span>
                      <?php else:?>
                  <span class="text-underline normal_bold span_block footer-paraf-name">____________</span>
                  <?php endif;?>
              </div>    
              <?php if(($detail->TransStatus == 3) or ($detail->TransStatus == 9)){?>
                  <div class="footer-status"><h4 id="title-form" class="suspended">DOKUMEN TIDAK BERLAKU</h4></div>     
              <?php }?>
              <div class='clear-float'></div>
          </div>

          <div class="footer-bottom">
              <div class="footer-bottom-company">
                  <?php echo $this->load->model('file/m_new_company')->get_company_name($this->session->userdata('company')); ?> - <?php echo $detail->BranchName; ?>
                  <div class="footer-bottom-page">Page : 1 Of 1</div>
              </div>
              <div class='clear-float'></div>
          </div>
      </div>
      

      <?php else:?>
      <?php
        $MaxList = 45;
        if($CountList <= $MaxList):
      ?>
      <!-- Item > 8 and item <=34 -->
      <!-- Start Item <=34 -->
        <table class="header">
        <tr>
             <td colspan="2" class="bdr-left bdr-right bdr-top bdr-bottom head-left">
              <span class="small_bold span_block" ><?php echo $detail->CustomerName;?></span>
                  <span class="small_bold span_block" > <?php echo preg_replace( "/\r|\n/", "", $detail->CustomerAddress ); ?> - &nbsp;&nbsp; <?php echo $detail->PhoneNumber;?></span>
            </td>
            <td colspan="2" class="bdr-right bdr-top bdr-bottom head-right">
              <h2>SALES INVOICE</h2>
            </td>
        </tr>
        <tr>
            <td class="bdr-left bdr-right bdr-bottom head-left-bottom-1">
            	<span class="small_bold span_block" >Billing Address : </span>
	            
	            <span class="small_bold span_block" ><?php echo preg_replace( "/\r|\n/", "", $detail->BillingAddress ); ?></span>
               
            </td>
            <td class="bdr-right bdr-bottom head-left-bottom-2">
                   <span class="small_bold span_block" >Shipping To :</span>
	               
	               <span class="small_bold span_block" ><?php echo preg_replace( "/\r|\n/", "", $detail->ShippingAddress ); ?></span>
            </td>
             <td class="bdr-right bdr-bottom head-right-bottom">
              <p><label class="lbl-a" >SInv No</label><label class="lbl-b">:</label><label class="lbl-c"><?php echo $detail->SInvNumber;?></label></p>
              <p><label class="lbl-a" >CPO </label><label class="lbl-b">:</label><label class="lbl-c"><?php echo date("d-m-Y", strtotime($detail->CustPONumber));?></label></p>
              <p><label class="lbl-a" >FOB </label><label class="lbl-b">:</label><label class="lbl-c"><?php echo $detail->FOB;?></label></p>
              <p><label class="lbl-a" >Ship Via </label><label class="lbl-b">:</label><label class="lbl-c"><?php echo $detail->ShipmentName;?></label></p>
              <p><label class="lbl-a" >Fsc. Rate </label><label class="lbl-b">:</label><label class="lbl-c"><?=($detail->CurrencyCode=='IDR')?'1,00':number_format($detail->FiscalRate,"2",",",".");?></label></p>
            </td>
            <td class="bdr-right bdr-bottom head-right-bottom" valign="top">
              <p><label class="lbl-a" >SInv Date</label><label class="lbl-b">:</label><label class="lbl-cbon"><?php echo date("d-m-Y", strtotime($detail->SInvDate));?></label></p>
              <p><label class="lbl-a" >Terms </label><label class="lbl-b">:</label><label class="lbl-cbon"><?php echo $detail->TermDesc;?> Day</label></p>
              <p><label class="lbl-a" >Ship Date</label><label class="lbl-b">:</label><label class="lbl-cbon"><?php echo date("d-m-Y", strtotime($detail->ShipDate));?></label></p>
              <p><label class="lbl-a" >Currency </label><label class="lbl-b">:</label><label class="lbl-cbon"><?php echo $detail->CurrencyCode;?></label></p>
              <p><label class="lbl-a" >Rate </label><label class="lbl-b">:</label><label class="lbl-cbon"><?=($detail->CurrencyCode=='IDR')?'1,00':number_format($detail->CurrencyRate,"2",",",".");?></label></p>
            </td>
        </tr>
      </table>
      
      
      <!-- Detail Item -->
      <table class="content">
      	<tr class="content-top">
          <th class="bdr-left bdr-right bdr-top bdr-bottom list-number"><span class="normal_bold">Item</span></th>
          <th class="bdr-right bdr-top bdr-bottom list-name"><span class="normal_bold">Description</span></th>
          <th class="bdr-right bdr-top bdr-bottom list-desc" ><span class="normal_bold">Qty</span></th>
          <th class="bdr-right bdr-top bdr-bottom list-qty text-center" ><span class="normal_bold">Unit</span></th>
          <th class="bdr-right bdr-top bdr-bottom list-number"><span class="normal_bold">Price</span></th>
          <th class="bdr-right bdr-top bdr-bottom list-desc"><span class="normal_bold">Disc %</span></th>
          <th  class="bdr-left bdr-right bdr-top bdr-bottom list-desc"><span class="normal_bold">Amount</span></th>
          
        </tr>
        <?php for($x = 0; $x < $CountList; $x++):?>
        <tr class="content-middle">
          <td  class="text-left bdr-left" ><span class="small_bold txt_item_code" id="txt_item_code_<?=$x;?>" onClick="open_master_item('<?=$list[$x]['ItemCode'];?>','<?php echo $list[$x]['ItemType']; ?>')"><?php echo $list[$x]['ItemCode']; ?></span></td>
          <td  class="text-left" ><span class="small_bold"><?php echo $list[$x]['ItemDesc']; ?></span></td>
          <td  class="text-center"><span class="small_bold"><?php echo number_format($list[$x]['ItemQty'],"2",",","."); ?></span></td>
          <td  class="text-center" ><span class="small_bold"><?php echo $list[$x]['ItemUnit']; ?></span></td>
          <td  class="text-left" ><span class="small_bold"><?php echo number_format($list[$x]['ItemPrice'],"2",",","."); ?></span></td>
          <td  class="text-center" ><span class="small_bold"><?php echo number_format($list[$x]['ItemDiscPcnt'],"2",",","."); ?></span></td>
          <td  class="item_no_border bdr-right text-right" ><span class="small_bold"><?php echo number_format($list[$x]['ItemAmount'],"2",",","."); ?></span></td>
         
        </tr>
        <?php endfor; ?>
          <?php

          // Count Last Item
          if($CountList < $MaxList):

            $ListDiff   = $MaxList - $CountList; // Variabel Count Last Item

            for($xi = 0; $xi < $ListDiff; $xi++):
          ?>
        <tr class="content-middle no-item">
            <td  class="bdr-left" ><span class="small_bold">&nbsp;</span></td>
            <td  class="" ><span class="small_bold">&nbsp;</span></td>
            <td  class="" ><span class="small_bold">&nbsp;</span></td>
            <td  class="" ><span class="small_bold">&nbsp;</span></td>
            <td  class="" ><span class="small_bold">&nbsp;</span></td>
            <td  class="" ><span class="small_bold">&nbsp;</span></td>
            <td  class="bdr-right" ><span class="small_bold">&nbsp;</span></td>
        </tr>
        <?php endfor;?>
        <?php endif;?>
        <!-- Description -->
        <tr class="content-bottom">
         <td colspan="4" class="bdr-left bdr-right bdr-top bdr-bottom description-so" valign="top">
              <span class="normal_bold">Description :</span>
              <?php if($detail->SInvDesc != ""):?>
              <span class="small_bold span_block">
              <?php echo preg_replace( "/\r|\n/", "", substr($detail->SInvDesc,0, 225) ); ?>
              </span>
              <?php else:?>
              <span class="normal_bold span_block">&nbsp;</span>
              <?php endif;?>
          </td>
          <td class="bdr-right bdr-top bdr-bottom content-bottom-amount" colspan="3">
              <table>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">SubTotal </span></td>
                    <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value"> <span class="small_bold"> <?php echo number_format($detail->SInvSubTotal,"2",",","."); ?></span></td>
                </tr>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">Discount </span></td>
                     <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value"> <span class="small_bold"><?php echo number_format($detail->SInvDiscount,"2",",","."); ?></span></td>
                </tr>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">PPN (10%)</span></td>
                     <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value"> <span class="small_bold"> <?php echo number_format($detail->SInvPPNOut,"2",",","."); ?></span></td>
                </tr>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">PPh 23 (<?php echo $detail->SOrdPPh23Pcnt;?>% ) </span></td>
                     <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value"> <span class="small_bold"> <?php echo number_format($detail->SInvPPH23,"2",",","."); ?></span></td>
                </tr>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">Down Payment</span></td>
                     <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value"> <span class="small_bold"><?php echo number_format($detail->SRecTotalDP,"2",",","."); ?></span></td>
                </tr>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">Total Amount</span></td>
                     <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value">
                      <span class="small_bold"> 
                      <?php
                        //$total_amount = ($detail->SOrdSubTotal + $detail->SOrdTaxes) - $detail->SOrdTotalDP;
                        echo number_format($detail->SInvTotalAmount,"2",",",".");
                      ?>
                      </span>
                    </td>
                </tr>
              </table>
          </td>
        </tr>  
      </table>
      <!-- Footer Form -->
      <div class="footer">
          <div class="footer-top">
              <div class="footer-paraf-div">
                  <div class="footer-paraf-by normal_bold">Elektronik Prepared By</div>
                  <?php if($detail->nm_prepared !=""):?>
                  <span class="text-underline text-center footer-paraf-name"><?php echo $detail->nm_prepared;?></span>
                      <?php else:?>
                  <span class="normal_bold span_block footer-paraf-name">____________</span>
                  <?php endif;?>
              </div>       
              <div class="footer-paraf-div">
                  <div class="footer-paraf-by normal_bold">Elektronik Approved By</div>
                  <?php if($detail->nm_manager  !=""):?>
                  <span class="text-underline text-center footer-paraf-name"><?php echo $detail->nm_manager;?></span>
                      <?php else:?>
                  <span class="text-underline normal_bold span_block footer-paraf-name">____________</span>
                  <?php endif;?>
              </div>    
              <div class="footer-paraf-div">
                  <div class="footer-paraf-by normal_bold">Elektronik Customer By</div>
                  <?php if($detail->CustomerName  !=""):?>
                  <span class="text-underline text-center footer-paraf-name"><?php echo $detail->CustomerName;?></span>
                      <?php else:?>
                  <span class="text-underline normal_bold span_block footer-paraf-name">____________</span>
                  <?php endif;?>
              </div>    
              <?php if(($detail->TransStatus == 3) or ($detail->TransStatus == 9)){?>
                  <div class="footer-status"><h4 id="title-form" class="suspended">DOKUMEN TIDAK BERLAKU</h4></div>     
              <?php }?>
              <div class='clear-float'></div>
          </div>

          <div class="footer-bottom">
              <div class="footer-bottom-company">
                  <?php echo $this->load->model('file/m_new_company')->get_company_name($this->session->userdata('company')); ?> - <?php echo $detail->BranchName; ?>
                  <div class="footer-bottom-page">Page : 1 Of 1</div>
              </div>
              <div class='clear-float'></div>
          </div>
      </div>
      <?php else:?>
      <!-- Item > 8 and Item > 25 -->
      <?php 

        $paper_count  = ceil($CountList / $MaxList); // Page AMount
        $ListTo     = array(0,0); // Array to get index Item

        for($i = 0; $i < $paper_count; $i++): // Loop Until Last Form

          $ListTo[0] = $i * $MaxList; // Index Item From
          $ListTo[1] = ($i * $MaxList) + 40; // Index Item To

          if($ListTo[1] == $CountList){ // If Index Item To == Item AMount

            $ListTo[1] = $CountList - 40;

          }elseif($ListTo[1] > $CountList){ // If Index More Than Item AMount

            $ListTo[1] = ($CountList - (($i-1) * $MaxList))-1;

          }
      ?>

      <!-- Header Form -->
     <table class="header">
        <tr>
             <td colspan="2" class="bdr-left bdr-right bdr-top bdr-bottom head-left">
              <span class="small_bold span_block" ><?php echo $detail->CustomerName;?></span>
                  <span class="small_bold span_block" > <?php echo preg_replace( "/\r|\n/", "", $detail->CustomerAddress ); ?> - &nbsp;&nbsp; <?php echo $detail->PhoneNumber;?></span>
            </td>
            <td colspan="2" class="bdr-right bdr-top bdr-bottom head-right">
              <h2>SALES INVOICE</h2>
            </td>
        </tr>
        <tr>
            <td class="bdr-left bdr-right bdr-bottom head-left-bottom-1">
            	<span class="small_bold span_block" >Billing Address : </span>
	            
	            <span class="small_bold span_block" ><?php echo preg_replace( "/\r|\n/", "", $detail->BillingAddress ); ?></span>
               
            </td>
            <td class="bdr-right bdr-bottom head-left-bottom-2">
                   <span class="small_bold span_block" >Shipping To :</span>
	               
	               <span class="small_bold span_block" ><?php echo preg_replace( "/\r|\n/", "", $detail->ShippingAddress ); ?></span>
            </td>
             <td class="bdr-right bdr-bottom head-right-bottom">
              <p><label class="lbl-a" >SInv No</label><label class="lbl-b">:</label><label class="lbl-c"><?php echo $detail->SInvNumber;?></label></p>
              <p><label class="lbl-a" >CPO </label><label class="lbl-b">:</label><label class="lbl-c"><?php echo date("d-m-Y", strtotime($detail->CustPONumber));?></label></p>
              <p><label class="lbl-a" >FOB </label><label class="lbl-b">:</label><label class="lbl-c"><?php echo $detail->FOB;?></label></p>
              <p><label class="lbl-a" >Ship Via </label><label class="lbl-b">:</label><label class="lbl-c"><?php echo $detail->ShipmentName;?></label></p>
              <p><label class="lbl-a" >Fsc. Rate </label><label class="lbl-b">:</label><label class="lbl-c"><?=($detail->CurrencyCode=='IDR')?'1,00':number_format($detail->FiscalRate,"2",",",".");?></label></p>
            </td>
            <td class="bdr-right bdr-bottom head-right-bottom" valign="top">
              <p><label class="lbl-a" >SInv Date</label><label class="lbl-b">:</label><label class="lbl-cbon"><?php echo date("d-m-Y", strtotime($detail->SInvDate));?></label></p>
              <p><label class="lbl-a" >Terms </label><label class="lbl-b">:</label><label class="lbl-cbon"><?php echo $detail->TermDesc;?> Day</label></p>
              <p><label class="lbl-a" >Ship Date</label><label class="lbl-b">:</label><label class="lbl-cbon"><?php echo date("d-m-Y", strtotime($detail->ShipDate));?></label></p>
              <p><label class="lbl-a" >Currency </label><label class="lbl-b">:</label><label class="lbl-cbon"><?php echo $detail->CurrencyCode;?></label></p>
              <p><label class="lbl-a" >Rate </label><label class="lbl-b">:</label><label class="lbl-cbon"><?=($detail->CurrencyCode=='IDR')?'1,00':number_format($detail->CurrencyRate,"2",",",".");?></label></p>
            </td>
        </tr>
      </table>
      <!-- Detail Item -->
      <table class="content">
        <tr class="content-top">
          <th class="bdr-left bdr-right bdr-top bdr-bottom list-number"><span class="normal_bold">Item</span></th>
          <th class="bdr-right bdr-top bdr-bottom list-name"><span class="normal_bold">Description</span></th>
          <th class="bdr-right bdr-top bdr-bottom list-desc" ><span class="normal_bold">Qty</span></th>
          <th class="bdr-right bdr-top bdr-bottom list-qty text-center" ><span class="normal_bold">Unit</span></th>
          <th class="bdr-right bdr-top bdr-bottom list-number"><span class="normal_bold">Price</span></th>
          <th class="bdr-right bdr-top bdr-bottom list-desc"><span class="normal_bold">Disc %</span></th>
          <th  class="bdr-left bdr-right bdr-top bdr-bottom list-desc"><span class="normal_bold">Amount</span></th>
          
        </tr>
        <?php for($x = $ListTo[0]; $x <= $ListTo[1]; $x++):?>
      <tr class="content-middle">
          <td  class="text-left bdr-left" ><span class="small_bold txt_item_code" id="txt_item_code_<?=$x;?>" onClick="open_master_item('<?=$list[$x]['ItemCode'];?>','<?php echo $list[$x]['ItemType']; ?>')"><?php echo $list[$x]['ItemCode']; ?></span></td>
          <td  class="text-left" ><span class="small_bold"><?php echo $list[$x]['ItemDesc']; ?></span></td>
          <td  class="text-center"><span class="small_bold"><?php echo number_format($list[$x]['ItemQty'],"2",",","."); ?></span></td>
          <td  class="text-center" ><span class="small_bold"><?php echo $list[$x]['ItemUnit']; ?></span></td>
          <td  class="text-left" ><span class="small_bold"><?php echo number_format($list[$x]['ItemPrice'],"2",",","."); ?></span></td>
          <td  class="text-center" ><span class="small_bold"><?php echo number_format($list[$x]['ItemDiscPcnt'],"2",",","."); ?></span></td>
          <td  class="item_no_border bdr-right text-right" ><span class="small_bold"><?php echo number_format($list[$x]['ItemAmount'],"2",",","."); ?></span></td>
         
        </tr>
        <?php endfor; ?>
        <?php
        // Count Last Item
        if(($i+1) == $paper_count):
          $ListDiff = $MaxList - ($CountList - $ListTo[0]);
          for($xi = 0; $xi < $ListDiff; $xi++):
        ?>
      	<tr class="content-middle no-item">
         <tr>
            <td  class="bdr-left" ><span class="small_bold">&nbsp;</span></td>
            <td  class="" ><span class="small_bold">&nbsp;</span></td>
            <td  class="" ><span class="small_bold">&nbsp;</span></td>
            <td  class="" ><span class="small_bold">&nbsp;</span></td>
            <td  class="" ><span class="small_bold">&nbsp;</span></td>
            <td  class="" ><span class="small_bold">&nbsp;</span></td>
            <td  class="bdr-right" ><span class="small_bold">&nbsp;</span></td>
        </tr>
        <?php endfor;?>
        <?php endif;?>
        <!-- Description -->
       <tr class="content-bottom">
         <td colspan="4" class="bdr-left bdr-right bdr-top bdr-bottom description-so" valign="top">
              <span class="normal_bold">Description :</span>
              <?php if($detail->SInvDesc != ""):?>
              <span class="small_bold span_block">
              <?php echo preg_replace( "/\r|\n/", "", character_limiter($detail->SInvDesc, 225) ); ?>
              </span>
              <?php else:?>
              <span class="normal_bold span_block">&nbsp;</span>
              <?php endif;?>
          </td>
          <td class="bdr-right bdr-top bdr-bottom content-bottom-amount" colspan="3">
              <table>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">SubTotal </span></td>
                    <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value"> <span class="small_bold"> <?php echo number_format($detail->SInvSubTotal,"2",",","."); ?></span></td>
                </tr>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">Discount </span></td>
                     <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value"> <span class="small_bold"><?php echo number_format($detail->SInvDiscount,"2",",","."); ?></span></td>
                </tr>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">PPN (10%)</span></td>
                     <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value"> <span class="small_bold"> <?php echo number_format($detail->SInvPPNOut,"2",",","."); ?></span></td>
                </tr>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">PPh 23 (<?php echo $detail->SOrdPPh23Pcnt;?>% ) </span></td>
                     <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value"> <span class="small_bold"> <?php echo number_format($detail->SInvPPH23,"2",",","."); ?></span></td>
                </tr>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">Down Payment</span></td>
                     <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value"> <span class="small_bold"><?php echo number_format($detail->SRecTotalDP,"2",",","."); ?></span></td>
                </tr>
                <tr>
                    <td class=" content-bottom-amount-label"> <span class="small_bold">Total Amount</span></td>
                     <td class=" "> <span class="small_bold"> : </span></td>
                    <td class=" content-bottom-amount-value">
                      <span class="small_bold"> 
                      <?php
                        //$total_amount = ($detail->SOrdSubTotal + $detail->SOrdTaxes) - $detail->SOrdTotalDP;
                        echo number_format($detail->SInvTotalAmount,"2",",",".");
                      ?>
                      </span>
                    </td>
                </tr>
              </table>
          </td>
        </tr>        
      </table>
      <!-- Footer Form -->
      <div class="margin-page">
          <div class="footer-top">
              <div class="footer-paraf-div">
                  <div class="footer-paraf-by normal_bold">Elektronik Prepared By</div>
                  <?php if($detail->nm_prepared !=""):?>
                  <span class="text-underline text-center footer-paraf-name"><?php echo $detail->nm_prepared;?></span>
                      <?php else:?>
                  <span class="normal_bold span_block footer-paraf-name">____________</span>
                  <?php endif;?>
              </div>       
              <div class="footer-paraf-div">
                  <div class="footer-paraf-by normal_bold">Elektronik Approved By</div>
                  <?php if($detail->nm_manager  !=""):?>
                  <span class="text-underline text-center footer-paraf-name"><?php echo $detail->nm_manager;?></span>
                      <?php else:?>
                  <span class="text-underline normal_bold span_block footer-paraf-name">____________</span>
                  <?php endif;?>
              </div>    
              <div class="footer-paraf-div">
                  <div class="footer-paraf-by normal_bold">Elektronik Customer By</div>
                  <?php if($detail->CustomerName  !=""):?>
                  <span class="text-underline text-center footer-paraf-name"><?php echo $detail->CustomerName;?></span>
                      <?php else:?>
                  <span class="text-underline normal_bold span_block footer-paraf-name">____________</span>
                  <?php endif;?>
              </div>    
              <?php if(($detail->TransStatus == 3) or ($detail->TransStatus == 9)){?>
                  <div class="footer-status"><h4 id="title-form" class="suspended">DOKUMEN TIDAK BERLAKU</h4></div>     
              <?php }?>
              <div class='clear-float'></div>
          </div>

          <div class="footer-bottom">
              <div class="footer-bottom-company">
                  <?php echo $this->load->model('file/m_new_company')->get_company_name($this->session->userdata('company')); ?> - <?php echo $detail->BranchName; ?>
                  <div class="footer-bottom-page">Page : 1 Of 1</div>
              </div>
              <div class='clear-float'></div>
          </div>
      </div>
      <?php endfor;?>
      <?php endif;?>
      <!-- End Item <=8 -->
    <?php endif;?>
        </div>
  </div>
</body>
</html>

<script type="text/javascript">

  $(document).ready(function(){

    $('.txt_do_number').on('click',function(){
        var ADebtNumber   = $(this).html();
        ADebtNumber       = ADebtNumber.trim();
        ADebtNumber       = ADebtNumber.replace('&nbsp;','');
        var arrNumber     = ADebtNumber.split("/");
        var type_trans    = arrNumber[1];
        var no_type       = type_trans.substr(-2,2);  
        if(no_type == 'DO'){ 
          parent.tab_edit('Edit Delivery Order', 'list/delivery_order', 'icon-edit', 'edit', ADebtNumber);
        }
    }).on('mouseover',function(){
        $(this).css({"color":"blue","text-decoration":"underline","cursor":"pointer"});
    }).on('mouseout',function(){
        $(this).css({"color":"#000000","text-decoration":"none"});
    });

    $('.txt_item_code').on('click',function(){
        
    }).on('mouseover',function(){
        $(this).css({"color":"blue","text-decoration":"underline","cursor":"pointer"});
    }).on('mouseout',function(){
        $(this).css({"color":"#000000","text-decoration":"none"});
    });

});

function open_master_item(ItemCode,status){
  if(status == 0){
    parent.tab_edit('Edit Item Master', 'list/items', 'icon-edit', 'edit', ItemCode);
  }
}

function open_sotrans(event){
  var ortu        = $(event.target);
  var poClass     = ortu.attr('soClass');
  var strNumber   = $('.so_trans_'+poClass).html();
  strNumber       = strNumber.replace('&nbsp;','');
  strNumber       = strNumber.trim();
  var arrNumber   = strNumber.split(",");
  var content_tt  = '';
  for(var x=0;x<arrNumber.length;x++){
    //content_tt += '<p onclick="open_transaction("'+arrNumber[x]+'")">'+arrNumber[x]+'</p>';
    content_tt += "<p onclick='open_sotransaction(event)'>"+arrNumber[x]+"</p>";
  }
   $('.SOTrans').tooltip({
      onShow:function(){
        $(this).tooltip({
          content:content_tt
        })
        var t = $(this);
        t.tooltip('tip').unbind().bind('mouseenter', function(){
            t.tooltip('show');
        }).bind('mouseleave', function(){
            t.tooltip('hide');
        });
      }
    });
}

function open_sotransaction(event){
  var ortu          = $(event.target);
  var number        = ortu.html();
  number            = number.trim();
  number            = number.replace('&nbsp;','');
  var arrNumber     = number.split("/");
  var type_trans    = arrNumber[1];
  var no_type       = type_trans.substr(-2,2);  
  if(no_type == 'SO'){ 
    parent.tab_edit('Edit Sales Order', 'list/sales_order', 'icon-edit', 'edit', number);
  }
}

function print_detail(){
  var data_print  = $("#print-container").html();
  Popup(data_print);
  
}


function Popup(data) 
{
    var mywindow = window.open('', 'print-container', 'height=528,width=700');
    var css = css_print();
    mywindow.document.write('<html><head><title>Print Detail</title>');
    mywindow.document.write(css);
    mywindow.document.write('</head><body >');
    mywindow.document.write(data);
    mywindow.document.write('</body></html>');

    mywindow.document.close(); // necessary for IE >= 10
    mywindow.focus(); // necessary for IE >= 10

    mywindow.print();
    mywindow.close();

    return true;
}

</script>