HEX
Server: Apache/2.2.15 (CentOS)
System: Linux ip-10-0-2-146.eu-west-1.compute.internal 2.6.32-754.35.1.el6.centos.plus.x86_64 #1 SMP Sat Nov 7 11:33:42 UTC 2020 x86_64
User: root (0)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: /www/exchange0old/exchange/admin/cache/%%8F^8F3^8F389B2A%%add_manual_transactions.html.php
<?php /* Smarty version 2.6.19, created on 2025-11-17 12:15:53
         compiled from transactions/add_manual_transactions.html */ ?>
<?php require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('modifier', 'siteUrl', 'transactions/add_manual_transactions.html', 14, false),)), $this); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>:: Credebt Exchange - Admin Panel ::</title>
<link rel="stylesheet" href="css/stylesheet.css" type="text/css" />
<link rel="shortcut icon" href="<?php echo $_SESSION['base_url']; ?>
images/logo_favicon.ico"  />
 <link rel="stylesheet" href="css/boot.css" type="text/css" />
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/aj_admin_home.js"></script>
<script type="text/javascript" src="js/tooltip.js"></script>
<script type="text/javascript" src="js/pngfix.js"></script>
<script type="text/javascript" src="js/row_color.js"></script>
<link type="text/css" href="<?php echo ((is_array($_tmp='/css/jquery-ui-1.7.2.custom.css')) ? $this->_run_mod_handler('siteUrl', true, $_tmp) : smarty_modifier_siteUrl($_tmp)); ?>
" rel="stylesheet" />
<script type="text/javascript" src="<?php echo $_SESSION['base_url']; ?>
js/jquery.ui.core.js"></script>
<script type="text/javascript" src="<?php echo $_SESSION['base_url']; ?>
js/ui.datepicker.js"></script>
<script type="text/javascript" src="<?php echo $_SESSION['exchange_url']; ?>
js/add_transaction.js"></script>
<link rel="stylesheet" href="<?php echo $_SESSION['admin_url']; ?>
css/stylesheet.css" type="text/css" />

<script type="text/javascript">
   $(document).ready(function(){ 
        $(document).pngFix();  
    }); 
</script>
 <script type="text/javascript" src="<?php echo $_SESSION['admin_url']; ?>
js/selecbox.js"></script>
    <script type="text/javascript">
  $(document).ready(function() {
    $('#Items').selectbox();
  });
  </script>
    <script type="text/javascript" src="<?php echo $_SESSION['admin_url']; ?>
js/dropdown.js"></script>
</head>

<body>

      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td align="left" valign="top">
            <!--
            <?php if (count ( $this->_tpl_vars['success_transactions'] ) > 0): ?>
            <div class="success-msgbox"><span>
              <?php $_from = $this->_tpl_vars['success_transactions']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }$this->_foreach['err'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['err']['total'] > 0):
    foreach ($_from as $this->_tpl_vars['err']):
        $this->_foreach['err']['iteration']++;
?>
              <?php echo $this->_tpl_vars['success_transactions']; ?>

              <br>
              <?php endforeach; endif; unset($_from); ?>
              </span></div>
            <?php endif; ?> -->
            <table cellpadding="0" cellspacing="0" border="0" width="100%" class="margin_table">
              <tr>
                <td valign="top" align="left" width="2%" class="hdr_tl">&nbsp;</td>
                <td valign="top" align="left" class="hdr_tc" width=""><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td>Manual Transactions</td>
                      <td align="right"><!-- <a class="under_blue" href="javascript:void(0);" onclick="history.go(-1);">Back</a> --></td>
                    </tr>
                  </table></td>
                <td valign="middle" align="right" class="hdr_tr" width="2%">&nbsp;</td>
              </tr>
              <tr>
                <td valign="top" align="left" colspan="3" class="hdr_center">
                    <form action="adminindex.php?do=savetransaction" method="post" enctype="multipart/form-data" id="save_transaction">
                    <table cellpadding="0" cellspacing="0" border="0" width="100%" id="transaction">
                      <tr class="row1" id="row_transaction_type">
                        <td width="23%" valign="top" align="left">Transaction Type :</td>
                        <td width="" valign="top" align="left"><?php echo $this->_tpl_vars['transaction_types']; ?>

                          <br>
                          <span style="color:#FF0000">
                          <?php echo $this->_tpl_vars['errmsg']['transaction_type']; ?>

                          </span></td>
                      </tr>
                      <tr class="row2" id="row_originator_id" >
                        <td valign="top" align="left">Originator :</td>
                        <td valign="top" align="left"><span id="d_originators">
                          <input type="text" name="d_originators" value="" class="text_b">
                          </span>
                          <?php if ($this->_tpl_vars['values']['originator_id'] != ''): ?>
                          <span>
                          <?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "originators/list.html", 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>
                          </span>
                          <?php else: ?>
                          <span id="originators" style="display:none;"></span>
                          <?php endif; ?>

                          <span id="err_currency">
                          <?php if ($this->_tpl_vars['values']['currency_id'] != ''): ?>
                          <span>
                          <?php echo $this->_tpl_vars['currency']; ?>

                          </span>
                          <?php else: ?>
                          <span id="currency" style="display:none;"></span>
                          <?php endif; ?>
                          </span>


                          &nbsp;<br>
                          <span style="color:#FF0000">
                          <?php echo $this->_tpl_vars['errmsg']['originator_id']; ?>

                          </span>
                          <?php if ($this->_tpl_vars['errmsg']['currency_id'] != ''): ?>
                          <span style="color:#FF0000;padding-left:215px;">
                          <?php echo $this->_tpl_vars['errmsg']['currency_id']; ?>

                          </span>
                          <?php endif; ?>
                        </td>
                      </tr>

                      <tr class="row1" id="row_debtor_id">
                        <td valign="top" align="left">Name :</td>
                        <td valign="top" align="left"><span id="d_debtors">
                          <input type="text" name="debtors" value="" class="text_b">
                          </span>
                          <?php if ($this->_tpl_vars['values']['debtor_id'] != ''): ?>
                          <span id="debtors">
                          <?php echo $this->_tpl_vars['debtors']; ?>

                          </span>
                          <?php else: ?>
                          <span id="debtors" style="display:none;"></span>
                          <?php endif; ?>
                          &nbsp;<br>
                          <span style="color:#FF0000">
                          <?php echo $this->_tpl_vars['errmsg']['debtor_id']; ?>

                          </span></td>
                      </tr>

                      <tr class="row1" id="row_ocpa_currency_id" style="display: none;">
                        <td valign="top" align="left">Resulting Ccy :</td>
                        <td valign="top" align="left">
                            <select name="ocpa_currency_id" id="ocpa_currency_id">
                                <option value="1">EUR</option>
                                <option value="2">GBP</option>
                                <option value="3">USD</option>
                            </select>
                        </td>
                      </tr>

                        <tr class="row1" id="row_rpas" style="display: none;">
                            <td valign="top" align="left">b-ETR:</td>
                            <td valign="top" align="left" id="rpas">
                            </td>
                        </tr>

                        <tr class="row1" id="row_deposits" style="display: none;">
                            <td valign="top" align="left">Deposit:</td>
                            <td valign="top" align="left" id="deposits">
                            </td>
                        </tr>



                        <tr class="row1" id="row_notification" style="display:none;">
                        <td valign="top" align="left">Notification Title :</td>
                        <td valign="top" align="left">
                          <!-- <input type="text"  class="text_b" value="<?php if ($this->_tpl_vars['values']['notification_title'] != ''): ?><?php echo $this->_tpl_vars['values']['notification_title']; ?>
<?php endif; ?>" name="notification_title" id="notification_title"> -->

                          <select class="cmb_bx1" name="notification_title" id="notification_title" ><option value="" selected="selected">Select</option>

                            <option value="1" <?php if ($this->_tpl_vars['values']['notification_title'] == '1'): ?>selected="selected"<?php endif; ?> >Fee Notice</option>
                            <option value="2" <?php if ($this->_tpl_vars['values']['notification_title'] == '2'): ?>selected="selected"<?php endif; ?> >RSA Offer</option>
                            <option value="3" <?php if ($this->_tpl_vars['values']['notification_title'] == '3'): ?>selected="selected"<?php endif; ?> >Other</option>

                          </select>
                          &nbsp;<br>
                          <span style="color:#FF0000">
                          <?php echo $this->_tpl_vars['errmsg']['notification_title']; ?>

                          </span></td>
                      </tr>

                  <tr class="row2" id="row_date">
                  <td align="left" valign="top">Date: <span class="txt_11_cute">(DD/MM/YYYY)</span></td>
                  <td align="left" valign="top" style="font-size: 11px; padding-left: 10px;"><div id="body_tag">
                      <div id="search_all_id" class="search_all">
                        <div class="search_element1">
                          <div class="city_div">
                            <table cellspacing="0" cellpadding="0" border="0" width="55%">
                              <tbody>
                                <tr>
                                  <td align="left" width="13%" valign="top" style="border:none; padding:5px 0px;"> <input type="text" maxlength="2" size="2" class="text_dd_code" id="trans_date" name="trans_date" value="<?php echo $this->_tpl_vars['values']['trans_date']; ?>
" style="vertical-align:top;">
                                    </td>
                                  <td align="left" width="13%" valign="top" style="border:none; padding:5px 0px;"><input type="text" maxlength="2" size="2" class="text_dd_code" id="trans_month" name="trans_month" value="<?php echo $this->_tpl_vars['values']['trans_month']; ?>
" style="vertical-align:top;">
                                    </td>
                                  <td align="left"  valign="top" style="border:none; padding:5px 0px;"><input type="text" maxlength="4" size="4" class="text_c_code" id="trans_year" name="trans_year" value="<?php echo $this->_tpl_vars['values']['trans_year']; ?>
