cmc-sales/php/app/controllers/purchase_orders_controller.php

129 lines
3 KiB
PHP
Raw Normal View History

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
2011-04-28 00:41:36 -07:00
var $paginate = array(
2011-04-28 00:41:36 -07:00
'contain' => false,
'limit' => 100,
'order'=>array('PurchaseOrder.id' => 'desc')
);
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'));
2011-04-28 00:41:36 -07:00
} else {
$this->Session->setFlash(__('The PurchaseOrder could not be saved. Please, try again.', true));
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'));
}
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');
$this->set(compact('jobs','principles'));
2011-04-28 00:41:36 -07:00
}
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);
}
2011-09-26 04:18:40 -07:00
function getdata($id) {
2011-09-26 04:49:36 -07:00
$this->layout = 'ajax';
2011-09-26 04:18:40 -07:00
$po = $this->PurchaseOrder->read(null, $id);
$this->set('po_json', json_encode($po));
}
2011-04-28 00:41:36 -07:00
2011-09-26 04:18:40 -07:00
2010-07-16 00:52:57 -07:00
}
?>