<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title></title>
</head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.16/webfont.js"></script>
<script>
WebFont.load({
  google: {"families":["Arial:300,400,500,600,700","Roboto:300,400,500,600,700"]},
  active: function() {
    sessionStorage.fonts = true;
  }
});
</script>
<style>
html, body {
    font-family: Arial !important;
}
.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;
}
.item_table td{
  padding: .75rem !important;
}
.item_table th{
  white-space: nowrap;
  padding: .75rem !important;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container.m-invoice__container--centered {
  width: 100% !important;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__body.m-invoice__body--centered {
  width: 100% !important;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container .m-invoice__items .m-invoice__item {
  display: table-cell;
}
@media print
{
  .no-print, .no-print *
  {
    display: none !important;
  }
  @page {
    margin: 10mm
  }
}
</style>
<body>
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
  <!--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" />
  <!--end::Base Styles -->
  <!--<link rel="shortcut icon" href="<?php //echo base_url()?>template/assets/app/media/img/logos/logo.png" style="width: 50px;"/>-->

  <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/jszip-2.5.0/dt-1.10.20/b-1.6.1/b-colvis-1.6.1/b-flash-1.6.1/b-html5-1.6.1/b-print-1.6.1/fc-3.3.0/fh-3.1.6/kt-2.5.1/r-2.2.3/rg-1.1.1/sc-2.0.1/sp-1.0.1/datatables.min.css"/>

  <body>
    <div class="m-portlet m-portlet--full-height">
      <div class="m-portlet__body m-portlet__body--no-padding">
        <?php if($this->config->item('company_letter_head')!=''){ ?>
          <img style="max-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: 0rem;">
                  <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 "WORK ORDER";
                          }
                          ?>
                        </h2>
                      </a>
                    </div>
                  </div>
                </div>
                <div class="m-invoice__items" style="padding: 1rem 0 1rem 0;">
                  <div class="m-invoice__item" style="text-align: left">
                    <span class="m-invoice__subtitle">ORDER ID</span>
                    <span class="m-invoice__text"><strong>#<?php echo $subcontract_data->contract_id ?></strong></span>
                  </div>
                  <div class="m-invoice__item" style="text-align: center">
                    <span class="m-invoice__subtitle">DATE</span>
                    <span class="m-invoice__text"><strong><?php if($subcontract_data->subcontract_date!='0000-00-00'){ echo date('d-m-Y',strtotime($subcontract_data->subcontract_date));}?></strong></span>
                  </div>
                  <div class="m-invoice__item" style="text-align: right">
                    <span class="m-invoice__subtitle">REFERENCE NO</span>
                    <span class="m-invoice__text"><strong><?php echo $subcontract_data->reference_no ?></strong></span>
                  </div>
                </div>

                <div class="m-invoice__items" style="padding: 1rem 0 1rem 0;border-bottom: 1px solid #ebedf2;">
                  <div class="m-invoice__item" style="border-right: 1px solid #ebedf2;">
                    <span class="m-invoice__subtitle">Contractor Details </span>
                    <span class="m-invoice__text"><strong><?php echo $subcontract_data->contractor_name?><br/><?php echo $subcontract_data->phone?><br/><?php echo nl2br($subcontract_data->contractor_address) ?></strong></span>
                  </div>
                  <div class="m-invoice__item" style="text-align: left;padding-left:20px">
                    <span class="m-invoice__subtitle">Project Details</span>
                    <span class="m-invoice__text"><strong><?php echo $subcontract_data->work_name?><br/><?php echo nl2br($subcontract_data->work_location) ?></strong></span>
                  </div>
                </div>
                <div class="m-invoice__items" style="padding: 1rem 0 1rem 0;border-bottom: 1px solid #ebedf2;">
                  <div class="m-invoice__item">
                    <span class="m-invoice__subtitle">Work Description </span>
                    <span class="m-invoice__text" style="text-align:justify"><strong><?php echo nl2br($subcontract_data->description)?></strong></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;font-weight:700">CONTRACT WORK DETAILS</th>
                    </tr>
                  </thead>
                </table>
                <table class="table m-table table-bordered item_table">
                  <thead>
                    <tr style="text-align:center">
                      <th>Sl No</th>
                      <th>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:justify"><?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;font-weight:700">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" style="margin-bottom: 50px">
                  <div style=" margin-bottom: 2%; "><strong>Terms and Conditions</strong></div>
                  <table class="table" style="font-size:16px !important;font-weight: 400 !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 style="text-align:justify"><?= 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 width="50%" rowspan="3">
                          <h4><strong>Billing Address<strong></h4>
                          <?php
                          if($subcontract_data->billing_address!=''){
                            echo '<div class="notices">
                            <div></div>
                            <div class="notice">'.nl2br($subcontract_data->billing_address).'</div>
                            </div>';
                          }else{
                            echo '<div class="notices">
                            <div></div>
                            <div class="notice">'.$this->config->item('company_name').'</div>
                            <div class="notice">'.preg_replace('#(<br */?>\s*)+#i', '<br />',$this->config->item('company_address')).'</div>
                            </div>';
                          }?>
                        </th>
                        <th width="33%" style="vertical-align: top;text-align:left">Signature :
                          <?php if($this->config->item('company_signature')!=''){
                            echo '<img style="max-height:50px" src="'.base_url().'uploads/company/'.$this->config->item('company_signature').'">'; } ?></th>
                          </tr>
                          <tr>
                            <th width="33%" style="vertical-align: top;text-align:left">Subcontractor Signature :  </th>
                          </tr>
                          <tr>
                            <th width="33%" style="vertical-align: top;text-align:left">Witness Signature :  </th>
                          </tr>
                        </thead>
                      </table>
                    </div>
                  </div>
                </div>

              </div>

            </div>
          </div>

          <?php if($this->config->item('company_letter_footer')!=''){ ?>
            <img class="footer" style="max-width: 100%" src="<?php echo base_url().'uploads/company/'.$this->config->item('company_letter_footer')?>" />
          <?php } ?>

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

        </body>
        </html>
