From d75eeb28deb9abdfe55f3323baae74cdcd17569c Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Thu, 19 May 2011 17:05:01 +1000 Subject: [PATCH] FUCK YEAH --- controllers/documents_controller.php | 193 +++++++++++-------- controllers/line_items_controller.php | 196 +++----------------- controllers/shipments_controller.php | 4 +- models/document.php | 3 +- models/line_item.php | 67 +++---- views/documents/ajax_edit.ctp | 0 views/documents/get_product_details.ctp | 1 + views/documents/get_products.ctp | 1 + views/documents/view.ctp | 22 ++- views/elements/add_edit_line_item.ctp | 19 ++ views/elements/document_quote_view.ctp | 11 +- views/line_items/add.ctp | 25 +-- views/line_items/ajax_add.ctp | 0 views/line_items/edit.ctp | 36 +--- views/line_items/get_table.ctp | 50 +++++ views/line_items/index.ctp | 108 ----------- views/line_items/principle_products.ctp | 12 -- views/line_items/product_options.ctp | 56 ------ views/line_items/view.ctp | 234 ------------------------ views/line_items/view_table.ctp | 162 ---------------- views/products/edit.ctp | 61 +++--- webroot/css/quotenik.css | 29 +++ webroot/js/document_add_edit.js | 120 +++++++++--- webroot/js/edit_product.js | 3 + webroot/js/global.js | 18 +- 25 files changed, 446 insertions(+), 985 deletions(-) create mode 100644 views/documents/ajax_edit.ctp create mode 100644 views/documents/get_product_details.ctp create mode 100644 views/documents/get_products.ctp create mode 100644 views/elements/add_edit_line_item.ctp mode change 100755 => 100644 views/line_items/add.ctp create mode 100644 views/line_items/ajax_add.ctp mode change 100755 => 100644 views/line_items/edit.ctp create mode 100644 views/line_items/get_table.ctp delete mode 100755 views/line_items/index.ctp delete mode 100755 views/line_items/principle_products.ctp delete mode 100755 views/line_items/product_options.ctp delete mode 100755 views/line_items/view.ctp delete mode 100755 views/line_items/view_table.ctp create mode 100644 webroot/js/edit_product.js 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 @@ +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 @@ +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; } ?> +
+ +
+ + +
input("DocPage.content", array('class'=>'page', 'label'=>'Page', 'between'=>'')); + echo $form->input("DocPage.content", array('class'=>'page', 'label'=>'Page', 'between'=>'')); ?>
-
- input('Product.principle_id', array('id'=>'principleSelect', 'label'=>'Principle','empty'=>'Select Principle'));?> - -
\ No newline at end of file +
+
+ + \ No newline at end of file diff --git a/views/elements/add_edit_line_item.ctp b/views/elements/add_edit_line_item.ctp new file mode 100644 index 00000000..b746ab51 --- /dev/null +++ b/views/elements/add_edit_line_item.ctp @@ -0,0 +1,19 @@ +input('Product.principle_id', array('id'=>'principleSelect', 'label'=>'Principle','empty'=>'Select Principle'));?> +
+
+ +
+ create('LineItem', array('default'=>false)); + echo $form->input('LineItem.document_id', array('type'=>'hidden', 'value'=>$document['Document']['id'])); + echo $form->input('LineItem.item_number'); + echo $form->input('LineItem.option'); + echo $form->input('LineItem.quantity'); + echo $form->input('LineItem.title'); + echo $form->input('LineItem.description'); + echo $form->input('LineItem.product_id', array('type'=>'hidden')); + echo $form->end(); + ?> + +
+ diff --git a/views/elements/document_quote_view.ctp b/views/elements/document_quote_view.ctp index 98282059..7107897a 100644 --- a/views/elements/document_quote_view.ctp +++ b/views/elements/document_quote_view.ctp @@ -6,7 +6,7 @@ if($document['Quote']['revision'] > 0) { create('Document',array('type'=>'post','action'=>'edit')); +echo $form->create('Document',array('type'=>'post','action'=>'edit', 'default'=>false)); echo $form->input('Document.id'); ?> @@ -15,6 +15,9 @@ echo $form->input('Document.id'); +
+
+
$page):?> @@ -27,11 +30,11 @@ echo $form->input('Document.id');
- -end('Save');?> +
+end();?> data);?> - + diff --git a/views/line_items/add.ctp b/views/line_items/add.ctp old mode 100755 new mode 100644 index 5dc1657a..9bc45ffc --- a/views/line_items/add.ctp +++ b/views/line_items/add.ctp @@ -1,24 +1 @@ -
-create('LineItem');?> -
- - input('item_number'); - echo $form->input('option'); - echo $form->input('product_id'); - echo $form->input('quantity'); - echo $form->input('title'); - echo $form->input('description'); - echo $form->input('document_id'); - echo $form->input('unit_price'); - echo $form->input('net_price_each'); - echo $form->input('discount_percent'); - echo $form->input('discount_amount_each'); - echo $form->input('total_discount_amount'); - echo $form->input('gross_price'); - echo $form->input('net_price'); - ?> -
-end('Submit');?> -
- +element('add_edit_line_item');?> \ No newline at end of file diff --git a/views/line_items/ajax_add.ctp b/views/line_items/ajax_add.ctp new file mode 100644 index 00000000..e69de29b diff --git a/views/line_items/edit.ctp b/views/line_items/edit.ctp old mode 100755 new mode 100644 index 216e122d..9bc45ffc --- a/views/line_items/edit.ctp +++ b/views/line_items/edit.ctp @@ -1,35 +1 @@ -
-create('LineItem');?> -
- - input('id'); - echo $form->input('item_number'); - echo $form->input('option'); - echo $form->input('quantity'); - echo $form->input('title'); - echo $form->input('description'); - echo $form->input('document_id'); - echo $form->input('product_id'); - echo $form->input('costing_id'); - echo $form->input('unit_price'); - echo $form->input('net_price_each'); - echo $form->input('discount_percent'); - echo $form->input('discount_amount_each'); - echo $form->input('total_discount_amount'); - echo $form->input('gross_price'); - echo $form->input('net_price'); - ?> -
-end('Submit');?> -
-
- -
+element('add_edit_line_item');?> \ No newline at end of file diff --git a/views/line_items/get_table.ctp b/views/line_items/get_table.ctp new file mode 100644 index 00000000..66187e25 --- /dev/null +++ b/views/line_items/get_table.ctp @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ITEM
NO.
QTYDESCRIPTIONUNIT + TOTAL
PRICE
ACTIONS
+ + + + + + +
+ +
\ No newline at end of file diff --git a/views/line_items/index.ctp b/views/line_items/index.ctp deleted file mode 100755 index abe1801e..00000000 --- a/views/line_items/index.ctp +++ /dev/null @@ -1,108 +0,0 @@ -
-

