X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2FRT%2FInterface%2FWeb_Vendor.pm;h=737748e6304372947e7c5987b45ff0c2332efcbd;hb=862381171227acfe4a7bf5e1957de991b3928704;hp=e9c63466187f7862641b57cb96aeeed611b3670d;hpb=8c3642a408636a316bc40815bbfdf01d24e6d605;p=freeside.git diff --git a/rt/lib/RT/Interface/Web_Vendor.pm b/rt/lib/RT/Interface/Web_Vendor.pm index e9c634661..737748e63 100644 --- a/rt/lib/RT/Interface/Web_Vendor.pm +++ b/rt/lib/RT/Interface/Web_Vendor.pm @@ -164,6 +164,42 @@ sub ProcessTicketCustomers { push @results, $msg; warn "$me: linking requestor to custnum $custnum: $msg\n" if $Debug > 1; + + ## check if FS contact email exists, if not create it. + if ( !qsearchs( { + 'table' => 'contact_email', + 'hashref' => { 'emailaddress' => $Requestor->{'values'}->{'emailaddress'}, }, + } ) ) { + + ## get first and last name for contact. + my ($fname, $lname) = ( + split (/\@/, substr($Requestor->{'values'}->{'emailaddress'}, 0, index($Requestor->{'values'}->{'emailaddress'}, "."))) + ); + + use Lingua::EN::NameParse; + my $name = Lingua::EN::NameParse->new(); + + my $error = $name->parse($Requestor->{'values'}->{'realname'}) + unless !$Requestor->{'values'}->{'realname'}; + + my %name_comps = $name->components unless !$Requestor->{'values'}->{'realname'} || $error; + + $fname = $name_comps{given_name_1} || $name_comps{initials_1} unless !$name_comps{given_name_1} && !$name_comps{initials_1}; + $lname = $name_comps{surname_1} unless !$name_comps{surname_1}; + + ## create the contact. + use FS::contact; + my $contact = new FS::contact { + 'custnum' => $custnum, + 'first' => $fname, + 'last' => $lname, + 'emailaddress' => $Requestor->{'values'}->{'emailaddress'}, + 'comment' => 'Auto created from RT requestor', + }; + $error = $contact->insert; + push @results, 'Created Freeside contact for requestor ' . $Requestor->{'values'}->{'emailaddress'} + unless $error; + } } } @@ -284,6 +320,16 @@ sub ProcessTicketBasics { } } + # RT core _will_ allow Set transactions that change these + # fields to empty strings, but internally change the values + # to zero. This is sloppy and causes some problems. + foreach my $field (qw(TimeWorked TimeEstimated TimeLeft)) { + if (exists $ARGSRef->{$field}) { + $ARGSRef->{$field} =~ s/\s//g; + $ARGSRef->{$field} ||= 0; + } + } + my @results = UpdateRecordObject( AttributesRef => \@attribs, Object => $TicketObj, @@ -413,12 +459,13 @@ sub ProcessColumnMapValue { my $value = shift; my %args = ( Arguments => [], Escape => 1, - FormatDate => \&default_FormatDate, @_ ); + my $FormatDate = $m->notes('FormatDate') || \&default_FormatDate; + if ( ref $value ) { if ( ref $value eq 'RT::Date' ) { - return $args{FormatDate}->($value); + return $FormatDate->($value); } elsif ( UNIVERSAL::isa( $value, 'CODE' ) ) { my @tmp = $value->( @{ $args{'Arguments'} } ); return ProcessColumnMapValue( ( @tmp > 1 ? \@tmp : $tmp[0] ), %args );