[freeside-commits] freeside/FS/FS/part_export ikano.pm,1.15,1.16

Erik Levinson levinse at wavetail.420.am
Thu Dec 9 11:26:22 PST 2010


Update of /home/cvs/cvsroot/freeside/FS/FS/part_export
In directory wavetail.420.am:/tmp/cvs-serv14877/FS/FS/part_export

Modified Files:
	ikano.pm 
Log Message:
-change ikano.pm to use the new part_pkg_vendor, RT7111
-implement service expiry and add export expire to ikano, RT7111
-fix edit part_pkg bug, RT7111


Index: ikano.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_export/ikano.pm,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -w -d -r1.15 -r1.16
--- ikano.pm	8 Dec 2010 21:37:45 -0000	1.15
+++ ikano.pm	9 Dec 2010 19:26:19 -0000	1.16
@@ -52,7 +52,6 @@
 # vendor_order_id, vendor_qual_id, vendor_order_type, pushed, monitored,
 # last_pull, address (from qual), contact info, ProductCustomId
     my($self, $svc_dsl, $threshold) = (shift, shift, shift);
-    $self->loadmod;
     my $result = $self->valid_order($svc_dsl,'pull');
     return $result unless $result eq '';
 
@@ -332,7 +331,9 @@
     my $list = "<B>Qualifying Packages:</B><UL>";
     my @part_pkgs = qsearch( 'part_pkg', { 'disabled' => '' } );
     foreach my $part_pkg ( @part_pkgs ) {
-	my $externalid = $part_pkg->option('externalid',1);
+	my %vendor_pkg_ids = $part_pkg->vendor_pkg_ids;
+	my $externalid = $vendor_pkg_ids{$self->exportnum} 
+	    if defined $vendor_pkg_ids{$self->exportnum};
 	if ( $externalid ) {
 	    $list .= "<LI>".$part_pkg->pkgpart.": ".$part_pkg->pkg." - "
 		.$part_pkg->comment."</LI>" 
@@ -404,8 +405,9 @@
 	    );
   return 'Missing or invalid order data' if $error;
   
+  my %vendor_pkg_ids = $svc_dsl->cust_svc->cust_pkg->part_pkg->vendor_pkg_ids;
   return 'Package does not have an external id configured'
-    if $svc_dsl->cust_svc->cust_pkg->part_pkg->options('externalid',1) eq '';
+    unless defined $vendor_pkg_ids{$self->exportnum};
 
   return 'No valid qualification for this order' 
     unless qsearch( 'qual', { 'vendor_qual_id' => $svc_dsl->vendor_qual_id });
@@ -415,7 +417,7 @@
   if($svc_dsl->vendor_order_type eq 'NEW') {
     if($svc_dsl->pushed) {
 	$error = !( ($action eq 'pull' || $action eq 'statuschg' 
-			|| $action eq 'delete')
+			|| $action eq 'delete' || $action eq 'expire')
 	    && 	length($svc_dsl->vendor_order_id) > 0
 	    && 	length($svc_dsl->vendor_order_status) > 0
 		);
@@ -463,8 +465,6 @@
 sub _export_insert {
   my( $self, $svc_dsl ) = (shift, shift);
 
-  $self->loadmod;
-
   my $result = $self->valid_order($svc_dsl,'insert');
   return $result unless $result eq '';
 
@@ -472,7 +472,8 @@
   my $contactTN = $svc_dsl->cust_svc->cust_pkg->cust_main->daytime;
   $contactTN =~ s/[^0-9]//g;
 
-  my $ProductCustomId = $svc_dsl->cust_svc->cust_pkg->part_pkg->option('externalid',1);
+  my %vendor_pkg_ids = $svc_dsl->cust_svc->cust_pkg->part_pkg->vendor_pkg_ids;
+  my $ProductCustomId = $vendor_pkg_ids{$self->exportnum};
 
   my $args = {
 	orderType => 'NEW',
@@ -551,7 +552,7 @@
   return $result unless $result eq '';
 
   # for now allow an immediate cancel only on New orders in New/Pending status
-  #XXX: add support for Chance and Cancel orders in New/Pending status later
+  #XXX: add support for Change and Cancel orders in New/Pending status later
 
   if($svc_dsl->vendor_order_type eq 'NEW') {
     if($svc_dsl->vendor_order_status eq 'NEW' 
@@ -572,6 +573,10 @@
 	return "Cannot cancel a NEW order unless it's in NEW or PENDING status";
     }
   }
+  elsif($svc_dsl->vendor_order_type eq 'CANCEL') {
+     return 'Cannot cancel a CANCEL order unless expire was set'
+	unless $svc_dsl->cust_svc->cust_pkg->expire > 0;
+  }
   else {
     return 'Canceling orders other than NEW orders is not currently implemented';
   }
@@ -579,6 +584,83 @@
   '';
 }
 
+sub export_expire {
+  my($self, $svc_dsl, $date) = (shift, shift, shift);
+  
+  my $result = $self->valid_order($svc_dsl,'expire');
+  return $result unless $result eq '';
+  
+  # for now allow a proper cancel only on New orders in Completed status
+  #XXX: add support for some other cases in future
+  
+  if($svc_dsl->vendor_order_type eq 'NEW' 
+	&& $svc_dsl->vendor_order_status eq 'COMPLETED') {
+    
+	  my $contactTN = $svc_dsl->cust_svc->cust_pkg->cust_main->daytime;
+	  $contactTN =~ s/[^0-9]//g;
+
+	  my %vendor_pkg_ids = $svc_dsl->cust_svc->cust_pkg->part_pkg->vendor_pkg_ids;
+	  my $ProductCustomId = $vendor_pkg_ids{$self->exportnum};
+
+	  # we are now a cancel order
+	  $svc_dsl->desired_due_date($date);
+	  $svc_dsl->vendor_order_type('CANCEL');
+
+	  my $args = {
+		orderType => 'CANCEL',
+		ProductCustomId => $ProductCustomId,
+		TermsId => $self->qual2termsid($svc_dsl->vendor_qual_id,$ProductCustomId),
+		DSLPhoneNumber => $svc_dsl->loop_type eq '0' ? 'STANDALONE'
+							    : $svc_dsl->phonenum,
+		Password => $svc_dsl->password,
+		PrequalId => $svc_dsl->vendor_qual_id,
+		CompanyName => $svc_dsl->company,
+		FirstName => $svc_dsl->first,
+		LastName => $svc_dsl->last,
+		MiddleName => '',
+		ContactMethod => 'PHONE',
+		ContactPhoneNumber => $contactTN,
+		ContactEmail => 'x at x.xx',
+		ContactFax => '',
+		DateToOrder => time2str("%Y-%m-%d",$date),
+		RequestClientIP => '127.0.0.1',
+		IspChange => 'NO',
+		IspPrevious => '',
+		CurrentProvider => '',
+	  };
+
+	  $args->{'VirtualPhoneNumber'} = $svc_dsl->phonenum 
+	    if $svc_dsl->loop_type eq '0';
+
+	  $result = $self->ikano_command('ORDER',$args); 
+	  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 _export_insert OrderResponse hash:\n".Dumper($result)
+		if $self->option('debug');
+	  
+	  return 'Invalid order response' unless defined $result->{'Order'};
+	  $result = $result->{'Order'};
+
+	  return 'No/invalid order id or status returned' 
+	    unless defined $result->{'Status'} && defined $result->{'OrderId'}
+		&& grep($_ eq $result->{'Status'}, @Net::Ikano::orderStatus);
+
+	  $svc_dsl->pushed(time);
+	  $svc_dsl->last_pull((time)+1); 
+	  $svc_dsl->vendor_order_id($result->{'OrderId'});
+	  $svc_dsl->vendor_order_status($result->{'Status'});
+	  local $FS::svc_Common::noexport_hack = 1;
+	  $result = $svc_dsl->replace; 
+	  return "Error setting DSL fields: $result" if $result;
+  }
+  else {
+    return "Cancelling anything other than NEW orders in COMPLETED status is "
+	. "not currently implemented";
+  }
+ '';
+}
+
 sub statuschg {
   my( $self, $svc_dsl, $type ) = (shift, shift, shift);
 



More information about the freeside-commits mailing list