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

<?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">
          BOQ - Update Daily Progress
        </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().'work' ?>" class="m-nav__link">
              <span class="m-nav__link-text">
                BOQ Details
              </span>
            </a>
          </li>
        </ul>
      </div>
      <div>
        <?php if ($this->session->flashdata('flashdata_msg') != "")
        {?>
          <div class="alert alert-<?php echo $this->session->flashdata('alert_type')?> alert-dismissible fade show   m-alert m-alert--air m-alert--outline m-alert--outline-2x" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"></button>
            <strong>
              <?php echo $this->session->flashdata('flashdata_title')?>
            </strong>
            <?php echo $this->session->flashdata('flashdata_msg')?>
          </div>
        <?php } ?>
      </div>
    </div>
  </div>
  <!-- END: Subheader -->
  <div class="m-content">
    <div class="m-portlet m-portlet--mobile m-portlet--info m-portlet--head-solid-bg m-portlet--bordered m-portlet--rounded">
      <div class="m-portlet__head">
        <div class="m-portlet__head-caption">
          <div class="m-portlet__head-title">
            <h3 class="m-portlet__head-text">
              BOQ - Update Daily Progress
            </h3>
          </div>
        </div>
        <div class="m-portlet__head-tools">

        </div>
      </div>
      <form autocomplete="off"  id="form_boq_progress_add" method="post" action="<?php echo base_url().'boq/create_dpr'?>" enctype="multipart/form-data" class="m-form m-form--fit m-form--state m-form--label-align-right ">
        <div class="m-portlet__body" style="padding: 2.2rem 2.2rem !important;">
          <!--begin: Datatable -->
          <div class="m-form m-form--label-align-right m--margin-bottom-10">
            <div class="row">
              <div class="col-md-6">
                <div class="form-group m-form__group">
                  <label>Project</label>
                  <input type="text" value="<?php echo $project_data->work_name ?>" name="project_name" class="form-control m-input m-input--air m-input--pill  m-input--solid" >
                  <input type="hidden" value="<?php echo $boq_data->boq_id ?>" name="boq_id">
                  <input type="hidden" value="<?php echo $boq_data->project_id ?>" name="project_id">
                  <span class="m-form__help"></span>
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group m-form__group">
                  <label>Date</label>
                  <input readonly value="<?php echo $work_date?>" name="work_date" type="text"  class="form-control m-input  m-input--pill m-input--air" placeholder="Work Date" >
                  <span class="m-form__help"></span>
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group m-form__group">
                  <label>Vehicle No</label>
                  <input  name="vehicle_no" type="text"  class="form-control m-input  m-input--pill m-input--air" placeholder="Vehicle No" >
                  <span class="m-form__help"></span>
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group m-form__group">
                  <label>Applicator Team Name</label>
                  <input  name="applicator_team_name" type="text"  class="form-control m-input  m-input--pill m-input--air" placeholder="Applicator Team Name" >
                  <span class="m-form__help"></span>
                </div>
              </div>
              <div class="col-lg-3">
                <div class="form-group m-form__group"  >
                  <label for="user_name">
                    Contractor
                  </label>
                  <div class="m-select2 m-select2--air m-select2--pill">
                    <select id="subcontract_add" name="subcontract" style="width: 100%" class="form-control m-input" aria-describedby="basic-addon1" data-placeholder="Select Subcontract">

                    </select>
                  </div>
                  <span class="m-form__help"></span>
                </div>
              </div>
              <div class="col-lg-3">
                <div class="form-group m-form__group">
                  <label for="user_name">
                    Site Supervisor
                  </label>
                  <div class="m-select2 m-select2--air m-select2--pill">
                    <select style="width: 100%" class="form-control m-select2 m-select2-general" required id="supervisor" name="supervisor">

                    </select>
                  </div>
                  <span class="m-form__help"></span>
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group m-form__group">
                  <label>No of Labours Worked</label>
                  <input  name="no_of_labours" required type="text"  class="form-control m-input  m-input--pill m-input--air" placeholder="No of Labours Worked" >
                  <span class="m-form__help"></span>
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group m-form__group">
                  <label>Start Time</label>
                  <input  name="start_time" id="start_time"  type="text"  class="form-control m-input  m-input--pill m-input--air" placeholder="Start Time" >
                  <span class="m-form__help"></span>
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group m-form__group">
                  <label>End Time</label>
                  <input  name="end_time" id="end_time" type="text"  class="form-control m-input  m-input--pill m-input--air" placeholder="End time" >
                  <span class="m-form__help"></span>
                </div>
              </div>
            </div>
            <br/>
          </div>
          <div style="background: white;border: 4px solid #f7f7fa;padding: 15px;margin: 5px;padding-bottom: 0px">
            <div class="m-section" style="margin-bottom: 10px">
              <h3 class="m-section__heading">Step 1 - Measurement Details [On <?php echo $work_date?>]</h3>
              <div class="row">
                <div class="col-lg-12">
                  <table style="width: 100%;max-width: 100%" id="table_measurements" class="table m-table table-bordered item_table m-table--head-bg-success">
                    <thead>
                      <tr>
                        <th style="width:5%;text-align:left;color:white" rowspan="2">Sl No</th>
                        <?php if($project_data->project_section=='Road Marking'){?>
                          <th style="width:25%;text-align:left;color:white" rowspan="2">Details</th>
                        <?php }elseif($project_data->project_section=='Sign Boards'){?>
                            <th style="width:10%;text-align:left;color:white" rowspan="2">Location</th>
                          <?php }else{?>
                          <th style="text-align:center;border:white 1px solid;color:white" colspan="2">Chainage</th>
                        <?php } ?>
                        <?php if($project_data->project_section=='Sign Boards'){?>
                          <th style="width:15%;text-align:left;color:white" rowspan="2">Board</th>
                        <?php } ?>
                        <th style="width:10%;text-align:left;color:white" rowspan="2">Side</th>
                        <?php if($project_data->project_section=='Road Marking' || $project_data->project_section=='Sign Boards'){?>
                          <th style="text-align:left;color:white" rowspan="2">No</th>
                        <?php } ?>
                        <?php if($project_data->project_section=='Road Studs'){?>
                          <th style="text-align:left;color:white" rowspan="2">Spacing</th>
                        <?php }elseif($project_data->project_section=='Crash Barriers' || $project_data->project_section=='Road Marking'){?>
                          <th style="text-align:left;color:white" rowspan="2">Length (Mtr)</th>
                        <?php } ?>
                        <?php if($project_data->project_section=='Road Marking'){?>
                          <th style="text-align:left;color:white" rowspan="2">Width (Mtr)</th>
                        <?php } ?>
                        <?php if($project_data->project_section=='Road Marking'){?>
                          <th style="text-align:left;color:white" rowspan="2">Total (SQMtr)</th>
                        <?php } ?>
                        <?php if(sizeof($stock_materials)>0 && $project_data->project_section!='Road Marking'){ ?>
                          <th style="text-align:center;border:white 1px solid;color:white" colspan="<?php echo sizeof($stock_materials)?>">Material Usage</th>
                        <?php } ?>
                        <?php if($project_data->project_section=='Sign Boards'){?>
                          <th style="text-align:left;color:white" rowspan="2">Ref No</th>
                        <?php } ?>
                        <th style="text-align:left;color:white" rowspan="2">Remarks</th>
                        <th style="width:5%;text-align:left;color:white" rowspan="2">&nbsp;</th>
                      </tr>
                      <?php if($project_data->project_section!='Road Marking'){?>
                        <tr>
                          <?php if($project_data->project_section!='Sign Boards'){?>
                          <th style="text-align:left;color:white">From</th>
                          <th style="text-align:left;color:white">To</th>
                        <?php } ?>
                          <?php foreach ($stock_materials as $key => $value) {?>
                            <th style="text-align:left;color:white" rowspan="2"><?php echo $value->material_name?></th>
                          <?php } ?>
                        </tr>
                      <?php } ?>
                    </thead>
                    <tbody id="table_body_measurements">
                      <?php $i = 0;?>
                      <tr class="row_<?php echo $i+1 ?>">
                        <td>
                          <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                            <div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" readonly type="text" class="form-control m-input item_slno" data-sl-no="<?php echo $i + 1 ?>" name="measurements[sl_no][<?php echo $i ?>]" value="<?php echo $i + 1 ?>" /></div>
                          </div>
                        </td>
                        <td>
                          <?php if($project_data->project_section=='Road Marking'){?>
                            <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                              <select required class="form-control m-bootstrap-select m-bootstrap-select--air m-bootstrap-select--pill m_selectpicker" data-sl-no="<?php echo $i + 1 ?>" name="measurements[chainage_from][<?php echo $i ?>]" id="chainage_from_<?php echo $i+1 ?>" title="Description">
                                <option selected disabled>Select Description</option>
                                <option value="Continue">Continue</option>
                                <option value="Strip">Strip</option>
                                <option value="Stop Line">Stop Line</option>
                                <option value="Dot Line">Dot Line</option>
                                <option value="Chevron">Chevron</option>
                                <option value="Hatching">Hatching</option>
                                <option value="PC">PC</option>
                                <option value="Hump">Hump</option>
                                <option value="Side Line">Side Line</option>
                                <option value="Gap">Gap</option>
                                <option value="Rumble Strip">Rumble Strip</option>
                                <option value="Lamp Round">Lamp Round</option>
                                <option value="Cheveron Round">Cheveron Round</option>
                                <option value="Cheveron Side Line">Cheveron Side Line</option>
                                <option value="Divider Line">Divider Line</option>
                                <option value="Busway Line">Busway Line</option>
                              </select>
                              <span class="m-form__help"></span>
                            </div>
                          <?php }else{ ?>
                          <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                            <div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" required type="text" class="form-control m-input" data-sl-no="<?php echo $i + 1 ?>" name="measurements[chainage_from][<?php echo $i ?>]" id="chainage_from_<?php echo $i+1 ?>" /></div>
                          </div>
                          <?php } ?>
                        </td>
                        <?php if($project_data->project_section=='Sign Boards'){?>
                          <td>
                            <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                              <select required class="form-control m-bootstrap-select m-bootstrap-select--air m-bootstrap-select--pill m_selectpicker item_material_id" data-sl-no="<?php echo $i + 1 ?>" name="measurements[item][<?php echo $i ?>]" id="item_<?php echo $i+1 ?>" title="Item">
                                <option selected disabled>Select Item</option>
                              <?php foreach ($stock_materials as $key => $value) {?>
                                <option value="<?php echo $value->material_id?>"><?php echo $value->material_name?></option>
                              <?php } ?>
                              </select>
                              <span class="m-form__help"></span>
                            </div>
                          </td>
                        <?php } ?>
                        <?php if($project_data->project_section!='Road Marking' && $project_data->project_section!='Sign Boards'){?>
                          <td>
                            <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                              <div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" required type="text" class="form-control m-input" data-sl-no="<?php echo $i + 1 ?>" name="measurements[chainage_to][<?php echo $i ?>]" id="chainage_to_<?php echo $i+1 ?>" /></div>
                            </div>
                          </td>
                        <?php } ?>
                        <td>
                          <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                            <select required class="form-control m-bootstrap-select m-bootstrap-select--air m-bootstrap-select--pill m_selectpicker" data-sl-no="<?php echo $i + 1 ?>" name="measurements[side][<?php echo $i ?>]" id="side_<?php echo $i+1 ?>" title="Side">
                              <?php
                              $measurement_sides = $this->config->item('Measurement_Sides');
                              foreach($measurement_sides as $row){
                                ?>
                                <option value="<?php echo $row?>"><?php echo $row?></option>
                              <?php } ?>
                            </select>
                            <span class="m-form__help"></span>
                          </div>
                        </td>
                        <?php if($project_data->project_section=='Road Marking' || $project_data->project_section=='Sign Boards'){?>
                          <td>
                            <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                              <div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" required type="text" class="form-control numeric_fields row_1_qty_fields length_qty_fields m-input" data-sl-no="<?php echo $i + 1 ?>" name="measurements[qty_no][<?php echo $i ?>]" id="qty_no_<?php echo $i+1 ?>" value="0" /></div>
                            </div>
                          </td>
                        <?php } ?>
                        <?php if($project_data->project_section!='Sign Boards'){?>
                        <td>
                          <?php if($project_data->project_section=='Road Studs'){?>
                            <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                              <div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" required type="text" class="form-control m-input" data-sl-no="<?php echo $i + 1 ?>" name="measurements[spacing][<?php echo $i ?>]" id="spacing_<?php echo $i+1 ?>" /></div>
                            </div>
                          <?php }elseif($project_data->project_section=='Crash Barriers' || $project_data->project_section=='Road Marking'){?>
                            <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                              <div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" required type="text" class="form-control numeric_fields row_1_qty_fields length_qty_fields m-input" data-sl-no="<?php echo $i + 1 ?>" name="measurements[length][<?php echo $i ?>]" id="length_<?php echo $i+1 ?>" value="0" /></div>
                            </div>
                          <?php } ?>
                        </td>
                        <?php } ?>
                        <?php if($project_data->project_section=='Road Marking'){?>
                          <td>
                            <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                              <div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" required type="text" class="form-control numeric_fields row_1_qty_fields length_qty_fields m-input" data-sl-no="<?php echo $i + 1 ?>" name="measurements[width][<?php echo $i ?>]" id="width_<?php echo $i+1 ?>" value="0" /></div>
                            </div>
                          </td>
                        <?php } ?>
                        <?php if($project_data->project_section=='Road Marking'){?>
                          <td>
                            <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                              <div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" required readonly type="text" class="form-control numeric_fields row_1_qty_fields total_qty_fields m-input" data-sl-no="<?php echo $i + 1 ?>" name="measurements[total_qty][<?php echo $i ?>]" id="total_qty_<?php echo $i+1 ?>" value="0" /></div>
                            </div>
                          </td>
                        <?php } ?>
                        <?php
                        if($project_data->project_section!='Road Marking'){
                          foreach ($stock_materials as $key => $value) {?>
                            <td>
                              <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                                <div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" required <?php if($project_data->project_section=='Sign Boards'){ echo 'readonly';}?> type="text" class="form-control m-input material_qty_field material_qty_field_<?php echo $i + 1 ?> material_<?php echo $value->material_id?>" data-material-id="<?php echo $value->material_id?>" data-sl-no="<?php echo $i + 1 ?>" value="0" name="measurements[material_qty][<?php echo $i ?>][<?php echo $value->material_id?>]" id="material_<?php echo $value->material_id?>_<?php echo $i+1 ?>" /></div>
                              </div>
                            </td>
                          <?php }
                        } ?>
                        <?php if($project_data->project_section=='Sign Boards'){?>
                          <td>
                            <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                              <div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" type="text" class="form-control m-input" data-sl-no="<?php echo $i + 1 ?>" name="measurements[ref_no][<?php echo $i ?>]" id="ref_no_<?php echo $i+1 ?>"  /></div>
                            </div>
                          </td>
                        <?php } ?>
                        <td>
                          <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                            <div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px"  type="text" class="form-control m-input" data-sl-no="<?php echo $i + 1 ?>" name="measurements[remarks][<?php echo $i ?>]" id="remarks_<?php echo $i+1 ?>" /></div>
                          </div>
                        </td>
                        <td>
                          <!-- <a href="javascript:" data-row-sl-no="<?php //echo $i ?>" class="ibtnDel_measurements btn btn-sm btn-danger btn-icon-only">
                          <i class="fa fa-trash"></i>
                        </a> -->
                      </td>
                    </tr>
                    <?php $i++;
                    ?>
                  </tbody>
                  <tfoot>
                    <tr>
                      <td colspan="12" style="text-align: left;border-bottom: 1px solid #e7ecf1;">
                        <button type="button" class="btn btn-block " id="addrow_measurements"><i class="fa fa-plus-square"></i> Add New Measurement</button>
                      </td>
                    </tr>
                    <tr>
                      <td colspan="4" style="text-align:center"><strong>Total</strong></td>
                      <td>
                        <?php if($project_data->project_section=='Crash Barriers' || $project_data->project_section=='Sign Boards'){?>
                          <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                            <div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" readonly type="text" class="form-control m-input" data-sl-no="<?php echo $i + 1 ?>" value="0" name="total_length_qty" id="total_length_qty" /></div>
                          </div>
                        <?php } ?>
                      </td>
                      <?php
                      if($project_data->project_section!='Road Marking'){
                        foreach ($stock_materials as $key => $value) {?>
                          <td>
                            <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                              <div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" readonly type="text" class="form-control m-input row_1_qty_fields total_material_qty_fields" data-sl-no="<?php echo $i + 1 ?>" value="0" name="material_total[<?php echo $value->material_id?>]" id="material_total_<?php echo $value->material_id?>" /></div>
                            </div>
                          </td>
                        <?php }
                      } ?>
                      <td>
                        <?php if($project_data->project_section!='Road Marking'){ ?>
                          <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                            <div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" readonly type="text" class="form-control m-input" data-sl-no="<?php echo $i + 1 ?>" value="0" name="total_material_qty" id="total_material_qty" /></div>
                          </div>
                        <?php } ?>
                      </td>
                      <?php if($project_data->project_section=='Road Marking'){ ?>
                        <td>
                          <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                            <div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" readonly type="text" class="form-control m-input" data-sl-no="<?php echo $i + 1 ?>" value="0" name="total_measure_qty" id="total_measure_qty" /></div>
                          </div>
                        </td>
                      <?php } ?>
                      <td>
                      </td>
                    </tr>
                  </tfoot>
                </table>
                <input type="hidden" value="<?php echo $i ?>" id="current_row_count_measurements" name="current_row_count_measurements">
                <input type="hidden" value="<?php echo $i ?>" id="actual_row_count_measurements" name="actual_row_count_measurements">
              </div>
            </div>
          </div>
        </div>
        <div style="background: white;border: 4px solid #f7f7fa;padding: 15px;margin: 5px;padding-bottom: 0px">
          <div class="m-section" style="margin-bottom: 10px">
            <h3 class="m-section__heading">Step 2 - Material Consumption Details [On <?php echo $work_date?>]</h3>
            <div class="row">
              <div class="col-lg-12">
                <table width="100%" class="table m-table table-bordered item_table m-table--head-bg-info" id="stock_consumption_table">
                  <thead>
                    <tr class="">
                      <th>Sl No</th>
                      <th>Material Name</th>
                      <th>Unit</th>
                      <th>Opening Stock</th>
                      <th>Received Qty</th>
                      <th>Consumed Qty</th>
                      <th>Balance Qty</th>
                      <th>Remarks</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php foreach ($stock_materials as $key => $value) {?>
                      <tr>
                        <td>
                          <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                            <div  class="input-group m-input-group m-input-group--pill m-input-group--air"><input readonly style="padding: 10px" readonly type="text" class="form-control m-input" value="<?php echo $key + 1 ?>" /></div>
                          </div>
                        </td>
                        <td>
                          <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                            <div  class="input-group m-input-group m-input-group--pill m-input-group--air"><input readonly style="padding: 10px" readonly type="text" class="form-control m-input" value="<?php echo $value->material_name ?>" /></div>
                          </div>
                        </td>
                        <td>
                          <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                            <div  class="input-group m-input-group m-input-group--pill m-input-group--air"><input readonly style="padding: 10px" readonly type="text" class="form-control m-input" value="<?php echo $value->unit_name ?>" /></div>
                          </div>
                        </td>
                        <td>
                          <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                            <div  class="input-group m-input-group m-input-group--pill m-input-group--air"><input readonly style="padding: 10px" readonly type="text" class="form-control m-input" value="<?php echo $value->opening_stock_today ?>" name="materials[opening_qty][<?php echo $value->material_id ?>]" id="material_opening_qty_<?php echo $value->material_id ?>" /></div>
                          </div>
                        </td>
                        <td>
                          <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                            <div  class="input-group m-input-group m-input-group--pill m-input-group--air"><input readonly style="padding: 10px" readonly type="text" class="form-control m-input" value="<?php echo $value->received_qty_today ?>" name="materials[received_qty][<?php echo $value->material_id ?>]" id="material_received_qty_<?php echo $value->material_id ?>" /></div>
                          </div>
                        </td>
                        <td>
                          <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                            <div  class="input-group m-input-group m-input-group--pill m-input-group--air"><input  style="padding: 10px" required <?php if($project_data->project_section!='Road Marking'){ echo 'readonly';}?> type="text" class="form-control m-input numeric_fields material_consumed_qty_fields" value="0" data-material-id="<?php echo $value->material_id ?>" name="materials[consumed_qty][<?php echo $value->material_id ?>]" id="material_consumed_qty_<?php echo $value->material_id ?>" name="consumed_qty" /></div>
                          </div>
                        </td>
                        <td>
                          <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                            <div  class="input-group m-input-group m-input-group--pill m-input-group--air"><input readonly style="padding: 10px" readonly type="text" class="form-control m-input" value="<?php echo $value->opening_stock_today+$value->received_qty_today ?>" name="materials[balance_qty][<?php echo $value->material_id ?>]" id="material_balance_qty_<?php echo $value->material_id ?>" /></div>
                          </div>
                        </td>
                        <td>
                          <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                            <div  class="input-group m-input-group m-input-group--pill m-input-group--air"><input  style="padding: 10px" type="text" class="form-control m-input" name="materials[remarks][<?php echo $value->material_id ?>]"  /></div>
                          </div>
                        </td>
                      </tr>
                    <?php } ?>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="m-portlet__foot m-portlet__foot--fit">
        <div class="m-form__actions m-form__actions">
          <div class="row">
            <div class="col-lg-9 ml-lg-auto">
              <button type="submit" class="btn btn-brand form_submit_btn">
                Submit
              </button>
              <button type="reset" class="btn btn-secondary">
                Cancel
              </button>
            </div>
          </div>
        </div>
      </div>
    </form>
  </div>
