switched clients listing over to the new serverside paging, sorting, searching, updated the table ui as well, started adding red * to required fields

This commit is contained in:
root 2019-06-14 23:20:51 -04:00
parent 0eda7e9762
commit 4c81efbdc2
9 changed files with 242 additions and 21 deletions

View File

@ -32,7 +32,7 @@
<div class="tab-pane fade show active" id="pills-basic" role="tabpanel" aria-labelledby="pills-basic-tab">
<div class="form-group">
<label>Name</label>
<label>Name <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
@ -42,7 +42,7 @@
</div>
<div class="form-group">
<label>Type</label>
<label>Type <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-list"></i></span>

View File

@ -2,8 +2,8 @@
<div class="card mb-3">
<div class="card-header">
<h5 class="float-left mt-2"><i class="fa fa-fw fa-tags mr-2"></i>Tickets</h5>
<button type="button" class="btn btn-primary badge-pill float-right" data-toggle="modal" data-target="#addTicketModal"><i class="fas fa-fw fa-plus"></i></button>
<h6 class="float-left mt-2"><i class="fa fa-fw fa-tags mr-2"></i>Tickets</h6>
<button type="button" class="btn btn-primary btn-sm float-right" data-toggle="modal" data-target="#addTicketModal"><i class="fas fa-fw fa-plus"></i></button>
</div>
<div class="card-body">
<div class="table-responsive">

View File

@ -1,24 +1,83 @@
<?php include("header.php"); ?>
<?php $sql = mysqli_query($mysqli,"SELECT * FROM clients ORDER BY client_name ASC"); ?>
<?php
//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET,array('sb' => $sb, 'o' => $o)));
if(isset($_GET['p'])){
$p = intval($_GET['p']);
$record_from = (($p)-1)*10;
$record_to = 10;
}else{
$record_from = 0;
$record_to = 10;
$p = 1;
}
if(isset($_GET['q'])){
$q = $_GET['q'];
}else{
$q = "";
}
if(!empty($_GET['sb'])){
$sb = $_GET['sb'];
}else{
$sb = "client_name";
}
if(isset($_GET['o'])){
if($_GET['o'] == 'ASC'){
$o = "ASC";
$disp = "DESC";
}else{
$o = "DESC";
$disp = "ASC";
}
}else{
$o = "ASC";
$disp = "DESC";
}
?>
<?php
$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM clients WHERE client_name LIKE '%$q%' OR client_email LIKE '%$q%' ORDER BY $sb $o LIMIT $record_from, $record_to");
$num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
$total_found_rows = $num_rows[0];
$total_pages = ceil($total_found_rows / 10);
?>
<div class="card mb-3">
<div class="card-header">
<h5 class="float-left mt-2"><i class="fa fa-users mr-2"></i>Clients</h5>
<button type="button" class="btn btn-primary badge-pill mr-auto float-right" data-toggle="modal" data-target="#addClientModal"><i class="fas fa-fw fa-user-plus"></i></button>
<div class="card-header bg-dark text-white">
<h6 class="float-left mt-2"><i class="fa fa-users mr-2"></i>Clients</h6>
<button type="button" class="btn btn-primary btn-sm float-right" data-toggle="modal" data-target="#addClientModal"><i class="fas fa-fw fa-user-plus"></i> New</button>
</div>
<div class="card-body">
<form autocomplete="off">
<div class="input-group">
<input type="search" class="form-control col-md-4" name="q" value="<?php if(isset($q)){echo $q;} ?>" placeholder="Search Clients">
<div class="input-group-append">
<button class="btn btn-primary"><i class="fa fa-search"></i></button>
</div>
</div>
</form>
<hr>
<div class="table-responsive">
<table class="table table-striped table-borderless table-hover" id="dataTable" width="100%" cellspacing="0">
<thead class="thead-dark">
<table class="table table-striped table-borderless table-hover">
<thead class="text-dark">
<tr>
<th>Name</th>
<th>Type</th>
<th><a class="text-secondary" href="?<?php echo $url_query_strings_sb; ?>&sb=client_name&o=<?php echo $disp; ?>">Name <i class="fa fa-sort<?php if($disp=='ASC'){ echo "-up"; }else{ echo "-down"; }?>"></i></a></th>
<th><a href="?<?php echo $url_query_strings_sb; ?>&sb=client_type&o=<?php echo $disp; ?>">Type <i class="fa fa-sort-up"></i></a></th>
<th>Email</th>
<th>Phone</th>
<th class="text-right">Balance</th>
<th class="text-center">Actions</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
@ -91,6 +150,9 @@
</tbody>
</table>
<?php include("pagination.php"); ?>
</div>
</div>
</div>

