working towards quote building

This commit is contained in:
Karl Cordes 2009-11-17 09:24:53 +11:00
parent 7e1902089c
commit 265ff9354b
5 changed files with 148 additions and 103 deletions

View file

@ -0,0 +1,38 @@
<?php
class CostingsController extends AppController {
var $name = 'Costings';
var $helpers = array('Html', 'Form','Ajax');
var $components = array('RequestHandler');
function index() {
$this->Costings->recursive = 0;
$this->set('costings', $this->paginate());
}
/**
* Add a costing to a product. It's either being added to a product, quote_product etc.
*
*
* @param int $id
* @param string $target
*/
function add($id, $target) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Quote ID', true));
$this->redirect(array('action'=>'index'));
}
}
}
?>

View file

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

View file

@ -36,8 +36,10 @@ class QuoteProduct extends AppModel {
var $hasOne = array( var $hasOne = array(
'Costing' => array('className' => 'Costing', 'Costing' => array('className' => 'Costing',
'foreignKey' => 'id') 'foreignKey' => 'quote_product_id')
); );
var $order = "item_number ASC"; var $order = "item_number ASC";

View file

@ -9,6 +9,8 @@
echo $form->input('quantity', array('class' => 'required validate-number', 'title'=>'Please enter the quantity. It must be a number')); echo $form->input('quantity', array('class' => 'required validate-number', 'title'=>'Please enter the quantity. It must be a number'));
echo $form->input('option', array('label' => 'This item is optional'));
echo $form->input('principle_id', array('empty' => 'Select a Principle')); echo $form->input('principle_id', array('empty' => 'Select a Principle'));
echo $ajax->observeField('QuoteProductPrincipleId', array( echo $ajax->observeField('QuoteProductPrincipleId', array(
'url' => 'principle_products', 'url' => 'principle_products',

View file

@ -24,7 +24,7 @@ else {
?> ?>
<div class="related"> <div class="related">
<h3>Cover Page <?php echo $i; ?> </h3> <h3>Page <?php echo $i; ?> </h3>
<div class="quotepageview"> <div class="quotepageview">
<?php echo $quotePage['content']; ?> <?php echo $quotePage['content']; ?>
</div> </div>
@ -33,7 +33,7 @@ else {
<?php echo $html->link(__('Delete', true), array('controller'=> 'quote_pages', 'action'=>'delete', $quotePage['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $quotePage['id'])); ?> <?php echo $html->link(__('Delete', true), array('controller'=> 'quote_pages', 'action'=>'delete', $quotePage['id']), null, sprintf(__('Are you ABSOLUTELY sure you want to delete Page # %s? This cannot be undone.', true), $i)); ?>
</div> </div>
@ -57,7 +57,6 @@ else {
<table cellpadding = "0" cellspacing = "0"> <table cellpadding = "0" cellspacing = "0">
<tr> <tr>
<th><?php __('Item Number'); ?></th> <th><?php __('Item Number'); ?></th>
<th><?php __('Option'); ?></th>
<th><?php __('Quantity'); ?></th> <th><?php __('Quantity'); ?></th>
<th><?php __('Title'); ?></th> <th><?php __('Title'); ?></th>
<th><?php __('Description'); ?></th> <th><?php __('Description'); ?></th>
@ -75,8 +74,12 @@ else {
?> ?>
<tr<?php echo $class;?>> <tr<?php echo $class;?>>
<td><?php echo number_format($quoteProduct['QuoteProduct']['item_number'], 1, '.', '');?></td> <td><?php
<td><?php echo $quoteProduct['QuoteProduct']['option'];?></td> if($quoteProduct['QuoteProduct']['option'] == 1 ) {
echo 'Option <br>';
}
echo number_format($quoteProduct['QuoteProduct']['item_number'], 1, '.', '');?></td>
<td><?php echo $quoteProduct['QuoteProduct']['quantity'];?></td> <td><?php echo $quoteProduct['QuoteProduct']['quantity'];?></td>
<td><?php echo $quoteProduct['QuoteProduct']['title'];?></td> <td><?php echo $quoteProduct['QuoteProduct']['title'];?></td>
@ -103,4 +106,4 @@ else {
</div> </div>
<?php debug($quote); ?> <?php debug($quote); ?>