Added Monthly Deferred GST to reports. Fixed DatePicker issues on New Invoices
This commit is contained in:
parent
aea86e55ca
commit
aa8414b68c
|
|
@ -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,7 +263,6 @@ class ShipmentsController extends AppController {
|
|||
$Fyears = $this->getFinancialYears($invoices);
|
||||
$this->set('Fyears',$Fyears);
|
||||
|
||||
|
||||
$this->set('invoices', $invoices);
|
||||
|
||||
}
|
||||
|
|
@ -275,10 +274,9 @@ function getFinancialYears($shipments) {
|
|||
|
||||
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.
|
||||
|
|
@ -307,5 +305,169 @@ function getFinancialYears($shipments) {
|
|||
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 .= '<a href="/jobs/view/'.$job['id'].'">'.$job['title'].'</a> '; //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"."<br>";
|
||||
}
|
||||
else {
|
||||
echo "Unable to save ".$si['id']."<br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
@ -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'));
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<?=$javascript->link('job_reports');?>
|
||||
<?=$javascript->link('reports');?>
|
||||
|
||||
<h2>Book 1 - Reports</h2>
|
||||
|
||||
|
|
@ -30,3 +30,5 @@
|
|||
<div id="reports">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<span id="modelString" style="display: none;">/jobs</span>
|
||||
|
|
@ -94,6 +94,7 @@ if ($currentuser['User']['access_level'] == 'manager' || $currentuser['User']['a
|
|||
<li class=""><?php echo $html->link('Direct Shipments', '/shipments/index/direct'); ?></li>
|
||||
<li class=""><?php echo $html->link('Export Shipments', '/shipments/index/export'); ?></li>
|
||||
<li class=""><?php echo $html->link('Local Shipments', '/shipments/index/local'); ?></li>
|
||||
<li class=""><?php echo $html->link('Monthly Deferred GST', '/shipments/reports'); ?></li>
|
||||
<li class="last"><?php echo $html->link('Freight Forwarders', '/freight_forwarders'); ?></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
|
|
|||
35
views/shipments/reports.ctp
Normal file
35
views/shipments/reports.ctp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
<?=$javascript->link('reports');?>
|
||||
|
||||
<h2>Shipment Deferred GST Reports</h2>
|
||||
|
||||
|
||||
<div id="years">
|
||||
<ul class="years">
|
||||
<? foreach($Fyears as $year => $count):
|
||||
$lastYear = $year - 1;
|
||||
?>
|
||||
|
||||
<?if($year != 1970 && $year != 0):?>
|
||||
<li id="<?=$year?>" class="year"><?=$lastYear?> - <?=$year?> <span class="count">(<?=$count?>)</span></li>
|
||||
<?else:?>
|
||||
<li id="0" class="year">No Date <span class="count">(<?=$count?>)</span></li>
|
||||
<?endif;?>
|
||||
|
||||
<?endforeach;?>
|
||||
</ul>
|
||||
|
||||
<span class="whichYear"></span>
|
||||
|
||||
<ul class="months">
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="scrollHorizontal">
|
||||
<div id="reports">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<span id="modelString" style="display: none;">/shipments</span>
|
||||
58
views/shipments/view_report.ctp
Normal file
58
views/shipments/view_report.ctp
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<h3><?=$jobRangeTitle?></h3>
|
||||
|
||||
<h4>Shipment Invoices</h4>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date Issued</th>
|
||||
<th>Shipment for Job#</th>
|
||||
<th>Principle</th>
|
||||
<th>Freight Forwarder</th>
|
||||
<th>Invoice Number</th>
|
||||
<th>Currency</th>
|
||||
<th>Invoice Amount</th>
|
||||
<th>Deferred GST?</th>
|
||||
<th>Deferred GST Amount</th>
|
||||
<th>Deferred GST running total</th>
|
||||
<th>Approved</th>
|
||||
<th>Paid</th>
|
||||
<th>Date Paid</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?
|
||||
$runningTotal = 0;
|
||||
|
||||
foreach($shipments as $shipment):
|
||||
|
||||
$runningTotal += $shipment['ShipmentInvoice']['deferred_gst_amount'];
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td><?=$this->element('isEmptyDate', array('date'=>$shipment['ShipmentInvoice']['date_issued']));?></td>
|
||||
<td><?=$jobList[$shipment['ShipmentInvoice']['shipment_id']];?></td>
|
||||
<td><?=$shipment['Principle']['name'];?></td>
|
||||
<td><?=$shipment['FreightForwarder']['name'];?></td>
|
||||
<td><?=$shipment['ShipmentInvoice']['invoice_number'];?></td>
|
||||
<td><?=$shipment['Currency']['iso4217'];?></td>
|
||||
<td><?=$shipment['ShipmentInvoice']['invoice_amount'];?></td>
|
||||
<td><?=$this->element('booleanTick', array('bool'=>$shipment['ShipmentInvoice']['deferred_gst']));?></td>
|
||||
<?if($shipment['ShipmentInvoice']['deferred_gst'] > 0):?>
|
||||
<td>
|
||||
<?=$shipment['ShipmentInvoice']['deferred_gst_amount'];?>
|
||||
</td>
|
||||
<td>
|
||||
<?=$runningTotal?>
|
||||
</td>
|
||||
<?else:?>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<?endif;?>
|
||||
<td><?=$this->element('booleanTick', array('bool'=>$shipment['ShipmentInvoice']['approved']));?></td>
|
||||
<td><?=$this->element('booleanTick', array('bool'=>$shipment['ShipmentInvoice']['paid']));?></td>
|
||||
<td><?=$this->element('isEmptyDate', array('date'=>$shipment['ShipmentInvoice']['date_paid']));?></td>
|
||||
</tr>
|
||||
<?endforeach;?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
@ -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 = $('<button>X</button>');
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
||||
Loading…
Reference in a new issue