cmc-sales/controllers/costings_controller.php
2009-11-20 15:46:23 +11:00

72 lines
2.3 KiB
PHP
Executable file

<?php
class CostingsController extends AppController {
var $name = 'Costings';
var $helpers = array('Html', 'Form');
function index() {
$this->Costing->recursive = 0;
$this->set('costings', $this->paginate());
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Costing.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('costing', $this->Costing->read(null, $id));
}
function add() {
if (!empty($this->data)) {
$this->Costing->create();
if ($this->Costing->save($this->data)) {
$this->Session->setFlash(__('The Costing has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Costing could not be saved. Please, try again.', true));
}
}
$products = $this->Costing->Product->find('list');
$quoteProducts = $this->Costing->QuoteProduct->find('list');
$purchaseCurrencies = $this->Costing->PurchaseCurrency->find('list');
$saleCurrencies = $this->Costing->SaleCurrency->find('list');
$this->set(compact('products', 'quoteProducts', 'purchaseCurrencies', 'saleCurrencies'));
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Costing', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->Costing->save($this->data)) {
$this->Session->setFlash(__('The Costing has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Costing could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Costing->read(null, $id);
}
$products = $this->Costing->Product->find('list');
$quoteProducts = $this->Costing->QuoteProduct->find('list');
$purchaseCurrencies = $this->Costing->PurchaseCurrency->find('list');
$saleCurrencies = $this->Costing->SaleCurrency->find('list');
$this->set(compact('products','quoteProducts','purchaseCurrencies','saleCurrencies'));
}
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for Costing', true));
$this->redirect(array('action'=>'index'));
}
if ($this->Costing->del($id)) {
$this->Session->setFlash(__('Costing deleted', true));
$this->redirect(array('action'=>'index'));
}
}
}
?>