<?php
	$rs_pian = $dbo->fetchArray("SELECT * FROM in_interventi WHERE idintervento=\"".$id_record."\"");
?>


<!-- RIGHE -->
<div class="panel panel-<?php echo $_SESSION['profilo_pannello'] ?>">
	<div class="panel-heading">
		<h3 class="panel-title">Posizioni Ordine di Servizio <?php echo $nome_magazzino ?> </h3>
	</div>

	<div class="panel-body">
		
		<div class="row">
			<div class="col-md-12">
				<div class="pull-left">						
					<?php
					if( $pulsante_elimina == "0"  ){
					?>	
						<a class="btn btn-sm btn-info" data-href="<?php echo $rootdir ?>/modules/documenti/add_articolo.php?iddocumento=<?php echo $id_record ?>&idmodule=<?php echo $id_module ?>&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</a>					
						<a class="btn btn-sm btn-info" data-href="<?php echo $rootdir ?>/modules/documenti/add_riga.php?iddocumento=<?php echo $id_record ?>&idmodule=<?php echo $id_module ?>&dir=<?php echo $dir ?>" data-toggle="modal" data-title="Aggiungi riga" data-target="#bs-popup"><i class="fa fa-plus"></i> Riga generica</a>													
						<a class="btn btn-sm btn-info" data-href="<?php echo $rootdir ?>/modules/documenti/add_riga_g.php?iddocumento=<?php echo $id_record ?>&idmodule=<?php echo $id_module ?>&dir=<?php echo $dir ?>" data-toggle="modal" data-title="Commento" data-target="#bs-popup"><i class="fa fa-plus"></i> Commento</a>															
					<?php																		
					}				
					?>
					
					<?php 
					// cerco moduli bottoni aggiuntivi
						if( $pulsante_elimina == "0"  ){
							$query_moduli_add = "SELECT *  FROM zz_modules_add_button WHERE module_dir_from='".$modules_info[$module_name]["module_dir"]."'";
							$rs_modadd = $dbo->fetchArray($query_moduli_add);
							for( $i=0; $i<sizeof($rs_modadd); $i++ ){
								if (file_exists($docroot . "/modules/" . $rs_modadd[$i]['module_dir_to'].$rs_modadd[$i]['script'])){
									include ($docroot . "/modules/" . $rs_modadd[$i]['module_dir_to'].$rs_modadd[$i]['script']);
								}
							}
						}
					?>	
				</div>				
			</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 width="3%">Ord.</th>
					<th>Descrizione</th>
					<?php
					if( $records[0]['id_contratto'] != "0" && $records[0]['id_contratto'] != "" ){
					?>	
						<th class="text-center" width="120">Canone</th>
						<th width="60">Opzioni</th>
					<?php																		
					}
					?>	
					<th class="text-center" width="120">Magazzino</th>	
					<th width="120">Q.t&agrave; nel Doc.</th>					
					<th width="80">U.m.</th>
					<th width="120">Costo unitario</th>
					<th width="120">Iva</th>
					<th width="120">Imponibile</th>
					<th width="60">Funzioni</th>
					<?php
					if( $abilita_transazioni != "0"  ){
					?>	
						<th width="120">T.Successive</th>
					<?php																		
					}
					?>	
					<th width="70">Id Rif</th>
				</tr>		
					<?php include($docroot."/modules/documenti/row-list.php"); ?>
				</table>
			</div>
		</div>
		
	</div>
