public function eventPdf($eventId = null) { if (isset($eventId)) { $invs = TableRegistry::get('Invoices'); $atts = TableRegistry::get('Attendees'); $itms = TableRegistry::get('InvoiceItems'); $evts = TableRegistry::get('Events'); $event = $evts->get($eventId, ['contain' => ['Applications']]); foreach ($event->applications as $applications) { // Insantiate Objects $application = $this->Applications->get($applications->id, ['contain' => ['Users', 'Scoutgroups', 'Events', 'Invoices', 'Attendees' => ['sort' => ['Attendees.role_id' => 'ASC', 'Attendees.lastname' => 'ASC'], 'Roles', 'Scoutgroups', 'Allergies'], 'Notes']]); $this->viewBuilder()->options(['pdfConfig' => ['orientation' => 'portrait', 'filename' => 'Application ' . $application->id]]); $this->set('application', $application); $this->set('_serialize', ['application']); $this->loadComponent('Progress'); $this->Progress->determineApp($application->id, true, $this->Auth->user('id'), true, true, false); $CakePdf = new \CakePdf\Pdf\CakePdf(); $CakePdf->template('application', 'default'); $CakePdf->viewVars($this->viewVars); // Get the PDF string returned $pdf = $CakePdf->output(); // Or write it to file directly $pdf = $CakePdf->write(FILES . DS . 'Event ' . $event->id . DS . 'Applications' . DS . 'Application #' . $application->id . '.pdf'); } } $this->redirect(['controller' => 'Events', 'action' => 'full_view', $event->id]); }
public function pdfView($id = null) { // Insantiate Objects $application = $this->Applications->get($id, ['contain' => ['Users', 'Scoutgroups', 'Events', 'Invoices', 'Attendees' => ['sort' => ['Attendees.role_id' => 'ASC', 'Attendees.lastname' => 'ASC']], 'Attendees.Roles' => ['conditions' => ['Attendees.user_id' => $this->Auth->user('id')]], 'Attendees.Scoutgroups' => ['conditions' => ['Attendees.user_id' => $this->Auth->user('id')]], 'Notes' => ['conditions' => ['visible' => true]]]]); $this->viewBuilder()->options(['pdfConfig' => ['orientation' => 'portrait', 'filename' => 'Invoice_' . $id]]); $this->set('application', $application); $this->set('_serialize', ['application']); $evts = TableRegistry::get('Events'); $event = $evts->get($application->event_id); $this->loadComponent('Progress'); $this->Progress->determineApp($application->id, false, $this->Auth->user('id'), true); $CakePdf = new \CakePdf\Pdf\CakePdf(); $CakePdf->template('application', 'default'); $CakePdf->viewVars($this->viewVars); // Get the PDF string returned $pdf = $CakePdf->output(); // Or write it to file directly $pdf = $CakePdf->write(FILES . DS . 'Event ' . $event->id . DS . 'Applications' . DS . 'Application #' . $id . '.pdf'); $this->redirect(['controller' => 'Applications', 'action' => 'view', $application->id, '_ext' => 'pdf']); }
public function sendPdf($id = null) { // Insantiate Objects $invoice = $this->Invoices->get($id, ['contain' => ['Users', 'Payments', 'InvoiceItems' => ['conditions' => ['visible' => 1]], 'Applications']]); $this->viewBuilder()->options(['pdfConfig' => ['orientation' => 'portrait', 'filename' => 'Invoice_' . $id]]); // Connect Registry $settings = TableRegistry::get('Settings'); $events = TableRegistry::get('Events'); $applications = TableRegistry::get('Applications'); $application = $applications->get($invoice->application_id); $event = $events->get($application->event_id, ['contain' => ['Applications', 'Settings']]); // Set Address Variables $eventName = $event->full_name; $invAddress = $event->address; $invCity = $event->city; $invPostcode = $event->postcode; $this->set(compact('eventName', 'invAddress', 'invCity', 'invPostcode')); // Set Deadline Variable $invDeadline = $event->deposit_date; // Set Prefix Variable $invSetPre = $event->invtext_id; $invSetting = $settings->get($invSetPre); $invPrefix = $invSetting->text; // Set Payable Variable $invPayable = $settings->get(4)->text; $this->set(compact('invoice', 'invPayable', 'invPrefix', 'invDeadline')); $this->set('_serialize', ['invoice']); $CakePdf = new \CakePdf\Pdf\CakePdf(); $CakePdf->template('invoice', 'default'); $CakePdf->viewVars($this->viewVars); // Get the PDF string returned $pdf = $CakePdf->output(); // Or write it to file directly $pdf = $CakePdf->write(FILES . DS . 'Event ' . $event->id . DS . 'Invoices' . DS . 'Invoice #' . $id . '.pdf'); $this->redirect(['controller' => 'Notifications', 'action' => 'sendPdf', $invoice->id]); }