<?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: #404040;
}
.item_table td{
  padding: .75rem !important;
}
.item_table th{
  white-space: nowrap;
  padding: .75rem !important;
}
.table thead th {
  border: 0px !important;
}
.table thead th {
  border: 0px !important;
}
.table tbody td {
  border: 0px !important;
}
.payment-table tbody td{
  border: 0px !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: 90%;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container.m-invoice__container--centered {
  width: 90%;
}
</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: 0px !important;
  }
  .m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container.m-invoice__container--centered {
    width: 97%;
  }
  .m-invoice-2 .m-invoice__wrapper .m-invoice__body.m-invoice__body--centered {
    width: 97%;
  }
  .m-invoice-2 .m-invoice__wrapper .m-invoice__body.m-invoice__body--centered {
    margin-left: 10px !important;
  }

  #print_view {
    margin-top: -25%;
  }
  #print, .print_hide_div
  {
    display: none !important;
    height: 0px !important;
    padding: 0px !important;
    margin: 0px !important;
  }
  body * {
    visibility: hidden;
  }
  .m-portlet__body * {
    visibility: visible;
    overflow: visible !important;
  }
  .letter_head_img{
    display: block !important;
  }
  body.m-content--skin-light2 {
    background-color: white !important;
  }
  .m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container.m-invoice__container--centered {
    width: 97% !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%;
}
.col-sm-5 {
  -webkit-box-flex: 0;
  -ms-flex: 0 0 41.66667%;
  flex: 0 0 41.66667%;
  max-width: 41.66667%;
}
.col-sm-7 {
  -webkit-box-flex: 0;
  -ms-flex: 0 0 58.3333%;
  flex: 0 0 58.3333%;
  max-width: 58.3333%;
}
.table th, .table td {
  padding: 0.25rem !important;
}

