Tax details are now stored with the transaction items they belong to.

This commit is contained in:
Martin Kamerbeek 2009-05-08 10:03:25 +00:00
parent cf98c81461
commit 9d90b92629
7 changed files with 133 additions and 7 deletions

View file

@ -6,6 +6,8 @@ use WebGUI::Exception;
use WebGUI::International;
use WebGUI::Pluggable;
use WebGUI::Utility;
use JSON qw{ from_json };
use base qw/WebGUI::Account/;
=head1 NAME
@ -348,9 +350,15 @@ sub www_viewTransaction {
url => $actions->{$label},
}
}
my %taxConfiguration = %{ from_json( $item->get( 'taxConfiguration' ) || '{}' ) };
my %taxVars =
map { ( "tax_$_" => $taxConfiguration{ $_ } ) }
keys %taxConfiguration;
push @items, {
%{$item->get},
%{ $item->get },
%taxVars,
viewItemUrl => $url->page('shop=transaction;method=viewItem;transactionId='.$transaction->getId.';itemId='.$item->getId),
price => sprintf("%.2f", $item->get('price')),
itemShippingAddress => $address,

View file

@ -178,6 +178,32 @@ sub getTaxRate {
#-----------------------------------------------------------
=head2 getTransactionTaxData ( sku, address )
Returns a hashref containing tax information that should be stored along with transaction items.
=head3 sku
The sku belonging to the transaction item.
=head3 address
The address belonging to the transaction item.
=cut
sub getTransactionTaxData {
my $self = shift;
my $config = {
className => $self->className,
};
return $config;
}
#-----------------------------------------------------------
=head2 getUserScreen ( )
Returns the screen for entering per user configuration for this tax driver.

View file

@ -507,6 +507,37 @@ sub getTaxRate {
return $taxRate;
}
#-------------------------------------------------------------------
=head2 getTransactionTaxData ( sku, address )
See WebGUI::Shop::TaxDriver->getTransactionTaxData.
=cut
sub getTransactionTaxData {
my $self = shift;
my $sku = shift;
my $address = shift;
my $countryCode = $self->getCountryCode( $address->get( 'country' ) );
my $config = $self->SUPER::getTransactionTaxData( $sku, $address );
if ( ! $countryCode ) {
$config->{ outsideEU } = 1;
}
elsif ( $self->hasVATNumber( $countryCode ) ) {
$config->{ useVATNumber } = 1;
$config->{ VATNumber } = $self->getVATNumbers( $countryCode )->[0]->{ vatNumber };
}
else {
$config->{ useVATNumber } = 0;
}
return $config;
}
#-------------------------------------------------------------------
=head2 getVATNumbers ( $countryCode )

View file

@ -2,10 +2,11 @@ package WebGUI::Shop::TransactionItem;
use strict;
use Class::InsideOut qw{ :std };
use JSON;
use JSON qw{ to_json };
use WebGUI::DateTime;
use WebGUI::Exception::Shop;
use WebGUI::Shop::Transaction;
use WebGUI::Shop::Tax;
=head1 NAME
@ -263,7 +264,10 @@ The status of this item. The default is 'NotShipped'. Other statuses include: Ca
sub update {
my ($self, $newProperties) = @_;
my $id = id $self;
my $id = id $self;
my $session = $self->transaction->session;
my $taxDriver = WebGUI::Shop::Tax->getDriver( $session );
if (exists $newProperties->{item}) {
my $item = $newProperties->{ item };
my $sku = $item->getSku;
@ -286,6 +290,12 @@ sub update {
$newProperties->{ shippingCountry } = $address->get('country');
$newProperties->{ shippingCode } = $address->get('code');
$newProperties->{ shippingPhoneNumber } = $address->get('phoneNumber');
# Store tax rate for product
$newProperties->{ taxRate } = $taxDriver->getTaxRate( $sku, $address );
$newProperties->{ taxConfiguration } =
to_json( $taxDriver->getTransactionTaxData( $sku, $address ) || '{}' );
unless ($sku->isShippingRequired) {
$newProperties->{orderStatus} = 'Shipped';
}
@ -293,7 +303,7 @@ sub update {
my @fields = (qw(assetId configuredTitle options shippingAddressId shippingTrackingNumber orderStatus
shippingName shippingAddress1 shippingAddress2 shippingAddress3 shippingCity shippingState
shippingCountry shippingCode shippingPhoneNumber quantity price vendorId
vendorPayoutStatus vendorPayoutAmount));
vendorPayoutStatus vendorPayoutAmount taxRate taxConfiguration));
foreach my $field (@fields) {
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
}