<script src="<?php echo $js ?>/bootstrap-colorpicker.min.js"></script>
<link rel="stylesheet" href="<?php echo $css ?>/bootstrap-colorpicker.min.css">

<form action="" method="post" role="form">
	<input type="hidden" name="backto" value="record-edit">
	<input type="hidden" name="op" value="update">
	<input type="hidden" name="id_record" value="<?php echo $id_record ?>">

	<?php
	//svuto varaibile di sessione
		$_SESSION['filtro_categoria']="0";
		$_SESSION['filtro_fornitore']="0";
	// ricerco eventuali canoni in stato 	
		$contratti_attivi=cerca_contratti_attivi($records[0]['id']);
		if ( $contratti_attivi > 0 ) echo "<div class='alert alert-warning'><i class='fa fa-warning'></i> Impossibile rimozione o modifiche della seguente tipologia di canone. Vi sono ".$contratti_attivi." Canoni con stato: ACCETTATO </a></div>\n";					
	?>

	
	<div class="panel panel-primary">
		<div class="clearfix"></div>
		</br>	
		<div class="col-md-4">				
			<div class="pull-left">		
				<?php
				if( $contratti_attivi == "0"  ){
				?>	
					 		
						<button type="submit" class="btn-app btn-success"><i class="fa fa-check"></i> Salva </button>		
					
				<?php																		
				}
				?>						
			</div>
		</div>
		<div class="col-md-4">				
			<div class="pull-right">								
				<?php
				if( $contratti_attivi == "0"  ){
				?>	
					<div class="pull-left showcase sweet"> 		
					<button type="button" class="btn-app btn-danger" aria-label="Show SweetAlert2 success message" ><i class="fa fa-trash-o"></i> Elimina</span></button>		
					</div>
				<?php																		
				}
				?>
	
			</div>	
		</div>
		
		<div class="col-md-4">
					
		</div>			
		<div class="clearfix"></div>
		
	</div>
	<div class="panel panel-primary">
		<div class="panel-heading">
			<h3 class="panel-title">Descrizione</h3>
		</div>		
		<div class="panel-body">	
			<div class="row">
				<div class="col-md-4">
					{[ "type": "span", "label": "Codice", "name": "idtipocontratto", "required": 0, "class": "", "value": "$idtipocontratto$", "extra": "" ]}
				</div>
				
				<div class="col-md-6">
					{[ "type": "text", "label": "Descrizione", "name": "descrizione", "required": 1, "class": "", "value": "$descrizione$", "extra": "" ]}
				</div>
				
			</div>
		</div>
	</div>
			
	<div class="panel panel-primary">
		<div class="panel-heading">
			<h3 class="panel-title">Impostazione Fisse unitari</h3>
		</div>
		
		<div class="panel-body">
			<div class="row">
				<div class="col-md-2">
					{[ "type": "text", "label": "Costo km", "name": "costo_km", "required": 0, "class": "inputmask-decimal", "value": "$costo_km$", "extra": "", "icon-after": "<i class='fa fa-euro'></i>" ]}
				</div>
				
				<div class="col-md-2">
					{[ "type": "text", "label": "Importo Mensile", "name": "costo_mensile", "required": 0, "class": "inputmask-decimal", "value": "$costo_mensile$", "extra": "", "icon-after": "<i class='fa fa-euro'></i>" ]}
				</div>
				<div class="col-md-2">
					{[ "type": "text", "label": "Importo annuale", "name": "costo_annuale", "required": 0, "class": "inputmask-decimal", "value": "$costo_annuale$", "extra": "", "icon-after": "<i class='fa fa-euro'></i>" ]}
				</div>	
				<!--			
				<div class="col-md-2">
					{[ "type": "checkbox", "label": "Fattura Mensile", "name": "v_fattura_mensile", "required": 0, "class": "", "values": "$v_fattura_mensile$", "value": "$v_fattura_mensile$", "extra": "", "help": "", "placeholder": "Attivo" ]}
				</div>	
				-->
				<div class="col-md-2">
					{[ "type": "checkbox", "label": "Forza importi = 0", "name": "v_ins_righe_zero", "required": 0, "class": "", "values": "$v_ins_righe_zero$", "value": "$v_ins_righe_zero$", "extra": "", "help": "", "placeholder": "Attivo" ]}
				</div>		

			</div>
		</div>
	</div>
	<div class="panel panel-primary">
		<div class="panel-heading">
			<h3 class="panel-title">Personalizzazione Importi Posizioni Ordini di Servizio</h3>
		</div>
		
		<div class="panel-body">
			<div class="row">
				<div class="col-md-12">
					<?php
					if( $contratti_attivi == "0"  ){
					?>	
						<div class="pull-left">						
							<a class="btn btn-sm btn-info" data-href="<?php echo $rootdir ?>/modules/contratti_tipo/add_articolo.php?iddocumento=<?php echo $id_record ?>&dir=<?php echo $dir ?>&filtra_art=<?php echo $filtra_art ?>" data-toggle="modal" data-title="Aggiungi articolo" data-target="#bs-popup"><i class="fa fa-plus"></i> Articolo Ordine di servizio</a>						
						</div>	
					<?php																		
					}
					?>				
				</div>
			</div>
			<div class="clearfix"></div>
			<br>
			<div class="row">
				<div class="col-md-12">
					<table class="table table-striped table-hover table-condensed table-bordered">
					<tr>
						<th>Descrizione</th>															
						<th width="80"></th>
						<th width="120">Costo unitario</th>						
						<th width="120">Imponibile</th>
						<th width="60">Funzioni</th>
					</tr>		
					<?php include($docroot."/modules/contratti_tipo/row-list.php"); ?>	
								
					</table>
				</div>
			</div>
		</div>
	</div>
	<div class="panel panel-primary">
		<div class="panel-heading">
			<h3 class="panel-title">Personalizzazione Posizioni Ordini di Servizio a Scalare</h3>
		</div>		
		<div class="panel-body">
			<div class="row">
				<div class="col-md-12">
					<?php
					if( $contratti_attivi == "0"  ){
					?>	
						<div class="pull-left">						
							<a class="btn btn-sm btn-info" data-href="<?php echo $rootdir ?>/modules/contratti_tipo/add_articolo_qt.php?iddocumento=<?php echo $id_record ?>&dir=<?php echo $dir ?>&filtra_art=<?php echo $filtra_art ?>" data-toggle="modal" data-title="Aggiungi articolo" data-target="#bs-popup"><i class="fa fa-plus"></i> Articolo Ordine di servizio</a>						
						</div>	
					<?php																		
					}
					?>					
				</div>
			</div>
			<div class="clearfix"></div>
			<br>
			<div class="row">
				<div class="col-md-12">
					<table class="table table-striped table-hover table-condensed table-bordered">
					<tr>
						<th>Descrizione</th>
						<th width="80">Qta.Scalare</th>
						<th width="60">Funzioni</th>
					</tr>		
					<?php include($docroot."/modules/contratti_tipo/row-list-qt.php"); ?>	
								
					</table>
				</div>
			</div>
		</div>
	</div>
	<div class="panel panel-primary">
		<div class="panel-heading">
			<h3 class="panel-title">Note</h3>
		</div>
		
		<div class="panel-body">
			<div class="row">
				<div class="col-md-12">
					{[ "type": "textarea", "label": "Note", "name": "note", "required": 0, "class": "autogrow", "value": "$note$", "extra": "rows='5'" ]}
				</div>						
			</div>
		</div>
	</div>
	
