 <?php 
   require_once("head2AltStaff.php");
   if(isset($_POST['post']))

  {

     if( isset($_POST['shopid']) && isset($_POST['owniD']))
     {

        $shopid=$_POST['shopid'];
        $ownID=$_POST['owniD']; 
        
        $getS=$myAgrocon->getSelectedShopOther($shopid);
         if ($getS->rowCount()>0) {
            $shop=$getS->fetch();
           }
    
   
    $arrived_on="";
    $edate="";

    $post=$_POST['post'];
    if ($post=="Date")
    {
       if (isset($_POST['sdate'])) {
         
           $arrived_on=($_POST['sdate']); 
             
            $hIo=$myAgrocon->getMyShopExpenseByDate($shopid,$arrived_on); 
       }
    }

     if ($post=="Range of date")
    {
       if (isset($_POST['sdate']) && isset($_POST['edate'])) {
           $arrived_on=($_POST['sdate']);
           $edate=($_POST['edate']); 
           $hIo=$myAgrocon->getMyShopExpenseByDateRange($shopid,$arrived_on,$edate);
            
         
       }
    }

    if ($post=="Expenses"){
        

        $hIo=$myAgrocon->getMyShopExpenses($shopid); 

    }
                 ////


    }
  }

if($post=="Submit"){
    
   if(isset($_POST['post']))

  {

  $hIo=$myAgrocon->getMyShopExpenses($shopid);
 

    $post=$_POST["post"];
    if ($post=="Submit") {
       //////////////////////
   $sname=$_POST['sname'];  $shopid=$_POST['shopid'];

   $scost =$_POST['scost']; $ownID=$_POST['owniD'];
 
  $dateearned=$_POST['dateearned'];

  
   if($con->vSname($sname) && $con->vDateearned($dateearned) && $con->vScost($scost))
      { 

        ?>

  <center>
     
      <div>
       
       <sup>
       <?php 
    
        print_r( $myAgrocon->addExpensesRecord($sname,$scost,$dateearned, $shopid)); 
        ?>
       </sup>
     </div>
  </center> 


<?php 

      }
   else
      {
       if(isset($_POST['shopid']) && isset($_POST['owniD']))
           {
            ?>


            <center>
                <div>
                 <sup>
                  <?php 
                  echo $con->eSname($sname)."<p/>";
                  echo $con->eScost($scost)."<p/>";
                  echo $con->eDateearned($dateearned)."<p/>";
    
                ?>
                 </sup>
                 </div>
            </center> 

            <?php
 
           }
      }

      //////////////////////
    }

  }
     
  }
  
?> 
 
  
 
   <!--NEW USER REGISTRATION FORM, DISPLAYED BY DEFAULTS IN PAGE LOAD-->


<center>
    
    <?php
    // require_once('shopNavLink.php');
    ?>
    
    
    <fieldset id="new_expform">
<label id="reg_form_tile_label">Add expenses here </label></p/>
<i>Please fill the form below to add the expenses-</i>
<form name="new_user_registration" id="new_user_registration" action="expensesReportStaff.php" method="POST">

<table border="0" width="100%">

   <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;?>">

        
    <tr>
  
  <td height="40px" >

        <label id="mini_label">Date:<sup>*</sup></label>  
 </td>
 
 
  <td height="40px" >
         <input type="date" value="<?php echo date("Y-m-d");?>" name="dateearned" id="dateearned" class="prof_info"/>
         <sup id="dp"></sup>
         
  </td>

 
  
  <td height="40px"  >

        <label id="mini_label">Purpose:<sup>*</sup></label>
</td>
 
 
  <td height="40px" >
    
         <input type="text" name="sname" id="sname" class="prof_info"/>
         <sup id="ln"></sup>
         
  </td>
 
 
  <td height="40px" >

        <label id="mini_label">Amount:<sup>*</sup></label>

   </td>
 
 
  <td height="40px">
    
         <input type="text" name="scost" id="scost" class="prof_info"/>
         <sup id="rt"></sup>
  </td>

  

  <td align="center">
        <input type="submit"  name="post" value="Submit" id="submit"/>
  </td>

</tr>

</table>
 
