<?php include("parent/callMe.php");

?>
<select name="Creditaccount_name[]" id="accountCredit" class="select select_add form-control">

  <option value="">Select Credit Account</option>
<?php



if ($_REQUEST['voucherType']=='1') {
  
  $branchID=$_SESSION['branch'];
  $sql = "SELECT * FROM  eduportal_accounts_finance_bank_details WHERE branch_id='$branchID'";
  $secondLevel = $m->query($sql);


  foreach($secondLevel as $secondLevel_val)
{

  $m->where("coa_id_fk ", $secondLevel_val['coa_id']);
  $m->where("branch_id ", $_SESSION['branch']);
  $accountBalance = $m->get("eduportal_branch_account_opening_balances");


  $m->where("coa_id", $secondLevel_val['coa_id']);
  $AccountsData = $m->get("eduportal_chart_of_accounts");

 
if(is_array($secondLevel_val)){
 ?>
  <option value="<?php echo $secondLevel_val['finance_account_id']; ?>"><?php echo trim(utf8_encode_all($AccountsData[0]['account_code']." (".$secondLevel_val['account_title'].")"." ( Balance ".$secondLevel_val['opening_balance'].")")); ?></option>

<?php } } } else {



 $voucherType=$_REQUEST['voucherType'];

  $sql = "SELECT * FROM  eduportal_account_debit_credit WHERE voucher_type_id='$voucherType' and transection_type='credit'";
  $secondLevel = $m->query($sql);

  //print_r($secondLevel);
if($secondLevel[0]>0){
foreach($secondLevel as $secondLevel_val)
{

  $m->where("coa_id_fk ", $secondLevel_val['account_id']);
  $m->where("branch_id ", $_SESSION['branch']);
  $WorkAssignList = $m->get("eduportal_branch_account_opening_balances");

  if ($WorkAssignList[0]['coa_id_fk']==NULL) {
    continue;
  }

  $m->where("coa_id ", $WorkAssignList[0]['coa_id_fk']);
  $accountName = $m->get("eduportal_chart_of_accounts");

if(is_array($secondLevel_val)){
 ?>
  <option value="<?php echo $WorkAssignList[0]['coa_id_fk']; ?>"><?php echo trim(utf8_encode_all($accountName[0]['account_title']." (".$accountName[0]['account_code'].")"." ( Balance ".$WorkAssignList[0]['current_balance'].")")); ?></option>

  <?php } } } } ?>
 
</select>