<?php
if(isset($_POST["cname"]) )
{  
 $cc=0;
 $tpayb=0;     
 $tptd=0;
 $tbal=0; 
 //$parts =explode(':', $_POST['cname']);  
 $cname=$_POST['cname']; 
  $dat1= $_POST['dat1'];
  $dat2= $_POST['dat2']; 
  $status="NOT PAID";
  require_once "labClass.php";
 
  require_once "labClass.php";
 $con = new labClass();
  ?> 
 <div class="container-fluid" id="dpl">
  <?php
  //if ($cname!="") 
  //{    
   //$chkp= $con->getThisCorderByD($cname,$status,$dat1,$dat2);
  //} 
  //else if($cname!="" )
  //{
    $chkp= $con->getThisCusNonPurchDebit($cname,$status);
 // }
 //echo $chkp->rowCount();
  // print_r($chkp->errorInfo());  
if ($chkp->rowCount()>0) {
  $chp=$chkp->fetchAll();
  ?>
<table class="table" border="1"> 
   <thead class="bg-secondary" >
      <th>  
        <small><h6>DATE</h6></small>
      </th>
      <th>  
        <small><h6>INV. NO/C'S NAME</h6></small>
      </th>
      <th>  
        <small><h6>TOTAL PAYABLE</h6></small>
      </th>
      <th>  
        <small><h6>PAID TO DATE</h6></small>
      </th>
      <th>  
        <small><h6>BALANCE</h6></small>
      </th>
       <th>  
        <small><h6>PAY</h6></small>
      </th>
    </thead>
   <?php
    foreach ($chp as $key => $p) {
    $orderID=$p['orderID']; 
    $cc++;  
    ?>
 <tbody>
 <tr>
 <td>
    <?php echo $p['orderdate'];?> 
    </td>
     <td>  
      <?php 
      $cname=$p['cname'];
      $c= $con->getThisCusRecByN($cname)->fetch(); 
      echo $p['cname']."<br/>Tel:".$c['phone'];?> 
     </td>
     <td align="right">
    <?php echo number_format($p['payableA'],2);?> 
    </td>
    <td align="right">
    <?php echo number_format($p['paidtodate'],2);?> 
    </td>
    <td align="right">
        <sup class="text-danger" id="rdn<?php echo $cc;?>"></sup>
        <input type="hidden" disabled="true" name="bal<?php echo $cc;?>" id="cbal<?php echo $cc;?>"  value="<?php echo $p['balance'];?>" />
        <input type="number" align="right" style="width:70%; border-radius:12px; border-color:white; background-color: white;" disabled="true" name="bal<?php echo $cc;?>" id="bal<?php echo $cc;?>"  value="<?php echo $p['balance'];?>" />  
    </td>
      <td>
      <button type="submit" class="btn btn-primary" style="width:100%; height:40px;"  name="postEdit<?php echo $cc;?>" id="postEdit<?php echo $cc;?>" value="PAY" id="submit" onclick="document.getElementById('bal<?php echo $cc;?>').disabled=false;$('#postEdit<?php echo $cc;?>').hide();$('#postUpdate<?php echo $cc;?>').show();" ><small>PAY</small>
      </button>
     <button type="submit" class="btn btn-success" style="width:100%; height:40px;  display:none;" name="postUpdate<?php echo $cc;?>" id="postUpdate<?php echo $cc;?>"value="Update" id="submit" onclick="  var orno =document.getElementById('orno<?php echo $cc;?>').innerHTML; var sdate=$('#sdate').val(); var user=$('#user').val(); var pOpt=$('#pOpt').val(); var cbal =$('#cbal<?php echo $cc;?>').val();var bal =$('#bal<?php echo $cc;?>').val();alert(pOpt); if(bal!=''  && orno!='' && cbal!='' && user!=''&& pOpt!='') {$.post('pharmPayDebitPro.php',{sdate:sdate,bal:bal,cbal:cbal,orno:orno,pOpt:pOpt,user:user},function(data){$('#rdn<?php echo $cc;?>').html(data).show();});document.getElementById('bal<?php echo $cc;?>').disabled=true;$('#postUpdate<?php echo $cc;?>').hide();$('#postEdit<?php echo $cc;?>').show();} else{document.getElementById('rdn<?php echo $cc;?>').innerHTML='Valide item detail required!..';}" > <small>SAVE</small></button>
    </td>
    </tr>   
<?php
$tbal=$tbal+$p['balance'];
$tpayb=$tpayb+$p['payableA'];
$tptd=$tptd+$p['paidtodate'];      
}
$cc=0; 
?>
<tr><td colspan="2" align="right">Total:</td><td align="right"><?php echo number_format($tpayb,2);?></td><td align="right"><?php echo number_format($tptd,2);?></td><td align="right"><?php echo number_format($tbal,2);?></td></tr>
</tbody>
</table> 

<?php
}
?>
</div>
<?php
}
else{
    ?>
<h6 class="text-danger">All field required!..</h6>
<?php
}
?>