</form>
</fieldset> </center>
 
 <center>
       <fieldset id="new_visitors_reg_form">
       <center>

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


                if ($post=="Date")
                {
                  if($arrived_on=="")
                  {
                  echo "Date required!";
                  }
               }
               ?>
            </sup>
        </center>
          <form action="expensesReportStaff.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 $arrived_on;?>" >


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

          </form>
        </fieldset>
                    <!--////////////////////
                    ////////////////////////-->
 

                     <!--///////////////////////////
                            OTHER EXPENSES


                            /////////////////////
                            -->

  <fieldset id="new_hotel_income_form">
    <table width="100%" >

    <tr><td colspan="4" align="center"><label id="min_lab">MY SHOP EXPENSES</label></td></tr>
    <tr class="tr1">

       <td align="center">

       <label id="min_lab">EXPENSE ID </label>

       </td>

       <td align="center">

       <label id="min_lab">EXPENSE PURPOSE</label>

       </td>

       <td align="center"> 
         <label id="min_lab">DATE SPEND</label>

       </td>
        

       <td align="center">
         <label id="min_lab">AMOUNT SPEND</label>

       </td>
       

    </tr>

    <?php
    if($hIo->rowCount()>0)
    {
       $hNo=$hIo->fetchAll();
       $Tc=0;
       $tC=0;
       $Tn=0;
       foreach ($hNo as $key => $ico) 
       {
          
      
       ?>
        <tr class="tr">

             <td valign="bottom" height="45px" align="center">
                
               <?php echo $ico["expenses_id"];?>
              
             </td>
             <td align="center">

               <?php echo $ico["exp_purpose"];?> 
             </td>
 


            <td align="center">

            <?php echo $ico["exp_date"];?> 

            </td>

           <td align="center">

           <?php echo $ico["amount"];   
             
          $Tn=$Tn+ $ico["amount"]; 
             ?> 
          
        </td>

         </tr>
    <?php
       }
       ?>
       <tr><td colspan="3" align="right">

           <label id="main_lab"> TOTAL:</label>

           
       </td>
       <td align="center">
       <label id="main_lab">
          <?php
            echo $Tn;
            ?>
            <hr>
            </label>
       </td>
        

       </tr>
       <?php
    }
    else{
      ?>
      <tr class="tr2" ><td colspan="4">No cash earned up to moment!..</td></tr>
   <?php
    }
    ?>
    </table>
     </fieldset>
     
     
  <?php
//require_once('footerIn.php');
?>


<script>
 
$(document).ready(function(){
  
$("#new_user_registration").on('submit',function(e){

var sname =document.getElementById('sname').value;
$.trim(sname);  
var scost =document.getElementById('scost').value;
$.trim(scost);  
 
var dateearned =document.getElementById('dateearned').value;
 

var vN =/[\(A-Za-z)]/g;
var nV =/[a-z\s]/i;
var nR =/[A-Za-z0-9]/i;
var nC =/[0-9]/i;
var j=0,k=0, g=0,i=0;

  



                                                       //SERVICE ID VALIDATION




  if(dateearned==""){
  e.preventDefault();

  document.getElementById('dp').innerHTML="Date required!..";

 }
 else
 {
 
   document.getElementById('dp').innerHTML="";

  }
   
 
    j=0, i=0;
 

                                                         //ROOM NAME VALIDATION
if(sname=="")
{
e.preventDefault();

document.getElementById('ln').innerHTML="Income source required!..";
 } 
 else
 {

      for(i=0;i<sname.length;i++)
       {
         if(!sname[i].match(nV))
          {
             j++;

           }
        }
      
       if(j>0){
       e.preventDefault();

       
        document.getElementById('ln').innerHTML="You typed Income source with error!.."; 


              }
         else{

        document.getElementById('ln').innerHTML="";

              }
   }
 
    j=0, i=0;
                                                                               ///ROOM TYPE VALIDATION
 

if(scost==""){
 e.preventDefault();

document.getElementById('rt').innerHTML="Amount required!..";
 }
 else{

     for(i=0;i<scost.length;i++)
       {
         if(!scost[i].match(nC))
          {
             j++;

           }
        }
      
       if(j>0){
       e.preventDefault();
 
        document.getElementById('rt').innerHTML="Amount typed with error!.."; 
              }
         else{
       

        document.getElementById('rt').innerHTML="";

              }
   }
 
    j=0, i=0;
      
 
                                                                            ///ROOM ID VALIDATION
  
}
);
}
);  
    
 
</script>
