<?php $__env->startSection('page-content'); ?>

<style>

.accordion-toggle:hover{
  background:grey !important;
  color:white;
  cursor:pointer;
}
.td-rt{
  text-align:right;
}

.td-lt{
  text-align:left;
}
.td-ct{
  text-align:center;
}
#dynamic_ajax_table_info{
  display:none;
}
.table td{
  line-height:0.1 !important;
}
.btm_dv{

  width:100%;
  background:#bcc6b6;
  font-weight:bold;
  font-family:'Roboto',sans-serif;
  height:20px;

position: fixed;
bottom: 6mm;

}
.pd{
font-weight:bold;
}


.card-body{
  padding:0px !important;
}

.hiddenRow{
  padding:0px !important;
}
.ico:hover{
  cursor:pointer;

}
.ico{
  color:green;
  font-size:15px;
}

.wrk_ordr_tbdy tbody tr:first-child{
  background: lightgrey;
}
.wrk_ordr_tbdy tbody tr:last-child{
  background: lightgrey;
}
.bd_cls{
  background:red;
}
.bd_cls2{
  background:#ffc0c0;
}
.bd_cls3{
  background:#d2b08b;
}
.bd_cls5{
  background:red;
}

#form-div{
  overflow-y:scroll;
  scrollbar-width: thin;
}

.ico:hover{
  cursor: pointer;
  font-size:19px;

}





</style>


<div class="container-fluid" style="padding-top:0px !important;">
<div class="card-body">
<div id="form-div">
    <?php if(session('usergroup')==1): ?>
                       

<div id="main-tab">

<div class="col-md-12 grid-margin stretch-card">
                <div class="card">
                  <div class="card-body">
                    <br>
                  <!-- <div style="float:right;">Select Date:<input type="text" readonly  onchange="load_index();" class="date_class form-control" id="p_date"></div> -->

                    <div class="d-sm-flex align-items-center ">
                      <h4 class="card-title mb-sm-0">Purchase Orders</h4>
                      <div class="col-lg-3 col-md-3 col-sm-3">

<input type="text" id="srch_po" placeholder="Search" class="form-control" style="border:1px solid grey !important;"> 

                      </div>
                   
                    </div>
                    <div class="table-responsive border rounded p-1">
                    <div class="containers" style="margin:0px !importatnt;">
	<div class="col-md-12">




    	<div class="panel panel-default">
				
        <div class="panel-body">
					<table class="table table-md table-striped">
    <thead>
        <tr>
				
        <th class="font-weight-bold">Po Number</th>
                            <th class="font-weight-bold">Po Con Number</th>
                            <th class="font-weight-bold">Po Date</th>
                            <th class="font-weight-bold">Po Amount</th>
                            <th class="font-weight-bold">Short Code</th>
                            <th class="font-weight-bold">Billed Value</th>
                            <th class="font-weight-bold">Total Expense</th>
                            <th class="font-weight-bold">Recevied Amt.</th>
                            <th class="font-weight-bold">Balance Amt.</th>

                            <th class="font-weight-bold" class="td-ct">Est.Complt Date</th>
                            <th class="font-weight-bold">Pay Status</th>
                            <th class="font-weight-bold"></th>
        </tr>
    </thead>

    <tbody id="dash_tbl_tbdy">
      
      
      
		
    </tbody>
</table>
            </div>
        
          </div> 
        
      </div>
	</div>
       

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


</div>

<div id="sec-tab">

  <div id="lbl_div">

  </div>

<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12" >



  <table class="table-responsive border table-bordered  p-3" style="font-size:13px;">
 
    <thead class="bg-primary text-white">
      <tr style="background:grey;color:white;text-align:center;"><th colspan="9">Work Orders</th></tr>
<tr>
  <th style="width: 5%;">

  Sl No
  </th>
  <th style="width: 15%;">

  Work Order
  </th>
  <th style="width: 10%;">

