/**
  * Modify Client Product Process
  */
 public function processModifyClientProductAction()
 {
     if (!$this->_request->isXmlHttpRequest() || !$this->_request->isPost()) {
         $this->_redirector->gotoRoute(array('controller' => 'index', 'module' => 'clients'), 'admin');
     }
     $return = array();
     $clientProductGateway = new Clients_Model_ClientProductGateway();
     $form = $clientProductGateway->getForm('ModifyClientProduct');
     $validForm = $form->isValid($this->_request->getParams());
     // Check the form for validity
     if (!$validForm) {
         $return['formErrors'] = $form->getMessages();
     } else {
         $form->removeElement('product_company_name');
         $form->removeElement('product_name');
         $formData = $form->getValues();
         //set correct date format for Product Issue Date
         $formData['client_product_issuedate'] = $this->_dateFormatter->saveDateFormat($formData['client_product_issuedate'], $formData['altIssueDate']);
         //set correct date format for Product Est Issue Date
         $formData['client_product_estissuedate'] = $this->_dateFormatter->saveDateFormat($formData['client_product_estissuedate'], $formData['altEstIssueDate']);
         unset($formData['altIssueDate']);
         unset($formData['altEstIssueDate']);
         $clientProduct = $clientProductGateway->create($formData);
         $clientProductId = $clientProduct->save();
         $clientProduct = $clientProductGateway->fetchClientProduct($clientProductId);
         if (is_object($clientProduct)) {
             $clientProduct = $clientProduct->toArray();
         }
         $clientProduct['client_product_issuedate'] = $this->_dateFormatter->viewDateFormat($clientProduct['client_product_issuedate']);
         $clientProduct['client_product_estissuedate'] = $this->_dateFormatter->viewDateFormat($clientProduct['client_product_estissuedate']);
         $flashMessenger = $this->_helper->getHelper('FlashMessenger');
         $flashMessenger->setNamespace('notifications')->addMessage('Client Product Modified');
         $return = array('append' => array('target' => '#clientProductList', 'content' => $this->view->partial('partials/_clientProductRow.phtml', 'clients', $clientProduct)), 'refresh' => true);
         $return['callback'] = '$("#modify-client-product-dialog").dialog("close");';
     }
     $this->_helper->json->sendJson($return);
 }
 /**
  * Save client product
  * @param
  * @return
  */
 public function save()
 {
     $data = $this->toArray();
     //Get cache to clear appropriate cache tag after save
     $cache = Zend_Controller_Action_HelperBroker::getStaticHelper('Cache')->getManager()->getCache('database');
     //If this product is marked as active and there is
     //another active product for this illustration change it to
     //an inactive state before saving this one
     if ($data['client_product_active']) {
         $productGateway = new Clients_Model_ClientProductGateway();
         $activeProducts = $productGateway->fetchActiveProductsByProposalAndIllnum($data);
         $activeProducts['client_product_active'] = '0';
         $this->getDbTable()->update($activeProducts, array('client_product_id = ?' => $activeProducts['client_product_id']));
     }
     //Save Client Product or update if exists
     if (!isset($data['client_product_id'])) {
         //Set defaults for dates not used at product initialization
         if (!$data['client_product_estissuedate']) {
             $data['client_product_estissuedate'] = '0000-00-00';
         }
         if (!$data['client_product_issuedate']) {
             $data['client_product_issuedate'] = '0000-00-00';
         }
         $data['client_product_id'] = $this->getDbTable()->insert($data);
     } else {
         $this->getDbTable()->update($data, array('client_product_id = ?' => $data['client_product_id']));
     }
     //Clear cache based on tag
     $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('clientProducts'));
     return $data['client_product_id'];
 }