diff --git a/controllers/app_controller.php b/controllers/app_controller.php
index a60be457..45c9ffac 100755
--- a/controllers/app_controller.php
+++ b/controllers/app_controller.php
@@ -75,7 +75,32 @@ class AppController extends Controller {
return false;
}
}
-
+
+
+
+ function calculateTotals($document, $gst) {
+ $totals = array('subtotal'=>0, 'gst'=>0, 'total'=>0);
+
+
+ foreach($document['LineItem'] as $lineitem) {
+ if($lineitem['option'] == 1) {
+ $totals['subtotal'] = 'TBA';
+ $totals['total'] = 'TBA';
+ $totals['gst'] = 'TBA';
+ return $totals;
+ }
+ else {
+ $totals['subtotal'] += $lineitem['net_price'];
+ }
+ }
+
+ if($gst == 1) {
+ $totals['gst'] = 0.1*$totals['subtotal'];
+ }
+ $totals['total'] = $totals['gst'] + $totals['subtotal'];
+ return $totals;
+
+ }
diff --git a/controllers/documents_controller.php b/controllers/documents_controller.php
index 11359bf4..598cf2c4 100755
--- a/controllers/documents_controller.php
+++ b/controllers/documents_controller.php
@@ -2,7 +2,7 @@
class DocumentsController extends AppController {
var $name = 'Documents';
- var $helpers = array('Html', 'Form');
+ var $helpers = array('Html', 'Form', 'Number');
function index() {
$this->Document->recursive = 0;
@@ -14,28 +14,14 @@ class DocumentsController extends AppController {
$this->Session->setFlash(__('Invalid Document.', true));
$this->redirect(array('action'=>'index'));
}
- $document = $this->Document->read(null, $id);
+ $document = $this->Document->read(null,$id);
+ //$document = $this->Document->find('first',array('conditions'=>array('Document.id'=>$id), 'recursive'=>2));
$this->set('document', $document);
-
-
- $docType = "";
-
- if(!empty($document['Invoice']['id'])) {
- $docType = "invoice";
- }
- elseif(!empty($document['Quote']['id'])) {
- $docType = "quote";
- $enquiry = $this->Document->Quote->Enquiry->read(null, $document['Quote']['enquiry_id']);
- $this->set('enquiry',$enquiry);
-
- }
- elseif(!empty($document['PurchaseOrder']['id'])) {
- $docType = "purchaseOrder";
- }
-
$this->data = $document;
- $this->set('docType',$docType);
+ $this->set('docType',$this->Document->getDocType($document));
+ $this->set('currency', $this->Document->getCurrency($document));
+ $this->set('enquiry', $this->Document->getEnquiry($document));
// $this->set('principles', $this->Document->LineItem->Product->Principle->find('list'));
}
@@ -87,8 +73,8 @@ class DocumentsController extends AppController {
$this->data['Quote']['revision'] = $number_of_revisions;
$this->data['Document']['user_id']= $enquiry['Enquiry']['user_id'];
-
-
+ $this->data['Document']['enquiry_id'] = $enquiryid;
+ $this->data['Document']['type'] = 'quote';
if ($this->Document->saveAll($this->data)) {
@@ -113,7 +99,7 @@ class DocumentsController extends AppController {
$enquiryid = $id;
$this->Document->create();
- $enquiry = $this->Document->Enquiry->findById($id);
+ $enquiry = $this->Document->Quote->Enquiry->findById($id);
$this->data['Document']['enquiry_id'] = $enquiryid;
@@ -124,13 +110,8 @@ class DocumentsController extends AppController {
$newInvoiceNumber = $invoice_number_offset + $number_of_invoices;
$this->data['Invoice']['title'] = "CMCIN".$newInvoiceNumber;
-
-
- $this->data['Document']['customer_id'] = $enquiry['Enquiry']['customer_id'];
$this->data['Document']['user_id']= $enquiry['Enquiry']['user_id'];
- $this->data['Document']['contact_id']= $enquiry['Enquiry']['contact_id'];
- $this->data['Page'][0]['page_number'] = 1;
- $this->data['Page'][0]['contentPage'] = 0;
+ $this->data['Document']['type'] = 'invoice';
if ($this->Document->saveAll($this->data)) {
$newid = $this->Document->id;
@@ -172,7 +153,7 @@ class DocumentsController extends AppController {
}
- function ajax_edit($id=null) {
+ function ajax_edit($id = null) {
$this->layout = 'ajax';
if (!$id && empty($this->data)) {
@@ -195,6 +176,122 @@ class DocumentsController extends AppController {
}
}
+
+ 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']);
+
+
+ $gst = $enquiry['Enquiry']['gst'];
+
+ $this->set('gst', $gst);
+
+ if($gst == 1) {
+ $totalsDescText = array(
+ 'subtotal' => 'SUB-TOTAL (EXCLUDING GST)',
+ 'gst' => 'GST (10%)',
+ 'total' => 'TOTAL PAYABLE (INCLUDING GST)'
+ );
+ }
+ else {
+ $totalsDescText = array(
+ 'subtotal' => 'SUB-TOTAL',
+ 'gst' => 'GST (10%)',
+ 'total' => 'TOTAL PAYABLE'
+ );
+ }
+
+
+ $totals = $this->calculateTotals($document, $gst);
+ $this->set('totals',$totals);
+ $this->set('totalsDescText',$totalsDescText);
+ /**
+ * 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
+ * 'dateIssued' => (String) eg. 2009-05-20
+ * '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($document['Quote']['delivery_time']),
+ 'paymentTerms' => strtoupper($document['Quote']['payment_terms']),
+ 'dateIssued' => $document['Quote']['date_issued'],
+ 'validFor' => $document['Quote']['days_valid'],
+ 'deliveryPoint' => strtoupper($document['Quote']['delivery_point']),
+ 'exchangeRate' => strtoupper($document['Quote']['exchange_rate']),
+ 'customsDuty' => strtoupper($document['Quote']['customs_duty']),
+ 'gst' => strtoupper($gstPhrase),
+ 'salesEngineer' => strtoupper($document['User']['first_name'].' '.$document['User']['last_name'])
+ );
+
+ $this->set('commercialDetails', $commercialDetails);
+
+ //debug($quote);
+ //debug($commercialDetails);
+
+ $this->set('currency', $currency);
+ $this->set('enquiry', $enquiry);
+
+ $this->set('principlesList', $this->Document->LineItem->Product->Principle->find('list'));
+
+ $this->set('products', $document['LineItem']);
+
+
+ $colWidths = array(
+ 'item' => '8%',
+ 'qty' => '8%',
+ 'desc' => '60%',
+ 'unit' => '12%',
+ 'total' => '12%'
+
+ );
+
+ $this->set('colWidths',$colWidths);
+
+ }
+
/*function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for Document', true));
diff --git a/controllers/enquiries_controller.php b/controllers/enquiries_controller.php
index e8a0238f..2fa2eaf3 100755
--- a/controllers/enquiries_controller.php
+++ b/controllers/enquiries_controller.php
@@ -62,7 +62,6 @@ class EnquiriesController extends AppController {
$this->pageTitle = "Enquiry: ".$enquiry['Enquiry']['title'];
- $this->set('number_of_quotes', $this->Enquiry->Quote->find('count', array('conditions'=>array('Quote.enquiry_id'=>$id))));
//$this->set('number_of_files', $this->Enquiry->EnquiryFile->find('count', array('conditions' => array('EnquiryFile.enquiry_id'=>$id))));
$this->set('principle_emails', $this->Enquiry->Principle->PrincipleContact->findAllByPrincipleId($enquiry['Enquiry']['principle_id']));
diff --git a/controllers/line_items_controller.php b/controllers/line_items_controller.php
index 47454cfd..c5a24914 100755
--- a/controllers/line_items_controller.php
+++ b/controllers/line_items_controller.php
@@ -2,7 +2,7 @@
class LineItemsController extends AppController {
var $name = 'LineItems';
- var $helpers = array('Html', 'Form', 'Javascript');
+ var $helpers = array('Html', 'Form', 'Javascript', 'Number');
var $components = array('RequestHandler');
@@ -13,7 +13,27 @@ class LineItemsController extends AppController {
if(!empty($this->data)) {
$this->LineItem->create($this->data);
- if ($this->LineItem->saveAll($this->data)) {
+ if ($this->LineItem->save($this->data)) {
+ echo "SUCCESS";
+ }
+ else {
+ echo "FAILURE";
+
+ //print_r($this->data);
+ }
+ }
+ else {
+ echo "NO-DATA";
+ }
+
+ }
+
+
+ function ajax_edit() {
+ $this->layout = 'ajax';
+ if(!empty($this->data)) {
+
+ if ($this->LineItem->save($this->data)) {
echo "SUCCESS";
}
else {
@@ -27,6 +47,21 @@ class LineItemsController extends AppController {
}
+ function ajax_delete($id = null) {
+ $this->layout = 'ajax';
+ if($id == null) {
+ echo "FAILURE";
+ }
+ else {
+ if ($this->LineItem->del($id)) {
+ echo "SUCCESS";
+ }
+ else {
+ echo "FAILURE";
+ }
+ }
+ }
+
function getTable($documentID = null) {
$this->layout = 'ajax';
if($documentID == null) {
@@ -36,19 +71,35 @@ class LineItemsController extends AppController {
$document = $this->LineItem->Document->find('first',array('conditions'=>array('Document.id'=>$documentID)));
$this->set('document',$document);
- $currencies = $this->LineItem->Document->Quote->Currency->find('list', array('fields'=>array('Currency.id','Currency.iso4217')));
- $this->set('currencies',$currencies);
+ $enquiry = $this->LineItem->Document->getEnquiry($document);
+
+ $gst = $this->LineItem->Document->gstApplies($enquiry);
+ $this->set('gst',$gst);
+
+ $this->set('totals', $this->calculateTotals($document, $gst));
+
+ $currency = $this->LineItem->Document->getCurrency($document);
+ $this->set('currencyCode', $currency['Currency']['iso4217']);
+ $this->set('currencySymbol', $currency['Currency']['symbol']);
}
}
-
-
+
function edit($id = null) {
+ $this->layout = 'ajax';
+
+ $this->data = $this->LineItem->read(null,$id);
+ $this->set('yesNo', array(0=>'No', 1=>'Yes'));
+ $this->set('principles', $this->LineItem->Product->Principle->find('list'));
+
+
}
function add($documentID = null) {
+ $this->layout = 'ajax';
$document = $this->LineItem->Document->read(null, $documentID);
$this->set('document', $document);
+ $this->set('yesNo', array(0=>'No', 1=>'Yes'));
$this->set('principles', $this->LineItem->Product->Principle->find('list'));
}
diff --git a/controllers/quote_pages_controller.php b/controllers/quote_pages_controller.php
deleted file mode 100755
index aced3045..00000000
--- a/controllers/quote_pages_controller.php
+++ /dev/null
@@ -1,214 +0,0 @@
-QuotePage->recursive = 0;
- $this->set('quotePages', $this->paginate());
- }
-
- function view($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid QuotePage.', true));
- $this->redirect(array('action'=>'index'));
- }
- $this->set('quotePage', $this->QuotePage->read(null, $id));
- }
-
- function add($id = null) {
-
- if (!$id && empty($this->data)) {
- $this->Session->setFlash(__('Invalid Quote ID', true));
- $this->redirect(array('controller' => 'quotes', 'action'=>'index'));
- }
-
-
-
- if (!empty($this->data)) {
- $this->QuotePage->create();
- if ($this->QuotePage->save($this->data)) {
- $this->Session->setFlash(__('The Quote Page has been saved', true));
- $this->redirect(array('controller'=>'quotes', 'action'=>'view/'.$this->data['QuotePage']['quote_id']));
- } else {
- $this->Session->setFlash(__('The Quote Page could not be saved. Please, try again.', true));
- }
- }
- $quotes = $this->QuotePage->Quote->find('list');
- $this->set(compact('quotes'));
- $this->set('quoteid', $id);
- $number_of_pages = $this->QuotePage->find('count', array('conditions' => array('QuotePage.quote_id'=>$id)));
- $number_of_pages++;
- $this->set('pagenumber', $number_of_pages);
- }
-
- function edit($id = null) {
-
- if (!$id && empty($this->data)) {
- $this->Session->setFlash(__('Invalid QuotePage', true));
- $this->redirect(array('action'=>'index'));
- }
-
- if (!empty($this->data)) {
- if ($this->QuotePage->save($this->data)) {
- $this->Session->setFlash(__('The QuotePage has been saved', true));
- $id = $this->data['QuotePage']['quote_id'];
- $this->redirect(array('controller' => 'quotes', 'action'=>'view/'.$id));
- } else {
- $this->Session->setFlash(__('The QuotePage could not be saved. Please, try again.', true));
- }
- }
- if (empty($this->data)) {
- $this->data = $this->QuotePage->read(null, $id);
- $this->set('content', $this->data['QuotePage']['content']);
- }
- $quotes = $this->QuotePage->Quote->find('list');
- $this->set(compact('quotes'));
- }
-
- function delete($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid id for QuotePage', true));
- $this->redirect(array('action'=>'index'));
- }
-
- $quotepage = $this->QuotePage->findById($id);
- $quoteid = $quotepage['QuotePage']['quote_id'];
-
- if ($this->QuotePage->del($id)) {
-
-
- $this->Session->setFlash(__('Quote Page deleted', true));
- $this->redirect(array('controller' => 'quotes' , 'action'=>'view', $quoteid));
- }
- }
-
-
- function show($id = null) {
- $this->layout = 'ajax';
- $this->set('quotePage', $this->QuotePage->read(null, $id));
-
- }
-
- function frame($id = null) {
- $this->layout = 'ajax';
- $this->set('id', $id);
- }
-
-
- function regeneratePage($id = null) {
- if(!$id) {
- $this->Session->setFlash(__('Invalid id for QuotePage', true));
- $this->redirect(array('action'=>'index'));
- }
- else {
- $quotePage = $this->QuotePage->read(null, $id);
-
- //$enquiry = $this->QuotePage->Quote->Enquiry->find('all', array('conditions' => array('Enquiry.id' => $quotePage['Quote']['enquiry_id'])));
-
- $enquiry = $this->QuotePage->Quote->Enquiry->read(null, $quotePage['Quote']['enquiry_id']);
-
- // $quote = $this->QuotePage->Quote->find('all', array('conditions' => array('Quote.id' => $quotePage['Quote']['id'])));
-
- $quoteProducts = $this->QuotePage->Quote->LineItem->find('all', array('recursive' => 0, 'conditions' =>
- array('LineItem.quote_id' => $quotePage['Quote']['id']),
- 'order' => array('LineItem.item_number ASC'))
- );
-
- $contactFirstName = $enquiry['Contact']['first_name'];
-
- $salesEngineerName = $enquiry['User']['first_name'].' '.$enquiry['User']['last_name'];
-
- $productRows = "";
-
-
- foreach($quoteProducts as $quoteproduct) {
-
- $itemNumber = $quoteproduct['LineItem']['item_number'];
- $title = $quoteproduct['LineItem']['title'];
-
- if($quoteproduct['LineItem']['option'] == 1) {
- $optionText = "Option ";
- }
- else {
- $optionText = "";
- }
-
- $productRows .= <<
- $optionText
- $itemNumber
-
-
- $title
-
-
-ENDROW;
-
- }
-
-
- $this->data['QuotePage']['content'] = <<
- -
Thank for your recent enquiry. Please see the following quotation for:
- -| Item | -Product | -
|---|
Regards,
- -$salesEngineerName
- -ENDCONTENT; - - - - if (!empty($this->data)) { - if ($this->QuotePage->save($this->data)) { - $this->Session->setFlash(__('The QuotePage has been saved', true)); - $id = $quotePage['Quote']['id']; - $this->redirect(array('controller' => 'quotes', 'action'=>'view/'.$id)); - } else { - $this->Session->setFlash(__('The QuotePage could not be saved. Please, try again.', true)); - } - } - - - - debug($quotePage); - - echo "