示例#1
0
 protected function search($params, $categories)
 {
     $contactsDb = new Contacts_Model_DbTable_Contact();
     $columns = array('c.id', 'c.name1', 'c.name2', 'a.postcode', 'a.street', 'a.postcode', 'a.city', 'a.country', 'p.phone', 'e.email', 'i.internet');
     $query = '';
     $schema = 'c';
     if ($params['keyword']) {
         $query = $this->_helper->Query->getQueryKeyword($query, $params['keyword'], $columns);
     }
     if ($params['catid']) {
         $query = $this->_helper->Query->getQueryCategory($query, $params['catid'], $categories, $schema);
     }
     if ($params['country']) {
         $query = $this->_helper->Query->getQueryCountryC($query, $params['country'], 'a');
     }
     if ($query) {
         $query .= " AND a.type = 'primaryAddress'";
         $query .= ' AND c.clientid = ' . $this->_user['clientid'];
     }
     $order = $params['order'];
     if ($order == 'street' || $order == 'postcode' || $order == 'city' || $order == 'country') {
         $order = 'a.' . $order;
     } else {
         $order = 'c.' . $order;
     }
     $contacts = $contactsDb->fetchAll($contactsDb->select()->setIntegrityCheck(false)->from(array($schema => 'contact'))->join(array('a' => 'address'), 'c.id = a.contactid', array('street', 'postcode', 'city', 'country'))->joinLeft(array('p' => 'phone'), 'c.id = p.contactid', array('phones' => new Zend_Db_Expr('GROUP_CONCAT(DISTINCT p.phone)')))->joinLeft(array('e' => 'email'), 'c.id = e.contactid', array('emails' => new Zend_Db_Expr('GROUP_CONCAT(DISTINCT e.email)')))->joinLeft(array('i' => 'internet'), 'c.id = i.contactid', array('internets' => new Zend_Db_Expr('GROUP_CONCAT(DISTINCT i.internet)')))->group($schema . '.id')->where($query ? $query : 1)->order($order . ' ' . $params['sort'])->limit($params['limit']));
     return $contacts;
 }
示例#2
0
 public function editAction()
 {
     $request = $this->getRequest();
     $id = $this->_getParam('id', 0);
     $activeTab = $request->getCookie('tab', null);
     $quoteDb = new Sales_Model_DbTable_Quote();
     $quote = $quoteDb->getQuote($id);
     if ($quote['quoteid']) {
         $this->_helper->redirector->gotoSimple('view', 'quote', null, array('id' => $id));
     } elseif ($this->isLocked($quote['locked'], $quote['lockedtime'])) {
         if ($request->isPost()) {
             header('Content-type: application/json');
             $this->_helper->viewRenderer->setNoRender();
             $this->_helper->getHelper('layout')->disableLayout();
             echo Zend_Json::encode(array('message' => $this->view->translate('MESSAGES_LOCKED')));
         } else {
             $this->_flashMessenger->addMessage('MESSAGES_LOCKED');
             $this->_helper->redirector('index');
         }
     } else {
         $quoteDb->lock($id, $this->_user['id'], $this->_date);
         $form = new Sales_Form_Quote();
         $options = $this->_helper->Options->getOptions($form, $this->_user['clientid']);
         //Get contact
         if ($quote['contactid']) {
             $contactDb = new Contacts_Model_DbTable_Contact();
             $contact = $contactDb->getContact($quote['contactid']);
             //Phone
             $phoneDb = new Contacts_Model_DbTable_Phone();
             $contact['phone'] = $phoneDb->getPhone($quote['contactid']);
             //Email
             $emailDb = new Contacts_Model_DbTable_Email();
             $contact['email'] = $emailDb->getEmail($quote['contactid']);
             //Internet
             $internetDb = new Contacts_Model_DbTable_Internet();
             $contact['internet'] = $internetDb->getInternet($quote['contactid']);
             $this->view->contact = $contact;
         }
         if ($request->isPost()) {
             header('Content-type: application/json');
             $this->_helper->viewRenderer->setNoRender();
             $this->_helper->getHelper('layout')->disableLayout();
             $data = $request->getPost();
             $element = key($data);
             if (isset($form->{$element}) && $form->isValidPartial($data)) {
                 $data['contactperson'] = $this->_user['name'];
                 $data['modified'] = $this->_date;
                 $data['modifiedby'] = $this->_user['id'];
                 if (isset($data['taxfree'])) {
                     $calculations = $this->_helper->Calculate($id, $this->_currency, $this->_date, $this->_user['id'], $data['taxfree']);
                     $data['subtotal'] = $calculations['subtotal'];
                     $data['taxes'] = $calculations['taxes'];
                     $data['total'] = $calculations['total'];
                 }
                 $quoteDb->updateQuote($id, $data);
                 echo Zend_Json::encode($quoteDb->getQuote($id));
             } else {
                 echo Zend_Json::encode(array('message' => $this->view->translate('MESSAGES_FORM_IS_INVALID')));
             }
         } else {
             if ($id > 0) {
                 $data = $quote;
                 if ($quote['contactid']) {
                     $data['contactinfo'] = $contact['info'];
                     $form->contactinfo->setAttrib('data-id', $contact['id']);
                     $form->contactinfo->setAttrib('data-controller', 'contact');
                     $form->contactinfo->setAttrib('data-module', 'contacts');
                     $form->contactinfo->setAttrib('readonly', null);
                 }
                 $form->populate($data);
                 //Toolbar
                 $toolbar = new Sales_Form_Toolbar();
                 $toolbar->state->setValue($data['state']);
                 $toolbarPositions = new Sales_Form_ToolbarPositions();
                 $this->view->form = $form;
                 $this->view->activeTab = $activeTab;
                 $this->view->toolbar = $toolbar;
                 $this->view->toolbarPositions = $toolbarPositions;
                 $this->view->textblocks = $this->getTextblocks();
             }
         }
     }
     $this->view->messages = $this->_flashMessenger->getMessages();
 }