" style="vertical-align:top;">
                                    </td>

                                </tr>
                              </tbody>
                            </table>
                             <script>
                                //For Date Picker
                                $(function() {
                                  $( "#trans_year" ).datepicker({
                                        minDate: -1095,
                                        maxDate: "+0D",
                                        showOn: "button",
                                        buttonImage: "<?php echo ((is_array($_tmp='/images/calender_month.png')) ? $this->_run_mod_handler('siteUrl', true, $_tmp) : smarty_modifier_siteUrl($_tmp)); ?>
",
                                        buttonImageOnly: true,
                                        onSelect: function( selectedDate ) {
                                            var i =0;
                                            selDate = selectedDate.split('/');
                                            var dates = new Array("trans_month","trans_date","trans_year");
                                            for(i = 0; i <=2; i++){
                                                $( "#"+dates[i] ).val(selDate[i]);
                                            }
                                        },
                                        onClose:function( selectedDate ) {
                                            if ($("#transaction_type option:selected").val() == '<?php echo @INBOUND_DEBTOR_PAYMENT; ?>
' || $("#transaction_type option:selected").val() == '<?php echo @TRANSFER_OF_PAYMENT_BY_ORIGINATOR; ?>
' || $("#transaction_type option:selected").val() == '<?php echo @PAID_DIRECTLY_TO_ORIGINATOR; ?>
' || $("#transaction_type option:selected").val() == '<?php echo @INBOUND_CREDITOR_PAYMENT; ?>
')
                                            {
                                                showTrades(); 
                                            }
                                        }
                                    });
                                    
                                    $('#trans_month,#trans_date,#trans_year').change(function(){
                                        if ($("#transaction_type option:selected").val() == '<?php echo @INBOUND_DEBTOR_PAYMENT; ?>
' || $("#transaction_type option:selected").val() == '<?php echo @TRANSFER_OF_PAYMENT_BY_ORIGINATOR; ?>
' || $("#transaction_type option:selected").val() == '<?php echo @PAID_DIRECTLY_TO_ORIGINATOR; ?>
' || $("#transaction_type option:selected").val() == '<?php echo @INBOUND_CREDITOR_PAYMENT; ?>
')
                                        {
                                            showTrades();
                                        }
                                    })
                                });
                              </script>
                          </div>
                        </div>
                        <div class="clear_div"></div>
                                    <span style="color:#FF0000">
                                    <?php echo $this->_tpl_vars['errmsg']['trans_date']; ?>

                                    </span>
                      </div>
                    </div>
                    
                    </td>
                  </tr>

				  <tr class="row1" id="row_is_aetr" style="display: none">
                    <td valign="top" align="left">Is a-ETR :</td>
                    <td valign="top" align="left">
						<input type="checkbox" id="is_aetr" name="is_aetr" <?php if ($this->_tpl_vars['values']['is_aetr']): ?>checked<?php endif; ?>>
                        <!-- onchange="getAEtrs('change')" -->
					</td>
				  </tr>

				  <!-- <tr class="row2" id="row_aetr" style="display: none;">
					  <td valign="top" align="left">a-ETR:</td>
					  <td valign="top" align="left" id="row_aetr_data">
						  <?php echo $this->_tpl_vars['a_etr_html']; ?>

					  </td>
				  </tr> -->

				  <!-- <tr class="row1" id="row_aetr_asset" style="display: none;">
					  <td valign="top" align="left">Asset:</td>
					  <td valign="top" align="left" id="row_aetr_asset_data">
						  <?php echo $this->_tpl_vars['asset_html']; ?>

					  </td>
				  </tr> -->

                  <tr class="row1" id="row_transaction_name" style="display:none;">
                    <td valign="top" align="left">Transaction Name :</td>
                    <td valign="top" align="left"><input type="text"  class="text_b" value="<?php if ($this->_tpl_vars['values']['transaction_name'] != ''): ?><?php echo $this->_tpl_vars['values']['transaction_name']; ?>
<?php endif; ?>" name="transaction_name" id="transaction_name">
                      &nbsp;<br>
                      <span style="color:#FF0000">
                      <?php echo $this->_tpl_vars['errmsg']['transaction_name']; ?>

                      </span></td>
                  </tr>
                      <tr class="row1" id="row_reconcile" style="display:none;">
                        <td valign="top" align="left">Payment(s) :</td>
                        <td valign="top" align="left">
                          <div style="clear:both;">
                            <span id="d_reconcile">
                              <input type="text" name"d_reconcile" value="" class="text_b" style="display:none;">
                            </span>
                            <?php if ($this->_tpl_vars['values']['reconcile_payment'] != ''): ?>
                            <span id="err_reconcile">
                              <?php echo $this->_tpl_vars['reconcile_payment']; ?>

                            </span>
                            <?php else: ?>
                            <span id="reconcile" style="display:none;"></span>
                            <?php endif; ?>

                            <span id="rec_deductibles" style="display:none;">
                            &nbsp;&nbsp;<input type="checkbox" name="check_deductible"  id="check_deductible" value="1" onClick="javascript:checkDeductible();" 
                              <?php if ($this->_tpl_vars['values']['check_deductible'] == '1'): ?>
                              checked="true"
                              <?php endif; ?>
                              style="vertical-align:middle;" /> & Specific Deductible(s) 

                              &nbsp;&nbsp;<input type="checkbox" name="check_trailing"  id="check_trailing" value="1" onClick="javascript:checkTrailing();" 
                              <?php if ($this->_tpl_vars['values']['check_trailing'] == '1'): ?>
                              checked="true"
                              <?php endif; ?>
                              style="vertical-align:middle;" /> & Trailing Balance
                            </span>

                          </div>
                          &nbsp;<br>
                          <span style="color:#FF0000">
                            <?php echo $this->_tpl_vars['errmsg']['reconcile_payment']; ?>

                          </span></td>
                        </tr>

                        <tr class="row1" id="ocpa_row" style="display:none;">
                            <td>OCPA Transaction:</td>
                            <td id="ocpa_cell"></td>
                        </tr>

                        <tr class="row1" id="ocpa_row_creditors" style="display:none;">
                            <td></td>
                            <td id="ocpa_cell_creditors"></td>
                        </tr>


                        <tr class="row1" id="row_payment_return" style="display:none;">
                        <td valign="top" align="left">Payment :</td>
                        <td valign="top" align="left">
                          <div style="clear:both;">
                            <span id="d_payment_return">
                              <input type="text" name"d_payment_return" value="" class="text_b" style="display:none;">
                            </span>
                            <?php if ($this->_tpl_vars['values']['payment_return'] != ''): ?>
                            <span id="err_payment_return">
                              <?php echo $this->_tpl_vars['payment_return']; ?>

                            </span>
                            <?php else: ?>
                            <span id="payment_return" style="display:none;"></span>
                            <?php endif; ?>

                          </div>
                          &nbsp;<br>
                          <span style="color:#FF0000">
                            <?php echo $this->_tpl_vars['errmsg']['payment_return']; ?>

                          </span></td>
                        </tr>


                        <tr class="row1" id="row_tb_return" style="display:none;">
                        <td valign="top" align="left">Payments :</td>
                        <td valign="top" align="left">
                            <div style="display: block; height: 21px; width: 450px;">
                                <span style="float: left; padding-left: 28px; width: 120px;">Type</span>
                                <span style="float: left; width: 150px;">Amount</span>
                                <span>Transaction Date</span>
                            </div>
                          <div style="clear:both;">
                            <span id="tb_return" style="display:none;"></span>
                          </div>
                          &nbsp;<br>
                          <span style="color:#FF0000">
                            <?php echo $this->_tpl_vars['errmsg']['tb_return']; ?>

                          </span></td>
                        </tr>


                        <tr class="row1" id="row_multiple_payments" style="display:none;">
                        <td valign="top" align="left">AR Payments :</td>
                        <td valign="top" align="left">

                          <div style="display: block; height: 21px; width: 450px;">
                            <span style="float: left; padding-left: 28px; width: 120px;">Receipt Type</span>
                            <span style="float: left; width: 150px;">Trailing Balance Amount</span>
                            <span style="float: right; width: 101px;">Issue Date</span>
                          </div>


                          <div style="clear:both;">
                            <span id="d_multiple_payments">
                              <input type="text" name"d_multiple_payments" value="" class="text_b" style="display:none;">
                            </span>
                            <?php if ($this->_tpl_vars['values']['multiple_payments'] != ''): ?>
                            <span id="err_multiple_payments">
                              <?php echo $this->_tpl_vars['multiple_payments']; ?>

                            </span>
                            <?php else: ?>
                            <span id="multiple_payments" style="display:none;"></span>
                            <?php endif; ?>

                          </div>
                          &nbsp;<br>
                          <span style="color:#FF0000">
                            <?php echo $this->_tpl_vars['errmsg']['multiple_payments']; ?>

                          </span></td>
                        </tr>


                      <tr class="row1" id="row_merge_payments" style="display: none;">
                        <td valign="top" align="left">Transactions :</td>
                        <td valign="top" align="left" id="merge_payments_cell"></td>
                      </tr>

                      <tr class="row1 row_split_payments" style="display: none;" >
                        <td valign="top" align="left">Transaction :</td>
                        <td valign="top" align="left" id="split_payments_cell"></td>
                      </tr>


                      <?php if ($this->_tpl_vars['errmsg']['split_payment'] != ''): ?>
                      <tr class="row1 row_split_payments" style="display: none;" >
                        <td valign="top" align="left"></td>
                        <td valign="top" align="left">
                          <span style="color:#FF0000">
                            <?php echo $this->_tpl_vars['errmsg']['split_payment']; ?>

                          </span>
                        </td>
                      </tr>
                      <?php endif; ?>

                      <tr class="row1 row_split_payments" style="display: none;" >
                        <td valign="top" align="left">Amount of splits :</td>
                        <td valign="top" align="left">
                            <select id="amount_of_splits" name="amount_of_splits" class="cmb_bx1" onchange="show_split_fields();">
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="5">5</option>
                                <option value="6">6</option>
                                <option value="7">7</option>
                                <option value="8">8</option>
                                <option value="9">9</option>
                                <option value="10">10</option>
                            </select>
                        </td>
                      </tr>


                      <?php if ($this->_tpl_vars['errmsg']['amount_of_splits'] != ''): ?>
                      <tr class="row1 row_split_payments" style="display: none;" >
                        <td valign="top" align="left"></td>
                        <td valign="top" align="left">
                          <span style="color:#FF0000">
                            <?php echo $this->_tpl_vars['errmsg']['amount_of_splits']; ?>

                          </span>
                        </td>
                      </tr>
                      <?php endif; ?>


                      <?php 
                      $this->assign('split_array', array(1,2,3,4,5,6,7,8,9,10));

                       ?>

                      <?php $_from = $this->_tpl_vars['split_array']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['i']):
?>
                      <tr class="row1" id="row_split_payments_<?php echo $this->_tpl_vars['i']; ?>
" style="display: none;"  >
                        <td valign="top" align="left">Split amount <?php echo $this->_tpl_vars['i']; ?>
:</td>
                        <td valign="top" align="left">
                          <input id="split_amount_<?php echo $this->_tpl_vars['i']; ?>
" name="split_amount_<?php echo $this->_tpl_vars['i']; ?>
" class="text_b split_amounts" value="<?php if ($this->_tpl_vars['values']['split_amounts'] != ''): ?> <?php echo $this->_tpl_vars['values']['split_amounts']; ?>
<?php endif; ?>">
                          <?php 
                          $i = $this->get_template_vars("i");
                          $err = $this->get_template_vars("errmsg");

                          if(isset($err['split_amount_' . $i]) and $err['split_amount_' . $i] != '' )
                          {
                            echo '<br><span style="color:#FF0000">'.$err['split_amount_' . $i].'</span>';
                          }

                           ?>
                        </td>
                      </tr>
                      <?php endforeach; endif; unset($_from); ?>

                      <style>
                        .err-msg
                        {
                          border: 1px solid red;
                          background-color: #e4b9b9;
                          color: red;
                        }
                      </style>
                      <script>
                        function show_split_fields()
                        {
                            var i = 0;
                            for( i = 1; i <= 10; i++)
                            {
                              $("#row_split_payments_" + i).hide();
                            }

                          console.log($('#amount_of_splits').val());

                          for( i = 1; i <= $('#amount_of_splits').val(); i++)
                          {
                            $("#row_split_payments_" + i).show();
                          }
                        }

                        $(document).ready(function(){
                            $('.split_amounts').keyup(function(){

                                var amt = $('#amount_of_splits').val();
                                var total = 0;
                                var is_error = 0;

                                for(var i = 1; i <= amt; i++)
                                {
                                    var v = parseFloat($('#split_amount_' + i).val());

                                    if(v && !isNaN(v)) {
                                      total += v;
                                    }
                                    else
                                    {
                                        $('#split_amount_' + i).addClass('err-msg');
                                    }
                                }

                                var amount = parseFloat($('#split_transaction option:selected').attr('data-amount'));

                                console.log(amount +' ' + total);

                                if( Math.abs(total - amount) > 0.01 )
                                {
                                  $('.split_amounts').addClass('err-msg');
                                  $(".login_bttn").attr('disabled', 'disabled');
                                }
                                else
                                {
                                  $('.split_amounts').removeClass('err-msg');
                                  $(".login_bttn").removeAttr('disabled');
                                }

                            });
                        });

                      </script>

                      <tr class="row1" id="row_amount">
                        <td valign="top" align="left">Amount :</td>
                        <td valign="top" align="left"><input type="text"  size="25" class="text_b_small" value="<?php if ($this->_tpl_vars['values']['amount'] != ''): ?><?php echo $this->_tpl_vars['values']['amount']; ?>
<?php endif; ?>" name="amount" id="amount">
                            <span id="row_ocpa_commisions" style="display: none;">
                                <input type="checkbox" name="ocpa_fees_commision"  id="ocpa_fees_commision" value="1" style="vertical-align:middle;" /> Fees and Charges
                            </span>

                            <span id="withallocation">

                                <input type="checkbox" name="trade_select"  id="trade_select" value="1"
                          <?php if ($this->_tpl_vars['values']['trade_select'] == '1'): ?>
                          checked="true"
                          <?php endif; ?>
                          style="vertical-align:middle;" /> With Specific Allocation

                          <span id="deductibles" style="display:none;" >
                          &nbsp;&nbsp;<input type="checkbox" name="check_deductible"  id="check_deductible" value="1" onClick="javascript:checkDeductible();" 
                          <?php if ($this->_tpl_vars['values']['check_deductible'] == '1'): ?>
                          checked="true"
                          <?php endif; ?>
                          style="vertical-align:middle;" /> & Specific Deductible(s) 


                          <span id="trailing" style="display:none;" >
                          &nbsp;&nbsp;<input type="checkbox" name="check_trailing"  id="check_trailing" value="1" onClick="javascript:checkTrailing();" 
                          <?php if ($this->_tpl_vars['values']['check_trailing'] == '1'): ?>
                          checked="true"
                          <?php endif; ?>
                          style="vertical-align:middle;" /> & Trailing Balance 
                          </span>

                         <!--  &nbsp;&nbsp;<input type="checkbox" name="check_deductible"  id="check_deductible" value="2" onClick="javascript:checkDeductible();"  
                          <?php if ($this->_tpl_vars['values']['check_deductible'] == '2'): ?>
                          checked="true"
                          <?php endif; ?>
                          style="vertical-align:middle;" /> Multiple Deductibles -->

                          </span>
                          <input type="hidden" name="amountval" id="amountval" value="<?php if ($this->_tpl_vars['values']['amount'] != ''): ?><?php echo $this->_tpl_vars['values']['amount']; ?>
<?php endif; ?>" />

                          <input type="hidden" name="multipleval" id="multipleval" value="<?php if ($this->_tpl_vars['values']['multipleval'] != ''): ?><?php echo $this->_tpl_vars['values']['multipleval']; ?>
<?php endif; ?>" />
                          </span>
                          <?php if ($this->_tpl_vars['errmsg']['amount'] != ''): ?>
                          <br>
                          <span style="color:#FF0000">
                          <?php echo $this->_tpl_vars['errmsg']['amount']; ?>

                          </span>
                          <?php endif; ?>

                         <!--  <?php if ($this->_tpl_vars['errmsg']['check_deductible'] != ''): ?>
                          <br>
                          <span style="color:#FF0000">
                          <?php echo $this->_tpl_vars['errmsg']['check_deductible']; ?>

                          </span>
                          <?php endif; ?> -->
                        </td>
                      </tr>
                      <tr class="row1" id="row_reference_to" style="display:none;">
                        <td valign="top" align="left">With specific reference to :</td>
                        <td valign="top" align="left">
                          <div style="display: block; height: 21px; width: 450px;">
                          <span style="float: left; padding-left: 28px; width: 195px;">Reference</span>

                          <span style="float: left; width: 77px;">Amount</span>
                          <span style="float: right; width: 101px;">Issue Date</span>
                          </div>

                          <div style="clear:both;">
                          <span id="d_reference">
                          <input type="text" name"d_reference" value="" class="text_b" style="display:none;">
                          </span>
                          <?php if ($this->_tpl_vars['values']['reference_to'] != ''): ?>
                          <span id="err_reference">
                          <?php echo $this->_tpl_vars['reference_to']; ?>

                          </span>
                          <?php else: ?>
                          <span id="reference" style="display:none;"></span>
                          <?php endif; ?>
                          </div>
                          &nbsp;<br>
                          <span style="color:#FF0000">
                          <?php echo $this->_tpl_vars['errmsg']['reference_to']; ?>

                          </span></td>
                      </tr>


                       <tr class="row1" id="row_paying_reserve" style="display:none;">
                        <td valign="top" align="left">Paying Reserve on :</td>
                        <td valign="top" align="left">
                          <div style="display: block; height: 21px; width: 450px;">
                          <span style="float: left; padding-left: 28px; width: 195px;">Reference</span>

                          <span style="float: left; width: 77px;">Amount</span>
                          <span style="float: right; width: 101px;">Issue Date</span>
                          </div>

                          <div style="clear:both;">
                          <span id="d_reference">
                          <input type="text" name"d_paying_reserve" value="" class="text_b" style="display:none;">
                          </span>
                          <?php if ($this->_tpl_vars['values']['paying_reserve'] != ''): ?>
                          <span id="err_paying_reserve">
                          <?php echo $this->_tpl_vars['reserve_reference_to']; ?>

                          </span>
                          <?php else: ?>
                          <span id="reserve" style="display:none;"></span>
                          <?php endif; ?>
                          </div>
                          &nbsp;<br>
                          <span style="color:#FF0000">
                          <?php echo $this->_tpl_vars['errmsg']['paying_reserve']; ?>

                          </span></td>
                      </tr>

                      <tr class="row2" id="row_balance">
                        <td valign="top" align="left">Balance :</td>
                        <td valign="top" align="left"><span id="d_balance">
                          <?php echo $this->_tpl_vars['currency']; ?>
 <?php echo $this->_tpl_vars['balance']; ?>

                          </span>
                          <?php if ($this->_tpl_vars['values']['balance'] != ''): ?>
                          <span>
                          <?php echo $this->_tpl_vars['currency']; ?>
 <?php echo $this->_tpl_vars['balance']; ?>

                          </span>
                          <?php else: ?>
                          <span id="bal_currency" style="display:none;"></span> <span id="balance" style="display:none;"></span>
                          <?php endif; ?>
                          <br>
                          <span style="color:#FF0000">
                          <?php echo $this->_tpl_vars['errmsg']['balance']; ?>

                          </span></td>
                      </tr>


                      <tr class="row1" id="row_deductible" style="display:none;">
                        <td valign="top" align="left">Specific Deductible <!-- <span id="txt_deductible" style="font-size:11px;"></span>  --> :</td>
                        <td valign="top" align="left">

                          <div style="display: block; height: 21px; width: 450px;">
                          <span style="float: left; padding-left: 28px; width: 195px;">&nbsp;</span>

                          <span style="float: left; width: 77px;"><input type="text" id="balance_deductible" name="balance_deductible" value="<?php echo $this->_tpl_vars['values']['balance_deductible']; ?>
" class="text_b_small" size="25" /></span>
                          <span style="float: right; width: 101px;">&nbsp;</span>
                          </div>
                          <?php if ($this->_tpl_vars['errmsg']['balance_deductible'] != ''): ?>
                          <span style="color:#FF0000;padding-left:221px;">
                          <?php echo $this->_tpl_vars['errmsg']['balance_deductible']; ?>

                          </span>
                          <?php endif; ?>
                        </td>
                      </tr>

                      <tr class="row1" id="row_trailing" style="display:none;">
                        <td valign="top" align="left">Trailing Balance <!-- <span id="txt_deductible" style="font-size:11px;"></span>  --> :</td>
                        <td valign="top" align="left">

                          <div style="display: block; height: 21px; width: 450px;">
                          <span style="float: left; padding-left: 28px; width: 195px;">&nbsp;</span>

                          <span style="float: left; width: 77px;"><input type="text" id="trailing_balance_amt" name="trailing_balance_amt" value="<?php echo $this->_tpl_vars['values']['trailing_balance_amt']; ?>
" class="text_b_small" size="25" /></span>
                          <span style="float: right; width: 101px;">&nbsp;</span>
                          </div>
                          <?php if ($this->_tpl_vars['errmsg']['trailing_balance_amt'] != ''): ?>
                          <span style="color:#FF0000;padding-left:221px;">
                          <?php echo $this->_tpl_vars['errmsg']['trailing_balance_amt']; ?>

                          </span>
                          <?php endif; ?>
                        </td>
                      </tr>

                      <tr class="row2" id="row_credit_note_no" style="display:none;">
                        <td valign="top" align="left">Number :</td>
                        <td valign="top" align="left"><input class="text_b" type="text" name="credit_note_no" value="<?php echo $this->_tpl_vars['values']['credit_note_no']; ?>
" />
                          &nbsp;<br>
                          <span style="color:#FF0000">
                          <?php echo $this->_tpl_vars['errmsg']['credit_note_no']; ?>

                          </span></td>
                      </tr>

                      <tr class="row2" id="row_transaction_file" style="display:none;">
                        <td valign="top" align="left">Transaction File :</td>
                        <td valign="top" align="left"><input type="file" name="transaction_file" value="" />
                          &nbsp;<br>
                          <span style="color:#FF0000">
                          <?php echo $this->_tpl_vars['errmsg']['transaction_file']; ?>

                          </span></td>
                      </tr>
                      <tr class="row1" id="row_notes">
                        <td valign="top" align="left">Notes/Comments :</td>
                        <td valign="top" align="left"><textarea style="height: 150px;width:310px;overflow:auto" class="text_b" name="notes"><?php echo $this->_tpl_vars['values']['notes']; ?>
</textarea>
                          &nbsp;<br>
                          <span style="color:#FF0000">
                          <?php echo $this->_tpl_vars['errmsg']['email']; ?>

                          </span></td>
                      </tr>
                      <tr>
                        <td align="left" valign="top" ></td>
                        <td align="left" valign="top" id="waiting_box">&nbsp;</td>
                      </tr>
                      <tr>
                        <td align="left" valign="top" ></td>
                        <td align="left" valign="top">&nbsp;&nbsp;
                            <input type="submit" value="Save"  class="login_bttn">
                            <button type="button" value="Save" class="login_bttn" id="save_ocpa" style="display: none">Save</button>
                        </td>
                      </tr>
                    </table>
                  </form></td>
              </tr>
              <tr>
                <td valign="top" align="left" width="2%" class="hdr_bl">&nbsp;</td>
                <td valign="top" align="left" width="96%" class="hdr_bc">&nbsp;</td>
                <td valign="top" align="left" width="2%" class="hdr_br">&nbsp;</td>
              </tr>
            </table></td>
        </tr>
      </table>

</body>
<style>
.grays_bg td{
  padding:5px 0px 5px 2px !important;
}
.row1 td , .row2 td{
  padding:5px 0px 5px 2px !important;
}
.grays_bg img{
  padding-bottom: 2px;
    vertical-align: bottom;
}
</style>

<script type="text/javascript">

    $(document).ready(function(){
        $('#save_ocpa').click(SaveOCPA);
        $('select[name="payment_return"]').live('change', function(){
			$('#is_aetr').prop('checked', $("option:selected", this).data('is-aetr'));
        });
    });

    function OCPAMerge_onChange(e)
    {
        var sel = $('#merge_transactions').val();

        var total = 0;

        var rates = $('#ocpa_merge_fx_info').attr('data-rates');
        var result_currency_id = parseInt($('#ocpa_currency_id').val());

        var ccy = new Array;


        ccy[1] = 1;
        ccy[2] = 1;
        ccy[3] = 1;

        var tDate = '';

        try
        {
            rates =  base64_decode(rates);
            rates = JSON.parse(rates);

            var targetDate = new Date('1970-01-01');

            for( var i = 0; i < sel.length; i++ )
            {
                var v = sel[i];
                var opt = $('#merge_transactions option[value="' + v + '"]');
                if(!opt)
                    continue;

                var currency_id     = parseInt($(opt).attr('data-currency-id'));
                var amount          = parseFloat($(opt).attr('data-amount'));
                var c_date          = $(opt).attr('data-date');
                var currency_rate   = parseFloat($(opt).attr('data-currency-rate'));

                var d = new Date(c_date);

                if( d.getTime() > targetDate.getTime() )
                {
                    targetDate = d;
                }
            }

            targetDate = targetDate.getFullYear() + '-' + ('0' + (targetDate.getMonth() + 1)).slice(-2) + '-' + ('0' + targetDate.getDate()).slice(-2);


            for( var el in rates )
            {
                var em = rates[el];

                if( em.currency_date == targetDate )
                {
                    ccy[parseInt(em.currency_id)] = parseFloat(em.currency_rate);
                }
            }

            //console.log(ccy);
        }
        catch(e){}

        var targetFx = ccy[result_currency_id];

        for( var i = 0; i < sel.length; i++ )
        {
            v = sel[i];
            opt = $('#merge_transactions option[value="' + v + '"]');
            if(!opt)
                 continue;

            currency_id     = parseInt($(opt).attr('data-currency-id'));
            amount          = parseFloat($(opt).attr('data-amount'));
            c_date          = $(opt).attr('data-date');
            currency_rate   = parseFloat($(opt).attr('data-currency-rate'));

            if( result_currency_id == currency_id )
            {
                total += amount;
            }
            else
            {
                if( currency_id == 1)
                {
                    total += amount / targetFx;
                }
                else
                {
                    var eur_amount = amount * currency_rate;
                    total += eur_amount / targetFx;
                }
            }
        }

        total = total.toFixed(4);

        var html = '<b>' + number_format(total, 2, '.', ',') + ' ' + $('#ocpa_currency_id :selected').text() + " ";
        html += "( Fx rates for " + targetDate + ": " + ccy[2] + " GBP, " + ccy[3] + " USD )";
        html += "</b>";

        $('#ocpa_merge_fx_info').html( html );
    }

    function showOCPAForReturn(val)
    {
      $.ajax({
        type: "POST",
        url: "?do=getocpa&return=1&originator_id=" + val,
        success: function(msg){

          if(document.getElementById("payment_return")) {
            document.getElementById("payment_return").innerHTML = msg;
          }

          $('#d_payment_return').show();
        }
      });
    }

  function showOCPA(val)
  {
      $transaction_type = $("#transaction_type").val();
      $url = "?do=getocpa&originator_id=" + val;
      if($transaction_type == <?php echo @OCPA_TO_ICP; ?>
){
          $url += "&without_fees=1";
      }
      $.ajax({
          type: "POST",
          url: $url,
          success: function(msg){

              if(document.getElementById("ocpa_cell")) {
                  document.getElementById("ocpa_cell").innerHTML = msg;
              }

              $('#ocpa_row').show();
          }
      });
  }

  var OCPA_Split = {};

  function base64_decode( data ) {	// Decodes data encoded with MIME base64
      //
      // +   original by: Tyler Akins (http://rumkin.com)


      var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
      var o1, o2, o3, h1, h2, h3, h4, bits, i=0, enc='';

      do {  // unpack four hexets into three octets using index points in b64
          h1 = b64.indexOf(data.charAt(i++));
          h2 = b64.indexOf(data.charAt(i++));
          h3 = b64.indexOf(data.charAt(i++));
          h4 = b64.indexOf(data.charAt(i++));

          bits = h1<<18 | h2<<12 | h3<<6 | h4;

          o1 = bits>>16 & 0xff;
          o2 = bits>>8 & 0xff;
          o3 = bits & 0xff;

          if (h3 == 64)	  enc += String.fromCharCode(o1);
          else if (h4 == 64) enc += String.fromCharCode(o1, o2);
          else			   enc += String.fromCharCode(o1, o2, o3);
      } while (i < data.length);

      return enc;
  }

  function showOCPACreditors(val)
  {
      $.ajax({
          type: "POST",
          url: "?do=getocpa_list&transaction_id=" + val,
          success: function(msg){

              if(document.getElementById("ocpa_cell_creditors")) {
                  document.getElementById("ocpa_cell_creditors").innerHTML = msg;

                  OCPA_Split.transaction    = JSON.parse( base64_decode($('#ocpa_transaction_info').val()) );
                  OCPA_Split.rates          = JSON.parse( base64_decode($('#ocpa_rates_info').val()) );
              }

              $('#ocpa_row_creditors').show();

              $('[ocpa-input]').unbind('keyup');
              $('[ocpa-select]').unbind('change');

              $('[ocpa-input]').on('keyup', OCPA_Split_CheckAmount);
              $('[ocpa-select]').on('change', OCPA_Split_CheckAmount);
          }
      });
  }

    function number_format (number, decimals, dec_point, thousands_sep) {

        number = (number + '')
                .replace(/[^0-9+\-Ee.]/g, '')
        var n = !isFinite(+number) ? 0 : +number,
                prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
                sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
                dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
                s = '',
                toFixedFix = function (n, prec) {
                    var k = Math.pow(10, prec)
                    return '' + (Math.round(n * k) / k)
                                    .toFixed(prec)
                }
        // Fix for IE parseFloat(0.55).toFixed(0) = 0;
        s = (prec ? toFixedFix(n, prec) : '' + Math.round(n))
                .split('.')
        if (s[0].length > 3) {
            s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep)
        }
        if ((s[1] || '')
                        .length < prec) {
            s[1] = s[1] || ''
            s[1] += new Array(prec - s[1].length + 1)
                    .join('0')
        }
        return s.join(dec)
    }

  function OCPA_Split_CheckAmount()
  {
      var check_amt = OCPA_Split.transaction.amount;

      var rates_map = new Array;

      rates_map[1] = 1;

      for( var i = 0; i < OCPA_Split.rates.length; i++ )
      {
          rates_map[OCPA_Split.rates[i].currency_id] = OCPA_Split.rates[i].currency_rate;
      }

      if( OCPA_Split.transaction.currency_code != 'EUR' )
      {
            check_amt = check_amt * rates_map[ OCPA_Split.transaction.currency_id ];
      }

      //console.log(check_amt);

      var total_amt = 0;

      var exisiting_creditors = new Array;
      var duplicate_creditors = false;

      for( var i = 0; i < 100; i++)
      {
          if( $('#ocpa_creditor_row_' + i).is(':visible') )
          {
              var raw_amount = parseFloat($('#ocpa_amount_' + i).val());

              var ccy_id = $("#ocpa_creditor_" + i + " option:selected").attr('data-currency-id');
              var creditor_id = $("#ocpa_creditor_" + i + " option:selected").attr('value');
              var ccy_code = $("#ocpa_creditor_" + i + " option:selected").attr('data-currency');

              $('#ocpa_currency_div_' + i).html('&nbsp;'+ ccy_code);

               if( isNaN(raw_amount) || raw_amount < 0 )
                        continue;

              if(ccy_id != 1)
              {
                  raw_amount = raw_amount * rates_map[ ccy_id ];
              }

              total_amt += raw_amount;

              for( var kk = 0; kk < exisiting_creditors; kk++)
              {
                  if(exisiting_creditors[kk] == creditor_id )
                  {
                      duplicate_creditors = true;
                  }
              }

              exisiting_creditors.push(creditor_id);
          }
      }

      if(duplicate_creditors)
      {
          $("#ocpa_warning").html('Warning: Duplicate creditors are not allowed.');
      }
      else
      {
          $("#ocpa_warning").html('');
      }

      var comparable = check_amt - total_amt;

      if( OCPA_Split.transaction.currency_code != 'EUR' )
      {
          comparable = comparable / rates_map[ OCPA_Split.transaction.currency_id ];
      }

      $('#ocpa_amount_left').html( number_format(comparable, 2, '.', ',') );
  }

  function SaveOCPA()
  {
      var ocpa_left = parseFloat($('#ocpa_amount_left').html());

      if( ocpa_left < 0 )
       {
           return alert('Amount left should be greater or equal to zero.');
       }

      if( $('#ocpa_warning').html()  != '' )
      {
          return alert('Please verify creditors - You have duplicates in Your list!');
      }

      $('#save_transaction').submit();
  }

  function OCPASplitAdd(current)
  {
        if(current > 0)
        {
            $('#ocpa_creditor_row_' + (current + 1)).show();
        }
  }

  function OCPASplitDelete(current)
  {
      if(current > 1)
      {
          $('#ocpa_creditor_row_' + (current)).hide();

          $('#ocpa_amount_' + (current)).val('');
          $('#ocpa_creditor_' + (current)).val('');
      }
  }

  function showFields(val)
  {

    $("#amount").removeAttr('readonly');
    $(".login_bttn").removeAttr('disabled');
    $("#is_aetr").attr('disabled', true);


      $('input[type="submit"]').show();
      $('#save_ocpa').hide();
      $('#row_is_aetr').hide();


      if( val == <?php echo @OCPA_TO_ICP; ?>
 )
      {
          $('input[type="submit"]').hide();
          $('#save_ocpa').show();
      }

      if( val != <?php echo @ORIGINATOR_DEPOSIT; ?>
 )
      {
          $('#row_rpas').hide();
      }

      if( val != <?php echo @DEPOSIT_TO_OCPA; ?>
 )
      {
          $('#row_deposit').hide();
      }


      $('#row_split_payments_1').hide();
      $('#row_split_payments_2').hide();
      $('#ocpa_row').hide();
      $('#ocpa_row_creditors').hide();
      $('#ocpa_cell_creditors').html('');
      $('.row_split_payments').hide();
      $('#row_ocpa_commisions').hide();
      $('#row_credit_note_no').hide();
      $('#row_tb_return').hide();
      /* $('#row_aetr').hide();
      $('#row_aetr_asset').hide();
      <?php if (isset ( $this->_tpl_vars['a_etr_html'] )): ?>
        $('#row_aetr').show();
        if (val == <?php echo @INBOUND_DEBTOR_PAYMENT; ?>
 || val == <?php echo @INBOUND_CREDITOR_PAYMENT; ?>
){
          $('#row_aetr_asset').show();
        }
		showHideWithAllocation(false);
      <?php endif; ?> */

      $('[name="transaction_file"]').removeAttr('accept');

    if(val=='')
    {
        $('#notification').show();
        $('#row_originator_id,#row_debtor_id,#row_amount,#row_date,#row_balance,#row_notes,#row_reconcile,#row_reference_to,#row_deductible,#row_trailing').hide();
        $('#rem_notification,#rec_notification,#row_reconcile,#row_multiple_payments').hide();
    }
    else if(val==<?php echo @INBOUND_DEBTOR_PAYMENT; ?>
 ||
            val== <?php echo @MERGE_INBOUND_DEBTOR_PAYMENT; ?>
 || val== <?php echo @SPLIT_INBOUND_DEBTOR_PAYMENT; ?>

            || val== <?php echo @OCPA_TO_ICP; ?>
 || val== <?php echo @ICP_SPLIT; ?>

            || val== <?php echo @ICP_MERGE; ?>
 || val== <?php echo @OCPA_MERGE; ?>

        )
    {

        if( val == <?php echo @OCPA_MERGE; ?>
 )
        {
          $('#row_ocpa_currency_id').show();
          $('#ocpa_currency_id').unbind('change');

          $('#ocpa_currency_id').change(  OCPAMerge_onChange );
        }
        else
        {
          $('#row_ocpa_currency_id').hide();
        }

        if( val ==  <?php echo @OCPA_TO_ICP; ?>
)
        {
            $('#row_split_payments_1').hide();
            $('#row_split_payments_2').hide();
            $('.row_split_payments').hide();
            $('#row_debtor_id').hide();
        }

      $.ajax({
        type: "POST",
        url: "?do=getoriginatorlist&type=" + val,
        success: function(msg){

          $('#d_originators').hide();
          $('#originators').show();

          if( val ==  <?php echo @OCPA_TO_ICP; ?>
)
          {
              $('#row_split_payments_1').hide();
              $('#row_split_payments_2').hide();
              $('.row_split_payments').hide();
              $('#row_debtor_id').hide();
          }

          if(document.getElementById("originators")) {
            document.getElementById("originators").innerHTML = msg;
          }
        }
      });

      $('#row_date').removeClass('row1');
      $('#row_date').addClass('row2');

      $('#row_amount').removeClass('row2');
      $('#row_amount').addClass('row1');

      $('#row_notes').removeClass('row2');
      $('#row_notes').addClass('row1');


      $('#row_transaction_file,#row_reconcile').hide();
      $('#row_originator_id').show();
      $('#row_notes').show();
      $('#row_debtor_id').show();
      $('#row_amount').show();
      $('#currency').show();
      $('#err_currency').hide();
      $('#row_reference_to,#fx_rate_notify').hide();
      $('#row_balance,#withallocation').show();
      $('#err_fx_rate_notify,#row_fx_rate').show();
      $('#row_paying_reserve,#row_multiple_payments,#row_transaction_name,#row_notification,#row_payment_return').hide();

      if( val== <?php echo @SPLIT_INBOUND_DEBTOR_PAYMENT; ?>
 )
      {
        $('#row_split_payments_1').show();
        $('#row_split_payments_2').show();
      }

        if( val== <?php echo @ICP_SPLIT; ?>
 )
        {
            $('#row_split_payments_1').show();
            $('#row_split_payments_2').show();
        }

        if( val== <?php echo @OCPA_TO_ICP; ?>
 )
        {
            $('#row_split_payments_1').hide();
            $('#row_split_payments_2').hide();
            $('#row_debtor_id').hide();
        }

    }
    else if(val==<?php echo @TRANSFER_OF_PAYMENT_BY_ORIGINATOR; ?>
 || val==<?php echo @PAID_DIRECTLY_TO_ORIGINATOR; ?>
)
    {
      $.ajax({
        type: "POST",
        url: "?do=getoriginatorlist",
        success: function(msg){

          $('#d_originators').hide();
          $('#originators').show();

          if(document.getElementById("originators")) {
            document.getElementById("originators").innerHTML = msg;
          }
        }
      });


      $('#row_date').removeClass('row1');
      $('#row_date').addClass('row2');

      $('#row_amount').removeClass('row2');
      $('#row_amount').addClass('row1');

      $('#row_notes').removeClass('row1');
      $('#row_notes').addClass('row2');

      $('#row_transaction_file,#row_reconcile').hide();
      $('#row_originator_id').show();
      $('#row_notes').show();
      $('#row_debtor_id').show();
      $('#row_amount').show();
      $('#currency').show();

      if($('#err_currency').length) {
        $('#err_currency').hide();
      }

      $('#row_reference_to').hide();
      $('#row_balance').show();

      if($('#withallocation').length) {
        $('#withallocation').show();
      }

      $('#fx_rate_notify').hide();
      $('#err_fx_rate_notify').show();
      $('#row_fx_rate').show();
      $('#row_notification').hide();
      $('#row_transaction_name').hide();
      $('#row_paying_reserve').hide();
      $('#row_multiple_payments,#row_payment_return').hide();
    }
    else if(val==<?php echo @NOTICE_OF_DEBTOR_REMITTANCE; ?>
)
    {
      $.ajax({
        type: "POST",
        url: "?do=getoriginatorlist",
        success: function(msg){

          $('#d_originators').hide();
          $('#originators').show();

          if(document.getElementById("originators")) {
            document.getElementById("originators").innerHTML = msg;
          }
        }
      });

      $('#row_date').removeClass('row1');
      $('#row_date').addClass('row2');

      $('#row_transaction_file').show();
      $('#row_notes').show();
      // $('#row_debtor_id').hide();
      $('#row_debtor_id').show();      
      // $('#row_amount').hide();
      $('#row_amount').show();
      $('#currency').hide();
      $('#err_currency').hide();
      $('#row_reference_to').hide();
      $('#row_balance').hide();
      $('#row_originator_id').show();
      $('#withallocation').hide();
      $('#fx_rate_notify').hide();
      $('#err_fx_rate_notify').hide();
      $('#row_fx_rate').hide();
      $('#row_notification').hide();
      $('#row_transaction_name').hide();
      $('#row_paying_reserve').hide();
      $('#row_reconcile').hide();
      $('#row_multiple_payments,#row_payment_return').hide();
    }
    else if(val==<?php echo @CREDIT_NOTE; ?>
 || val==<?php echo @EXTERNAL_BANK_CHARGES; ?>
 || val==<?php echo @VARIANCE_ON_FOREIGN_EXCHANGE; ?>
 || val==<?php echo @POSITIVE_RESERVE_ADJUSTMENT; ?>
)
    {
      $.ajax({
        type: "POST",
        url: "?do=getoriginatorlist",
        success: function(msg){

          $('#d_originators').hide();
          $('#originators').show();

          if(document.getElementById("originators")) {
            document.getElementById("originators").innerHTML = msg;
          }
        }
      });


      $('#row_date').removeClass('row1');
      $('#row_date').addClass('row2');

      $('#row_amount').removeClass('row2');
      $('#row_amount').addClass('row1');

      $('#row_notes').removeClass('row1');
      $('#row_notes').addClass('row2');

      $('#row_transaction_file,#row_reconcile').hide();
      $('#row_originator_id').show();
      $('#row_notes').show();
      $('#row_debtor_id').show();
      $('#row_amount').show();
      $('#row_balance').hide();
      $('#currency').show();
      $('#err_currency').hide();
      $('#row_reference_to').hide();
      $('#row_transaction_file').show();
      // $('#row_balance').show();
      $('#withallocation').hide();
      $('#fx_rate_notify').hide();
      $('#err_fx_rate_notify').show();
      $('#row_fx_rate').show();
      $('#row_notification').hide();
      $('#row_transaction_name').hide();
      $('#row_paying_reserve').hide();
      $('#row_multiple_payments,#row_payment_return').hide();
      if(val == <?php echo @CREDIT_NOTE; ?>
){
        $('#row_credit_note_no').show();
      }
      if(val == <?php echo @POSITIVE_RESERVE_ADJUSTMENT; ?>
){
        $('[name="transaction_file"]').attr('accept', '.pdf,.doc,.docx,.xls,.xlsx');
      }
    }
    else if(val==<?php echo @RECONCILE_DEBTOR_ACCOUNT; ?>
)
    {

      var today = new Date();

      var day = ("0" + today.getDate().toString()).substr(-2);
      var month = ("0" + (today.getMonth() + 1).toString()).substr(-2);
      var year  = today.getFullYear();

      $('#trans_date').val(day);
      $('#trans_month').val(month);
      $('#trans_year').val(year);
      
      $.ajax({
        type: "POST",
        url: "?do=getoriginatorlist",
        success: function(msg){

          $('#d_originators').hide();
          $('#originators').show();

          if(document.getElementById("originators")) {
            document.getElementById("originators").innerHTML = msg;
          }
        }
      });

      $('#row_date').removeClass('row2');
      $('#row_date').addClass('row1');

      $('#row_transaction_file').hide();
      $('#row_notes').show();
      // $('#row_debtor_id').hide();
      $('#row_debtor_id').show();

      $('#row_amount').hide();


      $('#currency').hide();
      $('#err_currency').hide();
      $('#row_reference_to').hide();
      $('#row_balance').show();
      $('#row_originator_id').show();

      $('#withallocation').hide();

      $('#fx_rate_notify').hide();
      $('#err_fx_rate_notify').show();
      $('#row_fx_rate').hide();
      $('#row_notification').hide();
      $('#row_transaction_name').hide();
      $('#row_paying_reserve').hide();
      $('#row_reconcile').show();
      $('#row_multiple_payments,#row_payment_return').hide();

    }
    else if(val==<?php echo @ORIGINATOR_PAYMENT_ON_ACCOUNT; ?>
 || val==<?php echo @CREDITOR_FEES_CHARGES; ?>

        || val==<?php echo @ORIGINATOR_DEPOSIT; ?>
 || val==<?php echo @DEPOSIT_TO_OCPA; ?>

  )
    {
        $.ajax({
            type: "POST",
            url: "?do=getoriginatorlist",
            success: function(msg){

              $('#d_originators').hide();
              $('#originators').show();

              if(document.getElementById("originators")) {
                document.getElementById("originators").innerHTML = msg;
              }
            }
          });

      $('#row_date').removeClass('row2');
      $('#row_date').addClass('row1');

      $('#row_amount').removeClass('row1');
      $('#row_amount').addClass('row2');

      $('#row_transaction_file').hide();
      $('#row_debtor_id').hide();
      $('#row_amount').show();
      $('#currency').show();
      $('#err_currency').show();
      $('#row_notes').show();
      $('#row_reference_to').hide();
      $('#row_balance').hide();
      $('#row_originator_id').show();
      $('#withallocation').hide();
      $('#fx_rate_notify').hide();
      $('#err_fx_rate_notify').hide();
      $('#row_fx_rate').hide();
      $('#row_notification').hide();
      $('#row_transaction_name').hide();
      $('#row_paying_reserve').hide();
      $('#row_reconcile').hide();
      $('#row_multiple_payments,#row_payment_return').hide();
      $('#row_ocpa_currency_id').hide();
      if($("#originator_id").val() == 0) {
          $("#currency_id").hide();
          $("#currency_id option[value='']").attr('selected', true);
      }
      if(val==<?php echo @ORIGINATOR_PAYMENT_ON_ACCOUNT; ?>
)
      {
         $('#row_ocpa_commisions').show();
      }

    }
    else if( val == <?php echo @OCPA_RETURN; ?>
)
    {
      $('#row_date').removeClass('row2');
      $('#row_date').addClass('row1');

      $('#row_amount').hide();

      $('#row_transaction_file').hide();
      $('#row_debtor_id').hide();
      $('#currency').hide();
      $('#err_currency').hide();
      $('#row_notes').show();
      $('#row_reference_to').hide();
      $('#row_balance').hide();
      $('#row_originator_id').show();
      $('#withallocation').hide();
      $('#fx_rate_notify').hide();
      $('#err_fx_rate_notify').hide();
      $('#row_fx_rate').hide();
      $('#row_notification').hide();
      $('#row_transaction_name').hide();
      $('#row_paying_reserve').hide();
      $('#row_reconcile').hide();
      $('#row_multiple_payments').hide();

      $('#row_payment_return').show();
      $('#d_payment_return').show();
      $('#payment_return').show();

      $.ajax({
        type: "POST",
        url: "?do=getoriginatorlist&type=" + val,
        success: function(msg){

          $('#d_originators').hide();
          $('#originators').show();

          if(document.getElementById("originators")) {
            document.getElementById("originators").innerHTML = msg;
          }
        }
      });


    }
    else if(val==<?php echo @BANK_TRANSMISSION_RECEIPT; ?>
)
    {
      $.ajax({
        type: "POST",
        url: "?do=getoriginatorlist",
        success: function(msg){

          $('#d_originators').hide();
          $('#originators').show();

          if(document.getElementById("originators")) {
            document.getElementById("originators").innerHTML = msg;
          }
        }
      });

      $('#row_date').removeClass('row1');
      $('#row_date').addClass('row2');

      $('#row_notes').removeClass('row2');
      $('#row_notes').addClass('row1');

      $('#row_debtor_id').show();
      $('#row_transaction_file').show();
      $('#row_notes').show();
      $('#row_amount').show();      
      $('#currency').hide();
      $('#err_currency').hide();
      $('#row_reference_to').hide();
      $('#row_balance').hide();
      $('#row_originator_id').show();
      $('#withallocation').hide();
      $('#fx_rate_notify').hide();
      $('#err_fx_rate_notify').hide();
      $('#row_fx_rate').hide();
      $('#row_notification').hide();
      $('#row_transaction_name').hide();
      $('#row_paying_reserve').hide();
      $('#row_reconcile').hide();
      $('#row_multiple_payments,#row_payment_return').hide();
    }
    else if(val==<?php echo @SUBMIT_NOTIFICATION; ?>
)
    {
      $.ajax({
        type: "POST",
        url: "?do=getoriginatorlist",
        success: function(msg){

          $('#d_originators').hide();
          $('#originators').show();

          if(document.getElementById("originators")) {
            document.getElementById("originators").innerHTML = msg;
          }
        }
      });

      $('#row_date').removeClass('row1');
      $('#row_date').addClass('row2');

      $('#row_notes').removeClass('row2');
      $('#row_notes').addClass('row1');

      $('#row_transaction_file').show();
      $('#row_notes').show();
      $('#row_debtor_id').hide();      
      $('#row_amount').hide();
      $('#currency').hide();
      $('#err_currency').hide();
      $('#row_reference_to').hide();
      $('#row_balance').hide();
      $('#row_originator_id').show();
      $('#withallocation').hide();
      $('#fx_rate_notify').hide();
      $('#err_fx_rate_notify').hide();
      $('#row_fx_rate').hide();
      $('#row_notification').show();
      $('#row_transaction_name').show();
       $('#row_paying_reserve').hide();
       $('#row_reconcile').hide();
      $('#row_multiple_payments,#row_payment_return').hide();

    }
    else if(val==<?php echo @DATED_RESERVE_PAYMENT; ?>
)
    {
      $.ajax({
        type: "POST",
        url: "?do=getoriginatorlist",
        success: function(msg){
          $('#d_originators').hide();
          $('#originators').show();

          if(document.getElementById("originators")) {
            document.getElementById("originators").innerHTML = msg;
          }
        }
      });

      $('#row_date').removeClass('row1');
      $('#row_date').addClass('row2');
      
      $('#row_amount').removeClass('row2');
      $('#row_amount').addClass('row1');
      
      $('#row_notes').removeClass('row1');
      $('#row_notes').addClass('row2');
    
      $('#row_transaction_file').hide();
      $('#row_originator_id').show();
      $('#row_notes').show();
      $('#row_debtor_id').show();
      $('#row_amount').show();
      $('#amount').attr('readonly','readonly');
      $('#currency').show();
      $('#err_currency').hide();
      $('#row_reference_to').hide();
      $('#row_balance').show();
      $('#withallocation').hide();
      $('#fx_rate_notify').hide();
      $('#err_fx_rate_notify').hide();
      $('#row_fx_rate').hide();
      $('#row_notification').hide();
      $('#row_transaction_name').hide();
      $('#row_reconcile').hide();
      $('#row_multiple_payments,#row_payment_return').hide();
    }
    else if( val==<?php echo @FALSE_PAYMENT_RETURNED; ?>
 || val==<?php echo @TB_RETURN; ?>
 )
    {
      $.ajax({
        type: "POST",
        url: "?do=getoriginatorlist",
        success: function(msg){

          $('#d_originators').hide();
          $('#originators').show();

          if(document.getElementById("originators")) {
            document.getElementById("originators").innerHTML = msg;
          }
        }
      });

      $('#row_date').removeClass('row2');
      $('#row_date').addClass('row1');

      $('#row_transaction_file,#row_reconcile').hide();
      $('#row_notes').show();
      // $('#row_debtor_id').hide();
      $('#row_debtor_id').show();

      $('#row_amount').hide();
      $('#currency').hide();
      $('#err_currency').hide();
      $('#row_reference_to').hide();
      $('#row_balance').hide();
      $('#row_originator_id').show();
      $('#withallocation').hide();
      $('#fx_rate_notify').hide();
      $('#err_fx_rate_notify').show();
      $('#row_fx_rate').hide();
      $('#row_notification').hide();
      $('#row_transaction_name').hide();
      $('#row_paying_reserve').hide();
      $('#row_payment_return').show();
      $('#row_multiple_payments').hide();
      if(val==<?php echo @TB_RETURN; ?>
){
        $('#row_payment_return').hide();
        $('#row_date').hide();
        $('#row_tb_return').show();
        $('#row_balance').show();
        $('#d_balance').hide();
        $('#balance').show();
        $('#balance').html('0.00');
      }
    }
  else if( val==<?php echo @ICP_RETURN; ?>
 )
    {
      $.ajax({
        type: "POST",
        url: "?do=getoriginatorlist&type="+ val,
        success: function(msg){

          $('#d_originators').hide();
          $('#originators').show();

          if(document.getElementById("originators")) {
            document.getElementById("originators").innerHTML = msg;
          }
        }
      });

      $('#row_date').removeClass('row2');
      $('#row_date').addClass('row1');

      $('#row_transaction_file,#row_reconcile').hide();
      $('#row_notes').show();
      // $('#row_debtor_id').hide();
      $('#row_debtor_id').show();

      $('#row_amount').hide();
      $('#currency').hide();
      $('#err_currency').hide();
      $('#row_reference_to').hide();
      $('#row_balance').hide();
      $('#row_originator_id').show();
      $('#withallocation').hide();
      $('#fx_rate_notify').hide();
      $('#err_fx_rate_notify').show();
      $('#row_fx_rate').hide();
      $('#row_notification').hide();
      $('#row_transaction_name').hide();
      $('#row_paying_reserve').hide();
      $('#row_payment_return').show();
      $('#row_multiple_payments').hide();
    }
    else if(val==<?php echo @MULTIPLE_PAYMENTS; ?>
)
    {  
      $.ajax({
        type: "POST",
        url: "?do=getoriginatorlist",
        success: function(msg){

          $('#d_originators').hide();
          $('#originators').show();

          if(document.getElementById("originators")) {
            document.getElementById("originators").innerHTML = msg;
          }
        }
      });

      $('#row_date').removeClass('row2');
      $('#row_date').addClass('row1');

      $('#row_transaction_file').hide();
      $('#row_notes').show();
      // $('#row_debtor_id').hide();
      $('#row_debtor_id').show();

      $('#row_amount').hide();
      $('#currency').hide();
      $('#err_currency').hide();
      $('#row_reference_to').hide();
      $('#row_balance').show();
      $('#row_originator_id').show();
      $('#withallocation').hide();
      $('#fx_rate_notify').hide();
      $('#err_fx_rate_notify').show();
      $('#row_fx_rate').hide();
      $('#row_notification').hide();
      $('#row_transaction_name').hide();
      $('#row_paying_reserve').hide();
      $('#row_reconcile').hide();
      $('#row_multiple_payments,#row_payment_return').show();

    }
    else if(val==<?php echo @AMENDMENT_TO_INVOICE; ?>
)
    {
      $.ajax({
        type: "POST",
        url: "?do=getoriginatorlist",
        success: function(msg){

          $('#d_originators').hide();
          $('#originators').show();

          if(document.getElementById("originators")) {
            document.getElementById("originators").innerHTML = msg;
          }
        }
      });

      $('#row_date').removeClass('row1');
      $('#row_date').addClass('row2');

      $('#row_amount').removeClass('row2');
      $('#row_amount').addClass('row1');

      $('#row_notes').removeClass('row2');
      $('#row_notes').addClass('row1');


      $('#row_transaction_file,#row_reconcile').hide();
      $('#row_originator_id').show();
      $('#row_notes').show();
      $('#row_debtor_id').show();
      $('#row_amount').show();
      $('#currency').show();
      $('#err_currency').hide();
      $('#row_reference_to').hide();
      // $('#row_balance').show();
      $('#row_balance').hide();      
      $('#withallocation').hide();
      $('#fx_rate_notify').hide();
      $('#err_fx_rate_notify').show();
      $('#row_fx_rate').show();
      $('#row_notification').hide();
      $('#row_transaction_name').hide();
      $('#row_paying_reserve').hide();
      $('#row_multiple_payments,#row_payment_return').hide();

    }
    else if(val==<?php echo @CREDITOR_OUTBOUND_PAYMENT; ?>
)
    {
        $.ajax({
            type: "POST",
            url: "?do=getoriginatorlist",
            success: function(msg){

              $('#d_originators').hide();
              $('#originators').show();

              if(document.getElementById("originators")) {
                document.getElementById("originators").innerHTML = msg;
              }
            }
          });
          
          $('#row_date').removeClass('row1');
          $('#row_date').addClass('row2');
          
          $('#row_amount').removeClass('row2');
          $('#row_amount').addClass('row1');
          
          $('#row_notes').removeClass('row1');
          $('#row_notes').addClass('row2');
          
          $('#row_transaction_file').hide();
          $('#row_originator_id').show();
          $('#row_notes').show();
          $('#row_debtor_id').show();
          $('#row_amount').show();
          $('#amount').attr('readonly','readonly');
          $('#currency').show();
          $('#err_currency').hide();
          $('#row_reference_to').hide();
          $('#row_balance').show();
          $('#withallocation').hide();
          $('#fx_rate_notify').hide();
          $('#err_fx_rate_notify').hide();
          $('#row_fx_rate').hide();
          $('#row_notification').hide();
          $('#row_transaction_name').hide();
          $('#row_reconcile').hide();
          $('#row_multiple_payments,#row_payment_return').hide();
    }
    else if(val==<?php echo @INBOUND_CREDITOR_PAYMENT; ?>
)
    {
        $.ajax({
            type: "POST",
            url: "?do=getoriginatorlist",
            success: function(msg){

                $('#d_originators').hide();
                $('#originators').show();

              if(document.getElementById("originators")) {
                document.getElementById("originators").innerHTML = msg;
              }
            }
        });

        $('#row_date').removeClass('row1');
        $('#row_date').addClass('row2');

        $('#row_amount').removeClass('row2');
        $('#row_amount').addClass('row1');

        $('#row_notes').removeClass('row2');
        $('#row_notes').addClass('row1');


        $('#row_transaction_file,#row_reconcile,#row_deductible').hide();
        $('#row_originator_id').show();
        $('#row_notes').show();
        $('#row_debtor_id').show();
        $('#row_amount').show();
        $('#currency').show();
        $('#err_currency').hide();
        $('#row_reference_to,#fx_rate_notify').hide();
        $('#row_balance,#withallocation').show();
        $('#err_fx_rate_notify,#row_fx_rate').show();
        $('#row_paying_reserve,#row_multiple_payments,#row_transaction_name,#row_notification,#row_payment_return').hide();
    }
    else if(val==<?php echo @RECONCILE_CREDITOR_ACCOUNT; ?>
)
    {
      var today = new Date();

      var day = ("0" + today.getDate().toString()).substr(-2);
      var month = ("0" + (today.getMonth() + 1).toString()).substr(-2);
      var year  = today.getFullYear();

      $('#trans_date').val(day);
      $('#trans_month').val(month);
      $('#trans_year').val(year);

      $.ajax({
        type: "POST",
        url: "?do=getoriginatorlist",
        success: function(msg){

          $('#d_originators').hide();
          $('#originators').show();

          if(document.getElementById("originators")) {
            document.getElementById("originators").innerHTML = msg;
          }
        }
      });

      $('#row_date').removeClass('row2');
      $('#row_date').addClass('row1');

      $('#row_transaction_file').hide();
      $('#row_notes').show();
      // $('#row_debtor_id').hide();
      $('#row_debtor_id').show();

      $('#row_amount').hide();
      $('#currency').hide();
      $('#err_currency').hide();
      $('#row_reference_to').hide();
      $('#row_balance').show();
      $('#row_originator_id').show();
      $('#withallocation').hide();
      $('#fx_rate_notify').hide();
      $('#err_fx_rate_notify').show();
      $('#row_fx_rate').hide();
      $('#row_notification').hide();
      $('#row_transaction_name').hide();
      $('#row_paying_reserve').hide();
      $('#row_reconcile').show();
      $('#row_multiple_payments,#row_payment_return').hide();

    }

    if( val == '<?php echo @MERGE_INBOUND_DEBTOR_PAYMENT; ?>
' ) {
      $('#row_originator_id').show();
      $('#row_debtor_id').show();
      //$('#debtor_id').unbind('change');
      //$('#debtor_id').attr('onchange', '');
      $('#debtor_id').on('change', showTradesForMerge);
      showTradesForMerge();
    }
    else
    {
      if( val == '<?php echo @OCPA_MERGE; ?>
'  )
      {
        $('#row_originator_id').show();
        $('#row_debtor_id').show();
        showTradesForMergeOCPA();
      }
      else
        {
        if (val == '<?php echo @ICP_MERGE; ?>
') {
          $('#row_originator_id').show();
          $('#row_debtor_id').show();
          $('#debtor_id').on('change', showTradesForMergeICP);
          showTradesForMergeICP();
        }
        else {
          $('#row_merge_payments').hide();
        }
      }
    }

    if( val == '<?php echo @SPLIT_INBOUND_DEBTOR_PAYMENT; ?>
' || val == '<?php echo @OCPA_TO_ICP; ?>
' )
    {
      $('#row_originator_id').show();
      $('#row_debtor_id').show();
      //$('#debtor_id').unbind('change');
      //$('#debtor_id').attr('onchange', '');
      $('#debtor_id').on('change', showTradesForSplit);

      $('#row_split_payments_1').show();
      $('#row_split_payments_2').show();

      showTradesForSplit();
    }
    else
    {
        if( val == '<?php echo @ICP_SPLIT; ?>
' ) {
            $('#row_originator_id').show();
            $('#row_debtor_id').show();
            //$('#debtor_id').unbind('change');
            //$('#debtor_id').attr('onchange', '');
            $('#debtor_id').on('change', showTradesForSplitICP);

            $('#row_split_payments_1').show();
            $('#row_split_payments_2').show();

            showTradesForSplitICP();
        }
        else {
            $('.row_split_payments').hide();
        }
    }

    if(val != '<?php echo @RECONCILE_DEBTOR_ACCOUNT; ?>
' && val != <?php echo @RECONCILE_CREDITOR_ACCOUNT; ?>
)
    {

      date1 = '<?php echo $this->_tpl_vars['values']['trans_date']; ?>
';
      month1 = '<?php echo $this->_tpl_vars['values']['trans_month']; ?>
';
      year1 = '<?php echo $this->_tpl_vars['values']['trans_year']; ?>
';

      if(date1=='' && month1=='' && year1==''){

        $('#trans_date').val('');
        $('#trans_month').val('');
        $('#trans_year').val('');
      }

    }


    if(  val == <?php echo @INBOUND_CREDITOR_PAYMENT; ?>

      || val == <?php echo @RECONCILE_CREDITOR_ACCOUNT; ?>

      || val == <?php echo @CREDITOR_OUTBOUND_PAYMENT; ?>

      || val == <?php echo @MERGE_INBOUND_DEBTOR_PAYMENT; ?>

      || val == <?php echo @SPLIT_INBOUND_DEBTOR_PAYMENT; ?>

      || val == <?php echo @OCPA_TO_ICP; ?>

      || val == <?php echo @ICP_SPLIT; ?>

      || val == <?php echo @ICP_MERGE; ?>

      || val == <?php echo @OCPA_MERGE; ?>

      )
        {
          $('#deductibles').hide();
          $('#rec_deductibles').hide();
        }
    if(val == <?php echo @INBOUND_DEBTOR_PAYMENT; ?>

	  || val == <?php echo @TRANSFER_OF_PAYMENT_BY_ORIGINATOR; ?>

	  || val == <?php echo @PAID_DIRECTLY_TO_ORIGINATOR; ?>

	  || val == <?php echo @FALSE_PAYMENT_RETURNED; ?>

	  || val == <?php echo @INBOUND_CREDITOR_PAYMENT; ?>

	  || val == <?php echo @ORIGINATOR_PAYMENT_ON_ACCOUNT; ?>

	  || val == <?php echo @ORIGINATOR_DEPOSIT; ?>

	  || val == <?php echo @OCPA_RETURN; ?>

	  || val == <?php echo @ICP_RETURN; ?>

	  || val == <?php echo @CREDIT_NOTE; ?>
){
        $('#row_is_aetr').show();
		$("#is_aetr").removeAttr('disabled');
    }
	//checkIsAEtr(0);
  }

  function showCurrency(val)
  {
     val ='';

     trans_type = $("#transaction_type option:selected").val();


      if( trans_type == '<?php echo @DEPOSIT_TO_OCPA; ?>
')
      {
          $.ajax({
              type: "POST",
              url: "?do=getdeposits",
              data: "id="+$("#originator_id option:selected").val(),
              success: function(msg)
              {

                  document.getElementById("deposits").innerHTML=msg;
                  $('#row_deposits').show();
                  $('#row_date').hide();
                  $('#row_amount').hide();
              }
          });

          return;
      }

     if(trans_type=='<?php echo @ORIGINATOR_PAYMENT_ON_ACCOUNT; ?>
' || trans_type=='<?php echo @CREDITOR_FEES_CHARGES; ?>
' || trans_type=='<?php echo @INBOUND_DEBTOR_PAYMENT; ?>
' || trans_type=='<?php echo @TRANSFER_OF_PAYMENT_BY_ORIGINATOR; ?>
' || trans_type=='<?php echo @PAID_DIRECTLY_TO_ORIGINATOR; ?>
' || trans_type=='<?php echo @INBOUND_CREDITOR_PAYMENT; ?>
' || trans_type=='<?php echo @ORIGINATOR_DEPOSIT; ?>
'  )
     {
        if($("#originator_id option:selected").val()!=undefined){

          $("#originator_id option:selected").each(function () {
                val += $(this).val();
            });

                $.ajax({
                type: "POST",
                url: "?do=getoriginatorcurrency",
                data: "id="+val,
                success: function(msg){

                  document.getElementById("currency").innerHTML=msg;
                  $('#currency').show();

                  if( trans_type == '<?php echo @ORIGINATOR_DEPOSIT; ?>
')
                  {
                      $.ajax({
                          type: "POST",
                          url: "?do=getrpas",
                          data: "id="+val,
                          success: function(msg){

                              document.getElementById("rpas").innerHTML=msg;
                              $('#row_rpas').show();
                          }
                      });

                  }
                }
              });

          
      }else{
        
        $('#currency').hide();
      }
    }



  }


  function showDebtors(flag)
  {
    val ='';

    if(flag=='change')
    {
        $("#originator_id option:selected").val('');
    }

    $('#row_merge_payments').hide();
    $('.row_split_payments').hide();

    if($("#originator_id option:selected").val()!=undefined)
    {
      $("#originator_id option:selected").each(function ()
      {
            val += $(this).val();

            var transaction_type = $('#transaction_type').val();

            if( transaction_type == 106 )
            {
              $('#row_debtor_id').hide();
              showTradesForMergeOCPA();
              return;
            }

            $.ajax({
                type: "POST",
                url: "?do=getdebtors&type="+$('#transaction_type option:selected').attr('type')+'&transaction_type=' + transaction_type,
                data: "id="+val,
                success: function(msg)
                {
                  $('#d_debtors').hide();
                  $('#debtors').show();

                  if(document.getElementById("debtors")) {
                    document.getElementById("debtors").innerHTML = msg;
					/* getAEtrs(flag); */
                    <?php if ($this->_tpl_vars['values']['debtor_id'] != ''): ?>
                      debtorId = <?php echo $this->_tpl_vars['values']['debtor_id']; ?>
;
                      if(debtorId){
                          $('#debtor_id').val(debtorId);
                      }
                    <?php endif; ?>
                  }
                }
            });
      });
    }
    else
    {
        $('#debtors').show();
        $('#d_debtors').hide();
    }
}

 function showFXRate()
 {}

 function  showTradesForMerge()
    {
        $("#row_date").hide();
        $("#row_amount").hide();
        $("#row_balance").hide();
        $("#row_merge_payments").hide();

        var originator_id = $("#originator_id").val();
        var debtor_id = $("#debtor_id").val();

        if( typeof(originator_id) == 'undefined' || typeof(debtor_id) == 'undefined' || originator_id == '' || debtor_id == '')
        {
            return;
        }

        $.ajax({
            type: "POST",
            url: "?do=getpaymentsformerge",
            data: {
                originator_id : originator_id,
                debtor_id: debtor_id
            },
            success: function(msg)
            {
                $('#merge_payments_cell').html(msg);
                $('#row_merge_payments').show();
            }
        });
    }

    function  showTradesForMergeICP()
    {
        $("#row_date").hide();
        $("#row_amount").hide();
        $("#row_balance").hide();
        $("#row_merge_payments").hide();
        $("#row_debtor_id").show();

        var originator_id = $("#originator_id").val();
        var debtor_id = $("#debtor_id").val();

        if( typeof(originator_id) == 'undefined' || typeof(debtor_id) == 'undefined' || originator_id == '' || debtor_id == '')
        {
            return;
        }

        $.ajax({
            type: "POST",
            url: "?do=getpaymentsformerge&icp=1",
            data: {
                originator_id : originator_id,
                debtor_id: debtor_id
            },
            success: function(msg)
            {
                $('#merge_payments_cell').html(msg);
                $('#row_merge_payments').show();
            }
        });
    }


    function  showTradesForMergeOCPA()
    {
      $("#row_date").hide();
      $("#row_amount").hide();
      $("#row_balance").hide();
      $("#row_merge_payments").hide();
      $("#row_debtor_id").hide();

      var originator_id = $("#originator_id").val();

      if( typeof(originator_id) == 'undefined' || originator_id == '' )
      {
        return;
      }

      $.ajax({
        type: "POST",
        url: "?do=getpaymentsformerge&ocpa=1",
        data: {
          originator_id : originator_id
        },
        success: function(msg)
        {
          $('#merge_payments_cell').html(msg);
          $('#row_merge_payments').show();
          $('#merge_transactions').change( OCPAMerge_onChange );
        }
      });
    }

    function  showTradesForSplitICP()
    {
        $("#row_date").hide();
        $("#row_amount").hide();
        $("#row_balance").hide();
        $(".row_split_payments").hide();

        var originator_id = $("#originator_id").val();
        var debtor_id = $("#debtor_id").val();

        if( typeof(originator_id) == 'undefined' || typeof(debtor_id) == 'undefined' || originator_id == '' || debtor_id == '')
        {
            return;
        }

        $.ajax({
            type: "POST",
            url: "?do=getpaymentsformerge&split=1&icp=1",
            data: {
                originator_id : originator_id,
                debtor_id: debtor_id
            },
            success: function(msg)
            {
                $('#split_payments_cell').html(msg);
                $('.row_split_payments').show();

                $(".login_bttn").attr('disabled', 'disabled');
            }
        });
    }

  function  showTradesForSplit()
  {
    $("#row_date").hide();
    $("#row_amount").hide();
    $("#row_balance").hide();
    $(".row_split_payments").hide();

    var originator_id = $("#originator_id").val();
    var debtor_id = $("#debtor_id").val();

    if( typeof(originator_id) == 'undefined' || typeof(debtor_id) == 'undefined' || originator_id == '' || debtor_id == '')
    {
      return;
    }

    $.ajax({
      type: "POST",
      url: "?do=getpaymentsformerge&split=1",
      data: {
        originator_id : originator_id,
        debtor_id: debtor_id
      },
      success: function(msg)
      {
        $('#split_payments_cell').html(msg);
        $('.row_split_payments').show();

        $(".login_bttn").attr('disabled', 'disabled');
      }
    });
  }

function showTrades(flag)
{
  if(flag==1){
    $('#rows_notify').hide();
  }

   $('#row_fx_rate').show();

   var transaction_type = $('#transaction_type').val();
   var trade_select     = $('#trade_select').checked;
    val ='';
    user_id = $('#originator_id').val();
    $("#debtor_id option:selected").each(function () {
          val += $(this).val() + ",";

    });
    

    var amounts = $('#amount').val();

    if(transaction_type=='<?php echo @MULTIPLE_PAYMENTS; ?>
')
    {
      view = '1';
    }
    else if(transaction_type=='<?php echo @AMENDMENT_TO_INVOICE; ?>
')
    {
      view = '2';
    }
    else
    {
      view = '0';
    }


    if( transaction_type == '<?php echo @MERGE_INBOUND_DEBTOR_PAYMENT; ?>
'
            || transaction_type == '<?php echo @ICP_MERGE; ?>
'
            || transaction_type == '<?php echo @OCPA_MERGE; ?>
')
    {
      return;
    }
  
       
    initialAmount = parseFloat(Math.round(amounts * 100) / 100);
  
  
    initialAmount = initialAmount.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  
          $('#balance').html(initialAmount);

    data="id="+$("#debtor_id").val()+"&user_id="+user_id+"&view="+view;
    
    
    if (transaction_type == '<?php echo @INBOUND_DEBTOR_PAYMENT; ?>
' || transaction_type == '<?php echo @TRANSFER_OF_PAYMENT_BY_ORIGINATOR; ?>
' || transaction_type == '<?php echo @PAID_DIRECTLY_TO_ORIGINATOR; ?>
' || transaction_type == '<?php echo @INBOUND_CREDITOR_PAYMENT; ?>
')
    {
        data+="&max_date="+$('#trans_year').val()+'-'+$('#trans_month').val()+'-'+$('#trans_date').val();
    }
    
    $.ajax({
        type: "POST",
        url: "?do=gettrades",
        data: data,
        success: function(msg)
        {
            $('#d_reference').hide();
            $('#reference').show();

            if($("#debtor_id option:selected").val()!=undefined && ($('#amount').val()!='' || transaction_type=='<?php echo @MULTIPLE_PAYMENTS; ?>
' || transaction_type=='<?php echo @AMENDMENT_TO_INVOICE; ?>
' || transaction_type=='<?php echo @CREDITOR_OUTBOUND_PAYMENT; ?>
'))
            {
                if(flag==1)
                {
                    if(document.getElementById("err_reference")) {
                        document.getElementById("err_reference").innerHTML = msg;
                    }
                }
                else
                {
                    try
                    {
                      document.getElementById("reference").innerHTML=msg;
                    }
                    catch(errs)
                    {
                      if((
                      (transaction_type == '<?php echo @INBOUND_DEBTOR_PAYMENT; ?>
' || transaction_type == '<?php echo @TRANSFER_OF_PAYMENT_BY_ORIGINATOR; ?>
' || transaction_type == '<?php echo @PAID_DIRECTLY_TO_ORIGINATOR; ?>
' || transaction_type == '<?php echo @INBOUND_CREDITOR_PAYMENT; ?>
')
                       && $('#trade_select').attr('checked')==true)  || transaction_type=='<?php echo @MULTIPLE_PAYMENTS; ?>
' || transaction_type=='<?php echo @AMENDMENT_TO_INVOICE; ?>
' || transaction_type=='<?php echo @CREDITOR_OUTBOUND_PAYMENT; ?>
' || transaction_type=='<?php echo @NEGATIVE_RESERVE_ADJUSTMENT; ?>
')
                      {
                                $('#row_reference_to').show();
                      }
                    }
                }
                if((
                    (transaction_type == '<?php echo @INBOUND_DEBTOR_PAYMENT; ?>
' || transaction_type == '<?php echo @TRANSFER_OF_PAYMENT_BY_ORIGINATOR; ?>
' || transaction_type == '<?php echo @PAID_DIRECTLY_TO_ORIGINATOR; ?>
' || transaction_type == '<?php echo @INBOUND_CREDITOR_PAYMENT; ?>
')
                     && $('#trade_select').attr('checked')==true) || transaction_type=='<?php echo @MULTIPLE_PAYMENTS; ?>
' || transaction_type=='<?php echo @AMENDMENT_TO_INVOICE; ?>
' || transaction_type=='<?php echo @CREDITOR_OUTBOUND_PAYMENT; ?>
')
                {
                  $('#row_reference_to').show();
                }
              }
              else
              {
                $('#row_reference_to').hide();
              }
          }
        });
}


function showReserveTrades(flag)
{
   var transaction_type = $('#transaction_type').val();
    val ='';
    user_id = $('#originator_id').val();
    $("#debtor_id option:selected").each(function () {
          val += $(this).val() + ",";

    });


    var amounts = $('#amount').val();
  
       
  initialAmount = parseFloat(Math.round(amounts * 100) / 100);
  
  initialAmount = initialAmount.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  
          $('#balance').html(initialAmount);

          $.ajax({
          type: "POST",
          url: "?do=getreservetrades",
          data: "id="+$("#debtor_id").val()+"&user_id="+user_id,
          success: function(msg){


            $('#d_paying_reserve').hide();
            $('#reserve').show();


              if($("#debtor_id option:selected").val()!=undefined)
              {
                if(flag==1){
                  document.getElementById("err_paying_reserve").innerHTML=msg;
                }else{
          
                    try{
                    
                      document.getElementById("reserve").innerHTML=msg;
                    }catch(errs){
                      if(transaction_type == '<?php echo @DATED_RESERVE_PAYMENT; ?>
' ){
                                $('#row_paying_reserve').show();
                      }
                    }
                }
                if(transaction_type == '<?php echo @DATED_RESERVE_PAYMENT; ?>
'){

                  $('#row_paying_reserve').show();
                }
              }else{
                $('#row_paying_reserve').hide();
              }

             
          }
        });
   
}

function getMultipleBalance(amt)
{
  val ='';
  payval = '';
  
  deductible = +$('#balance_deductible').val();
  trailing = +$('#trailing_balance_amt').val();

  transaction_type = $('#transaction_type').val();


  user_id = $('#originator_id').val();


  $("#reference_to option:selected").each(function () {

      var con;

          val +=  ","+$(this).val() ;
        
        });


 
    $("#multiple_payments option:selected").each(function () {

          payval +=  ","+$(this).val() ;
        
        });

        deb = $("#debtor_id option:selected").val()

        con="&id="+$("#debtor_id").val()+"&user_id="+user_id+"&debtor_id="+deb+"&multiple_payments="+payval;


          $.ajax({
          type: "POST",
          url: "?do=getmultiplebalance"+con,
          // data: "id="+val,
          success: function(msg){


            var msg=msg.split(",");

            $("#amountval").val(msg[0]);
            $("#multipleval").val(msg[2]);
            $("#amount").val(msg[2]);


            amt = +$('#amount').val();


            $('#d_balance').hide();
            $('#balance').show();
            $('#bal_currency').show();


              msg[0] = (amt+deductible-trailing) - msg[0];     
              msg[0] = parseFloat(Math.round(msg[0] * 100) / 100);
              msg[0] = msg[0].toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",");


              // $("#amountval").val(msg[0]);


            if($("#reference_to option:selected").val()!=undefined && $('#amount').val()!='')
            {

                document.getElementById("bal_currency").innerHTML=msg[1];
                document.getElementById("balance").innerHTML=msg[0];
                document.getElementById('bal_currency').style.fontWeight='700';
            }else{

                document.getElementById("bal_currency").innerHTML=msg[1];
                document.getElementById("balance").innerHTML='0.00';
                document.getElementById('bal_currency').style.fontWeight='700';
            }
          }
        });

}

    $('#amount').bind('blur keyup input',function()
    {
        if($("#reference_to option:selected").val()==undefined)
        {
            if($('#trade_select').attr('checked') == 'checked')
            {
                $('#trailing').show();
                deductiblesShow();
                showTrades();
            }
        }

        if(($("#paying_reserve option:selected").val()==undefined || $('#amount').val()=='') && $('#transaction_type')=='<?php echo @DATED_RESERVE_PAYMENT; ?>
')
        {
            showReserveTrades();
            getReserveBalance();
        }
        
        ($("#transaction_type").val()!='<?php echo @DATED_RESERVE_PAYMENT; ?>
')?getBalance():getReserveBalance();
    });

    $('#reference_to').live('change',function(){
        switch($('#transaction_type').val())
        {
            case '<?php echo @RECONCILE_DEBTOR_ACCOUNT; ?>
':{
                getReconcileBalance();
                break;
            }
            case '<?php echo @RECONCILE_CREDITOR_ACCOUNT; ?>
':{
                getReconcileBalance();
                break;
            }
            case '<?php echo @CREDITOR_OUTBOUND_PAYMENT; ?>
':{
                getReserveBalance(0,'reference_to');
                break;
            }
            default:{
                getBalance();
                break;
            }
        }
    });

    $('#paying_reserve').live('change mouseup',function(){
        getReserveBalance();
    });

    $('#tb_return').live('change mouseup', function () {
        var balance = 0;
        $("#tb_return option:selected").each(function () {
            if ($(this).data('amount')) {
                balance += (parseFloat($(this).data('amount')));
            }
        });
        $('#balance').html(balance.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ","));
    });
    
    $('input[type="submit"]').click(function(){
        $(this)
            .attr('disabled','disabled')
            .css('border','1px solid #808080').css('background','#808080').css('cursor','auto');
        $("#waiting_box").html('Please wait...');
        $('#save_transaction').submit();
    })
    

  <?php if ($this->_tpl_vars['values']['transaction_type'] != ''): ?>
  showFields(<?php echo $this->_tpl_vars['values']['transaction_type']; ?>
);
   <?php endif; ?>

   <?php if ($this->_tpl_vars['values']['originator_id'] != '' || $this->_tpl_vars['values']['transaction_type'] != ''): ?>
  showDebtors();
  <?php if ($this->_tpl_vars['values']['transaction_type'] == @ORIGINATOR_PAYMENT_ON_ACCOUNT || $this->_tpl_vars['values']['transaction_type'] == @ORIGINATOR_DEPOSIT || $this->_tpl_vars['values']['transaction_type'] == @CREDITOR_FEES_CHARGES || $this->_tpl_vars['values']['transaction_type'] == @RECONCILE_DEBTOR_ACCOUNT || $this->_tpl_vars['values']['transaction_type'] == @TRANSFER_OF_PAYMENT_BY_ORIGINATOR || $this->_tpl_vars['values']['transaction_type'] == @INBOUND_DEBTOR_PAYMENT || $this->_tpl_vars['values']['transaction_type'] == @PAID_DIRECTLY_TO_ORIGINATOR || $this->_tpl_vars['values']['transaction_type'] == @RECONCILE_CREDITOR_ACCOUNT || $this->_tpl_vars['values']['transaction_type'] == @INBOUND_CREDITOR_PAYMENT): ?>
  showCurrency();
  <?php endif; ?>
  <?php endif; ?>

  <?php if ($this->_tpl_vars['values']['debtor_id'] != '' && ( $this->_tpl_vars['values']['transaction_type'] == @RECONCILE_DEBTOR_ACCOUNT || $this->_tpl_vars['values']['transaction_type'] == @RECONCILE_CREDITOR_ACCOUNT )): ?>
  getReconcilePayments();
    <?php if ($this->_tpl_vars['values']['reconcile_payment'] != ''): ?>
    showReconcileTrades();
    <?php endif; ?>
  <?php elseif ($this->_tpl_vars['values']['debtor_id'] != '' && $this->_tpl_vars['values']['transaction_type'] == @FALSE_PAYMENT_RETURNED): ?>
  getAllPayments(1);
  <?php elseif ($this->_tpl_vars['values']['debtor_id'] != '' && $this->_tpl_vars['values']['transaction_type'] == @MULTIPLE_PAYMENTS): ?>
  getMultiplePayments(1);
  showTrades();
  <?php elseif ($this->_tpl_vars['values']['debtor_id'] != '' && $this->_tpl_vars['values']['transaction_type'] == @TB_RETURN): ?>
  showTbForReturn();
  <?php elseif ($this->_tpl_vars['values']['debtor_id'] != ''): ?>
  showTrades();
  <?php endif; ?>

  <?php if ($this->_tpl_vars['values']['amount'] != '' && ( $this->_tpl_vars['values']['transaction_type'] != @DATED_RESERVE_PAYMENT && $this->_tpl_vars['values']['transaction_type'] != @RECONCILE_DEBTOR_ACCOUNT && $this->_tpl_vars['values']['transaction_type'] != @RECONCILE_CREDITOR_ACCOUNT )): ?>
  showTrades();
  getBalance(<?php echo $this->_tpl_vars['values']['amount']; ?>
);
  <?php elseif ($this->_tpl_vars['values']['amount'] != '' && $this->_tpl_vars['values']['transaction_type'] == @DATED_RESERVE_PAYMENT): ?>
  showReserveTrades();    
  getReserveBalance(<?php echo $this->_tpl_vars['values']['amount']; ?>
);
  <?php elseif ($this->_tpl_vars['values']['amount'] != '' && ( $this->_tpl_vars['values']['transaction_type'] == @RECONCILE_DEBTOR_ACCOUNT || $this->_tpl_vars['values']['transaction_type'] == @RECONCILE_CREDITOR_ACCOUNT )): ?>
  showReconcileTrades();
  getReconcileBalance(<?php echo $this->_tpl_vars['values']['amount']; ?>
);
  <?php elseif ($this->_tpl_vars['values']['reference_to'] != '' && ( $this->_tpl_vars['values']['transaction_type'] != @DATED_RESERVE_PAYMENT && $this->_tpl_vars['values']['transaction_type'] != '6' && $this->_tpl_vars['values']['transaction_type'] != '20' )): ?>
  getBalance();
  <?php elseif ($this->_tpl_vars['values']['paying_reserve'] != '' && $this->_tpl_vars['values']['transaction_type'] == @DATED_RESERVE_PAYMENT): ?>
  getReserveBalance();
  <?php elseif ($this->_tpl_vars['values']['paying_reserve'] != '' && ( $this->_tpl_vars['values']['transaction_type'] == @RECONCILE_DEBTOR_ACCOUNT || $this->_tpl_vars['values']['transaction_type'] == @RECONCILE_CREDITOR_ACCOUNT )): ?>
  getReconcileBalance();
  <?php endif; ?>

  <?php if ($this->_tpl_vars['values']['trade_select'] != '' && ( $this->_tpl_vars['values']['transaction_type'] == @TRANSFER_OF_PAYMENT_BY_ORIGINATOR || $this->_tpl_vars['values']['transaction_type'] == @INBOUND_DEBTOR_PAYMENT || $this->_tpl_vars['values']['transaction_type'] == @PAID_DIRECTLY_TO_ORIGINATOR || $this->_tpl_vars['values']['transaction_type'] == @INBOUND_CREDITOR_PAYMENT )): ?>
  
  $('#row_reference_to').show(); 
  checkDeductible();
  checkTrailing();
  <?php endif; ?>

  <?php if ($this->_tpl_vars['values']['check_trailing'] != ''): ?>
  checkTrailing();
  <?php endif; ?>

  <?php if ($this->_tpl_vars['values']['check_deductible'] != ''): ?>
  checkDeductible();
  <?php endif; ?>
  

$('#trade_select').click(function(){
                  
  if($(this).attr('checked') != 'checked'){

  
    $('#row_reference_to').hide();
    $('#trailing').hide();
    $('#deductibles').hide();
    $('#row_deductible').hide();
  }else{

    $('#row_reference_to').show();
    $('#trailing').show();
    deductiblesShow();
    //$('#row_deductible').show();
    showTrades();
  }
                  
});


$(':checkbox').on('change',function()
{
 var th = $(this), name = th.prop('name'); 

 if(th.is(':checked')){
     $(':checkbox[name="'  + name + '"]').not($(this)).prop('checked',false);   
  }


  if(name=='check_deductible'){

    $('#row_deductible').show(); 

     if($('input[name="check_deductible"]:checked').val()==undefined){

       $('#row_deductible').hide(); 
       $('#balance_deductible').val('');   
       $('#row_notes').removeClass('row2');
        $('#row_notes').addClass('row1');
        

    }else if($('input[name="check_deductible"]:checked').val()=='1'){ 

      $('#row_deductible').show(); 
      $('#row_notes').removeClass('row1');
      $('#row_notes').addClass('row2');

      // document.getElementById('txt_deductible').innerHTML = 'Single Deductible';
    }else{

      $('#row_notes').removeClass('row1');
      $('#row_notes').addClass('row2');

      // document.getElementById('txt_deductible').innerHTML = 'Multiple Deductibles';
    }

  }else{

      if($('#transaction_type').val()!='<?php echo @RECONCILE_DEBTOR_ACCOUNT; ?>
' || $('#transaction_type').val()!='<?php echo @RECONCILE_CREDITOR_ACCOUNT; ?>
'){

        if($('input[name="check_deductible"]:checked').val()!=undefined && $('input[name="trade_select"]:checked').val()!=undefined ){

          $('#row_deductible').show();
        }else{
          $('#row_deductible').hide();
        }
      }else{
        // $('#row_deductible').hide();
      }
  }
  // $('#row_deductible').show();
});


$('#balance_deductible,#trailing_balance_amt').bind('blur keyup input',function(){
    ($('#transaction_type').val()=='<?php echo @RECONCILE_DEBTOR_ACCOUNT; ?>
' || $('#transaction_type').val()=='<?php echo @RECONCILE_CREDITOR_ACCOUNT; ?>
')?getReconcileBalance():getBalance();
});

    $('#balance_deductible,#trailing_balance_amt,#amount').on('change', function () {
        $(this).val($(this).val().replace(',', ''));
    });

  function checkDeductible()
  {
    deductiblesShow();
    transaction_type = $('#transaction_type').val();

    if($('input[name="check_deductible"]:checked').val()==undefined){

       $('#row_deductible').hide(); 
       $('#balance_deductible').val('');
       $('#row_notes').removeClass('row1');
       $('#row_notes').addClass('row2');
       if(transaction_type=='<?php echo @RECONCILE_DEBTOR_ACCOUNT; ?>
' || transaction_type=='<?php echo @RECONCILE_CREDITOR_ACCOUNT; ?>
')
       {
           getReconcileBalance();
       }
       else
       {
           getBalance();
       }

    }else if($('input[name="check_deductible"]:checked').val()=='1')
    { 

      $('#row_deductible').show(); 
      $('#row_notes').removeClass('row2');
      $('#row_notes').addClass('row1');
      if(transaction_type=='<?php echo @RECONCILE_DEBTOR_ACCOUNT; ?>
' || transaction_type=='<?php echo @RECONCILE_CREDITOR_ACCOUNT; ?>
')
      {
        getReconcileBalance();
      }else{
        getBalance();
      }


      // document.getElementById('txt_deductible').innerHTML = 'Single Deductible';
    }else if($('input[name="check_deductible"]:checked').val()=='2'){

      $('#row_deductible').show(); 
      $('#row_notes').removeClass('row2');
      $('#row_notes').addClass('row1');
      if(transaction_type=='<?php echo @RECONCILE_DEBTOR_ACCOUNT; ?>
' || transaction_type=='<?php echo @RECONCILE_CREDITOR_ACCOUNT; ?>
')
      {
        getReconcileBalance();
      }else{
        getBalance();
      }
    }
  }


  function checkTrailing()
  {
    $('#trailing').show();
    transaction_type = $('#transaction_type').val();

    if($('input[name="check_trailing"]:checked').val()==undefined){

       $('#row_trailing').hide(); 
       $('#trailing_balance_amt').val('');
       $('#row_notes').removeClass('row2');
        $('#row_notes').addClass('row1');
        if(transaction_type=='<?php echo @RECONCILE_DEBTOR_ACCOUNT; ?>
' || transaction_type=='<?php echo @RECONCILE_CREDITOR_ACCOUNT; ?>
')
        {
          getReconcileBalance();
        }else{
          getBalance();
        }

    }else if($('input[name="check_trailing"]:checked').val()=='1')
    { 

      $('#row_trailing').show(); 
      $('#row_notes').removeClass('row1');
      $('#row_notes').addClass('row2');
       if(transaction_type=='<?php echo @RECONCILE_DEBTOR_ACCOUNT; ?>
' || transaction_type=='<?php echo @RECONCILE_CREDITOR_ACCOUNT; ?>
')
       {
        getReconcileBalance();
      }else{
        getBalance();
      }


      // document.getElementById('txt_deductible').innerHTML = 'Single Deductible';
    }else if($('input[name="check_trailing"]:checked').val()=='2'){

      $('#row_trailing').show(); 
      $('#row_notes').removeClass('row1');
      $('#row_notes').addClass('row2');
       if(transaction_type=='<?php echo @RECONCILE_DEBTOR_ACCOUNT; ?>
' || transaction_type=='<?php echo @RECONCILE_CREDITOR_ACCOUNT; ?>
')
       {
        getReconcileBalance();
      }else{
        getBalance();
      }

      // document.getElementById('txt_deductible').innerHTML = 'Multiple Deductibles';
    }
  }


  function getAllPayments(flag) {
    $('#row_fx_rate').show();

    var transaction_type = $('#transaction_type').val();

    val = '';
    user_id = $('#originator_id').val();
    $("#debtor_id option:selected").each(function () {
      val += $(this).val();
    });

    var amounts = $('#amount').val();

    $.ajax({
      type: "POST",
      url: "?do=getallpayments",
      data: "id="+$("#debtor_id").val()+"&user_id="+user_id+'&transaction_type=' + transaction_type,
      success: function(msg){


        $('#d_payment_return').hide();



        if($("#debtor_id option:selected").val()!=undefined && $("#debtor_id option:selected").val()!='' && transaction_type!='')
        {
          if(flag==1){

            // $("#err_payment_return").html(msg);
          }else{

            try{

              $('#payment_return').show();
               $("#payment_return").html(msg);
               // $("#err_payment_return").html(msg);
              
            }catch(errs){
              if( transaction_type == '<?php echo @FALSE_PAYMENT_RETURNED; ?>
'
                      || transaction_type == '<?php echo @OCPA_RETURN; ?>
'
                      || transaction_type == '<?php echo @ICP_RETURN; ?>
' )
              {
                $('#row_payment_return').show();
              }
            }
          }

        }
        else{
          $('#row_reconcile').hide();
          $('#row_deductible').hide();
          $('#row_trailing').hide();
        }

      }
    });


  }


  function getMultiplePayments(flag)
  {
    $('#row_fx_rate').show();

    var transaction_type = $('#transaction_type').val();

    val ='';
    user_id = $('#originator_id').val();
    $("#debtor_id option:selected").each(function () {
      val += $(this).val();

    });


    var amounts = $('#amount').val();
    
    $.ajax({
      type: "POST",
      url: "?do=getmultiplepayments",
      data: "id="+$("#debtor_id").val()+"&user_id="+user_id,
      success: function(msg){


        $('#d_multiple_payments').hide();
        
        if($("#debtor_id option:selected").val()!=undefined && $("#debtor_id option:selected").val()!='' && transaction_type!='')
        {

          if(flag==1){

            // $("#err_multiple_payments").html(msg);
            //    $("#multiple_payments").html(msg);

          }else{

            try{

               $('#multiple_payments').show();
               $("#multiple_payments").html(msg);
               if(transaction_type == '<?php echo @MULTIPLE_PAYMENTS; ?>
'){
                 $('#row_reference_to').show();
               }

               // $("#err_payment_return").html(msg);
              
            }catch(errs){
              if(transaction_type == '<?php echo @MULTIPLE_PAYMENTS; ?>
'){

                 $('#row_multiple_payments').show();
                 $('#row_reference_to').show();

              }
            }
          }

        }else{
          $('#row_reconcile').hide();
          $('#row_deductible').hide();
          $('#row_trailing').hide();
        }

      }
    });

  }



  function getReconcilePayments(flag)
  {
    $('#row_fx_rate').show();

    var transaction_type = $('#transaction_type').val();

    val ='';
    user_id = $('#originator_id').val();
    $("#debtor_id option:selected").each(function () {
      val += $(this).val();

    });

    var amounts = $('#amount').val();

    initialAmount = parseFloat(Math.round(amounts * 100) / 100);
    
    initialAmount = initialAmount.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    
    $('#balance').html(initialAmount);

    $.ajax({
      type: "POST",
      url: "?do=getreconcilepayments",
      data: "id="+$("#debtor_id").val()+"&user_id="+user_id,
      success: function(msg){

        $('#d_reconcile').hide();
        $('#reconcile').show();


        if($("#debtor_id option:selected").val()!=undefined && $("#debtor_id option:selected").val()!='' && transaction_type!='')
        {

          deductiblesShow();
          if(flag==1){

            $("#err_reconcile").html(msg);
          }else{

            try{

               $("#reconcile").html(msg);
              
            }catch(errs){
              if(transaction_type == '<?php echo @RECONCILE_DEBTOR_ACCOUNT; ?>
' || transaction_type == '<?php echo @RECONCILE_CREDITOR_ACCOUNT; ?>
')
              {
                $('#row_reconcile').show();
              }
            }
          }
          if(transaction_type == '<?php echo @RECONCILE_DEBTOR_ACCOUNT; ?>
' || transaction_type == '<?php echo @RECONCILE_CREDITOR_ACCOUNT; ?>
')
          {
            $('#row_reconcile').show();
            $('#check_deductible').prop('checked', false);
            $('#check_trailing').prop('checked', false);
          }

        }else{
          $('#row_reconcile').hide();
          $('#row_deductible').hide();
          $('#row_trailing').hide();
        }

      }
    });


  }


function showReconcileTrades(flag)
{

  $('#row_fx_rate').show();

  var transaction_type = $('#transaction_type').val();
  var trade_select     = $('#trade_select').checked;


  var reconcile = $('#reconcile_payment').val();

  val ='';
  // user_id = $('#originator_id').val();
  user_id = $('#originator_id').val();
  $("#debtor_id option:selected").each(function () {
     val += $(this).val() + ",";

  });


  var amounts = $('#amount').val();
  

  initialAmount = parseFloat(Math.round(amounts * 100) / 100);
  
  // msg = msg.toFixed(2);
  
  initialAmount = initialAmount.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  
  $('#balance').html(initialAmount);

  $.ajax({
    type: "POST",
    url: "?do=getreconciletrades",
    data: "id="+$("#debtor_id").val()+"&user_id="+user_id+"&trans_id="+$('#reconcile_payment').val(),
    success: function(msg){


      $('#d_reference').hide();
      $('#reference').show();


      if($("#debtor_id option:selected").val()!=undefined && reconcile!='0' && reconcile!='' && transaction_type!='')
      {
        if(flag==1){

          $("#err_reference").html(msg);
        }else{

          try{

             $("#reference").html(msg);
            
          }catch(errs){
            if(transaction_type == '<?php echo @RECONCILE_DEBTOR_ACCOUNT; ?>
' || transaction_type == '<?php echo @RECONCILE_CREDITOR_ACCOUNT; ?>
'){
              $('#row_reference_to').show();
            }
          }
        }
        if((transaction_type == '<?php echo @RECONCILE_DEBTOR_ACCOUNT; ?>
' || transaction_type == '<?php echo @RECONCILE_CREDITOR_ACCOUNT; ?>
') && reconcile!='0' && reconcile!='')
        {

          $('#row_reference_to').show();
          $('#row_balance').show();
          $('#row_notes').show();
          $('#check_deductible').prop('checked', false);
          $('#check_trailing').prop('checked', false);
        }

      }else{
        $('#row_reference_to').hide();
        $('#rec_deductibles').hide();
        $('#row_deductible').hide();
        $('#row_trailing').hide();
        $('#row_balance').hide();
        $('#row_notes').hide();
        $('#check_deductible').prop('checked', false);
        $('#check_trailing').prop('checked', false);
      }


    }
  });

}
function deductiblesShow()
{
  var $transaction_type = $('#transaction_type').val();

  if( $transaction_type == <?php echo @RECONCILE_DEBTOR_ACCOUNT; ?>
 )
    {
        $('#deductibles').show();
        $('#rec_deductibles').show();
    }
    else
    {
        if ($("#trade_select").attr('checked') == 'checked') {
            $('#deductibles').show();
            $('#rec_deductibles').show();
        }
    }

  if(  $transaction_type == <?php echo @INBOUND_CREDITOR_PAYMENT; ?>

  || $transaction_type == <?php echo @RECONCILE_CREDITOR_ACCOUNT; ?>

  || $transaction_type == <?php echo @CREDITOR_OUTBOUND_PAYMENT; ?>

  || $transaction_type == <?php echo @MERGE_INBOUND_DEBTOR_PAYMENT; ?>

  || $transaction_type == <?php echo @SPLIT_INBOUND_DEBTOR_PAYMENT; ?>

  || $transaction_type == <?php echo @OCPA_TO_ICP; ?>

  || $transaction_type == <?php echo @ICP_SPLIT; ?>

  || $transaction_type == <?php echo @ICP_MERGE; ?>

  || $transaction_type == <?php echo @OCPA_MERGE; ?>

  )
  {
    $('#deductibles').hide();
    $('#rec_deductibles').hide();
  }
}
    function showOCPAInformation(index){
        var selectedOriginator = $("#originator_id").val();
        var selectedPayment = $("#ocpa_select_id").val();
        var selectedCreditor = $("#ocpa_creditor_"+index).val();
        var params = {'originator_id':selectedOriginator,'payment_id':selectedPayment,'creditor_id':selectedCreditor};
        console.log($.param(params));
        var ocpainfo = window.open("adminindex.php?do=getocpa_information&"+$.param(params),'ocpainfo','scrollbars=yes,width=850,height=1286,left=500');
        ocpainfo.focus();
    }

    function showTbForReturn() {
        $.ajax({
            type: "POST",
            url: "?do=get_trailings_for_return",
            data: {
                debtor_id: $("#debtor_id").val()
            },
            success: function(msg)
            {
                $('#tb_return').html(msg);
                $('#tb_return').show();
                $('select#tb_return').trigger('change');
            }
        });
    }
	
	function checkIsAEtr(is_aetr_value) {
		$('#is_aetr').prop('checked', !!is_aetr_value);
	}

    function getAEtrs(flag) {
		let isAEtr = false;
		if($("#transaction_type").val() == <?php echo @INBOUND_DEBTOR_PAYMENT; ?>

		|| $("#transaction_type").val() == <?php echo @INBOUND_CREDITOR_PAYMENT; ?>
){
			isAEtr = $("#debtor_id option:selected").data('is-aetr') && $("#is_aetr").prop('checked');
		}else if($("#transaction_type").val() == <?php echo @ORIGINATOR_PAYMENT_ON_ACCOUNT; ?>

        || $("#transaction_type").val() == <?php echo @ORIGINATOR_DEPOSIT; ?>
){
			isAEtr = $("#is_aetr").prop('checked');
		}
		if(isAEtr && ($("#transaction_type").val() == <?php echo @INBOUND_DEBTOR_PAYMENT; ?>

		|| $("#transaction_type").val() == <?php echo @INBOUND_CREDITOR_PAYMENT; ?>

		|| $("#transaction_type").val() == <?php echo @ORIGINATOR_PAYMENT_ON_ACCOUNT; ?>

		|| $("#transaction_type").val() == <?php echo @ORIGINATOR_DEPOSIT; ?>
)){
			$.ajax({
				type: "POST",
				url: "?do=get_aetrs_for_transaction",
				data: {
					transaction_type: $("#transaction_type").val(),
					lessee_id: $("#debtor_id").val(),
					originator_id: $("#originator_id").val(),
					currency_id: $("#currency_id").val(),
				},
				success: function (msg) {
                    if($("#transaction_type").val() == <?php echo @ORIGINATOR_DEPOSIT; ?>
){
                        $('#row_rpas').hide();
                    }
					$('#row_aetr_data').html(msg);
					$('#row_aetr').show();
					showHideWithAllocation(false);
                    getAssets();
				}
			});
		} else {
		    if(flag === 'change') {
                $('#row_aetr_data').html('');
                $('#row_aetr').hide();
                $('#row_aetr_asset_data').html('');
                $('#row_aetr_asset').hide();
                showHideWithAllocation(true);
            }
            if($("#transaction_type").val() == <?php echo @ORIGINATOR_DEPOSIT; ?>
){
                $('#row_rpas').show();
            }
		}
    }

    function getAssets(){
        if($("#transaction_type").val() == <?php echo @INBOUND_DEBTOR_PAYMENT; ?>

        || $("#transaction_type").val() == <?php echo @INBOUND_CREDITOR_PAYMENT; ?>
){
            $.ajax({
                type: "POST",
                url: "?do=get_assets_for_transaction",
                data: {
                    transaction_type: $("#transaction_type").val(),
                    lessee_id: $("#debtor_id").val(),
                    aetr_id: $("#a_etr_id").val(),
                },
                success: function (msg) {
                    $('#row_aetr_asset_data').html(msg);
                    $('#row_aetr_asset').show();
                }
            });
        }
    }
	
	function showHideWithAllocation(show){
		if($("#transaction_type").val() == <?php echo @INBOUND_DEBTOR_PAYMENT; ?>

		|| $("#transaction_type").val() == <?php echo @INBOUND_CREDITOR_PAYMENT; ?>
){
			if(show){
				$("#withallocation").show();
				if($("#trade_select").prop('checked')){
					$("#row_reference_to").show();
				} else {
					$("#row_reference_to").hide();
				}
			} else {
				$("#withallocation").hide();
				$("#row_reference_to").hide();
			}
		}
	}
	
	showHideWithAllocation(<?php if (isset ( $this->_tpl_vars['a_etr_html'] )): ?>false<?php else: ?>true<?php endif; ?>);
</script>