<?php include("../db.php") ?>
<link href="../assets/css/bootstrap.min.css" rel="stylesheet" rev="stylesheet" />
<?php
$pgMod="addexpance";
$pgAct="add";
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);


if($_POST)
{
	$_SESSION['form']=$_POST;
	$flgEr=FALSE;
	if(!isset($_POST['mode']) || trim($_POST['mode'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please enter Income mode.");
	}elseif(!isset($_POST['detail']) || trim($_POST['detail'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please enter Detail.");
	}elseif(!isset($_POST['amount']) || trim($_POST['amount'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please enter Amount.");
	}
	if($flgEr!=TRUE)
	{
		$detail=$_POST["detail"]." (".$_POST["mode"].")";
		$data = array(	
					 'rid'=>$_GET["id"],
					 'tid'=>0,
					 'tfor'=>$_POST["mode"],
					 'type'=>"withdraw",
					 'amount'=>$_POST["amount"],
					  'session'=>$_SESSION["admin"]["session"],
					 'status'=>"1",
					 "school_id"=>$_SESSION["admin"]["school_id"],"added_by"=>$_SESSION["admin"]["uid"],
					 'udate'=>$_POST["idate"],
					 'detail'=>$detail);
		$flgIn = $db->insertAry(TRANSECTION,$data);
		if(!is_null($flgIn))
		{
			$_SESSION['msg']='Saved Successfully';
			unset($_SESSION['form']);
			sms(mydetail("mobile",$_GET["id"],"student"),"Dear Parents, Expense Amount of Rs. ".$_POST["amount"]." is made ".$detail." in ".$LinksDetails["site_name"]." account","hostel_add_fee");
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
			
		}
	}
}
if(isset($_SESSION['msg']) && $_SESSION['msg']!="")
{
	?>
	<div class="alert alert-success">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-thumbs-up-alt"></i> <b>Notice</b><?php echo $_SESSION['msg'] ?></i>
	</div>
	<?php
	unset($_SESSION["msg"]);
}
if(is_array($alert_err) && count($alert_err)>0)
{
	?>
	<div class="alert alert-error">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}
?>
<!-- Forms --> 
	<div class="row-fluid">
        <form method="post" action="">
        <input type="hidden" value="hostel-expance" name="mode" />
			<!-- Forms: Box -->
			<div class="span12">

				<!-- Forms: Top Bar -->
				<div class="top-bar">
					<h3><i class="icon-cog"></i> Create Expance for <?php echo mydetail("name",$_GET["id"],"student")."(".mydetail("mobile",$_GET["id"],"student").")" ?></h3>
				</div>
				<!-- / Forms: Top Bar -->

				<!-- Forms: Content -->
				<div class="well no-padding">
                        <div class="control-group">
							<label class="control-label" for="detail">Expance Detail</label>
							<div class="controls">
								<textarea type="text" id="detail" name="detail" class="input-block-level"><?php if($_POST)echo $_POST["detail"]; ?></textarea>
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="idate">Expance Date</label>
							<div class="controls">
								<input type="date" id="idate" name="idate" class="input-block-level" value="<?php if($_POST)echo $_POST["idate"]; ?>">
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="amount">Expance Amount</label>
							<div class="controls">
								<input type="number" id="amount" name="amount" class="input-block-level" value="<?php if($_POST)echo $_POST["amount"]; ?>">
							</div>
						</div>
						<div class="form-actions">
							<button type="submit" class="btn btn-primary"> Save</button>
							<button type="button" class="btn"> Cancel</button>
						</div>
                        
				</div>
				<!-- / Forms: Content -->

			</div>
			<!-- / Forms: Box -->

        </form>
	</div>
<!-- / Forms -->