public function test_get_the_order_currency() { $currency = get_the_order_currency_name(self::$order->get_id()); $this->assertEquals($currency, APP_Currencies::get_name(self::$order->get_currency())); $this->expectOutputString($currency); the_order_currency(self::$order->get_id()); }
public function form_fields() { $form_fields = array(array('title' => __('Reference ID', APP_TD), 'type' => 'text', 'name' => 'cp_sys_ad_conf_id', 'default' => cp_generate_id(), 'extra' => array('readonly' => 'readonly')), array('title' => __('Views Today', APP_TD), 'type' => 'text', 'name' => 'cp_daily_count', 'sanitize' => 'absint', 'default' => '0', 'extra' => array('readonly' => 'readonly')), array('title' => __('Views Total', APP_TD), 'type' => 'text', 'name' => 'cp_total_count', 'sanitize' => 'absint', 'default' => '0', 'extra' => array('readonly' => 'readonly')), array('title' => __('Submitted from IP', APP_TD), 'type' => 'text', 'name' => 'cp_sys_userIP', 'default' => appthemes_get_ip(), 'extra' => array('readonly' => 'readonly'))); if (cp_payments_is_enabled()) { $form_fields[] = array('title' => __('Last Payment', APP_TD), 'type' => 'text', 'name' => 'cp_sys_total_ad_cost', 'default' => '0', 'desc' => APP_Currencies::get_current_symbol(), 'extra' => array('readonly' => 'readonly')); } return $form_fields; }
public function before_rendering_field($field) { if ('currency_identifier' == $field['name'] || 'currency_position' == $field['name']) { $currency = APP_Currencies::get_currency(APP_Gateway_Registry::get_options()->currency_code); foreach ($field['values'] as $key => $value) { $field['values'][$key] = str_replace(array('{symbol}', '{code}'), array($currency['symbol'], $currency['code']), $value); } } return $field; }
/** * Returns the price given the arguments in add_theme_support for 'app-price-format' * Note: if hide_decimals is turned on, the amount will be rounded. * * @param int $price The numerical value to format * @param string $override_currency The currency the value is in (defaults to 'currency_default') * @param string $override_format The format the value is in (defaults to 'currency_identifier') * @return string The formatted price */ function appthemes_get_price($price, $override_currency = '', $override_identifier = '') { $format_args = appthemes_price_format_get_args(); $decimals = $format_args['hide_decimals'] ? 0 : 2; $base_price = number_format($price, $decimals, $format_args['decimal_separator'], $format_args['thousands_separator']); $currency_code = empty($override_currency) ? $format_args['currency_default'] : $override_currency; $currency_identifier = empty($override_identifier) ? $format_args['currency_identifier'] : $override_identifier; $position = $format_args['currency_position']; $identifier = APP_Currencies::get_currency($currency_code, $currency_identifier); return _appthemes_format_display_price($base_price, $identifier, $position); }
/** * Returns the name of the current order's currency * @param $order_id (optional) If given, uses the specified order id, otherwise uses * the order currently being queried * @return string */ function get_the_order_currency_name($order_id = null) { $order = get_order($order_id); return APP_Currencies::get_name($order->get_currency()); }
function cp_dashboard_charts() { global $wpdb, $cp_options; $sql = "SELECT COUNT(post_title) as total, post_date FROM {$wpdb->posts} WHERE post_type = %s AND post_date > %s GROUP BY DATE(post_date) DESC"; $results = $wpdb->get_results($wpdb->prepare($sql, APP_POST_TYPE, appthemes_mysql_date(current_time('mysql'), -30))); $listings = array(); // put the days and total posts into an array foreach ((array) $results as $result) { $the_day = date('Y-m-d', strtotime($result->post_date)); $listings[$the_day] = $result->total; } // setup the last 30 days for ($i = 0; $i < 30; $i++) { $each_day = date('Y-m-d', strtotime('-' . $i . ' days')); // if there's no day with posts, insert a goose egg if (!in_array($each_day, array_keys($listings))) { $listings[$each_day] = 0; } } // sort the values by date ksort($listings); // Get sales - completed orders with a cost $results = array(); $currency_symbol = $cp_options->curr_symbol; if (current_theme_supports('app-payments')) { $sql = "SELECT sum( m.meta_value ) as total, p.post_date FROM {$wpdb->postmeta} m INNER JOIN {$wpdb->posts} p ON m.post_id = p.ID WHERE m.meta_key = 'total_price' AND p.post_status IN ( '" . APPTHEMES_ORDER_COMPLETED . "', '" . APPTHEMES_ORDER_ACTIVATED . "' ) AND p.post_date > %s GROUP BY DATE(p.post_date) DESC"; $results = $wpdb->get_results($wpdb->prepare($sql, appthemes_mysql_date(current_time('mysql'), -30))); $currency_symbol = APP_Currencies::get_current_symbol(); } $sales = array(); // put the days and total posts into an array foreach ((array) $results as $result) { $the_day = date('Y-m-d', strtotime($result->post_date)); $sales[$the_day] = $result->total; } // setup the last 30 days for ($i = 0; $i < 30; $i++) { $each_day = date('Y-m-d', strtotime('-' . $i . ' days')); // if there's no day with posts, insert a goose egg if (!in_array($each_day, array_keys($sales))) { $sales[$each_day] = 0; } } // sort the values by date ksort($sales); ?> <div id="placeholder"></div> <script language="javascript" type="text/javascript"> // <![CDATA[ jQuery(function() { var posts = [ <?php foreach ($listings as $day => $value) { $sdate = strtotime($day); $sdate = $sdate * 1000; // js timestamps measure milliseconds vs seconds $newoutput = "[{$sdate}, {$value}],\n"; echo $newoutput; } ?> ]; var sales = [ <?php foreach ($sales as $day => $value) { $sdate = strtotime($day); $sdate = $sdate * 1000; // js timestamps measure milliseconds vs seconds $newoutput = "[{$sdate}, {$value}],\n"; echo $newoutput; } ?> ]; var placeholder = jQuery("#placeholder"); var output = [ { data: posts, label: "<?php _e('New Ad Listings', APP_TD); ?> ", symbol: '' }, { data: sales, label: "<?php _e('Total Sales', APP_TD); ?> ", symbol: '<?php echo $currency_symbol; ?> ', yaxis: 2 } ]; var options = { series: { lines: { show: true }, points: { show: true } }, grid: { tickColor:'#f4f4f4', hoverable: true, clickable: true, borderColor: '#f4f4f4', backgroundColor:'#FFFFFF' }, xaxis: { mode: 'time', timeformat: "%m/%d" }, yaxis: { min: 0 }, y2axis: { min: 0, tickFormatter: function(v, axis) { return "<?php echo $currency_symbol; ?> " + v.toFixed(axis.tickDecimals) } }, legend: { position: 'nw' } }; jQuery.plot(placeholder, output, options); // reload the plot when browser window gets resized jQuery(window).resize(function() { jQuery.plot(placeholder, output, options); }); function showChartTooltip(x, y, contents) { jQuery('<div id="charttooltip">' + contents + '</div>').css( { position: 'absolute', display: 'none', top: y + 5, left: x + 5, opacity: 1 } ).appendTo("body").fadeIn(200); } var previousPoint = null; jQuery("#placeholder").bind("plothover", function (event, pos, item) { jQuery("#x").text(pos.x.toFixed(2)); jQuery("#y").text(pos.y.toFixed(2)); if (item) { if (previousPoint != item.datapoint) { previousPoint = item.datapoint; jQuery("#charttooltip").remove(); var x = new Date(item.datapoint[0]), y = item.datapoint[1]; var xday = x.getDate(), xmonth = x.getMonth()+1; // jan = 0 so we need to offset month showChartTooltip(item.pageX, item.pageY, xmonth + "/" + xday + " - <b>" + item.series.symbol + y + "</b> " + item.series.label); } } else { jQuery("#charttooltip").remove(); previousPoint = null; } }); }); // ]]> </script> <?php }
/** * Adds general order sections to the fields displayed * See view_transaction() * @param array $sections Sections already being displayed * @param APP_Order $order Order being processed * @return array $sections with added sections */ public function display_order($sections, $order) { $sections['General Information'] = array('ID' => $order->get_id()); $sections['Money & Currency'] = array('Currency' => APP_Currencies::get_name($order->get_currency()) . ' (' . $order->get_currency() . ')', 'Total' => APP_Currencies::get_price($order->get_total(), $order->get_currency())); return $sections; }
/** * Sets the currency to be used in this order. * Changing this does not affect any of the prices used in the order * @param string $currency_code Currency code used to identify the * currency. Must be registered with APP_Currencies * @return boolean True if currency was changed, false on error */ public function set_currency($currency_code) { if (!is_string($currency_code)) { trigger_error('Currency code must be string', E_USER_WARNING); } if (APP_Currencies::is_valid($currency_code)) { $this->payment['currency'] = $currency_code; } else { return false; } $this->update_meta('currency', $this->payment['currency']); return true; }
/** * Displays the order status summary * @param object $post Wordpress Post object * @return void */ function display($post) { $order = appthemes_get_order($post->ID); ?> <style type="text/css"> #admin-order-status th{ padding-right: 10px; text-align: right; width: 40%; } </style> <table id="admin-order-status"> <tbody> <tr> <th><?php _e('ID', APP_TD); ?> : </th> <td><?php echo $order->get_ID(); ?> </td> </tr> <tr> <th><?php _e('Status', APP_TD); ?> : </th> <td><?php echo $order->get_display_status(); ?> </td> </tr> <tr> <th><?php _e('Gateway', APP_TD); ?> : </th> <td> <?php $gateway_id = $order->get_gateway(); if (!empty($gateway_id)) { $gateway = APP_Gateway_Registry::get_gateway($gateway_id); if ($gateway) { echo $gateway->display_name('admin'); } else { _e('Unknown', APP_TD); } } else { _e('Undecided', APP_TD); } ?> </td> </tr> <tr> <th><?php _e('Currency', APP_TD); ?> : </th> <td><?php echo APP_Currencies::get_currency_string($order->get_currency()); ?> </td> </tr> <?php if ($order->is_recurring()) { $period = $order->get_recurring_period(); ?> <tr> <th><?php _e('Recurs:', APP_TD); ?> </th> <td><?php printf(_n('Every day', 'Every %d days', $period, APP_TD), $period); ?> </td> </tr> <tr> <th><?php _e('Payment Date:', APP_TD); ?> </th> <td><?php echo appthemes_display_date(get_post($order->get_id())->post_date, 'date'); ?> </td> </tr> <?php } ?> <?php if ($order->get_parent() != 0) { ?> <tr> <th><?php _e('Previously', APP_TD); ?> </th> <td><a href="<?php echo get_edit_post_link($order->get_parent()); ?> ">#<?php echo $order->get_parent(); ?> </a></td> </tr> <?php } ?> </tbody> </table> <?php }
/** * Verifies that the default currency returns correctly */ public function test_currency_defaults() { $code = 'USD'; $name = 'US Dollars'; $symbol = '$'; $currency = APP_Currencies::get_current_currency(); $this->assertNotEmpty($currency); $this->assertEquals(compact('code', 'name', 'symbol'), $currency); $this->assertEquals($name, APP_Currencies::get_current_currency('name')); $this->assertEquals($symbol, APP_Currencies::get_current_currency('symbol')); $this->assertEquals($name, APP_Currencies::get_current_name()); $this->assertEquals($symbol, APP_Currencies::get_current_symbol()); }
/** * Initializes the registered currency list. * Allows for localization of currency names. */ public static function init() { self::$currencies = array('USD' => array('symbol' => '$', 'name' => __('US Dollars', APP_TD)), 'EUR' => array('symbol' => '€', 'name' => __('Euros', APP_TD)), 'GBP' => array('symbol' => '£', 'name' => __('Pounds Sterling', APP_TD)), 'AUD' => array('symbol' => '$', 'name' => __('Australian Dollars', APP_TD)), 'BRL' => array('symbol' => 'R$', 'name' => __('Brazilian Real', APP_TD)), 'CAD' => array('symbol' => '$', 'name' => __('Canadian Dollars', APP_TD)), 'CZK' => array('symbol' => 'Kč', 'name' => __('Czech Koruna', APP_TD)), 'DKK' => array('symbol' => 'kr', 'name' => __('Danish Krone', APP_TD)), 'HKD' => array('symbol' => '$', 'name' => __('Hong Kong Dollar', APP_TD)), 'HUF' => array('symbol' => 'Ft', 'name' => __('Hungarian Forint', APP_TD)), 'ILS' => array('symbol' => '₪', 'name' => __('Israeli Shekel', APP_TD)), 'JPY' => array('symbol' => '¥', 'name' => __('Japanese Yen', APP_TD)), 'MYR' => array('symbol' => 'RM', 'name' => __('Malaysian Ringgits', APP_TD)), 'MXN' => array('symbol' => '$', 'name' => __('Mexican Peso', APP_TD)), 'NZD' => array('symbol' => '$', 'name' => __('New Zealand Dollar', APP_TD)), 'NOK' => array('symbol' => 'kr', 'name' => __('Norwegian Krone', APP_TD)), 'PHP' => array('symbol' => 'P', 'name' => __('Philippine Pesos', APP_TD)), 'PLN' => array('symbol' => 'zł', 'name' => __('Polish Zloty', APP_TD)), 'SGD' => array('symbol' => '$', 'name' => __('Singapore Dollar', APP_TD)), 'SEK' => array('symbol' => 'kr', 'name' => __('Swedish Krona', APP_TD)), 'CHF' => array('symbol' => 'Fr', 'name' => __('Swiss Franc', APP_TD)), 'TWD' => array('symbol' => '$', 'name' => __('Taiwan New Dollar', APP_TD)), 'THB' => array('symbol' => '฿', 'name' => __('Thai Baht', APP_TD)), 'TRY' => array('symbol' => '₤', 'name' => __('Turkish Lira', APP_TD))); }
public function form() { // translators: Start/End Date Help Text. Can be any format accepted by php.net/strtotime and php.net/date_parse. $date_format = __('( MM/DD/YYYY )', 'appthemes-coupons'); return array(array('title' => __('Coupon Code', 'appthemes-coupons'), 'type' => 'text', 'name' => 'code', 'extra' => array('style' => 'width: 150px;')), array('title' => __('Discount Amount', 'appthemes-coupons'), 'type' => 'text', 'name' => 'amount', 'extra' => array('style' => 'width: 50px;')), array('title' => __('Discount Type', 'appthemes-coupons'), 'type' => 'select', 'name' => 'type', 'values' => array('flat' => sprintf(__('Flat Discount (%s)', 'appthemes-coupons'), APP_Currencies::get_current_symbol()), 'percent' => __('Percentage Discount (%)', 'appthemes-coupons'))), array('title' => __('Start Date', 'appthemes-coupons'), 'type' => 'text', 'name' => 'start_date', 'desc' => $date_format, 'extra' => array('style' => 'width: 150px;')), array('title' => __('End Date', 'appthemes-coupons'), 'type' => 'text', 'name' => 'end_date', 'desc' => $date_format, 'extra' => array('style' => 'width: 150px;')), array('title' => __('Use Limit', 'appthemes-coupons'), 'type' => 'text', 'name' => 'use_limit', 'desc' => __('( 0 for Unlimited )', 'appthemes-coupons'), 'extra' => array('style' => 'width: 50px;')), array('title' => __('Use Limit Per User', 'appthemes-coupons'), 'type' => 'text', 'name' => 'user_use_limit', 'desc' => __('( 0 for Unlimited )', 'appthemes-coupons'), 'extra' => array('style' => 'width: 50px;'))); }