protected function _getValueToSaveFromPostData($postData)
 {
     $ret = parent::_getValueToSaveFromPostData($postData);
     $l = $this->_floatValidator->getLocale();
     $ret = Zend_Locale_Format::getNumber($ret, array('locale' => $l));
     return $ret;
 }
 /**
  * extracts the 
  * @return type
  */
 public function dataValue()
 {
     require_once THIRDPARTY_PATH . "/Zend/Locale/Format.php";
     $locale = new Zend_Locale(i18n::get_locale());
     $number = Zend_Locale_Format::getNumber($this->value, array('locale' => $locale));
     return $number;
 }
 /**
  * Extracts the number value from the localised string value
  * 
  * @return string number value
  */
 public function dataValue()
 {
     require_once "Zend/Locale/Format.php";
     if (!$this->isNumeric()) {
         return 0;
     }
     $locale = new Zend_Locale($this->getLocale());
     $number = Zend_Locale_Format::getNumber($this->clean($this->value), array('locale' => $locale));
     return $number;
 }
 /**
  * @return string
  * @throws Zend_Locale_Exception
  */
 public function Value()
 {
     if (!$this->isNumeric()) {
         return '0%';
     }
     require_once "Zend/Locale/Format.php";
     $locale = new Zend_Locale($this->getLocale());
     // convert from the stored format to a real number so we can multiply
     $number = Zend_Locale_Format::getNumber($this->clean($this->value), array('locale' => $locale));
     $number *= 100.0;
     // convert back to string
     $val = Zend_Locale_Format::toNumber($number, array('locale' => $locale));
     return $val . '%';
 }
Example #5
0
 /**
  * test getNumber
  * expected integer
  */
 public function testGetNumber()
 {
     $this->assertEquals(Zend_Locale_Format::getNumber(0), 0, "value 0 expected");
     $this->assertEquals(Zend_Locale_Format::getNumber(-1234567), -1234567, "value -1234567 expected");
     $this->assertEquals(Zend_Locale_Format::getNumber(1234567), 1234567, "value 1234567 expected");
     $this->assertEquals(Zend_Locale_Format::getNumber(0.1234567), 0.1234567, "value 0.1234567 expected");
     $this->assertEquals(Zend_Locale_Format::getNumber(-1234567.12345), -1234567.12345, "value -1234567.12345 expected");
     $this->assertEquals(Zend_Locale_Format::getNumber(1234567.12345), 1234567.12345, "value 1234567.12345 expected");
     $this->assertEquals(Zend_Locale_Format::getNumber('0', 'de'), 0, "value 0 expected");
     $this->assertEquals(Zend_Locale_Format::getNumber('-1234567', 'de'), -1234567, "value -1234567 expected");
     $this->assertEquals(Zend_Locale_Format::getNumber('1234567', 'de'), 1234567, "value 1234567 expected");
     $this->assertEquals(Zend_Locale_Format::getNumber('0,1234567', 'de'), 0.1234567, "value 0.1234567 expected");
     $this->assertEquals(Zend_Locale_Format::getNumber('-1.234.567,12345', 'de'), -1234567.12345, "value -1234567.12345 expected");
     $this->assertEquals(Zend_Locale_Format::getNumber('1.234.567,12345', 'de'), 1234567.12345, "value 1234567.12345 expected");
     $this->assertEquals(Zend_Locale_Format::getNumber('0', 'de_AT'), 0, "value 0 expected");
     $this->assertEquals(Zend_Locale_Format::getNumber('-1234567', 'de_AT'), -1234567, "value -1234567 expected");
     $this->assertEquals(Zend_Locale_Format::getNumber('1.234.567', 'de_AT'), 1234567, "value 1234567 expected");
     $this->assertEquals(Zend_Locale_Format::getNumber('0,1234567', 'de_AT'), 0.1234567, "value 0.1234567 expected");
     $this->assertEquals(Zend_Locale_Format::getNumber('-1.234.567,12345', 'de_AT'), -1234567.12345, "value -1234567.12345 expected");
     $this->assertEquals(Zend_Locale_Format::getNumber('1.234.567,12345', 'de_AT'), 1234567.12345, "value 1234567.12345 expected");
 }
