1
0
mirror of https://github.com/imapsync/imapsync.git synced 2024-11-17 08:12:48 +01:00
imapsync/W/paypal_reply/paypal_bilan_1.27
Nick Bebout 90be463820 1.452
2011-07-11 16:24:12 -05:00

827 lines
24 KiB
Perl
Executable File

#!/usr/bin/perl
# $Id: paypal_bilan,v 1.27 2011/05/01 12:57:37 gilles Exp gilles $
use strict;
use warnings;
use Getopt::Long;
use Text::CSV_XS ;
use IO::Handle ;
use Data::Dumper ;
use Unicode::MapUTF8 qw(to_utf8 from_utf8 utf8_supported_charset);
die unless (utf8_supported_charset('ISO-8859-1'));
my $total_usd_received = 0 ;
my $total_usd_invoice = 0 ;
my $total_HT_EUR_exo = 0 ;
my $total_HT_EUR_ass = 0 ;
my $total_TVA_EUR = 0 ;
my $total_eur_received = 0 ;
my $total_eur_invoice = 0 ;
my $nb_invoice = 0 ;
my $nb_invoice_refund = 0 ;
my $nb_invoice_suspended = 0 ;
my $debug ;
my $debug_csv ;
my $debug_dev ;
my $first_invoice = 1 ;
my $print_details = '' ;
my $bnc = '';
my $usdeur = 1.2981 ;
my $invoices ;
my %invoice_refund ;
my %invoice_suspended ;
my $write_invoices = 0;
my $dir_invoices = '/g/var/paypal_invoices' ;
my $option_ret = GetOptions (
'debug' => \$debug,
'debug_csv' => \$debug_csv,
'debug_dev' => \$debug_dev,
'first_invoice=i' => \$first_invoice,
'print_details|details' => \$print_details,
'bnc' => \$bnc,
'usdeur=f' => \$usdeur,
'invoices=s' => \$invoices,
'write_invoices!' => \$write_invoices,
);
my @files = @ARGV ;
my %action_of_invoice ;
my @invoices = split( /\s+/, $invoices ) if $invoices ;
#print "@invoices\n" ;
foreach my $file ( @files ) {
my @actions = parse_file( $file ) ;
foreach my $action (@actions) {
my %action = %$action ;
#print $action->{ Nom }, "\n" ;
my( $Date, $Heure, $Fuseau_horaire, $Nom, $Type, $Etat,
$Devise, $Montant, $Numero_davis_de_reception, $Solde,
$Pays, $Nom_Option_1, $Valeur_Option_1, $Hors_taxe )
= @action{ ( 'Date', 'Heure', 'Fuseau horaire', 'Nom', 'Type', 'Etat',
'Devise', 'Montant', "Numéro d'avis de réception", 'Solde',
'Pays', 'Nom Option 1', 'Valeur Option 1', 'Hors taxe') } ;
#print "$Nom\n" ;
my $invoice = 'NONE' ;
$Montant = $action->{ Net } if not defined $Montant;
compute_line($action, $invoice, $Date, $Heure, $Fuseau_horaire, $Nom, $Type, $Etat,
$Devise, $Montant, $Numero_davis_de_reception, $Solde,
$Pays, $Nom_Option_1, $Valeur_Option_1, $Hors_taxe ) ;
# index by invoice number
$action_of_invoice{ $action->{ 'invoice' } } = $action ;
}
delete $action_of_invoice{ 'NONE' } ;
}
my $last_invoice = $first_invoice + $nb_invoice -1 ;
@invoices = ( $first_invoice .. $last_invoice ) if ( ! @invoices ) ;
my @invoice_sent ;
my %invoice_sent ;
my @invoice_not_sent ;
my %invoice_not_sent ;
foreach my $invoice ( @invoices ) {
my $action = $action_of_invoice{ $invoice } ;
my $email_address = $action->{ "De l'adresse email" } ;
my $invoice_sent = invoice_sent( $dir_invoices, $invoice, $email_address ) ;
#print "$invoice $invoice_sent\n" ;
if ( $invoice_sent ) {
$invoice_sent{ $invoice }++ ;
}else{
$invoice_not_sent{ $invoice }++ ;
build_invoice( $invoice ) ;
}
}
@invoice_sent = sort { $a <=> $b } keys( %invoice_sent ) ;
my $nb_invoice_sent = scalar( @invoice_sent ) ;
@invoice_not_sent = sort { $a <=> $b } keys( %invoice_not_sent ) ;
print "USD banque $total_usd_received\n" ;
print "USD invoice $total_usd_invoice\n" ;
my $total_eur_from_usd ;
$total_eur_from_usd = int( ( $total_usd_invoice / $usdeur ) + 0.5 ) ; # au 30 nov 2010 http://fr.finance.yahoo.com/devises/convertisseur/#from=EUR;to=USD;amt=1
print "EUR from USD $total_eur_from_usd\n" ;
#$total_eur = int( ( $total_eur_invoice / 1.3 ) + 0.5 ) ;
#print "EUR $total_eur_from_usd\n" ;
print "EUR banque $total_eur_received\n" ;
print "EUR invoice $total_eur_invoice\n" ;
my $total_eur = $total_eur_from_usd + $total_eur_invoice ;
$total_HT_EUR_exo = sprintf('%2.f', $total_HT_EUR_exo) ;
$total_HT_EUR_ass = sprintf('%2.f', $total_HT_EUR_ass) ;
$total_TVA_EUR = sprintf('%2.f', $total_TVA_EUR) ;
$total_eur = sprintf('%2.f', $total_eur) ;
print "EUR total $total_eur\n" ;
print "EUR total HT exo $total_HT_EUR_exo\n" ;
print "EUR total HT assuj $total_HT_EUR_ass\n" ;
print "EUR total TVA $total_TVA_EUR\n" ;
print "Nb invoice $nb_invoice ( from $first_invoice to $last_invoice )\n" ;
print "Nb invoice refund $nb_invoice_refund\n" ;
print "Nb invoice suspended $nb_invoice_suspended\n" ;
print "Nb invoice sent $nb_invoice_sent\n" ;
print "Have to send invoices @invoice_not_sent\n" if ( @invoice_not_sent ) ;
print "$total_eur != $total_HT_EUR_exo + $total_HT_EUR_ass + $total_TVA_EUR\n"
if ( $total_eur != $total_HT_EUR_exo + $total_HT_EUR_ass + $total_TVA_EUR ) ;
sub parse_one_line_io {
my $csv = shift ;
my $io = shift ;
my $line = $csv->getline($io) ;
return if ( $csv->eof( ) ) ;
if ( not defined( $line ) ) {
my($cde, $str, $pos) = $csv->error_diag () ;
print "[$cde] [$str] [$pos]\n" ;
}
return( $line ) ;
}
sub hash_and_count_dupplicate {
my @columns = @_ ;
my %columns ;
#@columns_def{ @columns_def } = ( ) ;
foreach my $col ( @columns ) {
$columns{ $col } += 1 ;
}
$debug_csv and print "Nb columns: ", scalar( keys %columns ), " ", scalar( @columns ), "\n" ;
# debug how many time a title is defined
foreach my $col (1 .. scalar( @columns )) {
$debug_csv and print "$col | ",
deci_to_AA( $col ) , " | ",
$columns{ $columns[ $col - 1 ] }, " | ",
$columns[ $col - 1 ], "\n" ;
}
# exit in case two columns have the same name
die "Erreur : doublons dans les titres\n" if ( scalar( keys %columns ) != scalar( @columns ) ) ;
return( %columns ) ;
}
sub deci_to_AA {
my $deci = shift ;
my $AA = '';
while ( $deci > 0 ) {
my $quot = int( ( $deci - 1 ) / 26 ) ;
my $rest = $deci - 1 - ( 26 * $quot ) ;
my $char = chr ( ord('A') + $rest ) ;
$AA = $char . $AA ;
$deci = $quot ;
}
#print "col=$AA\n" ;
return( $AA ) ;
}
sub remove_first_blank {
my $string = shift ;
$string =~ s/^ +// ;
return( $string ) ;
}
sub parse_file {
my $file = shift ;
open my $io, "<", $file or die "$file: $!" ;
my $csv = Text::CSV_XS->new( {
sep_char => ',',
binary => 1,
keep_meta_info => 1,
eol => $/,
} ) ;
my $line_1 = parse_one_line_io( $csv, $io ) ;
die if ( not defined $line_1 ) ; # first line must have no problem
my @columns_def_orig = @$line_1 ;
my @columns_def = map { remove_first_blank( $_ ) } @columns_def_orig ;
$debug_csv and print "columns_def = ", map( { "[$_]" } @columns_def ), "\n";
my %columns_def = hash_and_count_dupplicate( @columns_def ) ;
my $nb_columns_def = scalar @columns_def ;
my $line_counter = 2 ;
my @actions ;
while ( 1 ) {
$debug_csv and print "ligne $line_counter ", $csv->eof( ), "\n" ;
my $line = parse_one_line_io( $csv, $io ) ;
last if ( $csv->eof( ) ) ;
if ( not defined $line ) {
print "Erreur ligne $line_counter : ", $csv->error_diag, "\n\n";
++$line_counter ;
next ;
}
my @columns = @$line ;
if ( $nb_columns_def != scalar @columns ) {
print "Erreur ligne $line_counter : nombre de colonnes = ", scalar @columns, " != $nb_columns_def\n" ;
++$line_counter ;
next ;
}
my %columns ;
@columns{ @columns_def } = @columns ;
$columns{ 'file_csv' } = $file ;
$columns{ 'line_number' } = $line_counter ;
$csv->combine( @columns ) ;
my $line_csv = $csv->string();
$columns{ 'line_csv' } = $line_csv ;
$debug_csv and print map( { "[$_] = [" . $columns{$_} . "]\n" }
@columns_def, 'line_number', 'line_csv', 'file_csv' ),
"\n";
++$line_counter ;
push( @actions, \%columns ) ;
}
close( $io );
return( reverse @actions ) ;
}
sub compute_line {
my( $action, $invoice, $Date, $Heure, $Fuseau_horaire, $Nom, $Type, $Etat,
$Devise, $Montant, $Numero_davis_de_reception, $Solde,
$Pays, $Nom_Option_1, $Valeur_Option_1, $Hors_taxe_paypal ) = @_ ;
$debug and print( "[$Date] [$Heure] [$Fuseau_horaire] [$Nom] [$Type] [$Etat] [$Devise] [$Montant] [$Numero_davis_de_reception] [$Solde]\n",
"[$Pays] [$Nom_Option_1] [$Valeur_Option_1]\n" ) ;
#$debug_dev and print "$Hors_taxe_paypal\n" ;
$Montant =~ s/[^0-9-,.]//g ;
$Montant =~ s/,/./g ;
#$debug and print "MM[$Montant]\n" ;
$Hors_taxe_paypal =~ s/,/./g ;
my $MontantEUR;
my( $montant_HT_EUR_exo, $montant_HT_EUR_ass, $montant_TVA_EUR ) ;
if ( $bnc ) {
$MontantEUR = $Montant ;
$MontantEUR = sprintf( "%.4f", $Montant/$usdeur ) if ($Devise eq 'USD') ;
print( "\n", "=" x 60, "\n" ) ;
print( "[$Date] [$Nom] [$Type] [$Etat] [$Devise] [$Montant] [EUR $MontantEUR]\n",
"[$Pays] [$Nom_Option_1] [$Valeur_Option_1]\n" ) ;
}
if (
'Paiement sur site marchand reçu' eq $Type
and 'USD' eq $Devise
and ( 'Terminé' eq $Etat or 'Compensé' eq $Etat )
) {
$Montant =~tr/,/./;
#print "$Montant\n" ;
my $Montant2_usd;
$Montant2_usd = $Hors_taxe_paypal ;
$total_usd_received += $Montant ;
$total_usd_invoice += $Montant2_usd ;
( $montant_HT_EUR_exo, $montant_HT_EUR_ass, $montant_TVA_EUR ) = tva_line( $Devise, $Montant2_usd, $Pays, $Nom_Option_1, $Valeur_Option_1 ) ;
$total_HT_EUR_exo += $montant_HT_EUR_exo ;
$total_HT_EUR_ass += $montant_HT_EUR_ass ;
$total_TVA_EUR += $montant_TVA_EUR ;
$invoice = $first_invoice + $nb_invoice ;
$nb_invoice++ ;
$print_details and print ( "[$invoice] [$Date] [$Heure] [$Fuseau_horaire] [$Nom] [$Type] [$Etat] [$Devise] [$Montant] [$Numero_davis_de_reception] [$Solde]\n" ) ;
}
if (
'Paiement sur site marchand reçu' eq $Type
and 'EUR' eq $Devise
and ( 'Terminé' eq $Etat or 'Compensé' eq $Etat )
) {
$Montant =~tr/,/./;
#print "$Montant\n" ;
my $Montant2_eur;
$Montant2_eur = $Hors_taxe_paypal ;
$total_eur_received += $Montant ;
$total_eur_invoice += $Montant2_eur ;
( $montant_HT_EUR_exo, $montant_HT_EUR_ass, $montant_TVA_EUR ) = tva_line( $Devise, $Montant2_eur, $Pays, $Nom_Option_1, $Valeur_Option_1 ) ;
$total_HT_EUR_exo += $montant_HT_EUR_exo ;
$total_HT_EUR_ass += $montant_HT_EUR_ass ;
$total_TVA_EUR += $montant_TVA_EUR ;
$invoice = $first_invoice + $nb_invoice ;
$nb_invoice++ ;
$print_details and print ( "[$invoice] [$Date] [$Heure] [$Fuseau_horaire] [$Nom] [$Type] [$Etat] [$Devise] [$Montant] [$Numero_davis_de_reception] [$Solde]\n" ) ;
}
if (
'Paiement sur site marchand reçu' eq $Type
and 'EUR' eq $Devise
and 'Remboursé' eq $Etat
) {
$invoice = $first_invoice + $nb_invoice ;
$nb_invoice++ ;
$nb_invoice_refund++;
$invoice_refund{ $invoice }++ ;
$print_details and print ( "[$invoice] [$Date] [$Heure] [$Fuseau_horaire] [$Nom] [$Type] [$Etat] [$Devise] [$Montant] [$Numero_davis_de_reception] [$Solde]\n" ) ;
}
if (
'Paiement sur site marchand reçu' eq $Type
and 'EUR' eq $Devise
and 'Suspendu' eq $Etat
) {
$invoice = $first_invoice + $nb_invoice ;
$nb_invoice++ ;
$nb_invoice_suspended++;
$invoice_suspended{ $invoice }++ ;
$print_details and print ( "[$invoice] [$Date] [$Heure] [$Fuseau_horaire] [$Nom] [$Type] [$Etat] [$Devise] [$Montant] [$Numero_davis_de_reception] [$Solde]\n" ) ;
}
if (
'Paiement sur site marchand reçu' eq $Type
and 'EUR' eq $Devise
and 'Non compensé' eq $Etat
) {
$invoice = $first_invoice + $nb_invoice ;
$nb_invoice++ ;
$print_details and print ( "[$invoice] [$Date] [$Heure] [$Fuseau_horaire] [$Nom] [$Type] [$Etat] [$Devise] [$Montant] [$Numero_davis_de_reception] [$Solde]\n" ) ;
}
$action->{ 'invoice' } = $invoice ;
if ( $bnc ) {
my $FR_flag = '' ;
$FR_flag = ' FR' if $Pays eq 'France' ;
my $IND_flag = '' ;
$IND_flag = ' IND' if ('imapsync usage' eq $Nom_Option_1 and 'individual' eq $Valeur_Option_1 ) ;
print "FE $invoice$FR_flag$IND_flag\n" ;
print "Facture $invoice imapsync$FR_flag $Nom\n" ;
printf( "%.2f [EUR %.2f]\n", $Montant, $MontantEUR ) ;
}
}
sub build_invoice {
my $invoice = shift ;
return if ! $invoice ;
my $action = $action_of_invoice{ $invoice } ;
my $refund = '' ;
$refund = 'REFUND ' if $invoice_refund{ $invoice } ;
my %action = %$action if $action ;
#print Data::Dumper->Dump( [$action] ) ;
my( $Date, $Heure, $Nom, $Type, $Etat, $Devise, $Hors_taxe, $Commission, $Net,
$De_l_adresse_email, $A_l_adresse_email, $N_de_transaction, $Titre_de_l_objet,
$TVA, $Nom_Option_1, $Valeur_Option_1, $N_de_transaction_de_reference,
$Adresse_1, $Adresse_2_district_quartier, $Ville,
$Etat_Province, $Code_postal, $Pays, $line_number, $line_csv, $file_csv )
= @action{ ( 'Date', 'Heure', 'Nom', 'Type', 'Etat', 'Devise', 'Hors taxe', 'Commission', 'Net',
"De l'adresse email", "A l'adresse email", 'N° de transaction', "Titre de l'objet",
'TVA', 'Nom Option 1', 'Valeur Option 1', 'Nº de transaction de référence',
'Adresse 1', 'Adresse 2/district/quartier', 'Ville',
'Etat/Province/Région/Comté/Territoire/Préfecture/République', 'Code postal', 'Pays', 'line_number', 'line_csv', 'file_csv' ) } ;
#print "$Hors_taxe $Devise\n" ;
my $Hors_taxe_num = $Hors_taxe ;
$Hors_taxe_num =~ s{,}{.} ;
if ($Hors_taxe_num > 100) {
print "invoice $invoice $Hors_taxe_num > 100\n" ;
#return() ;
}
my ( $email_message_header, $email_message_body )
= build_email_message( $Date, $Nom, $De_l_adresse_email, $invoice ) ;
if ( $write_invoices and ! invoice_sent( $dir_invoices, $invoice, $De_l_adresse_email ) ) {
write_email_message( $dir_invoices, $invoice,
$email_message_header, $email_message_body,
$De_l_adresse_email) ;
write_csv_info( $dir_invoices, $invoice, $file_csv, $line_number, $line_csv ) ;
}
#print "==== $invoice $refund=================================================" ;
#print $email_message ;
my(
$clientAdrA,
$clientAdrB,
$clientAdrC,
$clientAdrD,
$clientAdrE,
$clientAdrF,
)
= build_adress(
$Nom,
$Adresse_1,
$Adresse_2_district_quartier,
$Ville,
$Code_postal,
$Etat_Province,
$Pays,
) ;
foreach my $str (
$De_l_adresse_email,
$Nom,
$clientAdrA,
$clientAdrB,
$clientAdrC,
$clientAdrD,
$clientAdrE,
$clientAdrF,
) {
$str =~ s{#}{\\#}g ;
$str =~ s{_}{\\_}g ;
$str =~ s{&}{\\&}g ;
}
my ( $clientTypeEN, $clientTypeFR ) = client_type( $Nom_Option_1, $Valeur_Option_1 ) ;
my (
$priceHT,
$tvaFR,
$tvaEN,
$priceTVA,
$priceTTC,
$messageTVAFR,
$messageTVAEN,
$priceTTCusd
)
= tva_stuff( $clientTypeEN, $Pays, $Hors_taxe, $Devise ) ;
my ( $urlSrc, $urlExe ) = download_urls( $Date ) ;
my $tex_variables = qq{
%% Begin input from $0
\\providecommand{\\invoiceNumber}{$invoice}
\\providecommand{\\clientName}{$Nom}
\\providecommand{\\clientEmail}{$De_l_adresse_email}
\\providecommand{\\clientTypeEN}{$clientTypeEN}
\\providecommand{\\clientTypeFR}{$clientTypeFR}
\\providecommand{\\clientAdrA}{$clientAdrA}
\\providecommand{\\clientAdrB}{$clientAdrB}
\\providecommand{\\clientAdrC}{$clientAdrC}
\\providecommand{\\clientAdrD}{$clientAdrD}
\\providecommand{\\clientAdrE}{$clientAdrE}
\\providecommand{\\clientAdrF}{$clientAdrF}
\\providecommand{\\invoiceDate}{$Date}
\\providecommand{\\invoiceHour}{$Heure}
\\providecommand{\\priceHT}{$priceHT}
\\providecommand{\\tvaFR}{$tvaFR}
\\providecommand{\\tvaEN}{$tvaEN}
\\providecommand{\\priceTVA}{$priceTVA}
\\providecommand{\\priceTTC}{$priceTTC}
\\providecommand{\\priceTTCusd}{$priceTTCusd}
\\providecommand{\\messageTVAFR}{$messageTVAFR}
\\providecommand{\\messageTVAEN}{$messageTVAEN}
\\providecommand{\\urlSrc}{\\url{$urlSrc}}
\\providecommand{\\urlExe}{\\url{$urlExe}}
%% End input from $0
} ;
#print $tex_variables ;
#print "$invoice ", invoice_sent( $dir_invoices, $invoice, $De_l_adresse_email ), "\n" ;
if ( $write_invoices and ! invoice_sent( $dir_invoices, $invoice, $De_l_adresse_email ) ) {
write_tex_variables_file( $dir_invoices, $invoice, $Date, $tex_variables ) ;
}
}
sub build_email_message {
my ( $date, $name, $email, $invoice ) = @_ ;
my $message_header = qq{X-imapsync: invoice $invoice
From: Gilles LAMIRAL <gilles.lamiral\@laposte.net>
Bcc: gilles\@lamiral.info
Subject: [imapsync invoice] $invoice ($date)
Disposition-Notification-To: Gilles LAMIRAL <gilles.lamiral\@laposte.net>
} ;
my $message_body = qq{
Hello $name,
First of all, I'm sorry for the delay in getting back to you.
You'll find in the attachment the invoice of imapsync software you bought ($date).
The invoice file is named facture_imapsync-${invoice}.pdf
This invoice is in PDF format, ready to be print.
Should you need a hardcopy of this invoice,
I'll send it to you upon request by regular mail.
As the law requires, this numeric invoice PDF file
is signed with my private gpg key.
The resulting gpg signature is in the file named
facture_imapsync-${invoice}.pdf.asc
you will also find in the attachment.
You can check I (Gilles LAMIRAL) really did generate
this invoice with the following command line:
gpg --verify facture_imapsync-${invoice}.pdf.asc facture_imapsync-${invoice}.pdf
or any other gpg graphical tool.
Once more, thank you for buying and using imapsync.
Any feedback is welcome.
--
Best Regards, 09 51 84 42 42
Gilles Lamiral. France, Baulon (35580) 06 20 79 76 06
} ;
my $message_body_blabla = qq{
Here is the fingerprint of my public key
pub 1024D/FDA2B3DC 2002-05-08
Key fingerprint = 7906 F53D 0D62 0C67 304A 4CF0 6928 869B FDA2 B3DC
uid Gilles LAMIRAL <gilles.lamiral\@laposte.net>
sub 1024g/A2C4CB42 2002-05-08
Of course the verification doesn't prove anything until
all the following conditions are met:
- you met me,
- I agree that the fingerprint above is really mine
- I prove I'm Gilles LAMIRAL with an official paper.
Normally we won't have to verify anything unless
I disagree with this invoice and the payment
you made for imapsync.
} ;
return( $message_header, $message_body ) ;
}
sub write_csv_info {
my( $dir_invoices, $invoice, $file_csv, $line_number, $line_csv ) = @_ ;
open( CSVINFO, "> $dir_invoices/$invoice/csv_info.txt") or die ;
print CSVINFO join( "\n", $file_csv, $line_number, $line_csv ) ;
close( CSVINFO ) ;
}
sub invoice_sent {
my ( $dir_invoices, $invoice, $email_address ) = @_ ;
return( 1 ) if ( -f "$dir_invoices/$invoice/SENT_TO_$email_address" ) ;
return( 0 ) ;
}
sub write_email_message {
my ( $dir_invoices, $invoice, $message_header, $message_body, $email_address ) = @_ ;
my $message_body_utf8 = to_utf8({ -string => $message_body, -charset => 'ISO-8859-1' });
mkdir( "$dir_invoices/$invoice" ) or die if ! -d "$dir_invoices/$invoice" ;
open( HEADER, "> $dir_invoices/$invoice/facture_message_header.txt") or die ;
print HEADER $message_header ;
close( HEADER ) ;
open( BODY, "> $dir_invoices/$invoice/facture_message_body.txt") or die ;
print BODY $message_body_utf8 ;
close( BODY ) ;
open( ADDRESS, "> $dir_invoices/$invoice/email_address.txt") or die ;
print ADDRESS "$email_address\n" ;
close( ADDRESS ) ;
}
sub write_tex_variables_file {
my ( $dir_invoices, $invoice, $date_jjSmmSaaaa, $tex_variables ) = @_ ;
my $tex_variables_utf8 = to_utf8({ -string => $tex_variables, -charset => 'ISO-8859-1' });
mkdir( "$dir_invoices/$invoice" ) or die if ! -d "$dir_invoices/$invoice" ;
open( FILE, "> $dir_invoices/$invoice/imapsync_var.tex") or die ;
print FILE $tex_variables_utf8 ;
close( FILE ) ;
}
sub download_urls {
my $date_jjSmmSaaaa = shift ;
my $date_aaaa_mm_jj = date_aaaa_mm_jj( $date_jjSmmSaaaa ) ;
# print "$date_aaaa_mm_jj $date_jjSmmSaaaa\n" ;
my ( $urlSrc, $urlExe ) ;
if ('2011_03_24' le $date_aaaa_mm_jj) {
$urlSrc = 'http://www.linux-france.org/prj/imapsync/paypal_return.shtml' ;
$urlExe = '' ;
return( $urlSrc, $urlExe ) ;
}
if ('2011_02_21' le $date_aaaa_mm_jj) {
$urlSrc = 'http://www.linux-france.org/depot/2011_02_21/OUMbo7/' ;
$urlExe = 'http://www.linux-france.org/depot/2011_02_21/rHSVNs/' ;
return( $urlSrc, $urlExe ) ;
}
if ('2011_01_18' le $date_aaaa_mm_jj) {
$urlSrc = 'http://www.linux-france.org/depot/2011_01_18/zPRRNt/' ;
$urlExe = 'http://www.linux-france.org/depot/2011_01_18/FO1QzG/' ;
return( $urlSrc, $urlExe ) ;
}
if ('2011_01_18' le $date_aaaa_mm_jj) {
$urlSrc = 'http://www.linux-france.org/depot/2010_11_28/SiNdlZ/' ;
$urlExe = 'http://www.linux-france.org/depot/2010_11_28/R3ZAyr/' ;
return( $urlSrc, $urlExe ) ;
}
$urlSrc = 'http://www.linux-france.org/depot/2010_11_08/X2PWMe/' ;
$urlExe = 'http://www.linux-france.org/depot/2010_11_08/ZZ7zSc/' ;
return( $urlSrc, $urlExe ) ;
}
sub date_aaaa_mm_jj {
my $date_jjSmmSaaaa = shift ;
if ( $date_jjSmmSaaaa =~ m{(\d\d)/(\d\d)/(\d\d\d\d)} ) {
my( $jj, $mm, $aaaa ) = ( $1, $2, $3 ) ;
return( join( '_', $aaaa, $mm, $jj ) ) ;
}else{
return( '9999_12_31' ) ;
}
}
sub tva_line {
my( $Devise, $Montant2, $Pays, $Nom_Option_1, $Valeur_Option_1 ) = @_ ;
my( $montant_HT_EUR_exo, $montant_HT_EUR_ass, $montant_TVA_EUR ) ;
$Montant2 = $Montant2/$usdeur if 'USD' eq $Devise ;
if (
( 'imapsync usage' eq $Nom_Option_1 and 'individual' eq $Valeur_Option_1 )
or
( 'France' eq $Pays )
) {
$montant_HT_EUR_exo = 0 ;
$montant_HT_EUR_ass = $Montant2 / 1.196 ;
$montant_TVA_EUR = $Montant2 / 1.196 * 0.196 ;
$debug_dev and print "$Montant2 $Pays $Valeur_Option_1\n" ;
}else{
$montant_HT_EUR_exo = $Montant2 ;
$montant_HT_EUR_ass = 0 ;
$montant_TVA_EUR = 0 ;
}
return( $montant_HT_EUR_exo, $montant_HT_EUR_ass, $montant_TVA_EUR ) ;
}
sub tva_stuff {
my( $clientTypeEN, $Pays, $Hors_taxe, $Devise ) = @_ ;
my $priceTTCusd = '' ;
$Hors_taxe =~ s{,}{.} ;
if ( $Devise eq 'USD' ) {
$priceTTCusd = "(usd $Hors_taxe)" ;
$Hors_taxe = ( $Hors_taxe/$usdeur ) ;
}
my (
$priceHT,
$tvaFR,
$tvaEN,
$priceTVA,
$priceTTC,
$messageTVAFR,
$messageTVAEN,
) ;
if ( ( 'individual' eq $clientTypeEN)
or
( 'France' eq $Pays )
) {
$priceHT = sprintf('%2.2f', $Hors_taxe/1.196) ;
$tvaFR = '19,60\%';
$tvaEN = '';
$priceTVA = sprintf('%2.2f', $Hors_taxe/1.196*0.196) ;
$priceTTC = sprintf('%2.2f', $Hors_taxe) ;
$messageTVAFR = '';
$messageTVAEN = '';
}else{
$priceHT = sprintf('%2.2f', $Hors_taxe) ;
$tvaFR = 'néant';
$tvaEN = '(none)';
$priceTVA = 0 ;
$priceTTC = $priceHT;
$messageTVAFR = 'Exonération de TVA, article 259 B-1 du Code Général des Impôts';
$messageTVAEN = '(VAT tax-exempt, article 259 B-1 French General Tax Code)';
}
foreach my $price ( $priceHT, $priceTVA, $priceTTC, $priceTTCusd ) {
#print "[$price]\n" ;
$price =~ s{\.}{, } ;
}
return(
$priceHT,
$tvaFR,
$tvaEN,
$priceTVA,
$priceTTC,
$messageTVAFR,
$messageTVAEN,
$priceTTCusd
) ;
}
sub client_type {
my ( $Nom_Option_1, $Valeur_Option_1 ) = @_ ;
my ( $clientTypeEN, $clientTypeFR ) = ( 'professional', 'professionnel' ) ;
if ('imapsync usage' eq $Nom_Option_1 and 'individual' eq $Valeur_Option_1 ) {
$clientTypeEN = 'individual' ;
$clientTypeFR = 'individuel' ;
}elsif ('imapsync usage' eq $Nom_Option_1 and 'professional' eq $Valeur_Option_1 ) {
$clientTypeEN = 'professional' ;
$clientTypeFR = 'professionnel' ;
}
return( $clientTypeEN, $clientTypeFR ) ;
}
sub build_adress {
my(
$Nom,
$Adresse_1,
$Adresse_2_district_quartier,
$Ville,
$Code_postal,
$Etat_Province,
$Pays,
) = @_ ;
my $addr = "
===========================================================
Nom $Nom
Adresse_1 $Adresse_1
Adresse_2_district_quartier $Adresse_2_district_quartier
Ville Code_postal $Ville $Code_postal
Etat_Province $Etat_Province
Pays $Pays
" ;
#print $addr ;
my @address ;
$Nom = '' if ( $Nom =~ m/^\s+$/ ) ;
push( @address, $Nom ) if $Nom ;
push( @address, $Adresse_1 ) if $Adresse_1 ;
push( @address, $Adresse_2_district_quartier ) if $Adresse_2_district_quartier ;
push( @address, "$Ville $Code_postal" ) if ( $Ville or $Code_postal );
push( @address, $Etat_Province ) if $Etat_Province ;
push( @address, $Pays, ) if $Pays ;
my $clientAdrA = shift( @address ) || '' ;
my $clientAdrB = shift( @address ) || '' ;
my $clientAdrC = shift( @address ) || '' ;
my $clientAdrD = shift( @address ) || '' ;
my $clientAdrE = shift( @address ) || '' ;
my $clientAdrF = shift( @address ) || '' ;
$addr = "
[$clientAdrA]
[$clientAdrB]
[$clientAdrC]
[$clientAdrD]
[$clientAdrE]
[$clientAdrF]
";
#print $addr ;
return(
$clientAdrA,
$clientAdrB,
$clientAdrC,
$clientAdrD,
$clientAdrE,
$clientAdrF,
) ;
}