Start Date
  </th>
  <th style="width: 10%;">

End  Date
  </th>

  <th style="width: 20%;">

Contractor
  </th>
  <th style="width: 10%;">

Added By
  </th>
  <th style="width: 15%;">

Est Cost
  </th>
  <th style="width: 25%;">

Paid Amount
  </th>
  <th></th>


</tr>

    </thead>

    <tbody id="wrk_order_tbdy">



    </tbody>


  </table>


</div>
<!-- <div class="col-lg-12 col-md-12 col-sm-12 p-3">
  <div style="background:grey;color:white;text-align:center;font-weight:bold;font-size:13px;">Supplier Payments</div>
<table class="table table-bordered">
    <thead class="bg-warning">

      <tr>
        <th>Sl No</th>
        <th>Supplier Name</th>

        
        <th>Pay Date </th>
        <th>Remarks </th>
        <th>Bill </th>
        <th>Billed Amount </th>
        <th>Paid Amount</th>
      </tr>
    </thead>
    <tbody id="sup_pay_tbdy">
     
    </tbody>
  </table>
</div> -->

<div class="col-lg-12 col-md-12 col-sm-12 btm_dv">


<div class="row ">
    <div class="col-3 col-lg-3 col-md-3 col-sm-3 ">
      <span class="sp">PO Amount: <span id="pod" style="font-weight:bold;"></span></span>
    </div>
    <div class="col-2 col-lg-2 col-md-2 col-sm-2 ">
 <span class="sp">Total Expense: <span id="txp" style="font-weight:bold;"></span></span>
    </div>
    <div class="col-3 col-lg-3 col-md-3 col-sm-3 ">
 <span class="sp">IOCl Paid: <span id="iopd" style="font-weight:bold;"></span></span>
    </div>
    <div class="col-2 col-lg-2 col-md-2 col-sm-2 ">
 <span class="sp">Balance: <span id="blnc" style="font-weight:bold;"></span></span>
    </div>
  </div>


</div>



</div>



</div>












                    <?php endif; ?>

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


<script>


$(document).ready(function(){
  load_index();

$("#main-tab").show();
$("#sec-tab").hide();

$("#srch_po").on("keyup", function() {

    var value = $(this).val().toLowerCase();
    $(".accordion-toggle").filter(function() {
      $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
    });
  });



  
});