Example #6
0
 /**
  * test getNumber
  * expected integer
  */
 public function testGetNumber()
 {
     $this->assertEquals(       0,         Zend_Locale_Format::getNumber(       0)        );
     $this->assertEquals(-1234567,         Zend_Locale_Format::getNumber(-1234567)        );
     $this->assertEquals( 1234567,         Zend_Locale_Format::getNumber( 1234567)        );
     $this->assertEquals(       0.1234567, Zend_Locale_Format::getNumber(       0.1234567));
     $this->assertEquals(-1234567.12345,   Zend_Locale_Format::getNumber(-1234567.12345)  );
     $this->assertEquals( 1234567.12345,   Zend_Locale_Format::getNumber(1234567.12345)   );
     $options = array('locale' => 'de');
     $this->assertEquals(       0,         Zend_Locale_Format::getNumber(         '0',         $options));
     $this->assertEquals(-1234567,         Zend_Locale_Format::getNumber(  '-1234567',         $options));
     $this->assertEquals( 1234567,         Zend_Locale_Format::getNumber(   '1234567',         $options));
     $this->assertEquals(       0.1234567, Zend_Locale_Format::getNumber('         0,1234567', $options));
     $this->assertEquals(-1234567.12345,   Zend_Locale_Format::getNumber('-1.234.567,12345',   $options));
     $this->assertEquals( 1234567.12345,   Zend_Locale_Format::getNumber(' 1.234.567,12345',   $options));
     $options = array('locale' => 'de_AT');
     $this->assertEquals(       0,         Zend_Locale_Format::getNumber(         '0',         $options));
     $this->assertEquals(-1234567,         Zend_Locale_Format::getNumber(  '-1234567',         $options));
     $this->assertEquals( 1234567,         Zend_Locale_Format::getNumber( '1.234.567',         $options));
     $this->assertEquals(       0.1234567, Zend_Locale_Format::getNumber(         '0,1234567', $options));
     $this->assertEquals(-1234567.12345,   Zend_Locale_Format::getNumber('-1.234.567,12345',   $options));
     $this->assertEquals( 1234567.12345,   Zend_Locale_Format::getNumber( '1.234.567,12345',   $options));
 }
Example #7
0
 /**
  * Set a new value
  *
  * @param  $value  mixed  - Value as string, integer, real or float
  * @param  $type   type   - OPTIONAL a Zend_Measure_Area Type
  * @param  $locale locale - OPTIONAL a Zend_Locale Type
  * @throws Zend_Measure_Exception
  */
 public function setValue($value, $type, $locale = false)
 {
     if (empty($locale)) {
         $locale = $this->_Locale;
     }
     $value = Zend_Locale_Format::getNumber($value, $locale);
     if (empty(self::$_UNITS[$type])) {
         self::throwException('unknown type of area:' . $type);
     }
     parent::setValue($value, $type, $locale);
     parent::setType($type);
 }
Example #8
0
/**
 * Takes locale-formatted float (eg. 54,33) and converts it to the "standard"
 * format needed for calculations (eg 54.33)
 *
 * @param string $ps_value The value to convert
 * @param string $ps_locale The locale of the value
 * @return float The converted value
 */
