public static function add_currency_options($js_object = array()) { $js_object['currency_symbol'] = sa_get_currency_symbol(); $js_object['localeconv'] = si_localeconv(); return $js_object; }
public static function adv_form_fields($required = true, $client = 0) { $fields = array(); $fields['currency'] = array('weight' => 220, 'label' => __('Currency Code', 'sprout-invoices'), 'type' => 'text', 'default' => $client ? $client->get_currency() : '', 'required' => $required, 'placeholder' => 'USD', 'attributes' => array('size' => '8'), 'description' => __('This setting will override the setting for each payment processor that supports differing currency codes.', 'sprout-invoices')); /*/ $fields['currency_symbol'] = array( 'weight' => 225, 'label' => __( 'Currency Symbol', 'sprout-invoices' ), 'type' => 'text', 'default' => ( $client ) ? $client->get_currency_symbol() : '$', 'required' => $required, 'placeholder' => '$', 'attributes' => array( 'class' => 'small-text' ), 'description' => __( 'This setting will override the default payments setting. If your currency has the symbol after the amount place a % before your currency symbol. Example, % £', 'sprout-invoices' ) ); /**/ $money_format = $client ? $client->get_money_format() : get_locale(); $si_localeconv = si_localeconv(); $fields['money_format'] = array('weight' => 230, 'label' => __('Money Format', 'sprout-invoices'), 'type' => 'select', 'default' => $money_format, 'options' => $required, 'options' => array_flip(SI_Locales::$locales), 'attributes' => array('class' => 'select2'), 'description' => sprintf(__('Current format: %1$s. The default money formatting (%2$s) can be overridden for all client estimates and invoices here.', 'sprout-invoices'), sa_get_formatted_money(rand(11000, 9999999), get_the_id()), '<code>' . $si_localeconv['int_curr_symbol'] . '</code>')); $fields['nonce'] = array('type' => 'hidden', 'value' => wp_create_nonce(self::SUBMISSION_NONCE), 'weight' => 10000); $fields = apply_filters('si_client_adv_form_fields', $fields, $client); uasort($fields, array(__CLASS__, 'sort_by_weight')); return $fields; }
/** * Replacement for php money_format function * @param string $format * @param float $number * @return */ function si_money_format($format, $number, $doc_id = 0) { $regex = '/%((?:[\\^!\\-]|\\+|\\(|\\=.)*)([0-9]+)?' . '(?:#([0-9]+))?(?:\\.([0-9]+))?([in%])/'; $locale = si_localeconv($doc_id); if (empty($locale['mon_grouping'])) { return $number; } preg_match_all($regex, $format, $matches, PREG_SET_ORDER); foreach ($matches as $fmatch) { $value = floatval($number); $flags = array('fillchar' => preg_match('/\\=(.)/', $fmatch[1], $match) ? $match[1] : ' ', 'nogroup' => preg_match('/\\^/', $fmatch[1]) > 0, 'usesignal' => preg_match('/\\+|\\(/', $fmatch[1], $match) ? $match[0] : '+', 'nosimbol' => preg_match('/\\!/', $fmatch[1]) > 0, 'isleft' => preg_match('/\\-/', $fmatch[1]) > 0); $width = trim($fmatch[2]) ? (int) $fmatch[2] : 0; $left = trim($fmatch[3]) ? (int) $fmatch[3] : 0; $right = trim($fmatch[4]) ? (int) $fmatch[4] : $locale['int_frac_digits']; $conversion = $fmatch[5]; $positive = true; if ($value < 0) { $positive = false; $value *= -1; } $letter = $positive ? 'p' : 'n'; $prefix = $suffix = $cprefix = $csuffix = $signal = ''; $signal = $positive ? $locale['positive_sign'] : $locale['negative_sign']; switch (true) { case $locale["{$letter}_sign_posn"] == 1 && $flags['usesignal'] == '+': $prefix = $signal; break; case $locale["{$letter}_sign_posn"] == 2 && $flags['usesignal'] == '+': $suffix = $signal; break; case $locale["{$letter}_sign_posn"] == 3 && $flags['usesignal'] == '+': $cprefix = $signal; break; case $locale["{$letter}_sign_posn"] == 4 && $flags['usesignal'] == '+': $csuffix = $signal; break; case $flags['usesignal'] == '(': case $locale["{$letter}_sign_posn"] == 0: $prefix = '('; $suffix = ')'; break; } if (!$flags['nosimbol']) { $currency = $cprefix . ($conversion == 'i' ? $locale['int_curr_symbol'] : $locale['currency_symbol']) . $csuffix; } else { $currency = ''; } $space = $locale["{$letter}_sep_by_space"] ? ' ' : ''; $value = number_format($value, $right, $locale['mon_decimal_point'], $flags['nogroup'] ? '' : $locale['mon_thousands_sep']); $value = @explode($locale['mon_decimal_point'], $value); $n = strlen($prefix) + strlen($currency) + strlen($value[0]); if ($left > 0 && $left > $n) { $value[0] = str_repeat($flags['fillchar'], $left - $n) . $value[0]; } $value = implode($locale['mon_decimal_point'], $value); if ($locale["{$letter}_cs_precedes"]) { $value = $prefix . $currency . $space . $value . $suffix; } else { $value = $prefix . $value . $space . $currency . $suffix; } if ($width > 0) { $value = str_pad($value, $width, $flags['fillchar'], $flags['isleft'] ? STR_PAD_RIGHT : STR_PAD_LEFT); } $format = str_replace($fmatch[0], $value, $format); } return $format; }