From: ivan Date: Mon, 15 Oct 2001 10:42:29 +0000 (+0000) Subject: price plans web gui 1st pass, oh my X-Git-Tag: freeside_1_4_0pre11~283 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=a6d3e4dc73803cffad96fd4b6270b2fb5f4b0568;hp=87b5424ee8f16f824865cd7dbf1efde8da3bd429 price plans web gui 1st pass, oh my --- diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index d5beca92a..f99a15e69 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -216,10 +216,9 @@ otherwise returns false. CUST_PKG_HASHREF: If you pass a Tie::RefHash data structure to the insert method containing FS::cust_pkg and FS::svc_I objects, all records -are inserted atomicly, or the transaction is rolled back (this requries a -transactional database). Passing an empty hash reference is equivalent to -not supplying this parameter. There should be a better explanation of this, -but until then, here's an example: +are inserted atomicly, or the transaction is rolled back. Passing an empty +hash reference is equivalent to not supplying this parameter. There should be +a better explanation of this, but until then, here's an example: use Tie::RefHash; tie %hash, 'Tie::RefHash'; #this part is important @@ -233,7 +232,7 @@ INVOICING_LIST_ARYREF: If you pass an arrarref to the insert method, it will be set as the invoicing list (see L<"invoicing_list">). Errors return as expected and rollback the entire transaction; it is not necessary to call check_invoicing_list first. The invoicing_list is set after the records in the -CUST_PKG_HASHREF above are inserted, so it is now possible set set an +CUST_PKG_HASHREF above are inserted, so it is now possible to set an invoicing_list destination to the newly-created svc_acct. Here's an example: $cust_main->insert( {}, [ $email, 'POST' ] ); @@ -1216,9 +1215,9 @@ sub collect { } my @invoicing_list = grep { $_ ne 'POST' } $self->invoicing_list; - if ( $conf->exists('emailinvoiceonly') ) { - @invoicing_list = $self->default_invoicing_list - unless @invoicing_list; + if ( $conf->exists('emailinvoiceauto') + || ( $conf->exists('emailinvoiceonly') && ! @invoicing_list ) ) { + push @invoicing_list, $self->default_invoicing_list; } my $email = $invoicing_list[0]; @@ -1467,7 +1466,7 @@ sub apply_payments { } - # return 0; + return $self->total_unapplied_payments; } =item total_credited @@ -1559,15 +1558,17 @@ sub invoicing_list { } else { @cust_main_invoice = (); } + my %seen = map { $_->address => 1 } @cust_main_invoice; foreach my $address ( @{$arrayref} ) { - unless ( grep { $address eq $_->address } @cust_main_invoice ) { - my $cust_main_invoice = new FS::cust_main_invoice ( { - 'custnum' => $self->custnum, - 'dest' => $address, - } ); - my $error = $cust_main_invoice->insert; - warn $error if $error; - } + #unless ( grep { $address eq $_->address } @cust_main_invoice ) { + next if exists $seen{$address} && $seen{$address}; + $seen{$address} = 1; + my $cust_main_invoice = new FS::cust_main_invoice ( { + 'custnum' => $self->custnum, + 'dest' => $address, + } ); + my $error = $cust_main_invoice->insert; + warn $error if $error; } } if ( $self->custnum ) { @@ -1603,6 +1604,8 @@ sub check_invoicing_list { =item default_invoicing_list +Returns the email addresses of any + =cut sub default_invoicing_list { @@ -1647,6 +1650,40 @@ sub referral_cust_main { @cust_main; } +=item referral_cust_pkg [ DEPTH ] + +Like referral_cust_main, except returns a flat list of all unsuspended packages +for each customer. The number of items in this list may be useful for +comission calculations (perhaps after a grep). + +=cut + +sub referral_cust_pkg { + my $self = shift; + my $depth = @_ ? shift : 1; + + map { $_->unsuspended_pkgs } + grep { $_->unsuspended_pkgs } + $self->referral_cust_main($depth); +} + +=item credit AMOUNT, REASON + +Applies a credit to this customer. If there is an error, returns the error, +otherwise returns false. + +=cut + +sub credit { + my( $self, $amount, $reason ) = @_; + my $cust_credit = new FS::cust_credit { + 'custnum' => $self->custnum, + 'amount' => $amount, + 'reason' => $reason, + }; + $cust_credit->insert; +} + =back =head1 SUBROUTINES @@ -1788,7 +1825,7 @@ sub append_fuzzyfiles { =head1 VERSION -$Id: cust_main.pm,v 1.39 2001-10-09 23:10:16 ivan Exp $ +$Id: cust_main.pm,v 1.40 2001-10-15 10:42:28 ivan Exp $ =head1 BUGS diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index d262a04e0..d84b9c5b7 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -46,11 +46,15 @@ inherits from FS::Record. The following fields are currently supported: =item comment - Text name of this billing item definition (non-customer-viewable) -=item setup - Setup fee +=item setup - Setup fee expression =item freq - Frequency of recurring fee -=item recur - Recurring fee +=item recur - Recurring fee expression + +=item plan - Price plan + +=item plandata - Price plan data =back @@ -128,6 +132,8 @@ sub check { || $self->ut_anything('setup') || $self->ut_number('freq') || $self->ut_anything('recur') + || $self->ut_alphan('plan') + || $self->ut_anything('plandata') ; } @@ -166,7 +172,7 @@ sub svcpart { =head1 VERSION -$Id: part_pkg.pm,v 1.2 1999-08-20 08:27:06 ivan Exp $ +$Id: part_pkg.pm,v 1.3 2001-10-15 10:42:28 ivan Exp $ =head1 BUGS diff --git a/README.1.4.0pre3-4 b/README.1.4.0pre3-4 index 102b57872..49ca5a4d0 100644 --- a/README.1.4.0pre3-4 +++ b/README.1.4.0pre3-4 @@ -14,6 +14,8 @@ CREATE INDEX part_pop_local1 ON part_pop_local ( npa, nxx ); ALTER TABLE cust_pkg ADD manual_flag char(1) NULL; ALTER TABLE cust_pay_batch ADD paybatchnum integer; CREATE UNIQUE INDEX cust_pay_batch_pkey ON cust_pay_batch ( paybatchnum ); +ALTER TABLE part_pkg ADD plan varchar NULL; +ALTER TABLE part_pkg ADD plandata varchar NULL; Run bin/dbdef-create diff --git a/bin/fs-setup b/bin/fs-setup index edfc5ff1c..96ec2b74b 100755 --- a/bin/fs-setup +++ b/bin/fs-setup @@ -1,6 +1,6 @@ #!/usr/bin/perl -Tw # -# $Id: fs-setup,v 1.61 2001-10-09 23:10:17 ivan Exp $ +# $Id: fs-setup,v 1.62 2001-10-15 10:42:28 ivan Exp $ #to delay loading dbdef until we're ready BEGIN { $FS::Record::setup_hack = 1; } @@ -73,7 +73,7 @@ my($char_d) = 80; #default maxlength for text fields #my(@date_type) = ( 'timestamp', '', '' ); my(@date_type) = ( 'int', 'NULL', '' ); -my(@perl_type) = ( 'varchar', 'NULL', 255 ); +my(@perl_type) = ( 'varchar', 'NULL', '' ); my @money_type = ( 'decimal', '', '10,2' ); ### @@ -540,6 +540,8 @@ sub tables_hash_hack { 'setup', @perl_type, 'freq', 'int', '', '', #billing frequency (months) 'recur', @perl_type, + 'plan', 'varchar', 'NULL', '', + 'plandata', 'varchar', 'NULL', '', ], 'primary_key' => 'pkgpart', 'unique' => [ [] ], diff --git a/httemplate/browse/part_pkg.cgi b/httemplate/browse/part_pkg.cgi index 1538a7127..e20ba2404 100755 --- a/httemplate/browse/part_pkg.cgi +++ b/httemplate/browse/part_pkg.cgi @@ -1,5 +1,5 @@ <% -# +# use strict; use vars qw( $cgi $p $part_pkg ); @@ -27,9 +27,9 @@ print $cgi->header( '-expires' => 'now' ), header("Package Definition Listing",m Package Comment - Setup Fee Freq. - Recur. Fee + Plan + Data Service Quan. @@ -42,6 +42,16 @@ foreach $part_pkg ( sort { my(@pkg_svc)=grep $_->getfield('quantity'), qsearch('pkg_svc',{'pkgpart'=> $hashref->{pkgpart} }); my($rowspan)=scalar(@pkg_svc); + my $plandata; + if ( $hashref->{plan} ) { + $plandata = $hashref->{plandata}; + $plandata =~ s/^(\w+)=/$1 /mg; + $plandata =~ s/\n/
/g; + } else { + $hashref->{plan} = "(legacy)"; + $plandata = "Setup ". $hashref->{setup}. + "
Recur ". $hashref->{recur}; + } print < @@ -49,9 +59,9 @@ foreach $part_pkg ( sort { $hashref->{pkg} $hashref->{comment} - $hashref->{setup} $hashref->{freq} - $hashref->{recur} + $hashref->{plan} + $plandata END my($pkg_svc); diff --git a/httemplate/docs/config.html b/httemplate/docs/config.html index 63f6baba9..3c6fe0252 100644 --- a/httemplate/docs/config.html +++ b/httemplate/docs/config.html @@ -53,7 +53,8 @@ All further configuration files and directories are located in
  • disable_customer_referrals - The existance of this file will disable new customer-to-customer referrals in the web interface.
  • domain - Your domain name.
  • editreferrals - The existance of this file will allow you to change the referral of existing customers. -
  • emailinvoiceonly +
  • emailinvoiceonly - Disables postal mail invoices. +
  • emailinvoiceauto - Automatically adds new accounts to the email invoice list upon customer creation.
  • erpcdmachines - Your ERPCD authenticaion machines, one per line. This enables export of `/usr/annex/acp_passwd' and `/usr/annex/acp_dialup'.
  • hidecancelledpackages - The existance of this file will prevent cancelled packages from showing up in listings (though they will still be in the database)
  • hidecancelledcustomers - The existance of this file will prevent customers with only cancelled packages from showing up in listings (though they will still be in the database) diff --git a/httemplate/docs/schema.html b/httemplate/docs/schema.html index d831c59f4..88b4cb2b1 100644 --- a/httemplate/docs/schema.html +++ b/httemplate/docs/schema.html @@ -193,9 +193,11 @@
  • pkgpart - primary key
  • pkg - package name
  • comment - non-customer visable package comment -
  • setup - setup fee +
  • setup - setup fee expression
  • freq - recurring frequency (months) -
  • recur - recurring fee +
  • recur - recurring fee expression +
  • plan - price plan +
  • plandata - additional price plan data
  • part_referral - Referral listing
      diff --git a/httemplate/docs/upgrade8.html b/httemplate/docs/upgrade8.html index 79eb6da3f..c317e88c8 100644 --- a/httemplate/docs/upgrade8.html +++ b/httemplate/docs/upgrade8.html @@ -135,6 +135,8 @@ ALTER TABLE cust_pay ADD custnum integer; ALTER TABLE cust_pay_batch ADD paybatchnum integer; ALTER TABLE cust_refund ADD custnum integer; ALTER TABLE cust_pkg ADD manual_flag char(1) NULL; +ALTER TABLE part_pkg ADD plan varchar NULL; +ALTER TABLE part_pkg ADD plandata varchar NULL; CREATE INDEX cust_main3 ON cust_main ( referral_custnum ); CREATE INDEX cust_credit_bill1 ON cust_credit_bill ( crednum ); CREATE INDEX cust_credit_bill2 ON cust_credit_bill ( invnum ); @@ -223,7 +225,7 @@ CREATE TABLE cust_pay_temp ( INSERT INTO cust_pay_temp SELECT * from cust_pay; DROP TABLE cust_pay; ALTER TABLE cust_pay_temp RENAME TO cust_pay; -CREATE UNIQUE INDEX cust_pay1 ON cust_pay paynum; +CREATE UNIQUE INDEX cust_pay1 ON cust_pay (paynum); CREATE TABLE cust_refund_temp ( refundnum int primary key, custnum int not null, @@ -238,7 +240,7 @@ CREATE TABLE cust_refund_temp ( INSERT INTO cust_refund_temp SELECT * from cust_refund; DROP TABLE cust_refund; ALTER TABLE cust_refund_temp RENAME TO cust_refund; -CREATE UNIQUE INDEX cust_refund1 ON cust_refund refundnum; +CREATE UNIQUE INDEX cust_refund1 ON cust_refund (refundnum);
      diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi
      index b7707f3e8..a4123e137 100755
      --- a/httemplate/edit/part_pkg.cgi
      +++ b/httemplate/edit/part_pkg.cgi
      @@ -1,23 +1,7 @@
      -
      -
      -<% my $plan = 'flat'; %>
      -
      -
      +
       
       <%
       
      -$cgi = new CGI;
      -
      -&cgisuidsetup($cgi);
      -
       if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
         $cgi->param('clone', $1);
       } else {
      @@ -44,16 +28,36 @@ if ( $cgi->param('clone') ) {
         $part_pkg ||= $old_part_pkg->clone;
       } elsif ( $query && $query =~ /^(\d+)$/ ) {
         $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
      +  unless ( $part_pkg->plan ) {
      +    $part_pkg->plan('flat');
      +    $part_pkg->plandata("setup=". $part_pkg->setup. "\n".
      +                        "recur=". $part_pkg->recur. "\n");
      +  }
       } else {
         $part_pkg ||= new FS::part_pkg {};
      +  $part_pkg->plan('flat');
       }
       $action ||= $part_pkg->pkgpart ? 'Edit' : 'Add';
       my $hashref = $part_pkg->hashref;
       
      +%>
      +
      +
      +
      +<% 
      +
       print header("$action Package Definition", menubar(
         'Main Menu' => popurl(2),
         'View all packages' => popurl(2). 'browse/part_pkg.cgi',
      -));
      +), ' onLoad="visualize()"');
       
       print qq!Error: !, $cgi->param('error'),
             ""
      @@ -136,8 +140,12 @@ my %plans = (
         'flat' => {
           'name' => 'Flat rate',
           'fields' => {
      -      'setup_fee' => { 'name' => 'Setup fee for this package' },
      -      'recur_fee' => { 'name' => 'Recurring fee for this package' },
      +      'setup_fee' => { 'name' => 'Setup fee for this package',
      +                       'default' => 0,
      +                     },
      +      'recur_fee' => { 'name' => 'Recurring fee for this package',
      +                       'default' => 0,
      +                      },
           },
           'setup' => 'what.setup_fee.value',
           'recur' => 'what.recur_fee.value',
      @@ -146,13 +154,21 @@ my %plans = (
         'flat_comission' => {
           'name' => 'Flat rate with recurring referral comission as credit',
           'fields' => {
      -      'setup_fee' => { 'name' => 'Setup fee for this package' },
      -      'recur_fee' => { 'name' => 'Recurring fee for this package' },
      -      'comission_amount' => { 'name' => 'Comission amount' },
      -      'comission_depth' => { 'name' => 'Number of layers' },
      +      'setup_fee' => { 'name' => 'Setup fee for this package',
      +                       'default' => 0,
      +                     },
      +      'recur_fee' => { 'name' => 'Recurring fee for this package',
      +                       'default' => 0,
      +                     },
      +      'comission_amount' => { 'name' => 'Comission amount',
      +                              'default' => 0,
      +                            },
      +      'comission_depth'  => { 'name' => 'Number of layers',
      +                              'default' => 1,
      +                            },
           },
           'setup' => 'what.setup_fee.value',
      -    'recur' => '\'$cust_pkg->cust_main->credit( \' + what.comission_amount.value + \' * scalar($cust_pkg->cust_main->referral_cust_pkg(\' + what.comission_depth.value+ \')), "commission" ) ; \' + what.recur_fee.value + \';\'',
      +    'recur' => '\'my $error = $cust_pkg->cust_main->credit( \' + what.comission_amount.value + \' * scalar($cust_pkg->cust_main->referral_cust_pkg(\' + what.comission_depth.value+ \')), "commission" ); die $error if $error; \' + what.recur_fee.value + \';\'',
         },
       
       );
      @@ -160,8 +176,7 @@ my %plans = (
       %>
       
       
       
      -Price plan +