Created
September 12, 2012 16:56
-
-
Save Eclarian/3708093 to your computer and use it in GitHub Desktop.
Pancake Payments: Client Invoice Health Check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The code is from file found in : /third_party/themes/admin/pancake/views/modules/clients/view.php [Line 104] | |
Put this immediately after the "else" at approximately line 104 | |
You will replace the <div class="invoice-block"></div> that currently contains the health check. | |
*/ | |
<?php | |
// Requires PHP 5.2.0 or greater | |
// Setup the payment variables | |
$paid_on_time = 0; | |
$pending_payment = count($invoices['unpaid']); // We don't know whether they'll pay or not. | |
$paid_late = count($invoices['overdue']); | |
$timezone = new DateTimeZone("UTC"); | |
// Determine number of invoices paid on time vs paid late | |
foreach ($invoices['paid'] as $invoice) | |
{ | |
$due_date = new DateTime('@' . $invoice->due_date, $timezone); | |
$payment_date = new DateTime('@' . $invoice->payment_date, $timezone); | |
// Check if payment was received before the due date | |
if ($payment_date < $due_date) | |
{ | |
$paid_on_time++; | |
} | |
else | |
{ | |
$paid_late++; | |
} | |
} | |
// Get Total and Make sure its not zero | |
$total_payments = $pending_payment + $paid_on_time + $paid_late; | |
$total_payments = ($total_payments === 0) ? 1 : $total_payments; | |
// Get the percentages | |
$pending_payment_perc = ($pending_payment / $total_payments) * 100; | |
$paid_on_time_perc = ($paid_on_time / $total_payments) * 100; | |
$paid_late_perc = ($paid_late / $total_payments) * 100; | |
?> | |
<style> | |
/* You can throw this into the custom CSS area on the backend if you want */ | |
.healthBar { | |
font-size: 9px; | |
color: #fff; | |
text-align: center; | |
line-height: 14px; | |
} | |
.healthBar span { | |
overflow:hidden; | |
} | |
.healthBar .pending { | |
background: #DF9D29; | |
} | |
#healthcheck-holder, #payment-healthcheck-holder { | |
float: left; | |
} | |
#payment-healthcheck-holder { | |
margin-left: 20px; | |
color: #555; | |
} | |
</style> | |
<div class="invoice-block"> | |
<!-- Health Check --> | |
<div id="healthcheck-holder"> | |
<?php echo lang('clients:health_check') ?> (<?php echo $client->health['overall'];?>%): | |
<div class="healthCheck"> | |
<span class="healthBar"><span class="paid" style="width:<?php echo $client->health['overall'];?>%"></span></span> | |
</div><!-- /healthCheck --> | |
</div><!-- /healthcheck-holder --> | |
<!-- Late Payment Health Check --> | |
<div id="payment-healthcheck-holder"> | |
<strong>Invoices:</strong> <?php echo $paid_on_time; ?> On Time, <?php echo $pending_payment; ?> Pending, <?php echo $paid_late; ?> Late | |
<div class="healthCheck"> | |
<span class="healthBar"> | |
<span class="paid" style="width:<?php echo $paid_on_time_perc;?>%"><?php echo round($paid_on_time_perc, 2);?>%</span> | |
<span class="pending" style="width:<?php echo $pending_payment_perc;?>%"><?php echo round($pending_payment_perc, 2);?>%</span> | |
<span style="width:<?php echo $paid_late_perc;?>%"><?php echo round($paid_late_perc, 2);?>%</span> | |
</span> | |
</div><!-- /healthCheck --> | |
</div><!-- /healthcheck-holder --> | |
</div><!-- /invoice-block --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment