diff --git a/controllers/app_controller.php b/controllers/app_controller.php index d4041be2..426e4568 100755 --- a/controllers/app_controller.php +++ b/controllers/app_controller.php @@ -24,7 +24,7 @@ class AppController extends Controller { } - + //WTF. Why is this here?? function isAuthorized() { return true; } diff --git a/controllers/attachments_controller.php b/controllers/attachments_controller.php new file mode 100644 index 00000000..8717fc04 --- /dev/null +++ b/controllers/attachments_controller.php @@ -0,0 +1,74 @@ +Attachment->recursive = 1; + $this->set('attachments', $this->paginate()); + } + + function view($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid Attachment.', true)); + $this->redirect(array('action'=>'index')); + } + $this->set('attachment', $this->Attachment->read(null, $id)); + $this->layout = 'pdf'; + } + + function add() { + if (!empty($this->data)) { + + $attachment = $this->Attachment->process_attachment($this->data); + + + $this->Attachment->create(); + + if ($this->Attachment->save($attachment)) { + $this->Session->setFlash(__('The Attachment has been saved', true)); + $this->redirect(array('action'=>'index')); + } else { + $this->Session->setFlash(__('The Attachment could not be saved. Please, try again.', true)); + } + } + $principles = $this->Attachment->Principle->find('list'); + $this->set(compact('products', 'principles')); + } + + function edit($id = null) { + if (!$id && empty($this->data)) { + $this->Session->setFlash(__('Invalid Attachment', true)); + $this->redirect(array('action'=>'index')); + } + if (!empty($this->data)) { + $attachment = $this->Attachment->process_attachment($this->data); + if ($this->Attachment->save($attachment)) { + $this->Session->setFlash(__('The Attachment has been saved', true)); + $this->redirect(array('action'=>'index')); + } else { + $this->Session->setFlash(__('The Attachment could not be saved. Please, try again.', true)); + } + } + if (empty($this->data)) { + $this->data = $this->Attachment->read(null, $id); + } + $products = $this->Attachment->Product->find('list'); + $principles = $this->Attachment->Principle->find('list'); + $this->set(compact('products','principles')); + } + + function delete($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid id for Attachment', true)); + $this->redirect(array('action'=>'index')); + } + if ($this->Attachment->del($id)) { + $this->Session->setFlash(__('Attachment deleted', true)); + $this->redirect(array('action'=>'index')); + } + } + +} +?> diff --git a/controllers/documents_controller.php b/controllers/documents_controller.php index 7086736e..2ae47f7b 100755 --- a/controllers/documents_controller.php +++ b/controllers/documents_controller.php @@ -1,629 +1,693 @@ false, - 'limit' => 200, - 'order'=>array('Document.id' => 'desc') + var $paginate = array( + 'contain' => false, + 'limit' => 200, + 'order'=>array('Document.id' => 'desc') + ); + + var $components = array('Email'); + + function index() { + $this->Document->recursive = 0; + $this->set('documents', $this->paginate()); + + $this->set('users', $this->Document->User->getUsersList()); + } + + function view($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid Document.', true)); + $this->redirect(array('action'=>'index')); + } + $document = $this->Document->read(null,$id); + + $this->set('document', $document); + + $this->data = $document; + $docType = $this->Document->getDocType($document); + $this->set('docType', $docType); + + $this->set('docTypeFullName', $this->Document->getDocFullName($docType)); + $this->set('users', $this->Document->User->getUsersList()); + + $this->set('currency', $this->Document->getCurrency($document)); + $this->set('enquiry', $this->Document->getEnquiry($document)); + + $this->set('attachments', $this->Document->DocumentAttachment->find('all', array('conditions'=>array('document_id'=> $id)))); + $this->set('principles', $this->Document->LineItem->Product->Principle->find('list')); + + switch($docType) { + case 'quote': + $docTypeElement = 'document_quote_view'; + break; + case 'invoice': + $docTypeElement = 'document_invoice_view'; + $this->set('currencies', $this->Document->Invoice->Currency->find('list')); + $this->set('invoice', $this->Document->Invoice->find('first', array('conditions'=>array('Invoice.id'=>$document['Invoice']['id'])))); + break; + case 'purchaseOrder': + $docTypeElement = 'document_purchase_order_view'; + break; + case 'orderAck': + $this->set('currencies', $this->Document->OrderAcknowledgement->Currency->find('list')); + $this->set('job', $this->Document->OrderAcknowledgement->Job->find('first', array('conditions'=>array('Job.id'=>$document['OrderAcknowledgement']['job_id'])))); + $docTypeElement = 'document_orderack_view'; + } + + $this->set('docTypeElement', $docTypeElement); + + // $this->set('principles', $this->Document->LineItem->Product->Principle->find('list')); + } + + + function getProducts($principleID = null) { + $this->layout = 'ajax'; + + if($principleID == null) { + echo "INVALID PRINCIPLE ID"; + } + else { + $products = $this->Document->LineItem->Product->find('list', array('conditions'=>array('Product.principle_id'=>$principleID))); + $this->set('products',$products); + } + } + + + /** + * Return a JSON object of the Product. + */ + function getProductDetails($productID = null) { + $this->layout = 'ajax'; + + if($productID == null) { + echo "INVALID PRODUCT ID"; + } + else { + $product = $this->Document->LineItem->Product->find('first',array('conditions'=>array('Product.id'=>$productID))); + $this->set('product',$product); + } + } + + + function getAttachments($documentID) { + $this->layout = 'ajax'; + if(!$documentID) { + echo "FAIL"; + } + else { + $this->set('attachments', $this->Document->DocumentAttachment->find('all', array('conditions'=>array('document_id'=> $documentID)))); + } + } + + function getAttachmentsByPrinciple($principleID) { + $this->layout = 'ajax'; + if(!$principleID) { + echo "FAIL"; + } + else { + $attachments = $this->Document->DocumentAttachment->Attachment->find('all', array('conditions'=>array('principle_id'=> $principleID))); + $this->set('attachments', $attachments); + } + } + + function saveAttachments() { + $this->layout = 'ajax'; + if($this->data) { + $attachments = array(); + foreach($this->data['DocumentAttachment']['attachment_id'] as $i => $attachment_id) { + $docID = $this->data['DocumentAttachment']['document_id']; + $query = "DELETE FROM document_attachments WHERE document_id = {$docID} AND attachment_id = {$attachment_id}"; + $this->Document->DocumentAttachment->query($query); + + $attachment[$i]['DocumentAttachment']['document_id'] = $this->data['DocumentAttachment']['document_id']; + $attachment[$i]['DocumentAttachment']['attachment_id'] = $attachment_id; + } + if($this->Document->DocumentAttachment->saveAll($attachment)) { + echo "SUCCESS"; + } + else { + echo "FAIL"; + } + } + } + + function removeAttachments() { + $this->layout = 'ajax'; + foreach($this->data as $attachment) { + $this->Document->DocumentAttachment->delete($attachment); + } + } + + + /** + * Create a New Document + * + * + * @param $type + * @param $id + */ + function newDocument($type = null, $enquiryid = null, $jobid = 0) { + if(!$type) { + $this->Session->setFlash('Invalid Doc Type or ID'); + } + + $this->Document->create(); + + switch($type) { + case "quote": + + $enquiry = $this->Document->Quote->Enquiry->findById($enquiryid); + + if(!$enquiry) { + $this->Session->setFlash('Invalid Enquiry ID'); + $this->redirect(array('action'=>'index')); + return; + } + + + $this->data['Quote']['enquiry_id'] = $enquiryid; + $number_of_revisions = $this->Document->Quote->findCount('Quote.enquiry_id ='. $enquiryid); + $this->data['Document']['revision'] = $number_of_revisions; + $this->data['Quote']['date_issued'] = date('Y-m-d'); + $this->data['Quote']['currency_id'] = 2; //All new Quotes default to AUD. + + $this->data['Document']['user_id']= $enquiry['Enquiry']['user_id']; + + $this->data['Document']['type'] = 'quote'; + break; + case "invoice": + + $invoice_number_offset = 4436; //What Invoice number we are up to. Starting at 4500 due to the data loss. + + $number_of_invoices = $this->Document->Invoice->findCount(); + + $enquiry = $this->Document->Invoice->Enquiry->read(null, $enquiryid); + if(!$enquiry) { + $this->Session->setFlash('Invalid Enquiry ID'); + $this->redirect(array('action'=>'index')); + return; + } + + $newInvoiceNumber = $invoice_number_offset + $number_of_invoices; + $this->data['Invoice']['enquiry_id'] = $enquiryid; + $this->data['Invoice']['title'] = "CMCIN".$newInvoiceNumber; + $this->data['Invoice']['job_id'] = $jobid; + $this->data['Invoice']['customer_id'] = $enquiry['Enquiry']['customer_id']; + + $this->data['Document']['user_id']= $enquiry['Enquiry']['user_id']; + //$number_of_revisions = $this->Document->Invoice->findCount('Invoice.enquiry_id ='. $enquiryid); + $this->data['Document']['revision'] = 0; //No revisions for Invoices. I have decreed it! + $this->data['Document']['type'] = 'invoice'; + + $this->data['Invoice']['issue_date'] = date('Y-m-d'); //Argh. Quote model uses 'date_issed'. + $this->data['Invoice']['due_date'] = date("Y-m-d", strtotime("+30 days")); + + + $this->data['Invoice']['currency_id'] = 2; //All new Invoices default to AUD. + + break; + case "purchaseOrder": + + $count = $this->Document->PurchaseOrder->findCount(); + $count++; + + $offset = 2060; + $count += $offset; + $newPOnumber = "CMCPO".$count; + $this->data['PurchaseOrder']['title'] = $newPOnumber; + $this->data['PurchaseOrder']['issue_date'] = date('Y-m-d'); + + $this->data['Document']['user_id']= $enquiry['Enquiry']['user_id']; + $this->data['Document']['revision'] = 0; //No revisions for POs. I have decreed it! + $this->data['Document']['type'] = 'purchaseOrder'; + break; + case "orderAck": + $enquiry = $this->Document->OrderAcknowledgement->Enquiry->read(null, $enquiryid); + $this->data['OrderAcknowledgement']['job_id'] = $jobid; + $this->data['OrderAcknowledgement']['enquiry_id'] = $enquiryid; + $this->data['OrderAcknowledgement']['currency_id'] = 2; //Default to AUD. + $this->data['Document']['user_id']= $enquiry['Enquiry']['user_id']; + $this->data['Document']['revision'] = 0; //No revisions for Order Acks. I have decreed it! + $this->data['Document']['type'] = 'orderAck'; + break; + + } + + if ($this->Document->saveAll($this->data)) { + $newid = $this->Document->id; + + $this->Session->setFlash(__('The Document has been saved', true)); + $this->redirect(array('action'=>'view',$newid)); + } else { + $this->Session->setFlash(__('The Document could not be saved. Something went wrong! Ensure all fields are entered correctly.', true)); + } + + + } + + + /** + * Revise a Document. + * + * @param int $id - the document ID we want to make a new revision of. + * @return + */ + + function revise($id = null) { + if(!$id) { + $this->Session->setFlash('Invalid Document ID'); + return; + } + + $document = $this->Document->find('first', array('conditions' => array('Document.id' => $id))); + + $this->set('document', $document); + + $this->Document->create(); + + if(!empty($document['Invoice']['id'])) { + echo "WE HAVE AN INVOICE"; + } + else if (!empty($document['Quote']['id'])) { + + //First setup the Date and default valid until date. (30 days from today). + + $today_date = date("Y-m-d"); + $valid_until = date("Y-m-d", strtotime("+30 days")); + + $newDoc = array(); + + + $newDoc['Quote'] = $this->unset_keys($document['Quote'], array('id','created')); + + $newDoc['Quote']['date_issued'] = $today_date; + $newDoc['Quote']['days_valid'] = 30; + $newDoc['Quote']['valid_until'] = $valid_until; + + $enquiryid = $document['Quote']['enquiry_id']; + $number_of_revisions = $this->Document->Quote->findCount('Quote.enquiry_id ='. $enquiryid); + $newDoc['Document']['revision'] = $number_of_revisions; + $newDoc['Document']['type'] = 'quote'; + + + $newDoc['DocPage'] = $document['DocPage']; + + foreach($newDoc['DocPage'] as $index => $li) { + $newDoc['DocPage'][$index]['id'] = null; + $newDoc['DocPage'][$index]['document_id'] = null; + } + + } + + else if (!empty($document['PurchaseOrder']['id'])) { + echo "WE ARE REVISING A PO"; + } + + + else if (!empty($document['OrderAcknowledgement']['id'])) { + echo "WE ARE REVISING An ORDER ACK"; + } + + + /** Copy the LineItems from this Document. Applies to all of the Document Types */ + if(!empty($document['LineItem'])) { + $newDoc['LineItem'] = $document['LineItem']; + foreach($newDoc['LineItem'] as $index => $li) { + $newDoc['LineItem'][$index]['id'] = null; + $newDoc['LineItem'][$index]['document_id'] = null; + $newDoc['LineItem'][$index]['costing_id'] = null; + } + } + + + $this->set('newDoc', $newDoc); + // + //print_r($newDoc); + if ($this->Document->saveAll($newDoc)) { + $newid = $this->Document->id; + $this->Session->setFlash(__("Revision {$number_of_revisions} created", true)); + $this->redirect(array('action'=>'view',$newid)); + } else { + $this->Session->setFlash(__('The Document could not be saved. Please, try again.', true)); + } + + } + + + function ajax_edit($id = null) { + $this->layout = 'ajax'; + + if (!$id && empty($this->data)) { + echo 'Invalid Document ID'; + } + if (!empty($this->data)) { + $docID = $this->data['Document']['id']; + $this->Document->DocPage->deleteAll(array('document_id'=>$docID)); + $this->Document->DocPage->updateCounterCache(array('document_id'=>$docID)); + + + if ($this->Document->saveAll($this->data)) { + echo 'SUCCESS'; + } else { + echo 'FAILURE'; + } + } + else { + echo 'FAILURE'; + } + } + + + /** + * + * Convert a Quote to an OrderAcknowledgement. + * + * Create a new Job for the Enquiry. + * + * Make a new Document (orderack) with the same LineItems as Quote with Document ID #$id + * + * + */ + function convert_to_oa() { + $this->layout = 'ajax'; + if (empty($this->data)) { + echo 'FAILURE'; + } + else { + $id = $this->data['Document']['id']; + + $originalDoc = $this->Document->find('first', array('conditions' => array('Document.id' => $id))); + + $enquiry = $this->Document->OrderAcknowledgement->Enquiry->find('first', array('conditions'=>array('Enquiry.id'=>$originalDoc['Quote']['enquiry_id']))); + $enquiry['Enquiry']['status_id'] = 3; //Job Won, Order Placed + + $this->Document->OrderAcknowledgement->Enquiry->save($enquiry); + + $customer = $this->Document->OrderAcknowledgement->Enquiry->Customer->find('first', array('conditions'=>array('Customer.id'=>$enquiry['Enquiry']['customer_id']))); + + $customer['Customer']['customer_category_id'] = 3; //make Customer a Creditor + + $this->Document->OrderAcknowledgement->Enquiry->Customer->save($customer); + + $job = $this->Document->OrderAcknowledgement->Job->newJob($enquiry, $this->data['Job']['customer_order_number']); //Only way to know Enquiry ID is if it's a Quote. + + + + if($job == false) { + echo 'Error: Unable to create Job'; + } + else { + $newDoc = array(); + $newDoc['Document']['type'] = 'orderAck'; + $newDoc['OrderAcknowledgement']['job_id'] = $job['Job']['id']; + $newDoc['OrderAcknowledgement']['enquiry_id'] = $enquiry['Enquiry']['id']; + $newDoc['OrderAcknowledgement']['currency_id'] = 2; //Default to AUD. + $newDoc['OrderAcknowledgement']['issue_date'] = date('Y-m-d'); + + $newDoc['Document']['user_id']= $enquiry['Enquiry']['user_id']; + $newDoc['Document']['revision'] = 0; //No revisions for Order Acks. I have decreed it! + $newDoc['Document']['type'] = 'orderAck'; + + if(isset($enquiry['BillingAddress']['id'])) { + $newDoc['Document']['bill_to'] = ''.$customer['Customer']['name'].'
'; + $newDoc['Document']['bill_to'] .= $this->Document->OrderAcknowledgement->Enquiry->formatAddress($enquiry['BillingAddress']['id'], 'BillingAddress'); + } + + if(isset($enquiry['ShippingAddress']['id'])) { + $newDoc['Document']['ship_to'] = ''.$customer['Customer']['name'].'
'; + $newDoc['Document']['ship_to'] .= $this->Document->OrderAcknowledgement->Enquiry->formatAddress($enquiry['ShippingAddress']['id'], 'ShippingAddress'); + } + + + + /** Copy the LineItems from this Document. Applies to all of the Document Types */ + if(!empty($originalDoc['LineItem'])) { + $newDoc['LineItem'] = $originalDoc['LineItem']; + foreach($newDoc['LineItem'] as $index => $li) { + $newDoc['LineItem'][$index]['id'] = null; + $newDoc['LineItem'][$index]['document_id'] = null; + $newDoc['LineItem'][$index]['costing_id'] = null; + } + } + + if ($this->Document->saveAll($newDoc)) { + $newid = $this->Document->id; + $this->Session->setFlash(__("Job {$job['Job']['title']} and Order Acknowledgement created", true)); + $this->redirect(array('action'=>'view',$newid)); + } else { + $this->Session->setFlash(__('The Document could not be saved. Please, try again.', true)); + } + $this->Document->saveAll($newDoc); + } + } + + } + + + /** + * Convert an Order Acknowledgement to an Invoice. + * + * @TODO Finish this. + * + * @param $id + */ + function convert_to_invoice($id = null) { + if (!$id) { + echo 'Invalid Document ID'; + } + else { + + + } + + + } + + + function pdf($id = null) { + //Configure::write('debug',0); + if(!$id) { + $this->Session->setFlash(__('Invalid Document', true)); + $this->redirect(array('controller'=>'documents', 'action'=>'index')); + } + + $document = $this->Document->read(null,$id); + + $this->set('document', $document); + + $this->data = $document; + + $docType = $this->Document->getDocType($document); + $docTypeFullName = $this->Document->getDocFullName($docType); + + + + $currency = $this->Document->getCurrency($document); + $enquiry = $this->Document->getEnquiry($document); + + $this->set('docType', $docType); + $this->set('docTypeFullName',strtoupper($docTypeFullName)); + $this->set('currency',$currency); + $this->set('currencyCode', $currency['Currency']['iso4217']); + $this->set('currencySymbol', $currency['Currency']['symbol']); + + $gst = $enquiry['Enquiry']['gst']; + + $this->set('gst', $gst); + + if($gst == 1) { + $totalsDescText = array( + 'subtotal' => 'SUBTOTAL', + 'gst' => 'GST (10%)', + 'total' => 'TOTAL DUE' + ); + } + else { + $totalsDescText = array( + 'subtotal' => 'SUBTOTAL', + 'gst' => 'GST (10%)', + 'total' => 'TOTAL PAYABLE' + ); + } + + + $totals = $this->calculateTotals($document, $gst); + $this->set('totals',$totals); + $this->set('totalsDescText',$totalsDescText); + + $this->set('currency', $currency); + $this->set('enquiry', $enquiry); + + $this->set('principlesList', $this->Document->LineItem->Product->Principle->find('list')); + + $this->set('products', $document['LineItem']); + $this->set('states', $this->Document->Invoice->Enquiry->State->find('list')); + + + //Set filename for the document. + // + switch($docType) { + case "quote": + $filename = $enquiry['Enquiry']['title']; + $template_name = 'pdf_quote'; + break; + + case "invoice": + $filename = $document['Invoice']['title']; + $this->set('docTitle', $document['Invoice']['title']); + $this->set('job', $this->Document->Invoice->Job->find('first', array('conditions'=>array('Job.id'=>$document['Invoice']['job_id'])))); + $this->set('issue_date_string', date('d F Y', strtotime($document['Invoice']['issue_date']))); + + $this->set('ship_via', $document['Invoice']['ship_via']); + $this->set('fob', $document['Invoice']['fob']); + + + $template_name = 'pdf_invoice'; + break; + + case "purchaseOrder": + $filename = $document['PurchaseOrder']['title']; + break; + + case "orderAck": + + $job = $this->Document->OrderAcknowledgement->Job->find('first', array('conditions'=>array('Job.id'=>$document['OrderAcknowledgement']['job_id']))); + + $filename = $job['Job']['title'].'_OrderAcknowledgement'; + $this->set('docTitle', $job['Job']['title']); + + $this->set('docTypeFullName', 'JOB'); //So it doesnt say CMC order Ack # in the pdf_shipping_billing_box. This string is too long + $this->set('job', $job); + $this->set('issue_date_string', date('d F Y', strtotime($document['OrderAcknowledgement']['issue_date']))); + + $this->set('ship_via', $document['OrderAcknowledgement']['ship_via']); + $this->set('fob', $document['OrderAcknowledgement']['fob']); + $this->set('estimated_delivery', $document['OrderAcknowledgement']['estimated_delivery']); + + $template_name = 'pdf_orderack'; + break; + + } + + if($document['Document']['revision'] > 0) { + $filename = $filename.'_'.$document['Document']['revision'].'.pdf'; + } + else { + $filename = $filename.'.pdf'; + } + + $this->set('filename', $filename); + $document['Document']['pdf_filename'] = $filename; + $document['Document']['pdf_created_at'] = date('Y-m-d H:i:s'); + $document['Document']['pdf_created_by_user_id'] = $this->getCurrentUserID(); + if($this->Document->save($document)) { + //echo "Set pdf_filename attritbute to: ".$filename; + } + else { + //echo 'Failed to set pdf_filename to: '.$filename; + } + + + $colWidths = array( + 'item' => '7%', + 'qty' => '7%', + 'desc' => '56%', + 'unit' => '15%', + 'total' => '15%' + ); - var $components = array('Email'); + $this->set('colWidths',$colWidths); - function index() { - $this->Document->recursive = 0; - $this->set('documents', $this->paginate()); + $this->render($template_name); + } - $this->set('users', $this->Document->User->getUsersList()); + + //Called via AJAX to generate Quotation First Pages. + function generateFirstPage($id = null) { + $this->layout = 'ajax'; + + if(!$id) { + return; } - function view($id = null) { - if (!$id) { - $this->Session->setFlash(__('Invalid Document.', true)); - $this->redirect(array('action'=>'index')); - } - $document = $this->Document->read(null,$id); - - $this->set('document', $document); - - $this->data = $document; - $docType = $this->Document->getDocType($document); - $this->set('docType', $docType); - - $this->set('docTypeFullName', $this->Document->getDocFullName($docType)); - $this->set('users', $this->Document->User->getUsersList()); - - $this->set('currency', $this->Document->getCurrency($document)); - $this->set('enquiry', $this->Document->getEnquiry($document)); + $document = $this->Document->read(null, $id); + $this->set('document',$document); + $enquiry = $this->Document->Quote->Enquiry->read(null, $document['Quote']['enquiry_id']); + $this->set('enquiry', $enquiry); + } - switch($docType) { - case 'quote': - $docTypeElement = 'document_quote_view'; - break; - case 'invoice': - $docTypeElement = 'document_invoice_view'; - $this->set('currencies', $this->Document->Invoice->Currency->find('list')); - $this->set('invoice', $this->Document->Invoice->find('first', array('conditions'=>array('Invoice.id'=>$document['Invoice']['id'])))); - break; - case 'purchaseOrder': - $docTypeElement = 'document_purchase_order_view'; - break; - case 'orderAck': - $this->set('currencies', $this->Document->OrderAcknowledgement->Currency->find('list')); - $this->set('job', $this->Document->OrderAcknowledgement->Job->find('first', array('conditions'=>array('Job.id'=>$document['OrderAcknowledgement']['job_id'])))); - $docTypeElement = 'document_orderack_view'; - } + + /** + * Email the PDF(document + attachments) for this Document to a Recipient (Customer or Principle). + * + * + * @param $id - Document ID + */ + function email_pdf($id) { - $this->set('docTypeElement', $docTypeElement); + //Setup the SMTP Options + $this->Email->smtpOptions = Configure::read('smtp_settings'); + $this->Email->delivery = 'smtp'; -// $this->set('principles', $this->Document->LineItem->Product->Principle->find('list')); + $document = $this->Document->read(null,$id); + + + if(empty($document['Document']['pdf_filename'])) { + $this->Session->setFlash(__('Error. Please generate the PDF before attempting to email it', true)); + return; + } + else { + $pdf_dir = Configure::read('pdf_directory'); + + $attachment_files = array($pdf_dir.$document['Document']['pdf_filename']); + foreach($document['DocumentAttachment'] as $document_attachment) { + $attachment = $this->Document->DocumentAttachment->Attachment->read(null, $document_attachment['attachment_id']); + $attachment_files[] = $attachment['Attachment']['file']; + } + $this->Email->attachments = $attachment_files; + } + $enquiry = $this->Document->getEnquiry($document); + $this->Email->to = $enquiry['Contact']['email']; + //Uncomment this when going live + $this->Email->cc = array($enquiry['User']['email']); + // $this->Email->bcc = array('carpis@cmctechnologies.com.au'); - function getProducts($principleID = null) { - $this->layout = 'ajax'; - - if($principleID == null) { - echo "INVALID PRINCIPLE ID"; - } - else { - $products = $this->Document->LineItem->Product->find('list', array('conditions'=>array('Product.principle_id'=>$principleID))); - $this->set('products',$products); - } + $this->Email->subject = $enquiry['Enquiry']['title'].' '; + $this->Email->replyTo = $enquiry['User']['email']; + $this->Email->from = 'CMC Technologies - Sales '; + $this->Email->template = 'email_pdf'; + $this->Email->sendAs = 'both'; + $this->Email->charset = 'iso-8859-1'; + $this->set('enquiry', $enquiry); + $this->set('DocFullName', $this->Document->getDocFullName($document['Document']['type'])); + if($this->Email->send()) { + $this->Session->setFlash(__('The Email has been sent', true)); + $this->redirect(array('action'=>'view/'.$id), null, false); } - - - /** - * Return a JSON object of the Product. - */ - function getProductDetails($productID = null) { - $this->layout = 'ajax'; - - if($productID == null) { - echo "INVALID PRODUCT ID"; - } - else { - $product = $this->Document->LineItem->Product->find('first',array('conditions'=>array('Product.id'=>$productID))); - $this->set('product',$product); - } - } - - - /** - * Create a New Document - * - * - * @param $type - * @param $id - */ - function newDocument($type = null, $enquiryid = null, $jobid = 0) { - if(!$type) { - $this->Session->setFlash('Invalid Doc Type or ID'); - } - - $this->Document->create(); - - switch($type) { - case "quote": - - $enquiry = $this->Document->Quote->Enquiry->findById($enquiryid); - - if(!$enquiry) { - $this->Session->setFlash('Invalid Enquiry ID'); - $this->redirect(array('action'=>'index')); - return; - } - - - $this->data['Quote']['enquiry_id'] = $enquiryid; - $number_of_revisions = $this->Document->Quote->findCount('Quote.enquiry_id ='. $enquiryid); - $this->data['Document']['revision'] = $number_of_revisions; - $this->data['Quote']['date_issued'] = date('Y-m-d'); - $this->data['Quote']['currency_id'] = 2; //All new Quotes default to AUD. - - $this->data['Document']['user_id']= $enquiry['Enquiry']['user_id']; - - $this->data['Document']['type'] = 'quote'; - break; - case "invoice": - - $invoice_number_offset = 4436; //What Invoice number we are up to. Starting at 4500 due to the data loss. - - $number_of_invoices = $this->Document->Invoice->findCount(); - - $enquiry = $this->Document->Invoice->Enquiry->read(null, $enquiryid); - if(!$enquiry) { - $this->Session->setFlash('Invalid Enquiry ID'); - $this->redirect(array('action'=>'index')); - return; - } - - $newInvoiceNumber = $invoice_number_offset + $number_of_invoices; - $this->data['Invoice']['enquiry_id'] = $enquiryid; - $this->data['Invoice']['title'] = "CMCIN".$newInvoiceNumber; - $this->data['Invoice']['job_id'] = $jobid; - $this->data['Invoice']['customer_id'] = $enquiry['Enquiry']['customer_id']; - - $this->data['Document']['user_id']= $enquiry['Enquiry']['user_id']; -//$number_of_revisions = $this->Document->Invoice->findCount('Invoice.enquiry_id ='. $enquiryid); - $this->data['Document']['revision'] = 0; //No revisions for Invoices. I have decreed it! - $this->data['Document']['type'] = 'invoice'; - - $this->data['Invoice']['issue_date'] = date('Y-m-d'); //Argh. Quote model uses 'date_issed'. - $this->data['Invoice']['due_date'] = date("Y-m-d", strtotime("+30 days")); - - - $this->data['Invoice']['currency_id'] = 2; //All new Invoices default to AUD. - - break; - case "purchaseOrder": - - $count = $this->Document->PurchaseOrder->findCount(); - $count++; - - $offset = 2060; - $count += $offset; - $newPOnumber = "CMCPO".$count; - $this->data['PurchaseOrder']['title'] = $newPOnumber; - $this->data['PurchaseOrder']['issue_date'] = date('Y-m-d'); - - $this->data['Document']['user_id']= $enquiry['Enquiry']['user_id']; - $this->data['Document']['revision'] = 0; //No revisions for POs. I have decreed it! - $this->data['Document']['type'] = 'purchaseOrder'; - break; - case "orderAck": - $enquiry = $this->Document->OrderAcknowledgement->Enquiry->read(null, $enquiryid); - $this->data['OrderAcknowledgement']['job_id'] = $jobid; - $this->data['OrderAcknowledgement']['enquiry_id'] = $enquiryid; - $this->data['OrderAcknowledgement']['currency_id'] = 2; //Default to AUD. - $this->data['Document']['user_id']= $enquiry['Enquiry']['user_id']; - $this->data['Document']['revision'] = 0; //No revisions for Order Acks. I have decreed it! - $this->data['Document']['type'] = 'orderAck'; - break; - - } - - if ($this->Document->saveAll($this->data)) { - $newid = $this->Document->id; - - $this->Session->setFlash(__('The Document has been saved', true)); - $this->redirect(array('action'=>'view',$newid)); - } else { - $this->Session->setFlash(__('The Document could not be saved. Something went wrong! Ensure all fields are entered correctly.', true)); - } - + else { + $this->set('smtp_errors', $this->Email->smtpError); + $this->Session->setFlash(__('The Email has NOT been sent. Something went wrong.', true)); + // $this->redirect(array('action'=>'view/'.$id), null, false); } - - /** - * Revise a Document. - * - * @param int $id - the document ID we want to make a new revision of. - * @return - */ - - function revise($id = null) { - if(!$id) { - $this->Session->setFlash('Invalid Document ID'); - return; - } - - $document = $this->Document->find('first', array('conditions' => array('Document.id' => $id))); - - $this->set('document', $document); - - $this->Document->create(); - - if(!empty($document['Invoice']['id'])) { - echo "WE HAVE AN INVOICE"; - } - else if (!empty($document['Quote']['id'])) { - -//First setup the Date and default valid until date. (30 days from today). - - $today_date = date("Y-m-d"); - $valid_until = date("Y-m-d", strtotime("+30 days")); - - $newDoc = array(); - - - $newDoc['Quote'] = $this->unset_keys($document['Quote'], array('id','created')); - - $newDoc['Quote']['date_issued'] = $today_date; - $newDoc['Quote']['days_valid'] = 30; - $newDoc['Quote']['valid_until'] = $valid_until; - - $enquiryid = $document['Quote']['enquiry_id']; - $number_of_revisions = $this->Document->Quote->findCount('Quote.enquiry_id ='. $enquiryid); - $newDoc['Document']['revision'] = $number_of_revisions; - $newDoc['Document']['type'] = 'quote'; - - - $newDoc['DocPage'] = $document['DocPage']; - - foreach($newDoc['DocPage'] as $index => $li) { - $newDoc['DocPage'][$index]['id'] = null; - $newDoc['DocPage'][$index]['document_id'] = null; - } - - } - - else if (!empty($document['PurchaseOrder']['id'])) { - echo "WE ARE REVISING A PO"; - } - - - else if (!empty($document['OrderAcknowledgement']['id'])) { - echo "WE ARE REVISING An ORDER ACK"; - } - - - /** Copy the LineItems from this Document. Applies to all of the Document Types */ - if(!empty($document['LineItem'])) { - $newDoc['LineItem'] = $document['LineItem']; - foreach($newDoc['LineItem'] as $index => $li) { - $newDoc['LineItem'][$index]['id'] = null; - $newDoc['LineItem'][$index]['document_id'] = null; - $newDoc['LineItem'][$index]['costing_id'] = null; - } - } - - - $this->set('newDoc', $newDoc); -// -//print_r($newDoc); - if ($this->Document->saveAll($newDoc)) { - $newid = $this->Document->id; - $this->Session->setFlash(__("Revision {$number_of_revisions} created", true)); - $this->redirect(array('action'=>'view',$newid)); - } else { - $this->Session->setFlash(__('The Document could not be saved. Please, try again.', true)); - } - - } - - - function ajax_edit($id = null) { - $this->layout = 'ajax'; - - if (!$id && empty($this->data)) { - echo 'Invalid Document ID'; - } - if (!empty($this->data)) { - $docID = $this->data['Document']['id']; - $this->Document->DocPage->deleteAll(array('document_id'=>$docID)); - $this->Document->DocPage->updateCounterCache(array('document_id'=>$docID)); - - - if ($this->Document->saveAll($this->data)) { - echo 'SUCCESS'; - } else { - echo 'FAILURE'; - } - } - else { - echo 'FAILURE'; - } - } - - - /** - * - * Convert a Quote to an OrderAcknowledgement. - * - * Create a new Job for the Enquiry. - * - * Make a new Document (orderack) with the same LineItems as Quote with Document ID #$id - * - * - */ - function convert_to_oa() { - $this->layout = 'ajax'; - if (empty($this->data)) { - echo 'FAILURE'; - } - else { - $id = $this->data['Document']['id']; - - $originalDoc = $this->Document->find('first', array('conditions' => array('Document.id' => $id))); - - $enquiry = $this->Document->OrderAcknowledgement->Enquiry->find('first', array('conditions'=>array('Enquiry.id'=>$originalDoc['Quote']['enquiry_id']))); - $enquiry['Enquiry']['status_id'] = 3; //Job Won, Order Placed - $this->Document->OrderAcknowledgement->Enquiry->save($enquiry); - - $customer = $this->Document->OrderAcknowledgement->Enquiry->Customer->find('first', array('conditions'=>array('Customer.id'=>$enquiry['Enquiry']['customer_id']))); - - $customer['Customer']['customer_category_id'] = 3; //make Customer a Creditor - - $this->Document->OrderAcknowledgement->Enquiry->Customer->save($customer); - - $job = $this->Document->OrderAcknowledgement->Job->newJob($enquiry, $this->data['Job']['customer_order_number']); //Only way to know Enquiry ID is if it's a Quote. - - if($job == false) { - echo 'Error: Unable to create Job'; - } - else { - $newDoc = array(); - $newDoc['Document']['type'] = 'orderAck'; - $newDoc['OrderAcknowledgement']['job_id'] = $job['Job']['id']; - $newDoc['OrderAcknowledgement']['enquiry_id'] = $enquiry['Enquiry']['id']; - $newDoc['OrderAcknowledgement']['currency_id'] = 2; //Default to AUD. - $newDoc['OrderAcknowledgement']['issue_date'] = date('Y-m-d'); - $newDoc['Document']['user_id']= $enquiry['Enquiry']['user_id']; - $newDoc['Document']['revision'] = 0; //No revisions for Order Acks. I have decreed it! - $newDoc['Document']['type'] = 'orderAck'; - - if(isset($enquiry['BillingAddress']['id'])) { - $newDoc['Document']['bill_to'] = ''.$customer['Customer']['name'].'
'; - $newDoc['Document']['bill_to'] .= $this->Document->OrderAcknowledgement->Enquiry->formatAddress($enquiry['BillingAddress']['id'], 'BillingAddress'); - } - - if(isset($enquiry['ShippingAddress']['id'])) { - $newDoc['Document']['ship_to'] = ''.$customer['Customer']['name'].'
'; - $newDoc['Document']['ship_to'] .= $this->Document->OrderAcknowledgement->Enquiry->formatAddress($enquiry['ShippingAddress']['id'], 'ShippingAddress'); - } - - - - /** Copy the LineItems from this Document. Applies to all of the Document Types */ - if(!empty($originalDoc['LineItem'])) { - $newDoc['LineItem'] = $originalDoc['LineItem']; - foreach($newDoc['LineItem'] as $index => $li) { - $newDoc['LineItem'][$index]['id'] = null; - $newDoc['LineItem'][$index]['document_id'] = null; - $newDoc['LineItem'][$index]['costing_id'] = null; - } - } - - if ($this->Document->saveAll($newDoc)) { - $newid = $this->Document->id; - $this->Session->setFlash(__("Job {$job['Job']['title']} and Order Acknowledgement created", true)); - $this->redirect(array('action'=>'view',$newid)); - } else { - $this->Session->setFlash(__('The Document could not be saved. Please, try again.', true)); - } - $this->Document->saveAll($newDoc); - } - } - - } - - - /** - * Convert an Order Acknowledgement to an Invoice. - * - * @TODO Finish this. - * - * @param $id - */ - function convert_to_invoice($id = null) { - if (!$id) { - echo 'Invalid Document ID'; - } - else { - - - } - - - } - - - function pdf($id = null) { -//Configure::write('debug',0); - if(!$id) { - $this->Session->setFlash(__('Invalid Document', true)); - $this->redirect(array('controller'=>'documents', 'action'=>'index')); - } - - $document = $this->Document->read(null,$id); - - $this->set('document', $document); - - $this->data = $document; - - $docType = $this->Document->getDocType($document); - $docTypeFullName = $this->Document->getDocFullName($docType); - - - - $currency = $this->Document->getCurrency($document); - $enquiry = $this->Document->getEnquiry($document); - - $this->set('docType', $docType); - $this->set('docTypeFullName',strtoupper($docTypeFullName)); - $this->set('currency',$currency); - $this->set('currencyCode', $currency['Currency']['iso4217']); - $this->set('currencySymbol', $currency['Currency']['symbol']); - - $gst = $enquiry['Enquiry']['gst']; - - $this->set('gst', $gst); - - if($gst == 1) { - $totalsDescText = array( - 'subtotal' => 'SUBTOTAL', - 'gst' => 'GST (10%)', - 'total' => 'TOTAL DUE' - ); - } - else { - $totalsDescText = array( - 'subtotal' => 'SUBTOTAL', - 'gst' => 'GST (10%)', - 'total' => 'TOTAL PAYABLE' - ); - } - - - $totals = $this->calculateTotals($document, $gst); - $this->set('totals',$totals); - $this->set('totalsDescText',$totalsDescText); - - $this->set('currency', $currency); - $this->set('enquiry', $enquiry); - - $this->set('principlesList', $this->Document->LineItem->Product->Principle->find('list')); - - $this->set('products', $document['LineItem']); - $this->set('states', $this->Document->Invoice->Enquiry->State->find('list')); - - -//Set filename for the document. -// - switch($docType) { - case "quote": - $filename = $enquiry['Enquiry']['title']; - $template_name = 'pdf_quote'; - break; - - case "invoice": - $filename = $document['Invoice']['title']; - $this->set('docTitle', $document['Invoice']['title']); - $this->set('job', $this->Document->Invoice->Job->find('first', array('conditions'=>array('Job.id'=>$document['Invoice']['job_id'])))); - $this->set('issue_date_string', date('d F Y', strtotime($document['Invoice']['issue_date']))); - - $this->set('ship_via', $document['Invoice']['ship_via']); - $this->set('fob', $document['Invoice']['fob']); - - - $template_name = 'pdf_invoice'; - break; - - case "purchaseOrder": - $filename = $document['PurchaseOrder']['title']; - break; - - case "orderAck": - - $job = $this->Document->OrderAcknowledgement->Job->find('first', array('conditions'=>array('Job.id'=>$document['OrderAcknowledgement']['job_id']))); - - $filename = $job['Job']['title'].'_OrderAcknowledgement'; - $this->set('docTitle', $job['Job']['title']); - - $this->set('docTypeFullName', 'JOB'); //So it doesnt say CMC order Ack # in the pdf_shipping_billing_box. This string is too long - $this->set('job', $job); - $this->set('issue_date_string', date('d F Y', strtotime($document['OrderAcknowledgement']['issue_date']))); - - $this->set('ship_via', $document['OrderAcknowledgement']['ship_via']); - $this->set('fob', $document['OrderAcknowledgement']['fob']); - $this->set('estimated_delivery', $document['OrderAcknowledgement']['estimated_delivery']); - - $template_name = 'pdf_orderack'; - break; - - } - - if($document['Document']['revision'] > 0) { - $filename = $filename.'_'.$document['Document']['revision'].'.pdf'; - } - else { - $filename = $filename.'.pdf'; - } - - $this->set('filename', $filename); - $document['Document']['pdf_filename'] = $filename; - $document['Document']['pdf_created_at'] = date('Y-m-d H:i:s'); - $document['Document']['pdf_created_by_user_id'] = $this->getCurrentUserID(); - if($this->Document->save($document)) { -//echo "Set pdf_filename attritbute to: ".$filename; - } - else { -//echo 'Failed to set pdf_filename to: '.$filename; - } - - - $colWidths = array( - 'item' => '7%', - 'qty' => '7%', - 'desc' => '56%', - 'unit' => '15%', - 'total' => '15%' - - ); - - $this->set('colWidths',$colWidths); - - $this->render($template_name); - } - - -//Called via AJAX to generate Quotation First Pages. - function generateFirstPage($id = null) { - $this->layout = 'ajax'; - - if(!$id) { - return; - } - - $document = $this->Document->read(null, $id); - $this->set('document',$document); - $enquiry = $this->Document->Quote->Enquiry->read(null, $document['Quote']['enquiry_id']); - $this->set('enquiry', $enquiry); - } - - /** - * Email the PDF(document + attachments) for this Document to a Recipient (Customer or Principle). - * - * - * @param $id - Document ID - */ - function email_pdf($id) { - - //Setup the SMTP Options - $this->Email->smtpOptions = Configure::read('smtp_settings'); - $this->Email->delivery = 'smtp'; - - $document = $this->Document->read(null,$id); - - if(empty($document['Document']['pdf_filename'])) { - $this->Session->setFlash(__('Error. Please generate the PDF before attempting to email it', true)); - return; - } - else { - $pdf_dir = Configure::read('pdf_directory'); - $this->Email->attachments = array($pdf_dir.'/'.$document['Document']['pdf_filename']); - } - - $enquiry = $this->Document->getEnquiry($document); - - $this->Email->to = $enquiry['Contact']['email']; - -//Uncomment this when going live -// $this->Email->cc = array($enquiry['User']['email']); -// $this->Email->bcc = array('carpis@cmctechnologies.com.au'); - - $this->Email->subject = $enquiry['Enquiry']['title'].' '; - $this->Email->replyTo = $enquiry['User']['email']; - $this->Email->from = 'CMC Technologies - Sales '; - $this->Email->template = 'email_pdf'; - $this->Email->sendAs = 'both'; - $this->Email->charset = 'iso-8859-1'; - $this->set('enquiry', $enquiry); - $this->set('DocFullName', $this->Document->getDocFullName($document['Document']['type'])); - if($this->Email->send()) { - $this->Session->setFlash(__('The Email has been sent', true)); - // $this->redirect(array('action'=>'view/'.$id), null, false); - } - else { - $this->set('smtp_errors', $this->Email->smtpError); - $this->Session->setFlash(__('The Email has NOT been sent. Something went wrong.', true)); - // $this->redirect(array('action'=>'view/'.$id), null, false); - - } - - } + } } -?> \ No newline at end of file +?> diff --git a/models/attachment.php b/models/attachment.php new file mode 100644 index 00000000..80b54f5a --- /dev/null +++ b/models/attachment.php @@ -0,0 +1,77 @@ + array('numeric'), + 'name' => array('notempty'), + 'type' => array('notempty'), + 'size' => array('numeric'), + 'archived' => array('numeric'), + ); + + //The Associations below have been created with all possible keys, those that are not needed can be removed + var $belongsTo = array( + 'Principle' => array( + 'className' => 'Principle', + 'foreignKey' => 'principle_id', + 'conditions' => '', + 'fields' => '', + 'order' => '' + ) + ); + + var $hasMany = array( + 'DocumentAttachment' => array( + 'className' => 'DocumentAttachment', + 'foreignKey' => 'attachment_id' + ) + ); + + +// Based on comment 8 from: http://bakery.cakephp.org/articles/view/improved-advance-validation-with-parameters + + function isUploadedFile($params){ + $val = array_shift($params); + if ((isset($val['error']) && $val['error'] == 0) || + (!empty( $val['tmp_name']) && $val['tmp_name'] != 'none')) { + return is_uploaded_file($val['tmp_name']); + } + return false; + } + + + /** + * Passed a PHP upload + * array('name', 'type', 'tmp_name', 'error' 'size'). + * + * Move the uploaded file to the storage directory + * and return a cake array for insertion. + * + */ + + function process_attachment($attachment) { + + $upload = $attachment['Attachment']['file']; + + $new_filename = Configure::read('attachments_directory').time().$upload['name']; + + $moved = move_uploaded_file($upload['tmp_name'], $new_filename); + + if($moved) { + $attachment['Attachment']['filename'] = $upload['name']; + $attachment['Attachment']['file'] = $new_filename; + $attachment['Attachment']['size'] = $upload['size']; + $attachment['Attachment']['type'] = $upload['type']; + return $attachment; + } + else { + die("Error! Unable to move the uploaded file"); + } + + + + } + +} +?> diff --git a/models/document.php b/models/document.php index 81b31c16..d56cc53d 100755 --- a/models/document.php +++ b/models/document.php @@ -28,7 +28,14 @@ class Document extends AppModel { 'className'=> 'DocPage', 'foreignKey' => 'document_id', 'order' => 'DocPage.page_number ASC' - ) + ), + + 'DocumentAttachment' => array( + 'className'=> 'DocumentAttachment', + 'foreignKey' => 'document_id', + 'order' => 'DocumentAttachment.id ASC' + ), + ); @@ -53,7 +60,6 @@ class Document extends AppModel { ) ); - //So much refactoring possible on this. function getCurrency($document) { @@ -170,4 +176,4 @@ class Document extends AppModel { } -?> \ No newline at end of file +?> diff --git a/models/document_attachment.php b/models/document_attachment.php new file mode 100644 index 00000000..2009bcfb --- /dev/null +++ b/models/document_attachment.php @@ -0,0 +1,28 @@ + array( + 'className' => 'Document', + 'foreignKey' => 'document_id', + 'conditions' => '', + 'fields' => '', + 'order' => '' + ), + 'Attachment' => array( + 'className' => 'Attachment', + 'foreignKey' => 'attachment_id', + 'conditions' => '', + 'fields' => '', + 'order' => '' + ) + ); + +} +?> diff --git a/views/attachments/add.ctp b/views/attachments/add.ctp new file mode 100644 index 00000000..b1cfb51d --- /dev/null +++ b/views/attachments/add.ctp @@ -0,0 +1,14 @@ +
+create('Attachment', array('type'=>'file'));?> +
+ + input('principle_id'); + echo $form->input('name'); + echo $form->file('file'); + echo $form->input('description'); + echo $form->input('archived'); + ?> +
+end('Submit');?> +
diff --git a/views/attachments/edit.ctp b/views/attachments/edit.ctp new file mode 100644 index 00000000..3cd750ef --- /dev/null +++ b/views/attachments/edit.ctp @@ -0,0 +1,23 @@ +
+create('Attachment');?> +
+ + input('id'); + echo $form->input('principle_id'); + echo $form->input('name'); + echo $form->input('filename'); + echo $form->input('type'); + echo $form->input('size'); + echo $form->input('description'); + echo $form->input('archived'); + ?> +
+end('Submit');?> +
+
+
    +
  • link(__('Delete', true), array('action' => 'delete', $form->value('Attachment.id')), null, sprintf(__('Are you sure you want to delete # %s?', true), $form->value('Attachment.id'))); ?>
  • +
  • link(__('List Attachments', true), array('action' => 'index'));?>
  • +
+
diff --git a/views/attachments/index.ctp b/views/attachments/index.ctp new file mode 100644 index 00000000..af2adaa2 --- /dev/null +++ b/views/attachments/index.ctp @@ -0,0 +1,75 @@ +
+

+

+counter(array( +'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true) +)); +?>

+ + + + + + + + + + + + + > + + + + + + + + + + +
sort('id');?>sort('principle_id');?>sort('created');?>sort('name');?>sort('type');?>sort('size');?>sort('description');?>
+ + + link($attachment['Principle']['short_name'], '/principles/view/'.$attachment['Principle']['id']); + } + else { + echo $html->link($attachment['Principle']['name'], '/principles/view/'.$attachment['Principle']['id']); + } + ?> + + nice($attachment['Attachment']['created']); ?> + + + + + + toReadAbleSize($attachment['Attachment']['size']); ?> + + + + link(__('View', true), array('action' => 'view', $attachment['Attachment']['id'])); ?> + link(__('Edit', true), array('action' => 'edit', $attachment['Attachment']['id'])); ?> + link(__('Delete', true), array('action' => 'delete', $attachment['Attachment']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $attachment['Attachment']['id'])); ?> +
+
+
+ prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?> + | numbers();?> + next(__('next', true).' >>', array(), null, array('class' => 'disabled'));?> +
+
+
    +
  • link(__('New Attachment', true), array('action' => 'add')); ?>
  • +
+
diff --git a/views/attachments/view.ctp b/views/attachments/view.ctp new file mode 100644 index 00000000..4f27f363 --- /dev/null +++ b/views/attachments/view.ctp @@ -0,0 +1,17 @@ + + diff --git a/views/documents/get_attachments.ctp b/views/documents/get_attachments.ctp new file mode 100644 index 00000000..715ad21a --- /dev/null +++ b/views/documents/get_attachments.ctp @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + +
FilenameNameDesc
input('DocumentAttachment.id', array('type'=>'checkbox', 'value'=> $attachment['DocumentAttachment']['id'], 'label' => false)); ?> + link($attachment['Attachment']['filename'], '/attachments/view/'.$attachment['Attachment']['id']); ?> +
diff --git a/views/documents/get_attachments_by_principle.ctp b/views/documents/get_attachments_by_principle.ctp new file mode 100644 index 00000000..6f805a2b --- /dev/null +++ b/views/documents/get_attachments_by_principle.ctp @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + +
Add + FilenameNameDesc
+ + + link($attachment['Attachment']['filename'], '/attachments/view/'.$attachment['Attachment']['id']); ?> +
diff --git a/views/documents/remove_attachments.ctp b/views/documents/remove_attachments.ctp new file mode 100644 index 00000000..e69de29b diff --git a/views/documents/save_attachments.ctp b/views/documents/save_attachments.ctp new file mode 100644 index 00000000..e69de29b diff --git a/views/documents/view.ctp b/views/documents/view.ctp index 6a8e4a8e..6a4da433 100755 --- a/views/documents/view.ctp +++ b/views/documents/view.ctp @@ -3,6 +3,7 @@ echo $javascript->link('ckeditor/ckeditor'); echo $javascript->link('ckeditor/adapters/jquery'); echo $javascript->link('document_add_edit'); +echo $javascript->link('document_attachments'); ?> element('pdf_created_message'); ?> @@ -18,9 +19,9 @@ echo $this->element($docTypeElement);
- input("DocPage.content", array('class'=>'page', 'label'=>'Page', 'between'=>'')); - ?> +input("DocPage.content", array('class'=>'page', 'label'=>'Page', 'between'=>'')); +?>
@@ -30,6 +31,47 @@ echo $this->element($docTypeElement);
+
+

Attachments

+ +
+ + + + + + + + + $attachment) { +?> + + + + + + + + + +
FilenameNameDesc
input("DocumentAttachment[{$index}].id", + array('type'=>'checkbox', + 'value'=> $attachment['DocumentAttachment']['id'], + 'label' => false, 'class'=>'documentAttachment-checkbox')); ?> + link($attachment['Attachment']['filename'], '/attachments/view/'.$attachment['Attachment']['id']); ?> +
+
+ + +
+ +
+ element('add_attachment'); ?> +
+ + +
@@ -46,4 +88,5 @@ echo $this->element($docTypeElement); - \ No newline at end of file + + diff --git a/views/elements/add_attachment.ctp b/views/elements/add_attachment.ctp new file mode 100644 index 00000000..19196ebf --- /dev/null +++ b/views/elements/add_attachment.ctp @@ -0,0 +1,14 @@ + +create('DocumentAttachment', array('default'=>false)); ?> +input('DocumentAttachment.document_id', array('type'=>'hidden', 'value'=> $document['Document']['id'])); ?> +input('DocumentAttachment.principle_id', array('id'=>'attachmentPrincipleSelect', 'label'=>'Principle','empty'=>'Select Principle'));?> + +
+ +
+ +end(); +?> + + diff --git a/views/elements/document_quote_view.ctp b/views/elements/document_quote_view.ctp index b80176b5..c99564f0 100755 --- a/views/elements/document_quote_view.ctp +++ b/views/elements/document_quote_view.ctp @@ -20,6 +20,7 @@ echo $form->input('Document.id'); link('Generate PDF of this Quote', '/documents/pdf/'.$document['Document']['id']);?> + link('Email this Quote', '/documents/email_pdf/'.$document['Document']['id']);?>
diff --git a/views/enquiries/view.ctp b/views/enquiries/view.ctp index 046bacf1..fd753a4f 100755 --- a/views/enquiries/view.ctp +++ b/views/enquiries/view.ctp @@ -138,13 +138,14 @@