@media print {
.page-header, .page_table .page-header-space {
  height: 100px;
}
.page-footer, .page-footer-space {
  height: 120px;
}
.page-footer {
  position: fixed;
  bottom: 0;
  width: 100%;
}
.page-header {
  position: fixed;
  top: 0mm;
  width: 100%;
}
.page {
  page-break-after: always;
}
@page {
  margin: 20mm;
  size: A4;
}

  thead {display: table-header-group;}
  tfoot {display: table-footer-group;}
  button {display: none;}
  body {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">
          Purchase Order 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().'purchase_order' ?>" class="m-nav__link">
              <span class="m-nav__link-text">
                Purchase Order 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_purchase_order_approval')==1){
            if($this->session->userdata('user_role') == 'project_manager' && $order_data->approval_status_2==0){ ?>
              <a style="margin-left: 5px;margin-right: 5px"  data-approval-status="<?php echo $order_data->approval_status_1?>" data-approval-level="1" id="btn_approve_order" data-toggle="modal"  href="#purchase_order_approve_modal" 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="la la-check-circle"></i> Approve / <i class="la la-times-circle"></i> Reject
                </span>
              </a>
            <?php }
            if($this->session->userdata('user_role') == 'general_manager' && $order_data->approval_status_1==1){ ?>
              <a style="margin-left: 5px;margin-right: 5px"  data-approval-status="<?php echo $order_data->approval_status_2?>" data-approval-level="2" id="btn_approve_order" data-toggle="modal"  href="#purchase_order_approve_modal" 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="la la-check-circle"></i> Approve / <i class="la la-times-circle"></i> Reject
                </span>
              </a>
            <?php }
            ?>
          <?php } ?>
          <?php
          if($order_data->request_id != 0){?>
            <a href="<?php echo base_url().'purchase_request/profile/'.$order_data->request_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 Request of This Order
                </span>
              </span>
            </a>
          <?php } ?>
          <?php
          if($this->config->item('Purchase_delivery_challan') == 1){?>
            <a href="<?php echo base_url().'purchases/delivery_challan/add?order_id='.$order_data->order_id?>" style="margin-left: 5px;margin-right: 5px" class="btn m-btn--gradient-from-warning m-btn--gradient-to-success  m-btn  m-btn--icon m-btn--air m-btn--pill">
              <span>
                <i class="fa fa-plus-circle"></i>
                <span>
                  Create Delivery Challan
                </span>
              </span>
            </a>
          <?php } ?>
          <?php if($this->session->userdata('user_role') != 'auditor' || $this->session->userdata('user_data_permission')['adding']==1) { ?>
            <?php if($this->config->item('Purchase_delivery_challan') !=1 && $order_data->entry_approval_status==1){ ?>
              <a href="<?php echo base_url().'purchases/add?order_id='.$order_data->order_id?>" style="margin-left: 5px;margin-right: 5px" class="btn m-btn--gradient-from-info m-btn--gradient-to-success  m-btn  m-btn--icon m-btn--air m-btn--pill">
                <span>
                  <i class="fa fa-plus-circle"></i>
                  <span>
                    Create Purchase Bill
                  </span>
                </span>
              </a>
            <?php } ?>
            <a style="margin-left: 5px;margin-right: 5px" data-bill-type="purchase_order" data-bill-id="<?php echo $order_data->order_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 if($this->session->userdata('user_id')==$order_data->order_created_by){?>
            <a href="<?php echo base_url().'purchase_order/edit/'.$order_data->order_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 Order
                </span>
              </span>
            </a>
          <?php } ?>
          <?php if($order_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 Order
                </span>
              </span>
            </a>
          <?php } ?>
        </div>
      </div>
      <div class="m-portlet__body m-portlet__body--no-padding" id="print_view">
        <div class="page-header" style="text-align: center">
          <?php if($this->config->item('company_letter_head')!=''){ ?>
            <img class="letter_head_img" style="width:100%" src="<?php echo base_url().'uploads/company/'.$this->config->item('company_letter_head')?>" />
          <?php } ?>
        </div>
        <div class="page-footer">
          <?php if($this->config->item('purchase_order_footer')!=''){ ?>
            <img class="letter_head_img" style="width: 100%;" src="<?php echo base_url().'uploads/company/'.$this->config->item('purchase_order_footer')?>" />
          <?php } ?>
        </div>
        <table class="page_table" style="width:100%">
          <thead>
            <tr>
              <td>
                <!--place holder for the fixed-position header-->
                <div class="page-header-space"></div>
              </td>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>
                <div class="page" style="">
                  <h4 style="text-align:center">LOCAL PURCHASE ORDER</h4>
                  <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: 0rem;">
                            <a href="#"></a>
                          </div>
                          <div class="row">
                            <div class="col-xs-7 col-sm-7 col-md-7" >
                              <span class="m-invoice__desc" style="text-align: left;padding: 1rem 0 1rem 0 !important;">
                                <span class="m-invoice__subtitle"><h5><strong>To/Supplier:</strong></h5></span>
                                <span><strong><?php echo $order_data->supplier_name?></strong></span>
                                <span><strong><?php echo $order_data->supplier_address?></strong></span>
                                <span><strong><?php if($order_data->supplier_phone!=''){ echo "Phone: ".$order_data->supplier_phone;} ?></strong></span>
                                  <span><strong><?php if($order_data->supplier_email!=''){ echo "Email: ".$order_data->supplier_email;} ?></strong></span>
                                    <span><strong><?php if($order_data->supplier_tax_no!=''){ echo "TRN No: ".$order_data->supplier_tax_no;}?></strong></span>
                                    </span>
                                  </div>
                                  <div class="col-xs-5 col-sm-5 col-md-5 ">
                                    <span class="m-invoice__desc" style="text-align: left;padding: 1rem 0 1rem 0 !important;">
                                      <span class="m-invoice__subtitle">
                                        <table style="font-weight:700">
                                          <tr>
                                            <td >LPO No</td>
                                            <td>:</td>
                                            <td>&nbsp;<?php echo $order_data->reference_no."/".$order_data->order_id; ?></td>
                                          </tr>
                                          <tr>
                                            <td>Date</td>
                                            <td>:</td>
                                            <td>&nbsp;<?php echo date('d-m-Y',strtotime($order_data->order_date)); ?></td>
                                          </tr>

                                          <tr>
                                            <td>Service</td>
                                            <td>:</td>
                                            <td>&nbsp;<?php echo $order_data->service?></td>
                                          </tr>
                                          <tr>
                                            <td>TRN</td>
                                            <td>:</td>
                                            <td>&nbsp;</td>
                                          </tr>
                                        </table>
                                      </span>
                                      <?php if($order_data->order_attachment!=''){?>
                                        <a style="float: right; margin-bottom: 10px" target="_blank" href="<?php echo base_url().'uploads/bills/'.$order_data->order_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 class="col-xs-12 col-sm-12 col-md-12" >
                                      <table style="font-weight:700">
                                        <tr>
                                          <td>Project</td>
                                          <td>:</td>
                                          <td>&nbsp;<?php echo $order_data->location_name; ?></td>
                                        </tr>
                                      </table>
                                    </div>
                                  </div>
                                </div>
                              </div>
                              <div class="m-invoice__body m-invoice__body--centered" style="padding-top:0px !important">
                                <div class="table-responsive">
                                  <table class="table m-table table-bordered item_table">
                                    <thead>
                                      <tr>
                                        <?php
                                        $tax_splitting = 0;
                                        foreach($order_items as $row){
                                          if($row->tax1_percent!=0 || $row->tax2_percent!=0 || $row->tax3_percent!=0){
                                            $tax_splitting = 1;
                                          }
                                        }

                                        if($this->config->item('Tax_tax_enabled')==1 && $this->config->item('Tax_tax_splitting')==1 && $this->config->item('Tax_purchase_tax_type')=='item_wise'  && $this->config->item('Purchase_order_tax_enabled')==1){
                                          $rowspan="rowspan='2'";
                                        }else{
                                          $rowspan="";
                                        } ?>
                                        <th <?php echo $rowspan ?>>SNo</th>
                                        <th <?php echo $rowspan ?> style="text-align: left">Description</th>
                                        <th <?php echo $rowspan ?> >Unit</th>
                                        <th <?php echo $rowspan ?> >Unit Price</th>
                                        <th style="text-align: center" <?php echo $rowspan ?> >Qty</th>
                                        <?php if($this->config->item('Tax_tax_enabled')==1 && $this->config->item('Tax_tax_splitting')==1 && $this->config->item('Tax_purchase_tax_type')=='item_wise'  && $this->config->item('Purchase_order_tax_enabled')==1){ ?>
                                          <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($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 Amount</th>
                                      </tr>
                                      <tr>
                                        <?php if($this->config->item('Tax_tax_enabled')==1 && $this->config->item('Tax_tax_splitting')==1 && $this->config->item('Tax_purchase_tax_type')=='item_wise'  && $this->config->item('Purchase_order_tax_enabled')==1){ ?>
                                          <th>%</th>
                                          <th>Amt</th>
                                          <?php if($tax_splitting==1){ ?>
                                            <th>%</th>
                                            <th>Amt</th>
                                            <th>%</th>
                                            <th>Amt</th>
                                            <th>%</th>
                                            <th>Amt</th>
                                          <?php } ?>
                                        <?php } ?>
                                      </tr>
                                    </thead>
                                    <tbody>
                                      <?php
                                      $n = 1;
                                      $description_colspan=7;
                                      if($this->config->item('Tax_tax_enabled')==1 && $this->config->item('Tax_purchase_tax_type')=='item_wise' && $this->config->item('Purchase_order_tax_enabled')==1){
                                        $description_colspan=15;
                                      }
                                      if ($this->config->item('Purchase_delivery_challan') == 1) {
                                        $description_colspan++;
                                      }
                                      foreach($order_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->unit_name?></td>
                                          <td style="white-space:nowrap"><?php echo $this->config->item('currency_format')->formatCurrency($row->unit_price,$this->config->item('Currency_currency_shortname'));?></td>
                                          <td><?php echo $row->quantity?></td>
                                          <?php if($this->config->item('Tax_tax_enabled')==1 && $this->config->item('Tax_tax_splitting')==1 && $this->config->item('Tax_purchase_tax_type')=='item_wise' && $this->config->item('Purchase_order_tax_enabled')==1){ ?>
                                            <td><?php echo $row->tax_percentage?>%</td>
                                            <td style="white-space:nowrap"><?php echo $this->config->item('currency_format')->formatCurrency($row->tax_amount,$this->config->item('Currency_currency_shortname'));?></td>
                                            <?php if($tax_splitting==1){ ?>
                                              <td><?php echo $row->tax1_percent?>%</td>
                                              <td style="white-space:nowrap"><?php echo $this->config->item('currency_format')->formatCurrency($row->tax1_amount,$this->config->item('Currency_currency_shortname'));?></td>
                                              <td><?php echo $row->tax2_percent?>%</td>
                                              <td style="white-space:nowrap"><?php echo $this->config->item('currency_format')->formatCurrency($row->tax2_amount,$this->config->item('Currency_currency_shortname'));?></td>
                                              <td><?php echo $row->tax3_percent?>%</td>
                                              <td style="white-space:nowrap"><?php echo $this->config->item('currency_format')->formatCurrency($row->tax3_amount,$this->config->item('Currency_currency_shortname'));?></td>
                                            <?php }?>
                                          <?php }?>
                                          <td><?php echo $this->config->item('currency_format')->formatCurrency($row->total_amount,$this->config->item('Currency_currency_shortname'));?></td>
                                        </tr>

                                        <?php
                                      endforeach;
                                      ?>
                                    </tbody>
                                  </table>
                                </div>
                              </div>
                              <div class="m-invoice__body m-invoice__body--centered" style="padding-top:0px !important">
                                <div class="row">
                                  <div class="col-sm-8 col-md-8 col-lg-8">
                                    <br/><br/><br/><br/>
                                    <table class="table m-table">
                                      <thead>
                                        <tr>
                                          <th style="text-align:center">
                                            <h5><strong>Total In Words : <?php echo strtoupper($order_data->total_amount_in_words)?></strong></h5>
                                          </th>
                                        </tr>
                                      </thead>
                                    </table>
                                  </div>
                                  <div class="col-sm-4 col-md-4 col-lg-4">
                                    <table class="table item_table">
                                      <thead>
                                        <tr>
                                          <th>TOTAL TAXABLE AMOUNT</th>
                                          <th><strong><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($order_data->taxable_amount,$this->config->item('Currency_currency_shortname'));?></strong></th>
                                        </tr>
                                        <tr>
                                          <th>TOTAL <?php echo $this->config->item('Tax_tax_name')?> AMOUNT</th>
                                          <th><strong><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($order_data->tax_amount,$this->config->item('Currency_currency_shortname'));?></strong></th>
                                        </tr>
                                        <tr>
                                          <th>GRAND TOTAL AMOUNT</th>
                                          <th><strong><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($order_data->total_est_amount,$this->config->item('Currency_currency_shortname'));?></strong></th>
                                        </tr>
                                      </thead>
                                    </table>
                                  </div>
                                </div>
                                <div class="m-invoice__table  m-invoice__table--centered table-responsive">
                                  <div class="row">
                                    <div class="col-sm-8 col-md-8">
                                      <table class="table m-table">
                                        <thead>
                                          <tr>
                                            <td style="border:0px !important">Required By</td>
                                            <td style="border:0px !important">:</td>
                                            <td style="border:0px !important">&nbsp;<?php echo $order_data->requiredby?></td>
                                          </tr>
                                          <tr>
                                            <td style="border:0px !important">Site Address</td>
                                            <td style="border:0px !important">:</td>
                                            <td style="border:0px !important">&nbsp;<?php echo $order_data->work_location?></td>
                                          </tr>
                                          <tr>
                                            <td style="border:0px !important">Delivery Mode</td>
                                            <td style="border:0px !important">:</td>
                                            <td style="border:0px !important">&nbsp;<?php echo $order_data->delivery_mode?></td>
                                          </tr>
                                          <tr>
                                            <td style="border:0px !important">Payment Terms</td>
                                            <td style="border:0px !important">:</td>
                                            <td style="border:0px !important">&nbsp;<?php echo $order_data->payment_terms?></td>
                                          </tr>
                                          <tr>
                                            <td style="border:0px !important">Remarks</td>
                                            <td style="border:0px !important">:</td>
                                            <td style="border:0px !important">&nbsp;<?php echo $order_data->remarks?></td>
                                          </tr>
                                          <tr>
                                            <td style="border:0px !important">Contact Person</td>
                                            <td style="border:0px !important">:</td>
                                            <td style="border:0px !important">&nbsp;<strong><?php echo $order_data->contact_person_name?><br/><?php echo $order_data->contact_person_phone?></strong></td>
                                          </tr>
                                        </thead>
                                      </table>
                                    </div>
                                  </div>
                                  <h6 style="text-align:center">This is computer generated LPO, hence no signature required</h6>
                                  <table class="table m-table  item_table print_hide_div">
                                    <thead>
                                      <tr>
                                        <th style="text-align:center">Prepared By</th>
                                        <th style="text-align:center">Approved By</th>
                                        <th style="text-align:center">Authorised Signature</th>
                                      </tr>
                                    </thead>
                                    <tbody>
                                      <?php if($this->config->item('Purchase_purchase_order_approval')==1){ ?>
                                        <tr>
                                          <td>
                                            <span class='m-badge m-badge--info m-badge--wide'><i class='fa fa-check-circle'></i> Created By <?php echo $order_data->order_created_user;
                                            if ($this->config->item('UI_hide_created_date_field')==0){echo " On ".date('d-m-Y',strtotime($order_data->order_created_date));}else{echo '';} ?></span>
                                          </td>
                                          <td>
                                            <?php if($order_data->approval_status_1==1){ ?>
                                              <span class='m-badge m-badge--success m-badge--wide'><i class='fa fa-check-circle'></i> Approved By <?php echo $order_data->approved_1_user." On ".date('d-m-Y',strtotime($order_data->approved_date_1)); ?></span>
                                            <?php }elseif($order_data->approval_status_1==2){ ?>
                                              <span class='m-badge m-badge--danger m-badge--wide'><i class='fa fa-times-circle'></i> Rejected By <?php echo $order_data->approved_1_user." On ".date('d-m-Y',strtotime($order_data->approved_date_1)); ?></span>
                                            <?php }else{ ?>
                                              <span class='m-badge m-badge--warning m-badge--wide'><i class='fa fa-times-circle'></i> Pending</span>
                                            <?php } ?>
                                          </td>
                                          <td>
                                            <?php if($order_data->approval_status_2==1){ ?>
                                              <span class='m-badge m-badge--success m-badge--wide'><i class='fa fa-check-circle'></i> Approved By <?php echo $order_data->approved_2_user." On ".date('d-m-Y',strtotime($order_data->approved_date_2)); ?></span>
                                            <?php }elseif($order_data->approval_status_2==2){ ?>
                                              <span class='m-badge m-badge--danger m-badge--wide'><i class='fa fa-times-circle'></i> Rejected By <?php echo $order_data->approved_2_user." On ".date('d-m-Y',strtotime($order_data->approved_date_2)); ?></span>
                                            <?php }else{ ?>
                                              <span class='m-badge m-badge--warning m-badge--wide'><i class='fa fa-times-circle'></i> Pending</span>
                                            <?php } ?>
                                          </td>
                                        </tr>
                                      <?php }else{ ?>
                                        <tr>
                                          <td>&nbsp;<br/>&nbsp;</td>
                                          <td>&nbsp;<br/>&nbsp;</td>
                                          <td>&nbsp;<br/>&nbsp;</td>
                                        </tr>
                                      <?php } ?>
                                    </tbody>
                                  </table>
                                </div>
                              </div>

                              <div class="m-invoice__body m-invoice__body--centered print_hide_div">
                                <?php if(sizeof($order_payments)>0){?>
                                  <div class="" style="margin-bottom: 20px">
                                    <table id="" 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>
                                        </tr>
                                      </thead>
                                      <tbody style="font-weight: 600;font-size: 1.1rem;">
                                        <?php
                                        $sl_no=0;
                                        foreach($order_payments as $row):
                                          $sl_no++;
                                          $payment_part = 'Advance Payment';
                                          if($row->tr_amount!=0){
                                            ?>
                                            <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 $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;
                                        if(!empty($purchase_bill_payments)) {
                                          foreach($purchase_bill_payments as $row):
                                            $sl_no++;
                                            ?>
                                            <tr>
                                              <td><?php echo $sl_no?></td>
                                              <!-- <td><?php echo '#'.$row->reference_id?></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>
                                            </tr>
                                            <?php
                                          endforeach;
                                        }
                                        if(!empty($advance_return_payments)) {
                                          foreach($advance_return_payments as $row):
                                            $sl_no++;
                                            ?>
                                            <tr>
                                              <td><?php echo $sl_no?></td>
                                              <td></td>
                                              <td><?php echo $row->tr_amount?></td>
                                              <td></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>
                                  </div>
                                <?php } ?>
                                <div class="m-invoice__table  m-invoice__table--centered table-responsive print_hide_div" style="margin-bottom: 20px">
                                  <table class="table item_table">
                                    <thead>
                                      <?php if($this->config->item('Purchase_purchase_order_approval')==1){ ?>
                                        <tr>
                                          <th width="50%">
                                            Approval 1 :
                                            <?php if($order_data->approval_status_1==1){ ?>
                                              <span class='m-badge m-badge--success m-badge--wide'><i class='fa fa-check-circle'></i> Approved By <?php echo $order_data->approved_1_user." On ".date('d-m-Y',strtotime($order_data->approved_date_1)); ?></span>
                                            <?php }elseif($order_data->approval_status_1==2){ ?>
                                              <span class='m-badge m-badge--danger m-badge--wide'><i class='fa fa-times-circle'></i> Rejected By <?php echo $order_data->approved_1_user." On ".date('d-m-Y',strtotime($order_data->approved_date_1)); ?></span>
                                            <?php }else{ ?>
                                              <span class='m-badge m-badge--warning m-badge--wide'><i class='fa fa-times-circle'></i> Pending</span>
                                            <?php } ?>
                                          </th>
                                          <th width="40%">
                                            Approval 2 :
                                            <?php if($order_data->approval_status_2==1){ ?>
                                              <span class='m-badge m-badge--success m-badge--wide'><i class='fa fa-check-circle'></i> Approved By <?php echo $order_data->approved_2_user." On ".date('d-m-Y',strtotime($order_data->approved_date_2)); ?></span>
                                            <?php }elseif($order_data->approval_status_2==2){ ?>
                                              <span class='m-badge m-badge--danger m-badge--wide'><i class='fa fa-times-circle'></i> Rejected By <?php echo $order_data->approved_2_user." On ".date('d-m-Y',strtotime($order_data->approved_date_2)); ?></span>
                                            <?php }else{ ?>
                                              <span class='m-badge m-badge--warning m-badge--wide'><i class='fa fa-times-circle'></i> Pending</span>
                                            <?php } ?>
                                          </th>
                                        </tr>
                                      <?php } ?>
                                      <?php if ($this->config->item('Purchase_delivery_challan') == 1) { ?>
                                        <tr>
                                          <th width="60%">
                                          </th>
                                          <th width="40%">
                                            Delivery Challan Status :
                                            <?php if(sizeof($delivery_challan)>0){
                                              $no_of_delivery_challan = sizeof($delivery_challan); ?>
                                              <span class='m-badge m-badge--success m-badge--wide'><i class='fa fa-check-circle'></i> <?= $no_of_delivery_challan?> Delivery Challans Created</span>
                                              <?php
                                              foreach ($delivery_challan as $key => $value) { ?>
                                                <div style="margin-top:10px !important">
                                                  <a target="_blank" href="<?php echo base_url().'purchases/delivery_challan/view/'.$value->challan_id ?>"><span class='m-badge m-badge--focus m-badge--wide'><i class='fa fa-check-circle'></i>  View Challan #<?= $value->challan_id?></span></a><br/>
                                                </div>
                                              <?php } ?>
                                            <?php }else{?>
                                              <span class='m-badge m-badge--danger m-badge--wide'><i class='fa fa-times-circle'></i> Delivery Challan Not Created</span>
                                            <?php } ?>
                                          </th>
                                        </tr>
                                      <?php } ?>
                                      <tr>
                                        <th width="60%">Remarks : <?php echo $order_data->remarks;?>
                                        </th>
                                        <th width="40%">
                                          Purchase Bill Status :
                                          <?php if($order_data->purchase_bill_id!=0){ $no_of_bills = sizeof(explode(',',$order_data->purchase_bill_id)); ?>
                                          <span class='m-badge m-badge--success m-badge--wide'><i class='fa fa-check-circle'></i> <?= $no_of_bills?> Bill Created</span>
                                        <?php }else{?>
                                          <span class='m-badge m-badge--danger m-badge--wide'><i class='fa fa-times-circle'></i> Bill Not Created</span>
                                        <?php } ?>
                                      </th>
                                    </tr>
                                    <?php
                                    if($order_data->request_id != 0){ ?>
                                      <tr>
                                        <th>
                                          <?php echo "Purchase Order Created From Purchase Request #".$order_data->request_id; ?>
                                        </th>
                                        <th>
                                          <?php if($order_data->purchase_bill_id!=0){ $no_of_bills = sizeof(explode(',',$order_data->purchase_bill_id));
                                            foreach (explode(',',$order_data->purchase_bill_id) as $key => $value) { ?>
                                              <div style="margin-top:10px !important">
                                                <a target="_blank" href="<?php echo base_url().'purchases/profile/'.$value ?>"><span class='m-badge m-badge--focus m-badge--wide'><i class='fa fa-check-circle'></i>  View Bill #<?= $value?></span></a><br/>
                                              </div>
                                            <?php } ?>
                                          <?php } ?>
                                        </th>
                                      </tr>
                                    <?php } ?>
                                  </thead>
                                </table>
                              </div>
                              <!-- Bills created -->
                            </div>
                            <?php
                            $terms = unserialize($order_data->terms_and_conditions);
                            if($terms!='' && $terms!=null) {?>
                              <div style="background: white;border: 4px solid #f7f7fa;padding: 20px;margin: 0px;padding-bottom: 0px">
                                <div class="m-section" style="margin: 0px 0 10px 0;">
                                  <h3 class="m-section__heading" style="padding: 0px;margin: 0px;padding-bottom: 15px">Terms & Conditions</h3>
                                  <table class="table table-striped m-table">
                                    <thead>
                                      <tr>
                                        <th>Sl No</th>
                                        <th>Title </th>
                                        <th>Description</th>
                                      </tr>
                                    </thead>
                                    <tbody>
                                      <?php
                                      $count = sizeof($terms);
                                      $i = 1;
                                      foreach ($terms as $key => $value5) { ?>
                                        <tr>
                                          <td><?php echo $i ?></td>
                                          <td><?php echo $value5['title'] ?></td>
                                          <td><?php echo $value5['description'] ?></td>
                                        </tr>
                                        <?php $i++;
                                      }
                                      ?>
                                    </tbody>
                                  </table>
                                </div>
                              </div>
                            <?php }?>
                          </div>
                        </div>
                        <?php if($this->config->item('purchase_order_bottom')!=''){ ?>
                          <img class="letter_head_img" style="width: 100%;" src="<?php echo base_url().'uploads/company/'.$this->config->item('purchase_order_bottom')?>" />
                        <?php } ?>
                      </div>
                    </td>
                  </tr>
                </tbody>
                <tfoot>
                  <tr>
                    <td>
                      <!--place holder for the fixed-position footer-->
                      <div class="page-footer-space"></div>
                    </td>
                  </tr>
                </tfoot>
              </table>

            </div>
          </div>
          <?php $this->view("modules/include_modals/modal_bills");?>
          <?php if($this->config->item('Purchase_purchase_order_approval')==1){ ?>
            <div class="modal fade" tabindex="-1" id="purchase_order_approve_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
              <div class="modal-dialog " role="document">
                <div class="modal-content" >
                  <div class="modal-header" style="background-color: #36a3f7;border-radius: 4px">
                    <h5 class="modal-title" id="exampleModalLabel" style="color: #ffffff" >
                      Approve Purchase Order
                    </h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                      <span aria-hidden="true">
                        &times;
                      </span>
                    </button>
                  </div>
                  <form data-form-type="purchase_order_approve_status" data-modal-id="purchase_order_approve_modal" autocomplete="off" id="edit_purchase_order_approve_form" method="post" action="<?php echo base_url().'purchase_order/approve_order'?>" enctype="multipart/form-data" class="m-form m-form--fit m-form--state m-form--label-align-right " >
                    <div class="modal-body">
                      <div class="m-form__content">
                        <div class="m-alert m-alert--icon alert alert-warning m--hide" role="alert" id="form_material_add_msg">
                          <div class="m-alert__icon">
                            <i class="la la-warning"></i>
                          </div>
                          <div class="m-alert__text">
                            Oh snap! Change a few things up and try submitting again.
                          </div>
                          <div class="m-alert__close">
                            <button type="button" class="close" data-close="alert" aria-label="Close"></button>
                          </div>
                        </div>
                      </div>
                      <input type="hidden" name="order_id" value="<?php echo $order_data->order_id?>">
                      <input type="hidden" name="approval_level" id="approval_level">
                      <div class="row">
                        <div class="col-lg-12">
                          <div class="form-group m-form__group" >
                            <div class="m-radio-inline" style="margin-top: 10px;">
                              <label class="m-radio m-radio m-radio--solid m-radio--state-success">
                                <input required type="radio" name="approve_status"  value="1" checked>
                                Approved
                                <span></span>
                              </label>
                              <label class="m-radio m-radio m-radio--solid m-radio--state-danger">
                                <input type="radio" name="approve_status"  value="2">
                                Rejected
                                <span></span>
                              </label>
                            </div>
                            <span class="m-form__help"></span>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="modal-footer">
                      <button type="button" class="btn btn-secondary" data-dismiss="modal">
                        Close
                      </button>
                      <button type="submit" class="btn btn-primary form_submit_btn">
                        Submit
                      </button>
                    </div>
                  </form>
                </div>
              </div>
            </div>
          <?php } ?>
        </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_order_menu").addClass('m-menu__item--active m-menu__item--open');
    $("#purchase_order_menu_2").addClass('m-menu__item--active');
    $("#page_title").text("Purchase Order - #<?php echo $order_data->order_id.' ['.$order_data->supplier_name.'] ['.$order_data->work_name.']'?>");
    </script>

    <script>

    $('body').on('click', '#btn_approve_order', function() {
      var no = $(this).closest('tr').children('td');
      var approval_level = $(this).data('approval-level');
      $("#approval_level").val(approval_level);
      var approval_status = $(this).data('approval-status');
      if(approval_status!=0){
        $('input[type=radio][name=approve_status][value='+approval_status+']').prop('checked',true);
      }else{
        $('input[type=radio][name=approve_status]').prop('checked',false);
      }
    });

    $('#btn_print_order').on("click", function(e) {
      var id="<?php echo $order_data->order_id ?>";
      window.open('<?php echo base_url().'purchase_order/print/' ?>'+id,'newwindow','width='+screen.width+',height='+screen.height);
      return false
    });

    $('#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: {
          "paid_amount": {
            required: !0,
            min: 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);
            $("#"+modal_id).modal('toggle');
            toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
            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>
