  <!-- 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">OTHER COMPANY RECEIVED 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>COST</th>  
                        <th>SELLING</th>  
                        <th>REMARK</th>  
                        <th>COMPANY NAME</th>  
                        <th>SEND DATE</th>  
                        <th>RECEIVED DATE</th>  
                        <th>HISTORY</th>  
                        <th>Type</th>  
                        <th>Status</th>  
                        
                       
                    </tr>
                </thead>


                <tbody>
                    <?php
                    $i=1;
                    include './connection_sql.php';

                    
                    if($_SESSION['company']==""){
                        $sql = "select * from dag_item WHERE flag >'3' and cancel='0'   and TYPE='SENDOTHER'";
                    }else{
                        $sql = "select * from dag_item WHERE flag >'3' and cancel='0'   and TYPE='SENDOTHER' 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['cost']; ?></td>  
                            <td><?php echo $row['total']; ?></td>  
                            <td><?php echo $row['remark']; ?></td>  
                            <td><?php echo $row['ocompany']; ?></td>  
                            <td><?php echo $row['onhand_date']; ?></td>  
                            <td><?php echo $row['com_date']; ?></td>  
                            <td style="background-color:red"><?php echo $row_1['count']; ?></td>  
                            <td><a onclick="sendreject('<?php echo $row['refno']; ?>','<?php echo $row['serialno']; ?>');" class="btn btn-primary">
                        <span class="fa fa-save"></span> &nbsp; SEND TO REJECT
                    </a> </td>
                    
                          <?php
                             if($row['reject']=='0'){
                                 if($row['flag']=='0'){
                                     echo "<td style='background-color:yellow'>ONHAND </td>"; 
                                }else if($row['flag']=='1'){
                                    echo "<td style='background-color:#acdcf3'>PRODUCTION</td>"; 
                                }else if($row['flag']=='2'){
                                     echo "<td style='background-color:#1ef51e'>COMPLETE</td>"; 
                                }else if($row['flag']=='3'){
                                     echo "<td style='background-color:#1ef51e'>OTHER COMPANY SEND</td>"; 
                                }else if($row['flag']=='5'){
                                     echo "<td style='background-color:#1ef51e'>OTHER COMPANY RECEIVED</td>"; 
                                }else if($row['flag']=='6'){
                                     echo "<td style='background-color:#1ef51e'>ONHAND TRANSFER PENDING</td>"; 
                                }else if($row['flag']=='7'){
                                     echo "<td style='background-color:#eabf5d'>INVOICED</td>"; 
                                }
                             }else{
                                if($row['flag']=='7'){
                                     echo "<td style='background-color:red'>REJECTED & INVOICED</td>"; 
                                }else{
                                    echo "<td style='background-color:red'>REJECTED</td>"; 
                                }
                                 
                             }
                            
                            
                           
                            ?>
                    
                            
                             
                          
                            


                    </tr>

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

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

</section>

<script>
    function sendreject(refno,serialno){
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request");
        return;
    }
    var url = "otherreclist_data.php";                                 
    var params ="Command="+"sendreject";      
    params = params + "&refno=" + refno;
    params = params + "&serialno=" + serialno; 


    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_finish;

    xmlHttp.send(params);  
}

function re_finish()
{
    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>