  <!-- Main content -->
   <link rel="stylesheet" href="css/bootstrap.min.css">

<style type="text/css">
		tfoot input {
			width: 100%;
			padding: 3px;
			box-sizing: border-box;
		}
	</style>
   
    <link rel="stylesheet" href="css/bootstrap.min.css"> 
    <!--<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css">-->
 
    <link  href="vendor/new/multi/jquery.dataTables.min.css" rel="stylesheet" type="text/css"> 
	<script src="vendor/new/multi/jquery-3.5.1.js" ></script>
	<script src="vendor/new/multi/jquery.dataTables.min.js" ></script>
<?php
require_once("./connection_sql.php");
?>

<style>

    .view-cell{
        background-color: red;
        color: white; 
    }
    .table-hover tbody tr:hover td {
        background: aqua;
    }
</style>
 <section class="content" onload="search1();">

    <div class="box box-primary">
        <div class="box-header with-border">
            <h3 class="box-title">ONHAND LIST</h3>
            <h4 style="float: right;height: 3px;"><b id="time"></b></h4>
        </div>
        <form role="form" class="form-horizontal">
            <div class="box-body">


                <div class="panel-body" style="overflow-x: auto">
                     
                <table width="100%" class="table table-striped table-bordered table-hover" id="example" style="width:auto" >
                    <thead> 

                       <tr>
                        <th>#</th>
                        <th style="background-color:#ffeb00">JOB NO</th> 
                        <th>INVOICE NO</th>
                        <th>DATE</th>   
                        <th>CUSTOMER</th>
                        <th>MAKE</th> 
                        <th>SIZE</th>  
                        <th>BELT</th>  
                        <th>SERIAL NO</th>  
                        <th>CASING COST</th>  
                        <th>REMARK</th>  
                        <th>HISTORY</th>  
                        <th></th>   
                        <th></th> 
                        <?php    if($_SESSION['user_type']=="ADMIN"){?>
                        <th></th> 
                          <?php   }?>
                    </tr>
                </thead>


                <tbody>
                    <?php
                    $i=1;
                    include './connection_sql.php';
                    
                    if($_SESSION['company']==""){
                        $sql = "select * from dag_item WHERE flag='0' and cancel='0' and reject='0' ";
                    }else{
                        $sql = "select * from dag_item WHERE flag='0' and cancel='0' and reject='0' and company='".$_SESSION['company']."' ";
                    }
                    
                    
 

                    foreach ($conn->query($sql) as $row) {
                        if($_SESSION['company']=="ALL"){
                            $sql1 = "Select count(*) as count from dag_item  where cancel='0'  and  serialno='".$row['serialno']."' group by  serialno asc";  
                        }else{
                            $sql1 = "Select count(*) as count from dag_item  where cancel='0'  and  serialno='".$row['serialno']."' and company='".$_SESSION['company']."' group by  serialno asc";    
                        }
                     
                        $result_1 = $conn->query($sql1);
                        $row_1= $result_1->fetch(); 
                
                
               
              
              

                        ?>
                        <tr>
                            <td></td>  
                            <td style="background-color:#ffeb00"><?php echo $row['jobno']; ?></td>   
                            <td><?php echo $row['refno']; ?></td> 
                            <td><?php echo $row['sdate']; ?></td>   
                            <td><?php echo $row['cuscode'].'-'.$row['cusname']; ?></td> 
                            <td><?php echo $row['marker']; ?></td>   
                            <td><?php echo $row['size']; ?></td>   
                            <td><?php echo $row['belt']; ?></td>   
                            <td><?php echo $row['serialno']; ?></td>   
                            <td><?php echo $row['cascost']; ?></td>  
                            <td><?php echo $row['remark']; ?></td>  
                            <td style="background-color:red"><?php echo $row_1['count']; ?></td>  
                            <td> <a  onclick="sendother('<?php echo $row['id']; ?>');"  class="btn btn-primary">
                                <span class="fa fa-mail-forward"></span> &nbsp; SEND OTHER COMPANY
                            </a> 
                            </td> 
                            <td> <a  onclick="sendakeesha('<?php echo $row['id']; ?>');"  class="btn btn-primary">
                                <span class="fa fa-mail-forward"></span> &nbsp; SEND 
                            </a> 
                            </td> 
                             
                            <?php    if($_SESSION['user_type']=="ADMIN"){?>
                             <td> <a onclick="sendinvoice('<?php echo $row['id']; ?>');" class="btn btn-primary">
                                <span class="fa fa-mail-forward"></span> &nbsp; SEND TO INVOICE
                            </a> 
                            </td> 
                          <?php   }?>
                            


                    </tr>

                    <?php
                    $i= $i+1;
                }
                ?>
            </tbody>
        </table>
    </div>

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

