public function Action() { if (empty($_POST['start_date'])) { return null; } $db = JFactory::getDBO(); $start_timeframe = $_POST['start_date'] . ' 00:00:00'; if (empty($end)) { $end = date('Y-m-d', (int) gmdate('U')); } $end_timeframe = $end . ' 23:59:59'; $query = 'SELECT `id`' . ' FROM #__acctexp_log_history' . ' WHERE transaction_date >= \'' . $start_timeframe . '\'' . ' AND transaction_date <= \'' . $end_timeframe . '\'' . ' ORDER BY transaction_date ASC'; $db->setQuery($query); $entries = xJ::getDBArray($db); if (empty($entries)) { return "nothing to list"; } $historylist = array(); $groups = array(); foreach ($entries as $id) { $entry = new logHistory(); $entry->load($id); $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('Y-m-d', strtotime($entry->transaction_date)); $pgroups = ItemGroupHandler::parentGroups($entry->plan_id); if (!in_array($pgroups[0], $groups)) { $groups[] = $pgroups[0]; } if (!isset($historylist[$date])) { $historylist[$date] = array('amount' => null, 'groups' => null); } if ($refund) { $historylist[$date]['amount'] -= (double) $entry->amount; $historylist[$date]['groups'][$pgroups[0]]--; } else { $historylist[$date]['amount'] += (double) $entry->amount; $historylist[$date]['groups'][$pgroups[0]]++; } } foreach ($historylist as $date => $entry) { ksort($historylist[$date]['groups']); } $return = ""; $return .= '<table style="background-color: fff; width: 30%; margin: 0 auto; text-align: center !important; font-size: 180%;">'; $groupnames = array(); foreach ($groups as $group) { $groupnames[$group] = ItemGroupHandler::groupName($group); } $closer = 0; $incomplete = false; foreach ($historylist as $date => $history) { if (date('D', strtotime($date)) == 'Mon') { $week = array(); } elseif (!isset($week)) { $week = array(); $incomplete = true; } $return .= '<tr style="border-bottom: 2px solid #999 !important; height: 2em;">'; $return .= '<td title="Date" style="text-align: left !important; color: #aaa;">' . $date . '</td>'; $return .= '<td style="width: 5em;"> </td>'; foreach ($groups as $group) { if (empty($history['groups'][$group])) { $count = 0; } else { $count = $history['groups'][$group]; } $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">' . $count . '</td>'; if (isset($week)) { $week['groups'][$group] += $count; } } if (isset($week)) { $week['amount'] += $history['amount']; } $return .= '<td style="width: 5em;"> </td>'; $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($history['amount']) . '</td>'; $return .= '</tr>'; $return .= '<tr style="height: 1px; background-color: #999;">'; $return .= '<td colspan="' . (count($groups) + 4) . '"></td>'; $return .= '</tr>'; $closer = 0; if (date('D', strtotime($date)) == 'Sun') { $return .= '<tr ' . ($incomplete ? 'title="Incomplete!"' : '') . 'style="border-bottom: 2px solid #999 !important; height: 2em; background-color: #ddd;">'; $return .= '<td style="text-align: left !important; color: #aaa;">' . ($incomplete ? '(Week)' : 'Week') . '</td>'; $return .= '<td style="width: 5em;"> </td>'; foreach ($groups as $group) { if (empty($week['groups'][$group])) { $count = 0; } else { $count = $week['groups'][$group]; } if ($incomplete) { $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">(' . $count . ')</td>'; } else { $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">' . $count . '</td>'; } } $return .= '<td style="width: 5em;"> </td>'; if ($incomplete) { $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">(' . AECToolbox::correctAmount($week['amount']) . ')</td>'; } else { $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($week['amount']) . '</td>'; } $return .= '</tr>'; $return .= '<tr style="height: 1px; background-color: #999;">'; $return .= '<td colspan="' . (count($groups) + 4) . '"></td>'; $return .= '</tr>'; $closer = 1; $incomplete = false; } } if (!$closer) { $return .= '<tr style="border-bottom: 2px solid #999 !important; height: 2em; background-color: #ddd;">'; $return .= '<td title="Date" style="text-align: left !important; color: #aaa;">(Week)</td>'; $return .= '<td style="width: 5em;"> </td>'; foreach ($groups as $group) { if (empty($week['groups'][$group])) { $count = 0; } else { $count = $week['groups'][$group]; } $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">' . $count . '</td>'; } $return .= '<td style="width: 5em;"> </td>'; $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($week['amount']) . '</td>'; $return .= '</tr>'; $return .= '<tr style="height: 1px; background-color: #999;">'; $return .= '<td colspan="' . (count($groups) + 4) . '"></td>'; $return .= '</tr>'; $closer = 1; } $return .= '</table><br /><br />'; return $return; }
* @package AEC - Account Control Expiration - Membership Manager * @subpackage Install Includes * @copyright 2006-2015 Copyright (C) David Deutsch * @author David Deutsch <*****@*****.**> & Team AEC - http://www.valanx.org * @license GNU/GPL v.3 http://www.gnu.org/licenses/gpl.html or, at your option, any later version */ // Dont allow direct linking defined('_JEXEC') or die('Direct Access to this location is not allowed.'); // Check for a root group $db->setQuery("SELECT id FROM #__acctexp_itemgroups WHERE id='1'"); // Create root group completely out of thin air (tadaa!) if ($db->loadResult() != 1) { $rootgroup = new ItemGroup(); $rootgroup->id = 0; $rootgroup->active = 1; $rootgroup->visible = 1; $rootgroup->name = JText::_('AEC_INST_ROOT_GROUP_NAME'); $rootgroup->desc = JText::_('AEC_INST_ROOT_GROUP_DESC'); $rootgroup->params = array('color' => 'bbddff', 'icon' => 'flag_blue', 'reveal_child_items' => 1); $rootgroup->storeload(); if ($rootgroup->id != 1) { $db->setQuery("UPDATE #__acctexp_itemgroups SET id='1' WHERE id='" . $rootgroup->id . "'"); $db->query(); } // Adding in root group relation for all plans $planlist = SubscriptionPlanHandler::listPlans(); $db->setQuery("SELECT count(*) FROM #__acctexp_itemxgroup"); if (count($planlist) > $db->loadResult()) { ItemGroupHandler::setChildren(1, $planlist); } }
function export($type, $cmd = null) { $db = JFactory::getDBO(); $cmd_save = strcmp('save', $cmd) === 0; $cmd_apply = strcmp('apply', $cmd) === 0; $cmd_load = strcmp('load', $cmd) === 0; $cmd_export = strcmp('export', $cmd) === 0; $use_original = 0; $system_values = array(); $filter_values = array(); $options_values = array(); $params_values = array(); if ($type == 'sales') { $getpost = array('system' => array('selected_export', 'delete', 'save', 'save_name'), 'filter' => array('date_start', 'date_end', 'method', 'planid', 'groupid', 'status', 'orderby'), 'options' => array('collate', 'breakdown', 'breakdown_custom'), 'params' => array('export_method')); $pf = 8; } else { $getpost = array('system' => array('selected_export', 'delete', 'save', 'save_name'), 'filter' => array('planid', 'groupid', 'status', 'orderby'), 'options' => array('rewrite_rule'), 'params' => array('export_method')); $pf = 5; } $postfields = 0; foreach ($getpost as $name => $array) { $field = $name . '_values'; foreach ($array as $vname) { $vvalue = aecGetParam($vname, ''); if (!empty($vvalue)) { ${$field}[$vname] = $vvalue; $postfields++; } } } if (!empty($params_values['export_method'])) { $is_test = $params_values['export_method'] == 'test'; } else { $is_test = false; } $lists = array(); $pname = ""; if (!empty($system_values['selected_export']) || $cmd_save || $cmd_apply || $is_test) { $row = new aecExport($type == 'sales'); if (isset($system_values['selected_export'])) { $row->load($system_values['selected_export']); $pname = $row->name; } else { $row->load(0); } if (!empty($system_values['delete'])) { // User wants to delete the entry $row->delete(); } elseif (($cmd_save || $cmd_apply) && (!empty($system_values['selected_export']) || !empty($system_values['save_name']))) { // User wants to save an entry if (!empty($system_values['save'])) { // But as a copy of another entry $row->load(0); } $row->saveComplex($system_values['save_name'], $filter_values, $options_values, $params_values); if (!empty($system_values['save'])) { $system_values['selected_export'] = $row->getMax(); } } elseif (($cmd_save || $cmd_apply) && (empty($system_values['selected_export']) && !empty($system_values['save_name']) && $system_values['save']) && !$is_test) { // User wants to save a new entry $row->saveComplex($system_values['save_name'], $filter_values, $options_values, $params_values); } elseif ($cmd_load || count($postfields) && $postfields <= $pf && ($cmd_export || $is_test)) { if ($row->id) { // User wants to load an entry $filter_values = $row->filter; $options_values = $row->options; $params_values = $row->params; $pname = $row->name; $use_original = 1; } } } // Always store the last ten calls, but only if something is happening if ($cmd_save || $cmd_apply || $cmd_export) { $autorow = new aecExport($type == 'sales'); $autorow->load(0); $autorow->saveComplex('Autosave', $filter_values, $options_values, $params_values, true); if (isset($row)) { if ($autorow->filter == $row->filter && $autorow->options == $row->options && $autorow->params == $row->params) { $use_original = 1; } } } $filters = array('planid', 'groupid', 'status'); foreach ($filters as $filter) { if (!isset($filter_values[$filter])) { $filter_values[$filter] = array(); continue; } if (!is_array($filter_values[$filter])) { if (!empty($filter_values[$filter])) { $filter_values[$filter] = array($filter_values[$filter]); } else { $filter_values[$filter] = array(); } } } if ($is_test) { $row->params['export_method'] = 'test'; } // Create Parameters $params[] = array('userinfobox', 5); if ($type == 'members') { $params[] = array('section_paper', 'Compose Export'); $params['params_remap'] = array('subarea_change', 'params'); $params[] = array('div', '<div class="alert alert-info">'); $params[] = array('p', '<p>Take users that fit these criteria:</p>'); $params['groupid'] = array('list', ''); $params['planid'] = array('list', ''); $params['status'] = array('list', ''); $params[] = array('div_end', ''); $params[] = array('div', '<div class="alert alert-warning">'); $params[] = array('p', '<p>Order them like this:</p>'); $params['orderby'] = array('list', ''); $params[] = array('div_end', ''); $params[] = array('div', '<div class="alert alert-success">'); $params[] = array('p', '<p>And use these details for each line of the export:</p>'); $params['rewrite_rule'] = array('inputD', '[[user_id]];[[user_username]];[[subscription_expiration_date]]'); $params[] = array('div_end', ''); $params[] = array('section_end', ''); } else { $monthago = (int) gmdate('U') - 60 * 60 * 24 * 31; $params[] = array('section_paper', 'Compose Export'); $params['params_remap'] = array('subarea_change', 'params'); $params[] = array('div', '<div class="alert alert-info">'); $params[] = array('p', '<p>Collect Sales Data from this range:</p>'); $params['date_start'] = array('list_date', date('Y-m-d', $monthago)); $params['date_end'] = array('list_date', date('Y-m-d')); $params['method'] = array('list', ''); $params['planid'] = array('list', ''); $params['groupid'] = array('list', ''); $params[] = array('div_end', ''); $params[] = array('div', '<div class="alert alert-warning">'); $params[] = array('p', '<p>Collate it like this:</p>'); $params['collate'] = array('list', 'day'); $params[] = array('div_end', ''); $params[] = array('div', '<div class="alert alert-success">'); $params[] = array('p', '<p>Break down the data in each line like so:</p>'); $params['breakdown'] = array('list', 'month'); $params['breakdown_custom'] = array('inputD', ''); $params[] = array('div_end', ''); $params[] = array('section_end', ''); } if ($type == 'members') { $params[] = array('userinfobox', 5); $params[] = array('section_paper'); $rewriteswitches = array('cms', 'user', 'subscription', 'plan', 'invoice'); $params = AECToolbox::rewriteEngineInfo($rewriteswitches, $params); $params[] = array('section_end', ''); $params[] = array('2div_end', ''); } $params[] = array('2div_end', ''); $params[] = array('userinfobox', 5); $params[] = array('section_paper', 'Save or Load Export Presets'); $params[] = array('div', '<div class="form-wide">'); $params['selected_export'] = array('list', ''); $params['delete'] = array('checkbox'); $params['save'] = array('checkbox'); $params['save_name'] = array('inputC', $pname); $params[] = array('div_end', ''); $params[] = array('div', '<div class="right-btns">'); $params[] = array('p', '<a class="btn btn-primary" onclick="javascript: submitbutton(\'loadExport' . $type . '\')" href="#">' . aecHTML::Icon('upload') . ' Load Preset</a>'); $params[] = array('p', '<a class="btn btn-success" onclick="javascript: submitbutton(\'applyExport' . $type . '\')" href="#">' . aecHTML::Icon('download') . ' Save Preset</a>'); $params[] = array('p', '<a class="btn danger" onclick="javascript: submitbutton(\'saveExport' . $type . '\')" href="#">' . aecHTML::Icon('download-alt') . ' Save Preset & Exit</a>'); $params[] = array('div_end', ''); $params[] = array('section_end', ''); $params[] = array('2div_end', ''); $params[] = array('userinfobox', 5); $params[] = array('section_paper', 'Export'); $params['export_method'] = array('list', ''); $params[] = array('p', '<div class="right-btns"><div class="btn-group">'); $params[] = array('p', '<a class="btn btn-info" id="testexport" href="#export-result">' . aecHTML::Icon('eye-open') . ' Test Export</a>'); $params[] = array('p', '<a class="btn btn-success" onclick="javascript: submitbutton(\'exportExport' . $type . '\')" href="#">' . aecHTML::Icon('file') . ' Export Now</a>'); $params[] = array('2div_end', ''); $params[] = array('section_end', ''); $params[] = array('2div_end', ''); $params[] = array('userinfobox', 5); $params[] = array('div', '<div class="aec-settings-container" id="export-result">'); $params[] = array('h4', '<h4>Preview</h4>'); $params[] = array('2div_end', ''); // Create a list of export options // First, only the non-autosaved entries $query = 'SELECT `id`, `name`, `created_date`, `lastused_date`' . ' FROM #__acctexp_export' . ($type == 'sales' ? '_sales' : '') . ' WHERE `system` = \''; $db->setQuery($query . '0\''); $user_exports = $db->loadObjectList(); // Then the autosaved entries $db->setQuery($query . '1\''); $system_exports = $db->loadObjectList(); $entries = count($user_exports) + count($system_exports); $m = 0; if ($entries > 0) { $listitems = array(); $listitems[] = JHTML::_('select.option', 0, " --- Your Exports --- "); $user = false; for ($i = 0; $i < $entries; $i++) { if ($i >= count($user_exports) && $user === false) { $user = $i; $listitems[] = JHTML::_('select.option', 0, " --- Autosaves --- "); } if ($user === false) { if (!empty($user_exports[$i]->name)) { $used_date = $user_exports[$i]->lastused_date == '0000-00-00 00:00:00' ? 'never' : $user_exports[$i]->lastused_date; $listitems[] = JHTML::_('select.option', $user_exports[$i]->id, substr($user_exports[$i]->name, 0, 64) . ' - ' . 'last used: ' . $used_date . ', created: ' . $user_exports[$i]->created_date); } else { $m--; } } else { $ix = $i - $user; $used_date = $system_exports[$ix]->lastused_date == '0000-00-00 00:00:00' ? 'never' : $system_exports[$ix]->lastused_date; $listitems[] = JHTML::_('select.option', $system_exports[$ix]->id, substr($system_exports[$ix]->name, 0, 64) . ' - ' . 'last used: ' . $used_date . ', created: ' . $system_exports[$ix]->created_date); } } } else { $listitems[] = JHTML::_('select.option', 0, " --- No saved Preset available --- "); $listitems[] = JHTML::_('select.option', 0, " --- Your Exports --- ", 'value', 'text', true); $listitems[] = JHTML::_('select.option', 0, " --- Autosaves --- ", 'value', 'text', true); } $lists['selected_export'] = JHTML::_('select.genericlist', $listitems, 'selected_export', 'size="' . max(10, min(20, $entries + $m + 2)) . '" class="col-sm-7"', 'value', 'text', arrayValueDefault($system_values, 'selected_export', '')); // Get list of plans for filter $query = 'SELECT `id`, `name`' . ' FROM #__acctexp_plans' . ' ORDER BY `ordering`'; $db->setQuery($query); $db_plans = $db->loadObjectList(); $lists['planid'] = '<select id="plan-filter-select" class="col-sm-3" name="planid[]" multiple="multiple" size="5">'; foreach ($db_plans as $plan) { $lists['planid'] .= '<option value="' . $plan->id . '"' . (in_array($plan->id, $filter_values['planid']) ? ' selected="selected"' : '') . '>' . $plan->name . '</option>'; } $lists['planid'] .= '</select>'; $grouplist = ItemGroupHandler::getTree(); $lists['groupid'] = '<select id="group-filter-select" class="col-sm-3" name="groupid[]" multiple="multiple" size="5">'; foreach ($grouplist as $glisti) { if (defined('JPATH_MANIFESTS')) { $lists['groupid'] .= '<option value="' . $glisti[0] . '"' . (in_array($glisti[0], $filter_values['groupid']) ? ' selected="selected"' : '') . '>' . str_replace(' ', ' ', $glisti[1]) . '</option>'; } else { $lists['groupid'] .= '<option value="' . $glisti[0] . '"' . (in_array($glisti[0], $filter_values['groupid']) ? ' selected="selected"' : '') . '>' . $glisti[1] . '</option>'; } } $lists['groupid'] .= '</select>'; if ($type == 'members') { $status = array('excluded' => JText::_('AEC_SEL_EXCLUDED'), 'pending' => JText::_('AEC_SEL_PENDING'), 'active' => JText::_('AEC_SEL_ACTIVE'), 'expired' => JText::_('AEC_SEL_EXPIRED'), 'closed' => JText::_('AEC_SEL_CLOSED'), 'cancelled' => JText::_('AEC_SEL_CANCELLED'), 'hold' => JText::_('AEC_SEL_HOLD'), 'notconfig' => JText::_('AEC_SEL_NOT_CONFIGURED')); $lists['status'] = '<select id="status-group-select" name="status[]" multiple="multiple" size="5">'; foreach ($status as $id => $txt) { $lists['status'] .= '<option value="' . $id . '"' . (in_array($id, $filter_values['status']) ? ' selected="selected"' : '') . '>' . $txt . '</option>'; } $lists['status'] .= '</select>'; // Ordering $sel = array(); $sel[] = JHTML::_('select.option', 'expiration ASC', JText::_('EXP_ASC')); $sel[] = JHTML::_('select.option', 'expiration DESC', JText::_('EXP_DESC')); $sel[] = JHTML::_('select.option', 'name ASC', JText::_('NAME_ASC')); $sel[] = JHTML::_('select.option', 'name DESC', JText::_('NAME_DESC')); $sel[] = JHTML::_('select.option', 'username ASC', JText::_('LOGIN_ASC')); $sel[] = JHTML::_('select.option', 'username DESC', JText::_('LOGIN_DESC')); $sel[] = JHTML::_('select.option', 'signup_date ASC', JText::_('SIGNUP_ASC')); $sel[] = JHTML::_('select.option', 'signup_date DESC', JText::_('SIGNUP_DESC')); $sel[] = JHTML::_('select.option', 'lastpay_date ASC', JText::_('LASTPAY_ASC')); $sel[] = JHTML::_('select.option', 'lastpay_date DESC', JText::_('LASTPAY_DESC')); $sel[] = JHTML::_('select.option', 'plan_name ASC', JText::_('PLAN_ASC')); $sel[] = JHTML::_('select.option', 'plan_name DESC', JText::_('PLAN_DESC')); $sel[] = JHTML::_('select.option', 'status ASC', JText::_('STATUS_ASC')); $sel[] = JHTML::_('select.option', 'status DESC', JText::_('STATUS_DESC')); $sel[] = JHTML::_('select.option', 'type ASC', JText::_('TYPE_ASC')); $sel[] = JHTML::_('select.option', 'type DESC', JText::_('TYPE_DESC')); $lists['orderby'] = JHTML::_('select.genericlist', $sel, 'orderby', 'class="inputbox" size="1"', 'value', 'text', arrayValueDefault($filter_values, 'orderby', '')); } else { $collate_selection = array(); $collate_selection[] = JHTML::_('select.option', 'day', JText::_('Day')); $collate_selection[] = JHTML::_('select.option', 'week', JText::_('Week')); $collate_selection[] = JHTML::_('select.option', 'month', JText::_('Month')); $collate_selection[] = JHTML::_('select.option', 'year', JText::_('Year')); $selected_collate = 0; if (!empty($options_values['collate'])) { $selected_collate = $options_values['collate']; } else { $selected_collate = 'day'; } $lists['collate'] = JHTML::_('select.genericlist', $collate_selection, 'collate', 'size="1"', 'value', 'text', $selected_collate); $breakdown_selection = array(); $breakdown_selection[] = JHTML::_('select.option', '0', JText::_('None')); $breakdown_selection[] = JHTML::_('select.option', 'plan', JText::_('Plan')); $breakdown_selection[] = JHTML::_('select.option', 'group', JText::_('Group')); $selected_breakdown = 0; if (!empty($options_values['breakdown'])) { $selected_breakdown = $options_values['breakdown']; } $lists['breakdown'] = JHTML::_('select.genericlist', $breakdown_selection, 'breakdown', 'size="1"', 'value', 'text', $selected_breakdown); $processors = PaymentProcessorHandler::getInstalledObjectList(); $proc_list = array(); $selected_proc = array(); foreach ($processors as $proc) { $pp = new PaymentProcessor(); $pp->loadName($proc->name); $pp->getInfo(); $proc_list[] = JHTML::_('select.option', $pp->id, $pp->info['longname']); if (!empty($filter_values['method'])) { foreach ($filter_values['method'] as $id) { if ($id == $pp->id) { $selected_proc[] = JHTML::_('select.option', $id, $pp->info['longname']); } } } } $lists['method'] = JHTML::_('select.genericlist', $proc_list, 'method[]', 'size="8" multiple="multiple"', 'value', 'text', $selected_proc); } // Export Method $list = xJUtility::getFileArray(JPATH_SITE . '/components/com_acctexp/lib/export', 'php', false, true); $sel = array(); foreach ($list as $ltype) { $ltype = str_replace('.php', '', $ltype); if ($ltype != 'test') { $sel[] = JHTML::_('select.option', $ltype, $ltype); } } if (empty($params_values['export_method'])) { $params_values['export_method'] = 'csv'; } $lists['export_method'] = JHTML::_('select.genericlist', $sel, 'export_method', 'class="inputbox" size="1"', 'value', 'text', $params_values['export_method']); $settings = new aecSettings('export', 'general'); // Repackage the objects as array foreach ($getpost as $name => $array) { $field = $name . '_values'; foreach ($array as $vname) { if (!empty(${$field}->{$name})) { $settingsparams[$name] = ${$field}->{$name}; } else { $settingsparams[$name] = ""; } } } if (empty($params_values['rewrite_rule'])) { //$params_values['rewrite_rule'] = '[[user_id]];[[user_username]];[[subscription_expiration_date]]'; } $settingsparams = array_merge($filter_values, $options_values, $params_values); $settings->fullSettingsArray($params, $settingsparams, $lists); // Call HTML Class $aecHTML = new aecHTML($settings->settings, $settings->lists); if ($cmd_export && !empty($params_values['export_method'])) { if ($use_original) { $row->useExport(); } else { $autorow->useExport(); } } if ($cmd_save) { aecRedirect('index.php?option=com_acctexp&task=showCentral'); } else { HTML_AcctExp::export($type, $aecHTML); } }
public function actionRestrictionCheck() { $this->response->result = false; if (!empty($this->request->details->plan)) { $plan = new SubscriptionPlan(); $plan->load($this->request->details->plan); if ($plan->id != $this->request->details->plan) { $this->error = 'could not find plan to check restrictions for'; return; } $restrictions = $plan->getRestrictionsArray(); if (aecRestrictionHelper::checkRestriction($restrictions, $this->metaUser) !== false) { if (!ItemGroupHandler::checkParentRestrictions($plan, 'item', $this->metaUser)) { $this->error = 'user is denied permission - plans parent group is restricted from this user'; } } else { $this->error = 'user is denied permission - plan is restricted from this user'; } unset($this->request->details->plan); } if (!empty($this->request->details->group)) { $group = new ItemGroup(); $group->load($this->request->details->group); if ($group->id != $this->request->details->group) { $this->error = 'could not find group to check restrictions for'; return; } $restrictions = $group->getRestrictionsArray(); if (aecRestrictionHelper::checkRestriction($restrictions, $this->metaUser) !== false) { if (!ItemGroupHandler::checkParentRestrictions($group, 'group', $this->metaUser)) { $this->error = 'user is denied permission - groups parent group is restricted from this user'; } } else { $this->error = 'user is denied permission - group is restricted from this user'; } unset($this->request->details->group); } if (!empty($this->request->details)) { $re = get_object_vars($this->request->details); $restrictions = aecRestrictionHelper::getRestrictionsArray($re); if (aecRestrictionHelper::checkRestriction($restrictions, $this->metaUser) === false) { $this->error = 'user is denied permission - at least one restriction result was negative'; } } if (empty($this->error)) { $this->response->result = true; } }
public function copy() { $pid = $this->id; $this->id = 0; $this->storeload(); $parents = ItemGroupHandler::parentGroups($pid, 'group'); foreach ($parents as $parentid) { ItemGroupHandler::setChild($this->id, $parentid, 'group'); } }
public function create($intro = 0, $usage = 0, $group = 0, $processor = null, $invoice = 0, $autoselect = false) { global $aecConfig; $register = !$this->loadMetaUser(true); $this->getPassthrough(); // Reset $register if we seem to have all data if ($register && !empty($this->passthrough['username']) || !empty($aecConfig->cfg['skip_registration'])) { $register = 0; } if ($intro && $this->metaUser->hasSubscription && !$aecConfig->cfg['customintro_always']) { $intro = false; } if (empty($this->usage) && empty($group) && !$intro && !empty($aecConfig->cfg['customintro'])) { if (!empty($aecConfig->cfg['customintro_userid'])) { aecRedirect($aecConfig->cfg['customintro'], $this->userid, "aechidden"); } else { aecRedirect($aecConfig->cfg['customintro']); } } $this->recurring = aecGetParam('recurring', null); $planlist = new SubscriptionPlanList($usage, $group, $this->metaUser, $this->recurring); $nochoice = false; // There is no choice if we have only one group or only one item with one payment option if (count($planlist->list) === 1) { if ($planlist->list[0]['type'] == 'item') { if (count($planlist->list[0]['gw']) === 1) { $nochoice = true; } elseif (!empty($processor)) { foreach ($planlist->list[0]['gw'] as $gw) { if ($gw->processor_name == $processor) { $nochoice = true; } } if ($nochoice) { $first = 0; foreach ($planlist->list[0]['gw'] as $gwid => $gw) { if ($gw->processor_name != $processor) { unset($planlist->list[0]['gw'][$gwid]); } else { $first = $gwid; } } if (!empty($first)) { $planlist->list[0]['gw'][0] = $planlist->list[0]['gw'][$first]; unset($planlist->list[0]['gw'][$first]); } } } } else { // Jump back and use the only group we've found return $this->create($intro, 0, $planlist->list[0]['id'], null, 0, true); } } // If we have only one processor on one plan, there is no need for a decision if ($nochoice && !($aecConfig->cfg['show_fixeddecision'] && empty($processor))) { // If the user also needs to register, we need to guide him there after the selection has now been made if ($register && empty($aecConfig->cfg['skip_registration'])) { aecRegistration::registerRedirect($intro, $planlist->list[0]); } else { // Existing user account - so we need to move on to the confirmation page with the details $this->usage = $planlist->list[0]['id']; if (isset($planlist->list[0]['gw'][0]->recurring)) { $this->recurring = $planlist->list[0]['gw'][0]->recurring; } else { $this->recurring = 0; } $this->processor = $planlist->list[0]['gw'][0]->processor_name; if ($invoice != 0 && !is_null($invoice)) { $this->invoice_number = $invoice; } return $this->confirm(); } } if ($group) { $g = new ItemGroup(); $g->load($group); $planlist->list['group'] = ItemGroupHandler::getGroupListItem($g); } $cart = $this->userid ? aecCartHelper::getCartidbyUserid($this->userid) : false; $selected = (!empty($group) || !empty($usage)) && !$autoselect; if (!$selected && !empty($planlist->list['group'])) { unset($planlist->list['group']); } $passthrough = $this->getPassthrough(); $csslist = $planlist->addButtons($register, $passthrough); return getView('plans', array('userid' => $this->userid, 'list' => $planlist->list, 'passthrough' => $passthrough, 'register' => $register, 'cart' => $cart, 'selected' => $selected, 'group' => $group, 'csslist' => $csslist)); }
public function createGroups($amount) { $db = JFactory::getDBO(); if (!$_POST['create_groups']) { $query = 'SELECT MIN(id)' . ' FROM #__acctexp_itemgroups' . ' WHERE `id` > 1'; $db->setQuery($query); $this->range['groups']['start'] = $db->loadResult(); $query = 'SELECT MAX(id)' . ' FROM #__acctexp_itemgroups'; $db->setQuery($query); $this->range['groups']['end'] = $db->loadResult(); return array(); } $colors = array('1f77b4', 'aec7e8', 'ff7f0e', 'ffbb78', '2ca02c', '98df8a', 'd62728', 'ff9896', '9467bd', 'c5b0d5', '8c564b', 'c49c94', 'e377c2', 'f7b6d2', '7f7f7f', 'c7c7c7', 'bcbd22', 'dbdb8d', '17becf', '9edae5', 'BBDDFF', '5F8BC4', 'A2BE72', 'DDFF99', 'D07C30', 'C43C42', 'AA89BB', 'B7B7B7', '808080'); $grouplist = array(); for ($i = 0; $i <= $amount; $i++) { $row = new ItemGroup(); $post = array('active' => 1, 'visible' => 0, 'name' => 'Group ' . ($i + 1), 'desc' => 'Group ' . ($i + 1), 'color' => $colors[$i % 29]); $row->savePOSTsettings($post); $row->storeload(); ItemGroupHandler::setChildren(1, array($row->id), $type = 'group'); if ($i == 0) { $this->range['groups']['start'] = $row->id; } elseif ($i == $amount) { $this->range['groups']['end'] = $row->id; } $grouplist[] = $row->id; } return $grouplist; }
public function delete($pk = null) { ItemGroupHandler::removeChildren($this->id); return parent::delete($pk); }
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); }
/** * @param string $gkey * @param string $pkey */ static function addGroupPlans($source, $gkey, $pkey, $target = null) { $okey = str_replace('_req', '_req_enabled', $pkey); if (!is_array($source[$pkey]) || empty($source[$okey])) { $plans = array(); } else { $plans = $source[$pkey]; } $newplans = ItemGroupHandler::getGroupsPlans($source[$gkey]); $plans = array_merge($plans, $newplans); $plans = array_unique($plans); if (is_null($target)) { $restrictions[$pkey] = $plans; return $restrictions; } else { $target[$pkey] = $plans; return $target; } }