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

(-)a/C4/Acquisition.pm (-10 / +10 lines)
Lines 29-35 use C4::Debug; Link Here
29
use C4::Templates qw(gettemplate);
29
use C4::Templates qw(gettemplate);
30
use Koha::DateUtils qw( dt_from_string output_pref );
30
use Koha::DateUtils qw( dt_from_string output_pref );
31
use Koha::Acquisition::Order;
31
use Koha::Acquisition::Order;
32
use Koha::Acquisition::Bookseller;
32
use Koha::Acquisition::Booksellers;
33
use Koha::Number::Price;
33
use Koha::Number::Price;
34
use Koha::Libraries;
34
use Koha::Libraries;
35
35
Lines 351-363 sub GetBasketGroupAsCSV { Link Here
351
        my $contract   = GetContract({
351
        my $contract   = GetContract({
352
            contractnumber => $basket->{contractnumber}
352
            contractnumber => $basket->{contractnumber}
353
        });
353
        });
354
        my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} });
354
        my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
355
        my $basketgroup = GetBasketgroup( $$basket{basketgroupid} );
355
        my $basketgroup = GetBasketgroup( $$basket{basketgroupid} );
356
356
357
        foreach my $order (@orders) {
357
        foreach my $order (@orders) {
358
            my $bd = GetBiblioData( $order->{'biblionumber'} );
358
            my $bd = GetBiblioData( $order->{'biblionumber'} );
359
            my $row = {
359
            my $row = {
360
                clientnumber => $bookseller->{accountnumber},
360
                clientnumber => $bookseller->accountnumber,
361
                basketname => $basket->{basketname},
361
                basketname => $basket->{basketname},
362
                ordernumber => $order->{ordernumber},
362
                ordernumber => $order->{ordernumber},
363
                author => $bd->{author},
363
                author => $bd->{author},
Lines 369-382 sub GetBasketGroupAsCSV { Link Here
369
                quantity => $order->{quantity},
369
                quantity => $order->{quantity},
370
                rrp_tax_included => $order->{rrp_tax_included},
370
                rrp_tax_included => $order->{rrp_tax_included},
371
                rrp_tax_excluded => $order->{rrp_tax_excluded},
371
                rrp_tax_excluded => $order->{rrp_tax_excluded},
372
                discount => $bookseller->{discount},
372
                discount => $bookseller->discount,
373
                ecost_tax_included => $order->{ecost_tax_included},
373
                ecost_tax_included => $order->{ecost_tax_included},
374
                ecost_tax_excluded => $order->{ecost_tax_excluded},
374
                ecost_tax_excluded => $order->{ecost_tax_excluded},
375
                notes => $order->{order_vendornote},
375
                notes => $order->{order_vendornote},
376
                entrydate => $order->{entrydate},
376
                entrydate => $order->{entrydate},
377
                booksellername => $bookseller->{name},
377
                booksellername => $bookseller->name,
378
                bookselleraddress => $bookseller->{address1},
378
                bookselleraddress => $bookseller->address1,
379
                booksellerpostal => $bookseller->{postal},
379
                booksellerpostal => $bookseller->postal,
380
                contractnumber => $contract->{contractnumber},
380
                contractnumber => $contract->{contractnumber},
381
                contractname => $contract->{contractname},
381
                contractname => $contract->{contractname},
382
            };
382
            };
Lines 2868-2874 sub populate_order_with_prices { Link Here
2868
    my $booksellerid = $params->{booksellerid};
2868
    my $booksellerid = $params->{booksellerid};
2869
    return unless $booksellerid;
2869
    return unless $booksellerid;
2870
2870
2871
    my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
2871
    my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
2872
2872
2873
    my $receiving = $params->{receiving};
2873
    my $receiving = $params->{receiving};
2874
    my $ordering  = $params->{ordering};
2874
    my $ordering  = $params->{ordering};
Lines 2877-2883 sub populate_order_with_prices { Link Here
2877
2877
2878
    if ($ordering) {
2878
    if ($ordering) {
2879
        $order->{tax_rate_on_ordering} //= $order->{tax_rate};
2879
        $order->{tax_rate_on_ordering} //= $order->{tax_rate};
2880
        if ( $bookseller->{listincgst} ) {
2880
        if ( $bookseller->listincgst ) {
2881
            # The user entered the rrp tax included
2881
            # The user entered the rrp tax included
2882
            $order->{rrp_tax_included} = $order->{rrp};
2882
            $order->{rrp_tax_included} = $order->{rrp};
2883
2883
Lines 2914-2920 sub populate_order_with_prices { Link Here
2914
2914
2915
    if ($receiving) {
2915
    if ($receiving) {
2916
        $order->{tax_rate_on_receiving} //= $order->{tax_rate};
2916
        $order->{tax_rate_on_receiving} //= $order->{tax_rate};
2917
        if ( $bookseller->{invoiceincgst} ) {
2917
        if ( $bookseller->invoiceincgst ) {
2918
            # Trick for unitprice. If the unit price rounded value is the same as the ecost rounded value
2918
            # Trick for unitprice. If the unit price rounded value is the same as the ecost rounded value
2919
            # we need to keep the exact ecost value
2919
            # we need to keep the exact ecost value
2920
            if ( Koha::Number::Price->new( $order->{unitprice} )->round == Koha::Number::Price->new( $order->{ecost_tax_included} )->round ) {
2920
            if ( Koha::Number::Price->new( $order->{unitprice} )->round == Koha::Number::Price->new( $order->{ecost_tax_included} )->round ) {
(-)a/C4/Bookseller.pm (-138 lines)
Lines 23-35 use warnings; Link Here
23
23
24
use base qw( Exporter );
24
use base qw( Exporter );
25
25
26
use C4::Bookseller::Contact;
27
28
our @EXPORT_OK = qw(
26
our @EXPORT_OK = qw(
29
  GetBooksellersWithLateOrders
27
  GetBooksellersWithLateOrders
30
  ModBookseller
31
  DelBookseller
32
  AddBookseller
33
);
28
);
34
29
35
=head1 NAME
30
=head1 NAME
Lines 113-251 sub GetBooksellersWithLateOrders { Link Here
113
    return %supplierlist;
108
    return %supplierlist;
114
}
109
}
115
110
116
#--------------------------------------------------------------------#
117
118
=head2 AddBookseller
119
120
$id = &AddBookseller($bookseller);
121
122
Creates a new bookseller. C<$bookseller> is a reference-to-hash whose
123
keys are the fields of the aqbooksellers table in the Koha database.
124
All fields must be present.
125
126
Returns the ID of the newly-created bookseller.
127
128
=cut
129
130
sub AddBookseller {
131
    my ($data, $contacts) = @_;
132
    my $dbh    = C4::Context->dbh;
133
    my $query = q|
134
        INSERT INTO aqbooksellers
135
            (
136
                name,      address1,      address2,     address3, address4,
137
                postal,    phone,         accountnumber,fax,      url,
138
                active,    listprice,     invoiceprice, gstreg,
139
                listincgst,invoiceincgst, tax_rate,      discount, notes,
140
                deliverytime
141
            )
142
        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) |
143
      ;
144
    my $sth = $dbh->prepare($query);
145
    $sth->execute(
146
        $data->{'name'},         $data->{'address1'},
147
        $data->{'address2'},     $data->{'address3'},
148
        $data->{'address4'},     $data->{'postal'},
149
        $data->{'phone'},        $data->{'accountnumber'},
150
        $data->{'fax'},          $data->{'url'},
151
        $data->{'active'},       $data->{'listprice'},
152
        $data->{'invoiceprice'}, $data->{'gstreg'},
153
        $data->{'listincgst'},   $data->{'invoiceincgst'},
154
        $data->{'tax_rate'},      $data->{'discount'},
155
        $data->{notes},          $data->{deliverytime},
156
    );
157
158
    # return the id of this new supplier
159
    my $id = $dbh->{'mysql_insertid'};
160
    if ($id && $contacts) {
161
        foreach my $contact (@$contacts) {
162
            $contact = C4::Bookseller::Contact->new( $contact )
163
                unless ref $contacts eq 'C4::Bookseller::Contact';
164
            $contact->bookseller($id);
165
            $contact->save();
166
        }
167
    }
168
    return $id;
169
}
170
171
#-----------------------------------------------------------------#
172
173
=head2 ModBookseller
174
175
ModBookseller($bookseller);
176
177
Updates the information for a given bookseller. C<$bookseller> is a
178
reference-to-hash whose keys are the fields of the aqbooksellers table
179
in the Koha database. It must contain entries for all of the fields.
180
The entry to modify is determined by C<$bookseller-E<gt>{id}>.
181
182
The easiest way to get all of the necessary fields is to look up a
183
book seller with C<Koha::Acquisition::Bookseller>, modify what's necessary, then call
184
C<&ModBookseller> with the result.
185
186
=cut
187
188
sub ModBookseller {
189
    my ($data, $contacts) = @_;
190
    my $dbh    = C4::Context->dbh;
191
    return unless $data->{'id'};
192
    my $query  = 'UPDATE aqbooksellers
193
        SET name=?,address1=?,address2=?,address3=?,address4=?,
194
            postal=?,phone=?,accountnumber=?,fax=?,url=?,
195
            active=?,listprice=?, invoiceprice=?,
196
            gstreg=?,listincgst=?,invoiceincgst=?,
197
            discount=?,notes=?,tax_rate=?,deliverytime=?
198
        WHERE id=?';
199
    my $sth = $dbh->prepare($query);
200
    my $cnt = $sth->execute(
201
        $data->{'name'},         $data->{'address1'},
202
        $data->{'address2'},     $data->{'address3'},
203
        $data->{'address4'},     $data->{'postal'},
204
        $data->{'phone'},        $data->{'accountnumber'},
205
        $data->{'fax'},          $data->{'url'},
206
        $data->{'active'},       $data->{'listprice'},
207
        $data->{'invoiceprice'}, $data->{'gstreg'},
208
        $data->{'listincgst'},   $data->{'invoiceincgst'},
209
        $data->{'discount'},     $data->{'notes'},
210
        $data->{'tax_rate'},      $data->{deliverytime},
211
        $data->{'id'}
212
    );
213
    $contacts ||= $data->{'contacts'};
214
    my $contactquery = "DELETE FROM aqcontacts WHERE booksellerid = ?";
215
    my @contactparams = ($data->{'id'});
216
    if ($contacts) {
217
        foreach my $contact (@$contacts) {
218
            $contact = C4::Bookseller::Contact->new( $contact )
219
                unless ref $contacts eq 'C4::Bookseller::Contact';
220
            $contact->bookseller($data->{'id'});
221
            $contact->save();
222
            push @contactparams, $contact->id if $contact->id;
223
        }
224
        if ($#contactparams > 0) {
225
            $contactquery .= ' AND id NOT IN (' . ('?, ' x ($#contactparams - 1)) . '?);';
226
        }
227
    }
228
    $sth = $dbh->prepare($contactquery);
229
    $sth->execute(@contactparams);
230
    return $cnt;
231
}
232
233
=head2 DelBookseller
234
235
DelBookseller($booksellerid);
236
237
delete the supplier record identified by $booksellerid
238
This sub assumes it is called only if the supplier has no order.
239
240
=cut
241
242
sub DelBookseller {
243
    my $id  = shift;
244
    my $dbh = C4::Context->dbh;
245
    my $sth = $dbh->prepare('DELETE FROM aqbooksellers WHERE id=?');
246
    return $sth->execute($id);
247
}
248
249
1;
111
1;
250
112
251
__END__
113
__END__
(-)a/C4/Bookseller/Contact.pm (-209 lines)
Lines 1-209 Link Here
1
package C4::Bookseller::Contact;
2
3
# Copyright 2013 C & P Bibliography Services
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
=head1 NAME
21
22
C4::Bookseller::Contact - object class for contacts associated with vendors
23
24
=head1 SYNPOSIS
25
26
This class provides an object-oriented interface for handling vendor contacts.
27
It uses Class::Accessor to provide access to the following fields:
28
29
=head1 FIELDS
30
31
=over 8
32
33
=item id
34
35
ID of the contact. This is not used initially, since contacts are actually
36
stored in the aqbooksellers table.
37
38
=item name
39
40
Contact name.
41
42
=item position
43
44
Contact's position.
45
46
=item phone
47
48
Contact's primary phone number.
49
50
=item altphone
51
52
Contact's alternate phone number.
53
54
=item fax
55
56
Contact's fax number.
57
58
=item email
59
60
Contact's e-mail address.
61
62
=item notes
63
64
Notes about contact.
65
66
=item orderacquisition
67
68
Whether the contact should receive acquisitions orders.
69
70
=item claimacquisition
71
72
Whether the contact should receive acquisitions claims.
73
74
=item claimissues
75
76
Whether the contact should receive serials claims.
77
78
=item acqprimary
79
80
Whether the contact is the primary contact for acquisitions.
81
82
=item serialsprimary
83
84
Whether the contact is the primary contact for serials.
85
86
=item bookseller
87
88
ID of the bookseller the contact is associated with.
89
90
=back
91
92
=cut
93
94
use Modern::Perl;
95
use C4::Context;
96
97
use base qw(Class::Accessor);
98
99
__PACKAGE__->mk_accessors(qw(id name position phone altphone fax email notes orderacquisition claimacquisition claimissues acqprimary serialsprimary bookseller));
100
101
=head1 METHODS
102
103
=head2 get_from_bookseller
104
105
    my @contacts = @{C4::Bookseller::Contact->get_from_bookseller($booksellerid)};
106
107
Returns a reference to an array of C4::Bookseller::Contact objects for the
108
specified bookseller. This will always return at least one item, though that one
109
item may be an empty contact.
110
111
=cut
112
113
sub get_from_bookseller {
114
    my ($class, $bookseller) = @_;
115
116
    return unless $bookseller;
117
118
    my @contacts;
119
    my $query = "SELECT * FROM aqcontacts WHERE booksellerid = ?";
120
    my $dbh = C4::Context->dbh;
121
    my $sth = $dbh->prepare($query);
122
    $sth->execute($bookseller);
123
    while (my $rec = $sth->fetchrow_hashref()) {
124
        push @contacts, $class->new($rec);
125
    }
126
127
    push @contacts, $class->new() unless @contacts;
128
129
    return \@contacts;
130
}
131
132
133
=head2 fetch
134
135
    my $contact = C4::Bookseller::Contact->fetch($contactid);
136
137
Retrieves the specified contact from the database. Currently commented out
138
because there is no separate table from which contacts can be fetched.
139
140
=cut
141
142
sub fetch {
143
    my ($class, $id) = @_;
144
145
    my $rec = { };
146
    if ($id) {
147
        my $query = "SELECT * FROM aqcontacts WHERE id = ?";
148
        my $dbh = C4::Context->dbh;
149
        my $sth = $dbh->prepare($query);
150
        $sth->execute($id);
151
        $rec = $sth->fetchrow_hashref();
152
    }
153
    my $self = $class->new($rec);
154
    bless $self, $class;
155
    return $self;
156
}
157
158
=head2 save
159
160
    $contact->save();
161
162
Save a contact to the database.
163
164
=cut
165
166
sub save {
167
    my ($self) = @_;
168
169
    my $query;
170
    my @params = (
171
        $self->name,  $self->position,
172
        $self->phone, $self->altphone,
173
        $self->fax,   $self->email,
174
        $self->notes, $self->acqprimary ? 1 : 0,
175
        $self->serialsprimary ? 1 : 0,
176
        $self->orderacquisition ? 1 : 0, $self->claimacquisition ? 1 : 0,
177
        $self->claimissues ? 1 : 0, $self->bookseller
178
    );
179
    if ($self->id) {
180
        $query = 'UPDATE aqcontacts SET name = ?, position = ?, phone = ?, altphone = ?, fax = ?, email = ?, notes = ?, acqprimary = ?, serialsprimary = ?, orderacquisition = ?, claimacquisition = ?, claimissues = ?, booksellerid = ? WHERE id = ?;';
181
        push @params, $self->id;
182
    } else {
183
        $query = 'INSERT INTO aqcontacts (name, position, phone, altphone, fax, email, notes, acqprimary, serialsprimary, orderacquisition, claimacquisition, claimissues, booksellerid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);';
184
    }
185
    my $dbh = C4::Context->dbh;
186
    my $sth = $dbh->prepare($query);
187
    $sth->execute(@params);
188
    $self->id($dbh->{'mysql_insertid'}) unless $self->id;
189
    return $self->id;
190
}
191
192
sub delete {
193
    my ($self) = @_;
194
195
    return unless $self->id;
196
197
    my $dbh = C4::Context->dbh;
198
    my $sth = $dbh->prepare("DELETE FROM aqcontacts WHERE id = ?;");
199
    $sth->execute($self->id);
200
    return;
201
}
202
203
=head1 AUTHOR
204
205
Jared Camins-Esakov <jcamins@cpbibliography.com>
206
207
=cut
208
209
1;
(-)a/Koha/Acquisition/Bookseller.pm (-101 / +12 lines)
Lines 3-122 package Koha::Acquisition::Bookseller; Link Here
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use Koha::Database;
5
use Koha::Database;
6
use Koha::DateUtils qw( dt_from_string output_pref );
6
use base qw( Koha::Object );
7
8
use Carp qw( croak );
9
10
use base qw( Class::Accessor );
11
12
use C4::Bookseller::Contact;
13
14
sub fetch {
15
    my ( $class, $params ) = @_;
16
    my $id = $params->{id};
17
    return unless $id;
18
    my $schema = Koha::Database->new->schema;
19
20
    my $bookseller =
21
      $schema->resultset('Aqbookseller')->find( { id => $id },
22
        { result_class => 'DBIx::Class::ResultClass::HashRefInflator' } );
23
24
    return unless $bookseller;
25
26
    my $self = $class->new( $bookseller );
27
    $self->contacts; # TODO: This should be generated on demand.
28
    return $self;
29
}
30
31
sub search {
32
    my ( $class, $params ) = @_;
33
34
    my $schema = Koha::Database->new->schema;
35
36
    my $search_params;
37
    while ( my ( $field, $value ) = each %$params ) {
38
        if ( $field eq 'name' ) {
39
            # Use "like" if search on name
40
            $search_params->{name} = { -like => "%$value%" };
41
        } else {
42
            $search_params->{$field} = $value;
43
        }
44
    }
45
    my $rs = $schema->resultset('Aqbookseller')->search(
46
        $search_params,
47
        { order_by => 'name' }
48
    );
49
50
    my @booksellers;
51
    while ( my $b = $rs->next ) {
52
        my $t = Koha::Acquisition::Bookseller->fetch({ id => $b->id });
53
        push @booksellers, $t;
54
    }
55
    return @booksellers;
56
}
57
7
58
sub basket_count {
8
use Koha::DateUtils qw( dt_from_string output_pref );
59
    my ( $self ) = @_;
60
    my $schema = Koha::Database->new->schema;
61
9
62
    return $schema->resultset('Aqbasket')->count( { booksellerid => $self->{id} });
10
use Koha::Acquisition::Bookseller::Contacts;
63
}
11
use Koha::Subscriptions;
64
12
65
sub subscription_count {
13
sub baskets {
66
    my ( $self ) = @_;
14
    my ( $self ) = @_;
67
15
    return $self->{_result}->aqbaskets;
68
    my $schema = Koha::Database->new->schema;
69
70
    return $schema->resultset('Subscription')->count( { aqbooksellerid => $self->{id} });
71
}
16
}
72
17
73
sub contacts {
18
sub contacts {
74
    my ( $self ) = @_;
19
    my ($self) = @_;
75
20
    return Koha::Acquisition::Bookseller::Contacts->search( { booksellerid => $self->id } );
76
    return $self->{contacts} if $self->{contacts};
77
    $self->{contacts} = C4::Bookseller::Contact->get_from_bookseller($self->{id});
78
    return $self->{contacts};
79
}
21
}
80
22
81
sub insert {
23
sub subscriptions {
82
    my ($self) = @_;
24
    my ($self) = @_;
83
25
84
    # if these parameters are missing, we can't continue
26
    return Koha::Subscriptions->search( { aqbooksellerid => $self->id } );
85
    for my $key (qw( id )) {
86
        croak "Cannot insert bookseller: Mandatory parameter $key is missing"
87
          unless $self->{$key};
88
    }
89
90
    $self->{quantityreceived} ||= 0;
91
    $self->{entrydate} ||=
92
      output_pref( { dt => dt_from_string, dateformat => 'iso' } );
93
94
    my $schema  = Koha::Database->new->schema;
95
    my @columns = $schema->source('Aqorder')->columns;
96
    my $rs = $schema->resultset('Aqorder')->create(
97
        {
98
            map {
99
                exists $self->{$_} ? ( $_ => $self->{$_} ) : ()
100
            } @columns
101
        }
102
    );
103
    $self->{ordernumber} = $rs->id;
104
105
    unless ( $self->{parent_ordernumber} ) {
106
        $rs->update( { parent_ordernumber => $self->{ordernumber} } );
107
    }
108
109
    return $self;
110
}
111
112
# TODO Move code from ModBookseller
113
sub update {
114
    die "not implemented yet";
115
}
27
}
116
28
117
# TODO Move code from DelBookseller
29
sub _type {
118
sub delete {
30
    return 'Aqbookseller';
119
    die "not implemented yet";
120
}
31
}
121
32
122
1;
33
1;
(-)a/Koha/Acquisition/Bookseller/Contact.pm (+13 lines)
Line 0 Link Here
1
package Koha::Acquisition::Bookseller::Contact;
2
3
use Modern::Perl;
4
5
use base qw( Koha::Object );
6
7
use Carp qw( croak );
8
9
sub _type {
10
    return 'Aqcontact';
11
}
12
13
1;
(-)a/Koha/Acquisition/Bookseller/Contacts.pm (+19 lines)
Line 0 Link Here
1
package Koha::Acquisition::Bookseller::Contacts;
2
3
use Modern::Perl;
4
5
use Carp;
6
7
use base qw( Koha::Objects );
8
9
use Koha::Acquisition::Bookseller::Contact;
10
11
sub _type {
12
    return 'Aqcontact';
13
}
14
15
sub object_class {
16
    return 'Koha::Acquisition::Bookseller::Contact';
17
}
18
19
1;
(-)a/Koha/Acquisition/Booksellers.pm (+37 lines)
Line 0 Link Here
1
package Koha::Acquisition::Booksellers;
2
3
use Modern::Perl;
4
5
use Carp;
6
7
use Koha::Database;
8
9
use base qw( Koha::Objects );
10
11
use Koha::Acquisition::Bookseller;
12
13
sub search {
14
    my ( $self, $params, $attributes ) = @_;
15
16
17
    while ( my ( $field, $value ) = each %$params ) {
18
        if ( $field eq 'name' ) {
19
            # Use "like" if search on name
20
            $params->{name} = { -like => "%$value%" };
21
        }
22
    }
23
24
    $attributes->{order_by} ||= { -asc => 'name' };
25
26
    return $self->SUPER::search( $params, $attributes );
27
}
28
29
sub _type {
30
    return 'Aqbookseller';
31
}
32
33
sub object_class {
34
    return 'Koha::Acquisition::Bookseller';
35
}
36
37
1;
(-)a/Koha/Object.pm (-1 lines)
Lines 221-227 sub _columns { Link Here
221
    return $self->{_columns};
221
    return $self->{_columns};
222
}
222
}
223
223
224
225
=head3 AUTOLOAD
224
=head3 AUTOLOAD
226
225
227
The autoload method is used only to get and set values for an objects properties.
226
The autoload method is used only to get and set values for an objects properties.
(-)a/acqui/addorderiso2709.pl (-6 / +6 lines)
Lines 44-50 use C4::Members; Link Here
44
use Koha::Number::Price;
44
use Koha::Number::Price;
45
use Koha::Acquisition::Currencies;
45
use Koha::Acquisition::Currencies;
46
use Koha::Acquisition::Order;
46
use Koha::Acquisition::Order;
47
use Koha::Acquisition::Bookseller;
47
use Koha::Acquisition::Booksellers;
48
48
49
my $input = new CGI;
49
my $input = new CGI;
50
my ($template, $loggedinuser, $cookie, $userflags) = get_template_and_user({
50
my ($template, $loggedinuser, $cookie, $userflags) = get_template_and_user({
Lines 60-70 my $cgiparams = $input->Vars; Link Here
60
my $op = $cgiparams->{'op'} || '';
60
my $op = $cgiparams->{'op'} || '';
61
my $booksellerid  = $input->param('booksellerid');
61
my $booksellerid  = $input->param('booksellerid');
62
my $allmatch = $input->param('allmatch');
62
my $allmatch = $input->param('allmatch');
63
my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
63
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
64
64
65
$template->param(scriptname => "/cgi-bin/koha/acqui/addorderiso2709.pl",
65
$template->param(scriptname => "/cgi-bin/koha/acqui/addorderiso2709.pl",
66
                booksellerid => $booksellerid,
66
                booksellerid => $booksellerid,
67
                booksellername => $bookseller->{name},
67
                booksellername => $bookseller->name,
68
                );
68
                );
69
69
70
if ($cgiparams->{'import_batch_id'} && $op eq ""){
70
if ($cgiparams->{'import_batch_id'} && $op eq ""){
Lines 218-226 if ($op eq ""){ Link Here
218
            # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation
218
            # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation
219
            $price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR";
219
            $price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR";
220
            $price = Koha::Number::Price->new($price)->unformat;
220
            $price = Koha::Number::Price->new($price)->unformat;
221
            $orderinfo{tax_rate} = $bookseller->{tax_rate};
221
            $orderinfo{tax_rate} = $bookseller->tax_rate;
222
            my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100;
222
            my $c = $c_discount ? $c_discount : $bookseller->discount / 100;
223
            if ( $bookseller->{listincgst} ) {
223
            if ( $bookseller->listincgst ) {
224
                if ( $c_discount ) {
224
                if ( $c_discount ) {
225
                    $orderinfo{ecost} = $price;
225
                    $orderinfo{ecost} = $price;
226
                    $orderinfo{rrp}   = $orderinfo{ecost} / ( 1 - $c );
226
                    $orderinfo{rrp}   = $orderinfo{ecost} / ( 1 - $c );
(-)a/acqui/basket.pl (-8 / +9 lines)
Lines 33-38 use C4::Biblio; Link Here
33
use C4::Members qw/GetMember/;  #needed for permissions checking for changing basketgroup of a basket
33
use C4::Members qw/GetMember/;  #needed for permissions checking for changing basketgroup of a basket
34
use C4::Items;
34
use C4::Items;
35
use C4::Suggestions;
35
use C4::Suggestions;
36
use Koha::Acquisition::Booksellers;
36
use Koha::Libraries;
37
use Koha::Libraries;
37
use C4::Letters qw/SendAlerts/;
38
use C4::Letters qw/SendAlerts/;
38
use Date::Calc qw/Add_Delta_Days/;
39
use Date::Calc qw/Add_Delta_Days/;
Lines 86-92 my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( Link Here
86
87
87
my $basket = GetBasket($basketno);
88
my $basket = GetBasket($basketno);
88
$booksellerid = $basket->{booksellerid} unless $booksellerid;
89
$booksellerid = $basket->{booksellerid} unless $booksellerid;
89
my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
90
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
90
my $schema = Koha::Database->new()->schema();
91
my $schema = Koha::Database->new()->schema();
91
my $rs = $schema->resultset('VendorEdiAccount')->search(
92
my $rs = $schema->resultset('VendorEdiAccount')->search(
92
    { vendor_id => $booksellerid, } );
93
    { vendor_id => $booksellerid, } );
Lines 98-104 unless (CanUserManageBasket($loggedinuser, $basket, $userflags)) { Link Here
98
        basketno => $basketno,
99
        basketno => $basketno,
99
        basketname => $basket->{basketname},
100
        basketname => $basket->{basketname},
100
        booksellerid => $booksellerid,
101
        booksellerid => $booksellerid,
101
        name => $bookseller->{name}
102
        name => $bookseller->name,
102
    );
103
    );
103
    output_html_with_http_headers $query, $cookie, $template->output;
104
    output_html_with_http_headers $query, $cookie, $template->output;
104
    exit;
105
    exit;
Lines 293-299 if ( $op eq 'list' ) { Link Here
293
    my $estimateddeliverydate;
294
    my $estimateddeliverydate;
294
    if( $basket->{closedate} ) {
295
    if( $basket->{closedate} ) {
295
        my ($year, $month, $day) = ($basket->{closedate} =~ /(\d+)-(\d+)-(\d+)/);
296
        my ($year, $month, $day) = ($basket->{closedate} =~ /(\d+)-(\d+)-(\d+)/);
296
        ($year, $month, $day) = Add_Delta_Days($year, $month, $day, $bookseller->{deliverytime});
297
        ($year, $month, $day) = Add_Delta_Days($year, $month, $day, $bookseller->deliverytime);
297
        $estimateddeliverydate = sprintf( "%04d-%02d-%02d", $year, $month, $day );
298
        $estimateddeliverydate = sprintf( "%04d-%02d-%02d", $year, $month, $day );
298
    }
299
    }
299
300
Lines 395-403 if ( $op eq 'list' ) { Link Here
395
        is_standing          => $basket->{is_standing},
396
        is_standing          => $basket->{is_standing},
396
        deliveryplace        => $basket->{deliveryplace},
397
        deliveryplace        => $basket->{deliveryplace},
397
        billingplace         => $basket->{billingplace},
398
        billingplace         => $basket->{billingplace},
398
        active               => $bookseller->{'active'},
399
        active               => $bookseller->active,
399
        booksellerid         => $bookseller->{'id'},
400
        booksellerid         => $bookseller->id,
400
        name                 => $bookseller->{'name'},
401
        name                 => $bookseller->name,
401
        books_loop           => \@books_loop,
402
        books_loop           => \@books_loop,
402
        book_foot_loop       => \@book_foot_loop,
403
        book_foot_loop       => \@book_foot_loop,
403
        cancelledorders_loop => \@cancelledorders_loop,
404
        cancelledorders_loop => \@cancelledorders_loop,
Lines 406-412 if ( $op eq 'list' ) { Link Here
406
        total_tax_included   => $total_tax_included,
407
        total_tax_included   => $total_tax_included,
407
        total_tax_value      => $total_tax_value,
408
        total_tax_value      => $total_tax_value,
408
        currency             => $active_currency->currency,
409
        currency             => $active_currency->currency,
409
        listincgst           => $bookseller->{listincgst},
410
        listincgst           => $bookseller->listincgst,
410
        basketgroups         => $basketgroups,
411
        basketgroups         => $basketgroups,
411
        basketgroup          => $basketgroup,
412
        basketgroup          => $basketgroup,
412
        grouped              => $basket->{basketgroupid},
413
        grouped              => $basket->{basketgroupid},
Lines 491-497 sub get_order_infos { Link Here
491
    foreach my $key (qw(transferred_from transferred_to)) {
492
    foreach my $key (qw(transferred_from transferred_to)) {
492
        if ($line{$key}) {
493
        if ($line{$key}) {
493
            my $order = GetOrder($line{$key});
494
            my $order = GetOrder($line{$key});
494
            my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} });
495
            my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
495
            $line{$key} = {
496
            $line{$key} = {
496
                order => $order,
497
                order => $order,
497
                basket => $basket,
498
                basket => $basket,
(-)a/acqui/basketgroup.pl (-8 / +8 lines)
Lines 55-61 use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsBy Link Here
55
use C4::Members qw/GetMember/;
55
use C4::Members qw/GetMember/;
56
use Koha::EDI qw/create_edi_order get_edifact_ean/;
56
use Koha::EDI qw/create_edi_order get_edifact_ean/;
57
57
58
use Koha::Acquisition::Bookseller;
58
use Koha::Acquisition::Booksellers;
59
59
60
our $input=new CGI;
60
our $input=new CGI;
61
61
Lines 75-87 sub BasketTotal { Link Here
75
    my @orders = GetOrders($basketno);
75
    my @orders = GetOrders($basketno);
76
    for my $order (@orders){
76
    for my $order (@orders){
77
        # FIXME The following is wrong
77
        # FIXME The following is wrong
78
        if ( $bookseller->{listincgst} ) {
78
        if ( $bookseller->listincgst ) {
79
            $total = $total + ( $order->{ecost_tax_included} * $order->{quantity} );
79
            $total = $total + ( $order->{ecost_tax_included} * $order->{quantity} );
80
        } else {
80
        } else {
81
            $total = $total + ( $order->{ecost_tax_excluded} * $order->{quantity} );
81
            $total = $total + ( $order->{ecost_tax_excluded} * $order->{quantity} );
82
        }
82
        }
83
    }
83
    }
84
    $total .= " " . ($bookseller->{invoiceprice} // 0);
84
    $total .= " " . ($bookseller->invoiceprice // 0);
85
    return $total;
85
    return $total;
86
}
86
}
87
87
Lines 118-124 sub displaybasketgroups { Link Here
118
        }
118
        }
119
    }
119
    }
120
    $template->param(baskets => $baskets);
120
    $template->param(baskets => $baskets);
121
    $template->param( booksellername => $bookseller ->{'name'});
121
    $template->param( booksellername => $bookseller->name);
122
}
122
}
123
123
124
sub printbasketgrouppdf{
124
sub printbasketgrouppdf{
Lines 143-149 sub printbasketgrouppdf{ Link Here
143
    }
143
    }
144
    
144
    
145
    my $basketgroup = GetBasketgroup($basketgroupid);
145
    my $basketgroup = GetBasketgroup($basketgroupid);
146
    my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basketgroup->{booksellerid} });
146
    my $bookseller = Koha::Acquisition::Booksellers->find( $basketgroup->{booksellerid} );
147
    my $baskets = GetBasketsByBasketgroup($basketgroupid);
147
    my $baskets = GetBasketsByBasketgroup($basketgroupid);
148
    
148
    
149
    my %orders;
149
    my %orders;
Lines 206-212 sub printbasketgrouppdf{ Link Here
206
        -type       => 'application/pdf',
206
        -type       => 'application/pdf',
207
        -attachment => ( $basketgroup->{name} || $basketgroupid ) . '.pdf'
207
        -attachment => ( $basketgroup->{name} || $basketgroupid ) . '.pdf'
208
    );
208
    );
209
    my $pdf = printpdf($basketgroup, $bookseller, $baskets, \%orders, $bookseller->{tax_rate} // C4::Context->preference("gist")) || die "pdf generation failed";
209
    my $pdf = printpdf($basketgroup, $bookseller, $baskets, \%orders, $bookseller->tax_rate // C4::Context->preference("gist")) || die "pdf generation failed";
210
    print $pdf;
210
    print $pdf;
211
211
212
}
212
}
Lines 243-249 if ( $op eq "add" ) { Link Here
243
# else, edit (if it is open) or display (if it is close) the basketgroup basketgroupid
243
# else, edit (if it is open) or display (if it is close) the basketgroup basketgroupid
244
# the template will know if basketgroup must be displayed or edited, depending on the value of closed key
244
# the template will know if basketgroup must be displayed or edited, depending on the value of closed key
245
#
245
#
246
    my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
246
    my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
247
    my $basketgroupid = $input->param('basketgroupid');
247
    my $basketgroupid = $input->param('basketgroupid');
248
    my $billingplace;
248
    my $billingplace;
249
    my $deliveryplace;
249
    my $deliveryplace;
Lines 392-398 if ( $op eq "add" ) { Link Here
392
}else{
392
}else{
393
# no param : display the list of all basketgroups for a given vendor
393
# no param : display the list of all basketgroups for a given vendor
394
    my $basketgroups = &GetBasketgroups($booksellerid);
394
    my $basketgroups = &GetBasketgroups($booksellerid);
395
    my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
395
    my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
396
    my $baskets = &GetBasketsByBookseller($booksellerid);
396
    my $baskets = &GetBasketsByBookseller($booksellerid);
397
397
398
    displaybasketgroups($basketgroups, $bookseller, $baskets);
398
    displaybasketgroups($basketgroups, $bookseller, $baskets);
(-)a/acqui/basketheader.pl (-4 / +4 lines)
Lines 54-60 use C4::Output; Link Here
54
use C4::Acquisition qw/GetBasket NewBasket ModBasketHeader/;
54
use C4::Acquisition qw/GetBasket NewBasket ModBasketHeader/;
55
use C4::Contract qw/GetContracts/;
55
use C4::Contract qw/GetContracts/;
56
56
57
use Koha::Acquisition::Bookseller;
57
use Koha::Acquisition::Booksellers;
58
58
59
my $input = new CGI;
59
my $input = new CGI;
60
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
60
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Lines 104-121 if ( $op eq 'add_form' ) { Link Here
104
        });
104
        });
105
        push(@contractloop, @$contracts);
105
        push(@contractloop, @$contracts);
106
    }
106
    }
107
    my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
107
    my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
108
    my $count = scalar @contractloop;
108
    my $count = scalar @contractloop;
109
    if ( $count > 0) {
109
    if ( $count > 0) {
110
        $template->param(contractloop => \@contractloop,
110
        $template->param(contractloop => \@contractloop,
111
                         basketcontractnumber => $basket->{'contractnumber'});
111
                         basketcontractnumber => $basket->{'contractnumber'});
112
    }
112
    }
113
    my @booksellers = Koha::Acquisition::Bookseller->search;
113
    my @booksellers = Koha::Acquisition::Booksellers->search;
114
    $template->param( add_form => 1,
114
    $template->param( add_form => 1,
115
                    basketname => $basket->{'basketname'},
115
                    basketname => $basket->{'basketname'},
116
                    basketnote => $basket->{'note'},
116
                    basketnote => $basket->{'note'},
117
                    basketbooksellernote => $basket->{'booksellernote'},
117
                    basketbooksellernote => $basket->{'booksellernote'},
118
                    booksellername => $bookseller->{'name'},
118
                    booksellername => $bookseller->name,
119
                    booksellerid => $booksellerid,
119
                    booksellerid => $booksellerid,
120
                    basketno => $basketno,
120
                    basketno => $basketno,
121
                    booksellers => \@booksellers,
121
                    booksellers => \@booksellers,
(-)a/acqui/booksellers.pl (-11 / +11 lines)
Lines 63-69 use C4::Acquisition qw/ GetBasketsInfosByBookseller CanUserManageBasket /; Link Here
63
use C4::Members qw/GetMember/;
63
use C4::Members qw/GetMember/;
64
use C4::Context;
64
use C4::Context;
65
65
66
use Koha::Acquisition::Bookseller;
66
use Koha::Acquisition::Booksellers;
67
67
68
my $query = CGI->new;
68
my $query = CGI->new;
69
my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user(
69
my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user(
Lines 83-100 my $allbaskets= $query->param('allbaskets')||0; Link Here
83
my @suppliers;
83
my @suppliers;
84
84
85
if ($booksellerid) {
85
if ($booksellerid) {
86
    push @suppliers, Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
86
    push @suppliers, Koha::Acquisition::Booksellers->find( $booksellerid );
87
} else {
87
} else {
88
    @suppliers = Koha::Acquisition::Bookseller->search({ name => $supplier });
88
    @suppliers = Koha::Acquisition::Booksellers->search({ name => $supplier });
89
}
89
}
90
90
91
my $supplier_count = @suppliers;
91
my $supplier_count = @suppliers;
92
if ( $supplier_count == 1 ) {
92
if ( $supplier_count == 1 ) {
93
    $template->param(
93
    $template->param(
94
        supplier_name => $suppliers[0]->{'name'},
94
        supplier_name => $suppliers[0]->name,
95
        booksellerid  => $suppliers[0]->{'id'},
95
        booksellerid  => $suppliers[0]->id,
96
        basketcount   => $suppliers[0]->{'basketcount'},
96
        basketcount   => $suppliers[0]->baskets->count,
97
        active        => $suppliers[0]->{active},
97
        active        => $suppliers[0]->active,
98
    );
98
    );
99
}
99
}
100
100
Lines 124-130 foreach my $r (@{$budgets}) { Link Here
124
my $loop_suppliers = [];
124
my $loop_suppliers = [];
125
125
126
for my $vendor (@suppliers) {
126
for my $vendor (@suppliers) {
127
    my $baskets = GetBasketsInfosByBookseller( $vendor->{id}, $allbaskets );
127
    my $baskets = GetBasketsInfosByBookseller( $vendor->id, $allbaskets );
128
128
129
    my $loop_basket = [];
129
    my $loop_basket = [];
130
130
Lines 150-158 for my $vendor (@suppliers) { Link Here
150
150
151
    push @{$loop_suppliers},
151
    push @{$loop_suppliers},
152
      { loop_basket => $loop_basket,
152
      { loop_basket => $loop_basket,
153
        booksellerid  => $vendor->{id},
153
        booksellerid  => $vendor->id,
154
        name        => $vendor->{name},
154
        name        => $vendor->name,
155
        active      => $vendor->{active},
155
        active      => $vendor->active,
156
      };
156
      };
157
157
158
}
158
}
(-)a/acqui/finishreceive.pl (-4 / +1 lines)
Lines 28-38 use C4::Output; Link Here
28
use C4::Context;
28
use C4::Context;
29
use C4::Acquisition;
29
use C4::Acquisition;
30
use C4::Biblio;
30
use C4::Biblio;
31
use C4::Bookseller;
32
use C4::Items;
31
use C4::Items;
33
use C4::Search;
32
use C4::Search;
34
33
35
use Koha::Acquisition::Bookseller;
34
use Koha::Acquisition::Booksellers;
36
35
37
use List::MoreUtils qw/any/;
36
use List::MoreUtils qw/any/;
38
37
Lines 84-91 if ($quantityrec > $origquantityrec ) { Link Here
84
    $order->{tax_rate_on_receiving} = $input->param("tax_rate");
83
    $order->{tax_rate_on_receiving} = $input->param("tax_rate");
85
    $order->{unitprice} = $unitprice;
84
    $order->{unitprice} = $unitprice;
86
85
87
    my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
88
89
    $order = C4::Acquisition::populate_order_with_prices(
86
    $order = C4::Acquisition::populate_order_with_prices(
90
        {
87
        {
91
            order => $order,
88
            order => $order,
(-)a/acqui/invoice.pl (-3 / +3 lines)
Lines 35-41 use C4::Output; Link Here
35
use C4::Acquisition;
35
use C4::Acquisition;
36
use C4::Budgets;
36
use C4::Budgets;
37
37
38
use Koha::Acquisition::Bookseller;
38
use Koha::Acquisition::Booksellers;
39
use Koha::Acquisition::Currencies;
39
use Koha::Acquisition::Currencies;
40
use Koha::DateUtils;
40
use Koha::DateUtils;
41
use Koha::Misc::Files;
41
use Koha::Misc::Files;
Lines 112-118 elsif ( $op && $op eq 'delete' ) { Link Here
112
112
113
113
114
my $details = GetInvoiceDetails($invoiceid);
114
my $details = GetInvoiceDetails($invoiceid);
115
my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $details->{booksellerid} });
115
my $bookseller = Koha::Acquisition::Booksellers->find( $details->{booksellerid} );
116
my @orders_loop = ();
116
my @orders_loop = ();
117
my $orders = $details->{'orders'};
117
my $orders = $details->{'orders'};
118
my @foot_loop;
118
my @foot_loop;
Lines 177-183 $template->param( Link Here
177
    total_tax_value  => $total_tax_value,
177
    total_tax_value  => $total_tax_value,
178
    total_tax_excluded_shipment => $total_tax_excluded + $details->{shipmentcost},
178
    total_tax_excluded_shipment => $total_tax_excluded + $details->{shipmentcost},
179
    total_tax_included_shipment => $total_tax_included + $details->{shipmentcost},
179
    total_tax_included_shipment => $total_tax_included + $details->{shipmentcost},
180
    invoiceincgst    => $bookseller->{invoiceincgst},
180
    invoiceincgst    => $bookseller->invoiceincgst,
181
    currency         => Koha::Acquisition::Currencies->get_active,
181
    currency         => Koha::Acquisition::Currencies->get_active,
182
    budgets_loop     => \@budgets_loop,
182
    budgets_loop     => \@budgets_loop,
183
);
183
);
(-)a/acqui/invoices.pl (-1 / +2 lines)
Lines 36-41 use C4::Output; Link Here
36
use C4::Acquisition qw/GetInvoices/;
36
use C4::Acquisition qw/GetInvoices/;
37
use C4::Budgets;
37
use C4::Budgets;
38
use Koha::DateUtils;
38
use Koha::DateUtils;
39
use Koha::Acquisition::Booksellers;
39
40
40
my $input = CGI->new;
41
my $input = CGI->new;
41
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
42
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
Lines 89-95 if ( $op and $op eq 'do_search' ) { Link Here
89
}
90
}
90
91
91
# Build suppliers list
92
# Build suppliers list
92
my @suppliers      = Koha::Acquisition::Bookseller->search;
93
my @suppliers      = Koha::Acquisition::Booksellers->search;
93
my $suppliers_loop = [];
94
my $suppliers_loop = [];
94
my $suppliername;
95
my $suppliername;
95
foreach (@suppliers) {
96
foreach (@suppliers) {
(-)a/acqui/modordernotes.pl (-4 / +4 lines)
Lines 33-39 use C4::Auth; Link Here
33
use C4::Output;
33
use C4::Output;
34
use C4::Acquisition;
34
use C4::Acquisition;
35
35
36
use Koha::Acquisition::Bookseller;
36
use Koha::Acquisition::Booksellers;
37
37
38
my $input = new CGI;
38
my $input = new CGI;
39
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
39
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
Lines 51-57 my $referrer = $input->param('referrer') || $input->referer(); Link Here
51
my $type = $input->param('type');
51
my $type = $input->param('type');
52
my $order = GetOrder($ordernumber);
52
my $order = GetOrder($ordernumber);
53
my $basket = GetBasket($order->{basketno});
53
my $basket = GetBasket($order->{basketno});
54
my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} });
54
my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
55
55
56
56
57
if($op and $op eq 'save') {
57
if($op and $op eq 'save') {
Lines 79-86 if($op) { Link Here
79
$template->param(
79
$template->param(
80
    basketname           => $basket->{'basketname'},
80
    basketname           => $basket->{'basketname'},
81
    basketno             => $order->{basketno},
81
    basketno             => $order->{basketno},
82
    booksellerid         => $bookseller->{'id'},
82
    booksellerid         => $bookseller->id,
83
    booksellername       => $bookseller->{'name'},
83
    booksellername       => $bookseller->name,
84
    ordernumber => $ordernumber,
84
    ordernumber => $ordernumber,
85
    referrer => $referrer,
85
    referrer => $referrer,
86
    type => $type,
86
    type => $type,
(-)a/acqui/neworderbiblio.pl (-6 / +6 lines)
Lines 67-73 use C4::Koha; Link Here
67
use C4::Members qw/ GetMember /;
67
use C4::Members qw/ GetMember /;
68
use C4::Budgets qw/ GetBudgetHierarchy /;
68
use C4::Budgets qw/ GetBudgetHierarchy /;
69
69
70
use Koha::Acquisition::Bookseller;
70
use Koha::Acquisition::Booksellers;
71
use Koha::SearchEngine;
71
use Koha::SearchEngine;
72
use Koha::SearchEngine::Search;
72
use Koha::SearchEngine::Search;
73
use Koha::SearchEngine::QueryBuilder;
73
use Koha::SearchEngine::QueryBuilder;
Lines 83-89 my $results_per_page = $params->{'num'} || 20; Link Here
83
my $booksellerid     = $params->{'booksellerid'};
83
my $booksellerid     = $params->{'booksellerid'};
84
my $basketno         = $params->{'basketno'};
84
my $basketno         = $params->{'basketno'};
85
my $sub              = $params->{'sub'};
85
my $sub              = $params->{'sub'};
86
my $bookseller       = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
86
my $bookseller       = Koha::Acquisition::Booksellers->find( $booksellerid );
87
87
88
# getting the template
88
# getting the template
89
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
89
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Lines 115-122 if (defined $error) { Link Here
115
    $template->param(
115
    $template->param(
116
        query_error => $error,
116
        query_error => $error,
117
        basketno             => $basketno,
117
        basketno             => $basketno,
118
        booksellerid     => $bookseller->{'id'},
118
        booksellerid     => $bookseller->id,
119
        name             => $bookseller->{'name'},
119
        name             => $bookseller->name,
120
    );
120
    );
121
    output_html_with_http_headers $input, $cookie, $template->output;
121
    output_html_with_http_headers $input, $cookie, $template->output;
122
    exit;
122
    exit;
Lines 147-154 foreach my $r (@{$budgets}) { Link Here
147
$template->param(
147
$template->param(
148
    has_budgets          => $has_budgets,
148
    has_budgets          => $has_budgets,
149
    basketno             => $basketno,
149
    basketno             => $basketno,
150
    booksellerid         => $bookseller->{'id'},
150
    booksellerid         => $bookseller->id,
151
    name                 => $bookseller->{'name'},
151
    name                 => $bookseller->name,
152
    resultsloop          => \@results,
152
    resultsloop          => \@results,
153
    total                => $total_hits,
153
    total                => $total_hits,
154
    query                => $query,
154
    query                => $query,
(-)a/acqui/neworderempty.pl (-9 / +9 lines)
Lines 87-93 use C4::Search qw/FindDuplicate/; Link Here
87
#needed for z3950 import:
87
#needed for z3950 import:
88
use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/;
88
use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/;
89
89
90
use Koha::Acquisition::Bookseller;
90
use Koha::Acquisition::Booksellers;
91
use Koha::Acquisition::Currencies;
91
use Koha::Acquisition::Currencies;
92
use Koha::ItemTypes;
92
use Koha::ItemTypes;
93
93
Lines 130-136 if(!$basketno) { Link Here
130
130
131
our $basket = GetBasket($basketno);
131
our $basket = GetBasket($basketno);
132
$booksellerid = $basket->{booksellerid} unless $booksellerid;
132
$booksellerid = $basket->{booksellerid} unless $booksellerid;
133
my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
133
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
134
134
135
my $contract = GetContract({
135
my $contract = GetContract({
136
    contractnumber => $basket->{contractnumber}
136
    contractnumber => $basket->{contractnumber}
Lines 320-339 $template->param( Link Here
320
    firstnamesuggestedby => $suggestion->{firstnamesuggestedby},
320
    firstnamesuggestedby => $suggestion->{firstnamesuggestedby},
321
    biblionumber         => $biblionumber,
321
    biblionumber         => $biblionumber,
322
    uncertainprice       => $data->{'uncertainprice'},
322
    uncertainprice       => $data->{'uncertainprice'},
323
    discount_2dp         => sprintf( "%.2f",  $bookseller->{'discount'} ) ,   # for display
323
    discount_2dp         => sprintf( "%.2f",  $bookseller->discount ) ,   # for display
324
    discount             => $bookseller->{'discount'},
324
    discount             => $bookseller->discount,
325
    orderdiscount_2dp    => sprintf( "%.2f", $data->{'discount'} || 0 ),
325
    orderdiscount_2dp    => sprintf( "%.2f", $data->{'discount'} || 0 ),
326
    orderdiscount        => $data->{'discount'},
326
    orderdiscount        => $data->{'discount'},
327
    order_internalnote   => $data->{'order_internalnote'},
327
    order_internalnote   => $data->{'order_internalnote'},
328
    order_vendornote     => $data->{'order_vendornote'},
328
    order_vendornote     => $data->{'order_vendornote'},
329
    listincgst       => $bookseller->{'listincgst'},
329
    listincgst       => $bookseller->listincgst,
330
    invoiceincgst    => $bookseller->{'invoiceincgst'},
330
    invoiceincgst    => $bookseller->invoiceincgst,
331
    name             => $bookseller->{'name'},
331
    name             => $bookseller->name,
332
    cur_active_sym   => $active_currency->symbol,
332
    cur_active_sym   => $active_currency->symbol,
333
    cur_active       => $active_currency->currency,
333
    cur_active       => $active_currency->currency,
334
    currencies       => \@currencies,
334
    currencies       => \@currencies,
335
    currency         => $data->{currency},
335
    currency         => $data->{currency},
336
    vendor_currency  => $bookseller->{listprice},
336
    vendor_currency  => $bookseller->listprice,
337
    orderexists      => ( $new eq 'yes' ) ? 0 : 1,
337
    orderexists      => ( $new eq 'yes' ) ? 0 : 1,
338
    title            => $data->{'title'},
338
    title            => $data->{'title'},
339
    author           => $data->{'author'},
339
    author           => $data->{'author'},
Lines 348-354 $template->param( Link Here
348
    quantityrec      => $quantity,
348
    quantityrec      => $quantity,
349
    rrp              => $data->{'rrp'},
349
    rrp              => $data->{'rrp'},
350
    gst_values       => \@gst_values,
350
    gst_values       => \@gst_values,
351
    tax_rate         => $data->{tax_rate_on_ordering} ? $data->{tax_rate_on_ordering}+0.0 : $bookseller->{tax_rate} ? $bookseller->{tax_rate}+0.0 : 0,
351
    tax_rate         => $data->{tax_rate_on_ordering} ? $data->{tax_rate_on_ordering}+0.0 : $bookseller->tax_rate ? $bookseller->tax_rate+0.0 : 0,
352
    listprice        => sprintf( "%.2f", $data->{listprice} || $data->{price} || $listprice),
352
    listprice        => sprintf( "%.2f", $data->{listprice} || $data->{price} || $listprice),
353
    total            => sprintf( "%.2f", ($data->{ecost} || 0) * ($data->{'quantity'} || 0) ),
353
    total            => sprintf( "%.2f", ($data->{ecost} || 0) * ($data->{'quantity'} || 0) ),
354
    ecost            => sprintf( "%.2f", $data->{ecost} || 0),
354
    ecost            => sprintf( "%.2f", $data->{ecost} || 0),
(-)a/acqui/newordersubscription.pl (-3 / +3 lines)
Lines 25-31 use C4::Context; Link Here
25
use C4::Output;
25
use C4::Output;
26
use C4::Serials;
26
use C4::Serials;
27
27
28
use Koha::Acquisition::Bookseller;
28
use Koha::Acquisition::Booksellers;
29
29
30
my $query        = new CGI;
30
my $query        = new CGI;
31
my $title        = $query->param('title_filter');
31
my $title        = $query->param('title_filter');
Lines 52-58 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( Link Here
52
52
53
my $basket = GetBasket($basketno);
53
my $basket = GetBasket($basketno);
54
$booksellerid = $basket->{booksellerid} unless $booksellerid;
54
$booksellerid = $basket->{booksellerid} unless $booksellerid;
55
my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
55
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
56
56
57
my @subscriptions;
57
my @subscriptions;
58
if ($searched) {
58
if ($searched) {
Lines 88-93 $template->param( Link Here
88
    booksellerid     => $booksellerid,
88
    booksellerid     => $booksellerid,
89
    basketno         => $basket->{basketno},
89
    basketno         => $basket->{basketno},
90
    basketname       => $basket->{basketname},
90
    basketname       => $basket->{basketname},
91
    booksellername   => $bookseller->{name},
91
    booksellername   => $bookseller->name,
92
);
92
);
93
output_html_with_http_headers $query, $cookie, $template->output;
93
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/acqui/newordersuggestion.pl (-3 / +3 lines)
Lines 97-103 use C4::Output; Link Here
97
use C4::Suggestions;
97
use C4::Suggestions;
98
use C4::Biblio;
98
use C4::Biblio;
99
99
100
use Koha::Acquisition::Bookseller;
100
use Koha::Acquisition::Booksellers;
101
101
102
my $input = new CGI;
102
my $input = new CGI;
103
103
Lines 137-148 my $suggestions_loop = SearchSuggestion( Link Here
137
        STATUS        => 'ACCEPTED'
137
        STATUS        => 'ACCEPTED'
138
    }
138
    }
139
);
139
);
140
my $vendor = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
140
my $vendor = Koha::Acquisition::Booksellers->find( $booksellerid );
141
$template->param(
141
$template->param(
142
    suggestions_loop        => $suggestions_loop,
142
    suggestions_loop        => $suggestions_loop,
143
    basketno                => $basketno,
143
    basketno                => $basketno,
144
    booksellerid              => $booksellerid,
144
    booksellerid              => $booksellerid,
145
    name					=> $vendor->{'name'},
145
    name                    => $vendor->name,
146
    loggedinuser            => $borrowernumber,
146
    loggedinuser            => $borrowernumber,
147
    "op_$op"                => 1,
147
    "op_$op"                => 1,
148
);
148
);
(-)a/acqui/orderreceive.pl (-4 / +4 lines)
Lines 73-79 use C4::Items; Link Here
73
use C4::Biblio;
73
use C4::Biblio;
74
use C4::Suggestions;
74
use C4::Suggestions;
75
75
76
use Koha::Acquisition::Bookseller;
76
use Koha::Acquisition::Booksellers;
77
use Koha::DateUtils qw( dt_from_string );
77
use Koha::DateUtils qw( dt_from_string );
78
78
79
my $input      = new CGI;
79
my $input      = new CGI;
Lines 85-91 my $booksellerid = $invoice->{booksellerid}; Link Here
85
my $freight      = $invoice->{shipmentcost};
85
my $freight      = $invoice->{shipmentcost};
86
my $ordernumber  = $input->param('ordernumber');
86
my $ordernumber  = $input->param('ordernumber');
87
87
88
my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
88
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
89
my $results;
89
my $results;
90
$results = SearchOrders({
90
$results = SearchOrders({
91
    ordernumber => $ordernumber
91
    ordernumber => $ordernumber
Lines 155-161 $order->{quantityreceived} = '' if $order->{quantityreceived} == 0; Link Here
155
155
156
my $unitprice = $order->{unitprice};
156
my $unitprice = $order->{unitprice};
157
my ( $rrp, $ecost );
157
my ( $rrp, $ecost );
158
if ( $bookseller->{invoiceincgst} ) {
158
if ( $bookseller->invoiceincgst ) {
159
    $rrp = $order->{rrp_tax_included};
159
    $rrp = $order->{rrp_tax_included};
160
    $ecost = $order->{ecost_tax_included};
160
    $ecost = $order->{ecost_tax_included};
161
    unless ( $unitprice != 0 and defined $unitprice) {
161
    unless ( $unitprice != 0 and defined $unitprice) {
Lines 198-204 $template->param( Link Here
198
    subscriptionid        => $order->{subscriptionid},
198
    subscriptionid        => $order->{subscriptionid},
199
    booksellerid          => $order->{'booksellerid'},
199
    booksellerid          => $order->{'booksellerid'},
200
    freight               => $freight,
200
    freight               => $freight,
201
    name                  => $bookseller->{'name'},
201
    name                  => $bookseller->name,
202
    title                 => $order->{'title'},
202
    title                 => $order->{'title'},
203
    author                => $order->{'author'},
203
    author                => $order->{'author'},
204
    copyrightdate         => $order->{'copyrightdate'},
204
    copyrightdate         => $order->{'copyrightdate'},
(-)a/acqui/parcel.pl (-6 / +6 lines)
Lines 67-73 use C4::Output; Link Here
67
use C4::Suggestions;
67
use C4::Suggestions;
68
use C4::Reserves qw/GetReservesFromBiblionumber/;
68
use C4::Reserves qw/GetReservesFromBiblionumber/;
69
69
70
use Koha::Acquisition::Bookseller;
70
use Koha::Acquisition::Booksellers;
71
use Koha::DateUtils;
71
use Koha::DateUtils;
72
72
73
use JSON;
73
use JSON;
Lines 110-116 unless( $invoiceid and $invoice->{invoiceid} ) { Link Here
110
}
110
}
111
111
112
my $booksellerid = $invoice->{booksellerid};
112
my $booksellerid = $invoice->{booksellerid};
113
my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
113
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
114
114
115
my @orders        = @{ $invoice->{orders} };
115
my @orders        = @{ $invoice->{orders} };
116
my $countlines    = scalar @orders;
116
my $countlines    = scalar @orders;
Lines 124-130 my $subtotal_for_funds; Link Here
124
for my $order ( @orders ) {
124
for my $order ( @orders ) {
125
    $order->{'unitprice'} += 0;
125
    $order->{'unitprice'} += 0;
126
126
127
    if ( $bookseller->{invoiceincgst} ) {
127
    if ( $bookseller->invoiceincgst ) {
128
        $order->{ecost}     = $order->{ecost_tax_included};
128
        $order->{ecost}     = $order->{ecost_tax_included};
129
        $order->{unitprice} = $order->{unitprice_tax_included};
129
        $order->{unitprice} = $order->{unitprice_tax_included};
130
    }
130
    }
Lines 222-228 unless( defined $invoice->{closedate} ) { Link Here
222
    for (my $i = 0 ; $i < $countpendings ; $i++) {
222
    for (my $i = 0 ; $i < $countpendings ; $i++) {
223
        my $order = $pendingorders->[$i];
223
        my $order = $pendingorders->[$i];
224
224
225
        if ( $bookseller->{invoiceincgst} ) {
225
        if ( $bookseller->invoiceincgst ) {
226
            $order->{ecost} = $order->{ecost_tax_included};
226
            $order->{ecost} = $order->{ecost_tax_included};
227
        } else {
227
        } else {
228
            $order->{ecost} = $order->{ecost_tax_excluded};
228
            $order->{ecost} = $order->{ecost_tax_excluded};
Lines 283-290 $template->param( Link Here
283
    invoice               => $invoice->{invoicenumber},
283
    invoice               => $invoice->{invoicenumber},
284
    invoiceclosedate      => $invoice->{closedate},
284
    invoiceclosedate      => $invoice->{closedate},
285
    datereceived          => dt_from_string,
285
    datereceived          => dt_from_string,
286
    name                  => $bookseller->{'name'},
286
    name                  => $bookseller->name,
287
    booksellerid          => $bookseller->{id},
287
    booksellerid          => $bookseller->id,
288
    loop_received         => \@loop_received,
288
    loop_received         => \@loop_received,
289
    loop_orders           => \@loop_orders,
289
    loop_orders           => \@loop_orders,
290
    book_foot_loop        => \@book_foot_loop,
290
    book_foot_loop        => \@book_foot_loop,
(-)a/acqui/parcels.pl (-3 / +3 lines)
Lines 75-81 use C4::Output; Link Here
75
use C4::Acquisition;
75
use C4::Acquisition;
76
use C4::Budgets;
76
use C4::Budgets;
77
77
78
use Koha::Acquisition::Bookseller;
78
use Koha::Acquisition::Booksellers;
79
use Koha::DateUtils qw( output_pref dt_from_string );
79
use Koha::DateUtils qw( output_pref dt_from_string );
80
80
81
my $input          = CGI->new;
81
my $input          = CGI->new;
Lines 139-145 if ($op and $op eq 'confirm') { Link Here
139
    }
139
    }
140
}
140
}
141
141
142
my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
142
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
143
my @parcels = GetInvoices(
143
my @parcels = GetInvoices(
144
    supplierid => $booksellerid,
144
    supplierid => $booksellerid,
145
    invoicenumber => $code,
145
    invoicenumber => $code,
Lines 203-209 $template->param( Link Here
203
    datefrom                 => $datefrom,
203
    datefrom                 => $datefrom,
204
    dateto                   => $dateto,
204
    dateto                   => $dateto,
205
    resultsperpage           => $resultsperpage,
205
    resultsperpage           => $resultsperpage,
206
    name                     => $bookseller->{'name'},
206
    name                     => $bookseller->name,
207
    shipmentdate_today       => dt_from_string,
207
    shipmentdate_today       => dt_from_string,
208
    booksellerid             => $booksellerid,
208
    booksellerid             => $booksellerid,
209
    GST                      => C4::Context->preference('gist'),
209
    GST                      => C4::Context->preference('gist'),
(-)a/acqui/pdfformat/layout2pages.pm (-6 / +6 lines)
Lines 199-215 sub printhead { Link Here
199
    
199
    
200
    # print bookseller infos
200
    # print bookseller infos
201
    $text->translate(100/mm, ($height-180)/mm);
201
    $text->translate(100/mm, ($height-180)/mm);
202
    $text->text($bookseller->{name});
202
    $text->text($bookseller->name);
203
    $text->translate(100/mm, ($height-185)/mm);
203
    $text->translate(100/mm, ($height-185)/mm);
204
    $text->text($bookseller->{postal});
204
    $text->text($bookseller->postal);
205
    $text->translate(100/mm, ($height-190)/mm);
205
    $text->translate(100/mm, ($height-190)/mm);
206
    $text->text($bookseller->{address1});
206
    $text->text($bookseller->address1);
207
    $text->translate(100/mm, ($height-195)/mm);
207
    $text->translate(100/mm, ($height-195)/mm);
208
    $text->text($bookseller->{address2});
208
    $text->text($bookseller->address2);
209
    $text->translate(100/mm, ($height-200)/mm);
209
    $text->translate(100/mm, ($height-200)/mm);
210
    $text->text($bookseller->{address3});
210
    $text->text($bookseller->address3);
211
    $text->translate(100/mm, ($height-205)/mm);
211
    $text->translate(100/mm, ($height-205)/mm);
212
    $text->text($bookseller->{accountnumber});
212
    $text->text($bookseller->accountnumber);
213
    
213
    
214
    # print delivery infos
214
    # print delivery infos
215
    $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm );
215
    $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm );
(-)a/acqui/pdfformat/layout2pagesde.pm (-6 / +6 lines)
Lines 199-215 sub printhead { Link Here
199
    
199
    
200
    # print bookseller infos
200
    # print bookseller infos
201
    $text->translate(100/mm, ($height-180)/mm);
201
    $text->translate(100/mm, ($height-180)/mm);
202
    $text->text($bookseller->{name});
202
    $text->text($bookseller->name);
203
    $text->translate(100/mm, ($height-185)/mm);
203
    $text->translate(100/mm, ($height-185)/mm);
204
    $text->text($bookseller->{postal});
204
    $text->text($bookseller->postal);
205
    $text->translate(100/mm, ($height-190)/mm);
205
    $text->translate(100/mm, ($height-190)/mm);
206
    $text->text($bookseller->{address1});
206
    $text->text($bookseller->address1);
207
    $text->translate(100/mm, ($height-195)/mm);
207
    $text->translate(100/mm, ($height-195)/mm);
208
    $text->text($bookseller->{address2});
208
    $text->text($bookseller->address2);
209
    $text->translate(100/mm, ($height-200)/mm);
209
    $text->translate(100/mm, ($height-200)/mm);
210
    $text->text($bookseller->{address3});
210
    $text->text($bookseller->address3);
211
    $text->translate(100/mm, ($height-205)/mm);
211
    $text->translate(100/mm, ($height-205)/mm);
212
    $text->text($bookseller->{accountnumber});
212
    $text->text($bookseller->accountnumber);
213
    
213
    
214
    # print delivery infos
214
    # print delivery infos
215
    $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm );
215
    $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm );
(-)a/acqui/pdfformat/layout3pages.pm (-6 / +6 lines)
Lines 365-381 sub printhead { Link Here
365
    
365
    
366
    # print bookseller infos
366
    # print bookseller infos
367
    $text->translate(100/mm,  ($height-180)/mm);
367
    $text->translate(100/mm,  ($height-180)/mm);
368
    $text->text($bookseller->{name});
368
    $text->text($bookseller->name);
369
    $text->translate(100/mm,  ($height-185)/mm);
369
    $text->translate(100/mm,  ($height-185)/mm);
370
    $text->text($bookseller->{postal});
370
    $text->text($bookseller->postal);
371
    $text->translate(100/mm,  ($height-190)/mm);
371
    $text->translate(100/mm,  ($height-190)/mm);
372
    $text->text($bookseller->{address1});
372
    $text->text($bookseller->address1);
373
    $text->translate(100/mm,  ($height-195)/mm);
373
    $text->translate(100/mm,  ($height-195)/mm);
374
    $text->text($bookseller->{address2});
374
    $text->text($bookseller->address2);
375
    $text->translate(100/mm,  ($height-200)/mm);
375
    $text->translate(100/mm,  ($height-200)/mm);
376
    $text->text($bookseller->{address3});
376
    $text->text($bookseller->address3);
377
    $text->translate(100/mm, ($height-205)/mm);
377
    $text->translate(100/mm, ($height-205)/mm);
378
    $text->text($bookseller->{accountnumber});
378
    $text->text($bookseller->accountnumber);
379
    
379
    
380
    # print delivery infos
380
    # print delivery infos
381
    $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm );
381
    $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm );
(-)a/acqui/pdfformat/layout3pagesfr.pm (-6 / +6 lines)
Lines 365-381 sub printhead { Link Here
365
365
366
    # print bookseller infos
366
    # print bookseller infos
367
    $text->translate(100/mm,  ($height-180)/mm);
367
    $text->translate(100/mm,  ($height-180)/mm);
368
    $text->text($bookseller->{name});
368
    $text->text($bookseller->name);
369
    $text->translate(100/mm,  ($height-185)/mm);
369
    $text->translate(100/mm,  ($height-185)/mm);
370
    $text->text($bookseller->{postal});
370
    $text->text($bookseller->postal);
371
    $text->translate(100/mm,  ($height-190)/mm);
371
    $text->translate(100/mm,  ($height-190)/mm);
372
    $text->text($bookseller->{address1});
372
    $text->text($bookseller->address1);
373
    $text->translate(100/mm,  ($height-195)/mm);
373
    $text->translate(100/mm,  ($height-195)/mm);
374
    $text->text($bookseller->{address2});
374
    $text->text($bookseller->address2);
375
    $text->translate(100/mm,  ($height-200)/mm);
375
    $text->translate(100/mm,  ($height-200)/mm);
376
    $text->text($bookseller->{address3});
376
    $text->text($bookseller->address3);
377
    $text->translate(100/mm, ($height-205)/mm);
377
    $text->translate(100/mm, ($height-205)/mm);
378
    $text->text($bookseller->{accountnumber});
378
    $text->text($bookseller->accountnumber);
379
379
380
    # print delivery infos
380
    # print delivery infos
381
    $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm );
381
    $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm );
(-)a/acqui/supplier.pl (-18 / +20 lines)
Lines 48-58 use C4::Biblio; Link Here
48
use C4::Output;
48
use C4::Output;
49
use CGI qw ( -utf8 );
49
use CGI qw ( -utf8 );
50
50
51
use C4::Bookseller qw( DelBookseller );
52
use C4::Bookseller::Contact;
53
use C4::Budgets;
51
use C4::Budgets;
54
52
55
use Koha::Acquisition::Bookseller;
53
use Koha::Acquisition::Bookseller::Contacts;
54
use Koha::Acquisition::Booksellers;
56
use Koha::Acquisition::Currencies;
55
use Koha::Acquisition::Currencies;
57
56
58
my $query    = CGI->new;
57
my $query    = CGI->new;
Lines 67-99 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
67
    }
66
    }
68
);
67
);
69
my $booksellerid       = $query->param('booksellerid');
68
my $booksellerid       = $query->param('booksellerid');
70
my $supplier = {};
69
my $supplier;
71
if ($booksellerid) {
70
if ($booksellerid) {
72
    $supplier = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
71
    $supplier = Koha::Acquisition::Booksellers->find( $booksellerid );
73
    foreach ( keys %{$supplier} ) {
72
    my $supplier_hashref = $supplier->unblessed;
74
        $template->{'VARS'}->{$_} = $supplier->{$_};
73
    foreach ( keys %{$supplier_hashref} ) {
74
        $template->{'VARS'}->{$_} = $supplier->$_;
75
    }
75
    }
76
    $template->{VARS}->{contacts} = $supplier->contacts if $supplier->contacts->count;
76
    $template->{'VARS'}->{'booksellerid'} = $booksellerid;
77
    $template->{'VARS'}->{'booksellerid'} = $booksellerid;
77
}
78
}
78
$template->{'VARS'}->{'contacts'} = C4::Bookseller::Contact->new() unless $template->{'VARS'}->{'contacts'};
79
80
$template->{VARS}->{contacts} ||= Koha::Acquisition::Bookseller::Contact->new;
79
81
80
if ( $op eq 'display' ) {
82
if ( $op eq 'display' ) {
81
    my $contracts = GetContracts( { booksellerid => $booksellerid } );
83
    my $contracts = GetContracts( { booksellerid => $booksellerid } );
82
84
83
    $template->param(
85
    $template->param(
84
        active        => $supplier->{'active'},
86
        active        => $supplier->active,
85
        tax_rate       => $supplier->{'tax_rate'} + 0.0,
87
        tax_rate      => $supplier->tax_rate + 0.0,
86
        invoiceprice  => $supplier->{'invoiceprice'},
88
        invoiceprice  => $supplier->invoiceprice,
87
        listprice     => $supplier->{'listprice'},
89
        listprice     => $supplier->listprice,
88
        basketcount   => $supplier->{'basketcount'},
90
        basketcount   => $supplier->baskets->count,
89
        subscriptioncount   => $supplier->{'subscriptioncount'},
91
        subscriptioncount => $supplier->subscriptions->count,
90
        contracts     => $contracts,
92
        contracts     => $contracts,
91
    );
93
    );
92
} elsif ( $op eq 'delete' ) {
94
} elsif ( $op eq 'delete' ) {
93
    # no further message needed for the user
95
    # no further message needed for the user
94
    # the DELETE button only appears in the template if basketcount == 0
96
    # the DELETE button only appears in the template if basketcount == 0
95
    if ( $supplier->{'basketcount'} == 0 ) {
97
    if ( $supplier->baskets->count == 0 ) {
96
        DelBookseller($booksellerid);
98
        Koha::Acquisition::Booksellers->find($booksellerid)->delete;
97
    }
99
    }
98
    print $query->redirect('/cgi-bin/koha/acqui/acqui-home.pl');
100
    print $query->redirect('/cgi-bin/koha/acqui/acqui-home.pl');
99
    exit;
101
    exit;
Lines 107-114 if ( $op eq 'display' ) { Link Here
107
109
108
    $template->param(
110
    $template->param(
109
        # set active ON by default for supplier add (id empty for add)
111
        # set active ON by default for supplier add (id empty for add)
110
        active       => $booksellerid ? $supplier->{'active'} : 1,
112
        active     => $supplier ? $supplier->active         : 1,
111
        tax_rate       => $supplier->{tax_rate} ? $supplier->{'tax_rate'}+0.0 : 0,
113
        tax_rate   => $supplier ? $supplier->tax_rate + 0.0 : 0,
112
        gst_values    => \@gst_values,
114
        gst_values    => \@gst_values,
113
        currencies    => \@currencies,
115
        currencies    => \@currencies,
114
        enter         => 1,
116
        enter         => 1,
(-)a/acqui/transferorder.pl (-9 / +10 lines)
Lines 27-32 use C4::Output; Link Here
27
use C4::Context;
27
use C4::Context;
28
use C4::Acquisition;
28
use C4::Acquisition;
29
use C4::Members;
29
use C4::Members;
30
use Koha::Acquisition::Booksellers;
30
31
31
my $input = new CGI;
32
my $input = new CGI;
32
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
33
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Lines 54-68 if($order) { Link Here
54
    $bookselleridfrom = $basket->{booksellerid} if $basket;
55
    $bookselleridfrom = $basket->{booksellerid} if $basket;
55
}
56
}
56
57
57
my $booksellerfrom = Koha::Acquisition::Bookseller->fetch({ id => $bookselleridfrom });
58
my $booksellerfrom = Koha::Acquisition::Booksellers->find( $bookselleridfrom );
58
my $booksellerfromname;
59
my $booksellerfromname;
59
if($booksellerfrom){
60
if($booksellerfrom){
60
    $booksellerfromname = $booksellerfrom->{name};
61
    $booksellerfromname = $booksellerfrom->name;
61
}
62
}
62
my $booksellerto = Koha::Acquisition::Bookseller->fetch({ id => $bookselleridto });
63
my $booksellerto = Koha::Acquisition::Booksellers->finf( $bookselleridto );
63
my $booksellertoname;
64
my $booksellertoname;
64
if($booksellerto){
65
if($booksellerto){
65
    $booksellertoname = $booksellerto->{name};
66
    $booksellertoname = $booksellerto->name;
66
}
67
}
67
68
68
69
Lines 70-77 if( $basketno && $ordernumber) { Link Here
70
    # Transfer order and exit
71
    # Transfer order and exit
71
    my $order = GetOrder( $ordernumber );
72
    my $order = GetOrder( $ordernumber );
72
    my $basket = GetBasket($order->{basketno});
73
    my $basket = GetBasket($order->{basketno});
73
    my $booksellerfrom = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} });
74
    my $booksellerfrom = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
74
    my $bookselleridfrom = $booksellerfrom->{id};
75
    my $bookselleridfrom = $booksellerfrom->id;
75
76
76
    TransferOrder($ordernumber, $basketno);
77
    TransferOrder($ordernumber, $basketno);
77
78
Lines 80-87 if( $basketno && $ordernumber) { Link Here
80
    # Show open baskets for this bookseller
81
    # Show open baskets for this bookseller
81
    my $order = GetOrder( $ordernumber );
82
    my $order = GetOrder( $ordernumber );
82
    my $basketfrom = GetBasket( $order->{basketno} );
83
    my $basketfrom = GetBasket( $order->{basketno} );
83
    my $booksellerfrom = Koha::Acquisition::Bookseller->fetch({ id => $basketfrom->{booksellerid} });
84
    my $booksellerfrom = Koha::Acquisition::Booksellers->find( $basketfrom->{booksellerid} );
84
    $booksellerfromname = $booksellerfrom->{name};
85
    $booksellerfromname = $booksellerfrom->name;
85
    my $baskets = GetBasketsByBookseller( $bookselleridto );
86
    my $baskets = GetBasketsByBookseller( $bookselleridto );
86
    my $basketscount = scalar @$baskets;
87
    my $basketscount = scalar @$baskets;
87
    my @basketsloop = ();
88
    my @basketsloop = ();
Lines 117-123 if( $basketno && $ordernumber) { Link Here
117
    # Search for booksellers to transfer from/to
118
    # Search for booksellers to transfer from/to
118
    $op = '' unless $op;
119
    $op = '' unless $op;
119
    if( $op eq "do_search" ) {
120
    if( $op eq "do_search" ) {
120
        my @booksellers = Koha::Acquisition::Bookseller->search({ name => $query });
121
        my @booksellers = Koha::Acquisition::Booksellers->search({ name => $query });
121
        $template->param(
122
        $template->param(
122
            query => $query,
123
            query => $query,
123
            do_search => 1,
124
            do_search => 1,
(-)a/acqui/uncertainprice.pl (-19 / +18 lines)
Lines 50-60 use C4::Auth; Link Here
50
use C4::Output;
50
use C4::Output;
51
use CGI qw ( -utf8 );
51
use CGI qw ( -utf8 );
52
52
53
use C4::Bookseller::Contact;
54
use C4::Acquisition qw/SearchOrders GetOrder ModOrder/;
53
use C4::Acquisition qw/SearchOrders GetOrder ModOrder/;
55
use C4::Biblio qw/GetBiblioData/;
54
use C4::Biblio qw/GetBiblioData/;
56
55
57
use Koha::Acquisition::Bookseller;
56
use Koha::Acquisition::Booksellers;
58
57
59
my $input=new CGI;
58
my $input=new CGI;
60
59
Lines 71-77 my $booksellerid = $input->param('booksellerid'); Link Here
71
my $basketno     = $input->param('basketno');
70
my $basketno     = $input->param('basketno');
72
my $op = $input->param('op');
71
my $op = $input->param('op');
73
my $owner = $input->param('owner') || 0 ; # flag to see only "my" orders, or everyone orders
72
my $owner = $input->param('owner') || 0 ; # flag to see only "my" orders, or everyone orders
74
my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
73
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
75
74
76
#show all orders that have uncertain price for the bookseller
75
#show all orders that have uncertain price for the bookseller
77
my $pendingorders = SearchOrders({
76
my $pendingorders = SearchOrders({
Lines 106-112 if ( $op eq 'validate' ) { Link Here
106
        my $ordernumber = $order->{ordernumber};
105
        my $ordernumber = $order->{ordernumber};
107
        my $order_as_from_db=GetOrder($order->{ordernumber});
106
        my $order_as_from_db=GetOrder($order->{ordernumber});
108
        $order->{'listprice'} = $input->param('price'.$ordernumber);
107
        $order->{'listprice'} = $input->param('price'.$ordernumber);
109
        $order->{'ecost'}= $input->param('price'.$ordernumber) - (($input->param('price'.$ordernumber) /100) * $bookseller->{'discount'});
108
        $order->{'ecost'}= $input->param('price'.$ordernumber) - (($input->param('price'.$ordernumber) /100) * $bookseller->discount);
110
        $order->{'rrp'} = $input->param('price'.$ordernumber);
109
        $order->{'rrp'} = $input->param('price'.$ordernumber);
111
        $order->{'quantity'}=$input->param('qty'.$ordernumber);
110
        $order->{'quantity'}=$input->param('qty'.$ordernumber);
112
        $order->{'uncertainprice'}=$input->param('uncertainprice'.$ordernumber);
111
        $order->{'uncertainprice'}=$input->param('uncertainprice'.$ordernumber);
Lines 115-135 if ( $op eq 'validate' ) { Link Here
115
}
114
}
116
115
117
$template->param( uncertainpriceorders => \@orders,
116
$template->param( uncertainpriceorders => \@orders,
118
                                   booksellername => "".$bookseller->{'name'},
117
                                   booksellername => "".$bookseller->name,
119
                                   booksellerid => $bookseller->{'id'},
118
                                   booksellerid => $bookseller->id,
120
                                   booksellerpostal =>$bookseller->{'postal'},
119
                                   booksellerpostal =>$bookseller->postal,
121
                                   bookselleraddress1 => $bookseller->{'address1'},
120
                                   bookselleraddress1 => $bookseller->address1,
122
                                   bookselleraddress2 => $bookseller->{'address2'},
121
                                   bookselleraddress2 => $bookseller->address2,
123
                                   bookselleraddress3 => $bookseller->{'address3'},
122
                                   bookselleraddress3 => $bookseller->address3,
124
                                   bookselleraddress4 => $bookseller->{'address4'},
123
                                   bookselleraddress4 => $bookseller->address4,
125
                                   booksellerphone =>$bookseller->{'phone'},
124
                                   booksellerphone =>$bookseller->phone,
126
                                   booksellerfax => $bookseller->{'fax'},
125
                                   booksellerfax => $bookseller->fax,
127
                                   booksellerurl => $bookseller->{'url'},
126
                                   booksellerurl => $bookseller->url,
128
                                   booksellernotes => $bookseller->{'notes'},
127
                                   booksellernotes => $bookseller->notes,
129
                                   basketcount   => $bookseller->{'basketcount'},
128
                                   basketcount   => $bookseller->baskets->count,
130
                                   subscriptioncount   => $bookseller->{'subscriptioncount'},
129
                                   subscriptioncount   => $bookseller->subscriptions->count,
131
                                   active => $bookseller->{active},
130
                                   active => $bookseller->active,
132
                                   owner => $owner,
131
                                   owner => $owner,
133
                                   scriptname => "/cgi-bin/koha/acqui/uncertainprice.pl");
132
                                   scriptname => "/cgi-bin/koha/acqui/uncertainprice.pl");
134
$template->{'VARS'}->{'contacts'} = $bookseller->{'contacts'};
133
$template->{'VARS'}->{'contacts'} = $bookseller->contacts;
135
output_html_with_http_headers $input, $cookie, $template->output;
134
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/acqui/updatesupplier.pl (-8 / +21 lines)
Lines 52-61 use List::Util; Link Here
52
use C4::Context;
52
use C4::Context;
53
use C4::Auth;
53
use C4::Auth;
54
54
55
use C4::Bookseller qw( ModBookseller AddBookseller );
56
use C4::Bookseller::Contact;
57
use C4::Biblio;
55
use C4::Biblio;
58
use C4::Output;
56
use C4::Output;
57
58
use Koha::Acquisition::Bookseller::Contacts;
59
use Koha::Acquisition::Booksellers;
59
use CGI qw ( -utf8 );
60
use CGI qw ( -utf8 );
60
61
61
my $input=new CGI;
62
my $input=new CGI;
Lines 108-122 for my $cnt (0..scalar(@{$contact_info{'id'}})) { Link Here
108
        $contact{$_} = $contact_info{$_}->[$cnt];
109
        $contact{$_} = $contact_info{$_}->[$cnt];
109
        $real_contact = 1 if $contact{$_};
110
        $real_contact = 1 if $contact{$_};
110
    }
111
    }
111
    push @contacts, C4::Bookseller::Contact->new(\%contact) if $real_contact;
112
    push @contacts, \%contact if $real_contact;
112
}
113
}
113
114
114
if($data{'name'}) {
115
if($data{'name'}) {
115
	if ($data{'id'}){
116
    if ( $data{id} ) {
116
        ModBookseller(\%data, \@contacts);
117
        # Update
117
	} else {
118
        my $bookseller = Koha::Acquisition::Booksellers->find( $data{id} )->set(\%data)->store;
118
        $data{id}=AddBookseller(\%data, \@contacts);
119
        # Delete existing contacts
119
	}
120
        $bookseller->contacts->delete;
121
    } else {
122
        # Insert
123
        delete $data{id}; # Remove the key if exists
124
        my $bookseller = Koha::Acquisition::Bookseller->new( \%data )->store;
125
        $data{id} = $bookseller->id;
126
    }
127
    # Insert contacts
128
    for my $contact ( @contacts ) {
129
        $contact->{booksellerid} = $data{id};
130
        Koha::Acquisition::Bookseller::Contact->new( $contact )->store
131
    }
132
120
    #redirect to booksellers.pl
133
    #redirect to booksellers.pl
121
    print $input->redirect("booksellers.pl?booksellerid=".$data{id});
134
    print $input->redirect("booksellers.pl?booksellerid=".$data{id});
122
} else {
135
} else {
(-)a/acqui/z3950_search.pl (-3 / +3 lines)
Lines 29-35 use C4::Context; Link Here
29
use C4::Breeding;
29
use C4::Breeding;
30
use C4::Koha;
30
use C4::Koha;
31
31
32
use Koha::Acquisition::Bookseller;
32
use Koha::Acquisition::Booksellers;
33
use Koha::BiblioFrameworks;
33
use Koha::BiblioFrameworks;
34
34
35
my $input           = new CGI;
35
my $input           = new CGI;
Lines 52-58 $page = $input->param('goto_page') if $input->param('changepage_go Link Here
52
# get framework list
52
# get framework list
53
my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
53
my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
54
54
55
my $vendor = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
55
my $vendor = Koha::Acquisition::Booksellers->find( $booksellerid );
56
56
57
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
57
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
58
    {
58
    {
Lines 66-72 $template->param( Link Here
66
        frameworks   => $frameworks,
66
        frameworks   => $frameworks,
67
        booksellerid => $booksellerid,
67
        booksellerid => $booksellerid,
68
        basketno     => $basketno,
68
        basketno     => $basketno,
69
        name         => $vendor->{'name'},
69
        name         => $vendor->name,
70
        isbn         => $isbn,
70
        isbn         => $isbn,
71
        issn         => $issn,
71
        issn         => $issn,
72
        lccn         => $lccn,
72
        lccn         => $lccn,
(-)a/admin/aqcontract.pl (-6 / +6 lines)
Lines 29-42 use C4::Output; Link Here
29
use C4::Contract;
29
use C4::Contract;
30
use Koha::DateUtils;
30
use Koha::DateUtils;
31
31
32
use Koha::Acquisition::Bookseller;
32
use Koha::Acquisition::Booksellers;
33
33
34
my $input          = new CGI;
34
my $input          = new CGI;
35
my $contractnumber = $input->param('contractnumber');
35
my $contractnumber = $input->param('contractnumber');
36
my $booksellerid   = $input->param('booksellerid');
36
my $booksellerid   = $input->param('booksellerid');
37
my $op             = $input->param('op') || 'list';
37
my $op             = $input->param('op') || 'list';
38
38
39
my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
39
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
40
40
41
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
41
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
42
    {   template_name   => "admin/aqcontract.tt",
42
    {   template_name   => "admin/aqcontract.tt",
Lines 51-60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
51
$template->param(
51
$template->param(
52
    contractnumber => $contractnumber,
52
    contractnumber => $contractnumber,
53
    booksellerid   => $booksellerid,
53
    booksellerid   => $booksellerid,
54
    booksellername => $bookseller->{name},
54
    booksellername => $bookseller->name,
55
    basketcount   => $bookseller->{'basketcount'},
55
    basketcount   => $bookseller->baskets->count,
56
    active         => $bookseller->{active},
56
    active         => $bookseller->active,
57
    subscriptioncount   => $bookseller->{'subscriptioncount'},
57
    subscriptioncount   => $bookseller->subscriptions->count,
58
);
58
);
59
59
60
#ADD_FORM: called if $op is 'add_form'. Used to create form to add or  modify a record
60
#ADD_FORM: called if $op is 'add_form'. Used to create form to add or  modify a record
(-)a/admin/currency.pl (-2 / +2 lines)
Lines 25-31 use C4::Auth; Link Here
25
use C4::Context;
25
use C4::Context;
26
use C4::Output;
26
use C4::Output;
27
27
28
use Koha::Acquisition::Bookseller;
28
use Koha::Acquisition::Booksellers;
29
use Koha::Acquisition::Currency;
29
use Koha::Acquisition::Currency;
30
use Koha::Acquisition::Currencies;
30
use Koha::Acquisition::Currencies;
31
31
Lines 95-101 if ( $op eq 'add_form' ) { Link Here
95
    # TODO rewrite the following when Koha::Acquisition::Orders will use Koha::Objects
95
    # TODO rewrite the following when Koha::Acquisition::Orders will use Koha::Objects
96
    my $schema = Koha::Database->schema;
96
    my $schema = Koha::Database->schema;
97
    my $nb_of_orders = $schema->resultset('Aqorder')->search( { currency => $currency->currency } )->count;
97
    my $nb_of_orders = $schema->resultset('Aqorder')->search( { currency => $currency->currency } )->count;
98
    my $nb_of_vendors = Koha::Acquisition::Bookseller->search( { -or => { listprice => $currency->currency, invoiceprice => $currency->currency } });
98
    my $nb_of_vendors = Koha::Acquisition::Booksellers->search( { -or => { listprice => $currency->currency, invoiceprice => $currency->currency } });
99
    $template->param(
99
    $template->param(
100
        currency     => $currency,
100
        currency     => $currency,
101
        nb_of_orders => $nb_of_orders,
101
        nb_of_orders => $nb_of_orders,
(-)a/catalogue/moredetail.pl (-3 / +3 lines)
Lines 35-41 use C4::Search; # enabled_staff_search_views Link Here
35
use C4::Members qw/GetHideLostItemsPreference/;
35
use C4::Members qw/GetHideLostItemsPreference/;
36
use C4::Reserves qw(GetReservesFromBiblionumber);
36
use C4::Reserves qw(GetReservesFromBiblionumber);
37
37
38
use Koha::Acquisition::Bookseller;
38
use Koha::Acquisition::Booksellers;
39
use Koha::AuthorisedValues;
39
use Koha::AuthorisedValues;
40
use Koha::DateUtils;
40
use Koha::DateUtils;
41
use Koha::Items;
41
use Koha::Items;
Lines 159-166 foreach my $item (@items){ Link Here
159
    $item->{'orderdate'}               = $order->{'entrydate'};
159
    $item->{'orderdate'}               = $order->{'entrydate'};
160
    if ($item->{'basketno'}){
160
    if ($item->{'basketno'}){
161
	    my $basket = GetBasket($item->{'basketno'});
161
	    my $basket = GetBasket($item->{'basketno'});
162
        my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} });
162
        my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
163
	    $item->{'vendor'} = $bookseller->{'name'};
163
        $item->{'vendor'} = $bookseller->name;
164
    }
164
    }
165
    $item->{'invoiceid'}               = $order->{'invoiceid'};
165
    $item->{'invoiceid'}               = $order->{'invoiceid'};
166
    if($item->{invoiceid}) {
166
    if($item->{invoiceid}) {
(-)a/serials/acqui-search-result.pl (-2 / +2 lines)
Lines 49-55 use CGI qw ( -utf8 ); Link Here
49
use C4::Acquisition qw( SearchOrders );
49
use C4::Acquisition qw( SearchOrders );
50
use Koha::DateUtils;
50
use Koha::DateUtils;
51
51
52
use Koha::Acquisition::Bookseller;
52
use Koha::Acquisition::Booksellers;
53
53
54
my $query=new CGI;
54
my $query=new CGI;
55
my ($template, $loggedinuser, $cookie)
55
my ($template, $loggedinuser, $cookie)
Lines 62-68 my ($template, $loggedinuser, $cookie) Link Here
62
                 });
62
                 });
63
63
64
my $supplier=$query->param('supplier');
64
my $supplier=$query->param('supplier');
65
my @suppliers = Koha::Acquisition::Bookseller->search({ name => $supplier });
65
my @suppliers = Koha::Acquisition::Booksellers->search({ name => $supplier });
66
#my $count = scalar @suppliers;
66
#my $count = scalar @suppliers;
67
67
68
#build result page
68
#build result page
(-)a/serials/subscription-detail.pl (-5 / +5 lines)
Lines 122-128 if ( defined $subscriptionid ) { Link Here
122
    my $lastOrderReceived = GetLastOrderReceivedFromSubscriptionid $subscriptionid;
122
    my $lastOrderReceived = GetLastOrderReceivedFromSubscriptionid $subscriptionid;
123
    if ( defined $lastOrderNotReceived ) {
123
    if ( defined $lastOrderNotReceived ) {
124
        my $basket = GetBasket $lastOrderNotReceived->{basketno};
124
        my $basket = GetBasket $lastOrderNotReceived->{basketno};
125
        my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} });
125
        my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
126
        ( $tmpl_infos->{value_tax_included_ordered}, $tmpl_infos->{value_tax_excluded_ordered} ) = get_value_with_gst_params ( $lastOrderNotReceived->{ecost}, $lastOrderNotReceived->{tax_rate}, $bookseller );
126
        ( $tmpl_infos->{value_tax_included_ordered}, $tmpl_infos->{value_tax_excluded_ordered} ) = get_value_with_gst_params ( $lastOrderNotReceived->{ecost}, $lastOrderNotReceived->{tax_rate}, $bookseller );
127
        $tmpl_infos->{value_tax_included_ordered} = sprintf( "%.2f", $tmpl_infos->{value_tax_included_ordered} );
127
        $tmpl_infos->{value_tax_included_ordered} = sprintf( "%.2f", $tmpl_infos->{value_tax_included_ordered} );
128
        $tmpl_infos->{value_tax_excluded_ordered} = sprintf( "%.2f", $tmpl_infos->{value_tax_excluded_ordered} );
128
        $tmpl_infos->{value_tax_excluded_ordered} = sprintf( "%.2f", $tmpl_infos->{value_tax_excluded_ordered} );
Lines 132-138 if ( defined $subscriptionid ) { Link Here
132
    }
132
    }
133
    if ( defined $lastOrderReceived ) {
133
    if ( defined $lastOrderReceived ) {
134
        my $basket = GetBasket $lastOrderReceived->{basketno};
134
        my $basket = GetBasket $lastOrderReceived->{basketno};
135
        my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} });
135
        my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
136
        ( $tmpl_infos->{value_tax_included_spent}, $tmpl_infos->{value_tax_excluded_spent} ) = get_value_with_gst_params ( $lastOrderReceived->{unitprice}, $lastOrderReceived->{tax_rate}, $bookseller );
136
        ( $tmpl_infos->{value_tax_included_spent}, $tmpl_infos->{value_tax_excluded_spent} ) = get_value_with_gst_params ( $lastOrderReceived->{unitprice}, $lastOrderReceived->{tax_rate}, $bookseller );
137
        $tmpl_infos->{value_tax_included_spent} = sprintf( "%.2f", $tmpl_infos->{value_tax_included_spent} );
137
        $tmpl_infos->{value_tax_included_spent} = sprintf( "%.2f", $tmpl_infos->{value_tax_included_spent} );
138
        $tmpl_infos->{value_tax_excluded_spent} = sprintf( "%.2f", $tmpl_infos->{value_tax_excluded_spent} );
138
        $tmpl_infos->{value_tax_excluded_spent} = sprintf( "%.2f", $tmpl_infos->{value_tax_excluded_spent} );
Lines 193-199 sub get_value_with_gst_params { Link Here
193
    my $value = shift;
193
    my $value = shift;
194
    my $tax_rate = shift;
194
    my $tax_rate = shift;
195
    my $bookseller = shift;
195
    my $bookseller = shift;
196
    if ( $bookseller->{listincgst} ) {
196
    if ( $bookseller->listincgst ) {
197
        return ( $value, $value / ( 1 + $tax_rate ) );
197
        return ( $value, $value / ( 1 + $tax_rate ) );
198
    } else {
198
    } else {
199
        return ( $value * ( 1 + $tax_rate ), $value );
199
        return ( $value * ( 1 + $tax_rate ), $value );
Lines 204-210 sub get_tax_excluded { Link Here
204
    my $value = shift;
204
    my $value = shift;
205
    my $tax_rate = shift;
205
    my $tax_rate = shift;
206
    my $bookseller = shift;
206
    my $bookseller = shift;
207
    if ( $bookseller->{invoiceincgst} ) {
207
    if ( $bookseller->invoiceincgst ) {
208
        return $value / ( 1 + $tax_rate );
208
        return $value / ( 1 + $tax_rate );
209
    } else {
209
    } else {
210
        return $value;
210
        return $value;
Lines 215-221 sub get_gst { Link Here
215
    my $value = shift;
215
    my $value = shift;
216
    my $tax_rate = shift;
216
    my $tax_rate = shift;
217
    my $bookseller = shift;
217
    my $bookseller = shift;
218
    if ( $bookseller->{invoiceincgst} ) {
218
    if ( $bookseller->invoiceincgst ) {
219
        return $value / ( 1 + $tax_rate ) * $tax_rate;
219
        return $value / ( 1 + $tax_rate ) * $tax_rate;
220
    } else {
220
    } else {
221
        return $value * ( 1 + $tax_rate ) - $value;
221
        return $value * ( 1 + $tax_rate ) - $value;
(-)a/t/Prices.t (-34 / +16 lines)
Lines 8-21 use Module::Load::Conditional qw/check_install/; Link Here
8
8
9
BEGIN {
9
BEGIN {
10
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
10
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
11
        plan tests => 17;
11
        plan tests => 16;
12
    } else {
12
    } else {
13
        plan skip_all => "Need Test::DBIx::Class"
13
        plan skip_all => "Need Test::DBIx::Class"
14
    }
14
    }
15
}
15
}
16
16
17
use_ok('C4::Acquisition');
17
use_ok('C4::Acquisition');
18
use_ok('C4::Bookseller');
19
use_ok('C4::Context');
18
use_ok('C4::Context');
20
use_ok('Koha::Number::Price');
19
use_ok('Koha::Number::Price');
21
20
Lines 36-41 fixtures_ok [ Link Here
36
        [ qw/ currency symbol rate active / ],
35
        [ qw/ currency symbol rate active / ],
37
        [[ 'my_cur', '€', 1, 1, ]],
36
        [[ 'my_cur', '€', 1, 1, ]],
38
    ],
37
    ],
38
    Aqbookseller => [
39
        [ qw/ id name listincgst invoiceincgst / ],
40
        [ 1, '0 0', 0, 0 ],
41
        [ 2, '0 1', 0, 1 ],
42
        [ 3, '1 0', 1, 0 ],
43
        [ 4, '1 1', 1, 1 ],
44
    ],
39
], 'add currency fixtures';
45
], 'add currency fixtures';
40
46
41
my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller');
47
my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller');
Lines 48-59 for my $currency_format ( qw( US FR ) ) { Link Here
48
    t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
54
    t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
49
    subtest 'Configuration 1: 0 0' => sub {
55
    subtest 'Configuration 1: 0 0' => sub {
50
        plan tests => 8;
56
        plan tests => 8;
51
        $bookseller_module->mock(
52
            'fetch',
53
            sub {
54
                return { listincgst => 0, invoiceincgst => 0 };
55
            }
56
        );
57
57
58
        my $biblionumber_0_0 = 42;
58
        my $biblionumber_0_0 = 42;
59
59
Lines 74-80 for my $currency_format ( qw( US FR ) ) { Link Here
74
        $order_0_0 = C4::Acquisition::populate_order_with_prices(
74
        $order_0_0 = C4::Acquisition::populate_order_with_prices(
75
            {
75
            {
76
                order        => $order_0_0,
76
                order        => $order_0_0,
77
                booksellerid => 'just_something',
77
                booksellerid => 1,
78
                ordering     => 1,
78
                ordering     => 1,
79
            }
79
            }
80
        );
80
        );
Lines 123-129 for my $currency_format ( qw( US FR ) ) { Link Here
123
        $order_0_0 = C4::Acquisition::populate_order_with_prices(
123
        $order_0_0 = C4::Acquisition::populate_order_with_prices(
124
            {
124
            {
125
                order        => $order_0_0,
125
                order        => $order_0_0,
126
                booksellerid => 'just_something',
126
                booksellerid => 1,
127
                receiving    => 1,
127
                receiving    => 1,
128
            }
128
            }
129
        );
129
        );
Lines 156-167 for my $currency_format ( qw( US FR ) ) { Link Here
156
156
157
    subtest 'Configuration 1: 1 1' => sub {
157
    subtest 'Configuration 1: 1 1' => sub {
158
        plan tests => 8;
158
        plan tests => 8;
159
        $bookseller_module->mock(
160
            'fetch',
161
            sub {
162
                return { listincgst => 1, invoiceincgst => 1 };
163
            }
164
        );
165
159
166
        my $biblionumber_1_1 = 43;
160
        my $biblionumber_1_1 = 43;
167
        my $order_1_1        = {
161
        my $order_1_1        = {
Lines 182-188 for my $currency_format ( qw( US FR ) ) { Link Here
182
        $order_1_1 = C4::Acquisition::populate_order_with_prices(
176
        $order_1_1 = C4::Acquisition::populate_order_with_prices(
183
            {
177
            {
184
                order        => $order_1_1,
178
                order        => $order_1_1,
185
                booksellerid => 'just_something',
179
                booksellerid => 4,
186
                ordering     => 1,
180
                ordering     => 1,
187
            }
181
            }
188
        );
182
        );
Lines 231-237 for my $currency_format ( qw( US FR ) ) { Link Here
231
        $order_1_1 = C4::Acquisition::populate_order_with_prices(
225
        $order_1_1 = C4::Acquisition::populate_order_with_prices(
232
            {
226
            {
233
                order        => $order_1_1,
227
                order        => $order_1_1,
234
                booksellerid => 'just_something',
228
                booksellerid => 4,
235
                receiving    => 1,
229
                receiving    => 1,
236
            }
230
            }
237
        );
231
        );
Lines 264-275 for my $currency_format ( qw( US FR ) ) { Link Here
264
258
265
    subtest 'Configuration 1: 1 0' => sub {
259
    subtest 'Configuration 1: 1 0' => sub {
266
        plan tests => 8;
260
        plan tests => 8;
267
        $bookseller_module->mock(
268
            'fetch',
269
            sub {
270
                return { listincgst => 1, invoiceincgst => 0 };
271
            }
272
        );
273
261
274
        my $biblionumber_1_0 = 44;
262
        my $biblionumber_1_0 = 44;
275
        my $order_1_0        = {
263
        my $order_1_0        = {
Lines 290-296 for my $currency_format ( qw( US FR ) ) { Link Here
290
        $order_1_0 = C4::Acquisition::populate_order_with_prices(
278
        $order_1_0 = C4::Acquisition::populate_order_with_prices(
291
            {
279
            {
292
                order        => $order_1_0,
280
                order        => $order_1_0,
293
                booksellerid => 'just_something',
281
                booksellerid => 3,
294
                ordering     => 1,
282
                ordering     => 1,
295
            }
283
            }
296
        );
284
        );
Lines 339-345 for my $currency_format ( qw( US FR ) ) { Link Here
339
        $order_1_0 = C4::Acquisition::populate_order_with_prices(
327
        $order_1_0 = C4::Acquisition::populate_order_with_prices(
340
            {
328
            {
341
                order        => $order_1_0,
329
                order        => $order_1_0,
342
                booksellerid => 'just_something',
330
                booksellerid => 3,
343
                receiving    => 1,
331
                receiving    => 1,
344
            }
332
            }
345
        );
333
        );
Lines 372-383 for my $currency_format ( qw( US FR ) ) { Link Here
372
360
373
    subtest 'Configuration 1: 0 1' => sub {
361
    subtest 'Configuration 1: 0 1' => sub {
374
        plan tests => 8;
362
        plan tests => 8;
375
        $bookseller_module->mock(
376
            'fetch',
377
            sub {
378
                return { listincgst => 0, invoiceincgst => 1 };
379
            }
380
        );
381
363
382
        my $biblionumber_0_1 = 45;
364
        my $biblionumber_0_1 = 45;
383
        my $order_0_1        = {
365
        my $order_0_1        = {
Lines 398-404 for my $currency_format ( qw( US FR ) ) { Link Here
398
        $order_0_1 = C4::Acquisition::populate_order_with_prices(
380
        $order_0_1 = C4::Acquisition::populate_order_with_prices(
399
            {
381
            {
400
                order        => $order_0_1,
382
                order        => $order_0_1,
401
                booksellerid => 'just_something',
383
                booksellerid => 2,
402
                ordering     => 1,
384
                ordering     => 1,
403
            }
385
            }
404
        );
386
        );
Lines 447-453 for my $currency_format ( qw( US FR ) ) { Link Here
447
        $order_0_1 = C4::Acquisition::populate_order_with_prices(
429
        $order_0_1 = C4::Acquisition::populate_order_with_prices(
448
            {
430
            {
449
                order        => $order_0_1,
431
                order        => $order_0_1,
450
                booksellerid => 'just_something',
432
                booksellerid => 2,
451
                receiving    => 1,
433
                receiving    => 1,
452
            }
434
            }
453
        );
435
        );
(-)a/t/db_dependent/Acquisition.t (-9 / +7 lines)
Lines 19-35 use Modern::Perl; Link Here
19
19
20
use POSIX qw(strftime);
20
use POSIX qw(strftime);
21
21
22
use Test::More tests => 65;
22
use Test::More tests => 63;
23
use Koha::Database;
23
use Koha::Database;
24
24
25
BEGIN {
25
BEGIN {
26
    use_ok('C4::Acquisition');
26
    use_ok('C4::Acquisition');
27
    use_ok('C4::Bookseller');
28
    use_ok('C4::Biblio');
27
    use_ok('C4::Biblio');
29
    use_ok('C4::Budgets');
28
    use_ok('C4::Budgets');
30
    use_ok('C4::Bookseller');
31
    use_ok('Koha::Acquisition::Order');
29
    use_ok('Koha::Acquisition::Order');
32
    use_ok('Koha::Acquisition::Bookseller');
30
    use_ok('Koha::Acquisition::Booksellers');
33
}
31
}
34
32
35
# Sub used for testing C4::Acquisition subs returning order(s):
33
# Sub used for testing C4::Acquisition subs returning order(s):
Lines 125-131 my $dbh = C4::Context->dbh; Link Here
125
$dbh->{RaiseError} = 1;
123
$dbh->{RaiseError} = 1;
126
124
127
# Creating some orders
125
# Creating some orders
128
my $booksellerid = C4::Bookseller::AddBookseller(
126
my $bookseller = Koha::Acquisition::Bookseller->new(
129
    {
127
    {
130
        name         => "my vendor",
128
        name         => "my vendor",
131
        address1     => "bookseller's address",
129
        address1     => "bookseller's address",
Lines 133-143 my $booksellerid = C4::Bookseller::AddBookseller( Link Here
133
        active       => 1,
131
        active       => 1,
134
        deliverytime => 5,
132
        deliverytime => 5,
135
    }
133
    }
136
);
134
)->store;
137
135
my $booksellerid = $bookseller->id;
138
my $booksellerinfo = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
139
136
140
is( $booksellerinfo->{deliverytime},
137
my $booksellerinfo = Koha::Acquisition::Booksellers->find( $booksellerid );
138
is( $booksellerinfo->deliverytime,
141
    5, 'set deliverytime when creating vendor (Bug 10556)' );
139
    5, 'set deliverytime when creating vendor (Bug 10556)' );
142
140
143
my ( $basket, $basketno );
141
my ( $basket, $basketno );
(-)a/t/db_dependent/Acquisition/CancelReceipt.t (-4 / +4 lines)
Lines 24-35 use C4::Context; Link Here
24
use C4::Acquisition;
24
use C4::Acquisition;
25
use C4::Biblio;
25
use C4::Biblio;
26
use C4::Items;
26
use C4::Items;
27
use C4::Bookseller;
28
use C4::Budgets;
27
use C4::Budgets;
29
use t::lib::Mocks;
28
use t::lib::Mocks;
30
29
31
use Koha::Database;
30
use Koha::Database;
32
use Koha::DateUtils;
31
use Koha::DateUtils;
32
use Koha::Acquisition::Booksellers;
33
use Koha::Acquisition::Order;
33
use Koha::Acquisition::Order;
34
use MARC::Record;
34
use MARC::Record;
35
35
Lines 41-57 $dbh->{RaiseError} = 1; Link Here
41
my $builder = t::lib::TestBuilder->new;
41
my $builder = t::lib::TestBuilder->new;
42
my $itemtype = $builder->build({ source => 'Itemtype' })->{ itemtype };
42
my $itemtype = $builder->build({ source => 'Itemtype' })->{ itemtype };
43
43
44
my $booksellerid1 = C4::Bookseller::AddBookseller(
44
my $bookseller = Koha::Acquisition::Bookseller->new(
45
    {
45
    {
46
        name => "my vendor 1",
46
        name => "my vendor 1",
47
        address1 => "bookseller's address",
47
        address1 => "bookseller's address",
48
        phone => "0123456",
48
        phone => "0123456",
49
        active => 1
49
        active => 1
50
    }
50
    }
51
);
51
)->store;
52
52
53
my $basketno1 = C4::Acquisition::NewBasket(
53
my $basketno1 = C4::Acquisition::NewBasket(
54
    $booksellerid1
54
    $bookseller->id
55
);
55
);
56
56
57
my $budgetid = C4::Budgets::AddBudget(
57
my $budgetid = C4::Budgets::AddBudget(
(-)a/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t (-3 / +3 lines)
Lines 6-12 use Data::Dumper; Link Here
6
6
7
use C4::Acquisition qw( NewBasket GetBasketsInfosByBookseller );
7
use C4::Acquisition qw( NewBasket GetBasketsInfosByBookseller );
8
use C4::Biblio qw( AddBiblio );
8
use C4::Biblio qw( AddBiblio );
9
use C4::Bookseller qw( AddBookseller );
10
use C4::Budgets qw( AddBudget );
9
use C4::Budgets qw( AddBudget );
11
use C4::Context;
10
use C4::Context;
12
use Koha::Database;
11
use Koha::Database;
Lines 18-24 $schema->storage->txn_begin(); Link Here
18
my $dbh = C4::Context->dbh;
17
my $dbh = C4::Context->dbh;
19
$dbh->{RaiseError} = 1;
18
$dbh->{RaiseError} = 1;
20
19
21
my $supplierid = C4::Bookseller::AddBookseller(
20
my $supplier = Koha::Acquisition::Bookseller->new(
22
    {
21
    {
23
        name => 'my vendor',
22
        name => 'my vendor',
24
        address1 => 'bookseller\'s address',
23
        address1 => 'bookseller\'s address',
Lines 26-32 my $supplierid = C4::Bookseller::AddBookseller( Link Here
26
        active => 1,
25
        active => 1,
27
        deliverytime => 5,
26
        deliverytime => 5,
28
    }
27
    }
29
);
28
)->store;
29
my $supplierid = $supplier->id;
30
30
31
my $basketno;
31
my $basketno;
32
ok($basketno = NewBasket($supplierid, 1), 'NewBasket(  $supplierid , 1  ) returns $basketno');
32
ok($basketno = NewBasket($supplierid, 1), 'NewBasket(  $supplierid , 1  ) returns $basketno');
(-)a/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t (-4 / +3 lines)
Lines 5-11 use Modern::Perl; Link Here
5
use Test::More;
5
use Test::More;
6
use C4::Acquisition;
6
use C4::Acquisition;
7
use C4::Biblio;
7
use C4::Biblio;
8
use C4::Bookseller;
9
use C4::Budgets;
8
use C4::Budgets;
10
use Koha::Database;
9
use Koha::Database;
11
use Koha::Acquisition::Order;
10
use Koha::Acquisition::Order;
Lines 18-34 $schema->storage->txn_begin(); Link Here
18
my $dbh = C4::Context->dbh;
17
my $dbh = C4::Context->dbh;
19
$dbh->{RaiseError} = 1;
18
$dbh->{RaiseError} = 1;
20
19
21
my $booksellerid = C4::Bookseller::AddBookseller(
20
my $bookseller = Koha::Acquisition::Bookseller->new(
22
    {
21
    {
23
        name => "my vendor",
22
        name => "my vendor",
24
        address1 => "bookseller's address",
23
        address1 => "bookseller's address",
25
        phone => "0123456",
24
        phone => "0123456",
26
        active => 1
25
        active => 1
27
    }
26
    }
28
);
27
)->store;
29
28
30
my $basketno = C4::Acquisition::NewBasket(
29
my $basketno = C4::Acquisition::NewBasket(
31
    $booksellerid
30
    $bookseller->id
32
);
31
);
33
32
34
my $budgetid = C4::Budgets::AddBudget(
33
my $budgetid = C4::Budgets::AddBudget(
(-)a/t/db_dependent/Acquisition/Invoices.t (-5 / +5 lines)
Lines 3-12 Link Here
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use C4::Biblio qw( AddBiblio );
5
use C4::Biblio qw( AddBiblio );
6
use C4::Bookseller qw( AddBookseller );
7
6
8
use Koha::Acquisition::Order;
7
use Koha::Acquisition::Order;
9
use Koha::Acquisition::Bookseller;
8
use Koha::Acquisition::Booksellers;
10
use Koha::Database;
9
use Koha::Database;
11
10
12
use Test::More tests => 24;
11
use Test::More tests => 24;
Lines 22-37 $dbh->{RaiseError} = 1; Link Here
22
21
23
$dbh->do(q{DELETE FROM aqinvoices});
22
$dbh->do(q{DELETE FROM aqinvoices});
24
23
25
my $booksellerid = C4::Bookseller::AddBookseller(
24
my $bookseller = Koha::Acquisition::Bookseller->new(
26
    {
25
    {
27
        name => "my vendor",
26
        name => "my vendor",
28
        address1 => "bookseller's address",
27
        address1 => "bookseller's address",
29
        phone => "0123456",
28
        phone => "0123456",
30
        active => 1
29
        active => 1
31
    }
30
    }
32
);
31
)->store;
32
my $booksellerid = $bookseller->id;
33
33
34
my $booksellerinfo = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
34
my $booksellerinfo = Koha::Acquisition::Booksellers->find( $booksellerid );
35
my $basketno = NewBasket($booksellerid, 1);
35
my $basketno = NewBasket($booksellerid, 1);
36
my $basket   = GetBasket($basketno);
36
my $basket   = GetBasket($basketno);
37
37
(-)a/t/db_dependent/Acquisition/NewOrder.t (-5 / +5 lines)
Lines 5-15 use Modern::Perl; Link Here
5
use Test::More tests => 7;
5
use Test::More tests => 7;
6
use C4::Acquisition;
6
use C4::Acquisition;
7
use C4::Biblio;
7
use C4::Biblio;
8
use C4::Bookseller;
9
use C4::Budgets;
8
use C4::Budgets;
10
use MARC::Record;
9
use MARC::Record;
11
use Koha::Database;
10
use Koha::Database;
12
use Koha::DateUtils qw( dt_from_string output_pref );
11
use Koha::DateUtils qw( dt_from_string output_pref );
12
use Koha::Acquisition::Booksellers;
13
use Koha::Acquisition::Order;
13
use Koha::Acquisition::Order;
14
14
15
my $schema = Koha::Database->new()->schema();
15
my $schema = Koha::Database->new()->schema();
Lines 17-33 $schema->storage->txn_begin(); Link Here
17
my $dbh = C4::Context->dbh;
17
my $dbh = C4::Context->dbh;
18
$dbh->{RaiseError} = 1;
18
$dbh->{RaiseError} = 1;
19
19
20
my $booksellerid = C4::Bookseller::AddBookseller(
20
my $bookseller = Koha::Acquisition::Bookseller->new(
21
    {
21
    {
22
        name => "my vendor",
22
        name => "my vendor",
23
        address1 => "bookseller's address",
23
        address1 => "bookseller's address",
24
        phone => "0123456",
24
        phone => "0123456",
25
        active => 1
25
        active => 1
26
    }
26
    }
27
);
27
)->store;
28
28
29
my $basketno = C4::Acquisition::NewBasket(
29
my $basketno = C4::Acquisition::NewBasket(
30
    $booksellerid
30
    $bookseller->id
31
);
31
);
32
32
33
my $budgetid = C4::Budgets::AddBudget(
33
my $budgetid = C4::Budgets::AddBudget(
Lines 87-90 $order = Koha::Acquisition::Order->fetch({ ordernumber => $ordernumber }); Link Here
87
is( $order->{quantityreceived}, 0, 'Koha::Acquisition::Order->insert set quantityreceivedto 0 if undef is given' );
87
is( $order->{quantityreceived}, 0, 'Koha::Acquisition::Order->insert set quantityreceivedto 0 if undef is given' );
88
is( $order->{entrydate}, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), 'Koha::Acquisition::Order->insert set entrydate to today' );
88
is( $order->{entrydate}, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), 'Koha::Acquisition::Order->insert set entrydate to today' );
89
89
90
$schema->storage->txn_rollback();
90
$schema->storage->txn_rollback();
(-)a/t/db_dependent/Acquisition/OrderFromSubscription.t (-6 / +5 lines)
Lines 1-10 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
use Test::More tests => 13;
3
use Test::More tests => 12;
4
4
5
use_ok('C4::Acquisition');
5
use_ok('C4::Acquisition');
6
use_ok('C4::Biblio');
6
use_ok('C4::Biblio');
7
use_ok('C4::Bookseller');
8
use_ok('C4::Budgets');
7
use_ok('C4::Budgets');
9
use_ok('C4::Serials');
8
use_ok('C4::Serials');
10
9
Lines 17-30 $schema->storage->txn_begin(); Link Here
17
my $dbh = C4::Context->dbh;
16
my $dbh = C4::Context->dbh;
18
$dbh->{RaiseError} = 1;
17
$dbh->{RaiseError} = 1;
19
18
20
my $booksellerid = C4::Bookseller::AddBookseller(
19
my $bookseller = Koha::Acquisition::Bookseller->new(
21
    {
20
    {
22
        name => "my vendor",
21
        name => "my vendor",
23
        address1 => "bookseller's address",
22
        address1 => "bookseller's address",
24
        phone => "0123456",
23
        phone => "0123456",
25
        active => 1
24
        active => 1
26
    }
25
    }
27
);
26
)->store;
28
27
29
my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
28
my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
30
my $budgetid;
29
my $budgetid;
Lines 53-59 my $subscriptionid = NewSubscription( Link Here
53
die unless $subscriptionid;
52
die unless $subscriptionid;
54
53
55
my ($basket, $basketno);
54
my ($basket, $basketno);
56
ok($basketno = NewBasket($booksellerid, 1), "NewBasket(  $booksellerid , 1  ) returns $basketno");
55
ok($basketno = NewBasket($bookseller->id, 1), "NewBasket(  " . $bookseller->id . ", 1  ) returns $basketno");
57
56
58
my $cost = 42.00;
57
my $cost = 42.00;
59
my $subscription = GetSubscription( $subscriptionid );
58
my $subscription = GetSubscription( $subscriptionid );
Lines 83-89 is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscripti Link Here
83
ok( $order->{ecost} == $cost, "test cost for the last order not received");
82
ok( $order->{ecost} == $cost, "test cost for the last order not received");
84
83
85
$dbh->do(q{DELETE FROM aqinvoices});
84
$dbh->do(q{DELETE FROM aqinvoices});
86
my $invoiceid = AddInvoice(invoicenumber => 'invoice1', booksellerid => $booksellerid, unknown => "unknown");
85
my $invoiceid = AddInvoice(invoicenumber => 'invoice1', booksellerid => $bookseller->id, unknown => "unknown");
87
86
88
my $invoice = GetInvoice( $invoiceid );
87
my $invoice = GetInvoice( $invoiceid );
89
$invoice->{datereceived} = '02-01-2013';
88
$invoice->{datereceived} = '02-01-2013';
(-)a/t/db_dependent/Acquisition/OrderUsers.t (-5 / +5 lines)
Lines 3-12 use Test::More tests => 3; Link Here
3
3
4
use C4::Acquisition;
4
use C4::Acquisition;
5
use C4::Biblio;
5
use C4::Biblio;
6
use C4::Bookseller;
7
use C4::Letters;
6
use C4::Letters;
8
use Koha::Database;
7
use Koha::Database;
9
use Koha::Acquisition::Order;
8
use Koha::Acquisition::Order;
9
use Koha::Acquisition::Booksellers;
10
10
11
use t::lib::TestBuilder;
11
use t::lib::TestBuilder;
12
12
Lines 19-34 my $library = $builder->build({ Link Here
19
});
19
});
20
20
21
# Creating some orders
21
# Creating some orders
22
my $booksellerid = C4::Bookseller::AddBookseller(
22
my $bookseller = Koha::Acquisition::Bookseller->new(
23
    {
23
    {
24
        name         => "my vendor",
24
        name         => "my vendor",
25
        address1     => "bookseller's address",
25
        address1     => "bookseller's address",
26
        phone        => "0123456",
26
        phone        => "0123456",
27
        active       => 1,
27
        active       => 1,
28
    }
28
    }
29
);
29
)->store;
30
30
31
my $basketno = NewBasket( $booksellerid, 1 );
31
my $basketno = NewBasket( $bookseller->id, 1 );
32
32
33
my $budgetid = C4::Budgets::AddBudget(
33
my $budgetid = C4::Budgets::AddBudget(
34
    {
34
    {
Lines 61-67 my $ordernumber = $order->{ordernumber}; Link Here
61
61
62
my $invoiceid = AddInvoice(
62
my $invoiceid = AddInvoice(
63
    invoicenumber => 'invoice',
63
    invoicenumber => 'invoice',
64
    booksellerid  => $booksellerid,
64
    booksellerid  => $bookseller->id,
65
    unknown       => "unknown"
65
    unknown       => "unknown"
66
);
66
);
67
67
(-)a/t/db_dependent/Acquisition/StandingOrders.t (-1 lines)
Lines 7-13 use C4::Context; Link Here
7
use C4::Acquisition;
7
use C4::Acquisition;
8
use C4::Biblio;
8
use C4::Biblio;
9
use C4::Items;
9
use C4::Items;
10
use C4::Bookseller;
11
use C4::Budgets;
10
use C4::Budgets;
12
use Koha::Acquisition::Order;
11
use Koha::Acquisition::Order;
13
use t::lib::Mocks;
12
use t::lib::Mocks;
(-)a/t/db_dependent/Acquisition/TransferOrder.t (-7 / +7 lines)
Lines 7-16 use C4::Context; Link Here
7
use C4::Acquisition;
7
use C4::Acquisition;
8
use C4::Biblio;
8
use C4::Biblio;
9
use C4::Items;
9
use C4::Items;
10
use C4::Bookseller;
11
use C4::Budgets;
10
use C4::Budgets;
12
use Koha::Database;
11
use Koha::Database;
13
use Koha::DateUtils;
12
use Koha::DateUtils;
13
use Koha::Acquisition::Booksellers;
14
use Koha::Acquisition::Order;
14
use Koha::Acquisition::Order;
15
use MARC::Record;
15
use MARC::Record;
16
16
Lines 20-49 $schema->storage->txn_begin(); Link Here
20
my $dbh = C4::Context->dbh;
20
my $dbh = C4::Context->dbh;
21
$dbh->{RaiseError} = 1;
21
$dbh->{RaiseError} = 1;
22
22
23
my $booksellerid1 = C4::Bookseller::AddBookseller(
23
my $bookseller1 = Koha::Acquisition::Bookseller->new(
24
    {
24
    {
25
        name => "my vendor 1",
25
        name => "my vendor 1",
26
        address1 => "bookseller's address",
26
        address1 => "bookseller's address",
27
        phone => "0123456",
27
        phone => "0123456",
28
        active => 1
28
        active => 1
29
    }
29
    }
30
);
30
)->store;
31
31
32
my $basketno1 = C4::Acquisition::NewBasket(
32
my $basketno1 = C4::Acquisition::NewBasket(
33
    $booksellerid1
33
    $bookseller1->id
34
);
34
);
35
35
36
my $booksellerid2 = C4::Bookseller::AddBookseller(
36
my $bookseller2 = Koha::Acquisition::Bookseller->new(
37
    {
37
    {
38
        name => "my vendor 2",
38
        name => "my vendor 2",
39
        address1 => "bookseller's address",
39
        address1 => "bookseller's address",
40
        phone => "0123456",
40
        phone => "0123456",
41
        active => 1
41
        active => 1
42
    }
42
    }
43
);
43
)->store;
44
44
45
my $basketno2 = C4::Acquisition::NewBasket(
45
my $basketno2 = C4::Acquisition::NewBasket(
46
    $booksellerid2
46
    $bookseller2->id
47
);
47
);
48
48
49
my $budgetid = C4::Budgets::AddBudget(
49
my $budgetid = C4::Budgets::AddBudget(
(-)a/t/db_dependent/Acquisition/close_reopen_basket.t (-4 / +4 lines)
Lines 5-14 use Modern::Perl; Link Here
5
use Test::More tests => 6;
5
use Test::More tests => 6;
6
use C4::Acquisition;
6
use C4::Acquisition;
7
use C4::Biblio qw( AddBiblio DelBiblio );
7
use C4::Biblio qw( AddBiblio DelBiblio );
8
use C4::Bookseller;
9
use C4::Budgets;
8
use C4::Budgets;
10
use C4::Context;
9
use C4::Context;
11
use Koha::Database;
10
use Koha::Database;
11
use Koha::Acquisition::Bookseller;
12
use Koha::Acquisition::Order;
12
use Koha::Acquisition::Order;
13
13
14
# Start transaction
14
# Start transaction
Lines 22-38 $dbh->do(q{ Link Here
22
    DELETE FROM aqorders;
22
    DELETE FROM aqorders;
23
});
23
});
24
24
25
my $booksellerid = C4::Bookseller::AddBookseller(
25
my $bookseller = Koha::Acquisition::Bookseller->new(
26
    {
26
    {
27
        name => "my vendor",
27
        name => "my vendor",
28
        address1 => "bookseller's address",
28
        address1 => "bookseller's address",
29
        phone => "0123456",
29
        phone => "0123456",
30
        active => 1
30
        active => 1
31
    }
31
    }
32
);
32
)->store;
33
33
34
my $basketno = C4::Acquisition::NewBasket(
34
my $basketno = C4::Acquisition::NewBasket(
35
    $booksellerid
35
    $bookseller->id
36
);
36
);
37
37
38
my $budgetid = C4::Budgets::AddBudget(
38
my $budgetid = C4::Budgets::AddBudget(
(-)a/t/db_dependent/AdditionalField.t (-10 lines)
Lines 3-9 Link Here
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 40;
4
use Test::More tests => 40;
5
5
6
use C4::Bookseller qw( AddBookseller );
7
use C4::Context;
6
use C4::Context;
8
use Koha::AdditionalField;
7
use Koha::AdditionalField;
9
8
Lines 108-122 use C4::Serials; Link Here
108
use C4::Serials::Frequency;
107
use C4::Serials::Frequency;
109
use C4::Serials::Numberpattern;
108
use C4::Serials::Numberpattern;
110
109
111
my $booksellerid = C4::Bookseller::AddBookseller(
112
    {
113
        name => "my vendor",
114
        address1 => "bookseller's address",
115
        phone => "0123456",
116
        active => 1
117
    }
118
);
119
120
my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
110
my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
121
my $budgetid;
111
my $budgetid;
122
my $bpid = AddBudgetPeriod({
112
my $bpid = AddBudgetPeriod({
(-)a/t/db_dependent/Bookseller.t (-94 / +99 lines)
Lines 2-8 Link Here
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use Test::More tests => 88;
5
use Test::More tests => 86;
6
use Test::MockModule;
6
use Test::MockModule;
7
use Test::Warn;
7
use Test::Warn;
8
8
Lines 15-35 use C4::Serials; Link Here
15
use C4::Budgets;
15
use C4::Budgets;
16
use C4::Biblio;
16
use C4::Biblio;
17
17
18
use Koha::Acquisition::Booksellers;
18
use Koha::Acquisition::Order;
19
use Koha::Acquisition::Order;
19
use Koha::Database;
20
use Koha::Database;
20
21
21
BEGIN {
22
BEGIN {
22
    use_ok('C4::Bookseller');
23
    use_ok('C4::Bookseller');
23
    use_ok('Koha::Acquisition::Bookseller');
24
}
24
}
25
25
26
can_ok(
26
can_ok(
27
27
28
    'C4::Bookseller', qw(
28
    'C4::Bookseller', qw(
29
      AddBookseller
30
      DelBookseller
31
      GetBooksellersWithLateOrders
29
      GetBooksellersWithLateOrders
32
      ModBookseller )
30
    )
33
);
31
);
34
32
35
#Start transaction
33
#Start transaction
Lines 47-53 $dbh->do(q|DELETE FROM aqbooksellers|); Link Here
47
$dbh->do(q|DELETE FROM subscription|);
45
$dbh->do(q|DELETE FROM subscription|);
48
46
49
#Test AddBookseller
47
#Test AddBookseller
50
my $count            = scalar( Koha::Acquisition::Bookseller->search() );
48
my $count            = Koha::Acquisition::Booksellers->search()->count();
51
my $sample_supplier1 = {
49
my $sample_supplier1 = {
52
    name          => 'Name1',
50
    name          => 'Name1',
53
    address1      => 'address1_1',
51
    address1      => 'address1_1',
Lines 89-125 my $sample_supplier2 = { Link Here
89
    deliverytime  => 2
87
    deliverytime  => 2
90
};
88
};
91
89
92
my $id_supplier1 = C4::Bookseller::AddBookseller($sample_supplier1);
90
my $supplier1 = Koha::Acquisition::Bookseller->new($sample_supplier1)->store;
93
my $id_supplier2 = C4::Bookseller::AddBookseller($sample_supplier2);
91
my $id_supplier1 = $supplier1->id;
94
92
my $supplier2 = Koha::Acquisition::Bookseller->new($sample_supplier2)->store;
95
#my $id_bookseller3 = C4::Bookseller::AddBookseller();# NOTE : Doesn't work because the field name cannot be null
93
my $id_supplier2 = $supplier2->id;
96
94
97
like( $id_supplier1, '/^\d+$/', "AddBookseller for supplier1 return an id" );
95
like( $id_supplier1, '/^\d+$/', "AddBookseller for supplier1 return an id" );
98
like( $id_supplier2, '/^\d+$/', "AddBookseller for supplier2 return an id" );
96
like( $id_supplier2, '/^\d+$/', "AddBookseller for supplier2 return an id" );
99
my @b = Koha::Acquisition::Bookseller->search();
97
is( Koha::Acquisition::Booksellers->search()->count,
100
is ( scalar(@b),
101
    $count + 2, "Supplier1 and Supplier2 have been added" );
98
    $count + 2, "Supplier1 and Supplier2 have been added" );
102
99
103
#Test DelBookseller
100
#Test DelBookseller
104
my $del = C4::Bookseller::DelBookseller($id_supplier1);
101
my $del = $supplier1->delete;
105
is( $del, 1, "DelBookseller returns 1 - 1 supplier has been deleted " );
102
is( $del, 1, "DelBookseller returns 1 - 1 supplier has been deleted " );
106
my $b = Koha::Acquisition::Bookseller->fetch({id => $id_supplier1});
103
my $b = Koha::Acquisition::Booksellers->find( $id_supplier1 );
107
is( $b,
104
is( $b,
108
    undef, "Supplier1  has been deleted - id_supplier1 $id_supplier1 doesnt exist anymore" );
105
    undef, "Supplier1  has been deleted - id_supplier1 $id_supplier1 doesnt exist anymore" );
109
106
110
#Test get bookseller
107
#Test get bookseller
111
my @bookseller2 = Koha::Acquisition::Bookseller->search({name => $sample_supplier2->{name} });
108
my @bookseller2 = Koha::Acquisition::Booksellers->search({name => $sample_supplier2->{name} });
112
is( scalar(@bookseller2), 1, "Get only  Supplier2" );
109
is( scalar(@bookseller2), 1, "Get only  Supplier2" );
113
$bookseller2[0] = field_filter( $bookseller2[0] );
110
for my $bookseller ( @bookseller2 ) {
111
    $bookseller = field_filter( $bookseller->unblessed );
112
}
114
113
115
$sample_supplier2->{id} = $id_supplier2;
114
$sample_supplier2->{id} = $id_supplier2;
116
is_deeply( $bookseller2[0], $sample_supplier2,
115
is_deeply( $bookseller2[0], $sample_supplier2,
117
    "Koha::Acquisition::Bookseller->search returns the right informations about $sample_supplier2" );
116
    "Koha::Acquisition::Booksellers->search returns the right informations about supplier $sample_supplier2->{name}" );
118
117
119
$id_supplier1 = C4::Bookseller::AddBookseller($sample_supplier1);
118
$supplier1 = Koha::Acquisition::Bookseller->new($sample_supplier1)->store;
120
my @booksellers = Koha::Acquisition::Bookseller->search(); #NOTE :without params, it returns all the booksellers
119
$id_supplier1 = $supplier1->id;
121
for my $i ( 0 .. scalar(@booksellers) - 1 ) {
120
my @booksellers = Koha::Acquisition::Booksellers->search();
122
    $booksellers[$i] = field_filter( $booksellers[$i] );
121
for my $bookseller ( @booksellers ) {
122
    $bookseller = field_filter( $bookseller->unblessed );
123
}
123
}
124
124
125
$sample_supplier1->{id} = $id_supplier1;
125
$sample_supplier1->{id} = $id_supplier1;
Lines 128-157 my @tab = ( $sample_supplier1, $sample_supplier2 ); Link Here
128
is_deeply( \@booksellers, \@tab,
128
is_deeply( \@booksellers, \@tab,
129
    "Returns right fields of Supplier1 and Supplier2" );
129
    "Returns right fields of Supplier1 and Supplier2" );
130
130
131
#Test basket_count
131
#Test baskets
132
my @bookseller1 = Koha::Acquisition::Bookseller->search({name => $sample_supplier1->{name} });
132
my @bookseller1 = Koha::Acquisition::Booksellers->search({name => $sample_supplier1->{name} });
133
is( $bookseller1[0]->basket_count, 0, 'Supplier1 has 0 basket' );
133
is( $bookseller1[0]->baskets->count, 0, 'Supplier1 has 0 basket' );
134
my $basketno1 =
134
my $basketno1 =
135
  C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby1', 'basketname1' );
135
  C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby1', 'basketname1' );
136
my $basketno2 =
136
my $basketno2 =
137
  C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby2', 'basketname2' );
137
  C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby2', 'basketname2' );
138
@bookseller1 = Koha::Acquisition::Bookseller::search({ name => $sample_supplier1->{name} });
138
@bookseller1 = Koha::Acquisition::Booksellers->search({ name => $sample_supplier1->{name} });
139
is( $bookseller1[0]->basket_count, 2, 'Supplier1 has 2 baskets' );
139
is( $bookseller1[0]->baskets->count, 2, 'Supplier1 has 2 baskets' );
140
140
141
#Test Koha::Acquisition::Bookseller->new using id
141
#Test Koha::Acquisition::Bookseller->new using id
142
my $bookseller1fromid = Koha::Acquisition::Bookseller->fetch;
142
my $bookseller1fromid = Koha::Acquisition::Booksellers->find;
143
is( $bookseller1fromid, undef,
143
is( $bookseller1fromid, undef,
144
    "fetch returns undef if no id given" );
144
    "find returns undef if no id given" );
145
$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1});
145
$bookseller1fromid = Koha::Acquisition::Booksellers->find( $id_supplier1 );
146
$bookseller1fromid = field_filter($bookseller1fromid);
146
$bookseller1fromid = field_filter($bookseller1fromid->unblessed);
147
is_deeply( $bookseller1fromid, $sample_supplier1,
147
is_deeply( $bookseller1fromid, $sample_supplier1,
148
    "Get Supplier1 (fetch a bookseller by id)" );
148
    "Get Supplier1 (find a bookseller by id)" );
149
149
150
#Test basket_count
150
$bookseller1fromid = Koha::Acquisition::Booksellers->find( $id_supplier1 );
151
$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1});
151
is( $bookseller1fromid->baskets->count, 2, 'Supplier1 has 2 baskets' );
152
is( $bookseller1fromid->basket_count, 2, 'Supplier1 has 2 baskets' );
153
152
154
#Test subscription_count
153
#Test subscriptions
155
my $dt_today    = dt_from_string;
154
my $dt_today    = dt_from_string;
156
my $today       = output_pref({ dt => $dt_today, dateformat => 'iso', timeformat => '24hr', dateonly => 1 });
155
my $today       = output_pref({ dt => $dt_today, dateformat => 'iso', timeformat => '24hr', dateonly => 1 });
157
156
Lines 178-185 $bib->append_fields( Link Here
178
    MARC::Field->new('500', ' ', ' ', a => 'bib notes'),
177
    MARC::Field->new('500', ' ', ' ', a => 'bib notes'),
179
);
178
);
180
my ($biblionumber, $biblioitemnumber) = AddBiblio($bib, '');
179
my ($biblionumber, $biblioitemnumber) = AddBiblio($bib, '');
181
$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1 });
180
$bookseller1fromid = Koha::Acquisition::Booksellers->find( $id_supplier1 );
182
is( $bookseller1fromid->subscription_count,
181
is( $bookseller1fromid->subscriptions->count,
183
    0, 'Supplier1 has 0 subscription' );
182
    0, 'Supplier1 has 0 subscription' );
184
183
185
my $id_subscription1 = NewSubscription(
184
my $id_subscription1 = NewSubscription(
Lines 203-210 my $id_subscription2 = NewSubscription( Link Here
203
    undef, undef, 0,          undef,         '2013-07-31', 0
202
    undef, undef, 0,          undef,         '2013-07-31', 0
204
);
203
);
205
204
206
$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1 });
205
$bookseller1fromid = Koha::Acquisition::Booksellers->find( $id_supplier1 );
207
is( $bookseller1fromid->subscription_count,
206
is( $bookseller1fromid->subscriptions->count,
208
    2, 'Supplier1 has 2 subscriptions' );
207
    2, 'Supplier1 has 2 subscriptions' );
209
208
210
#Test ModBookseller
209
#Test ModBookseller
Lines 230-251 $sample_supplier2 = { Link Here
230
    deliverytime  => 2,
229
    deliverytime  => 2,
231
};
230
};
232
231
233
my $modif1 = C4::Bookseller::ModBookseller();
232
my $modif1 = Koha::Acquisition::Booksellers->find($id_supplier2)->set($sample_supplier2)->store;
234
is( $modif1, undef,
233
is( ref $modif1, 'Koha::Acquisition::Bookseller', "ModBookseller has updated the bookseller" );
235
    "ModBookseller returns undef if no params given - Nothing happened" );
234
is( Koha::Acquisition::Booksellers->search->count,
236
$modif1 = C4::Bookseller::ModBookseller($sample_supplier2);
237
is( $modif1, 1, "ModBookseller modifies only the supplier2" );
238
is( scalar( Koha::Acquisition::Bookseller->search ),
239
    $count + 2, "Supplier2 has been modified - Nothing added" );
235
    $count + 2, "Supplier2 has been modified - Nothing added" );
240
236
$supplier2 = Koha::Acquisition::Booksellers->find($id_supplier2);
241
$modif1 = C4::Bookseller::ModBookseller(
237
is( $supplier2->name, 'Name2 modified', "supplier's name should have been modified" );
242
    {
243
        id   => -1,
244
        name => 'name3'
245
    }
246
);
247
#is( $modif1, '0E0',
248
#    "ModBookseller returns OEO if the id doesnt exist - Nothing modified" );
249
238
250
#Test GetBooksellersWithLateOrders
239
#Test GetBooksellersWithLateOrders
251
#Add 2 suppliers
240
#Add 2 suppliers
Lines 288-295 my $sample_supplier4 = { Link Here
288
    discount      => '3.0000',
277
    discount      => '3.0000',
289
    notes         => 'notes3',
278
    notes         => 'notes3',
290
};
279
};
291
my $id_supplier3 = C4::Bookseller::AddBookseller($sample_supplier3);
280
my $supplier3 = Koha::Acquisition::Bookseller->new($sample_supplier3)->store;
292
my $id_supplier4 = C4::Bookseller::AddBookseller($sample_supplier4);
281
my $id_supplier3 = $supplier3->id;
282
my $supplier4 = Koha::Acquisition::Bookseller->new($sample_supplier4)->store;
283
my $id_supplier4 = $supplier4->id;
293
284
294
#Add 2 baskets
285
#Add 2 baskets
295
my $basketno3 =
286
my $basketno3 =
Lines 681-749 is( Link Here
681
    3,
672
    3,
682
    'superlibrarian can see all subscriptions with IndependentBranches on (bug 12048)'
673
    'superlibrarian can see all subscriptions with IndependentBranches on (bug 12048)'
683
);
674
);
675
684
#Test contact editing
676
#Test contact editing
685
my $booksellerid = C4::Bookseller::AddBookseller(
677
my $sample_supplier = {
686
    {
687
        name     => "my vendor",
678
        name     => "my vendor",
688
        address1 => "bookseller's address",
679
        address1 => "bookseller's address",
689
        phone    => "0123456",
680
        phone    => "0123456",
690
        active   => 1
681
        active   => 1
691
    },
682
    };
692
    [
683
my $supplier = Koha::Acquisition::Bookseller->new($sample_supplier)->store;
693
        { name => 'John Smith',  phone => '0123456x1' },
684
my $booksellerid = $supplier->id;
694
        { name => 'Leo Tolstoy', phone => '0123456x2' },
685
my $contact1 = Koha::Acquisition::Bookseller::Contact->new({
695
    ]
686
        name => 'John Smith',
696
);
687
        phone => '0123456x1',
697
688
        booksellerid => $booksellerid,
698
@booksellers = Koha::Acquisition::Bookseller->search({ name => 'my vendor' });
689
})->store;
690
my $contact2 = Koha::Acquisition::Bookseller::Contact->new({
691
        name => 'Leo Tolstoy',
692
        phone => '0123456x2',
693
        booksellerid => $booksellerid,
694
})->store;
695
696
@booksellers = Koha::Acquisition::Booksellers->search({ name => 'my vendor' });
699
ok(
697
ok(
700
    ( grep { $_->{'id'} == $booksellerid } @booksellers ),
698
    ( grep { $_->id == $booksellerid } @booksellers ),
701
    'Koha::Acquisition::Bookseller->search returns correct record when passed a name'
699
    'Koha::Acquisition::Booksellers->search returns correct record when passed a name'
702
);
700
);
703
701
704
my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
702
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
705
is( $bookseller->{'id'}, $booksellerid, 'Retrieved desired record' );
703
is( $bookseller->id, $booksellerid, 'Retrieved desired record' );
706
is( $bookseller->{'phone'}, '0123456', 'New bookseller has expected phone' );
704
is( $bookseller->phone, '0123456', 'New bookseller has expected phone' );
707
my $contacts = $bookseller->contacts;
705
my $contacts = $bookseller->contacts;
708
is( ref $bookseller->contacts,
706
is( $contacts->count,
709
    'ARRAY', 'Koha::Acquisition::Bookseller->fetch returns arrayref of contacts' );
707
    2, 'bookseller should have 2 contacts' );
708
my $first_contact = $contacts->next;
710
is(
709
is(
711
    ref $bookseller->{'contacts'}->[0],
710
    ref $first_contact,
712
    'C4::Bookseller::Contact',
711
    'Koha::Acquisition::Bookseller::Contact',
713
    'First contact is a contact object'
712
    'First contact is a AqContact'
714
);
713
);
715
is( $bookseller->{'contacts'}->[0]->phone,
714
is( $first_contact->phone,
716
    '0123456x1', 'Contact has expected phone number' );
715
    '0123456x1', 'Contact has expected phone number' );
717
is( scalar @{ $bookseller->{'contacts'} }, 2, 'Saved two contacts' );
718
716
719
pop @{ $bookseller->{'contacts'} };
717
my $second_contact = $contacts->next;
720
$bookseller->{'name'} = 'your vendor';
718
$second_contact->delete;
721
$bookseller->{'contacts'}->[0]->phone('654321');
719
$bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
722
C4::Bookseller::ModBookseller($bookseller);
720
$bookseller->name('your vendor')->store;
723
724
$bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
725
$contacts = $bookseller->contacts;
721
$contacts = $bookseller->contacts;
726
is( $bookseller->{'name'}, 'your vendor',
722
$first_contact = $contacts->next;
723
$first_contact->phone('654321');
724
$first_contact->store;
725
726
$bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
727
is( $bookseller->name, 'your vendor',
727
    'Successfully changed name of vendor' );
728
    'Successfully changed name of vendor' );
728
is( $contacts->[0]->phone,
729
$contacts = $bookseller->contacts;
730
is( $contacts->count,
731
    1, 'Only one contact after modification' );
732
$first_contact = $contacts->next;
733
is( $first_contact->phone,
729
    '654321',
734
    '654321',
730
    'Successfully changed contact phone number by modifying bookseller hash' );
735
    'Successfully changed contact phone number by modifying bookseller hash' );
731
is( scalar @$contacts,
732
    1, 'Only one contact after modification' );
733
736
734
C4::Bookseller::ModBookseller( $bookseller,
737
$first_contact->name( 'John Jacob Jingleheimer Schmidt' );
735
    [ { name => 'John Jacob Jingleheimer Schmidt' } ] );
738
$first_contact->phone(undef);
739
$first_contact->store;
736
740
737
$bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
741
$bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
738
$contacts = $bookseller->contacts;
742
$contacts = $bookseller->contacts;
743
$first_contact = $contacts->next;
739
is(
744
is(
740
    $contacts->[0]->name,
745
    $first_contact->name,
741
    'John Jacob Jingleheimer Schmidt',
746
    'John Jacob Jingleheimer Schmidt',
742
    'Changed name of contact'
747
    'Changed name of contact'
743
);
748
);
744
is( $contacts->[0]->phone,
749
is( $first_contact->phone,
745
    undef, 'Removed phone number from contact' );
750
    undef, 'Removed phone number from contact' );
746
is( scalar @$contacts,
751
is( $contacts->count,
747
    1, 'Only one contact after modification' );
752
    1, 'Only one contact after modification' );
748
753
749
#End transaction
754
#End transaction
(-)a/t/db_dependent/Budgets.t (-3 / +4 lines)
Lines 7-17 BEGIN { Link Here
7
}
7
}
8
use C4::Context;
8
use C4::Context;
9
use C4::Biblio;
9
use C4::Biblio;
10
use C4::Bookseller;
11
use C4::Acquisition;
10
use C4::Acquisition;
12
use C4::Members qw( AddMember );
11
use C4::Members qw( AddMember );
13
12
14
use Koha::Acquisition::Order;
13
use Koha::Acquisition::Order;
14
use Koha::Acquisition::Booksellers;
15
15
16
use t::lib::TestBuilder;
16
use t::lib::TestBuilder;
17
17
Lines 270-276 my $budget_id21 = AddBudget( Link Here
270
    }
270
    }
271
);
271
);
272
272
273
my $booksellerid = C4::Bookseller::AddBookseller(
273
my $bookseller = Koha::Acquisition::Bookseller->new(
274
    {
274
    {
275
        name         => "my vendor",
275
        name         => "my vendor",
276
        address1     => "bookseller's address",
276
        address1     => "bookseller's address",
Lines 278-284 my $booksellerid = C4::Bookseller::AddBookseller( Link Here
278
        active       => 1,
278
        active       => 1,
279
        deliverytime => 5,
279
        deliverytime => 5,
280
    }
280
    }
281
);
281
)->store;
282
my $booksellerid = $bookseller->id;
282
283
283
my $basketno = C4::Acquisition::NewBasket( $booksellerid, 1 );
284
my $basketno = C4::Acquisition::NewBasket( $booksellerid, 1 );
284
my ( $biblionumber, $biblioitemnumber ) =
285
my ( $biblionumber, $biblioitemnumber ) =
(-)a/t/db_dependent/Contract.t (-3 / +5 lines)
Lines 20-27 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use C4::Context;
22
use C4::Context;
23
use C4::Bookseller;
24
use Koha::DateUtils;
23
use Koha::DateUtils;
24
use Koha::Acquisition::Booksellers;
25
25
26
use DateTime::Duration;
26
use DateTime::Duration;
27
27
Lines 40-48 $dbh->do(q|DELETE FROM aqcontract|); Link Here
40
$dbh->do(q|DELETE FROM aqbooksellers|);
40
$dbh->do(q|DELETE FROM aqbooksellers|);
41
41
42
42
43
my $bookseller_id1 = C4::Bookseller::AddBookseller( { name => 'My first bookseller' } );
43
my $bookseller1 = Koha::Acquisition::Bookseller->new( { name => 'My first bookseller' } )->store;
44
my $bookseller_id1 = $bookseller1->id;
44
isnt( $bookseller_id1, undef, 'AddBookseller does not return undef' );
45
isnt( $bookseller_id1, undef, 'AddBookseller does not return undef' );
45
my $bookseller_id2 = C4::Bookseller::AddBookseller( { name => 'My second bookseller' } );
46
my $bookseller2 = Koha::Acquisition::Bookseller->new( { name => 'My second bookseller' } )->store;
47
my $bookseller_id2 = $bookseller2->id;
46
isnt( $bookseller_id2, undef, 'AddBookseller does not return undef' );
48
isnt( $bookseller_id2, undef, 'AddBookseller does not return undef' );
47
my $contracts = GetContracts();
49
my $contracts = GetContracts();
48
is( @$contracts, 0, 'GetContracts returns the correct number of contracts' );
50
is( @$contracts, 0, 'GetContracts returns the correct number of contracts' );
(-)a/t/db_dependent/Letters.t (-14 / +12 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 80;
21
use Test::More tests => 79;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 38-51 use_ok('C4::Context'); Link Here
38
use_ok('C4::Members');
38
use_ok('C4::Members');
39
use_ok('C4::Acquisition');
39
use_ok('C4::Acquisition');
40
use_ok('C4::Biblio');
40
use_ok('C4::Biblio');
41
use_ok('C4::Bookseller');
42
use_ok('C4::Letters');
41
use_ok('C4::Letters');
43
use t::lib::Mocks;
42
use t::lib::Mocks;
44
use t::lib::TestBuilder;
43
use t::lib::TestBuilder;
45
use Koha::Database;
44
use Koha::Database;
46
use Koha::DateUtils qw( dt_from_string output_pref );
45
use Koha::DateUtils qw( dt_from_string output_pref );
47
use Koha::Acquisition::Order;
46
use Koha::Acquisition::Order;
48
use Koha::Acquisition::Bookseller;
47
use Koha::Acquisition::Booksellers;
48
use Koha::Acquisition::Bookseller::Contacts;
49
use Koha::Libraries;
49
use Koha::Libraries;
50
my $schema = Koha::Database->schema;
50
my $schema = Koha::Database->schema;
51
$schema->storage->txn_begin();
51
$schema->storage->txn_begin();
Lines 366-384 $dbh->do(q{INSERT INTO letter (module, code, name, title, content) VALUES ('orde Link Here
366
    is( $values->{dateexpiry}, '2015-12-13', "_parseletter doesn't modify its parameters" );
366
    is( $values->{dateexpiry}, '2015-12-13', "_parseletter doesn't modify its parameters" );
367
}
367
}
368
368
369
my $booksellerid = C4::Bookseller::AddBookseller(
369
my $bookseller = Koha::Acquisition::Bookseller->new(
370
    {
370
    {
371
        name => "my vendor",
371
        name => "my vendor",
372
        address1 => "bookseller's address",
372
        address1 => "bookseller's address",
373
        phone => "0123456",
373
        phone => "0123456",
374
        active => 1,
374
        active => 1,
375
        deliverytime => 5,
375
        deliverytime => 5,
376
    },
376
    }
377
    [
377
)->store;
378
        { name => 'John Smith', acqprimary => 1, phone => '0123456x1', claimacquisition => 1, orderacquisition => 1 },
378
my $booksellerid = $bookseller->id;
379
        { name => 'Leo Tolstoy', phone => '0123456x2', claimissues => 1 },
379
380
    ]
380
Koha::Acquisition::Bookseller::Contact->new( { name => 'John Smith',  phone => '0123456x1', claimacquisition => 1, orderacquisition => 1, booksellerid => $booksellerid } )->store;
381
);
381
Koha::Acquisition::Bookseller::Contact->new( { name => 'Leo Tolstoy', phone => '0123456x2', claimissues      => 1, booksellerid => $booksellerid } )->store;
382
my $basketno = NewBasket($booksellerid, 1);
382
my $basketno = NewBasket($booksellerid, 1);
383
383
384
my $budgetid = C4::Budgets::AddBudget({
384
my $budgetid = C4::Budgets::AddBudget({
Lines 416-425 warning_like { Link Here
416
    "SendAlerts prints a warning";
416
    "SendAlerts prints a warning";
417
is($err->{'error'}, 'no_email', "Trying to send an alert when there's no e-mail results in an error");
417
is($err->{'error'}, 'no_email', "Trying to send an alert when there's no e-mail results in an error");
418
418
419
my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
419
$bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
420
$bookseller->contacts->[0]->email('testemail@mydomain.com');
420
$bookseller->contacts->next->email('testemail@mydomain.com')->store;
421
C4::Bookseller::ModBookseller($bookseller);
422
$bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
423
421
424
# Ensure that the preference 'LetterLog' is set to logging
422
# Ensure that the preference 'LetterLog' is set to logging
425
t::lib::Mocks::mock_preference( 'LetterLog', 'on' );
423
t::lib::Mocks::mock_preference( 'LetterLog', 'on' );
(-)a/t/db_dependent/Serials.t (-2 / +2 lines)
Lines 11-20 use C4::Serials; Link Here
11
use C4::Serials::Frequency;
11
use C4::Serials::Frequency;
12
use C4::Serials::Numberpattern;
12
use C4::Serials::Numberpattern;
13
use C4::Debug;
13
use C4::Debug;
14
use C4::Bookseller;
15
use C4::Biblio;
14
use C4::Biblio;
16
use C4::Budgets;
15
use C4::Budgets;
17
use Koha::DateUtils;
16
use Koha::DateUtils;
17
use Koha::Acquisition::Booksellers;
18
use t::lib::Mocks;
18
use t::lib::Mocks;
19
use Test::More tests => 48;
19
use Test::More tests => 48;
20
20
Lines 32-38 $dbh->{RaiseError} = 1; Link Here
32
my @methods = ('updateClaim');
32
my @methods = ('updateClaim');
33
can_ok('C4::Serials', @methods);
33
can_ok('C4::Serials', @methods);
34
34
35
my $booksellerid = C4::Bookseller::AddBookseller(
35
my $bookseller = Koha::Acquisition::Bookseller->new(
36
    {
36
    {
37
        name => "my vendor",
37
        name => "my vendor",
38
        address1 => "bookseller's address",
38
        address1 => "bookseller's address",
(-)a/t/db_dependent/Serials/Claims.t (-4 / +5 lines)
Lines 2-9 use Modern::Perl; Link Here
2
use Test::More tests => 17;
2
use Test::More tests => 17;
3
3
4
use C4::Acquisition;
4
use C4::Acquisition;
5
use C4::Bookseller;
6
use C4::Budgets;
5
use C4::Budgets;
6
use Koha::Acquisition::Booksellers;
7
use_ok('C4::Serials');
7
use_ok('C4::Serials');
8
8
9
use Koha::DateUtils qw( dt_from_string output_pref );
9
use Koha::DateUtils qw( dt_from_string output_pref );
Lines 74-81 my $sample_supplier2 = { Link Here
74
    deliverytime  => 2
74
    deliverytime  => 2
75
};
75
};
76
76
77
my $supplier_id1 = C4::Bookseller::AddBookseller($sample_supplier1);
77
my $supplier1 = Koha::Acquisition::Bookseller->new($sample_supplier1)->store;
78
my $supplier_id2 = C4::Bookseller::AddBookseller($sample_supplier2);
78
my $supplier2 = Koha::Acquisition::Bookseller->new($sample_supplier2)->store;
79
my $supplier_id1 = $supplier1->id;
80
my $supplier_id2 = $supplier2->id;
79
81
80
my $supplierlist = eval { GetSuppliersWithLateIssues() };
82
my $supplierlist = eval { GetSuppliersWithLateIssues() };
81
is( length($@), 0, "No SQL problem in GetSuppliersWithLateIssues" );
83
is( length($@), 0, "No SQL problem in GetSuppliersWithLateIssues" );
82
- 

Return to bug 13726