示例#3
0
 public function editAction()
 {
     $request = $this->getRequest();
     $id = $this->_getParam('id', 0);
     //		$element = $this->_getParam('element', null);
     $activeTab = $request->getCookie('tab', null);
     $processDb = new Processes_Model_DbTable_Process();
     $process = $processDb->getProcess($id);
     if ($process['completed'] || $process['cancelled']) {
         $this->_helper->redirector->gotoSimple('view', 'process', null, array('id' => $id));
     } elseif ($this->isLocked($process['locked'], $process['lockedtime'])) {
         if ($request->isPost()) {
             header('Content-type: application/json');
             $this->_helper->viewRenderer->setNoRender();
             $this->_helper->getHelper('layout')->disableLayout();
             echo Zend_Json::encode(array('message' => $this->view->translate('MESSAGES_LOCKED')));
         } else {
             $this->_flashMessenger->addMessage('MESSAGES_LOCKED');
             $this->_helper->redirector('index');
         }
     } else {
         $processDb->lock($id, $this->_user['id'], $this->_date);
         $form = new Processes_Form_Process();
         $options = $this->_helper->Options->getOptions($form, $this->_user['clientid']);
         //Get contact
         if ($process['customerid']) {
             $contactDb = new Contacts_Model_DbTable_Contact();
             $contact = $contactDb->getContact($process['customerid']);
             //Phone
             $phoneDb = new Contacts_Model_DbTable_Phone();
             $contact['phone'] = $phoneDb->getPhone($process['customerid']);
             //Email
             $emailDb = new Contacts_Model_DbTable_Email();
             $contact['email'] = $emailDb->getEmail($process['customerid']);
             //Internet
             $internetDb = new Contacts_Model_DbTable_Internet();
             $contact['internet'] = $internetDb->getInternet($process['customerid']);
             $this->view->contact = $contact;
         }
         if ($request->isPost()) {
             header('Content-type: application/json');
             $this->_helper->viewRenderer->setNoRender();
             $this->_helper->getHelper('layout')->disableLayout();
             $data = $request->getPost();
             $element = key($data);
             if (isset($form->{$element}) && $form->isValidPartial($data)) {
                 $data['contactperson'] = $this->_user['name'];
                 $data['modified'] = $this->_date;
                 $data['modifiedby'] = $this->_user['id'];
                 if (isset($data['taxfree'])) {
                     $calculations = $this->_helper->Calculate($id, $this->_currency, $this->_date, $this->_user['id'], $data['taxfree']);
                     $data['subtotal'] = $calculations['subtotal'];
                     $data['taxes'] = $calculations['taxes'];
                     $data['total'] = $calculations['total'];
                 }
                 if (isset($data['total'])) {
                     $data['total'] = Zend_Locale_Format::getNumber($data['total'], array('precision' => 2, 'locale' => $locale));
                 }
                 if (isset($data['supplierinvoicetotal'])) {
                     $data['supplierinvoicetotal'] = Zend_Locale_Format::getNumber($data['supplierinvoicetotal'], array('precision' => 2, 'locale' => $locale));
                 }
                 if (isset($data['prepaymenttotal'])) {
                     $data['prepaymenttotal'] = Zend_Locale_Format::getNumber($data['prepaymenttotal'], array('precision' => 2, 'locale' => $locale));
                 }
                 $processDb->updateProcess($id, $data);
                 echo Zend_Json::encode($processDb->getProcess($id));
             } else {
                 echo Zend_Json::encode(array('message' => $this->view->translate('MESSAGES_FORM_IS_INVALID')));
             }
         } else {
             if ($id > 0) {
                 $data = $process;
                 if ($process['customerid']) {
                     $data['customerinfo'] = $contact['info'];
                     $form->customerinfo->setAttrib('data-id', $contact['id']);
                     $form->customerinfo->setAttrib('data-controller', 'contact');
                     $form->customerinfo->setAttrib('data-module', 'contacts');
                     $form->customerinfo->setAttrib('readonly', null);
                 }
                 $data['total'] = $this->_currency->toCurrency($data['total']);
                 $data['prepaymenttotal'] = $this->_currency->toCurrency($data['prepaymenttotal']);
                 $data['creditnotetotal'] = $this->_currency->toCurrency($data['creditnotetotal']);
                 if ($process['editpositionsseparately']) {
                     $form->deliverystatus->setAttrib('disabled', 'disabled');
                     $form->shippingmethod->setAttrib('disabled', 'disabled');
                     $form->deliverydate->setAttrib('disabled', 'disabled');
                     $form->shipmentdate->setAttrib('disabled', 'disabled');
                     $form->shipmentnumber->setAttrib('disabled', 'disabled');
                     $form->deliveryorderid->setAttrib('disabled', 'disabled');
                     $form->deliveryorderdate->setAttrib('disabled', 'disabled');
                     $form->supplierid->setAttrib('disabled', 'disabled');
                     $form->purchaseorderid->setAttrib('disabled', 'disabled');
                     $form->suppliersalesorderid->setAttrib('disabled', 'disabled');
                     $form->supplierinvoiceid->setAttrib('disabled', 'disabled');
                     $form->supplierinvoicetotal->setAttrib('disabled', 'disabled');
                     $form->supplierorderstatus->setAttrib('disabled', 'disabled');
                     $form->suppliername->setAttrib('disabled', 'disabled');
                     $form->purchaseorderdate->setAttrib('disabled', 'disabled');
                     $form->suppliersalesorderdate->setAttrib('disabled', 'disabled');
                     $form->supplierinvoicedate->setAttrib('disabled', 'disabled');
                     $form->supplierpaymentdate->setAttrib('disabled', 'disabled');
                 }
                 $form->populate($data);
                 //Toolbar
                 $toolbar = new Processes_Form_Toolbar();
                 $toolbar->state->setValue($data['state']);
                 $toolbarPositions = new Processes_Form_ToolbarPositions();
                 $this->view->form = $form;
                 $this->view->activeTab = $activeTab;
                 $this->view->toolbar = $toolbar;
                 $this->view->toolbarPositions = $toolbarPositions;
             }
         }
     }
     $this->view->messages = $this->_flashMessenger->getMessages();
 }