/** * printInvoice: similar in consturction to other FOP print functions, however * this is more restrictive, at the time only used as part of save_confirmsale * * @param DataObject $invoice * @param array $data */ protected function printInvoice($invoice, $data) { $options = array('filename' => 'SalesInvoice' . $invoice->id, 'report' => 'SalesInvoice'); // prepare the extra array $extra = array(); $tax_status = DataObjectFactory::Factory('TaxStatus'); $tax_status->load($invoice->tax_status_id); // get the company address $company_address = array('name' => $this->getCompanyName()); $company_address += $this->formatAddress($this->getCompanyAddress()); $extra['company_address'] = $company_address; // get the company details $extra['company_details'] = $this->getCompanyDetails(); // get the invoice address $invoice_address = array(); $invoice_address['name'] = $invoice->customer; if (!is_null($invoice->person_id)) { $invoice_address['person'] = $invoice->person; } $invoice_address += (array) $this->formatAddress($invoice->getInvoiceAddress()); $extra['invoice_address'] = $invoice_address; $extra['tax_description'] = $invoice->customerdetail->companydetail->tax_description; $extra['vatnumber'] = $invoice->customerdetail->companydetail->vatnumber; // get Sales Invoice Notes for default customer or first in customer $note = DataObjectFactory::Factory('PartyNote'); $party_id = $invoice->customerdetail->companydetail->party_id; $cc = new ConstraintChain(); $note->orderby = 'lastupdated'; $note->orderdir = 'DESC'; $cc->add(new Constraint('note_type', '=', 'sales_invoicing')); $cc->add(new Constraint('party_id', '=', $party_id)); $latest_note = $note->loadBy($cc); $extra['notes'] = $latest_note->note; // get the delivery address $delivery_address = $invoice->customer . ", " . $invoice->getDeliveryAddress()->fulladdress; $extra['delivery_address'] = $delivery_address; // get the settlement terms if ($invoice->transaction_type == 'I') { $settlement_terms = $invoice->getSettlementTerms(); $extra['settlement_terms'] = $settlement_terms; $bank_account = $invoice->customerdetail->bank_account_detail; if (!is_null($bank_account->bank_account_number)) { $extra['bank_account']['bank_name'] = $bank_account->bank_name; $extra['bank_account']['bank_sort_code'] = $bank_account->bank_sort_code; $extra['bank_account']['bank_account_number'] = $bank_account->bank_account_number; $extra['bank_account']['bank_address'] = $bank_account->bank_address; $extra['bank_account']['bank_iban_number'] = $bank_account->bank_iban_number; $extra['bank_account']['bank_bic_code'] = $bank_account->bank_bic_code; } } // get invoice totals $invoice_totals = array(); $invoice_totals[]['line'][] = array('field1' => 'NET VALUE', 'field2' => $invoice->net_value . ' ' . $invoice->currency); $invoice_totals[]['line'][] = array('field1' => 'VAT', 'field2' => $invoice->tax_value . ' ' . $invoice->currency); $invoice_totals[]['line'][] = array('field1' => strtoupper($invoice->getFormatted('transaction_type')) . ' TOTAL', 'field2' => $invoice->gross_value . ' ' . $invoice->currency); $extra['invoice_totals'] = $invoice_totals; // get invoice vat analysis if ($tax_status->eu_tax == 't' && $tax_status->apply_tax == 'f') { $extra['vat_analysis_exempt'][]['line'] = 'Zero rated intra-EU supply'; $extra['vat_analysis_exempt'][]['line'] = 'Not subject to UK VAT under Article 56 Directive 2006/112/EC'; } else { $vat_analysis = $invoice->vatAnalysis(); foreach ($vat_analysis as $key => $value) { $extra['vat_analysis'][]['line'][] = $value; } } // generate the XML, include the extras array too $options['xmlSource'] = $this->generateXML(array('model' => $invoice, 'relationship_whitelist' => array('lines'), 'extra' => $extra)); // construct the document, capture the response return $this->constructOutput($data, $options); }