   } else if ($piTipo==69) {
      $sEcoTxt = '/qtux/www/FullPlat/processos/logs/OnSave_69_'.time().'.log';
      $sEcoTxt = fsDirEcoTxt($sEcoTxt);
      fpc($sEcoTxt,"inicio-psDDFChamada=$psDDFChamada");
      if ($psDDFChamada==1) {         // alterar
         $pCapa   = $piIdPai;
         $pCPgmto = $piId;
         fpc_append($sEcoTxt,"pCapa=$pCapa,pCPgmto=$pCPgmto");

         $sSql = "select nTmpVlPedCPgmto from CPgmto a where a.pPId=$piId and a.iVer=a.iVAt";
         fpc_append($sEcoTxt,"sSql=$sSql");
         $aDb  = faDbSelect($phDb,$sSql);
         $nTmpVlPedCPgmto  = $aDb[0][0];
         fpc_append($sEcoTxt,"nTmpVlPedCPgmto=$nTmpVlPedCPgmto");

         $sSql = "select pPId from PVlMinimo_CPgmto where pCapa=$pCapa and pCPgmto=$pCPgmto and iVer=iVAt";
         fpc_append($sEcoTxt,"sSql=$sSql");
         $aDb  = faDbSelect($phDb,$sSql);
         $pPVlMinimo_CPgmto  = $aDb[0][0];
         fpc_append($sEcoTxt,"pPVlMinimo_CPgmto=$pPVlMinimo_CPgmto");
         ///
         if ($pPVlMinimo_CPgmto>0) { // ja existe
            // criando nova versao do registro
            $sTab = 'PVlMinimo_CPgmto';
            $sUpd = "update $sTab set iVAt=iVAt+1 where pPId=$pPVlMinimo_CPgmto";
            fpc_append($sEcoTxt,"sUpd=$sUpd");
            $lOk  = flDbUpdate($phDb,$sUpd);

            if ($lOk==true) {
               $sIns = "insert into $sTab select * from $sTab where pPId=$pPVlMinimo_CPgmto and iVer+1= iVAt";
               fpc_append($sEcoTxt,"sIns=$sIns");
               $lOk  = flDbInsert($phDb,$sIns);
            }
   
            // update do processo
            if ($lOk==true) {
               $sSql = "update PVlMinimo_CPgmto set nVlPedCPgmto= $nTmpVlPedCPgmto,
                                                    pInc        = $psLogin,
                                                    tInc        = 'now'
                        where pPId       = $pPVlMinimo_CPgmto
                          and iVer       = iVAt";
               fpc_append($sEcoTxt,"sSql=$sSql");
               $lOk  = flDbUpdate($phDb,$sSql);
               fpc_append($sEcoTxt,"lOk=$lOk");
            }
         } else {   // nao existe
           $sSql = "insert into PVlMinimo_CPgmto (pInc,pCapa,pCPgmto,nVlPedCPgmto) values ($psLogin,$pCapa,$pCPgmto,$nTmpVlPedCPgmto)";
           fpc_append($sEcoTxt,"sSql=$sSql");
           $lOk  = flDbInsert($phDb,$sSql);
           fpc_append($sEcoTxt,"lOk=$lOk");
         }
         ///
      }   // if ($psDDFChamada==1)

   } else if ($piTipo==70) {
      $sEcoTxt = '/qtux/www/FullPlat/processos/logs/OnSave_70_'.time().'.log';
      $sEcoTxt = fsDirEcoTxt($sEcoTxt);
      fpc($sEcoTxt,"inicio-psDDFChamada=$psDDFChamada");
      if ($psDDFChamada==1) {         // alterar
         $pOrdem = $piId;
         fpc_append($sEcoTxt,"pOrdem=$pOrdem");

         $sSql        = "select m.nVlPedCPgmto,
                                a.nTot_vNF,
                                a.lCalculado
                         from Ordens   a  left join Ordens_FPgmto      b on b.pOrdem             = a.pPId    and b.iVer = b.iVAt and b.lExc=0
                                          left join PED_FPgmto_CPgmto  c on b.pPED_FPgmto_CPgmto = c.pPId    and c.iVer = (case when b.fPED_FPgmto_CPgmto=0 then c.iVAt else b.fPED_FPgmto_CPgmto end)
                                          left join CPgmto             d on c.pCPgmto            = d.pPId    and d.iVer = d.iVAt and d.lExc=0
                                          left join PVlMinimo_Emi      l on l.pEmi               = a.pEmi    and l.iVer = l.iVAt
                                          left join PVlMinimo_CPgmto   m on d.pPId               = m.pCPgmto and l.pCapa = m.pCapa and m.iVer = m.iVAt and m.lExc=0
                         where  a.lExc = 0 and a.iVer = a.iVAt
                            and a.pPId = $pOrdem";
         fpc_append($sEcoTxt,"sSql=$sSql");
         $aDb          = faDbSelect($phDb,$sSql);
         $nVlPedCPgmto = $aDb[0][0];
         $nTot_vNF     = $aDb[0][1];
         $lCalculado   = $aDb[0][2];
         fpc_append($sEcoTxt,"nTot_vNF=$nTot_vNF,lCalculado=$lCalculado");
                      
         if ($lCalculado==0) { 
            $psMsg = "Por gentileza recalcular a Ordem para escolher a condio de pagamento.";
            fpc_append($sEcoTxt,"Por gentileza recalcular a Ordem para escolher a condio de pagamento.");
            $lOk=false;
         }

         if ($nTot_vNF>=$nVlPedCPgmto) { 
            $psMsg = "O Valor Mnimo da Condio de Pagamento [$nVlPedCPgmto] est menor que o valor do faturamento [$nTot_vNF].";
            fpc_append($sEcoTxt,"O Valor Mnimo da Condio de Pagamento [$nVlPedCPgmto] est menor que o valor do faturamento [$nTot_vNF].");
            $lOk=false;
         }
         ///
      }   // if ($psDDFChamada==1)

   } else if ($piTipo==71) {
      $sEcoTxt = '/qtux/www/FullPlat/processos/logs/OnSave_71_'.time().'.log';
      $sEcoTxt = fsDirEcoTxt($sEcoTxt);
      fpc($sEcoTxt,"inicio-psDDFChamada=$psDDFChamada");

      $pOrdem = $piId;
      fpc_append($sEcoTxt,"pOrdem=$pOrdem");

      $sSql = "select a.pPId,
                      b.pPId,
                      b.sCoringa
                 from PVlMinimo_Emi a join CUP   b on a.pEmi = b.pPId  and b.iVer  = b.iVAt
                where a.iVer  = a.iVAt
                  and a.lExc  = 0
                  and a.pCapa != $piId
                order by b.sCoringa";
      fpc_append($sEcoTxt,"sSql=$sSql");
      $aDb            = faDbSelect($phDb,$sSql);
      $aArr_Emi = array();
      foreach ($aDb as $aLin) {
         $pPVlMinimo_Emi = $aLin[0];
         $pEmi           = $aLin[1];
         $sEmi           = $aLin[2];
         fpc_append($sEcoTxt,"pPVlMinimo_Emi=$pPVlMinimo_Emi, pEmi=$pEmi, sEmi=$sEmi");
         $aArr_Emi[]     = $pEmi;
      }

      $sSql = "select a.pPId,
                      b.pPId,
                      b.sCoringa
                 from PVlMinimo_Emi a join CUP   b on a.pEmi = b.pPId  and b.iVer  = b.iVAt
                where a.iVer  = a.iVAt
                  and a.lExc  = 0
                  and a.pCapa = $piId
                order by b.sCoringa";
      fpc_append($sEcoTxt,"sSql=$sSql");
      $aDb            = faDbSelect($phDb,$sSql);
      foreach ($aDb as $aLin) {
         $pPVlMinimo_Emi = $aLin[0];
         $pEmi           = $aLin[1];
         $sEmi           = $aLin[2];
         fpc_append($sEcoTxt,"pPVlMinimo_Emi=$pPVlMinimo_Emi, pEmi=$pEmi, sEmi=$sEmi");
         if (in_array($pEmi,$aArr_Emi)) {
            $psMsg = "A UNeg no deve se repetir, j existe um registro com a UNeg $sEmi.";
            fpc_append($sEcoTxt,"psMsg=$psMsg");
            $lOk=false;   
         } else {
            $aArr_Emi[]     = $pEmi;
         }
      }
