View | Details | Raw Unified | Return to bug 5379
Collapse All | Expand All

(-)a/C4/Members.pm (-11 / +18 lines)
Lines 772-788 sub ModMember { Link Here
772
        }
772
        }
773
    }
773
    }
774
	my $execute_success=UpdateInTable("borrowers",\%data);
774
	my $execute_success=UpdateInTable("borrowers",\%data);
775
# ok if its an adult (type) it may have borrowers that depend on it as a guarantor
775
    if ($execute_success) { # only proceed if the update was a success
776
# so when we update information for an adult we should check for guarantees and update the relevant part
776
        # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
777
# of their records, ie addresses and phone numbers
777
        # so when we update information for an adult we should check for guarantees and update the relevant part
778
    my $borrowercategory= GetBorrowercategory( $data{'category_type'} );
778
        # of their records, ie addresses and phone numbers
779
    if ( exists  $borrowercategory->{'category_type'} && $borrowercategory->{'category_type'} eq ('A' || 'S') ) {
779
        my $borrowercategory= GetBorrowercategory( $data{'category_type'} );
780
        # is adult check guarantees;
780
        if ( exists  $borrowercategory->{'category_type'} && $borrowercategory->{'category_type'} eq ('A' || 'S') ) {
781
        UpdateGuarantees(%data);
781
            # is adult check guarantees;
782
            UpdateGuarantees(%data);
783
        }
784
        logaction("MEMBERS", "MODIFY", $data{'borrowernumber'}, "UPDATE (executed w/ arg: $data{'borrowernumber'})") if C4::Context->preference("BorrowersLog");
782
    }
785
    }
783
    logaction("MEMBERS", "MODIFY", $data{'borrowernumber'}, "UPDATE (executed w/ arg: $data{'borrowernumber'})") 
784
        if C4::Context->preference("BorrowersLog");
785
786
    return $execute_success;
786
    return $execute_success;
787
}
787
}
788
788
Lines 792-798 sub ModMember { Link Here
792
  $borrowernumber = &AddMember(%borrower);
792
  $borrowernumber = &AddMember(%borrower);
793
793
794
insert new borrower into table
794
insert new borrower into table
795
Returns the borrowernumber
795
Returns the borrowernumber upon success
796
797
Returns as undef upon any db error without further processing
796
798
797
=cut
799
=cut
798
800
Lines 810-819 sub AddMember { Link Here
810
    my $sth = $dbh->prepare("SELECT enrolmentfee FROM categories WHERE categorycode=?");
812
    my $sth = $dbh->prepare("SELECT enrolmentfee FROM categories WHERE categorycode=?");
811
    $sth->execute($data{'categorycode'});
813
    $sth->execute($data{'categorycode'});
812
    my ($enrolmentfee) = $sth->fetchrow;
814
    my ($enrolmentfee) = $sth->fetchrow;
815
    if ($sth->err) {
816
        warn sprintf('Database returned the following error: %s', $sth->errstr);
817
        return;
818
    }
813
    if ($enrolmentfee && $enrolmentfee > 0) {
819
    if ($enrolmentfee && $enrolmentfee > 0) {
814
        # insert fee in patron debts
820
        # insert fee in patron debts
815
        manualinvoice($data{'borrowernumber'}, '', '', 'A', $enrolmentfee);
821
        manualinvoice($data{'borrowernumber'}, '', '', 'A', $enrolmentfee);
816
    }
822
    }
823
817
    return $data{'borrowernumber'};
824
    return $data{'borrowernumber'};
818
}
825
}
819
826
(-)a/C4/Members/Attributes.pm (+5 lines)
Lines 203-209 sub SetBorrowerAttributes { Link Here
203
    foreach my $attr (@$attr_list) {
203
    foreach my $attr (@$attr_list) {
204
        $attr->{password} = undef unless exists $attr->{password};
204
        $attr->{password} = undef unless exists $attr->{password};
205
        $sth->execute($borrowernumber, $attr->{code}, $attr->{value}, $attr->{password});
205
        $sth->execute($borrowernumber, $attr->{code}, $attr->{value}, $attr->{password});
206
        if ($sth->err) {
207
            warn sprintf('Database returned the following error: %s', $sth->errstr);
208
            return; # bail immediately on errors
209
        }
206
    }
210
    }
211
    return 1; # borower attributes successfully set
207
}
212
}
208
213
209
=head2 extended_attributes_code_value_arrayref 
214
=head2 extended_attributes_code_value_arrayref 
(-)a/tools/import_borrowers.pl (-3 / +8 lines)
Lines 66-72 my $columnkeystpl = [ map { {'key' => $_} } grep {$_ ne 'borrowernumber' && $_ Link Here
66
66
67
my $input = CGI->new();
67
my $input = CGI->new();
68
our $csv  = Text::CSV->new({binary => 1});  # binary needed for non-ASCII Unicode
68
our $csv  = Text::CSV->new({binary => 1});  # binary needed for non-ASCII Unicode
69
# push @feedback, {feedback=>1, name=>'backend', value=>$csv->backend, backend=>$csv->backend};
69
#push @feedback, {feedback=>1, name=>'backend', value=>$csv->backend, backend=>$csv->backend}; #XXX
70
70
71
my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
71
my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
72
        template_name   => "tools/import_borrowers.tmpl",
72
        template_name   => "tools/import_borrowers.tmpl",
Lines 193-198 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
193
        }
193
        }
