2019-07-02 14:21:01 +00:00
|
|
|
package Pear::LocalLoop::Controller::Admin::ImportFrom;
|
|
|
|
use Mojo::Base 'Mojolicious::Controller';
|
2019-07-05 14:30:31 +00:00
|
|
|
use Moo;
|
2019-07-04 13:16:49 +00:00
|
|
|
use Devel::Dwarn;
|
2019-07-02 14:21:01 +00:00
|
|
|
|
2019-07-05 14:30:31 +00:00
|
|
|
use Pear::LocalLoop::Import::LCCCsv::Suppliers;
|
|
|
|
|
2019-07-04 13:16:49 +00:00
|
|
|
sub index {
|
|
|
|
my $c = shift;
|
|
|
|
|
2019-07-05 14:30:31 +00:00
|
|
|
$c->app->max_request_size(104857600);
|
2019-07-04 13:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub post_suppliers {
|
|
|
|
my $c = shift;
|
|
|
|
|
2019-07-05 14:30:31 +00:00
|
|
|
unless ($c->param('suppliers_csv')) {
|
|
|
|
$c->flash( error => "No CSV file given" );
|
|
|
|
return $c->redirect_to( '/admin/import_from' );
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check file size
|
|
|
|
if ($c->req->is_limit_exceeded) {
|
|
|
|
$c->flash( error => "CSV file size is too large" );
|
|
|
|
return $c->redirect_to( '/admin/import_from' );
|
|
|
|
}
|
|
|
|
my $csv_import = Pear::LocalLoop::Import::LCCCsv::Suppliers->new(
|
|
|
|
csv_string => $c->param('suppliers_csv')->slurp,
|
|
|
|
schema => $c->app->schema
|
|
|
|
)->import_csv;
|
|
|
|
|
|
|
|
$c->flash( success => "CSV imported" );
|
2019-07-04 13:16:49 +00:00
|
|
|
return $c->redirect_to( '/admin/import_from' );
|
|
|
|
}
|
|
|
|
|
|
|
|
sub post_transactions {
|
|
|
|
my $c = shift;
|
|
|
|
|
2019-07-05 14:30:31 +00:00
|
|
|
unless ($c->param('transactions_csv')) {
|
|
|
|
$c->flash( error => "No CSV file given" );
|
|
|
|
return $c->redirect_to( '/admin/import_from' );
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check file size
|
|
|
|
if ($c->req->is_limit_exceeded) {
|
|
|
|
$c->flash( error => "CSV file size is too large" );
|
|
|
|
return $c->redirect_to( '/admin/import_from' );
|
|
|
|
}
|
|
|
|
|
|
|
|
my $csv_import = Pear::LocalLoop::Import::LCCCsv::Suppliers->import( $c->param('transactions_csv') );
|
|
|
|
|
|
|
|
$c->flash( success => "CSV imported" );
|
2019-07-04 13:16:49 +00:00
|
|
|
return $c->redirect_to( '/admin/import_from' );
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|