Improvements to invoice display and other misc items
This commit is contained in:
@@ -12,67 +12,6 @@
|
||||
class Controller_Task_Invoice extends Controller_Task {
|
||||
public $auto_render = FALSE;
|
||||
|
||||
public function action_send() {
|
||||
// Used to only process X invoices in a row.
|
||||
$max = ORM::factory('Invoice')->config('EMAIL_INV_MAX');
|
||||
|
||||
$action = array();
|
||||
$iid = $this->request->param('id');
|
||||
$x = NULL;
|
||||
|
||||
if (preg_match('/:/',$iid))
|
||||
list($iid,$x) = explode(':',$iid);
|
||||
|
||||
// Get our list of invoices to send
|
||||
$i = $iid ? ORM::factory('Invoice')->where('id','=',$iid) : ORM::factory('Invoice')->list_tosend();
|
||||
|
||||
$key = 'send';
|
||||
|
||||
$max_count = 0;
|
||||
foreach ($i->find_all() as $io) {
|
||||
// If we have already sent a reminder or we dont email invoices we'll skip to the next one.
|
||||
if (($io->remind($key) AND (is_null($x) OR $x != 'again')) OR ($io->account->invoice_delivery != 1))
|
||||
continue;
|
||||
|
||||
// If we have issued the max number of invoices this round, finish.
|
||||
if (++$max_count > $max)
|
||||
break;
|
||||
|
||||
// Send our email
|
||||
$et = Email_Template::instance('task_invoice_'.$key);
|
||||
$token = ORM::factory('Module_Method_Token')
|
||||
->method(array('invoice','user_download'))
|
||||
->account($io->account)
|
||||
->expire(time()+86400*21)
|
||||
->uses(3)
|
||||
->generate();
|
||||
|
||||
$et->to = array('account'=>array($io->account_id));
|
||||
$et->variables = array(
|
||||
'DUE'=>$io->due(TRUE),
|
||||
'DUE_DATE'=>$io->display('due_date'),
|
||||
'EMAIL'=>Company::instance()->email(),
|
||||
'FIRST_NAME'=>$io->account->first_name,
|
||||
'HTML_INVOICE'=>$io->html(),
|
||||
'INV_NUM'=>$io->refnum(),
|
||||
'INV_URL'=>URL::site(URL::link('user','invoice/view/'.$io->id),'http'),
|
||||
'INV_URL_DOWNLOAD'=>URL::site(URL::link('user',sprintf('invoice/download/%s?token=%s',$io->id,$token)),'http'),
|
||||
'SITE_NAME'=>Company::instance()->name(),
|
||||
);
|
||||
|
||||
// @todo Record email log id if possible.
|
||||
if ($et->send()) {
|
||||
$io->print_status = 1;
|
||||
$io->set_remind($key,time(),($x=='again' ? TRUE : FALSE));
|
||||
array_push($action,(string)$io);
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->body(_('Invoices Sent: ').join('|',$action));
|
||||
}
|
||||
|
||||
/** END **/
|
||||
|
||||
public function action_audit_invoice_items() {
|
||||
$output = '';
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
class Controller_User_Invoice extends Controller_Invoice {
|
||||
protected $secure_actions = array(
|
||||
'download'=>TRUE,
|
||||
'email'=>TRUE,
|
||||
'list'=>TRUE,
|
||||
'view'=>TRUE,
|
||||
);
|
||||
@@ -33,11 +34,41 @@ class Controller_User_Invoice extends Controller_Invoice {
|
||||
$imo->memo = 'Invoice Downloaded.';
|
||||
$imo->save();
|
||||
|
||||
$this->response->body(Invoice::instance($io)->pdf()->Output(sprintf('%s.pdf',$io->refnum()),'D'));
|
||||
$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
|
||||
*/
|
||||
@@ -74,8 +105,12 @@ class Controller_User_Invoice extends Controller_Invoice {
|
||||
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 .= View::factory('invoice/user/view')
|
||||
->set('o',$io);
|
||||
$output .= Invoice::instance($io)->render('html','all');
|
||||
|
||||
$output .= '<br>';
|
||||
|
||||
$output .= HTML::anchor(URL::link('user','invoice/email/'.$io->id),'Email',array('class'=>'btn pull-right'));
|
||||
$output .= HTML::anchor(URL::link('user','invoice/download/'.$io->id),'Download',array('class'=>'btn pull-right'));
|
||||
|
||||
if ($io->due() AND ! $io->cart_exists())
|
||||
$output .= View::factory('invoice/user/view/pay')
|
||||
@@ -100,6 +135,7 @@ class Controller_User_Invoice extends Controller_Invoice {
|
||||
Block::factory()
|
||||
->title('Invoice Memos')
|
||||
->title_icon('icon-list-alt')
|
||||
->span(6)
|
||||
->body(Table::factory()
|
||||
->data($x)
|
||||
->columns(array(
|
||||
@@ -108,6 +144,27 @@ class Controller_User_Invoice extends Controller_Invoice {
|
||||
'account->name()'=>'Account',
|
||||
'memo'=>'Memo',
|
||||
)));
|
||||
|
||||
$x = $io->email()->find_all();
|
||||
if ($x->count())
|
||||
Block::factory()
|
||||
->title('Invoice Emails')
|
||||
->title_icon('icon-list-alt')
|
||||
->span(6)
|
||||
->body(Table::factory()
|
||||
->data($x)
|
||||
->columns(array(
|
||||
'id'=>'ID',
|
||||
'date_orig'=>'Date',
|
||||
'resolve("subject")'=>'Subject',
|
||||
))
|
||||
->prepend(array(
|
||||
'id'=>array('url'=>URL::link('user','email/view/')),
|
||||
))
|
||||
->postproc(array(
|
||||
'resolve("subject")'=>array('trim'=>55),
|
||||
))
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user