<?php

require('../headMyStockStaff.php');
if (isset($_POST['owniD'])) {
	



 
	///////////////////////////RANGE FILTER BY DATE///////////////////
	/////////////////////////////////////////////////////////////////
 $MS=$mcon->getMyShop($ownID);
 if ($MS->rowCount()>0) {
  

 $shop=$MS->fetch();

 // $shopid=$shop['shopid'];
        
    $sdate="";
    $edate="";
    $id="";

    $post=$_POST['post'];
    if ($post=="Date")
    {
       if (isset($_POST['sdate'])) {
         
           $sdate= $_POST['sdate']; 
           $Ord=$mcon->getMyShopOrderByDate($shopid,$sdate);
       }
    }

     if ($post=="Search")
    {
       if (isset($_POST['id'])) {
         
           $id= $_POST['id']; 
           $Ord=$mcon->getMyShopOrderByItemId($shopid,$id);
       }
    }


    if ($post=="Range of date")
    {
       if (isset($_POST['sdate']) && isset($_POST['edate'])) {
         
           $sdate= $_POST['sdate'];
           $edate= $_POST['edate']; 
           $Ord=$mcon->getMyShopOrderByRange($shopid,$sdate,$edate); 
       }
    }

    if ($post=="Order in progress"){
       
      $Ord=$mcon->getOrderFromMyShop($shopid); 

    }
                 ////


    
?> 
  
     <center>
      <!--<ul id="lipad">
        
                <li>
                 <form action="selectedShopItemDetail.php" method="post">

                     <input class="hi" type="hidden" name="owniD"  value="<?php// echo $ownID;?>">


                     <input class="hi" type="hidden" name="shopid"  value="<?php //echo $shop['shopid'];?>">

                    <input  class="spos" type="submit" value="<?php //echo $shop['shopname'];?>" name="post">

                 </form>

                </li>
               <li>
                 <form action="myShopIemListView.php" method="post">

                     <input class="hi" type="hidden" name="owniD"  value="<?php //echo $ownID;?>">


                     <input class="hi" type="hidden" name="shopid"  value="<?php// echo $shop['shopid'];?>">

                    <input  class="spos" type="submit" value="My stock" name="post">

                 </form>

                </li>
              <li >
        
                <form action="newshopitempost.php" method="post">

                      <input class="hi" type="hidden" name="owniD"  value="<?php// echo $ownID;?>">


                      <input class="hi" type="hidden" name="shopid"  value="<?php// echo $shop['shopid'];?>">

 

                      <input  class="spos" type="submit" value="New item" name="post">

                 </form>

          </li>

          <li>
        
                <form action="OrderToMyShop.php" method="post">

                      <input class="hi" type="hidden" name="owniD"  value="<?php// echo $ownID;?>">


                      <input class="hi" type="hidden" name="shopid"  value="<?php// echo $shop['shopid'];?>">

 

                      <input  class="spos" type="submit" value="New order" name="post">

                 </form>

       </li>
        <li >
        
                <form action="shopWorkersProfile.php" method="post">

                      <input class="hi" type="hidden" name="owniD"  value="<?php// echo $ownID;?>">


                      <input class="hi" type="hidden" name="shopid"  value="<?php// echo $shop['shopid'];?>">

 

                      <input  class="spos" type="submit" value="Workers" name="post"  >

                 </form>

       </li>
  </ul>-->



      <ul><li> <label id="main_lab">SORT ORDERED ITEM REPORT BY DATE OR ID HERE</label></li></ul>
     
    <!-- <table>
       <tr>
         <td>-->
            
        <!-- </td>
       </tr>

     </table>-->
    
<!-- b/////////////////////////lll-->


       <fieldset id="new_visitors_reg_form">
       <center>

           <sup>
               <?php
               if ($post=="Range of date")
                {
                  if($sdate=="" ||  $edate=="")
                  {
                  echo "Date range required!";
                  }
               }


                if ($post=="Date")
                {
                  if($sdate=="")
                  {
                  echo "Date required!";
                  }
               }

               if ($post=="Search")
                {
                  if($id=="")
                  {
                  echo "Item or order id required!";
                  }
               }
               ?>
            </sup>
        </center>
          <form action="OrderToMyShopStaff.php" method="post">
 

                               <input class="hi" type="hidden" name="owniD"  value="<?php echo $ownID;?>">
                              <input class="hi" type="hidden" name="ownerid"  value="<?php echo $ownerid;?>">
                              <input class="hi" type="hidden" name="shopid"  value="<?php echo $shopid;?>">

 
 

                              <label id="main_lab">Select date:</label>

                              <input  type="date" name="sdate" value="<?php echo $sdate;?>" >


                              <label style="padding-left:24%">

                              <input  type="date" name="edate" value="<?php echo $edate;?>"  >

                              </label><p/>

                              <label id="main_lab">Search by:</label>

                              <input class="pos" type="submit" value="Date" name="post"  >
                         
                             <label style="padding-left:27%">

                              <input class="pos" type="submit" value="Range of date" name="post">

                            </label><p/>


                              <label id="main_lab">Search by item id and order id:</label>

                              <input class="ssinput" type="text" value="" name="id"  >
                         
                             <label>

                              <input class="pos" type="submit" value="Search" name="post">

                            </label>

          </form>
        </fieldset>
                    <!--////////////////////
           <         ////////////////////////-->
           <?php

	//////////////////////////////////////////////RANGE DATE////////////////////
	///////////////////////////////////////////////////////////////////////////

?>
<table width="100%" border="0">
<tr>
	<td colspan="10">
		
	  <label id="main_title"> ORDER REPORT</label>
	</td>
</tr>
	

<?php
if ($Ord->rowCount()>0){
	$On=$Ord->fetchAll();
 ?>
 <tr class="tr1"><td align="center"><label id="inner_top">ORDER BY</label></td><td align="center"><label id="inner_top">ORDER ID</label></td><td align="center"><label id="inner_top">SHOP NAME</label></td> <td align="center"><label id="inner_top">ITEM NAME</label></td> <td align="center"><label id="inner_top">QUANTITY </label></td><td align="center"><label id="inner_top">DATE ORDERED</label></td><td align="center"><label id="inner_top">PRICE/ITEM</label></td><td align="center"><label id="inner_top">TOTAL PAID</label><td align="center"><label id="inner_top"> STATUS</label></td><td align="center"><label id="inner_top"> DELIVERING DATE</label></td></td></tr>
 <?php
 $cc=0;
foreach ($On as $key => $Od) {
$cc++;
$itemid=$Od['itemid'];
$shopid=$Od['shopid'];
$code=$Od['paymentcode'];
$accountId=$Od['customerid'];
$sn=$mcon->getShopName($shopid)->fetch();
$in=$mcon->getItemName($itemid,$shopid)->fetch();
$pc=$mcon->getAmountPaid($code)->fetch();
$cP=$con->myProfileInfo($accountId)->fetch();
 ?>
 <tr><td colspan="10">
       <sup id="rdn<?php echo $cc;?>"></sup></td></tr>
	<tr>
      <td height="40px"> 
            <?php
                echo $cP['fname']." ".$cP['mname']." ".$cP['lname'];
             ?>
     </td>
		 <td height="40px"> 
            <?php
                echo $Od['orderid'];
             ?>
		 </td>

		 <td> 
              <?php
                echo $sn['shopname'];
                ?>
		</td>

		 

		<td> 

    <form action="myShopOrderDetailStaff.php" method="post">

                     <input class="hi" type="hidden" name="owniD"  value="<?php echo $ownID;?>">
 

                     <input class="hi" type="hidden" name="orderid"  value="<?php echo $Od['orderid'];?>">



                     <input class="hi" type="hidden" name="shopid"  value="<?php echo $shopid;?>">
                    <input class="hi" type="hidden" name="ownerid"  value="<?php echo $ownerid;?>">

 

                    <input class="pos" type="submit" value="<?php echo $in['itemname'];?>" name="post">

                 </form>  
		</td>

		 
		<td>
		        <?php
                echo $Od['quantity'];
                ?>
    </td>
		<td>    <?php
                   echo $Od['dateordered'];
                  ?>

		</td>
		

		<td> 
                  <?php
                     echo $in['itemcost'];
                   ?>
		</td>

		<td> 
                  <?php
                     echo $pc['amount'];
                   ?>
		</td>
    <td> 
      <label  id="status<?php echo $cc;?>">
                  <?php
                   echo $Od['processingstatus'];
                  ?>
      </label>
    </td>

   <td>
     <input class="hi" type="hidden" name="customerid<?php echo $cc;?>" id="customerid<?php echo $cc;?>"  value="<?php echo $Od['customerid'];?>">
     <input class="hi" type="hidden" name="orderid<?php echo $cc;?>" id="orderid<?php echo $cc;?>"  value="<?php echo $Od['orderid'];?>">
    <input class="hi" type="hidden" name="shopid<?php echo $cc;?>" id="shopid<?php echo $cc;?>"  value="<?php echo $Od['shopid'];?>">
   <input class="hi" type="hidden" name="itemid<?php echo $cc;?>" id="itemid<?php echo $cc;?>"  value="<?php echo $Od['itemid'];?>">




 <label  id="lab<?php echo $cc;?>"><?php echo $Od['deliverdate'];?></label>
  <?php
  if ($Od['deliverdate']=="") {
  ?>
   <input  type="date" name="date<?php echo $cc;?>" id="date<?php echo $cc;?>">
     <input type="submit"  name="postEdit<?php echo $cc;?>" id="postEdit<?php echo $cc;?>" value="Comfirm" id="submit" onclick="var itemid=$('#itemid<?php echo $cc;?>').val();var shopid=$('#shopid<?php echo $cc;?>').val();var customerid=$('#customerid<?php echo $cc;?>').val(); var orderid=$('#orderid<?php echo $cc;?>').val();var date=$('#date<?php echo $cc;?>').val();
if(date!=''){


     $.post('updateOrderStatusComfirmed.php',{date:date,itemid:itemid,orderid:orderid,customerid:customerid,shopid:shopid},function(data){$('#rdn<?php echo $cc;?>').html(data).show();});  $('#postEdit<?php echo $cc;?>').hide();$('#date<?php echo $cc;?>').hide();$('#status').empty(); document.getElementById('status<?php echo $cc;?>').innerHTML='Comfirmed'; document.getElementById('lab<?php echo $cc;?>').innerHTML=date;
     }else{
      document.getElementById('rdn<?php echo $cc;?>').innerHTML='Date required!..';
     }
     " />
   <?php
  }
  ?>
       <!--
        <input type="submit"  name="postUpdate<?php //echo $cc;?>" id="postUpdate<?php //echo $cc;?>"value="Undo confirm" id="submit" onclick="var itemid=$('#itemid<?php// echo $cc;?>').val();var shopid=$('#shopid<?php// echo $cc;?>').val();var customerid=$('#customerid<?php //echo $cc;?>').val(); var orderid=$('#orderid<?php //echo $cc;?>').val();$.post('updateOrderStatusUndo.php',{itemid:itemid,orderid:orderid,customerid:customerid,shopid:shopid},function(data){$('#rdn<?php// echo $cc;?>').html(data).show();}); $('#postUpdate<?php //echo $cc;?>').hide();$('#postEdit<?php //echo $cc;?>').show();" />
 -->
  </td>

	</tr>

<?php
} 
$cc=0;
}
else
{
	?>
	<tr>
		<td>
			You don't have any order now!..
		</td>
	</tr>
	<?php
}
?>
</table>
<?php
}
else{
  echo "Currently you don't have register!..";
}
}
else{
	echo "NETWORK PROBLEM WHILE TRYING TO LOAD!..";
}
?>