cmc-sales/controllers/shipments_controller.php
2011-04-28 17:41:36 +10:00

94 lines
2.1 KiB
PHP

<?php
class ShipmentsController extends AppController {
var $name = 'Shipments';
var $helpers = array('Html', 'Form');
var $paginate = array(
'contain' => false,
'limit' => 100,
'order'=>array('Shipment.id' => 'desc'),
'recursive' => 1
);
function index() {
$this->Shipment->recursive = 0;
$this->set('shipments', $this->paginate());
$principles = $this->Shipment->Principle->find('list');
$freightForwarders = $this->Shipment->FreightForwarder->find('list');
$shipmentType = $this->typeOptions(false);
$shipmentTypeShort = $this->typeOptions(true);
$this->set(compact('principles', 'freightForwarders', 'shipmentType', 'shipmentTypeShort'));
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Shipment.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('shipment', $this->Shipment->read(null, $id));
}
function ajax_edit() {
$this->layout = 'ajax';
if(!empty($this->data)) {
if ($this->Shipment->saveAll($this->data)) {
echo "SUCCESS";
}
else {
echo "FAILURE";
}
}
else {
return;
}
}
/* Moved the Views for Adding/Editing to elements. Called from the Index.
*
* function add($action = 'add') {
$principles = $this->Shipment->Principle->find('list');
$freightForwarders = $this->Shipment->FreightForwarder->find('list');
$shipmentType = $this->typeOptions();
$this->set(compact('principles', 'freightForwarders', 'shipmentType'));
}*/
function typeOptions($short = false) {
if($short == false) {
$options = array('','Import: Principle to CMC','Direct: Principle to Customer','Export','Local');
}
else {
$options = array('','Import','Direct','Export','Local');
}
return $options;
}
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for Shipment', true));
$this->redirect(array('action'=>'index'));
}
if ($this->Shipment->del($id)) {
$this->Session->setFlash(__('Shipment deleted', true));
$this->redirect(array('action'=>'index'));
}
}
}
?>