<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8" />
	<title>::_("Attendance sheet")::</title>
	<link href="/css/print.css" rel="stylesheet"/>
</head>
<body>
	
	<h1>::user._amap.name::</h1>
	<h2>Livraison du ::hDate(date)::</h2>
	
		<table style="width:100%;">
				::set name = ""::
				::set name2 = ""::
				::set total = 0::
				::set productNum = 0::
				<tr>
					<th>::_("Name")::</th>
					<th>::_("Contact details")::</th>
					<th>::_("Qty")::</th>
					<th>::_("Product")::</th>
					<th>::_("U.P.")::</th>
					<th>::_("Fees")::</th>
					<th>::_("Total")::</th>
					<th>::_("Signature")::</th>
				</tr>
		
				::foreach m orders::				
				
				
				::if m.userName != name || m.userName2 != name2::
					::set class="name"::
				::else::
					::set class=""::
				::end::
				<tr class="::class::">				
					<td>
						::if m.userName != name || m.userName2 != name2::
						
								::set basket = getBasket(m.userId,place.id,date)::							
								<span ::cond basket!=null::>::_("Num"):: ::basket.num:: - </span>
						
								<b>::m.userName::</b>
								::if m.userName2 != null::
									<br />::_("alternately with"):: <b>::m.userName2::</b>
								::end::
								::set total = 0::
								::set productNum = 0::
						::end::						
					</td>
					<td>
						::if m.userName != name || m.userName2 != name2::
							::set u = getUser(m.userId):
							::if u !=null::
							$$nullSafe(::u.phone::)
							::end::

							::if m.userName2 != null::
								::set u = getUser(m.userId2):
								::if u !=null::
								<br />$$nullSafe(::u.phone::)
								::end::
							::end::
						::end::
						
					</td>
					::set name =  m.userName ::
					::set name2 =  m.userName2 ::
					<td>
						::if(m.quantity==0 && m.canceled)::
							::_("Canceled")::
						::else::
							::raw m.smartQt::
						::end::
						
						::set productNum = productNum+m.quantity::
					</td>
					<td>
						::m.productName::
					</td>
					<td>
						::formatNum(m.productPrice)::&nbsp;::currency()::
					</td>
					<td>
						::if m.fees!=null::
							::formatNum(m.fees)::&nbsp;::currency()::
						::end::
					</td>
					<td>
						::formatNum(m.total)::&nbsp;::currency()::
						::set total = total + m.total::
					</td>
					
					<td style="width:20%;"></td>
				</tr>
			
				<!--TOTAL-->
				::set next = orders[repeat.m.index+1]::
					::if next==null || next.userName!=name || next.userName2!=name2::
					<tr>
						<td></td>
						<td></td>
						<td class="total">::formatNum(productNum)::</td>
						<td class="total" colspan="2"></td>
						<td class="total">::_("TOTAL")::</td>
						<td class="total">::formatNum(total)::&nbsp;::currency()::</td>
						<td></td>
					</tr>
			
					<!-- PAIEMENTS -->
					<tr ::cond user._amap.hasPayments()::>
						
						<!--  PAYMENT CHECK FOR SHOP MODE -->
						
						::if (user._amap.hasShopMode())::

					
						<td></td>
						<th>::_("Payment:"):: </th>
						<td colspan="6">
							<table style="width:100%;border:1px solid #CCC;">
							::if(basket!=null)::
								::set tpaid=0::
								::set op = basket.getOrderOperation(false)::
								::if op!=null::
									::foreach p op.getRelatedPayments()::
									<tr>
										<td style="min-width:30px;">
											::if(p.pending==true)::
											<img src="/img/tick_no.png"/>
											::else::
											<img src="/img/tick_ok_me.png"/>
											::end::
										</td>
										<td>
											::formatNum(p.amount):: ::currency()::
											::set tpaid = p.amount+tpaid::
										</td>
										<td>
											::p.name::
										</td>
									</tr>
									::end::
								::end::
								
								<!-- bug : 2 vars are the same but == doesnt work -->
								::set total = numClean(total)::
								::set tpaid = numClean(tpaid)::
								
								::if(total!=tpaid)::
								
								<tr style="background-color:#EEE;">
									<td><img src="/img/tick_no.png"/></td>
									<td>::formatNum(total-tpaid):: ::currency()::</td>
									<td>
										::if(total>tpaid)::
											::_("To be paid"):: ::formatNum(total-tpaid):: ::currency()::
										::else::
											::_("Pay back"):: ::formatNum(tpaid-total):: ::currency()::
										::end::
									</td>
								</tr>
								::end::
							::end::
							</table>
						</td>
						
						::else::
						<!--  PAYMENT CHECK FOR STANDARD MODE -->
						<td></td>
						::set ua = u.getUserAmap(user._amap)::
						::set balance = ua.balance::
						<th>::_("Balance of the member:"):: ::ua.balance:: ::currency()::</th>
						<td colspan="6">							
							::set pending = 0::
							
							<table style="width:100%;border:1px solid #CCC;">
								<!-- payment to confirm -->
								::foreach p ua.getLastOperations(5)::
								::if p.type==2 && p.pending==true::
								<tr>
									<td style="width:30px;">
										::if(p.pending==true)::
										<img src="/img/tick_no.png"/>
										::else::
										<img src="/img/tick_ok_me.png"/>
										::end::
									</td>
									<td>
										::formatNum(p.amount):: ::currency()::											
										 - ::p.name::
										 
										::set pending = pending + p.amount:: 
										
									</td>
								</tr>
								::end::
								::end::
								
							
								<!-- need to pay more or cash back -->							
								::if(balance<0 && balance+pending!=0)::								
								<tr style="background-color:#EEE;">
									<td style="width:30px;"><img src="/img/tick_no.png"/></td>
									<td>
										::if(balance+pending<0)::
											::_("To be paid"):: ::formatNum(abs(balance+pending)):: ::currency():: pour équilibrer le solde
										::else::
											::_("Pay back"):: ::formatNum(balance+pending):: ::currency():: pour équilibrer le solde
										::end::
									</td>
								</tr>
								::end::
								
							</table>
						
							
							
						</td>
						::end::
						
						
					</tr>
					::end::
				::end::

				</table>
				
				<p>::raw nl2br(user.getAmap().txtDistrib)::</p>
		
				<p class="hidden">
					<i>::_("Push on \"Control + P\" to print this page.")::</i>					
				</p>
	
	
	
	<table class="" ::cond sqlLog::>
	::foreach r sqlLog::
	<tr ::attr class if(r.bad) 'badSql'::>
		<td>::r.t::ms</td>
		<td>::r.length::</td>
		<td><a href="#" onclick="javascript:alert('::r.explain::');return false;">Exp</a></td>
		<td><a href="#" onclick="javascript:alert('::r.stack::');return false;">Stack</a></td>
		<td>::r.sql::</td>
	</tr>
	::end::
	</table>
	
	
</body>
</html>