diff --git a/controllers/documents_controller.php b/controllers/documents_controller.php index 311674ee..11359bf4 100755 --- a/controllers/documents_controller.php +++ b/controllers/documents_controller.php @@ -5,38 +5,38 @@ class DocumentsController extends AppController { var $helpers = array('Html', 'Form'); function index() { - $this->Document->recursive = 0; - $this->set('documents', $this->paginate()); + $this->Document->recursive = 0; + $this->set('documents', $this->paginate()); } 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); + if (!$id) { + $this->Session->setFlash(__('Invalid Document.', true)); + $this->redirect(array('action'=>'index')); + } + $document = $this->Document->read(null, $id); + $this->set('document', $document); - $docType = ""; + $docType = ""; - if(!empty($document['Invoice']['id'])) { - $docType = "invoice"; - } - elseif(!empty($document['Quote']['id'])) { - $docType = "quote"; + 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"; - } + } + elseif(!empty($document['PurchaseOrder']['id'])) { + $docType = "purchaseOrder"; + } - $this->data = $document; + $this->data = $document; $this->set('docType',$docType); - $this->set('principles', $this->Document->LineItem->Product->Principle->find('list')); +// $this->set('principles', $this->Document->LineItem->Product->Principle->find('list')); } @@ -48,6 +48,26 @@ class DocumentsController extends AppController { 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); + } } /** @@ -55,30 +75,30 @@ class DocumentsController extends AppController { * @param int $id - the Enquiry ID that this quote belongs to. */ function newQuote($id = null) { - $enquiryid = $id; - $this->Document->create(); + $enquiryid = $id; + $this->Document->create(); - $enquiry = $this->Document->Quote->Enquiry->findById($id); + $enquiry = $this->Document->Quote->Enquiry->findById($id); - $this->data['Document']['enquiry_id'] = $enquiryid; + $this->data['Document']['enquiry_id'] = $enquiryid; - $this->data['Quote']['enquiry_id'] = $enquiryid; - $number_of_revisions = $this->Document->Quote->findCount('Quote.enquiry_id ='. $enquiryid); - $this->data['Quote']['revision'] = $number_of_revisions; + $this->data['Quote']['enquiry_id'] = $enquiryid; + $number_of_revisions = $this->Document->Quote->findCount('Quote.enquiry_id ='. $enquiryid); + $this->data['Quote']['revision'] = $number_of_revisions; - $this->data['Document']['user_id']= $enquiry['Enquiry']['user_id']; - - + $this->data['Document']['user_id']= $enquiry['Enquiry']['user_id']; - 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. Please, try again.', true)); - } + + 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. Please, try again.', true)); + } } @@ -90,36 +110,36 @@ class DocumentsController extends AppController { * @param int $id - the Enquiry ID that this quote belongs to. */ function newInvoice($id = null) { - $enquiryid = $id; - $this->Document->create(); + $enquiryid = $id; + $this->Document->create(); - $enquiry = $this->Document->Enquiry->findById($id); + $enquiry = $this->Document->Enquiry->findById($id); - $this->data['Document']['enquiry_id'] = $enquiryid; + $this->data['Document']['enquiry_id'] = $enquiryid; - $this->data['Invoice']['enquiry_id'] = $enquiryid; - $invoice_number_offset = 4436; //What Invoice number we were up to before the new system. - $number_of_invoices = $this->Document->Invoice->findCount(); + $this->data['Invoice']['enquiry_id'] = $enquiryid; + $invoice_number_offset = 4436; //What Invoice number we were up to before the new system. + $number_of_invoices = $this->Document->Invoice->findCount(); - $newInvoiceNumber = $invoice_number_offset + $number_of_invoices; + $newInvoiceNumber = $invoice_number_offset + $number_of_invoices; - $this->data['Invoice']['title'] = "CMCIN".$newInvoiceNumber; + $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']['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; - if ($this->Document->saveAll($this->data)) { - $newid = $this->Document->id; + 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. Please, try again.', true)); - } + $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. Please, try again.', true)); + } } @@ -129,27 +149,50 @@ class DocumentsController extends AppController { function edit($id = null) { - if (!$id && empty($this->data)) { - $this->Session->setFlash(__('Invalid Document', true)); - $this->redirect(array('action'=>'index')); - } - if (!empty($this->data)) { + if (!$id && empty($this->data)) { + $this->Session->setFlash(__('Invalid Document', true)); + $this->redirect(array('action'=>'index')); + } + 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)) { - $this->Session->setFlash(__('The Document has been saved', true)); - $this->redirect(array('action'=>'index')); - } else { - $this->Session->setFlash(__('The Document could not be saved. Please, try again.', true)); - } - } - if (empty($this->data)) { - $this->data = $this->Document->read(null, $id); - } - + if ($this->Document->saveAll($this->data)) { + $this->Session->setFlash(__('The Document has been saved', true)); + $this->redirect(array('action'=>'index')); + } else { + $this->Session->setFlash(__('The Document could not be saved. Please, try again.', true)); + } + } + if (empty($this->data)) { + $this->data = $this->Document->read(null, $id); + } + + } + + + 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'; + } } /*function delete($id = null) { diff --git a/controllers/line_items_controller.php b/controllers/line_items_controller.php index 4fcf3bf0..47454cfd 100755 --- a/controllers/line_items_controller.php +++ b/controllers/line_items_controller.php @@ -6,191 +6,51 @@ class LineItemsController extends AppController { var $components = array('RequestHandler'); - function index() { - $this->LineItem->recursive = 0; - $this->set('lineItems', $this->paginate()); - } - function view($id = null) { - if (!$id) { - $this->Session->setFlash(__('Invalid LineItem.', true)); - $this->redirect(array('action'=>'index')); - } - $this->set('lineItem', $this->LineItem->read(null, $id)); - } - function add($documentID = null) { + function ajax_add() { $this->layout = 'ajax'; - if (!$documentID && empty($this->data)) { - $this->Session->setFlash(__('Invalid Document ID', true)); - $this->redirect(array('action'=>'index')); - } + if(!empty($this->data)) { + $this->LineItem->create($this->data); - if (!empty($this->data)) { - $this->LineItem->create(); - - if ($this->LineItem->save($this->data)) { - $documentID = $this->data['LineItem']['document_id']; - - $this->Session->setFlash(__('Product Added to Quote Successfully', true)); - $this->redirect(array('controller'=>'documents', 'action'=>'view', $documentID)); - } else { - $this->Session->setFlash(__('The LineItem could not be saved. Please, try again.', true)); - } - } - - - $principles = $this->LineItem->Product->Principle->find('list'); - $products = $this->LineItem->Product->find('list'); - - $this->set(compact('principles', 'products')); + if ($this->LineItem->saveAll($this->data)) { + echo "SUCCESS"; + } + else { + echo "FAILURE"; + } + } + else { + echo "NO-DATA"; + } } - /* Process the Line Item and add it to a quote */ - function ajaxSave() { - - - if($this->RequestHandler->isAjax()) { - - if (!empty($this->data)) { - $this->LineItem->create(); - - if(isset($this->data['LineItem']['product_id'])) { - $product = $this->LineItem->Product->findById($this->data['LineItem']['product_id']); - - /* Copy all the data from the Product to the new LineItem */ - - $this->data['LineItem']['description'] = $product['Product']['description']; - - - - $this->data['LineItem']['title'] = $product['Product']['title']; - } - - - - - if($this->LineItem->save($this->data)) { - echo 'success'; - } - else { - echo 'failure'; - } - Configure::write('debug', 0); - $this->autoRender = false; - exit(); - - - /* Need to find a way to append Product Option data to the description / model number title */ - - - } - - - } - - - + function getTable($documentID = null) { + $this->layout = 'ajax'; + if($documentID == null) { + echo "INVALID DOCUMENT ID"; + } + else { + $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); + } } - /* Display a list of Products for a given principle. Used for the add() method */ - function principle_products() { - if (empty($this->data['LineItem']['principle_id'])) { - } - else { - $this->set('products', $this->LineItem->Product->find('list', array('conditions'=>array('Product.principle_id'=>$this->data['LineItem']['principle_id'])))); - } - } - - - /* Display a list of Options (if any) for a given Product. Used for the add() method */ - function product_options() { - - /*$this->set('categories', $this->LineItem->Product->ProductOptionsCategory->find('list'), - array('conditions' => array('ProductOptionsCategory.product_id'=>$this->data['LineItem']['product_id']), - 'order'=>'ProductOptionsCategory.location ASC') );*/ - - $this->set('options', $this->LineItem->Product->ProductOptionsCategory->find('all', - array('conditions' => array('ProductOptionsCategory.product_id'=>$this->data['LineItem']['product_id']), - 'order'=>'ProductOptionsCategory.location ASC'))); - - - } - - - function edit($id = null) { - - if (!$id && empty($this->data)) { - $this->Session->setFlash(__('Invalid LineItem', true)); - $this->redirect(array('action'=>'index')); - } - - - - if (!empty($this->data)) { - if ($this->LineItem->save($this->data)) { - $this->Session->setFlash(__('The LineItem has been saved', true)); - $this->redirect(array('action'=>'index')); - } else { - $this->Session->setFlash(__('The LineItem could not be saved. Please, try again.', true)); - } - } - if (empty($this->data)) { - $this->data = $this->LineItem->read(null, $id); - } - - $quotes = $this->LineItem->Quote->find('list'); - $products = $this->LineItem->Product->find('list'); - $this->set(compact('quotes','products')); } - function delete($id = null) { - - $thisQP = $this->LineItem->read(null, $id); - - if (!$id) { - $this->Session->setFlash(__('Invalid id for LineItem', true)); - $this->redirect(array('action'=>'index')); - } - if ($this->LineItem->del($id)) { - $this->Session->setFlash(__('LineItem deleted', true)); - $this->redirect(array('controller'=>'quotes', 'action'=>'view/'.$thisQP['Quote']['id'])); - } + function add($documentID = null) { + $document = $this->LineItem->Document->read(null, $documentID); + $this->set('document', $document); + $this->set('principles', $this->LineItem->Product->Principle->find('list')); } - - - function viewTable() { - - - if($this->RequestHandler->isAjax()) { - if (!empty($this->data)) { - if($this->data['LineItem']['quote_id'] != null) { - $quoteid = $this->data['LineItem']['quote_id']; - - $lineItems = $this->LineItem->find('all', array('recursive' => 0, 'conditions' => array('LineItem.quote_id' => $quoteid), - 'order' => array('LineItem.item_number ASC')) - ); - - $quote = $this->LineItem->Quote->read(null, $quoteid); - $this->set('quote', $quote); - - $this->set('lineItems', $lineItems); - } - } - else { - //Was POSTed with no data. - $this->set('lineItems', 'Something has broken. Requesting a LineItem table without POSTing a quote or job ID'); - } - } - } - - } ?> diff --git a/controllers/shipments_controller.php b/controllers/shipments_controller.php index 2fbaa2fe..2351cc6a 100644 --- a/controllers/shipments_controller.php +++ b/controllers/shipments_controller.php @@ -178,13 +178,13 @@ class ShipmentsController extends AppController { function ajax_add() { - //$this->layout = 'ajax'; + $this->layout = 'ajax'; if(!empty($this->data)) { $this->Shipment->create($this->data); if ($this->Shipment->saveAll($this->data)) { echo "SUCCESS"; - print_r($this->data); + } else { echo "FAILURE"; diff --git a/models/document.php b/models/document.php index 4d8a95b9..9115a7a6 100755 --- a/models/document.php +++ b/models/document.php @@ -20,7 +20,8 @@ class Document extends AppModel { 'LineItem' => array( 'className' => 'LineItem', - 'foreignKey' => 'document_id' + 'foreignKey' => 'document_id', + 'order' => 'LineItem.item_number ASC' ), 'DocPage' => array( diff --git a/models/line_item.php b/models/line_item.php index dbbf3729..cded3ee0 100755 --- a/models/line_item.php +++ b/models/line_item.php @@ -1,41 +1,46 @@ array('className' => 'Product', + 'foreignKey' => 'product_id', + 'conditions' => '', + 'fields' => '', + 'order' => '' + ), + + 'Document' => array('className'=> 'Document', + 'foreignKey' => 'document_id', + + ) + ); + + + var $hasOne = array( + 'Costing' => array('className' => 'Costing', + 'foreignKey' => 'line_item_id') + ); - - - - //The Associations below have been created with all possible keys, those that are not needed can be removed - - - - var $belongsTo = array( - 'Product' => array('className' => 'Product', - 'foreignKey' => 'product_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ) - ); - - - var $hasOne = array( - 'Costing' => array('className' => 'Costing', - 'foreignKey' => 'line_item_id') - ); - - - var $order = "LineItem.item_number ASC"; } ?> \ No newline at end of file diff --git a/views/documents/ajax_edit.ctp b/views/documents/ajax_edit.ctp new file mode 100644 index 00000000..e69de29b diff --git a/views/documents/get_product_details.ctp b/views/documents/get_product_details.ctp new file mode 100644 index 00000000..bcb606a1 --- /dev/null +++ b/views/documents/get_product_details.ctp @@ -0,0 +1 @@ +=$javascript->object($product['Product']);?> \ No newline at end of file diff --git a/views/documents/get_products.ctp b/views/documents/get_products.ctp new file mode 100644 index 00000000..af1c6eef --- /dev/null +++ b/views/documents/get_products.ctp @@ -0,0 +1 @@ +=$form->input('product', array('label'=>'Product', 'id'=>'productSelect', 'empty'=>'Choose Products', 'options'=>$products));?> \ No newline at end of file diff --git a/views/documents/view.ctp b/views/documents/view.ctp index 36755503..26e4c94a 100755 --- a/views/documents/view.ctp +++ b/views/documents/view.ctp @@ -8,27 +8,33 @@ echo $javascript->link('document_add_edit'); switch($docType) { case 'quote': echo $this->element('document_quote_view'); - break; + break; case 'invoice': echo "INVOICE!!"; - break; + break; case 'purchaseOrder': echo 'Purchase OOOOORDER!!'; - break; + break; } ?> +
| ITEM NO. |
+ QTY | +DESCRIPTION | +UNIT| TOTAL |
+ PRICE ACTIONS |
+ |
|---|---|---|---|---|---|
| + | + | + | =$currencies[$document['Quote']['currency_id']]?> | +=$currencies[$document['Quote']['currency_id']]?> | ++ |
| =$li['item_number'];?> | +=$li['quantity'];?> | +=$li['title'];?> + =$li['description'];?> + | ++ =$li['unit_price'];?> + | ++ =$li['gross_price'];?> + | +
+ + + |
+
-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('item_number');?> | -sort('option');?> | -sort('quantity');?> | -sort('title');?> | -sort('description');?> | -sort('document_id');?> | -sort('product_id');?> | -sort('costing_id');?> | -sort('unit_price');?> | -sort('net_price_each');?> | -sort('discount_percent');?> | -sort('discount_amount_each');?> | -sort('total_discount_amount');?> | -sort('gross_price');?> | -sort('net_price');?> | -- |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| - - | -- - | -- - | -- - | -- - | -- - | -- - | -- link($lineItem['Product']['title'], array('controller' => 'products', 'action' => 'view', $lineItem['Product']['id'])); ?> - | -- - | -- - | -- - | -- - | -- - | -- - | -- - | -- - | -- link(__('View', true), array('action' => 'view', $lineItem['LineItem']['id'])); ?> - link(__('Edit', true), array('action' => 'edit', $lineItem['LineItem']['id'])); ?> - link(__('Delete', true), array('action' => 'delete', $lineItem['LineItem']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $lineItem['LineItem']['id'])); ?> - | -
| - | - | - | - | Unit Price () | - -() | - -- |
|---|---|---|---|---|---|---|
| - | - | - | SUB-TOTAL (Excluding GST) | -- | - | - |
| - | - | - | GST (10%) | -- | - | - |
| - | - | - | TOTAL PAYABLE | -- | - | -- |
| '; - } - echo number_format($lineItem['LineItem']['item_number'], 1, '.', '');?> | - -- | - | - - | less ".$lineItem['LineItem']['discount_percent']."% discount (-".
- $quote['Currency']['symbol'].$lineItem['LineItem']['discount_amount_each'].") "; - echo "= ".$quote['Currency']['symbol'].$lineItem['LineItem']['net_price_each']; - } - - ?> |
- - - | - - link(__('View/Edit', true), array('controller'=> 'line_items', 'action'=>'edit', $lineItem['LineItem']['id']), array('class'=>'editLink')); ?> - - - link(__('Remove', true), array('controller'=> 'line_items', 'action'=>'delete', $lineItem['LineItem']['id']), null, sprintf(__('Are you sure you want to remove # %s?', true), $lineItem['LineItem']['item_number'])); ?> - | - - -