cmc-sales/controllers/products_controller.php

132 lines
4.4 KiB
PHP
Raw Normal View History

<?php
class ProductsController extends AppController {
2009-12-16 12:50:48 -08:00
var $name = 'Products';
var $components = array('RequestHandler');
var $helpers = array('Html', 'Form', 'Ajax', 'Number');
2009-12-16 12:50:48 -08:00
function index() {
2010-01-10 10:05:04 -08:00
/*$this->Product->recursive = 0;
2009-12-16 12:50:48 -08:00
$this->set('products', $this->paginate());
2010-01-10 10:05:04 -08:00
*
*/
$this->set('principles', $this->Product->Principle->find('all', array('order' => 'Principle.name ASC')));
}
function view_principle($id = null) {
if(!$id) {
$this->Session->setFlash(__('Invalid Principle ID', true));
$this->redirect(array('action'=>'index'));
}
$this->set('products', $this->Product->find('all', array('conditions'=>array('Product.principle_id'=>$id))));
2010-01-10 10:05:04 -08:00
$this->set('principle', $this->Product->Principle->findById($id));
2009-12-16 12:50:48 -08:00
}
2009-12-16 12:50:48 -08:00
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Product.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('product', $this->Product->read(null, $id));
2009-12-16 12:50:48 -08:00
//$this->set('product', $this->Product->find('first', array('conditions' => array('Product.id'=>$id), 'recursive' => 1)));
2009-12-16 12:50:48 -08:00
$this->set('options', $this->Product->ProductOptionsCategory->find('all', array('conditions' => array('ProductOptionsCategory.product_id'=>$id), 'order'=>'ProductOptionsCategory.location ASC')));
2009-12-16 12:50:48 -08:00
$this->set('files', $this->Product->ProductAttachment->findAllByProductId($id));
$this->set('number_of_files', $this->Product->ProductAttachment->find('count', array('conditions' => array('ProductAttachment.product_id'=>$id))));
}
2009-12-16 12:50:48 -08:00
function add() {
if (!empty($this->data)) {
$this->Product->create();
2009-12-16 12:50:48 -08:00
if ($this->Product->save($this->data)) {
$this->Session->setFlash(__('The Product has been saved', true));
$id = $this->Product->id;
$this->redirect(array('action'=>'view/'.$id));
} else {
$this->Session->setFlash(__('The Product could not be saved. Please, try again.', true));
}
}
$principles = $this->Product->Principle->find('list');
$this->set(compact('principles', 'product_categories'));
}
function add_costing() {
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Product', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->Product->save($this->data)) {
$this->Session->setFlash(__('The Product has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Product could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Product->read(null, $id);
$this->set('description', $this->data['Product']['description']);
}
$principles = $this->Product->Principle->find('list');
$this->set(compact('principles'));
}
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for Product', true));
$this->redirect(array('action'=>'index'));
}
if ($this->Product->del($id)) {
$this->Session->setFlash(__('Product deleted', true));
$this->redirect(array('action'=>'index'));
}
}
2010-02-18 21:38:43 -08:00
/**
*
* Outputs a select box with the Products that belong to a particular principal. Perhaps will change to an autocomplete in the future.
*/
function getPrincipleProducts() {
if(empty($this->data)) {
return;
}
2010-02-18 21:38:43 -08:00
else {
$this->set('products', $this->Product->find('list', array('conditions' =>
array('Product.principle_id'=> $this->data['LineItem']['principle_id']))));
2010-02-18 21:38:43 -08:00
}
}
function getProductOptions() {
if(empty($this->data)) {
return;
}
else {
$this->set('options', $this->Product->ProductOptionsCategory->find('all', array('conditions' => array('ProductOptionsCategory.product_id'=>$this->data['LineItem']['product_id']), 'order'=>'ProductOptionsCategory.location ASC')));
2010-02-18 21:38:43 -08:00
}
}
}
?>