function load_index(){


  $.ajax({
              type: 'POST',
               async: false,
                url: '/get_data',
                data: {
                     '_token': "<?php echo e(csrf_token()); ?>",
                    
                     row_id: '',
                 
                  
              url1:'load_po_index.php'
                },
                error: function (request, error) {
                    alert("Please Wait, Loading...");
                },
                success: function (response) {
               
 data=response;
 tr='';

for(i=0;i<data.length;i++){


  styl='';


  if(parseFloat(data[i]['tot_exp'])>parseFloat(data[i]['po_limit'])){
console.log(data[i]['po_limit'])

    styl='style="background:#ff8d55;color:black;"';

  }
  tr+='  <tr title="Po Limit is '+data[i]['po_limit']+'" data-toggle="collapse" '+styl+'  class="accordion-toggle" data-target="#scc_'+data[i]['pod_a_id']+'" class="accordion-toggle" po_id='+data[i]['pod_a_id']+'  po_no="'+data[i]['po_no']+'"   po_con_no="'+data[i]['po_con_no']+'" onclick="load_dash_po('+data[i]['pod_a_id']+');"    >';


      


//tr+='<tr  class="table-striped dsh_tbl" onclick="load_po_detail(this)" po_id='+data[i]['pod_a_id']+'  po_no="'+data[i]['po_no']+'"   po_con_no="'+data[i]['po_con_no']+'">';


tr+='<td >'+data[i]['po_no']+'</td>';
tr+='<td style="color:#b93a52;font-weight:bold;">'+data[i]['po_con_no']+'</td>';

tr+='<td>'+data[i]['po_date']+'</td>';

tr+='<td class="td-rt">'+data[i]['po_amount1']+'</td>';
tr+='<td class="td-ct">'+data[i]['po_short_code']+'</td>';


tr+='<td class="td-rt">'+data[i]['tot_billd1'] +'</td>';

tr+='<td class="td-rt">'+data[i]['tot_exp1']+'</td>';
tr+='<td class="td-rt" style="color:#022b57;font-weight:bold;">'+data[i]['tot_paid1']+'</td>';
tr+='<td class="td-rt">'+new Intl.NumberFormat().format((data[i]['tot_billd']-data[i]['tot_paid']).toFixed(2))+'</td>';
tr+='<td class="td-ct">'+data[i]['est_comp_date']+'</td>';
if(data[i]['flag']==1){

  tr+='<td style="padding: 0px !important;"><div class="badge badge-success p-2" >In Progress</div></td>';

}
else if(data[i]['flag']==2){
 // tr+='<td style="padding: 0px !important;"><div class="badge badge-warning p-2" >Part Payment</div></td>';
 tr+='<td style="padding: 0px !important;"><div class="badge badge-success p-2" >In Progress</div></td>';
}
else{
  tr+='<td style="padding: 0px !important;"><div class="badge badge-danger p-2" >Pending</div></td>';
}

tr+='<td class="td-rt"><i class="icon-arrow-right-circle ico" onclick="load_po_detail(this)"></i></td>';
tr+='</tr>';



tr+='<tr>   <td colspan="12" class="hiddenRow"><div class="accordian-body collapse" id="scc_'+data[i]['pod_a_id']+'">  </div> </td></tr>';

         
							
            
             
    
        

}
$("#dash_tbl_tbdy").html(tr);

     
        }
          
     });


    
}


function load_po_detail(elm){
$("#lbl_div").html('');

po_id=$(elm).closest('tr').attr('po_id');
po_no=$(elm).closest('tr').attr('po_no');
po_con_no=$(elm).closest('tr').attr('po_con_no');

$("#lbl_div").html('<i class="icon-arrow-left-circle ico" style="font-weight:bold;cursor:pointer;" onclick="go_bck();"></i> PO Number: <span style="font-weight:bold;color:red;">'+po_no+'</span>/ Po CO No: <span style="font-weight:bold;color:blue;">'+po_con_no+'</span>');

$.ajax({
              type: 'POST',
               async: false,
                url: '/get_data',
                data: {
                     '_token': "<?php echo e(csrf_token()); ?>",
                    
                     row_id: po_id,
                 
                  
              url1:'load_po_wrk_order.php'
                },
                error: function (request, error) {
                    alert("Please Wait, Loading...");
                },
                success: function (response) {



           

                  $('#main-tab').hide("slide", { direction: "left" }, 250, function () {
            $('#sec-tab').show("slide", { direction: "right" }, 250);
        });
                  
// $("#sec-tab").fadeIn(100);



               
 data=response['wo'];
 data1=response['sup_pay'];
 data2=response['po_dtl'];
 tr='';
 tr2='';

total=0.00;
crb=0.00;

for(i=0;i<data.length;i++){
j=i;
j++;
  total+=parseFloat(data[i]['est_cost']);
  crb+=parseFloat(data[i]['cb']);
tr+='<tr  data-toggle="collapse" data-target="#wo_t_'+data[i]['pa_id']+'"  class="accordion-toggle table-striped dsh_tbl" onclick="load_wo_detail_bll('+data[i]['pa_id']+')"  >';


tr+='<td>'+j+'</td>';
tr+='<td>'+data[i]['pa_no']+'</td>';

tr+='<td class="td-ct">'+data[i]['strt_dt']+'</td>';

tr+='<td class="td-ct">'+data[i]['end_dt']+'</td>';


tr+='<td class="td-ct">'+data[i]['c_name']+'</td>';
tr+='<td class="td-ct">'+data[i]['added_by']+'</td>';
tr+='<td class="td-rt">'+new Intl.NumberFormat().format(parseFloat(data[i]['est_cost']).toFixed(2))+'</td>';
tr+='<td class="td-rt">'+data[i]['cb1']+'</td>';
if(data[i]['cb']!=0){

  // tr+='<td><div class="badge badge-success p-2">Paid</div></td>';

}

else{
  // tr+='<td><div class="badge badge-danger p-2">Pending</div></td></tr>';
}
tr+='<td></td>';


tr+='<tr>   <td colspan="12" class="hiddenRow"><div class="accordian-body collapse" id="wo_t_'+data[i]['pa_id']+'">  </div> </td></tr>';

}
tr+='<tr><td colspan="6" style="text-align:center;font-weight:bold;">Total</td><td class="td-rt">'+new Intl.NumberFormat().format(total.toFixed(2))+'</td><td class="td-rt pd">'+new Intl.NumberFormat().format(crb.toFixed(2))+'</td></tr>';
$("#wrk_order_tbdy").html(tr);








p_amt=0.00;




$("#sup_pay_tbdy").html(tr2);

$("#txp").html(new Intl.NumberFormat().format(data2[0]['tot_exp1']));
$("#pod").html(new Intl.NumberFormat().format(data2[0]['po_amount']));
$("#iopd").html(new Intl.NumberFormat().format(data2[0]['iopd']));
$("#blnc").html(new Intl.NumberFormat().format(data2[0]['blnc']));







     
        }
          
     });




}


