<!DOCTYPE html>
<meta charset="utf-8">

<HTML>
<HEAD>
<TITLE>Editare Chitante</TITLE>

<link rel="stylesheet" type="text/css" href="A21_stiluri2.css">
<link rel="stylesheet" type="text/css" href="jquery-ui.css">

<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="jquery-ui.min.js"></script>

<script language="JavaScript" type="text/javascript">

var w12;
function target_popup12(form) {
		w12=window.open('', 'win12','width=1265,height=700,top=100,left=0,resizeable,scrollbars');
		form.target = 'win12';
}	

if (!document.all) 
{
	document.captureEvents (Event.CLICK);
}
document.onclick = function() 
{
	if (w12 != null && !w12.closed) 
	{
		w12.focus();
	}
}	

</script>

<script language="JavaScript">
	

$(document).ready(function() {
    $('#data_doc').each(function() {
        $(this).datepicker({ dateFormat: 'dd-mm-yy' });
    });
});

</script>

<script>
function validateForm() {
    var x = document.forms["formID"]["nr_doc"].value;
    if (x==null || x=="") 
	{
		alert("Campul 'Nr doc' nu a fost completat!");
        return false;
    }
	var y = document.forms["formID"]["data_doc"].value;
    if (y==null || y=="") 
	{
		alert("Campul 'Data doc' nu a fost completat!");
        return false;
    }
	var z = document.forms["formID"]["val_doc"].value;
    if (z==null || z=="") 
	{
		alert("Campul 'Suma' nu a fost completat!");
        return false;
    }
	var p = document.forms["formID"]["platitor"].value;
    if (p==null || p=="") 
	{
		alert("Campul 'Platitor' nu a fost completat!");
        return false;
    }
	
}
</script>

