Overhauled export, and other minor updates
This commit is contained in:
@@ -9,51 +9,123 @@
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_Admin_Export extends Controller_TemplateDefault_Admin {
|
||||
protected $control_title = 'Export';
|
||||
class Controller_Admin_Export extends Controller_Export {
|
||||
protected $secure_actions = array(
|
||||
'add'=>TRUE,
|
||||
'edit'=>TRUE,
|
||||
'index'=>TRUE,
|
||||
'module'=>TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Add Export Maping items
|
||||
*/
|
||||
public function action_add() {
|
||||
$eo = ORM::factory('Export');
|
||||
$output = '';
|
||||
if (empty($_POST['export_module_id']) OR empty($_POST['module_id']))
|
||||
HTTP::redirect(URL::link('admin','export/index'));
|
||||
|
||||
if ($_POST AND $eo->values($_POST)->check()) {
|
||||
$eo->module_id = ORM::factory('Module',array('name'=>'product'))->id; // @todo This probably should be in the form.
|
||||
$eo->plugin_name = 'quicken'; // @todo This should be in the form.
|
||||
// Entry updated
|
||||
if (! $eo->save())
|
||||
throw new Kohana_Exception('Unable to save data :post',array(':post'=>serialize($_POST)));
|
||||
$edo = ORM::factory('Export_DataMap');
|
||||
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Record add'),
|
||||
'type'=>'info',
|
||||
'body'=>_('Export Map entry added.')
|
||||
));
|
||||
if ($_POST AND isset($_POST['item_id']) AND $edo->values($_POST)->check()) {
|
||||
$edo->status = 1;
|
||||
|
||||
if (! $edo->save())
|
||||
throw HTTP_Exception::factory(501,'Unable to save data :post',array(':post'=>serialize($_POST)));
|
||||
|
||||
SystemMessage::factory()
|
||||
->title('Record added')
|
||||
->type('success')
|
||||
->body(_('Export DataMap record has been added.'));
|
||||
}
|
||||
|
||||
$output .= Form::open();
|
||||
$output .= View::factory($this->viewpath())
|
||||
->set('eo',$eo);
|
||||
|
||||
$output .= '<div>'.Form::submit('submit',_('Add'),array('class'=>'form_button')).'</div>';
|
||||
$output .= Form::close();
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Add Export Map'),
|
||||
'body'=>$output,
|
||||
));
|
||||
Block::factory()
|
||||
->title('Add Export Item Map')
|
||||
->title_icon('icon-plus-sign')
|
||||
->type('form-horizontal')
|
||||
->body(View::factory('export/admin/add')
|
||||
->set('o',$edo)
|
||||
->set('emo',ORM::factory('Export_Module',$_POST['export_module_id']))
|
||||
->set('module',ORM::factory('Module',$_POST['module_id'])->module()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit Export Maping items
|
||||
* Select our primary export target
|
||||
*/
|
||||
public function action_edit() {
|
||||
public function action_index() {
|
||||
$output = '';
|
||||
|
||||
if ($_POST and isset($_POST['eid'])) {
|
||||
$select = array();
|
||||
foreach (ORM::factory('Export_Module')->where('export_id','=',$_POST['eid'])->find_all() as $emo)
|
||||
$select[$emo->id] = $emo->module->name;
|
||||
|
||||
$output .= Form::open(URL::link('admin','export/add'));
|
||||
$output .= Form::select('export_module_id',$select);
|
||||
$output .= Form::button('submit','Submit',array('class'=>'btn btn-primary'));
|
||||
|
||||
// @todo This shouldnt be hard coded.
|
||||
$output .= Form::hidden('module_id',ORM::factory('Product')->mid());
|
||||
|
||||
} else {
|
||||
|
||||
$output .= Form::open();
|
||||
$output .= Form::select('eid',ORM::factory('Export')->list_select());
|
||||
$output .= Form::button('submit','Submit',array('class'=>'btn btn-primary'));
|
||||
}
|
||||
|
||||
$output .= Form::close();
|
||||
|
||||
Block::factory()
|
||||
->title('Select Export Target')
|
||||
->title_icon('icon-share')
|
||||
->body($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the export module settings
|
||||
*/
|
||||
public function action_module() {
|
||||
if ($_POST AND isset($_POST['export_module_id'])) {
|
||||
$emo = ORM::factory('Export_Module',$_POST['export_module_id']);
|
||||
|
||||
if ($emo->loaded()) {
|
||||
$emo->values($_POST);
|
||||
$emo->save();
|
||||
|
||||
if ($emo->saved())
|
||||
SystemMessage::factory()
|
||||
->title('Record updated')
|
||||
->type('success')
|
||||
->body(_('Export Module record has been updated.'));
|
||||
}
|
||||
}
|
||||
|
||||
if ($x = $this->request->param('id')) {
|
||||
$emo = ORM::factory('Export_Module',$x);
|
||||
|
||||
if ($emo->loaded())
|
||||
Block::factory()
|
||||
->title(sprintf('Export Module: %s for %s',$emo->module->display('name'),$emo->export->display('name')))
|
||||
->title_icon('icon-wrench')
|
||||
->type('form-horizontal')
|
||||
->body(View::factory('export/module/admin/edit')->set('o',$emo));
|
||||
|
||||
} else {
|
||||
Block::factory()
|
||||
->title('Export Module Update')
|
||||
->title_icon('icon-th-list')
|
||||
->body(Table::factory()
|
||||
->data(ORM::factory('Export_Module')->find_all())
|
||||
->jssort(TRUE)
|
||||
->columns(array(
|
||||
'id'=>'ID',
|
||||
'export->name'=>'Name',
|
||||
'module->name'=>'Module'
|
||||
))
|
||||
->prepend(array(
|
||||
'id'=>array('url'=>URL::link('admin','export/module/')),
|
||||
))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -1,87 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides OSB exporting capabilities.
|
||||
*
|
||||
* @package Export
|
||||
* @category Controllers/Affiliate
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @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']))
|
||||
$this->request->redirect('affiliate/export/index');
|
||||
|
||||
$sc = Kohana::classname('Export_'.$_POST['plugin']);
|
||||
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.
|
||||
*/
|
||||
public function action_index() {
|
||||
// @todo this should come from a file list
|
||||
$TBRexportplugins = array('quicken'=>'Export to Quicken');
|
||||
|
||||
// @todo: Need to limit this to affiliate acounts
|
||||
$p = ORM::factory('Payment');
|
||||
|
||||
if ($p->find_all()->count()) {
|
||||
Block::add(array(
|
||||
'title'=>_('Payments to Export'),
|
||||
'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')),
|
||||
),
|
||||
)),
|
||||
));
|
||||
|
||||
# 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.'),
|
||||
$daysago,date(Kohana::$config->load('osb')->date_format,$daysago*86400+time())),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
104
modules/export/classes/Controller/Reseller/Export.php
Normal file
104
modules/export/classes/Controller/Reseller/Export.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides OSB exporting capabilities.
|
||||
*
|
||||
* @package Export
|
||||
* @category Controllers/Reseller
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_Reseller_Export extends Controller_Export {
|
||||
protected $secure_actions = array(
|
||||
'export'=>TRUE,
|
||||
'index'=>TRUE,
|
||||
'list'=>TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Export plugins must define an export action.
|
||||
*/
|
||||
public function action_export() {
|
||||
$this->auto_render = FALSE;
|
||||
|
||||
if (empty($_POST['export_module_id']) OR ! ($emo = ORM::factory('Export_Module',$_POST['export_module_id'])) OR ! $emo->loaded())
|
||||
HTTP::redirect(URL::link('reseller','export/index'));
|
||||
|
||||
$emo->export->plugin($emo)->export($this->response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Select our primary export target
|
||||
*/
|
||||
public function action_index() {
|
||||
$output = '';
|
||||
|
||||
$output .= Form::open(URL::link('reseller','export/list'));
|
||||
$output .= Form::select('eid',ORM::factory('Export')->list_select());
|
||||
$output .= Form::button('submit','Submit',array('class'=>'btn btn-primary'));
|
||||
$output .= Form::close();
|
||||
|
||||
Block::factory()
|
||||
->title('Select Export Target')
|
||||
->title_icon('icon-share')
|
||||
->body($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function action_list() {
|
||||
if (empty($_POST['eid']))
|
||||
HTTP::redirect(URL::link('reseller','export/index'));
|
||||
|
||||
$eo = ORM::factory('Export',$_POST['eid']);
|
||||
|
||||
if (! $eo->loaded())
|
||||
HTTP::redirect(URL::link('reseller','export/index'));
|
||||
|
||||
$c = 0;
|
||||
|
||||
$output = '<div class="tabbable span11">';
|
||||
|
||||
$output .= '<ul class="nav nav-tabs">';
|
||||
// @todo To limit to Reseller accounts only
|
||||
foreach ($eo->export_module->find_all() as $emo)
|
||||
$output .= sprintf('<li class="%s"><a href="#tab%s" data-toggle="tab">%s</a></li>',$c++ ? '' : 'active',$emo->id,ucfirst($emo->module->module()->object_name()));
|
||||
$output .= '</ul>';
|
||||
|
||||
$c = 0;
|
||||
$output .= '<div class="tab-content">';
|
||||
foreach ($eo->export_module->find_all() as $emo) {
|
||||
$output .= sprintf('<div class="tab-pane %s" id="tab%s">',$c++ ? '' : 'active',$emo->id);
|
||||
|
||||
$output .= Table::factory()
|
||||
->data($emo->list_export())
|
||||
->jssort($emo->id)
|
||||
->columns(Arr::merge(array(
|
||||
'id'=>'ID',
|
||||
'account->name(TRUE)'=>'Account',
|
||||
'date_orig'=>'Date',
|
||||
'status(TRUE)'=>'Active',
|
||||
'total(TRUE)'=>'Total',
|
||||
'exported'=>'Exported',
|
||||
),$emo->display ? $emo->display : array()))
|
||||
->select(URL::link('reseller','export/export'),$emo->id,array('export_module_id'=>$emo->id))
|
||||
->prepend(array(
|
||||
'id'=>array('checkbox'=>'id[]'),
|
||||
))->filters(array(
|
||||
'exported'=>array(array('Config::date',array(':value'))),
|
||||
));
|
||||
|
||||
$output .= '</div>';
|
||||
}
|
||||
$output .= '</div>';
|
||||
|
||||
Block::factory()
|
||||
->title('Export Transactions')
|
||||
->title_icon('icon-share')
|
||||
->body($output);
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user