<html>

<head>
<style type="text/css">

element {
}

element1 {
}

</style>
</head>
</html><?php

//Plan dzialania - skrypt KSIEG_DOKUMENTY_ZASOB1182_SUBIEKT_MSSQL_IMPORT.php
// I - import z subiekta - koszty
//1. Import z SUBIEKTA do FAKTUR wszelkich faktur kosztowych -> ID_PROJECT
//
//2. Import z Subiekta do FAKTUR wszelkich wielkosci amortyzacji -> ID_PROJECT (inwestycje)
//3. Import z Subiekta do FAKTUR wszelkich wielkosci nakladow -> ID_PROJECT - (wielkosci nadane na konta 0-80)
// II - analiza sprzedazy
//1. Nalezy w SERVICES dac znacznik ID_PROJECT i powiazac jego nadawanie z identyfikacja typu zasobu mieszkaniowego
// III - do wdrozenia w "http://se.dev.webone.pl/budynki.php?ANALIZA_HISTORII_USERS2=1"
//(1). Nalezy importowac sprzedaz do analizy czynnikow w innych skryptach ( analiza )
//(2). Nalezy w systemach analizowac parametry wspolczynniki
//(3). HP-HC/ID_PROJECT ( Podlaczeni do Zasiegu sieci) - na podstawie telboxes--U2_marketing - TARGET HANDLOWY/
//(4). Naklady/HC (Naklady do ilosci abonentow) - TARGET INWESTYCJI
//(5). Naklady/Suma calkowitej sprzedazy  + suma aktualnych kontraktow (wartosci podpisane)/ID_PROJECT - TARGET HANDLOWY
//(6). Wydatki calego marketingu - Pracownicy, reklamy, (sprawy podlegle pod marketing) (minus) Cala wartosc nowej sprzedazy * wspolczynnik , jezeli wiecej niz 3000 PLN, to jest to premia dla dzialu marketingowego TARGET HANDLOWY




if ($_FILES["file1182"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file1182"]["error"] . "<br />";
  print_r($_FILES);
  }
else if(isset($_FILES["file1182"]["name"]))
  {
  echo "Upload: " . $_FILES["file1182"]["name"] . "<br />";
  echo "Type: " . $_FILES["file1182"]["type"] . "<br />";
  echo "Size: " . ($_FILES["file1182"]["size"] / 1024) . " Kb<br />";
  echo "Stored in: " . $_FILES["file1182"]["tmp_name"];


/*
		//$ourFileName = "testFile.txt";
		$fh = fopen($_FILES["file1182"]["tmp_name"], 'r') or die("Can't open file");
		$theData = fread($fh, filesize($_FILES["file1182"]["tmp_name"]));
		fclose($fh);
		echo "<br>the data is<br>\n";
		//echo $theData;
		echo "<br>the data was<br>\n";
		fclose($fh);
*/
		 $xml = simplexml_load_file($_FILES["file1182"]["tmp_name"]);

		 //tutaj kasujemy stare importy
		 if(isset($xml)) {
		 $ZAP_SQL="delete from KSIEG_DOKUMENTY
      where COALESCE(unix_timestamp(DATA_DOK), 0) > COALESCE(unix_timestamp('".$_REQUEST['START_ROK']."-".$_REQUEST['START_MIESIAC']."-".$_REQUEST['START_DZIEN']."'), 0)
        and COALESCE(unix_timestamp(DATA_DOK), 0) < COALESCE(unix_timestamp('".$_REQUEST['KONIEC_ROK']."-".$_REQUEST['KONIEC_MIESIAC']."-".$_REQUEST['KONIEC_DZIEN']."'), 0)
        and TYP_DOKUMENTU='IMPORT' ;
		 	";
		 	include(".config.php");
		//	ZAP_SQL('select 1+1');

		 	ZAP_SQL($ZAP_SQL);
		 	echo "<br>".$ZAP_SQL;

//			print_r($_SESSION);

		 }

echo "<pre>";
//	    var_dump($xml);
//	    print_r($xml->FormattedReport->FormattedAreaPair->FormattedAreaPair->FormattedArea);
//		foreach($xml->FormattedReport->FormattedAreaPair->FormattedAreaPair->FormattedArea as $A => $V ) {

 echo "<table border=1>";

 echo "<tr><td>Konto:</td><td>Opis Konta</td><td>BO Wn</td><td> BO Ma</td><td> Obroty Wn </td><td>Obroty Ma </td><td>Obroty NWn </td><td>Obroty NMa</td><td>
  Saldo Wn </td><td>Saldo Ma</td></tr>";


	foreach($xml->FormattedAreaPair->FormattedAreaPair as $A2 => $V2) {

//	    echo "<tr><td>A1:".$A1." </td></tr>\n";

		foreach($V2->FormattedArea->FormattedSections->FormattedSection->FormattedReportObjects->FormattedReportObject as $A => $V ) {
//		echo "###1 A:".$A." \n V: ".$V->ObjectName."\n";
//		echo "A:".$A." \n V: ".$V->FormattedValue."\n";
//		echo "A:".$A." \n V: ".$V->Value."\n";
		//print_r($V);
		$INDNAME=(string)$V->ObjectName;
		$KDI[$INDNAME]=$V->Value;
		}

	//	print_r($KD);
	echo "<tr><td>".$KDI['z1f1']."</td><td>".$KDI['Field2']."</td><td>".$KDI['Field3']."</td><td>".$KDI['Field4']."</td>
	<td>".$KDI['Field5']."</td><td>".$KDI['Field6']."</td><td>".$KDI['Field7']."</td><td>".$KDI['Field8']."</td><td>
  ".$KDI['Field9']."</td><td>".$KDI['Field10']."</td></tr>";

		unset($KD);
		foreach($V2->FormattedAreaPair as $A3 => $V3) {
			foreach($V3->FormattedArea->FormattedSections->FormattedSection->FormattedReportObjects->FormattedReportObject as $A => $V ) {
///			echo " ###2 A:".$A." \n V: ".$V->ObjectName."\n";
//			echo "A:".$A." \n V: ".$V->FormattedValue."\n";
///			echo " A:".$A." \n V: ".$V->Value."\n";
			//print_r($V);
			$INDNAME=(string)$V->ObjectName;
			$KD[$INDNAME]=$V->Value;

			}
			echo "<tr><td>".$KD['Field44']."</td><td>".$KD['Field45']."</td><td>".$KD['Field46']."</td><td>".$KD['Field47']."</td>
			<td>".$KD['Field48']."</td><td>".$KD['Field49']."</td><td>".$KD['Field50']."</td><td>"."</td><td>
		  "."</td><td>"."</td></tr>";
		//print_r($KD);

			if(($KD['Field44']<>'BO-1')||(!isset($_REQUEST['IGNORE_BO']))) {

						if(strlen($KD['Field46'])>strlen($KD['Field47'])) {
							//echo "<br>\n WINIEN";
								 $WINIEN_MA='WINIEN';
								$KWOTA=$KD['Field46'];
							} else {
								$WINIEN_MA='MA';
								$KWOTA=$KD['Field47'];
							}
				$ZAP_SQL="insert into KSIEG_DOKUMENTY (A_RECORD_CREATE_DATE,A_RECORD_CREATE_AUTHOR, DATA_DOK, NUMER_DOK , SPRZEDAWCA ,
						ID_SPRZEDAWCA , ILOSC , CENA_JEDN_NETTO , STAWKA_VAT , wartosc , CZY_URZADZENIE , TYP_DOKUMENTU, ID_PROJECT, 							ID_BUDZET,A_STATUS,KONTO_KSIEG , WINIEN_MA) values (
						now() , '".$_SESSION['AUTHORIZE_USER']."' ,
						'".$KD['Field45']."','".$KD['Field44']."--".$KD['Field48']."',
						'SPRZEDAWCA','ID_SPRZEDAWCA','1','".$KWOTA."','0','".$KWOTA."','NOT_DEVICE',
						'IMPORT','ID_PROJECT','ID_BUDZET','NORMAL','".$KDI['z1f1']."', '".$WINIEN_MA."')";
					//	echo "<br>\n".$ZAP_SQL;
				ZAP_SQL($ZAP_SQL);
				//die();
			}
		unset($KD);

		}



	}

//foreach($xml->FormattedAreaPair as $a=>$b) {
//    echo $a,'="',$b,"\"\n";
//}


echo "</pre>";

  }

