Feature #442
Updated by Lari Taskula almost 4 years ago
<pre> Save this code into a slip_tester.pl file, edit lettercode and mtt to your liking, then run _perl slip_tester.pl_ <pre><code class="perl"> use Modern::Perl; use C4::Context; use C4::Letters; use Koha::DateUtils; use Koha::Patrons; use Koha::Items; ### EDIT THESE TO YOUR LIKING ### my $lettercode = 'ODUE'; my $mtt = 'email'; ### IF YOU WANT TO TARGET SOME SPECIFIC PATRONS OR BIBLIOS, EDIT THESE ### ### OTHERWISE I WILL PICK SOME RANDOM VALUES FOR YOU ### my $patron = Koha::Patrons->search->next; my $borrowernumber = $patron->borrowernumber; my $biblionumber = Koha::Items->search->next->biblionumber; my $itemnumber = Koha::Items->search({ biblionumber => $biblionumber })->next->itemnumber; my $branchcode = $patron->branchcode; ### STOP EDITING #### my $dbh = C4::Context->dbh(); my $sth = $dbh->prepare(<<'END_SQL'); SELECT biblio.*, items.* FROM items,biblio WHERE biblio.biblionumber=items.biblionumber AND biblio.biblionumber = ? END_SQL my $itemscontent = join(',',qw( date_due title author barcode )); my @item_content_fields = split(/,/,$itemscontent); my $titles = ""; $sth->execute($biblionumber); while ( my $item_info = $sth->fetchrow_hashref()) { my @item_info = map { $_ =~ /^date|date$/ ? format_date($item_info->{$_}) : $item_info->{$_} || '' } @item_content_fields; $titles .= join("\t",@item_info) . "\n"; } my %branch_info = get_branch_info( $borrowernumber ); my $letter; $letter = parse_letter( { letter_code => $lettercode, borrowernumber => $borrowernumber, biblionumber => $biblionumber, itemnumber => $itemnumber, substitute => { count => 5, 'items.content' => $titles, %branch_info, }, branchcode => $branchcode, message_transport_type => $mtt, } ); warn Data::Dumper::Dumper($letter); sub parse_letter { my $params = shift; foreach my $required ( qw( letter_code borrowernumber ) ) { return unless exists $params->{$required}; } my $patron = Koha::Patrons->find( $params->{borrowernumber} ); my %table_params = ( 'borrowers' => $params->{'borrowernumber'} ); if ( my $p = $params->{'branchcode'} ) { $table_params{'branches'} = $p; } if ( my $p = $params->{'itemnumber'} ) { $table_params{'issues'} = $p; $table_params{'items'} = $p; } if ( my $p = $params->{'biblionumber'} ) { $table_params{'biblio'} = $p; $table_params{'biblioitems'} = $p; } return C4::Letters::GetPreparedLetter ( module => 'circulation', letter_code => $params->{'letter_code'}, branchcode => $table_params{'branches'}, lang => $patron->lang, substitute => $params->{'substitute'}, tables => \%table_params, message_transport_type => $params->{message_transport_type}, ); } sub get_branch_info { my ( $borrowernumber ) = @_; ## Get branch info for borrowers home library. my $borrower_details = C4::Members::GetMember( borrowernumber => $borrowernumber ); my $borrower_branchcode = $borrower_details->{'branchcode'}; my $branch = Koha::Libraries->find( $borrower_branchcode )->unblessed; my %branch_info; foreach my $key( keys %$branch ) { $branch_info{"branches.$key"} = $branch->{$key}; } return %branch_info; } sub format_date { my $date_string = shift; my $dt=dt_from_string($date_string); return output_pref($dt); } </code></pre> </pre>