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

@@ -22,8 +22,15 @@ class Controller_Admin_Invoice extends Controller_TemplateDefault_Admin {
public function action_setup() {
$this->setup(array(
'EMAIL_INV_MAX'=>_('Email this many invoices in a run (0=no limit)'),
'GEN_DAYS'=>_('Generate Invoices this many days in advance of the due date'),
'GEN_INV_MAX'=>_('Generate this many invoices in a run (0=no limit)'),
'GEN_SOON_DAYS'=>_('Days before GEN_DAYS to list invoices that will be generated'),
'DUE_DAYS_MIN'=>_('When invoices are generated, the minimum days in advance the due date should be set to'),
'REMIND_DUE'=>_('Days before an invoice due to sent out a reminder'),
'REMIND_OVERDUE_1'=>_('Days after an invoice is due to send first reminder'),
'REMIND_OVERDUE_2'=>_('Days after an invoice is due to send second reminder'),
'REMIND_OVERDUE_3'=>_('Days after an invoice is due to send third and final reminder'),
'TAX_ID'=>_('TAX ID shown on invoices'),
'TAX_ID_NAME'=>_('TAX ID name shown on invoices'),
));

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;