<?lsmb INCLUDE 'ui-header.html' 
	titlebar = 'Payments'
	include_stylesheet = [
			'css/global.css' 
			'UI/payments/payments.css'
		]
?>
<?lsmb BLOCK format_money ?><?lsmb FILTER format('%15.2f') ?><?lsmb number 
?><?lsmb END # filter ?><?lsmb END # block ?>
 <?lsmb PROCESS elements.html  # Include form elements helper. ?>
<?lsmb contact_type = (account_class == 1) ? text('Vendor') : text('Customer') 
?>
<?lsmb payment_type = (account_class == 1) ? text('Payments') : text('Receipts') 
?>
<body id="payment_2_body">
<!-- CT:  This template produces invalid XHTML due to the use of nested tables.
    Because nested tables are widely used (perhaps improperly) for layout,
    most browsers should have no issues with them.  Furthermore, I cannot find
    any cleaner solution to embedding tabular data within tabular data than
    this -->
<div class="listtop"><?lsmb payment_type ?></div>
 <form name="pay_dues" method="post" action="payment.pl">
 <!-- Moving all hidden variables to the top.  -CT -->
 <?lsmb INCLUDE input element_data = {
	type = "hidden"
	name = "project_id"
	value = project_id
 } ?>
 <?lsmb INCLUDE input element_data = {
	type = "hidden"
	name = "account_class"
	value = account_class

 } ?>
 <?lsmb INCLUDE input element_data = {
	type = "hidden"
	name = "department_id"
	value = department_id
 } ?>
 <?lsmb INCLUDE input element_data = {
	type = "hidden"
	name = "source_start"
	value = source_start
 } ?>
 <?lsmb INCLUDE input element_data = {
	type = "hidden"
	name = "approved"
	value = approved
 } ?>
 <?lsmb INCLUDE input element_data = {
	type = "hidden"
	name = "currency"
	value = currency
 } ?>
 <?lsmb INCLUDE input element_data = {
	type = "hidden"
	name = "ar_ap_accno"
	value = ar_ap_accno
 } ?>	
 <?lsmb INCLUDE input element_data = {
	type = "hidden"
	name = "date_from"
	value = date_from
 } ?>
 <?lsmb INCLUDE input element_data = {
	type = "hidden"
	name = "date_to"
	value = date_to
 } ?>
 <?lsmb INCLUDE input element_data = {
	type = "hidden"
	name = "business_id"
	value = business_id
 } ?>
 <?lsmb INCLUDE input element_data = {
	type = "hidden"
	name = "batch_id"
	value = batch_id
 } ?>
