From d3ccea11c63e84d101cf23130e70c317e401d56e Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Thu, 12 May 2011 16:39:39 +1000 Subject: [PATCH] Reports almost finished --- controllers/jobs_controller.php | 166 +++++++++++++++++-- views/jobs/reports.ctp | 36 +++-- views/jobs/view_report.ctp | 279 +++++++++++++++----------------- webroot/css/quotenik.css | 41 +++-- webroot/js/job_reports.js | 6 +- 5 files changed, 332 insertions(+), 196 deletions(-) diff --git a/controllers/jobs_controller.php b/controllers/jobs_controller.php index 9eae3f3d..979c6857 100755 --- a/controllers/jobs_controller.php +++ b/controllers/jobs_controller.php @@ -108,6 +108,11 @@ class JobsController extends AppController { $monthList = $this->getYearMonths($jobs); $this->set('monthList', $monthList); + + + $Fyears = $this->getFinancialYears($jobs); + $this->set('Fyears',$Fyears); + /* $this->set('jobs', $jobs); $this->set('customers', $this->Job->Enquiry->Customer->find('list')); $this->set('currencies', $this->Job->Currency->find('list'));*/ @@ -116,11 +121,9 @@ class JobsController extends AppController { - function viewReport($year, $month) { - $this->layout = 'ajax'; + function viewReport($year, $month = null) { + //$this->layout = 'ajax'; - $this->set('year', $year); - $this->set('month', $month); 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'=> array('Job.date_order_received BETWEEN ? AND ?'=>array($startDate, $endDate)))); + + $this->set('year', $year); + $this->set('month', $month); + + $this->set('jobs', $jobs); $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 { @@ -167,7 +215,7 @@ class JobsController extends AppController { /** - * Generate aggregates for the financial data in $jobs. + * Generate aggregates for the financial data in $jobs. * * Procedure: * 1. Loop over the $jobs. @@ -176,19 +224,113 @@ class JobsController extends AppController { * * @param $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'; $query = strtolower($_GET["term"]); diff --git a/views/jobs/reports.ctp b/views/jobs/reports.ctp index f63bc7bb..a6610b84 100644 --- a/views/jobs/reports.ctp +++ b/views/jobs/reports.ctp @@ -3,27 +3,29 @@

Book 1 - Reports

-
- $monthArr): - ?> -
    -
  • -
      - $count):?> -
    • ()
    • - -
    -
  • - +
    +
      + $count): + $lastYear = $year - 1; + ?> + + +
    • - ()
    • + +
    • No Date ()
    • + + +
    - +
      + +
    - -
    - +
    +
    +
    \ No newline at end of file diff --git a/views/jobs/view_report.ctp b/views/jobs/view_report.ctp index 0664f450..36cee938 100644 --- a/views/jobs/view_report.ctp +++ b/views/jobs/view_report.ctp @@ -1,120 +1,102 @@ -

    +

    - -

    - - - +Skip to Totals +
    + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - + + + - - - - - + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Order ReceivedAll PaidAll SentStatusSale CategoryJob TypeShipment Category Job Number Enquiry Number PrincipleCMC POs CustomerStatus Sale CurrencyGross Sales AUDNet Sales AUDGross Profit AUDNet Export Sales Converted to Or Invoiced in AUDGross Profit Value Export in AUDGP% Excl CommissionsATO Exchange RateGross Australian Sales Foreign CurrencyNet Australian Sales Foreign CurrencyGross Profit value Australian Sales Foreign CurrencyGross Export Sales Foreign CurrencyNet Export Sales Foreign CurrencyGross Profit Value After Discount Exports Foreign CurrencyGross CommissionsNet CommisionsGross Sales AUDNet Sales AUDGross Profit AUDNet Export Sales Converted to Or Invoiced in AUDGross Profit Value Export in AUDGP% Excl CommissionsATO Exchange RateGross Australian Sales Foreign CurrencyNet Australian Sales Foreign CurrencyGross Profit value Australian Sales Foreign CurrencyGross Export Sales Foreign CurrencyNet Export Sales Foreign CurrencyGross Profit Value After Discount Exports Foreign CurrencyGross CommissionsNet Commisions
    link($job['Job']['title'], array('controller'=>'jobs', 'action'=>'view', $job['Job']['id']));?> + element('isEmptyDate', array('date'=>$job['Job']['date_order_received']));?> + element('booleanTick', array('bool'=>$job['Job']['all_paid'])); ?> + + element('booleanTick', array('bool'=>$job['Job']['all_sent'])); ?> link($job['Enquiry']['title'], array('controller'=>'enquiries','action'=>'view', $job['Enquiry']['id']));?> - link($principleList[$job['Enquiry']['principle_id']], '/principles/view/'.$job['Enquiry']['principle_id']);?>link($job['Customer']['name'], array('controller'=>'customers','action'=>'view', $job['Customer']['id']));?> + + + link($job['Job']['title'], array('controller'=>'jobs', 'action'=>'view', $job['Job']['id']));?>link($job['Enquiry']['title'], array('controller'=>'enquiries','action'=>'view', $job['Enquiry']['id']));?>link($principleList[$job['Enquiry']['principle_id']], '/principles/view/'.$job['Enquiry']['principle_id']);?>link($po['title'], array('controller'=>'purchase_orders', 'action'=>'view', $po['id'])); + } + echo $poString; + ?> + link($job['Customer']['name'], array('controller'=>'customers','action'=>'view', $job['Customer']['id']));?> - currency($job['Job']['company_gross_sales_aud']);?> - + + - currency($job['Job']['net_sales_aud']);?> - + + - currency($job['Job']['gross_profit_aud']);?> - + - currency($job['Job']['gross_profit_exports_aud']);?> + @@ -123,99 +105,94 @@ currency($job['Job']['gross_australian_sales_foreign_currency'], $job['Currency']['iso4217']);?> - + - currency($job['Job']['net_australian_sales_foreign_currency'], $job['Currency']['iso4217']); - if($doCount) { - $net_australian_sales_foreign_currency_total += $job['Job']['net_australian_sales_foreign_currency']; - - } - - ?> + currency($job['Job']['gross_profit_value_australian_sales_foreign_currency'], $job['Currency']['iso4217']); - if($doCount) { - $gross_profit_value_australian_sales_foreign_currency_total += $job['Job']['gross_profit_value_australian_sales_foreign_currency']; - - } - ?> + - currency($job['Job']['gross_export_sales_foreign_currency'],$job['Currency']['iso4217']); - - if($doCount) { - - $gross_export_sales_foreign_currency_total += $job['Job']['gross_export_sales_foreign_currency']; - } - ?> + currency($job['Job']['net_export_sales_foreign_currency'],$job['Currency']['iso4217']); - if($doCount) { - $net_export_sales_foreign_currency_total += $job['Job']['net_export_sales_foreign_currency']; - } - ?> + currency($job['Job']['gross_profit_value_after_discount_exports_foreign_currency'],$job['Currency']['iso4217']); - - if($doCount) { - $gross_profit_value_after_discount_exports_foreign_currency_total += $job['Job']['gross_profit_value_after_discount_exports_foreign_currency']; - } - ?> + - currency($job['Job']['gross_commissions']); - if($doCount) { - $gross_commissions_total += $job['Job']['gross_commissions']; - } - ?> + currency($job['Job']['net_commissions']); - if($doCount) { - $net_commissions_total += $job['Job']['net_commissions']; - } - - ?> +
    currency($gross_sales_aud_total)?>currency($net_sales_aud_total)?>currency($gross_profit_total)?> Order ReceivedAll PaidAll SentStatusSale CategoryJob TypeShipment CategoryJob NumberEnquiry NumberPrincipleCMC POsCustomerSale CurrencyGross Sales AUDNet Sales AUDGross Profit AUDNet Export Sales Converted to Or Invoiced in AUDGross Profit Value Export in AUDGP% Excl CommissionsATO Exchange RateGross Australian Sales Foreign CurrencyNet Australian Sales Foreign CurrencyGross Profit value Australian Sales Foreign CurrencyGross Export Sales Foreign CurrencyNet Export Sales Foreign CurrencyGross Profit Value After Discount Exports Foreign CurrencyGross CommissionsNet Commisionscurrency($gross_australian_sales_foreign_currency_total);?>currency($net_australian_sales_foreign_currency_total);?>currency($gross_profit_value_australian_sales_foreign_currency_total);?>currency($gross_export_sales_foreign_currency_total);?>currency($net_export_sales_foreign_currency_total);?>currency($gross_profit_value_after_discount_exports_foreign_currency_total);?>currency($gross_commissions_total);?>currency($net_commissions_total);?>
    currency($totals['company_gross_sales_aud']);?>currency($totals['net_sales_aud']);?>currency($totals['gross_profit_aud']);?>currency($totals['net_export_sales_aud']);?>currency($totals['gross_profit_exports_aud']);?>toPercentage($totals['gp_percent']);?>currency($totals['gross_australian_sales_foreign_currency']);?>currency($totals['net_australian_sales_foreign_currency']);?>currency($totals['gross_profit_value_australian_sales_foreign_currency']);?>currency($totals['gross_export_sales_foreign_currency']);?>currency($totals['net_export_sales_foreign_currency']);?>currency($totals['gross_profit_value_after_discount_exports_foreign_currency']);?>currency($totals['gross_commissions']);?>currency($totals['net_commissions']);?>
    - - - \ No newline at end of file diff --git a/webroot/css/quotenik.css b/webroot/css/quotenik.css index 8d87695c..e315b627 100755 --- a/webroot/css/quotenik.css +++ b/webroot/css/quotenik.css @@ -1230,12 +1230,7 @@ span.addLineItem { table .jobsTable { - height: 900px; -} - -table.jobsTable tbody { - height: 800px; - overflow: scroll; + } 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'. */ th.purple { background-color: #8D80FC; @@ -1350,7 +1350,7 @@ select.shipmentCategories { /* CSS for the Job Reporting */ #yearMonths { - width: 6em; + float: left; margin-right: 4em; } @@ -1359,25 +1359,34 @@ select.shipmentCategories { float: left; } -ul.yearList { +ul.years { list-style: none; margin: 0; 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; margin: 0; - padding-left: 0.5em; } -ul.monthList li { - margin-left:0.5em; - margin-top:0.5em; - width: 10em; +ul.months li { + display: inline; } + span.month { cursor: pointer; font-size: 80% @@ -1392,6 +1401,10 @@ tr.cancelled td { text-decoration: line-through; } +#reports h3 { + padding-top:0.5em; +} + /* Shipments Index */ diff --git a/webroot/js/job_reports.js b/webroot/js/job_reports.js index 3c4d5268..4b58496d 100644 --- a/webroot/js/job_reports.js +++ b/webroot/js/job_reports.js @@ -2,11 +2,13 @@ $(function() { $(".year").click(function() { - var thisYear = $(this).html(); + var thisYear = $(this).attr('id'); + //alert(thisYear); + $.get('/jobs/viewReport/'+thisYear, function(data) { $("#reports").html(data); }); -; + });