summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorivan <ivan>2004-06-29 04:02:45 +0000
committerivan <ivan>2004-06-29 04:02:45 +0000
commit157e8bdba110b7aac022bd2c2f7b377d3c5b2f85 (patch)
tree9dc49439d40ebbbeeea1db3f48fdd6ee7602cb34 /httemplate
parentf1e474e3ea4c658b9a1f84af108f09a65886055c (diff)
add cust_pay_refund table to refund payments
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/docs/upgrade10.html20
-rwxr-xr-xhttemplate/edit/cust_bill_pay.cgi8
-rwxr-xr-xhttemplate/edit/process/cust_bill_pay.cgi24
-rwxr-xr-xhttemplate/view/cust_main.cgi40
4 files changed, 66 insertions, 26 deletions
diff --git a/httemplate/docs/upgrade10.html b/httemplate/docs/upgrade10.html
index c2b88be32..1d099646f 100644
--- a/httemplate/docs/upgrade10.html
+++ b/httemplate/docs/upgrade10.html
@@ -113,8 +113,8 @@ select setval('public.part_pkg_temp_pkgpart_seq', ( select max(pkgpart) from par
Or on Pg versions that don't support DROP CONSTRAINT and ADD PRIMARY KEY (tested on 7.1 and 7.2 so far):
DROP INDEX part_pkg_temp_pkey;
CREATE UNIQUE INDEX part_pkg_pkey ON part_pkg (pkgpart);
-7.1?: select setval('part_pkg_temp_pkgpart_seq', ( select max(pkgpart) from part_pkg) );
-7.2: select setval('part_pkg_pkgpart_seq', ( select max(pkgpart) from part_pkg) );
+probably this one?: select setval('part_pkg_temp_pkgpart_seq', ( select max(pkgpart) from part_pkg) );
+probably not this one?: select setval('part_pkg_pkgpart_seq', ( select max(pkgpart) from part_pkg) );
CREATE TABLE h_part_pkg_temp (
historynum serial NOT NULL,
@@ -148,9 +148,19 @@ select setval('public.h_part_pkg_temp_historynum_seq', ( select max(historynum)
Or on Pg versions that don't support DROP CONSTRAINT and ADD PRIMARY KEY (tested on 7.1 and 7.2 so far):
DROP INDEX h_part_pkg_temp_pkey;
CREATE UNIQUE INDEX h_part_pkg_pkey ON h_part_pkg (historynum);
-7.1?: select setval('h_part_pkg_temp_historynum_seq', ( select max(historynum) from h_part_pkg) );
-7.2: select setval('h_part_pkg_historynum_seq', ( select max(historynum) from h_part_pkg) );
-
+probably this one?: select setval('h_part_pkg_temp_historynum_seq', ( select max(historynum) from h_part_pkg) );
+probably not this one?: select setval('h_part_pkg_historynum_seq', ( select max(historynum) from h_part_pkg) );
+
+CREATE TABLE cust_pay_refund (
+ payrefundnum serial NOT NULL,
+ paynum int NOT NULL,
+ refundnum int NOT NULL,
+ _date int NOT NULL,
+ amount decimal(10,2) NOT NULL,
+ PRIMARY KEY (payrefundnum)
+);
+CREATE INDEX cust_pay_refund1 ON cust_pay_refund(paynum);
+CREATE INDEX cust_pay_refund2 ON cust_pay_refund(refundnum);
DROP INDEX cust_bill_pkg1;
diff --git a/httemplate/edit/cust_bill_pay.cgi b/httemplate/edit/cust_bill_pay.cgi
index 8cdf4509a..24bce308a 100755
--- a/httemplate/edit/cust_bill_pay.cgi
+++ b/httemplate/edit/cust_bill_pay.cgi
@@ -59,10 +59,10 @@ foreach my $cust_bill ( @cust_bill ) {
END
}
-# if ( cust_bill == "Refund" ) {
-# what.form.amount.value = "$credited";
-# }
print <<END;
+ if ( cust_bill == "Refund" ) {
+ what.form.amount.value = "$unapplied";
+ }
}
</SCRIPT>
END
@@ -75,7 +75,7 @@ foreach my $cust_bill ( @cust_bill ) {
' - '. time2str("%D",$cust_bill->_date).
' - $'. $cust_bill->owed;
}
-#print qq!<OPTION VALUE="Refund">Refund!;
+print qq!<OPTION VALUE="Refund">Refund!;
print "</SELECT>";
print qq!<BR>Amount \$<INPUT TYPE="text" NAME="amount" VALUE="$amount" SIZE=8 MAXLENGTH=8>!;
diff --git a/httemplate/edit/process/cust_bill_pay.cgi b/httemplate/edit/process/cust_bill_pay.cgi
index 0c33506a8..0025b16b5 100755
--- a/httemplate/edit/process/cust_bill_pay.cgi
+++ b/httemplate/edit/process/cust_bill_pay.cgi
@@ -11,12 +11,24 @@ my $cust_main = qsearchs('cust_main', { 'custnum' => $cust_pay->custnum } )
my $custnum = $cust_main->custnum;
-my $new = new FS::cust_bill_pay ( {
- map {
- $_, scalar($cgi->param($_));
- #} qw(custnum _date amount invnum)
- } fields('cust_bill_pay')
-} );
+my $new;
+if ($cgi->param('invnum') =~ /^Refund$/) {
+ $new = new FS::cust_refund ( {
+ 'reason' => 'Refunding payment', #enter reason in UI
+ 'refund' => $cgi->param('amount'),
+ 'payby' => 'BILL',
+ #'_date' => $cgi->param('_date'),
+ 'payinfo' => 'Cash', #enter payinfo in UI
+ 'paynum' => $paynum,
+ } );
+} else {
+ $new = new FS::cust_bill_pay ( {
+ map {
+ $_, scalar($cgi->param($_));
+ #} qw(custnum _date amount invnum)
+ } fields('cust_bill_pay')
+ } );
+}
my $error = $new->insert;
diff --git a/httemplate/view/cust_main.cgi b/httemplate/view/cust_main.cgi
index cf899d041..125c51aef 100755
--- a/httemplate/view/cust_main.cgi
+++ b/httemplate/view/cust_main.cgi
@@ -604,6 +604,7 @@ function cust_credit_areyousure(href) {
? $cust_pay->payinfo_masked
: $cust_pay->payinfo;
my @cust_bill_pay = $cust_pay->cust_bill_pay;
+ my @cust_pay_refund = $cust_pay->cust_pay_refund;
my $target = "$payby$payinfo";
$payby =~ s/^BILL$/Check #/ if $payinfo;
@@ -612,25 +613,42 @@ function cust_credit_areyousure(href) {
my $info = $payby ? " ($payby$payinfo)" : '';
my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
- if ( scalar(@cust_bill_pay) == 0 ) {
+ if ( scalar(@cust_bill_pay) == 0
+ && scalar(@cust_pay_refund) == 0 ) {
#completely unapplied
$pre = '<B><FONT COLOR="#FF0000">Unapplied ';
$post = '</FONT></B>';
$apply = qq! (<A HREF="${p}edit/cust_bill_pay.cgi?!.
$cust_pay->paynum. '">apply</A>)';
- } elsif ( scalar(@cust_bill_pay) == 1 && $cust_pay->unapplied == 0 ) {
- #applied to one invoice
+ } elsif ( scalar(@cust_bill_pay) == 1
+ && scalar(@cust_pay_refund) == 0
+ && $cust_pay->unapplied == 0 ) {
+ #applied to one invoice, the usual situation
$desc = ' applied to Invoice #'. $cust_bill_pay[0]->invnum;
+ } elsif ( scalar(@cust_bill_pay) == 0
+ && scalar(@cust_pay_refund) == 1
+ && $cust_pay->unapplied == 0 ) {
+ #applied to one refund
+ $desc = ' refunded on '. time2str("%D", $cust_pay_refund[0]->_date);
} else {
#complicated
$desc = '<BR>';
- foreach my $cust_bill_pay (@cust_bill_pay) {
- $desc .= '&nbsp;&nbsp;'.
- '$'. $cust_bill_pay->amount.
- ' applied to Invoice #'. $cust_bill_pay->invnum.
- '<BR>';
- #' on '. time2str("%D", $cust_bill_pay->_date).
-
+ foreach my $app ( sort { $a->_date <=> $b->_date }
+ ( @cust_bill_pay, @cust_pay_refund ) ) {
+ if ( $app->isa('FS::cust_bill_pay') ) {
+ $desc .= '&nbsp;&nbsp;'.
+ '$'. $app->amount.
+ ' applied to Invoice #'. $app->invnum.
+ '<BR>';
+ #' on '. time2str("%D", $cust_bill_pay->_date).
+ } elsif ( $app->isa('FS::cust_pay_refund') ) {
+ $desc .= '&nbsp;&nbsp;'.
+ '$'. $app->amount.
+ ' refunded on'. time2str("%D", $app->_date).
+ '<BR>';
+ } else {
+ die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
+ }
}
if ( $cust_pay->unapplied > 0 ) {
$desc .= '&nbsp;&nbsp;'.
@@ -684,7 +702,7 @@ function cust_credit_areyousure(href) {
} elsif ( scalar(@cust_credit_bill) == 1
&& scalar(@cust_credit_refund) == 0
&& $cust_credit->credited == 0 ) {
- #applied to one invoice
+ #applied to one invoice, the usual situation
$desc = ' applied to Invoice #'. $cust_credit_bill[0]->invnum;
} elsif ( scalar(@cust_credit_bill) == 0
&& scalar(@cust_credit_refund) == 1