function go_bck(){
     

  $('#sec-tab').hide("slide", { direction: "right" }, 300, function () {
            $('#main-tab').show("slide", { direction: "left" }, 300);
        });
             
}



function load_dash_po(po_id){

$(".accordian-body").removeClass('show');

html='';
html+='  <table class="table table-striped"> <thead> <tr class="bg-warning fw-bold" style="font-weight:bold;"> <th class="pd">Date</th> <th class="pd">Client Billed</th> <th class="pd">Client Collected</th><th class="pd">Supplier Billed</th> <th class="pd">Paid To Supplier</th> <th class="pd">Contarctor Billed</th> <th class="pd">Paid To Contartcor</th> <th class="pd">Labour Paid</th> <th class="pd">Total Paid</th> </tr> </thead> <tbody>';


                     
												
																								
             
              

  $.ajax({
              type: 'POST',
               async: false,
                url: '/get_data',
                data: {
                     '_token': "<?php echo e(csrf_token()); ?>",
                    
                     row_id:po_id,
                 
                  
              url1:'load_dash_po.php'
                },
                error: function (request, error) {
                    alert("Please Wait, Loading...");
                },
                success: function (response) {
               
 data=response;
 tr='';


 tot_billd_ioc=0.00;
 tot_paid_ioc=0.00;
 sup_billd=0.00;
 sup_paid=0.00;
 con_billd=0.00;
 con_paid=0.00;
 lab_paid=0.00;
 total=0.00;

for(i=0;i<data.length;i++){ 
  tot_billd_ioc+=parseFloat(data[i]['tot_billd_ioc']);
  tot_paid_ioc+=parseFloat(data[i]['tot_paid_ioc']);
  sup_billd+=parseFloat(data[i]['sup_billd']);
  sup_paid+=parseFloat(data[i]['sup_paid']);
  con_billd+=parseFloat(data[i]['con_billd']);
  con_paid+=parseFloat(data[i]['con_paid']);
  lab_paid+=parseFloat(data[i]['lab_paid']);
  total+=parseFloat(data[i]['total']);


  html+='<tr>';

html+='<td>'+data[i]['t_date']+'</td>';
html+='<td class="td-rt">'+data[i]['tot_billd_ioc1']+'</td>';
html+='<td class="td-rt pd">'+data[i]['tot_paid_ioc1']+'</td>';
html+='<td class="td-rt">'+data[i]['sup_billd1']+'</td>';
html+='<td class="td-rt pd">'+data[i]['sup_paid1']+'</td>';
html+='<td class="td-rt">'+data[i]['con_billd1']+'</td>';
html+='<td class="td-rt pd">'+data[i]['con_paid1']+'</td>';

html+='<td class="td-rt pd">'+data[i]['lab_paid1']+'</td>';
html+='<td class="td-rt">'+data[i]['total1']+'</td>';
html+='</tr>';
             
    
        

}
html+='</tbody><tfoot><tr style="background:#393838;color:white;font-weight:bold;">';

html+='<td class="fw-bold">Total</td>';
html+='<td class="fw-bold td-rt ">'+new Intl.NumberFormat().format(tot_billd_ioc.toFixed(2));+'</td>';
html+='<td class="fw-bold td-rt" style="color:#5de649;">'+new Intl.NumberFormat().format(tot_paid_ioc.toFixed(2))+'</td>';
html+='<td class="fw-bold td-rt">'+new Intl.NumberFormat().format(sup_billd.toFixed(2))+'</td>';
html+='<td class="fw-bold td-rt pd">'+new Intl.NumberFormat().format(sup_paid.toFixed(2))+'</td>';
html+='<td class="fw-bold td-rt">'+new Intl.NumberFormat().format(con_billd.toFixed(2))+'</td>';
html+='<td class="fw-bold td-rt pd">'+new Intl.NumberFormat().format(con_paid.toFixed(2))+'</td>';
html+='<td class="fw-bold td-rt pd">'+new Intl.NumberFormat().format(lab_paid.toFixed(2))+'</td>';
html+='<td class="fw-bold td-rt">'+new Intl.NumberFormat().format(total.toFixed(2))+'</td>';

html+='</tr></tfoot></table>';

$("#scc_"+po_id).html(html)
     
        }
          
     });

}





