<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title><?= $this->config->item('company_name')?></title>
  <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>
  <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" />

</head>
<style type="text/css">

body {
  font-size: 15pt !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;
}
.table thead th {
  border-top: 2px solid #f4f5f8 !important;
}
@media print
{
  #print, .print_hide_div
  {
    display: none !important;
  }
}

/* @media print {
html, body, div, span, applet, object, iframe, td, tr, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
font-size: 15pt !important;
}
h1.entry-title {
font-size: 15pt !important;
}
}

@media print {
html, body, div, span, applet, object, iframe, td, tr, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
font-size: 15pt !important;
}
h1.entry-title {
font-size: 15pt !important;
}
} */
.page-header, .page_table .page-header-space {
  height: 250px;
}
.page-footer, .page-footer-space {
  height: 100px;
}
.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;}
}
</style>
<body>
  <div class="m-grid__item m-grid__item--fluid m-wrapper" id="content">
    <div class="m-content">
      <div class="page-header" style="text-align: center">
        <img style="max-width: 1000px;max-height:300px" src="<?php echo base_url().'uploads/company/'.$this->config->item('company_letter_head')?>" />
        <br/><br/>
      </div>
      <div class="page-footer">
        <?php if($this->config->item('company_letter_footer')!=''){ ?>
          <img style="max-width: 1000px;max-height:100px" src="<?php echo base_url().'uploads/company/'.$this->config->item('company_letter_footer')?>" />
        <?php } ?>
      </div>
      <table class="page_table">
        <thead>
          <tr>
            <td>
              <!--place holder for the fixed-position header-->
              <div class="page-header-space"></div>
            </td>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>
              <!--*** CONTENT GOES HERE ***-->
              <?php if($print_type=='boq_details'){?>
                <div class="page">
                  <div class="row">
                    <div class="col-md-6">
                      <label>Reference No: <?php echo $boq_data->reference_no ?></label>
                    </div>
                    <div class="col-md-6" >
                      <label style="float:right"><?php if($boq_data->boq_date!='0000-00-00'){ echo date('d-m-Y',strtotime($boq_data->boq_date));}  ?></label>
                    </div>
                  </div>
                  <br/><br/>
                  <div class="row">
                    <div class="col-md-12">
                      <?php echo $boq_data->boq_description ?>
                    </div>
                  </div>
                </div>
              <?php } ?>
              <div class="page">
                <div class="m-portlet__head-text" style="text-align: center;text-decoration: underline">
                  <label style="font-weight:900">BOQ Of Project : " <?php echo $project_data->work_name?> "</label>
                </div>
                <br/>
                <table class="table table-striped table-bordered table-hover table-header-fixed" id="table_boq_list">
                  <thead>
                    <tr class="">
                      <th >ITEM</th>
                      <th style="width: 100%">DESCRIPTION</th>
                      <th>QTY</th>
                      <th>UNIT</th>
                      <th>UNIT PRICE</th>
                      <th>TOTAL PRICE</th>
                    </tr>
                  </thead>
                  <tbody id="table-body">
                    <?php
                    $priority=1;
                    $tasks_table_body='';
                    $tasks_table_summary='<tr>'.
                    '<td colspan="6" style="text-align: center"><strong>SUMMARY</strong></td>'.
                    '</tr>';
                    $boq_id = $boq_data->boq_id;
                    foreach($project_work_types as $row):

                      $work_type_id=$row->id;
                      $type_id=$row->type_id;
                      $type_name=$row->type_name;

                      $data2['bt.project_work_type_id']=$work_type_id;
                      $data2['bt.boq_id']=$boq_id;

                      $total_amt_sum=$row->boq_task_sum;

                      $tasks_table_body.='<tr>'.
                      '<td><strong>'.$priority.'</strong></td>'.
                      '<td colspan="5"><strong>'.$type_name.'</strong></td>'.
                      '</tr>';

                      $tasks_table_summary.='<tr>'.
                      '<td></td>'.
                      '<td colspan="4"><strong>'.$type_name.'</strong></td>'.
                      '<td ><strong>'.number_format($total_amt_sum,$this->config->item('Currency_amount_decimals_2'),'.','').'</strong></td>'.
                      '</tr>';

                      $sub_total=0;

                      $priority2 = 1;
                      $j=1;
                      foreach ($row->boq_tasks as $row2){
                        $unit_name = $row2->unit_name;
                        $priority3 = $priority.'.'.$priority2;
                        $task_id = $row2->task_id;
                        $project_work_type_id = $row2->project_work_type_id;
                        $description = $row2->description;
                        $qnty = $row2->qty;
                        $unit = $row2->unit;
                        $unit_price = $row2->unit_price;
                        $total_price = $row2->total_price;
                        $data3['bt.boq_id']=$boq_id;
                        $data3['bt.project_work_type_id']=$project_work_type_id;
                        $data3['bti.boq_task_id']=$task_id;
                        $data3['bti.delete_status']=0;
                        $column = "bt.project_work_type_id,mu.unit_name,bt.task_id,bt.boq_id,bt.description,bt.project_work_type_id,bt.item_sl_no,bt.qty,bt.unit as psuedo_unit, bt.unit_price,bt.total_price,bt.created_date,bt.created_by,bt.updated_by,bt.updated_date,bti.*,m.material_id,m.material_name,m.unit as psuedo_unit2,b.*";
                        $res3=$this->Boq->select_task_items($column,$data3);
                        $task_item_count=$res3->num_rows();
                        $boq_id = $row2->boq_id;
                        $work_type_id = $row2->project_work_type_id;
                        $tasks_table_body.=
                        '<tr>'.
                        '<td><strong>'.$priority3.'</strong></td>'.
                        '<td style="line-height: 25px;">'.$description.'</td>'.
                        '<td>'.number_format($qnty,$this->config->item('Currency_amount_decimals_2'),'.','').'</td>'.
                        '<td>'.$unit_name.'</td>'.
                        '<td>'.number_format($unit_price,$this->config->item('Currency_amount_decimals_2'),'.','').'</td>'.
                        '<td>'.number_format($total_price,$this->config->item('Currency_amount_decimals_2'),'.','').'</td>'.
                        '</tr>';
                        $sub_total=$sub_total+$total_price;
                        $priority2++;
                        if($task_item_count>0){
                          $tasks_table_body.= '<tr>'.
                          '<td ></td>'.
                          '<td colspan="5" class="right" style=" font-weight: 500;font-style: italic;  ">Item Requirements : </td>'.
                          '</tr>';
                          $priority4=1;
                          foreach ($res3->result() as $row3):
                            if(($row3->item_type)=="other" && $row3->item_name !='0') {
                              $material_name = $row3->item_name;
                            }
                            else{
                              $material_name = $row3->material_name;
                            }
                            $unit_name = $row3->unit_name;
                            $tasks_table_body.=
                            '<tr>'.
                            '<td>'.$priority3.'.'.$priority4.'</td>'.
                            '<td>'.$material_name.'</td>'.
                            '<td>'.number_format($row3->qnty,$this->config->item('Currency_amount_decimals_2'),'.','').'</td>'.
                            '<td>'.$unit_name.'</td>'.
                            '<td>'.number_format($row3->unit_rate,$this->config->item('Currency_amount_decimals_2'),'.','').'</td>'.
                            '<td>'.number_format($row3->total_amount,$this->config->item('Currency_amount_decimals_2'),'.','').'</td>'.
                            '</tr>';
                            $priority4++;
                          endforeach;
                        }

                      }

                      $tasks_table_body.='<tr>'.
                      '<td></td>'.
                      '<td colspan="4" class="right">Sub Total : to be carried to summary</td>'.
                      '<td>'.number_format($sub_total,$this->config->item('Currency_amount_decimals_2'),'.','').'</td>'.
                      '</tr>';
                      $priority++;
                    endforeach;
                    $tasks_table_summary.='<tr>'.
                    '<td></td>'.
                    '<td colspan="4"><strong>Total Amount</strong></td>'.
                    '<td ><strong>'.$this->config->item("Currency_currency_format").' ' .number_format($total_boq_amt,$this->config->item('Currency_amount_decimals_2'),'.','').' </strong></td>'.
                    '</tr>';
                    $table_content=$tasks_table_body.$tasks_table_summary;
                    echo $table_content;
                    ?>
                  </tbody>
                </table>
                <div style="text-align: center;text-decoration:underline">
                  <h3>Total Amount : <?php echo $this->config->item("Currency_currency_format").' ' .number_format($total_boq_amt,$this->config->item('Currency_amount_decimals_2'),'.','') ?> </h3>
                  <br/>
                  <h3> <?php echo ucwords(getIndianCurrency($total_boq_amt));?></h3>
                </div>
                <?php if($print_type=='boq_details'){?>
                <br/><br/>
                <div>
                  <?php
                  $materials_count = 0;
                  $material_description = unserialize($boq_data->materials_description);
                  if($material_description!='' && $material_description!=null) { ?>
                    <h3 style="text-decoration:underline">Materials Description</h3>
                    <table>
                      <thead></thead>
                      <tbody>
                        <?php
                        $materials_count = sizeof($material_description);
                        $i = 0;
                        foreach ($material_description as $key => $value) {?>
                          <tr>
                            <td style="vertical-align:top"><?php echo $key+1 ?>. &nbsp;&nbsp;&nbsp;</td>
                            <td><?php
                            if($value['title']!=''){
                              echo $value['title']." : ";
                            }
                            echo $value['description'];
                            ?></td>
                          </tr>
                        <?php } ?>
                      </tbody>
                    </table>
                  <?php } ?>
                </div>
                <?php } ?>
                <?php if($print_type=='boq_details'){?>
                <div class="">
                  <div>
                    <br/><br/>
                    <?php
                    $terms_count=0;
                    $terms = unserialize($boq_data->terms_and_conditions);
                    if($terms!='' && $terms!=null) { ?>
                      <h3 style="text-decoration:underline">Terms & Conditions:</h3>
                      <table>
                        <thead></thead>
                        <tbody>
                          <?php
                          $terms_count = sizeof($terms);
                          $i = 0;
                          foreach ($terms as $key => $value) {?>
                            <tr>
                              <td style="vertical-align:top"><?php echo $key+1 ?>. &nbsp;&nbsp;&nbsp;</td>
                              <td><?php
                              if($value['title']!=''){
                                echo $value['title']." : ";
                              }
                              echo $value['description'];
                              ?></td>
                            </tr>
                          <?php } ?>
                        </tbody>
                      </table>
                    <?php } ?>
                  </div>
                </div>
                <?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>
  <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" src="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.js"></script>

  <!--end::Base Scripts -->


  <script>
  jQuery(document).ready(function() {
    var project_id="<?php echo $boq_data->project_id ?>";
    var boq_id="<?php echo $boq_data->boq_id ?>";

    // var table = $('#table_boq_list').dataTable({
    //   "scrollX" : true,
    //   buttons: [
    //     { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'},exportOptions: {columns:[1,2,3,4,5,6,7]} },
    //     { extend: 'pdf', className: 'btn purple btn-outline',exportOptions: {columns:[1,2,3,4,5,6,7]} },
    //     { extend: 'csv', className: 'btn purple btn-outline',exportOptions: {columns:[1,2,3,4,5,6,7]} },
    //   ],
    //   dom:"<'row'<'col-sm-6 text-left'B><'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
    //   "lengthMenu": [
    //     [100, 250, 500, -1],
    //     [100, 250, 500, "All"] // change per page values here
    //   ],
    //   "columnDefs": [
    //     {
    //       "targets": [],
    //       className: "hidden"
    //     }
    //   ],
    //   'order': false,
    //   'ordering':false,
    //   "pageLength":100
    // });

    window.print();
  });
  </script>
  <style>
  .hidden{
    display: none;
  }
  </style>

</body>
</html>
