Subversion Repositories Sigmater

Rev

Blame | Last modification | View Log | Download | RSS feed

<?
//funzione costruzione select per controllo in tabella protocolli esistenza istanza della fornitura attuale
 function       getSelectProtocollo($connect,$arrDatiFornitura)
{
        $sql    =       '';
        if(trim($arrDatiFornitura['sez'])       ==      '')
        {
                $arrDatiFornitura['sez']        =       ' ';
        }

    //07/06/2004 13.15 inserito ordinamento e conversione data
        $sql    =       "select
                                TI07_PROTOCOLLO,
                                TI07_PROTOCOLLO_STAGING,
                                TI07_KEYCOM,
                                TI07_KEYSEZ,
                                to_char(TI07_PERIODO_DA,'DD/MM/YYYY') TI07_PERIODO_DA,
                                to_char(TI07_PERIODO_A,'DD/MM/YYYY') TI07_PERIODO_A,
                                TI07_TIPO_FORNITURA,
                                TI07_TIPO_PROCESSO,
                                TI07_PROT_DBTI,
                                TI07_CODSTATO
                        from s3_ti07_protocolli where ti07_keycom = '".$arrDatiFornitura['codcom']."'".
        " and ti07_keysez = '".$arrDatiFornitura['sez']."'".
        " and ti07_tipo_processo = '".$arrDatiFornitura['tipocatasto']."'";

    $sql        .=      " order by  ti07_protocollo_staging desc";
        list($result, $err) = exec_select_format($connect, $sql,1);

        return(array($err,$result));

}
function        getSequenceProtocollo($connect)
{
        $sql            =       '';
        $sql            =       "select  ti07_seq.nextval SEQUENCE from dual";

        list($result, $err) = exec_select_format($connect, $sql,1);
        return(array($err,$result[0]['SEQUENCE']));
}
function        getSequenceProtStag($connect)
{
        $sql    =       '';
        $sql    =       "select  ti07_staging_seq.nextval SEQUENCE from dual";
        list($result, $err) = exec_select_format($connect, $sql,1);
        return(array($err,$result[0]['SEQUENCE']));
}

function        insetProtocolS3_ti07($connect,$arrArg)
{
        $sql    =       '';
        $err    =       0;
        $sql    ="insert into s3_ti07_protocolli values (".
                                                                                        $arrArg['protocollo'].","
                                                                                        .$arrArg['protocollo_stag'].","
                                                                                        ."'".$arrArg['keycom']."',"
                                                                                        ."'".($arrArg['keysez']==''?' ':$arrArg['keysez'])."',"
                                                                                        ."to_date('".$arrArg['periodo_da']."','DD/MM/YYYY'),"
                                                                                        ."to_date('".$arrArg['periodo_a']."','DD/MM/YYYY'),"
                                                                                        ."'".$arrArg['tipo_fornitura']."',"
                                                                                        ."'".$arrArg['tipo_processo']."',"
                                                                                        ."null,"
                                                                                        ."null,"
                                                                                        ."'".$arrArg['nome_fornitura']."'"

                                                                                .")";

        list ($stmt, $ocierr) = exec_sql($connect, $sql, 1);

        if (!$stmt) {
                $err = $ocierr;
        }
        return($err);
}
function        insetTcw17_errlog($connect,$arrArg)
{
        $sql    =       '';
        $err    =       0;
        $sql    ="insert into tcw17_errlog values (".
                                                                                        $arrArg['TCW17_STEP'].","
                                                                                        ."'".$arrArg['TCW17_DESCR_ERR']."',"
                                                                                        .$arrArg['TCW17_LAST_RECORD'].","
                                                                                        ."to_date('".$arrArg['TCW17_DATE']."','DD/MM/YYYY'),"
                                                                                        .$arrArg['TCW17_PROTOCOLLO']
                                                                                        .")";

        list ($stmt, $ocierr) = exec_sql($connect, $sql, 1);

        if (!$stmt) {
                $err = $ocierr;
        }
        return($err);
}
function        updateProtocolS3_ti07($connect,$value,$where)
{
        $sql    =       '';
        $err    =       0;
        $sql    ="update  s3_ti07_protocolli set $value where $where";

        list ($stmt, $ocierr) = exec_sql($connect, $sql, 1);
        //echo $sql."<br>";
        if (!$stmt) {
                $err = 1;
        }
        return($err);
}
function        updateTcw17_errlog($connect,$value,$where)
{
        $sql    =       '';
        $err    =       0;
        $sql    ="update  TCW17_ERRLOG set $value where $where";

        list ($stmt, $ocierr) = exec_sql($connect, $sql, 1);

        if (!$stmt) {
                $err = 1;
        }
        return($err);
}

