View | Details | Raw Unified | Return to bug 11967
Collapse All | Expand All

(-)a/C4/Letters.pm (-1 / +61 lines)
Lines 407-412 sub SendAlerts { Link Here
407
        );
407
        );
408
        sendmail(%mail) or carp $Mail::Sendmail::error;
408
        sendmail(%mail) or carp $Mail::Sendmail::error;
409
    }
409
    }
410
    elsif ( $type eq 'rma' ) {
411
        my $userenv = C4::Context->userenv;
412
        my $branchcode = $userenv->{branch};
413
414
        # prepare the letter...
415
        # search the biblionumber
416
        my $strsth =
417
        "select aqorders.*,aqbasket.*,biblio.*,biblioitems.* from aqorders
418
        LEFT JOIN aqbasket on aqbasket.basketno=aqorders.basketno
419
        LEFT JOIN biblio on aqorders.biblionumber=biblio.biblionumber
420
        LEFT JOIN biblioitems on aqorders.biblionumber=biblioitems.biblionumber
421
        where aqorders.ordernumber IN ("
422
          . join( ",", @$externalid ) . ")";
423
        my $sthorders = $dbh->prepare($strsth);
424
        $sthorders->execute;
425
        my $dataorders = $sthorders->fetchall_arrayref( {} );
426
        my $sthbookseller =
427
          $dbh->prepare("select aqbooksellers.*, aqcontacts.* from aqbooksellers LEFT JOIN aqcontacts on aqbooksellers.id=aqcontacts.booksellerid where aqbooksellers.id=?");
428
        $sthbookseller->execute( $dataorders->[0]->{booksellerid} );
429
        my $databookseller = $sthbookseller->fetchrow_hashref;
430
431
432
        my $letter = GetPreparedLetter (
433
            module => 'rma',
434
            letter_code => $letter_code,
435
            branchcode => $branchcode,
436
            tables => {
437
                'aqbooksellers'    => $dataorders->[0]->{booksellerid},
438
                'branches' => $branchcode,
439
            },
440
            repeat => $dataorders,
441
        );
442
443
        my $innerletter = $letter;
444
445
        # ... then send mail
446
        if ( $databookseller->{email} )
447
        {
448
            utf8::encode($innerletter->{title});
449
            utf8::encode($innerletter->{content});
450
            my %mail = (
451
                To             => $databookseller->{email},
452
                From           => $userenv->{emailaddress} || C4::Context->preference('KohaAdminEmailAddress'),
453
                Subject        => "" . $innerletter->{title},
454
                Message        => "" . $innerletter->{content},
455
                'Content-Type' => 'text/plain; charset="utf8"',
456
            );
457
458
            sendmail(%mail) or carp $Mail::Sendmail::error;
459
        }
460
        if ( C4::Context->preference("LetterLog") ) {
461
            logaction(
462
                "ACQUISITION",
463
                "Send RMA letter",
464
                "",
465
                "order list : "
466
                  . join( ",", @$externalid )
467
                  . "\n$innerletter->{title}\n$innerletter->{content}"
468
            );
469
        }
470
    }
410
}
471
}
411
472
412
=head2 GetPreparedLetter( %params )
473
=head2 GetPreparedLetter( %params )
Lines 747-753 sub SendQueuedMessages { Link Here
747
808
748
    my $unsent_messages = _get_unsent_messages();
809
    my $unsent_messages = _get_unsent_messages();
749
    MESSAGE: foreach my $message ( @$unsent_messages ) {
810
    MESSAGE: foreach my $message ( @$unsent_messages ) {
750
        # warn Data::Dumper->Dump( [ $message ], [ 'message' ] );
751
        warn sprintf( 'sending %s message to patron: %s',
811
        warn sprintf( 'sending %s message to patron: %s',
752
                      $message->{'message_transport_type'},
812
                      $message->{'message_transport_type'},
753
                      $message->{'borrowernumber'} || 'Admin' )
813
                      $message->{'borrowernumber'} || 'Admin' )
(-)a/acqui/returnorder.pl (+181 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use strict;
4
use warnings;
5
use CGI;
6
use C4::Bookseller;
7
use C4::Auth;
8
use C4::Koha;
9
use C4::Output;
10
use C4::Context;
11
use C4::Acquisition;
12
use C4::Letters;
13
use C4::Branch; # GetBranches
14
use C4::Members qw/GetMember/;
15
use C4::Dates qw/format_date/;
16
use C4::Reports;
17
18
my $input = new CGI;
19
my ($template, $loggedinuser, $cookie) = get_template_and_user({
20
    template_name => "acqui/returnorder.tt",
21
    query => $input,
22
    type => "intranet",
23
    authnotrequired => 0,
24
    flagsrequired => {acquisition => 'order_receive'},
25
    debug => 1,
26
});
27
28
my $supplierid = $input->param('supplierid') || undef; # we don't want "" or 0
29
my $delay      = $input->param('delay');
30
my $branch     = $input->param('branch');
31
my $op         = $input->param('op');
32
33
my @errors = ();
34
$delay = 30 unless defined $delay;
35
unless ($delay =~ /^\d{1,3}$/) {
36
    push @errors, {delay_digits => 1, bad_delay => $delay};
37
    $delay = 30;    #default value for delay
38
}
39
40
if ($op and $op eq "findsupplier")
41
{
42
    my $supplier = $input->param('supplier');
43
    my @suppliers = C4::Bookseller::GetBookSeller($supplier);
44
    my $count = scalar @suppliers;
45
    my @loop_suppliers;
46
    for ( my $i = 0 ; $i < $count ; $i++ ) {
47
        my $orders  = GetBasketsByBookseller( $suppliers[$i]->{'id'}, {groupby => "aqbasket.basketno", orderby => "aqbasket.basketname"} );
48
        my $ordcount = scalar @$orders;
49
        my %line;
50
51
        $line{supplierid} = $suppliers[$i]->{'id'};
52
        $line{name}       = $suppliers[$i]->{'name'};
53
        $line{active}     = $suppliers[$i]->{'active'};
54
        my @loop_basket;
55
        my $uid;
56
        $uid = GetMember(borrowernumber => $loggedinuser)->{userid} if $loggedinuser;
57
        my $i3 = 0;
58
        for ( my $i2 = 0 ; $i2 < $ordcount ; $i2++ ) {
59
            if ( $orders->[$i2]{'authorisedby'} == $loggedinuser || haspermission($uid, { flagsrequired   => { 'acquisition' => '*' } } ) ) {
60
                my %inner_line;
61
                my @orders_items = GetOrders($orders->[$i2]{'basketno'});
62
                $inner_line{basketno}     = $orders->[$i2]{'basketno'};
63
                $inner_line{basketname}     = $orders->[$i2]{'basketname'};
64
                $inner_line{total}        = scalar @orders_items;
65
                $inner_line{authorisedby} = $orders->[$i2]{'authorisedby'};
66
                my $authby = GetMember(borrowernumber => $orders->[$i2]{'authorisedby'});
67
                $inner_line{surname}      = $authby->{'firstname'};
68
                $inner_line{firstname}    = $authby->{'surname'};
69
                $inner_line{creationdate} = format_date( $orders->[$i2]{'creationdate'} );
70
                $inner_line{closedate}    = format_date( $orders->[$i2]{'closedate'}    );
71
                $inner_line{uncertainprice} = $orders->[$i2]{'uncertainprice'};
72
                $inner_line{orders_items} = \@orders_items;
73
                $inner_line{odd} = $i3 % 2;
74
                if ($inner_line{total} > 0) {
75
                    push @loop_basket, \%inner_line;
76
                    $i3++;
77
                }
78
            }
79
        }
80
        $line{loop_basket} = \@loop_basket;
81
        push @loop_suppliers, \%line;
82
    }
83
84
    #use Data::Dumper;
85
    #die Dumper \@loop_suppliers;
86
87
    my @letters;
88
    my $letters=GetLetters({module=>'rma',code=>'RMA'});
89
    foreach (@$letters){
90
        push @letters, {code=>$_->{code},name=>$_->{name}};
91
    }
92
    $template->param(letters=>\@letters) if (@letters);
93
    $template->param(suppliers => \@loop_suppliers);
94
    $template->param(suppliername => $input->param('supplier'));
95
}
96
97
if ($op and $op eq "send_alert"){
98
    my @ordernums = $input->param("generate_for");
99
    my $output = $input->param("output");
100
    if (@ordernums){
101
        if ($output eq "email"){
102
            SendAlerts('rma',\@ordernums,$input->param("letter_code"));
103
        }
104
        else {
105
            my $dbh = C4::Context->dbh;
106
            my $basename = $input->param("basename");
107
            my $sep      = $input->param("sep");
108
            print $input->header(
109
                -type       => 'application/vnd.sun.xml.calc',
110
                -encoding    => 'utf-8',
111
                -attachment => "$basename.csv",
112
                -name       => "$basename.csv"
113
            );
114
            my $strsth = "SELECT aqorders.*,aqbasket.*,biblio.*,biblioitems.*, bs.*
115
                FROM aqorders
116
                LEFT JOIN aqbasket on aqbasket.basketno=aqorders.basketno
117
                LEFT JOIN biblio on aqorders.biblionumber=biblio.biblionumber
118
                LEFT JOIN biblioitems on aqorders.biblionumber=biblioitems.biblionumber
119
                JOIN aqbooksellers bs on bs.id = booksellerid
120
                where aqorders.ordernumber IN (". join( ",", @ordernums ) . ")";
121
            my $sthorders = $dbh->prepare($strsth);
122
            $sthorders->execute;
123
            my $dataorders = $sthorders->fetchall_arrayref( {} );
124
            print "aqbooksellers.name" . $sep;
125
            print "aqbooksellers.address1" . $sep;
126
            print "aqbooksellers.address2" . $sep;
127
            print "aqbooksellers.address3" . $sep;
128
            print "aqbooksellers.address4" . $sep;
129
            print "aqbooksellers.phone" . $sep;
130
            print "aqorders.ordernumber" . $sep;
131
            print "biblioitems.isbn" . $sep;
132
            print "biblio.title" . $sep;
133
            print "biblio.author" . $sep;
134
            print "aqorders.quantity" . $sep;
135
            print "aqorders.listprice" . $sep;
136
            print "\n";
137
            foreach my $data (@$dataorders) {
138
                print _surround($data->{name}) . $sep;
139
                print _surround($data->{address1}) . $sep;
140
                print _surround($data->{address2}) . $sep;
141
                print _surround($data->{address3}) . $sep;
142
                print _surround($data->{address4}) . $sep;
143
                print _surround($data->{phone}) . $sep;
144
                print _surround($data->{ordernumber}) . $sep;
145
                print _surround($data->{isbn}) . $sep;
146
                print _surround($data->{title}) . $sep;
147
                print _surround($data->{author}) . $sep;
148
                print _surround($data->{quantity}) . $sep;
149
                print _surround($data->{listprice}) . $sep;
150
                print "\n";
151
            }
152
153
        exit(1);
154
        }
155
    }
156
}
157
158
sub _surround {
159
    my $string = shift || "";
160
    $string =~ s/"/""/g;
161
    return "\"$string\"";
162
}
163
164
my $CGIextChoice = CGI::scrolling_list(
165
    -name     => 'MIME',
166
    -id       => 'MIME',
167
    -values   => ['CSV'], # FIXME translation
168
    -size     => 1,
169
    -multiple => 0
170
);
171
172
my $CGIsepChoice = C4::Reports::GetDelimiterChoices;
173
174
$template->param(ERROR_LOOP => \@errors) if (@errors);
175
$template->param(
176
    CGIextChoice  => $CGIextChoice,
177
    CGIsepChoice  => $CGIsepChoice,
178
    delay => $delay,
179
    intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
180
);
181
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/installer/data/mysql/en/mandatory/sample_notices.sql (+12 lines)
Lines 142-144 Thank you. Link Here
142
142
143
Your library.'
143
Your library.'
144
);
144
);
145
INSERT INTO `letter` (`module`,`code`,`name`,`title`,`content`)
146
VALUES ('rma', 'RMA', 'Return merchandise authorization', 'Return merchandise authorization',
147
'<<aqbooksellers.name>>
148
<<aqbooksellers.address1>>
149
<<aqbooksellers.address2>>
150
<<aqbooksellers.address3>>
151
<<aqbooksellers.address4>>
152
<<aqbooksellers.phone>>
153
Some items in this order will be returned :
154
Order number
155
<<aqorders.ordernumber>> (<<aqorders.title>>) (<<aqorders.quantity>> ordered) ($<<aqorders.listprice>> each)'
156
);
(-)a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql (+10 lines)
Lines 44-46 Thank you. Link Here
44
44
45
Your library.'
45
Your library.'
46
);
46
);
47
INSERT INTO `letter` (`module`,`code`,`name`,`title`,`content`) VALUES ('rma', 'RMA', 'Bon de retour', 'Bon de retour', '<<aqbooksellers.name>>
48
<<aqbooksellers.address1>>
49
<<aqbooksellers.address2>>
50
<<aqbooksellers.address3>>
51
<<aqbooksellers.address4>>
52
<<aqbooksellers.phone>>
53
Certains items de la commande seront retournés :
54
Numéro de commande
55
<<aqorders.ordernumber>> (<<aqorders.title>>) (<<aqorders.quantity>> commandé(s)) ($<<aqorders.listprice>> chacun)'
56
);
(-)a/installer/data/mysql/updatedatabase.pl (+18 lines)
Lines 8705-8710 if ( CheckVersion($DBversion) ) { Link Here
8705
}
8705
}
8706
8706
8707
8707
8708
$DBversion = "XXX";
8709
if ( CheckVersion($DBversion) ) {
8710
    $dbh->do(q{
8711
        INSERT INTO `letter` (`module`,`code`,`name`,`title`,`content`) VALUES ('rma', 'RMA', 'Return merchandise authorization', 'Return merchandise authorization',
8712
        '<<aqbooksellers.name>>
8713
        <<aqbooksellers.address1>>
8714
        <<aqbooksellers.address2>>
8715
        <<aqbooksellers.address3>>
8716
        <<aqbooksellers.address4>>
8717
        <<aqbooksellers.phone>>
8718
        Some items in this order will be returned :
8719
        Order number
8720
        <<aqorders.ordernumber>> (<<aqorders.title>>) (<<aqorders.quantity>> ordered) ($<<aqorders.listprice>> each)');
8721
    });
8722
    print "Upgrade to $DBversion done (Add the RMA letter)\n";
8723
    SetVersion($DBversion);
8724
}
8725
8708
=head1 FUNCTIONS
8726
=head1 FUNCTIONS
8709
8727
8710
=head2 TableExists($table)
8728
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css (+12 lines)
Lines 1899-1904 fieldset.rows+h3 {clear:both;padding-top:.5em;} Link Here
1899
    color : #cc0000;
1899
    color : #cc0000;
1900
    }
