sales tax

This commit is contained in:
Colin Kuskie 2006-10-21 01:13:07 +00:00
parent 4deff2a0a9
commit f3ab99bc02
23 changed files with 607 additions and 111 deletions

View file

@ -230,6 +230,20 @@ sub type {
#-------------------------------------------------------------------
=head2 useSalesTax ( )
This method should return whether or not the item uses sales tax.
This must be implemented by an item plugin.
=cut
sub useSalesTax {
my $self = shift;
return $self->session->errorHandler->fatalError('The useSalesTax method of WebGUI::Commerce::Item must be overridden.');
}
#-------------------------------------------------------------------
=head2 weight ( )
Returns the weight of the item. If your item has a weight, you'll want to overload this method. Weight is calculated on a unit based scale.

View file

@ -88,7 +88,7 @@ sub new {
$session = shift;
$eventId = shift;
my $eventData = $session->db->quickHashRef("select p.productId, p.title, p.description, p.price, p.sku, e.approved, e.passId, e.passType
my $eventData = $session->db->quickHashRef("select p.productId, p.title, p.description, p.price, p.useSalesTax, p.sku, e.approved, e.passId, e.passType
from EventManagementSystem_products as e, products as p
where p.productId = e.productId and p.productId=".$session->db->quote($eventId));
@ -183,6 +183,12 @@ sub type {
return 'Event';
}
#-------------------------------------------------------------------
sub useSalesTax {
my $self = shift;
return $self->{_event}->{useSalesTax} ? 1 : 0;
}
#-------------------------------------------------------------------
sub weight {
return 0;

View file

@ -0,0 +1,33 @@
package WebGUI::Commerce::Item::Fake;
# Adding this to cope with sales tax without changing the schema.
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use WebGUI::Commerce::Item;
use base 'WebGUI::Commerce::Item';
sub new {
my $class = shift;
my $session = shift;
my $id = shift;
my $namespace = shift;
my ($price, $name) = split /\,/, $id, 2;
bless { _name => $name, _price => $price }, $class;
}
sub useSalesTax { 0 }
sub name { $_[0]{_name} }
sub price { $_[0]{_price} }
sub type { 'Fake' }
sub id { "$_[0]{_price},$_[0]{_name}" }
sub description { $_[0]{_name} }
1;

View file

@ -44,36 +44,37 @@ sub description {
#-------------------------------------------------------------------
sub handler {
my $self = shift;
### Add to group action
# If group is 'everyone', skip
unless ($self->{_product}->get('groupId') eq '7') {
my $g = WebGUI::Group->new($self->session,$self->{_product}->get('groupId'));
my $expiresOffset;
# Parse the value
if ($self->{_product}->get('groupExpiresOffset') =~ /^(\d+)month/i) {
$expiresOffset = $1 * 3600*24*30; # One month
} elsif ($self->{_product}->get('groupExpiresOffset') =~ /^(\d+)year/i) {
$expiresOffset = $1 * 3600*24*365; # One year
}
# Multiply by how many quantity we're purchasing
#!!! TODO !!! - handlers don't know how many we're purchasing
# If user has time left
my $remains = $g->userGroupExpireDate($self->session->user->userId);
if ($remains) {
# Add any remaining time to the offset
$expiresOffset += $remains - time();
}
# Add user to group
$g->addUsers([$self->session->user->userId],$expiresOffset);
}
my $self = shift;
### Add to group action
# If group is 'everyone', skip
unless ($self->{_product}->get('groupId') eq '7') {
my $g = WebGUI::Group->new($self->session,$self->{_product}->get('groupId'));
my $expiresOffset;
# Parse the value
if ($self->{_product}->get('groupExpiresOffset') =~ /^(\d+)month/i) {
$expiresOffset = $1 * 3600*24*30; # One month
} elsif ($self->{_product}->get('groupExpiresOffset') =~ /^(\d+)year/i) {
$expiresOffset = $1 * 3600*24*365; # One year
}
# Multiply by how many quantity we're purchasing
#!!! TODO !!! - handlers don't know how many we're purchasing
# If user has time left
my $remains = $g->userGroupExpireDate($self->session->user->userId);
if ($remains) {
# Add any remaining time to the offset
$expiresOffset += $remains - time();
}
# Add user to group
$g->addUsers([$self->session->user->userId],$expiresOffset);
}
}
#-------------------------------------------------------------------
sub id {
return $_[0]->{_variant}->{variantId};
@ -121,6 +122,12 @@ sub price {
return $_[0]->{_variant}->{price};
}
#-------------------------------------------------------------------
sub useSalesTax {
my $self = shift;
return $self->{_product}->get('useSalesTax') ? 1 : 0;
}
#-------------------------------------------------------------------
sub type {
return 'Product';

View file

@ -82,6 +82,12 @@ sub price {
return $_[0]->{_subscription}->get('price');
}
#-------------------------------------------------------------------
sub useSalesTax {
my $self = shift;
return $self->{_subscription}->get('useSalesTax') ? 1 : 0;
}
#-------------------------------------------------------------------
sub type {
return 'Subscription';

View file

@ -219,16 +219,20 @@ The instantiated plugin of this item. See WebGUI::Commerce::Item for a detailed
sub getItems {
my ($self, $periodResolve, %cartContent, $item, $properties, @recurring, @normal);
$self = shift;
my $salesTaxRate = shift;
$periodResolve = WebGUI::Commerce::Payment->recurringPeriodValues($self->session);
%cartContent = %{$self->{_items}};
foreach (values(%cartContent)) {
$item = WebGUI::Commerce::Item->new($self->session,$_->{itemId}, $_->{itemType});
my $totalPrice = $item->price * $_->{quantity};
my $productTax = $salesTaxRate * $item->useSalesTax;
$properties = {
quantity => $_->{quantity},
period => lc($periodResolve->{$item->duration}),
name => $item->name,
price => sprintf('%.2f', $item->price),
totalPrice => sprintf('%.2f', $item->price * $_->{quantity}),
totalPrice => sprintf('%.2f', $totalPrice),
salesTax => sprintf('%.2f', $totalPrice * $productTax),
item => $item,
};