Odyssey
hcuMRDCDeposit.prg
1 <?php
2  /*
3  * File: hcuMRDCDeposit.prg
4  *
5  * Purpose: This script will let the user select the account, enter the amount, and
6  * interact with the apps to capture both front and back images of the check.
7  * A thumbnail of the image will be shown.
8  *
9  * This script is part of Pegasus and is intended to be invoked by the app.
10  *
11  */
12 
13  // ** SET SCRIPT LEVEL VARIABLES
14  $serviceShowInfo = true;
15  $serviceLiveCheck = true;
16  // ** INCLUDE MAIN GLOBAL SCRIPT -- Handles security / global variable values
17  require_once(dirname(__FILE__) . '/../library/hcuService.i');
18 
19  require_once(dirname(__FILE__) . '../../../shared/library/cutrusted.i');
20  /*
21  * ** CHECK USER FEATURE PERMISSIONS **
22  * NOTE: DOES NOT RETURN ON FAILURE
23  */
24 
25  PermCheckFeatureScreen($dbh, $HB_ENV, $MC, FEATURE_MOBILE_RDC);
26 
27  // ** INSERT BUSINESS LOGIC FOR THIS FORM
28  $inputVars = array();
29  $varOk = array("rdc_token"=>"string");
30  HCU_ImportVars( $inputVars, "", $varOk );
31 
32  // extract the encrypted stuff
33  if ( strpos( $inputVars['rdc_token'], "=" ) !== false ||
34  strpos( $inputVars['rdc_token'], "+" ) !== false ) {
35  // already decoded
36  $decodedToken = $inputVars['rdc_token'];
37  $encodedToken = urlencode( $inputVars['rdc_token'] );
38  } else {
39  $encodedToken = $inputVars['rdc_token'];
40  $decodedToken = urldecode( $inputVars['rdc_token'] );
41  }
42 
43  $commonString = hcu_decrypturl( $decodedToken, $HB_ENV['2factorkey']);
44 
45  parse_str( $commonString, $commonParms );
46 
47  $rdcVendorKey = $commonParms["rdcVendor"];
48  $rdcAccount = $commonParms["rdcAccount"];
49  $rdcDepositId = $commonParms["rdcDepositId"];
50  $rdcEndorse = $commonParms["rdcEndorse"];
51 
52  // make sure got required inputs
53  if ( (strlen($rdcVendorKey) == 0) || (strlen($rdcAccount) == 0) || (strlen($rdcDepositId) == 0) ) {
54  // no token or bad token
55  // show error message
56  $serviceErrorMsg = $MC->msg('Feature Not Set', HCU_DISPLAY_AS_HTML);
57  $serviceErrorCode = '915';
58  require_once(dirname(__FILE__) . '/../includes/hcuErrorPage.i');
59  // ** DO NOT CONTINUE
60  exit;
61  }
62 
63  // build up the parameters for the front and back thumnail to send to the (appropriate) app
64  $frontParameters = array( "depositId" => $rdcDepositId, "mbracct" => $rdcAccount, "thumbId" => "frontThumb" );
65  $parametersJSON = HCU_JsonEncode( $frontParameters );
66  $captureFrontParameters = urlencode( $parametersJSON );
67 
68  $backParameters = array( "depositId" => $rdcDepositId, "mbracct" => $rdcAccount, "thumbId" => "backThumb", "rdcEndorse" => $rdcEndorse );
69  $parametersJSON = HCU_JsonEncode( $backParameters );
70  $captureBackParameters = urlencode( $parametersJSON );
71 
72  //this is the header and side menu
73  // ** INCLUDE PRE CONTENT SCRIPT
74  require_once(dirname(__FILE__) . '/../includes/hcuPreContent.i');
75 ?>
76 <!-- kendo mobile -->
77 <style>
78 .btn-group-wrap {
79  text-align: center;
80 }
81 
82 .btn-group {
83  text-align: center;
84 }
85 
86 .k-radio-label {
87  padding-bottom: .5em;
88  font-weight: normal;
89 }
90 
91 h6 {
92  font-weight: bold;
93  padding-bottom: .5em;
94 }
95 
96 </style>
97  <div id="confirmationWindow"></div>
98  <div id="confirmationWindowRetry"></div>
99  <div id="confirmSaveTemplate"></div>
100  <!-- Edit Payment -->
101  <div id="depositWindow" name="depositWindow" class="container-fluid"><!-- DISPLAY NONE -->
102  <div class="row" style="margin: 10px 0px 10px 0px;">
103  <span class="hcu-breadcrumbs"><a href='hcuMRDC.prg?rdc_token=<?php echo $encodedToken ?>&<?php echo $HB_ENV['cuquery'] ?>' class="tabReturnBtn"><?php echo $MC->msg("Menu", HCU_DISPLAY_AS_HTML) ?></a> / <span class="realname"><?php echo $MC->msg("New Deposit", HCU_DISPLAY_AS_HTML) ?></span></span>
104  </div>
105  <div class="row">
106  <div class="k-content col-xs-12 " style="max-width: 600px;">
107  <div id="depositFormStatus" class="homecu-formStatus k-block k-error-colored" style="display:none; margin-bottom:10px;max-width:800px;"></div>
108  <div class="form-horizontal form-widgets well well-sm">
109  <!-- from ACCOUNT -->
110  <div class="form-group">
111  <div class="">
112  <label class="col-sm-12" for="toAcct" id="editToAcct"><?php echo $MC->msg("Account", HCU_DISPLAY_AS_HTML)?>
113  </label>
114  <div class="col-sm-12">
115  <input id='toAcct' class='distinctAcct hcu-all-100' name='toAcct'
116  data-role='dropdownlist'
117  data-bind='value: rdcToId, events:{change: setDirty}'
118  data-required-msg="<?php echo $MC->msg("Account is required", HCU_DISPLAY_AS_HTML)?>"
119  required />
120  </div>
121  </div>
122  </div>
123  <!-- AMOUNT -->
124  <div class="form-group">
125  <div class="">
126  <label class="col-sm-12" for="depositAmount"><?php echo $MC->msg('Amount', HCU_DISPLAY_AS_HTML); ?>
127  <span class="hcu-required-field"><sup>*</sup></span></label>
128  <div class="col-sm-12">
129  <input type="number" id="depositAmount" name="depositAmount" class="hcu-all-100"
130  placeholder="<?php echo $MC->msg('Amount', HCU_DISPLAY_AS_HTML); ?>"
131  data-bind="value: rdcAmt, events:{change: setDirty}"
132  data-required-msg="<?php echo $MC->msg('Amount Missing', HCU_DISPLAY_AS_HTML); ?>"
133  required />
134  </div>
135  </div>
136  </div>
137  <!-- Check Image Front -->
138  <div class="form-group">
139  <div class="">
140  <label class="col-sm-12"><?php echo $MC->msg('Front', HCU_DISPLAY_AS_HTML); ?>
141  </label>
142  <div class="col-sm-12" id="frontImageContainer">
143  <input type="button" value="Front Image" onClick="captureCheck('CAPTURE_IMAGE_FRONT', '<?php echo $captureFrontParameters ?>')" style="margin:10px;" />
144 
145  <img id="frontThumb" style="visibility: visible; height:70px;" />
146  </div>
147  </div>
148  </div>
149  <!-- Check Image Back -->
150  <div class="form-group">
151  <div class="">
152  <label class="col-sm-12"><?php echo $MC->msg('Back', HCU_DISPLAY_AS_HTML); ?>
153  </label>
154  <div class="col-sm-12" id="backImageContainer">
155  <input type="button" value="Back Image" onClick="captureCheck('CAPTURE_IMAGE_BACK', '<?php echo $captureBackParameters ?>')" style="margin:10px;" />
156 
157  <img id="backThumb" style="visibility: visible; height:70px;" />
158  </div>
159  </div>
160  </div>
161  <!-- ACTION BUTTONS -->
162  <div class="hcu-template">
163  <div class="hcu-edit-buttons k-state-default">
164  <a href="hcuMRDC.prg?rdc_token=<?php echo $encodedToken ?>&<?php echo $HB_ENV['cuquery'] ?>" id="lnkCancel" style=""><?php echo $MC->msg("Cancel", HCU_DISPLAY_AS_HTML)?></a>
165  &emsp;
166  <a href="##" id="btnMakeDeposit" class="k-button k-primary">
167  <i class="fa fa-check fa-lg"></i><?php echo $MC->msg("Online Deposits Button Finish Deposit", HCU_DISPLAY_AS_HTML)?>
168  </a>
169  </div>
170  </div>
171  </div>
172  </div>
173  </div>
174  <script id="confirmationTemplate" type="text/x-kendo-tmpl">
175  <div id="confirmationStatus"></div>
176  <div id="responseDiv">
177  <div class="local-transfer-msg">#= data['message'] #</div>
178  </div>
179  </script>
180 <script>
181 var windowStack = [];
182 var dataDepAccts = [];
183 var dsGetAccounts = [];
184 var dsGetDepAccts = [];
185 
186 var confirmSaveDialog;
187 
188 var depositModel;
189 var processDates;
190 
191 function InitDataSources() {
192 
193  dsGetDepAccts = new kendo.data.DataSource ({
194  data: dataDepAccts
195  });
196 
197  //pulling user account information
198  dsGetAccounts = new kendo.data.DataSource ({
199  transport: {
200  read: {
201  url: "hcuMRDC.data?cu=<?php echo $HB_ENV['cu']; ?>&rdc_token=<?php echo $encodedToken ?>&rdc_type=Accounts&<?php echo $HB_ENV['cuquery'] ?>",
202  contentType: 'application/x-www-form-urlencoded',
203  type: 'POST',
204  data: {},
205  pageable: true,
206  cache: false
207  }
208  },
209  requestStart: function( e ) {
210  ShowWaitWindow();
211  },
212  requestEnd: function( e ) {
213  CloseWaitWindow();
214  var error = null;
215  // see if there is an error
216  if ( e.response && e.response.homecuErrors )
217  error = e.response.homecuErrors;
218  if ( error && error.length > 0 ) {
219  e.preventDefault();
220  $.homecuValidator.displayMessage(error, $.homecuValidator.settings.statusError);
221  } else {
222  // not sure
223  }
224  },
225  // code to run if the request fails; the raw request and
226  // status codes are passed to the function
227  error: function( e ) {
228  alert( "Transport error" );
229  },
230  schema: {
231  data: function (response) {
232  /* PARSE RESPONSE DATA */
233  var returnData = Array();
234  try {
235  if (response.homecuData) {
236  //Get Deposit Accounts List
237  dataDepAccts = (response.homecuData ? response.homecuData : []);
238  dsGetDepAccts.data(dataDepAccts);
239 
240  // var saveValue = "Add " + mpType;
241  // $("#btnAddPayment").text(saveValue);
242  returnData = response.homecuData;
243  } else if (response.homecuErrors) {
244  //error has been handled
245  } else {
246  throw "Error Parsing Accounts From Server";
247  }
248  } catch (err) {
249  // ** Need to report the message to the main screen
250  /* *** REPORT THE ERROR *** */
251  alert(err);
252  returnData = [];
253  }
254  return [response];
255  },
256  }
257  });
258 
259  $("#toAcct").kendoDropDownList({
260  optionLabel: "<?php echo $MC->msg("ACH Select Account", HCU_DISPLAY_AS_JS) ?>",
261  dataSource: dsGetDepAccts,
262  dataTextField: "Name",
263  dataValueField: "FromId",
264  });
265 
266 }
267 
268 // Confirmation dialogs - different actions based on the different possible statuses
269 $("#confirmationWindow").kendoDialog({
270  title: "<?php echo $MC->msg('Unknown', HCU_DISPLAY_AS_JS); ?>", // default title
271  width: "85%",
272  maxWidth: "768px",
273  minWidth: "300px",
274  modal: true,
275  closable: false,
276  visible: false,
277  resizable: false,
278  actions: [
279  {
280  text: "<?php echo $MC->msg('Return to Menu', HCU_DISPLAY_AS_JS); ?>",
281  primary: false,
282  action: function(e) {
283  // close and return to the menu
284  window.location = 'hcuMRDC.prg?<?php echo $HB_ENV['cuquery'] ?>&rdc_token=<?php echo $encodedToken ?>';
285 
286  return true;
287  }
288  },
289  {
290  text: "<?php echo $MC->msg('Start New Deposit', HCU_DISPLAY_AS_JS); ?>",
291  primary: true
292  }
293  ],
294  show: function(e) {
295  windowStack.push(this);
296  },
297  close: function(e) {
298  windowStack.pop();
299 
300  // Reset validator to use page status field.
301  $.homecuValidator.settings.formStatusField = "formStatus";
302  $.homecuValidator.settings.formInfoTitle = "";
303  }
304  });
305 
306 $("#confirmationWindowRetry").kendoDialog({
307  title: "<?php echo $MC->msg('Unknown', HCU_DISPLAY_AS_JS); ?>", // default title
308  width: "85%",
309  maxWidth: "768px",
310  minWidth: "300px",
311  modal: true,
312  closable: false,
313  visible: false,
314  resizable: false,
315  actions: [
316  {
317  text: "<?php echo $MC->msg('Retry', HCU_DISPLAY_AS_JS); ?>",
318  primary: false,
319  action: function(e) {
320  // close and stay on the page
321  return true;
322  }
323  },
324  {
325  text: "<?php echo $MC->msg('Start New Deposit', HCU_DISPLAY_AS_JS); ?>",
326  primary: true,
327  action: function(e) {
328  // close and return to the menu
329  window.location = 'hcuMRDC.prg?<?php echo $HB_ENV['cuquery'] ?>&rdc_token=<?php echo $encodedToken ?>';
330 
331  return true;
332  }
333  }
334  ],
335  show: function(e) {
336  windowStack.push(this);
337  },
338  close: function(e) {
339  windowStack.pop();
340 
341  // Reset validator to use page status field.
342  $.homecuValidator.settings.formStatusField = "formStatus";
343  $.homecuValidator.settings.formInfoTitle = "";
344  }
345  });
346 
347 // this is used to make the deposit
348 depositModel = kendo.observable({
349  rdcDepositId: "",
350  rdcToId: "",
351  rdcAmt: "",
352  dirtyFlag: false,
353  setDirty: function(e) {
354  this.set( "dirtyFlag", true );
355  },
356  Save: function() {
357  dsDeposit.options.transport.read.data.depositid = this.rdcDepositId;
358  dsDeposit.options.transport.read.data.toid = this.rdcToId;
359  dsDeposit.options.transport.read.data.amount = this.rdcAmt;
360  dsDeposit.options.transport.read.data.rdc_token = "<?php echo $inputVars["rdc_token"] ?>";
361  dsDeposit.read();
362  },
363  ResetModel: function() {
364  this.set( "rdcDepositId", "" );
365  this.set( "rdcToId", "" );
366  this.set( "rdcAmt", "" );
367 
368  // also make sure the thumbnails are cleared out
369  $("#frontThumb").removeAttr('src')
370  $('#frontThumb').show();
371 
372  $("#backThumb").removeAttr('src')
373  $('#backThumb').show();
374  }
375 });
376 
377 function DespositSave() {
378  var msgConfirm;
379  var type;
380 
381  msgConfirm = "Deposit <b>" + kendo.toString(depositModel.rdcAmt, "c2") +
382  "</b> into account <b>" + $("#toAcct").data("kendoDropDownList").text() + "</b>.";
383 
384  confirmSaveDialog = $('#confirmSaveTemplate').kendoDialog({
385  width: "85%",
386  title: "<?php echo $MC->msg("Save", HCU_DISPLAY_AS_JS) ?> " + mpType,
387  maxWidth: "500px",
388  minWidth: "300px",
389  closable: false,
390  modal: true,
391  visible: false,
392  resizable: false,
393  content: msgConfirm,
394  show: function(e) {
395  // add the close function to the window stack
396  windowStack.push(function(e) {
397  confirmSaveDialog.close(e);
398  });
399  },
400  close: function(e) {
401  // remove the close function from the window windowStack
402  windowStack.pop();
403  },
404  actions: [
405  { text: '<?php echo $MC->msg("Close", HCU_DISPLAY_AS_HTML)?>',
406  action: function(e) {
407  // ** Close the current confirmSaveDialog
408  }
409  },
410  { text: "<?php echo $MC->msg("Confirm New Transfer", HCU_DISPLAY_AS_JS) ?>",
411  primary: true,
412  action: function(e) {
413  //save payment or transfer
414  if ( $.homecuValidator.validate() ) {
415  depositModel.Save();
416  }
417  }
418  }
419  ]
420  }).data("kendoDialog");
421  confirmSaveDialog.open();
422 }
423 
424 function compareDates(xdate, mdates) {
425  for (var i = 0; i < mdates.length; i++) {
426  if (mdates[i].getDate() == xdate.getDate() &&
427  mdates[i].getMonth() == xdate.getMonth() &&
428  mdates[i].getYear() == xdate.getYear()) {
429  return true
430  }
431  }
432 }
433 
434 function ShowDepositResult(resultData) {
435  var confirmationTemplate = kendo.template($("#confirmationTemplate").html());
436 
437  // show the results
438  var confirmationDisplay = confirmationDisplay = confirmationTemplate(resultData);
439 
440  // dialog depends on the status
441  var dialog;
442  if ( resultData.status == "B" ||
443  resultData.status == "F" ) {
444  dialog = $("#confirmationWindowRetry").data("kendoDialog");
445  // don't reset the data
446  } else {
447  dialog = $("#confirmationWindow").data("kendoDialog");
448 
449  // reset the data since starting over
450  depositModel.ResetModel();
451  }
452 
453  dialog.content(confirmationDisplay);
454  dialog.title(resultData.title);
455 
456  dialog.open();
457 
458 }
459 
460 function newDeposit(){
461 
462  depositModel.ResetModel();
463  depositModel.rdcLabel = "<?php echo $MC->msg("Deposit", HCU_DISPLAY_AS_JS) ?>";
464  $.homecuValidator.setup({formValidate: "depositWindow",
465  formErrorTitle: "<?php echo $MC->msg("Error Occurred", HCU_DISPLAY_AS_JS) ?>",
466  formStatusField: "depositFormStatus"});
467 
468  $("#editToAcct").text("<?php echo $MC->msg("ACH To Account", HCU_DISPLAY_AS_JS) ?>");
469 
470  $("#toAcct").attr("data-required-msg", "<?php echo $MC->msg("Account is required", HCU_DISPLAY_AS_HTML)?>");
471  $("#depositAmount").attr("data-required-msg", "<?php echo $MC->msg("Amount Missing", HCU_DISPLAY_AS_JS) ?>");
472 
473  //adding required stars
474  $("#editToAcct").append('<span class="hcu-required-field"><sup>*</sup></span>');
475 
476  dsGetAccounts.read();
477 
478 
479  kendo.bind($("#depositWindow"), depositModel);
480 
481  $("#depositAmount").val(0);
482 
483  $("#depositAmount").kendoNumericTextBox({
484  format: "c",
485  value: 0,
486  decimals: 2,
487  step: 0,
488  spinners: false,
489  min: .01,
490  max: 9999999,
491  placeholder: '<?php echo $MC->msg('Amount', HCU_DISPLAY_AS_JS); ?>'
492  });
493 
494  $("#btnMakeDeposit").click( function() {
495  if ( $.homecuValidator.validate() ) {
496  depositModel.Save();
497  }
498  });
499 
500 
501 }
502 
503  $(".btn-group > .btn").click(function(e){
504  $(this).addClass("active").siblings().removeClass("active");
505  var grid = $("#grid").data("kendoGrid");
506  var dataSource = grid.dataSource;
507  switch($('.btn-group > .btn.active').text()) {
508  case "Payments":
509  dataSource.filter ({
510  "field": "Type",
511  "operator": "eq",
512  "value": "Payment"
513  });
514  break;
515  case "Transfers":
516  dataSource.filter ({
517  "field": "Type",
518  "operator": "eq",
519  "value": "Transfer"
520  });
521  break;
522  default:
523  dataSource.filter ({
524  });
525  }
526 
527  });
528 
529  var dsDeposit = new kendo.data.DataSource({
530  transport: {
531  read: {
532  url: 'hcuMRDC.data?cu=<?php echo $HB_ENV['cu']; ?>&rdc_token=<?php echo $encodedToken ?>&rdc_type=Deposit&<?php echo $HB_ENV['cuquery'] ?>',
533  dataType: "json",
534  contentType: "application/x-www-form-urlencoded",
535  type: "POST",
536  data: {},
537  cache: false
538  }
539  },
540  schema: {
541  parse: function(response) {
542  var display = [];
543  if ( response.homecuData ) {
544  for (var i = 0; i < response.homecuData.length; i++) {
545  display.push(response.homecuData[i]);
546  }
547  }
548  return display;
549  },
550  },
551  requestStart: function( e ) {
552  ShowWaitWindow();
553  },
554  requestEnd: function( e ) {
555  var error = null;
556  //ENR - not needed
557  //dsAcctHistory.read();
558  CloseWaitWindow();
559  // see if there is an error
560  if ( e.response && e.response.homecuErrors )
561  error = e.response.homecuErrors;
562  if ( error && error.length > 0 ) {
563  e.preventDefault();
564  $.homecuValidator.displayMessage(error, $.homecuValidator.settings.statusError);
565  } else {
566  try {
567  // get the response - there should always be homecuData and homecuInfo is not used here
568  if (e.response.homecuData) {
569  var data = e.response.homecuData;
570 
571  //show the results of the deposit
572 console.log(data);
573  ShowDepositResult(data);
574  } else {
575  throw "Error Parsing Result From Server";
576  }
577  } catch (err) {
578  // ** Need to report the message to the main screen
579  $.homecuValidator.displayMessage(err, $.homecuValidator.settings.statusError);
580  }
581  }
582  },
583  // code to run if the request fails; the raw request and
584  // status codes are passed to the function
585  error: function( e ) {
586  alert( "<?php echo $MC->msg("Transport error", HCU_DISPLAY_AS_JS); ?>: " + e.status );
587  }
588  });
589 
590  $(document).on("click", ".k-overlay", function (e) {
591  if(windowStack.length > 0) {
592  // get the close function from the stack, without poping it (the close will pop it)
593  var fn = windowStack[windowStack.length - 1];
594  var ret = fn(e);
595  }
596  });
597 
598  $(document).ready(function () {
599  $.homecuValidator.setup({depositFormStatus: "<?php echo $MC->msg("Error Occurred", HCU_DISPLAY_AS_JS) ?>"});
600 
601  InitDataSources();
602  newDeposit();
603  });
604  <?php if ( $HB_ENV["platform"] == "ADA" ) : ?>
605  function captureCheck(command, parameters) {
606  AndroidController.notifyCommand(command, parameters);
607  }
608  <?php elseif ( $HB_ENV["platform"] == "APP" ) : ?>
609 
610  function captureCheck(command, parameters) {
611  var postObject = {
612  body: {
613  cmd: command,
614  params: parameters
615  }
616  };
617  window.webkit.messageHandlers.interOp.postMessage(postObject);
618  }
619  <?php endif ?>
620 
621 </script>
622 <?php
623  /*
624  * ** END CONTENT
625  */
626 
627 
628  // ** INCLUDE POST CONTENT SCRIPT
629  require_once(dirname(__FILE__) . '/../includes/hcuPostContent.i');
630 ?>