[Koha-bugs] [Bug 20119] Improve orders claiming
bugzilla-daemon at bugs.koha-community.org
bugzilla-daemon at bugs.koha-community.org
Fri Feb 2 10:17:09 CET 2018
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20119
Alex Arnaud <alex.arnaud at biblibre.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #71107|0 |1
is obsolete| |
--- Comment #6 from Alex Arnaud <alex.arnaud at biblibre.com> ---
Comment on attachment 71107
--> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=71107
Bug 20119 - Add a script to claim late orders (ordersClaim.pl)
>From 2c7a930cf6e6cb12b4a7963d34e86bbfde0ceb42 Mon Sep 17 00:00:00 2001
>From: Alex Arnaud <alex.arnaud at biblibre.com>
>Date: Wed, 31 Jan 2018 15:16:16 +0000
>Subject: [PATCH] Bug 20119 - Add a script to claim late orders
> (ordersClaim.pl)
>
>---
> misc/cronjobs/ordersClaim.pl | 162 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 162 insertions(+)
> create mode 100755 misc/cronjobs/ordersClaim.pl
>
>diff --git a/misc/cronjobs/ordersClaim.pl b/misc/cronjobs/ordersClaim.pl
>new file mode 100755
>index 0000000..a0d046c
>--- /dev/null
>+++ b/misc/cronjobs/ordersClaim.pl
>@@ -0,0 +1,162 @@
>+#!/usr/bin/perl
>+
>+# Copyright 2018 Biblibre
>+#
>+# 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>.
>+
>+=head1 NAME
>+
>+ordersClaim.pl - cron script that put late orders in message queue grouped by basket.
>+
>+=head1 SYNOPSIS
>+
>+./ordersClaim.pl --delay 40 --claimed-for 10 --max-claims 3
>+
>+=head1 DESCRIPTION
>+
>+This script get all late orders (depending on --delay parameter,
>+group them by basket and put an entry in message_queue table.
>+
>+=cut
>+
>+use Modern::Perl;
>+
>+use Getopt::Long;
>+use Pod::Usage;
>+
>+use C4::Letters;
>+use C4::Acquisition;
>+
>+=head1 NAME
>+
>+ordersClaim.pl - cron script that put late orders in message queue grouped by basket.
>+
>+=head1 SYNOPSIS
>+
>+perl ordersClaim.pl
>+ [ --delay|d <number of days> ][ --claimed-for|c <number of days> ][ --max-claims <number of claims> ]
>+
>+=head1 OPTIONS
>+
>+=over
>+
>+=item B<--help>
>+
>+Print a brief help message and exits.
>+
>+=item B<--delay>
>+
>+Number of days from which an orders is considered as late.
>+Default is the booseller's delivery time or 0.
>+
>+=item B<--claimed-for>
>+
>+Minimum number of days since the last claim. Default is 0.
>+
>+=item B<--max-claim>
>+
>+Number of claims beyond which we stop sending others.
>+Default is 1;
>+
>+=cut
>+
>+my $help;
>+my $delay;
>+my $claimed_for = 0;
>+my $max_claims = 1;
>+
>+GetOptions(
>+ 'help|?' => \$help,
>+ 'delay|d:i' => \$delay,
>+ 'claimed-for|c:i' => \$claimed_for,
>+ 'max-claims|m:i' => \$max_claims,
>+) or pod2usage(1);
>+
>+pod2usage(1) if $help;
>+
>+my @lateorders = GetLateOrders( ($delay) );
>+
>+# Sort orders by basket
>+my $baskets_orders;
>+push @{ $baskets_orders->{ $_->{basketno} } }, $_->{ordernumber} for @lateorders;
>+
>+while (my ($basketno, $orderids) = each %$baskets_orders) {
>+ my $schema = Koha::Database->new->schema;
>+
>+ my $basket = $schema->resultset('Aqbookseller')->find(
>+ { id => $basketno },
>+ { result_class => 'DBIx::Class::ResultClass::HashRefInflator' });
>+
>+ my $booksellerid = $basket->{booksellerid};
>+ my $bookseller = $schema->resultset('Aqbookseller')->find(
>+ { id => $booksellerid },
>+ { result_class => 'DBIx::Class::ResultClass::HashRefInflator' });
>+
>+ my $contact = $schema->resultset('Aqcontact')->find(
>+ { booksellerid => $booksellerid, claimacquisition => 1 },
>+ { result_class => 'DBIx::Class::ResultClass::HashRefInflator' });
>+
>+ unless ( defined( $delay ) ) {
>+ $delay = $bookseller->{deliverytime} || 0;
>+ }
>+
>+ my $dbh = C4::Context->dbh;
>+
>+ my $orderids_str = join(',', ('?') x @$orderids);
>+ my $orders = $dbh->selectall_arrayref(qq{
>+ SELECT aqorders.*, aqbasket.*, biblio.*
>+ FROM aqorders
>+ LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber
>+ LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno
>+ WHERE aqorders.ordernumber IN ($orderids_str)
>+ AND aqorders.claims_count < $max_claims
>+ AND (aqorders.claimed_date IS NULL or aqorders.claimed_date <= DATE_SUB(CAST(now() AS date),INTERVAL $claimed_for DAY))
>+ }, {Slice => {}}, @$orderids);
>+
>+ next unless @$orders;
>+
>+ my $letter = GetPreparedLetter(
>+ module => 'claimacquisition',
>+ letter_code => 'ACQCLAIM',
>+ message_transport_type => 'email',
>+ tables => {
>+ 'aqbooksellers' => $bookseller,
>+ 'aqcontacts' => $contact,
>+ 'aqbasket' => $basket
>+ },
>+ repeat => $orders,
>+ ) or next;
>+
>+ my $admin_address = C4::Context->preference('KohaAdminEmailAddress');
>+ my $id = C4::Letters::EnqueueLetter({
>+ letter => $letter,
>+ from_address => $admin_address,
>+ to_address => $contact->{email},
>+ message_transport_type => $letter->{message_transport_type}
>+ });
>+
>+ continue unless $id
>+
>+ my $today = Koha::DateUtils::dt_from_string;
>+ foreach my $o ( @$orders ) {
>+ my $order = $schema->resultset('Aqorder')->find($o->{ordernumber});
>+ my $count = $order->get_column('claims_count') || 0;
>+ $order->set_columns({
>+ claimed_date => $today->ymd,
>+ claims_count => $count+1
>+ })->update_or_insert;
>+ }
>+}
>--
>2.7.4
--
You are receiving this mail because:
You are watching all bug changes.
More information about the Koha-bugs
mailing list