public static function execute($request = null) { if (empty($request['label'])) { return false; } App::uses('LilReport', 'Lil.Lib'); $report = new LilReport(Configure::read('LilCrm.label.' . $request['label'])); $report->helpers(array('Lil.Lil', 'Lil.LilDate', 'Lil.LilFloat', 'Html')); $report->template('LilCrm.' . $request['label']); $AdremasContact = ClassRegistry::init('LilCrm.AdremasContact'); $params = array('conditions' => array('AdremasContact.adrema_id' => empty($request['adrema']) ? null : $request['adrema'])); $addresses = $AdremasContact->find('all', $params); $i = 0; foreach ($addresses as $data) { $data['i'] = $i; $data += $request; $report->reset(); $report->set(compact('data')); $report->render(null); $i++; } $report->output('labels', 'I'); return true; }
public static function execute($type, $filter, $inline) { $Invoice = ClassRegistry::init('LilInvoices.Invoice'); App::uses('LilDateEngine', 'Lil.Lib'); $LilDate = LilDateEngine::getInstance(); $default_params = array('contain' => array('InvoicesItem', 'InvoicesCounter', 'InvoicesTax', 'Client' => array('PrimaryAddress', 'PrimaryAccount', 'PrimaryEmail'), 'InvoicesAttachment')); $ret = true; $params = array_merge_recursive($default_params, $Invoice->filter($filter)); if ($invoices = $Invoice->find('all', $params)) { switch ($type) { case 'pdf': App::uses('LilReport', 'Lil.Lib'); $report = new LilReport('Invoice'); $report->helpers(array('Lil.Lil', 'Lil.LilDate', 'Lil.LilFloat', 'Html')); App::uses('Sanitize', 'Utility'); // define filename if (sizeof($invoices) == 1) { $filename = Sanitize::paranoid(__d('lil_invoices', 'invoice') . '_' . $invoices[0]['Invoice']['no'], array('-', '_')); } else { $filename = Sanitize::paranoid(__d('lil_invoices', 'invoices') . '_' . $LilDate->toSql(null, true), array('_')); } $Vat = ClassRegistry::init('LilInvoices.Vat'); $vats = $Vat->findList(); $i = 1; foreach ($invoices as $data) { $report->template('LilInvoices.' . $data['InvoicesCounter']['layout'], 'LilInvoices.lil_invoices_pdf'); $report->reset(); $report->set(compact('data', 'vats')); $report->render(null); if ($i < sizeof($invoices)) { $report->addPage(); } $i++; } $report->output($filename, $inline ? 'I' : 'D'); break; case 'envelope': case 'eslog': case 'sepaxml': App::uses('LilCurrentUser', 'Lil.Lib'); $currentUser = LilCurrentUser::getInstance(); if (($company_id = $currentUser->get('company_id')) && ($Contact = ClassRegistry::init('LilCrm.Contact'))) { if (!($Company = $Contact->find('first', array('conditions' => array('Contact.id' => $company_id), 'contain' => array('PrimaryAccount', 'PrimaryAddress'))))) { $errors[] = __d('lil_invoices', 'Cannot fetch your employer!'); } } else { $errors[] = __d('lil_invoices', 'Please provide your employer!'); } $Vat = ClassRegistry::init('LilInvoices.Vat'); $vats = $Vat->findList(); $errors = array(); if (empty($Company['PrimaryAccount'])) { $errors[] = __d('lil_invoices', 'Please provide your default account!'); } if (empty($Company['PrimaryAddress'])) { $errors[] = __d('lil_invoices', 'Please provide your address!'); } if (empty($Company['Contact']['tax_no'])) { $errors[] = __d('lil_invoices', 'Please provide your tax no!'); } foreach ($invoices as $data) { if ($type == 'sepaxml' && empty($data['Client']['PrimaryAccount'])) { $errors[] = __d('lil_invoices', 'Please provide client\'s "%s" default account!', $data['Client']['title']); } if (empty($data['Client']['PrimaryAddress'])) { $errors[] = __d('lil_invoices', 'Please provide client\'s "%s" default address!', $data['Client']['title']); } if ($data['Client']['kind'] == 'C' && empty($data['Client']['tax_no'])) { $errors[] = __d('lil_invoices', 'Please provide client\'s "%s" tax no!', $data['Client']['title']); } if ($type == 'sepaxml' && (empty($data['Invoice']['pmt_type']) || empty($data['Invoice']['pmt_module']) || empty($data['Invoice']['pmt_ref']))) { $errors[] = __d('lil_invoices', 'Please provide payment details for invoice "%1$s - %2$s"', $data['Invoice']['no'], $data['Invoice']['title']); } } if (empty($errors)) { $View = new View(null); $View->viewPath = 'Invoices'; $View->plugin = 'LilInvoices'; $View->helpers = array('Session', 'Html'); $View->set('invoices', $invoices); $View->set('Company', $Company); $View->set('vats', $vats); switch ($type) { case 'eslog': $template = 'admin_export_eslog'; break; case 'envelope': $template = 'admin_export_envelope'; break; default: $template = 'admin_export_sepaxml'; } echo $View->render($template, 'xml'); } else { $ret = __d('lil_invoices', 'EXPORT ERROR(s):') . '<br />' . implode('<br />', $errors); } break; } } else { return __d('lil_invoices', 'Export error: No invoices found.'); } return $ret; }