+=cut
+
+sub preinsert_hook_first { shift->_inline_add(@_); }
+sub prereplace_hook_first { shift->_inline_add(@_); }
+
+sub _inline_add {
+ my $self = shift;
+
+ my $agentnum = $self->cust_svc->cust_pkg->cust_main->agentnum;
+
+ if ( $self->alarmsystemnum == -1 ) {
+ my $alarm_system = new FS::alarm_system {
+ 'agentnum' => $agentnum,
+ 'systemname' => $self->alarmsystemnum_systemname,
+ };
+ my $error = $alarm_system->insert;
+ return $error if $error;
+ $self->alarmsystemnum($alarm_system->alarmsystemnum);
+ }
+
+ if ( $self->alarmtypenum == -1 ) {
+ my $alarm_type = new FS::alarm_type {
+ 'agentnum' => $agentnum,
+ 'inputs' => $self->alarmtypenum_inputs,
+ 'outputs' => $self->alarmtypenum_outputs,
+ };
+ my $error = $alarm_type->insert;
+ return $error if $error;
+ $self->alarmtypenum($alarm_type->alarmtypenum);
+ }
+
+ if ( $self->alarmstationnum == -1 ) {
+ my $alarm_station = new FS::alarm_station {
+ 'agentnum' => $agentnum,
+ 'stationname' => $self->alarmstationnum_stationname,
+ };
+ my $error = $alarm_station->insert;
+ return $error if $error;
+ $self->alarmstationnum($alarm_station->alarmstationnum)
+ }
+
+ '';
+}
+