Minor fixes to statement, services and internal things
Many misc updates
This commit is contained in:
@@ -50,74 +50,77 @@ class Controller_Affiliate_Service extends Controller_TemplateDefault_Affiliate
|
||||
* 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
|
||||
// @todo need to restrict this to affiliate services
|
||||
$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 ($this->filter($ao->service->list_active(),$this->ao->affiliate->id,'name()') as $so)
|
||||
if (! $so->service_billing->checkout_plugin_id)
|
||||
array_push($svs,$so);
|
||||
|
||||
$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,
|
||||
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',
|
||||
)),
|
||||
));
|
||||
else
|
||||
Block::add(array(
|
||||
'title'=>'Services that should be auto-billed',
|
||||
'body'=>_('None found'),
|
||||
));
|
||||
|
||||
Style::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'css/list.css',
|
||||
));
|
||||
foreach (ORM::factory('checkout')->where('active','=',1)->find_all() as $co) {
|
||||
$svs = array();
|
||||
|
||||
foreach ($co->account->find_all() as $ao)
|
||||
foreach ($this->filter($ao->service->list_active(),$this->ao->affiliate->id,'name()') 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',
|
||||
)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private function consoltraffic($svs,$date) {
|
||||
|
Reference in New Issue
Block a user