</section>

<!--<script src="js/medical_approve.js"></script>-->
<script>
 
  

function sendother(cdate) {
 
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request");
        return;
    }
    
    var msg = confirm("Do you want to Continue this ! ");
    if (msg == true) {
        var ocompany= prompt("Please Enter Company Name", "");
        if(ocompany.length == 0){
         
            alert('Enter Company');
        }
        
        var url = "onhandlist_data.php";
        var params ="Command="+"sendother";    
        params = params + "&id=" + cdate; 
        params = params + "&ocompany=" + ocompany; 

        xmlHttp.open("POST", url, true);

        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", params.length);
        xmlHttp.setRequestHeader("Connection", "close");

        xmlHttp.onreadystatechange=item_del;

        xmlHttp.send(params);  

    }
}

function sendakeesha(cdate) {
 
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request");
        return;
    }
    
    var msg = confirm("Do you want to Continue this ! ");
    if (msg == true) {
         
        
        var url = "onhandlist_data.php";
        var params ="Command="+"sendother";    
        params = params + "&id=" + cdate; 
        params = params + "&ocompany=" + "AKEESHA"; 

        xmlHttp.open("POST", url, true);

        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", params.length);
        xmlHttp.setRequestHeader("Connection", "close");

        xmlHttp.onreadystatechange=item_del;

        xmlHttp.send(params);  

    }
}
 
function item_del() {

    var XMLAddress1;

    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        alert(xmlHttp.responseText);
        setTimeout("location.reload(true);", 500);
    }
}

function sendinvoice(cdate) {
 
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request");
        return;
    }
    
    var msg = confirm("Do you want to Continue this ! ");
    if (msg == true) {
        var url = "onhandlist_data.php";
        var params ="Command="+"sendinvoice";    
        params = params + "&id=" + cdate; 

        xmlHttp.open("POST", url, true);

        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", params.length);
        xmlHttp.setRequestHeader("Connection", "close");

        xmlHttp.onreadystatechange=re_invoice;

        xmlHttp.send(params);  

    }
}


function re_invoice() {

    var XMLAddress1;

    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        alert(xmlHttp.responseText);
        setTimeout("location.reload(true);", 500);
    }
}

</script>

<script type="text/javascript">
 $(document).ready(function() {
         
      var table =  $('#example').DataTable( {
            dom: 'Bfrtip',  
            lengthChange: true,
            fixedHeader: true,
            responsive: true,
            "deferRender": true,
            "pageLength": 10,
            
            buttons: ['pageLength',
                {
                    extend: 'print',
                    customize: function ( win ) {
                         $(win.document.body).find('table').addClass('printer');
     
                        
                    }
                }
            ]
        } );
        
            table.on( 'order.dt search.dt', function () {
            table.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
                cell.innerHTML = i+1;
            } );
             } ) 
              $('div.dataTables_filter input', table.table().container()).focus();
          table.buttons().container()
          .appendTo( '#example_wrapper .col-md-6:eq(0)' );
    } );
</script>