<?php

session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DMMYSQLG.php");
$com = "A";
include("DF30000.inc");
include("DF80000.php");
include("DFJSISCI.inc");
require_once("DFJQUERY.inc");
?>
<html>
<head>
<link rel="stylesheet" href="css/estilo1.csss" type="text/css"/>
<script>
function subt(price,cant,porde,poriv)
{
//Dimensiono name como nuevo arreglo
var subt = new Array();
var de = new Array();
var iv = new Array();
//En name guardo un split o recorte del nombre recibido en cant separado por el _
subt = cant.split("_");
de=porde.split("_");
iv=poriv.split("_");
sbt=price.split("_");
//Multiplico precio por cantidad
var subtot = parseFloat (document.getElementById(price).value) * parseFloat (document.getElementById(cant).value);
var descu = (parseFloat ((document.getElementById(porde).value)* subtot)/100);
var iva = (parseFloat((document.getElementById(poriv).value)* subtot)/100);
var subtt= (subtot-descu)+iva;
//Creo variable con el nombre del subtotal y name[1] que contiene el $row['+[a-z_]+']
var subname = 'total_'+subt[1];
var subname1 = 'descu_'+de[1];
var subname2 = 'iva_'+iv[1];
var subname3 = 'supertotal_'+sbt[1];
//Asigno el valor subtot al cuadro de texto Subtotal del producto correspondiente
document.getElementById(subname).value=subtot;
document.getElementById(subname1).value=descu;
document.getElementById(subname2).value=iva;
document.getElementById(subname3).value=subtt;
//Total = parseInt(document.getElementById('Total').value) + subtot;
//document.getElementById('Total').value = Total;
}
</script>
<script language="JavaScript"> 
function pregunta(){ 
var chk=0; 
for(i=0; ele=document.frm1.elements['i']; i++){ 
	if (ele.type=="checkbox") 
		if (ele.checked){chk=1;break;}
} 

if (chk==1){
	if (document.frm1.cbc.value.length==0){  //valida campo de cambios)
   		if (confirm('SE ENVIARA A LA FACTURA SIN GUARDAR CAMBIOS!!!!')){ 
			document.frm1.submit(sendFormNAS('frm1','AL107012_ACO.php?pas=<?php
 echo $regis['folio_control']; ?>&tnum=<?php
 echo $_POST['tnum']; ?>','_self')) 
    	}
	}else {
		document.frm1.submit(sendFormNAS('frm1','AL107012_ACO.php?pas=<?php
 echo $regis['folio_control']; ?>&tnum=<?php
 echo $_POST['tnum']; ?>','_self')) 
	}
}else{ 
	alert('DEBE SELECCIONAR LOS ARTICULOS!!');
	return;
} 


} 

	function todos(va) {
  		frm = document.forms['frm1'];
  		for(i=0; ele=frm.elements['i']; i++){
			var Type = ele.type;
			if(Type=="checkbox" && va.checked == true){
				ele.checked = true;
			}else if(Type=="checkbox" && va.checked == false){
				ele.checked = false;
			}
		}
	}
</script>


</head>
<body>
<div align="center">
<table width="898" height="43" border="0">
    <tr>
      <td colspan="3" nowrap><label>
        
      </label>
        <span style="display:block">
        <input name="boton2" type="button" class="tragre" onClick="pregunta()" value="TERMINAR FACTURA">
      </span></td>
      <td width="121" nowrap><span style="display:block">
	   <input name="boton_car2" type="submit" class="tragre" onClick="sendFormNAS('frm1','AL10701_MO.php?pas=<?php
 echo $regis['folio_control']; ?>&tnum=<?php
 echo $_POST['tnum']; ?>&cbc=1','_self')" value="GUARDAR CAMBIOS"><input name="cbc" type="hidden" value="<?php
 echo $_GET["cbc"];?>">
      </span></td>
      <td width="80" nowrap>&nbsp;</td>
      <td width="79" nowrap>&nbsp;</td>
      <td width="68" nowrap>&nbsp;</td>
      <td colspan="2" nowrap>&nbsp;</td>
      <th colspan="4" nowrap><span class="Estilo17">TIPO DE COMPRA.</span>
        <select name="select2" id="select2">
          <?php

		@$resultado=mysqli_query($con ,"select * from dgalmacen");
		while($registro=mysqli_fetch_array($resultado))
		{
			if(($registro['almacen']==$_POST['ver3'] or $registro['almacen']==$_POST['select2']) or (isset($_REQUEST['Submit3']) and $registro['almacen'] == $regyy['almacen'])){
				echo '<option value="' . $registro['almacen'] . '" selected>' . $registro['desc_almacen'].'</option>';
			}else{
				echo '<option value="' . $registro['almacen'] . '">' . $registro['desc_almacen'].'</option>';
			}
		}		
		
	?>
        </select></th>
    </tr>
  
  <tr>
    <th colspan="13" scope="col">ORDEN DE COMPRA No. <?php
 echo str_pad($regis['folio_control'],5,'0',STR_PAD_LEFT);?> </th>
  </tr>
  <tr>
    <th width="80" scope="col">  </th>
    <th width="21" scope="col"><input type='checkbox' name='checkbox' onClick="todos(this)"></th>
    <th width="42" scope="col">CLAVE</th>
    <th scope="col">DESCRIPCION</th>
    <th scope="col">CANTIDAD</th>
    <th scope="col">PRECIO</th>
    <th scope="col">IMPORTE</th>
    <th colspan="2" scope="col">DESCUENTO</th>
    <th colspan="2" scope="col">IVA</th>
    <th width="64" scope="col">TOTAL</th>
    <th width="83" scope="col">&nbsp;</th>
  </tr>
  <?php

	$sql2=mysqli_query($con ,"SELECT * FROM frecomart where codfre=$regis['folio_control'] order by nparte1 asc");
	$cont=mysqli_num_rows($sql2);
	$i=0;
while($row2 = mysqli_fetch_array($sql2)){
if ($row2['facturado']==0){
++$i;
?>
  <div align="center">
    <tr align="center">
      <td align="right"><div align="center"><input name="boton" type="submit" class="botonmen" onClick="sendFormNAS('frm1','AL10701_EL.php?pas=<?php
 echo $regis['folio_control']; ?>&tnum=<?php
 echo $_POST['tnum']; ?>&contr=<?php
 echo $regis['folio_control'];?>&elm=<?php
 echo $row2['codart'];?>','_self')" value="ELIMINAR">
	   </div></td>
      <input name='txtnot' type='hidden'  id='txtnot' value=" <?php
 echo $regis['folio_control']; ?>" />      <td align="right"><div align="center">
        <input name="todos[]" id="todos[]" value="<?php
 echo $row2['codart'];?>" type="checkbox" style=" width:15px;"/>
      </div></td>
      <td height="22"><div align="center"><?php
 echo number_format($row2['codart'],2,'.',',');?></div></td>
      <td><div align="center"><?php
 echo $row2['desc_art']; ?></div></td>
      <td><div align="center">  
	  <?php
 echo " <input name='art[]' type='hidden' value='".$row2['codart']."' > "; ?>
	  <?php
 echo " <input name='tcan[]' id='tcan_$i' type='text' size='5' onblur=subt('tpre_$i','tcan_$i','pordes_$i','poriva_$i') value='".number_format($row2['cant'],2,'.',',')."' >"; ?> 
	  </div></td>
      <td> <div align="center">
	  <?php
 echo " <input name='tpre[]' id='tpre_$i' type='text' onblur=subt('tpre_$i','tcan_$i','pordes_$i','poriva_$i') size='5' value='".number_format($row2['precio'],2,'.',',')."' >";?>  
	  </div></td>
      <td align="right"><div align="center">
	  <?php
 echo "<input name='total[]' id='total_$i' type='text' size='5' readonly=''  value='".number_format($row2['subpre'],2,'.',',')."'>"; ?>
	  </div></td>
	  <td width="53"> <div align="center">
	<?php
 echo "  <input name='pordes[]' id='pordes_$i' type='text' onblur=subt('tpre_$i','tcan_$i','pordes_$i','poriva_$i') size='5' value='".number_format($row2['por_desc'],2,'.',',')."' >";?> 
	  </div></td>
      <td width="56"><?php
 echo " <input size='5' readonly='' name='descu[]' id='descu_$i' type='text' value='".number_format($row2['des'],2,'.',',')."' >";?></td>
      <td width="55" align="right"><div align="center">
	   <?php
 echo " <input name='poriva[]' id='poriva_$i'  type='text' onblur=subt('tpre_$i','tcan_$i','pordes_$i','poriva_$i') size='5' value='".number_format($row2['por_iva'],2,'.',',')."' > ";?>
      </div></td>
      <td width="42" align="right"><div align="center">
       <?php
 echo " <input size='5' readonly='' name='iva[]' id='iva_$i' type='text' value='".number_format($row2['iva'],2,'.',',')."' > ";?>
      </div></td>
      <td align="right"><div align="center"> 	  
	  <?php
 echo "<input name='supertotal[]' id='supertotal_$i' type='text' readonly='' size='5' value='".number_format($row2['subpre'],2,'.',',')."'> "; ?>
	  </div></td>
      <td align="right"><div align="center">
     
      </div></td>
    </tr>
  </div>
  <?php

} else {
?>
  <div align="center">
    <tr align="center">
      <td align="right"><div align="center"><input name="boton" type="submit" class="botonmen" onClick="sendFormNAS('frm1','AL107012_EL.php?pas=<?php
 echo $regis['folio_control']; ?>&tnum=<?php
 echo $_POST['tnum']; ?>&clav=<?php
 echo $row2['fol_fac'];?>&art=<?php
 echo $row2['codart'];?>','_self')" value="ELIMINAR">
	   </div></td>
      <input name='txtnot' type='hidden'  id='txtnot' value=" <?php
 echo $regis['folio_control']; ?>" />      <td align="right"><div align="center">
       </div></td>
      <td height="22"><div align="center"><?php
 echo number_format($row2['codart'],2,'.',',');?></div></td>
      <td><div align="center"><?php
 echo $row2['desc_art']; ?></div></td>
      <td><div align="center"><?php
 echo number_format($row2['cant'],2,'.',',');?></div></td>
      <td> <div align="center"><?php
 echo number_format($row2['precio'],2,'.',','); ?></div></td>
      <td align="right"><div align="center"><?php
 echo $row2['subpre'];  ?></div></td>
      <td colspan="2"> <div align="center"><?php
 echo number_format($row2['po_desc'],2,'.',',')."%"; ?></div></td>
      <td colspan="2" align="right"><div align="center"><?php
 echo number_format($row2['iva'],2,'.',','); ?></div></td>
      <td align="right"><div align="center"><?php
 echo number_format($row2['total'],2,'.',','); ?></div></td>
      <td align="right"><div align="center">
        </div></td>
    </tr>
  </div>
  <?php
	
} }
?>
  <tr>
    <div id="total" style="display:block">
    <th colspan="13" scope="col" align="right"><div id="tot" align="right" style="display:block"></div></th>
    </div>
  </tr>
</table>
</div>
</body>
</html>
