 <?php 
include 'dheader.php';
$success = "";
$danger = "";
if (isset($_POST['submitf'])) {
 	# code...
 	extract($_POST, EXTR_OVERWRITE);
 	$date = $_POST['date'];

	$change_date = explode("/", $date);
	$show_date = $change_date[1]."/".$change_date[0]."/".$change_date[2];
	$php_date = $change_date[2]."/".$change_date[0]."/".$change_date[1];

	$ecus_date = explode('/', $date);
	$set_date = $ecus_date[2].'/'.$ecus_date[0].'/'.$ecus_date[1];
 	$countQuery = $db->query("SELECT count(*) totalCount FROM customer_setup WHERE customer_name = '$fullname'");
 	$rowcount = $countQuery->fetchArray();
 	$totalCount = $rowcount['totalCount'];
 	if ($totalCount < 1) {
 		# code...
 		$sql = $db->query("INSERT INTO customer_setup (date, customer_name, email, phone, address, city, ntn, gst, comments, open_balance, amountLimit, company_name, account_no, current_balance, active) VALUES ('$date', '$fullname', '$email', '$phone_number', '$address', '$city', '$ntn', '$gst', '$comments', '$balance', '$credit_limit', '$company_name', '$account_number', '$balance', 1)");

 		$GetID = $db->query("SELECT * FROM customer_setup ORDER BY id DESC LIMIT 1");
 		$ID = $GetID->fetchArray();

 		$sql = $db->query("INSERT INTO customerinvoice (payment_type, date, php_date, show_date, name, subtotal, remaining) VALUES ('Opening Balance', '$date', '$php_date', '$show_date', 'c".$ID['id']."', '$balance', '$balance')");

 		$success = "<strong>Success!</strong> Customer added successfully."; 
 	}else{
 		$danger = "<strong>Warning!</strong> This Customer name already exist.";
 	} 
 }  
?>
	<div class="modal fade hidden-print" id="myModal" tabindex="-1" role="dialog" aria-hidden="true"></div>
	<div class="wrapper ">
		<?php include 'leftbar.php'; ?>
		<!-- left-bar -->
		<?php include 'topbar.php'; ?>
			<!-- top-bar -->
			<div class="main-content">

<div class="row" id="form">
	<div class="spinner" id="grid-loader" style="display:none">
	  <div class="rect1"></div>
	  <div class="rect2"></div>
	  <div class="rect3"></div>
	</div>
	
	<div class="col-md-12">
			
		
			<form action="" id="customer_form" class="form-horizontal" enctype="multipart/form-data" method="post" accept-charset="utf-8" novalidate="novalidate">

			<div class="panel panel-piluku">
				<div class="panel-heading">
		                <h3 class="panel-title">
		                     <i class="ion-edit"></i> 
		                    Customer Information							<small>(Fields in red are required)</small>
		                </h3>
		        </div>

			<div class="panel-body">
					<?php
                    if (isset($_POST['submitf'])) {
                    ?>
                    <div class="alert alert-<?php echo ($success) ? "success" : "danger"; ?>"> 
                            <?php echo ($success) ? $success : $danger; ?>                          
                    </div>
                 <?php } ?>

				<div class="row">
	<div class="col-md-12">
		<div class="form-group">
			<label for="date" class="col-sm-3 col-md-3 col-lg-2 control-label required">Date :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
			<input type="text" name="date" value="<?php echo date("m/d/Y"); ?>" class="form-control datepicker" id="date">
			</div>
		</div>

		<div class="form-group">
			<label for="first_name" class="required col-sm-3 col-md-3 col-lg-2 control-label ">Customer Name:</label>			<div class="col-sm-9 col-md-9 col-lg-10">
				<input type="text" name="fullname" list="listCustomers" autofocus  value="" class="form-control" id="fullname">
				<datalist id="listCustomers">
						<?php
							$listItems = $db->query("SELECT * FROM customer_setup");
							while($listrow = $listItems->fetchArray()){
						?>
							<option value="<?php echo $listrow['customer_name']; ?>"><?php echo $listrow['customer_name']; ?></option>
						<?php } ?>
				</datalist>
			</div>
		</div>

		<div class="form-group">
			<label for="email" class="col-sm-3 col-md-3 col-lg-2 control-label not_required">Email :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
			<input type="text" name="email" value="" class="form-control" id="email">
			</div>
		</div>
		<div class="form-group">	
			<label for="phone_number" class="col-sm-3 col-md-3 col-lg-2 control-label ">Phone Number :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
			<input type="text" name="phone_number" value="" class="form-control" id="phone_number">
			</div>
		</div>
		

<div class="form-group">	
<label for="address_1" class="col-sm-3 col-md-3 col-lg-2 control-label ">Address :</label>	<div class="col-sm-9 col-md-9 col-lg-10">
	<input type="text" name="address" value="" class="form-control" id="address">
	</div>
</div>

			<div class="form-group">	
<label for="city" class="col-sm-3 col-md-3 col-lg-2 control-label ">City :</label>	<div class="col-sm-9 col-md-9 col-lg-10">
	<input type="text" name="city" value="" class="form-control " id="city">
	</div>
</div>

			<div class="form-group">	
<label for="ntn" class="col-sm-3 col-md-3 col-lg-2 control-label ">NTN :</label>	<div class="col-sm-9 col-md-9 col-lg-10">
	<input type="text" name="ntn" value="" class="form-control " id="ntn">
	</div>
</div>

			<div class="form-group">	
<label for="gst" class="col-sm-3 col-md-3 col-lg-2 control-label ">GST :</label>	<div class="col-sm-9 col-md-9 col-lg-10">
	<input type="text" name="gst" value="" class="form-control " id="gst">
	</div>
</div>

	<div class="form-group">	
<label for="comments" class="col-sm-3 col-md-3 col-lg-2 control-label ">Comments :</label>	<div class="col-sm-9 col-md-9 col-lg-10">
	<textarea name="comments" cols="17" rows="5" id="comments" class="form-control text-area"></textarea>
	</div>
</div>
 
	</div><!-- /col-md-12 -->
</div><!-- /row -->				
								<div class="form-group">	
					<label for="balance" class="col-sm-3 col-md-3 col-lg-2 control-label ">Opening Balance :</label>					<div class="col-sm-9 col-md-9 col-lg-10">
						<input type="text" name="balance" value="0.00" id="balance" class="form-control balance">
						</div>
					</div>

				<div class="form-group">	
					<label for="credit_limit" class="col-sm-3 col-md-3 col-lg-2 control-label ">Credit Limit :</label>					<div class="col-sm-9 col-md-9 col-lg-10">
						<input type="text" name="credit_limit" value="" id="credit_limit" class="form-control credit_limit">
						</div>
					</div>
								
								
				
				<div class="form-group">	
					<label for="company_name" class="col-sm-3 col-md-3 col-lg-2 control-label ">Company Name :</label>					<div class="col-sm-9 col-md-9 col-lg-10">
						<input type="text" name="company_name" value="" id="company_name" class="company_names form-control">
						</div>
					</div>

					<div class="form-group">	
						<label for="account_number" class="col-sm-3 col-md-3 col-lg-2 control-label ">Account # :</label>						<div class="col-sm-9 col-md-9 col-lg-10">
							<input type="text" name="account_number" value="" id="account_number" class="company_names form-control">
							</div>
						</div>

						<div class="form-actions pull-right">
														
							<input type="submit" name="submitf" value="Submit" id="submitf" class=" submit_button btn btn-primary">
						</div>
					</div>
				</div>
										</form>
			</div>
		</div><!-- /row -->


	

			
<?php include 'dfooter.php'; ?>