-

-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'])); ?> -
-
-
- prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?> - | numbers();?> - next(__('next', true).' >>', array(), null, array('class' => 'disabled'));?> -
-
- -
diff --git a/views/line_items/principle_products.ctp b/views/line_items/principle_products.ctp deleted file mode 100755 index 51e8ce24..00000000 --- a/views/line_items/principle_products.ctp +++ /dev/null @@ -1,12 +0,0 @@ -Select a Product'; - -if(!empty($products)) { - - foreach($products as $k => $v) { - echo ""; - } -} - -?> diff --git a/views/line_items/product_options.ctp b/views/line_items/product_options.ctp deleted file mode 100755 index f5f819e7..00000000 --- a/views/line_items/product_options.ctp +++ /dev/null @@ -1,56 +0,0 @@ -input('ProductOption.'.$opt['ProductOptionsCategory']['name'], - array('label' => $opt['ProductOptionsCategory']['name'], - 'options' => $drop_options, 'default' => $default_option)); - } - - else { - echo $form->input($opt['ProductOptionsCategory']['name'], - array('options' => $drop_options, 'default' => $default_option, - 'multiple' => 'checkbox')); - } - - unset($drop_options); -} - - - - - - - - -//print_r($categories); - -print_r($options); -?> diff --git a/views/line_items/view.ctp b/views/line_items/view.ctp deleted file mode 100755 index 2700e4e9..00000000 --- a/views/line_items/view.ctp +++ /dev/null @@ -1,234 +0,0 @@ -
-

