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')); } if (empty($this->data)) { $quote = $this->Quote->read(null, $id); $this->data = $quote; $this->set('quote', $quote); } $quoteProducts = $this->Quote->LineItem->find('all', array('recursive' => 0, 'conditions' => array('LineItem.quote_id' => $id), 'order' => array('LineItem.item_number ASC')) ); $this->set('customer', $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id'])); $this->set('quoteProducts', $quoteProducts); $currencies = $this->Quote->Currency->find('list'); $this->set('currencies', $currencies); $this->set('principles', $this->Quote->Enquiry->Principle->find('list')); } 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'); $this->data['Quote']['currency_id'] = 2; /** * @todo Fix this hard coded default currency. Currently set to '2' for AUD. */ 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)) { $issuedate = $this->data['Quote']['date_issued']; $issuedate = $issuedate['year'].'-'.$issuedate['month'].'-'.$issuedate['day']; $validUntilDate = strtotime($issuedate."+ ".$this->data['Quote']['days_valid']." days"); $this->data['Quote']['valid_until'] = date('Y-m-d', $validUntilDate); 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']); $currencies = $this->Quote->Currency->find('list'); $this->set(compact('enquiry', 'quote', 'currencies')); } function pdf($id = null) { Configure::write('debug',1); if(!$id) { $this->Session->setFlash(__('Invalid Quote', true)); $this->redirect(array('controller'=>'enquiries', 'action'=>'index')); } $quote = $this->Quote->findById($id); //$customer = $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id']); $enquiry = $this->Quote->Enquiry->find('first', array('conditions' => array('Enquiry.id' => $quote['Quote']['enquiry_id']))); $quoteProducts = $this->Quote->LineItem->find('all', array('recursive' => 0, 'conditions' => array('LineItem.quote_id' => $id), 'order' => array('LineItem.item_number ASC')) ); $user = $this->Quote->Enquiry->User->find('first', array('conditions' => array('User.id' => $enquiry['Enquiry']['user_id']))); /** * Call the commercial Comments. Need to have already figured out what page to do this on.. * * * Passing a data structure in the following format. * * $details = array( * 'deliveryTime' => (String) eg. 2-3 * 'paymentTerms => (String) eg. 100% PAYMENT WITH ORDER || NET 30 DAYS FOR APPROVED ACCOUNTS * 'daysValid' => (Int) eg. 30 * 'deliveryPoint' => (String) eg. EX-CMC Technologies, NSW. || EX-SUPPLIER NAME * 'exchangeRate' => (String) eg. FIXED * 'customsDuty' => (String) eg. NIL || 5% * 'gst' => (String) eg. 10% EXTRA || Not Applicable for Export * 'salesEngineer' => (String) eg. Karl Cordes || Con Carpis || Kenan Fernandes etc * ); * * */ if($enquiry['Enquiry']['gst'] == 1) { $gstPhrase = "10% EXTRA"; } else { $gstPhrase = "Not Applicable for Export"; } $commercialDetails = array ( 'deliveryTime' => strtoupper($quote['Quote']['delivery_time']), 'paymentTerms' => strtoupper($quote['Quote']['payment_terms']), 'validFor' => $quote['Quote']['days_valid'], 'deliveryPoint' => strtoupper($quote['Quote']['delivery_point']), 'exchangeRate' => strtoupper($quote['Quote']['exchange_rate']), 'customsDuty' => strtoupper($quote['Quote']['customs_duty']), 'gst' => strtoupper($gstPhrase), 'salesEngineer' => strtoupper($user['User']['first_name'].' '.$user['User']['last_name']) ); $this->set('commercialDetails', $commercialDetails); debug($quote); debug($commercialDetails); $this->set('quote', $quote); $this->set('enquiry', $enquiry); $this->set('products', $quoteProducts); } } ?>