<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Purchase Order - #<?php echo $order_data->order_id.' ['.$order_data->supplier_name.'] ['.$order_data->work_name.']'?></title>

  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous" media="all">
  <!--end::Web font -->
  <!--begin::Base Styles -->
  <link href="<?php  echo $this->config->item('Template_template_file_url'); ?>template/assets/vendors/base/vendors.bundle.css" rel="stylesheet" type="text/css" />
  <link href="<?php echo $this->config->item('Template_template_file_url'); ?>template/assets/demo/default/base/style.bundle.css" rel="stylesheet" type="text/css" />
  <script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.16/webfont.js"></script>
  <script>
  WebFont.load({
    google: {"families":["Poppins:300,400,500,600,700","Roboto:300,400,500,600,700"]},
    active: function() {
      sessionStorage.fonts = true;
    }
  });
  </script>
</head>
<style>
.table-bordered th, .table-bordered td {
    border: 1px solid #858585 !important;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__body table thead tr th {
    color: #000000 !important;
}
.table thead th {
    border-top: 2px solid #858585 !important;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__body table tbody tr td {
    color: #000000 !important;
}
.table thead th {
    vertical-align: bottom !important;
    border-bottom: 2px solid #858585 !important;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container .m-invoice__items .m-invoice__item {
  display: table-cell !important;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container .m-invoice__items {
    border: 0px;
    padding: 0px;
}
.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: 100%;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__body.m-invoice__body--centered {
  width: 100%;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container.m-invoice__container--centered {
  width: 100%;
}
</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;
  }

  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-content{
    width:100% !important;
  }
}
.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;
}
.m-invoice-2{
  font-size: 13px !important;
  font-weight: 500 !important;
  font-family: "Poppins" !important;
  color: black;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__body table tbody tr td {
  font-size: 13px !important;
  font-weight: 500 !important;
  font-family: "Poppins" !important;
  color: black;
}
table tbody tr td {
  font-size: 13px !important;
  font-weight: 500 !important;
  font-family: "Poppins" !important;
  color: black;
}
table thead tr th {
  font-size: 13px !important;
  font-weight: 500 !important;
  font-family: "Poppins" !important;
  color: black;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__body table thead tr th {
  color: black;
}
</style>
<style type="text/css">

body {
  font-size: 20pt !important;
  line-height: 25px;
  /* font-size: 13px;
  font-weight: 300;
  font-family: Poppins;
  -ms-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  line-height: 20px;
  padding:0px;
  margin:0px;
  line-height:18px; */
}
.item_table td{
  padding: .75rem !important;
}
.item_table th{
  white-space: nowrap;
  padding: .75rem !important;
}


.page-header, .page_table .page-header-space {
  height: 375px;
}
.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
}

@media print {
  thead {display: table-header-group;}
  tfoot {display: table-footer-group;}
  button {display: none;}
  body {margin: 0;}

}
* {
  -webkit-print-color-adjust: exact !important;   /* Chrome, Safari, Edge */
  color-adjust: exact !important;                 /*Firefox*/
}

</style>


<body class="">
  <div class="m-grid__item m-grid__item--fluid m-wrapper" id="content">
    <div class="m-content" style="height:auto; float:left; width:100% !important;">
      <div class="page-header" style="text-align: left;padding-left: 0px;">
        <?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 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: 1rem;">
                  <a href="#">

                  </a>
                </div>
                <div class="row">
                  <div class="col-md-12">
                    <div class="m-invoice__logo" style="padding-top: 0px;">
                      <a href="#" style="text-align: center;">
                        <h2>SUBCONTRACT
                          <?php if($type=='summary'){
                            echo "SUMMARY";
                          }else{
                            echo "AGREEMENT";
                          }
                          ?>
                        </h2>
                      </a>
                    </div>
                  </div>
                </div>
                <div class="m-invoice__items" style="padding: 5px 0 5px 0;">
                  <div class="m-invoice__item" style="text-align: left">
                    <span class="m-invoice__subtitle">ORDER NO : <?php if($subcontract_data->reference_no!=''){ echo $subcontract_data->reference_no."/";}  ?><?php echo $subcontract_data->contract_id ?></span>
                  </div>
                  <div class="m-invoice__item" style="text-align:right">
                    <span class="m-invoice__subtitle">DATE : <?php if($subcontract_data->subcontract_date!='0000-00-00'){ echo date('d-m-Y',strtotime($subcontract_data->subcontract_date));}?></span>
                  </div>
                </div>

                <div class="m-invoice__items" style="padding: 5px 0 5px 0;border-bottom: 1px solid #ebedf2;">
                  <span class="m-invoice__desc" style="text-align: left;padding: 5px 0 0 0 !important;">
                    <span class="m-invoice__subtitle"></span>
                    <span>Contractor: <?php echo $subcontract_data->contractor_name?></span>
                    <span><?php echo $subcontract_data->contractor_address?></span>
                    <span><?php if($subcontract_data->phone!=''){ echo "Phone: ".$subcontract_data->phone;} ?></span>
                      <span><?php if($subcontract_data->tax_no!=''){ echo "TRN No: ".$subcontract_data->tax_no;}?></span>
                      </span>
                    </div>
                    <div class="m-invoice__items" style="padding: 5px 0 5px 0;border-bottom: 1px solid #ebedf2;">
                      <div class="m-invoice__item" >
                        <span class="m-invoice__subtitle">Project : <?php echo $subcontract_data->work_name?></span>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </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" >
                    <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__items" style="padding: 5px 0 5px 0;border-bottom: 1px solid #ebedf2;">
                              <div class="m-invoice__item">
                                <span class="m-invoice__subtitle"></span>
                                <span class="m-invoice__text"><?php echo nl2br($subcontract_data->description)?></span>
                              </div>
                            </div>
                          </div>
                        </div>
                        <div class="m-invoice__body m-invoice__body--centered" style="min-height: 200px">
                          <div class="table-responsive">
                            <table class="table m-table table-bordered item_table" style="margin-bottom:0px !important">
                              <thead>
                                <tr>
                                  <th style="text-align:center;">CONTRACT WORK DETAILS</th>
                                </tr>
                              </thead>
                            </table>
                            <table class="table m-table table-bordered item_table">
                              <thead>
                                <tr>
                                  <th>Sl No</th>
                                  <th style="text-align:left">Work Details</th>
                                  <?php if($subcontract_data->contract_type=='unit_rate'){ ?>
                                    <th>UOM</th>
                                    <th>Qty</th>
                                    <th>Rate</th>
                                    <th>Tax %</th>
                                  <?php } ?>
                                  <th>Total</th>
                                </tr>
                              </thead>
                              <tbody>
                                <?php
                                $item_sl_no = 1;
                                $colspan = 2;
                                foreach($work_items->result() as $value):

                                  ?>
                                  <tr>
                                    <td><?php echo $item_sl_no ?></td>
                                    <td style="text-align:left"><?php echo $value->type_name ?><br/><?php echo nl2br($value->work_details) ?></td>
                                    <?php if($subcontract_data->contract_type=='unit_rate'){
                                      $colspan = 6;
                                      ?>
                                      <td><?php echo $value->unit_name ?></td>
                                      <td><?php echo $value->qty ?></td>
                                      <td><?php echo $value->unit_rate ?></td>
                                      <td><?php echo $value->tax_percent ?></td>
                                    <?php } ?>
                                    <td><?php echo $this->config->item('currency_format')->formatCurrency($value->est_amount,$this->config->item('Currency_currency_shortname')) ?></td>
                                  </tr>
                                  <?php
                                  $item_sl_no ++;
                                endforeach;
                                ?>
                                <tr>
                                  <td colspan="<?php echo $colspan ?>">Total (<?php echo $this->config->item('Tax_tax_name') ?> Inclusive)</td>
                                  <td ><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($subcontract_data->total_budget,$this->config->item('Currency_currency_shortname'));?></td>
                                </tr>
                              </tbody>
                            </table>
                          </div>
                        </div>
                        <?php if($type=='summary'){ ?>
                          <div class="m-invoice__body m-invoice__body--centered" style="min-height: 200px">
                            <div class="table-responsive">
                              <table class="table m-table table-bordered item_table" style="margin-bottom:0px !important">
                                <thead>
                                  <tr>
                                    <th style="text-align:center;">BILLS & PAYMENT SUMMARY</th>
                                  </tr>
                                </thead>
                              </table>
                              <table class="table m-table table-bordered item_table">
                                <thead>
                                  <tr>
                                    <th>No. of Bills</th>
                                    <th><?php echo $no_of_bills ?></th>
                                  </tr>
                                  <tr>
                                    <th>Total Bill Amount</th>
                                    <th><?php echo $bill_amount ?></th>
                                  </tr>
                                  <tr>
                                    <th>Total Deduction Amount</th>
                                    <th><?php echo $deduction_amount ?></th>
                                  </tr>
                                  <tr>
                                    <th>Total Paid On Bill</th>
                                    <th><?php echo $bill_paid_amount ?></th>
                                  </tr>
                                  <tr>
                                    <th>Total Paid As Advance</th>
                                    <th><?php echo $advance_paid_amount ?></th>
                                  </tr>
                                  <tr>
                                    <th>Total Paid (Bill+Advance+OP Balance)</th>
                                    <th><?php echo $total_paid ?></th>
                                  </tr>
                                  <tr>
                                    <th>Balance Payable (Bill Amt - Deductions - Total Paid)</th>
                                    <th><?php echo $bill_amount-$deduction_amount-$total_paid ?></th>
                                  </tr>
                                  <tr>
                                    <th>Balance to Contract Budget</th>
                                    <th><?php echo $budget_balance-$bill_tds_amount-$deduction_amount ?></th>
                                  </tr>
                                </thead>
                              </table>
                            </div>
                          </div>
                        <?php } ?>
                        <div class="" style="width: 90%;margin: 0 auto;padding: 2rem 0 0 0;">
                          <?php
                          $terms = unserialize($subcontract_data->terms_and_conditions);
                          if($terms!='' && $terms!=null) {
                            $count = sizeof($terms);
                            $i = 1;
                            ?>
                            <div class="m-invoice__table  m-invoice__table--centered table-responsive" style="margin-bottom: 50px">
                              <div style=" margin-bottom: 2%; ">Terms and Conditions</div>
                              <table class="table" style="font-size:16px !important;">
                                <thead>
                                  <tr>
                                    <th width="5%">SL</th>
                                    <th width="30%">Title</th>
                                    <th width="65%">Description</th>
                                  </tr>
                                </thead>
                                <tbody>
                                  <?php foreach ($terms as $key => $value) { ?>
                                    <tr>
                                      <td><?= $i ?>.</td>
                                      <td><?= $value['title'] ?></td>
                                      <td><?= nl2br($value['description']) ?></td>
                                    </tr>
                                    <?php $i++; } ?>
                                  </tbody>
                                </table>
                              </div>
                            <?php } ?>
                            <!-- Bills created -->
                            <div class="m-invoice__table  m-invoice__table--centered table-responsive" style="margin-bottom: 30px">
                              <table class="table">
                                <thead>
                                  <tr><th colspan="3">Agreed and Accepted</th></tr>
                                  <tr><th colspan="3">&nbsp;</th></tr>
                                  <tr><th colspan="3">&nbsp;</th></tr>
                                  <tr><th colspan="3">&nbsp;</th></tr>
                                  <tr>
                                    <th width="33%" style="border-top:1px dashed black !important"><?php echo $this->config->item('company_name') ?><br/>&nbsp;</th>
                                    <th></th>
                                    <th width="33%" style="border-top:1px dashed black !important;vertical-align: top;text-align:right"><?php echo $subcontract_data->contractor_name?><br/>(CONTRACTOR)</th>
                                  </tr>
                                </thead>
                              </table>
                            </div>
                          </div>
                        </div>

                      </div>
                    </div>
                  </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>
      <script src="<?php echo $this->config->item('Template_template_file_url'); ?>template/assets/vendors/base/vendors.bundle.js" type="text/javascript"></script>
      <script src="<?php echo $this->config->item('Template_template_file_url'); ?>template/assets/demo/default/base/scripts.bundle.js" type="text/javascript"></script>

      <script type="text/javascript">
      $("#page_title").text("Subcontract Work <?php if($type=='summary'){
        echo "SUMMARY";
      }else{
        echo "AGREEMENT";
      }
      ?> #<?php echo $subcontract_data->contract_id." [".$subcontract_data->contractor_name."] [".$subcontract_data->work_name."]" ?>");
      $(function() {
        window.print();
      });
      </script>

    </body>
    </html>
