Move invoice config items into the DB

This commit is contained in:
Deon George
2012-01-12 10:23:35 +11:00
parent 8d53924988
commit 14d5f1939e
5 changed files with 60 additions and 42 deletions

View File

@@ -58,9 +58,8 @@ class Controller_Task_Invoice extends Controller_Task {
*/
public function action_remind_due() {
$action = array();
// @todo This should go in a config somewhere
$days = 5;
$key = 'remind_due';
$days = ORM::factory('invoice')->config('REMIND_DUE');
foreach (ORM::factory('invoice')->list_due(time()+86400*$days) as $io) {
// If we have already sent a reminder, we'll skip to the next one.
@@ -103,18 +102,9 @@ class Controller_Task_Invoice extends Controller_Task {
switch ($notice) {
case 1:
// @todo This should go in a config somewhere
$days = 2;
break;
case 2:
// @todo This should go in a config somewhere
$days = 7;
break;
case 3:
// @todo This should go in a config somewhere
$days = 13;
$days = ORM::factory('invoice')->config('REMIND_OVERDUE_'.$notice);
break;
default:
@@ -162,8 +152,8 @@ class Controller_Task_Invoice extends Controller_Task {
*/
public function action_services() {
// Used to only process X invoices in a row.
// @todo This should be a configuration item.
$max = 10;
$max = ORM::factory('invoice')->config('GEN_INV_MAX');
$action = array();
$snd = array(); // Our service next billing dates that need to be updated if this is successful.
$sid = is_null($this->request->param('id')) ? NULL : explode(':',$this->request->param('id'));
@@ -189,7 +179,7 @@ class Controller_Task_Invoice extends Controller_Task {
}
// If we have issued the max number of invoices this round, finish.
if (++$max_count > $max)
if ($max AND (++$max_count > $max))
break;
// Start a new invoice.
@@ -247,7 +237,7 @@ class Controller_Task_Invoice extends Controller_Task {
}
// Save our invoice.
if (! $io->saved() AND ! $io->save()) {
if ($io AND ! $io->saved() AND ! $io->save()) {
print_r($io->items());
throw new Kohana_Exception('Failed to save invoice :invoice for service :service',array(':invoice'=>$io->id,':service'=>$so->id));
}
@@ -264,8 +254,8 @@ class Controller_Task_Invoice extends Controller_Task {
public function action_send() {
// Used to only process X invoices in a row.
// @todo This should be a configuration item.
$max = 10;
$max = ORM::factory('invoice')->config('EMAIL_INV_MAX');
$action = array();
$iid = $this->request->param('id');
$x = NULL;