mirror of https://github.com/itflow-org/itflow
Marked Invoice status overdue if > due_date and not draft or paid, Added some nice statistic graphics for invoices
This commit is contained in:
parent
eecdb18a06
commit
448267cb32
|
|
@ -10,7 +10,6 @@
|
|||
<tr>
|
||||
<th>Number</th>
|
||||
<th class="text-right">Amount</th>
|
||||
<th class="text-right">Balance</th>
|
||||
<th>Date</th>
|
||||
<th>Due</th>
|
||||
<th>Status</th>
|
||||
|
|
@ -27,10 +26,18 @@
|
|||
$invoice_date = $row['invoice_date'];
|
||||
$invoice_due = $row['invoice_due'];
|
||||
$invoice_amount = $row['invoice_amount'];
|
||||
//check to see if overdue
|
||||
|
||||
|
||||
|
||||
$now = time();
|
||||
|
||||
if(($invoice_status == "Sent" or $invoice_status == "Partial") and strtotime($invoice_due) < $now ){
|
||||
$overdue_color = "text-danger font-weight-bold";
|
||||
$overdue_badge = "badge-danger";
|
||||
$invoice_status = "Overdue";
|
||||
}else{
|
||||
$overdue_color = "";
|
||||
$overdue_badge = "";
|
||||
}
|
||||
|
||||
//Set Badge color based off of invoice status
|
||||
if($invoice_status == "Sent"){
|
||||
$invoice_badge_color = "warning";
|
||||
|
|
@ -44,31 +51,15 @@
|
|||
$invoice_badge_color = "secondary";
|
||||
}
|
||||
|
||||
//Add up all the payments for the invoice and get the total amount paid to the invoice
|
||||
|
||||
$sql_amount_paid = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS amount_paid FROM payments WHERE invoice_id = $invoice_id");
|
||||
$row = mysqli_fetch_array($sql_amount_paid);
|
||||
|
||||
$amount_paid = $row['amount_paid'];
|
||||
|
||||
$balance = $invoice_amount - $amount_paid;
|
||||
//set Text color on balance
|
||||
if($balance > 0){
|
||||
$balance_text_color = "text-danger";
|
||||
}else{
|
||||
$balance_text_color = "";
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td><a href="invoice.php?invoice_id=<?php echo $invoice_id; ?>">INV-<?php echo $invoice_number; ?></a></td>
|
||||
<td class="text-right text-monospace">$<?php echo number_format($invoice_amount,2); ?></td>
|
||||
<td class="text-right text-monospace <?php echo $balance_text_color; ?>">$<?php echo number_format($balance,2); ?></td>
|
||||
<td><?php echo $invoice_date; ?></td>
|
||||
<td><div class="<?php echo $overdue_color; ?>"><?php echo $invoice_due; ?></div></td>
|
||||
<td>
|
||||
<span class="p-2 badge badge-<?php echo $invoice_badge_color; ?>">
|
||||
<span class="p-2 badge badge-<?php echo $invoice_badge_color; ?> echo $overdue_badge;">
|
||||
<?php echo $invoice_status; ?>
|
||||
</span>
|
||||
</td>
|
||||
|
|
|
|||
|
|
@ -3,8 +3,11 @@
|
|||
<?php
|
||||
|
||||
if(isset($_GET['orderby'])){
|
||||
$sql_orderby = "ORDER BY " . $_GET['orderby'];
|
||||
$sql_order = "ASC";
|
||||
$orderby = "ORDER BY " . $_GET['orderby'];
|
||||
}
|
||||
|
||||
if(isset($_GET['order'])){
|
||||
$order = $_GET['order'];
|
||||
}
|
||||
|
||||
if(isset($_GET['search'])){
|
||||
|
|
@ -13,7 +16,7 @@ if(isset($_GET['search'])){
|
|||
|
||||
?>
|
||||
|
||||
<?php $sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE client_name LIKE '%$search%' $sql_orderby $sql_order LIMIT 10"); ?>
|
||||
<?php $sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE client_name LIKE '%$search%' $orderby $order LIMIT 10"); ?>
|
||||
|
||||
|
||||
<div class="card">
|
||||
|
|
@ -39,7 +42,7 @@ if(isset($_GET['search'])){
|
|||
<table class="table table-striped table-borderless table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><a href="<?php echo $_SERVER['REQUEST_URI']; ?>?orderby=client_name">Name <i class="fa fa-sort-alpha-down"></i></a></th>
|
||||
<th><a href="<?php $_SERVER['PHP_SELF']; ?>?orderby=client_name&order=asc">Name <i class="fa fa-sort-alpha-down"></i></a></th>
|
||||
<th><a href="?orderby=client_email">Email</a></th>
|
||||
<th><a href="?sortby=client_phone">Phone</a></th>
|
||||
<th class="text-right">Balance</th>
|
||||
|
|
|
|||
96
invoices.php
96
invoices.php
|
|
@ -1,12 +1,87 @@
|
|||
<?php include("header.php"); ?>
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Sent'"));
|
||||
$sent_count = $row['num'];
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Partial'"));
|
||||
$partial_count = $row['num'];
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Draft'"));
|
||||
$draft_count = $row['num'];
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_due > CURDATE()"));
|
||||
$overdue_count = $row['num'];
|
||||
|
||||
$sql_total_sent = mysqli_query($mysqli,"SELECT SUM(invoice_amount) AS total_sent FROM invoices WHERE invoice_status = 'Sent'");
|
||||
$row = mysqli_fetch_array($sql_total_sent);
|
||||
$total_sent = $row['total_sent'];
|
||||
|
||||
$sql_total_partial = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_partial FROM payments, invoices WHERE payments.invoice_id = invoices.invoice_id AND invoices.invoice_status = 'Partial'");
|
||||
$row = mysqli_fetch_array($sql_total_partial);
|
||||
$total_partial = $row['total_partial'];
|
||||
$total_partial_count = mysqli_num_rows($sql_total_partial);
|
||||
|
||||
$sql_total_overdue_partial = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_overdue_partial FROM payments, invoices WHERE payments.invoice_id = invoices.invoice_id AND invoices.invoice_status = 'Partial' AND invoices.invoice_due < CURDATE()");
|
||||
$row = mysqli_fetch_array($sql_total_overdue_partial);
|
||||
$total_overdue_partial = $row['total_overdue_partial'];
|
||||
|
||||
$sql_total_overdue = mysqli_query($mysqli,"SELECT SUM(invoice_amount) AS total_overdue FROM invoices WHERE invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Paid' AND invoice_due < CURDATE()");
|
||||
$row = mysqli_fetch_array($sql_total_overdue);
|
||||
$total_overdue = $row['total_overdue'];
|
||||
|
||||
$real_overdue_amount = $total_overdue - $total_overdue_partial;
|
||||
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients
|
||||
WHERE invoices.client_id = clients.client_id
|
||||
ORDER BY invoices.invoice_number DESC");
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xl-3 col-sm-6 mb-3">
|
||||
<div class="card text-white bg-warning o-hidden">
|
||||
<div class="card-body">
|
||||
<div class="card-body-icon">
|
||||
<i class="fas fa-fw fa-paper-plane"></i>
|
||||
</div>
|
||||
<div class="mr-5"><?php echo $sent_count; ?> Sent <h1>$<?php echo number_format($total_sent,2); ?></h1></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xl-3 col-sm-6 mb-3">
|
||||
<div class="card text-white bg-primary o-hidden">
|
||||
<div class="card-body">
|
||||
<div class="card-body-icon">
|
||||
<i class="fas fa-fw fa-wine-glass-alt"></i>
|
||||
</div>
|
||||
<div class="mr-5"><?php echo $partial_count; ?> Partial <h1>$<?php echo number_format($total_partial,2); ?></h1></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xl-3 col-sm-6 mb-3">
|
||||
<div class="card text-white bg-secondary o-hidden">
|
||||
<div class="card-body">
|
||||
<div class="card-body-icon">
|
||||
<i class="fas fa-fw fa-pencil-ruler"></i>
|
||||
</div>
|
||||
<div class="mr-5"><?php echo $draft_count; ?> Draft <h1>$<?php echo number_format($total_paid,2); ?></h1></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xl-3 col-sm-6 mb-3">
|
||||
<div class="card text-white bg-danger o-hidden">
|
||||
<div class="card-body">
|
||||
<div class="card-body-icon">
|
||||
<i class="fas fa-fw fa-skull-crossbones"></i>
|
||||
</div>
|
||||
<div class="mr-5"><?php echo $overdue_count; ?> Overdue <h1>$<?php echo number_format($real_overdue_amount,2); ?></h1></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h6 class="float-left mt-1"><i class="fa fa-file"></i> Invoices</h6>
|
||||
|
|
@ -39,13 +114,24 @@
|
|||
$client_id = $row['client_id'];
|
||||
$client_name = $row['client_name'];
|
||||
|
||||
$unixtime_invoice_due = strtotime($invoice_due);
|
||||
if($unixtime_invoice_due < time()){
|
||||
$overdue_color = "text-danger";
|
||||
$now = time();
|
||||
|
||||
if(($invoice_status == "Sent" or $invoice_status == "Partial") and strtotime($invoice_due) < $now ){
|
||||
$overdue_color = "text-danger font-weight-bold";
|
||||
$overdue_badge = "badge-danger";
|
||||
$invoice_status = "Overdue";
|
||||
}else{
|
||||
$overdue_color = "";
|
||||
$overdue_badge = "";
|
||||
}
|
||||
|
||||
//$unixtime_invoice_due = strtotime($invoice_due);
|
||||
//if($unixtime_invoice_due < time()){
|
||||
// $overdue_color = "text-danger";
|
||||
//}else{
|
||||
// $overdue_color = "";
|
||||
//}
|
||||
|
||||
if($invoice_status == "Sent"){
|
||||
$invoice_badge_color = "warning";
|
||||
}elseif($invoice_status == "Partial"){
|
||||
|
|
@ -67,7 +153,7 @@
|
|||
<td><?php echo $invoice_date; ?></td>
|
||||
<td class="<?php echo $overdue_color; ?>"><?php echo $invoice_due; ?></td>
|
||||
<td>
|
||||
<span class="p-2 badge badge-<?php echo $invoice_badge_color; ?>">
|
||||
<span class="p-2 badge badge-<?php echo $invoice_badge_color; ?> <?php echo $overdue_badge; ?>">
|
||||
<?php echo $invoice_status; ?>
|
||||
</span>
|
||||
</td>
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue