<?php 	
            include_once('../../config.php');    
			
			
			function Rechech($valpass)
			{   		
						
						$sr=1; 
						$a = 40;
						$Main =$a; 
						$x = $Main; 
						
						for($i=0;$i<50;$i++)
						{
							
							if($sr>1)
							{ 
								$x = 0;
								$x1 = 0;
								for($i1=0;$i1<=$i;$i1++) 
								{
									$x +=  $val1[$i1]  + (($val1[$i1]*15)/100) ;
									$x1 += $val1[$i1] +  (($val1[$i1]*15)/100) ;
								} 
								$x +=$Main; 
							   // die;
							}  
							
							$val1[$i] = round($x/9.5); 
							
							$PerGame[] = ($val1[$i]+($val1[$i]*15)/100);
						 
								
								if($sr % 2 == 0)  
								{
									//$Main += $a;
									// echo '<br>';
								}  
								$sr++;
							}
					
						$zeroSet = 0;
						 
						
						foreach($PerGame as $key=>$dt)
						{ 	 
							$dt = round($dt);
							if( ($dt > round($valpass)) && ($zeroSet==0) ) 
							{  
								$zero = round($dt);  
								$zeroSet = 1; 
							} 
						}
						
						return $zero;
			}
	 
			    
			    
			 
			
			if(isset($_POST['submit']))
			{    
                $RST = mysql_query("select * from  splitCalc order by id");
                while($rw = mysql_fetch_object($RST))
                {
                    $amt = 0;   
					$amt =  Rechech($rw->splitAmt); 
                    mysql_query("update  splitCalc set splitAmt = $amt where id = $rw->id  ");   
                }   
              
                $tDate = date("Y-m-d"); 
                $market = $_POST['market']." ".$_POST['type']." ".date("d-M-Y") ; 
                
                $Ft = $_POST['zero']+$_POST['one']+$_POST['two']+$_POST['three']+$_POST['four']+$_POST['five']+$_POST['six']+$_POST['seven']+$_POST['eight']+$_POST['nine'];
	    	    mysql_query("insert into calc (zero,one,two,three,four,five,six,seven,eight,nine,tDate,market) values($_POST[zero],$_POST[one],$_POST[two],$_POST[three],$_POST[four],$_POST[five],$_POST[six],$_POST[seven],$_POST[eight],$_POST[nine],'$tDate','$market') ");				
			    $ID = mysql_fetch_object(mysql_query("select id from  calc order by id desc "));  
			    mysql_query("update splitCalc set calcId = $ID->id; ");
			    
			    mysql_query("update  FinalAmt set finalAmt = finalAmt - $Ft ");   
                header("Location:  calc.php "); 
                die;
			} 
		 

			$rst = mysql_query("select * from calc where id=$_REQUEST[id]");
			$value  = mysql_fetch_object($rst);
		 
		 
    $sr=1; 
    $a = 40;
    $Main =$a; 
    $x = $Main; 
    
        
        $Tdate= date("Y-m-d"); 
        $aryD[] = 10;
        
        $BlockR = mysql_query("select * from  blockedD where Tdate = '$Tdate' ");
        while($Brst = mysql_fetch_object($BlockR)) 
        $aryD[] =$Brst->digit;

    
    for($i=0;$i<50;$i++)
    {
        
        if($sr>1)
        { 
            $x = 0;
            $x1 = 0;
            for($i1=0;$i1<=$i;$i1++) 
            {
                $x +=  $val1[$i1]  + (($val1[$i1]*15)/100) ;
                $x1 += $val1[$i1] +  (($val1[$i1]*15)/100) ;
            } 
            $x +=$Main; 
           // die;
        }  
        
        $val1[$i] = round($x/9.5); 
        
        $PerGame[] = ($val1[$i]+($val1[$i]*15)/100);
    //    echo '<tr><td>'.$sr.'</td>'.'<td>'.($val1[$i]+($val1[$i]*15)/100).'</td><td>'.(($val1[$i]+($val1[$i]*15)/100) * 9.5).'</td><td>'.($x1+($val1[$i]+($val1[$i]*15)/100)).'</td></tr>';
        
     
            
            
            if($sr % 2 == 0)  
            {
                //$Main += $a;
                // echo '<br>';
            }  
            $sr++;
        }
        
        $zeroSet = 0;
        $OneSet = 0;
        $TwoSet = 0;
        $ThreeSet = 0;
        $FourSet = 0;
        $FiveSet = 0;
        $SixSet = 0;
        $SevenSet = 0;
        $EightSet = 0;
        $NineSet = 0;
		
		foreach($PerGame as $key=>$dt)
		{ 	
		    
		    $dt = round($dt);
			if( ($dt > round($value->zero)) && ($zeroSet==0) ) 
			{  
				
                if(array_search(0,$aryD))
                $zero = round($value->zero);
                else
                $zero = round($dt);    
				$zeroSet = 1; 
				$nextzero = round($PerGame[$key+1]);
			}
			
			if( ($dt > round($value->one)) && ($OneSet==0) ) 
			{  
				 if(array_search(1,$aryD))
                    $one = round($value->one);
                    else
				$one = round($dt);  
				$OneSet = 1;
				$nextone = round($PerGame[$key+1]);
			}
			
			if( ($dt > round($value->two)) && ($TwoSet==0) ) 
			{  
				 if(array_search(2,$aryD))
                    $two = round($value->two);
                    else
				$two = round($dt);  
				$TwoSet = 1;
				$nexttwo = round($PerGame[$key+1]);
			}
			
			if( ($dt > round($value->three)) && ($ThreeSet==0) ) 
			{  
				if(array_search(3,$aryD))
                    $three = round($value->three);
                    else
				$three = round($dt);  
				$ThreeSet = 1;
				$nexthree = round($PerGame[$key+1]);
			}
			
			
			if( ($dt > round($value->four)) && ($FourSet==0) ) 
			{  
					if(array_search(4,$aryD))
                    $four = round($value->four);
                    else
                $four = round($dt);  
				$FourSet = 1;
				$nextfour = round($PerGame[$key+1]);
			}  

			if( ($dt > round($value->five)) && ($FiveSet==0) ) 
			{  
				
					if(array_search(5,$aryD))
                    $five = round($value->five);
                    else 
				$five = round($dt);  
				$FiveSet = 1;
				$nextfive = round($PerGame[$key+1]);
			}  

			if( ($dt > round($value->six)) && ($SixSet==0) ) 
			{  
					if(array_search(6,$aryD))
                    $six = round($value->six);
                    else 
				$six = round($dt);  
				$SixSet = 1;
				$nextsix = round($PerGame[$key+1]);
			}  	
			
			if( ($dt > round($value->seven)) && ($SevenSet==0) ) 
			{  
					if(array_search(7,$aryD))
                    $seven = round($value->seven);
                    else 
				$seven = round($dt);  
				$SevenSet = 1;
				$nextseven = round($PerGame[$key+1]);
			} 

			if( ($dt > round($value->eight)) && ($EightSet==0) ) 
			{  
				
                if(array_search(8,$aryD))
                $eight = round($value->eight);
                else 
				$eight = round($dt);  
				$EightSet = 1;
				$nexteight = round($PerGame[$key+1]);
			} 

			if( ($dt > round($value->nine)) && ($NineSet==0) ) 
			{  
                if(array_search(9,$aryD))
                $nine = round($value->nine);
                else 
				$nine = round($dt);  
				
				$NineSet = 1;
				$nextnine = round($PerGame[$key+1]);
			} 
		}
		
		
       
		 
			        
