
@extends('layouts.admin')
@section('pageTitle', 'Vega Soft')
@section('page-content')

<input type="hidden" id="table_settings_field" branch_id="" branch_name=""  column_heading="<?= $rows->column_heading;?>" column_width="<?= $rows->column_width;?>" column_alighn="<?= $rows->column_alighn;?>"  column_conversion="<?= $rows->column_conversion;?>" settings_row_id="<?= $id;?>" sp_date_picker="<?= $rows->sp_date_picker;?>"  header_from_date="<?=date('d-m-Y', strtotime('-7 days')); ?>"   header_till_date="<?=date('d-m-Y'); ?>"  sp_sort="<?= $rows->menu_id; ?>"  active_mn="<?= $rows->root;?>"  active_mnt="<?= $rows->menu_type;?>">
<style type="text/css">
  #po_tab td{
    font-size: 0.8rem;
    font-weight: bold;
border: none;
padding: 0.3rem;
  }

 #po_tab  .bord_mid{
  width: 2%;
 }
 #po_tab  .second_td{
    width: 72%;
       font-weight: unset; 
  }
  .pad{
    padding: 0.45rem 2.5rem;
  }
  .load{
    cursor: pointer;
  }
    .load:hover{

    background-color: #e93755;
    font-weight: bold;
  }
 .table  tfoot th{
  margin-bottom: 0px;
 }
 .table  thead th{
background-color: #bff5f6;
 }
 .table  tfoot th{
    padding: 0px;
  }
 .table tbody td{
    padding: 0.5375rem;
  }

.badge{
  cursor: pointer;
}

#po_description{
  white-space: break-spaces;
  word-wrap: break-word;
}
</style>
<div id="form-div">
<input type="hidden" id="hidden_status" value="0">
<input type="hidden" id="row_id" value="0">


<div class="page-header form-header" >
  <h3 class="page-title text-white"> <?= $rows->menu_name;?> </h3>
    <nav aria-label="breadcrumb">
      <ol class="breadcrumb">
      <!-- 
        <li class="breadcrumb-item text-white  icon-md " aria-current="page"><i class="icon-list slide1"></i> </li> -->
      </ol>
    </nav>
    

    <input type="hidden" id="table_settings_field" branch_id="" branch_name=""  column_heading="<?= $rows->column_heading;?>" column_width="<?= $rows->column_width;?>" column_alighn="<?= $rows->column_alighn;?>"  column_conversion="<?= $rows->column_conversion;?>" settings_row_id="<?= $id;?>" sp_date_picker="<?= $rows->sp_date_picker;?>"  header_from_date="<?=date('d-m-Y', strtotime('-7 days')); ?>"   header_till_date="<?=date('d-m-Y'); ?>"  sp_sort="<?= $rows->menu_id; ?>"   >
    @if ($rows->sedp != "")
  @foreach(explode(',', $rows->sedp) as  $z=>$info) 
     @if ($info == "1" && $z==1)
       <input type="hidden" class="additional_btns" btn_text="Edit" btn_click_function="call_edit_modal" btn_class="btn btn-success btn-sm btn-dtbl" col_width="30" >
     @endif 
     @if ($info == "1" && $z==2)
        <input type="hidden" class="additional_btns" btn_text="Cancel Payment" btn_click_function="call_remove_modal" btn_class="btn btn-danger btn-sm btn-dtbl" col_width="40"  >
     @endif 
     @if ($info == "1" && $z==3)
          <input type="hidden" class="additional_btns" btn_text="Print" btn_click_function="call_print_function2" btn_class="btn btn-info btn-sm btn-dtbl" col_width="40"  >
     @endif
  @endforeach
