0) :
$historicJobParameterState = $jbHistoryDataArray[0];
$jobentry = $jbHistoryDataArray[1];
$tourentry = $jbHistoryDataArray[2];
$jobcosts = $jbHistoryDataArray[3];
$courierentry = $jbHistoryDataArray[4];
$employeeentry = $jbHistoryDataArray[5];
$takeRealJobData = false;
$historicJobParameterState = str_replace("|", "-,-", $historicJobParameterState);
$historicJobParameterArray = spliti("-,-", $historicJobParameterState);
$historicJobParameterArrayLen = count($historicJobParameterArray);
for ($l = 0; $l < $historicJobParameterArrayLen; $l++) :
$singleJobParameterArray = spliti("=", $historicJobParameterArray[$l]);
${$singleJobParameterArray[0]} = trim($singleJobParameterArray[1]);
endfor;
endif;
endif;
endif;
endif;
if ($takeRealJobData) :
// --- JOB -------------------
// Initialize
if ($f_act == "mailsend" || $f_act == "printjob") :
// $titles = "Nr.,Fahrzeug,Auftragszeit,Annahme,Erledigung";
$titles = getLngt("Nr.") . "," . getLngt("Fahrzeug") . "," . getLngt("Auftragszeit") . "," . getLngt("Annahme") . "," . getLngt("Erledigung");
$fields = "jb_id,vht_value,jb_ordertime,jb_taketime,jb_finishtime";
else :
$titles = getLngt("Nr.") . "," . getLngt("Tourenname") . "," . getLngt("Kostenstelle") . "," . getLngt("Fahrzeug angefordert ") . "," . getLngt("Fahrzeug gefahren") . "," . getLngt("Auslage") . "," . getLngt("Gewicht") . "," . getLngt("Auftragszeit") . "," . getLngt("Reservierung") . "," . getLngt("Dauerauftrag") . "," . getLngt("Anforderung") . "," . getLngt("Permanente Anford.") . "," . getLngt("Storno") . "," . getLngt("Spät. Annahmezeit") . "," . getLngt("Annahme") . "," . getLngt("Erledigung") . "," . getLngt("Filter") . "," . getLngt("Opt. Filter") . "," . getLngt("L x B x H") . "," . getLngt("Dispo-Info");
$fields = "jb_id,jb_tourname,csc_name,vht_value,vht_value_real,jb_outlay,jb_weight,jb_ordertime,jb_reserv,jb_permanent,cr_sid,cr_id_permanent,jb_storno,jb_latesttaketime,jb_taketime,jb_finishtime,jb_cr_filter,jb_cr_filter_opt,jb_crvh_measures,jb_dispoinfo";
endif;
$titlesArray = spliti(",",$titles);
$titlesLength = count($titlesArray);
$fieldsArray = spliti(",",$fields);
$fieldsLength = count($fieldsArray);
// Get csc_id of the current job (job entered by customer [csc_id > 0] or headquarter [csc_id = 0])
$job_csc_id = getFieldValueFromId($dbh_jb, "jb_id", "$job_id", "csc_id");
if ($job_csc_id == "") : $job_csc_id = "0"; endif;
$fieldClause = getDBFields("job") . "," . getDBFields("vehicletype") . "," . getDBFields("vehicletype_real") . "," . getDBFields("jobstatus") . "," . getDBFields("jb_latesttaketime");
$fieldClause .= ", CONCAT(jb.jb_crvh_length,' x ',jb.jb_crvh_width,' x ',jb.jb_crvh_height) AS jb_crvh_measures";
$fieldClause .= ", srvpt.srvpt_traveltime ";
// Check for existing costcenter
if ($job_csc_id != "0") : $fieldClause .= "," . getDBFields("costcenter"); endif;
// $fromClause = $dbh_jb . " AS jb, metatype AS vht, metatype AS jbs ";
$fromClause = "metatype AS vht, metatype AS jbs ";
if ($job_csc_id != "0") : $fromClause .= ", costcenter AS csc "; endif;
$fromClause .= ", " . $dbh_jb . " AS jb ";
// Additional joins e.g. for traveltime to startaddress
$fromClause .= " LEFT JOIN " . $dbh_tr . " AS tr ON jb.jb_id = tr.jb_id AND tr.tr_sort = '1' ";
$fromClause .= " LEFT JOIN address AS ad ON tr.ad_id = ad.ad_id ";
$fromClause .= " LEFT JOIN serviceplz AS srvp ON ad.ad_zipcode = srvp.srvp_plz ";
$fromClause .= " LEFT JOIN serviceplztraveltime AS srvpt ON srvp.srvp_id = srvpt.srvp_id AND srvpt.hq_id = jb.hq_id ";
$fromClause .= " LEFT JOIN metatype AS vht_real ON jb.vht_id_real = vht_real.mt_sort AND vht_real.mt_type = 'vehicletype' ";
// $whereClause = "jb.hq_id = " . $currentHqId . " AND ";
$whereClause = "jb.jb_id = " . $job_id . " AND ";
if ($job_csc_id != "0") : $whereClause .= "(jb.csc_id = csc.csc_id) AND "; endif;
$whereClause .= "(jb.vht_id = vht.mt_sort AND vht.mt_type = 'vehicletype') AND ";
$whereClause .= "(jb.jb_status = jbs.mt_sort AND jbs.mt_type = 'job_status') ";
// Changes only because of jb_status='9' within the SAME list as jb_status='0'! Look in "jb_list.php"
// $whereClause .= "((jb.jb_status = jbs.mt_sort OR jb.jb_status-9 = jbs.mt_sort) AND jbs.mt_type = 'job_status') ";
$orderByClause = "";
$sqlqueryJob = generateStatement($fieldClause,$fromClause,$whereClause,$orderByClause);
// echo $sqlqueryJob; die();
// Send request to database
$result = $db->query($sqlqueryJob);
if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage() . ": " . $sqlqueryJob);
// Job-data
$jobentry = "";
$jobCourierId = "";
$job_usr_id = "";
$job_status = "";
$job_cr_sid = "";
$job_longhaul = "";
while ($row = $result->fetch_assoc()):
for ($i = 0; $i < $fieldsLength; $i++) :
$showCol = TRUE;
if ($i % 2 == 0) : $cellColor = "#BBBBFF"; $cellColor2 = "#DDDDDD"; endif;
if ($i % 2 == 1) : $cellColor = "#CCCCFF"; $cellColor2 = "#EEEEEE"; endif;
if (trim($titlesArray[$i]) == "") : $titlesArray[$i] = " "; endif;
$jobentry .= "
";
$jobentry .= "
" . $titlesArray[$i] . "
";
$tmpVarName = $fieldsArray[$i];
${$tmpVarName} = $row[$tmpVarName];
// Some parameters (e.g. for mail, booking, changing tourname, etc.)
$job_status = $row["jb_status"];
$job_tourname = $row["jb_tourname"];
$job_export_time = $row["jb_export_time"];
$job_reserv = $row["jb_reserv"];
$job_incomplete = $row["jb_incomplete"];
$job_cr_sid = $row["cr_sid"];
$job_longhaul = $row["jb_longhaul"];
$job_id_parent = $row["jb_id_parent"];
$job_subtotalprice = $row["jb_subtotalprice"];
$job_markup = $row["jb_markup"];
$job_ordertime = $row["jb_ordertime"];
// Get the current courier-ID of the job
// if ($tmpVarName == "cr_id") : $jobCourierId = $row[cr_id]; endif;
$jobCourierId = $row["cr_id"];
// Get the payer of the job
$cscIdPayer = getFieldValueFromId($dbh_jb, "jb_id", $job_id, "csc_id_payer");
$csIdPayer = getFieldValueFromId("costcenter", "csc_id", $cscIdPayer, "cs_id");
// If automailer is running check job for having subjobs to change
// courier data to courier data of the subjob to get the real driver
if ($automailer == "1" || $f_act == "mailsend") :
if ($job_id_parent == "-1") :
// $tmpJobIdParent = getFieldValueFromId($dbh_jb,"jb_id_parent",$job_id,"jb_id");
$tmpJobIdParent = getFieldValueFromClause($dbh_jb,"jb_id"," jb_id_parent = '" . $job_id . "' ORDER BY jb_id DESC ");
$jobCourierId = getFieldValueFromId($dbh_jb,"jb_id",$tmpJobIdParent,"cr_id");
$job_cr_sid = getFieldValueFromId($dbh_jb,"jb_id",$tmpJobIdParent,"cr_sid");
endif;
endif;
// Get the current employee (user-id !!!) of the job
// HAS TO BE IN THE field-list TO GET HERE !!!!!!!!!!
// if ($tmpVarName == "emp_id") : $job_usr_id = $row["emp_id"]; endif;
// Special job-data
if ($tmpVarName == "jb_latesttaketime") :
if ($row["jb_waittime"] != "") :
${$tmpVarName} = $row["jb_waittime"];
else :
$tmp = ${$tmpVarName};
if ($row["jb_reserv"] == 1) :
// mktime(hour,minute,second,month,day,year)
$latestTakeTime = LATEST_TAKETIME_IN_MINUTES;
if (is_numeric($row["srvpt_traveltime"]) && $row["srvpt_traveltime"] > 0) :
$latestTakeTime = $row["srvpt_traveltime"];
endif;
${$tmpVarName} = date("Y-m-d H:i:s", mktime(substr($tmp,11,2),substr($tmp,14,2)-($latestTakeTime),substr($tmp,17,2),substr($tmp,5,2),substr($tmp,8,2),substr($tmp,2,2)));
else :
${$tmpVarName} = date("Y-m-d H:i:s", mktime(substr($tmp,11,2),substr($tmp,14,2)+5,substr($tmp,17,2),substr($tmp,5,2),substr($tmp,8,2),substr($tmp,2,2)));
endif;
endif;
if ((date("Y-m-d H:i:s") > ${$tmpVarName}) && ($row["jb_status"] == 0)) :
if ($i % 2 == 0) : $cellColor = "#FF2222"; $cellColor2 = "#FF4444"; endif;
if ($i % 2 == 1) : $cellColor = "#FF3333"; $cellColor2 = "#FF5555"; endif;
endif;
endif;
if ($showCol) :
$out = formatOutput(${$tmpVarName},$outputFormatField[$tmpVarName]);
if ($tmpVarName == "jb_storno") :
if (${$tmpVarName} != "0" && ${$tmpVarName} != "") :
if ($rowCounter % 2 == 0 && $i % 2 == 0) : $cellColor = "#FF2222"; endif;
if ($rowCounter % 2 == 0 && $i % 2 == 1) : $cellColor = "#FF3333"; endif;
if ($rowCounter % 2 == 1 && $i % 2 == 0) : $cellColor = "#FF4444"; endif;
if ($rowCounter % 2 == 1 && $i % 2 == 1) : $cellColor = "#FF5555"; endif;
if (${$tmpVarName} == "1") :
$out = getLngt("St.m.K.");
elseif (${$tmpVarName} == "2") :
$out = getLngt("St.o.K.");
endif;
endif;
endif;
if ($tmpVarName == "csc_name" && $job_csc_id == "0") :
$out = getLngt("Zentrale");
endif;
$jobentry .= "
" . $out . "
";
endif;
$jobentry .= "
";
endfor;
// Link to copy the job and link to history
if ($f_act != "mailsend" && $f_act != "printjob") :
// Get some informations for the following links
$tmpCmpIdPayer = getFieldValueFromId("customer", "cs_id", $csIdPayer, "cmp_id");
$tmpCmpPayerFields = getFieldsValueFromId("company", "cmp_id", $tmpCmpIdPayer, array("cmp_authenticated","cmp_visible"));
$jobentry .= "
" . getLngt("Ihr Transportauftrag befindet sich in der Vermittlung.") . "
";
else :
$mailtext .= "
" . getLngt("Ihr Transportauftrag wurde ausgeführt.") . "
";
endif;
$mailtext .= "
" . getLngt("Anbei übersenden wir Ihnen die Auftragsdaten.") . "
";
// Special usage for requesting state of the customer service
if ($job_status == "2") :
$mailSuccessRequest = getParameterValue("0", "MAIL_SUCCESS_REQUEST", $currentHqId);
if ($mailSuccessRequest != "") :
// Only if a mail success request does exist in the database (line above) then check if it is enabled for the payer of the job
$csJbstatusmailEmp = getFieldValueFromId("customer","cs_id",$csIdPayer,"cs_jbstatusmail_emp");
if ($csJbstatusmailEmp == "1") :
// Get the user data of the current employee of the job
$job_usr_id = getFieldValueFromId($dbh_jb,"jb_id",$job_id,"emp_id");
if ($job_usr_id != "") :
$tmpFields = getFieldsValueFromId("user", "usr_id", $job_usr_id, array("usr_firstname","usr_name","usr_phone","usr_email"));
if ($tmpFields[0] != "" && $tmpFields[1] != "" && $tmpFields[2] != "" && $tmpFields[3] != "") :
$mailtext .= "
";
endif;
endif;
// --- BOOK JOB (Finalize) ---------------
// --- CHANGE COURIER (If job is finished and not exported) ---------------
if ($automailer == "0" && $job_id != "") :
$bookjob = "";
$bookjobStatus = " ";
if ($f_act == "bookjob") :
if ($f_crvh_sid_book != "") :
// Get cr_id from SID
$cr_id_book = getFieldValueFromId("couriervehicle", "crvh_sid", $f_crvh_sid_book, "cr_id");
// Get real vht_id to store in job in contrast to requested vht_id
$vht_id_book = getFieldValueFromId("couriervehicle", "crvh_sid", $f_crvh_sid_book, "vht_id");
// Set the current timestamp to store the data
$currentTime = getDateTime("0");
if ($cr_id_book != "") :
$bookJobTime = $currentTime;
$cr_hq_id_book = getFieldValueFromId("courier", "cr_id", $cr_id_book, "hq_id");
// Get ordertime of the job if requested to store the value into jb_finishtime
if ($f_jb_finishtime4booking == "1") :
$bookJobTime = getFieldValueFromId($dbh_jb, "jb_id", $job_id, "jb_ordertime");
if ($bookJobTime == "") : $bookJobTime = $currentTime; endif;
endif;
if ($job_id_parent == "" || $job_id_parent == "0") : // Only jobs not having sub-jobs
if ($job_status != "2") :
// Update and finalize job
updateStmt($dbh_jb, "jb_id", $job_id, array("cr_id", $cr_id_book, "hq_id_exec", $cr_hq_id_book, "jb_status", "2", "cr_sid", $f_crvh_sid_book, "vht_id_real", $vht_id_book, "jb_finishtime", $bookJobTime, "jb_booktime", $currentTime), "(hq_id = '" . $currentHqId . "')");
$bookjobStatus = getLngt("Der Auftrag wurde abgeschlossen!");
// Update available time according to finishing by PDA
if ($jobCourierId == $cr_id_book && substr($job_ordertime, 0, 10) == substr($currentTime, 0, 10)) :
updateStmt("courier", "cr_id", $cr_id_book, array("cr_availabletime", $currentTime), "(hq_id = '" . $currentHqId . "')");
$bookjobStatus .= " " . getLngt("Der Transporteur verlor seine Rankingposition!");
endif;
// Write logdata into log database
writeToLogDB("5",$currentHqId,$job_id,$currentSessionUsrId,$cr_id_book,$f_crvh_sid_book,"","");
else :
if ($job_export_time == "" || $job_export_time == "0000-00-00 00:00:00") :
// Activate this ONLY for changing the vehicle of the current courier of the job to avoid booking of other couriers!
// if ($jobCourierId == $cr_id_book) :
// Update finalized (not exported) job only with vehicle number
// updateStmt($dbh_jb, "jb_id", $job_id, array("cr_sid", $f_crvh_sid_book), "(hq_id = '" . $currentHqId . "')");
updateStmt($dbh_jb, "jb_id", $job_id, array("cr_id", $cr_id_book, "cr_sid", $f_crvh_sid_book, "vht_id_real", $vht_id_book), "(hq_id = '" . $currentHqId . "')");
$bookjobStatus = getLngt("Die Fahrzeugnummer wurde geändert!");
// Write logdata into log database
writeToLogDB("21",$currentHqId,$job_id,$currentSessionUsrId,$cr_id_book,$f_crvh_sid_book,"","");
// else :
// $bookjobStatus = getLngt("Achtung! Das eingegebene Fahrzeug stammt nicht von dem Transporteur der Tour!");
// endif;
else:
$bookjobStatus = getLngt("Der Auftrag wurde schon exportiert! Eine Änderung ist daher nicht möglich!");
endif;
endif;
else:
$bookjobStatus = getLngt("Der Auftrag hat Unteraufträge! Eine Änderung ist daher nicht möglich!");
endif;
else :
$bookjobStatus = getLngt("Die gewählte Fahrzeugnummer konnte keinem Kurier zugeordnet werden!");
endif;
else:
$bookjobStatus = getLngt("Der Auftrag konnte nicht verbucht werden! Geben Sie bitte einen Transporteur an!");
endif;
endif;
// ONLY show if job is not exported
if ($automailer == "0" && ($job_export_time == "" || $job_export_time == "0000-00-00 00:00:00") && $takeRealJobData) :
$bookjobButtonText = getLngt("Auftrag abschließen");
if ($job_status == "2") : $bookjobButtonText = getLngt("Fahrzeug ändern"); endif;
$bookjob .= "