<!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" xml:lang="en" lang="en">
<head>
  <title><?lsmb titlebar ?></title>
  <meta http-equiv="Pragma" content="no-cache" />
  <meta http-equiv="Expires" content="-1" />
  <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" href="css/<?lsmb stylesheet ?>" type="text/css" />
  <script language="JavaScript"  src="UI/payments/javascript/maximize_minimize.js"></script>
  <meta http-equiv="content-type" content="text/html; charset=<?lsmb charset ?>" />  
  <meta name="robots" content="noindex,nofollow" />
</head>
<body id="payment_2_body"
onLoad="maximize_minimize_on_load('div_topay_state', 'UI/payments/img/down.gif','UI/payments/img/up.gif') ">
 <form name="pay_single_dues" method="post" action="payment.pl">

 <?lsmb PROCESS elements.html  # Include form elements helper. ?>
 <?lsmb accountclass.type = 'hidden';
        INCLUDE input element_data=accountclass ?>
 <?lsmb login.type = 'hidden' ; INCLUDE input element_data=login ?>
 <?lsmb #WE NEED TO KNOW HOW MANY COLUMNS ARE WE USING, PLEASE DO NOT MOVE THE NEXT LINE -?>
 <?lsmb column_count = 0 -?>

 <table width="100%">
  <tr id="top_bar" class="listtop">
    <th id="top_bar_header" class="listtop">
    	<?lsmb header.text ?>
        <?lsmb type.type = 'hidden' ; INCLUDE input element_data=type ?>
    </th>
    
  </tr>
 </table>
 <table width="100%" id="info_table">
  <tr valign="top" id="info_row">
   <td width="50%" id="info_data">
    <table id="cv_info_table">
     <tr id="cv_row">
      <th class="label_left" id="cv_label_column"><?lsmb  text('Vendor') ?></th>
       <td id="cv_column">
       		<?lsmb vc.name ?><?lsmb vendorcustomer.type = 'hidden'; INCLUDE input element_data=vendorcustomer?>       		
       </td>
     </tr>
     <tr id="cv_address_row">
      <th valign="top" align="right" id="cv_address_label_column"><?lsmb text('Location') ?></th>
      <td id="cv_address_column">
       <table id="cv_address_table">
       <?lsmb # this table will show the customer/vendor address, city, phone and others things that could help to reminds them?>
       <?lsmb FOREACH address IN vc.address  # Loop through customer/vendor address info ?>
         <tr>
          <td><?lsmb address.text ?></td>
         </tr>
	      <?lsmb END ?>
        </table>
      </td>
     </tr>
     <tr align="right" id="notes_row">
      <th valign="top" id="notes_column"><?lsmb text('Notes') ?></th>
      <td><textarea id="notes" name="notes" cols="35" rows="3"><?lsmb notes ?></textarea></td>
     </tr>
    </table>
   </td>
   <td align="right">
    <table>
     <?lsmb # the project will be shown if it was selected in the first step  ?>
     <?lsmb IF project.value  # Only process element if the value exists.  ?>
     <tr id="project_row">
      <th align="right" nowrap id="project_label_column"><?lsmb text('Projects') ?>:</th>
      <td colspan="2" id="project_column">
          <?lsmb project.text ?>
	  <?lsmb  project.type="hidden"; INCLUDE input element_data=project ?>
     </td>
     </tr>
     <?lsmb END ?>
     <?lsmb #the department will be shown if it was selected in the first step ?>
     <?lsmb IF department.value  # Only process element if one exists. As in project above ?>
     <tr id="department-row">
      <th align="right" nowrap id="department_label_column"><?lsmb  text('Department')  ?>:</th>
      <td colspan="2" id="department_column">
       <?lsmb  department.text ?>
       <?lsmb  department.type="hidden"; INCLUDE input element_data=department ?>
      </td>
     </tr>
     <?lsmb END ?>
     <tr id="account_row">
     <?lsmb  #here goes all the posible accounts were the paid can be done  ?>
      <th align="right" nowrap id="account_label_column"><?lsmb text('Account') ?></th>
      <td colspan="2" id="account_column">
       <select id="account" name="account">
        <?lsmb FOREACH item IN account -?>
         <option value="<?lsmb item.id -?>" <?lsmb IF item.id ==  selected_account -?> selected <?lsmb END ?>><?lsmb item.description -?></option>
        <?lsmb END -?>
       </select> 
     </td>
     </tr>
     <tr id="date_row"><?lsmb # here goes an input where the date can be written, we can also use a java calendar :). We can use an ajax script to call the Exchange rate of the input date wich can be called with the onChange Method	  ?>
      <th align="right" nowrap id="date_label_column"><?lsmb text('Date') ?></th>
      <td colspan="2" id="date_column"> <?lsmb INCLUDE input element_data=datepaid ?> </td>
     </tr>
     <tr id="source_row">
     <?lsmb # here goes all the posible sources wich we can use -?>
      <th align="right" nowrap id="source_label_column"><?lsmb text('Source')?></th>
      <td width="28%" id="source_column">
         <select id="source" name="source">
          <?lsmb FOREACH item IN source -?>
           <option value="<?lsmb item -?>"<?lsmb IF item == selected_source -?> selected <?lsmb END ?>><?lsmb item -?></option>
          <?lsmb END -?>
         </select>
      </td>
      <td id="source_text_column">
      <?lsmb INCLUDE input element_data={ name  => 'source_value' 
                                          id    => 'source_value'
                                          value => source_value } -?>
      </td>
     </tr>
     <tr id="currency_row">
     <?lsmb #  here goes the selected currency in step 1 ?>
      <th align="right" id="currency_label_column"><?lsmb text('Currency') -?>:</th>
      <td id="currency_column">
      		<?lsmb curr.value -?><?lsmb curr.type='hidden'; INCLUDE input element_data=curr -?>
      </td>
     </tr>
     <?lsmb # here goes the exchange rate of the selected currency, it can be done by the ajax script or the update button ?>
     <?lsmb  IF defaultcurrency.text != curr.text # Only process element if one exists. ?>
      <tr id="exrate_row">
       <th valig="top" align="right" id="exrate_label_column"><?lsmb text('Exchange Rate') ?>:</th>
       <td id="exrate_column">
        <?lsmb  IF exrate.value -?>        
        <?lsmb  exrate.text -?>
        <?lsmb  exrate.type='hidden'; INCLUDE input element_data=exrate -?>
        <?lsmb  END -?>
        <?lsmb  IF !exrate.value -?>
        <?lsmb INCLUDE input element_data=exrate -?>
        <?lsmb  END -?>
       </td>
      </tr>
     <?lsmb END ?>
    </table>
   </td>
  </tr>
 </table>
 <table width="100%">
  <tr class="listheading">
   <?lsmb FOREACH column IN column_headers  # Loop through columns ?>
   <?lsmb column_count = column_count + 1 -?>
   <th class="listheading"><?lsmb column.text ?></th>
   <?lsmb END ?>
  </tr>
  <?lsmb # We have to clear i for later usage :)  ?>
  <?lsmb i = '0'; topay_subtotal = 0  -?>
  <?lsmb FOREACH row IN rows ?>
  <?lsmb i = i + 1; j = i % 2; alterning_style = "listrow$j" ?>
  <tr class="<?lsmb alterning_style ?>"=>
    <td><a href="<?lsmb row.invoice.href ?>"><?lsmb row.invoice.number ?></a>
        <input type="hidden" value="<?lsmb row.invoice.id ?>" />                 </td>
    <?lsmb # we can use an href to link this invoice number to the invoice ?>
    <td><?lsmb row.invoice_date ?></td>
    <td><?lsmb row.amount ?></td>
    <td><?lsmb row.paid ?></td>

    <td><?lsmb row.discount ?></td>
    <td align="center"><input  name="<?lsmb "optional_discount_$row.invoice.id" -?>"  id="<?lsmb
       "optional_discount_$row.invoice.id" -?>" type="checkbox"  class="checkbox"<?lsmb IF
       row.optional_discount OR first_load -?> checked <?lsmb END -?> ></td>
    <td><?lsmb row.due ?></td>
    <?lsmb IF defaultcurrency.text != curr.value ?>
    <td><?lsmb row.exchange_rate ?></td>
    <td><?lsmb row.due ?></td>
    <td><div id="<?lsmb "div_topay_invoice_$i" ?>"><?lsmb row.due_fx ?></div></td>
    <?lsmb END ?> 
    <?lsmb #This should be computed and updated to the div using  ?> 
    <td><?lsmb  row.topay_fx.id = row.topay_fx.name ;INCLUDE input element_data=row.topay_fx;
    	       topay_subtotal = topay_subtotal + row.topay_fx.value -?>
    <?lsmb # A DEGRADABLE JAVASCRIPT IS USED, BECAUSE OF THE VISUAL IMPACT
    	   # THAT CAUSES THE SIZE OF THIS DIV -?>
    <img src="UI/payments/img/up.gif" id="button_topay_<?lsmb row.invoice.id ?>" name="<?lsmb "button_topay_$i" ?>"
     onClick="maximize_minimize('div_topay_<?lsmb row.invoice.id ?>',
    'topaystate_<?lsmb row.invoice.id ?>' ,this,
    'UI/payments/img/down.gif', 'UI/payments/img/up.gif')">
     <div id="div_topay_<?lsmb row.invoice.id ?>">
      <table>
       <tr id="<?lsmb "account-row$i"?>">
        <?lsmb # here goes all the posible accounts were the paid can be  done ?>
        <th align="right" nowrap id="<?lsmb "account_label_column$i" ?>"><?lsmb text('Account') ?></th>
        <td colspan="2" id="<?lsmb "account_column$i" ?>">
         <select id="account_<?lsmb row.invoice.id -?>" name="account_<?lsmb row.invoice.id -?>">
          <?lsmb FOREACH item IN account -?>
           <option value="<?lsmb item.id -?>" <?lsmb IF item.id == row.selected_account -?> selected <?lsmb END ?>><?lsmb item.description -?></option>
          <?lsmb END -?>
         </select>
        </td>
       </tr>
       <tr id="<?lsmb "source_row$i" ?>">
        <?lsmb # here goes all the posible sources wich we can used ?>
        <th align="right" nowrap id="<?lsmb "source_label_column$i" ?>"><?lsmb text('Source') ?></th>
        <td width="28%" id="<?lsmb "source_column$i" ?>">
         <select id="source_<?lsmb row.invoice.id -?>" name="source_<?lsmb row.invoice.id -?>">
          <?lsmb FOREACH item IN source -?>
           <option value="<?lsmb item -?>"<?lsmb IF item == row.selected_source -?> selected <?lsmb END ?>><?lsmb item -?></option>
          <?lsmb END -?>
         </select>
        </td>
        <td><?lsmb INCLUDE input element_data={
                                              name  => "source_text_$row.invoice.id",
                                              id    => "source_text_$row.invoice.id",
                                              value => row.source_text 
                                              } -?></td>   
        <td nowrap align="left"><input  name="<?lsmb "optional_pay_$row.invoice.id" -?>"  id="<?lsmb "optional_pay_$row.invoice.id" -?>" type="checkbox"  class="checkbox"
        <?lsmb IF row.optional -?> checked <?lsmb END -?>></td>
       </tr>
      </table>
     </div>
     </td>
     <td valign="MIDDLE"><input type="checkbox" name="checkbox_<?lsmb row.invoice.id ?>"></td>
   <?lsmb END ?>
   </tr>
   <?lsmb  colspan = column_count - 2 # We will use this later on totals -?>
   <tr class="listsubtotal">
   <th colspan="<?lsmb colspan -?>" align="right"><?lsmb text('Subtotal') -?></th>
   <th colspan="2"><?lsmb topay_subtotal -?>&nbsp;<?lsmb curr.value -?></th>
   </tr>
   </table>
   <table width="100%">
   <tr>
    <th class="listheading" colspan="7" ><?lsmb text('OVERPAYMENT / ADVANCED PAYMENT / PREPAYMENT') ?></th>
   </tr>
   <tr>
   <th class="listheading"><?lsmb text('Item') ?></th>
   <th class="listheading"><?lsmb text('Account') ?></th>
   <th class="listheading"><?lsmb text('Cash Account')?></th>
   <th class="listheading"><?lsmb text('Source') ?></th>
   <th class="listheading"><?lsmb text('Memo') ?></th>
   <th class="listheading"><?lsmb text('Amount') ?></th>
   <th class="listheading">X</th>
   </tr>
   <?lsmb # We have to insert the overpayment data  -?>
   <?lsmb overpayment_item = 0; overpayment_subtotal = 0 -?>
   <?lsmb FOREACH item IN overpayment -?>
   <?lsmb overpayment_item = overpayment_item + 1  -?>
   <?lsmb j = overpayment_item % 2; alterning_style = "listrow$j" ?>
   <tr class="<?lsmb alterning_style -?>">
     <td align="center"><?lsmb overpayment_item ?> </td>
     <td align="center">
                        <?lsmb item.account.accno -?>--<?lsmb item.account.description -?>
                        <input type="hidden" id="overpayment_account_<?lsmb overpayment_item -?>" name="overpayment_account_<?lsmb overpayment_item -?>" value="<?lsmb item.account.id -?>--<?lsmb item.account.accno ?>--<?lsmb item.account.description ?>" />
     </td>
     <td align="center">
                        <?lsmb item.cashaccount.accno -?>--<?lsmb item.cashaccount.description -?>
                        <input type="hidden" id="overpayment_cash_account_<?lsmb overpayment_item -?>"
                        name="overpayment_cash_account_<?lsmb overpayment_item -?>" 
                        value="<?lsmb item.cashaccount.id -?>--<?lsmb item.cashaccount.accno ?>--<?lsmb
                        item.cashaccount.description ?>" />
     </td>
     <td align="center">
     	<?lsmb item.source1 -?>	<?lsmb item.source2 -?>
     	<input type="hidden" id="overpayment_source1_<?lsmb overpayment_item -?>" name="overpayment_source1_<?lsmb overpayment_item -?>" value="<?lsmb item.source1 -?>" />
     	<input type="hidden" id="overpayment_source2_<?lsmb overpayment_item -?>" name="overpayment_source2_<?lsmb overpayment_item -?>" value="<?lsmb item.source2 -?>" />
     </td>
     <td align="center">
        <?lsmb item.memo -?>
        <input type="hidden" id="overpayment_memo_<?lsmb overpayment_item -?>" name="overpayment_memo_<?lsmb overpayment_item -?>" value="<?lsmb item.memo -?>" />
     </td>
     <td align="center">
     	<?lsmb item.amount -?>
     	<input type="hidden" id="overpayment_topay_<?lsmb overpayment_item -?>" name="overpayment_topay_<?lsmb overpayment_item -?>" value="<?lsmb item.amount ?>" />
     	<?lsmb overpayment_subtotal = overpayment_subtotal + item.amount -?>
     </td>
     <td align="center"><input type="checkbox" name="overpayment_checkbox_<?lsmb overpayment_item -?>"/></td>   
   </tr>        
   <?lsmb END -?>
   <?lsmb #Now we insert an empty field to process a new overpayment -?>
   <?lsmb overpayment_item = overpayment_item + 1;
          j = overpayment_item % 2;
          alterning_style = "listrow$j"            -?>
    <tr class="<?lsmb alterning_style -?>">
     <td align="center"><?lsmb  overpayment_item -?></td>
     <td align="center"> 
          <select id="overpayment_account_<?lsmb overpayment_item -?>"  name="overpayment_account_<?lsmb overpayment_item -?>">
        <?lsmb FOREACH item IN overpayment_account -?>
           <option value="<?lsmb item.id ?>--<?lsmb item.accno ?>--<?lsmb item.description ?>"> <?lsmb item.accno ?>--<?lsmb item.description -?></option>
        <?lsmb END -?>
          </select>
     </td>
     <td align="center"> 
        <select id="overpayment_cash_account_<?lsmb overpayment_item -?>" name="overpayment_cash_account_<?lsmb overpayment_item -?>"> 
         <?lsmb FOREACH item IN account -?>
         <option value="<?lsmb item.id -?>--<?lsmb item.accno ?>--<?lsmb item.description ?>"><?lsmb item.description -?></option>
         <?lsmb END -?>
        </select>
    </td>
     <td align="center">
        <select id="overpayment_source1_<?lsmb overpayment_item -?>" name="overpayment_source1_<?lsmb overpayment_item -?>">
          <?lsmb FOREACH item IN source -?>
           <option value="<?lsmb item -?>"><?lsmb item -?></option>
          <?lsmb END -?>
         </select>
         <input name="overpayment_source2_<?lsmb overpayment_item -?>"  id="overpayment_source2_<?lsmb overpayment_item -?>"/>
         <input type="hidden" name="overpayment_qty" id="overpayment_qty" value="<?lsmb overpayment_item ?>" />
     </td>
     <td align="center"><input name="overpayment_memo_<?lsmb overpayment_item -?>" id="overpayment_memo_<?lsmboverpayment_item ?>" /></td>     
     <td align="center">
      <input 
      	name="overpayment_topay_<?lsmb overpayment_item -?>"
      	id="overpayment_topay_<?lsmboverpayment_item ?>"
        value="<?lsmb IF unhandled_overpayment.value > 0 -?>
                    <?lsmb unhandled_overpayment.value -?>
                <?lsmb END -?>"      
      />
     </td>
     <td align="center"><input type="checkbox" name="overpayment_checkbox_<?lsmb overpayment_item -?>"/></td>
   </tr>
   <tr class="listsubtotal">
   <th colspan="5" align="right"><?lsmb text('Subtotal') -?></th>
   <th colspan="2"><?lsmb overpayment_subtotal -?>&nbsp;<?lsmb curr.value -?></th>
   </tr>
   <tr class="listtotal">
   <?lsmb payment_total = overpayment_subtotal + topay_subtotal -?>
   <th colspan="5" align="right"><?lsmb text('Total') -?></th>
   <th colspan="2"><?lsmb payment_total -?>&nbsp;<?lsmb curr.value -?></th>
   </tr>
   </table>
   
   <hr />
  <?lsmb update.accesskey   = "U";
         update.title       = "UPDATE ALT+U";
         update.name        = "action";
         update.value	    = "payment2";
         update.text        = text("UPDATE");
         INCLUDE button element_data=update -?>
  <?lsmb post.accesskey   = "P";
         post.title	  = "POST ALT+P";
         post.name	  = "action";
         post.value	  = "post_payment";
         post.text	  = text("POST"); 
         INCLUDE button element_data=post -?>
  <?lsmb post_and_print.accesskey = "R";
         post_and_print.title     = "POST AND PRINT ALT+R";
         post_and_print.name = "action";
         post_and_print.value = "post_and_print_payment";
         post_and_print.text = text("POST AND PRINT");;
         INCLUDE button element_data=post_and_print ?>
  <?lsmb INCLUDE select element_data=format ?>
  <?lsmb INCLUDE select element_data=media ?>
  <?lsmb FOREACH element_data IN selectedcheckboxes  ?>
    <?lsmb # We should use a cipher here, to avoid XSS
           element_data.type  ='hidden';
    	   element_data.value ='checked'; 
           INCLUDE input element_data?>
  <?lsmb END ?>
  <div id=div_topay_state>
  <?lsmb FOREACH item IN topay_state -?>
        <?lsmb  item.type = "hidden";
                item.name = item.id;
                INCLUDE input element_data=item ?>
  <?lsmb END -?>
  </div>          
  </form>
 </body>
</html>