function show_payment_summary() { global $order, $db; $payments = billingmethod::$payment_types; $order_ids = array(); if (isset($this->params['applytoall']) && $this->params['applytoall'] == 1) { $obs = expSession::get('order_export_values'); foreach ($obs as $ob) { $order_ids[] = $ob->id; } } else { foreach ($this->params['act-upon'] as $order_id) { $order_ids[] = $order_id; } } $order_ids = array_unique($order_ids); $orders_string = implode(',', $order_ids); $payment_summary = array(); // $Credit Cards $sql = "SELECT orders_id, billing_cost, billing_options, calculator_name, user_title FROM " . DB_TABLE_PREFIX . "_billingmethods, " . DB_TABLE_PREFIX . "_billingcalculator WHERE " . DB_TABLE_PREFIX . "_billingcalculator.id = billingcalculator_id and orders_id IN (" . $orders_string . ")"; $res = $db->selectObjectsBySql($sql); if (!empty($res)) { foreach ($res as $item) { $options = unserialize($item->billing_options); if (!empty($item->billing_cost)) { if ($item->user_title == 'Credit Card') { if (!empty($options->cc_type)) { //@$payment_summary[$payments[$options->cc_type]] += $item->billing_cost; @($payment_summary[$payments[$options->cc_type]] += $options->result->amount_captured); } } else { @($payment_summary[$payments[$item->calculator_name]] += $item->billing_cost); } } } } foreach ($payment_summary as $key => $item) { $payments_key_arr[] = '"' . $key . '"'; $payment_values_arr[] = round($item, 2); } $payments_key = implode(",", $payments_key_arr); $payment_values = implode(",", $payment_values_arr); //tax $tax_sql = "SELECT SUM(tax) as tax_total FROM " . DB_TABLE_PREFIX . "_orders WHERE id IN (" . $orders_string . ")"; $tax_res = $db->selectObjectBySql($tax_sql); $tax_types = taxController::getTaxClasses(); $tax_type_formatted = $tax_types[0]->zonename . ' - ' . $tax_types[0]->classname . ' - ' . $tax_types[0]->rate . '%'; assign_to_template(array('payment_summary' => $payment_summary, 'payments_key' => $payments_key, 'payment_values' => $payment_values, 'tax_total' => $tax_res->tax_total, 'tax_type' => $tax_type_formatted)); }
function manage() { expHistory::set('manageable', $this->params); $taxes = taxController::getTaxClasses(); assign_to_template(array('taxes' => $taxes)); }
/** * This is the main invoice collector. It collects all items for a userid and also * can fix the invoice and imports all cancelled invoices which should be reinvoiced. * For every service category it fires up the collector, fetches data and pushes the * rows through the taxcontroller to apply taxes before they finally get stored in * self::invoices. * * @param int UserId to handle * @param bool Fix invoice * @return bool true if everything went okay, false if something went wrong * * @author Former03 GmbH :: Florian Lippert <*****@*****.**> */ function collect($userId, $fixInvoice = false) { $this->userId = $userId; $this->user = $this->db->query_first('SELECT * FROM `' . getModeDetails($this->mode, 'TABLE_PANEL_USERS', 'table') . '` WHERE `' . getModeDetails($this->mode, 'TABLE_PANEL_USERS', 'key') . '` = \'' . $this->userId . '\' '); if ($this->userId == 0 || !is_array($this->user) || empty($this->user) || $this->user[getModeDetails($this->mode, 'TABLE_PANEL_USERS', 'key')] != $this->userId) { return false; } $taxController = new taxController(&$this->db); if ($this->user['calc_tax'] === '1') { $taxController->calc_tax = true; } else { $taxController->calc_tax = false; } $cancelledInvoices_result = $this->db->query('SELECT * FROM `' . getModeDetails($this->mode, 'TABLE_BILLING_INVOICES', 'table') . '` WHERE `' . getModeDetails($this->mode, 'TABLE_BILLING_INVOICES', 'key') . '` = \'' . $this->userId . '\' AND ( `state` = \'' . CONST_BILLING_INVOICESTATE_CANCELLED_REINVOICE_WITHOUT_CREDIT_NOTE . '\' OR `state` = \'' . CONST_BILLING_INVOICESTATE_CANCELLED_REINVOICE_WITH_CREDIT_NOTE . '\' ) '); while ($cancelledInvoices_row = $this->db->fetch_array($cancelledInvoices_result)) { $this->importXml($cancelledInvoices_row['xml']); $this->cancelledInvoices[$cancelledInvoices_row['id']] = $cancelledInvoices_row; } if ($fixInvoice === true && !empty($this->cancelledInvoices)) { $this->db->query('UPDATE `' . getModeDetails($this->mode, 'TABLE_BILLING_INVOICES', 'table') . '` SET `state` = \'' . CONST_BILLING_INVOICESTATE_CANCELLED_REINVOICED . '\', `state_change` = \'' . time() . '\' WHERE `' . getModeDetails($this->mode, 'TABLE_BILLING_INVOICES', 'key') . '` = \'' . $this->userId . '\' AND ( `state` = \'' . CONST_BILLING_INVOICESTATE_CANCELLED_REINVOICE_WITHOUT_CREDIT_NOTE . '\' OR `state` = \'' . CONST_BILLING_INVOICESTATE_CANCELLED_REINVOICE_WITH_CREDIT_NOTE . '\' ) AND `id` IN ( ' . implode(', ', array_keys($this->cancelledInvoices)) . ' ) '); } foreach ($this->service_categories as $service_category => $service_category_details) { if (!class_exists($service_category_details['category_classname'])) { require_once './' . makeCorrectFile($service_category_details['category_classfile']); } if (class_exists($service_category_details['category_classname'])) { $subject = 0; $mode = $this->mode; $include_setup_fee = false; $include_interval_fee = false; if ($this->mode === 1 && intval($service_category_details['category_mode']) === 1) { if (isset($this->admin2customers[$this->userId])) { $subject = $this->admin2customers[$this->userId]; $mode = 0; // We have to set mode to customer because we are feeding an array of customer ids, so serviceCategory should also work in customer mode if (in_array($service_category_details['id'], $this->adminmode_include_once)) { $include_setup_fee = true; } if (in_array($service_category_details['id'], $this->adminmode_include_period)) { $include_interval_fee = true; } } } else { $subject = $this->userId; $include_setup_fee = true; $include_interval_fee = true; } if ($subject != 0) { $currentServiceCategory = new $service_category_details['category_classname'](&$this->db, $mode, $service_category_details['category_name']); $currentServiceCategory->fetchData($subject); $this->invoice = array_merge($this->invoice, $taxController->applyTaxRate($currentServiceCategory->collect($fixInvoice, $include_setup_fee, $include_interval_fee))); unset($currentServiceCategory); } } } return true; }