<?php
	include("includes/dbconfig.php");
	$pagetitle = "Customers";
	require('includes/applicationtop.php');
	require('includes/applicationmenu.php');//newexpanse.php
	$save = 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['cat'])){
									
									  $cat = ucfirst(strtolower(trim($_POST['cat']))); 
									
									 

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

                                        $trxnConnextn->insert
                                        ('expanse_types', 
                                            array
                                            (
                                                'expanse_type' => $cat
                                            )
                                        );
										$save = 1;


                                        $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-6">
            <div class="card">
              <div class="card-header">
                <h3 class="card-title">Expense Category <a href='newexpanse.php'> Add expense</a></h3>
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                 <form role="form" method='post' action='expanse_category.php'>
             
                <div class="card-body">
				 
				 
				
			 
					  
                  <div class="form-group">
                    <label for="cat">Expense Type</label>
                    <input type="text" class="form-control" name='cat' id="cat" required  placeholder="Enter Category">
                  </div>
				  
				   <!-- /.card-body -->
                   </div>
				   <div class="card-footer">
                  <button type="submit" class="btn btn-primary">Submit</button>
                </div>
              </form>
              </div>
              <!-- /.card-body -->
              
            </div>
            <!-- /.card -->

         
            <!-- /.card -->
          </div>
          <!-- /.col -->
          <div class="col-md-6">
            <div class="card">
              <div class="card-header">
                <h3 class="card-title">Available Categories</h3>

                
              </div>
              <!-- /.card-header -->
              <div class="card-body p-0">
                <table class="table">
                  
                  <tbody>
                     
					
					
			  <?php   
				  
				   
										$shopsalesdata = DB::query("SELECT *from expanse_types ");
										
									 $i = 0;
										
										foreach($shopsalesdata as $row)
										{
										 
										 
											echo ' <tr > <td>'. ($i += 1).'</td><td>'.$row['expanse_type'].'</td></tr>';
									 
										}
										echo '</table>';
									 
				  
				  
			 
				  ?>
                    
                  </tbody>
                </table>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
			</div>
			</div>
				
				 
						 
						
			 
					
		 
					
					
					<?php
						}
						else
						{
					?>
					<div class="alert alert-danger alert-dismissable">
						<i class="fa fa-ban-circle"></i>
						Limited Access
					</div>
					<?php
						}
					?>
					
					 
       
				</section><!-- /.content -->
	 

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