package Purchase;

sub new{
my($class,$self);
$class = shift;
$self={
	"subtotal" => 0,
	"subtotal_new" => 0,
	"subtotal_old" => 0,
	"a_total" => 0,
	"postage_all" => 0,
	"tax_all" => 0,
	"tax_new" => 0,
	"tax_old" => 0,
	"vol_all" => 0,
	"weight_all" => 0,
	"wari" => 0,
	"nop" => 0,
	"plusp" => 0,
	"no_s_count" => 0,
	"cool_count" => 0,
	"wrap_count" => 0,
	"total" => 0,
	"wrap_charge" => 0,
	"dai_charge" => 0,
	"subtotal_o" => 0,
	"goods_all" => "",
	"goods_all_kessai" => "",
	"g_line" => "",
	"pack_all" => "",
	"wari_c" => "",
	"p_wari_c" => "",
	"wari_charge_c" => "",
	"dai_name" => "",
	"dai_charge_c" => "",
	"postage_all_c" => "",
	"tax_all_c" => "",
	"tax_new_c" => "",
	"tax_old_c" => "",
	"subtotal_c" => "",
	"subtotal_new_c" => "",
	"subtotal_old_c" => "",
	"total_c" => "",
	"subtotal_o_c" => "",
	"zei_old" => 0,
};
return bless $self,$class;
}

sub GoodsCal{
my($self,$goods_ref,$ref,$l,$ctref,$op,$fukusu,$tax_each,$price_c,$goods_d,$tax_each_all,$act);
$self=$_[0];
$act=$_[1];
$goods_ref=$_[2];
$ref=$_[3];

$wari=0;
@pack_all_a=();
foreach $l(@{$ref}){
	$ctref=&Functions::SplitCart($l);
	if($CF::waribiki){
		$self->{'wari'}+=int(${$ctref}{'price'}*${$ctref}{'amount'}*$CF::wariritu/100);
	}
	if(${$ctref}{'cool'}){
		$self->{'cool_count'}++;
	}
	if(${$ctref}{'wrap'}){
		$self->{'wrap_count'}++;
	}
	$op=${$ctref}{'op'};
	$op=~s/:/ /g;

	$fukusu=${$ctref}{'price'}*${$ctref}{'amount'};

	$fukusu_c=&Functions::Comma($act,$fukusu);

	$self->{'subtotal'}+=$fukusu;

	$self->{'a_total'}+=${$ctref}{'amount'};

	$self->{'weight_all'}+=${$ctref}{'weight'}*${$ctref}{'amount'};
	if(${$ctref}{'pack'}){
		push @pack_all_a,${$ctref}{'pack'}.':'.${$ctref}{'amount'};
	}
	if($CF::postage == 3){
		if(${$ctref}{'postage'} == ""){
			${$ctref}{'postage'}=0;
		}
		${$ctref}{'postage'}*=${$ctref}{'amount'};
		$self->{'postage_all'}+=${$ctref}{'postage'};
	}

	$tax_each=&Functions::Kazei(${$ctref}{'price'},${$ctref}{'tax'});
	$tax_each_all=$tax_each*${$ctref}{'amount'};

	if(${$ctref}{'tax'}){
		$self->{'subtotal_old'}+=$fukusu;
		$self->{'tax_old'}+=$tax_each_all;
		${$ctref}{'name'}='※'.${$ctref}{'name'};
		$self->{'zei_old'}=${$ctref}{'tax'};
	}
	else{
		$self->{'subtotal_new'}+=$fukusu;
		$self->{'tax_new'}+=$tax_each_all;
	}
	
	$self->{'tax_all'}+=$tax_each_all;
	
	$price_c=&Functions::Comma($act,${$ctref}{'price'});

	if($op){
		${$ctref}{'name'}.=" ".'('.$op.')';
	}
	if(${$ctref}{'wrap'}){
		${$ctref}{'name'}.=" ラッピング";
	}
	$self->{'goods_all'}.="${$ctref}{'number'} ${$ctref}{'name'} ${price_c} × ${$ctref}{'amount'}個 ＝ ${fukusu_c}\n";
	$self->{'goods_all_kessai'}.="${$ctref}{'name'} ${$ctref}{'price'}円 ${$ctref}{'amount'}個 :";

	if(${$ctref}{'image'}){
		${$ctref}{'image'}="<a href=\"${$ctref}{'image'}\" target=\"_blank\"><img src=\"${$ctref}{'image'}\" alt=\"\" width=\"$CF::wh\" align=\"absmiddle\" border=\"0\" class=\"img\"></a>";
	}
	$goods_d=${$goods_ref};
	$goods_d=~s/<!--number-->/${$ctref}{'number'}/;
	$goods_d=~s/<!--name-->/${$ctref}{'name'}/;
	${$ctref}{'number'}.=${$ctref}{'op'};
	$goods_d =~ s/#id/${$ctref}{'number'}/;
	${$ctref}{'number'} =~ s/([^\w\=\& ])/'%' . unpack("H2", $1)/eg;
	${$ctref}{'number'} =~ tr/ /+/;
	$goods_d =~ s/#num/${$ctref}{'number'}/;
	$goods_d =~ s/<!--image-->/${$ctref}{'image'}/;
	$goods_d =~ s/<!--price-->/$price_c/;
	$goods_d =~ s/#amount/${$ctref}{'amount'}/;
	$goods_d =~ s/<!--amount-->/${$ctref}{'amount'}/;
	$goods_d =~ s/<!--fukusu-->/$fukusu_c/;

	$self->{'g_line'}.=$goods_d;

}

$self->{'pack_all'}=join("!",@pack_all_a);

}


1;
