--- /dev/null
+#!/usr/bin/env perl
+use strict;
+use warnings;
+#################################################################################
+#
+# VERSION
+#
+#################################################################################
+my $VERSION = '0.0.1';
+# NB 22.07.14
+# - create script
+
+#################################################################################
+#
+# GLOBALS
+#
+#################################################################################
+my ($NAME) = $0 =~ m,([^/]+)$,;
+
+#################################################################################
+#
+# ARGS
+#
+#################################################################################
+my $VERBOSE = $main::VERBOSE = 0;
+my $DEBUG = $main::DEBUG = 0;
+my $DATE_FORMAT = '%d/%m/%Y';
+my $TEMPLATE = $ENV{HOME}.'/doc/Rent/Quittance.html';
+my $LODGER = 'Stephane Boutiot';
+my $ADDR1 = '174 Avenue Raymond Naves';
+my $ADDR2 = '31300 Toulouse';
+
+my %Opt; get_options(\%Opt);
+help() unless @ARGV;
+$main::_DATA_ = undef;
+
+#################################################################################
+#
+# BEGIN
+#
+#################################################################################
+use Data::Dumper;
+use Date::Manip qw(ParseDate UnixDate DateCalc);
+ use File::Basename;
+
+open(TEMPLATE,$TEMPLATE) or die "$NAME: can't read $TEMPLATE";
+my $template = join('',<TEMPLATE>);
+close TEMPLATE;
+
+#chdir dirname($TEMPLATE);
+for my $date (@ARGV) {
+
+ my $date1 = ParseDate($date);
+ my $next_month = ParseDate(DateCalc($date,'+1 month'));
+ my $date2 = ParseDate(DateCalc($next_month,'-1 day'));
+
+ $date1 = UnixDate($date1,$DATE_FORMAT);
+ $date2 = UnixDate($date2,$DATE_FORMAT);
+ $next_month = UnixDate($next_month,$DATE_FORMAT);
+
+ $_ = $template;
+ s/\[DATE1\]/$date1/g;
+ s/\[DATE2\]/$date2/g;
+ s/\[NEXT_MONTH\]/$next_month/g;
+ s/\[ADDR1\]/$ADDR1/g;
+ s/\[ADDR2\]/$ADDR2/g;
+ s/\[LODGER\]/$LODGER/g;
+ print "$LODGER: $next_month from $date1 to $date2 -> Quittance-$date.pdf\n";
+ next if $DEBUG;
+ #open(PDF,"| htmldoc --encryption --quiet --webpage --no-title --header '...' --footer '...' -t pdf - > Quittance-$date.pdf") or die "$NAME: can't write into $date.pdf";
+ open(PDF,"| wkhtmltopdf ".($VERBOSE ? '' : '--quiet ')."- Quittance-$date.pdf") or die "$NAME: can't write into $date.pdf";
+ print PDF $_;
+ close PDF;
+
+}
+
+#################################################################################
+#
+# END
+#
+#################################################################################
+exit 0;
+
+#################################################################################
+#
+# Functions
+#
+#################################################################################
+
+sub help {
+#------------------------------------------------------------------------------
+# Print help and exit
+#------------------------------------------------------------------------------
+
+ require 'Pod/Usage.pm' unless $INC{'Pod/Usage.pm'};
+ require 'Pod/Perldoc.pm' unless $INC{'Pod/Perldoc.pm'};
+
+ # Substitutions
+ sub pod_env {
+ my $v = '';
+ eval '$v = ref(\\'.$_[0].') eq "ARRAY" ? join(" ",'.$_[0].') : '.$_[0].'; return defined $v ? $v : qq|UNDEF|;';
+ return $v;
+ }
+
+ $main::_DATA_ =~ s/([@\$][A-Z_]+)/pod_env($1)/eg;
+
+ # Create tmp
+ my $in_file = (-e '/dev/shm' ? '/dev/shm' : '/tmp')."/$NAME.$$";
+ my $in;
+ open($in,">$in_file") or die "$NAME: Can't write into $in_file: $!";
+ print $in $main::_DATA_;
+ close $in;
+
+ # Output
+ open(STDOUT,"|perl -pe 's/\.$$//g'".(($ENV{PAGER}||'') eq 'less' ? "|less -FRi" : ""));
+ my $opts = {
+ -input => $in_file,
+ -ouput => \*STDOUT,
+ -exitval => 'noexit',
+ -sections => [qw(SYNOPSIS DESCRIPTION OPTIONS)],
+ -verbose => ($Opt{'help'} ? 99 : 3),
+ };
+
+ Pod::Usage::pod2usage($opts);
+ close STDOUT;
+ unlink $in_file if $in_file and -e $in_file;
+
+ exit 0;
+}
+
+#------------------------------------------------------------------------------
+# Print version and exit
+#------------------------------------------------------------------------------
+sub version { print "$NAME: version [$VERSION]\n"; exit 0; }
+
+#------------------------------------------------------------------------------
+# Get options from pod
+#------------------------------------------------------------------------------
+sub get_options {
+
+ use Getopt::Long qw(:config no_ignore_case no_auto_abbrev);
+
+ my @Opt;
+
+ sub pod_opt {
+ local $_;
+ my $o = shift;
+ $o =~ s/(=.|[\+\-\!]$)//;
+ $o = join(", ",map{"-$_"} split(/[\|,:;]/,$o));
+ return "$o";
+ }
+
+ while (<DATA>) {
+ s/option\[([^\]]+)\]/push(@Opt,$1) and pod_opt($1)/eg;
+ $main::_DATA_ .= $_;
+ }
+
+ GetOptions($_[0],@Opt) || exit -1;
+
+ help() if $_[0]{'help'} or $_[0]{'man'};
+ version() if $_[0]{'version'};
+
+ $main::VERBOSE = $VERBOSE = $_[0]{'verbose'} if defined $_[0]{'verbose'};
+ $main::DEBUG = $DEBUG = $_[0]{'debug'} if defined $_[0]{'debug'};
+
+}
+
+__DATA__
+
+=head1 NAME
+
+$NAME - Generate quitance
+
+=head1 SYNOPSIS
+
+Quick usage: $NAME YYYY-MM YYYY-MM
+
+=over
+
+=item $NAME --verbose
+
+=item $NAME --help
+
+=back
+
+=head1 DESCRIPTION
+
+...
+
+=head1 OPTIONS
+
+=over 2
+
+=item B<option[verbose|v+]> Verbose mode: increase the verbosity level.
+
+=item B<option[debug+]> Debug mode: increase the verbosity level.
+
+=item B<option[version|V]> Print version (default: $VERSION)
+
+=item B<option[help|h|?]> Print a brief help message and exits.
+
+=item B<option[man]> Prints the manual page and exits.
+
+=back
+
+=cut
+
+=head1 EXAMPLES
+
+...
+
+=head1 REQUIRES
+
+Getopt::Std, Pod::Usage
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2014 Nicolas Boisselier
+
+This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+See <http://www.gnu.org/licenses/>.
+
+=head1 SEE ALSO
+
+perl(1), http://perldoc.perl.org/perlpodstyle.html
+
+=head1 AUTHOR
+
+Nicolas Boisselier nicolas.boisselier@gmail.com
+
+=cut