/**
  * 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);
 }
 /**
  * Initializes the Page
  *
  * If an invoice ID appears in the URL, then init() attempts to load that Invoice,
  * otherwise, it uses an invoice already in the session.
  */
 function init()
 {
     parent::init();
     // Set URL Field values
     $this->setURLField("invoice", $this->get['invoice']->getID());
     // Set this page's Nav Vars
     $this->setNavVar("invoice_id", $this->get['invoice']->getID());
     // Retrieve the Account DBO for this invoice
     $account_dbo = $this->get['invoice']->getAccountDBO();
     // Replace tokens in subject field
     $subject = $this->conf['invoice_subject'];
     $subject = str_replace("{company_name}", $this->conf['company']['name'], $subject);
     $subject = str_replace("{period_begin_date}", date("m/d/y", DBConnection::datetime_to_unix($this->get['invoice']->getPeriodBegin())), $subject);
     $subject = str_replace("{period_end_date}", date("m/d/y", DBConnection::datetime_to_unix($this->get['invoice']->getPeriodEnd())), $subject);
     $this->smarty->assign("email", $account_dbo->getContactEmail());
     $this->smarty->assign("subject", $subject);
     $this->smarty->assign("body", $this->get['invoice']->text($this->conf['invoice_text']));
 }
 /**
  * Get Description for "Recurring" Line Item
  *
  * @return string The text that should appear on the invoice for this purchase
  */
 public function getLineItemTextRecurring()
 {
     $term = intval($this->getTerm() / 12);
     return sprintf("%s ([TERM]: %d %s, [EXPIRES] %s)", $this->getTitle(), $term, $term > 1 ? "[YEARS]" : "[YEAR]", date("m/d/y", DBConnection::datetime_to_unix($this->getExpireDate())));
 }
/**
 * Smarty Date/Time Modifier
 *
 * Convert a MySQL DATETIME to a more presentable format
 *
 * @param string $value MySQL DATETIME
 * @param string $show_part Show only the specified part of the date/time ("date or "time")
 * @return string Formated Date / Time
 */
function smarty_modifier_datetime($value, $show_part = null)
{
    // Convert datetime to a unix time stamp
    $time = DBConnection::datetime_to_unix($value);
    // Return a formated date, e.g. 12/11/2005, 11:39:00am
    // (or just one part, date/time)
    switch ($show_part) {
        case "date":
            return date('m/d/Y', $time);
            break;
        case "time":
            return date('h:i:s a', $time);
            break;
        default:
            return date('m/d/Y, h:i:s a', $time);
    }
}
 /**
  * Formatted Invoice Text
  *
  * Using the supplied template, this function generates text for the invoice.
  *
  * @param string $email_text Format string
  *
  * @return string Invoice text
  */
 function text($email_text)
 {
     global $conf;
     // Generate Invoice & E-mail text
     $email_text = str_replace("{invoice_id}", $this->getID(), $email_text);
     $invoiceDate = DBConnection::datetime_to_unix($this->getDate());
     $email_text = str_replace("{invoice_date}", date("F j, Y", $invoiceDate), $email_text);
     $email_text = str_replace("{invoice_subtotal}", sprintf("%s%01.2f", $conf['locale']['currency_symbol'], $this->getSubTotal()), $email_text);
     $email_text = str_replace("{invoice_taxtotal}", sprintf("%s%01.2f", $conf['locale']['currency_symbol'], $this->getTaxTotal()), $email_text);
     $email_text = str_replace("{invoice_total}", sprintf("%s%01.2f", $conf['locale']['currency_symbol'], $this->getTotal()), $email_text);
     $email_text = str_replace("{invoice_payments}", sprintf("%s%01.2f", $conf['locale']['currency_symbol'], $this->getTotalPayments()), $email_text);
     $email_text = str_replace("{invoice_balance}", sprintf("%s%.2f", $conf['locale']['currency_symbol'], $this->getBalance()), $email_text);
     $email_text = str_replace("{outstanding_balance}", sprintf("%s%.2f", $conf['locale']['currency_symbol'], $this->getOutstandingBalance()), $email_text);
     $due_date = date("F j, Y", $this->getDueDate());
     $email_text = str_replace("{invoice_due}", $due_date, $email_text);
     // Generate invoice line items
     $line_items = "";
     if (($item_dbo_array = $this->getItems()) != null) {
         foreach ($item_dbo_array as $item_dbo) {
             $line_items .= sprintf("%-40s%s%6.2f %3d    %s%6.2f\n", $item_dbo->getText(), $conf['locale']['currency_symbol'], $item_dbo->getUnitAmount(), $item_dbo->getQuantity(), $conf['locale']['currency_symbol'], $item_dbo->getAmount());
         }
     }
     $email_text = str_replace("{invoice_items}", $line_items, $email_text);
     return $email_text;
 }