Revision 628 (by ahitrov, 2016/11/30 22:04:11) Find order by id

<& "/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_company_filter.msn, value => $company_filter_value &>
<& /contenido/webshop/components/block_order_id_finder.msn &>
<& /contenido/webshop/components/block_order_status_changer.msn, status => $ost &>

<& /contenido/webshop/components/block_coupons.msn &>
%#<& /contenido/webshop/components/block_discounts.msn &>
<& /contenido/webshop/components/block_order_finder.msn &>

</td>
<td width="1%">&nbsp;</td>
<td width="65%">

<div id="search-by-id-found"></div>

<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/order_browse.msn, documents => \@documents, columns => \@columns, filter => \%filter_params, status => $ost, %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%">&nbsp;</td>
</tr>
</table>

</body>
</html>
<%args>

	$ost	=> 1
	$p	=> 1
	$delete	=> undef
	$drop_owner	=> undef

</%args>
<%init>

    my %filter_params;

    my (@documents, $total);
    $filter_params{ost} = $ost		if $ost != 1;
    my $size = 40;

    my %opts;
    my $company_filter_value;
    if ( exists $ARGS{order_company_filter} ) {
	$company_filter_value = $ARGS{order_company_filter};
	$m->comp( '/contenido/components/cookies.msn', name => $request->{cookie_filter_company}, value => $company_filter_value );
	if ( defined $company_filter_value && $company_filter_value ne '' ) {
		$opts{company_id} = $company_filter_value;
	}
    } else {
	$company_filter_value = $m->comp( '/contenido/components/cookies.msn', name => $request->{cookie_filter_company} );
	if ( defined $company_filter_value && $company_filter_value ne '' ) {
		$opts{company_id} = $company_filter_value;
	}
    }

    @documents = $keeper->get_documents(
			class	=> 'webshop::Order',
			status	=> $ost,
			limit	=> $size,
			offset	=> ($p-1)*$size,
			%opts
		);
    $total = $keeper->get_documents(
				class	=> 'webshop::Order',
			status	=> $ost,
			count	=> 1,
			%opts
		);
    my @structure = webshop::Order->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] == $ost } @{$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;
			if ( $user->type ) {
				$object->status( 5 );
				$object->store;
			} else {
				$object->delete;
			}
		}
	}
	$m->redirect("/contenido/webshop/".($return_params ? '?'.$return_params : ''));
    } elsif ( $active_rights == 0 && $drop_owner ) {
	my $id = $ARGS{id};
	my $doc = $keeper->get_document_by_id( $id,
			class	=> 'webshop::Order',
		)			if $id && $id =~ /^\d+$/;
	if ( ref $doc ) {
		my $user_id = $ARGS{field};
		$doc->$user_id( 0 );
		$doc->store;
		$m->redirect( $r->header_in('Referer') );
	}
    }

</%init>