From 1d089b86f7701910ec015a28c9f046d0f30f49a6 Mon Sep 17 00:00:00 2001 From: Jared Camins-Esakov Date: Thu, 6 Jun 2013 22:38:19 -0400 Subject: [PATCH] Bug 10402: Use an object for contacts In preparation for adding the ability to handle multiple contacts, this patch moves booksellers' contacts into their own class, C4::Bookseller::Contact. To test: 1) Apply patch. 2) Run database update. 3) Edit a bookseller, making sure to add a contact. 4) View the bookseller's information, making sure the contact information is there. 5) Run the unit test: > prove t/db_dependent/Bookseller.t Signed-off-by: Owen Leonard Signed-off-by: Jared Camins-Esakov Signed-off-by: Paola Rossi Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi --- C4/Bookseller.pm | 81 ++++---- C4/Bookseller/Contact.pm | 177 ++++++++++++++++++ acqui/supplier.pl | 63 +------ acqui/uncertainprice.pl | 9 +- acqui/updatesupplier.pl | 36 ++-- .../prog/en/css/staff-global.css | 4 + .../prog/en/modules/acqui/supplier.tt | 78 +++++--- .../prog/en/modules/acqui/uncertainprice.tt | 18 +- t/db_dependent/Bookseller.t | 52 +++++ 9 files changed, 369 insertions(+), 149 deletions(-) create mode 100644 C4/Bookseller/Contact.pm diff --git a/C4/Bookseller.pm b/C4/Bookseller.pm index f317719d6f..768a8c39d9 100644 --- a/C4/Bookseller.pm +++ b/C4/Bookseller.pm @@ -23,6 +23,8 @@ use warnings; use base qw( Exporter ); +use C4::Bookseller::Contact; + # set the version for version checking our $VERSION = 3.07.00.049; our @EXPORT_OK = qw( @@ -52,8 +54,8 @@ a bookseller. @results = GetBookSeller($searchstring); -Looks up a book seller. C<$searchstring> may be either a book seller -ID, or a string to look for in the book seller's name. +Looks up a book seller. C<$searchstring> is a string to look for in the +book seller's name. C<@results> is an array of hash_refs whose keys are the fields of of the aqbooksellers table in the Koha database. @@ -90,6 +92,7 @@ sub GetBookSellerFromId { ( $vendor->{subscriptioncount} ) = $dbh->selectrow_array( 'SELECT count(*) FROM subscription WHERE aqbooksellerid = ?', {}, $id ); + $vendor->{'contacts'} = C4::Bookseller::Contact->get_from_bookseller($id); } return $vendor; } @@ -176,40 +179,42 @@ Returns the ID of the newly-created bookseller. =cut sub AddBookseller { - my ($data) = @_; + my ($data, $contacts) = @_; my $dbh = C4::Context->dbh; - my $query = q| + my $query = q| INSERT INTO aqbooksellers ( - name, address1, address2, address3, address4, - postal, phone, accountnumber,fax, url, - contact, contpos, contphone, contfax, contaltphone, - contemail, contnotes, active, listprice, invoiceprice, - gstreg, listincgst, invoiceincgst,gstrate, discount, - notes, deliverytime + name, address1, address2, address3, address4, + postal, phone, accountnumber,fax, url, + active, listprice, invoiceprice, gstreg, + listincgst,invoiceincgst, gstrate, discount, notes, + deliverytime ) - VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) | + 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->{contact}, - $data->{contpos} ,$data->{contphone}, - $data->{contfax} ,$data->{contaltphone}, - $data->{contemail} ,$data->{contnotes}, - $data->{active} ,$data->{listprice}, - $data->{invoiceprice} ,$data->{gstreg}, - $data->{listincgst} ,$data->{invoiceincgst}, - $data->{gstrate} ,$data->{discount}, - $data->{notes} ,$data->{deliverytime}, + $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->{'gstrate'}, $data->{'discount'}, + $data->{notes}, $data->{deliverytime}, ); # return the id of this new supplier - return $dbh->{'mysql_insertid'}; + my $id = $dbh->{'mysql_insertid'}; + if ($id && $contacts) { + $contacts->[0] = C4::Bookseller::Contact->new( $contacts->[0] ) + unless ref $contacts->[0] eq 'C4::Bookseller::Contact'; + $contacts->[0]->bookseller($id); + $contacts->[0]->save(); + } + return $id; } #-----------------------------------------------------------------# @@ -230,14 +235,13 @@ C<&ModBookseller> with the result. =cut sub ModBookseller { - my ($data) = @_; + 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=?,contact=?,contpos=?, - contphone=?,contfax=?,contaltphone=?,contemail=?, - contnotes=?,active=?,listprice=?, invoiceprice=?, + postal=?,phone=?,accountnumber=?,fax=?,url=?, + active=?,listprice=?, invoiceprice=?, gstreg=?,listincgst=?,invoiceincgst=?, discount=?,notes=?,gstrate=?,deliverytime=? WHERE id=?'; @@ -247,19 +251,22 @@ sub ModBookseller { $data->{'address2'}, $data->{'address3'}, $data->{'address4'}, $data->{'postal'}, $data->{'phone'}, $data->{'accountnumber'}, - $data->{'fax'}, - $data->{'url'}, $data->{'contact'}, - $data->{'contpos'}, $data->{'contphone'}, - $data->{'contfax'}, $data->{'contaltphone'}, - $data->{'contemail'}, $data->{'contnotes'}, + $data->{'fax'}, $data->{'url'}, $data->{'active'}, $data->{'listprice'}, $data->{'invoiceprice'}, $data->{'gstreg'}, $data->{'listincgst'}, $data->{'invoiceincgst'}, $data->{'discount'}, $data->{'notes'}, - $data->{'gstrate'}, - $data->{deliverytime}, + $data->{'gstrate'}, $data->{deliverytime}, $data->{'id'} ); + $contacts ||= $data->{'contacts'}; + if ($contacts) { + $contacts->[0] = C4::Bookseller::Contact->new( $contacts->[0] ) + unless ref $contacts->[0] eq 'C4::Bookseller::Contact'; + $contacts->[0]->bookseller($data->{'id'}); + $contacts->[0]->save(); + } + return; } =head2 DelBookseller diff --git a/C4/Bookseller/Contact.pm b/C4/Bookseller/Contact.pm new file mode 100644 index 0000000000..e08d66d53e --- /dev/null +++ b/C4/Bookseller/Contact.pm @@ -0,0 +1,177 @@ +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 primary + +Flag to indicate whether a contact is "primary" or not. Initially unused since +each bookseller can have only one contact. + +=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 primary 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. + +=cut + +sub get_from_bookseller { + my ($class, $bookseller) = @_; + + return unless $bookseller; + + my @contacts; + my $query = "SELECT contact AS name, contpos AS position, contphone AS phone, contaltphone AS altphone, contfax AS fax, contemail AS email, contnotes AS notes, id AS bookseller FROM aqbooksellers WHERE id = ?"; + # When we have our own table, we can use: my $query = "SELECT * FROM aqcontacts WHERE bookseller = ?"; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare($query); + $sth->execute($bookseller); + while (my $rec = $sth->fetchrow_hashref()) { + $rec->{'primary'} = 1; + push @contacts, $class->new($rec); + } + + 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->SUPER::new($rec); +# bless $self, $class; +# return $self; +#} + +=head2 save + + $contact->save(); + +Save a contact to the database. + +=cut + +sub save { + my ($self) = @_; + + my $query; +# if ($self->id) { +# $query = 'UPDATE aqcontacts SET name = ?, position = ?, phone = ?, altphone = ?, fax = ?, email = ?, notes = ?, primary = ? WHERE id = ?;'; +# } else { +# $query = 'INSERT INTO aqcontacts (name, position, phone, altphone, fax, email, notes, primary) VALUES (?, ?, ?, ?, ? ,? ,?, ?);'; +# } + if ($self->bookseller) { + $query = 'UPDATE aqbooksellers SET contact = ?, contpos = ?, contphone = ?, contaltphone = ?, contfax = ?, contemail = ?, contnotes = ? WHERE id = ?;'; + } else { + return; + } + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare($query); + $sth->execute($self->name, $self->position, $self->phone, $self->altphone, $self->fax, $self->email, $self->notes, $self->bookseller); + #$self->id = $dbh->last_insert_id(undef, undef, 'aqcontacts', undef); + return $self->bookseller; +} + +=head1 AUTHOR + +Jared Camins-Esakov + +=cut + +1; diff --git a/acqui/supplier.pl b/acqui/supplier.pl index e2c688f435..16d6ee4e05 100755 --- a/acqui/supplier.pl +++ b/acqui/supplier.pl @@ -49,14 +49,10 @@ use C4::Output; use CGI; use C4::Bookseller qw( GetBookSellerFromId DelBookseller ); +use C4::Bookseller::Contact; use C4::Budgets; my $query = CGI->new; -my $booksellerid = $query->param('booksellerid'); -my $supplier = {}; -if ($booksellerid) { - $supplier = GetBookSellerFromId($booksellerid); -} my $op = $query->param('op') || 'display'; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => 'acqui/supplier.tt', @@ -67,38 +63,23 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( debug => 1, } ); +my $booksellerid = $query->param('booksellerid'); +my $supplier = {}; +if ($booksellerid) { + $supplier = GetBookSellerFromId($booksellerid); + foreach ( keys $supplier ) { + $template->{'VARS'}->{$_} = $supplier->{$_}; + } + $template->{'VARS'}->{'booksellerid'} = $booksellerid; +} #build array for currencies if ( $op eq 'display' ) { my $contracts = GetContracts( { booksellerid => $booksellerid } ); $template->param( - booksellerid => $booksellerid, - name => $supplier->{'name'}, - postal => $supplier->{'postal'}, - address1 => $supplier->{'address1'}, - address2 => $supplier->{'address2'}, - address3 => $supplier->{'address3'}, - address4 => $supplier->{'address4'}, - phone => $supplier->{'phone'}, - accountnumber => $supplier->{'accountnumber'}, - fax => $supplier->{'fax'}, - url => $supplier->{'url'}, - contact => $supplier->{'contact'}, - contpos => $supplier->{'contpos'}, - contphone => $supplier->{'contphone'}, - contaltphone => $supplier->{'contaltphone'}, - contfax => $supplier->{'contfax'}, - contemail => $supplier->{'contemail'}, - contnotes => $supplier->{'contnotes'}, - notes => $supplier->{'notes'}, active => $supplier->{'active'}, - gstreg => $supplier->{'gstreg'}, - listincgst => $supplier->{'listincgst'}, - invoiceincgst => $supplier->{'invoiceincgst'}, gstrate => $supplier->{'gstrate'} + 0.0, - discount => $supplier->{'discount'}, - deliverytime => $supplier->{deliverytime}, invoiceprice => $supplier->{'invoiceprice'}, listprice => $supplier->{'listprice'}, basketcount => $supplier->{'basketcount'}, @@ -140,34 +121,10 @@ if ( $op eq 'display' ) { }, split( '\|', C4::Context->preference("gist") ); $template->param( - booksellerid => $booksellerid, - name => $supplier->{'name'}, - postal => $supplier->{'postal'}, - address1 => $supplier->{'address1'}, - address2 => $supplier->{'address2'}, - address3 => $supplier->{'address3'}, - address4 => $supplier->{'address4'}, - phone => $supplier->{'phone'}, - accountnumber=> $supplier->{'accountnumber'}, - fax => $supplier->{'fax'}, - url => $supplier->{'url'}, - contact => $supplier->{'contact'}, - contpos => $supplier->{'contpos'}, - contphone => $supplier->{'contphone'}, - contaltphone => $supplier->{'contaltphone'}, - contfax => $supplier->{'contfax'}, - contemail => $supplier->{'contemail'}, - contnotes => $supplier->{'contnotes'}, - notes => $supplier->{'notes'}, # set active ON by default for supplier add (id empty for add) active => $booksellerid ? $supplier->{'active'} : 1, - gstreg => $supplier->{'gstreg'}, - listincgst => $supplier->{'listincgst'}, - invoiceincgst => $supplier->{'invoiceincgst'}, gstrate => $supplier->{gstrate} ? $supplier->{'gstrate'}+0.0 : 0, gst_values => \@gst_values, - discount => $supplier->{'discount'}, - deliverytime => $supplier->{deliverytime}, loop_currency => $loop_currency, enter => 1, ); diff --git a/acqui/uncertainprice.pl b/acqui/uncertainprice.pl index 83bdea6352..0b680d85d4 100755 --- a/acqui/uncertainprice.pl +++ b/acqui/uncertainprice.pl @@ -52,6 +52,7 @@ use C4::Output; use CGI; use C4::Bookseller qw/GetBookSellerFromId/; +use C4::Bookseller::Contact; use C4::Acquisition qw/SearchOrders GetOrder ModOrder/; use C4::Biblio qw/GetBiblioData/; @@ -124,16 +125,10 @@ $template->param( uncertainpriceorders => \@orders, booksellerphone =>$bookseller->{'phone'}, booksellerfax => $bookseller->{'fax'}, booksellerurl => $bookseller->{'url'}, - booksellercontact => $bookseller->{'contact'}, - booksellercontpos => $bookseller->{'contpos'}, - booksellercontphone => $bookseller->{'contphone'}, - booksellercontaltphone => $bookseller->{'contaltphone'}, - booksellercontfax => $bookseller->{'contfax'}, - booksellercontemail => $bookseller->{'contemail'}, - booksellercontnotes => $bookseller->{'contnotes'}, booksellernotes => $bookseller->{'notes'}, basketcount => $bookseller->{'basketcount'}, subscriptioncount => $bookseller->{'subscriptioncount'}, owner => $owner, scriptname => "/cgi-bin/koha/acqui/uncertainprice.pl"); +$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 7b3bf9d6d8..77fa2761d1 100755 --- a/acqui/updatesupplier.pl +++ b/acqui/updatesupplier.pl @@ -45,11 +45,13 @@ list_currency, gst, list_gst, invoice_gst, discount, gstrate. =cut use strict; -#use warnings; FIXME - Bug 2505 +use warnings; +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 CGI; @@ -83,13 +85,6 @@ $data{'phone'}=$input->param('company_phone'); $data{'accountnumber'}=$input->param('accountnumber'); $data{'fax'}=$input->param('company_fax'); $data{'url'}=$input->param('website'); -$data{'contact'}=$input->param('company_contact_name'); -$data{'contpos'}=$input->param('company_contact_position'); -$data{'contphone'}=$input->param('contact_phone'); -$data{'contaltphone'}=$input->param('contact_phone_2'); -$data{'contfax'}=$input->param('contact_fax'); -$data{'contemail'}=$input->param('company_email'); -$data{'contnotes'}=$input->param('contact_notes'); # warn "".$data{'contnotes'}; $data{'notes'}=$input->param('notes'); $data{'active'}=$input->param('status'); @@ -104,14 +99,29 @@ $data{'gstrate'} = $input->param('gstrate'); $data{'discount'} = $input->param('discount'); $data{deliverytime} = $input->param('deliverytime'); $data{'active'}=$input->param('status'); +my @contacts; +my %contact_info; + +foreach (qw(id name position phone altphone fax email notes)) { + $contact_info{$_} = [ $input->param('contact_' . $_) ]; +} + +for my $cnt (0..scalar(@{$contact_info{'id'}})) { + my %contact; + foreach (qw(id name position phone altphone fax email notes)) { + $contact{$_} = $contact_info{$_}->[$cnt]; + } + push @contacts, C4::Bookseller::Contact->new(\%contact); +} + if($data{'name'}) { if ($data{'id'}){ - ModBookseller(\%data); + ModBookseller(\%data, \@contacts); } else { - $data{id}=AddBookseller(\%data); + $data{id}=AddBookseller(\%data, \@contacts); } -#redirect to booksellers.pl -print $input->redirect("booksellers.pl?booksellerid=".$data{id}); + #redirect to booksellers.pl + print $input->redirect("booksellers.pl?booksellerid=".$data{id}); } else { -print $input->redirect("supplier.pl?op=enter"); # fail silently. + print $input->redirect("supplier.pl?op=enter"); # fail silently. } diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css index bbd845828f..f08fe54e18 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css @@ -1962,6 +1962,10 @@ div#acqui_order_supplierlist > div.supplier > div.baskets { margin-top: 0.5em; } +.supplier-contact-details { + float: left; +} + /* Override core jQueryUI widgets */ .ui-widget-content { border: 1px solid #B9D8D9; background: #ffffff none; color: #222222; } .ui-widget-header { border: 1px solid #B9D8D9; background: #E6F0F2 none; color: #222222; font-weight: bold; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt index f54b1ea5e9..e851a64281 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt @@ -1,4 +1,36 @@ [% USE KohaDates %] +[% BLOCK edit_contact %] +
    + +
  1. +
  2. +
  3. +
  4. +
  5. +
  6. +
  7. +
  8. +
  9. +
  10. +
  11. +
  12. +
  13. +
  14. +
