Added affiliate pages and email due invoices
This commit is contained in:
@@ -11,7 +11,9 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_Task_Invoice extends Controller_Task {
|
||||
public function action_list($mode) {
|
||||
public function action_list() {
|
||||
$mode = $this->request->param('id');
|
||||
|
||||
$io = ORM::factory('invoice');
|
||||
$tm = 'list_'.$mode;
|
||||
|
||||
@@ -30,7 +32,7 @@ class Controller_Task_Invoice extends Controller_Task {
|
||||
$duelist .= View::factory('invoice/task/'.$tm.'_foot');
|
||||
|
||||
// Send our email
|
||||
$et = Email_Template::instance('task_invoice_overdue');
|
||||
$et = Email_Template::instance('task_list_invoice_overdue');
|
||||
|
||||
// @todo Update this to be dynamic
|
||||
$et->to = array('account'=>array(1,68));
|
||||
@@ -44,5 +46,37 @@ class Controller_Task_Invoice extends Controller_Task {
|
||||
$output = sprintf('List (%s) sent to: %s',$mode,implode(',',array_keys($et->to)));
|
||||
$this->response->body($output);
|
||||
}
|
||||
|
||||
public function action_remind_due() {
|
||||
// @todo This should go in a config somewhere
|
||||
$days = 5;
|
||||
$io = ORM::factory('invoice');
|
||||
|
||||
foreach ($io->list_due(time()-86400*$days) as $io) {
|
||||
// If we have already sent a reminder, we'll skip to the next one.
|
||||
if ($io->remind('due_reminder') AND (is_null($x=$this->request->param('id')) OR $x != 'again'))
|
||||
continue;
|
||||
|
||||
// Send our email
|
||||
$et = Email_Template::instance('task_invoice_due_reminder');
|
||||
|
||||
$et->to = array('account'=>array($io->account_id));
|
||||
$et->variables = array(
|
||||
'DUE'=>$io->due(TRUE),
|
||||
'INV_NUM'=>$io->refnum(),
|
||||
'INV_URL'=>URL::site('user/invoice/view/'.$io->id,'http'),
|
||||
'DUE_DATE'=>$io->display('due_date'),
|
||||
'FIRSTNAME'=>$io->account->first_name,
|
||||
'SITE_NAME'=>Config::sitename(),
|
||||
);
|
||||
|
||||
// @todo Record email log id if possible.
|
||||
if ($et->send())
|
||||
$io->set_remind('due_reminder',time());
|
||||
}
|
||||
|
||||
$output = _('Overdue Reminders Sent.');
|
||||
$this->response->body($output);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -60,7 +60,7 @@ class Controller_User_Invoice extends Controller_TemplateDefault_User {
|
||||
|
||||
$io = ORM::factory('invoice',$id);
|
||||
|
||||
if (! $io->loaded() OR ! Auth::instance()->authorised($io->account_id)) {
|
||||
if (! $io->loaded() OR ! Auth::instance()->authorised($io->account_id,$io->affiliate_id)) {
|
||||
$this->template->content = 'Unauthorised or doesnt exist?';
|
||||
return FALSE;
|
||||
}
|
||||
|
@@ -299,8 +299,6 @@ class Model_Invoice extends ORMOSB {
|
||||
|
||||
} else
|
||||
throw new Kohana_Exception('Couldnt save invoice for some reason?');
|
||||
|
||||
echo Kohana::debug(array('saved'=>$this));
|
||||
}
|
||||
|
||||
public function calc_total(Validate $array, $field) {
|
||||
@@ -325,6 +323,48 @@ class Model_Invoice extends ORMOSB {
|
||||
$this->_changed[$field] = $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the reminder value
|
||||
*/
|
||||
public function remind($key) {
|
||||
if (! $this->loaded())
|
||||
return NULL;
|
||||
|
||||
if (! trim($this->reminders))
|
||||
return FALSE;
|
||||
|
||||
if (! preg_match('/^a:/',$this->reminders))
|
||||
throw new Kohana_Exception('Reminder is not an array? (:reminder)',array(':remind',$this->reminders));
|
||||
|
||||
$remind = unserialize($this->reminders);
|
||||
return isset($remind[$key]) ? $remind[$key] : FALSE;
|
||||
}
|
||||
|
||||
public function set_remind($key,$value,$add=FALSE) {
|
||||
if (! $this->loaded())
|
||||
throw new Kohana_Exception('Cant call :method when a record not loaded.',array(':method',__METHOD__));
|
||||
|
||||
if (! trim($this->reminders)) {
|
||||
$remind = array();
|
||||
$remind[$key][] = $value;
|
||||
|
||||
} else {
|
||||
if (! preg_match('/^a:/',$this->reminders))
|
||||
throw new Kohana_Exception('Reminder is not an array? (:reminder)',array(':remind',$this->reminders));
|
||||
|
||||
$remind = unserialize($this->reminders);
|
||||
|
||||
if ($add)
|
||||
$remind[$key][] = $value;
|
||||
else
|
||||
$remind[$key] = $value;
|
||||
}
|
||||
|
||||
$this->reminders = serialize($remind);
|
||||
$this->save();
|
||||
return $this->saved();
|
||||
}
|
||||
|
||||
/** LIST FUNCTIONS **/
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user