Minor fixes to statement, services and internal things
Many misc updates
This commit is contained in:
@@ -12,17 +12,38 @@
|
||||
*/
|
||||
class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
|
||||
protected $secure_actions = array(
|
||||
'autolist'=>FALSE, // @todo To Change
|
||||
'list'=>TRUE,
|
||||
'listbycheckout'=>TRUE,
|
||||
'listadslbilling'=>TRUE,
|
||||
'listadslservices'=>TRUE,
|
||||
'listdomainservices'=>TRUE,
|
||||
'listdomainservicesbysupplier'=>TRUE,
|
||||
'listhostservices'=>TRUE,
|
||||
'listhspaservices'=>TRUE,
|
||||
'listinvoicesoon'=>TRUE,
|
||||
'update'=>TRUE,
|
||||
);
|
||||
|
||||
public function action_autolist() {
|
||||
$return = array();
|
||||
|
||||
$s = ORM::factory('service')->where('active','=',1);
|
||||
if (isset($_REQUEST['aid']))
|
||||
$s = $s->where('account_id','=',$_REQUEST['aid']);
|
||||
|
||||
// @todo This should limit the results so that users dont see other users services.
|
||||
foreach ($s->find_all() as $so)
|
||||
array_push($return,array(
|
||||
'value'=>$so->id,
|
||||
'text'=>sprintf('%s: %s',$so->id,$so->service_name()),
|
||||
));
|
||||
|
||||
$this->auto_render = FALSE;
|
||||
$this->response->headers('Content-Type','application/json');
|
||||
$this->response->body(json_encode($return));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a list of services
|
||||
*/
|
||||
@@ -53,73 +74,72 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
|
||||
* List all services by their default checkout method
|
||||
*/
|
||||
public function action_listbycheckout() {
|
||||
// @todo need to add the DB prefix here
|
||||
// @todo need to remove the explicit references to the group_id
|
||||
$services = DB::query(Database::SELECT,'
|
||||
SELECT c.id AS cid,c.name as checkout_plugin_name,s.id AS sid,a.company,a.first_name,a.last_name,a.id as aid
|
||||
FROM ab_service s LEFT JOIN ab_account_billing ab ON (s.account_billing_id=ab.id) LEFT JOIN ab_checkout c ON (ab.checkout_plugin_id=c.id),ab_account a, ab_account_group ag
|
||||
WHERE s.active=1 AND s.price > 0 AND s.account_id=a.id AND a.id=ag.account_id AND ((s.account_billing_id IS NOT NULL AND ag.group_id!=2 ) OR (a.id=ag.account_id and ag.group_id=1003))
|
||||
ORDER BY c.id,s.recur_schedule,c.name,a.company,a.last_name,a.first_name
|
||||
')
|
||||
->execute();
|
||||
$svs = array();
|
||||
// @todo This needs to be configurable
|
||||
$go = ORM::factory('group',array('name'=>'Personal'));
|
||||
|
||||
// @todo If no items, show a nice message. This is not correct for ORM.
|
||||
if (! count($services)) {
|
||||
echo Kohana::debug('No services with account_billing');
|
||||
die();
|
||||
foreach (ORM::factory('account')->where('status','=',1)->find_all() as $ao)
|
||||
if ($ao->has_any('group',array($go)))
|
||||
foreach ($ao->service->list_active() as $so)
|
||||
if (! $so->service_billing->checkout_plugin_id)
|
||||
array_push($svs,$so);
|
||||
|
||||
if ($svs)
|
||||
Block::add(array(
|
||||
'title'=>'Services that should be auto-billed',
|
||||
'body'=>Table::display(
|
||||
$svs,
|
||||
25,
|
||||
array(
|
||||
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
|
||||
'service_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'),
|
||||
'date_next_invoice'=>array('label'=>'Next Invoice'),
|
||||
'account->invoices_due_total(NULL,TRUE)'=>array('label'=>'Due Invoices'),
|
||||
),
|
||||
array(
|
||||
'page'=>TRUE,
|
||||
'type'=>'select',
|
||||
'form'=>'user/service/view',
|
||||
)),
|
||||
));
|
||||
|
||||
foreach (ORM::factory('checkout')->where('active','=',1)->find_all() as $co) {
|
||||
$svs = array();
|
||||
|
||||
foreach ($co->account->find_all() as $ao)
|
||||
foreach ($ao->service->list_active() as $so)
|
||||
if ($so->service_billing->checkout_plugin_id == $co->id)
|
||||
array_push($svs,$so);
|
||||
|
||||
if ($svs)
|
||||
Block::add(array(
|
||||
'title'=>$co->name,
|
||||
'body'=>Table::display(
|
||||
$svs,
|
||||
25,
|
||||
array(
|
||||
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
|
||||
'service_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'),
|
||||
'date_next_invoice'=>array('label'=>'Next Invoice'),
|
||||
'account->invoices_due_total(NULL,TRUE)'=>array('label'=>'Due Invoices'),
|
||||
),
|
||||
array(
|
||||
'page'=>TRUE,
|
||||
'type'=>'select',
|
||||
'form'=>'user/service/view',
|
||||
)),
|
||||
));
|
||||
}
|
||||
|
||||
$last_checkout = '';
|
||||
$last_account = '';
|
||||
$i = 0;
|
||||
$sc = $st = 0;
|
||||
$output = '<table class="box-left">';
|
||||
foreach ($services as $service) {
|
||||
$so = ORM::factory('service',$service['sid']);
|
||||
$si = $so->account_id.$so->recur_schedule;
|
||||
|
||||
if (($si != $last_account) AND $last_account) {
|
||||
if ($sc > 1)
|
||||
$output .= View::factory('service/admin/list/bycheckout_subtotal')
|
||||
->set('subtotal',Currency::display($st))
|
||||
->set('i',$i++%2);
|
||||
$sc = $st = 0;
|
||||
}
|
||||
|
||||
if (($service['cid'] != $last_checkout) OR (! is_null($last_checkout) AND ! $last_checkout)) {
|
||||
$output .= View::factory('service/admin/list/bycheckout_header')
|
||||
->set('checkout_name',$service['checkout_plugin_name'])
|
||||
->set('last_checkout',$last_checkout);
|
||||
}
|
||||
|
||||
$last_checkout = $service['cid'];
|
||||
$last_account = $si;
|
||||
// @todo This rounding should be a system default
|
||||
$st += round($so->price+$so->tax(),2);
|
||||
$sc++;
|
||||
|
||||
$output .= View::factory('service/admin/list/bycheckout_body')
|
||||
->set('service',$so)
|
||||
->set('i',$i++%2);
|
||||
}
|
||||
|
||||
// Last subtotal
|
||||
if ($sc > 1)
|
||||
$output .= View::factory('service/admin/list/bycheckout_subtotal')
|
||||
->set('subtotal',$st)
|
||||
->set('i',$i++%2);
|
||||
|
||||
$output .= '</table>';
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('List all Services by Default Payment Method'),
|
||||
'body'=>$output,
|
||||
));
|
||||
|
||||
Style::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'css/list.css',
|
||||
));
|
||||
}
|
||||
|
||||
private function consoltraffic($svs,$date) {
|
||||
@@ -255,6 +275,39 @@ ORDER BY c.id,s.recur_schedule,c.name,a.company,a.last_name,a.first_name
|
||||
));
|
||||
}
|
||||
|
||||
public function action_listdomainservicesbysupplier() {
|
||||
$svs = ORM::factory('service')->list_bylistgroup('DOMAIN');
|
||||
Sort::MAsort($svs,'plugin()->domain_registrar_id,name()');
|
||||
|
||||
$list = array();
|
||||
|
||||
foreach ($svs as $so)
|
||||
$list[$so->plugin()->domain_registrar_id][] = $so;
|
||||
|
||||
foreach (array_keys($list) as $sid)
|
||||
Block::add(array(
|
||||
'title'=>sprintf(_('Domain Names by Supplier %s'),$sid),
|
||||
'body'=>Table::display(
|
||||
$list[$sid],
|
||||
25,
|
||||
array(
|
||||
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
|
||||
'service_name()'=>array('label'=>'Details'),
|
||||
'plugin()->display("domain_expire")'=>array('label'=>'Expire'),
|
||||
'recur_schedule'=>array('label'=>'Billing'),
|
||||
'price'=>array('label'=>'Price','class'=>'right'),
|
||||
'account->accnum()'=>array('label'=>'Cust ID'),
|
||||
'account->name()'=>array('label'=>'Customer'),
|
||||
'display("date_next_invoice")'=>array('label'=>'Next Invoice'),
|
||||
),
|
||||
array(
|
||||
'page'=>TRUE,
|
||||
'type'=>'select',
|
||||
'form'=>'user/service/view',
|
||||
)),
|
||||
));
|
||||
}
|
||||
|
||||
public function action_listhostservices() {
|
||||
$svs = ORM::factory('service')->list_bylistgroup('HOST');
|
||||
Sort::MAsort($svs,'name()');
|
||||
@@ -298,7 +351,7 @@ ORDER BY c.id,s.recur_schedule,c.name,a.company,a.last_name,a.first_name
|
||||
->rule('csv','Upload::type',array(':value',array('csv')))
|
||||
->rule('csv','Upload::size',array(':value','10M'));
|
||||
|
||||
if ($files->check())
|
||||
if ($files->check())
|
||||
foreach ($files as $file)
|
||||
$csv = $this->process($file);
|
||||
}
|
||||
@@ -318,7 +371,7 @@ ORDER BY c.id,s.recur_schedule,c.name,a.company,a.last_name,a.first_name
|
||||
|
||||
// If our uploaded file has some cost data.
|
||||
if (! empty($csv[$so->plugin()->service_number])) {
|
||||
$uploaded['amount'] =
|
||||
$uploaded['amount'] =
|
||||
(empty($csv[$so->plugin()->service_number]['cost']) ? 0 : $csv[$so->plugin()->service_number]['cost']) +
|
||||
(empty($csv[$so->plugin()->service_number]['credit']) ? 0 : $csv[$so->plugin()->service_number]['credit']);
|
||||
|
||||
|
Reference in New Issue
Block a user