summaryrefslogtreecommitdiff
path: root/FS/FS
diff options
context:
space:
mode:
authorlevinse <levinse>2010-12-08 21:37:45 +0000
committerlevinse <levinse>2010-12-08 21:37:45 +0000
commit19f2731dbceb444c5dd45f57fb0a785dcaf9aa65 (patch)
treea4bcff91ee75260b0f0384b6888b86f7c0232d29 /FS/FS
parentdf2bf964527e0b5596af471b1b7d84d14305b2a2 (diff)
-rename qual export sub to part_export, RT7111
-initial commit of part_pkg_vendor implementation, RT7111
Diffstat (limited to 'FS/FS')
-rw-r--r--FS/FS/Mason.pm1
-rw-r--r--FS/FS/Schema.pm12
-rw-r--r--FS/FS/part_export/ikano.pm2
-rw-r--r--FS/FS/part_pkg.pm85
-rw-r--r--FS/FS/part_pkg_vendor.pm140
-rw-r--r--FS/FS/qual.pm2
6 files changed, 241 insertions, 1 deletions
diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm
index c132074..3b46d77 100644
--- a/FS/FS/Mason.pm
+++ b/FS/FS/Mason.pm
@@ -262,6 +262,7 @@ if ( -e $addl_handler_use_file ) {
use FS::qual;
use FS::qual_option;
use FS::dsl_note;
+ use FS::part_pkg_vendor;
# Sammath Naur
if ( $FS::Mason::addl_handler_use ) {
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 7cccc7f..48363ce 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -2323,6 +2323,18 @@ sub tables_hashref {
'index' => [ [ 'pkgpart' ], [ 'optionname' ] ],
},
+ 'part_pkg_vendor' => {
+ 'columns' => [
+ 'num', 'serial', '', '', '', '',
+ 'pkgpart', 'int', '', '', '', '',
+ 'exportnum', 'int', '', '', '', '',
+ 'vendor_pkg_id', 'varchar', '', $char_d, '', '',
+ ],
+ 'primary_key' => 'num',
+ 'unique' => [ [ 'pkgpart', 'exportnum' ] ],
+ 'index' => [ [ 'pkgpart' ] ],
+ },
+
'part_pkg_report_option' => {
'columns' => [
'num', 'serial', '', '', '', '',
diff --git a/FS/FS/part_export/ikano.pm b/FS/FS/part_export/ikano.pm
index afed6f4..30e2bac 100644
--- a/FS/FS/part_export/ikano.pm
+++ b/FS/FS/part_export/ikano.pm
@@ -40,6 +40,8 @@ END
sub rebless { shift; }
+sub external_pkg_map { 1; }
+
sub dsl_pull {
# we distinguish between invalid new data (return error) versus data that
# has legitimately changed (may eventually execute hooks; now just update)
diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm
index 98bb74c..46067d1 100644
--- a/FS/FS/part_pkg.pm
+++ b/FS/FS/part_pkg.pm
@@ -275,6 +275,23 @@ sub insert {
}
}
+ if ( $options{'part_pkg_vendor'} ) {
+ my($exportnum,$vendor_pkg_id);
+ my %options_part_pkg_vendor = $options{'part_pkg_vendor'};
+ while(($exportnum,$vendor_pkg_id) = each %options_part_pkg_vendor){
+ my $ppv = new FS::part_pkg_vendor( {
+ 'pkgpart' => $self->pkgpart,
+ 'exportnum' => $exportnum,
+ 'vendor_pkg_id' => $vendor_pkg_id,
+ } );
+ my $error = $ppv->insert;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Error inserting part_pkg_vendor record: $error";
+ }
+ }
+ }
+
warn " commiting transaction" if $DEBUG;
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
@@ -432,6 +449,51 @@ sub replace {
return $error;
}
}
+
+ my @part_pkg_vendor = $old->part_pkg_vendor;
+ my @current_exportnum = ();
+ if ( $options->{'part_pkg_vendor'} ) {
+ my($exportnum,$vendor_pkg_id);
+ while ( ($exportnum,$vendor_pkg_id)
+ = each %{$options->{'part_pkg_vendor'}} ) {
+ my $replaced = 0;
+ foreach my $part_pkg_vendor ( @part_pkg_vendor ) {
+ if($exportnum == $part_pkg_vendor->exportnum
+ && $vendor_pkg_id ne $part_pkg_vendor->vendor_pkg_id) {
+ $part_pkg_vendor->vendor_pkg_id($vendor_pkg_id);
+ my $error = $part_pkg_vendor->replace;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Error replacing part_pkg_vendor record: $error";
+ }
+ $replaced = 1;
+ last;
+ }
+ }
+ unless ( $replaced ) {
+ my $ppv = new FS::part_pkg_vendor( {
+ 'pkgpart' => $new->pkgpart,
+ 'exportnum' => $exportnum,
+ 'vendor_pkg_id' => $vendor_pkg_id,
+ } );
+ my $error = $ppv->insert;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Error inserting part_pkg_vendor record: $error";
+ }
+ }
+ push @current_exportnum, $exportnum;
+ }
+ }
+ foreach my $part_pkg_vendor ( @part_pkg_vendor ) {
+ unless ( grep($_ eq $part_pkg_vendor->exportnum, @current_exportnum) ) {
+ my $error = $part_pkg_vendor->delete;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Error deleting part_pkg_vendor record: $error";
+ }
+ }
+ }
warn " commiting transaction" if $DEBUG;
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
@@ -885,6 +947,29 @@ sub plandata {
}
}
+=item part_pkg_vendor
+
+Returns all vendor/external package ids as FS::part_pkg_vendor objects (see
+L<FS::part_pkg_vendor>).
+
+=cut
+
+sub part_pkg_vendor {
+ my $self = shift;
+ qsearch('part_pkg_vendor', { 'pkgpart' => $self->pkgpart } );
+}
+
+=item vendor_pkg_ids
+
+Returns a list of vendor/external package ids by exportnum
+
+=cut
+
+sub vendor_pkg_ids {
+ my $self = shift;
+ map { $_->exportnum => $_->vendor_pkg_id } $self->part_pkg_vendor;
+}
+
=item part_pkg_option
Returns all options as FS::part_pkg_option objects (see
diff --git a/FS/FS/part_pkg_vendor.pm b/FS/FS/part_pkg_vendor.pm
new file mode 100644
index 0000000..6b91f75
--- /dev/null
+++ b/FS/FS/part_pkg_vendor.pm
@@ -0,0 +1,140 @@
+package FS::part_pkg_vendor;
+
+use strict;
+use base qw( FS::Record );
+use FS::Record qw( qsearch qsearchs );
+
+=head1 NAME
+
+FS::part_pkg_vendor - Object methods for part_pkg_vendor records
+
+=head1 SYNOPSIS
+
+ use FS::part_pkg_vendor;
+
+ $record = new FS::part_pkg_vendor \%hash;
+ $record = new FS::part_pkg_vendor { 'column' => 'value' };
+
+ $error = $record->insert;
+
+ $error = $new_record->replace($old_record);
+
+ $error = $record->delete;
+
+ $error = $record->check;
+
+=head1 DESCRIPTION
+
+An FS::part_pkg_vendor object represents a mapping of pkgpart numbers to
+external package numbers. FS::part_pkg_vendor inherits from FS::Record.
+The following fields are currently supported:
+
+=over 4
+
+=item num
+
+primary key
+
+=item pkgpart
+
+pkgpart
+
+=item exportnum
+
+exportnum
+
+=item vendor_pkg_id
+
+vendor_pkg_id
+
+
+=back
+
+=head1 METHODS
+
+=over 4
+
+=item new HASHREF
+
+Creates a new example. To add the example to the database, see L<"insert">.
+
+Note that this stores the hash reference, not a distinct copy of the hash it
+points to. You can ask the object for a copy with the I<hash> method.
+
+=cut
+
+# the new method can be inherited from FS::Record, if a table method is defined
+
+sub table { 'part_pkg_vendor'; }
+
+=item insert
+
+Adds this record to the database. If there is an error, returns the error,
+otherwise returns false.
+
+=cut
+
+# the insert method can be inherited from FS::Record
+
+=item delete
+
+Delete this record from the database.
+
+=cut
+
+# the delete method can be inherited from FS::Record
+
+=item replace OLD_RECORD
+
+Replaces the OLD_RECORD with this one in the database. If there is an error,
+returns the error, otherwise returns false.
+
+=cut
+
+# the replace method can be inherited from FS::Record
+
+=item check
+
+Checks all fields to make sure this is a valid example. If there is
+an error, returns the error, otherwise returns false. Called by the insert
+and replace methods.
+
+=cut
+
+# the check method should currently be supplied - FS::Record contains some
+# data checking routines
+
+sub check {
+ my $self = shift;
+
+ my $error =
+ $self->ut_numbern('num')
+ || $self->ut_foreign_key('pkgpart', 'part_pkg', 'pkgpart')
+ || $self->ut_foreign_key('exportnum', 'part_export', 'exportnum')
+ || $self->ut_textn('vendor_pkg_id')
+ ;
+ return $error if $error;
+
+ $self->SUPER::check;
+}
+
+=item part_export
+
+Returns the L<FS::part_export> associated with this vendor/external package id.
+
+=cut
+sub part_export {
+ my $self = shift;
+ qsearchs( 'part_export', { 'exportnum' => $self->exportnum } );
+}
+
+=back
+
+=head1 SEE ALSO
+
+L<FS::part_pkg>, L<FS::Record>, schema.html from the base documentation.
+
+=cut
+
+1;
+
diff --git a/FS/FS/qual.pm b/FS/FS/qual.pm
index 1bc3397..23a8272 100644
--- a/FS/FS/qual.pm
+++ b/FS/FS/qual.pm
@@ -127,7 +127,7 @@ sub check {
$self->SUPER::check;
}
-sub export {
+sub part_export {
my $self = shift;
if ( $self->exportnum ) {
return qsearchs('part_export', { exportnum => $self->exportnum } )