function getTcw17_errlog($connect,$protStag)
{
        $sql_select     =       '';
        $sql_select     ="SELECT TCW17_STEP, TCW17_DESCR_ERR, TCW17_LAST_RECORD, TCW17_DATE FROM tcw17_errlog WHERE tcw17_protocollo = $protStag ORDER BY TCW17_DATE DESC";
        //23/06/2004 18.29      ricerco protocolli cancellati o in caricamento
        $arrReturn      =       Array();

        list($result, $err) = exec_select_format($connect, $sql_select,1);
        if ($err == 'NODATA') {
           //nessun dato
                $return =       array(
                                                'err'                   =>      'NODATA',
                                                'message'       =>      ''
                                        );
        }
        elseif ($err != '') {
          //errore
                $return =       array(
                                                        'err'                   =>   'E008',
                                                        'message'       =>      $err.' '.$sql_select
                                                );
        }
        else {
         //ok
                $return =       $result;
        }

        return($return);
}

function protIsDeleted($connect,$protStag)
{
        $sql_select     =       '';
        $sql_select     ="SELECT TCW17_STEP, TCW17_DESCR_ERR, TCW17_LAST_RECORD, TCW17_DATE FROM tcw17_errlog WHERE TCW17_DESCR_ERR = 'IMPDBDELETE'     and tcw17_protocollo = $protStag";
        $arrReturn      =       Array();
        list($result, $err) = exec_select_format($connect, $sql_select,1);

        if ($err == 'NODATA') {
                 //nessun dato
                $return =       false;
        }
        elseif ($err != '') {
          //errore
                $return =       array(
                                                        'err'                   =>   'E008',
                                                        'message'       =>      $err.' '.$sql_select
                                                );
        }
        else {
         //ok
                $return =       true;

        }

        return($return  );
}

