From cb59027c3cff379f91196d8c209ad3477a2019af Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 17 Feb 2015 14:37:10 +0100 Subject: [PATCH] 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's contracts data. --- C4/Acquisition.pm | 20 +-- C4/Bookseller.pm | 136 --------------- Koha/Acquisition/Bookseller.pm | 117 +++---------- Koha/Acquisition/Bookseller/Contact.pm | 13 ++ Koha/Acquisition/Bookseller/Contacts.pm | 17 ++ Koha/Acquisition/Booksellers.pm | 37 ++++ Koha/Object.pm | 5 + Koha/Objects.pm | 8 +- acqui/addorderiso2709.pl | 16 +- acqui/basket.pl | 31 ++-- acqui/basketgroup.pl | 16 +- acqui/basketheader.pl | 8 +- acqui/booksellers.pl | 20 +-- acqui/finishreceive.pl | 5 +- acqui/invoice.pl | 6 +- acqui/modordernotes.pl | 8 +- acqui/neworderbiblio.pl | 12 +- acqui/neworderempty.pl | 20 +-- acqui/newordersubscription.pl | 6 +- acqui/newordersuggestion.pl | 6 +- acqui/orderreceive.pl | 8 +- acqui/parcel.pl | 16 +- 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 | 56 +++--- acqui/transferorder.pl | 19 ++- acqui/uncertainprice.pl | 34 ++-- acqui/updatesupplier.pl | 31 +++- acqui/z3950_search.pl | 6 +- admin/aqcontract.pl | 10 +- catalogue/moredetail.pl | 6 +- serials/subscription-detail.pl | 12 +- t/db_dependent/Acquisition.t | 13 +- t/db_dependent/Acquisition/CancelReceipt.t | 9 +- .../Acquisition/GetBasketsInfosByBookseller.t | 7 +- .../Acquisition/GetOrdersByBiblionumber.t | 7 +- t/db_dependent/Acquisition/Invoices.t | 9 +- t/db_dependent/Acquisition/NewOrder.t | 7 +- t/db_dependent/Acquisition/OrderFromSubscription.t | 7 +- t/db_dependent/Acquisition/TransferOrder.t | 12 +- t/db_dependent/Acquisition/close_reopen_basket.t | 7 +- t/db_dependent/Bookseller.t | 190 +++++++++++---------- t/db_dependent/Budgets.t | 7 +- t/db_dependent/Contract.t | 8 +- t/db_dependent/Letters.t | 26 +-- t/db_dependent/Serials.t | 7 +- t/db_dependent/Serials/Claims.t | 8 +- 50 files changed, 498 insertions(+), 585 deletions(-) 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 96c779e..d2ec2a6 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -31,7 +31,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 Time::localtime; @@ -363,13 +363,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}, @@ -381,14 +381,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}, basketgroupdeliveryplace => C4::Branch::GetBranchName( $basketgroup->{deliveryplace} ), @@ -2842,7 +2842,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}; @@ -2851,7 +2851,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}; @@ -2887,7 +2887,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 0f8d368..24e2d20 100644 --- a/C4/Bookseller.pm +++ b/C4/Bookseller.pm @@ -29,9 +29,6 @@ use C4::Bookseller::Contact; our $VERSION = 3.07.00.049; our @EXPORT_OK = qw( GetBooksellersWithLateOrders - ModBookseller - DelBookseller - AddBookseller ); =head1 NAME @@ -115,139 +112,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/Koha/Acquisition/Bookseller.pm b/Koha/Acquisition/Bookseller.pm index 79b1510..b43ff8b 100644 --- a/Koha/Acquisition/Bookseller.pm +++ b/Koha/Acquisition/Bookseller.pm @@ -3,122 +3,51 @@ 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 base qw( Koha::Object ); -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 ) = @_; - - croak "Cannot search on other fields than aqbooksellers.name" if $params and grep { $_ !~ /^name$/ } keys %$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 Koha::DateUtils qw( dt_from_string output_pref ); -sub basket_count { - my ( $self ) = @_; - my $schema = Koha::Database->new->schema; +use Carp qw( croak ); - return $schema->resultset('Aqbasket')->count( { booksellerid => $self->{id} }); -} +use Koha::Acquisition::Bookseller::Contact; +use Koha::Acquisition::Bookseller::Contacts; -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}); + $self->{contacts} = Koha::Acquisition::Bookseller::Contacts->search( { booksellerid => $self->id } ); return $self->{contacts}; } -sub insert { - 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}; - } +sub store { + my ( $self ) = @_; - $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 + if ( $self->{contacts} ) { + $self->{contacts}->reset; + while ( my $contact = $self->{contacts}->next ) { + $contact->store; } - ); - $self->{ordernumber} = $rs->id; - - unless ( $self->{parent_ordernumber} ) { - $rs->update( { parent_ordernumber => $self->{ordernumber} } ); } - return $self; + return $self->SUPER::store; } -# TODO Move code from ModBookseller -sub update { - die "not implemented yet"; +sub subscriptions { + my ( $self ) = @_; + + my $schema = Koha::Database->new->schema; + + return $schema->resultset('Subscription')->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..0df191b --- /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..a4ca628 --- /dev/null +++ b/Koha/Acquisition/Bookseller/Contacts.pm @@ -0,0 +1,17 @@ +package Koha::Acquisition::Bookseller::Contacts; + +use Modern::Perl; + +use Carp; + +use base qw( Koha::Objects ); + +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..eb5abeb --- /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 a77eb5c..76349e7 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -238,6 +238,11 @@ sub _columns { return $self->{_columns}; } +sub as_hashref { + my ( $self ) = @_; + my %columns = $self->{_result}->get_columns; + return \%columns; +} =head3 AUTOLOAD diff --git a/Koha/Objects.pm b/Koha/Objects.pm index 701e535..8a3edad 100644 --- a/Koha/Objects.pm +++ b/Koha/Objects.pm @@ -88,6 +88,8 @@ sub find { my $result = $self->_resultset()->find($id); + return unless $result; + my $object = $self->object_class()->_new_from_dbic( $result ); return $object; @@ -100,17 +102,17 @@ my @objects = Koha::Objects->search($params); =cut sub search { - my ( $self, $params ) = @_; + my ( $self, $params, $attributes ) = @_; if (wantarray) { - my @dbic_rows = $self->_resultset()->search($params); + my @dbic_rows = $self->_resultset()->search($params, $attributes); return $self->_wrap(@dbic_rows); } else { my $class = ref($self) ? ref($self) : $self; - my $rs = $self->_resultset()->search($params); + my $rs = $self->_resultset()->search($params, $attributes); return $class->_new_from_dbic($rs); } diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index 634c6ac..3573df1 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -45,7 +45,7 @@ use C4::Members; use Koha::Number::Price; 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,12 +60,12 @@ my ($template, $loggedinuser, $cookie, $userflags) = get_template_and_user({ my $cgiparams = $input->Vars; my $op = $cgiparams->{'op'} || ''; my $booksellerid = $input->param('booksellerid'); -my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); my $data; $template->param(scriptname => "/cgi-bin/koha/acqui/addorderiso2709.pl", booksellerid => $booksellerid, - booksellername => $bookseller->{name}, + booksellername => $bookseller->name, ); if ($cgiparams->{'import_batch_id'} && $op eq ""){ @@ -93,8 +93,8 @@ if ($op eq ""){ my $active_currency = GetCurrency(); my $default_currency; if (! $data->{currency} ) { # New order no currency set - if ( $bookseller->{listprice} ) { - $default_currency = $bookseller->{listprice}; + if ( $bookseller->listprice ) { + $default_currency = $bookseller->listprice; } else { $default_currency = $active_currency->{currency}; @@ -229,9 +229,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 79a55d7..f02fdfd 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -35,6 +35,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 Date::Calc qw/Add_Delta_Days/; =head1 NAME @@ -82,7 +83,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 ); unless (CanUserManageBasket($loggedinuser, $basket, $userflags)) { $template->param( @@ -90,7 +91,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; @@ -183,13 +184,13 @@ if ( $op eq 'delete_confirm' ) { closedate => $basket->{closedate}, deliveryplace => $basket->{deliveryplace}, billingplace => $basket->{billingplace}, - active => $bookseller->{'active'}, - booksellerid => $bookseller->{'id'}, - name => $bookseller->{'name'}, - address1 => $bookseller->{'address1'}, - address2 => $bookseller->{'address2'}, - address3 => $bookseller->{'address3'}, - address4 => $bookseller->{'address4'}, + active => $bookseller->active, + booksellerid => $bookseller->id, + name => $bookseller->name, + address1 => $bookseller->address1, + address2 => $bookseller->address2, + address3 => $bookseller->address3, + address4 => $bookseller->address4, ); } elsif ($op eq 'export') { print $query->header( @@ -311,7 +312,7 @@ if ( $op eq 'delete_confirm' ) { 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 = "$year-$month-$day"; } @@ -412,9 +413,9 @@ if ( $op eq 'delete_confirm' ) { estimateddeliverydate=> $estimateddeliverydate, deliveryplace => C4::Branch::GetBranchName( $basket->{deliveryplace} ), billingplace => C4::Branch::GetBranchName( $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, @@ -423,7 +424,7 @@ if ( $op eq 'delete_confirm' ) { total_tax_included => $total_tax_included, total_tax_value => $total_tax_value, currency => $cur->{'currency'}, - listincgst => $bookseller->{listincgst}, + listincgst => $bookseller->listincgst, basketgroups => $basketgroups, basketgroup => $basketgroup, grouped => $basket->{basketgroupid}, @@ -501,7 +502,7 @@ sub get_order_infos { if ($line{$key}) { my $order = GetOrder($line{$key}); my $basket = GetBasket($order->{basketno}); - 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 38536f8..0359fa8 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -57,7 +57,7 @@ use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsBy use C4::Branch qw/GetBranches/; use C4::Members qw/GetMember/; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; our $input=new CGI; @@ -77,13 +77,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; } @@ -120,7 +120,7 @@ sub displaybasketgroups { } } $template->param(baskets => $baskets); - $template->param( booksellername => $bookseller ->{'name'}); + $template->param( booksellername => $bookseller->name); } sub printbasketgrouppdf{ @@ -145,7 +145,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; @@ -208,7 +208,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; } @@ -233,7 +233,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; @@ -380,7 +380,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 15c76e8..ae7e993 100755 --- a/acqui/basketheader.pl +++ b/acqui/basketheader.pl @@ -55,7 +55,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( @@ -106,18 +106,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 a5eb47d..a67ed23 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,17 +83,17 @@ 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'} + supplier_name => $suppliers[0]->name, + booksellerid => $suppliers[0]->id, + basketcount => $suppliers[0]->baskets->count ); } @@ -123,7 +123,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 = []; @@ -149,9 +149,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 b6e4197..6a356cb 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 cc80a82..e93429a 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::Misc::Files; my $input = new CGI; @@ -110,7 +110,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 $qty_total; @@ -176,7 +176,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 => GetCurrency()->{currency}, budgets_loop => \@budgets_loop, ); diff --git a/acqui/modordernotes.pl b/acqui/modordernotes.pl index 2c6b71b..c6755b3 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 e7c427c..e23b26e 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; my $input = new CGI; @@ -80,7 +80,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( @@ -111,8 +111,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; @@ -143,8 +143,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 d66f15e..6b32155 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -91,7 +91,7 @@ use C4::Search qw/FindDuplicate/; #needed for z3950 import: use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; our $input = new CGI; my $booksellerid = $input->param('booksellerid'); # FIXME: else ERROR! @@ -132,7 +132,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} @@ -205,8 +205,8 @@ $suggestion = GetSuggestionInfo($suggestionid) if $suggestionid; my $active_currency = GetCurrency(); my $default_currency; if (! $data->{currency} ) { # New order no currency set - if ( $bookseller->{listprice} ) { - $default_currency = $bookseller->{listprice}; + if ( $bookseller->listprice ) { + $default_currency = $bookseller->listprice; } else { $default_currency = $active_currency->{currency}; @@ -364,15 +364,15 @@ $template->param( biblionumber => $biblionumber, uncertainprice => $data->{'uncertainprice'}, authorisedbyname => $borrower->{'firstname'} . " " . $borrower->{'surname'}, - 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'}, loop_currencies => \@loop_currency, @@ -390,7 +390,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 cb04c64..f1be664 100755 --- a/acqui/newordersubscription.pl +++ b/acqui/newordersubscription.pl @@ -26,7 +26,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'); @@ -53,7 +53,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) { @@ -102,6 +102,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 839b4f4..9d72a89 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 e408efe..538162c 100755 --- a/acqui/orderreceive.pl +++ b/acqui/orderreceive.pl @@ -75,7 +75,7 @@ use C4::Items; use C4::Biblio; use C4::Suggestions; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; my $input = new CGI; @@ -90,7 +90,7 @@ my $ordernumber = $input->param('ordernumber'); $datereceived = $datereceived ? C4::Dates->new($datereceived, 'iso') : C4::Dates->new(); -my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); my $results; $results = SearchOrders({ ordernumber => $ordernumber @@ -165,7 +165,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) { @@ -206,7 +206,7 @@ $template->param( subscriptionid => $order->{subscriptionid}, booksellerid => $order->{'booksellerid'}, freight => $freight, - name => $bookseller->{'name'}, + name => $bookseller->name, date => format_date($order->{entrydate}), title => $order->{'title'}, author => $order->{'author'}, diff --git a/acqui/parcel.pl b/acqui/parcel.pl index 0ca9361..baca7c3 100755 --- a/acqui/parcel.pl +++ b/acqui/parcel.pl @@ -68,7 +68,7 @@ use C4::Dates qw/format_date format_date_in_iso/; use C4::Suggestions; use C4::Reserves qw/GetReservesFromBiblionumber/; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; 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 $datereceived = C4::Dates->new(); my @orders = @{ $invoice->{orders} }; @@ -125,11 +125,11 @@ my $subtotal_for_funds; for my $order ( @orders ) { $order->{'unitprice'} += 0; - if ( $bookseller->{listincgst} and not $bookseller->{invoiceincgst} ) { + if ( $bookseller->listincgst and not $bookseller->invoiceincgst ) { $order->{ecost} = $order->{ecost_tax_excluded}; $order->{unitprice} = $order->{unitprice_tax_excluded}; } - elsif ( not $bookseller->{listinct} and $bookseller->{invoiceincgst} ) { + elsif ( not $bookseller->listinct and $bookseller->invoiceincgst ) { $order->{ecost} = $order->{ecost_tax_included}; $order->{unitprice} = $order->{unitprice_tax_included}; } else { @@ -225,9 +225,9 @@ unless( defined $invoice->{closedate} ) { for (my $i = 0 ; $i < $countpendings ; $i++) { my $order = $pendingorders->[$i]; - if ( $bookseller->{listincgst} and not $bookseller->{invoiceincgst} ) { + if ( $bookseller->listincgst and not $bookseller->invoiceincgst ) { $order->{ecost} = $order->{ecost_tax_excluded}; - } elsif ( not $bookseller->{listinct} and $bookseller->{invoiceincgst} ) { + } elsif ( not $bookseller->listinct and $bookseller->invoiceincgst ) { $order->{ecost} = $order->{ecost_tax_included}; } else { $order->{ecost} = $order->{ecost_tax_excluded}; @@ -290,8 +290,8 @@ $template->param( datereceived => $datereceived->output('iso'), invoicedatereceived => $datereceived->output('iso'), formatteddatereceived => $datereceived->output(), - 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 ba91abd..67514ab 100755 --- a/acqui/parcels.pl +++ b/acqui/parcels.pl @@ -76,7 +76,7 @@ use C4::Dates qw/format_date/; use C4::Acquisition; use C4::Budgets; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; my $input = CGI->new; my $booksellerid = $input->param('booksellerid'); @@ -141,7 +141,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, @@ -205,7 +205,7 @@ $template->param( datefrom => $datefrom, dateto => $dateto, resultsperpage => $resultsperpage, - name => $bookseller->{'name'}, + name => $bookseller->name, shipmentdate_today => C4::Dates->new()->output(), booksellerid => $booksellerid, GST => C4::Context->preference('gist'), diff --git a/acqui/pdfformat/layout2pages.pm b/acqui/pdfformat/layout2pages.pm index 4f2ea11..1e5c0c3 100644 --- a/acqui/pdfformat/layout2pages.pm +++ b/acqui/pdfformat/layout2pages.pm @@ -202,17 +202,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 ce78f45..30cc2d3 100644 --- a/acqui/pdfformat/layout2pagesde.pm +++ b/acqui/pdfformat/layout2pagesde.pm @@ -202,17 +202,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 ebad9c9..bb83eb8 100644 --- a/acqui/pdfformat/layout3pages.pm +++ b/acqui/pdfformat/layout3pages.pm @@ -366,17 +366,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 af999f0..a6f3e45 100644 --- a/acqui/pdfformat/layout3pagesfr.pm +++ b/acqui/pdfformat/layout3pagesfr.pm @@ -366,17 +366,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 3370473..01d5b19 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::Booksellers; my $query = CGI->new; my $op = $query->param('op') || 'display'; @@ -66,34 +65,35 @@ 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->as_hashref; + foreach ( keys %{$supplier_hashref} ) { + $template->{'VARS'}->{$_} = $supplier->$_; } $template->{'VARS'}->{'booksellerid'} = $booksellerid; + $template->{'VARS'}->{'contacts'} = $supplier->contacts; } -$template->{'VARS'}->{'contacts'} = C4::Bookseller::Contact->new() unless $template->{'VARS'}->{'contacts'}; #build array for currencies 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->basketcount == 0 ) { + Koha::Acquisition::Booksellers->find($booksellerid)->delete; } print $query->redirect('/cgi-bin/koha/acqui/acqui-home.pl'); exit; @@ -101,14 +101,22 @@ if ( $op eq 'display' ) { my @currencies = GetCurrencies(); my $loop_currency; my $active_currency = GetCurrency(); - my $active_listprice = $supplier->{'listprice'}; - my $active_invoiceprice = $supplier->{'invoiceprice'}; - if (!$supplier->{listprice}) { - $active_listprice = $active_currency->{currency}; - } - if (!$supplier->{invoiceprice}) { - $active_invoiceprice = $active_currency->{currency}; + my ( $active_listprice, $active_invoiceprice ); + if ( $supplier ) { + my $active_listprice = $supplier->listprice; + my $active_invoiceprice = $supplier->invoiceprice; + if (!$supplier->listprice) { + $active_listprice = $active_currency->{currency}; + } + if (!$supplier->invoiceprice) { + $active_invoiceprice = $active_currency->{currency}; + } + $template->param( + active => $booksellerid ? $supplier->active : 1, + gstrate => $supplier->gstrate ? $supplier->gstrate + 0.0 : 0, + ); } + for (@currencies) { push @{$loop_currency}, { @@ -125,8 +133,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 => $booksellerid ? $supplier->active : 1, + tax_rate => $supplier->tax_rate ? $supplier->tax_rate+0.0 : 0, gst_values => \@gst_values, loop_currency => $loop_currency, enter => 1, diff --git a/acqui/transferorder.pl b/acqui/transferorder.pl index 3e8bdc8..30ca477 100755 --- a/acqui/transferorder.pl +++ b/acqui/transferorder.pl @@ -28,6 +28,7 @@ use C4::Context; use C4::Acquisition; use C4::Members; use C4::Dates qw/format_date_in_iso/; +use Koha::Acquisition::Booksellers; use Date::Calc qw/Today/; my $input = new CGI; @@ -54,23 +55,23 @@ 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->find( $bookselleridto ); my $booksellertoname; if($booksellerto){ - $booksellertoname = $booksellerto->{name}; + $booksellertoname = $booksellerto->name; } 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); @@ -79,8 +80,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 = (); @@ -116,7 +117,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 b53b7e7..4b5a18e 100755 --- a/acqui/uncertainprice.pl +++ b/acqui/uncertainprice.pl @@ -55,7 +55,7 @@ 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; @@ -72,7 +72,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({ @@ -107,7 +107,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); @@ -116,20 +116,20 @@ 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'}, + 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, 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 71d5521..0ef9045 100755 --- a/acqui/updatesupplier.pl +++ b/acqui/updatesupplier.pl @@ -52,10 +52,12 @@ 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; +use Koha::Acquisition::Booksellers; use CGI qw ( -utf8 ); my $input=new CGI; @@ -115,15 +117,30 @@ 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; + my $contacts = $bookseller->contacts; + # Delete existing contacts + while ( my $contact = $contacts->next ) { + $contact->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 e30901a..309073a 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; my $input = new CGI; my $biblionumber = $input->param('biblionumber')||0; @@ -63,7 +63,7 @@ foreach my $thisframeworkcode ( keys %$frameworks ) { push @frameworkcodeloop, \%row; } -my $vendor = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +my $vendor = Koha::Acquisition::Booksellers->find( $booksellerid ); my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { @@ -78,7 +78,7 @@ $template->param( frameworkcodeloop => \@frameworkcodeloop, 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 a19efdb..9e7adca 100755 --- a/admin/aqcontract.pl +++ b/admin/aqcontract.pl @@ -29,14 +29,14 @@ use C4::Output; use C4::Dates qw/format_date format_date_in_iso/; use C4::Contract; -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,9 +51,9 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( $template->param( contractnumber => $contractnumber, booksellerid => $booksellerid, - booksellername => $bookseller->{name}, - basketcount => $bookseller->{'basketcount'}, - subscriptioncount => $bookseller->{'subscriptioncount'}, + booksellername => $bookseller->name, + basketcount => $bookseller->baskets->count, + 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/catalogue/moredetail.pl b/catalogue/moredetail.pl index 39d3c9f..bf39aff 100755 --- a/catalogue/moredetail.pl +++ b/catalogue/moredetail.pl @@ -36,7 +36,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::DateUtils; my $query=new CGI; @@ -162,8 +162,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/subscription-detail.pl b/serials/subscription-detail.pl index 3869c01..1ab8aee 100755 --- a/serials/subscription-detail.pl +++ b/serials/subscription-detail.pl @@ -27,7 +27,7 @@ use C4::Output; use C4::Context; use C4::Search qw/enabled_staff_search_views/; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/; use Carp; @@ -119,7 +119,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} ); @@ -129,7 +129,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} ); @@ -182,7 +182,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 ); @@ -193,7 +193,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; @@ -204,7 +204,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/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index b86343e..bcc2cc1 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -23,12 +23,11 @@ use Test::More tests => 87; 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): @@ -121,7 +120,7 @@ $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; # Creating some orders -my $booksellerid = C4::Bookseller::AddBookseller( +my $bookseller = Koha::Acquisition::Bookseller->new( { name => "my vendor", address1 => "bookseller's address", @@ -129,11 +128,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 6f53662..32c389f 100644 --- a/t/db_dependent/Acquisition/CancelReceipt.t +++ b/t/db_dependent/Acquisition/CancelReceipt.t @@ -7,29 +7,30 @@ use C4::Context; use C4::Acquisition; use C4::Biblio; use C4::Items; -use C4::Bookseller; use C4::Budgets; use t::lib::Mocks; use Koha::DateUtils; use Koha::Acquisition::Order; +use Koha::Acquisition::Bookseller; use MARC::Record; my $dbh = C4::Context->dbh; $dbh->{RaiseError} = 1; $dbh->{AutoCommit} = 0; -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 $booksellerid = $bookseller->id; my $basketno1 = C4::Acquisition::NewBasket( - $booksellerid1 + $booksellerid ); my $budgetid = C4::Budgets::AddBudget( diff --git a/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t b/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t index 342d431..d470d19 100644 --- a/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t +++ b/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t @@ -6,17 +6,17 @@ 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::Acquisition::Order; +use Koha::Acquisition::Bookseller; my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; -my $supplierid = C4::Bookseller::AddBookseller( +my $supplier = Koha::Acquisition::Bookseller->new( { name => 'my vendor', address1 => 'bookseller\'s address', @@ -24,7 +24,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 adc11b6..2335572 100644 --- a/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t +++ b/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t @@ -5,10 +5,10 @@ use Modern::Perl; use Test::More; use C4::Acquisition; use C4::Biblio; -use C4::Bookseller; use C4::Budgets; use Koha::Acquisition::Order; +use Koha::Acquisition::Bookseller; use MARC::Record; @@ -17,14 +17,15 @@ my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; $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 $booksellerid = $bookseller->id; my $basketno = C4::Acquisition::NewBasket( $booksellerid diff --git a/t/db_dependent/Acquisition/Invoices.t b/t/db_dependent/Acquisition/Invoices.t index f6f51bc..b4e2b94 100644 --- a/t/db_dependent/Acquisition/Invoices.t +++ b/t/db_dependent/Acquisition/Invoices.t @@ -3,10 +3,10 @@ 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 Test::More tests => 24; @@ -20,16 +20,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 aa9bfed..5436394 100644 --- a/t/db_dependent/Acquisition/NewOrder.t +++ b/t/db_dependent/Acquisition/NewOrder.t @@ -5,24 +5,25 @@ 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::DateUtils qw( dt_from_string output_pref ); use Koha::Acquisition::Order; +use Koha::Acquisition::Bookseller; my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; $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 $booksellerid = $bookseller->id; my $basketno = C4::Acquisition::NewBasket( $booksellerid diff --git a/t/db_dependent/Acquisition/OrderFromSubscription.t b/t/db_dependent/Acquisition/OrderFromSubscription.t index 13dc10e..28cd09f 100644 --- a/t/db_dependent/Acquisition/OrderFromSubscription.t +++ b/t/db_dependent/Acquisition/OrderFromSubscription.t @@ -4,9 +4,9 @@ use Test::More tests => 13; use_ok('C4::Acquisition'); use_ok('C4::Biblio'); -use_ok('C4::Bookseller'); use_ok('C4::Budgets'); use_ok('C4::Serials'); +use_ok('Koha::Acquisition::Bookseller'); use Koha::Acquisition::Order; @@ -15,14 +15,15 @@ my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; $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 $booksellerid = $bookseller->id; my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, ''); my $budgetid; diff --git a/t/db_dependent/Acquisition/TransferOrder.t b/t/db_dependent/Acquisition/TransferOrder.t index 5d2014c..8182b1a 100644 --- a/t/db_dependent/Acquisition/TransferOrder.t +++ b/t/db_dependent/Acquisition/TransferOrder.t @@ -7,37 +7,39 @@ use C4::Context; use C4::Acquisition; use C4::Biblio; use C4::Items; -use C4::Bookseller; use C4::Budgets; use Koha::DateUtils; use Koha::Acquisition::Order; +use Koha::Acquisition::Bookseller; use MARC::Record; my $dbh = C4::Context->dbh; $dbh->{RaiseError} = 1; $dbh->{AutoCommit} = 0; -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 $booksellerid1 = $bookseller1->id; my $basketno1 = C4::Acquisition::NewBasket( $booksellerid1 ); -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 $booksellerid2 = $bookseller2->id; my $basketno2 = C4::Acquisition::NewBasket( $booksellerid2 diff --git a/t/db_dependent/Acquisition/close_reopen_basket.t b/t/db_dependent/Acquisition/close_reopen_basket.t index a5ae64d..2bcc917 100644 --- a/t/db_dependent/Acquisition/close_reopen_basket.t +++ b/t/db_dependent/Acquisition/close_reopen_basket.t @@ -5,9 +5,9 @@ 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::Acquisition::Bookseller; use Koha::Acquisition::Order; @@ -20,14 +20,15 @@ $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 $booksellerid = $bookseller->id; my $basketno = C4::Acquisition::NewBasket( $booksellerid diff --git a/t/db_dependent/Bookseller.t b/t/db_dependent/Bookseller.t index 1bd94ed..cd93974 100644 --- a/t/db_dependent/Bookseller.t +++ b/t/db_dependent/Bookseller.t @@ -19,15 +19,14 @@ use Koha::Acquisition::Order; BEGIN { use_ok('C4::Bookseller'); use_ok('Koha::Acquisition::Bookseller'); + use_ok('Koha::Acquisition::Booksellers'); } can_ok( 'C4::Bookseller', qw( - AddBookseller - DelBookseller GetBooksellersWithLateOrders - ModBookseller ) + ) ); #Start transaction @@ -42,7 +41,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', @@ -84,37 +83,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->as_hashref ); +} $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->as_hashref ); } $sample_supplier1->{id} = $id_supplier1; @@ -123,30 +124,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->as_hashref); 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 }); @@ -173,8 +173,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( @@ -198,8 +198,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 @@ -225,22 +225,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 @@ -283,8 +273,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 = @@ -676,69 +668,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'); $contacts = $bookseller->contacts; -is( $bookseller->{'name'}, 'your vendor', +$first_contact = $contacts->next; +$first_contact->phone('654321'); +$bookseller->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); +$bookseller->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 faa60a2..02b758a 100755 --- a/t/db_dependent/Budgets.t +++ b/t/db_dependent/Budgets.t @@ -6,11 +6,11 @@ BEGIN { } use C4::Context; use C4::Biblio; -use C4::Bookseller; use C4::Acquisition; use C4::Dates; use C4::Members qw( AddMember ); +use Koha::Acquisition::Bookseller; use Koha::Acquisition::Order; use YAML; @@ -263,7 +263,7 @@ my $budget_id21 = AddBudget( } ); -my $booksellerid = C4::Bookseller::AddBookseller( +my $bookseller = Koha::Acquisition::Bookseller->new( { name => "my vendor", address1 => "bookseller's address", @@ -271,7 +271,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 7439873..901c12f 100644 --- a/t/db_dependent/Contract.t +++ b/t/db_dependent/Contract.t @@ -19,7 +19,7 @@ use Modern::Perl; use C4::Context; -use C4::Bookseller; +use Koha::Acquisition::Bookseller; use Test::More tests => 43; @@ -36,9 +36,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 f53e75b..fc811ca 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 => 58; +use Test::More tests => 57; use Test::MockModule; use Test::Warn; @@ -39,12 +39,12 @@ use_ok('C4::Members'); use_ok('C4::Branch'); use_ok('C4::Acquisition'); use_ok('C4::Biblio'); -use_ok('C4::Bookseller'); use_ok('C4::Letters'); use t::lib::Mocks; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Acquisition::Order; use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; my $dbh = C4::Context->dbh; @@ -277,7 +277,7 @@ is( $prepared_letter->{content}, $my_content_letter, 'GetPreparedLetter returns $dbh->do(q{INSERT INTO letter (module, code, name, title, content) VALUES ('claimacquisition','TESTACQCLAIM','Acquisition Claim','Item Not Received','<>|<>|Ordernumber <> (<>) (<> ordered)');}); -my $booksellerid = C4::Bookseller::AddBookseller( +my $bookseller = Koha::Acquisition::Bookseller->new( { name => "my vendor", address1 => "bookseller's address", @@ -285,11 +285,11 @@ my $booksellerid = C4::Bookseller::AddBookseller( active => 1, deliverytime => 5, }, - [ - { name => 'John Smith', phone => '0123456x1', claimacquisition => 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, 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({ @@ -327,10 +327,12 @@ 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 ); +my $contacts = $bookseller->contacts; +my $contact = $contacts->next; +$contact->email('testemail@mydomain.com'); +$bookseller->store; +$bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); warning_is { $err = SendAlerts( 'claimacquisition', [ $ordernumber ], 'TESTACQCLAIM' ) } diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t index c255b9e..ae5e9a3 100644 --- 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::Bookseller; use Test::More tests => 43; BEGIN { @@ -27,14 +27,15 @@ my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; $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 $booksellerid = $bookseller->id; my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, ''); diff --git a/t/db_dependent/Serials/Claims.t b/t/db_dependent/Serials/Claims.t index eca6d16..4dbd50e 100644 --- a/t/db_dependent/Serials/Claims.t +++ b/t/db_dependent/Serials/Claims.t @@ -2,11 +2,11 @@ use Modern::Perl; use Test::More tests => 13; use C4::Acquisition; -use C4::Bookseller; use C4::Budgets; use_ok('C4::Serials'); use Koha::DateUtils qw( dt_from_string output_pref ); +use Koha::Acquisition::Bookseller; my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; @@ -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.0