<?php
	include("includes/dbconfig.php");
	$pagetitle = "Customers";
	require('includes/applicationtop.php');
	require('includes/applicationmenu.php');//newexpanse.php
	$post = 0;
	
	
?>
			<!-- Content Wrapper. Contains page content -->
			<div class="content-wrapper">
				<!-- Content Header (Page header) -->
				<section class="content-header">
					 
					<ol class="breadcrumb">
					</ol>
				</section>

				<!-- Main content -->
				<section class="content">
					<!-- Default card -->
					<?php
						if($_SESSION["connectedusergroup"] == 3 || $_SESSION["connectedusergroup"] == 4 || $_SESSION["connectedusergroup"] == 1)
						{
					?>
					<div class="row">
						<div class="col-md-12">
							<div id="servererrormessage">
							</div>
						</div>
					</div>

                    <div class="row">
						<div class="col-md-12">
							<div style="">
                                <?php
                                if(isset($_POST['amount'])){
									$post = 1;
                                    $expanse = trim($_POST['expanse']);
                                    $amount = trim($_POST['amount']);
                                    $notes = trim($_POST['notes']); 
									$branch = trim($_POST['branch']); 

                                    DB::$error_handler = false;
		                            DB::$throw_exception_on_error = true;
		
                                    try
                                    {
                                       
                                        $trxnConnextn = new MeekroDB();
                                        $trxnConnextn->startTransaction();

                                        $trxnConnextn->insert
                                        ('expanses', 
                                            array
                                            (
                                                'exnotes' => $notes,
                                                'expanse' => $expanse,
                                               
												  'exbranch' => $branch,
												  'examount'=> $amount,
                                                
                                                'captured_by' => $_SESSION["connecteduserid"]
                                            )
                                        );


                                        $insertedrecord = $trxnConnextn->insertId();
                                        $trxnConnextn->commit();
                                    }
                                    catch(MeekroDBException $e)
		                            {
                                        $err = $err.$e->getMessage()."<br>";
                                        $err = $err.$e->getQuery()."<br>";
                                        $trxnConnextn->rollback();
                                        $errormessage = "<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>" . $err . "</div>";
                                        $server_response[] = array('issaved' => 0, 'message' => $errormessage);
                                        DB::$error_handler = 'meekrodb_error_handler';
                                        DB::$throw_exception_on_error = false;
                                        echo json_encode($server_response);
                                        exit();
                                    }
                                }
                                    
                                ?>
							</div>
						</div>
					</div>
				
					<div class="row">
						<div class="col-md-12"  id="customerdetails">
						
						 <!-- general form elements -->
            <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Expenses </h3>
              </div>
			  
			  <div class="card-body">
			  <a href='newexpanse.php'> Add New</a>
			   <table class="table">
			    <thead>
                    <tr>
                    
                      <th>Amount</th>
					  <th>Type</th>
                      <th>Date</th>
					   <th>Branch</th>
					  <th>Notes</th>
					  <th>Captured By</th>
					 
                       
                    </tr>
                  </thead>
			  <?php
			                        // if($post > 0){
			  
										$shopsalesdata = DB::query("SELECT exid, examount, expanse_type, exnotes, full_name, exdate, first_name , last_name FROM `expanses`  join shop on shop.id = exbranch left JOIN expanse_types on expanse_types.eid=expanse JOIN personnel_details on personnel_details.id=captured_by");
										
									 
									// }
									 $i = 0;
										
										foreach($shopsalesdata as $row)//
										{
										 
										 
											echo ' <tr > 
											<td>'.$row['examount'].'</td>
											<td>'.$row['expanse_type'].'</td>
											<td>'.$row['exdate'].'</td>
											<td>'.$row['full_name'].'</td>
											 <td>'.$row['exnotes'].'</td>
											
											<td>'.$row['first_name'].' , '.$row['last_name'].'</td> 
											</tr>';
									 
										}
			  ?>
			  </table>
			  
			  </div>
               
            </div>
            <!-- /.card -->
							 
						
						
					</div>
					<?php
						}
						else
						{
					?>
					<div class="alert alert-danger alert-dismissable">
						<i class="fa fa-ban-circle"></i>
						Limited Access
					</div>
					<?php
						}
					?>
				</section><!-- /.content -->
			</div><!-- /.content-wrapper -->

			 
		</div><!-- ./wrapper -->
		
		
		
		<?php include ('includes/general_footer.php')?>
		
		<script src="plugins/bert/jquery.price_format.min.js" type="text/javascript"></script>
		<script src="plugins/bert/storepos.js" type="text/javascript"></script>
		<script src="plugins/bert/cashsalesregister.js" type="text/javascript"></script>
	</body>
</html>