?>  
<?php  include ABS_PATH.'/admin/header.php';	?>  


 <script>
	$(function() {
		$( "#datepicker" ).datepicker(); 
	}); 
  
	$(document).ready(function()
	{   

	
	$("#product_frm").validate({
		
		errorElement:'div',
		rules:{ 
			city:{
				required:true				 
			} 
			
			
			
		},
		messages:{				
			 
			 city:{
				required:"Enter city name"				 
			} 
		}
	});


	});
 


</script>
		 
		 <div class="col-md-10">

	  			<div class="row">
	  				<div class="col-md-12">
	  					<div class="content-box-large">
							<div class="panel-heading">
								<div class="panel-title"> <h3> <?php //echo $val;?> </h3></div>    
								
								<div class="panel-options"> 

								   <input type="button"  class="btn btn-warning" name="btnback" id="btnback" value=" Back " onClick="javascript:location.href='calc.php';" />
								  
								</div>
							</div>
							
			  				<div class="panel-body">
								
								 
			  					<form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" id="product_frm">
								
								<div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">Market Name</label>
								    <div class="col-sm-3">
								      <select name="market" class="form-control"> 
										<option>Karnataka Day</option>  
										<option>Sridevi</option> 
										<option>Time Bazar</option>  
										<option>Madhur Day</option> 
										<option>Milan Day</option> 
										<option>Rajdhani  Day</option> 
										<option>Kalyan </option>  
										<option>Suprem  Day</option>   
										<option>Karnatak night</option> 
										<option>Sridevi Night </option>
										<option>Madhur   Night </option> 
										<option>Milan    Night </option>   
										<option>Suprem  Night</option>  
										<option>Kalyan   Night </option>     
										<option>Main Bazar  </option>
										
									  </select>
								    </div>
								 </div>
								 <hr> 

								<div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">Type</label>
								    <div class="col-sm-3">
								       <select name="type" class="form-control"> 
										<option>Open</option>
										<option>Close</option> 
									  </select>
								    </div>
								 </div>
								 <hr>  

								<div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">0</label>
								    <div class="col-sm-3">
								      <input name="zero" class="form-control"   placeholder="Value" value="<?php echo $zero;?>"  >
									   => <?php echo $nextzero;?>
								    </div>
								 </div>
								 <hr>  		
								 
								 
								<div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">1</label>
								    <div class="col-sm-3">
								      <input name="one" class="form-control"   placeholder="Value" value="<?php echo $one;?>"  >
									  => <?php echo $nextone;?>
								    </div>
								 </div>
								 <hr>   
								   
								   
								  
								   
								<div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">2</label>
								    <div class="col-sm-3">
								      <input name="two" class="form-control"   placeholder="Value" value="<?php echo $two;?>"  >
									  => <?php echo $nexttwo;?>
								    </div>
								 </div>
								 <hr>   
								 
								    
								<div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">3</label>
								    <div class="col-sm-3">
								      <input name="three" class="form-control"   placeholder="Value" value="<?php echo $three;?>"  >
									  => <?php echo $nexthree;?>
								    </div>
								 </div>
								 <hr>   
								   
								   
								      
								<div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">4</label>
								    <div class="col-sm-3">
								      <input name="four" class="form-control"   placeholder="Value" value="<?php echo $four;?>"  >
									  => <?php echo $nextfour;?>
								    </div>
								 </div>
								 <hr>   
								   
								   
								      
								<div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">5</label>
								    <div class="col-sm-3">
								      <input name="five" class="form-control"   placeholder="Value" value="<?php echo $five;?>"  >
									  => <?php echo $nextfive;?>
								    </div>
								 </div>
								 <hr>   
								   
								   
								      
								<div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">6</label>
								    <div class="col-sm-3">
								      <input name="six" class="form-control"   placeholder="Value" value="<?php echo $six;?>"  >
									  => <?php echo $nextsix;?>
								    </div>
								 </div>
								 <hr>   
								   
								   
								      
								<div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">7</label>
								    <div class="col-sm-3">
								      <input name="seven" class="form-control"   placeholder="Value" value="<?php echo $seven;?>"  >
									  => <?php echo $nextseven;?>
								    </div>
								 </div>
								 <hr>   
								   
								   
								      
								<div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">8</label>
								    <div class="col-sm-3">
								      <input name="eight" class="form-control"   placeholder="Value" value="<?php echo $eight;?>"  >
									  => <?php echo $nexteight;?>
								    </div>
								 </div>
								 <hr>    
								 
								 <div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">9</label>
								    <div class="col-sm-3">
								      <input name="nine" class="form-control"   placeholder="Value" value="<?php echo $nine;?>"  >
									  => <?php echo $nextnine;?>
								    </div>
								 </div>
								 <hr>        
								  
								  <div class="form-group">
										<label for="inputEmail3" class="col-sm-2 control-label">Add</label>
										<div class="col-sm-10">
										  <input type="submit"    class="btn btn-primary"  name="submit" value="Add">  
										   
										</div>
								  </div>   
								  
								   
								  
								  
								</form>
								
								
							
			  				</div>
			  			</div>
	  				</div>
	  				 
	  			</div>

	  			 


	  		<!--  Page content -->
		  </div>
		</div>
    </div>

