{extends file=$smarty.const.SMARTY_LAYOUT_DASHBOARD_WIDGET_DEFAULT}

{block name="template-head" append}
	{$CSS->loadGroup("widgetTable")}
{/block}

{block name="localCSS" append}
	<style>
		table.simpleList tbody tr td {			
			padding: 5px;
		}
				
		table.simpleList tbody td button {
			width: 150px;
		}
	
	</style>

{/block}


{block name="content"}

	{$colsAssoc=$widget['data']['columnsList']}
	
	{$statusList = $widget['data']['statusList']}
	
	{if $widget['data']['errorMessage']}
		<div class="messageDivContainer layout-inline">
			{message type='warning' message=$widget['data']['errorMessage']}
		</div>
	{else}
		{$orderEntity = \Entity\Order::select($widget['data']['orderId'])}	
		
		<table class="simpleList w100p" style="cell-padding:0; cell-spacing:0;">
			<thead>
				<tr>					
					{foreach $colsAssoc as $col => $nothing}
						<th>{$widgetLang['columnList'][$col]}</th>
					{/foreach}
				</tr>
			</thead>
			<tbody>
				{$orderGeneratedDocs = $orderEntity->generatedDocumentsAssoc}
				{foreach $widgetLang['entityList'] as $entityKey => $entityName}
					<tr>
					<td class = "left" style="width:15%;"><b>{$entityName}</b></td>
							
					{if $entityKey == 'order'}
					
						<td class="optionsBox sectionRow left">
							{*GO TO ORDER LIST*}
							<button type="button"
								{if !$widget['data']['buttons']['order']['redirectToList']}
									 onclick="window.open(MVC.appUrl('Orders/OrdersList', 'index', { 'filters[idReservation]': {$widget['data']['orderId']}, 'filters[idReservationType]':'id' }), '_blank');"
								{else} disabled="1" {/if}
							>{$widgetLang['buttons']['order']['redirectToList']}</button>	
							
							{*GENERATE DOCUMENTS ON THIS ORDER*}
							<button type="button"
								{if !$widget['data']['buttons']['order']['adminDocuments']}
									 onclick="loadPivotGenerateDoc(this, 'Generate documents', 'order', '{$widget['data']['orderId']}');"
								{else} disabled="1" {/if}
							>{$widgetLang['buttons']['order']['adminDocuments']}</button>	
							
							{*CANCEL ORDER*}
							<button type="button" 
								{if !$widget['data']['buttons']['order']['cancelOrder']}
									 onclick="return Popup2.create().setId('orderCancel').setUrl( MVC.appUrl('Orders/Cancel', 'cancelOrder', { 'idOrder' : '{$widget['data']['orderId']}' } ) ).setDimensions(550, 450).show();"
								{else} disabled="1" {/if}
							>{$widgetLang['buttons']['order']['cancelOrder']}</button>
						
						</td>
						
					
					
					{elseif $entityKey == 'service'}
						<td class="optionsBox sectionRow left">
								
								{*GO TO SERVICES LIST*}
								<button type="button"
									{if !$widget['data']['buttons']['service']['redirectToList']}
										onclick="window.open(MVC.appUrl('Orders/ServicesList', 'index', { 'filters[orderId]': {$widget['data']['orderId']}, 'filters[idOrdersTypes]':'id' }), '_blank');"
									{else} disabled="1" {/if}
								>{$widgetLang['buttons']['service']['redirectToList']}</button>	
								
								{*IMPORT SERVICES*}
								<button type="button"
									{if !$widget['data']['buttons']['service']['addImportedService']}
										onclick="importedOrderServicesList('{$widget['data']['orderId']}');"
									{else} disabled="1" {/if}
								>{$widgetLang['buttons']['service']['addImportedService']}</button>	
								
								{*ADD SERVICE*}
								<button type="button"
									{if !$widget['data']['buttons']['service']['addManualService']}
										onclick="orderServiceInsert('{$widget['data']['orderId']}', {});"
									{else} disabled="1" {/if}
								>{$widgetLang['buttons']['service']['addManualService']}</button>	
								
						</td>
					
					{elseif $entityKey == 'clientInvoice'}
					
						<td class="optionsBox sectionRow left">
							
							{*GO TO CLIENT INVOICES LIST*}
							<button type="button"
								{if !$widget['data']['buttons']['clientInvoice']['redirectToList']}
									onclick="window.open(MVC.appUrl('Invoices/InvoicesList', 'index', { 'filters[idReservation]': {$widget['data']['orderId']}, 'filters[idReservationType]':'id'}), '_blank');"
								{else} disabled="1" {/if}
							>{$widgetLang['buttons']['clientInvoice']['redirectToList']}</button>	
							
							{*ADD CLIENT INVOICE*}
							<button type="button"
								{if !$widget['data']['buttons']['clientInvoice']['addInvoice']}
									onclick=" window.open(MVC.appUrl('Invoices/InvoiceInsert', 'index', { 'idOrder' : '{$widget['data']['orderId']}' }), '_blank') "
								{else} disabled="1" {/if}
							>{$widgetLang['buttons']['clientInvoice']['addInvoice']}</button>						
						
						</td>
					
					{elseif $entityKey == 'supplierInvoice'}
					
						<td class="optionsBox sectionRow left">
						
							{*GO TO SUPPLIER INVOICES LIST*}
							<button type="button"
								{if !$widget['data']['buttons']['supplierInvoice']['redirectToList']}
									onclick="window.open(MVC.appUrl('Invoices/SupplierInvoices', 'index', { 'filters[idReservation]': {$widget['data']['orderId']}, 'filters[idReservationType]':'id'}), '_blank');"
								{else} disabled="1" {/if}
							>{$widgetLang['buttons']['supplierInvoice']['redirectToList']}</button>
						
							{*ADD SUPPLIER INVOICE*}
							<button type="button"
								{if !$widget['data']['buttons']['supplierInvoice']['addSupplierInvoice']}
									onclick="
										Popup2.create().setId( 
											'supplierInvoiceInsert').setUrl(MVC.appUrl('Invoices/SupplierInvoices/Management', 'insert', 
												{ 'orderData[reservationId]' : '{$orderEntity->convertedId}', 'orderData[reservationCode]' : '{$orderEntity->reservationCode}', 'orderData[reservationNumber]' : '{$orderEntity->reservationNumber}' } 
											) 
										).setDimensions(1500, 800).show();
									"
								{else} disabled="1" {/if}
							>{$widgetLang['buttons']['supplierInvoice']['addSupplierInvoice']}</button>
					
						
						</td>
					
					{elseif $entityKey == 'balance'}
						<td class="optionsBox sectionRow left">
						
							{*GO TO AUTOBALANCES LIST*}
							<button type="button"
								{if !$widget['data']['buttons']['balance']['redirectToList']}
									onclick="window.open(MVC.appUrl('Invoices/BalancesAuto', 'index', { 'filters[idOrder]': {$widget['data']['orderId']}, 'filters[idOrderType]':'id'}), '_blank');"
								{else} disabled="1" {/if}
							>{$widgetLang['buttons']['balance']['redirectToList']}</button>
						
							{*ORDER BALANCE*}
							<button type="button"
								{if !$widget['data']['buttons']['balance']['orderBalance']}
									onclick="
										var params = ['resetClientInvoicesFilters=1', 'dontRedirectOnClientReset=1', 'client[idReservationType]=id', 'client[idReservation]={$orderEntity->convertedId}',
											'resetSupplierInvoicesFilters=1', 'dontRedirectOnSupplierReset=1', 'supplier[idReservationType]=id', 'supplier[idReservation]={$orderEntity->convertedId}'
										];
										window.open( DCsConfigs.APP_URL + 'invoices/balanceInvoices/?' + params.join('&'), '_blank');
									"
								{else} disabled="1" {/if}
							>{$widgetLang['buttons']['balance']['orderBalance']}</button>
						
						</td>
										
					{/if}
					</tr>
				{/foreach}
			</tbody>
		</table>	
	
	{/if}
	
{/block}

	