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

(-)a/C4/Acquisition.pm (-67 / +7 lines)
Lines 27-32 use C4::Dates qw(format_date format_date_in_iso); Link Here
27
use MARC::Record;
27
use MARC::Record;
28
use C4::Suggestions;
28
use C4::Suggestions;
29
use C4::Biblio;
29
use C4::Biblio;
30
use C4::Contract;
30
use C4::Debug;
31
use C4::Debug;
31
use C4::SQLHelper qw(InsertInTable UpdateInTable);
32
use C4::SQLHelper qw(InsertInTable UpdateInTable);
32
use C4::Bookseller qw(GetBookSellerFromId);
33
use C4::Bookseller qw(GetBookSellerFromId);
Lines 65-71 BEGIN { Link Here
65
        &NewOrderItem &ModItemOrder
66
        &NewOrderItem &ModItemOrder
66
67
67
        &GetParcels &GetParcel
68
        &GetParcels &GetParcel
68
        &GetContracts &GetContract
69
69
70
        &GetInvoices
70
        &GetInvoices
71
        &GetInvoice
71
        &GetInvoice
Lines 293-299 sub GetBasketAsCSV { Link Here
293
    my ($basketno, $cgi) = @_;
293
    my ($basketno, $cgi) = @_;
294
    my $basket = GetBasket($basketno);
294
    my $basket = GetBasket($basketno);
295
    my @orders = GetOrders($basketno);
295
    my @orders = GetOrders($basketno);
296
    my $contract = GetContract($basket->{'contractnumber'});
296
    my $contract = GetContract({
297
        contractnumber => $basket->{'contractnumber'}
298
    });
297
299
298
    my $template = C4::Templates::gettemplate("acqui/csv/basket.tmpl", "intranet", $cgi);
300
    my $template = C4::Templates::gettemplate("acqui/csv/basket.tmpl", "intranet", $cgi);
299
301
Lines 361-367 sub GetBasketGroupAsCSV { Link Here
361
    my @rows;
363
    my @rows;
362
    for my $basket (@$baskets) {
364
    for my $basket (@$baskets) {
363
        my @orders     = GetOrders( $$basket{basketno} );
365
        my @orders     = GetOrders( $$basket{basketno} );
364
        my $contract   = GetContract( $$basket{contractnumber} );
366
        my $contract   = GetContract({
367
            contractnumber => $$basket{contractnumber}
368
        });
365
        my $bookseller = GetBookSellerFromId( $$basket{booksellerid} );
369
        my $bookseller = GetBookSellerFromId( $$basket{booksellerid} );
366
        my $basketgroup = GetBasketgroup( $$basket{basketgroupid} );
370
        my $basketgroup = GetBasketgroup( $$basket{basketgroupid} );
367
371
Lines 2453-2524 sub GetRecentAcqui { Link Here
2453
    return $results;
2457
    return $results;
2454
}
2458
}
2455
2459
2456
=head3 GetContracts
2457
2458
  $contractlist = &GetContracts($booksellerid, $activeonly);
2459
2460
Looks up the contracts that belong to a bookseller
2461
2462
Returns a list of contracts
2463
2464
=over
2465
2466
=item C<$booksellerid> is the "id" field in the "aqbooksellers" table.
2467
2468
=item C<$activeonly> if exists get only contracts that are still active.
2469
2470
=back
2471
2472
=cut
2473
2474
sub GetContracts {
2475
    my ( $booksellerid, $activeonly ) = @_;
2476
    my $dbh = C4::Context->dbh;
2477
    my $query;
2478
    if (! $activeonly) {
2479
        $query = "
2480
            SELECT *
2481
            FROM   aqcontract
2482
            WHERE  booksellerid=?
2483
        ";
2484
    } else {
2485
        $query = "SELECT *
2486
            FROM aqcontract
2487
            WHERE booksellerid=?
2488
                AND contractenddate >= CURDATE( )";
2489
    }
2490
    my $result_set =
2491
      $dbh->selectall_arrayref( $query, { Slice => {} }, $booksellerid );
2492
    return @{$result_set};
2493
}
2494
2495
#------------------------------------------------------------#
2460
#------------------------------------------------------------#
2496
2461
2497
=head3 GetContract
2498
2499
  $contract = &GetContract($contractID);
2500
2501
Looks up the contract that has PRIMKEY (contractnumber) value $contractID
2502
2503
Returns a contract
2504
2505
=cut
2506
2507
sub GetContract {
2508
    my ( $contractno ) = @_;
2509
    my $dbh = C4::Context->dbh;
2510
    my $query = "
2511
        SELECT *
2512
        FROM   aqcontract
2513
        WHERE  contractnumber=?
2514
        ";
2515
2516
    my $sth = $dbh->prepare($query);
2517
    $sth->execute( $contractno );
2518
    my $result = $sth->fetchrow_hashref;
2519
    return $result;
2520
}
2521
2522
=head3 AddClaim
2462
=head3 AddClaim
2523
2463
2524
=over
2464
=over
(-)a/C4/Contract.pm (-7 / +77 lines)
Lines 17-24 package C4::Contract; Link Here
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
19
20
use Modern::Perl;
20
use strict;
21
use strict;
21
#use warnings; FIXME - Bug 2505
22
#use warnings; FIXME - Bug 2505
23
use C4::Context;
22
use C4::SQLHelper qw(:all);
24
use C4::SQLHelper qw(:all);
23
25
24
use vars qw($VERSION @ISA @EXPORT);
26
use vars qw($VERSION @ISA @EXPORT);
Lines 29-38 BEGIN { Link Here
29
    require Exporter;
31
    require Exporter;
30
	@ISA    = qw(Exporter);
32
	@ISA    = qw(Exporter);
31
	@EXPORT = qw(
33
	@EXPORT = qw(
32
		&GetContract
34
        &GetContracts
33
		&AddContract
35
        &GetContract
34
		&ModContract
36
        &AddContract
35
		&DelContract
37
        &ModContract
38
        &DelContract
36
	);
39
	);
37
}
40
}
38
41
Lines 50-61 The functions in this module deal with contracts. They allow to Link Here
50
add a new contract, to modify it or to get some informations around
53
add a new contract, to modify it or to get some informations around
51
a contract.
54
a contract.
52
55
53
This module is just a wrapper for C4::SQLHelper functions, so take a look at
56
=cut
54
SQLHelper centralised documentation to know how to use the following subs.
57
58
59
=head2 GetContracts
60
61
$contractlist = GetContracts({
62
    booksellerid => $booksellerid,
63
    activeonly => $activeonly
64
});
65
66
Looks up the contracts that belong to a bookseller
67
68
Returns a list of contracts
69
70
=over
71
72
=item C<$booksellerid> is the "id" field in the "aqbooksellers" table.
73
74
=item C<$activeonly> if exists get only contracts that are still active.
75
76
=back
55
77
56
=cut
78
=cut
57
79
58
sub GetContract { SearchInTable("aqcontract", shift); }
80
sub GetContracts {
81
    my ($params) = @_;
82
    my $booksellerid = $params->{booksellerid};
83
    my $activeonly = $params->{activeonly};
84
85
    my $dbh = C4::Context->dbh;
86
    my $query = "SELECT * FROM aqcontract";
87
    my $result_set;
88
    if($booksellerid) {
89
        $query .= " WHERE booksellerid=?";
90
91
        if($activeonly) {
92
            $query .= " AND contractenddate >= CURDATE( )";
93
        }
94
95
        $result_set = $dbh->selectall_arrayref( $query, { Slice => {} }, $booksellerid );
96
    }
97
    else {
98
        $result_set = $dbh->selectall_arrayref( $query, { Slice => {} } );
99
    }
100
101
    return $result_set;
102
}
103
104
=head2 GetContract
105
106
$contract = GetContract( { contractnumber => $contractnumber } );
107
108
Looks up the contract that has PRIMKEY (contractnumber) value $contractID
109
110
Returns a contract
111
112
=cut
113
114
sub GetContract {
115
    my ($params) = @_;
116
    my $contractno = $params->{contractnumber};
117
118
    my $dbh = C4::Context->dbh;
119
    my $query = "SELECT * FROM aqcontract WHERE contractnumber=?";
120
121
    my $sth = $dbh->prepare($query);
122
    $sth->execute($contractno);
123
    my $result = $sth->fetchrow_hashref;
124
    return $result;
125
}
126
127
128
#sub GetContract { SearchInTable("aqcontract", shift); }
59
129
60
sub AddContract { InsertInTable("aqcontract", shift); }
130
sub AddContract { InsertInTable("aqcontract", shift); }
61
131
(-)a/acqui/basket.pl (-2 / +7 lines)
Lines 30-35 use C4::Acquisition; Link Here
30
use C4::Budgets;
30
use C4::Budgets;
31
use C4::Branch;
31
use C4::Branch;
32
use C4::Bookseller qw( GetBookSellerFromId);
32
use C4::Bookseller qw( GetBookSellerFromId);
33
use C4::Contract;
33
use C4::Debug;
34
use C4::Debug;
34
use C4::Biblio;
35
use C4::Biblio;
35
use C4::Members qw/GetMember/;  #needed for permissions checking for changing basketgroup of a basket
36
use C4::Members qw/GetMember/;  #needed for permissions checking for changing basketgroup of a basket
Lines 167-173 if ( $op eq 'delete_confirm' ) { Link Here
167
    }
168
    }
168
    $basket->{creationdate} = ""            unless ( $basket->{creationdate} );
169
    $basket->{creationdate} = ""            unless ( $basket->{creationdate} );
169
    $basket->{authorisedby} = $loggedinuser unless ( $basket->{authorisedby} );
170
    $basket->{authorisedby} = $loggedinuser unless ( $basket->{authorisedby} );
170
    my $contract = &GetContract($basket->{contractnumber});
171
    my $contract = GetContract({
172
        contractnumber => $basket->{contractnumber}
173
    });
171
    $template->param(
174
    $template->param(
172
        basketno             => $basketno,
175
        basketno             => $basketno,
173
        basketname           => $basket->{'basketname'},
176
        basketname           => $basket->{'basketname'},
Lines 370-376 if ( $op eq 'delete_confirm' ) { Link Here
370
        push @cancelledorders_loop, $line;
373
        push @cancelledorders_loop, $line;
371
    }
374
    }
372
375
373
    my $contract = &GetContract($basket->{contractnumber});
376
    my $contract = GetContract({
377
        contractnumber => $basket->{contractnumber}
378
    });
374
    my @orders = GetOrders($basketno);
379
    my @orders = GetOrders($basketno);
375
380
376
    if ($basket->{basketgroupid}){
381
    if ($basket->{basketgroupid}){
(-)a/acqui/basketheader.pl (-3 / +13 lines)
Lines 52-59 use C4::Context; Link Here
52
use C4::Auth;
52
use C4::Auth;
53
use C4::Branch;
53
use C4::Branch;
54
use C4::Output;
54
use C4::Output;
55
use C4::Acquisition qw/GetBasket NewBasket GetContracts ModBasketHeader/;
55
use C4::Acquisition qw/GetBasket NewBasket ModBasketHeader/;
56
use C4::Bookseller qw/GetBookSellerFromId GetBookSeller/;
56
use C4::Bookseller qw/GetBookSellerFromId GetBookSeller/;
57
use C4::Contract qw/GetContracts/;
57
58
58
59
59
my $input = new CGI;
60
my $input = new CGI;
Lines 84-90 if ( $op eq 'add_form' ) { Link Here
84
        if (! $booksellerid) {
85
        if (! $booksellerid) {
85
            $booksellerid=$basket->{'booksellerid'};
86
            $booksellerid=$basket->{'booksellerid'};
86
        }
87
        }
87
        @contractloop = &GetContracts($booksellerid, 1);
88
        my $contracts = GetContracts({
89
            booksellerid => $booksellerid,
90
            activeonly => 1,
91
        });
92
93
        @contractloop = @$contracts;
88
        for (@contractloop) {
94
        for (@contractloop) {
89
            if ( $basket->{'contractnumber'} eq $_->{'contractnumber'} ) {
95
            if ( $basket->{'contractnumber'} eq $_->{'contractnumber'} ) {
90
                $_->{'selected'} = 1;
96
                $_->{'selected'} = 1;
Lines 94-100 if ( $op eq 'add_form' ) { Link Here
94
    } else {
100
    } else {
95
    #new basket
101
    #new basket
96
        my $basket;
102
        my $basket;
97
        push(@contractloop, &GetContracts($booksellerid, 1));
103
        my $contracts = GetContracts({
104
            booksellerid => $booksellerid,
105
            activeonly => 1,
106
        });
107
        push(@contractloop, @$contracts);
98
    }
108
    }
99
    my $bookseller = GetBookSellerFromId($booksellerid);
109
    my $bookseller = GetBookSellerFromId($booksellerid);
100
    my $count = scalar @contractloop;
110
    my $count = scalar @contractloop;
(-)a/acqui/neworderempty.pl (-1 / +4 lines)
Lines 78-83 use C4::Input; Link Here
78
78
79
use C4::Bookseller  qw/ GetBookSellerFromId /;
79
use C4::Bookseller  qw/ GetBookSellerFromId /;
80
use C4::Acquisition;
80
use C4::Acquisition;
81
use C4::Contract;
81
use C4::Suggestions;	# GetSuggestion
82
use C4::Suggestions;	# GetSuggestion
82
use C4::Biblio;			# GetBiblioData GetMarcPrice
83
use C4::Biblio;			# GetBiblioData GetMarcPrice
83
use C4::Items; #PrepareItemRecord
84
use C4::Items; #PrepareItemRecord
Lines 132-138 our $basket = GetBasket($basketno); Link Here
132
$booksellerid = $basket->{booksellerid} unless $booksellerid;
133
$booksellerid = $basket->{booksellerid} unless $booksellerid;
133
my $bookseller = GetBookSellerFromId($booksellerid);
134
my $bookseller = GetBookSellerFromId($booksellerid);
134
135
135
my $contract = &GetContract($basket->{contractnumber});
136
my $contract = GetContract({
137
    contractnumber => $basket->{contractnumber}
138
});
136
139
137
#simple parameters reading (all in one :-)
140
#simple parameters reading (all in one :-)
138
our $params = $input->Vars;
141
our $params = $input->Vars;
(-)a/acqui/supplier.pl (-3 / +2 lines)
Lines 43-49 To know the bookseller this script has to display details. Link Here
43
use strict;
43
use strict;
44
use warnings;
44
use warnings;
45
use C4::Auth;
45
use C4::Auth;
46
use C4::Contract qw/GetContract/;
46
use C4::Contract;
47
use C4::Biblio;
47
use C4::Biblio;
48
use C4::Output;
48
use C4::Output;
49
use CGI;
49
use CGI;
Lines 70-77 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
70
70
71
#build array for currencies
71
#build array for currencies
72
if ( $op eq 'display' ) {
72
if ( $op eq 'display' ) {
73
73
    my $contracts = GetContracts( { booksellerid => $booksellerid } );
74
    my $contracts = GetContract( { booksellerid => $booksellerid } );
75
74
76
    $template->param(
75
    $template->param(
77
        booksellerid  => $booksellerid,
76
        booksellerid  => $booksellerid,
(-)a/admin/aqcontract.pl (-5 / +5 lines)
Lines 61-68 if ( $op eq 'add_form' ) { Link Here
61
61
62
   # if contractnumber exists, it's a modify action, so read values to modify...
62
   # if contractnumber exists, it's a modify action, so read values to modify...
63
    if ($contractnumber) {
63
    if ($contractnumber) {
64
        my $contract =
64
        my $contract = GetContract({
65
          @{ GetContract( { contractnumber => $contractnumber } ) }[0];
65
            contractnumber => $contractnumber
66
        });
66
67
67
        $template->param(
68
        $template->param(
68
            contractnumber      => $contract->{contractnumber},
69
            contractnumber      => $contract->{contractnumber},
Lines 118-124 elsif ( $op eq 'add_validate' ) { Link Here
118
elsif ( $op eq 'delete_confirm' ) {
119
elsif ( $op eq 'delete_confirm' ) {
119
    $template->param( delete_confirm => 1 );
120
    $template->param( delete_confirm => 1 );
120
121
121
    my $contract = @{GetContract( { contractnumber => $contractnumber } )}[0];
122
    my $contract = GetContract( { contractnumber => $contractnumber } );
122
123
123
    $template->param(
124
    $template->param(
124
        contractnumber      => $$contract{contractnumber},
125
        contractnumber      => $$contract{contractnumber},
Lines 146-152 else { Link Here
146
    $template->param(else => 1);
147
    $template->param(else => 1);
147
148
148
    # get contracts
149
    # get contracts
149
    my @contracts = @{GetContract( { booksellerid => $booksellerid } )};
150
    my @contracts = @{GetContracts( { booksellerid => $booksellerid } )};
150
151
151
    # format dates
152
    # format dates
152
    for ( @contracts ) {
153
    for ( @contracts ) {
153
- 

Return to bug 12493