select only one billing_mapping per contract

select the billing_mapping which has an start_date and end_date closest
to the current time. do not select one that does not match the current time.

also prevent db error about multiple id columns by using 'me.id' in
the root controller
agranig/1_0_subfix
Gerhard Jungwirth 13 years ago
parent bb0d585418
commit 8d43a6ae92

@ -7,7 +7,34 @@ use NGCP::Panel::Utils;
sub contract_list :Chained('/') :PathPart('contract') :CaptureArgs(0) {
my ($self, $c) = @_;
my $mapping_rs = $c->model('billing')->resultset('billing_mappings');
my $rs = $c->model('billing')->resultset('contracts')
->search({
'billing_mappings.id' => {
'=' => $mapping_rs->search({
contract_id => { -ident => 'me.id' },
start_date => [ -or =>
{ '<=' => {-ident => 'now()'}},
{ -is => undef },
],
end_date => [ -or =>
{ '>=' => {-ident => 'now()'}},
{ -is => undef },
],
},{
alias => 'sub_query',
rows => 1,
order_by => {-desc => ['start_date', 'id']},
})->get_column('id')->as_query,
},
},{
'join' => 'billing_mappings',
'+select' => 'billing_mappings.billing_profile_id',
'+as' => 'billing_profile',
});
$c->stash(contract_select_rs => $rs);
$c->stash(ajax_uri => $c->uri_for_action("/contract/ajax"));
$c->stash(template => 'contract/list.tt');
@ -118,12 +145,7 @@ sub delete :Chained('base') :PathPart('delete') :Args(0) {
sub ajax :Chained('contract_list') :PathPart('ajax') :Args(0) {
my ($self, $c) = @_;
my $rs = $c->model('billing')->resultset('contracts')
->search(undef, {
'join' => 'billing_mappings',
'+select' => 'billing_mappings.billing_profile_id',
'+as' => 'billing_profile',
});
my $rs = $c->stash->{contract_select_rs};
$c->forward( "/ajax_process_resultset", [$rs,
["id","contact_id","billing_profile","status"],
@ -145,13 +167,11 @@ sub peering_root :Chained('peering_list') :PathPart('') :Args(0) {
sub peering_ajax :Chained('peering_list') :PathPart('ajax') :Args(0) {
my ($self, $c) = @_;
my $rs = $c->model('billing')->resultset('contracts')
->search({
my $base_rs = $c->stash->{contract_select_rs};
my $rs = $base_rs->search({
'product.class' => 'sippeering',
}, {
'join' => {'billing_mappings' => 'product'},
'+select' => 'billing_mappings.billing_profile_id',
'+as' => 'billing_profile',
});
$c->forward( "/ajax_process_resultset", [$rs,

@ -161,6 +161,8 @@ sub ajax_process_resultset :Private {
my @searchdata = map{ +{ $_ => { like => '%'.$sSearch.'%' } } } @$columns[@$searchable];
$rs = $rs->search(\@searchdata);
my $totalDisplayRecords = $rs->count;
#potentially selected Id as first element
if (defined($iIdOnTop)) {
my $topRow = $rs->find($iIdOnTop);
@ -169,7 +171,7 @@ sub ajax_process_resultset :Private {
my @tmpTopRowArray = @tmpTopRow{@$columns};
push @$aaData, \@tmpTopRowArray;
$rs = $rs->search({ id => { '!=', $iIdOnTop}});
$rs = $rs->search({ 'me.id' => { '!=', $iIdOnTop}});
}
}
@ -182,8 +184,6 @@ sub ajax_process_resultset :Private {
$rs = $rs->search(undef, $sortdata);
}
my $totalDisplayRecords = $rs->count;
#Pagination
if (defined($iDisplayStart) && $iDisplayLength) {
$rs = $rs->search(

Loading…
Cancel
Save