From c7942bb34d9ef4f2c73a7379ded5fbb91ca47615 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 17 Feb 2015 14:37:10 +0100 Subject: [PATCH] [SIGNED-OFF] Bug 13726: Make Koha::Acq::Bookseller using Koha::Object This patch create a Koha::Acquisition::Booksellers module and Koha::Acquisition::Bookseller::Contract[s] modules. All code in the acquisition module is adapted to use the CRUD methods of Koha::Object[s]. The former C4 routines are removed. Test plan: Since a lot of files are impacted by this patch, try a complete acquisition workflow and try to catch errors. Be focused on bookseller and bookseller' contacts data. Signed-off-by: Josef Moravec --- C4/Acquisition.pm | 20 +- C4/Bookseller.pm | 138 -------------- C4/Bookseller/Contact.pm | 209 --------------------- Koha/Acquisition/Bookseller.pm | 113 ++--------- Koha/Acquisition/Bookseller/Contact.pm | 13 ++ Koha/Acquisition/Bookseller/Contacts.pm | 19 ++ Koha/Acquisition/Booksellers.pm | 37 ++++ Koha/Object.pm | 1 - acqui/addorderiso2709.pl | 12 +- acqui/basket.pl | 17 +- acqui/basketgroup.pl | 16 +- acqui/basketheader.pl | 8 +- acqui/booksellers.pl | 22 +-- acqui/finishreceive.pl | 5 +- acqui/invoice.pl | 6 +- acqui/invoices.pl | 3 +- acqui/modordernotes.pl | 8 +- acqui/neworderbiblio.pl | 12 +- acqui/neworderempty.pl | 18 +- acqui/newordersubscription.pl | 6 +- acqui/newordersuggestion.pl | 6 +- acqui/orderreceive.pl | 8 +- acqui/parcel.pl | 12 +- acqui/parcels.pl | 6 +- acqui/pdfformat/layout2pages.pm | 12 +- acqui/pdfformat/layout2pagesde.pm | 12 +- acqui/pdfformat/layout3pages.pm | 12 +- acqui/pdfformat/layout3pagesfr.pm | 12 +- acqui/supplier.pl | 38 ++-- acqui/transferorder.pl | 19 +- acqui/uncertainprice.pl | 37 ++-- acqui/updatesupplier.pl | 29 ++- acqui/z3950_search.pl | 6 +- admin/aqcontract.pl | 12 +- admin/currency.pl | 4 +- catalogue/moredetail.pl | 6 +- serials/acqui-search-result.pl | 4 +- serials/subscription-detail.pl | 10 +- t/Prices.t | 50 ++--- t/db_dependent/Acquisition.t | 16 +- t/db_dependent/Acquisition/CancelReceipt.t | 8 +- .../Acquisition/GetBasketsInfosByBookseller.t | 6 +- .../Acquisition/GetOrdersByBiblionumber.t | 7 +- t/db_dependent/Acquisition/Invoices.t | 10 +- t/db_dependent/Acquisition/NewOrder.t | 10 +- t/db_dependent/Acquisition/OrderFromSubscription.t | 11 +- t/db_dependent/Acquisition/OrderUsers.t | 10 +- t/db_dependent/Acquisition/StandingOrders.t | 1 - t/db_dependent/Acquisition/TransferOrder.t | 14 +- t/db_dependent/Acquisition/close_reopen_basket.t | 8 +- t/db_dependent/AdditionalField.t | 10 - t/db_dependent/Bookseller.t | 193 ++++++++++--------- t/db_dependent/Budgets.t | 7 +- t/db_dependent/Contract.t | 8 +- t/db_dependent/Letters.t | 26 ++- t/db_dependent/Serials.t | 4 +- t/db_dependent/Serials/Claims.t | 8 +- 57 files changed, 478 insertions(+), 857 deletions(-) delete mode 100644 C4/Bookseller/Contact.pm create mode 100644 Koha/Acquisition/Bookseller/Contact.pm create mode 100644 Koha/Acquisition/Bookseller/Contacts.pm create mode 100644 Koha/Acquisition/Booksellers.pm diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 6ad5ff7..c113c16 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -29,7 +29,7 @@ use C4::Debug; use C4::Templates qw(gettemplate); use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Acquisition::Order; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; use Koha::Number::Price; use Koha::Libraries; @@ -351,13 +351,13 @@ sub GetBasketGroupAsCSV { my $contract = GetContract({ contractnumber => $basket->{contractnumber} }); - my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} }); + my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} ); my $basketgroup = GetBasketgroup( $$basket{basketgroupid} ); foreach my $order (@orders) { my $bd = GetBiblioData( $order->{'biblionumber'} ); my $row = { - clientnumber => $bookseller->{accountnumber}, + clientnumber => $bookseller->accountnumber, basketname => $basket->{basketname}, ordernumber => $order->{ordernumber}, author => $bd->{author}, @@ -369,14 +369,14 @@ sub GetBasketGroupAsCSV { quantity => $order->{quantity}, rrp_tax_included => $order->{rrp_tax_included}, rrp_tax_excluded => $order->{rrp_tax_excluded}, - discount => $bookseller->{discount}, + discount => $bookseller->discount, ecost_tax_included => $order->{ecost_tax_included}, ecost_tax_excluded => $order->{ecost_tax_excluded}, notes => $order->{order_vendornote}, entrydate => $order->{entrydate}, - booksellername => $bookseller->{name}, - bookselleraddress => $bookseller->{address1}, - booksellerpostal => $bookseller->{postal}, + booksellername => $bookseller->name, + bookselleraddress => $bookseller->address1, + booksellerpostal => $bookseller->postal, contractnumber => $contract->{contractnumber}, contractname => $contract->{contractname}, }; @@ -2868,7 +2868,7 @@ sub populate_order_with_prices { my $booksellerid = $params->{booksellerid}; return unless $booksellerid; - my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); + my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); my $receiving = $params->{receiving}; my $ordering = $params->{ordering}; @@ -2877,7 +2877,7 @@ sub populate_order_with_prices { if ($ordering) { $order->{tax_rate_on_ordering} //= $order->{tax_rate}; - if ( $bookseller->{listincgst} ) { + if ( $bookseller->listincgst ) { # The user entered the rrp tax included $order->{rrp_tax_included} = $order->{rrp}; @@ -2914,7 +2914,7 @@ sub populate_order_with_prices { if ($receiving) { $order->{tax_rate_on_receiving} //= $order->{tax_rate}; - if ( $bookseller->{invoiceincgst} ) { + if ( $bookseller->invoiceincgst ) { # Trick for unitprice. If the unit price rounded value is the same as the ecost rounded value # we need to keep the exact ecost value if ( Koha::Number::Price->new( $order->{unitprice} )->round == Koha::Number::Price->new( $order->{ecost_tax_included} )->round ) { diff --git a/C4/Bookseller.pm b/C4/Bookseller.pm index 8a5f43e..eaf486a 100644 --- a/C4/Bookseller.pm +++ b/C4/Bookseller.pm @@ -23,13 +23,8 @@ use warnings; use base qw( Exporter ); -use C4::Bookseller::Contact; - our @EXPORT_OK = qw( GetBooksellersWithLateOrders - ModBookseller - DelBookseller - AddBookseller ); =head1 NAME @@ -113,139 +108,6 @@ sub GetBooksellersWithLateOrders { return %supplierlist; } -#--------------------------------------------------------------------# - -=head2 AddBookseller - -$id = &AddBookseller($bookseller); - -Creates a new bookseller. C<$bookseller> is a reference-to-hash whose -keys are the fields of the aqbooksellers table in the Koha database. -All fields must be present. - -Returns the ID of the newly-created bookseller. - -=cut - -sub AddBookseller { - my ($data, $contacts) = @_; - my $dbh = C4::Context->dbh; - my $query = q| - INSERT INTO aqbooksellers - ( - name, address1, address2, address3, address4, - postal, phone, accountnumber,fax, url, - active, listprice, invoiceprice, gstreg, - listincgst,invoiceincgst, tax_rate, discount, notes, - deliverytime - ) - VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) | - ; - my $sth = $dbh->prepare($query); - $sth->execute( - $data->{'name'}, $data->{'address1'}, - $data->{'address2'}, $data->{'address3'}, - $data->{'address4'}, $data->{'postal'}, - $data->{'phone'}, $data->{'accountnumber'}, - $data->{'fax'}, $data->{'url'}, - $data->{'active'}, $data->{'listprice'}, - $data->{'invoiceprice'}, $data->{'gstreg'}, - $data->{'listincgst'}, $data->{'invoiceincgst'}, - $data->{'tax_rate'}, $data->{'discount'}, - $data->{notes}, $data->{deliverytime}, - ); - - # return the id of this new supplier - my $id = $dbh->{'mysql_insertid'}; - if ($id && $contacts) { - foreach my $contact (@$contacts) { - $contact = C4::Bookseller::Contact->new( $contact ) - unless ref $contacts eq 'C4::Bookseller::Contact'; - $contact->bookseller($id); - $contact->save(); - } - } - return $id; -} - -#-----------------------------------------------------------------# - -=head2 ModBookseller - -ModBookseller($bookseller); - -Updates the information for a given bookseller. C<$bookseller> is a -reference-to-hash whose keys are the fields of the aqbooksellers table -in the Koha database. It must contain entries for all of the fields. -The entry to modify is determined by C<$bookseller-E{id}>. - -The easiest way to get all of the necessary fields is to look up a -book seller with C, modify what's necessary, then call -C<&ModBookseller> with the result. - -=cut - -sub ModBookseller { - my ($data, $contacts) = @_; - my $dbh = C4::Context->dbh; - return unless $data->{'id'}; - my $query = 'UPDATE aqbooksellers - SET name=?,address1=?,address2=?,address3=?,address4=?, - postal=?,phone=?,accountnumber=?,fax=?,url=?, - active=?,listprice=?, invoiceprice=?, - gstreg=?,listincgst=?,invoiceincgst=?, - discount=?,notes=?,tax_rate=?,deliverytime=? - WHERE id=?'; - my $sth = $dbh->prepare($query); - my $cnt = $sth->execute( - $data->{'name'}, $data->{'address1'}, - $data->{'address2'}, $data->{'address3'}, - $data->{'address4'}, $data->{'postal'}, - $data->{'phone'}, $data->{'accountnumber'}, - $data->{'fax'}, $data->{'url'}, - $data->{'active'}, $data->{'listprice'}, - $data->{'invoiceprice'}, $data->{'gstreg'}, - $data->{'listincgst'}, $data->{'invoiceincgst'}, - $data->{'discount'}, $data->{'notes'}, - $data->{'tax_rate'}, $data->{deliverytime}, - $data->{'id'} - ); - $contacts ||= $data->{'contacts'}; - my $contactquery = "DELETE FROM aqcontacts WHERE booksellerid = ?"; - my @contactparams = ($data->{'id'}); - if ($contacts) { - foreach my $contact (@$contacts) { - $contact = C4::Bookseller::Contact->new( $contact ) - unless ref $contacts eq 'C4::Bookseller::Contact'; - $contact->bookseller($data->{'id'}); - $contact->save(); - push @contactparams, $contact->id if $contact->id; - } - if ($#contactparams > 0) { - $contactquery .= ' AND id NOT IN (' . ('?, ' x ($#contactparams - 1)) . '?);'; - } - } - $sth = $dbh->prepare($contactquery); - $sth->execute(@contactparams); - return $cnt; -} - -=head2 DelBookseller - -DelBookseller($booksellerid); - -delete the supplier record identified by $booksellerid -This sub assumes it is called only if the supplier has no order. - -=cut - -sub DelBookseller { - my $id = shift; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare('DELETE FROM aqbooksellers WHERE id=?'); - return $sth->execute($id); -} - 1; __END__ diff --git a/C4/Bookseller/Contact.pm b/C4/Bookseller/Contact.pm deleted file mode 100644 index a91ecda..0000000 --- a/C4/Bookseller/Contact.pm +++ /dev/null @@ -1,209 +0,0 @@ -package C4::Bookseller::Contact; - -# Copyright 2013 C & P Bibliography Services -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 3 of the License, or (at your option) any later -# version. -# -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -=head1 NAME - -C4::Bookseller::Contact - object class for contacts associated with vendors - -=head1 SYNPOSIS - -This class provides an object-oriented interface for handling vendor contacts. -It uses Class::Accessor to provide access to the following fields: - -=head1 FIELDS - -=over 8 - -=item id - -ID of the contact. This is not used initially, since contacts are actually -stored in the aqbooksellers table. - -=item name - -Contact name. - -=item position - -Contact's position. - -=item phone - -Contact's primary phone number. - -=item altphone - -Contact's alternate phone number. - -=item fax - -Contact's fax number. - -=item email - -Contact's e-mail address. - -=item notes - -Notes about contact. - -=item orderacquisition - -Whether the contact should receive acquisitions orders. - -=item claimacquisition - -Whether the contact should receive acquisitions claims. - -=item claimissues - -Whether the contact should receive serials claims. - -=item acqprimary - -Whether the contact is the primary contact for acquisitions. - -=item serialsprimary - -Whether the contact is the primary contact for serials. - -=item bookseller - -ID of the bookseller the contact is associated with. - -=back - -=cut - -use Modern::Perl; -use C4::Context; - -use base qw(Class::Accessor); - -__PACKAGE__->mk_accessors(qw(id name position phone altphone fax email notes orderacquisition claimacquisition claimissues acqprimary serialsprimary bookseller)); - -=head1 METHODS - -=head2 get_from_bookseller - - my @contacts = @{C4::Bookseller::Contact->get_from_bookseller($booksellerid)}; - -Returns a reference to an array of C4::Bookseller::Contact objects for the -specified bookseller. This will always return at least one item, though that one -item may be an empty contact. - -=cut - -sub get_from_bookseller { - my ($class, $bookseller) = @_; - - return unless $bookseller; - - my @contacts; - my $query = "SELECT * FROM aqcontacts WHERE booksellerid = ?"; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare($query); - $sth->execute($bookseller); - while (my $rec = $sth->fetchrow_hashref()) { - push @contacts, $class->new($rec); - } - - push @contacts, $class->new() unless @contacts; - - return \@contacts; -} - - -=head2 fetch - - my $contact = C4::Bookseller::Contact->fetch($contactid); - -Retrieves the specified contact from the database. Currently commented out -because there is no separate table from which contacts can be fetched. - -=cut - -sub fetch { - my ($class, $id) = @_; - - my $rec = { }; - if ($id) { - my $query = "SELECT * FROM aqcontacts WHERE id = ?"; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare($query); - $sth->execute($id); - $rec = $sth->fetchrow_hashref(); - } - my $self = $class->new($rec); - bless $self, $class; - return $self; -} - -=head2 save - - $contact->save(); - -Save a contact to the database. - -=cut - -sub save { - my ($self) = @_; - - my $query; - my @params = ( - $self->name, $self->position, - $self->phone, $self->altphone, - $self->fax, $self->email, - $self->notes, $self->acqprimary ? 1 : 0, - $self->serialsprimary ? 1 : 0, - $self->orderacquisition ? 1 : 0, $self->claimacquisition ? 1 : 0, - $self->claimissues ? 1 : 0, $self->bookseller - ); - if ($self->id) { - $query = 'UPDATE aqcontacts SET name = ?, position = ?, phone = ?, altphone = ?, fax = ?, email = ?, notes = ?, acqprimary = ?, serialsprimary = ?, orderacquisition = ?, claimacquisition = ?, claimissues = ?, booksellerid = ? WHERE id = ?;'; - push @params, $self->id; - } else { - $query = 'INSERT INTO aqcontacts (name, position, phone, altphone, fax, email, notes, acqprimary, serialsprimary, orderacquisition, claimacquisition, claimissues, booksellerid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);'; - } - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare($query); - $sth->execute(@params); - $self->id($dbh->{'mysql_insertid'}) unless $self->id; - return $self->id; -} - -sub delete { - my ($self) = @_; - - return unless $self->id; - - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("DELETE FROM aqcontacts WHERE id = ?;"); - $sth->execute($self->id); - return; -} - -=head1 AUTHOR - -Jared Camins-Esakov - -=cut - -1; diff --git a/Koha/Acquisition/Bookseller.pm b/Koha/Acquisition/Bookseller.pm index 57a6113..e32b010 100644 --- a/Koha/Acquisition/Bookseller.pm +++ b/Koha/Acquisition/Bookseller.pm @@ -3,120 +3,31 @@ package Koha::Acquisition::Bookseller; use Modern::Perl; use Koha::Database; -use Koha::DateUtils qw( dt_from_string output_pref ); - -use Carp qw( croak ); - -use base qw( Class::Accessor ); - -use C4::Bookseller::Contact; - -sub fetch { - my ( $class, $params ) = @_; - my $id = $params->{id}; - return unless $id; - my $schema = Koha::Database->new->schema; - - my $bookseller = - $schema->resultset('Aqbookseller')->find( { id => $id }, - { result_class => 'DBIx::Class::ResultClass::HashRefInflator' } ); - - return unless $bookseller; - - my $self = $class->new( $bookseller ); - $self->contacts; # TODO: This should be generated on demand. - return $self; -} - -sub search { - my ( $class, $params ) = @_; - - my $schema = Koha::Database->new->schema; - - my $search_params; - while ( my ( $field, $value ) = each %$params ) { - if ( $field eq 'name' ) { - # Use "like" if search on name - $search_params->{name} = { -like => "%$value%" }; - } else { - $search_params->{$field} = $value; - } - } - my $rs = $schema->resultset('Aqbookseller')->search( - $search_params, - { order_by => 'name' } - ); - - my @booksellers; - while ( my $b = $rs->next ) { - my $t = Koha::Acquisition::Bookseller->fetch({ id => $b->id }); - push @booksellers, $t; - } - return @booksellers; -} +use base qw( Koha::Object ); -sub basket_count { - my ( $self ) = @_; - my $schema = Koha::Database->new->schema; +use Koha::DateUtils qw( dt_from_string output_pref ); - return $schema->resultset('Aqbasket')->count( { booksellerid => $self->{id} }); -} +use Koha::Acquisition::Bookseller::Contacts; +use Koha::Subscriptions; -sub subscription_count { +sub baskets { my ( $self ) = @_; - - my $schema = Koha::Database->new->schema; - - return $schema->resultset('Subscription')->count( { aqbooksellerid => $self->{id} }); + return $self->{_result}->aqbaskets; } sub contacts { - my ( $self ) = @_; - - return $self->{contacts} if $self->{contacts}; - $self->{contacts} = C4::Bookseller::Contact->get_from_bookseller($self->{id}); - return $self->{contacts}; + my ($self) = @_; + return Koha::Acquisition::Bookseller::Contacts->search( { booksellerid => $self->id } ); } -sub insert { +sub subscriptions { my ($self) = @_; - # if these parameters are missing, we can't continue - for my $key (qw( id )) { - croak "Cannot insert bookseller: Mandatory parameter $key is missing" - unless $self->{$key}; - } - - $self->{quantityreceived} ||= 0; - $self->{entrydate} ||= - output_pref( { dt => dt_from_string, dateformat => 'iso' } ); - - my $schema = Koha::Database->new->schema; - my @columns = $schema->source('Aqorder')->columns; - my $rs = $schema->resultset('Aqorder')->create( - { - map { - exists $self->{$_} ? ( $_ => $self->{$_} ) : () - } @columns - } - ); - $self->{ordernumber} = $rs->id; - - unless ( $self->{parent_ordernumber} ) { - $rs->update( { parent_ordernumber => $self->{ordernumber} } ); - } - - return $self; -} - -# TODO Move code from ModBookseller -sub update { - die "not implemented yet"; + return Koha::Subscriptions->search( { aqbooksellerid => $self->id } ); } -# TODO Move code from DelBookseller -sub delete { - die "not implemented yet"; +sub _type { + return 'Aqbookseller'; } 1; diff --git a/Koha/Acquisition/Bookseller/Contact.pm b/Koha/Acquisition/Bookseller/Contact.pm new file mode 100644 index 0000000..61da32e --- /dev/null +++ b/Koha/Acquisition/Bookseller/Contact.pm @@ -0,0 +1,13 @@ +package Koha::Acquisition::Bookseller::Contact; + +use Modern::Perl; + +use base qw( Koha::Object ); + +use Carp qw( croak ); + +sub _type { + return 'Aqcontact'; +} + +1; diff --git a/Koha/Acquisition/Bookseller/Contacts.pm b/Koha/Acquisition/Bookseller/Contacts.pm new file mode 100644 index 0000000..053e7a6 --- /dev/null +++ b/Koha/Acquisition/Bookseller/Contacts.pm @@ -0,0 +1,19 @@ +package Koha::Acquisition::Bookseller::Contacts; + +use Modern::Perl; + +use Carp; + +use base qw( Koha::Objects ); + +use Koha::Acquisition::Bookseller::Contact; + +sub _type { + return 'Aqcontact'; +} + +sub object_class { + return 'Koha::Acquisition::Bookseller::Contact'; +} + +1; diff --git a/Koha/Acquisition/Booksellers.pm b/Koha/Acquisition/Booksellers.pm new file mode 100644 index 0000000..5fa3540 --- /dev/null +++ b/Koha/Acquisition/Booksellers.pm @@ -0,0 +1,37 @@ +package Koha::Acquisition::Booksellers; + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use base qw( Koha::Objects ); + +use Koha::Acquisition::Bookseller; + +sub search { + my ( $self, $params, $attributes ) = @_; + + + while ( my ( $field, $value ) = each %$params ) { + if ( $field eq 'name' ) { + # Use "like" if search on name + $params->{name} = { -like => "%$value%" }; + } + } + + $attributes->{order_by} ||= { -asc => 'name' }; + + return $self->SUPER::search( $params, $attributes ); +} + +sub _type { + return 'Aqbookseller'; +} + +sub object_class { + return 'Koha::Acquisition::Bookseller'; +} + +1; diff --git a/Koha/Object.pm b/Koha/Object.pm index a9e35ba..c191358 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -221,7 +221,6 @@ sub _columns { return $self->{_columns}; } - =head3 AUTOLOAD The autoload method is used only to get and set values for an objects properties. diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index 74ea8e2..b64ddad 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -44,7 +44,7 @@ use C4::Members; use Koha::Number::Price; use Koha::Acquisition::Currencies; use Koha::Acquisition::Order; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; my $input = new CGI; my ($template, $loggedinuser, $cookie, $userflags) = get_template_and_user({ @@ -60,11 +60,11 @@ my $cgiparams = $input->Vars; my $op = $cgiparams->{'op'} || ''; my $booksellerid = $input->param('booksellerid'); my $allmatch = $input->param('allmatch'); -my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); $template->param(scriptname => "/cgi-bin/koha/acqui/addorderiso2709.pl", booksellerid => $booksellerid, - booksellername => $bookseller->{name}, + booksellername => $bookseller->name, ); if ($cgiparams->{'import_batch_id'} && $op eq ""){ @@ -218,9 +218,9 @@ if ($op eq ""){ # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation $price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR"; $price = Koha::Number::Price->new($price)->unformat; - $orderinfo{tax_rate} = $bookseller->{tax_rate}; - my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100; - if ( $bookseller->{listincgst} ) { + $orderinfo{tax_rate} = $bookseller->tax_rate; + my $c = $c_discount ? $c_discount : $bookseller->discount / 100; + if ( $bookseller->listincgst ) { if ( $c_discount ) { $orderinfo{ecost} = $price; $orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c ); diff --git a/acqui/basket.pl b/acqui/basket.pl index ca2d2d2..1aed6b3 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -33,6 +33,7 @@ use C4::Biblio; use C4::Members qw/GetMember/; #needed for permissions checking for changing basketgroup of a basket use C4::Items; use C4::Suggestions; +use Koha::Acquisition::Booksellers; use Koha::Libraries; use C4::Letters qw/SendAlerts/; use Date::Calc qw/Add_Delta_Days/; @@ -86,7 +87,7 @@ my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( my $basket = GetBasket($basketno); $booksellerid = $basket->{booksellerid} unless $booksellerid; -my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); my $schema = Koha::Database->new()->schema(); my $rs = $schema->resultset('VendorEdiAccount')->search( { vendor_id => $booksellerid, } ); @@ -98,7 +99,7 @@ unless (CanUserManageBasket($loggedinuser, $basket, $userflags)) { basketno => $basketno, basketname => $basket->{basketname}, booksellerid => $booksellerid, - name => $bookseller->{name} + name => $bookseller->name, ); output_html_with_http_headers $query, $cookie, $template->output; exit; @@ -293,7 +294,7 @@ if ( $op eq 'list' ) { my $estimateddeliverydate; if( $basket->{closedate} ) { my ($year, $month, $day) = ($basket->{closedate} =~ /(\d+)-(\d+)-(\d+)/); - ($year, $month, $day) = Add_Delta_Days($year, $month, $day, $bookseller->{deliverytime}); + ($year, $month, $day) = Add_Delta_Days($year, $month, $day, $bookseller->deliverytime); $estimateddeliverydate = sprintf( "%04d-%02d-%02d", $year, $month, $day ); } @@ -395,9 +396,9 @@ if ( $op eq 'list' ) { is_standing => $basket->{is_standing}, deliveryplace => $basket->{deliveryplace}, billingplace => $basket->{billingplace}, - active => $bookseller->{'active'}, - booksellerid => $bookseller->{'id'}, - name => $bookseller->{'name'}, + active => $bookseller->active, + booksellerid => $bookseller->id, + name => $bookseller->name, books_loop => \@books_loop, book_foot_loop => \@book_foot_loop, cancelledorders_loop => \@cancelledorders_loop, @@ -406,7 +407,7 @@ if ( $op eq 'list' ) { total_tax_included => $total_tax_included, total_tax_value => $total_tax_value, currency => $active_currency->currency, - listincgst => $bookseller->{listincgst}, + listincgst => $bookseller->listincgst, basketgroups => $basketgroups, basketgroup => $basketgroup, grouped => $basket->{basketgroupid}, @@ -491,7 +492,7 @@ sub get_order_infos { foreach my $key (qw(transferred_from transferred_to)) { if ($line{$key}) { my $order = GetOrder($line{$key}); - my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} }); + my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} ); $line{$key} = { order => $order, basket => $basket, diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index 9ad5482..bd4c6bf 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -55,7 +55,7 @@ use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsBy use C4::Members qw/GetMember/; use Koha::EDI qw/create_edi_order get_edifact_ean/; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; our $input=new CGI; @@ -75,13 +75,13 @@ sub BasketTotal { my @orders = GetOrders($basketno); for my $order (@orders){ # FIXME The following is wrong - if ( $bookseller->{listincgst} ) { + if ( $bookseller->listincgst ) { $total = $total + ( $order->{ecost_tax_included} * $order->{quantity} ); } else { $total = $total + ( $order->{ecost_tax_excluded} * $order->{quantity} ); } } - $total .= " " . ($bookseller->{invoiceprice} // 0); + $total .= " " . ($bookseller->invoiceprice // 0); return $total; } @@ -118,7 +118,7 @@ sub displaybasketgroups { } } $template->param(baskets => $baskets); - $template->param( booksellername => $bookseller ->{'name'}); + $template->param( booksellername => $bookseller->name); } sub printbasketgrouppdf{ @@ -143,7 +143,7 @@ sub printbasketgrouppdf{ } my $basketgroup = GetBasketgroup($basketgroupid); - my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basketgroup->{booksellerid} }); + my $bookseller = Koha::Acquisition::Booksellers->find( $basketgroup->{booksellerid} ); my $baskets = GetBasketsByBasketgroup($basketgroupid); my %orders; @@ -206,7 +206,7 @@ sub printbasketgrouppdf{ -type => 'application/pdf', -attachment => ( $basketgroup->{name} || $basketgroupid ) . '.pdf' ); - my $pdf = printpdf($basketgroup, $bookseller, $baskets, \%orders, $bookseller->{tax_rate} // C4::Context->preference("gist")) || die "pdf generation failed"; + my $pdf = printpdf($basketgroup, $bookseller, $baskets, \%orders, $bookseller->tax_rate // C4::Context->preference("gist")) || die "pdf generation failed"; print $pdf; } @@ -243,7 +243,7 @@ if ( $op eq "add" ) { # else, edit (if it is open) or display (if it is close) the basketgroup basketgroupid # the template will know if basketgroup must be displayed or edited, depending on the value of closed key # - my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); + my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); my $basketgroupid = $input->param('basketgroupid'); my $billingplace; my $deliveryplace; @@ -392,7 +392,7 @@ if ( $op eq "add" ) { }else{ # no param : display the list of all basketgroups for a given vendor my $basketgroups = &GetBasketgroups($booksellerid); - my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); + my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); my $baskets = &GetBasketsByBookseller($booksellerid); displaybasketgroups($basketgroups, $bookseller, $baskets); diff --git a/acqui/basketheader.pl b/acqui/basketheader.pl index c0db854..8cfde89 100755 --- a/acqui/basketheader.pl +++ b/acqui/basketheader.pl @@ -54,7 +54,7 @@ use C4::Output; use C4::Acquisition qw/GetBasket NewBasket ModBasketHeader/; use C4::Contract qw/GetContracts/; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; my $input = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -104,18 +104,18 @@ if ( $op eq 'add_form' ) { }); push(@contractloop, @$contracts); } - my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); + my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); my $count = scalar @contractloop; if ( $count > 0) { $template->param(contractloop => \@contractloop, basketcontractnumber => $basket->{'contractnumber'}); } - my @booksellers = Koha::Acquisition::Bookseller->search; + my @booksellers = Koha::Acquisition::Booksellers->search; $template->param( add_form => 1, basketname => $basket->{'basketname'}, basketnote => $basket->{'note'}, basketbooksellernote => $basket->{'booksellernote'}, - booksellername => $bookseller->{'name'}, + booksellername => $bookseller->name, booksellerid => $booksellerid, basketno => $basketno, booksellers => \@booksellers, diff --git a/acqui/booksellers.pl b/acqui/booksellers.pl index b56f73e..a4d010f 100755 --- a/acqui/booksellers.pl +++ b/acqui/booksellers.pl @@ -63,7 +63,7 @@ use C4::Acquisition qw/ GetBasketsInfosByBookseller CanUserManageBasket /; use C4::Members qw/GetMember/; use C4::Context; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; my $query = CGI->new; my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( @@ -83,18 +83,18 @@ my $allbaskets= $query->param('allbaskets')||0; my @suppliers; if ($booksellerid) { - push @suppliers, Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); + push @suppliers, Koha::Acquisition::Booksellers->find( $booksellerid ); } else { - @suppliers = Koha::Acquisition::Bookseller->search({ name => $supplier }); + @suppliers = Koha::Acquisition::Booksellers->search({ name => $supplier }); } my $supplier_count = @suppliers; if ( $supplier_count == 1 ) { $template->param( - supplier_name => $suppliers[0]->{'name'}, - booksellerid => $suppliers[0]->{'id'}, - basketcount => $suppliers[0]->{'basketcount'}, - active => $suppliers[0]->{active}, + supplier_name => $suppliers[0]->name, + booksellerid => $suppliers[0]->id, + basketcount => $suppliers[0]->baskets->count, + active => $suppliers[0]->active, ); } @@ -124,7 +124,7 @@ foreach my $r (@{$budgets}) { my $loop_suppliers = []; for my $vendor (@suppliers) { - my $baskets = GetBasketsInfosByBookseller( $vendor->{id}, $allbaskets ); + my $baskets = GetBasketsInfosByBookseller( $vendor->id, $allbaskets ); my $loop_basket = []; @@ -150,9 +150,9 @@ for my $vendor (@suppliers) { push @{$loop_suppliers}, { loop_basket => $loop_basket, - booksellerid => $vendor->{id}, - name => $vendor->{name}, - active => $vendor->{active}, + booksellerid => $vendor->id, + name => $vendor->name, + active => $vendor->active, }; } diff --git a/acqui/finishreceive.pl b/acqui/finishreceive.pl index 10a0e0c..18220e6 100755 --- a/acqui/finishreceive.pl +++ b/acqui/finishreceive.pl @@ -28,11 +28,10 @@ use C4::Output; use C4::Context; use C4::Acquisition; use C4::Biblio; -use C4::Bookseller; use C4::Items; use C4::Search; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; use List::MoreUtils qw/any/; @@ -84,8 +83,6 @@ if ($quantityrec > $origquantityrec ) { $order->{tax_rate_on_receiving} = $input->param("tax_rate"); $order->{unitprice} = $unitprice; - my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); - $order = C4::Acquisition::populate_order_with_prices( { order => $order, diff --git a/acqui/invoice.pl b/acqui/invoice.pl index 66f3c58..9906341 100755 --- a/acqui/invoice.pl +++ b/acqui/invoice.pl @@ -35,7 +35,7 @@ use C4::Output; use C4::Acquisition; use C4::Budgets; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; use Koha::Acquisition::Currencies; use Koha::DateUtils; use Koha::Misc::Files; @@ -112,7 +112,7 @@ elsif ( $op && $op eq 'delete' ) { my $details = GetInvoiceDetails($invoiceid); -my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $details->{booksellerid} }); +my $bookseller = Koha::Acquisition::Booksellers->find( $details->{booksellerid} ); my @orders_loop = (); my $orders = $details->{'orders'}; my @foot_loop; @@ -177,7 +177,7 @@ $template->param( total_tax_value => $total_tax_value, total_tax_excluded_shipment => $total_tax_excluded + $details->{shipmentcost}, total_tax_included_shipment => $total_tax_included + $details->{shipmentcost}, - invoiceincgst => $bookseller->{invoiceincgst}, + invoiceincgst => $bookseller->invoiceincgst, currency => Koha::Acquisition::Currencies->get_active, budgets_loop => \@budgets_loop, ); diff --git a/acqui/invoices.pl b/acqui/invoices.pl index 7f0ed5d..c060cfd 100755 --- a/acqui/invoices.pl +++ b/acqui/invoices.pl @@ -36,6 +36,7 @@ use C4::Output; use C4::Acquisition qw/GetInvoices/; use C4::Budgets; use Koha::DateUtils; +use Koha::Acquisition::Booksellers; my $input = CGI->new; my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( @@ -89,7 +90,7 @@ if ( $op and $op eq 'do_search' ) { } # Build suppliers list -my @suppliers = Koha::Acquisition::Bookseller->search; +my @suppliers = Koha::Acquisition::Booksellers->search; my $suppliers_loop = []; my $suppliername; foreach (@suppliers) { diff --git a/acqui/modordernotes.pl b/acqui/modordernotes.pl index a1008f0..d0bd672 100755 --- a/acqui/modordernotes.pl +++ b/acqui/modordernotes.pl @@ -33,7 +33,7 @@ use C4::Auth; use C4::Output; use C4::Acquisition; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; my $input = new CGI; my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( { @@ -51,7 +51,7 @@ my $referrer = $input->param('referrer') || $input->referer(); my $type = $input->param('type'); my $order = GetOrder($ordernumber); my $basket = GetBasket($order->{basketno}); -my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} }); +my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} ); if($op and $op eq 'save') { @@ -79,8 +79,8 @@ if($op) { $template->param( basketname => $basket->{'basketname'}, basketno => $order->{basketno}, - booksellerid => $bookseller->{'id'}, - booksellername => $bookseller->{'name'}, + booksellerid => $bookseller->id, + booksellername => $bookseller->name, ordernumber => $ordernumber, referrer => $referrer, type => $type, diff --git a/acqui/neworderbiblio.pl b/acqui/neworderbiblio.pl index 01fb1e2..8c492b7 100755 --- a/acqui/neworderbiblio.pl +++ b/acqui/neworderbiblio.pl @@ -67,7 +67,7 @@ use C4::Koha; use C4::Members qw/ GetMember /; use C4::Budgets qw/ GetBudgetHierarchy /; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; use Koha::SearchEngine; use Koha::SearchEngine::Search; use Koha::SearchEngine::QueryBuilder; @@ -83,7 +83,7 @@ my $results_per_page = $params->{'num'} || 20; my $booksellerid = $params->{'booksellerid'}; my $basketno = $params->{'basketno'}; my $sub = $params->{'sub'}; -my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); # getting the template my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -115,8 +115,8 @@ if (defined $error) { $template->param( query_error => $error, basketno => $basketno, - booksellerid => $bookseller->{'id'}, - name => $bookseller->{'name'}, + booksellerid => $bookseller->id, + name => $bookseller->name, ); output_html_with_http_headers $input, $cookie, $template->output; exit; @@ -147,8 +147,8 @@ foreach my $r (@{$budgets}) { $template->param( has_budgets => $has_budgets, basketno => $basketno, - booksellerid => $bookseller->{'id'}, - name => $bookseller->{'name'}, + booksellerid => $bookseller->id, + name => $bookseller->name, resultsloop => \@results, total => $total_hits, query => $query, diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index 57a22e4..b76b4f4 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -87,7 +87,7 @@ use C4::Search qw/FindDuplicate/; #needed for z3950 import: use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; use Koha::Acquisition::Currencies; use Koha::ItemTypes; @@ -130,7 +130,7 @@ if(!$basketno) { our $basket = GetBasket($basketno); $booksellerid = $basket->{booksellerid} unless $booksellerid; -my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); my $contract = GetContract({ contractnumber => $basket->{contractnumber} @@ -320,20 +320,20 @@ $template->param( firstnamesuggestedby => $suggestion->{firstnamesuggestedby}, biblionumber => $biblionumber, uncertainprice => $data->{'uncertainprice'}, - discount_2dp => sprintf( "%.2f", $bookseller->{'discount'} ) , # for display - discount => $bookseller->{'discount'}, + discount_2dp => sprintf( "%.2f", $bookseller->discount ) , # for display + discount => $bookseller->discount, orderdiscount_2dp => sprintf( "%.2f", $data->{'discount'} || 0 ), orderdiscount => $data->{'discount'}, order_internalnote => $data->{'order_internalnote'}, order_vendornote => $data->{'order_vendornote'}, - listincgst => $bookseller->{'listincgst'}, - invoiceincgst => $bookseller->{'invoiceincgst'}, - name => $bookseller->{'name'}, + listincgst => $bookseller->listincgst, + invoiceincgst => $bookseller->invoiceincgst, + name => $bookseller->name, cur_active_sym => $active_currency->symbol, cur_active => $active_currency->currency, currencies => \@currencies, currency => $data->{currency}, - vendor_currency => $bookseller->{listprice}, + vendor_currency => $bookseller->listprice, orderexists => ( $new eq 'yes' ) ? 0 : 1, title => $data->{'title'}, author => $data->{'author'}, @@ -348,7 +348,7 @@ $template->param( quantityrec => $quantity, rrp => $data->{'rrp'}, gst_values => \@gst_values, - tax_rate => $data->{tax_rate_on_ordering} ? $data->{tax_rate_on_ordering}+0.0 : $bookseller->{tax_rate} ? $bookseller->{tax_rate}+0.0 : 0, + tax_rate => $data->{tax_rate_on_ordering} ? $data->{tax_rate_on_ordering}+0.0 : $bookseller->tax_rate ? $bookseller->tax_rate+0.0 : 0, listprice => sprintf( "%.2f", $data->{listprice} || $data->{price} || $listprice), total => sprintf( "%.2f", ($data->{ecost} || 0) * ($data->{'quantity'} || 0) ), ecost => sprintf( "%.2f", $data->{ecost} || 0), diff --git a/acqui/newordersubscription.pl b/acqui/newordersubscription.pl index 81bc18d..51151af 100755 --- a/acqui/newordersubscription.pl +++ b/acqui/newordersubscription.pl @@ -25,7 +25,7 @@ use C4::Context; use C4::Output; use C4::Serials; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; my $query = new CGI; my $title = $query->param('title_filter'); @@ -52,7 +52,7 @@ my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( my $basket = GetBasket($basketno); $booksellerid = $basket->{booksellerid} unless $booksellerid; -my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); my @subscriptions; if ($searched) { @@ -88,6 +88,6 @@ $template->param( booksellerid => $booksellerid, basketno => $basket->{basketno}, basketname => $basket->{basketname}, - booksellername => $bookseller->{name}, + booksellername => $bookseller->name, ); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/acqui/newordersuggestion.pl b/acqui/newordersuggestion.pl index a0e88e9..c182ed3 100755 --- a/acqui/newordersuggestion.pl +++ b/acqui/newordersuggestion.pl @@ -97,7 +97,7 @@ use C4::Output; use C4::Suggestions; use C4::Biblio; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; my $input = new CGI; @@ -137,12 +137,12 @@ my $suggestions_loop = SearchSuggestion( STATUS => 'ACCEPTED' } ); -my $vendor = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +my $vendor = Koha::Acquisition::Booksellers->find( $booksellerid ); $template->param( suggestions_loop => $suggestions_loop, basketno => $basketno, booksellerid => $booksellerid, - name => $vendor->{'name'}, + name => $vendor->name, loggedinuser => $borrowernumber, "op_$op" => 1, ); diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl index 0e302bd..b8be537 100755 --- a/acqui/orderreceive.pl +++ b/acqui/orderreceive.pl @@ -73,7 +73,7 @@ use C4::Items; use C4::Biblio; use C4::Suggestions; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; use Koha::DateUtils qw( dt_from_string ); my $input = new CGI; @@ -85,7 +85,7 @@ my $booksellerid = $invoice->{booksellerid}; my $freight = $invoice->{shipmentcost}; my $ordernumber = $input->param('ordernumber'); -my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); my $results; $results = SearchOrders({ ordernumber => $ordernumber @@ -155,7 +155,7 @@ $order->{quantityreceived} = '' if $order->{quantityreceived} == 0; my $unitprice = $order->{unitprice}; my ( $rrp, $ecost ); -if ( $bookseller->{invoiceincgst} ) { +if ( $bookseller->invoiceincgst ) { $rrp = $order->{rrp_tax_included}; $ecost = $order->{ecost_tax_included}; unless ( $unitprice != 0 and defined $unitprice) { @@ -198,7 +198,7 @@ $template->param( subscriptionid => $order->{subscriptionid}, booksellerid => $order->{'booksellerid'}, freight => $freight, - name => $bookseller->{'name'}, + name => $bookseller->name, title => $order->{'title'}, author => $order->{'author'}, copyrightdate => $order->{'copyrightdate'}, diff --git a/acqui/parcel.pl b/acqui/parcel.pl index 65be105..8641e53 100755 --- a/acqui/parcel.pl +++ b/acqui/parcel.pl @@ -67,7 +67,7 @@ use C4::Output; use C4::Suggestions; use C4::Reserves qw/GetReservesFromBiblionumber/; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; use Koha::DateUtils; use JSON; @@ -110,7 +110,7 @@ unless( $invoiceid and $invoice->{invoiceid} ) { } my $booksellerid = $invoice->{booksellerid}; -my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); my @orders = @{ $invoice->{orders} }; my $countlines = scalar @orders; @@ -124,7 +124,7 @@ my $subtotal_for_funds; for my $order ( @orders ) { $order->{'unitprice'} += 0; - if ( $bookseller->{invoiceincgst} ) { + if ( $bookseller->invoiceincgst ) { $order->{ecost} = $order->{ecost_tax_included}; $order->{unitprice} = $order->{unitprice_tax_included}; } @@ -222,7 +222,7 @@ unless( defined $invoice->{closedate} ) { for (my $i = 0 ; $i < $countpendings ; $i++) { my $order = $pendingorders->[$i]; - if ( $bookseller->{invoiceincgst} ) { + if ( $bookseller->invoiceincgst ) { $order->{ecost} = $order->{ecost_tax_included}; } else { $order->{ecost} = $order->{ecost_tax_excluded}; @@ -283,8 +283,8 @@ $template->param( invoice => $invoice->{invoicenumber}, invoiceclosedate => $invoice->{closedate}, datereceived => dt_from_string, - name => $bookseller->{'name'}, - booksellerid => $bookseller->{id}, + name => $bookseller->name, + booksellerid => $bookseller->id, loop_received => \@loop_received, loop_orders => \@loop_orders, book_foot_loop => \@book_foot_loop, diff --git a/acqui/parcels.pl b/acqui/parcels.pl index ffcbb66..85da683 100755 --- a/acqui/parcels.pl +++ b/acqui/parcels.pl @@ -75,7 +75,7 @@ use C4::Output; use C4::Acquisition; use C4::Budgets; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; use Koha::DateUtils qw( output_pref dt_from_string ); my $input = CGI->new; @@ -139,7 +139,7 @@ if ($op and $op eq 'confirm') { } } -my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); my @parcels = GetInvoices( supplierid => $booksellerid, invoicenumber => $code, @@ -203,7 +203,7 @@ $template->param( datefrom => $datefrom, dateto => $dateto, resultsperpage => $resultsperpage, - name => $bookseller->{'name'}, + name => $bookseller->name, shipmentdate_today => dt_from_string, booksellerid => $booksellerid, GST => C4::Context->preference('gist'), diff --git a/acqui/pdfformat/layout2pages.pm b/acqui/pdfformat/layout2pages.pm index d2fd2cd..7e7bc3d 100644 --- a/acqui/pdfformat/layout2pages.pm +++ b/acqui/pdfformat/layout2pages.pm @@ -199,17 +199,17 @@ sub printhead { # print bookseller infos $text->translate(100/mm, ($height-180)/mm); - $text->text($bookseller->{name}); + $text->text($bookseller->name); $text->translate(100/mm, ($height-185)/mm); - $text->text($bookseller->{postal}); + $text->text($bookseller->postal); $text->translate(100/mm, ($height-190)/mm); - $text->text($bookseller->{address1}); + $text->text($bookseller->address1); $text->translate(100/mm, ($height-195)/mm); - $text->text($bookseller->{address2}); + $text->text($bookseller->address2); $text->translate(100/mm, ($height-200)/mm); - $text->text($bookseller->{address3}); + $text->text($bookseller->address3); $text->translate(100/mm, ($height-205)/mm); - $text->text($bookseller->{accountnumber}); + $text->text($bookseller->accountnumber); # print delivery infos $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm ); diff --git a/acqui/pdfformat/layout2pagesde.pm b/acqui/pdfformat/layout2pagesde.pm index f51599b..08924d3 100644 --- a/acqui/pdfformat/layout2pagesde.pm +++ b/acqui/pdfformat/layout2pagesde.pm @@ -199,17 +199,17 @@ sub printhead { # print bookseller infos $text->translate(100/mm, ($height-180)/mm); - $text->text($bookseller->{name}); + $text->text($bookseller->name); $text->translate(100/mm, ($height-185)/mm); - $text->text($bookseller->{postal}); + $text->text($bookseller->postal); $text->translate(100/mm, ($height-190)/mm); - $text->text($bookseller->{address1}); + $text->text($bookseller->address1); $text->translate(100/mm, ($height-195)/mm); - $text->text($bookseller->{address2}); + $text->text($bookseller->address2); $text->translate(100/mm, ($height-200)/mm); - $text->text($bookseller->{address3}); + $text->text($bookseller->address3); $text->translate(100/mm, ($height-205)/mm); - $text->text($bookseller->{accountnumber}); + $text->text($bookseller->accountnumber); # print delivery infos $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm ); diff --git a/acqui/pdfformat/layout3pages.pm b/acqui/pdfformat/layout3pages.pm index e91d1e6..f825ed3 100644 --- a/acqui/pdfformat/layout3pages.pm +++ b/acqui/pdfformat/layout3pages.pm @@ -365,17 +365,17 @@ sub printhead { # print bookseller infos $text->translate(100/mm, ($height-180)/mm); - $text->text($bookseller->{name}); + $text->text($bookseller->name); $text->translate(100/mm, ($height-185)/mm); - $text->text($bookseller->{postal}); + $text->text($bookseller->postal); $text->translate(100/mm, ($height-190)/mm); - $text->text($bookseller->{address1}); + $text->text($bookseller->address1); $text->translate(100/mm, ($height-195)/mm); - $text->text($bookseller->{address2}); + $text->text($bookseller->address2); $text->translate(100/mm, ($height-200)/mm); - $text->text($bookseller->{address3}); + $text->text($bookseller->address3); $text->translate(100/mm, ($height-205)/mm); - $text->text($bookseller->{accountnumber}); + $text->text($bookseller->accountnumber); # print delivery infos $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm ); diff --git a/acqui/pdfformat/layout3pagesfr.pm b/acqui/pdfformat/layout3pagesfr.pm index 8b9bc20..14b0cc0 100644 --- a/acqui/pdfformat/layout3pagesfr.pm +++ b/acqui/pdfformat/layout3pagesfr.pm @@ -365,17 +365,17 @@ sub printhead { # print bookseller infos $text->translate(100/mm, ($height-180)/mm); - $text->text($bookseller->{name}); + $text->text($bookseller->name); $text->translate(100/mm, ($height-185)/mm); - $text->text($bookseller->{postal}); + $text->text($bookseller->postal); $text->translate(100/mm, ($height-190)/mm); - $text->text($bookseller->{address1}); + $text->text($bookseller->address1); $text->translate(100/mm, ($height-195)/mm); - $text->text($bookseller->{address2}); + $text->text($bookseller->address2); $text->translate(100/mm, ($height-200)/mm); - $text->text($bookseller->{address3}); + $text->text($bookseller->address3); $text->translate(100/mm, ($height-205)/mm); - $text->text($bookseller->{accountnumber}); + $text->text($bookseller->accountnumber); # print delivery infos $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm ); diff --git a/acqui/supplier.pl b/acqui/supplier.pl index d37bd72..e0addbc 100755 --- a/acqui/supplier.pl +++ b/acqui/supplier.pl @@ -48,11 +48,10 @@ use C4::Biblio; use C4::Output; use CGI qw ( -utf8 ); -use C4::Bookseller qw( DelBookseller ); -use C4::Bookseller::Contact; use C4::Budgets; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Bookseller::Contacts; +use Koha::Acquisition::Booksellers; use Koha::Acquisition::Currencies; my $query = CGI->new; @@ -67,33 +66,36 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); my $booksellerid = $query->param('booksellerid'); -my $supplier = {}; +my $supplier; if ($booksellerid) { - $supplier = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); - foreach ( keys %{$supplier} ) { - $template->{'VARS'}->{$_} = $supplier->{$_}; + $supplier = Koha::Acquisition::Booksellers->find( $booksellerid ); + my $supplier_hashref = $supplier->unblessed; + foreach ( keys %{$supplier_hashref} ) { + $template->{'VARS'}->{$_} = $supplier->$_; } + $template->{VARS}->{contacts} = $supplier->contacts if $supplier->contacts->count; $template->{'VARS'}->{'booksellerid'} = $booksellerid; } -$template->{'VARS'}->{'contacts'} = C4::Bookseller::Contact->new() unless $template->{'VARS'}->{'contacts'}; + +$template->{VARS}->{contacts} ||= Koha::Acquisition::Bookseller::Contact->new; if ( $op eq 'display' ) { my $contracts = GetContracts( { booksellerid => $booksellerid } ); $template->param( - active => $supplier->{'active'}, - tax_rate => $supplier->{'tax_rate'} + 0.0, - invoiceprice => $supplier->{'invoiceprice'}, - listprice => $supplier->{'listprice'}, - basketcount => $supplier->{'basketcount'}, - subscriptioncount => $supplier->{'subscriptioncount'}, + active => $supplier->active, + tax_rate => $supplier->tax_rate + 0.0, + invoiceprice => $supplier->invoiceprice, + listprice => $supplier->listprice, + basketcount => $supplier->baskets->count, + subscriptioncount => $supplier->subscriptions->count, contracts => $contracts, ); } elsif ( $op eq 'delete' ) { # no further message needed for the user # the DELETE button only appears in the template if basketcount == 0 - if ( $supplier->{'basketcount'} == 0 ) { - DelBookseller($booksellerid); + if ( $supplier->baskets->count == 0 ) { + Koha::Acquisition::Booksellers->find($booksellerid)->delete; } print $query->redirect('/cgi-bin/koha/acqui/acqui-home.pl'); exit; @@ -107,8 +109,8 @@ if ( $op eq 'display' ) { $template->param( # set active ON by default for supplier add (id empty for add) - active => $booksellerid ? $supplier->{'active'} : 1, - tax_rate => $supplier->{tax_rate} ? $supplier->{'tax_rate'}+0.0 : 0, + active => $supplier ? $supplier->active : 1, + tax_rate => $supplier ? $supplier->tax_rate + 0.0 : 0, gst_values => \@gst_values, currencies => \@currencies, enter => 1, diff --git a/acqui/transferorder.pl b/acqui/transferorder.pl index 5ce3890..6cd1d2e 100755 --- a/acqui/transferorder.pl +++ b/acqui/transferorder.pl @@ -27,6 +27,7 @@ use C4::Output; use C4::Context; use C4::Acquisition; use C4::Members; +use Koha::Acquisition::Booksellers; my $input = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -54,15 +55,15 @@ if($order) { $bookselleridfrom = $basket->{booksellerid} if $basket; } -my $booksellerfrom = Koha::Acquisition::Bookseller->fetch({ id => $bookselleridfrom }); +my $booksellerfrom = Koha::Acquisition::Booksellers->find( $bookselleridfrom ); my $booksellerfromname; if($booksellerfrom){ - $booksellerfromname = $booksellerfrom->{name}; + $booksellerfromname = $booksellerfrom->name; } -my $booksellerto = Koha::Acquisition::Bookseller->fetch({ id => $bookselleridto }); +my $booksellerto = Koha::Acquisition::Booksellers->finf( $bookselleridto ); my $booksellertoname; if($booksellerto){ - $booksellertoname = $booksellerto->{name}; + $booksellertoname = $booksellerto->name; } @@ -70,8 +71,8 @@ if( $basketno && $ordernumber) { # Transfer order and exit my $order = GetOrder( $ordernumber ); my $basket = GetBasket($order->{basketno}); - my $booksellerfrom = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} }); - my $bookselleridfrom = $booksellerfrom->{id}; + my $booksellerfrom = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} ); + my $bookselleridfrom = $booksellerfrom->id; TransferOrder($ordernumber, $basketno); @@ -80,8 +81,8 @@ if( $basketno && $ordernumber) { # Show open baskets for this bookseller my $order = GetOrder( $ordernumber ); my $basketfrom = GetBasket( $order->{basketno} ); - my $booksellerfrom = Koha::Acquisition::Bookseller->fetch({ id => $basketfrom->{booksellerid} }); - $booksellerfromname = $booksellerfrom->{name}; + my $booksellerfrom = Koha::Acquisition::Booksellers->find( $basketfrom->{booksellerid} ); + $booksellerfromname = $booksellerfrom->name; my $baskets = GetBasketsByBookseller( $bookselleridto ); my $basketscount = scalar @$baskets; my @basketsloop = (); @@ -117,7 +118,7 @@ if( $basketno && $ordernumber) { # Search for booksellers to transfer from/to $op = '' unless $op; if( $op eq "do_search" ) { - my @booksellers = Koha::Acquisition::Bookseller->search({ name => $query }); + my @booksellers = Koha::Acquisition::Booksellers->search({ name => $query }); $template->param( query => $query, do_search => 1, diff --git a/acqui/uncertainprice.pl b/acqui/uncertainprice.pl index a90c75f..34a6b25 100755 --- a/acqui/uncertainprice.pl +++ b/acqui/uncertainprice.pl @@ -50,11 +50,10 @@ use C4::Auth; use C4::Output; use CGI qw ( -utf8 ); -use C4::Bookseller::Contact; use C4::Acquisition qw/SearchOrders GetOrder ModOrder/; use C4::Biblio qw/GetBiblioData/; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; my $input=new CGI; @@ -71,7 +70,7 @@ my $booksellerid = $input->param('booksellerid'); my $basketno = $input->param('basketno'); my $op = $input->param('op'); my $owner = $input->param('owner') || 0 ; # flag to see only "my" orders, or everyone orders -my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); #show all orders that have uncertain price for the bookseller my $pendingorders = SearchOrders({ @@ -106,7 +105,7 @@ if ( $op eq 'validate' ) { my $ordernumber = $order->{ordernumber}; my $order_as_from_db=GetOrder($order->{ordernumber}); $order->{'listprice'} = $input->param('price'.$ordernumber); - $order->{'ecost'}= $input->param('price'.$ordernumber) - (($input->param('price'.$ordernumber) /100) * $bookseller->{'discount'}); + $order->{'ecost'}= $input->param('price'.$ordernumber) - (($input->param('price'.$ordernumber) /100) * $bookseller->discount); $order->{'rrp'} = $input->param('price'.$ordernumber); $order->{'quantity'}=$input->param('qty'.$ordernumber); $order->{'uncertainprice'}=$input->param('uncertainprice'.$ordernumber); @@ -115,21 +114,21 @@ if ( $op eq 'validate' ) { } $template->param( uncertainpriceorders => \@orders, - booksellername => "".$bookseller->{'name'}, - booksellerid => $bookseller->{'id'}, - booksellerpostal =>$bookseller->{'postal'}, - bookselleraddress1 => $bookseller->{'address1'}, - bookselleraddress2 => $bookseller->{'address2'}, - bookselleraddress3 => $bookseller->{'address3'}, - bookselleraddress4 => $bookseller->{'address4'}, - booksellerphone =>$bookseller->{'phone'}, - booksellerfax => $bookseller->{'fax'}, - booksellerurl => $bookseller->{'url'}, - booksellernotes => $bookseller->{'notes'}, - basketcount => $bookseller->{'basketcount'}, - subscriptioncount => $bookseller->{'subscriptioncount'}, - active => $bookseller->{active}, + booksellername => "".$bookseller->name, + booksellerid => $bookseller->id, + booksellerpostal =>$bookseller->postal, + bookselleraddress1 => $bookseller->address1, + bookselleraddress2 => $bookseller->address2, + bookselleraddress3 => $bookseller->address3, + bookselleraddress4 => $bookseller->address4, + booksellerphone =>$bookseller->phone, + booksellerfax => $bookseller->fax, + booksellerurl => $bookseller->url, + booksellernotes => $bookseller->notes, + basketcount => $bookseller->baskets->count, + subscriptioncount => $bookseller->subscriptions->count, + active => $bookseller->active, owner => $owner, scriptname => "/cgi-bin/koha/acqui/uncertainprice.pl"); -$template->{'VARS'}->{'contacts'} = $bookseller->{'contacts'}; +$template->{'VARS'}->{'contacts'} = $bookseller->contacts; output_html_with_http_headers $input, $cookie, $template->output; diff --git a/acqui/updatesupplier.pl b/acqui/updatesupplier.pl index 04f4b5f..822d7a0 100755 --- a/acqui/updatesupplier.pl +++ b/acqui/updatesupplier.pl @@ -52,10 +52,11 @@ use List::Util; use C4::Context; use C4::Auth; -use C4::Bookseller qw( ModBookseller AddBookseller ); -use C4::Bookseller::Contact; use C4::Biblio; use C4::Output; + +use Koha::Acquisition::Bookseller::Contacts; +use Koha::Acquisition::Booksellers; use CGI qw ( -utf8 ); my $input=new CGI; @@ -108,15 +109,27 @@ for my $cnt (0..scalar(@{$contact_info{'id'}})) { $contact{$_} = $contact_info{$_}->[$cnt]; $real_contact = 1 if $contact{$_}; } - push @contacts, C4::Bookseller::Contact->new(\%contact) if $real_contact; + push @contacts, \%contact if $real_contact; } if($data{'name'}) { - if ($data{'id'}){ - ModBookseller(\%data, \@contacts); - } else { - $data{id}=AddBookseller(\%data, \@contacts); - } + if ( $data{id} ) { + # Update + my $bookseller = Koha::Acquisition::Booksellers->find( $data{id} )->set(\%data)->store; + # Delete existing contacts + $bookseller->contacts->delete; + } else { + # Insert + delete $data{id}; # Remove the key if exists + my $bookseller = Koha::Acquisition::Bookseller->new( \%data )->store; + $data{id} = $bookseller->id; + } + # Insert contacts + for my $contact ( @contacts ) { + $contact->{booksellerid} = $data{id}; + Koha::Acquisition::Bookseller::Contact->new( $contact )->store + } + #redirect to booksellers.pl print $input->redirect("booksellers.pl?booksellerid=".$data{id}); } else { diff --git a/acqui/z3950_search.pl b/acqui/z3950_search.pl index 061bd46..d7bd2ee 100755 --- a/acqui/z3950_search.pl +++ b/acqui/z3950_search.pl @@ -29,7 +29,7 @@ use C4::Context; use C4::Breeding; use C4::Koha; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; use Koha::BiblioFrameworks; my $input = new CGI; @@ -52,7 +52,7 @@ $page = $input->param('goto_page') if $input->param('changepage_go # get framework list my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] }); -my $vendor = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +my $vendor = Koha::Acquisition::Booksellers->find( $booksellerid ); my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { @@ -66,7 +66,7 @@ $template->param( frameworks => $frameworks, booksellerid => $booksellerid, basketno => $basketno, - name => $vendor->{'name'}, + name => $vendor->name, isbn => $isbn, issn => $issn, lccn => $lccn, diff --git a/admin/aqcontract.pl b/admin/aqcontract.pl index 57a9fce..e35b057 100755 --- a/admin/aqcontract.pl +++ b/admin/aqcontract.pl @@ -29,14 +29,14 @@ use C4::Output; use C4::Contract; use Koha::DateUtils; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; my $input = new CGI; my $contractnumber = $input->param('contractnumber'); my $booksellerid = $input->param('booksellerid'); my $op = $input->param('op') || 'list'; -my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => "admin/aqcontract.tt", @@ -51,10 +51,10 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( $template->param( contractnumber => $contractnumber, booksellerid => $booksellerid, - booksellername => $bookseller->{name}, - basketcount => $bookseller->{'basketcount'}, - active => $bookseller->{active}, - subscriptioncount => $bookseller->{'subscriptioncount'}, + booksellername => $bookseller->name, + basketcount => $bookseller->baskets->count, + active => $bookseller->active, + subscriptioncount => $bookseller->subscriptions->count, ); #ADD_FORM: called if $op is 'add_form'. Used to create form to add or modify a record diff --git a/admin/currency.pl b/admin/currency.pl index 5258a2f..09b6a74 100755 --- a/admin/currency.pl +++ b/admin/currency.pl @@ -25,7 +25,7 @@ use C4::Auth; use C4::Context; use C4::Output; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; use Koha::Acquisition::Currency; use Koha::Acquisition::Currencies; @@ -95,7 +95,7 @@ if ( $op eq 'add_form' ) { # TODO rewrite the following when Koha::Acquisition::Orders will use Koha::Objects my $schema = Koha::Database->schema; my $nb_of_orders = $schema->resultset('Aqorder')->search( { currency => $currency->currency } )->count; - my $nb_of_vendors = Koha::Acquisition::Bookseller->search( { -or => { listprice => $currency->currency, invoiceprice => $currency->currency } }); + my $nb_of_vendors = Koha::Acquisition::Booksellers->search( { -or => { listprice => $currency->currency, invoiceprice => $currency->currency } }); $template->param( currency => $currency, nb_of_orders => $nb_of_orders, diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl index 1d50d50..83019f4 100755 --- a/catalogue/moredetail.pl +++ b/catalogue/moredetail.pl @@ -35,7 +35,7 @@ use C4::Search; # enabled_staff_search_views use C4::Members qw/GetHideLostItemsPreference/; use C4::Reserves qw(GetReservesFromBiblionumber); -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; use Koha::AuthorisedValues; use Koha::DateUtils; use Koha::Items; @@ -159,8 +159,8 @@ foreach my $item (@items){ $item->{'orderdate'} = $order->{'entrydate'}; if ($item->{'basketno'}){ my $basket = GetBasket($item->{'basketno'}); - my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} }); - $item->{'vendor'} = $bookseller->{'name'}; + my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} ); + $item->{'vendor'} = $bookseller->name; } $item->{'invoiceid'} = $order->{'invoiceid'}; if($item->{invoiceid}) { diff --git a/serials/acqui-search-result.pl b/serials/acqui-search-result.pl index 4be4d84..595b6ed 100755 --- a/serials/acqui-search-result.pl +++ b/serials/acqui-search-result.pl @@ -49,7 +49,7 @@ use CGI qw ( -utf8 ); use C4::Acquisition qw( SearchOrders ); use Koha::DateUtils; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; my $query=new CGI; my ($template, $loggedinuser, $cookie) @@ -62,7 +62,7 @@ my ($template, $loggedinuser, $cookie) }); my $supplier=$query->param('supplier'); -my @suppliers = Koha::Acquisition::Bookseller->search({ name => $supplier }); +my @suppliers = Koha::Acquisition::Booksellers->search({ name => $supplier }); #my $count = scalar @suppliers; #build result page diff --git a/serials/subscription-detail.pl b/serials/subscription-detail.pl index 1cb2f9b..b7e7c05 100755 --- a/serials/subscription-detail.pl +++ b/serials/subscription-detail.pl @@ -122,7 +122,7 @@ if ( defined $subscriptionid ) { my $lastOrderReceived = GetLastOrderReceivedFromSubscriptionid $subscriptionid; if ( defined $lastOrderNotReceived ) { my $basket = GetBasket $lastOrderNotReceived->{basketno}; - my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} }); + my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} ); ( $tmpl_infos->{value_tax_included_ordered}, $tmpl_infos->{value_tax_excluded_ordered} ) = get_value_with_gst_params ( $lastOrderNotReceived->{ecost}, $lastOrderNotReceived->{tax_rate}, $bookseller ); $tmpl_infos->{value_tax_included_ordered} = sprintf( "%.2f", $tmpl_infos->{value_tax_included_ordered} ); $tmpl_infos->{value_tax_excluded_ordered} = sprintf( "%.2f", $tmpl_infos->{value_tax_excluded_ordered} ); @@ -132,7 +132,7 @@ if ( defined $subscriptionid ) { } if ( defined $lastOrderReceived ) { my $basket = GetBasket $lastOrderReceived->{basketno}; - my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} }); + my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} ); ( $tmpl_infos->{value_tax_included_spent}, $tmpl_infos->{value_tax_excluded_spent} ) = get_value_with_gst_params ( $lastOrderReceived->{unitprice}, $lastOrderReceived->{tax_rate}, $bookseller ); $tmpl_infos->{value_tax_included_spent} = sprintf( "%.2f", $tmpl_infos->{value_tax_included_spent} ); $tmpl_infos->{value_tax_excluded_spent} = sprintf( "%.2f", $tmpl_infos->{value_tax_excluded_spent} ); @@ -193,7 +193,7 @@ sub get_value_with_gst_params { my $value = shift; my $tax_rate = shift; my $bookseller = shift; - if ( $bookseller->{listincgst} ) { + if ( $bookseller->listincgst ) { return ( $value, $value / ( 1 + $tax_rate ) ); } else { return ( $value * ( 1 + $tax_rate ), $value ); @@ -204,7 +204,7 @@ sub get_tax_excluded { my $value = shift; my $tax_rate = shift; my $bookseller = shift; - if ( $bookseller->{invoiceincgst} ) { + if ( $bookseller->invoiceincgst ) { return $value / ( 1 + $tax_rate ); } else { return $value; @@ -215,7 +215,7 @@ sub get_gst { my $value = shift; my $tax_rate = shift; my $bookseller = shift; - if ( $bookseller->{invoiceincgst} ) { + if ( $bookseller->invoiceincgst ) { return $value / ( 1 + $tax_rate ) * $tax_rate; } else { return $value * ( 1 + $tax_rate ) - $value; diff --git a/t/Prices.t b/t/Prices.t index d94a04c..f89c7f6 100644 --- a/t/Prices.t +++ b/t/Prices.t @@ -8,14 +8,13 @@ use Module::Load::Conditional qw/check_install/; BEGIN { if ( check_install( module => 'Test::DBIx::Class' ) ) { - plan tests => 17; + plan tests => 16; } else { plan skip_all => "Need Test::DBIx::Class" } } use_ok('C4::Acquisition'); -use_ok('C4::Bookseller'); use_ok('C4::Context'); use_ok('Koha::Number::Price'); @@ -36,6 +35,13 @@ fixtures_ok [ [ qw/ currency symbol rate active / ], [[ 'my_cur', '€', 1, 1, ]], ], + Aqbookseller => [ + [ qw/ id name listincgst invoiceincgst / ], + [ 1, '0 0', 0, 0 ], + [ 2, '0 1', 0, 1 ], + [ 3, '1 0', 1, 0 ], + [ 4, '1 1', 1, 1 ], + ], ], 'add currency fixtures'; my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller'); @@ -48,12 +54,6 @@ for my $currency_format ( qw( US FR ) ) { t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format ); subtest 'Configuration 1: 0 0' => sub { plan tests => 8; - $bookseller_module->mock( - 'fetch', - sub { - return { listincgst => 0, invoiceincgst => 0 }; - } - ); my $biblionumber_0_0 = 42; @@ -74,7 +74,7 @@ for my $currency_format ( qw( US FR ) ) { $order_0_0 = C4::Acquisition::populate_order_with_prices( { order => $order_0_0, - booksellerid => 'just_something', + booksellerid => 1, ordering => 1, } ); @@ -123,7 +123,7 @@ for my $currency_format ( qw( US FR ) ) { $order_0_0 = C4::Acquisition::populate_order_with_prices( { order => $order_0_0, - booksellerid => 'just_something', + booksellerid => 1, receiving => 1, } ); @@ -156,12 +156,6 @@ for my $currency_format ( qw( US FR ) ) { subtest 'Configuration 1: 1 1' => sub { plan tests => 8; - $bookseller_module->mock( - 'fetch', - sub { - return { listincgst => 1, invoiceincgst => 1 }; - } - ); my $biblionumber_1_1 = 43; my $order_1_1 = { @@ -182,7 +176,7 @@ for my $currency_format ( qw( US FR ) ) { $order_1_1 = C4::Acquisition::populate_order_with_prices( { order => $order_1_1, - booksellerid => 'just_something', + booksellerid => 4, ordering => 1, } ); @@ -231,7 +225,7 @@ for my $currency_format ( qw( US FR ) ) { $order_1_1 = C4::Acquisition::populate_order_with_prices( { order => $order_1_1, - booksellerid => 'just_something', + booksellerid => 4, receiving => 1, } ); @@ -264,12 +258,6 @@ for my $currency_format ( qw( US FR ) ) { subtest 'Configuration 1: 1 0' => sub { plan tests => 8; - $bookseller_module->mock( - 'fetch', - sub { - return { listincgst => 1, invoiceincgst => 0 }; - } - ); my $biblionumber_1_0 = 44; my $order_1_0 = { @@ -290,7 +278,7 @@ for my $currency_format ( qw( US FR ) ) { $order_1_0 = C4::Acquisition::populate_order_with_prices( { order => $order_1_0, - booksellerid => 'just_something', + booksellerid => 3, ordering => 1, } ); @@ -339,7 +327,7 @@ for my $currency_format ( qw( US FR ) ) { $order_1_0 = C4::Acquisition::populate_order_with_prices( { order => $order_1_0, - booksellerid => 'just_something', + booksellerid => 3, receiving => 1, } ); @@ -372,12 +360,6 @@ for my $currency_format ( qw( US FR ) ) { subtest 'Configuration 1: 0 1' => sub { plan tests => 8; - $bookseller_module->mock( - 'fetch', - sub { - return { listincgst => 0, invoiceincgst => 1 }; - } - ); my $biblionumber_0_1 = 45; my $order_0_1 = { @@ -398,7 +380,7 @@ for my $currency_format ( qw( US FR ) ) { $order_0_1 = C4::Acquisition::populate_order_with_prices( { order => $order_0_1, - booksellerid => 'just_something', + booksellerid => 2, ordering => 1, } ); @@ -447,7 +429,7 @@ for my $currency_format ( qw( US FR ) ) { $order_0_1 = C4::Acquisition::populate_order_with_prices( { order => $order_0_1, - booksellerid => 'just_something', + booksellerid => 2, receiving => 1, } ); diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index 4eacccf..b51dc9c 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -19,17 +19,15 @@ use Modern::Perl; use POSIX qw(strftime); -use Test::More tests => 65; +use Test::More tests => 63; use Koha::Database; BEGIN { use_ok('C4::Acquisition'); - use_ok('C4::Bookseller'); use_ok('C4::Biblio'); use_ok('C4::Budgets'); - use_ok('C4::Bookseller'); use_ok('Koha::Acquisition::Order'); - use_ok('Koha::Acquisition::Bookseller'); + use_ok('Koha::Acquisition::Booksellers'); } # Sub used for testing C4::Acquisition subs returning order(s): @@ -125,7 +123,7 @@ my $dbh = C4::Context->dbh; $dbh->{RaiseError} = 1; # Creating some orders -my $booksellerid = C4::Bookseller::AddBookseller( +my $bookseller = Koha::Acquisition::Bookseller->new( { name => "my vendor", address1 => "bookseller's address", @@ -133,11 +131,11 @@ my $booksellerid = C4::Bookseller::AddBookseller( active => 1, deliverytime => 5, } -); - -my $booksellerinfo = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +)->store; +my $booksellerid = $bookseller->id; -is( $booksellerinfo->{deliverytime}, +my $booksellerinfo = Koha::Acquisition::Booksellers->find( $booksellerid ); +is( $booksellerinfo->deliverytime, 5, 'set deliverytime when creating vendor (Bug 10556)' ); my ( $basket, $basketno ); diff --git a/t/db_dependent/Acquisition/CancelReceipt.t b/t/db_dependent/Acquisition/CancelReceipt.t index 288ff53..94aae51 100644 --- a/t/db_dependent/Acquisition/CancelReceipt.t +++ b/t/db_dependent/Acquisition/CancelReceipt.t @@ -24,12 +24,12 @@ use C4::Context; use C4::Acquisition; use C4::Biblio; use C4::Items; -use C4::Bookseller; use C4::Budgets; use t::lib::Mocks; use Koha::Database; use Koha::DateUtils; +use Koha::Acquisition::Booksellers; use Koha::Acquisition::Order; use MARC::Record; @@ -41,17 +41,17 @@ $dbh->{RaiseError} = 1; my $builder = t::lib::TestBuilder->new; my $itemtype = $builder->build({ source => 'Itemtype' })->{ itemtype }; -my $booksellerid1 = C4::Bookseller::AddBookseller( +my $bookseller = Koha::Acquisition::Bookseller->new( { name => "my vendor 1", address1 => "bookseller's address", phone => "0123456", active => 1 } -); +)->store; my $basketno1 = C4::Acquisition::NewBasket( - $booksellerid1 + $bookseller->id ); my $budgetid = C4::Budgets::AddBudget( diff --git a/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t b/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t index b742ddf..c25d11b 100644 --- a/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t +++ b/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t @@ -6,7 +6,6 @@ use Data::Dumper; use C4::Acquisition qw( NewBasket GetBasketsInfosByBookseller ); use C4::Biblio qw( AddBiblio ); -use C4::Bookseller qw( AddBookseller ); use C4::Budgets qw( AddBudget ); use C4::Context; use Koha::Database; @@ -18,7 +17,7 @@ $schema->storage->txn_begin(); my $dbh = C4::Context->dbh; $dbh->{RaiseError} = 1; -my $supplierid = C4::Bookseller::AddBookseller( +my $supplier = Koha::Acquisition::Bookseller->new( { name => 'my vendor', address1 => 'bookseller\'s address', @@ -26,7 +25,8 @@ my $supplierid = C4::Bookseller::AddBookseller( active => 1, deliverytime => 5, } -); +)->store; +my $supplierid = $supplier->id; my $basketno; ok($basketno = NewBasket($supplierid, 1), 'NewBasket( $supplierid , 1 ) returns $basketno'); diff --git a/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t b/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t index 3447b27..1d7b142 100644 --- a/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t +++ b/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t @@ -5,7 +5,6 @@ use Modern::Perl; use Test::More; use C4::Acquisition; use C4::Biblio; -use C4::Bookseller; use C4::Budgets; use Koha::Database; use Koha::Acquisition::Order; @@ -18,17 +17,17 @@ $schema->storage->txn_begin(); my $dbh = C4::Context->dbh; $dbh->{RaiseError} = 1; -my $booksellerid = C4::Bookseller::AddBookseller( +my $bookseller = Koha::Acquisition::Bookseller->new( { name => "my vendor", address1 => "bookseller's address", phone => "0123456", active => 1 } -); +)->store; my $basketno = C4::Acquisition::NewBasket( - $booksellerid + $bookseller->id ); my $budgetid = C4::Budgets::AddBudget( diff --git a/t/db_dependent/Acquisition/Invoices.t b/t/db_dependent/Acquisition/Invoices.t index a929ff3..055b645 100644 --- a/t/db_dependent/Acquisition/Invoices.t +++ b/t/db_dependent/Acquisition/Invoices.t @@ -3,10 +3,9 @@ use Modern::Perl; use C4::Biblio qw( AddBiblio ); -use C4::Bookseller qw( AddBookseller ); use Koha::Acquisition::Order; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; use Koha::Database; use Test::More tests => 24; @@ -22,16 +21,17 @@ $dbh->{RaiseError} = 1; $dbh->do(q{DELETE FROM aqinvoices}); -my $booksellerid = C4::Bookseller::AddBookseller( +my $bookseller = Koha::Acquisition::Bookseller->new( { name => "my vendor", address1 => "bookseller's address", phone => "0123456", active => 1 } -); +)->store; +my $booksellerid = $bookseller->id; -my $booksellerinfo = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +my $booksellerinfo = Koha::Acquisition::Booksellers->find( $booksellerid ); my $basketno = NewBasket($booksellerid, 1); my $basket = GetBasket($basketno); diff --git a/t/db_dependent/Acquisition/NewOrder.t b/t/db_dependent/Acquisition/NewOrder.t index b491075..a6deef8 100644 --- a/t/db_dependent/Acquisition/NewOrder.t +++ b/t/db_dependent/Acquisition/NewOrder.t @@ -5,11 +5,11 @@ use Modern::Perl; use Test::More tests => 7; use C4::Acquisition; use C4::Biblio; -use C4::Bookseller; use C4::Budgets; use MARC::Record; use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); +use Koha::Acquisition::Booksellers; use Koha::Acquisition::Order; my $schema = Koha::Database->new()->schema(); @@ -17,17 +17,17 @@ $schema->storage->txn_begin(); my $dbh = C4::Context->dbh; $dbh->{RaiseError} = 1; -my $booksellerid = C4::Bookseller::AddBookseller( +my $bookseller = Koha::Acquisition::Bookseller->new( { name => "my vendor", address1 => "bookseller's address", phone => "0123456", active => 1 } -); +)->store; my $basketno = C4::Acquisition::NewBasket( - $booksellerid + $bookseller->id ); my $budgetid = C4::Budgets::AddBudget( @@ -87,4 +87,4 @@ $order = Koha::Acquisition::Order->fetch({ ordernumber => $ordernumber }); is( $order->{quantityreceived}, 0, 'Koha::Acquisition::Order->insert set quantityreceivedto 0 if undef is given' ); is( $order->{entrydate}, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), 'Koha::Acquisition::Order->insert set entrydate to today' ); -$schema->storage->txn_rollback(); \ No newline at end of file +$schema->storage->txn_rollback(); diff --git a/t/db_dependent/Acquisition/OrderFromSubscription.t b/t/db_dependent/Acquisition/OrderFromSubscription.t index d0a970a..4641894 100644 --- a/t/db_dependent/Acquisition/OrderFromSubscription.t +++ b/t/db_dependent/Acquisition/OrderFromSubscription.t @@ -1,10 +1,9 @@ use Modern::Perl; -use Test::More tests => 13; +use Test::More tests => 12; use_ok('C4::Acquisition'); use_ok('C4::Biblio'); -use_ok('C4::Bookseller'); use_ok('C4::Budgets'); use_ok('C4::Serials'); @@ -17,14 +16,14 @@ $schema->storage->txn_begin(); my $dbh = C4::Context->dbh; $dbh->{RaiseError} = 1; -my $booksellerid = C4::Bookseller::AddBookseller( +my $bookseller = Koha::Acquisition::Bookseller->new( { name => "my vendor", address1 => "bookseller's address", phone => "0123456", active => 1 } -); +)->store; my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, ''); my $budgetid; @@ -53,7 +52,7 @@ my $subscriptionid = NewSubscription( die unless $subscriptionid; my ($basket, $basketno); -ok($basketno = NewBasket($booksellerid, 1), "NewBasket( $booksellerid , 1 ) returns $basketno"); +ok($basketno = NewBasket($bookseller->id, 1), "NewBasket( " . $bookseller->id . ", 1 ) returns $basketno"); my $cost = 42.00; my $subscription = GetSubscription( $subscriptionid ); @@ -83,7 +82,7 @@ is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscripti ok( $order->{ecost} == $cost, "test cost for the last order not received"); $dbh->do(q{DELETE FROM aqinvoices}); -my $invoiceid = AddInvoice(invoicenumber => 'invoice1', booksellerid => $booksellerid, unknown => "unknown"); +my $invoiceid = AddInvoice(invoicenumber => 'invoice1', booksellerid => $bookseller->id, unknown => "unknown"); my $invoice = GetInvoice( $invoiceid ); $invoice->{datereceived} = '02-01-2013'; diff --git a/t/db_dependent/Acquisition/OrderUsers.t b/t/db_dependent/Acquisition/OrderUsers.t index 51e7877..6497a9e 100644 --- a/t/db_dependent/Acquisition/OrderUsers.t +++ b/t/db_dependent/Acquisition/OrderUsers.t @@ -3,10 +3,10 @@ use Test::More tests => 3; use C4::Acquisition; use C4::Biblio; -use C4::Bookseller; use C4::Letters; use Koha::Database; use Koha::Acquisition::Order; +use Koha::Acquisition::Booksellers; use t::lib::TestBuilder; @@ -19,16 +19,16 @@ my $library = $builder->build({ }); # Creating some orders -my $booksellerid = C4::Bookseller::AddBookseller( +my $bookseller = Koha::Acquisition::Bookseller->new( { name => "my vendor", address1 => "bookseller's address", phone => "0123456", active => 1, } -); +)->store; -my $basketno = NewBasket( $booksellerid, 1 ); +my $basketno = NewBasket( $bookseller->id, 1 ); my $budgetid = C4::Budgets::AddBudget( { @@ -61,7 +61,7 @@ my $ordernumber = $order->{ordernumber}; my $invoiceid = AddInvoice( invoicenumber => 'invoice', - booksellerid => $booksellerid, + booksellerid => $bookseller->id, unknown => "unknown" ); diff --git a/t/db_dependent/Acquisition/StandingOrders.t b/t/db_dependent/Acquisition/StandingOrders.t index d067747..f0e7dc8 100644 --- a/t/db_dependent/Acquisition/StandingOrders.t +++ b/t/db_dependent/Acquisition/StandingOrders.t @@ -7,7 +7,6 @@ use C4::Context; use C4::Acquisition; use C4::Biblio; use C4::Items; -use C4::Bookseller; use C4::Budgets; use Koha::Acquisition::Order; use t::lib::Mocks; diff --git a/t/db_dependent/Acquisition/TransferOrder.t b/t/db_dependent/Acquisition/TransferOrder.t index efb8e00..a25d2a2 100644 --- a/t/db_dependent/Acquisition/TransferOrder.t +++ b/t/db_dependent/Acquisition/TransferOrder.t @@ -7,10 +7,10 @@ use C4::Context; use C4::Acquisition; use C4::Biblio; use C4::Items; -use C4::Bookseller; use C4::Budgets; use Koha::Database; use Koha::DateUtils; +use Koha::Acquisition::Booksellers; use Koha::Acquisition::Order; use MARC::Record; @@ -20,30 +20,30 @@ $schema->storage->txn_begin(); my $dbh = C4::Context->dbh; $dbh->{RaiseError} = 1; -my $booksellerid1 = C4::Bookseller::AddBookseller( +my $bookseller1 = Koha::Acquisition::Bookseller->new( { name => "my vendor 1", address1 => "bookseller's address", phone => "0123456", active => 1 } -); +)->store; my $basketno1 = C4::Acquisition::NewBasket( - $booksellerid1 + $bookseller1->id ); -my $booksellerid2 = C4::Bookseller::AddBookseller( +my $bookseller2 = Koha::Acquisition::Bookseller->new( { name => "my vendor 2", address1 => "bookseller's address", phone => "0123456", active => 1 } -); +)->store; my $basketno2 = C4::Acquisition::NewBasket( - $booksellerid2 + $bookseller2->id ); my $budgetid = C4::Budgets::AddBudget( diff --git a/t/db_dependent/Acquisition/close_reopen_basket.t b/t/db_dependent/Acquisition/close_reopen_basket.t index ad489e7..aba4824 100644 --- a/t/db_dependent/Acquisition/close_reopen_basket.t +++ b/t/db_dependent/Acquisition/close_reopen_basket.t @@ -5,10 +5,10 @@ use Modern::Perl; use Test::More tests => 6; use C4::Acquisition; use C4::Biblio qw( AddBiblio DelBiblio ); -use C4::Bookseller; use C4::Budgets; use C4::Context; use Koha::Database; +use Koha::Acquisition::Bookseller; use Koha::Acquisition::Order; # Start transaction @@ -22,17 +22,17 @@ $dbh->do(q{ DELETE FROM aqorders; }); -my $booksellerid = C4::Bookseller::AddBookseller( +my $bookseller = Koha::Acquisition::Bookseller->new( { name => "my vendor", address1 => "bookseller's address", phone => "0123456", active => 1 } -); +)->store; my $basketno = C4::Acquisition::NewBasket( - $booksellerid + $bookseller->id ); my $budgetid = C4::Budgets::AddBudget( diff --git a/t/db_dependent/AdditionalField.t b/t/db_dependent/AdditionalField.t index 91d6cd3..0a56ce0 100644 --- a/t/db_dependent/AdditionalField.t +++ b/t/db_dependent/AdditionalField.t @@ -3,7 +3,6 @@ use Modern::Perl; use Test::More tests => 40; -use C4::Bookseller qw( AddBookseller ); use C4::Context; use Koha::AdditionalField; @@ -108,15 +107,6 @@ use C4::Serials; use C4::Serials::Frequency; use C4::Serials::Numberpattern; -my $booksellerid = C4::Bookseller::AddBookseller( - { - name => "my vendor", - address1 => "bookseller's address", - phone => "0123456", - active => 1 - } -); - my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, ''); my $budgetid; my $bpid = AddBudgetPeriod({ diff --git a/t/db_dependent/Bookseller.t b/t/db_dependent/Bookseller.t index 54765bd..77cf3ef 100644 --- a/t/db_dependent/Bookseller.t +++ b/t/db_dependent/Bookseller.t @@ -2,7 +2,7 @@ use Modern::Perl; -use Test::More tests => 88; +use Test::More tests => 86; use Test::MockModule; use Test::Warn; @@ -15,21 +15,19 @@ use C4::Serials; use C4::Budgets; use C4::Biblio; +use Koha::Acquisition::Booksellers; use Koha::Acquisition::Order; use Koha::Database; BEGIN { use_ok('C4::Bookseller'); - use_ok('Koha::Acquisition::Bookseller'); } can_ok( 'C4::Bookseller', qw( - AddBookseller - DelBookseller GetBooksellersWithLateOrders - ModBookseller ) + ) ); #Start transaction @@ -47,7 +45,7 @@ $dbh->do(q|DELETE FROM aqbooksellers|); $dbh->do(q|DELETE FROM subscription|); #Test AddBookseller -my $count = scalar( Koha::Acquisition::Bookseller->search() ); +my $count = Koha::Acquisition::Booksellers->search()->count(); my $sample_supplier1 = { name => 'Name1', address1 => 'address1_1', @@ -89,37 +87,39 @@ my $sample_supplier2 = { deliverytime => 2 }; -my $id_supplier1 = C4::Bookseller::AddBookseller($sample_supplier1); -my $id_supplier2 = C4::Bookseller::AddBookseller($sample_supplier2); - -#my $id_bookseller3 = C4::Bookseller::AddBookseller();# NOTE : Doesn't work because the field name cannot be null +my $supplier1 = Koha::Acquisition::Bookseller->new($sample_supplier1)->store; +my $id_supplier1 = $supplier1->id; +my $supplier2 = Koha::Acquisition::Bookseller->new($sample_supplier2)->store; +my $id_supplier2 = $supplier2->id; like( $id_supplier1, '/^\d+$/', "AddBookseller for supplier1 return an id" ); like( $id_supplier2, '/^\d+$/', "AddBookseller for supplier2 return an id" ); -my @b = Koha::Acquisition::Bookseller->search(); -is ( scalar(@b), +is( Koha::Acquisition::Booksellers->search()->count, $count + 2, "Supplier1 and Supplier2 have been added" ); #Test DelBookseller -my $del = C4::Bookseller::DelBookseller($id_supplier1); +my $del = $supplier1->delete; is( $del, 1, "DelBookseller returns 1 - 1 supplier has been deleted " ); -my $b = Koha::Acquisition::Bookseller->fetch({id => $id_supplier1}); +my $b = Koha::Acquisition::Booksellers->find( $id_supplier1 ); is( $b, undef, "Supplier1 has been deleted - id_supplier1 $id_supplier1 doesnt exist anymore" ); #Test get bookseller -my @bookseller2 = Koha::Acquisition::Bookseller->search({name => $sample_supplier2->{name} }); +my @bookseller2 = Koha::Acquisition::Booksellers->search({name => $sample_supplier2->{name} }); is( scalar(@bookseller2), 1, "Get only Supplier2" ); -$bookseller2[0] = field_filter( $bookseller2[0] ); +for my $bookseller ( @bookseller2 ) { + $bookseller = field_filter( $bookseller->unblessed ); +} $sample_supplier2->{id} = $id_supplier2; is_deeply( $bookseller2[0], $sample_supplier2, - "Koha::Acquisition::Bookseller->search returns the right informations about $sample_supplier2" ); + "Koha::Acquisition::Booksellers->search returns the right informations about supplier $sample_supplier2->{name}" ); -$id_supplier1 = C4::Bookseller::AddBookseller($sample_supplier1); -my @booksellers = Koha::Acquisition::Bookseller->search(); #NOTE :without params, it returns all the booksellers -for my $i ( 0 .. scalar(@booksellers) - 1 ) { - $booksellers[$i] = field_filter( $booksellers[$i] ); +$supplier1 = Koha::Acquisition::Bookseller->new($sample_supplier1)->store; +$id_supplier1 = $supplier1->id; +my @booksellers = Koha::Acquisition::Booksellers->search(); +for my $bookseller ( @booksellers ) { + $bookseller = field_filter( $bookseller->unblessed ); } $sample_supplier1->{id} = $id_supplier1; @@ -128,30 +128,29 @@ my @tab = ( $sample_supplier1, $sample_supplier2 ); is_deeply( \@booksellers, \@tab, "Returns right fields of Supplier1 and Supplier2" ); -#Test basket_count -my @bookseller1 = Koha::Acquisition::Bookseller->search({name => $sample_supplier1->{name} }); -is( $bookseller1[0]->basket_count, 0, 'Supplier1 has 0 basket' ); +#Test baskets +my @bookseller1 = Koha::Acquisition::Booksellers->search({name => $sample_supplier1->{name} }); +is( $bookseller1[0]->baskets->count, 0, 'Supplier1 has 0 basket' ); my $basketno1 = C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby1', 'basketname1' ); my $basketno2 = C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby2', 'basketname2' ); -@bookseller1 = Koha::Acquisition::Bookseller::search({ name => $sample_supplier1->{name} }); -is( $bookseller1[0]->basket_count, 2, 'Supplier1 has 2 baskets' ); +@bookseller1 = Koha::Acquisition::Booksellers->search({ name => $sample_supplier1->{name} }); +is( $bookseller1[0]->baskets->count, 2, 'Supplier1 has 2 baskets' ); #Test Koha::Acquisition::Bookseller->new using id -my $bookseller1fromid = Koha::Acquisition::Bookseller->fetch; +my $bookseller1fromid = Koha::Acquisition::Booksellers->find; is( $bookseller1fromid, undef, - "fetch returns undef if no id given" ); -$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1}); -$bookseller1fromid = field_filter($bookseller1fromid); + "find returns undef if no id given" ); +$bookseller1fromid = Koha::Acquisition::Booksellers->find( $id_supplier1 ); +$bookseller1fromid = field_filter($bookseller1fromid->unblessed); is_deeply( $bookseller1fromid, $sample_supplier1, - "Get Supplier1 (fetch a bookseller by id)" ); + "Get Supplier1 (find a bookseller by id)" ); -#Test basket_count -$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1}); -is( $bookseller1fromid->basket_count, 2, 'Supplier1 has 2 baskets' ); +$bookseller1fromid = Koha::Acquisition::Booksellers->find( $id_supplier1 ); +is( $bookseller1fromid->baskets->count, 2, 'Supplier1 has 2 baskets' ); -#Test subscription_count +#Test subscriptions my $dt_today = dt_from_string; my $today = output_pref({ dt => $dt_today, dateformat => 'iso', timeformat => '24hr', dateonly => 1 }); @@ -178,8 +177,8 @@ $bib->append_fields( MARC::Field->new('500', ' ', ' ', a => 'bib notes'), ); my ($biblionumber, $biblioitemnumber) = AddBiblio($bib, ''); -$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1 }); -is( $bookseller1fromid->subscription_count, +$bookseller1fromid = Koha::Acquisition::Booksellers->find( $id_supplier1 ); +is( $bookseller1fromid->subscriptions->count, 0, 'Supplier1 has 0 subscription' ); my $id_subscription1 = NewSubscription( @@ -203,8 +202,8 @@ my $id_subscription2 = NewSubscription( undef, undef, 0, undef, '2013-07-31', 0 ); -$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1 }); -is( $bookseller1fromid->subscription_count, +$bookseller1fromid = Koha::Acquisition::Booksellers->find( $id_supplier1 ); +is( $bookseller1fromid->subscriptions->count, 2, 'Supplier1 has 2 subscriptions' ); #Test ModBookseller @@ -230,22 +229,12 @@ $sample_supplier2 = { deliverytime => 2, }; -my $modif1 = C4::Bookseller::ModBookseller(); -is( $modif1, undef, - "ModBookseller returns undef if no params given - Nothing happened" ); -$modif1 = C4::Bookseller::ModBookseller($sample_supplier2); -is( $modif1, 1, "ModBookseller modifies only the supplier2" ); -is( scalar( Koha::Acquisition::Bookseller->search ), +my $modif1 = Koha::Acquisition::Booksellers->find($id_supplier2)->set($sample_supplier2)->store; +is( ref $modif1, 'Koha::Acquisition::Bookseller', "ModBookseller has updated the bookseller" ); +is( Koha::Acquisition::Booksellers->search->count, $count + 2, "Supplier2 has been modified - Nothing added" ); - -$modif1 = C4::Bookseller::ModBookseller( - { - id => -1, - name => 'name3' - } -); -#is( $modif1, '0E0', -# "ModBookseller returns OEO if the id doesnt exist - Nothing modified" ); +$supplier2 = Koha::Acquisition::Booksellers->find($id_supplier2); +is( $supplier2->name, 'Name2 modified', "supplier's name should have been modified" ); #Test GetBooksellersWithLateOrders #Add 2 suppliers @@ -288,8 +277,10 @@ my $sample_supplier4 = { discount => '3.0000', notes => 'notes3', }; -my $id_supplier3 = C4::Bookseller::AddBookseller($sample_supplier3); -my $id_supplier4 = C4::Bookseller::AddBookseller($sample_supplier4); +my $supplier3 = Koha::Acquisition::Bookseller->new($sample_supplier3)->store; +my $id_supplier3 = $supplier3->id; +my $supplier4 = Koha::Acquisition::Bookseller->new($sample_supplier4)->store; +my $id_supplier4 = $supplier4->id; #Add 2 baskets my $basketno3 = @@ -681,69 +672,83 @@ is( 3, 'superlibrarian can see all subscriptions with IndependentBranches on (bug 12048)' ); + #Test contact editing -my $booksellerid = C4::Bookseller::AddBookseller( - { +my $sample_supplier = { name => "my vendor", address1 => "bookseller's address", phone => "0123456", active => 1 - }, - [ - { name => 'John Smith', phone => '0123456x1' }, - { name => 'Leo Tolstoy', phone => '0123456x2' }, - ] -); - -@booksellers = Koha::Acquisition::Bookseller->search({ name => 'my vendor' }); + }; +my $supplier = Koha::Acquisition::Bookseller->new($sample_supplier)->store; +my $booksellerid = $supplier->id; +my $contact1 = Koha::Acquisition::Bookseller::Contact->new({ + name => 'John Smith', + phone => '0123456x1', + booksellerid => $booksellerid, +})->store; +my $contact2 = Koha::Acquisition::Bookseller::Contact->new({ + name => 'Leo Tolstoy', + phone => '0123456x2', + booksellerid => $booksellerid, +})->store; + +@booksellers = Koha::Acquisition::Booksellers->search({ name => 'my vendor' }); ok( - ( grep { $_->{'id'} == $booksellerid } @booksellers ), - 'Koha::Acquisition::Bookseller->search returns correct record when passed a name' + ( grep { $_->id == $booksellerid } @booksellers ), + 'Koha::Acquisition::Booksellers->search returns correct record when passed a name' ); -my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); -is( $bookseller->{'id'}, $booksellerid, 'Retrieved desired record' ); -is( $bookseller->{'phone'}, '0123456', 'New bookseller has expected phone' ); +my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); +is( $bookseller->id, $booksellerid, 'Retrieved desired record' ); +is( $bookseller->phone, '0123456', 'New bookseller has expected phone' ); my $contacts = $bookseller->contacts; -is( ref $bookseller->contacts, - 'ARRAY', 'Koha::Acquisition::Bookseller->fetch returns arrayref of contacts' ); +is( $contacts->count, + 2, 'bookseller should have 2 contacts' ); +my $first_contact = $contacts->next; is( - ref $bookseller->{'contacts'}->[0], - 'C4::Bookseller::Contact', - 'First contact is a contact object' + ref $first_contact, + 'Koha::Acquisition::Bookseller::Contact', + 'First contact is a AqContact' ); -is( $bookseller->{'contacts'}->[0]->phone, +is( $first_contact->phone, '0123456x1', 'Contact has expected phone number' ); -is( scalar @{ $bookseller->{'contacts'} }, 2, 'Saved two contacts' ); -pop @{ $bookseller->{'contacts'} }; -$bookseller->{'name'} = 'your vendor'; -$bookseller->{'contacts'}->[0]->phone('654321'); -C4::Bookseller::ModBookseller($bookseller); - -$bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +my $second_contact = $contacts->next; +$second_contact->delete; +$bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); +$bookseller->name('your vendor')->store; $contacts = $bookseller->contacts; -is( $bookseller->{'name'}, 'your vendor', +$first_contact = $contacts->next; +$first_contact->phone('654321'); +$first_contact->store; + +$bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); +is( $bookseller->name, 'your vendor', 'Successfully changed name of vendor' ); -is( $contacts->[0]->phone, +$contacts = $bookseller->contacts; +is( $contacts->count, + 1, 'Only one contact after modification' ); +$first_contact = $contacts->next; +is( $first_contact->phone, '654321', 'Successfully changed contact phone number by modifying bookseller hash' ); -is( scalar @$contacts, - 1, 'Only one contact after modification' ); -C4::Bookseller::ModBookseller( $bookseller, - [ { name => 'John Jacob Jingleheimer Schmidt' } ] ); +$first_contact->name( 'John Jacob Jingleheimer Schmidt' ); +$first_contact->phone(undef); +$first_contact->store; -$bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +$bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); $contacts = $bookseller->contacts; +$first_contact = $contacts->next; is( - $contacts->[0]->name, + $first_contact->name, 'John Jacob Jingleheimer Schmidt', 'Changed name of contact' ); -is( $contacts->[0]->phone, +is( $first_contact->phone, undef, 'Removed phone number from contact' ); -is( scalar @$contacts, +is( $contacts->count, 1, 'Only one contact after modification' ); #End transaction diff --git a/t/db_dependent/Budgets.t b/t/db_dependent/Budgets.t index 5bc23cb..0611389 100755 --- a/t/db_dependent/Budgets.t +++ b/t/db_dependent/Budgets.t @@ -7,11 +7,11 @@ BEGIN { } use C4::Context; use C4::Biblio; -use C4::Bookseller; use C4::Acquisition; use C4::Members qw( AddMember ); use Koha::Acquisition::Order; +use Koha::Acquisition::Booksellers; use t::lib::TestBuilder; @@ -270,7 +270,7 @@ my $budget_id21 = AddBudget( } ); -my $booksellerid = C4::Bookseller::AddBookseller( +my $bookseller = Koha::Acquisition::Bookseller->new( { name => "my vendor", address1 => "bookseller's address", @@ -278,7 +278,8 @@ my $booksellerid = C4::Bookseller::AddBookseller( active => 1, deliverytime => 5, } -); +)->store; +my $booksellerid = $bookseller->id; my $basketno = C4::Acquisition::NewBasket( $booksellerid, 1 ); my ( $biblionumber, $biblioitemnumber ) = diff --git a/t/db_dependent/Contract.t b/t/db_dependent/Contract.t index eefa047..9ca0e18 100644 --- a/t/db_dependent/Contract.t +++ b/t/db_dependent/Contract.t @@ -20,8 +20,8 @@ use Modern::Perl; use C4::Context; -use C4::Bookseller; use Koha::DateUtils; +use Koha::Acquisition::Booksellers; use DateTime::Duration; @@ -40,9 +40,11 @@ $dbh->do(q|DELETE FROM aqcontract|); $dbh->do(q|DELETE FROM aqbooksellers|); -my $bookseller_id1 = C4::Bookseller::AddBookseller( { name => 'My first bookseller' } ); +my $bookseller1 = Koha::Acquisition::Bookseller->new( { name => 'My first bookseller' } )->store; +my $bookseller_id1 = $bookseller1->id; isnt( $bookseller_id1, undef, 'AddBookseller does not return undef' ); -my $bookseller_id2 = C4::Bookseller::AddBookseller( { name => 'My second bookseller' } ); +my $bookseller2 = Koha::Acquisition::Bookseller->new( { name => 'My second bookseller' } )->store; +my $bookseller_id2 = $bookseller2->id; isnt( $bookseller_id2, undef, 'AddBookseller does not return undef' ); my $contracts = GetContracts(); is( @$contracts, 0, 'GetContracts returns the correct number of contracts' ); diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index 9b5c469..8219e5b 100644 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -18,7 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 80; +use Test::More tests => 79; use Test::MockModule; use Test::Warn; @@ -38,14 +38,14 @@ use_ok('C4::Context'); use_ok('C4::Members'); use_ok('C4::Acquisition'); use_ok('C4::Biblio'); -use_ok('C4::Bookseller'); use_ok('C4::Letters'); use t::lib::Mocks; use t::lib::TestBuilder; use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Acquisition::Order; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; +use Koha::Acquisition::Bookseller::Contacts; use Koha::Libraries; my $schema = Koha::Database->schema; $schema->storage->txn_begin(); @@ -366,19 +366,19 @@ $dbh->do(q{INSERT INTO letter (module, code, name, title, content) VALUES ('orde is( $values->{dateexpiry}, '2015-12-13', "_parseletter doesn't modify its parameters" ); } -my $booksellerid = C4::Bookseller::AddBookseller( +my $bookseller = Koha::Acquisition::Bookseller->new( { name => "my vendor", address1 => "bookseller's address", phone => "0123456", active => 1, deliverytime => 5, - }, - [ - { name => 'John Smith', acqprimary => 1, phone => '0123456x1', claimacquisition => 1, orderacquisition => 1 }, - { name => 'Leo Tolstoy', phone => '0123456x2', claimissues => 1 }, - ] -); + } +)->store; +my $booksellerid = $bookseller->id; + +Koha::Acquisition::Bookseller::Contact->new( { name => 'John Smith', phone => '0123456x1', claimacquisition => 1, orderacquisition => 1, booksellerid => $booksellerid } )->store; +Koha::Acquisition::Bookseller::Contact->new( { name => 'Leo Tolstoy', phone => '0123456x2', claimissues => 1, booksellerid => $booksellerid } )->store; my $basketno = NewBasket($booksellerid, 1); my $budgetid = C4::Budgets::AddBudget({ @@ -416,10 +416,8 @@ warning_like { "SendAlerts prints a warning"; is($err->{'error'}, 'no_email', "Trying to send an alert when there's no e-mail results in an error"); -my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); -$bookseller->contacts->[0]->email('testemail@mydomain.com'); -C4::Bookseller::ModBookseller($bookseller); -$bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +$bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); +$bookseller->contacts->next->email('testemail@mydomain.com')->store; # Ensure that the preference 'LetterLog' is set to logging t::lib::Mocks::mock_preference( 'LetterLog', 'on' ); diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t index e09a076..1ef0cb0 100755 --- a/t/db_dependent/Serials.t +++ b/t/db_dependent/Serials.t @@ -11,10 +11,10 @@ use C4::Serials; use C4::Serials::Frequency; use C4::Serials::Numberpattern; use C4::Debug; -use C4::Bookseller; use C4::Biblio; use C4::Budgets; use Koha::DateUtils; +use Koha::Acquisition::Booksellers; use t::lib::Mocks; use Test::More tests => 48; @@ -32,7 +32,7 @@ $dbh->{RaiseError} = 1; my @methods = ('updateClaim'); can_ok('C4::Serials', @methods); -my $booksellerid = C4::Bookseller::AddBookseller( +my $bookseller = Koha::Acquisition::Bookseller->new( { name => "my vendor", address1 => "bookseller's address", diff --git a/t/db_dependent/Serials/Claims.t b/t/db_dependent/Serials/Claims.t index 80126a2..3acb2d3 100644 --- a/t/db_dependent/Serials/Claims.t +++ b/t/db_dependent/Serials/Claims.t @@ -2,8 +2,8 @@ use Modern::Perl; use Test::More tests => 17; use C4::Acquisition; -use C4::Bookseller; use C4::Budgets; +use Koha::Acquisition::Booksellers; use_ok('C4::Serials'); use Koha::DateUtils qw( dt_from_string output_pref ); @@ -74,8 +74,10 @@ my $sample_supplier2 = { deliverytime => 2 }; -my $supplier_id1 = C4::Bookseller::AddBookseller($sample_supplier1); -my $supplier_id2 = C4::Bookseller::AddBookseller($sample_supplier2); +my $supplier1 = Koha::Acquisition::Bookseller->new($sample_supplier1)->store; +my $supplier2 = Koha::Acquisition::Bookseller->new($sample_supplier2)->store; +my $supplier_id1 = $supplier1->id; +my $supplier_id2 = $supplier2->id; my $supplierlist = eval { GetSuppliersWithLateIssues() }; is( length($@), 0, "No SQL problem in GetSuppliersWithLateIssues" ); -- 2.1.4