public static function create($conn = null, $class = null) { $q = new InvoiceQuery($conn); $q->from('Invoice i')->orderBy('i.issue_date desc, i.number desc'); $q->_model = 'Invoice'; return $q; }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $namespace = $request->getParameter('searchNamespace'); $search = $this->getUser()->getAttribute('search', null, $namespace); $this->maxResults = sfConfig::get('app_dashboard_max_results'); $q = InvoiceQuery::create()->search($search)->limit($this->maxResults); // for the overdue unset the date filters, to show all the overdue unset($search['from'], $search['to']); $overdueQuery = InvoiceQuery::create()->search($search)->status(Invoice::OVERDUE); // totals $this->gross = $q->total('gross_amount'); $this->due = $q->total('due_amount'); $this->paid = $q->total('paid_amount'); $this->odue = $overdueQuery->total('due_amount'); $this->taxes = $q->total('tax_amount'); $this->net = $q->total('net_amount'); $taxes = Doctrine_Query::create()->select('t.id, t.name')->from('Tax t')->execute(); $total_taxes = array(); foreach ($taxes as $t) { if ($value = $q->total_tax($t->id)) { $total_taxes[$t->name] = $q->total_tax($t->id); } } $this->total_taxes = $total_taxes; // this is for the redirect of the payments forms $this->getUser()->setAttribute('module', $request->getParameter('module')); // link counters $this->recentCounter = $q->count(); $this->overdueCounter = $overdueQuery->count(); // recent & overdue invoices $this->recent = $q->execute(); $this->overdue = $overdueQuery->execute(); }
public function view() { $invoiceId = $this->request_stack["arguments"][0]; $invoice = InvoiceQuery::create()->findOneById($invoiceId); $bills = $invoice->getBillsJoinTask(); $customer = $invoice->getCustomer(); $this->assign("invoice", $invoice->toArray()); $this->assign("bills", $bills->toArray()); $this->assign("customer", $customer->toArray()); $this->assign("person", $customer->getPerson()->toArray()); $this->build("view"); }
/** * calculate the totals for all invoices (recurring included) if $all is true * or for opened and overdue invoices otherwise * * @return void **/ public static function calculateTotals($all = false) { if ($all) { $invoices = Doctrine::getTable('Common')->findAll(); } else { $invoices = InvoiceQuery::create()->status(array(Invoice::OPENED, Invoice::OVERDUE))->execute(); $recurrings = RecurringInvoiceQuery::create()->execute(); foreach ($recurrings as $r) { $r->refresh(true); $r->setAmounts()->save(); unset($r); } } foreach ($invoices as $invoice) { $invoice->refresh(true); $invoice->setAmounts()->save(); unset($invoice); } }
/** * Export search results as CSV * * - Date * - Invoice Number * - Customer * - VAT ID * - Net Amount (before VAT) * - VAT % * - VAT Amount * - Gross Amount (after VAT) * - Customer Address */ public function executeExportSearchResults(sfWebRequest $request) { $this->getContext()->getConfiguration()->loadHelpers('Date'); $this->getContext()->getConfiguration()->loadHelpers('Number'); $decimals = Tools::getDecimals(); $namespace = $request->getParameter('searchNamespace'); $search = $this->getUser()->getAttribute('search', null, $namespace); $sort = $this->getUser()->getAttribute('sort', array('issue_date', 'desc'), $namespace); $q = InvoiceQuery::create()->search($search)->orderBy("{$sort['0']} {$sort['1']}, number {$sort['1']}"); $this->getResponse()->clearHttpHeaders(); $this->getResponse()->setHttpHeader('Content-Description', 'File Transfer'); $this->getResponse()->setHttpHeader('Content-Type', 'text/csv'); $this->getResponse()->setHttpHeader('Content-Disposition', 'attachment;filename=' . date('YmdHis') . '_invoices.csv'); $this->getResponse()->setHttpHeader('Pragma', 'public'); $this->getResponse()->setHttpHeader('Expires', '0'); $this->getResponse()->setHttpHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0'); $this->getResponse()->sendHttpHeaders(); $fh = fopen('php://output', 'w'); // Output the header fputcsv($fh, array('date', 'invoice number', 'customer name', 'vat id', 'net amount', 'vat', 'vat amount', 'gross amount', 'customer address', 'notes')); foreach ($q->execute() as $invoice) { fputcsv($fh, array(format_date($invoice->getIssueDate()), $invoice->__toString(), $invoice->getCustomerName(), $invoice->getCustomerIdentification(), format_number(Tools::getRounded($invoice->getNetAmount(), $decimals), $this->getUser()->getCulture()), implode(', ', $invoice->getAppliedTaxes()), format_number(Tools::getRounded($invoice->getTaxAmount(), $decimals), $this->getUser()->getCulture()), format_number(Tools::getRounded($invoice->getGrossAmount(), $decimals), $this->getUser()->getCulture()), str_replace(array("\n", "\r"), " - ", $invoice->getInvoicingAddress()), str_replace(array("\n", "\r"), " ", $invoice->getNotes()))); } fclose($fh); return sfView::NONE; }
public function getNonDraftInvoices($customer_id, $date_range = array()) { $search = array_merge(array('customer_id' => $customer_id), $date_range); $q = InvoiceQuery::create()->search($search)->andWhere('i.draft = 0'); return $q->execute(); }