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

<style>
.item_table td{
  padding: .75rem !important;
}
.item_table th{
  white-space: nowrap;
  padding: .75rem !important;
}
.table thead th {
  border-top: 2px solid #f4f5f8 !important;
}
.payment-table tbody td{
  border-top: 2px solid #f4f5f8 !important;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container.m-invoice__container--centered {
  width: 95%;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__body.m-invoice__body--centered {
  width: 95%;
}
</style>


<style>

@media print {

  .table-bordered td{
    padding: .75rem !important;
  }
  .table-bordered th{
    white-space: nowrap;
    padding: .75rem !important;
  }
  .table-bordered .table thead th {
    border-top: 2px solid #f4f5f8 !important;
  }
  .m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container.m-invoice__container--centered {
    width: 95%;
  }
  .m-invoice-2 .m-invoice__wrapper .m-invoice__body.m-invoice__body--centered {
    width: 95%;
  }

  #print_view {
    margin-top: -20%;
  }

  body * {
    visibility: hidden;
  }
  .m-portlet__body * {
    visibility: visible;
    overflow: visible !important;
  }
  .letter_head_img{
    display: block !important;
  }
  .m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container .m-invoice__items .m-invoice__item {
    display: table-cell;
  }
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container .m-invoice__items .m-invoice__item {
  display: table-cell !important;
}
.col-sm-4 {
  -webkit-box-flex: 0;
  -ms-flex: 0 0 33.33333%;
  flex: 0 0 33.33333%;
  max-width: 33.33333%;
}
.col-sm-8 {
  -webkit-box-flex: 0;
  -ms-flex: 0 0 66.66667%;
  flex: 0 0 66.66667%;
  max-width: 66.66667%;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container.m-invoice__container--centered {
  width: 95%;
}
</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">
          Purchase Details
        </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().'purchases' ?>" class="m-nav__link">
              <span class="m-nav__link-text">
                Purchase Details
              </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" >
          <?php if ($this->config->item('Purchase_delivery_challan') == 1 && $purchase_data->delivery_challan_id != 0) { ?>
            <a href="<?php echo base_url().'purchases/delivery_challan/view/'.$purchase_data->delivery_challan_id?>" style="margin-left: 5px;margin-right: 5px" class="btn m-btn--gradient-from-danger m-btn--gradient-to-success  m-btn  m-btn--icon m-btn--air m-btn--pill">
              <span>
                <i class="fa fa-eye"></i>
                <span>
                  View Delivery Challan of This Bill
                </span>
              </span>
            </a>
          <?php } ?>
          <?php
          if($purchase_data->purchase_order_id != 0){?>
            <a href="<?php echo base_url().'purchase_order/profile/'.$purchase_data->purchase_order_id?>" style="margin-left: 5px;margin-right: 5px" class="btn m-btn--gradient-from-primary m-btn--gradient-to-success  m-btn  m-btn--icon m-btn--air m-btn--pill">
              <span>
                <i class="fa fa-eye"></i>
                <span>
                  View Purchase Order of This Bill
                </span>
              </span>
            </a>
          <?php } ?>

          <?php if($this->session->userdata('user_role')!='auditor' || $this->session->userdata('user_data_permission')['adding']==1){ ?>

            <?php
            if($purchase_data->payment_status != 1){?>
              <a style="margin-left: 5px;margin-right: 5px" data-bill-type="purchase_bill" data-bill-id="<?php echo $purchase_data->purchase_id?>" id="btn_add_bill_payment" data-toggle="modal"  href="#bill_payment_add_modal" 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-plus"></i>
                  <span>
                    Add Payment
                  </span>
                </span>
              </a>
            <?php } ?>

          <?php } ?>
          <?php if($purchase_data->sales_invoice_id==0){?>
            <?php if($this->session->userdata('user_role')=='admin' || $this->session->userdata('user_id')==$purchase_data->purchase_created_by){?>
              <a href="<?php echo base_url().'purchases/edit/'.$purchase_data->purchase_id?>" style="margin-left: 5px;margin-right: 5px" class="btn m-btn--gradient-from-focus m-btn--gradient-to-danger  m-btn  m-btn--icon m-btn--air m-btn--pill">
                <span>
                  <i class="fa fa-edit"></i>
                  <span>
                    Edit Bill
                  </span>
                </span>
              </a>
            <?php } ?>
          <?php } ?>
          <?php if($purchase_data->entry_approval_status==1){ ?>
            <a href="javascript:;" onclick="window.print()" id="btn_print_bill" style="margin-left: 5px;margin-right: 5px" class="btn m-btn--gradient-from-danger m-btn--gradient-to-info  m-btn  m-btn--icon m-btn--air m-btn--pill">
              <span>
                <i class="fa fa-print"></i>
                <span>
                  Print Purchase Bill
                </span>
              </span>
            </a>
          <?php } ?>
        </div>
      </div>
      <div class="m-portlet__body m-portlet__body--no-padding" id="print_view">
        <?php if($this->config->item('company_letter_head')!=''){ ?>
          <img class="letter_head_img" style="max-width: 100%;display:none" src="<?php echo base_url().'uploads/company/'.$this->config->item('company_letter_head')?>" />
        <?php } ?>
        <div class="m-invoice-2" style="padding-bottom: 20px">
          <div  class="m-invoice__wrapper">
            <div class="m-invoice__head" >
              <div class="m-invoice__container m-invoice__container--centered">
                <div class="m-invoice__logo" style="padding-top: 3rem;">

                </div>
                <div class="row">
                  <div class="col-sm-8 col-md-8" style="border-right: 1px solid #ebedf2;">
                    <span class="m-invoice__desc" style="text-align: left;padding: 1rem 0 1rem 0 !important;">
                      <span class="m-invoice__subtitle">Supplier.</span>
                      <span><strong><?php echo $purchase_data->supplier_name?></strong></span>
                      <span><strong><?php echo $purchase_data->supplier_address?></strong></span>

                    </span>
                  </div>
                  <div class="col-sm-4 col-md-4">
                    <div class="m-invoice__logo" style="padding-top: 1rem;">
                      <a href="#">
                        <h2>PURCHASE BILL <br/>#<?php echo $purchase_data->purchase_id ?></h2>

                      </a>
                    </div>
                    <?php if($purchase_data->bill_attachment!=''){?>
                      <a style="float: right; margin-bottom: 10px" target="_blank" href="<?php echo base_url().'uploads/bills/'.$purchase_data->bill_attachment?>" style="margin-left: 5px;margin-right: 5px" class="btn m-btn--gradient-from-info m-btn--gradient-to-focus  m-btn  m-btn--icon m-btn--air m-btn--pill">
                        <span>
                          <i class="fa fa-file-alt"></i>
                          <span>
                            View Bill Attachment
                          </span>
                        </span>
                      </a>
                    <?php } ?>
                  </div>
                </div>
                <div class="m-invoice__items" style="padding: 2rem 0 3rem 0;">
                  <div class="m-invoice__item">
                    <span class="m-invoice__subtitle">PURCHASED TO</span>
                    <span class="m-invoice__text"><strong><?php echo $purchase_data->location_name?></strong></span>
                  </div>
                  <div class="m-invoice__item" style="text-align: center">
                    <span class="m-invoice__subtitle">PURCHASE DATE</span>
                    <span class="m-invoice__text"><strong><?php echo date('d-m-Y',strtotime($purchase_data->purchase_date))?></strong></span>
                  </div>
                  <div class="m-invoice__item" style="text-align: right">
                    <span class="m-invoice__subtitle">BILL NO</span>
                    <span class="m-invoice__text"><strong><?php echo $purchase_data->bill_invoice_no?></strong></span>
                  </div>
                  <div class="m-invoice__item" style="text-align: right">
                    <span class="m-invoice__subtitle">VEHICLE NO</span>
                    <span class="m-invoice__text"><strong><?php echo $purchase_data->vehicle_no?></strong></span>
                  </div>
                  <div class="m-invoice__item" style="text-align: right">
                    <span class="m-invoice__subtitle">CREATED BY</span>
                    <span class="m-invoice__text"><strong><?php echo $purchase_data->user_alias?></strong></span>
                  </div>
                </div>
              </div>
            </div>
            <div class="m-invoice__body m-invoice__body--centered" style="min-height: 200px">
              <div class="table-responsive">
                <?php
                $rowspan="";
                if($this->config->item('Tax_tax_enabled')==1 && $this->config->item('Tax_purchase_tax_type')=='item_wise'){
                  $rowspan="rowspan='2'";
                }
                ?>

                <table class="table m-table table-bordered item_table">
                  <thead>
                    <tr>
                      <th <?php echo $rowspan ?>>Sl No</th>
                      <th <?php echo $rowspan ?> style="text-align: left">Material Name</th>
                      <th <?php echo $rowspan ?> >Item Code</th>
                      <th <?php echo $rowspan ?> >Qty</th>
                      <th <?php echo $rowspan ?> >Unit</th>
                      <th <?php echo $rowspan ?> >Unit Price</th>
                      <?php if($purchase_data->sales_invoice_id!=0){?>
                        <th <?php echo $rowspan ?> >Disc.</th>
                      <?php } ?>
                      <?php if($this->config->item('Tax_tax_enabled')==1 && $this->config->item('Tax_purchase_tax_type')=='item_wise'){ ?>
                        <th colspan="2" style="text-align:center"><?php if($this->config->item('Tax_tax_splitting')==1){ echo "Total ";}?><?php echo $this->config->item('Tax_tax_name')?></th>
                        <?php if($this->config->item('Tax_tax_splitting')==1){ ?>
                          <th colspan="2" style="text-align:center"><?php echo $this->config->item('Tax_tax1_name')?></th>
                          <th colspan="2" style="text-align:center"><?php echo $this->config->item('Tax_tax2_name')?></th>
                          <th colspan="2" style="text-align:center"><?php echo $this->config->item('Tax_tax3_name')?></th>
                        <?php } ?>
                      <?php } ?>
                      <th <?php echo $rowspan ?> >Total<br/>Amount</th>
                    </tr>
                    <?php if($this->config->item('Tax_tax_enabled')==1 && $this->config->item('Tax_purchase_tax_type')=='item_wise'){ ?>
                      <tr>
                        <th style="text-align:right">%</th>
                        <th>Amt</th>
                        <?php if($this->config->item('Tax_tax_splitting')==1){ ?>
                          <th>%</th>
                          <th>Amt</th>
                          <th>%</th>
                          <th>Amt</th>
                          <th>%</th>
                          <th>Amt</th>
                        <?php } ?>
                      </tr>
                    <?php } ?>
                  </thead>
                  <tbody>
                    <?php
                    $n = 1;
                    $description_colspan=6;
                    if($this->config->item('Tax_tax_enabled')==1 && $this->config->item('Tax_purchase_tax_type')=='item_wise'){
                      $description_colspan=14;
                    }
                    foreach($purchase_items as $row):
                      $row->tax1_amount = round($row->unit_price*$row->quantity*$row->tax1_percent/100,$this->config->item('Currency_amount_decimals_2'));
                      $row->tax2_amount = round($row->unit_price*$row->quantity*$row->tax2_percent/100,$this->config->item('Currency_amount_decimals_2'));
                      $row->tax3_amount = round($row->unit_price*$row->quantity*$row->tax3_percent/100,$this->config->item('Currency_amount_decimals_2'));
                      ?>
                      <tr>
                        <td><?php echo $n++?></td>
                        <td style="text-align: left"><?php echo $row->material_name?><br/><?php echo $row->item_code?></td>
                        <td><?php echo $row->item_code?></td>
                        <td style="white-space: nowrap;"><?php echo $row->quantity?></td>
                        <td style="white-space: nowrap;"><?php echo $row->unit_name?></td>
                        <td style="white-space: nowrap;"><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($row->unit_price,$this->config->item('Currency_currency_shortname'));?></td>
                        <?php if($purchase_data->sales_invoice_id!=0){
                          $description_colspan++;?>
                          <td style="white-space: nowrap;"><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($row->disc_amt,$this->config->item('Currency_currency_shortname'));?></td>
                        <?php } ?>
                        <?php if($this->config->item('Tax_tax_enabled')==1 && $this->config->item('Tax_purchase_tax_type')=='item_wise'){ ?>
                          <td style="white-space: nowrap;"><?php echo $row->tax_percentage?>%</td>
                          <td style="white-space: nowrap;"><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($row->tax_amount,$this->config->item('Currency_currency_shortname'));?></td>
                          <?php if($this->config->item('Tax_tax_splitting')==1){ ?>
                            <td style="white-space: nowrap;"><?php echo $row->tax1_percent?>%</td>
                            <td style="white-space: nowrap;"><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($row->tax1_amount,$this->config->item('Currency_currency_shortname'));?></td>
                            <td style="white-space: nowrap;"><?php echo $row->tax2_percent?>%</td>
                            <td style="white-space: nowrap;"><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($row->tax2_amount,$this->config->item('Currency_currency_shortname'));?></td>
                            <td style="white-space: nowrap;"><?php echo $row->tax3_percent?>%</td>
                            <td style="white-space: nowrap;"><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($row->tax3_amount,$this->config->item('Currency_currency_shortname'));?></td>
                          <?php }?>
                        <?php }?>
                        <td style="white-space: nowrap;"><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($row->total_amount,$this->config->item('Currency_currency_shortname'));?></td>
                      </tr>
                      <tr>
                        <td style="border-bottom: 1px solid #c5c5c5"></td>
                        <td colspan="<?php echo $description_colspan?>" style="text-align: left;font-weight: 300;border-bottom: 1px solid #c5c5c5">Description: <?php echo $row->description?></td>
                      </tr>
                      <?php
                    endforeach;
                    ?>
                  </tbody>
                </table>
              </div>
            </div>
            <div class="m-invoice__body m-invoice__body--centered">
              <div class="m-invoice__table  m-invoice__table--centered table-responsive">
                <table class="table">
                  <thead>
                    <tr>
                      <th>SUB TOTAL</th>
                      <?php if($purchase_data->sales_invoice_id==0){?>
                        <th>DISCOUNT AMT</th>
                      <?php } ?>
                      <th><?php if($this->config->item('Tax_tax_splitting')==1){ echo "Total ";}?><?php echo $this->config->item('Tax_tax_name');?> AMT</th>
                      <th>OTHER CHARGES</th>
                      <th>TDS AMT</th>
                      <th>ROUND AMT</th>
                      <th>NET TOTAL</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr>
                      <td><strong><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($purchase_data->bill_total_amount,$this->config->item('Currency_currency_shortname'));?></strong></td>
                      <?php if($purchase_data->sales_invoice_id==0){?>
                        <td><strong><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($purchase_data->bill_discount_amount,$this->config->item('Currency_currency_shortname'));?></strong></td>
                      <?php } ?>
                      <td><strong><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($purchase_data->bill_tax_amount,$this->config->item('Currency_currency_shortname'));?></strong></td>
                      <td><strong><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($purchase_data->bill_other_amount,$this->config->item('Currency_currency_shortname'));?></strong></td>
                      <td><strong><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($purchase_data->bill_tds_amount,$this->config->item('Currency_currency_shortname'));?></strong></td>
                      <td><strong><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($purchase_data->bill_round_amount,$this->config->item('Currency_currency_shortname'));?></strong></td>
                      <td class="m--font-danger"><strong><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($purchase_data->bill_payable_amount,$this->config->item('Currency_currency_shortname'));?></strong></td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </div>
            <div class="" style="width: 95%;margin: 0 auto;padding: 2rem 0 0 0;">

              <div class="" style="margin-bottom: 20px">
                <?php if(sizeof($purchase_payments)>0 || sizeof($advance_return_payments)>0){?>
                  <table id=""  class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" width="100%">
                    <caption style="caption-side: top;text-align:left"><strong>Purchase Bill - Supplier Payments</strong></caption>
                    <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>
                      </tr>
                    </thead>
                    <tbody style="font-weight: 600;font-size: 1.1rem;">
                      <?php
                      $sl_no=0;
                      foreach($purchase_payments as $row):
                        $sl_no++;
                        if($row->tr_payment_part==1){
                          $payment_part = 'Initial Payment';
                        }elseif($row->tr_payment_part==0){
                          $payment_part = 'Advance Payment<br/><span style="font-size: 12px;">(Purchase Order Payment)</span>';
                        }else{
                          $payment_part = 'Down Payment';
                        }
                        ?>
                        <tr>
                          <td><?php echo $sl_no?></td>
                          <td><?php echo date('d-m-Y',strtotime($row->tr_date))?></td>
                          <td><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($row->tr_amount,$this->config->item('Currency_currency_shortname'));?></td>
                          <td><?php echo $row->debit_account?></td>
                          <!-- <td><?php //echo $payment_part?></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>
                        </tr>
                        <?php
                      endforeach;
                      foreach($advance_return_payments as $row):
                        $sl_no++;
                        ?>
                        <tr>
                          <td><?php echo $sl_no?></td>
                          <td></td>
                          <td><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($row->tr_amount,$this->config->item('Currency_currency_shortname'));?></td>
                          <td></td>
                          <!-- <td><?php //echo $payment_part?></td> -->
                          <td></td>
                          <td></td>
                          <td></td>
                          <td>Debited From Supplier Advance</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>
                        </tr>
                        <?php
                      endforeach;
                      ?>
                    </tbody>
                  </table>
                <?php } ?>
                <?php if(sizeof($other_charges)>0){?>
                  <table id="" class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" width="100%">
                    <caption style="caption-side: top;text-align:left"><strong>Other Charges Payments</strong></caption>
                    <thead style="font-weight: 500;font-size: 1.1rem;">
                      <tr>
                        <th>Sl No</th>
                        <th>Head</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>
                      </tr>
                    </thead>
                    <tbody style="font-weight: 600;font-size: 1.1rem;">
                      <?php
                      $sl_no=0;
                      foreach($other_charges as $row):
                        $sl_no++;
                        ?>
                        <tr>
                          <td><?php echo $sl_no?></td>
                          <td><?php echo $row->credit_account?></td>
                          <td><?php echo date('d-m-Y',strtotime($row->tr_date))?></td>
                          <td><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($row->tr_amount,$this->config->item('Currency_currency_shortname'));?></td>
                          <td><?php echo $row->debit_account?></td>
                          <!-- <td><?php //echo $payment_part?></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>
                        </tr>
                        <?php
                      endforeach;
                      ?>
                    </tbody>
                  </table>
                <?php } ?>
              </div>
              <div class="m-invoice__table  m-invoice__table--centered table-responsive" style="margin-bottom: 100px">
                <table class="table">
                  <thead>
                    <tr>
                      <th width="40%">PAYMENT STATUS :
                        <label class="m--font-danger">
                          <strong>
                            <?php
                            if($purchase_data->payment_status == 1){
                              echo "PAID";
                            }elseif($purchase_data->balance_amount>0 && $purchase_data->total_paid>0) {
                              echo "PARTIALLY PAID";
                            }else {
                              echo "NOT PAID";
                            }
                            ?></strong>
                          </label>
                        </th>
                        <th width="30%" style="vertical-align: top">Total Paid : <?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($purchase_data->total_paid,$this->config->item('Currency_currency_shortname'));?></th>
                        <th width="30%" style="vertical-align: top;text-align:right">Balance :
                          <strong class="m--font-danger" >
                            <?php
                            echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($purchase_data->balance_amount,$this->config->item('Currency_currency_shortname'));
                            ?>
                          </strong>
                        </th>
                      </tr>
                      <tr>
                        <th >Remarks : <?php echo $purchase_data->remarks;?>
                        </th>
                        <th colspan="2">
                          <?php
                          if($this->config->item('Purchase_delivery_challan') == 1 && $purchase_data->delivery_challan_id != 0){
                            echo "Purchase Bill Created From Delivery Challan #".$purchase_data->delivery_challan_id."   -||-    ";
                          }?>
                          <?php
                          if($purchase_data->purchase_order_id != 0){
                            echo "Purchase Bill Created From Purchase Order #".$purchase_data->purchase_order_id;
                          }?>

                        </th>
                      </tr>
                    </thead>

                  </table>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <?php $this->view("modules/include_modals/modal_bills");?>
    </div>
  </div>
</div>

<!-- 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");

$("#purchase_menu").addClass('m-menu__item--active m-menu__item--open');
$("#purchase_menu_2").addClass('m-menu__item--active');
$("#page_title").text("Purchase Bill - #<?php echo $purchase_data->purchase_id.' ['.$purchase_data->supplier_name.'] ['.$purchase_data->location_name.']'?>");

</script>
<script>
$('#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
});
$('#other_charges_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>