</HEAD>
<BODY bgcolor="#DCDCDC">
<CENTER>
	
	
<?php
include 'javascripts.php';
include 'conectare.php';

	echo "<BODY id=\"bg_plati\">";

		echo "<CENTER>";
		echo" </TABLE>";
		echo "<TABLE class=\"table2\" cellSpacing=0 cellPadding=0 width=\"98%\" border=0>";

			$connection=mysql_connect("$host","$username","$password") or die("Nu aveti acces la server");
			$baza="apponlin_".$_POST["aplic"]."_".$_POST["unit"];  
			$db=mysql_select_db($baza,$connection) or die("Nu puteti selecta Baza de date ".$baza);
 
			echo "<TR>";
			echo "<TD colspan=\"6\" align=\"left\" class=\"td_print2\">";
			echo "<B>PLATI</B>";
			echo "</TD>";
			echo "</TR>";
			echo "<TR>";
			echo "<TD colspan=\"6\" align=\"left\">";
			echo "<B>".$_POST["codcopil"]." - ";
			echo "&nbsp".trim($_POST["nume"])." ".trim($_POST["prenume"])."&nbsp</B>";
			echo "</TD>";
			echo "</TR>";
		
			echo "<FORM NAME=\"form1\" ACTION=\"A21_copii.php\" METHOD=\"POST\" TARGET=\"win01\">";
			include 'A21_param1.php';
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"PLA\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".$_POST["codcopil"]."\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"toate_grp\" VALUE=\"".$_POST["toate_grp"]."\">";
				if(isset($_POST["sel_codcopil"]))
				{
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_codcopil\" VALUE=\"".$_POST["sel_codcopil"]."\">";
				}
				if(isset($_POST["sel_copilul"]))
				{
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_copilul\" VALUE=\"".$_POST["sel_copilul"]."\">";
				}
				
			echo "<TR>";
			echo "<TD colspan=\"35\" height=\"35\" align=\"right\">";
			echo "<INPUT TYPE=\"SUBMIT\" id=\"button11\" NAME=\"actiune\" VALUE=\"INAPOI\" onMouseUp=\"javascript:setTimeout('window.close()',300);\">";
			echo "</TD>";
			echo "</TR>";
			echo "</form>";

			echo "<FORM id=\"formID\" ACTION=\"A21_editare_chit.php\" METHOD=\"POST\"  TARGHET=\"win10\">";
			include 'A21_param1.php';
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"PLA\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".$_POST["codcopil"]."\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nume\" VALUE=\"".$_POST["nume"]."\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"prenume\" VALUE=\"".$_POST["prenume"]."\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"toate_grp\" VALUE=\"".$_POST["toate_grp"]."\">";
			
				if(isset($_POST["sel_codcopil"]))
				{
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_codgos\" VALUE=\"".$_POST["sel_codcopil"]."\">";
				}
				if(isset($_POST["sel_copilul"]))
				{
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"sel_gospodar\" VALUE=\"".$_POST["sel_copilul"]."\">";
				}
			
	if($_POST["actiune"]==="ADAUG")
	{
		$query="SELECT cha FROM unitate";
		$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());		
		while ($row = mysql_fetch_array( $result))
		{	
			if ($row["cha"] === '1')
			{
				echo "<TD colspan=\"35\" height=\"35\" align=\"left\">";
				echo "<INPUT TYPE=\"SUBMIT\" name=\"actiune\" id=\"button13\" VALUE=\"CHITANTE AUTOMATE\">";
				echo "</TD>";
			}
		}			
		
		echo "<TR>";
		echo "<td colspan=\"1\">";
		echo "</td>";
		echo "<td colspan=\"1\" width=\"5%\" align=\"center\">";
		echo "<select onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" name=\"tip_doc\">";
		echo "<option SELECTED value=\"CH\">CH</option>";
		echo "<option value=\"OP\">OP</option>";
		echo "</td>";
		echo "<td colspan=\"1\" width=\"10%\" align=\"center\">";
		echo "<input name=\"nr_doc\" type=\"text\" style=\"text-align:center;\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey1(event)\" id=\"nr_doc\" size=\"10\" VALUE=\"\">";
		echo "</td>";
		echo "<td colspan=\"1\" width=\"10%\" align=\"center\">";
		echo "<input name=\"data_doc\" type=\"text\" style=\"text-align:center;\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" id=\"data_doc\" size=\"10\" VALUE=\"\">";
		echo "</td>";
		echo "<td colspan=\"1\" width=\"5%\" align=\"center\">";
		echo "<input name=\"val_doc\" type=\"text\" style=\"text-align:center;\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" id=\"val_doc\" size=\"5\" onkeypress=\"return isNumberKey1(event)\" VALUE=\"\">";
		echo "</td>";
		
		$query1="SELECT * FROM copii where codcopil=\"".$_POST["codcopil"]."\"";
		$result1=mysql_query($query1) or die("Interogare esuata: ".mysql_error());
		$row1 = mysql_fetch_array( $result1);		

		echo "<td colspan=\"1\" width=\"35%\"  align=\"center\">";
		echo "<select onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" name=\"platitor\" id=\"platitor\">";
		echo "<option SELECTED value=\"".$row1["parinte1"]."\">".$row1["parinte1"]."</option>";
	
		IF (!EMPTY($row1["parinte2"]) OR $row1["parinte2"] <> NULL)
		{
			echo "<option value=\"".$row1["parinte2"]."\">".$row1["parinte2"]."</option>";
		}
		IF (!EMPTY($row1["parinte3"]) OR $row1["parinte3"] <> NULL)
		{
			echo "<option value=\"".$row1["parinte3"]."\">".$row1["parinte3"]."</option>";
		}
		echo "</selected>";
		echo "</td>";
		echo "<td colspan=\"1\" width=\"35%\" align=\"center\">";
		echo "<input name=\"reprezentand\" type=\"text\" style=\"text-align:left;\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" id=\"reprezentand\" size=\"30\" VALUE=\"\">";
		echo "</td>";
		
		echo "<TD colspan=\"35\" height=\"35\" align=\"right\">";
		echo "<INPUT DISABLED TYPE=\"SUBMIT\" name=\"actiune\" id=\"button11\" VALUE=\"ADAUG\">";
		echo "</TD>";
		echo "</TR>";

		echo "<tr>";
		echo "<td colspan=\"7\" align=\"right\">";
		echo "<input type=\"submit\" name=\"actiune\" id=\"button11\" onClick=\"return validateForm()\" value=\"CONFIRM\">";
		echo "<input type=\"submit\" name=\"actiune\" id=\"button11\" value=\"RENUNT\">";
		echo "</TD>";
		echo "</TR>";
		echo "<TR>";
		echo "<TD>";
		echo "&nbsp";
		echo "</TD>";
		echo "</TR>";
	}

	elseif($_POST["actiune"]==="CHITANTE AUTOMATE")
	{			
		$query="SELECT * FROM users.login WHERE nume=\"".$_POST["nume_log"]."\" and prenume=\"".$_POST["prenume_log"]."\" and aplic=\"".$_POST["aplic"]."\"";
		$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());	
		while($row = mysql_fetch_array( $result )) 
		{
			$serie_chit = $row["serie_chit"];
		}	

			$query1="SELECT * FROM chitante where tip_doc='CHA' and substr(serie_doc,1,3)=\"".$serie_chit."\" order by nr_doc DESC LIMIT 1";
			$result1=mysql_query($query1) or die("Interogare esuata: ".mysql_error());		
			
		$i=0;		
		$wnr_doc=0;
		$wdata_doc=0;
		if(mysql_num_rows($result1) === 0) 
		{
			$query2="SELECT * FROM users.login WHERE nume=\"".$_POST["nume_log"]."\" and prenume=\"".$_POST["prenume_log"]."\" and aplic=\"".$_POST["aplic"]."\"";
			$result2=mysql_query($query2) or die("Interogare esuata: ".mysql_error());
			
			while($row2 = mysql_fetch_array( $result2 )) 
			{ 
				$wdengrp_sel=substr($_POST["grp_sel"],3,strlen($_POST["grp_sel"])-3);
				$wnr_doc="".$row2["serie_chit"]."_".$row2["nr_chit"]."";	
				$wdata_doc=date('d-m-Y');
			}			
		}
		else
		{
			while($row1 = mysql_fetch_array( $result1 )) 
			{ 	
				$wdata_doc=date('d-m-Y');				
				$serie = $row1["serie_doc"];
				$nr = $row1["nr_doc"] + 1;
				$wnr_doc = $serie."_".$nr;
			}				
		}
			echo "<TR>";
			echo "<td colspan=\"1\" width=\"5%\">";
			echo "</td>";
			echo "<td colspan=\"1\" width=\"5%\" align=\"center\">";
			echo "<B>CHA</B>";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_doc\" value=\"CHA\">";	
			echo "</td>";
			echo "<td colspan=\"1\" width=\"10%\" align=\"center\">";
			echo "<B>".$wnr_doc."</B>";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nr_doc\" VALUE=\"".$wnr_doc."\">";	
			echo "</td>";
			echo "<td colspan=\"1\" width=\"10%\" align=\"center\">";
			echo "<B>".$wdata_doc."</B>";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"data_doc\" VALUE=\"".$wdata_doc."\">";	
			echo "</td>";
			echo "<td colspan=\"1\" width=\"5%\" align=\"right\">";
			echo "<input name=\"val_doc\" type=\"text\" style=\"text-align:center;\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" id=\"val_doc\" size=\"5\" onkeypress=\"return isNumberKey1(event)\" VALUE=\"\">";
			echo "</td>";	
			
			$query1="SELECT * FROM copii where codcopil=\"".$_POST["codcopil"]."\"";
			$result1=mysql_query($query1) or die("Interogare esuata: ".mysql_error());
			$row1 = mysql_fetch_array( $result1);		

			echo "<td colspan=\"1\" width=\"35%\" align=\"center\">";
			echo "<select onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" name=\"platitor\" id=\"platitor\">";
			echo "<option SELECTED value=\"".$row1["parinte1"]."\">".$row1["parinte1"]."</option>";
		
			IF (!EMPTY($row1["parinte2"]) OR $row1["parinte2"] <> NULL)
			{
				echo "<option value=\"".$row1["parinte2"]."\">".$row1["parinte2"]."</option>";
			}
			IF (!EMPTY($row1["parinte3"]) OR $row1["parinte3"] <> NULL)
			{
				echo "<option value=\"".$row1["parinte3"]."\">".$row1["parinte3"]."</option>";
			}
			echo "</selected>";
			echo "</td>";			
			echo "<td colspan=\"1\" width=\"35%\" align=\"center\">";
			echo "<input name=\"reprezentand\" type=\"text\" style=\"text-align:left;\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" id=\"reprezentand\" size=\"30\" VALUE=\"\">";
			echo "</td>";
			
			echo "<TD colspan=\"35\" height=\"35\" align=\"right\">";
			echo "<INPUT DISABLED TYPE=\"SUBMIT\" name=\"actiune\" id=\"button11\" VALUE=\"ADAUG\">";
			echo "</TD>";
			echo "</tr>";
			echo "<tr>";
			echo "<td colspan=\"7\" align=\"right\">";
			echo "<input type=\"submit\" name=\"actiune\" id=\"button11\" onClick=\"return validateForm()\" value=\"CONFIRM\">";
			echo "<input type=\"submit\" name=\"actiune\" id=\"button11\" value=\"RENUNT\">";
			echo "</TD>";
			echo "</TR>";
			echo "<TR>";
			echo "<TD>";
			echo "&nbsp";
			echo "</TD>";
			echo "</TR>";	
	}
	else
	{
		if(substr($_POST["actiune"],0,1)==="<")
		{
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"chitanta\" VALUE=\"".$_POST["actiune"]."\">";
			
			$wid_ch=substr($_POST["actiune"],1,strpos($_POST["actiune"],'>',1)-1);
			$query3="SELECT * FROM chitante WHERE id=".$wid_ch." order by data_doc,nr_doc";
			$result3=mysql_query($query3) or die("Interogare esuata: ".mysql_error());
			$row3=mysql_fetch_array($result3);
			
			$data_doc = date("d-m-Y", strtotime($row3["data_doc"]));
			
			echo "<TR>";
			echo "<td colspan=\"1\" align=\"center\">";
			echo "<B>".$_POST["actiune"]."</B>";
			echo "</td>";
			if ($row3["tip_doc"] === "CH" or $row3["tip_doc"] === "OP")
			{			
				echo "<td colspan=\"1\" width=\"5%\" align=\"center\">";
				echo "<select onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" name=\"tip_doc\">";
				if($row3["tip_doc"]==="CH")
				{
					echo "<option SELECTED value=\"CH\">CH</option>";
					echo "<option value=\"OP\">OP</option>";			
				}
				else
				{
					echo "<option value=\"CH\">CH</option>";
					echo "<option SELECTED value=\"OP\">OP</option>";					
				}
			
				echo "</td>";
				echo "</select>";
				echo "<td colspan=\"1\" width=\"10%\" align=\"right\">";
				echo "<input name=\"nr_doc\" type=\"text\" style=\"text-align:center;\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" onkeypress=\"return isNumberKey1(event)\" id=\"nr_doc\" size=\"10\" VALUE=\"".$row3["nr_doc"]."\">";
				echo "</td>";
				echo "<td colspan=\"1\" width=\"10%\" align=\"center\">";
				echo "<input name=\"data_doc\" type=\"text\" style=\"text-align:center;\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" id=\"data_doc\" size=\"10\" VALUE=".$data_doc.">";
				echo "</td>";
				echo "<td colspan=\"1\" width=\"5%\" align=\"right\">";
				echo "<input name=\"val_doc\" type=\"text\" style=\"text-align:center;\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" id=\"val_doc\" size=\"5\" onkeypress=\"return isNumberKey1(event)\" VALUE=\"".$row3["val_doc"]."\">";
				echo "</td>";
				
				$query1="SELECT * FROM copii where codcopil=\"".$_POST["codcopil"]."\" ";
				$result1=mysql_query($query1) or die("Interogare esuata: ".mysql_error());
				$row1 = mysql_fetch_array( $result1);		
				
				echo "<td colspan=\"1\" width=\"35%\" align=\"center\">";
				echo "<select onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" name=\"platitor\" id=\"platitor\">";
				echo "<option SELECTED value=\"".$row3["platitor"]."\">".$row3["platitor"]."</option>";
			
				IF ((!EMPTY($row1["parinte1"]) OR $row1["parinte1"] <> NULL) AND ($row1["parinte1"] <> $row3["platitor"]))
				{
					echo "<option value=\"".$row1["parinte1"]."\">".$row1["parinte1"]."</option>";
				}
				IF ((!EMPTY($row1["parinte2"]) OR $row1["parinte2"] <> NULL) AND ($row1["parinte2"] <> $row3["platitor"]))
				{
					echo "<option value=\"".$row1["parinte2"]."\">".$row1["parinte2"]."</option>";
				}
				IF ((!EMPTY($row1["parinte3"]) OR $row1["parinte3"] <> NULL) AND ($row1["parinte3"] <> $row3["platitor"]))
				{
					echo "<option value=\"".$row1["parinte3"]."\">".$row1["parinte3"]."</option>";
				}
				echo "</selected>";
				echo "</td>";			
				echo "<td colspan=\"1\" width=\"35%\" align=\"center\">";
				echo "<input name=\"reprezentand\" type=\"text\" style=\"text-align:left;\" onfocus=\"onfocus_camp(this)\" onblur=\"onblur_text(this)\" id=\"reprezentand\" size=\"30\"  VALUE=\"".$row3["reprezentand"]."\">";
				echo "</td>";				
			}	
			else
			{
				echo "<td colspan=\"1\" width=\"5%\" align=\"center\">";
				echo "<B>".$row3["tip_doc"]."</B>";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_doc\" VALUE=\"".$row3["tip_doc"]."\">";	
				echo "<td colspan=\"1\" width=\"10%\" align=\"center\">";
				echo "<B>".$row3["serie_doc"]."_".$row3["nr_doc"]."</B>";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nr_doc\" VALUE=\"".$row3["serie_doc"]."_".$row3["nr_doc"]."\">";					
				echo "</td>";
				echo "<td colspan=\"1\" width=\"10%\" align=\"center\">";
				echo "<B>".$data_doc."</B>";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"data_doc\" VALUE=".$data_doc.">";	
				echo "</td>";
				echo "<td colspan=\"1\" width=\"5%\" align=\"center\">";
				echo "<B>".$row3["val_doc"]."</B>";
				echo "</td>";
				echo "<td colspan=\"1\" width=\"35%\" align=\"left\">";
				echo "<B>".$row3["platitor"]."</B>";
				echo "</td>";
				echo "<td colspan=\"1\" width=\"35%\" align=\"left\">";
				echo "<B>".$row3["reprezentand"]."</B>";
				echo "</td>";	
			}	
			echo "<TD colspan=\"35\" height=\"35\" align=\"right\">";
			echo "<INPUT DISABLED TYPE=\"SUBMIT\" name=\"actiune\" id=\"button11\" VALUE=\"ADAUG\">";
			echo "</TD>";
			echo "</tr>";	
			echo "<tr>";
			echo "<td colspan=\"7\" align=\"right\">";
			
			if($row3["tip_doc"]<>"CHA")
			{
				echo "<input type=\"submit\" name=\"actiune\" id=\"button11\" onClick=\"return validateForm()\" value=\"MODIFIC\">";
				echo "<input type=\"submit\" name=\"actiune\" id=\"button11\" value=\"STERG\" onClick=\"return confirm('Doriti sa stergeti?');\">";
			}
			else
			{
				echo "<input type=\"submit\" name=\"actiune\" id=\"button11\" value=\"ANULEZ\" onClick=\"return confirm('Doriti sa anulati?');\">";
			}	
			echo "<input type=\"submit\" name=\"actiune\" id=\"button11\" value=\"RENUNT\">";
			echo "</TR>";
			echo "<TR>";
			echo "<TD>";
			echo "&nbsp";
			echo "</TD>";
			echo "</TR>";
		}
		else
		{
			if ($_POST["actiune"]=="CONFIRM")
			{
				$wln=date("m",strtotime($_POST["data_doc"]));
				$wdata_doc=date("Y-m-d",strtotime($_POST["data_doc"]));
				if($_POST["tip_doc"]=="CHA")
				{
					$wserie_doc=substr($_POST["nr_doc"],0,3);
					$wnr_doc=substr($_POST["nr_doc"],4,strlen($_POST["nr_doc"]));
					$wplatitor=$_POST["platitor"];
					$wreprezentand=$_POST["reprezentand"];
				}
				else
				{
					$wserie_doc="";
					$wnr_doc=$_POST["nr_doc"];
					$wplatitor=$_POST["platitor"];
					$wreprezentand=$_POST["reprezentand"];
				}
				
				$query3="INSERT INTO chitante (codgrp,codcopil,tip_doc,serie_doc,nr_doc,ln,data_doc,val_doc,platitor,reprezentand) ";
				$query3=$query3."VALUES (\"".$_POST["grp_sel"]."\",\"".$_POST["codcopil"]."\",\"".$_POST["tip_doc"]."\",";
				$query3=$query3."\"".$wserie_doc."\",\"".$wnr_doc."\",\"".$wln."\",\"".$wdata_doc."\",\"".$_POST["val_doc"]."\",\"".$wplatitor."\",\"".$wreprezentand."\")";
				$result3=mysql_query($query3) or die("Interogare esuata: ".mysql_error());

			}

			if ($_POST["actiune"]==="MODIFIC")
			{
				if($_POST["tip_doc"]==="CHA")
				{
					$wserie_doc=substr($_POST["nr_doc"],0,3);
					$wnr_doc=substr($_POST["nr_doc"],4,strlen($_POST["nr_doc"]));
					//$wplatitor=$_POST["platitor"];
				}
				else
				{
					$wserie_doc="";
					$wnr_doc=$_POST["nr_doc"];
					$wplatitor=$_POST["platitor"];
					$wreprezentand=$_POST["reprezentand"];
				}
			
				$wln=date("m",strtotime($_POST["data_doc"]));
				$wdata_doc=date("Y-m-d",strtotime($_POST["data_doc"]));
				$wid_chit=substr($_POST["chitanta"],1,strpos($_POST["chitanta"],'>',1)-1);
				
				$query3="UPDATE chitante set tip_doc=\"".$_POST["tip_doc"]."\",serie_doc=\"".$wserie_doc."\",";
				//$query3=$query3."nr_doc=\"".substr($_POST["nr_doc"],4,strlen($_POST["nr_doc"]))."\",ln=\"".$wln."\",";
				$query3=$query3."nr_doc=\"".$wnr_doc."\",ln=\"".$wln."\",";
				$query3=$query3."data_doc=\"".$wdata_doc."\",val_doc=\"".$_POST["val_doc"]."\",platitor=\"".$wplatitor."\",reprezentand=\"".$wreprezentand."\"";
				$query3=$query3."WHERE id=".$wid_chit;
				$result3=mysql_query($query3) or die("Interogare esuata: ".mysql_error());
			}

			if ($_POST["actiune"]==="STERG")
			{
				$wid_chit=substr($_POST["chitanta"],1,strpos($_POST["chitanta"],'>',1)-1);
				$query3="DELETE from chitante WHERE id=".$wid_chit;
				$result3=mysql_query($query3) or die("Interogare esuata: ".mysql_error());
			}
			
			if ($_POST["actiune"]==="ANULEZ")
			{
				$wid_chit=substr($_POST["chitanta"],1,strpos($_POST["chitanta"],'>',1)-1);
				$query3="UPDATE chitante set anulat='X' WHERE id=".$wid_chit;
				$result3=mysql_query($query3) or die("Interogare esuata: ".mysql_error());
			}

			if ($_POST["actiune"]==="CONFIRM" or $_POST["actiune"]==="MODIFIC" or $_POST["actiune"]==="STERG" or $_POST["actiune"]==="ANULEZ")
			{
				$query0="SELECT * FROM copii WHERE codcopil=\"".$_POST["codcopil"]."\"";
				$result0=mysql_query($query0) or die("Interogare esuata: ".mysql_error());
				$row0 = mysql_fetch_array( $result0);
							
				$wp_val01=0;
				$wp_val02=0;
				$wp_val03=0;
				$wp_val04=0;
				$wp_val05=0;
				$wp_val06=0;
				$wp_val07=0;
				$wp_val08=0;
				$wp_val09=0;
				$wp_val10=0;
				$wp_val11=0;
				$wp_val12=0;
				
				
				$wr_val09=$row0["d_val00"]+$row0["d_val09"];
				$wr_val10=$row0["d_val00"]+$row0["d_val09"]+$row0["d_val10"];
				$wr_val11=$row0["d_val00"]+$row0["d_val09"]+$row0["d_val10"]+$row0["d_val11"];
				$wr_val12=$row0["d_val00"]+$row0["d_val09"]+$row0["d_val10"]+$row0["d_val11"]+$row0["d_val12"];
				$wr_val01=$row0["d_val00"]+$row0["d_val09"]+$row0["d_val10"]+$row0["d_val11"]+$row0["d_val12"]+$row0["d_val01"];
				$wr_val02=$row0["d_val00"]+$row0["d_val09"]+$row0["d_val10"]+$row0["d_val11"]+$row0["d_val12"]+$row0["d_val01"]+$row0["d_val02"];
				$wr_val03=$row0["d_val00"]+$row0["d_val09"]+$row0["d_val10"]+$row0["d_val11"]+$row0["d_val12"]+$row0["d_val01"]+$row0["d_val02"]+$row0["d_val03"];
				$wr_val04=$row0["d_val00"]+$row0["d_val09"]+$row0["d_val10"]+$row0["d_val11"]+$row0["d_val12"]+$row0["d_val01"]+$row0["d_val02"]+$row0["d_val03"]+$row0["d_val04"];
				$wr_val05=$row0["d_val00"]+$row0["d_val09"]+$row0["d_val10"]+$row0["d_val11"]+$row0["d_val12"]+$row0["d_val01"]+$row0["d_val02"]+$row0["d_val03"]+$row0["d_val04"]+$row0["d_val05"];
				$wr_val06=$row0["d_val00"]+$row0["d_val09"]+$row0["d_val10"]+$row0["d_val11"]+$row0["d_val12"]+$row0["d_val01"]+$row0["d_val02"]+$row0["d_val03"]+$row0["d_val04"]+$row0["d_val05"]+$row0["d_val06"];
				$wr_val07=$row0["d_val00"]+$row0["d_val09"]+$row0["d_val10"]+$row0["d_val11"]+$row0["d_val12"]+$row0["d_val01"]+$row0["d_val02"]+$row0["d_val03"]+$row0["d_val04"]+$row0["d_val05"]+$row0["d_val06"]+$row0["d_val07"];
				$wr_val08=$row0["d_val00"]+$row0["d_val09"]+$row0["d_val10"]+$row0["d_val11"]+$row0["d_val12"]+$row0["d_val01"]+$row0["d_val02"]+$row0["d_val03"]+$row0["d_val04"]+$row0["d_val05"]+$row0["d_val06"]+$row0["d_val07"]+$row0["d_val08"];
				
				$query="SELECT * FROM chitante WHERE codcopil=\"".$_POST["codcopil"]."\" and anulat IS NULL order by data_doc,nr_doc";
				$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());
				while ($row = mysql_fetch_array( $result))
				{
					$wln=date("m",strtotime($row["data_doc"]));
					if ($wln==="01")
					{
						$wp_val01=$wp_val01+$row["val_doc"];
					}
					if ($wln==="02")
					{
						$wp_val02=$wp_val02+$row["val_doc"];
					}
					if ($wln==="03")
					{
						$wp_val03=$wp_val03+$row["val_doc"];
					}
					if ($wln==="04")
					{
						$wp_val04=$wp_val04+$row["val_doc"];
					}
					if ($wln==="05")
					{
						$wp_val05=$wp_val05+$row["val_doc"];
					}
					if ($wln==="06")
					{
						$wp_val06=$wp_val06+$row["val_doc"];
					}
					if ($wln==="07")
					{
						$wp_val07=$wp_val07+$row["val_doc"];
					}
					if ($wln==="08")
					{
						$wp_val08=$wp_val08+$row["val_doc"];
					}
					if ($wln==="09")
					{
						$wp_val09=$wp_val09+$row["val_doc"];
					}
					if ($wln==="10")
					{
						$wp_val10=$wp_val10+$row["val_doc"];
					}
					if ($wln==="11")
					{
						$wp_val11=$wp_val11+$row["val_doc"];
					}
					if ($wln==="12")
					{
						$wp_val12=$wp_val12+$row["val_doc"];
					}
				}
				$wr_val09=$wr_val09-$wp_val09;
				$wr_val10=$wr_val10-($wp_val09+$wp_val10);
				$wr_val11=$wr_val11-($wp_val09+$wp_val10+$wp_val11);
				$wr_val12=$wr_val12-($wp_val09+$wp_val10+$wp_val11+$wp_val12);
				$wr_val01=$wr_val01-($wp_val09+$wp_val10+$wp_val11+$wp_val12+$wp_val01);
				$wr_val02=$wr_val02-($wp_val09+$wp_val10+$wp_val11+$wp_val12+$wp_val01+$wp_val02);
				$wr_val03=$wr_val03-($wp_val09+$wp_val10+$wp_val11+$wp_val12+$wp_val01+$wp_val02+$wp_val03);
				$wr_val04=$wr_val04-($wp_val09+$wp_val10+$wp_val11+$wp_val12+$wp_val01+$wp_val02+$wp_val03+$wp_val04);
				$wr_val05=$wr_val05-($wp_val09+$wp_val10+$wp_val11+$wp_val12+$wp_val01+$wp_val02+$wp_val03+$wp_val04+$wp_val05);
				$wr_val06=$wr_val06-($wp_val09+$wp_val10+$wp_val11+$wp_val12+$wp_val01+$wp_val02+$wp_val03+$wp_val04+$wp_val05+$wp_val06);
				$wr_val07=$wr_val07-($wp_val09+$wp_val10+$wp_val11+$wp_val12+$wp_val01+$wp_val02+$wp_val03+$wp_val04+$wp_val05+$wp_val06+$wp_val07);
				$wr_val08=$wr_val08-($wp_val09+$wp_val10+$wp_val11+$wp_val12+$wp_val01+$wp_val02+$wp_val03+$wp_val04+$wp_val05+$wp_val06+$wp_val07+$wp_val08);
				
				$query4="UPDATE copii SET p_val01=\"".$wp_val01."\", p_val02=\"".$wp_val02."\", p_val03=\"".$wp_val03."\", ";
				$query4=$query4." p_val04=\"".$wp_val04."\", p_val05=\"".$wp_val05."\", p_val06=\"".$wp_val06."\", p_val07=\"".$wp_val07."\",";
				$query4=$query4." p_val08=\"".$wp_val08."\", p_val09=\"".$wp_val09."\", p_val10=\"".$wp_val10."\", p_val11=\"".$wp_val11."\", p_val12=\"".$wp_val12."\",";
				$query4=$query4." r_val01=\"".$wr_val01."\", r_val02=\"".$wr_val02."\", r_val03=\"".$wr_val03."\", r_val04=\"".$wr_val04."\", r_val05=\"".$wr_val05."\",";
				$query4=$query4." r_val06=\"".$wr_val06."\", r_val07=\"".$wr_val07."\", r_val08=\"".$wr_val08."\", r_val09=\"".$wr_val09."\", r_val10=\"".$wr_val10."\",";
				$query4=$query4." r_val11=\"".$wr_val11."\", r_val12=\"".$wr_val12."\" ";
				$query4=$query4."WHERE codcopil=\"".$_POST["codcopil"]."\"";
				$result=mysql_query($query4) or die("Interogare esuata: ".mysql_error());				
			}
			
			echo "<TD colspan=\"35\" height=\"35\" align=\"right\">";
			echo "<INPUT TYPE=\"SUBMIT\" name=\"actiune\" id=\"button11\" VALUE=\"ADAUG\">";
			echo "</TD>";
			echo "</TR>";
			
			echo "<TR>";
			echo "<TD>";
			echo "&nbsp";
			echo "</TD>";
			echo "</TR>";
		}
	}

		$query="SELECT * FROM chitante WHERE codcopil=\"".$_POST["codcopil"]."\" order by data_doc,nr_doc";
		$result=mysql_query($query) or die("Interogare esuata: ".mysql_error());

			echo "<TR BGCOLOR=\"white\">";			
			echo    "<TH colspan=\"1\" align=\"center\" width=\"5%\" class=\"td35\">Nrc</TH>";
			echo	"<TH colspan=\"1\" align=\"center\" width=\"5%\" class=\"td35\">Tip</TH>";
			echo	"<TH colspan=\"1\" align=\"center\" width=\"10%\" class=\"td35\">Nr doc</TH>";
			echo	"<TH colspan=\"1\" align=\"center\" width=\"10%\" class=\"td35\">Data doc</TH>";
			echo	"<TH colspan=\"1\" align=\"center\" width=\"5%\" class=\"td35\">Suma</TH>";
			echo	"<TH colspan=\"1\" align=\"center\" width=\"35%\" class=\"td35\">Platitor</TH>";
			echo	"<TH colspan=\"1\" align=\"center\" width=\"35%\" class=\"td35\">Reprezentand</TH>";
			echo    "<TH colspan=\"1\" align=\"center\" width=\"10%\" class=\"td35\">Editare</TH>";		
			echo    "<TH colspan=\"1\" align=\"center\" width=\"10%\" class=\"td35\">Listare</TH>";
			echo    "<TH colspan=\"1\" align=\"center\" width=\"5%\" class=\"td39\">Anulat</TH>";	
			
			echo "</TR>";
		
			$platit_tot=0;
			$i=0;
			while ($row = mysql_fetch_array( $result))
			{						
				echo "<FORM id=\"formID\" ACTION=\"A21_editare_chit.php\" METHOD=\"POST\"  TARGET=\"win10\">";
				include 'A21_param1.php';
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"PLA\">";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".$_POST["codcopil"]."\">";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nume\" VALUE=\"".$_POST["nume"]."\">";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"prenume\" VALUE=\"".$_POST["prenume"]."\">";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"toate_grp\" VALUE=\"".$_POST["toate_grp"]."\">";
				
				$data_doc = date("d-m-Y", strtotime($row["data_doc"]));

				if ($row["anulat"] <> 'X')
				{				
					$platit_tot = $platit_tot+$row["val_doc"];
				}

				if ($i-floor($i/2)*2==0)
				{
					echo "<TR class=\"tr4\" BGCOLOR=\"#FFFFFF\">";
				}
				else
				{
					echo "<TR class=\"tr4\" BGCOLOR=\"#EAEBEB\">";
				}
		
				echo "<TD colspan=\"1\" width=\"5%\" align=\"center\">",$i+1,"</TD>";
				echo"<TD colspan=\"1\" width=\"5%\" align=\"center\">";
				echo "&nbsp".$row["tip_doc"]."&nbsp";
				echo "</TD>";
				echo"<TD colspan=\"1\" width=\"10%\" align=\"center\">";
				if($row["tip_doc"]==="CHA")
				{
					echo "&nbsp".$row["serie_doc"]."_".$row["nr_doc"]."&nbsp";
				}
				else
				{
					echo "&nbsp".$row["nr_doc"]."&nbsp";
				}
				echo "</TD>";
				echo"<TD colspan=\"1\" width=\"10%\" align=\"center\">";
				echo "&nbsp".$data_doc."&nbsp";
				echo "</TD>";
					
				if ($row["anulat"] === 'X')
				{
					echo"<TD colspan=\"1\" width=\"5%\" align=\"center\">";
					echo "0&nbsp(".$row["val_doc"].")&nbsp";
					echo "</TD>";
					echo"<TD colspan=\"1\" width=\"35%\" align=\"left\">";
					echo "&nbsp".$row["platitor"]."&nbsp";
					echo "</TD>";	
					echo"<TD colspan=\"1\" width=\"35%\" align=\"left\">";
					echo "&nbsp".$row["reprezentand"]."&nbsp";
					echo "</TD>";	
					echo "<td colspan=\"1\" width=\"10%\" align=\"center\">";
					echo "</TD>";
				}
				else
				{
					echo"<TD colspan=\"1\" width=\"5%\" align=\"center\">";
					echo "&nbsp".$row["val_doc"]."&nbsp";
					echo "</TD>";
					echo"<TD colspan=\"1\" width=\"35%\" align=\"left\">";
					echo "&nbsp".$row["platitor"]."&nbsp";
					echo "</TD>";	
					echo"<TD colspan=\"1\" width=\"35%\" align=\"left\">";
					echo "&nbsp".$row["reprezentand"]."&nbsp";
					echo "</TD>";						
					echo "<td colspan=\"1\" width=\"10%\" align=\"center\">";
					echo "<INPUT TYPE=\"SUBMIT\" NAME=\"actiune\" id=\"button11\" VALUE=\"<".$row["id"].">\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nume\" VALUE=\"".$_POST["nume"]."\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"prenume\" VALUE=\"".$_POST["prenume"]."\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"toate_grp\" VALUE=\"".$_POST["toate_grp"]."\">";
					echo "</TD>";
				}
				
				if ($row["tip_doc"] === "CHA" and $row["anulat"] <> 'X')
				{			
					echo "</FORM>";
					echo "<FORM id=\"formID\" ACTION=\"A21_listare_chit.php\" METHOD=\"POST\" onsubmit=\"target_popup12(this)\">";
					include 'A21_param1.php';
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"tip_act\" VALUE=\"PLA\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"codcopil\" VALUE=\"".$_POST["codcopil"]."\">";
				
					echo "<td colspan=\"1\" width=\"10%\" align=\"center\">";
					echo "<INPUT TYPE=\"SUBMIT\" NAME=\"actiune\" id=\"button11\" VALUE=\"-".$row["id"]."-\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nume\" VALUE=\"".$_POST["nume"]."\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"prenume\" VALUE=\"".$_POST["prenume"]."\">";
					echo "<INPUT TYPE=\"HIDDEN\" NAME=\"toate_grp\" VALUE=\"".$_POST["toate_grp"]."\">";
					echo "</TD>";
					echo "</FORM>";
				}
				else
				{
					echo "<td colspan=\"1\" width=\"10%\" align=\"center\">";
					echo "</TD>";
				}
				echo"<TD colspan=\"1\" width=\"5%\" align=\"center\">";
				echo "&nbsp".$row["anulat"]."&nbsp";
				echo "</TD>";
				$i++;
			}				
				echo "<TR>";
				echo "<TD>&nbsp</TD>";
				echo "</TR>";

				echo "<tr>";
			    echo "<td colspan=\"4\" align=\"right\">";
				echo "Total:";
				echo "</TD>";
			    echo "<td colspan=\"1\" align=\"center\">";
				echo $platit_tot;
				echo "</TD>";
				echo "</TR>";
				
				echo "<TR>";
				echo "<TD>&nbsp</TD>";
				echo "</TR>";

	echo "</FORM>";
	echo "</TABLE>";
	mysql_close($connection);
?>
</CENTER>
</BODY>
</HTML>