Odyssey
hcuM2MAccts.prg
1 <?php
2  /*
3  * File: hcuM2MAccts.prg
4  *
5  * Purpose: Let the user configure member to member accounts for M2M Transfers. User will set up an M2M
6  * account and activate it. At that point the M2M account can be used by the Transfer feature.
7  *
8  * This feature will be a single screen with dialogs to help enter information.
9  *
10  * This file leverages the External Account logic and will call the hcuExternalAccts.data and hcuExternalAccts.i files.
11  *
12  */
13  require_once(dirname(__FILE__) . '/../library/permissions.i');
14 
15 
16  // ** SET SCRIPT LEVEL VARIABLES
17  $serviceShowInfo = true;
18  $serviceLoadMenu = true;
19  $serviceShowMenu = true;
20 
21  // ** INCLUDE MAIN GLOBAL SCRIPT -- Handles security / global variable values
22  require_once(dirname(__FILE__) . '/../library/hcuService.i');
23  require_once(dirname(__FILE__) . '/../library/hcuExternalAccts.i');
24 
25  // include common functions
26 
27  /********* functions ************/
28  /********* end functions ********/
29 
30 
31  // ** INSERT BUSINESS LOGIC FOR THIS FORM
32  try {
33  $Cu = $HB_ENV["Cu"];
34  $Cn = $HB_ENV["Cn"];
35  $chome = $HB_ENV["chome"];
36  $Flang = $HB_ENV["Flang"];
37 
38  // get initial variables
39  $inputVars = array();
40  $varOk = array(
41  );
42 
43  HCU_ImportVars($inputVars, "", $varOk);
44 
45  // ** INCLUDE PRE CONTENT SCRIPT
46  require_once(dirname(__FILE__) . '/../includes/hcuPreContent.i');
47 
48  // do not allow m2m access if system is not live
49  if ($HB_ENV['live'] == 0) {
50  header ("Location: hcuPermNotice.prg?cu=" . HCU_array_key_value('Cu', $HB_ENV));
51  // ** DO NOT CONTINUE
52  exit;
53  }
54 
55  // make sure the user can be here
56  PermCheckFeatureScreen($dbh, $HB_ENV, $MC, FEATURE_M2M_TRANSFERS, 'create');
57 
58  // ** Verify the feature is enabled for the Credit Union.
59 // unresolves - need to fill out this function (and the one for external accounts)
60  $featureEnabled = Check_M2MTransfersEnabled( $dbh, $HB_ENV );
61  if ( $featureEnabled !== true ) {
62  // * Feature NOT set
63  throw new Exception( HCU_JsonEncode( $MC->msg('Option not set', HCU_DISPLAY_AS_HTML) ), 915 );
64  }
65 
66  // ** Verify the user can access this feature.
67  $permissionInputs = array( "feature" => FEATURE_M2M_TRANSFERS );
68  $accessRights = Perm_AccessRights( $dbh, $HB_ENV, $permissionInputs );
69  if ( !$accessRights["create"] ) {
70  // * Rights NOT set
71  throw new Exception( HCU_JsonEncode( $MC->msg('Rights not set', HCU_DISPLAY_AS_HTML) ), 915 );
72  }
73 
74  // get some allowed amounts for client-side validation
75  $limits = Perm_GetValidationLimits( $dbh, $HB_ENV, $permissionInputs );
76 
77  if ( $limits === false || !isset( $limits["count_per_day"] ) || !isset( $limits["group"]["count_per_day"] ) ) {
78  // error occurred - assume count of zero
79  $allowedCount = 0;
80  } else {
81  $allowedCount = intval( $limits["count_per_day"] );
82  }
83 
84  $Fset = $HB_ENV["Fset"];
85 
86 
87 
88 
89  // ** Retrieve the notice for MEMBER TO MEMBER
90  // ** the user needs to accept these in order to make a
91  // ** transfer using a member to member account.
92  $noticesAry = Get_NoticeInfo($dbh, $HB_ENV, $MC, "D", "m2mAccountNotice", true);
93 
94  $hasNoticeM2M = false;
95  $hasNoticePopupM2M = false;
96  $noticeURLM2M = "";
97  $noticeLinkDisplayM2M = "";
98 
99  if ( $noticesAry["status"]["code"] == "000" && HCU_array_key_exists('0', $noticesAry['notice'])) {
100  if ($noticesAry["notice"][0]["notice_id"] ) {
101  $hasNoticeM2M = true;
102  $noticeLinkDisplayM2M = $noticesAry["notice"][0]["notice_linkdisplay"];
103 
104  $noticeOption = $noticesAry['notice'][0];
105 
106  $noticeOptions = Array (
107  'docsid' => $noticeOption['notice_id'],
108  'docstype' => $noticeOption['notice_type'],
109  'device' => 'D',
110  'noticeOnly' => '0',
111  'expireTime' => mktime() + 86400
112  );
113 
114  $encryptedDocDetails= HCU_PayloadEncode($HB_ENV['Cu'], $noticeOptions);
115 
116  $noticeOptions['noticeOnly'] = 1;
117 
118  $encryptedDocDetailsNoticeOnly= HCU_PayloadEncode($HB_ENV['Cu'], $noticeOptions);
119 
120  // build the url encoded string
121  // * For the popup terms
122  $noticeURLM2M = $HB_ENV['homebankingpath'] . '/hcuViewNotice.prg?cu=' . $HB_ENV['cu'] . '&x=' . urlencode($encryptedDocDetails);
123 
124  // * For the regular Button
125  $noticeURLNoticeOnly = $HB_ENV['homebankingpath'] . '/hcuViewNotice.prg?cu=' . $HB_ENV['cu'] . '&x=' . urlencode($encryptedDocDetailsNoticeOnly);
126 
127  // see if there is a popup notice
128  $hasNoticePopupM2M = $noticeOption["notice_popup"] ? true : false;
129  }
130  }
131 
132  // ** Retrieve the Terms of Use for MEMBER TO MEMBER
133  // ** the user needs to accept these in order to make a
134  // ** transfer using a member to member account.
135  $noticesAry = Get_NoticeInfo($dbh, $HB_ENV, $MC, "D", "m2mAccountTerms", true);
136 
137  $hasTermsM2M = false;
138  $hasTermsPopupM2M = false;
139  $termsURLM2M = "";
140  $termsLinkDisplayM2M = "";
141 
142  if ( $noticesAry["status"]["code"] == "000" && HCU_array_key_exists('0', $noticesAry['notice'])) {
143  if ($noticesAry["notice"][0]["notice_id"] ) {
144  $hasTermsM2M = true;
145  $noticeOption = $noticesAry['notice'][0];
146 
147  $noticeOptions = Array (
148  'docsid' => $noticeOption['notice_id'],
149  'docstype' => $noticeOption['notice_type'],
150  'device' => 'D',
151  'noticeOnly' => '0',
152  'expireTime' => mktime() + 86400
153  );
154 
155  $encryptedDocDetails= HCU_PayloadEncode($HB_ENV['Cu'], $noticeOptions);
156 
157  $noticeOptions['noticeOnly'] = 1;
158 
159  $encryptedDocDetailsNoticeOnly= HCU_PayloadEncode($HB_ENV['Cu'], $noticeOptions);
160 
161  // build the url encoded string
162  // * For the popup terms
163  $termsURLM2M = $HB_ENV['homebankingpath'] . '/hcuViewNotice.prg?cu=' . $HB_ENV['cu'] . '&x=' . urlencode($encryptedDocDetails);
164 
165  // * For the regular Button
166  $termsURLNoticeOnly = $HB_ENV['homebankingpath'] . '/hcuViewNotice.prg?cu=' . $HB_ENV['cu'] . '&x=' . urlencode($encryptedDocDetailsNoticeOnly);
167 
168  // see if there is a popup notice
169  $hasTermsPopupM2M = $noticeOption["notice_popup"] ? true : false;
170 
171  $termsButtonText = $noticeOption["notice_linkdisplay"];
172  }
173  }
174 
175  /*
176  * ** START CONTENT
177  */
178 
179  // list the account types for remote account (for ach) - used in dropdown list
180  $accountTypes = array( array( "type" => ACCOUNT_TYPE_CHECKING, "display" => $MC->msg("ACH Checking", HCU_DISPLAY_AS_HTML) ),
181  array( "type" => ACCOUNT_TYPE_SAVINGS, "display" => $MC->msg("ACH Savings", HCU_DISPLAY_AS_HTML) )
182  );
183 
184  ?>
185  <div class="col-xs-12" style='font-size:12px;'>
186  <div id="hcuAchTables" class="k-content" style="max-width:700px;"></div>
187  <!-- set up the array with status names (these are the same for M2M accounts) -->
188  <?php $statuses = Get_ExternalTransferStatusLookup( $MC ); ?>
189 
190  </div>
191  <script >
192 
193  var extAcctGrid;
194  var achAccountTypes = <?php echo HCU_JsonEncode( $accountTypes ); ?>;
195  var statusLookup = <?php echo HCU_JsonEncode( $statuses ) ?>;
196  var gridList = [];
197  var addAccountModel;
198  var addAccountDialog;
199  var window_stack = [];
200  var detailDialog;
201  var deleteDialog;
202  var dsHelper = null;
203 
204  // check for notices
205  var terms = <?php echo HCU_JsonEncode($hasTermsM2M && $hasTermsPopupM2M); ?>;
206  var notice = <?php echo HCU_JsonEncode($hasNoticeM2M && $hasNoticePopupM2M); ?>;
207 
208  // status will be shown in the default info location
209  function ShowStatus( statusMessage ) {
210  $.homecuValidator.settings.formStatusField = "formStatus";
211  $.homecuValidator.settings.formInfoTitle = "";
212  $.homecuValidator.displayMessage(statusMessage);
213  }
214 
215  function GetM2MAccounts( ) {
216  var request = { action: "get_m2m_accounts" };
217 
218  dsHelper.read( request );
219  }
220 
221  // This is to launch the dialog from a link (for screenreaders).
222  function LaunchValidationDialog( id ) {
223  // find the right entry
224  for ( var i = 0; i < gridList.length; i++ ) {
225  if ( gridList[i].id == id ) {
226  ShowValidationInput( gridList[i] );
227  break;
228  }
229  }
230  } // end LaunchValidationDialog
231 
232  // This is to launch the dialog from a link (for screenreaders).
233  function LaunchUpdateDialog( id ) {
234  // find the right entry
235  for ( var i = 0; i < gridList.length; i++ ) {
236  if ( gridList[i].id == id ) {
237  ShowExtAcctDetail( gridList[i] );
238  break;
239  }
240  }
241  } // end LaunchUpdateDialog
242 
243  // Show the detail of the External Account info.
244  function ShowExtAcctDetail( detailInfo ) {
245  // initialize the observable
246  updateAccountModel.ResetModel();
247  updateAccountModel.set( "extAcctId", detailInfo.id );
248  updateAccountModel.set( "extName", detailInfo.displayName );
249  updateAccountModel.set( "extNameOnAccount", detailInfo.nameOnAccount );
250 
251  var content = "<div id='extAcctUpdate' class='form-horizontal'>" +
252  "<div id='editFormStatus' class='homecu-formStatus k-block k-error-colored' style='display:none; margin-bottom:10px;max-width:800px;'></div>" +
253  "<div class='form-group'>" +
254  "<label class='col-xs-12 col-sm-5' for='extNameUpdate'><?php echo $MC->msg("EXT Display Name", HCU_DISPLAY_AS_JS) ?></label>" +
255  "<div class='col-xs-12 col-sm-7'>" +
256  "<input id='extNameUpdate' \
257  name='extNameUpdate' \
258  maxlength='20' \
259  data-bind='value: extName, events:{change: setDirty}' \
260  placeholder='<?php echo $MC->msg("ACH Required", HCU_DISPLAY_AS_JS) ?>' \
261  type='text' \
262  class='k-textbox k-autocomplete hcu-all-100' \
263  required \
264  validationMessage = '<?php echo $MC->msg("EXT Display Name required", HCU_DISPLAY_AS_JS) ?>' \
265  autocomplete='off' />" +
266  "</div>" +
267  "</div>" +
268  "<div class='form-group'>" +
269  "<label class='col-xs-12 col-sm-5'><?php echo $MC->msg("Status", HCU_DISPLAY_AS_JS) ?></label>" +
270  "<div class='col-xs-12 col-sm-7'>" + detailInfo.statusName + "</div>" +
271  "</div>" +
272  "<div class='form-group'>" +
273  "<label class='col-xs-12 col-sm-5'><?php echo $MC->msg("Account", HCU_DISPLAY_AS_JS) ?></label>" +
274  "<div class='col-xs-12 col-sm-7'>" + detailInfo.account + "</div>" +
275  "</div>" +
276  "<div class='form-group'>" +
277  "<label class='col-xs-12 col-sm-5'><?php echo $MC->msg("Type", HCU_DISPLAY_AS_JS) ?></label>" +
278  "<div class='col-xs-12 col-sm-7'>" + detailInfo.type + "</div>" +
279  "</div>" +
280  "</div>";
281 
282  detailDialog.content(content).open().center();
283 
284  } // end ShowExtAcctDetail
285 
286  // Handle the account info returned from server. Use the status to set up correct string for the link cell.
287  function HandleGetAccounts( accountInfo ) {
288  var hasPending = false;
289  gridList = [];
290 
291  for ( var i = 0; i < accountInfo.length; i++ ) {
292  var remoteInfo = JSON.parse( accountInfo[i].remote_info );
293  var remoteAccount = accountInfo[i]["remoteAccount"];
294 
295  var retries = 0;
296  var verificationStart = "";
297  var linkStr = "<a title='<?php echo $MC->msg("EXT Edit Account Info", HCU_DISPLAY_AS_JS) ?>' href='javascript:LaunchUpdateDialog(" + accountInfo[i].id + ")'><div class='fa fa-pencil text-primary'></div></a>";
298  linkStr += "<span class='hcu-icon-spacer'></span>";
299  if ( accountInfo[i].status == 'a' ) {
300  linkStr += "<div class='fa fa-check text-success'></div>";
301  } else if ( accountInfo[i].status == 'i' ) {
302  linkStr += "<div class='fa fa-ban text-danger'></div>";
303  } else if ( accountInfo[i].status == 'l' ) {
304  // lowercase "L"
305  linkStr += "<div class='fa fa-lock text-danger'></div>";
306  } else {
307  linkStr += "<div class='fa fa-question text-danger'></div>";
308  }
309 
310  var newObject = {
311  id: accountInfo[i].id,
312  userId: accountInfo[i].user_id,
313  displayName: accountInfo[i].display_name,
314  nameOnAccount: accountInfo[i].name_on_account,
315  status: accountInfo[i].status,
316  statusName: statusLookup[accountInfo[i].status],
317  linksStr: linkStr,
318  account: remoteAccount,
319  type: (remoteInfo.rdfi.type == 20 ?
320  "<?php echo $MC->msg("ACH Savings", HCU_DISPLAY_AS_JS) ?>" :
321  "<?php echo $MC->msg("ACH Checking", HCU_DISPLAY_AS_JS) ?>"),
322  retries: retries,
323  pendingDate: verificationStart
324  };
325 
326  gridList.push( newObject );
327 
328  // see if it is a pending
329  if ( accountInfo[i].status == 'p' ) {
330  hasPending = true;
331  }
332 
333  if ( hasPending ) {
334  $("#extValidationMsg").show();
335  } else {
336  $("#extValidationMsg").hide();
337  }
338  }
339 
340  // reset the data in the grid
341  extAcctGrid.dataSource.data(gridList);
342 
343  } // end HandleGetAccounts
344 
345  function HandleUpdateAccount( updateInfo ) {
346  var idUpdated = updateInfo["id"];
347 
348  // remove from the list
349  for ( var i = 0; i < gridList.length; i++ ) {
350  if ( gridList[i].id == idUpdated ) {
351  gridList[i].displayName = updateInfo["display_name"];
352  gridList[i].nameOnAccount = updateInfo["name_on_account"];
353  break;
354  }
355  }
356 
357  // reset the data in the grid
358  extAcctGrid.dataSource.data(gridList);
359 
360  } // end HandleUpdateAccount
361 
362  function HandleDeleteAccount( idToDelete ) {
363  // remove from the list
364  for ( var i = 0; i < gridList.length; i++ ) {
365  if ( gridList[i].id == idToDelete ) {
366  gridList.splice(i, 1);
367  break;
368  }
369  }
370 
371  // reset the data in the grid
372  extAcctGrid.dataSource.data(gridList);
373 
374  } // end HandleDeleteAccount
375 
376  function InitDataSources() {
377  dsHelper = new kendo.data.DataSource({
378  autoSync: false,
379  batch: false,
380  transport: {
381  read: {
382  url: 'hcuExternalAccts.data?cu=<?php echo $HB_ENV['cu']; ?>',
383  dataType: "json",
384  contentType: "application/x-www-form-urlencoded",
385  type: "POST",
386  cache: false
387  }
388  },
389  schema: {
390  parse: function(response) {
391  // not showing data, so return empty array
392  var display = [];
393  return display;
394  }
395  },
396  requestStart: function( e ) {
397  ShowWaitWindow();
398  },
399  requestEnd: function( e ) {
400  var error = null;
401  var results = null;
402 
403  CloseWaitWindow();
404 
405  if ( e.response && e.response.Results ) {
406  results = e.response.Results;
407 
408  // see if there is an error
409  if ( results && results.homecuErrors )
410  error = results.homecuErrors;
411 
412  if ( error && error.length > 0 ) {
413  e.preventDefault();
414  // make sure only old data
415  dsHelper.cancelChanges();
416  // show the error information
417  $.homecuValidator.displayMessage(error, $.homecuValidator.settings.statusError);
418  } else {
419 
420  if ( results && results.homecuInfo && (results.homecuInfo.length > 0) ) {
421  ShowStatus( results.homecuInfo );
422  }
423 
424  // handle any returned data
425  if ( results && results.homecuData ) {
426  if ( results.homecuData.get_m2m_accounts ) {
427  HandleGetAccounts( results.homecuData.get_m2m_accounts);
428  } else if ( results.homecuData.add_m2m_account ) {
429  // close the window
430  addAccountDialog.close();
431 
432  // reset the default error form
433  $.homecuValidator.settings.formStatusField = "formStatus";
434 
435  // the same data gets returns as "get_m2m_accounts" if successful
436  HandleGetAccounts( results.homecuData.add_m2m_account );
437  } else if ( results.homecuData.update_account ) {
438  // close the window
439  detailDialog.close();
440 
441  // reset the default error form
442  $.homecuValidator.settings.formStatusField = "formStatus";
443 
444  // the same data gets returns as "get_accounts" if successful
445  HandleUpdateAccount( results.homecuData.update_account );
446  } else if ( results.homecuData.delete_account ) {
447  // close the window
448  detailDialog.close();
449 
450  // reset the default error form
451  $.homecuValidator.settings.formStatusField = "formStatus";
452 
453  // the same data gets returns as "get_accounts" if successful
454  HandleDeleteAccount( results.homecuData.delete_account );
455  }
456 
457  }
458  }
459  } else {
460  error = "<?php echo $MC->msg("Transport error", HCU_DISPLAY_AS_JS) ?>";
461  $.homecuValidator.displayMessage(error, $.homecuValidator.settings.statusError);
462  }
463  },
464 
465  // code to run if the request fails; the raw request and
466  // status codes are passed to the function
467  error: function( e ) {
468  }
469  });
470  }
471 
472  function InitDataViews() {
473  addAccountModel = kendo.observable({
474  extName: "",
475  extNameOnAccount: "",
476  extDFIAccount: "",
477  extDFIConfirm: "",
478  extDFISelectedType: "",
479  dirtyFlag: false,
480  ResetModel: function () {
481  this.set( "extName", "" );
482  this.set( "extNameOnAccount", "" );
483  this.set( "extDFIAccount", "" );
484  this.set( "extDFIConfirm", "" );
485  this.set( "extDFISelectedType", "" );
486  this.set( "dirtyFlag", false );
487  },
488  setDirty: function(e) {
489  this.set( "dirtyFlag", true );
490  },
491  SendToServer: function () {
492  var action = "add_m2m_account";
493  var request = {
494  action: action,
495  display_name: this.extName,
496  name_on_account: this.extNameOnAccount,
497  dfi_account: this.extDFIAccount,
498  dfi_account_type: this.extDFISelectedType
499  };
500 
501  dsHelper.read( request );
502  }
503  });
504 
505  updateAccountModel = kendo.observable({
506  extAcctId: 0,
507  extName: "",
508  extNameOnAccount: "",
509  retries: 0, // read-only, for verfication step
510  pendingDate: "", // read-only, for verfication step
511  dirtyFlag: false,
512  ResetModel: function () {
513  this.set( "extAcctId", 0 );
514  this.set( "extName", "" );
515  this.set( "extNameOnAccount", "" );
516  this.set( "dirtyFlag", false );
517  },
518  setDirty: function(e) {
519  this.set( "dirtyFlag", true );
520  },
521  SendToServer: function () {
522  var action = "update_account";
523  var request = {
524  action: action,
525  id: this.extAcctId,
526  display_name: this.extName,
527  name_on_account: this.extNameOnAccount
528  };
529 
530  dsHelper.read( request );
531  }
532  });
533 
534  // set up an error validator in case of an error
535  $.homecuValidator.setup({formErrorTitle: "<?php echo $MC->msg("Error Occurred", HCU_DISPLAY_AS_JS) ?>"});
536 
537  extAcctGrid = $('#extAcctGrid').kendoGrid({
538  dataSource: gridList,
539  autoBind: true,
540  selectable: "cell",
541  scrollable: true,
542  toolbar: kendo.template($("#gridToolbar").html()),
543  noRecords: {template: "<span class='hcu-secondary-text'><?php echo $MC->msg("EXT No Accounts", HCU_DISPLAY_AS_JS) ?></span>"},
544  columns: [
545  { field: "status",
546  title: " ",
547  template: "#= data.linksStr #",
548  width: 65 },
549  { field: "displayName",
550  title: "<?php echo $MC->msg("Name", HCU_DISPLAY_AS_JS) ?>" },
551  { field: "statusName",
552  title: "<?php echo $MC->msg("Status", HCU_DISPLAY_AS_JS) ?>",
553  width: 160,
554  minScreenWidth: 567 },
555  { field: "account",
556  title: "<?php echo $MC->msg("ACH Account Info", HCU_DISPLAY_AS_JS) ?>",
557  minScreenWidth: 374 }
558  ],
559  change: function(e) {
560  e.preventDefault();
561  $.homecuValidator.displayMessage( "" );
562 
563  var selectedCell = this.select();
564  var selectedRow = selectedCell.closest("tr");
565  var cellIndex = selectedCell.index();
566 
567  // get the values
568  var currSelectedItem = extAcctGrid.dataItem(selectedRow);
569 
570  if ( cellIndex >= 1 ) {
571  ShowExtAcctDetail( currSelectedItem );
572  }
573 
574  selectedCell.removeClass( "k-state-selected" );
575  }
576  }).data('kendoGrid');
577 
578  var maxHeight = parseInt($(window).height() * .9, 10);
579  var widthDialog = parseInt($(window).width() * .8, 10);
580  var addAccountTemplate = $("#addAccountTemplate").html();
581  addAccountDialog = $(addAccountTemplate).kendoDialog({
582  visible: false,
583  maxHeight: maxHeight,
584  width: widthDialog,
585  maxWidth: 700,
586  title: "<?php echo $MC->msg("ACH Account Info", HCU_DISPLAY_AS_JS) ?>",
587  show: function() {
588  // add the close function to the window stack
589  window_stack.push(function(e) {
590  if ( addAccountModel.dirtyFlag ) {
591  discardDialog.open();
592  } else {
593  addAccountDialog.close(e);
594  }
595  });
596 
597  // clean out any existing data
598  addAccountModel.ResetModel();
599 
600  // need to strip out something Kendo added
601  $('#addAccountDialog').css('overflow', '');
602 
603  // add the dropdown
604  $("#achAccountType").kendoDropDownList({
605  dataTextField: "display",
606  dataValueField: "type",
607  dataSource: achAccountTypes,
608  optionLabel: {type: "", display: "<?php echo $MC->msg("ACH Select Type", HCU_DISPLAY_AS_JS) ?>"},
609  });
610 
611  // bind the add model to the template
612  kendo.bind($("#addAccountDialog"), addAccountModel);
613 
614  // set the form status so validation errors show on the form
615  $.homecuValidator.setup({formValidate: "addAccountDialog", formStatusField: 'addFormStatus'});
616  },
617  close: function(e) {
618  // now remove the close function call
619  window_stack.pop();
620  },
621  actions: [
622  { text: "<?php echo $MC->msg('Cancel', HCU_DISPLAY_AS_JS); ?>",
623  action: function(e){
624  if ( addAccountModel.dirtyFlag ) {
625  discardDialog.open();
626  return false;
627  } else {
628  return true;
629  }
630  }
631  },
632  {
633  text: "<?php echo $MC->msg('Save', HCU_DISPLAY_AS_JS); ?>",
634  action: function(e){
635  $.homecuValidator.setup( {formValidate: "addAccountDialog", formStatusField: 'addFormStatus'} );
636  if ( $.homecuValidator.validate() ) {
637  // also check other things
638  var otherErrors = Array();
639  if ( addAccountModel.extDFIAccount.length < 1 ) {
640  // get the validation message from the component
641  otherErrors.push( $("#singleRecipientAccount").attr( "validationMessage" ) );
642  }
643  if ( addAccountModel.extDFIAccount !== addAccountModel.extDFIConfirm ) {
644  // get the validation message from the component
645  otherErrors.push( $("#singleRecipientConfirm").attr( "data-homecuCustomEquals-msg" ) );
646  }
647  if ( addAccountModel.extDFISelectedType === "" ) {
648  // get the validation message from the component
649  otherErrors.push( $("#achAccountType").attr( "validationMessage" ) );
650  }
651 
652  if (otherErrors.length > 0) {
653  $.homecuValidator.displayMessage(otherErrors, $.homecuValidator.settings.statusError);
654  } else {
655  // set up to report to the dialog's form
656  $.homecuValidator.settings.formStatusField = "addFormStatus";
657 
658  if ( addAccountModel.dirtyFlag ) {
659  // send update to server
660  addAccountModel.SendToServer();
661 
662  // don't close, in case an error is returned
663  return false;
664  } else {
665  return true;
666  }
667  }
668  }
669 
670  return false;
671  },
672  primary: true
673  }]
674  }).data("kendoDialog");
675 
676  var maxHeight = parseInt($(window).height() * .9, 10);
677  detailDialog = $("#detailDialog").kendoDialog({
678  visible: false,
679  title: "<?php echo $MC->msg("ACH Account Info", HCU_DISPLAY_AS_JS) ?>",
680  content: "<span class='hcu-secondary-text'><?php echo $MC->msg("Loading Data", HCU_DISPLAY_AS_JS) ?></span>",
681  maxHeight: maxHeight,
682  maxWidth: 700,
683  open: function(e) {
684  },
685  show: function(e) {
686  // add the close function to the window stack
687  window_stack.push(function(e) {
688  if ( updateAccountModel.dirtyFlag ) {
689  discardDialog.open();
690  } else {
691  detailDialog.close(e);
692  }
693  });
694 
695  // validation
696  $.homecuValidator.setup( {formStatusField: "editFormStatus", formValidate: "extAcctUpdate"} );
697 
698  // now that the dialog is visible, bind to the view model
699  kendo.bind($("#extAcctUpdate"), updateAccountModel);
700 
701  // start with no focus
702  $("#extNameUpdate").blur();
703  },
704  close: function(e) {
705  // now remove the close function call
706  window_stack.pop();
707  },
708  actions: [
709  {
710  text: "<?php echo $MC->msg("Delete", HCU_DISPLAY_AS_JS) ?>",
711  action: function(e) {
712  deleteDialog.open();
713  return false;
714  }
715  },
716  {
717  text: "<?php echo $MC->msg("Cancel", HCU_DISPLAY_AS_JS) ?>",
718  action: function(e){
719  if ( updateAccountModel.dirtyFlag ) {
720  discardDialog.open();
721  return false;
722  }
723  }
724  },
725  {
726  text: "<?php echo $MC->msg("Save", HCU_DISPLAY_AS_JS) ?>",
727  action: function(e){
728  // validate the name
729  if ( $.homecuValidator.validate() ) {
730  if ( updateAccountModel.dirtyFlag ) {
731  // update the names
732  updateAccountModel.SendToServer();
733 
734  // keep the window open in case of error
735  return false;
736  }
737  return true;
738  }
739  return false;
740  },
741  primary: true
742  }]
743  }).data("kendoDialog");
744 
745  deleteDialog = $("#deleteDialog").kendoDialog({
746  visible: false,
747  title: "<?php echo $MC->msg("Delete", HCU_DISPLAY_AS_JS) ?>",
748  content: "<p><?php echo $MC->msg("EXT Continue delete", HCU_DISPLAY_AS_JS) ?></p><p><?php echo $MC->msg("ACH Continue", HCU_DISPLAY_AS_JS) ?></p>",
749  show: function(e) {
750  // add the close function to the window stack
751  window_stack.push(function(e) {
752  deleteDialog.close(e);
753  });
754  },
755  close: function(e) {
756  // remove the close function from the window stack
757  window_stack.pop();
758  },
759  actions: [{text: "<?php echo $MC->msg("No", HCU_DISPLAY_AS_JS) ?>"},
760  {
761  text: "<?php echo $MC->msg("Yes", HCU_DISPLAY_AS_JS) ?>",
762  action: function(e){
763  var request = { action: "delete_account",
764  id: updateAccountModel.extAcctId };
765 
766  dsHelper.read( request );
767 
768  // Returning false will prevent the closing of the dialog
769  return true;
770  },
771  primary: true
772  }]
773  }).data("kendoDialog");
774 
775  GetM2MAccounts();
776 
777  discardDialog = $("#discardDialog").kendoDialog({
778  visible: false,
779  title: "<?php echo $MC->msg("ACH Discard Changes?", HCU_DISPLAY_AS_JS) ?>",
780  content: "<p><?php echo $MC->msg("ACH Discard changes warning", HCU_DISPLAY_AS_JS) ?></p><p><?php echo $MC->msg("ACH Continue", HCU_DISPLAY_AS_JS) ?></p>",
781  show: function(e) {
782  // add the close function to the window stack
783  window_stack.push(function(e) {
784  discardDialog.close(e);
785  });
786  },
787  close: function(e) {
788  // remove the close function from the window stack
789  window_stack.pop();
790  },
791  actions: [{
792  text: "<?php echo $MC->msg("No", HCU_DISPLAY_AS_JS) ?>",
793  action: function(e) {
794  // ** Close the current dialog
795  }
796  }, {
797  text: "<?php echo $MC->msg("Yes", HCU_DISPLAY_AS_JS) ?>",
798  primary: true,
799  action: function(e) {
800  // clear any dirty flags
801  addAccountModel.ResetModel();
802  updateAccountModel.ResetModel();
803 
804  // remove this dialog's close
805  window_stack.pop();
806 
807  /* ** DISCARD CHANGES by calling prior window's close ** */
808  var fn = window_stack[window_stack.length - 1];
809  var ret = fn(e);
810  }
811  }]
812  }).data("kendoDialog");
813  }
814 
815  function InitScreen() {
816  InitDataSources();
817  InitDataViews();
818 
819  // initialize then show
820  $("#ach-payment").show();
821  }
822 
823  $(document).ready(function() {
824  if (terms) {
825  ShowNotice('<?php echo $termsURLM2M; ?>', "<?php echo $termsLinkDisplayM2M ?>",
826  function() {
827  InitScreen();
828  if (notice) {
829  ShowNotice('<?php echo $noticeURLM2M; ?>', "<?php echo $noticeLinkDisplayM2M ?>");
830  }
831  },
832  function() {
833  // if they do not accept, send them to banking accounts screen
834  ShowWaitWindow();
835 
836  var urlInit = window.location.href.substring(0, window.location.href.indexOf("hcu"));
837  var urlCu = "<?php echo $Cu ?>";
838  var urlPage = "hcuAccounts.prg";
839  var urlRedirect = urlInit + urlPage + "?cu=" + urlCu;
840 
841  window.location.replace(urlRedirect);
842  }
843  );
844  } else if (notice) {
845  InitScreen();
846  ShowNotice('<?php echo $noticeURLM2M; ?>', "<?php echo $noticeLinkDisplayM2M ?>");
847  } else {
848  InitScreen();
849  }
850  }); // end ready function
851 
852  // Handle clicking on the overlay
853  $(document).on("click", ".k-overlay", function (e) {
854  if(window_stack.length > 0) {
855  // get the close function from the stack, without poping it (the close will pop it)
856  var fn = window_stack[window_stack.length - 1];
857  var ret = fn(e);
858  }
859  });
860 
861  </script>
862  <script id="gridToolbar" type="text/x-kendo-template">
863  <a class="k-button" href="\#" onclick="return addAccountDialog.open()"><span class="fa fa-plus"></span>&nbsp; <?php echo $MC->msg("EXT Add Account", HCU_DISPLAY_AS_JS) ?></a>
864  </script>
865  <script id="addAccountTemplate" type="text/x-kendo-template">
866  <div id="addAccountDialog" class="container-fluid hcu-scrolling-dialog">
867  <div id="addFormStatus" class="homecu-formStatus k-block k-error-colored" style="display:none; margin-bottom:10px;max-width:800px;"></div>
868  <div class="form-horizontal">
869  <div class="form-group">
870  <div class="col-xs-12 hcu-secondary-text">&nbsp;<?php echo $MC->msg("EXT All Required", HCU_DISPLAY_AS_HTML); ?></div>
871  </div>
872  <div class="form-group">
873  <label for="singleDisplayName" class="col-xs-12 col-sm-4 control-label"><?php echo $MC->msg("ACH Display Name", HCU_DISPLAY_AS_HTML) ?></label>
874  <div class="col-xs-12 col-sm-6">
875  <input type="text"
876  id="singleDisplayName"
877  name=singleDisplayName"
878  class="k-textbox hcu-all-100"
879  maxlength="20"
880  data-bind="value: extName, events:{change: setDirty}"
881  validationMessage="<?php echo $MC->msg("ACH Unique display name required", HCU_DISPLAY_AS_HTML) ?>"
882  required />
883  </div>
884  </div>
885  <div class="form-group">
886  <div class="col-xs-12 h4">&nbsp;<?php echo $MC->msg("ACH Remote Account", HCU_DISPLAY_AS_HTML); ?></div>
887  </div>
888  <div class="form-group">
889  <label for="extNameOnAccount" class="col-xs-12 col-sm-4 control-label"><?php echo $MC->msg("M2M Last Name", HCU_DISPLAY_AS_HTML); ?><span class="required-field"></label>
890  <div class="col-xs-12 col-sm-6"><input id="extNameOnAccount"
891  name="extNameOnAccount"
892  class="k-textbox hcu-all-100"
893  maxlength="30"
894  data-bind="value: extNameOnAccount, events:{change: setDirty}"
895  validationMessage="<?php echo $MC->msg("M2M Last Name Required", HCU_DISPLAY_AS_HTML); ?>"
896  required /></div>
897  </div>
898  <div class="form-group">
899  <label for="singleRecipientAccount" class="col-xs-12 col-sm-4 control-label"><?php echo $MC->msg("ACH Account", HCU_DISPLAY_AS_HTML) ?></label>
900  <div class="col-xs-12 col-sm-6"><input type="text"
901  name="singleRecipientAccount"
902  id="singleRecipientAccount"
903  class="k-textbox hcu-all-100 account-match"
904  maxlength="20"
905  data-bind="value: extDFIAccount, events:{change: setDirty}"
906  validationMessage="<?php echo $MC->msg('Account Number Missing', HCU_DISPLAY_AS_HTML); ?>"
907  required /></div>
908  </div>
909  <div class="form-group">
910  <label for="singleRecipientAccountConfirm" class="col-xs-12 col-sm-4 control-label"><?php echo $MC->msg('ACH Confirm Account', HCU_DISPLAY_AS_HTML); ?></label>
911  <div class="col-xs-12 col-sm-6"><input type="text"
912  id="singleRecipientConfirm"
913  name="singleRecipientConfirm"
914  class="k-textbox hcu-all-100 account-match"
915  maxlength="20"
916  homecu-equals="account-match"
917  data-homecuCustomEquals-msg="<?php echo $MC->msg('ACH Accounts no match', HCU_DISPLAY_AS_HTML); ?>"
918  data-bind="value: extDFIConfirm, events:{change: setDirty}"
919  validationMessage="<?php echo $MC->msg('Account Number Missing', HCU_DISPLAY_AS_HTML); ?>"
920  required /></div>
921  </div>
922  <div class="form-group">
923  <label for="achAccountType" class="col-xs-12 col-sm-4 control-label"><?php echo $MC->msg('Account Type', HCU_DISPLAY_AS_HTML); ?></label>
924  <div class="col-xs-12 col-sm-5"><input id="achAccountType"
925  name="achAccountType"
926  class="hcu-all-100"
927  data-bind="value: extDFISelectedType, events:{change: setDirty}"
928  validationMessage="<?php echo $MC->msg('Account Type Missing', HCU_DISPLAY_AS_HTML) ?>"
929  required /></div>
930  </div>
931  </div>
932  </script>
933  <div id="disclosureWindow" name="disclosureWindow"></div>
934  <div id="discardDialog"></div>
935  <style type="text/css">
936  .hcu-scrolling-dialog {
937  overflow-y: auto;
938  }
939  .k-grid-content {
940  max-height: 400px;
941  }
942  .account-rows .k-grid-content tr td {
943  border-left-width: 0;
944  }
945  .k-grid .k-grid-content tr:hover {
946  cursor: pointer;
947  }
948  .leading-zero-fontsize {
949  font-size: 1.8em;
950  }
951  .local-align-leading-zero {
952  text-align: right;
953  padding-top:5px;
954  }
955  .hcu-icon-spacer {
956  margin-right: 20px;
957  }
958 
959  /* Small devices @screen-sm-min (tablets, 768px and up) */
960  @media (min-width: 768px) {
961  }
962 
963  /* Medium devices @screen-md-min (desktops, 992px and up) */
964  @media (min-width: 992px) {
965  }
966  </style>
967  <div id="detailDialog"></div>
968  <div id="deleteDialog"></div>
969  <div class="k-content col-xs-12" id="ach-payment" style="max-width:700px; display: none;">
970  <div class="form-horizontal">
971  <div class="well well-sm">
972  <div class="form-group">
973  <div class="col-xs-12 h4"><?php echo $MC->msg('M2M Accounts', HCU_DISPLAY_AS_HTML) ?></div>
974  </div>
975  <div class="form-group">
976  <div class="col-xs-12 "><div class="account-rows" id="extAcctGrid"></div></div>
977  </div>
978  </div>
979  </div>
980  </div>
981 
982  <?php
983  } catch (Exception $ex) {
984  // * Include the Error page and then end the content
985  // NOTE: this is for when the page is first loading
986  $serviceErrorMsg = HCU_JsonDecode($ex->getMessage());
987 
988  $serviceErrorCode = $ex->getCode(); // this chooses which error page to show
989 
990  require_once(dirname(__FILE__) . '/../includes/hcuErrorPage.i');
991  }
992  /*
993  * ** END CONTENT
994  */
995 
996 
997  // ** INCLUDE POST CONTENT SCRIPT
998  require_once(dirname(__FILE__) . '/../includes/hcuPostContent.i');
999