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')); } $this->set('quote', $this->Quote->read(null, $id)); } 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; $this->data['Quote']['date_issued'] = date('Y-m-d'); if ($this->Quote->save($this->data)) { $quoteid = $this->Quote->id; $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)); $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)) { $quote = $this->Quote->read(null, $id); $this->data = $quote; } $enquiry = $this->Quote->Enquiry->findById($quote['Quote']['enquiry_id']); $this->set(compact('enquiry', 'quote')); } } ?>