Revision 638 (by ahitrov, 2017/01/12 12:34:10) Orders by coupon functionality. Context table and browse mode table.

<fieldset style="background:white; margin:5px;">
<legend>Последние заказы (<% scalar @orders %>)</legend>
% if ( @orders ) {
	<table width="100%" border="0" cellpadding="3" cellspacing="0" class="tlistdocs">
%	foreach my $order ( @orders ) {
%		my ($href, $action, $user_id);
%		my $status = $order->status;
%		if ( ($status == 1 || $status == 6 || $status == 7 || $status == 8) && (!$active_rights || $active_rights == 1) ) {
%			$href = 'take_care.html';
%			$action = { href => $href, name => 'обработать' };
%			$user_id = 'manager_id';
%		} elsif ( $status == 2 && (!$active_rights || $active_rights == 2) ) {
%			$href = 'facility.html';
%			$action = { href => $href, name => 'собрать' };
%			$user_id = 'vault_id';
%		} elsif ( $status == 3 && (!$active_rights || $active_rights == 3) ) {
%			$href = 'delivery.html';
%			$action = { href => $href, name => 'доставить' };
%			$user_id = 'postman_id';
%		} elsif ( $status == 4 && !$active_rights ) {
%			$href = 'delivery.html';
%			$action = { href => $href, name => 'просмотр' };
%		} elsif ( $status == 5 && !$active_rights ) {
%			$href = 'delivery.html';
%			$action = { href => $href, name => 'просмотр' };
%		}
%		my $url = $href.'?id='.$order->id;
%		my $status_name = exists $status_options{$order->status} ? $status_options{$order->status} : 'unknown';
		<tr>
			<td><a href="<% $url %>"><% $order->id %></a></td>
			<td><a href="<% $url %>"><% $order->name %></a></td>
			<td><% $status_name %></td>
			<td><a href="<% $url %>"><% $action->{name} %></a></td>
		</tr>
%	}
	</table>
	<a href="/contenido/webshop/?coupon_id=<% $object->id %>">Все заказы (<% $total %>)</a>
% }
</fieldset>
<%args>

	$object	=> undef

</%args>
<%init>

    return	unless ref $object && $object->id;

    my $total = $keeper->get_documents(
		class	=> 'webshop::OrderCouponLink',
		dest_id	=> $object->id,
		source_id	=> 'positive',
		count	=> 1,
	);
    my (@links, @orders);
    if ( $total ) {
	@links = $keeper->get_documents(
			class	=> 'webshop::OrderCouponLink',
			dest_id	=> $object->id,
			source_id	=> 'positive',
			order_by	=> 'ctime desc',
			limit	=> 10,
		);
	my @ids = map { $_->source_id } @links;
	@orders = $keeper->get_documents(
			id	=> \@ids,
			class	=> 'webshop::Order',
			order_by	=> 'ctime desc',
		);
    }
    my %props = map { $_->{attr} => $_ } webshop::Order->new( $keeper )->structure;
    my $prop = $props{status};
    my %status_options = map { $_->[0] => $_->[1] } @{$prop->{cases}};
    my $active_rights = $m->comp('/contenido/webshop/subs/user_rights.msn');

</%init>