cmc-sales/controllers/shipments_controller.php
2011-05-02 09:42:35 +10:00

110 lines
2.3 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)) {
$this->Shipment->create();
if ($this->Shipment->save($this->data)) {
echo "SUCCESS";
}
else {
echo "FAILURE";
}
}
else {
echo "NO-DATA";
}
}
function ajax_add() {
$this->layout = 'ajax';
$this->Shipment->create();
if ($this->Shipment->save($this->data)) {
echo "SUCCESS";
}
else {
echo "FAILURE";
}
}
/* 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'));
}
}
}
?>