public function explodePlanList($recurring)
 {
     global $aecConfig;
     $groups = array();
     $plans = array();
     $gs = array();
     $ps = array();
     // Break apart groups and items, make sure we have no duplicates
     foreach ($this->list as $litem) {
         if ($litem['type'] == 'group') {
             if (!in_array($litem['id'], $gs)) {
                 $gs[] = $litem['id'];
                 $groups[] = $litem;
             }
         } else {
             if (!in_array($litem['id'], $ps)) {
                 if (ItemGroupHandler::checkParentRestrictions($litem['plan'], 'item', $this->metaUser)) {
                     $ps[] = $litem['id'];
                     $plans[] = $litem;
                 }
             }
         }
     }
     foreach ($plans as $pid => $plan) {
         if (!isset($plan['plan']->params['cart_behavior'])) {
             $plan['plan']->params['cart_behavior'] = 0;
         }
         if ($this->metaUser->userid && !$this->expired && ($aecConfig->cfg['enable_shoppingcart'] || $plan['plan']->params['cart_behavior'] == 1) && $plan['plan']->params['cart_behavior'] != 2) {
             // We have a shopping cart situation, care about processors later
             if ($plan['plan']->params['processors'] == '' || is_null($plan['plan']->params['processors'])) {
                 if (!$plan['plan']->params['full_free']) {
                     continue;
                 }
             }
             $plans[$pid]['gw'][0] = new stdClass();
             $plans[$pid]['gw'][0]->processor_name = 'add_to_cart';
             $plans[$pid]['gw'][0]->info['statement'] = '';
             $plans[$pid]['gw'][0]->recurring = 0;
             continue;
         }
         if (empty($plan['select_mode'])) {
             $select_mode = '0';
         } else {
             $select_mode = $plan['select_mode'];
         }
         if ($select_mode == 1) {
             // We want to only select the processors on confirmation
             if ($plan['plan']->params['processors'] == '' || is_null($plan['plan']->params['processors'])) {
                 if (!$plan['plan']->params['full_free']) {
                     continue;
                 }
             }
             $plans[$pid]['gw'][0] = new stdClass();
             $plans[$pid]['gw'][0]->processor_name = 'select';
             $plans[$pid]['gw'][0]->info['statement'] = '';
             $plans[$pid]['gw'][0]->recurring = 0;
             continue;
         }
         if ($plan['plan']->params['full_free']) {
             $plans[$pid]['gw'][0] = new stdClass();
             $plans[$pid]['gw'][0]->processor_name = 'free';
             $plans[$pid]['gw'][0]->info['statement'] = '';
             $plans[$pid]['gw'][0]->recurring = 0;
         } else {
             if ($plan['plan']->params['processors'] != '' && !is_null($plan['plan']->params['processors'])) {
                 $processors = array_reverse($plan['plan']->params['processors']);
                 // Restrict to pre-chosen processor (if set)
                 if (!empty($this->processor)) {
                     $processorid = PaymentProcessorHandler::getProcessorIdfromName($this->processor);
                     if (in_array($processorid, $processors)) {
                         $processors = array($processorid);
                     }
                 }
                 $plan_gw = array();
                 if (count($processors)) {
                     foreach ($processors as $n) {
                         if (empty($n)) {
                             continue;
                         }
                         $pp = new PaymentProcessor();
                         if (!$pp->loadId($n)) {
                             continue;
                         }
                         if (!$pp->processor->active) {
                             continue;
                         }
                         $pp->init();
                         $pp->getInfo();
                         $pp->exchangeSettingsByPlan($plan['plan']);
                         $recurring = $pp->is_recurring($recurring, true);
                         if ($recurring > 1) {
                             $pp->recurring = 0;
                             $plan_gw[] = $pp;
                             if (!$plan['plan']->params['lifetime']) {
                                 $pp = new PaymentProcessor();
                                 $pp->loadId($n);
                                 $pp->init();
                                 $pp->getInfo();
                                 $pp->exchangeSettingsByPlan($plan['plan']);
                                 $pp->recurring = 1;
                                 $plan_gw[] = $pp;
                             }
                         } elseif (!($plan['plan']->params['lifetime'] && $recurring)) {
                             if (is_int($recurring)) {
                                 $pp->recurring = $recurring;
                             }
                             $plan_gw[] = $pp;
                         }
                     }
                 }
                 if (!empty($plan_gw)) {
                     $plans[$pid]['gw'] = $plan_gw;
                 } else {
                     unset($plans[$pid]);
                 }
             }
         }
     }
     $this->list = array_merge($groups, $plans);
 }
示例#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;
 }
示例#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;
 }