[freeside-commits] branch master updated. 9437bfc0dfccd408aa30e0c259031167a1991016

Ivan ivan at 420.am
Tue Dec 27 12:26:42 PST 2016


The branch, master has been updated
       via  9437bfc0dfccd408aa30e0c259031167a1991016 (commit)
      from  58c17d959b59b61da9a5b6b752bb8c295d61fc63 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 9437bfc0dfccd408aa30e0c259031167a1991016
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue Dec 27 12:26:41 2016 -0800

    credit limit for printing

diff --git a/FS/FS/ClientAPI/Freeside.pm b/FS/FS/ClientAPI/Freeside.pm
index 8aa61e6..42b9c42 100644
--- a/FS/FS/ClientAPI/Freeside.pm
+++ b/FS/FS/ClientAPI/Freeside.pm
@@ -44,16 +44,34 @@ sub freesideinc_service {
     return { 'error' => 'bad support-key' };
   }
 
+  my $cust_pkg = $svc_acct->cust_svc->cust_pkg;
+  my $custnum = $cust_pkg->custnum;
+
+  my $quantity = $packet->{'quantity'} || 1;
+
+  #false laziness w/webservice_log.pm
+  my $color = 1.10;
+  my $page = 0.10;
+
   #XXX check if some customers can use some API calls, rate-limiting, etc.
   # but for now, everybody can use everything
+  if ( $packet->{method} eq 'print' ) {
+    my $avail_credit = $cust_pkg->cust_main->credit_limit
+                       - $color - $quantity * $page
+                       - FS::webservice_log->price_print(
+                           'custnum' => $custnum,
+                         );
+
+    return { 'error' => 'Over credit limit' }
+      if $avail_credit <= 0;
+  }
 
   #record it happened
-  my $custnum = $svc_acct->cust_svc->cust_pkg->custnum;
   my $webservice_log = new FS::webservice_log {
     'custnum'  => $custnum,
     'svcnum'   => $svc_acct->svcnum,
     'method'   => $packet->{'method'},
-    'quantity' => $packet->{'quantity'} || 1,
+    'quantity' => $quantity,
   };
   my $error = $webservice_log->insert;
   return { 'error' => $error } if $error;
diff --git a/FS/FS/webservice_log.pm b/FS/FS/webservice_log.pm
index 7e320c2..1dfabe6 100644
--- a/FS/FS/webservice_log.pm
+++ b/FS/FS/webservice_log.pm
@@ -125,6 +125,40 @@ sub check {
 
 =back
 
+=head1 CLASS METHODS
+
+=over 4
+
+=item price_print
+
+Calculates cost of printing unbilled print jobs for this customer.
+
+=cut
+
+sub price_print {
+  my( $class, %opt ) = @_;
+
+#  $opt{'beginning'} ||= 0;
+#  $opt{'ending'}    ||= 4294967295;
+
+  #false laziness w/ClientAPI/Freeside.pm
+  my $color = 1.10;
+  my $page = 0.10;
+
+  $class->scalar_sql("
+    SELECT SUM( $color + quantity * $page )
+      FROM webservice_log
+      WHERE custnum = $opt{custnum}
+        AND method = 'print'
+        AND status IS NULL
+   ");
+#        AND _date >= $opt{beginning}
+#        AND _date <  $opt{ending}
+
+}
+
+=back
+
 =head1 BUGS
 
 =head1 SEE ALSO

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/ClientAPI/Freeside.pm |   22 ++++++++++++++++++++--
 FS/FS/webservice_log.pm     |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 2 deletions(-)




More information about the freeside-commits mailing list