Akopia Akopia Services

[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date ][Minivend by thread ]

Re: [mv] Prorate discount script bug



******    message to minivend-users from "Bill Randle" <billr@exgate.tek.com>     ******

Sydney,

On Aug 20,  2:35am, Sydney Urshan wrote:
} Subject: Re: [mv] Prorate discount script bug
} This works perfect:

[snip]

} Now to the next step...
}
} I need this exact *result* to work on the if-loop pages (index.html,
} etc.) *before* a product is selected.  Here is a make-shift solution
} I used, but for obvious reasons, it will not always work without
} manual changes (like the month).
}
} [if-loop-field monthly]
} <B>[currency][calc][loop-field monthly] - ([loop-field monthly] / 31
} * [tag time]%d[/tag]) [/calc][/currency]</B></font><BR>
} <FONT FACE="Arial" SIZE="2" COLOR=blue><B>Startup Cost Automatically
} Prorated [currency][calc][loop-field monthly] - ([loop-field monthly]
} - ([loop-field monthly] / 31 * [tag time]%d[/tag]))
} [/calc][/currency]!</B>
} [else]
} <B>[currency][loop-field setup][/currency]</B></font><BR>
} <FONT FACE="Arial" SIZE="2" COLOR=blue><B>Not Prorated</B>
} [/else]
} [/if-loop-field]
}
} Basically, I need the first example to work on index.html before a
} product is selected.

[snip]

I would suggest putting the prorate calculation in a UserTag that you
can then use wherever you need it. For example:

UserTag prorate Order price
UserTag prorate PosNumber 1
UserTag prorate Routine <<EOR
sub {
    my ($price) = @_;
    my $bit = $Tag->time('', {}, '%Y %m %d');
    my ($year, $month, $n) = split /\s+/, $bit;
    $n =~ s/^0//;
    my $leap = (($year % 4 == 0) && (($year % 100 != 0) || ($year % 400 ==
0)));
    my %mon = (
        '01' => 31,
        '02' => 28,
        '03' => 31,
        '04' => 30,
        '05' => 31,
        '06' => 30,
        '07' => 31,
        '08' => 31,
        '09' => 30,
        '10' => 31,
        '11' => 30,
        '12' => 31,
    );
    my $monlen = $mon{$month};
    $monlen++ if $leap && $month eq '02';
    if ($monlen and $n > 1) {
        return $price * (1 - 1 / $monlen) * ($n - 1) / ($monlen - 1);
    }
    return 0;
}
EOR

Note that the above code also takes into account leap years properly
which the original didn't.

Then, for the discount, you could use:

[discount [loop-code]]
  return $s - $Tag->prorate($s);
[/discount]

and for the index page:

[if-loop-field monthly]
[seti monthly][loop-field monthly][/seti]
Monthly cost of [currency][scratch monthly][/currency] is
[mvasp global=1]
<%
    no strict;
    my $pro = $Tag->prorate($Scratch->{monthly});
    if ($pro) {
        my $cpro = $Tag->currency({}, $pro);
        my $cproprice = $Tag->currency({}, $Scratch->{monthly} - $pro);
        HTML("prorated by $cpro to $cproprice for the first month.\n");
    }
    else {
        HTML("not prorated.\n");
    }
%>
[/mvasp]
[else]
Not Prorated.
[/else]
[/if-loop-field]

Except for the [if-loop-field] part, I tested the usertag and [mvasp]
code and it appears to work correctly.

	-Bill
-
To unsubscribe from the list, DO NOT REPLY to this message.  Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list


Search for: Match: Format: Sort by: