Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Additional line in date-global

Quote Reply
Additional line in date-global
Hi to all,

i am using this global to view a SUM of data-records with a special value in colun "Ausgabe":
Code:
sub {
my $cond = new GT::SQL::Condition;
my($ausgabe)=@_;
$cond->bool('AND');
$cond->add('Ausgabe','=',$ausgabe);
$cond->add('MagArt','=','gumag');
my ($total) = $DB->table('Links')->select(['SUM(Wert)'],$cond)->fetchrow_array;
local $_ = int $total;
my($grouping,$thousands_sep);
$grouping=3;
$thousands_sep='.';
1 while
s/(\d)(\d{$grouping}($|\Q$thousands_sep\E))/$1$thousands_sep$2/;
return "$_";
}

The using is:
1. I define the "Ausgabe" from the actual date and
2. put this Ausgabe (format: mm-yyyy) into global like this:

<%set Ausgabe = GT::Date::date_transform($date, '%dd%.%mm%.%yyyy%', '%mm%-%yyyy%')%>
<%gutscheine_wert($Ausgabe)%>

Now what i need is this:
When the actual "Ausgabe" is not in db (e.g. 02-2005), then the global search for the last available date, in this case: 01-2005.
Perhaps: IF $total = 0 ...... etc ....... ???

How can i do that?

Thanks in advance!

Coyu
Quote Reply
Re: [Coyu] Additional line in date-global In reply to
Something like this before the original select should get the closest value:my $db1=$DB->table('Links');
$db1->select_options (ORDER BY Ausgabe DESC LIMIT 1);
my $cond1= GT::SQL::Condition->new('Ausgabe','<=',$ausgabe);
$ausgabe=$db1->select(['Ausgabe'],$cond)->fetchrow_array;