function load_wo_detail_bll(pa_id){

html='';
html+='<table class="table wrk_ordr_tbdy"><thead clas="bg-info text-white"><tr class="bg-dark text-white"><th>Contarctor</th><th>Bill Number</th><th>Bill/Pay Date</th><th>Bill</th><th>Bill Amount</th></tr> </thead>';

  $.ajax({
              type: 'POST',
               async: false,
                url: '/get_data',
                data: {
                     '_token': "<?php echo e(csrf_token()); ?>",
                    
                     row_id:pa_id,
                 
                  
              url1:'load_wo_detl_bll.php'
                },
                error: function (request, error) {
                    alert("Please Wait, Loading...");
                },
                success: function (response) {
               
 data=response;

for(i=0;i<data.length;i++){ 
  html+='<tr class="'+data[i]['cls']+'">';

  html+='<td>'+data[i]['cname']+'</td>';
  html+='<td>'+data[i]['bll']+'</td>';
  html+='<td>'+data[i]['bill_dt']+'</td>';
  if(data[i]['bill_file']!=''){
    html+='<td><a href="/view_pdf/'+data[i]['bill_file']+'" target="_blank" /a> View Bill</td>';
  }
else{
  html+='<td>&nbsp;</td>';
}
if(parseFloat(data[i]['bill_amt'])==0){
  html+='<td class="td-rt">&nbsp;</td>';
}else{
  html+='<td class="td-rt">'+new Intl.NumberFormat().format(parseFloat(data[i]['bill_amt']).toFixed(2),2)+'</td>';
}


  html+='</tr>';
             
    
        

}

$("#wo_t_"+pa_id).html(html)
     
        }
          
     });






}

$("body").on('click',function(){
$(".accordian-body").removeClass('show');

});




</script>







<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/trafiqer/public_html/petro/resources/views/home.blade.php ENDPATH**/ ?>