/** * Check if the customer is subject to EU-VAT * TODO: add support for multiple invoicing addresses * * @param integer $id * @return boolean * @throws Exception */ public static function isVATFree($id) { if (!is_numeric($id)) { throw new Exception('Customer Id paramenter is mandatory'); } $customer = self::getAllInfo($id); // tax free also means vat free if (!empty($customer['taxfree']) && $customer['taxfree']) { return true; } $Addresses = Addresses::findOneByUserId($id); if (!isset($Addresses->country_id) || !is_numeric($Addresses->country_id)) { return false; } if (empty($customer['vat'])) { /* * Private */ //* EU country, VAT ok return !Countries::isUEbyId($Addresses->country_id); } else { /* * Company */ //* TODO: 82 is Italy. This should not be hardcoded here. return $Addresses->country_id != 82 ? true : false; } }
/** * processAction * Update the record previously selected * @return unknown_type */ public function processAction() { $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); $form = $this->getForm("/profile/process"); $request = $this->getRequest(); // Check if we have a POST request if (!$request->isPost()) { return $this->_helper->redirector('index', 'index', 'default'); } if ($form->isValid($request->getPost())) { // Get the id $id = $this->getRequest()->getParam('customer_id'); try { // Set the new values if (is_numeric($id)) { $customer = Doctrine::getTable('Customers')->find($id); $oldCustomer = $customer->toArray(); // Get the values posted $params = $form->getValues(); $customer->company = $params['company']; $customer->firstname = $params['firstname']; $customer->lastname = $params['lastname']; $customer->email = $params['email']; $customer->birthdate = Shineisp_Commons_Utilities::formatDateIn($params['birthdate']); if (!empty($params['password'])) { $customer->password = MD5($params['password']); } $customer->birthplace = $params['birthplace']; $customer->birthdistrict = $params['birthdistrict']; $customer->birthcountry = $params['birthcountry']; $customer->birthnationality = $params['birthnationality']; $customer->vat = $params['vat']; $customer->taxpayernumber = $params['taxpayernumber']; $customer->type_id = !empty($params['company_type_id']) ? $params['company_type_id'] : NULL; $customer->legalform_id = $params['legalform']; $customer->gender = $params['gender']; // Save the data $customer->save(); $id = is_numeric($id) ? $id : $customer->getIncremented(); // Manage the address of the customer $address = new Addresses(); $mainAddress = $address->findOneByUserId($id); if ($mainAddress) { $address = $mainAddress; } $address->address = $params['address']; $address->city = $params['city']; $address->code = $params['code']; $address->country_id = $params['country_id']; $address->area = $params['area']; $address->customer_id = $id; $address->save(); if (!empty($params['contact'])) { $contacts = new Contacts(); $contacts->contact = $params['contact']; $contacts->type_id = $params['contacttypes']; $contacts->customer_id = $id; $contacts->save(); } // Add or Remove the customer email in the newsletter list Customers::newsletter_subscription($id, $params['newsletter']); $retval = Shineisp_Commons_Utilities::getEmailTemplate('profile_changed'); if ($retval) { $subject = $retval['subject']; $subject = str_replace("[user]", $params['firstname'] . " " . $params['lastname'], $retval['subject']); // Alert the administrator about the changing of the customer information $body = $retval['template']; $body = str_replace("[user]", $params['firstname'] . " " . $params['lastname'], $body); $body = str_replace("[old]", print_r($oldCustomer, true), $body); $body = str_replace("[new]", print_r($customer->toArray(), true), $body); $isp = Shineisp_Registry::get('ISP'); Shineisp_Commons_Utilities::SendEmail($isp->email, $isp->email, null, $subject, $body); } } } catch (Exception $e) { echo $e->getMessage(); die; } return $this->_helper->redirector('account', 'profile', 'default', array('mex' => 'The task requested has been executed successfully.', 'status' => 'success')); } else { $this->view->form = $form; $this->view->title = $this->translator->translate("Profile details"); $this->view->description = $this->translator->translate("Update here your details filling the applicant form with all the information about you."); return $this->_helper->viewRenderer('applicantform'); } }