From dbb2e37427b0edc90a633dd6a23aea57faf949ad Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Mon, 8 Aug 2016 20:20:16 -0500 Subject: RT#71969: High-priority: Add reason to cancellations details for Reports -> Packages -> Package churn --- httemplate/search/cust_pkg_churn.html | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/httemplate/search/cust_pkg_churn.html b/httemplate/search/cust_pkg_churn.html index 30962c996..4c7e7e8b2 100644 --- a/httemplate/search/cust_pkg_churn.html +++ b/httemplate/search/cust_pkg_churn.html @@ -18,7 +18,7 @@ emt('Susp.'), emt('Changed'), emt('Cancel'), - #emt('Reason'), # hard to do this right + @reason_header, FS::UI::Web::cust_header( $cgi->param('cust_fields') ), @@ -45,6 +45,7 @@ ( map { time_or_blank($_) } qw( setup last_bill bill susp change_date cancel ) ), + @reason_fields, \&FS::UI::Web::cust_fields, ], 'sort_fields' => [ @@ -53,21 +54,25 @@ ('') x 3, # can't use at all # use the plain SQL column names qw( setup last_bill bill susp change_date cancel ), + @reason_blank, # cust_fields can take care of themselves ], 'color' => [ ('') x 15, + @reason_blank, FS::UI::Web::cust_colors(), ], 'style' => [ ('') x 15, + @reason_blank, FS::UI::Web::cust_styles() ], 'size' => [ '', '', '', '', '-1' ], - 'align' => 'rrlcccrrlrrrrrr'. FS::UI::Web::cust_aligns(). 'r', + 'align' => 'rrlcccrrlrrrrrr'.$reason_align. FS::UI::Web::cust_aligns(). 'r', 'links' => [ $link, $link, $link, ('') x 12, + @reason_blank, ( map { $_ ne 'Cust. Status' ? $clink : '' } FS::UI::Web::cust_header( $cgi->param('cust_fields') @@ -184,4 +189,16 @@ sub time_or_blank { }; } +my (@reason_header,@reason_fields,@reason_blank); +my $reason_align = ''; +if ($status eq 'cancel') { + push @reason_header, emt('Cancel Reason'); + push @reason_fields, sub { + my $c = shift; + my $cust_pkg_reason = $c->last_cust_pkg_reason('cancel'); + $cust_pkg_reason ? $cust_pkg_reason->reason->reason : ''; + }; + push @reason_blank, ''; + $reason_align = 'l'; +} -- cgit v1.2.1 From 8b37069f938208760656e740ebbf0e49c1ef1854 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Fri, 26 Aug 2016 14:55:48 -0700 Subject: localize "of" in invoice page numbers ("1 of 5", etc.), #39084 --- conf/invoice_latex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/invoice_latex b/conf/invoice_latex index c1d04d651..1cbed4a6d 100644 --- a/conf/invoice_latex +++ b/conf/invoice_latex @@ -117,7 +117,7 @@ { % First page } { % ... pages - \small{\thepage\ of \pageref{LastPage}} + \small{\thepage~[@-- emt('of') --@]~\pageref{LastPage}} } } -- cgit v1.2.1 From bcaab65d7ce645ea7fef8361fe57fbcde532b0ab Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Fri, 26 Aug 2016 15:44:02 -0700 Subject: agent-virtual contract end date report, #71964 --- httemplate/search/cust_pkg-date.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/httemplate/search/cust_pkg-date.html b/httemplate/search/cust_pkg-date.html index 1b9377546..5bb772bf6 100644 --- a/httemplate/search/cust_pkg-date.html +++ b/httemplate/search/cust_pkg-date.html @@ -36,6 +36,8 @@ my @sort_fields = ( map '', @fields ); # should only ever sort by $col push @header, FS::UI::Web::cust_header($cust_fields); push @fields, \&FS::UI::Web::cust_fields; +my $agentnums_sql = $curuser->agentnums_sql('table' => 'cust_main'); + my $query = { 'table' => 'cust_pkg', 'addl_from' => FS::UI::Web::join_cust_main('cust_pkg', 'cust_pkg'), @@ -43,11 +45,13 @@ my $query = { $col => { op => '!=', value => '' }, 'cancel' => '', }, - 'order_by' => "ORDER BY $col", + 'extra_sql' => ' AND '.$agentnums_sql, + 'order_by' => "ORDER BY $col", }; my $count_query = - "SELECT COUNT(*) FROM cust_pkg WHERE $col IS NOT NULL AND cancel IS NULL"; + "SELECT COUNT(*) FROM cust_pkg JOIN cust_main USING (custnum) ". + "WHERE $col IS NOT NULL AND cancel IS NULL AND $agentnums_sql"; my $pkg_link = sub { my $self = shift; -- cgit v1.2.1 From 501210e1bbf79d8a9d6308257124c44a261bf379 Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Wed, 3 Aug 2016 23:04:05 -0500 Subject: RT#42043: Check for cancelled packages with a cancellation date age option [age_newest options] --- FS/FS/part_event/Condition.pm | 2 +- .../Condition/hasnt_pkg_class_cancelled.pm | 22 +++++++++++++++------- .../Condition/hasnt_pkgpart_cancelled.pm | 15 ++++++++++++--- httemplate/edit/process/part_event.html | 4 ++-- httemplate/elements/tr-freq.html | 2 +- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/FS/FS/part_event/Condition.pm b/FS/FS/part_event/Condition.pm index 36fbe9a0d..d1d519683 100644 --- a/FS/FS/part_event/Condition.pm +++ b/FS/FS/part_event/Condition.pm @@ -312,7 +312,7 @@ sub option_age_from { } elsif ( $age =~ /^(\d+)d$/i ) { $mday -= $1; } elsif ( $age =~ /^(\d+)h$/i ) { - $hour -= $hour; + $hour -= $1; } else { die "unparsable age: $age"; } diff --git a/FS/FS/part_event/Condition/hasnt_pkg_class_cancelled.pm b/FS/FS/part_event/Condition/hasnt_pkg_class_cancelled.pm index 353e6469f..d54fb88fa 100644 --- a/FS/FS/part_event/Condition/hasnt_pkg_class_cancelled.pm +++ b/FS/FS/part_event/Condition/hasnt_pkg_class_cancelled.pm @@ -21,9 +21,16 @@ sub option_fields { 'type' => 'select-pkg_class', 'multiple' => 1, }, - 'age' => { 'label' => 'Cancellation in last', - 'type' => 'freq', - }, + 'age_newest' => { 'label' => 'Cancelled more than', + 'type' => 'freq', + 'post_text' => ' ago (blank for no limit)', + 'allow_blank' => 1, + }, + 'age' => { 'label' => 'Cancelled less than', + 'type' => 'freq', + 'post_text' => ' ago (blank for no limit)', + 'allow_blank' => 1, + }, ); } @@ -32,11 +39,12 @@ sub condition { my $cust_main = $self->cust_main($object); - my $age = $self->option_age_from('age', $opt{'time'} ); + my $oldest = length($self->option('age')) ? $self->option_age_from('age', $opt{'time'} ) : 0; + my $newest = $self->option_age_from('age_newest', $opt{'time'} ); + + my $pkgclass = $self->option('pkgclass') || {}; - #XXX test - my $hashref = $self->option('pkgclass') || {}; - ! grep { $hashref->{ $_->part_pkg->classnum } && $_->get('cancel') > $age } + ! grep { $pkgclass->{ $_->part_pkg->classnum } && ($_->get('cancel') > $oldest) && ($_->get('cancel') <= $newest) } $cust_main->cancelled_pkgs; } diff --git a/FS/FS/part_event/Condition/hasnt_pkgpart_cancelled.pm b/FS/FS/part_event/Condition/hasnt_pkgpart_cancelled.pm index b4ff6c32b..42845cb8a 100644 --- a/FS/FS/part_event/Condition/hasnt_pkgpart_cancelled.pm +++ b/FS/FS/part_event/Condition/hasnt_pkgpart_cancelled.pm @@ -18,8 +18,15 @@ sub option_fields { 'type' => 'select-part_pkg', 'multiple' => 1, }, - 'age' => { 'label' => 'Cancellation in last', + 'age_newest' => { 'label' => 'Cancelled more than', 'type' => 'freq', + 'post_text' => ' ago (blank for no limit)', + 'allow_blank' => 1, + }, + 'age' => { 'label' => 'Cancelled less than', + 'type' => 'freq', + 'post_text' => ' ago (blank for no limit)', + 'allow_blank' => 1, }, ); } @@ -29,10 +36,12 @@ sub condition { my $cust_main = $self->cust_main($object); - my $age = $self->option_age_from('age', $opt{'time'} ); + my $oldest = length($self->option('age')) ? $self->option_age_from('age', $opt{'time'} ) : 0; + my $newest = $self->option_age_from('age_newest', $opt{'time'} ); my $if_pkgpart = $self->option('if_pkgpart') || {}; - ! grep { $if_pkgpart->{ $_->pkgpart } && $_->get('cancel') > $age } + + ! grep { $if_pkgpart->{ $_->pkgpart } && ($_->get('cancel') > $oldest) && ($_->get('cancel') <= $newest) } $cust_main->cancelled_pkgs; } diff --git a/httemplate/edit/process/part_event.html b/httemplate/edit/process/part_event.html index bac69241c..0293af886 100644 --- a/httemplate/edit/process/part_event.html +++ b/httemplate/edit/process/part_event.html @@ -39,8 +39,8 @@ split(/\0/, $value) }; } elsif ( $info->{'type'} eq 'freq' ) { - $value = '0' if !length($value); - $value .= $params->{$cgi_field.'_units'}; + $value = '0' if !length($value) and !$info->{'allow_blank'}; + $value .= $params->{$cgi_field.'_units'} if length($value); } #warn "value of $cgi_field is $value\n"; diff --git a/httemplate/elements/tr-freq.html b/httemplate/elements/tr-freq.html index cb58bf6b5..795684cf7 100644 --- a/httemplate/elements/tr-freq.html +++ b/httemplate/elements/tr-freq.html @@ -15,7 +15,7 @@ <% $freq eq $units ? 'SELECTED' : '' %> ><% $freq{$freq} %> % } - + <% $opt{'post_text'} || '' %> -- cgit v1.2.1 From a31ad48b7e59c261ada66682b2892c5fa3ea5ffc Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Mon, 25 Jul 2016 22:01:03 -0500 Subject: RT#71049: Add order_number to payment reports [show_order_number checkboxes] --- httemplate/search/cust_bill_pay_pkg.html | 30 ++++++++++++++-------- httemplate/search/cust_pay.html | 1 - httemplate/search/elements/cust_pay_or_refund.html | 2 +- .../search/elements/report_cust_pay_or_refund.html | 6 +++++ httemplate/search/report_cust_bill_pay_pkg.html | 7 +++++ 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/httemplate/search/cust_bill_pay_pkg.html b/httemplate/search/cust_bill_pay_pkg.html index 7c231a65d..e2ffd1258 100644 --- a/httemplate/search/cust_bill_pay_pkg.html +++ b/httemplate/search/cust_bill_pay_pkg.html @@ -14,7 +14,7 @@ #payment 'Date', - 'Order Number', + @on_header, 'By', #application @@ -44,7 +44,7 @@ ? cardtype($cust_pay->paymask) : ''; }, sub { time2str('%b %d %Y', shift->get('cust_pay_date') ) }, - sub { shift->cust_bill_pay->cust_pay->order_number }, + @on_field, sub { shift->cust_bill_pay->cust_pay->otaker }, sub { sprintf($money_char.'%.2f', shift->amount ) }, @@ -66,7 +66,7 @@ '', #payinfo/paymask '', #cardtype 'cust_pay_date', - '', #order_number + @on_null, #order_number '', #'otaker', '', #amount '', #line item description @@ -83,7 +83,7 @@ '', '', '', - '', + @on_null, '', '', '', @@ -96,10 +96,9 @@ FS::UI::Web::cust_header() ), ], - 'align' => 'rcrlrrlrlll', -#original value before cardtype & package were added -#why are there 13 cols? -#'rcrrlrlllrrcl'. + 'align' => 'rcrlr'. + $on_align. + 'lrlll'. $post_desc_align. 'rr'. FS::UI::Web::cust_aligns(), @@ -109,7 +108,7 @@ '', '', '', - '', + @on_null, '', '', '', @@ -126,7 +125,7 @@ '', '', '', - '', + @on_null, '', '', '', @@ -148,6 +147,17 @@ die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Financial reports'); +my @on_header = (); +my @on_field = (); +my @on_null = (); +my $on_align = ''; +if ($cgi->param('show_order_number')) { + @on_header = ('Order Number'); + @on_field = (sub { shift->cust_bill_pay->cust_pay->order_number }); + @on_null = (''); + $on_align = 'r'; +} + my $conf = new FS::Conf; my %payby = FS::payby->payby2shortname; diff --git a/httemplate/search/cust_pay.html b/httemplate/search/cust_pay.html index 536ab291f..e466f6afa 100755 --- a/httemplate/search/cust_pay.html +++ b/httemplate/search/cust_pay.html @@ -4,5 +4,4 @@ 'name_singular' => emt('payment'), 'name_verb' => emt('paid'), 'show_card_type' => 1, - 'show_order_number' => 1, &> diff --git a/httemplate/search/elements/cust_pay_or_refund.html b/httemplate/search/elements/cust_pay_or_refund.html index 4ed297dac..896f0fa2d 100755 --- a/httemplate/search/elements/cust_pay_or_refund.html +++ b/httemplate/search/elements/cust_pay_or_refund.html @@ -211,7 +211,7 @@ push @links, ''; push @fields, sub { time2str('%b %d %Y', shift->_date ) }; push @sort_fields, '_date'; -if ($opt{'show_order_number'}) { +if ($cgi->param('show_order_number')) { push @header, emt('Order Number'); $align .= 'r'; push @links, ''; diff --git a/httemplate/search/elements/report_cust_pay_or_refund.html b/httemplate/search/elements/report_cust_pay_or_refund.html index 730db68e8..806746a23 100644 --- a/httemplate/search/elements/report_cust_pay_or_refund.html +++ b/httemplate/search/elements/report_cust_pay_or_refund.html @@ -151,6 +151,12 @@ Examples: 'value' => 1, &> + <& /elements/tr-checkbox.html, + 'label' => emt('Include order number'), + 'field' => 'show_order_number', + 'value' => 1, + &> + % } diff --git a/httemplate/search/report_cust_bill_pay_pkg.html b/httemplate/search/report_cust_bill_pay_pkg.html index 2347bab6d..bdcd1549e 100644 --- a/httemplate/search/report_cust_bill_pay_pkg.html +++ b/httemplate/search/report_cust_bill_pay_pkg.html @@ -41,6 +41,13 @@ field => 'paid', &> + <& /elements/tr-checkbox.html, + 'label' => emt('Display order number'), + 'field' => 'show_order_number', + 'value' => 1, + 'cell_style' => 'font-weight: normal', #for consistency + &> + Yes, transaction completed sucessfully. -% if ( $action eq 'complete' ) { +% if ( $action eq 'complete' ) {     +% if ($authorized) { + + + +% } else { +% }     - % } + + @@ -156,6 +165,8 @@ my $cust_pay_pending = }) or die 'unknown paypendingnum'; +my $authorized = ($cust_pay_pending->status eq 'authorized') ? 1 : 0; + my $conf = new FS::Conf; my $money_char = $conf->config('money_char') || '$'; diff --git a/httemplate/edit/process/cust_pay_pending.html b/httemplate/edit/process/cust_pay_pending.html index 1bad6cffe..0ff7d26d0 100644 --- a/httemplate/edit/process/cust_pay_pending.html +++ b/httemplate/edit/process/cust_pay_pending.html @@ -59,6 +59,15 @@ if ( $action eq 'delete' ) { $title = 'Pending payment completed (decline)'; } +} elsif ( $action eq 'reverse' ) { + + $error = $cust_pay_pending->reverse; + if ( $error ) { + $title = 'Error reversing pending payment'; + } else { + $title = 'Pending payment completed (reverse)'; + } + } else { die "unknown action $action"; diff --git a/httemplate/search/cust_pay_pending.html b/httemplate/search/cust_pay_pending.html index 942085c6c..52646265b 100755 --- a/httemplate/search/cust_pay_pending.html +++ b/httemplate/search/cust_pay_pending.html @@ -17,7 +17,7 @@ my %statusaction = ( 'new' => 'delete', 'pending' => 'complete', - #'authorized' => '', + 'authorized' => 'complete', 'captured' => 'capture', #'declined' => '', #wouldn't need to take action on a done state#'done' diff --git a/httemplate/search/elements/cust_pay_or_refund.html b/httemplate/search/elements/cust_pay_or_refund.html index 896f0fa2d..cbda680ca 100755 --- a/httemplate/search/elements/cust_pay_or_refund.html +++ b/httemplate/search/elements/cust_pay_or_refund.html @@ -91,29 +91,30 @@ my $title = ''; $title = 'Unapplied ' if $unapplied; $title .= "\u$name_singular Search Results"; -my $link = ''; -if ( ( $curuser->access_right('View invoices') #remove in 2.5 (2.7?) - || ($curuser->access_right('View payments') && $table =~ /^cust_pay/) - || ($curuser->access_right('View refunds') && $table eq 'cust_refund') - ) - && ! $opt{'disable_link'} - ) -{ - - my $key; - my $q = ''; - if ( $table eq 'cust_pay_void' ) { - $key = 'paynum'; - $q .= 'void=1;'; - } elsif ( $table eq /^cust_(\w+)$/ ) { - $key = $1.'num'; - } - - if ( $key ) { - $q .= "$key="; - $link = [ "${p}view/$table.html?$q", $key ] - } -} +###NOT USED??? +#my $link = ''; +#if ( ( $curuser->access_right('View invoices') #remove in 2.5 (2.7?) +# || ($curuser->access_right('View payments') && $table =~ /^cust_pay/) +# || ($curuser->access_right('View refunds') && $table eq 'cust_refund') +# ) +# && ! $opt{'disable_link'} +# ) +#{ +# +# my $key; +# my $q = ''; +# if ( $table eq 'cust_pay_void' ) { +# $key = 'paynum'; +# $q .= 'void=1;'; +# } elsif ( $table eq /^cust_(\w+)$/ ) { +# $key = $1.'num'; +# } +# +# if ( $key ) { +# $q .= "$key="; +# $link = [ "${p}view/$table.html?$q", $key ] +# } +#} my $cust_link = sub { my $cust_thing = shift; @@ -166,12 +167,18 @@ if ( $opt{'pre_header'} ) { push @sort_fields, @{ $opt{'pre_fields'} }; } -my $sub_receipt = sub { +my $sub_receipt = $opt{'disable_link'} ? '' : sub { my $obj = shift; my $objnum = $obj->primary_key . '=' . $obj->get($obj->primary_key); + my $table = $obj->table; + my $void = ''; + if ($table eq 'cust_pay_void') { + $table = 'cust_pay'; + $void = ';void=1'; + } include('/elements/popup_link_onclick.html', - 'action' => $p.'view/cust_pay.html?link=popup;'.$objnum, + 'action' => $p.'view/'.$table.'.html?link=popup;'.$objnum.$void, 'actionlabel' => emt('Payment Receipt'), ); }; diff --git a/httemplate/view/cust_main/payment_history/pending_payment.html b/httemplate/view/cust_main/payment_history/pending_payment.html index 31149231b..cf7ef7c08 100644 --- a/httemplate/view/cust_main/payment_history/pending_payment.html +++ b/httemplate/view/cust_main/payment_history/pending_payment.html @@ -12,6 +12,7 @@ my %statusaction = ( 'new' => 'delete', 'thirdparty' => 'delete', 'pending' => 'complete', + 'authorized' => 'complete', 'captured' => 'capture', ); -- cgit v1.2.1 From b6cbc6cc5b933c08bf4f1132df7aee7910636295 Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Thu, 4 Aug 2016 21:07:24 -0500 Subject: RT#71930: Package fields are not showing up in...Advanced wireless broadband report --- httemplate/search/svc_broadband.cgi | 39 ++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/httemplate/search/svc_broadband.cgi b/httemplate/search/svc_broadband.cgi index 8cdf29d1c..0e52d5fb6 100755 --- a/httemplate/search/svc_broadband.cgi +++ b/httemplate/search/svc_broadband.cgi @@ -10,6 +10,7 @@ 'Router', @tower_header, 'IP Address', + @header_pkg, emt('Pkg. Status'), FS::UI::Web::cust_header($cgi->param('cust_fields')), ], @@ -21,6 +22,7 @@ }, @tower_fields, 'ip_addr', + @fields_pkg, sub { $cust_pkg_cache{$_[0]->svcnum} ||= $_[0]->cust_svc->cust_pkg; return '' unless $cust_pkg_cache{$_[0]->svcnum}; @@ -32,20 +34,25 @@ $link, '', #$link_router, (map '', @tower_fields), - $link, + $link, # ip_addr + @blank_pkg, '', # pkg status ( map { $_ ne 'Cust. Status' ? $link_cust : '' } FS::UI::Web::cust_header($cgi->param('cust_fields')) ), ], - 'align' => 'rll'.('r' x @tower_fields).'rr'. + 'align' => 'rll'.('r' x @tower_fields). + 'r'. # ip_addr + $align_pkg. + 'r'. # pkg status FS::UI::Web::cust_aligns(), 'color' => [ '', '', '', (map '', @tower_fields), - '', + '', # ip_addr + @blank_pkg, sub { $cust_pkg_cache{$_[0]->svcnum} ||= $_[0]->cust_svc->cust_pkg; return '' unless $cust_pkg_cache{$_[0]->svcnum}; @@ -59,8 +66,9 @@ '', '', (map '', @tower_fields), - '', - 'b', + '', # ip_addr + @blank_pkg, + 'b', # pkg status FS::UI::Web::cust_styles(), ], @@ -129,4 +137,25 @@ $html_init .= ' | ' . $fsurl . 'search/svc_broadband-map.html?' . $cgi->query_string . '">' . emt('View a map of these services') . ''; +my (@header_pkg,@fields_pkg,@blank_pkg); +my $align_pkg = ''; +#false laziness with search/svc_acct.cgi +$cgi->param('cust_pkg_fields') =~ /^([\w\,]*)$/ or die "bad cust_pkg_fields"; +my @pkg_fields = split(',', $1); +foreach my $pkg_field ( @pkg_fields ) { + ( my $header = ucfirst($pkg_field) ) =~ s/_/ /; #:/ + push @header_pkg, $header; + + #not the most efficient to do it every field, but this is of niche use. so far + push @fields_pkg, sub { my $svc_x = shift; + my $cust_pkg = $svc_x->cust_svc->cust_pkg or return ''; + my $value = $cust_pkg->get($pkg_field);#closures help alot + $value ? time2str('%b %d %Y', $value ) : ''; + }; + + push @blank_pkg, ''; + $align_pkg .= 'c'; +} + + -- cgit v1.2.1 From ac602a212f0cb29cc9f2693de4df75c70dc5211f Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Tue, 26 Jul 2016 16:44:10 -0500 Subject: RT#38217: Send email when logging conditions are met [fix to warning invocation in cust_bill_pkg_tax_location] --- FS/FS/cust_bill_pkg_tax_location.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FS/FS/cust_bill_pkg_tax_location.pm b/FS/FS/cust_bill_pkg_tax_location.pm index f16e930b9..0e510005f 100644 --- a/FS/FS/cust_bill_pkg_tax_location.pm +++ b/FS/FS/cust_bill_pkg_tax_location.pm @@ -341,7 +341,7 @@ sub upgrade_taxable_billpkgnum { } #for $i } else { # the more complicated case - $log->warn("mismatched charges and tax links in pkg#$pkgnum", + $log->warning("mismatched charges and tax links in pkg#$pkgnum", object => $cust_bill); my $tax_amount = sum(map {$_->amount} @tax_links); # remove all tax link records and recreate them to be 1:1 with -- cgit v1.2.1 From 77f2d55e48d2a59ec020b6fd64cb627b38dd9340 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Mon, 29 Aug 2016 18:26:18 -0700 Subject: add a script to inherit report classes on cloned/customized packages, #72260 --- bin/part_pkg-clone_fix_options | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 bin/part_pkg-clone_fix_options diff --git a/bin/part_pkg-clone_fix_options b/bin/part_pkg-clone_fix_options new file mode 100755 index 000000000..4d8192bce --- /dev/null +++ b/bin/part_pkg-clone_fix_options @@ -0,0 +1,53 @@ +#!/usr/bin/perl + +use strict; +use FS::Misc::Getopt; +use FS::part_pkg; +use FS::Record qw(qsearch dbh); + +our %opt; +getopts('p:'); # pkgpart +$FS::UID::AutoCommit = 0; + +sub usage { + die "Usage: part_pkg-clone_fix_options -p pkgpart[,pkgpart...] user\n\n"; +} + +my @pkgpart = split(',',$opt{p}) or usage(); +foreach my $base_pkgpart (@pkgpart) { + my $base_part_pkg = FS::part_pkg->by_key($base_pkgpart); + warn "Base package '".$base_part_pkg->pkg."'\n"; + my @children = qsearch('part_pkg', { 'family_pkgpart' => $base_pkgpart }); + next if !@children; + my $n_pkg = 0; + my $n_upd = 0; + my %base_options = $base_part_pkg->options; + my %report_classes = map { $_ => $base_options{$_} } + grep /^report_option_/, keys %base_options; + if (!keys %report_classes) { + warn "No report classes.\n"; + next; + } + + foreach my $part_pkg (@children) { + my $pkgpart = $part_pkg->pkgpart; + next if $pkgpart == $base_pkgpart; + $n_pkg++; + + # don't do this if it has report options already + my %options = $part_pkg->options; + if (grep /^report_option_/, keys %options) { + warn "#$pkgpart has report classes; skipped\n"; + } else { + %options = ( %options, %report_classes ); + my $error = $part_pkg->replace(options => \%options); + die "#$pkgpart: $error\n" if $error; + $n_upd++; + } + } + warn "Updated $n_upd / $n_pkg child packages.\n"; +} + +warn "Finished.\n"; +dbh->commit; + -- cgit v1.2.1 From 7258c57a184360cf89730f81db915791c389c7e7 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Tue, 30 Aug 2016 12:24:36 -0700 Subject: add agent and cust-fields selection to package contract end date report, #71964 --- httemplate/elements/menu.html | 2 +- httemplate/search/cust_pkg-date.html | 34 ++++++++++++++++---------- httemplate/search/report_cust_pkg-date.html | 38 +++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 14 deletions(-) create mode 100755 httemplate/search/report_cust_pkg-date.html diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index 582dda622..cdb1d733c 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -274,7 +274,7 @@ $report_packages{'Suspension summary'} = [ $fsurl.'search/cust_pkg_susp.html', ' $report_packages{'Customer packages with unconfigured services'} = [ $fsurl.'search/cust_pkg.cgi?APKG_pkgnum', 'List packages which have provisionable services' ]; $report_packages{'FCC Form 477'} = [ $fsurl.'search/report_477.html' ] if $conf->exists('part_pkg-show_fcc_options'); -$report_packages{'Contract end dates'} = [ $fsurl.'search/cust_pkg-date.html?date=contract_end', 'Show packages by contract end date' ]; +$report_packages{'Contract end dates'} = [ $fsurl.'search/report_cust_pkg-date.html?date=contract_end', 'Show packages by contract end date' ]; $report_packages{'Advanced package reports'} = [ $fsurl.'search/report_cust_pkg.html', 'by agent, date range, status, package definition' ]; tie my %report_inventory, 'Tie::IxHash', diff --git a/httemplate/search/cust_pkg-date.html b/httemplate/search/cust_pkg-date.html index 5bb772bf6..231bbac16 100644 --- a/httemplate/search/cust_pkg-date.html +++ b/httemplate/search/cust_pkg-date.html @@ -1,3 +1,16 @@ +<& elements/search.html, + 'title' => $title, + 'name' => 'packages', + 'query' => $query, + 'count_query' => $count_query, + 'header' => \@header, + 'fields' => \@fields, + 'align' => 'rrrl'. FS::UI::Web::cust_aligns(), + 'color' => \@color, + 'style' => \@style, + 'links' => \@links, + 'cell_style' => [ $date_color_sub ], +&> <%init> my $curuser = $FS::CurrentUser::CurrentUser; die 'access denied' unless $curuser->access_right('List packages'); @@ -18,8 +31,7 @@ my $col = $cgi->param('date'); die "invalid date column" unless $cols{$col}; my $title = 'Packages by ' . lc($cols{$col}) . ' date'; -# second option on the cust_fields_avail list, plus email -my $cust_fields = 'Cust# | Customer | Day phone | Night phone | Mobile phone | Invoicing email(s)'; +my $cust_fields = $cgi->param('cust_fields'); my @header = ( $cols{$col}, emt('#'), emt('Quan.'), @@ -32,11 +44,18 @@ my @fields = ( sub { time2str('%b %d %Y', $_[0]->$col) }, 'pkg_label', ); my @sort_fields = ( map '', @fields ); # should only ever sort by $col +my @color = ( map '', @fields ); +my @style = ( map '', @fields ); push @header, FS::UI::Web::cust_header($cust_fields); push @fields, \&FS::UI::Web::cust_fields; +push @color, FS::UI::Web::cust_colors(); +push @style, FS::UI::Web::cust_styles(); my $agentnums_sql = $curuser->agentnums_sql('table' => 'cust_main'); +if ( $cgi->param('agentnum') =~ /^(\d+)$/ and $1 ) { + $agentnums_sql .= " AND agentnum = $1"; +} my $query = { 'table' => 'cust_pkg', @@ -80,15 +99,4 @@ my $date_color_sub = sub { }; -<& elements/search.html, - 'title' => $title, - 'name' => 'packages', - 'query' => $query, - 'count_query' => $count_query, - 'header' => \@header, - 'fields' => \@fields, - 'align' => 'rrrl'. FS::UI::Web::cust_aligns(), - 'links' => \@links, - 'cell_style' => [ $date_color_sub ], -&> diff --git a/httemplate/search/report_cust_pkg-date.html b/httemplate/search/report_cust_pkg-date.html new file mode 100755 index 000000000..ceb9a9c75 --- /dev/null +++ b/httemplate/search/report_cust_pkg-date.html @@ -0,0 +1,38 @@ +<& /elements/header.html, mt($title) &> + +
+ + + + + <& /elements/tr-select-agent.html, + 'curr_value' => scalar( $cgi->param('agentnum') ), + 'disable_empty' => 0, + &> + + <& /elements/tr-select-cust-fields.html &> + +
+ +
+ + +
+ +<% include('/elements/footer.html') %> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('List packages'); + +# for the page title +my %cols = ( + 'contract_end' => 'Contract end' +); + +# or let the column be selected here? +my $col = $cgi->param('date'); +die "invalid date column" unless $cols{$col}; +my $title = 'Packages by ' . lc($cols{$col}) . ' date'; + + -- cgit v1.2.1 From 35659e9343b94942e5907c65e07f520d962b7ce5 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Tue, 30 Aug 2016 12:55:54 -0700 Subject: fix password_history schema upgrade from pre-3.8 versions, #72265 --- FS/FS/password_history.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/FS/FS/password_history.pm b/FS/FS/password_history.pm index a34f6169b..13d16010d 100644 --- a/FS/FS/password_history.pm +++ b/FS/FS/password_history.pm @@ -161,9 +161,14 @@ sub password_equals { } sub _upgrade_schema { + my $class = shift; + # if the table doesn't exist yet then nothing needs to happen here + my $dbdef_table = $class->dbdef_table + or return; + # clean up history records where linked_acct has gone away my @where; - for my $fk ( grep /__/, __PACKAGE__->dbdef_table->columns ) { + for my $fk ( grep /__/, $dbdef_table->columns ) { my ($table, $key) = split(/__/, $fk); push @where, " ( $fk IS NOT NULL AND NOT EXISTS(SELECT 1 FROM $table WHERE $table.$key = $fk) )"; -- cgit v1.2.1 From b44c17c7d9686e3a0227f15a567fe39de508160f Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Tue, 30 Aug 2016 16:01:48 -0700 Subject: fix cust-fields, #71964 --- httemplate/search/cust_pkg-date.html | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/httemplate/search/cust_pkg-date.html b/httemplate/search/cust_pkg-date.html index 231bbac16..22a67402b 100644 --- a/httemplate/search/cust_pkg-date.html +++ b/httemplate/search/cust_pkg-date.html @@ -5,6 +5,7 @@ 'count_query' => $count_query, 'header' => \@header, 'fields' => \@fields, + 'sort_fields' => [], 'align' => 'rrrl'. FS::UI::Web::cust_aligns(), 'color' => \@color, 'style' => \@style, @@ -31,7 +32,6 @@ my $col = $cgi->param('date'); die "invalid date column" unless $cols{$col}; my $title = 'Packages by ' . lc($cols{$col}) . ' date'; -my $cust_fields = $cgi->param('cust_fields'); my @header = ( $cols{$col}, emt('#'), emt('Quan.'), @@ -43,14 +43,25 @@ my @fields = ( sub { time2str('%b %d %Y', $_[0]->$col) }, 'quantity', 'pkg_label', ); -my @sort_fields = ( map '', @fields ); # should only ever sort by $col my @color = ( map '', @fields ); my @style = ( map '', @fields ); -push @header, FS::UI::Web::cust_header($cust_fields); +my $pkg_link = sub { + my $self = shift; + my $frag = 'cust_pkg'. $self->pkgnum; + [ "${p}view/cust_main.cgi?custnum=".$self->custnum. + ";show=packages;fragment=$frag#cust_pkg", + 'pkgnum' + ]; +}; + +my @links = ( '', ($pkg_link) x 3 ); + +push @header, FS::UI::Web::cust_header($cgi->param('cust_fields')); push @fields, \&FS::UI::Web::cust_fields; -push @color, FS::UI::Web::cust_colors(); -push @style, FS::UI::Web::cust_styles(); +push @color, FS::UI::Web::cust_colors(); +push @style, FS::UI::Web::cust_styles(); +push @links, FS::UI::Web::cust_links(); my $agentnums_sql = $curuser->agentnums_sql('table' => 'cust_main'); if ( $cgi->param('agentnum') =~ /^(\d+)$/ and $1 ) { @@ -58,6 +69,7 @@ if ( $cgi->param('agentnum') =~ /^(\d+)$/ and $1 ) { } my $query = { + 'select' => join(',', 'cust_pkg.*', FS::UI::Web::cust_sql_fields() ), 'table' => 'cust_pkg', 'addl_from' => FS::UI::Web::join_cust_main('cust_pkg', 'cust_pkg'), 'hashref' => { @@ -72,17 +84,6 @@ my $count_query = "SELECT COUNT(*) FROM cust_pkg JOIN cust_main USING (custnum) ". "WHERE $col IS NOT NULL AND cancel IS NULL AND $agentnums_sql"; -my $pkg_link = sub { - my $self = shift; - my $frag = 'cust_pkg'. $self->pkgnum; - [ "${p}view/cust_main.cgi?custnum=".$self->custnum. - ";show=packages;fragment=$frag#cust_pkg", - 'pkgnum' - ]; -}; - -my @links = ( '', ($pkg_link) x 3, - FS::UI::Web::cust_links() ); my $date_color_sub = sub { my $self = shift; -- cgit v1.2.1 From 5efca2378f5eb82e5c807cbcc66c72d91fd267c3 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Wed, 24 Aug 2016 17:17:03 -0700 Subject: de-transactionize cust_pay_pending updates during card verification, #57135 --- FS/FS/Schema.pm | 2 +- FS/FS/cust_main/Billing_Realtime.pm | 434 ++++++++++++++++++------------------ FS/FS/cust_pay_pending.pm | 6 +- 3 files changed, 228 insertions(+), 214 deletions(-) diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 980cd2116..b7ec7df19 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1713,7 +1713,7 @@ sub tables_hashref { 'cust_pay_pending' => { 'columns' => [ 'paypendingnum','serial', '', '', '', '', - 'custnum', 'int', '', '', '', '', + 'custnum', 'int', 'NULL', '', '', '', 'paid', @money_type, '', '', '_date', @date_type, '', '', 'payby', 'char', '', 4, '', '', #CARD/BILL/COMP, should diff --git a/FS/FS/cust_main/Billing_Realtime.pm b/FS/FS/cust_main/Billing_Realtime.pm index 7c194e102..dc0eea610 100644 --- a/FS/FS/cust_main/Billing_Realtime.pm +++ b/FS/FS/cust_main/Billing_Realtime.pm @@ -5,7 +5,7 @@ use vars qw( $conf $DEBUG $me ); use vars qw( $realtime_bop_decline_quiet ); #ugh use Data::Dumper; use Business::CreditCard 0.35; -use FS::UID qw( dbh ); +use FS::UID qw( dbh myconnect ); use FS::Record qw( qsearch qsearchs ); use FS::Misc qw( send_email ); use FS::payby; @@ -1731,6 +1731,7 @@ sub realtime_verify_bop { my $self = shift; local($DEBUG) = $FS::cust_main::DEBUG if $FS::cust_main::DEBUG > $DEBUG; + my $log = FS::Log->new('FS::cust_main::Billing_Realtime::realtime_verify_bop'); my %options = (); if (ref($_[0]) eq 'HASH') { @@ -1836,29 +1837,14 @@ sub realtime_verify_bop { # run transaction(s) ### - warn "claiming mutex on customer ". $self->custnum. "\n" if $DEBUG > 1; - $self->select_for_update; #mutex ... just until we get our pending record in - warn "obtained mutex on customer ". $self->custnum. "\n" if $DEBUG > 1; - - #the checks here are intended to catch concurrent payments - #double-form-submission prevention is taken care of in cust_pay_pending::check - - #also check and make sure there aren't *other* pending payments for this cust - - my @pending = qsearch('cust_pay_pending', { - 'custnum' => $self->custnum, - 'status' => { op=>'!=', value=>'done' } - }); - - return "A payment is already being processed for this customer (". - join(', ', map 'paypendingnum '. $_->paypendingnum, @pending ). - "); verification transaction aborted." - if scalar(@pending); - - #okay, good to go, if we're a duplicate, cust_pay_pending will kick us out + my $error; + my $transaction; #need this back so we can do _tokenize_card + # don't mutex the customer here, because they might be uncommitted. and + # this is only verification. it doesn't matter if they have other + # unfinished verifications. my $cust_pay_pending = new FS::cust_pay_pending { - 'custnum' => $self->custnum, + 'custnum_pending' => 1, 'paid' => '1.00', '_date' => '', 'payby' => $bop_method2payby{'CC'}, @@ -1875,221 +1861,243 @@ sub realtime_verify_bop { $cust_pay_pending->payunique( $options{payunique} ) if defined($options{payunique}) && length($options{payunique}); - warn "inserting cust_pay_pending record for customer ". $self->custnum. "\n" - if $DEBUG > 1; - my $cpp_new_err = $cust_pay_pending->insert; #mutex lost when this is inserted - return $cpp_new_err if $cpp_new_err; + IMMEDIATE: { + # open a separate handle for creating/updating the cust_pay_pending record + local $FS::UID::dbh = myconnect(); + local $FS::UID::AutoCommit = 1; - warn "inserted cust_pay_pending record for customer ". $self->custnum. "\n" - if $DEBUG > 1; - warn Dumper($cust_pay_pending) if $DEBUG > 2; + warn "inserting cust_pay_pending record for customer ". $self->custnum. "\n" + if $DEBUG > 1; - my $transaction = new $namespace( $payment_gateway->gateway_module, - $self->_bop_options(\%options), - ); + # if this fails, just return; everything else will still allow the + # cust_pay_pending to have its custnum set later + my $cpp_new_err = $cust_pay_pending->insert; + return $cpp_new_err if $cpp_new_err; - $transaction->content( - 'type' => 'CC', - $self->_bop_auth(\%options), - 'action' => 'Authorization Only', - 'description' => $options{'description'}, - 'amount' => '1.00', - #'invoice_number' => $options{'invnum'}, - 'customer_id' => $self->custnum, - %$bop_content, - 'reference' => $cust_pay_pending->paypendingnum, #for now - 'callback_url' => $payment_gateway->gateway_callback_url, - 'cancel_url' => $payment_gateway->gateway_cancel_url, - 'email' => $email, - %content, #after - ); + warn "inserted cust_pay_pending record for customer ". $self->custnum. "\n" + if $DEBUG > 1; + warn Dumper($cust_pay_pending) if $DEBUG > 2; - $cust_pay_pending->status('pending'); - my $cpp_pending_err = $cust_pay_pending->replace; - return $cpp_pending_err if $cpp_pending_err; + $transaction = new $namespace( $payment_gateway->gateway_module, + $self->_bop_options(\%options), + ); - warn Dumper($transaction) if $DEBUG > 2; + $transaction->content( + 'type' => 'CC', + $self->_bop_auth(\%options), + 'action' => 'Authorization Only', + 'description' => $options{'description'}, + 'amount' => '1.00', + #'invoice_number' => $options{'invnum'}, + 'customer_id' => $self->custnum, + %$bop_content, + 'reference' => $cust_pay_pending->paypendingnum, #for now + 'callback_url' => $payment_gateway->gateway_callback_url, + 'cancel_url' => $payment_gateway->gateway_cancel_url, + 'email' => $email, + %content, #after + ); - unless ( $BOP_TESTING ) { - $transaction->test_transaction(1) - if $conf->exists('business-onlinepayment-test_transaction'); - $transaction->submit(); - } else { - if ( $BOP_TESTING_SUCCESS ) { - $transaction->is_success(1); - $transaction->authorization('fake auth'); + $cust_pay_pending->status('pending'); + my $cpp_pending_err = $cust_pay_pending->replace; + return $cpp_pending_err if $cpp_pending_err; + + warn Dumper($transaction) if $DEBUG > 2; + + unless ( $BOP_TESTING ) { + $transaction->test_transaction(1) + if $conf->exists('business-onlinepayment-test_transaction'); + $transaction->submit(); } else { - $transaction->is_success(0); - $transaction->error_message('fake failure'); + if ( $BOP_TESTING_SUCCESS ) { + $transaction->is_success(1); + $transaction->authorization('fake auth'); + } else { + $transaction->is_success(0); + $transaction->error_message('fake failure'); + } } - } - my $log = FS::Log->new('FS::cust_main::Billing_Realtime::realtime_verify_bop'); + if ( $transaction->is_success() ) { - if ( $transaction->is_success() ) { + $cust_pay_pending->status('authorized'); + my $cpp_authorized_err = $cust_pay_pending->replace; + return $cpp_authorized_err if $cpp_authorized_err; - $cust_pay_pending->status('authorized'); - my $cpp_authorized_err = $cust_pay_pending->replace; - return $cpp_authorized_err if $cpp_authorized_err; + my $auth = $transaction->authorization; + my $ordernum = $transaction->can('order_number') + ? $transaction->order_number + : ''; - my $auth = $transaction->authorization; - my $ordernum = $transaction->can('order_number') - ? $transaction->order_number - : ''; + my $reverse = new $namespace( $payment_gateway->gateway_module, + $self->_bop_options(\%options), + ); - my $reverse = new $namespace( $payment_gateway->gateway_module, - $self->_bop_options(\%options), - ); + $reverse->content( 'action' => 'Reverse Authorization', + $self->_bop_auth(\%options), - $reverse->content( 'action' => 'Reverse Authorization', - $self->_bop_auth(\%options), + # B:OP + 'amount' => '1.00', + 'authorization' => $transaction->authorization, + 'order_number' => $ordernum, - # B:OP - 'amount' => '1.00', - 'authorization' => $transaction->authorization, - 'order_number' => $ordernum, + # vsecure + 'result_code' => $transaction->result_code, + 'txn_date' => $transaction->txn_date, - # vsecure - 'result_code' => $transaction->result_code, - 'txn_date' => $transaction->txn_date, + %content, + ); + $reverse->test_transaction(1) + if $conf->exists('business-onlinepayment-test_transaction'); + $reverse->submit(); - %content, - ); - $reverse->test_transaction(1) - if $conf->exists('business-onlinepayment-test_transaction'); - $reverse->submit(); + if ( $reverse->is_success ) { - if ( $reverse->is_success ) { + $cust_pay_pending->status('done'); + $cust_pay_pending->statustext('reversed'); + my $cpp_reversed_err = $cust_pay_pending->replace; + return $cpp_reversed_err if $cpp_reversed_err; - $cust_pay_pending->status('done'); - $cust_pay_pending->statustext('reversed'); - my $cpp_authorized_err = $cust_pay_pending->replace; - return $cpp_authorized_err if $cpp_authorized_err; + } else { - } else { + my $e = "Authorization successful but reversal failed, custnum #". + $self->custnum. ': '. $reverse->result_code. + ": ". $reverse->error_message; + $log->warning($e); + warn $e; + return $e; - my $e = "Authorization successful but reversal failed, custnum #". - $self->custnum. ': '. $reverse->result_code. - ": ". $reverse->error_message; - $log->warning($e); - warn $e; - return $e; + } - } + ### Address Verification ### + # + # Single-letter codes vary by cardtype. + # + # Erring on the side of accepting cards if avs is not available, + # only rejecting if avs occurred and there's been an explicit mismatch + # + # Charts below taken from vSecure documentation, + # shows codes for Amex/Dscv/MC/Visa + # + # ACCEPTABLE AVS RESPONSES: + # Both Address and 5-digit postal code match Y A Y Y + # Both address and 9-digit postal code match Y A X Y + # United Kingdom – Address and postal code match _ _ _ F + # International transaction – Address and postal code match _ _ _ D/M + # + # ACCEPTABLE, BUT ISSUE A WARNING: + # Ineligible transaction; or message contains a content error _ _ _ E + # System unavailable; retry R U R R + # Information unavailable U W U U + # Issuer does not support AVS S U S S + # AVS is not applicable _ _ _ S + # Incompatible formats – Not verified _ _ _ C + # Incompatible formats – Address not verified; postal code matches _ _ _ P + # International transaction – address not verified _ G _ G/I + # + # UNACCEPTABLE AVS RESPONSES: + # Only Address matches A Y A A + # Only 5-digit postal code matches Z Z Z Z + # Only 9-digit postal code matches Z Z W W + # Neither address nor postal code matches N N N N + + if (my $avscode = uc($transaction->avs_code)) { + + # map codes to accept/warn/reject + my $avs = { + 'American Express card' => { + 'A' => 'r', + 'N' => 'r', + 'R' => 'w', + 'S' => 'w', + 'U' => 'w', + 'Y' => 'a', + 'Z' => 'r', + }, + 'Discover card' => { + 'A' => 'a', + 'G' => 'w', + 'N' => 'r', + 'U' => 'w', + 'W' => 'w', + 'Y' => 'r', + 'Z' => 'r', + }, + 'MasterCard' => { + 'A' => 'r', + 'N' => 'r', + 'R' => 'w', + 'S' => 'w', + 'U' => 'w', + 'W' => 'r', + 'X' => 'a', + 'Y' => 'a', + 'Z' => 'r', + }, + 'VISA card' => { + 'A' => 'r', + 'C' => 'w', + 'D' => 'a', + 'E' => 'w', + 'F' => 'a', + 'G' => 'w', + 'I' => 'w', + 'M' => 'a', + 'N' => 'r', + 'P' => 'w', + 'R' => 'w', + 'S' => 'w', + 'U' => 'w', + 'W' => 'r', + 'Y' => 'a', + 'Z' => 'r', + }, + }; + my $cardtype = cardtype($content{card_number}); + if ($avs->{$cardtype}) { + my $avsact = $avs->{$cardtype}->{$avscode}; + my $warning = ''; + if ($avsact eq 'r') { + return "AVS code verification failed, cardtype $cardtype, code $avscode"; + } elsif ($avsact eq 'w') { + $warning = "AVS did not occur, cardtype $cardtype, code $avscode"; + } elsif (!$avsact) { + $warning = "AVS code unknown, cardtype $cardtype, code $avscode"; + } # else $avsact eq 'a' + if ($warning) { + $log->warning($warning); + warn $warning; + } + } # else $cardtype avs handling not implemented + } # else !$transaction->avs_code + + } else { # is not success + + # status is 'done' not 'declined', as in _realtime_bop_result + $cust_pay_pending->status('done'); + $error = $transaction->error_message || 'Unknown error'; + $cust_pay_pending->statustext($error); + # could also record failure_status here, + # but it's not supported by B::OP::vSecureProcessing... + # need a B::OP module with (reverse) auth only to test it with + my $cpp_declined_err = $cust_pay_pending->replace; + return $cpp_declined_err if $cpp_declined_err; - ### Address Verification ### - # - # Single-letter codes vary by cardtype. - # - # Erring on the side of accepting cards if avs is not available, - # only rejecting if avs occurred and there's been an explicit mismatch - # - # Charts below taken from vSecure documentation, - # shows codes for Amex/Dscv/MC/Visa - # - # ACCEPTABLE AVS RESPONSES: - # Both Address and 5-digit postal code match Y A Y Y - # Both address and 9-digit postal code match Y A X Y - # United Kingdom – Address and postal code match _ _ _ F - # International transaction – Address and postal code match _ _ _ D/M - # - # ACCEPTABLE, BUT ISSUE A WARNING: - # Ineligible transaction; or message contains a content error _ _ _ E - # System unavailable; retry R U R R - # Information unavailable U W U U - # Issuer does not support AVS S U S S - # AVS is not applicable _ _ _ S - # Incompatible formats – Not verified _ _ _ C - # Incompatible formats – Address not verified; postal code matches _ _ _ P - # International transaction – address not verified _ G _ G/I - # - # UNACCEPTABLE AVS RESPONSES: - # Only Address matches A Y A A - # Only 5-digit postal code matches Z Z Z Z - # Only 9-digit postal code matches Z Z W W - # Neither address nor postal code matches N N N N - - if (my $avscode = uc($transaction->avs_code)) { - - # map codes to accept/warn/reject - my $avs = { - 'American Express card' => { - 'A' => 'r', - 'N' => 'r', - 'R' => 'w', - 'S' => 'w', - 'U' => 'w', - 'Y' => 'a', - 'Z' => 'r', - }, - 'Discover card' => { - 'A' => 'a', - 'G' => 'w', - 'N' => 'r', - 'U' => 'w', - 'W' => 'w', - 'Y' => 'r', - 'Z' => 'r', - }, - 'MasterCard' => { - 'A' => 'r', - 'N' => 'r', - 'R' => 'w', - 'S' => 'w', - 'U' => 'w', - 'W' => 'r', - 'X' => 'a', - 'Y' => 'a', - 'Z' => 'r', - }, - 'VISA card' => { - 'A' => 'r', - 'C' => 'w', - 'D' => 'a', - 'E' => 'w', - 'F' => 'a', - 'G' => 'w', - 'I' => 'w', - 'M' => 'a', - 'N' => 'r', - 'P' => 'w', - 'R' => 'w', - 'S' => 'w', - 'U' => 'w', - 'W' => 'r', - 'Y' => 'a', - 'Z' => 'r', - }, - }; - my $cardtype = cardtype($content{card_number}); - if ($avs->{$cardtype}) { - my $avsact = $avs->{$cardtype}->{$avscode}; - my $warning = ''; - if ($avsact eq 'r') { - return "AVS code verification failed, cardtype $cardtype, code $avscode"; - } elsif ($avsact eq 'w') { - $warning = "AVS did not occur, cardtype $cardtype, code $avscode"; - } elsif (!$avsact) { - $warning = "AVS code unknown, cardtype $cardtype, code $avscode"; - } # else $avsact eq 'a' - if ($warning) { - $log->warning($warning); - warn $warning; - } - } # else $cardtype avs handling not implemented - } # else !$transaction->avs_code + } - } else { # is not success + } # end of IMMEDIATE; we now have our $error and $transaction - # status is 'done' not 'declined', as in _realtime_bop_result - $cust_pay_pending->status('done'); - $cust_pay_pending->statustext( $transaction->error_message || 'Unknown error' ); - # could also record failure_status here, - # but it's not supported by B::OP::vSecureProcessing... - # need a B::OP module with (reverse) auth only to test it with - my $cpp_declined_err = $cust_pay_pending->replace; - return $cpp_declined_err if $cpp_declined_err; + ### + # Save the custnum (as part of the main transaction, so it can reference + # the cust_main) + ### + $cust_pay_pending->set('custnum', $self->custnum); + my $set_custnum_err = $cust_pay_pending->replace; + if ($set_custnum_err) { + $log->error($set_custnum_err); + $error ||= $set_custnum_err; + # but if there was a real verification error also, return that one } ### @@ -2114,7 +2122,9 @@ sub realtime_verify_bop { # result handling ### - $transaction->is_success() ? '' : $transaction->error_message(); + # $error contains the transaction error_message, if is_success was false. + + return $error; } diff --git a/FS/FS/cust_pay_pending.pm b/FS/FS/cust_pay_pending.pm index a775553c9..48748025e 100644 --- a/FS/FS/cust_pay_pending.pm +++ b/FS/FS/cust_pay_pending.pm @@ -213,7 +213,7 @@ sub check { my $error = $self->ut_numbern('paypendingnum') - || $self->ut_foreign_key('custnum', 'cust_main', 'custnum') + || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum') || $self->ut_money('paid') || $self->ut_numbern('_date') || $self->ut_textn('payunique') @@ -232,6 +232,10 @@ sub check { ; return $error if $error; + if (!$self->custnum and !$self->get('custnum_pending')) { + return 'custnum required'; + } + $self->_date(time) unless $self->_date; # UNIQUE index should catch this too, without race conditions, but this -- cgit v1.2.1 From 8a90342b21d4ae2e132bdbc12b9bb6523e8847e4 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Wed, 24 Aug 2016 17:53:40 -0700 Subject: but keep failed verification payments linked to their customers, #57135 --- FS/FS/cust_main/Billing_Realtime.pm | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/FS/FS/cust_main/Billing_Realtime.pm b/FS/FS/cust_main/Billing_Realtime.pm index dc0eea610..5d35fc2c4 100644 --- a/FS/FS/cust_main/Billing_Realtime.pm +++ b/FS/FS/cust_main/Billing_Realtime.pm @@ -1862,10 +1862,19 @@ sub realtime_verify_bop { if defined($options{payunique}) && length($options{payunique}); IMMEDIATE: { - # open a separate handle for creating/updating the cust_pay_pending record + # open a separate handle for creating/updating the cust_pay_pending + # record local $FS::UID::dbh = myconnect(); local $FS::UID::AutoCommit = 1; + # if this is an existing customer (and we can tell now because + # this is a fresh transaction), it's safe to assign their custnum + # to the cust_pay_pending record, and then the verification attempt + # will remain linked to them even if it fails. + if ( FS::cust_main->by_key($self->custnum) ) { + $cust_pay_pending->set('custnum', $self->custnum); + } + warn "inserting cust_pay_pending record for customer ". $self->custnum. "\n" if $DEBUG > 1; @@ -2092,12 +2101,14 @@ sub realtime_verify_bop { # the cust_main) ### - $cust_pay_pending->set('custnum', $self->custnum); - my $set_custnum_err = $cust_pay_pending->replace; - if ($set_custnum_err) { - $log->error($set_custnum_err); - $error ||= $set_custnum_err; - # but if there was a real verification error also, return that one + if (!$cust_pay_pending->custnum) { + $cust_pay_pending->set('custnum', $self->custnum); + my $set_custnum_err = $cust_pay_pending->replace; + if ($set_custnum_err) { + $log->error($set_custnum_err); + $error ||= $set_custnum_err; + # but if there was a real verification error also, return that one + } } ### -- cgit v1.2.1 From d26b7edb666abcaed41193ec40dbb00781848b13 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Wed, 31 Aug 2016 12:41:32 -0700 Subject: on upgrade, remove all leading/trailing whitespace from address fields, #72194 Conflicts: FS/FS/Upgrade.pm --- FS/FS/Upgrade.pm | 6 +++--- FS/FS/cust_location.pm | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm index 5b2750577..8b7d7337f 100644 --- a/FS/FS/Upgrade.pm +++ b/FS/FS/Upgrade.pm @@ -329,6 +329,9 @@ sub upgrade_data { tie my %hash, 'Tie::IxHash', + #fix whitespace - before cust_main + 'cust_location' => [], + #cust_main (remove paycvv from history) 'cust_main' => [], @@ -444,9 +447,6 @@ sub upgrade_data { #mark certain taxes as system-maintained, # and fix whitespace 'cust_main_county' => [], - - #fix whitespace - 'cust_location' => [], ; \%hash; diff --git a/FS/FS/cust_location.pm b/FS/FS/cust_location.pm index 481ebb11a..67a5e3eb1 100644 --- a/FS/FS/cust_location.pm +++ b/FS/FS/cust_location.pm @@ -14,6 +14,12 @@ use FS::cust_main_county; use FS::part_export; use FS::GeocodeCache; +# Essential fields. Can't be modified in place, will be considered in +# deciding if a location is "new", and (because of that) can't have +# leading/trailing whitespace. +my @essential = (qw(custnum address1 address2 city county state zip country + location_number location_type location_kind disabled)); + $import = 0; $DEBUG = 0; @@ -143,9 +149,6 @@ sub find_or_insert { warn "find_or_insert:\n".Dumper($self) if $DEBUG; - my @essential = (qw(custnum address1 address2 city county state zip country - location_number location_type location_kind disabled)); - if ($conf->exists('cust_main-no_city_in_address')) { warn "Warning: passed city to find_or_insert when cust_main-no_city_in_address is configured, ignoring it" if $self->get('city'); @@ -346,9 +349,9 @@ sub check { return '' if $self->disabled; # so that disabling locations never fails - # maybe should just do all fields in the table? - # or in every table? - $self->trim_whitespace(qw(district city county state country)); + # whitespace in essential fields leads to problems figuring out if a + # record is "new"; get rid of it. + $self->trim_whitespace(@essential); my $error = $self->ut_numbern('locationnum') @@ -907,7 +910,9 @@ sub _upgrade_data { # trim whitespace on records that need it local $allow_location_edit = 1; - foreach my $field (qw(city county state country district)) { + foreach my $field (@essential) { + next if $field eq 'custnum'; + next if $field eq 'disabled'; foreach my $location (qsearch({ table => 'cust_location', extra_sql => " WHERE $field LIKE ' %' OR $field LIKE '% '" -- cgit v1.2.1 From b8a0fbd814bd8e1ba3a8b8c58c5f162af8dc9f00 Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Wed, 31 Aug 2016 19:56:36 -0500 Subject: 38973: Bill for time worked on ticket resolution [v3 bug fix] --- FS/FS/cust_pkg.pm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 101dd81d0..548d00051 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -6108,6 +6108,12 @@ sub _upgrade_data { # class method } } +# will autoload in v4+ +sub rt_field_charge { + my $self = shift; + qsearch('rt_field_charge',{ 'pkgnum' => $self->pkgnum }); +} + =back =head1 BUGS -- cgit v1.2.1 From f61619b95f05b576518ea698ad7e22267b4c36c4 Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Tue, 9 Aug 2016 00:55:45 -0500 Subject: RT#71890: SelfService API: Return monthly recurring fee [display_recurring, v3 reconcile] --- FS/FS/cust_main/Packages.pm | 98 ++++++++++++++++++++++++++++++++++ httemplate/view/cust_main/billing.html | 73 ++----------------------- 2 files changed, 101 insertions(+), 70 deletions(-) diff --git a/FS/FS/cust_main/Packages.pm b/FS/FS/cust_main/Packages.pm index 8f96f81aa..4d0eee7ed 100644 --- a/FS/FS/cust_main/Packages.pm +++ b/FS/FS/cust_main/Packages.pm @@ -706,6 +706,104 @@ sub num_usage_pkgs { FS::Record->scalar_sql($sql, $self->custnum); } +=item display_recurring + +Returns an array of hash references, one for each recurring freq +on billable customer packages, with keys of freq, freq_pretty and amount +(the amount that this customer will next be charged at the given frequency.) + +Results will be numerically sorted by freq. + +Only intended for display purposes, not used for actual billing. + +=cut + +sub display_recurring { + my $cust_main = shift; + + my $sth = dbh->prepare(" + SELECT DISTINCT freq FROM cust_pkg LEFT JOIN part_pkg USING (pkgpart) + WHERE freq IS NOT NULL AND freq != '0' + AND ( cancel IS NULL OR cancel = 0 ) + AND custnum = ? + ") or die $DBI::errstr; + + $sth->execute($cust_main->custnum) or die $sth->errstr; + + #not really a numeric sort because freqs can actually be all sorts of things + # but good enough for the 99% cases of ordering monthly quarterly annually + my @freqs = sort { $a <=> $b } map { $_->[0] } @{ $sth->fetchall_arrayref }; + + $sth->finish; + + my @out; + + foreach my $freq (@freqs) { + + my @cust_pkg = qsearch({ + 'table' => 'cust_pkg', + 'addl_from' => 'LEFT JOIN part_pkg USING (pkgpart)', + 'hashref' => { 'custnum' => $cust_main->custnum, }, + 'extra_sql' => 'AND ( cancel IS NULL OR cancel = 0 ) + AND freq = '. dbh->quote($freq), + 'order_by' => 'ORDER BY COALESCE(start_date,0), pkgnum', # to ensure old pkgs come before change_to_pkg + }) or next; + + my $freq_pretty = $cust_pkg[0]->part_pkg->freq_pretty; + + my $amount = 0; + my $skip_pkg = {}; + foreach my $cust_pkg (@cust_pkg) { + my $part_pkg = $cust_pkg->part_pkg; + next if $cust_pkg->susp + && ! $cust_pkg->option('suspend_bill') + && ( ! $part_pkg->option('suspend_bill') + || $cust_pkg->option('no_suspend_bill') + ); + + #pkg change handling + next if $skip_pkg->{$cust_pkg->pkgnum}; + if ($cust_pkg->change_to_pkgnum) { + #if change is on or before next bill date, use new pkg + next if $cust_pkg->expire <= $cust_pkg->bill; + #if change is after next bill date, use old (this) pkg + $skip_pkg->{$cust_pkg->change_to_pkgnum} = 1; + } + + my $pkg_amount = 0; + + #add recurring amounts for this package and its billing add-ons + foreach my $l_part_pkg ( $part_pkg->self_and_bill_linked ) { + $pkg_amount += $l_part_pkg->base_recur($cust_pkg); + } + + #subtract amounts for any active discounts + #(there should only be one at the moment, otherwise this makes no sense) + foreach my $cust_pkg_discount ( $cust_pkg->cust_pkg_discount_active ) { + my $discount = $cust_pkg_discount->discount; + #and only one of these for each + $pkg_amount -= $discount->amount; + $pkg_amount -= $amount * $discount->percent/100; + } + + $pkg_amount *= ( $cust_pkg->quantity || 1 ); + + $amount += $pkg_amount; + + } #foreach $cust_pkg + + next unless $amount; + push @out, { + 'freq' => $freq, + 'freq_pretty' => $freq_pretty, + 'amount' => $amount, + }; + + } #foreach $freq + + return @out; +} + =back =head1 BUGS diff --git a/httemplate/view/cust_main/billing.html b/httemplate/view/cust_main/billing.html index 3d0983e67..eed3baf4b 100644 --- a/httemplate/view/cust_main/billing.html +++ b/httemplate/view/cust_main/billing.html @@ -28,79 +28,12 @@ % # customer base, and compare it to a graph of the overhead for generating this % # information. (and optimize it better, we could get it more from SQL) % if ( $cust_main->num_ncancelled_pkgs < 54 ) { -% my $sth = dbh->prepare(" -% SELECT DISTINCT freq FROM cust_pkg LEFT JOIN part_pkg USING (pkgpart) -% WHERE freq IS NOT NULL AND freq != '0' -% AND ( cancel IS NULL OR cancel = 0 ) -% AND custnum = ? -% ") or die $DBI::errstr; -% -% $sth->execute($cust_main->custnum) or die $sth->errstr; - -% #not really a numeric sort because freqs can actually be all sorts of things -% # but good enough for the 99% cases of ordering monthly quarterly annually -% my @freqs = sort { $a <=> $b } map { $_->[0] } @{ $sth->fetchall_arrayref }; -% -% foreach my $freq (@freqs) { -% my @cust_pkg = qsearch({ -% 'table' => 'cust_pkg', -% 'addl_from' => 'LEFT JOIN part_pkg USING (pkgpart)', -% 'hashref' => { 'custnum' => $cust_main->custnum, }, -% 'extra_sql' => 'AND ( cancel IS NULL OR cancel = 0 ) -% AND freq = '. dbh->quote($freq), -% 'order_by' => 'ORDER BY COALESCE(start_date,0), pkgnum', # to ensure old pkgs come before change_to_pkg -% }) or next; -% -% my $freq_pretty = $cust_pkg[0]->part_pkg->freq_pretty; -% -% my $amount = 0; -% my $skip_pkg = {}; -% foreach my $cust_pkg (@cust_pkg) { -% my $part_pkg = $cust_pkg->part_pkg; -% next if $cust_pkg->susp -% && ! $cust_pkg->option('suspend_bill') -% && ( ! $part_pkg->option('suspend_bill') -% || $cust_pkg->option('no_suspend_bill') -% ); -% -% #pkg change handling -% next if $skip_pkg->{$cust_pkg->pkgnum}; -% if ($cust_pkg->change_to_pkgnum) { -% #if change is on or before next bill date, use new pkg -% next if $cust_pkg->expire <= $cust_pkg->bill; -% #if change is after next bill date, use old (this) pkg -% $skip_pkg->{$cust_pkg->change_to_pkgnum} = 1; -% } -% -% my $pkg_amount = 0; -% -% #add recurring amounts for this package and its billing add-ons -% foreach my $l_part_pkg ( $part_pkg->self_and_bill_linked ) { -% $pkg_amount += $l_part_pkg->base_recur($cust_pkg); -% } -% -% #subtract amounts for any active discounts -% #(there should only be one at the moment, otherwise this makes no sense) -% foreach my $cust_pkg_discount ( $cust_pkg->cust_pkg_discount_active ) { -% my $discount = $cust_pkg_discount->discount; -% #and only one of these for each -% $pkg_amount -= $discount->amount; -% $pkg_amount -= $amount * $discount->percent/100; -% } -% -% $pkg_amount *= ( $cust_pkg->quantity || 1 ); -% -% $amount += $pkg_amount; -% -% } - +% foreach my $freq_info ($cust_main->display_recurring) { - <% emt( ucfirst($freq_pretty). ' recurring' ) %> - <% $money_char. sprintf('%.2f', $amount) %> - + <% emt( ucfirst($freq_info->{'freq_pretty'}). ' recurring' ) %> + <% $money_char. sprintf('%.2f', $freq_info->{'amount'}) %> % } - % } % if ( $conf->exists('cust_main-select-prorate_day') ) { -- cgit v1.2.1 From 259777e4667fc8a45496ba2805d1f7e01c75ac7b Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Wed, 31 Aug 2016 22:26:32 -0500 Subject: RT#71890: SelfService API: Return monthly recurring fee [display_recurring, v3 reconcile bug fix] --- httemplate/view/cust_main/billing.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/httemplate/view/cust_main/billing.html b/httemplate/view/cust_main/billing.html index eed3baf4b..7be320131 100644 --- a/httemplate/view/cust_main/billing.html +++ b/httemplate/view/cust_main/billing.html @@ -30,8 +30,8 @@ % if ( $cust_main->num_ncancelled_pkgs < 54 ) { % foreach my $freq_info ($cust_main->display_recurring) { - <% emt( ucfirst($freq_info->{'freq_pretty'}). ' recurring' ) %> - <% $money_char. sprintf('%.2f', $freq_info->{'amount'}) %> + <% emt( ucfirst($freq_info->{'freq_pretty'}). ' recurring' ) %> + <% $money_char. sprintf('%.2f', $freq_info->{'amount'}) %> % } % } -- cgit v1.2.1 From d5461ef7f534030b662ce5c6ee81eafd5f18cbec Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Wed, 31 Aug 2016 21:49:04 -0500 Subject: 71890: SelfService API: Return monthly recurring fee --- FS/FS/ClientAPI/MyAccount.pm | 23 +++++++++++++++++++++ FS/FS/ClientAPI_XMLRPC.pm | 1 + bin/xmlrpc-customer_recurring | 30 ++++++++++++++++++++++++++++ fs_selfservice/FS-SelfService/SelfService.pm | 26 ++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100755 bin/xmlrpc-customer_recurring diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index 630346a81..23fbf6cf6 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -645,6 +645,29 @@ sub customer_info_short { }; } +sub customer_recurring { + my $p = shift; + + my($context, $session, $custnum) = _custoragent_session_custnum($p); + return { 'error' => $session } if $context eq 'error'; + + my %return; + + my $conf = new FS::Conf; + + my $search = { 'custnum' => $custnum }; + $search->{'agentnum'} = $session->{'agentnum'} if $context eq 'agent'; + my $cust_main = qsearchs('cust_main', $search ) + or return { 'error' => "customer_info_short: unknown custnum $custnum" }; + + $return{'display_recurring'} = [ $cust_main->display_recurring ]; + + return { 'error' => '', + 'custnum' => $custnum, + %return, + }; +} + sub billing_history { my $p = shift; diff --git a/FS/FS/ClientAPI_XMLRPC.pm b/FS/FS/ClientAPI_XMLRPC.pm index 97019d194..7a1fc3e0f 100644 --- a/FS/FS/ClientAPI_XMLRPC.pm +++ b/FS/FS/ClientAPI_XMLRPC.pm @@ -111,6 +111,7 @@ sub ss2clientapi { 'switch_acct' => 'MyAccount/switch_acct', 'customer_info' => 'MyAccount/customer_info', 'customer_info_short' => 'MyAccount/customer_info_short', + 'customer_recurring' => 'MyAccount/customer_recurring', 'contact_passwd' => 'MyAccount/contact/contact_passwd', 'list_contacts' => 'MyAccount/contact/list_contacts', diff --git a/bin/xmlrpc-customer_recurring b/bin/xmlrpc-customer_recurring new file mode 100755 index 000000000..18dd3e896 --- /dev/null +++ b/bin/xmlrpc-customer_recurring @@ -0,0 +1,30 @@ +#!/usr/bin/perl + +use strict; +use Frontier::Client; +use Data::Dumper; + +my( $email, $password ) = @ARGV; +die "Usage: xmlrpc-customer_recurring email password\n" + unless $email && length($password); + +my $uri = new URI 'http://localhost:8080/'; + +my $server = new Frontier::Client ( 'url' => $uri ); + +my $login_result = $server->call( + 'FS.ClientAPI_XMLRPC.login', + 'email' => $email, + 'password' => $password, +); +die $login_result->{'error'}."\n" if $login_result->{'error'}; + +my $list_result = $server->call( + 'FS.ClientAPI_XMLRPC.customer_recurring', + 'session_id' => $login_result->{'session_id'}, +); +die $list_result->{'error'}."\n" if $list_result->{'error'}; + +print Dumper($list_result); + +1; diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm index ecbb6e932..32b2ded32 100644 --- a/fs_selfservice/FS-SelfService/SelfService.pm +++ b/fs_selfservice/FS-SelfService/SelfService.pm @@ -32,6 +32,7 @@ $socket .= '.'.$tag if defined $tag && length($tag); 'switch_acct' => 'MyAccount/switch_acct', 'customer_info' => 'MyAccount/customer_info', 'customer_info_short' => 'MyAccount/customer_info_short', + 'customer_recurring' => 'MyAccount/customer_recurring', 'contact_passwd' => 'MyAccount/contact/contact_passwd', 'list_contacts' => 'MyAccount/contact/list_contacts', @@ -479,6 +480,31 @@ first last company address1 address2 city county state zip country daytime night =back +=item customer_recurring HASHREF + +Takes a hash reference as parameter with a single key B +or keys B and B. + +Returns a hash reference with the keys error, custnum and display_recurring. + +display_recurring is an arrayref of hashrefs with the following keys: + +=over 4 + +=item freq + +frequency of charge, in months unless units are specified + +=item freq_pretty + +frequency of charge, suitable for display + +=item amount + +amount charged at this frequency + +=back + =item edit_info HASHREF Takes a hash reference as parameter with any of the following keys: -- cgit v1.2.1 From 0b8f014e86b3464cca92fd925159e457ae54c2b8 Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Sat, 6 Aug 2016 00:10:39 -0500 Subject: RT#71696: OFM Request for additional action on Billing Events --- FS/FS/part_event/Action/rt_ticket.pm | 100 ++++++++++++++++++++++++++++ httemplate/elements/select-rt-queue.html | 2 +- httemplate/elements/tr-select-rt-queue.html | 7 ++ 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 FS/FS/part_event/Action/rt_ticket.pm create mode 100644 httemplate/elements/tr-select-rt-queue.html diff --git a/FS/FS/part_event/Action/rt_ticket.pm b/FS/FS/part_event/Action/rt_ticket.pm new file mode 100644 index 000000000..a6a616033 --- /dev/null +++ b/FS/FS/part_event/Action/rt_ticket.pm @@ -0,0 +1,100 @@ +package FS::part_event::Action::rt_ticket; + +use strict; +use base qw( FS::part_event::Action ); +use FS::Record qw( qsearchs ); +use FS::msg_template; + +sub description { 'Open an RT ticket for the customer' } + +#need to be valid for msg_template substitution +sub eventtable_hashref { + { 'cust_main' => 1, + 'cust_bill' => 1, + 'cust_pkg' => 1, + 'cust_pay' => 1, + 'svc_acct' => 1, + }; +} + +sub option_fields { + ( + 'msgnum' => { 'label' => 'Template', + 'type' => 'select-table', + 'table' => 'msg_template', + 'name_col' => 'msgname', + 'hashref' => { disabled => '' }, + 'disable_empty' => 1, + }, + 'queueid' => { 'label' => 'Queue', + 'type' => 'select-rt-queue', + }, + 'requestor' => { 'label' => 'Requestor', + 'type' => 'select', + 'options' => [ 0, 1 ], + 'labels' => { + 0 => 'Customer\'s invoice address', + 1 => 'Template From: address', + }, + }, + + ); +} + +sub default_weight { 59; } + +sub do_action { + + my( $self, $object ) = @_; + + my $cust_main = $self->cust_main($object) + or die "Could not load cust_main"; + + my $msgnum = $self->option('msgnum'); + my $msg_template = qsearchs('msg_template', { 'msgnum' => $msgnum } ) + or die "Template $msgnum not found"; + + my $queueid = $self->option('queueid') + or die "No queue specified"; + + # technically this only works if create_ticket is implemented, + # and it is only implemented in RT_Internal, + # but we can let create_ticket throw that error + my $conf = new FS::Conf; + die "rt_ticket event - no ticket system configured" + unless $conf->config('ticket_system'); + + FS::TicketSystem->init(); + + my $cust_msg = $msg_template->prepare( + 'cust_main' => $cust_main, + 'object' => $object, + ); + + my $subject = $cust_msg->entity->head->get('Subject'); + chomp($subject); + + my $requestor = $self->option('requestor') + ? $msg_template->from_addr + : [ $cust_main->invoicing_list_emailonly ]; + + my $svcnum = ref($object) eq 'FS::svc_acct' + ? $object->svcnum + : undef; + + my $err_or_ticket = FS::TicketSystem->create_ticket( + '', #session should already exist + 'queue' => $queueid, + 'subject' => $subject, + 'requestor' => $requestor, + 'message' => $cust_msg->preview, + 'mime_type' => 'text/html', + 'custnum' => $cust_main->custnum, + 'svcnum' => $svcnum, + ); + die $err_or_ticket unless ref($err_or_ticket); + return ''; + +} + +1; diff --git a/httemplate/elements/select-rt-queue.html b/httemplate/elements/select-rt-queue.html index 4ae8bc942..289336516 100644 --- a/httemplate/elements/select-rt-queue.html +++ b/httemplate/elements/select-rt-queue.html @@ -1,4 +1,4 @@ -> % while ( @fields ) { % my $value = shift @fields; % my $label = shift @fields; diff --git a/httemplate/elements/tr-select-rt-queue.html b/httemplate/elements/tr-select-rt-queue.html new file mode 100644 index 000000000..ac3689b1c --- /dev/null +++ b/httemplate/elements/tr-select-rt-queue.html @@ -0,0 +1,7 @@ + +<& 'tr-td-label.html', @_ &> + +<& 'select-rt-queue.html', @_ &> + + + -- cgit v1.2.1 From f33281a9f445b06e319c45f393c71577701eff67 Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Wed, 31 Aug 2016 23:34:48 -0500 Subject: 71696: OFM Request for additional action on Billing Events [v3 fixes] --- FS/FS/part_event/Action/rt_ticket.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FS/FS/part_event/Action/rt_ticket.pm b/FS/FS/part_event/Action/rt_ticket.pm index a6a616033..4a2b993a1 100644 --- a/FS/FS/part_event/Action/rt_ticket.pm +++ b/FS/FS/part_event/Action/rt_ticket.pm @@ -66,12 +66,12 @@ sub do_action { FS::TicketSystem->init(); - my $cust_msg = $msg_template->prepare( + my %msg = $msg_template->prepare( 'cust_main' => $cust_main, 'object' => $object, ); - my $subject = $cust_msg->entity->head->get('Subject'); + my $subject = $msg{'subject'}; chomp($subject); my $requestor = $self->option('requestor') @@ -87,7 +87,7 @@ sub do_action { 'queue' => $queueid, 'subject' => $subject, 'requestor' => $requestor, - 'message' => $cust_msg->preview, + 'message' => $msg{'html_body'}, 'mime_type' => 'text/html', 'custnum' => $cust_main->custnum, 'svcnum' => $svcnum, -- cgit v1.2.1