Revision 270 (by ahitrov, 2013/02/01 20:48:45) |
Coupon discounts workaround
|
<& "/contenido/components/header.msn" &>
<style>
<!--
.inverted td { font-weight:bold; color:white; background-color:#8093B0; }
.inverted td a { color:white; font-weight:bold; }
//-->
</style>
<% spacer( h=>10 ) %>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr valign="top">
<td width="35%">
<& /contenido/webshop/components/block_order_status_changer.msn &>
<& /contenido/webshop/components/block_coupons.msn, status => $cst &>
</td>
<td width="1%"> </td>
<td width="65%">
<fieldset>
<legend>Купоны со статусом "<span style="color:yellow"><% $current_status->[1] %></span>"</legend>
% if ( $total ) {
<div style="font-size:75%; font-family:Arial;">
<& /inc/pages_.msn, p=>$p, n=>$size, total=>$total, params=>\%filter_params, &>
<div style="height:5px"><spacer type="block" height="5"></div>
</div>
<& /contenido/webshop/components/coupon_browse.msn, documents => \@documents, columns => \@columns, filter => \%filter_params, status => $cst, %ARGS &>
<div style="font-size:75%; font-family:Arial;">
<& /inc/pages_.msn, p=>$p, n=>$size, total=>$total, params=>\%filter_params, &>
<div style="height:5px"><spacer type="block" height="5"></div>
</div>
% } else {
<h4 align="center"><i>---- Нет документов -----</i></h4>
% }
</td>
<td width="1%"> </td>
</tr>
</table>
</body>
</html>
<%args>
$cst => 1
$p => 1
$delete => undef
</%args>
<%init>
my %filter_params;
my (@documents, $total);
$filter_params{cst} = $cst if $cst != 1;
my $size = 40;
@documents = $keeper->get_documents(
class => 'webshop::Coupon',
status => $cst,
limit => $size,
offset => ($p-1)*$size,
order_by => 'dtime desc',
);
$total = $keeper->get_documents(
class => 'webshop::Coupon',
status => $cst,
count => 1,
);
my @structure = webshop::Coupon->new( $keeper->{webshop} )->structure;
my @columns = sort { $a->{column} <=> $b->{column} }
grep { $_->{column} } @structure;
push @columns, {attr => '_act_', rusname => 'Действия'};
my ($status_map) = grep { $_->{attr} eq 'status' } @structure;
my ($current_status) = grep { $_->[0] == $cst } @{$status_map->{cases}};
my $active_rights = $m->comp('/contenido/webshop/subs/user_rights.msn');
if ( !$active_rights && $delete ) {
my $return_params = join ('&', map { $_.'='.$filter_params{$_} } grep { $_ ne 's' } keys %filter_params );
my %deleted;
while ( my ($field, $value) = each %ARGS ) {
if ( $field =~ /^delete_(\d+)_(\w+)$/ ) {
my $oid = $1;
my $attr = $2;
$deleted{$oid}{$attr} = $value;
}
}
my %classes = map { $_->{class} => 1 } values %deleted;
foreach my $delete_class ( keys %classes ) {
my @ids;
while ( my ($oid, $attr) = each %deleted) {
push @ids, $oid if exists $attr->{id} && $attr->{id} && ($attr->{class} eq $delete_class);
}
my @objects = $keeper->get_documents (
id => \@ids,
class => $delete_class
) if @ids;
foreach my $object ( @objects ) {
my $document_access = $user->section_accesses($user, $object->section);
next unless $document_access == 2;
$object->delete;
}
}
$m->redirect("/contenido/webshop/".($return_params ? '?'.$return_params : ''));
}
</%init>