<?php

  include_once('config.php');

  ob_start('ob_gzhandler');
  @$codcliente = $_GET["codcliente"];
  @$nrovenda = $_GET["nrovenda"];

  $sql = "select nrolancto, codcliente, dataemissao, datavencto, valor, valorpago, codportador, situacao, nrodocumento, nroparc, codvendedor, ".
        "coalesce(valdespesas,0) + coalesce(VALDESPOUT,0) valdespesas, valorjuros, codbanco, hash_pix, identif_pix ".
      "from CONTASRECEBER ".
      "where SITUACAO IN ('A', 'R') ";
	  
	if ($codcliente > 0){  
	  $sql .= " and CODCLIENTE = ".$codcliente;
	} else if ($nrovenda > 0){
	  $sql .= " and NROVENDA = ".$nrovenda;
	}

	$query = ibase_query($sql); 
	  
  $array = array();
  while ($row = ibase_fetch_assoc($query)) {
    $array[] = $row;
  }

  print json_encode($array);

?>