+[% END %] +[% BLOCK show_contact %] +

Contact name: [% contact.name %]

+

Position: [% contact.position %]

+

Phone: [% contact.phone %]

+

Alternative phone: [% contact.altphone %]

+

Fax: [% contact.fax %]

+ [% IF ( contact.email ) %] +

Email: [% contact.email %]

+ [% END %] + [% IF ( contact.notes ) %] +

Notes: [% contact.notes %]

+ [% END %] +[% END %] [% INCLUDE 'doc-head-open.inc' %] Koha › Vendor [% bookselname %] @@ -13,6 +45,9 @@ function confirm_deletion() { } } +function add_contact() { +} + $(document).ready(function() { var contractst = $("#contractst").dataTable($.extend(true, {}, dataTablesDefaults, { "aoColumnDefs": [ @@ -65,23 +100,12 @@ function confirm_deletion() {
  • -
    - Contact details -
    1. -
    2. -
    3. -
    4. -
    5. -
    6. -
    7. -
    8. -
    9. -
    10. -
    11. -
    12. -
    13. -
    -
    + [% FOREACH contact IN contacts %] +
    + Contact details + [% INCLUDE edit_contact %] +
    + [% END %]
    @@ -191,20 +215,12 @@ function confirm_deletion() {

    Account number: [% accountnumber %]

    [% END %]
    -
    -

    Contact details

    -

    Contact name: [% contact %]

    -

    Position: [% contpos %]

    -

    Phone: [% contphone %]

    -

    Alternative phone: [% contaltphone %]

    -

    Fax: [% contfax %]

    - [% IF ( contemail ) %] -

    Email: [% contemail %]

    - [% END %] - [% IF ( contnotes ) %] -

    Notes: [% contnotes %]

    - [% END %] -
    + [% FOREACH contact IN contacts %] +
    +

    Contact details

    + [% INCLUDE show_contact %] +
    + [% END %]

    Ordering information

    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/uncertainprice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/uncertainprice.tt index 41aad00a08..a503f2bbdf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/uncertainprice.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/uncertainprice.tt @@ -56,14 +56,16 @@ function check(form) { [% booksellerphone %] / Fax: [% booksellerfax %]

    -
    Contact:
    -
    [% booksellercontact %] - [% booksellercontpos %] - [% booksellercontphone %] - [% booksellercontaltphone %] - [% booksellercontemail %] - [% booksellercontnotes %] -
    + [% FOREACH contact IN contacts %] +
    Contact:
    +
    [% contact.name %] + [% contact.position %] + [% contact.phone %] + [% contact.altphone %] + [% contact.email %] + [% contact.notes %] +
    + [% END %]
    [% IF ( booksellernotes ) %]

    Notes: diff --git a/t/db_dependent/Bookseller.t b/t/db_dependent/Bookseller.t index c7ea24cd18..2f73c8123e 100644 --- a/t/db_dependent/Bookseller.t +++ b/t/db_dependent/Bookseller.t @@ -702,6 +702,58 @@ is( 3, 'superlibrarian can see all subscriptions with IndependentBranches on (bug 12048)' ); +#Test contact editing +my $booksellerid = C4::Bookseller::AddBookseller( + { + name => "my vendor", + address1 => "bookseller's address", + phone => "0123456", + active => 1 + }, + [ { name => 'John Smith', phone => '0123456x1' } ] +); + +my @booksellers = C4::Bookseller::GetBookSeller('my vendor'); +ok( + (grep { $_->{'id'} == $booksellerid } @booksellers), + 'GetBookSeller returns correct record when passed a name' +); + +my $bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid); +is( $bookseller->{'id'}, $booksellerid, 'Retrieved desired record' ); +is( $bookseller->{'phone'}, '0123456', 'New bookseller has expected phone' ); +is( ref $bookseller->{'contacts'}, + 'ARRAY', 'GetBookSellerFromId returns arrayref of contacts' ); +is( + ref $bookseller->{'contacts'}->[0], + 'C4::Bookseller::Contact', + 'First contact is a contact object' +); +is( $bookseller->{'contacts'}->[0]->phone, + '0123456x1', 'Contact has expected phone number' ); + +$bookseller->{'name'} = 'your vendor'; +$bookseller->{'contacts'}->[0]->phone('654321'); +C4::Bookseller::ModBookseller($bookseller); + +$bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid); +is( $bookseller->{'name'}, 'your vendor', + 'Successfully changed name of vendor' ); +is( $bookseller->{'contacts'}->[0]->phone, + '654321', + 'Successfully changed contact phone number by modifying bookseller hash' ); + +C4::Bookseller::ModBookseller( $bookseller, + [ { name => 'John Jacob Jingleheimer Schmidt' } ] ); + +$bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid); +is( + $bookseller->{'contacts'}->[0]->name, + 'John Jacob Jingleheimer Schmidt', + 'Changed name of contact' +); +is( $bookseller->{'contacts'}->[0]->phone, + undef, 'Removed phone number from contact' ); #End transaction $dbh->rollback; -- 2.39.5