% if ( $show eq 'html' ) { <& "/contenido/components/title.msn", %ARGS &> % } % if ( $errstr ) { % if ( $show eq 'html' ) {

<% $errstr %>

% } else { % $m->out($errstr); % } % } else { % if ( $show eq 'html' ) {
Отобраны купоны
С даты: <% $from->dmy('.') %>
По дату: <% $to->dmy('.') %>
% if ( $status ) { Со статусом: <% $status_opts{$status} %>
% }
% } else { С даты <% $from->dmy('.') %> По дату <% $to->dmy('.') %> % if ( $status ) { Со статусом <% $status_opts{$status} %> % } % } % if ( @coupons ) { % if ( $show eq 'html' ) {
% } else { # Имя заказчика E-mail Тел. Сумма заказа Скидка Доставка Сумма общая Купоны % } % foreach my $coupon ( @coupons ) { % my $begin = Contenido::DateTime->new( postgres => $coupon->dtime ); % my $end = Contenido::DateTime->new( postgres => $coupon->etime ); % my $status = exists $status_opts{$coupon->status} ? $status_opts{$coupon->status} : 'неизвестный ('.$coupon->status.')'; % if ( $show eq 'html' ) { % } else { % $m->out( join ("\t", ($coupon->id, $coupon->name, $status, $begin->dmy('.'), $end->dmy('.'), $coupon->{order_amount}, $coupon->{sum_total}, $coupon->{discount_total}))."\t" ); % $m->out("\n"); % } % } % if ( $show eq 'html' ) {
# Название Статус Активен К-во заказов Сумма заказов Сумма скидки
  с     по  
contenido_status_style ? ' style="' . $coupon->contenido_status_style . '"' : '' %> class="<% $coupon->status ? '':'hiddensect' %>" href="/contenido/webshop/coupon.html?id=<% $coupon->id %>"><% $coupon->id %> contenido_status_style ? ' style="' . $coupon->contenido_status_style . '"' : '' %> class="<% $coupon->status ? '':'hiddensect' %>" href="/contenido/webshop/coupon.html?id=<% $coupon->id %>"><% $coupon->name %> <% $status %> <% $begin->dmy('.') %> <% $end->dmy('.') %> <% $coupon->{order_amount} %> <% $coupon->{sum_total} %> <% $coupon->{discount_total} %>
% } % } else { % if ( $show eq 'html' ) {

В данном диапазоне дат с учетом выбранных условий купоны не найдены

% } else { В данном диапазоне дат с учетом выбранных условий купоны не найдены % } % } % } % if ( $show eq 'html' ) { % } <%args> $show => 'html' $status => undef $from_day => undef $from_month => undef $from_year => undef $to_day => undef $to_month => undef $to_year => undef <%init> if ( $show eq 'html' ) { $r->content_type ("text/html; charset=utf-8"); } else { $r->content_type ("text/plain; charset=utf-8"); } my ($from, $to); my $errstr; my @props = webshop::Coupon->new( $keeper )->structure; my ($status_prop) = grep { $_->{attr} eq 'status' } @props; my %status_opts = map { $_->[0] => $_->[1] } @{$status_prop->{cases}}; my $now = Contenido::DateTime->new; if ( $from_day && $from_month && $from_year ) { eval { $from = Contenido::DateTime->new( datetime => { day => $from_day, month => $from_month, year => $from_year } ) }; } if ( $to_day && $to_month && $to_year ) { eval { $to = Contenido::DateTime->new( datetime => { day => $to_day, month => $to_month, year => $to_year } ) }; } $from = $now unless ref $from; $to = $now unless ref $to; if ( $from > $to ) { $errstr = 'Неверно указан диапазон дат'; } my %opts = ( interval => [$from->ymd, $to->ymd] ); if ( $status ) { $opts{status} = $status; } my @coupons; unless ( $errstr ) { @coupons = $keeper->get_documents( class => 'webshop::Coupon', %opts, order_by => 'etime desc', ); foreach my $coupon ( @coupons ) { my $orders = $keeper->get_documents( class => 'webshop::Order', lclass => 'webshop::OrderCouponLink', lsource => 'positive', ldest => $coupon->id, no_limit => 1, order_by => 'ctime desc', return_mode => 'array_ref', ); my ($sum, $discount) = (0,0); foreach my $order( @$orders ) { $sum += $order->sum; $discount += $order->sum_discount; } $coupon->{order_amount} = scalar @$orders; $coupon->{sum_total} = $sum; $coupon->{discount_total} = $discount; } }