Reports almost finished

This commit is contained in:
Karl Cordes 2011-05-12 16:39:39 +10:00
parent dd0f4adb59
commit d3ccea11c6
5 changed files with 332 additions and 196 deletions

View file

@ -108,6 +108,11 @@ class JobsController extends AppController {
$monthList = $this->getYearMonths($jobs); $monthList = $this->getYearMonths($jobs);
$this->set('monthList', $monthList); $this->set('monthList', $monthList);
$Fyears = $this->getFinancialYears($jobs);
$this->set('Fyears',$Fyears);
/* $this->set('jobs', $jobs); /* $this->set('jobs', $jobs);
$this->set('customers', $this->Job->Enquiry->Customer->find('list')); $this->set('customers', $this->Job->Enquiry->Customer->find('list'));
$this->set('currencies', $this->Job->Currency->find('list'));*/ $this->set('currencies', $this->Job->Currency->find('list'));*/
@ -116,11 +121,9 @@ class JobsController extends AppController {
function viewReport($year, $month) { function viewReport($year, $month = null) {
$this->layout = 'ajax'; //$this->layout = 'ajax';
$this->set('year', $year);
$this->set('month', $month);
if(isset($month) && isset($year)) { //After a Specific Month for a Year if(isset($month) && isset($year)) { //After a Specific Month for a Year
@ -140,6 +143,11 @@ class JobsController extends AppController {
$jobs = $this->Job->find('all', array('conditions'=> $jobs = $this->Job->find('all', array('conditions'=>
array('Job.date_order_received BETWEEN ? AND ?'=>array($startDate, $endDate)))); array('Job.date_order_received BETWEEN ? AND ?'=>array($startDate, $endDate))));
$this->set('year', $year);
$this->set('month', $month);
$this->set('jobs', $jobs); $this->set('jobs', $jobs);
$this->set('principleList',$this->Job->Enquiry->Principle->find('list')); $this->set('principleList',$this->Job->Enquiry->Principle->find('list'));
@ -150,8 +158,48 @@ class JobsController extends AppController {
} }
elseif(isset($year) && !isset($month)) { //After a whole Years Stats. elseif(isset($year) && !isset($month)) { //Requested a whole Financial Year Jobs
$this->set('year', $year);
$lastDayUnix = $this->getLastDayFY($year);
$firstDayUnix = $this->getFirstDayFY($year,true);
$lastDayDate = date('Y-m-d', $lastDayUnix);
$firstDayDate = date('Y-m-d', $firstDayUnix);
$dateStringFormat = 'j F Y';
$dateString['first'] = date($dateStringFormat, $firstDayUnix);
$dateString['last'] = date($dateStringFormat, $lastDayUnix);
$jobs = $this->Job->find('all', array('conditions'=>
array('Job.date_order_received BETWEEN ? AND ?'=>array($firstDayDate, $lastDayDate))
)
);
$this->set('jobs',$jobs);
$lastYear = $year - 1;
$jobRangeTitle = $lastYear.' - '.$year.' ('.$dateString['first']." to ".$dateString['last'].')';
$this->set('jobRangeTitle', $jobRangeTitle);
$this->set('principleList',$this->Job->Enquiry->Principle->find('list'));
$this->set('sale_category_options', $this->sale_category_options());
$this->set('sale_category_array', $this->sale_category_array());
$this->set('job_type_options', $this->job_type_options());
$this->set('shipment_category_options', $this->shipment_category_options());
$this->set('freight_paid_by_options',$this->freight_paid_options());
$this->set('gst_options', $this->gst_options());
$this->set('totals', $this->getTotals($jobs));
//print_r($jobs);
} }
else { else {
@ -176,19 +224,113 @@ class JobsController extends AppController {
* *
* @param <type> $jobs * @param <type> $jobs
*/ */
function getTotals($jobs, $fields) { function getTotals($jobs) {
$fields = array(
'company_gross_sales_aud' => 'total',
'net_sales_aud' =>'total',
'gross_profit_aud' => 'total',
'net_export_sales_aud' => 'total',
'gross_profit_exports_aud' => 'total',
'gp_percent' => 'average',
'gross_australian_sales_foreign_currency' => 'total',
'net_australian_sales_foreign_currency' => 'total',
'gross_profit_value_australian_sales_foreign_currency' => 'total',
'gross_export_sales_foreign_currency' => 'total',
'net_export_sales_foreign_currency' => 'total',
'gross_profit_value_after_discount_exports_foreign_currency' => 'total',
'gross_commissions' => 'total',
'net_commissions' => 'total'
);
$totals = array();
foreach($fields as $field => $action) {
$totals[$field] = 0;
}
$jobCount = 0;
foreach($jobs as $job) {
if($job['Job']['job_status'] == 'JOB CANCELLED' ||
$job['Job']['job_status'] == 'JOB ON HOLD' ) {
continue; //Don't total cancelled or on hold jobs.
}
else { //Total all other jobs.
foreach(array_keys($job['Job']) as $key) {
if(isset($fields[$key])) {
$totals[$key] += $job['Job'][$key];
}
}
$jobCount++;
}
}
foreach($totals as $key => $value) {
if($fields[$key] == 'average') {
$avg = $value / $jobCount;
$totals[$key] = $avg;
}
}
return $totals;
} }
function getFinancialYears() { function getFinancialYears($jobs) {
$Fyears = array();
foreach($jobs as $job) {
$time = strtotime($job['Job']['date_order_received']);
$year = date('Y', $time); //ISO-8601 year number
$startFYunix = $this->getFirstDayFY($year); //1 July of $year.
$month = date('n', $time);
if($time < $startFYunix) { //Date is before 1 July $year.
$lastYear = $year - 1;
if(!isset($Fyears[$year])) {
$Fyears[$year] = 1;
}
else {
$Fyears[$year]++;
}
}
else { //Date is After 1 July $year.
$nextYear = $year + 1;
if(!isset($Fyears[$nextYear])) {
$Fyears[$nextYear] = 1;
}
else {
$Fyears[$nextYear]++;
}
}
}
krsort($Fyears); //Sort the array in reverse order, most recent to oldest.
return $Fyears;
} }
function getFirstDayFY($year,$prevYear = false) {
if($prevYear == false) {
return mktime(0,0,0,7,1,$year);
}
else {
return mktime(0,0,0,7,1,$year-1);
}
}
function getFirstFYday($year) { function getLastDayFY($year) {
return mktime(23,59,59,6,30,$year);
} }
@ -422,7 +564,7 @@ class JobsController extends AppController {
} }
function autocomplete() { function autocomplete() {
$this->layout = 'ajax'; $this->layout = 'ajax';
$query = strtolower($_GET["term"]); $query = strtolower($_GET["term"]);

View file

@ -3,27 +3,29 @@
<h2>Book 1 - Reports</h2> <h2>Book 1 - Reports</h2>
<div id="yearMonths"> <div id="years">
<? <ul class="years">
foreach($monthList as $year => $monthArr): <? foreach($Fyears as $year => $count):
?> $lastYear = $year - 1;
<ul class="yearList"> ?>
<li><span class="year"><?=$year?></span>
<ul class="monthList" id="<?=$year?>"> <?if($year != 1970):?>
<?foreach($monthArr as $month => $count):?> <li id="<?=$year?>" class="year"><?=$lastYear?> - <?=$year?> <span class="count">(<?=$count?>)</span></li>
<li><span class="month"><?=$month;?></span> (<?=$count?>)</li> <?else:?>
<?endforeach;?> <li id="<?=$year?>" class="year">No Date <span class="count">(<?=$count?>)</span></li>
</ul> <?endif;?>
</li>
<?endforeach;?>
</ul>
<ul months="months">
</ul> </ul>
<?endforeach;?>
</div> </div>
<div class="scrollHorizontal">
<div id="reports"> <div id="reports">
</div>
</div> </div>

View file

@ -1,120 +1,102 @@
<h3><?=$year?></h3> <h3><?=$jobRangeTitle?></h3>
<? if(isset($month)):?> <a href="#totals">Skip to Totals</a>
<h4><?=$month?></h4> <table cellpadding="0" cellspacing="0" class="jobsTable">
<?endif;?>
<table class="jobsTable">
<thead> <thead>
<tr> <tr>
<th>Order Received</th> <th>Order Received</th>
<th>All Paid</th>
<th>All Sent</th>
<th>Status</th>
<th class="sale_category">Sale Category</th>
<th>Job Type</th>
<th>Shipment Category</th>
<th>Job Number</th> <th>Job Number</th>
<th>Enquiry Number</th> <th>Enquiry Number</th>
<th>Principle</th> <th>Principle</th>
<th>CMC POs</th>
<th>Customer</th> <th>Customer</th>
<th>Status</th>
<th>Sale Currency</th> <th>Sale Currency</th>
<th>Gross Sales AUD</th> <th class="purple">Gross Sales AUD</th>
<th>Net Sales AUD</th> <th class="purple">Net Sales AUD</th>
<th>Gross Profit AUD</th> <th class="purple">Gross Profit AUD</th>
<th>Net Export Sales Converted to Or Invoiced in AUD</th> <th class="purple">Net Export Sales Converted to Or Invoiced in AUD</th>
<th>Gross Profit Value Export in AUD</th> <th class="purple">Gross Profit Value Export in AUD</th>
<th>GP% Excl Commissions</th> <th class="purple">GP% Excl Commissions</th>
<th>ATO Exchange Rate</th> <th class="pink">ATO Exchange Rate</th>
<th class="lightblue">Gross Australian Sales Foreign Currency</th>
<th>Gross Australian Sales Foreign Currency</th> <th class="lightblue">Net Australian Sales Foreign Currency</th>
<th>Net Australian Sales Foreign Currency</th> <th class="lightblue">Gross Profit value Australian Sales Foreign Currency</th>
<th>Gross Profit value Australian Sales Foreign Currency</th> <th class="lightgreen">Gross Export Sales Foreign Currency</th>
<th>Gross Export Sales Foreign Currency</th> <th class="lightgreen">Net Export Sales Foreign Currency</th>
<th>Net Export Sales Foreign Currency</th> <th class="lightgreen">Gross Profit Value After Discount Exports Foreign Currency</th>
<th>Gross Profit Value After Discount Exports Foreign Currency</th> <th class="darkgreen">Gross Commissions</th>
<th>Gross Commissions</th> <th class="darkgreen">Net Commisions</th>
<th>Net Commisions</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?
$gross_sales_aud_total = 0;
$net_sales_aud_total = 0;
$gross_profit_total = 0;
$count = 0;
$gross_profit_exports_aud_total = 0;
$gross_australian_sales_foreign_currency_total = 0;
$net_australian_sales_foreign_currency_total = 0;
$gross_profit_value_australian_sales_foreign_currency_total = 0;
$gross_export_sales_foreign_currency_total =0;
$net_export_sales_foreign_currency_total = 0;
$gross_profit_value_after_discount_exports_foreign_currency_total =0;
$gross_commissions_total =0;
$net_commissions_total = 0;
?>
<?foreach($jobs as $job):?> <?foreach($jobs as $job):?>
<? if($job['Job']['job_status'] == 'JOB CANCELLED' || $job['Job']['job_status'] == 'JOB ON HOLD' ) { <? if($job['Job']['job_status'] == 'JOB CANCELLED' || $job['Job']['job_status'] == 'JOB ON HOLD' ) {
$class='cancelled'; $class='cancelled';
$doCount = false;
} }
else { else {
$class =''; $class ='';
$doCount = true;
} }
?> ?>
<tr class="<?=$class?>"> <tr class="<?=$class?>">
<td><?=$job['Job']['date_order_received'];?></td> <td><?=$this->element('isEmptyDate', array('date'=>$job['Job']['date_order_received']));?></td>
<td class="nowrap"><?=$html->link($job['Job']['title'], array('controller'=>'jobs', 'action'=>'view', $job['Job']['id']));?>
<td>
<?=$this->element('booleanTick', array('bool'=>$job['Job']['all_paid'])); ?>
</td>
<td>
<?=$this->element('booleanTick', array('bool'=>$job['Job']['all_sent'])); ?>
</td> </td>
<td class="nowrap"><?=$html->link($job['Enquiry']['title'], array('controller'=>'enquiries','action'=>'view', $job['Enquiry']['id']));?>
</td>
<td><?=$html->link($principleList[$job['Enquiry']['principle_id']], '/principles/view/'.$job['Enquiry']['principle_id']);?></td>
<td><?=$html->link($job['Customer']['name'], array('controller'=>'customers','action'=>'view', $job['Customer']['id']));?></td>
<td><?=$job['Job']['job_status'];?></td> <td><?=$job['Job']['job_status'];?></td>
<td>
<?=$sale_category_array[$job['Job']['sale_category']];?>
</td>
<td>
<?=$job['Job']['job_type'];?></td>
<td><?=$shipment_category_options[$job['Job']['shipment_category']];?></td>
<td class="nowrap"><?=$html->link($job['Job']['title'], array('controller'=>'jobs', 'action'=>'view', $job['Job']['id']));?></td>
<td class="nowrap"><?=$html->link($job['Enquiry']['title'], array('controller'=>'enquiries','action'=>'view', $job['Enquiry']['id']));?></td>
<td><?=$html->link($principleList[$job['Enquiry']['principle_id']], '/principles/view/'.$job['Enquiry']['principle_id']);?></td>
<td><?
$poString = '';
foreach($job['PurchaseOrder'] as $po) {
$poString .= ' '.$html->link($po['title'], array('controller'=>'purchase_orders', 'action'=>'view', $po['id']));
}
echo $poString;
?>
</td>
<td><?=$html->link($job['Customer']['name'], array('controller'=>'customers','action'=>'view', $job['Customer']['id']));?></td>
<td> <td>
<?=$job['Currency']['name'];?> <?=$job['Currency']['name'];?>
</td> </td>
<td> <td>
<?=$number->currency($job['Job']['company_gross_sales_aud']);?> <?=$job['Job']['company_gross_sales_aud'];?>
<?
if($doCount) {
$gross_sales_aud_total += $job['Job']['company_gross_sales_aud'];
}
?>
</td> </td>
<td> <td>
<?=$number->currency($job['Job']['net_sales_aud']);?> <?=$job['Job']['net_sales_aud'];?>
<? </td>
if($doCount) { <td> <?=$job['Job']['gross_profit_aud'];?>
$net_sales_aud_total += $job['Job']['net_sales_aud'];
} ?>
</td> </td>
<td> <td>
<?=$number->currency($job['Job']['gross_profit_aud']);?> <?=$job['Job']['net_export_sales_aud'];?>
<?
if($doCount) {
$gross_profit_total += $job['Job']['gross_profit_aud'];
}
?>
</td> </td>
<td> <td>
<?=$number->currency($job['Job']['gross_profit_exports_aud']);?> <?=$job['Job']['gross_profit_exports_aud'];?>
</td> </td>
<td> <td>
<?=$job['Job']['gp_percent'];?> <?=$job['Job']['gp_percent'];?>
@ -123,99 +105,94 @@
<td> <td>
<?=$job['Job']['ato_exchange_rate'];?> <?=$job['Job']['ato_exchange_rate'];?>
</td> </td>
<td> <?=$number->currency($job['Job']['gross_australian_sales_foreign_currency'], $job['Currency']['iso4217']);?> <td> <?=$job['Job']['gross_australian_sales_foreign_currency'];?>
<?
if($doCount) {
$gross_australian_sales_foreign_currency_total += $job['Job']['gross_australian_sales_foreign_currency']; }
?>
</td> </td>
<td> <td>
<?=$number->currency($job['Job']['net_australian_sales_foreign_currency'], $job['Currency']['iso4217']); <?=$job['Job']['net_australian_sales_foreign_currency'];?>
if($doCount) {
$net_australian_sales_foreign_currency_total += $job['Job']['net_australian_sales_foreign_currency'];
}
?>
</td> </td>
<td> <?=$number->currency($job['Job']['gross_profit_value_australian_sales_foreign_currency'], $job['Currency']['iso4217']); <td> <?=$job['Job']['gross_profit_value_australian_sales_foreign_currency'];?>
if($doCount) {
$gross_profit_value_australian_sales_foreign_currency_total += $job['Job']['gross_profit_value_australian_sales_foreign_currency'];
}
?>
</td> </td>
<td> <td>
<?=$number->currency($job['Job']['gross_export_sales_foreign_currency'],$job['Currency']['iso4217']); <?=$job['Job']['gross_export_sales_foreign_currency'];?>
if($doCount) {
$gross_export_sales_foreign_currency_total += $job['Job']['gross_export_sales_foreign_currency'];
}
?>
</td> </td>
<td> <?=$number->currency($job['Job']['net_export_sales_foreign_currency'],$job['Currency']['iso4217']); <td> <?=$job['Job']['net_export_sales_foreign_currency'];?>
if($doCount) {
$net_export_sales_foreign_currency_total += $job['Job']['net_export_sales_foreign_currency'];
}
?>
</td> </td>
<td> <?=$number->currency($job['Job']['gross_profit_value_after_discount_exports_foreign_currency'],$job['Currency']['iso4217']); <td> <?=$job['Job']['gross_profit_value_after_discount_exports_foreign_currency'];?>
if($doCount) {
$gross_profit_value_after_discount_exports_foreign_currency_total += $job['Job']['gross_profit_value_after_discount_exports_foreign_currency'];
}
?>
</td> </td>
<td> <td>
<?=$number->currency($job['Job']['gross_commissions']); <?=$job['Job']['gross_commissions'];?>
if($doCount) {
$gross_commissions_total += $job['Job']['gross_commissions'];
}
?>
</td> </td>
<td> <?=$number->currency($job['Job']['net_commissions']); <td> <?=$job['Job']['net_commissions'];?>
if($doCount) {
$net_commissions_total += $job['Job']['net_commissions'];
}
?>
</td> </td>
</tr> </tr>
<? <?
$count++;
endforeach;?> endforeach;?>
</tbody> </tbody>
<tfoot> <tfoot>
<tr> <tr>
<td><? //Date ?></td> <th>Order Received</th>
<td><? //Job No ?></td> <th>All Paid</th>
<td><? //Enq No ?></td> <th>All Sent</th>
<td><? //Principle ?></td> <th>Status</th>
<td><? //Customer ?></td> <th class="sale_category">Sale Category</th>
<td><?//Status ?></td> <th>Job Type</th>
<td><? //Sale Currency?></td> <th>Shipment Category</th>
<td><?=$number->currency($gross_sales_aud_total)?></td> <th>Job Number</th>
<td><?=$number->currency($net_sales_aud_total)?></td> <th>Enquiry Number</th>
<td><?=$number->currency($gross_profit_total)?></td> <th>Principle</th>
<td><? //Net Sales Conv to AUD?></td> <th>CMC POs</th>
<td><? //GP % Excl Comm?> </td> <th>Customer</th>
<td><? //ATO EXH RATE?></td> <th>Sale Currency</th>
<th class="purple">Gross Sales AUD</th>
<th class="purple">Net Sales AUD</th>
<th class="purple">Gross Profit AUD</th>
<th class="purple">Net Export Sales Converted to Or Invoiced in AUD</th>
<th class="purple">Gross Profit Value Export in AUD</th>
<th class="purple">GP% Excl Commissions</th>
<th class="pink">ATO Exchange Rate</th>
<th class="lightblue">Gross Australian Sales Foreign Currency</th>
<th class="lightblue">Net Australian Sales Foreign Currency</th>
<th class="lightblue">Gross Profit value Australian Sales Foreign Currency</th>
<th class="lightgreen">Gross Export Sales Foreign Currency</th>
<th class="lightgreen">Net Export Sales Foreign Currency</th>
<th class="lightgreen">Gross Profit Value After Discount Exports Foreign Currency</th>
<th class="darkgreen">Gross Commissions</th>
<th class="darkgreen">Net Commisions</th>
<td><?=$number->currency($gross_australian_sales_foreign_currency_total);?></td> </tr>
<td><?=$number->currency($net_australian_sales_foreign_currency_total);?></td>
<td><?=$number->currency($gross_profit_value_australian_sales_foreign_currency_total);?></td>
<td><?=$number->currency($gross_export_sales_foreign_currency_total);?></td> <tr>
<td><?=$number->currency($net_export_sales_foreign_currency_total);?></td> <td><?//Order Recd ?></td>
<td><?=$number->currency($gross_profit_value_after_discount_exports_foreign_currency_total);?></td> <td><? //All Paid ?></td>
<td><?=$number->currency($gross_commissions_total);?></td> <td><?//All Sent ?></td>
<td><?=$number->currency($net_commissions_total);?></td> <td><?//Status ?></td>
<td><?//Sale Cat ?></td>
<td><?//Job Type ?></td>
<td><?// Ship Cat ?></td>
<td><?// Job No ?></td>
<td><?// Enq No ?></td>
<td><?// Principle ?></td>
<td><?// CMC PO ?></td>
<td><?// Customer ?></td>
<td><?// Sale Currenct ?></td>
<td id="totals"><?=$number->currency($totals['company_gross_sales_aud']);?></td>
<td><?=$number->currency($totals['net_sales_aud']);?></td>
<td><?=$number->currency($totals['gross_profit_aud']);?></td>
<td><?=$number->currency($totals['net_export_sales_aud']);?></td>
<td><?=$number->currency($totals['gross_profit_exports_aud']);?></td>
<td><?=$number->toPercentage($totals['gp_percent']);?></td>
<td><?//ATO Exch Rate?></td>
<td><?=$number->currency($totals['gross_australian_sales_foreign_currency']);?></td>
<td><?=$number->currency($totals['net_australian_sales_foreign_currency']);?></td>
<td><?=$number->currency($totals['gross_profit_value_australian_sales_foreign_currency']);?></td>
<td><?=$number->currency($totals['gross_export_sales_foreign_currency']);?></td>
<td><?=$number->currency($totals['net_export_sales_foreign_currency']);?></td>
<td><?=$number->currency($totals['gross_profit_value_after_discount_exports_foreign_currency']);?></td>
<td><?=$number->currency($totals['gross_commissions']);?></td>
<td><?=$number->currency($totals['net_commissions']);?></td>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
<?
//print_r($jobs);
?>

View file

@ -1230,12 +1230,7 @@ span.addLineItem {
table .jobsTable { table .jobsTable {
height: 900px;
}
table.jobsTable tbody {
height: 800px;
overflow: scroll;
} }
table.jobsTable tr th { table.jobsTable tr th {
@ -1244,6 +1239,11 @@ table.jobsTable tr th {
} }
table .jobsTable tr td {
padding:0;
margin:0;
}
/** Header Colors for Job table to replaced 'Book1'. */ /** Header Colors for Job table to replaced 'Book1'. */
th.purple { th.purple {
background-color: #8D80FC; background-color: #8D80FC;
@ -1350,7 +1350,7 @@ select.shipmentCategories {
/* CSS for the Job Reporting */ /* CSS for the Job Reporting */
#yearMonths { #yearMonths {
width: 6em;
float: left; float: left;
margin-right: 4em; margin-right: 4em;
} }
@ -1359,25 +1359,34 @@ select.shipmentCategories {
float: left; float: left;
} }
ul.yearList { ul.years {
list-style: none; list-style: none;
margin: 0; margin: 0;
padding-bottom: 1em; padding-bottom: 1em;
display: inline;
} }
ul.monthList { ul.years li {
display: inline;
cursor: pointer;
font-size: 0.9em;
}
ul.years li span.count {
font-size: 0.7em;
}
ul.months {
list-style: none; list-style: none;
margin: 0; margin: 0;
padding-left: 0.5em;
} }
ul.monthList li { ul.months li {
margin-left:0.5em; display: inline;
margin-top:0.5em;
width: 10em;
} }
span.month { span.month {
cursor: pointer; cursor: pointer;
font-size: 80% font-size: 80%
@ -1392,6 +1401,10 @@ tr.cancelled td {
text-decoration: line-through; text-decoration: line-through;
} }
#reports h3 {
padding-top:0.5em;
}
/* Shipments Index */ /* Shipments Index */

View file

@ -2,11 +2,13 @@ $(function() {
$(".year").click(function() { $(".year").click(function() {
var thisYear = $(this).html(); var thisYear = $(this).attr('id');
//alert(thisYear);
$.get('/jobs/viewReport/'+thisYear, function(data) { $.get('/jobs/viewReport/'+thisYear, function(data) {
$("#reports").html(data); $("#reports").html(data);
}); });
;
}); });