//print_r($_FILES);

//phpinfo();


SEF('TRIM_ZERO');


if($_REQUEST['UPDATE_MAPA_DEKRETOW']) {

//	$ZAP_SQL="update KSIEG_DOKUMENTY set ID_BUDZET='39-INWESTYCJE' where
//		 and TYP_DOKUMENTU='IMPORT'  ";
    ZAP_SQL('select 1+1;');
	$ZAP_SQL="select * from KSIEG_DOKUMENTY where TYP_DOKUMENTU='IMPORT'
         and (	  KONTO_KSIEG like 'XXXX011-%' or
		  KONTO_KSIEG like '071-%' or
		  KONTO_KSIEG like '080-%' or
  		  KONTO_KSIEG like 'XXXX138-%' or
  		  KONTO_KSIEG like 'XXXX139-%' or
		  KONTO_KSIEG like '2%-%' or
		  KONTO_KSIEG like '310-%' or

		  KONTO_KSIEG like 'XXXX202-%' or
		  KONTO_KSIEG like 'XXXX220-%' or
		  KONTO_KSIEG like 'XXXX221-%' or
		  KONTO_KSIEG like 'XXXX230-%' or
		  KONTO_KSIEG like '750-%' or
		  KONTO_KSIEG like '751-%' or
		  KONTO_KSIEG like '761-%' or
		  KONTO_KSIEG like '703-%' or


		  KONTO_KSIEG like '4%-%'  )	; ";
	   $r=mysql_query($ZAP_SQL) or die('Error z zap_sql'.$ZAP_SQL);
		echo "<pre>";
	   while($h=mysql_fetch_array($r)) {
	   		echo "\n";
			echo "/".$h['ID'];
			echo "/".$h['DATA_DOK'];
			echo "/".$h['KONTO_KSIEG'];
			echo "/".$h['ID_PROJECT'];
			echo "/".$h['BUDZET'];
			echo "/".$h['ID_BUDZET'];

			if(isset($t)) unset($t);

				//preg_match_all("/^([[:digit:]]{2,5}-/", $h['KONTO_KSIEG'], $matches, PREG_SET_ORDER);
				$m=explode('-',$h['KONTO_KSIEG']);
				$m[0]=TRIM_ZERO($m[0]);
				$m[1]=TRIM_ZERO($m[1]);

					if(($m[0]>=310)&&($m[0]<=310)) { //konta 4xx
				//	$t['ID_BUDZET']=TRIM_ZERO($m[2]);
				//	$t['ID_PROJECT']=TRIM_ZERO($m[3]);
					$t['KONTO_SYN']=$m[0];



				} else if(($m[0]>=400)&&($m[0]<=499)) { //konta 4xx

				    if($m[3]=="0000")$m[3]=$m[2];
					$t['ID_BUDZET']=TRIM_ZERO($m[2]);
					$t['ID_PROJECT']=TRIM_ZERO($m[3]);
					$t['KONTO_SYN']=$m[0][0];

				} else 	if(($m[0]>=71)&&($m[0]<=71)) { //konta 80
					$t['KONTO_SYN']=TRIM_ZERO($m[0]);
					//$t['ID_BUDZET']=TRIM_ZERO($m[2]);
//					$t['ID_PROJECT']=TRIM_ZERO($m[1]);
					//print_r($m);
				} else 	if(($m[0]>=80)&&($m[0]<=80)) { //konta 80
					$t['KONTO_SYN']=TRIM_ZERO($m[0]);
					//$t['ID_BUDZET']=TRIM_ZERO($m[2]);
					$t['ID_PROJECT']=TRIM_ZERO($m[1]);
					//print_r($m);
				} else 	if(($m[0]>=201)&&($m[0]<=201)) { //naleznosci od klientow 201
					$t['KONTO_SYN']=TRIM_ZERO($m[0]);
					//$t['ID_BUDZET']=TRIM_ZERO($m[2]);
					if($h['WINIEN_MA']=='WINIEN') $t['201_WINIEN']=$h['wartosc'];
					if($h['WINIEN_MA']=='MA') $t['201_MA']=$h['wartosc'];
					//print_r($m);
				} else 	if(($m[0]>=202)&&($m[0]<=299)) { //naleznosci od dostawcow 202
					$t['KONTO_SYN']=TRIM_ZERO($m[0]);

					if($h['WINIEN_MA']=='WINIEN') $t['202_WINIEN']=$h['wartosc'];
					if($h['WINIEN_MA']=='MA') $t['202_MA']=$h['wartosc'];

				} else 	if(($m[0]>=703)&&($m[0]<=703)) { //odsetki od kredytow i odsetki
					$t['KONTO_SYN']=TRIM_ZERO($m[0]);
				} else 	if(($m[0]>=750)&&($m[0]<=750)) { //pozostale koszty operacyjne
					$t['KONTO_SYN']=TRIM_ZERO($m[0]);

				} else 	if(($m[0]>=751)&&($m[0]<=751)) { //pozostale koszty operacyjne
					$t['KONTO_SYN']=TRIM_ZERO($m[0]);

				}   else 	if(($m[0]>=761)&&($m[0]<=761)) { //pozostale koszty operacyjne
					$t['KONTO_SYN']=TRIM_ZERO($m[0]);
					//$t['ID_BUDZET']=TRIM_ZERO($m[2]);
					if($h['WINIEN_MA']=='WINIEN') $t['202_WINIEN']=$h['wartosc'];
					if($h['WINIEN_MA']=='MA') $t['202_MA']=$h['wartosc'];
					//print_r($m);
				} else 	if(($m[0]>=751)&&($m[0]<=751)) { //odsetki od kredytow i odsetki

					$t['KONTO_SYN']=TRIM_ZERO($m[0]);

					//$t['ID_BUDZET']=TRIM_ZERO($m[2]);
					if($h['WINIEN_MA']=='WINIEN') $t['202_WINIEN']=$h['wartosc'];
					if($h['WINIEN_MA']=='MA') $t['202_MA']=$h['wartosc'];
					//print_r($m);
				}





				//print_r($t);
				if(isset($t)) { //update do bazy
					$ZAP_UPD="update KSIEG_DOKUMENTY set KONTO_SYN='".$t['KONTO_SYN']."', ID_BUDZET='".$t['ID_BUDZET']."' , ID_PROJECT='".$t['ID_PROJECT']."' ,
							 201_WINIEN='".$t['201_WINIEN']."', 201_MA='".$t['201_MA']."' ,
							  202_WINIEN='".$t['202_WINIEN']."' , 202_MA='".$t['202_MA']."'   where ID='".$h['ID']."' limit 1";
					//echo "\n ".$ZAP_UPD;
					ZAP_SQL($ZAP_UPD);
				}


	   }

	   	echo "</pre>";

}