-
- > - > - -   - - > - > - -   - - > - > - -   - - > - > - -   - - > - > - -   - - > - > - -   - - > - > - -   - - > - > - link($lineItem['Product']['title'], array('controller' => 'products', 'action' => 'view', $lineItem['Product']['id'])); ?> -   - - > - > - -   - - > - > - -   - - > - > - -   - - > - > - -   - - > - > - -   - - > - > - -   - - > - > - -   - - > - > - -   - -
-
-
- -
- - \ No newline at end of file diff --git a/views/line_items/view_table.ctp b/views/line_items/view_table.ctp deleted file mode 100755 index 92763369..00000000 --- a/views/line_items/view_table.ctp +++ /dev/null @@ -1,162 +0,0 @@ -link('editLineItem'); ?> - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > - - - - - - - - - - - - - - - - -
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'])); ?> -
\ No newline at end of file diff --git a/views/products/edit.ctp b/views/products/edit.ctp index aca18ed9..86cd3d7c 100755 --- a/views/products/edit.ctp +++ b/views/products/edit.ctp @@ -1,43 +1,32 @@ +link('ckeditor/ckeditor'); +echo $javascript->link('ckeditor/adapters/jquery'); +echo $javascript->link('edit_product'); +?> +
-create('Product');?> -
- + create('Product');?> +
+ input('id'); - echo $form->input('principle_id'); - echo $form->input('title'); - //echo $form->input('description'); - + echo $form->input('id'); + echo $form->input('principle_id'); + echo $form->input('title'); - /*echo "
"; - echo ""; - echo $fck->fckeditor(array('Product', 'description'), $description); - echo "
"; - */ - echo $form->input('description', array('class'=>'ckeditor')); + echo $form->input('description'); - echo $form->input('model_number'); - echo $form->input('model_number_format'); - echo $form->input('cost_price_each'); - echo $form->input('our_discount'); - echo $form->input('packing_each'); - echo $form->input('shipping_weight_each'); - echo $form->input('shipping_cost_each'); - echo $form->input('duty'); - echo $form->input('sellprice_each'); - echo $form->input('notes'); + echo $form->input('model_number'); + echo $form->input('model_number_format'); + echo $form->input('cost_price_each'); + echo $form->input('our_discount'); + echo $form->input('packing_each'); + echo $form->input('shipping_weight_each'); + echo $form->input('shipping_cost_each'); + echo $form->input('duty'); + echo $form->input('sellprice_each'); + echo $form->input('notes'); ?> -
-end(array('label' => 'Edit Product', 'class'=>'wymupdate'));?> -
-
- + + end(array('label' => 'Edit Product', 'class'=>'wymupdate'));?>
diff --git a/webroot/css/quotenik.css b/webroot/css/quotenik.css index 572107de..81d07f69 100755 --- a/webroot/css/quotenik.css +++ b/webroot/css/quotenik.css @@ -142,6 +142,8 @@ ul.principle-emails { /* background: #E9E9E9 url(../img/top-gradient2.png) repeat-x bottom; */ /* background: #4686c3 url(../img/gradient-blue4.png) repeat-x bottom; */ background: #4686c3; + height: 30px; + /* background: #6BBA70; */ padding-bottom: 2%; } @@ -1504,4 +1506,31 @@ div.address span { .pages label { display: inline; padding-right: 0.2em; +} + +#productDetails { + margin-top: 0.4em; + border: 1px solid; +} + +table.lineItems { + border: 1px solid; + border-spacing: 0px; +} + +table.lineItems tr td { + border: 1px solid; + border-spacing: 0px; +} + +table.lineItems tr th { + border: 1px solid; + border-spacing: 0px; + background-color: #f2f2f2; + padding: 0.5em; +} + +table.lineItems tr td.description { + text-align: left; + padding: 0.5em; } \ No newline at end of file diff --git a/webroot/js/document_add_edit.js b/webroot/js/document_add_edit.js index aabf308f..8e031c97 100644 --- a/webroot/js/document_add_edit.js +++ b/webroot/js/document_add_edit.js @@ -3,7 +3,13 @@ $(function() { + // var config defined in global.js + loadLineItems(); + + $("#flashMessage").hide(); + + $("#lineItemDetails").hide(); $( "#lineItemModal" ).dialog({ autoOpen: false, @@ -12,49 +18,41 @@ $(function() { modal: true, buttons: { "Add Line Item": function() { - //var thisShipmentInputs = $('#ShipmentAddForm').find('input,select,textarea'); + /*for ( instance in CKEDITOR.instances ) { + CKEDITOR.instances[instance].updateElement(); + CKEDITOR.instances[instance].destroy(); + }*/ + $('#LineItemDescription').ckeditor(function() { + this.updateElement(); + this.destroy(); + }); - $.post('/line_items/ajax_add', null, function(data) { + + var thisLineItemInputs = $('#LineItemAddForm').find('input,select,textarea'); + + $.post('/line_items/ajax_add', thisLineItemInputs, function(data) { $( "#lineItemModal" ).dialog('close'); - //window.location.reload(); //Change this to fetch a new copy of the table and update a
. + loadLineItems(); }); }, Cancel: function() { $( this ).dialog( "close" ); - //$("#ShipmentAddForm")[0].reset(); - $("#principlesList").empty(); + loadLineItems(); } }, close: function() { - - $("#importFields").hide(); - $("#principle").hide(); - + loadLineItems(); } }); - //Setup CKEditor toolbars - var config = { - toolbar:[ - - ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Scayt'], - ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], - ['Image','Table','HorizontalRule','SpecialChar'], - '/', - ['Styles','Format'], - ['Bold','Italic','Strike'], - ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'], - ['Link','Unlink'], - ['Maximize','-','About'] - ] - }; + $("#pageContentFactory").hide(); - + //Add a new Page Element. $("#addPage").button().click(function(event) { event.preventDefault(); @@ -96,25 +94,57 @@ $(function() { return false; }); + //Open the LineItem dialog $("#addLineItem").button().click(function() { - $( "#lineItemModal" ).dialog('open'); + var docID = $('#documentID').html(); + $.get('/line_items/add/'+docID, function(data) { + $("#lineItemModal").html(data); + $("#productDetails").hide(); + $('#LineItemDescription').ckeditor(config); + $( "#lineItemModal" ).dialog('open'); + + }); return false; }); - $("#principleSelect").change(function() { - alert("OH YEAH LETS DO THIS"); + + $("#principleSelect").live('change',function() { + + var principleID = getSelectedID('#principleSelect'); + + $("#productDetails").hide(); + + $.get('/documents/getProducts/'+principleID, function(data) { + $('#productsDiv').html(data); + }); }); + + $("#productSelect").live('change',function() { + + var productID = getSelectedID('#productSelect'); + + $.get('/documents/getProductDetails/'+productID, function(data) { + + $("#lineItemDetails").show(); + $("#LineItemProductId").val(data.id); + $("#LineItemTitle").val(data.title); + $("#LineItemDescription").val(data.description); + + + }, "json"); + }); // Initialize the editor. // Callback function can be passed and executed after full instance creation. $('.page').ckeditor(config); + //Remove this Page @@ -130,4 +160,38 @@ $(function() { }); + + $("#savePages").click(function() { + var docPages = $('#DocumentEditForm').find('input,select,textarea'); + + $('.page').ckeditor(function() { + this.updateElement(); + }); + + $.post('/documents/ajax_edit', docPages, function(data) { + if(data =='SUCCESS') { + $("#flashMessage").html("Pages Saved Successfully"); + } + else { + $("#flashMessage").html("Unable to Save Pages"); + } + + $("#flashMessage").show(); + + loadLineItems(); + }); + + }); + }); + + + +function loadLineItems() { + var documentID = $("#documentID").html(); + + $.get('/line_items/getTable/'+documentID, function(data) { + $("#lineItems").html(data); + }); + +} \ No newline at end of file diff --git a/webroot/js/edit_product.js b/webroot/js/edit_product.js new file mode 100644 index 00000000..82a6eda2 --- /dev/null +++ b/webroot/js/edit_product.js @@ -0,0 +1,3 @@ +$(function() { + $('#ProductDescription').ckeditor(config); +}); \ No newline at end of file diff --git a/webroot/js/global.js b/webroot/js/global.js index 82d5379f..d171ac6c 100644 --- a/webroot/js/global.js +++ b/webroot/js/global.js @@ -48,4 +48,20 @@ function getSelectedText(elementID) { text = $(selected).text(); }); return text; -} \ No newline at end of file +} + +//Setup CKEditor toolbars +var config = { + toolbar:[ + + ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Scayt'], + ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], + ['Image','Table','HorizontalRule','SpecialChar'], + '/', + ['Styles','Format'], + ['Bold','Italic','Strike'], + ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'], + ['Link','Unlink'], + ['Maximize','-','About'] + ] +}; \ No newline at end of file