1900
    }
1901
1901
1902
td.expanded {
1903
        background : transparent url("../../img/collapse.gif") 0 6px no-repeat;
1904
        cursor : pointer;
1905
        padding-left : 12px;
1906
}
1907
1908
td.collapsed {
1909
        background : transparent url("../../img/expand.gif") 0 6px no-repeat;
1910
        cursor : pointer;
1911
	padding-left : 12px;
1912
}
1913
1902
div.pager {
1914
div.pager {
1903
	background-color : #E8E8E8;
1915
	background-color : #E8E8E8;
1904
	border : 1px solid #BCBCBC;
1916
	border : 1px solid #BCBCBC;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc (+1 lines)
Lines 1-5 Link Here
1
<ul>
1
<ul>
2
	<li><a href="/cgi-bin/koha/acqui/lateorders.pl">Late orders</a></li>
2
	<li><a href="/cgi-bin/koha/acqui/lateorders.pl">Late orders</a></li>
3
    <li><a href="/cgi-bin/koha/acqui/returnorder.pl">Return order</a></li>
3
	[% IF ( suggestion ) %]<li><a href="/cgi-bin/koha/suggestion/suggestion.pl">Suggestions</a></li>[% ELSE %][% END %]
4
	[% IF ( suggestion ) %]<li><a href="/cgi-bin/koha/suggestion/suggestion.pl">Suggestions</a></li>[% ELSE %][% END %]
4
    <li><a href="/cgi-bin/koha/acqui/invoices.pl">Invoices</a></li>
5
    <li><a href="/cgi-bin/koha/acqui/invoices.pl">Invoices</a></li>
5
    [% IF ( CAN_user_acquisition_budget_manage ) %]
6
    [% IF ( CAN_user_acquisition_budget_manage ) %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/returnorder.tt (+116 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Acquisitions &rsaquo; Return merchandise authorization</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
</head>
5
<body>
6
[% INCLUDE 'header.inc' %]
7
[% INCLUDE 'acquisitions-search.inc' %]
8
9
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> &rsaquo; <a href="returnorder.pl">Return merchandise authorization</a></div>
10
11
<div id="doc3" class="yui-t2">
12
13
   <div id="bd">
14
   <div id="yui-main">
15
   <div class="yui-b">
16
17
<h1>Return merchandise authorization</h1>
18
<div id="acqui_returnorder">
19
20
<form name="findsupplier" action="returnorder.pl" method="post">
21
    <input type="hidden" name="op" value="findsupplier" />
22
    <p><label for="supplierpage">Vendor </label>
23
    <input type="text" size="25" name="supplier" id="supplierpage" class="focus" value="[% suppliername %]" />
24
    <input type="submit" value="Search" />
25
    </p>
26
</form>
27
28
[% IF ( suppliers ) %]
29
<form action="returnorder.pl" name="returnorder" method="post">
30
  <input type="hidden" name="op" value="send_alert" />
31
    <table>
32
        <tr>
33
            <th>Basket (#)</th>
34
            <th>Items</th>
35
            <th>Created by</th>
36
            <th>Date</th>
37
        </tr>
38
    [% FOREACH supplier IN suppliers %]
39
        [% FOREACH loop_baske IN supplier.loop_basket %]
40
        <tr class="[% IF ( loop_baske.odd ) %]highlight[% END %]"
41
            onclick="jQuery('.orders_items_[% loop_baske.basketno %]').toggle();
42
                jQuery(this).children(':first').toggleClass('collapsed');jQuery(this).children(':first').toggleClass('expanded')"
43
                style="cursor:pointer;">
44
            <td class="collapsed"> [% loop_baske.basketname %] (#[% loop_baske.basketno %])</td>
45
            <td>[% loop_baske.total %]</td>
46
            <td>
47
                    [% loop_baske.firstname %]
48
                    [% loop_baske.surname %]
49
            </td>
50
            <td>[% loop_baske.creationdate %]</td>
51
        </tr>
52
        [% FOREACH orders_item IN loop_baske.orders_items %]
53
        <tr class="orders_items_[% orders_item.basketno %] [% IF ( orders_item.odd ) %] highlight[% END %]"
54
            style="display:none;">
55
            <td colspan="3">
56
                [% orders_item.title %][% orders_item.seriestitle %][% orders_item.volume %]
57
                by [% orders_item.author %]
58
            </td>
59
            <td>
60
                <input type="checkbox" name="generate_for" value="[% orders_item.ordernumber %]" />
61
            </td>
62
        </tr>
63
        [% END %]
64
    [% END %]
65
    [% END %]
66
    </table>
67
    <fieldset class="rows">
68
    <legend>Output</legend>
69
        <ol>
70
            [% IF ( letters ) %]
71
            <li>
72
                <label for="outputemail">Send email</label>
73
                <input type="radio" name="output" value="email" id="outputemail" checked="checked" />
74
                <label class="inline" for="letter_code">Using notice: </label>
75
                <select name="letter_code" id="letter_code">
76
                  [% FOREACH letter IN letters %]
77
                    <option value="[% letter.code %]">[% letter.name %]</option>
78
                  [% END %]
79
                </select>
80
            </li>
81
            [% END %]
82
            <li>
83
                <label for="outputfile">To a file:</label>
84
                <input type="radio" name="output" value="file" id="outputfile" />
85
                <label class="inline" for="basename">Named: </label>
86
                <input type="text" name="basename" id="basename" value="Export" />
87
                <label class="inline" for="MIME">Into an application</label>
88
                [% CGIextChoice %]
89
                <select name="sep" id="sep" size="1">
90
                    [% FOREACH value IN CGIsepChoice.values.sort() %]
91
                      [% IF ( value == CGIsepChoice.default ) %]
92
                        <option value="[% value %]" selected="selected">[% value %]</option>
93
                      [% ELSE %]
94
                        <option value="[% value %]">[% value %]</option>
95
                    [% END %]
96
                    [% END %]
97
               </select>
98
            </li>
99
        </ol>
100
    </fieldset>
101
    <fieldset class="action">
102
        <input type="submit" value="Generate RMA" />
103
        <input type="hidden" name="report_name" value="[% report_name %]" />
104
        <input type="hidden" name="do_it" value="1" />
105
    </fieldset>
106
    </form>
107
[% ELSE %]<p>No baskets for this vendor.</p>
108
[% END %]
109
</div>
110
</div>
111
</div>
112
<div class="yui-b">
113
[% INCLUDE 'acquisitions-menu.inc' %]
114
</div>
115
</div>
116
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt (-1 / +6 lines)
Lines 320-326 $(document).ready(function() { Link Here
320
                                    [% ELSE %]
320
                                    [% ELSE %]
321
                                      <option value="members">Members</option>
321
                                      <option value="members">Members</option>
322
                                    [% END %]
322
                                    [% END %]
323
                                    [% IF ( module == "serial" ) %]
323
                                    [% IF ( module == "rma" ) %]
324
                                      <option value="rma" selected="selected">Return Merchandise Authorization</option>
325
                                    [% ELSE %]
326
                                      <option value="rma">Return Merchandise Authorization</option>
327
                                    [% END %]
328
                                    [% IF ( serial ) %]
324
                                      <option value="serial" selected="selected">Serials (routing list)</option>
329
                                      <option value="serial" selected="selected">Serials (routing list)</option>
325
                                    [% ELSE %]
330
                                    [% ELSE %]
326
                                      <option value="serial">Serials (routing list)</option>
331
                                      <option value="serial">Serials (routing list)</option>
(-)a/tools/letter.pl (-2 / +1 lines)
Lines 221-227 sub add_form { Link Here
221
    if ($module eq 'reserves') {
221
    if ($module eq 'reserves') {
222
        push @{$field_selection}, add_fields('borrowers', 'reserves', 'biblio', 'items');
222
        push @{$field_selection}, add_fields('borrowers', 'reserves', 'biblio', 'items');
223
    }
223
    }
224
    elsif ($module eq 'claimacquisition') {
224
    elsif ($module eq 'claimacquisition' || $module eq 'rma') {
225
        push @{$field_selection}, add_fields('aqbooksellers', 'aqorders', 'biblio', 'biblioitems');
225
        push @{$field_selection}, add_fields('aqbooksellers', 'aqorders', 'biblio', 'biblioitems');
226
    }
226
    }
227
    elsif ($module eq 'claimissues') {
227
    elsif ($module eq 'claimissues') {
228
- 

Return to bug 11967