Ejemplo n.º 1
0
 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') . '&nbsp;Load Preset</a>');
     $params[] = array('p', '<a class="btn btn-success" onclick="javascript: submitbutton(\'applyExport' . $type . '\')" href="#">' . aecHTML::Icon('download') . '&nbsp;Save Preset</a>');
     $params[] = array('p', '<a class="btn danger" onclick="javascript: submitbutton(\'saveExport' . $type . '\')" href="#">' . aecHTML::Icon('download-alt') . '&nbsp;Save Preset &amp; 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') . '&nbsp;Test Export</a>');
     $params[] = array('p', '<a class="btn btn-success" onclick="javascript: submitbutton(\'exportExport' . $type . '\')" href="#">' . aecHTML::Icon('file') . '&nbsp;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('&nbsp;', ' ', $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);
     }
 }
Ejemplo n.º 2
0
 public function getPrintout($InvoiceFactory, $forcecleared = false, $forcecounter = null)
 {
     global $aecConfig;
     if (is_null($forcecounter)) {
         $this->counter = $forcecounter;
     }
     if ($this->transaction_date == '0000-00-00 00:00:00' && $forcecleared) {
         $this->transaction_date = date('Y-m-d H:i:s', (int) gmdate('U'));
     }
     $data = $this->getWorkingData($InvoiceFactory);
     $data['invoice_id'] = $this->id;
     $data['invoice_number'] = $this->invoice_number;
     $data['invoice_date'] = aecTemplate::date($InvoiceFactory->invoice->created_date);
     $data['itemlist'] = array();
     foreach ($InvoiceFactory->items->itemlist as $iid => $item) {
         if (isset($item['obj'])) {
             $amt = $item['terms']->nextterm->cost[0]->cost['amount'];
             $data['itemlist'][] = '<tr id="invoice_content_item">' . '<td>' . $item['name'] . '</td>' . '<td>' . AECToolbox::formatAmount($amt, $InvoiceFactory->invoice->currency) . '</td>' . '<td>' . $item['quantity'] . '</td>' . '<td>' . AECToolbox::formatAmount($amt * $item['quantity'], $InvoiceFactory->invoice->currency) . '</td>' . '</tr>';
             foreach ($item['terms']->nextterm->cost as $cid => $cost) {
                 if ($cid != 0) {
                     if ($cost->type == 'discount') {
                         if (!empty($cost->cost['details'])) {
                             $ta = '&nbsp;(' . $cost->cost['details'] . ')';
                         } else {
                             $ta = "";
                         }
                         $data['itemlist'][] = '<tr id="invoice_content_item">' . '<td>' . JText::_('AEC_CHECKOUT_DISCOUNT') . $ta . '</td>' . '<td></td>' . '<td></td>' . '<td>' . AECToolbox::formatAmount($cost->cost['amount'], $InvoiceFactory->invoice->currency) . '</td>' . '</tr>';
                     } elseif ($cost->type == 'cost') {
                         if (!empty($cost->cost['details'])) {
                             $ta = '&nbsp;(' . $cost->cost['details'] . ')';
                         } else {
                             $ta = "";
                         }
                         $data['itemlist'][] = '<tr id="invoice_content_item">' . '<td>' . $ta . '</td>' . '<td></td>' . '<td></td>' . '<td>' . AECToolbox::formatAmount($cost->cost['amount'], $InvoiceFactory->invoice->currency) . '</td>' . '</tr>';
                     }
                 }
             }
         }
     }
     $data['totallist'][] = '<tr id="invoice_content_item_separator">' . '<td colspan="4"></td>' . '</tr>';
     if (isset($InvoiceFactory->items->tax)) {
         if (isset($InvoiceFactory->items->total)) {
             $data['totallist'][] = '<tr id="invoice_content_item_total">' . '<td>' . JText::_('INVOICEPRINT_TOTAL') . '</td>' . '<td></td>' . '<td></td>' . '<td>' . AECToolbox::formatAmount($InvoiceFactory->items->total->cost['amount'], $InvoiceFactory->invoice->currency) . '</td>' . '</tr>';
         }
         foreach ($InvoiceFactory->items->tax as $item) {
             $details = null;
             foreach ($item['terms']->terms[0]->cost as $citem) {
                 if ($citem->type == 'tax') {
                     $details = $citem->cost['details'];
                 }
             }
             $data['totallist'][] = '<tr id="invoice_content_item_tax">' . '<td>Tax' . '&nbsp;( ' . $details . ' )' . '</td>' . '<td></td>' . '<td></td>' . '<td>' . AECToolbox::formatAmount($item['cost'], $InvoiceFactory->invoice->currency) . '</td>' . '</tr>';
         }
     }
     if (isset($InvoiceFactory->items->grand_total)) {
         $data['totallist'][] = '<tr id="invoice_content_item_total">' . '<td>' . JText::_('INVOICEPRINT_GRAND_TOTAL') . '</td>' . '<td></td>' . '<td></td>' . '<td>' . AECToolbox::formatAmount($InvoiceFactory->items->grand_total->cost['amount'], $InvoiceFactory->invoice->currency) . '</td>' . '</tr>';
     }
     if ($this->transaction_date == '0000-00-00 00:00:00') {
         if (!$this->active) {
             $data['paidstatus'] = JText::_('INVOICEPRINT_PAIDSTATUS_CANCEL');
         } else {
             $data['paidstatus'] = JText::_('INVOICEPRINT_PAIDSTATUS_UNPAID');
         }
     } else {
         if (!$this->active) {
             $data['paidstatus'] = JText::_('INVOICEPRINT_PAIDSTATUS_CANCEL');
         } else {
             $date = AECToolbox::formatDate($this->transaction_date);
             $data['paidstatus'] = sprintf(JText::_('INVOICEPRINT_PAIDSTATUS_PAID'), $date);
         }
     }
     $pplist = array();
     if ($this->method != 'none') {
         $pp = new PaymentProcessor();
         if ($pp->loadName($this->method)) {
             $pp->init();
             $pp->getInfo();
             if (!empty($InvoiceFactory->plan->id)) {
                 $pp->exchangeSettingsByPlan($InvoiceFactory->plan->id, $InvoiceFactory->plan->params);
             }
         }
     } else {
         $pp = null;
     }
     $pplist[$this->method] = $pp;
     $recurring = false;
     if (!empty($pp)) {
         $recurring = $pplist[$this->method]->is_recurring();
     }
     $data['recurringstatus'] = "";
     if ($recurring) {
         $data['recurringstatus'] = JText::_('INVOICEPRINT_RECURRINGSTATUS_RECURRING');
     } elseif (!empty($InvoiceFactory->plan->id)) {
         if (!empty($InvoiceFactory->plan->params['trial_amount']) && $InvoiceFactory->plan->params['trial_period']) {
             $data['recurringstatus'] = JText::_('INVOICEPRINT_RECURRINGSTATUS_ONCE');
         }
     }
     $data['invoice_billing_history'] = "";
     if (!empty($this->transactions)) {
         if (count($this->transactions) > 0 && !empty($data['recurringstatus']) && $this->method != 'none') {
             $data['paidstatus'] = sprintf(JText::_('INVOICEPRINT_PAIDSTATUS_PAID'), "");
             foreach ($this->transactions as $transaction) {
                 if (!isset($pplist[$transaction->processor])) {
                     $pp = new PaymentProcessor();
                     if ($pp->loadName($transaction->processor)) {
                         $pp->getInfo();
                         $pplist[$transaction->processor] = $pp;
                     }
                 }
                 $data['invoice_billing_history'] .= '<tr><td>' . AECToolbox::formatDate($transaction->timestamp) . '</td><td>' . $transaction->amount . '&nbsp;' . $transaction->currency . '</td><td>' . $pplist[$transaction->processor]->info['longname'] . '</td></tr>';
             }
         }
     }
     $s = array("before_header", "header", "after_header", "address", "before_content", "after_content", "before_footer", "footer", "after_footer");
     foreach ($s as $k) {
         if (empty($data[$k])) {
             $data[$k] = "";
         }
     }
     return $data;
 }
