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

	$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];
	
	//$cs_id = $_GET['pay'];
	$action = 0;
	($type == 1) ? $action = 1 : $action = 2;
		$sql = $db->query("INSERT INTO payments2 (date, php_date, show_date, cs_id, type, amount, bank, description, action, debcre) 
			VALUES ('$date', '$php_date', '$show_date', '$pay', '$type', '$amount', '$bank', '".addslashes($description)."', 1, $debcre)");
	
 	if($sql){	
 		$success = "<strong>Success!</strong> Payment added successfully.";
 	}else{
 		$danger = "<strong>Warning!</strong> Something went wrong.";
 	} 

 	$get_pay = preg_replace('/[^0-9]/', "", strtolower($pay));
 	$sql = $db->query("SELECT * FROM supplier_setup WHERE id = '".$get_pay."'");
	$row = $sql->fetchArray();   
 }

 
?>
	<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> 
		                    Supplier Payment							<small>(Fields in red are required)</small>
		                </h3>
		                 <a href="supplierledger.php?name=s<?php echo $row['id']; ?>" title="Account Ledger" class="btn btn-success " style="float: right;">View Ledger</a>
		        </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="required col-sm-3 col-md-3 col-lg-2 control-label ">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 ">Supplier Name :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
			<select name="pay" class="ui search selection dropdown form-control" id="search-select">
				  <option value="">Supplier Name</option>
				  <?php
					$listNames = $db->query("SELECT * FROM supplier_setup ORDER BY supplier_name ASC");
					while($rowNames = $listNames->fetchArray()){
						$selected = "";
						if (isset($_GET["pay"])) {
						 	$cus_id = preg_replace('/[^0-9]/', "", strtolower($_GET["pay"]));
						 	if ($cus_id == $rowNames['id']) {
						 		$selected = "selected";
						 	}
						}    
				?>
					<option value="s<?php echo $rowNames['id']; ?>" <?php echo $selected; ?>><?php echo $rowNames['supplier_name']; ?></option>
				<?php } ?>
			</select>
			</div>
		</div>

		<div class="form-group">
			<label for="type" class="col-sm-3 col-md-3 col-lg-2 control-label not_required">Payment Type :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
			<select name="type" class="form-control" id="type">
				<!-- <option value="">Select Type</option> -->
				<option value="1">Cash</option>
				<option value="2">Check</option>
			</select>
			</div>
		</div>

		<div class="form-group">
			<label for="Debit/Credit" class="col-sm-3 col-md-3 col-lg-2 control-label not_required">Debit/Credit :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
			<select name="debcre" class="form-control" id="debcre">
				<option value="1">Debit</option>
				<option value="2">Credit</option>
			</select>
			</div>
		</div>

		<div class="form-group">
			<label for="amount" class="col-sm-3 col-md-3 col-lg-2 control-label not_required">Amount :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
			<input type="text" name="amount" value="" class="form-control" id="amount">
			</div>
		</div>
		<div class="form-group">	
			<label for="bank" class="col-sm-3 col-md-3 col-lg-2 control-label ">Bank :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
			<input type="text" name="bank" list="bankNames" class="form-control" id="bank">
			<a href="addbank.php" target="_blank"><input type="button"  value="Add Bank" class=" submit_button btn btn-success"></a>
				<datalist id="bankNames">
				<?php
	                $sn4d  = "SELECT * FROM ";
	                $sn4d .= "bank";
	                $sn4d_run = $db->query($sn4d);
	                while($sn4d_row = $sn4d_run->fetchArray())
	                {
	            ?>
	                <option value="<?php echo $sn4d_row["name"]; ?>">
	            <?php
	                }
	            ?>    
	            </datalist>
			</div>
		</div>
		


	<div class="form-group">	
<label for="description" class="col-sm-3 col-md-3 col-lg-2 control-label ">Description :</label>	<div class="col-sm-9 col-md-9 col-lg-10">
	<input type = "text" name="description" cols="17"  id="description" class="form-control ">
	</div>
</div>
 
	</div><!-- /col-md-12 -->
</div><!-- /row -->				
							
						<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'; ?>