Exemple #1
0
 public function edit($id)
 {
     $lists = array();
     $mi = new microIntegration();
     $mi->load($id);
     $aecHTML = null;
     $attached = array();
     $mi_gsettings = $mi->getGeneralSettings();
     if (!$mi->id) {
         // Create MI Selection List
         $mi_handler = new microIntegrationHandler();
         $mi_list = $mi_handler->getIntegrationList();
         $drilldown = array('all' => array());
         $mi_gsettings['class_name'] = array('hidden');
         $mi_gsettings['class_list'] = array('list');
         if (count($mi_list) > 0) {
             foreach ($mi_list as $name) {
                 $mi_item = new microIntegration();
                 if ($mi_item->callDry($name)) {
                     $handle = str_replace('mi_', '', $mi_item->class_name);
                     if (isset($mi_item->info['type'])) {
                         foreach ($mi_item->info['type'] as $type) {
                             $drill = explode('.', $type);
                             $cursor =& $drilldown;
                             $mi_item->name = str_replace(array(' AEC ', ' MI '), ' ', $mi_item->name);
                             foreach ($drill as $i => $k) {
                                 if (!isset($cursor[$k])) {
                                     $cursor[$k] = array();
                                 }
                                 if ($i == count($drill) - 1) {
                                     $cursor[$k][] = '<a href="#' . $handle . '" class="mi-menu-mi"><span class="mi-menu-mi-name">' . $mi_item->name . '</span><span class="mi-menu-mi-desc">' . $mi_item->desc . '</span></a>';
                                 } else {
                                     $cursor =& $cursor[$k];
                                 }
                             }
                         }
                     }
                     $drilldown['all'][] = '<a href="#' . $handle . '" class="mi-menu-mi"><span class="mi-menu-mi-name">' . $mi_item->name . '</span><span class="mi-menu-mi-desc">' . $mi_item->desc . '</span></a>';
                 }
             }
             deep_ksort($drilldown);
             $lists['class_list'] = '<a tabindex="0" href="#mi-select-list" class="btn btn-primary" id="drilldown">Select an Integration</a>';
             $lists['class_list'] .= '<div id="mi-select-list" class="hidden"><ul>';
             foreach ($drilldown as $lin => $li) {
                 if ($this->lang->hasKey('AEC_MI_LIST_' . strtoupper($lin))) {
                     $kkey = JText::_('AEC_MI_LIST_' . strtoupper($lin));
                 } else {
                     $kkey = ucwords(str_replace('_', ' ', $lin));
                 }
                 $lists['class_list'] .= '<li><a href="#">' . $kkey . '</a><ul>';
                 foreach ($li as $lixn => $lix) {
                     if (is_array($lix)) {
                         if ($this->lang->hasKey('AEC_MI_LIST_' . strtoupper($lixn))) {
                             $xkey = JText::_('AEC_MI_LIST_' . strtoupper($lixn));
                         } else {
                             $xkey = ucwords(str_replace('_', ' ', $lixn));
                         }
                         $lists['class_list'] .= '<li><a href="#">' . $xkey . '</a><ul>';
                         foreach ($lix as $mix) {
                             $lists['class_list'] .= '<li>' . $mix . '</li>';
                         }
                         $lists['class_list'] .= '</ul></li>';
                     } else {
                         $lists['class_list'] .= '<li>' . $lix . '</li>';
                     }
                 }
                 $lists['class_list'] .= '</ul></li>';
             }
             $lists['class_list'] .= '</ul></div>';
         } else {
             $lists['class_list'] = '';
         }
     }
     if ($mi->id) {
         // Call MI (override active check) and Settings
         if ($mi->callIntegration(true)) {
             $attached['plans'] = microIntegrationHandler::getPlansbyMI($mi->id, false, true);
             $attached['groups'] = microIntegrationHandler::getGroupsbyMI($mi->id, false, true);
             $set = array();
             foreach ($mi_gsettings as $n => $v) {
                 if (!isset($mi->{$n})) {
                     if (isset($mi->settings[$n])) {
                         $set[$n] = $mi->settings[$n];
                     } else {
                         $set[$n] = null;
                     }
                 } else {
                     $set[$n] = $mi->{$n};
                 }
             }
             $restrictionHelper = new aecRestrictionHelper();
             $mi_gsettings['restr_remaps'] = array('subarea_change', 'restrictions');
             $mi_gsettings = array_merge($mi_gsettings, $restrictionHelper->getParams());
             if (empty($mi->restrictions)) {
                 $mi->restrictions = array();
             }
             $lists = array_merge($lists, $restrictionHelper->getLists($set, $mi->restrictions));
             $mi_gsettings[$mi->id . 'remap'] = array('area_change', 'MI');
             $mi_gsettings[$mi->id . 'remaps'] = array('subarea_change', $mi->class_name);
             $mi_settings = $mi->getSettings();
             // Get lists supplied by the MI
             if (!empty($mi_settings['lists'])) {
                 $lists = array_merge($lists, $mi_settings['lists']);
                 unset($mi_settings['lists']);
             }
             $available_plans = SubscriptionPlanHandler::getPlanList(false, false, true, null, true);
             $selected_plans = array();
             foreach ($attached['plans'] as $p) {
                 $selected_plans[] = (object) array('value' => $p->id, 'text' => $p->name);
             }
             $lists['attach_to_plans'] = JHTML::_('select.genericlist', $available_plans, 'attach_to_plans[]', 'size="1" multiple="multiple" class="select2-bootstrap"', 'value', 'text', $selected_plans);
             $available_groups = ItemGroupHandler::getGroups(null, true);
             $selected_groups = array();
             foreach ($attached['groups'] as $g) {
                 $selected_groups[] = (object) array('value' => $g->id, 'text' => $g->name);
             }
             $lists['attach_to_groups'] = JHTML::_('select.genericlist', $available_groups, 'attach_to_groups[]', 'size="1" multiple="multiple" class="select2-bootstrap"', 'value', 'text', $selected_groups);
             $gsettings = new aecSettings('MI', 'E');
             $gsettings->fullSettingsArray($mi_gsettings, array_merge($set, $mi->restrictions), $lists);
             $settings = new aecSettings('MI', $mi->class_name);
             $settings->fullSettingsArray($mi_settings, $set, $lists);
             // Call HTML Class
             $aecHTML = new aecHTML(array_merge($gsettings->settings, $settings->settings), array_merge($gsettings->lists, $settings->lists));
             $aecHTML->hasHacks = method_exists($mi->mi_class, 'hacks');
             $aecHTML->customparams = array();
             foreach ($mi_settings as $n => $v) {
                 $aecHTML->customparams[] = $n;
             }
             $aecHTML->hasSettings = true;
             $aecHTML->hasRestrictions = !empty($mi->settings['has_restrictions']);
         } else {
             $short = 'microIntegration loading failure';
             $event = 'When trying to load microIntegration: ' . $mi->id . ', callIntegration failed';
             $tags = 'microintegration,loading,error';
             $params = array();
             $eventlog = new eventLog();
             $eventlog->issue($short, $tags, $event, 128, $params);
         }
     } else {
         $settings = new aecSettings('MI', 'E');
         $settings->fullSettingsArray($mi_gsettings, array(), $lists);
         // Call HTML Class
         $aecHTML = new aecHTML($settings->settings, $settings->lists);
         $aecHTML->hasSettings = false;
         $aecHTML->hasRestrictions = false;
         $available_plans = SubscriptionPlanHandler::getPlanList(false, false, true, null, true);
         $lists['attach_to_plans'] = JHTML::_('select.genericlist', $available_plans, 'attach_to_plans[]', 'size="1" multiple="multiple" class="select2-bootstrap"', 'value', 'text', null);
         $available_groups = ItemGroupHandler::getGroups(null, true);
         $lists['attach_to_groups'] = JHTML::_('select.genericlist', $available_groups, 'attach_to_groups[]', 'size="1" multiple="multiple" class="select2-bootstrap"', 'value', 'text', null);
     }
     HTML_AcctExp::editMicroIntegration($mi, $lists, $aecHTML, $attached);
 }
