editing shipments will now delete all boxes and ShipmentInvoices before saving new ones

This commit is contained in:
Karl Cordes 2011-05-10 14:50:42 +10:00
parent 95fcfb5373
commit 796371fc36
5 changed files with 64 additions and 15 deletions

View file

@ -166,6 +166,17 @@ class JobsController extends AppController {
}
function getFinancialYears() {
}
function getFirstFYday($year) {
}
/**
* Build an array of Years/Months with Jobs.
*

View file

@ -106,7 +106,7 @@ class ShipmentsController extends AppController {
$invoiceType = $this->invoiceTypeOptions();
$this->set('yesNo', array(0=>'No', 1=>'Yes'));
$this->set(compact('principles', 'freightForwarders', 'shipmentType', 'shipmentTypeShort', 'currencies','invoiceType', 'yesNo'));
@ -122,9 +122,18 @@ class ShipmentsController extends AppController {
if(!empty($this->data)) {
//$this->Shipment->create($this->data);
$shipment_id = $this->data['Shipment']['id'];
$this->Shipment->Box->deleteAll(array('shipment_id'=>$shipment_id));
$this->Shipment->ShipmentInvoice->deleteAll(array('shipment_id'=>$shipment_id));
if ($this->Shipment->saveAll($this->data)) {
$boxIDs = array();
$this->Shipment->Box->updateCounterCache(array('shipment_id'=>$shipment_id));
$this->Shipment->ShipmentInvoice->updateCounterCache(array('shipment_id'=>$shipment_id));
/*$boxIDs = array();
foreach($this->data['Box'] as $box) {
$boxIDs[] = $box['id'];
@ -134,8 +143,15 @@ class ShipmentsController extends AppController {
foreach($this->data['ShipmentInvoice'] as $si) {
$invoiceIDs[] = $si['id'];
}
print_r($boxIDs);
print_r($boxIDs);*/
/*foreach($this->data['Job'] as $job) {
foreach($job as $index => $id) {
echo $id."\n";
}
}*/
print_r($this->data);
echo "SUCCESS";
@ -160,6 +176,7 @@ class ShipmentsController extends AppController {
if ($this->Shipment->saveAll($this->data)) {
echo "SUCCESS";
print_r($this->data);
}
else {
echo "FAILURE";
@ -174,6 +191,11 @@ class ShipmentsController extends AppController {
}
function markJobsSent() {
}
/* Moved the Views for Adding/Editing to elements. Called from the Index.
*
* function add($action = 'add') {

View file

@ -55,9 +55,9 @@ echo $form->input('id', array('type'=>'hidden'));
<div id="job" class="hiddenDefault">
<?
echo $form->input('job', array('id'=>'job_autocomplete'));
echo $form->input('job', array('id'=>'job_autocomplete', array('label'=>'Job (start typing and select from the list)')));
?>
<span class="moreInfo">Jobs in this Shipment will be updated as "sent"</span>
<ul id="jobsList" class="habtmList">
<?php foreach($this->data['Job'] as $job):?>
@ -72,7 +72,7 @@ echo $form->input('id', array('type'=>'hidden'));
</div>
<div id="customer" class="hiddenDefault">
<?=$form->input('customer', array('id'=>'customer_autocomplete', 'label'=>'Customer', 'value'=>$this->data['Customer']['name']));?>
<?=$form->input('customer', array('id'=>'customer_autocomplete', 'label'=>'Customer (start typing and select from the list)', 'value'=>$this->data['Customer']['name']));?>
<?=$form->input('customer_id', array('type'=>'hidden', 'id'=>'customer_id', 'value'=>$this->data['Shipment']['customer_id']));?>
</div>

View file

@ -121,7 +121,8 @@
<td>
<?=$shipment['Shipment']['shipment_invoice_count'];?>
</td>
<td><?foreach($shipment['ShipmentInvoice'] as $si) {
<td><?
foreach($shipment['ShipmentInvoice'] as $si) {
if(!empty($si['principle_id'])) {
echo $principles[$si['principle_id']];
}
@ -144,18 +145,31 @@
}?>
</td>
<td><?
if($si['deferred_gst'] == 1) {
foreach($shipment['ShipmentInvoice'] as $si) {
foreach($shipment['ShipmentInvoice'] as $si) {
if($si['deferred_gst'] == 1) {
echo $currencies[$si['currency_id']]." ".$si['deferred_gst_amount']."<br />";
}
}
?>
</td>
<td><?=$this->element('booleanTick', array('bool'=>$si['approved'])); ?></td>
<td><?=$this->element('booleanTick', array('bool'=>$si['paid'])); ?></td>
<td><?=$this->element('isEmptyDate', array('date'=>$si['date_paid']));?></td>
<td><?
foreach($shipment['ShipmentInvoice'] as $si) {
echo $this->element('booleanTick', array('bool'=>$si['approved'])); }
?>
</td>
<td><? foreach($shipment['ShipmentInvoice'] as $si) {
echo $this->element('booleanTick', array('bool'=>$si['paid']));
}?>
</td>
<td><? foreach($shipment['ShipmentInvoice'] as $si) {
echo $this->element('isEmptyDate', array('date'=>$si['date_paid']));
}
?>
</td>
<td>
<?php echo $shipment['Shipment']['comments']; ?>
</td>

View file

@ -45,7 +45,7 @@ $(function() {
$.post('/shipments/ajax_edit', thisShipmentInputs, function(data) {
$( "#edit-form" ).dialog('close');
window.location.reload(); //Change this to fetch a new copy of the table and update a <div>.
// window.location.reload(); //Change this to fetch a new copy of the table and update a <div>.
});
},
@ -69,9 +69,10 @@ $(function() {
$.get('/shipments/add/', false, function(data) {
$("#add-form").html(data);
$( "#add-form" ).dialog( "open" );
} );
$( "#add-form" ).dialog( "open" );
});
@ -83,9 +84,10 @@ $(function() {
$.get('/shipments/edit/'+id, false, function(data) {
$("#edit-form").html(data);
$( "#edit-form" ).dialog( "open" );
} );
$( "#edit-form" ).dialog( "open" );
});