Example #1
0
 public static function getTypes(array $filter = null)
 {
     if (!($types =& static::$types)) {
         static::getTypesInternal();
     }
     if (!static::$ready) {
         static::$ready = true;
         uasort($types, function ($a, $b) {
             $a = $a['SORT'];
             $b = $b['SORT'];
             return $a < $b ? -1 : ($a > $b ? 1 : 0);
         });
         if (static::$checkModule) {
             $modules = Config::getModules();
             foreach ($types as &$type) {
                 $module = $modules[$type['MODULE']];
                 $type['ACTIVE'] = $module && $module['ACTIVE'];
             }
             unset($type);
         }
     }
     if ($filter) {
         $count = count($filter);
         return array_filter($types, function (array $type) use($count, $filter) {
             return $count == count(array_intersect_assoc($filter, $type));
         });
     } else {
         return $types;
     }
 }
 public static function onGenerateInitialData(Date $from, Date $to)
 {
     $data = array();
     // 1. Payments
     $result = \CSaleOrder::GetList(array(), array('PAYED' => 'Y', 'CANCELED' => 'N', '>=DATE_PAYED' => $from, '<=DATE_PAYED' => $to), false, false, array('LID', 'DATE_PAYED', 'PRICE', 'CURRENCY'));
     while ($row = $result->Fetch()) {
         $day = new DateTime($row['DATE_PAYED']);
         $sum = Config::convertToBaseCurrency($row['PRICE'], $row['CURRENCY']);
         if ($counters =& $data[$row['LID']][$day->format('Y-m-d')]) {
             $counters['sale_payment_add_day'] += 1;
             $counters['sale_payment_sum_add'] += $sum;
         } else {
             $counters = array('sale_payment_add_day' => 1, 'sale_payment_sum_add' => $sum);
         }
     }
     // 2. Orders
     $result = \CSaleOrder::GetList(array(), array('CANCELED' => 'N', '>=DATE_INSERT' => $from, '<=DATE_INSERT' => $to), false, false, array('LID', 'DATE_INSERT', 'PRICE', 'CURRENCY'));
     while ($row = $result->Fetch()) {
         $day = new DateTime($row['DATE_INSERT']);
         $sum = Config::convertToBaseCurrency($row['PRICE'], $row['CURRENCY']);
         if ($counters =& $data[$row['LID']][$day->format('Y-m-d')]) {
             $counters['sale_order_add_day'] += 1;
             $counters['sale_order_sum_add'] += $sum;
         } else {
             $counters = array('sale_order_add_day' => 1, 'sale_order_sum_add' => $sum);
         }
     }
     // 3. Cart
     $result = \CSaleBasket::GetList(array(), array('>=DATE_INSERT' => $from, '<=DATE_INSERT' => $to), false, false, array('LID', 'DATE_INSERT', 'PRICE', 'CURRENCY', 'QUANTITY'));
     while ($row = $result->Fetch()) {
         $day = new DateTime($row['DATE_INSERT']);
         $sum = Config::convertToBaseCurrency($row['PRICE'] * $row['QUANTITY'], $row['CURRENCY']);
         if ($counters =& $data[$row['LID']][$day->format('Y-m-d')]) {
             $counters['sale_cart_add_day'] += 1;
             $counters['sale_cart_sum_add'] += $sum;
         } else {
             $counters = array('sale_cart_add_day' => 1, 'sale_cart_sum_add' => $sum);
         }
     }
     // Result
     unset($counters);
     $result = array();
     foreach ($data as $siteId => $dayCounters) {
         $result[] = array('ATTRIBUTES' => array('conversion_site' => $siteId), 'DAY_COUNTERS' => $dayCounters);
     }
     return $result;
 }
Example #3
0
 /** @deprecated */
 public static function getBaseCurrencyUnit()
 {
     static $unit;
     if (!$unit) {
         $unit = Config::getBaseCurrency();
         if (LANGUAGE_ID == 'ru' && Loader::includeModule('currency')) {
             switch ($unit) {
                 case 'RUB':
                 case 'BYR':
                 case 'UAH':
                     if ($row = CurrencyLangTable::getByPrimary(array('CURRENCY' => $unit, 'LID' => LANGUAGE_ID))->fetch()) {
                         $unit = trim(str_replace('#', '', $row['FORMAT_STRING']));
                     }
                     break;
             }
         }
     }
     return $unit;
 }
