diff --git a/controllers/shipments_controller.php b/controllers/shipments_controller.php
index 37b84ab3..93d4ba84 100644
--- a/controllers/shipments_controller.php
+++ b/controllers/shipments_controller.php
@@ -249,7 +249,7 @@ class ShipmentsController extends AppController {
function reports() {
- $invoices = $this->Shipment->ShipmentInvoice->find('all',array('conditions'=>array('ShipmentInvoice.deferred_gst > 0')));
+ $invoices = $this->Shipment->ShipmentInvoice->find('all');
/*foreach($shipments as $shipment) {
foreach($shipment['ShipmentInvoice'] as $si) {
@@ -263,22 +263,20 @@ class ShipmentsController extends AppController {
$Fyears = $this->getFinancialYears($invoices);
$this->set('Fyears',$Fyears);
-
$this->set('invoices', $invoices);
-}
+ }
-function getFinancialYears($shipments) {
+ function getFinancialYears($shipments) {
$Fyears = array();
foreach($shipments as $shipment) {
- $time = strtotime($shipment['Shipment']['created']);
+ $time = strtotime($shipment['ShipmentInvoice']['date_issued']);
$year = date('Y', $time); //ISO-8601 year number
-
$startFYunix = $this->getFirstDayFY($year); //1 July of $year.
if($time < $startFYunix) { //Date is before 1 July $year.
@@ -305,7 +303,171 @@ function getFinancialYears($shipments) {
}
krsort($Fyears); //Sort the array in reverse order, most recent to oldest.
return $Fyears;
-}
+ }
+
+ function viewReport($year, $month = null) {
+ $this->layout = 'ajax';
+
+
+ if(isset($month) && isset($year)) { //After a Specific Month for a Year
+
+
+
+ $startDate = $year.'-'.$month.'-01';
+
+ $startDateTime = strtotime($startDate);
+
+ $numberOfDaysInMonth = date('t', $startDateTime);
+
+ $endDate = $year.'-'.$month.'-'.$numberOfDaysInMonth;
+
+ $monthStrings = array(
+ '01'=>'January',
+ '02'=> 'February',
+ '03'=>'March',
+ '04'=> 'April',
+ '05'=> 'May',
+ '06'=> 'June',
+ '07'=> 'July',
+ '08'=> 'August',
+ '09'=> 'September',
+ '10'=> 'October',
+ '11'=> 'November',
+ '12' => 'December');
+
+
+
+ $jobRangeTitle = $monthStrings[$month]." $year";
+ $shipmentInvoices = $this->Shipment->ShipmentInvoice->find('all', array('recursive'=>1, 'conditions'=>
+ array('ShipmentInvoice.date_issued BETWEEN ? AND ?'=>array($startDate, $endDate)),
+ 'order'=>'ShipmentInvoice.date_issued ASC'));
+
+ $shipments = $this->Shipment->find('all');
+
+
+ $jobList = array();
+ foreach($shipments as $shipment) {
+ $jobListString = '';
+ foreach($shipment['Job'] as $job) {
+ $jobListString .= ''.$job['title'].' '; //Goddamn
+ //$html->link($job['Job']['title'], '/jobs/view/'.$job['Job']['id']).' ';
+
+
+ }
+ $jobList[$shipment['Shipment']['id']] = $jobListString;
+ }
+
+ $this->set('jobList', $jobList);
+
+ /* $dateStringFormat = 'j F Y';
+ $dateString['first'] = date($dateStringFormat, $firstDayUnix);
+ $dateString['last'] = date($dateStringFormat, $lastDayUnix);
+ */
+ $this->set('jobRangeTitle', $jobRangeTitle);
+
+ $this->set('year', $year);
+ $this->set('month', $month);
+ $this->set('shipments',$shipmentInvoices); //ugh.
+
+
+
+ // $this->set('totals', $this->getTotals($jobs));
+
+ $this->set('principleList',$this->Shipment->Job->Enquiry->Principle->find('list'));
+
+ $this->set('startDate',$startDate);
+ $this->set('endDate',$endDate);
+
+
+ }
+
+ 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);
+
+
+ if($year == 0) { //Jobs with an empty 'date_order_received
+ $jobs = $this->Job->find('all', array('conditions'=>array('Job.date_order_received'=>'0000-00-000')));
+ $jobRangeTitle = "Jobs without Order Received date";
+ }
+ else { //We're looking for Jobs that have an 'date_order_received'
+
+ $jobs = $this->Job->find('all', array('conditions'=>
+ array('Job.date_order_received BETWEEN ? AND ?'=>array($firstDayDate, $lastDayDate))
+ )
+ );
+
+ $lastYear = $year - 1;
+ $jobRangeTitle = $lastYear.' - '.$year.' ('.$dateString['first']." to ".$dateString['last'].')';
+
+ }
+
+ $this->set('jobRangeTitle', $jobRangeTitle);
+
+ $this->set('shipments',$shipments);
+ $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($totals);
+//print_r($jobs);
+ }
+
+ else {
+ echo "Failure";
+ }
+
+
+ //$this->set('jobs', )
+
+
+
+ }
+
+
+ function setInvoiceDates() {
+
+ $shipments = $this->Shipment->find('all');
+
+ foreach($shipments as $shipment) {
+
+ $created = $shipment['Shipment']['created'];
+
+ foreach($shipment['ShipmentInvoice'] as $si) {
+
+ $this->Shipment->ShipmentInvoice->id = $si['id'];
+ $this->data = $si;
+ $this->data['created'] = $created;
+ $this->data['date_issued'] = date('Y-m-d', strtotime($created));
+ if($this->Shipment->ShipmentInvoice->save($this->data)) {
+ echo 'Updated '.$si['id']."to have {$created} as created and date_issued"."
";
+ }
+ else {
+ echo "Unable to save ".$si['id']."
";
+ }
+ }
+ }
+
+ }
}
?>
\ No newline at end of file
diff --git a/views/elements/add_edit_shipment.ctp b/views/elements/add_edit_shipment.ctp
index 1323b971..49bc7e16 100644
--- a/views/elements/add_edit_shipment.ctp
+++ b/views/elements/add_edit_shipment.ctp
@@ -150,6 +150,7 @@ echo $form->input('id', array('type'=>'hidden'));
echo $form->input("ShipmentInvoice.{$invNo}.freight_forwarder_id", array('label'=>'Freight Forwarder', 'div'=>'inv_freight_forwarder_id', 'options'=>$freightForwarders, 'empty'=>'Select Freight Forwarder'));
echo $form->input("ShipmentInvoice.{$invNo}.principle_id", array('label'=>'Invoice Issued by Principle', 'div'=>'inv_principle_id', 'options'=>$principles, 'empty'=>'Select Principle'));
echo $form->input("ShipmentInvoice.{$invNo}.invoice_number", array('label'=>'Invoice Number', 'div'=>'inv_invoice_number'));
+ echo $form->input("ShipmentInvoice.{$invNo}.date_issued", array('label'=>'Date Issued', 'div'=>'inv_date_issued', 'class'=>'date_issued', 'type'=>'text'));
echo $form->input("ShipmentInvoice.{$invNo}.invoice_amount", array('label'=>'Invoice Amount', 'div'=>'inv_invoice_amount'));
echo $form->input("ShipmentInvoice.{$invNo}.gst_amount", array('label'=>'GST Amount', 'div'=>'inv_gst_amount'));
echo $form->input("ShipmentInvoice.{$invNo}.deferred_gst", array('label'=>'Deferred GST?', 'div'=>'inv_deferred_gst', 'options'=>$yesNo));
@@ -187,13 +188,14 @@ echo $form->input('id', array('type'=>'hidden'));
echo $form->input("freight_forwarder_id", array('label'=>'Invoice Issued by Freight Forwarder', 'div'=>'inv_freight_forwarder_id', 'options'=>$freightForwarders, 'empty'=>'Select Freight Forwarder'));
echo $form->input('principle_id', array('label'=>'Invoice Issued by Principle', 'div'=>'inv_principle_id', 'options'=>$principles, 'empty'=>'Select Principle'));
echo $form->input("invoice_number", array('label'=>'Invoice Number', 'div'=>'inv_invoice_number'));
+ echo $form->input("date_issued", array('label'=>'Date Issued', 'div'=>'inv_date_issued', 'class'=>'date_issued_factory', 'type'=>'text'));
echo $form->input("invoice_amount", array('label'=>'Invoice Amount', 'div'=>'inv_invoice_amount'));
echo $form->input("gst_amount", array('label'=>'GST Amount', 'div'=>'inv_gst_amount'));
echo $form->input("deferred_gst", array('label'=>'Deferred GST?', 'div'=>'inv_deferred_gst', 'options'=>$yesNo));
echo $form->input("deferred_gst_amount", array('label'=>'Deferred GST Amount', 'div'=>'inv_deferred_gst_amount'));
echo $form->input("approved", array('label'=>'Approved', 'div'=>'inv_approved', 'options'=>$yesNo));
echo $form->input("paid", array('label'=>'Paid', 'div'=>'inv_paid', 'options'=>$yesNo));
- echo $form->input("date_paid", array('label'=>'Date Paid', 'div'=>'inv_date_paid', 'class'=>'date_paid', 'type'=>'text'));
+ echo $form->input("date_paid", array('label'=>'Date Paid', 'div'=>'inv_date_paid', 'class'=>'date_paid_factory', 'type'=>'text'));
?>
\ No newline at end of file
diff --git a/views/jobs/reports.ctp b/views/jobs/reports.ctp
index cce89107..9c96c2cc 100644
--- a/views/jobs/reports.ctp
+++ b/views/jobs/reports.ctp
@@ -1,4 +1,4 @@
-=$javascript->link('job_reports');?>
+=$javascript->link('reports');?>
| Date Issued | +Shipment for Job# | +Principle | +Freight Forwarder | +Invoice Number | +Currency | +Invoice Amount | +Deferred GST? | +Deferred GST Amount | +Deferred GST running total | +Approved | +Paid | +Date Paid | +||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| =$this->element('isEmptyDate', array('date'=>$shipment['ShipmentInvoice']['date_issued']));?> | +=$jobList[$shipment['ShipmentInvoice']['shipment_id']];?> | +=$shipment['Principle']['name'];?> | +=$shipment['FreightForwarder']['name'];?> | +=$shipment['ShipmentInvoice']['invoice_number'];?> | +=$shipment['Currency']['iso4217'];?> | +=$shipment['ShipmentInvoice']['invoice_amount'];?> | +=$this->element('booleanTick', array('bool'=>$shipment['ShipmentInvoice']['deferred_gst']));?> | + 0):?> ++ =$shipment['ShipmentInvoice']['deferred_gst_amount'];?> + | ++ =$runningTotal?> + | + ++ | + + | =$this->element('booleanTick', array('bool'=>$shipment['ShipmentInvoice']['approved']));?> | +=$this->element('booleanTick', array('bool'=>$shipment['ShipmentInvoice']['paid']));?> | +=$this->element('isEmptyDate', array('date'=>$shipment['ShipmentInvoice']['date_paid']));?> | +