<?php $this->view("includes/Inc_pagehead");?>
<!-- Page Styles Goes Here-->

<style>
.m-invoice-2 .m-invoice__wrapper .m-invoice__body table thead tr th {
  color: #000000;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__body table tbody tr td {
  color: #000000;
}
.item_table td{
  padding: .75rem !important;
}
.item_table th{
  white-space: nowrap;
  padding: .75rem !important;
}
.table thead th {
  border-top: 2px solid #00000091 !important;
}
.table thead th {
  border: 2px solid #00000091 !important;
}
.table tbody td {
  border: 2px solid #00000091 !important;
}
.payment-table tbody td{
  border-top: 2px solid #00000091 !important;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container.m-invoice__container--centered {
  width: 90%;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__body.m-invoice__body--centered {
  width: 95%;
  padding: 1rem 1rem 1rem 1rem;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__body table thead tr th {
  padding: 0.2rem 0.5rem 0.3rem 0.5rem !important
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__body table tbody tr td {
  padding: 0.2rem 0.5rem 0.3rem 0.5rem !important
}
.m-invoice-2{
  line-height: 20px !important;
}

@media print
{
  body * {
    visibility: hidden;
  }
  .m-portlet__body * {
    visibility: visible;
    overflow: visible !important;
  }
  .table-bordered td{
    padding: .75rem !important;
  }
  .table-bordered th{
    white-space: nowrap;
    padding: .75rem !important;
  }
  .table-bordered .table thead th {
    border-top: 2px solid #00000091 !important;
  }
  .table thead th {
    border-top: 2px solid #00000091 !important;
  }
  .table tbody td {
    border: 2px solid #00000091 !important;
  }
  .m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container.m-invoice__container--centered {
    width: 100%;
  }
  .m-invoice-2 .m-invoice__wrapper .m-invoice__body.m-invoice__body--centered {
    width: 100%;
    padding: 0rem !important;
  }
  .m-invoice__container{
    width: 100%;
  }
  .m-content{
    padding: 0px !important;
  }
  body{
    background-color: white !important;
  }
  .m-body .m-content {
    min-height: 200px !important;
  }
  #print, .print_hide_div
  {
    display: none !important;
    height: 0px !important;
    padding: 0px !important;
    margin: 0px !important;
  }
  .m-portlet .m-portlet__head {
    display: none !important;
    height: 0px !important;
  }
  .m-subheader  {
    display: none !important;
    height: 0px !important;
  }
  .m-header--fixed .m-body {
    padding-top: 0px !important;
    padding-bottom: 0px !important;
  }
  .m-header {
    height: 0px !important;
  }
  .m-portlet {
    margin-bottom: 0px !important;
}
.m-footer--push.m-aside-left--enabled:not(.m-footer--fixed) .m-aside-right, .m-footer--push.m-aside-left--enabled:not(.m-footer--fixed) .m-wrapper {
    margin-bottom: 0px !important;
}
}
@media print {
  /* html, body, div, span, applet, object, iframe, td, tr, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
    font-size: 15pt !important;  }
    h1.entry-title {
      font-size: 15pt !important;
    }*/
  }

  @media print { tr.bg_S { background-color: rgb(224, 224, 224) !important; -webkit-print-color-adjust: exact; } } @media print { .bg_S th { background-color: rgb(224, 224, 224) !important; } }
  @media print { tr.bg_H { background-color: rgb(224, 224, 224) !important; -webkit-print-color-adjust: exact; } } @media print { .bg_H th { background-color: rgb(224, 224, 224) !important; } }
  @media print { tr.bg_L { background-color: #7f7f7f !important; -webkit-print-color-adjust: exact; } } @media print { .bg_L th { background-color: #7f7f7f !important; } }
  @media print { tr.bg_N { background-color: rgba(94, 94, 94, 0.52) !important; -webkit-print-color-adjust: exact; } } @media print { .bg_N th { background-color: rgba(94, 94, 94, 0.52) !important; } }

  .no-border thead th {
    border: none !important;
    border-top: none !important;
  }
  @page {
    size: auto;
    margin: 0;
}
</style>
<?php $this->view("includes/Inc_navigation");?>
<div class="m-grid__item m-grid__item--fluid m-wrapper">
  <!-- BEGIN: Subheader -->
  <div class="m-subheader ">
    <div class="d-flex align-items-center">
      <div class="mr-auto">
        <h3 class="m-subheader__title m-subheader__title--separator">
          Sales Invoice
        </h3>
        <ul class="m-subheader__breadcrumbs m-nav m-nav--inline">
          <li class="m-nav__item m-nav__item--home">
            <a href="#" class="m-nav__link m-nav__link--icon">
              <i class="m-nav__link-icon la la-home"></i>
            </a>
          </li>
          <li class="m-nav__separator">
            -
          </li>
          <li class="m-nav__item">
            <a href="<?php echo base_url().'dashboard'?>" class="m-nav__link">
              <span class="m-nav__link-text">
                Home
              </span>
            </a>
          </li>
          <li class="m-nav__separator">
            -
          </li>
          <li class="m-nav__item">
            <a href="<?php echo base_url().'sales_invoice' ?>" class="m-nav__link">
              <span class="m-nav__link-text">
                Sales Invoice
              </span>
            </a>
          </li>


        </ul>
      </div>
      <div>

      </div>
    </div>
  </div>
  <!-- END: Subheader -->
  <div class="m-content">
    <div class="m-portlet m-portlet--full-height">
      <div class="m-portlet__head">
        <div class="m-portlet__head-caption">
          <div class="m-portlet__head-title">
            <h3 class="m-portlet__head-text">
            </h3>
          </div>
        </div>
        <div class="m-portlet__head-tools" >

          <a style="margin-left: 5px;margin-right: 5px" href="javascript:;" onclick="window.print()" id="btn_print_invoice" class="btn m-btn--gradient-from-warning m-btn--gradient-to-danger  m-btn  m-btn--icon m-btn--air m-btn--pill">
            <span>
              <i class="la la-print"></i>
              <span>
                Print Invoice
              </span>
            </span>
          </a>
          <?php if($this->session->userdata('user_role')!='auditor'){ ?>
            <?php
            if($invoice_data->balance_amount > 0){?>
              <a style="margin-left: 5px;margin-right: 5px" data-bill-type="sales_invoice" data-bill-id="<?php echo $invoice_data->invoice_id?>" id="btn_receive_payment_add" data-toggle="modal"  href="#receive_payment_add_modal" class="btn m-btn--gradient-from-success m-btn--gradient-to-focus  m-btn  m-btn--icon m-btn--air m-btn--pill">
                <span>
                  <i class="la la-plus"></i>
                  <span>
                    Receive Payment
                  </span>
                </span>
              </a>
            <?php } ?>
          <?php } ?>

        </div>
      </div>
      <div class="m-portlet__body m-portlet__body--no-padding" id="print_view">
        <div class="m-invoice-2" style="padding: 40px;padding-bottom:20px">
          <div  class="m-invoice__wrapper">
            <div class="m-invoice__body m-invoice__body--centered" style="">
              <table class="table m-table table-bordered item_table" style="width:100%;margin-bottom:0px !important">
                <thead>
                  <tr>
                    <th colspan="3" style="text-align:center">INVOICE <?php echo $invoice_data->invoice_type?></th>
                  </tr>
                  <tr>
                    <th rowspan="4" style="vertical-align: top;line-height: 24px !important;">
                        <?php if($invoice_data->invoice_branch_id!=0){ ?>
                          <h5><?php echo $invoice_data->branch_name ?></h5>
                          <span><?php echo nl2br($invoice_data->branch_address) ?></span>
                          <span><?php if($branch_data->branch_taxno!=''){
                            echo "<br/>GSTIN : ".$branch_data->branch_taxno."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;State : ".$branch_data->state_name." &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Code : ".$branch_data->state_code."";
                          } ?></span>
                        <?php }else{ ?>
                          <h5><?php echo $this->config->item('company_name')?></h5>
                          <?php echo preg_replace('#(<br */?>\s*)+#i', '<br />',$this->config->item('company_address'))?>
                        <?php } ?>
                      </th>
                      <?php
                      $invoice_suffix = '';
                      if($invoice_data->fin_year!=''){
                        $fin_year_array = explode("-",$invoice_data->fin_year);
                        $fin_year_1 = $fin_year_array[0];
                        $fin_year_1 = substr($fin_year_1, -2);
                        $fin_year_2 = $fin_year_array[1];
                        $fin_year_2 = substr($fin_year_2, -2);
                        $invoice_suffix = "/".$fin_year_1."-".$fin_year_2;
                    }
                       ?>
                      <th style="text-align:left"><strong>Invoice No</strong></th>
                      <th style="text-align:left"><strong><?php echo $invoice_data->invoice_no_prefix.sprintf('%03u',$invoice_data->invoice_no).$invoice_suffix?></strong></th>
                    </tr>
                    <tr>
                      <th style="text-align:left"><strong>Date</strong></th>
                      <th style="text-align:left"><strong><?php echo date('d-m-Y',strtotime($invoice_data->invoice_date))?></strong></th>
                    </tr>
                    <tr>
                      <th style="text-align:left">Buyers Order No.<br/><strong><?php echo $invoice_data->buyers_order_no?></strong>&nbsp;</th>
                      <th style="text-align:left">Dated <br/><strong><?php if($invoice_data->buyers_order_date!='0000-00-00'){ echo date('d-m-Y',strtotime($invoice_data->buyers_order_date));}?></strong>&nbsp;</th>
                    </tr>
                    <tr>
                      <th style="text-align:left">Despatched Through.<br/><strong><?php echo $invoice_data->despatched_through?></strong>&nbsp;</th>
                      <th style="text-align:left">Destination <br/><strong><?php echo $invoice_data->destination?></strong>&nbsp;</th>
                    </tr>

                    <tr>
                      <th rowspan="5" style="padding: 0px !important;vertical-align: top">
                        <table class="no-border">
                          <thead>
                            <tr>
                              <th style="text-align:left"><strong>Customer</strong></th>
                              <th>:</th>
                              <th colspan="4" style="text-align:left"><strong><?php echo $invoice_data->buyer_name?></strong></th>
                            </tr>
                            <tr>
                              <th style="text-align:left"><strong>Address</strong></th>
                              <th>:</th>
                              <th style="text-align:left" colspan="4"><?php echo $invoice_data->buyer_address?></th>
                            </tr>
                            <tr>
                              <th style="text-align:left"><strong>Phone</strong></th>
                              <th>:</th>
                              <th style="text-align:left" colspan="4"><?php echo $invoice_data->buyer_phone?></th>
                            </tr>
                            <tr>
                              <th style="text-align:left"><strong>GSTIN</strong></th>
                              <th>:</th>
                              <th style="text-align:left" colspan="4"><strong><?php echo $invoice_data->buyer_taxno?></strong></th>
                            </tr>
                            <tr>
                              <th style="text-align:left"><strong>State</strong></th>
                              <th>:</th>
                              <th style="text-align:left"><?php echo $invoice_data->state_name?></th>
                              <th style="text-align:left"><strong>State Code</strong></th>
                              <th>:</th>
                              <th style="text-align:left"><?php echo $invoice_data->state_code?></th>
                            </tr>
                          </thead>
                        </table>
                        <div style="border-top:2px solid #00000091"></div>
                        <label style="margin:10px"><strong>Buyer Shipping Address</strong></label>
                        <table class="no-border">
                          <thead>
                            <tr>
                              <th style="text-align:left"><strong>Customer</strong></th>
                              <th>:</th>
                              <th colspan="4" style="text-align:left"><strong><?php echo $invoice_data->buyer_name?></strong></th>
                            </tr>
                            <tr>
                              <th style="text-align:left"><strong>Address</strong></th>
                              <th>:</th>
                              <th style="text-align:left" colspan="4"><?php echo $invoice_data->buyer_address?></th>
                            </tr>
                            <tr>
                              <th style="text-align:left"><strong>Phone</strong></th>
                              <th>:</th>
                              <th style="text-align:left" colspan="4"><?php echo $invoice_data->buyer_phone?></th>
                            </tr>
                            <tr>
                              <th style="text-align:left"><strong>GSTIN</strong></th>
                              <th>:</th>
                              <th style="text-align:left" colspan="4"><strong><?php echo $invoice_data->buyer_taxno?></strong></th>
                            </tr>
                            <tr>
                              <th style="text-align:left"><strong>State</strong></th>
                              <th>:</th>
                              <th style="text-align:left"><?php echo $invoice_data->state_name?></th>
                              <th style="text-align:left"><strong>State Code</strong></th>
                              <th>:</th>
                              <th style="text-align:left"><?php echo $invoice_data->state_code?></th>
                            </tr>
                          </thead>
                        </table>
                      </th>
                      <th style="text-align:left;height: 30px;">Delivery Note No.</th>
                      <th style="text-align:left"><strong><?php echo $invoice_data->delivery_note_no?></strong></th>
                    </tr>
                    <tr>
                      <th style="text-align:left;height: 30px;">Delivery Date</th>
                      <th style="text-align:left"><?php if($invoice_data->delivery_date!='0000-00-00'){ echo date('d-m-Y',strtotime($invoice_data->delivery_date));}?></strong></th>
                    </tr>
                    <tr>
                      <th style="text-align:left;height: 30px;">Vehicle</th>
                      <th style="text-align:left"><strong><?php echo $invoice_data->vehicle?></strong></th>
                    </tr>
                    <tr>
                      <th style="text-align:left;height: 30px;">&nbsp;</th>
                      <th style="text-align:left">&nbsp;</th>
                    </tr>
                    <tr>
                      <th style="text-align:left;vertical-align: top" colspan="2">Terms of Delivery
                        <br/><br/><?php echo $invoice_data->bill_remarks?></th>
                      </tr>
                    </thead>
                    <tbody>

                    </tbody>
                  </table>
                  <table class="table m-table table-bordered item_table" style="width:100%;margin-bottom:0px !important">
                    <?php
                    $tax0_have = $tax1_have = $tax2_have = $tax3_have = $colspan = 0;
                    foreach($invoice_items as $row):
                      if($row->tax1_percent!=0){
                        $tax1_have = 1;
                        $colspan += 2;
                      }
                      if($row->tax2_percent!=0){
                        $tax2_have = 1;
                        $colspan += 2;
                      }
                      if($row->tax3_percent!=0){
                        $tax3_have = 1;
                        $colspan += 2;
                      }
                      if($row->tax1_percent==0 && $row->tax2_percent==0 && $row->tax3_percent==0){
                        $tax0_have = 1;
                      }
                    endforeach;
                    if($colspan == 0){
                      $colspan = 1;
                    }
                    ?>
                    <thead>
                      <tr>
                        <th rowspan="2" style="width:5% !important">Sl<br/>No</th>
                        <th rowspan="2" style="text-align: left;width:22% !important">Item Name</th>
                        <th rowspan="2" >HSN Code</th>
                        <th rowspan="2" >Rate</th>
                        <th rowspan="2" >Qty</th>
                        <th rowspan="2" >UoM</th>
                        <th rowspan="2" >Disc.</th>
                        <th rowspan="2" >Net</th>
                        <?php if($tax1_have==1){ ?>
                          <th colspan="2" style="text-align:center"><?php echo $this->config->item('Tax_tax1_name')?></th>
                        <?php } ?>
                        <?php if($tax2_have==1){ ?>
                          <th colspan="2" style="text-align:center"><?php echo $this->config->item('Tax_tax2_name')?></th>
                        <?php } ?>
                        <?php if($tax3_have==1){ ?>
                          <th colspan="2" style="text-align:center"><?php echo $this->config->item('Tax_tax3_name')?></th>
                        <?php } ?>
                        <th rowspan="2" >Amount</th>
                      </tr>
                      <tr>
                        <?php if($tax1_have==1){ ?>
                          <th>%</th>
                          <th>Amt</th>
                        <?php } ?>
                        <?php if($tax2_have==1){ ?>
                          <th>%</th>
                          <th>Amt</th>
                        <?php } ?>
                        <?php if($tax3_have==1){ ?>
                          <th>%</th>
                          <th>Amt</th>
                        <?php } ?>
                      </tr>
                    </thead>
                    <tbody>
                      <?php
                      $total_qty = 0;
                      $n = 1;
                      $tax_percent = $this->config->item('Tax_tax_percent');
                      foreach ($tax_percent as $row){
                        ${'total_taxable_amt_'.$row->tax_id} = 0;
                      }
                      $total_tax0_amt = $total_tax1_amt = $total_tax2_amt = $total_tax3_amt = 0;
                      foreach($invoice_items as $row):
                        $row->tax1_amount = round($row->taxable_amount*$row->tax1_percent/100,$this->config->item('Currency_amount_decimals_2'));
                        $row->tax2_amount = round($row->taxable_amount*$row->tax2_percent/100,$this->config->item('Currency_amount_decimals_2'));
                        $row->tax3_amount = round($row->taxable_amount*$row->tax3_percent/100,$this->config->item('Currency_amount_decimals_2'));
                        if($row->tax1_percent==0 && $row->tax2_percent==0 && $row->tax3_percent==0){
                          $total_tax0_amt += $row->taxable_amount;
                        }
                        $total_tax1_amt += $row->tax1_amount;
                        $total_tax2_amt += $row->tax2_amount;
                        $total_tax3_amt += $row->tax3_amount;
                        ?>
                        <tr>
                          <td style="border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"><?php echo $n++?></td>
                          <td style="text-align: left;border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"><?php echo $row->material_name?><br/><span style="font-style: italic"><?php echo $row->description?></span></td>
                          <td style="border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"><?php echo $row->item_code?></td>
                          <td style="white-space: nowrap;border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"><?php echo $this->config->item('currency_format')->formatCurrency($row->unit_sale_price,$this->config->item('Currency_currency_shortname'));?></td>
                          <td style="white-space: nowrap;border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"><?php echo $row->quantity?></td>
                          <td style="white-space: nowrap;border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"><?php echo $row->unit_name?></td>
                          <td style="white-space: nowrap;border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"><?php echo $this->config->item('currency_format')->formatCurrency($row->discount_amount,$this->config->item('Currency_currency_shortname'));?></td>
                          <td style="white-space: nowrap;border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"><?php echo $this->config->item('currency_format')->formatCurrency($row->taxable_amount,$this->config->item('Currency_currency_shortname'));?></td>
                          <?php if($tax1_have==1){ ?>
                            <td style="white-space: nowrap;border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"><?php echo $row->tax1_percent?>%</td>
                            <td style="white-space: nowrap;border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"><?php echo $this->config->item('currency_format')->formatCurrency($row->tax1_amount,$this->config->item('Currency_currency_shortname'));?></td>
                          <?php } ?>
                          <?php if($tax2_have==1){ ?>
                            <td style="white-space: nowrap;border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"><?php echo $row->tax2_percent?>%</td>
                            <td style="white-space: nowrap;border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"><?php echo $this->config->item('currency_format')->formatCurrency($row->tax2_amount,$this->config->item('Currency_currency_shortname'));?></td>
                          <?php } ?>
                          <?php if($tax3_have==1){ ?>
                            <td style="white-space: nowrap;border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"><?php echo $row->tax3_percent?>%</td>
                            <td style="white-space: nowrap;border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"><?php echo $this->config->item('currency_format')->formatCurrency($row->tax3_amount,$this->config->item('Currency_currency_shortname'));?></td>
                          <?php } ?>
                          <td style="white-space: nowrap;border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"><?php echo $this->config->item('currency_format')->formatCurrency($row->total_amount,$this->config->item('Currency_currency_shortname'));?></td>
                        </tr>
                        <?php
                        ${'total_taxable_amt_'.$row->tax_id} += $row->taxable_amount;
                        $total_qty += $row->quantity;
                      endforeach;
                      if(sizeof($invoice_items)<10){ //Add Blank Columns
                        for($i=1;$i<(10-sizeof($invoice_items));$i++){ ?>
                          <tr>
                            <td style="border-top: 0px !important;border-bottom: 0px !important;vertical-align:top">&nbsp;</td>
                            <td style="border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"></td>
                            <td style="border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"></td>
                            <td style="border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"></td>
                            <td style="border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"></td>
                            <td style="border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"></td>
                            <td style="border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"></td>
                            <td style="border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"></td>
                            <?php if($tax1_have==1){ ?>
                              <td style="border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"></td>
                              <td style="border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"></td>
                            <?php } ?>
                            <?php if($tax2_have==1){ ?>
                              <td style="border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"></td>
                              <td style="border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"></td>
                            <?php } ?>
                            <?php if($tax3_have==1){ ?>
                              <td style="border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"></td>
                              <td style="border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"></td>
                            <?php } ?>
                            <td style="border-top: 0px !important;border-bottom: 0px !important;vertical-align:top"></td>
                          </tr>
                        <?php }
                      }
                      ?>
                    </tbody>
                    <tfoot>
                      <tr>
                        <td colspan="4" style="text-align:right;border:2px solid #00000091 !important;"><strong> Total Qty : </strong></td>
                        <td style="text-align:right;border:2px solid #00000091 !important;"><strong><?php echo $total_qty?></strong></td>
                        <td style="border:2px solid #00000091 !important;"colspan="<?php echo $colspan+4?>"></td>
                      </tr>
                    </tfoot>
                  </table>
                  <table class="table  m-table table-bordered item_table" style="width:100%;margin-bottom:0px !important">
                    <thead>

                    </thead>
                    <tbody>
                      <tr>
                        <td rowspan="10" style="width:65%;border-top: 2px solid #b7b7b7 !important;padding: 0px !important;border-bottom:0px !important">
                          <table class="table  m-table table-bordered item_table">
                            <caption style="color:black">TAX DETAILS</caption>
                            <thead>
                              <tr>
                                <th style="text-align: center">Class</th>
                                <th style="text-align: center">Taxable Amt</th>
                                <?php if($tax1_have==1){ ?>
                                  <th style="text-align: center"><?php echo $this->config->item('Tax_tax1_name')?></th>
                                  <th style="text-align: center">Amount</th>
                                <?php } ?>
                                <?php if($tax2_have==1){ ?>
                                  <th style="text-align: center"><?php echo $this->config->item('Tax_tax2_name')?></th>
                                  <th style="text-align: center">Amount</th>
                                <?php } ?>
                                <?php if($tax3_have==1){ ?>
                                  <th style="text-align: center"><?php echo $this->config->item('Tax_tax3_name')?></th>
                                  <th style="text-align: center">Amount</th>
                                <?php } ?>
                              </tr>
                            </thead>
                            <tbody>
                              <?php
                              $tax_percent = $this->config->item('Tax_tax_percent');
                              foreach ($tax_percent as $row){
                                if($row->tax1_percent==0 && $row->tax2_percent==0 && $row->tax3_percent==0){ ?>
                                  <tr>
                                    <td style="text-align: center"><?php echo $this->config->item('Tax_tax_name')." ".$row->tax_percentage."%" ?></td>
                                    <td style="text-align: center"><?php echo ${'total_taxable_amt_'.$row->tax_id}; ?></td>
                                    <?php if($tax1_have==1){ ?>
                                      <td style="text-align: center"><?php echo $row->tax1_percent."%" ?></td>
                                      <td style="text-align: center"><?php echo $this->config->item('currency_format')->formatCurrency(((${'total_taxable_amt_'.$row->tax_id})*$row->tax1_percent/100),$this->config->item('Currency_currency_shortname')); ?></td>
                                    <?php } ?>
                                    <?php if($tax2_have==1){ ?>
                                      <td style="text-align: center"><?php echo $row->tax2_percent."%" ?></td>
                                      <td style="text-align: center"><?php echo $this->config->item('currency_format')->formatCurrency(((${'total_taxable_amt_'.$row->tax_id})*$row->tax2_percent/100),$this->config->item('Currency_currency_shortname')); ?></td>
                                    <?php } ?>
                                    <?php if($tax3_have==1){ ?>
                                      <td style="text-align: center"><?php echo $row->tax3_percent."%" ?></td>
                                      <td style="text-align: center"><?php echo $this->config->item('currency_format')->formatCurrency(((${'total_taxable_amt_'.$row->tax_id})*$row->tax3_percent/100),$this->config->item('Currency_currency_shortname')); ?></td>
                                    <?php } ?>
                                  </tr>
                                <?php }
                                if($row->tax1_percent!=0 || $row->tax2_percent!=0 || ($tax3_have==1 && $row->tax3_percent!=0) ){ ?>
                                  <tr>
                                    <td style="text-align: center"><?php echo $this->config->item('Tax_tax_name')." ".$row->tax_percentage."%" ?></td>
                                    <td style="text-align: center"><?php echo ${'total_taxable_amt_'.$row->tax_id}; ?></td>
                                    <?php if($tax1_have==1){ ?>
                                      <td style="text-align: center"><?php echo $row->tax1_percent."%" ?></td>
                                      <td style="text-align: center"><?php echo $this->config->item('currency_format')->formatCurrency(((${'total_taxable_amt_'.$row->tax_id})*$row->tax1_percent/100),$this->config->item('Currency_currency_shortname')); ?></td>
                                    <?php } ?>
                                    <?php if($tax2_have==1){ ?>
                                      <td style="text-align: center"><?php echo $row->tax2_percent."%" ?></td>
                                      <td style="text-align: center"><?php echo $this->config->item('currency_format')->formatCurrency(((${'total_taxable_amt_'.$row->tax_id})*$row->tax2_percent/100),$this->config->item('Currency_currency_shortname')); ?></td>
                                    <?php } ?>
                                    <?php if($tax3_have==1){ ?>
                                      <td style="text-align: center"><?php echo $row->tax3_percent."%" ?></td>
                                      <td style="text-align: center"><?php echo $this->config->item('currency_format')->formatCurrency(((${'total_taxable_amt_'.$row->tax_id})*$row->tax3_percent/100),$this->config->item('Currency_currency_shortname')); ?></td>
                                    <?php } ?>
                                  </tr>
                                <?php }
                              } ?>
                            </tbody>
                          </table>
                          <table class="no-border" style="width:100%">
                            <thead>
                              <tr>
                                <th colspan="4" style="font-size: 1.2rem;text-align:center;border-bottom:2px solid #00000091 !important"><?php echo $invoice_data->receivable_amount_in_words ?></th>
                              </tr>
                              <tr>
                                <th style="text-align:left">Bank Name</th>
                                <th style="text-align:left;width:40%;min-width:40%"><?php echo $invoice_data->bank_name ?></th>
                                <th style="text-align:left">Old Balance</th>
                                <th><?php echo $this->config->item('currency_format')->formatCurrency(0,$this->config->item('Currency_currency_shortname')); ?></th>
                              </tr>
                              <tr>
                                <th style="text-align:left">Branch</th>
                                <th style="text-align:left"><?php echo $invoice_data->bank_branch ?></th>
                                <th style="text-align:left">Cash Received</th>
                                <th><?php echo $this->config->item('currency_format')->formatCurrency(0,$this->config->item('Currency_currency_shortname')); ?></th>
                              </tr>
                              <tr>
                                <th style="text-align:left">Acc No</th>
                                <th style="text-align:left"><?php echo $invoice_data->bank_account_no ?></th>
                                <th style="text-align:left">Net Balance</th>
                                <th><?php echo $this->config->item('currency_format')->formatCurrency($invoice_data->receivable_amount,$this->config->item('Currency_currency_shortname')); ?></th>
                              </tr>
                              <tr>
                                <th style="text-align:left"><?= $this->config->item('bank_ifsc_name')?></th>
                                <th style="text-align:left"><?php echo $invoice_data->bank_ifsc ?></th>
                                <th style="text-align:left"><h6>Receivers Signature</h6></th>
                                <th></th>
                              </tr>
                            </thead>
                          </table>
                        </td>
                        <td style="text-align:left;border:none !important"><strong>NET TOTAL</strong></td>
                        <td style="border:none !important;border-left:2px solid #00000091 !important;border-right:2px solid #00000091 !important"><strong><?php echo $this->config->item('currency_format')->formatCurrency($invoice_data->net_total,$this->config->item('Currency_currency_shortname'));?></strong></td>
                      </tr>
                      <tr>
                        <td style="text-align:left;border:none !important"><?php echo $this->config->item('Tax_tax1_name')?></td>
                        <td style="border:none !important;border-left:2px solid #00000091 !important;border-right:2px solid #00000091 !important"><?php echo $this->config->item('currency_format')->formatCurrency($total_tax1_amt,$this->config->item('Currency_currency_shortname'));?></td>
                      </tr>
                      <tr>
                        <td style="text-align:left;border:none !important"><?php echo $this->config->item('Tax_tax2_name')?></td>
                        <td style="border:none !important;border-left:2px solid #00000091 !important;border-right:2px solid #00000091 !important"><?php echo $this->config->item('currency_format')->formatCurrency($total_tax2_amt,$this->config->item('Currency_currency_shortname'));?></td>
                      </tr>
                      <tr>
                        <td style="text-align:left;border:none !important"><?php echo $this->config->item('Tax_tax3_name')?></td>
                        <td style="border:none !important;border-left:2px solid #00000091 !important;border-right:2px solid #00000091 !important"><?php echo $this->config->item('currency_format')->formatCurrency($total_tax3_amt,$this->config->item('Currency_currency_shortname'));?></td>
                      </tr>
                      <tr>
                        <td style="text-align:left;border:none !important">&nbsp;</td>
                        <td style="border:none !important;border-left:2px solid #00000091 !important;border-right:2px solid #00000091 !important">&nbsp;</td>
                      </tr>
                      <tr>
                        <td style="text-align:left;border:none !important"><strong>GRAND TOTAL</strong></td>
                        <td style="border:none !important;border-left:2px solid #00000091 !important;border-right:2px solid #00000091 !important"><strong><?php echo $this->config->item('currency_format')->formatCurrency($invoice_data->net_total+$invoice_data->tax_amount,$this->config->item('Currency_currency_shortname'));?></strong></td>
                      </tr>
                      <tr>
                        <td style="text-align:left;border:none !important">Other Charges</td>
                        <td style="border:none !important;border-left:2px solid #00000091 !important;border-right:2px solid #00000091 !important"><?php echo $this->config->item('currency_format')->formatCurrency(0,$this->config->item('Currency_currency_shortname'));?></td>
                      </tr>
                      <tr>
                        <td style="text-align:left;border:none !important">Other Discount</td>
                        <td style="border:none !important;border-left:2px solid #00000091 !important;border-right:2px solid #00000091 !important"><?php echo $this->config->item('currency_format')->formatCurrency(0,$this->config->item('Currency_currency_shortname'));?></td>
                      </tr>
                      <tr>
                        <td style="text-align:left;border:none !important">Round Off</td>
                        <td style="border:none !important;border-left:2px solid #00000091 !important;border-right:2px solid #00000091 !important"><?php echo $this->config->item('currency_format')->formatCurrency($invoice_data->round_amount,$this->config->item('Currency_currency_shortname'));?></td>
                      </tr>
                      <tr>
                        <td style="text-align:left;border:none !important;border-bottom:2px solid #00000091 !important;font-size:1.8rem !important;"><strong>BILL AMOUNT</strong></td>
                        <td style="border:none !important;border-left:2px solid #00000091 !important;border-right:2px solid #00000091 !important;border-bottom:2px solid #00000091 !important;font-size:1.8rem !important;"><strong><?php echo $this->config->item('currency_format')->formatCurrency($invoice_data->receivable_amount,$this->config->item('Currency_currency_shortname'));?></strong></td>
                      </tr>
                    </tbody>
                  </table>
                  <table style="width:100%">
                    <thead>
                      <tr>
                        <th style="border-left:2px solid #00000091 !important;border-bottom:2px solid #00000091 !important;">
                          <strong>Declaration :<br/><br/>Certified that the Particulars given above are true and correct</strong>
                        </th>
                        <th style="text-align:right;border-right:2px solid #00000091 !important;border-bottom:2px solid #00000091 !important;">
                          <h5 style="margin-top:10px">
                            <?php if($invoice_data->invoice_branch_id!=0){ ?>
                              <?php echo $invoice_data->branch_name ?></h3>
                            <?php }else{ ?>
                              <?php echo $this->config->item('company_name') ?>
                            <?php } ?>
                          </h5><br/><br/><br/>
                          <strong>Authorised Signatory</strong>
                        </th>
                      </tr>
                    </thead>
                  </table>
                </div>

                <div class="print_hide_div" style="width: 90%;margin: 0 auto;padding: 2rem 0 0 0;">
                  <div class="" style="margin-bottom: 100px">
                    <table id="payment_view_table" class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" width="100%">
                      <thead style="font-weight: 500;font-size: 1.1rem;">
                        <tr>
                          <th>Sl No</th>
                          <th>Paid Date</th>
                          <th>Paid Amount</th>
                          <th>Debit Acc</th>
                          <!-- <th>Payment Part</th> -->
                          <th>TR Mode</th>
                          <th>TR Ref No</th>
                          <th>TR Ref Date</th>
                          <th>Remarks</th>
                          <th>Created By</th>
                          <th>Created Date</th>
                          <th>Actions</th>
                          <th class="hidden">TRID</th>
                          <th class="hidden">referenceno</th>
                          <th class="hidden">tr_credit_acc</th>
                          <th class="hidden">tr_amount</th>
                        </tr>
                      </thead>
                      <tbody style="font-weight: 600;font-size: 1.1rem;">
                        <?php
                        $sl_no=0;
                        foreach($sales_receipts as $row):
                          $sl_no++;

                          ?>
                          <tr>
                            <td><?php echo $sl_no?></td>
                            <td><?php echo date('d-m-Y',strtotime($row->tr_date))?></td>
                            <td><?php echo $row->tr_amount?></td>
                            <td><?php echo $row->debit_account?></td>
                            <td><?php echo $row->tr_mode?></td>
                            <td><?php echo $row->tr_reference_no?></td>
                            <td><?php if($row->tr_reference_date!='0000-00-00'){echo date('d-m-Y',strtotime($row->tr_reference_date));}?></td>
                            <td><?php echo $row->tr_remarks?></td>
                            <td><?php echo $row->created_user?></td>
                            <td><?php if ($this->config->item('UI_hide_created_date_field')==0){echo date('d-m-Y',strtotime($row->created_date));}else{ echo '';}?></td>
                            <td class="print_hide_div">
                              <!-- <a style="margin-left: 5px;margin-right: 5px" id="client_payment_edit_btn" href="#client_payment_edit_modal" data-toggle="modal" class="btn btn-info m-btn m-btn--icon  m-btn--icon-only m-btn--pill m-btn--air"><i class="la la-edit"></i></a> -->
                              <a style="margin-left: 5px;margin-right: 5px" data-form-type="sales_invoice" data-tr-type="sales_invoice_transaction" data-form-type="sales_invoice" data-id-column="11" id="sales_invoice_transaction_delete_btn"  href="#transaction_delete_modal" data-toggle="modal" class="btn btn-danger m-btn m-btn--icon  m-btn--icon-only m-btn--pill m-btn--air"><i class="la la-trash"></i></a>
                            </td>
                            <td class="hidden"><?= $row->transaction_id ?></td>
                            <td class="hidden"><?= $row->tr_reference_no ?></td>
                            <td class="hidden"><?= $row->tr_credit_acc ?></td>
                            <td class="hidden"><?= $row->tr_amount ?></td>
                          </tr>
                          <?php
                        endforeach;
                        ?>
                      </tbody>
                    </table>
                  </div>
                  <div class="m-invoice__table  m-invoice__table--centered table-responsive print_hide_div" style="margin-bottom: 100px">
                    <table class="table">
                      <thead>
                        <tr>
                          <th width="50%">PAYMENT STATUS :
                            <label class="m--font-danger">
                              <strong>
                                <?php
                                if($invoice_data->balance_amount <=0){
                                  echo "PAID";
                                }elseif($invoice_data->balance_amount>0 && $invoice_data->total_received>0) {
                                  echo "PARTIALLY PAID";
                                }else {
                                  echo "NOT PAID";
                                }
                                ?></strong>
                              </label>
                            </th>
                            <th width="30%" style="vertical-align: top">Total Received : <?php  echo $invoice_data->total_received;?></th>
                            <th width="30%" style="vertical-align: top">Balance :
                              <strong class="m--font-danger">
                                <?php
                                echo $invoice_data->balance_amount;
                                ?>
                              </strong>
                            </th>
                          </tr>
                          <tr>
                            <th colspan="4" >Remarks : <?php echo $invoice_data->bill_remarks;?>
                            </th>
                          </tr>
                        </thead>

                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <?php $this->view("modules/include_modals/modal_bills");?>
    <?php $this->view("modules/include_modals/modal_transaction_delete");?>
    <!-- end:: Body -->
    <!-- begin::Footer -->

    <?php $this->view("includes/Inc_footer");?>
    <!-- end::Footer -->

    <!-- end:: Page -->

    <?php $this->view("includes/Inc_sidebar");?>
    <?php $this->view("includes/Inc_scripts");?>


    <!--begin::Page Snippets -->
    <?php $this->view("modules/include_scripts/bill_scripts");?>
    <script>
    //    Toggle Sidebar
    // $("#m_aside_left_minimize_toggle").addClass("m-brand__toggler--active");
    // $("#body").addClass("m-brand--minimize m-aside-left--minimize");

    $("#sales_invoice_menu").addClass('m-menu__item--active m-menu__item--open');
    $("#sales_invoice_menu2").addClass('m-menu__item--active');

    $("#page_title").text("Sales Invoice - <?php echo $invoice_data->invoice_no_prefix.sprintf('%03u',$invoice_data->invoice_no).$invoice_suffix."-".$invoice_data->buyer_name?>")
    </script>
    <script>
    $('body').on('click', '#sales_invoice_transaction_delete_btn', function() {
      var no = $(this).closest('tr').children('td');
      $('#transaction_id_delete').val(no.eq(11).text());
    });
    $('#payment_view_table').DataTable({
      "scrollX" : true,
      scrollX:!0, scrollCollapse:!0,
      dom:"<'row'<'col-sm-6 text-left'><'col-sm-6 text-right'f>>\n\t\t\t<'row'<'col-sm-12'tr>>\n\t\t\t<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7 dataTables_pager'lp>>", // horizobtal scrollable datatable
      "paging":   false,
      "ordering": false,
      "info":     false,
      searching: false
    });
    $(".form_submit_btn").click(function (e) {

      e.preventDefault();
      var a = $(this),
      l = $(this).closest("form"),
      action = l.attr('action');
      var form_id = l.attr('id');
      l.validate({
        rules: {
          "new_paid_amount": {
            required: !0,
            number: !0
          }
        }, invalidHandler: function (e, r) {
          var i = $("#" + form_id + "_msg");
          i.removeClass("m--hide").show(), mUtil.scrollTo(i, -200)
        }, submitHandler: function (e) {
        }
      }), l.valid() && (a.addClass("m-loader m-loader--right m-loader--light").attr("disabled", !0),
      l.ajaxSubmit({
        url: action,
        success: function (e, t, r, s) {
          var modal_id = l.attr('data-modal-id');
          var form_type = l.attr('data-form-type');
          $("#" + form_id + "_msg").addClass("m--hide");
          // Block UI
          mApp.blockPage({
            overlayColor: "#000000",
            type: "loader",
            state: "success",
            message: "Please wait..."
          }), setTimeout(function () {
            mApp.unblockPage()
          }, 2e3);
          var obj = $.parseJSON(e);
          if (obj.status == 1) {
            a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
            toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
            $("#"+modal_id).modal('toggle');
            $("."+form_id+"_fields").val("");
            location.reload();
          } else {
            a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
            toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
          }
          if (obj == null) {
            setTimeout(function () {
              a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
              toastr["warning"]("Your Attempt is Timed Out. Please Try Again.", "Timed Out");
            }, 2e4)
          }
        },error: function() {
          a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
          toastr["error"]("Sorry. There Has Been Some Error Occurred. Please Try Again.", "Error");
        }
      })
    )
  });

</script>