Example #4
0
 public static function OnGetRateClasses()
 {
     $scale = array(0.5, 1, 1.5, 2, 5);
     $units = array('SUM' => Config::getBaseCurrencyUnit());
     return array('sale_payment' => array('TITLE' => Loc::getMessage('SALE_CONVERSION_RATE_PAYMENT_TITLE'), 'SCALE' => $scale, 'UNITS' => $units, 'MODULE' => 'sale', 'COUNTERS' => array('conversion_visit_day', 'sale_payment_add_day', 'sale_payment_sum_add'), 'CALCULATE' => function (array $counters) {
         $denominator = $counters['conversion_visit_day'] ?: 0;
         $numerator = $counters['sale_payment_add_day'] ?: 0;
         $sum = $counters['sale_payment_sum_add'] ?: 0;
         return array('DENOMINATOR' => $denominator, 'NUMERATOR' => $numerator, 'RATE' => $denominator ? $numerator / $denominator : 0, 'SUM' => $sum);
     }), 'sale_order' => array('TITLE' => Loc::getMessage('SALE_CONVERSION_RATE_ORDER_TITLE'), 'SCALE' => $scale, 'UNITS' => $units, 'MODULE' => 'sale', 'COUNTERS' => array('conversion_visit_day', 'sale_order_add_day', 'sale_order_sum_add'), 'CALCULATE' => function (array $counters) {
         $denominator = $counters['conversion_visit_day'] ?: 0;
         $numerator = $counters['sale_order_add_day'] ?: 0;
         $sum = $counters['sale_order_sum_add'] ?: 0;
         return array('DENOMINATOR' => $denominator, 'NUMERATOR' => $numerator, 'RATE' => $denominator ? $numerator / $denominator : 0, 'SUM' => $sum);
     }), 'sale_cart' => array('TITLE' => Loc::getMessage('SALE_CONVERSION_RATE_CART_TITLE'), 'SCALE' => $scale, 'UNITS' => $units, 'MODULE' => 'sale', 'COUNTERS' => array('conversion_visit_day', 'sale_cart_add_day', 'sale_cart_sum_add'), 'CALCULATE' => function (array $counters) {
         $denominator = $counters['conversion_visit_day'] ?: 0;
         $numerator = $counters['sale_cart_add_day'] ?: 0;
         $sum = $counters['sale_cart_sum_add'] ?: 0;
         return array('DENOMINATOR' => $denominator, 'NUMERATOR' => $numerator, 'RATE' => $denominator ? $numerator / $denominator : 0, 'SUM' => $sum);
     }));
 }
Example #5
0
}
if ($REQUEST_METHOD == 'POST' && strlen($Update . $Apply . $RestoreDefaults) > 0 && check_bitrix_sessid()) {
    if (strlen($RestoreDefaults) > 0) {
        Config::setBaseCurrency(null);
        $currency = Config::getBaseCurrency();
        Config::setModules(array());
        $modules = Config::getModules();
    } else {
        if ($currencies[$_POST['CURRENCY']]) {
            $currency = $_POST['CURRENCY'];
            Config::setBaseCurrency($currency);
        }
        foreach ($modules as $name => $config) {
            $modules[$name]['ACTIVE'] = isset($_POST['MODULE'][$name]['ACTIVE']);
        }
        Config::setModules($modules);
    }
    //	if(strlen($Update)>0 && strlen($_REQUEST["back_url_settings"])>0)
    //		LocalRedirect($_REQUEST["back_url_settings"]);
    //	else
    //		LocalRedirect($APPLICATION->GetCurPage()."?mid=".urlencode($mid)."&lang=".urlencode(LANGUAGE_ID)."&back_url_settings=".urlencode($_REQUEST["back_url_settings"])."&".$tabControl->ActiveTabParam());
}
// VIEW
$tabControl = new CAdminTabControl('tabControl', array(array('DIV' => 'edit1', 'TAB' => Loc::getMessage('MAIN_TAB_SET'), 'ICON' => 'ib_settings', 'TITLE' => Loc::getMessage('MAIN_TAB_TITLE_SET')), array('DIV' => 'edit2', 'TAB' => Loc::getMessage('CONVERSION_TAB_MODULES_NAME'), 'ICON' => 'ib_settings', 'TITLE' => Loc::getMessage('CONVERSION_TAB_MODULES_DESC'))));
$tabControl->Begin();
?>
<form method="post" action="<?php 
echo $APPLICATION->GetCurPage();
?>
?mid=<?php 
echo urlencode($mid);