Ejemplo n.º 3
0
 static function getCartProcessorGroups($cart, $recurring = false)
 {
     $pgroups = array();
     foreach ($cart->content as $cid => $c) {
         $cartitem = aecCartHelper::getCartItemObject($cart, $cid);
         $pplist = array();
         $pplist_names = array();
         if (!empty($cartitem->params['processors'])) {
             foreach ($cartitem->params['processors'] as $n) {
                 $pp = new PaymentProcessor();
                 if (!$pp->loadId($n)) {
                     continue;
                 }
                 $pp->init();
                 $pp->getInfo();
                 $pp->exchangeSettingsByPlan($cartitem);
                 if (isset($recurring)) {
                     $recurring = $pp->is_recurring($recurring);
                 } else {
                     $recurring = $pp->is_recurring();
                 }
                 if ($recurring > 1) {
                     $pplist[] = $pp->id;
                     $pplist_names[] = $pp->info['longname'];
                     if (!$cartitem->params['lifetime']) {
                         $pplist[] = $pp->id . '_recurring';
                         $pplist_names[] = $pp->info['longname'];
                     }
                 } elseif (!$cartitem->params['lifetime'] && $recurring) {
                     $pplist[] = $pp->id . '_recurring';
                     $pplist_names[] = $pp->info['longname'];
                 } else {
                     $pplist[] = $pp->id;
                     $pplist_names[] = $pp->info['longname'];
                 }
             }
         }
         if (empty($pplist)) {
             continue;
         }
         if (empty($pgroups)) {
             $pg = array();
             $pg['members'] = array($cid);
             $pg['processors'] = $pplist;
             $pg['processor_names'] = $pplist_names;
             $pgroups[] = $pg;
         } else {
             $create = true;
             foreach ($pgroups as $pgid => $pgroup) {
                 $pg = array();
                 if (count($pplist) == count($pgroup['processors'])) {
                     $a = true;
                     foreach ($pplist as $k => $v) {
                         if ($pgroup['processors'][$k] != $v) {
                             $a = false;
                         }
                     }
                     if ($a) {
                         $pgroups[$pgid]['members'][] = $cid;
                         $create = false;
                     }
                 }
             }
             if ($create) {
                 $pg['members'] = array($cid);
                 $pg['processors'] = $pplist;
                 $pg['processor_names'] = $pplist_names;
                 $pgroups[] = $pg;
             }
         }
     }
     return $pgroups;
 }
 public function applyPlan($user, $processor = 'none', $silent = 0, $multiplicator = 1, $invoice = null, $tempparams = null)
 {
     global $aecConfig;
     $forcelifetime = false;
     if (is_string($multiplicator)) {
         if (strcmp($multiplicator, 'lifetime') === 0) {
             $forcelifetime = true;
         }
     } elseif (is_int($multiplicator) && $multiplicator < 1) {
         $multiplicator = 1;
     }
     if (empty($user)) {
         return false;
     }
     if (is_object($user)) {
         if (is_a($user, 'metaUser')) {
             $metaUser = $user;
         } elseif (is_a($user, 'Subscription')) {
             $metaUser = new metaUser($user->userid);
             $metaUser->focusSubscription = $user;
         }
     } else {
         $metaUser = new metaUser($user);
     }
     if (!isset($this->params['make_primary'])) {
         $this->params['make_primary'] = 1;
     }
     $fstatus = $metaUser->establishFocus($this, $processor, false);
     // TODO: Figure out why $status returns 'existing' - even on a completely fresh subscr
     if ($fstatus != 'existing') {
         $is_pending = $metaUser->focusSubscription->isPending();
         $is_trial = $metaUser->focusSubscription->isTrial();
     } else {
         $is_pending = false;
         $is_trial = $metaUser->focusSubscription->isTrial();
     }
     $comparison = $this->doPlanComparison($metaUser->focusSubscription);
     $renew = $metaUser->is_renewing();
     $lifetime = $metaUser->focusSubscription->lifetime;
     if ($comparison['total_comparison'] === false || $is_pending) {
         // If user is using global trial period he still can use the trial period of a plan
         if ($this->params['trial_period'] > 0 && !$is_trial) {
             $trial = true;
             $value = $this->params['trial_period'];
             $perunit = $this->params['trial_periodunit'];
             $this->params['lifetime'] = 0;
             // We are entering the trial period. The lifetime will come at the renew.
             $amount = $this->params['trial_amount'];
         } else {
             $trial = false;
             $value = $this->params['full_period'];
             $perunit = $this->params['full_periodunit'];
             $amount = $this->params['full_amount'];
         }
     } elseif (!$is_pending) {
         $trial = false;
         $value = $this->params['full_period'];
         $perunit = $this->params['full_periodunit'];
         $amount = $this->params['full_amount'];
     } else {
         return false;
     }
     if ($this->params['lifetime'] || $forcelifetime) {
         $metaUser->focusSubscription->expiration = '9999-12-31 00:00:00';
         $metaUser->focusSubscription->lifetime = 1;
     } else {
         $metaUser->focusSubscription->lifetime = 0;
         $value *= $multiplicator;
         if ($comparison['comparison'] == 2 && !$lifetime) {
             $metaUser->focusSubscription->setExpiration($perunit, $value, 1);
         } else {
             $metaUser->focusSubscription->setExpiration($perunit, $value, 0);
         }
     }
     if ($is_pending) {
         // Is new = set signup date
         $metaUser->focusSubscription->signup_date = date('Y-m-d H:i:s', (int) gmdate('U'));
         if ($this->params['trial_period'] > 0 && !$is_trial) {
             $status = 'Trial';
         } else {
             if ($this->params['full_period'] || $this->params['lifetime']) {
                 if (!isset($this->params['make_active'])) {
                     $status = 'Active';
                 } else {
                     $status = $this->params['make_active'] ? 'Active' : 'Pending';
                 }
             } else {
                 // This should not happen
                 $status = 'Pending';
             }
         }
     } else {
         // Renew subscription - Do NOT set signup_date
         if (!isset($this->params['make_active'])) {
             $status = $trial ? 'Trial' : 'Active';
         } else {
             $status = $this->params['make_active'] ? $trial ? 'Trial' : 'Active' : 'Pending';
         }
     }
     $metaUser->focusSubscription->status = $status;
     $metaUser->focusSubscription->plan = $this->id;
     $metaUser->temporaryRFIX();
     $metaUser->focusSubscription->lastpay_date = date('Y-m-d H:i:s', (int) gmdate('U'));
     $metaUser->focusSubscription->type = $processor;
     if (is_object($invoice)) {
         if (!empty($invoice->params)) {
             $tempparam = array();
             if (!empty($invoice->params['creator_ip'])) {
                 $tempparam['creator_ip'] = $invoice->params['creator_ip'];
             }
             if (!empty($tempparam)) {
                 $metaUser->focusSubscription->addParams($tempparam, 'params', false);
                 $metaUser->focusSubscription->storeload();
             }
         }
     }
     $pp = new PaymentProcessor();
     if ($pp->loadName(strtolower($processor))) {
         $pp->init();
         $pp->getInfo();
         $recurring_choice = null;
         if (is_object($invoice)) {
             if (!empty($invoice->params)) {
                 if (isset($invoice->params["userselect_recurring"])) {
                     $recurring_choice = $invoice->params["userselect_recurring"];
                 }
             }
         }
         // Check whether we have a custome choice set
         if (!is_null($recurring_choice)) {
             $metaUser->focusSubscription->recurring = $pp->is_recurring($recurring_choice);
         } else {
             $metaUser->focusSubscription->recurring = $pp->is_recurring();
         }
     } else {
         $metaUser->focusSubscription->recurring = 0;
     }
     $metaUser->focusSubscription->storeload();
     if (empty($invoice->id)) {
         $invoice = new stdClass();
         $invoice->amount = $amount;
     }
     $exchange = $add = null;
     $result = $this->triggerMIs('action', $metaUser, $exchange, $invoice, $add, $silent);
     if ($result === false) {
         return false;
     } elseif ($result === true) {
         // MIs might have changed the subscription. Reload it.
         $metaUser->focusSubscription->reload();
     }
     if ($this->params['gid_enabled']) {
         $metaUser->instantGIDchange($this->params['gid']);
     }
     $metaUser->focusSubscription->storeload();
     if (!($silent || $aecConfig->cfg['noemails']) || $aecConfig->cfg['noemails_adminoverride']) {
         $adminonly = $this->id == $aecConfig->cfg['entry_plan'] || $aecConfig->cfg['noemails'] && $aecConfig->cfg['noemails_adminoverride'];
         $metaUser->focusSubscription->sendEmailRegistered($renew, $adminonly, $invoice);
     }
     $metaUser->meta->addPlanID($this->id);
     $result = $this->triggerMIs('afteraction', $metaUser, $exchange, $invoice, $add, $silent);
     if ($result === false) {
         return false;
     }
     $this->incrementInventory();
     return $renew;
 }
 public static function getSelectList($selection = "", $installed = false)
 {
     $pplist = self::getProcessorList();
     $pp_installed_list = self::getInstalledObjectList(false, true);
     asort($pplist);
     $pp_list_html = array();
     foreach ($pplist as $ppname) {
         if (in_array($ppname, $pp_installed_list) && !$installed) {
             continue;
         } elseif (!in_array($ppname, $pp_installed_list) && $installed) {
             continue;
         }
         // Load Payment Processor
         $pp = new PaymentProcessor();
         if ($pp->loadName($ppname)) {
             xJLanguageHandler::loadList(array('com_acctexp.processors.' . $ppname => JPATH_SITE . '/components/com_acctexp/processors/' . $ppname));
             $pp->getInfo();
             if (!empty($pp->info['longname'])) {
                 $name = $pp->info['longname'];
             } else {
                 $name = ucwords(str_replace('_', ' ', strtolower($ppname)));
             }
             // Add to general PP List
             $pp_list_html[] = JHTML::_('select.option', $ppname, $name);
         }
     }
     $size = $installed ? 1 : max(min(count($pplist), 24), 2);
     return JHTML::_('select.genericlist', $pp_list_html, 'processor', 'size="' . $size . '"', 'value', 'text', $selection);
 }