<?php  include ABS_PATH.'/admin/footer.php';	

 /*    
                    if($rw->spliFor==0)
                        mysql_query("update  splitCalc set splitAmt = $_POST[zero] where spliFor = 0 ");
                     
                    if($rw->spliFor==1)
                        mysql_query("update  splitCalc set splitAmt = $_POST[one] where spliFor = 1 ");
                    
                    if($rw->spliFor==2)
                        mysql_query("update  splitCalc set splitAmt = $_POST[two] where spliFor = 2 ");
                    
                    if($rw->spliFor==3)
                        mysql_query("update  splitCalc set splitAmt = $_POST[three] where spliFor = 3 ");
                    
                    if($rw->spliFor==4)
                        mysql_query("update  splitCalc set splitAmt = $_POST[four] where spliFor = 4 ");
                        
                    if($rw->spliFor==5)
                        mysql_query("update  splitCalc set splitAmt = $_POST[five] where spliFor = 5 ");
                    
                    if($rw->spliFor==6)
                        mysql_query("update  splitCalc set splitAmt = $_POST[six] where spliFor = 6 "); 
                    
                    if($rw->spliFor==7)
                        mysql_query("update  splitCalc set splitAmt = $_POST[seven] where spliFor = 7 ");
                    
                     if($rw->spliFor==8)
                        mysql_query("update  splitCalc set splitAmt = $_POST[eight] where spliFor = 8 ");
                        
                    
                     if($rw->spliFor==9)
                        mysql_query("update  splitCalc set splitAmt = $_POST[nine] where spliFor = 9 ");   
                        
                    */
                    
?>    