194
        if ($extended) {
194
        if ($extended) {
195
            my $attr_str = $borrower{patron_attributes};
195
            my $attr_str = $borrower{patron_attributes};
196
            $attr_str =~ s/\xe2\x80\x9c/"/g; # fixup double quotes in case we are passed smart quotes
197
            $attr_str =~ s/\xe2\x80\x9d/"/g;
198
            push @feedback, {feedback=>1, name=>'attribute string', value=>$attr_str, filename=>$uploadborrowers};
196
            delete $borrower{patron_attributes};    # not really a field in borrowers, so we don't want to pass it to ModMember.
199
            delete $borrower{patron_attributes};    # not really a field in borrowers, so we don't want to pass it to ModMember.
197
            $patron_attributes = extended_attributes_code_value_arrayref($attr_str); 
200
            $patron_attributes = extended_attributes_code_value_arrayref($attr_str); 
198
        }
201
        }
Lines 246-251 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
246
            }
249
            }
247
            unless (ModMember(%borrower)) {
250
            unless (ModMember(%borrower)) {
248
                $invalid++;
251
                $invalid++;
252
                # untill we have better error trapping, we have no way of knowing why ModMember errored out...
253
                push @errors, {unknown_error => 1};
249
                $template->param('lastinvalid'=>$borrower{'surname'}.' / '.$borrowernumber);
254
                $template->param('lastinvalid'=>$borrower{'surname'}.' / '.$borrowernumber);
250
                next LINE;
255
                next LINE;
251
            }
256
            }
Lines 254-260 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
254
                    my $old_attributes = GetBorrowerAttributes($borrowernumber);
259
                    my $old_attributes = GetBorrowerAttributes($borrowernumber);
255
                    $patron_attributes = extended_attributes_merge($old_attributes, $patron_attributes);  #TODO: expose repeatable options in template
260
                    $patron_attributes = extended_attributes_merge($old_attributes, $patron_attributes);  #TODO: expose repeatable options in template
256
                }
261
                }
257
                SetBorrowerAttributes($borrower{'borrowernumber'}, $patron_attributes);
262
                push @errors, {unknown_error => 1} unless SetBorrowerAttributes($borrower{'borrowernumber'}, $patron_attributes);
258
            }
263
            }
259
            $overwritten++;
264
            $overwritten++;
260
            $template->param('lastoverwritten'=>$borrower{'surname'}.' / '.$borrowernumber);
265
            $template->param('lastoverwritten'=>$borrower{'surname'}.' / '.$borrowernumber);
Lines 276-281 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
276
                $template->param('lastimported'=>$borrower{'surname'}.' / '.$borrowernumber);
281
                $template->param('lastimported'=>$borrower{'surname'}.' / '.$borrowernumber);
277
            } else {
282
            } else {
278
                $invalid++;
283
                $invalid++;
284
                push @errors, {unknown_error => 1};
279
                $template->param('lastinvalid'=>$borrower{'surname'}.' / AddMember');
285
                $template->param('lastinvalid'=>$borrower{'surname'}.' / AddMember');
280
            }
286
            }
281
        }
287
        }
282
- 

Return to bug 5379