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 @@ -link('job_reports');?> +link('reports');?>

Book 1 - Reports

@@ -29,4 +29,6 @@
-
\ No newline at end of file + + + \ No newline at end of file diff --git a/views/layouts/default.ctp b/views/layouts/default.ctp index 25417887..36beddd6 100755 --- a/views/layouts/default.ctp +++ b/views/layouts/default.ctp @@ -94,6 +94,7 @@ if ($currentuser['User']['access_level'] == 'manager' || $currentuser['User']['a
  • link('Direct Shipments', '/shipments/index/direct'); ?>
  • link('Export Shipments', '/shipments/index/export'); ?>
  • link('Local Shipments', '/shipments/index/local'); ?>
  • +
  • link('Monthly Deferred GST', '/shipments/reports'); ?>
  • link('Freight Forwarders', '/freight_forwarders'); ?>
  • diff --git a/views/shipments/reports.ctp b/views/shipments/reports.ctp new file mode 100644 index 00000000..2cb426d7 --- /dev/null +++ b/views/shipments/reports.ctp @@ -0,0 +1,35 @@ + +link('reports');?> + +

    Shipment Deferred GST Reports

    + + +
    + + + + + + +
    + +
    +
    +
    +
    + + \ No newline at end of file diff --git a/views/shipments/view_report.ctp b/views/shipments/view_report.ctp new file mode 100644 index 00000000..bbacaa7b --- /dev/null +++ b/views/shipments/view_report.ctp @@ -0,0 +1,58 @@ +

    + +

    Shipment Invoices

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0):?> + + + + + + + + + + + + +
    Date IssuedShipment for Job#PrincipleFreight ForwarderInvoice NumberCurrencyInvoice AmountDeferred GST?Deferred GST AmountDeferred GST running totalApprovedPaidDate Paid
    element('isEmptyDate', array('date'=>$shipment['ShipmentInvoice']['date_issued']));?>element('booleanTick', array('bool'=>$shipment['ShipmentInvoice']['deferred_gst']));?> + + + + element('booleanTick', array('bool'=>$shipment['ShipmentInvoice']['approved']));?>element('booleanTick', array('bool'=>$shipment['ShipmentInvoice']['paid']));?>element('isEmptyDate', array('date'=>$shipment['ShipmentInvoice']['date_paid']));?>
    diff --git a/webroot/js/add_edit_shipment.js b/webroot/js/add_edit_shipment.js index a3c5b862..688c1774 100644 --- a/webroot/js/add_edit_shipment.js +++ b/webroot/js/add_edit_shipment.js @@ -29,6 +29,12 @@ $(function() { dateFormat: 'yy-mm-dd' }); + + $('.date_issued').datepicker({ + showButtonPanel: true, + dateFormat: 'yy-mm-dd' + }); + /** * Display the relevent elements depending on this Shipment Type */ $("#shipmentType").change(function() { @@ -284,7 +290,7 @@ $(function() { newInvoiceForm.addClass('invForm'); newInvoiceForm.show(); - var invFields = ['currency_id','principle_id', 'freight_forwarder_id', 'invoice_number', + var invFields = ['currency_id','principle_id', 'freight_forwarder_id', 'invoice_number', 'date_issued', 'invoice_amount','gst_amount','deferred_gst', 'deferred_gst_amount','approved', 'paid', 'date_paid','invoice_type']; var div; @@ -297,6 +303,13 @@ $(function() { div.children('label').attr('for', ID); div.children(':input').attr('id', ID).attr('name', name); + if(field == 'date_issued' || field == 'date_paid') { + div.children(':input').datepicker({ + showButtonPanel: true, + dateFormat: 'yy-mm-dd' + }); + } + }); var closeButton = $(''); @@ -304,6 +317,18 @@ $(function() { closeButton.button(); newInvoiceForm.prepend(closeButton); + + /* $("#ShipmentInvoice"+invoiceNo+"Date_Issued").datepicker({ + showButtonPanel: true, + dateFormat: 'yy-mm-dd' + }); + $("#ShipmentInvoice"+invoiceNo+"Date_Paid").datepicker({ + showButtonPanel: true, + dateFormat: 'yy-mm-dd' + }); */ + + + $("#invoices").append(newInvoiceForm); } diff --git a/webroot/js/job_reports.js b/webroot/js/reports.js similarity index 91% rename from webroot/js/job_reports.js rename to webroot/js/reports.js index 3ed951a3..b7dde3bc 100644 --- a/webroot/js/job_reports.js +++ b/webroot/js/reports.js @@ -1,13 +1,13 @@ $(function() { - var model = $("#modelString").val(); + var model = $("#modelString").html(); $(".month").live('click',function(event) { event.preventDefault(); var target = $(this).children('a').attr('href'); - var targetString = '/jobs/viewReport/'+target; + var targetString = model+'/viewReport/'+target; $("#reports").fadeOut('fast'); @@ -33,7 +33,7 @@ $(function() { } - $.get('/jobs/viewReport/'+thisYear, function(data) { + $.get(model+'/viewReport/'+thisYear, function(data) { $("#reports").html(data); });