cmc-sales/controllers/quotes_controller.php

93 lines
2.6 KiB
PHP
Executable file

<?php
class QuotesController extends AppController {
var $name = 'Quotes';
var $helpers = array('Html', 'Form');
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'));
}
$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;
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 addold($id = null) {
if(isset($this->params['named']['enquiryid'])) {
$enquiryid = $this->params['named']['enquiryid'];
}
if (!empty($this->data)) {
$this->Quote->create();
$number_of_revisions = $this->Quote->findCount('enquiry_id ='. $this->data['Quote']['enquiry_id']);
$number_of_revisions++;
$this->data['Quote']['revision'] = $number_of_revisions;
if ($this->Quote->save($this->data)) {
$this->Session->setFlash(__('The Quote has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Quote could not be saved. Please, try again.', true));
}
}
$enquiries = $this->Quote->Enquiry->find('list');
$this->set(compact('enquiries'));
}
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));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Quote could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Quote->read(null, $id);
}
$enquiries = $this->Quote->Enquiry->find('list');
$this->set(compact('enquiries'));
}
}
?>