Ejemplo n.º 1
0
 /**
  * This method is a wrapper for parent::collect. Before launching it,
  * we will gather information about traffic usage for all given userids.
  *
  * @param bool   Should we fix invoice (means we call self::setLastInvoiced to latest invoiced date).
  * @param bool   Should we include the setup fee?
  * @param bool   Should we include the interval fees?
  * @return array All invoice rows
  *
  * @author Former03 GmbH :: Florian Lippert <*****@*****.**>
  */
 function collect($fixInvoice = false, $include_setup_fee = false, $include_interval_fee = false)
 {
     $traffic_result = $this->db->query('SELECT `' . getModeDetails($this->mode, 'TABLE_PANEL_TRAFFIC', 'key') . '`, `year`, `month`, `day`, SUM(`http`+`ftp_down`+`ftp_up`+`mail`) as traffic FROM `' . getModeDetails($this->mode, 'TABLE_PANEL_TRAFFIC', 'table') . '` WHERE `' . getModeDetails($this->mode, 'TABLE_PANEL_TRAFFIC', 'key') . '` IN ( ' . implode(', ', $this->userIds) . ' ) GROUP BY `' . getModeDetails($this->mode, 'TABLE_PANEL_TRAFFIC', 'key') . '`, `year`, `month`, `day`');
     while ($traffic_row = $this->db->fetch_array($traffic_result)) {
         if (!isset($this->traffic_data[$traffic_row[getModeDetails($this->mode, 'TABLE_PANEL_TRAFFIC', 'key')]]) || !is_array($this->traffic_data[$traffic_row[getModeDetails($this->mode, 'TABLE_PANEL_TRAFFIC', 'key')]])) {
             $this->traffic_data[$traffic_row[getModeDetails($this->mode, 'TABLE_PANEL_TRAFFIC', 'key')]] = array();
         }
         $date = $traffic_row['year'] . '-' . $traffic_row['month'] . '-' . $traffic_row['day'];
         if (!isset($this->traffic_data[$traffic_row[getModeDetails($this->mode, 'TABLE_PANEL_TRAFFIC', 'key')]][$date]) && checkDateArray(transferDateToArray($date))) {
             $this->traffic_data[$traffic_row[getModeDetails($this->mode, 'TABLE_PANEL_TRAFFIC', 'key')]][$date] = (int) $traffic_row['traffic'];
         }
     }
     reset($this->userIds);
     foreach ($this->userIds as $userId) {
         // Using fixed values here, because those settings are always the same. interval_fee will be calculated lateron, when traffic consumption is calculated
         $this->service_details[$userId]['service_active'] = '1';
         $this->service_details[$userId]['interval_fee'] = '0.00';
         $this->service_details[$userId]['interval_length'] = '1';
         $this->service_details[$userId]['interval_type'] = 'm';
         $this->service_details[$userId]['interval_payment'] = '1';
         // Always postpaid, we can't invoice this month/payment_term's traffic, if it hasn't finished yet
         $this->service_details[$userId]['setup_fee'] = '0.00';
         $this->service_details[$userId]['payment_every'] = '1';
         $this->service_details[$userId]['lastinvoiced_date'] = $this->service_details[$userId]['lastinvoiced_date_traffic'];
         // We still want to be able to calculate traffic usage in case of no service information
         if (($this->service_details[$userId]['lastinvoiced_date'] == '0' || $this->service_details[$userId]['lastinvoiced_date'] == '') && ($this->service_details[$userId]['servicestart_date'] == '0' || $this->service_details[$userId]['servicestart_date'] == '') && isset($this->traffic_data[$userId]) && is_array($this->traffic_data[$userId]) && !empty($this->traffic_data[$userId])) {
             // Get the date of first appereance of traffic
             ksort($this->traffic_data[$userId]);
             $dates = array_keys($this->traffic_data[$userId]);
             $this->service_details[$userId]['servicestart_date'] = $dates[0];
         }
     }
     return parent::collect($fixInvoice, $include_setup_fee, $include_interval_fee);
 }
