From 7771514bdfdbb08865ebb8028eef6277a7caba04 Mon Sep 17 00:00:00 2001 From: Sergiotarxz Date: Sat, 16 Sep 2023 20:53:05 +0200 Subject: [PATCH] Improvements. --- burguillos.svg | 106 ++++++++++++++++++ config.example.json | 3 +- example_bill.sh | 12 +- lib/Owlcode/Tech/Facturer.pm | 4 + lib/Owlcode/Tech/Facturer/MainCommand.pm | 134 +++++++++++++++++++---- 5 files changed, 232 insertions(+), 27 deletions(-) create mode 100644 burguillos.svg diff --git a/burguillos.svg b/burguillos.svg new file mode 100644 index 0000000..93b7927 --- /dev/null +++ b/burguillos.svg @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config.example.json b/config.example.json index fc2da50..fcca217 100644 --- a/config.example.json +++ b/config.example.json @@ -2,5 +2,6 @@ "fullname": "Pepito el de los Palotes", "dni": "12345678A", "address": "Calle Salvador Allende S/N", - "postal_code": "13243" + "postal_code": "13243", + "img": "burguillos.svg" } diff --git a/example_bill.sh b/example_bill.sh index 07e2a5b..62adea2 100644 --- a/example_bill.sh +++ b/example_bill.sh @@ -4,13 +4,13 @@ echo '8' echo 'y' echo '2' - echo 'Example concept' + echo '32123123F' + echo 'Peppa Pig' + echo '32454' + echo 'Calle República 14' + echo 'Concepto de prueba' echo '1' - echo '20.03' - echo 'y' - echo 'Example concept 2' - echo '2' - echo '20.03' + echo '20.00' echo 'n' ) | perl -Ilib scripts/facturer.pl diff --git a/lib/Owlcode/Tech/Facturer.pm b/lib/Owlcode/Tech/Facturer.pm index 61d726b..1b27fad 100644 --- a/lib/Owlcode/Tech/Facturer.pm +++ b/lib/Owlcode/Tech/Facturer.pm @@ -32,6 +32,10 @@ sub postal_code ($self) { return $self->config->{postal_code}; } +sub image ($self) { + return $ROOT_PATH->child($self->config->{img}); +} + sub _build_config { my $config_path = $ROOT_PATH->child('config.json'); return decode_json( $config_path->slurp_utf8 ); diff --git a/lib/Owlcode/Tech/Facturer/MainCommand.pm b/lib/Owlcode/Tech/Facturer/MainCommand.pm index 9b58e2c..0b62183 100644 --- a/lib/Owlcode/Tech/Facturer/MainCommand.pm +++ b/lib/Owlcode/Tech/Facturer/MainCommand.pm @@ -24,6 +24,7 @@ my $IVA_INCLUDED = 1; my $IVA_NOT_INCLUDED = 2; binmode STDOUT, ':utf8'; +binmode STDIN, ':utf8'; sub run ($self) { my $app = Owlcode::Tech::Facturer->new; @@ -32,8 +33,11 @@ sub run ($self) { my $self_dni = $app->dni; my $self_address = $app->address; my $self_postal_code = $app->postal_code; + my $logo = $app->image; my $client_dni; my $client_name; + my $client_postal_code; + my $client_address; say "Tu nombre completo es $self_name."; say "Tu dni es $self_dni."; @@ -47,31 +51,37 @@ sub run ($self) { my $kind_of_bill = $self->ask_kind_of_bill; say $kind_of_bill; if ( $kind_of_bill eq $COMPLETA ) { - $client_dni = $self->ask_for_client_dni; - $client_name = $self->ask_for_client_name; + $client_dni = $self->ask_for_client_dni; + $client_name = $self->ask_for_client_name; + $client_postal_code = $self->ask_for_client_postal_code; + $client_address = $self->ask_for_client_address; } my $concepts = $self->ask_for_concepts; print 'Los conceptos son: ' . Data::Dumper::Dumper $concepts; my $final_data = $self->final_data($concepts); my $mt = Mojo::Template->new( auto_escape => 1 ); + require MIME::Base64; path("FACTURA @{[sprintf '%06d', $number]}.html")->spew_utf8( $mt->vars(1)->render( $self->template_bill, { - self_name => $self_name, - self_dni => $self_dni, - self_address => $self_address, - self_postal_code => $self_postal_code, - client_dni => $client_dni, - client_name => $client_name, - number => $number, - date => $self->print_date($date), - kind_of_bill => $kind_of_bill, - SIMPLIFICADA => $SIMPLIFICADA, - COMPLETA => $COMPLETA, - concepts => $concepts, - final_data => $final_data, + self_name => $self_name, + self_dni => $self_dni, + self_address => $self_address, + self_postal_code => $self_postal_code, + client_dni => $client_dni, + client_name => $client_name, + client_address => $client_address, + client_postal_code => $client_postal_code, + number => $number, + date => $self->print_date($date), + kind_of_bill => $kind_of_bill, + SIMPLIFICADA => $SIMPLIFICADA, + COMPLETA => $COMPLETA, + concepts => $concepts, + final_data => $final_data, + logo => MIME::Base64::encode_base64($logo->slurp_raw), } ) ); @@ -83,15 +93,59 @@ sub template_bill ($self) { -

Factura número <%= sprintf '%06d', $number %>

+
+ +

Factura <%=$kind_of_bill eq $SIMPLIFICADA ? 'Simplificada' : 'Completa'%>

-

Datos emisor.

+

Datos de factura

-

Emitida por <%= $self_name %> con DNI/CIF <%= $self_dni %> en fecha <%= $date %>.

+ + + + + + + + + +
Fecha<%=$date%>
Número<%=$number%>
+ +

Datos de emisión recepción.

+ + + + + + + + + + + + + + + + % if ($kind_of_bill eq $COMPLETA) { -

Datos receptor.

-

Destinatario <%= $client_name %> con DNI/CIF <%= $client_dni %>.

+ + + + + + + +% } else { + + + + + + + % } +
Nombre CompletoDNI/CIF/NIECódigo postalDirección
Emisor<%= $self_name %><%= $self_dni %><%= $self_postal_code %><%= $self_address %>
Receptor<%= $client_name %><%= $client_dni %><%= $client_postal_code %><%= $client_address %>
ReceptorClientes varios---------
+

Desglose factura.

@@ -124,6 +178,24 @@ sub template_bill ($self) {
<%=$final_data->{total}%>€
+
+ EOF @@ -150,6 +222,28 @@ sub final_data ( $self, $concepts ) { }; } +sub ask_for_client_postal_code ($self) { + my $input; + while ( !defined $input || $input =~ /^\s*$/ ) { + print "Introduce el código postal del cliente o su empresa +> "; + $input = ; + chomp $input; + } + return $input; +} + +sub ask_for_client_address ($self) { + my $input; + while ( !defined $input || $input =~ /^\s*$/ ) { + print "Introduce la dirección (calle y número) del cliente o su empresa +> "; + $input = ; + chomp $input; + } + return $input; +} + sub ask_for_client_name ($self) { my $input; while ( !defined $input || $input =~ /^\s*$/ ) {