<?php
	include_once(__DIR__."/../../core.php");

	
	

	$module_name = "Tipi di canone";
	
	$iddocumento = $html->form('iddocumento');
	$idriga = $html->form('idriga');
	
	//Info riga inserita
	$q = "SELECT * FROM co_contratti_tipi_righe WHERE id='".$idriga."'";
	$rsr = $dbo->fetchArray($q);
	$idconto_fattura = $rsr[0]['idconto'];
	$id_magazzino_e=$rsr[0]['id_magazzino_e'];
	
	/*
		Form di modifica riga documento
	*/
	echo "<label>Modifica riga </label><br><br>\n";
	echo "<form id=\"link_form\" action=\"".$rootdir."/editor.php?id_module=".$modules_info[$module_name]['id']."&id_record=".$iddocumento."\" method=\"post\">\n";
	
	echo "	<input type='hidden' name='op' value='editriga'>\n";
	echo "	<input type='hidden' name='idriga' value='".$idriga."'>\n";
	echo "	<input type='hidden' name='backto' value='record-edit'>\n";
	echo "	<input type='hidden' name='dir' value='".$dir."'>\n";
	
	
	
	//Descrizione
	echo "	<div class='row'>\n";
	echo "		<div class='col-md-12'>\n";
	echo "			<label>Descrizione</label>\n";
	echo "			<textarea name=\"descrizione\" id=\"descrizione\" class='form-control' >".$rsr[0]['descrizione']."</textarea>\n";
	echo "		</div>\n";
	echo "	</div>\n";
			
	echo "<br>";

	echo "<div class='panel panel-primary'>";
		echo "<div class='panel-body'>";
			echo "	<div class='row'>\n";	
			//Qta	
				echo "		<div class='col-md-2'>\n";
				echo "			<div class='form-group'>\n";
				echo "				<label>Q.t&agrave;</label>\n";
				echo "				<div class='input-group'>\n";
				echo "					<input type='text' class='form-control inputmask-decimal' id='qta' maxlength='8' name='qta' value=\"".$rsr[0]['qta']."\">\n";
				echo "				</div>\n";
				echo "			</div>\n";
				echo "		</div>\n";		
			
			//Costo unitario
				echo "		<div class='col-md-3'>\n";
				echo "			<div class='form-group'>\n";
				echo "				<label>Costo unitario</label>\n";
				echo "				<div class='input-group'>\n";
				echo "					<input type='text' class='form-control inputmask-decimal' id='subtot' name='subtot' value=\"".number_format($rsr[0]['subtotale']/$rsr[0]['qta'], get_var("Cifre decimali"), ".", "")."\"><span class='input-group-addon'>&euro;</span>\n";
				echo "				</div>\n";
				echo "			</div>\n";
				echo "		</div>\n";
							
			echo "		</div>\n";	
		echo "		</div>\n";		
	echo "		</div>\n";		
	
	
	
	
	echo "<div class='panel panel-primary'>";
		echo "<div class='panel-body'>";
			echo "	<div class='row'>\n";		
			//Sconto
				echo "		<div class='col-md-3'>\n";
					echo "			<div class='form-group'>\n";
					echo "				<label>Sconto</label>\n";
					echo "				<div class='input-group'>\n";
					if($rsr[0]['tipo_sconto']=='2'){
						echo "					<input type='text'  class='form-control text-right'  id='sconto' name='sconto' value=\"".number_format($rsr[0]['sconto_primo'], get_var("Cifre decimali"), ".", "")."\"  />\n";
					}else{
						echo "					<input type='text'  class='form-control inputmask-decimal'  id='sconto' name='sconto' value=\"".number_format($rsr[0]['sconto']/$rsr[0]['qta'], get_var("Cifre decimali"), ".", "")."\"  />\n";
					}
					
					echo "				</div>\n";
					echo "			</div>\n";
				echo "		</div>\n";
			//Sconto 1
				echo "		<div class='col-md-3'>\n";
					echo "		<div class='form-group'>\n";
					echo "			<label>Extra</label>\n";
					echo "				<div class='input-group'>\n";
					if($rsr[0]['tipo_sconto']=='2'){
						echo "					<input type='text'  class='form-control inputmask-decimal'  id='sconto_extra' name='sconto_extra' value=\"".number_format($rsr[0]['sconto_extra'], get_var("Cifre decimali"), ".", "")."\"  />\n";
					}else{
						echo "					<input type='text'  class='form-control inputmask-decimal'  id='sconto_extra' name='sconto_extra' value=\"".number_format($rsr[0]['sconto_extra']/$rsr[0]['qta'], get_var("Cifre decimali"), ".", "")."\"  />\n";
					}
					echo "				</div>\n";
					echo "			</div>\n";
				echo "		</div>\n";
			//Sconto
				echo "		<div class='col-md-3'>\n";
				echo "			<div class='form-group'>\n";
				echo "				<label>Extra</label>\n";
				echo "				<div class='input-group'>\n";
				if($rsr[0]['tipo_sconto']=='2'){
					echo "					<input type='text'  class='form-control inputmask-decimal'  id='sconto_extra1' name='sconto_extra1' value=\"".number_format($rsr[0]['sconto_extra1'], get_var("Cifre decimali"), ".", "")."\"  />\n";
				}else{
					echo "					<input type='text'  class='form-control inputmask-decimal'  id='sconto_extra1' name='sconto_extra1' value=\"".number_format($rsr[0]['sconto_extra1']/$rsr[0]['qta'], get_var("Cifre decimali"), ".", "")."\"  />\n";
				}		
				echo "				</div>\n";
				echo "			</div>\n";
				echo "	</div>\n";				
				//Tipo Sconto
				$query = "SELECT * FROM co_tipisconto";
				$rs = $dbo->fetchArray($query);	
				echo "		<div class='col-md-3'>\n";
				echo "			<label>Tipologia Sconto</label>\n";
					echo "			<select id='idtiposconto' class='superselect' name=\"idtiposconto\">\n";														
					if($rsr[0]['tipo_sconto']=='2'){
						echo "					<option value='2'>Percentuale</option>\n";	
					}else{
						echo "					<option value='1'>Fisso</option>\n";	
						
					}	
					for( $i=0; $i<sizeof($rs); $i++ ){				
						echo "	<option value='".$rs[$i]['id']."' $attr>".$rs[$i]['descrizione']."</option>\n";
					}	
					echo "			</select>\n";	
				echo "		</div>\n";
			echo "		</div>\n";		
		echo "		</div>\n";	
	echo "	</div>\n";
	

	
	echo "	<a onclick=\"addriga();\" class=\"btn btn-primary pull-right\"><i class=\"fa fa-edit\"></i> Modifica</a>\n";
	echo "</form>\n";
?>

	<script type="text/javascript">
	
		function addriga(){
			if( $('#descrizione').val()!='' && $('#idiva option:selected').val()!='' ){
				$("#link_form").submit();
			}
		}
		
		$(document).ready( function(){
		
			start_superselect();
			start_inputmask();
		
		});
	</script>

	<div class="clearfix"></div>

