Bugzilla – Attachment 157586 Details for
Bug 33547
Print slips from the preservation module
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33547: Add print slip
Bug-33547-Add-print-slip.patch (text/plain), 23.23 KB, created by
Jonathan Druart
on 2023-10-21 06:22:27 UTC
(
hide
)
Description:
Bug 33547: Add print slip
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2023-10-21 06:22:27 UTC
Size:
23.23 KB
patch
obsolete
>From f57a37329134b7288a2651dcd3cc9a98b940dbf6 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 12 Apr 2023 15:20:12 +0200 >Subject: [PATCH] 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> >--- > C4/Letters.pm | 8 +- > Koha/Preservation/Train/Item.pm | 12 +++ > .../definitions/preservation_processing.yaml | 5 ++ > api/v1/swagger/paths/preservation_trains.yaml | 1 + > debian/templates/apache-shared-intranet.conf | 1 + > .../data/mysql/atomicupdate/bug_33547.pl | 37 +++++++++ > .../mysql/en/mandatory/sample_notices.yml | 22 ++++++ > installer/data/mysql/kohastructure.sql | 1 + > .../prog/en/modules/preservation/home.tt | 1 + > .../prog/en/modules/tools/letter.tt | 7 ++ > .../SettingsProcessingsFormAdd.vue | 15 ++++ > .../Preservation/SettingsProcessingsShow.vue | 24 ++++++ > .../components/Preservation/TrainsShow.vue | 34 ++++++++- > .../js/vue/fetch/preservation-api-client.js | 2 +- > preservation/home.pl | 5 ++ > preservation/print_slip.pl | 75 +++++++++++++++++++ > t/db_dependent/Koha/Preservation/Trains.t | 6 +- > 17 files changed, 251 insertions(+), 5 deletions(-) > create mode 100755 installer/data/mysql/atomicupdate/bug_33547.pl > create mode 100755 preservation/print_slip.pl > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index 3221e1f6129..dd8291aac0c 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -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 ) { >diff --git a/Koha/Preservation/Train/Item.pm b/Koha/Preservation/Train/Item.pm >index 413e18410b7..b6c65de52bb 100644 >--- a/Koha/Preservation/Train/Item.pm >+++ b/Koha/Preservation/Train/Item.pm >@@ -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 >diff --git a/api/v1/swagger/definitions/preservation_processing.yaml b/api/v1/swagger/definitions/preservation_processing.yaml >index 62ef2d8a9a2..4ae51d92572 100644 >--- a/api/v1/swagger/definitions/preservation_processing.yaml >+++ b/api/v1/swagger/definitions/preservation_processing.yaml >@@ -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: >diff --git a/api/v1/swagger/paths/preservation_trains.yaml b/api/v1/swagger/paths/preservation_trains.yaml >index 6e316e6c325..fca0cda0bec 100644 >--- a/api/v1/swagger/paths/preservation_trains.yaml >+++ b/api/v1/swagger/paths/preservation_trains.yaml >@@ -168,6 +168,7 @@ > - items.attributes > - items.attributes+strings > - items.attributes.processing_attribute >+ - items.processing > - default_processing > - default_processing.attributes > collectionFormat: csv >diff --git a/debian/templates/apache-shared-intranet.conf b/debian/templates/apache-shared-intranet.conf >index 75f495eb381..b4fe0ea2263 100644 >--- a/debian/templates/apache-shared-intranet.conf >+++ b/debian/templates/apache-shared-intranet.conf >@@ -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" >diff --git a/installer/data/mysql/atomicupdate/bug_33547.pl b/installer/data/mysql/atomicupdate/bug_33547.pl >new file mode 100755 >index 00000000000..980153fe305 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_33547.pl >@@ -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)"; >+ }, >+}; >diff --git a/installer/data/mysql/en/mandatory/sample_notices.yml b/installer/data/mysql/en/mandatory/sample_notices.yml >index 8d368e659ed..b9ac82e6215 100644 >--- a/installer/data/mysql/en/mandatory/sample_notices.yml >+++ b/installer/data/mysql/en/mandatory/sample_notices.yml >@@ -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 %]" >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index c99e69e2b7e..ae30fd34784 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -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 */; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/preservation/home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/preservation/home.tt >index 39695277834..14771f064e1 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/preservation/home.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/preservation/home.tt >@@ -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 %]"; > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt >index 9d773dd96ac..79e660255c9 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt >@@ -168,6 +168,7 @@ > <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&module=ill">Interlibrary loans</a></li> > <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&module=orderacquisition">Order acquisition</a></li> > <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&module=members">Patrons</a></li> >+ <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&module=preservation">Preservation</a></li> > <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&module=serial">Serials (new issue)</a></li> > <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&module=suggestions">Suggestions</a></li> > <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&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 %] >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/SettingsProcessingsFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/SettingsProcessingsFormAdd.vue >index 6504cb6a0bb..b8398939775 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/SettingsProcessingsFormAdd.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/SettingsProcessingsFormAdd.vue >@@ -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() { >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/SettingsProcessingsShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/SettingsProcessingsShow.vue >index 72e9f9d07e1..96cec7ce2f4 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/SettingsProcessingsShow.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/SettingsProcessingsShow.vue >@@ -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: [], > }, >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue >index 16d600ed497..63a9a33b6a0 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue >@@ -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) > }) >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/preservation-api-client.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/preservation-api-client.js >index f8a281f4178..3474facd6ce 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/preservation-api-client.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/preservation-api-client.js >@@ -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 = {}) => >diff --git a/preservation/home.pl b/preservation/home.pl >index 0e096c531ac..b5f3d2e03fb 100755 >--- a/preservation/home.pl >+++ b/preservation/home.pl >@@ -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; >diff --git a/preservation/print_slip.pl b/preservation/print_slip.pl >new file mode 100755 >index 00000000000..ec3687ba0f1 >--- /dev/null >+++ b/preservation/print_slip.pl >@@ -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; >diff --git a/t/db_dependent/Koha/Preservation/Trains.t b/t/db_dependent/Koha/Preservation/Trains.t >index b441eeee654..11d20447b44 100755 >--- a/t/db_dependent/Koha/Preservation/Trains.t >+++ b/t/db_dependent/Koha/Preservation/Trains.t >@@ -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 } ); > } >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 33547
:
149774
|
149775
|
152048
|
152257
|
152258
|
152259
|
152260
|
152971
|
152972
|
152973
|
152974
|
154204
|
154205
|
154206
|
154207
|
156892
|
156893
|
156894
|
156895
|
156966
|
156967
|
156968
|
156969
|
156970
| 157586 |
157587
|
157588
|
157589
|
157590