2011-09-26 10:12:54 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides OSB exporting capabilities.
|
|
|
|
*
|
2013-03-19 22:35:19 +00:00
|
|
|
* @package Export
|
2011-09-26 10:12:54 +00:00
|
|
|
* @category Controllers/Affiliate
|
|
|
|
* @author Deon George
|
2013-03-19 22:35:19 +00:00
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
2011-09-26 10:12:54 +00:00
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
|
|
|
class Controller_Affiliate_Export extends Controller_TemplateDefault_Affiliate {
|
|
|
|
protected $control_title = 'Export';
|
|
|
|
protected $secure_actions = array(
|
|
|
|
'index'=>TRUE,
|
|
|
|
'export'=>TRUE,
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Export plugins must define an export action.
|
|
|
|
*/
|
|
|
|
public function action_export() {
|
|
|
|
if (empty($_POST['plugin']))
|
2011-10-14 05:44:12 +00:00
|
|
|
$this->request->redirect('affiliate/export/index');
|
2011-09-26 10:12:54 +00:00
|
|
|
|
2012-11-09 23:13:57 +00:00
|
|
|
$sc = sprintf('Export_%s',ucfirst($_POST['plugin']));
|
2011-09-26 10:12:54 +00:00
|
|
|
if (! class_exists($sc))
|
|
|
|
throw new Kohana_Exception('Export Class doesnt exist for :plugin',array(':plugin'=>$_POST['plugin']));
|
|
|
|
else
|
|
|
|
$export = new $sc;
|
|
|
|
|
|
|
|
// @todo: Need to limit this to affiliate acounts
|
|
|
|
$export->export();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the main call to export, providing a list of items to export and
|
|
|
|
* setting up the page to call the export plugin when submitted.
|
|
|
|
*/
|
2011-10-14 05:44:12 +00:00
|
|
|
public function action_index() {
|
2011-09-26 10:12:54 +00:00
|
|
|
// @todo this should come from a file list
|
|
|
|
$TBRexportplugins = array('quicken'=>'Export to Quicken');
|
|
|
|
|
|
|
|
// @todo: Need to limit this to affiliate acounts
|
2012-11-09 23:13:57 +00:00
|
|
|
$p = ORM::factory('Payment');
|
2011-09-26 10:12:54 +00:00
|
|
|
|
2011-10-14 05:44:12 +00:00
|
|
|
if ($p->find_all()->count()) {
|
2011-09-26 10:12:54 +00:00
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('Payments to Export'),
|
2011-10-14 05:44:12 +00:00
|
|
|
'body'=>Table::display(
|
|
|
|
$p->find_all(),
|
|
|
|
25,
|
|
|
|
array(
|
|
|
|
'id'=>array('label'=>'ID'),
|
|
|
|
'date_payment'=>array('label'=>'Date'),
|
|
|
|
'checkout->display("name")'=>array('label'=>'Method'),
|
|
|
|
'account->accnum()'=>array('label'=>'Acc Num'),
|
|
|
|
'account->name()'=>array('label'=>'Account'),
|
|
|
|
'total_amt'=>array('label'=>'Total','class'=>'right'),
|
|
|
|
'balance(TRUE)'=>array('label'=>'Balance','class'=>'right'),
|
|
|
|
'invoicelist()'=>array('label'=>'Invoices'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'page'=>TRUE,
|
|
|
|
'type'=>'select',
|
|
|
|
'form'=>'affiliate/export/export',
|
|
|
|
'hidden'=>array(
|
|
|
|
Form::hidden('plugin','quicken'),
|
|
|
|
),
|
|
|
|
'button'=>array(
|
|
|
|
Form::submit('submit',_('Export'),array('class'=>'form_button')),
|
|
|
|
),
|
|
|
|
)),
|
2011-09-26 10:12:54 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
# Nothing to export
|
|
|
|
} else {
|
|
|
|
SystemMessage::add(array(
|
|
|
|
'title'=>_('No payments to export'),
|
|
|
|
'type'=>'info',
|
|
|
|
'body'=>sprintf(_('There are no payments within the last %s days (since %s) to show.'),
|
2012-11-09 23:13:57 +00:00
|
|
|
$daysago,date(Kohana::$config->load('osb')->date_format,$daysago*86400+time())),
|
2011-09-26 10:12:54 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|