Ejemplo n.º 1
0
function import()
{
    global $error, $importLog, $tempDBName, $sourceDBName, $targetDBName, $sourceDBID, $importRtyID, $importedRecTypes;
    $importedRecTypes = array();
    $error = false;
    $importLog = array();
    if (!$tempDBName || $tempDBName === "" || !$targetDBName || $targetDBName === "" || !$sourceDBID || !is_numeric($sourceDBID) || !$importRtyID || !is_numeric($importRtyID)) {
        makeLogEntry("importParameters", -1, "One or more required import parameters not supplied or incorrect form ( " . "importingDBName={name of target DB} sourceDBID={reg number of source DB or 0} " . "importRtyID={numeric ID of record type} tempDBName={temp db name where source DB type data are held}");
        $error = true;
    }
    $startedTransaction = false;
    if (!$error) {
        mysql_query("start transaction");
        $startedTransaction = true;
        // Get recordtype data that has to be imported
        $res = mysql_query("select * from " . $tempDBName . ".defRecTypes where rty_ID = " . $importRtyID);
        if (mysql_num_rows($res) == 0) {
            $error = true;
            makeLogEntry("Record type", $importRtyID, " was not found in local, temporary copy of, source database ({$sourceDBName})");
        } else {
            $importRty = mysql_fetch_assoc($res);
        }
        // check if rectype already imported, if so return the local id.
        if (!$error && $importRty) {
            $origRtyName = $importRty["rty_Name"];
            $replacementName = @$_GET["replaceRecTypeName"];
            if ($replacementName && $replacementName != "") {
                $importRty["rty_Name"] = $replacementName;
                $importRty["rty_Plural"] = "";
                //TODO  need better way of determining the plural
            }
            if ($importRty["rty_OriginatingDBID"] == 0 || $importRty["rty_OriginatingDBID"] == "") {
                $importRty["rty_OriginatingDBID"] = $sourceDBID;
                $importRty["rty_IDInOriginatingDB"] = $importRtyID;
                $importRty["rty_NameInOriginatingDB"] = $origRtyName;
            }
            //lookup rty in target DB
            $resRtyExist = mysql_query("select rty_ID from " . $targetDBName . ".defRecTypes " . "where rty_OriginatingDBID = " . $importRty["rty_OriginatingDBID"] . " AND rty_IDInOriginatingDB = " . $importRty["rty_IDInOriginatingDB"]);
            // Rectype is not in target DB so import it
            $localRtyID = null;
            if (mysql_num_rows($resRtyExist) > 0) {
                $localRtyID = mysql_fetch_array($resRtyExist, MYSQL_NUM);
                $localRtyID = $localRtyID[0];
                makeLogEntry("Record type", $importRtyID, " ALREADY EXISTS in {$targetDBName} as ID = {$localRtyID}");
            }
            $localRtyID = importRectype($importRty, $localRtyID);
            if ($localRtyID) {
                array_push($importedRecTypes, $importRty["rty_ID"]);
            }
        }
    }
    // successful import
    if (!$error) {
        if ($startedTransaction) {
            mysql_query("commit");
        }
        $mask = $importRty["rty_TitleMask"];
        // note we use special global array $fields_correspondence - for proper conversion of remote id to concept code
        $res = updateTitleMask($localRtyID, $mask);
        if (!is_numeric($res)) {
            makeLogEntry("Error convertion title mask", $localRtyID, $res);
        }
        $statusMsg = "";
        if (sizeof($importLog) > 0) {
            foreach ($importLog as $logLine) {
                echo $logLine[0] . (intval($logLine[1]) < 0 ? "" : " #" . $logLine[1] . " ") . $logLine[2] . "<br />";
            }
        }
        echo "Successfully imported record type '" . $importRty["rty_Name"] . "' from " . $sourceDBName . "<br />";
        echo "<br />";
        echo "IMPORTED:" . implode(",", $importedRecTypes);
        sendReportEmail($importRty, $localRtyID);
        return $localRtyID;
        // duplicate record found
    } else {
        if (substr(mysql_error(), 0, 9) == "Duplicate") {
            if ($startedTransaction) {
                mysql_query("rollback");
            }
            echo "prompt";
            //general error condition
        } else {
            if (isset($startedTransaction) && $startedTransaction) {
                mysql_query("rollback");
            }
            if (mysql_error()) {
                $statusMsg = "MySQL error: " . mysql_error() . "<br />";
            } else {
                $statusMsg = "Error:<br />";
            }
            if (sizeof($importLog) > 0) {
                foreach ($importLog as $logLine) {
                    $statusMsg .= $logLine[0] . (intval($logLine[1]) < 0 ? "" : " #" . $logLine[1] . " ") . $logLine[2] . "<br />";
                }
                $statusMsg .= "Changes rolled back, nothing was imported";
            }
            // TODO: Delete all information that has already been imported (retrieve from $importLog)
            echo $statusMsg;
        }
    }
}
Ejemplo n.º 2
0
// END - 2009/05/29 - Michael
//put url together
$fqurl = $report_url . "?x=" . $x . "&dir=" . $dir . "&ses=" . $ses . "&form_ses=" . $form_ses . "&r=" . $r . "&thisauth=4887aa210c4f420080724070105&emailer=1";
//create file on server
$pfile = getReportFile($fqurl, $ext);
// BEGIN - 2009/05/29 - Michael
// Check if there was an error getting the report file.
// sendResponse terminates the script.
if (!$pfile) {
    sendResponse("report_error");
}
// END - Michael
//send email
// BEGIN - 2009/05/29
// Check if there was an error sending the email.
if (!sendReportEmail($to, $from, $message, $html = true, $subject, $wordWrap = 120, $pfile, $filename . $ext, $receipt)) {
    sendResponse("email_error");
}
// END - 2009/05/29 - Michael
//debug email
//sendReportEmail('*****@*****.**', '*****@*****.**', $fqurl, $html = true, 'debug', $wordWrap = 120, $pfile, $filename.$ext);
//delete file
@unlink($pfile);
// 2009/05/29 - Michael
sendResponse($form_ses);
//set cookie
function sendReportEmail($to, $from = "*****@*****.**", $content = "nuBuilder Email", $html = false, $subject = "", $wordWrap = 120, $filesource, $filename, $receipt = "false")
{
    $mail = new PHPMailer();
    // BEGIN - 2009/06/09 - Michael
    switch ($GLOBALS["NUMailMethod"]) {
Ejemplo n.º 3
0
function reporteCsv($arrIdCli, $fecha1, $fecha2, $fv)
{
    global $db, $db2;
    //$usuario=getValueTable("Nombre","USUARIO","Id_usuario",$mscIdUsuario);
    //$pais = getValueTable("pais","INFO","id_info",1);
    //$cliente=getValueTable("cliente","D_CLIENTE","id_cliente",$idCliente);
    foreach ($arrIdCli as $idCliente) {
        // --------------------------------------------------------
        // ACTUALZA COBRANZA
        // --------------------------------------------------------
        $sql = "select c.id_calculo as ID_CALCULO, ";
        $sql .= "c.st_tipo_calculo as TIPO_CAL,";
        $sql .= "c.diaLib_usr as DL_APL_USR, ";
        $sql .= "c.libre_dias as DL,";
        $sql .= "c.fecha_vacio as FV,";
        $sql .= "c.id_bl_conte as ID_BL_CONTE ";
        $sql .= "from D_CALCULO c, BL_CONTE bc, EXPO e, BARCO b, D_CLIENTE cc ";
        $sql .= "where ";
        $sql .= "c.id_bl_conte=bc.id_bl_conte and ";
        $sql .= "c.id_cliente='{$idCliente}' and ";
        $sql .= "bc.Id_bl=e.Id_expo and ";
        $sql .= "e.Id_barco=b.Id_barco and ";
        $sql .= "c.id_cliente=cc.id_cliente and ";
        $sql .= "c.dias_demora >= 15 and ";
        $sql .= "c.libre_f1 BETWEEN '{$fecha1}' and '{$fecha2}' ";
        // Morosos
        // $sql.="and c.pago_pendiente_iva > 0 ";
        //$sql.="order by c.id_cliente ";
        $db->query($sql);
        while ($db->next_record()) {
            $idCalculo = $db->f(ID_CALCULO);
            $tipoCal = $db->f(TIPO_CAL);
            //echo "tipo(1): $tipoCal / $idCalculo  / $idCliente<br>";
            if ($tipoCal == "P") {
                $usrAplicoDiasLib = $db->f(DL_APL_USR);
                if ($usrAplicoDiasLib > 0) {
                    $libDias = $db->f(DL);
                    if (!empty($tipoCal)) {
                        $hoy = date("Y-m-d");
                        $fvDb = $db->f(FV);
                        if ($fvDb != $hoy) {
                            calcularDemora($idCalculo, $fv, $tipoCal, $libDias);
                        }
                    }
                } else {
                    $fvDb = $db->f(FV);
                    if ($fvDb != $fv) {
                        calcularDemora($idCalculo, $fv, $tipoCal);
                    }
                }
            }
            // Actualizar pagos realizados y pendientes
            // ----------------------------------------
            $idBlConte = $db->f(ID_BL_CONTE);
            $idBl = getValueTable("id_bl", "BL_CONTE", "id_bl_conte", $idBlConte);
            $idConte = getValueTable("id_contenedor", "BL_CONTE", "id_bl_conte", $idBlConte);
            $pagosRealizados = getMontoPagado($idBl, $idConte);
            $pagosRealizadosTl = getMontoPagadoTl($idBl, $idConte);
            // -------------------------------------------------------
            // IMPORTANTE: Esta funcion puede quitar mucho tiempo de proceso.
            // Pero es importante, ya que trae los pagos realizados por parte del cliente.
            // Asi que no se debe evitar.
            calcularPendientes($idCalculo, $pagosRealizados, $pagosRealizadosTl);
            // -------------------------------------------------------
            $bl = getValueTable("Bl", "EXPO", "Id_expo", $idBl);
            $conte = getValueTable("Numero", "CONTENEDOR", "id_contenedor", $idConte);
        }
    }
    foreach ($arrIdCli as $idCliente) {
        $idEje = getValueTable("id_eje", "D_CLIENTE", "id_cliente", $idCliente);
        switch ($idEje) {
            case "80":
                // Catalina Alonso
                $arrCliCata[] = $idCliente;
                break;
            case "81":
                // Raymundo Perez
                $arrCliRay[] = $idCliente;
                break;
            case "155":
                // Miguel Ramirez
                $arrCliMike[] = $idCliente;
                break;
            case "171":
                // Evaristo Morales
                $arrCliEva[] = $idCliente;
                break;
            case "194":
                // Tona
                $arrCliTona[] = $idCliente;
                break;
            default:
                break;
        }
    }
    require_once '../include/pclzip.lib.php';
    // -----------------------
    // Reportes por Ejecutivos
    // -----------------------
    if (is_array($arrCliCata)) {
        $cliCata = implode(",", $arrCliCata);
        reporteCsvP2($cliCata, 80, $fecha1, $fecha2, $fv);
        // ZIP
        $archive = new PclZip('../files/demPosAba_80.zip');
        $v_list = $archive->add('../files/demPosAba_80.csv', PCLZIP_OPT_ADD_PATH, 'install', PCLZIP_OPT_REMOVE_PATH, 'dev');
        if ($v_list == 0) {
            die("Error : " . $archive->errorInfo(true));
        }
        // EMAIL
        sendReportEmail(80);
        // ELIMINA - BASURA
        unlink("../files/demPosAba_80.zip");
        unlink("../files/demPosAba_80.csv");
    }
    if (is_array($arrCliRay)) {
        $cliRay = implode(",", $arrCliRay);
        reporteCsvP2($cliRay, 81, $fecha1, $fecha2, $fv);
        // ZIP
        $archive = new PclZip('../files/demPosAba_81.zip');
        $v_list = $archive->add('../files/demPosAba_81.csv', PCLZIP_OPT_ADD_PATH, 'install', PCLZIP_OPT_REMOVE_PATH, 'dev');
        if ($v_list == 0) {
            die("Error : " . $archive->errorInfo(true));
        }
        // EMAIL
        sendReportEmail(81);
        // ELIMINA - BASURA
        unlink("../files/demPosAba_81.zip");
        unlink("../files/demPosAba_81.csv");
    }
    if (is_array($arrCliMike)) {
        $cliMike = implode(",", $arrCliMike);
        reporteCsvP2($cliMike, 155, $fecha1, $fecha2, $fv);
        // ZIP
        $archive = new PclZip('../files/demPosAba_155.zip');
        $v_list = $archive->add('../files/demPosAba_155.csv', PCLZIP_OPT_ADD_PATH, 'install', PCLZIP_OPT_REMOVE_PATH, 'dev');
        if ($v_list == 0) {
            die("Error : " . $archive->errorInfo(true));
        }
        // EMAIL
        sendReportEmail(155);
        // ELIMINA - BASURA
        unlink("../files/demPosAba_155.zip");
        unlink("../files/demPosAba_155.csv");
    }
    if (is_array($arrCliEva)) {
        $cliEva = implode(",", $arrCliEva);
        reporteCsvP2($cliEva, 171, $fecha1, $fecha2, $fv);
        // ZIP
        $archive = new PclZip('../files/demPosAba_171.zip');
        $v_list = $archive->add('../files/demPosAba_171.csv', PCLZIP_OPT_ADD_PATH, 'install', PCLZIP_OPT_REMOVE_PATH, 'dev');
        if ($v_list == 0) {
            die("Error : " . $archive->errorInfo(true));
        }
        // EMAIL
        sendReportEmail(171);
        // ELIMINA - BASURA
        unlink("../files/demPosAba_171.zip");
        unlink("../files/demPosAba_171.csv");
    }
    if (is_array($arrCliTona)) {
        $cliTona = implode(",", $arrCliTona);
        reporteCsvP2($cliTona, 194, $fecha1, $fecha2, $fv);
        // ZIP
        $archive = new PclZip('../files/demPosAba_194.zip');
        $v_list = $archive->add('../files/demPosAba_194.csv', PCLZIP_OPT_ADD_PATH, 'install', PCLZIP_OPT_REMOVE_PATH, 'dev');
        if ($v_list == 0) {
            die("Error : " . $archive->errorInfo(true));
        }
        // EMAIL
        sendReportEmail(194);
        // ELIMINA - BASURA
        unlink("../files/demPosAba_194.zip");
        unlink("../files/demPosAba_155.csv");
    }
}