2009-01-12 21:13:18 -08:00
|
|
|
<?php
|
|
|
|
|
class QuotesController extends AppController {
|
|
|
|
|
|
|
|
|
|
var $name = 'Quotes';
|
2009-08-13 19:09:47 -07:00
|
|
|
var $helpers = array('Html', 'Form','Ajax');
|
|
|
|
|
|
|
|
|
|
var $components = array('RequestHandler');
|
2009-01-12 21:13:18 -08:00
|
|
|
|
|
|
|
|
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'));
|
|
|
|
|
}
|
2009-09-09 20:23:39 -07:00
|
|
|
$quote = $this->Quote->read(null, $id);
|
|
|
|
|
$this->set('quote', $quote);
|
|
|
|
|
$this->set('customer', $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id']));
|
2009-01-12 21:13:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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');
|
2009-01-12 21:13:18 -08:00
|
|
|
|
|
|
|
|
if ($this->Quote->save($this->data)) {
|
|
|
|
|
$quoteid = $this->Quote->id;
|
2009-08-13 19:09:47 -07:00
|
|
|
|
|
|
|
|
$this->Quote->QuotePage->create();
|
|
|
|
|
$this->data['QuotePage']['quote_id'] = $quoteid;
|
|
|
|
|
$this->data['QuotePage']['page_number'] = '1';
|
|
|
|
|
|
|
|
|
|
$this->Quote->QuotePage->save($this->data);
|
|
|
|
|
|
2009-01-12 21:13:18 -08:00
|
|
|
$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);
|
2009-01-12 21:13:18 -08:00
|
|
|
} 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-12 21:13:18 -08:00
|
|
|
}
|
2009-01-26 17:46:00 -08:00
|
|
|
$enquiry = $this->Quote->Enquiry->findById($quote['Quote']['enquiry_id']);
|
|
|
|
|
$this->set(compact('enquiry', 'quote'));
|
2009-01-12 21:13:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-10-08 01:42:23 -07:00
|
|
|
function pdf($id = null) {
|
|
|
|
|
if(!$id) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid Quote', true));
|
|
|
|
|
$this->redirect(array('controller'=>'enquiries', 'action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
$quote = $this->Quote->findAllById($id);
|
|
|
|
|
//$this->set('quote', $quote);
|
|
|
|
|
$this->layout = 'pdf';
|
|
|
|
|
$this->render();
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-12 21:13:18 -08:00
|
|
|
}
|
2009-09-09 20:23:39 -07:00
|
|
|
|
2009-01-12 21:13:18 -08:00
|
|
|
?>
|