49 function LoadUserData($pHbEnv, $pUserId, $pUserData, $pForceUpdate=
false) {
50 $retVal = Array(
"code" =>
"000",
"data" => Array());
53 $noUpdatesNeeded =
true;
55 $mbrReqType = PACKET_REQUEST_INQUIRY;
60 $cuConnResp = _ReturnCUSettings($pHbEnv);
61 if ($cuConnResp[
'code'] !=
'000') {
62 throw new Exception (
"Unable to Load CU Settings");
64 $cuConnSet = HCU_array_key_value(
'data', $cuConnResp);
66 _ApplPrintLogger($pHbEnv, $cuConnSet,
"\n** Load User Data **\n");
71 $mbrAcctList = _ReturnMemberAcctList($pHbEnv, $pUserId);
72 if ($mbrAcctList[
'code'] !=
'000') {
73 throw new Exception (
"No Accounts Found");
83 $mbrLastLogin = (HCU_array_key_value(
'lastlogin', $pUserData) ==
'' ?
'NULL' : HCU_array_key_value(
'lastlogin', $pUserData));
85 $lastPktDate = date(
'D M j Y H:i:s T');
89 foreach ($mbrAcctList[
'data'] as $idx => $subAcctItem) {
93 $reqMemberAcctNbr = $subAcctItem[
'accountnumber'];
100 $paramEmail = HCU_array_key_value(
'email', $pUserData);
101 $mbrEmail = (($paramEmail ==
'' || $paramEmail ==
'no@email.com') ?
"NULL" : trim($paramEmail));
106 $lastAcctStatus = _FetchLastPacketStatus($pHbEnv, $reqMemberAcctNbr);
107 if ($lastAcctStatus[
'code'] ==
'999') {
108 throw new Exception (
"Unable to read account status", 50115);
111 $pktStamps = HCU_array_key_value(
'data', $lastAcctStatus);
112 _ApplPrintLogger($pHbEnv, $cuConnSet,
"\nPacketStamps\n" . print_r($pktStamps,
true));
115 $lastPktStamp = HCU_array_key_value(
'balance_stamp', $pktStamps);
119 if ($lastPktStamp <= 1) {
121 $lastPktDate = date(
'D M j Y H:i:s T');
124 $lastPktDate = date(
'D M j Y H:i:s T', $lastPktStamp);
126 $lastPktAttempt = HCU_array_key_value(
'balance_attempt', $pktStamps);
132 $waitTimeEpoch = time() - HCU_array_key_value(
'livewait', $cuConnSet);
134 if ((abs($lastPktStamp) > $waitTimeEpoch || $lastPktAttempt > $waitTimeEpoch) && !$pForceUpdate) {
143 $noUpdatesNeeded =
false;
152 $lastPktStamp = ($lastPktStamp < 1 ? 1 : $lastPktStamp);
154 $pktStamps[
'laststamp'] = $lastPktStamp;
155 $pktStamps[
'lastattempt'] = $lastPktAttempt;
159 $packetCutoff = _ReturnCutoffDate($cuConnSet, $pktStamps, $mbrReqType);
161 _ApplPrintLogger($pHbEnv, $cuConnSet,
"\n Packet Cutoff $packetCutoff ");
170 $newPacketAttempt = time();
173 "accountnumber" => $reqMemberAcctNbr,
174 "balance_attempt" => $newPacketAttempt,
175 "history_attempt" => $newPacketAttempt
181 $respStatus = _SetPacketStatus($pHbEnv, $pktData);
182 if ($respStatus[
'code'] !=
'000') {
183 throw new Exception(
'Error updating Accounts: ' . HCU_JsonEncode($respStatus[
'error']), 50120);
190 $newPacketAttempt = time();
193 "accountnumber" => $reqMemberAcctNbr,
194 "balance_attempt" => $newPacketAttempt,
195 "history_attempt" => $newPacketAttempt
204 "member" => $reqMemberAcctNbr,
206 "if_mod_since" => $lastPktStamp,
208 "lastlogin" => $mbrLastLogin,
209 "cutoff" => $packetCutoff
211 _ApplPrintLogger($pHbEnv, $cuConnSet, print_r($dataArray,
true));
215 $acctResp = _RetrieveMemberInquiry($pHbEnv, $cuConnSet, $dataArray);
217 if (!in_array($acctResp[
'code'], array(
'000',
'001',
'002',
'003'))) {
222 throw new Exception (
"Unable to retrieve list of accounts - " . $acctResp[
'error']);
227 $packetStatus = HCU_array_key_value(
"packet-status", $acctResp[
'data']);
228 _ApplPrintLogger($pHbEnv, $cuConnSet,
" ** Packet Status Array ** " . print_r($packetStatus,
true));
230 switch (HCU_array_key_value(
'pktStatCode', $packetStatus)) {
234 $pktTime = HCU_array_key_value(
'pktTime', $packetStatus);
236 _ApplPrintLogger($pHbEnv, $cuConnSet,
" * 100 No New Data * $pktTime" );
238 $newPacketAttempt = time();
240 "accountnumber" => $reqMemberAcctNbr,
241 "balance_stamp" => $pktTime,
242 "balance_attempt" => $newPacketAttempt,
243 "history_stamp" => $pktTime,
244 "history_attempt" => $newPacketAttempt
250 $respStatus = _SetPacketStatus($pHbEnv, $pktData);
251 if ($respStatus[
'code'] !=
'000') {
252 throw new Exception(
'Error updating Accounts: ' . HCU_JsonEncode($respStatus[
'error']), 50120);
258 $xmlPacket = $acctResp[
'data'][
'packet-xml'];
265 $lastPktStamp = HCU_array_key_value(
'balance_stamp', $pktStamps);
266 $lastPktStamp = ($lastPktStamp ==
'' ? 1 : $lastPktStamp);
267 $newTimeStamp = time();
271 if ($lastPktStamp <= 1) {
273 $lastPktDate = date(
'D M j Y H:i:s T');
276 $lastPktDate = date(
'D M j Y H:i:s T', HCU_array_key_value(
'pktTime', $packetStatus));
282 $waitTimeEpoch = time() - HCU_array_key_value(
'livewait', $cuConnSet);
283 if (abs($lastPktStamp) > $waitTimeEpoch) {
285 throw new Exception($lastPktDate,
'50111');
300 'type' => PACKET_REQUEST_INQUIRY,
301 'member' => $reqMemberAcctNbr,
302 'cutoff' => $packetCutoff
304 $dataResp = _SaveMemberData($pHbEnv, $cuConnSet, $pktStamps, $mbrData, $xmlPacket);
305 if ($dataResp[
'code'] ==
'999') {
306 throw new Exception (
"Update Failure", 999);
316 throw new Exception (
"Unknown Packet Status Code", intval(HCU_array_key_value(
'pktStatCode', $packetStatus)));
319 $retVal = Array(
'code' =>
'000',
'data' => array(
'requestDate' => $lastPktDate,
'requestDesc' =>
'Success'));
320 }
catch (Exception $e) {
321 _ApplPrintLogger($pHbEnv, $cuConnSet,
"\n Load User Data -- Catch Error :: ({$e->getCode()}) {$e->getMessage()}");
323 if ($e->getCode() == 50111) {
326 $retVal = Array(
'code' =>
'900',
'data' => array(
'requestDate' => $e->getMessage(),
'requestDesc' =>
'Too soon to ask again'));
329 $retVal = Array(
'code' =>
'999',
'data' => array(
'requestDate' => 1,
'requestDesc' =>
'Unable to retrieve data'));
335 if ($noUpdatesNeeded && $retVal[
'code'] ==
'000') {
337 $retVal = Array(
'code' =>
'900',
'data' => array(
'requestDate' => $lastPktDate,
'requestDesc' =>
'Too soon to ask again'));
360 function SetbackMemberStamps($pHbEnv, $pUserId, $pUserData) {
361 $retVal = Array(
"code" =>
"000",
"data" => Array());
367 $cuConnResp = _ReturnCUSettings($pHbEnv);
368 if ($cuConnResp[
'code'] !=
'000') {
369 throw new Exception (
"Unable to Load CU Settings");
371 $cuConnSet = HCU_array_key_value(
'data', $cuConnResp);
373 _ApplPrintLogger($pHbEnv, $cuConnSet,
"\n* SetbackMemberStamps *\n" . print_r($pUserData,
true));
379 if (count(HCU_array_key_exists(
"accountnumbers", $pUserData)) == 0) {
380 throw new Exception (
"No Member Accounts Listed");
382 if (!is_array(HCU_array_key_value(
"accountnumbers", $pUserData))) {
383 throw new Exception (
"No Member Accounts Listed");
388 $waitBuffer = intval($pHbEnv[
'livewait']);
391 $newPktStamp = time() - (2 * $waitBuffer);
392 $stampThreshold = time() - (3 * $waitBuffer);
395 "accountnumber" =>
'',
396 "balance_attempt" => $newPktStamp,
397 "balance_stamp" => $newPktStamp,
398 "history_attempt" => $newPktStamp,
399 "history_stamp" => $newPktStamp
404 foreach (HCU_array_key_value(
"accountnumbers", $pUserData) as $idx => $reqMemberAcctNbr) {
410 $lastAcctStatus = _FetchLastPacketStatus($pHbEnv, $reqMemberAcctNbr);
411 if ($lastAcctStatus[
'code'] ==
'999') {
412 throw new Exception (
"Unable to read account status", 50115);
414 $pktStamps = HCU_array_key_value(
'data', $lastAcctStatus);
415 _ApplPrintLogger($pHbEnv, $cuConnSet,
"\nPacketStamps\n" . print_r($pktStamps,
true));
418 $lastPktStamp = HCU_array_key_value(
'balance_stamp', $pktStamps);
420 if ($lastPktStamp > $stampThreshold) {
426 $pktData[
'accountnumber'] = $reqMemberAcctNbr;
431 $respStatus = _SetPacketStatus($pHbEnv, $pktData);
432 if ($respStatus[
'code'] !=
'000') {
433 throw new Exception(
'Error updating Accounts: ' . HCU_JsonEncode($respStatus[
'error']), 50120);
439 }
catch (exception $e) {
440 $retVal[
'code'] =
'999';
441 $retVal[
'error'] = $e->getMessage();
467 function _ReturnAccountPacketData($pHbEnv, $pMbrData) {
468 $retVal = Array(
"code" =>
'000',
"data" => Array());
473 $acctData = explode(
"|", HCU_array_key_value(
'acct-key', $pMbrData));
476 if ($acctData[0] ==
'') {
477 throw new Exception (
"Unknown Account Number");
480 $lastStatus = _FetchLastPacketStatus($pHbEnv, $acctData[0]);
482 if ($lastStatus[
'code'] ==
'000') {
486 }
catch (Exception $e) {
487 $retVal[
'code'] =
'999';
488 $retVal[
'error'] =
"Unable to get last account status";
510 function _FetchLastPacketStatus($pHbEnv, $pMbrAcct) {
512 $retVal = Array(
"code" =>
"000",
"data" => Array());
514 $cuCode = HCU_array_key_value(
'Cu', $pHbEnv);
515 $dbConn = HCU_array_key_value(
'dbh', $pHbEnv);
519 throw new Exception(
"CU Not Set");
524 if ($pMbrAcct ==
'') {
525 throw new Exception (
"Unknown Account Number");
528 if (db_connection_status($dbConn) !== PGSQL_CONNECTION_OK) {
530 throw new Exception(
"Problem connecting to database");
542 $sql =
"SELECT balance_attempt, balance_stamp, balance_attempt as history_attempt, balance_stamp as history_stamp 543 FROM " . prep_save($cuCode, 10) .
"memberacct 544 WHERE accountnumber = '" . prep_save($pMbrAcct, 12) .
"' ";
561 $sqlRs = db_query($sql, $dbConn);
563 $retVal[
'data'] = db_fetch_assoc($sqlRs);
565 throw new Exception(
"Unable to retrieve records");
568 }
catch (Exception $e) {
570 $retVal[
'code'] =
'999';
571 $retVal[
'error'] =
"Data retrieval failed";
572 $retVal[
'data'] = Array();
601 function _SetPacketStatus ($pHbEnv, $pPktData) {
602 $retVal = Array(
"code" =>
"000",
'data' => Array());
605 $dbConn = HCU_array_key_value(
'dbh', $pHbEnv);
606 $cuCode = HCU_array_key_value(
'Cu', $pHbEnv);
607 $acctNbr = HCU_array_key_value(
'accountnumber', $pPktData);
615 if (db_connection_status($dbConn) !== PGSQL_CONNECTION_OK) {
617 throw new Exception(
"Problem connecting to database", 750);
625 throw new Exception(
"CU Code Not Set", 751);
631 if ($acctNbr ==
'') {
633 throw new Exception (
"Account Number not set", 752);
639 "memberacct" => Array(
643 "accountbalance" => Array(
648 "loanbalance" => Array(
657 "memberacct" => Array(
666 foreach ($tableList as $tableName => $fieldList) {
669 $fieldUpdList = array_intersect_key($pPktData, array_flip($fieldList));
670 if (count($fieldUpdList) > 0) {
672 $sql .=
"UPDATE " . prep_save($cuCode, 10) . $tableName .
" SET ";
674 foreach ($fieldUpdList as $fieldName => $fieldVal) {
675 $sqlSep = ($fieldCnt == 0 ?
'' :
', ');
676 $sql .= $sqlSep . $fieldName .
" = " . intval(HCU_array_key_value($fieldName, $pPktData));
680 $sql .=
" WHERE accountnumber = '" . prep_save($acctNbr, 12) .
"';\n";
684 $sqlRs = db_query($sql, $dbConn);
686 $retVal[
'data'] = db_fetch_all($sqlRs);
688 throw new Exception(
"Unable to retrieve records");
691 }
catch (Exception $e) {
692 switch ($e->getCode()) {
695 $retVal[
'error'] = $e->getMessage();
699 $retVal[
'error'] =
"Unknown error while updating packet status. " . $e->getMessage();
703 $retVal[
'code'] =
'999';
704 $retVal[
'data'] = Array();
729 function _SaveMemberData($pHbEnv, $pConnSet, $pPktStamps, $pMbrData, $pDataPacket) {
730 $retVal = array(
"code" =>
"000",
"data" => array());
732 _ApplPrintLogger($pHbEnv, $pConnSet,
"\nSaveMemberData\n" . print_r($pPktStamps,
true));
736 $dbConn = HCU_array_key_value(
'dbh', $pHbEnv);
740 $newPktStamp = time();
743 "accountnumber" => HCU_array_key_value(
'member', $pMbrData),
744 "balance_stamp" => ($newPktStamp * -1)
747 $respStatus = _SetPacketStatus($pHbEnv, $pktData);
748 if ($respStatus[
'code'] !=
'000') {
749 throw new Exception (
"Unable to update the packet stamp prior to update.");
752 $pPktStamps[
'balance_stamp'] = $newPktStamp;
753 $pPktStamps[
'history_stamp'] = $newPktStamp;
756 if (!is_a($pDataPacket,
"SimpleXMLElement")) {
758 throw new Exception (
"Data Packet Error");
763 if (db_transaction_status($dbConn) === PGSQL_TRANSACTION_ACTIVE || db_transaction_status($dbConn) === PGSQL_TRANSACTION_INTRANS) {
766 $startRs = db_work ($dbConn, HOMECU_WORK_BEGIN);
772 $pktInquiryNode = $pDataPacket->Inquiry;
773 $updTableList = Array(
"accountbalance",
"accounthistory",
"loanbalance",
"loanhistory");
778 if ($pHbEnv[
'Fset2'] & GetFlagsetValue(
'CU2_SHOWHOLD')) {
779 array_push($updTableList,
"holds");
781 _ApplPrintLogger($pHbEnv, $pConnSet,
" ** Table List -- " . print_r($updTableList,
true));
791 if (isset($pktInquiryNode->Parameters)) {
792 $newParameters = $pktInquiryNode->Parameters;
793 list($paramMbr, $paramCutoff) = explode(
"\t", $newParameters);
794 $paramCutoff = trim($paramCutoff);
796 if ($paramCutoff !=
'' && strlen($paramCutoff) == 8) {
799 _ApplPrintLogger($pHbEnv, $pConnSet,
"Cutoff Changed -- From {$pMbrData['cutoff']} to $paramCutoff");
800 $pMbrData[
'cutoff'] = $paramCutoff;
802 _ApplPrintLogger($pHbEnv, $pConnSet,
"Cutoff NOT Changed -- {$pMbrData['cutoff']}");
806 _ApplPrintLogger($pHbEnv, $pConnSet,
"Parameters NOT SET");
812 foreach ($updTableList as $updTableName) {
813 _ApplPrintLogger($pHbEnv, $pConnSet,
"\nUpdate -- $updTableName\n");
816 $updTableDef = _GetPacketColumnList($pHbEnv, $updTableName);
818 $tblPktData = $pktInquiryNode->{HCU_array_key_value(
'node', $updTableDef)};
820 $tblUpdFunction = HCU_array_key_value(
'import-function', $updTableDef);
821 if (!function_exists($tblUpdFunction)) {
822 throw new Exception (
"Unknown Import Function");
824 $updTableResp = $tblUpdFunction($pHbEnv, $pConnSet, $pPktStamps, HCU_array_key_value(
'tablename', $updTableDef), $pMbrData, $tblPktData);
826 if ($updTableResp[
'code'] !=
'000') {
828 throw new Exception (
"Table Update Failed -- $updTableName");
831 if (HCU_array_key_exists(
'insert', $updTableResp[
'data'])) {
837 $updUserAcct = _UpdateUserAccounts($pHbEnv, $pConnSet, trim(HCU_array_key_value(
'member', $pMbrData)), $updTableResp[
'data'][
'insert']);
838 if ($updUserAcct[
'code'] !=
'000') {
840 throw new Exception (
"Table Update Failed -- UpdateUserAccounts");
850 $pktData[
"balance_stamp"] = $newPktStamp;
854 $respStatus = _SetPacketStatus($pHbEnv, $pktData);
859 $commitRs = db_work ($dbConn, HOMECU_WORK_COMMIT);
862 throw new Exception (
"Failed to Commit Work");
868 }
catch (Exception $e) {
870 _ApplPrintLogger($pHbEnv, $pConnSet,
"\nSave Member Failed\n{$e->getMessage()}, " . db_last_error() .
", " . print_r($pMbrData,
true) .
"");
874 $commitRs = db_work ($dbConn, HOMECU_WORK_ROLLBACK);
877 $retVal[
'code'] =
'999';
878 $retVal[
'error'] =
"Error occurred while updating tables";
901 function _SaveMemberXAData($pHbEnv, $pConnSet, $pMbrData, $pDataPacket) {
902 $retVal = array(
"code" =>
"000",
"data" => array());
904 _ApplPrintLogger($pHbEnv, $pConnSet,
"\nSaveMemberXAData\n" . print_r($pMbrData,
true));
907 $dbConn = HCU_array_key_value(
'dbh', $pHbEnv);
909 $newPktStamp = time();
912 if (!is_a($pDataPacket,
"SimpleXMLElement")) {
914 throw new Exception (
"Data Packet Error");
918 if (db_transaction_status($dbConn) === PGSQL_TRANSACTION_ACTIVE || db_transaction_status($dbConn) === PGSQL_TRANSACTION_INTRANS) {
921 $startRs = db_work ($dbConn, HOMECU_WORK_BEGIN);
928 $pktInquiryNode = $pDataPacket->CrossAccount;
930 $updTableName =
"crossaccounts";
931 _ApplPrintLogger($pHbEnv, $pConnSet,
"\nCross Account Update -- $updTableName\n");
934 $updTableDef = _GetPacketColumnList($pHbEnv, $updTableName);
937 $tblPktData = $pktInquiryNode->{HCU_array_key_value(
'node', $updTableDef)};
939 $tblUpdFunction = HCU_array_key_value(
'import-function', $updTableDef);
941 if (!function_exists($tblUpdFunction)) {
942 throw new Exception (
"Unknown Import Function");
944 _ApplPrintLogger($pHbEnv, $pConnSet,
"\n CALL FUNCTION $tblUpdFunction \n");
946 $updTableResp = $tblUpdFunction($pHbEnv, $pConnSet, HCU_array_key_value(
'tablename', $updTableDef), $pMbrData, $tblPktData);
948 if ($updTableResp[
'code'] !=
'000') {
950 throw new Exception (
"Table Update Failed -- $updTableName");
953 if (HCU_array_key_exists(
'insert', $updTableResp[
'data'])) {
959 $updUserAcct = _UpdateUserAccounts($pHbEnv, $pConnSet, trim(HCU_array_key_value(
'member', $pMbrData)), $updTableResp[
'data'][
'insert']);
960 if ($updUserAcct[
'code'] !=
'000') {
963 throw new Exception (
"Table Update Failed -- UpdateUserAccounts");
966 $retVal[
'data'][
'memberacct-added'] = count($updUserAcct[
'data']);
975 $commitRs = db_work ($dbConn, HOMECU_WORK_COMMIT);
978 throw new Exception (
"Failed to Commit Work");
984 }
catch (Exception $e) {
985 _ApplPrintLogger($pHbEnv, $pConnSet,
"\nSave Cross Account Failed\n{$e->getMessage()}, " . db_last_error() .
", " . print_r($pMbrData,
true) .
"");
988 $commitRs = db_work ($dbConn, HOMECU_WORK_ROLLBACK);
991 $retVal[
'code'] =
'999';
992 $retVal[
'error'] =
"Error occurred while updating tables";
1006 function _GetPacketColumnList ($pHbEnv, $pTableType) {
1022 switch (strtolower($pTableType)) {
1023 case "accountbalance":
1028 'tablename' =>
'accountbalance',
1029 'import-type' =>
"Update else import",
1030 'import-function' =>
'_UpdateInsertBalance',
1032 'node' =>
'AccountBalance',
1033 'allow-missing' =>
false,
1050 'tablename' =>
'loanbalance',
1051 'import-type' =>
"Update else import",
1052 'import-function' =>
'_UpdateInsertBalance',
1053 'node' =>
'LoanBalance',
1054 'allow-missing' =>
false,
1082 case "accounthistory":
1087 'tablename' =>
'accounthistory',
1088 'import-type' =>
"Delete from cutoff then copy in",
1089 'import-function' =>
'_UpdateCopyInHistory',
1091 'node' =>
'AccountHistory',
1092 'allow-missing' =>
false,
1112 'tablename' =>
'loanhistory',
1113 'import-type' =>
"Delete from cutoff then copy in",
1114 'import-function' =>
'_UpdateCopyInHistory',
1116 'node' =>
'LoanHistory',
1117 'allow-missing' =>
false,
1139 if (HCU_array_key_value(
'flagset2', $pHbEnv) & GetFlagsetValue(
'CU2_ESCHEMA')) {
1140 array_push($retVal[
'columns'],
"fee",
"escrow");
1143 case "crossaccounts":
1148 'tablename' =>
'crossaccounts',
1149 'import-style' =>
'Update misc1 if exists, Insert if NOT, delete unused',
1150 'import-function' =>
'_DeleteInsertCrossAcct',
1152 'node' =>
'TxAccount',
1153 'allow-missing' =>
true,
1169 'tablename' =>
'holds',
1170 'import-style' =>
'Truncate Table, Insert all records',
1171 'import-function' =>
'_UpdateCopyIn',
1174 'allow-missing' =>
false,
1193 if (HCU_array_key_exists(
'columns', $retVal)) {
1194 $retVal[
'column-list'] = implode (
', ', $retVal[
'columns']);
1201 }
catch (Exception $e) {
1229 function _UpdateInsertBalance ($pHbEnv, $pConnSet, $pPktStamps, $pTableName, $pMbrData, $pData) {
1230 $retVal = array(
"code" =>
"000",
"data" => array());
1232 $insertedRows = Array();
1234 $dbConn = HCU_array_key_value(
'dbh', $pHbEnv);
1235 $lMc = HCU_array_key_value(
'MC', $pHbEnv);
1237 $tbl2Update = _GetPacketColumnList($pHbEnv, $pTableName);
1238 $tblColumns = HCU_array_key_value(
"columns", $tbl2Update);
1250 $dataRow = strtok($pData,
"\n");
1251 while ($dataRow !==
false) {
1254 if ($dataRow !=
'') {
1256 $recordValues = explode(
"\t", $dataRow);
1263 if (count($tblColumns) > count($recordValues) && $tbl2Update[
"allow-missing"]) {
1265 for ($colIdx = count($recordValues); $colIdx < count($tblColumns); $colIdx++) {
1267 $recordValues[] =
"";
1271 if (count($tblColumns) != count($recordValues)) {
1272 throw new Exception (
"Column Count Mismatch");
1274 $updateRow = array_combine($tblColumns, $recordValues);
1276 $updateRow[
'_action'] =
"update";
1279 $updateRow[
'balance_stamp'] = HCU_array_key_value(
'balance_stamp', $pPktStamps);
1280 $updateRow[
'history_stamp'] = HCU_array_key_value(
'history_stamp', $pPktStamps);
1283 $mayResp = _DetermineMayValues($pHbEnv, $pTableName, $updateRow);
1285 $updateRow = array_merge($updateRow, $mayResp);
1286 $updResult = SetDataTableUpdate($dbConn, $pHbEnv, $lMc, $pTableName, $updateRow,
false);
1289 if ($updResult[
'code'] ==
'000') {
1291 if (HCU_array_key_value($pTableName, $updResult[
'data'][
'row']) ===
false) {
1293 $updateRow[
'_action'] =
"insert";
1294 $updResult = SetDataTableUpdate($dbConn, $pHbEnv, $lMc, $pTableName, $updateRow,
false);
1297 $insertedRows[$pTableName][] = $updateRow;
1298 _ApplPrintLogger($pHbEnv, $pConnSet,
"\nInsert Balance Record\n" . print_r($updateRow,
true));
1303 $dataRow = strtok(
"\n");
1306 if (count($insertedRows) > 0) {
1308 $retVal[
'data'][
'insert'] = $insertedRows;
1314 FROM {$pHbEnv['cu']}{$pTableName} 1315 WHERE balance_stamp < " . HCU_array_key_value(
'balance_stamp', $pPktStamps) .
" 1316 AND accountnumber = '" . prep_save(HCU_array_key_value(
'member', $pMbrData), 12) .
"'; ";
1318 _ApplPrintLogger($pHbEnv, $pConnSet,
"\nSAMPLE DELETE RESULTS \n" . $delSql);
1320 $delResults = db_query($delSql, $dbConn);
1322 }
catch (Exception $e) {
1323 _ApplPrintLogger($pHbEnv, $pConnSet,
"\nUpdate Insert Failed\n" . db_last_error());
1325 $retVal[
'code'] =
'999';
1326 $retVal[
'error'] = $e->getMessage();
1329 _ApplPrintLogger($pHbEnv, $pConnSet,
"\n Return from UpdateInsertBalance " . print_r($retVal,
true));
1352 function _UpdateCopyInHistory($pHbEnv, $pConnSet, $pPktStamps, $pTableName, $pMbrData, $pData) {
1353 $retVal = array(
"code" =>
"000",
"data" => array());
1358 $dbConn = HCU_array_key_value(
'dbh', $pHbEnv);
1359 $lMc = HCU_array_key_value(
'MC', $pHbEnv);
1360 $cuCode = HCU_array_key_value(
'Cu', $pHbEnv);
1362 $mbrAcctNbr = HCU_array_key_value(
'member', $pMbrData);
1363 $dataCutoff = HCU_array_key_value(
'cutoff', $pMbrData);
1365 $tbl2Update = _GetPacketColumnList($pHbEnv, $pTableName);
1367 $tblColList = HCU_array_key_value(
"column-list", $tbl2Update);
1370 $sql =
"DELETE FROM " . prep_save($cuCode, 12) . $tbl2Update[
'tablename'] .
" 1371 WHERE accountnumber = '" . prep_save($mbrAcctNbr, 12) .
"' 1372 AND date >= '" . prep_save($dataCutoff) .
"'; ";
1374 _ApplPrintLogger($pHbEnv, $pConnSet,
"\nCOPY IN DELETE: $sql");
1375 $sqlRs = db_query($sql, $dbConn);
1377 throw new Exception(
"Unable to truncate history");
1381 $pData = ltrim($pData,
"\n");
1383 $pData = rtrim($pData,
"\n");
1387 if (strlen($pData) > 0) {
1393 $sql =
"COPY " . prep_save($cuCode, 12) . $pTableName .
" ($tblColList) 1394 FROM STDIN WITH NULL as ''";
1395 $copyRs = db_query($sql, $dbConn);
1397 throw new Exception (
"Error starting the copy");
1402 $dataRecords = explode(
"\n", $pData);
1406 foreach ($dataRecords as $key => $line) {
1409 $line = preg_replace(
"/ ?\t ?/" ,
"\t", $line);
1410 $line = preg_replace(
"/ $/",
"", $line);
1411 $line = preg_replace(
"/\\0/",
" ", $line);
1413 _ApplPrintLogger($pHbEnv, $pConnSet,
"\nCopy In Line [{$line}]");
1415 pg_put_line($dbConn, $line .
"\n");
1421 $endCopyRs = pg_put_line($dbConn,
"\\.\n");
1425 throw new Exception (
"Error with the final pg_put_line");
1427 $resultsRs = pg_end_copy($dbConn);
1429 throw new Exception (
"Error Performing the Copy");
1432 }
catch (Exception $e) {
1434 _ApplPrintLogger($pHbEnv, $pConnSet,
"\n_UpdateCopyInHistory -- Catch Error :: " . $e->getMessage() .
" :: " . db_last_error() .
"");
1435 $retVal[
'code'] =
'999';
1436 $retVal[
'error'] = $e->getMessage();
1460 function _UpdateCopyIn($pHbEnv, $pConnSet, $pPktStamps, $pTableName, $pMbrData, $pData) {
1461 $retVal = array(
"code" =>
"000",
"data" => array());
1463 _ApplPrintLogger($pHbEnv, $pConnSet,
"\n** Update Copy In **\n $pData");
1466 $dbConn = HCU_array_key_value(
'dbh', $pHbEnv);
1467 $lMc = HCU_array_key_value(
'MC', $pHbEnv);
1468 $cuCode = HCU_array_key_value(
'Cu', $pHbEnv);
1470 $mbrAcctNbr = HCU_array_key_value(
'member', $pMbrData);
1473 $tbl2Update = _GetPacketColumnList($pHbEnv, $pTableName);
1475 $tblColList = HCU_array_key_value(
"column-list", $tbl2Update);
1478 $sql =
"DELETE FROM " . prep_save($cuCode, 12) . $tbl2Update[
'tablename'] .
" 1479 WHERE accountnumber = '" . prep_save($mbrAcctNbr, 12) .
"'; ";
1481 _ApplPrintLogger($pHbEnv, $pConnSet,
"\nCOPY IN DELETE $sql");
1482 $sqlRs = db_query($sql, $dbConn);
1484 throw new Exception(
"Unable to truncate " . $tbl2Update[
'tablename']);
1488 $pData = ltrim($pData,
"\n");
1490 $pData = rtrim($pData,
"\n");
1493 if (strlen($pData) > 0) {
1499 $sql =
"COPY " . prep_save($cuCode, 12) . $tbl2Update[
'tablename'] .
" ($tblColList) 1500 FROM STDIN WITH NULL as ''";
1501 $copyRs = db_query($sql, $dbConn);
1503 throw new Exception (
"Error starting the copy");
1505 _ApplPrintLogger($pHbEnv, $pConnSet,
"\n$sql");
1507 $dataRecords = explode(
"\n", $pData);
1509 _ApplPrintLogger($pHbEnv, $pConnSet, print_r($dataRecords,
true));
1511 foreach ($dataRecords as $key => $line) {
1514 $line = preg_replace(
"/ ?\t ?/" ,
"\t", $line);
1515 $line = preg_replace(
"/ $/",
"", $line);
1516 $line = preg_replace(
"/\\0/",
" ", $line);
1518 _ApplPrintLogger($pHbEnv, $pConnSet,
"\nCopy In Line [{$line}]");
1520 pg_put_line($dbConn, $line .
"\n");
1526 $endCopyRs = pg_put_line($dbConn,
"\\.\n");
1530 throw new Exception (
"Error with the final pg_put_line");
1532 $resultsRs = pg_end_copy($dbConn);
1534 throw new Exception (
"Error Performing the Copy");
1537 }
catch (Exception $e) {
1539 _ApplPrintLogger($pHbEnv, $pConnSet,
"\n_UpdateCopyIn -- Catch Error :: " . $e->getMessage() .
" :: " . db_last_error() .
"");
1540 $retVal[
'code'] =
'999';
1541 $retVal[
'error'] = $e->getMessage();
1563 function _DeleteInsertCrossAcct ($pHbEnv, $pConnSet, $pTableName, $pMbrData, $pData) {
1564 $retVal = array(
"code" =>
"000",
"data" => array());
1566 $insertedRows = Array();
1568 $dbConn = HCU_array_key_value(
'dbh', $pHbEnv);
1569 $lMc = HCU_array_key_value(
'MC', $pHbEnv);
1570 $cuCode = HCU_array_key_value(
'Cu', $pHbEnv);
1572 $mbrAcctNbr = HCU_array_key_value(
'member', $pMbrData);
1575 $tbl2Update = _GetPacketColumnList($pHbEnv, $pTableName);
1576 $tblColumns = HCU_array_key_value(
"columns", $tbl2Update);
1582 $delSql =
"DELETE FROM " . prep_save($cuCode, 10) .
"crossaccounts 1583 WHERE accountnumber = '" . prep_save($mbrAcctNbr, 12) .
"';";
1585 $delRs = db_query($delSql, $dbConn);
1588 throw new Exception(
"Unable to truncate ${cuCode}crossaccounts");
1592 $dataRow = strtok($pData,
"\n");
1594 while ($dataRow !==
false) {
1596 if ($dataRow !=
'') {
1598 $recordValues = explode(
"\t", $dataRow);
1605 if (count($tblColumns) > count($recordValues) && $tbl2Update[
"allow-missing"]) {
1607 for ($colIdx = count($recordValues); $colIdx < count($tblColumns); $colIdx++) {
1609 $recordValues[] =
"";
1613 if (count($tblColumns) != count($recordValues)) {
1614 throw new Exception (
"Column Count Mismatch");
1616 $updateRow = array_combine($tblColumns, $recordValues);
1619 $updateRow[
'_action'] =
"insert";
1621 $updResult = SetDataTableUpdate($dbConn, $pHbEnv, $lMc, $pTableName, $updateRow,
false);
1623 $insertedRows[$pTableName][] = $updateRow;
1625 if ($updResult[
'code'] !=
'000') {
1626 throw new Exception (
"Unable to load cross accounts.");
1630 $dataRow = strtok(
"\n");
1633 if (count($insertedRows) > 0) {
1635 $retVal[
'data'][
'insert'] = $insertedRows;
1639 }
catch (Exception $e) {
1640 _ApplPrintLogger($pHbEnv, $pConnSet,
"\nUpdate Insert Failed\n" . db_last_error());
1642 $retVal[
'code'] =
'999';
1643 $retVal[
'error'] = $e->getMessage();
1646 _ApplPrintLogger($pHbEnv, $pConnSet,
"\n Return from DeleteInsertCrossAcct " . print_r($retVal,
true));
1668 function _DetermineMayValues($pHbEnv, $pTableName, $pUpdateRow) {
1672 if ($pTableName ==
'loanbalance') {
1673 $retVal = Array(
"may_payment" =>
false,
"may_addon" =>
false);
1676 $retVal[
'may_payment'] =
true;
1680 if (HCU_array_key_value(
'Ffset2', $pUpdateRow) & GetFlagsetValue(
'CU2_SPEC18') == 0 || HCU_array_key_value(
'cbype', $pUpdateRow) !=
'18' 1682 && HCU_array_key_value(
'creditlimit', $pUpdateRow) > 0) {
1683 $retVal[
'may_addon'] =
true;
1686 } elseif ($pTableName ==
'accountbalance') {
1687 $retVal = Array(
"may_deposit" =>
false,
"may_withdraw" =>
false);
1692 $allowedDPTypes = array(
'Y',
'S',
'N');
1693 if (in_array(trim(HCU_array_key_value(
'deposittype', $pUpdateRow)), $allowedDPTypes)) {
1696 $retVal[
"may_deposit"] =
true;
1700 $allowedWDTypes = array(
'Y',
'S',
'N');
1701 if (in_array(trim(HCU_array_key_value(
'deposittype', $pUpdateRow)), $allowedWDTypes)) {
1702 $retVal[
"may_withdraw"] =
true;
1705 } elseif ($pTableName ==
'crossaccounts') {
1706 $retVal[
'may_withdraw'] =
false;
1707 $retVal[
'may_deposit'] =
true;
1727 function _ConvertPacketLineToArray ($pHbEnv, $pConnSet, $pTableName, $pData) {
1728 $retVal = array(
"code" =>
"000",
"data" => array());
1730 $retBalances = Array();
1731 _ApplPrintLogger($pHbEnv, $pConnSet,
"\n* Convert Packet Line To Array *\n");
1735 $tbl2Update = _GetPacketColumnList($pHbEnv, $pTableName);
1738 $tblColumns = HCU_array_key_value(
"columns", $tbl2Update);
1741 $dataRow = strtok($pData,
"\n");
1742 while ($dataRow !==
false) {
1744 if ($dataRow !=
'') {
1746 $recordValues = explode(
"\t", $dataRow);
1754 if (count($tblColumns) > count($recordValues) && $tbl2Update[
"allow-missing"]) {
1756 for ($colIdx = count($recordValues); $colIdx < count($tblColumns); $colIdx++) {
1758 $recordValues[] =
"";
1762 if (count($tblColumns) != count($recordValues)) {
1763 throw new Exception (
"Column Count Mismatch");
1765 $newRow = array_combine($tblColumns, $recordValues);
1768 $mayResp = _DetermineMayValues($pHbEnv, $pTableName, $newRow);
1770 $newRow = array_merge($newRow, $mayResp);
1771 $retBalances[] = $newRow;
1774 $dataRow = strtok(
"\n");
1783 $retVal[
'data'] = $retBalances;
1785 }
catch (Exception $e) {
1786 _ApplPrintLogger($pHbEnv, $pConnSet,
"\nCATCH ERROR Bal Upd Insert {$e->getMessage()}\n");
1787 $retVal[
'code'] =
'999';
1788 $retVal[
'error'] = $e->getMessage();
1809 function _ReturnMemberAcctList($pHbEnv, $pUserId, $pAutoAddOnly=
false) {
1810 $retVal = Array(
"code" =>
"000",
"data" => Array());
1813 $cuCode = HCU_array_key_value(
'Cu', $pHbEnv);
1814 $dbConn = HCU_array_key_value(
'dbh', $pHbEnv);
1816 if ($cuCode ==
'') {
1818 throw new Exception(
"CU Not Set");
1821 if (db_connection_status($dbConn) !== PGSQL_CONNECTION_OK) {
1823 throw new Exception(
"Problem connecting to database");
1836 if ($pAutoAddOnly) {
1837 $sql =
"SELECT distinct trim(useraccounts.accountnumber) as accountnumber 1838 FROM {$cuCode}useraccounts as useraccounts 1839 JOIN {$cuCode}memberacctrights as memberacctrights on memberacctrights.accountnumber = useraccounts.accountnumber 1840 AND memberacctrights.user_id = useraccounts.user_id AND memberacctrights.whichright = 'ACCESS' 1841 WHERE useraccounts.user_id = " . intval($pUserId) .
" 1842 AND memberacctrights.allowed = true 1843 AND (view_balances OR view_transactions OR int_deposit OR int_withdraw OR ext_withdraw OR ext_deposit) ";
1845 $sql =
"SELECT distinct trim(accountnumber) as accountnumber 1846 FROM {$cuCode}useraccounts 1847 WHERE user_id = " . intval($pUserId) .
" 1848 AND (view_balances OR view_transactions OR int_deposit OR int_withdraw OR ext_withdraw OR ext_deposit) ";
1861 SELECT distinct trim(memberacctrights.accountnumber) as accountnumber 1862 FROM {$cuCode}memberacctrights as memberacctrights 1863 WHERE user_id=" . intval($pUserId) .
" 1864 AND memberacctrights.whichright='ACCESS' 1865 AND memberacctrights.allowed =true ; ";
1867 $sqlRs = db_query($sql, $dbConn);
1869 if (db_num_rows($sqlRs) > 0) {
1870 $retVal[
'data'] = db_fetch_all($sqlRs);
1873 throw new Exception(
"Unable to retrieve records");
1876 }
catch (Exception $e) {
1878 $retVal[
'code'] =
'999';
1879 $retVal[
'error'] = $e->getMessage();
1880 $retVal[
'data'] = Array();
1911 function _UpdateUserAccounts($pHbEnv, $pConnSet, $pMbrAcct, $pInsData) {
1913 $retVal = Array(
"code" =>
"000",
"data" => Array());
1915 $cuCode = HCU_array_key_value(
'Cu', $pHbEnv);
1916 $dbConn = HCU_array_key_value(
'dbh', $pHbEnv);
1918 $grantRights = Array(
"ext_deposit" =>
false,
1919 "int_deposit" =>
false,
1920 "ext_withdraw" =>
false,
1921 "int_withdraw" =>
false,
1922 "view_transactions" =>
false,
1923 "view_balances" =>
false 1925 $displayOrder = 999;
1931 $processedMbrAcct = Array();
1934 $userList = GetMemberAccessList($dbConn, $pHbEnv, $pMbrAcct);
1936 if (is_array($userList) && count($userList) > 0) {
1938 foreach ($userList as $user_id) {
1939 $createRecords = Array();
1944 foreach ($pInsData as $tableName => $insertedRecords) {
1945 for ($recIdx = 0; $recIdx < count($insertedRecords); $recIdx++) {
1946 $insertedRecord = $insertedRecords[$recIdx];
1951 if ($tableName ==
"loanbalance") {
1954 $uaAcctType = trim(HCU_array_key_value(
"loannumber", $insertedRecord));
1956 $uaRecordType =
'L';
1957 $grantRights = Array(
"ext_deposit" =>
true,
1958 "int_deposit" =>
true,
1959 "ext_withdraw" =>
false,
1960 "int_withdraw" =>
true,
1961 "view_transactions" =>
true,
1962 "view_balances" =>
true 1965 } elseif ($tableName ==
"accountbalance") {
1968 $uaAcctType = trim(HCU_array_key_value(
"accounttype", $insertedRecord));
1969 $uaCertNumber = intval(HCU_array_key_value(
"certnumber", $insertedRecord));
1970 $uaRecordType =
'D';
1971 $grantRights = Array(
"ext_deposit" =>
true,
1972 "int_deposit" =>
true,
1973 "ext_withdraw" =>
true,
1974 "int_withdraw" =>
true,
1975 "view_transactions" =>
true,
1976 "view_balances" =>
true 1978 } elseif ($tableName ==
"crossaccounts") {
1987 if ((GetFlagsetValue(
"CU3_CREATE_ACCESS_CONTROL_FROM_XAC") & HCU_array_key_value(
"flagset3", $pHbEnv)) == 0) {
1989 $uaAcctType = trim(HCU_array_key_value(
"accounttype", $insertedRecord)) .
'#' . trim(HCU_array_key_value(
"tomember", $insertedRecord));
1996 $uaRecordType = (trim(HCU_array_key_value(
'deposittype', $insertedRecord)) ==
'L' ?
'P' :
'T');
1997 $grantRights = Array(
"ext_deposit" =>
false,
1998 "int_deposit" =>
true,
1999 "ext_withdraw" =>
false,
2000 "int_withdraw" =>
false,
2001 "view_transactions" =>
false,
2002 "view_balances" =>
false 2012 if (trim(HCU_array_key_value(
"tomember", $insertedRecord)) == trim(HCU_array_key_value(
"accountnumber", $insertedRecord))) {
2019 $pMbrAcct = trim(HCU_array_key_value(
"tomember", $insertedRecord));
2020 $uaAcctType = trim(HCU_array_key_value(
"accounttype", $insertedRecord));
2022 $uaCertNumber =
'0';
2023 $uaRecordType = (trim(HCU_array_key_value(
'deposittype', $insertedRecord)) ==
"L" ?
"L" :
"D");
2024 $grantRights = Array(
"ext_deposit" =>
false,
2025 "int_deposit" =>
true,
2026 "ext_withdraw" =>
false,
2027 "int_withdraw" =>
false,
2028 "view_transactions" =>
false,
2029 "view_balances" =>
false 2037 if (!in_array($pMbrAcct, $processedMbrAcct)) {
2038 if (!FindMemberAccountExists ($dbConn, $cuCode, $pMbrAcct)) {
2041 $retVal[
'data'][] = $pMbrAcct;
2043 $memberRecords = array(
"memberacct" => array(array(
"_action" =>
"create",
"accountnumber" => $pMbrAcct,
"primary_user" => 0,
"allowenroll" =>
true)));
2045 if (DataUserTableUpdate($dbConn, $pHbEnv,
null, $memberRecords, $user_id,
"UM_ADD", HCU_array_key_value(
"platform", $pHbEnv), HCU_array_key_value(
'currentscript', $pHbEnv),
"A",
"Auto Add Member Acct", HCU_array_key_value(
'Cn', $pHbEnv),
'', HCU_array_key_value(
'remoteIp', $pHbEnv)) ===
false) {
2046 throw new exception(
"Adding failed.", 108);
2051 $processedMbrAcct[] = $pMbrAcct;
2058 if (!FindUserAccountExists ($dbConn, $cuCode, $user_id, $uaRecordType, $pMbrAcct, $uaAcctType, $uaCertNumber)) {
2059 $createRecords[]= array(
2060 "_action" =>
"create",
"user_id" => $user_id,
2061 "accountnumber" => $pMbrAcct,
"accounttype" => $uaAcctType,
"certnumber" => $uaCertNumber,
"display_name" =>
"",
2062 "recordtype" => $uaRecordType,
2063 "ext_deposit" => $grantRights[
'ext_deposit'],
"ext_withdraw" => $grantRights[
'ext_withdraw'],
2064 "int_deposit" => $grantRights[
'int_deposit'],
"int_withdraw" => $grantRights[
'int_withdraw'],
2065 "view_transactions" => $grantRights[
'view_transactions'],
"view_balances" => $grantRights[
'view_balances'],
2066 "display_order" => $displayOrder);
2071 if (count($createRecords) > 0) {
2074 $createRecords = array(
"useraccounts" => $createRecords);
2076 if (DataUserTableUpdate($dbConn, $pHbEnv,
null, $createRecords, $user_id,
"UA_ADD", HCU_array_key_value(
"platform", $pHbEnv), HCU_array_key_value(
'currentscript', $pHbEnv),
2077 "A",
"Auto Add User Accounts", HCU_array_key_value(
'Cn', $pHbEnv),
'', HCU_array_key_value(
'remoteIp', $pHbEnv)) ===
false) {
2078 throw new exception(
"Adding failed", 106);
2081 if (db_transaction_status($dbConn) == PGSQL_TRANSACTION_INERROR) {
2082 throw new Exception(
"Audit Failure", 107);
2093 }
catch (Exception $e) {
2095 $retVal[
'code'] =
'999';
2096 $retVal[
'error'] = $e->getMessage();
2097 $retVal[
'data'] = Array();