1. Import

This commit is contained in:
2026-03-29 10:34:57 +02:00
parent b0e00c1259
commit a1129565af
4899 changed files with 3007593 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
Datensatzstruktur "import_TOURS":
- Lfd : Numerisch fortlaufend (1..n)
- Tourname : Entweder Tourname/Tourkennung ggfs. mit Präfix (z.B. "T01_") UND
IMMER MIT Tages-Semantik, also z.B. für den 01. Juni 2019 IMMER
"01062019" in den hinteren 8 Zeichen. Das Format ist zwingend
Nachfolgende Stationen können dann leer sein oder identisch.
Folgt eine Änderung in diesem Feld bei einem Datensatz
(z.B."T02_01062019"), dann beginnt ein neuer Auftrag, wobei
dann für diesen die nachfolgenden Zellen der Spalte entwerder
leer oder identisch sein müssen.
Möchte man also nur einen Auftrag in der csv-Datei, definiert
man lediglich die Zelle des 1. Datensatzes mit z.B. "Txx_01062019".
WICHTIG: Das angegebene Datum ist wichtig für den Ausführungstag!
- Optional Kommissionsnummer der Station
- Firma der Station
- Bemerkung (Fahrer) für die Station
- Kennung für Station, kann z.B. für jede Tour durchnummeriert werden ("Auftrags-Lfd.")
Wenn z.B. nur ein Auftrag, also nur eine Tour in der datei, dann entspräche z.B.
diese "Auftrags-Lfd." der Lfd. in der 1. Spalte.
- PLZ der Station
- Stadt der Station
- Strasse der Station
- Hausnr. der Station
Wenn diese leer ist, also z.B. in de Str. mit übergeben wird, dann wird
automatisch ein Punkt (".") hier eingetragen
- Erwartete Abfahrtszeit von der Station
Wird hier eine Zeit eingetragen, wird diese in die Stationsbemerkung geschrieben

View File

@@ -0,0 +1,901 @@
<?php
/*=======================================================================
*
* data_transfer.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
include_once ("../import/import.php");
// Execution-Time for script
set_time_limit(30000);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "f_importFile", "f_uploadFile", "docLocalDirCurrent", "docLocalDirCurrentUpload",
"f_ftp_filename", "ftp_server", "ftp_user_name",
"ftp_user_pass", "ftp_path_dest", "f_ftp_servername", "f_ftp_ssl",
"deactivateMenu", "objType", "objId", "objType_upload", "objId_upload",
"customerId", "cscIdRoot", "cscIdActual"));
// INIT
$dirSpecialForObjType = "";
$fileFilterPrefix = "";
$storedImportFiles = "";
$storedRemoteFiles = "";
// Select user-type for mode of security check
$userType = getFieldValueFromId("user","usr_id",$usr_id,"usr_type");
$userTypeName = getUserTypeName($userType);
$userTypeRAMP = "5";
// Get special user types from parameter
$specialUserTypeIsLoggedIn = false;
$specialUserType = "";
$specialUserHqId = "";
$specialUserFTPServerList = "";
$specialUserDirSpecialForObjType = "";
$userTypesSpecialArray = getDatatransferSpecialUserData($userType);
if (count($userTypesSpecialArray) > 0) :
$specialUserTypeIsLoggedIn = true;
list($specialUserType, $specialUserHqId, $specialUserFTPServerList, $objType, $objId, $specialUserDirSpecialForObjType) = $userTypesSpecialArray;
endif;
// Check for authentication access
$hasRightUpload = false;
$hasRightDownload = false;
$specialStaticDirActive = false;
if ($specialUserTypeIsLoggedIn) :
$specialStaticDirActive = true;
$specialFTPServerList = $specialUserFTPServerList;
// $hasRightUpload = true;
// $hasRightDownload = true;
elseif ($userType == $userTypeRAMP) :
$specialStaticDirActive = true;
$specialFTPServerList = "ITCS";
// $hasRightUpload = true;
// $hasRightDownload = true;
elseif ($userTypeName == "cs") :
$usrAccessArray["cs"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
$hasRightDownload = authCheckEmployeeRights($emp_id, "11");
if (!$hasRightDownload) : gotoReferer("1"); endif;
// Check existence of object type AND object id
if ($objType == "" || $objId == "") : gotoReferer("1"); endif;
// Set object type to "JB" in every case of customer access
$objType = "JB";
// Deactivate menu (!!!!)
$deactivateMenuStatic = "1";
elseif ($userTypeName == "hq") :
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
$hasRightUpload = authCheckEmployeeRights($emp_id, "22");
$hasRightDownload = authCheckEmployeeRights($emp_id, "23");
if (!($hasRightUpload || $hasRightDownload)) : gotoReferer("1"); endif;
endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
if ($userTypeName == "hq") :
$hasRightUpload = true;
$hasRightDownload = true;
endif;
endif;
getLanguage(__FILE__);
$pageTitel = getLngt("DATENIMPORT");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
include_once ("../include/ftp.inc.php");
getCurrentScript(__FILE__);
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
$statusMessage = "";
$importFileStatusMsg = "";
$pageHeadline = getLngt("Allgemeine Dokumente");
// Set root directory regarding the current mandator
$rootDirDefault = "../import/upload/";
$rootDirDefaultLen = strlen($rootDirDefault);
$mdRootDirDefault = getFieldValueFromId("mandator","md_id",$md_id,"md_doc_path");
if ($mdRootDirDefault != "" && substr($mdRootDirDefault, 0,$rootDirDefaultLen) == $rootDirDefault) :
$rootDirDefault = $mdRootDirDefault;
else :
gotoReferer("1");
endif;
$rootDirDefaultLen = strlen($rootDirDefault);
// Set enforced object type regarding to some user types if object type is empty
if ($userTypeName != "hq" && $objType == "") :
if ($userTypeName == "cs") : $objType = "CS"; endif;
if ($userTypeName == "cr") : $objType = "CR"; endif;
if ($userTypeName == "crvh") : $objType = "CRVH"; endif;
if ($userTypeName == "jb") : $objType = "JB"; endif;
if ($userTypeName == "emp") : $objType = "EMP"; endif;
if ($f_act == "uploadFile" && !$specialStaticDirActive) : $f_act = ""; endif;
endif;
// For form parameters only
if ($f_act == "uploadFile") :
$objType = $objType_upload;
$objId = $objId_upload;
endif;
// Map $objType from "CSC" TO "CS" and change object ID containing the "csc_id" to the corresponding "cs_id"
$objType = strtoupper(trim($objType));
if ($objType == "CSC_CS" && $objId != "" && is_numeric($objId)) :
$objType = "CS";
$objId = getFieldValueFromId("costcenter","csc_id",$objId,"cs_id");
endif;
// * SECURITY BEGIN *
// Restriction: Set a fix object type regarding to the uset type
if ($userType == $userTypeRAMP) :
$objType = "RAMP";
endif;
// * SECURITY END *
if ($debug) :
echo "objType : " . $objType . "<br>";
endif;
// Set current directory and check for special object type (e.g. customer = "cs") to define a special subdirectory to be "root"
if ($docLocalDirCurrentUpload != "") :
if ($docLocalDirCurrentUpload != "" && substr($docLocalDirCurrentUpload, 0,$rootDirDefaultLen) == $rootDirDefault) :
$docLocalDirCurrent = $docLocalDirCurrentUpload;
else :
gotoReferer("1");
endif;
endif;
if ($objType != "") :
$dirSpecialForObjType = getParameterValue("0", "DATATRANSFER_DIRECTORY_" . $objType, $hq_id);
if ($dirSpecialForObjType == "") : $dirSpecialForObjType = getParameterValue("0", "DATATRANSFER_DIRECTORY_" . $objType, "0"); endif;
if ($dirSpecialForObjType == "") :
if ($objType == "CS") : $dirSpecialForObjType = "90b1a8efc903576bbb2d6e2a79b00a5e"; endif;
if ($objType == "CR") : $dirSpecialForObjType = "f697836ccbee1a08ff752f5510049f6e"; endif;
if ($objType == "JB") : $dirSpecialForObjType = "a547bc4b2a91355a3aba3ed0827cf6f2"; endif;
if ($objType == "EMP") : $dirSpecialForObjType = "yxj5fr3gz7uau378cf4gh2fcnh67i7gh"; endif;
if ($objType == "CRVH") : $dirSpecialForObjType = "7bb0357ar00a5u89ob1e3c9b2d6e2a79"; endif;
if ($objType == "RAMP") : $dirSpecialForObjType = "traffic_control"; endif;
// Special user type logged in
if ($specialUserTypeIsLoggedIn) : $dirSpecialForObjType = $specialUserDirSpecialForObjType; endif;
endif;
$dirSpecialForObjType .= "/";
// Get parameter for usage the headquarters as sub-paths
$parUseHqPath = getParameterValue("0", "DATATRANSFER_HQ_PATH_" . $objType . "_ENABLED", $hq_id);
if ($parUseHqPath == "") : $parUseHqPath = getParameterValue("0", "DATATRANSFER_HQ_PATH_" . $objType . "_ENABLED", "0"); endif;
// Check for filter according to specified object type and object ID
$fileFilterPrefix = "";
if ($objId != "" && is_numeric($objId)) :
if ($objType == "CS") :
$fileFilterPrefix = getFieldValueFromId("customer","cs_id",$objId,"cs_eid");
$cmpId = getFieldValueFromId("customer","cs_id",$objId,"cmp_id");
if ($cmpId != "") :
$cmpComp = getFieldValueFromId("company","cmp_id",$cmpId,"cmp_comp");
$cmpComp2 = getFieldValueFromId("company","cmp_id",$cmpId,"cmp_comp2");
$pageHeadline = "<span class=\"f12bp1_blue\">" . getLngt("KUNDE") . "</span>&nbsp;&nbsp;&nbsp;&nbsp;" . $fileFilterPrefix . " :: " . $cmpComp . ($cmpComp2 != "" ? " :: " . $cmpComp2 : "");
endif;
endif;
if ($objType == "CR") :
$fileFilterPrefix = getFieldValueFromId("courier","cr_id",$objId,"cr_eid");
$cmpId = getFieldValueFromId("courier","cr_id",$objId,"cmp_id");
if ($cmpId != "") :
$cmpComp = getFieldValueFromId("company","cmp_id",$cmpId,"cmp_comp");
$cmpComp2 = getFieldValueFromId("company","cmp_id",$cmpId,"cmp_comp2");
$pageHeadline = "<span class=\"f12bp1_blue\">" . getLngt("TRANSPORTEUR") . "</span>&nbsp;&nbsp;&nbsp;&nbsp;" . $fileFilterPrefix . " :: " . $cmpComp . ($cmpComp2 != "" ? " :: " . $cmpComp2 : "");
endif;
endif;
if ($objType == "JB") :
$fileFilterPrefix = $objId;
endif;
if ($objType == "EMP") :
$fileFilterPrefix = $objId;
endif;
if ($objType == "CRVH") :
$fileFilterPrefix = $objId;
endif;
if ($objType == "RAMP") :
$fileFilterPrefix = $hq_id;
endif;
endif;
// Check for headquartes
if ($hq_id != "" && $parUseHqPath == "1") :
$hqMnemonic = getFieldValueFromId("headquarters","hq_id",$hq_id,"hq_mnemonic");
if ($hqMnemonic == "") : $hqMnemonic = "MISC" ; endif;
$dirSpecialForObjType .= $hqMnemonic . "/";
endif;
endif;
if ($docLocalDirCurrent == "") :
$docLocalDirCurrent = $rootDirDefault;
$docLocalDirCurrent .= $dirSpecialForObjType;
endif;
// Set current root dir
$rootDirCurrent = $rootDirDefault . $dirSpecialForObjType;
$rootDirCurrentLen = strlen($rootDirCurrent);
$docLocalDirCurrentLen = strlen($docLocalDirCurrent);
$dirSpecialForObjTypeLen = strlen($dirSpecialForObjType);
$fileFilterPrefixLen = strlen($fileFilterPrefix);
// Set FTP or SFTP
if ($f_ftp_ssl == "") : $f_ftp_ssl = ""; endif;
// Get existing FTP server names AND/OR import types
if ($specialStaticDirActive) :
$ftpServerList = $specialFTPServerList;
else :
$ftpServerList = getParameterValue("0", "FTP_IMPORT_SERVERLIST", $hq_id);
if ($ftpServerList == "") :
$ftpServerList = getParameterValue("0", "FTP_IMPORT_SERVERLIST", "0");
endif;
endif;
$ftpServerListArray = array();
$ftpCurrentSelectedServerAccess = false;
if ($userTypeName == "hq" || $specialStaticDirActive) :
if ($ftpServerList != "") :
// Get the list of remote (S)FTP servers
// $ftpServerListArray = spliti(",",$ftpServerList);
// Check for accessability by admin only
$tmpFtpServerListArray = spliti(",",$ftpServerList);
$tmpFtpServerListArrayLen = count($tmpFtpServerListArray);
for ($j = 0; $j < $tmpFtpServerListArrayLen; $j++) :
// Check item to be displayed for all or for admin only
$ftpAdminAccessState = getParameterValue("0", "FTP_DISPLAY_ADMIN_ONLY_" . $tmpFtpServerListArray[$j], "0");
if ($ftpAdminAccessState != "1" || $empHasAdminRights) :
$ftpServerListArray[] = $tmpFtpServerListArray[$j];
endif;
// Check parameter for current item to to have access rights for remote server
if ($f_ftp_servername != "" && $tmpFtpServerListArray[$j] == $f_ftp_servername) :
$ftpAdminAccessState = getParameterValue("0", "FTP_ACCESS_ADMIN_ONLY_" . $tmpFtpServerListArray[$j], "0");
if ($ftpAdminAccessState != "1" || $empHasAdminRights) :
$ftpCurrentSelectedServerAccess = true;
endif;
endif;
endfor;
endif;
endif;
$ftpServerListArrayLen = count($ftpServerListArray);
// If ONLY ONE item does exist AND this entry does NOT having an association to a FTP data set then preselect it
if ($ftpServerListArrayLen == 1 && $f_ftp_servername == "" && $ftp_server == "") :
$f_ftp_servername = $ftpServerListArray[0];
endif;
// Get FTP access data
// "$f_ftp_servername" contains the FTP server name AND/OR the "IMPORT TYPE" (UTA, APO, ...) NOT being associated to a FTP data set stringently (!!!)
if ($f_ftp_servername != "" && $ftp_server == "") :
$ftp_server = getParameterValue("0", "FTP_SERVER_" . $f_ftp_servername, $hq_id);
if ($ftp_server == "") : $ftp_server = getParameterValue("0", "FTP_SERVER_" . $f_ftp_servername, "0"); endif;
if ($ftp_server != "") :
$ftp_user_name = getParameterValue("0", "FTP_USER_" . $f_ftp_servername, $hq_id);
if ($ftp_user_name == "") : $ftp_user_name = getParameterValue("0", "FTP_USER_" . $f_ftp_servername, "0"); endif;
$ftp_user_pass = getParameterValue("0", "FTP_PASSWORD_" . $f_ftp_servername, $hq_id);
if ($ftp_user_pass == "") : $ftp_user_pass = getParameterValue("0", "FTP_PASSWORD_" . $f_ftp_servername, "0"); endif;
$ftp_path_dest = "";
if ($ftpCurrentSelectedServerAccess) :
$ftp_path_dest = getParameterValue("0", "FTP_REMOTEPATH_" . $f_ftp_servername, $hq_id);
if ($ftp_path_dest == "") : $ftp_path_dest = getParameterValue("0", "FTP_REMOTEPATH_" . $f_ftp_servername, "0"); endif;
if ($ftp_path_dest != "") :
// Check subpath especially defined each customer
$remoteSubPath = getParameterValue("0", "FTP_REMOTEPATH_" . $f_ftp_servername . "_" . $objType . "_" . $objId, "0");
if ($remoteSubPath != "") :
$ftp_path_dest .= $remoteSubPath;
endif;
endif;
endif;
endif;
endif;
if ($debug) :
echo "ftpServerList : " . $ftpServerList . "<br>";
echo "ftp_server : " . $ftp_server . "<br>";
echo "f_ftp_servername : " . $f_ftp_servername . "<br>";
echo "ftp_user_name : " . $ftp_user_name . "<br>";
echo "ftp_user_pass : " . $ftp_user_pass . "<br>";
echo "<br><br>";
endif;
// !!!!!!! TEST !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/*
INSERT INTO parameter (par_id, par_key, hq_id, emp_id, par_value, par_text) VALUES (104137, 'FTP_SERVERNAME_UTA', 0, 0, 'UTA', 'FTP server name for UTA');
INSERT INTO parameter (par_id, par_key, hq_id, emp_id, par_value, par_text) VALUES (104127, 'FTP_SERVER_UTA', 0, 0, 'server', 'FTP server for UTA');
INSERT INTO parameter (par_id, par_key, hq_id, emp_id, par_value, par_text) VALUES (104128, 'FTP_USER_UTA', 0, 0, 'u1234567890', 'FTP user for UTA');
INSERT INTO parameter (par_id, par_key, hq_id, emp_id, par_value, par_text) VALUES (104129, 'FTP_PASSWORD_UTA', 0, 0, 'asds1234', 'FTP password for UTA');
INSERT INTO parameter (par_id, par_key, hq_id, emp_id, par_value, par_text) VALUES (104130, 'FTP_REMOTEPATH_UTA', 0, 0, '/uppath/', 'FTP upload path where files will be stored for UTA');
INSERT INTO parameter (par_id, par_key, hq_id, emp_id, par_value, par_text) VALUES (104138, 'FTP_SERVERNAME_AS2_TRANSFER', 0, 0, 'AS2_TRANSFER', 'FTP server name for AS2_TRANSFER');
INSERT INTO parameter (par_id, par_key, hq_id, emp_id, par_value, par_text) VALUES (104132, 'FTP_SERVER_AS2_TRANSFER', 0, 0, '172.16.0.155', 'FTP server for AS2_TRANSFER');
INSERT INTO parameter (par_id, par_key, hq_id, emp_id, par_value, par_text) VALUES (104133, 'FTP_USER_AS2_TRANSFER', 0, 0, 'anonymous', 'FTP user for AS2_TRANSFER');
INSERT INTO parameter (par_id, par_key, hq_id, emp_id, par_value, par_text) VALUES (104134, 'FTP_PASSWORD_AS2_TRANSFER', 0, 0, '', 'FTP password for AS2_TRANSFER');
INSERT INTO parameter (par_id, par_key, hq_id, emp_id, par_value, par_text) VALUES (104135, 'FTP_REMOTEPATH_AS2_TRANSFER', 0, 0, '/download/', 'FTP remote path where files will be stored for AS2_TRANSFER');
if ($f_ftp_servername == "") :
$ftp_server = FTP_SERVER;
$ftp_user_name = FTP_USER;
$ftp_user_pass = FTP_PASSWORD;
$ftp_path_dest = FTP_UPLOADPATH;
endif;
*/
// !!!!!!! TEST !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$ftp_path_dest = trim($ftp_path_dest);
if ($ftp_path_dest != "") :
$ftp_path_dest = urldecode($ftp_path_dest);
endif;
if (substr($ftp_path_dest,0,1) == "/" && substr($ftp_path_dest,-1) == "/") :
$ftp_path_dest = substr($ftp_path_dest,1,-1);
endif;
// Get number of files in the upload folder
$numOfFiles = getNumOfFilesInFolder($docLocalDirCurrent);
if ($debug) :
echo "rootDirDefault : " . $rootDirDefault . " [Länge: " . $rootDirDefaultLen . "]<br>";
echo "rootDirCurrent : " . $rootDirCurrent . " [Länge: " . $rootDirCurrentLen . "]<br>";
echo "docLocalDirCurrent : " . $docLocalDirCurrent . " [Länge: " . $docLocalDirCurrentLen . "]<br>";
echo "dirSpecialForObjType : " . $dirSpecialForObjType . " [Länge: " . $dirSpecialForObjTypeLen . "]<br>";
echo "fileFilterPrefix : " . $fileFilterPrefix . " [Länge: " . $fileFilterPrefixLen . "]<br>";
echo "numOfFiles : " . $numOfFiles . "<br>";
echo "f_ftp_servername_upload : " . $f_ftp_servername_upload . "<br>";
echo "ftpServerList : " . $ftpServerList . "<br>";
echo "f_ftp_servername : " . $f_ftp_servername . "<br>";
echo "ftp_path_dest : " . $ftp_path_dest . "<br>";
echo "<br>";
endif;
// Process uploaded file per HTTP
if ($f_act == "uploadFile") :
$processUpload = true;
// Check for max. of ALL files in path
if ($processUpload) :
$parMaxFiles = getParameterValue("0", "DATATRANSFER_MAX_ALL_FILES_DIRECTORY_" . $objType, $hq_id);
if ($parMaxFiles == "" || !is_numeric($parMaxFiles)) : $parMaxFiles = getParameterValue("0", "DATATRANSFER_MAX_ALL_FILES_DIRECTORY_" . $objType, "0"); endif;
if ($parMaxFiles == "" || !is_numeric($parMaxFiles)) : $parMaxFiles = 500; endif;
if ($numOfFiles >= $parMaxFiles) :
$processUpload = false;
endif;
endif;
// Check for max. of files of the current customer in path
if ($processUpload && $fileFilterPrefix != "") :
$parMaxFiles = getParameterValue("0", "DATATRANSFER_MAX_FILES_SPECIAL_" . $objType, $hq_id);
if ($parMaxFiles == "" || !is_numeric($parMaxFiles)) : $parMaxFiles = getParameterValue("0", "DATATRANSFER_MAX_FILES_SPECIAL_" . $objType, "0"); endif;
if ($parMaxFiles == "" || !is_numeric($parMaxFiles)) : $parMaxFiles = 3; endif;
$objNumOfFiles = getNumOfFilesByFilterInFolder($docLocalDirCurrent, $fileFilterPrefix, "1");
if ($objNumOfFiles >= $parMaxFiles) :
$processUpload = false;
endif;
endif;
// Check for employee rights. Administrators have no restrictions regarding the number of files
if ($empHasAdminRights) : $processUpload = true; endif;
if ($processUpload) :
if ($_FILES['f_uploadFile']['size'] <= 4000000) :
// Append filename for prefix if e.g. a special customer (courier, etc.) has been selected
$uploadPrefix = "";
if ($fileFilterPrefix != "" && substr($_FILES['f_uploadFile']['tmp_name'],0,$fileFilterPrefixLen) != $fileFilterPrefix) :
$uploadPrefix = $fileFilterPrefix . "_";
endif;
// Target filename
$uploadTargetFilename = $_FILES['f_uploadFile']['name'];
// Check prefix of the imported file to be renamed automatically for script execution
$parPrefixRename = getParameterValue("0", "DATATRANSFER_UPLOAD_PREFIX_RENAME", $hq_id);
if ($parPrefixRename == "") : $parPrefixRename = getParameterValue("0", "DATATRANSFER_UPLOAD_PREFIX_RENAME", "0"); endif;
if ($parPrefixRename != "") :
$prefixArray = explode(",", $parPrefixRename);
$uploadTargetFilename = str_replace($prefixArray[0], $prefixArray[1], $uploadTargetFilename);
endif;
if (!move_uploaded_file($_FILES['f_uploadFile']['tmp_name'], $docLocalDirCurrent . $uploadPrefix . $uploadTargetFilename)) :
$statusMessage .= getLngt("Die Datei wurde leider nicht hochgeladen!");
writeToLogDB("97",$hq_id,"",$usr_id,"","","","FILE=" . $_FILES['f_uploadFile']['name'] . "|STATUS=NO_UPLOAD");
else :
writeToLogDB("97",$hq_id,"",$usr_id,"","","","FILE=" . $_FILES['f_uploadFile']['name'] . "|STATUS=OK");
endif;
else :
$statusMessage .= getLngt("Die Datei ist für den Upload zu groß!");
writeToLogDB("97",$hq_id,"",$usr_id,"","","","FILE=" . $_FILES['f_uploadFile']['name'] . "|STATUS=TOO_LARGE");
// Delete real file if does exist
$retVal = removeFile($_FILES['f_uploadFile']['name'], $docLocalDirCurrent, $pathSeparator);
endif;
// Delete temp file if does exist
$retVal = removeFile($_FILES['f_uploadFile']['tmp_name'], $tempPath, $pathSeparator);
// Insert or update in REDUNDANT structure ("gdc") because of performance by displaying lists (customer list, courier list, job list, etc.)!
gdcSetNumberOfDocuments($docLocalDirCurrent, $objType, $objId, $fileFilterPrefix);
else :
$statusMessage .= getLngt("Bevor eine weitere Datei hochgeladen werden kann, muss das Verzeichnis bereinigt werden!");
endif;
endif;
// Manually removal of a specified importfile
if ($f_act == "removeImportfile") :
// Remove import file
$retVal = removeFile($f_importFile, $docLocalDirCurrent, $pathSeparator);
writeToLogDB("183",$hq_id,"",$usr_id,"","","","FILE=" . $f_importFile . "|STATUS=" . $retVal);
if ($retVal == "0") :
elseif ($retVal == "-1") :
$statusMessage = getLngt("Es liegt kein Dateiname vor!");
elseif ($retVal == "-2") :
$statusMessage = getLngt("Die Datei befindet sich nicht mehr in dem Verzeichnis!");
elseif ($retVal == "") :
$statusMessage = getLngt("Es fand keine Löschung statt!");
endif;
// Insert or update in REDUNDANT structure ("gdc") because of performance by displaying lists (customer list, courier list, job list, etc.)!
gdcSetNumberOfDocuments($docLocalDirCurrent, $objType, $objId, $fileFilterPrefix);
endif;
// Upload FTP file
if ($f_act == "ftpUpload") :
if ($f_ftp_filename != "") :
if ($ftp_server != "" && $ftp_user_name != "") :
$tmpArray = ftpUpload($f_ftp_filename, "", $ftp_server, $ftp_user_name, $ftp_user_pass, $docLocalDirCurrent, $ftp_path_dest, $f_ftp_ssl);
if ($tmpArray[0] == "0") :
writeToLogDB("99",$hq_id,"",$usr_id,"","","","FILE=" . $f_ftp_filename . "|SERVER=" . $ftp_server . "|STATUS=OK|ERR=");
// Insert or update in REDUNDANT structure ("gdc") because of performance by displaying lists (customer list, courier list, job list, etc.)!
gdcSetNumberOfDocuments($docLocalDirCurrent, $objType, $objId, $fileFilterPrefix);
else :
$statusMessage = $tmpArray[1];
writeToLogDB("99",$hq_id,"",$usr_id,"","","","FILE=" . $f_ftp_filename . "|SERVER=" . $ftp_server . "|STATUS=NO_UPLOAD|ERR=" . $statusMessage);
endif;
else :
$statusMessage = getLngt("Die Angaben für den Zugriff auf den FTP-Server sind unvollständig!");
// writeToLogDB("99",$hq_id,"",$usr_id,"","","","FILE=" . $f_ftp_filename . "|SERVER=" . $ftp_server . "|STATUS=BAD_CONFIG");
endif;
else :
$statusMessage = getLngt("Die Datei wurde nicht gefunden!");
// writeToLogDB("99",$hq_id,"",$usr_id,"","","","FILE=" . $f_ftp_filename . "|SERVER=" . $ftp_server . "|STATUS=FILE_NOT_FOUND");
endif;
endif;
// Download FTP file
if ($f_act == "ftpDownload") :
if ($f_ftp_filename != "") :
if ($ftp_server != "" && $ftp_user_name != "") :
$tmpArray = ftpDownload($f_ftp_filename, "", $ftp_server, $ftp_user_name, $ftp_user_pass, $docLocalDirCurrent, $ftp_path_dest, $f_ftp_ssl);
if ($tmpArray[0] == "0") :
writeToLogDB("100",$hq_id,"",$usr_id,"","","","FILE=" . $f_ftp_filename . "|SERVER=" . $ftp_server . "|STATUS=OK|ERR=");
// Insert or update in REDUNDANT structure ("gdc") because of performance by displaying lists (customer list, courier list, job list, etc.)!
gdcSetNumberOfDocuments($docLocalDirCurrent, $objType, $objId, $fileFilterPrefix);
else :
$statusMessage = $tmpArray[1];
writeToLogDB("100",$hq_id,"",$usr_id,"","","","FILE=" . $f_ftp_filename . "|SERVER=" . $ftp_server . "|STATUS=NO_DOWNLOAD|ERR=" . $statusMessage);
endif;
else :
$statusMessage = getLngt("Die Angaben für den Zugriff auf den FTP-Server sind unvollständig!");
// writeToLogDB("100",$hq_id,"",$usr_id,"","","","FILE=" . $f_ftp_filename . "|SERVER=" . $ftp_server . "|STATUS=BAD_CONFIG");
endif;
else :
$statusMessage = getLngt("Die Datei wurde nicht gefunden!");
// writeToLogDB("100",$hq_id,"",$usr_id,"","","","FILE=" . $f_ftp_filename . "|SERVER=" . $ftp_server . "|STATUS=FILE_NOT_FOUND");
endif;
endif;
// Delete FTP file
if ($f_act == "ftpDelete") :
if ($f_ftp_filename != "") :
if ($ftp_server != "" && $ftp_user_name != "") :
$tmpArray = ftpDelete($f_ftp_filename, $ftp_server, $ftp_user_name, $ftp_user_pass, $ftp_path_dest, $f_ftp_ssl);
if ($tmpArray[0] != "0") :
$statusMessage = $tmpArray[1];
endif;
else :
$statusMessage = getLngt("Die Angaben für den Zugriff auf den FTP-Server sind unvollständig!");
endif;
else :
$statusMessage = getLngt("Die Datei wurde nicht gefunden!");
endif;
endif;
if ($debug) :
echo "rootDirDefault : " . $rootDirDefault . " [Länge: " . $rootDirDefaultLen . "]<br>";
echo "rootDirCurrent : " . $rootDirCurrent . " [Länge: " . $rootDirCurrentLen . "]<br>";
echo "docLocalDirCurrent : " . $docLocalDirCurrent . " [Länge: " . $docLocalDirCurrentLen . "]<br>";
echo "dirSpecialForObjType : " . $dirSpecialForObjType . " [Länge: " . $dirSpecialForObjTypeLen . "]<br>";
echo "fileFilterPrefix : " . $fileFilterPrefix . " [Länge: " . $fileFilterPrefixLen . "]<br>";
echo "numOfFiles : " . $numOfFiles . "<br>";
echo "f_ftp_servername_upload : " . $f_ftp_servername_upload . "<br>";
echo "ftpServerList : " . $ftpServerList . "<br>";
echo "f_ftp_servername : " . $f_ftp_servername . "<br>";
echo "ftp_path_dest : " . $ftp_path_dest . "<br>";
echo "ftp_server : " . $ftp_server . "<br>";
echo "ftp_user_name : " . $ftp_user_name . "<br>";
echo "ftp_user_pass : " . $ftp_user_pass . "<br>";
echo "<br><br>";
endif;
// **************************************************
// * Read all of the local filenames to be imported *
// **************************************************
if ($userTypeName == "hq" || $userTypeName == "cs" || $specialStaticDirActive) :
$colspan = "3";
// * FILES ON LOCAL SERVER *
// Get filenames
$fileNames = getFilenamesInFolder($docLocalDirCurrent);
$storedImportFiles .= "<table>";
$storedImportFiles .= "<tr><td class=\"f12bp1_blue\" colspan=\"" . $colspan . "\">" . getLngt("votian") . "</td></tr>";
$storedImportFiles .= "<tr><td colspan=\"" . $colspan . "\"><br></td></tr>";
$storedImportFiles .= "<tr><td class=\"f12bn1\" colspan=\"" . $colspan . "\">" . getLngt("Verzeichnis") . ":&nbsp;&nbsp;./" . substr($docLocalDirCurrent, $dirSpecialForObjTypeLen + $rootDirDefaultLen) . "</td></tr>";
$storedImportFiles .= "<tr><td colspan=\"" . $colspan . "\"><br></td></tr>";
// Define table header
$storedImportFiles .= "<tr><td>" . getLngt("Löschen") . "&nbsp;&nbsp;&nbsp;&nbsp;</td><td>" . getLngt("Dateiname") . "&nbsp;&nbsp;&nbsp;&nbsp;</td><td>" . getLngt("WEB-Download") . "&nbsp;&nbsp;&nbsp;&nbsp;</td><td>" . getLngt("FTP-Upload") . "</td></tr>";
$storedImportFiles .= "<tr><td colspan=\"" . $colspan . "\"><br></td></tr>";
// Link to parent directory
$docLocalDirCurrentParent = dirname($docLocalDirCurrent) . "/";
if ($debug) :
echo "docLocalDirCurrentParent : " . $docLocalDirCurrentParent . "<br>";
endif;
if (strlen($docLocalDirCurrent) > $rootDirCurrentLen && substr($docLocalDirCurrentParent,0,$rootDirCurrentLen) == $rootDirCurrent && $docLocalDirCurrentParent != "../" && $docLocalDirCurrentParent != "./") :
$storedImportFiles .= "<tr>";
$docLocalDirCurrentParent = dirname($docLocalDirCurrent) . "/";
$storedImportFiles .= "<td>&nbsp;</td>";
// Enable navigation for headquarter employees only !!!!
if (!$specialStaticDirActive) :
$parMasknavigate = getParameterValue("0", "MASK_DATATRANSFER_NAV2ROOTDIR_ENABLED", $hq_id);
if ($parMasknavigate == "") : $parMasknavigate = getParameterValue("0", "MASK_DATATRANSFER_NAV2ROOTDIR_ENABLED", "0"); endif;
if ($parMasknavigate == "1") :
$storedImportFiles .= "<td><a href=\"javascript:document.forms[0].docLocalDirCurrent.value='" .
urlencode($docLocalDirCurrentParent) . "'; finishPage();\">" . "[..]" .
"</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
endif;
endif;
$storedImportFiles .= "</tr>";
endif;
// Define table body from array
if (!is_array($fileNames)) : $fileNames = array(); endif;
$fileNamesLen = count($fileNames);
for ($j = 0; $j < $fileNamesLen; $j++) :
// Check for predifined directories being not accessible
if (!is_dir($docLocalDirCurrent . $fileNames[$j]) || $empHasAdminRights || checkForPredefinedDirectories($fileNames[$j])) :
if (is_file($docLocalDirCurrent . $fileNames[$j])) :
// Check for filter according to a specified object type and object ID
// Display all files (e.g. of a specified customer, courier, etc.) only
$showFile = true;
if ($fileFilterPrefix != "") :
if (substr($fileNames[$j],0,$fileFilterPrefixLen) != $fileFilterPrefix) :
$showFile = false;
endif;
endif;
if ($showFile) :
$storedImportFiles .= "<tr>";
$storedImportFiles .= "<td align=\"center\">";
if ($specialStaticDirActive || $hasRightUpload) :
$storedImportFiles .= "<a href=\"javascript:removeImportfile('" . $fileNames[$j] . "');\"><img src=\"../images/trash.jpg\" border=\"0\" height=\"13\" width=\"8\"></a>";
endif;
$storedImportFiles .= "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
// Check current filename is prefix of the name of the import script
$activateImportLink = false;
$phraseForActivatingImportScript = "import_" . $f_ftp_servername . "_";
$phraseForActivatingImportScriptLen = strlen($phraseForActivatingImportScript);
if ($fileFilterPrefix == "") :
if (substr($fileNames[$j],0,$phraseForActivatingImportScriptLen) == $phraseForActivatingImportScript) :
$activateImportLink = true;
endif;
else :
if (substr($fileNames[$j],($fileFilterPrefixLen + 1),$phraseForActivatingImportScriptLen) == $phraseForActivatingImportScript) :
$activateImportLink = true;
endif;
endif;
// Show thumbnail
$displayThumbnail = "";
if (strtolower(substr($fileNames[$j],-4)) == ".jpg" || strtolower(substr($fileNames[$j],-4)) == ".png") :
$displayThumbnail = "<img src=\"" . $docLocalDirCurrent . $fileNames[$j] . "\" border=\"0\" height=\"" . "80" . "\" width=\"" . "80" . "\">" . "&nbsp;&nbsp;&nbsp;&nbsp;";
endif;
// Check for existence of a corresponding import script
if (($hasRightUpload || $specialStaticDirActive) && $f_ftp_servername != "" && $activateImportLink && file_exists("../import/import_" . $f_ftp_servername . ".php")) :
$urlClause = "";
if ($objType != "") :
$urlClause = "&objType=" . $objType . "&objId=" . $objId;
endif;
if ($debug) :
echo "urlClause : " . $urlClause . "<br>";
endif;
$storedImportFiles .= "<td style=\"vertical-align:middle\"><a href=\"../import/import_" . $f_ftp_servername . ".php?importFile=" . urlencode($docLocalDirCurrent . $fileNames[$j]) . $urlClause . "\" target=\"_blank\">" . $fileNames[$j] .
"</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;" . $displayThumbnail . "</td>";
else :
$storedImportFiles .= "<td style=\"vertical-align:middle\">" . $fileNames[$j] . "&nbsp;&nbsp;&nbsp;&nbsp;" . $displayThumbnail . "</td>";
endif;
$storedImportFiles .= "<td style=\"text-align:center;vertical-align:middle\">";
if ($specialStaticDirActive || $hasRightUpload || $hasRightDownload) :
$storedImportFiles .= "<a href=\"../include/data_download.php?f_path=" . "EMC2" . substr($docLocalDirCurrent, 2) . "&customerId=" . ec($customerId) . "&cscIdRoot=" . ec($cscIdRoot) .
"&cscIdActual=" . ec($cscIdActual) . "&f_fileName=" . $fileNames[$j] . "&context=DATATRANSFER" . "\" target=\"_blank\">" .
"<img src=\"../images/arrow_down.png\" border=\"0\" height=\"25\" width=\"10\"></a>";
endif;
$storedImportFiles .= "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedImportFiles .= "<td style=\"text-align:center;vertical-align:middle\">";
if ($specialStaticDirActive || $hasRightUpload) :
$storedImportFiles .= "<a href=\"javascript:ftpUpload('" . $fileNames[$j] . "');\"><img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\"></a>";
endif;
$storedImportFiles .= "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedImportFiles .= "</tr>";
endif;
elseif (is_dir($docLocalDirCurrent . $fileNames[$j])) :
$storedImportFiles .= "<tr>";
$storedImportFiles .= "<td>&nbsp;</td>";
$storedImportFiles .= "<td><a href=\"javascript:document.forms[0].docLocalDirCurrent.value='" .
urlencode($docLocalDirCurrent . $fileNames[$j] . "/") . "'; finishPage();\">" . "[" . $fileNames[$j] . "]" .
"</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedImportFiles .= "</tr>";
endif;
endif;
endfor;
$storedImportFiles .= "</table>";
// * REMOTE FTP FILES *
// Get filenames
$fileNames = array();
$tmpErrNo = "";
$tmpErrDesc = "";
if ($ftpCurrentSelectedServerAccess) :
if ($f_ftp_servername != "" && $ftp_server != "" && $f_ftp_ssl != "") :
$tmpArray = ftpDir($ftp_server, $ftp_user_name, $ftp_user_pass, $ftp_path_dest, "", $f_ftp_ssl);
$fileNames = $tmpArray[0]; $tmpErrNo = $tmpArray[1]; $tmpErrDesc = $tmpArray[2];
endif;
endif;
$storedRemoteFiles .= "<table>";
$storedRemoteFiles .= "<tr><td class=\"f12bp1_blue\" colspan=\"" . $colspan . "\">" . getLngt("Externe Daten") . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
$storedRemoteFiles .= " <select class=\"f8np1\" name=\"f_ftp_servername\" onchange=\"ftpSelectEnvironment();\">";
$storedRemoteFiles .= " <option value=\"\">" . getLngt("Keine Auswahl") . "</option>";
for ($k = 0; $k < $ftpServerListArrayLen; $k++) :
$storedRemoteFiles .= " <option value=\"" . $ftpServerListArray[$k] . "\" " . ($f_ftp_servername == $ftpServerListArray[$k] ? "selected" : "") . ">" . getLngt($ftpServerListArray[$k]) . "</option>";
endfor;
$storedRemoteFiles .= " </select>&nbsp;&nbsp;";
$storedRemoteFiles .= " <select class=\"f8np1\" name=\"f_ftp_ssl\" onchange=\"ftpSelectEnvironment();\">";
$storedRemoteFiles .= " <option value=\"\" " . ($f_ftp_ssl == "" ? "selected" : "") . ">" . getLngt("Protokoll:") . "</option>";
$storedRemoteFiles .= " <option value=\"0\" " . ($f_ftp_ssl == "0" ? "selected" : "") . ">" . getLngt("FTP") . "</option>";
$storedRemoteFiles .= " <option value=\"1\" " . ($f_ftp_ssl == "1" ? "selected" : "") . ">" . getLngt("FTPS") . "</option>";
$storedRemoteFiles .= " <option value=\"2\" " . ($f_ftp_ssl == "2" ? "selected" : "") . ">" . getLngt("SFTP") . "</option>";
$storedRemoteFiles .= " </select>";
$storedRemoteFiles .= "</td></tr>";
$storedRemoteFiles .= "<tr><td colspan=\"" . $colspan . "\"><br></td></tr>";
$storedRemoteFiles .= "<tr><td class=\"f12bn1\" colspan=\"" . $colspan . "\">" . getLngt("Verzeichnis") . ":&nbsp;&nbsp;" . ($ftp_path_dest != "" ? "../" . $ftp_path_dest : "./") . "</td></tr>";
$storedRemoteFiles .= "<tr><td colspan=\"" . $colspan . "\"><br></td></tr>";
// Define table header
$storedRemoteFiles .= "<tr><td>" . getLngt("FTP-Download") . "&nbsp;&nbsp;&nbsp;&nbsp;</td><td>" . getLngt("Dateiname") . "&nbsp;&nbsp;&nbsp;&nbsp;</td><td>" . getLngt("Löschen") . "</td></tr>";
$storedRemoteFiles .= "<tr><td colspan=\"" . $colspan . "\"><br></td></tr>";
if ($ftpCurrentSelectedServerAccess) :
if ($tmpErrNo == "0") :
// Define table body from array
$fileNamesLen = count($fileNames);
for ($j = 0; $j < $fileNamesLen; $j++) :
$storedRemoteFiles .= "<tr>";
$storedRemoteFiles .= "<td align=\"center\"><a href=\"javascript:ftpDownload('" . $fileNames[$j] . "');\">"
. "<img src=\"../images/arrow_left.png\" border=\"0\" height=\"10\" width=\"25\">"
. "</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedRemoteFiles .= "<td>" . $fileNames[$j] . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedRemoteFiles .= "<td align=\"center\"><a href=\"javascript:ftpDelete('" . $fileNames[$j] . "');\">"
. "<img src=\"../images/trash.jpg\" border=\"0\" height=\"13\" width=\"8\">"
. "</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedRemoteFiles .= "</tr>";
endfor;
else :
// "$f_ftp_servername" contains the FTP server name AND/OR the "IMPORT TYPE" (UTA, APO, ...) NOT being associated to a FTP data set stringently (!!!)
if ($f_ftp_servername != "" && $ftp_server == "") :
$storedRemoteFiles .= "<tr><td class=\"f10bp1_blue\" colspan=\"" . $colspan . "\">" . getLngt("Keine FTP-Konfigurationsdaten hinterlegt") . "</td></tr>";
else :
$storedRemoteFiles .= "<tr><td class=\"f10bp1_red\" colspan=\"" . $colspan . "\">" . getLngt($tmpErrDesc) . "</td></tr>";
endif;
endif;
endif;
$storedRemoteFiles .= "</table>";
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<style type="text/css">
<?php include_once ("../css/phoenix.css.php"); ?>
<?php include_once ("../css/navigation.css.php"); ?>
<?php include_once ("../css/mc.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPage(f_act_value) {
document.forms[0].f_act.value=f_act_value;
document.forms[0].submit();
};
function ftpSelectEnvironment() {
document.forms[0].ftp_server.value = '';
document.forms[0].ftp_user_name.value = '';
document.forms[0].ftp_user_pass.value = '';
document.forms[0].ftp_path_dest.value = '';
document.forms[0].submit();
}
function ftpUpload(fileName) {
document.forms[0].f_ftp_filename.value = fileName;
finishPage('ftpUpload');
};
function ftpDownload(fileName) {
document.forms[0].f_ftp_filename.value = fileName;
finishPage('ftpDownload');
};
function ftpDelete(fileName) {
document.forms[0].f_ftp_filename.value = fileName;
finishPage('ftpDelete');
};
function removeImportfile(fileName) {
if (confirm('<?php echo getLngt("Importdatei") ?> ' + fileName + ' <?php echo getLngt("entfernen?") ?>')) {
document.forms[0].f_importFile.value = fileName;
finishPage('removeImportfile');
};
};
function finishPageUpload(f_act_value) {
document.forms[1].f_act.value=f_act_value;
document.forms[1].submit();
};
// File upload
document.addEventListener('DOMContentLoaded', () => {
const fileInput = document.getElementById('fileUpload');
const fileNameDisplay = document.getElementById('fileName');
fileInput.addEventListener('change', () => {
if (fileInput.files.length > 0) {
fileNameDisplay.textContent = fileInput.files[0].name;
} else {
fileNameDisplay.textContent = 'Keine Datei ausgewählt';
}
});
});
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>displayStatusMessage();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<?php if ($pageHeadline != "") : ?>
<div class="mc_page-header" id="mc_page-header">
<?php echo $pageHeadline ?>
</div>
<?php endif ?>
<div class="maincontent mc_elem" style="height: auto;" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/data_transfer.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="docLocalDirCurrent" value="<?php echo $docLocalDirCurrent; ?>">
<input type="hidden" name="f_importFile" value="">
<input type="hidden" name="f_ftp_filename" value="">
<input type="hidden" name="ftp_server" value="<?php echo $ftp_server; ?>">
<input type="hidden" name="ftp_user_name" value="<?php echo $ftp_user_name; ?>">
<input type="hidden" name="ftp_user_pass" value="<?php echo $ftp_user_pass; ?>">
<input type="hidden" name="ftp_path_dest" value="<?php echo urlencode($ftp_path_dest); ?>">
<input type="hidden" name="objType" value="<?php echo urlencode($objType); ?>">
<input type="hidden" name="objId" value="<?php echo urlencode($objId); ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<div>
<table width="98%">
<tr>
<td width="49%" style="border: 1px solid var(--primary-color); border-collapse: collapse; padding: 8px; vertical-align:top;">
<?php echo $storedImportFiles; ?>
</td>
<td width="49%" style="border: 1px solid var(--primary-color); border-collapse: collapse; padding: 8px; vertical-align:top;">
<?php echo $storedRemoteFiles; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
<?php echo htmlDivLineSpacer("15px"); ?>
</div>
<?php if ($specialStaticDirActive || ($userTypeName == "hq" && $hasRightUpload)) : ?>
<div class="maincontent mc_elem" name="maincontent" id="maincontent">
<div class="mc_page-header">
<?php echo getLngt("W&auml;hlen Sie eine lokale Datei auf Ihrem Rechner aus:") ?>
</div>
<?php echo htmlDivLineSpacer("10px"); ?>
<div>
<form id="uploadForm" action="../import/data_transfer.php" enctype="multipart/form-data" method="post">
<input type="hidden" name="f_act" value="">
<input type="hidden" name="MAX_FILE_SIZE" value="4000000">
<input type="hidden" name="docLocalDirCurrentUpload" value="<?php echo htmlspecialchars($docLocalDirCurrent, ENT_QUOTES, 'UTF-8'); ?>">
<input type="hidden" name="objType_upload" value="<?php echo htmlspecialchars($objType, ENT_QUOTES, 'UTF-8'); ?>">
<input type="hidden" name="objId_upload" value="<?php echo htmlspecialchars($objId, ENT_QUOTES, 'UTF-8'); ?>">
<div class="file-upload-wrapper">
<label for="fileUpload" class="file-upload-label">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="17 8 12 3 7 8"></polyline><line x1="12" y1="3" x2="12" y2="15"></line></svg>
<span>Datei auswählen...</span>
</label>
<input id="fileUpload" name="f_uploadFile" type="file" accept="text/*">
<span id="fileName" class="file-name">Keine Datei ausgewählt</span>
</div>
<?php echo defineButtonType10(getLngt("Upload"), "action_upload", "finishPageUpload('uploadFile');", "100", "left", "0"); ?>
<br><br>
<?php echo $importFileStatusMsg; ?>
</form>
</div>
</div>
<?php endif; ?>
</body>
</html>

67
html/import/import.php Normal file
View File

@@ -0,0 +1,67 @@
<?php
/*=======================================================================
*
* import.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
include_once ("../include/mcglobal.inc.php");
include_once ("../include/auth.inc.php");
if (!isset($doNotIncludeGeocode)) :
include_once ("../geo/geocode.inc.php");
endif;
// *************************
// * INITIALISIERUNGSDATEN *
// *************************
$pathSeparator = "/";
$importType = "";
$importPath = "../import/upload/";
$tempPath = "../temp/upload/";
$logFile = "../import/import.log";
$delimiter = "|";
$write2logfile = "1";
$currentTime = getDateTime("0");
include_once ("../include/inc_file.inc.php");
// Converts STR to DATE
function cStr2Date ($str, $mode = "") {
if ($mode == "1") :
// Default: "d.m.Y" => "Y-m-d"
$str = substr($str,6,4) . "-" . substr($str,3,2) . "-" . substr($str,0,2);
elseif ($mode == "2") :
// "d.m.Y H:i" => "Y-m-d H:i:s" 09.08.2011 06:30
$str = substr($str,6,4) . "-" . substr($str,3,2) . "-" . substr($str,0,2) . " " . substr($str,11,2) . ":" . substr($str,14,2) . ":" . "00";
else :
// Default: "dmY" => "Y-m-d"
$str = substr($str,4,4) . "-" . substr($str,2,2) . "-" . substr($str,0,2);
endif;
return $str;
}
// Converts STR to FLOAT (with ".") [e.g.: 000011122 => 111.22 with 2 decimals]
function cStr2Float ($str, $decimals = "2") {
if (is_numeric($str)) :
$numberPrefix = substr($str, 0, strlen($str) - $decimals);
$numberSuffix = substr($str, strlen($str) - $decimals, $decimals);
while (substr($numberPrefix,0,1) == "0" && strlen($numberPrefix) > 0) {
$numberPrefix = substr($numberPrefix,1);
}
$str = $numberPrefix . "." . $numberSuffix;
endif;
return $str;
}
?>

View File

@@ -0,0 +1,755 @@
<?php
/*=======================================================================
*
* import_ALLERGO.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
include_once ("../include/services_func.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csId = "";
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
$csAddress = array();
$adIdFrom = 0;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
// $csAddress = getAddress($csId, "customer");
$csAddress = getAddress($csId, "costcenteraddress");
$adIdFrom = $csAddress["id"];
$trHsnoFrom = $csAddress["hsno"];
if ($trHsnoFrom == "") : $trHsnoFrom = "."; endif;
$trCompFrom = $csAddress["comp"];
if ($trCompFrom == "") : $trCompFrom = "STANDARD_02"; endif;
$trFloorFrom = "";
// USE FOLLOWING FIX ADDRESS
// $adIdFrom = "220594"; // Invoice address
// $adIdFrom = "125964"; // Pick-up address
// $trHsnoFrom = "4";
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
// Init
$jbIdNew = "";
$jbTourdata = "";
$jbTourdataZipcode = "";
$jbTourdataCity = "";
$jbTourdataCountry = "";
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strrpos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
/*
$tourVehicleArray = array();
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
*/
$tourCourierArray = array();
/*
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
$tourCourierArray["294505"] = "e8020205";
$tourCourierArray["294506"] = "e8020206";
$tourCourierArray["294507"] = "e8020207";
$tourCourierArray["294508"] = "e8020208";
$tourCourierArray["294509"] = "e8020209";
$tourCourierArray["294510"] = "e8020210";
$tourCourierArray["294511"] = "e8020211";
$tourCourierArray["294512"] = "e8020212";
$tourCourierArray["294590"] = "e8020213";
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
return $aStr;
}
echo "importFile" . $importFile . "<br>";
echo "hqId" . $hqId . "<br>";
echo "csId" . $csId . "<br>";
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_ALLERGO_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$jbIdNew = 0;
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_ALLERGO_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
/*
transcode 0,"020" N 3.0 0: Transaction Code X
transid 1,"001" A 30 1: Transaction ID (primary - Schlüsselfeld - ) X
absender 4 A 35 4: Absender Firmenname (oder Feld 32)
absid 31,"SENDERID A 35 31: Sender ID
abskontakt 32,"A. Mehlinger" A 35 32: Absender Kontaktperson (oder Feld 4)
absans1 5,"Langer Kornweg 43k" A 35 5: Absender Anschrift 1 X
absans2 6,"Geb. 43" A 35 6: Absender Anschrift 2
absort 7,"Kelsterbach" A 35 7: Absender Ort X
absplz 9,"65451" A 10 9: Absender Postleitzahl X
kdnrabs 10,"111111111" N 9.0 10: Stadtbote Kundennummer Absender X
absland ACHTUNG! Steht NICHT in der Schnittstellenbeschreibung, ist aber eine Spalte der mitgelieferten Beispieldatei!
abstel 183,"061079370" A 15 183: Absender Telefonnummer X
absunters 1150,"A. Mehlinger" A 35 1150: Absender Unterschrift X
empname 11 A 35 11: Empfänger Firmenname (oder Feld 12)
empkontakt 12,"Mr. Contact" A 35 12: Empfänger Kontaktperson (oder Feld 11)
empans1 13,"Prestwick Drive" A 35 13: Empfänger Anschrift 1 X
empans2 14,"Bldg. 118" A 35 14: Empfänger Anschrift 2
emport 15,"Memphis" A 35 15: Empfänger Ort X
empbsp 16,"TN" A 2 16: Empfänger Bundesstaat/Provinz
empplz 17,"38191" A 10 17: Empfänger Postleitzahl X
emptel 18,"9012331789" A 15 18: Empfänger Telefonnummer X
kdnrfz ACHTUNG! Steht NICHT in der Schnittstellenbeschreibung, ist aber eine Spalte der mitgelieferten Beispieldatei!
comuw 4129,"5000000" N 16. 111111 4129: commodity unit weight X
fzahler 23,"1" N 1.0 23: Frachtzahler X
vdatum 24,"20100322" N 8 24: Versanddatum YYYYMMDD
referenz 25,"CC: DEU12345" A 35 25: Referenz X
pakh 57-1,"10" N 3.0 57: Pakethöhe in cm kann entfallen
pakb 58-1,"20" N 3.0 58: Paketbreite in cm kann entfallen
pakl 59-1,"30" N 3.0 59: Paketlänge in cm kann entfallen
waehrg 68,"EUR" A 3 68: Währung X
geweinh 75,"KGS" A 3 75: Gewichtseinheit X
commw 77,"50" N 8 77: Commodity weight kann entfallen
produkt 79-1,"Computer Spareparts" A 148 79: Inhalt / Produktbeschreibung X
comminfl 113,"Y" A 1 113: commercial invoice flag (bedingt Feld 1681)
packanz 116,"1" N 7.0 116: Anzahl Packstücke X
doksend 190,"N" B 1 190:Dokumentensendung kann entfallen
verpack 1273,"1" N 2.0 1273: Verpackung X
servart 1274,"1" N 2.0 1274: Serviceart X
rsamail 1202,"reci@reci.com" A 60 1202: Recipient ship alert Email X
endtr 99,"" A 2 99: Ende einer Transaktion X
paketnr A 15 - vom Versandunternehmen vergebene Nr. des Paketes
empfdatum N 8 gewünschtes Zustelldatum YYYYMMDD
zustelldatum N 8 Datum der Zustellung YYYYMMDD
zustellzeit A 5 Zeitpunkt der Zustellung (Bsp.: 15:30)
kuriernr Debitorennr. Kurier- Info ans Lager
aend Timestamp Datum und Zeit der letzten Änderung
*/
$rowToImport[0] = "transcode"; // A
$rowToImport[1] = "transid"; // B
$rowToImport[2] = "absender"; // C
$rowToImport[3] = "absid"; // D
$rowToImport[4] = "abskontakt"; // E
$rowToImport[5] = "absans1"; // F
$rowToImport[6] = "absans2"; // G
$rowToImport[7] = "absort"; // H
$rowToImport[8] = "absplz"; // I
$rowToImport[9] = "kdnrabs"; // J
$rowToImport[10] = "absland"; // K
$rowToImport[11] = "abstel"; // L
$rowToImport[12] = "absunters"; // M
$rowToImport[13] = "empname"; // N
$rowToImport[14] = "empkontakt"; // O
$rowToImport[15] = "empans1"; // P
$rowToImport[16] = "empans2"; // Q
$rowToImport[17] = "emport"; // R
$rowToImport[18] = "empbsp"; // S
$rowToImport[19] = "empplz"; // T
$rowToImport[20] = "emptel"; // U
$rowToImport[21] = "kdnrfz"; // V
$rowToImport[22] = "comuw"; // W
$rowToImport[23] = "fzahler"; // X
$rowToImport[24] = "vdatum"; // Y
$rowToImport[25] = "referenz"; // Z
$rowToImport[26] = "pakh"; // AA
$rowToImport[27] = "pakb"; // AB
$rowToImport[28] = "pakl"; // AC
$rowToImport[29] = "waehrg"; // AD
$rowToImport[30] = "geweinh"; // AE
$rowToImport[31] = "commw"; // AF
$rowToImport[32] = "produkt"; // AG
$rowToImport[33] = "comminfl"; // AH
$rowToImport[34] = "packanz"; // AI
$rowToImport[35] = "doksend"; // AJ
$rowToImport[36] = "verpack"; // AK
$rowToImport[37] = "servart"; // AL
$rowToImport[38] = "rsamail"; // AM
$rowToImport[39] = "endtr"; // AN
$rowToImport[40] = "paketnr"; // AO
$rowToImport[41] = "empfdatum"; // AP
$rowToImport[42] = "zustelldatum"; // AQ
$rowToImport[43] = "zustellzeit"; // AR
$rowToImport[44] = "kuriernr"; // AS
$rowToImport[45] = "aend"; // AT
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_jb_tourname = "ALLERGO"; // In the beginning constant because import into single job!
$f_transcode = mcStrWrap($transcode);
$f_transid = mcStrWrap($transid);
$f_tr_comp_sender = mcStrWrap($absender);
$f_tr_comp2_sender = "";
$f_absid = mcStrWrap($absid);
$f_tr_person_sender = mcStrWrap($abskontakt);
$f_absans1 = mcStrWrap($absans1);
$f_absans2 = mcStrWrap($absans2);
$f_ad_city_sender = mcStrWrap($absort);
$f_ad_zipcode_sender = mcStrWrap($absplz);
$f_kdnrabs = mcStrWrap($kdnrabs);
$f_ad_country_sender = mcStrWrap($absland);
$f_tr_phone_sender = mcStrWrap($abstel);
$f_tr_signname_sender = mcStrWrap($absunters);
$f_tr_comp = mcStrWrap($empname);
$f_tr_person = mcStrWrap($empkontakt);
$f_empans1 = mcStrWrap($empans1);
$f_empans2 = mcStrWrap($empans2);
$f_ad_city = mcStrWrap($emport);
$f_ad_country = mcStrWrap($empbsp);
$f_ad_zipcode = mcStrWrap($empplz);
$f_tr_phone = mcStrWrap($emptel);
$f_kdnrfz = mcStrWrap($kdnrfz);
$f_comuw = mcStrWrap($comuw);
$f_fzahler = mcStrWrap($fzahler);
$f_vdatum = mcStrWrap($vdatum);
$f_referenz = mcStrWrap($referenz);
$f_pakh = mcStrWrap($pakh);
$f_pakb = mcStrWrap($pakb);
$f_pakl = mcStrWrap($pakl);
$f_currency = mcStrWrap($waehrg);
$f_geweinh = mcStrWrap($geweinh);
$f_commw = mcStrWrap($commw);
$f_produkt = mcStrWrap($produkt);
$f_comminfl = mcStrWrap($comminfl);
$f_trat_packingpieces = mcStrWrap($packanz);
$f_doksend = mcStrWrap($doksend);
$f_verpack = mcStrWrap($verpack);
$f_servart = mcStrWrap($servart);
$f_rsamail = mcStrWrap($rsamail);
$f_endtr = mcStrWrap($endtr);
$f_paketnr = mcStrWrap($paketnr);
// $f_jb_orderdate = mcStrWrap($empfdatum);
$f_jb_orderdate = ""; // Init empty => "today"
// $f_jb_warningdate = mcStrWrap($zustelldatum);
$f_jb_warningdate = ""; // Init empty => "today"
// $f_clocktimewarning = mcStrWrap($zustellzeit);
$f_clocktimewarning = ""; // Init empty => Default warning time
$f_kuriernr = mcStrWrap($kuriernr);
$f_aend = mcStrWrap($aend);
// Check for existing headline
if ($j > 0) :
$f_tr_remark = ""; // Init
$f_tr_remark .= "Sender&nbsp;ID: " . $f_absid . "<br>";
$f_tr_remark .= "Kd-Nr.&nbsp;Abs.: " . $f_kdnrabs . "<br>";
$f_tr_remark .= "Kd-Nr.&nbsp;Fz.: " . $f_kdnrfz . "<br>";
$f_tr_remark .= "Gewichtseinheit: " . $f_comuw . "<br>";
$f_tr_remark .= "Frachtzahler: " . $f_fzahler . "<br>";
$f_tr_remark .= "Versanddatum: " . $f_vdatum . "<br>";
$f_tr_remark .= "Referenz: " . $f_referenz . "<br>";
$f_tr_remark .= "Paketmaße&nbsp;(LxBxH): " . $f_pakl . "&nbsp;x&nbsp;" . $f_pakb . "&nbsp;x&nbsp;" . $f_pakh . "<br>";
// $f_tr_remark .= "Währung: " . $f_currency . "<br>";
$f_tr_remark .= "Gewichtseinheit: " . $f_geweinh . "<br>";
$f_tr_remark .= "Warengewicht: " . $f_commw . "<br>";
$f_tr_remark .= "Produktbeschreibung: " . $f_produkt . "<br>";
$f_tr_remark .= "Rechnungs-Flag: " . $f_comminfl . "<br>";
$f_tr_remark .= "Anz.&nbsp;Packstücke: " . $f_trat_packingpieces . "<br>";
$f_tr_remark .= "Dokumentensendung: " . $f_doksend . "<br>";
$f_tr_remark .= "Verpackung: " . $f_verpack . "<br>";
$f_tr_remark .= "Serviceart: " . $f_servart . "<br>";
// $f_tr_remark .= "Alarm-Mail: " . $f_rsamail . "<br>";
// $f_tr_remark .= "Transaktionsende: " . $f_endtr . "<br>";
$f_tr_remark .= "Paketnr.&nbsp;Versand-UN: " . $f_paketnr . "<br>";
// $f_tr_remark .= "Kuriernr.: " . $f_kuriernr . "<br>";
$f_tr_remark .= "Letzte&nbsp;Änderung: " . $f_aend . "<br>";
$f_ad_street_sender = trim($f_absans1 . " " . $f_absans2);
$f_tr_hsno_sender = "";
if ($f_tr_hsno_sender == "") :
$f_tr_hsno_sender = ".";
endif;
$f_ad_street = trim($f_empans1 . " " . $f_empans2);
$f_tr_hsno = "";
if ($f_tr_hsno == "") :
$f_tr_hsno = ".";
endif;
$clockTime = " 16:00:00";
if ($f_jb_orderdate == "") :
$f_jb_orderdate = $currentDate;
else :
$f_jb_orderdate = substr($f_jb_orderdate,0,4) . "-" . substr($f_jb_orderdate,4,2) . "-" . substr($f_jb_orderdate,6,2);
endif;
$f_jb_ordertime = $f_jb_orderdate . " " . $clockTime;
$clockTimeWarning = " 20:00:00";
if ($f_jb_warningdate == "") :
$f_jb_warningdate = $currentDate;
else :
$f_jb_warningdate = substr($f_jb_warningdate,0,4) . "-" . substr($f_jb_warningdate,4,2) . "-" . substr($f_jb_warningdate,6,2);
endif;
if ($f_clocktimewarning != "") :
$clockTimeWarning = $f_clocktimewarning .= ":00";
endif;
$f_jb_warningtime = $f_jb_warningdate . " " . $clockTimeWarning;
// The first row of the tour contains the tour name. The following rows of the same tour are empty for $f_jb_tourname !!!!
if ($f_jb_tourname == "") :
$f_jb_tourname = $remTourNo;
endif;
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_jb_tourname];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
*/
$crEid = $tourCourierArray[$f_jb_tourname];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
endif;
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
$jbStatus = "1";
$jbTaketime = $currentTime;
endif;
$jbType = "";
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo $f_jb_tourname . ";" . $f_transcode . ";" . $f_transid . ";";
echo "<br>";
// Check for existence of the imported "transid" (unique for station)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","info_0","gdc_content",$f_transid,"gdc_context","ALLERGO"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if ALLERGO number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = true;
if ($remTourNo == "" || $remTourNo == $f_jb_tourname) :
if ($jbTourdataZipcode != "") : $jbTourdataZipcode .= ";"; endif;
$jbTourdataZipcode .= $f_ad_zipcode;
if ($jbTourdataCity != "") : $jbTourdataCity .= ";"; endif;
$jbTourdataCity .= $f_ad_city;
if ($jbTourdataCountry != "") : $jbTourdataCountry .= ";"; endif;
$jbTourdataCountry .= "DE";
endif;
// Insert address
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_jb_tourname) :
// Finalize currently imported job
// Write "jb_tourdata" of the job currently imported
if ($remTourNo != "" && $jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// Remove existing tourname
updateStmt("job","jb_tourname",$f_jb_tourname,array("jb_tourname",""), "jb_tourname = '" . $f_jb_tourname . "'");
// Tour data
/*
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
*/
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
$jbIdNew = ""; // Init
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbIdNew = getLastInsertId();
if ($jbIdNew != "") :
// Insert sender address
$tmpArray = insertAddress($f_ad_street_sender, $f_ad_zipcode_sender, $f_ad_city_sender, "", $f_ad_country_sender, $noValidationOfAddress);
$ad_id_sender_new = $tmpArray[0];
if ($ad_id_sender_new == "") :
$ad_id_sender_new = $adIdFrom;
$f_tr_hsno_sender = $trHsnoFrom;
endif;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_sender_new, "tr_sort", "1", "tr_comp", my_str_check($f_tr_comp_sender), "tr_comp2", my_str_check($f_tr_comp2_sender),
"tr_hsno", $f_tr_hsno_sender, "csc_id", $cscIdPayer, "tr_status", "1", "tr_signname", $f_tr_signname_sender,
"tr_finishtime", $jbFinishtime, "tr_commission_no", $trCommissionNo, "tr_person", $f_tr_person_sender, "tr_phone", $f_tr_phone_sender));
if ($trsPrice != 0) :
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", "0",
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $trsPrice, "trs_discount", $csDiscount));
endif;
if ($servicePrice != 0) :
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", "0",
"srv_id", "0", "trs_srv_name", "Servicepreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $servicePrice, "trs_discount", "0"));
endif;
endif;
$trSort = 1; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$remTourNo = $f_jb_tourname;
// Init for the next job to be imported
$jbTourdata = "";
// Init with current values
$jbTourdataZipcode = $f_ad_zipcode;
$jbTourdataCity = $f_ad_city;
$jbTourdataCountry = "DE";
endif;
// Check for inserted job
if ($jbIdNew != "") :
$trSort++;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", my_str_check($f_tr_comp), "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
// Insert tourservice data
/*
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
*/
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort, "srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "", "trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// Tourname
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_0", "gdc_content", $f_transid, "gdc_context", "ALLERGO"));
// Insert tourarticle data (delivery stations)
/*
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
*/
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
/*
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
*/
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $$f_jb_tourname . " " . $f_tr_sort . "]<br>";
endif;
endif; // Check for headline
}
// If at least onne imported job does exist ($jbIdNew > 0) then finalize last imported job
// Write "jb_tourdata" of the job currently imported
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_ALLERGO.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

319
html/import/import_APO.php Normal file
View File

@@ -0,0 +1,319 @@
<?php
/*=======================================================================
*
* import_APO.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
include_once ("../import/import.php");
// Execution-Time for script
set_time_limit(30000);
// Get the rights of the employee logged in and check the accessibility
authCheckEmployeeRights($emp_id, "22", "1");
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT APO");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
// Converts STR to DATE
function cStr2Date ($str, $mode = "") {
if ($mode == "1") :
// Default: "d.m.Y" => "Y-m-d"
$str = substr($str,6,4) . "-" . substr($str,3,2) . "-" . substr($str,0,2);
elseif ($mode == "2") :
// "d.m.Y H:i" => "Y-m-d H:i:s" 09.08.2011 06:30
$str = substr($str,6,4) . "-" . substr($str,3,2) . "-" . substr($str,0,2) . " " . substr($str,11,2) . ":" . substr($str,14,2) . ":" . "00";
else :
// Default: "dmY" => "Y-m-d"
$str = substr($str,4,4) . "-" . substr($str,2,2) . "-" . substr($str,0,2);
endif;
return $str;
}
// Converts STR to FLOAT (with ".") [e.g.: 000011122 => 111.22 with 2 decimals]
function cStr2Float ($str, $decimals = "2") {
if (is_numeric($str)) :
$numberPrefix = substr($str, 0, strlen($str) - $decimals);
$numberSuffix = substr($str, strlen($str) - $decimals, $decimals);
while (substr($numberPrefix,0,1) == "0" && strlen($numberPrefix) > 0) {
$numberPrefix = substr($numberPrefix,1);
}
$str = $numberPrefix . "." . $numberSuffix;
endif;
return $str;
}
if ($importFile != "") :
$importFile = urldecode($importFile);
if (file_exists($importFile)) :
$f_numOfRows = 0;
$f_checksum = 0;
$currentTime = getDateTime("0");
// *******************
// * Import APO data *
// *******************
if ($executeImportProcess == "1") :
$outText .= getLngt("IMPORTDATEI:") . "&nbsp;" . $importFile . "<br><br>";
// "Nr","Apotheke","Tour","Tourdatum","Tourzeit","Anrede","Vorname","Nachname","PLZ","Ort","Ortsteil","Strasse","Land","Telefon","Offene Kredite","Lieferhinweis","Bediener"
// 187,"AP90DEVVSPOS (9999010)","Morgentour Mo-Fr 06:30 09:00",09.08.2011,06:30,,"Urmel","Ka aus dem Eis",12345,"Titiwu",,"Im Holzhaus 1",,"012 3456789","17,27","in den Briefkasten legen","Michels, Sylvia"
// 190,"AP90DEVVSPOS (9999010)","Morgentour Mo-Fr 06:30 09:00",09.08.2011,06:30,"Herr","Willnix","Ka Lieferkunde",90762,"Fürth","West","Hafenstr. 87",,,"0,00",,"Kormann, Stefan"
$rowToImport = array();
$rowToImport[0] = "f_no";
$rowToImport[1] = "f_apo";
$rowToImport[2] = "f_jb_tourname";
$rowToImport[3] = "f_orderdate";
$rowToImport[4] = "f_ordertime";
$rowToImport[5] = "f_title";
$rowToImport[6] = "f_usr_firstname";
$rowToImport[7] = "f_usr_name";
$rowToImport[8] = "f_ad_zipcode";
$rowToImport[9] = "f_ad_city";
$rowToImport[10] = "f_ad_district";
$rowToImport[11] = "f_ad_street";
$rowToImport[12] = "f_ad_country";
$rowToImport[13] = "f_usr_phone";
$rowToImport[14] = "f_open_credits";
$rowToImport[15] = "f_jb_remark";
$rowToImport[16] = "f_driver_name";
$rowToImport[17] = "f_dummy";
$rowToImportLen = count($rowToImport);
// read file to import
$data = importCSV($importFile, ",");
$dataLen = count($data);
// loop all rows (EXCEPT header row [$j = 1])
for ($j = 1; $j < $dataLen; $j++) {
// loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_apo = removeFieldSigns($f_apo);
$f_jb_tourname = removeFieldSigns($f_jb_tourname);
$f_title = removeFieldSigns($f_title);
$f_usr_firstname = removeFieldSigns($f_usr_firstname);
$f_usr_name = removeFieldSigns($f_usr_name);
$f_ad_city = removeFieldSigns($f_ad_city);
$f_ad_district = removeFieldSigns($f_ad_district);
$f_ad_street = removeFieldSigns($f_ad_street);
$f_ad_country = removeFieldSigns($f_ad_country);
$f_usr_phone = removeFieldSigns($f_usr_phone);
$f_open_credits = removeFieldSigns($f_open_credits);
$f_jb_remark = removeFieldSigns($f_jb_remark);
$f_driver_name = removeFieldSigns($f_driver_name);
$f_jb_ordertime = cStr2Date ($f_orderdate . " " . $f_ordertime, "2");
if ($f_ad_country == "") : $f_ad_country = "DE"; endif;
$f_jb_tourdata = $f_ad_zipcode . "|" . $f_ad_city . "|" . $f_ad_country;
$f_tr_person = $f_title . " " . $f_usr_firstname . " " . $f_usr_name;
if ($f_open_credits != "") :
$f_jb_remark = $f_jb_remark . " [Außenstände: " . $f_open_credits . "]";
endif;
$f_ad_id = "";
if ($f_ad_street != "" && $f_ad_zipcode != "" && $f_ad_city != "") :
$sqlStmt = "SELECT ad_id FROM address WHERE ad_street = '" . $f_ad_street . "' AND ad_zipcode = '" . $f_ad_zipcode . "' AND ad_city = '" . $f_ad_city . "' AND ad_country = 'DE'";
$f_ad_id = $db->getOne($sqlStmt);
if (DB::isError($ad_id)) die ("$PHP_SELF: <br>$sqlStmt<br>" . $ad_id->getMessage());
if ($f_ad_id == ""):
insertStmt("address", array("ad_street", $f_ad_street, "ad_zipcode", $f_ad_zipcode, "ad_city", $f_ad_city, "ad_country", "DE"));
$f_ad_id = getLastInsertID();
endif;
endif;
// Get costcenter for "csc_id_payer" in "job"
$cscId = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hq_id);
$trCscId = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hq_id);
$txValue = getFieldValueFromId("tax","tx_id","4","tx_value");
$txSign = getFieldValueFromId("tax","tx_id","4","tx_sign");
$fixprice = "0.00";
$trCommissionNo = "";
echo "f_orderdate: " . $f_orderdate . "<br>";
echo "f_ordertime: " . $f_ordertime . "<br>";
echo "f_apo: " . $f_apo . "<br>";
echo "f_jb_tourname: " . $f_jb_tourname . "<br>";
echo "f_title: " . $f_title . "<br>";
echo "f_usr_firstname: " . $f_usr_firstname . "<br>";
echo "f_usr_name: " . $f_usr_name . "<br>";
echo "f_ad_city: " . $f_ad_city . "<br>";
echo "f_ad_district: " . $f_ad_district . "<br>";
echo "f_ad_street: " . $f_ad_street . "<br>";
echo "f_ad_country: " . $f_ad_country . "<br>";
echo "f_usr_phone: " . $f_usr_phone . "<br>";
echo "f_open_credits: " . $f_open_credits . "<br>";
echo "f_jb_remark: " . $f_jb_remark . "<br>";
echo "f_driver_name: " . $f_driver_name . "<br>";
echo "f_jb_ordertime: " . $f_jb_ordertime . "<br>";
echo "f_jb_tourdata: " . $f_jb_tourdata . "<br>";
echo "f_tr_person: " . $f_tr_person . "<br>";
echo "f_ad_id: " . $f_ad_id . "<br>";
echo "cscId: " . $cscId . "<br>";
echo "trCscId: " . $trCscId . "<br>";
echo "txValue: " . $txValue . "<br>";
echo "txSign: " . $txSign . "<br>";
echo "fixprice: " . $fixprice . "<br>";
echo "trCommissionNo: " . $trCommissionNo . "<br>";
// Insert new job(s)
if (true) :
TA("B");
insertStmt("job", array("hq_id", $hq_id, "csc_id", $cscId, "vht_id", "2", "csc_id_payer", $cscId, "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "cr_id", "", "cr_sid", "", "cr_id_order", "",
"jb_cr_filter", "", "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", "", "jb_status", "9", "jb_autoranking", "0", "jb_type", "",
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_jb_tourname,
"jb_finishtime", "", "emp_id", $usr_id, "jb_fixprice", $fixprice, "jb_totalprice", $fixprice,
"jb_postage", "", "jb_invmode", "", "jb_freetext_1", "",
"jb_weight", "", "jb_crvh_length", "", "jb_crvh_width", "",
"jb_crvh_height", "", "jb_crvh_position", "", "jb_invtext", $f_jb_remark,
"jb_tourdata", $f_jb_tourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_booktime", ""));
$jbIdNew = getLastInsertId();
$i = 0;
// for ($i = 0; $i < $numOfStations; $i++) :
$trSort = $i + 1;
// Insert tour data for station
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $f_ad_id, "tr_sort", $trSort, "tr_comp", "", "tr_comp2", "",
"tr_hsno", ".", "csc_id", $trCscId, "tr_status", "0",
"tr_commission_no", $trCommissionNo, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", "", "tr_remark", $f_jb_remark));
// Insert tourservice data
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscId, "tr_sort", "0",
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", ""));
$trCommissionNo = ""; // Reset commission number because associated to the first station only
// endfor;
TA("C");
TA("E");
endif;
}
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_APO.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,479 @@
<?php
/*=======================================================================
*
* import_ARTICLE.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
include_once ("../import/import.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT ARTIKEL");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
$showRawData = true;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true;
// Customer and headquarters references have to exist
$hqId = "";
$csEid = "";
$objType = trim($objType);
$objId = trim($objId);
if ($objType == "CS" && is_numeric($objId)) :
$csId = getFieldValueFromId("phoenix.customer", "cs_id", $objId, "cs_id");
endif;
if ($csId != "") :
$hqId = getFieldValueFromId("phoenix.customer", "cs_id", $csId, "hq_id");
$csEid = getFieldValueFromId("phoenix.customer", "cs_id", $csId, "cs_eid");
else :
$csId = "0";
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$hqMnemonic = getFieldValueFromId("phoenix.headquarters", "hq_id", $hqId, "hq_mnemonic");
if ($debug) :
echo "f_act : " . $f_act . "<br>";
echo "objType : " . $objType . "<br>";
echo "objId : " . $objId . "<br>";
echo "hqId : " . $hqId . "<br>";
echo "csId : " . $csId . "<br>";
endif;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Check group names for accessing the script !!!!
$groupId = "";
$groupName = "";
$tmpPosForGrpName = strrpos($filename, "_");
if (!($tmpPosForGrpName === false)) :
$groupName = substr($filename, $tmpPosForGrpName + 1);
// Remove extension if does exist
$tmpPosForGrpName = strrpos($groupName, ".");
if (!($tmpPosForGrpName === false)) :
$groupName = substr($groupName, 0, $tmpPosForGrpName);
endif;
$groupId = getFieldValueFromId("phoenix.groups", "grp_name", $groupName, "grp_id");
endif;
if ($debug) :
echo "groupName : " . $groupName . "<br>";
echo "groupId : " . $groupId . "<br>";
echo "<br>";
endif;
if ($importFile != "" && (($csId != "" && $csId != "0") || $groupId != "")) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// Activate buffering
ob_start();
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, "import_ARTICLE_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$rowToImport = array();
$parImportArticleFieldsGroup == "";
if ($groupId != "") :
$parImportArticleFieldsGroup = getParameterValue("0", "IMPORT_ARTICLE_FIELDS_GROUP_" . $groupId, "0");
endif;
if ($parImportArticleFieldsGroup != "") :
/*
$parImportArticleFieldsGroupArray = spliti(",", $parImportArticleFieldsGroup);
$parImportArticleFieldsGroupArrayLen = count($parImportArticleFieldsGroupArray);
for ($k = 0; $k < $parImportArticleFieldsGroupArrayLen; $k++) :
$rowToImport[$k] = $parImportArticleFieldsGroupArray[$k];
endfor;
*/
$rowToImport = spliti(",", $parImportArticleFieldsGroup);
else :
// Default
$rowToImport[0] = "f_at_name"; // Article number
$rowToImport[1] = "f_at_description"; // Article name
$rowToImport[2] = "f_at_totalweight";
$rowToImport[3] = "f_at_price";
$rowToImport[4] = "f_at_price2"; // Family price
$rowToImport[5] = "f_at_no_packages"; // Number of packages
$rowToImport[6] = "f_at_dummy";
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter);
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
if ($f_at_match == "") : $f_at_match = $groupName; endif;
$f_at_name = removeFieldSigns($f_at_name);
$f_at_description = removeFieldSigns($f_at_description);
$f_at_match = removeFieldSigns($f_at_match);
$f_at_barcode = removeFieldSigns($f_at_barcode);
$f_atg_id = removeFieldSigns($f_atg_id);
$f_at_bundlequantity = removeFieldSigns($f_at_bundlequantity);
$f_at_bundlecode = removeFieldSigns($f_at_bundlecode);
$f_at_stk_itemquantity = removeFieldSigns($f_at_stk_itemquantity);
$f_at_stk_areaquantity = removeFieldSigns($f_at_stk_areaquantity);
$f_at_serialno = removeFieldSigns($f_at_serialno);
$f_at_totalweight = removeFieldSigns($f_at_totalweight);
$f_at_no_packages = removeFieldSigns($f_at_no_packages);
$f_at_price = removeFieldSigns($f_at_price);
$f_at_price2 = removeFieldSigns($f_at_price2);
$f_at_price3 = removeFieldSigns($f_at_price3);
$f_at_price4 = removeFieldSigns($f_at_price4);
$f_at_price5 = removeFieldSigns($f_at_price5);
$f_at_price6 = removeFieldSigns($f_at_price6);
$f_at_totalweight = str_replace (",", ".", $f_at_totalweight);
$f_at_totalweight = $f_at_totalweight / 1000; // Gram => Kilo
// $f_at_totalweight = $f_at_totalweight * 100; // Kilo => Gram
$f_at_no_packages = str_replace (",", ".", $f_at_no_packages);
if ($f_at_no_packages == "" || !is_numeric($f_at_no_packages)) : $f_at_no_packages = "1"; endif;
$f_at_price = str_replace (",", ".", $f_at_price); // Has to be the standard price
$f_at_prices_mt_sort = array();
$f_at_prices_mt_sort[0] = str_replace (",", ".", $f_at_price2); // First mt_sort entry (== "0") for this customer (e.g. "Familycard")
$f_at_prices_mt_sort[1] = str_replace (",", ".", $f_at_price3); // mt_sort == "1"
$f_at_prices_mt_sort[2] = str_replace (",", ".", $f_at_price4); // mt_sort == "2"
$f_at_prices_mt_sort[3] = str_replace (",", ".", $f_at_price5); // mt_sort == "3"
$f_at_prices_mt_sort[4] = str_replace (",", ".", $f_at_price6); // mt_sort == "4"
if ($f_at_bundlequantity == "") : $f_at_bundlequantity = "1"; endif;
if ($f_at_stk_itemquantity == "") : $f_at_stk_itemquantity = "1"; endif;
if ($f_at_stk_areaquantity == "") : $f_at_stk_areaquantity = "1"; endif;
// $f_atg_id // Article group
if ($showRawData) :
if ($j == 0) :
echo "<b>f_at_name" . $delimiter . "f_at_description" . $delimiter . "f_at_totalweight" . $delimiter . "f_at_price" . $delimiter . "f_at_price2" . $delimiter . "f_at_no_packages </b><br>";
endif;
echo $f_at_name . $delimiter . $f_at_description . $delimiter . $f_at_totalweight . $delimiter . $f_at_price . $delimiter . $f_at_price2 . $delimiter . $f_at_no_packages . "<br>";
ob_flush(); flush();
endif;
if ($f_at_name != "") :
// Insert new article
if ($fire && $executeImportProcess == "1") :
// TA("B");
$currAtId = "";
if (existsEntry("article",array("at_name", $f_at_name, "hq_id", $hqId))) : // ,"at_match",$f_at_match????
// Get field data for the current article. If imported data of some fields are empty because of delta import (subset, some fields only), the do NOT overwrite existing informations
$atFieldsCurrent = getFieldsValueFromId("phoenix.article", "at_name", $f_at_name, array("at_match","at_description","at_barcode","at_bundlequantity","at_bundlecode","at_stk_itemquantity","at_stk_areaquantity","at_serialno","at_totalweight","at_packingpieces"));
if ($atFieldsCurrent[0] != "" && $f_at_match == "") : $f_at_match = $atFieldsCurrent[0]; endif; // at_match
if ($atFieldsCurrent[1] != "" && $f_at_description == "") : $f_at_description = $atFieldsCurrent[1]; endif; // at_description
if ($atFieldsCurrent[2] != "" && $f_at_barcode == "") : $f_at_barcode = $atFieldsCurrent[2]; endif; // at_barcode
if ($f_at_barcode == "") : $f_at_barcode = $f_at_name; endif; // at_barcode <- at_name
if ($atFieldsCurrent[3] != "" && $f_at_bundlequantity != $atFieldsCurrent[3]) : $f_at_bundlequantity = $atFieldsCurrent[3]; endif; // at_bundlequantity
if ($atFieldsCurrent[4] != "" && $f_at_bundlecode == "") : $f_at_bundlecode = $atFieldsCurrent[4]; endif; // at_bundlecode
if ($atFieldsCurrent[5] != "" && $f_at_stk_itemquantity != $atFieldsCurrent[5]) : $f_at_stk_itemquantity = $atFieldsCurrent[5]; endif; // at_stk_itemquantity
if ($atFieldsCurrent[6] != "" && $f_at_stk_areaquantity != $atFieldsCurrent[6]) : $f_at_stk_areaquantity = $atFieldsCurrent[5]; endif; // at_stk_areaquantity
if ($atFieldsCurrent[7] != "" && $f_at_serialno == "") : $f_at_serialno = $atFieldsCurrent[7]; endif; // at_serialno
if ($atFieldsCurrent[8] != "" && $f_at_totalweight == "") : $f_at_totalweight = $atFieldsCurrent[8]; endif; // at_totalweight
if ($atFieldsCurrent[9] != "" && $f_at_no_packages == "") : $f_at_no_packages = $atFieldsCurrent[9]; endif; // at_no_packages
// Update article
// $defaultFields = array("at_match", $f_at_match, "at_description", $f_at_description, "at_barcode", $f_at_barcode, "at_bundlequantity", $f_at_bundlequantity, "at_bundlecode", $f_at_bundlecode, "at_stk_itemquantity", $f_at_stk_itemquantity, "at_stk_areaquantity", $f_at_stk_areaquantity, "at_serialno", $f_at_serialno, "at_totalweight", $f_at_totalweight, "at_packingpieces", $f_at_no_packages);
// ATTENTION: ARTICLE DESCRIPTION PRESENTLY WILL NOT BE UPDATED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$defaultFields = array("at_match", $f_at_match, "at_barcode", $f_at_barcode, "at_bundlequantity", $f_at_bundlequantity, "at_bundlecode", $f_at_bundlecode, "at_stk_itemquantity", $f_at_stk_itemquantity, "at_stk_areaquantity", $f_at_stk_areaquantity, "at_serialno", $f_at_serialno, "at_totalweight", $f_at_totalweight, "at_packingpieces", $f_at_no_packages);
$res = updateStmt("phoenix.article", "at_name", $f_at_name, $defaultFields, "hq_id = '" . $hqId . "'");
// Check update for success
if ($db->affected_rows > 0) :
$executionCount++;
$updateCount++;
$currAtId = getFieldValueFromClause("phoenix.article","at_id","at_name = '" . $f_at_name . "' AND hq_id = '" . $hqId . "'");
$outText .= getLngt("Update des Artikels:") . " " . $f_at_name . " [" . getLngt("NL") . " " . $hqMnemonic . "]<br>";
else :
$failedCount++;
endif;
else :
// Set special fields
if ($f_at_barcode == "") : $f_at_barcode = $f_at_name; endif; // at_barcode <- at_name
// Get max-value of the EID of the current article for inserting a new row
// The constant value "AT_EID_GENERATION" contains the prefix of the SID [SPECIAL TREATMENT]
// Get EID prefix and reset EID only if equals prefix
$constAtEidPrefix = getParameterValue("0", "AT_EID_PREFIX", $hqId);
if ($constAtEidPrefix == "") : $constAtEidPrefix = getParameterValue("0", "AT_EID_PREFIX", "0"); endif;
$constAtEidGeneration = getParameterValue("0", "AT_EID_GENERATION", $hqId);
if ($constAtEidGeneration == "") : $constAtEidGeneration = getParameterValue("0", "AT_EID_GENERATION", "0"); endif;
$f_eid_maxval = "";
if ($constAtEidGeneration != "") :
$f_eid_maxval = getMaxOfField("article", "at_eid", "at_eid < '" . $constAtEidGeneration . "'");
endif;
// Check existence of at least one EID with requested prefix
if ($f_eid_maxval == "" || substr($f_eid_maxval, 0, strlen($constAtEidPrefix)) != $constAtEidPrefix) :
$f_eid_maxval = $constAtEidPrefix . "100000";
endif;
if (is_numeric($f_eid_maxval)) :
++$f_eid_maxval; // Increment because of the next free EID (Attention: Not TA-safe!)
else :
// Remove alphanumeric chars (e.g "HTHB123456" => "123456")
$prefixChars = ereg_replace("[^[:alpha:]+]","",$f_eid_maxval);
$f_eid_maxval = ereg_replace("[^[:digit:]+]","",$f_eid_maxval);
++$f_eid_maxval;
$f_eid_maxval = $prefixChars . $f_eid_maxval;
endif;
// Insert article
if ($f_eid_maxval != "") :
insertStmt("article", array("at_eid", $f_eid_maxval, "at_name", $f_at_name, "hq_id", $hqId, "at_match", $f_at_match, "at_description", $f_at_description, "at_barcode", $f_at_barcode, "at_createtime", $currentTime,
"atg_id", $f_atg_id, "at_bundlequantity", $f_at_bundlequantity, "at_bundlecode", $f_at_bundlecode, "at_stk_itemquantity", $f_at_stk_itemquantity, "at_stk_areaquantity", $f_at_stk_areaquantity,
"at_serialno", $f_at_serialno, "at_totalweight", $f_at_totalweight, "at_packingpieces", $f_at_no_packages));
$currAtId = getLastInsertId();
$executionCount++;
$insertCount++;
else :
$outText .= getLngt("Die EID des folgenden Artikels konnte nicht generiert werden:") . " " . $f_at_name . "<br>";
$failedCount++;
endif;
endif;
// Update group information if a group has to be associated ($groupId != "") and the article does exist or has been inserted
if ($groupId != "" && $currAtId != "" && is_numeric($currAtId)) :
// Update group association
$groupsOfcurrArticle = getFieldValueFromId("phoenix.article", "at_id", $currAtId, "at_group");
if ($groupsOfcurrArticle == "") :
$res = updateStmt("phoenix.article", "at_id", $currAtId, array("at_group", "," . $groupId . ","));
elseif (strpos($groupsOfcurrArticle, "," . $groupId . ",") === false) :
$res = updateStmt("phoenix.article", "at_id", $currAtId, array("at_group", $groupsOfcurrArticle . $groupId . ","));
endif;
endif;
// Insert new prices if have been changed
if ($groupId != "" || $csId != "") :
// Check for $currAtId being set or not by modification or insertion of the article by itself
if ($currAtId == "") :
$currAtId = getFieldValueFromClause("phoenix.article","at_id","at_name = '" . $f_at_name . "' AND hq_id = '" . $hqId . "'");
endif;
// Insert article prices
if ($currAtId != "") :
// Check standard price
$oldPrice = getFieldValueFromClause("articleprice","atp_price","at_id = '" . $currAtId . "' AND cs_id = '" . $csId . "' AND grp_id = '" . $groupId . "' AND mt_sort = ''");
if ($f_at_price != "" && is_numeric($f_at_price) && ($oldPrice == "" || $oldPrice != $f_at_price)) :
insertStmt("articleprice", array("at_id", $currAtId, "cs_id", $csId, "grp_id", $groupId, "mt_sort", "", "atp_price", $f_at_price, "atp_validfrom", $currentTime)); // Insert standard price
endif;
// Iterate and check special prices
$f_at_prices_mt_sort_len = count($f_at_prices_mt_sort);
for ($k = 0; $k < $f_at_prices_mt_sort_len; $k++) :
if ($f_at_prices_mt_sort[$k] != "" && is_numeric($f_at_prices_mt_sort[$k])) :
$oldPrice = getFieldValueFromClause("articleprice","atp_price","at_id = '" . $currAtId . "' AND cs_id = '" . $csId . "' AND grp_id = '" . $groupId . "' AND mt_sort = '" . $k . "'");
if ($oldPrice == "" || $oldPrice != $f_at_prices_mt_sort[$k]) :
insertStmt("articleprice", array("at_id", $currAtId, "cs_id", $csId, "grp_id", $groupId, "mt_sort", $k, "atp_price", $f_at_prices_mt_sort[$k], "atp_validfrom", $currentTime)); // Insert special prices
endif;
endif;
endfor;
endif;
endif;
// TA("C");
// TA("E");
// $closeWindow = "1";
endif;
else :
$outText .= getLngt("Kein Artikel im Datensatz!") . "<br>";
endif;
// Reset all parameters corresponding with database fields fields! This is necessary because the imported fields can be a subset from all table fields defined for "article" in the database !!!!
$f_at_name = "";
$f_at_match = "";
$f_at_description = "";
$f_at_barcode = "";
$f_atg_id = "";
$f_at_bundlequantity = "";
$f_at_bundlecode = "";
$f_at_stk_itemquantity = "";
$f_at_stk_areaquantity = "";
$f_at_serialno = "";
$f_at_totalweight = "";
$f_at_no_packages = "";
$f_at_price = "";
$f_at_price2 = "";
$f_at_price3 = "";
$f_at_price4 = "";
$f_at_price5 = "";
$f_at_price6 = "";
// Feedback for browser
$m = $j;
if ($executeImportProcess == "1") :
if (($m % 100) == 0) :
echo "<br>";
echo round((($m / $dataLen) * 100), 2) . "%";
if ($showRawData) : echo "<br>"; endif;
ob_flush(); flush();
endif;
endif;
}
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
$outText .= getLngt("Neue Einträge: " . $insertCount . "<br>");
$outText .= getLngt("Modifizierte Einträge: " . $updateCount . "<br>");
$outText .= getLngt("INSERT oder UPDATE final nicht durchgeführt: " . $failedCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
// Deactivate buffering and flush data
ob_end_flush();
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_ARTICLE.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,312 @@
<?php
/*=======================================================================
*
* import_ARTICLEGROUP.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
include_once ("../import/import.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT ARTIKELGRUPPE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true;
// Customer and headquarters references have to exist
$hqId = "";
$csEid = "";
$objType = trim($objType);
$objId = trim($objId);
if ($objType == "CS" && is_numeric($objId)) :
$csId = getFieldValueFromId("phoenix.customer", "cs_id", $objId, "cs_id");
endif;
if ($csId != "") :
$hqId = getFieldValueFromId("phoenix.customer", "cs_id", $csId, "hq_id");
$csEid = getFieldValueFromId("phoenix.customer", "cs_id", $csId, "cs_eid");
else :
$csId = "0";
endif;
if ($debug) :
echo "f_act : " . $f_act . "<br>";
echo "objType : " . $objType . "<br>";
echo "objId : " . $objId . "<br>";
echo "hqId : " . $hqId . "<br>";
echo "csId : " . $csId . "<br>";
endif;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Check group names for accessing the script !!!!
$groupId = "";
$groupName = "";
$tmpPosForGrpName = strrpos($filename, "_");
if (!($tmpPosForGrpName === false)) :
$groupName = substr($filename, $tmpPosForGrpName + 1);
// Remove extension if does exist
$tmpPosForGrpName = strrpos($groupName, ".");
if (!($tmpPosForGrpName === false)) :
$groupName = substr($groupName, 0, $tmpPosForGrpName);
endif;
$groupId = getFieldValueFromId("phoenix.groups", "grp_name", $groupName, "grp_id");
endif;
if ($debug) :
echo "groupName : " . $groupName . "<br>";
echo "groupId : " . $groupId . "<br>";
echo "<br>";
endif;
if ($importFile != "" && (($csId != "" && $csId != "0") || $groupId != "")) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, "import_ARTICLEGROUP_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$rowToImport = array();
$parImportArticleFieldsGroup == "";
if ($groupId != "") :
$parImportArticleFieldsGroup = getParameterValue("0", "IMPORT_ARTICLEGROUP_FIELDS_GROUP_" . $groupId, "0");
endif;
if ($parImportArticleFieldsGroup != "") :
/*
$parImportArticleFieldsGroupArray = spliti(",", $parImportArticleFieldsGroup);
$parImportArticleFieldsGroupArrayLen = count($parImportArticleFieldsGroupArray);
for ($k = 0; $k < $parImportArticleFieldsGroupArrayLen; $k++) :
$rowToImport[$k] = $parImportArticleFieldsGroupArray[$k];
endfor;
*/
$rowToImport = spliti(",", $parImportArticleFieldsGroup);
else :
// Default
$rowToImport[0] = "f_atg_key"; // Articlegroup key/no.
$rowToImport[1] = "f_atg_name"; // Articlegroup name
$rowToImport[2] = "f_atg_dummy";
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter);
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_atg_key = removeFieldSigns($f_atg_key);
$f_atg_name = removeFieldSigns($f_atg_name);
$f_hq_id = "0";
if ($f_atg_key != "") :
// Insert new article
if ($fire && $executeImportProcess == "1") :
// TA("B");
$currAtgId = "";
if (existsEntry("articlegroup",array("atg_key",$f_atg_key))) :
// Update articlegroup
$res = updateStmt("phoenix.articlegroup", "atg_key", $f_atg_key, array("atg_name", $f_atg_name));
// Check update for success
if ($db->affected_rows > 0) :
$executionCount++;
$updateCount++;
$currAtgId = getFieldValueFromId("phoenix.articlegroup", "atg_key", $f_atg_key, "atg_id");
$outText .= getLngt("Update der Artikelgruppe:") . " " . $f_atg_key . " - " . $f_atg_name . "<br>";
else :
$failedCount++;
endif;
else :
// Insert article
if ($f_atg_name != "") :
insertStmt("phoenix.articlegroup", array("atg_key", $f_atg_key, "atg_name", $f_atg_name));
$currAtgId = getLastInsertId();
$executionCount++;
$insertCount++;
else :
$outText .= getLngt("Die Artikelgruppe hat zwar einen Schlüssel, aber keinen Namen:") . " " . $f_atg_key . "<br>";
$failedCount++;
endif;
endif;
// Update group information if a group has to be associated ($groupId != "") and the article does exist or has been inserted
if ($groupId != "" && $currAtgId != "" && is_numeric($currAtgId)) :
// Update group association
$groupsOfcurrArticle = getFieldValueFromId("phoenix.articlegroup", "atg_id", $currAtgId, "atg_group");
if ($groupsOfcurrArticle == "") :
$res = updateStmt("phoenix.articlegroup", "atg_id", $currAtgId, array("atg_group", "," . $groupId . ","));
elseif (strpos($groupsOfcurrArticle, "," . $groupId . ",") === false) :
$res = updateStmt("phoenix.articlegroup", "atg_id", $currAtgId, array("atg_group", $groupsOfcurrArticle . $groupId . ","));
endif;
endif;
// TA("C");
// TA("E");
// $closeWindow = "1";
endif;
else :
$outText .= getLngt("Keine Artikelgruppe im Datensatz!") . "<br>";
endif;
}
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
$outText .= getLngt("Neue Einträge: " . $insertCount . "<br>");
$outText .= getLngt("Modifizierte Einträge: " . $updateCount . "<br>");
$outText .= getLngt("INSERT oder UPDATE final nicht durchgeführt: " . $failedCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_ARTICLEGROUP.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,595 @@
<?php
/*=======================================================================
*
* import_BAUHAUS.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// include_once ("../include/inc_parseXML.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$currentShortDate = getDateTime(1);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csEid = "";
$cscIdPayer = "";
$address = array();
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
$address = getAddress($csId, "costcenteraddress"); // Get pickup address of the customer
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
// Init
$jbIdNew = "";
$jbTourdata = "";
$jbTourdataZipcode = "";
$jbTourdataCity = "";
$jbTourdataCountry = "";
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strrpos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
/*
$tourVehicleArray = array();
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
*/
$tourCourierArray = array();
/*
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
$tourCourierArray["294505"] = "e8020205";
$tourCourierArray["294506"] = "e8020206";
$tourCourierArray["294507"] = "e8020207";
$tourCourierArray["294508"] = "e8020208";
$tourCourierArray["294509"] = "e8020209";
$tourCourierArray["294510"] = "e8020210";
$tourCourierArray["294511"] = "e8020211";
$tourCourierArray["294512"] = "e8020212";
$tourCourierArray["294590"] = "e8020213";
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
// $aStr = mcDecode($aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
$aStr = str_replace("ß", "ß", $aStr);
$aStr = str_replace("ä", "ä", $aStr);
$aStr = str_replace("ö", "ö", $aStr);
$aStr = str_replace("ü", "ü", $aStr);
$aStr = str_replace("Ä", "Ä", $aStr);
$aStr = str_replace("Ö", "Ö", $aStr);
$aStr = str_replace("Ü", "Ü", $aStr);
return $aStr;
}
echo "importFile: " . $importFile . "<br>";
echo "hqId: " . $hqId . "<br>";
echo "csId: " . $csId . "<br>";
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// The filename contains the execution day !!!!
// $tmpJbOrdertime = substr($filename,-12,8);
// $jbOrdertime = substr($tmpJbOrdertime,0,4) . "-" . substr($tmpJbOrdertime,4,2) . "-" . substr($tmpJbOrdertime,6,2) . " 08:00:00";
// echo $jbOrdertime . "<br>";
// $jbOrdertime = checkDateTimeFormat($jbOrdertime); // DISABLED BECAUSE OF PHP VERSION ONLY !!! ACTIVATE AFTER MIGRATION !!!
// $checkGmtdatetimeIsValid = strtotime($jbOrdertime);
// echo $checkGmtdatetimeIsValid . "<br>";
// if ($checkGmtdatetimeIsValid != "" && is_int($checkGmtdatetimeIsValid)):
if (true):
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_BAUHAUS_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$f_tour_no = 1;
$remIsPickup = true;
$jbIdNew = 0;
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_BAUHAUS_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
/*
Station;Datum;Avisiertes Zeitfenster;Auftragsnr.;Name;Straße;Hausnr.;Plz;Ort;Telefonnr.;Kunde;Bemerkungen (Warenart; KG; Stpl.; Zone; Inkasso; Besonderheiten
*/
$rowToImport[0] = "f_lfd"; // A : Nur fortlaufende Nummer
$rowToImport[1] = "f_orderdate"; // B : Tag des Auftragsbeginns
$rowToImport[2] = "f_time_window"; // C : Auftragsstartzeit und gewünschte Auftragsendezeit
$rowToImport[3] = "f_tr_commission_no"; // D : Kundenauftragsnummer
$rowToImport[4] = "f_tr_comp"; // E : Kunde / Firma
$rowToImport[5] = "f_ad_street"; // F : Straße
$rowToImport[6] = "f_tr_hsno"; // G : Hausnummer
$rowToImport[7] = "f_ad_zipcode"; // H : PLZ
$rowToImport[8] = "f_ad_city"; // I : Ort
$rowToImport[9] = "f_tr_phone"; // J : Telefon
$rowToImport[10] = "f_tr_remark"; // K : Bemerkung
$rowToImport[11] = "f_dummy_01"; // L : ?
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
echo "Datensätze: " . ($dataLen - 1) . "<br>";
// print_r($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
// Check for existing headline
if ($j > 0) :
$f_lfd = mcStrWrap($f_lfd);
$f_orderdate = mcStrWrap($f_orderdate);
$f_time_window = mcStrWrap($f_time_window);
$f_tr_commission_no = mcStrWrap($f_tr_commission_no);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_ad_street = mcStrWrap($f_ad_street);
$f_tr_hsno = mcStrWrap($f_tr_hsno);
$f_ad_zipcode = mcStrWrap($f_ad_zipcode);
$f_ad_city = mcStrWrap($f_ad_city);
$f_tr_phone = mcStrWrap($f_tr_phone);
$f_tr_remark = mcStrWrap($f_tr_remark);
// Ordertime by order date and time window
$f_ordertime = substr($f_orderdate,6,4) . "-" . substr($f_orderdate,3,2) . "-" . substr($f_orderdate,0,2);
$f_warningtime = $f_ordertime;
if ($f_time_window != "") :
$orderClockTime = " " . substr($f_time_window,0,2) . ":" . substr($f_time_window,3,2) . ":00";
$warningClockTime = " " . substr($f_time_window,8,2) . ":" . substr($f_time_window,11,2) . ":00";
else :
$orderClockTime = " 08:00:00";
$warningClockTime = " 08:00:00";
endif;
// Special static handling per headquarters
if ($hqId == "111") :
$orderClockTime = " 07:30:00";
$warningClockTime = " 07:30:00";
endif;
$f_ordertime .= $orderClockTime;
$f_warningtime .= $warningClockTime;
$f_tr_person = $f_tr_comp;
// Set vehicle and courier
$crId = "";
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
$jbStatus = "1";
$jbTaketime = $currentTime;
endif;
$jbType = "2"; // Init with job type "G"
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo "------------------------------------------------------<br>";
echo "f_tour_no: " . $f_tour_no . "<br>";
echo "f_lfd: " . $f_lfd . "<br>";
echo "f_orderdate: " . $f_orderdate . "<br>";
echo "f_time_window: " . $f_time_window . "<br>";
echo "f_ordertime: " . $f_ordertime . "<br>";
echo "f_warningtime: " . $f_warningtime . "<br>";
echo "f_tr_commission_no: " . $f_tr_commission_no . "<br>";
echo "f_tr_comp: " . $f_tr_comp . "<br>";
echo "f_tr_person: " . $f_tr_person . "<br>";
echo "f_ad_street: " . $f_ad_street . "<br>";
echo "f_tr_hsno: " . $f_tr_hsno . "<br>";
echo "f_ad_zipcode: " . $f_ad_zipcode . "<br>";
echo "f_ad_city: " . $f_ad_city . "<br>";
echo "f_tr_phone: " . $f_tr_phone . "<br>";
echo "f_tr_remark: " . $f_tr_remark . "<br>";
// Check for existence of the imported "tour name" AND "station number" (unique for station)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_orderdate . " " . $f_tr_commission_no,"gdc_context","BAUHAUS"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if BAUHAUS number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = true;
if ($remTourNo == "" || $remTourNo == $f_tour_no) :
if ($jbTourdataZipcode != "") : $jbTourdataZipcode .= ";"; endif;
$jbTourdataZipcode .= $f_ad_zipcode;
if ($jbTourdataCity != "") : $jbTourdataCity .= ";"; endif;
$jbTourdataCity .= $f_ad_city;
if ($jbTourdataCountry != "") : $jbTourdataCountry .= ";"; endif;
$jbTourdataCountry .= "DE";
endif;
// Insert address
if ($f_ad_street == "" || $f_ad_zipcode == "" || $f_ad_city == "") :
$noValidationOfAddress = "1";
endif;
if ($f_ad_zipcode != "" && $f_ad_city != "") :
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$isPickup = false;
else :
$ad_id_new = $address["id"];
$f_tr_hsno = $address["hsno"];
$isPickup = true;
endif;
// $outText .= "AD_ID : " . $ad_id_new . " | ";
// If current station IS "pickup" AND the station before was NOT "pickup" then start next tour
// Check last stations
if ($j < 1 || $j >= ($dataLen - 2)) :
$remIsPickup = true;
endif;
echo "isPickup : " . ($isPickup ? "YES" : "NO") . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;remIsPickup : " . ($remIsPickup ? "YES" : "NO") . "<br>";
if ($isPickup && !$remIsPickup) :
$f_tour_no++;
$remIsPickup = $isPickup;
endif;
// Tourname
$f_jb_tourname = $f_tr_comp . " " . $f_orderdate . " " . $f_tour_no;
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_tour_no) :
// Finalize currently imported job
// Write "jb_tourdata" of the job currently imported
if ($remTourNo != "" && $jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// Remove existing tourname
updateStmt("job","jb_tourname",$f_jb_tourname,array("jb_tourname",""), "jb_tourname = '" . $f_jb_tourname . "'");
// Tour data
/*
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
*/
$jbIdNew = ""; // Init
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", "", "jb_warningtime", $f_warningtime, "jb_createtime", $currentTime));
$jbIdNew = getLastInsertId();
$trSort = 0;
$remTourNo = $f_tour_no;
$remIsPickup = true;
// Init for the next job to be imported
$jbTourdata = "";
// Init with current values
$jbTourdataZipcode = $f_ad_zipcode;
$jbTourdataCity = $f_ad_city;
$jbTourdataCountry = "DE";
endif;
// Check for inserted job
if ($jbIdNew != "") :
$trSort++;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
// Insert tourservice data
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// Tourname
// insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_orderdate . " " . $f_tr_commission_no, "gdc_context", "BAUHAUS"));
// Insert tourarticle data (delivery stations)
/*
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
*/
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
/*
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
*/
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_order_id . "]<br>";
endif;
endif; // Check for headline
}
// If at least onne imported job does exist ($jbIdNew > 0) then finalize last imported job
// Write "jb_tourdata" of the job currently imported
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Das Datum für den Ausführungstag im Dateinamen scheint nicht korrekt! Bitte folgendes Format für den Dateinamen verwenden: import_BAUHAUS_YYYYMMDD.csv");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_BAUHAUS.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,595 @@
<?php
/*=======================================================================
*
* import_BAUHAUS.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// include_once ("../include/inc_parseXML.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$currentShortDate = getDateTime(1);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csEid = "";
$cscIdPayer = "";
$address = array();
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
$address = getAddress($csId, "costcenteraddress"); // Get pickup address of the customer
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
// Init
$jbIdNew = "";
$jbTourdata = "";
$jbTourdataZipcode = "";
$jbTourdataCity = "";
$jbTourdataCountry = "";
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strrpos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
/*
$tourVehicleArray = array();
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
*/
$tourCourierArray = array();
/*
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
$tourCourierArray["294505"] = "e8020205";
$tourCourierArray["294506"] = "e8020206";
$tourCourierArray["294507"] = "e8020207";
$tourCourierArray["294508"] = "e8020208";
$tourCourierArray["294509"] = "e8020209";
$tourCourierArray["294510"] = "e8020210";
$tourCourierArray["294511"] = "e8020211";
$tourCourierArray["294512"] = "e8020212";
$tourCourierArray["294590"] = "e8020213";
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
// $aStr = mcDecode($aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
$aStr = str_replace("ß", "ß", $aStr);
$aStr = str_replace("ä", "ä", $aStr);
$aStr = str_replace("ö", "ö", $aStr);
$aStr = str_replace("ü", "ü", $aStr);
$aStr = str_replace("Ä", "Ä", $aStr);
$aStr = str_replace("Ö", "Ö", $aStr);
$aStr = str_replace("Ü", "Ü", $aStr);
return $aStr;
}
echo "importFile: " . $importFile . "<br>";
echo "hqId: " . $hqId . "<br>";
echo "csId: " . $csId . "<br>";
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// The filename contains the execution day !!!!
// $tmpJbOrdertime = substr($filename,-12,8);
// $jbOrdertime = substr($tmpJbOrdertime,0,4) . "-" . substr($tmpJbOrdertime,4,2) . "-" . substr($tmpJbOrdertime,6,2) . " 08:00:00";
// echo $jbOrdertime . "<br>";
// $jbOrdertime = checkDateTimeFormat($jbOrdertime); // DISABLED BECAUSE OF PHP VERSION ONLY !!! ACTIVATE AFTER MIGRATION !!!
// $checkGmtdatetimeIsValid = strtotime($jbOrdertime);
// echo $checkGmtdatetimeIsValid . "<br>";
// if ($checkGmtdatetimeIsValid != "" && is_int($checkGmtdatetimeIsValid)):
if (true):
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_BAUHAUS_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$f_tour_no = 1;
$remIsPickup = true;
$jbIdNew = 0;
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_BAUHAUS_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
/*
Station;Datum;Avisiertes Zeitfenster;Auftragsnr.;Name;Straße;Hausnr.;Plz;Ort;Telefonnr.;Kunde;Bemerkungen (Warenart; KG; Stpl.; Zone; Inkasso; Besonderheiten
*/
$rowToImport[0] = "f_lfd"; // A : Nur fortlaufende Nummer
$rowToImport[1] = "f_orderdate"; // B : Tag des Auftragsbeginns
$rowToImport[2] = "f_time_window"; // C : Auftragsstartzeit und gewünschte Auftragsendezeit
$rowToImport[3] = "f_tr_commission_no"; // D : Kundenauftragsnummer
$rowToImport[4] = "f_tr_comp"; // E : Kunde / Firma
$rowToImport[5] = "f_ad_street"; // F : Straße
$rowToImport[6] = "f_tr_hsno"; // G : Hausnummer
$rowToImport[7] = "f_ad_zipcode"; // H : PLZ
$rowToImport[8] = "f_ad_city"; // I : Ort
$rowToImport[9] = "f_tr_phone"; // J : Telefon
$rowToImport[10] = "f_tr_remark"; // K : Bemerkung
$rowToImport[11] = "f_dummy_01"; // L : ?
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
echo "Datensätze: " . ($dataLen - 1) . "<br>";
// print_r($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
// Check for existing headline
if ($j > 0) :
$f_lfd = mcStrWrap($f_lfd);
$f_orderdate = mcStrWrap($f_orderdate);
$f_time_window = mcStrWrap($f_time_window);
$f_tr_commission_no = mcStrWrap($f_tr_commission_no);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_ad_street = mcStrWrap($f_ad_street);
$f_tr_hsno = mcStrWrap($f_tr_hsno);
$f_ad_zipcode = mcStrWrap($f_ad_zipcode);
$f_ad_city = mcStrWrap($f_ad_city);
$f_tr_phone = mcStrWrap($f_tr_phone);
$f_tr_remark = mcStrWrap($f_tr_remark);
// Ordertime by order date and time window
$f_ordertime = substr($f_orderdate,6,4) . "-" . substr($f_orderdate,3,2) . "-" . substr($f_orderdate,0,2);
$f_warningtime = $f_ordertime;
if ($f_time_window != "") :
$orderClockTime = " " . substr($f_time_window,0,2) . ":" . substr($f_time_window,3,2) . ":00";
$warningClockTime = " " . substr($f_time_window,8,2) . ":" . substr($f_time_window,11,2) . ":00";
else :
$orderClockTime = " 08:00:00";
$warningClockTime = " 08:00:00";
endif;
// Special static handling per headquarters
if ($hqId == "111") :
$orderClockTime = " 07:30:00";
$warningClockTime = " 07:30:00";
endif;
$f_ordertime .= $orderClockTime;
$f_warningtime .= $warningClockTime;
$f_tr_person = $f_tr_comp;
// Set vehicle and courier
$crId = "";
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
$jbStatus = "1";
$jbTaketime = $currentTime;
endif;
$jbType = "2"; // Init with job type "G"
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo "------------------------------------------------------<br>";
echo "f_tour_no: " . $f_tour_no . "<br>";
echo "f_lfd: " . $f_lfd . "<br>";
echo "f_orderdate: " . $f_orderdate . "<br>";
echo "f_time_window: " . $f_time_window . "<br>";
echo "f_ordertime: " . $f_ordertime . "<br>";
echo "f_warningtime: " . $f_warningtime . "<br>";
echo "f_tr_commission_no: " . $f_tr_commission_no . "<br>";
echo "f_tr_comp: " . $f_tr_comp . "<br>";
echo "f_tr_person: " . $f_tr_person . "<br>";
echo "f_ad_street: " . $f_ad_street . "<br>";
echo "f_tr_hsno: " . $f_tr_hsno . "<br>";
echo "f_ad_zipcode: " . $f_ad_zipcode . "<br>";
echo "f_ad_city: " . $f_ad_city . "<br>";
echo "f_tr_phone: " . $f_tr_phone . "<br>";
echo "f_tr_remark: " . $f_tr_remark . "<br>";
// Check for existence of the imported "tour name" AND "station number" (unique for station)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_orderdate . " " . $f_tr_commission_no,"gdc_context","BAUHAUS"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if BAUHAUS number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = true;
if ($remTourNo == "" || $remTourNo == $f_tour_no) :
if ($jbTourdataZipcode != "") : $jbTourdataZipcode .= ";"; endif;
$jbTourdataZipcode .= $f_ad_zipcode;
if ($jbTourdataCity != "") : $jbTourdataCity .= ";"; endif;
$jbTourdataCity .= $f_ad_city;
if ($jbTourdataCountry != "") : $jbTourdataCountry .= ";"; endif;
$jbTourdataCountry .= "DE";
endif;
// Insert address
if ($f_ad_street == "" || $f_ad_zipcode == "" || $f_ad_city == "") :
$noValidationOfAddress = "1";
endif;
if ($f_ad_zipcode != "" && $f_ad_city != "") :
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$isPickup = false;
else :
$ad_id_new = $address["id"];
$f_tr_hsno = $address["hsno"];
$isPickup = true;
endif;
// $outText .= "AD_ID : " . $ad_id_new . " | ";
// If current station IS "pickup" AND the station before was NOT "pickup" then start next tour
// Check last stations
if ($j < 1 || $j >= ($dataLen - 2)) :
$remIsPickup = true;
endif;
echo "isPickup : " . ($isPickup ? "YES" : "NO") . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;remIsPickup : " . ($remIsPickup ? "YES" : "NO") . "<br>";
if ($isPickup && !$remIsPickup) :
$f_tour_no++;
$remIsPickup = $isPickup;
endif;
// Tourname
$f_jb_tourname = $f_tr_comp . " " . $f_orderdate . " " . $f_tour_no;
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_tour_no) :
// Finalize currently imported job
// Write "jb_tourdata" of the job currently imported
if ($remTourNo != "" && $jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// Remove existing tourname
updateStmt("job","jb_tourname",$f_jb_tourname,array("jb_tourname",""), "jb_tourname = '" . $f_jb_tourname . "'");
// Tour data
/*
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
*/
$jbIdNew = ""; // Init
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", "", "jb_warningtime", $f_warningtime, "jb_createtime", $currentTime));
$jbIdNew = getLastInsertId();
$trSort = 0;
$remTourNo = $f_tour_no;
$remIsPickup = true;
// Init for the next job to be imported
$jbTourdata = "";
// Init with current values
$jbTourdataZipcode = $f_ad_zipcode;
$jbTourdataCity = $f_ad_city;
$jbTourdataCountry = "DE";
endif;
// Check for inserted job
if ($jbIdNew != "") :
$trSort++;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
// Insert tourservice data
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// Tourname
// insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_orderdate . " " . $f_tr_commission_no, "gdc_context", "BAUHAUS"));
// Insert tourarticle data (delivery stations)
/*
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
*/
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
/*
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
*/
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_order_id . "]<br>";
endif;
endif; // Check for headline
}
// If at least onne imported job does exist ($jbIdNew > 0) then finalize last imported job
// Write "jb_tourdata" of the job currently imported
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Das Datum für den Ausführungstag im Dateinamen scheint nicht korrekt! Bitte folgendes Format für den Dateinamen verwenden: import_BAUHAUS_YYYYMMDD.csv");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_BAUHAUS.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,611 @@
<?php
/*=======================================================================
*
* import_BAUHAUS.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// include_once ("../include/inc_parseXML.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$currentShortDate = getDateTime(1);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
// Init
$jbIdNew = "";
$jbTourdata = "";
$jbTourdataZipcode = "";
$jbTourdataCity = "";
$jbTourdataCountry = "";
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strrpos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
/*
$tourVehicleArray = array();
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
*/
$tourCourierArray = array();
/*
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
$tourCourierArray["294505"] = "e8020205";
$tourCourierArray["294506"] = "e8020206";
$tourCourierArray["294507"] = "e8020207";
$tourCourierArray["294508"] = "e8020208";
$tourCourierArray["294509"] = "e8020209";
$tourCourierArray["294510"] = "e8020210";
$tourCourierArray["294511"] = "e8020211";
$tourCourierArray["294512"] = "e8020212";
$tourCourierArray["294590"] = "e8020213";
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
/*
$aStr = utf8_decode($aStr);
$aStr = str_replace("\"", '', $aStr);
$aStr = str_replace("ß", "ß", $aStr);
$aStr = str_replace("ä", "ä", $aStr);
$aStr = str_replace("ö", "ö", $aStr);
$aStr = str_replace("ü", "ü", $aStr);
$aStr = str_replace("Ä", "Ä", $aStr);
$aStr = str_replace("Ö", "Ö", $aStr);
$aStr = str_replace("Ü", "Ü", $aStr);
*/
return $aStr;
}
echo "importFile" . $importFile . "<br>";
echo "hqId" . $hqId . "<br>";
echo "csId" . $csId . "<br>";
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// The filename contains the execution day !!!!
$tmpJbOrdertime = substr($filename,-12,8);
$jbOrdertime = substr($tmpJbOrdertime,0,4) . "-" . substr($tmpJbOrdertime,4,2) . "-" . substr($tmpJbOrdertime,6,2) . " 08:00:00";
echo $jbOrdertime . "<br>";
// $jbOrdertime = checkDateTimeFormat($jbOrdertime); // DISABLED BECAUSE OF PHP VERSION ONLY !!! ACTIVATE AFTER MIGRATION !!!
$checkGmtdatetimeIsValid = strtotime($jbOrdertime);
echo $checkGmtdatetimeIsValid . "<br>";
if ($checkGmtdatetimeIsValid != "" && is_int($checkGmtdatetimeIsValid)):
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_BAUHAUS_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$jbIdNew = 0;
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_BAUHAUS_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
/*
Nr. Tour Bezeichnung Tourelement Bezeichnung Auftrag Bemerkungen Tourelement Position in Tour Tourelement PLZ Tourelement Ort Tourelement Straße Tourelement Hausnummer Tourelement Ankunft Tourelement Abfahrt Tourelement Strecke Auftrag Fixe Dauer
*/
$rowToImport[0] = "f_jb_tourname"; // A : Tour (v = vormittags, n = nachmittags)
$rowToImport[1] = "f_tr_sort"; // B : Lfd der Station
$rowToImport[2] = "f_tr_commission_no"; // C : Belegnummer
$rowToImport[3] = "f_tr_comp"; // D : Kunde / Frima
$rowToImport[4] = "f_ad_data"; // E : Adresse
$rowToImport[5] = "f_tr_phone"; // F : Telefon
$rowToImport[6] = "f_tr_mobile"; // G : Mobil
$rowToImport[7] = "f_tr_remark"; // H : Wareninfo
$rowToImport[8] = "f_palettes"; // I : Anzahl Paletten
$rowToImport[9] = "f_tr_remark2"; // J : Weitere Bemerkungen
$rowToImport[10] = "f_tr_remark3"; // K : Zusatz-Leistungen
$rowToImport[11] = "f_dummy_01"; // L : ?
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_jb_tourname = mcStrWrap($f_jb_tourname);
if (strtolower($f_jb_tourname) == "v") : $f_jb_tourname = "BAUHAUS-Vormittagstour"; endif;
if (strtolower($f_jb_tourname) == "n") : $f_jb_tourname = "BAUHAUS-Namchmittagstour"; endif;
$f_tr_sort = mcStrWrap($f_tr_sort);
$f_tr_commission_no = mcStrWrap($f_tr_commission_no);
// Check for existing headline
if ($j > 0 && ($f_tr_sort != "" && is_numeric($f_tr_sort)) && $f_tr_commission_no != "") :
$tmpArray = spliti(":", $f_tr_commission_no);
$tmpRemark = $tmpArray[1];
$tmpRemark = trim($tmpRemark);
$f_tr_commission_no = $tmpArray[0];
$f_tr_commission_no = trim($f_tr_commission_no);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_tr_person = $f_tr_comp;
$f_ad_data = mcStrWrap($f_ad_data);
$tmpArray = spliti(",", $f_ad_data);
$f_ad_street = $tmpArray[0];
if ($f_tr_hsno == "") :
$f_tr_hsno = ".";
endif;
$tmpArray[1] = str_replace ("D -", "", $tmpArray[1]);
$tmpArray[1] = str_replace ("D-", "", $tmpArray[1]);
$tmpArray[1] = trim($tmpArray[1]);
if (!is_numeric(substr($tmpArray[1],0,1))) :
$pos = strpos("-",$tmpArray[1]);
if ($pos === false) : $pos = 0; endif;
$f_ad_zipcode = substr($tmpArray[1],0,($pos + 1)) . "-" . preg_replace('/[^0-9]/', '', $tmpArray[1]);
$f_ad_city = preg_replace('/[^a-zäöü]/i', '', substr($tmpArray[1],1)); // Without first char (being the letter for the country)
else :
$f_ad_zipcode = preg_replace('/[^0-9]/', '', $tmpArray[1]);
$f_ad_zipcode = substr(trim($f_ad_zipcode),0,5);
$f_ad_city = preg_replace('/[^a-zäöü]/i', '', $tmpArray[1]);
endif;
$f_ad_city = trim($f_ad_city);
$f_tr_phone = mcStrWrap($f_tr_phone);
$f_tr_phone = eregPhoneNo($f_tr_phone);
$f_tr_mobile = mcStrWrap($f_tr_mobile);
$f_tr_mobile = eregPhoneNo($f_tr_mobile);
$f_tr_remark = mcStrWrap($f_tr_remark);
$f_palettes = mcStrWrap($f_palettes);
$f_tr_remark2 = mcStrWrap($f_tr_remark2);
$f_tr_remark3 = mcStrWrap($f_tr_remark3);
$f_tr_remark = $tmpRemark . "\n\n" . $f_tr_remark . "\n\n" . $f_tr_remark2 . "\n\n" . $f_palettes . "\n\n" . $f_tr_remark3;
if ($f_tr_phone == "") :
$f_tr_phone = $f_tr_mobile;
else :
if ($f_tr_mobile != "") :
$f_tr_remark .= "\n\n" . $f_tr_mobile;
endif;
endif;
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_jb_tourname];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
$crEid = $tourCourierArray[$f_jb_tourname];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
endif;
*/
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
$jbStatus = "1";
$jbTaketime = $currentTime;
endif;
$jbType = "2";
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
/*
echo $f_jb_tourname . ";" . $f_tr_sort . ";" . $f_tr_commission_no . ";";
echo $f_ad_street . ";" . $f_ad_zipcode . ";" . $f_ad_city . ";";
echo $f_tr_phone . ";" . $f_tr_mobile . ";" . $f_tr_remark;
echo "<br>";
*/
echo "------------------------------------------------------<br>";
echo "f_jb_tourname: " . $f_jb_tourname . "<br>";
echo "f_tr_sort: " . $f_tr_sort . "<br>";
echo "f_tr_commission_no: " . $f_tr_commission_no . "<br>";
echo "f_ad_street: " . $f_ad_street . "<br>";
echo "f_ad_zipcode: " . $f_ad_zipcode . "<br>";
echo "f_ad_city: " . $f_ad_city . "<br>";
echo "f_tr_phone: " . $f_tr_phone . "<br>";
echo "f_tr_mobile: " . $f_tr_mobile . "<br>";
echo "f_tr_remark: " . $f_tr_remark . "<br>";
// Check for existence of the imported "tour name" AND "station number" (unique for station)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_tr_commission_no . " " . $f_tr_sort . " " . $currentShortDate,"gdc_context","BAUHAUS"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if BAUHAUS number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = true;
if ($remTourNo == "" || $remTourNo == $f_jb_tourname) :
if ($jbTourdataZipcode != "") : $jbTourdataZipcode .= ";"; endif;
$jbTourdataZipcode .= $f_ad_zipcode;
if ($jbTourdataCity != "") : $jbTourdataCity .= ";"; endif;
$jbTourdataCity .= $f_ad_city;
if ($jbTourdataCountry != "") : $jbTourdataCountry .= ";"; endif;
$jbTourdataCountry .= "DE";
endif;
// Insert address
if ($f_ad_street == "" || $f_ad_zipcode == "" || $f_ad_city == "") :
$noValidationOfAddress = "1";
endif;
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_jb_tourname) :
// Finalize currently imported job
// Write "jb_tourdata" of the job currently imported
if ($remTourNo != "" && $jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// Remove existing tourname
updateStmt("job","jb_tourname",$f_jb_tourname,array("jb_tourname",""), "jb_tourname = '" . $f_jb_tourname . "'");
// Tour data
/*
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
*/
$jbIdNew = ""; // Init
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $jbOrdertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_createtime", $currentTime, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbIdNew = getLastInsertId();
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$remTourNo = $f_jb_tourname;
// Init for the next job to be imported
$jbTourdata = "";
// Init with current values
$jbTourdataZipcode = $f_ad_zipcode;
$jbTourdataCity = $f_ad_city;
$jbTourdataCountry = "DE";
endif;
// Check for inserted job
if ($jbIdNew != "") :
$trSort++;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
// Insert tourservice data
/*
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
*/
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort, "srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "", "trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// Tourname
// insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_0", "gdc_content", $f_tr_commission_no . " " . $f_tr_sort . " " . $currentShortDate, "gdc_context", "BAUHAUS"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_tr_commission_no . " " . $f_tr_sort . " " . $currentShortDate, "gdc_context", "BAUHAUS"));
// Insert tourarticle data (delivery stations)
/*
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
*/
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
/*
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
*/
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_order_id . "]<br>";
endif;
endif; // Check for headline
}
// If at least onne imported job does exist ($jbIdNew > 0) then finalize last imported job
// Write "jb_tourdata" of the job currently imported
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Das Datum für den Ausführungstag im Dateinamen scheint nicht korrekt! Bitte folgendes Format für den Dateinamen verwenden: import_BAUHAUS_YYYYMMDD.csv");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_BAUHAUS.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

614
html/import/import_BMW.php Normal file
View File

@@ -0,0 +1,614 @@
<?php
/*=======================================================================
*
* import_ZONE_JOBS.php [BMW]
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
include_once ("../locating/xServer.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csEid = "";
$cscIdPayer = "";
$srvzIdArray = array();
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
// Get zone ids (primary key) of the current customer
$srvzIdArray = getColVectorFromDB2ArrayByClause("phoenix.servicezone", "srvz_id", "hq_id = '" . $hqId . "' AND cs_id = '" . $csId . "'");
$csAddress = getAddress($csId, "costcenteraddress");
$adIdFrom = $csAddress["id"];
$adZipcodeFrom = $csAddress["zipcode"];
$adCityFrom = $csAddress["city"];
$adCountryFrom = $csAddress["country"];
$trHsnoFrom = $csAddress["hsno"];
if ($trHsnoFrom == "") : $trHsnoFrom = "."; endif;
$trCompFrom = $csAddress["comp"];
if ($trCompFrom == "") : $trCompFrom = "IMPORT"; endif;
$trFloorFrom = "";
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$srvzIdArrayLen = count($srvzIdArray);
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strrpos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
/*
$tourVehicleArray = array();
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
*/
$tourCourierArray = array();
/*
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
$tourCourierArray["294505"] = "e8020205";
$tourCourierArray["294506"] = "e8020206";
$tourCourierArray["294507"] = "e8020207";
$tourCourierArray["294508"] = "e8020208";
$tourCourierArray["294509"] = "e8020209";
$tourCourierArray["294510"] = "e8020210";
$tourCourierArray["294511"] = "e8020211";
$tourCourierArray["294512"] = "e8020212";
$tourCourierArray["294590"] = "e8020213";
*/
function mcStrWrap ($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
return $aStr;
}
function eregPhoneNo_MC ($phoneNo) {
$phoneNo = str_replace("'", "", $phoneNo);
$phoneNo = preg_replace ("/ /", "", $phoneNo); // Remove blanks
$phoneNo = preg_replace ("/-/", "", $phoneNo); // Remove sign "-"
$phoneNo = str_replace("/", "", $phoneNo); // Remove sign "/"
// $phoneNo = preg_replace ("/^\+/", "00", $phoneNo); // Remove country prefix sign "+" with "00"
// $phoneNo = preg_replace ("/^00" . $parCountryPhonePrefix . "/", "0", $phoneNo); // Remove country prefix with "0"
// $phoneNo = preg_replace ("/^00/", "", $phoneNo); // Remove leading "00"
// $phoneNo = preg_replace ("/^0/", "", $phoneNo); // Remove leading "0"
return $phoneNo;
}
/*
echo "importFile: " . $importFile . "<br>";
echo "hqId: " . $hqId . "<br>";
echo "csId: " . $csId . "<br>";
*/
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_BMW_") === false)) :
if ($srvzIdArrayLen > 0) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$txValue = "4";
$txSign = "V";
$jbZoneIdArray = array(); // Associative array ($jbZoneIdArray[zone] = jbId)
$jbTrSortArray = array(); // Associative array ($jbTrSortArray[jbId] = trSort)
$jbTrIdArray = array(); // Associative array ($jbTrIdArray[jbId][trSort] = trId)
$jbTourdataZipcodeArray = array(); // Associative array ($jbTourdataZipcodeArray[jbId] = "....")
$jbTourdataCityArray = array(); // Associative array ($jbTourdataCityArray[jbId] = "....")
$jbTourdataCountryArray = array(); // Associative array ($jbTourdataCountryArray[jbId] = "....")
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_BMW_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
/*
Debitor Name 1 Straße Postleitz. Ort Telefon-1 Bar
*/
$rowToImport[0] = "f_lfd"; // A : Lfd
$rowToImport[1] = "f_tr_comp"; // B : Bezeichnung
$rowToImport[2] = "f_ad_street"; // C : Straße und Hausnummer
$rowToImport[3] = "f_ad_zipcode"; // D : PLZ
$rowToImport[4] = "f_ad_city"; // E : Ort
$rowToImport[5] = "f_tr_commission_no"; // F : Kommissionsnummer (=> Kundennummer.)
// $rowToImport[5] = "f_search"; // F : Suchfelder (=! GDC.search)
$rowToImport[6] = "f_dummy_01"; // G : ?
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
// Check for existing headline
if ($j > 0) :
$f_lfd = mcStrWrap($f_lfd);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_ad_street = mcStrWrap($f_ad_street);
$f_tr_hsno = "";
$f_ad_zipcode = mcStrWrap($f_ad_zipcode);
$f_ad_city = mcStrWrap($f_ad_city);
$f_tr_commission_no = mcStrWrap($f_tr_commission_no);
// $f_tr_phone = mcStrWrap($f_tr_phone);
$f_search = mcStrWrap($f_search);
$f_cash = mcStrWrap($f_cash);
if ($f_tr_hsno == "") : $f_tr_hsno = "."; endif;
$f_tr_phone = eregPhoneNo_MC($f_tr_phone);
$f_ad_country = "DE";
$clockTime = "09:00:00";
$f_jb_ordertime = $currentDate . " " . $clockTime;
// **** Check zone of given zipcode for the customer ****
$srvzNo = "";
$srvzName = "";
// Get srvp_id from serviceplz
$srvpId = getFieldValueFromId("phoenix.serviceplz", "srvp_plz", $f_ad_zipcode, "srvp_id");
if ($srvpId != "") :
// If country "Germany" then fill zipcode with "0" up to 5 chars
if ($f_ad_country == "DE") :
$f_ad_zipcode = pad($f_ad_zipcode, 5);
endif;
// Get zone ids (primary key) of the current customer
// $srvzIdArray = getColVectorFromDB2ArrayByClause("phoenix.servicezone", "srvz_id", "hq_id = '" . $hqId . "' AND cs_id = '" . $csId . "'");
// $srvzIdArrayLen = count($srvzIdArray);
// => Zones got for customer before entering the loops (!!!!)
// if ($srvzIdArrayLen > 0) :
// Get zone id from mapping
$srvz_id = getFieldValueFromClause("phoenix.servicezonemapping", "srvz_id", "srvp_id = '" . $srvpId . "' AND srvz_id IN (" . implode(",", $srvzIdArray) . ")");
if ($srvz_id != "") :
$srvzNo = getFieldValueFromId("phoenix.servicezone", "srvz_id", $srvz_id, "srvz_no");
$srvzName = getFieldValueFromId("phoenix.servicezone", "srvz_id", $srvz_id, "srvz_name");
else :
$outText .= getLngt("Die PLZ " . $f_ad_zipcode . " ist keiner Zone des Kunden zugeordnet! Wurden PLZn den Zonendaten assoziiert?") . "<br>";
endif;
// else :
// $outText .= getLngt("Für den Kunden " . $csEid . " werden derzeit keine Zonen im Datenbestand geführt!") . "<br>";
// endif;
else :
$outText .= getLngt("PLZ " . $f_ad_zipcode . " wird im Basisdatenbestand nicht geführt!") . "<br>";
endif;
if ($srvzNo != "") :
// **** Courier ****
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_jb_tourname];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
*/
$crEid = $tourCourierArray[$f_jb_tourname];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
endif;
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
$jbStatus = "1";
$jbTaketime = $currentTime;
endif;
$jbType = "";
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
$f_tr_ware_from_to = 0;
// $f_jb_tourname = $csEid . ": Zone " . $srvzNo;
$f_jb_tourname = "";
$f_tr_remark = "";
$f_searchArr = array();
if ($f_search != "") :
$f_searchArr = explode(",", $f_search);
$f_tr_remark .= $f_search;
endif;
$f_searchArrLen = count($f_searchArr);
if ($f_cash != "") :
if ($f_tr_remark != "") : $f_tr_remark .= " || "; endif;
$f_tr_remark .= "**** BARZAHLUNG ****";
endif;
echo $f_lfd . ";" . $f_tr_comp . ";" . $f_ad_street . ";" . $f_tr_hsno . ";" . $f_ad_zipcode . ";" . $f_ad_city . ";" . $f_tr_commission_no . ";";
// echo $f_tr_phone . ";" . $f_cash . ";";
echo "<br>";
// Check for existence of the imported "tour name" AND "station number" (unique for station)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$csId . "_" . $currentDate . "_" . $j . "_" . $f_tr_commission_no,"gdc_context","BMW"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if BMW number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
// Insert address
$noValidationOfAddress = true;
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($jbZoneIdArray[$srvzNo] == "") :
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", "", "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbZoneIdArray[$srvzNo] = getLastInsertId();
$jbTrSortArray[$jbZoneIdArray[$srvzNo]] = 1;
// Insert pick up station after job is generated
if ($jbZoneIdArray[$srvzNo] != "") :
insertStmt("tour", array("jb_id", $jbZoneIdArray[$srvzNo], "ad_id", $adIdFrom, "tr_sort", "1", "tr_comp", $trCompFrom, "tr_comp2", "",
"tr_hsno", $trHsnoFrom, "tr_floor", $trFloorFrom, "csc_id", $cscIdPayer, "tr_status", $trStatus, "tr_finishtime", $trFinishtime,
"tr_commission_no", "", "tr_ware_from_to", $f_tr_ware_from_to, "tr_person", "", "tr_phone", "", "tr_remark", ""));
$jbTrIdArray[$jbZoneIdArray[$srvzNo]][1] = getLastInsertID();
$jbTourdataZipcodeArray[$jbZoneIdArray[$srvzNo]][] = $adZipcodeFrom;
$jbTourdataCityArray[$jbZoneIdArray[$srvzNo]][] = $adCityFrom;
$jbTourdataCountryArray[$jbZoneIdArray[$srvzNo]][] = $adCountryFrom;
endif;
endif;
// Check for inserted job
if ($jbZoneIdArray[$srvzNo] != "") :
$jbTrSortArray[$jbZoneIdArray[$srvzNo]]++;
insertStmt("tour", array("jb_id", $jbZoneIdArray[$srvzNo], "ad_id", $ad_id_new, "tr_sort", $jbTrSortArray[$jbZoneIdArray[$srvzNo]], "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$jbTrIdArray[$jbZoneIdArray[$srvzNo]][$jbTrSortArray[$jbZoneIdArray[$srvzNo]]] = getLastInsertID();
// Insert tourservice data
insertStmt("tourservice", array("jb_id", $jbZoneIdArray[$srvzNo], "csc_id", $cscIdPayer, "tr_sort", $jbTrSortArray[$jbZoneIdArray[$srvzNo]], "srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "", "trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// Tourname
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $jbTrIdArray[$jbZoneIdArray[$srvzNo]][$jbTrSortArray[$jbZoneIdArray[$srvzNo]]], "gdc_gen_fieldname", "check_exist", "gdc_content", $csId . "_" . $currentDate . "_" . $j . "_" . $f_tr_commission_no, "gdc_context", "BMW"));
$jbTourdataZipcodeArray[$jbZoneIdArray[$srvzNo]][] = $f_ad_zipcode;
$jbTourdataCityArray[$jbZoneIdArray[$srvzNo]][] = $f_ad_city;
$jbTourdataCountryArray[$jbZoneIdArray[$srvzNo]][] = $f_ad_country;
// Search values
if ($f_searchArrLen > 0) :
for ($s = 0; $s < $f_searchArrLen; $s++) :
$gdcJbSearchVal = trim($f_searchArr[$s]);
if ($gdcJbSearchVal != "" && strlen($gdcJbSearchVal) > 3) :
insertStmt("genericdatacontainer", array("gdc_obj_type", "jb", "gdc_obj_id", $jbZoneIdArray[$srvzNo], "gdc_gen_fieldname", "search", "gdc_content", $gdcJbSearchVal, "gdc_context", "SEARCH.JOB.BMW"));
endif;
endfor;
endif;
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $currentDate . " " . $f_lfd . "]<br>";
endif;
else :
$outText .= getLngt("Eine gültige Zonen-ID liegt nicht vor! Es erfolgte kein Import!") . " [" . $f_lfd . "]<br>";
endif;
endif; // Check for headline
}
// If at least one imported job does exist ($jbIdNew > 0) then finalize last imported job
// Write "jb_tourdata" of the job currently imported and write log regarding B2B-Import
if ($fire && $executeImportProcess == "1") :
$jbTourdataZipcodeKeysArray = array_keys($jbTourdataZipcodeArray); // The keys are job IDs
$jbTourdataZipcodeKeysArrayLen = count($jbTourdataZipcodeKeysArray);
if ($jbTourdataZipcodeKeysArrayLen > 0) :
for ($k = 0; $k < $jbTourdataZipcodeKeysArrayLen; $k++) :
$jbId = $jbTourdataZipcodeKeysArray[$k];
if ($jbId != "") :
$jbTourdata = implode(";", $jbTourdataZipcodeArray[$jbId]) . "|" . implode(";", $jbTourdataCityArray[$jbId]) . "|" . implode(";", $jbTourdataCountryArray[$jbId]);
updateStmt("job","jb_id",$jbId,array("jb_tourdata",$jbTourdata));
writeToLogDB("102",$hqId,$jbId,$usr_id,"","",$csId,"B2B_IMPORT=1"); // Success!
endif;
endfor;
endif;
endif;
// Sort jobs after all operations are done well (same loop !!!!)
if ($fire && $executeImportProcess == "1") :
$jbTourdataZipcodeKeysArray = array_keys($jbTourdataZipcodeArray); // The keys are job IDs
$jbTourdataZipcodeKeysArrayLen = count($jbTourdataZipcodeKeysArray);
if ($jbTourdataZipcodeKeysArrayLen > 0) :
for ($k = 0; $k < $jbTourdataZipcodeKeysArrayLen; $k++) :
$jbId = $jbTourdataZipcodeKeysArray[$k];
if ($jbId != "") :
$optResult = XSplanTourJob($jbId);
if ($optResult) :
$outText .= getLngt("Der Auftrag " . $jbId . " konnte optimiert werden!<br>");
else :
$outText .= getLngt("Der Auftrag " . $jbId . " konnte NICHT optimiert werden!<br>");
endif;
endif;
endfor;
endif;
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Für den Kunden " . $csEid . " sind keine Zonen angelegt!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_BMW.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,592 @@
<?php
/*=======================================================================
*
* import_COUNT.php ["Count"-Kunden wie "Tims Kanadische Backwaren"]
*
* Autor: Marc Vollmann
*
=======================================================================*/
/*
- Variation von "TOURS" (Beschreibung siehe "import_TOURS.php")
- Startzeit von 09 auf 06 Uhr
*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
// Init
$jbIdNew = "";
$jbTourdata = "";
$jbTourdataZipcode = "";
$jbTourdataCity = "";
$jbTourdataCountry = "";
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strrpos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
/*
$tourVehicleArray = array();
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
*/
$tourCourierArray = array();
/*
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
$tourCourierArray["294505"] = "e8020205";
$tourCourierArray["294506"] = "e8020206";
$tourCourierArray["294507"] = "e8020207";
$tourCourierArray["294508"] = "e8020208";
$tourCourierArray["294509"] = "e8020209";
$tourCourierArray["294510"] = "e8020210";
$tourCourierArray["294511"] = "e8020211";
$tourCourierArray["294512"] = "e8020212";
$tourCourierArray["294590"] = "e8020213";
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
return $aStr;
}
echo "importFile" . $importFile . "<br>";
echo "hqId" . $hqId . "<br>";
echo "csId" . $csId . "<br>";
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_COUNT_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$jbIdNew = 0;
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_TOURS_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
$rowToImport[0] = "f_no_row"; // A : (Laufende) Nr. (Datensatz)
$rowToImport[1] = "f_jb_tourname"; // B : Auftrag Bezeichnung (Tourname)
$rowToImport[2] = "f_tr_commission_no"; // C : Station Kommissionsnummer
$rowToImport[3] = "f_tr_comp"; // D : Station Bezeichnung
$rowToImport[4] = "f_tr_remark"; // E : Station Bemerkung
$rowToImport[5] = "f_tr_sort"; // F : Station Position in Tour
$rowToImport[6] = "f_ad_zipcode"; // G : Station PLZ
$rowToImport[7] = "f_ad_city"; // H : Station Ort
$rowToImport[8] = "f_ad_street"; // I : Station Straße
$rowToImport[9] = "f_tr_hsno"; // J : Station Hausnummer
$rowToImport[10] = "f_tr_arrival_time"; // K : Station Ankunft
$rowToImport[11] = "f_tr_departure_time"; // L : Station Abfahrt
$rowToImport[12] = "f_tr_point2point_time"; // M : Station Strecke
$rowToImport[13] = "f_tr_point2point_min"; // N : Auftrag Fixe Dauer
$rowToImport[14] = "f_dummy_01"; // O : ?
endif;
// Special handling
$parFieldCmpComp = getParameterValue("0", "IMPORT_TOURS_FIELD_TR_COMP", $hqId);
if ($parFieldCmpComp == "") : $parFieldCmpComp = getParameterValue("0", "IMPORT_TOURS_FIELD_TR_COMP", "0"); endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_no_row = mcStrWrap($f_no_row);
$f_jb_tourname = mcStrWrap($f_jb_tourname);
$f_tr_commission_no = mcStrWrap($f_tr_commission_no);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_tr_remark = mcStrWrap($f_tr_remark);
$f_tr_sort = mcStrWrap($f_tr_sort);
$f_ad_zipcode = mcStrWrap($f_ad_zipcode);
$f_ad_city = mcStrWrap($f_ad_city);
$f_ad_street = mcStrWrap($f_ad_street);
$f_tr_hsno = mcStrWrap($f_tr_hsno);
$f_tr_arrival_time = mcStrWrap($f_tr_arrival_time);
$f_tr_departure_time = mcStrWrap($f_tr_departure_time);
$f_tr_point2point_time = mcStrWrap($f_tr_point2point_time);
$f_tr_point2point_min = mcStrWrap($f_tr_point2point_min);
// Check for existing headline
if ($j > 0 || ($f_no_row != "" && is_numeric($f_no_row))) :
if ($parFieldCmpComp == "0") :
$tmpArray = spliti("_", $f_tr_comp);
// Do nothing
elseif ($parFieldCmpComp == "1") :
$tmpArray = spliti("__", $f_tr_comp); // Two underline chars as delimiter
$f_tr_person = $tmpArray[1];
$f_tr_comp = $tmpArray[0];
else :
// Default
$tmpArray = spliti("_", $f_tr_comp);
$f_tr_person = $tmpArray[0];
endif;
$tmpArray = spliti("_", $f_tr_remark);
$f_tr_phone = $tmpArray[2];
$f_tr_phone = str_replace ("Tel:", "", $f_tr_phone);
$f_tr_phone = eregPhoneNo($f_tr_phone);
if ($f_tr_hsno == "") :
$f_tr_hsno = ".";
endif;
if ($f_tr_arrival_time != "") :
$f_tr_remark .= "\n\nAnkunft: " . $f_tr_arrival_time;
endif;
if ($f_tr_departure_time != "") :
$f_tr_remark .= "\n\nAbfahrt" . $f_tr_departure_time;
endif;
// $f_tr_remark .= $f_tr_point2point_time
// $f_tr_remark .= $f_tr_point2point_min
// Move commission number to station remark
if ($f_tr_commission_no != "") :
$f_tr_remark .= "\n\n[*" . $f_tr_commission_no . "*]";
$f_tr_commission_no = "";
endif;
// Clock time depends on headquarters
$clockTime = "06:00:00";
/*
if ($hqId == "3") :
$clockTime = "12:45:00";
endif;
*/
if ($f_jb_tourname != "") :
$f_jb_orderdate = substr($f_jb_tourname, -8);
$f_jb_ordertime = "20" . substr($f_jb_orderdate,6,2) . "-" . substr($f_jb_orderdate,2,2) . "-" . substr($f_jb_orderdate,0,2) . " " . $clockTime;
endif;
// The first row of the tour contains the tour name. The following rows of the same tour are empty for $f_jb_tourname !!!!
if ($f_jb_tourname == "") :
$f_jb_tourname = $remTourNo;
endif;
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_jb_tourname];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
*/
$crEid = $tourCourierArray[$f_jb_tourname];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
endif;
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
$jbStatus = "1";
$jbTaketime = $currentTime;
endif;
$jbType = "";
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo $f_no_row . ";" . $f_jb_tourname . ";" . $f_tr_commission_no . ";" . $f_tr_comp . ";" . $f_tr_remark . ";" . $f_tr_sort . ";" . $f_ad_zipcode . ";";
echo $f_ad_city . ";" . $f_ad_street . ";" . $f_tr_hsno;
// echo ";" . $f_tr_arrival_time . ";" . $f_tr_departure_time . ";" . $f_tr_point2point_time . ";";
// echo $f_tr_point2point_min . ";" . $f_tr_person . ";" . $f_tr_phone . ";" . $f_jb_ordertime;
echo "<br>";
// Check for existence of the imported "tour name" AND "station number" (unique for station)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_jb_tourname . " " . $f_tr_sort,"gdc_context","COUNT"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if TOURS number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = true;
if ($remTourNo == "" || $remTourNo == $f_jb_tourname) :
if ($jbTourdataZipcode != "") : $jbTourdataZipcode .= ";"; endif;
$jbTourdataZipcode .= $f_ad_zipcode;
if ($jbTourdataCity != "") : $jbTourdataCity .= ";"; endif;
$jbTourdataCity .= $f_ad_city;
if ($jbTourdataCountry != "") : $jbTourdataCountry .= ";"; endif;
$jbTourdataCountry .= "DE";
endif;
// Insert address
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_jb_tourname) :
// Finalize currently imported job
// Write "jb_tourdata" of the job currently imported
if ($remTourNo != "" && $jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// Remove existing tourname
updateStmt("job","jb_tourname",$f_jb_tourname,array("jb_tourname",""), "jb_tourname = '" . $f_jb_tourname . "'");
// Tour data
/*
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
*/
$jbIdNew = ""; // Init
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbIdNew = getLastInsertId();
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$remTourNo = $f_jb_tourname;
// Init for the next job to be imported
$jbTourdata = "";
// Init with current values
$jbTourdataZipcode = $f_ad_zipcode;
$jbTourdataCity = $f_ad_city;
$jbTourdataCountry = "DE";
endif;
// Check for inserted job
if ($jbIdNew != "") :
$trSort++;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
// Insert tourservice data
/*
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
*/
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort, "srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "", "trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// Tourname
// insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_0", "gdc_content", $f_jb_tourname . " " . $f_tr_sort, "gdc_context", "COUNT"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_jb_tourname . " " . $f_tr_sort, "gdc_context", "COUNT"));
// Insert tourarticle data (delivery stations)
/*
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
*/
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
/*
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
*/
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_jb_tourname . " " . $f_tr_sort . "]<br>";
endif;
endif; // Check for headline
}
// If at least onne imported job does exist ($jbIdNew > 0) then finalize last imported job
// Write "jb_tourdata" of the job currently imported
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_COUNT.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

565
html/import/import_DHL.php Normal file
View File

@@ -0,0 +1,565 @@
<?php
/*=======================================================================
*
* import_DHL.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
// Init
$jbIdNew = "";
$jbTourdata = "";
$jbTourdataZipcode = "";
$jbTourdataCity = "";
$jbTourdataCountry = "";
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strrpos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
/*
$tourVehicleArray = array();
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
*/
$tourCourierArray = array();
/*
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
$tourCourierArray["294505"] = "e8020205";
$tourCourierArray["294506"] = "e8020206";
$tourCourierArray["294507"] = "e8020207";
$tourCourierArray["294508"] = "e8020208";
$tourCourierArray["294509"] = "e8020209";
$tourCourierArray["294510"] = "e8020210";
$tourCourierArray["294511"] = "e8020211";
$tourCourierArray["294512"] = "e8020212";
$tourCourierArray["294590"] = "e8020213";
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
return $aStr;
}
echo "importFile" . $importFile . "<br>";
echo "hqId" . $hqId . "<br>";
echo "csId" . $csId . "<br>";
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_DHL_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$jbIdNew = 0;
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_DHL_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
/*
Nr. Tour Bezeichnung Tourelement Bezeichnung Auftrag Bemerkungen Tourelement Position in Tour Tourelement PLZ Tourelement Ort Tourelement Straße Tourelement Hausnummer Tourelement Ankunft Tourelement Abfahrt Tourelement Strecke Auftrag Fixe Dauer
*/
$rowToImport[0] = "f_no_row"; // A : (Laufende) Nr. (Datensatz)
$rowToImport[1] = "f_jb_tourname"; // B : Tour Bezeichnung
$rowToImport[2] = "f_tr_comp"; // C : Tourelement Bezeichnung
$rowToImport[3] = "f_tr_remark"; // D : Auftrag Bemerkungen
$rowToImport[4] = "f_tr_sort"; // E : Tourelement Position in Tour
$rowToImport[5] = "f_ad_zipcode"; // F : Tourelement PLZ
$rowToImport[6] = "f_ad_city"; // G : Tourelement Ort
$rowToImport[7] = "f_ad_street"; // H : Tourelement Straße
$rowToImport[8] = "f_tr_hsno"; // I : Tourelement Hausnummer
$rowToImport[9] = "f_tr_arrival_time"; // J : Tourelement Ankunft
$rowToImport[10] = "f_tr_departure_time"; // K : Tourelement Abfahrt
$rowToImport[11] = "f_tr_point2point_time"; // L : Tourelement Strecke
$rowToImport[12] = "f_tr_point2point_min"; // M : Auftrag Fixe Dauer
$rowToImport[13] = "f_dummy_01"; // N : ?
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_no_row = mcStrWrap($f_no_row);
$f_jb_tourname = mcStrWrap($f_jb_tourname);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_tr_remark = mcStrWrap($f_tr_remark);
$f_tr_sort = mcStrWrap($f_tr_sort);
$f_ad_zipcode = mcStrWrap($f_ad_zipcode);
$f_ad_city = mcStrWrap($f_ad_city);
$f_ad_street = mcStrWrap($f_ad_street);
$f_tr_hsno = mcStrWrap($f_tr_hsno);
$f_tr_arrival_time = mcStrWrap($f_tr_arrival_time);
$f_tr_departure_time = mcStrWrap($f_tr_departure_time);
$f_tr_point2point_time = mcStrWrap($f_tr_point2point_time);
$f_tr_point2point_min = mcStrWrap($f_tr_point2point_min);
// Check for existing headline
if ($j > 0 || ($f_no_row != "" && is_numeric($f_no_row))) :
$tmpArray = spliti("_", $f_tr_comp);
$f_tr_person = $tmpArray[0];
$tmpArray = spliti("_", $f_tr_remark);
$f_tr_phone = $tmpArray[2];
$f_tr_phone = str_replace ("Tel:", "", $f_tr_phone);
$f_tr_phone = eregPhoneNo($f_tr_phone);
if ($f_tr_hsno == "") :
$f_tr_hsno = ".";
endif;
if ($f_tr_arrival_time != "") :
$f_tr_remark .= "\n\nAnkunft: " . $f_tr_arrival_time;
endif;
if ($f_tr_departure_time != "") :
$f_tr_remark .= "\n\nAbfahrt" . $f_tr_departure_time;
endif;
// $f_tr_remark .= $f_tr_point2point_time
// $f_tr_remark .= $f_tr_point2point_min
// Clock time depends on headquarters
$clockTime = "17:45:00";
if ($hqId == "3") :
$clockTime = "12:45:00";
endif;
if ($f_jb_tourname != "") :
$f_jb_orderdate = substr($f_jb_tourname, -8);
$f_jb_ordertime = "20" . substr($f_jb_orderdate,6,2) . "-" . substr($f_jb_orderdate,3,2) . "-" . substr($f_jb_orderdate,0,2) . " " . $clockTime;
endif;
// The first row of the tour contains the tour name. The following rows of the same tour are empty for $f_jb_tourname !!!!
if ($f_jb_tourname == "") :
$f_jb_tourname = $remTourNo;
endif;
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_jb_tourname];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
*/
$crEid = $tourCourierArray[$f_jb_tourname];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
endif;
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
$jbStatus = "1";
$jbTaketime = $currentTime;
endif;
$jbType = "";
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo $f_no_row . ";" . $f_jb_tourname . ";" . $f_tr_comp . ";" . $f_tr_remark . ";" . $f_tr_sort . ";" . $f_ad_zipcode . ";";
echo $f_ad_city . ";" . $f_ad_street . ";" . $f_tr_hsno . ";" . $f_tr_arrival_time . ";" . $f_tr_departure_time . ";" . $f_tr_point2point_time . ";";
echo $f_tr_point2point_min . ";" . $f_tr_person . ";" . $f_tr_phone . ";" . $f_jb_ordertime;
echo "<br>";
// Check for existence of the imported "tour name" AND "station number" (unique for station)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_jb_tourname . " " . $f_tr_sort,"gdc_context","DHL"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if DHL number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = true;
if ($remTourNo == "" || $remTourNo == $f_jb_tourname) :
if ($jbTourdataZipcode != "") : $jbTourdataZipcode .= ";"; endif;
$jbTourdataZipcode .= $f_ad_zipcode;
if ($jbTourdataCity != "") : $jbTourdataCity .= ";"; endif;
$jbTourdataCity .= $f_ad_city;
if ($jbTourdataCountry != "") : $jbTourdataCountry .= ";"; endif;
$jbTourdataCountry .= "DE";
endif;
// Insert address
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_jb_tourname) :
// Finalize currently imported job
// Write "jb_tourdata" of the job currently imported
if ($remTourNo != "" && $jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// Remove existing tourname
updateStmt("job","jb_tourname",$f_jb_tourname,array("jb_tourname",""), "jb_tourname = '" . $f_jb_tourname . "'");
// Tour data
/*
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
*/
$jbIdNew = ""; // Init
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbIdNew = getLastInsertId();
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$remTourNo = $f_jb_tourname;
// Init for the next job to be imported
$jbTourdata = "";
// Init with current values
$jbTourdataZipcode = $f_ad_zipcode;
$jbTourdataCity = $f_ad_city;
$jbTourdataCountry = "DE";
endif;
// Check for inserted job
if ($jbIdNew != "") :
$trSort++;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
// Insert tourservice data
/*
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
*/
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort, "srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "", "trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// Tourname
// insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_0", "gdc_content", $f_jb_tourname . " " . $f_tr_sort, "gdc_context", "DHL"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_jb_tourname . " " . $f_tr_sort, "gdc_context", "DHL"));
// Insert tourarticle data (delivery stations)
/*
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
*/
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
/*
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
*/
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_jb_tourname . " " . $f_tr_sort . "]<br>";
endif;
endif; // Check for headline
}
// If at least onne imported job does exist ($jbIdNew > 0) then finalize last imported job
// Write "jb_tourdata" of the job currently imported
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_DHL.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,304 @@
<?php
/*=======================================================================
*
* import_EXPRESS.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
include_once ("../import/import.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT EXPRESS");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = true;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true;
// Customer and headquarters references have to exist
$hqId = "";
$csEid = "";
$objType = trim($objType);
$objId = trim($objId);
if ($objType == "CS" && is_numeric($objId)) :
$csId = getFieldValueFromId("phoenix.customer", "cs_id", $objId, "cs_id");
endif;
if ($csId != "") :
$hqId = getFieldValueFromId("phoenix.customer", "cs_id", $csId, "hq_id");
$csEid = getFieldValueFromId("phoenix.customer", "cs_id", $csId, "cs_eid");
// Get zone IDs because an update of zipcodes has to be filtered by the zones of the current customer
$srvzIdArray = getColVectorFromDB2ArrayByClause("servicezone", "srvz_id", "cs_id = '" . $csId . "'", "", "", "");
$srvzIdArrayLen = count($srvzIdArray);
endif;
if ($debug) :
echo "f_act : " . $f_act . "<br>";
echo "objType : " . $objType . "<br>";
echo "objId : " . $objId . "<br>";
echo "hqId : " . $hqId . "<br>";
echo "csId : " . $csId . "<br>";
echo "srvzIdArray : " . implode(",", $srvzIdArray) . "<br>";
echo "<br>";
endif;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
if ($importFile != "") :
if ($hqId != "" && $csId != "" && $srvzIdArrayLen > 0) :
// Create internal representation
$srvpArray = array();
$srvzIdsOfCurrentCustomer = implode(",", $srvzIdArray); // Zone IDs of the current customer
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
$executionCount = 0;
$failedCount = 0;
// ********************
// * IMPORT FILE zone *
// ********************
if (!(strpos($filename, "import_EXPRESS_") === false)) :
// PLZ
// 22844
// 22850
// ...
// 22xxx
// ...
$rowToImport = array();
$rowToImport[0] = "f_zipcode";
$rowToImport[1] = "f_price";
$rowToImport[2] = "f_dummy";
$rowToImportLen = count($rowToImport);
// read file to import
$data = importCSV($importFile, $delimiter);
$dataLen = count($data);
// loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_zipcode = removeFieldSigns($f_zipcode);
$f_price = str_replace(",", ".", $f_price);
if ($f_price == "" || !is_numeric($f_price)) :
$f_price = "0.00";
endif;
$f_country = "";
if ($f_zipcode != "") :
if ($f_country == "" || !existsEntry("phoenix_special.country",array("cou_iso_2",$f_country))) :
$f_country = "DE";
endif;
// Get srvp_id from serviceplz
$srvpId = getFieldValueFromId("phoenix.serviceplz", "srvp_plz", $f_zipcode, "srvp_id");
if ($srvpId != "") :
// If country "Germany" then fill zipcode with "0" up to 5 chars
if ($f_country == "DE") :
$f_zipcode = pad($f_zipcode, 5);
endif;
// Set arrays
$srvpArray[] = array($f_zipcode, $srvpId, $f_country, $f_price);
else :
$outText .= getLngt("PLZ " . $f_zipcode . " wird im Basisdatenbestand nicht geführt!") . "<br>";
endif;
else :
$outText .= getLngt("Keine PLZ im Datensatz!") . "<br>";
endif;
}
// Insert new zone zipcodes into the database from internal structure
if ($fire && $executeImportProcess == "1") :
$srvpArrayLen = count($srvpArray);
TA("B");
// Remove ALL EXPRESS associations for the CURRENT CUSTOMER
updateStmt("phoenix.servicezonemapping", "", "", array("srvzm_mt_1", "0.00"), "srvz_id IN (" . $srvzIdsOfCurrentCustomer . ")");
// Associate zipcodes to be enabled for EXPRESS for the current customer
for ($k = 0; $k < $srvpArrayLen; $k++) :
$res = updateStmt("phoenix.servicezonemapping", "srvp_id", $srvpArray[$k][1], array("srvzm_mt_1", $srvpArray[$k][3]), "srvz_id IN (" . $srvzIdsOfCurrentCustomer . ")");
// Check update for success
if ($db->affected_rows > 0) :
$executionCount++;
$outText .= getLngt("Update PLZ:") . " " . $srvpArray[$k][0] . " " . getLngt("mit Preis") . " " . $srvpArray[$k][3] . "<br>";
else :
$failedCount++;
endif;
endfor;
TA("C");
TA("E");
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
$outText .= getLngt("Nicht verarbeitete Einträge: " . $failedCount . "<br>");
// $closeWindow = "1";
endif;
endif;
// ********************
// * IMPORT FILE xxxx *
// ********************
// if (!(strpos($filename, "import_xxxx") === false)) :
// endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Diese Datei muss für einen bestimmten Kunden verarbeitet werden!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_EXPRESS.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

672
html/import/import_FAMO.php Normal file
View File

@@ -0,0 +1,672 @@
<?php
/*=======================================================================
*
* import_FAMO.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Get special user types from parameter
$specialUserTypeIsLoggedIn = false;
$specialUserType = "";
$specialUserHqId = "";
$specialUserFTPServerList = "";
$specialUserDirSpecialForObjType = "";
$userTypesSpecialArray = getDatatransferSpecialUserData($userType);
if (count($userTypesSpecialArray) > 0) :
$specialUserTypeIsLoggedIn = true;
list($specialUserType, $specialUserHqId, $specialUserFTPServerList, $specialUserObjType, $specialUserObjId, $specialUserDirSpecialForObjType) = $userTypesSpecialArray;
if ($objType == $specialUserObjType && $objId == $specialUserObjType) :
$hqId = $specialUserHqId;
endif;
endif;
// Check for authentication access
$empHasAdminRights = false;
if (!$specialUserTypeIsLoggedIn) :
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csId = "";
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
$csAddress = array();
$adIdFrom = 0;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
// $csAddress = getAddress($csId, "customer");
$csAddress = getAddress($csId, "costcenteraddress");
$adIdFrom = $csAddress["id"];
// USE FOLLOWING FIX ADDRESS
// $adIdFrom = "220594"; // Invoice address
// $adIdFrom = "125964"; // Pick-up address
// $trHsnoFrom = "4";
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
$pickUpStationFinishedByDefault = false;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
$tourVehicleArray = array();
if ($hqId == "9000") :
// ESSEN
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
elseif ($hqId == "9001") :
// NÜRNBERG
/*
$tourVehicleArray["299001"] = "N156";
$tourVehicleArray["299002"] = "N157";
$tourVehicleArray["299003"] = "N153";
$tourVehicleArray["299004"] = "N154";
$tourVehicleArray["299005"] = "N155";
$tourVehicleArray["299050"] = "N106";
*/
endif;
$tourCourierArray = array();
if ($hqId == "9000") :
// ESSEN
$tourCourierArray["294590"] = "e8020401"; // stepenka 01
$tourCourierArray["294501"] = "e8020402"; // stepenka 02
$tourCourierArray["294502"] = "e8020403"; // stepenka 03
$tourCourierArray["294503"] = "e8020404"; // stepneka 04
$tourCourierArray["294504"] = "e8020405"; // stepenka 05
$tourCourierArray["294505"] = "e8020406"; // stepenka 06
$tourCourierArray["294506"] = "e8020407"; // stepenka 07
$tourCourierArray["294507"] = "e8020408"; // stepenka 08
$tourCourierArray["294508"] = "e8020409"; // stepenka 09
$tourCourierArray["294509"] = "e8020410"; // stepenka 10
$tourCourierArray["294510"] = "e8020411"; // stepenka 11
$tourCourierArray["294511"] = "e8020412"; // stepneka 12
$tourCourierArray["294512"] = "e8020413"; // stepenka 13
$tourCourierArray["294513"] = "e8020414"; // stepenka 14
elseif ($hqId == "9001") :
// NÜRNBERG
$tourCourierArray["299001"] = "n8124502"; // Hokamp Benjamin 0157 84862698
$tourCourierArray["299002"] = "n8124503"; // Schulz Michael 0152 53666367
$tourCourierArray["299003"] = "n8124504"; // Möller Rene 0171 5823128
$tourCourierArray["299004"] = "n8124505"; // Kirschner Sascha 0152 53910965
$tourCourierArray["299005"] = "n8124506"; // Schulz Thomas 0176 24177518
$tourCourierArray["299050"] = "n8124507"; // Holler Stefan 0157 35374266
endif;
// SID array (fix!)
$tourSIDArray = array();
if ($hqId == "9000") :
// ESSEN
$tourSIDArray["294590"] = "E355";
$tourSIDArray["294501"] = "E356";
$tourSIDArray["294502"] = "E357";
$tourSIDArray["294503"] = "E358";
$tourSIDArray["294504"] = "E359";
$tourSIDArray["294505"] = "E360";
$tourSIDArray["294506"] = "E361";
$tourSIDArray["294507"] = "E362";
$tourSIDArray["294508"] = "E363";
$tourSIDArray["294509"] = "E364";
$tourSIDArray["294510"] = "E365";
$tourSIDArray["294511"] = "E366";
$tourSIDArray["294512"] = "E367";
$tourSIDArray["294513"] = "E368";
elseif ($hqId == "9001") :
// NÜRNBERG
$tourSIDArray["299001"] = "N156";
$tourSIDArray["299002"] = "N157";
$tourSIDArray["299003"] = "N153";
$tourSIDArray["299004"] = "N154";
$tourSIDArray["299005"] = "N155";
$tourSIDArray["299050"] = "N106";
endif;
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
return $aStr;
}
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_FAMO_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
// Check for existence of the imported order number (for the same day ONLY)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","cs","gdc_obj_id",$csId,"gdc_gen_fieldname","check_exist","gdc_content",$currentDate,"gdc_context","FAMO"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if FAMO number does exist !!!!
if (!$gdcEntryExists) :
$remTourNo = "";
$remTrSort = "";
$jbIdNew = 0;
$trSort = 2; // Init for 2nd station equals first delivery !!!!
$tratSort = 1; // Init all serial numbers !!!!
$jobNewArray = array();
$useJbNewArray = false;
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_FAMO_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
/*
A= Ausliefertag
B= Fortlaufende Nummer je Tour
C= Leer
D= Fahrzeug
E= Kundennummer / Kunden von Famo
F= Auftragsnummer Famo
G= Reihenfolge der Tour
H= leer
I= leer
J= Zeitfenster der von uns geplanten Anlieferung
K= PLZ
L= Ort
M= Straße
N = Kundenname
O= Brauchen wir aber im Votian Import nicht
P= Artikelnummer ( Brauchen wir aber im Votian Import nicht)
Q= Brauchen wir aber im Votian Import nicht
R= Brauchen wir aber im Votian Import nicht
S= Brauchen wir aber im Votian Import nicht
T= Brauchen wir aber im Votian Import nicht
*/
$rowToImport[0] = "f_jb_orderdate"; // A : Bearbeitungsdatum (Ausführungsdatum)
$rowToImport[1] = "f_tour_no"; // B : Tour
$rowToImport[2] = "f_dummy_01"; // C : ?
$rowToImport[3] = "f_vehicle_id"; // D : Fahrzeug
$rowToImport[4] = "f_customer_id"; // E : Warenempfänger (spezielle Kundennummer)
$rowToImport[5] = "f_order_id"; // F : Fremdauftragsnummer
$rowToImport[6] = "f_tr_sort"; // G : Station
$rowToImport[7] = "f_dummy_02"; // H : ?
$rowToImport[8] = "f_dummy_03"; // I : ?
$rowToImport[9] = "f_jb_warningtime"; // J : Gewünschte Anlieferzeit am Ausführungstag
$rowToImport[10] = "f_ad_zipcode"; // K : Adresse.PLZ
$rowToImport[11] = "f_ad_city"; // L : Adresse.Ort
$rowToImport[12] = "f_ad_street_hsno"; // M : Adresse.Straße_Hausnummer
$rowToImport[13] = "f_tr_comp"; // N : Firma Anlieferung
$rowToImport[14] = "f_dummy_04"; // O : ?
$rowToImport[15] = "f_trat_name"; // P : Artikelnummer (Bemerkung)
$rowToImport[16] = "f_dummy_05"; // Q : ?
$rowToImport[17] = "f_trat_data"; // R : Artikeldaten (Bemerkung)
$rowToImport[18] = "f_trat_data2"; // S : Artikeldaten (Bemerkung)
$rowToImport[19] = "f_dummy_08"; // T : ?
// "f_tr_cs_freetext","f_tr_comp2","f_ad_country","f_trat_packingpieces","f_trat_palets","f_trat_weight","f_tr_phone"
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_tour_no = mcStrWrap($f_tour_no);
$f_vehicle_id = mcStrWrap($f_vehicle_id);
$f_jb_orderdate = mcStrWrap($f_jb_orderdate);
$f_jb_ordertime = "20" . substr($f_jb_orderdate, 4,2) . "-" . substr($f_jb_orderdate, 2,2) . "-" . substr($f_jb_orderdate, 0,2);
$f_jb_warningtime = mcStrWrap($f_jb_warningtime);
$f_jb_warningtime = $f_jb_ordertime . " " . substr($f_jb_warningtime, 0,2) . ":" . substr($f_jb_warningtime, 3,2) . ":00";
$f_jb_ordertime .= " 06:00:00";
$f_tr_sort = mcStrWrap($f_tr_sort);
$f_order_id = mcStrWrap($f_order_id);
$f_customer_id = mcStrWrap($f_customer_id);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_tr_comp2 = "";
$f_tr_cs_freetext = "";
$f_trat_name = mcStrWrap($f_trat_name);
$f_ad_street_hsno = mcStrWrap($f_ad_street_hsno);
$f_ad_country = "";
if ($f_ad_country == "" || $f_ad_country == "D") : $f_ad_country = "DE"; endif;
$f_ad_zipcode = mcStrWrap($f_ad_zipcode);
$f_ad_city = mcStrWrap($f_ad_city);
$f_tr_phone = "";
$f_dummy_01 = mcStrWrap($f_dummy_01);
$f_trat_packingpieces = "";
$f_trat_palets = "";
$f_trat_weight = "";
// $f_trat_weight = str_replace (",", ".", $f_trat_weight);
$f_tr_person = "";
$f_trat_data = mcStrWrap($f_trat_data);
$f_trat_data2 = mcStrWrap($f_trat_data2);
$f_dummy_04 = mcStrWrap($f_dummy_04);
$f_dummy_05 = mcStrWrap($f_dummy_05);
$f_dummy_06 = mcStrWrap($f_dummy_06);
// $f_jb_totalprice = str_replace (",", ".", $f_jb_totalprice);
// $f_tr_commission_no = mcStrWrap($f_tr_commission_no);
$f_tr_commission_no = $f_tour_no . "_" . $f_order_id . "_" . $f_tr_sort;
$f_trat_remark = $f_trat_data . " " . $f_trat_data2;
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_tour_no];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
*/
$crEid = $tourCourierArray[$f_tour_no];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
$crSid = $tourSIDArray[$f_tour_no];
endif;
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
// $jbStatus = "1"; // jb_status will be set after the whole job is generated
$jbTaketime = $currentTime;
$useJbNewArray = true;
endif;
$jbType = "2"; // Init with job type "G"
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo $f_jb_orderdate . ";" . $f_tour_no . ";" . $f_vehicle_id . ";" . $f_customer_id . ";" . $f_order_id . ";";
echo $f_tr_sort . ";" . $f_jb_warningtime . ";" . $f_ad_zipcode . ";" . $f_ad_city . ";" . $f_ad_street_hsno . ";" . $f_tr_comp . ";";
echo $f_trat_name . ";" . $f_trat_data . ";" . $f_trat_data2 . ";";
echo "<br>";
// Do NOT import if FAMO number does exist !!!!
if (true) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = true;
if ($fire) :
// [**** JOB ****]
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_tour_no) :
$jbIdNew = "";
// Remove existing tourname
updateStmt("job","jb_tourname",$f_tour_no,array("jb_tourname",""), "jb_tourname = '" . $f_tour_no . "'");
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_tour_no,
"jb_finishtime", $jbFinishtime, "jb_warningtime", $f_jb_warningtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbIdNew = getLastInsertId();
$jobNewArray[] = $jbIdNew;
$trSort = 2; // Init for 2nd station equals first delivery !!!!
$remTourNo = $f_tour_no;
endif;
// Check for inserted job
if ($jbIdNew != "") :
// [**** TOUR ****]
if ($remTrSort == "" || $remTrSort != $f_tr_sort) :
// Insert address
$tmpArray = insertAddress($f_ad_street_hsno, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
// $outText .= "AD_ID : " . $ad_id_new . " | ";
// Insert stations
if ($trSort == 2) :
$trStatus = "0";
$trFinishtime = "";
if ($pickUpStationFinishedByDefault) :
$trStatus = "1";
$trFinishtime = $currentTime;
endif;
// Insert pick up station during first iteration
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $adIdFrom, "tr_sort", "1", "tr_comp", "FAMO", "tr_comp2", "",
"tr_hsno", $trHsnoFrom, "tr_floor", $f_ad_floor, "csc_id", $cscIdPayer, "tr_status", $trStatus, "tr_finishtime", $trFinishtime,
"tr_commission_no", "", "tr_ware_from_to", "",
"tr_person", "", "tr_phone", "", "tr_remark", ""));
$trIdPickUpNew = getLastInsertID();
endif;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", "", "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_trat_name, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
// Insert tourservice data
// !!!! MIT tr_id !!!! insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// ****
// Special patch because of "bug" in function "mk_jb_invtext()"
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// ****
// Fremdauftragsnummer "$f_order_id"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_0", "gdc_content", $f_order_id, "gdc_context", "FAMO"));
// Kundennummer "$f_customer_id"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_1", "gdc_content", $f_customer_id, "gdc_context", "FAMO"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_cust_no", "gdc_content", $f_customer_id, "gdc_context", "FAMO"));
$trSort4Trat = $trSort; // To avoid that all articles will be shifted right
$trSort++;
$executionCount++;
$remTrSort = $f_tr_sort;
$tratSort = 1; // Init all serial numbers !!!!
endif;
// Check for inserted station
if ($trIdNew != "") :
// [**** TOURARTICLE ****]
// Insert tourarticle data (delivery stations)
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort4Trat, "trat_sort", $tratSort, "at_id", "", "trat_name", $f_trat_name, "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_trat_name,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
if (!$pickUpStationFinishedByDefault) :
// insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_name", $f_trat_name, "trat_quantity", "0",
// "trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_trat_name,
// "trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
endif;
$tratSort++;
endif;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_order_id . "]<br>";
endif;
}
// Set generated jobs to status "taken"
$jobNewArrayLen = count($jobNewArray);
if ($jobNewArrayLen > 0) :
for ($i = 0; $i < $jobNewArrayLen; $i++) :
// updateStmt("job", "jb_id", $jobNewArray[$i], array("jb_status", "1"));
endfor;
// Write info to check existence by new import
insertStmt("genericdatacontainer", array("gdc_obj_type", "cs", "gdc_obj_id", $csId, "gdc_gen_fieldname", "check_exist", "gdc_content", $currentDate, "gdc_context", "FAMO"));
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei wurde nach der Datenlage vermeintlich schon exportiert! Ein Verarbeitung fand nicht statt!");
endif;
$outText .= getLngt("Angelegte Stationen: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_FAMO.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,595 @@
<?php
/*=======================================================================
*
* import_GLOBUS.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// include_once ("../include/inc_parseXML.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$currentShortDate = getDateTime(1);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csEid = "";
$cscIdPayer = "";
$address = array();
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
$address = getAddress($csId, "costcenteraddress"); // Get pickup address of the customer
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
// Init
$jbIdNew = "";
$jbTourdata = "";
$jbTourdataZipcode = "";
$jbTourdataCity = "";
$jbTourdataCountry = "";
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strrpos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
/*
$tourVehicleArray = array();
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
*/
$tourCourierArray = array();
/*
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
$tourCourierArray["294505"] = "e8020205";
$tourCourierArray["294506"] = "e8020206";
$tourCourierArray["294507"] = "e8020207";
$tourCourierArray["294508"] = "e8020208";
$tourCourierArray["294509"] = "e8020209";
$tourCourierArray["294510"] = "e8020210";
$tourCourierArray["294511"] = "e8020211";
$tourCourierArray["294512"] = "e8020212";
$tourCourierArray["294590"] = "e8020213";
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
// $aStr = mcDecode($aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
$aStr = str_replace("ß", "ß", $aStr);
$aStr = str_replace("ä", "ä", $aStr);
$aStr = str_replace("ö", "ö", $aStr);
$aStr = str_replace("ü", "ü", $aStr);
$aStr = str_replace("Ä", "Ä", $aStr);
$aStr = str_replace("Ö", "Ö", $aStr);
$aStr = str_replace("Ü", "Ü", $aStr);
return $aStr;
}
echo "importFile: " . $importFile . "<br>";
echo "hqId: " . $hqId . "<br>";
echo "csId: " . $csId . "<br>";
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// The filename contains the execution day !!!!
// $tmpJbOrdertime = substr($filename,-12,8);
// $jbOrdertime = substr($tmpJbOrdertime,0,4) . "-" . substr($tmpJbOrdertime,4,2) . "-" . substr($tmpJbOrdertime,6,2) . " 08:00:00";
// echo $jbOrdertime . "<br>";
// $jbOrdertime = checkDateTimeFormat($jbOrdertime); // DISABLED BECAUSE OF PHP VERSION ONLY !!! ACTIVATE AFTER MIGRATION !!!
// $checkGmtdatetimeIsValid = strtotime($jbOrdertime);
// echo $checkGmtdatetimeIsValid . "<br>";
// if ($checkGmtdatetimeIsValid != "" && is_int($checkGmtdatetimeIsValid)):
if (true):
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_GLOBUS_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$f_tour_no = 1;
$remIsPickup = true;
$jbIdNew = 0;
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_GLOBUS_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
/*
Station;Datum;Avisiertes Zeitfenster;Auftragsnr.;Name;Straße;Hausnr.;Plz;Ort;Telefonnr.;Kunde;Bemerkungen (Warenart; KG; Stpl.; Zone; Inkasso; Besonderheiten
*/
$rowToImport[0] = "f_lfd"; // A : Nur fortlaufende Nummer
$rowToImport[1] = "f_orderdate"; // B : Tag des Auftragsbeginns
$rowToImport[2] = "f_time_window"; // C : Auftragsstartzeit und gewünschte Auftragsendezeit
$rowToImport[3] = "f_tr_commission_no"; // D : Kundenauftragsnummer
$rowToImport[4] = "f_tr_comp"; // E : Kunde / Firma
$rowToImport[5] = "f_ad_street"; // F : Straße
$rowToImport[6] = "f_tr_hsno"; // G : Hausnummer
$rowToImport[7] = "f_ad_zipcode"; // H : PLZ
$rowToImport[8] = "f_ad_city"; // I : Ort
$rowToImport[9] = "f_tr_phone"; // J : Telefon
$rowToImport[10] = "f_tr_remark"; // K : Bemerkung
$rowToImport[11] = "f_dummy_01"; // L : ?
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
echo "Datensätze: " . ($dataLen - 1) . "<br>";
// print_r($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
// Check for existing headline
if ($j > 0) :
$f_lfd = mcStrWrap($f_lfd);
$f_orderdate = mcStrWrap($f_orderdate);
$f_time_window = mcStrWrap($f_time_window);
$f_tr_commission_no = mcStrWrap($f_tr_commission_no);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_ad_street = mcStrWrap($f_ad_street);
$f_tr_hsno = mcStrWrap($f_tr_hsno);
$f_ad_zipcode = mcStrWrap($f_ad_zipcode);
$f_ad_city = mcStrWrap($f_ad_city);
$f_tr_phone = mcStrWrap($f_tr_phone);
$f_tr_remark = mcStrWrap($f_tr_remark);
// Ordertime by order date and time window
$f_ordertime = substr($f_orderdate,6,4) . "-" . substr($f_orderdate,3,2) . "-" . substr($f_orderdate,0,2);
$f_warningtime = $f_ordertime;
if ($f_time_window != "") :
$orderClockTime = " " . substr($f_time_window,0,2) . ":" . substr($f_time_window,3,2) . ":00";
$warningClockTime = " " . substr($f_time_window,8,2) . ":" . substr($f_time_window,11,2) . ":00";
else :
$orderClockTime = " 08:00:00";
$warningClockTime = " 08:00:00";
endif;
// Special static handling per headquarters
if ($hqId == "111") :
$orderClockTime = " 07:30:00";
$warningClockTime = " 07:30:00";
endif;
$f_ordertime .= $orderClockTime;
$f_warningtime .= $warningClockTime;
$f_tr_person = $f_tr_comp;
// Set vehicle and courier
$crId = "";
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
$jbStatus = "1";
$jbTaketime = $currentTime;
endif;
$jbType = "2"; // Init with job type "G"
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo "------------------------------------------------------<br>";
echo "f_tour_no: " . $f_tour_no . "<br>";
echo "f_lfd: " . $f_lfd . "<br>";
echo "f_orderdate: " . $f_orderdate . "<br>";
echo "f_time_window: " . $f_time_window . "<br>";
echo "f_ordertime: " . $f_ordertime . "<br>";
echo "f_warningtime: " . $f_warningtime . "<br>";
echo "f_tr_commission_no: " . $f_tr_commission_no . "<br>";
echo "f_tr_comp: " . $f_tr_comp . "<br>";
echo "f_tr_person: " . $f_tr_person . "<br>";
echo "f_ad_street: " . $f_ad_street . "<br>";
echo "f_tr_hsno: " . $f_tr_hsno . "<br>";
echo "f_ad_zipcode: " . $f_ad_zipcode . "<br>";
echo "f_ad_city: " . $f_ad_city . "<br>";
echo "f_tr_phone: " . $f_tr_phone . "<br>";
echo "f_tr_remark: " . $f_tr_remark . "<br>";
// Check for existence of the imported "tour name" AND "station number" (unique for station)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_orderdate . " " . $f_tr_commission_no,"gdc_context","GLOBUS"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if GLOBUS number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = true;
if ($remTourNo == "" || $remTourNo == $f_tour_no) :
if ($jbTourdataZipcode != "") : $jbTourdataZipcode .= ";"; endif;
$jbTourdataZipcode .= $f_ad_zipcode;
if ($jbTourdataCity != "") : $jbTourdataCity .= ";"; endif;
$jbTourdataCity .= $f_ad_city;
if ($jbTourdataCountry != "") : $jbTourdataCountry .= ";"; endif;
$jbTourdataCountry .= "DE";
endif;
// Insert address
if ($f_ad_street == "" || $f_ad_zipcode == "" || $f_ad_city == "") :
$noValidationOfAddress = "1";
endif;
if ($f_ad_zipcode != "" && $f_ad_city != "") :
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$isPickup = false;
else :
$ad_id_new = $address["id"];
$f_tr_hsno = $address["hsno"];
$isPickup = true;
endif;
// $outText .= "AD_ID : " . $ad_id_new . " | ";
// If current station IS "pickup" AND the station before was NOT "pickup" then start next tour
// Check last stations
if ($j < 1 || $j >= ($dataLen - 2)) :
$remIsPickup = true;
endif;
echo "isPickup : " . ($isPickup ? "YES" : "NO") . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;remIsPickup : " . ($remIsPickup ? "YES" : "NO") . "<br>";
if ($isPickup && !$remIsPickup) :
$f_tour_no++;
$remIsPickup = $isPickup;
endif;
// Tourname
$f_jb_tourname = $f_tr_comp . " " . $f_orderdate . " " . $f_tour_no;
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_tour_no) :
// Finalize currently imported job
// Write "jb_tourdata" of the job currently imported
if ($remTourNo != "" && $jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// Remove existing tourname
updateStmt("job","jb_tourname",$f_jb_tourname,array("jb_tourname",""), "jb_tourname = '" . $f_jb_tourname . "'");
// Tour data
/*
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
*/
$jbIdNew = ""; // Init
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", "", "jb_warningtime", $f_warningtime, "jb_createtime", $currentTime));
$jbIdNew = getLastInsertId();
$trSort = 0;
$remTourNo = $f_tour_no;
$remIsPickup = true;
// Init for the next job to be imported
$jbTourdata = "";
// Init with current values
$jbTourdataZipcode = $f_ad_zipcode;
$jbTourdataCity = $f_ad_city;
$jbTourdataCountry = "DE";
endif;
// Check for inserted job
if ($jbIdNew != "") :
$trSort++;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
// Insert tourservice data
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// Tourname
// insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_orderdate . " " . $f_tr_commission_no, "gdc_context", "GLOBUS"));
// Insert tourarticle data (delivery stations)
/*
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
*/
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
/*
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
*/
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_order_id . "]<br>";
endif;
endif; // Check for headline
}
// If at least onne imported job does exist ($jbIdNew > 0) then finalize last imported job
// Write "jb_tourdata" of the job currently imported
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Das Datum für den Ausführungstag im Dateinamen scheint nicht korrekt! Bitte folgendes Format für den Dateinamen verwenden: import_GLOBUS_YYYYMMDD.csv");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_GLOBUS.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,595 @@
<?php
/*=======================================================================
*
* import_HAGEBAU.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// include_once ("../include/inc_parseXML.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$currentShortDate = getDateTime(1);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csEid = "";
$cscIdPayer = "";
$address = array();
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
$address = getAddress($csId, "costcenteraddress"); // Get pickup address of the customer
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
// Init
$jbIdNew = "";
$jbTourdata = "";
$jbTourdataZipcode = "";
$jbTourdataCity = "";
$jbTourdataCountry = "";
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strrpos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
/*
$tourVehicleArray = array();
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
*/
$tourCourierArray = array();
/*
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
$tourCourierArray["294505"] = "e8020205";
$tourCourierArray["294506"] = "e8020206";
$tourCourierArray["294507"] = "e8020207";
$tourCourierArray["294508"] = "e8020208";
$tourCourierArray["294509"] = "e8020209";
$tourCourierArray["294510"] = "e8020210";
$tourCourierArray["294511"] = "e8020211";
$tourCourierArray["294512"] = "e8020212";
$tourCourierArray["294590"] = "e8020213";
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
// $aStr = mcDecode($aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
$aStr = str_replace("ß", "ß", $aStr);
$aStr = str_replace("ä", "ä", $aStr);
$aStr = str_replace("ö", "ö", $aStr);
$aStr = str_replace("ü", "ü", $aStr);
$aStr = str_replace("Ä", "Ä", $aStr);
$aStr = str_replace("Ö", "Ö", $aStr);
$aStr = str_replace("Ü", "Ü", $aStr);
return $aStr;
}
echo "importFile: " . $importFile . "<br>";
echo "hqId: " . $hqId . "<br>";
echo "csId: " . $csId . "<br>";
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// The filename contains the execution day !!!!
// $tmpJbOrdertime = substr($filename,-12,8);
// $jbOrdertime = substr($tmpJbOrdertime,0,4) . "-" . substr($tmpJbOrdertime,4,2) . "-" . substr($tmpJbOrdertime,6,2) . " 08:00:00";
// echo $jbOrdertime . "<br>";
// $jbOrdertime = checkDateTimeFormat($jbOrdertime); // DISABLED BECAUSE OF PHP VERSION ONLY !!! ACTIVATE AFTER MIGRATION !!!
// $checkGmtdatetimeIsValid = strtotime($jbOrdertime);
// echo $checkGmtdatetimeIsValid . "<br>";
// if ($checkGmtdatetimeIsValid != "" && is_int($checkGmtdatetimeIsValid)):
if (true):
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_HAGEBAU_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$f_tour_no = 1;
$remIsPickup = true;
$jbIdNew = 0;
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_HAGEBAU_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
/*
Station;Datum;Avisiertes Zeitfenster;Auftragsnr.;Name;Straße;Hausnr.;Plz;Ort;Telefonnr.;Kunde;Bemerkungen (Warenart; KG; Stpl.; Zone; Inkasso; Besonderheiten
*/
$rowToImport[0] = "f_lfd"; // A : Nur fortlaufende Nummer
$rowToImport[1] = "f_orderdate"; // B : Tag des Auftragsbeginns
$rowToImport[2] = "f_time_window"; // C : Auftragsstartzeit und gewünschte Auftragsendezeit
$rowToImport[3] = "f_tr_commission_no"; // D : Kundenauftragsnummer
$rowToImport[4] = "f_tr_comp"; // E : Kunde / Firma
$rowToImport[5] = "f_ad_street"; // F : Straße
$rowToImport[6] = "f_tr_hsno"; // G : Hausnummer
$rowToImport[7] = "f_ad_zipcode"; // H : PLZ
$rowToImport[8] = "f_ad_city"; // I : Ort
$rowToImport[9] = "f_tr_phone"; // J : Telefon
$rowToImport[10] = "f_tr_remark"; // K : Bemerkung
$rowToImport[11] = "f_dummy_01"; // L : ?
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
echo "Datensätze: " . ($dataLen - 1) . "<br>";
// print_r($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
// Check for existing headline
if ($j > 0) :
$f_lfd = mcStrWrap($f_lfd);
$f_orderdate = mcStrWrap($f_orderdate);
$f_time_window = mcStrWrap($f_time_window);
$f_tr_commission_no = mcStrWrap($f_tr_commission_no);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_ad_street = mcStrWrap($f_ad_street);
$f_tr_hsno = mcStrWrap($f_tr_hsno);
$f_ad_zipcode = mcStrWrap($f_ad_zipcode);
$f_ad_city = mcStrWrap($f_ad_city);
$f_tr_phone = mcStrWrap($f_tr_phone);
$f_tr_remark = mcStrWrap($f_tr_remark);
// Ordertime by order date and time window
$f_ordertime = substr($f_orderdate,6,4) . "-" . substr($f_orderdate,3,2) . "-" . substr($f_orderdate,0,2);
$f_warningtime = $f_ordertime;
if ($f_time_window != "") :
$orderClockTime = " " . substr($f_time_window,0,2) . ":" . substr($f_time_window,3,2) . ":00";
$warningClockTime = " " . substr($f_time_window,8,2) . ":" . substr($f_time_window,11,2) . ":00";
else :
$orderClockTime = " 08:00:00";
$warningClockTime = " 08:00:00";
endif;
// Special static handling per headquarters
if ($hqId == "111") :
$orderClockTime = " 07:30:00";
$warningClockTime = " 07:30:00";
endif;
$f_ordertime .= $orderClockTime;
$f_warningtime .= $warningClockTime;
$f_tr_person = $f_tr_comp;
// Set vehicle and courier
$crId = "";
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
$jbStatus = "1";
$jbTaketime = $currentTime;
endif;
$jbType = "2"; // Init with job type "G"
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo "------------------------------------------------------<br>";
echo "f_tour_no: " . $f_tour_no . "<br>";
echo "f_lfd: " . $f_lfd . "<br>";
echo "f_orderdate: " . $f_orderdate . "<br>";
echo "f_time_window: " . $f_time_window . "<br>";
echo "f_ordertime: " . $f_ordertime . "<br>";
echo "f_warningtime: " . $f_warningtime . "<br>";
echo "f_tr_commission_no: " . $f_tr_commission_no . "<br>";
echo "f_tr_comp: " . $f_tr_comp . "<br>";
echo "f_tr_person: " . $f_tr_person . "<br>";
echo "f_ad_street: " . $f_ad_street . "<br>";
echo "f_tr_hsno: " . $f_tr_hsno . "<br>";
echo "f_ad_zipcode: " . $f_ad_zipcode . "<br>";
echo "f_ad_city: " . $f_ad_city . "<br>";
echo "f_tr_phone: " . $f_tr_phone . "<br>";
echo "f_tr_remark: " . $f_tr_remark . "<br>";
// Check for existence of the imported "tour name" AND "station number" (unique for station)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_orderdate . " " . $f_tr_commission_no,"gdc_context","HAGEBAU"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if HAGEBAU number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = true;
if ($remTourNo == "" || $remTourNo == $f_tour_no) :
if ($jbTourdataZipcode != "") : $jbTourdataZipcode .= ";"; endif;
$jbTourdataZipcode .= $f_ad_zipcode;
if ($jbTourdataCity != "") : $jbTourdataCity .= ";"; endif;
$jbTourdataCity .= $f_ad_city;
if ($jbTourdataCountry != "") : $jbTourdataCountry .= ";"; endif;
$jbTourdataCountry .= "DE";
endif;
// Insert address
if ($f_ad_street == "" || $f_ad_zipcode == "" || $f_ad_city == "") :
$noValidationOfAddress = "1";
endif;
if ($f_ad_zipcode != "" && $f_ad_city != "") :
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$isPickup = false;
else :
$ad_id_new = $address["id"];
$f_tr_hsno = $address["hsno"];
$isPickup = true;
endif;
// $outText .= "AD_ID : " . $ad_id_new . " | ";
// If current station IS "pickup" AND the station before was NOT "pickup" then start next tour
// Check last stations
if ($j < 1 || $j >= ($dataLen - 2)) :
$remIsPickup = true;
endif;
echo "isPickup : " . ($isPickup ? "YES" : "NO") . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;remIsPickup : " . ($remIsPickup ? "YES" : "NO") . "<br>";
if ($isPickup && !$remIsPickup) :
$f_tour_no++;
$remIsPickup = $isPickup;
endif;
// Tourname
$f_jb_tourname = $f_tr_comp . " " . $f_orderdate . " " . $f_tour_no;
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_tour_no) :
// Finalize currently imported job
// Write "jb_tourdata" of the job currently imported
if ($remTourNo != "" && $jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// Remove existing tourname
updateStmt("job","jb_tourname",$f_jb_tourname,array("jb_tourname",""), "jb_tourname = '" . $f_jb_tourname . "'");
// Tour data
/*
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
*/
$jbIdNew = ""; // Init
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", "", "jb_warningtime", $f_warningtime, "jb_createtime", $currentTime));
$jbIdNew = getLastInsertId();
$trSort = 0;
$remTourNo = $f_tour_no;
$remIsPickup = true;
// Init for the next job to be imported
$jbTourdata = "";
// Init with current values
$jbTourdataZipcode = $f_ad_zipcode;
$jbTourdataCity = $f_ad_city;
$jbTourdataCountry = "DE";
endif;
// Check for inserted job
if ($jbIdNew != "") :
$trSort++;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
// Insert tourservice data
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// Tourname
// insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_orderdate . " " . $f_tr_commission_no, "gdc_context", "HAGEBAU"));
// Insert tourarticle data (delivery stations)
/*
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
*/
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
/*
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
*/
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_order_id . "]<br>";
endif;
endif; // Check for headline
}
// If at least onne imported job does exist ($jbIdNew > 0) then finalize last imported job
// Write "jb_tourdata" of the job currently imported
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Das Datum für den Ausführungstag im Dateinamen scheint nicht korrekt! Bitte folgendes Format für den Dateinamen verwenden: import_HAGEBAU_YYYYMMDD.csv");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_HAGEBAU.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

1090
html/import/import_HHA.php Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,595 @@
<?php
/*=======================================================================
*
* import_HORNBACH.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// include_once ("../include/inc_parseXML.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$currentShortDate = getDateTime(1);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csEid = "";
$cscIdPayer = "";
$address = array();
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
$address = getAddress($csId, "costcenteraddress"); // Get pickup address of the customer
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
// Init
$jbIdNew = "";
$jbTourdata = "";
$jbTourdataZipcode = "";
$jbTourdataCity = "";
$jbTourdataCountry = "";
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strrpos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
/*
$tourVehicleArray = array();
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
*/
$tourCourierArray = array();
/*
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
$tourCourierArray["294505"] = "e8020205";
$tourCourierArray["294506"] = "e8020206";
$tourCourierArray["294507"] = "e8020207";
$tourCourierArray["294508"] = "e8020208";
$tourCourierArray["294509"] = "e8020209";
$tourCourierArray["294510"] = "e8020210";
$tourCourierArray["294511"] = "e8020211";
$tourCourierArray["294512"] = "e8020212";
$tourCourierArray["294590"] = "e8020213";
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
// $aStr = mcDecode($aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
$aStr = str_replace("ß", "ß", $aStr);
$aStr = str_replace("ä", "ä", $aStr);
$aStr = str_replace("ö", "ö", $aStr);
$aStr = str_replace("ü", "ü", $aStr);
$aStr = str_replace("Ä", "Ä", $aStr);
$aStr = str_replace("Ö", "Ö", $aStr);
$aStr = str_replace("Ü", "Ü", $aStr);
return $aStr;
}
echo "importFile: " . $importFile . "<br>";
echo "hqId: " . $hqId . "<br>";
echo "csId: " . $csId . "<br>";
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// The filename contains the execution day !!!!
// $tmpJbOrdertime = substr($filename,-12,8);
// $jbOrdertime = substr($tmpJbOrdertime,0,4) . "-" . substr($tmpJbOrdertime,4,2) . "-" . substr($tmpJbOrdertime,6,2) . " 08:00:00";
// echo $jbOrdertime . "<br>";
// $jbOrdertime = checkDateTimeFormat($jbOrdertime); // DISABLED BECAUSE OF PHP VERSION ONLY !!! ACTIVATE AFTER MIGRATION !!!
// $checkGmtdatetimeIsValid = strtotime($jbOrdertime);
// echo $checkGmtdatetimeIsValid . "<br>";
// if ($checkGmtdatetimeIsValid != "" && is_int($checkGmtdatetimeIsValid)):
if (true):
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_HORNBACH_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$f_tour_no = 1;
$remIsPickup = true;
$jbIdNew = 0;
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_HORNBACH_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
/*
Station;Datum;Avisiertes Zeitfenster;Auftragsnr.;Name;Straße;Hausnr.;Plz;Ort;Telefonnr.;Kunde;Bemerkungen (Warenart; KG; Stpl.; Zone; Inkasso; Besonderheiten
*/
$rowToImport[0] = "f_lfd"; // A : Nur fortlaufende Nummer
$rowToImport[1] = "f_orderdate"; // B : Tag des Auftragsbeginns
$rowToImport[2] = "f_time_window"; // C : Auftragsstartzeit und gewünschte Auftragsendezeit
$rowToImport[3] = "f_tr_commission_no"; // D : Kundenauftragsnummer
$rowToImport[4] = "f_tr_comp"; // E : Kunde / Firma
$rowToImport[5] = "f_ad_street"; // F : Straße
$rowToImport[6] = "f_tr_hsno"; // G : Hausnummer
$rowToImport[7] = "f_ad_zipcode"; // H : PLZ
$rowToImport[8] = "f_ad_city"; // I : Ort
$rowToImport[9] = "f_tr_phone"; // J : Telefon
$rowToImport[10] = "f_tr_remark"; // K : Bemerkung
$rowToImport[11] = "f_dummy_01"; // L : ?
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
echo "Datensätze: " . ($dataLen - 1) . "<br>";
// print_r($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
// Check for existing headline
if ($j > 0) :
$f_lfd = mcStrWrap($f_lfd);
$f_orderdate = mcStrWrap($f_orderdate);
$f_time_window = mcStrWrap($f_time_window);
$f_tr_commission_no = mcStrWrap($f_tr_commission_no);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_ad_street = mcStrWrap($f_ad_street);
$f_tr_hsno = mcStrWrap($f_tr_hsno);
$f_ad_zipcode = mcStrWrap($f_ad_zipcode);
$f_ad_city = mcStrWrap($f_ad_city);
$f_tr_phone = mcStrWrap($f_tr_phone);
$f_tr_remark = mcStrWrap($f_tr_remark);
// Ordertime by order date and time window
$f_ordertime = substr($f_orderdate,6,4) . "-" . substr($f_orderdate,3,2) . "-" . substr($f_orderdate,0,2);
$f_warningtime = $f_ordertime;
if ($f_time_window != "") :
$orderClockTime = " " . substr($f_time_window,0,2) . ":" . substr($f_time_window,3,2) . ":00";
$warningClockTime = " " . substr($f_time_window,8,2) . ":" . substr($f_time_window,11,2) . ":00";
else :
$orderClockTime = " 08:00:00";
$warningClockTime = " 08:00:00";
endif;
// Special static handling per headquarters
if ($hqId == "111") :
$orderClockTime = " 07:30:00";
$warningClockTime = " 07:30:00";
endif;
$f_ordertime .= $orderClockTime;
$f_warningtime .= $warningClockTime;
$f_tr_person = $f_tr_comp;
// Set vehicle and courier
$crId = "";
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
$jbStatus = "1";
$jbTaketime = $currentTime;
endif;
$jbType = "2"; // Init with job type "G"
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo "------------------------------------------------------<br>";
echo "f_tour_no: " . $f_tour_no . "<br>";
echo "f_lfd: " . $f_lfd . "<br>";
echo "f_orderdate: " . $f_orderdate . "<br>";
echo "f_time_window: " . $f_time_window . "<br>";
echo "f_ordertime: " . $f_ordertime . "<br>";
echo "f_warningtime: " . $f_warningtime . "<br>";
echo "f_tr_commission_no: " . $f_tr_commission_no . "<br>";
echo "f_tr_comp: " . $f_tr_comp . "<br>";
echo "f_tr_person: " . $f_tr_person . "<br>";
echo "f_ad_street: " . $f_ad_street . "<br>";
echo "f_tr_hsno: " . $f_tr_hsno . "<br>";
echo "f_ad_zipcode: " . $f_ad_zipcode . "<br>";
echo "f_ad_city: " . $f_ad_city . "<br>";
echo "f_tr_phone: " . $f_tr_phone . "<br>";
echo "f_tr_remark: " . $f_tr_remark . "<br>";
// Check for existence of the imported "tour name" AND "station number" (unique for station)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_orderdate . " " . $f_tr_commission_no,"gdc_context","HORNBACH"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if HORNBACH number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = true;
if ($remTourNo == "" || $remTourNo == $f_tour_no) :
if ($jbTourdataZipcode != "") : $jbTourdataZipcode .= ";"; endif;
$jbTourdataZipcode .= $f_ad_zipcode;
if ($jbTourdataCity != "") : $jbTourdataCity .= ";"; endif;
$jbTourdataCity .= $f_ad_city;
if ($jbTourdataCountry != "") : $jbTourdataCountry .= ";"; endif;
$jbTourdataCountry .= "DE";
endif;
// Insert address
if ($f_ad_street == "" || $f_ad_zipcode == "" || $f_ad_city == "") :
$noValidationOfAddress = "1";
endif;
if ($f_ad_zipcode != "" && $f_ad_city != "") :
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$isPickup = false;
else :
$ad_id_new = $address["id"];
$f_tr_hsno = $address["hsno"];
$isPickup = true;
endif;
// $outText .= "AD_ID : " . $ad_id_new . " | ";
// If current station IS "pickup" AND the station before was NOT "pickup" then start next tour
// Check last stations
if ($j < 1 || $j >= ($dataLen - 2)) :
$remIsPickup = true;
endif;
echo "isPickup : " . ($isPickup ? "YES" : "NO") . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;remIsPickup : " . ($remIsPickup ? "YES" : "NO") . "<br>";
if ($isPickup && !$remIsPickup) :
$f_tour_no++;
$remIsPickup = $isPickup;
endif;
// Tourname
$f_jb_tourname = $f_tr_comp . " " . $f_orderdate . " " . $f_tour_no;
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_tour_no) :
// Finalize currently imported job
// Write "jb_tourdata" of the job currently imported
if ($remTourNo != "" && $jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// Remove existing tourname
updateStmt("job","jb_tourname",$f_jb_tourname,array("jb_tourname",""), "jb_tourname = '" . $f_jb_tourname . "'");
// Tour data
/*
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
*/
$jbIdNew = ""; // Init
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", "", "jb_warningtime", $f_warningtime, "jb_createtime", $currentTime));
$jbIdNew = getLastInsertId();
$trSort = 0;
$remTourNo = $f_tour_no;
$remIsPickup = true;
// Init for the next job to be imported
$jbTourdata = "";
// Init with current values
$jbTourdataZipcode = $f_ad_zipcode;
$jbTourdataCity = $f_ad_city;
$jbTourdataCountry = "DE";
endif;
// Check for inserted job
if ($jbIdNew != "") :
$trSort++;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
// Insert tourservice data
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// Tourname
// insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_orderdate . " " . $f_tr_commission_no, "gdc_context", "HORNBACH"));
// Insert tourarticle data (delivery stations)
/*
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
*/
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
/*
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
*/
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_order_id . "]<br>";
endif;
endif; // Check for headline
}
// If at least onne imported job does exist ($jbIdNew > 0) then finalize last imported job
// Write "jb_tourdata" of the job currently imported
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Das Datum für den Ausführungstag im Dateinamen scheint nicht korrekt! Bitte folgendes Format für den Dateinamen verwenden: import_HORNBACH_YYYYMMDD.csv");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_HORNBACH.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

251
html/import/import_ITCS.php Normal file
View File

@@ -0,0 +1,251 @@
<?php
/*=======================================================================
*
* import_ITCS.php
*
=======================================================================*/
include_once ("../import/import.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
/*
$HTTP_POST_VARS = !empty($HTTP_POST_VARS) ? $HTTP_POST_VARS : $_POST;
$HTTP_GET_VARS = !empty($HTTP_GET_VARS) ? $HTTP_GET_VARS : $_GET;
$HTTP_COOKIE_VARS = !empty($HTTP_COOKIE_VARS) ? $HTTP_COOKIE_VARS : $_COOKIE;
$HTTP_SERVER_VARS = !empty($HTTP_SERVER_VARS) ? $HTTP_SERVER_VARS : $_SERVER;
$HTTP_ENV_VARS = !empty($HTTP_ENV_VARS) ? $HTTP_ENV_VARS : $_ENV;
$HTTP_POST_FILES = !empty($HTTP_POST_FILES) ? $HTTP_POST_FILES : $_FILES;
if (!isset($PHP_SELF))
$PHP_SELF = $_SERVER["PHP_SELF"];
if (substr(phpversion(), 0, 3) >= "5.1") :
date_default_timezone_set('Europe/Berlin');
endif;
// Check HTTP-Parameters
// getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
$f_act = $HTTP_POST_VARS["f_act"]; if ($f_act) == "" : $f_act = $HTTP_GET_VARS["f_act"]; endif;
$statusMessage = $HTTP_POST_VARS["statusMessage"]; if ($statusMessage) == "" : $statusMessage = $HTTP_GET_VARS["statusMessage"]; endif;
$importFile = $HTTP_POST_VARS["importFile"]; if ($importFile) == "" : $importFile = $HTTP_GET_VARS["importFile"]; endif;
$executeImportProcess = $HTTP_POST_VARS["executeImportProcess"]; if ($executeImportProcess) == "" : $executeImportProcess = $HTTP_GET_VARS["executeImportProcess"]; endif;
*/
// *****************************************************************************
function get_url ($request_url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
function create_url ($req) {
global $rfcProt,$rfcUrl;
$request_url = $rfcProt . $rfcUrl ."?operation=".urlencode($req);
return $request_url;
}
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT ITCS");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
// $usrAccessArray["hq"] = "1";
// authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
// if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
// $empHasAdminRights = false;
// $empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
// if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
// endif;
$debug = false;
// if ($empIdRootAdmin == $emp_id) :
// $debug = true;
// endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true;
// Customer and headquarters references have to exist
/*
$hqId = "";
$csEid = "";
$objType = trim($objType);
$objId = trim($objId);
if ($objType == "CS" && is_numeric($objId)) :
$csId = getFieldValueFromId("phoenix.customer", "cs_id", $objId, "cs_id");
endif;
if ($csId != "") :
$hqId = getFieldValueFromId("phoenix.customer", "cs_id", $csId, "hq_id");
$csEid = getFieldValueFromId("phoenix.customer", "cs_id", $csId, "cs_eid");
endif;
if ($debug) :
echo "f_act : " . $f_act . "<br>";
echo "objType : " . $objType . "<br>";
echo "objId : " . $objId . "<br>";
echo "hqId : " . $hqId . "<br>";
echo "csId : " . $csId . "<br>";
echo "<br>";
endif;
*/
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
if ($importFile != "") :
// Create internal representation
$srvpArray = array();
$zoneArray = array();
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ********************
// * IMPORT FILE xxxx *
// ********************
if (!(strpos($filename, "import_ITCS_") === false)) :
if ($executeImportProcess) :
// Init
$rfcProt = "https://";
$rfcUrl = "app.assecutor.de/cgi-bin/vudi_itc.test/";
$op = "import";
$auth = "local";
$type = "csv";
$data = importDataset($importFile);
$dataLen = count($data);
for ($j = 0; $j < $dataLen; $j++) {
$xml_ = "<XML><operation op=\"" . $op . "\" auth=\"" . $auth . "\" type=\"" . $type . "\"><data>" . $data[$j] . "</data></operation></XML>";
$request_url = create_url($xml_);
$response = get_url($request_url);
echo $response;
echo "<br />";
$response = json_decode($response);
}
endif;
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_ITCS.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

891
html/import/import_JOB.php Normal file
View File

@@ -0,0 +1,891 @@
<?php
/*=======================================================================
*
* import_JOB.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
include_once ("../include/inc_disposition.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
// Check IKEA store
$mode = "";
if (!(strpos($filename, "_SCHNELSEN_") === false)) :
$mode = "SCHNELSEN";
elseif (!(strpos($filename, "_MOORFLEET_") === false)) :
$mode = "MOORFLEET";
elseif (!(strpos($filename, "_ALTONA_") === false)) :
$mode = "ALTONA";
endif;
if ($mode == "") :
die("DER DATEINAME ENTHÄLT NICHT DEN MARKT! (Bsp.: import_JOB_SCHNELSEN_20141222.csv)");
endif;
// Set headquarters to import jobs
// $csId = $objId;
$f_jb_id_child = $db->getOne("SELECT MAX(jb_id) FROM job WHERE (jb_id > 260000 AND jb_id < 265001)");
if ($f_jb_id_child == "")
$f_jb_id_child = 260001;
else
$f_jb_id_child++;
$tVal = 1.19;
if ($mode == "SCHNELSEN") :
$cscIdRelated = "1";
$vhtPrefix = "HH";
$cVal = 0.95;
$cBool = true;
$tr1_adId = "432200";
$tr1_cscId = "1";
$tr1_comp = "IKEA Schnelsen";
elseif ($mode == "MOORFLEET") :
$cscIdRelated = "2";
$vhtPrefix = "HH";
$cVal = 0.95;
$cBool = true;
$tr1_adId = "433346";
$tr1_cscId = "2";
$tr1_comp = "IKEA Moorfleet";
elseif ($mode == "ALTONA") :
$cscIdRelated = "17051";
$vhtPrefix = "HH";
$cVal = 0.95;
$cBool = true;
$tr1_adId = "439426";
$tr1_cscId = "17051";
$tr1_comp = "IKEA Altona";
endif;
// Timeunits
$jbTimeUnits = "2";
$jbTimeUnits_M = "4";
// Service
$jbService = "1";
$jbService_M = "6"; // Neumöbelmontage
if ($hqId == "") : $hqId = $hq_id; endif;
// Mapping for payment types
// 1 = EC-Pin, 2 = EC-Last, 3=Family, 4= BC, 5=Bar [6=Bar-Mont., 7=EC-Pin-Mont., 8=EC-LAst-Mont., 9=Famil.Mont., 10=Rechnung]
$paymentTypeMappingArray = array();
$paymentTypeMappingArray[0] = 0;
$paymentTypeMappingArray[1] = 1;
$paymentTypeMappingArray[2] = 2;
$paymentTypeMappingArray[3] = 10;
$paymentTypeMappingArray[4] = 11;
$paymentTypeMappingArray[5] = 0;
$paymentTypeMappingArray[6] = 0;
$paymentTypeMappingArray[7] = 1;
$paymentTypeMappingArray[8] = 2;
$paymentTypeMappingArray[9] = 10;
$paymentTypeMappingArray[10] = 5;
// Array for "jobpaymentcollection"
$jbpcArray = array();
$jbpcSamsFlagArray = array();
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
function mcStrWrap($aStr)
{
// $aStr = str_replace("'", "", $aStr);
// $aStr = str_replace("'", "\'", $aStr);
// $aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
// $aStr = str_replace('\"', '', $aStr);
return $aStr;
}
// $hourStart : Begin of interval (from metatype mapped value)
function checkAvailabilityForJob ($crvhId, $currDay, $hourStart, $hourEnd, $jbId, $csId) {
global $db, $PHP_SELF;
global $f_jb_ordertime, $orderTimePair, $outText, $f_jb_id_child, $generateDeliveryJob, $generateInstallationJob;
$retVal = "";
// echo "crvhId : " . $crvhId . "<br>";
// echo "currDay : " . $currDay . "<br>";
// echo "hourStart : " . $hourStart . "<br>";
// echo "hourEnd : " . $hourEnd . "<br>";
// echo "jbId : " . $jbId . "<br>";
// echo "csId : " . $csId . "<br>";
if ($crvhId != "" && $currDay != "" && $hourStart != "" && $hourEnd != "" && $jbId != "" && $csId != "") :
echo "jbId : " . $jbId . "<br>";
// Check the availability of the specified vehicle for the requested interval
$hourTimeUnits = 6;
$hour = $hourStart; // INIT (!!!!)
$jbId_M = $f_jb_id_child;
// Get SID from ID
$crvhSid = getFieldValueFromId("couriervehicle", "crvh_id", $crvhId, "crvh_sid");
$outText .= "CRVH_SID : " . $crvhSid . " | ";
echo "crvhSid : " . $crvhSid . "<br>";
// Get max ordertime of the job of the current vehicle with the largest ordertime on this day
$jbMaxOrdertime = getMaxOfField("job", "jb_ordertime", "cr_sid = '" . $crvhSid . "' AND jb_status IN ('9', '1') AND LEFT(jb_ordertime, 10) = '" . $currDay . "' AND SUBSTRING(jb_ordertime,12,2) >= '" . $hourStart . "' AND SUBSTRING(jb_ordertime,12,2) <= '" . $hourEnd . "'");
echo "jbMaxOrdertime : " . $jbMaxOrdertime . "<br>";
if ($jbMaxOrdertime != "") :
$hour = intval(substr($jbMaxOrdertime,11,2)) + 1;
endif;
echo "hour : " . $hour . "<br>";
if ($hour != "") :
$intHourStart = intval($hour);
echo "intHourStart : " . $intHourStart . "<br>";
$intHourEnd = intval($hourEnd);
echo "intHourEnd : " . $intHourEnd . "<br>";
for ($i = $intHourStart; $i <= $intHourEnd; $i++) :
$startTimeslotToBeChecked = $currDay . "_" . pad($i,2) . "_00";
$endTimeslotToBeChecked = $currDay . "_" . pad($i,2) . "_05";
$capacityProblem = checkAvailableVehicleCapacity($crvhId, $currDay, $startTimeslotToBeChecked, $endTimeslotToBeChecked, $jbId);
if ($capacityProblem == "") :
// Delivery OR single installation job
if ($generateDeliveryJob) :
$startTimeslotToBeChecked = $currDay . "_" . pad($i,2) . "_00";
$endTimeslotToBeChecked = $currDay . "_" . pad($i,2) . "_01";
elseif (!$generateDeliveryJob && $generateInstallationJob) :
$startTimeslotToBeChecked = $currDay . "_" . pad($i,2) . "_00";
$endTimeslotToBeChecked = $currDay . "_" . pad($i,2) . "_05";
endif;
$res = updateStmt("vehicledisposition", "crvh_id", $crvhId, array("jb_id", $jbId), "vhd_timeslot >= '" . $startTimeslotToBeChecked . "' AND vhd_timeslot <= '" . $endTimeslotToBeChecked . "'");
if ($db->affected_rows > 0) :
updateVehicleAvailability($crvhId, $csId, $startTimeslotToBeChecked, $hourTimeUnits); // Write redundant data for delivery appointment search later on
echo "VEHICLEDISPOSITION: DELIVERY UPDATE ON TIMELINE<br>";
// Check vehicle restrictions (weight, positions, etc.)
// if ($jbId != "") :
// $atWeightJb = getTratTotalweight($jbId); // Get the total weight of all articles of the specified job
// $capacityFreeWeight = getFieldValueFromClause("vehicleavailability","vha_weight","crvh_id = '" . $crvhId . "' AND vha_day = '" . $currDay . "'"); // Get free weight capacity of the specified vehicle
// $capacityFreeWeight = $capacityFreeWeight - $atWeightJb;
// updateStmt("vehicleavailability", "crvh_id", $crvhId, array("vha_weight", $capacityFreeWeight), "vha_day = '" . $currDay . "'");
// endif;
// Set global defined parameter
$f_jb_ordertime .= " " . pad($i,2) . ":00:00";
$orderTimePair[0] = $f_jb_ordertime;
$outText .= "JB_ORDERTIME : " . $f_jb_ordertime . " | ";
$retVal = "OK";
if (!$generateInstallationJob) :
break; // Stop iteration
endif;
endif;
// Installion job
if ($generateDeliveryJob && $generateInstallationJob) :
$startTimeslotToBeChecked = $currDay . "_" . pad($i,2) . "_02";
$endTimeslotToBeChecked = $currDay . "_" . pad($i,2) . "_05";
$res = updateStmt("vehicledisposition", "crvh_id", $crvhId, array("jb_id", $jbId_M), "vhd_timeslot >= '" . $startTimeslotToBeChecked . "' AND vhd_timeslot <= '" . $endTimeslotToBeChecked . "'");
if ($db->affected_rows > 0) :
updateVehicleAvailability($crvhId, $csId, $startTimeslotToBeChecked, $hourTimeUnits); // Write redundant data for delivery appointment search later on
echo "VEHICLEDISPOSITION: INSTALLATION UPDATE ON TIMELINE<br>";
// Check vehicle restrictions (weight, positions, etc.)
// if ($jbId != "") :
// $atWeightJb = getTratTotalweight($jbId); // Get the total weight of all articles of the specified job
// $capacityFreeWeight = getFieldValueFromClause("vehicleavailability","vha_weight","crvh_id = '" . $crvhId . "' AND vha_day = '" . $currDay . "'"); // Get free weight capacity of the specified vehicle
// $capacityFreeWeight = $capacityFreeWeight - $atWeightJb;
// updateStmt("vehicleavailability", "crvh_id", $crvhId, array("vha_weight", $capacityFreeWeight), "vha_day = '" . $currDay . "'");
// endif;
// Set global defined parameter
$f_jb_ordertime .= " " . pad($i,2) . ":20:00";
$orderTimePair[1] = $f_jb_ordertime;
$outText .= "JB_ORDERTIME : " . $f_jb_ordertime . " | ";
$retVal = "OK";
break; // Stop iteration
endif;
endif;
endif;
endfor;
endif;
endif;
return $retVal;
}
// ------------------------------------------------------------------------------------------
// ---- PREPARSER JOBSERVICE START ----------------------------------------------------------
// ------------------------------------------------------------------------------------------
$importFileJobService = str_replace("_JOB_", "_JOBSERVICE_", $importFile);
echo $importFile . "<br>";
echo $importFileJobService . "<br>";
//if ($fire && $executeImportProcess == "1" && $importFile != "" && $hqId != "" && is_numeric($hqId) && $cscIdRelated != "" && is_numeric($cscIdRelated) && file_exists($importFileJobService)) :
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $cscIdRelated != "" && is_numeric($cscIdRelated) && file_exists($importFileJobService)) :
echo "Preparser<br>\n";
// Service definition
$serviceArray = array();
// idnum idname fulo_fahrer fulo_monteur provisionsart baulstg
$serviceArray[1] = array("Lieferung", true, false, 0, false , "0002");
$serviceArray[2] = array("Auftragspauschale", false, false, 0, false , "ident_0014");
$serviceArray[3] = array("Kuechenmontage", false, true, 2, true , "ident_0013");
$serviceArray[4] = array("KuechenmontageLfdMeter", false, true, 2, true , "0010");
$serviceArray[5] = array("InstallationEGeraetPauschal", false, true, 2, true , "ident_0005");
$serviceArray[6] = array("KuechendemontageGrundPauschale", false, true, 2, true, "ident_0015");
$serviceArray[7] = array("KuechendemontageLfdMeter", false, true, 2, true , "ident_0025");
$serviceArray[8] = array("Aufmass", true, false, 2, false , "ident_0016");
$serviceArray[9] = array("MontageAnfahrt", false, true, 1, false , "ident_0017");
$serviceArray[10] = array("MontageStunde", false, true, 1, false , "ident_0001");
$serviceArray[11] = array("MontageStundeKArbeitsplatte", false, true, 1, false , "ident_0018");
$serviceArray[12] = array("MoebelmontageGrundPauschale", false, true, 1, false , "ident_0009");
$serviceArray[13] = array("Moebelmontage", false, true, 1, false , "0004");
$serviceArray[14] = array("Sofamontage", true, false, 0, false , "ident_0027");
$serviceArray[15] = array("WasseranschlussBadmoebel", false, true, 1, false , "ident_0011");
$serviceArray[16] = array("InstallationTVGeraet", false, true, 1, false , "ident_0019");
$serviceArray[17] = array("InstallationLautsprecher", false, true, 1, false , "ident_0020");
$serviceArray[18] = array("EntsorgungAltmoebel", true, false, 0, false , "NA");
$serviceArray[19] = array("EntsorgungEGeraet", true, false, 0, false , "ident_0021");
$serviceArray[20] = array("ZusatzKilometerLieferung", true, false, 0, false , "0012");
$serviceArray[21] = array("ZusatzKilometerMontage", false, true, 1, false , "0012");
$serviceArray[22] = array("LagergeldAb6Tag", false, false, 0, false , "0003");
$serviceArray[23] = array("EKS", true, false, 0, false , "ident_0004");
$serviceArray[24] = array("Zusatzmontage", false, true, 1, false , "0014");
$serviceArray[25] = array("Zusatzlieferung", true, false, 0, false , "0013");
$serviceArray[26] = array("Wasseranschluss Küche", false, true, 2, true , "ident_0006");
$serviceArray[27] = array("Verpackung", false, false, 0, false , "ident_0010");
$serviceArray[28] = array("Gewichtszuschlag", true, false, 0, false , "0015");
$serviceArray[29] = array("Abholung", true, false, 0, false , "NA");
$serviceArray[30] = array("Austausch", true, false, 0, false , "NA");
$serviceArray[31] = array("BlaueTasche", true, false, 0, false , "ident_0023");
$serviceArray[32] = array("EntsorgungSofa", true, false, 0, false , "0006:1000");
$serviceArray[33] = array("EntsorgungPolsterbett", true, false, 0, false , "0006:1001");
$serviceArray[34] = array("EntsorgungAnbauwand", true, false, 0, false , "0006:1002");
$serviceArray[35] = array("EntsorgungKleinmoebel", true, false, 0, false , "0006:1003");
$serviceArray[36] = array("EntsorgungBett", true, false, 0, false , "0006:1004");
$serviceArray[37] = array("EntsorgungMatratze", true, false, 0, false , "0006:1005");
$serviceArray[38] = array("Expresslieferung", false, false, 0, false , "NA");
$serviceArray[39] = array("Erste_blaue_Tasche", false, false, 0, false , "ident_0023");
$serviceArray[40] = array("Kuechenzusatzmeter", false, true, 2, true , "ident_0024");
$serviceArray[41] = array("Erneute Anfahrt", true, false, 0, false , "NA");
$serviceArray[42] = array("Montageausfall", false, true, 1, false , "NA");
$jobServiceArray = array();
if (true) :
$rowToImport = array();
$rowToImport[0] = "f_jb_id"; // A : Job ID, "KV-Nr."
$rowToImport[1] = "f_jb_dummy_01"; // B : ????
$rowToImport[2] = "f_order_id"; // C : Commission no. (tr_sort = "2")
$rowToImport[3] = "f_voucher"; // D : Commission no. (tr_sort = "1")
$rowToImport[4] = "f_businesscard_no"; // E : Business card number
$rowToImport[5] = "f_jb_dummy_02"; // F : Business card number
$rowToImport[6] = "f_lfdmeter"; // G: Kosten für laufenden Meter Küche
$rowToImport[7] = "f_service_flag"; // H: SAMS-Flag
$rowToImport[8] = "f_service_id"; // I: Leistungsart => MAPPING !!!!! (Anliegende Tabelle)
$rowToImport[9] = "f_paymenttype"; // J: Zahlart => MAPPING (Lieferung und Montage) !!!!!
$rowToImport[10] = "f_fzg"; // K: Rechnungsfahrzeug !!!!!!!!!!!!!!
$rowToImport[11] = "f_preisev"; // L: Preis ???
$rowToImport[12] = "f_jb_totalprice"; // M: Preis für Service IKEA
$rowToImport[13] = "f_jb_cr_price"; // N: Preis für Service Unternehmer (HTM)
$rowToImport[14] = "f_preisunt"; // O: Preis ???
$rowToImport[15] = "f_rueckvergikea"; // P: Preis Rückvergütung IKEA
$rowToImport[16] = "f_rueckvergunt"; // Q: Preis Rückvergütung Unternehmer (HTM)
$rowToImport[17] = "f_anzahlpf"; // R: ???
$rowToImport[18] = "f_rgnrev"; // S: Rechnungsnr. ???
$rowToImport[19] = "f_rgnrevdatum"; // T: Zugehöriges Datum ???
$rowToImport[20] = "f_rgnrikea"; // U: Rechnungsnr. IKEA ???
$rowToImport[21] = "f_rgnrikeadatum"; // V: Zugehöriges Datum ???
$rowToImport[22] = "f_rgnrunt"; // W: Rechnungsnr. Unternehmer ???
$rowToImport[23] = "f_rgnruntdatum"; // X: Zugehöriges Datum ???
$rowToImport[24] = "f_rgnrrueckvergikea"; // Y: Rechnung Rückvergütung IKEA
$rowToImport[25] = "f_rgnrrueckvergikeadatum"; // Z: Zugehöriges Datum ???
$rowToImport[26] = "f_rgnrgutikea"; // AA : Rechnungsgutschrift IKEA
$rowToImport[27] = "f_rgnrgutikeadatum"; // AB: Zugehöriges Datum ???
$rowToImport[28] = "f_evabgeschlossen"; // AC: Flag
$rowToImport[29] = "f_untabgeschlossen"; // AD: Flag
$rowToImport[30] = "f_evtosap"; // AE: Flag
$rowToImport[31] = "f_unttosap"; // AF: Flag
$rowToImport[32] = "f_rueckvergikeatosap"; // AG: Flag
$rowToImport[33] = "f_gutikeatosap"; // AH: Flag
$rowToImport[34] = "f_kvs"; // AI: Flag
$rowToImport[35] = "f_kvs_info"; // AJ: Flag
$rowToImport[36] = "f_dummy"; // AK: Dummy
$rowToImportLen = count($rowToImport);
// Read file to import
$dataPre = importCSV($importFileJobService, $delimiter);
$dataLen = count($dataPre);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $dataPre[$j][$i];
}
$f_jb_id = mcStrWrap($f_jb_id);
$f_service_id = mcStrWrap($f_service_id);
// Delivery
if ($serviceArray[$f_service_id][1]) :
$jobServiceArray[$f_jb_id][0] = "1";
endif;
// Installation
if ($serviceArray[$f_service_id][2]) :
$jobServiceArray[$f_jb_id][1] = "1";
endif;
}
endif;
endif;
// ------------------------------------------------------------------------------------------
// ---- PREPARSER JOBSERVICE END ------------------------------------------------------------
// ------------------------------------------------------------------------------------------
/*
if ($fire && $executeImportProcess == "1") :
print_r($jobServiceArray);
die();
endif;
*/
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $cscIdRelated != "" && is_numeric($cscIdRelated)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, "import_JOB_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$rowToImport = array();
$parImportArticleFieldsGroup == "";
if ($groupId != "") :
$parImportArticleFieldsGroup = getParameterValue("0", "IMPORT_JOB_FIELDS", "0");
endif;
if ($parImportArticleFieldsGroup != "") :
$rowToImport = spliti(",", $parImportArticleFieldsGroup);
else :
// Default
$rowToImport[0] = "f_jb_id"; // A : Job ID, "KV-Nr."
$rowToImport[1] = "f_jb_dummy_01"; // B : ????
$rowToImport[2] = "f_crvh_sid"; // C : Vehicle SID delivery
$rowToImport[3] = "f_crvh_sid_inst"; // D : Vehicle SID installation
$rowToImport[4] = "f_jb_createtime"; // E : Creation datetime of the job
$rowToImport[5] = "f_jb_ordertime"; // F : Order datetime of the job
$rowToImport[6] = "f_jb_daytime"; // G : Daytime of the job
$rowToImport[7] = "f_cmp_comp"; // H : Customer delivery name and firstname
$rowToImport[8] = "f_ad_street"; // I : Customer delivery.address.street
$rowToImport[9] = "f_ad_addon"; // J : Customer delivery.address.addon
$rowToImport[10] = "f_ad_zipcode"; // K : Customer delivery.address.zipcode
$rowToImport[11] = "f_ad_city"; // L : Customer delivery.address.city
$rowToImport[12] = "f_ad_floor"; // M : Customer delivery.address.floor
$rowToImport[13] = "f_tr_phone"; // N : Customer phone
$rowToImport[14] = "f_inv_ad_name"; // O : Customer invoice name and firstname
$rowToImport[15] = "f_inv_ad_street"; // P : Customer invoice.address.street
$rowToImport[16] = "f_inv_ad_addon"; // Q : Customer invoice.address.addon
$rowToImport[17] = "f_inv_ad_city"; // R : Customer invoice.address.city
$rowToImport[18] = "f_inv_ad_zipcode"; // S : Customer invoice.address.zipcode
$rowToImport[19] = "f_dummy"; // T : Dummy
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter);
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
print_r($data[$j]);
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_jb_id = mcStrWrap($f_jb_id);
$f_crvh_sid = mcStrWrap($f_crvh_sid);
$f_crvh_sid_inst = mcStrWrap($f_crvh_sid_inst);
$f_jb_createtime = mcStrWrap($f_jb_createtime);
$f_jb_ordertime = mcStrWrap($f_jb_ordertime);
$f_jb_ordertime = substr($f_jb_ordertime, 6,4) . "-" . substr($f_jb_ordertime, 3,2) . "-" . substr($f_jb_ordertime, 0,2);
$f_jb_ordertime_ORG = $f_jb_ordertime;
$f_jb_daytime = mcStrWrap($f_jb_daytime);
$f_cmp_comp = mcStrWrap($f_cmp_comp);
$f_ad_street = mcStrWrap($f_ad_street);
$f_ad_addon = mcStrWrap($f_ad_addon);
$f_ad_zipcode = mcStrWrap($f_ad_zipcode);
$f_ad_city = mcStrWrap($f_ad_city);
$f_ad_floor = mcStrWrap($f_ad_floor);
$f_tr_phone = mcStrWrap($f_tr_phone);
$f_inv_ad_name = mcStrWrap($f_inv_ad_name);
$f_inv_ad_street = mcStrWrap($f_inv_ad_street);
$f_inv_ad_addon = mcStrWrap($f_inv_ad_addon);
$f_inv_ad_city = mcStrWrap($f_inv_ad_city);
$f_inv_ad_zipcode = mcStrWrap($f_inv_ad_zipcode);
if (true) :
// Insert new job
if ($fire && $executeImportProcess == "1") :
TA("B");
$csIdRelated = getFieldValueFromId("costcenter", "csc_id", $cscIdRelated, "cs_id");
// Check for existence of the vehicle
$crvhId = getFieldValueFromClause("couriervehicle", "crvh_id", "crvh_sid = '" . $vhtPrefix . $f_crvh_sid . "'");
if ($crvhId == "") :
echo "Fahrzeug " . $vhtPrefix . $f_crvh_sid . " steht nicht im System! <br>------------------------------------------------------------------<br>";
endif;
echo "JB : " . $f_jb_id . " | SID : " . $vhtPrefix . $f_crvh_sid . " | CRVH : " . $crvhId . " | CS_ID : " . $csIdRelated . " | DT : " . $f_jb_daytime . " | ";
// Generate delivery and/or installation job
$generateDeliveryJob = false;
if ($jobServiceArray[$f_jb_id][0] == "1") :
$generateDeliveryJob = true;
echo "DEL YES |";
endif;
$generateInstallationJob = false;
if ($jobServiceArray[$f_jb_id][1] == "1") :
$generateInstallationJob = true;
echo "INST YES |";
endif;
// **** Get daytime intervals from and write FDS ****
$orderTimePair = array();
// if ($mode == "SCHNELSEN") :
if ($crvhId == "" || $f_jb_daytime == "G") :
$f_jb_ordertime .= " 00:00:01";
// echo "IN : G | ";
elseif ($f_jb_daytime == "V") :
$jbDaytimeInterval = getFieldValueFromClause("metatype","mt_mapped_value","mt_type = 'day_time' AND mt_objtype = 'cs' AND mt_objid = '" . $csIdRelated . "' AND mt_sort = '0'");
$hourStart = substr($jbDaytimeInterval,0,2);
$hourEnd = substr($jbDaytimeInterval,8,2);
$chkFDS = checkAvailabilityForJob($crvhId, $f_jb_ordertime, $hourStart, $hourEnd, $f_jb_id, $csIdRelated);
if ($chkFDS == "") : $f_jb_ordertime .= " 00:00:01"; endif;
// echo "IN : V | ";
elseif ($f_jb_daytime == "N") :
$jbDaytimeInterval = getFieldValueFromClause("metatype","mt_mapped_value","mt_type = 'day_time' AND mt_objtype = 'cs' AND mt_objid = '" . $csIdRelated . "' AND mt_sort = '1'");
$hourStart = substr($jbDaytimeInterval,0,2);
$hourEnd = substr($jbDaytimeInterval,8,2);
$chkFDS = checkAvailabilityForJob($crvhId, $f_jb_ordertime, $hourStart, $hourEnd, $f_jb_id, $csIdRelated);
if ($chkFDS == "") : $f_jb_ordertime .= " 00:00:01"; endif;
// echo "IN : N | ";
elseif ($f_jb_daytime == "A") :
$jbDaytimeInterval = getFieldValueFromClause("metatype","mt_mapped_value","mt_type = 'day_time' AND mt_objtype = 'cs' AND mt_objid = '" . $csIdRelated . "' AND mt_sort = '2'");
$hourStart = substr($jbDaytimeInterval,0,2);
$hourEnd = substr($jbDaytimeInterval,8,2);
$chkFDS = checkAvailabilityForJob($crvhId, $f_jb_ordertime, $hourStart, $hourEnd, $f_jb_id, $csIdRelated);
if ($chkFDS == "") : $f_jb_ordertime .= " 00:00:01"; endif;
// echo "IN : A | ";
else :
$f_jb_ordertime .= " 00:00:01";
endif;
// endif;
$orderTimePairLen = count($orderTimePair);
// echo "JB_OT : " . $f_jb_ordertime . " | ";
echo "<br>";
$currentTime = $f_jb_ordertime;
// $jbFinishtime = $f_jb_ordertime;
$jbFinishtime = "";
$f_cs_discount = "0.00";
$f_cs_prov = "0.00";
$f_ad_country = "DE";
$vhtId = "7";
$jbStatus = "9";
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = "1";
// Get zone of the zipcode and customer
$srvpId = getFieldValueFromId("serviceplz", "srvp_plz", $f_ad_zipcode, "srvp_id");
$srvzId = "";
if ($srvpId != "") :
$srvzId = getOneStmt("SELECT srvz.srvz_id FROM servicezone AS srvz, servicezonemapping AS srvzm WHERE srvzm.srvp_id = '" . $srvpId . "' AND srvzm.srvz_id = srvz.srvz_id AND srvz.cs_id = '" . $csIdRelated . "'", "srvz_id");
$srvzName = "";
if ($srvzId != "") :
$srvzName = getFieldValueFromId("servicezone","srvz_id",$srvzId,"srvz_name");
endif;
endif;
// Insert costcenter
$csc_id_new = dbInsert("costcenter", array("csc_name", $f_cmp_comp));
$outText .= "CSC_ID : " . $csc_id_new . " | ";
// Insert user
// $cryptedUsrPassword = cryptDbPassword($f_usr_password);
// $usr_id_new = dbInsert("user", array("hq_id",$hqId,"usr_type",'2',"usr_name",$f_usr_name,"usr_firstname",$f_usr_firstname,"usr_email",$f_usr_email,"usr_phone",$f_usr_phone,"usr_phone2",$f_usr_phone2,"usr_fax",$f_usr_fax,"usr_account",$f_usr_account,"usr_password",$cryptedUsrPassword));
// Insert employee
// $emp_id_new = dbInsert("employee", array("usr_id",$usr_id_new,"csc_id",$csc_id_new,"emp_rights","111111000000"));
// Insert company
$cmp_id_new = dbInsert("company", array("cmp_type", "0", "cmp_comp", $f_cmp_comp, "cmp_comp2", $f_cmp_comp2, "cmp_comp3", $f_cmp_comp3, "cmp_comp4", $f_cmp_comp4,
"cmp_hsno", $f_cmp_hsno, "cmp_iln", $f_cmp_iln, "cmp_tax_idno", $f_cmp_tax_idno, "cmp_stax_idno", $f_cmp_stax_idno, "tx_id", $g_tx_id,
"br_id", $g_br_id, "emp_id_sales", $g_sales_emp_id, "cmp_sales_ranking_man", $f_cmp_sales_ranking_man,
"cmp_bank", $f_cmp_bank, "cmp_bankno", $f_cmp_bankno, "cmp_bankacc", $f_cmp_bankacc,
"cmp_bankmode", $f_cmp_bankmode, "cmp_iban", $f_cmp_iban, "cmp_swift", $f_cmp_swift, "cmp_hqlino", $f_cmp_hqlino,
"cmp_postage", "0", "cmp_inv2hq", $f_cmp_inv2hq,
"cmp_authenticated", "1", "cmp_visible", "1", "cmp_match", $f_cmp_match, "cmp_match2", $f_cmp_match2,
"cmp_remark", $f_cmp_remark, "cmp_remark2", $f_cmp_remark2, "cmp_newsletter", $f_cmp_newsletter, "cmp_new_date", $currentTime, "cmp_modify_status", "0"));
$outText .= "CMP_ID : " . $cmp_id_new . " | ";
// Insert customer
$f_cs_discount = str_replace (",", ".", $f_cs_discount);
$f_cs_prov = str_replace (",", ".", $f_cs_prov);
$f_cs_markup_prov = str_replace (",", ".", $f_cs_markup_prov);
$cs_id_new = dbInsert("customer", array("cmp_id", $cmp_id_new, "hq_id", $hqId, "cs_eid", $f_cs_eid, "csc_id", $csc_id_new,
"csc_id_payer", $g_csc_id, "cs_id_parent", $g2_cs_id, "cs_admin", $emp_id_new, "cs_discount", $f_cs_discount,
"cs_invmode", $f_cs_invmode, "cs_jbstatusmail2csc", $f_cs_jbstatusmail2csc,
"cs_jbstatusmail_price", $f_cs_jbstatusmail_price, "cs_jbstatusmail_emp", $f_cs_jbstatusmail_emp, "cs_jbstatusmail_pdf", $f_cs_jbstatusmail_pdf,
"cs_jbstatusmail_fields", $f_cs_jbstatusmail_fields,
"cs_jbstatusmail", $f_cs_jbstatusmail, "cs_jbstatusmail2", $f_cs_jbstatusmail2, "cs_jbstatusmail3", $f_cs_jbstatusmail3,
"cs_commission_no", $f_cs_commission_no, "cs_cr_fav_only", $f_cs_cr_fav_only,
"cs_jobbatch", $f_cs_jobbatch, "cs_invtext_mode", $f_cs_invtext_mode, "cs_jbedit", $f_cs_jbedit,
"cs_fixprice_discount", $f_cs_fixprice_discount, "cs_prov", $f_cs_prov, "cs_markup", $f_cs_markup, "cs_markup_prov", $f_cs_markup_prov,
"cs_price_warn_uncomplete", $f_cs_price_warn_uncomplete));
$outText .= "CS_ID : " . $cs_id_new . " | ";
// Update new costcenter with new customer
updateStmt("costcenter", "csc_id", $csc_id_new, array("cs_id", $cs_id_new, "csc_visible", "1"));
// Insert address
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
echo "a<br>\n";
$outText .= "AD_ID : " . $ad_id_new . " | ";
// Update (the new) company-entry with address-id
updateStmt("company", "cmp_id", $cmp_id_new, array("ad_id", $ad_id_new));
echo "b<br>\n";
// Insert invoice address
$tmpArray = insertAddress($f_inv_ad_street, $f_inv_ad_zipcode, $f_inv_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_inv_new = $tmpArray[0];
$outText .= "AD_ID_INV : " . $ad_id_inv_new . " | ";
echo "c<br>\n";
// Update the costcenteraddresses
insertStmt("costcenteraddress", array("csc_id", $csc_id_new, "cscad_comp", $f_cmp_comp, "cscad_comp2", $f_cmp_comp2, "cscad_comp3", $f_cmp_comp3, "cscad_comp4", $f_cmp_comp4, "ad_id", $ad_id_new, "adt_id", 1, "cscad_hsno", $f_cmp_hsno, "cscad_remark", "", "cscad_person", "", "cscad_phone", $f_usr_phone));
insertStmt("costcenteraddress", array("csc_id", $csc_id_new, "cscad_comp", $f_cmp_comp, "cscad_comp2", $f_cmp_comp2, "cscad_comp3", $f_cmp_comp3, "cscad_comp4", $f_cmp_comp4, "ad_id", $ad_id_inv_new, "adt_id", 2, "cscad_hsno", $f_cmp_hsno, "cscad_remark", "", "cscad_person", "", "cscad_phone", $f_usr_phone));
insertStmt("costcenteraddress", array("csc_id", $csc_id_new, "cscad_comp", $f_cmp_comp, "cscad_comp2", $f_cmp_comp2, "cscad_comp3", $f_cmp_comp3, "cscad_comp4", $f_cmp_comp4, "ad_id", $ad_id_inv_new, "adt_id", 3, "cscad_hsno", $f_cmp_hsno, "cscad_remark", "", "cscad_person", "", "cscad_phone", $f_usr_phone));
insertStmt("costcenteraddress", array("csc_id", $csc_id_new, "cscad_comp", $f_cmp_comp, "cscad_comp2", $f_cmp_comp2, "cscad_comp3", $f_cmp_comp3, "cscad_comp4", $f_cmp_comp4, "ad_id", $ad_id_new, "adt_id", 4, "cscad_hsno", $f_cmp_hsno, "cscad_remark", "", "cscad_person", "", "cscad_phone", $f_usr_phone));
echo "d<br>\n";
// Insert DEFAULT template for export
// $sqlStmtExport = "INSERT INTO exportparameters (hq_id, cs_id, expc_id, expp_parstr, expp_bolchars, expp_eolchars, expp_bofchars, expp_eofchars, expp_name, expp_fileextension)" .
// " VALUES ($hqId, $cs_id_new, 110, '100010-,-10-,-r-,-0-,--,-0-,-0-,--,--,- -,- -;-100020-,-5-,-r-,-3-,--,-0-,-0-,--,--,- -,- -;-100030-,-8-,-l-,-4-,--,-0-,- -,--,--,- -,- -;-100040-,-5-,-l-,-5-,--,-0-,- -,--,--,- -,- -;-100050-,-8-,-l-,-6-,--,-0-,- -,--,--,- -,- -;-100060-,-5-,-l-,-7-,--,-0-,- -,--,--,- -,- -;-100070-,-8-,-l-,-8-,--,-0-,- -,--,--,- -,- -;-100080-,-5-,-l-,-9-,--,-0-,- -,--,--,- -,- -;-100090-,-420-,-l-,-24-,--,-0-,- -,--,--,- -,- -;-100110-,-10-,-r-,-1-,--,-0-,- -,-1-,--,- -,- -;-100130-,-2-,-r-,-2-,--,-0-,-0-,--,--,- -,- -;-100150-,-30-,-l-,-10-,--,-0-,- -,--,--,- -,- -;-100160-,-30-,-l-,-12-,--,-0-,- -,--,--,- -,- -;-100170-,-30-,-l-,-13-,--,-0-,- -,--,--,- -,- -;-100180-,-30-,-l-,-14-,--,-0-,- -,--,--,- -,- -;-100190-,-5-,-l-,-15-,--,-0-,- -,--,--,- -,- -;-100200-,-5-,-l-,-16-,--,-0-,- -,--,--,- -,- -;-100210-,-30-,-l-,-17-,--,-0-,- -,--,--,- -,- -;-100220-,-15-,-l-,-11-,--,-0-,- -,--,--,- -,- -;-100230-,-30-,-l-,-18-,--,-0-,- -,--,--,- -,- -;-100240-,-30-,-l-,-19-,--,-0-,- -,--,--,- -,- -;-100250-,-30-,-l-,-20-,--,-0-,- -,--,--,- -,- -;-100260-,-5-,-l-,-21-,--,-0-,- -,--,--,- -,- -;-100270-,-5-,-l-,-22-,--,-0-,- -,--,--,- -,- -;-100280-,-30-,-l-,-23-,--,-0-,- -,--,--,- -,- ', '', '', '', '', 'DEFAULT', NULL)";
// $res = $db->query($sqlStmtExport);
// if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif;
// if ($generateDeliveryJob) : echo "generateDeliveryJob: JA"; else : echo "generateDeliveryJob: NEIN"; endif; echo "<br>";
// if ($generateInstallationJob) : echo "generateInstallationJob: JA"; else : echo "generateInstallationJob: NEIN"; endif; echo "<br>";
// Delivery job
if ($generateDeliveryJob) :
if ($orderTimePair[0] != "") :
$f_jb_ordertime = $orderTimePair[0];
endif;
if ($f_jb_ordertime == "" || $f_jb_ordertime == "0000-00-00 00:00:00") :
$f_jb_ordertime = $f_jb_ordertime_ORG . " 00:00:01";
endif;
insertStmt("job", array("jb_id", $f_jb_id, "hq_id", $hqId, "csc_id", $csc_id_new, "vht_id", $vhtId, "csc_id_payer", $csc_id_new, "csc_id_related", $cscIdRelated, "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "0", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", "", "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $jbTourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_invmode", $csInvmode, "jb_mediationarea_id", $srvzId, "jb_mediationarea_name", $srvzName,
"jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", $jbTimeUnits,
"jb_service", $jbService, "jb_booktime", ""));
// $jbIdNew = getLastInsertId();
$jbIdNew = $f_jb_id; // Take existing job ID from import file
$outText .= "JB_ID_DELV : " . $jbIdNew . "<br>";
// Insert tour data
// Station 1
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $tr1_adId, "tr_sort", "1", "tr_comp", $tr1_comp, "tr_comp2", "",
"tr_hsno", "", "tr_floor", $f_ad_floor, "csc_id", $tr1_cscId, "tr_status", "0",
"tr_commission_no", $f_voucher, "tr_ware_from_to", "",
"tr_person", "", "tr_phone", "", "tr_remark", ""));
// Station 2
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", "2", "tr_comp", $f_cmp_comp, "tr_comp2", "",
"tr_hsno", "", "csc_id", $csc_id_new, "tr_status", "0",
"tr_commission_no", $f_order_id, "tr_ware_from_to", "",
"tr_person", "", "tr_phone", $f_tr_phone, "tr_remark", ""));
// Insert tourservice data
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $csc_id_new, "tr_sort", "0",
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
// echo "jbIdNew: " . $jbIdNew . "<br>";
// echo "jbpIdNew: " . $jbpIdNew . "<br>";
endif;
// Installation job
if ($generateInstallationJob) :
if ($orderTimePair[1] != "") :
$f_jb_ordertime = $orderTimePair[1];
endif;
if ($generateDeliveryJob) :
$f_jb_id = $f_jb_id_child++;
else :
$jbIdNew = "0";
endif;
if ($orderTimePairLen > 0) :
$f_jb_ordertime = $orderTimePair[1];
endif;
if ($f_jb_ordertime == "" || $f_jb_ordertime == "0000-00-00 00:00:00") :
$f_jb_ordertime = $f_jb_ordertime_ORG . " 00:00:01";
endif;
insertStmt("job", array("jb_id", $f_jb_id, "hq_id", $hqId, "csc_id", $csc_id_new, "vht_id", $vhtId, "csc_id_payer", $csc_id_new, "csc_id_related", $cscIdRelated, "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "0", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", "", "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $jbTourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice_M, "jb_totalprice", $sum_totalprice_M, "jb_subtotalprice", $sum_totalprice_M,
"jb_cr_price", $f_jb_cr_price_M, "jb_cr_subprice", $f_jb_cr_price_M,
"jb_postage", "0", "jb_invmode", $csInvmode, "jb_mediationarea_id", $srvzId, "jb_mediationarea_name", $srvzName,
"jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", $jbIdNew, "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", $jbTimeUnits_M,
"jb_service", $jbService_M, "jb_booktime", ""));
// $jbIdNew = getLastInsertId();
$jbIdNew = $f_jb_id; // Take existing job ID from import file
$outText .= "JB_ID_INST : " . $jbIdNew . "<br>";
// Insert tour data
// Station 1
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $tr1_adId, "tr_sort", "1", "tr_comp", $tr1_comp, "tr_comp2", "",
"tr_hsno", "", "tr_floor", $f_ad_floor, "csc_id", $tr1_cscId, "tr_status", "0",
"tr_commission_no", $f_voucher, "tr_ware_from_to", "",
"tr_person", "", "tr_phone", "", "tr_remark", ""));
// Station 2
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", "2", "tr_comp", $f_cmp_comp, "tr_comp2", "",
"tr_hsno", "", "csc_id", $csc_id_new, "tr_status", "0",
"tr_commission_no", $f_order_id, "tr_ware_from_to", "",
"tr_person", "", "tr_phone", $f_tr_phone, "tr_remark", ""));
// Insert tourservice data
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $csc_id_new, "tr_sort", "0",
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice_M));
endif;
$executionCount++;
TA("C");
TA("E");
endif;
else :
$outText .= getLngt("XXXX!") . "<br>";
endif;
echo "--------------------------- <br>";
}
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_JOB.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,548 @@
<?php
/*=======================================================================
*
* import_JOBARTICLE.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRAGSARTIKEL");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true;
// Set headquarters to import jobs
$hqId = $objId;
if ($hqId == "") : $hqId = $hq_id; endif;
$tratSort = 1;
$remJbId = "";
$f_jb_id_addM = $db->getOne("SELECT MAX(jb_id) FROM job WHERE (jb_id > 265000 AND jb_id < 270000)");
if ($f_jb_id_addM == "")
$f_jb_id_addM = 265001;
else
$f_jb_id_addM++;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
if ($importFile != "" && $hqId != "" && is_numeric($hqId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, "import_JOBARTICLE_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$rowToImport = array();
$parImportArticleFieldsGroup == "";
if ($groupId != "") :
$parImportArticleFieldsGroup = getParameterValue("0", "IMPORT_JOBARTICLE_FIELDS", "0");
endif;
if ($parImportArticleFieldsGroup != "") :
$rowToImport = spliti(",", $parImportArticleFieldsGroup);
else :
// Default
$rowToImport[0] = "f_jb_id"; // Job ID, "KV-Nr."
$rowToImport[1] = "f_jb_dummy_01"; // ????
$rowToImport[2] = "f_at_name"; // Article number (name)
$rowToImport[3] = "f_at_description"; // Article description
$rowToImport[4] = "f_at_price"; // Article price
$rowToImport[5] = "f_trat_price"; // Tourarticle price
$rowToImport[6] = "f_trat_quantity"; // Tourarticle quantity
$rowToImport[7] = "f_stock"; // Stock information
$rowToImport[8] = "f_stock_name"; // Stock information
$rowToImport[9] = "f_inst_mode"; // Versandart (NUMERISCH) ("Lieferung IKEA" [= 51], "Austausch" [= 57], "Lieferung + Sofa-Montage IKEA" [= 53], "Lieferung + Montage IKEA" [= 52])
$rowToImport[10] = "f_trat_remark"; // Remark ("Lieferung, Montage, Abholung, ...")
$rowToImport[11] = "f_inst_timeunits"; // Zusatzmontage
$rowToImport[12] = "f_trat_packingpieces"; // Customer delivery.address.floor
$rowToImport[13] = "f_dummy"; // Dummy
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter);
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_jb_id = removeFieldSigns($f_jb_id);
$f_at_name = removeFieldSigns($f_at_name);
$f_at_description = removeFieldSigns($f_at_description);
$f_at_price = removeFieldSigns($f_at_price);
$f_at_price = str_replace (",", ".", $f_at_price);
$f_trat_price = removeFieldSigns($f_trat_price);
$f_trat_price = str_replace (",", ".", $f_trat_price);
$f_trat_quantity = removeFieldSigns($f_trat_quantity);
$f_trat_quantity = str_replace (",", ".", $f_trat_quantity);
$f_stock = removeFieldSigns($f_stock);
$f_stock_name = removeFieldSigns($f_stock_name);
$f_inst_mode = removeFieldSigns($f_inst_mode);
$f_trat_remark = removeFieldSigns($f_trat_remark);
$gdcTratInstallation = $f_trat_remark; // TEXT ZUR "VERSANDART" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$f_trat_remark = $f_at_description; // !!!!
$f_inst_timeunits = removeFieldSigns($f_inst_timeunits);
$f_trat_packingpieces = removeFieldSigns($f_trat_packingpieces);
if ($remJbId != $f_jb_id) :
$tratSort = 1;
$remJbId = $f_jb_id;
// Init job services regarding article
$jbServiceDel = 0;
$jbServiceInst = 0;
// Init job has no addmont
$jbHasAddmont = false;
endif;
// "Addmont"
if ($f_at_name == "80100" && $f_inst_timeunits != "" && is_numeric($f_inst_timeunits)) :
echo "ZM-Std.: " . $f_inst_timeunits . " => ";
$f_inst_timeunits = round(round(round($f_inst_timeunits / 12, 1) * 2) / 2, 1);
echo $f_inst_timeunits . "<br>";
$jbHasAddmont = true;
else :
$f_inst_timeunits = 0;
endif;
// Article is delivery AND installation
$articleIsDelvAndInst = false;
if ($f_inst_mode == "52" || $f_inst_mode == "56" || $f_inst_mode == "58") :
$articleIsDelvAndInst = true;
endif;
// Article is "sofa-montage"
$articleIsCouchInstallation = false;
if ($f_inst_mode == "53") :
$articleIsCouchInstallation = true;
endif;
$installationOnly = false;
if ($f_inst_mode == "54") :
$installationOnly = true;
endif;
// "Versandart" (NUMERISCH)
// ("Lieferung IKEA" [= 51], "Austausch" [= 57], "Lieferung + Sofa-Montage IKEA" [= 53],
// "Lieferung + Montage IKEA" [= 52], "Montage" [= 54], "Abholung und Demontage" [= 56], "Austausch und Montage" [= 58])
if ($f_inst_mode == "52" || $f_inst_mode == "54" || $f_inst_mode == "56" || $f_inst_mode == "58") :
// Set job services
if ($f_inst_mode == "56") :
(int)$jbServiceInst = ((int)$jbServiceInst | 128);
endif;
if ($f_inst_mode == "58") :
(int)$jbServiceInst = ((int)$jbServiceInst | 256);
endif;
$f_inst_mode = "1";
else :
// Set job services
if ($f_inst_mode == "57") :
(int)$jbServiceDel = ((int)$jbServiceDel | 256);
endif;
$f_inst_mode = "0";
endif;
if (true) :
// Insert new article
if ($fire && $executeImportProcess == "1") :
TA("B");
if ($articleIsDelvAndInst || $f_inst_mode == "0" || $installationOnly) :
if (existsEntry("job",array("jb_id",$f_jb_id))) :
// Search article
$atId = getFieldValueFromId("article", "at_name", $f_at_name, "at_id");
// if ($atId != "") :
// Insert into table "tourarticle"
insertStmt("tourarticle", array("jb_id", $f_jb_id, "tr_sort", "2", "trat_sort", $tratSort,
"at_id", $atId, "trat_quantity", $f_trat_quantity, "trat_weight", "", "trat_price", $f_trat_price,
"trat_packingpieces", $f_trat_packingpieces, "trat_remark", $f_trat_remark));
$tratIdNew = getLastInsertId();
if ($tratIdNew != "") :
// Insert article installation mode ("Lieferung IKEA" [= 51], "Austausch" [= 57], etc)
if ($articleIsCouchInstallation) :
$gdcContentAddInfo = getFieldValueFromClause("genericdatacontainer", "gdc_content", "gdc_obj_type = 'jb' AND gdc_obj_id = '" . $f_jb_id . "' AND gdc_gen_fieldname = 'jb_addinfo'");
if ($gdcContentAddInfo == "") :
insertStmt("genericdatacontainer", array("gdc_obj_type", "jb", "gdc_obj_id", $f_jb_id, "gdc_gen_fieldname", "jb_addinfo", "gdc_content", "ACHTUNG: Sofa-Montage", "gdc_context", ""));
endif;
endif;
$tratSort++;
$executionCount++;
// Update jb_service
if ($installationOnly) :
(int)$jbServiceDel = ((int)$jbServiceDel | 2);
endif;
$jbService = getFieldValueFromId("job", "jb_id", $f_jb_id, "jb_service");
(int)$jbServiceDel = ((int)$jbServiceDel | (int)$jbService);
updateStmt("job", "jb_id", $f_jb_id, array("jb_service", $jbServiceDel));
else :
$outText .= getLngt("TOURARTICLE WURDE NICHT ANGELEGT!") . " [JOB " . $f_jb_id . "]<br>";
endif;
// else :
// $outText .= getLngt("ARTIKEL NICHT IM ARTIKELSTAMM!") . " [JOB " . $f_jb_id . "]<br>";
// endif;
if ($atId == "") : $outText .= getLngt("ARTIKEL NICHT IM ARTIKELSTAMM!") . " [JOB " . $f_jb_id . " | NR.: " . $f_at_name . " | ARTIKELTEXT : " . $f_trat_remark . "]<br>"; endif;
else :
$outText .= getLngt("AUFTRAG /1 EXISTIERT NICHT!") . " [JOB " . $f_jb_id . "]<br>";
endif;
endif;
// ----
if ($articleIsDelvAndInst) :
$f_jb_id_M = getFieldValueFromId("job","jb_id_parent",$f_jb_id,"jb_id");
// Search article
$atId = getFieldValueFromId("article", "at_name", $f_at_name, "at_id");
// if ($atId != "") :
// Insert into table "tourarticle"
insertStmt("tourarticle", array("jb_id", $f_jb_id_M, "tr_sort", "2", "trat_sort", $tratSort,
"at_id", $atId, "trat_quantity", $f_trat_quantity, "trat_weight", "", "trat_price", $f_trat_price,
"trat_packingpieces", $f_trat_packingpieces, "trat_remark", $f_trat_remark));
$tratIdNew = getLastInsertId();
if ($tratIdNew != "") :
// Insert article installation mode ("Lieferung IKEA" [= 51], "Austausch" [= 57], etc)
// insertStmt("genericdatacontainer", array("gdc_obj_type", "trat", "gdc_obj_id", $tratIdNew, "gdc_gen_fieldname", "sofa-montage", "gdc_content", $f_inst_mode, "gdc_context", $gdcTratInstallation));
$tratSort++;
$executionCount++;
// Update jb_service
$jbService = getFieldValueFromId("job", "jb_id", $f_jb_id_M, "jb_service");
(int)$jbServiceInst = ((int)$jbServiceInst | (int)$jbService);
updateStmt("job", "jb_id", $f_jb_id_M, array("jb_service", $jbServiceInst));
else :
$outText .= getLngt("TOURARTICLE WURDE NICHT ANGELEGT!") . " [JOB " . $f_jb_id_M . "]<br>";
endif;
// else :
// $outText .= getLngt("ARTIKEL NICHT IM ARTIKELSTAMM!") . " [JOB " . $f_jb_id_M . "]<br>";
// endif;
if ($atId == "") : $outText .= getLngt("ARTIKEL NICHT IM ARTIKELSTAMM!") . " [JOB " . $f_jb_id_M . " | NR.: " . $f_at_name . " | ARTIKELTEXT : " . $f_trat_remark . "]<br>"; endif;
else:
$f_jb_id_M = $f_jb_id;
endif;
if ($jbHasAddmont) :
// ----
// ($jbHasAddmont && $f_inst_mode == "0") <=> Delivery only but addmont does exist!
// if ($articleIsDelvAndInst || $f_inst_mode == "1" || ($jbHasAddmont && $f_inst_mode == "0")) :
// $f_jb_id_M = getFieldValueFromId("job","jb_id_parent",$f_jb_id,"jb_id");
// **** NEW (START) ****
// Job could not exist because JOB IMPORT had delivery job only but added installation is in article !!!!
// if (($jbHasAddmont && $f_inst_mode == "0") && !existsEntry("job",array("jb_id",$f_jb_id_M))) :
// if ($jbHasAddmont && $f_jb_id_M != "" && !existsEntry("job",array("jb_id",$f_jb_id_addM))) :
if ($f_jb_id_M == ""):
$csc_id_new = getFieldValueFromId("job","jb_id",$f_jb_id,"csc_id");
$vhtId = getFieldValueFromId("job","jb_id",$f_jb_id,"vht_id");
$csc_id_new = getFieldValueFromId("job","jb_id",$f_jb_id,"csc_id_payer");
$cscIdRelated = getFieldValueFromId("job","jb_id",$f_jb_id,"csc_id_related");
$f_jb_ordertime = getFieldValueFromId("job","jb_id",$f_jb_id,"jb_ordertime");
$crId = getFieldValueFromId("job","jb_id",$f_jb_id,"cr_id");
$crSid = getFieldValueFromId("job","jb_id",$f_jb_id,"cr_sid");
$jbCrFilter = getFieldValueFromId("job","jb_id",$f_jb_id,"jb_cr_filter");
$usr_id = getFieldValueFromId("job","jb_id",$f_jb_id,"emp_id");
$csInvmode = getFieldValueFromId("job","jb_id",$f_jb_id,"jb_invmode");
$srvzId = getFieldValueFromId("job","jb_id",$f_jb_id,"jb_mediationarea_id");
$srvzName = getFieldValueFromId("job","jb_id",$f_jb_id,"jb_mediationarea_name");
$jbRemark = getFieldValueFromId("job","jb_id",$f_jb_id,"jb_freetext_1");
$jbTourdata = getFieldValueFromId("job","jb_id",$f_jb_id,"jb_tourdata");
$txValue = getFieldValueFromId("job","jb_id",$f_jb_id,"jb_sales_tax_rate");
$txSign = getFieldValueFromId("job","jb_id",$f_jb_id,"jb_sales_tax_rate_sign");
$jbTimeUnits_M = "2";
$jbService_M = "2";
$sum_totalprice_M = "0";
$f_jb_cr_price_M = "0";
insertStmt("job", array("jb_id", $f_jb_id_addM, "hq_id", $hqId, "csc_id", $csc_id_new, "vht_id", $vhtId, "csc_id_payer", $csc_id_new, "csc_id_related", $cscIdRelated, "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "0", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", "", "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $jbTourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice_M, "jb_totalprice", $sum_totalprice_M, "jb_subtotalprice", $sum_totalprice_M,
"jb_cr_price", $f_jb_cr_price_M, "jb_cr_subprice", $f_jb_cr_price_M,
"jb_postage", "0", "jb_invmode", $csInvmode, "jb_mediationarea_id", $srvzId, "jb_mediationarea_name", $srvzName,
"jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", $f_jb_id, "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", $jbTimeUnits_M,
"jb_service", $jbService_M, "jb_booktime", ""));
// $jbIdNew = getLastInsertId();
$jbIdNew = $f_jb_id_addM; // Take existing job ID from import file
$outText .= "JB_ID_INST : " . $jbIdNew . "<br>";
$tr1_adId = getFieldValueFromClause("tour", "ad_id", "jb_id = '" . $f_jb_id . "' AND tr_sort = '1'");
$tr1_comp = getFieldValueFromClause("tour", "tr_comp", "jb_id = '" . $f_jb_id . "' AND tr_sort = '1'");
$f_ad_floor = getFieldValueFromClause("tour", "tr_floor", "jb_id = '" . $f_jb_id . "' AND tr_sort = '1'");
$tr1_cscId = getFieldValueFromClause("tour", "csc_id", "jb_id = '" . $f_jb_id . "' AND tr_sort = '1'");
$f_voucher = getFieldValueFromClause("tour", "tr_commission_no", "jb_id = '" . $f_jb_id . "' AND tr_sort = '1'");
// Insert tour data
// Station 1
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $tr1_adId, "tr_sort", "1", "tr_comp", $tr1_comp, "tr_comp2", "",
"tr_hsno", "", "tr_floor", $f_ad_floor, "csc_id", $tr1_cscId, "tr_status", "0",
"tr_commission_no", $f_voucher, "tr_ware_from_to", "",
"tr_person", "", "tr_phone", "", "tr_remark", ""));
$ad_id_new = getFieldValueFromClause("tour", "ad_id", "jb_id = '" . $f_jb_id . "' AND tr_sort = '2'");
$f_cmp_comp = getFieldValueFromClause("tour", "tr_comp", "jb_id = '" . $f_jb_id . "' AND tr_sort = '2'");
$f_ad_floor = getFieldValueFromClause("tour", "tr_floor", "jb_id = '" . $f_jb_id . "' AND tr_sort = '2'");
$csc_id_new = getFieldValueFromClause("tour", "csc_id", "jb_id = '" . $f_jb_id . "' AND tr_sort = '2'");
$f_order_id = getFieldValueFromClause("tour", "tr_commission_no", "jb_id = '" . $f_jb_id . "' AND tr_sort = '2'");
$f_tr_phone = getFieldValueFromClause("tour", "tr_phone", "jb_id = '" . $f_jb_id . "' AND tr_sort = '2'");
// Station 2
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", "2", "tr_comp", $f_cmp_comp, "tr_comp2", "",
"tr_hsno", "", "tr_floor", $f_ad_floor, "csc_id", $csc_id_new, "tr_status", "0",
"tr_commission_no", $f_order_id, "tr_ware_from_to", "",
"tr_person", "", "tr_phone", $f_tr_phone, "tr_remark", ""));
$csc_id_new = getFieldValueFromClause("tourservice", "csc_id", "jb_id = '" . $f_jb_id . "' AND tr_sort = '0'");
// Insert tourservice data
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $csc_id_new, "tr_sort", "0",
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice_M));
// insertStmt("jobcalculator", array("jb_id", $jbIdNew, "tr_sort", "2", "srv_id", "0", "srv_name", "Grundpauschale&nbsp;Montage", "srvt_id", "0",
// "srvt_name", "0002:par_01", "jbc_amount", "1.00", "jbc_price", $sum_totalprice_M, "jbc_totalprice", $sum_totalprice_M));
$f_jb_id_M = $f_jb_id_addM++;
endif;
// **** NEW (END) ****
// if (existsEntry("job",array("jb_id",$f_jb_id_M))) :
//echo "|" . $f_inst_timeunits . "|<br>";
// Added installation
if ($f_inst_timeunits > 0) :
if (existsEntry("genericdatacontainer", array("gdc_obj_type", "jb", "gdc_gen_fieldname", "jb_addmont", "gdc_obj_id", $f_jb_id_M))) :
$gdcContextAddMon = getFieldValueFromClause("genericdatacontainer", "gdc_context", "gdc_obj_type = 'jb' AND gdc_gen_fieldname = 'jb_addmont' AND gdc_obj_id = '" . $f_jb_id_M . "'");
if ($gdcContextAddMon == "" || !is_numeric($gdcContextAddMon)) :
$gdcContextAddMon = 0;
endif;
$f_inst_timeunits += $gdcContextAddMon;
updateStmt("genericdatacontainer", "gdc_obj_id", $f_jb_id_M, array("gdc_context", $f_inst_timeunits), "gdc_obj_type = 'jb' AND gdc_gen_fieldname = 'jb_addmont'");
//echo "update $f_jb_id_M<br>";
else :
// if ($f_inst_timeunits > 0) :
insertStmt("genericdatacontainer", array("gdc_obj_type", "jb", "gdc_obj_id", $f_jb_id_M, "gdc_gen_fieldname", "jb_addmont", "gdc_context", $f_inst_timeunits));
//echo "insert $f_jb_id_M<br>";
updateStmt("job", "jb_id", $f_jb_id_M, array("jb_incomplete", "1"));
// $jbCscIdRelated = getFieldValueFromId("job", "jb_id", $f_jb_id_M, "csc_id_related");
// insertStmt("jobpayment", array("jb_id", $f_jb_id_M, "tr_sort", "2", "csc_id", $jbCscIdRelated, "jbp_mode", "0", "jbp_price", "0.000", "jbp_bookingtime", "", "jbp_counter", "0"));
// $jbpIdNew = getLastInsertId();
// insertStmt("genericdatacontainer", array("gdc_obj_type", "jb", "gdc_obj_id", $f_jb_id_M, "gdc_gen_fieldname", "jbp_id", "gdc_content", $jbpIdNew));
// endif;
endif;
endif;
// else :
// if ($f_jb_id_M != "")
// $outText .= getLngt("AUFTRAG /2 EXISTIERT NICHT!") . " [JOB " . $f_jb_id_M . "]<br>";
// endif;
endif;
TA("C");
TA("E");
// $closeWindow = "1";
endif;
else :
$outText .= getLngt("XXXX!") . "<br>";
endif;
}
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_JOBARTICLE.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,612 @@
<?php
/*=======================================================================
*
* import_JOBSERVICE.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRAGSARTIKEL");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true;
// Set headquarters to import jobs
$hqId = $hq_id;
$csIdRelated = $objId;
$remJbId = "";
// Array for "jobpaymentcollection"
$jbpcArray = array();
$jbpc_modeArray = array();
$jbpcSamsFlagArray = array();
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
if ($importFile != "" && $hqId != "" && is_numeric($hqId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// Service definition
$serviceArray = array();
// idnum idname fulo_fahrer fulo_monteur provisionsart baulstg
$serviceArray[1] = array("Lieferung", true, false, 0, false , "0002");
$serviceArray[2] = array("Auftragspauschale", false, false, 0, false , "ident_0014");
$serviceArray[3] = array("Kuechenmontage", false, true, 2, true , "ident_0013");
$serviceArray[4] = array("KuechenmontageLfdMeter", false, true, 2, true , "0010");
$serviceArray[5] = array("InstallationEGeraetPauschal", false, true, 2, true , "ident_0005");
$serviceArray[6] = array("KuechendemontageGrundPauschale", false, true, 2, true, "ident_0015");
$serviceArray[7] = array("KuechendemontageLfdMeter", false, true, 2, true , "ident_0025");
$serviceArray[8] = array("Aufmass", true, false, 2, false , "ident_0016");
$serviceArray[9] = array("MontageAnfahrt", false, true, 1, false , "ident_0017");
$serviceArray[10] = array("MontageStunde", false, true, 1, false , "ident_0001");
$serviceArray[11] = array("MontageStundeKArbeitsplatte", false, true, 1, false , "ident_0018");
$serviceArray[12] = array("MoebelmontageGrundPauschale", false, true, 1, false , "ident_0009");
$serviceArray[13] = array("Moebelmontage", false, true, 1, false , "0004");
$serviceArray[14] = array("Sofamontage", true, false, 0, false , "ident_0027");
$serviceArray[15] = array("WasseranschlussBadmoebel", false, true, 1, false , "ident_0011");
$serviceArray[16] = array("InstallationTVGeraet", false, true, 1, false , "ident_0019");
$serviceArray[17] = array("InstallationLautsprecher", false, true, 1, false , "ident_0020");
$serviceArray[18] = array("EntsorgungAltmoebel", true, false, 0, false , "NA");
$serviceArray[19] = array("EntsorgungEGeraet", true, false, 0, false , "ident_0021");
$serviceArray[20] = array("ZusatzKilometerLieferung", true, false, 0, false , "0012");
$serviceArray[21] = array("ZusatzKilometerMontage", false, true, 1, false , "0012");
$serviceArray[22] = array("LagergeldAb6Tag", false, false, 0, false , "0003");
$serviceArray[23] = array("EKS", true, false, 0, false , "ident_0004");
$serviceArray[24] = array("Zusatzmontage", false, true, 1, false , "0014");
$serviceArray[25] = array("Zusatzlieferung", true, false, 0, false , "0013");
$serviceArray[26] = array("Wasseranschluss Küche", false, true, 2, true , "ident_0006");
$serviceArray[27] = array("Verpackung", false, false, 0, false , "ident_0010");
$serviceArray[28] = array("Gewichtszuschlag", true, false, 0, false , "0015");
$serviceArray[29] = array("Abholung", true, false, 0, false , "NA");
$serviceArray[30] = array("Austausch", true, false, 0, false , "NA");
$serviceArray[31] = array("BlaueTasche", true, false, 0, false , "ident_0023");
$serviceArray[32] = array("EntsorgungSofa", true, false, 0, false , "0006:1000");
$serviceArray[33] = array("EntsorgungPolsterbett", true, false, 0, false , "0006:1001");
$serviceArray[34] = array("EntsorgungAnbauwand", true, false, 0, false , "0006:1002");
$serviceArray[35] = array("EntsorgungKleinmoebel", true, false, 0, false , "0006:1003");
$serviceArray[36] = array("EntsorgungBett", true, false, 0, false , "0006:1004");
$serviceArray[37] = array("EntsorgungMatratze", true, false, 0, false , "0006:1005");
$serviceArray[38] = array("Expresslieferung", false, false, 0, false , "NA");
$serviceArray[39] = array("Erste_blaue_Tasche", false, false, 0, false , "ident_0023");
$serviceArray[40] = array("Kuechenzusatzmeter", false, true, 2, true , "ident_0024");
$serviceArray[41] = array("Erneute Anfahrt", true, false, 0, false , "NA");
$serviceArray[42] = array("Montageausfall", false, true, 1, false , "NA");
// Mapping for payment types
// 1 = EC-Pin, 2 = EC-Last, 3=Family, 4= BC, 5=Bar [6=Bar-Mont., 7=EC-Pin-Mont., 8=EC-LAst-Mont., 9=Famil.Mont., 10=Rechnung]
$paymentTypeMappingArray = array();
$paymentTypeMappingArray[0] = 0;
$paymentTypeMappingArray[1] = 1;
$paymentTypeMappingArray[2] = 2;
$paymentTypeMappingArray[3] = 10;
$paymentTypeMappingArray[4] = 11;
$paymentTypeMappingArray[5] = 0;
$paymentTypeMappingArray[6] = 0;
$paymentTypeMappingArray[7] = 1;
$paymentTypeMappingArray[8] = 2;
$paymentTypeMappingArray[9] = 10;
$paymentTypeMappingArray[10] = 5;
// ***********************
// * IMPORT FILE SERVICE *
// ***********************
if (!(strpos($filename, "import_JOBSERVICE_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$rowToImport = array();
$parImportServiceFieldsGroup == "";
if ($groupId != "") :
$parImportServiceFieldsGroup = getParameterValue("0", "IMPORT_JOBSERVICE_FIELDS", "0");
endif;
if ($parImportServiceFieldsGroup != "") :
$rowToImport = spliti(",", $parImportServiceFieldsGroup);
else :
// Default
$rowToImport[0] = "f_jb_id"; // A : Job ID, "KV-Nr."
$rowToImport[1] = "f_jb_dummy_01"; // B : ????
$rowToImport[2] = "f_order_id"; // C : Commission no. (tr_sort = "2")
$rowToImport[3] = "f_voucher"; // D : Commission no. (tr_sort = "1")
$rowToImport[4] = "f_businesscard_no"; // E : Business card number
$rowToImport[5] = "f_jb_dummy_02"; // F : ???
$rowToImport[6] = "f_lfdmeter"; // G: Kosten für laufenden Meter Küche
$rowToImport[7] = "f_service_flag"; // H: SAMS-Flag
$rowToImport[8] = "f_service_id"; // I: Leistungsart => MAPPING !!!!! (Anliegende Tabelle)
$rowToImport[9] = "f_paymenttype"; // J: Zahlart => MAPPING (Lieferung und Montage) !!!!!
$rowToImport[10] = "f_fzg"; // K: Rechnungsfahrzeug !!!!!!!!!!!!!!
$rowToImport[11] = "f_preisev"; // L: Preis Endverbraucher
$rowToImport[12] = "f_preisikea"; // M: Preis für Service IKEA (Gutschrift extern)
$rowToImport[13] = "f_preisht"; // N: Preis für Service Unternehmer (HTM) (Forderung extern)
$rowToImport[14] = "f_preisunt"; // O: Preis Unternehmer (Fuhrlohn brutto)
$rowToImport[15] = "f_rueckvergikea"; // P: Preis Rückvergütung IKEA (Rückvergütung Forderung extern)
$rowToImport[16] = "f_rueckvergunt"; // Q: Preis Rückvergütung Unternehmer (HTM) (Rückvergütung Fuhrlohn)
$rowToImport[17] = "f_anzahlpf"; // R: Anzahl Paketfahrscheine
$rowToImport[18] = "f_rgnrev"; // S: Rechnungsnr.
$rowToImport[19] = "f_rgnrevdatum"; // T: Zugehöriges Datum ???
$rowToImport[20] = "f_rgnrikea"; // U: Rechnungsnr. IKEA (nur für EKS leistungsart = 23)
$rowToImport[21] = "f_rgnrikeadatum"; // V: Zugehöriges Datum ???
$rowToImport[22] = "f_rgnrunt"; // W: Rechnungsnr. Unternehmer ???
$rowToImport[23] = "f_rgnruntdatum"; // X: Zugehöriges Datum ???
$rowToImport[24] = "f_rgnrrueckvergikea"; // Y: Rechnung Rückvergütung IKEA
$rowToImport[25] = "f_rgnrrueckvergikeadatum"; // Z: Zugehöriges Datum ???
$rowToImport[26] = "f_rgnrgutikea"; // AA : Rechnungsgutschrift IKEA
$rowToImport[27] = "f_rgnrgutikeadatum"; // AB: Zugehöriges Datum ???
$rowToImport[28] = "f_evabgeschlossen"; // AC: Flag
$rowToImport[29] = "f_untabgeschlossen"; // AD: Flag
$rowToImport[30] = "f_evtosap"; // AE: Flag
$rowToImport[31] = "f_unttosap"; // AF: Flag
$rowToImport[32] = "f_rueckvergikeatosap"; // AG: Flag
$rowToImport[33] = "f_gutikeatosap"; // AH: Flag
$rowToImport[34] = "f_kvs"; // AI: Flag
$rowToImport[35] = "f_kvs_info"; // AJ: Flag
$rowToImport[36] = "f_dummy"; // AK: Dummy
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter);
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_jb_id = removeFieldSigns($f_jb_id);
$f_order_id = removeFieldSigns($f_order_id);
$f_voucher = removeFieldSigns($f_voucher);
$f_businesscard_no = removeFieldSigns($f_businesscard_no);
$f_service_flag = removeFieldSigns($f_service_flag);
$f_service_id = removeFieldSigns($f_service_id);
$f_fzg = removeFieldSigns($f_fzg);
$f_preisikea = removeFieldSigns($f_preisikea);
$f_preisikea = str_replace (",", ".", $f_preisikea);
$f_preisht = removeFieldSigns($f_preisht);
$f_preisht = str_replace (",", ".", $f_preisht);
$f_preisht2 = removeFieldSigns($f_preisht2);
$f_preisht2 = str_replace (",", ".", $f_preisht2);
$f_jb_stockprice = removeFieldSigns($f_jb_stockprice);
$f_jb_stockprice = str_replace (",", ".", $f_jb_stockprice);
$f_jb_packingprice = removeFieldSigns($f_jb_packingprice);
$f_jb_packingprice = str_replace (",", ".", $f_jb_packingprice);
$f_jb_removalprice = removeFieldSigns($f_jb_removalprice);
$f_jb_removalprice = str_replace (",", ".", $f_jb_removalprice);
$f_jb_eks = removeFieldSigns($f_jb_eks);
$f_jb_eks = str_replace (",", ".", $f_jb_eks);
$f_rgnrlief = removeFieldSigns($f_rgnrlief);
$f_rgnrev = removeFieldSigns($f_rgnrev);
$f_paymenttype = removeFieldSigns($f_paymenttype);
$f_paymenttype = $paymentTypeMappingArray[$f_paymenttype]; // Mapping payment type for delivery
$f_rgnrliefdatum = removeFieldSigns($f_rgnrliefdatum);
$f_rgnrliefdatum = substr($f_rgnrliefdatum, 6,4) . "-" . substr($f_rgnrliefdatum, 3,2) . "-" . substr($f_rgnrliefdatum, 6,4) . " 10:00:00";
$f_rgnrevdatum = removeFieldSigns($f_rgnrevdatum);
$f_rgnrevdatum = substr($f_rgnrevdatum, 6,4) . "-" . substr($f_rgnrevdatum, 3,2) . "-" . substr($f_rgnrevdatum, 0,2) . " 10:00:00";
if ($f_rgnrevdatum == "-- 10:00:00")
$f_rgnrevdatum = date("Y-m-d") . " 10:00:00";
$f_montpreisikea = removeFieldSigns($f_montpreisikea);
$f_montpreisikea = str_replace (",", ".", $f_montpreisikea);
$f_montpreisht = removeFieldSigns($f_montpreisht);
$f_montpreisht = str_replace (",", ".", $f_montpreisht);
$f_zmontpreisht = removeFieldSigns($f_zmontpreisht);
$f_zmontpreisht = str_replace (",", ".", $f_zmontpreisht);
$f_rgnrmont = removeFieldSigns($f_rgnrmont);
$f_rgnrmontdatum = removeFieldSigns($f_rgnrmontdatum);
$f_kuechepreisht = removeFieldSigns($f_kuechepreisht);
$f_kuechepreisht = str_replace (",", ".", $f_kuechepreisht);
$f_wasserpreisht = removeFieldSigns($f_wasserpreisht);
$f_wasserpreisht = str_replace (",", ".", $f_wasserpreisht);
$f_elektropreisht = removeFieldSigns($f_elektropreisht);
$f_elektropreisht = str_replace (",", ".", $f_elektropreisht);
$f_lfdmeter = removeFieldSigns($f_lfdmeter);
$f_lfdmeter = str_replace (",", ".", $f_lfdmeter);
$f_kuechepreisikea = removeFieldSigns($f_kuechepreisikea);
$f_kuechepreisikea = str_replace (",", ".", $f_kuechepreisikea);
$f_preisev = removeFieldSigns($f_preisev);
$f_preisev = str_replace (",", ".", $f_preisev);
$f_preisunt = removeFieldSigns($f_preisunt);
$f_preisunt = str_replace (",", ".", $f_preisunt);
$f_rueckvergikea = removeFieldSigns($f_rueckvergikea);
$f_rueckvergikea = str_replace (",", ".", $f_rueckvergikea);
$f_rueckvergunt = removeFieldSigns($f_rueckvergunt);
$f_rueckvergunt = str_replace (",", ".", $f_rueckvergunt);
// Insert new article
if ($fire && $executeImportProcess == "1") :
TA("B");
if ($remJbId != $f_jb_id) :
if ($remJbId != ""):
if ($f_anzahlpf > 0):
$sum_totalpriceL = $sum_totalpriceM = 0;
endif;
$cr_prov = 0;
$cr_prov_child = 0;
$csc_id_related = getFieldValueFromId("job", "jb_id", $remJbId, "csc_id_related");
$csId = getFieldValueFromId("costcenter", "csc_id", $csc_id_related, "cs_id");
$cr_provArr = array_filter(explode(",", getParameterValue("0", "CR_PROV_" . $csId, "0")));
if (count($cr_provArr) == 3):
$cr_prov = $cr_provArr[$prov_idx] / 100;
$cr_prov_child = $cr_provArr[$prov_idx_child] / 100;
endif;
/* if ($jbIdChild == ""):
updateStmt("job", "jb_id", $remJbId, array("jb_totalprice", ($sum_totalpriceL+$sum_totalpriceM), "jb_cr_price", ($sum_cr_priceL+$sum_cr_priceM) * (1 - $cr_prov), "jb_cr_subprice", ($sum_cr_priceL+$sum_cr_priceM)));
deleteStmt("jobprice", "jb_id = " . $remJbId . " AND mt_sort = 6");
insertStmt("jobprice", array("jb_id", $remJbId, "mt_sort", 6, "jbprc_price", ($sum_cr_priceL+$sum_cr_priceM), "jbprc_remark", "Gesamt"));
insertStmt("jobprice", array("jb_id", $remJbId, "mt_sort", 7, "jbprc_price", ($sum_cr_priceL+$sum_cr_priceM) * (1 - $cr_prov), "jbprc_remark", "Gesamt"));
else:
updateStmt("job", "jb_id", $remJbId, array("jb_totalprice", $sum_totalpriceL, "jb_cr_price", $sum_cr_priceL * (1 - $cr_prov), "jb_cr_subprice", $sum_cr_priceL));
deleteStmt("jobprice", "jb_id = " . $remJbId . " AND mt_sort = 6");
insertStmt("jobprice", array("jb_id", $remJbId, "mt_sort", 6, "jbprc_price", $sum_cr_priceL, "jbprc_remark", "Gesamt"));
insertStmt("jobprice", array("jb_id", $remJbId, "mt_sort", 7, "jbprc_price", $sum_cr_priceL * (1 - $cr_prov), "jbprc_remark", "Gesamt"));
updateStmt("job", "jb_id", $jbIdChild, array("jb_totalprice", $sum_totalpriceM, "jb_cr_price", $sum_cr_priceM * (1 - $cr_prov_child), "jb_cr_subprice", $sum_cr_priceM));
deleteStmt("jobprice", "jb_id = " . $jbIdChild . " AND mt_sort = 6");
insertStmt("jobprice", array("jb_id", $jbIdChild, "mt_sort", 6, "jbprc_price", $sum_cr_priceM, "jbprc_remark", "Gesamt"));
insertStmt("jobprice", array("jb_id", $jbIdChild, "mt_sort", 7, "jbprc_price", $sum_cr_priceM * (1 - $cr_prov_child), "jbprc_remark", "Gesamt"));
endif;
*/
endif;
$sum_totalpriceL = 0;
$sum_cr_priceL = 0;
$sum_totalpriceM = 0;
$sum_cr_priceM = 0;
$jb_serviceL = 1;
$jb_serviceM = 0;
$jb_timeunitsL = 0;
$jb_timeunitsM = 0;
$prov_idx = 0;
$prov_idx_child = 0;
// Parent job ID
$jbIdChild = getFieldValueFromId("job", "jb_id_parent", $f_jb_id, "jb_id");
// Station 1
// if ($f_voucher != "")
// updateStmt("tour", "jb_id", $f_jb_id, array("tr_commission_no", $f_voucher), "tr_sort = 1 OR (jb_id = '$jb_id_child' AND tr_sort = 1)");
// Station 2
// if ($f_order_id != "")
// updateStmt("tour", "jb_id", $f_jb_id, array("tr_commission_no", $f_order_id), "tr_sort = 2 OR (jb_id = '$jb_id_child' AND tr_sort = 2)");
// Business card no
// if ($f_businesscard_no != "")
// insertStmt("genericdatacontainer", array("gdc_obj_type", "jb", "gdc_obj_id", $f_jb_id, "gdc_gen_fieldname", "jb_business_card", "gdc_content", $f_businesscard_no, "gdc_context", ""));
// if ($jbIdChild != "")
// insertStmt("genericdatacontainer", array("gdc_obj_type", "jb", "gdc_obj_id", $jbIdChild, "gdc_gen_fieldname", "jb_business_card", "gdc_content", $f_businesscard_no, "gdc_context", ""));
// Service job (SAMS)
$isServiceJob = false;
$jbpcSamsFlagArray[$f_rgnrev] = "0";
if (strtoupper($f_service_flag) == "WAHR" || strtoupper($f_service_flag) == "TRUE") :
$isServiceJob = true;
if ($f_rgnrev != "") :
$jbpcSamsFlagArray[$f_rgnrev] = "1";
endif;
endif;
if ($isServiceJob) :
// insertStmt("genericdatacontainer", array("gdc_obj_type", "jb","gdc_obj_id", $f_jb_id, "gdc_gen_fieldname", "jb_service_job","gdc_content", "1", "gdc_context", ""));
// if ($jbIdChild != "")
// insertStmt("genericdatacontainer", array("gdc_obj_type", "jb","gdc_obj_id", $jbIdChild, "gdc_gen_fieldname", "jb_service_job","gdc_content", "1", "gdc_context", ""));
endif;
$remJbId = $f_jb_id;
endif;
if ($f_service_id == 3 || $f_service_id == 4 || $f_service_id == 6 || $f_service_id == 7 || $f_service_id == 8 || $f_service_id == 11):
$jb_serviceM = 18;
$sum_totalpriceM += ($f_preisev / 1.19);
$jb_timeunitsM = 24;
$sum_cr_priceM += (($f_preisunt - $f_rueckvergunt) / 1.19);
elseif (in_array($f_service_id, array(9, 10, 11, 12, 13, 15, 16, 17, 21, 24, 26, 40, 42))):
$jb_serviceM = 6;
$sum_totalpriceM += ($f_preisev / 1.19);
$jb_timeunitsM = 18;
$sum_cr_priceM += (($f_preisunt - $f_rueckvergunt) / 1.19);
elseif ($f_service_id == 29): // Abholung
$jb_serviceL = 128;
$sum_totalpriceL += ($f_preisev / 1.19);
$jb_timeunitsL = 2;
$sum_cr_priceL += (($f_preisunt - $f_rueckvergunt) / 1.19);
elseif ($f_service_id == 30): // Austausch
$jb_serviceL = 256;
$sum_totalpriceL += ($f_preisev / 1.19);
$jb_timeunitsL = 2;
$sum_cr_priceL += (($f_preisunt - $f_rueckvergunt) / 1.19);
else:
$jb_serviceL = 1;
$sum_totalpriceL += ($f_preisev / 1.19);
$jb_timeunitsL = 2;
$sum_cr_priceL += (($f_preisunt - $f_rueckvergunt) / 1.19);
endif;
// Delivery
$jbIdNew = $f_jb_id;
$prov_idx = max(0,$prov_idx);
// $prov_idx_child = max(1,$prov_idx_child);
// Installation
if ($serviceArray[$f_service_id][2]) :
$prov_idx = max(1,$prov_idx);
if ($f_service_id == 3 || $f_service_id == 4 || $f_service_id == 6 || $f_service_id == 7 || $f_service_id == 11):
$prov_idx = max(2,$prov_idx);
$jb_service = 18;
$jb_timeunits = 10;
endif;
if ($jbIdChild != ""):
$jbIdNew = $jbIdChild;
$prov_idx_child = $prov_idx;
$prov_idx = 0;
endif;
endif;
$funcNo = $serviceArray[$f_service_id][5];
if (substr($funcNo, 0, 6) != "ident_"):
$parMtfFuncHeadline = getParameterValue("0", "MTF_FUNC_" . $funcNo . "_MASKNAME", "0");
else:
$parMtfFuncHeadline = getParameterValue("0", "MTF_FUNC_IDENT" . substr($funcNo, -4) . "_MASKNAME", "0");
endif;
// Insert jobcalculator data
// insertStmt("jobcalculator", array("jb_id", $jbIdNew, "tr_sort", "2", "srv_id", "0", "srv_name", $parMtfFuncHeadline, "srvt_id", "0",
// "srvt_name", "$funcNo:par_01", "jbc_amount", "1.00", "jbc_price", ($f_preisev / 1.19), "jbc_totalprice", ($f_preisev / 1.19)));
/*
updateStmt("jobcalculator", "jb_id", $jbIdNew, array("jbc_price", ($f_preisev / 1.19), "jbc_totalprice", ($f_preisev / 1.19)), "srvt_name = '" . $funcNo . ":par_01'");
*/
// mt_sort mt_value mt_mapped_value
// 0 enduser Endverbraucherpreis
// 1 credit_extern Gutschrift extern
// 2 debit_extern Belastung extern
// 3 debit_return Rückvergütung Belastung
// 4 cr_price_gross Fuhrlohn brutto
// 5 cr_price_return Rückvergütung Fuhrlohn
// 6 cr_price_net Fuhrlohn netto
// 7 cr_price_prov Fuhrlohn nach Provision
// Preis EV (aus calculator holen?)
// insertStmt("jobprice", array("jb_id", $jbIdNew, "mt_sort", 0, "jbprc_price", ($f_preisev / 1.19), "jbprc_remark", $parMtfFuncHeadline));
/*
updateStmt("jobprice", "jb_id", $jbIdNew, array("jbprc_price", ($f_preisev / 1.19)), "mt_sort = 0 AND jbprc_remark = '" . $parMtfFuncHeadline . "'");
*/
// Summate for jbpc
if ($f_rgnrev != "") :
if ($jbpcArray[$f_rgnrev] == "") :
$jbpcArray[$f_rgnrev] = 0;
endif;
if ($f_preisev != "") :
$jbpcArray[$f_rgnrev] += ($f_preisev / 1.19);
endif;
$jbpc_modeArray[$f_rgnrev] = $f_paymenttype;
endif;
/*
// credit_extern
// insertStmt("jobprice", array("jb_id", $jbIdNew, "mt_sort", 1, "jbprc_price", ($f_preisikea / 1.19), "jbprc_remark", $parMtfFuncHeadline, "jbprc_reference", ($f_rgnrgutikea != "" ? $f_rgnrgutikea : 0)));
updateStmt("jobprice", "jb_id", $jbIdNew, array("jbprc_price", ($f_preisikea / 1.19)), "mt_sort = 1 AND jbprc_remark = '" . $parMtfFuncHeadline . "'");
// debit_extern
// insertStmt("jobprice", array("jb_id", $jbIdNew, "mt_sort", 2, "jbprc_price", ($f_preisht / 1.19), "jbprc_remark", $parMtfFuncHeadline, "jbprc_reference", ($f_rgnrgutikea != "" ? $f_rgnrgutikea : ($f_rgnrikea != "" ? $f_rgnrikea : 0))));
updateStmt("jobprice", "jb_id", $jbIdNew, array("jbprc_price", ($f_preisht / 1.19)), "mt_sort = 2 AND jbprc_remark = '" . $parMtfFuncHeadline . "'");
// debit_return
// insertStmt("jobprice", array("jb_id", $jbIdNew, "mt_sort", 3, "jbprc_price", ($f_rueckvergikea / 1.19), "jbprc_remark", $parMtfFuncHeadline, "jbprc_reference", ($f_rgnrrueckvergikea != "" ? $f_rgnrrueckvergikea : 0)));
updateStmt("jobprice", "jb_id", $jbIdNew, array("jbprc_price", ($f_rueckvergikea / 1.19)), "mt_sort = 3 AND jbprc_remark = '" . $parMtfFuncHeadline . "'");
// cr_price_return
// insertStmt("jobprice", array("jb_id", $jbIdNew, "mt_sort", 4, "jbprc_price", ($f_preisunt / 1.19), "jbprc_remark", $parMtfFuncHeadline));
updateStmt("jobprice", "jb_id", $jbIdNew, array("jbprc_price", ($f_preisunt / 1.19)), "mt_sort = 4 AND jbprc_remark = '" . $parMtfFuncHeadline . "'");
// insertStmt("jobprice", array("jb_id", $jbIdNew, "mt_sort", 5, "jbprc_price", ($f_rueckvergunt / 1.19), "jbprc_remark", $parMtfFuncHeadline));
updateStmt("jobprice", "jb_id", $jbIdNew, array("jbprc_price", ($f_rueckvergunt / 1.19)), "mt_sort = 5 AND jbprc_remark = '" . $parMtfFuncHeadline . "'");
*/
// Insert jobpayment
$jbpIdNew = "";
$csc_id_related = getFieldValueFromId("job", "jb_id", $jbIdNew, "csc_id_related");
if ($f_rgnrev != "" && is_numeric($f_rgnrev) && ($f_preisev > 0)) :
insertStmt("jobpayment", array("jb_id", $jbIdNew, "tr_sort", "2", "csc_id", $csc_id_related, "jbp_mode", "0", "jbp_price", ($f_preisev / 1.19),
"jbp_counter", "1", "jbpc_id", $f_rgnrev, "jbp_export_time", $f_rgnrevdatum));
// echo "insertStmt(\"jobpayment\", array(\"jb_id\", $jbIdNew, \"tr_sort\", \"2\", \"csc_id\", $csc_id_related, \"jbp_mode\", \"0\", \"jbp_price\", " . ($f_preisev / 1.19) . "," .
"\"jbp_counter\", \"1\", \"jbpc_id\", $f_rgnrev, \"jbp_export_time\", $f_rgnrevdatum));<br>\n";
// $jbpIdNew = getLastInsertId();
elseif($f_preisev > 0) :
updateStmt("job", "jb_id", $jbIdNew, array("jb_incomplete", "1"));
// echo "updateStmt(\"job\", \"jb_id\", $jbIdNew, array(\"jb_incomplete\", \"1\"));<br>\n";
endif;
// if ($isServiceJob) :
// insertStmt("genericdatacontainer", array("gdc_obj_type", "jb","gdc_obj_id", $jbIdNew, "gdc_gen_fieldname", "jb_service_job","gdc_content", "1", "gdc_context", ""));
// endif;
TA("C");
TA("E");
endif;
}
echo "------------------------------ <br>";
print_r($jbpcArray); echo "<br>";
// Insert jbpc for ALL jobs
$jbpcArrayLen = count($jbpcArray);
if ($jbpcArrayLen > 0) :
$tmpKeys = array_keys($jbpcArray);
$tmpKeysLen = count($tmpKeys);
for ($k = 0; $k < $tmpKeysLen; $k++) :
// Set jbpc text
$jbpc_text = "Wir berechnen Ihnen für die durchgeführten Aufträge|bis einschließlich";
if ($jbpcSamsFlagArray[$tmpKeys[$k]] == "1") :
// SAMS
$jbpc_text = "Wir berechnen Ihnen für die Serviceaufträge|bis einschließlich";
endif;
//echo "jbpcIdNew: " . $tmpKeys[$k] . "<br>";
// insertStmt("jobpaymentcollection", array("jbpc_id", $tmpKeys[$k], "cs_id", $csIdRelated, "jbpc_mode", $jbpc_modeArray[$tmpKeys[$k]], "jbpc_price", $jbpcArray[$tmpKeys[$k]], "jbpc_bookingdate", $currentTime,
// "jbpc_export_time", $currentTime, "jbpc_invtext", $jbpc_text));
// echo "insertStmt(\"jobpaymentcollection\", array(\"jbpc_id\", " . $tmpKeys[$k] . ", \"cs_id\", $csIdRelated, \"jbpc_mode\", " . $jbpc_modeArray[$tmpKeys[$k]] . ", \"jbpc_price\", " . $jbpcArray[$tmpKeys[$k]] . ", \"jbpc_bookingdate\", $currentTime," .
"\"jbpc_export_time\", $currentTime, \"jbpc_invtext\", $jbpc_text));<br>\n";
endfor;
endif;
echo "------------------------------ <br>";
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_JOBSERVICE.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,713 @@
<?php
/*=======================================================================
*
* import_JOBS_BY_PRICEMATRIX.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Get special user types from parameter
$specialUserTypeIsLoggedIn = false;
$specialUserType = "";
$specialUserHqId = "";
$specialUserFTPServerList = "";
$specialUserDirSpecialForObjType = "";
$userTypesSpecialArray = getDatatransferSpecialUserData($userType);
if (count($userTypesSpecialArray) > 0) :
$specialUserTypeIsLoggedIn = true;
list($specialUserType, $specialUserHqId, $specialUserFTPServerList, $specialUserObjType, $specialUserObjId, $specialUserDirSpecialForObjType) = $userTypesSpecialArray;
if ($objType == $specialUserObjType && $objId == $specialUserObjType) :
$hqId = $specialUserHqId;
endif;
endif;
// Check for authentication access
$empHasAdminRights = false;
if (!$specialUserTypeIsLoggedIn) :
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csId = "";
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
$csAddress = array();
$adIdFrom = 0;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
// $csAddress = getAddress($csId, "customer");
$csAddress = getAddress($csId, "costcenteraddress");
$adIdFrom = $csAddress["id"];
$trHsnoFrom = $csAddress["hsno"];
if ($trHsnoFrom == "") : $trHsnoFrom = "."; endif;
$trCompFrom = $csAddress["comp"];
if ($trCompFrom == "") : $trCompFrom = "JOBS_BY_PRICEMATRIX"; endif;
$trFloorFrom = "";
// USE FOLLOWING FIX ADDRESS
// $adIdFrom = "220594"; // Invoice address
// $adIdFrom = "125964"; // Pick-up address
// $trHsnoFrom = "4";
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
$pickUpStationFinishedByDefault = true;
// Tourdata array
$jbTourdata = "";
$jbTourdataZipcodeArray = array();
$jbTourdataCityArray = array();
$jbTourdataCountryArray = array();
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
$tourVehicleArray = array();
/*
if ($hqId == "nnn") :
// NL X
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
....
elseif ($hqId == "mmm") :
// NL Y
endif;
*/
/*
BSP.:
TOUR_NO SID EID NAME FIRSTNAME
294501 E501  e8020201  Schmidt   Alexander  0176 62283533
294502 E502  e8020202  Brazinskas  Zilvinas  0152 55904274
294503 E503  e8020203  Orakov   Anton  0152 01985959
294504 E504  e8020204  Isaak   Alexander  0152 53172115
....
$tourCourierArray = array();
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
....
*/
$tourCourierArray = array();
/*
if ($hqId == "nnn") :
// NL X
$tourCourierArray["294590"] = "e8020401"; // stepenka 01
$tourCourierArray["294501"] = "e8020402"; // stepenka 02
$tourCourierArray["294502"] = "e8020403"; // stepenka 03
$tourCourierArray["294503"] = "e8020404"; // stepneka 04
....
elseif ($hqId == "mmm") :
// NL Y
endif;
// SID array (fix!)
$tourSIDArray = array();
if ($hqId == "107") :
// NL X
$tourSIDArray["294590"] = "E355";
$tourSIDArray["294501"] = "E356";
$tourSIDArray["294502"] = "E357";
$tourSIDArray["294503"] = "E358";
....
elseif ($hqId == "110") :
// NL Y
endif;
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
return $aStr;
}
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_JOBS_BY_PRICEMATRIX_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$jbIdNew = 0;
$trSort = 2; // Init for 2nd station equals first delivery !!!!
$tratSort = 1; // Init all serial numbers !!!!
$jobNewArray = array();
$useJbNewArray = false;
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_JOBS_BY_PRICEMATRIX_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
$rowToImport[0] = "f_tour_no"; // A : Tournr. / Tourbezeichnung
$rowToImport[1] = "f_shipment_mode"; // B : Lieferung/Abholung
$rowToImport[2] = "f_tr_orderdate"; // C : Ausführungsdatum / Ausführungszeitstempel
$rowToImport[3] = "f_tr_warningdate"; // D : Zustellungsdatum
$rowToImport[4] = "f_tr_starttime"; // E : Zustellung von
$rowToImport[5] = "f_tr_endtime"; // F : Zustellung bis
$rowToImport[6] = "f_tr_commission_no"; // G : Lieferscheinnummer
$rowToImport[7] = "f_order_id"; // H : Kundenauftragsnummer
$rowToImport[8] = "f_cs_id_external"; // I : Kundennummer extern / Lieferantennummer
$rowToImport[9] = "f_cs_eid"; // J : Kundenummer (EID,intern)
$rowToImport[10] = "f_tr_comp"; // K : Firma
$rowToImport[11] = "f_tr_comp2"; // L : Firma Zusatz
$rowToImport[12] = "f_special_01"; // M : Besteller
$rowToImport[13] = "f_ad_street"; // N : Straße
$rowToImport[14] = "f_tr_hsno"; // O : Hausnummer
$rowToImport[15] = "f_tr_floor"; // P : Etage
$rowToImport[16] = "f_ad_zipcode"; // Q : PLZ
$rowToImport[17] = "f_ad_city"; // R : Ort
$rowToImport[18] = "f_ad_country"; // S : Land
$rowToImport[19] = "f_ad_supplement_1"; // T : Adresszusatz I
$rowToImport[20] = "f_ad_supplement_2"; // U : Adresszusatz II
$rowToImport[21] = "f_tr_person"; // V : Ansprechpartner
$rowToImport[22] = "f_tr_phone"; // W : Telefon
$rowToImport[23] = "f_special_02"; // X : Mobiltelefonnummer
$rowToImport[24] = "f_special_03"; // Y : Emailadresse
$rowToImport[25] = "f_tr_remark"; // Z : Bemerkung / Zustellinfo
$rowToImport[26] = "f_id"; // AA: Sendungsidentifikationsnummer
$rowToImport[27] = "f_trat_packingpieces"; // AB: Packstücke
$rowToImport[28] = "f_trat_palets"; // AC: Paletten
$rowToImport[29] = "f_trat_weight"; // AD: Gewicht
$rowToImport[30] = "f_special_04"; // AE: Stellplätze
$rowToImport[31] = "f_special_05"; // AF: Warenart
$rowToImport[32] = "f_zone_no"; // AG: Zone
$rowToImport[33] = "f_special_06"; // AH: Inkasso/Rückführung
$rowToImport[34] = "f_price_type"; // AI: Preistyp
$rowToImport[35] = "f_service_type"; // AJ: Leistungstyp
$rowToImport[36] = "f_dummy_01"; // AK: DUMMY_01
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_tour_no = mcStrWrap($f_tour_no); // Tournr. / Tourbezeichnung
$f_shipment_mode = mcStrWrap($f_shipment_mode); // Lieferung/Abholung
$f_tr_ware_from_to = 0;
if ($f_shipment_mode == "R") :
$f_tr_ware_from_to = 1;
elseif ($f_shipment_mode == "L") :
$f_tr_ware_from_to = 2;
endif;
$f_tr_orderdate = mcStrWrap($f_tr_orderdate); // Ausführungsdatum / Ausführungszeitstempel
$f_tr_warningdate = mcStrWrap($f_tr_warningdate); // Zustellungsdatum
$f_tr_starttime = mcStrWrap($f_tr_starttime); // Zustellung von
$f_tr_endtime = mcStrWrap($f_tr_endtime); // Zustellung bis
$f_tr_commission_no = mcStrWrap($f_tr_commission_no); // Lieferscheinnummer
$f_order_id = mcStrWrap($f_order_id); // Kundenauftragsnummer
$f_cs_id_external = mcStrWrap($f_cs_id_external); // Kundennummer extern / Lieferantennummer
$f_cs_eid = mcStrWrap($f_cs_eid); // Kundenummer (votian)
$f_tr_comp = mcStrWrap($f_tr_comp); // Firma
$f_tr_comp2 = mcStrWrap($f_tr_comp2); // Firma Zusatz
$f_special_01 = mcStrWrap($f_special_01); // Besteller
$f_ad_street = mcStrWrap($f_ad_street); // Straße
$f_tr_hsno = mcStrWrap($f_tr_hsno); // Hausnummer
if ($f_tr_hsno == "") : $f_tr_hsno = "."; endif;
$f_tr_floor = mcStrWrap($f_tr_floor); // Etage
$f_ad_zipcode = mcStrWrap($f_ad_zipcode); // PLZ
$f_ad_city = mcStrWrap($f_ad_city); // Ort
$f_ad_country = mcStrWrap($f_ad_country); // Land
if ($f_ad_country == "" || $f_ad_country == "D") : $f_ad_country = "DE"; endif;
$f_ad_supplement_1 = mcStrWrap($f_ad_supplement_1); // Adresszusatz I
$f_ad_supplement_2 = mcStrWrap($f_ad_supplement_2); // Adresszusatz II
$f_tr_person = mcStrWrap($f_tr_person); // Ansprechpartner
$f_tr_phone = mcStrWrap($f_tr_phone); // Telefon
$f_special_02 = mcStrWrap($f_special_02); // Mobiltelefonnummer
$f_special_03 = mcStrWrap($f_special_03); // Emailadresse
$f_tr_remark = mcStrWrap($f_tr_remark); // Bemerkung / Zustellinfo
$f_id = mcStrWrap($f_id); // Sendungsidentifikationsnummer
$f_trat_packingpieces = mcStrWrap($f_trat_packingpieces); // Packstücke
$f_trat_palets = mcStrWrap($f_trat_palets); // Paletten
$f_trat_weight = mcStrWrap($f_trat_weight); // Gewicht
$f_trat_weight = str_replace (",", ".", $f_trat_weight);
$f_special_04 = mcStrWrap($f_special_04); // Stellplätze
$f_special_05 = mcStrWrap($f_special_05); // Warenart
$f_zone_no = mcStrWrap($f_zone_no); // Zone
$f_special_06 = mcStrWrap($f_special_06); // Inkasso/Rückführung
$f_price_type = mcStrWrap($f_price_type); // Preistyp
$f_service_type = mcStrWrap($f_service_type); // Leistungstyp
$f_dummy_01 = mcStrWrap($f_dummy_01);
if ($f_special_01 != "") : $f_tr_remark .= "\n<br>" . getLngt("Besteller") . ": " . $f_special_01; endif;
if ($f_special_02 != "") : $f_tr_remark .= "\n<br>" . getLngt("Mobiltelefonnummer") . ": " . $f_special_02; endif;
if ($f_special_03 != "") : $f_tr_remark .= "\n<br>" . getLngt("Emailadresse") . ": " . $f_special_03; endif;
if ($f_id != "") : $f_tr_remark .= "\n<br>" . getLngt("Sendungs-ID") . ": " . $f_id; endif;
if ($f_trat_packingpieces != "") : $f_tr_remark .= "\n<br>" . getLngt("Packstücke") . ": " . $f_trat_packingpieces; endif;
if ($f_trat_palets != "") : $f_tr_remark .= "\n<br>" . getLngt("Paletten") . ": " . $f_trat_palets; endif;
if ($f_trat_weight != "") : $f_tr_remark .= "\n<br>" . getLngt("Gewicht") . ": " . $f_trat_weight; endif;
if ($f_special_04 != "") : $f_tr_remark .= "\n<br>" . getLngt("Stellplätze") . ": " . $f_special_04; endif;
if ($f_special_05 != "") : $f_tr_remark .= "\n<br>" . getLngt("Warenart") . ": " . $f_special_05; endif;
if ($f_zone_no != "") : $f_tr_remark .= "\n<br>" . getLngt("Zone") . ": " . $f_zone_no; endif;
if ($f_special_06 != "") : $f_tr_remark .= "\n<br>" . getLngt("Inkasso/Rückführung") . ": " . $f_special_06; endif;
if ($f_price_type != "") : $f_tr_remark .= "\n<br>" . getLngt("Preistyp") . ": " . $f_price_type; endif;
if ($f_service_type != "") : $f_tr_remark .= "\n<br>" . getLngt("Leistungstyp") . ": " . $f_service_type; endif;
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_tour_no];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
*/
$crEid = $tourCourierArray[$f_tour_no];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
$crSid = $tourSIDArray[$f_tour_no];
endif;
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
// $jbStatus = "1"; // jb_status will be set after the whole job is generated
$jbTaketime = $currentTime;
$useJbNewArray = true;
endif;
$jbType = "";
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo $f_id . ";" . $f_tour_no . ";" . $f_shipment_mode . ";" . $f_jb_orderdate . ";" . $f_jb_warningdate . ";" . $f_jb_starttime . ";" . $f_jb_endtime . ";";
echo $f_tr_commission_no . ";" . $f_order_id . ";" . $f_cs_id_external . ";" . $f_cs_eid . ";" . $f_tr_comp . ";" . $f_tr_comp2 . ";" . $f_special_01 . ";";
echo $f_tr_remark . ";" . $f_ad_street . ";" . $f_tr_hsno . ";" . $f_tr_floor . ";" . $f_ad_zipcode . ";" . $f_ad_city . ";" . ";" . $f_ad_country;
echo $f_ad_supplement_1 . ";" . $f_ad_supplement_2 . ";" . $f_tr_person . ";" . $f_tr_phone . ";" . $f_special_02 . ";" . $f_special_03 . ";" . ";" . $f_tr_remark;
echo $f_trat_packingpieces . ";" . $f_trat_palets . ";" . $f_trat_weight . ";" . $f_special_04 . ";" . $f_special_05 . ";";
echo $f_zone_no . ";" . $f_special_06 . ";" . $f_price_type . ";" . $f_service_type . ";";
echo "<br>";
echo "----------------------------------------------------------------------------------------------------------------------------------------------<br>";
// Check for existence of the imported order number (for the same day ONLY)
$gdcEntryExists = false;
// if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","info_2","gdc_content",$f_tr_commission_no,"gdc_context","JOBS_BY_PRICEMATRIX"))) :
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_tr_commission_no . "_" . $currentDate,"gdc_context","JOBS_BY_PRICEMATRIX"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if JOBS_BY_PRICEMATRIX number does exist on the current day!!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$callInsertAddress = true;
if ($f_cs_eid != "") :
$csEndId = getFieldValueFromId("customer","cs_eid",$f_cs_eid,"cs_id");
if ($csEndId != "") :
$csEndAddress = getAddress($csEndId, "costcenteraddress");
$adIdCsEnd = $csEndAddress["id"];
if ($adIdCsEnd != "") :
$callInsertAddress = false;
endif;
$f_ad_street = $csEndAddress["street"];
$f_tr_hsno = $csEndAddress["hsno"];
$f_ad_zipcode = $csEndAddress["zipcode"];
$f_ad_city = $csEndAddress["city"];
$f_ad_country = $csEndAddress["country"];
if ($f_ad_country == "") :
$f_ad_country = "DE";
endif;
endif;
endif;
$noValidationOfAddress = true;
// Insert address
if ($callInsertAddress) :
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
endif;
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_tour_no) :
$jbIdNew = "";
// Start datetime
if ($f_tr_starttime == "") : $f_tr_starttime = "08:00"; endif;
$f_jb_ordertime = substr($f_tr_orderdate, 0,4) . "-" . substr($f_tr_orderdate, 4,2) . "-" . substr($f_tr_orderdate, 6,2) . " " . $f_tr_starttime . ":00";
// End datetime
$f_jb_warningtime = "";
if ($f_tr_endtime == "") : $f_tr_endtime = "18:00"; endif;
/*
if ($f_jb_warningdate != "") :
$f_jb_warningtime = substr($f_tr_warningdate, 0,4) . "-" . substr($f_tr_warningdate, 4,2) . "-" . substr($f_tr_warningdate, 6,2);
if ($f_tr_warningdate != "") :
$f_jb_warningtime .= " " . $f_tr_endtime . ":00";
endif;
endif;
*/
// Remove existing tourname
updateStmt("job","jb_tourname",$f_tour_no,array("jb_tourname",""), "jb_tourname = '" . $f_tour_no . "'");
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_tour_no,
"jb_finishtime", $jbFinishtime, "jb_warningtime", $f_jb_warningtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbIdNew = getLastInsertId();
$jobNewArray[] = $jbIdNew;
// Tour-Nr. "$f_tour_no"
insertStmt("genericdatacontainer", array("gdc_obj_type", "jb", "gdc_obj_id", $jbIdNew, "gdc_gen_fieldname", "tourname", "gdc_content", $f_tour_no, "gdc_context", "JOBS_BY_PRICEMATRIX"));
$trSort = 2; // Init for 2nd station equals first delivery !!!!
$tratSort = 1; // Init all serial numbers !!!!
$remTourNo = $f_tour_no;
endif;
// Check for inserted job
if ($jbIdNew != "") :
// Insert stations
if ($trSort == 2) :
$trStatus = "0";
$trFinishtime = "";
if ($pickUpStationFinishedByDefault) :
$trStatus = "1";
$trFinishtime = $currentTime;
endif;
// Insert pick up station during first iteration
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $adIdFrom, "tr_sort", "1", "tr_comp", $trCompFrom, "tr_comp2", "",
"tr_hsno", $trHsnoFrom, "tr_floor", $trFloorFrom, "csc_id", $cscIdPayer, "tr_status", $trStatus, "tr_finishtime", $trFinishtime,
"tr_commission_no", "", "tr_ware_from_to", $f_tr_ware_from_to,
"tr_person", "", "tr_phone", "", "tr_remark", ""));
$trIdPickUpNew = getLastInsertID();
// Init array für jb_tourdata
$jbTourdataZipcodeArray[$jbIdNew][] = $csAddress["zipcode"];
$jbTourdataCityArray[$jbIdNew][] = $csAddress["city"];
$jbTourdataCountryArray[$jbIdNew][] = $csAddress["country"];
endif;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "tr_floor", $f_tr_floor, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
$jbTourdataZipcodeArray[$jbIdNew][] = $f_ad_zipcode;
$jbTourdataCityArray[$jbIdNew][] = $f_ad_city;
$jbTourdataCountryArray[$jbIdNew][] = $f_ad_country;
// Insert tourservice data
// !!!! MIT tr_id !!!! insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// ****
// Special patch because of "bug" in function "mk_jb_invtext()"
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// ****
// Fremdauftragsnummer "$f_order_id"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_0", "gdc_content", $f_order_id, "gdc_context", "JOBS_BY_PRICEMATRIX"));
// Kundennummer "$f_cs_id_external"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_1", "gdc_content", $f_cs_id_external, "gdc_context", "JOBS_BY_PRICEMATRIX"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_cust_no", "gdc_content", $f_cs_id_external, "gdc_context", "JOBS_BY_PRICEMATRIX"));
// Lieferscheinnummer "$f_tr_commission_no"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_2", "gdc_content", $f_tr_commission_no, "gdc_context", "JOBS_BY_PRICEMATRIX"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_tr_commission_no . "_" . $currentDate, "gdc_context", "JOBS_BY_PRICEMATRIX"));
// Insert tourarticle data (delivery stations)
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
$trSort++;
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_order_id . "]<br>";
endif;
}
// Set generated jobs to status "taken"
$jobNewArrayLen = count($jobNewArray);
if ($jobNewArrayLen > 0) :
for ($i = 0; $i < $jobNewArrayLen; $i++) :
// jb_status
// updateStmt("job", "jb_id", $jobNewArray[$i], array("jb_status", "1"));
// jb_tourdata
$jbTourdata = implode(";", $jbTourdataZipcodeArray[$jobNewArray[$i]]) . "|" . implode(";", $jbTourdataCityArray[$jobNewArray[$i]]) . "|" . implode(";", $jbTourdataCountryArray[$jobNewArray[$i]]);
updateStmt("job", "jb_id", $jobNewArray[$i], array("jb_tourdata", $jbTourdata));
endfor;
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_JOBS_BY_PRICEMATRIX.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,609 @@
<?php
/*=======================================================================
*
* import_KABUCO.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Get special user types from parameter
$specialUserTypeIsLoggedIn = false;
$specialUserType = "";
$specialUserHqId = "";
$specialUserFTPServerList = "";
$specialUserDirSpecialForObjType = "";
$userTypesSpecialArray = getDatatransferSpecialUserData($userType);
if (count($userTypesSpecialArray) > 0) :
$specialUserTypeIsLoggedIn = true;
list($specialUserType, $specialUserHqId, $specialUserFTPServerList, $specialUserObjType, $specialUserObjId, $specialUserDirSpecialForObjType) = $userTypesSpecialArray;
if ($objType == $specialUserObjType && $objId == $specialUserObjType) :
$hqId = $specialUserHqId;
endif;
endif;
// Check for authentication access
$empHasAdminRights = false;
if (!$specialUserTypeIsLoggedIn) :
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// $currentDate = getDateTime(3);
$currentDate = getDateTime("0");
$currentDate = str_replace(" ", "_", substr($currentDate,0,13)); // date and hour
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csId = "";
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
$csAddress = array();
$adIdFrom = 0;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
// $csAddress = getAddress($csId, "customer");
$csAddress = getAddress($csId, "costcenteraddress");
$adIdFrom = $csAddress["id"];
// USE FOLLOWING FIX ADDRESS
// $adIdFrom = "220594"; // Invoice address
// $adIdFrom = "125964"; // Pick-up address
// $trHsnoFrom = "4";
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
$tourVehicleArray = array();
if ($hqId == "107") :
// ESSEN
/*
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
*/
elseif ($hqId == "110") :
// NÜRNBERG
$tourVehicleArray["N401"] = "N401";
$tourVehicleArray["N402"] = "N402";
endif;
$tourCourierArray = array();
if ($hqId == "107") :
// ESSEN
/*
$tourCourierArray["294590"] = "e8021001"; // nostris 01
$tourCourierArray["294501"] = "e8021002"; // nostris 02
*/
elseif ($hqId == "110") :
// NÜRNBERG
$tourCourierArray["N402"] = "n8118302"; // 89882390000008451018 (Account: "Fahrer1")
$tourCourierArray["N401"] = "n8118304"; // 89882390000013359974 (Account: "Fahrer2")
endif;
// SID array (fix!)
$tourSIDArray = array();
if ($hqId == "107") :
// ESSEN
/*
$tourSIDArray["294590"] = "E370"; // 89882390000008452644
$tourSIDArray["294501"] = "E371"; // 89882390000012935618
*/
elseif ($hqId == "110") :
// NÜRNBERG
$tourSIDArray["N401"] = "N401";
$tourSIDArray["N402"] = "N402";
endif;
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
return $aStr;
}
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_KABUCO_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$jbIdNew = 0;
$trSort = 2; // Init for 2nd station equals first delivery !!!!
$tratSort = 1; // Init all serial numbers !!!!
$jobNewArray = array();
$useJbNewArray = false;
$rowToImport = array();
$searchValueArray = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_KABUCO_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
/*
Tour Lieferung/Rückholung Bearbeitungsdatum Lieferscheinnummer Auftragsnummer Warenempfänger Name Ansprechpartner Auslieferangaben Straße,Hausnr. Länderkürzel Postleitszahl Ort ? Packstücke Paletten Gewicht Besteller Kundenbestellnummer Sendungsidentifikationsnummer ? ? ? ? ? ? ? ? ? Lieferdatum ? 2
299050 D 20141203 1039740933 38061862 100755403 AUDI AG Markus Dilger T06-Ingols,UG,G004 Ettinger Str. / Südstraße DE 85049 INGOLSTADT ? 1 0 0 MARKUS DILGER 5701829128 869 ? ? ? ? ? ? ? ? ? 20141202 ? 2
*/
$rowToImport[0] = "f_tour_no"; // A : Tour
$rowToImport[1] = "f_shipment_mode"; // B : Lieferung/Rückholung
$rowToImport[2] = "f_jb_orderdate"; // C : Bearbeitungsdatum (Ausführungsdatum)
$rowToImport[3] = "f_tr_commission_no"; // D : Lieferscheinnummer
$rowToImport[4] = "f_order_id"; // E : Fremdauftragsnummer
$rowToImport[5] = "f_customer_id"; // F : Warenempfänger (spezielle Kundennummer)
$rowToImport[6] = "f_tr_comp"; // G : Firma Anlieferung
$rowToImport[7] = "f_tr_cs_freetext"; // H : Ansprechpartner (Person Anlieferung / Bemerkung)
$rowToImport[8] = "f_tr_comp2"; // I : Auslieferangaben (Firma2 Anlieferung)
$rowToImport[9] = "f_ad_street_hsno"; // J : Adresse.Straße_Hausnummer
$rowToImport[10] = "f_ad_country"; // K : Adresse.Land
$rowToImport[11] = "f_ad_zipcode"; // L : Adresse.PLZ
$rowToImport[12] = "f_ad_city"; // M : Adresse.Ort
$rowToImport[13] = "f_dummy_01"; // N : ?
$rowToImport[14] = "f_trat_packingpieces"; // O : Packstücke
$rowToImport[15] = "f_trat_palets"; // P : Paletten
$rowToImport[16] = "f_trat_weight"; // Q : Gewicht
$rowToImport[17] = "f_tr_person"; // R : Ansprechpartner
$rowToImport[18] = "f_tr_remark2"; // S : Kundenbestellnummer (Bemerkung)
$rowToImport[19] = "f_tr_remark3"; // T : Sendungsidentifikationsnummer (Bemerkung)
$rowToImport[20] = "f_dummy_04"; // U : ?
$rowToImport[21] = "f_dummy_05"; // V : ?
$rowToImport[22] = "f_tr_remark4"; // W : Bemerkung (4.) [Anlieferbemerkung]
$rowToImport[23] = "f_dummy_06"; // X : ?
$rowToImport[24] = "f_tr_phone"; // Y : Telefon
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_tour_no = mcStrWrap($f_tour_no);
$f_shipment_mode = mcStrWrap($f_shipment_mode);
$f_jb_orderdate = mcStrWrap($f_jb_orderdate);
$f_jb_ordertime = substr($f_jb_orderdate, 0,4) . "-" . substr($f_jb_orderdate, 4,2) . "-" . substr($f_jb_orderdate, 6,2) . " 06:00:00";
$f_tr_commission_no = mcStrWrap($f_tr_commission_no);
$f_tr_commission_no = substr($f_tr_commission_no,0,7);
$f_order_id = mcStrWrap($f_order_id);
$f_customer_id = mcStrWrap($f_customer_id);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_tr_comp2 = mcStrWrap($f_tr_comp2);
$f_tr_cs_freetext = mcStrWrap($f_tr_cs_freetext);
// $f_tr_remark = mcStrWrap($f_tr_remark);
$f_tr_remark = ""; // Init
$f_ad_street_hsno = mcStrWrap($f_ad_street_hsno);
$f_ad_country = mcStrWrap($f_ad_country);
if ($f_ad_country == "" || $f_ad_country == "D") : $f_ad_country = "DE"; endif;
$f_ad_zipcode = mcStrWrap($f_ad_zipcode);
$f_ad_city = mcStrWrap($f_ad_city);
$f_tr_phone = mcStrWrap($f_tr_phone);
$f_dummy_01 = mcStrWrap($f_dummy_01);
$f_trat_packingpieces = mcStrWrap($f_trat_packingpieces);
$f_trat_palets = mcStrWrap($f_trat_palets);
$f_trat_weight = mcStrWrap($f_trat_weight);
$f_trat_weight = str_replace (",", ".", $f_trat_weight);
$f_tr_person = mcStrWrap($f_tr_person);
$f_tr_remark2 = mcStrWrap($f_tr_remark2);
$f_tr_remark3 = mcStrWrap($f_tr_remark3);
$f_dummy_04 = mcStrWrap($f_dummy_04);
$f_dummy_05 = mcStrWrap($f_dummy_05);
$f_dummy_06 = mcStrWrap($f_dummy_06);
$f_tr_remark4 = mcStrWrap($f_tr_remark4);
// $f_jb_totalprice = str_replace (",", ".", $f_jb_totalprice);
if ($f_tr_remark2 != "") : $f_tr_remark .= " | Kundenbestellnummer: " . $f_tr_remark2; endif;
if ($f_tr_remark3 != "") : $f_tr_remark .= " | Sendungsidentifikationsnummer: " . $f_tr_remark3; endif;
// if ($f_tr_remark4 != "") : $f_tr_remark .= " | " . $f_tr_remark4; endif;
$f_trat_remark = $f_trat_palets;
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_tour_no];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
*/
$crEid = $tourCourierArray[$f_tour_no];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
$crSid = $tourSIDArray[$f_tour_no];
endif;
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
// $jbStatus = "1"; // jb_status will be set after the whole job is generated
$jbTaketime = $currentTime;
$useJbNewArray = true;
endif;
$jbType = "2";
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo $f_tour_no . ";" . $f_shipment_mode . ";" . $f_jb_orderdate . ";" . $f_tr_commission_no . ";" . $f_order_id . ";" . $f_customer_id . ";";
echo $f_tr_comp . ";" . $f_tr_comp2 . ";" . $f_tr_remark . ";" . $f_ad_street_hsno . ";" . $f_ad_country . ";" . $f_ad_zipcode . ";";
echo $f_ad_city . ";" . $f_tr_phone . ";" . $f_tr_person . ";" . $f_tr_remark2 . ";" . $f_tr_remark3 . ";" . $f_tr_remark4 . ";";
echo "<br>";
// Check for existence of the imported order number (for the same day ONLY)
$gdcEntryExists = false;
// if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","info_2","gdc_content",$f_tr_commission_no,"gdc_context","KABUCO"))) :
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_tr_commission_no . "_" . $currentDate,"gdc_context","KABUCO"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if KABUCO number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = true;
$jbTourdataZipcode = $csAddress["zipcode"] . ";" . $f_ad_zipcode;
$jbTourdataCity = $csAddress["city"] . ";" . $f_ad_city;
$jbTourdataCountry = "DE;DE";
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
// Insert address
$tmpArray = insertAddress($f_ad_street_hsno, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_tour_no) :
$jbIdNew = "";
// Remove existing tourname
updateStmt("job","jb_tourname",$f_tour_no,array("jb_tourname",""), "jb_tourname = '" . $f_tour_no . "'");
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_tour_no,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbIdNew = getLastInsertId();
$jobNewArray[] = $jbIdNew;
$trSort = 2; // Init for 2nd station equals first delivery !!!!
$tratSort = 1; // Init all serial numbers !!!!
$remTourNo = $f_tour_no;
endif;
// Check for inserted job
if ($jbIdNew != "") :
// Insert stations
if ($trSort == 2) :
$trStatus = "0";
$trFinishtime = "";
if ($pickUpStationFinishedByDefault) :
$trStatus = "1";
$trFinishtime = $currentTime;
endif;
// Insert pick up station during first iteration
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $adIdFrom, "tr_sort", "1", "tr_comp", "KABUCO", "tr_comp2", "",
"tr_hsno", $trHsnoFrom, "tr_floor", $f_ad_floor, "csc_id", $cscIdPayer, "tr_status", $trStatus, "tr_finishtime", $trFinishtime,
"tr_commission_no", "", "tr_ware_from_to", "",
"tr_person", "", "tr_phone", "", "tr_remark", ""));
$trIdPickUpNew = getLastInsertID();
endif;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", ".", "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
$searchValueArray[$jbIdNew][] = $f_tr_commission_no;
// Insert tourservice data
// !!!! MIT tr_id !!!! insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// ****
// Special patch because of "bug" in function "mk_jb_invtext()"
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// ****
// Fremdauftragsnummer "$f_order_id"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_0", "gdc_content", $f_order_id, "gdc_context", "KABUCO"));
// Kundennummer "$f_customer_id"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_1", "gdc_content", $f_customer_id, "gdc_context", "KABUCO"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_cust_no", "gdc_content", $f_customer_id, "gdc_context", "KABUCO"));
// Lieferscheinnummer "$f_tr_commission_no"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_2", "gdc_content", $f_tr_commission_no, "gdc_context", "KABUCO"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_tr_commission_no . "_" . $currentDate, "gdc_context", "KABUCO"));
// Sendungsnummer "f_tr_remark3"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_3", "gdc_content", $f_tr_remark3, "gdc_context", "KABUCO"));
// Insert tourarticle data (delivery stations)
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
$trSort++;
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_order_id . "]<br>";
endif;
}
// Set generated jobs to status "taken"
$jobNewArrayLen = count($jobNewArray);
if ($jobNewArrayLen > 0) :
for ($i = 0; $i < $jobNewArrayLen; $i++) :
// Insert special search informations into GDC
$searchVal = "," . implode(",",$searchValueArray[$jobNewArray[$i]]) . ",";
insertStmt("genericdatacontainer", array("gdc_obj_type", "jb", "gdc_obj_id", $jobNewArray[$i], "gdc_gen_fieldname", "search", "gdc_content", $searchVal, "gdc_context", "KABUCO"));
// Update status
updateStmt("job", "jb_id", $jobNewArray[$i], array("jb_status", "1"));
endfor;
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_KABUCO.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,687 @@
<?php
/*=======================================================================
*
* import_LYRECO.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Get special user types from parameter
$specialUserTypeIsLoggedIn = false;
$specialUserType = "";
$specialUserHqId = "";
$specialUserFTPServerList = "";
$specialUserDirSpecialForObjType = "";
$userTypesSpecialArray = getDatatransferSpecialUserData($userType);
if (count($userTypesSpecialArray) > 0) :
$specialUserTypeIsLoggedIn = true;
list($specialUserType, $specialUserHqId, $specialUserFTPServerList, $specialUserObjType, $specialUserObjId, $specialUserDirSpecialForObjType) = $userTypesSpecialArray;
if ($objType == $specialUserObjType && $objId == $specialUserObjType) :
$hqId = $specialUserHqId;
endif;
endif;
// Check for authentication access
$empHasAdminRights = false;
if (!$specialUserTypeIsLoggedIn) :
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csId = "";
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
$csAddress = array();
$adIdFrom = 0;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
// $csAddress = getAddress($csId, "customer");
$csAddress = getAddress($csId, "costcenteraddress");
$adIdFrom = $csAddress["id"];
// USE FOLLOWING FIX ADDRESS
// $adIdFrom = "220594"; // Invoice address
// $adIdFrom = "125964"; // Pick-up address
// $trHsnoFrom = "4";
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
$tourVehicleArray = array();
if ($hqId == "107") :
// ESSEN
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
elseif ($hqId == "110") :
// NÜRNBERG
/*
$tourVehicleArray["299001"] = "N156";
$tourVehicleArray["299002"] = "N157";
$tourVehicleArray["299003"] = "N153";
$tourVehicleArray["299004"] = "N154";
$tourVehicleArray["299005"] = "N155";
$tourVehicleArray["299050"] = "N106";
*/
endif;
/*
294501 E501  e8020201  Schmidt  Alexander  0176 62283533
294502 E502  e8020202  Brazinskas  Zilvinas  0152 55904274
294503 E503  e8020203  Orakov  Anton  0152 01985959
294504 E504  e8020204  Isaak  Alexander  0152 53172115
294505 E505  e8020205  Fakhridinov  Dzhamshed  0177 8515225
294506 E506  e8020206  Ehlert  Günter  0171 3179072
294507 E507  e8020207  El Kourouchi  Rachid  0177 8457400
294508 E508  e8020208  Prokhorov  Vladimir  0176 22000601
294509 E509  e8020209  Ulle  Achim  0157 50623924
294510 E510  e8020210  Vogel  Waldemar  0157 87262689
294511 E511  e8020211  Smirnov  Igor  0176 32432192
294512 E512  e8020212  Cetin  Muammer  0172 2704315
294590 E590  e8020213  Chahbari  Majid  0176 47746437
$tourCourierArray = array();
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
$tourCourierArray["294505"] = "e8020205";
$tourCourierArray["294506"] = "e8020206";
$tourCourierArray["294507"] = "e8020207";
$tourCourierArray["294508"] = "e8020208";
$tourCourierArray["294509"] = "e8020209";
$tourCourierArray["294510"] = "e8020210";
$tourCourierArray["294511"] = "e8020211";
$tourCourierArray["294512"] = "e8020212";
$tourCourierArray["294590"] = "e8020213";
// **** NEU SEIT 27.07.2016 ****
stepenka 01  e8020401 E355 294590 nostris 01  e8021001 E370  89882390000008452644
stepenka 02  e8020402 E356 294501 nostris 02  e8021002 E371  89882390000012935618
stepenka 03  e8020403 E357 294502 nostris 03  e8021003 E372  89882390000012935675
stepenka 04  e8020404 E358 294503 nostris 04  e8021004 E373  89882390000012935683
stepenka 05  e8020405 E359 294504 nostris 05  e8021005 E374  89882390000012935709
stepenka 06  e8020406 E360 294505 nostris 06  e8021006 E375  89882390000012935626
stepenka 07  e8020407 E361 294506 nostris 07  e8021007 E376  89882390000008451471
stepenka 08  e8020408 E362 294507 nostris 08  e8021008 E377  89882390000012935584
stepenka 09  e8020409 E363 294508 nostris 09  e8021009 E378  89882390000012935576
stepenka 10  e8020410 E364 294509 nostris 10  e8021010 E379  89882390000012935568
stepenka 11  e8020411 E365 294510 nostris 11  e8021011 E380  89882390000012935550
stepenka 12  e8020412 E366 294511 nostris 12  e8021012 E381  89882390000012935733
stepenka 13  e8020413 E367 294512 nostris 13  e8021013 E382  89882390000008451448
stepenka 14  e8020414 E368 294513 nostris 14  e8021014 E383  89882390000012935634
*/
$tourCourierArray = array();
if ($hqId == "107") :
// ESSEN
$tourCourierArray["294590"] = "e8021001"; // nostris 01
$tourCourierArray["294501"] = "e8021002"; // nostris 02
$tourCourierArray["294502"] = "e8021003"; // nostris 03
$tourCourierArray["294503"] = "e8021004"; // nostris 04
$tourCourierArray["294504"] = "e8021005"; // nostris 05
$tourCourierArray["294505"] = "e8021006"; // nostris 06
$tourCourierArray["294506"] = "e8021007"; // nostris 07
$tourCourierArray["294507"] = "e8021008"; // nostris 08
$tourCourierArray["294508"] = "e8021009"; // nostris 09
$tourCourierArray["294509"] = "e8021010"; // nostris 10
$tourCourierArray["294510"] = "e8021011"; // nostris 11
$tourCourierArray["294511"] = "e8021012"; // nostris 12
$tourCourierArray["294512"] = "e8021013"; // nostris 13
$tourCourierArray["294513"] = "e8021014"; // nostris 14
elseif ($hqId == "110") :
// NÜRNBERG
$tourCourierArray["299001"] = "n8124502"; // Hokamp Benjamin 0157 84862698
$tourCourierArray["299002"] = "n8124503"; // Schulz Michael 0152 53666367
$tourCourierArray["299003"] = "n8124504"; // Möller Rene 0171 5823128
$tourCourierArray["299004"] = "n8124505"; // Kirschner Sascha 0152 53910965
$tourCourierArray["299005"] = "n8124506"; // Schulz Thomas 0176 24177518
$tourCourierArray["299050"] = "n8124507"; // Holler Stefan 0157 35374266
endif;
// SID array (fix!)
$tourSIDArray = array();
if ($hqId == "107") :
// ESSEN
$tourSIDArray["294590"] = "E370"; // 89882390000008452644
$tourSIDArray["294501"] = "E371"; // 89882390000012935618
$tourSIDArray["294502"] = "E372"; // 89882390000012935675
$tourSIDArray["294503"] = "E373"; // 89882390000012935683
$tourSIDArray["294504"] = "E374"; // 89882390000012935709
$tourSIDArray["294505"] = "E375"; // 89882390000012935626
$tourSIDArray["294506"] = "E376"; // 89882390000008451471
$tourSIDArray["294507"] = "E377"; // 89882390000012935584
$tourSIDArray["294508"] = "E378"; // 89882390000012935576
$tourSIDArray["294509"] = "E379"; // 89882390000012935568
$tourSIDArray["294510"] = "E380"; // 89882390000012935550
$tourSIDArray["294511"] = "E381"; // 89882390000012935733
$tourSIDArray["294512"] = "E382"; // 89882390000008451448
$tourSIDArray["294513"] = "E383"; // 89882390000012935634
elseif ($hqId == "110") :
// NÜRNBERG
$tourSIDArray["299001"] = "N156";
$tourSIDArray["299002"] = "N157";
$tourSIDArray["299003"] = "N153";
$tourSIDArray["299004"] = "N154";
$tourSIDArray["299005"] = "N155";
$tourSIDArray["299050"] = "N106";
endif;
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
return $aStr;
}
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_LYRECO_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$jbIdNew = 0;
$trSort = 2; // Init for 2nd station equals first delivery !!!!
$tratSort = 1; // Init all serial numbers !!!!
$jobNewArray = array();
$useJbNewArray = false;
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_LYRECO_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
/*
Tour Lieferung/Rückholung Bearbeitungsdatum Lieferscheinnummer Auftragsnummer Warenempfänger Name Ansprechpartner Auslieferangaben Straße,Hausnr. Länderkürzel Postleitszahl Ort ? Packstücke Paletten Gewicht Besteller Kundenbestellnummer Sendungsidentifikationsnummer ? ? ? ? ? ? ? ? ? Lieferdatum ? 2
299050 D 20141203 1039740933 38061862 100755403 AUDI AG Markus Dilger T06-Ingols,UG,G004 Ettinger Str. / Südstraße DE 85049 INGOLSTADT ? 1 0 0 MARKUS DILGER 5701829128 869 ? ? ? ? ? ? ? ? ? 20141202 ? 2
*/
$rowToImport[0] = "f_tour_no"; // A : Tour
$rowToImport[1] = "f_shipment_mode"; // B : Lieferung/Rückholung
$rowToImport[2] = "f_jb_orderdate"; // C : Bearbeitungsdatum (Ausführungsdatum)
$rowToImport[3] = "f_tr_commission_no"; // D : Lieferscheinnummer
$rowToImport[4] = "f_order_id"; // E : Fremdauftragsnummer
$rowToImport[5] = "f_customer_id"; // F : Warenempfänger (spezielle Kundennummer)
$rowToImport[6] = "f_tr_comp"; // G : Firma Anlieferung
$rowToImport[7] = "f_tr_cs_freetext"; // H : Ansprechpartner (Person Anlieferung / Bemerkung)
$rowToImport[8] = "f_tr_comp2"; // I : Auslieferangaben (Firma2 Anlieferung)
$rowToImport[9] = "f_ad_street_hsno"; // J : Adresse.Straße_Hausnummer
$rowToImport[10] = "f_ad_country"; // K : Adresse.Land
$rowToImport[11] = "f_ad_zipcode"; // L : Adresse.PLZ
$rowToImport[12] = "f_ad_city"; // M : Adresse.Ort
$rowToImport[13] = "f_dummy_01"; // N : ?
$rowToImport[14] = "f_trat_packingpieces"; // O : Packstücke
$rowToImport[15] = "f_trat_palets"; // P : Paletten
$rowToImport[16] = "f_trat_weight"; // Q : Gewicht
$rowToImport[17] = "f_tr_person"; // R : Ansprechpartner
$rowToImport[18] = "f_tr_remark2"; // S : Kundenbestellnummer (Bemerkung)
$rowToImport[19] = "f_tr_remark3"; // T : Sendungsidentifikationsnummer (Bemerkung)
$rowToImport[20] = "f_dummy_04"; // U : ?
$rowToImport[21] = "f_dummy_05"; // V : ?
$rowToImport[22] = "f_tr_remark4"; // W : Bemerkung (4.) [Anlieferbemerkung]
$rowToImport[23] = "f_dummy_06"; // X : ?
$rowToImport[24] = "f_tr_phone"; // Y : Telefon
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_tour_no = mcStrWrap($f_tour_no);
$f_shipment_mode = mcStrWrap($f_shipment_mode);
$f_jb_orderdate = mcStrWrap($f_jb_orderdate);
$f_jb_ordertime = substr($f_jb_orderdate, 0,4) . "-" . substr($f_jb_orderdate, 4,2) . "-" . substr($f_jb_orderdate, 6,2) . " 06:00:00";
$f_tr_commission_no = mcStrWrap($f_tr_commission_no);
$f_order_id = mcStrWrap($f_order_id);
$f_customer_id = mcStrWrap($f_customer_id);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_tr_comp2 = mcStrWrap($f_tr_comp2);
$f_tr_cs_freetext = mcStrWrap($f_tr_cs_freetext);
// $f_tr_remark = mcStrWrap($f_tr_remark);
$f_tr_remark = ""; // Init
$f_ad_street_hsno = mcStrWrap($f_ad_street_hsno);
$f_ad_country = mcStrWrap($f_ad_country);
if ($f_ad_country == "" || $f_ad_country == "D") : $f_ad_country = "DE"; endif;
$f_ad_zipcode = mcStrWrap($f_ad_zipcode);
$f_ad_city = mcStrWrap($f_ad_city);
$f_tr_phone = mcStrWrap($f_tr_phone);
$f_dummy_01 = mcStrWrap($f_dummy_01);
$f_trat_packingpieces = mcStrWrap($f_trat_packingpieces);
$f_trat_palets = mcStrWrap($f_trat_palets);
$f_trat_weight = mcStrWrap($f_trat_weight);
$f_trat_weight = str_replace (",", ".", $f_trat_weight);
$f_tr_person = mcStrWrap($f_tr_person);
$f_tr_remark2 = mcStrWrap($f_tr_remark2);
$f_tr_remark3 = mcStrWrap($f_tr_remark3);
$f_dummy_04 = mcStrWrap($f_dummy_04);
$f_dummy_05 = mcStrWrap($f_dummy_05);
$f_dummy_06 = mcStrWrap($f_dummy_06);
$f_tr_remark4 = mcStrWrap($f_tr_remark4);
// $f_jb_totalprice = str_replace (",", ".", $f_jb_totalprice);
if ($f_tr_remark2 != "") : $f_tr_remark .= " | Kundenbestellnummer: " . $f_tr_remark2; endif;
if ($f_tr_remark3 != "") : $f_tr_remark .= " | Sendungsidentifikationsnummer: " . $f_tr_remark3; endif;
// if ($f_tr_remark4 != "") : $f_tr_remark .= " | " . $f_tr_remark4; endif;
$f_trat_remark = $f_trat_palets;
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_tour_no];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
*/
$crEid = $tourCourierArray[$f_tour_no];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
$crSid = $tourSIDArray[$f_tour_no];
endif;
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
// $jbStatus = "1"; // jb_status will be set after the whole job is generated
$jbTaketime = $currentTime;
$useJbNewArray = true;
endif;
$jbType = "";
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo $f_tour_no . ";" . $f_shipment_mode . ";" . $f_jb_orderdate . ";" . $f_tr_commission_no . ";" . $f_order_id . ";" . $f_customer_id . ";";
echo $f_tr_comp . ";" . $f_tr_comp2 . ";" . $f_tr_remark . ";" . $f_ad_street_hsno . ";" . $f_ad_country . ";" . $f_ad_zipcode . ";";
echo $f_ad_city . ";" . $f_tr_phone . ";" . $f_tr_person . ";" . $f_tr_remark2 . ";" . $f_tr_remark3 . ";" . $f_tr_remark4 . ";";
echo "<br>";
// Check for existence of the imported order number (for the same day ONLY)
$gdcEntryExists = false;
// if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","info_2","gdc_content",$f_tr_commission_no,"gdc_context","LYRECO"))) :
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_tr_commission_no . "_" . $currentDate,"gdc_context","LYRECO"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if LYRECO number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = true;
$jbTourdataZipcode = $csAddress["zipcode"] . ";" . $f_ad_zipcode;
$jbTourdataCity = $csAddress["city"] . ";" . $f_ad_city;
$jbTourdataCountry = "DE;DE";
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
// Insert address
$tmpArray = insertAddress($f_ad_street_hsno, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_tour_no) :
$jbIdNew = "";
// Remove existing tourname
updateStmt("job","jb_tourname",$f_tour_no,array("jb_tourname",""), "jb_tourname = '" . $f_tour_no . "'");
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_tour_no,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbIdNew = getLastInsertId();
$jobNewArray[] = $jbIdNew;
$trSort = 2; // Init for 2nd station equals first delivery !!!!
$tratSort = 1; // Init all serial numbers !!!!
$remTourNo = $f_tour_no;
endif;
// Check for inserted job
if ($jbIdNew != "") :
// Insert stations
if ($trSort == 2) :
$trStatus = "0";
$trFinishtime = "";
if ($pickUpStationFinishedByDefault) :
$trStatus = "1";
$trFinishtime = $currentTime;
endif;
// Insert pick up station during first iteration
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $adIdFrom, "tr_sort", "1", "tr_comp", "Lyreco", "tr_comp2", "",
"tr_hsno", $trHsnoFrom, "tr_floor", $f_ad_floor, "csc_id", $cscIdPayer, "tr_status", $trStatus, "tr_finishtime", $trFinishtime,
"tr_commission_no", "", "tr_ware_from_to", "",
"tr_person", "", "tr_phone", "", "tr_remark", ""));
$trIdPickUpNew = getLastInsertID();
endif;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", "", "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
// Insert tourservice data
// !!!! MIT tr_id !!!! insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// ****
// Special patch because of "bug" in function "mk_jb_invtext()"
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// ****
// Fremdauftragsnummer "$f_order_id"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_0", "gdc_content", $f_order_id, "gdc_context", "LYRECO"));
// Kundennummer "$f_customer_id"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_1", "gdc_content", $f_customer_id, "gdc_context", "LYRECO"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_cust_no", "gdc_content", $f_customer_id, "gdc_context", "LYRECO"));
// Lieferscheinnummer "$f_tr_commission_no"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_2", "gdc_content", $f_tr_commission_no, "gdc_context", "LYRECO"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_tr_commission_no . "_" . $currentDate, "gdc_context", "LYRECO"));
// Sendungsnummer "f_tr_remark3"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_3", "gdc_content", $f_tr_remark3, "gdc_context", "LYRECO"));
// Insert tourarticle data (delivery stations)
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
$trSort++;
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_order_id . "]<br>";
endif;
}
// Set generated jobs to status "taken"
$jobNewArrayLen = count($jobNewArray);
if ($jobNewArrayLen > 0) :
for ($i = 0; $i < $jobNewArrayLen; $i++) :
updateStmt("job", "jb_id", $jobNewArray[$i], array("jb_status", "1"));
endfor;
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_LYRECO.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

611
html/import/import_OBI.php Normal file
View File

@@ -0,0 +1,611 @@
<?php
/*=======================================================================
*
* import_OBI.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// include_once ("../include/inc_parseXML.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$currentShortDate = getDateTime(1);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
// Init
$jbIdNew = "";
$jbTourdata = "";
$jbTourdataZipcode = "";
$jbTourdataCity = "";
$jbTourdataCountry = "";
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strrpos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
/*
$tourVehicleArray = array();
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
*/
$tourCourierArray = array();
/*
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
$tourCourierArray["294505"] = "e8020205";
$tourCourierArray["294506"] = "e8020206";
$tourCourierArray["294507"] = "e8020207";
$tourCourierArray["294508"] = "e8020208";
$tourCourierArray["294509"] = "e8020209";
$tourCourierArray["294510"] = "e8020210";
$tourCourierArray["294511"] = "e8020211";
$tourCourierArray["294512"] = "e8020212";
$tourCourierArray["294590"] = "e8020213";
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
/*
$aStr = utf8_decode($aStr);
$aStr = str_replace("\"", '', $aStr);
$aStr = str_replace("ß", "ß", $aStr);
$aStr = str_replace("ä", "ä", $aStr);
$aStr = str_replace("ö", "ö", $aStr);
$aStr = str_replace("ü", "ü", $aStr);
$aStr = str_replace("Ä", "Ä", $aStr);
$aStr = str_replace("Ö", "Ö", $aStr);
$aStr = str_replace("Ü", "Ü", $aStr);
*/
return $aStr;
}
echo "importFile" . $importFile . "<br>";
echo "hqId" . $hqId . "<br>";
echo "csId" . $csId . "<br>";
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// The filename contains the execution day !!!!
$tmpJbOrdertime = substr($filename,-12,8);
$jbOrdertime = substr($tmpJbOrdertime,0,4) . "-" . substr($tmpJbOrdertime,4,2) . "-" . substr($tmpJbOrdertime,6,2) . " 08:00:00";
echo $jbOrdertime . "<br>";
// $jbOrdertime = checkDateTimeFormat($jbOrdertime); // DISABLED BECAUSE OF PHP VERSION ONLY !!! ACTIVATE AFTER MIGRATION !!!
$checkGmtdatetimeIsValid = strtotime($jbOrdertime);
echo $checkGmtdatetimeIsValid . "<br>";
if ($checkGmtdatetimeIsValid != "" && is_int($checkGmtdatetimeIsValid)):
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_OBI_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$jbIdNew = 0;
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_OBI_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
/*
Nr. Tour Bezeichnung Tourelement Bezeichnung Auftrag Bemerkungen Tourelement Position in Tour Tourelement PLZ Tourelement Ort Tourelement Straße Tourelement Hausnummer Tourelement Ankunft Tourelement Abfahrt Tourelement Strecke Auftrag Fixe Dauer
*/
$rowToImport[0] = "f_jb_tourname"; // A : Tour (v = vormittags, n = nachmittags)
$rowToImport[1] = "f_tr_sort"; // B : Lfd der Station
$rowToImport[2] = "f_tr_commission_no"; // C : Belegnummer
$rowToImport[3] = "f_tr_comp"; // D : Kunde / Frima
$rowToImport[4] = "f_ad_data"; // E : Adresse
$rowToImport[5] = "f_tr_phone"; // F : Telefon
$rowToImport[6] = "f_tr_mobile"; // G : Mobil
$rowToImport[7] = "f_tr_remark"; // H : Wareninfo
$rowToImport[8] = "f_palettes"; // I : Anzahl Paletten
$rowToImport[9] = "f_tr_remark2"; // J : Weitere Bemerkungen
$rowToImport[10] = "f_tr_remark3"; // K : Zusatz-Leistungen
$rowToImport[11] = "f_dummy_01"; // L : ?
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_jb_tourname = mcStrWrap($f_jb_tourname);
if (strtolower($f_jb_tourname) == "v") : $f_jb_tourname = "OBI-Vormittagstour"; endif;
if (strtolower($f_jb_tourname) == "n") : $f_jb_tourname = "OBI-Namchmittagstour"; endif;
$f_tr_sort = mcStrWrap($f_tr_sort);
$f_tr_commission_no = mcStrWrap($f_tr_commission_no);
// Check for existing headline
if ($j > 0 && ($f_tr_sort != "" && is_numeric($f_tr_sort)) && $f_tr_commission_no != "") :
$tmpArray = spliti(":", $f_tr_commission_no);
$tmpRemark = $tmpArray[1];
$tmpRemark = trim($tmpRemark);
$f_tr_commission_no = $tmpArray[0];
$f_tr_commission_no = trim($f_tr_commission_no);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_tr_person = $f_tr_comp;
$f_ad_data = mcStrWrap($f_ad_data);
$tmpArray = spliti(",", $f_ad_data);
$f_ad_street = $tmpArray[0];
if ($f_tr_hsno == "") :
$f_tr_hsno = ".";
endif;
$tmpArray[1] = str_replace ("D -", "", $tmpArray[1]);
$tmpArray[1] = str_replace ("D-", "", $tmpArray[1]);
$tmpArray[1] = trim($tmpArray[1]);
if (!is_numeric(substr($tmpArray[1],0,1))) :
$pos = strpos("-",$tmpArray[1]);
if ($pos === false) : $pos = 0; endif;
$f_ad_zipcode = substr($tmpArray[1],0,($pos + 1)) . "-" . preg_replace('/[^0-9]/', '', $tmpArray[1]);
$f_ad_city = preg_replace('/[^a-zäöü]/i', '', substr($tmpArray[1],1)); // Without first char (being the letter for the country)
else :
$f_ad_zipcode = preg_replace('/[^0-9]/', '', $tmpArray[1]);
$f_ad_zipcode = substr(trim($f_ad_zipcode),0,5);
$f_ad_city = preg_replace('/[^a-zäöü]/i', '', $tmpArray[1]);
endif;
$f_ad_city = trim($f_ad_city);
$f_tr_phone = mcStrWrap($f_tr_phone);
$f_tr_phone = eregPhoneNo($f_tr_phone);
$f_tr_mobile = mcStrWrap($f_tr_mobile);
$f_tr_mobile = eregPhoneNo($f_tr_mobile);
$f_tr_remark = mcStrWrap($f_tr_remark);
$f_palettes = mcStrWrap($f_palettes);
$f_tr_remark2 = mcStrWrap($f_tr_remark2);
$f_tr_remark3 = mcStrWrap($f_tr_remark3);
$f_tr_remark = $tmpRemark . "\n\n" . $f_tr_remark . "\n\n" . $f_tr_remark2 . "\n\n" . $f_palettes . "\n\n" . $f_tr_remark3;
if ($f_tr_phone == "") :
$f_tr_phone = $f_tr_mobile;
else :
if ($f_tr_mobile != "") :
$f_tr_remark .= "\n\n" . $f_tr_mobile;
endif;
endif;
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_jb_tourname];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
$crEid = $tourCourierArray[$f_jb_tourname];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
endif;
*/
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
$jbStatus = "1";
$jbTaketime = $currentTime;
endif;
$jbType = "2";
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
/*
echo $f_jb_tourname . ";" . $f_tr_sort . ";" . $f_tr_commission_no . ";";
echo $f_ad_street . ";" . $f_ad_zipcode . ";" . $f_ad_city . ";";
echo $f_tr_phone . ";" . $f_tr_mobile . ";" . $f_tr_remark;
echo "<br>";
*/
echo "------------------------------------------------------<br>";
echo "f_jb_tourname: " . $f_jb_tourname . "<br>";
echo "f_tr_sort: " . $f_tr_sort . "<br>";
echo "f_tr_commission_no: " . $f_tr_commission_no . "<br>";
echo "f_ad_street: " . $f_ad_street . "<br>";
echo "f_ad_zipcode: " . $f_ad_zipcode . "<br>";
echo "f_ad_city: " . $f_ad_city . "<br>";
echo "f_tr_phone: " . $f_tr_phone . "<br>";
echo "f_tr_mobile: " . $f_tr_mobile . "<br>";
echo "f_tr_remark: " . $f_tr_remark . "<br>";
// Check for existence of the imported "tour name" AND "station number" (unique for station)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_tr_commission_no . " " . $f_tr_sort . " " . $currentShortDate,"gdc_context","OBI"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if OBI number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = true;
if ($remTourNo == "" || $remTourNo == $f_jb_tourname) :
if ($jbTourdataZipcode != "") : $jbTourdataZipcode .= ";"; endif;
$jbTourdataZipcode .= $f_ad_zipcode;
if ($jbTourdataCity != "") : $jbTourdataCity .= ";"; endif;
$jbTourdataCity .= $f_ad_city;
if ($jbTourdataCountry != "") : $jbTourdataCountry .= ";"; endif;
$jbTourdataCountry .= "DE";
endif;
// Insert address
if ($f_ad_street == "" || $f_ad_zipcode == "" || $f_ad_city == "") :
$noValidationOfAddress = "1";
endif;
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_jb_tourname) :
// Finalize currently imported job
// Write "jb_tourdata" of the job currently imported
if ($remTourNo != "" && $jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// Remove existing tourname
updateStmt("job","jb_tourname",$f_jb_tourname,array("jb_tourname",""), "jb_tourname = '" . $f_jb_tourname . "'");
// Tour data
/*
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
*/
$jbIdNew = ""; // Init
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $jbOrdertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_createtime", $currentTime, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbIdNew = getLastInsertId();
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$remTourNo = $f_jb_tourname;
// Init for the next job to be imported
$jbTourdata = "";
// Init with current values
$jbTourdataZipcode = $f_ad_zipcode;
$jbTourdataCity = $f_ad_city;
$jbTourdataCountry = "DE";
endif;
// Check for inserted job
if ($jbIdNew != "") :
$trSort++;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
// Insert tourservice data
/*
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
*/
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort, "srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "", "trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// Tourname
// insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_0", "gdc_content", $f_tr_commission_no . " " . $f_tr_sort . " " . $currentShortDate, "gdc_context", "OBI"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_tr_commission_no . " " . $f_tr_sort . " " . $currentShortDate, "gdc_context", "OBI"));
// Insert tourarticle data (delivery stations)
/*
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
*/
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
/*
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
*/
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_order_id . "]<br>";
endif;
endif; // Check for headline
}
// If at least onne imported job does exist ($jbIdNew > 0) then finalize last imported job
// Write "jb_tourdata" of the job currently imported
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Das Datum für den Ausführungstag im Dateinamen scheint nicht korrekt! Bitte folgendes Format für den Dateinamen verwenden: import_OBI_YYYYMMDD.csv");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_OBI.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,209 @@
<?php
/*=======================================================================
*
* import_OBJECTS.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
include_once ("import.php");
// Execution-Time for script
set_time_limit(30000);
// Select user-type for mode of security check
$userType = getFieldValueFromId("user","usr_id",$usr_id,"usr_type");
$userTypeName = getUserTypeName($userType);
// Get the rights of the employee logged in and check the accessibility
if (!authCheckEmployeeRights($emp_id, "7")) : die ("$PHP_SELF: Access denied!"); endif;
// SPEZIELLER DATEINAME
$importPath = "../temp/";
$f_importFile = "hha_objekte.csv";
$currentDate = getDateTime("3") . " 03:00:00";
$fire = false;
// Import process
if (true) :
if (true) :
// 1547 BS_01
// 1742 FABS-AT-LAGER
$stkId = "1742";
$bekCountINS = 0;
$bekCountEXIST = 0;
$mekCountINS = 0;
$mekCountEXIST = 0;
$hop1CountINS = 0;
$hop1CountEXIST = 0;
$hop2CountINS = 0;
$hop2CountEXIST = 0;
$hop3CountINS = 0;
$hop3CountEXIST = 0;
$atIdMappingArr = array();
$atIdMappingArr["BEK"] = "4281";
$atIdMappingArr["MEK"] = "4282";
$atIdMappingArr["HOP1"] = "4289";
$atIdMappingArr["HOP2"] = "4287";
$atIdMappingArr["HOP3"] = "4288";
echo "<br><br><br><br><span class=\"f12bp1_red\" colspan=\"2\">Verarbeitungsprotokoll:</span><br><br>";
echo "Import-Datei: " . $f_importFile . "<br><br>";
$rowToImport = array();
$rowToImport[0] = "bek";
$rowToImport[1] = "mek";
$rowToImport[2] = "hop1";
$rowToImport[3] = "hop2";
$rowToImport[4] = "hop3";
$rowToImport[5] = "dummy";
$rowToImportLen = count($rowToImport);
// read file to import
$data = importCSV($importPath . $f_importFile);
$dataLen = count($data);
// loop all rows
for ($j = 0; $j < $dataLen; $j++) {
// loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
// $logJbId = getFieldValueFromClause("phoenix_log.import","jb_id","imp_id = '" . $f_jb_tourname . "' AND imp_pos = '" . $f_position . "'");
if (true) :
$bek = trim($bek);
$mek = trim($mek);
$hop1 = trim($hop1);
$hop2 = trim($hop2);
$hop3 = trim($hop3);
echo "[" . pad($j,3) . "] " . "BEK=" . $bek . " " . "MEK=" . $mek . " " . "HOP1=" . $hop1 . " " . "HOP2=" . $hop2 . " " . "HOP3=" . $hop3 . "<br>";
$bek = substr($bek,3);
$mek = substr($mek,3);
$hop1 = substr($hop1,3);
$hop2 = substr($hop2,3);
$hop3 = substr($hop3,3);
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . "BEK=" . $bek . " " . "MEK=" . $mek . " " . "HOP1=" . $hop1 . " " . "HOP2=" . $hop2 . " " . "HOP3=" . $hop3 . "<br>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
if ($bek != "") :
$bekId = getFieldValueFromId("articleitem","ati_serialno",$bek,"ati_id");
if ($bekId == "") :
echo "BEK=INS ";
$bekCountINS++;
else :
echo "BEK=EXIST ";
$bekCountEXIST++;
endif;
endif;
if ($mek != "") :
$mekId = getFieldValueFromId("articleitem","ati_serialno",$mek,"ati_id");
if ($mekId == "") :
echo "MEK=INS ";
$mekCountINS++;
else :
echo "MEK=EXIST ";
$mekCountEXIST++;
endif;
endif;
if ($hop1 != "") :
$hop1Id = getFieldValueFromId("articleitem","ati_serialno",$hop1,"ati_id");
if ($hop1Id == "") :
echo "HOP1=INS ";
$hop1CountINS++;
else :
echo "HOP1=EXIST ";
$hop1CountEXIST++;
endif;
endif;
if ($hop2 != "") :
$hop2Id = getFieldValueFromId("articleitem","ati_serialno",$hop2,"ati_id");
if ($hop2Id == "") :
echo "HOP2=INS ";
$hop2CountINS++;
else :
echo "HOP2=EXIST ";
$hop2CountEXIST++;
endif;
endif;
if ($hop3 != "") :
$hop3Id = getFieldValueFromId("articleitem","ati_serialno",$hop3,"ati_id");
if ($hop3Id == "") :
echo "HOP3=INS ";
$hop3CountINS++;
else :
echo "HOP3=EXIST ";
$hop3CountEXIST++;
endif;
endif;
echo "<br><br>";
if ($fire) :
if ($bek != "" && $bekId == "") :
insertStmt("articleitem", array("at_id", $atIdMappingArr["BEK"], "stk_id", $stkId, "ati_serialno", $bek, "ati_data_04", $currentDate));
endif;
if ($mek != "" && $mekId == "") :
insertStmt("articleitem", array("at_id", $atIdMappingArr["MEK"], "stk_id", $stkId, "ati_serialno", $mek, "ati_data_04", $currentDate));
endif;
if ($hop1 != "" && $hop1Id == "") :
insertStmt("articleitem", array("at_id", $atIdMappingArr["HOP1"], "stk_id", $stkId, "ati_serialno", $hop1, "ati_data_04", $currentDate));
endif;
if ($hop2 != "" && $hop2Id == "") :
insertStmt("articleitem", array("at_id", $atIdMappingArr["HOP2"], "stk_id", $stkId, "ati_serialno", $hop2, "ati_data_04", $currentDate));
endif;
if ($hop3 != "" && $hop3Id == "") :
insertStmt("articleitem", array("at_id", $atIdMappingArr["HOP3"], "stk_id", $stkId, "ati_serialno", $hop3, "ati_data_04", $currentDate));
endif;
endif;
endif;
}
echo "BEK::INS=" . $bekCountINS . "<br>";
echo "BEK::EXIST=" . $bekCountEXIST . "<br>";
echo "MEK::INS=" . $mekCountINS . "<br>";
echo "MEK::EXIST=" . $mekCountEXIST . "<br>";
echo "HOP1::INS=" . $hop1CountINS . "<br>";
echo "HOP1::EXIST=" . $hop1CountEXIST . "<br>";
echo "HOP2::INS=" . $hop2CountINS . "<br>";
echo "HOP2::EXIST=" . $hop2CountEXIST . "<br>";
echo "HOP3::INS=" . $hop3CountINS . "<br>";
echo "HOP3::EXIST=" . $hop3CountEXIST . "<br>";
echo "<br>";
$sumExist = $bekCountEXIST + $mekCountEXIST + $hop1CountEXIST + $hop2CountEXIST + $hop3CountEXIST;
$sumIns = $bekCountINS + $mekCountINS + $hop1CountINS + $hop2CountINS + $hop3CountINS;
echo "SUMME EXISTENTER OBJEKTE: " . $sumExist . "<br>";
echo "SUMME NEUER OBJEKTE: " . $sumIns . "<br>";
// Remove import file
// $retVal = removeFile($f_importFile, $importPath, $pathSeparator);
endif;
endif;
?>

View File

@@ -0,0 +1,338 @@
<?php
/*=======================================================================
*
* import_RADIUSZONE.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
include_once ("../import/import.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT RADIUS-ZONEN");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = true;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Customer and headquarters references have to exist
$hqId = "";
$csEid = "";
$objType = trim($objType);
$objId = trim($objId);
if ($objType == "CS" && is_numeric($objId)) :
// $csId = getFieldValueFromId("phoenix.customer", "cs_id", $objId, "cs_id");
$csId = $objId;
endif;
// Get $csId (if empty) from EID out of the filename
if ($csId == "") :
$posLastSlash = strripos($filename, "_");
$posLastSlash++;
$csEid = trim(substr($filename, $posLastSlash));
$csId = getFieldValueFromId("phoenix.customer", "cs_id", $csEid, "cs_eid");
if (is_numeric($csId)) :
$objId = $csId;
$objType = "CS";
endif;
endif;
// Get headquarters and EID
if ($csId != "") :
$hqId = getFieldValueFromId("phoenix.customer", "cs_id", $csId, "hq_id");
$csEid = getFieldValueFromId("phoenix.customer", "cs_id", $csId, "cs_eid");
endif;
if ($debug) :
echo "f_act : " . $f_act . "<br>";
echo "objType : " . $objType . "<br>";
echo "objId : " . $objId . "<br>";
echo "hqId : " . $hqId . "<br>";
echo "csId : " . $csId . "<br>";
echo "<br>";
endif;
if ($importFile != "") :
if ($hqId != "" && $csId != "") :
// Create internal representation
$srvpArray = array();
$zoneArray = array();
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ********************
// * IMPORT FILE zone *
// ********************
if (!(strpos($filename, "import_RADIUSZONE_") === false)) :
$rowToImport = array();
$rowToImport[0] = "f_zone_no";
$rowToImport[1] = "f_zipcode";
$rowToImport[2] = "f_district";
$rowToImport[3] = "f_dummy";
$rowToImportLen = count($rowToImport);
// read file to import
$data = importCSV($importFile, $delimiter);
$dataLen = count($data);
// loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_country = "DE";
$f_zone_no = removeFieldSigns($f_zone_no);
$f_zipcode = removeFieldSigns($f_zipcode);
$f_district = removeFieldSigns($f_district);
if ($f_zipcode != "") :
if ($f_country == "" || !existsEntry("phoenix_special.country",array("cou_iso_2",$f_country))) :
$f_country = "DE";
endif;
// Get srvp_id from serviceplz
$srvpId = getFieldValueFromId("phoenix.serviceplz", "srvp_plz", $f_zipcode, "srvp_id");
if ($srvpId != "") :
// If country "Germany" then fill zipcode with "0" up to 5 chars
if ($f_country == "DE") :
$f_zipcode = pad($f_zipcode, 5);
endif;
// Set arrays
$srvpArray[] = array($srvpId, $f_zipcode, $f_zone_no, $f_country, $f_district);
$x = array_search($f_zone_no, $zoneArray);
if ($x === FALSE) :
$zoneArray[] = $f_zone_no;
endif;
else :
$outText .= getLngt("PLZ " . $f_zipcode . " wird im Basisdatenbestand nicht geführt!") . "<br>";
endif;
else :
$outText .= getLngt("Keine PLZ im Datensatz!") . "<br>";
endif;
}
if ($debug) :
// print_r($zoneArray); echo "<br><br>";
// print_r($srvpArray); echo "<br><br>";
endif;
// Insert new zone zipcodes into the database from internal structure
if ($fire && $executeImportProcess == "1") :
$zoneArrayLen = count($zoneArray);
$srvpArrayLen = count($srvpArray);
TA("B");
// Delete zipcodes of the customer (and headquarters) and the specified zone
for ($k = 0; $k < $zoneArrayLen; $k++) :
deleteStmt("phoenix.serviceradius","srvz_id = '" . $zoneArray[$k] . "' AND cs_id = '" . $csId . "' AND hq_id = '" . $hqId . "'");
$outText .= getLngt("Zone " . $zoneArray[$k] . " für den Kunden " . $csEid . " wurde im Basisdatenbestand entfernt!") . "<br>";
endfor;
// Import new zipcodes
$executionCount = 0;
$existingCount = 0;
for ($k = 0; $k < $srvpArrayLen; $k++) :
// Check for existence of mapping entry
if (!existsEntry("phoenix.serviceradius",array("cs_id", $csId, "hq_id", $hqId, "srvr_zipcode", $srvpArray[$k][1], "srvr_zipcode", $srvpArray[$k][4]))) :
insertStmt("phoenix.serviceradius", array("cs_id", $csId, "hq_id", $hqId, "srvr_zipcode", $srvpArray[$k][1], "srvr_zipcode", $srvpArray[$k][4], "srvr_radiusarea_no", $srvpArray[$k][2])));
$executionCount++;
else :
$existingCount++;
endif;
endfor;
TA("C");
TA("E");
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Eingefügte Einträge: " . $executionCount . "<br>");
$outText .= getLngt("Existierende Einträge: " . $existingCount . "<br>");
// $closeWindow = "1";
endif;
endif;
// ********************
// * IMPORT FILE xxxx *
// ********************
// if (!(strpos($filename, "import_xxxx") === false)) :
// endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Diese Datei muss für einen bestimmten Kunden verarbeitet werden!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
/*
CREATE TABLE servicezone (
srvz_id int(10) NOT NULL auto_increment,
hq_id int(10) NOT NULL default '0',
cs_id int(10) NOT NULL default '0',
srvz_no tinyint(3) default '0',
srvz_name varchar(50) NOT NULL default '',
srvz_price float(10,4) NOT NULL default '0.0000',
srvz_price2 float(10,4) NOT NULL default '0.0000',
PRIMARY KEY (srvz_id)
) ENGINE=InnoDB;
CREATE TABLE servicezonemapping (
srvz_id int(10) NOT NULL default '0',
srvp_id int(10) NOT NULL default '0'
) ENGINE=InnoDB;
*/
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_ZONE.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,737 @@
<?php
/*=======================================================================
*
* import_SCHWEMANN.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Get special user types from parameter
$specialUserTypeIsLoggedIn = false;
$specialUserType = "";
$specialUserHqId = "";
$specialUserFTPServerList = "";
$specialUserDirSpecialForObjType = "";
$userTypesSpecialArray = getDatatransferSpecialUserData($userType);
if (count($userTypesSpecialArray) > 0) :
$specialUserTypeIsLoggedIn = true;
list($specialUserType, $specialUserHqId, $specialUserFTPServerList, $specialUserObjType, $specialUserObjId, $specialUserDirSpecialForObjType) = $userTypesSpecialArray;
if ($objType == $specialUserObjType && $objId == $specialUserObjType) :
$hqId = $specialUserHqId;
endif;
endif;
// Check for authentication access
$empHasAdminRights = false;
if (!$specialUserTypeIsLoggedIn) :
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csId = "";
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
$csAddress = array();
$adIdFrom = 0;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
// $csAddress = getAddress($csId, "customer");
$csAddress = getAddress($csId, "costcenteraddress");
$adIdFrom = $csAddress["id"];
$trHsnoFrom = $csAddress["hsno"];
if ($trHsnoFrom == "") : $trHsnoFrom = "."; endif;
$trCompFrom = $csAddress["comp"];
if ($trCompFrom == "") : $trCompFrom = "SCHWEMANN"; endif;
$trFloorFrom = "";
// USE FOLLOWING FIX ADDRESS
// $adIdFrom = "220594"; // Invoice address
// $adIdFrom = "125964"; // Pick-up address
// $trHsnoFrom = "4";
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
$pickUpStationFinishedByDefault = true;
// Tourdata array
$jbTourdata = "";
$jbTourdataZipcodeArray = array();
$jbTourdataCityArray = array();
$jbTourdataCountryArray = array();
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
$tourVehicleArray = array();
/*
if ($hqId == "nnn") :
// NL X
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
....
elseif ($hqId == "mmm") :
// NL Y
endif;
*/
/*
BSP.:
TOUR KARTE FAHRER-EID
SE1 89882390000018392582 h8042504
SE2 89882390000018392566 h8042503
SE3 89882390000018392541 h8042501
SE4 89882390000018392574 h8042502
SE5 89882390000018392590 h8042505
SE6 89882390000018392749 h8042506
SE7 89882390000012934850 h8042507
ST1 89882390000018392582 h8042504
ST2 89882390000018392566 h8042503
ST3 89882390000018392756 h8042501
ST4 89882390000018392574 h8042502
ST5 89882390000018392590 h8042505
ST6 89882390000018392749 h8042506
ST7 89882390000012934850 h8042507
....
*/
$tourCourierArray = array();
$tourCourierArray["SE1"] = "h8042504";
$tourCourierArray["SE2"] = "h8042503";
$tourCourierArray["SE3"] = "h8042501";
$tourCourierArray["SE4"] = "h8042502";
$tourCourierArray["SE5"] = "h8042505";
$tourCourierArray["SE6"] = "h8042506";
$tourCourierArray["SE7"] = "h8042507";
$tourCourierArray["ST1"] = "h8042504";
$tourCourierArray["ST2"] = "h8042503";
$tourCourierArray["ST3"] = "h8042501";
$tourCourierArray["ST4"] = "h8042502";
$tourCourierArray["ST5"] = "h8042505";
$tourCourierArray["ST6"] = "h8042506";
$tourCourierArray["ST7"] = "h8042507";
$tourSIDArray = array();
/*
// SID array (fix!)
if ($hqId == "107") :
// NL X
$tourSIDArray["294590"] = "E355";
$tourSIDArray["294501"] = "E356";
$tourSIDArray["294502"] = "E357";
$tourSIDArray["294503"] = "E358";
....
elseif ($hqId == "110") :
// NL Y
endif;
*/
$tourSIDArray["SE1"] = "H075";
$tourSIDArray["SE2"] = "H076";
$tourSIDArray["SE3"] = "H077";
$tourSIDArray["SE4"] = "H078";
$tourSIDArray["SE5"] = "H079";
$tourSIDArray["SE6"] = "H080";
$tourSIDArray["SE7"] = "H091";
$tourSIDArray["ST1"] = "H075";
$tourSIDArray["ST2"] = "H076";
$tourSIDArray["ST3"] = "H077";
$tourSIDArray["ST4"] = "H078";
$tourSIDArray["ST5"] = "H079";
$tourSIDArray["ST6"] = "H080";
$tourSIDArray["ST7"] = "H091";
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
return $aStr;
}
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_SCHWEMANN_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$jbIdNew = 0;
$trSort = 2; // Init for 2nd station equals first delivery !!!!
$tratSort = 1; // Init all serial numbers !!!!
$jobNewArray = array();
$useJbNewArray = false;
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_SCHWEMANN_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
$rowToImport[0] = "f_tour_no"; // A : Tournr. / Tourbezeichnung
$rowToImport[1] = "f_shipment_mode"; // B : Lieferung/Abholung
$rowToImport[2] = "f_tr_orderdate"; // C : Ausführungsdatum / Ausführungszeitstempel
$rowToImport[3] = "f_tr_warningdate"; // D : Zustellungsdatum
$rowToImport[4] = "f_tr_starttime"; // E : Zustellung von
$rowToImport[5] = "f_tr_endtime"; // F : Zustellung bis
$rowToImport[6] = "f_tr_commission_no"; // G : Lieferscheinnummer
$rowToImport[7] = "f_order_id"; // H : Kundenauftragsnummer
$rowToImport[8] = "f_cs_id_external"; // I : Kundennummer extern / Lieferantennummer
$rowToImport[9] = "f_cs_eid"; // J : Kundenummer (EID,intern)
$rowToImport[10] = "f_tr_comp"; // K : Firma
$rowToImport[11] = "f_tr_comp2"; // L : Firma Zusatz
$rowToImport[12] = "f_special_01"; // M : Besteller
$rowToImport[13] = "f_ad_street"; // N : Straße
$rowToImport[14] = "f_tr_hsno"; // O : Hausnummer
$rowToImport[15] = "f_tr_floor"; // P : Etage
$rowToImport[16] = "f_ad_zipcode"; // Q : PLZ
$rowToImport[17] = "f_ad_city"; // R : Ort
$rowToImport[18] = "f_ad_country"; // S : Land
$rowToImport[19] = "f_ad_supplement_1"; // T : Adresszusatz I
$rowToImport[20] = "f_ad_supplement_2"; // U : Adresszusatz II
$rowToImport[21] = "f_tr_person"; // V : Ansprechpartner
$rowToImport[22] = "f_tr_phone"; // W : Telefon
$rowToImport[23] = "f_special_02"; // X : Mobiltelefonnummer
$rowToImport[24] = "f_special_03"; // Y : Emailadresse
$rowToImport[25] = "f_tr_remark"; // Z : Bemerkung / Zustellinfo
$rowToImport[26] = "f_id"; // AA: Sendungsidentifikationsnummer
$rowToImport[27] = "f_trat_packingpieces"; // AB: Packstücke
$rowToImport[28] = "f_trat_palets"; // AC: Paletten
$rowToImport[29] = "f_trat_weight"; // AD: Gewicht
$rowToImport[30] = "f_special_04"; // AE: Stellplätze
$rowToImport[31] = "f_special_05"; // AF: Warenart
$rowToImport[32] = "f_zone_no"; // AG: Zone
$rowToImport[33] = "f_special_06"; // AH: Inkasso/Rückführung
$rowToImport[34] = "f_price_type"; // AI: Preistyp
$rowToImport[35] = "f_service_type"; // AJ: Leistungstyp
$rowToImport[36] = "f_dummy_01"; // AK: DUMMY_01
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_tour_no = mcStrWrap($f_tour_no); // Tournr. / Tourbezeichnung
$f_shipment_mode = mcStrWrap($f_shipment_mode); // Lieferung/Abholung
$f_tr_ware_from_to = 0;
if ($f_shipment_mode == "R") :
$f_tr_ware_from_to = 1;
elseif ($f_shipment_mode == "L") :
$f_tr_ware_from_to = 2;
endif;
$f_tr_orderdate = mcStrWrap($f_tr_orderdate); // Ausführungsdatum / Ausführungszeitstempel
$f_tr_warningdate = mcStrWrap($f_tr_warningdate); // Zustellungsdatum
$f_tr_starttime = mcStrWrap($f_tr_starttime); // Zustellung von
$f_tr_endtime = mcStrWrap($f_tr_endtime); // Zustellung bis
$f_tr_commission_no = mcStrWrap($f_tr_commission_no); // Lieferscheinnummer
$f_order_id = mcStrWrap($f_order_id); // Kundenauftragsnummer
$f_cs_id_external = mcStrWrap($f_cs_id_external); // Kundennummer extern / Lieferantennummer
$f_cs_eid = mcStrWrap($f_cs_eid); // Kundenummer (votian)
$f_tr_comp = mcStrWrap($f_tr_comp); // Firma
$f_tr_comp2 = mcStrWrap($f_tr_comp2); // Firma Zusatz
$f_special_01 = mcStrWrap($f_special_01); // Besteller
$f_ad_street = mcStrWrap($f_ad_street); // Straße
$f_tr_hsno = mcStrWrap($f_tr_hsno); // Hausnummer
if ($f_tr_hsno == "") : $f_tr_hsno = "."; endif;
$f_tr_floor = mcStrWrap($f_tr_floor); // Etage
$f_ad_zipcode = mcStrWrap($f_ad_zipcode); // PLZ
$f_ad_city = mcStrWrap($f_ad_city); // Ort
$f_ad_country = mcStrWrap($f_ad_country); // Land
if ($f_ad_country == "" || $f_ad_country == "D") : $f_ad_country = "DE"; endif;
$f_ad_supplement_1 = mcStrWrap($f_ad_supplement_1); // Adresszusatz I
$f_ad_supplement_2 = mcStrWrap($f_ad_supplement_2); // Adresszusatz II
$f_tr_person = mcStrWrap($f_tr_person); // Ansprechpartner
$f_tr_phone = mcStrWrap($f_tr_phone); // Telefon
$f_special_02 = mcStrWrap($f_special_02); // Mobiltelefonnummer
$f_special_03 = mcStrWrap($f_special_03); // Emailadresse
$f_tr_remark = mcStrWrap($f_tr_remark); // Bemerkung / Zustellinfo
$f_id = mcStrWrap($f_id); // Sendungsidentifikationsnummer
$f_trat_packingpieces = mcStrWrap($f_trat_packingpieces); // Packstücke
$f_trat_palets = mcStrWrap($f_trat_palets); // Paletten
$f_trat_weight = mcStrWrap($f_trat_weight); // Gewicht
$f_trat_weight = str_replace (",", ".", $f_trat_weight);
$f_special_04 = mcStrWrap($f_special_04); // Stellplätze
$f_special_05 = mcStrWrap($f_special_05); // Warenart
$f_zone_no = mcStrWrap($f_zone_no); // Zone
$f_special_06 = mcStrWrap($f_special_06); // Inkasso/Rückführung
$f_price_type = mcStrWrap($f_price_type); // Preistyp
$f_service_type = mcStrWrap($f_service_type); // Leistungstyp
$f_dummy_01 = mcStrWrap($f_dummy_01);
if ($f_special_01 != "") : $f_tr_remark .= "\n<br>" . getLngt("Besteller") . ": " . $f_special_01; endif;
if ($f_special_02 != "") : $f_tr_remark .= "\n<br>" . getLngt("Mobiltelefonnummer") . ": " . $f_special_02; endif;
if ($f_special_03 != "") : $f_tr_remark .= "\n<br>" . getLngt("Emailadresse") . ": " . $f_special_03; endif;
if ($f_id != "") : $f_tr_remark .= "\n<br>" . getLngt("Sendungs-ID") . ": " . $f_id; endif;
if ($f_trat_packingpieces != "") : $f_tr_remark .= "\n<br>" . getLngt("Packstücke") . ": " . $f_trat_packingpieces; endif;
if ($f_trat_palets != "") : $f_tr_remark .= "\n<br>" . getLngt("Paletten") . ": " . $f_trat_palets; endif;
if ($f_trat_weight != "") : $f_tr_remark .= "\n<br>" . getLngt("Gewicht") . ": " . $f_trat_weight; endif;
if ($f_special_04 != "") : $f_tr_remark .= "\n<br>" . getLngt("Stellplätze") . ": " . $f_special_04; endif;
if ($f_special_05 != "") : $f_tr_remark .= "\n<br>" . getLngt("Warenart") . ": " . $f_special_05; endif;
if ($f_zone_no != "") : $f_tr_remark .= "\n<br>" . getLngt("Zone") . ": " . $f_zone_no; endif;
if ($f_special_06 != "") : $f_tr_remark .= "\n<br>" . getLngt("Inkasso/Rückführung") . ": " . $f_special_06; endif;
if ($f_price_type != "") : $f_tr_remark .= "\n<br>" . getLngt("Preistyp") . ": " . $f_price_type; endif;
if ($f_service_type != "") : $f_tr_remark .= "\n<br>" . getLngt("Leistungstyp") . ": " . $f_service_type; endif;
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_tour_no];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
*/
$crEid = $tourCourierArray[$f_tour_no];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
$crSid = $tourSIDArray[$f_tour_no];
endif;
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
// $jbStatus = "1"; // jb_status will be set after the whole job is generated
$jbTaketime = $currentTime;
$useJbNewArray = true;
endif;
$jbType = "2";
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo $f_id . ";" . $f_tour_no . ";" . $f_shipment_mode . ";" . $f_jb_orderdate . ";" . $f_jb_warningdate . ";" . $f_jb_starttime . ";" . $f_jb_endtime . ";";
echo $f_tr_commission_no . ";" . $f_order_id . ";" . $f_cs_id_external . ";" . $f_cs_eid . ";" . $f_tr_comp . ";" . $f_tr_comp2 . ";" . $f_special_01 . ";";
echo $f_tr_remark . ";" . $f_ad_street . ";" . $f_tr_hsno . ";" . $f_tr_floor . ";" . $f_ad_zipcode . ";" . $f_ad_city . ";" . ";" . $f_ad_country;
echo $f_ad_supplement_1 . ";" . $f_ad_supplement_2 . ";" . $f_tr_person . ";" . $f_tr_phone . ";" . $f_special_02 . ";" . $f_special_03 . ";" . ";" . $f_tr_remark;
echo $f_trat_packingpieces . ";" . $f_trat_palets . ";" . $f_trat_weight . ";" . $f_special_04 . ";" . $f_special_05 . ";";
echo $f_zone_no . ";" . $f_special_06 . ";" . $f_price_type . ";" . $f_service_type . ";";
echo "<br>";
echo "----------------------------------------------------------------------------------------------------------------------------------------------<br>";
// Check for existence of the imported order number (for the same day ONLY)
$gdcEntryExists = false;
// if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","info_2","gdc_content",$f_tr_commission_no,"gdc_context","SCHWEMANN"))) :
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_tr_commission_no . "_" . $currentDate,"gdc_context","SCHWEMANN"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if SCHWEMANN number does exist on the current day!!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$callInsertAddress = true;
if ($f_cs_eid != "") :
$csEndId = getFieldValueFromId("customer","cs_eid",$f_cs_eid,"cs_id");
if ($csEndId != "") :
$csEndAddress = getAddress($csEndId, "costcenteraddress");
$adIdCsEnd = $csEndAddress["id"];
if ($adIdCsEnd != "") :
$callInsertAddress = false;
endif;
$f_ad_street = $csEndAddress["street"];
$f_tr_hsno = $csEndAddress["hsno"];
$f_ad_zipcode = $csEndAddress["zipcode"];
$f_ad_city = $csEndAddress["city"];
$f_ad_country = $csEndAddress["country"];
if ($f_ad_country == "") :
$f_ad_country = "DE";
endif;
endif;
endif;
$noValidationOfAddress = true;
// Insert address
if ($callInsertAddress) :
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
endif;
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_tour_no) :
$jbIdNew = "";
// Start datetime
if ($f_tr_starttime == "") : $f_tr_starttime = "08:00"; endif;
$f_jb_ordertime = substr($f_tr_orderdate, 0,4) . "-" . substr($f_tr_orderdate, 4,2) . "-" . substr($f_tr_orderdate, 6,2) . " " . $f_tr_starttime . ":00";
// End datetime
$f_jb_warningtime = "";
if ($f_tr_endtime == "") : $f_tr_endtime = "18:00"; endif;
/*
if ($f_jb_warningdate != "") :
$f_jb_warningtime = substr($f_tr_warningdate, 0,4) . "-" . substr($f_tr_warningdate, 4,2) . "-" . substr($f_tr_warningdate, 6,2);
if ($f_tr_warningdate != "") :
$f_jb_warningtime .= " " . $f_tr_endtime . ":00";
endif;
endif;
*/
// Remove existing tourname
updateStmt("job","jb_tourname",$f_tour_no,array("jb_tourname",""), "jb_tourname = '" . $f_tour_no . "'");
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_tour_no,
"jb_finishtime", $jbFinishtime, "jb_warningtime", $f_jb_warningtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbIdNew = getLastInsertId();
$jobNewArray[] = $jbIdNew;
// Tour-Nr. "$f_tour_no"
insertStmt("genericdatacontainer", array("gdc_obj_type", "jb", "gdc_obj_id", $jbIdNew, "gdc_gen_fieldname", "tourname", "gdc_content", $f_tour_no, "gdc_context", "SCHWEMANN"));
$trSort = 2; // Init for 2nd station equals first delivery !!!!
$tratSort = 1; // Init all serial numbers !!!!
$remTourNo = $f_tour_no;
endif;
// Check for inserted job
if ($jbIdNew != "") :
// Insert stations
if ($trSort == 2) :
$trStatus = "0";
$trFinishtime = "";
if ($pickUpStationFinishedByDefault) :
$trStatus = "1";
$trFinishtime = $currentTime;
endif;
// Insert pick up station during first iteration
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $adIdFrom, "tr_sort", "1", "tr_comp", $trCompFrom, "tr_comp2", "",
"tr_hsno", $trHsnoFrom, "tr_floor", $trFloorFrom, "csc_id", $cscIdPayer, "tr_status", $trStatus, "tr_finishtime", $trFinishtime,
"tr_commission_no", "", "tr_ware_from_to", $f_tr_ware_from_to,
"tr_person", "", "tr_phone", "", "tr_remark", ""));
$trIdPickUpNew = getLastInsertID();
// Init array für jb_tourdata
$jbTourdataZipcodeArray[$jbIdNew][] = $csAddress["zipcode"];
$jbTourdataCityArray[$jbIdNew][] = $csAddress["city"];
$jbTourdataCountryArray[$jbIdNew][] = $csAddress["country"];
endif;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "tr_floor", $f_tr_floor, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
$jbTourdataZipcodeArray[$jbIdNew][] = $f_ad_zipcode;
$jbTourdataCityArray[$jbIdNew][] = $f_ad_city;
$jbTourdataCountryArray[$jbIdNew][] = $f_ad_country;
// Insert tourservice data
// !!!! MIT tr_id !!!! insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// ****
// Special patch because of "bug" in function "mk_jb_invtext()"
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// ****
// Fremdauftragsnummer "$f_order_id"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_0", "gdc_content", $f_order_id, "gdc_context", "SCHWEMANN"));
// Kundennummer "$f_cs_id_external"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_1", "gdc_content", $f_cs_id_external, "gdc_context", "SCHWEMANN"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_cust_no", "gdc_content", $f_cs_id_external, "gdc_context", "SCHWEMANN"));
// Lieferscheinnummer "$f_tr_commission_no"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_2", "gdc_content", $f_tr_commission_no, "gdc_context", "SCHWEMANN"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_tr_commission_no . "_" . $currentDate, "gdc_context", "SCHWEMANN"));
// Insert tourarticle data (delivery stations)
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
$trSort++;
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_order_id . "]<br>";
endif;
}
// Set generated jobs to status "taken"
$jobNewArrayLen = count($jobNewArray);
if ($jobNewArrayLen > 0) :
for ($i = 0; $i < $jobNewArrayLen; $i++) :
// jb_status
updateStmt("job", "jb_id", $jobNewArray[$i], array("jb_status", "1"));
// jb_tourdata
$jbTourdata = implode(";", $jbTourdataZipcodeArray[$jobNewArray[$i]]) . "|" . implode(";", $jbTourdataCityArray[$jobNewArray[$i]]) . "|" . implode(";", $jbTourdataCountryArray[$jobNewArray[$i]]);
updateStmt("job", "jb_id", $jobNewArray[$i], array("jb_tourdata", $jbTourdata));
endfor;
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_SCHWEMANN.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,715 @@
<?php
/*=======================================================================
*
* import_SERVONA.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Get special user types from parameter
$specialUserTypeIsLoggedIn = false;
$specialUserType = "";
$specialUserHqId = "";
$specialUserFTPServerList = "";
$specialUserDirSpecialForObjType = "";
$userTypesSpecialArray = getDatatransferSpecialUserData($userType);
if (count($userTypesSpecialArray) > 0) :
$specialUserTypeIsLoggedIn = true;
list($specialUserType, $specialUserHqId, $specialUserFTPServerList, $specialUserObjType, $specialUserObjId, $specialUserDirSpecialForObjType) = $userTypesSpecialArray;
if ($objType == $specialUserObjType && $objId == $specialUserObjType) :
$hqId = $specialUserHqId;
endif;
endif;
// Check for authentication access
$empHasAdminRights = false;
if (!$specialUserTypeIsLoggedIn) :
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csId = "";
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
$csAddress = array();
$adIdFrom = 0;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
// $csAddress = getAddress($csId, "customer");
$csAddress = getAddress($csId, "costcenteraddress");
$adIdFrom = $csAddress["id"];
$trHsnoFrom = $csAddress["hsno"];
if ($trHsnoFrom == "") : $trHsnoFrom = "."; endif;
$trCompFrom = $csAddress["comp"];
if ($trCompFrom == "") : $trCompFrom = "SERVONA"; endif;
$trFloorFrom = "";
// USE FOLLOWING FIX ADDRESS
// $adIdFrom = "220594"; // Invoice address
// $adIdFrom = "125964"; // Pick-up address
// $trHsnoFrom = "4";
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
$pickUpStationFinishedByDefault = true;
// Tourdata array
$jbTourdata = "";
$jbTourdataZipcodeArray = array();
$jbTourdataCityArray = array();
$jbTourdataCountryArray = array();
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
$tourVehicleArray = array();
/*
if ($hqId == "nnn") :
// NL X
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
....
elseif ($hqId == "mmm") :
// NL Y
endif;
*/
/*
BSP.:
TOUR_NO SID EID NAME FIRSTNAME
294501 E501  e8020201  Schmidt   Alexander  0176 62283533
294502 E502  e8020202  Brazinskas  Zilvinas  0152 55904274
294503 E503  e8020203  Orakov   Anton  0152 01985959
294504 E504  e8020204  Isaak   Alexander  0152 53172115
....
$tourCourierArray = array();
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
....
*/
$tourCourierArray = array();
/*
if ($hqId == "nnn") :
// NL X
$tourCourierArray["294590"] = "e8020401"; // stepenka 01
$tourCourierArray["294501"] = "e8020402"; // stepenka 02
$tourCourierArray["294502"] = "e8020403"; // stepenka 03
$tourCourierArray["294503"] = "e8020404"; // stepneka 04
....
elseif ($hqId == "mmm") :
// NL Y
endif;
// SID array (fix!)
$tourSIDArray = array();
if ($hqId == "107") :
// NL X
$tourSIDArray["294590"] = "E355";
$tourSIDArray["294501"] = "E356";
$tourSIDArray["294502"] = "E357";
$tourSIDArray["294503"] = "E358";
....
elseif ($hqId == "110") :
// NL Y
endif;
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
return $aStr;
}
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_SERVONA_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$jbIdNew = 0;
$trSort = 2; // Init for 2nd station equals first delivery !!!!
$tratSort = 1; // Init all serial numbers !!!!
$jobNewArray = array();
$useJbNewArray = false;
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_SERVONA_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
$rowToImport[0] = "f_tour_no"; // A : Tournr. / Tourbezeichnung
$rowToImport[1] = "f_shipment_mode"; // B : Lieferung/Abholung
$rowToImport[2] = "f_tr_orderdate"; // C : Ausführungsdatum / Ausführungszeitstempel
$rowToImport[3] = "f_tr_warningdate"; // D : Zustellungsdatum
$rowToImport[4] = "f_tr_starttime"; // E : Zustellung von
$rowToImport[5] = "f_tr_endtime"; // F : Zustellung bis
$rowToImport[6] = "f_tr_commission_no"; // G : Lieferscheinnummer
$rowToImport[7] = "f_order_id"; // H : Kundenauftragsnummer
$rowToImport[8] = "f_cs_id_external"; // I : Kundennummer extern / Lieferantennummer
$rowToImport[9] = "f_cs_eid"; // J : Kundenummer (EID,intern)
$rowToImport[10] = "f_tr_comp"; // K : Firma
$rowToImport[11] = "f_tr_comp2"; // L : Firma Zusatz
$rowToImport[12] = "f_special_01"; // M : Besteller
$rowToImport[13] = "f_ad_street"; // N : Straße
$rowToImport[14] = "f_tr_hsno"; // O : Hausnummer
$rowToImport[15] = "f_tr_floor"; // P : Etage
$rowToImport[16] = "f_ad_zipcode"; // Q : PLZ
$rowToImport[17] = "f_ad_city"; // R : Ort
$rowToImport[18] = "f_ad_country"; // S : Land
$rowToImport[19] = "f_ad_supplement_1"; // T : Adresszusatz I
$rowToImport[20] = "f_ad_supplement_2"; // U : Adresszusatz II
$rowToImport[21] = "f_tr_person"; // V : Ansprechpartner
$rowToImport[22] = "f_tr_phone"; // W : Telefon
$rowToImport[23] = "f_special_02"; // X : Mobiltelefonnummer
$rowToImport[24] = "f_special_03"; // Y : Emailadresse
$rowToImport[25] = "f_tr_remark"; // Z : Bemerkung / Zustellinfo
$rowToImport[26] = "f_id"; // AA: Sendungsidentifikationsnummer
$rowToImport[27] = "f_trat_packingpieces"; // AB: Packstücke
$rowToImport[28] = "f_trat_palets"; // AC: Paletten
$rowToImport[29] = "f_trat_weight"; // AD: Gewicht
$rowToImport[30] = "f_special_04"; // AE: Stellplätze
$rowToImport[31] = "f_special_05"; // AF: Warenart
$rowToImport[32] = "f_zone_no"; // AG: Zone
$rowToImport[33] = "f_special_06"; // AH: Inkasso/Rückführung
$rowToImport[34] = "f_price_type"; // AI: Preistyp
$rowToImport[35] = "f_service_type"; // AJ: Leistungstyp
$rowToImport[36] = "f_dummy_01"; // AK: DUMMY_01
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_tour_no = mcStrWrap($f_tour_no); // Tournr. / Tourbezeichnung
$f_shipment_mode = mcStrWrap($f_shipment_mode); // Lieferung/Abholung
$f_tr_ware_from_to = 0;
if ($f_shipment_mode == "R") :
$f_tr_ware_from_to = 1;
elseif ($f_shipment_mode == "L") :
$f_tr_ware_from_to = 2;
endif;
$f_tr_orderdate = mcStrWrap($f_tr_orderdate); // Ausführungsdatum / Ausführungszeitstempel
$f_tr_warningdate = mcStrWrap($f_tr_warningdate); // Zustellungsdatum
$f_tr_starttime = mcStrWrap($f_tr_starttime); // Zustellung von
$f_tr_endtime = mcStrWrap($f_tr_endtime); // Zustellung bis
$f_tr_commission_no = mcStrWrap($f_tr_commission_no); // Lieferscheinnummer
$f_order_id = mcStrWrap($f_order_id); // Kundenauftragsnummer
$f_cs_id_external = mcStrWrap($f_cs_id_external); // Kundennummer extern / Lieferantennummer
$f_cs_eid = mcStrWrap($f_cs_eid); // Kundenummer (votian)
$f_tr_comp = mcStrWrap($f_tr_comp); // Firma
$f_tr_comp2 = mcStrWrap($f_tr_comp2); // Firma Zusatz
$f_special_01 = mcStrWrap($f_special_01); // Besteller
$f_ad_street = mcStrWrap($f_ad_street); // Straße
$f_tr_hsno = mcStrWrap($f_tr_hsno); // Hausnummer
if ($f_tr_hsno == "") : $f_tr_hsno = "."; endif;
$f_tr_floor = mcStrWrap($f_tr_floor); // Etage
$f_ad_zipcode = mcStrWrap($f_ad_zipcode); // PLZ
$f_ad_city = mcStrWrap($f_ad_city); // Ort
$f_ad_country = mcStrWrap($f_ad_country); // Land
if ($f_ad_country == "" || $f_ad_country == "D") : $f_ad_country = "DE"; endif;
$f_ad_supplement_1 = mcStrWrap($f_ad_supplement_1); // Adresszusatz I
$f_ad_supplement_2 = mcStrWrap($f_ad_supplement_2); // Adresszusatz II
$f_tr_person = mcStrWrap($f_tr_person); // Ansprechpartner
$f_tr_phone = mcStrWrap($f_tr_phone); // Telefon
$f_special_02 = mcStrWrap($f_special_02); // Mobiltelefonnummer
$f_special_03 = mcStrWrap($f_special_03); // Emailadresse
$f_tr_remark = mcStrWrap($f_tr_remark); // Bemerkung / Zustellinfo
$f_id = mcStrWrap($f_id); // Sendungsidentifikationsnummer
$f_trat_packingpieces = mcStrWrap($f_trat_packingpieces); // Packstücke
$f_trat_palets = mcStrWrap($f_trat_palets); // Paletten
$f_trat_weight = mcStrWrap($f_trat_weight); // Gewicht
$f_trat_weight = str_replace (",", ".", $f_trat_weight);
$f_special_04 = mcStrWrap($f_special_04); // Stellplätze
$f_special_05 = mcStrWrap($f_special_05); // Warenart
$f_zone_no = mcStrWrap($f_zone_no); // Zone
$f_special_06 = mcStrWrap($f_special_06); // Inkasso/Rückführung
$f_price_type = mcStrWrap($f_price_type); // Preistyp
$f_service_type = mcStrWrap($f_service_type); // Leistungstyp
$f_dummy_01 = mcStrWrap($f_dummy_01);
if ($f_special_01 != "") : $f_tr_remark .= "\n<br>" . getLngt("Besteller") . ": " . $f_special_01; endif;
if ($f_tr_starttime != "") : $f_tr_remark .= "\n<br>" . getLngt("Zustellung von") . ": " . $f_tr_starttime; endif;
if ($f_tr_endtime != "") : $f_tr_remark .= "\n<br>" . getLngt("Zustellung bis") . ": " . $f_tr_endtime; endif;
if ($f_special_02 != "") : $f_tr_remark .= "\n<br>" . getLngt("Mobiltelefonnummer") . ": " . $f_special_02; endif;
if ($f_special_03 != "") : $f_tr_remark .= "\n<br>" . getLngt("Emailadresse") . ": " . $f_special_03; endif;
if ($f_id != "") : $f_tr_remark .= "\n<br>" . getLngt("Sendungs-ID") . ": " . $f_id; endif;
if ($f_trat_packingpieces != "") : $f_tr_remark .= "\n<br>" . getLngt("Packstücke") . ": " . $f_trat_packingpieces; endif;
if ($f_trat_palets != "") : $f_tr_remark .= "\n<br>" . getLngt("Paletten") . ": " . $f_trat_palets; endif;
if ($f_trat_weight != "") : $f_tr_remark .= "\n<br>" . getLngt("Gewicht") . ": " . $f_trat_weight; endif;
if ($f_special_04 != "") : $f_tr_remark .= "\n<br>" . getLngt("Stellplätze") . ": " . $f_special_04; endif;
if ($f_special_05 != "") : $f_tr_remark .= "\n<br>" . getLngt("Warenart") . ": " . $f_special_05; endif;
if ($f_zone_no != "") : $f_tr_remark .= "\n<br>" . getLngt("Zone") . ": " . $f_zone_no; endif;
if ($f_special_06 != "") : $f_tr_remark .= "\n<br>" . getLngt("Inkasso/Rückführung") . ": " . $f_special_06; endif;
if ($f_price_type != "") : $f_tr_remark .= "\n<br>" . getLngt("Preistyp") . ": " . $f_price_type; endif;
if ($f_service_type != "") : $f_tr_remark .= "\n<br>" . getLngt("Leistungstyp") . ": " . $f_service_type; endif;
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_tour_no];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
*/
$crEid = $tourCourierArray[$f_tour_no];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
$crSid = $tourSIDArray[$f_tour_no];
endif;
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
// $jbStatus = "1"; // jb_status will be set after the whole job is generated
$jbTaketime = $currentTime;
$useJbNewArray = true;
endif;
$jbType = "2";
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo $f_id . ";" . $f_tour_no . ";" . $f_shipment_mode . ";" . $f_jb_orderdate . ";" . $f_jb_warningdate . ";" . $f_jb_starttime . ";" . $f_jb_endtime . ";";
echo $f_tr_commission_no . ";" . $f_order_id . ";" . $f_cs_id_external . ";" . $f_cs_eid . ";" . $f_tr_comp . ";" . $f_tr_comp2 . ";" . $f_special_01 . ";";
echo $f_tr_remark . ";" . $f_ad_street . ";" . $f_tr_hsno . ";" . $f_tr_floor . ";" . $f_ad_zipcode . ";" . $f_ad_city . ";" . ";" . $f_ad_country;
echo $f_ad_supplement_1 . ";" . $f_ad_supplement_2 . ";" . $f_tr_person . ";" . $f_tr_phone . ";" . $f_special_02 . ";" . $f_special_03 . ";" . ";" . $f_tr_remark;
echo $f_trat_packingpieces . ";" . $f_trat_palets . ";" . $f_trat_weight . ";" . $f_special_04 . ";" . $f_special_05 . ";";
echo $f_zone_no . ";" . $f_special_06 . ";" . $f_price_type . ";" . $f_service_type . ";";
echo "<br>";
echo "----------------------------------------------------------------------------------------------------------------------------------------------<br>";
// Check for existence of the imported order number (for the same day ONLY)
$gdcEntryExists = false;
// if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","info_2","gdc_content",$f_tr_commission_no,"gdc_context","SERVONA"))) :
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_tr_commission_no . "_" . $currentDate,"gdc_context","SERVONA"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if SERVONA number does exist on the current day!!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$callInsertAddress = true;
if ($f_cs_eid != "") :
$csEndId = getFieldValueFromId("customer","cs_eid",$f_cs_eid,"cs_id");
if ($csEndId != "") :
$csEndAddress = getAddress($csEndId, "costcenteraddress");
$adIdCsEnd = $csEndAddress["id"];
if ($adIdCsEnd != "") :
$callInsertAddress = false;
endif;
$f_ad_street = $csEndAddress["street"];
$f_tr_hsno = $csEndAddress["hsno"];
$f_ad_zipcode = $csEndAddress["zipcode"];
$f_ad_city = $csEndAddress["city"];
$f_ad_country = $csEndAddress["country"];
if ($f_ad_country == "") :
$f_ad_country = "DE";
endif;
endif;
endif;
$noValidationOfAddress = true;
// Insert address
if ($callInsertAddress) :
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
endif;
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_tour_no) :
$jbIdNew = "";
// Start datetime
if ($f_tr_starttime == "") : $f_tr_starttime = "08:00"; endif;
$f_jb_ordertime = substr($f_tr_orderdate, 0,4) . "-" . substr($f_tr_orderdate, 4,2) . "-" . substr($f_tr_orderdate, 6,2) . " " . $f_tr_starttime . ":00";
// End datetime
$f_jb_warningtime = "";
if ($f_tr_endtime == "") : $f_tr_endtime = "18:00"; endif;
/*
if ($f_jb_warningdate != "") :
$f_jb_warningtime = substr($f_tr_warningdate, 0,4) . "-" . substr($f_tr_warningdate, 4,2) . "-" . substr($f_tr_warningdate, 6,2);
if ($f_tr_warningdate != "") :
$f_jb_warningtime .= " " . $f_tr_endtime . ":00";
endif;
endif;
*/
// Remove existing tourname
updateStmt("job","jb_tourname",$f_tour_no,array("jb_tourname",""), "jb_tourname = '" . $f_tour_no . "'");
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_tour_no,
"jb_finishtime", $jbFinishtime, "jb_warningtime", $f_jb_warningtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbIdNew = getLastInsertId();
$jobNewArray[] = $jbIdNew;
// Tour-Nr. "$f_tour_no"
insertStmt("genericdatacontainer", array("gdc_obj_type", "jb", "gdc_obj_id", $jbIdNew, "gdc_gen_fieldname", "tourname", "gdc_content", $f_tour_no, "gdc_context", "SERVONA"));
$trSort = 2; // Init for 2nd station equals first delivery !!!!
$tratSort = 1; // Init all serial numbers !!!!
$remTourNo = $f_tour_no;
endif;
// Check for inserted job
if ($jbIdNew != "") :
// Insert stations
if ($trSort == 2) :
$trStatus = "0";
$trFinishtime = "";
if ($pickUpStationFinishedByDefault) :
$trStatus = "1";
$trFinishtime = $currentTime;
endif;
// Insert pick up station during first iteration
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $adIdFrom, "tr_sort", "1", "tr_comp", $trCompFrom, "tr_comp2", "",
"tr_hsno", $trHsnoFrom, "tr_floor", $trFloorFrom, "csc_id", $cscIdPayer, "tr_status", $trStatus, "tr_finishtime", $trFinishtime,
"tr_commission_no", "", "tr_ware_from_to", $f_tr_ware_from_to,
"tr_person", "", "tr_phone", "", "tr_remark", ""));
$trIdPickUpNew = getLastInsertID();
// Init array für jb_tourdata
$jbTourdataZipcodeArray[$jbIdNew][] = $csAddress["zipcode"];
$jbTourdataCityArray[$jbIdNew][] = $csAddress["city"];
$jbTourdataCountryArray[$jbIdNew][] = $csAddress["country"];
endif;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "tr_floor", $f_tr_floor, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
$jbTourdataZipcodeArray[$jbIdNew][] = $f_ad_zipcode;
$jbTourdataCityArray[$jbIdNew][] = $f_ad_city;
$jbTourdataCountryArray[$jbIdNew][] = $f_ad_country;
// Insert tourservice data
// !!!! MIT tr_id !!!! insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// ****
// Special patch because of "bug" in function "mk_jb_invtext()"
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// ****
// Fremdauftragsnummer "$f_order_id"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_0", "gdc_content", $f_order_id, "gdc_context", "SERVONA"));
// Kundennummer "$f_cs_id_external"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_1", "gdc_content", $f_cs_id_external, "gdc_context", "SERVONA"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_cust_no", "gdc_content", $f_cs_id_external, "gdc_context", "SERVONA"));
// Lieferscheinnummer "$f_tr_commission_no"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_2", "gdc_content", $f_tr_commission_no, "gdc_context", "SERVONA"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_tr_commission_no . "_" . $currentDate, "gdc_context", "SERVONA"));
// Insert tourarticle data (delivery stations)
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
$trSort++;
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_order_id . "]<br>";
endif;
}
// Set generated jobs to status "taken"
$jobNewArrayLen = count($jobNewArray);
if ($jobNewArrayLen > 0) :
for ($i = 0; $i < $jobNewArrayLen; $i++) :
// jb_status
// updateStmt("job", "jb_id", $jobNewArray[$i], array("jb_status", "1"));
// jb_tourdata
$jbTourdata = implode(";", $jbTourdataZipcodeArray[$jobNewArray[$i]]) . "|" . implode(";", $jbTourdataCityArray[$jobNewArray[$i]]) . "|" . implode(";", $jbTourdataCountryArray[$jobNewArray[$i]]);
updateStmt("job", "jb_id", $jobNewArray[$i], array("jb_tourdata", $jbTourdata));
endfor;
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_SERVONA.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,115 @@
<?php
/*=======================================================================
*
* import_SOAP_HHA.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
include_once ("../import/import.php");
include_once ("../include/auth.inc.php");
// Execution-Time for script
set_time_limit(30000);
// Select user-type for mode of security check
$userType = getFieldValueFromId("user","usr_id",$usr_id,"usr_type");
$userTypeName = getUserTypeName($userType);
// Check authentication verifying emmployee an his/her costcenter- and customer-association
if ( !( authCheckHQ($hq_id,$usr_id,$emp_id) || authCheck($hq_id,$usr_id,$emp_id,$cscIdRoot,$customerId,$cscIdActual) ) || $userTypeName == "" ) :
die ("$PHP_SELF: Access denied!");
endif;
// Get the rights of the employee logged in and check the accessibility
// authCheckEmployeeRights($emp_id, "22", "1");
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act"));
if ($f_act == "executeImport") :
// Activate buffering
ob_start();
$path = getAbsoluteSystemPath();
// Call script to import service unit master data
writeToFile($mcDebugImportErrLogFile, "----------------------------------------------------------------------------------------------");
writeToFile($mcDebugImportErrLogFile, "[HQ_ID:" . $hq_id . "] " . " [USR_ID:" . $usr_id . "]");
writeToFile($mcDebugImportErrLogFile, "Import Stammdaten begonnen.");
echo "Import Stammdaten.<br>"; ob_flush(); flush();
$mcDebugImportErrLogFile = $path . "/log/soap_data_" . $hq_id . "_err.stdout+err";
$cmd = "php " . $path . "/import/soap.php acapella7890 " . $hq_id . " 1" . " > " . $mcDebugImportErrLogFile . " 2>&1 &";
system($cmd);
writeToFile($mcDebugImportErrLogFile, "Import Stammdaten beendet.");
// echo "Import Stammdaten beendet.<br>"; ob_flush(); flush();
sleep(2);
// Call script to import service unit status data
writeToFile($mcDebugImportErrLogFile, "----------------------------------------------------------------------------------------------");
writeToFile($mcDebugImportErrLogFile, "[HQ_ID:" . $hq_id . "] " . " [USR_ID:" . $usr_id . "]");
writeToFile($mcDebugImportErrLogFile, "Import Statusdaten begonnen.");
echo "Import Statusdaten.<br>";
$mcDebugImportErrLogFile = $path . "/log/soap_data_" . $hq_id . "_err.stdout+err";
$cmd = "php " . $path . "/import/soap.php acapella7890 " . $hq_id . " 0" . " > " . $mcDebugImportErrLogFile . " 2>&1 &";
system($cmd);
writeToFile($mcDebugImportErrLogFile, "Import Statusdaten beendet.");
// echo "Import Statusdaten beendet.<br>"; ob_flush(); flush();
// sleep(2);
echo "Neuaufbau der Tourenplanungsliste im Hintergrund.<br>"; ob_flush(); flush();
sleep(2);
// Deactivate buffering and flush data
ob_end_flush();
sleep(2);
else :
echo "Fehler, keine Verarbeitung!<br>";
endif;
echo $path . "/illt/servicejob.php?currentNavigationItem=serviceauftraege" . "<br>";
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
.navfixed {position:fixed; top:0px; background-color: #DDDDDD; width: 100%;}
.navlabel {width: 170px; height: 22px;}
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
function finishPage(f_act) {
document.forms[0].f_act.value = f_act;
document.forms[0].submit();
};
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function refreshOpener() {
opener.finishPage('');
// opener.location.href = "<?php echo $path ?>/illt/servicejob.php?currentNavigationItem=serviceauftraege";
sleep(5000);
window.close();
};
-->
</script>
</head>
<body onLoad="refreshOpener();">
</body>
</html>

View File

@@ -0,0 +1,713 @@
<?php
/*=======================================================================
*
* import_STANDARD_01.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Get special user types from parameter
$specialUserTypeIsLoggedIn = false;
$specialUserType = "";
$specialUserHqId = "";
$specialUserFTPServerList = "";
$specialUserDirSpecialForObjType = "";
$userTypesSpecialArray = getDatatransferSpecialUserData($userType);
if (count($userTypesSpecialArray) > 0) :
$specialUserTypeIsLoggedIn = true;
list($specialUserType, $specialUserHqId, $specialUserFTPServerList, $specialUserObjType, $specialUserObjId, $specialUserDirSpecialForObjType) = $userTypesSpecialArray;
if ($objType == $specialUserObjType && $objId == $specialUserObjType) :
$hqId = $specialUserHqId;
endif;
endif;
// Check for authentication access
$empHasAdminRights = false;
if (!$specialUserTypeIsLoggedIn) :
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csId = "";
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
$csAddress = array();
$adIdFrom = 0;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
// $csAddress = getAddress($csId, "customer");
$csAddress = getAddress($csId, "costcenteraddress");
$adIdFrom = $csAddress["id"];
$trHsnoFrom = $csAddress["hsno"];
if ($trHsnoFrom == "") : $trHsnoFrom = "."; endif;
$trCompFrom = $csAddress["comp"];
if ($trCompFrom == "") : $trCompFrom = "STANDARD_01"; endif;
$trFloorFrom = "";
// USE FOLLOWING FIX ADDRESS
// $adIdFrom = "220594"; // Invoice address
// $adIdFrom = "125964"; // Pick-up address
// $trHsnoFrom = "4";
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
$pickUpStationFinishedByDefault = true;
// Tourdata array
$jbTourdata = "";
$jbTourdataZipcodeArray = array();
$jbTourdataCityArray = array();
$jbTourdataCountryArray = array();
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
$tourVehicleArray = array();
/*
if ($hqId == "nnn") :
// NL X
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
....
elseif ($hqId == "mmm") :
// NL Y
endif;
*/
/*
BSP.:
TOUR_NO SID EID NAME FIRSTNAME
294501 E501  e8020201  Schmidt   Alexander  0176 62283533
294502 E502  e8020202  Brazinskas  Zilvinas  0152 55904274
294503 E503  e8020203  Orakov   Anton  0152 01985959
294504 E504  e8020204  Isaak   Alexander  0152 53172115
....
$tourCourierArray = array();
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
....
*/
$tourCourierArray = array();
/*
if ($hqId == "nnn") :
// NL X
$tourCourierArray["294590"] = "e8020401"; // stepenka 01
$tourCourierArray["294501"] = "e8020402"; // stepenka 02
$tourCourierArray["294502"] = "e8020403"; // stepenka 03
$tourCourierArray["294503"] = "e8020404"; // stepneka 04
....
elseif ($hqId == "mmm") :
// NL Y
endif;
// SID array (fix!)
$tourSIDArray = array();
if ($hqId == "107") :
// NL X
$tourSIDArray["294590"] = "E355";
$tourSIDArray["294501"] = "E356";
$tourSIDArray["294502"] = "E357";
$tourSIDArray["294503"] = "E358";
....
elseif ($hqId == "110") :
// NL Y
endif;
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
return $aStr;
}
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_STANDARD_01_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$jbIdNew = 0;
$trSort = 2; // Init for 2nd station equals first delivery !!!!
$tratSort = 1; // Init all serial numbers !!!!
$jobNewArray = array();
$useJbNewArray = false;
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_STANDARD_01_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
$rowToImport[0] = "f_tour_no"; // A : Tournr. / Tourbezeichnung
$rowToImport[1] = "f_shipment_mode"; // B : Lieferung/Abholung
$rowToImport[2] = "f_tr_orderdate"; // C : Ausführungsdatum / Ausführungszeitstempel
$rowToImport[3] = "f_tr_warningdate"; // D : Zustellungsdatum
$rowToImport[4] = "f_tr_starttime"; // E : Zustellung von
$rowToImport[5] = "f_tr_endtime"; // F : Zustellung bis
$rowToImport[6] = "f_tr_commission_no"; // G : Lieferscheinnummer
$rowToImport[7] = "f_order_id"; // H : Kundenauftragsnummer
$rowToImport[8] = "f_cs_id_external"; // I : Kundennummer extern / Lieferantennummer
$rowToImport[9] = "f_cs_eid"; // J : Kundenummer (EID,intern)
$rowToImport[10] = "f_tr_comp"; // K : Firma
$rowToImport[11] = "f_tr_comp2"; // L : Firma Zusatz
$rowToImport[12] = "f_special_01"; // M : Besteller
$rowToImport[13] = "f_ad_street"; // N : Straße
$rowToImport[14] = "f_tr_hsno"; // O : Hausnummer
$rowToImport[15] = "f_tr_floor"; // P : Etage
$rowToImport[16] = "f_ad_zipcode"; // Q : PLZ
$rowToImport[17] = "f_ad_city"; // R : Ort
$rowToImport[18] = "f_ad_country"; // S : Land
$rowToImport[19] = "f_ad_supplement_1"; // T : Adresszusatz I
$rowToImport[20] = "f_ad_supplement_2"; // U : Adresszusatz II
$rowToImport[21] = "f_tr_person"; // V : Ansprechpartner
$rowToImport[22] = "f_tr_phone"; // W : Telefon
$rowToImport[23] = "f_special_02"; // X : Mobiltelefonnummer
$rowToImport[24] = "f_special_03"; // Y : Emailadresse
$rowToImport[25] = "f_tr_remark"; // Z : Bemerkung / Zustellinfo
$rowToImport[26] = "f_id"; // AA: Sendungsidentifikationsnummer
$rowToImport[27] = "f_trat_packingpieces"; // AB: Packstücke
$rowToImport[28] = "f_trat_palets"; // AC: Paletten
$rowToImport[29] = "f_trat_weight"; // AD: Gewicht
$rowToImport[30] = "f_special_04"; // AE: Stellplätze
$rowToImport[31] = "f_special_05"; // AF: Warenart
$rowToImport[32] = "f_zone_no"; // AG: Zone
$rowToImport[33] = "f_special_06"; // AH: Inkasso/Rückführung
$rowToImport[34] = "f_price_type"; // AI: Preistyp
$rowToImport[35] = "f_service_type"; // AJ: Leistungstyp
$rowToImport[36] = "f_dummy_01"; // AK: DUMMY_01
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_tour_no = mcStrWrap($f_tour_no); // Tournr. / Tourbezeichnung
$f_shipment_mode = mcStrWrap($f_shipment_mode); // Lieferung/Abholung
$f_tr_ware_from_to = 0;
if ($f_shipment_mode == "R") :
$f_tr_ware_from_to = 1;
elseif ($f_shipment_mode == "L") :
$f_tr_ware_from_to = 2;
endif;
$f_tr_orderdate = mcStrWrap($f_tr_orderdate); // Ausführungsdatum / Ausführungszeitstempel
$f_tr_warningdate = mcStrWrap($f_tr_warningdate); // Zustellungsdatum
$f_tr_starttime = mcStrWrap($f_tr_starttime); // Zustellung von
$f_tr_endtime = mcStrWrap($f_tr_endtime); // Zustellung bis
$f_tr_commission_no = mcStrWrap($f_tr_commission_no); // Lieferscheinnummer
$f_order_id = mcStrWrap($f_order_id); // Kundenauftragsnummer
$f_cs_id_external = mcStrWrap($f_cs_id_external); // Kundennummer extern / Lieferantennummer
$f_cs_eid = mcStrWrap($f_cs_eid); // Kundenummer (votian)
$f_tr_comp = mcStrWrap($f_tr_comp); // Firma
$f_tr_comp2 = mcStrWrap($f_tr_comp2); // Firma Zusatz
$f_special_01 = mcStrWrap($f_special_01); // Besteller
$f_ad_street = mcStrWrap($f_ad_street); // Straße
$f_tr_hsno = mcStrWrap($f_tr_hsno); // Hausnummer
if ($f_tr_hsno == "") : $f_tr_hsno = "."; endif;
$f_tr_floor = mcStrWrap($f_tr_floor); // Etage
$f_ad_zipcode = mcStrWrap($f_ad_zipcode); // PLZ
$f_ad_city = mcStrWrap($f_ad_city); // Ort
$f_ad_country = mcStrWrap($f_ad_country); // Land
if ($f_ad_country == "" || $f_ad_country == "D") : $f_ad_country = "DE"; endif;
$f_ad_supplement_1 = mcStrWrap($f_ad_supplement_1); // Adresszusatz I
$f_ad_supplement_2 = mcStrWrap($f_ad_supplement_2); // Adresszusatz II
$f_tr_person = mcStrWrap($f_tr_person); // Ansprechpartner
$f_tr_phone = mcStrWrap($f_tr_phone); // Telefon
$f_special_02 = mcStrWrap($f_special_02); // Mobiltelefonnummer
$f_special_03 = mcStrWrap($f_special_03); // Emailadresse
$f_tr_remark = mcStrWrap($f_tr_remark); // Bemerkung / Zustellinfo
$f_id = mcStrWrap($f_id); // Sendungsidentifikationsnummer
$f_trat_packingpieces = mcStrWrap($f_trat_packingpieces); // Packstücke
$f_trat_palets = mcStrWrap($f_trat_palets); // Paletten
$f_trat_weight = mcStrWrap($f_trat_weight); // Gewicht
$f_trat_weight = str_replace (",", ".", $f_trat_weight);
$f_special_04 = mcStrWrap($f_special_04); // Stellplätze
$f_special_05 = mcStrWrap($f_special_05); // Warenart
$f_zone_no = mcStrWrap($f_zone_no); // Zone
$f_special_06 = mcStrWrap($f_special_06); // Inkasso/Rückführung
$f_price_type = mcStrWrap($f_price_type); // Preistyp
$f_service_type = mcStrWrap($f_service_type); // Leistungstyp
$f_dummy_01 = mcStrWrap($f_dummy_01);
if ($f_special_01 != "") : $f_tr_remark .= "\n<br>" . getLngt("Besteller") . ": " . $f_special_01; endif;
if ($f_special_02 != "") : $f_tr_remark .= "\n<br>" . getLngt("Mobiltelefonnummer") . ": " . $f_special_02; endif;
if ($f_special_03 != "") : $f_tr_remark .= "\n<br>" . getLngt("Emailadresse") . ": " . $f_special_03; endif;
if ($f_id != "") : $f_tr_remark .= "\n<br>" . getLngt("Sendungs-ID") . ": " . $f_id; endif;
if ($f_trat_packingpieces != "") : $f_tr_remark .= "\n<br>" . getLngt("Packstücke") . ": " . $f_trat_packingpieces; endif;
if ($f_trat_palets != "") : $f_tr_remark .= "\n<br>" . getLngt("Paletten") . ": " . $f_trat_palets; endif;
if ($f_trat_weight != "") : $f_tr_remark .= "\n<br>" . getLngt("Gewicht") . ": " . $f_trat_weight; endif;
if ($f_special_04 != "") : $f_tr_remark .= "\n<br>" . getLngt("Stellplätze") . ": " . $f_special_04; endif;
if ($f_special_05 != "") : $f_tr_remark .= "\n<br>" . getLngt("Warenart") . ": " . $f_special_05; endif;
if ($f_zone_no != "") : $f_tr_remark .= "\n<br>" . getLngt("Zone") . ": " . $f_zone_no; endif;
if ($f_special_06 != "") : $f_tr_remark .= "\n<br>" . getLngt("Inkasso/Rückführung") . ": " . $f_special_06; endif;
if ($f_price_type != "") : $f_tr_remark .= "\n<br>" . getLngt("Preistyp") . ": " . $f_price_type; endif;
if ($f_service_type != "") : $f_tr_remark .= "\n<br>" . getLngt("Leistungstyp") . ": " . $f_service_type; endif;
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_tour_no];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
*/
$crEid = $tourCourierArray[$f_tour_no];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
$crSid = $tourSIDArray[$f_tour_no];
endif;
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
// $jbStatus = "1"; // jb_status will be set after the whole job is generated
$jbTaketime = $currentTime;
$useJbNewArray = true;
endif;
$jbType = "";
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo $f_id . ";" . $f_tour_no . ";" . $f_shipment_mode . ";" . $f_jb_orderdate . ";" . $f_jb_warningdate . ";" . $f_jb_starttime . ";" . $f_jb_endtime . ";";
echo $f_tr_commission_no . ";" . $f_order_id . ";" . $f_cs_id_external . ";" . $f_cs_eid . ";" . $f_tr_comp . ";" . $f_tr_comp2 . ";" . $f_special_01 . ";";
echo $f_tr_remark . ";" . $f_ad_street . ";" . $f_tr_hsno . ";" . $f_tr_floor . ";" . $f_ad_zipcode . ";" . $f_ad_city . ";" . ";" . $f_ad_country;
echo $f_ad_supplement_1 . ";" . $f_ad_supplement_2 . ";" . $f_tr_person . ";" . $f_tr_phone . ";" . $f_special_02 . ";" . $f_special_03 . ";" . ";" . $f_tr_remark;
echo $f_trat_packingpieces . ";" . $f_trat_palets . ";" . $f_trat_weight . ";" . $f_special_04 . ";" . $f_special_05 . ";";
echo $f_zone_no . ";" . $f_special_06 . ";" . $f_price_type . ";" . $f_service_type . ";";
echo "<br>";
echo "----------------------------------------------------------------------------------------------------------------------------------------------<br>";
// Check for existence of the imported order number (for the same day ONLY)
$gdcEntryExists = false;
// if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","info_2","gdc_content",$f_tr_commission_no,"gdc_context","STANDARD_01"))) :
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_tr_commission_no . "_" . $currentDate,"gdc_context","STANDARD_01"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if STANDARD_01 number does exist on the current day!!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$callInsertAddress = true;
if ($f_cs_eid != "") :
$csEndId = getFieldValueFromId("customer","cs_eid",$f_cs_eid,"cs_id");
if ($csEndId != "") :
$csEndAddress = getAddress($csEndId, "costcenteraddress");
$adIdCsEnd = $csEndAddress["id"];
if ($adIdCsEnd != "") :
$callInsertAddress = false;
endif;
$f_ad_street = $csEndAddress["street"];
$f_tr_hsno = $csEndAddress["hsno"];
$f_ad_zipcode = $csEndAddress["zipcode"];
$f_ad_city = $csEndAddress["city"];
$f_ad_country = $csEndAddress["country"];
if ($f_ad_country == "") :
$f_ad_country = "DE";
endif;
endif;
endif;
$noValidationOfAddress = true;
// Insert address
if ($callInsertAddress) :
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
endif;
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_tour_no) :
$jbIdNew = "";
// Start datetime
if ($f_tr_starttime == "") : $f_tr_starttime = "08:00"; endif;
$f_jb_ordertime = substr($f_tr_orderdate, 0,4) . "-" . substr($f_tr_orderdate, 4,2) . "-" . substr($f_tr_orderdate, 6,2) . " " . $f_tr_starttime . ":00";
// End datetime
$f_jb_warningtime = "";
if ($f_tr_endtime == "") : $f_tr_endtime = "18:00"; endif;
/*
if ($f_jb_warningdate != "") :
$f_jb_warningtime = substr($f_tr_warningdate, 0,4) . "-" . substr($f_tr_warningdate, 4,2) . "-" . substr($f_tr_warningdate, 6,2);
if ($f_tr_warningdate != "") :
$f_jb_warningtime .= " " . $f_tr_endtime . ":00";
endif;
endif;
*/
// Remove existing tourname
updateStmt("job","jb_tourname",$f_tour_no,array("jb_tourname",""), "jb_tourname = '" . $f_tour_no . "'");
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_tour_no,
"jb_finishtime", $jbFinishtime, "jb_warningtime", $f_jb_warningtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbIdNew = getLastInsertId();
$jobNewArray[] = $jbIdNew;
// Tour-Nr. "$f_tour_no"
insertStmt("genericdatacontainer", array("gdc_obj_type", "jb", "gdc_obj_id", $jbIdNew, "gdc_gen_fieldname", "tourname", "gdc_content", $f_tour_no, "gdc_context", "STANDARD_01"));
$trSort = 2; // Init for 2nd station equals first delivery !!!!
$tratSort = 1; // Init all serial numbers !!!!
$remTourNo = $f_tour_no;
endif;
// Check for inserted job
if ($jbIdNew != "") :
// Insert stations
if ($trSort == 2) :
$trStatus = "0";
$trFinishtime = "";
if ($pickUpStationFinishedByDefault) :
$trStatus = "1";
$trFinishtime = $currentTime;
endif;
// Insert pick up station during first iteration
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $adIdFrom, "tr_sort", "1", "tr_comp", $trCompFrom, "tr_comp2", "",
"tr_hsno", $trHsnoFrom, "tr_floor", $trFloorFrom, "csc_id", $cscIdPayer, "tr_status", $trStatus, "tr_finishtime", $trFinishtime,
"tr_commission_no", "", "tr_ware_from_to", $f_tr_ware_from_to,
"tr_person", "", "tr_phone", "", "tr_remark", ""));
$trIdPickUpNew = getLastInsertID();
// Init array für jb_tourdata
$jbTourdataZipcodeArray[$jbIdNew][] = $csAddress["zipcode"];
$jbTourdataCityArray[$jbIdNew][] = $csAddress["city"];
$jbTourdataCountryArray[$jbIdNew][] = $csAddress["country"];
endif;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "tr_floor", $f_tr_floor, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
$jbTourdataZipcodeArray[$jbIdNew][] = $f_ad_zipcode;
$jbTourdataCityArray[$jbIdNew][] = $f_ad_city;
$jbTourdataCountryArray[$jbIdNew][] = $f_ad_country;
// Insert tourservice data
// !!!! MIT tr_id !!!! insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// ****
// Special patch because of "bug" in function "mk_jb_invtext()"
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// ****
// Fremdauftragsnummer "$f_order_id"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_0", "gdc_content", $f_order_id, "gdc_context", "STANDARD_01"));
// Kundennummer "$f_cs_id_external"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_1", "gdc_content", $f_cs_id_external, "gdc_context", "STANDARD_01"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_cust_no", "gdc_content", $f_cs_id_external, "gdc_context", "STANDARD_01"));
// Lieferscheinnummer "$f_tr_commission_no"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_2", "gdc_content", $f_tr_commission_no, "gdc_context", "STANDARD_01"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_tr_commission_no . "_" . $currentDate, "gdc_context", "STANDARD_01"));
// Insert tourarticle data (delivery stations)
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
$trSort++;
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_order_id . "]<br>";
endif;
}
// Set generated jobs to status "taken"
$jobNewArrayLen = count($jobNewArray);
if ($jobNewArrayLen > 0) :
for ($i = 0; $i < $jobNewArrayLen; $i++) :
// jb_status
// updateStmt("job", "jb_id", $jobNewArray[$i], array("jb_status", "1"));
// jb_tourdata
$jbTourdata = implode(";", $jbTourdataZipcodeArray[$jobNewArray[$i]]) . "|" . implode(";", $jbTourdataCityArray[$jobNewArray[$i]]) . "|" . implode(";", $jbTourdataCountryArray[$jobNewArray[$i]]);
updateStmt("job", "jb_id", $jobNewArray[$i], array("jb_tourdata", $jbTourdata));
endfor;
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_STANDARD_01.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,603 @@
<?php
/*=======================================================================
*
* import_STANDARD_02.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/caglobal.inc.php"); // For pricing and invoice-text only
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
include_once ("../include/services_func.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Get special user types from parameter
$specialUserTypeIsLoggedIn = false;
$specialUserType = "";
$specialUserHqId = "";
$specialUserFTPServerList = "";
$specialUserDirSpecialForObjType = "";
$userTypesSpecialArray = getDatatransferSpecialUserData($userType);
if (count($userTypesSpecialArray) > 0) :
$specialUserTypeIsLoggedIn = true;
list($specialUserType, $specialUserHqId, $specialUserFTPServerList, $specialUserObjType, $specialUserObjId, $specialUserDirSpecialForObjType) = $userTypesSpecialArray;
if ($objType == $specialUserObjType && $objId == $specialUserObjType) :
$hqId = $specialUserHqId;
endif;
endif;
// Check for authentication access
$empHasAdminRights = false;
if (!$specialUserTypeIsLoggedIn) :
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$currentYear = getDateTime("year");
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csId = "";
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
$csAddress = array();
$adIdFrom = 0;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
$csAddress = getAddress($csId, "customer");
// $csAddress = getAddress($csId, "costcenteraddress");
$adIdFrom = $csAddress["id"];
$trHsnoFrom = $csAddress["hsno"];
if ($trHsnoFrom == "") : $trHsnoFrom = "."; endif;
$trCompFrom = $csAddress["comp"];
if ($trCompFrom == "") : $trCompFrom = "STANDARD_02"; endif;
$trFloorFrom = "";
// USE FOLLOWING FIX ADDRESS
// $adIdFrom = "220594"; // Invoice address
// $adIdFrom = "125964"; // Pick-up address
// $trHsnoFrom = "4";
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
$pickUpStationFinishedByDefault = true;
// Tourdata array
$jbTourdata = "";
$jbTourdataZipcodeArray = array();
$jbTourdataCityArray = array();
$jbTourdataCountryArray = array();
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
$tourVehicleArray = array();
/*
if ($hqId == "nnn") :
// NL X
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
....
elseif ($hqId == "mmm") :
// NL Y
endif;
*/
/*
BSP.:
TOUR_NO SID EID NAME FIRSTNAME
294501 E501  e8020201  Schmidt   Alexander  0176 62283533
294502 E502  e8020202  Brazinskas  Zilvinas  0152 55904274
294503 E503  e8020203  Orakov   Anton  0152 01985959
294504 E504  e8020204  Isaak   Alexander  0152 53172115
....
$tourCourierArray = array();
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
....
*/
$tourCourierArray = array();
/*
if ($hqId == "nnn") :
// NL X
$tourCourierArray["294590"] = "e8020401"; // stepenka 01
$tourCourierArray["294501"] = "e8020402"; // stepenka 02
$tourCourierArray["294502"] = "e8020403"; // stepenka 03
$tourCourierArray["294503"] = "e8020404"; // stepneka 04
....
elseif ($hqId == "mmm") :
// NL Y
endif;
// SID array (fix!)
$tourSIDArray = array();
if ($hqId == "107") :
// NL X
$tourSIDArray["294590"] = "E355";
$tourSIDArray["294501"] = "E356";
$tourSIDArray["294502"] = "E357";
$tourSIDArray["294503"] = "E358";
....
elseif ($hqId == "110") :
// NL Y
endif;
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
return $aStr;
}
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_STANDARD_02_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$jbIdNew = 0;
$trSort = 2; // Init for 2nd station equals first delivery !!!!
$tratSort = 1; // Init all serial numbers !!!!
$jobNewArray = array();
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_STANDARD_02_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
/*
Lfd Datum Auftrag / Tourenverlauf Betrag Fahrzeug
1; 10.03.2016; JIS: Magna Bremen-Daimler Bremen Bordero: 6410-0001; 75,94; HB048
2; 11.03.2016; JIS: Magna Bremen-Daimler Bremen Bordero: 6410-0002; 75,94; HB048
3; 12.03.2016; JIS: Magna Bremen-Daimler Bremen Bordero: 6410-0003; 75,94; HB048
4; 13.03.2016; JIS: Magna Bremen-Daimler Bremen Bordero: 6410-0004; 75,94; HB048
*/
$rowToImport[0] = "f_lfd"; // A : LFD
$rowToImport[1] = "f_tr_orderdate"; // B : Datum (Auftragszeit UND Erledigungszeit)
$rowToImport[2] = "f_inv_text"; // C : Rechnungstext (Auftrag/Tourenverlauf)
$rowToImport[3] = "f_inv_reference"; // D : Kostenstelle/Referenz
$rowToImport[4] = "f_jb_totalprice"; // E : Preis (Betrag)
$rowToImport[5] = "f_crvh_sid"; // F : Fahrzeug
$rowToImport[6] = "f_dummy"; // G : DUMMY
// $rowToImport[6] = "f_discount"; // F : Rabatt
// $rowToImport[7] = "f_markup"; // G : Zuschlag
// $rowToImport[8] = "f_dummy_01"; // H : DUMMY
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 1; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_lfd = mcStrWrap($f_lfd);
$f_tr_orderdate = mcStrWrap($f_tr_orderdate);
$f_inv_text = mcStrWrap($f_inv_text);
$f_inv_reference = mcStrWrap($f_inv_reference);
$f_jb_totalprice = mcStrWrap($f_jb_totalprice);
$crSid = mcStrWrap($f_crvh_sid);
$f_discount = mcStrWrap($f_discount);
$f_markup = mcStrWrap($f_markup);
// if ($f_special_01 != "") : $f_tr_remark .= "\n<br>" . getLngt("Besteller") . ": " . $f_special_01; endif;
// if ($f_special_02 != "") : $f_tr_remark .= "\n<br>" . getLngt("Mobiltelefonnummer") . ": " . $f_special_02; endif;
// Set vehicle and courier
$crId = "";
$vhtId = "";
$doContinue = false;
if ($crSid != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_sid",$crSid,"cr_id");
$vhtId = getFieldValueFromId("couriervehicle", "crvh_sid", $crSid, "vht_id");
if ($crId != "" && is_numeric($crId)) :
$doContinue = true;
endif;
endif;
if ($doContinue) :
$jbStatus = "2";
$jbOrdertime = substr($f_tr_orderdate,6,4) . "-" . substr($f_tr_orderdate,3,2) . "-" . substr($f_tr_orderdate,0,2) . " 08:00:00";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
$jbTaketime = $jbOrdertime;
endif;
$f_jb_totalprice = str_replace (",", ".", $f_jb_totalprice);
// $f_discount = str_replace (",", ".", $f_discount);
if ($f_discount != "1") :
$f_discount = "0";
endif;
// $f_markup = str_replace (",", ".", $f_markup);
if ($f_markup != "1") :
$f_markup = "0";
endif;
$jbType = "";
$jbFinishtime = $jbOrdertime;
$jbFreetext1 = $f_inv_text . " " . $f_inv_reference;
// $jbFreetext1 = $f_inv_reference;
$trCommissionNo = $f_inv_reference;
$txValue = "4";
$txSign = "V";
$price = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
if (is_numeric($f_jb_totalprice)) :
$price = $f_jb_totalprice;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
else :
$doContinue = false;
endif;
endif;
echo $f_lfd . ";" . $f_tr_orderdate . ";" . $f_tr_starttime . ";" . $f_inv_text . ";" . $f_inv_reference . ";" . $f_jb_totalprice . ";" . $f_crvh_sid . ";";
// echo $f_discount . ";" . $f_markup . ";";
echo ";<br>";
echo "--------------------------------------------------------------------------------------------------------------------------------------------------<br>";
// Insert job
if ($doContinue && $executeImportProcess == "1") :
// Check for existence of the imported order number (for the same day ONLY)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","jb","gdc_gen_fieldname","check_exist","gdc_content",$currentYear . "_" . $f_inv_reference,"gdc_context","STANDARD_02"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if STANDARD_02 number does exist on the current day!!!!
if (!$gdcEntryExists) :
// Check debug mode
if ($fire) :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
// Postage
$cmpId = getFieldValueFromId("customer", "cs_id", $csId, "cmp_id");
$cmpPostage = getFieldValueFromId("company", "cmp_id", $cmpId, "cmp_postage");
if ($cmpPostage == "" || !is_numeric($cmpPostage)) :
$cmpPostage = 0;
endif;
$csInvmode = getFieldValueFromId("customer", "cs_id", $csId, "cs_invmode");
// Check for customer provision, amount to be stored in "jb_cr_price"
$csProv = 0;
// $useCsProvEnabled = getParameterValue("0", "JB_EDITBATCH_CS_PROV_ENABLED", "0");
$useCsProvEnabled = "1";
if ($useCsProvEnabled == "1") :
$csProv = getFieldValueFromId("customer", "cs_id", $csId, "cs_prov");
if ($csProv == "" || $csProv == 0) :
$csProv = getParameterValue("0", "MASK_CS_PROV_DEFAULT", $hq_id);
$csProv = str_replace (",", ".", $csProv);
if ($csProv == "") :
$csProv = 0;
endif;
endif;
endif;
// Check for absolute customer discount (ATTENTION: Parameter means DISABLED !!!) and check for markup
$csDiscountAbsolute = "0";
$csMarkupFlag = "0";
if ($csId != "") :
// Discount
$csDiscountAbsolute = getFieldValueFromId("customer", "cs_id", $csId, "cs_discount");
// Markup
$csMarkupFlag = getFieldValueFromId("customer", "cs_id", $csId, "cs_markup");
endif;
$csDiscount = "0";
if ($csDiscountAbsolute != 0 && $f_discount == "1") :
$csDiscount = $csDiscountAbsolute;
endif;
$csMarkup = "0";
if ($csMarkupFlag == "1" && $f_markup == "1") :
$csMarkup = "1";
endif;
// Check prices because one of them has to be set only (!!!)
if ($price == "") : $price = 0; endif;
if ($price2 == "") : $price2 = 0; endif;
// Fixprice without markup and without customer discount
$fixPrice = $price;
// Service price
$servicePrice = $price2;
// Compute markup
$subTotalPrice = $price; // Price without markup
$tmpSrvt = $db->getOne("SELECT mt_value FROM metatype WHERE mt_sort = '" . $vhtId . "' AND mt_type= 'vehicletype'");
$final_markup = getFuelMarkup($tmpSrvt, $csId, $hqId, $jbFinishtime);
if ($f_markup == "0" && $final_markup > 0) :
$final_markup = 0;
endif;
// New price containing markup
if ($final_markup > 0) :
$price *= (1 + ($final_markup / 100));
endif;
// Price with markup but without customer discount
$trsPrice = $price;
// Check for absolute customer discount
if ($csDiscountAbsolute > 0) :
$price = ($price * ((100 - $csDiscount) / 100));
$subTotalPrice = ($subTotalPrice * ((100 - $csDiscount) / 100));
endif;
// Courier price
$jbCrPrice = 0;
if (is_numeric($csProv) && $csProv > 0) :
$jbCrPrice = ($price * ((100 - $csProv) / 100));
endif;
// Total price and subtotal price containing the service price
$subTotalPrice = $subTotalPrice + $servicePrice;
$totalPrice = $price + $servicePrice;
insertStmt("job", array("hq_id", $hqId, "vht_id", $vhtId, "vht_id_real", $vhtId, "csc_id_payer", $cscIdPayer, "jb_payment", "0",
"jb_ordertime", $jbOrdertime, "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_taketime", $jbFinishtime, "jb_status", "2", "jb_autoranking", "0", "jb_type", $jbType,
"jb_finishtime", $jbFinishtime, "emp_id", $usrId, "jb_fixprice", $fixPrice, "jb_serviceprice", $servicePrice, "jb_totalprice", $totalPrice, "jb_cr_price", $jbCrPrice,
"jb_subtotalprice", $subTotalPrice, "jb_markup", $final_markup, "jb_postage", $cmpPostage, "jb_invmode", $csInvmode, "jb_freetext_1", $jbFreetext1,
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign,
"jb_automailsent", "997", "jb_booktime", $currentTime));
$jbIdNew = getLastInsertId();
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $adIdFrom, "tr_sort", "1", "tr_comp", my_str_check($trCompFrom), "tr_comp2", "",
"tr_hsno", $trHsnoFrom, "csc_id", $cscIdPayer, "tr_status", "1", "tr_signname", "Listenbuchung",
"tr_finishtime", $jbFinishtime, "tr_commission_no", $trCommissionNo));
if ($trsPrice != 0) :
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", "0",
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $trsPrice, "trs_discount", $csDiscount));
endif;
if ($servicePrice != 0) :
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", "0",
"srv_id", "0", "trs_srv_name", "Servicepreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $servicePrice, "trs_discount", "0"));
endif;
insertStmt("genericdatacontainer", array("gdc_obj_type", "jb", "gdc_obj_id", $jbIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $currentYear . "_" . $f_inv_reference, "gdc_context", "STANDARD_02"));
// Write logdata into log database
writeToLogDB("1",$hq_id,$jbIdNew,$usrId,$crId,$crSid,"","");
// Generate invoice text
mk_jb_invtext($jbIdNew, false);
$executionCount++;
TA("C");
TA("E");
endif;
else :
if ($executeImportProcess == "1") :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_inv_reference . "]<br>";
endif;
endif;
else :
if ($executeImportProcess == "1") :
$outText .= getLngt("Der Datensatz wurde nicht importiert! Die Vorlagedaten sind nicht vollständig!") . " [" . $f_inv_reference . "]<br>";
endif;
endif;
}
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_STANDARD_02.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

592
html/import/import_TIMS.php Normal file
View File

@@ -0,0 +1,592 @@
<?php
/*=======================================================================
*
* import_TIMS.php [Tims Kanadische Backwaren]
*
* Autor: Marc Vollmann
*
=======================================================================*/
/*
- Variation von "TOURS" (Beschreibung siehe "import_TOURS.php")
- Startzeit von 09 auf 06 Uhr
*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
// Init
$jbIdNew = "";
$jbTourdata = "";
$jbTourdataZipcode = "";
$jbTourdataCity = "";
$jbTourdataCountry = "";
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strrpos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
/*
$tourVehicleArray = array();
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
*/
$tourCourierArray = array();
/*
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
$tourCourierArray["294505"] = "e8020205";
$tourCourierArray["294506"] = "e8020206";
$tourCourierArray["294507"] = "e8020207";
$tourCourierArray["294508"] = "e8020208";
$tourCourierArray["294509"] = "e8020209";
$tourCourierArray["294510"] = "e8020210";
$tourCourierArray["294511"] = "e8020211";
$tourCourierArray["294512"] = "e8020212";
$tourCourierArray["294590"] = "e8020213";
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
return $aStr;
}
echo "importFile" . $importFile . "<br>";
echo "hqId" . $hqId . "<br>";
echo "csId" . $csId . "<br>";
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_TIMS_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$jbIdNew = 0;
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_TOURS_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
$rowToImport[0] = "f_no_row"; // A : (Laufende) Nr. (Datensatz)
$rowToImport[1] = "f_jb_tourname"; // B : Auftrag Bezeichnung (Tourname)
$rowToImport[2] = "f_tr_commission_no"; // C : Station Kommissionsnummer
$rowToImport[3] = "f_tr_comp"; // D : Station Bezeichnung
$rowToImport[4] = "f_tr_remark"; // E : Station Bemerkung
$rowToImport[5] = "f_tr_sort"; // F : Station Position in Tour
$rowToImport[6] = "f_ad_zipcode"; // G : Station PLZ
$rowToImport[7] = "f_ad_city"; // H : Station Ort
$rowToImport[8] = "f_ad_street"; // I : Station Straße
$rowToImport[9] = "f_tr_hsno"; // J : Station Hausnummer
$rowToImport[10] = "f_tr_arrival_time"; // K : Station Ankunft
$rowToImport[11] = "f_tr_departure_time"; // L : Station Abfahrt
$rowToImport[12] = "f_tr_point2point_time"; // M : Station Strecke
$rowToImport[13] = "f_tr_point2point_min"; // N : Auftrag Fixe Dauer
$rowToImport[14] = "f_dummy_01"; // O : ?
endif;
// Special handling
$parFieldCmpComp = getParameterValue("0", "IMPORT_TOURS_FIELD_TR_COMP", $hqId);
if ($parFieldCmpComp == "") : $parFieldCmpComp = getParameterValue("0", "IMPORT_TOURS_FIELD_TR_COMP", "0"); endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_no_row = mcStrWrap($f_no_row);
$f_jb_tourname = mcStrWrap($f_jb_tourname);
$f_tr_commission_no = mcStrWrap($f_tr_commission_no);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_tr_remark = mcStrWrap($f_tr_remark);
$f_tr_sort = mcStrWrap($f_tr_sort);
$f_ad_zipcode = mcStrWrap($f_ad_zipcode);
$f_ad_city = mcStrWrap($f_ad_city);
$f_ad_street = mcStrWrap($f_ad_street);
$f_tr_hsno = mcStrWrap($f_tr_hsno);
$f_tr_arrival_time = mcStrWrap($f_tr_arrival_time);
$f_tr_departure_time = mcStrWrap($f_tr_departure_time);
$f_tr_point2point_time = mcStrWrap($f_tr_point2point_time);
$f_tr_point2point_min = mcStrWrap($f_tr_point2point_min);
// Check for existing headline
if ($j > 0 || ($f_no_row != "" && is_numeric($f_no_row))) :
if ($parFieldCmpComp == "0") :
$tmpArray = spliti("_", $f_tr_comp);
// Do nothing
elseif ($parFieldCmpComp == "1") :
$tmpArray = spliti("__", $f_tr_comp); // Two underline chars as delimiter
$f_tr_person = $tmpArray[1];
$f_tr_comp = $tmpArray[0];
else :
// Default
$tmpArray = spliti("_", $f_tr_comp);
$f_tr_person = $tmpArray[0];
endif;
$tmpArray = spliti("_", $f_tr_remark);
$f_tr_phone = $tmpArray[2];
$f_tr_phone = str_replace ("Tel:", "", $f_tr_phone);
$f_tr_phone = eregPhoneNo($f_tr_phone);
if ($f_tr_hsno == "") :
$f_tr_hsno = ".";
endif;
if ($f_tr_arrival_time != "") :
$f_tr_remark .= "\n\nAnkunft: " . $f_tr_arrival_time;
endif;
if ($f_tr_departure_time != "") :
$f_tr_remark .= "\n\nAbfahrt" . $f_tr_departure_time;
endif;
// $f_tr_remark .= $f_tr_point2point_time
// $f_tr_remark .= $f_tr_point2point_min
// Move commission number to station remark
if ($f_tr_commission_no != "") :
$f_tr_remark .= "\n\n[*" . $f_tr_commission_no . "*]";
$f_tr_commission_no = "";
endif;
// Clock time depends on headquarters
$clockTime = "06:00:00";
/*
if ($hqId == "3") :
$clockTime = "12:45:00";
endif;
*/
if ($f_jb_tourname != "") :
$f_jb_orderdate = substr($f_jb_tourname, -8);
$f_jb_ordertime = "20" . substr($f_jb_orderdate,6,2) . "-" . substr($f_jb_orderdate,2,2) . "-" . substr($f_jb_orderdate,0,2) . " " . $clockTime;
endif;
// The first row of the tour contains the tour name. The following rows of the same tour are empty for $f_jb_tourname !!!!
if ($f_jb_tourname == "") :
$f_jb_tourname = $remTourNo;
endif;
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_jb_tourname];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
*/
$crEid = $tourCourierArray[$f_jb_tourname];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
endif;
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
$jbStatus = "1";
$jbTaketime = $currentTime;
endif;
$jbType = "";
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo $f_no_row . ";" . $f_jb_tourname . ";" . $f_tr_commission_no . ";" . $f_tr_comp . ";" . $f_tr_remark . ";" . $f_tr_sort . ";" . $f_ad_zipcode . ";";
echo $f_ad_city . ";" . $f_ad_street . ";" . $f_tr_hsno;
// echo ";" . $f_tr_arrival_time . ";" . $f_tr_departure_time . ";" . $f_tr_point2point_time . ";";
// echo $f_tr_point2point_min . ";" . $f_tr_person . ";" . $f_tr_phone . ";" . $f_jb_ordertime;
echo "<br>";
// Check for existence of the imported "tour name" AND "station number" (unique for station)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_jb_tourname . " " . $f_tr_sort,"gdc_context","TIMS"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if TOURS number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = true;
if ($remTourNo == "" || $remTourNo == $f_jb_tourname) :
if ($jbTourdataZipcode != "") : $jbTourdataZipcode .= ";"; endif;
$jbTourdataZipcode .= $f_ad_zipcode;
if ($jbTourdataCity != "") : $jbTourdataCity .= ";"; endif;
$jbTourdataCity .= $f_ad_city;
if ($jbTourdataCountry != "") : $jbTourdataCountry .= ";"; endif;
$jbTourdataCountry .= "DE";
endif;
// Insert address
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_jb_tourname) :
// Finalize currently imported job
// Write "jb_tourdata" of the job currently imported
if ($remTourNo != "" && $jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// Remove existing tourname
updateStmt("job","jb_tourname",$f_jb_tourname,array("jb_tourname",""), "jb_tourname = '" . $f_jb_tourname . "'");
// Tour data
/*
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
*/
$jbIdNew = ""; // Init
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbIdNew = getLastInsertId();
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$remTourNo = $f_jb_tourname;
// Init for the next job to be imported
$jbTourdata = "";
// Init with current values
$jbTourdataZipcode = $f_ad_zipcode;
$jbTourdataCity = $f_ad_city;
$jbTourdataCountry = "DE";
endif;
// Check for inserted job
if ($jbIdNew != "") :
$trSort++;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
// Insert tourservice data
/*
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
*/
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort, "srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "", "trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// Tourname
// insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_0", "gdc_content", $f_jb_tourname . " " . $f_tr_sort, "gdc_context", "TIMS"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_jb_tourname . " " . $f_tr_sort, "gdc_context", "TIMS"));
// Insert tourarticle data (delivery stations)
/*
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
*/
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
/*
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
*/
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_jb_tourname . " " . $f_tr_sort . "]<br>";
endif;
endif; // Check for headline
}
// If at least onne imported job does exist ($jbIdNew > 0) then finalize last imported job
// Write "jb_tourdata" of the job currently imported
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_TIMS.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

810
html/import/import_TOOM.php Normal file
View File

@@ -0,0 +1,810 @@
<?php
/*=======================================================================
*
* import_TOOM.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/services_func.inc.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// include_once ("../include/inc_parseXML.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
// Writes a string to a file optional with or without linefeed
function writeToLogFile($fileName, $stringToOperate, $mode = 'a', $noLf = "") {
$fileHandle = fopen($fileName, $mode);
if ($noLf == "") : $stringToOperate .= "\n"; endif;
$opCode = fwrite($fileHandle, $stringToOperate);
fclose($fileHandle);
return $opCode;
}
$logFilename = "import_toom.log";
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$currentShortDate = getDateTime(1);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
// Init
$jbIdNew = "";
$jbTourdata = "";
$jbTourdataZipcode = "";
$jbTourdataCity = "";
$jbTourdataCountry = "";
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strrpos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
/*
$tourVehicleArray = array();
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
*/
$tourCourierArray = array();
/*
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
$tourCourierArray["294505"] = "e8020205";
$tourCourierArray["294506"] = "e8020206";
$tourCourierArray["294507"] = "e8020207";
$tourCourierArray["294508"] = "e8020208";
$tourCourierArray["294509"] = "e8020209";
$tourCourierArray["294510"] = "e8020210";
$tourCourierArray["294511"] = "e8020211";
$tourCourierArray["294512"] = "e8020212";
$tourCourierArray["294590"] = "e8020213";
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
/*
$aStr = utf8_decode($aStr);
$aStr = str_replace("\"", '', $aStr);
$aStr = str_replace("ß", "ß", $aStr);
$aStr = str_replace("ä", "ä", $aStr);
$aStr = str_replace("ö", "ö", $aStr);
$aStr = str_replace("ü", "ü", $aStr);
$aStr = str_replace("Ä", "Ä", $aStr);
$aStr = str_replace("Ö", "Ö", $aStr);
$aStr = str_replace("Ü", "Ü", $aStr);
*/
return $aStr;
}
echo "importFile" . $importFile . "<br>";
echo "hqId" . $hqId . "<br>";
echo "csId" . $csId . "<br>";
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// Get meta customer of the current customer
$csIdParent = getFieldValueFromId("customer","cs_id",$csId,"cs_id_parent");
$hqIdCsParent = getFieldValueFromId("customer","cs_id",$csIdParent,"hq_id");
// The filename contains the execution day !!!!
$tmpJbOrdertime = substr($filename,-12,8);
$jbOrdertime = substr($tmpJbOrdertime,0,4) . "-" . substr($tmpJbOrdertime,4,2) . "-" . substr($tmpJbOrdertime,6,2) . " 08:00:00";
// echo $jbOrdertime . "<br>";
// $jbOrdertime = checkDateTimeFormat($jbOrdertime); // DISABLED BECAUSE OF PHP VERSION ONLY !!! ACTIVATE AFTER MIGRATION !!!
$checkGmtdatetimeIsValid = strtotime($jbOrdertime);
// echo $checkGmtdatetimeIsValid . "<br>";
if ($checkGmtdatetimeIsValid != "" && is_int($checkGmtdatetimeIsValid)):
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_TOOM_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$jbIdNew = 0;
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
// Array für Preis-/Leistungstypnamen
$jbCalcNameArr = array();
// $jbCalcNameArr["vht"] = array("LKW 1 To.", "Kran");
$jbCalcNameArr["sz"] = "Spätzustellung";
$jbCalcNameArr["fu"] = "Uhrzeit";
$jbCalcNameArr["sdd"] = "same-day";
$jbCalcNameArr["1mh"] = "Verwendungsstelle";
$jbCalcNameArr["2mh"] = "2-Mann";
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_TOOM_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
/*
Nr. Tour Bezeichnung Tourelement Bezeichnung Auftrag Bemerkungen Tourelement Position in Tour Tourelement PLZ Tourelement Ort Tourelement Straße Tourelement Hausnummer Tourelement Ankunft Tourelement Abfahrt Tourelement Strecke Auftrag Fixe Dauer
*/
$rowToImport[0] = "f_jb_tourname"; // A : Tour (v = vormittags, n = nachmittags)
$rowToImport[1] = "f_tr_sort"; // B : Lfd der Station
$rowToImport[2] = "f_tr_commission_no"; // C : Belegnummer
$rowToImport[3] = "f_tr_comp"; // D : Kunde / Frima
$rowToImport[4] = "f_ad_data"; // E : Adresse
$rowToImport[5] = "f_tr_phone"; // F : Telefon
$rowToImport[6] = "f_tr_mobile"; // G : Mobil
$rowToImport[7] = "f_tr_remark"; // H : Wareninfo
$rowToImport[8] = "f_palettes"; // I : Anzahl Paletten
$rowToImport[9] = "f_tr_remark2"; // J : Weitere Bemerkungen
$rowToImport[10] = "f_tr_remark3"; // K : Zusatz-Leistungen
// $rowToImport[11] = "f_jb_calculator"; // L : Calculator-Vektoren
// $rowToImport[12] = "f_dummy_01"; // M : ?
$rowToImport[11] = "f_vht_type"; // L : Fahrzeugtyp (1 = Kran, ansonsten "Default LKW")
$rowToImport[12] = "f_jb_calc_sz"; // M : Calculator.Spätzustellung (1 = JA, ansonsten NEIN)
$rowToImport[13] = "f_jb_calc_fu"; // N : Calculator.FixeUhrzeit (Format "H:i")
$rowToImport[14] = "f_jb_calc_sdd"; // O : Calculator.SameDayDelivery (1 = JA, ansonsten NEIN)
$rowToImport[15] = "f_jb_calc_mh"; // P : Calculator.(1|2)-MannHandling
$rowToImport[16] = "f_dummy_01"; // Q : ?
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_jb_tourname = mcStrWrap($f_jb_tourname);
$f_daytime = "";
if ($f_jb_tourname != "") :
$f_daytime = "Zeitfenster: " . $f_jb_tourname;
endif;
if (strtolower($f_jb_tourname) == "v") :
$f_jb_tourname = "Vormittagstour";
endif;
if (strtolower($f_jb_tourname) == "n") :
$f_jb_tourname = "Nachmittagstour";
endif;
$f_jb_tourname = "TOOM";
$f_tr_sort = mcStrWrap($f_tr_sort);
$f_tr_commission_no = mcStrWrap($f_tr_commission_no);
// Check for existing headline
if ($j > 0 && ($f_tr_sort != "" && is_numeric($f_tr_sort)) && $f_tr_commission_no != "") :
$tmpArray = spliti(":", $f_tr_commission_no);
$tmpRemark = $tmpArray[1];
$tmpRemark = trim($tmpRemark);
$f_tr_commission_no = $tmpArray[0];
$f_tr_commission_no = trim($f_tr_commission_no);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_tr_person = $f_tr_comp;
$f_ad_data = mcStrWrap($f_ad_data);
$tmpArray = spliti(",", $f_ad_data);
$f_ad_street = $tmpArray[0];
if ($f_tr_hsno == "") :
$f_tr_hsno = ".";
endif;
$tmpArray[1] = str_replace ("D -", "", $tmpArray[1]);
$tmpArray[1] = str_replace ("D-", "", $tmpArray[1]);
$tmpArray[1] = trim($tmpArray[1]);
if (!is_numeric(substr($tmpArray[1],0,1))) :
$pos = strpos("-",$tmpArray[1]);
if ($pos === false) : $pos = 0; endif;
$f_ad_zipcode = substr($tmpArray[1],0,($pos + 1)) . "-" . preg_replace('/[^0-9]/', '', $tmpArray[1]);
$f_ad_city = preg_replace('/[^a-zäöü]/i', '', substr($tmpArray[1],1)); // Without first char (being the letter for the country)
else :
$f_ad_zipcode = preg_replace('/[^0-9]/', '', $tmpArray[1]);
$f_ad_zipcode = substr(trim($f_ad_zipcode),0,5);
$f_ad_city = preg_replace('/[^a-zäöü]/i', '', $tmpArray[1]);
endif;
$f_ad_city = trim($f_ad_city);
$f_tr_phone = trim($f_tr_phone);
if ($f_tr_phone != "") :
$f_tr_phone = mcStrWrap($f_tr_phone);
$f_tr_phone = eregPhoneNo($f_tr_phone);
endif;
$f_tr_mobile = trim($f_tr_mobile);
if ($f_tr_mobile != "") :
$f_tr_mobile = mcStrWrap($f_tr_mobile);
$f_tr_mobile = eregPhoneNo($f_tr_mobile);
endif;
$f_tr_remark = mcStrWrap($f_tr_remark);
$f_palettes = mcStrWrap($f_palettes);
$f_tr_remark2 = mcStrWrap($f_tr_remark2);
$f_tr_remark3 = mcStrWrap($f_tr_remark3);
$f_tr_remark = $tmpRemark . ",\n" . $f_tr_remark . ",\n" . $f_tr_remark2 . ",\n" . $f_palettes . ",\n" . $f_tr_remark3;
if ($f_daytime != "") :
$f_tr_remark .= ",\n" . $f_daytime;
endif;
if ($f_tr_phone == "") :
$f_tr_phone = $f_tr_mobile;
else :
if ($f_tr_mobile != "") :
$f_tr_remark .= ",\n" . $f_tr_mobile;
endif;
endif;
// $f_jb_calculator = mcStrWrap($f_jb_calculator);
$f_jb_calc_sz = mcStrWrap($f_jb_calc_sz);
$f_jb_calc_fu = mcStrWrap($f_jb_calc_fu);
$f_jb_calc_sdd = mcStrWrap($f_jb_calc_sdd);
$f_jb_calc_mh = mcStrWrap($f_jb_calc_mh);
/*
3142 40512 IWV 30 km-Radius 2016-09-26 16:07:13
3141 40512 IWV 20 km-Radius 2016-09-26 16:06:45
3140 40512 IWV 10 km-Radius 2016-09-26 16:06:16
3139 40512 Wartezeit / 30 Min. 2016-09-26 16:05:47
3138 40512 Kran Mindestabrechnung 2016-09-26 15:59:34
3137 40512 Kran Mehrstunde 2016-09-26 16:00:10
3135 40512 same-day delivery 2016-09-26 13:42:22
3134 40512 Fixe Uhrzeit 2016-09-26 13:41:41
3133 40512 Spätzustellung >17:00 Uhr 2016-09-26 13:41:20
3132 40512 2-Mann-Handling / 30 Min. 2016-09-26 13:40:40
3131 40512 Frei Verwendungsstelle / 30 Min. 2016-09-26 13:39:56
3130 40512 Mehrkilometer 2016-09-26 13:37:13
3129 40512 30 km-Radius 2016-09-26 13:37:03
3128 40512 20 km-Radius 2016-09-26 13:36:56
3127 40512 10 km-Radius 2016-09-26 13:36:47
*/
$f_jb_calc_arr = array();
if ($f_jb_calc_sz == "1") :
$f_jb_calc_arr[] = "sz";
endif;
if ($f_jb_calc_fu != "") :
// Get start hour an start minute from fixed time
$tmpHour = substr($f_jb_calc_fu, 0, 2);
$tmpMinute = substr($f_jb_calc_fu, 3, 2);
if (is_numeric($tmpHour) && is_numeric($tmpMinute) && $tmpHour >= 0 && $tmpHour <= 23 && $tmpHour >= 0 && $tmpHour <= 59) :
$f_jb_calc_arr[] = "fu";
$jbOrdertime = substr($jbOrdertime, 0, 10) . " " . pad($tmpHour, 2) . ":" . pad($tmpMinute, 2) . ":" . "00";
endif;
endif;
if ($f_jb_calc_sdd == "1") :
$f_jb_calc_arr[] = "sdd";
endif;
if ($f_jb_calc_mh == "1") :
$f_jb_calc_arr[] = "1mh";
elseif ($f_jb_calc_mh == "2") :
$f_jb_calc_arr[] = "2mh";
endif;
$f_vht_type = mcStrWrap($f_vht_type);
$vhtId = "70";
$jbCalcNameArr["vht"] = "Fzg.";
if ($f_vht_type == "1") :
$vhtId = "990";
$jbCalcNameArr["vht"] = "Kran";
endif;
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_jb_tourname];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
$crEid = $tourCourierArray[$f_jb_tourname];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
endif;
*/
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
$jbStatus = "1";
$jbTaketime = $currentTime;
endif;
$jbType = "2";
$jbFinishtime = "";
$jbRemark = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
/*
echo $f_jb_tourname . ";" . $f_tr_sort . ";" . $f_tr_commission_no . ";";
echo $f_ad_street . ";" . $f_ad_zipcode . ";" . $f_ad_city . ";";
echo $f_tr_phone . ";" . $f_tr_mobile . ";" . $f_tr_remark;
echo "<br>";
*/
echo "------------------------------------------------------<br>";
echo "f_jb_tourname: " . $f_jb_tourname . "<br>";
echo "f_tr_sort: " . $f_tr_sort . "<br>";
echo "f_tr_commission_no: " . $f_tr_commission_no . "<br>";
echo "f_ad_street: " . $f_ad_street . "<br>";
echo "f_ad_zipcode: " . $f_ad_zipcode . "<br>";
echo "f_ad_city: " . $f_ad_city . "<br>";
echo "f_tr_phone: " . $f_tr_phone . "<br>";
echo "f_tr_mobile: " . $f_tr_mobile . "<br>";
echo "f_tr_remark: " . $f_tr_remark . "<br>";
// Check for existence of the imported "tour name" AND "station number" (unique for station)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_tr_commission_no . " " . $f_tr_sort . " " . $currentShortDate,"gdc_context","TOOM"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if TOOM number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = true;
if ($remTourNo == "" || $remTourNo == $f_jb_tourname) :
if ($jbTourdataZipcode != "") : $jbTourdataZipcode .= ";"; endif;
$jbTourdataZipcode .= $f_ad_zipcode;
if ($jbTourdataCity != "") : $jbTourdataCity .= ";"; endif;
$jbTourdataCity .= $f_ad_city;
if ($jbTourdataCountry != "") : $jbTourdataCountry .= ";"; endif;
$jbTourdataCountry .= "DE";
endif;
// Insert address
if ($f_ad_street == "" || $f_ad_zipcode == "" || $f_ad_city == "") :
$noValidationOfAddress = "1";
endif;
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_jb_tourname) :
// Finalize currently imported job
// Write "jb_tourdata" of the job currently imported
if ($remTourNo != "" && $jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// Remove existing tourname
updateStmt("job","jb_tourname",$f_jb_tourname,array("jb_tourname",""), "jb_tourname = '" . $f_jb_tourname . "'");
// Tour data
/*
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
*/
$jbIdNew = ""; // Init
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $jbOrdertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_createtime", $currentTime, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbIdNew = getLastInsertId();
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$remTourNo = $f_jb_tourname;
// Init for the next job to be imported
$jbTourdata = "";
// Init with current values
$jbTourdataZipcode = $f_ad_zipcode;
$jbTourdataCity = $f_ad_city;
$jbTourdataCountry = "DE";
endif;
// Check for inserted job
if ($jbIdNew != "") :
$trSort++;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
// Insert tourservice data
/*
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
*/
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort, "srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "", "trs_price", $sum_totalprice));
// Positions
// insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "trat_sum_volume", "gdc_content", $f_palettes, "gdc_context", "TOOM"));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// Tourname
// insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_0", "gdc_content", $f_tr_commission_no . " " . $f_tr_sort . " " . $currentShortDate, "gdc_context", "TOOM"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_tr_commission_no . " " . $f_tr_sort . " " . $currentShortDate, "gdc_context", "TOOM"));
// Services
$strServices = "SZ=" . $f_jb_calc_sz . "|" . "FU=" . $f_jb_calc_fu . "|" . "SDD=" . $f_jb_calc_sdd . "|" . "MH=" . $f_jb_calc_mh;
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "services", "gdc_content", $strServices, "gdc_context", "TOOM"));
// Insert tourarticle data (delivery stations)
/*
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
*/
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
/*
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
*/
// Insert jobcalculator data
/*
if ($f_jb_calculator != "") :
$f_jb_calculator = str_replace("|", "-,-", $f_jb_calculator);
$trCalcItemArray = spliti("§§", $f_jb_calculator);
$numOfCalcItems = count($trCalcItemArray);
if ($numOfCalcItems > 0) :
for ($k = 0; $k < $numOfCalcItems; $k++) :
$jbCalcArray = spliti("-,-", $trCalcItemArray[$k]);
// Get srv_id and srvt_id, both has to exist (!!!!)
$tmpSrvId = getFieldValueFromClause("service","srv_id","srv_mode = '1' AND cs_id = '" . $csId . "' AND srv_name = '" . $jbCalcArray[0] . "'");
$tmpSrvtId = getFieldValueFromClause("servicetype","srvt_id","srvt_mode = '1' AND cs_id = '" . $csId . "' AND srvt_name = '" . $jbCalcArray[1] . "'");
if ($tmpSrvId == "" || $tmpSrvId == "0" || $tmpSrvtId == "" || $tmpSrvtId == "0") :
$tmpSrvId = getFieldValueFromClause("service","srv_id","srv_mode = '1' AND cs_id = '" . $csIdParent . "' AND srv_name = '" . $jbCalcArray[0] . "'");
$tmpSrvtId = getFieldValueFromClause("servicetype","srvt_id","srvt_mode = '1' AND cs_id = '" . $csIdParent . "' AND srvt_name = '" . $jbCalcArray[1] . "'");
endif;
if ($tmpSrvId != "" && $tmpSrvtId != "") :
// Get price from service matrix
$jbCalcPrice = getServiceValues($tmpSrvId, $tmpSrvtId, $csId, $hqId, $currentTime, 1);
if ($jbCalcPrice == "" || $jbCalcPrice == "0") :
// Try to get price from meta customer
$jbCalcPrice = getServiceValues($tmpSrvId, $tmpSrvtId, $csIdParent, $hqIdCsParent, $currentTime, 1);
// If price empty or "0" then take price from request
// if ($jbCalcPrice == "" || $jbCalcPrice == "0") :
// $jbCalcPrice = $trCalcItemArray[$i][$j]["price"];
// endif;
endif;
insertStmt("jobcalculator", array("jb_id", $jbIdNew, "tr_id", $trIdNew, "tr_sort", $trSort, "srv_id", $tmpSrvId, "srv_name", $trCalcItemArray[$i][$k]["pricetype"],
"srvt_id", $tmpSrvtId, "srvt_name", $trCalcItemArray[$i][$k]["servicetype"],
"jbc_amount", $trCalcItemArray[$i][$k]["quantity"], "jbc_price", $jbCalcPrice,
"jbc_totalprice", ($trCalcItemArray[$i][$k]["quantity"] * $jbCalcPrice)));
endif;
endfor;
endif;
endif;
*/
// writeToLogFile($logFilename, "0 :: CS_CSPARENT_JB_TR :: " . $csId . " " . $csIdParent . " " . $jbIdNew . " " . $trIdNew);
// writeToLogFile($logFilename, "1 :: CALC_ARRAY :: " . $f_jb_calc_arr[0] . " " . $f_jb_calc_arr[1] . " " . $f_jb_calc_arr[2] . " " . $f_jb_calc_arr[3] . " " . $f_jb_calc_arr[4]);
// $f_jb_calc_arr_keys = array_keys($f_jb_calc_arr);
// $f_jb_calc_arr_keys_len = count($f_jb_calc_arr_keys);
$f_jb_calc_arr_len = count($f_jb_calc_arr);
// writeToLogFile($logFilename, "2 :: CALC_ARRAY_LEN :: " . $f_jb_calc_arr_len);
// writeToLogFile($logFilename, "3 :: START ITER");
for ($k = 0; $k < $f_jb_calc_arr_len; $k++) :
$calcKey = $f_jb_calc_arr[$k]; // "sz", "fu", "sdd", "1mh", "2mh", ....
// writeToLogFile($logFilename, "3.a :: calcKey :: " . $calcKey);
// writeToLogFile($logFilename, "3.a2 :: cs.jbCalcNameArr[vht] :: " . $jbCalcNameArr["vht"]);
// writeToLogFile($logFilename, "3.a3 :: cs.jbCalcNameArr[$calcKey] :: " . $jbCalcNameArr[$calcKey]);
// Get srv_id and srvt_id, both has to exist (!!!!)
$csIdForServiceNames = $csId;
$tmpSrvId = getFieldValueFromClause("service","srv_id","srv_mode = '1' AND cs_id = '" . $csId . "' AND srv_name LIKE '%" . $jbCalcNameArr["vht"] . "%'");
// writeToLogFile($logFilename, "3.b :: cs.tmpSrvId :: " . $tmpSrvId);
$tmpSrvtId = getFieldValueFromClause("servicetype","srvt_id","srvt_mode = '1' AND cs_id = '" . $csId . "' AND srvt_name LIKE '%" . $jbCalcNameArr[$calcKey] . "%'");
// writeToLogFile($logFilename, "3.c :: cs.tmpSrvtId :: " . $tmpSrvtId);
if ($tmpSrvId == "" || $tmpSrvId == "0" || $tmpSrvtId == "" || $tmpSrvtId == "0") :
$csIdForServiceNames = $csIdParent;
$tmpSrvId = getFieldValueFromClause("service","srv_id","srv_mode = '1' AND cs_id = '" . $csIdParent . "' AND srv_name LIKE '%" . $jbCalcNameArr["vht"] . "%'");
// writeToLogFile($logFilename, "3.d :: cs_parent.tmpSrvId :: " . $tmpSrvId);
$tmpSrvtId = getFieldValueFromClause("servicetype","srvt_id","srvt_mode = '1' AND cs_id = '" . $csIdParent . "' AND srvt_name LIKE '%" . $jbCalcNameArr[$calcKey] . "%'");
// writeToLogFile($logFilename, "3.e :: cs_parent.tmpSrvtId :: " . $tmpSrvtId);
endif;
if ($tmpSrvId != "" && $tmpSrvtId != "") :
// writeToLogFile($logFilename, "3.f :: IDS OK!");
// Get full name of service and servicetype
$tmpSrvName = getFieldValueFromClause("service","srv_name","srv_mode = '1' AND cs_id = '" . $csIdForServiceNames . "' AND srv_id = '" . $tmpSrvId . "'");
// writeToLogFile($logFilename, "3.g :: tmpSrvName :: " . $tmpSrvName);
$tmpSrvtName = getFieldValueFromClause("servicetype","srvt_name","srvt_mode = '1' AND cs_id = '" . $csIdForServiceNames . "' AND srvt_id = '" . $tmpSrvtId . "'");
// writeToLogFile($logFilename, "3.h :: tmpSrvtName :: " . $tmpSrvtName);
// Get price from service matrix
// writeToLogFile($logFilename, "3.i :: BEFORE PRICE REQUEST!");
$jbCalcPrice = getServiceValues($tmpSrvId, $tmpSrvtId, $csId, $hqId, $currentTime, 1);
// writeToLogFile($logFilename, "3.j :: cs.jbCalcPrice :: " . $jbCalcPrice);
if ($jbCalcPrice == "" || $jbCalcPrice == "0") :
// Try to get price from meta customer
$jbCalcPrice = getServiceValues($tmpSrvId, $tmpSrvtId, $csIdParent, $hqIdCsParent, $currentTime, 1);
// writeToLogFile($logFilename, "3.k :: cs_parent.jbCalcPrice :: " . $jbCalcPrice);
// If price empty or "0" then take price from request
// if ($jbCalcPrice == "" || $jbCalcPrice == "0") :
// $jbCalcPrice = $trCalcItemArray[$i][$j]["price"];
// endif;
endif;
// writeToLogFile($logFilename, "3.l :: BEFORE INSERT!");
insertStmt("jobcalculator", array("jb_id", $jbIdNew, "tr_id", $trIdNew, "tr_sort", $trSort, "srv_id", $tmpSrvId, "srv_name", $tmpSrvName,
"srvt_id", $tmpSrvtId, "srvt_name", $tmpSrvtName, "jbc_amount", "1", "jbc_price", "0", "jbc_totalprice", "0"));
// writeToLogFile($logFilename, "3.l :: AFTER INSERT!");
endif;
endfor;
// writeToLogFile($logFilename, "3.z :: END ITER");
// writeToLogFile($logFilename, "----------------------------------------------------");
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_order_id . "]<br>";
endif;
endif; // Check for headline
}
// If at least onne imported job does exist ($jbIdNew > 0) then finalize last imported job
// Write "jb_tourdata" of the job currently imported
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Das Datum für den Ausführungstag im Dateinamen scheint nicht korrekt! Bitte folgendes Format für den Dateinamen verwenden: import_TOOM_YYYYMMDD.csv");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_TOOM.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,638 @@
<?php
/*=======================================================================
*
* import_TOURS.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
/*
Die zu importierende Datei MUSS IMMER den Präfix "import_TOURS_" UND die
Endung ".csv" aufweisen. Hinter dem Präfix kann irgend etwas individuelle
stehen. Die Schreibweise (Groß-/Kleinschreibung) bitte IMMER beachten!
Beispiel: "import_TOURS_Test_20190603.csv"
Über das Kundenstammblatt (oben rechts der Button "Dokumente") wird die
Dokumentenseite für den Kunden (<=> Bezahler der Tour) geöffnet.
Unten auf der linken Hälfte kann über den Button "Durchsuchen" die (lokale)
CSV-Datei ausgewählt und über den Button "Upload" anschließend hochgeladen
werden. Der Dateiname erscheint im Anschluss (nach dem Reload) auf der
linken Seite.
ACHTUNG: Der Dateiname wurde vorne um die Kundennummer (EID) automatisch erweitert!
Auf der rechten Seite wählt man den Eintrag "TOURS" (analog zum Dateinamensbestandteil
der CSV-Datei) aus. Auf der linken Seite wird entsprechend der Dateiname dann als
Link dargestellt. Wird dieser betätigt, wird eine weitere Seite für den Import geöffnet.
Diese schreibt den Dateiinhalt auf den Schirm, gefolgt von
Datensatzstruktur "import_TOURS_xxxx.csv"
Die folgende Aufstellung definiert die Reihenfolge der Felder (Spalten) der CSV-Datei:
- Lfd : Numerisch fortlaufend (1..n)
- Tourname/Tourkennung ggfs. mit Präfix (z.B. "T01_") und IMMER mit Datumssemantik,
also z.B. für den 01. Juni 2019 (z.B.) IMMER im Format "01062019" (TTMMJJJ) in
den hinteren 8 Zeichen. Das Format ist zwingend und die letzten 8 Zeichen ebenfalls.
Nachfolgende Stationen MÜSSEN dann identisch sein und denselben Tourennamen aufweisen!
Folgt eine Änderung in diesem Feld bei einem folgenden Datensatz (z.B."T02_01062019"),
dann beginnt ein neuer Auftrag, wobei dann für diesen die nachfolgenden Zellen der
wieder identisch sein müssen. Möchte man also nur einen Auftrag in der csv-Datei,
definiert man alle Zellen der 2. Spalte Datensatzes mit z.B. "Txx_01062019".
WICHTIG: Das angegebene Datum im Tourenname ist wichtig für den Ausführungstag!
Per default wird vorerst die Uhrzeit 09:00 Uhr eingetragen. Diese kann in der
Erfassung nach wunsch geändert werden.
- Optionale Kommissionsnummer der Station
Sollte dieses Feld leer gelasssen werden, würden zwei ";"-Zeichen in der Datei
direkt hintereinanderstehen.
Beispiel MIT : xxxx;KOM_01;yyyy
Beispiel OHNE: xxxx;;yyyy
- Firma/Kunde der Station
- Bemerkung (Fahrer) für die Station
- Kennung für Station, kann z.B. für jede Tour durchnummeriert werden ("Auftrags-Lfd.")
Wenn z.B. nur ein Auftrag, also nur eine Tour in der datei, dann entspräche z.B.
diese "Auftrags-Lfd." der Lfd. in der 1. Spalte.
- PLZ der Station
- Stadt der Station
- Strasse der Station
- Hausnr. der Station
Wenn diese leer ist, also z.B. in de Str. mit übergeben wird, dann wird
automatisch ein Punkt (".") hier eingetragen
- Erwartete Abfahrtszeit von der Station
Wird hier eine Zeit eingetragen, wird diese in die Stationsbemerkung geschrieben
- Beispiele:
[1]
-- DATEIANFANG --
1;T01_03062019;KOM_100000;Firma_1;Bemerkung_1;1;22525;Hamburg;Ottensener Str.;8;
2;T01_03062019;KOM_100001;Firma_2;Bemerkung_2;2;22525;Hamburg;Schnackenburgallee;157;
3;T02_04062019;KOM_100003;Firma_A;Bemerkung_A;1;22525;Hamburg;Schnackenburgallee;157;
4;T02_04062019;KOM_100004;Firma_B;Bemerkung_B;2;22525;Hamburg;Ottensener Str.;8;
-- DATEIENDE --
[2]
-- DATEIANFANG --
1;T01_03062019;KOM_100000;Firma_1;Bemerkung_1;1;22525;Hamburg;Ottensener Str.;8;
2;T01_03062019;KOM_100001;Firma_2;Bemerkung_2;2;22525;Hamburg;Schnackenburgallee;157;
3;T01_03062019;KOM_100002;Firma_3;Bemerkung_3;3;....
....
8;T02_04062019;KOM_100009;Firma_A;Bemerkung_1;1;22525;Hamburg;Ottensener Str.;8;
9;T02_04062019;KOM_100009;Firma_B;Bemerkung_2;2;22525;Hamburg;Schnackenburgallee;157;
10;T02_04062019;KOM_100010;Firma_C;Bemerkung_3;3;....
....
-- DATEIENDE --
*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
// Init
$jbIdNew = "";
$jbTourdata = "";
$jbTourdataZipcode = "";
$jbTourdataCity = "";
$jbTourdataCountry = "";
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strrpos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
/*
$tourVehicleArray = array();
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
*/
$tourCourierArray = array();
/*
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
$tourCourierArray["294505"] = "e8020205";
$tourCourierArray["294506"] = "e8020206";
$tourCourierArray["294507"] = "e8020207";
$tourCourierArray["294508"] = "e8020208";
$tourCourierArray["294509"] = "e8020209";
$tourCourierArray["294510"] = "e8020210";
$tourCourierArray["294511"] = "e8020211";
$tourCourierArray["294512"] = "e8020212";
$tourCourierArray["294590"] = "e8020213";
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
return $aStr;
}
echo "importFile" . $importFile . "<br>";
echo "hqId" . $hqId . "<br>";
echo "csId" . $csId . "<br>";
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_TOURS_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$jbIdNew = 0;
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_TOURS_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
$rowToImport[0] = "f_no_row"; // A : (Laufende) Nr. (Datensatz)
$rowToImport[1] = "f_jb_tourname"; // B : Auftrag Bezeichnung (Tourname)
$rowToImport[2] = "f_tr_commission_no"; // C : Station Kommissionsnummer
$rowToImport[3] = "f_tr_comp"; // D : Station Bezeichnung
$rowToImport[4] = "f_tr_remark"; // E : Station Bemerkung
$rowToImport[5] = "f_tr_sort"; // F : Station Position in Tour
$rowToImport[6] = "f_ad_zipcode"; // G : Station PLZ
$rowToImport[7] = "f_ad_city"; // H : Station Ort
$rowToImport[8] = "f_ad_street"; // I : Station Straße
$rowToImport[9] = "f_tr_hsno"; // J : Station Hausnummer
$rowToImport[10] = "f_tr_arrival_time"; // K : Station Ankunft
$rowToImport[11] = "f_tr_departure_time"; // L : Station Abfahrt
$rowToImport[12] = "f_tr_point2point_time"; // M : Station Strecke
$rowToImport[13] = "f_tr_point2point_min"; // N : Auftrag Fixe Dauer
$rowToImport[14] = "f_dummy_01"; // O : ?
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_no_row = mcStrWrap($f_no_row);
$f_jb_tourname = mcStrWrap($f_jb_tourname);
$f_tr_commission_no = mcStrWrap($f_tr_commission_no);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_tr_remark = mcStrWrap($f_tr_remark);
$f_tr_sort = mcStrWrap($f_tr_sort);
$f_ad_zipcode = mcStrWrap($f_ad_zipcode);
$f_ad_city = mcStrWrap($f_ad_city);
$f_ad_street = mcStrWrap($f_ad_street);
$f_tr_hsno = mcStrWrap($f_tr_hsno);
$f_tr_arrival_time = mcStrWrap($f_tr_arrival_time);
$f_tr_departure_time = mcStrWrap($f_tr_departure_time);
$f_tr_point2point_time = mcStrWrap($f_tr_point2point_time);
$f_tr_point2point_min = mcStrWrap($f_tr_point2point_min);
// Check for existing headline
if ($j > 0 || ($f_no_row != "" && is_numeric($f_no_row))) :
$tmpArray = spliti("_", $f_tr_comp);
$f_tr_person = $tmpArray[0];
$tmpArray = spliti("_", $f_tr_remark);
$f_tr_phone = $tmpArray[2];
$f_tr_phone = str_replace ("Tel:", "", $f_tr_phone);
$f_tr_phone = eregPhoneNo($f_tr_phone);
if ($f_tr_hsno == "") :
$f_tr_hsno = ".";
endif;
if ($f_tr_arrival_time != "") :
$f_tr_remark .= "\n\nAnkunft: " . $f_tr_arrival_time;
endif;
if ($f_tr_departure_time != "") :
$f_tr_remark .= "\n\nAbfahrt" . $f_tr_departure_time;
endif;
// $f_tr_remark .= $f_tr_point2point_time
// $f_tr_remark .= $f_tr_point2point_min
// Clock time depends on headquarters
$clockTime = "09:00:00";
/*
if ($hqId == "3") :
$clockTime = "12:45:00";
endif;
*/
if ($f_jb_tourname != "") :
$f_jb_orderdate = substr($f_jb_tourname, -8);
$f_jb_ordertime = "20" . substr($f_jb_orderdate,6,2) . "-" . substr($f_jb_orderdate,2,2) . "-" . substr($f_jb_orderdate,0,2) . " " . $clockTime;
endif;
// The first row of the tour contains the tour name. The following rows of the same tour are empty for $f_jb_tourname !!!!
if ($f_jb_tourname == "") :
$f_jb_tourname = $remTourNo;
endif;
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_jb_tourname];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
*/
$crEid = $tourCourierArray[$f_jb_tourname];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
endif;
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
$jbStatus = "1";
$jbTaketime = $currentTime;
endif;
$jbType = "";
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo $f_no_row . ";" . $f_jb_tourname . ";" . $f_tr_comp . ";" . $f_tr_remark . ";" . $f_tr_sort . ";" . $f_ad_zipcode . ";";
echo $f_ad_city . ";" . $f_ad_street . ";" . $f_tr_hsno . ";" . $f_tr_arrival_time . ";" . $f_tr_departure_time . ";" . $f_tr_point2point_time . ";";
echo $f_tr_point2point_min . ";" . $f_tr_person . ";" . $f_tr_phone . ";" . $f_jb_ordertime;
echo "<br>";
// Check for existence of the imported "tour name" AND "station number" (unique for station)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_jb_tourname . " " . $f_tr_sort,"gdc_context","TOURS"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if TOURS number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = true;
if ($remTourNo == "" || $remTourNo == $f_jb_tourname) :
if ($jbTourdataZipcode != "") : $jbTourdataZipcode .= ";"; endif;
$jbTourdataZipcode .= $f_ad_zipcode;
if ($jbTourdataCity != "") : $jbTourdataCity .= ";"; endif;
$jbTourdataCity .= $f_ad_city;
if ($jbTourdataCountry != "") : $jbTourdataCountry .= ";"; endif;
$jbTourdataCountry .= "DE";
endif;
// Insert address
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_jb_tourname) :
// Finalize currently imported job
// Write "jb_tourdata" of the job currently imported
if ($remTourNo != "" && $jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// Remove existing tourname
updateStmt("job","jb_tourname",$f_jb_tourname,array("jb_tourname",""), "jb_tourname = '" . $f_jb_tourname . "'");
// Tour data
/*
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
*/
$jbIdNew = ""; // Init
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbIdNew = getLastInsertId();
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$remTourNo = $f_jb_tourname;
// Init for the next job to be imported
$jbTourdata = "";
// Init with current values
$jbTourdataZipcode = $f_ad_zipcode;
$jbTourdataCity = $f_ad_city;
$jbTourdataCountry = "DE";
endif;
// Check for inserted job
if ($jbIdNew != "") :
$trSort++;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
// Insert tourservice data
/*
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
*/
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort, "srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "", "trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// Tourname
// insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_0", "gdc_content", $f_jb_tourname . " " . $f_tr_sort, "gdc_context", "TOURS"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_jb_tourname . " " . $f_tr_sort, "gdc_context", "TOURS"));
// Insert tourarticle data (delivery stations)
/*
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
*/
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
/*
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
*/
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_jb_tourname . " " . $f_tr_sort . "]<br>";
endif;
endif; // Check for headline
}
// If at least onne imported job does exist ($jbIdNew > 0) then finalize last imported job
// Write "jb_tourdata" of the job currently imported
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_TOURS.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,702 @@
<?php
/*=======================================================================
*
* import_UNIMET.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Get special user types from parameter
$specialUserTypeIsLoggedIn = false;
$specialUserType = "";
$specialUserHqId = "";
$specialUserFTPServerList = "";
$specialUserDirSpecialForObjType = "";
$userTypesSpecialArray = getDatatransferSpecialUserData($userType);
if (count($userTypesSpecialArray) > 0) :
$specialUserTypeIsLoggedIn = true;
list($specialUserType, $specialUserHqId, $specialUserFTPServerList, $specialUserObjType, $specialUserObjId, $specialUserDirSpecialForObjType) = $userTypesSpecialArray;
if ($objType == $specialUserObjType && $objId == $specialUserObjType) :
$hqId = $specialUserHqId;
endif;
endif;
// Check for authentication access
$empHasAdminRights = false;
if (!$specialUserTypeIsLoggedIn) :
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csId = "";
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
$csAddress = array();
$adIdFrom = 0;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
// $csAddress = getAddress($csId, "customer");
$csAddress = getAddress($csId, "costcenteraddress");
$adIdFrom = $csAddress["id"];
$trHsnoFrom = $csAddress["hsno"];
if ($trHsnoFrom == "") : $trHsnoFrom = "."; endif;
$trCompFrom = $csAddress["comp"];
if ($trCompFrom == "") : $trCompFrom = "UNIMET"; endif;
$trFloorFrom = "";
// USE FOLLOWING FIX ADDRESS
// $adIdFrom = "220594"; // Invoice address
// $adIdFrom = "125964"; // Pick-up address
// $trHsnoFrom = "4";
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
$pickUpStationFinishedByDefault = true;
// Tourdata array
$jbTourdata = "";
$jbTourdataZipcodeArray = array();
$jbTourdataCityArray = array();
$jbTourdataCountryArray = array();
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
$tourVehicleArray = array();
/*
if ($hqId == "nnn") :
// NL X
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
....
elseif ($hqId == "mmm") :
// NL Y
endif;
*/
/*
BSP.:
TOUR KARTE FAHRER-EID
SE1 89882390000018392582 h8042504
SE2 89882390000018392566 h8042503
SE3 89882390000018392541 h8042501
SE4 89882390000018392574 h8042502
SE5 89882390000018392590 h8042505
....
*/
$tourCourierArray = array();
$tourCourierArray["SE1"] = "h8042504";
$tourCourierArray["SE2"] = "h8042503";
$tourCourierArray["SE3"] = "h8042501";
$tourCourierArray["SE4"] = "h8042502";
$tourCourierArray["SE5"] = "h8042505";
$tourSIDArray = array();
/*
// SID array (fix!)
if ($hqId == "107") :
// NL X
$tourSIDArray["294590"] = "E355";
$tourSIDArray["294501"] = "E356";
$tourSIDArray["294502"] = "E357";
$tourSIDArray["294503"] = "E358";
....
elseif ($hqId == "110") :
// NL Y
endif;
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
return $aStr;
}
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_UNIMET_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$jbIdNew = 0;
$trSort = 2; // Init for 2nd station equals first delivery !!!!
$tratSort = 1; // Init all serial numbers !!!!
$jobNewArray = array();
$useJbNewArray = false;
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_UNIMET_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
$rowToImport[0] = "f_tour_no"; // A : Tournr. / Tourbezeichnung
$rowToImport[1] = "f_shipment_mode"; // B : Lieferung/Abholung
$rowToImport[2] = "f_tr_orderdate"; // C : Ausführungsdatum / Ausführungszeitstempel
$rowToImport[3] = "f_tr_warningdate"; // D : Zustellungsdatum
$rowToImport[4] = "f_tr_starttime"; // E : Zustellung von
$rowToImport[5] = "f_tr_endtime"; // F : Zustellung bis
$rowToImport[6] = "f_tr_commission_no"; // G : Lieferscheinnummer
$rowToImport[7] = "f_order_id"; // H : Kundenauftragsnummer
$rowToImport[8] = "f_cs_id_external"; // I : Kundennummer extern / Lieferantennummer
$rowToImport[9] = "f_cs_eid"; // J : Kundenummer (EID,intern)
$rowToImport[10] = "f_tr_comp"; // K : Firma
$rowToImport[11] = "f_tr_comp2"; // L : Firma Zusatz
$rowToImport[12] = "f_special_01"; // M : Besteller
$rowToImport[13] = "f_ad_street"; // N : Straße
$rowToImport[14] = "f_tr_hsno"; // O : Hausnummer
$rowToImport[15] = "f_tr_floor"; // P : Etage
$rowToImport[16] = "f_ad_zipcode"; // Q : PLZ
$rowToImport[17] = "f_ad_city"; // R : Ort
$rowToImport[18] = "f_ad_country"; // S : Land
$rowToImport[19] = "f_ad_supplement_1"; // T : Adresszusatz I
$rowToImport[20] = "f_ad_supplement_2"; // U : Adresszusatz II
$rowToImport[21] = "f_tr_person"; // V : Ansprechpartner
$rowToImport[22] = "f_tr_phone"; // W : Telefon
$rowToImport[23] = "f_special_02"; // X : Mobiltelefonnummer
$rowToImport[24] = "f_special_03"; // Y : Emailadresse
$rowToImport[25] = "f_tr_remark"; // Z : Bemerkung / Zustellinfo
$rowToImport[26] = "f_id"; // AA: Sendungsidentifikationsnummer
$rowToImport[27] = "f_trat_packingpieces"; // AB: Packstücke
$rowToImport[28] = "f_trat_palets"; // AC: Paletten
$rowToImport[29] = "f_trat_weight"; // AD: Gewicht
$rowToImport[30] = "f_special_04"; // AE: Stellplätze
$rowToImport[31] = "f_special_05"; // AF: Warenart
$rowToImport[32] = "f_zone_no"; // AG: Zone
$rowToImport[33] = "f_special_06"; // AH: Inkasso/Rückführung
$rowToImport[34] = "f_price_type"; // AI: Preistyp
$rowToImport[35] = "f_service_type"; // AJ: Leistungstyp
$rowToImport[36] = "f_dummy_01"; // AK: DUMMY_01
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_tour_no = mcStrWrap($f_tour_no); // Tournr. / Tourbezeichnung
$f_shipment_mode = mcStrWrap($f_shipment_mode); // Lieferung/Abholung
$f_tr_ware_from_to = 0;
if ($f_shipment_mode == "R") :
$f_tr_ware_from_to = 1;
elseif ($f_shipment_mode == "L") :
$f_tr_ware_from_to = 2;
endif;
$f_tr_orderdate = mcStrWrap($f_tr_orderdate); // Ausführungsdatum / Ausführungszeitstempel
$f_tr_warningdate = mcStrWrap($f_tr_warningdate); // Zustellungsdatum
$f_tr_starttime = mcStrWrap($f_tr_starttime); // Zustellung von
$f_tr_endtime = mcStrWrap($f_tr_endtime); // Zustellung bis
$f_tr_commission_no = mcStrWrap($f_tr_commission_no); // Lieferscheinnummer
$f_order_id = mcStrWrap($f_order_id); // Kundenauftragsnummer
$f_cs_id_external = mcStrWrap($f_cs_id_external); // Kundennummer extern / Lieferantennummer
$f_cs_eid = mcStrWrap($f_cs_eid); // Kundenummer (votian)
$f_tr_comp = mcStrWrap($f_tr_comp); // Firma
$f_tr_comp2 = mcStrWrap($f_tr_comp2); // Firma Zusatz
$f_special_01 = mcStrWrap($f_special_01); // Besteller
$f_ad_street = mcStrWrap($f_ad_street); // Straße
$f_tr_hsno = mcStrWrap($f_tr_hsno); // Hausnummer
if ($f_tr_hsno == "") : $f_tr_hsno = "."; endif;
$f_tr_floor = mcStrWrap($f_tr_floor); // Etage
$f_ad_zipcode = mcStrWrap($f_ad_zipcode); // PLZ
$f_ad_city = mcStrWrap($f_ad_city); // Ort
$f_ad_country = mcStrWrap($f_ad_country); // Land
if ($f_ad_country == "" || $f_ad_country == "D") : $f_ad_country = "DE"; endif;
$f_ad_supplement_1 = mcStrWrap($f_ad_supplement_1); // Adresszusatz I
$f_ad_supplement_2 = mcStrWrap($f_ad_supplement_2); // Adresszusatz II
$f_tr_person = mcStrWrap($f_tr_person); // Ansprechpartner
$f_tr_phone = mcStrWrap($f_tr_phone); // Telefon
$f_special_02 = mcStrWrap($f_special_02); // Mobiltelefonnummer
$f_special_03 = mcStrWrap($f_special_03); // Emailadresse
$f_tr_remark = mcStrWrap($f_tr_remark); // Bemerkung / Zustellinfo
$f_id = mcStrWrap($f_id); // Sendungsidentifikationsnummer
$f_trat_packingpieces = mcStrWrap($f_trat_packingpieces); // Packstücke
$f_trat_palets = mcStrWrap($f_trat_palets); // Paletten
$f_trat_weight = mcStrWrap($f_trat_weight); // Gewicht
$f_trat_weight = str_replace (",", ".", $f_trat_weight);
$f_special_04 = mcStrWrap($f_special_04); // Stellplätze
$f_special_05 = mcStrWrap($f_special_05); // Warenart
$f_zone_no = mcStrWrap($f_zone_no); // Zone
$f_special_06 = mcStrWrap($f_special_06); // Inkasso/Rückführung
$f_price_type = mcStrWrap($f_price_type); // Preistyp
$f_service_type = mcStrWrap($f_service_type); // Leistungstyp
$f_dummy_01 = mcStrWrap($f_dummy_01);
if ($f_special_01 != "") : $f_tr_remark .= "\n<br>" . getLngt("Besteller") . ": " . $f_special_01; endif;
if ($f_special_02 != "") : $f_tr_remark .= "\n<br>" . getLngt("Mobiltelefonnummer") . ": " . $f_special_02; endif;
if ($f_special_03 != "") : $f_tr_remark .= "\n<br>" . getLngt("Emailadresse") . ": " . $f_special_03; endif;
if ($f_id != "") : $f_tr_remark .= "\n<br>" . getLngt("Sendungs-ID") . ": " . $f_id; endif;
if ($f_trat_packingpieces != "") : $f_tr_remark .= "\n<br>" . getLngt("Packstücke") . ": " . $f_trat_packingpieces; endif;
if ($f_trat_palets != "") : $f_tr_remark .= "\n<br>" . getLngt("Paletten") . ": " . $f_trat_palets; endif;
if ($f_trat_weight != "") : $f_tr_remark .= "\n<br>" . getLngt("Gewicht") . ": " . $f_trat_weight; endif;
if ($f_special_04 != "") : $f_tr_remark .= "\n<br>" . getLngt("Stellplätze") . ": " . $f_special_04; endif;
if ($f_special_05 != "") : $f_tr_remark .= "\n<br>" . getLngt("Warenart") . ": " . $f_special_05; endif;
if ($f_zone_no != "") : $f_tr_remark .= "\n<br>" . getLngt("Zone") . ": " . $f_zone_no; endif;
if ($f_special_06 != "") : $f_tr_remark .= "\n<br>" . getLngt("Inkasso/Rückführung") . ": " . $f_special_06; endif;
if ($f_price_type != "") : $f_tr_remark .= "\n<br>" . getLngt("Preistyp") . ": " . $f_price_type; endif;
if ($f_service_type != "") : $f_tr_remark .= "\n<br>" . getLngt("Leistungstyp") . ": " . $f_service_type; endif;
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_tour_no];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
*/
$crEid = $tourCourierArray[$f_tour_no];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
$crSid = $tourSIDArray[$f_tour_no];
endif;
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
// $jbStatus = "1"; // jb_status will be set after the whole job is generated
$jbTaketime = $currentTime;
$useJbNewArray = true;
endif;
$jbType = "";
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo $f_id . ";" . $f_tour_no . ";" . $f_shipment_mode . ";" . $f_jb_orderdate . ";" . $f_jb_warningdate . ";" . $f_jb_starttime . ";" . $f_jb_endtime . ";";
echo $f_tr_commission_no . ";" . $f_order_id . ";" . $f_cs_id_external . ";" . $f_cs_eid . ";" . $f_tr_comp . ";" . $f_tr_comp2 . ";" . $f_special_01 . ";";
echo $f_tr_remark . ";" . $f_ad_street . ";" . $f_tr_hsno . ";" . $f_tr_floor . ";" . $f_ad_zipcode . ";" . $f_ad_city . ";" . ";" . $f_ad_country;
echo $f_ad_supplement_1 . ";" . $f_ad_supplement_2 . ";" . $f_tr_person . ";" . $f_tr_phone . ";" . $f_special_02 . ";" . $f_special_03 . ";" . ";" . $f_tr_remark;
echo $f_trat_packingpieces . ";" . $f_trat_palets . ";" . $f_trat_weight . ";" . $f_special_04 . ";" . $f_special_05 . ";";
echo $f_zone_no . ";" . $f_special_06 . ";" . $f_price_type . ";" . $f_service_type . ";";
echo "<br>";
echo "----------------------------------------------------------------------------------------------------------------------------------------------<br>";
// Check for existence of the imported order number (for the same day ONLY)
$gdcEntryExists = false;
// if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","info_2","gdc_content",$f_tr_commission_no,"gdc_context","UNIMET"))) :
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_tr_commission_no . "_" . $currentDate,"gdc_context","UNIMET"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if UNIMET number does exist on the current day!!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$callInsertAddress = true;
if ($f_cs_eid != "") :
$csEndId = getFieldValueFromId("customer","cs_eid",$f_cs_eid,"cs_id");
if ($csEndId != "") :
$csEndAddress = getAddress($csEndId, "costcenteraddress");
$adIdCsEnd = $csEndAddress["id"];
if ($adIdCsEnd != "") :
$callInsertAddress = false;
endif;
$f_ad_street = $csEndAddress["street"];
$f_tr_hsno = $csEndAddress["hsno"];
$f_ad_zipcode = $csEndAddress["zipcode"];
$f_ad_city = $csEndAddress["city"];
$f_ad_country = $csEndAddress["country"];
if ($f_ad_country == "") :
$f_ad_country = "DE";
endif;
endif;
endif;
$noValidationOfAddress = true;
// Insert address
if ($callInsertAddress) :
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
endif;
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_tour_no) :
$jbIdNew = "";
// Start datetime
if ($f_tr_starttime == "") : $f_tr_starttime = "08:00"; endif;
$f_jb_ordertime = substr($f_tr_orderdate, 0,4) . "-" . substr($f_tr_orderdate, 4,2) . "-" . substr($f_tr_orderdate, 6,2) . " " . $f_tr_starttime . ":00";
// End datetime
$f_jb_warningtime = "";
if ($f_tr_endtime == "") : $f_tr_endtime = "18:00"; endif;
/*
if ($f_jb_warningdate != "") :
$f_jb_warningtime = substr($f_tr_warningdate, 0,4) . "-" . substr($f_tr_warningdate, 4,2) . "-" . substr($f_tr_warningdate, 6,2);
if ($f_tr_warningdate != "") :
$f_jb_warningtime .= " " . $f_tr_endtime . ":00";
endif;
endif;
*/
// Remove existing tourname
updateStmt("job","jb_tourname",$f_tour_no,array("jb_tourname",""), "jb_tourname = '" . $f_tour_no . "'");
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_tour_no,
"jb_finishtime", $jbFinishtime, "jb_warningtime", $f_jb_warningtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbIdNew = getLastInsertId();
$jobNewArray[] = $jbIdNew;
// Tour-Nr. "$f_tour_no"
insertStmt("genericdatacontainer", array("gdc_obj_type", "jb", "gdc_obj_id", $jbIdNew, "gdc_gen_fieldname", "tourname", "gdc_content", $f_tour_no, "gdc_context", "UNIMET"));
$trSort = 2; // Init for 2nd station equals first delivery !!!!
$tratSort = 1; // Init all serial numbers !!!!
$remTourNo = $f_tour_no;
endif;
// Check for inserted job
if ($jbIdNew != "") :
// Insert stations
if ($trSort == 2) :
$trStatus = "0";
$trFinishtime = "";
if ($pickUpStationFinishedByDefault) :
$trStatus = "1";
$trFinishtime = $currentTime;
endif;
// Insert pick up station during first iteration
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $adIdFrom, "tr_sort", "1", "tr_comp", $trCompFrom, "tr_comp2", "",
"tr_hsno", $trHsnoFrom, "tr_floor", $trFloorFrom, "csc_id", $cscIdPayer, "tr_status", $trStatus, "tr_finishtime", $trFinishtime,
"tr_commission_no", "", "tr_ware_from_to", $f_tr_ware_from_to,
"tr_person", "", "tr_phone", "", "tr_remark", ""));
$trIdPickUpNew = getLastInsertID();
// Init array für jb_tourdata
$jbTourdataZipcodeArray[$jbIdNew][] = $csAddress["zipcode"];
$jbTourdataCityArray[$jbIdNew][] = $csAddress["city"];
$jbTourdataCountryArray[$jbIdNew][] = $csAddress["country"];
endif;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "tr_floor", $f_tr_floor, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
$jbTourdataZipcodeArray[$jbIdNew][] = $f_ad_zipcode;
$jbTourdataCityArray[$jbIdNew][] = $f_ad_city;
$jbTourdataCountryArray[$jbIdNew][] = $f_ad_country;
// Insert tourservice data
// !!!! MIT tr_id !!!! insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// ****
// Special patch because of "bug" in function "mk_jb_invtext()"
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// ****
// Fremdauftragsnummer "$f_order_id"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_0", "gdc_content", $f_order_id, "gdc_context", "UNIMET"));
// Kundennummer "$f_cs_id_external"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_1", "gdc_content", $f_cs_id_external, "gdc_context", "UNIMET"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_cust_no", "gdc_content", $f_cs_id_external, "gdc_context", "UNIMET"));
// Lieferscheinnummer "$f_tr_commission_no"
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_2", "gdc_content", $f_tr_commission_no, "gdc_context", "UNIMET"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_tr_commission_no . "_" . $currentDate, "gdc_context", "UNIMET"));
// Insert tourarticle data (delivery stations)
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
$trSort++;
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_order_id . "]<br>";
endif;
}
// Set generated jobs to status "taken"
$jobNewArrayLen = count($jobNewArray);
if ($jobNewArrayLen > 0) :
for ($i = 0; $i < $jobNewArrayLen; $i++) :
// jb_status
// updateStmt("job", "jb_id", $jobNewArray[$i], array("jb_status", "1"));
// jb_tourdata
$jbTourdata = implode(";", $jbTourdataZipcodeArray[$jobNewArray[$i]]) . "|" . implode(";", $jbTourdataCityArray[$jobNewArray[$i]]) . "|" . implode(";", $jbTourdataCountryArray[$jobNewArray[$i]]);
updateStmt("job", "jb_id", $jobNewArray[$i], array("jb_tourdata", $jbTourdata));
endfor;
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_UNIMET.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

386
html/import/import_UTA.php Normal file
View File

@@ -0,0 +1,386 @@
<?php
/*=======================================================================
*
* import_UTA.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
include_once ("../import/import.php");
// Execution-Time for script
set_time_limit(30000);
// Get the rights of the employee logged in and check the accessibility
authCheckEmployeeRights($emp_id, "22", "1");
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT UTA");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
// Converts STR to DATE
function cStr2Date ($str, $mode = "") {
if ($mode == "1") :
// Default: "d.m.Y" => "Y-m-d"
$str = substr($str,6,4) . "-" . substr($str,3,2) . "-" . substr($str,0,2);
elseif ($mode == "2") :
// ...
else :
// Default: "dmY" => "Y-m-d"
$str = substr($str,4,4) . "-" . substr($str,2,2) . "-" . substr($str,0,2);
endif;
return $str;
}
// Converts STR to FLOAT (with ".") [e.g.: 000011122 => 111.22 with 2 decimals]
function cStr2Float ($str, $decimals = "2") {
if (is_numeric($str)) :
$numberPrefix = substr($str, 0, strlen($str) - $decimals);
$numberSuffix = substr($str, strlen($str) - $decimals, $decimals);
while (substr($numberPrefix,0,1) == "0" && strlen($numberPrefix) > 0) {
$numberPrefix = substr($numberPrefix,1);
}
$str = $numberPrefix . "." . $numberSuffix;
endif;
return $str;
}
if ($importFile != "") :
$importFile = urldecode($importFile);
if (file_exists($importFile)) :
$f_numOfRows = 0;
$f_checksum = 0;
$currentTime = getDateTime("0");
// *******************
// * Import UTA data *
// *******************
if (true) :
$outText .= getLngt("IMPORTDATEI:") . "&nbsp;" . $importFile . "<br><br>";
// Read file to import
$data = importDataset($importFile);
$dataLen = count($data);
$outText .= getLngt("Anzahl Einträge:") . "&nbsp;" . $dataLen . "<br><br>";
$f_31_sum = 0; // Sum of all values of field $f_31 to be compared with the checksum
$numOfNotEmptyRows = 0;
// Loop all rows
for ($j = 0; $j < $dataLen; $j++) :
$r = trim($data[$j]); // Get row
if ($r != "") :
$outText .= "<br>";
if ($j < $dataLen - 1) : $outText .= $j . ". "; endif;
$f_dataset_type = substr($r,0,2); // Type of the data set
if ($f_dataset_type == "10") :
$f_02 = substr($r,2,13); // Absender-ID
$f_03 = substr($r,15,13); // Empfänger-ID
$f_04 = cStr2Date(substr($r,28,10),1); // Datum
$f_05 = substr($r,38,1); // Leerzeichen
$f_06 = substr($r,39,8); // Uhrzeit
$f_07 = substr($r,47,13); // Abrechnungsnr.
$f_08 = substr($r,60,6); // Übertragungsnr.
$f_09 = substr($r,66,6); // DTF-Format
elseif ($f_dataset_type == "20") :
$f_02 = substr($r,2,13); // Abrechnungsnr.
$f_03 = cStr2Date(substr($r,15,8)); // Datum "Für Lieferungen und Leistungen bis"
$f_04 = substr($r,23,13); // Rechnunsempfänger-Kundennr.
$f_05 = cStr2Date(substr($r,36,8)); // Abrechnungsdatum
$f_06 = substr($r,44,13); // Kundennr.
$f_07 = substr($r,57,19); // Kartennr. (vollständig)
$f_08 = cStr2Date(substr($r,76,8)); // Belegdatum [TTMMJJJJ]
$f_09 = substr($r,84,13); // Akzeptanzstellennr.
$f_10 = substr($r,97,25); // Standort der Akzeptanzstelle
$f_11 = substr($r,122,3); // Lieferland
$f_12 = substr($r,125,13); // Belegnr. des Lieferanten
$f_13 = substr($r,138,8); // Kilometer-Stand
$f_14 = substr($r,146,5); // Fakturierwarenart
$f_15 = substr($r,151,1); // Vorzeichen-Statusfeld für alle Beträge und Mengen (0 = pos., 1 = neg.)
$f_16 = cStr2Float(substr($r,152,10)); // Menge
$f_17 = substr($r,162,1); // SB / BT (1 = Selbstbedienung / 0 = Bedienung)
$f_18 = cStr2Float(substr($r,163,5)); // USt.-Prozentsatz
$f_19 = substr($r,168,3); // Lieferlandwährung (ISO)
$f_20 = cStr2Float(substr($r,171,11)); // Einzelpreis-Brutto in Lieferlandwährung (= $f_21 * (($f_18 + 100) / 100))
$f_21 = cStr2Float(substr($r,182,11)); // Einzelpreis-Netto in Lieferlandwährung
$f_22 = cStr2Float(substr($r,193,11)); // Betrag Service in Lieferlandwährung (Brutto)
$f_23 = cStr2Float(substr($r,204,11)); // Betrag Nachlass in Lieferlandwährung (Brutto)
$f_24 = cStr2Float(substr($r,215,11)); // Gesamtbetrag-Netto in Lieferlandwährung (= ($f_16 * $f_48) + ($f_22 / (($f_18 + 100) / 100)))
$f_25 = cStr2Float(substr($r,226,11)); // Gesamtbetrag-Brutto in Lieferlandwährung (= ($f_16 * $f_47) + $f_22)
$f_26 = substr($r,237,3); // Darstellwährung (ISO)
$f_27 = cStr2Float(substr($r,240,11)); // Betrag Service in Darstellwährung
$f_28 = cStr2Float(substr($r,251,11)); // Betrag Nachlass in Darstellwährung
$f_29 = cStr2Float(substr($r,262,11)); // Gesamtbetrag-Netto in Darstellwährung
$f_30 = cStr2Float(substr($r,273,11)); // Gesamtbetrag-USt. in Darstellwährung
$f_31 = cStr2Float(substr($r,284,11)); // Gesamtbetrag-Brutto in Darstellwährung (= $f_29 + $f_30)#
$f_31_sum += $f_31;
$f_32 = substr($r,295,16); // Prägetext (i.d.R. KFZ-Kennzeichen)
$f_33 = substr($r,311,20); // Kunden-Kostenstelle (für ein Fahrzeug gewählte Kostenstelle)
$f_34 = substr($r,331,8); // Kartentyp
$f_35 = substr($r,339,1); // %
$f_36 = substr($r,340,3); // %
$f_37 = substr($r,343,1); // KZ Autobahn (0 = liegt nicht an der Autobahn, 1 = liegt an der Autobahn)
$f_38 = substr($r,344,18); // Info-Feld (für später)
$f_39 = substr($r,362,16); // KFZ-Kennzeichen (evtl. = $f_32)
$f_40 = substr($r,378,1); // %
$f_41 = substr($r,379,1); // Buchungsart (B = Buchung, G = Gutschrift, S = Storno)
$f_42 = substr($r,380,1); // Buchungsgrund (- = normale Buchung, Q = Kulanz, B = Betrug, K = Kondition)
$f_43 = substr($r,381,1); // %
$f_44 = substr($r,382,1); // Informationsbeleg (0 = nein, 1 = ja)
$f_45 = substr($r,383,1); // Belegherkunft (D = Digitaler Beleg, normaler Dateneingang, M = Manueller Beleg über Belegerfassung ohne EXTERNEN Papierbeleg, A = Analoger Beleg mit EXT. Papierbeleg, K = Konditionsbeleg)
$f_46 = substr($r,384,14); // %
// Further fields according to version DTF 6301
$f_47 = cStr2Float(substr($r,398,13),4); // Einzelpreis-Brutto in Lieferlandwährung mit vier Nachkommastellen
$f_48 = cStr2Float(substr($r,411,13),4); // Einzelpreis-Netto in Lieferlandwährung mit vier Nachkommastellen
$f_49 = cStr2Date(substr($r,424,8)); // Rechnungsdatum
$f_50 = substr($r,432,5); // USt.-Prozentsatz informativ
$f_51 = cStr2Float(substr($r,437,11)); // Betrag Nachlass in Lieferlandwährung USt. informativ
$f_52 = cStr2Float(substr($r,448,11)); // Betrag Service in Lieferlandwährung USt. informativ
$f_53 = cStr2Float(substr($r,459,11)); // Gesamtbetrag in Lieferlandwährung USt. informativ
$f_54 = cStr2Date(substr($r,470,8)); // Fälligkeitsdatum
$f_55 = substr($r,478,3); // Zahlungsziel in Tagen
$f_56 = substr($r,481,8); // Zahlungsart
$f_57 = substr($r,489,20); // TC-Rechnungsnr. gegenüber dem Nutzer
$f_58 = substr($r,509,8); // TC-Rechnungsdatum
$f_59 = substr($r,517,7); // Zahlungszielgruppe
$f_60 = substr($r,524,20); // Kunden-Kostenstelle 2
$f_61 = substr($r,544,6); // Lieferzeit
// Further fields according to version DTF 6303
$f_62 = substr($r,550,20); // Fremdkartennr.
$f_63 = substr($r,570,20); // OnBoardUnit-ID
$f_64 = substr($r,590,16); // KFZ-Kennzeichen komprimiert (wie $f_32 bzw. $f_39, nur ohne Leerzeichen und Bindestriche)
$f_65 = substr($r,606,8); // Kartenkategorie
$f_66 = substr($r,614,13); // Rechnungsnr. pro Lieferland
$f_67 = substr($r,627,40); // Autobahnauffahrt
$f_68 = substr($r,667,40); // Autobahnausfahrt
$f_69 = substr($r,707,1); // Rabattschlüssel der französischen Autobahngesellschaften
$f_70 = substr($r,708,13); // Nr. Belastungsanzeige
$f_71 = substr($r,721,20); // Betreuungsstelle
$f_72 = substr($r,741,20); // %
$f_73 = substr($r,761,20); // Akzeptanz-Medium
// Further fields according to version DTF 6304
$f_74 = substr($r,781,8); // Steuerkategorie
$f_75 = substr($r,789,11); // UTA Beleg-ID
$f_76 = substr($r,800,11); // UTA Normbeleg-ID
$f_77 = cStr2Date(substr($r,811,8)); // Gebühren-Bescheinigung von
$f_78 = cStr2Date(substr($r,819,8)); // Gebühren-Bescheinigung bis
$f_79 = substr($r,827,20); // Herausgeber- / Nutzer-Nr.
$f_80 = substr($r,847,8); // Maßeinheit
$f_81 = substr($r,855,3); // Land der Akzeptanzstelle
$f_82 = substr($r,858,7); // PLZ der Akzeptanzstelle
// Further fields according to version DTF 6305
$f_83 = substr($r,865,3); // steuerliches Leistungsland
$f_84 = substr($r,868,5); // steuerliches Produktgruppe
$f_85 = substr($r,873,1); // Leistungsort verlagerbar (0 = nein, 1 = ja)
// $f_86 = substr($r,,); //
// $f_87 = substr($r,,); //
// $f_88 = substr($r,,); //
// $f_89 = substr($r,,); //
// $f_90 = substr($r,,); //
elseif ($f_dataset_type == "90") :
$f_numOfRows = substr($r,2,13); // Anzahl Sätze inklusive Header und Trailer
$f_checksum = cStr2Float(substr($r,15,18)); // Checksumme über Feld "Gesamt Brutto in Darstellwährung" [Satzart 20] unter Berücksichtigung des Vorzeichens (Statusfeld Vorzeichen!!!)
endif;
// Generate output for visual check
if ($f_dataset_type == "10" || $f_dataset_type == "20") :
$outText .= $f_01 . " - " . $f_02 . " - " . $f_03 . " - " . $f_04 . " - " . $f_05 . " - " . $f_06 . " - " . $f_07 . " - " . $f_08 . " - " . $f_09 . " - " . $f_10 . " - " . "<br>";
$outText .= $f_11 . " - " . $f_12 . " - " . $f_13 . " - " . $f_14 . " - " . $f_15 . " - " . $f_16 . " - " . $f_17 . " - " . $f_18 . " - " . $f_19 . " - " . $f_20 . " - " . "<br>";
$outText .= $f_21 . " - " . $f_22 . " - " . $f_23 . " - " . $f_24 . " - " . $f_25 . " - " . $f_26 . " - " . $f_27 . " - " . $f_28 . " - " . $f_29 . " - " . $f_30 . " - " . "<br>";
$outText .= $f_31 . " - " . $f_32 . " - " . $f_33 . " - " . $f_34 . " - " . $f_35 . " - " . $f_36 . " - " . $f_37 . " - " . $f_38 . " - " . $f_39 . " - " . $f_40 . " - " . "<br>";
$outText .= $f_41 . " - " . $f_42 . " - " . $f_43 . " - " . $f_44 . " - " . $f_45 . " - " . $f_46 . " - " . $f_47 . " - " . $f_48 . " - " . $f_49 . " - " . $f_50 . " - " . "<br>";
$outText .= $f_51 . " - " . $f_52 . " - " . $f_53 . " - " . $f_54 . " - " . $f_55 . " - " . $f_56 . " - " . $f_57 . " - " . $f_58 . " - " . $f_59 . " - " . $f_60 . " - " . "<br>";
$outText .= $f_61 . " - " . $f_62 . " - " . $f_63 . " - " . $f_64 . " - " . $f_65 . " - " . $f_66 . " - " . $f_67 . " - " . $f_68 . " - " . $f_69 . " - " . $f_70 . " - " . "<br>";
$outText .= $f_71 . " - " . $f_72 . " - " . $f_73 . " - " . $f_74 . " - " . $f_75 . " - " . $f_76 . " - " . $f_77 . " - " . $f_78 . " - " . $f_79 . " - " . $f_80 . " - " . "<br>";
$outText .= $f_81 . " - " . $f_82 . " - " . $f_83 . " - " . $f_84 . " - " . $f_85 . " - " . $f_86 . " - " . $f_87 . " - " . $f_88 . " - " . $f_89 . " - " . $f_90 . " - " . "<br>";
$outText .= "<br>";
endif;
// *** START DATABASE ACCESS ***
if ($executeImportProcess == "1") :
if ($f_dataset_type == "10") :
insertStmt("phoenix_log.uta_header", array("utah_dataset_type", $f_dataset_type, "utah_consigner_id", $f_02, "utah_receiver_id", $f_03, "utah_date", $f_04, "utah_time", $f_06, "utah_account_no", $f_07, "utah_transfer_no", $f_08, "utah_dtf_format", $f_09, "utah_createtimestamp", $currentTime));
elseif ($f_dataset_type == "20") :
insertStmt("phoenix_log.uta", array("uta_01", $f_dataset_type, "uta_02", $f_02, "uta_03", $f_03, "uta_04", $f_04, "uta_05", $f_05, "uta_06", $f_06, "uta_07", $f_07, "uta_08", $f_08, "uta_09", $f_09, "uta_10", $f_10,
"uta_11", $f_11, "uta_12", $f_12, "uta_13", $f_13, "uta_14", $f_14, "uta_15", $f_15, "uta_16", $f_16, "uta_17", $f_17, "uta_18", $f_18, "uta_19", $f_19, "uta_20", $f_20,
"uta_21", $f_21, "uta_22", $f_22, "uta_23", $f_23, "uta_24", $f_24, "uta_25", $f_25, "uta_26", $f_26, "uta_27", $f_27, "uta_28", $f_28, "uta_29", $f_29, "uta_30", $f_30,
"uta_31", $f_31, "uta_32", $f_32, "uta_33", $f_33, "uta_34", $f_34, "uta_35", $f_35, "uta_36", $f_36, "uta_37", $f_37, "uta_38", $f_38, "uta_39", $f_39, "uta_40", $f_40,
"uta_41", $f_41, "uta_42", $f_42, "uta_43", $f_43, "uta_44", $f_44, "uta_45", $f_45, "uta_46", $f_46, "uta_47", $f_47, "uta_48", $f_48, "uta_49", $f_49, "uta_50", $f_50,
"uta_51", $f_51, "uta_52", $f_52, "uta_53", $f_53, "uta_54", $f_54, "uta_55", $f_55, "uta_56", $f_56, "uta_57", $f_57, "uta_58", $f_58, "uta_59", $f_59, "uta_60", $f_60,
"uta_61", $f_61, "uta_62", $f_62, "uta_63", $f_63, "uta_64", $f_64, "uta_65", $f_65, "uta_66", $f_66, "uta_67", $f_67, "uta_68", $f_68, "uta_69", $f_69, "uta_70", $f_70,
"uta_71", $f_71, "uta_72", $f_72, "uta_73", $f_73, "uta_74", $f_74, "uta_75", $f_75, "uta_76", $f_76, "uta_77", $f_77, "uta_78", $f_78, "uta_79", $f_79, "uta_80", $f_80,
"uta_81", $f_81, "uta_82", $f_82, "uta_83", $f_83, "uta_84", $f_84, "uta_85", $f_85, "uta_createtimestamp", $currentTime));
endif;
endif;
$numOfNotEmptyRows++;
endif;
endfor;
settype($f_checksum, 'string');
settype($f_31_sum, 'string');
if (!is_numeric($f_numOfRows) || $f_numOfRows != $numOfNotEmptyRows) :
$statusMessage .= getLngt("Die Anzahl durchlaufener Datensätze (") . $numOfNotEmptyRows . getLngt(") stimmt NICHT mit der Angabe in der Datei überein (") . $f_numOfRows . ")!";
$showExecutionProcessButton = false;
endif;
if (!is_numeric($f_checksum)) :
$statusMessage .= getLngt("Die vorgegebene Checksumme in der Datei ist nicht numerisch!");
$showExecutionProcessButton = false;
else :
if ($f_checksum != $f_31_sum) :
$statusMessage .= getLngt("Die vorgegebene Checksumme (") . $f_checksum . getLngt(") in der Datei ist ungleich der Summer der Bruttosummen (") . $f_31_sum . ")!";
$showExecutionProcessButton = false;
endif;
endif;
if ($showExecutionProcessButton) :
if ($executeImportProcess != "1") :
$statusMessage .= getLngt("Der Importprozess kann jetzt initiiert werden!");
else :
$statusMessage .= getLngt("DER IMPORTPROZESS IST ERFOLGREICH ABGESCHLOSSEN!");
$closeWindow = "1";
// Remove file
$retVal = removeFile($importFile, "", $pathSeparator);
if ($retVal == "0") :
// OK
elseif ($retVal == "-1") :
$statusMessage .= getLngt("Es liegt kein Dateiname vor!");
elseif ($retVal == "-2") :
$statusMessage .= getLngt("Die Datei befindet sich nicht mehr in dem Verzeichnis!");
elseif ($retVal == "") :
$statusMessage .= getLngt("Es fand keine Löschung statt!");
endif;
endif;
endif;
// else :
// echo getLngt("");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_UTA.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

592
html/import/import_ZFBG.php Normal file
View File

@@ -0,0 +1,592 @@
<?php
/*=======================================================================
*
* import_ZFBG.php [Zeit für Brot GmbH]
*
* Autor: Marc Vollmann
*
=======================================================================*/
/*
- Variation von "TOURS" (Beschreibung siehe "import_TOURS.php")
- Startzeit von 09 auf 06 Uhr
*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csEid = "";
$cscIdPayer = "";
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
// Init
$jbIdNew = "";
$jbTourdata = "";
$jbTourdataZipcode = "";
$jbTourdataCity = "";
$jbTourdataCountry = "";
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strrpos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
/*
$tourVehicleArray = array();
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
*/
$tourCourierArray = array();
/*
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
$tourCourierArray["294505"] = "e8020205";
$tourCourierArray["294506"] = "e8020206";
$tourCourierArray["294507"] = "e8020207";
$tourCourierArray["294508"] = "e8020208";
$tourCourierArray["294509"] = "e8020209";
$tourCourierArray["294510"] = "e8020210";
$tourCourierArray["294511"] = "e8020211";
$tourCourierArray["294512"] = "e8020212";
$tourCourierArray["294590"] = "e8020213";
*/
function mcStrWrap($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
return $aStr;
}
echo "importFile" . $importFile . "<br>";
echo "hqId" . $hqId . "<br>";
echo "csId" . $csId . "<br>";
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_ZFBG_") === false)) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$remTourNo = "";
$jbIdNew = 0;
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_TOURS_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
$rowToImport[0] = "f_no_row"; // A : (Laufende) Nr. (Datensatz)
$rowToImport[1] = "f_jb_tourname"; // B : Auftrag Bezeichnung (Tourname)
$rowToImport[2] = "f_tr_commission_no"; // C : Station Kommissionsnummer
$rowToImport[3] = "f_tr_comp"; // D : Station Bezeichnung
$rowToImport[4] = "f_tr_remark"; // E : Station Bemerkung
$rowToImport[5] = "f_tr_sort"; // F : Station Position in Tour
$rowToImport[6] = "f_ad_zipcode"; // G : Station PLZ
$rowToImport[7] = "f_ad_city"; // H : Station Ort
$rowToImport[8] = "f_ad_street"; // I : Station Straße
$rowToImport[9] = "f_tr_hsno"; // J : Station Hausnummer
$rowToImport[10] = "f_tr_arrival_time"; // K : Station Ankunft
$rowToImport[11] = "f_tr_departure_time"; // L : Station Abfahrt
$rowToImport[12] = "f_tr_point2point_time"; // M : Station Strecke
$rowToImport[13] = "f_tr_point2point_min"; // N : Auftrag Fixe Dauer
$rowToImport[14] = "f_dummy_01"; // O : ?
endif;
// Special handling
$parFieldCmpComp = getParameterValue("0", "IMPORT_TOURS_FIELD_TR_COMP", $hqId);
if ($parFieldCmpComp == "") : $parFieldCmpComp = getParameterValue("0", "IMPORT_TOURS_FIELD_TR_COMP", "0"); endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_no_row = mcStrWrap($f_no_row);
$f_jb_tourname = mcStrWrap($f_jb_tourname);
$f_tr_commission_no = mcStrWrap($f_tr_commission_no);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_tr_remark = mcStrWrap($f_tr_remark);
$f_tr_sort = mcStrWrap($f_tr_sort);
$f_ad_zipcode = mcStrWrap($f_ad_zipcode);
$f_ad_city = mcStrWrap($f_ad_city);
$f_ad_street = mcStrWrap($f_ad_street);
$f_tr_hsno = mcStrWrap($f_tr_hsno);
$f_tr_arrival_time = mcStrWrap($f_tr_arrival_time);
$f_tr_departure_time = mcStrWrap($f_tr_departure_time);
$f_tr_point2point_time = mcStrWrap($f_tr_point2point_time);
$f_tr_point2point_min = mcStrWrap($f_tr_point2point_min);
// Check for existing headline
if ($j > 0 || ($f_no_row != "" && is_numeric($f_no_row))) :
if ($parFieldCmpComp == "0") :
$tmpArray = spliti("_", $f_tr_comp);
// Do nothing
elseif ($parFieldCmpComp == "1") :
$tmpArray = spliti("__", $f_tr_comp); // Two underline chars as delimiter
$f_tr_person = $tmpArray[1];
$f_tr_comp = $tmpArray[0];
else :
// Default
$tmpArray = spliti("_", $f_tr_comp);
$f_tr_person = $tmpArray[0];
endif;
$tmpArray = spliti("_", $f_tr_remark);
$f_tr_phone = $tmpArray[2];
$f_tr_phone = str_replace ("Tel:", "", $f_tr_phone);
$f_tr_phone = eregPhoneNo($f_tr_phone);
if ($f_tr_hsno == "") :
$f_tr_hsno = ".";
endif;
if ($f_tr_arrival_time != "") :
$f_tr_remark .= "\n\nAnkunft: " . $f_tr_arrival_time;
endif;
if ($f_tr_departure_time != "") :
$f_tr_remark .= "\n\nAbfahrt" . $f_tr_departure_time;
endif;
// $f_tr_remark .= $f_tr_point2point_time
// $f_tr_remark .= $f_tr_point2point_min
// Move commission number to station remark
if ($f_tr_commission_no != "") :
$f_tr_remark .= "\n\n[*" . $f_tr_commission_no . "*]";
$f_tr_commission_no = "";
endif;
// Clock time depends on headquarters
$clockTime = "06:00:00";
/*
if ($hqId == "3") :
$clockTime = "12:45:00";
endif;
*/
if ($f_jb_tourname != "") :
$f_jb_orderdate = substr($f_jb_tourname, -8);
$f_jb_ordertime = "20" . substr($f_jb_orderdate,6,2) . "-" . substr($f_jb_orderdate,2,2) . "-" . substr($f_jb_orderdate,0,2) . " " . $clockTime;
endif;
// The first row of the tour contains the tour name. The following rows of the same tour are empty for $f_jb_tourname !!!!
if ($f_jb_tourname == "") :
$f_jb_tourname = $remTourNo;
endif;
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_jb_tourname];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
*/
$crEid = $tourCourierArray[$f_jb_tourname];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
endif;
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
$jbStatus = "1";
$jbTaketime = $currentTime;
endif;
$jbType = "";
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
echo $f_no_row . ";" . $f_jb_tourname . ";" . $f_tr_commission_no . ";" . $f_tr_comp . ";" . $f_tr_remark . ";" . $f_tr_sort . ";" . $f_ad_zipcode . ";";
echo $f_ad_city . ";" . $f_ad_street . ";" . $f_tr_hsno;
// echo ";" . $f_tr_arrival_time . ";" . $f_tr_departure_time . ";" . $f_tr_point2point_time . ";";
// echo $f_tr_point2point_min . ";" . $f_tr_person . ";" . $f_tr_phone . ";" . $f_jb_ordertime;
echo "<br>";
// Check for existence of the imported "tour name" AND "station number" (unique for station)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$f_jb_tourname . " " . $f_tr_sort,"gdc_context","ZFBG"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if TOURS number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
if ($cscIdPayer == "") :
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
endif;
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
$txValue = "4";
$txSign = "V";
$noValidationOfAddress = true;
if ($remTourNo == "" || $remTourNo == $f_jb_tourname) :
if ($jbTourdataZipcode != "") : $jbTourdataZipcode .= ";"; endif;
$jbTourdataZipcode .= $f_ad_zipcode;
if ($jbTourdataCity != "") : $jbTourdataCity .= ";"; endif;
$jbTourdataCity .= $f_ad_city;
if ($jbTourdataCountry != "") : $jbTourdataCountry .= ";"; endif;
$jbTourdataCountry .= "DE";
endif;
// Insert address
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($remTourNo == "" || $remTourNo != $f_jb_tourname) :
// Finalize currently imported job
// Write "jb_tourdata" of the job currently imported
if ($remTourNo != "" && $jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
// Remove existing tourname
updateStmt("job","jb_tourname",$f_jb_tourname,array("jb_tourname",""), "jb_tourname = '" . $f_jb_tourname . "'");
// Tour data
/*
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
// updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
*/
$jbIdNew = ""; // Init
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbIdNew = getLastInsertId();
$trSort = 0; // Init for 1st station
$tratSort = 1; // Init all serial numbers !!!!
$remTourNo = $f_jb_tourname;
// Init for the next job to be imported
$jbTourdata = "";
// Init with current values
$jbTourdataZipcode = $f_ad_zipcode;
$jbTourdataCity = $f_ad_city;
$jbTourdataCountry = "DE";
endif;
// Check for inserted job
if ($jbIdNew != "") :
$trSort++;
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new, "tr_sort", $trSort, "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$trIdNew = getLastInsertID();
// Insert tourservice data
/*
insertStmt("tourservice", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort,
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $sum_totalprice));
*/
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort, "srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "", "trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// Tourname
// insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "info_0", "gdc_content", $f_jb_tourname . " " . $f_tr_sort, "gdc_context", "ZFBG"));
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $trIdNew, "gdc_gen_fieldname", "check_exist", "gdc_content", $f_jb_tourname . " " . $f_tr_sort, "gdc_context", "ZFBG"));
// Insert tourarticle data (delivery stations)
/*
insertStmt("tourarticle", array("tr_id", $trIdNew, "jb_id", $jbIdNew, "tr_sort", $trSort, "trat_sort", "1", "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
*/
// Insert tourarticle data (pick up station only)
// ATTENTION: Execution only if pick-up station is NOT finished by default
/*
if (!$pickUpStationFinishedByDefault) :
insertStmt("tourarticle", array("tr_id", $trIdPickUpNew, "jb_id", $jbIdNew, "tr_sort", "1", "trat_sort", $tratSort, "at_id", "", "trat_quantity", "0",
"trat_weight", $f_trat_weight, "trat_price", "0", "trat_packingpieces", $f_trat_packingpieces, "trat_serialno", $f_tr_commission_no,
"trat_remark", $f_trat_remark, "trat_createtime", $currentTime));
$tratSort++;
endif;
*/
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $f_jb_tourname . " " . $f_tr_sort . "]<br>";
endif;
endif; // Check for headline
}
// If at least onne imported job does exist ($jbIdNew > 0) then finalize last imported job
// Write "jb_tourdata" of the job currently imported
if ($jbIdNew != "" && is_numeric($jbIdNew)) :
$jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;
updateStmt("job","jb_id",$jbIdNew,array("jb_tourdata",$jbTourdata));
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_ZFBG.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,10 @@
22844;HH
22846;hh
22848;B
22850;b
22851;HB
22869;hb
22880;DD
22885;dd
22889;L
22926;l
1 22844 HH
2 22846 hh
3 22848 B
4 22850 b
5 22851 HB
6 22869 hb
7 22880 DD
8 22885 dd
9 22889 L
10 22926 l

View File

@@ -0,0 +1,303 @@
<?php
/*=======================================================================
*
* import_ZIPCODE_NEIGHBOURS.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// include_once ("../include/auth.inc.php");
include_once ("../import/import.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT ZIPCODE_NEIGHBOURS");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = true;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true;
// Customer and headquarters references have to exist
if ($debug) :
echo "f_act : " . $f_act . "<br>";
echo "objType : " . $objType . "<br>";
echo "objId : " . $objId . "<br>";
echo "hq_id : " . $hq_id . "<br>";
echo "csId : " . $csId . "<br>";
echo "<br>";
endif;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
if ($importFile != "") :
if ($hq_id != "") :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ********************
// * IMPORT FILE zone *
// ********************
if (!(strpos($filename, "import_ZIPCODE_NEIGHBOURS_") === false)) :
/*
- CSV-Datei
- die 1. Spalte enthält die PLZ, für die die folgenden Nachbar-PLZn angelegt werden sollen (Spalte 2 bin Spalte n)
- Format-Beispiel:
80331;80539;80469;80538;80336;80335;80333;80337;;;;
80333;80539;80331;80335;80798;80799;80797;80336;;;;
80335;80333;80331;80336;80339;80636;80797;;;;;
80336;80331;80337;81373;80339;80335;80333;81371;80469;;;
80337;80469;81371;80336;80331;81373;81543;;;;;
80339;80336;81373;80686;80634;80636;80335;80639;80687;80337;;
80469;81541;81543;81371;80337;80538;81667;80331;80539;80336;;
80538;80802;81679;81675;81667;80469;80331;80539;81669;;;
80539;80538;80469;80331;80333;80799;80802;80801;;;;
80634;80636;80339;80639;80637;80335;80638;80687;;;;
*/
$rowToImport = array();
$rowToImport[0] = "f_zipcode";
$rowToImport[1] = "f_zip_01";
$rowToImport[2] = "f_zip_02";
$rowToImport[3] = "f_zip_03";
$rowToImport[4] = "f_zip_04";
$rowToImport[5] = "f_zip_05";
$rowToImport[6] = "f_zip_06";
$rowToImport[7] = "f_zip_07";
$rowToImport[8] = "f_zip_08";
$rowToImport[9] = "f_zip_09";
$rowToImport[10] = "f_zip_10";
$rowToImport[11] = "f_dummy";
$rowToImportLen = count($rowToImport);
// read file to import
$data = importCSV($importFile, $delimiter);
$dataLen = count($data);
// loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$zipcodeArray = array(); // Init
$f_zipcode = removeFieldSigns($f_zipcode);
$zipcodeArray[0] = $f_zipcode;
$zipcodeArray[1] = removeFieldSigns($f_zip_01);
$zipcodeArray[2] = removeFieldSigns($f_zip_02);
$zipcodeArray[3] = removeFieldSigns($f_zip_03);
$zipcodeArray[4] = removeFieldSigns($f_zip_04);
$zipcodeArray[5] = removeFieldSigns($f_zip_05);
$zipcodeArray[6] = removeFieldSigns($f_zip_06);
$zipcodeArray[7] = removeFieldSigns($f_zip_07);
$zipcodeArray[8] = removeFieldSigns($f_zip_08);
$zipcodeArray[9] = removeFieldSigns($f_zip_09);
$zipcodeArray[10] = removeFieldSigns($f_zip_10);
$zipcodeArrayLen = count($zipcodeArray);
$outText .= "(" . $j . ".) ";
if ($f_zipcode != "") : // ">1", because $zipcodeArray[1] ist first neighbour
if ($zipcodeArrayLen > 1) : // ">1", because $zipcodeArray[1] ist first neighbour
// Get srvp_id from serviceplz
$srvpId = getFieldValueFromId("phoenix.serviceplz", "srvp_plz", $f_zipcode, "srvp_id");
if ($srvpId != "") :
$outText .= $f_zipcode . " => ";
for ($z = 1; $z < $zipcodeArrayLen; $z++) : // ($z = 1) <=> First neighbour
if ($zipcodeArray[$z] != "") :
$srvpIdNeighbour = getFieldValueFromId("phoenix.serviceplz", "srvp_plz", $zipcodeArray[$z], "srvp_id");
if ($srvpIdNeighbour != "") :
// Insert into serviceplzneighbour if does not exist
if ($executeImportProcess == "1") :
if (!existsEntry("phoenix.serviceplzneighbour",array("hq_id", $hq_id, "srvp_id", $srvpId, "srvp2_id", $srvpIdNeighbour))) :
if ($fire) :
insertStmt("phoenix.serviceplzneighbour", array("hq_id", $hq_id, "srvp_id", $srvpId, "srvp2_id", $srvpIdNeighbour, "srvpn_sort", $z));
$outText .= "[" . $zipcodeArray[$z] . " : INS_OK] ";
else :
$outText .= "[" . $zipcodeArray[$z] . " : INS_RDY2IMP] "; // Ready to be imported
endif;
else :
$outText .= "[" . $zipcodeArray[$z] . " : EXISTS] ";
endif;
else :
$outText .= "[" . $zipcodeArray[$z] . "] ";
endif;
else :
$outText .= "<span class=\"f8np1_red\">" . "[" . getLngt("NB-PLZ " . $zipcodeArray[$z] . " NIB!") . "]</span> "; // Nachbar-PLZ nicht im Basisdatenbestand
endif;
else :
$outText .= "<span class=\"f8np1_red\">" . "[" . getLngt("NB-PLZ NA!") . "]</span> "; // Nachbar-PLZ nicht in der Importdatei angegeben
endif;
endfor;
else :
$outText .= "[" . getLngt("Basis-PLZ " . $f_zipcode . " wird im Basisdatenbestand nicht geführt!") . "] ";
endif;
else :
$outText .= getLngt("Keine Nachbar-PLZ angegeben!") . "<br>";
endif;
else :
$outText .= getLngt("Basis-PLZ nicht angegeben!") . "<br>";
endif;
$outText .= "<br>";
}
endif;
/*
TA("B");
TA("C");
TA("E");
*/
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Diese Datei muss für eine bestimmte Niederlassung verarbeitet werden!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_ZIPCODE_NEIGHBOURS.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

361
html/import/import_ZONE.php Normal file
View File

@@ -0,0 +1,361 @@
<?php
/*=======================================================================
*
* import_ZONE.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
include_once ("../import/import.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT ZONEN");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = true;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true;
// Customer and headquarters references have to exist
$hqId = "";
$csEid = "";
$objType = trim($objType);
$objId = trim($objId);
if ($objType == "CS" && is_numeric($objId)) :
// $csId = getFieldValueFromId("phoenix.customer", "cs_id", $objId, "cs_id");
$csId = $objId;
endif;
if ($csId != "") :
$hqId = getFieldValueFromId("phoenix.customer", "cs_id", $csId, "hq_id");
$csEid = getFieldValueFromId("phoenix.customer", "cs_id", $csId, "cs_eid");
endif;
if ($debug) :
echo "f_act : " . $f_act . "<br>";
echo "objType : " . $objType . "<br>";
echo "objId : " . $objId . "<br>";
echo "hqId : " . $hqId . "<br>";
echo "csId : " . $csId . "<br>";
echo "<br>";
endif;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
if ($importFile != "") :
if ($hqId != "" && $csId != "") :
// Create internal representation
$srvpArray = array();
$zoneArray = array();
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ********************
// * IMPORT FILE zone *
// ********************
if (!(strpos($filename, "import_ZONE_") === false)) :
// Gebietstyptyp; Land; PLZ; Preis
// Bsp.-Gebietstyptypen IKEA: 0=Kerngebiet, 1=Sekundärgebiet Nord, 2=Sekundärgebiet Süd, 3=Restgebiet Nord, 4=Restgebiet Süd, ...
// 0;DE;22844;
// 0;DE;22850;
// ...
// 1;DE;22xxx;
// ...
$rowToImport = array();
$rowToImport[0] = "f_zone_no";
$rowToImport[1] = "f_country";
$rowToImport[2] = "f_zipcode";
$rowToImport[3] = "f_price";
$rowToImport[4] = "f_price2";
$rowToImport[5] = "f_price3";
$rowToImport[6] = "f_dummy";
$rowToImportLen = count($rowToImport);
// read file to import
$data = importCSV($importFile, $delimiter);
$dataLen = count($data);
// loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_zone_no = removeFieldSigns($f_zone_no);
$f_country = removeFieldSigns($f_country);
$f_zipcode = removeFieldSigns($f_zipcode);
$f_price = removeFieldSigns($f_price);
$f_price2 = removeFieldSigns($f_price2);
$f_price3 = removeFieldSigns($f_price3);
if ($f_zipcode != "") :
if ($f_country == "" || !existsEntry("phoenix_special.country",array("cou_iso_2",$f_country))) :
$f_country = "DE";
endif;
// Convert price(s)
$f_price = str_replace (",", ".", $f_price);
$f_price2 = str_replace (",", ".", $f_price2);
$f_price3 = str_replace (",", ".", $f_price3);
// Get srvp_id from serviceplz
$srvpId = getFieldValueFromId("phoenix.serviceplz", "srvp_plz", $f_zipcode, "srvp_id");
if ($srvpId != "") :
// If country "Germany" then fill zipcode with "0" up to 5 chars
if ($f_country == "DE") :
$f_zipcode = pad($f_zipcode, 5);
endif;
// Set arrays
$srvpArray[] = array($srvpId, $f_zipcode, $f_zone_no, $f_country, $f_price, $f_price2, $f_price3);
$x = array_search($f_zone_no, $zoneArray);
if ($x === FALSE) :
$zoneArray[] = $f_zone_no;
endif;
else :
$outText .= getLngt("PLZ " . $f_zipcode . " wird im Basisdatenbestand nicht geführt!") . "<br>";
endif;
else :
$outText .= getLngt("Keine PLZ im Datensatz!") . "<br>";
endif;
}
if ($debug) :
// print_r($zoneArray); echo "<br><br>";
// print_r($srvpArray); echo "<br><br>";
endif;
// Insert new zone zipcodes into the database from internal structure
if ($fire && $executeImportProcess == "1") :
$zoneArrayLen = count($zoneArray);
$srvpArrayLen = count($srvpArray);
TA("B");
// Delete all mapped entries of a zone for a special headquarters and customer to be reimported
// Check for zones existing for the headquarters and the customer.
$csZonesToBeImported = array();
for ($k = 0; $k < $zoneArrayLen; $k++) :
// Get zone id (primary key) of the current zone number regarding hqId, csId
$srvz_id = getFieldValueFromClause("phoenix.servicezone","srvz_id","hq_id = '" . $hqId . "' AND cs_id = '" . $csId . "' AND srvz_no = '" . $zoneArray[$k] . "'");
// Delete mapped zipcodes
if ($srvz_id != "") :
$csZonesToBeImported[$zoneArray[$k]] = $srvz_id; // Define zones for zone mapppings to be deleted and reimported only
deleteStmt("phoenix.servicezonemapping","srvz_id = '" . $srvz_id . "'");
$outText .= getLngt("Zone " . $zoneArray[$k] . " für den Kunden " . $csEid . " wurde im Basisdatenbestand entfernt!") . "<br>";
else :
$outText .= getLngt("Die Zone " . $zoneArray[$k] . " für den Kunden " . $csEid . " wurde nicht gefunden! Wurden die Zonendaten eingerichtet?") . "<br>";
endif;
endfor;
// Get zones to be imported
$csZonesKeys = array_keys($csZonesToBeImported);
// $csZonesKeysLen = count($csZonesKeys);
// Import new zipcodes
$executionCount = 0;
$existingCount = 0;
for ($k = 0; $k < $srvpArrayLen; $k++) :
$x = array_search($srvpArray[$k][2], $csZonesKeys);
if (!($x === FALSE)) :
// Check for existence of mapping entry
if (!existsEntry("phoenix.servicezonemapping",array("srvz_id", $csZonesToBeImported[$srvpArray[$k][2]], "srvp_id", $srvpArray[$k][0]))) :
insertStmt("phoenix.servicezonemapping", array("srvz_id", $csZonesToBeImported[$srvpArray[$k][2]], "srvp_id", $srvpArray[$k][0], "srvzm_mt_1", $srvpArray[$k][4], "srvzm_mt_2", $srvpArray[$k][5], "srvzm_mt_3", $srvpArray[$k][6]));
$executionCount++;
else :
$existingCount++;
endif;
endif;
endfor;
TA("C");
TA("E");
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Eingefügte Einträge: " . $executionCount . "<br>");
$outText .= getLngt("Existierende Einträge: " . $existingCount . "<br>");
// $closeWindow = "1";
endif;
endif;
// ********************
// * IMPORT FILE xxxx *
// ********************
// if (!(strpos($filename, "import_xxxx") === false)) :
// endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Diese Datei muss für einen bestimmten Kunden verarbeitet werden!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
/*
CREATE TABLE servicezone (
srvz_id int(10) NOT NULL auto_increment,
hq_id int(10) NOT NULL default '0',
cs_id int(10) NOT NULL default '0',
srvz_no tinyint(3) default '0',
srvz_name varchar(50) NOT NULL default '',
srvz_price float(10,4) NOT NULL default '0.0000',
srvz_price2 float(10,4) NOT NULL default '0.0000',
PRIMARY KEY (srvz_id)
) ENGINE=InnoDB;
CREATE TABLE servicezonemapping (
srvz_id int(10) NOT NULL default '0',
srvp_id int(10) NOT NULL default '0'
) ENGINE=InnoDB;
*/
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_ZONE.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,304 @@
<?php
/*=======================================================================
*
* import_ZONEAGIO.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
include_once ("../import/import.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT ZONEAGIO");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = true;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true;
// Customer and headquarters references have to exist
$hqId = "";
$csEid = "";
$objType = trim($objType);
$objId = trim($objId);
if ($objType == "CS" && is_numeric($objId)) :
$csId = getFieldValueFromId("phoenix.customer", "cs_id", $objId, "cs_id");
endif;
if ($csId != "") :
$hqId = getFieldValueFromId("phoenix.customer", "cs_id", $csId, "hq_id");
$csEid = getFieldValueFromId("phoenix.customer", "cs_id", $csId, "cs_eid");
// Get zone IDs because an update of zipcodes has to be filtered by the zones of the current customer
$srvzIdArray = getColVectorFromDB2ArrayByClause("servicezone", "srvz_id", "cs_id = '" . $csId . "'", "", "", "");
$srvzIdArrayLen = count($srvzIdArray);
endif;
if ($debug) :
echo "f_act : " . $f_act . "<br>";
echo "objType : " . $objType . "<br>";
echo "objId : " . $objId . "<br>";
echo "hqId : " . $hqId . "<br>";
echo "csId : " . $csId . "<br>";
echo "srvzIdArray : " . implode(",", $srvzIdArray) . "<br>";
echo "<br>";
endif;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
if ($importFile != "") :
if ($hqId != "" && $csId != "" && $srvzIdArrayLen > 0) :
// Create internal representation
$srvpArray = array();
$srvzIdsOfCurrentCustomer = implode(",", $srvzIdArray); // Zone IDs of the current customer
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
$executionCount = 0;
$failedCount = 0;
// ********************
// * IMPORT FILE zone *
// ********************
if (!(strpos($filename, "import_ZONEAGIO_") === false)) :
// PLZ
// 22844
// 22850
// ...
// 22xxx
// ...
$rowToImport = array();
$rowToImport[0] = "f_zipcode";
$rowToImport[1] = "f_price";
$rowToImport[2] = "f_dummy";
$rowToImportLen = count($rowToImport);
// read file to import
$data = importCSV($importFile, $delimiter);
$dataLen = count($data);
// loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_zipcode = removeFieldSigns($f_zipcode);
$f_price = str_replace(",", ".", $f_price);
if ($f_price == "" || !is_numeric($f_price)) :
$f_price = "0.00";
endif;
$f_country = "";
if ($f_zipcode != "") :
if ($f_country == "" || !existsEntry("phoenix_special.country",array("cou_iso_2",$f_country))) :
$f_country = "DE";
endif;
// Get srvp_id from serviceplz
$srvpId = getFieldValueFromId("phoenix.serviceplz", "srvp_plz", $f_zipcode, "srvp_id");
if ($srvpId != "") :
// If country "Germany" then fill zipcode with "0" up to 5 chars
if ($f_country == "DE") :
$f_zipcode = pad($f_zipcode, 5);
endif;
// Set arrays
$srvpArray[] = array($f_zipcode, $srvpId, $f_country, $f_price);
else :
$outText .= getLngt("PLZ " . $f_zipcode . " wird im Basisdatenbestand nicht geführt!") . "<br>";
endif;
else :
$outText .= getLngt("Keine PLZ im Datensatz!") . "<br>";
endif;
}
// Insert new zone zipcodes into the database from internal structure
if ($fire && $executeImportProcess == "1") :
$srvpArrayLen = count($srvpArray);
TA("B");
// Remove ALL ZONEAGIO associations for the CURRENT CUSTOMER
updateStmt("phoenix.servicezonemapping", "", "", array("srvzm_mt_2", "0.00"), "srvz_id IN (" . $srvzIdsOfCurrentCustomer . ")");
// Associate zipcodes to be enabled for ZONEAGIO for the current customer
for ($k = 0; $k < $srvpArrayLen; $k++) :
$res = updateStmt("phoenix.servicezonemapping", "srvp_id", $srvpArray[$k][1], array("srvzm_mt_2", $srvpArray[$k][3]), "srvz_id IN (" . $srvzIdsOfCurrentCustomer . ")");
// Check update for success
if ($db->affected_rows > 0) :
$executionCount++;
$outText .= getLngt("Update PLZ:") . " " . $srvpArray[$k][0] . " " . getLngt("mit Preis") . " " . $srvpArray[$k][3] . "<br>";
else :
$failedCount++;
endif;
endfor;
TA("C");
TA("E");
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
$outText .= getLngt("Nicht verarbeitete Einträge: " . $failedCount . "<br>");
// $closeWindow = "1";
endif;
endif;
// ********************
// * IMPORT FILE xxxx *
// ********************
// if (!(strpos($filename, "import_xxxx") === false)) :
// endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Diese Datei muss für einen bestimmten Kunden verarbeitet werden!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_ZONEAGIO.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,596 @@
<?php
/*=======================================================================
*
* import_ZONE_JOBS.php
*
* Autor: Marc Vollmann
*
=======================================================================*/
// $doNotIncludeGeocode = true;
include_once ("../import/import.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_job.inc.php");
include_once ("../locating/xServer.inc.php");
// Execution-Time for script
set_time_limit(0);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
getLanguage(__FILE__);
$deactivateMenuStatic = "1";
$pageTitel = getLngt("IMPORT AUFTRÄGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);
// Check for authentication access
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
$empHasAdminRights = false;
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
$empHasAdminRights = true;
endif;
$debug = false;
if ($empIdRootAdmin == $emp_id) :
$debug = false;
endif;
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
$showExecutionProcessButton = true;
$outText = "";
$closeWindow = "0";
$delimiter = ";";
$fire = true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$currentDate = getDateTime(3);
$objType = strtolower($objType);
// Import for special customer ONLY !!!!
$csEid = "";
$cscIdPayer = "";
$srvzIdArray = array();
if ($objType == "cs" && $objId != "" && is_numeric($objId)) :
$csId = $objId;
endif;
if ($objType == "csc" && $objId != "" && is_numeric($objId)) :
$cscIdPayer = $objId;
$csId = getFieldValueFromClause("costcenter", "cs_id", "csc_id = '" . $cscIdPayer . "'");
endif;
if ($csId != "") :
$hqId = getFieldValueFromClause("customer", "hq_id", "cs_id = '" . $csId . "'");
$csEid = getFieldValueFromClause("customer", "cs_eid", "cs_id = '" . $csId . "'");
// Get root costcenter
$cscIdPayer = getFieldValueFromClause("costcenter", "csc_id", "cs_id = '" . $csId . "' AND (isnull(csc_pre_id) OR csc_pre_id = '')");
// Get zone ids (primary key) of the current customer
$srvzIdArray = getColVectorFromDB2ArrayByClause("phoenix.servicezone", "srvz_id", "hq_id = '" . $hqId . "' AND cs_id = '" . $csId . "'");
$csAddress = getAddress($csId, "costcenteraddress");
$adIdFrom = $csAddress["id"];
$adZipcodeFrom = $csAddress["zipcode"];
$adCityFrom = $csAddress["city"];
$adCountryFrom = $csAddress["country"];
$trHsnoFrom = $csAddress["hsno"];
if ($trHsnoFrom == "") : $trHsnoFrom = "."; endif;
$trCompFrom = $csAddress["comp"];
if ($trCompFrom == "") : $trCompFrom = "IMPORT"; endif;
$trFloorFrom = "";
endif;
if ($hqId == "") :
$hqId = $hq_id;
endif;
$srvzIdArrayLen = count($srvzIdArray);
$cscIdPayerExtern = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
$pickUpStationFinishedByDefault = true;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strrpos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span>&nbsp;" . $filename . "<br><br>";
// Mapping "tour id" to "vehicle SID"
/*
$tourVehicleArray = array();
$tourVehicleArray["294501"] = "E501";
$tourVehicleArray["294502"] = "E502";
$tourVehicleArray["294503"] = "E503";
$tourVehicleArray["294504"] = "E504";
$tourVehicleArray["294505"] = "E505";
$tourVehicleArray["294506"] = "E506";
$tourVehicleArray["294507"] = "E507";
$tourVehicleArray["294508"] = "E508";
$tourVehicleArray["294509"] = "E509";
$tourVehicleArray["294510"] = "E510";
$tourVehicleArray["294511"] = "E511";
$tourVehicleArray["294512"] = "E512";
$tourVehicleArray["294590"] = "E590";
*/
$tourCourierArray = array();
/*
$tourCourierArray["294501"] = "e8020201";
$tourCourierArray["294502"] = "e8020202";
$tourCourierArray["294503"] = "e8020203";
$tourCourierArray["294504"] = "e8020204";
$tourCourierArray["294505"] = "e8020205";
$tourCourierArray["294506"] = "e8020206";
$tourCourierArray["294507"] = "e8020207";
$tourCourierArray["294508"] = "e8020208";
$tourCourierArray["294509"] = "e8020209";
$tourCourierArray["294510"] = "e8020210";
$tourCourierArray["294511"] = "e8020211";
$tourCourierArray["294512"] = "e8020212";
$tourCourierArray["294590"] = "e8020213";
*/
function mcStrWrap ($aStr)
{
$aStr = str_replace("'", "", $aStr);
$aStr = removeFieldSigns($aStr);
// $aStr = str_replace("'", "\'", $aStr);
$aStr = str_replace("\"", '', $aStr);
return $aStr;
}
function eregPhoneNo_MC ($phoneNo) {
$phoneNo = str_replace("'", "", $phoneNo);
$phoneNo = preg_replace ("/ /", "", $phoneNo); // Remove blanks
$phoneNo = preg_replace ("/-/", "", $phoneNo); // Remove sign "-"
$phoneNo = str_replace("/", "", $phoneNo); // Remove sign "/"
// $phoneNo = preg_replace ("/^\+/", "00", $phoneNo); // Remove country prefix sign "+" with "00"
// $phoneNo = preg_replace ("/^00" . $parCountryPhonePrefix . "/", "0", $phoneNo); // Remove country prefix with "0"
// $phoneNo = preg_replace ("/^00/", "", $phoneNo); // Remove leading "00"
// $phoneNo = preg_replace ("/^0/", "", $phoneNo); // Remove leading "0"
return $phoneNo;
}
/*
echo "importFile: " . $importFile . "<br>";
echo "hqId: " . $hqId . "<br>";
echo "csId: " . $csId . "<br>";
*/
if ($importFile != "" && $hqId != "" && is_numeric($hqId) && $csId != "" && is_numeric($csId)) :
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ***********************
// * IMPORT FILE article *
// ***********************
if (!(strpos($filename, $csEid . "_import_ZONE_JOBS_") === false)) :
if ($srvzIdArrayLen > 0) :
$executionCount = 0;
$insertCount = 0;
$updateCount = 0;
$failedCount = 0;
$txValue = "4";
$txSign = "V";
$jbZoneIdArray = array(); // Associative array ($jbZoneIdArray[zone] = jbId)
$jbTrSortArray = array(); // Associative array ($jbTrSortArray[jbId] = trSort)
$jbTrIdArray = array(); // Associative array ($jbTrIdArray[jbId][trSort] = trId)
$jbTourdataZipcodeArray = array(); // Associative array ($jbTourdataZipcodeArray[jbId] = "....")
$jbTourdataCityArray = array(); // Associative array ($jbTourdataCityArray[jbId] = "....")
$jbTourdataCountryArray = array(); // Associative array ($jbTourdataCountryArray[jbId] = "....")
$rowToImport = array();
$parImportFieldsGroup == "";
if ($groupId != "") :
$parImportFieldsGroup = getParameterValue("0", "IMPORT_ZONE_JOBS_JOB_FIELDS", "0");
endif;
if ($parImportFieldsGroup != "") :
$rowToImport = spliti(",", $parImportFieldsGroup);
else :
/*
Debitor Name 1 Straße Postleitz. Ort Telefon-1 Bar
*/
$rowToImport[0] = "f_tr_commission_no"; // A : Kommissionsnummer
$rowToImport[1] = "f_tr_comp"; // B : Bezeichnung
$rowToImport[2] = "f_ad_street"; // C : Straße und Hausnummer
// $rowToImport[3] = "f_tr_hsno"; // : Hausnummer
$rowToImport[3] = "f_ad_zipcode"; // D : PLZ
$rowToImport[4] = "f_ad_city"; // E : Ort
$rowToImport[5] = "f_tr_phone"; // F : Telefon
$rowToImport[6] = "f_cash"; // G : "Bar"
$rowToImport[7] = "f_dummy_01"; // H : ?
endif;
$rowToImportLen = count($rowToImport);
// Read file to import
$data = importCSV($importFile, $delimiter, "1");
$dataLen = count($data);
// Loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// Loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
// Check for existing headline
if ($j > 0) :
$f_tr_commission_no = mcStrWrap($f_tr_commission_no);
$f_tr_comp = mcStrWrap($f_tr_comp);
$f_ad_street = mcStrWrap($f_ad_street);
$f_tr_hsno = "";
$f_ad_zipcode = mcStrWrap($f_ad_zipcode);
$f_ad_city = mcStrWrap($f_ad_city);
// $f_tr_phone = mcStrWrap($f_tr_phone);
$f_cash = mcStrWrap($f_cash);
if ($f_tr_hsno == "") : $f_tr_hsno = "."; endif;
$f_tr_phone = eregPhoneNo_MC($f_tr_phone);
$f_ad_country = "DE";
$clockTime = "11:00:00";
$f_jb_ordertime = $currentDate . " " . $clockTime;
// **** Check zone of given zipcode for the customer ****
$srvzNo = "";
$srvzName = "";
// Get srvp_id from serviceplz
$srvpId = getFieldValueFromId("phoenix.serviceplz", "srvp_plz", $f_ad_zipcode, "srvp_id");
if ($srvpId != "") :
// If country "Germany" then fill zipcode with "0" up to 5 chars
if ($f_ad_country == "DE") :
$f_ad_zipcode = pad($f_ad_zipcode, 5);
endif;
// Get zone ids (primary key) of the current customer
// $srvzIdArray = getColVectorFromDB2ArrayByClause("phoenix.servicezone", "srvz_id", "hq_id = '" . $hqId . "' AND cs_id = '" . $csId . "'");
// $srvzIdArrayLen = count($srvzIdArray);
// => Zones got for customer before entering the loops (!!!!)
// if ($srvzIdArrayLen > 0) :
// Get zone id from mapping
$srvz_id = getFieldValueFromClause("phoenix.servicezonemapping", "srvz_id", "srvp_id = '" . $srvpId . "' AND srvz_id IN (" . implode(",", $srvzIdArray) . ")");
if ($srvz_id != "") :
$srvzNo = getFieldValueFromId("phoenix.servicezone", "srvz_id", $srvz_id, "srvz_no");
$srvzName = getFieldValueFromId("phoenix.servicezone", "srvz_id", $srvz_id, "srvz_name");
else :
$outText .= getLngt("Die PLZ " . $f_ad_zipcode . " ist keiner Zone des Kunden zugeordnet! Wurden PLZn den Zonendaten assoziiert?") . "<br>";
endif;
// else :
// $outText .= getLngt("Für den Kunden " . $csEid . " werden derzeit keine Zonen im Datenbestand geführt!") . "<br>";
// endif;
else :
$outText .= getLngt("PLZ " . $f_ad_zipcode . " wird im Basisdatenbestand nicht geführt!") . "<br>";
endif;
if ($srvzNo != "") :
// **** Courier ****
// Set vehicle and courier
$crId = "";
/*
$crSid = $tourVehicleArray[$f_jb_tourname];
if ($crSid != "") :
$crId = getFieldValueFromId("courier","cr_sid",$crSid,"cr_id");
endif;
*/
$crEid = $tourCourierArray[$f_jb_tourname];
if ($crEid != "") :
$crId = getFieldValueFromId("courier","cr_eid",$crEid,"cr_id");
endif;
$jbStatus = "9";
$jbTaketime = "";
if ($crId != "" && is_numeric($crId)) :
$jbStatus = "1";
$jbTaketime = $currentTime;
endif;
$jbType = "";
$jbFinishtime = "";
$jbRemark = "";
$vhtId = "";
$jbCrFilter = "";
$sum_totalprice = 0;
$f_jb_cr_price = 0;
$jbCrvhWeight = 0;
$jbCrvhLength = 0;
$jbCrvhWidth = 0;
$jbCrvhHeight = 0;
$jbCrvhPosition = 0;
$f_tr_ware_from_to = 0;
// $f_jb_tourname = $csEid . ": Zone " . $srvzNo;
$f_jb_tourname = "";
$f_tr_remark = "";
if ($f_cash != "") :
$f_tr_remark = "**** BARZAHLUNG ****";
endif;
echo $f_tr_commission_no . ";" . $f_tr_comp . ";" . $f_ad_street . ";" . $f_tr_hsno . ";" . $f_ad_zipcode . ";" . $f_ad_city . ";";
echo $f_tr_phone . ";" . $f_cash . ";";
echo "<br>";
// Check for existence of the imported "tour name" AND "station number" (unique for station)
$gdcEntryExists = false;
if (existsEntry("genericdatacontainer",array("gdc_obj_type","tr","gdc_gen_fieldname","check_exist","gdc_content",$csId . "_" . $currentDate . "_" . $j . "_" . $f_tr_commission_no,"gdc_context","ZONE_JOBS"))) :
$gdcEntryExists = true;
endif;
// Do NOT import if ZONE_JOBS number does exist !!!!
if (!$gdcEntryExists) :
// Insert new article
if ($executeImportProcess == "1") :
TA("B");
/*
$crId = "";
$crSid = "";
if ($crvhId != "") :
$crId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"cr_id");
if ($crId != "") :
$crSid = $vhtPrefix . $f_crvh_sid;
endif;
endif;
*/
// Insert address
$noValidationOfAddress = true;
$tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
$ad_id_new = $tmpArray[0];
$outText .= "AD_ID : " . $ad_id_new . " | ";
if ($fire) :
// Insert new job because new cartage note does begin
if ($jbZoneIdArray[$srvzNo] == "") :
// Insert job
insertStmt("job", array("hq_id", $hqId, "csc_id", "", "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", "0", "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0",
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType,
"jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id,
"jb_serviceprice", "0", "jb_fixprice", $sum_totalprice, "jb_totalprice", $sum_totalprice, "jb_subtotalprice", $sum_totalprice,
"jb_cr_price", $f_jb_cr_price, "jb_cr_subprice", $f_jb_cr_price,
"jb_postage", "0", "jb_freetext_1", $jbRemark,
"jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth,
"jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition,
"jb_tourdata", "", "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
"jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_timeunits", "0",
"jb_service", "", "jb_booktime", ""));
$jbZoneIdArray[$srvzNo] = getLastInsertId();
$jbTrSortArray[$jbZoneIdArray[$srvzNo]] = 1;
// Insert pick up station after job is generated
if ($jbZoneIdArray[$srvzNo] != "") :
insertStmt("tour", array("jb_id", $jbZoneIdArray[$srvzNo], "ad_id", $adIdFrom, "tr_sort", "1", "tr_comp", $trCompFrom, "tr_comp2", "",
"tr_hsno", $trHsnoFrom, "tr_floor", $trFloorFrom, "csc_id", $cscIdPayer, "tr_status", $trStatus, "tr_finishtime", $trFinishtime,
"tr_commission_no", "", "tr_ware_from_to", $f_tr_ware_from_to, "tr_person", "", "tr_phone", "", "tr_remark", ""));
$jbTrIdArray[$jbZoneIdArray[$srvzNo]][1] = getLastInsertID();
$jbTourdataZipcodeArray[$jbZoneIdArray[$srvzNo]][] = $adZipcodeFrom;
$jbTourdataCityArray[$jbZoneIdArray[$srvzNo]][] = $adCityFrom;
$jbTourdataCountryArray[$jbZoneIdArray[$srvzNo]][] = $adCountryFrom;
endif;
endif;
// Check for inserted job
if ($jbZoneIdArray[$srvzNo] != "") :
$jbTrSortArray[$jbZoneIdArray[$srvzNo]]++;
insertStmt("tour", array("jb_id", $jbZoneIdArray[$srvzNo], "ad_id", $ad_id_new, "tr_sort", $jbTrSortArray[$jbZoneIdArray[$srvzNo]], "tr_comp", $f_tr_comp, "tr_comp2", "",
"tr_hsno", $f_tr_hsno, "csc_id", $cscIdPayerExtern, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "",
"tr_person", $f_tr_person, "tr_phone", $f_tr_phone, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$jbTrIdArray[$jbZoneIdArray[$srvzNo]][$jbTrSortArray[$jbZoneIdArray[$srvzNo]]] = getLastInsertID();
// Insert tourservice data
insertStmt("tourservice", array("jb_id", $jbZoneIdArray[$srvzNo], "csc_id", $cscIdPayer, "tr_sort", $jbTrSortArray[$jbZoneIdArray[$srvzNo]], "srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "", "trs_price", $sum_totalprice));
// Generate invoice text
// mk_jb_invtext($jbIdNew, false);
// Tourname
insertStmt("genericdatacontainer", array("gdc_obj_type", "tr", "gdc_obj_id", $jbTrIdArray[$jbZoneIdArray[$srvzNo]][$jbTrSortArray[$jbZoneIdArray[$srvzNo]]], "gdc_gen_fieldname", "check_exist", "gdc_content", $csId . "_" . $currentDate . "_" . $j . "_" . $f_tr_commission_no, "gdc_context", "ZONE_JOBS"));
$jbTourdataZipcodeArray[$jbZoneIdArray[$srvzNo]][] = $f_ad_zipcode;
$jbTourdataCityArray[$jbZoneIdArray[$srvzNo]][] = $f_ad_city;
$jbTourdataCountryArray[$jbZoneIdArray[$srvzNo]][] = $f_ad_country;
$executionCount++;
endif;
TA("C");
TA("E");
endif;
endif;
else :
$outText .= getLngt("Der Datensatz existiert schon! Es erfolgte kein Import!") . " [" . $currentDate . " " . $f_tr_commission_no . "]<br>";
endif;
else :
$outText .= getLngt("Eine gültige Zonen-ID liegt nicht vor! Es erfolgte kein Import!") . " [" . $f_tr_commission_no . "]<br>";
endif;
endif; // Check for headline
}
// If at least one imported job does exist ($jbIdNew > 0) then finalize last imported job
// Write "jb_tourdata" of the job currently imported and write log regarding B2B-Import
if ($fire && $executeImportProcess == "1") :
$jbTourdataZipcodeKeysArray = array_keys($jbTourdataZipcodeArray); // The keys are job IDs
$jbTourdataZipcodeKeysArrayLen = count($jbTourdataZipcodeKeysArray);
if ($jbTourdataZipcodeKeysArrayLen > 0) :
for ($k = 0; $k < $jbTourdataZipcodeKeysArrayLen; $k++) :
$jbId = $jbTourdataZipcodeKeysArray[$k];
if ($jbId != "") :
$jbTourdata = implode(";", $jbTourdataZipcodeArray[$jbId]) . "|" . implode(";", $jbTourdataCityArray[$jbId]) . "|" . implode(";", $jbTourdataCountryArray[$jbId]);
updateStmt("job","jb_id",$jbId,array("jb_tourdata",$jbTourdata));
writeToLogDB("102",$hqId,$jbId,$usr_id,"","",$csId,"B2B_IMPORT=1"); // Success!
endif;
endfor;
endif;
endif;
// Sort jobs after all operations are done well (same loop !!!!)
if ($fire && $executeImportProcess == "1") :
$jbTourdataZipcodeKeysArray = array_keys($jbTourdataZipcodeArray); // The keys are job IDs
$jbTourdataZipcodeKeysArrayLen = count($jbTourdataZipcodeKeysArray);
if ($jbTourdataZipcodeKeysArrayLen > 0) :
for ($k = 0; $k < $jbTourdataZipcodeKeysArrayLen; $k++) :
$jbId = $jbTourdataZipcodeKeysArray[$k];
if ($jbId != "") :
$optResult = XSplanTourJob($jbId);
if ($optResult) :
$outText .= getLngt("Der Auftrag " . $jbId . " konnte optimiert werden!<br>");
else :
$outText .= getLngt("Der Auftrag " . $jbId . " konnte NICHT optimiert werden!<br>");
endif;
endif;
endfor;
endif;
endif;
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
$outText .= getLngt("Verarbeitete Einträge: " . $executionCount . "<br>");
else :
$statusMessage .= getLngt("Für den Kunden " . $csEid . " sind keine Zonen angelegt!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei scheint nicht kompatibel zur angeforderten Importfunktionalität!");
endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
?>
<html>
<head>
<title><?php echo $pageTitel ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
<?php include_once ("../css/navigation.css.php"); ?>
</style>
<?php include_once ("../include/js_framework.inc.php"); ?>
<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>
function finishPageExecuteImportProcess(f_act) {
document.forms[0].f_act.value=f_act;
document.forms[0].executeImportProcess.value = '1';
document.forms[0].submit();
};
function onBodyLoad() {
displayStatusMessage();
var closeWindow = '<?php echo $closeWindow ?>';
if (closeWindow == '1') {
opener.document.forms[0].submit();
window.close();
};
};
-->
</script>
</head>
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>
<div class="maincontent" name="maincontent" id="maincontent">
<div>
<form name="import_form" action="../import/import_ZONE_JOBS.php" method="post">
<input type="hidden" name="f_act" value="">
<?php echo $phpCurrentNavigationInputHidden ?>
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
<?php echo htmlDivLineSpacer("10px"); ?>
<?php
if ($showExecutionProcessButton && $executeImportProcess != "1") :
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
echo htmlDivLineSpacer("5px");
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
echo htmlDivLineSpacer("5px");
endif;
?>
<?php echo htmlDivLineSpacer("20px"); ?>
<div>
<table border="1" margin="10" padding="10">
<tr>
<td style="vertical-align:top;">
<?php echo $outText; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,449 @@
<?php
/*=======================================================================
*
* import_generic.php
*
* Autor: Marc Vollmann
*
* ToDoS :
* [1] Configuration in php.ini:
* "file_uploads", "upload_max_filesize", "upload_tmp_dir", "post_max_size"
* [2] Change tables "tour" and "tourhistory"
* ALTER TABLE `tour` ADD `tr_cs_freetext` TEXT;
* ALTER TABLE `tourhistory` ADD `tr_cs_freetext` TEXT;
* [3] Create table "import_log"
* CREATE TABLE import (imp_id int(10) NOT NULL default '0',imp_pos smallint(6) NOT NULL default '0', imp_createtime timestamp(14) NOT NULL, jb_id int(10) NOT NULL default '0', UNIQUE KEY imp_id_pos (imp_id,imp_pos)) TYPE=MyISAM;
* [4] Exportcategoryfields have to be inserted
* DELETE FROM `exportcategoryfields` WHERE expc_id = '110'
* => Start Insert-Script
*
=======================================================================*/
include_once ("import.php");
// Execution-Time for script
set_time_limit(30000);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "f_importFile", "f_uploadFile"));
// Select user-type for mode of security check
$userType = getFieldValueFromId("user","usr_id",$usr_id,"usr_type");
$userTypeName = getUserTypeName($userType);
// Get the rights of the employee logged in and check the accessibility
if (!authCheckEmployeeRights($emp_id, "7")) : die ("$PHP_SELF: Access denied!"); endif;
$statusMessage = "";
$importFileStatusMsg = "";
$jbIdNew = "";
$fJbTourname = "";
$fTrSort = "";
// Get number of files in the upload folder
$numOfFiles = getNumOfFilesInFolder($importPath);
// Process uploaded file
if ($f_act == "uploadFile") :
if ($numOfFiles < 1) :
if ($_FILES['f_uploadFile']['size'] <= 2000000) :
if (!move_uploaded_file($_FILES['f_uploadFile']['tmp_name'], $importPath . $_FILES['f_uploadFile']['name'])) :
$statusMessage .= "Die Datei wurde leider nicht hochgeladen!";
endif;
else :
$statusMessage .= "Die Datei ist für den Upload zu groß!";
// Delete real file if does exist
$retVal = removeFile($_FILES['f_uploadFile']['name'], $importPath, $pathSeparator);
endif;
// Delete temp file if does exist
$retVal = removeFile($_FILES['f_uploadFile']['tmp_name'], $tempPath, $pathSeparator);
else :
$statusMessage .= "Bevor eine weitere Datei hochgeladen werden kann, muss das Verzeichnis geleert werden!";
endif;
endif;
// Manually removal of a specified importfile
if ($f_act == "removeImportfile") :
// Remove import file
$retVal = removeFile($f_importFile, $importPath, $pathSeparator);
if ($retVal == "0") :
elseif ($retVal == "-1") :
$statusMessage = "Es liegt kein Dateiname vor!";
elseif ($retVal == "-2") :
$statusMessage = "Die Datei befindet sich nicht mehr in dem Verzeichnis!";
elseif ($retVal == "") :
$statusMessage = "Es fand keine Löschung statt!";
endif;
endif;
// Import process
if ($f_act == "goImport") :
if ($numOfFiles == 1) :
$importFileStatusMsg .= "<br><br><br><br><span class=\"f12bp1_red\" colspan=\"2\">Verarbeitungsprotokoll:</span><br><br>";
$importFileStatusMsg .= "Import-Datei: " . $f_importFile . "<br><br>";
$rowToImport = array();
$rowToImport[0] = "f_position"; // position
$rowToImport[1] = "f_tr_person"; // externalOrderID
$rowToImport[2] = "f_dummy_01"; // dummy
$rowToImport[3] = "f_tr_ware_from_to"; // type
$rowToImport[4] = "f_tr_comp_01"; // name 1
$rowToImport[5] = "f_tr_comp2_01"; // name 2
$rowToImport[6] = "f_ad_street_01"; // pickup/street
$rowToImport[7] = "f_ad_zipcode_01"; // pickup/zipCode
$rowToImport[8] = "f_ad_city_01"; // pickup/city
$rowToImport[9] = "f_tr_remark_1"; // goodsdescription
$rowToImport[10] = "f_tr_commission_no"; // loadingUnitType
$rowToImport[11] = "f_jb_ordertime_01"; // pickup/plannedPickup
$rowToImport[12] = "f_jb_tourname"; // tourID
$rowToImportLen = count($rowToImport);
// read file to import
$data = importCSV($importPath . $f_importFile);
$dataLen = count($data);
// loop all rows
for ($j = 0; $j < $dataLen; $j++) {
// loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
// Next job begins
if ($fJbTourname == "" || $fJbTourname != $f_jb_tourname) :
$jbIdNew = "";
$fTrSort = "";
$fJbTourname = $f_jb_tourname;
endif;
// Check import log table in db according to the unique key "tourID + position" (<=> $f_jb_tourname + $f_position)
$logJbId = getFieldValueFromClause("phoenix_log.import","jb_id","imp_id = '" . $f_jb_tourname . "' AND imp_pos = '" . $f_position . "'");
if ($logJbId == "") :
TA("B");
$f_position = trim($f_position);
$f_tr_person = trim($f_tr_person);
$f_tr_ware_from_to = trim($f_tr_ware_from_to);
$f_tr_comp_01 = trim($f_tr_comp_01);
$f_tr_comp2_01 = trim($f_tr_comp2_01);
$f_ad_street_01 = trim($f_ad_street_01);
$f_ad_zipcode_01 = trim($f_ad_zipcode_01);
$f_ad_city_01 = trim($f_ad_city_01);
$f_tr_remark_1 = trim($f_tr_remark_1);
$f_tr_commission_no = trim($f_tr_commission_no);
$f_jb_ordertime_01 = trim($f_jb_ordertime_01);
$f_jb_tourname = trim($f_jb_tourname);
$f_cs_eid = trim($f_cs_eid);
if ($f_ad_street_01 == "") : $f_ad_street_01 = "."; endif;
if ($f_ad_zipcode_01 == "") : $f_ad_zipcode_01 = "."; endif;
if ($f_ad_city_01 == "") : $f_ad_city_01 = "."; endif;
// Constants
$cscIdCashPayer = getParameterValue("0", "CSC_ID_PAYER_CASH", $f_hq_id);
// Concatenation of external cs_eid and name
// $f_tr_comp_01 = $f_cs_eid . " " . $f_tr_comp_01;
$f_tr_comp_01 = $f_tr_comp_01 . " " . $f_tr_comp2_01;
$f_tr_comp2_01 = "";
if ($f_tr_ware_from_to == "Rücknahme") :
$f_tr_ware_from_to = "1";
elseif ($f_tr_ware_from_to == "Installation") :
$f_tr_ware_from_to = "2";
else :
$f_tr_ware_from_to = "0";
endif;
$f_tr_remark = $f_tr_remark_1; // . " " . $f_tr_remark_2 . " " . $f_tr_remark_3 . " " . $f_jb_ordertime_02;
// Extra field "internal remark of the customer" for customer export
$f_tr_cs_freetext = $f_tr_remark;
// Format date field
$dVal = $f_jb_ordertime_01;
$f_jb_ordertime_01 = substr($dVal,6,4) . "-" . substr($dVal,3,2) . "-" . substr($dVal,0,2) . " 10:00";
// Split street to street and houseno.
$f_tr_hsno_01 = ".";
$f_tr_hsno_02 = ".";
// Get 1. address id
$tmpArray = insertAddress($f_ad_street_01, $f_ad_zipcode_01, $f_ad_city_01, "", "", true);
$ad_id_new_01 = $tmpArray[0];
// Get the current time
$currentTime = getDateTime("0");
// Insert job data
if ($jbIdNew == "") :
$jbStatus = "9";
$jbType = "2"; // "G"
$crId = "";
$crSid = "";
$jbFinishtime = "";
$csInvmod = "";
$price = 0;
if (!isset($f_tax_value) || $f_tax_value == ""):
$f_tax_value = getFieldValueFromId("tax","tx_id","4","tx_value");
if ($f_tax_value == ""):
$f_tax_value = "19.00";
endif;
endif;
$txSign = "V";
// Mapping of the headquarters
$tmpZipcode = substr($f_ad_zipcode_01 ,0 ,1); // Get the first character
if ($tmpZipcode == "0") :
$f_hq_id = "108"; // Leipzig
$f_cs_eid_payer = "HTL40098";
$trCscIdRoot_01 = "44548"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44548"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "3") :
$f_hq_id = "104"; // Hannover
$f_cs_eid_payer = "HTH40105";
$trCscIdRoot_01 = "44545"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44545"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "4") :
$f_hq_id = "107"; // Essen
// $f_cs_eid_payer = "HTE10496";
$f_cs_eid_payer = "HTE10977";
$trCscIdRoot_01 = "44543"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44543"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "6") :
$f_hq_id = "105"; // Frankfurt
$f_cs_eid_payer = "HTF40090";
$trCscIdRoot_01 = "44544"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44544"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "7") :
$f_hq_id = "111"; // Stuttgart
$f_cs_eid_payer = "HTS10799";
$trCscIdRoot_01 = "44547"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44547"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "8") :
$f_hq_id = "109"; // München
$f_cs_eid_payer = "HTM65105";
$trCscIdRoot_01 = "44549"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44549"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "9") :
$f_hq_id = "109"; // München
$f_cs_eid_payer = "HTM65105";
$trCscIdRoot_01 = "44549"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44549"; // Hauptkostenstelle Kunde "Extern"
else :
$f_hq_id = "107"; // Essen (Default !!!)
// $f_cs_eid_payer = "HTE10496";
$f_cs_eid_payer = "HTE10977";
$trCscIdRoot_01 = "44543"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44543"; // Hauptkostenstelle Kunde "Extern"
// 44539 101 44540 102 44541 103 44542 106 44546 110
endif;
$csId = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cs_id");
$cscIdRoot = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"csc_id");
// if ($isCashPayerTour): $cscIdRoot = $cscIdCashPayer; endif;
$csInvmode = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cs_invmode");
$cmpPostage = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cmp_id");
if ($cmpPostage == "") : $cmpPostage = "0.00"; endif;
// Check for absolute customer discount
$csDiscountAbsolute = getFieldValueFromId("customer", "cs_id", $csId, "cs_discount");
$useDicountDisabled = getParameterValue("0", "JB_EDITBATCH_DISCOUNT_DISABLED");
if ($useDicountDisabled == "1") :
$csDiscountAbsolute = 0;
endif;
// Mapping of the vehicle type
if ($f_vht_id == "1") :
$f_vht_id = "8"; // 3-To.
elseif ($f_vht_id == "2") :
$f_vht_id = "9"; // 5-To.
elseif ($f_vht_id == "3") :
$f_vht_id = "7"; // 1-To.
else :
$f_vht_id = "8"; // 3-To.
endif;
insertStmt("job", array("hq_id", $f_hq_id, "vht_id", $f_vht_id, "csc_id_payer", $cscIdRoot, "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime_01, "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_taketime", "", "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType, "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id, "jb_fixprice", $f_price, "jb_totalprice", $f_price,
"jb_postage", $cmpPostage, "jb_invmode", $csInvmode, "jb_freetext_1", "",
"jb_sales_tax_rate", $f_tax_value, "jb_sales_tax_rate_sign", $txSign, "jb_booktime", ""));
$jbIdNew = getLastInsertId();
// Insert tour data for station
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new_01, "tr_sort", "1", "tr_comp", $f_tr_comp_01, "tr_comp2", $f_tr_comp2_01,
"tr_hsno", $f_tr_hsno_01, "csc_id", $trCscIdRoot_01, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", $f_tr_ware_from_to,
"tr_person", $f_tr_person, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
// Insert tourservice data
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdRoot, "tr_sort", "0",
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $price, "trs_discount", $csDiscountAbsolute));
// Write logdata into log database
writeToLogDB("55",$hq_id,$jbIdNew,$usr_id,"","","",$csId);
$importFileStatusMsg .= "Station 1 des Auftrags " . $jbIdNew . " wurde importiert.<br>";
else :
if ($fTrSort == "") :
$fTrSort = "2";
else :
$fTrSort++;
endif;
// Update job data
// updateStmt("job","jb_id",$jbIdNew,array("usr_name",$f_usr_name,"usr_firstname",$f_usr_firstname));
// Insert tour data
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new_01, "tr_sort", $fTrSort, "tr_comp", $f_tr_comp_01, "tr_comp2", $f_tr_comp2_01,
"tr_hsno", $f_tr_hsno_01, "csc_id", $trCscIdRoot_01, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", $f_tr_ware_from_to,
"tr_person", $f_tr_person, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$importFileStatusMsg .= "Station " . $fTrSort . " des Auftrags " . $jbIdNew . " wurde importiert.<br>";
endif;
// Insert into import log table
insertStmt("phoenix_log.import", array("imp_id", $f_jb_tourname, "imp_pos", $f_position, "imp_createtime", $currentTime, "jb_id", $jbIdNew));
TA("C");
TA("E");
else :
$importFileStatusMsg .= "Datensatz " . $j . " wurde NICHT importiert, weil sie schon importiert wurde! (Auftrag " . $logJbId . ")<br>";
endif;
}
// Remove import file
$retVal = removeFile($f_importFile, $importPath, $pathSeparator);
else :
$importFileStatusMsg .= "Der Import konnte nicht vollzogen werden, da noch mindestens eine andere Importdatei existiert!<br>";
endif;
endif;
// **************************************************
// * Read all of the local filenames to be imported *
// **************************************************
if ($userTypeName == "hq") :
// Get filenames
$fileNames = getFilenamesInFolder($importPath);
$storedImportFiles .= "<table>";
$storedImportFiles .= "<tr><td class=\"f12bp1_red\" colspan=\"2\">Auftragsimport</td></tr>";
$storedImportFiles .= "<tr><td colspan=\"2\"><br><br></td></tr>";
// Define table header
$storedImportFiles .= "<tr><td>Dateiname&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Löschen</td></tr>";
$storedImportFiles .= "<tr><td colspan=\"2\"><br></td></tr>";
// Define table body from array
$fileNamesLen = count($fileNames);
for ($j = 0; $j < $fileNamesLen; $j++) :
$storedImportFiles .= "<tr>";
$storedImportFiles .= "<td><a href=\"javascript:importImportfile('" . $fileNames[$j] . "');\">" . $fileNames[$j] .
"</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedImportFiles .= "<td align=\"center\"><a href=\"javascript:removeImportfile('" . $fileNames[$j] . "');\">"
. "<img src=\"../images/trash.jpg\" border=\"0\" height=\"13\" width=\"8\">"
. "</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedImportFiles .= "</tr>";
endfor;
$storedImportFiles .= "</table>";
endif;
?>
<html>
<head>
<title>AUFTRAGSIMPORT</title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<script type="text/javascript">
<!--
var statusMessage = "<?php echo $statusMessage ?>";
function displayStatusMessage() {
if (statusMessage != "") {
alert(statusMessage);
}
};
function finishPage(f_act_value) {
document.forms[0].f_act.value=f_act_value;
document.forms[0].submit();
};
function removeImportfile(fileName) {
if (confirm('Importdatei ' + fileName + ' entfernen?')) {
document.forms[0].f_importFile.value = fileName;
finishPage('removeImportfile');
};
};
function importImportfile(fileName) {
if (confirm('Importdatei ' + fileName + ' jetzt importieren?')) {
document.forms[0].f_importFile.value = fileName;
finishPage('goImport');
};
};
function finishPageUpload(f_act_value) {
document.forms[1].f_act.value=f_act_value;
document.forms[1].submit();
};
-->
</script>
</head>
<body onLoad="displayStatusMessage();">
<form name="import_form" action="../import/import_job.php" method="post">
<input type="hidden" name="f_act" value="">
<input type="hidden" name="f_importFile" value="">
<?php echo $storedImportFiles; ?>
</form>
<br><br>
<form name="upload_file" action="../import/import_job.php" enctype="multipart/form-data" method="post">
<!-- <form name="upload_file" action="../import/upload_file.php" enctype="multipart/form-data" method="post"> -->
<input type="hidden" name="f_act" value="">
<p>W&auml;hlen Sie die Auftragsdateidatei von Ihrem Rechner aus:<br>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="f_uploadFile" type="file" size="50" accept="text/*">
<input type="button" value="Upload" onClick="finishPageUpload('uploadFile');">
</p>
<br><br>
<?php echo $importFileStatusMsg; ?>
</form>
</body>
</html>

View File

@@ -0,0 +1,449 @@
<?php
/*=======================================================================
*
* import_job.php
*
* Autor: Marc Vollmann
*
* ToDoS :
* [1] Configuration in php.ini:
* "file_uploads", "upload_max_filesize", "upload_tmp_dir", "post_max_size"
* [2] Change tables "tour" and "tourhistory"
* ALTER TABLE `tour` ADD `tr_cs_freetext` TEXT;
* ALTER TABLE `tourhistory` ADD `tr_cs_freetext` TEXT;
* [3] Create table "import_log"
* CREATE TABLE import (imp_id int(10) NOT NULL default '0',imp_pos smallint(6) NOT NULL default '0', imp_createtime timestamp(14) NOT NULL, jb_id int(10) NOT NULL default '0', UNIQUE KEY imp_id_pos (imp_id,imp_pos)) TYPE=MyISAM;
* [4] Exportcategoryfields have to be inserted
* DELETE FROM `exportcategoryfields` WHERE expc_id = '110'
* => Start Insert-Script
*
=======================================================================*/
include_once ("import.php");
// Execution-Time for script
set_time_limit(30000);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "f_importFile", "f_uploadFile"));
// Select user-type for mode of security check
$userType = getFieldValueFromId("user","usr_id",$usr_id,"usr_type");
$userTypeName = getUserTypeName($userType);
// Get the rights of the employee logged in and check the accessibility
if (!authCheckEmployeeRights($emp_id, "7")) : die ("$PHP_SELF: Access denied!"); endif;
$statusMessage = "";
$importFileStatusMsg = "";
$jbIdNew = "";
$fJbTourname = "";
$fTrSort = "";
// Get number of files in the upload folder
$numOfFiles = getNumOfFilesInFolder($importPath);
// Process uploaded file
if ($f_act == "uploadFile") :
if ($numOfFiles < 1) :
if ($_FILES['f_uploadFile']['size'] <= 2000000) :
if (!move_uploaded_file($_FILES['f_uploadFile']['tmp_name'], $importPath . $_FILES['f_uploadFile']['name'])) :
$statusMessage .= "Die Datei wurde leider nicht hochgeladen!";
endif;
else :
$statusMessage .= "Die Datei ist für den Upload zu groß!";
// Delete real file if does exist
$retVal = removeFile($_FILES['f_uploadFile']['name'], $importPath, $pathSeparator);
endif;
// Delete temp file if does exist
$retVal = removeFile($_FILES['f_uploadFile']['tmp_name'], $tempPath, $pathSeparator);
else :
$statusMessage .= "Bevor eine weitere Datei hochgeladen werden kann, muss das Verzeichnis geleert werden!";
endif;
endif;
// Manually removal of a specified importfile
if ($f_act == "removeImportfile") :
// Remove import file
$retVal = removeFile($f_importFile, $importPath, $pathSeparator);
if ($retVal == "0") :
elseif ($retVal == "-1") :
$statusMessage = "Es liegt kein Dateiname vor!";
elseif ($retVal == "-2") :
$statusMessage = "Die Datei befindet sich nicht mehr in dem Verzeichnis!";
elseif ($retVal == "") :
$statusMessage = "Es fand keine Löschung statt!";
endif;
endif;
// Import process
if ($f_act == "goImport") :
if ($numOfFiles == 1) :
$importFileStatusMsg .= "<br><br><br><br><span class=\"f12bp1_red\" colspan=\"2\">Verarbeitungsprotokoll:</span><br><br>";
$importFileStatusMsg .= "Import-Datei: " . $f_importFile . "<br><br>";
$rowToImport = array();
$rowToImport[0] = "f_id_unique"; // internalOrderID (unique key)
$rowToImport[1] = "f_tr_person"; // externalOrderID
$rowToImport[2] = "f_cs_eid"; // externalCustomerNumber
$rowToImport[3] = "f_tr_ware_from_to"; // type
$rowToImport[4] = "f_jb_weight"; // weight
$rowToImport[5] = "f_vht_id"; // capacityClass
$rowToImport[6] = "f_tr_commission_no"; // loadingUnitType
$rowToImport[7] = "f_tr_remark_1"; // goodsdescription
$rowToImport[8] = "f_tr_comp_01"; // pickup/name
$rowToImport[9] = "f_ad_zipcode_01"; // pickup/zipCode
$rowToImport[10] = "f_ad_city_01"; // pickup/city
$rowToImport[11] = "f_ad_street_01"; // pickup/street (containing houseno.)
$rowToImport[12] = "f_jb_ordertime_01"; // pickup/plannedPickup
$rowToImport[13] = "f_tr_comp_02"; // delivery/name
$rowToImport[14] = "f_tr_remark_2"; // delivery/contact
$rowToImport[15] = "f_tr_remark_3"; // delivery/telephone
$rowToImport[16] = "f_ad_zipcode_02"; // delivery/zipCode
$rowToImport[17] = "f_ad_city_02"; // delivery/city
$rowToImport[18] = "f_ad_street_02"; // delivery/street (containing houseno.)
$rowToImport[19] = "f_jb_ordertime_02"; // delivery/plannedDelivery
$rowToImport[20] = "f_jb_tourname"; // tourID
$rowToImport[21] = "f_position"; // position
$rowToImport[22] = "f_dummy"; // dummy
$rowToImportLen = count($rowToImport);
// read file to import
$data = importCSV($importPath . $f_importFile, $delimiter);
$dataLen = count($data);
// loop all rows
for ($j = 0; $j < $dataLen; $j++) {
// loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
// Next job begins
if ($fJbTourname == "" || $fJbTourname != $f_jb_tourname) :
$jbIdNew = "";
$fTrSort = "";
$fJbTourname = $f_jb_tourname;
endif;
// Check import log table in db according to the unique key "tourID + position" (<=> $f_jb_tourname + $f_position)
$logJbId = getFieldValueFromClause("phoenix_log.import","jb_id","imp_id = '" . $f_jb_tourname . "' AND imp_pos = '" . $f_position . "'");
if ($logJbId == "") :
TA("B");
if (substr($f_cs_eid, 0, 9) == "000000000") :
$f_cs_eid = substr($f_cs_eid, -($csEidStrLen));
else :
$tmpLen = strlen($f_cs_eid);
while (substr($f_cs_eid, 0, 1) == "0"):
$f_cs_eid = substr($f_cs_eid, 1, $tmpLen);
endwhile;
endif;
// Constants
$cscIdCashPayer = getParameterValue("0", "CSC_ID_PAYER_CASH", $f_hq_id);
// Concatenation of external cs_id an name
$f_tr_comp_01 = $f_cs_eid . " " . $f_tr_comp_01;
$f_tr_remark = $f_tr_remark_1 . " " . $f_tr_remark_2 . " " . $f_tr_remark_3 . " " . $f_jb_ordertime_02;
$f_tr_remark = $f_tr_remark;
// Extra field "internal remark of the customer" for customer export
$f_tr_cs_freetext = $f_tr_remark;
// Split street to street and houseno.
$f_tr_hsno_01 = ".";
$f_tr_hsno_02 = ".";
// Get 1. address id
$tmpArray = insertAddress($f_ad_street_01, $f_ad_zipcode_01, $f_ad_city_01, "", "", true);
$ad_id_new_01 = $tmpArray[0];
// Get 2. address id
$tmpArray = insertAddress($f_ad_street_02, $f_ad_zipcode_02, $f_ad_city_02, "", "", true);
$ad_id_new_02 = $tmpArray[0];
// Get the current time
$currentTime = getDateTime("0");
// Insert job data
if ($jbIdNew == "") :
$jbStatus = "9";
$jbType = "2"; // "G"
$crId = "";
$crSid = "";
$jbFinishtime = "";
$csInvmod = "";
$price = 0;
if (!isset($f_tax_value) || $f_tax_value == ""):
$f_tax_value = getFieldValueFromId("tax","tx_id","4","tx_value");
if ($f_tax_value == ""):
$f_tax_value = "19.00";
endif;
endif;
$txSign = "V";
// Mapping of the headquarters
$tmpZipcode = substr($f_ad_zipcode_01 ,0 ,1); // Get the first character
if ($tmpZipcode == "0") :
$f_hq_id = "108"; // Leipzig
$f_cs_eid_payer = "HTL40098";
$trCscIdRoot_01 = "44548"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44548"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "3") :
$f_hq_id = "104"; // Hannover
$f_cs_eid_payer = "HTH40105";
$trCscIdRoot_01 = "44545"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44545"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "4") :
$f_hq_id = "107"; // Essen
$f_cs_eid_payer = "HTE10496";
$trCscIdRoot_01 = "44543"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44543"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "6") :
$f_hq_id = "105"; // Frankfurt
$f_cs_eid_payer = "HTF40090";
$trCscIdRoot_01 = "44544"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44544"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "7") :
$f_hq_id = "111"; // Stuttgart
$f_cs_eid_payer = "HTS40032";
$trCscIdRoot_01 = "44547"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44547"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "8") :
$f_hq_id = "109"; // München
$f_cs_eid_payer = "HTM65105";
$trCscIdRoot_01 = "44549"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44549"; // Hauptkostenstelle Kunde "Extern"
else :
$f_hq_id = "107"; // Essen (Default !!!)
$f_cs_eid_payer = "HTE10496";
$trCscIdRoot_01 = "44543"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44543"; // Hauptkostenstelle Kunde "Extern"
// 44539 101 44540 102 44541 103 44542 106 44546 110
endif;
$csId = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cs_id");
$cscIdRoot = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"csc_id");
// if ($isCashPayerTour): $cscIdRoot = $cscIdCashPayer; endif;
$csInvmode = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cs_invmode");
$cmpPostage = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cmp_id");
if ($cmpPostage == "") : $cmpPostage = "0.00"; endif;
// Check for absolute customer discount
$csDiscountAbsolute = getFieldValueFromId("customer", "cs_id", $csId, "cs_discount");
$useDicountDisabled = getParameterValue("0", "JB_EDITBATCH_DISCOUNT_DISABLED");
if ($useDicountDisabled == "1") :
$csDiscountAbsolute = 0;
endif;
// Mapping of the vehicle type
if ($f_vht_id == "1") :
$f_vht_id = "8"; // 3-To.
elseif ($f_vht_id == "2") :
$f_vht_id = "9"; // 5-To.
elseif ($f_vht_id == "3") :
$f_vht_id = "7"; // 1-To.
else :
$f_vht_id = "8"; // 3-To.
endif;
insertStmt("job", array("hq_id", $f_hq_id, "vht_id", $f_vht_id, "csc_id_payer", $cscIdRoot, "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime_01, "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_taketime", "", "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType, "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id, "jb_fixprice", $f_price, "jb_totalprice", $f_price,
"jb_postage", $cmpPostage, "jb_invmode", $csInvmode, "jb_freetext_1", "",
"jb_sales_tax_rate", $f_tax_value, "jb_sales_tax_rate_sign", $txSign, "jb_booktime", ""));
$jbIdNew = getLastInsertId();
// Insert tour data for station 1
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new_01, "tr_sort", "1", "tr_comp", $f_tr_comp_01, "tr_comp2", "",
"tr_hsno", $f_tr_hsno_01, "csc_id", $trCscIdRoot_01, "tr_status", "0",
"tr_commission_no", "", "tr_ware_from_to", "1",
"tr_person", "", "tr_remark", "", "tr_cs_freetext", ""));
// Insert tour data for station 2
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new_02, "tr_sort", "2", "tr_comp", $f_tr_comp_02, "tr_comp2", "",
"tr_hsno", $f_tr_hsno_02, "csc_id", $trCscIdRoot_02, "tr_status", "0",
"tr_person", $f_tr_person, "tr_commission_no", $f_tr_commission_no,
"tr_ware_from_to", "2", "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
// Insert tourservice data
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdRoot, "tr_sort", "0",
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $price, "trs_discount", $csDiscountAbsolute));
// Write logdata into log database
writeToLogDB("55",$hq_id,$jbIdNew,$usr_id,"","","",$csId);
$importFileStatusMsg .= "Stationen 1 und 2 des Auftrags " . $jbIdNew . " wurden importiert.<br>";
else :
if ($fTrSort == "") :
$fTrSort = "3";
else :
$fTrSort++;
endif;
// Update job data
// updateStmt("job","jb_id",$jbIdNew,array("usr_name",$f_usr_name,"usr_firstname",$f_usr_firstname));
// Insert tour data for
if ($f_tr_ware_from_to == "0") :
// Delivery => Delivery address
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new_02, "tr_sort", $fTrSort, "tr_comp", $f_tr_comp_02, "tr_comp2", "",
"tr_hsno", $f_tr_hsno_02, "csc_id", $trCscIdRoot_02, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "2",
"tr_person", $f_tr_person, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
else :
// Retoure => Pickup address
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new_01, "tr_sort", $fTrSort, "tr_comp", $f_tr_comp_01, "tr_comp2", "",
"tr_hsno", $f_tr_hsno_01, "csc_id", $trCscIdRoot_01, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "1",
"tr_person", $f_tr_person, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
endif;
$importFileStatusMsg .= "Station " . $fTrSort . " des Auftrags " . $jbIdNew . " wurde importiert.<br>";
endif;
// Insert into import log table
insertStmt("phoenix_log.import", array("imp_id", $f_jb_tourname, "imp_pos", $f_position, "imp_createtime", $currentTime, "jb_id", $jbIdNew));
TA("C");
TA("E");
else :
$importFileStatusMsg .= "Datensatz " . $j . " wurde NICHT importiert, weil sie schon importiert wurde! (Auftrag " . $logJbId . ")<br>";
endif;
}
// Remove import file
$retVal = removeFile($f_importFile, $importPath, $pathSeparator);
else :
$importFileStatusMsg .= "Der Import konnte nicht vollzogen werden, da noch mindestens eine andere Importdatei existiert!<br>";
endif;
endif;
// **************************************************
// * Read all of the local filenames to be imported *
// **************************************************
if ($userTypeName == "hq") :
// Get filenames
$fileNames = getFilenamesInFolder($importPath);
$storedImportFiles .= "<table>";
$storedImportFiles .= "<tr><td class=\"f12bp1_red\" colspan=\"2\">Auftragsimport</td></tr>";
$storedImportFiles .= "<tr><td colspan=\"2\"><br><br></td></tr>";
// Define table header
$storedImportFiles .= "<tr><td>Dateiname&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Löschen</td></tr>";
$storedImportFiles .= "<tr><td colspan=\"2\"><br></td></tr>";
// Define table body from array
$fileNamesLen = count($fileNames);
for ($j = 0; $j < $fileNamesLen; $j++) :
$storedImportFiles .= "<tr>";
$storedImportFiles .= "<td><a href=\"javascript:importImportfile('" . $fileNames[$j] . "');\">" . $fileNames[$j] .
"</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedImportFiles .= "<td align=\"center\"><a href=\"javascript:removeImportfile('" . $fileNames[$j] . "');\">"
. "<img src=\"../images/trash.jpg\" border=\"0\" height=\"13\" width=\"8\">"
. "</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedImportFiles .= "</tr>";
endfor;
$storedImportFiles .= "</table>";
endif;
?>
<html>
<head>
<title>Mi2ju: Auftragsimport</title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<script type="text/javascript">
<!--
var statusMessage = "<?php echo $statusMessage ?>";
function displayStatusMessage() {
if (statusMessage != "") {
alert(statusMessage);
}
};
function finishPage(f_act_value) {
document.forms[0].f_act.value=f_act_value;
document.forms[0].submit();
};
function removeImportfile(fileName) {
if (confirm('Importdatei ' + fileName + ' entfernen?')) {
document.forms[0].f_importFile.value = fileName;
finishPage('removeImportfile');
};
};
function importImportfile(fileName) {
if (confirm('Importdatei ' + fileName + ' jetzt importieren?')) {
document.forms[0].f_importFile.value = fileName;
finishPage('goImport');
};
};
function finishPageUpload(f_act_value) {
document.forms[1].f_act.value=f_act_value;
document.forms[1].submit();
};
-->
</script>
</head>
<body onLoad="displayStatusMessage();">
<form name="import_form" action="../import/import_job.php" method="post">
<input type="hidden" name="f_act" value="">
<input type="hidden" name="f_importFile" value="">
<?php echo $storedImportFiles; ?>
</form>
<br><br>
<form name="upload_file" action="../import/import_job.php" enctype="multipart/form-data" method="post">
<!-- <form name="upload_file" action="../import/upload_file.php" enctype="multipart/form-data" method="post"> -->
<input type="hidden" name="f_act" value="">
<p>W&auml;hlen Sie die Auftragsdateidatei von Ihrem Rechner aus:<br>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="f_uploadFile" type="file" size="50" accept="text/*">
<input type="button" value="Upload" onClick="finishPageUpload('uploadFile');">
</p>
<br><br>
<?php echo $importFileStatusMsg; ?>
</form>
</body>
</html>

449
html/import/import_job_.php Normal file
View File

@@ -0,0 +1,449 @@
<?php
/*=======================================================================
*
* import_job.php
*
* Autor: Marc Vollmann
*
* ToDoS :
* [1] Configuration in php.ini:
* "file_uploads", "upload_max_filesize", "upload_tmp_dir", "post_max_size"
* [2] Change tables "tour" and "tourhistory"
* ALTER TABLE `tour` ADD `tr_cs_freetext` TEXT;
* ALTER TABLE `tourhistory` ADD `tr_cs_freetext` TEXT;
* [3] Create table "import_log"
* CREATE TABLE import (imp_id int(10) NOT NULL default '0',imp_pos smallint(6) NOT NULL default '0', imp_createtime timestamp(14) NOT NULL, jb_id int(10) NOT NULL default '0', UNIQUE KEY imp_id_pos (imp_id,imp_pos)) TYPE=MyISAM;
* [4] Exportcategoryfields have to be inserted
* DELETE FROM `exportcategoryfields` WHERE expc_id = '110'
* => Start Insert-Script
*
=======================================================================*/
include_once ("import.php");
// Execution-Time for script
set_time_limit(30000);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "f_importFile", "f_uploadFile"));
// Select user-type for mode of security check
$userType = getFieldValueFromId("user","usr_id",$usr_id,"usr_type");
$userTypeName = getUserTypeName($userType);
// Get the rights of the employee logged in and check the accessibility
if (!authCheckEmployeeRights($emp_id, "7")) : die ("$PHP_SELF: Access denied!"); endif;
$statusMessage = "";
$importFileStatusMsg = "";
$jbIdNew = "";
$fJbTourname = "";
$fTrSort = "";
// Get number of files in the upload folder
$numOfFiles = getNumOfFilesInFolder($importPath);
// Process uploaded file
if ($f_act == "uploadFile") :
if ($numOfFiles < 1) :
if ($_FILES['f_uploadFile']['size'] <= 2000000) :
if (!move_uploaded_file($_FILES['f_uploadFile']['tmp_name'], $importPath . $_FILES['f_uploadFile']['name'])) :
$statusMessage .= "Die Datei wurde leider nicht hochgeladen!";
endif;
else :
$statusMessage .= "Die Datei ist für den Upload zu groß!";
// Delete real file if does exist
$retVal = removeFile($_FILES['f_uploadFile']['name'], $importPath, $pathSeparator);
endif;
// Delete temp file if does exist
$retVal = removeFile($_FILES['f_uploadFile']['tmp_name'], $tempPath, $pathSeparator);
else :
$statusMessage .= "Bevor eine weitere Datei hochgeladen werden kann, muss das Verzeichnis geleert werden!";
endif;
endif;
// Manually removal of a specified importfile
if ($f_act == "removeImportfile") :
// Remove import file
$retVal = removeFile($f_importFile, $importPath, $pathSeparator);
if ($retVal == "0") :
elseif ($retVal == "-1") :
$statusMessage = "Es liegt kein Dateiname vor!";
elseif ($retVal == "-2") :
$statusMessage = "Die Datei befindet sich nicht mehr in dem Verzeichnis!";
elseif ($retVal == "") :
$statusMessage = "Es fand keine Löschung statt!";
endif;
endif;
// Import process
if ($f_act == "goImport") :
if ($numOfFiles == 1) :
$importFileStatusMsg .= "<br><br><br><br><span class=\"f12bp1_red\" colspan=\"2\">Verarbeitungsprotokoll:</span><br><br>";
$importFileStatusMsg .= "Import-Datei: " . $f_importFile . "<br><br>";
$rowToImport = array();
$rowToImport[0] = "f_position"; // position
$rowToImport[1] = "f_tr_person"; // externalOrderID
$rowToImport[2] = "f_dummy_01"; // dummy
$rowToImport[3] = "f_tr_ware_from_to"; // type
$rowToImport[4] = "f_tr_comp_01"; // name 1
$rowToImport[5] = "f_tr_comp2_01"; // name 2
$rowToImport[6] = "f_ad_street_01"; // pickup/street
$rowToImport[7] = "f_ad_zipcode_01"; // pickup/zipCode
$rowToImport[8] = "f_ad_city_01"; // pickup/city
$rowToImport[9] = "f_tr_remark_1"; // goodsdescription
$rowToImport[10] = "f_tr_commission_no"; // loadingUnitType
$rowToImport[11] = "f_jb_ordertime_01"; // pickup/plannedPickup
$rowToImport[12] = "f_jb_tourname"; // tourID
$rowToImportLen = count($rowToImport);
// read file to import
$data = importCSV($importPath . $f_importFile);
$dataLen = count($data);
// loop all rows
for ($j = 0; $j < $dataLen; $j++) {
// loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
// Next job begins
if ($fJbTourname == "" || $fJbTourname != $f_jb_tourname) :
$jbIdNew = "";
$fTrSort = "";
$fJbTourname = $f_jb_tourname;
endif;
// Check import log table in db according to the unique key "tourID + position" (<=> $f_jb_tourname + $f_position)
$logJbId = getFieldValueFromClause("phoenix_log.import","jb_id","imp_id = '" . $f_jb_tourname . "' AND imp_pos = '" . $f_position . "'");
if ($logJbId == "") :
TA("B");
$f_position = trim($f_position);
$f_tr_person = trim($f_tr_person);
$f_tr_ware_from_to = trim($f_tr_ware_from_to);
$f_tr_comp_01 = trim($f_tr_comp_01);
$f_tr_comp2_01 = trim($f_tr_comp2_01);
$f_ad_street_01 = trim($f_ad_street_01);
$f_ad_zipcode_01 = trim($f_ad_zipcode_01);
$f_ad_city_01 = trim($f_ad_city_01);
$f_tr_remark_1 = trim($f_tr_remark_1);
$f_tr_commission_no = trim($f_tr_commission_no);
$f_jb_ordertime_01 = trim($f_jb_ordertime_01);
$f_jb_tourname = trim($f_jb_tourname);
$f_cs_eid = trim($f_cs_eid);
if ($f_ad_street_01 == "") : $f_ad_street_01 = "."; endif;
if ($f_ad_zipcode_01 == "") : $f_ad_zipcode_01 = "."; endif;
if ($f_ad_city_01 == "") : $f_ad_city_01 = "."; endif;
// Constants
$cscIdCashPayer = getParameterValue("0", "CSC_ID_PAYER_CASH", $f_hq_id);
// Concatenation of external cs_eid and name
// $f_tr_comp_01 = $f_cs_eid . " " . $f_tr_comp_01;
$f_tr_comp_01 = $f_tr_comp_01 . " " . $f_tr_comp2_01;
$f_tr_comp2_01 = "";
if ($f_tr_ware_from_to == "Rücknahme") :
$f_tr_ware_from_to = "1";
elseif ($f_tr_ware_from_to == "Installation") :
$f_tr_ware_from_to = "2";
else :
$f_tr_ware_from_to = "0";
endif;
$f_tr_remark = $f_tr_remark_1; // . " " . $f_tr_remark_2 . " " . $f_tr_remark_3 . " " . $f_jb_ordertime_02;
// Extra field "internal remark of the customer" for customer export
$f_tr_cs_freetext = $f_tr_remark;
// Format date field
$dVal = $f_jb_ordertime_01;
$f_jb_ordertime_01 = substr($dVal,6,4) . "-" . substr($dVal,3,2) . "-" . substr($dVal,0,2) . " 10:00";
// Split street to street and houseno.
$f_tr_hsno_01 = ".";
$f_tr_hsno_02 = ".";
// Get 1. address id
$tmpArray = insertAddress($f_ad_street_01, $f_ad_zipcode_01, $f_ad_city_01, "", "", true);
$ad_id_new_01 = $tmpArray[0];
// Get the current time
$currentTime = getDateTime("0");
// Insert job data
if ($jbIdNew == "") :
$jbStatus = "9";
$jbType = "2"; // "G"
$crId = "";
$crSid = "";
$jbFinishtime = "";
$csInvmod = "";
$price = 0;
if (!isset($f_tax_value) || $f_tax_value == ""):
$f_tax_value = getFieldValueFromId("tax","tx_id","4","tx_value");
if ($f_tax_value == ""):
$f_tax_value = "19.00";
endif;
endif;
$txSign = "V";
// Mapping of the headquarters
$tmpZipcode = substr($f_ad_zipcode_01 ,0 ,1); // Get the first character
if ($tmpZipcode == "0") :
$f_hq_id = "108"; // Leipzig
$f_cs_eid_payer = "HTL40098";
$trCscIdRoot_01 = "44548"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44548"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "3") :
$f_hq_id = "104"; // Hannover
$f_cs_eid_payer = "HTH40105";
$trCscIdRoot_01 = "44545"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44545"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "4") :
$f_hq_id = "107"; // Essen
// $f_cs_eid_payer = "HTE10496";
$f_cs_eid_payer = "HTE10977";
$trCscIdRoot_01 = "44543"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44543"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "6") :
$f_hq_id = "105"; // Frankfurt
$f_cs_eid_payer = "HTF40090";
$trCscIdRoot_01 = "44544"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44544"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "7") :
$f_hq_id = "111"; // Stuttgart
$f_cs_eid_payer = "HTS10799";
$trCscIdRoot_01 = "44547"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44547"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "8") :
$f_hq_id = "109"; // München
$f_cs_eid_payer = "HTM65105";
$trCscIdRoot_01 = "44549"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44549"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "9") :
$f_hq_id = "109"; // München
$f_cs_eid_payer = "HTM65105";
$trCscIdRoot_01 = "44549"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44549"; // Hauptkostenstelle Kunde "Extern"
else :
$f_hq_id = "107"; // Essen (Default !!!)
// $f_cs_eid_payer = "HTE10496";
$f_cs_eid_payer = "HTE10977";
$trCscIdRoot_01 = "44543"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44543"; // Hauptkostenstelle Kunde "Extern"
// 44539 101 44540 102 44541 103 44542 106 44546 110
endif;
$csId = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cs_id");
$cscIdRoot = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"csc_id");
// if ($isCashPayerTour): $cscIdRoot = $cscIdCashPayer; endif;
$csInvmode = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cs_invmode");
$cmpPostage = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cmp_id");
if ($cmpPostage == "") : $cmpPostage = "0.00"; endif;
// Check for absolute customer discount
$csDiscountAbsolute = getFieldValueFromId("customer", "cs_id", $csId, "cs_discount");
$useDicountDisabled = getParameterValue("0", "JB_EDITBATCH_DISCOUNT_DISABLED");
if ($useDicountDisabled == "1") :
$csDiscountAbsolute = 0;
endif;
// Mapping of the vehicle type
if ($f_vht_id == "1") :
$f_vht_id = "8"; // 3-To.
elseif ($f_vht_id == "2") :
$f_vht_id = "9"; // 5-To.
elseif ($f_vht_id == "3") :
$f_vht_id = "7"; // 1-To.
else :
$f_vht_id = "8"; // 3-To.
endif;
insertStmt("job", array("hq_id", $f_hq_id, "vht_id", $f_vht_id, "csc_id_payer", $cscIdRoot, "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime_01, "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_taketime", "", "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType, "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id, "jb_fixprice", $f_price, "jb_totalprice", $f_price,
"jb_postage", $cmpPostage, "jb_invmode", $csInvmode, "jb_freetext_1", "",
"jb_sales_tax_rate", $f_tax_value, "jb_sales_tax_rate_sign", $txSign, "jb_booktime", ""));
$jbIdNew = getLastInsertId();
// Insert tour data for station
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new_01, "tr_sort", "1", "tr_comp", $f_tr_comp_01, "tr_comp2", $f_tr_comp2_01,
"tr_hsno", $f_tr_hsno_01, "csc_id", $trCscIdRoot_01, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", $f_tr_ware_from_to,
"tr_person", $f_tr_person, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
// Insert tourservice data
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdRoot, "tr_sort", "0",
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $price, "trs_discount", $csDiscountAbsolute));
// Write logdata into log database
writeToLogDB("55",$hq_id,$jbIdNew,$usr_id,"","","",$csId);
$importFileStatusMsg .= "Station 1 des Auftrags " . $jbIdNew . " wurde importiert.<br>";
else :
if ($fTrSort == "") :
$fTrSort = "2";
else :
$fTrSort++;
endif;
// Update job data
// updateStmt("job","jb_id",$jbIdNew,array("usr_name",$f_usr_name,"usr_firstname",$f_usr_firstname));
// Insert tour data
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new_01, "tr_sort", $fTrSort, "tr_comp", $f_tr_comp_01, "tr_comp2", $f_tr_comp2_01,
"tr_hsno", $f_tr_hsno_01, "csc_id", $trCscIdRoot_01, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", $f_tr_ware_from_to,
"tr_person", $f_tr_person, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$importFileStatusMsg .= "Station " . $fTrSort . " des Auftrags " . $jbIdNew . " wurde importiert.<br>";
endif;
// Insert into import log table
insertStmt("phoenix_log.import", array("imp_id", $f_jb_tourname, "imp_pos", $f_position, "imp_createtime", $currentTime, "jb_id", $jbIdNew));
TA("C");
TA("E");
else :
$importFileStatusMsg .= "Datensatz " . $j . " wurde NICHT importiert, weil sie schon importiert wurde! (Auftrag " . $logJbId . ")<br>";
endif;
}
// Remove import file
$retVal = removeFile($f_importFile, $importPath, $pathSeparator);
else :
$importFileStatusMsg .= "Der Import konnte nicht vollzogen werden, da noch mindestens eine andere Importdatei existiert!<br>";
endif;
endif;
// **************************************************
// * Read all of the local filenames to be imported *
// **************************************************
if ($userTypeName == "hq") :
// Get filenames
$fileNames = getFilenamesInFolder($importPath);
$storedImportFiles .= "<table>";
$storedImportFiles .= "<tr><td class=\"f12bp1_red\" colspan=\"2\">Auftragsimport</td></tr>";
$storedImportFiles .= "<tr><td colspan=\"2\"><br><br></td></tr>";
// Define table header
$storedImportFiles .= "<tr><td>Dateiname&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Löschen</td></tr>";
$storedImportFiles .= "<tr><td colspan=\"2\"><br></td></tr>";
// Define table body from array
$fileNamesLen = count($fileNames);
for ($j = 0; $j < $fileNamesLen; $j++) :
$storedImportFiles .= "<tr>";
$storedImportFiles .= "<td><a href=\"javascript:importImportfile('" . $fileNames[$j] . "');\">" . $fileNames[$j] .
"</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedImportFiles .= "<td align=\"center\"><a href=\"javascript:removeImportfile('" . $fileNames[$j] . "');\">"
. "<img src=\"../images/trash.jpg\" border=\"0\" height=\"13\" width=\"8\">"
. "</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedImportFiles .= "</tr>";
endfor;
$storedImportFiles .= "</table>";
endif;
?>
<html>
<head>
<title>AUFTRAGSIMPORT</title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<script type="text/javascript">
<!--
var statusMessage = "<?php echo $statusMessage ?>";
function displayStatusMessage() {
if (statusMessage != "") {
alert(statusMessage);
}
};
function finishPage(f_act_value) {
document.forms[0].f_act.value=f_act_value;
document.forms[0].submit();
};
function removeImportfile(fileName) {
if (confirm('Importdatei ' + fileName + ' entfernen?')) {
document.forms[0].f_importFile.value = fileName;
finishPage('removeImportfile');
};
};
function importImportfile(fileName) {
if (confirm('Importdatei ' + fileName + ' jetzt importieren?')) {
document.forms[0].f_importFile.value = fileName;
finishPage('goImport');
};
};
function finishPageUpload(f_act_value) {
document.forms[1].f_act.value=f_act_value;
document.forms[1].submit();
};
-->
</script>
</head>
<body onLoad="displayStatusMessage();">
<form name="import_form" action="../import/import_job.php" method="post">
<input type="hidden" name="f_act" value="">
<input type="hidden" name="f_importFile" value="">
<?php echo $storedImportFiles; ?>
</form>
<br><br>
<form name="upload_file" action="../import/import_job.php" enctype="multipart/form-data" method="post">
<!-- <form name="upload_file" action="../import/upload_file.php" enctype="multipart/form-data" method="post"> -->
<input type="hidden" name="f_act" value="">
<p>W&auml;hlen Sie die Auftragsdateidatei von Ihrem Rechner aus:<br>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="f_uploadFile" type="file" size="50" accept="text/*">
<input type="button" value="Upload" onClick="finishPageUpload('uploadFile');">
</p>
<br><br>
<?php echo $importFileStatusMsg; ?>
</form>
</body>
</html>

View File

@@ -0,0 +1,449 @@
<?php
/*=======================================================================
*
* import_job.php
*
* Autor: Marc Vollmann
*
* ToDoS :
* [1] Configuration in php.ini:
* "file_uploads", "upload_max_filesize", "upload_tmp_dir", "post_max_size"
* [2] Change tables "tour" and "tourhistory"
* ALTER TABLE `tour` ADD `tr_cs_freetext` TEXT;
* ALTER TABLE `tourhistory` ADD `tr_cs_freetext` TEXT;
* [3] Create table "import_log"
* CREATE TABLE import (imp_id int(10) NOT NULL default '0',imp_pos smallint(6) NOT NULL default '0', imp_createtime timestamp(14) NOT NULL, jb_id int(10) NOT NULL default '0', UNIQUE KEY imp_id_pos (imp_id,imp_pos)) TYPE=MyISAM;
* [4] Exportcategoryfields have to be inserted
* DELETE FROM `exportcategoryfields` WHERE expc_id = '110'
* => Start Insert-Script
*
=======================================================================*/
include_once ("import.php");
// Execution-Time for script
set_time_limit(30000);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "f_importFile", "f_uploadFile"));
// Select user-type for mode of security check
$userType = getFieldValueFromId("user","usr_id",$usr_id,"usr_type");
$userTypeName = getUserTypeName($userType);
// Get the rights of the employee logged in and check the accessibility
if (!authCheckEmployeeRights($emp_id, "7")) : die ("$PHP_SELF: Access denied!"); endif;
$statusMessage = "";
$importFileStatusMsg = "";
$jbIdNew = "";
$fJbTourname = "";
$fTrSort = "";
// Get number of files in the upload folder
$numOfFiles = getNumOfFilesInFolder($importPath);
// Process uploaded file
if ($f_act == "uploadFile") :
if ($numOfFiles < 1) :
if ($_FILES['f_uploadFile']['size'] <= 2000000) :
if (!move_uploaded_file($_FILES['f_uploadFile']['tmp_name'], $importPath . $_FILES['f_uploadFile']['name'])) :
$statusMessage .= "Die Datei wurde leider nicht hochgeladen!";
endif;
else :
$statusMessage .= "Die Datei ist für den Upload zu groß!";
// Delete real file if does exist
$retVal = removeFile($_FILES['f_uploadFile']['name'], $importPath, $pathSeparator);
endif;
// Delete temp file if does exist
$retVal = removeFile($_FILES['f_uploadFile']['tmp_name'], $tempPath, $pathSeparator);
else :
$statusMessage .= "Bevor eine weitere Datei hochgeladen werden kann, muss das Verzeichnis geleert werden!";
endif;
endif;
// Manually removal of a specified importfile
if ($f_act == "removeImportfile") :
// Remove import file
$retVal = removeFile($f_importFile, $importPath, $pathSeparator);
if ($retVal == "0") :
elseif ($retVal == "-1") :
$statusMessage = "Es liegt kein Dateiname vor!";
elseif ($retVal == "-2") :
$statusMessage = "Die Datei befindet sich nicht mehr in dem Verzeichnis!";
elseif ($retVal == "") :
$statusMessage = "Es fand keine Löschung statt!";
endif;
endif;
// Import process
if ($f_act == "goImport") :
if ($numOfFiles == 1) :
$importFileStatusMsg .= "<br><br><br><br><span class=\"f12bp1_red\" colspan=\"2\">Verarbeitungsprotokoll:</span><br><br>";
$importFileStatusMsg .= "Import-Datei: " . $f_importFile . "<br><br>";
$rowToImport = array();
$rowToImport[0] = "f_position"; // position
$rowToImport[1] = "f_tr_person"; // externalOrderID
$rowToImport[2] = "f_dummy_01"; // dummy
$rowToImport[3] = "f_tr_ware_from_to"; // type
$rowToImport[4] = "f_tr_comp_01"; // name 1
$rowToImport[5] = "f_tr_comp2_01"; // name 2
$rowToImport[6] = "f_ad_street_01"; // pickup/street
$rowToImport[7] = "f_ad_zipcode_01"; // pickup/zipCode
$rowToImport[8] = "f_ad_city_01"; // pickup/city
$rowToImport[9] = "f_tr_remark_1"; // goodsdescription
$rowToImport[10] = "f_tr_commission_no"; // loadingUnitType
$rowToImport[11] = "f_jb_ordertime_01"; // pickup/plannedPickup
$rowToImport[12] = "f_jb_tourname"; // tourID
$rowToImportLen = count($rowToImport);
// read file to import
$data = importCSV($importPath . $f_importFile);
$dataLen = count($data);
// loop all rows
for ($j = 0; $j < $dataLen; $j++) {
// loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
// Next job begins
if ($fJbTourname == "" || $fJbTourname != $f_jb_tourname) :
$jbIdNew = "";
$fTrSort = "";
$fJbTourname = $f_jb_tourname;
endif;
// Check import log table in db according to the unique key "tourID + position" (<=> $f_jb_tourname + $f_position)
$logJbId = getFieldValueFromClause("phoenix_log.import","jb_id","imp_id = '" . $f_jb_tourname . "' AND imp_pos = '" . $f_position . "'");
if ($logJbId == "") :
TA("B");
$f_position = trim($f_position);
$f_tr_person = trim($f_tr_person);
$f_tr_ware_from_to = trim($f_tr_ware_from_to);
$f_tr_comp_01 = trim($f_tr_comp_01);
$f_tr_comp2_01 = trim($f_tr_comp2_01);
$f_ad_street_01 = trim($f_ad_street_01);
$f_ad_zipcode_01 = trim($f_ad_zipcode_01);
$f_ad_city_01 = trim($f_ad_city_01);
$f_tr_remark_1 = trim($f_tr_remark_1);
$f_tr_commission_no = trim($f_tr_commission_no);
$f_jb_ordertime_01 = trim($f_jb_ordertime_01);
$f_jb_tourname = trim($f_jb_tourname);
$f_cs_eid = trim($f_cs_eid);
if ($f_ad_street_01 == "") : $f_ad_street_01 = "."; endif;
if ($f_ad_zipcode_01 == "") : $f_ad_zipcode_01 = "."; endif;
if ($f_ad_city_01 == "") : $f_ad_city_01 = "."; endif;
// Constants
$cscIdCashPayer = getParameterValue("0", "CSC_ID_PAYER_CASH", $f_hq_id);
// Concatenation of external cs_eid and name
// $f_tr_comp_01 = $f_cs_eid . " " . $f_tr_comp_01;
$f_tr_comp_01 = $f_tr_comp_01 . " " . $f_tr_comp2_01;
$f_tr_comp2_01 = "";
if ($f_tr_ware_from_to == "Rücknahme") :
$f_tr_ware_from_to = "1";
elseif ($f_tr_ware_from_to == "Installation") :
$f_tr_ware_from_to = "2";
else :
$f_tr_ware_from_to = "0";
endif;
$f_tr_remark = $f_tr_remark_1; // . " " . $f_tr_remark_2 . " " . $f_tr_remark_3 . " " . $f_jb_ordertime_02;
// Extra field "internal remark of the customer" for customer export
$f_tr_cs_freetext = $f_tr_remark;
// Format date field
$dVal = $f_jb_ordertime_01;
$f_jb_ordertime_01 = substr($dVal,6,4) . "-" . substr($dVal,3,2) . "-" . substr($dVal,0,2) . " 10:00";
// Split street to street and houseno.
$f_tr_hsno_01 = ".";
$f_tr_hsno_02 = ".";
// Get 1. address id
$tmpArray = insertAddress($f_ad_street_01, $f_ad_zipcode_01, $f_ad_city_01, "", "", true);
$ad_id_new_01 = $tmpArray[0];
// Get the current time
$currentTime = getDateTime("0");
// Insert job data
if ($jbIdNew == "") :
$jbStatus = "9";
$jbType = "2"; // "G"
$crId = "";
$crSid = "";
$jbFinishtime = "";
$csInvmod = "";
$price = 0;
if (!isset($f_tax_value) || $f_tax_value == ""):
$f_tax_value = getFieldValueFromId("tax","tx_id","4","tx_value");
if ($f_tax_value == ""):
$f_tax_value = "19.00";
endif;
endif;
$txSign = "V";
// Mapping of the headquarters
$tmpZipcode = substr($f_ad_zipcode_01 ,0 ,1); // Get the first character
if ($tmpZipcode == "0") :
$f_hq_id = "108"; // Leipzig
$f_cs_eid_payer = "HTL40098";
$trCscIdRoot_01 = "44548"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44548"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "3") :
$f_hq_id = "104"; // Hannover
$f_cs_eid_payer = "HTH40105";
$trCscIdRoot_01 = "44545"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44545"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "4") :
$f_hq_id = "107"; // Essen
// $f_cs_eid_payer = "HTE10496";
$f_cs_eid_payer = "HTE10977";
$trCscIdRoot_01 = "44543"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44543"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "6") :
$f_hq_id = "105"; // Frankfurt
$f_cs_eid_payer = "HTF40090";
$trCscIdRoot_01 = "44544"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44544"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "7") :
$f_hq_id = "111"; // Stuttgart
$f_cs_eid_payer = "HTS10799";
$trCscIdRoot_01 = "44547"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44547"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "8") :
$f_hq_id = "109"; // München
$f_cs_eid_payer = "HTM65105";
$trCscIdRoot_01 = "44549"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44549"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "9") :
$f_hq_id = "109"; // München
$f_cs_eid_payer = "HTM65105";
$trCscIdRoot_01 = "44549"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44549"; // Hauptkostenstelle Kunde "Extern"
else :
$f_hq_id = "107"; // Essen (Default !!!)
// $f_cs_eid_payer = "HTE10496";
$f_cs_eid_payer = "HTE10977";
$trCscIdRoot_01 = "44543"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44543"; // Hauptkostenstelle Kunde "Extern"
// 44539 101 44540 102 44541 103 44542 106 44546 110
endif;
$csId = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cs_id");
$cscIdRoot = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"csc_id");
// if ($isCashPayerTour): $cscIdRoot = $cscIdCashPayer; endif;
$csInvmode = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cs_invmode");
$cmpPostage = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cmp_id");
if ($cmpPostage == "") : $cmpPostage = "0.00"; endif;
// Check for absolute customer discount
$csDiscountAbsolute = getFieldValueFromId("customer", "cs_id", $csId, "cs_discount");
$useDicountDisabled = getParameterValue("0", "JB_EDITBATCH_DISCOUNT_DISABLED");
if ($useDicountDisabled == "1") :
$csDiscountAbsolute = 0;
endif;
// Mapping of the vehicle type
if ($f_vht_id == "1") :
$f_vht_id = "8"; // 3-To.
elseif ($f_vht_id == "2") :
$f_vht_id = "9"; // 5-To.
elseif ($f_vht_id == "3") :
$f_vht_id = "7"; // 1-To.
else :
$f_vht_id = "8"; // 3-To.
endif;
insertStmt("job", array("hq_id", $f_hq_id, "vht_id", $f_vht_id, "csc_id_payer", $cscIdRoot, "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime_01, "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_taketime", "", "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType, "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id, "jb_fixprice", $f_price, "jb_totalprice", $f_price,
"jb_postage", $cmpPostage, "jb_invmode", $csInvmode, "jb_freetext_1", "",
"jb_sales_tax_rate", $f_tax_value, "jb_sales_tax_rate_sign", $txSign, "jb_booktime", ""));
$jbIdNew = getLastInsertId();
// Insert tour data for station
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new_01, "tr_sort", "1", "tr_comp", $f_tr_comp_01, "tr_comp2", $f_tr_comp2_01,
"tr_hsno", $f_tr_hsno_01, "csc_id", $trCscIdRoot_01, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", $f_tr_ware_from_to,
"tr_person", $f_tr_person, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
// Insert tourservice data
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdRoot, "tr_sort", "0",
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $price, "trs_discount", $csDiscountAbsolute));
// Write logdata into log database
writeToLogDB("55",$hq_id,$jbIdNew,$usr_id,"","","",$csId);
$importFileStatusMsg .= "Station 1 des Auftrags " . $jbIdNew . " wurde importiert.<br>";
else :
if ($fTrSort == "") :
$fTrSort = "2";
else :
$fTrSort++;
endif;
// Update job data
// updateStmt("job","jb_id",$jbIdNew,array("usr_name",$f_usr_name,"usr_firstname",$f_usr_firstname));
// Insert tour data
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new_01, "tr_sort", $fTrSort, "tr_comp", $f_tr_comp_01, "tr_comp2", $f_tr_comp2_01,
"tr_hsno", $f_tr_hsno_01, "csc_id", $trCscIdRoot_01, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", $f_tr_ware_from_to,
"tr_person", $f_tr_person, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$importFileStatusMsg .= "Station " . $fTrSort . " des Auftrags " . $jbIdNew . " wurde importiert.<br>";
endif;
// Insert into import log table
insertStmt("phoenix_log.import", array("imp_id", $f_jb_tourname, "imp_pos", $f_position, "imp_createtime", $currentTime, "jb_id", $jbIdNew));
TA("C");
TA("E");
else :
$importFileStatusMsg .= "Datensatz " . $j . " wurde NICHT importiert, weil sie schon importiert wurde! (Auftrag " . $logJbId . ")<br>";
endif;
}
// Remove import file
$retVal = removeFile($f_importFile, $importPath, $pathSeparator);
else :
$importFileStatusMsg .= "Der Import konnte nicht vollzogen werden, da noch mindestens eine andere Importdatei existiert!<br>";
endif;
endif;
// **************************************************
// * Read all of the local filenames to be imported *
// **************************************************
if ($userTypeName == "hq") :
// Get filenames
$fileNames = getFilenamesInFolder($importPath);
$storedImportFiles .= "<table>";
$storedImportFiles .= "<tr><td class=\"f12bp1_red\" colspan=\"2\">Auftragsimport</td></tr>";
$storedImportFiles .= "<tr><td colspan=\"2\"><br><br></td></tr>";
// Define table header
$storedImportFiles .= "<tr><td>Dateiname&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Löschen</td></tr>";
$storedImportFiles .= "<tr><td colspan=\"2\"><br></td></tr>";
// Define table body from array
$fileNamesLen = count($fileNames);
for ($j = 0; $j < $fileNamesLen; $j++) :
$storedImportFiles .= "<tr>";
$storedImportFiles .= "<td><a href=\"javascript:importImportfile('" . $fileNames[$j] . "');\">" . $fileNames[$j] .
"</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedImportFiles .= "<td align=\"center\"><a href=\"javascript:removeImportfile('" . $fileNames[$j] . "');\">"
. "<img src=\"../images/trash.jpg\" border=\"0\" height=\"13\" width=\"8\">"
. "</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedImportFiles .= "</tr>";
endfor;
$storedImportFiles .= "</table>";
endif;
?>
<html>
<head>
<title>AUFTRAGSIMPORT</title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<script type="text/javascript">
<!--
var statusMessage = "<?php echo $statusMessage ?>";
function displayStatusMessage() {
if (statusMessage != "") {
alert(statusMessage);
}
};
function finishPage(f_act_value) {
document.forms[0].f_act.value=f_act_value;
document.forms[0].submit();
};
function removeImportfile(fileName) {
if (confirm('Importdatei ' + fileName + ' entfernen?')) {
document.forms[0].f_importFile.value = fileName;
finishPage('removeImportfile');
};
};
function importImportfile(fileName) {
if (confirm('Importdatei ' + fileName + ' jetzt importieren?')) {
document.forms[0].f_importFile.value = fileName;
finishPage('goImport');
};
};
function finishPageUpload(f_act_value) {
document.forms[1].f_act.value=f_act_value;
document.forms[1].submit();
};
-->
</script>
</head>
<body onLoad="displayStatusMessage();">
<form name="import_form" action="../import/import_job.php" method="post">
<input type="hidden" name="f_act" value="">
<input type="hidden" name="f_importFile" value="">
<?php echo $storedImportFiles; ?>
</form>
<br><br>
<form name="upload_file" action="../import/import_job.php" enctype="multipart/form-data" method="post">
<!-- <form name="upload_file" action="../import/upload_file.php" enctype="multipart/form-data" method="post"> -->
<input type="hidden" name="f_act" value="">
<p>W&auml;hlen Sie die Auftragsdateidatei von Ihrem Rechner aus:<br>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="f_uploadFile" type="file" size="50" accept="text/*">
<input type="button" value="Upload" onClick="finishPageUpload('uploadFile');">
</p>
<br><br>
<?php echo $importFileStatusMsg; ?>
</form>
</body>
</html>

View File

@@ -0,0 +1,454 @@
<?php
/*=======================================================================
*
* import_job_ls.php
*
* Autor: Marc Vollmann
*
* ToDoS :
* [1] Configuration in php.ini:
* "file_uploads", "upload_max_filesize", "upload_tmp_dir", "post_max_size"
* [2] Change tables "tour" and "tourhistory"
* ALTER TABLE `tour` ADD `tr_cs_freetext` TEXT;
* ALTER TABLE `tourhistory` ADD `tr_cs_freetext` TEXT;
* [3] Create table "import_log"
* CREATE TABLE import (imp_id int(10) NOT NULL default '0',imp_pos smallint(6) NOT NULL default '0', imp_createtime timestamp(14) NOT NULL, jb_id int(10) NOT NULL default '0', UNIQUE KEY imp_id_pos (imp_id,imp_pos)) TYPE=MyISAM;
* [4] Exportcategoryfields have to be inserted
* DELETE FROM `exportcategoryfields` WHERE expc_id = '110'
* => Start Insert-Script
*
=======================================================================*/
include_once ("import.php");
// Execution-Time for script
set_time_limit(30000);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "f_importFile", "f_uploadFile"));
// Select user-type for mode of security check
$userType = getFieldValueFromId("user","usr_id",$usr_id,"usr_type");
$userTypeName = getUserTypeName($userType);
// Get the rights of the employee logged in and check the accessibility
if (!authCheckEmployeeRights($emp_id, "7")) : die ("$PHP_SELF: Access denied!"); endif;
$statusMessage = "";
$importFileStatusMsg = "";
$jbIdNew = "";
$fJbTourname = "";
$fTrSort = "";
// Get number of files in the upload folder
$numOfFiles = getNumOfFilesInFolder($importPath);
// Process uploaded file
if ($f_act == "uploadFile") :
if ($numOfFiles < 1) :
if ($_FILES['f_uploadFile']['size'] <= 2000000) :
if (!move_uploaded_file($_FILES['f_uploadFile']['tmp_name'], $importPath . $_FILES['f_uploadFile']['name'])) :
$statusMessage .= "Die Datei wurde leider nicht hochgeladen!";
endif;
else :
$statusMessage .= "Die Datei ist für den Upload zu groß!";
// Delete real file if does exist
$retVal = removeFile($_FILES['f_uploadFile']['name'], $importPath, $pathSeparator);
endif;
// Delete temp file if does exist
$retVal = removeFile($_FILES['f_uploadFile']['tmp_name'], $tempPath, $pathSeparator);
else :
$statusMessage .= "Bevor eine weitere Datei hochgeladen werden kann, muss das Verzeichnis geleert werden!";
endif;
endif;
// Manually removal of a specified importfile
if ($f_act == "removeImportfile") :
// Remove import file
$retVal = removeFile($f_importFile, $importPath, $pathSeparator);
if ($retVal == "0") :
elseif ($retVal == "-1") :
$statusMessage = "Es liegt kein Dateiname vor!";
elseif ($retVal == "-2") :
$statusMessage = "Die Datei befindet sich nicht mehr in dem Verzeichnis!";
elseif ($retVal == "") :
$statusMessage = "Es fand keine Löschung statt!";
endif;
endif;
// Import process
if ($f_act == "goImport") :
if ($numOfFiles == 1) :
$importFileStatusMsg .= "<br><br><br><br><span class=\"f12bp1_red\" colspan=\"2\">Verarbeitungsprotokoll:</span><br><br>";
$importFileStatusMsg .= "Import-Datei: " . $f_importFile . "<br><br>";
$rowToImport = array();
$rowToImport[0] = "f_id_unique"; // internalOrderID (unique key)
$rowToImport[1] = "f_tr_person"; // externalOrderID
$rowToImport[2] = "f_cs_eid"; // externalCustomerNumber
$rowToImport[3] = "f_tr_ware_from_to"; // type
$rowToImport[4] = "f_jb_weight"; // weight
$rowToImport[5] = "f_vht_id"; // capacityClass
$rowToImport[6] = "f_tr_commission_no"; // loadingUnitType
$rowToImport[7] = "f_tr_remark_1"; // goodsdescription
$rowToImport[8] = "f_tr_comp_01"; // pickup/name
$rowToImport[9] = "f_ad_zipcode_01"; // pickup/zipCode
$rowToImport[10] = "f_ad_city_01"; // pickup/city
$rowToImport[11] = "f_ad_street_01"; // pickup/street (containing houseno.)
$rowToImport[12] = "f_jb_ordertime_01"; // pickup/plannedPickup
$rowToImport[13] = "f_tr_comp_02"; // delivery/name
$rowToImport[14] = "f_tr_remark_2"; // delivery/contact
$rowToImport[15] = "f_tr_remark_3"; // delivery/telephone
$rowToImport[16] = "f_ad_zipcode_02"; // delivery/zipCode
$rowToImport[17] = "f_ad_city_02"; // delivery/city
$rowToImport[18] = "f_ad_street_02"; // delivery/street (containing houseno.)
$rowToImport[19] = "f_jb_ordertime_02"; // delivery/plannedDelivery
$rowToImport[20] = "f_jb_tourname"; // tourID
$rowToImport[21] = "f_position"; // position
$rowToImport[22] = "f_dummy"; // dummy
$rowToImportLen = count($rowToImport);
// read file to import
$data = importCSV($importPath . $f_importFile, $delimiter);
$dataLen = count($data);
// loop all rows
for ($j = 0; $j < $dataLen; $j++) {
// loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
// Next job begins
if ($fJbTourname == "" || $fJbTourname != $f_jb_tourname) :
$jbIdNew = "";
$fTrSort = "";
$fJbTourname = $f_jb_tourname;
endif;
// Check import log table in db according to the unique key "tourID + position" (<=> $f_jb_tourname + $f_position)
$logJbId = getFieldValueFromClause("phoenix_log.import","jb_id","imp_id = '" . $f_jb_tourname . "' AND imp_pos = '" . $f_position . "'");
if ($logJbId == "") :
TA("B");
if (substr($f_cs_eid, 0, 9) == "000000000") :
$f_cs_eid = substr($f_cs_eid, -($csEidStrLen));
else :
$tmpLen = strlen($f_cs_eid);
while (substr($f_cs_eid, 0, 1) == "0"):
$f_cs_eid = substr($f_cs_eid, 1, $tmpLen);
endwhile;
endif;
// Constants
$cscIdCashPayer = getParameterValue("0", "CSC_ID_PAYER_CASH", $f_hq_id);
// Concatenation of external cs_id an name
$f_tr_comp_01 = $f_cs_eid . " " . $f_tr_comp_01;
$f_tr_remark = $f_tr_remark_1 . " " . $f_tr_remark_2 . " " . $f_tr_remark_3 . " " . $f_jb_ordertime_02;
$f_tr_remark = $f_tr_remark;
// Extra field "internal remark of the customer" for customer export
$f_tr_cs_freetext = $f_tr_remark;
// Split street to street and houseno.
$f_tr_hsno_01 = ".";
$f_tr_hsno_02 = ".";
// Get 1. address id
$tmpArray = insertAddress($f_ad_street_01, $f_ad_zipcode_01, $f_ad_city_01, "", "", true);
$ad_id_new_01 = $tmpArray[0];
// Get 2. address id
$tmpArray = insertAddress($f_ad_street_02, $f_ad_zipcode_02, $f_ad_city_02, "", "", true);
$ad_id_new_02 = $tmpArray[0];
// Get the current time
$currentTime = getDateTime("0");
// Insert job data
if ($jbIdNew == "") :
$jbStatus = "9";
$jbType = "2"; // "G"
$crId = "";
$crSid = "";
$jbFinishtime = "";
$csInvmod = "";
$price = 0;
if (!isset($f_tax_value) || $f_tax_value == ""):
$f_tax_value = getFieldValueFromId("tax","tx_id","4","tx_value");
if ($f_tax_value == ""):
$f_tax_value = "19.00";
endif;
endif;
$txSign = "V";
// Mapping of the headquarters
$tmpZipcode = substr($f_ad_zipcode_01 ,0 ,1); // Get the first character
if ($tmpZipcode == "0") :
$f_hq_id = "108"; // Leipzig
$f_cs_eid_payer = "HTL40098";
$trCscIdRoot_01 = "44548"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44548"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "3") :
$f_hq_id = "104"; // Hannover
$f_cs_eid_payer = "HTH40105";
$trCscIdRoot_01 = "44545"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44545"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "4") :
$f_hq_id = "107"; // Essen
$f_cs_eid_payer = "HTE10496";
$trCscIdRoot_01 = "44543"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44543"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "6") :
$f_hq_id = "105"; // Frankfurt
$f_cs_eid_payer = "HTF40090";
$trCscIdRoot_01 = "44544"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44544"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "7") :
$f_hq_id = "111"; // Stuttgart
$f_cs_eid_payer = "HTS40032";
$trCscIdRoot_01 = "44547"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44547"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "8") :
$f_hq_id = "109"; // München
$f_cs_eid_payer = "HTM65105";
$trCscIdRoot_01 = "44549"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44549"; // Hauptkostenstelle Kunde "Extern"
elseif ($tmpZipcode == "9") :
$f_hq_id = "109"; // München
$f_cs_eid_payer = "HTM65105";
$trCscIdRoot_01 = "44549"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44549"; // Hauptkostenstelle Kunde "Extern"
else :
$f_hq_id = "107"; // Essen (Default !!!)
$f_cs_eid_payer = "HTE10496";
$trCscIdRoot_01 = "44543"; // Hauptkostenstelle Kunde "Extern"
$trCscIdRoot_02 = "44543"; // Hauptkostenstelle Kunde "Extern"
// 44539 101 44540 102 44541 103 44542 106 44546 110
endif;
$csId = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cs_id");
$cscIdRoot = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"csc_id");
// if ($isCashPayerTour): $cscIdRoot = $cscIdCashPayer; endif;
$csInvmode = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cs_invmode");
$cmpPostage = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cmp_id");
if ($cmpPostage == "") : $cmpPostage = "0.00"; endif;
// Check for absolute customer discount
$csDiscountAbsolute = getFieldValueFromId("customer", "cs_id", $csId, "cs_discount");
$useDicountDisabled = getParameterValue("0", "JB_EDITBATCH_DISCOUNT_DISABLED");
if ($useDicountDisabled == "1") :
$csDiscountAbsolute = 0;
endif;
// Mapping of the vehicle type
if ($f_vht_id == "1") :
$f_vht_id = "8"; // 3-To.
elseif ($f_vht_id == "2") :
$f_vht_id = "9"; // 5-To.
elseif ($f_vht_id == "3") :
$f_vht_id = "7"; // 1-To.
else :
$f_vht_id = "8"; // 3-To.
endif;
insertStmt("job", array("hq_id", $f_hq_id, "vht_id", $f_vht_id, "csc_id_payer", $cscIdRoot, "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime_01, "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_taketime", "", "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType, "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id, "jb_fixprice", $f_price, "jb_totalprice", $f_price,
"jb_postage", $cmpPostage, "jb_invmode", $csInvmode, "jb_freetext_1", "",
"jb_sales_tax_rate", $f_tax_value, "jb_sales_tax_rate_sign", $txSign, "jb_booktime", ""));
$jbIdNew = getLastInsertId();
// Insert tour data for station 1
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new_01, "tr_sort", "1", "tr_comp", $f_tr_comp_01, "tr_comp2", "",
"tr_hsno", $f_tr_hsno_01, "csc_id", $trCscIdRoot_01, "tr_status", "0",
"tr_commission_no", "", "tr_ware_from_to", "1",
"tr_person", "", "tr_remark", "", "tr_cs_freetext", ""));
// Insert tour data for station 2
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new_02, "tr_sort", "2", "tr_comp", $f_tr_comp_02, "tr_comp2", "",
"tr_hsno", $f_tr_hsno_02, "csc_id", $trCscIdRoot_02, "tr_status", "0",
"tr_person", $f_tr_person, "tr_commission_no", $f_tr_commission_no,
"tr_ware_from_to", "2", "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
// Insert tourservice data
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdRoot, "tr_sort", "0",
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $price, "trs_discount", $csDiscountAbsolute));
// Write logdata into log database
writeToLogDB("55",$hq_id,$jbIdNew,$usr_id,"","","",$csId);
$importFileStatusMsg .= "Stationen 1 und 2 des Auftrags " . $jbIdNew . " wurden importiert.<br>";
else :
if ($fTrSort == "") :
$fTrSort = "3";
else :
$fTrSort++;
endif;
// Update job data
// updateStmt("job","jb_id",$jbIdNew,array("usr_name",$f_usr_name,"usr_firstname",$f_usr_firstname));
// Insert tour data for
if ($f_tr_ware_from_to == "0") :
// Delivery => Delivery address
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new_02, "tr_sort", $fTrSort, "tr_comp", $f_tr_comp_02, "tr_comp2", "",
"tr_hsno", $f_tr_hsno_02, "csc_id", $trCscIdRoot_02, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "2",
"tr_person", $f_tr_person, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
else :
// Retoure => Pickup address
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new_01, "tr_sort", $fTrSort, "tr_comp", $f_tr_comp_01, "tr_comp2", "",
"tr_hsno", $f_tr_hsno_01, "csc_id", $trCscIdRoot_01, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", "1",
"tr_person", $f_tr_person, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
endif;
$importFileStatusMsg .= "Station " . $fTrSort . " des Auftrags " . $jbIdNew . " wurde importiert.<br>";
endif;
// Insert into import log table
insertStmt("phoenix_log.import", array("imp_id", $f_jb_tourname, "imp_pos", $f_position, "imp_createtime", $currentTime, "jb_id", $jbIdNew));
TA("C");
TA("E");
else :
$importFileStatusMsg .= "Datensatz " . $j . " wurde NICHT importiert, weil sie schon importiert wurde! (Auftrag " . $logJbId . ")<br>";
endif;
}
// Remove import file
$retVal = removeFile($f_importFile, $importPath, $pathSeparator);
else :
$importFileStatusMsg .= "Der Import konnte nicht vollzogen werden, da noch mindestens eine andere Importdatei existiert!<br>";
endif;
endif;
// **************************************************
// * Read all of the local filenames to be imported *
// **************************************************
if ($userTypeName == "hq") :
// Get filenames
$fileNames = getFilenamesInFolder($importPath);
$storedImportFiles .= "<table>";
$storedImportFiles .= "<tr><td class=\"f12bp1_red\" colspan=\"2\">Auftragsimport</td></tr>";
$storedImportFiles .= "<tr><td colspan=\"2\"><br><br></td></tr>";
// Define table header
$storedImportFiles .= "<tr><td>Dateiname&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Löschen</td></tr>";
$storedImportFiles .= "<tr><td colspan=\"2\"><br></td></tr>";
// Define table body from array
$fileNamesLen = count($fileNames);
for ($j = 0; $j < $fileNamesLen; $j++) :
$storedImportFiles .= "<tr>";
$storedImportFiles .= "<td><a href=\"javascript:importImportfile('" . $fileNames[$j] . "');\">" . $fileNames[$j] .
"</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedImportFiles .= "<td align=\"center\"><a href=\"javascript:removeImportfile('" . $fileNames[$j] . "');\">"
. "<img src=\"../images/trash.jpg\" border=\"0\" height=\"13\" width=\"8\">"
. "</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedImportFiles .= "</tr>";
endfor;
$storedImportFiles .= "</table>";
endif;
?>
<html>
<head>
<title>AUFTRAGSIMPORT</title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<script type="text/javascript">
<!--
var statusMessage = "<?php echo $statusMessage ?>";
function displayStatusMessage() {
if (statusMessage != "") {
alert(statusMessage);
}
};
function finishPage(f_act_value) {
document.forms[0].f_act.value=f_act_value;
document.forms[0].submit();
};
function removeImportfile(fileName) {
if (confirm('Importdatei ' + fileName + ' entfernen?')) {
document.forms[0].f_importFile.value = fileName;
finishPage('removeImportfile');
};
};
function importImportfile(fileName) {
if (confirm('Importdatei ' + fileName + ' jetzt importieren?')) {
document.forms[0].f_importFile.value = fileName;
finishPage('goImport');
};
};
function finishPageUpload(f_act_value) {
document.forms[1].f_act.value=f_act_value;
document.forms[1].submit();
};
-->
</script>
</head>
<body onLoad="displayStatusMessage();">
<form name="import_form" action="../import/import_job_ls.php" method="post">
<input type="hidden" name="f_act" value="">
<input type="hidden" name="f_importFile" value="">
<?php echo $storedImportFiles; ?>
</form>
<br><br>
<form name="upload_file" action="../import/import_job.php" enctype="multipart/form-data" method="post">
<!-- <form name="upload_file" action="../import/upload_file.php" enctype="multipart/form-data" method="post"> -->
<input type="hidden" name="f_act" value="">
<p>W&auml;hlen Sie die Auftragsdateidatei von Ihrem Rechner aus:<br>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="f_uploadFile" type="file" size="50" accept="text/*">
<input type="button" value="Upload" onClick="finishPageUpload('uploadFile');">
</p>
<br><br>
<?php echo $importFileStatusMsg; ?>
</form>
</body>
</html>

View File

@@ -0,0 +1,579 @@
<?php
/*=======================================================================
*
* import_saturn.php
*
* Autor: Marc Vollmann, Carsten Annacker
*
* ToDoS :
* [1] Configuration in php.ini:
* "file_uploads", "upload_max_filesize", "upload_tmp_dir", "post_max_size"
* [2] Change tables "tour" and "tourhistory"
* ALTER TABLE `tour` ADD `tr_cs_freetext` TEXT;
* ALTER TABLE `tourhistory` ADD `tr_cs_freetext` TEXT;
* [3] Create table "import_log"
* CREATE TABLE import (imp_id int(10) NOT NULL default '0',imp_pos smallint(6) NOT NULL default '0', imp_createtime timestamp(14) NOT NULL, jb_id int(10) NOT NULL default '0', UNIQUE KEY imp_id_pos (imp_id,imp_pos)) TYPE=MyISAM;
* [4] Exportcategoryfields have to be inserted
* DELETE FROM `exportcategoryfields` WHERE expc_id = '110'
* => Start Insert-Script
*
* - Ablauf: Erst Rollkarte, dann Tourenplanung importieren; von letzterer wird nur das ausführende Fahrzeug, der vollständige Name des Kunden
* (zusätzlich der Vorname vorhanden), der auftraggebende Saturn-Markt, das ausführendes Fahrzeug, die Kundennummer des Kunden bei Saturn
* übernommen und anhand der Belegnummer der bestehenden Rollkartenstation zugeordnet
* - Nur eine Datei pro Upload möglich, bearbeitete Datei wird gelöscht --> ok so?
* - Tourenplanung enthält weniger Belege als Rollkarte, d.h einige Stationen verbleiben ohne vollständigen Namen in der Adresse
* --> unvollständige Stationen verbleiben, wenn das normal ist, dann muss jb_incomplete gepflegt werden
* - Welche Bedeutung haben die auftraggebenden Märkte für die Tourenplanung?
=======================================================================*/
include_once ("import.php");
include_once ("xServer.inc.php");
// Execution-Time for script
set_time_limit(30000);
$importPath = "../import/upload_saturn/";
$tempPath = "../temp/upload_saturn/";
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "f_importFile", "f_uploadFile"));
// Select user-type for mode of security check
$userType = getFieldValueFromId("user","usr_id",$usr_id,"usr_type");
$userTypeName = getUserTypeName($userType);
// Get the rights of the employee logged in and check the accessibility
if (!authCheckEmployeeRights($emp_id, "7")) : die ("$PHP_SELF: Access denied!"); endif;
$statusMessage = "";
$importFileStatusMsg = "";
$jbIdNew = "";
// Get number of files in the upload folder
$numOfFiles = getNumOfFilesInFolder($importPath);
// Process uploaded file
if ($f_act == "uploadFile") :
if ($numOfFiles < 1) :
if ($_FILES['f_uploadFile']['size'] <= 2000000) :
if (!move_uploaded_file($_FILES['f_uploadFile']['tmp_name'], $importPath . $_FILES['f_uploadFile']['name'])) :
$statusMessage .= "Die Datei wurde leider nicht hochgeladen!";
endif;
else :
$statusMessage .= "Die Datei ist für den Upload zu groß!";
// Delete real file if does exist
$retVal = removeFile($_FILES['f_uploadFile']['name'], $importPath, $pathSeparator);
endif;
// Delete temp file if does exist
$retVal = removeFile($_FILES['f_uploadFile']['tmp_name'], $tempPath, $pathSeparator);
else :
$statusMessage .= "Bevor eine weitere Datei hochgeladen werden kann, muss das Verzeichnis geleert werden!";
endif;
endif;
// Manually removal of a specified importfile
if ($f_act == "removeImportfile") :
// Remove import file
$retVal = removeFile($f_importFile, $importPath, $pathSeparator);
if ($retVal == "0") :
elseif ($retVal == "-1") :
$statusMessage = "Es liegt kein Dateiname vor!";
elseif ($retVal == "-2") :
$statusMessage = "Die Datei befindet sich nicht mehr in dem Verzeichnis!";
elseif ($retVal == "") :
$statusMessage = "Es fand keine Löschung statt!";
endif;
endif;
// Import process
if ($f_act == "goImport") :
// if ($numOfFiles == 1) :
/**************************************************
* Read csv
**************************************************/
$importFileStatusMsg .= "<br><br><br><br><span class=\"f12bp1_red\" colspan=\"2\">Verarbeitungsprotokoll:</span><br><br>\n";
$importFileStatusMsg .= "Import-Datei: " . $f_importFile . "<br><br>\n";
// read file to import
$data = importCSV($importPath . $f_importFile);
$dataLen = count($data);
$impType = 0;
// find out whether current file ist Rollkarte oder Tourenplanung
if (count($data[0]) == 12): // Rollkarte
$impType = 1;
$impName = "Rollkarte";
elseif (count($data[0]) == 19): // Tourenplanung
$impType = 2;
$impName = "Tourenplanung";
else:
die('Fehler: Importdatei hat ungültige Anzahl von Spalten.');
endif;
/**************************************************
* aggregate lines to stops
**************************************************/
$file_csv = file_get_contents($importPath . $f_importFile);
writeLog($f_importFile . "\n" . $file_csv, "import_saturn_csv");
//print_r($data); die();
$tourA = array();
// loop all rows
$j = 0;
$i = 0;
$cr_sids = array(); // nur Tourenplanung
$f_hq_id = "102"; // Hamburg
$trCscIdRoot = "44540"; // Hauptkostenstelle Kunde "Extern"
while ($j < $dataLen):
if ($impType == 1): // Rollkarte
// get current documentnumber
$cur_documentnumber = $data[$j][3];
$i++;
while (trim($data[$j][3]) == $cur_documentnumber && $j < $dataLen):
// loop for all fields of $fields of the row
// $tourA[$i]["f_jb_ordertime"] = trim($data[$j][1]); // delivery date
// $tourA[$i]["f_tr_ware_from_to"] = trim($data[$j][2]); // time-limit: G=0=full-time, V=1=ante meridiem, N=2=post meridiem
$tourA[$i]["f_tr_person"] = trim($data[$j][3]); // documentnumber (Belegnummer) Saturn (stored in tr_persopn because of searchability)
$tourA[$i]["f_tr_remark"] .= str_replace("\\\\", "|", trim($data[$j][4]) . " " . trim($data[$j][5]) . " " . trim($data[$j][6])) . "\n";
// arcticlenumber Saturn, arcticledescription1 Saturn, arcticledescription2 Saturn
$tourA[$i]["f_tr_remark1"] = str_replace("\\\\", "|", trim($data[$j][11])); // rest of description
// $tourA[$i]["f_tr_comp"] = trim($data[$j][7]); // name of customer
$tourA[$i]["f_ad_street"] = trim($data[$j][8]); // delivery/street
$tourA[$i]["f_ad_zipcode"] = trim($data[$j][9]); // delivery/zipCode
$tourA[$i]["f_ad_city"] = (trim($data[$j][10]) == "HH" ? "HAMBURG" : trim($data[$j][10])); // delivery/city
$j++;
// rest dummy
// ignore garbage lines (i.e. no documentnumber)
while (trim($data[$j][3]) == "" && $j < $dataLen):
$tourA[$i]["f_tr_remark1"] .= " " . str_replace("\\\\", "|", trim($data[$j][0])); // rest of previous remarkline
$j++;
endwhile;
endwhile;
elseif ($impType == 2): // Tourenplanung
// get current documentnumber
$cur_documentnumber = $data[$j][6];
$i++;
while (trim($data[$j][6]) == $cur_documentnumber && $j < $dataLen):
// loop for all fields of $fields of the row, negative numbers are ignored
if (trim($data[$j][10]) != "-1"):
$tourA[$i]["f_jb_ordertime"] = trim($data[$j][0]); // delivery date
$tourA[$i]["f_tr_ware_from_to"] = trim($data[$j][1]); // time-limit: G=0=full-time, V=1=ante meridiem, N=2=post meridiem
$tourA[$i]["f_tr_mediationarea_name"] = trim($data[$j][2]); // Auftraggebender Saturn-Markt
$cr_sid_parts = explode(" ", trim($data[$j][4])); // ausführendes Fahrzeug in brauchbare cr_sid verwandeln...
$tourA[$i]["f_jb_cr_sid"] = "HH" . $cr_sid_parts[count($cr_sid_parts) - 1];
$tourA[$i]["f_jb_cr_id"] = getFieldValueFromId("couriervehicle", "crvh_sid", $tourA[$i]["f_jb_cr_sid"], "cr_id");
$tourA[$i]["f_jb_vht_id"] = getFieldValueFromId("couriervehicle", "crvh_sid", $tourA[$i]["f_jb_cr_sid"], "vht_id");
$tourA[$i]["f_tr_comp2"] = trim($data[$j][5]); // Kundennummer des Kunden bei Saturn
$tourA[$i]["f_tr_person"] = trim($data[$j][6]); // Beleggnummer Saturn
$tourA[$i]["f_tr_comp"] = trim($data[$j][7]) . ", " . trim($data[$j][8]); // Nachname, Vorname des Kunden
// rest dummy
// ignore garbage lines (i.e. no documentnumber)
endif;
$j++;
while (trim($data[$j][6]) == "" && $j < $dataLen): $j++; endwhile;
endwhile;
else:
die('Fehler: Ungültiger Importtyp.');
endif;
endwhile;
//print_r($tourA); die();
/**************************************************
* write stops to job and tour
**************************************************/
$allCoords = array();
$doPlan = array();
TA("BEGIN");
foreach ($tourA AS $tour) {
// Check import log table in db according to the unique key "f_tr_person"
$logJbId = getFieldValueFromClause("phoenix_log.import","jb_id","imp_id = '" . $tour["f_tr_person"] . $impType . "'");
if ($logJbId == "" && $tour["f_tr_person"] != "Beleg-Nr.") :
if ($impType == 1): // Rollkarte
// find corresponding Tourenplanung
$jbIdNew = getFieldValueFromClause("phoenix_log.import","jb_id","imp_id = '" . $tour["f_tr_person"] . 2 . "'");
// writeToLogDB("55", $hq_id, $jbIdNew, $usr_id, $tour["f_jb_cr_id"], $tour["f_jb_cr_sid"], $csId, "Import Rollkarte");
if ($jbIdNew != ''):
// Get address id
$tour["f_ad_street"] = str_replace(".", ". ", $tour["f_ad_street"]);
$f_ad_street_parts = explode(" ", $tour["f_ad_street"]);
$f_ad_street = $f_ad_street_parts[0];
$f_tr_hsno = "";
if (count($f_ad_street_parts) > 1):
$f_tr_hsno = $f_ad_street_parts[1];
if (count($f_ad_street_parts) > 2):
if (strlen($f_ad_street_parts[count($f_ad_street_parts) - 1]) == 1):
if (ord(strtoupper($f_ad_street_parts[count($f_ad_street_parts) - 1])) >= ord("A")
&& ord(strtoupper($f_ad_street_parts[count($f_ad_street_parts) - 1])) <= ord("Z")):
$f_tr_hsno = $f_ad_street_parts[count($f_ad_street_parts) - 2] . " " . $f_ad_street_parts[count($f_ad_street_parts) - 1];
for ($k = 1; $k < count($f_ad_street_parts) - 2; $k++)
$f_ad_street .= " " . $f_ad_street_parts[$k];
else:
for ($k = 1; $k < count($f_ad_street_parts) - 1; $k++)
$f_ad_street .= " " . $f_ad_street_parts[$k];
$f_tr_hsno = $f_ad_street_parts[count($f_ad_street_parts) - 1];
endif;
else:
for ($k = 1; $k < count($f_ad_street_parts) - 1; $k++)
$f_ad_street .= " " . $f_ad_street_parts[$k];
$f_tr_hsno = $f_ad_street_parts[count($f_ad_street_parts) - 1];
endif;
endif;
endif;
$txt = "Suche Koordinaten für Adresse " . $tour["f_ad_zipcode"] . " " . $tour["f_ad_city"] . " " . $f_ad_street . " " . $f_tr_hsno . " ...";
echo $txt; flush();
writeLog($txt, "import_saturn");
$coords = XSfindAddress("D", $tour["f_ad_zipcode"], $tour["f_ad_city"], $f_ad_street, $f_tr_hsno);
$invalidAddressCur = 1;
if ($coords[0][0] != 100) {
$txt = " kein exakter Match<br>\n";
echo $txt; flush();
writeLog($txt, "import_saturn");
$importFileStatusMsg .= "Fehlerhafte Adresse in Belegnummer [" . $tour["f_tr_person"] . "]: [" .
$tour["f_ad_zipcode"] . " " . $tour["f_ad_city"] . " " . $f_ad_street . " " . $f_tr_hsno . "]. <b>Routenoptmierung nicht möglich!</b><br>\n";
$invalidAddressCur = -1;
} else {
$txt = " ok<br>\n";
echo $txt; flush();
writeLog($txt, "import_saturn");
$allCoords[] = array($coords[0][1], $coords[0][2]);
$f_tr_cs_freetext = $coords[0][1] . "," . $coords[0][2];
}
$tmpArray = insertAddress($f_ad_street, $tour["f_ad_zipcode"], $tour["f_ad_city"], "", "", true);
$ad_id_new = $tmpArray[0];
endif;
elseif ($impType == 2): // Tourenplanung
// nur ein Auftrag pro Fahrer!
$jbIdNew = "";
$fTrSort = 2;
$f_jb_ordertime = substr($tour["f_jb_ordertime"],6,4) . "-" . substr($tour["f_jb_ordertime"],3,2) . "-" . substr($tour["f_jb_ordertime"],0,2) . " 08:00:00";
if (!(array_key_exists($tour["f_jb_cr_sid"], $cr_sids))):
// check, whether jobs have already been created today in a previous import
writeLog("SELECT jb_id FROM phoenix_log.log WHERE cr_sid = '" . $tour["f_jb_cr_sid"] . "' AND logo_description = 'Import Tourenplanung $f_jb_ordertime'", "import_saturn");
$jb_id_tmp = $db->getOne("SELECT jb_id FROM phoenix_log.log WHERE cr_sid = '" . $tour["f_jb_cr_sid"] . "' AND logo_description = 'Import Tourenplanung $f_jb_ordertime'");
if ($jb_id_tmp > 0):
$tr_sort_tmp = $db->getOne("SELECT MAX(tr_sort) FROM tour WHERE jb_id = $jb_id_tmp");
$cr_sids[$tour["f_jb_cr_sid"]][0] = $jb_id_tmp;
$cr_sids[$tour["f_jb_cr_sid"]][1] = $tr_sort_tmp + 2;
$jbIdNew = $jb_id_tmp;
$fTrSort = $tr_sort_tmp + 1;
writeLog("jbIdNew = $jbIdNew, fTrSort = $fTrSort", "import_saturn");
else:
$cr_sids[$tour["f_jb_cr_sid"]][0] = 0;
$cr_sids[$tour["f_jb_cr_sid"]][1] = 3;
endif;
elseif ($cr_sids[$tour["f_jb_cr_sid"]][0] > 0):
$jbIdNew = $cr_sids[$tour["f_jb_cr_sid"]][0];
$fTrSort = $cr_sids[$tour["f_jb_cr_sid"]][1]++;
//echo "$jbIdNew, $fTrSort<br>\n";
endif;
else:
die('Fehler: Ungültiger Importtyp.');
endif;
/**************************************************
* write data to db
**************************************************/
// Get the current time
$currentTime = getDateTime("0");
// Insert job data
if ($jbIdNew == "" && $impType == 2):
$jbStatus = "9";
$jbType = "2"; // "G"
$csInvmod = "";
$price = 0;
if (!isset($f_tax_value) || $f_tax_value == ""):
$f_tax_value = getFieldValueFromId("tax","tx_id","4","tx_value");
if ($f_tax_value == ""):
$f_tax_value = "19.00";
endif;
endif;
$txSign = "V";
$f_price = $price;
$f_cs_eid_payer = "HTHH30794";
$csId = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cs_id");
$f_csc_id_payer = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"csc_id");
// if ($isCashPayerTour): $cscIdRoot = $cscIdCashPayer; endif;
$csInvmode = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cs_invmode");
$cmpPostage = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cmp_id");
if ($cmpPostage == "") : $cmpPostage = "0.00"; endif;
// Check for absolute customer discount
$csDiscountAbsolute = getFieldValueFromId("customer", "cs_id", $csId, "cs_discount");
$useDiscountDisabled = getParameterValue("0", "JB_EDITBATCH_DISCOUNT_DISABLED");
if ($useDicountDisabled == "1") :
$csDiscountAbsolute = 0;
endif;
insertStmt("job", array("hq_id", $f_hq_id, "vht_id", $f_vht_id, "csc_id_payer", $f_csc_id_payer, "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $tour["f_jb_cr_id"], "cr_sid", $tour["f_jb_cr_sid"], "cr_id_order", $tour["f_jb_cr_id"],
"jb_taketime", "", "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType, "jb_incomplete", "0", "jb_globaljob", 0,
"jb_tourname", "", "emp_id", $usr_id, "jb_fixprice", $f_price, "jb_totalprice", $f_price,
"jb_postage", $cmpPostage, "jb_invmode", $csInvmode, "jb_freetext_1", "",
"jb_sales_tax_rate", $f_tax_value, "jb_sales_tax_rate_sign", $txSign,));
// print_r( array("hq_id", $f_hq_id, "vht_id", $f_vht_id, "csc_id_payer", $f_csc_id_payer, "jb_payment", "0",
// "jb_ordertime", $f_jb_ordertime, "jb_reserv", "1", "cr_id", $tour["f_jb_cr_id"], "cr_sid", $tour["f_jb_cr_sid"], "cr_id_order", $tour["f_jb_cr_id"],
// "jb_taketime", "", "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType, "jb_tourname", "",
// "emp_id", $usr_id, "jb_fixprice", $f_price, "jb_totalprice", $f_price,
// "jb_postage", $cmpPostage, "jb_invmode", $csInvmode, "jb_freetext_1", "",
// "jb_sales_tax_rate", $f_tax_value, "jb_sales_tax_rate_sign", $txSign,));
$jbIdNew = getLastInsertId();
$cr_sids[$tour["f_jb_cr_sid"]][0] = $jbIdNew;
// $coords = XSfindAddress("D", "22848", "Norderstedt", "Niendorfer Str.", 172);
// $coords = XSfindAddress("D", "20537", "Hamburg", "Sorbenstr.", 22);
// $f_tr_cs_freetext = $coords[0][1] . "," . $coords[0][2];
// insert first station
insertStmt("tour", array("jb_id", $jbIdNew, "tr_sort", 1, "ad_id", 117135 /*2229*/, "tr_hsno", 22 /*172*/, "csc_id", $trCscIdRoot,
"tr_remark", "", "tr_cs_freetext", "1003996, 5354938" /*"997928.0000000017,5366139.000000002"*/,
"tr_mediationarea_name", "", "tr_comp2", "", "tr_comp", "Master-Express" /*"Haase Logistik GmbH"*/,
"tr_commission_no", "07 - 09 Uhr", "tr_ware_from_to", 0, "tr_person", ""));
// Insert tourservice data
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $f_csc_id_payer, "tr_sort", "0",
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $price, "trs_discount", $csDiscountAbsolute));
// print_r(array("jb_id", $jbIdNew, "csc_id", $f_csc_id_payer, "tr_sort", "0",
// "srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
// "trs_price", $price, "trs_discount", $csDiscountAbsolute));
// Write logdata into log database
writeToLogDB("55",$hq_id,$jbIdNew,$usr_id,$tour["f_jb_cr_id"],$tour["f_jb_cr_sid"],$csId, "Import Tourenplanung $f_jb_ordertime");
endif;
if ($impType == 1):
if ($jbIdNew != ''):
updateStmt("tour","jb_id", $jbIdNew, array("ad_id", $ad_id_new, "tr_hsno", $f_tr_hsno, "csc_id", $trCscIdRoot,
"tr_remark", $tour["f_tr_remark"] . $tour["f_tr_remark1"], "tr_cs_freetext", $f_tr_cs_freetext), "tr_person = " . $tour["f_tr_person"]);
$importFileStatusMsg .= "$impName zu Belegnummer <i>" . $tour["f_tr_person"] . "</i> wurde importiert in Auftrag Nr. <i>" . $jbIdNew . "</i>.<br>\n";
if ($invalidAddressCur == 1)
insertStmt("phoenix_log.import", array("imp_id", ($tour["f_tr_person"] * $invalidAddressCur). $impType, "imp_pos", $fTrSort, "imp_createtime", $currentTime, "jb_id", $jbIdNew));
// print_r(array("imp_id", $tour["f_tr_person"], "imp_pos", $fTrSort, "imp_createtime", $currentTime, "jb_id", $jbIdNew));
if (!(array_key_exists($jbIdNew, $doPlan))):
$doPlan[$jbIdNew] = 1;
endif;
if ($invalidAddressCur != 1):
$doPlan[$jbIdNew] = 0;
endif;
else:
$importFileStatusMsg .= "$impName zu Belegnummer <i>" . $tour["f_tr_person"] . "</i> wurde <b>nicht</b> importiert, weil <b>entsprechende Tourenplanung noch nicht vorhanden.</b><br>\n";
endif;
elseif ($impType == 2):
$doNotImport = false;
$f_tr_commission_no = "";
// time-limit: G=0=full-time, V=1=ante meridiem, N=2=post meridiem
switch ($tour["f_tr_ware_from_to"]) {
case 'G':
$f_tr_commission_no = "08 - 19 Uhr"; break;
case 'V':
$f_tr_commission_no = "08 - 14 Uhr"; break;
case 'N':
$f_tr_commission_no = "13 - 19 Uhr"; break;
case 'E':
$f_tr_commission_no = "16 - 20 Uhr"; break;
default:
$importFileStatusMsg .= "$impName zu Belegnummer <i>" . $tour["f_tr_person"] . "</i> wurde <b>nicht</b> importiert. ";
$importFileStatusMsg .= "Fehlerhaftes Zeitfenster: [" . $tour["f_tr_ware_from_to"] . "]. Erlaubt sind nur [G], [V], [N], und [E].</b><br>\n";
$doNotImport = true;
}
if (!$doNotImport):
// Insert tour data for station
insertStmt("tour", array("jb_id", $jbIdNew, "tr_sort", $fTrSort,
"tr_mediationarea_name", $tour["f_tr_mediationarea_name"], "tr_comp2", $tour["f_tr_comp2"], "tr_comp", $tour["f_tr_comp"],
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", 1, "tr_person", $tour["f_tr_person"]));
$importFileStatusMsg .= "$impName zu Belegnummer <i>" . $tour["f_tr_person"] . "</i> wurde importiert in Auftrag Nr. <i>" . $jbIdNew . "</i>.<br>\n";
// Insert into import log table
insertStmt("phoenix_log.import", array("imp_id", $tour["f_tr_person"] . $impType, "imp_pos", $fTrSort, "imp_createtime", $currentTime, "jb_id", $jbIdNew));
// print_r(array("imp_id", $tour["f_tr_person"], "imp_pos", $fTrSort, "imp_createtime", $currentTime, "jb_id", $jbIdNew));
endif;
else:
die('Fehler: Ungültiger Importtyp.');
endif;
else :
if ($tour["f_tr_person"] != "Beleg-Nr.")
$importFileStatusMsg .= "$impName zu Belegnummer <i>" . $tour["f_tr_person"] . "</i> wurde <b>nicht</b> importiert, weil bereits vorhanden in Auftrag Nr. <i>" . $logJbId . "</i>.<br>\n";
endif;
}
/**************************************************
* Plan tour
**************************************************/
// if ($doPlan && !$invalidAddress) {
// $planTour = XSplanTour($allCoords);
// for ($i = 0; $i < count($planTour); $i++) {
// updateStmt("tour", "jb_id", $jbIdNew, array("tr_sort", $i + 1), "tr_sort = " . (100 + $planTour[$i]));
// }
// }
TA("COMMIT");
// $importFileStatusMsg .= "Datei wurde erfolgreich importiert.<br>";
// if (!$invalidAddress) {
// } else {
// TA("ROLLBACK");
// deleteStmt("phoenix_log.import", "jb_id = $jbIdNew");
// writeToLogDB("55", $hq_id, $jbIdNew, $usr_id, $tour["f_jb_cr_id"], $tour["f_jb_cr_sid"], $csId, "Import abgebrochen aufgrund fehlerhafter Adresse(n)");
// $importFileStatusMsg .= "<i>Datei wurde aufgrund fehlerhafter Adresse(n) <b>nicht</b> importiert.</i><br>";
// $importFileStatusMsg .= "<i>Datei wurde aufgrund fehlerhafter Adresse(n) <b>nicht</b> importiert.</i><br>";
// }
TA("END");
foreach ($doPlan AS $jb_id_plan => $doit) {
if ($doit == 1):
$txt = "Auftrag $jb_id_plan wird optimiert...";
echo $txt; flush();
writeLog($txt, "import_saturn");
if (XSplanTourJob($jb_id_plan, 1)):
$txt = " ok!<br>\n";
echo $txt; flush();
writeLog($txt, "import_saturn");
else:
$txt = " fehlgeschlagen!<br>\n";
echo $txt; flush();
writeLog($txt, "import_saturn");
endif;
else:
$txt = "Auftrag $jb_id_plan wird nicht optimiert...<br>\n";
echo $txt; flush();
writeLog($txt, "import_saturn");
endif;
}
// Remove import file
$retVal = removeFile($f_importFile, $importPath, $pathSeparator);
// else :
// $importFileStatusMsg .= "Der Import konnte nicht vollzogen werden, da noch mindestens eine andere Importdatei existiert!<br>";
// endif;
writeLog($importFileStatusMsg, "import_saturn");
endif;
// **************************************************
// * Read all of the local filenames to be imported *
// **************************************************
if ($userTypeName == "hq") :
// Get filenames
$fileNames = getFilenamesInFolder($importPath);
$storedImportFiles .= "<table>";
$storedImportFiles .= "<tr><td class=\"f12bp1_red\" colspan=\"2\">Auftragsimport</td></tr>";
$storedImportFiles .= "<tr><td colspan=\"2\"><br><br></td></tr>";
// Define table header
$storedImportFiles .= "<tr><td>Dateiname&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Löschen</td></tr>";
$storedImportFiles .= "<tr><td colspan=\"2\"><br></td></tr>";
// Define table body from array
$fileNamesLen = count($fileNames);
for ($j = 0; $j < $fileNamesLen; $j++) :
$storedImportFiles .= "<tr>";
$storedImportFiles .= "<td><a href=\"javascript:importImportfile('" . $fileNames[$j] . "');\">" . $fileNames[$j] .
"</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedImportFiles .= "<td align=\"center\"><a href=\"javascript:removeImportfile('" . $fileNames[$j] . "');\">"
. "<img src=\"../images/trash.jpg\" border=\"0\" height=\"13\" width=\"8\">"
. "</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedImportFiles .= "</tr>";
endfor;
$storedImportFiles .= "</table>";
endif;
?>
<html>
<head>
<title>AUFTRAGSIMPORT</title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<script type="text/javascript">
<!--
var statusMessage = "<?php echo $statusMessage ?>";
function displayStatusMessage() {
if (statusMessage != "") {
alert(statusMessage);
}
};
function finishPage(f_act_value) {
document.forms[0].f_act.value=f_act_value;
document.forms[0].submit();
};
function removeImportfile(fileName) {
if (confirm('Importdatei ' + fileName + ' entfernen?')) {
document.forms[0].f_importFile.value = fileName;
finishPage('removeImportfile');
};
};
function importImportfile(fileName) {
if (confirm('Importdatei ' + fileName + ' jetzt importieren?')) {
document.forms[0].f_importFile.value = fileName;
finishPage('goImport');
};
};
function finishPageUpload(f_act_value) {
document.forms[1].f_act.value=f_act_value;
document.forms[1].submit();
};
-->
</script>
</head>
<body onLoad="displayStatusMessage();">
<form name="import_form" action="../import/import_saturn.php" method="post">
<input type="hidden" name="f_act" value="">
<input type="hidden" name="f_importFile" value="">
<?php echo $storedImportFiles; ?>
</form>
<br><br>
<form name="upload_file" action="../import/import_saturn.php" enctype="multipart/form-data" method="post">
<!-- <form name="upload_file" action="../import/upload_file.php" enctype="multipart/form-data" method="post"> -->
<input type="hidden" name="f_act" value="">
<p>W&auml;hlen Sie die Auftragsdateidatei von Ihrem Rechner aus:<br>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="f_uploadFile" type="file" size="50" accept="text/*">
<input type="button" value="Upload" onClick="finishPageUpload('uploadFile');">
</p>
<br><br>
<?php echo $importFileStatusMsg; ?>
</form>
</body>
</html>

View File

@@ -0,0 +1,445 @@
<?php
/*=======================================================================
*
* import_tourbo.php
*
* Autor: Marc Vollmann
*
* ToDoS :
* [1] Configuration in php.ini:
* "file_uploads", "upload_max_filesize", "upload_tmp_dir", "post_max_size"
* [2] Change tables "tour" and "tourhistory"
* ALTER TABLE `tour` ADD `tr_cs_freetext` TEXT;
* ALTER TABLE `tourhistory` ADD `tr_cs_freetext` TEXT;
* [3] Create table "import_log"
* CREATE TABLE import (imp_id int(10) NOT NULL default '0',imp_pos smallint(6) NOT NULL default '0', imp_createtime timestamp(14) NOT NULL, jb_id int(10) NOT NULL default '0', UNIQUE KEY imp_id_pos (imp_id,imp_pos)) TYPE=MyISAM;
* [4] Exportcategoryfields have to be inserted
* DELETE FROM `exportcategoryfields` WHERE expc_id = '110'
* => Start Insert-Script
*
=======================================================================*/
include_once ("import.php");
// Execution-Time for script
set_time_limit(30000);
// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "statusMessage", "f_importFile", "f_uploadFile"));
// Select user-type for mode of security check
$userType = getFieldValueFromId("user","usr_id",$usr_id,"usr_type");
$userTypeName = getUserTypeName($userType);
// Get the rights of the employee logged in and check the accessibility
if (!authCheckEmployeeRights($emp_id, "7")) : die ("$PHP_SELF: Access denied!"); endif;
$statusMessage = "";
$importFileStatusMsg = "";
$jbIdNew = "";
$fJbTourname = "";
$fTrSort = "";
// Get number of files in the upload folder
$numOfFiles = getNumOfFilesInFolder($importPath);
// Process uploaded file
if ($f_act == "uploadFile") :
if ($numOfFiles < 1) :
if ($_FILES['f_uploadFile']['size'] <= 2000000) :
if (!move_uploaded_file($_FILES['f_uploadFile']['tmp_name'], $importPath . $_FILES['f_uploadFile']['name'])) :
$statusMessage .= "Die Datei wurde leider nicht hochgeladen!";
endif;
else :
$statusMessage .= "Die Datei ist für den Upload zu groß!";
// Delete real file if does exist
$retVal = removeFile($_FILES['f_uploadFile']['name'], $importPath, $pathSeparator);
endif;
// Delete temp file if does exist
$retVal = removeFile($_FILES['f_uploadFile']['tmp_name'], $tempPath, $pathSeparator);
else :
$statusMessage .= "Bevor eine weitere Datei hochgeladen werden kann, muss das Verzeichnis geleert werden!";
endif;
endif;
// Manually removal of a specified importfile
if ($f_act == "removeImportfile") :
// Remove import file
$retVal = removeFile($f_importFile, $importPath, $pathSeparator);
if ($retVal == "0") :
elseif ($retVal == "-1") :
$statusMessage = "Es liegt kein Dateiname vor!";
elseif ($retVal == "-2") :
$statusMessage = "Die Datei befindet sich nicht mehr in dem Verzeichnis!";
elseif ($retVal == "") :
$statusMessage = "Es fand keine Löschung statt!";
endif;
endif;
// Import process
if ($f_act == "goImport") :
if ($numOfFiles == 1) :
$importFileStatusMsg .= "<br><br><br><br><span class=\"f12bp1_red\" colspan=\"2\">Verarbeitungsprotokoll:</span><br><br>";
$importFileStatusMsg .= "Import-Datei: " . $f_importFile . "<br><br>";
$rowToImport = array();
/*
$rowToImport[0] = "f_position"; // position
$rowToImport[1] = "f_tr_person"; // externalOrderID
$rowToImport[2] = "f_dummy_01"; // dummy
$rowToImport[3] = "f_tr_ware_from_to"; // type
$rowToImport[4] = "f_tr_comp_01"; // name 1
$rowToImport[5] = "f_tr_comp2_01"; // name 2
$rowToImport[6] = "f_ad_street_01"; // pickup/street
$rowToImport[7] = "f_ad_zipcode_01"; // pickup/zipCode
$rowToImport[8] = "f_ad_city_01"; // pickup/city
$rowToImport[9] = "f_tr_remark_1"; // goodsdescription
$rowToImport[10] = "f_tr_commission_no"; // loadingUnitType
$rowToImport[11] = "f_jb_ordertime_01"; // pickup/plannedPickup
$rowToImport[12] = "f_jb_tourname"; // tourID
*/
$rowToImport[0] = "f_cs_eid"; // customer EID
$rowToImport[1] = "f_jb_tourname"; // tourID
$rowToImport[2] = "f_cr_sid"; // courier SID
$rowToImport[3] = "f_jb_ordertime_01"; // pickup time
$rowToImport[4] = "f_position"; // position
$rowToImport[5] = "f_ad_zipcode_01"; // zipcode
$rowToImport[6] = "f_ad_city_01"; // city
$rowToImport[7] = "f_ad_street_01"; // street
$rowToImport[8] = "f_tr_hsno_01"; // house number
$rowToImport[9] = "f_time_arrival"; // extra
$rowToImport[10] = "f_km"; // extra
$rowToImport[11] = "f_ls"; // extra
$rowToImport[12] = "f_tr_remark_1"; // remark
$rowToImport[13] = "f_kg"; // weight
$rowToImportLen = count($rowToImport);
// read file to import
$data = importCSV($importPath . $f_importFile);
$dataLen = count($data);
// loop all rows
for ($j = 0; $j < $dataLen; $j++) {
// loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
// Next job begins
if ($fJbTourname == "" || $fJbTourname != $f_jb_tourname) :
$jbIdNew = "";
$fTrSort = "";
$fJbTourname = $f_jb_tourname;
endif;
// Check import log table in db according to the unique key "tourID + position" (<=> $f_jb_tourname + $f_position)
$logJbId = getFieldValueFromClause("phoenix_log.import","jb_id","imp_id = '" . $f_jb_tourname . "' AND imp_pos = '" . $f_position . "'");
if ($logJbId == "") :
TA("B");
$f_position = trim($f_position);
$f_position++; // Increment because votian starts with "1" instead of "0"
$f_jb_tourname = trim($f_jb_tourname);
$f_jb_ordertime_01 = trim($f_jb_ordertime_01);
$f_ad_street_01 = trim($f_ad_street_01);
$f_tr_hsno_01 = trim($f_tr_hsno_01);
$f_ad_zipcode_01 = trim($f_ad_zipcode_01);
$f_ad_city_01 = trim($f_ad_city_01);
$f_tr_remark_1 = trim($f_tr_remark_1);
$f_cs_eid = trim($f_cs_eid);
$f_cr_sid = trim($f_cr_sid);
$f_time_arrival = trim($f_time_arrival);
$f_km = trim($f_km);
$f_ls = trim($f_ls);
$f_kg = trim($f_kg);
$f_tr_person = trim($f_tr_person);
$f_tr_ware_from_to = trim($f_tr_ware_from_to);
$f_tr_comp_01 = trim($f_tr_comp_01);
$f_tr_comp2_01 = trim($f_tr_comp2_01);
$f_tr_commission_no = trim($f_tr_commission_no);
if ($f_ad_street_01 == "") : $f_ad_street_01 = "."; endif;
if ($f_tr_hsno_01 == "") : $f_tr_hsno_01 = "."; endif;
if ($f_ad_zipcode_01 == "") : $f_ad_zipcode_01 = "."; endif;
if ($f_ad_city_01 == "") : $f_ad_city_01 = "."; endif;
// Constants
// $cscIdCashPayer = getParameterValue("0", "CSC_ID_PAYER_CASH", $f_hq_id);
// Concatenation of external cs_eid and name
$f_cs_id = getFieldValueFromId("customer","cs_eid",$f_cs_eid,"cs_id");
$f_cmp_id = getFieldValueFromId("company","cs_id",$f_cs_id,"cmp_id");
$f_tr_comp_01 = getFieldValueFromId("company","cmp_id",$f_cmp_id,"cmp_comp");
$f_tr_comp2_01 = getFieldValueFromId("company","cmp_id",$f_cmp_id,"cmp_comp2");
// $f_tr_comp_01 = $f_tr_comp_01 . " " . $f_tr_comp2_01;
// $f_tr_comp2_01 = "";
if ($f_tr_ware_from_to == "Rücknahme") :
$f_tr_ware_from_to = "1";
elseif ($f_tr_ware_from_to == "Installation") :
$f_tr_ware_from_to = "2";
else :
$f_tr_ware_from_to = "0";
endif;
// $f_tr_remark = $f_tr_remark_1; // . " " . $f_tr_remark_2 . " " . $f_tr_remark_3 . " " . $f_jb_ordertime_02;
$f_tr_remark = $f_tr_remark_1 . " | Ankunft: " . $f_time_arrival . " | KM: " . $f_km . " | LS: " . $f_ls . " | KG: " . $f_kg;
// Extra field "internal remark of the customer" for customer export
$f_tr_cs_freetext = $f_tr_remark;
// Format date field
$dVal = $f_jb_ordertime_01;
// $f_jb_ordertime_01 = substr($dVal,6,4) . "-" . substr($dVal,3,2) . "-" . substr($dVal,0,2) . " 00:00";
// Split street to street and houseno.
// $f_tr_hsno_01 = ".";
// $f_tr_hsno_02 = ".";
// Get 1. address id
$tmpArray = insertAddress($f_ad_street_01, $f_ad_zipcode_01, $f_ad_city_01, "", "", true);
$ad_id_new_01 = $tmpArray[0];
// Get the current time
$currentTime = getDateTime("0");
// Insert job data
if ($jbIdNew == "") :
$jbStatus = "1";
$jbType = "0"; // "---"
$crSid = $f_cr_sid;
$crId = getFieldValueFromId("couriervehicle","crvh_sid",$crSid,"cr_id");
$jbTaketime = $f_jb_ordertime_01;
$jbFinishtime = "";
$csInvmod = "";
$price = 0;
if (!isset($f_tax_value) || $f_tax_value == ""):
$f_tax_value = getFieldValueFromId("tax","tx_id","4","tx_value");
if ($f_tax_value == ""):
$f_tax_value = "19.00";
endif;
endif;
$txSign = "V";
// Mapping of the headquarters
$tmpZipcode = substr($f_ad_zipcode_01 ,0 ,1); // Get the first character
if (true) :
$f_hq_id = "1"; // SB HB (Default !!!)
$f_cs_eid_payer = $f_cs_eid;
$trCscIdRoot_01 = "141012"; // Hauptkostenstelle Kunde "Extern"
endif;
$csId = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cs_id");
$cscIdRoot = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"csc_id");
// if ($isCashPayerTour): $cscIdRoot = $cscIdCashPayer; endif;
$csInvmode = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cs_invmode");
$cmpPostage = getFieldValueFromId("customer","cs_eid",$f_cs_eid_payer,"cmp_id");
if ($cmpPostage == "") : $cmpPostage = "0.00"; endif;
// Check for absolute customer discount
$csDiscountAbsolute = getFieldValueFromId("customer", "cs_id", $csId, "cs_discount");
$useDicountDisabled = getParameterValue("0", "JB_EDITBATCH_DISCOUNT_DISABLED");
if ($useDicountDisabled == "1") :
$csDiscountAbsolute = 0;
endif;
// Mapping of the vehicle type
$f_vht_id = getFieldValueFromId("couriervehicle","crvh_sid",$crSid,"vht_id");
/*
if ($f_vht_id == "1") :
$f_vht_id = "8"; // 3-To.
elseif ($f_vht_id == "2") :
$f_vht_id = "9"; // 5-To.
elseif ($f_vht_id == "3") :
$f_vht_id = "7"; // 1-To.
else :
$f_vht_id = "8"; // 3-To.
endif;
*/
insertStmt("job", array("hq_id", $f_hq_id, "vht_id", $f_vht_id, "csc_id_payer", $cscIdRoot, "jb_payment", "0",
"jb_ordertime", $f_jb_ordertime_01, "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crId,
"jb_taketime", $jbTaketime, "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType, "jb_tourname", $f_jb_tourname,
"jb_finishtime", $jbFinishtime, "emp_id", $usr_id, "jb_fixprice", $f_price, "jb_totalprice", $f_price,
"jb_postage", $cmpPostage, "jb_invmode", $csInvmode, "jb_freetext_1", "",
"jb_sales_tax_rate", $f_tax_value, "jb_sales_tax_rate_sign", $txSign, "jb_booktime", ""));
$jbIdNew = getLastInsertId();
// Insert tour data for station
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new_01, "tr_sort", "1", "tr_comp", $f_tr_comp_01, "tr_comp2", $f_tr_comp2_01,
"tr_hsno", $f_tr_hsno_01, "csc_id", $trCscIdRoot_01, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", $f_tr_ware_from_to,
"tr_person", $f_tr_person, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
// Insert tourservice data
insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdRoot, "tr_sort", "0",
"srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "",
"trs_price", $price, "trs_discount", $csDiscountAbsolute));
// Write logdata into log database
writeToLogDB("55",$hq_id,$jbIdNew,$usr_id,"","","",$csId);
$importFileStatusMsg .= "Station 1 des Auftrags " . $jbIdNew . " wurde importiert.<br>";
else :
if ($fTrSort == "") :
$fTrSort = "2";
else :
$fTrSort++;
endif;
// Update job data
// updateStmt("job","jb_id",$jbIdNew,array("usr_name",$f_usr_name,"usr_firstname",$f_usr_firstname));
// Insert tour data
insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $ad_id_new_01, "tr_sort", $fTrSort, "tr_comp", $f_tr_comp_01, "tr_comp2", $f_tr_comp2_01,
"tr_hsno", $f_tr_hsno_01, "csc_id", $trCscIdRoot_01, "tr_status", "0",
"tr_commission_no", $f_tr_commission_no, "tr_ware_from_to", $f_tr_ware_from_to,
"tr_person", $f_tr_person, "tr_remark", $f_tr_remark, "tr_cs_freetext", $f_tr_cs_freetext));
$importFileStatusMsg .= "Station " . $fTrSort . " des Auftrags " . $jbIdNew . " wurde importiert.<br>";
endif;
// Insert into import log table
insertStmt("phoenix_log.import", array("imp_id", $f_jb_tourname, "imp_pos", $f_position, "imp_createtime", $currentTime, "jb_id", $jbIdNew));
TA("C");
TA("E");
else :
$importFileStatusMsg .= "Datensatz " . $j . " wurde NICHT importiert, weil sie schon importiert wurde! (Auftrag " . $logJbId . ")<br>";
endif;
}
// Remove import file
$retVal = removeFile($f_importFile, $importPath, $pathSeparator);
else :
$importFileStatusMsg .= "Der Import konnte nicht vollzogen werden, da noch mindestens eine andere Importdatei existiert!<br>";
endif;
endif;
// **************************************************
// * Read all of the local filenames to be imported *
// **************************************************
if ($userTypeName == "hq") :
// Get filenames
$fileNames = getFilenamesInFolder($importPath);
$storedImportFiles .= "<table>";
$storedImportFiles .= "<tr><td class=\"f12bp1_red\" colspan=\"2\">Auftragsimport</td></tr>";
$storedImportFiles .= "<tr><td colspan=\"2\"><br><br></td></tr>";
// Define table header
$storedImportFiles .= "<tr><td>Dateiname&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Löschen</td></tr>";
$storedImportFiles .= "<tr><td colspan=\"2\"><br></td></tr>";
// Define table body from array
$fileNamesLen = count($fileNames);
for ($j = 0; $j < $fileNamesLen; $j++) :
$storedImportFiles .= "<tr>";
$storedImportFiles .= "<td><a href=\"javascript:importImportfile('" . $fileNames[$j] . "');\">" . $fileNames[$j] .
"</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedImportFiles .= "<td align=\"center\"><a href=\"javascript:removeImportfile('" . $fileNames[$j] . "');\">"
. "<img src=\"../images/trash.jpg\" border=\"0\" height=\"13\" width=\"8\">"
. "</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
$storedImportFiles .= "</tr>";
endfor;
$storedImportFiles .= "</table>";
endif;
?>
<html>
<head>
<title>AUFTRAGSIMPORT</title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<script type="text/javascript">
<!--
var statusMessage = "<?php echo $statusMessage ?>";
function displayStatusMessage() {
if (statusMessage != "") {
alert(statusMessage);
}
};
function finishPage(f_act_value) {
document.forms[0].f_act.value=f_act_value;
document.forms[0].submit();
};
function removeImportfile(fileName) {
if (confirm('Importdatei ' + fileName + ' entfernen?')) {
document.forms[0].f_importFile.value = fileName;
finishPage('removeImportfile');
};
};
function importImportfile(fileName) {
if (confirm('Importdatei ' + fileName + ' jetzt importieren?')) {
document.forms[0].f_importFile.value = fileName;
finishPage('goImport');
};
};
function finishPageUpload(f_act_value) {
document.forms[1].f_act.value=f_act_value;
document.forms[1].submit();
};
-->
</script>
</head>
<body onLoad="displayStatusMessage();">
<form name="import_form" action="../import/import_job.php" method="post">
<input type="hidden" name="f_act" value="">
<input type="hidden" name="f_importFile" value="">
<?php echo $storedImportFiles; ?>
</form>
<br><br>
<form name="upload_file" action="../import/import_job.php" enctype="multipart/form-data" method="post">
<!-- <form name="upload_file" action="../import/upload_file.php" enctype="multipart/form-data" method="post"> -->
<input type="hidden" name="f_act" value="">
<p>W&auml;hlen Sie die Auftragsdateidatei von Ihrem Rechner aus:<br>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="f_uploadFile" type="file" size="50" accept="text/*">
<input type="button" value="Upload" onClick="finishPageUpload('uploadFile');">
</p>
<br><br>
<?php echo $importFileStatusMsg; ?>
</form>
</body>
</html>

Binary file not shown.

18
html/import/index.html Normal file
View File

@@ -0,0 +1,18 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="de">
<head>
<title>votian</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="votian"> <meta name="keywords" content="votian">
<meta http-equiv="refresh" content="0; URL=../index.php">
<link rel="stylesheet" type="text/css" href="css/phoenix.css">
</head>
<body bgcolor="#FFFFFA" leftmargin="1" topmargin="1" marginwidth="0" marginheight="0" link="#990000" vlink="#990000" alink="#990000">
<a href="../index.php">Bitte hier klicken, wenn Sie nicht automatisch weitergeleitet werden...</a>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB

378
html/import/xServer.inc.php Normal file
View File

@@ -0,0 +1,378 @@
<?php
include_once("../include/dbglobal.inc.php");
$allCoords = array();
//$coords = XSfindAddress("D", "25469", "Halstenbek", "Friedrichshulder Weg", "81");
//echo $coords[0][1] . ", " . $coords[0][2] . "<br>\n";
//$allCoords[] = array($coords[0][1], $coords[0][2], 8*3600, 14*3600);
//$coords = XSfindAddress("D", "22848", "Norderstedt", "Ochsenzoller Straße", "31");
//echo $coords[0][1] . ", " . $coords[0][2] . "<br>\n";
//$allCoords[] = array($coords[0][1], $coords[0][2], 12.5*3600, 19*3600);
//$coords = XSfindAddress("D", "21502", "Geesthacht", "Gerhart-Hauptmann-Weg", "14");
//echo $coords[0][1] . ", " . $coords[0][2] . "<br>\n";
//$allCoords[] = array($coords[0][1], $coords[0][2], 8*3600, 14*3600);
//$coords = XSfindAddress("D", "25421", "Pinneberg", "Oeltingsallee", "1b");
//echo $coords[0][1] . ", " . $coords[0][2] . "<br>\n";
//$allCoords[] = array($coords[0][1], $coords[0][2], 13*3600, 19*3600);
//$coords = XSfindAddress("D", "22041", "Hamburg", "Holzmühlenstraße", "41");
//echo $coords[0][1] . ", " . $coords[0][2] . "<br>\n";
//$allCoords[] = array($coords[0][1], $coords[0][2], 8*3600, 14*3600);
//$coords = XSfindAddress("D", "22525", "Hamburg", "Ottensener Straße", "8");
//echo $coords[0][1] . ", " . $coords[0][2] . "<br>\n";
//$allCoords[] = array($coords[0][1], $coords[0][2], 13*3600, 19*3600);
//print_r(XSplanTimewindowTour($allCoords));
//XSplanTour(array(
// array(843650, 4901137),
// array(842164, 4901883),
// array(843914, 4900754),
// array(841020, 4900941),
// array(841050, 4900578))
//);
function XSfindAddress($ad_country, $ad_zipcode, $ad_city, $ad_street, $tr_hsno)
{
// $XS_HOST = 'localhost';
$XS_HOST = '172.16.0.154';
$XS_PORT = 50020;
$XS_SERVICE = '/xlocate/ws/XLocate';
$out =
'<?xml version="1.0" encoding="utf-8"?>' . "\n" .
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' . "\n" .
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . "\n" .
' xmlns:xsd="http://www.w3.org/2001/XMLSchema">' . "\n" .
' <soap:Body>' . "\n" .
' <findAddress xmlns="http://types.xlocate.xserver.ptvag.com">' . "\n" .
' <Address_1' . "\n" .
' country="'. $ad_county . '"' . "\n" .
' postCode="'. $ad_zipcode . '"' . "\n" .
' city="'. utf8_encode($ad_city) . '"' . "\n" .
' city2=""' . "\n" .
' street="'. utf8_encode($ad_street) . '"' . "\n" .
' houseNumber="'. $tr_hsno . '"' . "\n" .
' />' . "\n" .
' <ArrayOfSearchOptionBase_2 xsi:nil="true" />' . "\n" .
' <ArrayOfSortOption_3 xsi:nil="true" />' . "\n" .
' <ArrayOfResultField_4 xsi:nil="true" />' . "\n" .
' <CallerContext_5 log1="" log2="" log3="">' . "\n" .
' <wrappedProperties xmlns="http://baseservices.service.jabba.ptvag.com">' . "\n" .
' <CallerContextProperty key="CoordFormat" value="PTV_GEODECIMAL" />' . "\n" .
' <CallerContextProperty key="Profile" value="default" />' . "\n" .
' </wrappedProperties>' . "\n" .
' </CallerContext_5>' . "\n" .
' </findAddress>' . "\n" .
' </soap:Body>' . "\n" .
'</soap:Envelope>' . "\n" .
"\n";
$res = xmlRequest($XS_HOST, $XS_PORT, $XS_SERVICE, $out);
$vals = $res[0];
$index = $res[1];
$log_txt = "********************************************************************************\n" . $out;
$retA = array();
if (array_key_exists('SOAP:FAULT', $index)) {
echo $vals[$index['FAULTCODE'][0]]['value'] . " : " . $vals[$index['FAULTSTRING'][0]]['value'] . "\n";
writeLog($log_txt, "xServer.inc");
die();
} else {
$log_txt .= "ERRORCODE=" . $vals[$index['RESULT'][0]]['attributes']['ERRORCODE'] . "\n";
$i = 0;
for ($i = 0, $j = 0; $i < count($index['NS6:POINT']); $i++, $j += 2) {
$log_txt .= "\n";
foreach ($vals[$index['NS2:RESULTADDRESS'][$j]]['attributes'] AS $attr => $val) {
$log_txt .= "$attr: " . $val . "\n";
}
$log_txt .= "Y, X = " . $vals[$index['NS6:POINT'][$i]]['attributes']['Y'] . ", " . $vals[$index['NS6:POINT'][$i]]['attributes']['X'] . "\n";
$retA[] = array($vals[$index['NS2:RESULTADDRESS'][$j]]['attributes']['TOTALSCORE'], $vals[$index['NS6:POINT'][$i]]['attributes']['X'], $vals[$index['NS6:POINT'][$i]]['attributes']['Y']);
}
// echo "Index array\n";
// print_r($index);
// echo "\nVals array\n";
// print_r($vals);
}
writeLog($log_txt, "xServer.inc");
return $retA;
}
function XSplanTimewindowTour($stopCoordinates, $predPos = 0, $succPos = 0)
{
// $XS_HOST = 'localhost';
$XS_HOST = '172.16.0.154';
$XS_PORT = 50050;
$XS_SERVICE = '/xsequence/ws/XSequence';
// if $predPos == 0
if ($succPos == 0)
$succPos = count($stopCoordinates) + 1;
$outStops = '';
$subStops = '';
foreach ($stopCoordinates as $idx => $pairs) {
$outStops .=
' <ns2:TimewindowStop stopID="' . ($idx + 1) . '" xsi:type="ns2:TimewindowStop">' . "\n" .
// ' <ns2:TimewindowStop servicePeriod="900" stopID="' . ($idx + 1) . '" xsi:type="ns2:TimewindowStop">' . "\n" .
' <ns2:loc x="' . round($pairs[0]) . '" y="' . round($pairs[1]) . '"/>' . "\n" .
' <ns2:wrappedOpeningIntervals>' . "\n" .
' <ns2:Interval from="' . $pairs[2] . '" till="' . $pairs[3] . '"/>' . "\n" .
' </ns2:wrappedOpeningIntervals>' . "\n" .
' </ns2:TimewindowStop>' . "\n";
$subStops .= ' <ns2:InputTourPoint stopID="' . ($idx + 1) . '"/>' . "\n";
}
// $planningParams->costDistanceKm = 10;
// $planningParams->costPeriodMinute = 50;
// $planningParams->maxProcessorPeriod = 5;
// $planningParams->distanceCalculation->dimaCoordFormat = 'GEODECIMAL';
$out =
'<?xml version="1.0" encoding="utf-8"?>' . "\n" .
'<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"' .
' xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"' .
' xmlns:ns0="http://exception.core.jabba.ptvag.com"' .
' xmlns:ns1="http://common.xserver.ptvag.com"' .
' xmlns:ns2="http://xsequence.xserver.ptvag.com"' .
' xmlns:ns3="http://types.xsequence.xserver.ptvag.com"' .
' xmlns:xsd="http://www.w3.org/2001/XMLSchema"' .
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' . "\n" .
' <env:Body>' . "\n" .
' <ns3:planTimewindowTour>' . "\n" .
' <ns3:ArrayOfTimewindowStop_1>' . "\n" .
$outStops .
' </ns3:ArrayOfTimewindowStop_1>' . "\n" .
' <ns3:TimewindowPlanningParams_2 xsi:type="ns2:TimewindowPlanningParams">' . "\n" .
' <ns2:distanceCalculation dimaCoordFormat="GEODECIMAL" drivingPeriodFactor="1.0"/>' . "\n" .
' <ns2:wrappedOperatingIntervals>' . "\n" .
' <ns2:Interval from="25200" till="72000"/>' . "\n" .
' </ns2:wrappedOperatingIntervals>' . "\n" .
' </ns3:TimewindowPlanningParams_2>' . "\n" .
' <ns3:InputTour_3 xsi:type="ns2:InputTour">' . "\n" .
' <ns2:wrappedInputTourPoints>' . "\n" .
$subStops .
' </ns2:wrappedInputTourPoints>' . "\n" .
' <ns2:subSequence predPos="' . $predPos . '" succPos="' . $succPos . '"/>' . "\n" .
' </ns3:InputTour_3>' . "\n" .
' <ns3:CallerContext_4 xsi:nil="1"/>' . "\n" .
' </ns3:planTimewindowTour>' . "\n" .
' </env:Body>' . "\n" .
'</env:Envelope>' . "\n" .
"\n";
//echo $out;
$res = xmlRequest($XS_HOST, $XS_PORT, $XS_SERVICE, $out);
$vals = $res[0];
$index = $res[1];
$log_txt = "********************************************************************************\n" . $out;
$retA = array();
if (array_key_exists('SOAP:FAULT', $index)) {
$log_txt .= $vals[$index['FAULTCODE'][0]]['value'] . " : " . $vals[$index['FAULTSTRING'][0]]['value'] . "\n";
// die();
} else {
$log_txt .= "RESULT=" . $vals[$index['NS2:RESULT'][0]]['attributes']['RESULT'] . "\n\n";
foreach ($vals[$index['NS17:TOUR'][0]]['attributes'] AS $attr => $val) {
$log_txt .= "$attr: $val\n";
}
for ($i = 0; $i < count($index['NS17:OUTPUTTOURPOINT']); $i += 2) {
$otp = $index['NS17:OUTPUTTOURPOINT'][$i];
$log_txt .= "\n";
$retA[] = $vals[$otp]['attributes']['STOPID'];
foreach ($vals[$otp]['attributes'] AS $attr => $val) {
$log_txt .= "$attr: $val\n";
}
}
// echo "Index array\n";
// print_r($index);
// echo "\nVals array\n";
// print_r($vals);
}
writeLog($log_txt, "xServer.inc");
return $retA;
}
function XSplanTourJob($jb_id_plan, $predPos = 0, $succPos = 0)
{
global $db;
$stopCoordinates = array();
$sqlquery = "SELECT tr_cs_freetext, tr_commission_no FROM tour WHERE jb_id = $jb_id_plan ORDER BY tr_sort";
$res = $db->query($sqlquery);
if (DB::isError($res)) reportDie ("$PHP_SELF: '$sqlquery'" . $res->getMessage());
$i = 0;
while ($row = $res->fetch_assoc()):
$interval = array();
if ($row["tr_commission_no"] == "07 - 09 Uhr")
$interval = array(7*3600, 9*3600);
if ($row["tr_commission_no"] == "08 - 19 Uhr")
$interval = array(8*3600, 19*3600);
if ($row["tr_commission_no"] == "08 - 14 Uhr")
$interval = array(8*3600, 14*3600);
if ($row["tr_commission_no"] == "13 - 19 Uhr")
$interval = array(13*3600, 19*3600);
if ($row["tr_commission_no"] == "16 - 20 Uhr")
$interval = array(16*3600, 20*3600);
$coords = explode(",", $row["tr_cs_freetext"]);
$stopCoordinates[$i++] = array($coords[0], $coords[1], $interval[0], $interval[1]);
endwhile;
$res->free();
$stopIt = false;
do {
$planTour = XSplanTimewindowTour($stopCoordinates, $predPos, $succPos);
if (count($planTour) == 0):
for ($i = 1; $i < count($stopCoordinates); $i++):
$stopCoordinates[$i][2] -= 300;
$stopCoordinates[$i][3] += 300;
if ($stopCoordinates[$i][2] < 0 OR $stopCoordinates[$i][3] > 86400):
$stopIt = true;
break;
endif;
endfor;
endif;
} while (count($planTour) == 0 && !$stopIt);
if (count($planTour) > 0):
// bestehenden tr_sort mit 100 addieren
for ($i = 0; $i < count($planTour); $i++) {
updateStmt("tour", "jb_id", $jb_id_plan, array("tr_sort", 100 + $i + 1), "tr_sort = " . ($i+1));
}
// jetzt können die neuen tr_sort geschrieben werden
for ($i = 0; $i < count($planTour); $i++) {
updateStmt("tour", "jb_id", $jb_id_plan, array("tr_sort", $i + 1), "tr_sort = " . (100 + $planTour[$i]));
}
return true;
endif;
return false;
}
function xmlRequest($host, $port, $service, $xmlReq)
{
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
fputs ($fp, "POST $service HTTP/1.1\r\n");
fputs ($fp, "Host: localhost\r\n");
fputs ($fp, "Content-type: text/xml; charset=utf-8\r\n");
fputs ($fp, "Content-length: " . strlen($xmlReq) . "\r\n");
fputs ($fp, "Connection: close\r\n\r\n");
fputs ($fp, $xmlReq);
$line = "";
while (substr($line, 0, 14) != "<soap:Envelope" && !feof($fp)) {
$line = fgets($fp, 128);
}
$in = $line;
while (!feof($fp)) {
$in .= fgets($fp, 128);
}
fclose($fp);
//echo $in;
$p = xml_parser_create();
xml_parse_into_struct($p, $in, $vals, $index);
xml_parser_free($p);
return (array($vals, $index));
}
}
function writeLog($log_text, $log_file) {
$today = getdate();
$fileHandle = @fopen("../log/" . $log_file . "_" . $today['year'] . sprintf("%02d", $today['mon']) . ".log", 'a');
@fwrite($fileHandle, "[" . date("Y-m-d H:i:s") . "] " . $log_text . "\n");
@fclose($fileHandle);
return;
}
/*******************************************************************************
Working:
<?xml version="1.0" encoding="utf-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://exception.core.jabba.ptvag.com" xmlns:ns1="http://common.xserver.ptvag.com" xmlns:ns2="http://xsequence.xserver.ptvag.com" xmlns:ns3="http://types.xsequence.xserver.ptvag.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<ns3:planTimewindowTour>
<ns3:ArrayOfTimewindowStop_1>
<ns2:TimewindowStop servicePeriod="1800" stopID="1" xsi:type="ns2:TimewindowStop">
<ns2:loc x="983547" y="5362310"/>
<ns2:wrappedOpeningIntervals>
<ns2:Interval from="28800" till="50400"/>
</ns2:wrappedOpeningIntervals>
</ns2:TimewindowStop>
<ns2:TimewindowStop servicePeriod="1800" stopID="2" xsi:type="ns2:TimewindowStop">
<ns2:loc x="997272" y="5367644"/>
<ns2:wrappedOpeningIntervals>
<ns2:Interval from="46061" till="68400"/>
</ns2:wrappedOpeningIntervals>
</ns2:TimewindowStop>
<ns2:TimewindowStop servicePeriod="1800" stopID="3" xsi:type="ns2:TimewindowStop">
<ns2:loc x="1043632" y="5341378"/>
<ns2:wrappedOpeningIntervals>
<ns2:Interval from="28800" till="50400"/>
</ns2:wrappedOpeningIntervals>
</ns2:TimewindowStop>
</ns3:ArrayOfTimewindowStop_1>
<ns3:TimewindowPlanningParams_2 xsi:type="ns2:TimewindowPlanningParams">
<ns2:distanceCalculation dimaCoordFormat="GEODECIMAL" drivingPeriodFactor="1.0"/>
</ns3:TimewindowPlanningParams_2>
<ns3:InputTour_3 xsi:type="ns2:InputTour">
<ns2:wrappedInputTourPoints>
<ns2:InputTourPoint stopID="1"/>
<ns2:InputTourPoint stopID="2"/>
<ns2:InputTourPoint stopID="3"/>
</ns2:wrappedInputTourPoints>
<ns2:subSequence predPos="0" succPos="4"/>
</ns3:InputTour_3>
<ns3:CallerContext_4 xsi:nil="1"/>
</ns3:planTimewindowTour>
</env:Body>
</env:Envelope>
Not working:
<?xml version="1.0" encoding="utf-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://exception.core.jabba.ptvag.com" xmlns:ns1="http://common.xserver.ptvag.com" xmlns:ns2="http://xsequence.xserver.ptvag.com" xmlns:ns3="http://types.xsequence.xserver.ptvag.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<ns3:planTimewindowTour>
<ns3:ArrayOfTimewindowStop_1>
<ns2:TimewindowStop servicePeriod="1800" stopID="1" xsi:type="ns2:TimewindowStop">
<ns2:loc x="983547" y="5362310"/>
<ns2:wrappedOpeningIntervals>
<ns2:Interval from="28800" till="50400"/>
</ns2:wrappedOpeningIntervals>
</ns2:TimewindowStop>
<ns2:TimewindowStop servicePeriod="1800" stopID="2" xsi:type="ns2:TimewindowStop">
<ns2:loc x="997272" y="5367644"/>
<ns2:wrappedOpeningIntervals>
<ns2:Interval from="46062" till="68400"/>
</ns2:wrappedOpeningIntervals>
</ns2:TimewindowStop>
<ns2:TimewindowStop servicePeriod="1800" stopID="3" xsi:type="ns2:TimewindowStop">
<ns2:loc x="1043632" y="5341378"/>
<ns2:wrappedOpeningIntervals>
<ns2:Interval from="28800" till="50400"/>
</ns2:wrappedOpeningIntervals>
</ns2:TimewindowStop>
</ns3:ArrayOfTimewindowStop_1>
<ns3:TimewindowPlanningParams_2 xsi:type="ns2:TimewindowPlanningParams">
<ns2:distanceCalculation dimaCoordFormat="GEODECIMAL" drivingPeriodFactor="1.0"/>
</ns3:TimewindowPlanningParams_2>
<ns3:InputTour_3 xsi:type="ns2:InputTour">
<ns2:wrappedInputTourPoints>
<ns2:InputTourPoint stopID="1"/>
<ns2:InputTourPoint stopID="2"/>
<ns2:InputTourPoint stopID="3"/>
</ns2:wrappedInputTourPoints>
<ns2:subSequence predPos="0" succPos="4"/>
</ns3:InputTour_3>
<ns3:CallerContext_4 xsi:nil="1"/>
</ns3:planTimewindowTour>
</env:Body>
</env:Envelope>
*******************************************************************************/
?>