if($_REQUEST['ANALIZUJ_PLYNNOSC_KONT_2XX']) {
	echo "<pre>";





	//1. Budowa tabeli slownikowej INDEKS24

echo "<br>//Tworze slownikowa tabele od 0 do 24 miesiecy w przeszlosc\n";
 $ZAP_SQL=" drop  table  if exists   INDEKS24 ;"; //echo "<br> $ZAP_SQL  <br>\n";
 ZAP_SQL($ZAP_SQL);
 $ZAP_SQL=" create   table INDEKS24 (ID int(3)  , DATA date ) ;";
// echo "<br> $ZAP_SQL  <br>\n";
 ZAP_SQL($ZAP_SQL);
 $i=-24;
 $LP=24;
  while ($i < 48 ) {
  $i++;
  $LP--;
 //echo "Nas            z miesiac to $i<br>";
 $ZAP_SQL="insert into INDEKS24 SELECT '".$LP."', DATE_FORMAT(concat(PERIOD_ADD( DATE_FORMAT(now(), '%Y%m') ,-$i),'01'),'%Y-%m-%d'); ";
 ZAP_SQL($ZAP_SQL);

  // echo " $ZAP_SQL \n <br>";
//EOF Tworze slownikowa tabele od 0 do 24
 }









		ZAP_SQL("select t1.ID as LP , t1.DATA as DATA , count(t2.ID) as COUNT,

					t2.ID, t2.DATA_DOK, t2.KONTO_KSIEG, t2.wartosc, t2.TYP_DOKUMENTU, t2.ID_PROJECT, t2.WINIEN_MA ,
					sum(201_WINIEN) as A201_WINIEN_S , sum(201_MA) as A201_MA_S ,
						sum(202_WINIEN) as A202_WINIEN_S , sum(202_MA) as A202_MA_S
				 from INDEKS24 as t1
				 left join KSIEG_DOKUMENTY as t2 on ( YEAR(t1.DATA)=year(t2.DATA_DOK) and MONTH(t1.DATA)=MONTH(t2.DATA_DOK) )

				 where t2.TYP_DOKUMENTU='IMPORT' or t2.TYP_DOKUMENTU is NULL or TYP_DOKUMENTU='IMPORT-KOSZTORYS'
				 group by year(t1.DATA) , month(t1.DATA)

				  order by t1.ID  "); //, t2.ID_PROJECT,t2.KONTO_SYN
				  echo "<table border=1>";
				  	echo "<tr><td>LP</td><td>DATA</td><td>COUNT</td><td>KONT_KSIEG</td>
				<td>ID_PROJECT</td><td>A201_WINIEN_S</td><td>A201_MA_S</td><td>A202_WINIEN_S</td>
				<td>A202_MA_S</td><td>ZOB_KLIENT</td>
				<td>ZOB_DOST</td> <td>ZOB_ALL</td>
				 <td>ZOB_KLIENT_S</td><td>ZOB_DOST_S</td><td>ZOB_ALL_S</td>
				</tr>";

		while ($h=mysql_fetch_object($result )) {
			echo "\n";
			//print_r($h);
				$ZOB_KLIENT=$h->A201_WINIEN_S-$h->A201_MA_S;
				$ZOB_DOST=$h->A202_WINIEN_S-$h->A202_MA_S;
				$ZOB_ALL=$ZOB_DOST-$ZOB_KLIENT;
				$ZOB_KLIENT_S+=$ZOB_KLIENT;
				$ZOB_DOST_S+=$ZOB_DOST;
				$ZOB_ALL_S+=$ZOB_ALL;

				echo "<tr><td>".$h->LP."</td><td>".$h->DATA."</td><td>".$h->COUNT."</td><td>".$h->KONT_KSIEG."</td>
				<td>".$h->ID_PROJECT."</td><td>".$h->A201_WINIEN_S."</td><td>".$h->A201_MA_S."</td><td>".$h->A202_WINIEN_S."</td>
				<td>".$h->A202_MA_S."</td><td>".$ZOB_KLIENT."</td>
				<td>".$ZOB_DOST."</td> <td>".$ZOB_ALL."</td>
				 <td>".$ZOB_KLIENT_S."</td><td>".$ZOB_DOST_S."</td><td>".$ZOB_ALL_S."</td>
				</tr>";

		}
				echo "</table>";

	echo "\n </pre>";
} //eof if($_REQUEST['ANALIZUJ_PLYNNOSC_KONT_2XX']) {





if($_REQUEST['AKTUALIZACJA_ZAMOWIEN_ZD_SUBIEKT']) {
	echo "<pre>";

		echo "<br>Lacze sie do bazy IS";
		$db=mssql_connect($CNF_ZASOB['1182']['INTERFACE_ADDR'],$CNF_ZASOB['1182']['SQL_USER'],$CNF_ZASOB['1182']['SQL_USER_PASS']);
		mssql_select_db($CNF_ZASOB['1182']['SQL_DATABASE'],$db);

		$query="select *, CONVERT(varchar(10), dok_DataWyst , 20) as dok_DataWyst ,
				 CONVERT(varchar(10), dok_DataMag , 20) as dok_DataMag ,
				 CONVERT(varchar(10), dok_PlatTermin , 20) as dok_PlatTermin ,
				 CONVERT(varchar(10), dok_TerminRealizacji , 20) as dok_TerminRealizacji


		  from dok__Dokument where dok_NrPelny  like 'ZD%'   ; ";
		//$query=" convert(datetime, '2016-10-23 20:44:11.500',  121)";
		ZAP_SQL("delete from KSIEG_DOKUMENTY where TYP_DOKUMENTU='IMPORT-KOSZTORYS' ");
		$R=mssql_query($query);
 			while ($r=mssql_fetch_object($R)) {
 				//print_r($r);
 				if(isset($t)) unset($t);
 				//list('',$t['ID_PROJECT_GUESS'])=
 				list(,$t['ID_PROJECT_SGT'])=explode('/',$r->dok_NrPelny);
 					$ZAP_SQL="select ID from IN7_MK_BAZA_DYSTRYBUCJI where ID like '".$t['ID_PROJECT_SGT']."'";// echo "\n".$ZAP_SQL;
					//if($t['ID_PROJECT_SGT'])
					 ZAP_SQL($ZAP_SQL);
//						$RES=mysql_fetch_array($result);
//						print_r($RES);
						list($t['ID_PROJECT_GUESS'])=mysql_fetch_array($result);
						if($t['ID_PROJECT_GUESS']==$t['ID_PROJECT_SGT']) $t['ID_PROJECT']=$t['ID_PROJECT_GUESS'];
								$ZAP_SQL="select ID from IN7_MK_BAZA_DYSTRYBUCJI where M_DIST_DESC like '%(magazyn_".$t['ID_PROJECT_SGT'].")%'";
						if(!isset($t['ID_PROJECT'])) ZAP_SQL($ZAP_SQL);
						list($t['ID_PROJECT_GUESS'])=mysql_fetch_array($result);
					  	if(mysql_num_rows($result)>1) die("<br> Za duzo powiazanych projektow o tym samym oznaczeniu magazynu w opisie  : ".$t['ID_PROJECT_SGT'].".<br>Dokument : ".$r->dok_NrPelny."<br> w opisie projektu musi byc tylko 1 magazyn opisany w sposob : (magazyn ".$t['ID_PROJECT_SGT']."), a jest:".mysql_num_rows($result));
						if($t['ID_PROJECT_GUESS']) $t['ID_PROJECT']=$t['ID_PROJECT_GUESS'];
						if(!isset($t['ID_PROJECT'])) die("<br> Nie mozna rozpoznac magazynu dla rekordu ze wskazanym magazynem : ".$t['ID_PROJECT_SGT'].".<br>Dokument : ".$r->dok_NrPelny."<br> w opisie projektu musi byc magazyn opisany w sposob : (magazyn ".$t['ID_PROJECT_SGT'].")");
						//tu szukamy glownego numeru sprawy budzetu!
						$safe=10;
						if($t['ID_PROJECT']) $t['ID_PROJECT_GUESS']=$t['ID_PROJECT'];
						$t['ID_PROJECT_ROOT_GUESS']=$t['ID_PROJECT_GUESS'];$t['ID_PROJECT_ROOT_LAST']=$t['ID_PROJECT_ROOT_GUESS'];

							while($safe>0) {
						   		$ZAP_SQL="select P_ID from IN7_MK_BAZA_DYSTRYBUCJI where ID='".$t['ID_PROJECT_ROOT_GUESS']."'";
						   ZAP_SQL($ZAP_SQL); //echo "\n".$ZAP_SQL;
							list($t['ID_PROJECT_ROOT_LAST'])=mysql_fetch_array($result);
								if($t['ID_PROJECT_ROOT_LAST']=='0') {
								unset($t['ID_PROJECT_ROOT_LAST']);
								break;
								} else $t['ID_PROJECT_ROOT_GUESS']=$t['ID_PROJECT_ROOT_LAST'];

								$safe--;
								echo ".";
							}
							//if(!)

 						print_r($t);


				$ZAP_SQL="insert into KSIEG_DOKUMENTY (A_RECORD_CREATE_DATE,A_RECORD_CREATE_AUTHOR, DATA_DOK, NUMER_DOK , SPRZEDAWCA ,
						ID_SPRZEDAWCA , ILOSC , CENA_JEDN_NETTO , STAWKA_VAT , wartosc , CZY_URZADZENIE , TYP_DOKUMENTU, ID_PROJECT,
						ID_BUDZET,A_STATUS,KONTO_KSIEG , WINIEN_MA , 202_WINIEN) values (
						now() , '".$_SESSION['AUTHORIZE_USER']."' ,
						'".$r->dok_TerminRealizacji."','".$r->dok_NrPelny."',
						'".$r->dok_PlatnikId."','".$r->dok_PlatnikId."','1','".$r->dok_WartNetto."','0','".$r->dok_WartNetto."','NOT_DEVICE',
						'IMPORT-KOSZTORYS','".$t['ID_PROJECT_GUESS']."','".$t['ID_PROJECT_ROOT_GUESS']."','NORMAL','400-00-".$t['ID_PROJECT_ROOT_GUESS']."-".$t['ID_PROJECT_GUESS']."', 'WINIEN' , '".$r->dok_WartBrutto."')";
						echo "<br>\n".$ZAP_SQL;
				 		ZAP_SQL($ZAP_SQL);


			}
		echo "</pre>";




} //eof  if($_REQUEST['AKTUALIZACJA_ZAMOWIEN_ZD_SUBIEKT']) {



