cmc-sales/controllers/shipments_controller.php

249 lines
5.5 KiB
PHP
Raw Normal View History

<?php
class ShipmentsController extends AppController {
2011-04-21 00:38:01 -07:00
var $name = 'Shipments';
var $helpers = array('Html', 'Form');
var $paginate = array(
'contain' => false,
2011-05-03 18:49:07 -07:00
'limit' => 300,
'order'=>array('Shipment.id' => 'desc'),
'recursive' => 1
);
2011-05-03 18:49:07 -07:00
function index($type = 'all') {
2011-04-21 00:38:01 -07:00
$this->Shipment->recursive = 0;
2011-05-03 18:49:07 -07:00
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:
}
2011-05-03 18:49:07 -07:00
$this->set('shipments', $this->paginate($conditions));
$this->set('type', $type);
2011-04-28 00:41:36 -07:00
$principles = $this->Shipment->Principle->find('list');
$freightForwarders = $this->Shipment->FreightForwarder->find('list');
$shipmentType = $this->typeOptions(false);
$shipmentTypeShort = $this->typeOptions(true);
2011-05-08 21:12:00 -07:00
$currencies = $this->Shipment->ShipmentInvoice->Currency->find('list', array('fields'=>array('Currency.id','Currency.iso4217')));
$principles = $this->Shipment->Principle->find('list');
$this->set(compact('principles', 'freightForwarders', 'shipmentType', 'shipmentTypeShort', 'currencies', 'principles'));
2011-04-28 00:41:36 -07:00
2011-04-21 00:38:01 -07:00
}
2011-04-21 00:38:01 -07:00
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Shipment.', true));
$this->redirect(array('action'=>'index'));
}
2011-04-21 00:38:01 -07:00
$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);
2011-05-08 18:11:23 -07:00
$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'));
2011-05-03 18:49:07 -07:00
}
function edit($id = null) {
if(isset($id)) {
if (empty($this->data)) {
$this->data = $this->Shipment->read(null, $id);
$address = $this->Shipment->Address->find('first', array('conditions'=>array('Address.id'=>$this->data['Shipment']['address_id']),'recursive'=>0));
2011-05-16 21:30:23 -07:00
$principles = $this->Shipment->Principle->find('list');
$freightForwarders = $this->Shipment->FreightForwarder->find('list');
$shipmentType = $this->typeOptions(false);
$shipmentTypeShort = $this->typeOptions(true);
2011-05-08 18:11:23 -07:00
$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', 'address'));
}
}
}
2011-04-28 00:41:36 -07:00
function ajax_edit() {
$this->layout = 'ajax';
if(!empty($this->data)) {
//$this->Shipment->create($this->data);
2011-05-01 16:42:35 -07:00
$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)) {
2011-05-16 23:12:16 -07:00
$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'];
2011-05-08 18:11:23 -07:00
}
$invoiceIDs = array();
foreach($this->data['ShipmentInvoice'] as $si) {
$invoiceIDs[] = $si['id'];
}
print_r($boxIDs);*/
2011-05-16 21:30:23 -07:00
if($this->data['Shipment']['type'] > 1) {
$jobIDs = array();
foreach($this->data['Job'] as $job) {
foreach($job as $index => $id) {
$jobIDs[] = $id;
}
}
2011-05-16 21:30:23 -07:00
$this->Shipment->Job->updateAll(array('Job.all_sent' => 1), array('Job.id'=>$jobIDs));
}
2011-05-10 16:44:56 -07:00
//print_r($this->data);
2011-04-28 00:41:36 -07:00
echo "SUCCESS";
}
else {
echo "FAILURE";
}
2011-04-28 00:41:36 -07:00
}
else {
echo "NO-DATA";
2011-04-28 00:41:36 -07:00
}
2011-04-28 00:41:36 -07:00
}
2011-04-21 00:38:01 -07:00
2011-05-01 16:42:35 -07:00
function ajax_add() {
//$this->layout = 'ajax';
if(!empty($this->data)) {
$this->Shipment->create($this->data);
2011-05-01 16:42:35 -07:00
if ($this->Shipment->saveAll($this->data)) {
echo "SUCCESS";
print_r($this->data);
}
else {
echo "FAILURE";
}
2011-05-01 16:42:35 -07:00
}
else {
echo "NO-DATA";
2011-05-01 16:42:35 -07:00
}
2011-05-01 16:42:35 -07:00
}
function markJobsSent() {
}
2011-04-28 00:41:36 -07:00
/* 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'));
}*/
2011-05-08 18:11:23 -07:00
function invoiceTypeOptions() {
$options = array('', 'Freight','Customs','Principle');
return $options;
}
2011-04-28 00:41:36 -07:00
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');
}
2011-04-21 00:38:01 -07:00
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'));
}
2011-04-21 00:38:01 -07:00
}
}
?>