2010-05-03 23:49:57 -07:00
|
|
|
<?php
|
|
|
|
|
class InvoicesController extends AppController {
|
|
|
|
|
|
|
|
|
|
var $name = 'Invoices';
|
2011-03-13 17:21:56 -07:00
|
|
|
var $helpers = array('Html', 'Form', 'Time', 'Text','Javascript');
|
2010-05-03 23:49:57 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
var $paginate = array(
|
2010-07-15 19:45:58 -07:00
|
|
|
'limit' => 300,
|
|
|
|
|
'contain' => array('Customer'),
|
|
|
|
|
'order'=>array('Invoice.id' => 'desc')
|
2010-05-03 23:49:57 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
function index() {
|
|
|
|
|
$this->Invoice->recursive = 0;
|
|
|
|
|
$this->set('invoices', $this->paginate());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function view($id = null) {
|
|
|
|
|
if (!$id) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid Invoice.', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
2011-03-13 17:21:56 -07:00
|
|
|
$invoice = $this->Invoice->read(null, $id);
|
|
|
|
|
$this->set('invoice', $invoice);
|
|
|
|
|
|
|
|
|
|
$emailIDs = array();
|
|
|
|
|
foreach($invoice['Email'] as $email) {
|
|
|
|
|
$emailIDs[] = $email['id'];
|
|
|
|
|
}
|
|
|
|
|
$emails = $this->Invoice->Email->find('all', array('conditions'=>array('Email.id'=>$emailIDs)));
|
|
|
|
|
$this->set('emails', $emails);
|
|
|
|
|
|
|
|
|
|
|
2010-05-03 23:49:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-07-07 23:18:04 -07:00
|
|
|
function add() { //No longer creating invoices directly. Done through the Documents Controller
|
2010-05-03 23:49:57 -07:00
|
|
|
|
|
|
|
|
if (!empty($this->data)) {
|
|
|
|
|
$this->Invoice->create();
|
|
|
|
|
|
2010-05-04 00:00:46 -07:00
|
|
|
$invoice_number_offset = 4436; //What Invoice number we are up to. Starting at 4500 due to the data loss.
|
2010-05-03 23:49:57 -07:00
|
|
|
|
|
|
|
|
$number_of_invoices = $this->Invoice->findCount();
|
|
|
|
|
|
|
|
|
|
$newInvoiceNumber = $invoice_number_offset + $number_of_invoices;
|
|
|
|
|
|
|
|
|
|
$this->data['Invoice']['title'] = "CMCIN".$newInvoiceNumber;
|
|
|
|
|
|
|
|
|
|
$enqid = $this->data['Invoice']['enquiry_id'];
|
|
|
|
|
|
2010-05-17 23:45:38 -07:00
|
|
|
|
2010-05-03 23:49:57 -07:00
|
|
|
if ($this->Invoice->save($this->data)) {
|
|
|
|
|
$this->Session->setFlash(__('The Invoice has been saved', true));
|
|
|
|
|
$this->redirect(array('controller'=>'enquiries', 'action'=>'view/'.$enqid));
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The Invoice could not be saved. Please, try again.', true));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if(isset($this->params['named']['enquiryid'])) {
|
|
|
|
|
$enquiryid = $this->params['named']['enquiryid'];
|
|
|
|
|
$enquiry = $this->Invoice->Enquiry->findById($enquiryid);
|
2010-07-07 23:18:04 -07:00
|
|
|
|
2010-07-15 19:43:23 -07:00
|
|
|
$jobs = $this->Invoice->Job->find('list', array('conditions'=>array('Job.enquiry_id'=>$enquiryid)));
|
2010-05-17 23:45:38 -07:00
|
|
|
|
2010-05-03 23:49:57 -07:00
|
|
|
$user = $this->Auth->user();
|
2010-07-15 19:43:23 -07:00
|
|
|
$this->set(compact('enquiry', 'user','jobs'));
|
2010-05-03 23:49:57 -07:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$this->Session->setFlash(__('Invalid Enquiry ID', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function edit($id = null) {
|
|
|
|
|
if (!$id && empty($this->data)) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid Invoice', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
if (!empty($this->data)) {
|
|
|
|
|
if ($this->Invoice->save($this->data)) {
|
|
|
|
|
$this->Session->setFlash(__('The Invoice has been saved', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The Invoice could not be saved. Please, try again.', true));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->data)) {
|
2010-07-15 20:56:25 -07:00
|
|
|
$invoice = $this->Invoice->read(null, $id);
|
|
|
|
|
$this->data = $invoice;
|
|
|
|
|
|
2010-05-03 23:49:57 -07:00
|
|
|
}
|
2010-07-15 20:56:25 -07:00
|
|
|
|
2010-05-03 23:49:57 -07:00
|
|
|
$users = $this->Invoice->User->find('list');
|
2010-07-15 20:56:25 -07:00
|
|
|
$jobs = $this->Invoice->Job->find('list', array('conditions'=>array('Job.enquiry_id'=>$invoice['Invoice']['enquiry_id'])));
|
|
|
|
|
$this->set(compact('users', 'jobs'));
|
2010-05-03 23:49:57 -07:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 21:35:13 -07:00
|
|
|
/*function delete($id = null) {
|
2010-05-03 23:49:57 -07:00
|
|
|
if (!$id) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid id for Invoice', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
if ($this->Invoice->del($id)) {
|
|
|
|
|
$this->Session->setFlash(__('Invoice deleted', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
2010-07-15 21:35:13 -07:00
|
|
|
}*/
|
2010-05-03 23:49:57 -07:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|