diff options
Diffstat (limited to 'httemplate/view/cust_main.cgi')
-rwxr-xr-x | httemplate/view/cust_main.cgi | 236 |
1 files changed, 139 insertions, 97 deletions
diff --git a/httemplate/view/cust_main.cgi b/httemplate/view/cust_main.cgi index c36c9e265..ee5f86973 100755 --- a/httemplate/view/cust_main.cgi +++ b/httemplate/view/cust_main.cgi @@ -76,7 +76,7 @@ print '<TD VALIGN="top">'; print "Billing address", &ntable("#cccccc"), "<TR><TD>", &ntable("#cccccc",2), - '<TR><TD ALIGN="right">Contact name</TD>', + '<TR><TD ALIGN="right">Contact name</TD>', '<TD COLSPAN=3 BGCOLOR="#ffffff">', $cust_main->last, ', ', $cust_main->first, '</TD>'; @@ -105,8 +105,8 @@ print '</TR>', $cust_main->country, '</TD></TR>', ; - my $daytime_label = FS::Msgcat::_gettext('daytime') || 'Day Phone'; - my $night_label = FS::Msgcat::_gettext('night') || 'Night Phone'; + my $daytime_label = FS::Msgcat::_gettext('daytime') || 'Day Phone'; + my $night_label = FS::Msgcat::_gettext('night') || 'Night Phone'; print '<TR><TD ALIGN="right">'. $daytime_label. '</TD><TD COLSPAN=5 BGCOLOR="#ffffff">', $cust_main->daytime || ' ', '</TD></TR>', @@ -166,7 +166,7 @@ print '</TD>'; print '<TD VALIGN="top">'; print &ntable("#cccccc"), "<TR><TD>", &ntable("#cccccc",2), - '<TR><TD ALIGN="right">Customer number</TD><TD BGCOLOR="#ffffff">', + '<TR><TD ALIGN="right">Customer number</TD><TD BGCOLOR="#ffffff">', $custnum, '</TD></TR>', ; @@ -184,13 +184,13 @@ print '<TD VALIGN="top">'; my $referral = qsearchs('part_referral', { 'refnum' => $cust_main->refnum } ); - print '<TR><TD ALIGN="right">Advertising source</TD><TD BGCOLOR="#ffffff">', + print '<TR><TD ALIGN="right">Advertising source</TD><TD BGCOLOR="#ffffff">', $referral->refnum, ": ", $referral->referral, '</TD></TR>'; } print '<TR><TD ALIGN="right">Order taker</TD><TD BGCOLOR="#ffffff">', $cust_main->otaker, '</TD></TR>'; - print '<TR><TD ALIGN="right">Referring Customer</TD><TD BGCOLOR="#ffffff">'; + print '<TR><TD ALIGN="right">Referring Customer</TD><TD BGCOLOR="#ffffff">'; my $referring_cust_main = ''; if ( $cust_main->referral_custnum && ( $referring_cust_main = @@ -220,22 +220,22 @@ if ( $conf->config('payby-default') ne 'HIDE' ) { print "Billing information (", qq!<A HREF="!, popurl(2), qq!misc/bill.cgi?$custnum">!, "Bill now</A>)", &ntable("#cccccc"), "<TR><TD>", &ntable("#cccccc",2), - '<TR><TD ALIGN="right">Tax exempt</TD><TD BGCOLOR="#ffffff">', + '<TR><TD ALIGN="right">Tax exempt</TD><TD BGCOLOR="#ffffff">', $cust_main->tax ? 'yes' : 'no', '</TD></TR>', - '<TR><TD ALIGN="right">Postal invoices</TD><TD BGCOLOR="#ffffff">', + '<TR><TD ALIGN="right">Postal invoices</TD><TD BGCOLOR="#ffffff">', ( grep { $_ eq 'POST' } @invoicing_list ) ? 'yes' : 'no', '</TD></TR>', - '<TR><TD ALIGN="right">Email invoices</TD><TD BGCOLOR="#ffffff">', + '<TR><TD ALIGN="right">Email invoices</TD><TD BGCOLOR="#ffffff">', join(', ', grep { $_ ne 'POST' } @invoicing_list ) || 'no', '</TD></TR>', - '<TR><TD ALIGN="right">Billing type</TD><TD BGCOLOR="#ffffff">', + '<TR><TD ALIGN="right">Billing type</TD><TD BGCOLOR="#ffffff">', ; if ( $cust_main->payby eq 'CARD' || $cust_main->payby eq 'DCRD' ) { my $payinfo = $cust_main->payinfo; $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4)); - print 'Credit card ', + print 'Credit card ', ( $cust_main->payby eq 'CARD' ? '(automatic)' : '(on-demand)' ), '</TD></TR>', '<TR><TD ALIGN="right">Card number</TD><TD BGCOLOR="#ffffff">', @@ -247,7 +247,7 @@ if ( $conf->config('payby-default') ne 'HIDE' ) { ; } elsif ( $cust_main->payby eq 'CHEK' || $cust_main->payby eq 'DCHK') { my( $account, $aba ) = split('@', $cust_main->payinfo ); - print 'Electronic check', + print 'Electronic check ', ( $cust_main->payby eq 'CHEK' ? '(automatic)' : '(on-demand)' ), '</TD></TR>', '<TR><TD ALIGN="right">Account number</TD><TD BGCOLOR="#ffffff">', @@ -260,7 +260,7 @@ if ( $conf->config('payby-default') ne 'HIDE' ) { } elsif ( $cust_main->payby eq 'LECB' ) { $cust_main->payinfo =~ /^(\d{3})(\d{3})(\d{4})$/; my $payinfo = "$1-$2-$3"; - print 'Phone bill billing</TD></TR>', + print 'Phone bill billing</TD></TR>', '<TR><TD ALIGN="right">Phone number</TD><TD BGCOLOR="#ffffff">', $payinfo, '</TD></TR>', ; @@ -276,7 +276,7 @@ if ( $conf->config('payby-default') ne 'HIDE' ) { ; } elsif ( $cust_main->payby eq 'COMP' ) { print 'Complimentary</TD></TR>', - '<TR><TD ALIGN="right">Authorized by</TD><TD BGCOLOR="#ffffff">', + '<TR><TD ALIGN="right">Authorized by</TD><TD BGCOLOR="#ffffff">', $cust_main->payinfo, '</TD></TR>', '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">', $cust_main->paydate, '</TD></TR>', @@ -370,7 +370,7 @@ print qq!<BR><A NAME="cust_pkg">Packages</A> !, #get package info -my $packages = get_packages($cust_main); +my $packages = get_packages($cust_main, $conf); if ( @$packages ) { %> @@ -401,27 +401,30 @@ foreach my $pkg (sort pkgsort_pkgnum_cancel @$packages) { <%=$pkg->{pkg}%> - <%=$pkg->{comment}%> ( <%=pkg_details_link($pkg)%> )<BR> <% unless ($pkg->{cancel}) { %> ( <%=pkg_change_link($pkg)%> ) - ( <%=pkg_dates_link($pkg)%> | <%=pkg_customize_link($pkg)%> ) + ( <%=pkg_dates_link($pkg)%> | <%=pkg_customize_link($pkg,$custnum)%> ) <% } %> </TD> <% #foreach (qw(setup last_bill next_bill susp expire cancel)) { - # print qq! <TD ROWSPAN=$rowspan>! . pkg_datestr($pkg,$_) . qq!</TD>\n!; + # print qq! <TD ROWSPAN=$rowspan>! . pkg_datestr($pkg,$_,$conf) . qq!</TD>\n!; #} print "<TD ROWSPAN=$rowspan>". &itable(''); - #move - my %freq = ( - 1 => 'monthly', - 2 => 'bi-monthly', - 3 => 'quarterly', - 6 => 'semi-annually', - 12 => 'annually', - 24 => 'bi-annually', - 36 => 'tri-annually', - ); - sub freq { + + #false laziness w/edit/part_pkg.cgi + my %freq = ( #move this + '1d' => 'daily', + '1w' => 'weekly', + '2w' => 'biweekly (every 2 weeks)', + '1' => 'monthly', + '2' => 'bimonthly (every 2 months)', + '3' => 'quarterly (every 3 months)', + '6' => 'semiannually (every 6 months)', + '12' => 'annually', + '24' => 'biannually (every 2 years)', + ); + my $freq = shift; exists $freq{$freq} ? $freq{$freq} : "every $freq months"; } @@ -431,17 +434,17 @@ foreach my $pkg (sort pkgsort_pkgnum_cancel @$packages) { if ( $pkg->{cancel} ) { #status: cancelled print '<TR><TD><FONT COLOR="#ff0000"><B>Cancelled </B></FONT></TD>'. - '<TD>'. pkg_datestr($pkg,'cancel'). '</TD></TR>'; + '<TD>'. pkg_datestr($pkg,'cancel',$conf). '</TD></TR>'; unless ( $pkg->{setup} ) { print '<TR><TD COLSPAN=2>Never billed</TD></TR>'; } else { print "<TR><TD>Setup </TD><TD>". - pkg_datestr($pkg, 'setup'). '</TD></TR>'; + pkg_datestr($pkg, 'setup',$conf). '</TD></TR>'; print "<TR><TD>Last bill </TD><TD>". - pkg_datestr($pkg, 'last_bill'). '</TD></TR>' + pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>' if $pkg->{'last_bill'}; print "<TR><TD>Suspended </TD><TD>". - pkg_datestr($pkg, 'susp'). '</TD></TR>' + pkg_datestr($pkg, 'susp',$conf). '</TD></TR>' if $pkg->{'susp'}; } @@ -449,19 +452,19 @@ foreach my $pkg (sort pkgsort_pkgnum_cancel @$packages) { if ( $pkg->{susp} ) { #status: suspended print '<TR><TD><FONT COLOR="#FF9900"><B>Suspended</B> </FONT></TD>'. - '<TD>'. pkg_datestr($pkg,'susp'). '</TD></TR>'; + '<TD>'. pkg_datestr($pkg,'susp',$conf). '</TD></TR>'; unless ( $pkg->{setup} ) { print '<TR><TD COLSPAN=2>Never billed</TD></TR>'; } else { print "<TR><TD>Setup </TD><TD>". - pkg_datestr($pkg, 'setup'). '</TD></TR>'; + pkg_datestr($pkg, 'setup',$conf). '</TD></TR>'; } print "<TR><TD>Last bill </TD><TD>". - pkg_datestr($pkg, 'last_bill'). '</TD></TR>' + pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>' if $pkg->{'last_bill'}; # next bill ?? print "<TR><TD>Expires </TD><TD>". - pkg_datestr($pkg, 'expire'). '</TD></TR>' + pkg_datestr($pkg, 'expire',$conf). '</TD></TR>' if $pkg->{'expire'}; print '<TR><TD COLSPAN=2>( '. pkg_unsuspend_link($pkg). ' | '. pkg_cancel_link($pkg). ' )</TD></TR>'; @@ -484,24 +487,24 @@ foreach my $pkg (sort pkgsort_pkgnum_cancel @$packages) { unless ( $pkg->{freq} ) { print "<TR><TD COLSPAN=2>One-time charge</TD></TR>". '<TR><TD>Billed </TD><TD>'. - pkg_datestr($pkg,'setup'). '</TD></TR>'; + pkg_datestr($pkg,'setup',$conf). '</TD></TR>'; } else { print '<TR><TD COLSPAN=2><FONT COLOR="#00CC00"><B>Active</B></FONT>'. ', billed '. freq($pkg->{freq}). '</TD></TR>'. '<TR><TD>Setup </TD><TD>'. - pkg_datestr($pkg, 'setup'). '</TD></TR>'; + pkg_datestr($pkg, 'setup',$conf). '</TD></TR>'; } } print "<TR><TD>Last bill </TD><TD>". - pkg_datestr($pkg, 'last_bill'). '</TD></TR>' + pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>' if $pkg->{'last_bill'}; print "<TR><TD>Next bill </TD><TD>". - pkg_datestr($pkg, 'next_bill'). '</TD></TR>' + pkg_datestr($pkg, 'next_bill',$conf). '</TD></TR>' if $pkg->{'next_bill'}; print "<TR><TD>Expires </TD><TD>". - pkg_datestr($pkg, 'expire'). '</TD></TR>' + pkg_datestr($pkg, 'expire',$conf). '</TD></TR>' if $pkg->{'expire'}; if ( $pkg->{freq} ) { print '<TR><TD COLSPAN=2>( '. pkg_suspend_link($pkg). @@ -551,6 +554,11 @@ function cust_pay_unapply_areyousure(href) { == true) window.location.href = href; } +function cust_credit_areyousure(href) { + if (confirm("Are you sure you want to delete this credit?") + == true) + window.location.href = href; +} </SCRIPT> END @@ -625,9 +633,13 @@ if ( $conf->config('payby-default') ne 'HIDE' ) { $cust_credit->reason, time2str("%D", $cust_credit_bill->_date), ); + my $delete = + $cust_credit->closed !~ /^Y/i && $conf->exists('deletecredits') + ? qq! (<A HREF="javascript:cust_credit_areyousure('${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum. qq!')">delete</A>)! + : ''; push @history, "$date\tCredit #$crednum: $reason<BR>". - "(applied to invoice #$invnum on $app_date)\t\t\t$amount\t"; + "(applied to invoice #$invnum on $app_date)$delete\t\t\t$amount\t"; } } @@ -656,12 +668,16 @@ if ( $conf->config('payby-default') ne 'HIDE' ) { qsearch('cust_credit',{'custnum'=>$custnum}); foreach my $credit (@credits) { my($cref)=$credit->hashref; + my $delete = + $credit->closed !~ /^Y/i && $conf->exists('deletecredits') + ? qq! (<A HREF="javascript:cust_credit_areyousure('${p}misc/delete-cust_credit.cgi?!. $credit->crednum. qq!')">delete</A>)! + : ''; push @history, $cref->{_date} . "\t" . qq!<A HREF="! . popurl(2). qq!edit/cust_credit_bill.cgi?!. $cref->{crednum} . qq!">!. '<b><font size="+1" color="#ff0000">Unapplied credit #' . $cref->{crednum} . "</font></b></A>: ". - $cref->{reason} . "\t\t\t" . $credit->credited . "\t"; + $cref->{reason} . "$delete\t\t\t" . $credit->credited . "\t"; } my(@refunds)=qsearch('cust_refund',{'custnum'=> $custnum } ); @@ -767,52 +783,79 @@ sub keyfield_numerically { (split(/\t/,$a))[0] <=> (split(/\t/,$b))[0]; } sub get_packages { + my $cust_main = shift or return undef; + my $conf = shift; + + my @packages = (); + + foreach my $cust_pkg ( + $conf->exists('hidecancelledpackages') + ? $cust_main->ncancelled_pkgs + : $cust_main->all_pkgs + ) { + + my $part_pkg = $cust_pkg->part_pkg; + + my %pkg = (); + $pkg{pkgnum} = $cust_pkg->pkgnum; + $pkg{pkg} = $part_pkg->pkg; + $pkg{pkgpart} = $part_pkg->pkgpart; + $pkg{comment} = $part_pkg->getfield('comment'); + $pkg{freq} = $part_pkg->freq; + $pkg{setup} = $cust_pkg->getfield('setup'); + $pkg{last_bill} = $cust_pkg->getfield('last_bill'); + $pkg{next_bill} = $cust_pkg->getfield('bill'); + $pkg{susp} = $cust_pkg->getfield('susp'); + $pkg{expire} = $cust_pkg->getfield('expire'); + $pkg{cancel} = $cust_pkg->getfield('cancel'); + + my %svcparts = (); -my $cust_main = shift or return undef; - -my @packages = (); - -foreach my $cust_pkg (($conf->exists('hidecancelledpackages') ? ($cust_main->ncancelled_pkgs) - : ($cust_main->all_pkgs))) { - - my $part_pkg = $cust_pkg->part_pkg; - - my %pkg = (); - $pkg{pkgnum} = $cust_pkg->pkgnum; - $pkg{pkg} = $part_pkg->pkg; - $pkg{pkgpart} = $part_pkg->pkgpart; - $pkg{comment} = $part_pkg->getfield('comment'); - $pkg{freq} = $part_pkg->freq; - $pkg{setup} = $cust_pkg->getfield('setup'); - $pkg{last_bill} = $cust_pkg->getfield('last_bill'); - $pkg{next_bill} = $cust_pkg->getfield('bill'); - $pkg{susp} = $cust_pkg->getfield('susp'); - $pkg{expire} = $cust_pkg->getfield('expire'); - $pkg{cancel} = $cust_pkg->getfield('cancel'); - - $pkg{svcparts} = []; - - foreach my $pkg_svc (qsearch('pkg_svc', { 'pkgpart' => $part_pkg->pkgpart })) { - - next if ($pkg_svc->quantity == 0); - - my $part_svc = qsearchs('part_svc', { 'svcpart' => $pkg_svc->svcpart }); - - my $svcpart = {}; - $svcpart->{svcpart} = $part_svc->svcpart; - $svcpart->{svc} = $part_svc->svc; - $svcpart->{svcdb} = $part_svc->svcdb; - $svcpart->{quantity} = $pkg_svc->quantity; - $svcpart->{count} = 0; + foreach my $pkg_svc ( + qsearch('pkg_svc', { 'pkgpart' => $part_pkg->pkgpart }) + ) { + + next if ($pkg_svc->quantity == 0); + + my $part_svc = qsearchs('part_svc', { 'svcpart' => $pkg_svc->svcpart }); + + my $svcpart = {}; + $svcpart->{svcpart} = $part_svc->svcpart; + $svcpart->{svc} = $part_svc->svc; + $svcpart->{svcdb} = $part_svc->svcdb; + $svcpart->{quantity} = $pkg_svc->quantity; + $svcpart->{count} = 0; + + $svcpart->{services} = []; - $svcpart->{services} = []; + $svcparts{$svcpart->{svcpart}} = $svcpart; - foreach my $cust_svc (qsearch('cust_svc', { 'pkgnum' => $cust_pkg->pkgnum, - 'svcpart' => $part_svc->svcpart } )) { + } - my $svc = {}; - $svc->{svcnum} = $cust_svc->svcnum; - $svc->{label} = ($cust_svc->label)[1]; + foreach my $cust_svc ( + qsearch( 'cust_svc', { + 'pkgnum' => $cust_pkg->pkgnum, + #'svcpart' => $part_svc->svcpart, + } + ) + ) { + + warn "svcnum ". $cust_svc->svcnum. " / svcpart ". $cust_svc->svcpart. "\n"; + my $svc = { + 'svcnum' => $cust_svc->svcnum, + 'label' => ($cust_svc->label)[1], + }; + + #false laziness with above, to catch extraneous services. whole + #damn thing should be OO... + my $svcpart = ( $svcparts{$cust_svc->svcpart} ||= { + 'svcpart' => $cust_svc->svcpart, + 'svc' => $cust_svc->part_svc->svc, + 'svcdb' => $cust_svc->part_svc->svcdb, + 'quantity' => 0, + 'count' => 0, + 'services' => [], + } ); push @{$svcpart->{services}}, $svc; @@ -820,29 +863,27 @@ foreach my $cust_pkg (($conf->exists('hidecancelledpackages') ? ($cust_main->nca } - push @{$pkg{svcparts}}, $svcpart; + $pkg{svcparts} = [ values %svcparts ]; + push @packages, \%pkg; + } - - push @packages, \%pkg; - -} - -return \@packages; + + return \@packages; } sub svc_link { - my ($svcpart, $svc) = (shift,shift) or return ''; - return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svcpart->{svc}</A>!; + my ($svcpart, $svc) = (shift,shift) or return ''; + return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svcpart->{svc}</A>!; } sub svc_label_link { - my ($svcpart, $svc) = (shift,shift) or return ''; - return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svc->{label}</A>!; + my ($svcpart, $svc) = (shift,shift) or return ''; + return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svc->{label}</A>!; } @@ -875,7 +916,7 @@ sub pkgsort_pkgnum_cancel { } sub pkg_datestr { - my($pkg, $field) = @_ or return ''; + my($pkg, $field, $conf) = @_ or return ''; return ' ' unless $pkg->{$field}; my $format = $conf->exists('pkg_showtimes') ? '<B>%D</B> <FONT SIZE=-3>%l:%M:%S%P %z</FONT>' @@ -916,6 +957,7 @@ sub pkg_dates_link { sub pkg_customize_link { my $pkg = shift or return ''; + my $custnum = shift; return qq!<A HREF="${p}edit/part_pkg.cgi?keywords=$custnum;clone=$pkg->{pkgpart};pkgnum=$pkg->{pkgnum}">Customize</A>!; } |