From 7e78fde169d6e1b25c7e82a9bbcc399d87a2fa02 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 20 Nov 2014 11:42:22 -0800 Subject: optimize once_percust condition --- FS/FS/part_event/Condition/once_percust.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/FS/FS/part_event/Condition/once_percust.pm b/FS/FS/part_event/Condition/once_percust.pm index 67767f91b..2773ca020 100644 --- a/FS/FS/part_event/Condition/once_percust.pm +++ b/FS/FS/part_event/Condition/once_percust.pm @@ -52,13 +52,13 @@ sub condition_sql { my $pkey = $pkey{$table}; - "0 = ( SELECT COUNT(*) FROM cust_event - WHERE cust_event.eventpart = part_event.eventpart - AND cust_event.tablenum IN ( - SELECT $pkey FROM $table AS once_percust - WHERE once_percust.custnum = cust_main.custnum ) - AND status != 'failed' - ) + "NOT EXISTS ( SELECT 1 FROM cust_event + WHERE cust_event.eventpart = part_event.eventpart + AND cust_event.tablenum IN ( + SELECT $pkey FROM $table AS once_percust + WHERE once_percust.custnum = cust_main.custnum ) + AND status != 'failed' + ) "; } -- cgit v1.2.1 From a582fcff5237e93aa3d61fc639c4c766e877ccac Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 20 Nov 2014 11:44:58 -0800 Subject: optimize --- FS/FS/TicketSystem/RT_External.pm | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/FS/FS/TicketSystem/RT_External.pm b/FS/FS/TicketSystem/RT_External.pm index c2aac2db7..9f07732c7 100644 --- a/FS/FS/TicketSystem/RT_External.pm +++ b/FS/FS/TicketSystem/RT_External.pm @@ -175,12 +175,11 @@ sub _from_customer { } else { - $where = - "AND 0 = ( SELECT COUNT(*) FROM ObjectCustomFieldValues - WHERE ObjectId = Tickets.id - AND ObjectType = 'RT::Ticket' - AND $customfield_sql - ) + $where = " AND NOT EXISTS ( SELECT 1 FROM ObjectCustomFieldValues + WHERE ObjectId = Tickets.id + AND ObjectType = 'RT::Ticket' + AND $customfield_sql + ) "; } -- cgit v1.2.1 From d4b8e45c3589f3c6489442798f5fba439d5a29c9 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 20 Nov 2014 11:48:06 -0800 Subject: optimize --- FS/FS/cust_main/Billing_Discount.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/FS/FS/cust_main/Billing_Discount.pm b/FS/FS/cust_main/Billing_Discount.pm index 9dda389f6..d437740e3 100644 --- a/FS/FS/cust_main/Billing_Discount.pm +++ b/FS/FS/cust_main/Billing_Discount.pm @@ -42,11 +42,13 @@ sub _discount_pkgs_and_bill { push @where, "part_pkg.freq = '1'"; push @where, "(cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0)"; push @where, "(cust_pkg.susp IS NULL OR cust_pkg.susp = 0)"; - push @where, "0<(SELECT count(*) FROM part_pkg_discount - WHERE part_pkg.pkgpart = part_pkg_discount.pkgpart)"; + push @where, "EXISTS( SELECT 1 FROM part_pkg_discount + WHERE part_pkg.pkgpart = part_pkg_discount.pkgpart )"; push @where, - "0=(SELECT count(*) FROM cust_bill_pkg_discount - WHERE cust_bill_pkg.billpkgnum = cust_bill_pkg_discount.billpkgnum)"; + "NOT EXISTS ( + SELECT 1 FROM cust_bill_pkg_discount + WHERE cust_bill_pkg.billpkgnum = cust_bill_pkg_discount.billpkgnu: + )"; my $extra_sql = 'WHERE '. join(' AND ', @where); -- cgit v1.2.1 From 5228e2f266bce7e42ad24179da3cddb563c687a0 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 20 Nov 2014 11:55:36 -0800 Subject: optimize --- FS/FS/Cron/notify.pm | 72 ++++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/FS/FS/Cron/notify.pm b/FS/FS/Cron/notify.pm index 1859fcaf7..6d7065429 100644 --- a/FS/FS/Cron/notify.pm +++ b/FS/FS/Cron/notify.pm @@ -28,52 +28,52 @@ sub notify_flat_delay { # select * from cust_pkg where my $where_pkg = <<"END"; - where ( cancel is null or cancel = 0 ) - and ( bill > 0 ) - and - 0 < ( select count(*) from part_pkg - where cust_pkg.pkgpart = part_pkg.pkgpart - and part_pkg.plan = 'flat_delayed' - and 0 < ( select count(*) from part_pkg_option - where part_pkg.pkgpart = part_pkg_option.pkgpart - and part_pkg_option.optionname = 'recur_notify' - and CAST( part_pkg_option.optionvalue AS $integer ) > 0 - and 0 <= ( $time - + CAST( part_pkg_option.optionvalue AS $integer ) - * 86400 - - cust_pkg.bill - ) - and ( cust_pkg.expire is null - or cust_pkg.expire > ( $time - + CAST( part_pkg_option.optionvalue AS $integer ) - * 86400 - ) + WHERE ( cancel IS NULL OR cancel = 0 ) + AND ( bill > 0 ) + AND EXISTS ( + SELECT 1 FROM part_pkg + WHERE cust_pkg.pkgpart = part_pkg.pkgpart + AND part_pkg.plan = 'flat_delayed' + AND EXISTS ( SELECT 1 from part_pkg_option + WHERE part_pkg.pkgpart = part_pkg_option.pkgpart + AND part_pkg_option.optionname = 'recur_notify' + AND CAST( part_pkg_option.optionvalue AS $integer ) > 0 + AND 0 <= ( $time + + CAST( part_pkg_option.optionvalue AS $integer ) + * 86400 + - cust_pkg.bill + ) + AND ( cust_pkg.expire is null + OR cust_pkg.expire > ( $time + + CAST( part_pkg_option.optionvalue AS $integer ) + * 86400 + ) END -#/* and ( cust_pkg.adjourn is null -# or cust_pkg.adjourn > $time +#/* and ( cust_pkg.adjourn is null +# or cust_pkg.adjourn > $time #-- Should notify suspended ones + cast(part_pkg_option.optionvalue as $integer) -# * 86400 +# * 86400 #*/ $where_pkg .= <<"END"; - ) - ) - ) - and - 0 = ( select count(*) from cust_pkg_option - where cust_pkg.pkgnum = cust_pkg_option.pkgnum - and cust_pkg_option.optionname = 'impending_recur_notification_sent' - and CAST( cust_pkg_option.optionvalue AS $integer ) = 1 - ) + ) + ) + ) + AND NOT EXISTS ( + SELECT 1 from cust_pkg_option + WHERE cust_pkg.pkgnum = cust_pkg_option.pkgnum + AND cust_pkg_option.optionname = 'impending_recur_notification_sent' + AND CAST( cust_pkg_option.optionvalue AS $integer ) = 1 + ) END if ($opt{a}) { $where_pkg .= < Date: Thu, 20 Nov 2014 11:57:38 -0800 Subject: optimize --- FS/FS/Misc/prune.pm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/FS/FS/Misc/prune.pm b/FS/FS/Misc/prune.pm index 3f0c79d00..ce7240578 100644 --- a/FS/FS/Misc/prune.pm +++ b/FS/FS/Misc/prune.pm @@ -44,34 +44,34 @@ sub prune_applications { my $ccr = < Date: Thu, 20 Nov 2014 12:02:08 -0800 Subject: optimize --- FS/FS/cust_pkg/Search.pm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/FS/FS/cust_pkg/Search.pm b/FS/FS/cust_pkg/Search.pm index 9cd1ff063..aacd387a6 100644 --- a/FS/FS/cust_pkg/Search.pm +++ b/FS/FS/cust_pkg/Search.pm @@ -312,10 +312,10 @@ sub search { if (@report_option) { # this will result in the empty set for the dangling comma case as it should push @where, - map{ "0 < ( SELECT count(*) FROM part_pkg_option - WHERE part_pkg_option.pkgpart = part_pkg.pkgpart - AND optionname = 'report_option_$_' - AND optionvalue = '1' )" + map{ "EXISTS ( SELECT 1 FROM part_pkg_option + WHERE part_pkg_option.pkgpart = part_pkg.pkgpart + AND optionname = 'report_option_$_' + AND optionvalue = '1' )" } @report_option; } @@ -331,10 +331,10 @@ sub search { if (@report_option_any) { # this will result in the empty set for the dangling comma case as it should push @where, ' ( '. join(' OR ', - map{ "0 < ( SELECT count(*) FROM part_pkg_option - WHERE part_pkg_option.pkgpart = part_pkg.pkgpart - AND optionname = 'report_option_$_' - AND optionvalue = '1' )" + map{ "EXISTS ( SELECT 1 FROM part_pkg_option + WHERE part_pkg_option.pkgpart = part_pkg.pkgpart + AND optionname = 'report_option_$_' + AND optionvalue = '1' )" } @report_option_any ). ' ) '; } -- cgit v1.2.1 From 128cc33659b9811c9ed455275f76fbc7c50a47b7 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 20 Nov 2014 12:02:14 -0800 Subject: optimize --- FS/FS/tax_rate.pm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/FS/FS/tax_rate.pm b/FS/FS/tax_rate.pm index a6da3d111..ec3bb12b6 100644 --- a/FS/FS/tax_rate.pm +++ b/FS/FS/tax_rate.pm @@ -1366,11 +1366,14 @@ sub _remember_tax_products { my ( $imported, $last, $min_sec ) = _progressbar_foo(); - my $extra_sql = "WHERE taxproductnum IS NOT NULL OR ". - "0 < ( SELECT count(*) from part_pkg_option WHERE ". - " part_pkg_option.pkgpart = part_pkg.pkgpart AND ". - " optionname LIKE 'usage_taxproductnum_%' AND ". - " optionvalue != '' )"; + my $extra_sql = " + WHERE taxproductnum IS NOT NULL + OR EXISTS ( SELECT 1 from part_pkg_option + WHERE part_pkg_option.pkgpart = part_pkg.pkgpart + AND optionname LIKE 'usage_taxproductnum_%' + AND optionvalue != '' + ) + "; my @items = qsearch( { table => 'part_pkg', select => 'DISTINCT pkgpart,taxproductnum', hashref => {}, -- cgit v1.2.1 From d87d0051be0696a481ab25fffbd0d53f68af565d Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 4 Dec 2014 10:35:56 -0800 Subject: html nits --- httemplate/misc/suspend_cust.html | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/httemplate/misc/suspend_cust.html b/httemplate/misc/suspend_cust.html index e0d17f30b..8eedd0a57 100644 --- a/httemplate/misc/suspend_cust.html +++ b/httemplate/misc/suspend_cust.html @@ -7,8 +7,7 @@

<% mt('Suspend this customer?') |h %> - +
@@ -36,8 +35,7 @@ function toggle(val) { toggle(false); - +
<& /elements/tr-select-reason.html, 'field' => 'reasonnum', 'reason_class' => 'S', -- cgit v1.2.1 From 2713274c36a5f7688810241157ff9cd2a3b87b1f Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 4 Dec 2014 10:36:12 -0800 Subject: contact reports --- httemplate/elements/menu.html | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index f26882b1f..3236bc14b 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -89,10 +89,16 @@ my $curuser = $FS::CurrentUser::CurrentUser; #XXX Active tickets not assigned to a customer -tie my %report_prospects, 'Tie::IxHash', - 'List prospects' => [ $fsurl. 'search/prospect_main.html', '' ], - 'Advanced prospect reports' => [ $fsurl. 'search/report_prospect_main.html', '' ], -; +tie my %report_prospects, 'Tie::IxHash'; +if ( $curuser->access_right('List prospects') ) { + $report_prospects{'List prospects'} = [ $fsurl. 'search/prospect_main.html', '' ]; + $report_prospects{'Advanced prospect reports'} = [ $fsurl. 'search/report_prospect_main.html', '' ]; +} +$report_prospects{'separator'} = '' + if $curuser->access_right('List prospects') + && $curuser->access_right('List contacts'); +$report_prospects{'Prospect contacts'} = [ $fsurl. 'search/report_contact.html?link=prospect_main', '' ] + if $curuser->access_right('List contacts'); tie my %report_quotations, 'Tie::IxHash', 'List quotations' => [ $fsurl. 'search/quotation.html', '' ], @@ -118,6 +124,10 @@ $report_customers{'Customer churn report'} = [ $fsurl.'graph/report_cust_churn. $report_customers{'Signup date report'} = [ $fsurl. 'graph/report_signupdate.html', 'Signup date report (by date of signup)' ]; $report_customers{'Advanced customer reports'} = [ $fsurl. 'search/report_cust_main.html', 'by status, signup date, agent, etc.' ] if $curuser->access_right('Advanced customer search'); +if ( $curuser->access_right('List contacts') ) { + $report_customers{'separator'} = ''; + $report_customers{'Customer contacts'} = [ $fsurl. 'search/report_contact.html?link=cust_main' ]; +} tie my %report_invoices_open, 'Tie::IxHash', 'All open invoices' => [ $fsurl.'search/cust_bill.html?OPEN_date', 'All invoices with an unpaid balance' ], @@ -399,11 +409,13 @@ $report_logs{'Outgoing messages'} = [ $fsurl.'search/cust_msg.html', 'View outgo tie my %report_menu, 'Tie::IxHash'; $report_menu{'Prospects'} = [ \%report_prospects, 'Prospect reports' ] - if $curuser->access_right('List prospects'); + if $curuser->access_right('List prospects') + || $curuser->access_right('List contacts'); $report_menu{'Quotations'} = [ \%report_quotations, 'Quotation reports' ] if $curuser->access_right('List quotations'); $report_menu{'Customers'} = [ \%report_customers, 'Customer reports' ] - if $curuser->access_right('List customers'); + if $curuser->access_right('List customers') + || $curuser->access_right('List contacts'); $report_menu{'Invoices'} = [ \%report_invoices, 'Invoice reports' ] if $curuser->access_right('List invoices'); $report_menu{'Discounts'} = [ \%report_discounts, 'Discount reports' ] -- cgit v1.2.1 From e4b861922881a19ce2dec5090d964dd56d38cb6a Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 4 Dec 2014 10:36:58 -0800 Subject: fix invoice sorting by package category, RT#31272 --- FS/FS/Template_Mixin.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm index 0928ee52f..5af5b270b 100644 --- a/FS/FS/Template_Mixin.pm +++ b/FS/FS/Template_Mixin.pm @@ -2153,9 +2153,9 @@ sub _items_sections { } else { $section->{'category'} = $sectionname; $section->{'description'} = &{ $escape }($sectionname); - if ( _pkg_category($_) ) { - $section->{'sort_weight'} = _pkg_category($_)->weight; - if ( _pkg_category($_)->condense ) { + if ( _pkg_category($sectionname) ) { + $section->{'sort_weight'} = _pkg_category($sectionname)->weight; + if ( _pkg_category($sectionname)->condense ) { $section = { %$section, $self->_condense_section($opt{format}) }; } } -- cgit v1.2.1 From a2df4ef9575be1ae2f1f5b9089f121316f796bac Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 4 Dec 2014 10:37:14 -0800 Subject: html nits --- httemplate/misc/cancel_cust.html | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/httemplate/misc/cancel_cust.html b/httemplate/misc/cancel_cust.html index 3259a03f6..ebf111935 100644 --- a/httemplate/misc/cancel_cust.html +++ b/httemplate/misc/cancel_cust.html @@ -7,8 +7,7 @@

<% mt('Permanently delete all services and cancel this customer?') |h %> -

+
@@ -44,8 +43,7 @@ toggle(false); <% mt($ban) |h %> % } - +
<& /elements/tr-select-reason.html, 'field' => 'reasonnum', 'reason_class' => 'C', -- cgit v1.2.1 From 61e2f89c40a50478d12b4818400caff32d20f61a Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 4 Dec 2014 10:50:40 -0800 Subject: eliminiate spurious warnings: Argument "" isn't numeric in addition (+) --- FS/FS/Template_Mixin.pm | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm index 05972c0b7..b153d3114 100644 --- a/FS/FS/Template_Mixin.pm +++ b/FS/FS/Template_Mixin.pm @@ -703,10 +703,10 @@ sub print_generic { # cares about application dates. We want to know the sum of all # _top-level transactions_ dated before the last invoice. my @sql = ( - 'SELECT SUM(charged) FROM cust_bill WHERE _date <= ? AND custnum = ?', - 'SELECT -1*SUM(amount) FROM cust_credit WHERE _date <= ? AND custnum = ?', - 'SELECT -1*SUM(paid) FROM cust_pay WHERE _date <= ? AND custnum = ?', - 'SELECT SUM(refund) FROM cust_refund WHERE _date <= ? AND custnum = ?', + "SELECT COALESCE( SUM(charged), 0 ) FROM cust_bill", + "SELECT -1 * COALESCE( SUM(amount), 0 ) FROM cust_credit", + "SELECT -1 * COALESCE( SUM(paid), 0 ) FROM cust_pay", + "SELECT COALESCE( SUM(refund), 0 ) FROM cust_refund", ); # the customer's current balance immediately after generating the last @@ -714,13 +714,11 @@ sub print_generic { my $last_bill_balance = $last_bill->charged; foreach (@sql) { - #warn "$_\n"; my $delta = FS::Record->scalar_sql( - $_, + "$_ WHERE _date <= ? AND custnum = ?", $last_bill->_date - 1, $self->custnum, ); - #warn "$delta\n"; $last_bill_balance += $delta; } @@ -2729,7 +2727,7 @@ sub _items_cust_bill_pkg { 'pkgnum' => $cust_bill_pkg->pkgpart, #so it displays in Ref 'description' => $description, 'amount' => sprintf("%.2f", $cust_bill_pkg->setup), - 'unit_amount' => sprintf("%.2f", $cust_bill_pkg->unitsetup), + 'unit_amount' => sprintf("%.2f", $cust_bill_pkg->unitsetup), 'quantity' => $cust_bill_pkg->quantity, 'preref_html' => ( $opt{preref_callback} ? &{ $opt{preref_callback} }( $cust_bill_pkg ) @@ -2742,9 +2740,9 @@ sub _items_cust_bill_pkg { 'pkgnum' => $cust_bill_pkg->pkgpart, #so it displays in Ref 'description' => "$desc (". $cust_bill_pkg->part_pkg->freq_pretty.")", 'amount' => sprintf("%.2f", $cust_bill_pkg->recur), - 'unit_amount' => sprintf("%.2f", $cust_bill_pkg->unitrecur), + 'unit_amount' => sprintf("%.2f", $cust_bill_pkg->unitrecur), 'quantity' => $cust_bill_pkg->quantity, - 'preref_html' => ( $opt{preref_callback} + 'preref_html' => ( $opt{preref_callback} ? &{ $opt{preref_callback} }( $cust_bill_pkg ) : '' ), -- cgit v1.2.1 From 478c4c0029aca4a9b39ba908c04c8669cde3a6a4 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Thu, 4 Dec 2014 12:58:51 -0800 Subject: fix census tract format, #32499, etc. --- FS/FS/Report/FCC_477.pm | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/FS/FS/Report/FCC_477.pm b/FS/FS/Report/FCC_477.pm index f5d6a06ec..20d402d7d 100644 --- a/FS/FS/Report/FCC_477.pm +++ b/FS/FS/Report/FCC_477.pm @@ -355,8 +355,10 @@ sub fbs_sql { my $agentnum = $opt{agentnum}; my $q = $opt{ignore_quantity} ? '1' : 'COALESCE(cust_pkg.quantity, 1)'; + my $censustract = "replace(cust_location.censustract, '.', '')"; + my @select = ( - 'cust_location.censustract', + "$censustract AS censustract", 'technology', 'broadband_downstream', 'broadband_upstream', @@ -381,8 +383,7 @@ sub fbs_sql { is_fixed_broadband() ); push @where, "cust_main.agentnum = $agentnum" if $agentnum; - my $group_by = 'cust_location.censustract, technology, '. - 'broadband_downstream, broadband_upstream '; + my $group_by = "$censustract, technology, broadband_downstream, broadband_upstream "; my $order_by = $group_by; "SELECT ".join(', ', @select) . " @@ -400,9 +401,10 @@ sub fvs_sql { my $date = $opt{date} || time; my $agentnum = $opt{agentnum}; my $q = $opt{ignore_quantity} ? '1' : 'COALESCE(cust_pkg.quantity, 1)'; + my $censustract = "replace(cust_location.censustract, '.', '')"; my @select = ( - 'cust_location.censustract', + "$censustract AS censustract", # VoIP indicator (0 for non-VoIP, 1 for VoIP) 'COALESCE(is_voip, 0)', # number of lines/subscriptions @@ -426,7 +428,7 @@ sub fvs_sql { "(is_voip = 1 OR is_phone = 1)", ); push @where, "cust_main.agentnum = $agentnum" if $agentnum; - my $group_by = 'cust_location.censustract, COALESCE(is_voip, 0)'; + my $group_by = "$censustract, COALESCE(is_voip, 0)"; my $order_by = $group_by; "SELECT ".join(', ', @select) . " -- cgit v1.2.1 From 7dd8215a91ca6ca4a9988a0108647ada7f2a11d8 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 4 Dec 2014 14:47:49 -0800 Subject: backdate credits, RT#32320 --- FS/FS/AccessRight.pm | 2 ++ FS/FS/access_right.pm | 1 + httemplate/edit/cust_credit.cgi | 20 ++++++++++++----- httemplate/edit/cust_pay.cgi | 39 ++++++++++++--------------------- httemplate/edit/process/cust_credit.cgi | 15 ++++++++++--- httemplate/elements/tr-fixed-date.html | 10 +++++++-- 6 files changed, 52 insertions(+), 35 deletions(-) diff --git a/FS/FS/AccessRight.pm b/FS/FS/AccessRight.pm index 92cede6a5..4a1f89aa0 100644 --- a/FS/FS/AccessRight.pm +++ b/FS/FS/AccessRight.pm @@ -217,6 +217,7 @@ tie my %rights, 'Tie::IxHash', ### 'Customer credit and refund rights' => [ 'Post credit', + { rightname=>'Backdate credit', desc=>'Enable credits to be posted for days other than today.' }, 'Credit line items', #NEWNEWNEW 'Apply credit', #NEWNEW { rightname=>'Unapply credit', desc=>'Enable "unapplication" of unclosed credits.' }, #aka unapplycredits @@ -444,6 +445,7 @@ sub default_superuser_rights { 'Credit card void', 'Echeck void', 'Void invoices',#people are overusing this when credits are more appropriate + 'Backdate credit', ); no warnings 'uninitialized'; diff --git a/FS/FS/access_right.pm b/FS/FS/access_right.pm index ee0c494ae..e5a5781a9 100644 --- a/FS/FS/access_right.pm +++ b/FS/FS/access_right.pm @@ -249,6 +249,7 @@ sub _upgrade_data { # class method 'Edit package definition costs' => 'View package definition costs', 'List prospects' => 'List contacts', 'List customers' => 'List contacts', + 'Backdate payment' => 'Backdate credit', ); # foreach my $old_acl ( keys %onetime ) { diff --git a/httemplate/edit/cust_credit.cgi b/httemplate/edit/cust_credit.cgi index 29801efef..18416c5fb 100755 --- a/httemplate/edit/cust_credit.cgi +++ b/httemplate/edit/cust_credit.cgi @@ -6,15 +6,25 @@ - <% ntable("#cccccc", 2) %> - - - - +% my %date_args = ( +% 'name' => '_date', +% 'label' => emt('Date'), +% 'value' => $_date, +% 'format' => $date_format. ' %r', +% ); +% if ( $FS::CurrentUser::CurrentUser->access_right('Backdate credit') ) { + + <& /elements/tr-input-date-field.html, \%date_args &> + +% } else { + + <& /elements/tr-fixed-date.html, \%date_args &> + +% } diff --git a/httemplate/edit/cust_pay.cgi b/httemplate/edit/cust_pay.cgi index ec7391b20..888335fbb 100755 --- a/httemplate/edit/cust_pay.cgi +++ b/httemplate/edit/cust_pay.cgi @@ -23,37 +23,26 @@ <% mt('Payment') |h %> <% ntable("#cccccc", 2) %> +% my %date_args = ( +% 'name' => '_date', +% 'label' => emt('Date'), +% 'value' => $_date, +% 'format' => $date_format. ' %r', +% 'colspan' => 2, +% ); % if ( $FS::CurrentUser::CurrentUser->access_right('Backdate payment') ) { - - - - - -% } -% else { - - - - + <& /elements/tr-input-date-field.html, \%date_args &> + +% } else { + + <& /elements/tr-fixed-date.html, \%date_args &> + % } - - + % if ( $conf->exists('part_pkg-term_discounts') ) { diff --git a/httemplate/edit/process/cust_credit.cgi b/httemplate/edit/process/cust_credit.cgi index e442d7fa6..39c6f1997 100755 --- a/httemplate/edit/process/cust_credit.cgi +++ b/httemplate/edit/process/cust_credit.cgi @@ -42,11 +42,20 @@ if (!$reasonnum) { } $cgi->param('reasonnum', $reasonnum) unless $error; +my $_date; +if ( $FS::CurrentUser::CurrentUser->access_right('Backdate credit') ) { + $_date = parse_datetime($cgi->param('_date')); +} +else { + $_date = time; +} + +my @fields = grep { $_ ne '_date' } fields('cust_credit'); + unless ($error) { my $new = new FS::cust_credit ( { - map { - $_, scalar($cgi->param($_)); - } fields('cust_credit') + _date => $_date, + map { $_ => scalar($cgi->param($_)) } @fields } ); $error = $new->insert; } diff --git a/httemplate/elements/tr-fixed-date.html b/httemplate/elements/tr-fixed-date.html index 716e5ceb8..ef599796d 100644 --- a/httemplate/elements/tr-fixed-date.html +++ b/httemplate/elements/tr-fixed-date.html @@ -1,12 +1,18 @@ <% include('tr-fixed.html', %opt ) %> <%init> -my %opt = @_; +my %opt; +if ( ref($_[0]) ) { + my $hashref = shift; + %opt = %$hashref; +} else { + %opt = @_; +} my $value = $opt{'curr_value'} || $opt{'value'}; my $conf = new FS::Conf; -my $date_format = $conf->config('date_format') || '%m/%d/%Y'; +my $date_format = $opt{'format'} || $conf->config('date_format') || '%m/%d/%Y'; $opt{'formatted_value'} = time2str($date_format, $value); -- cgit v1.2.1 From 57bdfd4f7e70cab525c9a4bce7f26015517a81ed Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 4 Dec 2014 16:09:10 -0800 Subject: fix to be how we always search for un-disabled things, RT#32230 --- FS/FS/part_export/send_email.pm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/FS/FS/part_export/send_email.pm b/FS/FS/part_export/send_email.pm index 3e5142260..537a562bb 100644 --- a/FS/FS/part_export/send_email.pm +++ b/FS/FS/part_export/send_email.pm @@ -17,13 +17,13 @@ my %template_select = ( $templates{$_[0]}; }, option_values => sub { - %templates = (0 => '', + %templates = ( + 0 => '', map { $_->msgnum, $_->msgname } - qsearch({ table => 'msg_template', - hashref => { disabled => { 'op' => '!=', - 'value' => 1 }}, - order_by => 'ORDER BY msgnum ASC' - }) + qsearch({ table => 'msg_template', + hashref => { disabled => '', }, + order_by => 'ORDER BY msgnum ASC' + }) ); sort keys (%templates); }, -- cgit v1.2.1
<% mt('Date') |h %><% time2str($date_format, $_date) %>
<% mt('Amount') |h %>
<% mt('Date') |h %> - - -
<% mt('Date') |h %> - <% time2str($date_format.' %r',$_date) %> -
<% mt('Amount') |h %><% $money_char %> <% mt('by') |h %> <% mt(FS::payby->payname($payby)) |h %><% $money_char |h %> <% mt('by') |h %> <% mt(FS::payby->payname($payby)) |h %>