<?php

	include('connection1.php');

 	/*$sql= "select * from lcodes";
	$result=$dbacc2->query($sql);
	while($row = $result->fetch()){	
		$sql_up= "update lcodes set c_opbal1='".$row["c_opbal1"]."' where c_code='".$row["c_code"]."'";
		$result_up=$dbacc1->query($sql_up);
	}
	*/
	$sql_up= "update lcodes set c_opbal1='0' ";
			echo $sql_up;
			$result_up=$dbacc1->query($sql_up);
			
	$sql= "select * from ledger where l_flag='OPB'";
	$result=$dbacc2->query($sql);
	while($row = $result->fetch()){	
		if ($row["l_flag1"]=="DEB"){
			$sql_up= "update lcodes set c_opbal1='".$row["l_amount"]."'  where c_code='".$row["l_code"]."'";
			echo $sql_up;
			$result_up=$dbacc1->query($sql_up);
		} else if ($row["l_flag1"]=="CRE"){
			$sql_up= "update lcodes set c_opbal1='".(-1*$row["l_amount"])."'  where c_code='".$row["l_code"]."'";
			echo $sql_up;
			$result_up=$dbacc1->query($sql_up);
		}	
	}
	
?>

