Author: benj
Date: Mon Jan  2 13:19:02 2017
New Revision: 1769

URL: http://svn.gna.org/viewcvs/gdtc?rev=1769&view=rev
Log:
Implement non-payments in coherence amount check.

Modified:
    trunk/gdtc/include/cb_cmcic.php
    trunk/gdtc/include/coherence.php

Modified: trunk/gdtc/include/cb_cmcic.php
URL: 
http://svn.gna.org/viewcvs/gdtc/trunk/gdtc/include/cb_cmcic.php?rev=1769&r1=1768&r2=1769&view=diff
==============================================================================
--- trunk/gdtc/include/cb_cmcic.php     (original)
+++ trunk/gdtc/include/cb_cmcic.php     Mon Jan  2 13:19:02 2017
@@ -31,8 +31,8 @@
       $interval = $date1->diff($date2);
       $months = $interval->format('%m') + $interval->format('%y')*12;
       if ( date_format($date1, 'd' ) > 5 ) $months--;
-      if ( date_format($date2, 'd' ) > 5 ) $months++;
-      #if ( date_format($date1, 'd' ) == date_format($date2, 'd' ) ) $months--;
+      if ( date_format($date2, 'd' ) >= 5 ) $months++;
+      if ( date_format($date1, 'd' ) == date_format($date2, 'd' ) ) $months--;
       return $months * $amount + $prorata;
 }
 
@@ -616,6 +616,16 @@
 }
 
 
+function cbrecur_get_total_non_payment ( $subscription_id )
+{
+    return simple_unique_query ( sprintf (
+        "SELECT SUM(amount) AS total " .
+        "  FROM non_payment " .
+        " WHERE subscription_id = '%s'; ",
+        $subscription_id ) ) [ 'total' ];
+}
+
+
 /* Local Variables: */
 /* c-basic-offset: 4 */
 /* End: */

Modified: trunk/gdtc/include/coherence.php
URL: 
http://svn.gna.org/viewcvs/gdtc/trunk/gdtc/include/coherence.php?rev=1769&r1=1768&r2=1769&view=diff
==============================================================================
--- trunk/gdtc/include/coherence.php    (original)
+++ trunk/gdtc/include/coherence.php    Mon Jan  2 13:19:02 2017
@@ -445,13 +445,22 @@
   foreach ( $results as $result )
     {
       $computed_amount = compute_real_cbrecur_amount ( $result['start_date'], 
$result['end_date'], $result['prelevement_amount'], $result['cbrecur_prorata'] 
);
+      if ( $result [ 'cbrecur_expiration_date' ] == $result [ 'end_date' ] &&
+      preg_match ( '/05$/', $result [ 'cbrecur_expiration_date' ] ) )
+          {
+              $computed_amount += $result [ 'prelevement_amount' ];
+          }
+      $non_payments = cbrecur_get_total_non_payment ( $result [ 
'subscription_id' ] );
+      $computed_amount -= $non_payments;
       if ( $computed_amount != $result [ 'amount' ] )
-       {
-         $name = actor_get_clickable_name ( $result );   
-         $output[3][] = Array ( $result [ 'actor_id' ], 
-                                $name,
-                                sprintf ( "%.2f€ != calculated 
%.2f€", $result [ 'amount' ], $computed_amount ) );
-       }
+      {
+          $name = actor_get_clickable_name ( $result );          
+          $output[3][] = Array
+              ( $result [ 'actor_id' ], 
+              $name,
+              sprintf ( "%.2f€ != calculated %.2f€%s", $result [ 
'amount' ], $computed_amount,
+              ( $computed_amount + $non_payments == $result [ 'amount' ] ? ' 
(fault of non payments)' : '' ) ) );
+      }
     }
 
   $output[0] = "Problème de montant CB récur : " . sizeof($output[3]). " 
résultat(s)";


_______________________________________________
Gdtc-commits mailing list
[email protected]
https://mail.gna.org/listinfo/gdtc-commits

Reply via email to