#!/usr/bin/perl 
#
# Copyright (c) 2004-2006 Javier Gutierrez <https://github.com/tap3edit/TAP3-Tap3edit>. 
# All rights reserved. This program is free software; you can redistribute 
# it and/or modify it under the same terms as Perl itself.
#  
# Show the charge detail of every calls in a TAP file
#
#
#  Usage: tap3edit_show_charge_details tapfile
#
#  E.g: tap3edit_show_charge_details CDOPER1OPER200001
#


use TAP3::Tap3edit;

use Data::Dumper;
$Data::Dumper::Indent=1;
$Data::Dumper::Quotekeys=1;
$Data::Dumper::Useqq=1;



$filename=shift;

if ( ! $filename ) {
	die "Usage: $0 tapname\n";
}


$tap3 = TAP3::Tap3edit->new();
$tap3->decode($filename)  or  die $tap3->error;

$struct=$tap3->structure;

my $key;

# Will scan all the calls for Camel attachments.
foreach $key ( @{$struct->{'transferBatch'}->{'callEventDetails'} } ) {

	$call=(keys %{$key})[0]; # Every element has always only one call
	print "This call is: $call\n";

	# This shows the content of the chargelist.
	# print Dumper( $key->{$call}->{basicServiceUsedList}[0]{chargeInformationList}[0]{chargeDetailList} );

	foreach $charge ( @{$key->{$call}->{basicServiceUsedList}[0]{chargeInformationList}[0]{chargeDetailList} } ) {
		print "chargeType= $charge->{chargeType}, charge= $charge->{charge}\n";
	}
}
