/**
  * Generate Invoice Batch
  *
  * Generate an Invoice for each billable account during the period set
  * in the form.
  */
 function generate_invoices()
 {
     $invoice_date = $this->post['date'];
     $terms = $this->post['terms'];
     $period_begin = $this->post['periodbegin'];
     $period_end = $this->post['periodend'];
     $note = $this->post['note'];
     // Get all accounts
     $accountdbo_array = load_array_AccountDBO();
     // Generate an invoice for each account
     foreach ($accountdbo_array as $account) {
         if ($account->getStatus() != "Active" || $account->getBillingStatus() == "Do Not Bill") {
             // Skip invalid, pending, and non-billable accounts
             continue;
         }
         // Create a new Invoice
         $invoice = new InvoiceDBO();
         $invoice->setAccountID($account->getID());
         $invoice->setDate(DBConnection::format_datetime($invoice_date));
         $invoice->setPeriodBegin(DBConnection::format_datetime($period_begin));
         $invoice->setPeriodEnd(DBConnection::format_datetime($period_end));
         $invoice->setNote($note);
         $invoice->setTerms($terms);
         // Generate line items
         $invoice->generate();
         $invoiceItems = $invoice->getItems();
         if (empty($invoiceItems)) {
             // Abandon empty invoices
             continue;
         }
         // Insert invoice into database
         add_InvoiceDBO($invoice);
     }
     // Success
     $this->setMessage(array("type" => "[INVOICE_BATCH_CREATED]"));
     $this->gotoPage("billing_invoices");
 }
예제 #2
0
 /**
  * Generate Invoice
  *
  * Creates a new Invoice and adds it to the database.
  */
 function generate_invoice()
 {
     // Determine the correct source of the account ID
     $account_id = isset($this->get['account']) ? $this->get['account']->getID() : $this->post['account']->getID();
     // Create a new invoice DBO
     $invoice = new InvoiceDBO();
     $invoice->setAccountID($account_id);
     $invoice->setDate(DBConnection::format_datetime($this->post['date']));
     $invoice->setPeriodBegin(DBConnection::format_datetime($this->post['periodbegin']));
     $invoice->setPeriodEnd(DBConnection::format_datetime($this->post['periodend']));
     $invoice->setNote($this->post['note']);
     $invoice->setTerms($this->post['terms']);
     // Generate lineitems
     $invoice->generate();
     // Insert invoice into database
     add_InvoiceDBO($invoice);
     // Success
     $this->setMessage(array("type" => "[INVOICE_CREATED]"));
     $this->gotoPage("billing_view_invoice", null, "invoice=" . $invoice->getID());
 }
예제 #3
0
/**
 * Load multiple InvoiceDBO's from database
 *
 * @param string $filter A WHERE clause
 * @param string $sortby Field name to sort results by
 * @param string $sortdir Direction to sort in (ASEC or DESC)
 * @param int $limit Limit the number of results
 * @param int $start Record number to start the results at
 * @return array Array of InvoiceDBO's
 */
function &load_array_InvoiceDBO($filter = null, $sortby = null, $sortdir = null, $limit = null, $start = null)
{
    $DB = DBConnection::getDBConnection();
    // Build query
    $sql = $DB->build_select_sql("invoice", "*", $filter, $sortby, $sortdir, $limit, $start);
    // Run query
    if (!($result = @mysql_query($sql, $DB->handle()))) {
        // Query error
        throw new DBException(mysql_error($DB->handle()));
    }
    if (mysql_num_rows($result) == 0) {
        // No services found
        throw new DBNoRowsFoundException();
    }
    // Build an array of DBOs from the result set
    $dbo_array = array();
    while ($data = mysql_fetch_array($result)) {
        // Create and initialize a new DBO with the data from the DB
        $dbo = new InvoiceDBO();
        $dbo->load($data);
        // Add HostingServiceDBO to array
        $dbo_array[] = $dbo;
    }
    return $dbo_array;
}