/*=======================================================================
*
* lib_courier.js
*
* Autor: Carsten Annacker
*
=======================================================================*/
/**
* Funktionen für die Kurierliste der Auftragserfassung und -disposition
*
*/
/*
* getCr_id
* params: i
* return: cr_id
* global: cr_id_order_list (muss von PHP definiert werden)
*
* Aus der Liste cr_id_order_list wird die Kuriernummer von Eintrag Nummer i
* zurückgegeben.
* Wenn Liste mit PLZ und Zeit, dann muss Kuriernummer aus Liste extrahiert werden
*/
/*
function getPLZ(cr_id_order_list, i)
{
return cr_id_order_list[i].substring(0, cr_id_order_list[i].indexOf(", "));
}
*/
function getPLZ(cr_id_order_list_i_)
{
return cr_id_order_list_i_.substring(0, cr_id_order_list_i_.indexOf(", "));
}
function getCr_id(cr_id_order_list, i)
{
var start = cr_id_order_list[i].indexOf(" ") + " ".length;
var cr_id = cr_id_order_list[i].substring(start, cr_id_order_list[i].indexOf(", "));
if (cr_id.indexOf("span") > -1)
{
var start = cr_id.indexOf("\">") + "\">".length;
cr_id = cr_id.substring(start, cr_id.indexOf(""));
}
return cr_id;
// if (cr_id_order_list.length >= i - 1)
// {
// if (cr_id_order_list[i].indexOf("*, ") > -1 && cr_id_order_list[i].indexOf(")") > -1)
// {
// return cr_id_order_list[i].substr(0, cr_id_order_list[i].indexOf("*, "));
// } else {
// if (cr_id_order_list[i].indexOf(", ") > -1 && cr_id_order_list[i].indexOf(")") > -1)
// {
// return cr_id_order_list[i].substr(0, cr_id_order_list[i].indexOf(", "));
// } else {
// return cr_id_order_list[i];
// }
// }
// } else {
// return "";
// }
}
function getCr_id2(cr_id_order_list_i_)
{
var start = cr_id_order_list_i_.indexOf(" ") + " ".length;
var cr_id = cr_id_order_list_i_.substring(start, cr_id_order_list_i_.indexOf(", "));
if (jb_longhaul == "1")
cr_id = cr_id_order_list_i_.substring(start, cr_id_order_list_i_.indexOf(" "));
if (cr_id.indexOf("span") > -1)
{
var start = cr_id.indexOf("\">") + "\">".length;
cr_id = cr_id.substring(start, cr_id.indexOf(""));
}
return cr_id;
}
function getCr_vehicle(cr_id_order_list_i_)
{
if (jb_longhaul != "1")
return "";
var start = cr_id_order_list_i_.indexOf("
") + " | ".length;
start = cr_id_order_list_i_.indexOf("\" value=\"", start) + "\" value=\"".length;
return cr_id_order_list_i_.substring(start, cr_id_order_list_i_.indexOf("\"> | ", start));
}
function getCr_starting_min(cr_id_order_list_i_)
{
if (jb_longhaul != "1")
return "";
var start = cr_id_order_list_i_.indexOf("") + " | ".length;
start = cr_id_order_list_i_.indexOf(" | ", start) + " | ".length;
return cr_id_order_list_i_.substring(start, cr_id_order_list_i_.indexOf(" | ", start));
}
function getCr_starting_km(cr_id_order_list_i_)
{
if (jb_longhaul != "1")
return "";
var start = cr_id_order_list_i_.indexOf("") + " | ".length;
start = cr_id_order_list_i_.indexOf(" | ", start) + " | ".length;
start = cr_id_order_list_i_.indexOf(" | ", start) + " | ".length;
return cr_id_order_list_i_.substring(start, cr_id_order_list_i_.indexOf(" | ", start));
}
function getCr_current_location(cr_id_order_list_i_)
{
if (jb_longhaul != "1")
return "";
var start = cr_id_order_list_i_.indexOf("") + " | ".length;
start = cr_id_order_list_i_.indexOf(" | ", start) + " | ".length;
start = cr_id_order_list_i_.indexOf(" | ", start) + " | ".length;
start = cr_id_order_list_i_.indexOf(" | ", start) + " | ".length;
return cr_id_order_list_i_.substring(start, cr_id_order_list_i_.indexOf(" | ", start));
}
function getCur_cr_homezipcode(cr_id_order_list_i_)
{
if (jb_longhaul != "1")
return "";
var start = cr_id_order_list_i_.indexOf("") + " | ".length;
start = cr_id_order_list_i_.indexOf(" | ", start) + " | ".length;
start = cr_id_order_list_i_.indexOf(" | ", start) + " | ".length;
start = cr_id_order_list_i_.indexOf(" | ", start) + " | ".length;
start = cr_id_order_list_i_.indexOf(" | ", start) + " | ".length;
return cr_id_order_list_i_.substring(start, cr_id_order_list_i_.indexOf(" | ", start));
}
function getRound_km(cr_id_order_list_i_)
{
if (jb_longhaul != "1")
return "";
var start = cr_id_order_list_i_.indexOf("") + " | ".length;
start = cr_id_order_list_i_.indexOf(" | ", start) + " | ".length;
start = cr_id_order_list_i_.indexOf(" | ", start) + " | ".length;
start = cr_id_order_list_i_.indexOf(" | ", start) + " | ".length;
start = cr_id_order_list_i_.indexOf(" | ", start) + " | ".length;
start = cr_id_order_list_i_.indexOf(" | ", start) + " | ".length;
return cr_id_order_list_i_.substring(start, cr_id_order_list_i_.indexOf(" | ", start));
}
function getCr_price(cr_id_order_list_i_)
{
if (jb_longhaul != "1")
return "";
var start = cr_id_order_list_i_.lastIndexOf("") + " | ".length;
var end_correct = 0;
if (cr_id_order_list_i_.substring(start, start + "".length) == "") {
start += "".length;
end_correct = "".length;
}
var cr_price = cr_id_order_list_i_.substring(start, cr_id_order_list_i_.indexOf(" | "));
}
function is_blocked(cr_id_order_list_i_)
{
if (typeof(cr_id_order_list_blocked)!='undefined'&&typeof(MASK_COURIER_BLOCK_BLOCKED)!='undefined') {
if(MASK_COURIER_BLOCK_BLOCKED=="1") {
cr_id = getCr_id2(cr_id_order_list_i_);
for (var i = 0; i < cr_id_order_list_blocked.length; i++)
if (cr_id_order_list_blocked[i] == cr_id)
return true;
}
}
return false;
}
var refresh_done = false;
function is_in_cr_id_order_list_customer(cr_sid)
{
//alert("'" + cr_sid + "' '" + cr_id_order_list_customer.length + "'");
for (var j = 0; j < cr_id_order_list_customer.length; j++)
{
if (cr_id_order_list_customer[j] == cr_sid) {
//alert("'" + cr_sid + "' '" + cr_id_order_list_customer.length + "'");
return true;
}
}
return false;
}
/*
* update_cr_id_list
* params: jb_id, ad_zipcode
* return:
* global: cr_id_order_list
*
* Update der Kurierliste in cr_id_order_list per Server-Request, wenn auto_refresh = 0
* (d.h. automatischer Refresh ausgeschaltet).
* Wird durch glob_defs.inc.php gesteuert, PHP (job_options.php und jb_list.php) setzt
* in die Variable auto_refresh den Wert aus MASK_AUTO_REFRESH.
*/
function update_cr_id_list(jb_id, ad_zipcode, hq_id_string)
{
var php_params = "jb_id=" + jb_id + "&zipcode=" + ad_zipcode + "&hq_id_string=" + hq_id_string;
// Wenn jb_id nicht angegeben, dann handelt es sich um einen Aufruf aus der Auftragserfassung heraus
if (jb_id == '')
php_params = "zipcode=" + getJobList(0, jl_ad_zipcode);
tempWin = mkPopupWin(
"function startReload()\n" +
"{\n" +
" checkDone();\n" +
" self.location.href=\"../jobs/get_couriers.php?" + php_params + "\";\n" +
"}\n" +
"\n" +
"//--" + ">\n" +
"<\/script>\n" +
"<\/head>\n" +
"\n" +
" \n" +
" \n" +
" \n" +
" Hole Daten...\n" +
" <\/td>\n" +
" <\/tr>\n" +
" <\/table>\n" +
"<\/body>\n" +
"<\/html>\n", 0, 0);
refresh_done = true;
}
function compareFn1(a, b) {
if (getCr_vehicle(a) < getCr_vehicle(b)) {
return -1;
} else if (getCr_vehicle(a) > getCr_vehicle(b)) {
return 1;
}
return 0;
}
function compareFn2(a, b) {
if (Number(getCr_starting_min(a)) < Number(getCr_starting_min(b))) {
return -1;
} else if (Number(getCr_starting_min(a)) > Number(getCr_starting_min(b))) {
return 1;
}
return 0;
}
function compareFn3(a, b) {
if (Number(getCr_starting_km(a)) < Number(getCr_starting_km(b))) {
return -1;
} else if (Number(getCr_starting_km(a)) > Number(getCr_starting_km(b))) {
return 1;
}
return 0;
}
function compareFn4(a, b) {
if (getCr_current_location(a) < getCr_current_location(b)) {
return -1;
} else if (getCr_current_location(a) > getCr_current_location(b)) {
return 1;
}
return 0;
}
function compareFn5(a, b) {
if (getCur_cr_homezipcode(a) < getCur_cr_homezipcode(b)) {
return -1;
} else if (getCur_cr_homezipcode(a) > getCur_cr_homezipcode(b)) {
return 1;
}
return 0;
}
function compareFn6(a, b) {
if (Number(getRound_km(a)) < Number(getRound_km(b))) {
return -1;
} else if (Number(getRound_km(a)) > Number(getRound_km(b))) {
return 1;
}
return 0;
}
function compareFn7(a, b) {
if (Number(getCr_price(a)) < Number(getCr_price(b))) {
return -1;
} else if (Number(getCr_price(a)) > Number(getCr_price(b))) {
return 1;
}
return 0;
}
function cr_id_order_list_sort(cr_id_order_list_no, s)
{
var cur_sort = [];
var cur_i = 0;
if (cr_id_order_list_no == 1)
cr_id_order_list_length = cr_id_order_list.length;
if (cr_id_order_list_no == 2)
cr_id_order_list_length = cr_id_order_list2.length;
for (i = 0; i < cr_id_order_list_length; i++)
{
if (cr_id_order_list_no == 1)
cr_id_order_list_i_ = cr_id_order_list[i];
if (cr_id_order_list_no == 2)
cr_id_order_list_i_ = cr_id_order_list2[i];
if (cr_id_order_list_i_.indexOf("Heimat-PLZ") > -1)
{
if (cur_sort.length > 0) {
switch(Number(s)) {
case 1:
cur_sort.sort(compareFn1);
break;
case 2:
cur_sort.sort(compareFn2);
break;
case 3:
cur_sort.sort(compareFn3);
break;
case 4:
cur_sort.sort(compareFn4);
break;
case 5:
cur_sort.sort(compareFn5);
break;
case 6:
cur_sort.sort(compareFn6);
break;
case 7:
default:
cur_sort.sort(compareFn7);
}
// Reverse sort order ?
var reverse = false;
if ((cr_id_order_list_no == 1 && cr_id_order_list[cur_i+0] == cur_sort[0] && cr_id_order_list[cur_i+cur_sort.length-1] == cur_sort[cur_sort.length-1]) ||
(cr_id_order_list_no == 2 && cr_id_order_list2[cur_i+0] == cur_sort[0] && cr_id_order_list2[cur_i+cur_sort.length-1] == cur_sort[cur_sort.length-1]))
reverse = true;
for (j = 0; j < cur_sort.length; j++) {
if (cr_id_order_list_no == 1)
cr_id_order_list[cur_i+j] = (!reverse ? cur_sort[j] : cur_sort[cur_sort.length-1-j]);
if (cr_id_order_list_no == 2)
cr_id_order_list2[cur_i+j] = (!reverse ? cur_sort[j] : cur_sort[cur_sort.length-1-j]);
}
}
cur_sort = [];
cur_i = i + 1;
} else {
if (cr_id_order_list_i_.substr(0, 1) != "*" && cr_id_order_list_i_.substr(0, 1) != "#")
cur_sort[cur_sort.length] = cr_id_order_list_i_;
}
}
if (cur_sort.length > 0) {
switch(Number(s)) {
case 1:
cur_sort.sort(compareFn1);
break;
case 2:
cur_sort.sort(compareFn2);
break;
case 3:
cur_sort.sort(compareFn3);
break;
case 4:
cur_sort.sort(compareFn4);
break;
case 5:
cur_sort.sort(compareFn5);
break;
case 6:
cur_sort.sort(compareFn6);
break;
case 7:
default:
cur_sort.sort(compareFn7);
}
// Reverse sort order ?
var reverse = false;
if ((cr_id_order_list_no == 1 && cr_id_order_list[cur_i+0] == cur_sort[0] && cr_id_order_list[cur_i+cur_sort.length-1] == cur_sort[cur_sort.length-1]) ||
(cr_id_order_list_no == 2 && cr_id_order_list2[cur_i+0] == cur_sort[0] && cr_id_order_list2[cur_i+cur_sort.length-1] == cur_sort[cur_sort.length-1]))
reverse = true;
for (j = 0; j < cur_sort.length; j++) {
if (cr_id_order_list_no == 1)
cr_id_order_list[cur_i+j] = (!reverse ? cur_sort[j] : cur_sort[cur_sort.length-1-j]);
if (cr_id_order_list_no == 2)
cr_id_order_list2[cur_i+j] = (!reverse ? cur_sort[j] : cur_sort[cur_sort.length-1-j]);
}
}
}
//var whenString = " ";
var lfdNr = 1;
function mk_cr_id_list_content(cr_id_order_list_no, jb_id, ad_zipcode, s)
{
var lfdNrStr = "";
var content = "";
var cr_id_order_list_length;
var customer_courier_list = false;
if (typeof (cs_jbedit_cr) != 'undefined')
{
if (cs_jbedit_cr == 1)
{
customer_courier_list = true;
}
}
if (jb_longhaul == "1")
cr_id_order_list_sort(cr_id_order_list_no, s);
if (cr_id_order_list_no == 1)
cr_id_order_list_length = cr_id_order_list.length;
if (cr_id_order_list_no == 2)
cr_id_order_list_length = cr_id_order_list2.length;
if (cr_id_order_list_length == 0)
content = "[Kein Eintrag vorhanden]";
var curPLZ = "***START***";
var spacer = " |  | ";
var cr_id_order_list_i_ = "";
for (i = 0; i < cr_id_order_list_length; i++)
{
curBestAnchorStart = "";
curBestAnchorEnd = "";
curSelectedStart = "";
curSelectedEnd = "";
if (cr_id_order_list_no == 1)
cr_id_order_list_i_ = cr_id_order_list[i];
if (cr_id_order_list_no == 2)
cr_id_order_list_i_ = cr_id_order_list2[i];
// Überschrift
if (cr_id_order_list_i_.substr(0, 1) == "#")
{
content = content + spacer + spacer +
"" +
cr_id_order_list_i_.substr(1) +
" \n" +
"<\/td><\/tr>";
} else {
// Uhrzeit/Aktualisieren
// if (cr_id_order_list_i_.substr(0, 1) == "~")
// {
// content = content + spacer + spacer +
// " | | " +
// cr_id_order_list_i_.substr(1) +
// "<\/td><\/tr>";
// } else {
// die Gruppennamen herausfiltern
if (cr_id_order_list_i_.substr(0, 1) == "*")
{
content = content + spacer + spacer +
" | " : ">") +
cr_id_order_list_i_.substr(1) +
"<\/td><\/tr>";
} else {
if (!customer_courier_list || (customer_courier_list && is_in_cr_id_order_list_customer(getCr_id2(cr_id_order_list_i_))))
{
if (curPLZ != getPLZ(cr_id_order_list_i_) && jb_id != "")
{
// if (curPLZ != "***START***")
content = content + spacer;
curPLZ = getPLZ(cr_id_order_list_i_);
}
var jb_id_param = "";
if (jb_id != '' && ad_zipcode != '')
jb_id_param = "'" + jb_id + "',";
lfdNrStr = lfdNr.toString();
if (lfdNr < 10)
lfdNrStr = "0" + lfdNrStr;
lfdNr++;
var cr_id_order_list_i_temp = "";
cr_id_order_list_i_temp = cr_id_order_list_i_.replace(/\*/,"");
if(customer_courier_list){
cr_id_order_list_i_temp = cr_id_order_list_i_temp.replace(//g,"");
//cr_id_order_list_i_temp = cr_id_order_list_i_temp.replace(/<\/span><\/i><\/a>/,"");
}
content = content + curBestAnchorStart +
"| " + lfdNrStr + ". " +
"" + "O" + "<\/a>" : ">") +
" " +
(is_blocked(cr_id_order_list_i_) ? "" :
"")+
curBestAnchorStart + curSelectedStart + cr_id_order_list_i_temp + curSelectedEnd + curBestAnchorEnd + "<\/a>" +
"\n" +
"<\/td><\/tr>";
//alert(cr_id_order_list_i_);
// MK, 13:02 - B9999A, Großer Bus
// | Großer Bus | 262 | 423 | 13597 Berlin, Gewerbehof 17 | 22525 | 1093 | 190,54
//alert(curBestAnchorStart +
// " | " + lfdNrStr + ". " +
// "" + "O" + "<\/a>" : ">") +
// " " +
// (is_blocked(cr_id_order_list_i_) ? "" :
// "")+
// curBestAnchorStart + curSelectedStart + cr_id_order_list_i_temp + curSelectedEnd + curBestAnchorEnd + lfdNrStr + "honk<\/a>" +
// "\n" +
// "<\/td><\/tr>");
}
}
}
}
// }
content = content + spacer + spacer;
return content;
}
var popupWin = null;
/*
* mk_cr_id_list
* params: jb_id, ad_zipcode
* return:
* global: cr_id_order_list
*
* Erzeugt Popup-Fenster für die Kurierauswahl. Wenn Auto-Refresh ausgeschaltet, dann
* wird die Liste vorher per Server-Request aktualisiert.
*/
function mk_cr_id_list(jb_id, ad_zipcode, hq_id_string, s)
{
var widthPopupWin = 1012;
var heightPopupWin = 700;
var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 5;
var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
var content = "";
var curSelectedStart = "";
var curSelectedEnd = "";
var curBest = "";
var curBestAnchorStart = "";
var curBestAnchorEnd = "";
if (typeof(s) == 'undefined')
var s = 0;
// whenString = "(Stand: " + when + " Uhr)
\n"
if (auto_refresh == "0" && jb_id != '' && ad_zipcode != '' && s == '0') {
if (!refresh_done) {
update_cr_id_list(jb_id, ad_zipcode, hq_id_string);
return;
} else {
refresh_done = false;
}
} else {
if (s != '0' && typeof(vht_id_str) == 'undefined') {
update_cr_id_list(jb_id, ad_zipcode, hq_id_string);
return;
}
}
lfdNr = 1;
content = content + mk_cr_id_list_content(1, jb_id, ad_zipcode, s);
if (MASK_COURIER_SORT_BY_OCCUPIED == "1")
{
content = content + mk_cr_id_list_content(2, jb_id, ad_zipcode, s);
}
setCourierFunction_vht_id_str = "vht_id_str = new Array();\n";
for (var _cr_sid_ in vht_id_str)
setCourierFunction_vht_id_str = setCourierFunction_vht_id_str + "vht_id_str[\"" + _cr_sid_ + "\"] = \"" + vht_id_str[_cr_sid_].replace(/\n\n/,"\\n\\n") + "\";\n";
setCourierFunction =
"function setCourier(jb_id,cr_sid,jb_cr_price,jb_cr_price_sub,jb_cr_fuel_markup)\n" +
"{\n" +
setCourierFunction_vht_id_str +
" addmsg = vht_id_str[cr_sid];\n" +
" var penalty = 0;\n"+
" if (this.document.reset_cr_availabletime_form.reset_cr_availabletime.checked) {\n"+
" addmsg = \"\\n(Freimeldezeit von \" + this.document.reset_cr_availabletime_form.cur_cr_sid.value + \" wird aktualisiert)\" + addmsg;\n"+
" penalty = 1;\n"+
" }"+
" if (confirm(\"Kurier \" + cr_sid + \" dem Auftrag \" + jb_id + \" zuweisen?\" + addmsg)) {\n" +
" this.opener.setCourier(jb_id,cr_sid,penalty,jb_cr_price,jb_cr_price_sub,jb_cr_fuel_markup);\n"+
" self.close();\n" +
" };\n" +
"};\n";
// Wenn jb_id nicht angegeben, dann handelt es sich um einen Aufruf aus der Auftragserfassung heraus
if (jb_id == '' || ad_zipcode == '')
{
setCourierFunction =
"function setCourier(cr_sid)\n" +
"{\n" +
" opener.parent.job_options.document.tourOptions.cr_id_order.value = cr_sid;\n" +
" opener.parent.job_options.document.tourOptions.cr_id_order_hidden.value = cr_sid;\n" +
" self.close();\n" +
" opener.checkCr_id_order();\n" +
" opener.parent.job_options.document.forms.tourOptions.cr_id_order.focus();\n" +
"};\n";
if (ad_zipcode == 'calculator')
setCourierFunction =
"function setCourier(cr_sid)\n" +
"{\n" +
" opener.cur_popupWin.document.forms[0].tmp_add_sid.value = cr_sid;\n" +
" self.close();\n" +
" opener.cur_popupWin.document.forms[0].tmp_add_sid.focus();\n" +
"};\n";
}
heightPopupWin += 8;
if (popupWin === null || popupWin.closed)
popupWin=window.open("about:blank", "",
"dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +
",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
popupWin.document.open();
popupWin.document.writeln(
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"votian: Auftragserfassung - Liste der Transporteure<\/title>\n"+
"\n"+
" | | |