2010-07-16 00:52:57 -07:00
|
|
|
<?php
|
|
|
|
|
class PurchaseOrdersController extends AppController {
|
|
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
var $name = 'PurchaseOrders';
|
|
|
|
|
var $helpers = array('Html', 'Form', 'Javascript');
|
2010-07-16 00:52:57 -07:00
|
|
|
|
2010-09-06 20:57:28 -07:00
|
|
|
|
|
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
var $paginate = array(
|
2010-09-06 20:57:28 -07:00
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
'contain' => false,
|
|
|
|
|
'limit' => 100,
|
|
|
|
|
'order'=>array('PurchaseOrder.id' => 'desc')
|
2010-09-06 20:57:28 -07:00
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
function index() {
|
|
|
|
|
$this->PurchaseOrder->recursive = 1;
|
|
|
|
|
$this->set('purchaseOrders', $this->paginate());
|
|
|
|
|
}
|
2010-07-16 00:52:57 -07:00
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
function view($id = null) {
|
|
|
|
|
if (!$id) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid PurchaseOrder.', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
2010-07-16 00:52:57 -07:00
|
|
|
}
|
2011-04-28 00:41:36 -07:00
|
|
|
$this->set('purchaseOrder', $this->PurchaseOrder->read(null, $id));
|
|
|
|
|
}
|
2010-07-16 00:52:57 -07:00
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
function add() {
|
|
|
|
|
if (!empty($this->data)) {
|
|
|
|
|
$this->PurchaseOrder->create();
|
2010-07-16 00:52:57 -07:00
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
$count = $this->PurchaseOrder->findCount();
|
|
|
|
|
$count++;
|
2010-07-16 00:52:57 -07:00
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
$offset = 2060;
|
2010-07-16 00:52:57 -07:00
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
$count += $offset;
|
2010-07-16 00:52:57 -07:00
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
$newPOnumber = "CMCPO".$count;
|
2010-07-16 00:52:57 -07:00
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
$this->data['PurchaseOrder']['title'] = $newPOnumber;
|
2010-07-16 00:52:57 -07:00
|
|
|
|
|
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
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);
|
2010-07-16 00:52:57 -07:00
|
|
|
}
|
2011-04-28 00:41:36 -07:00
|
|
|
$jobs = $this->PurchaseOrder->Job->find('list');
|
|
|
|
|
$principles = $this->PurchaseOrder->Principle->find('list');
|
|
|
|
|
$documents = $this->PurchaseOrder->Document->find('list');
|
|
|
|
|
$this->set(compact('jobs','principles','documents'));
|
|
|
|
|
}
|
2010-07-16 00:52:57 -07:00
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
|
|
|
|
|
function autocomplete() {
|
|
|
|
|
$this->layout = 'ajax';
|
|
|
|
|
|
|
|
|
|
$query = strtolower($_GET["term"]);
|
|
|
|
|
|
|
|
|
|
//$this->set('customers_json', print_r($this->data));
|
|
|
|
|
|
|
|
|
|
if($query == null) {
|
|
|
|
|
return;
|
2010-07-16 00:52:57 -07:00
|
|
|
}
|
|
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$POs_json = json_encode($po_list);
|
|
|
|
|
|
|
|
|
|
$this->set('POs_json', $POs_json);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*function delete($id = null) {
|
2010-07-16 00:52:57 -07:00
|
|
|
if (!$id) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid id for PurchaseOrder', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
if ($this->PurchaseOrder->del($id)) {
|
|
|
|
|
$this->Session->setFlash(__('PurchaseOrder deleted', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
?>
|