Index: civicrm/trunk/sites/all/modules/contribution_audit/contribution_audit.module |
— | — | @@ -47,10 +47,10 @@ |
48 | 48 | } |
49 | 49 | |
50 | 50 | function contribution_audit_allocate_unallocated_contribs( $start_date, $end_date ) { |
| 51 | + watchdog( 'contribution_audit', 'Running contribution_audit_allocate_unallocated_contribs for time period from @start_date until @end_date', array( '@start_date' => $start_date, '@end_date' => $end_date ), WATCHDOG_DEBUG ); |
51 | 52 | $allocated = array(); // country => $ |
52 | 53 | // find the info from missing trxns |
53 | 54 | $missing_trxns = contribution_audit_find_missing_trxns( $start_date, $end_date ); |
54 | | - |
55 | 55 | foreach ( $missing_trxns as $missing_trxn ) { |
56 | 56 | // what happens if we still dont have country data? |
57 | 57 | if ( !strlen($missing_trxn[ 'country' ])) { |
— | — | @@ -63,12 +63,14 @@ |
64 | 64 | |
65 | 65 | function _contribution_audit_aggregate_country_amounts( &$allocated, $trxn ) { |
66 | 66 | // handle currency conversion, etc |
67 | | - $trxn = _queue2civicrm_normalize_contrib_amnts( $missing_trxn ); |
| 67 | + $trxn = _queue2civicrm_normalize_contrib_amnts( $trxn ); |
68 | 68 | |
69 | 69 | if ( !in_array( $trxn[ 'country' ], array_keys( $allocated ))) { |
70 | | - $allocated[ $trxn[ 'country' ]] = $trxn[ 'gross' ]; |
| 70 | + $allocated[ $trxn[ 'country' ]][ 'amnt' ] = $trxn[ 'gross' ]; |
| 71 | + $allocated[ $trxn[ 'country' ]][ 'count' ] = 1; |
71 | 72 | } else { |
72 | | - $allocated[ $trxn[ 'country' ]] += $trxn[ 'gross' ]; |
| 73 | + $allocated[ $trxn[ 'country' ]][ 'amnt' ] += $trxn[ 'gross' ]; |
| 74 | + $allocated[ $trxn[ 'country' ]][ 'count' ]++; |
73 | 75 | } |
74 | 76 | } |
75 | 77 | |
— | — | @@ -77,8 +79,7 @@ |
78 | 80 | * @return array containing the missing transactions |
79 | 81 | */ |
80 | 82 | function contribution_audit_find_missing_trxns( $start_date, $end_date ) { |
81 | | - $missing_trxns = array(); |
82 | | - module_invoke_all( 'contribution_audit_find_missing_trxns', $missing_trxns, $start_date, $end_date ); |
| 83 | + $missing_trxns = module_invoke_all( 'contribution_audit_find_missing_trxns', $start_date, $end_date ); |
83 | 84 | return $missing_trxns; |
84 | 85 | } |
85 | 86 | |
Index: civicrm/trunk/sites/all/modules/contribution_audit/allocate_unallocated_contribs.drush.inc |
— | — | @@ -41,10 +41,44 @@ |
42 | 42 | * Fires the 'contribution_audit_allocate_unallocated_contribs' method in the contribution_audit. |
43 | 43 | */ |
44 | 44 | function drush_allocate_unallocated_contribs() { |
45 | | - $start_date = drush_get_option( $start ); |
46 | | - $end_date = drush_get_option( $end ); |
47 | | - $allocated = module_invoke( 'contribution_audit', 'contribution_audit_allocate_unallocated_contribs', $start_date, $end_date ); |
48 | | - foreach( $allocated as $key => $value ) { |
49 | | - print "'$key','$value'\n"; |
| 45 | + $start_date = drush_get_option( 'start' ); |
| 46 | + $end_date = drush_get_option( 'end' ); |
| 47 | + watchdog( 'contribution_audit_drush', 'Preparing to allocate unallocated contribs for timeframe between @start and @end', array('@start'=>$start_date, '@end'=>$end_date )); |
| 48 | + $allocated = array(); |
| 49 | + |
| 50 | + // for memory purposes, we don't want startdate/enddate to be more than 7 days apart, this should be configurable. |
| 51 | + while ( strtotime( $start_date ) < strtotime( $end_date )) { |
| 52 | + $this_end_date = date( 'Y-m-d', strtotime( '+7 days', strtotime( $start_date ))); |
| 53 | + // if our increment goes beyond the original end date, reset it back to the original end date |
| 54 | + if ( strtotime( $this_end_date ) > strtotime( $end_date )) { |
| 55 | + $this_end_date = $end_date; |
| 56 | + } |
| 57 | + |
| 58 | + watchdog( 'contribution_audit_drush', 'Preparing to invoke contribution_audit allocate_unallocated_contribs() for timeframe between @start and @end', array('@start'=>$start_date, '@end'=>$end_date )); |
| 59 | + |
| 60 | + $this_allocated = module_invoke( 'contribution_audit', 'allocate_unallocated_contribs', $start_date, $this_end_date ); |
| 61 | + allocate_unallocated_contribs_merge( $allocated, $this_allocated ); |
| 62 | + |
| 63 | + // move our start date up by 8 days for the next batch |
| 64 | + $start_date = date( 'Y-m-d', strtotime( '+8 days', strtotime( $start_date ))); |
50 | 65 | } |
| 66 | + |
| 67 | + if ( !count($allocated)) { |
| 68 | + print "All contributions present and allocated.\n"; |
| 69 | + } else { |
| 70 | + foreach( $allocated as $key => $val ) { |
| 71 | + print "'$key','" . $val['amnt'] . "','" . $val['count'] . "'\n"; |
| 72 | + } |
| 73 | + } |
51 | 74 | } |
| 75 | + |
| 76 | +function allocate_unallocated_contribs_merge( &$allocated, $local_allocated ) { |
| 77 | + foreach ( $local_allocated as $country => $data ) { |
| 78 | + if ( !in_array( $country, array_keys( $allocated ))) { |
| 79 | + $allocated = array_merge( $allocated, $local_allocated ); |
| 80 | + } else { |
| 81 | + $allocated[ $country ][ 'amnt' ] += $local_allocated[ $country ][ 'amnt' ]; |
| 82 | + $allocated[ $country ][ 'count' ] += $local_allocated[ $country ][ 'count' ]; |
| 83 | + } |
| 84 | + } |
| 85 | +} |