Ejemplo n.º 2
0
 /**
  * We first fill self::included_domains. Then we check for every domain of that user,
  * if it is literally mentioned in the list of included domains. Lastly we again walk
  * through the list of domains and test with self::_checkIncludedDomain if it is an
  * included domain. Afterwards parent::collect is called.
  *
  * @param bool   Should we fix invoice (means we call self::setLastInvoiced to latest invoiced date).
  * @param bool   Should we include the setup fee?
  * @param bool   Should we include the interval fees?
  * @return array All invoice rows
  *
  * @author Former03 GmbH :: Florian Lippert <*****@*****.**>
  */
 function collect($fixInvoice = false, $include_setup_fee = false, $include_interval_fee = false)
 {
     $this->idna = new idna_convert_wrapper();
     $included_domains_result = $this->db->query('SELECT `customerid`, `included_domains_qty`, `included_domains_tld` FROM `' . TABLE_PANEL_CUSTOMERS . '` WHERE `customerid` IN ( ' . implode(', ', $this->userIds) . ' ) ');
     while ($included_domains_row = $this->db->fetch_array($included_domains_result)) {
         $this->included_domains[$included_domains_row['customerid']] = $included_domains_row;
         unset($this->included_domains[$included_domains_row['customerid']]['customerid']);
     }
     // Get all domains owned by the customer (which have already been started) to verify if they are included domains
     $check_domains = array();
     $check_domains_result = $this->db->query('SELECT `customerid`, `domain` FROM `' . TABLE_PANEL_DOMAINS . '` WHERE `customerid` IN ( ' . implode(', ', $this->userIds) . ' ) AND `servicestart_date` != \'0000-00-00\' ORDER BY `add_date` ASC ');
     while ($check_domains_row = $this->db->fetch_array($check_domains_result)) {
         if (!isset($check_domains[$check_domains_row['customerid']])) {
             $check_domains[$check_domains_row['customerid']] = array();
         }
         $check_domains[$check_domains_row['customerid']][] = $check_domains_row['domain'];
     }
     foreach ($this->included_domains as $customerid => $included_domains) {
         $included_domains_tld = explode(' ', $included_domains['included_domains_tld']);
         $included_domains_tld_length = array();
         foreach ($included_domains_tld as $included_domain_tld) {
             $number_parts = count(explode('.', $included_domain_tld));
             if (!isset($included_domains_tld_length[$number_parts]) || !is_array($included_domains_tld_length[$number_parts])) {
                 $included_domains_tld_length[$number_parts] = array();
             }
             $included_domains_tld_length[$number_parts][] = $included_domain_tld;
         }
         krsort($included_domains_tld_length);
         $this->included_domains[$customerid]['included_domains_tld'] = '';
         foreach ($included_domains_tld_length as $included_domains_tld) {
             if ($this->included_domains[$customerid]['included_domains_tld'] != '') {
                 $this->included_domains[$customerid]['included_domains_tld'] .= ' ';
             }
             $this->included_domains[$customerid]['included_domains_tld'] .= implode(' ', $included_domains_tld);
         }
         $included_domains_tld = explode(' ', $this->included_domains[$customerid]['included_domains_tld']);
         if (isset($check_domains[$customerid]) && is_array($check_domains[$customerid])) {
             reset($check_domains[$customerid]);
             foreach ($check_domains[$customerid] as $check_domain) {
                 if (in_array($check_domain, $included_domains_tld)) {
                     $this->_checkIncludedDomain($check_domain, $customerid);
                 }
             }
             // Now cycle through the list of domains and check them
             reset($check_domains[$customerid]);
             foreach ($check_domains[$customerid] as $check_domain) {
                 $this->_checkIncludedDomain($check_domain, $customerid);
             }
         }
     }
     return parent::collect($fixInvoice, $include_setup_fee, $include_interval_fee);
 }