<?
$w=$GLOBALS[db]->query("select id,document_no from ecminvoiceoutolds where register_date>'2010-01-01' and type='normal'");
while($r=$GLOBALS[db]->fetchByAssoc($w)){
	$ww=$GLOBALS[db]->query("select price,quantity,ecmvat_value from ecminvoiceoutolditems where ecminvoiceoutold_id='".$r['id']."'");
	$total_vat=0;
	$total_brutto=0;
	$total_netto=0;
	$total_vat_r=0;
	$total_brutto_r=0;
	$total_netto_r=0;
	while($rr=$GLOBALS[db]->fetchByAssoc($ww)){
		$total_vat+=$rr['price']*$rr['quantity']*$rr['ecmvat_value']/100;
		$total_brutto+=$rr['price']*$rr['quantity']*(1+$rr['ecmvat_value']/100);
		$total_netto+=$rr['price']*$rr['quantity'];

		$total_vat_r+=round($rr['price']*$rr['quantity']*$rr['ecmvat_value']/100,2);
		$total_brutto_r+=round($rr['price']*$rr['quantity']*(1+$rr['ecmvat_value']/100),2);
		$total_netto_r+=round($rr['price']*$rr['quantity'],2);

		//if(round($rr['price']*$rr['quantity']*(1+$rr['ecmvat_value']/100)-

	}
	//if(!eregi(((float)round($total_netto,2)+(float)round($total_vat,2)),((float)round($total_brutto,2))))
	if(round($total_brutto-$total_netto,2)!=round($total_vat,2)){
	echo $r['document_no']."<br>";
	echo (round($total_brutto-$total_netto,2))." ".round($total_netto,2)." ".round($total_brutto,2)."<br>";
	echo round($total_vat,2)." ".round($total_netto,2)." ".round($total_brutto,2)."<br>";
	}
}
?>