//print_r($_SESSION);

if($_REQUEST['IMPORT_FAKTUR_Z_ZASOB_719']) {
	echo "<pre>";

		//$ZAP_SQL="select * from BILLS_FVAT_POS limit 100";
		//$res719 = mysql_query($ZAP_SQL,$conn719) or die("Blad zapytania ZAP_SQL. *$ZAP_SQL*!");
		//$numrows719=mysql_numrows($res719);
		//echo "\n".$numrows719;

		SEF('SYNC_MYDATABASE_SQIX');
		$sync_tables=array('BILLS_FVAT_POS','BILLS_FVAT');
//		$sync_tables=array('BILLS_FVAT_X');
		//$sync_tables=array('SERVICES');


SYNC_MYDATABASE_SQIX('719',$sync_tables,$DATABASE_ROOT_ZASOB_ID);
		//print_r($_SESSION);
//		$sync_tables=array('SES_VOIP_A','SES_USERS2_A','SERVICES');
//		$sync_tables=array('SES_VOIP_A','SERVICES');

//		SYNC_MYDATABASE_SQIX('695',$sync_tables,'14');
//2012-01-05 wywalone by Bzyk & plabudda

	echo "</pre>";

}//eof IMPORT_FAKTUR_Z_ZASOB_719






if($_REQUEST['RAPORT_WYNIKOWY_ala_Cyperska']) {

//funkcja napisana @2012-09-05 na potrzeby analizy kosztow projektow
	echo "<pre>";



		//1. Budowa tabeli slownikowej INDEKS24

echo "<br>//Tworze slownikowa tabele od 0 do 24 miesiecy w przeszlosc\n";
 $ZAP_SQL=" drop  table  if exists   INDEKS24 ;"; //echo "<br> $ZAP_SQL  <br>\n";
 ZAP_SQL($ZAP_SQL);
 $ZAP_SQL=" create   table INDEKS24 (ID int(3)  , DATA date ) ;";
// echo "<br> $ZAP_SQL  <br>\n";
 ZAP_SQL($ZAP_SQL);
 $i=-24;
 $LP=24;
  while ($i < 24 ) {
  $i++;
  $LP--;
 //echo "Nas            z miesiac to $i<br>";
 $ZAP_SQL="insert into INDEKS24 SELECT '".$LP."', DATE_FORMAT(concat(PERIOD_ADD( DATE_FORMAT(now(), '%Y%m') ,-$i),'01'),'%Y-%m-%d'); ";
 ZAP_SQL($ZAP_SQL);

//   echo " $ZAP_SQL \n <br>";
   }
//EOF Tworze slownikowa tabele od 0 do 24

	//jedziemy po datach biezacy rok //
	$ZAP_SQL="select DATA from INDEKS24 where year(DATA) like year(now()) or year(DATA) like year(DATE_ADD(date(now()),INTERVAL -1 YEAR)) order by DATA limit 24 ";
	$result_date=mysql_query($ZAP_SQL);
	while($res=mysql_fetch_object($result_date)) {


				$DATA=$res->DATA;
			//koszty dotyczace czworek 4
				$CYP_RAP_RODZAJE=array(703=>'PR '.$DATA ,750=>'PR '.$DATA,760=>'PR '.$DATA,4=>'KO '.$DATA,751=>'KO '.$DATA,761=>'KO '.$DATA,80=>'IN '.$DATA,310=>'IN '.$DATA);

				  foreach($CYP_RAP_RODZAJE as $CYP_RAP_RODZAJ=>$CYP_RAP_KOSZT_INWEST) {

				$zap_sql="select KD.ID, KD.KONTO_SYN, KD.KONTO_KSIEG, KD.DATA_DOK,KD.NUMER_DOK, KD.wartosc,
					KD.WINIEN_MA, KD.201_WINIEN,KD.201_MA,KD.202_WINIEN,KD.202_MA,KD.TYP_DOKUMENTU,KD.BUDZET,KD.ID_PROJECT
					, PR.M_DIST_TYPE , PR.M_DISTRIBUTOR, PR.M_DIST_DESC ,KD.ID_BUDZET
				 from KSIEG_DOKUMENTY as KD
				   left join IN7_MK_BAZA_DYSTRYBUCJI as PR on PR.ID=KD.ID_PROJECT
				 where month(KD.DATA_DOK) like month('".$DATA."') and year(KD.DATA_DOK) like year('".$DATA."') and KD.TYP_DOKUMENTU='IMPORT'
				 and KD.KONTO_SYN='".$CYP_RAP_RODZAJ."'
				 -- and PR.ID='629'
				 order by KD.ID_BUDZET,PR.M_DIST_TYPE ";
				ZAP_SQL($zap_sql);

				$CYP_RAP[$CYP_RAP_KOSZT_INWEST][$CYP_RAP_RODZAJ]=array();
				while($h=mysql_fetch_object($result)){
					 if($h->ID_BUDZET=="") $h->ID_BUDZET="0";
					 if($h->ID_PROJECT=="") $h->ID_PROJECT="0";
					$CYP_RAP[$CYP_RAP_KOSZT_INWEST][$CYP_RAP_RODZAJ]['detale']['analityka-projekty'][$h->ID_PROJECT]+=$h->wartosc;
						$KONTO_RODZAJ=split('-',$h->KONTO_KSIEG);
					$CYP_RAP[$CYP_RAP_KOSZT_INWEST][$CYP_RAP_RODZAJ]['detale']['analityka-1'][$KONTO_RODZAJ[0]]+=$h->wartosc;
					$CYP_RAP[$CYP_RAP_KOSZT_INWEST][$CYP_RAP_RODZAJ]['detale']['analityka-2'][$KONTO_RODZAJ[1]]+=$h->wartosc;
					$CYP_RAP[$CYP_RAP_KOSZT_INWEST][$CYP_RAP_RODZAJ]['detale']['analityka-2-M_DIST'][$h->M_DIST_TYPE][$KONTO_RODZAJ[1]]+=$h->wartosc;
				    $CYP_RAP[$CYP_RAP_KOSZT_INWEST][$CYP_RAP_RODZAJ]['detale']['analityka-2-M_DIST-ID_PROJ'][$KONTO_RODZAJ[1]][$h->M_DIST_TYPE][$h->ID_PROJECT]+=$h->wartosc;

					$CYP_RAP[$CYP_RAP_KOSZT_INWEST][$CYP_RAP_RODZAJ]['detale']['M_DIST_TYPE'][$h->M_DIST_TYPE]+=$h->wartosc;

					$RYP_CAP_PREFIX=$KONTO_RODZAJ[0]."--".$KONTO_RODZAJ[1]."--".$h->ID_BUDZET;
					//$RYP_CAP_SUFFIX="</b></nobr>";

					$CYP_RAP_USED[$RYP_CAP_PREFIX.$h->ID_PROJECT.$RYP_CAP_SUFFIX]['DATA'][$CYP_RAP_KOSZT_INWEST]+=$h->wartosc;
					$CYP_RAP_USED[$RYP_CAP_PREFIX.$h->ID_PROJECT.$RYP_CAP_SUFFIX]['KONTO_RODZAJ0']=$KONTO_RODZAJ[0];
					$CYP_RAP_USED[$RYP_CAP_PREFIX.$h->ID_PROJECT.$RYP_CAP_SUFFIX]['KONTO_RODZAJ1']=$KONTO_RODZAJ[1];
					$CYP_RAP_USED[$RYP_CAP_PREFIX.$h->ID_PROJECT.$RYP_CAP_SUFFIX]['ID_PROJECT']=$h->ID_PROJECT;
					$CYP_RAP_USED[$RYP_CAP_PREFIX.$h->ID_PROJECT.$RYP_CAP_SUFFIX]['ID_BUDZET']=$h->ID_BUDZET;




					$CYP_RAP_DATA['ID_PROJECT'][$RYP_CAP_PREFIX.$h->ID_PROJECT.$RYP_CAP_SUFFIX]['ID_PROJECT']=$h->ID_PROJECT;
					$CYP_RAP_DATA['ID_PROJECT'][$RYP_CAP_PREFIX.$h->ID_PROJECT.$RYP_CAP_SUFFIX]['M_DIST_TYPE']=$h->M_DIST_TYPE;
					$CYP_RAP_DATA['ID_PROJECT'][$RYP_CAP_PREFIX.$h->ID_PROJECT.$RYP_CAP_SUFFIX]['M_DIST_DESC']=$h->M_DIST_DESC;
					$CYP_RAP_DATA['ID_PROJECT'][$RYP_CAP_PREFIX.$h->ID_PROJECT.$RYP_CAP_SUFFIX]['M_DISTRIBUTOR']=$h->M_DISTRIBUTOR;
					$CYP_RAP_DATA['ID_PROJECT'][$RYP_CAP_PREFIX.$h->ID_PROJECT.$RYP_CAP_SUFFIX]['ID_BUDZET'][$h->ID_BUDZET]=1;

					$CYP_RAP_DATA['ID_PROJECT'][$RYP_CAP_PREFIX.$h->ID_PROJECT.$RYP_CAP_SUFFIX]['WYSTEPUJE_W_RODZAJACH'][$KONTO_RODZAJ[1]]=1;
					$CYP_RAP_DATA['ID_PROJECT'][$RYP_CAP_PREFIX.$h->ID_PROJECT.$RYP_CAP_SUFFIX]['WYSTEPUJE_W_DZIALACH'][$KONTO_RODZAJ[0]]=1;
					$CYP_RAP_DATA['ID_PROJECT'][$RYP_CAP_PREFIX.$h->ID_PROJECT.$RYP_CAP_SUFFIX]['SUMA_KOSZTOW']+=$h->wartosc;


    				$CYP_RAP[$CYP_RAP_KOSZT_INWEST][$CYP_RAP_RODZAJ]['detale']['syntetyka']+=$h->wartosc;
				    $CYP_RAP[$CYP_RAP_KOSZT_INWEST]['suma']+=$h->wartosc;


				}

			 } //foreach   foreach($CYP_RAP_RODZAJE as $CYP_RAP_RODZAJ) {

	} //foreach $result_date
	//			print_r($CYP_RAP);

				echo "</pre>";

				//algin wszystkich projektow z bazy
//				$zap_sql="select PR.M_DIST_TYPE , PR.M_DISTRIBUTOR, PR.M_DIST_DESC  from IN7_MK_BAZA_DYSTRYBYCJI as PR where PR.A_STATUS!='DELETED' "

	$LP=1;
echo "<table border=1><tr><td>Lp.</td><td>Konto</td><td>Rodzaj</td><td>Dzial-ID</td><td>PROJEKT</td><td>Typ Projektu</td><td>Opis</td><td>Koszta dzialach/rodzajach</td><td>Koszta w dzialach</td><td>Suma na prawo</td>";

	//malujemy naglowek
	foreach($CYP_RAP as $RCI=>$RCA) {
		  echo "<td>".$RCI."</td>";
    }
//malujemy w dol
	echo "</tr>";
echo "<tr>><td>".$LP."</td><td>.</td><td>.</td><td>.</td><td>.</td><td>.</td><td>.</td><td>.</td><td>Sumy Przychodow</td><td>";
			$LP++;
			$NAG=0;
			foreach($CYP_RAP as $RCI=>$RCA) {
			$NAG++;
			if($NAG==1) $SUMY['PR']+=$RCA['suma'];
			if($NAG==3) $NAG=0;
		    }
		echo $SUMY['PR'];
	echo "</td>";
//PRZYCHOD
			$NAG=0;
foreach($CYP_RAP as $RCI=>$RCA) {
		  echo "<td>";
			$NAG++;
			if($NAG==1) echo "<b>".str_replace('.',',',$RCA['suma'])."<b>";
			if($NAG==3) $NAG=0;
		  echo "</td>";
    }
    echo "</tr>";
//KOSZTY
	echo "<tr><td>".$LP."</td><td>.</td><td>.</td><td>.</td><td>.</td><td>.</td><td>.</td><td>.</td><td>Sumy Kosztow</td><td>";
	$NAG=0; $LP++;
			foreach($CYP_RAP as $RCI=>$RCA) {
			$NAG++;
			if($NAG==2) $SUMY['KO']+=$RCA['suma'];
			if($NAG==3) $NAG=0;
		    }
		echo $SUMY['KO'];


	echo "</td>";
				$NAG=0;
foreach($CYP_RAP as $RCI=>$RCA) {
		  echo "<td>";
			$NAG++;
			if($NAG==2) echo "<b>".str_replace('.',',',$RCA['suma'])."<b>";
			if($NAG==3) $NAG=0;
		  echo "</td>";
    }
    echo "</tr>";
//INWESTYCJE
echo "<tr><td>".$LP."</td><td>.</td><td>.</td><td>.</td><td>.</td><td>.</td><td>.</td><td>.</td><td>Sumy Inwestycji</td><td>";
		foreach($CYP_RAP as $RCI=>$RCA) {
			$NAG++;$LP++;
			if($NAG==3) $SUMY['IN']+=$RCA['suma'];
			if($NAG==3) $NAG=0;
		    }
		echo $SUMY['IN'];
echo "</td>";
			$NAG=0;
foreach($CYP_RAP as $RCI=>$RCA) {
		  echo "<td>";
		 	 $NAG++;
			if($NAG==3) echo "<b>".str_replace('.',',',$RCA['suma'])."<b>";
			if($NAG==3) $NAG=0;
		  echo "</td>";
    }
    echo "</tr>";


 	foreach($CYP_RAP_USED as $RPUI1=>$RPUA1) {
	echo "<tr>";//"<td>".$RPUI1."</td>";
	echo "<td>".$LP."</td>";$LP++;
	echo "<td>".$RPUA1['KONTO_RODZAJ0']."</td>";
		echo "<td>".$RPUA1['KONTO_RODZAJ1']."</td>";
					echo "<td>".$RPUA1['ID_BUDZET']."</td>";
			echo "<td>".$RPUA1['ID_PROJECT']."</td>";
		echo "<td>".str_replace('_',' ',$CYP_RAP_DATA['ID_PROJECT'][$RPUI1]['M_DIST_TYPE'])."</td>";
				echo "<td>".$CYP_RAP_DATA['ID_PROJECT'][$RPUI1]['M_DIST_DESC']." ".$CYP_RAP_DATA['ID_PROJECT'][$RPUI1]['M_DISTRIBUTOR']."</td>";
				echo "<td>";
 			 	foreach ($CYP_RAP_DATA['ID_PROJECT'][$RPUI1]['WYSTEPUJE_W_DZIALACH'] as $ind=>$arr) echo $ind.", ";
 				echo "--";
				foreach ($CYP_RAP_DATA['ID_PROJECT'][$RPUI1]['WYSTEPUJE_W_RODZAJACH'] as $ind=>$arr) echo $ind.", ";
				echo "</td>";
				echo "<td>";
				  foreach ($CYP_RAP_DATA['ID_PROJECT'][$RPUI1]['ID_BUDZET'] as $ind=>$arr) echo $ind.", ";

				echo "</td><td><b>".str_replace('.',',',$CYP_RAP_DATA['ID_PROJECT'][$RPUI1]['SUMA_KOSZTOW'])."</b></td>";
				$BGCOL_IND=0;
		foreach($CYP_RAP as $CRAI1=>$CRAA1) {
				$BGCOL_IND++;
				if($BGCOL_IND==1) $BGCOLOR="bgcolor='#ccffff'";
				else if($BGCOL_IND==2) $BGCOLOR="bgcolor='#ffccff'";
				else if($BGCOL_IND==3) { $BGCOLOR="bgcolor='#ffffcc'"; $BGCOL_IND=0;	 }

			echo "<td ".$BGCOLOR.">".str_replace('.',',',$RPUA1['DATA'][$CRAI1])."</td>";

		}
	echo "</tr>";
		 	}


	//echo "</tr>";




	echo "</table>";



} //eof if($_REQUEST['RAPORT_WYNIKOWY_ala_Cyperska']) ###############################################






