Lines 48-53
use Koha::Subscription::Histories;
Link Here
|
48 |
use Koha::Subscriptions; |
48 |
use Koha::Subscriptions; |
49 |
use Koha::Suggestions; |
49 |
use Koha::Suggestions; |
50 |
use Koha::TemplateUtils qw( process_tt ); |
50 |
use Koha::TemplateUtils qw( process_tt ); |
|
|
51 |
use List::Util qw( first ); |
52 |
use Locale::PO; |
51 |
|
53 |
|
52 |
# Define statuses |
54 |
# Define statuses |
53 |
use constant { |
55 |
use constant { |
Lines 76-110
BEGIN {
Link Here
|
76 |
require Exporter; |
78 |
require Exporter; |
77 |
@ISA = qw(Exporter); |
79 |
@ISA = qw(Exporter); |
78 |
@EXPORT_OK = qw( |
80 |
@EXPORT_OK = qw( |
79 |
NewSubscription ModSubscription DelSubscription |
81 |
NewSubscription ModSubscription DelSubscription |
80 |
GetSubscription CountSubscriptionFromBiblionumber GetSubscriptionsFromBiblionumber |
82 |
GetSubscription CountSubscriptionFromBiblionumber GetSubscriptionsFromBiblionumber |
81 |
SearchSubscriptions |
83 |
SearchSubscriptions |
82 |
GetFullSubscriptionsFromBiblionumber GetFullSubscription ModSubscriptionHistory |
84 |
GetFullSubscriptionsFromBiblionumber GetFullSubscription ModSubscriptionHistory |
83 |
HasSubscriptionStrictlyExpired HasSubscriptionExpired GetExpirationDate abouttoexpire |
85 |
HasSubscriptionStrictlyExpired HasSubscriptionExpired GetExpirationDate abouttoexpire |
84 |
GetFictiveIssueNumber |
86 |
GetFictiveIssueNumber |
85 |
GetSubscriptionHistoryFromSubscriptionId |
87 |
GetSubscriptionHistoryFromSubscriptionId |
86 |
|
88 |
|
87 |
GetNextSeq GetSeq NewIssue GetSerials |
89 |
GetNextSeq GetSeq NewIssue GetSerials |
88 |
GetLatestSerials ModSerialStatus GetNextDate |
90 |
GetLatestSerials ModSerialStatus GetNextDate |
89 |
CloseSubscription ReopenSubscription |
91 |
CloseSubscription ReopenSubscription |
90 |
subscriptionCurrentlyOnOrder |
92 |
subscriptionCurrentlyOnOrder |
91 |
can_claim_subscription can_edit_subscription can_show_subscription |
93 |
can_claim_subscription can_edit_subscription can_show_subscription |
92 |
GetSerials2 |
94 |
GetSerials2 |
93 |
GetSubscriptionLength ReNewSubscription GetLateOrMissingIssues |
95 |
GetSubscriptionLength ReNewSubscription GetLateOrMissingIssues |
94 |
GetSerialInformation AddItem2Serial |
96 |
GetSerialInformation AddItem2Serial |
95 |
PrepareSerialsData GetNextExpected ModNextExpected |
97 |
PrepareSerialsData GetNextExpected ModNextExpected |
96 |
GetSubscriptionIrregularities |
98 |
GetSubscriptionIrregularities |
97 |
GetPreviousSerialid |
99 |
GetPreviousSerialid |
98 |
|
100 |
|
99 |
GetSuppliersWithLateIssues |
101 |
GetSuppliersWithLateIssues |
100 |
getroutinglist delroutingmember addroutingmember |
102 |
getroutinglist delroutingmember addroutingmember |
101 |
reorder_members |
103 |
reorder_members |
102 |
check_routing updateClaim |
104 |
check_routing updateClaim |
103 |
CountIssues |
105 |
CountIssues |
104 |
HasItems |
106 |
HasItems |
105 |
|
107 |
|
106 |
findSerialsByStatus |
108 |
findSerialsByStatus |
107 |
|
109 |
|
|
|
110 |
GetSeasonsTranslations |
108 |
); |
111 |
); |
109 |
} |
112 |
} |
110 |
|
113 |
|
Lines 851-857
sub GetNextSeq {
Link Here
|
851 |
my $numberingmethod = $pattern->{numberingmethod}; |
854 |
my $numberingmethod = $pattern->{numberingmethod}; |
852 |
my $calculated = ""; |
855 |
my $calculated = ""; |
853 |
if ($numberingmethod) { |
856 |
if ($numberingmethod) { |
854 |
$calculated = $numberingmethod; |
857 |
$calculated = $numberingmethod; |
855 |
my $locale = $subscription->{locale}; |
858 |
my $locale = $subscription->{locale}; |
856 |
$newlastvalue1 = $subscription->{lastvalue1} || 0; |
859 |
$newlastvalue1 = $subscription->{lastvalue1} || 0; |
857 |
$newlastvalue2 = $subscription->{lastvalue2} || 0; |
860 |
$newlastvalue2 = $subscription->{lastvalue2} || 0; |
Lines 859-865
sub GetNextSeq {
Link Here
|
859 |
$newinnerloop1 = $subscription->{innerloop1} || 0; |
862 |
$newinnerloop1 = $subscription->{innerloop1} || 0; |
860 |
$newinnerloop2 = $subscription->{innerloop2} || 0; |
863 |
$newinnerloop2 = $subscription->{innerloop2} || 0; |
861 |
$newinnerloop3 = $subscription->{innerloop3} || 0; |
864 |
$newinnerloop3 = $subscription->{innerloop3} || 0; |
|
|
865 |
my $translations = $subscription->{translations}; |
866 |
|
862 |
my %calc; |
867 |
my %calc; |
|
|
868 |
|
863 |
foreach(qw/X Y Z/) { |
869 |
foreach(qw/X Y Z/) { |
864 |
$calc{$_} = 1 if ($numberingmethod =~ /\{$_\}/); |
870 |
$calc{$_} = 1 if ($numberingmethod =~ /\{$_\}/); |
865 |
} |
871 |
} |
Lines 897-911
sub GetNextSeq {
Link Here
|
897 |
} |
903 |
} |
898 |
} |
904 |
} |
899 |
if($calc{'X'}) { |
905 |
if($calc{'X'}) { |
900 |
my $newlastvalue1string = _numeration( $newlastvalue1, $pattern->{numbering1}, $locale ); |
906 |
my $newlastvalue1string = _numeration( $newlastvalue1, $pattern->{numbering1}, $locale, $translations ); |
901 |
$calculated =~ s/\{X\}/$newlastvalue1string/g; |
907 |
$calculated =~ s/\{X\}/$newlastvalue1string/g; |
902 |
} |
908 |
} |
903 |
if($calc{'Y'}) { |
909 |
if($calc{'Y'}) { |
904 |
my $newlastvalue2string = _numeration( $newlastvalue2, $pattern->{numbering2}, $locale ); |
910 |
my $newlastvalue2string = _numeration( $newlastvalue2, $pattern->{numbering2}, $locale, $translations ); |
905 |
$calculated =~ s/\{Y\}/$newlastvalue2string/g; |
911 |
$calculated =~ s/\{Y\}/$newlastvalue2string/g; |
906 |
} |
912 |
} |
907 |
if($calc{'Z'}) { |
913 |
if($calc{'Z'}) { |
908 |
my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale ); |
914 |
my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale, $translations ); |
909 |
$calculated =~ s/\{Z\}/$newlastvalue3string/g; |
915 |
$calculated =~ s/\{Z\}/$newlastvalue3string/g; |
910 |
} |
916 |
} |
911 |
|
917 |
|
Lines 934-951
sub GetSeq {
Link Here
|
934 |
|
940 |
|
935 |
my $locale = $subscription->{locale}; |
941 |
my $locale = $subscription->{locale}; |
936 |
|
942 |
|
|
|
943 |
my $translations = $subscription->{translations}; |
944 |
|
937 |
my $calculated = $pattern->{numberingmethod}; |
945 |
my $calculated = $pattern->{numberingmethod}; |
938 |
|
946 |
|
939 |
my $newlastvalue1 = $subscription->{'lastvalue1'} || 0; |
947 |
my $newlastvalue1 = $subscription->{'lastvalue1'} || 0; |
940 |
$newlastvalue1 = _numeration($newlastvalue1, $pattern->{numbering1}, $locale) if ($pattern->{numbering1}); # reset counter if needed. |
948 |
|
|
|
949 |
$newlastvalue1 = _numeration($newlastvalue1, $pattern->{numbering1}, $locale, $translations) if ($pattern->{numbering1}); # reset counter if needed. |
941 |
$calculated =~ s/\{X\}/$newlastvalue1/g; |
950 |
$calculated =~ s/\{X\}/$newlastvalue1/g; |
942 |
|
951 |
|
943 |
my $newlastvalue2 = $subscription->{'lastvalue2'} || 0; |
952 |
my $newlastvalue2 = $subscription->{'lastvalue2'} || 0; |
944 |
$newlastvalue2 = _numeration($newlastvalue2, $pattern->{numbering2}, $locale) if ($pattern->{numbering2}); # reset counter if needed. |
953 |
$newlastvalue2 = _numeration($newlastvalue2, $pattern->{numbering2}, $locale, $translations) if ($pattern->{numbering2}); # reset counter if needed. |
945 |
$calculated =~ s/\{Y\}/$newlastvalue2/g; |
954 |
$calculated =~ s/\{Y\}/$newlastvalue2/g; |
946 |
|
955 |
|
947 |
my $newlastvalue3 = $subscription->{'lastvalue3'} || 0; |
956 |
my $newlastvalue3 = $subscription->{'lastvalue3'} || 0; |
948 |
$newlastvalue3 = _numeration($newlastvalue3, $pattern->{numbering3}, $locale) if ($pattern->{numbering3}); # reset counter if needed. |
957 |
$newlastvalue3 = _numeration($newlastvalue3, $pattern->{numbering3}, $locale, $translations) if ($pattern->{numbering3}); # reset counter if needed. |
949 |
$calculated =~ s/\{Z\}/$newlastvalue3/g; |
958 |
$calculated =~ s/\{Z\}/$newlastvalue3/g; |
950 |
return $calculated; |
959 |
return $calculated; |
951 |
} |
960 |
} |
Lines 2501-2507
num_type can take :
Link Here
|
2501 |
=cut |
2510 |
=cut |
2502 |
|
2511 |
|
2503 |
sub _numeration { |
2512 |
sub _numeration { |
2504 |
my ($value, $num_type, $locale) = @_; |
2513 |
my ( $value, $num_type, $locale, $translations ) = @_; |
2505 |
$value ||= 0; |
2514 |
$value ||= 0; |
2506 |
$num_type //= ''; |
2515 |
$num_type //= ''; |
2507 |
$locale ||= 'en'; |
2516 |
$locale ||= 'en'; |
Lines 2529-2541
sub _numeration {
Link Here
|
2529 |
? $dt->format_cldr( "LLLL" ) |
2538 |
? $dt->format_cldr( "LLLL" ) |
2530 |
: $dt->strftime("%b"); |
2539 |
: $dt->strftime("%b"); |
2531 |
} elsif ( $num_type =~ /^season$/ ) { |
2540 |
} elsif ( $num_type =~ /^season$/ ) { |
2532 |
my @seasons= qw( Spring Summer Fall Winter ); |
2541 |
$value = $value % 4; |
2533 |
$value = $value % 4; |
2542 |
$string = $translations->{seasons}->[$value]; |
2534 |
$string = $seasons[$value]; |
|
|
2535 |
} elsif ( $num_type =~ /^seasonabrv$/ ) { |
2543 |
} elsif ( $num_type =~ /^seasonabrv$/ ) { |
2536 |
my @seasonsabrv= qw( Spr Sum Fal Win ); |
2544 |
$value = $value % 4; |
2537 |
$value = $value % 4; |
2545 |
$string = $translations->{seasonsabrv}->[$value]; |
2538 |
$string = $seasonsabrv[$value]; |
|
|
2539 |
} else { |
2546 |
} else { |
2540 |
$string = $value; |
2547 |
$string = $value; |
2541 |
} |
2548 |
} |
Lines 2597-2602
sub ReopenSubscription {
Link Here
|
2597 |
$sth->execute( EXPECTED, $subscriptionid, STOPPED ); |
2604 |
$sth->execute( EXPECTED, $subscriptionid, STOPPED ); |
2598 |
} |
2605 |
} |
2599 |
|
2606 |
|
|
|
2607 |
=head2 GetSeasonsTranslations |
2608 |
|
2609 |
Provide translations for the seasons and their abbreviations for the specified locale |
2610 |
|
2611 |
=cut |
2612 |
|
2613 |
sub GetSeasonsTranslations { |
2614 |
my ( $need_seasons, $need_seasonsabrv, $subtag ) = @_; |
2615 |
my @seasons = qw( Spring Summer Fall Winter ); |
2616 |
my @seasonsabrv = qw( Spr Sum Fal Win ); |
2617 |
my @error_messages = qw(); |
2618 |
|
2619 |
my @dirs = ( |
2620 |
C4::Context->config('intranetdir') . '/misc/translator/po', |
2621 |
C4::Context->config('intranetdir') . '/../../misc/translator/po', |
2622 |
); |
2623 |
|
2624 |
my $dir = first { -d } @dirs; |
2625 |
|
2626 |
if ($dir) { |
2627 |
my @po_paths = glob("$dir/$subtag*staff-prog.po"); |
2628 |
if (@po_paths) { |
2629 |
my $po_path = $po_paths[0]; |
2630 |
my $po_filename = ( $po_path =~ s/$dir\///gr ); |
2631 |
my $po_data = Locale::PO->load_file_ashash( $po_path, 'utf8' ); |
2632 |
|
2633 |
if ($need_seasons) { |
2634 |
my $response = _translate( $po_data, @seasons ); |
2635 |
@seasons = @{ $response->{translations} }; |
2636 |
@error_messages = |
2637 |
( @error_messages, map { sprintf( $_, $po_filename ) } @{ $response->{error_messages} } ); |
2638 |
} |
2639 |
|
2640 |
if ($need_seasonsabrv) { |
2641 |
my $response = _translate( $po_data, @seasonsabrv ); |
2642 |
@seasonsabrv = @{ $response->{translations} }; |
2643 |
@error_messages = |
2644 |
( @error_messages, map { sprintf( $_, $po_filename ) } @{ $response->{error_messages} } ); |
2645 |
} |
2646 |
} else { |
2647 |
push( |
2648 |
@error_messages, |
2649 |
"No translation file found for $subtag. Ensure that the translation files for $subtag are installed." |
2650 |
); |
2651 |
} |
2652 |
} else { |
2653 |
push( @error_messages, "The PO directory has not been found. There is a problem in your Koha installation." ); |
2654 |
} |
2655 |
|
2656 |
return { seasons => \@seasons, seasonsabrv => \@seasonsabrv, error_messages => \@error_messages }; |
2657 |
} |
2658 |
|
2600 |
=head2 subscriptionCurrentlyOnOrder |
2659 |
=head2 subscriptionCurrentlyOnOrder |
2601 |
|
2660 |
|
2602 |
$bool = subscriptionCurrentlyOnOrder( $subscriptionid ); |
2661 |
$bool = subscriptionCurrentlyOnOrder( $subscriptionid ); |
Lines 2691-2696
sub _can_do_on_subscription {
Link Here
|
2691 |
return 0; |
2750 |
return 0; |
2692 |
} |
2751 |
} |
2693 |
|
2752 |
|
|
|
2753 |
=head2 _translate |
2754 |
|
2755 |
Provide translations for the given words based on the provided data |
2756 |
|
2757 |
=cut |
2758 |
|
2759 |
sub _translate { |
2760 |
my ( $data, @words ) = @_; |
2761 |
|
2762 |
my @translations = qw(); |
2763 |
my @error_messages = qw(); |
2764 |
|
2765 |
for my $word (@words) { |
2766 |
my $regex = qr/^"$word"$|\%s$word\%s/; |
2767 |
my @msgids = grep /$regex/, keys %{$data}; |
2768 |
my $translation = ""; |
2769 |
|
2770 |
while ( ( $translation eq "" ) && ( my $msgid = shift(@msgids) ) ) { |
2771 |
next unless ( $data->{$msgid}->reference =~ /serials/ ); |
2772 |
my $msgstr = $data->{$msgid}->msgstr; |
2773 |
my @ids = split( /\%s/, $msgid ); |
2774 |
my @strs = split( /\%s/, $msgstr ); |
2775 |
|
2776 |
next unless ( scalar @ids == scalar @strs ); |
2777 |
|
2778 |
my $idx = first { $ids[$_] eq $word || $ids[$_] eq $msgid } 0 .. $#ids; |
2779 |
$translation = Locale::PO->dequote( $strs[$idx] ) if ( defined $idx ); |
2780 |
} |
2781 |
|
2782 |
if ( $translation eq "" ) { |
2783 |
push( @translations, $word ); |
2784 |
push( @error_messages, "The translation for $word doesn't exist in the file \%s" ); |
2785 |
next; |
2786 |
} |
2787 |
|
2788 |
push( @translations, $translation ); |
2789 |
} |
2790 |
|
2791 |
return { translations => \@translations, error_messages => \@error_messages }; |
2792 |
} |
2793 |
|
2694 |
=head2 findSerialsByStatus |
2794 |
=head2 findSerialsByStatus |
2695 |
|
2795 |
|
2696 |
@serials = findSerialsByStatus($status, $subscriptionid); |
2796 |
@serials = findSerialsByStatus($status, $subscriptionid); |