]> iEval git - app-web-oof.git/commitdiff
Add delivery CSV for myHermes to the orders display
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 28 May 2016 20:44:26 +0000 (21:44 +0100)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 28 May 2016 20:44:26 +0000 (21:44 +0100)
Makefile.PL
README
lib/App/Web/Oof.pm
tmpl/display.html

index fb896ce28baa724a02ac9e747d7f688cd20bc581..e50ee441f168c4bec135d1ac748c5c24159ddec2 100644 (file)
@@ -19,6 +19,7 @@ WriteMakefile(
                   HTML::TreeBuilder      0
                   HTML::Element::Library 0
                   JSON::MaybeXS          0
+                  Text::CSV              0
                   Try::Tiny              0/,
        },
        META_ADD         => {
diff --git a/README b/README
index 5a4876c00957d5ed111a80a093deaeb059465994..857267c402375aebccc4cf40f82644ee9cdba9f6 100644 (file)
--- a/README
+++ b/README
@@ -29,6 +29,7 @@ This module requires these other modules and libraries:
 * HTML::Element
 * HTML::Element::Library
 * JSON::MaybeXS
+* Text::CSV
 * Try::Tiny
 
 COPYRIGHT AND LICENCE
index 1294c168a9687da7c5155054d7b3a992eb165881..2fba9bedaf5730ba0fffe55c0d5caddd7643d1b6 100644 (file)
@@ -17,6 +17,7 @@ use HTML::Element::Library;
 use JSON::MaybeXS qw/encode_json decode_json/;
 use Plack::Builder;
 use Plack::Request;
+use Text::CSV;
 use Try::Tiny;
 
 sub HTML::Element::iter3 {
@@ -310,6 +311,16 @@ sub display_order {
        $div->fclass('stripe_token')->replace_content($data->{stripe_token}) if $data->{stripe_token};
 }
 
+my $csv_header = 'Address_line_1,Address_line_2,Address_line_3,Address_line_4,Postcode,First_name,Last_name,Email,Weight(Kg),Compensation(�),Signature(y/n),Reference,Contents,Parcel_value(�),Delivery_phone,Delivery_safe_place,Delivery_instructions' . "\n";
+
+sub make_hermes_csv {
+       my ($order) = @_;
+       my $csv = Text::CSV->new;
+       my @fields = map { $order->{$_} } qw/address1 address2 address3 address4 postcode first_name last_name email/;
+       $csv->combine(@fields, '', '', 'n', '', '', '', $order->{phone}, $order->{safe_place}, $order->{instructions});
+       $csv->string
+}
+
 sub display_app {
        my ($env) = @_;
        $db{$$} //= DBIx::Simple->connect($ENV{OOF_DSN} // 'dbi:Pg:');
@@ -318,6 +329,8 @@ sub display_app {
        my @orders = $db{$$}->query("SELECT * FROM orders ORDER BY date DESC LIMIT $n")->hashes;
        my $tree = $display->clone;
        $tree->fclass('order')->iter3(\@orders, \&display_order);
+       my $csv = join "\n", map { make_hermes_csv $_ } @orders;
+       $tree->fid('hermes_csv')->replace_content($csv_header . $csv);
        [200, ['Content-type' => 'text/html; charset=utf-8'], [$tree->as_HTML]];
 }
 
index 12323a21c3729271ed94dff5ddd1cf251d3c8c9f..95da05f91f36b397456c67ece81dea9534529c85 100644 (file)
@@ -15,3 +15,5 @@ From <span class="name"></span>
 <p>Stripe token: <span class="stripe_token">[None]</span></p>
 <hr>
 </div>
+
+<pre id="hermes_csv"></pre>
This page took 0.031723 seconds and 4 git commands to generate.