</div>
	<div class="panel panel-<?php echo $_SESSION['profilo_pannello'] ?>">
		<div class="panel-heading">
			<h3 class="panel-title">Pianificazione</h3>
		</div>
		
		<div class="panel-body">
			<div class="row">
			<div class="col-md-12">
				<?php
					if( $ordine_servizio=='1' ){			
						if( $records[0]['firma_file'] == '' ){
							$icona="fa fa-pencil-square-o";	
							$frase = "Attività da firmare";	
							$button="btn btn-sm btn-danger";							
							?>				
								<a type="button" class="<?php echo $button ?>" onclick="launch_modal( 'Anteprima e firma', '<?php echo $rootdir ?>/modules/documenti/add_firma_riepilogo.php?id_module=<?php echo $id_module ?>&id_record=<?php echo $id_record ?>&idmodulo=<?php echo $id_module ?>&idintervento=<?php echo $id_record ?>&anteprima=1', 1 );"><i class="fa fa-print"></i> <?= $frase ?></a>
							<?php	
								
						}
						else{
							$icona="fa fa-pencil-square";
							$frase = "Attività firmata";
							$button="btn btn-sm btn-success";
						?>									
						<a type="button" class="<?php echo $button ?>" href="<?php echo $rootdir ?>/templates/pdfgen.php?ptype=<?php echo $dir_pdf_attivita ?>&idintervento=<?php echo $id_record ?>" target="_blank"><i class="fa fa-print"></i> Stampa Attività</a>
								
						<button type="button" class="btn btn-sm btn-info" 
							onclick="launch_modal( 'Invio Report Attività tramite E-mail', '<?php echo $rootdir ?>/modules/documenti/mail_pdf_intervento.php?id_module=<?php echo $id_module ?>&idintervento=<?php echo $id_record ?>',1);">
							<i class="fa fa-envelope"></i> Invia Mail</button>																						
								<?php							
							}
						}					
				?>
				</div>	
			</div>	
		</div>				

		<div class="panel-body">
			<div class="row">
				<div class="col-md-12">
					<div class="panel-body">
						<?php include($docroot."/modules/documenti/ajax_pianificazione.php"); ?>	
					</div>
				</div>
			</div>	
		</div>
	</div>

	<!-- ARTICOLI -->
	<div class="panel panel-<?php echo $_SESSION['profilo_pannello'] ?>">
		<div class="panel-heading">
			<h3 class="panel-title">Materiale utilizzato</h3>
		</div>		
		<div class="panel-body">
			<div class="row">
				<div class="col-md-12">
					<div class="pull-left showcase sweet2"> 		
						<button type="button" class="btn btn-sm btn-info" aria-label="Show SweetAlert2 success message" ><i class="fa fa-plus"></i> Inserisci come posizioni</span></button>		
					</div>
				</div>
			</div>
		</div>
		<div class="panel-body">
			<div id="articoli">
				<?php include($docroot."/modules/documenti/ajax_articoli.php"); ?>
			</div>
		</div>
	</div>
	<!-- SPESE AGGIUNTIVE -->
	<div class="panel panel-<?php echo $_SESSION['profilo_pannello'] ?>">
		<div class="panel-heading">
			<h3 class="panel-title">Altre spese</h3>
		</div>
		<div class="panel-body">
			<div class="row">
				<div class="col-md-12">
					<div class="pull-left showcase sweet3"> 		
						<button type="button" class="btn btn-sm btn-info" aria-label="Show SweetAlert2 success message" ><i class="fa fa-plus"></i> Inserisci come posizioni</span></button>		
					</div>
				</div>
			</div>
		</div>
		<div class="panel-body">
			<div id="righe">
				<?php include($docroot."/modules/documenti/ajax_righe.php"); ?>
			</div>
		</div>
	</div>

	
<form action="" method="post" role="form" id="form-insart">
	<input type="hidden" name="backto" value="record-edit">
	<input type="hidden" name="op" value="inserisco_art_come_posizione">
</form>	
<form action="" method="post" role="form" id="form-insrighe">
	<input type="hidden" name="backto" value="record-edit">
	<input type="hidden" name="op" value="inserisco_riga_come_posizione">
</form>		
	
<script>
	
	$('.showcase.sweet2 button').on('click', () => {
		swal({
		  title: 'Sei sicuro?',
		  text: "Confermi inserimento articoli nelle posizioni del documento!",
		  type: 'warning',
		  showCancelButton: true,
		  confirmButtonColor: '#3085d6',
		  cancelButtonColor: '#d33',
		  confirmButtonText: 'Conferma!'
		}).then((result) => {
		  if (result.value) {			
			 { $('#form-insart').submit(); }
		  }
		})
	})
	$('.showcase.sweet3 button').on('click', () => {
		swal({
		  title: 'Sei sicuro?',
		  text: "Confermi inserimento spese nelle posizioni del documento!",
		  type: 'warning',
		  showCancelButton: true,
		  confirmButtonColor: '#3085d6',
		  cancelButtonColor: '#d33',
		  confirmButtonText: 'Conferma!'
		}).then((result) => {
		  if (result.value) {			
			 { $('#form-insrighe').submit(); }
		  }
		})
	})
	
</script>

	