cmc-sales/controllers/quote_products_controller.php
Karl Cordes 4347aee5f0 Changes
2009-11-04 17:12:12 +11:00

121 lines
3.8 KiB
PHP
Executable file

<?php
class QuoteProductsController extends AppController {
var $name = 'QuoteProducts';
var $helpers = array('Html', 'Form');
function index() {
$this->QuoteProduct->recursive = 0;
$this->set('quoteProducts', $this->paginate());
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid QuoteProduct.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('quoteProduct', $this->QuoteProduct->read(null, $id));
}
function add($quoteid = null) {
if (!$quoteid && empty($this->data)) {
$this->Session->setFlash(__('Invalid Quote ID', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
$this->QuoteProduct->create();
$product = $this->QuoteProduct->Product->findById($this->data['QuoteProduct']['product_id']);
$this->data['QuoteProduct']['description'] = $product['Product']['description'];
if ($this->QuoteProduct->save($this->data)) {
$quoteid = $this->data['QuoteProduct']['quote_id'];
$this->Session->setFlash(__('Product Added to Quote Successfully', true));
$this->redirect(array('controller'=>'quotes', 'action'=>'view', $quoteid));
} else {
$this->Session->setFlash(__('The QuoteProduct could not be saved. Please, try again.', true));
}
}
$principles = $this->QuoteProduct->Product->Principle->find('list');
$currencies = $this->QuoteProduct->Currency->find('list');
$quote = $this->QuoteProduct->Quote->read(null, $quoteid);
$this->set(compact('principles', 'currencies', 'quote', 'products'));
}
/* Display a list of Products for a given principle. Used for the add() method */
function principle_products() {
if (empty($this->data['QuoteProduct']['principle_id'])) {
}
else {
$this->set('products', $this->QuoteProduct->Product->find('list', array('conditions'=>array('Product.principle_id'=>$this->data['QuoteProduct']['principle_id']))));
}
}
/* Display a list of Options (if any) for a given Product. Used for the add() method */
function product_options() {
/*$this->set('categories', $this->QuoteProduct->Product->ProductOptionsCategory->find('list'),
array('conditions' => array('ProductOptionsCategory.product_id'=>$this->data['QuoteProduct']['product_id']),
'order'=>'ProductOptionsCategory.location ASC') );*/
$this->set('options', $this->QuoteProduct->Product->ProductOptionsCategory->find('all',
array('conditions' => array('ProductOptionsCategory.product_id'=>$this->data['QuoteProduct']['product_id']),
'order'=>'ProductOptionsCategory.location ASC')));
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid QuoteProduct', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->QuoteProduct->save($this->data)) {
$this->Session->setFlash(__('The QuoteProduct has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The QuoteProduct could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->QuoteProduct->read(null, $id);
}
$principles = $this->QuoteProduct->Principle->find('list');
$currencies = $this->QuoteProduct->Currency->find('list');
$quotes = $this->QuoteProduct->Quote->find('list');
$products = $this->QuoteProduct->Product->find('list');
$this->set(compact('principles','currencies','quotes','products'));
}
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for QuoteProduct', true));
$this->redirect(array('action'=>'index'));
}
if ($this->QuoteProduct->del($id)) {
$this->Session->setFlash(__('QuoteProduct deleted', true));
$this->redirect(array('action'=>'index'));
}
}
}
?>