public function executeNew(sfWebRequest $request) { $i18n = $this->getContext()->getI18N(); $invoice = new Invoice(); $invoice->fromArray(array('customer_name' => $i18n->__('Client Name'), 'customer_identification' => $i18n->__('Client Legal Id'), 'contact_person' => $i18n->__('Contact Person'), 'invoicing_address' => $i18n->__('Invoicing Address'), 'shipping_address' => $i18n->__('Shipping Address'), 'customer_email' => $i18n->__('Client Email Address'))); $this->invoiceForm = new InvoiceForm($invoice, array('culture' => $this->culture)); $this->title = $i18n->__('New Invoice'); $this->action = 'create'; $this->setTemplate('edit'); }
/** * Generates and saves an invoice based on this recurring * * @return Invoice **/ public function generateInvoice() { $i = new Invoice(); // Get Invoice column mapping and intersect with Recurring one // to remove non common columns. Unset id and type columns. $iKeys = array_flip(array_keys($i->getTable()->getColumns())); $data = $this->toArray(false); unset($data['id'], $data['type'], $data['must_occurrences'], $data['created_at'], $data['last_execution_date'], $data['occurrences']); $data = array_intersect_key($data, $iKeys); // Add specific fields for Invoice and hydrate. $data = array_merge($data, array('recurring_invoice_id' => $this->getId(), 'issue_date' => sfDate::getInstance()->format('Y-m-d'), 'due_date' => sfDate::getInstance()->addDay($this->getDaysToDue())->format('Y-m-d'), 'draft' => false)); $i->fromArray($data); // Copy Items and taxes foreach ($this->Items as $item) { $iTmp = $item->copy(false); foreach ($item->Taxes as $tax) { $iTmp->Taxes[] = $tax; } $i->Items[] = $iTmp; } // copy tags foreach ($this->getTags() as $tag) { $i->addTag($tag); } if ($i->trySave()) { $this->setLastExecutionDate(sfDate::getInstance()->format('Y-m-d')); $this->save(); } return $i; }
<?php include dirname(__FILE__) . '/../../bootstrap/functional.php'; include dirname(__FILE__) . '/../../testTools.php'; $browser = new SiwappTestBrowser(); $browser->signin()->info('Test the send email action')->post('/invoices/batch', array('ids' => array(23, 21), 'batch_action' => 'email'))->with('mailer')->begin()->hasSent(2)->checkHeader('Subject', '/Invoicer LTD \\[Invoice: ASET-8\\]/')->checkBody('/\\.*Invoicer LTD/')->end()->with('response')->begin()->isRedirected()->end()->followRedirect()->with('request')->begin()->isParameter('module', 'invoices')->isParameter('action', 'index')->end(); // create to fake invoices to delete them $inv1 = new Invoice(); $inv2 = new Invoice(); $inv1->fromArray($fake_invoice_array); $inv2->fromArray($fake_invoice_array); $inv1->save(); $inv2->save(); $browser->info('Test the batch delete action')->post('/invoices/batch', array('ids' => array($inv1->id, $inv2->id), 'batch_action' => 'delete'))->with('response')->begin()->isRedirected()->end()->followRedirect()->with('doctrine')->begin()->check('Invoice', array('id' => $inv1->id), false)->check('Invoice', array('id' => $inv2->id), false)->end();
public function generateInvoice() { $invoice = new Invoice(); // Get Invoice column mapping and intersect with Estimate columns // to remove non common columns. Unset id and type columns. $iKeys = array_flip(array_keys($invoice->getTable()->getColumns())); $data = $this->toArray(false); unset($data['id'], $data['type'], $data['created_at'], $data['updated_at'], $data['draft'], $data['number'], $data['sent_by_email']); $data = array_intersect_key($data, $iKeys); $invoice->fromArray($data); // $invoice->setDraft(true); $invoice->setIssueDate(sfDate::getInstance()->format('Y-m-d')); $invoice->setDueDate(sfDate::getInstance()->addMonth()->format('Y-m-d')); // Copy Items and taxes foreach ($this->Items as $item) { $iTmp = $item->copy(false); foreach ($item->Taxes as $tax) { $iTmp->Taxes[] = $tax; } $invoice->Items[] = $iTmp; } // copy tags foreach ($this->getTags() as $tag) { $invoice->addTag($tag); } if ($invoice->trySave()) { $invoice->refresh(true)->setAmounts()->save(); return $invoice; } return false; }