include "libs/db_sql.php";
include "classes/db_pcproc_classe.php";
include "classes/db_pcprocitem_classe.php";
include "classes/db_pcdotac_classe.php";
include "classes/db_pcorcam_classe.php";
include "classes/db_pcorcamitem_classe.php";
include "classes/db_pcorcamitemproc_classe.php";
include "classes/db_pcorcamforne_classe.php";
include "classes/db_cgm_classe.php";
$clpcproc = new cl_pcproc();
$clpcprocitem = new cl_pcprocitem();
$clpcdotac = new cl_pcdotac();
$clpcorcam = new cl_pcorcam();
$clpcorcamitem = new cl_pcorcamitem();
$clpcorcamitemproc = new cl_pcorcamitemproc();
$clpcorcamforne = new cl_pcorcamforne();
$clcgm = new cl_cgm();
$sqlpref = "select * from db_config where codigo = " . db_getsession("DB_instit");
$resultpref = pg_exec($sqlpref);
db_fieldsmemory($resultpref, 0);
parse_str($HTTP_SERVER_VARS['QUERY_STRING']);
$fornecedores = "";
$vir = "";
if (isset($forne) && $forne != "branco") {
    $arr_forne = split("forn_", $forne);
    for ($i = 1; $i < sizeof($arr_forne); $i++) {
        $fornecedores .= $vir . $arr_forne[$i];
        $vir = ",";
    }
    $fornecedor_cgm = $fornecedores;
    $fornecedores = " and z01_numcgm in ({$fornecedores}) ";
 *  02111-1307, USA.                                                  
 *  
 *  Copia da licenca no diretorio licenca/licenca_en.txt 
 *                                licenca/licenca_pt.txt 
 */
session_start();
include "libs/db_conecta.php";
include "libs/db_stdlib.php";
include "libs/db_sql.php";
include "dbforms/db_funcoes.php";
include "classes/db_pcorcamval_classe.php";
include "classes/db_pcorcamforne_classe.php";
parse_str(base64_decode($HTTP_SERVER_VARS["QUERY_STRING"]));
db_postmemory($HTTP_POST_VARS);
$cl_pcorcamval = new cl_pcorcamval();
$cl_pcorcamforne = new cl_pcorcamforne();
$clrotulo = new rotulocampo();
$clrotulo->label("pc23_vlrun");
$clrotulo->label("pc23_valor");
$sqlerro = false;
$sql = "select z01_cgccpf,\n              z01_nome,\n              pc20_dtate,\n              pc20_hrate,\n              pc21_prazoent,\n              pc21_validadorc  \n\t\t     from pcorcamforne \n\t\t    inner join cgm     on pc21_numcgm = z01_numcgm \n\t\t    inner join pcorcam on pc20_codorc = pc21_codorc\n\t\t    where pc21_numcgm = {$cgm} \n\t\t      and pc21_codorc = {$orc}";
$result = pg_exec($sql);
db_fieldsmemory($result, 0);
if ($sol == 1) {
    $sqlitens = "select pc11_codigo,\n                  pc11_quant,\n                  pc01_descrmater,\n                  pc11_resum,\n                  pc11_pgto,\n                  pc11_prazo,\n                  pc11_seq,\n                  pc10_numero,\n                  m61_usaquant,\n                  m61_descr,\n\t\t              pc17_codigo,\n\t\t              pc17_quant,\n\t\t              pc01_servico,\n\t\t              pc29_orcamitem,\n\t\t              pc23_valor,\n\t\t              pc23_obs,\n\t\t              pc23_vlrun,\n\t\t              pc23_validmin \n\t\t\t       from pcorcamitemsol \n\t\t\t      inner join pcorcamitem      on pcorcamitem.pc22_orcamitem      = pcorcamitemsol.pc29_orcamitem\n\t\t\t      inner join pcorcam          on pcorcam.pc20_codorc             = pcorcamitem.pc22_codorc \n\t\t\t      inner join solicitem        on solicitem.pc11_codigo           = pcorcamitemsol.pc29_solicitem \n\t\t\t      inner join solicita         on solicita.pc10_numero            = solicitem.pc11_numero \n\t\t        inner join pcorcamforne     on  pcorcam.pc20_codorc            = pc21_codorc\n\t\t\t       left join solicitemunid    on solicitemunid.pc17_codigo       = solicitem.pc11_codigo \n\t\t\t       left join matunid          on matunid.m61_codmatunid          = solicitemunid.pc17_unid \n\t\t\t       left join solicitempcmater on solicitempcmater.pc16_solicitem = solicitem.pc11_codigo \n\t\t\t       left join pcmater          on pcmater.pc01_codmater           = solicitempcmater.pc16_codmater \n\t\t\t       left join pcsubgrupo       on pcsubgrupo.pc04_codsubgrupo     = pcmater.pc01_codsubgrupo \n\t\t\t       left join pctipo           on pctipo.pc05_codtipo             = pcsubgrupo.pc04_codtipo\n\t\t\t       left join pcorcamval       on pcorcamitem.pc22_orcamitem      = pc23_orcamitem and pc23_orcamforne=pc21_orcamforne\n\t\t\t      where pc22_codorc     = {$orc} \n\t\t\t        and pc21_orcamforne = {$forne}\n\t\t\t      order by pc11_seq";
    $result = pg_exec($sqlitens);
    $linhas = pg_num_rows($result);
} else {
    $sol = 2;
    $sqlproc = "select pc11_seq,\n\t                 pc11_resum,\n\t                 pc11_codigo,\n\t                 pc11_vlrun,\n\t                 pc11_quant,\n\t                 pc01_descrmater,\n\t                 pc22_orcamitem,\n\t                 pc31_orcamitem,\n\t\t\t\t           pc23_valor,\n\t\t\t\t           pc23_obs,\n\t\t\t\t           pc23_vlrun,\n\t\t\t\t           pc23_validmin\n\t\t\t\t      from pcorcamitem \n\t\t\t\t     inner join pcorcam          on pcorcam.pc20_codorc             = pcorcamitem.pc22_codorc\n\t\t\t\t     inner join pcorcamforne     on pcorcam.pc20_codorc             = pc21_codorc \n\t\t\t\t     inner join pcorcamitemproc  on pcorcamitemproc.pc31_orcamitem  = pcorcamitem.pc22_orcamitem \n\t\t\t\t     inner join pcprocitem       on pcprocitem.pc81_codprocitem     = pcorcamitemproc.pc31_pcprocitem \n\t\t\t\t      left join pcorcamval       on pcorcamitemproc.pc31_orcamitem  = pc23_orcamitem\n\t\t\t\t                                and pc23_orcamforne = {$forne}\n\t\t\t\t     inner join solicitem        on solicitem.pc11_codigo           = pcprocitem.pc81_solicitem \n\t\t\t\t      left join solicitempcmater on solicitempcmater.pc16_solicitem = solicitem.pc11_codigo \n\t\t\t\t      left join pcmater          on pcmater.pc01_codmater           = solicitempcmater.pc16_codmater \n\t\t\t\t     where pc20_codorc={$orc}  \n\t\t\t\t       and pc21_orcamforne = {$forne}\n\t\t\t\t     order by pc22_orcamitem";
    $result = pg_exec($sqlproc);
include "classes/db_solicitem_classe.php";
include "classes/db_solicitemunid_classe.php";
include "classes/db_pcdotac_classe.php";
include "classes/db_pcorcam_classe.php";
include "classes/db_pcorcamitem_classe.php";
include "classes/db_pcorcamitemsol_classe.php";
include "classes/db_pcorcamforne_classe.php";
include "classes/db_cgm_classe.php";
$clsolicita = new cl_solicita();
$clsolicitem = new cl_solicitem();
$clsolicitemunid = new cl_solicitemunid();
$clpcdotac = new cl_pcdotac();
$clpcorcam = new cl_pcorcam();
$clpcorcamitem = new cl_pcorcamitem();
$clpcorcamitemsol = new cl_pcorcamitemsol();
$clpcorcamforne = new cl_pcorcamforne();
$clcgm = new cl_cgm();
//die($cgm);
//die( db_getsession("DB_login"));
//($HTTP_SESSION_VARS["DB_login"]);
//$z01_numcgm = db_getsession("DB_login");
$sqlpref = "select * from db_config where codigo = " . db_getsession("DB_instit");
$resultpref = pg_exec($sqlpref);
db_fieldsmemory($resultpref, 0);
parse_str($HTTP_SERVER_VARS['QUERY_STRING']);
$fornecedores = "";
$vir = "";
if (isset($forne) && $forne != "branco") {
    $arr_forne = split("forn_", $forne);
    for ($i = 1; $i < sizeof($arr_forne); $i++) {
        $fornecedores .= $vir . $arr_forne[$i];