/** * Initialize the Table * * @param array $params Parameters from the {form_table} tag */ public function init($params) { parent::init($params); // Build an invoice filter $where = isset($this->outstandingFilter) ? sprintf("outstanding='%s' ", $this->outstandingFilter) : null; $where .= isset($this->accountID) ? sprintf("accountid='%d' ", $this->accountID) : null; // If a prior-to invoice is given, just go with this clause: $where = isset($this->priorToInvoice) ? sprintf("id <> %d AND accountid=%d AND outstanding='%s' AND `date` < '%s'", $this->priorToInvoice->getID(), $this->priorToInvoice->getAccountID(), "yes", $this->priorToInvoice->getPeriodBegin()) : $where; // Load the Invoice Table try { // Build the table $invoices = load_array_InvoiceDBO($where); foreach ($invoices as $dbo) { // Put the row into the table $this->data[] = array("id" => $dbo->getID(), "accountid" => $dbo->getAccountID(), "accountname" => $dbo->getAccountName(), "date" => $dbo->getDate(), "periodbegin" => $dbo->getPeriodBegin(), "periodend" => $dbo->getPeriodEnd(), "note" => $dbo->getNote(), "terms" => $dbo->getTerms(), "outstanding" => $dbo->getOutstanding(), "total" => $dbo->getTotal(), "totalpayments", $dbo->getTotalPayments(), "balance" => $dbo->getBalance()); } } catch (DBNoRowsFoundException $e) { } }
/** * Outstanding Invoices Stats * * Gather stats for outstanding invoices * * @return array Outstanding Invoices stats */ function outstanding_invoices_stats() { // Count the outstanding invoices $count = 0; // Total the balance on all outstanding invoices $total_balance = 0.0; // Count the number of past-due invoices $count_past_due = 0; // ... and total $total_balance_past_due = 0.0; // Count the number of 30+ day past-due invoices $count_past_due_30 = 0; // ... and total $total_balance_past_due_30 = 0.0; // Iterate through all the invoices try { $invoicedbo_array = load_array_InvoiceDBO(); foreach ($invoicedbo_array as $invoice) { if (($invoice_balance = $invoice->getBalance()) >= 0.01) { // Invoice has not been paid in full, $count++; $total_balance += $invoice_balance; if (time() > $invoice->getDueDate()) { // Invoice is past due $count_past_due++; $total_balance_past_due += $invoice_balance; } if (time() > $invoice->getDueDate() + 30 * 24 * 60 * 60) { // Invoice is more than 30 days past due $count_past_due_30++; $total_balance_past_due_30 += $invoice_balance; } } } } catch (DBNoRowsFoundException $e) { } // Stuff array with stats and return return array("count" => $count, "total" => $total_balance, "count_past_due" => $count_past_due, "total_past_due" => $total_balance_past_due, "count_past_due_30" => $count_past_due_30, "total_past_due_30" => $total_balance_past_due_30); }
/** * Get Data * * @param array $config Field configuration * @return array value => description */ public function getData() { // Check if there is a specific account ID to show invoices for $where = null; if ($this->accountid != null) { $where = "accountid=" . $this->accountID . " "; } // Check if we should only show outstanding invoices if ($this->filterOutstanding) { $where .= "outstanding='yes' "; } // Query InvoiceDBO's $invoices = array(); try { $invoiceDBOs = load_array_InvoiceDBO($where); foreach ($invoiceDBOs as $invoiceDBO) { $invoices[$invoiceDBO->getID()] = $invoiceDBO->getDescription(); } } catch (DBNoRowsFoundException $e) { } return $invoices; }
/** * Get Outstanding Invoices * * Returns an array of all outstanding invoices with a creation date before * the beginning of this invoice period. * * @return array An array of InvoiceDBO's */ function getOutstandingInvoices() { $where = sprintf("id <> %d AND accountid=%d AND outstanding='%s' AND `date` < '%s'", $this->getID(), $this->getAccountID(), "yes", $this->getPeriodBegin()); try { return load_array_InvoiceDBO($where); } catch (DBNoRowsFoundException $e) { return array(); } }
/** * Get Account Balance * * @return double Account balance */ function getBalance() { // Sum up invoice balances $balance = 0; try { $invoices = load_array_InvoiceDBO("accountid=" . $this->getID()); foreach ($invoices as $invoice_dbo) { $balance += $invoice_dbo->getBalance(); } } catch (DBNoRowsFoundException $e) { } return $balance; }