Author: benj
Date: Thu Mar 12 19:16:58 2015
New Revision: 1652

URL: http://svn.gna.org/viewcvs/gdtc?rev=1652&view=rev
Log:
Add new coherence test

Modified:
    trunk/gdtc/include/coherence.php

Modified: trunk/gdtc/include/coherence.php
URL: 
http://svn.gna.org/viewcvs/gdtc/trunk/gdtc/include/coherence.php?rev=1652&r1=1651&r2=1652&view=diff
==============================================================================
--- trunk/gdtc/include/coherence.php    (original)
+++ trunk/gdtc/include/coherence.php    Thu Mar 12 19:16:58 2015
@@ -91,6 +91,9 @@
 
   if ( $test == 'prelevement_not_created' )
       return fix_prelevement_not_created ( $id );
+
+  if ( $test == 'cmcic_amount' )
+      return fix_cmcic_amount ( $id );
 
   print 'FAIL';
   return;
@@ -404,7 +407,7 @@
   $results = basic_query ( "AND subscription.payment_mode = 'cbweb_recur'" );
   if ( ! $results ) return;
 
-  $output = Array ( "Problème de montant CB récur : " . sizeof($results). " 
résultat(s)", false, 0 );
+  $output = Array ( "Problème de montant CB récur : " . sizeof($results). " 
résultat(s)", 'cmcic_amount', true );
   foreach ( $results as $result )
     {
       $computed_amount = compute_real_cbrecur_amount ( $result );
@@ -425,9 +428,41 @@
                                 sprintf ( "%.2f€ != calculated 
%.2f€", $result [ 'amount' ], $computed_amount ) );
        }
     }
+
+  $output[0] = "Problème de montant CB récur : " . sizeof($output[3]). " 
résultat(s)";
     
   if ( $output[3] )
     return $output;
+}
+
+
+function fix_cmcic_amount ($id)
+{
+  $orig = simple_unique_query 
+    ( sprintf 
+      ( "SELECT subscription.* " .
+       " FROM subscription, membership " .
+       "WHERE membership.actor_id = '%d' AND membership.membership_id = 
subscription.membership_id ".
+       "  AND subscription.payment_mode = 'cbweb_recur' " .
+       "  AND payment_received_date IS NOT NULL " .
+       "ORDER BY subscription_id DESC " .
+       "LIMIT 1;", $id ) );
+
+  if ( $orig )
+    {
+      if ( simple_query
+          ( sprintf
+            ( "UPDATE subscription SET amount=%d WHERE subscription_id = 
'%d';",
+              compute_real_cbrecur_amount ( $orig ), $orig [ 'subscription_id' 
] ) ) )
+       {
+         record_change ( 'changed', 'subscription', 'subscription_id',
+                         $orig['subscription_id'], 'amount', $orig [ 'amount' 
],
+                         compute_real_cbrecur_amount ( $orig ) );
+         return print "good";
+       }
+    }
+
+  print 'Impossible de corriger';
 }
 
 


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

Reply via email to