100
clients_old.php Normal file
View File

@ -0,0 +1,100 @@
<?php include("header.php"); ?>
<?php $sql = mysqli_query($mysqli,"SELECT * FROM clients ORDER BY client_name ASC"); ?>
<div class="card mb-3">
<div class="card-header">
<h6 class="float-left mt-2"><i class="fa fa-users mr-2"></i>Clients</h6>
<button type="button" class="btn btn-primary btn-sm float-right" data-toggle="modal" data-target="#addClientModal"><i class="fas fa-fw fa-user-plus"></i></button>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped table-borderless table-hover" id="dataTable" width="100%" cellspacing="0">
<thead class="thead-dark">
<tr>
<th>Name</th>
<th>Type</th>
<th>Email</th>
<th>Phone</th>
<th class="text-right">Balance</th>
<th class="text-center">Actions</th>
</tr>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_array($sql)){
$client_id = $row['client_id'];
$client_name = $row['client_name'];
$client_type = $row['client_type'];
$client_address = $row['client_address'];
$client_city = $row['client_city'];
$client_state = $row['client_state'];
$client_zip = $row['client_zip'];
$client_phone = $row['client_phone'];
if(strlen($client_phone)>2){
$client_phone = substr($row['client_phone'],0,3)."-".substr($row['client_phone'],3,3)."-".substr($row['client_phone'],6,4);
}
$client_email = $row['client_email'];
$client_website = $row['client_website'];
$client_net_terms = $row['client_net_terms'];
if($client_net_terms == 0){
$client_net_terms = $config_default_net_terms;
}
//Add up all the payments for the invoice and get the total amount paid to the invoice
$sql_invoice_amounts = mysqli_query($mysqli,"SELECT SUM(invoice_amount) AS invoice_amounts FROM invoices WHERE client_id = $client_id AND invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Cancelled' ");
$row = mysqli_fetch_array($sql_invoice_amounts);
$invoice_amounts = $row['invoice_amounts'];
$sql_amount_paid = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS amount_paid FROM payments, invoices WHERE payments.invoice_id = invoices.invoice_id AND invoices.client_id = $client_id");
$row = mysqli_fetch_array($sql_amount_paid);
$amount_paid = $row['amount_paid'];
$balance = $invoice_amounts - $amount_paid;
//set Text color on balance
if($balance > 0){
$balance_text_color = "text-danger font-weight-bold";
}else{
$balance_text_color = "";
}
?>
<tr>
<td><a href="client.php?client_id=<?php echo $client_id; ?>"><?php echo $client_name; ?></a></td>
<td><?php echo $client_type; ?></td>
<td><a href="mailto:<?php echo $client_email; ?>"><?php echo $client_email; ?></a></td>
<td><?php echo $client_phone; ?></td>
<td class="text-right text-monospace <?php echo $balance_text_color; ?>">$<?php echo number_format($balance,2); ?></td>
<td>
<div class="dropdown dropleft text-center">
<button class="btn btn-secondary btn-sm" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-ellipsis-h"></i>
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editClientModal<?php echo $client_id; ?>">Edit</a>
<a class="dropdown-item" href="post.php?delete_client=<?php echo $client_id; ?>">Delete</a>
</div>
</div>
<?php include("edit_client_modal.php"); ?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
<?php include("add_client_modal.php"); ?>
<?php include("footer.php");

View File

@ -99,8 +99,8 @@
<div class="card mb-3">
<div class="card-header">
<h5 class="float-left mt-2"><i class="fa fa-fw fa-file mr-2"></i>Invoices</h5>
<button type="button" class="btn btn-primary badge-pill float-right" data-toggle="modal" data-target="#addInvoiceModal"><i class="fas fa-fw fa-plus"></i></button>
<h6 class="float-left mt-2"><i class="fa fa-fw fa-file mr-2"></i>Invoices</h6>
<button type="button" class="btn btn-primary btn-sm float-right" data-toggle="modal" data-target="#addInvoiceModal"><i class="fas fa-fw fa-plus"></i></button>
</div>
<div class="card-body">
<div class="table-responsive">

59
pagination.php Normal file
View File

@ -0,0 +1,59 @@
<ul class="pagination justify-content-end">
<?php
if($total_pages <= 100){
$pages_split = 10;
}
if(($total_pages <= 1000) AND ($total_pages > 100)){
$pages_split = 100;
}
if(($total_pages <= 10000) AND ($total_pages > 1000)){
$pages_split = 1000;
}
if($p > 1){
$prev_class = "";
}else{
$prev_class = "disabled";
}
if($p <> $total_pages) {
$next_class = "";
}else{
$next_class = "disabled";
}
$url_query_strings = http_build_query(array_merge($_GET,array('p' => $i)));
$prev_page = $p - 1;
$next_page = $p + 1;
if($p > 1){
echo "<li class='page-item $prev_class'><a class='page-link' href='?$url_query_strings&p=$prev_page'>Prev</a></li>";
}
while($i < $total_pages){
$i++;
if(($i == 1) OR (($p <= 3) AND ($i <= 6)) OR (($i > $total_pages - 6) AND ($p > $total_pages - 3 )) OR (is_int($i / $pages_split)) OR (($p > 3) AND ($i >= $p - 2) AND ($i <= $p + 3)) OR ($i == $total_pages)){
if($p == $i ) {
$page_class = "active";
}else{
$page_class = "";
}
echo "<li class='page-item $page_class'><a class='page-link' href='?$url_query_strings&p=$i'>$i</a></li>";
}
}
if($p <> $total_pages){
echo "<li class='page_item $next_class'><a class='page-link' href='?$url_query_strings&p=$next_page'>Next</a></li>";
}
?>
</ul>
<?php
echo "<div class='justify-content-start'><br><b>$record_from to $record_to Records:</b> $total_found_rows</div>";
?>

View File

@ -5,8 +5,8 @@
<div class="card mb-3">
<div class="card-header">
<h5 class="float-left mt-2"><i class="fa fa-fw fa-box mr-2"></i>Products</h5>
<button type="button" class="btn btn-primary badge-pill mr-auto float-right" data-toggle="modal" data-target="#addProductModal"><i class="fas fa-fw fa-plus"></i></button>
<h6 class="float-left mt-2"><i class="fa fa-fw fa-box mr-2"></i>Products</h6>
<button type="button" class="btn btn-primary btn-sm float-right" data-toggle="modal" data-target="#addProductModal"><i class="fas fa-fw fa-plus"></i></button>
</div>
<div class="card-body">
<div class="table-responsive">

View File

@ -9,8 +9,8 @@
<div class="card mb-3">
<div class="card-header">
<h5 class="float-left mt-2"><i class="fa fa-fw fa-tags mr-2"></i>Tickets</h5>
<button type="button" class="btn btn-primary badge-pill float-right" data-toggle="modal" data-target="#addTicketModal"><i class="fas fa-fw fa-plus"></i></button>
<h6 class="float-left mt-2"><i class="fa fa-fw fa-tags mr-2"></i>Tickets</h6>
<button type="button" class="btn btn-primary btn-sm float-right" data-toggle="modal" data-target="#addTicketModal"><i class="fas fa-fw fa-plus"></i></button>
</div>
<div class="card-body">
<div class="table-responsive">

View File

@ -5,8 +5,8 @@
<div class="card mb-3">
<div class="card-header">
<h5 class="float-left mt-2"><i class="fa fa-fw fa-building mr-2"></i>Vendors</h5>
<button type="button" class="btn btn-primary badge-pill float-right" data-toggle="modal" data-target="#addVendorModal"><i class="fas fa-fw fa-plus"></i></button>
<h6 class="float-left mt-2"><i class="fa fa-fw fa-building mr-2"></i>Vendors</h6>
<button type="button" class="btn btn-primary btn-sm float-right" data-toggle="modal" data-target="#addVendorModal"><i class="fas fa-fw fa-plus"></i></button>
</div>
<div class="card-body">
<div class="table-responsive">