Exemple #2
0
 public function exportSales()
 {
     $db = JFactory::getDBO();
     $query = 'SELECT `id`' . ' FROM #__acctexp_log_history' . ' WHERE transaction_date >= \'' . $this->filter['date_start'] . '\'' . ' AND transaction_date <= \'' . $this->filter['date_end'] . '\'' . ' ORDER BY transaction_date ASC';
     $db->setQuery($query);
     $entries = xJ::getDBArray($db);
     switch ($this->options['collate']) {
         default:
         case 'day':
             $collation = 'Y-m-d';
             break;
         case 'week':
             $collation = 'Y-W';
             break;
         case 'month':
             $collation = 'Y-m';
             break;
         case 'year':
             $collation = 'Y';
             break;
     }
     $collators = array();
     switch ($this->options['breakdown']) {
         default:
         case 'plan':
             break;
         case 'group':
             $all_groups = ItemGroupHandler::getGroups();
             $collators = array();
             foreach ($all_groups as $gid) {
                 $collators[$gid] = ItemGroupHandler::getChildren($gid, 'item');
             }
             break;
     }
     $historylist = array();
     foreach ($entries as $id) {
         $entry = new logHistory();
         $entry->load($id);
         if (empty($entry->plan_id) || empty($entry->amount)) {
             continue;
         }
         if (!empty($this->filter['groupid'])) {
             if (empty($this->filter['planid'])) {
                 $this->filter['planid'] = array();
             }
             $children = ItemGroupHandler::getChildren($this->filter['groupid'], 'item');
             if (!empty($children)) {
                 $this->filter['planid'] = array_merge($this->filter['planid'], $children);
                 $this->filter['planid'] = array_unique($this->filter['planid']);
             }
         }
         if (!empty($this->filter['planid'])) {
             if (!in_array($entry->plan_id, $this->filter['planid'])) {
                 continue;
             }
         }
         if (!empty($this->filter['method'])) {
             if (!in_array($entry->proc_id, $this->filter['method'])) {
                 continue;
             }
         }
         $refund = false;
         if (is_array($entry->response)) {
             $filter = array('new_case', 'subscr_signup', 'paymentreview', 'subscr_eot', 'subscr_failed', 'subscr_cancel', 'Pending', 'Denied');
             $refund = false;
             foreach ($entry->response as $v) {
                 if (in_array($v, $filter)) {
                     continue 2;
                 } elseif ($v == 'refund' || $v == 'Reversed' || $v == 'Refunded') {
                     $refund = true;
                 }
             }
         }
         $date = date($collation, strtotime($entry->transaction_date));
         if ($this->options['breakdown'] == 'plan') {
             if (!array_key_exists($entry->plan_id, $collators)) {
                 $collators[$entry->plan_id] = 0;
             }
         }
         if (!isset($historylist[$date])) {
             $historylist[$date] = array();
         }
         $historylist[$date][] = $entry;
     }
     $line = array("line" => "Date");
     if ($this->options['breakdown'] == 'plan') {
         foreach ($collators as $col => $colamount) {
             $line['plan-' . $col] = "Plan #{$col}: " . SubscriptionPlanHandler::planName($col);
         }
     } elseif ($this->options['breakdown'] == 'group') {
         foreach ($collators as $col => $colplans) {
             $line['group-' . $col] = "Group #{$col}:" . ItemGroupHandler::groupName($col);
         }
     }
     $line['total_sum'] = "Total";
     // Remove whitespaces and newlines
     foreach ($line as $larrid => $larrval) {
         $line[$larrid] = trim($larrval);
         if (is_numeric($larrval)) {
             $line[$larrid] = AECToolbox::correctAmount($larrval);
         }
     }
     $this->exphandler->putDescription($line);
     $totalsum = 0;
     $collate_all = array();
     foreach ($collators as $col => $colv) {
         $collate_all[$col] = 0;
     }
     foreach ($historylist as $date => $collater) {
         $linesum = 0;
         $collatex = array();
         foreach ($collators as $col => $colv) {
             $collatex[$col] = 0;
         }
         foreach ($collater as $entry) {
             if ($this->options['breakdown'] == 'plan') {
                 $collatex[$entry->plan_id] += $entry->amount;
                 $collate_all[$entry->plan_id] += $entry->amount;
                 $linesum += $entry->amount;
                 $totalsum += $entry->amount;
             } else {
                 $pgroup = 0;
                 foreach ($collators as $gid => $gplans) {
                     if ($entry->plan_id == $gid) {
                         $pgroup = $gid;
                         break;
                     }
                 }
                 if ($pgroup) {
                     $collatex[$pgroup] += $entry->amount;
                     $collate_all[$pgroup] += $entry->amount;
                 }
                 $linesum += $entry->amount;
                 $totalsum += $entry->amount;
             }
         }
         $line = array("date" => $date);
         foreach ($collators as $col => $colamount) {
             if ($this->options['breakdown'] == 'plan') {
                 $line['plan-' . $col] = $collatex[$col];
             } else {
                 $line['group-' . $col] = $collatex[$col];
             }
         }
         $line['total_sum'] = $linesum;
         // Remove whitespaces and newlines
         $i = 0;
         foreach ($line as $larrid => $larrval) {
             $line[$larrid] = trim($larrval);
             if (is_numeric($larrval) && $i) {
                 $line[$larrid] = AECToolbox::correctAmount($larrval);
             }
             $i++;
         }
         $this->exphandler->putln($line);
     }
     $line = array("line" => "Grand Total");
     foreach ($collate_all as $col => $colamount) {
         if ($this->options['breakdown'] == 'plan') {
             $line['plan-' . $col] = $colamount;
         } else {
             $line['group-' . $col] = $colamount;
         }
     }
     $line['total_sum'] = $totalsum;
     // Remove whitespaces and newlines
     foreach ($line as $larrid => $larrval) {
         $line[$larrid] = trim($larrval);
         if (is_numeric($larrval)) {
             $line[$larrid] = AECToolbox::correctAmount($larrval);
         }
     }
     $this->exphandler->putSum($line);
 }