</form>


<form action="" method="post" role="form" id="form-delete">
	<input type="hidden" name="backto" value="record-list">
	<input type="hidden" name="op" value="delete">
	
</form>

<script>

	var id_module = "<?php echo $_GET['id_module'] ?>";
	var idanagraficacerca = "<?php echo $idanagrafica ?>";
	
	
	$('#idcategoria').change( function(){ 			
		$.get('<?php echo $rootdir ?>/ajax_autocomplete.php?module=FiltroCat&idcategoria='+this.value+'&idmodulo='+id_module , function(data,response){ 				
		start_jquerychosen();
			start_inputmask();		
		});	
	});	
	
	$('#filtro').change( function(){ 	
		$.get('<?php echo $rootdir ?>/ajax_autocomplete.php?module=Filtro&idfiltro='+this.value+'&idmodulo='+id_module , function(data,response){ 				
		start_jquerychosen();
			start_inputmask();		
		});	
	});	


	$(document).ready( function(){
		$('.colorpicker').colorpicker().on('changeColor', function(){
			$('#colore').parent().find('.square').css( 'background', $('#colore').val() );
		});

		$('#colore').parent().find('.square').css( 'background', $('#colore').val() );
	});
	$('.showcase.sweet button').on('click', () => {
		swal({
		  title: 'Sei sicuro?',
		  text: "Eliminare questo elemento!",
		  type: 'warning',
		  showCancelButton: true,
		  confirmButtonColor: '#3085d6',
		  cancelButtonColor: '#d33',
		  confirmButtonText: 'Conferma!'
		}).then((result) => {
		  if (result.value) {			
			{ $('#form-delete').submit(); }
		  }
		})
	})		
</script>