Esempio n. 1
0
 /**
  * Determine Widget Value
  *
  * Determines the correct source to use for the value of this widget and
  * format that value as such: MM-DD-YYYY or DD-MM-YYYY
  * The order goes like this:
  *   5. No value
  *   4. The default value set in the config file
  *   3. The value given by the 'value' parameter of the {form_field} tag
  *   2. The value of this field in the specified DBO
  *   1. The value as entered by the user
  *
  * @param array $params Paramets passed from the template
  * @throws SWException
  * @return string The value to use
  */
 protected function determineValue($params)
 {
     $value = parent::determineValue($params);
     if (is_string($value)) {
         $tsValue = strlen($value) > 10 ? DBConnection::datetime_to_unix($value) : DBConnection::date_to_unix($value);
     } else {
         $tsValue = $value;
     }
     return $this->TS2Date($tsValue == null ? time() : $tsValue);
 }
Esempio n. 2
0
 /**
  * Generate Invoice
  *
  * Given an Account to generate the invoice for and a period for which to bill,
  * this function will search out any purchases that occured during that period
  * and add an InvoiceItem to the Invoice for each purchase.
  *
  * @return boolean True on success
  */
 public function generate()
 {
     if (!($this->getAccountID() || $this->getPeriodBegin() || $this->getPeriodEnd())) {
         throw new SWException("Missing necessary information to generate this invoice");
     }
     $periodBeginTS = DBConnection::datetime_to_unix($this->getPeriodBegin());
     $periodEndTS = DBConnection::datetime_to_unix($this->getPeriodEnd());
     // Bill all applicable purchases for the account
     foreach ($this->accountDBO->getPurchases() as $purchaseDBO) {
         $taxes = 0;
         // Bill onetime price if necessary
         if ($purchaseDBO->getPrevInvoiceID() == 0 && $purchaseDBO->getOnetimePrice() > 0) {
             $taxes += $purchaseDBO->getOnetimeTaxes();
             $this->add_item(1, $purchaseDBO->getOnetimePrice(), $purchaseDBO->getLineItemTextOneTime(), false);
         }
         // Bill the purchase as many times as necessary during the period
         $nextBillingDateTS = DBConnection::date_to_unix($purchaseDBO->getNextBillingDate());
         $recurCount = 0;
         while ($nextBillingDateTS >= $periodBeginTS && $nextBillingDateTS < $periodEndTS) {
             // Calculate the "new next" billing date for this purchase
             if ($purchaseDBO->getTerm() == 0) {
                 // Do not bill again
                 $nextBillingDateTS = null;
                 $purchaseDBO->setNextBillingDate(null);
             } else {
                 // Increment the recurring count
                 $recurCount++;
                 // Increment the next billing date by term
                 $nextBillingDateTS = DBConnection::date_to_unix($purchaseDBO->incrementNextBillingDate());
             }
             // The -1 will be replaced by the invoice ID in add_InvoiceDBO
             $purchaseDBO->setPrevInvoiceID(-1);
             // Add this purchase to the list of purchase DBO's to update when
             // the invoice is added to the database
             $this->updatePurchases[] = $purchaseDBO;
         }
         // Bill the recurring price (if exists)
         if ($recurCount > 0 && $purchaseDBO->getRecurringPrice() > 0) {
             $taxes += $purchaseDBO->getRecurringTaxes() * $recurCount;
             $this->add_item($recurCount, $purchaseDBO->getRecurringPrice(), $purchaseDBO->getLineItemTextRecurring(), false);
         }
         // Charge taxes
         if ($taxes > 0) {
             $this->add_item(1, $taxes, $purchaseDBO->getLineItemTextTax(), true);
         }
     }
     // Done
     return true;
 }
Esempio n. 3
0
 /**
  * Increment Next Billing Date
  */
 public function incrementNextBillingDate()
 {
     $nextBillingDateTS = DBConnection::date_to_unix($this->getNextBillingDate());
     $oldBillingDate = getdate($nextBillingDateTS);
     $nextBillingDate = DBConnection::format_date(mktime(0, 0, 1, $oldBillingDate['mon'] + $this->getTerm(), $oldBillingDate['mday'], $oldBillingDate['year']));
     $this->setNextBillingDate($nextBillingDate);
     return $nextBillingDate;
 }