echo "<form method=\"post\" enctype=\"multipart/form-data\"> \n
<input type=hidden name=KSIEG_DOKUMENTY_ZASOB1182_SUBIEKT_MSSQL_IMPORT value=1>
<input type=hidden name=UPDATE_MAPA_DEKRETOW value=1>
<input type=submit value='AKTUALIZUJ_MAPE_DEKRETOW ( po imporcie XML)'></form><br>
";



echo "<form method=\"post\" enctype=\"multipart/form-data\"> \n
<input type=hidden name=KSIEG_DOKUMENTY_ZASOB1182_SUBIEKT_MSSQL_IMPORT value=1>
<input type=hidden name=RAPORT_WYNIKOWY_ala_Cyperska value=1>
<input type=submit value=RAPORT_WYNIKOWY_ala_Cyperska></form><br>
";



echo "<form method=\"post\" enctype=\"multipart/form-data\"> \n
<input type=hidden name=KSIEG_DOKUMENTY_ZASOB1182_SUBIEKT_MSSQL_IMPORT value=1>
<input type=hidden name=ANALIZUJ_PLYNNOSC_KONT_2XX value=1>
<input type=submit value=ANALIZUJ_PLYNNOSC_KONT_2XX></form><br>
";


echo "<form method=\"post\" enctype=\"multipart/form-data\"> \n
<input type=hidden name=KSIEG_DOKUMENTY_ZASOB1182_SUBIEKT_MSSQL_IMPORT value=1>
<input type=hidden name=AKTUALIZACJA_ZAMOWIEN_ZD_SUBIEKT value=1>
<input type=submit value=AKTUALIZACJA_ZAMOWIEN_ZD_SUBIEKT></form><br>
";



