2009-11-16 14:24:53 -08:00
|
|
|
<?php
|
|
|
|
|
class CostingsController extends AppController {
|
|
|
|
|
|
2009-11-17 14:42:42 -08:00
|
|
|
var $name = 'Costings';
|
2010-01-30 23:57:51 -08:00
|
|
|
var $helpers = array('Html', 'Form', 'Javascript');
|
2009-11-16 14:24:53 -08:00
|
|
|
|
2009-11-17 14:42:42 -08:00
|
|
|
function index() {
|
|
|
|
|
$this->Costing->recursive = 0;
|
|
|
|
|
$this->set('costings', $this->paginate());
|
|
|
|
|
}
|
2009-11-16 14:24:53 -08:00
|
|
|
|
2009-11-17 14:42:42 -08:00
|
|
|
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));
|
|
|
|
|
}
|
2009-11-16 14:24:53 -08:00
|
|
|
|
2009-11-17 14:42:42 -08:00
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-05 01:42:35 -07:00
|
|
|
if(isset($this->params['named']['productid'])) {
|
|
|
|
|
$product = $this->Costing->Product->findById($this->params['named']['productid']);
|
2010-03-30 21:09:27 -07:00
|
|
|
|
2013-05-05 01:42:35 -07:00
|
|
|
$this->set('type', 'product');
|
|
|
|
|
$this->set('product', $product);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(isset($this->params['named']['line_item_id'])) {
|
|
|
|
|
$line_item = $this->Costing->LineItem->findById($this->params['named']['line_item_id']);
|
|
|
|
|
|
|
|
|
|
$this->set('type', 'line_item');
|
|
|
|
|
$this->set('line_item', $line_item);
|
|
|
|
|
die(print_r($line_item));
|
|
|
|
|
}
|
2010-03-30 21:09:27 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-17 14:42:42 -08:00
|
|
|
$purchaseCurrencies = $this->Costing->PurchaseCurrency->find('list');
|
|
|
|
|
$saleCurrencies = $this->Costing->SaleCurrency->find('list');
|
2010-03-30 21:09:27 -07:00
|
|
|
$this->set(compact('purchaseCurrencies', 'saleCurrencies'));
|
2009-11-17 14:42:42 -08:00
|
|
|
}
|
2009-11-16 14:24:53 -08:00
|
|
|
|
2009-11-17 14:42:42 -08:00
|
|
|
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');
|
2010-01-30 23:57:51 -08:00
|
|
|
$lineItems = $this->Costing->LineItem->find('list');
|
2009-11-17 14:42:42 -08:00
|
|
|
$purchaseCurrencies = $this->Costing->PurchaseCurrency->find('list');
|
|
|
|
|
$saleCurrencies = $this->Costing->SaleCurrency->find('list');
|
2010-01-30 23:57:51 -08:00
|
|
|
$this->set(compact('products','lineItems','purchaseCurrencies','saleCurrencies'));
|
2009-11-17 14:42:42 -08:00
|
|
|
}
|
2009-11-16 14:24:53 -08:00
|
|
|
|
2009-11-17 14:42:42 -08:00
|
|
|
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'));
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-11-16 14:24:53 -08:00
|
|
|
|
|
|
|
|
}
|
2013-05-05 01:42:35 -07:00
|
|
|
?>
|