+ # sorting and direction of sorting
+ # ToDO: change this to the simpler field+direction method
+ if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
+ $form->{revers} = 0;
+ $form->{lastsort} = "partnumber";
+ $form->{sort} = "partnumber";
+ } else {
+ if ($form->{lastsort} eq $form->{sort}) {
+ $form->{revers} = 1 - $form->{revers};
+ } else {
+ $form->{revers} = 0;
+ $form->{lastsort} = $form->{sort};
+ } #fi
+ } #fi
+
+ # special case if we have a serialnumber limit search
+ # serialnumbers are only given in invoices and orders,
+ # so they can only pop up in bought, sold, rfq, and quoted stuff
+ $form->{no_sn_joins} = 'Y' if ( !$form->{bought} && !$form->{sold}
+ && !$form->{rfq} && !$form->{quoted}
+ && ($form->{l_serialnumber} || $form->{serialnumber}));
+
+ # special case for any checkbox of bought | sold | onorder | ordered | rfq | quoted.
+ # if any of these are ticked the behavior changes slightly for lastcost
+ # since all those are aggregation checks for the legder tables this is an internal switch
+ # refered to as ledgerchecks
+ $form->{ledgerchecks} = 'Y' if ( $form->{bought} || $form->{sold} || $form->{onorder}
+ || $form->{ordered} || $form->{rfq} || $form->{quoted});
+
+ # if something should be activated if something else is active, enter it here
+ my %dependencies = (
+ onhand => [ qw(l_onhand) ],
+ short => [ qw(l_onhand) ],
+ onorder => [ qw(l_ordnumber) ],
+ ordered => [ qw(l_ordnumber) ],
+ rfq => [ qw(l_quonumber) ],
+ quoted => [ qw(l_quonumber) ],
+ bought => [ qw(l_invnumber) ],
+ sold => [ qw(l_invnumber) ],
+ ledgerchecks => [ qw(l_name) ],
+ serialnumber => [ qw(l_serialnumber) ],
+ no_sn_joins => [ qw(bought sold) ],
+ );
+
+ # these strings get displayed at the top of the results to indicate the user which switches were used
+ my %optiontexts = (
+ active => $locale->text('Active'),
+ obsolete => $locale->text('Obsolete'),
+ orphaned => $locale->text('Orphaned'),
+ onhand => $locale->text('On Hand'),
+ short => $locale->text('Short'),
+ onorder => $locale->text('On Order'),
+ ordered => $locale->text('Ordered'),
+ rfq => $locale->text('RFQ'),
+ quoted => $locale->text('Quoted'),
+ bought => $locale->text('Bought'),
+ sold => $locale->text('Sold'),
+ transdatefrom => $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1),
+ transdateto => $locale->text('To (time)') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1),
+ partnumber => $locale->text('Part Number') . ": '$form->{partnumber}'",
+ partsgroup => $locale->text('Group') . ": '$form->{partsgroup}'",
+ serialnumber => $locale->text('Serial Number') . ": '$form->{serialnumber}'",
+ description => $locale->text('Part Description') . ": '$form->{description}'",
+ make => $locale->text('Make') . ": '$form->{make}'",
+ model => $locale->text('Model') . ": '$form->{model}'",
+ drawing => $locale->text('Drawing') . ": '$form->{drawing}'",
+ microfiche => $locale->text('Microfiche') . ": '$form->{microfiche}'",
+ l_soldtotal => $locale->text('soldtotal'),
+ );
+
+ my @itemstatus_keys = qw(active obsolete orphaned onhand short);
+ my @callback_keys = qw(onorder ordered rfq quoted bought sold partnumber partsgroup serialnumber description make model
+ drawing microfiche l_soldtotal l_deliverydate transdatefrom transdateto ean);
+
+ # calculate dependencies
+ for (@itemstatus_keys, @callback_keys) {
+ next if ($form->{itemstatus} ne $_ && !$form->{$_});
+ map { $form->{$_} = 'Y' } @{ $dependencies{$_} } if $dependencies{$_};
+ }
+
+ # generate callback and optionstrings
+ my @options;
+ for my $key (@itemstatus_keys, @callback_keys) {
+ next if ($form->{itemstatus} ne $key && !$form->{$key});
+ push @options, $optiontexts{$key};
+ }
+
+ # special case for lastcost
+ $form->{l_lastcost} = "" if $form->{ledgerchecks};