[freeside-commits] freeside/FS/FS/part_pkg cdr_termination.pm, NONE, 1.1 recur_Common.pm, NONE, 1.1

Ivan,,, ivan at wavetail.420.am
Wed Jul 1 03:28:51 PDT 2009


Update of /home/cvs/cvsroot/freeside/FS/FS/part_pkg
In directory wavetail.420.am:/tmp/cvs-serv10174/FS/FS/part_pkg

Added Files:
	cdr_termination.pm recur_Common.pm 
Log Message:
start of settlement CDR processing, RT#5495

--- NEW FILE: cdr_termination.pm ---
package FS::part_pkg::cdr_termination;

use strict;
use base qw( FS::part_pkg::recur_Common );
use vars qw( $DEBUG %info );
use Tie::IxHash;

tie my %temporalities, 'Tie::IxHash',
  'upcoming'  => "Upcoming (future)",
  'preceding' => "Preceding (past)",
;

%info = (
  'name' => 'VoIP rating of CDR records for termination partners.',
  'shortname' => 'VoIP/telco CDR termination',
  'fields' => {

    'setup_fee'     => { 'name' => 'Setup fee for this package',
                         'default' => 0,
                       },
    'recur_fee'     => { 'name' => 'Base recurring fee for this package',
                         'default' => 0,
                       },

    #false laziness w/flat.pm
    'recur_temporality' => { 'name' => 'Charge recurring fee for period',
                             'type' => 'select',
                             'select_options' => \%temporalities,
                           },

    'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
                                   ' of service at cancellation',
                         'type' => 'checkbox',
                       },

    'cutoff_day'    => { 'name' => 'Billing Day (1 - 28) for prorating or '.
                                   'subscription',
                         'default' => '1',
                       },

    'recur_method'  => { 'name' => 'Recurring fee method',
                         #'type' => 'radio',
                         #'options' => \%recur_method,
                         'type' => 'select',
                         'select_options' => \%FS::part_pkg::recur_Common::recur_method,
                       },
  },

  'fieldorder' => [qw(
                       setup_fee recur_fee recur_temporality unused_credit
                       recur_method cutoff_day
                     )
                  ],

  'weight' => 48,

);

sub calc_setup {
  my($self, $cust_pkg ) = @_;
  $self->option('setup_fee');
}

sub calc_recur {
  my $self = shift;
  my($cust_pkg, $sdate, $details, $param ) = @_;

  #my $last_bill = $cust_pkg->last_bill;
  my $last_bill = $cust_pkg->get('last_bill'); #->last_bill falls back to setup

  return 0
    if $self->option('recur_temporality', 1) eq 'preceding'
    && ( $last_bill eq '' || $last_bill == 0 );

  my $charges = 0;

  # termination calculations

  # find CDRs with cdr_termination.status NULL
  #  and matching our customer via svc_external.id/title?  (and via what field?)

  #for each cdr, set status and rated price and add the charges, and add a line
  #to the invoice

  # eotermiation calculation

  $charges += $self->calc_recur_Common(@_);

  $charges;
}

sub is_free {
  0;
}

1;

--- NEW FILE: recur_Common.pm ---
package FS::part_pkg::recur_Common;

use strict;
use vars qw( @ISA %recur_method );
use Tie::IxHash;
use Time::Local;
use FS::part_pkg::prorate;

@ISA = qw(FS::part_pkg::prorate);

tie %recur_method, 'Tie::IxHash',
  'anniversary'  => 'Charge the recurring fee at the frequency specified above',
  'prorate'      => 'Charge a prorated fee the first time (selectable billing date)',
  'subscription' => 'Charge the full fee for the first partial period (selectable billing date)',
;

sub calc_recur_Common {
  my $self = shift;
  my($cust_pkg, $sdate, $details, $param ) = @_; #only need $sdate & $param

  my $charges = 0;

  if ( $param->{'increment_next_bill'} ) {

    my $recur_method = $self->option('recur_method', 1) || 'anniversary';
                  
    if ( $recur_method eq 'prorate' ) {

      $charges = $self->SUPER::calc_recur(@_);

    } else {

      $charges = $self->option('recur_fee');

      if ( $recur_method eq 'subscription' ) {

        my $cutoff_day = $self->option('cutoff_day', 1) || 1;
        my ($day, $mon, $year) = ( localtime($$sdate) )[ 3..5 ];

        if ( $day < $cutoff_day ) {
          if ( $mon == 0 ) { $mon=11; $year--; }
          else { $mon--; }
        }

        $$sdate = timelocal(0, 0, 0, $cutoff_day, $mon, $year);

      }#$recur_method eq 'subscription'

    }#$recur_method eq 'prorate'

  }#increment_next_bill

  $charges;

}

1;



More information about the freeside-commits mailing list