use FS::cust_tax_exempt_pkg_void;
use FS::cust_bill_pkg_discount_void;
use FS::agent_pkg_class;
+ use FS::svc_export_machine;
# Sammath Naur
if ( $FS::Mason::addl_handler_use ) {
'columns' => [
'svcexportmachinenum', 'serial', '', '', '', '',
'svcnum', 'int', '', '', '', '',
+ 'exportnum', 'int', '', '', '', '',
'machinenum', 'int', '', '', '', '',
],
'primary_key' => 'svcexportmachinenum',
- 'unique' => [],
+ 'unique' => [ ['svcnum', 'exportnum'] ],
'index' => [],
},
If I<jobnum> is set to an array reference, the jobnums of any export jobs will
be added to the referenced array.
-If I<child_objects> is set to an array reference of FS::tablename objects (for
-example, FS::acct_snarf objects), they will have their svcnum field set and
-will be inserted after this record, but before any exports are run. Each
-element of the array can also optionally be a two-element array reference
-containing the child object and the name of an alternate field to be filled in
-with the newly-inserted svcnum, for example C<[ $svc_forward, 'srcsvc' ]>
+If I<child_objects> is set to an array reference of FS::tablename objects
+(for example, FS::svc_export_machine or FS::acct_snarf objects), they
+will have their svcnum field set and will be inserted after this record,
+but before any exports are run. Each element of the array can also
+optionally be a two-element array reference containing the child object
+and the name of an alternate field to be filled in with the newly-inserted
+svcnum, for example C<[ $svc_forward, 'srcsvc' ]>
If I<depend_jobnum> is set (to a scalar jobnum or an array reference of
jobnums), all provisioning jobs will have a dependancy on the supplied
Replaces OLD_RECORD with this one. If there is an error, returns the error,
otherwise returns false.
-Currently available options are: I<export_args> and I<depend_jobnum>.
+Currently available options are: I<child_objects>, I<export_args> and
+I<depend_jobnum>.
+
+If I<child_objects> is set to an array reference of FS::tablename objects
+(for example, FS::svc_export_machine or FS::acct_snarf objects), they
+will have their svcnum field set and will be inserted or replaced after
+this record, but before any exports are run. Each element of the array
+can also optionally be a two-element array reference containing the
+child object and the name of an alternate field to be filled in with
+the newly-inserted svcnum, for example C<[ $svc_forward, 'srcsvc' ]>
If I<depend_jobnum> is set (to a scalar jobnum or an array reference of
jobnums), all provisioning jobs will have a dependancy on the supplied
? shift
: { @_ };
+ my $objects = $options->{'child_objects'} || [];
+
my @jobnums = ();
local $FS::queue::jobnums = \@jobnums;
warn "[$me] replace: set \$FS::queue::jobnums to $FS::queue::jobnums\n"
return $error;
}
+ foreach my $object ( @$objects ) {
+ my($field, $obj);
+ if ( ref($object) eq 'ARRAY' ) {
+ ($obj, $field) = @$object;
+ } else {
+ $obj = $object;
+ $field = 'svcnum';
+ }
+ $obj->$field($new->svcnum);
+
+ my $oldobj = qsearchs( $obj->table, {
+ $field => $new->svcnum,
+ map { $_ => $obj->$_ } $obj->_svc_child_partfields,
+ });
+
+ if ( $oldobj ) {
+ my $pkey = $oldobj->primary_key;
+ $obj->$pkey($oldobj->$pkey);
+ $obj->replace($oldobj);
+ } else {
+ $error = $obj->insert;
+ }
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
#new-style exports!
unless ( $noexport_hack ) {
use strict;
use base qw( FS::Record );
-use FS::Record; # qw( qsearch qsearchs );
+use FS::Record qw( qsearchs ); #qsearch );
use FS::cust_svc;
+use FS::part_export;
use FS::part_export_machine;
+sub _svc_child_partfields { ('exportnum') };
+
=head1 NAME
FS::svc_export_machine - Object methods for svc_export_machine records
my $error =
$self->ut_numbern('svcexportmachinenum')
- || $self->ut_foreign_key('svcnum', 'cust_svc', 'svcnum')
- || $self->ut_foreign_key('machinenum', 'part_export_machine', 'machinenum' )
+ || $self->ut_foreign_key('svcnum', 'cust_svc', 'svcnum' )
+ || $self->ut_foreign_key('exportnum', 'part_export', 'exportnum' )
+ || $self->ut_foreign_key('machinenum', 'part_export_machine', 'machinenum')
;
return $error if $error;
$self->SUPER::check;
}
+=item part_export_machine
+
+=cut
+
+sub part_export_machine {
+ my $self = shift;
+ qsearchs('part_export_machine', { 'machinenum' => $self->machinenum } );
+}
+
=back
=head1 BUGS
my $error = '';
+my $part_svc = $svcnum ?
+ $old->part_svc :
+ qsearchs( 'part_svc',
+ { 'svcpart' => $cgi->param('svcpart') }
+ );
+
# google captcha auth
if ( $cgi->param('captcha_response') ) {
- my $part_svc = $svcnum ?
- $old->part_svc :
- qsearchs( 'part_svc',
- { 'svcpart' => $cgi->param('svcpart') }
- );
my ($export) = $part_svc->part_export('acct_google');
if ( $export and
! $export->captcha_auth($cgi->param('captcha_response')) ) {
}
if ( ! $error ) {
+
+ my $export_info = FS::part_export::export_info();
+
+ my @svc_export_machine =
+ map FS::svc_export_machine->new({
+ 'svcnum' => $svcnum,
+ 'exportnum' => $_->exportnum,
+ 'machinenum' => scalar($cgi->param('exportnum'.$_->exportnum.'machinenum')),
+ }),
+ grep { $_->machine eq '_SVC_MACHINE' }
+ $part_svc->part_export;
+
if ( $svcnum ) {
foreach ( grep { $old->$_ != $new->$_ }
qw( seconds upbytes downbytes totalbytes )
$error ||= $new->set_usage(\%hash); #unoverlimit and trigger radius changes
last; #once is enough
}
- $error ||= $new->replace($old);
+ $error ||= $new->replace($old, 'child_objects'=>\@svc_export_machine);
} else {
- $error ||= $new->insert;
+ $error ||= $new->insert('child_objects'=>\@svc_export_machine);
$svcnum = $new->svcnum;
}
}
<INPUT TYPE="hidden" NAME="sectornum" VALUE="<% $svc_acct->sectornum %>">
%}
+<& /elements/tr-svc_export_machine.html,
+ 'svc' => $svc_acct,
+ 'part_svc' => $part_svc,
+ 'cgi' => $cgi,
+&>
+
% #uid/gid
% foreach my $xid (qw( uid gid )) {
%
--- /dev/null
+% foreach my $part_export (@part_export) {
+% my $label = ( $part_export->exportname
+% ? $part_export->exportname
+% : $part_export->label
+% ).
+% ' hostname';
+%
+% my $element = 'exportnum'. $part_export->exportnum. 'machinenum';
+% my $machinenum = $opt{cgi}->param($element);
+% if ( ! $machinenum && $opt{svc}->svcnum ) {
+% my $svc_export_machine = qsearchs('svc_export_machine', {
+% 'svcnum' => $opt{svc}->svcnum,
+% 'exportnum' => $part_export->exportnum,
+% });
+% $machinenum = $svc_export_machine->machinenum if $svc_export_machine;
+% }
+
+ <& /elements/tr-select-table.html,
+ 'label' => $label,
+ 'element_name' => 'exportnum'. $part_export->exportnum. 'machinenum',
+ 'table' => 'part_export_machine',
+ 'name_col' => 'machine',
+ 'hashref' => { 'exportnum' => $part_export->exportnum,
+ 'disabled' => '',
+ },
+ 'curr_value' => $machinenum,
+ 'empty_label' => 'Select export hostname',
+ &>
+% }
+<%init>
+
+my %opt = @_;
+
+my @part_export = grep { $_->machine eq '_SVC_MACHINE' }
+ $opt{part_svc}->part_export;
+
+</%init>
--- /dev/null
+% foreach my $part_export (@part_export) {
+% my $label = ( $part_export->exportname
+% ? $part_export->exportname
+% : $part_export->label
+% ).
+% ' hostname';
+%
+% my $svc_export_machine = qsearchs('svc_export_machine', {
+% 'svcnum' => $opt{svc}->svcnum,
+% 'exportnum' => $part_export->exportnum,
+% });
+
+ <& tr.html,
+ 'label' => $label,
+ 'value' => $svc_export_machine
+ ? $svc_export_machine->part_export_machine->machine
+ : '',
+ &>
+% }
+<%init>
+
+my %opt = @_;
+
+my @part_export = grep { $_->machine eq '_SVC_MACHINE' }
+ $opt{part_svc}->part_export;
+
+</%init>
&>
% }
+<& /view/elements/tr-svc_export_machine.html,
+ 'svc' => $svc_acct,
+ 'part_svc' => $part_svc,
+&>
+
% if ($svc_acct->uid ne '') {
<& /view/elements/tr.html, label=>mt('UID'), value=>$svc_acct->uid &>
% }