'staticips', 'text', 'NULL', '', '', '',
'monitored', 'char', 'NULL', 1, '', '',
'last_pull', 'int', 'NULL', '', '', '',
- 'notes', 'text', 'NULL', '', '', '',
],
'primary_key' => 'svcnum',
'unique' => [ ],
'index' => [ ['phonenum'], ['vendor_order_id'] ],
},
-
+
+ 'dsl_note' => {
+ 'columns' => [
+ 'notenum', 'serial', '', '', '', '',
+ 'svcnum', 'int', '', '', '', '',
+ 'by', 'varchar', 'NULL', $char_d, '', '',
+ 'priority', 'char', 'NULL', 1, '', '',
+ 'date', 'int', 'NULL', '', '', '',
+ 'note', 'text', '', '', '', '',
+ ],
+ 'primary_key' => 'notenum',
+ 'unique' => [ ],
+ 'index' => [ ['svcnum'] ],
+ },
'domain_record' => {
'columns' => [
--- /dev/null
+package FS::dsl_note;
+
+use strict;
+use base qw( FS::Record );
+use FS::Record qw( qsearch qsearchs );
+
+=head1 NAME
+
+FS::dsl_note - Object methods for dsl_note records
+
+=head1 SYNOPSIS
+
+ use FS::dsl_note;
+
+ $record = new FS::dsl_note \%hash;
+ $record = new FS::dsl_note { 'column' => 'value' };
+
+ $error = $record->insert;
+
+ $error = $new_record->replace($old_record);
+
+ $error = $record->delete;
+
+ $error = $record->check;
+
+=head1 DESCRIPTION
+
+An FS::dsl_note object represents a DSL order note. FS::dsl_note inherits from
+FS::Record. The following fields are currently supported:
+
+=over 4
+
+=item notenum - primary key
+
+=item svcnum - the DSL for this note, see L<FS::svc_dsl>
+
+=item by - export-specific, e.g. note's author or ISP vs. telco/vendor
+
+=item priority - export-specific, e.g. high priority or not; not used by most
+
+=item date - note date
+
+=item note - the note
+
+
+=back
+
+=head1 METHODS
+
+=over 4
+
+=item new HASHREF
+
+Creates a new note. To add the note 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 { 'dsl_note'; }
+
+=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 note. 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('notenum')
+ || $self->ut_foreign_key('svcnum', 'svc_dsl', 'svcnum')
+ || $self->ut_textn('by')
+ || $self->ut_alphasn('priority')
+ || $self->ut_numbern('date')
+ || $self->ut_text('note')
+ ;
+ return $error if $error;
+
+ $self->SUPER::check;
+}
+
+=back
+
+=head1 SEE ALSO
+
+L<FS::Record>, schema.html from the base documentation.
+
+=cut
+
+1;
+
use vars qw(@ISA %info %orderType %orderStatus %loopType $DEBUG $me);
use Tie::IxHash;
use Date::Format qw( time2str );
+use Date::Parse qw( str2time );
use FS::Record qw(qsearch qsearchs);
use FS::part_export;
use FS::svc_dsl;
sub rebless { shift; }
sub dsl_pull {
+# we distinguish between invalid new data (return error) versus data that
+# has legitimately changed (may eventually execute hooks; now just update)
+
+ my($self, $svc_dsl) = (shift, shift);
+ my $result = $self->valid_order($svc_dsl,'pull');
+ return $result unless $result eq '';
+
+ $result = $self->ikano_command('ORDERSTATUS',
+ { OrderId => $svc_dsl->vendor_order_id } );
+ return $result unless ref($result); # scalar (string) is an error
+
+ # now we're getting an OrderResponse which should have one Order in it
+ warn "$me pull OrderResponse hash:\n".Dumper($result) if $DEBUG;
+
+ return 'Invalid order response' unless defined $result->{'Order'};
+ $result = $result->{'Order'};
+
+ return 'No order id or status returned'
+ unless defined $result->{'Status'} && defined $result->{'OrderId'};
+
+ # update this always (except in the above cases), even if error later
+ $svc_dsl->last_pull((time));
+ local $FS::svc_Common::noexport_hack = 1;
+ local $FS::UID::AutoCommit = 1;
+ my $error = $svc_dsl->replace;
+ return 'Error updating last pull time' if $error;
+
+ # let's compare what we have to what we got back...
+
+ # current assumptions of what won't change (from their side):
+ # vendor_order_id, vendor_qual_id, vendor_order_type, pushed, monitored,
+ # last_pull, address (from qual), contact info, ProductCustomId
+
+ my $wechanged = 0;
+
+ # 1. status
+ my $new_order_status = $self->orderstatus_long2short($result->{'Status'});
+ return 'Invalid new status' if $new_order_status eq '';
+ if($svc_dsl->vendor_order_status ne $new_order_status) {
+ if($new_order_status eq 'X' || $new_order_status eq 'C') {
+ $svc_dsl->monitored('');
+ }
+ $svc_dsl->vendor_order_status($new_order_status);
+ $wechanged = 1;
+ }
+
+ # 2. fields we don't care much about
+ my %justUpdate = ( 'first' => 'FirstName',
+ 'last' => 'LastName',
+ 'company' => 'CompanyName',
+ 'username' => 'Username',
+ 'password' => 'Password' );
+
+ while (($fsf, $ikanof) = each %justUpdate) {
+ if ( $result->{$ikanof} ne $svc_dsl->$fsf ) {
+ $svc_dsl->$fsf($result->{$ikanof});
+ $wechanged = 1;
+ }
+ }
+
+ # let's look inside the <Product> response element
+ my @product = $result->{'Product'};
+ return 'Invalid number of products on order' if scalar(@product) != 1;
+ my $product = $result->{'Product'}[0];
+
+ # 3. phonenum
+ if($svc_dsl->loop_type eq '') { # line-share
+ # TN may change only if sub changes it and
+ # New or Change order in Completed status
+ my $tn = $product->{'PhoneNumber'};
+ if($tn ne $svc_dsl->phonenum) {
+ if( ($svc_dsl->vendor_order_type eq 'N'
+ || $svc_dsl->vendor_order_type eq 'C')
+ && $svc_dsl->vendor_order_status eq 'C' ) {
+ $svc_dsl->phonenum($tn);
+ $wechanged = 1;
+ }
+ else { return 'TN has changed in an invalid state'; }
+ }
+ }
+ elsif($svc_dsl->loop_type eq '0') { # dry loop
+ return 'Invalid PhoneNumber value for a dry loop'
+ if $product->{'PhoneNumber'} ne 'STANDALONE';
+ my $tn = $product->{'VirtualPhoneNumber'};
+ if($tn ne $svc_dsl->phonenum) {
+ if( ($svc_dsl->vendor_order_type eq 'N'
+ || $svc_dsl->vendor_order_type eq 'C')
+ && $svc_dsl->vendor_order_status ne 'C'
+ && $svc_dsl->vendor_order_status ne 'X') {
+ $svc_dsl->phonenum($tn);
+ $wechanged = 1;
+ }
+ }
+ }
+
+ # 4. desired_due_date - may change if manually changed
+ if($svc_dsl->vendor_order_type eq 'N'
+ || $svc_dsl->vendor_order_type eq 'C'){
+ my $f = str2time($product->{'DateToOrder'});
+ return 'Invalid DateToOrder' unless $f;
+ if ( $svc_dsl->desired_due_date != $f ) {
+ $svc_dsl->desired_due_date($f);
+ $wechanged = 1;
+ }
+ # XXX: optionally sync back to start_date or whatever...
+ }
+ elsif($svc_dsl->vendor_order_type eq 'X'){
+ my $f = str2time($product->{'DateToDisconnect'});
+ return 'Invalid DateToDisconnect' unless $f;
+ if ( $svc_dsl->desired_due_date != $f ) {
+ $svc_dsl->desired_due_date($f);
+ $wechanged = 1;
+ }
+ # XXX: optionally sync back to expire or whatever...
+ }
+
+ # 4. due_date
+ if($svc_dsl->vendor_order_type eq 'N'
+ || $svc_dsl->vendor_order_type eq 'C') {
+ my $f = str2time($product->{'ActivationDate'});
+ if($svc_dsl->vendor_order_status ne 'N') {
+ return 'Invalid ActivationDate' unless $f;
+ if( $svc_dsl->due_date != $f ) {
+ $svc_dsl->due_date($f);
+ $wechanged = 1;
+ }
+ }
+ }
+ # Ikano API does not implement the proper disconnect date,
+ # so we can't do anything about it
+
+ # 6. staticips - for now just comma-separate them
+ my @statics = $result->{'StaticIps'};
+# XXX
+
+ # 7. notes - put them into the common format:
+ # "by" = 0 for Ikano; 1 for ISP
+ # "priority" = 1 for high priority; 0 otherwise
+ my @notes = $result->{'OrderNotes'};
+# XXX
+
+ if($wechanged) { # you can't check ->modified, the replace above screws it
+ # noexport_hack and AutoCommit are set correctly above
+ $result = $svc_dsl->replace;
+ return 'Error updating DSL data' if $result;
+ }
+
'';
}
-sub dsl_qual {
+sub qual {
'';
}
# weird ifs & long lines for readability and ease of understanding - don't change
if($svc_dsl->vendor_order_type eq 'N') {
if($svc_dsl->pushed) {
+ $error = !($action eq 'pull'
+ && length($svc_dsl->vendor_order_id) > 0
+ && length($svc_dsl->vendor_order_status) > 0
+ );
+ return 'Invalid order data' if $error;
}
else { # unpushed New order - cannot do anything other than push it
$error = !($action eq 'insert'
sub orderstatus_long2short {
my ($self,$order_status) = (shift,shift);
- while (($k, $v) = each %orderStatus) {
- return $k if $v eq $order_status;
- }
- return '';
+ my %rorderStatus = reverse %orderStatus;
+ return $rorderStatus{$order_status} if exists $rorderStatus{$order_status};
+ '';
}
sub _export_insert {