use JSON::MaybeXS qw/encode_json decode_json/;
use Plack::Builder;
use Plack::Request;
+use Text::CSV;
use Try::Tiny;
sub HTML::Element::iter3 {
$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:');
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]];
}