cd6f4aa303dd5e71e60eb94d50ce3e32850edee9
[srvgit] / Koha / Patrons / Import.pm
1 package Koha::Patrons::Import;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19 use Moo;
20 use namespace::clean;
21
22 use Carp;
23 use Text::CSV;
24 use Encode qw( decode_utf8 );
25 use Try::Tiny;
26
27 use C4::Members;
28
29 use Koha::Libraries;
30 use Koha::Patrons;
31 use Koha::Patron::Categories;
32 use Koha::Patron::Debarments;
33 use Koha::DateUtils;
34
35 =head1 NAME
36
37 Koha::Patrons::Import - Perl Module containing import_patrons method exported from import_borrowers script.
38
39 =head1 SYNOPSIS
40
41 use Koha::Patrons::Import;
42
43 =head1 DESCRIPTION
44
45 This module contains one method for importing patrons in bulk.
46
47 =head1 FUNCTIONS
48
49 =head2 import_patrons
50
51  my $return = Koha::Patrons::Import::import_patrons($params);
52
53 Applies various checks and imports patrons in bulk from a csv file.
54
55 Further pod documentation needed here.
56
57 =cut
58
59 has 'today_iso' => ( is => 'ro', lazy => 1,
60     default => sub { output_pref( { dt => dt_from_string(), dateonly => 1, dateformat => 'iso' } ); }, );
61
62 has 'text_csv' => ( is => 'rw', lazy => 1,
63     default => sub { Text::CSV->new( { binary => 1, } ); },  );
64
65 sub import_patrons {
66     my ($self, $params) = @_;
67
68     my $handle = $params->{file};
69     unless( $handle ) { carp('No file handle passed in!'); return; }
70
71     my $matchpoint           = $params->{matchpoint};
72     my $defaults             = $params->{defaults};
73     my $preserve_fields      = $params->{preserve_fields};
74     my $ext_preserve         = $params->{preserve_extended_attributes};
75     my $overwrite_cardnumber = $params->{overwrite_cardnumber};
76     my $overwrite_passwords  = $params->{overwrite_passwords};
77     my $dry_run              = $params->{dry_run};
78     my $extended             = C4::Context->preference('ExtendedPatronAttributes');
79     my $set_messaging_prefs  = C4::Context->preference('EnhancedMessagingPreferences');
80
81     my $schema = Koha::Database->new->schema;
82     $schema->storage->txn_begin if $dry_run;
83
84     my @columnkeys = $self->set_column_keys($extended);
85     my @feedback;
86     my @errors;
87
88     my $imported    = 0;
89     my $alreadyindb = 0;
90     my $overwritten = 0;
91     my $invalid     = 0;
92     my @imported_borrowers;
93     my $matchpoint_attr_type = $self->set_attribute_types({ extended => $extended, matchpoint => $matchpoint, });
94
95     # Use header line to construct key to column map
96     my %csvkeycol;
97     my $borrowerline = <$handle>;
98     my @csvcolumns   = $self->prepare_columns({headerrow => $borrowerline, keycol => \%csvkeycol, errors => \@errors, });
99     push(@feedback, { feedback => 1, name => 'headerrow', value => join( ', ', @csvcolumns ) });
100
101     my @criticals = qw( surname );    # there probably should be others - rm branchcode && categorycode
102   LINE: while ( my $borrowerline = <$handle> ) {
103         my $line_number = $.;
104         my %borrower;
105         my @missing_criticals;
106
107         my $status  = $self->text_csv->parse($borrowerline);
108         my @columns = $self->text_csv->fields();
109         if ( !$status ) {
110             push @missing_criticals, { badparse => 1, line => $line_number, lineraw => decode_utf8($borrowerline) };
111         }
112         elsif ( @columns == @columnkeys ) {
113             @borrower{@columnkeys} = @columns;
114
115             # MJR: try to fill blanks gracefully by using default values
116             foreach my $key (@columnkeys) {
117                 if ( $borrower{$key} !~ /\S/ ) {
118                     $borrower{$key} = $defaults->{$key};
119                 }
120             }
121         }
122         else {
123             # MJR: try to recover gracefully by using default values
124             foreach my $key (@columnkeys) {
125                 if ( defined( $csvkeycol{$key} ) and $columns[ $csvkeycol{$key} ] =~ /\S/ ) {
126                     $borrower{$key} = $columns[ $csvkeycol{$key} ];
127                 }
128                 elsif ( $defaults->{$key} ) {
129                     $borrower{$key} = $defaults->{$key};
130                 }
131                 elsif ( scalar grep { $key eq $_ } @criticals ) {
132
133                     # a critical field is undefined
134                     push @missing_criticals, { key => $key, line => $., lineraw => decode_utf8($borrowerline) };
135                 }
136                 else {
137                     $borrower{$key} = '';
138                 }
139             }
140         }
141
142         $borrower{cardnumber} = undef if $borrower{cardnumber} eq "";
143
144         # Check if borrower category code exists and if it matches to a known category. Pushing error to missing_criticals otherwise.
145         $self->check_borrower_category($borrower{categorycode}, $borrowerline, $line_number, \@missing_criticals);
146
147         # Check if branch code exists and if it matches to a branch name. Pushing error to missing_criticals otherwise.
148         $self->check_branch_code($borrower{branchcode}, $borrowerline, $line_number, \@missing_criticals);
149
150         # Popular spreadsheet applications make it difficult to force date outputs to be zero-padded, but we require it.
151         $self->format_dates({borrower => \%borrower, lineraw => $borrowerline, line => $line_number, missing_criticals => \@missing_criticals, });
152
153         if (@missing_criticals) {
154             foreach (@missing_criticals) {
155                 $_->{borrowernumber} = $borrower{borrowernumber} || 'UNDEF';
156                 $_->{surname}        = $borrower{surname}        || 'UNDEF';
157             }
158             $invalid++;
159             ( 25 > scalar @errors ) and push @errors, { missing_criticals => \@missing_criticals };
160
161             # The first 25 errors are enough.  Keeping track of 30,000+ would destroy performance.
162             next LINE;
163         }
164
165         # Generate patron attributes if extended.
166         my $patron_attributes = $self->generate_patron_attributes($extended, $borrower{patron_attributes}, \@feedback);
167         if( $extended ) { delete $borrower{patron_attributes}; } # Not really a field in borrowers.
168
169         # Default date enrolled and date expiry if not already set.
170         $borrower{dateenrolled} = $self->today_iso() unless $borrower{dateenrolled};
171         $borrower{dateexpiry} = Koha::Patron::Categories->find( $borrower{categorycode} )->get_expiry_date( $borrower{dateenrolled} ) unless $borrower{dateexpiry};
172
173         my $borrowernumber;
174         my ( $member, $patron );
175         if ( defined($matchpoint) && ( $matchpoint eq 'cardnumber' ) && ( $borrower{'cardnumber'} ) ) {
176             $patron = Koha::Patrons->find( { cardnumber => $borrower{'cardnumber'} } );
177         }
178         elsif ( defined($matchpoint) && ($matchpoint eq 'userid') && ($borrower{'userid'}) ) {
179             $patron = Koha::Patrons->find( { userid => $borrower{userid} } );
180         }
181         elsif ($extended) {
182             if ( defined($matchpoint_attr_type) ) {
183                 foreach my $attr (@$patron_attributes) {
184                     if ( $attr->{code} eq $matchpoint and $attr->{attribute} ne '' ) {
185                         my @borrowernumbers = Koha::Patron::Attributes->search(
186                             {
187                                 code      => $matchpoint_attr_type->code,
188                                 attribute => $attr->{attribute}
189                             }
190                         )->get_column('borrowernumber');
191
192                         $borrowernumber = $borrowernumbers[0] if scalar(@borrowernumbers) == 1;
193                         $patron = Koha::Patrons->find( $borrowernumber );
194                         last;
195                     }
196                 }
197             }
198         }
199
200         if ($patron) {
201             $member = $patron->unblessed;
202             $borrowernumber = $member->{'borrowernumber'};
203         } else {
204             $member = {};
205         }
206
207         if ( C4::Members::checkcardnumber( $borrower{cardnumber}, $borrowernumber ) ) {
208             push @errors,
209               {
210                 invalid_cardnumber => 1,
211                 borrowernumber     => $borrowernumber,
212                 cardnumber         => $borrower{cardnumber}
213               };
214             $invalid++;
215             next;
216         }
217
218
219         # Check if the userid provided does not exist yet
220         if (    defined($matchpoint)
221             and $matchpoint ne 'userid'
222             and exists $borrower{userid}
223             and $borrower{userid}
224             and not ( $borrowernumber ? $patron->userid( $borrower{userid} )->has_valid_userid : Koha::Patron->new( { userid => $borrower{userid} } )->has_valid_userid )
225         ) {
226             push @errors, { duplicate_userid => 1, userid => $borrower{userid} };
227             $invalid++;
228             next LINE;
229         }
230
231         my $guarantor_relationship = $borrower{guarantor_relationship};
232         delete $borrower{guarantor_relationship};
233         my $guarantor_id = $borrower{guarantor_id};
234         delete $borrower{guarantor_id};
235
236         # Remove warning for int datatype that cannot be null
237         # Argument "" isn't numeric in numeric eq (==) at /usr/share/perl5/DBIx/Class/Row.pm line 1018
238         for my $field (
239             qw( privacy privacy_guarantor_fines privacy_guarantor_checkouts anonymized login_attempts ))
240         {
241             delete $borrower{$field}
242               if exists $borrower{$field} and $borrower{$field} eq "";
243         }
244
245         my $success = 1;
246         if ($borrowernumber) {
247
248             # borrower exists
249             unless ($overwrite_cardnumber) {
250                 $alreadyindb++;
251                 push(
252                     @feedback,
253                     {
254                         already_in_db => 1,
255                         value         => $borrower{'surname'} . ' / ' . $borrowernumber
256                     }
257                 );
258                 next LINE;
259             }
260             $borrower{'borrowernumber'} = $borrowernumber;
261
262             if ( $preserve_fields ) {
263                 for my $field ( @$preserve_fields ) {
264                     $borrower{$field} = $patron->$field;
265                 }
266             }
267
268             for my $col ( keys %borrower ) {
269
270                 # use values from extant patron unless our csv file includes this column or we provided a default.
271                 # FIXME : You cannot update a field with a  perl-evaluated false value using the defaults.
272
273                 # The password is always encrypted, skip it unless we are forcing overwrite!
274                 next if $col eq 'password' && !$overwrite_passwords;
275
276                 unless ( exists( $csvkeycol{$col} ) || $defaults->{$col} ) {
277                     $borrower{$col} = $member->{$col} if ( $member->{$col} );
278                 }
279             }
280
281             my $patron = Koha::Patrons->find( $borrowernumber );
282             try {
283                 $schema->storage->txn_do(sub {
284                     $patron->set(\%borrower)->store;
285                     # Don't add a new restriction if the existing 'combined' restriction matches this one
286                     if ( $borrower{debarred} && ( ( $borrower{debarred} ne $member->{debarred} ) || ( $borrower{debarredcomment} ne $member->{debarredcomment} ) ) ) {
287
288                         # Check to see if this debarment already exists
289                         my $debarrments = GetDebarments(
290                             {
291                                 borrowernumber => $borrowernumber,
292                                 expiration     => $borrower{debarred},
293                                 comment        => $borrower{debarredcomment}
294                             }
295                         );
296
297                         # If it doesn't, then add it!
298                         unless (@$debarrments) {
299                             AddDebarment(
300                                 {
301                                     borrowernumber => $borrowernumber,
302                                     expiration     => $borrower{debarred},
303                                     comment        => $borrower{debarredcomment}
304                                 }
305                             );
306                         }
307                     }
308                     if ($patron->category->category_type ne 'S' && $overwrite_passwords && defined $borrower{password} && $borrower{password} ne ''){
309                         try {
310                             $patron->set_password({ password => $borrower{password} });
311                         }
312                         catch {
313                             if ( $_->isa('Koha::Exceptions::Password::TooShort') ) {
314                                 push @errors, { passwd_too_short => 1, borrowernumber => $borrowernumber, length => $_->{length}, min_length => $_->{min_length} };
315                             }
316                             elsif ( $_->isa('Koha::Exceptions::Password::WhitespaceCharacters') ) {
317                                 push @errors, { passwd_whitespace => 1, borrowernumber => $borrowernumber } ;
318                             }
319                             elsif ( $_->isa('Koha::Exceptions::Password::TooWeak') ) {
320                                 push @errors, { passwd_too_weak => 1, borrowernumber => $borrowernumber } ;
321                             }
322                             elsif ( $_->isa('Koha::Exceptions::Password::Plugin') ) {
323                                 push @errors, { passwd_plugin_err => 1, borrowernumber => $borrowernumber } ;
324                             }
325                             else {
326                                 push @errors, { passwd_unknown_err => 1, borrowernumber => $borrowernumber } ;
327                             }
328                         }
329                     }
330                     if ($extended) {
331                         if ($ext_preserve) {
332                             $patron_attributes = $patron->extended_attributes->merge_and_replace_with( $patron_attributes );
333                         }
334                         # We do not want to filter by branch, maybe we should?
335                         Koha::Patrons->find($borrowernumber)->extended_attributes->delete;
336                         $patron->extended_attributes($patron_attributes);
337                     }
338                     $overwritten++;
339                     push(
340                         @feedback,
341                         {
342                             feedback => 1,
343                             name     => 'lastoverwritten',
344                             value    => $borrower{'surname'} . ' / ' . $borrowernumber
345                         }
346                     );
347                 });
348             } catch {
349                 $invalid++;
350                 $success = 0;
351
352                 my $patron_id = defined $matchpoint ? $borrower{$matchpoint} : $matchpoint_attr_type;
353                 if ( $_->isa('Koha::Exceptions::Patron::Attribute::UniqueIDConstraint') ) {
354                     push @errors, { patron_attribute_unique_id_constraint => 1, borrowernumber => $borrowernumber, attribute => $_->attribute };
355                 } elsif ( $_->isa('Koha::Exceptions::Patron::Attribute::InvalidType') ) {
356                     push @errors, { patron_attribute_invalid_type => 1, borrowernumber => $borrowernumber, attribute_type_code => $_->type };
357                 } elsif ( $_->isa('Koha::Exceptions::Patron::Attribute::NonRepeatable') ) {
358                     push @errors, { patron_attribute_non_repeatable => 1, borrowernumber => $borrowernumber, attribute => $_->attribute };
359                 } else {
360                     warn $_;
361                     push @errors, { unknown_error => 1 };
362                 }
363
364                 push(
365                     @errors,
366                     {
367                         # TODO We can raise a better error
368                         name  => 'lastinvalid',
369                         value => $borrower{'surname'} . ' / ' . $borrowernumber
370                     }
371                 );
372             }
373         }
374         else {
375             try {
376                 $schema->storage->txn_do(sub {
377                     my $patron = Koha::Patron->new(\%borrower)->store;
378                     $borrowernumber = $patron->id;
379
380                     if ( $patron->is_debarred ) {
381                         AddDebarment(
382                             {
383                                 borrowernumber => $patron->borrowernumber,
384                                 expiration     => $patron->debarred,
385                                 comment        => $patron->debarredcomment,
386                             }
387                         );
388                     }
389
390                     if ($extended) {
391                         # FIXME Hum, we did not filter earlier and now we do?
392                         $patron->extended_attributes->filter_by_branch_limitations->delete;
393                         $patron->extended_attributes($patron_attributes);
394                     }
395
396                     if ($set_messaging_prefs) {
397                         C4::Members::Messaging::SetMessagingPreferencesFromDefaults(
398                             {
399                                 borrowernumber => $patron->borrowernumber,
400                                 categorycode   => $patron->categorycode,
401                             }
402                         );
403                     }
404
405                     $imported++;
406                     push @imported_borrowers, $patron->borrowernumber; #for patronlist
407                     push(
408                         @feedback,
409                         {
410                             feedback => 1,
411                             name     => 'lastimported',
412                             value    => $patron->surname . ' / ' . $patron->borrowernumber,
413                         }
414                     );
415                 });
416             } catch {
417                 $invalid++;
418                 $success = 0;
419                 my $patron_id = defined $matchpoint ? $borrower{$matchpoint} : $matchpoint_attr_type;
420                 if ( $_->isa('Koha::Exceptions::Patron::Attribute::UniqueIDConstraint') ) {
421                     push @errors, { patron_attribute_unique_id_constraint => 1, patron_id => $patron_id, attribute => $_->attribute };
422                 } elsif ( $_->isa('Koha::Exceptions::Patron::Attribute::InvalidType') ) {
423                     push @errors, { patron_attribute_invalid_type => 1, patron_id => $patron_id, attribute_type_code => $_->type };
424                 } elsif ( $_->isa('Koha::Exceptions::Patron::Attribute::NonRepeatable') ) {
425                     push @errors, { patron_attribute_non_repeatable => 1, patron_id => $patron_id, attribute => $_->attribute };
426
427                 } else {
428                     warn $_;
429                     push @errors, { unknown_error => 1 };
430                 }
431                 push(
432                     @errors,
433                     {
434                         name  => 'lastinvalid',
435                         value => $borrower{'surname'} . ' / Create patron',
436                     }
437                 );
438             };
439         }
440
441         next LINE unless $success;
442
443         # Add a guarantor if we are given a relationship
444         if ( $guarantor_id ) {
445             my $relationship = Koha::Patron::Relationships->find(
446                 {
447                     guarantee_id => $borrowernumber,
448                     guarantor_id => $guarantor_id,
449                 }
450             );
451
452             if ( $relationship ) {
453                 $relationship->relationship( $guarantor_relationship );
454                 $relationship->store();
455             }
456             else {
457                 Koha::Patron::Relationship->new(
458                     {
459                         guarantee_id => $borrowernumber,
460                         relationship => $guarantor_relationship,
461                         guarantor_id => $guarantor_id,
462                     }
463                 )->store();
464             }
465         }
466     }
467
468     $schema->storage->txn_rollback if $dry_run;
469
470     return {
471         feedback      => \@feedback,
472         errors        => \@errors,
473         imported      => $imported,
474         overwritten   => $overwritten,
475         already_in_db => $alreadyindb,
476         invalid       => $invalid,
477         imported_borrowers => \@imported_borrowers,
478     };
479 }
480
481 =head2 prepare_columns
482
483  my @csvcolumns = $self->prepare_columns({headerrow => $borrowerline, keycol => \%csvkeycol, errors => \@errors, });
484
485 Returns an array of all column key and populates a hash of colunm key positions.
486
487 =cut
488
489 sub prepare_columns {
490     my ($self, $params) = @_;
491
492     my $status = $self->text_csv->parse($params->{headerrow});
493     unless( $status ) {
494         push( @{$params->{errors}}, { badheader => 1, line => 1, lineraw => $params->{headerrow} });
495         return;
496     }
497
498     my @csvcolumns = $self->text_csv->fields();
499     my $col = 0;
500     foreach my $keycol (@csvcolumns) {
501         # columnkeys don't contain whitespace, but some stupid tools add it
502         $keycol =~ s/ +//g;
503         $keycol =~ s/^\N{BOM}//; # Strip BOM if exists, otherwise it will be part of first column key
504         $params->{keycol}->{$keycol} = $col++;
505     }
506
507     return @csvcolumns;
508 }
509
510 =head2 set_attribute_types
511
512  my $matchpoint_attr_type = $self->set_attribute_types({ extended => $extended, matchpoint => $matchpoint, });
513
514 Returns an attribute type based on matchpoint parameter.
515
516 =cut
517
518 sub set_attribute_types {
519     my ($self, $params) = @_;
520
521     my $attribute_type;
522     if( $params->{extended} ) {
523         $attribute_type = Koha::Patron::Attribute::Types->find($params->{matchpoint});
524     }
525
526     return $attribute_type;
527 }
528
529 =head2 set_column_keys
530
531  my @columnkeys = set_column_keys($extended);
532
533 Returns an array of borrowers' table columns.
534
535 =cut
536
537 sub set_column_keys {
538     my ($self, $extended) = @_;
539
540     my @columnkeys = map { $_ ne 'borrowernumber' ? $_ : () } Koha::Patrons->columns();
541     push( @columnkeys, 'patron_attributes' ) if $extended;
542     push( @columnkeys, qw( guarantor_relationship guarantor_id ) );
543
544     return @columnkeys;
545 }
546
547 =head2 generate_patron_attributes
548
549  my $patron_attributes = generate_patron_attributes($extended, $borrower{patron_attributes}, $feedback);
550
551 Returns a Koha::Patron::Attributes as expected by Koha::Patron->extended_attributes
552
553 =cut
554
555 sub generate_patron_attributes {
556     my ($self, $extended, $string, $feedback) = @_;
557
558     unless( $extended ) { return; }
559     unless( defined $string ) { return; }
560
561     # Fixup double quotes in case we are passed smart quotes
562     $string =~ s/\xe2\x80\x9c/"/g;
563     $string =~ s/\xe2\x80\x9d/"/g;
564
565     push (@$feedback, { feedback => 1, name => 'attribute string', value => $string });
566     return [] unless $string; # Unit tests want the feedback, is it really needed?
567
568     my $csv = Text::CSV->new({binary => 1});  # binary needed for non-ASCII Unicode
569     my $ok   = $csv->parse($string);  # parse field again to get subfields!
570     my @list = $csv->fields();
571     my @patron_attributes =
572       sort { $a->{code} cmp $b->{code} || $a->{attribute} cmp $b->{attribute} }
573       map {
574         my @arr = split /:/, $_, 2;
575         { code => $arr[0], attribute => $arr[1] }
576       } @list;
577     return \@patron_attributes;
578     # TODO: error handling (check $ok)
579 }
580
581 =head2 check_branch_code
582
583  check_branch_code($borrower{branchcode}, $borrowerline, $line_number, \@missing_criticals);
584
585 Pushes a 'missing_criticals' error entry if no branch code or branch code does not map to a branch name.
586
587 =cut
588
589 sub check_branch_code {
590     my ($self, $branchcode, $borrowerline, $line_number, $missing_criticals) = @_;
591
592     # No branch code
593     unless( $branchcode ) {
594         push (@$missing_criticals, { key => 'branchcode', line => $line_number, lineraw => decode_utf8($borrowerline), });
595         return;
596     }
597
598     # look for branch code
599     my $library = Koha::Libraries->find( $branchcode );
600     unless( $library ) {
601         push (@$missing_criticals, { key => 'branchcode', line => $line_number, lineraw => decode_utf8($borrowerline),
602                                      value => $branchcode, branch_map => 1, });
603     }
604 }
605
606 =head2 check_borrower_category
607
608  check_borrower_category($borrower{categorycode}, $borrowerline, $line_number, \@missing_criticals);
609
610 Pushes a 'missing_criticals' error entry if no category code or category code does not map to a known category.
611
612 =cut
613
614 sub check_borrower_category {
615     my ($self, $categorycode, $borrowerline, $line_number, $missing_criticals) = @_;
616
617     # No branch code
618     unless( $categorycode ) {
619         push (@$missing_criticals, { key => 'categorycode', line => $line_number, lineraw => decode_utf8($borrowerline), });
620         return;
621     }
622
623     # Looking for borrower category
624     my $category = Koha::Patron::Categories->find($categorycode);
625     unless( $category ) {
626         push (@$missing_criticals, { key => 'categorycode', line => $line_number, lineraw => decode_utf8($borrowerline),
627                                      value => $categorycode, category_map => 1, });
628     }
629 }
630
631 =head2 format_dates
632
633  format_dates({borrower => \%borrower, lineraw => $lineraw, line => $line_number, missing_criticals => \@missing_criticals, });
634
635 Pushes a 'missing_criticals' error entry for each of the 3 date types dateofbirth, dateenrolled and dateexpiry if it can not
636 be formatted to the chosen date format. Populates the correctly formatted date otherwise.
637
638 =cut
639
640 sub format_dates {
641     my ($self, $params) = @_;
642
643     foreach my $date_type (qw(dateofbirth dateenrolled dateexpiry date_renewed)) {
644         my $tempdate = $params->{borrower}->{$date_type} or next();
645         my $formatted_date = eval { output_pref( { dt => dt_from_string( $tempdate ), dateonly => 1, dateformat => 'iso' } ); };
646
647         if ($formatted_date) {
648             $params->{borrower}->{$date_type} = $formatted_date;
649         } else {
650             $params->{borrower}->{$date_type} = '';
651             push (@{$params->{missing_criticals}}, { key => $date_type, line => $params->{line}, lineraw => decode_utf8($params->{lineraw}), bad_date => 1 });
652         }
653     }
654 }
655
656 1;
657
658 =head1 AUTHOR
659
660 Koha Team
661
662 =cut