false, 'limit' => 300, 'order'=>array('Shipment.id' => 'desc'), 'recursive' => 1 ); function index($type = 'all') { $this->Shipment->recursive = 0; switch($type) { case 'all': $conditions = array(); break; case 'import': $conditions = array('Shipment.type'=>1); break; case 'direct': $conditions = array('Shipment.type'=>2); break; case 'export': $conditions = array('Shipment.type'=>3); break; case 'local': $conditions = array('Shipment.type'=>4); break; default: } $this->set('shipments', $this->paginate($conditions)); $this->set('type', $type); $principles = $this->Shipment->Principle->find('list'); $freightForwarders = $this->Shipment->FreightForwarder->find('list'); $shipmentType = $this->typeOptions(false); $shipmentTypeShort = $this->typeOptions(true); $currencies = $this->Shipment->ShipmentInvoice->Currency->find('list'); $this->set(compact('principles', 'freightForwarders', 'shipmentType', 'shipmentTypeShort', 'currencies')); } 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 add() { $principles = $this->Shipment->Principle->find('list'); $freightForwarders = $this->Shipment->FreightForwarder->find('list'); $shipmentType = $this->typeOptions(false); $shipmentTypeShort = $this->typeOptions(true); $currencies = $this->Shipment->ShipmentInvoice->Currency->find('list'); $invoiceType = $this->invoiceTypeOptions(); $this->set('yesNo', array(0=>'No', 1=>'Yes')); $this->set(compact('principles', 'freightForwarders', 'shipmentType', 'shipmentTypeShort', 'currencies','invoiceType', 'yesNo')); } function edit($id = null) { if(isset($id)) { if (empty($this->data)) { $this->data = $this->Shipment->read(null, $id); $principles = $this->Shipment->Principle->find('list'); $freightForwarders = $this->Shipment->FreightForwarder->find('list'); $shipmentType = $this->typeOptions(false); $shipmentTypeShort = $this->typeOptions(true); $currencies = $this->Shipment->ShipmentInvoice->Currency->find('list'); $this->set(compact('principles', 'freightForwarders', 'shipmentType', 'shipmentTypeShort', 'currencies')); } } } function ajax_edit() { $this->layout = 'ajax'; if(!empty($this->data)) { //$this->Shipment->create($this->data); if ($this->Shipment->saveAll($this->data)) { $boxIDs = array(); foreach($this->data['Box'] as $box) { $boxIDs[] = $box['id']; } $invoiceIDs = array(); foreach($this->data['ShipmentInvoice'] as $si) { $invoiceIDs[] = $si['id']; } print_r($boxIDs); echo "SUCCESS"; } else { echo "FAILURE"; } } else { echo "NO-DATA"; } } function ajax_add() { //$this->layout = 'ajax'; if(!empty($this->data)) { $this->Shipment->create($this->data); if ($this->Shipment->saveAll($this->data)) { echo "SUCCESS"; } else { echo "FAILURE"; } } else { echo "NO-DATA"; } } /* 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 invoiceTypeOptions() { $options = array('', 'Freight','Customs','Principle'); return $options; } 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')); } } } ?>