Revision 438 (by ahitrov, 2014/07/17 17:45:17) Order report now can be filtered by coupons

<fieldset>
<legend>Отчет по заказам</legend>
	<form name="searchdoc" action="orders.html" method="GET" target="_blank">
	<table width="100%" border="0" cellpadding="0" cellspacing="6" class="tform">
	<tr><td><b>Выберите статус:</b></td></tr>
	<tr><td><& "/contenido/components/select.msn", name=>'status', values => \@status_values, check => 4, style=>'width:100%;font-size:8pt;' &></td>
	<tr><td><b>Сортировать:</b></td></tr>
	<tr><td><& "/contenido/components/select.msn", name=>'sort', values => \@sorts, style=>'width:100%;font-size:8pt;' &></td>
	<tr><td height="5"></td></tr>
	<tr><td><b>Диапазон дат:</b></td></tr>
	<tr><td><& "/contenido/components/inputs/date.msn", name => 'from' &></td></tr>
	<tr><td><& "/contenido/components/inputs/date.msn", name => 'to' &></td></tr>
	<tr><td><b>По купону:</b></td></tr>
	<tr><td><& "/contenido/components/select.msn", name=>'coupon', values => \@coupons, style=>'width:100%;font-size:8pt;' &></td>
	<tr><td><b>Отобразить:</b></td></tr>
	<tr><td><& "/contenido/components/select.msn", name=>'show', values => \@shows, style=>'width:100%;font-size:8pt;' &></td>
	<tr><td><input type="submit" value="Отобрать" class="btn"></td></tr>
	</table>
	</form>
</fieldset>

<%once>

    my @sorts = (
	'id'	=> 'по номеру заказа',
	'uid'	=> 'по пользователю',
    );

    my @shows = (
	'html'	=> 'В виде HTML',
	'tsv'	=> 'Tab-separated текст',
    );

</%once>
<%args>


</%args>
<%init>

    my @props = webshop::Order->new($keeper)->structure;
    my ($prop_status) = grep { $_->{attr} eq 'status' } @props;
    my @status_values = map { $_->[0] => $_->[1] } @{$prop_status->{cases}};
    $status_values[1] = 'без учета статуса';

    my @coupons = ('' => 'без учета купонов');
    my $sql = "select id, name from webshop_coupons where class = 'webshop::Coupon' and ( status in (0, 4) or (status in (1,3) and pid = 0) ) order by status = 1 desc, status, dtime desc";
    my $que = $keeper->SQL->prepare($sql);
    $que->execute();
    while ( my $ln = $que->fetchrow_hashref ) {
	push @coupons, ($ln->{id}, $ln->{name});
    }

</%init>