<!DOCTYPE html>
<html lang="en">
{{fscript
	
	dueDate := NSDate date.
	arrayOfOpps := {}.

	incompleteTasks := objectContext objectsForEntityNamed:'Task' qualifierLocum:'(statusCode < 7)' bindings:nil.
	
	opsForTask := incompleteTasks opportunities.

	globals setFetchedOpportunities:(opsForTask flattenArrayOfArrays) distinct.
	globals setIncompTasks:incompleteTasks.
		
}}
<head>
	<meta charset="utf-8">
	<link rel="stylesheet" href="{{framework}}/default.css" type="text/css" charset="utf-8">
	<link rel="stylesheet" href="{{framework}}/screen.css" type="text/css" charset="utf-8" media="screen">
	<link rel="stylesheet" href="{{framework}}/print.css" type="text/css" charset="utf-8" media="print">
	
</head>
<body>
	<h2>{{localize 'Incomplete Tasks By Opportunity'}}</h2>
	{{foreach opportunity fetchedOpportunities do}}
	<br>
	Opportunity:  <b>{{opportunity.name}} </b><br>
	Status: <b>{{fscript (opportunity opportunityStateString).}}</b>
	<br><br>
	<table>
		<thead>
				<td width="40%">{{localize 'Task Name'}}</td>
				<td width="20%">{{localize 'Due Date'}}</td>
				<td width="20%">{{localize 'Status'}}</td>
				<td width="20%">{{localize 'Owner'}}</td>
		</thead>
		{{fscript
			globals setIncompTasksForOpp:nil.
			incomptasksForOpportunity := {}.
			allTasksForOpportunity := opportunity tasks.
			allTasksForOpportunity do:[:task |		
				(task statusCode < 7) ifTrue:
				[
					incomptasksForOpportunity addObject:task.
				].

			].
			incomptasksForOpportunity := incomptasksForOpportunity sortedArrayUsingDescriptors:{(NSSortDescriptor sortDescriptorWithKey:'dueDate' ascending:true)}.
			globals setIncompTasksForOpp:incomptasksForOpportunity.
			
		}}
		<tbody>{{foreach task incompTasksForOpp do}}
			<tr>
			<td>
				{{task.name}}</a>
			</td>
			<td>
				{{fscript (task dueDate) mcShortDate.}}
			</td>
			<td>
				{{fscript (task statusString).}}
			</td>
			<td>
				{{fscript task assignedTo contact derivedFullname.}}
			</td>
			</tr>{{endforeach do}}
		</tbody>	
	</table>
	
	<br>
	{{endforeach do}}

	<br>
	<br>
	<div id="reportfooter">
	{{localize 'Generated by %@ on %@', objectContext.user.contact.cachedName, date}}.		
	</div>

</body>
</html>