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;
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},
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},
};
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};
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};
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 ) {
use base qw( Exporter );
-use C4::Bookseller::Contact;
-
our @EXPORT_OK = qw(
GetBooksellersWithLateOrders
- ModBookseller
- DelBookseller
- AddBookseller
);
=head1 NAME
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<gt>{id}>.
-
-The easiest way to get all of the necessary fields is to look up a
-book seller with C<Koha::Acquisition::Bookseller>, 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__
+++ /dev/null
-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 <jcamins@cpbibliography.com>
-
-=cut
-
-1;
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;
--- /dev/null
+package Koha::Acquisition::Bookseller::Contact;
+
+use Modern::Perl;
+
+use base qw( Koha::Object );
+
+use Carp qw( croak );
+
+sub _type {
+ return 'Aqcontact';
+}
+
+1;
--- /dev/null
+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;
--- /dev/null
+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;
return $self->{_columns};
}
-
=head3 AUTOLOAD
The autoload method is used only to get and set values for an objects properties.
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({
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 ""){
# 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 );
use C4::Items;
use C4::Suggestions;
use Koha::Biblios;
+use Koha::Acquisition::Booksellers;
use Koha::Libraries;
use C4::Letters qw/SendAlerts/;
use Date::Calc qw/Add_Delta_Days/;
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, } );
basketno => $basketno,
basketname => $basket->{basketname},
booksellerid => $booksellerid,
- name => $bookseller->{name}
+ name => $bookseller->name,
);
output_html_with_http_headers $query, $cookie, $template->output;
exit;
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 );
}
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,
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},
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,
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;
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;
}
}
}
$template->param(baskets => $baskets);
- $template->param( booksellername => $bookseller ->{'name'});
+ $template->param( booksellername => $bookseller->name);
}
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;
-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;
}
# 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;
}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);
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(
});
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,
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(
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,
);
}
my $loop_suppliers = [];
for my $vendor (@suppliers) {
- my $baskets = GetBasketsInfosByBookseller( $vendor->{id}, $allbaskets );
+ my $baskets = GetBasketsInfosByBookseller( $vendor->id, $allbaskets );
my $loop_basket = [];
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,
};
}
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/;
$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,
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;
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;
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,
);
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(
}
# Build suppliers list
-my @suppliers = Koha::Acquisition::Bookseller->search;
+my @suppliers = Koha::Acquisition::Booksellers->search;
my $suppliers_loop = [];
my $suppliername;
foreach (@suppliers) {
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( {
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') {
$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,
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;
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(
$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;
$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,
#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;
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}
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'},
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),
use C4::Output;
use C4::Serials;
-use Koha::Acquisition::Bookseller;
+use Koha::Acquisition::Booksellers;
my $query = new CGI;
my $title = $query->param('title_filter');
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) {
booksellerid => $booksellerid,
basketno => $basket->{basketno},
basketname => $basket->{basketname},
- booksellername => $bookseller->{name},
+ booksellername => $bookseller->name,
);
output_html_with_http_headers $query, $cookie, $template->output;
use C4::Suggestions;
use C4::Biblio;
-use Koha::Acquisition::Bookseller;
+use Koha::Acquisition::Booksellers;
my $input = new CGI;
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,
);
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;
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
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) {
subscriptionid => $order->{subscriptionid},
booksellerid => $order->{'booksellerid'},
freight => $freight,
- name => $bookseller->{'name'},
+ name => $bookseller->name,
title => $order->{'title'},
author => $order->{'author'},
copyrightdate => $order->{'copyrightdate'},
}
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;
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};
}
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};
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,
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;
}
}
-my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
+my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
my @parcels = GetInvoices(
supplierid => $booksellerid,
invoicenumber => $code,
datefrom => $datefrom,
dateto => $dateto,
resultsperpage => $resultsperpage,
- name => $bookseller->{'name'},
+ name => $bookseller->name,
shipmentdate_today => dt_from_string,
booksellerid => $booksellerid,
GST => C4::Context->preference('gist'),
# 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 );
# 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 );
# 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 );
# 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 );
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;
}
);
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;
$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,
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(
$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;
}
# 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);
# 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 = ();
# 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,
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;
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({
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);
}
$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;
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;
$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 {
use C4::Breeding;
use C4::Koha;
-use Koha::Acquisition::Bookseller;
+use Koha::Acquisition::Booksellers;
use Koha::BiblioFrameworks;
my $input = new CGI;
# 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(
{
frameworks => $frameworks,
booksellerid => $booksellerid,
basketno => $basketno,
- name => $vendor->{'name'},
+ name => $vendor->name,
isbn => $isbn,
issn => $issn,
lccn => $lccn,
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",
$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
use C4::Context;
use C4::Output;
-use Koha::Acquisition::Bookseller;
+use Koha::Acquisition::Booksellers;
use Koha::Acquisition::Currency;
use Koha::Acquisition::Currencies;
# 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,
use C4::Search; # enabled_staff_search_views
use C4::Reserves qw(GetReservesFromBiblionumber);
-use Koha::Acquisition::Bookseller;
+use Koha::Acquisition::Booksellers;
use Koha::AuthorisedValues;
use Koha::DateUtils;
use Koha::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}) {
use C4::Acquisition qw( SearchOrders );
use Koha::DateUtils;
-use Koha::Acquisition::Bookseller;
+use Koha::Acquisition::Booksellers;
my $query=new CGI;
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
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} );
}
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} );
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 );
my $value = shift;
my $tax_rate = shift;
my $bookseller = shift;
- if ( $bookseller->{invoiceincgst} ) {
+ if ( $bookseller->invoiceincgst ) {
return $value / ( 1 + $tax_rate );
} else {
return $value;
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;
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');
[ 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');
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;
$order_0_0 = C4::Acquisition::populate_order_with_prices(
{
order => $order_0_0,
- booksellerid => 'just_something',
+ booksellerid => 1,
ordering => 1,
}
);
$order_0_0 = C4::Acquisition::populate_order_with_prices(
{
order => $order_0_0,
- booksellerid => 'just_something',
+ booksellerid => 1,
receiving => 1,
}
);
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 = {
$order_1_1 = C4::Acquisition::populate_order_with_prices(
{
order => $order_1_1,
- booksellerid => 'just_something',
+ booksellerid => 4,
ordering => 1,
}
);
$order_1_1 = C4::Acquisition::populate_order_with_prices(
{
order => $order_1_1,
- booksellerid => 'just_something',
+ booksellerid => 4,
receiving => 1,
}
);
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 = {
$order_1_0 = C4::Acquisition::populate_order_with_prices(
{
order => $order_1_0,
- booksellerid => 'just_something',
+ booksellerid => 3,
ordering => 1,
}
);
$order_1_0 = C4::Acquisition::populate_order_with_prices(
{
order => $order_1_0,
- booksellerid => 'just_something',
+ booksellerid => 3,
receiving => 1,
}
);
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 = {
$order_0_1 = C4::Acquisition::populate_order_with_prices(
{
order => $order_0_1,
- booksellerid => 'just_something',
+ booksellerid => 2,
ordering => 1,
}
);
$order_0_1 = C4::Acquisition::populate_order_with_prices(
{
order => $order_0_1,
- booksellerid => 'just_something',
+ booksellerid => 2,
receiving => 1,
}
);
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):
$dbh->{RaiseError} = 1;
# Creating some orders
-my $booksellerid = C4::Bookseller::AddBookseller(
+my $bookseller = Koha::Acquisition::Bookseller->new(
{
name => "my vendor",
address1 => "bookseller's address",
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 );
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;
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(
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;
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',
active => 1,
deliverytime => 5,
}
-);
+)->store;
+my $supplierid = $supplier->id;
my $basketno;
ok($basketno = NewBasket($supplierid, 1), 'NewBasket( $supplierid , 1 ) returns $basketno');
use Test::More;
use C4::Acquisition;
use C4::Biblio;
-use C4::Bookseller;
use C4::Budgets;
use Koha::Database;
use Koha::Acquisition::Order;
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(
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;
$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);
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();
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(
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();
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');
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;
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 );
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';
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;
});
# 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(
{
my $invoiceid = AddInvoice(
invoicenumber => 'invoice',
- booksellerid => $booksellerid,
+ booksellerid => $bookseller->id,
unknown => "unknown"
);
use C4::Acquisition;
use C4::Biblio;
use C4::Items;
-use C4::Bookseller;
use C4::Budgets;
use Koha::Acquisition::Order;
use t::lib::Mocks;
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;
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(
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
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(
use Modern::Perl;
use Test::More tests => 40;
-use C4::Bookseller qw( AddBookseller );
use C4::Context;
use Koha::AdditionalField;
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({
use Modern::Perl;
-use Test::More tests => 88;
+use Test::More tests => 86;
use Test::MockModule;
use Test::Warn;
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
$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',
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;
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 });
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(
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
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
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 =
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
}
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;
}
);
-my $booksellerid = C4::Bookseller::AddBookseller(
+my $bookseller = Koha::Acquisition::Bookseller->new(
{
name => "my vendor",
address1 => "bookseller's address",
active => 1,
deliverytime => 5,
}
-);
+)->store;
+my $booksellerid = $bookseller->id;
my $basketno = C4::Acquisition::NewBasket( $booksellerid, 1 );
my ( $biblionumber, $biblioitemnumber ) =
use Modern::Perl;
use C4::Context;
-use C4::Bookseller;
use Koha::DateUtils;
+use Koha::Acquisition::Booksellers;
use DateTime::Duration;
$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' );
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
-use Test::More tests => 80;
+use Test::More tests => 79;
use Test::MockModule;
use Test::Warn;
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();
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({
"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' );
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;
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",
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 );
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" );