<div class="container">
     <div id="date_row">
      <label for="date_paid"><?lsmb text('Posting Date:') ?></label>
	<?lsmb IF batch_id ?>
		<?lsmb IF ! datepaid ?><?lsmb datepaid = batch_date 
		?><?lsmb END ?>
		<span id="date_paid"><?lsmb datepaid ?></span>
	<?lsmb END ?>
	<?lsmb INCLUDE input element_data= {
		value = datepaid
		name = "datepaid" 
		size = 20
		class = (batch_id) ? "hidden" : "date"
		type = (batch_id) ? "hidden" : "text"
	} ?>

     </div>
     <div id="date_filter_row">
	<label for="filter_from"><?lsmb text('Filtering From:') ?></label>
	<span id="filter_from"><?lsmb date_from ?> </span>
	<label for="filter_to"><?lsmb text('To:') ?></label>
	<span id="filter_to"><?lsmb date_to ?> </span>
     <!-- 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 ?>
      <div class="info">
      <label for="department_info"><?lsmb  text('Department')  ?></label>
      <span id="department_info">
       <?lsmb  department ?>
      </span>
     </div>
     <?lsmb END ?>
     <div class="info" id="account_row">
      <label for="account_info">
	<?lsmb text('Account:'); ?> 
      </label>
      <span id="account_info"></td>
	<?lsmb FOREACH a = debt_accounts ?><?lsmb
		IF a.accno == ar_ap_accno 
	?><?lsmb a.accno ?>--<?lsmb a.description ?><?lsmb
		END # If a.accno... ?><?lsmb
	END # FOREACH a ?>
      </span>
     </div>
     <?lsmb  IF defaultcurrency != curr ?>
      <div class="info" id="exrate_row">
         <?lsmb PROCESS input element_data= {
		label = text('Exchange Rate')
		type = text
		class = "numeric"
		name = 'exchange_rate'
		value = exchange_rate
		size = 20
	} # ' ?>
	</div>
     <?lsmb END ?>
     <?lsmb IF business ?>
     <div class="info">
	<label for="business_info"><?lsmb text('Business:') ?></label>
	<span id="business_info"><?lsmb FOREACH b = businesses ?>
		<?lsmb IF b.id == business ?>
		<?lsmb b.id ?> -- <?lsmb b.description ?>
		<?lsmb END # if b.id... ?>
	<?lsmb END # foreach b ?></span>
    </div>
    <?lsmb END # if business ?>
    <div class="info" id="cash_account_div">
	<?lsmb INCLUDE input element_data = {
		type = "hidden"
		name = "cash_accno"
		value = cash_accno
	} ?>
	<label><?lsmb text('Pay From') ?></label>
	<?lsmb FOR c = cash_accounts -?>
		<?lsmb IF c.accno == cash_accno -?>
		<?lsmb c.accno ?>--<?lsmb c.description ?>
		<?lsmb END # if c.accno -?>
	<?lsmb END # for c -?>
    </div>
    <table id="payments_table">
    <tr class="listheading">
	<th class="account_number"><?lsmb text('Account_number') ?></th>
	<th class="entity_name"><?lsmb text('Name') ?></th>
	<th class="invoice"><?lsmb text('Invoice Total') ?></th>
        <th class="payment"><?lsmb text('Payment') ?></th>
        <th class="payment"><?lsmb text('Details') ?></th>
    </tr>
    <?lsmb rc = 1 ?><?lsmb count = 0 ?>
    <?lsmb FOREACH r = contact_invoices ?>
    <?lsmb rc = (rc + 1) % 2; count = count + 1 ?>
    <tr class="listrow<?lsmb rc ?>">
       <td class="account_number" rowspan="2" >
		<?lsmb INCLUDE input element_data = {
			type = "hidden"
			name = "contact_$count"
			value = r.contact_id
		} ?>
		<?lsmb INCLUDE input element_data = {
			type = "checkbox"
			name = "id_$r.contact_id"
			value = r.contact_id
			checked = (r.unselected) ? "" : "checked" 
			
		} ?>
		<?lsmb r.account_number ?>
	</td>
	<td class="entity_name"><span class="<?lsmb
		IF r.has_vouchers; 'name_has_vouchers' ; 
		ELSE ; 'name_has_no_vouchers' ; 
		END
		?>"><?lsmb r.contact_name ?></span></td>
	<td class="invoice"><?lsmb r.total_due ?> <?lsmb currency ?></td>
        <td class="payment">
		<?lsmb INCLUDE input element_data = {
		name = "paid_$r.contact_id"
		value = "some"
		label = text('Some')
		checked = ("${paid_$r.contact_id}" == 'some') ? checked : ""
		type = "radio"
	 }	?>
		<?lsmb INCLUDE input element_data = {
		name = "paid_$r.contact_id"
		value = "all"
		label = text('All')
		checked = ("${paid_$r.contact_id}" != 'some') ? checked : ""
		type = "radio"
	 }	?>
	</td>
	<td rowspan = 2><?lsmb INCLUDE input element_data = {
		name = "source_$r.contact_id"
		value = r.source 
		type = "text"
		size = "20" 
		label = text('Source')
	} ?></td>
    </tr>
    <tr class="listrow<?lsmb rc ?>">
	<td class="invoice_detail_list" colspan="3">
	<table id = "invoice_data_table_<?lsmb r.contact_id ?>" width="100%">
		<tr class="listheading">
			<th class="invoice_date_list"><?lsmb text('Date') ?>
			</th>
			<th class="invoice_list">
				<?lsmb text('Invoice Number') ?>
			</th>
		        <th class="total_due_list"><?lsmb text('Total') ?></th>
			<th class="paid_list"><?lsmb text('Paid') ?></th>
			<th class="net_due_list"><?lsmb text('Net Due') ?> </th>
			<th class="to_pay_list"><?lsmb text('To Pay') ?></th>
		</tr>
		<?lsmb icount = 0 ?>
		<?lsmb FOREACH i = r.invoices ?>
		<?lsmb icount = icount + 1 ?>
		<tr>
			<td class="invoice_date_list">&nbsp;<?lsmb i.2 ?></td>
			<td class="invoice_list">&nbsp;<?lsmb i.1 ?></td>
		        <td class="total_due_list">&nbsp;
				<?lsmb INCLUDE format_money number=i.3 ?></td>
			<td class="paid_list">&nbsp;
				<?lsmb INCLUDE format_money number=i.4 ?></td>
			<td class="net_due_list">&nbsp;
				<?lsmb INCLUDE format_money number= i.6 ?>
				<?lsmb currency ?></td>
			<td class="to_pay_list">
			<?lsmb IF ! ${"payment_$r.contact_id_$i.0"} ?>
				
			<?lsmb ${"payment_$r.contact_id_$i.0"} = 
				INCLUDE format_money number= i.6  ?>
			<?lsmb END # if ?>
			<?lsmb INCLUDE input element_data = {
				name = "payment_$r.contact_id_$i.0"
				value = ${"payment_$r.contact_id_$i.0"}
				size = 20
				type = "text"
				class = "monetary"
			} ?>
			<?lsmb INCLUDE input element_data = {
				type = "hidden"
				name = "invoice_${r.contact_id}_$icount"
				value = i.0
			} ?>
			<?lsmb INCLUDE input element_data = {
				type = "hidden"
				name = "net_$i.0"
				value = ${"payment_$r.contact_id_$i.0"}
			} ?>
			</td>
		</tr>
		<?lsmb END # foreach i ?>
		<?lsmb INCLUDE input element_data = {
			type = "hidden"
			name = "invoice_count_${r.contact_id}"
			value = icount
		} ?>
	</table>
    </tr>
   <?lsmb END # foreach r ?>
    </table>
    <?lsmb INCLUDE input element_data = {
	type = "hidden"
	name = "contact_count"
	value = count
    } ?>
    <?lsmb INCLUDE button element_data = {
	text = text((batch_id) ? 'Save' : 'Post'),
	value = 'post_payments_bulk'
	class = "submit"
	name = 'action'
	} ?>
    <?lsmb INCLUDE button element_data = {
	text = text('Add Payment Fees') # '
	value = 'paycom_add_fees'
	class = 'submit'
	name = 'action'
	} ?>
  </form>
 </body>
</html>