{extends file=$smarty.const.SMARTY_LAYOUT_DASHBOARD_WIDGET_DEFAULT}

{block name="content"}
	
	{if $widget['data']}
		
		<table class="simpleList w100p">
			<thead>
				<tr>
					<th class="center">{$_LANG['dashboard']['widgetsList']['App\Dashboard\Widget\KamSalesTargets']['options']['month']}</th>
					<th class="center">{$_LANG['dashboard']['widgetsList']['App\Dashboard\Widget\KamSalesTargets']['options']['totalSales']} [{$widget['defaultCurrency']}]</th>
					<th class="center">{$_LANG['dashboard']['widgetsList']['App\Dashboard\Widget\KamSalesTargets']['options']['salesTarget']} [{$widget['defaultCurrency']}]</th>
					<th class="center">{$_LANG['dashboard']['widgetsList']['App\Dashboard\Widget\KamSalesTargets']['options']['totalContacts']}</th>
					<th class="center">{$_LANG['dashboard']['widgetsList']['App\Dashboard\Widget\KamSalesTargets']['options']['contactsTarget']}</th>
				</tr>
			</thead>
			
			{foreach $widget['data'] as $month=>$monthData}
				<tr class="{cycle values="odd,even"}">
					<td>{$_LANG['date']['month']['long'][$month]}</td>
					<td>
						{if $monthData['salesTarget']>0}
							{$achievedPc = ($monthData['salesTotal']/$monthData['salesTarget'])|round:2}
						{else}
							{$achievedPc = 0}
						{/if}
						{if $achievedPc>1}
							{$displayPc=($achievedPc-1)*100}
							{$tooltip="{$_LANG['dashboard']['widgetsList']['App\Dashboard\Widget\KamSalesTargets']['options']['tooltipOverachievedPc']}"}
						{else}
							{$displayPc=$achievedPc*100}
							{$tooltip="{$_LANG['dashboard']['widgetsList']['App\Dashboard\Widget\KamSalesTargets']['options']['tooltipAchievedPc']}"}
						{/if}
						
						{if $monthData['salesTarget']>0}
							<div style="color:{if $achievedPc<1}#ff0000{else}#22cc22{/if};">
								<div style="float:left;" tooltip="{$tooltip}">[{if $achievedPc>1}+{/if}{$displayPc}%]</div>
								<div style="float:right;">{$monthData['salesTotal']|priceFormat}</div>
							</div>
						{else}
							<div style="float:right;">{$monthData['salesTotal']|priceFormat}</div>
						{/if}
					</td>
					<td>
						{if $monthData['salesTarget']>0}
							<div style="float:right;">{$monthData['salesTarget']|priceFormat}</div>
						{else}
							-
						{/if}
					</td>
					<td>
						{if $monthData['contactsTarget']>0}
							{$achievedPc = ($monthData['contactsTotal']/$monthData['contactsTarget'])|round:2}
						{else}
							{$achievedPc = 0}
						{/if}
						{if $achievedPc>1}
							{$displayPc=($achievedPc-1)*100}
							{$tooltip="{$_LANG['dashboard']['widgetsList']['App\Dashboard\Widget\KamSalesTargets']['options']['tooltipOverachievedPc']}"}
						{else}
							{$displayPc=$achievedPc*100}
							{$tooltip="{$_LANG['dashboard']['widgetsList']['App\Dashboard\Widget\KamSalesTargets']['options']['tooltipAchievedPc']}"}
						{/if}
						
						{if $monthData['contactsTarget']>0}
							<div style="color:{if $achievedPc<1}#ff0000{else}#22cc22{/if};">
								<div style="float:left;" tooltip="{$tooltip}">[{if $achievedPc>1}+{/if}{$displayPc}%]</div>
								<div style="float:right;">{$monthData['contactsTotal']}</div>
							</div>
						{else}
							<div style="float:right;">{$monthData['contactsTotal']}</div>
						{/if}
					</td>
					<td>
						{if $monthData['contactsTarget']>0}
							<div style="float:right;">{$monthData['contactsTarget']}</div>
						{else}
							-
						{/if}
					</td>
				</tr>
			{/foreach}
			
		</table>
		
	{/if}

{/block}
