<?php 
include 'dheader.php'; 
if (isset($_GET["delete"])) {
 	$remove = preg_replace('/[^0-9]/', "", strtolower($_GET["delete"]));
 	$delete = $db->query("DELETE FROM supplier_setup WHERE id = '$remove'");
 	$delete = $db->query("DELETE FROM customerinvoice WHERE name = '".$_GET["delete"]."'");
 	$delete = $db->query("DELETE FROM payments2 WHERE cs_id = '".$_GET["delete"]."'");
	}  

?>
	<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="manage_buttons">
	<div class="row">
		<div class="col-md-5">
			<form action="suppliers.php" id="search_form" autocomplete="off" method="get" accept-charset="utf-8">
				<div class="search no-left-border">
					<input type="text" class="form-control" name ='search' list="listSuppliers" id='search' value="" placeholder="Search Supplier" autocomplete="off" />
					<datalist id="listSuppliers">
						<?php
							$listItems = $db->query("SELECT * FROM supplier_setup");
							while($listrow = $listItems->fetchArray()){
						?>
							<option value="<?php echo $listrow['supplier_name']; ?>"><?php echo $listrow['supplier_name']; ?></option>
						<?php } ?>
					</datalist>
				</div>
					
			</form>	
			
		</div>
		<div class="col-md-7">	
			<div class="buttons-list">
				<div class="pull-right-btn">
					<a href="supplierledger.php" id="ledger-person-btn" class="btn btn-warning btn-lg" title="Show Ledger" <?php echo (@$_SESSION['suppliershowledger'] == '') ? 'style="display:none;"': ''; ?>><span class="">Show Ledger</span></a>

					<a href="paysuppliers.php" id="pay-person-btn" class="btn btn-success btn-lg" title="Add Payments" <?php echo (@$_SESSION['suppliermakepayment'] == '') ? 'style="display:none;"': ''; ?>><span class="">Add Payments</span></a>

					<a href="newsupplier.php" id="new-person-btn" class="btn btn-primary btn-lg" title="New Supplier" <?php echo (@$_SESSION['supplieradd'] == '') ? 'style="display:none;"': ''; ?>><span class="">New Supplier</span></a>					<div class="piluku-dropdown">
			
					</div>
				</div>
			</div>				
		</div>
	</div>
</div>

	<div class="container-fluid">
		<div class="row manage-table">
			<div class="panel panel-piluku">
				<div class="panel-heading">
				<h3 class="panel-title">
				<?php
					$countItems = $db->query("SELECT count(*) AS totalItems FROM supplier_setup");
					$count = $countItems->fetchArray();
				?>
					List of Suppliers					<span title="<?php echo $count['totalItems']; ?> total Suppliers" class="badge bg-primary tip-left"><?php echo $count['totalItems']; ?></span>
					<span class="panel-options custom">
											</span>
				</h3>
			</div>
				<div class="panel-body nopadding table_holder table-responsive" >
					<table class="tablesorter table  table-hover" id="sortable_table">
						<thead>
							<tr>
								<th>Person ID</th>
								<th>Name</th>
								<th>E-Mail</th>
								<th>Phone Number</th>
								<?php /* <th>Balance</th> */ ?>
								<th>Pay</th>
								<th>Ledger</th>
								<th>Action</th>
							</tr>
						</thead>
						<tbody>
						<?php
							if(!isset($_GET['search'])){
                        		$customer  = "SELECT * FROM supplier_setup ";
							}else{
								$customer  = "SELECT * FROM supplier_setup WHERE supplier_name = '".$_GET['search']."'";
							}
							$customer = $db->query($customer);
							while($row = $customer->fetchArray()){
						?>
							<tr>
								<td><?php echo $row['id']; ?></td>
								<td ><a href="viewsupplier.php?view=<?php echo $row['id']; ?>" class="underline"><?php echo $row['supplier_name']; ?> </a></td>
								<td><a href="mailto:<?php echo $row['email']; ?>" class="underline"><?php echo $row['email']; ?></a></td>
								<td><?php echo $row['phone']; ?></td>
								<?php /* <td><?php echo $row['current_balance']; ?></td> */ ?>
								<td><a href="paysuppliers.php?pay=s<?php echo $row['id']; ?>" title="Pay" class="btn btn-primary ">Pay</a></td>
								<td><a href="supplierledger.php?name=s<?php echo $row['id']; ?>" title="Account Ledger" class="btn btn-success ">Ledger</a></td>
								<td><a href="editsupplier.php?edit=s<?php echo $row['id']; ?>" class="  update-person" title="Update" <?php echo (@$_SESSION['supplieredit'] == '') ? 'style="display:none;"': ''; ?>>Edit</a> | <a href="suppliers.php?delete=s<?php echo $row['id']; ?>" class="  delete-person" title="Delete" style="color: red;" onclick="return confirm('Are you sure you want to delete this Supplier?');" <?php echo (@$_SESSION['supplierdelete'] == '') ? 'style="display:none;"': ''; ?>>Delete</a></td>
							</tr>
						<?php } ?>		
							</tbody>
						</table>			
				</div>	
		</div>	
				</div>
	</div>
</div>

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