/** * 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; }