cmc-sales/controllers/quotes_controller.php

110 lines
3.4 KiB
PHP
Raw Normal View History

<?php
class QuotesController extends AppController {
var $name = 'Quotes';
var $helpers = array('Html', 'Form','Ajax');
var $components = array('RequestHandler');
function index() {
$this->Quote->recursive = 0;
$this->set('quotes', $this->paginate());
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Quote.', true));
$this->redirect(array('action'=>'index'));
}
$quote = $this->Quote->read(null, $id);
$this->set('quote', $quote);
2009-11-15 19:31:10 -08:00
$quoteProducts = $this->Quote->QuoteProduct->find('all', array('recursive' => 0, 'conditions' => array('QuoteProduct.quote_id' => $id),
'order' => array('QuoteProduct.item_number ASC'))
);
$this->set('customer', $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id']));
2009-11-15 19:31:10 -08:00
$this->set('quoteProducts', $quoteProducts);
}
function add() {
if(isset($this->params['named']['enquiryid'])) {
$enquiryid = $this->params['named']['enquiryid'];
$this->Quote->create();
$number_of_revisions = $this->Quote->findCount('Quote.enquiry_id ='. $enquiryid);
$this->data['Quote']['revision'] = $number_of_revisions;
$this->data['Quote']['enquiry_id'] = $enquiryid;
2009-01-18 21:06:41 -08:00
$this->data['Quote']['date_issued'] = date('Y-m-d');
if ($this->Quote->save($this->data)) {
$quoteid = $this->Quote->id;
$this->Quote->QuotePage->create();
$this->data['QuotePage']['quote_id'] = $quoteid;
$this->data['QuotePage']['page_number'] = '1';
$this->Quote->QuotePage->save($this->data);
$this->Session->setFlash(__('The Quote has been saved', true));
$this->redirect(array('action'=>'view/'.$quoteid));
}
else {
$this->Session->setFlash(__('The Quote was not saved. Something has gone wrong.', true));
$this->redirect(array('action'=>'index'));
}
}
else {
$this->Session->setFlash(__('Invalid Enquiry ID', true));
$this->redirect(array('controller'=>'enquiries','action'=>'index'));
}
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Quote', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->Quote->save($this->data)) {
$this->Session->setFlash(__('The Quote has been saved', true));
2009-01-26 17:46:00 -08:00
$thisquote = $this->Quote->id;
$this->redirect(array('action' =>'view/'.$id), null, false);
} else {
$this->Session->setFlash(__('The Quote could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
2009-01-26 17:46:00 -08:00
$quote = $this->Quote->read(null, $id);
$this->data = $quote;
}
2009-01-26 17:46:00 -08:00
$enquiry = $this->Quote->Enquiry->findById($quote['Quote']['enquiry_id']);
$this->set(compact('enquiry', 'quote'));
}
function pdf($id = null) {
2009-10-10 00:06:46 -07:00
Configure::write('debug',0);
if(!$id) {
$this->Session->setFlash(__('Invalid Quote', true));
$this->redirect(array('controller'=>'enquiries', 'action'=>'index'));
}
2009-10-15 23:43:17 -07:00
$quote = $this->Quote->findById($id);
//$customer = $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id']);
$enquiry = $this->Quote->Enquiry->findById($quote['Quote']['enquiry_id']);
$this->set('quote', $quote);
$this->set('enquiry', $enquiry);
// $this->set('customer', $customer);
2009-10-10 00:06:46 -07:00
//$this->layout = 'pdf';
//$this->render();
}
}
2009-10-10 00:06:46 -07:00
?>