</div>

</div>
</div>
<!-- end:: Body -->
<!-- begin::Footer -->
<!-- end::Footer -->
<!-- end:: Page -->
<?php $this->view("includes/Inc_footer");?>
</div>

<?php $this->view("includes/Inc_sidebar");?>
<?php $this->view("includes/Inc_scripts");?>


<!--begin::Page Snippets -->
<script>
$("#table_filter_status").selectpicker();
$("[data-switch=true]").bootstrapSwitch()
</script>
<!--end::Page Snippets -->
<script>

$("#works_menu").addClass('m-menu__item--active m-menu__item--open');
$("#works_menu_2").addClass('m-menu__item--active');

//    Toggle Sidebar
$("#m_aside_left_minimize_toggle").addClass("m-brand__toggler--active");
$("#body").addClass("m-brand--minimize m-aside-left--minimize");

$("#start_time, #end_time").timepicker({defaultTime:""});
$("#work_date").datepicker( {
  todayHighlight:!0, orientation:"bottom left", templates: {
    leftArrow: '<i class="la la-angle-left"></i>', rightArrow: '<i class="la la-angle-right"></i>'
  }
})
$(".m_selectpicker").selectpicker();
$('.m_selectpicker').selectpicker('refresh');

$("#subcontract_add").select2({
  placeholder: "Select Subcontract",
  // dropdownParent: $("#form_vehicle_work_slip_add")
})
$("#supervisor").select2({
  placeholder: "Select Supervisor",
})
function select_subcontracts(select_id,selected_value='',project){
  $('#'+select_id).html('');
  $('#'+select_id).append("<option disabled selected >Select Subcontract</option>");
  if(project!='' && project!=null && project!='Select Location'){
    $.post("<?php echo base_url() ?>subcontracts/select_subcontracts_list",{work:project},function(data) {
      var obj = $.parseJSON(data);
      var i=0;
      if(obj.count>0) {
        while (i < obj.data.length) {
          $('#'+select_id).append("<option  value=" + obj.data[i]['contract_id'] + ">" + obj.data[i]['sub_work_name'] + " [" + obj.data[i]['contractor_name'] + " - " + obj.data[i]['contractor_phone'] + "]</option>");
          i++;
        }
        if(selected_value!=''){
          $("#"+select_id).val(selected_value).trigger("change");
        }
      }
    })
  }
}
select_subcontracts("subcontract_add",'','<?php echo $boq_data->project_id ?>');
select_users('supervisor','','supervisor','<?php echo $boq_data->project_id ?>');

