diff --git a/controllers/contacts_controller.php b/controllers/contacts_controller.php deleted file mode 100755 index af7a682a..00000000 --- a/controllers/contacts_controller.php +++ /dev/null @@ -1,118 +0,0 @@ - array('order' => array('Contact.customer_id' => 'asc')), - 'Enquiry' => array('order' => array('Enquiry.id' => 'asc')) - ); - - - function index() { - $this->Contact->recursive = 0; - $this->set('contacts', $this->paginate()); - } - - function view($id = null) { - if (!$id) { - $this->Session->setFlash(__('Invalid Contact.', true)); - $this->redirect(array('action'=>'index')); - } - $this->set('contact', $this->Contact->read(null, $id)); - //$enquiries = $this->Contact->Enquiry->findAllByContactId($id); - $this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.contact_id' => $id))); - //$this->set('enquiries', $this->paginate($enquiries)); - $statuses = $this->Contact->Enquiry->Status->find('all'); - $status_list = array(); - foreach ($statuses as $status) { - $status_list[] = array($status['Status']['id'], $status['Status']['name']); - } - $this->set('status_list', $status_list); - - } - - - - function add_to_customer($customerid = null) { - - if(isset($this->params['named']['customerid'])) { - $customerid = $this->params['named']['customerid']; - } - if (!$customerid && empty($this->data)) { - $this->Session->setFlash(__('Invalid Customer ID', true)); - $this->redirect(array('controller'=>'Enquiries', 'action'=>'index')); - } - if (!empty($this->data)) { - - $this->Contact->create(); - if ($this->Contact->save($this->data)) { - $this->Session->setFlash(__('The Contact has been saved', true)); - $this->redirect(array('controller' => 'Customers', 'action'=>'view/'.$this->data['Contact']['customer_id'])); - } else { - $this->Session->setFlash(__('The Contact could not be saved. Please try again.', true)); - } - } - $contact_categories = $this->Contact->ContactCategory->find('list'); - $customer = $this->Contact->Customer->findById($customerid); - $this->set(compact('customer', 'contact_categories')); - } - - function add_another($increment) { - $this->set('contact_categories', $this->Contact->ContactCategory->find('list')); - $this->set('increment', $increment); - - } - function remove_another($increment) { - $this->set('increment', $increment); - } - function add_one($customerid) { - $contact_categories = $this->Contact->ContactCategory->find('list'); - $this->set('customerid', $customerid); - $this->set('contact_categories', $contact_categories); - } - function remove_one($customerid) { - $contacts = $this->Contact->find('all', array('conditions' => array('Contact.customer_id' => $customerid))); - $contacts = Set::Combine($contacts, '{n}.Contact.id', array('{0} {1}', '{n}.Contact.first_name', '{n}.Contact.last_name')); - $this->set('contacts', $contacts); - $this->set('customerid', $customerid); - } - - function edit($id = null) { - if (!$id && empty($this->data)) { - $this->Session->setFlash(__('Invalid Contact', true)); - $this->redirect(array('action'=>'index')); - } - if (!empty($this->data)) { - $this->data['Contact']['name'] = $this->data['Contact']['first_name'].' '.$this->data['Contact']['last_name']; - if ($this->Contact->save($this->data)) { - $customerid = $this->data['Contact']['customer_id']; - - $this->Session->setFlash(__('The Contact has been saved', true)); - $this->redirect(array('controller' => 'Customers', 'action'=>'view/'.$customerid)); - } else { - $this->Session->setFlash(__('The Contact could not be saved. Please, try again.', true)); - } - } - if (empty($this->data)) { - $this->data = $this->Contact->read(null, $id); - } - $customers = $this->Contact->Customer->find('list'); - $contact_categories = $this->Contact->ContactCategory->find('list'); - $this->set(compact('customers', 'contact_categories')); - } - - function delete($id = null) { - if (!$id) { - $this->Session->setFlash(__('Invalid id for Contact', true)); - $this->redirect(array('action'=>'index')); - } - if ($this->Contact->del($id)) { - $this->Session->setFlash(__('Contact deleted', true)); - $this->redirect(array('action'=>'index')); - } - } - -} -?> diff --git a/controllers/customers_controller.php b/controllers/customers_controller.php index 19b0edb3..c3680e58 100755 --- a/controllers/customers_controller.php +++ b/controllers/customers_controller.php @@ -84,7 +84,8 @@ class CustomersController extends AppController { if ($this->Customer->saveAll($this->data)) { $this->Session->setFlash(__('The Customer has been saved', true)); $id = $this->Customer->id; - $this->redirect(array('action'=>'view/'.$id)); + debug($this->data); + //$this->redirect(array('action'=>'view/'.$id)); } else { $this->Session->setFlash(__('The Customer could not be saved. Please, try again.', true)); diff --git a/controllers/jobs_controller.php b/controllers/jobs_controller.php index b11ae466..383f7f79 100755 --- a/controllers/jobs_controller.php +++ b/controllers/jobs_controller.php @@ -396,6 +396,44 @@ class JobsController extends AppController { } + function autocomplete() { + $this->layout = 'ajax'; + + $query = strtolower($_GET["term"]); + + //$this->set('customers_json', print_r($this->data)); + + if($query == null) { + return; + } + + App::import('Core', 'Sanitize'); + + $query = Sanitize::clean($query); + + $jobs = $this->Job->find('list', array( + 'conditions' => array( + 'Job.title LIKE' => '%'.$query.'%' + ),'fields' => array('Job.title'), + 'order' => array('Job.title ASC') + + + + )); + + //print_r($POs); + + foreach ($jobs as $id => $job) { + $job_list[] = array('id'=> $id, 'label' => $job); + } + + $jobs_json = json_encode($job_list); + + $this->set('jobs_json', $jobs_json); + + } + + /** * Need to fix the customer_id which hasn't been set for these 500odd records. * diff --git a/controllers/principles_controller.php b/controllers/principles_controller.php index 5b995064..6b418839 100755 --- a/controllers/principles_controller.php +++ b/controllers/principles_controller.php @@ -1,76 +1,75 @@ array('limit' => 50, 'order' => array('Principle.name' => 'asc')), - 'Enquiry' => array('limit' => 150, 'order' => array('Enquiry.id' => 'desc')) - ); + var $paginate = array( + 'Principle' => array('limit' => 50, 'order' => array('Principle.name' => 'asc')), + 'Enquiry' => array('limit' => 150, 'order' => array('Enquiry.id' => 'desc')) + ); - function index() { - $this->Principle->recursive = 0; - $this->set('principles', $this->paginate()); - $this->set('enquiries', $this->paginate()); + function index() { + $this->Principle->recursive = 0; + $this->set('principles', $this->paginate()); + $this->set('enquiries', $this->paginate()); + } + + function view($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid Principle.', true)); + $this->redirect(array('action'=>'index')); } - - function view($id = null) { - if (!$id) { - $this->Session->setFlash(__('Invalid Principle.', true)); - $this->redirect(array('action'=>'index')); - } - $this->set('principle', $this->Principle->read(null, $id)); - $this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.principle_id' => $id))); - $this->set('addresses', $this->Principle->PrincipleAddress->findAllByPrincipleId($id)); - $this->set('principleContacts', $this->Principle->PrincipleContact->find('all', array('conditions'=>array('PrincipleContact.principle_id'=>$id)))); - $statuses = $this->Principle->Enquiry->Status->find('all'); - $status_list = array(); - foreach ($statuses as $status) { - $status_list[] = array($status['Status']['id'], $status['Status']['name']); - } - $this->set('status_list', $status_list); - $this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.principle_id' => $id))); - + $this->set('principle', $this->Principle->read(null, $id)); + $this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.principle_id' => $id))); + $this->set('addresses', $this->Principle->PrincipleAddress->findAllByPrincipleId($id)); + $this->set('principleContacts', $this->Principle->PrincipleContact->find('all', array('conditions'=>array('PrincipleContact.principle_id'=>$id)))); + $statuses = $this->Principle->Enquiry->Status->find('all'); + $status_list = array(); + foreach ($statuses as $status) { + $status_list[] = array($status['Status']['id'], $status['Status']['name']); } + $this->set('status_list', $status_list); + $this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.principle_id' => $id))); - function add() { - if (!empty($this->data)) { - $this->Principle->create(); - if ($this->Principle->save($this->data)) { - $this->Session->setFlash(__('The Principle has been saved', true)); - $this->redirect(array('action'=>'index')); - } else { - $this->Session->setFlash(__('The Principle could not be saved. Please, try again.', true)); - } - } - $countries = $this->Principle->Country->find('list'); - $currencies = $this->Principle->Currency->find('list'); - $this->set(compact('countries', 'currencies')); + } + + function add() { + if (!empty($this->data)) { + $this->Principle->create(); + if ($this->Principle->save($this->data)) { + $this->Session->setFlash(__('The Principle has been saved', true)); + $this->redirect(array('action'=>'index')); + } else { + $this->Session->setFlash(__('The Principle could not be saved. Please, try again.', true)); + } } + $countries = $this->Principle->Country->find('list'); + $currencies = $this->Principle->Currency->find('list'); + $this->set(compact('countries', 'currencies')); + } - function edit($id = null) { - if (!$id && empty($this->data)) { - $this->Session->setFlash(__('Invalid Principle', true)); - $this->redirect(array('action'=>'index')); - } - if (!empty($this->data)) { - if ($this->Principle->save($this->data)) { - $this->Session->setFlash(__('The Principle has been saved', true)); - $this->redirect(array('action'=>'index')); - } else { - $this->Session->setFlash(__('The Principle could not be saved. Please, try again.', true)); - } - } - if (empty($this->data)) { - $this->data = $this->Principle->read(null, $id); - } - $countries = $this->Principle->Country->find('list'); - $currencies = $this->Principle->Currency->find('list'); - $this->set(compact('countries','currencies')); + function edit($id = null) { + if (!$id && empty($this->data)) { + $this->Session->setFlash(__('Invalid Principle', true)); + $this->redirect(array('action'=>'index')); } + if (!empty($this->data)) { + if ($this->Principle->save($this->data)) { + $this->Session->setFlash(__('The Principle has been saved', true)); + $this->redirect(array('action'=>'index')); + } else { + $this->Session->setFlash(__('The Principle could not be saved. Please, try again.', true)); + } + } + if (empty($this->data)) { + $this->data = $this->Principle->read(null, $id); + } + $countries = $this->Principle->Country->find('list'); + $currencies = $this->Principle->Currency->find('list'); + $this->set(compact('countries','currencies')); + } - } ?> diff --git a/controllers/purchase_orders_controller.php b/controllers/purchase_orders_controller.php index a5117bbb..07e428c1 100755 --- a/controllers/purchase_orders_controller.php +++ b/controllers/purchase_orders_controller.php @@ -1,84 +1,125 @@ false, - 'limit' => 100, - 'order'=>array('PurchaseOrder.id' => 'desc') + 'contain' => false, + 'limit' => 100, + 'order'=>array('PurchaseOrder.id' => 'desc') ); - function index() { - $this->PurchaseOrder->recursive = 1; - $this->set('purchaseOrders', $this->paginate()); + function index() { + $this->PurchaseOrder->recursive = 1; + $this->set('purchaseOrders', $this->paginate()); + } + + function view($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid PurchaseOrder.', true)); + $this->redirect(array('action'=>'index')); + } + $this->set('purchaseOrder', $this->PurchaseOrder->read(null, $id)); + } + + function add() { + if (!empty($this->data)) { + $this->PurchaseOrder->create(); + + $count = $this->PurchaseOrder->findCount(); + $count++; + + $offset = 2060; + + $count += $offset; + + $newPOnumber = "CMCPO".$count; + + $this->data['PurchaseOrder']['title'] = $newPOnumber; + + + if ($this->PurchaseOrder->save($this->data)) { + $this->Session->setFlash(__('The PurchaseOrder has been saved', true)); + $this->redirect(array('action'=>'index')); + } else { + $this->Session->setFlash(__('The PurchaseOrder could not be saved. Please, try again.', true)); + } + } + $jobs = $this->PurchaseOrder->Job->find('list'); + $principles = $this->PurchaseOrder->Principle->find('list'); + $documents = $this->PurchaseOrder->Document->find('list'); + $this->set(compact('jobs', 'principles', 'documents')); + } + + function edit($id = null) { + if (!$id && empty($this->data)) { + $this->Session->setFlash(__('Invalid PurchaseOrder', true)); + $this->redirect(array('action'=>'index')); + } + if (!empty($this->data)) { + if ($this->PurchaseOrder->save($this->data)) { + $this->Session->setFlash(__('The PurchaseOrder has been saved', true)); + $this->redirect(array('action'=>'index')); + } else { + $this->Session->setFlash(__('The PurchaseOrder could not be saved. Please, try again.', true)); + } + } + if (empty($this->data)) { + $this->data = $this->PurchaseOrder->read(null, $id); + } + $jobs = $this->PurchaseOrder->Job->find('list'); + $principles = $this->PurchaseOrder->Principle->find('list'); + $documents = $this->PurchaseOrder->Document->find('list'); + $this->set(compact('jobs','principles','documents')); + } + + + function autocomplete() { + $this->layout = 'ajax'; + + $query = strtolower($_GET["term"]); + + //$this->set('customers_json', print_r($this->data)); + + if($query == null) { + return; } - function view($id = null) { - if (!$id) { - $this->Session->setFlash(__('Invalid PurchaseOrder.', true)); - $this->redirect(array('action'=>'index')); - } - $this->set('purchaseOrder', $this->PurchaseOrder->read(null, $id)); + App::import('Core', 'Sanitize'); + + $query = Sanitize::clean($query); + + $POs = $this->PurchaseOrder->find('list', array( + 'conditions' => array( + 'PurchaseOrder.title LIKE' => '%'.$query.'%' + ),'fields' => array('PurchaseOrder.title'), + 'order' => array('PurchaseOrder.title ASC') + + + + )); + + //print_r($POs); + + foreach ($POs as $id => $po) { + $po_list[] = array('id'=> $id, 'label' => $po); } - function add() { - if (!empty($this->data)) { - $this->PurchaseOrder->create(); + $POs_json = json_encode($po_list); - $count = $this->PurchaseOrder->findCount(); - $count++; + $this->set('POs_json', $POs_json); - $offset = 2060; - - $count += $offset; - - $newPOnumber = "CMCPO".$count; - - $this->data['PurchaseOrder']['title'] = $newPOnumber; + } - if ($this->PurchaseOrder->save($this->data)) { - $this->Session->setFlash(__('The PurchaseOrder has been saved', true)); - $this->redirect(array('action'=>'index')); - } else { - $this->Session->setFlash(__('The PurchaseOrder could not be saved. Please, try again.', true)); - } - } - $jobs = $this->PurchaseOrder->Job->find('list'); - $principles = $this->PurchaseOrder->Principle->find('list'); - $documents = $this->PurchaseOrder->Document->find('list'); - $this->set(compact('jobs', 'principles', 'documents')); - } - function edit($id = null) { - if (!$id && empty($this->data)) { - $this->Session->setFlash(__('Invalid PurchaseOrder', true)); - $this->redirect(array('action'=>'index')); - } - if (!empty($this->data)) { - if ($this->PurchaseOrder->save($this->data)) { - $this->Session->setFlash(__('The PurchaseOrder has been saved', true)); - $this->redirect(array('action'=>'index')); - } else { - $this->Session->setFlash(__('The PurchaseOrder could not be saved. Please, try again.', true)); - } - } - if (empty($this->data)) { - $this->data = $this->PurchaseOrder->read(null, $id); - } - $jobs = $this->PurchaseOrder->Job->find('list'); - $principles = $this->PurchaseOrder->Principle->find('list'); - $documents = $this->PurchaseOrder->Document->find('list'); - $this->set(compact('jobs','principles','documents')); - } - /*function delete($id = null) { + /*function delete($id = null) { if (!$id) { $this->Session->setFlash(__('Invalid id for PurchaseOrder', true)); $this->redirect(array('action'=>'index')); diff --git a/controllers/shipments_controller.php b/controllers/shipments_controller.php index ffee1135..61474617 100644 --- a/controllers/shipments_controller.php +++ b/controllers/shipments_controller.php @@ -17,6 +17,13 @@ class ShipmentsController extends AppController { 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) { @@ -27,27 +34,46 @@ class ShipmentsController extends AppController { $this->set('shipment', $this->Shipment->read(null, $id)); } - - - - - function add($action = 'add') { - - $jobs = $this->Shipment->Job->find('list'); - $principles = $this->Shipment->Principle->find('list'); - $purchaseOrders = $this->Shipment->PurchaseOrder->find('list'); - $freightForwarders = $this->Shipment->FreightForwarder->find('list'); - $shipmentType = $this->typeOptions(); - - $this->set(compact('jobs', 'principles', 'purchaseOrders', 'freightForwarders', 'shipmentType')); + function ajax_edit() { + $this->layout = 'ajax'; + + if(!empty($this->data)) { + if ($this->Shipment->saveAll($this->data)) { + echo "SUCCESS"; + } + else { + echo "FAILURE"; + } + } + else { + return; + } } - function typeOptions() { - $options = array('','Import to CMC','Direct: Principle to Customer','Export','Local'); + + /* 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; } diff --git a/models/shipment.php b/models/shipment.php index 3328c13f..a975a144 100644 --- a/models/shipment.php +++ b/models/shipment.php @@ -21,7 +21,13 @@ class Shipment extends AppModel { 'FreightService' => array( 'className' => 'FreightService', 'foreignKey' => 'freight_service_id' + ), + 'User' => array( + 'className' => 'User', + 'foreignKey' => 'user_id', + 'conditions' => array('User.type' => 'user') ) + ); var $hasMany = array( diff --git a/views/layouts/default.ctp b/views/layouts/default.ctp index 50145b75..23367771 100755 --- a/views/layouts/default.ctp +++ b/views/layouts/default.ctp @@ -78,7 +78,6 @@
| sort('user_id');?> | sort('date_arrived');?> | sort('date_dispatched');?> | sort('type');?> | @@ -28,16 +29,26 @@ foreach ($shipments as $shipment): ?>||||
|---|---|---|---|---|---|---|---|
| + + $initials = $shipment['User']['first_name'][0].$shipment['User']['last_name'][0]; - | - - | -- + echo $html->link($initials, array('controller'=> 'users', 'action'=>'view', $shipment['User']['id'])); ?> | - + element('isEmptyDate', array('date'=>$shipment['Shipment']['date_arrived'])); + ?> + | ++ element('isEmptyDate', array('date'=>$shipment['Shipment']['date_dispatched'])); + ?> + | + ++ | @@ -83,9 +94,7 @@ | - link(__('View', true), array('action' => 'view', $shipment['Shipment']['id'])); ?> - link(__('Edit', true), array('action' => 'edit', $shipment['Shipment']['id'])); ?> - link(__('Delete', true), array('action' => 'delete', $shipment['Shipment']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $shipment['Shipment']['id'])); ?> + |