Author: benj
Date: Fri Mar 6 16:15:30 2015
New Revision: 1650
URL: http://svn.gna.org/viewcvs/gdtc?rev=1650&view=rev
Log:
Add new 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=1650&r1=1649&r2=1650&view=diff
==============================================================================
--- trunk/gdtc/include/coherence.php (original)
+++ trunk/gdtc/include/coherence.php Fri Mar 6 16:15:30 2015
@@ -52,12 +52,14 @@
function incoherences_get ( )
{
- return Array ( check_membership_renewal_date_is_fucked (),
- check_prelevement_renewal_date_is_fucked (),
- check_prelevement_start_date_is_fucked (),
- check_prelevement_periodicity_is_fucked (),
- check_prelevement_not_created(),
- check_no_current_membership() );
+ return Array ( check_cmcic_periodicity_is_fucked () ,
+ check_cmcic_amount_is_fucked ()/* , */
+ /* check_membership_renewal_date_is_fucked (), */
+ /* check_prelevement_renewal_date_is_fucked (), */
+ /* check_prelevement_start_date_is_fucked (), */
+ /* check_prelevement_periodicity_is_fucked (), */
+ /* check_prelevement_not_created(), */
+ /* check_no_current_membership() */ );
}
@@ -74,6 +76,9 @@
function ajax_fix ( $test, $id )
{
+ if ( $test == 'cmcic_periodicity_is_fucked' )
+ return fix_cmcic_periodicity_is_fucked ( $id );
+
if ( $test == 'prelevement_renewal_date_is_fucked' )
return fix_prelevement_renewal_date_is_fucked ( $id );
@@ -374,4 +379,127 @@
}
+
+
+
+/***** CB amount is fucked */
+
+function compute_real_cbrecur_amount ( $result )
+{
+ $start_date = preg_replace ( '/^(\d\d\d\d-\d\d)-\d\d/', '$1-05',
$result['start_date']);
+ $end_date = preg_replace ( '/^(\d\d\d\d-\d\d)-\d\d/', '$1-05',
$result['end_date']);
+ $date1 = new DateTime($start_date);
+ $date2 = new DateTime($end_date);
+ $interval = $date1->diff($date2);
+ $months = $interval->format('%m') + $interval->format('%y')*12;
+ if ( date_format($date1, 'd' ) > 5 ) $month--;
+ if ( date_format($date2, 'd' ) >= 5 ) $month++;
+ return $months * $result [ 'prelevement_amount' ] + $result [
'cbrecur_prorata' ];
+}
+
+
+function check_cmcic_amount_is_fucked ()
+{
+ $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 );
+ foreach ( $results as $result )
+ {
+ $computed_amount = compute_real_cbrecur_amount ( $result );
+ if ( $computed_amount != $result [ 'amount' ] )
+ {
+ if ( $result [ 'actor_type' ] == 'person' )
+ {
+ $name = sprintf ( "%s %s",
+ $result [ 'firstname' ], $result [
'person_name' ] );
+ }
+ else
+ {
+ $name = $result [ 'entity_name' ];
+ }
+
+ $output[3][] = Array ( $result [ 'actor_id' ],
+ $name,
+ sprintf ( "%.2f€ != calculated
%.2f€", $result [ 'amount' ], $computed_amount ) );
+ }
+ }
+
+ if ( $output[3] )
+ return $output;
+}
+
+
+
+/***** CB recur periodicity */
+
+function check_cmcic_periodicity_is_fucked ()
+{
+ $results = basic_query ( " AND subscription.payment_mode = 'cbweb_recur' " .
+ " AND payment_received_date IS NOT NULL " .
+ " AND voucher is NULL" );
+ if ( ! $results ) return;
+
+ $output = Array ( "Problème de périodicity récur : " . sizeof($results).
" résultat(s)", 'cmcic_periodicity_is_fucked', 1 );
+ foreach ( $results as $result )
+ {
+ if ( $computed_amount != $result [ 'amount' ] )
+ {
+ if ( $result [ 'actor_type' ] == 'person' )
+ {
+ $name = sprintf ( "%s %s",
+ $result [ 'firstname' ], $result [
'person_name' ] );
+ }
+ else
+ {
+ $name = $result [ 'entity_name' ];
+ }
+
+ $output[3][] = Array ( $result [ 'actor_id' ],
+ $name,
+ "periodicity is NULL" );
+ }
+ }
+
+ if ( $output[3] )
+ return $output;
+}
+
+
+function fix_cmcic_periodicity_is_fucked ( $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 " .
+ " AND voucher is NULL;", $id ) );
+
+ $result = simple_unique_query
+ ( sprintf
+ ( "SELECT * FROM subscription WHERE payment_mode = 'cbweb_recur' AND
subscription_id != '%d' AND membership_id = '%d' ORDER BY subscription_id DESC
LIMIT 1",
+ $orig [ 'subscription_id' ], $orig [ 'membership_id' ] ) );
+
+ if ( $result )
+ {
+ if ( simple_query
+ ( sprintf
+ ( "UPDATE subscription SET voucher = '%s', reference='%s',
cbrecur_prorata = 0, amount=%d WHERE subscription_id = '%d';",
+ $result [ 'voucher' ], $result [ 'reference' ],
compute_real_cbrecur_amount ( $result ), $orig [ 'subscription_id' ] ) ) )
+ record_change ( 'changed', 'subscription', 'subscription_id',
+ $orig['subscription_id'], 'amount', $orig [ 'amount' ],
compute_real_cbrecur_amount ( $result ) );
+ record_change ( 'changed', 'subscription', 'subscription_id',
+ $orig['subscription_id'], 'reference', $orig [
'reference' ], $result [ 'reference' ] );
+ record_change ( 'changed', 'subscription', 'subscription_id',
+ $orig['subscription_id'], 'voucher', $orig [ 'voucher'
], $result [ 'voucher' ] );
+
+ return print "good";
+ }
+
+ print 'Impossible de corriger';
+}
+
+
?>
_______________________________________________
Gdtc-commits mailing list
[email protected]
https://mail.gna.org/listinfo/gdtc-commits