/**
  * Get Data
  *
  * @param array $config Field configuration
  * @return array value => description
  */
 function getData()
 {
     $accounts = array();
     // Query AccountDBO's
     try {
         $accountDBOs = load_array_AccountDBO();
         // Convery to an array: account ID => account name
         foreach ($accountDBOs as $accountDBO) {
             $accounts[$accountDBO->getID()] = $accountDBO->getAccountName();
         }
     } catch (DBNoRowsFoundException $e) {
     }
     return $accounts;
 }
 /**
  * Initialize the Table
  *
  * @param array $params Parameters from the {form_table} tag
  */
 public function init($params)
 {
     parent::init($params);
     // Build an account filter
     $where = isset($this->statusFilter) ? sprintf("status='%s'", $this->statusFilter) : null;
     // Load the Account Table
     try {
         $accounts = load_array_AccountDBO($where);
         // Build the table
         foreach ($accounts as $dbo) {
             // Put the row into the table
             $this->data[] = array("id" => $dbo->getID(), "accountname" => $dbo->getAccountName(), "type" => $dbo->getType(), "status" => $dbo->getStatus(), "balance" => $dbo->getBalance(), "billingstatus" => $dbo->getBillingStatus(), "billingday" => $dbo->getBillingDay(), "businessname" => $dbo->getBusinessName(), "contactname" => $dbo->getContactName(), "contactemail" => $dbo->getContactEmail());
         }
     } catch (DBNoRowsFoundException $e) {
     }
 }
 /**
  * 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");
 }