@endif
</div>
<div class="row quick-action-toolbar">
              <div class="col-md-12 grid-margin">
                <div class="card">
                  <div class="card-header d-block d-md-flex">
                            <div class="row report-inner-cards-wrapper" style="padding-top: 0PX; width: 100%;">
                      <div class=" col-md-6 col-xl report-inner-card" style="padding: 0;display: block;">
                        P.o Number <br>

                  <input type="text" class="form-control floating " id="po_no" autocomplete="off" pod_a_id="">
                      </div>
                      <div class="col-md-6 col-xl report-inner-card" style="padding: 2px;display: block;">
                         Contractor Name <br>

               <input type="text" class="form-control " id="contcrtr" c_id="0">
                      </div><br><div class="col-md-6 col-xl report-inner-card"><div style="height: 53%;" class="badge badge-danger p-2 load" onclick="fetch_report()">  <i class="icon-bulb"> Load result</i></div></div>
                    
                    </div>
                    
                        <table class="table" id="po_tab">
                      <thead>

                      </thead><tbody>
                        <tr>
                          <td>P.O DATE </td>
                          <td class="bord_mid">:</td>
                          <td id="po_date" class="second_td"></td>
                          <td>P.O CONTRACT NO </td>
                          <td class="bord_mid">:</td>
                          <td id="po_con_no" class="second_td"></td>
                        </tr>
                        <tr>
                          <td>P.O DESCRIPTION</td>
                          <td class="bord_mid">:</td>
                          <td id="po_description" class="second_td"></td>
                        <!-- </tr>
                        <tr> -->
                          <td>P.O Amount</td>
                          <td class="bord_mid">:</td>
                          <td id="po_amount" class="second_td"></td>
                        </tr>
                        
                      </tbody>
                    </table>
                      
                  </div>
           
                 <div class="card-body">
                 <div class="col-lg-12 " id="table_div">
                  
                       
                

                 </div>
                 </div>
                </div>
              </div>
            </div>



<input type="hidden" id="serverValue2" value="<?php echo date('m'); ?>">



<script type="text/javascript">


$(document).ready(function(){


 
 });




</script>


@endsection

@section('page-script')
<script type="text/javascript">
  
  function fetch_report() {
       arr={
               
               'row_id': $('#po_no').attr('pod_a_id'),
               'c_id': $('#contcrtr').attr('c_id'),
};

  

           $.ajax({
         url: "/get_data",
          type: "POST",
          data:{
             '_token': "{{ csrf_token() }}",
              'row_id':JSON.stringify(arr),
              url1:'fetch_contcrtr_report.php'
          },
          success:function(response){

         po_list=response.edit;  
                            trs='<table   class="table"   id="dynamic_rep_table">';
                      trs+='<colgroup>';
                        trs+='<col width="10px">';
                        trs+='<col width="130px">';
                        trs+='<col width="130px">';
                        trs+='<col width="130px">';
                        trs+='<col width="130px">';
                        trs+='<col width="130px">';
                        trs+='<col width="130px">';
                      trs+='</colgroup>';
                        trs+='<thead>';
                          trs+='<tr >';
                          trs+='<th class="font-weight-bold" >SL</th>';
                          trs+='<th class="font-weight-bold" style="width:30px !important">Contractor  Name</th>';
                          trs+='<th class="font-weight-bold" style="width:30px !important">Name</th>';
                          trs+='<th class="font-weight-bold" >Date</th>';
                          trs+='<th class="font-weight-bold" >Remarks</th>';
                          trs+='<th class="font-weight-bold text-right">Payment</th>';
                          trs+='<th class="font-weight-bold text-right">Gst</th>';
                          trs+='</tr>';
                        trs+='</thead>';
                   /*     trs+='<tfoot style="display: table-header-group;">';
                          trs+='<tr class="table-primary">';
                          trs+='<th></th>';
                          trs+='<th><input type="text" placeholder="Search" autocomplete="false"  class="form-control "  /></th>';
                          trs+='<th><input type="text" placeholder="Search" autocomplete="false"  class="form-control "  /></th>';
                          trs+='<th><input type="text" placeholder="Search" autocomplete="false"  class="form-control "  /></th>';
                          trs+='</tr>';
                        trs+='</tfoot>';*/
                         j=1;
         $(po_list).each(function(i,val) {
        
          if(val['Typeorder']==2||val['Typeorder']==4||val['Typeorder']==6){
             j=1;
  trs+='<tr class="text-danger ">';
                          trs+='<td></th>';
                          trs+='<td class="font-weight-bold">'+val['contrct_name']+'</td>';
                          trs+='<td class="font-weight-bold">'+val['name']+'</td>';
                          trs+='<td class="font-weight-bold">'+val['day']+'</td>';
                          trs+='<td class="font-weight-bold text-right">'+val['remark']+'</td>';
                          trs+='<td class="font-weight-bold text-right">'+val['Amount']+'</td>';
                          trs+='<td class="font-weight-bold text-right">'+val['gst']+'</td>';
                           trs+='</tr>';
}else{

    trs+='<tr>';
                          trs+='<td>'+j+'</td>';
                          trs+='<td>'+val['contrct_name']+'</td>';
                          trs+='<td>'+val['name']+'</td>';
                          trs+='<td>'+val['day']+'</td>';
                          trs+='<td>'+val['remark']+'</td>';
                          trs+='<td class=" text-right">'+val['Amount']+'</td>';
                          trs+='<td class=" text-right">'+val['gst']+'</td>';
                           trs+='</tr>';
}
 j++;

         });
         trs+='  </table>';
$("#table_div").html(trs);

load_table();
          },
          error: function(response) {
          }
         });
  }
  function load_table() {
 var table = $('#dynamic_rep_table').DataTable({
        dom: 'lBfrtip',
        'autoWidth':false,
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'colvis'
        ],
        "ordering": false,
        "searching": false,
        "bLengthChange": true,
        "bPaginate": false,
        "bSort" : true,
         "bInfo" : false,
        columnDefs: [ {
            visible: false
        } ]
        
        
    });
     table.columns().every( function () {
        var that = this;
 
        $( 'input', this.footer() ).on( 'keyup change', function () {
            if ( that.search() !== this.value ) {
                
                that.search( this.value ).draw(); 
                
            }
        } );
    } );
    
    
    
     table.on( 'order.dt search.dt', function () {
        table.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
            cell.innerHTML = i+1;
        } );
    } ).draw();

  // body...
}

