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

(-)a/C4/Bookseller.pm (-4 / +14 lines)
Lines 254-265 sub ModBookseller { Link Here
254
        $data->{'id'}
254
        $data->{'id'}
255
    );
255
    );
256
    $contacts ||= $data->{'contacts'};
256
    $contacts ||= $data->{'contacts'};
257
    my $contactquery = "DELETE FROM aqcontacts WHERE booksellerid = ?";
258
    my @contactparams = ($data->{'id'});
257
    if ($contacts) {
259
    if ($contacts) {
258
        $contacts->[0] = C4::Bookseller::Contact->new( $contacts->[0] )
260
        foreach my $contact (@$contacts) {
259
          unless ref $contacts->[0] eq 'C4::Bookseller::Contact';
261
            $contact = C4::Bookseller::Contact->new( $contact )
260
        $contacts->[0]->bookseller($data->{'id'});
262
                unless ref $contacts->[0] eq 'C4::Bookseller::Contact';
261
        $contacts->[0]->save();
263
            $contact->bookseller($data->{'id'});
264
            $contact->save();
265
            push @contactparams, $contact->id if $contact->id;
266
        }
267
        if ($#contactparams > 0) {
268
            $contactquery .= ' AND id NOT IN (' . ('?, ' x ($#contactparams - 1)) . '?);';
269
        }
262
    }
270
    }
271
    $sth = $dbh->prepare($contactquery);
272
    $sth->execute(@contactparams);
263
    return;
273
    return;
264
}
274
}
265
275
(-)a/C4/Bookseller/Contact.pm (-34 / +43 lines)
Lines 63-72 Contact's e-mail address. Link Here
63
63
64
Notes about contact.
64
Notes about contact.
65
65
66
=item primary
66
=item rank
67
67
68
Flag to indicate whether a contact is "primary" or not. Initially unused since
68
Ranking of the contact so that the contact can be given the correct
69
each bookseller can have only one contact.
69
priority in display.
70
70
71
=item bookseller
71
=item bookseller
72
72
Lines 81-87 use C4::Context; Link Here
81
81
82
use base qw(Class::Accessor);
82
use base qw(Class::Accessor);
83
83
84
__PACKAGE__->mk_accessors(qw(id name position phone altphone fax email notes primary bookseller));
84
__PACKAGE__->mk_accessors(qw(id name position phone altphone fax email notes rank bookseller));
85
85
86
=head1 METHODS
86
=head1 METHODS
87
87
Lines 90-96 __PACKAGE__->mk_accessors(qw(id name position phone altphone fax email notes pri Link Here
90
    my @contacts = @{C4::Bookseller::Contact->get_from_bookseller($booksellerid)};
90
    my @contacts = @{C4::Bookseller::Contact->get_from_bookseller($booksellerid)};
91
91
92
Returns a reference to an array of C4::Bookseller::Contact objects for the
92
Returns a reference to an array of C4::Bookseller::Contact objects for the
93
specified bookseller.
93
specified bookseller. This will always return at least one item, though that one
94
item may be an empty contact.
94
95
95
=cut
96
=cut
96
97
Lines 100-115 sub get_from_bookseller { Link Here
100
    return unless $bookseller;
101
    return unless $bookseller;
101
102
102
    my @contacts;
103
    my @contacts;
103
    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 = ?";
104
    my $query = "SELECT * FROM aqcontacts WHERE booksellerid = ?";
104
    # When we have our own table, we can use: my $query = "SELECT * FROM aqcontacts WHERE bookseller = ?";
105
    my $dbh = C4::Context->dbh;
105
    my $dbh = C4::Context->dbh;
106
    my $sth = $dbh->prepare($query);
106
    my $sth = $dbh->prepare($query);
107
    $sth->execute($bookseller);
107
    $sth->execute($bookseller);
108
    while (my $rec = $sth->fetchrow_hashref()) {
108
    while (my $rec = $sth->fetchrow_hashref()) {
109
        $rec->{'primary'} = 1;
110
        push @contacts, $class->new($rec);
109
        push @contacts, $class->new($rec);
111
    }
110
    }
112
111
112
    push @contacts, $class->new() unless @contacts;
113
113
    return \@contacts;
114
    return \@contacts;
114
}
115
}
115
116
Lines 123-143 because there is no separate table from which contacts can be fetched. Link Here
123
124
124
=cut
125
=cut
125
126
126
#sub fetch {
127
sub fetch {
127
#    my ($class, $id) = @_;
128
    my ($class, $id) = @_;
128
#
129
129
#    my $rec = { };
130
    my $rec = { };
130
#    if ($id) {
131
    if ($id) {
131
#        my $query = "SELECT * FROM aqcontacts WHERE id = ?";
132
        my $query = "SELECT * FROM aqcontacts WHERE id = ?";
132
#        my $dbh = C4::Context->dbh;
133
        my $dbh = C4::Context->dbh;
133
#        my $sth = $dbh->prepare($query);
134
        my $sth = $dbh->prepare($query);
134
#        $sth->execute($id);
135
        $sth->execute($id);
135
#        $rec = $sth->fetchrow_hashref();
136
        $rec = $sth->fetchrow_hashref();
136
#    }
137
    }
137
#    my $self = $class->SUPER::new($rec);
138
    my $self = $class->new($rec);
138
#    bless $self, $class;
139
    bless $self, $class;
139
#    return $self;
140
    return $self;
140
#}
141
}
141
142
142
=head2 save
143
=head2 save
143
144
Lines 151-171 sub save { Link Here
151
    my ($self) = @_;
152
    my ($self) = @_;
152
153
153
    my $query;
154
    my $query;
154
#    if ($self->id) {
155
    my @params = ($self->name, $self->position, $self->phone, $self->altphone, $self->fax, $self->email, $self->notes, $self->rank, $self->bookseller);
155
#        $query = 'UPDATE aqcontacts SET name = ?, position = ?, phone = ?, altphone = ?, fax = ?, email = ?, notes = ?, primary = ? WHERE id = ?;';
156
    if ($self->id) {
156
#    } else {
157
        $query = 'UPDATE aqcontacts SET name = ?, position = ?, phone = ?, altphone = ?, fax = ?, email = ?, notes = ?, rank = ?, booksellerid = ? WHERE id = ?;';
157
#        $query = 'INSERT INTO aqcontacts (name, position, phone, altphone, fax, email, notes, primary) VALUES (?, ?, ?, ?, ? ,? ,?, ?);';
158
        push @params, $self->id;
158
#    }
159
    if ($self->bookseller) {
160
        $query = 'UPDATE aqbooksellers SET contact = ?, contpos = ?, contphone = ?, contaltphone = ?, contfax = ?, contemail = ?, contnotes = ? WHERE id = ?;';
161
    } else {
159
    } else {
162
        return;
160
        $query = 'INSERT INTO aqcontacts (name, position, phone, altphone, fax, email, notes, rank, booksellerid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);';
163
    }
161
    }
164
    my $dbh = C4::Context->dbh;
162
    my $dbh = C4::Context->dbh;
165
    my $sth = $dbh->prepare($query);
163
    my $sth = $dbh->prepare($query);
166
    $sth->execute($self->name, $self->position, $self->phone, $self->altphone, $self->fax, $self->email, $self->notes, $self->bookseller);
164
    $sth->execute(@params);
167
    #$self->id = $dbh->last_insert_id(undef, undef, 'aqcontacts', undef);
165
    $self->id($dbh->{'mysql_insertid'}) unless $self->id;
168
    return $self->bookseller;
166
    return $self->id;
167
}
168
169
sub delete {
170
    my ($self) = @_;
171
172
    return unless $self->id;
173
174
    my $dbh = C4::Context->dbh;
175
    my $sth = $dbh->prepare("DELETE FROM aqcontacts WHERE id = ?;");
176
    $sth->execute($self->id);
177
    return;
169
}
178
}
170
179
171
=head1 AUTHOR
180
=head1 AUTHOR
(-)a/installer/data/mysql/kohastructure.sql (-7 / +21 lines)
Lines 2757-2771 CREATE TABLE `aqbooksellers` ( -- information about the vendors listed in acquis Link Here
2757
  `notes` mediumtext, -- order notes
2757
  `notes` mediumtext, -- order notes
2758
  `bookselleremail` mediumtext, -- vendor email
2758
  `bookselleremail` mediumtext, -- vendor email
2759
  `booksellerurl` mediumtext, -- unused in Koha
2759
  `booksellerurl` mediumtext, -- unused in Koha
2760
  `contact` varchar(100) default NULL, -- name of contact at vendor
2761
  `postal` mediumtext, -- vendor postal address (all lines)
2760
  `postal` mediumtext, -- vendor postal address (all lines)
2762
  `url` varchar(255) default NULL, -- vendor web address
2761
  `url` varchar(255) default NULL, -- vendor web address
2763
  `contpos` varchar(100) default NULL, -- contact person's position
2764
  `contphone` varchar(100) default NULL, -- contact's phone number
2765
  `contfax` varchar(100) default NULL,  -- contact's fax number
2766
  `contaltphone` varchar(100) default NULL, -- contact's alternate phone number
2767
  `contemail` varchar(100) default NULL, -- contact's email address
2768
  `contnotes` mediumtext, -- notes related to the contact
2769
  `active` tinyint(4) default NULL, -- is this vendor active (1 for yes, 0 for no)
2762
  `active` tinyint(4) default NULL, -- is this vendor active (1 for yes, 0 for no)
2770
  `listprice` varchar(10) default NULL, -- currency code for list prices
2763
  `listprice` varchar(10) default NULL, -- currency code for list prices
2771
  `invoiceprice` varchar(10) default NULL, -- currency code for invoice prices
2764
  `invoiceprice` varchar(10) default NULL, -- currency code for invoice prices
Lines 2861-2866 CREATE TABLE `aqbudgets_planning` ( Link Here
2861
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2854
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2862
2855
2863
--
2856
--
2857
-- Table structure for table 'aqcontacts'
2858
--
2859
2860
DROP TABLE IF EXISTS aqcontacts;
2861
CREATE TABLE aqcontacts (
2862
  id int(11) NOT NULL auto_increment, -- primary key and unique number assigned by Koha
2863
  name varchar(100) default NULL, -- name of contact at vendor
2864
  position varchar(100) default NULL, -- contact person's position
2865
  phone varchar(100) default NULL, -- contact's phone number
2866
  altphone varchar(100) default NULL, -- contact's alternate phone number
2867
  fax varchar(100) default NULL,  -- contact's fax number
2868
  email varchar(100) default NULL, -- contact's email address
2869
  notes mediumtext, -- notes related to the contact
2870
  rank SMALLINT default 0, -- display rank for the contact
2871
  booksellerid int(11) not NULL,
2872
  PRIMARY KEY  (id),
2873
  CONSTRAINT booksellerid_fk2 FOREIGN KEY (booksellerid)
2874
       REFERENCES aqbooksellers (id) ON DELETE CASCADE ON UPDATE CASCADE
2875
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
2876
2877
--
2864
-- Table structure for table 'aqcontract'
2878
-- Table structure for table 'aqcontract'
2865
--
2879
--
2866
2880
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +30 lines)
Lines 7104-7109 if ( CheckVersion($DBversion) ) { Link Here
7104
    SetVersion($DBversion);
7104
    SetVersion($DBversion);
7105
}
7105
}
7106
7106
7107
$DBversion = "3.13.00.XXX";
7108
if ( CheckVersion($DBversion) ) {
7109
    $dbh->do("CREATE TABLE aqcontacts (
7110
        id int(11) NOT NULL auto_increment,
7111
        name varchar(100) default NULL,
7112
        position varchar(100) default NULL,
7113
        phone varchar(100) default NULL,
7114
        altphone varchar(100) default NULL,
7115
        fax varchar(100) default NULL,
7116
        email varchar(100) default NULL,
7117
        notes mediumtext,
7118
        rank SMALLINT default 0,
7119
        booksellerid int(11) not NULL,
7120
        PRIMARY KEY  (id),
7121
        CONSTRAINT booksellerid_fk2 FOREIGN KEY (booksellerid)
7122
            REFERENCES aqbooksellers (id) ON DELETE CASCADE ON UPDATE CASCADE
7123
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;");
7124
    $dbh->do("INSERT INTO aqcontacts (name, position, phone, altphone, fax,
7125
            email, notes, booksellerid)
7126
        SELECT contact, contpos, contphone, contaltphone, contfax, contemail,
7127
            contnotes, id FROM aqbooksellers;");
7128
    $dbh->do("ALTER TABLE aqbooksellers DROP COLUMN contact,
7129
        DROP COLUMN contpos, DROP COLUMN contphone,
7130
        DROP COLUMN contaltphone, DROP COLUMN contfax,
7131
        DROP COLUMN contemail, DROP COLUMN contnotes;");
7132
    print "Upgrade to $DBversion done (Bug 10402: Move bookseller contacts to separate table)\n";
7133
    SetVersion($DBversion);
7134
}
7135
7136
7107
=head1 FUNCTIONS
7137
=head1 FUNCTIONS
7108
7138
7109
=head2 TableExists($table)
7139
=head2 TableExists($table)
7110
- 

Return to bug 10402