30 function TxnSchedRead($pEnv, $pDbh, $pMC) {
31 $retStatusAry = Array(
32 'status' => Array(
'code'=>
'000',
'errors' => Array()),
42 feature_code AS tx_feature, 43 start_date AS tx_start, 45 next_trigger_date AS tx_next, 46 interval_count AS tx_interval_count, 48 approved_status AS tx_approved, 49 repeating_parameters AS tx_parameters, 54 WHERE cu = '{$pEnv['Cu']}' 55 AND user_id = '{$pEnv['Uid']}'";
56 $sqlSelectRs = db_query($sqlSelect, $pDbh);
58 $retStatusAry[
'status'][
'code'] =
"999";
59 $retStatusAry[
'status'][
'severity'] =
"ERROR";
60 $retStatusAry[
'status'][
'errors'][] = $pMC->msg(
"Transfers Unavailable", HCU_DISPLAY_AS_RAW);
64 $sqlResult = db_fetch_all($sqlSelectRs);
66 if ($sqlResult !=
null) {
67 foreach ($sqlResult as $key => $value) {
70 $txData = HCU_JsonDecode($value[
'tx_data']);
71 $txParam = HCU_JsonDecode($value[
'tx_parameters']);
72 $txAmount = $txData[
'txn'][
'amount'];
73 $txMemo = $txData[
'txn'][
'memo'];
80 if ( trim($value[
'tx_feature']) ==
"ACHCOL" ) {
81 $txFromDesc = _GetACHPartnerDisplay( $pEnv, $txData[
'txn'][
'from'] );
82 $txFromSuffix =
"AC|{$pEnv['Uid']}|{$txData['txn']['from']}";
84 $acctParts = explode(
"|", $txData[
'txn'][
'to'] );
85 $certNumber = isset( $acctParts[3] ) && $acctParts[3] > 0 ? $acctParts[3] : 0;
86 $txToDesc = FindAccountDisplay( $pEnv, $pDbh, $pEnv[
'Cu'], $acctParts[1], $acctParts[2], $acctParts[0], $certNumber);
87 $txToSuffix = $txData[
'txn'][
'to'];
89 }
else if ( trim($value[
'tx_feature']) ==
"ACHPMT" ) {
90 $txToDesc = _GetACHPartnerDisplay( $pEnv, $txData[
'txn'][
'to'] );
91 $txToSuffix =
"AP|{$pEnv['Uid']}|{$txData['txn']['to']}";
93 $acctParts = explode(
"|", $txData[
'txn'][
'from'] );
94 $certNumber = isset( $acctParts[3] ) && $acctParts[3] > 0 ? $acctParts[3] : 0;
95 $txFromDesc = FindAccountDisplay( $pEnv, $pDbh, $pEnv[
'Cu'], $acctParts[1], $acctParts[2], $acctParts[0], $certNumber);
96 $txFromSuffix = $txData[
'txn'][
'from'];
97 }
else if ( trim($value[
'tx_feature']) ==
"TRNEXT" ) {
99 if ( $txData[
"txn"][
"type"] ==
"X2L" ) {
101 $txFromDesc = _GetExtPartnerDisplay( $pEnv, $txData[
'txn'][
'from'] );
102 $txFromSuffix =
"X|{$pEnv['Uid']}|{$txData['txn']['from']}";
104 $acctParts = explode(
"|", $txData[
'txn'][
'to'] );
105 $certNumber = isset( $acctParts[3] ) && $acctParts[3] > 0 ? $acctParts[3] : 0;
106 $txToDesc = FindAccountDisplay( $pEnv, $pDbh, $pEnv[
'Cu'], $txData[
'txn'][
'tomember'], $txData[
'txn'][
'tosuffix'], $txData[
'txn'][
'totype'], $certNumber);
107 $txToSuffix = $txData[
'txn'][
'to'];
109 $txToDesc = _GetExtPartnerDisplay( $pEnv, $txData[
'txn'][
'to'] );
110 $txToSuffix =
"X|{$pEnv['Uid']}|{$txData['txn']['to']}";
112 $acctParts = explode(
"|", $txData[
'txn'][
'from'] );
113 $certNumber = isset( $acctParts[3] ) && $acctParts[3] > 0 ? $acctParts[3] : 0;
114 $txFromDesc = FindAccountDisplay( $pEnv, $pDbh, $pEnv[
'Cu'], $txData[
'txn'][
'frommember'], $txData[
'txn'][
'fromsuffix'], $txData[
'txn'][
'fromtype'], $certNumber);
115 $txFromSuffix = $txData[
'txn'][
'from'];
117 }
else if ( trim($value[
'tx_feature']) ==
"TRNM2M" ) {
119 $txToDesc = _GetExtPartnerDisplay( $pEnv, $txData[
'txn'][
'to'] );
120 $txToSuffix =
"M|{$pEnv['Uid']}|{$txData['txn']['to']}";
122 $acctParts = explode(
"|", $txData[
'txn'][
'from'] );
123 $certNumber = isset( $acctParts[3] ) && $acctParts[3] > 0 ? $acctParts[3] : 0;
124 $txFromDesc = FindAccountDisplay( $pEnv, $pDbh, $pEnv[
'Cu'], $txData[
'txn'][
'frommember'], $txData[
'txn'][
'fromsuffix'], $txData[
'txn'][
'fromtype'], $certNumber);
125 $txFromSuffix = $txData[
'txn'][
'from'];
129 $acctPartsTo = explode(
"|", $txData[
'txn'][
'to'] );
130 $acctPartsFrom = explode(
"|", $txData[
'txn'][
'from'] );
132 $txFromDesc = FindAccountDisplay($pEnv, $pDbh, $pEnv[
'Cu'], $txData[
'txn'][
'frommember'], $txData[
'txn'][
'fromsuffix'], $txData[
'txn'][
'fromtype'], isset($acctPartsFrom[3]) ? $acctPartsFrom[3] : 0);
133 $txFromSuffix = $txData[
'txn'][
'from'];
139 if (in_array($txData[
'txn'][
'transactioncode'], array(
"XA",
"XP"))) {
146 $localToMbr = $txData[
'txn'][
'frommember'];
147 $localToSfx = $txData[
'txn'][
'tosuffix'] .
'#' . $txData[
'txn'][
'tomember'];
150 $localToMbr = $txData[
'txn'][
'tomember'];
151 $localToSfx = $txData[
'txn'][
'tosuffix'];
152 $localToCert = (isset($acctPartsTo[3]) ? $acctPartsTo[3] : 0);
155 $txToDesc = FindAccountDisplay($pEnv, $pDbh, $pEnv[
'Cu'], $localToMbr, $localToSfx, $txData[
'txn'][
'totype'], $localToCert);
156 $txToSuffix = $txData[
'txn'][
'to'];
160 $feature = trim( $value[
'tx_feature'] );
161 if ( $feature ==
"TRN" ) {
162 $featureName = $pMC->msg(
"Transfer", HCU_DISPLAY_AS_RAW);
163 }
else if ( $feature ==
"TRNEXT" ) {
164 $featureName = $pMC->msg(
"External Transfer", HCU_DISPLAY_AS_RAW);
165 }
else if ( $feature ==
"TRNM2M" ) {
166 $featureName = $pMC->msg(
"M2M Transfer", HCU_DISPLAY_AS_RAW);
167 }
else if ( $feature ==
"ACHPMT" ) {
168 $featureName = $pMC->msg(
"ACH Payment", HCU_DISPLAY_AS_RAW);
169 }
else if ( $feature ==
"ACHCOL" ) {
170 $featureName = $pMC->msg(
"ACH Collection", HCU_DISPLAY_AS_RAW);
172 $featureName = $pMC->msg(
"Unknown", HCU_DISPLAY_AS_RAW);
177 "txId" => intval($value[
'tx_id']),
178 "txFeature" => $featureName,
179 "txFromDesc" => trim($txFromDesc),
180 "txFromSuffix" => trim($txFromSuffix),
181 "txToDesc" => trim($txToDesc),
182 "txToSuffix" => trim($txToSuffix),
183 "txAmount" => floatval($txAmount),
184 "txMemo" => trim($txMemo),
185 "txStatus" => trim($value[
'tx_status']),
186 "txApproved" => intval($value[
'tx_approved']),
187 "txFrequency" => trim($txParam[
'interval']),
188 "txFrequencyCount" => intval($value[
'tx_interval_count']),
189 "txDateStart" => trim($value[
'tx_start']),
190 "txDateEnd" => trim($value[
'tx_end']),
191 "txDateNext" => trim($value[
'tx_next']),
192 "txContinue" => ($value[
'tx_end'] ==
null || ($value[
'tx_end'] == $value[
'tx_start'])) ?
199 $retStatusAry[
'status'][
'code'] =
"000";
200 $retStatusAry[
'status'][
'severity'] =
"SUCCESS";
201 $retStatusAry[
'data'] = $sqlData;
204 return $retStatusAry;
219 function TxnSchedCreate($pEnv, $pDbh, $pMC, $pValues) {
220 $retStatusAry = Array(
221 'status' => Array(
'code'=>
'000',
'errors' => Array()),
230 $confirmInputs = array(
"feature" => $pValues[
'txFeature']);
231 $confirmRequired = Perm_CheckConfirmReq($pDbh, $pEnv, $confirmInputs);
237 $featureCode = $pValues[
'txFeature'];
238 $cu = prep_save($pEnv[
'Cu'], 10);
239 $userID = intval($pEnv[
'Uid']);
252 $created =
"CURRENT_TIMESTAMP";
255 $trigger = TxNextInterval(
256 $pValues[
'txDateStart'],
257 $pValues[
'txFrequency'],
258 $pValues[
'txFrequencyCount']);
259 $trigger = $trigger ?
"'" . $trigger .
"'" :
"NULL";
265 if ( $pValues[
'txFrequency'] ==
"OneTime" ) {
266 $end =
"'{$pValues['txDateStart']}'";
268 $end = $pValues[
'txDateEnd'] ==
"" ?
"NULL" :
"'{$pValues['txDateEnd']}'";
272 $approvedDate = $confirmRequired ?
"NULL" :
"CURRENT_TIMESTAMP" ;
273 $approvedBy = $confirmRequired ?
"NULL" : $userID ;
274 $approvedStatus = $confirmRequired ? 0 : 10;
277 $editedDate = $created;
282 $intervalFailure = 0;
289 $parameters =
"'{$pValues['txParameters']}'";
291 $data =
"'{$pValues['txData']}'";
309 repeating_parameters, 330 $sqlCreate =
"INSERT INTO cu_scheduledtxn 332 VALUES ($sqlValues)";
333 $sqlCreateRs = db_query($sqlCreate, $pDbh);
335 $retStatusAry[
'status'][
'code'] =
"999";
336 $retStatusAry[
'status'][
'severity'] =
"ERROR";
337 $retStatusAry[
'status'][
'errors'][] = $pMC->msg(
"Transfer Save Error", HCU_DISPLAY_AS_RAW);
340 return $retStatusAry;
354 function TxnSchedUpdate($pEnv, $pDbh, $pMC, $pValues) {
355 $retStatusAry = Array(
356 'status' => Array(
'code'=>
'000',
'errors' => Array()),
365 $confirmInputs = array(
"feature" => $pValues[
'txFeature']);
366 $confirmRequired = Perm_CheckConfirmReq($pDbh, $pEnv, $confirmInputs);
376 $id = $pValues[
'txId'];
377 $cu = prep_save($pEnv[
'Cu'], 10);
380 $start = $pValues[
'txDateStart'] ==
"" ?
"NULL" :
"'{$pValues['txDateStart']}'";
381 if ( $pValues[
'txFrequency'] ==
"OneTime" ) {
382 $end =
"'{$pValues['txDateStart']}'";
384 $end = $pValues[
'txDateEnd'] ==
"" ?
"NULL" :
"'{$pValues['txDateEnd']}'";
388 $trigger = TxNextInterval(
389 $pValues[
'txDateStart'],
390 $pValues[
'txFrequency'],
391 $pValues[
'txFrequencyCount']);
392 $trigger = $trigger ?
"'" . $trigger .
"'" :
"NULL";
395 $intervalCount = intval($pValues[
'txFrequencyCount']);
398 $approvedDate = $confirmRequired ?
"NULL" :
"CURRENT_TIMESTAMP" ;
399 $approvedBy = $confirmRequired ?
"NULL" : intval($pEnv[
'Uid']) ;
402 $editedBy = intval($pEnv[
'Uid']);
403 $editedDate =
"CURRENT_TIMESTAMP";
406 $status =
"'{$pValues['txStatus']}'";
409 $parameters =
"'{$pValues['txParameters']}'";
411 $data =
"'{$pValues['txData']}'";
424 repeating_parameters, 439 UPDATE cu_scheduledtxn 440 SET ($sqlColumns) = ($sqlValues) 443 $sqlUpdateRs = db_query($sqlUpdate, $pDbh);
445 $retStatusAry[
'status'][
'code'] =
"999";
446 $retStatusAry[
'status'][
'severity'] =
"ERROR";
447 $retStatusAry[
'status'][
'errors'][] = $pMC->msg(
"Transfer Save Error", HCU_DISPLAY_AS_RAW);
450 return $retStatusAry;
464 function TxnSchedDelete($pEnv, $pDbh, $pMC, $pValues) {
465 $retStatusAry = Array(
466 'status' => Array(
'code'=>
'000',
'errors' => Array()),
473 $id = $pValues[
'txId'];
474 $cu = prep_save($pEnv[
'Cu'], 10);
478 DELETE FROM cu_scheduledtxn 481 $sqlDeleteRs = db_query($sqlDelete, $pDbh);
483 $retStatusAry[
'status'][
'code'] =
"999";
484 $retStatusAry[
'status'][
'severity'] =
"ERROR";
485 $retStatusAry[
'status'][
'errors'][] = $pMC->msg(
"Transfer Delete Fail", HCU_DISPLAY_AS_RAW);
488 return $retStatusAry;
500 function TxnSchedParameters($pValues) {
502 "interval" => $pValues[
'txFrequency']
504 $paramSTRING = HCU_JsonEncode($paramJSON);
518 function TxnSchedData( $pValues ) {
520 if ( $pValues[
"txFromType"] ==
'X' || $pValues[
"txToType"] ==
'X' ||
521 $pValues[
"txToType"] ==
'M' ) {
523 if ( $pValues[
"txFromType"] ==
'X' ) {
525 $fromParts = explode(
"|", $pValues[
"txFromAcctId"] );
526 $from = $fromParts[2];
529 $fromtype = $pValues[
"txMemType"];
530 $to = $pValues[
'txToAcctId'];
531 $tomember = $pValues[
'txToMember'];
532 $tosuffix = $pValues[
'txToSuffix'];
536 $from = $pValues[
'txFromAcctId'];
537 $frommember = $pValues[
'txFromMember'];
538 $fromsuffix = $pValues[
'txFromSuffix'];
539 $fromtype = $pValues[
'txFromType'];
540 $toParts = explode(
"|", $pValues[
"txToAcctId"] );
544 $type = $pValues[
"txToType"] ==
'M' ?
"L2M" :
"L2X";
550 "frommember" => $frommember,
551 "fromsuffix" => $fromsuffix,
552 "fromtype" => $fromtype,
554 "tomember" => $tomember,
555 "tosuffix" => $tosuffix,
556 "totype" => $pValues[
'txToType'],
557 "amount" => $pValues[
'txAmount'],
558 "transactioncode" => $pValues[
'txCode'],
559 "include_memo" =>
"",
560 "memo" => prep_save($pValues[
'txMemo']),
567 $tomember = $pValues[
'txToMember'];
568 if ($pValues[
"txTrust"] ==
"transfer") {
569 $toParts = explode(
"|", $pValues[
"txToAcctId"] );
570 $tomember = $toParts[1];
576 "from" => $pValues[
'txFromAcctId'],
577 "frommember" => $pValues[
'txFromMember'],
578 "fromsuffix" => $pValues[
'txFromSuffix'],
579 "fromtype" => $pValues[
'txFromType'],
580 "to" => $pValues[
'txToAcctId'],
581 "tomember" => $tomember,
582 "tosuffix" => $pValues[
'txToSuffix'],
583 "totype" => $pValues[
'txToType'],
584 "amount" => $pValues[
'txAmount'],
585 "transactioncode" => $pValues[
'txCode'],
586 "deposittype" => $pValues[
'txFromType'],
587 "memo" => prep_save($pValues[
'txMemo'])
593 $dataSTRING = HCU_JsonEncode($dataJSON);
607 function TxnSchedDataACH( $pValues ) {
611 "amount" => $pValues[
'txAmount'],
612 "transactioncode" => $pValues[
'txCode'],
613 "include_memo" =>
"",
614 "memo" => prep_save($pValues[
'txMemo']),
615 "addenda" => $pValues[
'txAddenda'],
616 "type" => $pValues[
'txType']
620 $acctId = explode(
"|", $pValues[
'txLocalAccount']);
621 if ($pValues[
'txType'] ==
"L2R") {
622 $dataJSON[
'txn'][
'from'] = $pValues[
'txLocalAccount'];
623 $dataJSON[
'txn'][
'frommember'] = $pValues[
'txLocalMember'];
624 $dataJSON[
'txn'][
'fromsuffix'] = $acctId[2];
625 $dataJSON[
'txn'][
'fromtype'] = $acctId[0];
626 $dataJSON[
'txn'][
'to'] = $pValues[
'txPartnerId'];
628 $dataJSON[
'txn'][
'to'] = $pValues[
'txLocalAccount'];
629 $dataJSON[
'txn'][
'tomember'] = $pValues[
'txLocalMember'];
630 $dataJSON[
'txn'][
'tosuffix'] = $acctId[2];
631 $dataJSON[
'txn'][
'totype'] = $acctId[0];
632 $dataJSON[
'txn'][
'from'] = $pValues[
'txPartnerId'];
635 $dataSTRING = HCU_JsonEncode($dataJSON);
647 function TxIntervalList($MC) {
649 Array(
"value" =>
"OneTime",
"text" => str_replace(
"#",
"\\#", $MC->msg(
"TRNSCHED OneTime"))),
650 Array(
"value" =>
"FirstDayOfMonth",
"text" => str_replace(
"#",
"\\#", $MC->msg(
"TRNSCHED FirstDayOfMonth"))),
651 Array(
"value" =>
"LastDayOfMonth",
"text" => str_replace(
"#",
"\\#", $MC->msg(
"TRNSCHED LastDayOfMonth"))),
652 Array(
"value" =>
"FirstFifteenth",
"text" => str_replace(
"#",
"\\#", $MC->msg(
"TRNSCHED FirstFifteenth"))),
653 Array(
"value" =>
"FifteenthLast",
"text" => str_replace(
"#",
"\\#", $MC->msg(
"TRNSCHED FifteenthLast"))),
654 Array(
"value" =>
"Weekly",
"text" => str_replace(
"#",
"\\#", $MC->msg(
"TRNSCHED Weekly"))),
655 Array(
"value" =>
"BiWeekly",
"text" => str_replace(
"#",
"\\#", $MC->msg(
"TRNSCHED BiWeekly"))),
656 Array(
"value" =>
"WeekDayOfMonth",
"text" => str_replace(
"#",
"\\#", $MC->msg(
"TRNSCHED WeekDayOfMonth"))),
657 Array(
"value" =>
"Monthly",
"text" => str_replace(
"#",
"\\#", $MC->msg(
"TRNSCHED Monthly"))),
658 Array(
"value" =>
"Every2Months",
"text" => str_replace(
"#",
"\\#", $MC->msg(
"TRNSCHED Every2Months"))),
659 Array(
"value" =>
"Quarterly",
"text" => str_replace(
"#",
"\\#", $MC->msg(
"TRNSCHED Quarterly"))),
660 Array(
"value" =>
"SemiAnnually",
"text" => str_replace(
"#",
"\\#", $MC->msg(
"TRNSCHED SemiAnnually"))),
661 Array(
"value" =>
"Annually",
"text" => str_replace(
"#",
"\\#", $MC->msg(
"TRNSCHED Annually")))
672 function TxContinueList($MC) {
674 Array(
"value" =>
"continuous",
"text" => $MC->msg(
'Transfer Continue Until', HCU_DISPLAY_AS_RAW) .
' ' .$MC->msg(
'Transfer Further Notice', HCU_DISPLAY_AS_RAW)),
675 Array(
"value" =>
"continueuntil",
"text" => $MC->msg(
'Transfer Continue Until', HCU_DISPLAY_AS_RAW))
689 function TxNextInterval($pStart, $pInterval, $pIntervalCount) {
692 $dateStart = strtotime($pStart);
695 $cDay = date(
"j", $dateStart);
696 $cMonth = date(
"m", $dateStart);
697 $cYear = date(
"Y", $dateStart);
698 $cInterval = intval($pIntervalCount);
701 switch ($pInterval) {
705 $dateTrigger = date(
"m/d/Y", $dateStart + (($cInterval > 0 ? 1 : 0) * 86400));
707 case "FirstDayOfMonth":
715 $cMonth = ($cDay > 1) ? $cMonth + 1 : $cMonth;
716 $cMonth = $cMonth + $cInterval;
718 $nextFirst = mktime(0,0,0, $cMonth, 1, $cYear);
719 $nextFirst = date(
"m/d/Y", $nextFirst);
720 $dateTrigger = $nextFirst;
722 case "LastDayOfMonth":
726 $cMonth = $cMonth + $cInterval;
728 $nextLast = mktime(0,0,0, $cMonth, 1, $cYear);
729 $nextLast = date(
"m/t/Y", $nextLast);
730 $dateTrigger = $nextLast;
732 case "FirstFifteenth":
752 $startDay = ($cDay > 15 || $cDay == 1) ? 1 : 15;
753 $startMonth = $cMonth + ($cDay > 15);
755 while ($cInterval > 0) {
756 if ($startDay == 1) {
761 if ($startMonth > 12) {
770 $nextDate = mktime(0,0,0, $startMonth, $startDay, $cYear);
771 $dateTrigger = date(
"m/d/Y", $nextDate);
774 case "FifteenthLast":
793 $startDay = ($cDay <= 15) ? 15 : date(
"t", $dateStart);
794 $startMonth = $cMonth;
796 while ($cInterval > 0) {
797 if ($startDay == 15) {
798 $startDay = strtotime($startMonth .
"/1/" . $cYear);
799 $startDay = date(
"t", $startDay);
803 if ($startMonth > 12) {
812 $nextDate = mktime(0,0,0, $startMonth, $startDay, $cYear);
813 $dateTrigger = date(
"m/d/Y", $nextDate);
818 $cDay = $cDay + (7 * $cInterval);
820 $nextWeek = mktime(0,0,0, $cMonth, $cDay, $cYear);
821 $nextWeek = date(
"m/d/Y", $nextWeek);
822 $dateTrigger = $nextWeek;
826 $cDay = $cDay + (14 * $cInterval);
828 $nextBiWeek = mktime(0,0,0, $cMonth, $cDay, $cYear);
829 $nextBiWeek = date(
"m/d/Y", $nextBiWeek);
830 $dateTrigger = $nextBiWeek;
832 case "WeekDayOfMonth":
835 $weekDay = date(
"l", $dateStart);
836 $week = ceil($cDay / 7);
841 $weekNumber =
"first";
844 $weekNumber =
"second";
847 $weekNumber =
"third";
850 $weekNumber =
"fourth";
853 $weekNumber =
"last";
857 $monthStart = mktime(0,0,0, $cMonth + $cInterval, 1, $cYear);
858 $monthName = date(
"M", $monthStart);
859 $monthYear = date(
"Y", $monthStart);
862 $nextDayOfMonth =
"";
863 $nextDayOfMonth .= $weekNumber .
" ";
864 $nextDayOfMonth .= $weekDay .
" of ";
865 $nextDayOfMonth .= $monthName .
" ";
866 $nextDayOfMonth .= $monthYear;
868 $nextDay = strtotime($nextDayOfMonth);
869 $dateTrigger = date(
"m/d/Y", $nextDay);
873 $cMonth = $cMonth + $cInterval;
875 $nextMonth = mktime(0,0,0, $cMonth, 1, $cYear);
876 $nextMonthDays = date(
"t", $nextMonth);
878 if ($cDay > $nextMonthDays) {
879 $nextDay = $nextMonthDays;
884 $nextDayOfMonth = mktime(0,0,0, $cMonth, $nextDay, $cYear);
885 $nextDayOfMonth = date(
"m/d/Y", $nextDayOfMonth);
886 $dateTrigger = $nextDayOfMonth;
889 $cMonth = $cMonth + (2 * $cInterval);
890 while ($cMonth > 12) {
891 $cMonth = $cMonth - 12;
895 $nextTwoMonth = mktime(0,0,0, $cMonth, 1, $cYear);
896 $nextTwoMonthDays = date(
"t", $nextTwoMonth);
898 if ($cDay > $nextTwoMonthDays) {
899 $nextDay = $nextTwoMonthDays;
904 $nextTwo = mktime(0,0,0, $cMonth, $nextDay, $cYear);
905 $nextTwo = date(
"m/d/Y", $nextTwo);
906 $dateTrigger = $nextTwo;
909 $cMonth = $cMonth + (3 * $cInterval);
910 while ($cMonth > 12) {
911 $cMonth = $cMonth - 12;
915 $nextThreeMonth = mktime(0,0,0, $cMonth, 1, $cYear);
916 $nextThreeMonthDays = date(
"t", $nextThreeMonth);
918 if ($cDay > $nextThreeMonthDays) {
919 $nextDay = $nextThreeMonthDays;
924 $nextQuarter = mktime(0,0,0, $cMonth, $nextDay, $cYear);
925 $nextQuarter = date(
"m/d/Y", $nextQuarter);
926 $dateTrigger = $nextQuarter;
929 $cMonth = $cMonth + (6 * $cInterval);
930 while ($cMonth > 12) {
931 $cMonth = $cMonth - 12;
935 $nextSixMonth = mktime(0,0,0, $cMonth, 1, $cYear);
936 $nextSixMonthDays = date(
"t", $nextSixMonth);
938 if ($cDay > $nextSixMonthDays) {
939 $nextDay = $nextSixMonthDays;
944 $nextSemi = mktime(0,0,0, $cMonth, $nextDay, $cYear);
945 $nextSemi = date(
"m/d/Y", $nextSemi);
946 $dateTrigger = $nextSemi;
950 $cYear = $cYear + $cInterval;
952 $nextAnnual = mktime(0,0,0, $cMonth, 1, $cYear);
953 $nextAnnualDays = date(
"t", $nextAnnual);
955 if ($cDay > $nextAnnualDays) {
956 $nextDay = $nextAnnualDays;
961 $nextAnnual = mktime(0,0,0, $cMonth, $nextDay, $cYear);
962 $nextAnnual = date(
"m/d/Y", $nextAnnual);
963 $dateTrigger = $nextAnnual;
973 function _GetACHPartnerDisplay( $pEnv, $pPartnerId ) {
976 $sql =
"SELECT ap.display_name 977 FROM {$Cu}achpartner ap 978 WHERE ap.id = $pPartnerId";
980 $rs = db_query( $sql, $pEnv[
"dbh"] );
981 $row = db_fetch_assoc( $rs );
982 $name =
"ACH: {$row["display_name
"]}";
988 function _GetExtPartnerDisplay( $pEnv, $pPartnerId ) {
991 $sql =
"SELECT ea.display_name, type 992 FROM {$Cu}extaccount ea 993 WHERE ea.id = $pPartnerId";
995 $rs = db_query( $sql, $pEnv[
"dbh"] );
996 $row = db_fetch_assoc( $rs );
997 $name =
"{$row["type
"]}: {$row["display_name
"]}";
1002 function FindTransactionData($pDbh, $pId) {
1004 SELECT txn_data, feature_code, start_date, repeating_parameters 1005 FROM cu_scheduledtxn 1007 $sqlSelectRs = db_query($sqlSelect, $pDbh);
1008 $sqlTxn = db_fetch_assoc($sqlSelectRs, 0);
1028 function GetCalendarData($pHBEnv, $pMC, $pSchedules, $pStart, $pEnd) {
1038 $sdDateStart = $pStart;
1039 $sdTimeStart = strtotime($pStart);
1041 $sdTimeEnd = strtotime($pEnd);
1052 $scheduleDates = array();
1053 $scheduleOccur = array();
1054 $scheduleValid = array();
1055 $scheduleReturn = array();
1058 foreach ($pSchedules as $key => $value) {
1059 $txStatus = $value[
'txStatus'];
1060 $txApproved = $value[
'txApproved'];
1061 $txInterval = $value[
'txFrequency'];
1062 $txIntervalCount = $value[
'txFrequencyCount'];
1067 $txTimeNext = strtotime($value[
'txDateNext']);
1068 $txDateNext = date(
"m/d/Y", $txTimeNext);
1075 if ($value[
'txDateEnd'] !=
"") {
1076 $txTimeEnd = strtotime($value[
'txDateEnd']);
1077 $txDateEnd = date(
"m/d/Y", $txTimeEnd);
1080 $txDateEnd = $sdDateEnd;
1081 $txTimeEnd = $sdTimeEnd;
1085 if ($txStatus ==
"A" && ($txApproved == 10 || $txApproved == 0)) {
1090 if ($txTimeNext >= $sdTimeStart) {
1099 while ($txDateNext !=
null) {
1100 $scheduleDates[] = returnJsonDateValue($txDateNext);
1101 $scheduleOccur[$txDateNext][] = $value[
'txId'];
1102 $txDateNext = TxNextInterval($txDateNext, $txInterval, $txIntervalCount);
1105 if ($txInterval ==
"OneTime") {
1111 if (strtotime($txDateNext) < $txTimeEnd) {
1118 $scheduleValid[] = $value;
1121 $scheduleReturn[
'valid'] = $scheduleValid;
1122 $scheduleReturn[
'dates'] = $scheduleDates;
1123 $scheduleReturn[
'occur'] = $scheduleOccur;
1124 return $scheduleReturn;
1142 function SkipTrans($dbh, $Cu, $userId, $changeList, $MC) {
1144 if ($changeList ==
"") {
1145 throw new exception(
"Nothing to skip.", 201);
1147 $changeList = HCU_JsonDecode($changeList);
1148 if (!is_array($changeList)) {
1149 throw new exception(
"Change List is malformed.", 202);
1151 if (count($changeList) == 0) {
1152 throw new exception(
"Nothing to skip.", 207);
1154 foreach($changeList as $changeListId) {
1155 if (!is_integer($changeListId)) {
1156 throw new exception(
"Change List is malformed.", 203);
1161 $sql =
"select id, approved_status, repeating_parameters::json->>'interval' as interval, interval_count, status, next_trigger_date, end_date, start_date from cu_scheduledtxn 1162 where cu = '$Cu' and user_id = $userId and id in (" . implode(
", ", $changeList) .
")";
1163 $sth = db_query($sql, $dbh);
1165 throw new exception(
"Select query failed.", 209);
1167 $updateList = array();
1168 for($i = 0; $row = db_fetch_assoc($sth, $i); $i++) {
1169 if ($row[
"status"] !=
"A") {
1170 throw new exception(
"Skips can only happen on active records.", 204);
1172 if ($row[
"approved_status"] != 10) {
1173 throw new exception(
"Skips can only happen on approved records.", 205);
1177 if (!isset($row[
"next_trigger_date"])) {
1178 throw new exception(
"Skips cannot happen on records with a null next trigger date.", 209);
1181 $nextInterval = TxNextInterval($row[
"start_date"], $row[
"interval"], $row[
"interval_count"] + 1);
1183 if (isset($nextInterval)) {
1184 $nextInterval = explode(
"/", $nextInterval);
1185 $nextInterval =
"'" . $nextInterval[2] .
"-" . $nextInterval[0] .
"-" . $nextInterval[1] .
"'";
1187 $nextInterval =
"null";
1190 if ($nextInterval !=
"null" && isset($row[
"end_date"]) && $nextInterval >
"'" . $row[
"end_date"] .
"'") {
1191 $nextInterval =
"null";
1193 $updateList[$id] =
"($id, $nextInterval)";
1195 if (count($updateList) != count($changeList)) {
1196 throw new exception(
"Some ids in the changeList are invalid.", 206);
1200 $sql =
"update cu_scheduledtxn set next_trigger_date = b.next_trigger_date::date, interval_count = interval_count + 1 1201 from (values " . implode(
", ", $updateList) .
") as b (id, next_trigger_date) where cu_scheduledtxn.id = b.id";
1202 $sth = db_query($sql, $dbh);
1204 throw new exception(
"Update query failed.", 208);
1207 $readResults = ReadTrans($dbh, $Cu, $userId, $MC);
1209 if ($readResults[
"status"] !=
"000") {
1210 throw new exception($readResults[
"error"][0], $readResults[
"code"]);
1212 $repeatingTransfers = $readResults[
"repeatingTransfers"];
1213 unset($readResults);
1215 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"repeatingTransfers" => $repeatingTransfers,
1216 "info" => (count($updateList) == 1 ?
"Transfer was " :
"Transfers were ") .
"skipped successfully.");
1217 }
catch(exception $e) {
1218 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
1220 return $returnArray;
1236 function ReadTrans($dbh, $Cu, $userId, $MC) {
1238 $intervalList = TxIntervalList($MC);
1239 $intervalLookup = array();
1240 foreach($intervalList as $intervalRecord) {
1241 $intervalLookup[$intervalRecord[
"value"]] = $intervalRecord[
"text"];
1243 unset($intervalList);
1246 $subqueryTXN =
"select ss.id, ss.feature_code, ss.feature, ss.create_date, ss.start_date, ss.end_date, ss.next_trigger_date, ss.status, ss.repeating_parameters, 1247 ss.txn_data, ss.failure_count, case when strpos(ss.fromkey, '|') = 0 then cast(ss.fromkey as text) 1248 when coalesce(strpos(ss.fromsuffix, '@'), '0') <> 0 then trim(split_part(fromkey, '|', 1)) || trim(ss.frommember) 1249 || trim(ss.fromsuffix) || coalesce(nullif(split_part(fromkey, '|', 4), ''), '0') 1250 else trim(split_part(fromkey, '|', 1)) || trim(split_part(fromkey, '|', 2)) || trim(split_part(fromkey, '|', 3)) || coalesce(nullif(split_part(fromkey, '|', 4), ''), '0') end 1252 case when strpos(ss.tokey, '|') = 0 then cast(ss.tokey as text) 1253 when coalesce(strpos(ss.tosuffix, '@'), 0) <> 0 then trim(split_part(tokey, '|', 1)) || trim(ss.tomember) || trim(ss.tosuffix) || coalesce(nullif(split_part(tokey, '|', 4), ''), '0') 1254 when ss.code not in ('XA', 'XP') then trim(split_part(tokey, '|', 1)) || trim(split_part(tokey, '|', 2)) || trim(split_part(tokey, '|', 3)) || 1255 coalesce(nullif(split_part(tokey, '|', 4), ''), '0') 1256 else case when trim(split_part(tokey, '|', 1)) = 'D' then 'T' else 'P' end || frommember || trim(split_part(tokey, '|', 3)) || '#' || trim(split_part(tokey, '|', 2)) 1257 || coalesce(nullif(split_part(tokey, '|', 4), ''), '0') end as tokey 1259 select s.id, s.feature_code, f.description as feature, s.create_date, s.start_date, s.end_date, s.next_trigger_date, s.status, s.repeating_parameters, s.txn_data, 1261 replace(s.txn_data::json->'txn'->>'from', 'C|', 'L|') as fromkey, 1262 replace(s.txn_data::json->'txn'->>'to', 'C|', 'L|') as tokey, 1263 s.txn_data::json->'txn'->>'transactioncode' as code, 1264 s.txn_data::json->'txn'->>'frommember' as frommember, s.txn_data::json->'txn'->>'fromsuffix' as fromsuffix, s.txn_data::json->'txn'->>'tomember' as tomember, 1265 s.txn_data::json->'txn'->>'tosuffix' as tosuffix 1266 from cu_scheduledtxn s 1267 inner join cu_feature f on s.feature_code = f.feature_code and s.cu = '$Cu' and f.enabled and approved_status = 10 1268 where s.user_id = $userId 1271 $subqueryALXB =
"select 'D' || trim(accountnumber) || trim(accounttype) || certnumber as key, may_deposit, may_withdraw, 1272 accountnumber, accounttype, certnumber, description 1273 from ${Cu}accountbalance 1275 select 'T' || trim(accountnumber) || trim(accounttype) || '#' || trim(tomember) || '0' as key, true, false, tomember, accounttype, 0, description 1276 from ${Cu}crossaccounts where deposittype not in ('L', 'C') 1278 select 'L' || trim(accountnumber) || trim(loannumber) || '0' as key, may_payment, may_addon, accountnumber, loannumber, 0, description 1279 from ${Cu}loanbalance 1281 select 'P' || trim(accountnumber) || trim(accounttype) || '#' || trim(tomember) || '0' as key, false, false, tomember, accounttype, 0, description 1282 from ${Cu}crossaccounts where deposittype in ('L', 'C')";
1284 $sql =
"select txn.*, alxbfrom.description as from_desc, alxbfrom.accountnumber as from_acct, alxbfrom.accounttype as from_accounttype, 1285 alxbfrom.certnumber as from_certnumber, alxbto.description as to_desc, alxbto.accountnumber as to_acct, 1286 alxbto.accounttype as to_accounttype, alxbto.certnumber as to_certnumber from ($subqueryTXN) txn 1287 left join ($subqueryALXB) as alxbfrom on txn.fromkey::text = alxbfrom.key::text 1288 left join ($subqueryALXB) as alxbto on txn.tokey::text = alxbto.key::text 1289 order by txn.next_trigger_date";
1291 $sth = db_query($sql, $dbh);
1293 throw new exception(
"Select query failed.", 101);
1295 $repeatingTransfers = array();
1301 for($i = 0; $row = db_fetch_assoc($sth, $i); $i++) {
1302 switch($row[
"feature_code"]) {
1304 $achcols[] = $row[
"id"];
1307 $achpmts[] = $row[
"id"];
1311 $exts[] = $row[
"id"];
1315 $repeatingTransfers[] = $row;
1320 if (count($achcols) > 0) {
1321 $sql[] =
"select s.id as data_id, ap.ach_name, ap.display_name, ap.address, ap.dfi_data from cu_scheduledtxn s 1322 inner join ${Cu}achpartner ap on s.feature_code = 'ACHCOL' and cast(s.txn_data::json->'txn'->>'from' as int) = ap.id where s.id in (" . implode(
", ", $achcols) .
")";
1324 if (count($achpmts) > 0) {
1325 $sql[] =
"select s.id as data_id, ap.ach_name, ap.display_name, ap.address, ap.dfi_data from cu_scheduledtxn s 1326 inner join ${Cu}achpartner ap on s.feature_code = 'ACHPMT' and cast(s.txn_data::json->'txn'->>'to' as int) = ap.id where s.id in (" . implode(
", ", $achpmts) .
")";
1329 if (count($sql) > 0) {
1330 $sql = implode(
" union all ", $sql);
1331 $sth = db_query($sql, $dbh);
1333 throw new exception(
"ach map query failed.", 307);
1335 for($i = 0; $row = db_fetch_assoc($sth, $i); $i++) {
1336 $row[
"dfi_data"] = HCU_JsonDecode($row[
"dfi_data"]);
1337 $row[
"address"] = HCU_JsonDecode($row[
"address"]);
1339 $achMap[$row[
"data_id"]] = $row;
1345 if (count($exts) > 0) {
1346 $sql[] =
"select s.id as data_id, 'from' as dir, ea.display_name, ea.remote_info from cu_scheduledtxn s 1347 inner join ${Cu}extaccount ea on s.feature_code in ('TRNEXT') and s.txn_data::json->'txn'->>'type' in ('X2L') and cast(s.txn_data::json->'txn'->>'from' as int) = ea.id 1348 and ea.type = 'EXT' where s.id in (" . implode(
", ", $exts) .
")";
1349 $sql[] =
"select s.id as data_id, 'to', ea.display_name, ea.remote_info from cu_scheduledtxn s 1350 inner join ${Cu}extaccount ea on s.feature_code in ('TRNEXT', 'TRNM2M') and s.txn_data::json->'txn'->>'type' in ('L2X', 'L2M') and replace(s.feature_code, 'TRN', '') = ea.type 1351 and cast(s.txn_data::json->'txn'->>'to' as int) = ea.id where s.id in (" . implode(
", ", $exts) .
")";
1354 if (count($sql) > 0) {
1355 $sql = implode(
" union all ", $sql);
1356 $sth = db_query($sql, $dbh);
1358 throw new exception(
"ext map query failed.", 308);
1360 for($i = 0; $row = db_fetch_assoc($sth, $i); $i++) {
1361 $row[
"remote_info"] = HCU_JsonDecode($row[
"remote_info"]);
1363 $extMap[$row[
"data_id"]] = $row;
1367 $mask = GetMask($dbh, $Cu)[
"data"];
1368 for($i = 0, $iCount = count($repeatingTransfers); $i != $iCount; $i++) {
1369 $row = $repeatingTransfers[$i];
1371 $repeating = isset($row[
"repeating_parameters"]) ? trim($row[
"repeating_parameters"]) :
"";
1372 if ($repeating !=
"") {
1373 $repeating = HCU_JsonDecode($repeating);
1374 if (!is_array($repeating)) {
1375 throw new exception(
"Repeating is malformed.", 102);
1377 if (!HCU_array_key_exists(
"interval", $repeating)) {
1378 throw new exception(
"Repeating is malformed.", 103);
1380 $row[
"interval"] = $repeating[
"interval"];
1381 $row[
"intervalText"] = HCU_array_key_exists($row[
"interval"], $intervalLookup) ? $intervalLookup[$row[
"interval"]] :
"";
1383 unset($row[
"repeating_parameters"]);
1385 $txnData = isset($row[
"txn_data"]) ? trim($row[
"txn_data"]) :
"";
1386 $flagset3 = GetFlagsetValue(
'CU3_PREPEND_MBR_DESC');
1387 $row[
"details"] =
"";
1388 if ($txnData !=
"") {
1389 $txnData = HCU_JsonDecode($txnData);
1390 if (!is_array($txnData)) {
1391 throw new exception(
"TxnData is malformed.", 104);
1395 switch($row[
"feature_code"]) {
1397 $row[
"details"] =
"<b>From</b> " .
1398 getAccountDescription($dbh, $Cu, $row[
"from_acct"], $row[
"from_desc"], $row[
"from_accounttype"],
"", $flagset3, $row[
"from_certnumber"])
1399 .
"<br> <b>To</b> " .
1400 getAccountDescription($dbh, $Cu, $row[
"to_acct"], $row[
"to_desc"], $row[
"to_accounttype"],
"", $flagset3, $row[
"to_certnumber"]);
1403 $partnerRow = $achMap[$row[
"id"]];
1404 $routing = trim($partnerRow[
"dfi_data"][
"dfi_routing"]);
1405 $account = trim($partnerRow[
"dfi_data"][
"dfi_account"]);
1406 $from = $routing .
" / " . ApplyMask($account, $mask);
1407 $row[
"details"] =
"<b>From</b> $from " 1408 .
"<br> <b>To</b> " . getAccountDescription($dbh, $Cu, $row[
"to_acct"], $row[
"to_desc"], $row[
"to_accounttype"],
"", $flagset3, $row[
"to_certnumber"]);
1411 $partnerRow = $achMap[$row[
"id"]];
1412 $routing = trim($partnerRow[
"dfi_data"][
"dfi_routing"]);
1413 $account = trim($partnerRow[
"dfi_data"][
"dfi_account"]);
1414 $to = $routing .
" / " . ApplyMask($account, $mask);
1415 $row[
"details"] =
"<b>From</b> " .
1416 getAccountDescription($dbh, $Cu, $row[
"from_acct"], $row[
"from_desc"], $row[
"from_accounttype"],
"", $flagset3, $row[
"from_certnumber"])
1417 .
"<br> <b>To</b> $to ";
1420 $extAccount = $extMap[$row[
"id"]];
1421 $account = trim($extAccount[
"remote_info"][
"rdfi"][
"account"]);
1422 $type = intval($extAccount[
"remote_info"][
"rdfi"][
"type"]);
1423 $type = $type == 10 ?
"Checking" :
"Savings";
1424 $to = ApplyMask($account, $mask) .
" / $type";
1426 $row[
"details"] =
"<b>From</b> " .
1427 getAccountDescription($dbh, $Cu, $row[
"from_acct"], $row[
"from_desc"], $row[
"from_accounttype"],
"", $flagset3, $row[
"from_certnumber"])
1428 .
"<br> <b>To</b> $to";
1431 $extAccount = $extMap[$row[
"id"]];
1432 $fromLabel = $extAccount[
"dir"] ==
"from" ?
"ACH From Account" :
"From";
1433 $toLabel = $extAccount[
"dir"] ==
"to" ?
"ACH To Account" :
"To";
1435 if ($extAccount[
"dir"] ==
"from") {
1436 $routing = trim($extAccount[
"remote_info"][
"rdfi"][
"routing"]);
1437 $account = trim($extAccount[
"remote_info"][
"rdfi"][
"account"]);
1438 $from = $routing .
" / " . ApplyMask($account, $mask);
1439 $to = getAccountDescription($dbh, $Cu, $row[
"to_acct"], $row[
"to_desc"], $row[
"to_accounttype"],
"", $flagset3, $row[
"to_certnumber"]);
1441 $from = getAccountDescription($dbh, $Cu, $row[
"from_acct"], $row[
"from_desc"], $row[
"from_accounttype"],
"", $flagset3, $row[
"from_certnumber"]);
1442 $routing = trim($extAccount[
"remote_info"][
"rdfi"][
"routing"]);
1443 $account = trim($extAccount[
"remote_info"][
"rdfi"][
"account"]);
1444 $to = $routing .
" / " . ApplyMask($account, $mask);
1446 $row[
"details"] =
"<b>From</b> $from <br> <b>To</b> $to";
1452 $row[
"details"] .=
"<br> <b>Amount</b> \$" . money_format(
'%.2n', $txnData[
"txn"][
"amount"]);
1456 unset($row[
"txn_data"]);
1458 $row[
"statusText"] = $row[
"status"] ==
"A" ?
"Active" :
"Inactive";
1459 $repeatingTransfers[$i] = $row;
1461 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"repeatingTransfers" => $repeatingTransfers);
1462 }
catch(exception $e) {
1463 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
1465 return $returnArray;