//      Funzione estrae protocolo e protocollo di staging dalla sequence e inserisce nellan ti07_protocolli
//      array(
//      'protocollo'            =>      $numProt,
//      'protocollo_stag'       =>      $numProtStag,
//      'keycom'                        =>      $p_prm->getCodCom(),
//      'keysez'                        =>      $p_prm->getSez(),
//      'periodo_da'            =>      $p_prm->getDataRegDa(),
//      'periodo_a'             =>      $p_prm->getDataRegA(),
//      'tipo_fornitura'                =>      $p_prm->getTipoFornitura(),
//      'tipo_processo' =>      $p_prm->getTipoCatasto('1')
//      )
function newStag($conn,$arrPrm)
{
        //caricamento fornitura differente
        //controllo date validita
        //nuovo caricamento
        $err                                    =       '';
        $ti07_tipo_fornitura    =       '';
        $ti07_periodo_da                =       '';
        $ti07_periodo_a                 =       '';
        $numProt                                =       0;
        $numProtStag                    =       0;

        list($err,$numProt)             =       getSequenceProtocollo($conn);
        if($err !=      '')
        {
                 jError('E002',$err,1);
                 exit();
        }

        list($err,$numProtStag)         =       getSequenceProtStag($conn);
        if($err !=      '')
        {
                 jError('E003',$err,1);
                 exit();
        }


        $arrPrm['protocollo']           =       $numProt;
        $arrPrm['protocollo_stag']      =       $numProtStag;

        $err                            =       insetProtocolS3_ti07($conn,$arrPrm);
        if($err !=      '')
        {
                 JError('E004',$err,1);
        }


        $ti07_tipo_fornitura    =       $arrPrm['tipo_fornitura'];
        $ti07_periodo_da        =       $arrPrm['periodo_da'];
        $ti07_periodo_a         =       (trim($arrPrm['periodo_a'])     ==      ''?'':$arrPrm['periodo_a']);
        return(
                        array(
                                        'err'                   =>      $err,
                                        'protocollo'            =>      $numProt,
                                        'protocollo_stag'       =>      $numProtStag,
                                        'tipo_fornitura'        =>      $ti07_tipo_fornitura,
                                        'periodo_da'            =>      $ti07_periodo_da,
                                        'periodo_a'             =>      $ti07_periodo_a
                        )
        );

}

 function       getSelectProtocolloDbti($connect)
{
        $sql    =       '';

        $sql    =       "select

                                TI07_PROTOCOLLO_STAGING,
                                TI07_KEYCOM,
                                TI07_KEYSEZ,
                                TI07_TIPO_FORNITURA,
                                TI07_TIPO_PROCESSO,
                                TI07_PROT_DBTI,
                                TI07_CODSTATO,
                                TI07_NOME_FORNITURA
                        from s3_ti07_protocolli where TI07_CODSTATO is null  or  TI07_CODSTATO != 2";
        list($result, $err) = exec_select_format($connect, $sql,1);

        if ($err == 'NODATA') {
           //nessun dato
                $return =       array(
                                                'err'                   =>      'NODATA',
                                                'message'       =>      ''
                                        );
        }
        elseif ($err != '') {
          //errore
                $return =       array(
                                                        'err'                   =>   'Errore',
                                                        'message'       =>      $err.' '.$sql_select
                                                );
        }
        else {
                return(array($err,$result));
        }

}

function getProtStagOK($connect)
{
        $sql_select     =       '';

        $sql_select     ="select TI07_NOME_FORNITURA,TI07_PROTOCOLLO_STAGING,TI07_CODSTATO from S3_TI07_PROTOCOLLI a,TCW17_ERRLOG b where (a.TI07_PROTOCOLLO_STAGING like b.TCW17_PROTOCOLLO) and ((b.TCW17_DESCR_ERR like 'IMPDBOK')OR(b.TCW17_DESCR_ERR like 'IMPDBRIPROK')) AND (A.TI07_CODSTATO <> 2 OR A.TI07_CODSTATO IS NULL)";

        $arrReturn      =       Array();

        list($result, $err) = exec_select_format($connect, $sql_select,1);
        if ($err == 'NODATA') {
           //nessun dato
                $return =       array(
                                                'err'                   =>      'NODATA',
                                                'message'       =>      ''
                                        );
        }
        elseif ($err != '') {
          //errore
                $return =       array(
                                                        'err'                   =>   'E016',
                                                        'message'       =>      $err.' '.$sql_select
                                                );
        }
        else {
                $return =       $result;
        }

        return($return);
}

function        getOracleDate($connect)
{

        $sql_select     =       '';

        //$sql_select   ="select to_char(sysdate,'dd/mm/yyyy hh24:mi:ss') data from dual";
        $sql_select     ="select to_char(sysdate,'dd/mm/yyyy') data from dual";
        $arrReturn      =       Array();

        list($result, $err) = exec_select_format($connect, $sql_select,1);
        if ($err == 'NODATA') {
           //nessun dato
                $return =       array(
                                                'err'                   =>      'NODATA',
                                                'message'       =>      ''
                                        );
        }
        elseif ($err != '') {
          //errore
                $return =       array(
                                                        'err'                   =>   'E016',
                                                        'message'       =>      $err.' '.$sql_select
                                                );
        }
        else {
                //print_r($result);
                $return =       $result[0]['DATA'];
        }

        return($return);
}
?>