Line # Revision Author
1 422 ahitrov % if ( $show eq 'html' ) {
2 <& "/contenido/components/title.msn", %ARGS &>
3 % }
4
5 % if ( $errstr ) {
6 % if ( $show eq 'html' ) {
7 <p style="color:red;"><% $errstr %></p>
8 % } else {
9 % $m->out($errstr);
10 % }
11 % } else {
12 % if ( $show eq 'html' ) {
13 <fieldset>
14 <legend>Отобраны заказы</legend>
15 <table width="100%" cellspacing="5" cellpadding="0" class="tform">
16 <tr><td>
17 С даты: <b><% $from->dmy('.') %></b><br>
18 По дату: <b><% $to->dmy('.') %></b><br>
19 % if ( $status ) {
20 Со статусом: <b><% $status_opts{$status} %></b><br>
21 % }
22 % if ( $sort && exists $sorts{$sort} ) {
23 Сортировка <b><% $sorts{$sort}{name} %></b>
24 % }
25 </td></tr>
26 </table>
27 </fieldset>
28 % } else {
29 С даты <% $from->dmy('.') %>
30 По дату <% $to->dmy('.') %>
31 % if ( $status ) {
32 Со статусом <% $status_opts{$status} %>
33 % }
34 % if ( $sort && exists $sorts{$sort} ) {
35 Сортировка <% $sorts{$sort}{name} %>
36 % }
37 % }
38 % if ( @orders ) {
39 % if ( $show eq 'html' ) {
40 <div style="padding:10px;">
41 <table border="0" cellpadding="4" cellspacing="0" class="tlistdocs">
42 <tr>
43 <th>#</th>
44 <th>Имя заказчика</th>
45 <th>E-mail</th>
46 <th>Тел.</th>
47 <th>Сумма заказа</th>
48 <th>Скидка</th>
49 <th>Доставка</th>
50 <th>Сумма общая</th>
51 <th>Купоны</th>
52 </tr>
53 % } else {
54 # Имя заказчика E-mail Тел. Сумма заказа Скидка Доставка Сумма общая Купоны
55 % }
56 % foreach my $order ( @orders ) {
57 % my $profile = $order->{profile};
58 % my $coupons = $order->{coupons};
59 % if ( $show eq 'html' ) {
60 <tr>
61 <td><% $order->id %></td>
62 <td><% $order->name %></td>
63 <td><% $order->email %></td>
64 <td><% $order->phone %></td>
65 <td><% $order->sum %></td>
66 <td><% $order->sum_discount %></td>
67 <td><% $order->sum_delivery %></td>
68 <td><% $order->sum_total %></td>
69 <td>
70 % if ( ref $coupons eq 'ARRAY'&& @$coupons ) {
71 % foreach my $coupon ( @$coupons ) {
72 <% $coupon->name %><br>
73 % }
74 % }
75 </td>
76 </tr>
77 % } else {
78 % $m->out( join ("\t", ($order->id, $order->name, $order->email, $order->phone, $order->sum, $order->sum_discount, $order->sum_delivery, $order->sum_total))."\t" );
79 % if ( ref $coupons eq 'ARRAY'&& @$coupons ) {
80 % my $str = join ', ', map { my $name = $_->name; $name =~ s/\t/\ /g; $name } @$coupons;
81 % $m->out( $str );
82 % }
83 % $m->out("\n");
84 % }
85 % }
86 % if ( $show eq 'html' ) {
87 </table>
88 </div>
89 % }
90 % } else {
91 % if ( $show eq 'html' ) {
92 <p>В данном диапазоне дат с учетом выбранных условий заказы не найдены</p>
93 % } else {
94 В данном диапазоне дат с учетом выбранных условий заказы не найдены
95 % }
96 % }
97 % }
98 % if ( $show eq 'html' ) {
99 </body>
100 </html>
101 % }
102 <%once>
103
104 my %sorts = (
105 'id' => { name => 'по номеру заказа', order_by => 'id' },
106 'uid' => { name => 'по пользователю', order_by => 'name, uid' },
107 );
108
109 </%once>
110 <%args>
111
112 $status => undef
113 $sort => undef
114 $show => 'html'
115
116 $from_day => undef
117 $from_month => undef
118 $from_year => undef
119
120 $to_day => undef
121 $to_month => undef
122 $to_year => undef
123
124 </%args>
125 <%init>
126
127 if ( $show eq 'html' ) {
128 $r->content_type ("text/html; charset=utf-8");
129 } else {
130 $r->content_type ("text/plain; charset=utf-8");
131 }
132 my ($from, $to);
133
134 my $errstr;
135 my @props = webshop::Order->new( $keeper )->structure;
136 my ($status_prop) = grep { $_->{attr} eq 'status' } @props;
137 my %status_opts = map { $_->[0] => $_->[1] } @{$status_prop->{cases}};
138 my $now = Contenido::DateTime->new;
139 if ( $from_day && $from_month && $from_year ) {
140 eval { $from = Contenido::DateTime->new( datetime => { day => $from_day, month => $from_month, year => $from_year } ) };
141 }
142 if ( $to_day && $to_month && $to_year ) {
143 eval { $to = Contenido::DateTime->new( datetime => { day => $to_day, month => $to_month, year => $to_year } ) };
144 }
145 $from = $now unless ref $from;
146 $to = $now unless ref $to;
147 if ( $from > $to ) {
148 $errstr = 'Неверно указан диапазон дат';
149 }
150 my %opts = ( date => [$from->ymd, $to->ymd] );
151 if ( $status ) {
152 $opts{status} = $status;
153 }
154 if ( $sort && exists $sorts{$sort} ) {
155 $opts{order_by} = $sorts{$sort}{order_by};
156 }
157 my @orders;
158 unless ( $errstr ) {
159 @orders = $keeper->get_documents(
160 class => 'webshop::Order',
161 %opts
162 );
163 if ( @orders ) {
164 my %uids = map { $_->uid => 1 } @orders;
165 my @uids = keys %uids;
166 my $profiles = @uids ? $keeper->get_documents(
167 id => \@uids,
168 class => $state->{users}->profile_document_class,
169 return_mode => 'hash_ref',
170 ) : {};
171 foreach my $order ( @orders ) {
172 $order->{profile} = exists $profiles->{$order->uid} ? $profiles->{$order->uid} : undef;
173 if ( $order->sum_discount ) {
174 my @coupons = $keeper->get_documents(
175 class => 'webshop::Coupon',
176 lclass => 'webshop::OrderCouponLink',
177 lsource => $order->id,
178 );
179 $order->{coupons} = \@coupons;
180 }
181 }
182 }
183 }
184
185 </%init>