Bug 33547: Add print slip

Sponsored-by: BULAC - http://www.bulac.fr/

Signed-off-by: BULAC - http://www.bulac.fr/
Signed-off-by: Heather Hernandez <heather_hernandez@nps.gov>
Signed-off-by: Laurence Rault <laurence.rault@biblibre.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2023-04-12 15:20:12 +02:00 committed by Tomas Cohen Arazi
parent ebc28a9753
commit 10649d4921
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
17 changed files with 251 additions and 5 deletions

View File

@ -1848,7 +1848,13 @@ sub _get_tt_params {
singular => 'illrequest',
plural => 'illrequests',
pk => 'illrequest_id'
}
},
preservation_train_items => {
module => 'Koha::Preservation::Train::Items',
singular => 'train_item',
plural => 'train_items',
pk => 'train_item_id'
},
};
foreach my $table ( keys %$tables ) {

View File

@ -62,6 +62,18 @@ sub catalogue_item {
return Koha::Item->_new_from_dbic($item_rs);
}
=head3 train
Return the train object for this item
=cut
sub train {
my ( $self ) = @_;
my $rs = $self->_result->train;
return Koha::Preservation::Train->_new_from_dbic($rs);
}
=head3 attributes
Getter and setter for the attributes

View File

@ -8,6 +8,11 @@ properties:
name:
description: name of the processing
type: string
letter_code:
description: Letter code of the letter to use for printing slips
type:
- string
- "null"
attributes:
description: attributes of the processing
items:

View File

@ -168,6 +168,7 @@
- items.attributes
- items.attributes+strings
- items.attributes.processing_attribute
- items.processing
- default_processing
- default_processing.attributes
collectionFormat: csv

View File

@ -21,6 +21,7 @@ RewriteRule ^/issn/([^\/]*)/?$ /search?q=issn:$1 [PT]
RewriteRule ^(.*)_[0-9]{2}\.[0-9]{7}\.(js|css)$ $1.$2 [L]
RewriteRule ^/cgi-bin/koha/erm/.*$ /cgi-bin/koha/erm/erm.pl [PT]
RewriteCond %{REQUEST_URI} !^/cgi-bin/koha/preservation/.*.pl$
RewriteRule ^/cgi-bin/koha/preservation/.*$ /cgi-bin/koha/preservation/home.pl [PT]
Alias "/api" "/usr/share/koha/api"

View File

@ -0,0 +1,37 @@
use Modern::Perl;
return {
bug_number => "33547",
description => "Add a new notice template 'PRES_TRAIN_ITEM'",
up => sub {
my ($args) = @_;
my ($dbh, $out) = @$args{qw(dbh out)};
unless ( column_exists('preservation_processings', 'letter_code') ) {
$dbh->do(q{
ALTER TABLE preservation_processings
ADD COLUMN `letter_code` varchar(20) DEFAULT NULL COMMENT 'Foreign key to the letters table' AFTER `name`
});
}
my $notice_template = q{[%~ SET train = train_item.train ~%]
[%~ SET item = train_item.catalogue_item ~%]
Train name: [% train.name %]
Sent on: [% train.sent_on | $KohaDates %]
[% train.default_processing.name %]
Item number #[% train_item.user_train_item_id %]
[% FOREACH item_attribute IN train_item.attributes %]
[% item_attribute.processing_attribute.name %]: [% item_attribute.value %]
[% END %]};
$dbh->do(q{
INSERT IGNORE INTO letter
(module,code,branchcode,name,is_html,title,content,message_transport_type,lang)
VALUES
('preservation','PRES_TRAIN_ITEM','','Train item slip',0,'Train item slip',?, 'print','default')}, undef, $notice_template);
say $out "Added new letter 'PRES_TRAIN_ITEM' (print)";
},
};

View File

@ -2384,3 +2384,25 @@ tables:
- "[% IF ( biblio.items.count > 0 ) %]<br>Items: <ul>[% FOREACH item IN biblio.items %]<li>[% Branches.GetName( item.holdingbranch ) | html %]"
- "[% IF ( item.location ) %], [% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => item.location ) | html %][% END %][% IF item.itemcallnumber %]([% item.itemcallnumber | html %])[% END %][% item.barcode | html %]</li>[% END %]</ul>[% END %]"
- "<hr></li>[% END %]</ol>"
- module: preservation
code: PRES_TRAIN_ITEM
branchcode: ""
name: "Train item slip"
is_html: 0
title: "Train item slip"
message_transport_type: print
lang: default
content:
- "[%~ SET train = train_item.train ~%]"
- "[%~ SET item = train_item.catalogue_item ~%]"
- "Train name: [% train.name %]"
- "Sent on: [% train.sent_on | $KohaDates %]"
- ""
- "[% train.default_processing.name %]"
- ""
- "Item number #[% train_item.user_train_item_id %]"
- ""
- "[% FOREACH item_attribute IN train_item.attributes %]"
- " [% item_attribute.processing_attribute.name %]: [% item_attribute.value %]"
- "[% END %]"

View File

@ -4849,6 +4849,7 @@ DROP TABLE IF EXISTS `preservation_processings`;
CREATE TABLE `preservation_processings` (
`processing_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`name` varchar(80) NOT NULL COMMENT 'name of the processing',
`letter_code` varchar(20) DEFAULT NULL COMMENT 'Foreign key to the letters table',
PRIMARY KEY (`processing_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

View File

@ -34,6 +34,7 @@
const authorised_value_categories = [% To.json(AuthorisedValues.GetCategories()) | $raw %].map(c => c.category);
const db_columns = [% To.json(db_columns) | $raw %];
const api_mappings = [% To.json(api_mappings) | $raw %];
const notice_templates = [% To.json(notice_templates || []) | $raw %];
const csrf_token = "[% Koha.GenerateCSRF | $raw %]";

View File

@ -168,6 +168,7 @@
<li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=ill">Interlibrary loans</a></li>
<li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=orderacquisition">Order acquisition</a></li>
<li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=members">Patrons</a></li>
<li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=preservation">Preservation</a></li>
<li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=serial">Serials (new issue)</a></li>
<li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=suggestions">Suggestions</a></li>
<li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=pos">Point of sale</a></li>
@ -225,6 +226,7 @@
[% CASE 'reserves' %]<span>Holds</span>
[% CASE 'ill' %]<span>Interlibrary loans</span>
[% CASE 'members' %]<span>Patrons</span>
[% CASE 'preservation' %]<span>Preservation</span>
[% CASE 'serial' %]<span>Serials (new issue)</span>
[% CASE 'suggestions' %]<span>Suggestions</span>
[% CASE 'pos' %]<span>Point of sale</span>
@ -389,6 +391,11 @@
[% ELSE %]
<option value="members">Patrons</option>
[% END %]
[% IF ( module == "preservation" ) %]
<option value="preservation" selected="selected">Preservation</option>
[% ELSE %]
<option value="preservation">Preservation</option>
[% END %]
[% IF ( module == "serial" ) %]
<option value="serial" selected="selected">Serials (new issue)</option>
[% ELSE %]

View File

@ -21,6 +21,20 @@
/>
<span class="required">{{ $__("Required") }}</span>
</li>
<li>
<label for="letter_code"
>{{
$__("Letter template for printing slip")
}}:</label
>
<v-select
id="letter_code"
label="name"
v-model="processing.letter_code"
:options="notice_templates"
:reduce="n => n.code"
/>
</li>
</ol>
</fieldset>
<fieldset class="rows">
@ -199,6 +213,7 @@ export default {
setWarning,
authorised_value_categories,
db_column_options,
notice_templates,
}
},
data() {

View File

@ -24,6 +24,21 @@
{{ processing.name }}
</span>
</li>
<li v-if="notice_template">
<label
>{{
$__("Letter template for printing slip")
}}:</label
>
<span>
{{ notice_template.name }}
<a
:href="`/cgi-bin/koha/tools/letter.pl?op=add_form&module=preservation&code=${notice_template.code}`"
><i class="fa fa-edit"></i>
{{ $__("Edit this template") }}</a
>
</span>
</li>
</ol>
</fieldset>
<fieldset class="rows">
@ -77,14 +92,23 @@ export default {
const { setConfirmationDialog, setMessage } = inject("mainStore")
return {
notice_templates,
setConfirmationDialog,
setMessage,
}
},
computed: {
notice_template() {
return this.notice_templates.find(
n => n.id == this.processing.letter_code
)
},
},
data() {
return {
processing: {
processing_id: null,
letter_code: null,
name: "",
attributes: [],
},

View File

@ -437,6 +437,13 @@ export default {
}
)
},
printSlip(train_item_id) {
window.open(
"/cgi-bin/koha/preservation/print_slip.pl?train_item_id=" +
train_item_id,
"_blank"
)
},
selectTrainForCopy(train_item_id) {
this.show_modal = true
this.train_item_id_to_copy = train_item_id
@ -469,6 +476,7 @@ export default {
let item_table = this.item_table
let removeItem = this.removeItem
let editItem = this.editItem
let printSlip = this.printSlip
let selectTrainForCopy = this.selectTrainForCopy
let train = this.train
@ -481,8 +489,8 @@ export default {
var api = new $.fn.dataTable.Api(settings)
$.each($(this).find("td.actions"), function (index, e) {
let tr = $(this).parent()
let train_item_id = api.row(tr).data()
.item.train_item_id
let train_item = api.row(tr).data().item
let train_item_id = train_item.train_item_id
let editButton = createVNode(
"a",
@ -547,6 +555,28 @@ export default {
)
}
if (train_item.processing.letter_code !== null) {
let printButton = createVNode(
"a",
{
class: "btn btn-default btn-xs",
role: "button",
onClick: () => {
printSlip(train_item_id)
},
},
[
createVNode("i", {
class: "fa fa-print",
"aria-hidden": "true",
}),
__("Print slip"),
]
)
buttons.push(" ")
buttons.push(printButton)
}
let n = createVNode("span", {}, buttons)
render(n, e)
})

View File

@ -23,7 +23,7 @@ export class PreservationAPIClient extends HttpClient {
endpoint: "trains/" + id,
headers: {
"x-koha-embed":
"default_processing,default_processing.attributes,items,items.attributes,items.attributes+strings,items.attributes.processing_attribute",
"default_processing,default_processing.attributes,items,items.attributes,items.attributes+strings,items.attributes.processing_attribute,items.processing",
},
}),
getAll: (query = {}) =>

View File

@ -22,6 +22,7 @@ use C4::Auth qw( get_template_and_user );
use C4::Output qw( output_html_with_http_headers );
use Koha::Database::Columns;
use Koha::Notice::Templates;
my $query = CGI->new;
my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user(
@ -47,6 +48,10 @@ $template->param(
biblioitems => Koha::Biblioitem->to_api_mapping,
biblio => Koha::Biblio->to_api_mapping,
},
notice_templates =>
[ map { { id => $_->id, code => $_->code, name => $_->name } }
Koha::Notice::Templates->search( { module => 'preservation' } )
->as_list ],
);
output_html_with_http_headers $query, $cookie, $template->output;

75
preservation/print_slip.pl Executable file
View File

@ -0,0 +1,75 @@
#!/usr/bin/perl
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Context;
use C4::Auth qw( get_template_and_user );
use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
use C4::Letters;
use Koha::Patrons;
use Koha::Preservation::Train::Items;
my $input = CGI->new;
my $train_item_id = $input->param('train_item_id');
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => "circ/printslip.tt",
query => $input,
type => "intranet",
flagsrequired => { preservation => '*' },
}
);
my $logged_in_user = Koha::Patrons->find($loggedinuser);
my $branch = C4::Context->userenv->{'branch'};
my $train_item = Koha::Preservation::Train::Items->find($train_item_id);
unless ($train_item){
print $input->redirect("/cgi-bin/koha/errors/404.pl");
exit;
}
my $train = $train_item->train;
my $letter = C4::Letters::GetPreparedLetter(
module => 'preservation',
letter_code => $train_item->processing->letter_code,
branchcode => $branch,
lang => $logged_in_user->lang,
tables => {
preservation_train_items => $train_item_id,
},
message_transport_type => 'print'
);
my $slip = $letter->{content};
my $is_html = $letter->{is_html};
$template->param(
slip => $slip,
plain => !$is_html,
caller => 'preservation',
stylesheet => C4::Context->preference("SlipCSS"),
);
$template->param( IntranetSlipPrinterJS => C4::Context->preference('IntranetSlipPrinterJS' ) );
output_html_with_http_headers $input, $cookie, $template->output;

View File

@ -57,7 +57,7 @@ subtest 'default_processing' => sub {
};
subtest 'add_items & items' => sub {
plan tests => 14;
plan tests => 15;
$schema->storage->txn_begin;
@ -110,6 +110,10 @@ subtest 'add_items & items' => sub {
is( $item_2->get_from_storage->notforloan, 0 );
is( $item_3->get_from_storage->notforloan, $not_for_loan_train_in );
is( ref( $item_train_1->train ),
'Koha::Preservation::Train',
'Train::Item->train returns a Koha::Preservation::Train object' );
warning_is {
$train->add_item( { item_id => $item_2->itemnumber }, { skip_waiting_list_check => 1 } );
}