Changeset 2711 for sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/reimbursement-request.php
- Timestamp:
- 03/08/2016 05:05:43 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/reimbursement-request.php
r2710 r2711 956 956 return ob_get_clean(); 957 957 } 958 959 /** 960 * NACHA via JP Morgan 961 * 962 * @param array $args 963 * 964 * @return string 965 */ 966 function _generate_payment_report_jpm_ach( $args ) { 967 $args = wp_parse_args( $args, array( 968 'data' => array(), 969 'status' => '', 970 'post_type' => '', 971 ) ); 972 973 $ach_options = apply_filters( 'wcb_payment_req_ach_options', array( 974 'bank-routing-number' => '', // Immediate Destination (bank routing number) 975 'company-id' => '', // Company ID 976 'financial-inst' => '', // Originating Financial Institution 977 ) ); 978 979 ob_start(); 980 981 // File Header Record 982 983 echo '1'; // Record Type Code 984 echo '01'; // Priority Code 985 echo ' ' . str_pad( substr( $ach_options['bank-routing-number'], 0, 9 ), 9, '0', STR_PAD_LEFT ); 986 echo str_pad( substr( $ach_options['company-id'], 0, 10 ), 10, '0', STR_PAD_LEFT ); // Immediate Origin (TIN) 987 echo date( 'ymd' ); // Transmission Date 988 echo date( 'Hi' ); // Transmission Time 989 echo 'A'; // File ID Modifier 990 echo '094'; // Record Size 991 echo '10'; // Blocking Factor 992 echo '1'; // Format Code 993 echo str_pad( 'JPMORGANCHASE', 23 ); // Destination 994 echo str_pad( 'WCEXPORT', 23 ); // Origin 995 echo str_pad( '', 8 ); // Reference Code (optional) 996 echo PHP_EOL; 997 998 // Batch Header Record 999 1000 echo '5'; // Record Type Code 1001 echo '200'; // Service Type Code 1002 echo 'WordCamp Communi'; // Company Name 1003 echo str_pad( '', 20 ); // Blanks 1004 echo str_pad( substr( $ach_options['company-id'], 0, 10 ), 10 ); // Company Identification 1005 1006 // Get the first one in the set. 1007 // @todo Split batches by account type. 1008 foreach ( $args['data'] as $entry ) { 1009 switch_to_blog( $entry->blog_id ); 1010 $post = get_post( $entry->request_id ); 1011 1012 if ( $args['status'] && $post->post_status != $args['status'] ) { 1013 restore_current_blog(); 1014 continue; 1015 } elseif ( $post->post_type != POST_TYPE ) { 1016 restore_current_blog(); 1017 continue; 1018 } elseif ( get_post_meta( $post->ID, '_wcbrr_payment_method', true ) != 'Direct Deposit' ) { 1019 restore_current_blog(); 1020 continue; 1021 } 1022 1023 $account_type = get_post_meta( $post->ID, '_wcbrr_ach_account_type', true ); 1024 restore_current_blog(); 1025 break; 1026 } 1027 1028 $entry_class = $account_type == 'Personal' ? 'PPD' : 'CCD'; 1029 echo $entry_class; // Standard Entry Class 1030 1031 echo 'Reimbursem'; // Entry Description 1032 echo date( 'ymd', \WordCamp\Budgets_Dashboard\_next_business_day_timestamp() ); // Company Description Date 1033 echo date( 'ymd', \WordCamp\Budgets_Dashboard\_next_business_day_timestamp() ); // Effective Entry Date 1034 echo str_pad( '', 3 ); // Blanks 1035 echo '1'; // Originator Status Code 1036 echo str_pad( substr( $ach_options['financial-inst'], 0, 8 ), 8 ); // Originating Financial Institution 1037 echo '0000001'; // Batch Number 1038 echo PHP_EOL; 1039 1040 $count = 0; 1041 $total = 0; 1042 $hash = 0; 1043 1044 foreach ( $args['data'] as $entry ) { 1045 switch_to_blog( $entry->blog_id ); 1046 $post = get_post( $entry->request_id ); 1047 1048 if ( $args['status'] && $post->post_status != $args['status'] ) { 1049 restore_current_blog(); 1050 continue; 1051 } elseif ( $post->post_type != POST_TYPE ) { 1052 restore_current_blog(); 1053 continue; 1054 } elseif ( get_post_meta( $post->ID, '_wcbrr_payment_method', true ) != 'Direct Deposit' ) { 1055 restore_current_blog(); 1056 continue; 1057 } 1058 1059 $count++; 1060 1061 // Entry Detail Record 1062 1063 echo '6'; // Record Type Code 1064 1065 $transaction_code = $account_type == 'Personal' ? '27' : '22'; 1066 echo $transaction_code; // Transaction Code 1067 1068 // Transit/Routing Number of Destination Bank + Check digit 1069 $routing_number = get_post_meta( $post->ID, '_wcbrr_ach_routing_number', true ); 1070 $routing_number = \WCP_Encryption::maybe_decrypt( $routing_number ); 1071 $routing_number = substr( $routing_number, 0, 8 + 1 ); 1072 $routing_number = str_pad( $routing_number, 8 + 1 ); 1073 $hash += absint( substr( $routing_number, 0, 8 ) ); 1074 echo $routing_number; 1075 1076 // Bank Account Number 1077 $account_number = get_post_meta( $post->ID, '_wcbrr_ach_account_number', true ); 1078 $account_number = \WCP_Encryption::maybe_decrypt( $account_number ); 1079 $account_number = substr( $account_number, 0, 17 ); 1080 $account_number = str_pad( $account_number, 17 ); 1081 echo $account_number; 1082 1083 // Amount 1084 $amount = 0; 1085 $expenses = get_post_meta( $post->ID, '_wcbrr_expenses', true ); 1086 foreach ( $expenses as $expense ) { 1087 if ( ! empty( $expense['_wcbrr_amount'] ) ) { 1088 $amount += floatval( $expense['_wcbrr_amount'] ); 1089 } 1090 } 1091 1092 $amount = round( $amount, 2 ); 1093 $total += $amount; 1094 $amount = str_pad( number_format( $amount, 2, '', '' ), 10, '0', STR_PAD_LEFT ); 1095 echo $amount; 1096 1097 // Individual Identification Number 1098 echo str_pad( sprintf( '%d-%d', $entry->blog_id, $entry->request_id ), 15 ); 1099 1100 // Individual Name 1101 $name = get_post_meta( $post->ID, '_wcbrr_ach_account_holder_name', true ); 1102 $name = \WCP_Encryption::maybe_decrypt( $name ); 1103 $name = substr( $name, 0, 22 ); 1104 $name = str_pad( $name, 22 ); 1105 echo $name; 1106 1107 echo ' '; // User Defined Data 1108 echo '0'; // Addenda Record Indicator 1109 1110 // Trace Number 1111 echo str_pad( substr( $ach_options['bank-routing-number'], 0, 8 ), 8, '0', STR_PAD_LEFT ); // routing number 1112 echo str_pad( $count, 7, '0', STR_PAD_LEFT ); // sequence number 1113 echo PHP_EOL; 1114 } 1115 1116 // Batch Trailer Record 1117 1118 echo '8'; // Record Type Code 1119 echo '200'; // Service Class Code 1120 echo str_pad( $count, 6, '0', STR_PAD_LEFT ); // Entry/Addenda Count 1121 echo str_pad( substr( $hash, -10 ), 10, '0', STR_PAD_LEFT ); // Entry Hash 1122 echo str_pad( number_format( $total, 2, '', '' ), 12, '0', STR_PAD_LEFT ); // Total Debit Entry Dollar Amount 1123 echo str_pad( 0, 12, '0', STR_PAD_LEFT ); // Total Credit Entry Dollar Amount 1124 echo str_pad( substr( $ach_options['company-id'], 0, 10 ), 10 ); // Company ID 1125 echo str_pad( '', 25 ); // Blanks 1126 echo str_pad( substr( $ach_options['financial-inst'], 0, 8 ), 8 ); // Originating Financial Institution 1127 echo '0000001'; // Batch Number 1128 echo PHP_EOL; 1129 1130 1131 // File Trailer Record 1132 1133 echo '9'; // Record Type Code 1134 echo '000001'; // Batch Count 1135 echo str_pad( ceil( $count / 10 ), 6, '0', STR_PAD_LEFT ); // Block Count 1136 echo str_pad( $count, 8, '0', STR_PAD_LEFT ); // Entry/Addenda Count 1137 echo str_pad( substr( $hash, -10 ), 10, '0', STR_PAD_LEFT ); // Entry Hash 1138 echo str_pad( number_format( $total, 2, '', '' ), 12, '0', STR_PAD_LEFT ); // Total Debit Entry Dollar Amount 1139 echo str_pad( 0, 12, '0', STR_PAD_LEFT ); // Total Credit Entry Dollar Amount 1140 echo str_pad( '', 39 ); // Blanks 1141 echo PHP_EOL; 1142 1143 // The file must have a number of lines that is a multiple of 10 (e.g. 10, 20, 30). 1144 echo str_repeat( PHP_EOL, 10 - ( ( 4 + $count ) % 10 ) - 1 ); 1145 return ob_get_clean(); 1146 }
Note: See TracChangeset
for help on using the changeset viewer.