TRUE, 'email'=>TRUE, 'list'=>TRUE, 'view'=>TRUE, ); /** * Download an invoice */ public function action_download() { $io = ORM::factory('Invoice',$this->request->param('id')); if (! $io->loaded() OR ! Auth::instance()->authorised($io->account)) throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it'); // Log the download $imo = $io->invoice_memo; $imo->invoice_id = $io->id; $imo->account_id = $this->ao->id; $imo->type = 'download'; $imo->memo = 'Invoice Downloaded.'; $imo->save(); $this->response->body(Invoice::instance($io)->render('pdf','all',array('download'=>sprintf('%s.pdf',$io->refnum())))); $this->response->headers(array('Content-Type' => 'application/pdf')); $this->auto_render = FALSE; } /** * Email an invoice */ public function action_email() { $io = ORM::factory('Invoice',$this->request->param('id')); if (! $io->loaded() OR ! Auth::instance()->authorised($io->account)) throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it'); if ($x=Invoice::instance($io)->render('email','all')) { // Log the emailling $imo = $io->invoice_memo; $imo->invoice_id = $io->id; $imo->account_id = $this->ao->id; $imo->type = 'email'; $imo->memo = 'Invoice Emailed.'; $imo->save(); SystemMessage::factory() ->title('Invoice') ->type('success') ->body(sprintf('Invoice :%s sent via email',$io->refnum())); HTTP::redirect(URL::link('user','email/view/'.$x)); } else { HTTP::redirect(URL::link('user','invoice/view/'.$io->id)); } } /** * Show a list of invoices */ public function action_list() { $this->meta->title = 'Invoice List'; Block::factory() ->title(sprintf('Invoices for Account: %s',$this->ao->accnum())) ->title_icon('fa fa-list') ->body(Table::factory() ->jssort('invoices') ->data($this->ao->invoice->find_all()) ->columns(array( 'id'=>'ID', 'date_orig'=>'Date Issued', 'due_date'=>'Date Due', 'total(TRUE)'=>'Total', 'total_credits(TRUE)'=>'Credits', 'payments_total(TRUE)'=>'Payments', 'due(TRUE)'=>'Still Due', )) ->prepend(array( 'id'=>array('url'=>URL::link('user','invoice/view/')), )) ); } /** * View an Invoice */ public function action_view() { list($id,$output) = Table::page(__METHOD__); $io = ORM::factory('Invoice',$id); if (! $io->loaded() OR ! Auth::instance()->authorised($io->account)) throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it'); $output .= Invoice::instance($io)->render('html','all'); $this->template->content = View::factory('invoice/user/view')->set('o',$io)->set('output',$output); } } ?>