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