X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fquotation.pm;h=a3f061291b4330dc404bc9cbc36255ffdce399ad;hp=c61e001c6a84efa9442b8ead5b43cae38e37d29b;hb=046409735189fe40a1d349c4f1902da2bc1d71b2;hpb=5f2456557fee6e8d09733aad18200e4b2bbc2d93 diff --git a/FS/FS/quotation.pm b/FS/FS/quotation.pm index c61e001c6..a3f061291 100644 --- a/FS/FS/quotation.pm +++ b/FS/FS/quotation.pm @@ -138,8 +138,9 @@ sub check { $self->usernum($FS::CurrentUser::CurrentUser->usernum) unless $self->usernum; - return 'confidence must be an integer between 1 and 100' - if length($self->confidence) && (($self->confidence < 1) || ($self->confidence > 100)); + return 'confidence percentage must be an integer between 1 and 100' + if length($self->confidence) + && ( ($self->confidence < 1) || ($self->confidence > 100) ); return 'prospectnum or custnum must be specified' if ! $self->prospectnum @@ -226,6 +227,11 @@ sub email_subject { eval qq("$subject"); } +sub pdf_filename { + my $self = shift; + 'Quotation-'. $self->quotationnum. '.pdf'; +} + =item cust_or_prosect =cut @@ -272,9 +278,10 @@ sub _items_sections { my %opt = @_; my $escape = $opt{escape}; # the only one we care about + my %show; # package frequency => 1 if there's anything to display my %subtotals = (); # package frequency => subtotal - my $disable_total = 0; + my $prorate_total = 0; foreach my $pkg ($self->quotation_pkg) { my $part_pkg = $pkg->part_pkg; @@ -288,7 +295,7 @@ sub _items_sections { #this is a shitty hack based on what's in part_pkg/ at the moment # but its good enough for the 99% common case of preventing totals from # displaying for prorate packages - $disable_total = 1 + $prorate_total = 1 if $part_pkg->plan =~ /^(prorate|torrus|agent$)/ || $part_pkg->option('recur_method') eq 'prorate' || ( $part_pkg->option('sync_bill_date') @@ -296,6 +303,9 @@ sub _items_sections { && $self->cust_main->billing_pkgs #num_billing_pkgs when we have it ); + #possible improvement: keep track of flat vs. prorate totals to make the + # bottom range more accurate when mixing flat and prorate packages + } my @pkg_freq_order = keys %{ FS::Misc->pkg_freqs }; @@ -330,15 +340,31 @@ sub _items_sections { }; } - unless ( $disable_total || $no_recurring ) { + unless ( $no_recurring ) { my $total = 0; $total += $_ for values %subtotals; - push @sections, { - 'description' => 'First payment', + my %total = ( 'sort_weight' => 0, - 'category' => 'Total category', #required but what's it used for? - 'subtotal' => sprintf('%.2f',$total) - }; + 'category' => 'Total category', #required but what's it used for? + ); + + if ( $prorate_total ) { + + push @sections, { + %total, + 'description' => 'First payment (depending on day of month)', + 'subtotal' => [ $subtotals{0}, $total ], + }; + + } else { + + push @sections, { + %total, + 'description' => 'First payment', + 'subtotal' => $total, + }; + } + } return \@sections, []; @@ -510,6 +536,7 @@ sub charge { my $cust_pkg_ref = ''; my ( $bill_now, $invoice_terms ) = ( 0, '' ); my $locationnum; + my ( $discountnum, $discountnum_amount, $discountnum_percent ) = ( '','','' ); if ( ref( $_[0] ) ) { $amount = $_[0]->{amount}; $setup_cost = $_[0]->{setup_cost}; @@ -529,6 +556,9 @@ sub charge { $bill_now = exists($_[0]->{bill_now}) ? $_[0]->{bill_now} : ''; $invoice_terms = exists($_[0]->{invoice_terms}) ? $_[0]->{invoice_terms} : ''; $locationnum = $_[0]->{locationnum}; + $discountnum = $_->{setup_discountnum}; + $discountnum_amount = $_->{setup_discountnum_amount}; + $discountnum_percent = $_->{setup_discountnum_percent}; } else { $amount = shift; $setup_cost = ''; @@ -599,12 +629,15 @@ sub charge { # of ordering a customer package, no "bill now") my $quotation_pkg = new FS::quotation_pkg ( { - 'quotationnum' => $self->quotationnum, - 'pkgpart' => $pkgpart, - 'quantity' => $quantity, - #'start_date' => $start_date, - #'no_auto' => $no_auto, - 'locationnum'=> $locationnum, + 'quotationnum' => $self->quotationnum, + 'pkgpart' => $pkgpart, + 'quantity' => $quantity, + #'start_date' => $start_date, + #'no_auto' => $no_auto, + 'locationnum' => $locationnum, + 'setup_discountnum' => $discountnum, + 'setup_discountnum_amount' => $discountnum_amount, + 'setup_discountnum_percent' => $discountnum_percent, } ); $error = $quotation_pkg->insert; @@ -683,7 +716,10 @@ sub estimate { my $cust_main; if ( $cust_or_prospect->isa('FS::prospect_main') ) { $cust_main = $cust_or_prospect->convert_cust_main; - die "$cust_main (simulating customer signup)\n" unless ref $cust_main; + unless ( ref($cust_main) ) { + $temp_dbh->rollback; + die "$cust_main (simulating customer signup)\n"; + } $fake_self->set('prospectnum', ''); $fake_self->set('custnum', $cust_main->custnum); } else { @@ -691,8 +727,12 @@ sub estimate { } # order packages + local($FS::cust_pkg::disable_start_on_hold) = 1; $error = $fake_self->order(\%pkgnum_of); - die "$error (simulating package order)\n" if $error; + if ( $error ) { + $temp_dbh->rollback; + die "$error (simulating package order)\n"; + } my @new_pkgs = map { FS::cust_pkg->by_key($_) } values(%pkgnum_of); @@ -705,7 +745,10 @@ sub estimate { 'no_usage_reset' => 1, ); $error = $cust_main->bill(%bill_opt); - die "$error (simulating initial billing)\n" if $error; + if ( $error ) { + $temp_dbh->rollback; + die "$error (simulating initial billing)\n" if $error; + } # pick dates for future bills my %next_bill_pkgs; @@ -721,7 +764,10 @@ sub estimate { $bill_opt{'return_bill'} = $return_bill[$i] = []; $bill_opt{'pkg_list'} = $next_bill_pkgs{$next_bill}; $error = $cust_main->bill(%bill_opt); - die "$error (simulating recurring billing cycle $i)\n" if $error; + if ( $error ) { + $temp_dbh->rollback; + die "$error (simulating recurring billing cycle $i)\n"; + } $i++; }