summaryrefslogtreecommitdiff
path: root/httemplate/REST/1.0/rate_detail
blob: 6ae503190d2083f709e17e20ca917ef5f2ebc851 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<% encode_rest( \@rate_detail ) %>\
<%init>

rest_auth($cgi);

my $extra_sql = '';
if ( $cgi->param('countrycode') =~ /^\+?(\d+)$/ ) {
  my $countrycode = $1;
  $extra_sql = "
    WHERE EXISTS ( SELECT 1 FROM rate_region
                     WHERE rate_detail.dest_regionnum = rate_region.regionnum
                       AND countrycode = '$countrycode'
  ";
}

my @detail_fields = fields('rate_detail');
my @region_fields = fields('rate_region');

my @rate_detail =
  map {
    my $rate_detail = $_;
    my $rate_region = $rate_detail->dest_region;

    +{
      ( map { $_ => $rate_detail->$_ } @detail_fields ),
      ( map { $_ => $rate_region->$_ } @region_fields ),
     };

  } qsearch({
      'table'   => 'rate_detail',
      'hashref' => {},
      extra_sql => $extra_sql,
    });

</%init>