echo "<form method=\"post\" enctype=\"multipart/form-data\"> \n
<input type=hidden name=KSIEG_DOKUMENTY_ZASOB1182_SUBIEKT_MSSQL_IMPORT value=1>
<input type=hidden name=IMPORT_FAKTUR_Z_ZASOB_719 value=1>
<input type=submit value=IMPORT_FAKTUR_Z_ZASOB_719></form><br>
";




echo "<form method=\"post\" enctype=\"multipart/form-data\"> \n
<table border=1><tr><td colspan=2>
<input type=hidden name=KSIEG_DOKUMENTY_ZASOB1182_SUBIEKT_MSSQL_IMPORT value=1>
<br>wkaz lokalizacje ZSO - szczegolowe w postaci XML (analityka 4)
<label for=\"file\">Filename:</label>
<input type=\"file\" name=\"file1182\" id=\"file1182\">\n
</td></tr>
<tr><td>POCZATEK OKRESU IMPORTOWANYCH DANYCH</td><td>DATA KONCA IMPORTU DANYCH</td></tr>
<tr><td><br>ROK YYYY<input type=text size=4 name=START_ROK value=".$_REQUEST['START_ROK']."> \n
<br>MIESIAC MM<input type=text size=2 name=START_MIESIAC value=".$_REQUEST['START_MIESIAC']."> \n
<br>DZIEN DD<input type=text size=2 name=START_DZIEN value=".$_REQUEST['START_DZIEN']."> \n
</td><td><br>ROK YYYY<input type=text size=4 name=KONIEC_ROK value=".$_REQUEST['KONIEC_ROK']."> \n
<br>MIESIAC MM<input type=text size=2 name=KONIEC_MIESIAC value=".$_REQUEST['KONIEC_MIESIAC']."> \n
<br>DZIEN DD<input type=text size=2 name=KONIEC_DZIEN value=".$_REQUEST['KONIEC_DZIEN']."> \n
</td></tr>