function select_users(select_id,branch_id='',user_role='',project=''){
  $('#'+select_id).html('');
  $('#'+select_id).append("<option disabled selected >Select Supervisor</option>");
  $.post("<?php echo base_url() ?>work/select_assigned_users/select",{work_id:project},function(data) {
    var obj = $.parseJSON(data);
    var i=0;
    if(obj.count>0) {
      while (i < obj.id.length) {
        $('#'+select_id).append("<option value=" + obj.id[i] + ">" + obj.name[i] + "</option>");
        i++;
      }
    }
  })
}
</script>

<script>

$("#addrow_measurements").on("click", function() {
  var i = parseInt($('#current_row_count_measurements').val());

  var new_row = '<tr class="row_'+(i+1)+'">'+
  '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">'+
  '<div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" readonly type="text" class="form-control m-input item_slno" data-sl-no="'+(i+1)+'" name="measurements[sl_no]['+(i)+']" value="'+(i+1)+'" /></div>'+
  '</div></td>'+
  '<td>'+
  <?php if($project_data->project_section=='Road Marking'){?>
    '<div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">'+
      '<select required class="form-control m-bootstrap-select m-bootstrap-select--air m-bootstrap-select--pill m_selectpicker" data-sl-no="<?php echo $i + 1 ?>" name="measurements[chainage_from]['+(i)+']" id="chainage_from_'+(i+1)+'" title="Description">'+
        '<option selected disabled>Select Description</option>'+
        '<option value="Continue">Continue</option>'+
        '<option value="Strip">Strip</option>'+
        '<option value="Stop Line">Stop Line</option>'+
        '<option value="Dot Line">Dot Line</option>'+
        '<option value="Chevron">Chevron</option>'+
        '<option value="Hatching">Hatching</option>'+
        '<option value="PC">PC</option>'+
        '<option value="Hump">Hump</option>'+
        '<option value="Side Line">Side Line</option>'+
        '<option value="Gap">Gap</option>'+
        '<option value="Rumble Strip">Rumble Strip</option>'+
        '<option value="Lamp Round">Lamp Round</option>'+
        '<option value="Cheveron Round">Cheveron Round</option>'+
        '<option value="Cheveron Side Line">Cheveron Side Line</option>'+
        '<option value="Divider Line">Divider Line</option>'+
        '<option value="Busway Line">Busway Line</option>'+
      '</select><span class="m-form__help"></span></div>'+
  <?php }else{ ?>
  '<div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">'+
  '<div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" required type="text" class="form-control m-input" data-sl-no="'+(i+1)+'" name="measurements[chainage_from]['+(i)+']" id="chainage_from_'+(i+1)+'" /></div></div>'+
<?php } ?>
  '</td>'+
  <?php if($project_data->project_section=='Sign Boards'){?>
    '<td>'+
      '<div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">'+
        '<select required class="form-control m-bootstrap-select m-bootstrap-select--air m-bootstrap-select--pill m_selectpicker" data-sl-no="'+(i+1)+' item_material_id" name="measurements[item]['+(i)+']" id="item_'+(i+1)+'" title="Item">'+
          '<option selected disabled>Select Item</option>'+
        <?php foreach ($stock_materials as $key => $value) {?>
          '<option value="<?php echo $value->material_id?>"><?php echo $value->material_name?></option>'+
        <?php } ?>
        '</select>'+
        '<span class="m-form__help"></span>'+
      '</div>'+
    '</td>'+
  <?php } ?>
  <?php if($project_data->project_section!='Road Marking' && $project_data->project_section!='Sign Boards'){?>
  '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">'+
  '<div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" required type="text" class="form-control m-input" data-sl-no="'+(i+1)+'" name="measurements[chainage_to]['+(i)+']" id="chainage_to_'+(i+1)+'" /></div>'+
  '</div></td>'+
  <?php } ?>
  '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">'+
  '<select required class="form-control m-bootstrap-select m-bootstrap-select--air m-bootstrap-select--pill m_selectpicker" data-sl-no="'+(i+1)+'" name="measurements[side]['+(i)+']" id="side_'+(i+1)+'" title="Side">'+
  <?php
  $measurement_sides = $this->config->item('Measurement_Sides');
  foreach($measurement_sides as $row){
    ?>
    '<option value="<?php echo $row?>"><?php echo $row?></option>'+
    <?php } ?>
    '</select><span class="m-form__help"></span></div></td>'+
    <?php if($project_data->project_section=='Road Marking' || $project_data->project_section=='Sign Boards'){?>
      '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">'+
      '<div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" required type="text" class="form-control m-input numeric_fields row_'+(i+1)+'_qty_fields length_qty_fields" data-sl-no="'+(i+1)+'"  name="measurements[qty_no]['+(i)+']" id="qty_no_'+(i+1)+'" value="0" /></div>'+
      '</div></td>'+
      <?php } ?>
    <?php if($project_data->project_section=='Road Studs'){?>
      '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">'+
      '<div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" required type="text" class="form-control m-input" data-sl-no="'+(i+1)+'" name="measurements[spacing]['+(i)+']" id="spacing_'+(i+1)+'" /></div>'+
      '</div></td>'+
      <?php }elseif($project_data->project_section=='Crash Barriers' || $project_data->project_section=='Road Marking'){?>
        '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">'+
        '<div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" required type="text" class="form-control m-input numeric_fields row_'+(i+1)+'_qty_fields length_qty_fields" data-sl-no="'+(i+1)+'"  name="measurements[length]['+(i)+']" id="length_'+(i+1)+'" value="0" /></div>'+
        '</div></td>'+
        <?php } ?>
        <?php if($project_data->project_section=='Road Marking'){?>
          '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">'+
          '<div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" required type="text" class="form-control m-input numeric_fields row_'+(i+1)+'_qty_fields length_qty_fields" data-sl-no="'+(i+1)+'"  name="measurements[width]['+(i)+']" id="width_'+(i+1)+'" value="0" /></div>'+
          '</div></td>'+
          <?php } ?>
          <?php if($project_data->project_section=='Road Marking'){?>
            '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">'+
            '<div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" required readonly type="text" class="form-control m-input numeric_fields row_'+(i+1)+'_qty_fields total_qty_fields" data-sl-no="'+(i+1)+'"  name="measurements[total_qty]['+(i)+']" id="total_qty_'+(i+1)+'" value="0" /></div>'+
            '</div></td>'+
            <?php } ?>
        <?php
        if($project_data->project_section!='Road Marking'){
        foreach ($stock_materials as $key => $value) {?>
          '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">'+
          '<div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" required type="text" <?php if($project_data->project_section=='Sign Boards'){ echo 'readonly';}?> class="form-control m-input row_'+(i+1)+'_qty_fields material_qty_field material_qty_field_'+(i+1)+' material_<?php echo $value->material_id?>" data-material-id="<?php echo $value->material_id?>" data-sl-no="'+(i+1)+'" value="0" name="measurements[material_qty]['+(i)+'][<?php echo $value->material_id?>]" id="material_<?php echo $value->material_id?>_'+(i+1)+'" /></div>'+
          '</div></td>'+
          <?php }
        } ?>
        <?php if($project_data->project_section=='Sign Boards'){?>
          '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">'+
          '<div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px"  type="text" class="form-control m-input " data-sl-no="'+(i+1)+'"  name="measurements[ref_no]['+(i)+']" id="ref_no_'+(i+1)+'" /></div>'+
          '</div></td>'+
          <?php } ?>
          '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">'+
          '<div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px"  type="text" class="form-control m-input" data-sl-no="'+(i+1)+'" name="measurements[remarks]['+(i)+']" id="remarks_'+(i+1)+'" /></div>'+
          '</div></td>'+
          '<td><a href="javascript:" data-row-sl-no="'+(i+1)+'" class="ibtnDel_measurements btn btn-sm btn-danger btn-icon-only"><i class="fa fa-trash"></i></a></td>'+
          '</tr>';

          $('#table_body_measurements').append(new_row);
          $('#current_row_count_measurements').val((i+1));
          $(".m_selectpicker").selectpicker();
          $('.m_selectpicker').selectpicker('refresh');
        });

        $("#table_body_measurements").on("click", ".ibtnDel_measurements", function(event) {
          var row_sl_no = $(this).data('row-sl-no');
          $('.row_'+row_sl_no+'_qty_fields').val(0).change();
          var counter = parseInt($("#actual_row_count").val());
          $('.row_'+row_sl_no).remove();
          counter -= 1;
          $("#actual_row_count").val(counter);

          //rearrange higher sl no
          var new_sl_no = 0;
          $(".item_slno").each(function () {
            new_sl_no++;
            $(this).val(new_sl_no);
          })
        });

        function init_table() {
          $('#table_boq_list').dataTable().fnDestroy();
          var table = $('#table_boq_list').dataTable({
            "scrollX" : true,
            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
            "columnDefs": [
              {
                "targets": [1,2],
                className: "hidden"
              }
            ],
            'order': false,
            'ordering':false,
            "paging":false,
            "searching":false
          });
          $("body").on("change", ".checkbox_display", function (event) {
            $('#table_boq_list').DataTable()
            .columns.adjust()
            .responsive.recalc();
          })
        }
        </script>
        <script type="text/javascript">
        var project_id="<?php echo $boq_data->project_id ?>";
        var boq_id="<?php echo $boq_data->boq_id ?>";

        </script>

        <script>
        <?php if($project_data->project_section=='Crash Barriers'){?>
          $("body").on("change keyup", ".length_qty_fields", function (event) {
            var total_qty = 0;
            $(".length_qty_fields").each(function () {
              total_qty+= parseFloat($(this).val());
            })
            $("#total_length_qty").val(total_qty);
          })
          <?php } ?>
          <?php if($project_data->project_section=='Sign Boards'){?>
            $("body").on("change keyup", ".length_qty_fields,.item_material_id", function (event) {
              var sl_no = $(this).data('sl-no');
              var qty = parseFloat($("#qty_no_"+sl_no).val());
              var material_item_id = $("#item_"+sl_no+" :selected").val();
              $(".material_qty_field_"+sl_no).val(0).trigger('change');
              if(material_item_id!='' && material_item_id!=null && material_item_id!='Select Item'){
                $("#material_"+material_item_id+"_"+sl_no).val(qty);
              }
              calculate_material_qty(material_item_id);
            })
            <?php } ?>
          <?php if($project_data->project_section=='Road Marking'){ ?>
            $("body").on("change keyup", ".length_qty_fields", function (event) {
              var total_qty = 0;
              var sl_no = $(this).data('sl-no');
              $(".length_qty_fields").each(function () {
                var length = parseFloat($("#length_"+sl_no).val());
                var width = parseFloat($("#width_"+sl_no).val());
                var no = parseFloat($("#qty_no_"+sl_no).val());
                var total = length*width*no;
                $("#total_qty_"+sl_no).val(total);
              })
              $(".total_qty_fields").each(function () {
                total_qty += parseFloat($(this).val());
              })
              $("#total_measure_qty").val(total_qty);
            })
            <?php } ?>
          function calculate_material_consumption(material_id){
            var opening_qty = parseFloat($("#material_opening_qty_"+material_id).val());
            var received = parseFloat($("#material_received_qty_"+material_id).val());
            var consumed_qty = parseFloat($("#material_consumed_qty_"+material_id).val());
            var balance_qty = opening_qty+received-consumed_qty
            $("#material_balance_qty_"+material_id).val(balance_qty);
          }
          $("body").on("change keyup", ".material_consumed_qty_fields", function (event) {
            var material_id = $(this).data('material-id');
            calculate_material_consumption(material_id);
          })
          $("body").on("change keyup", ".material_qty_field", function (event) {
            var material_id = $(this).data('material-id');
            calculate_material_qty(material_id);
          })
          function calculate_material_qty(material_id){
            var total_qty = 0;
            $(".material_"+material_id).each(function () {
              total_qty+= parseFloat($(this).val());
            })
            $("#material_total_"+material_id).val(total_qty);
            $("#material_consumed_qty_"+material_id).val(total_qty);
            calculate_material_consumption(material_id);
            calculate_sum();
          }

          function calculate_sum(){
            // get Items
            var total_qty = 0;
            $(".total_material_qty_fields").each(function () {
              total_qty+= parseFloat($(this).val());
            })
            $("#total_material_qty").val(total_qty);
          }

          </script>

          <script>

          jQuery(document).ready(function() {
            $(".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: 1,
                    number: !0
                  },
                  "budget": {
                    number: !0,
                    required: !0,
                  }
                }, invalidHandler: function (e, r) {
                  var i = $("#" + form_id + "_msg");
                  i.removeClass("m--hide").show(), mUtil.scrollTo(i, -200)
                }, submitHandler: function (e) {
                }
              }),
              $(".numeric_fields").each(function () {
                $(this).rules('add', {
                  number: !0
                });
              }),
              l.valid() && (a.addClass("m-loader m-loader--right m-loader--light").attr("disabled", !0),
              l.ajaxSubmit({
                url: action,
                success: function (e, t, r, s) {
                  var modal_id = l.attr('data-modal-id');
                  var form_type = l.attr('data-form-type');
                  $("#" + form_id + "_msg").addClass("m--hide");
                  // Block UI
                  mApp.blockPage({
                    overlayColor: "#000000",
                    type: "loader",
                    state: "success",
                    message: "Please wait..."
                  }), setTimeout(function () {
                    mApp.unblockPage()
                  }, 2e3);
                  var obj = $.parseJSON(e);
                  if (obj.status == 1) {
                    a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
                    toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
                    swal({
                      width: 500,
                      title: obj.flashdata_title,
                      text: obj.flashdata_msg,
                      type: obj.flashdata_type,
                      // showCancelButton: !0,
                      confirmButtonText: "OK",
                      // cancelButtonText: "Add New Project",
                      confirmButtonColor: '#3085d6',
                      cancelButtonColor: '#d33',
                      reverseButtons: !0,
                      closeOnClickOutside: false,
                      allowOutsideClick: false,
                    }).then(function(e) {
                      window.location.replace("<?php echo base_url()?>boq/profile/<?php echo $boq_data->boq_id ?>");
                    })
                  } 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>
