Added User email viewing

Improved Table::
This commit is contained in:
Deon George 2011-08-27 16:33:46 +10:00
parent 495da41e0d
commit 6d44e7d5b2
51 changed files with 701 additions and 273 deletions

View File

@ -25,22 +25,34 @@ class Controller_Admin_Welcome extends Controller_TemplateDefault {
Block_Sub::add(array(
'title'=>'Invoices Overdue',
'body'=>Table::limit(
'body'=>Table::display(
$o->list_overdue($t),
30,
array('Due Date'=>'display("due_date")','Account'=>'account->name()','Active'=>'account->display("status")','ID'=>'id()','Amount Due'=>'due(TRUE)'),
'due()'),
25,
array(
'due_date'=>array('label'=>'Due Date'),
'account->name()'=>array('label'=>'Account'),
'account->display("status")'=>array('label'=>'Active'),
'id()'=>array('label'=>'ID'),
'due(TRUE)'=>array('label'=>'Amount Due','class'=>'right'),
),
array('page'=>TRUE)),
'position'=>1,
'order'=>1,
));
Block_Sub::add(array(
'title'=>'Invoices Due',
'body'=>Table::limit(
'body'=>Table::display(
$o->list_due($t),
30,
array('Due Date'=>'display("due_date")','Account'=>'account->name()','Active'=>'account->display("status")','ID'=>'id()','Amount Due'=>'due(TRUE)'),
'due()'),
25,
array(
'due_date'=>array('label'=>'Due Date'),
'account->name()'=>array('label'),
'account->display("status")'=>array('label'=>'Active'),
'id()'=>array('label'=>'ID'),
'due(TRUE)'=>array('label'=>'Amount Due','class'=>'right'),
),
array('show_other'=>'due()')),
'position'=>2,
'order'=>1,
));
@ -50,11 +62,17 @@ class Controller_Admin_Welcome extends Controller_TemplateDefault {
Block_Sub::add(array(
'title'=>'Unapplied Payments',
'body'=>Table::limit(
'body'=>Table::display(
$o->list_unapplied(),
30,
array('ID'=>'id','Account'=>'account->name()','Total'=>'display("total_amt")','Balance'=>'balance(TRUE)'),
'balance(TRUE)'),
25,
array(
'id'=>array('label'=>'ID'),
'account->name()'=>array('label'=>'Account'),
'account->display("status")'=>array('label'=>'Active'),
'total_amt'=>array('label'=>'Total','class'=>'right'),
'balance(TRUE)'=>array('label'=>'Balance','class'=>'right'),
),
array('show_other'=>'balance()')),
'position'=>3,
'order'=>1,
));

View File

@ -107,7 +107,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
Block::add(array(
'title'=>_('Register'),
'body'=>View::factory('bregister')
'body'=>View::factory('register')
->set('account',$account)
->set('errors',$account->validation()->errors('form/register')),
));

View File

@ -185,10 +185,13 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
if ($s = $this->_sysmsg() AND (string)$s)
$this->response->body(sprintf('<table class="sysmsg"><tr><td>%s</td></tr></table>',$s));
# In case there any style sheets or scrpits for this render.
// In case there any style sheets for this render.
$this->response->bodyadd(Style::factory());
# Get the response body
// In case there any javascript for this render.
$this->response->bodyadd(Script::factory());
// Get the response body
$this->response->bodyadd(sprintf('<table class="content"><tr><td>%s</td></tr></table>',$this->template->content));
}

View File

@ -17,10 +17,10 @@ class Controller_lnApp_Tree extends Controller_Default {
protected static $jsmediaroute = 'default/media';
public function after() {
parent::after();
$this->response->headers('Content-Type','application/json');
$this->response->body(sprintf('[%s]',json_encode($this->output)));
parent::after();
}
public static function js() {

View File

@ -86,7 +86,7 @@ class lnApp_Block_Sub extends HTMLRender {
// Render our output.
$output .= '<table class="subblockhead">';
foreach ($o as $k => $v)
$output .= sprintf('<tr><td style="width: %s%%;">%s</td></tr>',round(100/$y,0),implode('</td><td>',$v));
$output .= sprintf('<tr><td style="width: %s%%;">%s</td></tr>',$x=round(100/$y,0),implode(sprintf('</td><td style="width: %s%%;">',$x),$v));
$output .= '</table>';
return $output;

View File

@ -12,52 +12,242 @@
* @uses Style
*/
class lnApp_Table {
public static function limit($data,$rows,array $cols,$other) {
public static function resolve($d,$key) {
if (is_array($d) AND isset($d[$key]))
$x = $d[$key];
// If the key is a method, we need to eval it
elseif (preg_match('/\(/',$key))
eval("\$x = \$d->$key;");
elseif (preg_match('/^__VALUE__$/',$key))
$x = $d;
else
$x = $d->display($key);
return $x;
}
public static function display($data,$rows,array $cols,array $option) {
if (! (array)$data)
return '';
$output = '';
$pag = NULL;
$view = $output = '';
$other = $i = 0;
$output = '<table border="0">';
$output .= '<tr><th>'.implode('</th><th>',array_keys($cols)).'</th></tr>';
foreach ($data as $do) {
if ($i++ < $rows) {
$output .= '<tr>';
if (isset($option['type']) AND $option['type'])
switch ($option['type']) {
case 'select':
$view = 'table/select';
foreach (array_values($cols) as $col) {
if (is_array($do) AND isset($do[$col]))
$x = $do[$col];
// If the col is a method, we need to eval it
elseif (preg_match('/\(/',$col))
eval("\$x = \$do->$col;");
else
$x = $do->{$col};
$output .= sprintf('<td>%s</td>',$x);
Script::add(array(
'type'=>'stdin',
'data'=>'
(function($) {
// Enable Range Selection
$.fn.enableCheckboxRangeSelection = function() {
var lastCheckbox = null;
var followOn = 0;
var $spec = this;
$spec.bind("click", function(e) {
if (lastCheckbox != null && e.shiftKey) {
x = y = 0;
if (followOn != 0) {
if ($spec.index(lastCheckbox) < $spec.index(e.target)) {
x = 1 - ((followOn == 1) ? 1 : 0);
} else {
y = 1 - ((followOn == -1) ? 1 : 0);
}
}
$output .= '</tr>';
$spec.slice(
Math.min($spec.index(lastCheckbox) - x, $spec.index(e.target)) + 1,
Math.max($spec.index(lastCheckbox), $spec.index(e.target)) + y
).attr("checked",function() { return ! this.checked; })
.parent().parent().toggleClass("selected");
followOn = ($spec.index(lastCheckbox) < $spec.index(e.target)) ? 1 : -1;
} else {
if (is_array($do) AND isset($do[$col]))
$x = $do[$col];
// If the col is a method, we need to eval it
elseif (preg_match('/\(/',$col))
eval("\$x = \$do->$col;");
else
$x = $do->{$col};
followOn = 0;
}
lastCheckbox = e.target;
});
$other += $x;
return $spec;
};
// Enable Toggle, (De)Select All
$.fn.check = function(mode) {
// if mode is undefined, use "on" as default
var mode = mode || "on";
switch(mode) {
case "on":
$("#select-table tr:not(.head)")
.filter(":has(:checkbox:not(checked))")
.toggleClass("selected")
break;
case "off":
$("#select-table tr:not(.head)")
.filter(":has(:checkbox:checked)")
.toggleClass("selected")
break;
case "toggle":
$("#select-table tr:not(.head)")
.toggleClass("selected");
break;
}
return this.each(function(e) {
switch(mode) {
case "on":
this.checked = true;
break;
case "off":
this.checked = false;
break;
case "toggle":
this.checked = !this.checked;
break;
}
});
};
})(jQuery);
// Bind our actions
$(document).ready(function() {
$("#select-table :checkbox").enableCheckboxRangeSelection();
$("#select-menu > #toggle").bind("click",function() {
$("#select-table :checkbox").check("toggle");
});
$("#select-menu > #all_on").bind("click",function() {
$("#select-table :checkbox").check("on");
});
$("#select-menu > #all_off").bind("click",function() {
$("#select-table :checkbox").check("off");
});
// Our mouse over row highlight
$("#select-table tr:not(.head)").hover(function() {
$(this).children().toggleClass("highlight");
},
function() {
$(this).children().toggleClass("highlight");
});
// Click to select Row
$("#select-table tr:not(.head)")
.filter(":has(:checkbox:checked)")
.addClass("selected")
.end()
.click(function(e) {
$(this).toggleClass("selected");
if (e.target.type !== "checkbox") {
$(":checkbox", this).attr("checked", function() {
return !this.checked;
});
}
});
});
'));
$output .= Form::open((isset($option['form']) ? $option['form'] : ''));
break;
case 'list':
default:
Script::add(array(
'type'=>'stdin',
'data'=>'
// Bind our actions
$(document).ready(function() {
// Our mouse over row highlight
$("#list-table tr:not(.head)").hover(function() {
$(this).children().toggleClass("highlight");
},
function() {
$(this).children().toggleClass("highlight");
});
});
'));
}
If (! $view)
$view = 'table/list';
if (isset($option['page']) AND $option['page']) {
$pag = new Pagination(array(
'total_items'=>count($data),
'items_per_page'=>$rows,
));
$output .= (string)$pag;
}
$other = $i = 0;
$td = $th = array();
foreach ($cols as $col => $details) {
$th[$col] = isset($details['label']) ? $details['label'] : '';
$td[$col]['class'] = isset($details['class']) ? $details['class'] : '';
$td[$col]['url'] = isset($details['url']) ? $details['url'] : '';
}
$output .= View::factory($view.'_head')
->set('th',array_values($th));
foreach ($data as $do) {
if ($pag) {
if (++$i < $pag->current_first_item())
continue;
elseif ($i > $pag->current_last_item())
break;
}
if ($pag OR ($i++ < $rows)) {
foreach (array_keys($cols) as $col)
$td[$col]['value'] = Table::resolve($do,$col);
$output .= View::factory($view.'_body')
->set('td',$td)
->set('trc',$i%2 ? 'odd' : 'even');
} elseif (isset($option['show_other']) AND ($col=$option['show_other'])) {
$other += Table::resolve($do,$col);
}
}
if ($other)
$output .= sprintf('<tr><td>Other</td><td colspan="%s">(%s) %s</td></tr>',count($cols)-1,$i-$rows,$other);
$output .= View::factory($view.'_xtra')
->set('td',array_values($cols))
->set('count',$i-$rows)
->set('other',$other);
$output .= '</table>';
$output .= View::factory($view.'_foot');
if (isset($option['type']) AND $option['type'])
switch ($option['type']) {
case 'select':
$output .= Form::close();
}
return $output;
}
public static function post($key,$i='id') {
if (isset($_POST[$i]))
Session::instance()->set('page_table_view'.$key,$_POST[$i]);
}
public static function page($key) {
if ($ids = Session::instance()->get('page_table_view'.$key)) {
$pag = new Pagination(array(
'total_items'=>count($ids),
'items_per_page'=>1,
));
return array($ids[$pag->current_first_item()-1],(string)$pag);
// If we get here, then there is no previous data to retrieve.
} else
return array(NULL,'');
}
}
?>

View File

@ -27,8 +27,13 @@ class Model_Module extends ORMOSB {
'name'=>'ASC',
);
protected $_formats = array(
'status'=>array('StaticList_YesNo::display'=>array()),
protected $_display_filters = array(
'name'=>array(
array('strtoupper',array(':value')),
),
'status'=>array(
array('StaticList_YesNo::display',array(':value')),
),
);
}
?>

View File

@ -0,0 +1,15 @@
<?php defined('SYSPATH') or die('No direct script access.');
return array(
// Application defaults
'default' => array(
'current_page' => array('source' => 'query_string', 'key' => 'page'), // source: "query_string" or "route"
'total_items' => 0,
'items_per_page' => 20,
'view' => 'pagination/floating',
'auto_hide' => TRUE,
'first_page_in_url' => FALSE,
),
);

View File

@ -1,5 +1,19 @@
/* Default Template CSS */
.form_button {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #000000;
background-color: #E1E1E3;
border-color: #AAAACC;
border-width: 1px;
padding: 1px;
}
.highlight {
background-color: #AABBCC;
}
table.box-left { border: 1px solid #AAAACC; margin-right: auto; }
table.box-center { border: 1px solid #AAAACC; margin-left: auto; margin-right: auto; }
table.box-full { border: 1px solid #AAAACC; margin-right: auto; width: 100%; }
@ -14,6 +28,8 @@ td.data-right { font-weight: bold; text-align: right; }
td.right { text-align: right; }
tr.odd { background-color: #FCFCFE; }
tr.even { background-color: #F6F6F8; }
tr.odd.selected { background-color: #ECECEE; }
tr.even.selected { background-color: #E6E6E8; }
/* Global Page */
table.page {
@ -208,8 +224,6 @@ table.page tr.pagemain td.pagebody table.content table.subblockhead {
table.page tr.pagemain td.pagebody table.content table.subblock {
width: 100%;
border: 1px solid #AAAACC;
margin-right: auto;
width: 100%;
}
table.page tr.pagemain td.pagebody table.content tr.title {

View File

@ -0,0 +1,7 @@
<tr class="<?php echo $trc; ?>">
<?php foreach ($td as $col => $details) { ?>
<td class="<?php echo $details['class']; ?>">
<?php echo $details['url'] ? sprintf(HTML::anchor($details['url'].$details['value'],$details['value'])) : $details['value']; ?>
</td>
<?php } ?>
</tr>

View File

@ -0,0 +1,2 @@
<table class="box-left" border="0" id="list-table">
<tr class="head"><td class="head"><?php echo implode('</td><td class="head">',$th); ?></td></tr>

View File

@ -0,0 +1 @@
<tr><td>Other</td><td colspan="<?php echo count($td)-1; ?>"><?php printf('(%s) %s',$count,$other); ?></td></tr>

View File

@ -0,0 +1,8 @@
<tr class="<?php echo $trc; ?>">
<td><?php echo Form::checkbox('id[]',$td['id']['value']); ?></td>
<?php foreach ($td as $col => $details) { ?>
<td class="<?php echo $details['class']; ?>">
<?php echo $details['url'] ? sprintf(HTML::anchor($details['url'].$details['value'],$details['value'])) : $details['value']; ?>
</td>
<?php } ?>
</tr>

View File

@ -0,0 +1,8 @@
</table>
<div style="text-align: center;" id="select-menu">
<br/>
<input type="submit" name="Submit" value="View/Edit" class="form_button"/>
<input type="button" name="Submit" value="Select All" class="form_button" id="all_on" />
<input type="button" name="Submit" value="Deselect All" class="form_button" id="all_off" />
<input type="button" name="Submit" value="Toggle Select" class="form_button" id="toggle" />
</div>

View File

@ -0,0 +1,2 @@
<table class="box-full" border="0" id="select-table">
<tr class="head"><td style="width: 25px;">&nbsp;</td><td class="head"><?php echo implode('</td><td class="head">',$th); ?></td></tr>

View File

@ -0,0 +1 @@
<tr><td>Other</td><td colspan="<?php echo count($td)-1; ?>"><?php printf('(%s) %s',$count,$other); ?></td></tr>

View File

@ -93,7 +93,7 @@ class Controller_User_Account extends Controller_TemplateDefault_User {
Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Account Edit'),$this->ao->accnum(),$this->ao->name(TRUE)),
'body'=>View::factory('account/edit')
'body'=>View::factory('account/user/edit')
->set('record',$this->ao),
));
}

View File

@ -12,6 +12,7 @@ class Model_Account extends Model_Auth_UserDefault {
// Relationships
protected $_has_many = array(
'user_tokens' => array('model' => 'user_token'),
'email_log' => array('far_key'=>'id'),
'group' => array('through' => 'account_group'),
'invoice' => array('far_key'=>'id'),
'payment'=>array('far_key'=>'id'),

View File

@ -12,11 +12,38 @@
*/
class Controller_Admin_Email extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'list'=>TRUE,
'templateadd'=>TRUE,
'templateedit'=>TRUE,
'templatelist'=>TRUE,
);
/**
* Show a list of emails
*/
public function action_list() {
$elo = ORM::factory('email_log');
Block::add(array(
'title'=>_('System Emails Sent'),
'body'=>Table::display(
$elo->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>'user/email/view/'),
'date_orig'=>array('label'=>'Date'),
'translate_resolve("subject")'=>array('label'=>'Subject'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
),
array(
'page'=>TRUE,
'type'=>'select',
'form'=>'user/email/view',
)),
));
}
/**
* List our defined email templates
*/

View File

@ -0,0 +1,70 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides User Email View functions
*
* @package OSB
* @subpackage Email
* @category Controllers/User
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_User_Email extends Controller_TemplateDefault_User {
protected $secure_actions = array(
'list'=>TRUE,
'view'=>TRUE,
);
/**
* Show a list of emails
*/
public function action_list() {
Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Email For'),$this->ao->accnum(),$this->ao->name(TRUE)),
'body'=>Table::display(
$this->ao->email_log->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>'user/email/view/'),
'date_orig'=>array('label'=>'Date'),
'translate_resolve("subject")'=>array('label'=>'Subject'),
),
array(
'page'=>TRUE,
'type'=>'select',
'form'=>'user/email/view',
)),
));
}
public function action_view() {
$output = '';
if (! $id = $this->request->param('id')) {
if (isset($_POST['id']) AND is_array($_POST['id']))
Table::post('email_view','id');
list($id,$output) = Table::page('email_view');
} else {
$id = $this->request->param('id');
}
$elo = ORM::factory('email_log',$id);
if (! $elo->loaded() OR ! Auth::instance()->authorised($elo->account_id)) {
$this->template->content = 'Unauthorised or doesnt exist?';
return FALSE;
}
$output .= View::factory('email/user/view')
->set('elo',$elo);
Block::add(array(
'title'=>sprintf('%s: %s',_('Email'),$elo->translate_resolve('subject')),
'body'=>$output,
));
}
}
?>

View File

@ -13,7 +13,7 @@
class Email_Template {
// We'll store the template here
private $template;
private $template_mail;
private $etto;
private $email_data = array();
private $default_lang = 'en';
private $components = array('subject','message_text','message_html');
@ -27,9 +27,9 @@ class Email_Template {
if (is_null($language_id))
$language_id=$this->default_lang;
$this->template_mail = $this->template->email_template_translate->where('language_id','=',$language_id)->find();
if (! $this->template_mail->loaded() AND
($this->template_mail = $this->template->email_template_translate->where('language_id','=',$this->default_lang)->find()) AND ! $this->template_mail->loaded())
$this->etto = $this->template->email_template_translate->where('language_id','=',$language_id)->find();
if (! $this->etto->loaded() AND
($this->etto = $this->template->email_template_translate->where('language_id','=',$this->default_lang)->find()) AND ! $this->etto->loaded())
// @todo Change this to log/email the admin
throw new Kohana_Exception('No template (:template) found for user language (:language_id) or default language (:default_lang)',
@ -97,23 +97,20 @@ class Email_Template {
$return = array();
foreach ($this->components as $v)
foreach ($this->template_mail->variables($v) as $x=>$y)
foreach ($this->etto->variables($v) as $x => $y)
if (! in_array($y,$return))
array_push($return,$y);
return $return;
}
public function send($admin=FALSE) {
public function send(array $admin=array()) {
$e = Email::connect();
$sm = Swift_Message::newInstance()
->setFrom(Kohana::config('config.email_from'));
foreach ($this->components as $component) {
$s = $this->template_mail->$component;
foreach ($this->template_mail->variables($component) as $k => $v)
$s = str_replace('%'.$v.'%',$this->email_data['variables'][$v],$s);
$s = $this->etto->resolve($this->email_data['variables'],$component);
switch ($component) {
case 'message_html':
@ -131,7 +128,6 @@ class Email_Template {
}
}
// @todo This should go to the admin defined in email_setup
if ($admin OR ($admin = Config::testmail($this->template->name))) {
$sm->setTo($admin);
$sa = array(1);
@ -153,7 +149,7 @@ class Email_Template {
$elo->clear();
$elo->account_id = $id;
$elo->email_template_id = $this->template_mail->id;
$elo->email_template_translate_id = $this->etto->id;
$elo->data = $data;
$elo->save();
}

View File

@ -11,10 +11,26 @@
* @license http://dev.osbill.net/license.html
*/
class Model_Email_Log extends ORMOSB {
protected $_belongs_to = array(
'account'=>array('far_key'=>'id'),
'email_template_translate'=>array('far_key'=>'id'),
);
protected $_sorting = array(
'id'=>'DESC',
);
protected $_display_filters = array(
'date_orig'=>array(
array('Config::datetime',array(':value')),
),
);
public function translate_resolve($column) {
if (! $this->data OR ! ($r = $this->email_template_translate->variables($column)))
return $this->email_template_translate->display($column);
else
return $this->email_template_translate->resolve(unserialize(gzuncompress($this->data)),$column);
}
}
?>

View File

@ -28,5 +28,14 @@ class Model_Email_Template_Translate extends ORMOSB {
return $results;
}
public function resolve($data,$column) {
$output = $this->display($column);
foreach ($this->variables($column) as $k => $v)
$output = str_replace('%'.$v.'%',$data[$v],$output);
return $output;
}
}
?>

View File

@ -0,0 +1,20 @@
<table width="100%">
<tr>
<td>To:</td><td class="data"><?php printf('%s (%s)',$elo->account->name(),$elo->account->display('email')); ?></td>
</tr>
<tr>
<td>Date:</td><td class="data"><?php echo $elo->display('date_orig'); ?></td>
</tr>
<tr>
<td>Subject:</td><td class="data"><?php echo $elo->translate_resolve('subject'); ?></td>
</tr>
<tr>
<td style="width: 100%;" colspan="2">
<table class="box-full">
<tr>
<td><?php echo $elo->translate_resolve('message_html'); ?></td>
</tr>
</table>
</td>
</tr>
</table>

View File

@ -1,28 +0,0 @@
<?php
echo '<b>'.__FILE__.'</b><br/>';
echo Form::open();
echo Form::select('plugin',$plugins);
echo '<table>';
echo '<tr>';
printf('<td class="heading">%s</td>','Date');
printf('<td class="heading">%s</td>','Invoice');
printf('<td class="heading">%s</td>','Customer');
printf('<td class="heading">%s</td>','Method');
printf('<td class="heading">%s</td>','Export');
echo '</tr>';
$c = 0;
foreach ($invoices as $invoice) {
printf('<tr class="%s">',(++$c%2==0?'even':'odd'));
printf('<td>%s</td><td>%s</td><td>%s %s (%s)</td><td>%s [%s/%s]</td><td><input type="checkbox" name="invoiceid[]" value="%s" /></td>',
$invoice->date_orig,$invoice->id,
$invoice->account->first_name,$invoice->account->last_name,$invoice->account->company,'paymentmethod',$invoice->total_amt,$invoice->due_date,
$invoice->id);
echo '</tr>';
}
echo '</table>';
echo Form::close();
echo '<PRE>';print_r($invoice);
?>

View File

@ -11,6 +11,39 @@
* @license http://dev.osbill.net/license.html
*/
class Controller_Admin_Invoice extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'list'=>TRUE,
);
/**
* Show a list of invoices
*/
public function action_list() {
$io = ORM::factory('invoice');
Block::add(array(
'title'=>_('System Customer Invoices'),
'body'=>Table::display(
$io->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>'user/invoice/view/'),
'date_orig'=>array('label'=>'Date'),
'total_amt'=>array('label'=>'Total','class'=>'right'),
'credit_amt'=>array('label'=>'Credits','class'=>'right'),
'billed_amt'=>array('label'=>'Payments','class'=>'right'),
'due(TRUE)'=>array('label'=>'Still Due','class'=>'right'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
),
array(
'page'=>TRUE,
'type'=>'select',
'form'=>'user/invoice/view',
)),
));
}
public function action_convert() {
if (Config::sitemode() != KOHANA::DEVELOPMENT)
throw new Kohana_Exception(__METHOD__.' can only be run in development');

View File

@ -11,11 +11,5 @@
* @license http://dev.osbill.net/license.html
*/
class Controller_Invoice extends Controller_TemplateDefault {
public function action_display() {
// @todo - this should be a global config item
$mediapath = Route::get('default/media');
$this->template->content = Kohana::debug(func_get_args());
}
}
?>

View File

@ -19,7 +19,7 @@ class Controller_Task_Invoice extends Controller_Task {
throw new Kohana_Exception('Unknown Task List command :command',array(':command'=>$mode));
$total = $numinv = 0;
$duelist = View::factory('invoice/task/'.$tm.'_header');
$duelist = View::factory('invoice/task/'.$tm.'_head');
foreach ($io->$tm() as $t) {
$duelist .= View::factory('invoice/task/'.$tm.'_body')
->set('io',$t);
@ -27,7 +27,7 @@ class Controller_Task_Invoice extends Controller_Task {
$numinv++;
$total += $t->due();
}
$duelist .= View::factory('invoice/task/'.$tm.'_footer');
$duelist .= View::factory('invoice/task/'.$tm.'_foot');
// Send our email
$et = Email_Template::instance('task_invoice_overdue');

View File

@ -18,20 +18,46 @@ class Controller_User_Invoice extends Controller_TemplateDefault_User {
);
/**
* Show a product
* Show a list of invoices
*/
public function action_list() {
Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Invoices For'),$this->ao->accnum(),$this->ao->name(TRUE)),
'body'=>View::factory('invoice/user/list')
->set('invoices',$this->ao->invoice->find_all()),
'body'=>Table::display(
$this->ao->invoice->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>'user/invoice/view/'),
'date_orig'=>array('label'=>'Date'),
'total_amt'=>array('label'=>'Total','class'=>'right'),
'credit_amt'=>array('label'=>'Credits','class'=>'right'),
'billed_amt'=>array('label'=>'Payments','class'=>'right'),
'due(TRUE)'=>array('label'=>'Still Due','class'=>'right'),
),
array(
'page'=>TRUE,
'type'=>'select',
'form'=>'user/invoice/view',
)),
));
}
/**
* View an Invoice
*/
public function action_view($id) {
public function action_view() {
$output = '';
if (! $id = $this->request->param('id')) {
if (isset($_POST['id']) AND is_array($_POST['id']))
Table::post('invoice_view','id');
list($id,$output) = Table::page('invoice_view');
} else {
$id = $this->request->param('id');
}
$io = ORM::factory('invoice',$id);
if (! $io->loaded() OR ! Auth::instance()->authorised($io->account_id)) {
@ -39,10 +65,14 @@ class Controller_User_Invoice extends Controller_TemplateDefault_User {
return FALSE;
}
// @todo media path probably should be a config item
$this->template->content = View::factory('invoice/user/html')
$output .= View::factory('invoice/user/view')
->set('mediapath',Route::get('default/media'))
->set('invoice',$io);
->set('io',$io);
Block::add(array(
'title'=>sprintf('%s: %s',_('Invoice'),$io->refnum()),
'body'=>$output,
));
}
/**

View File

@ -1,23 +0,0 @@
<!-- @todo NEEDS TO BE TRANSLATED -->
<table class="box-left">
<tr>
<td class="head">ID</td>
<td class="head">Date</td>
<td class="head">Total</td>
<td class="head">Credits</td>
<td class="head">Payments</td>
<td class="head">Due</td>
<td class="head">Active</td>
</tr>
<?php $i = 0; foreach ($invoices as $invoice) { ?>
<tr class="<?php echo ++$i%2 ? 'odd' : 'even'; ?>">
<td><?php echo HTML::anchor('/user/invoice/view/'.$invoice->id,$invoice->id()); ?></td>
<td><?php echo $invoice->display('date_orig'); ?></td>
<td class="number"><?php echo $invoice->display('total_amt'); ?></td>
<td class="number"><?php echo $invoice->display('credit_amt'); ?></td>
<td class="number"><?php echo $invoice->display('billed_amt'); ?></td>
<td style="font-weight: <?php echo $invoice->due() ? 'bold' : 'normal'; ?>"><?php echo Currency::display($invoice->due()); ?></td>
<td><?php echo $invoice->display('status'); ?></td>
</tr>
<?php } ?>
</table>

View File

@ -14,27 +14,27 @@
<table class="invoice_summary" border="0">
<tr>
<td>TAX INVOICE</td>
<td class="bold-right"><?php echo $invoice->id(); ?></td>
<td class="bold-right"><?php echo $io->id(); ?></td>
</tr>
<tr>
<td>Issue Date</td>
<td class="bold-right"><?php echo $invoice->display('date_orig'); ?></td>
<td class="bold-right"><?php echo $io->display('date_orig'); ?></td>
</tr>
<tr>
<td>Due Date</td>
<td class="bold-right"><?php echo $invoice->display('due_date'); ?></td>
<td class="bold-right"><?php echo $io->display('due_date'); ?></td>
</tr>
<tr>
<td>Current Charges Due</td>
<td class="bold-right"><?php echo $invoice->display('total_amt'); ?></td>
<td class="bold-right"><?php echo $io->display('total_amt'); ?></td>
</tr>
<tr>
<td>Payments Received to Date</td>
<td class="bold-right"><?php echo $invoice->display('billed_amt'); ?></td>
<td class="bold-right"><?php echo $io->display('billed_amt'); ?></td>
</tr>
<tr>
<td>Total Charges Due</td>
<td class="bold-right"><?php echo $invoice->due(TRUE); ?></td>
<td class="bold-right"><?php echo $io->due(TRUE); ?></td>
</tr>
</table>
</td>
@ -46,7 +46,7 @@
<tr>
<td class="head" colspan="4">Charges Detail:</td>
</tr>
<?php foreach ($invoice->sorted_service_items('recur_schedule') as $cat => $catitems) { ?>
<?php foreach ($io->sorted_service_items('recur_schedule') as $cat => $catitems) { ?>
<?php if ($cat) { ?>
<tr>
<td><div id="toggle_<?php echo $cat; ?>"><?php echo HTML::image($mediapath->uri(array('file'=>'img/toggle-closed.png')),array('alt'=>'+')); ?></div><script type="text/javascript">$("#toggle_<?php echo $cat; ?>").click(function() {$('#detail_toggle_<?php echo $cat; ?>').toggle();});</script></td>
@ -71,7 +71,7 @@
<tr class="head">
<td><?php echo HTML::anchor('/user/service/view/'.$item->service->id,$item->service->id()); ?></td>
<td colspan="3"><?php echo $item->product->product_translate->find()->name; ?> (<?php echo $item->product_id; ?>)</td>
<td class="right"><?php echo Currency::display($invoice->items_service_total($item->service_id));?></td>
<td class="right"><?php echo Currency::display($io->items_service_total($item->service_id));?></td>
</tr>
<!-- End Product Information -->
@ -86,7 +86,7 @@
<!-- Product Sub Items -->
<?php
foreach ($invoice->items_sub($item->service_id) as $subitem) {
foreach ($io->items_sub($item->service_id) as $subitem) {
if (! is_null($subitem->module_id)) {
$m = StaticList_Module::record('module','name','id',$subitem->module_id);
// @todo Need to remove the explicit test for 'charge' and be more dynamic
@ -109,14 +109,14 @@
<tr>
<td colspan="2">&nbsp;</td>
<td><?php echo _('Taxes'); ?></td>
<td class="right"><?php echo Currency::display($invoice->items_service_tax($item->service_id));?></td>
<td class="right"><?php echo Currency::display($io->items_service_tax($item->service_id));?></td>
</tr>
<!-- Product End Sub Items Tax -->
<?php } ?>
<?php } else { ?>
<!-- Product Sub Items -->
<?php
foreach ($invoice->items_sub(NULL) as $subitem) {
foreach ($io->items_sub(NULL) as $subitem) {
if (! is_null($subitem->module_id)) {
$m = StaticList_Module::record('module','name','id',$subitem->module_id);
// @todo Need to remove the explicit test for 'charge' and be more dynamic
@ -142,13 +142,13 @@
<?php } ?>
<tr>
<td class="head" colspan="2">Sub Total:</td>
<td class="bold-right"><?php echo $invoice->subtotal(TRUE); ?></td>
<td class="bold-right"><?php echo $io->subtotal(TRUE); ?></td>
</tr>
<tr>
<td class="head" colspan="4">Taxes Included:</td>
</tr>
<?php
foreach ($invoice->tax_summary() as $tid => $amount) {
foreach ($io->tax_summary() as $tid => $amount) {
$m = ORM::factory('tax',$tid);
?>
<tr>
@ -160,12 +160,12 @@
<!-- @todo Add discounts -->
<tr>
<td class="head" colspan="3">Total:</td>
<td class="bold-right"><?php echo $invoice->total(TRUE); ?></td>
<td class="bold-right"><?php echo $io->total(TRUE); ?></td>
</tr>
</table>
</td>
</tr>
<tr>
<td><?php echo HTML::anchor('user/invoice/download/'.$invoice->id,'Download detailed invoice'); ?></td>
<td><?php echo HTML::anchor('user/invoice/download/'.$io->id,'Download detailed invoice'); ?></td>
</tr>
</table>

View File

@ -12,6 +12,7 @@
*/
class Controller_Admin_Module extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'add'=>TRUE,
'edit'=>TRUE,
'list'=>TRUE,
);
@ -47,30 +48,32 @@ class Controller_Admin_Module extends Controller_TemplateDefault_Admin {
* List our installed modules
*/
public function action_list() {
$modules = ORM::factory('module');
$output = '';
$output .= View::factory('module/admin/list_header');
foreach ($modules->find_all() as $mo) {
$output .= View::factory('module/admin/list_body')
->set('module',$mo);
}
$output .= View::factory('module/admin/list_footer');
$mo = ORM::factory('module');
Block::add(array(
'title'=>_('Currently installed modules'),
'body'=>$output,
));
'title'=>sprintf('%s: %s - %s',_('Email For'),$this->ao->accnum(),$this->ao->name(TRUE)),
'body'=>Table::display(
$mo->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>'admin/module/edit/'),
'name'=>array('label'=>'Name'),
'status'=>array('label'=>'Active'),
),
array(
'page'=>TRUE,
'type'=>'list',
)),
));
}
/**
* Edit a Module Configuration
*
* @param int $mid Module ID
* @todo Highlight those methods that have security, but the class does not have auth_required set to YES or the method isnt defined in secure_actions
*/
public function action_edit($mid) {
public function action_edit() {
$mid = $this->request->param('id');
$mo = ORM::factory('module',$mid);
if (! $mo->loaded()) {
@ -87,35 +90,42 @@ class Controller_Admin_Module extends Controller_TemplateDefault_Admin {
$methods = $this->_methods($mo->name);
// Show methods defined in the DB already.
$output .= View::factory('module/admin/method_list_header');
foreach ($mo->module_method->find_all() as $meo) {
Block::add(array(
'title'=>sprintf('%s: %s ',_('Defined Module Methods For'),$mo->display('name')),
'body'=>Table::display(
$mo->module_method->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>'admin/module_method/edit/'),
'name'=>array('label'=>'Name'),
'notes'=>array('label'=>'Notes'),
'menu_display'=>array('label'=>'Menu'),
),
array(
'page'=>TRUE,
'type'=>'list',
)),
));
// Show new methods NOT defined in the DB already.
foreach ($mo->module_method->find_all() as $meo)
if (($method = array_search($meo->name,$methods)) !== false)
unset($methods[$method]);
$output .= View::factory('module/admin/method_list_body')
->set('method',$meo)
->set('module',$mo)
->set('defined',$method !== false);
}
$output .= View::factory('module/admin/method_list_spacer');
// Show new methods NOT defined in the DB already.
foreach ($methods as $method) {
$meo = ORM::factory('module_method')
->values(array('name'=>$method,'notes'=>_('Not defined in DB')));
$output .= View::factory('module/admin/method_list_body')
->set('method',$meo)
->set('module',$mo)
->set('defined',$method === false);
}
$output .= View::factory('module/admin/method_list_footer');
Block::add(array(
'title'=>sprintf(_('%s Methods'),strtoupper($mo->name)),
'body'=>$output,
));
if (count($methods))
Block::add(array(
'title'=>sprintf('%s: %s ',_('Undefined Module Methods For'),$mo->display('name')),
'body'=>Table::display(
$methods,
25,
array(
'__VALUE__'=>array('label'=>'Name','url'=>sprintf('admin/module_method/add/%s/',$mo->id)),
),
array(
'page'=>TRUE,
'type'=>'list',
)),
));
}
}
?>

View File

@ -10,7 +10,7 @@
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_Admin_Module_Method extends Controller_Module {
class Controller_Admin_Module_Method extends Controller_Admin_Module {
/**
* Add a method to the database
*/
@ -63,7 +63,8 @@ class Controller_Admin_Module_Method extends Controller_Module {
*
* @param int $mid Module ID
*/
public function action_edit($mid) {
public function action_edit() {
$mid = $this->request->param('id');
$mmo = ORM::factory('module_method',$mid);
if (! $mmo->loaded()) {
@ -114,13 +115,13 @@ class Controller_Admin_Module_Method extends Controller_Module {
$output .= Form::open();
$output .= View::factory('module/admin/method_detail_header');
$output .= View::factory('module/admin/method_detail_head');
foreach ($groups->find_all() as $go) {
$output .= View::factory('module/admin/method_detail_body')
->set('group',$go)
->set('defined',$mmo->has('group',$go));
}
$output .= View::factory('module/admin/method_detail_footer');
$output .= View::factory('module/admin/method_detail_foot');
$output .= '<div>'.Form::submit('submit',_('Update')).'</div>';
$output .= Form::close();

View File

@ -1,4 +0,0 @@
<tr>
<td><a href="<?php echo URL::site(sprintf('/admin/module/edit/%s',$module->id)); ?>" alt=""><?php echo $module->name; ?></a></td>
<td><?php echo $module->display('status'); ?></td>
</tr>

View File

@ -1,6 +0,0 @@
<!-- //@todo Translation required -->
<table class="box-left">
<tr class="head">
<td>Module</td>
<td>Active</td>
</tr>

View File

@ -1,11 +0,0 @@
<tr>
<td>
<?php if ($defined) { ?>
<a href="<?php echo URL::site(sprintf('/admin/module_method/edit/%s',$method->id)); ?>" alt=""><?php echo $method->name; ?></a>
<?php } else { ?>
<a href="<?php echo URL::site(sprintf('/admin/module_method/add/%s/%s',$module->id,$method->name)); ?>" alt=""><?php echo $method->name; ?></a>
<?php } ?>
</td>
<td><?php echo $method->display('notes'); ?></td>
<td><?php echo $method->display('menu_display'); ?></td>
</tr>

View File

@ -1,7 +0,0 @@
<!-- //@todo Translation required -->
<table class="box-left">
<tr class="head">
<td>Method</td>
<td>Notes</td>
<td>Menu</td>
</tr>

View File

@ -1,3 +0,0 @@
<tr class="spacer">
<td>&nbsp;</td>
</tr>

View File

@ -20,9 +20,22 @@ class Controller_User_Payment extends Controller_TemplateDefault_User {
*/
public function action_list() {
Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Payments For'),$this->ao->accnum(),$this->ao->name(TRUE)),
'body'=>View::factory('payment/user/list')
->set('payments',$this->ao->payment->find_all()),
'title'=>sprintf('%s: %s - %s',_('Payments Received For'),$this->ao->accnum(),$this->ao->name(TRUE)),
'body'=>Table::display(
$this->ao->payment->find_all(),
25,
array(
'id'=>array('label'=>'ID'),
'date_payment'=>array('label'=>'Date'),
'checkout->display("name")'=>array('label'=>'Method'),
'total_amt'=>array('label'=>'Total','class'=>'right'),
'balance(TRUE)'=>array('label'=>'Balance','class'=>'right'),
'invoicelist()'=>array('label'=>'Invoices'),
),
array(
'page'=>TRUE,
'type'=>'list',
)),
));
}
}

View File

@ -1,21 +0,0 @@
<!-- @todo NEEDS TO BE TRANSLATED -->
<table class="box-left">
<tr>
<td class="head">ID</td>
<td class="head">Date</td>
<td class="head">Method</td>
<td class="head">Total</td>
<td class="head">Unallocated</td>
<td class="head">Invoices</td>
</tr>
<?php $i = 0; foreach ($payments as $po) { ?>
<tr class="<?php echo ++$i%2 ? 'odd' : 'even'; ?>">
<td><?php echo $po->id; ?></td>
<td><?php echo $po->display('date_payment'); ?></td>
<td><?php echo $po->checkout->display('name'); ?></td>
<td class="number"><?php echo $po->display('total_amt'); ?></td>
<td class="number"><?php echo $po->balance() ? '<b>'.$po->balance(TRUE).'</b>' : $po->balance(TRUE); ?></td>
<td class="number"><?php echo $po->invoicelist(); ?></td>
</tr>
<?php } ?>
</table>

View File

@ -14,12 +14,43 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
protected $control = array('Services'=>'services');
protected $secure_actions = array(
'list'=>TRUE,
'listbycheckout'=>TRUE,
'listadslbilling'=>TRUE,
'listadslservices'=>TRUE,
'listhspaservices'=>TRUE,
'update'=>TRUE,
);
/**
* Show a list of services
*/
public function action_list() {
$so = ORM::factory('service');
Block::add(array(
'title'=>_('System Customer Services'),
'body'=>Table::display(
$so->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
'type'=>array('label'=>'Type'),
'name()'=>array('label'=>'Details'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'active'=>array('label'=>'Active'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
),
array(
'page'=>TRUE,
'type'=>'select',
'form'=>'user/email/view',
)),
));
}
/**
* List all services by their default checkout method
*/

View File

@ -17,17 +17,43 @@ class Controller_User_Service extends Controller_TemplateDefault_User {
);
/**
* Show a product
* Show a list of services
*/
public function action_list() {
Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Services For'),$this->ao->accnum(),$this->ao->name(TRUE)),
'body'=>View::factory('service/user/list')
->set('services',$this->ao->service->find_all()),
'body'=>Table::display(
$this->ao->service->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
'type'=>array('label'=>'Type'),
'name()'=>array('label'=>'Details'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'active'=>array('label'=>'Active'),
),
array(
'page'=>TRUE,
'type'=>'select',
'form'=>'user/service/view',
)),
));
}
public function action_view($id) {
public function action_view() {
$output = '';
if (! $id = $this->request->param('id')) {
if (isset($_POST['id']) AND is_array($_POST['id']))
Table::post('service_view','id');
list($id,$output) = Table::page('service_view');
} else {
$id = $this->request->param('id');
}
$so = ORM::factory('service',$id);
if (! $so->loaded() OR ! Auth::instance()->authorised($so->account_id)) {
@ -35,10 +61,12 @@ class Controller_User_Service extends Controller_TemplateDefault_User {
return FALSE;
}
$output .= View::factory('service/user/view')
->set('so',$so);
Block::add(array(
'title'=>sprintf('%s: %s',$so->id(),$so->product->name()),
'body'=>View::factory('service/user/view')
->set('so',$so),
'body'=>$output,
));
}
}

View File

@ -1,21 +0,0 @@
<!-- @todo NEEDS TO BE TRANSLATED -->
<table class="box-left">
<tr>
<td class="head">ID</td>
<td class="head">Type</td>
<td class="head">Details</td>
<td class="head">Billing</td>
<td class="head">Price</td>
<td class="head">Active</td>
</tr>
<?php $i = 0; foreach ($services as $service) { ?>
<tr class="<?php echo ++$i%2 ? 'odd' : 'even'; ?>">
<td><?php echo HTML::anchor('user/service/view/'.$service->id,$service->id); ?></td>
<td><?php echo $service->display('type'); ?></td>
<td><?php echo $service->name(); ?></td>
<td><?php echo $service->display('recur_schedule');?></td>
<td><?php echo $service->display('price'); ?></td>
<td><?php echo $service->display('active'); ?></td>
</tr>
<?php } ?>
</table>