<tr><td colspan=2>Ignorowanie Bilansow Otwarcia - BO-1 <input type=CHECKBOX name=IGNORE_BO";
 if($_REQUEST['IGNORE_BO']) echo " checked=1 ";
echo "></td></tr>

<tr><td colspan=2>Wgranie pliku skasuje wszystkie TYP_DOKUMENTU=IMPORT danych w FAKTURY dla  <input type=submit value=wyslij></td></tr>

</table>

</form>";

//phpinfo();

/*

echo "TEST";

$db=mssql_connect($myServer,$myUser,$myPass);
mssql_select_db($myDB,$db);

$query="
SELECT KhEw.kh_Id,KhEw.kh_Zablokowany,KhEw.kh_Osoba,KhEw.kh_Rodzaj,KhEw.kh_Symbol,AdrEwid.adr_Id,AdrEwid.adr_Nazwa,AdrEwid.adr_NIP,AdrEwid.adr_Adres,AdrEwid.adr_Miejscowosc,AdrEwid.adr_NazwaPelna,case

when kh_NrAnalitykaO<>'' and kh_NrAnalitykaD<>'' and kh_NrAnalitykaO <> kh_NrAnalitykaD

then 'BLAD w analitykach '+kh_NrAnalitykaO + ' ' + kh_NrAnalitykaD

when kh_NrAnalitykaD<>''        then kh_NrAnalitykaD

when kh_NrAnalitykaO<>''        then kh_NrAnalitykaO

else        ''
end as Analityka,Flagi.flg_Numer,FlagiWartosci.flw_CzasOstatniejZmiany,FlagaUzytk.uz_Identyfikator,FlagiWartosci.flw_Komentarz,FlagiWartosci.flw_IdFlagi,Flagi.flg_Text,Flagi.flg_Id FROM kh__Kontrahent AS KhEw LEFT JOIN adr__Ewid AS AdrEwid ON KhEw.kh_Id=AdrEwid.adr_IdObiektu LEFT JOIN sl_Wojewodztwo AS WojEwid ON AdrEwid.adr_IdWojewodztwo=WojEwid.woj_Id LEFT JOIN (SELECT adr_IdObiektu as kdk_IdKontrahenta, COUNT(adr_IdObiektu) AS IleDokBibl FROM bib_Dokument LEFT JOIN adr__Ewid ON adr_Id = bib_IdObiektu WHERE bib_TypObiektu = 1 GROUP BY adr_IdObiektu) AS BiblDok ON KhEw.kh_Id=BiblDok.kdk_IdKontrahenta LEFT JOIN (SELECT zdk_IdKlienta,COUNT(zdk_IdZadania) AS LiczbaNotatek FROM zd_Uczestnik INNER JOIN zd__Zadanie ON zd_Id=zdk_IdZadania AND zd_Rodzaj=4 GROUP BY zdk_IdKlienta) AS KhNotatka ON AdrEwid.adr_Id=KhNotatka.zdk_IdKlienta LEFT JOIN fl_Wartosc AS FlagiWartosci ON KhEw.kh_Id=FlagiWartosci.flw_IdObiektu AND flw_IdGrupyFlag = 18 LEFT JOIN pd_Uzytkownik AS FlagaUzytk ON FlagiWartosci.flw_IdUzytkownika=FlagaUzytk.uz_Id LEFT JOIN fl__Flagi AS Flagi ON FlagiWartosci.flw_IdFlagi=Flagi.flg_Id";
// WHERE kh_Jednorazowy=0 AND ((adr_Id is NULL) OR (adr_TypAdresu = 1)) AND KhEw.kh_IdGrupa=4";

$query="select * from sys.Tables";

//$query="SELECT column_name , data_type + COALESCE( '(' + CAST(character_maximum_length AS VARCHAR) + ')' , '(' + CAST(numeric_precision AS VARCHAR) + ')' , '' ) , column_default, is_nullable FROM information_schema.columns WHERE table_name = '__BeforeDropOldTables';";

$query="nz__Finanse";

$result=mssql_query($query);

if ($result_arr=mssql_fetch_array($result)) {
	echo "<table border=1><tr>";
	for ($i=0;$i<mssql_num_fields($result);$i++) {
		$fields_name[]=mssql_field_name($result,$i);
		echo "<td>".mssql_field_name($result,$i)."</td>";
	}
	echo "</tr>";
	do {
		echo "<tr>";
		foreach ($fields_name as $field_name)
			echo "<td>".$result_arr[$field_name]."</td>";


		echo "</tr>";


/*		 //###
       		$query2="SELECT                                      column_name
						,         data_type +
                         COALESCE(
                                         '(' + CAST(character_maximum_length AS VARCHAR) + ')'
                                      ,  '(' + CAST(numeric_precision AS VARCHAR) + ')'
                                      ,  ''
                                      ) ,         column_default,         is_nullable FROM information_schema.columns
                            			WHERE
                                      table_name = '".$result_arr[0]."';";

       			//echo "<tr><td colspan=20>".$query2."<br>";

				$result2=mssql_query($query2);


				if ($result_arr2=mssql_fetch_array($result2)) {
 						echo "<tr><td colspan=20><table border=1><tr>";
 						for ($i=0;$i<mssql_num_fields($result2);$i++) {
 							$fields_name2[]=mssql_field_name($result2,$i);
 							echo "<td>".mssql_field_name($result2,$i)."</td>";
 						}
 						echo "</tr>";
 						do {
 							echo "<tr>";
 							foreach ($fields_name2 as $field_name)
 								echo "<td>".$result_arr2[$field_name]."</td>";


 							echo "</tr>";

							} while ($result_arr2=mssql_fetch_array($result2));
							echo "</table></td></tr>";
				}



       		//###


	} while ($result_arr=mssql_fetch_array($result));
	echo "</table>";
}


*/



?></body></html>