$(document).on('keyup keydown', '#po_no', function (e) {
  ename=$.trim($(this).val());
  id=$(this).attr('id');
  $(this).tableAutocomplete({
    appendTo:".autocomplete_result2",
        source:  function( request, response ) {
$.ajax({
url: "/fetch_po_no_val",
type: "POST",

data: {
  '_token': "{{ csrf_token() }}",
ename: ename,
id:id

},
dataType: "json",
success: function( data ) {

response( $.map( data, function( item ) {
return {

 name: item.po_con_no,                   
 value: item.value,
 po_no:item.po_no,
 pod_a_id:item.pod_a_id,
 desc:item.po_description,                 
 po_amount:item.po_amount,                 
 po_date:item.po_date ,                
 po_con_no:item.po_con_no                 
                  
                  

}
}));
}
});
},
        columns: [ {
            field: 'po_no',
            title: 'Po No',
            width: '30%'
        },{
            field: 'name',
            title: 'Po Contract No',
            width: '30%'
        },
        {
            field: 'desc',
            title: 'Desc',
            width: '30%'
        }],
         change : function(event, ui) {
                   if ( !ui.item ) 
                   { 
                    alert('Not Found');
                   $(this).val('')
                  $('#po_no').val('');
                  $('#po_con_no').html('');
                  $('#po_no').attr('pod_a_id','0');
$("#po_amount").html('');
$("#po_description").html('');
$("#po_date").html('');
             
                   }
                   else
                   {
                      
                   }
           },
               open: function(event, ui) {}, 
        select: function (event, ui) {
          if (ui.item.value!=undefined)
                {

                  $(this).val(ui.item.value);
                  $('#po_no').val(ui.item.po_no);
                  $('#po_con_no').html(ui.item.po_con_no);
                  $('#po_no').attr('pod_a_id',ui.item.pod_a_id);
$("#po_description").html(ui.item.desc);
$("#po_amount").html(ui.item.po_amount);
$("#po_date").html(ui.item.po_date);
//fetch_report();
               
                }
              
  
        }
    });
    });

$(document).on('keyup', '#contcrtr', function (e) {
  ename=$.trim($(this).val());
 
  $(this).tableAutocomplete({

    appendTo:".autocomplete_result2",
        source:  function( request, response ) {
$.ajax({
url: "/fetch_sup_con",
type: "POST",

data: {
  '_token': "{{ csrf_token() }}",
ename: ename,
po_id: $('#po_no').attr('pod_a_id'),
type:0

},
dataType: "json",
success: function( data ) {

response( $.map( data, function( item ) {
return {

 name: item.c_name,                   
 value: item.c_name,
 pa_no: item.pa_no,
 pad_id: item.pad_id,
 c_id:item.c_id                
                  
                  

}
}));
}
});
},
        columns: [ 
        {
            field: 'name',
            title: 'Name',
            width: '50%'
        },{
            field: 'pa_no',
            title: 'Work Order',
            width: '50%'
        }],
         change : function(event, ui) { console.log(ui.item );
                   if (ui.item ==null) 
                   { 
                   $('#contcrtr').val('');
                  $('#contcrtr').attr('c_id','0');
                  
             
                   }
                   
                  
           },
               open: function(event, ui) {}, 
        select: function (event, ui) {
          if (ui.item.value!=undefined)
                {
                  $(this).val(ui.item.name);
                  $(this).attr('c_id',ui.item.c_id);
                 // get_details_receipt();
               
                }else { 
                   $('#contcrtr').val('');
                  $('#contcrtr').attr('c_id','0');
                  
             
                   }
              
  
        }
    });
    });
</script>
@endsection