function caConvertLocaleSpecificFloat($ps_value, $ps_locale = "en_US")
{
    try {
        return Zend_Locale_Format::getNumber($ps_value, array('locale' => $ps_locale));
    } catch (Zend_Locale_Exception $e) {
        // happens when you enter 54.33 but 54,33 is expected in the current locale
        return floatval($ps_value);
    }
}
Example #9
0
 /**
  * Set a new value
  *
  * @param  $value  mixed  - Value as string, integer, real or float
  * @param  $type   type   - OPTIONAL a Zend_Measure_Number Type
  * @param  $locale locale - OPTIONAL a Zend_Locale Type
  * @throws Zend_Measure_Exception
  */
 public function setValue($value, $type, $locale = false)
 {
     if (empty($locale)) {
         $locale = $this->_Locale;
     }
     if (empty(self::$_UNITS[$type])) {
         self::throwException('unknown type of number:' . $type);
     }
     switch ($type) {
         case 'Number::BINARY':
             preg_match('/[01]+/', $value, $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::TERNARY':
             preg_match('/[012]+/', $value, $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::QUATERNARY':
             preg_match('/[0123]+/', $value, $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::QUINARY':
             preg_match('/[01234]+/', $value, $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::SENARY':
             preg_match('/[012345]+/', $value, $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::SEPTENARY':
             preg_match('/[0123456]+/', $value, $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::OCTAL':
             preg_match('/[01234567]+/', $value, $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::NONARY':
             preg_match('/[012345678]+/', $value, $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::DUODECIMAL':
             preg_match('/[0123456789AB]+/', strtoupper($value), $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::HEXADECIMAL':
             preg_match('/[0123456789ABCDEF]+/', strtoupper($value), $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::ROMAN':
             preg_match('/[IVXLCDM_]+/', strtoupper($value), $ergebnis);
             $value = $ergebnis[0];
             break;
         default:
             $value = Zend_Locale_Format::getNumber($value, $locale);
             if (bccomp($value, 0) < 0) {
                 $value = bcsqrt(bcpow($value, 2));
             }
             break;
     }
     parent::setValue($value, $type, $locale);
     parent::setType($type);
 }
Example #10
0
 /**
  * @group ZF-9160
  */
 public function testGetNumberWithZeroPrecision()
 {
     $this->assertEquals(1234, Zend_Locale_Format::getNumber('1234.567', array('locale' => 'en_US', 'precision' => 0)));
 }
Example #11
0
 /**
  * Set a new value
  *
  * @param  $value  mixed  - Value as string, integer, real or float
  * @param  $type   type   - OPTIONAL a Zend_Measure_Torque Type
  * @param  $locale locale - OPTIONAL a Zend_Locale Type
  * @throws Zend_Measure_Exception
  */
 public function setValue($value, $type, $locale = false)
 {
     if (empty($locale)) {
         $locale = $this->_Locale;
     }
     try {
         $value = Zend_Locale_Format::getNumber($value, $locale);
     } catch (Exception $e) {
         throw Zend::exception('Zend_Measure_Exception', $e->getMessage());
     }
     if (empty(self::$_UNITS[$type])) {
         throw Zend::exception('Zend_Measure_Exception', 'unknown type of torque:' . $type);
     }
     parent::setValue($value, $type, $locale);
     parent::setType($type);
 }
Example #12
0
 /**
  * Set a new value
  *
  * @param  integer|string      $value   Value as string, integer, real or float
  * @param  string              $type    OPTIONAL A Zend_Measure_Flow_Mass Type
  * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing numbers
  * @throws Zend_Measure_Exception
  */
 public function setValue($value, $type = null, $locale = null)
 {
     if ($locale === null) {
         $locale = $this->_Locale;
     }
     if (!($locale = Zend_Locale::isLocale($locale, true))) {
         throw new Zend_Measure_Exception("language ({$locale}) is a unknown language");
     }
     if ($type === null) {
         $type = self::STANDARD;
     }
     try {
         $value = Zend_Locale_Format::getNumber($value, $locale);
     } catch (Exception $e) {
         throw new Zend_Measure_Exception($e->getMessage());
     }
     if (empty(self::$_UNITS[$type])) {
         throw new Zend_Measure_Exception("type ({$type}) is a unknown flow mass");
     }
     parent::setValue($value, $type, $locale);
     parent::setType($type);
 }
Example #13
0
 protected function _localizeNumber($number, $options = array())
 {
     $options = Mage::helper('currencymanager')->getOptions($options, true, $this->getCurrencyCode());
     if ($options['display'] == Zend_Currency::NO_SYMBOL) {
         // in Zend_Currency toCurrency() function
         // are stripped unbreakable spaces only for currency without Currency Symbol
         return $number;
     } else {
         $locale = Mage::app()->getLocale()->getLocaleCode();
         $format = Zend_Locale_Data::getContent($locale, 'decimalnumber');
         $numberOptions = array('locale' => $locale, 'number_format' => $format, 'precision' => 0);
         $number = Zend_Locale_Format::getNumber($number, $numberOptions);
         return Zend_Locale_Format::toNumber($number, $numberOptions);
     }
 }
Example #14
0
 /**
  * test positive seperation language locale
  * expected integer
  */
 public function testRegionSeperatedPositive()
 {
     $value = Zend_Locale_Format::getNumber('1.234.567,12345', 'de_AT');
     $this->assertEquals($value, 1234567.12345, "value 1234567.12345 expected");
 }
Example #15
0
 /**
  * Returns the normalized number from a localized one
  * Parsing depends on the Formatter locale
  * @param String $input Formatted String
  * @param Integer $digits Precision
  * @return String normalized number of Boolean false
  * if $input is not a valid formatted number.
  */
 public function getNumber($input, $digits = null)
 {
     try {
         return Zend_Locale_Format::getNumber($input, array('locale' => $this->zendLocale, 'precision' => $digits));
     } catch (Zend_Locale_Exception $e) {
         // The string is not a valid formatted number.
         return false;
     }
 }
 /**
  * Defined by Zend_Filter_Interface
  *
  * Normalizes the given input
  *
  * @param  string $value Value to normalized
  * @return string|array The normalized value
  */
 public function filter($value)
 {
     if (Zend_Locale_Format::isNumber($value, $this->_options)) {
         return Zend_Locale_Format::getNumber($value, $this->_options);
         //        if (($this->_options['precision'] === 0) && Zend_Locale_Format::isInteger($value, $this->_options)) {
         // Detect integer
         //            return Zend_Locale_Format::getInteger($value, $this->_options);
         //        } else if (($this->_options['precision'] === null) && Zend_Locale_Format::isFloat($value, $this->_options)) {
         // Detect float
         //            return Zend_Locale_Format::getFloat($value, $this->_options);
         //        } else if (Zend_Locale_Format::isNumber($value, $this->_options)) {
         // Detect all other numbers
         //            return Zend_Locale_Format::getNumber($value, $this->_options);
     } else {
         if ($this->_options['date_format'] === null && strpos($value, ':') !== false) {
             // Special case, no date format specified, detect time input
             return Zend_Locale_Format::getTime($value, $this->_options);
         } else {
             if (Zend_Locale_Format::checkDateFormat($value, $this->_options)) {
                 // Detect date or time input
                 return Zend_Locale_Format::getDate($value, $this->_options);
             }
         }
     }
     return $value;
 }
Example #17
0
 public function editAction()
 {
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->getHelper('layout')->disableLayout();
     $request = $this->getRequest();
     $locale = Zend_Registry::get('Zend_Locale');
     $id = $this->_getParam('id', 0);
     $processid = $this->_getParam('processid', 0);
     $form = new Processes_Form_Processpos();
     $form->uom->addMultiOptions($this->_helper->Uom->getUoms());
     $form->shippingmethod->addMultiOptions($this->_helper->ShippingMethod->getShippingMethods($this->_user['clientid']));
     $form->ordering->addMultiOptions($this->getOrdering($processid));
     if ($request->isPost()) {
         $data = $request->getPost();
         $element = key($data);
         if (isset($form->{$element}) && $form->isValidPartial($data)) {
             $data['modified'] = $this->_date;
             $data['modifiedby'] = $this->_user['id'];
             if ($element == 'price' || $element == 'quantity' || $element == 'supplierinvoicetotal') {
                 $data[$element] = Zend_Locale_Format::getNumber($data[$element], array('precision' => 2, 'locale' => $locale));
             }
             $position = new Processes_Model_DbTable_Processpos();
             $position->updatePosition($id, $data);
         } else {
             throw new Exception('Form is invalid');
         }
     }
 }
Example #18
0
 public function editAction()
 {
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->getHelper('layout')->disableLayout();
     $request = $this->getRequest();
     $locale = Zend_Registry::get('Zend_Locale');
     $id = $this->_getParam('id', 0);
     $quoteid = $this->_getParam('quoteid', 0);
     $form = new Sales_Form_Quotepos();
     $form->uom->addMultiOptions($this->_helper->Uom->getUoms());
     $form->ordering->addMultiOptions($this->getOrdering($quoteid));
     $form->taxrate->addMultiOptions($this->_helper->TaxRate->getTaxRates($locale));
     if ($request->isPost()) {
         $data = $request->getPost();
         $element = key($data);
         if (isset($form->{$element}) && $form->isValidPartial($data)) {
             $data['modified'] = $this->_date;
             $data['modifiedby'] = $this->_user['id'];
             if ($element == 'price' || $element == 'quantity') {
                 $data[$element] = Zend_Locale_Format::getNumber($data[$element], array('precision' => 2, 'locale' => $locale));
             }
             $positionDb = new Sales_Model_DbTable_Quotepos();
             $positionDb->updatePosition($id, $data);
             if ($element == 'price' || $element == 'quantity') {
                 $this->_helper->Calculate($quoteid, $this->_currency, $this->_date, $this->_user['id']);
             }
         } else {
             throw new Exception('Form is invalid');
         }
     }
 }
Example #19
0
 /**
  * Set a new value
  *
  * @param  integer|string      $value   Value as string, integer, real or float
  * @param  string              $type    OPTIONAL A Zend_Measure_Acceleration Type
  * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing numbers
  * @throws Zend_Measure_Exception
  */
 public function setValue($value, $type = null, $locale = null)
 {
     if ($type !== null and Zend_Locale::isLocale($type, null, false)) {
         $locale = $type;
         $type = null;
     }
     if ($locale === null) {
         $locale = $this->_locale;
     }
     if (!Zend_Locale::isLocale($locale, true, false)) {
         if (!Zend_Locale::isLocale($locale, false, false)) {
             require_once 'Zend/Measure/Exception.php';
             throw new Zend_Measure_Exception("Language (" . (string) $locale . ") is unknown");
         }
         $locale = new Zend_Locale($locale);
     }
     $locale = (string) $locale;
     if ($type === null) {
         $type = $this->_units['STANDARD'];
     }
     if (empty($this->_units[$type])) {
         require_once 'Zend/Measure/Exception.php';
         throw new Zend_Measure_Exception("Type ({$type}) is unknown");
     }
     try {
         $value = Zend_Locale_Format::getNumber($value, array('locale' => $locale));
     } catch (Exception $e) {
         require_once 'Zend/Measure/Exception.php';
         throw new Zend_Measure_Exception($e->getMessage());
     }
     $this->_value = $value;
     $this->setType($type);
 }
Example #20
0
 /**
  * Set a new value
  *
  * @param  integer|string      $value   Value as string, integer, real or float
  * @param  string              $type    OPTIONAL A measure type f.e. Zend_Measure_Length::METER
  * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing numbers
  * @throws Zend_Measure_Exception
  * @return Zend_Measure_Abstract
  */
 public function setValue($value, $type = null, $locale = null)
 {
     if ($type !== null and Zend_Locale::isLocale($type, null, false)) {
         $locale = $type;
         $type = null;
     }
     if ($locale === null) {
         $locale = $this->_locale;
     }
     $this->setLocale($locale, true);
     if ($type === null) {
         $type = $this->_units['STANDARD'];
     }
     if (empty($this->_units[$type])) {
         throw new Zend_Measure_Exception("Type ({$type}) is unknown");
     }
     try {
         $value = Zend_Locale_Format::getNumber($value, array('locale' => $locale));
     } catch (Exception $e) {
         throw new Zend_Measure_Exception($e->getMessage(), $e->getCode(), $e);
     }
     $this->_value = $value;
     $this->setType($type);
     return $this;
 }
Example #21
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();
 }
 public function parseValue($ps_value, $pa_element_info, $pa_options = null)
 {
     $ps_value = trim($ps_value);
     $va_settings = $this->getSettingValuesFromElementArray($pa_element_info, array('minValue', 'maxValue', 'mustNotBeBlank'));
     if (strlen($ps_value) == 0) {
         if ((bool) $va_settings['mustNotBeBlank']) {
             $this->postError(1970, _t('%1 must not be empty', $pa_element_info['displayLabel']), 'CurrencyAttributeValue->parseValue()');
             return false;
         }
         return null;
     }
     // it's either "<something><decimal>" ($1000) or "<decimal><something>" (1000 EUR) or just "<decimal>" with an implicit <something>
     // either
     if (preg_match("!^([^\\d]+)([\\d\\.\\,]+)\$!", trim($ps_value), $va_matches)) {
         $vs_decimal_value = $va_matches[2];
         $vs_currency_specifier = trim($va_matches[1]);
         // or 1
     } else {
         if (preg_match("!^([\\d\\.\\,]+)([^\\d]+)\$!", trim($ps_value), $va_matches)) {
             $vs_decimal_value = $va_matches[1];
             $vs_currency_specifier = trim($va_matches[2]);
             // or 2
         } else {
             if (preg_match("!(^[\\d\\,\\.]+\$)!", trim($ps_value), $va_matches)) {
                 $vs_decimal_value = $va_matches[1];
                 $vs_currency_specifier = null;
                 // derp
             } else {
                 $this->postError(1970, _t('%1 is not a valid currency value; be sure to include a currency symbol', $pa_element_info['displayLabel']), 'CurrencyAttributeValue->parseValue()');
                 return false;
             }
         }
     }
     if (!$vs_currency_specifier) {
         // this respects the global UI locale which is set using Zend_Locale
         $o_currency = new Zend_Currency();
         $vs_currency_specifier = $o_currency->getShortName();
     }
     // get UI locale from registry and convert string to actual php float
     // based on rules for this locale (e.g. most non-US locations use 10.000,00 as notation)
     if (Zend_Registry::isRegistered("Zend_Locale")) {
         $o_locale = Zend_Registry::get('Zend_Locale');
     } else {
         $o_locale = new Zend_Locale('en_US');
     }
     try {
         $vn_value = Zend_Locale_Format::getNumber($vs_decimal_value, array('locale' => $o_locale, 'precision' => 2));
     } catch (Zend_Locale_Exception $e) {
         $this->postError(1970, _t('%1 does not use a valid decimal notation for your locale', $pa_element_info['displayLabel']), 'CurrencyAttributeValue->parseValue()');
         return false;
     }
     switch ($vs_currency_specifier) {
         case '$':
             $o_config = Configuration::load();
             $vs_currency_specifier = ($vs_dollars_are_this = $o_config->get('default_dollar_currency')) ? $vs_dollars_are_this : 'USD';
             break;
         case '¥':
             $vs_currency_specifier = 'JPY';
             break;
         case '£':
             $vs_currency_specifier = 'GBP';
             break;
         case '€':
             $vs_currency_specifier = 'EUR';
             break;
         default:
             $vs_currency_specifier = strtoupper($vs_currency_specifier);
             break;
     }
     if (strlen($vs_currency_specifier) != 3) {
         $this->postError(1970, _t('Currency specified for %1 does not appear to be valid', $pa_element_info['displayLabel']), 'CurrencyAttributeValue->parseValue()');
         return false;
     }
     if ($vn_value < 0) {
         $this->postError(1970, _t('%1 must not be negative', $pa_element_info['displayLabel']), 'CurrencyAttributeValue->parseValue()');
         return false;
     }
     if ($vn_value < floatval($va_settings['minValue'])) {
         // value is too low
         $this->postError(1970, _t('%1 must be at least %2', $pa_element_info['displayLabel'], $va_settings['minValue']), 'CurrencyAttributeValue->parseValue()');
         return false;
     }
     if (floatval($va_settings['maxValue']) > 0 && $vn_value > floatval($va_settings['maxValue'])) {
         // value is too high
         $this->postError(1970, _t('%1 must be less than %2', $pa_element_info['displayLabel'], $va_settings['maxValue']), 'CurrencyAttributeValue->parseValue()');
         return false;
     }
     return array('value_longtext1' => $vs_currency_specifier, 'value_decimal1' => $vn_value);
 }
Example #23
0
 /** Parses a localized number representation and returns the number (or null if $string is not a valid number representation).
  * @param string $string The number representation to parse.
  * @param bool $trim [default: true] Remove spaces and new lines at the start/end of $string?
  * @param int|null $precision [default: null] The wanted precision; if null or not specified the complete number will be returned.
  * @return null|number
  * @example http://www.concrete5.org/documentation/how-tos/developers/formatting-numbers/ See the Formatting numbers how-to for more details
  */
 public function unformat($string, $trim = true, $precision = null)
 {
     if (is_int($string) || is_float($string)) {
         return is_numeric($precision) ? round($string, $precision) : $string;
     }
     if (!is_string($string)) {
         return null;
     }
     if ($trim) {
         $string = trim($string);
     }
     if (!(strlen($string) && $this->isNumber($string))) {
         return null;
     }
     $options = array('locale' => $this->getZendLocale());
     if (is_numeric($precision)) {
         $options['precision'] = $precision;
     }
     return Zend_Locale_Format::getNumber($string, $options);
 }
Example #24
0
    /**
     * Set a new value
     *
     * @param  integer|string      $value   Value as string, integer, real or float
     * @param  string              $type    OPTIONAL A Zend_Measure_Acceleration Type
     * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing numbers
     * @throws Zend_Measure_Exception
     */
    public function setValue($value, $type = null, $locale = null)
    {
        if (Zend_Locale::isLocale($type)) {
            $locale = $type;
            $type = null;
        }

        if ($locale === null) {
            $locale = $this->_Locale;
        }

        if ($locale instanceof Zend_Locale) {
            $locale = $locale->toString();
        }

        if (!Zend_Locale::isLocale($locale)) {
            throw new Zend_Measure_Exception("Language ($locale) is unknown");
        }

        if ($type === null) {
            $type = $this->_UNITS['STANDARD'];
        }

        if (empty($this->_UNITS[$type])) {
            throw new Zend_Measure_Exception("Type ($type) is unknown");
        }

        try {
            $value = Zend_Locale_Format::getNumber($value, array('locale' => $locale));
        } catch(Exception $e) {
            throw new Zend_Measure_Exception($e->getMessage());
        }

        $this->_value = $value;
        $this->setType($type);
    }
Example #25
0
 public function editAction()
 {
     $request = $this->getRequest();
     $id = $this->_getParam('id', 0);
     $activeTab = $request->getCookie('tab', null);
     $itemDb = new Items_Model_DbTable_Item();
     $item = $itemDb->getItem($id);
     if (false) {
         $this->_helper->redirector->gotoSimple('view', 'item', null, array('id' => $id));
     } elseif ($this->isLocked($item['locked'], $item['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 {
         $itemDb->lock($id, $this->_user['id'], $this->_date);
         $form = new Items_Form_Item();
         $options = $this->_helper->Options->getOptions($form, $this->_user['clientid']);
         if ($request->isPost()) {
             $this->_helper->viewRenderer->setNoRender();
             $this->_helper->getHelper('layout')->disableLayout();
             $data = $request->getPost();
             $element = key($data);
             if (isset($form->{$element}) && $form->isValidPartial($data)) {
                 $data['modified'] = $this->_date;
                 $data['modifiedby'] = $this->_user['id'];
                 if (array_key_exists('price', $data)) {
                     $locale = Zend_Registry::get('Zend_Locale');
                     $data['price'] = Zend_Locale_Format::getNumber($data['price'], array('precision' => 2, 'locale' => $locale));
                 }
                 if (array_key_exists('quantity', $data)) {
                     $locale = Zend_Registry::get('Zend_Locale');
                     $data['quantity'] = Zend_Locale_Format::getNumber($data['quantity'], array('precision' => 2, 'locale' => $locale));
                 }
                 if (array_key_exists('margin', $data)) {
                     $locale = Zend_Registry::get('Zend_Locale');
                     $data['margin'] = Zend_Locale_Format::getNumber($data['margin'], array('precision' => 2, 'locale' => $locale));
                 }
                 if (array_key_exists('weight', $data)) {
                     $locale = Zend_Registry::get('Zend_Locale');
                     $data['weight'] = Zend_Locale_Format::getNumber($data['weight'], array('precision' => 4, 'locale' => $locale));
                 }
                 $item = new Items_Model_DbTable_Item();
                 $item->updateItem($id, $data);
             } else {
                 throw new Exception('Form is invalid');
             }
         } else {
             if ($id > 0) {
                 $item['cost'] = $this->_currency->toCurrency($item['cost']);
                 $item['price'] = $this->_currency->toCurrency($item['price']);
                 $item['margin'] = $this->_currency->toCurrency($item['margin']);
                 $locale = Zend_Registry::get('Zend_Locale');
                 $item['weight'] = $this->_currency->toCurrency($item['weight'], array('precision' => 4, 'locale' => $locale));
                 $form->populate($item);
                 //Toolbar
                 $toolbar = new Items_Form_Toolbar();
                 $this->view->form = $form;
                 $this->view->activeTab = $activeTab;
                 $this->view->toolbar = $toolbar;
             }
         }
     }
     $this->view->messages = $this->_flashMessenger->getMessages();
 }
 /**
  * Defined by Zend_Filter_Interface
  *
  * Normalizes the given input
  *
  * @param  string $value Value to normalized
  * @return string|array The normalized value
  */
 public function filter($value)
 {
     if (Zend_Locale_Format::isNumber($value, $this->_options)) {
         return Zend_Locale_Format::getNumber($value, $this->_options);
     } else {
         if ($this->_options['date_format'] === null && strpos($value, ':') !== false) {
             // Special case, no date format specified, detect time input
             return Zend_Locale_Format::getTime($value, $this->_options);
         } else {
             if (Zend_Locale_Format::checkDateFormat($value, $this->_options)) {
                 // Detect date or time input
                 return Zend_Locale_Format::getDate($value, $this->_options);
             }
         }
     }
     return $value;
 }
Example #27
0
 protected static function _getTaxInfo($product)
 {
     $showPercentage = true;
     $tax = Mage::helper('tax');
     $helper = Mage::helper('codevog_options');
     if ($product->getTypeId() == 'bundle') {
         $showPercentage = false;
     }
     if ($showPercentage) {
         $taxPercent = $product->getTaxPercent();
         $locale = Mage::app()->getLocale()->getLocaleCode();
         $taxPercent = Zend_Locale_Format::getNumber($taxPercent, array('locale' => $locale));
         if ($taxPercent == 0) {
             $showPercentage = false;
         }
     }
     if ($showPercentage && Mage::getStoreConfigFlag(self::SHOW_TAX_INFO)) {
         if ($tax->displayPriceIncludingTax()) {
             $taxInfo = sprintf($helper->__('Incl. %1$s%% VAT'), $taxPercent);
         } else {
             $taxInfo = sprintf($helper->__('Excl. %1$s%% VAT'), $taxPercent);
         }
     } else {
         if ($tax->displayPriceIncludingTax()) {
             $taxInfo = $helper->__('Incl. VAT');
         } else {
             $taxInfo = $helper->__('Excl. VAT');
         }
     }
     return $taxInfo;
 }