<?php
	include("my_functions.php");
	$pagetitle = "Remove a task from a job";
	require('includes/applicationtop.php');
	require('includes/applicationmenu.php');
	
	$err= "";

    $actual_link = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
		$parts = explode('deleteatask' , $actual_link);
		
    $fromdate = false;
    $command = false;
	
	$startdatevalid = false;
	
	 
		 
        if(!empty($_POST["receipt"]) and !empty($_POST["focus"])   ){

  
            $status = $_POST["status"];  
            $bill     = $_POST["bill"]; 
            DB::startTransaction();
					DB::query("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE");
					DB::update
					('job_receipt', 
						array
						(
							'bill' => $bill,
                             
                        ),"id=%i", $_POST['receipt']
					);
					
					DB::commit();

                    DB::query('DELETE FROM job_sale_item WHERE id='.$_POST['focus'].'');
                    DB::commit();
                    
                    
                    ?>
						<script>
							window.location = "<?= $base_url?>dashboard";
						</script>
                        <?php
			
			 
			
			 
			 
		 
	}else{

        $end = $parts[1];
		 $parts = explode('/' , $end);

        $command =  $parts[1];
        

        
								 
								  
 
    }
?>
			<!-- Content Wrapper. Contains page content -->
			<div class="content-wrapper">
			 

				<!-- Main content -->
				<section class="content">
					<!-- Default card -->
					<div class="card card-primary">
						<?php
							if($_SESSION["connectedusergroup"] == 1 || $_SESSION["connectedusergroup"] < 5)
							{
						?>
						<div class="card-body">
							<div id="servererrormessage">
							</div>
							
							<?php
								if($err!="")
								{
							?>
							<div class="alert alert-danger alert-dismissable">
								<i class="fa fa-ban"></i>
								<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button><br>
								<?php 
									echo $err; 
								?>
							</div>
							<?php
								}
							?>
							
							<div class="card card-info">
                                <div class="card-header">
                                    <h6 class="card-title"><?= $pagetitle ?></h6>
                                </div>
                                <div class="card-body">
                            
                               
							
							 
								<?php
									if($err=="" )
									{
								?>
								   

                                 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

                                 <div class="form-group  ">
									

                                    <?php  

                                     $task= receipt_item_by_id($command);

                                  
                                     $receipt = $name = $fees = $bar =   $grand_amount =0;

                                     foreach($task as $t){

                                         $name = strtoupper(strtolower($t['job_name']));
                                         $fees = $t['job_amount']; 
                                         $bar= $t['general_bar_code'];

                                         $parent_job = getjob_by_barcode($bar);

                                         foreach($parent_job as $r){
                                            $receipt = $r['id'];
                                            $grand_amount = $r['bill'];
                                         }
                                     }

                                     if(  $grand_amount > 0){

                                     $grand_amount -= $fees; 



                                    
                                    ?>

                                <label for="employee_role"> <b> <?= $name;?></b> will be removed from this job. Your new cost is now <?= $grand_amount ?> from <?=  $grand_amount + $fees?></label>
									 
                                         
                                         
                                         
                                         <!-- form-group -->

                                         <input type="hidden" name="focus"   maxlength="40" class="form-control" value="<?php echo $command; ?>" >  
                                         <input type="hidden" name="bill"   maxlength="40" class="form-control" value="<?php echo $grand_amount ; ?>" >
                                         <input type="hidden" name="receipt"   maxlength="40" class="form-control" value="<?php echo $receipt ; ?>" >
                                      
 
                                            

                                            <div class="btn-list">
								<div class="text-right">
									<a href="dashboard.php" class="btn btn-danger"><i class="glyphicon glyphicon-remove"></i> Cancel</a>
									
									<button type="submit" name="savedatabtn" id="savedatabtn" class="btn btn-success"><i class="glyphicon glyphicon-floppy-disk"></i> Save</button>
								</div>
							</div>

                            <?php } else { echo 'Error has occurred';}?>

                                    </form>
								  
								   
                                     

                                </div>
                            </div>
              <!-- /.card-body -->
            </div>
									 
								
								   
								 
										 
								
								
								
								</div>
							</div>
						</div><!-- /.card-body -->
						<?php
							}
							}
							else
							{
						?>
						<div class="alert alert-danger alert-dismissable">
							<i class="fa fa-ban-circle"></i><br>
							Limited Access
						</div>
						<?php
							}
						?>
					</div><!-- /.card -->
				</section><!-- /.content -->
			</div><!-- /.content-wrapper -->
 
		</div><!-- ./wrapper -->
		
		<div class="modal" id="waitdialogmodal"  data-backdrop="static">
            <div class="modal-dialog modal-sm">
              <div class="modal-content">
                  <div class="modal-body">
					<div class="text-center">
						<img src="<?php echo $base_url . $ajax_loading_image; ?>" />
					</div>
				  </div>
              </div>
            </div>
        </div>

		 
	
	
	
	
 <?php include ('includes/general_footer.php')?>  
 
<script>
 
		$(function(){
			 
			$('#from').datepicker();
			$('#to').datepicker();
			 
			 
		});
	</script>

	 
		<script src="plugins/bert/storepos.js" type="text/javascript"></script>
		<script src="plugins/bert/store.js" type="text/javascript"></script>
	</body>
</html>