<?php
header('Content-Type: application/json');
if (isset($_GET['employ_id'])) {
  $employId = $_GET['employ_id'];
  include("dbConfig.php");
  $sql_cw = "SELECT * FROM coonect_employ_with_solfacount_tn WHERE employ_id='$employId' AND company_id!='' AND (type='auhd' or type='salf')  AND deleted='0'";
  $result_cw = $conn->query($sql_cw);
 

  if ($result_cw->num_rows > 0) {
    while ($row_cw = $result_cw->fetch_assoc()) {
         $daenn = 0.0;
  $madenn = 0.0;
  $rasedd = 0.0;
         $type = $row_cw["type"];
         $company_id = $row_cw["company_id"];
         $account_number = $row_cw["account_number"];
      $sql_daily_restt = "SELECT account_number, daen, maden FROM daily_restriction_tbl WHERE company_id='".$row_cw["company_id"]."' AND account_number='".$row_cw["account_number"]."' AND opening_balance='0'";
      $result_daily_ress = $conn->query($sql_daily_restt);

      if ($result_daily_ress->num_rows > 0) {
        while ($row_daily_restt = $result_daily_ress->fetch_assoc()) {
          $daenn +=  $row_daily_restt["daen"];
          $madenn +=  $row_daily_restt["maden"];
          $rasedd =  $madenn - $daenn;
        }
      }
      $balance[]= [
    'type' => $type,
    'company_id' => $company_id,
    'account_number' => $account_number,
    'daenn' => strval($daenn),
        'madenn' => strval($madenn),
        'rasedd' => strval($rasedd)
              ]; 
    }
  }
  echo json_encode($balance);
}


?>