"; // ******************************** // Get interval of one year before $day_from_year_before = $day_from; $month_from_year_before = $month_from; $year_from_year_before = ($year_from - 1); $day_to_year_before = $day_to; $month_to_year_before = $month_to; $year_to_year_before = ($year_to - 1); // Check for leap year $currentYearIsLeapYearFrom = date("L", mktime(0, 0, 0, $month_from, $day_from, $year_from)); if ($currentYearIsLeapYearFrom == "1" && $month_from == "2" && $day_from == "29") : $day_from_year_before = "28"; endif; $currentYearIsLeapYearTo = date("L", mktime(0, 0, 0, $month_to, $day_to, $year_to)); if ($currentYearIsLeapYearTo == "1" && $month_to == "2" && $day_to == "29") : $day_to_year_before = "28"; endif; $yearBeforeIsLeapYearFrom = date("L", mktime(0, 0, 0, $month_from_year_before, $day_from_year_before, $year_from_year_before)); if ($yearBeforeIsLeapYearFrom == "1" && $month_from == "2" && $day_from == "28") : $day_from_year_before = "29"; endif; $yearBeforeIsLeapYearTo = date("L", mktime(0, 0, 0, $month_to_year_before, $day_to_year_before, $year_to_year_before)); if ($yearBeforeIsLeapYearTo == "1" && $month_to == "2" && $day_to == "28") : $day_from_year_before = "29"; endif; // Range one year before $fromDateRangeYearBefore = $year_from_year_before . "-" . pad($month_from_year_before,2) . "-" . pad($day_from_year_before,2) . " 00:00:00"; $toDateRangeYearBefore = $year_to_year_before . "-" . pad($month_to_year_before,2) . "-" . pad($day_to_year_before,2) . " 23:59:59"; // Get date from datetime only $tmpFromDateYearBefore = substr($fromDateRangeYearBefore,0,10); $tmpToDateYearBefore = substr($toDateRangeYearBefore,0,10); // ******************************** // Get all entries of logo_id = '95' between a specified date range $sqlquery = "SELECT hq.hq_mnemonic, usr.usr_id, CONCAT(usr.usr_name, ', ', usr.usr_firstname) AS user, log.cs_id, cs.cs_eid, cmp.cmp_comp, log.logo_description" . " FROM phoenix_log.log AS log, phoenix.user AS usr, phoenix.customer AS cs, phoenix.company AS cmp, phoenix.headquarters AS hq" . " WHERE log.logo_id = '95' AND log.log_createtime >= '" . $fromDateRange . "' AND log.log_createtime <= '" . $toDateRange . "' AND" . " log.hq_id = hq.hq_id AND log.usr_id = usr.usr_id AND log.cs_id = cs.cs_id AND cs.cmp_id = cmp.cmp_id" . " ORDER BY log.hq_id, user"; $result = $db->query($sqlquery); if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage()); $statArray = array(); $usrIdArray = array(); $usrNameArray = array(); $hqMnemonicArray = array(); $cmpCompArray = array(); $csEidArray = array(); $csStatArray = array(); $showUserInEveryCaseArray = array(); while ($row = $result->fetch_assoc()): $f_hq_mnemonic = $row["hq_mnemonic"]; $f_usr_id = $row["usr_id"]; $f_user = $row["user"]; $f_cs_id = $row["cs_id"]; $f_cs_eid = $row["cs_eid"]; $f_cmp_comp = $row["cmp_comp"]; $f_logo_description = $row["logo_description"]; $descArray = getKeyValueArrayFromString($f_logo_description); // echo ($descArray["SRC"] == "" ? "_" : $descArray["SRC"]); echo "   "; echo ($descArray["OLD"] == "" ? "_" : $descArray["OLD"]); echo "   "; echo ($descArray["NEW"] == "" ? "_" : $descArray["NEW"]); echo "
"; // if ($descArray["OLD"] == "") : $descArray["OLD"] = "0"; endif; // No switch of the state, only a new customer entry $j = array_search($f_usr_id, $usrIdArray); if ($j === FALSE) : $usrIdArray[] = $f_usr_id; $usrNameArray[$f_usr_id] = $f_user; $hqMnemonicArray[$f_usr_id] = $f_hq_mnemonic; $statArray[$f_usr_id]["cs"]["0"] = "0"; $statArray[$f_usr_id]["cs"]["1"] = "0"; $statArray[$f_usr_id]["cs"]["2"] = "0"; $statArray[$f_usr_id]["cs"]["3"] = "0"; $statArray[$f_usr_id]["jb"]["0"] = "0"; $statArray[$f_usr_id]["jb"]["1"] = "0"; $statArray[$f_usr_id]["jb"]["2"] = "0"; $statArray[$f_usr_id]["jb"]["3"] = "0"; endif; // Statistic only for switch to real customer state (== "0") if ($descArray["NEW"] == "0" && $descArray["OLD"] != "") : ++$statArray[$f_usr_id][$descArray["SRC"]][$descArray["OLD"]]; if ($cs_out) : $cmpCompArray[$f_usr_id][$descArray["SRC"]][$descArray["OLD"]][] = $f_cmp_comp; $csEidArray[$f_usr_id][$descArray["SRC"]][$descArray["OLD"]][] = $f_cs_eid; if ($cs_stat_out) : // Statistic business volume from 01.01. of the current year to the current day $statisticValue = getCsStatistic($f_cs_id, $tmpFromDate, $tmpToDate); $csStatArray[$f_usr_id][$descArray["SRC"]][$descArray["OLD"]][] = $statisticValue; endif; endif; endif; endwhile; $result->free(); // **** ADDING SALES EMPLOYEES **** // Get all sales employees being associated to companies and merge not existing users (in $usrIdArray) $usrIdSalesArray = getColVectorFromDB2ArrayByClause("company AS cmp, employee AS emp, user AS usr", "usr.usr_id", "cmp.emp_id_sales = emp.emp_id AND emp.usr_id = usr.usr_id", "", "", "DISTINCT"); $usrIdSalesArrayLen = count($usrIdSalesArray); for ($i = 0; $i < $usrIdSalesArrayLen; $i++) : $currUsrId = $usrIdSalesArray[$i]; $showUserInEveryCaseArray[$currUsrId] = "1"; $j = array_search($currUsrId, $usrIdArray); if ($j === FALSE) : $usrIdArray[] = $currUsrId; $tmpUsrName = getFieldValueFromId("phoenix.user", "usr_id", $currUsrId, "usr_name"); $tmpUsrFirstname = getFieldValueFromId("phoenix.user", "usr_id", $currUsrId, "usr_firstname"); $usrNameArray[$currUsrId] = $tmpUsrName . ", " . $tmpUsrFirstname; $tmpHqId = getFieldValueFromId("user", "usr_id", $currUsrId, "hq_id"); $hqMnemonicArray[$currUsrId] = getFieldValueFromId("headquarters", "hq_id", $tmpHqId, "hq_mnemonic"); endif; endfor; $out = ""; $usrIdArrayLen = count($usrIdArray); for ($i = 0; $i < $usrIdArrayLen; $i++) : $currUsrId = $usrIdArray[$i]; $stat_jb_1 = $statArray[$currUsrId]["jb"]["1"]; $stat_jb_2 = $statArray[$currUsrId]["jb"]["2"]; $stat_jb_3 = $statArray[$currUsrId]["jb"]["3"]; // $stat_cs_0 = $statArray[$currUsrId]["cs"]["0"]; $stat_cs_1 = $statArray[$currUsrId]["cs"]["1"]; $stat_cs_2 = $statArray[$currUsrId]["cs"]["2"]; $stat_cs_3 = $statArray[$currUsrId]["cs"]["3"]; if ($cs_out) : mcArrIsSet($cmpCompArray, $currUsrId, array()); mcArrIsSet($cmpCompArray[$currUsrId], "jb", array()); mcArrIsSet($cmpCompArray[$currUsrId], "cs", array()); $cmpComp_jb_1 = ""; mcArrIsSet($cmpCompArray[$currUsrId]["jb"], "1", array()); $arrayLen = count($cmpCompArray[$currUsrId]["jb"]["1"]); if ($arrayLen > 0) : for ($k = 0; $k < $arrayLen; $k++) : $cmpComp_jb_1 .= ""; if ($fileOutput) : $tmpOutputLinesArray_jb_1[$currUsrId][] = $cmpCompArray[$currUsrId]["jb"]["1"][$k] . $delimiter . $csEidArray[$currUsrId]["jb"]["1"][$k] . $delimiter . ($cs_stat_out == true ? $csStatArray[$currUsrId]["jb"]["1"][$k] : "") . $delimiter; endif; endfor; endif; $cmpComp_jb_2 = ""; mcArrIsSet($cmpCompArray[$currUsrId]["jb"], "2", array()); $arrayLen = count($cmpCompArray[$currUsrId]["jb"]["2"]); if ($arrayLen > 0) : for ($k = 0; $k < $arrayLen; $k++) : $cmpComp_jb_2 .= ""; if ($fileOutput) : $tmpOutputLinesArray_jb_2[$currUsrId][] = $cmpCompArray[$currUsrId]["jb"]["2"][$k] . $delimiter . $csEidArray[$currUsrId]["jb"]["2"][$k] . $delimiter . ($cs_stat_out == true ? $csStatArray[$currUsrId]["jb"]["2"][$k] : "") . $delimiter; endif; endfor; endif; $cmpComp_jb_3 = ""; mcArrIsSet($cmpCompArray[$currUsrId]["jb"], "3", array()); $arrayLen = count($cmpCompArray[$currUsrId]["jb"]["3"]); if ($arrayLen > 0) : for ($k = 0; $k < $arrayLen; $k++) : $cmpComp_jb_3 .= ""; if ($fileOutput) : $tmpOutputLinesArray_jb_3[$currUsrId][] = $cmpCompArray[$currUsrId]["jb"]["3"][$k] . $delimiter . $csEidArray[$currUsrId]["jb"]["3"][$k] . $delimiter . ($cs_stat_out == true ? $csStatArray[$currUsrId]["jb"]["3"][$k] : "") . $delimiter; endif; endfor; endif; $cmpComp_cs_1 = ""; mcArrIsSet($cmpCompArray[$currUsrId]["cs"], "1", array()); $arrayLen = count($cmpCompArray[$currUsrId]["cs"]["1"]); if ($arrayLen > 0) : for ($k = 0; $k < $arrayLen; $k++) : $cmpComp_cs_1 .= ""; if ($fileOutput) : $tmpOutputLinesArray_cs_1[$currUsrId][] = $cmpCompArray[$currUsrId]["cs"]["1"][$k] . $delimiter . $csEidArray[$currUsrId]["cs"]["1"][$k] . $delimiter . ($cs_stat_out == true ? $csStatArray[$currUsrId]["cs"]["1"][$k] : "") . $delimiter; endif; endfor; endif; $cmpComp_cs_2 = ""; mcArrIsSet($cmpCompArray[$currUsrId]["cs"], "2", array()); $arrayLen = count($cmpCompArray[$currUsrId]["cs"]["2"]); if ($arrayLen > 0) : for ($k = 0; $k < $arrayLen; $k++) : $cmpComp_cs_2 .= ""; if ($fileOutput) : $tmpOutputLinesArray_cs_2[$currUsrId][] = $cmpCompArray[$currUsrId]["cs"]["2"][$k] . $delimiter . $csEidArray[$currUsrId]["cs"]["2"][$k] . $delimiter . ($cs_stat_out == true ? $csStatArray[$currUsrId]["cs"]["2"][$k] : "") . $delimiter; endif; endfor; endif; $cmpComp_cs_3 = ""; mcArrIsSet($cmpCompArray[$currUsrId]["cs"], "3", array()); $arrayLen = count($cmpCompArray[$currUsrId]["cs"]["3"]); if ($arrayLen > 0) : for ($k = 0; $k < $arrayLen; $k++) : $cmpComp_cs_3 .= ""; if ($fileOutput) : $tmpOutputLinesArray_cs_3[$currUsrId][] = $cmpCompArray[$currUsrId]["cs"]["3"][$k] . $delimiter . $csEidArray[$currUsrId]["cs"]["3"][$k] . $delimiter . ($cs_stat_out == true ? $csStatArray[$currUsrId]["cs"]["3"][$k] : "") . $delimiter; endif; endfor; endif; endif; if ($showUserInEveryCaseArray[$currUsrId] == "1" || $stat_jb_1 > 0 || $stat_jb_2 > 0 || $stat_jb_3 > 0 || $stat_cs_1 > 0 || $stat_cs_2 > 0 || $stat_cs_3 > 0) : // if (true) : $out .= ""; if ($fileOutput) : $tmpOutputLinesArrayUsrData = $usrNameArray[$currUsrId] . $delimiter . $hqMnemonicArray[$currUsrId] . $delimiter; endif; if ($stat_jb_1 > 0) : $out .= ""; $tmpOutputLinesArraySwitchMode = "Interessent zu Kunde über Auftrag" . $delimiter; if ($cs_out) : $out .= $cmpComp_jb_1; if ($fileOutput) : $tmpLen = count($tmpOutputLinesArray_jb_1[$currUsrId]); for ($k = 0; $k < $tmpLen; $k++) : $outputLinesArray[] = $tmpOutputLinesArrayUsrData . $tmpOutputLinesArraySwitchMode . $tmpOutputLinesArray_jb_1[$currUsrId][$k]; endfor; endif; endif; endif; if ($stat_jb_2 > 0) : $out .= ""; $tmpOutputLinesArraySwitchMode = "Potentialkunde zu Kunde über Auftrag" . $delimiter; if ($cs_out) : $out .= $cmpComp_jb_2; if ($fileOutput) : $tmpLen = count($tmpOutputLinesArray_jb_2[$currUsrId]); for ($k = 0; $k < $tmpLen; $k++) : $outputLinesArray[] = $tmpOutputLinesArrayUsrData . $tmpOutputLinesArraySwitchMode . $tmpOutputLinesArray_jb_2[$currUsrId][$k]; endfor; endif; endif; endif; if ($stat_jb_3 > 0) : $out .= ""; $tmpOutputLinesArraySwitchMode = "Wunschkunde zu Kunde über Auftrag" . $delimiter; if ($cs_out) : $out .= $cmpComp_jb_3; if ($fileOutput) : $tmpLen = count($tmpOutputLinesArray_jb_3[$currUsrId]); for ($k = 0; $k < $tmpLen; $k++) : $outputLinesArray[] = $tmpOutputLinesArrayUsrData . $tmpOutputLinesArraySwitchMode . $tmpOutputLinesArray_jb_3[$currUsrId][$k]; endfor; endif; endif; endif; // if ($stat_cs_0 > 0) : // $out .= ""; // endif; if ($stat_cs_1 > 0) : $out .= ""; $tmpOutputLinesArraySwitchMode = "Interessent zu Kunde über Stammblatt" . $delimiter; if ($cs_out) : $out .= $cmpComp_cs_1; if ($fileOutput) : $tmpLen = count($tmpOutputLinesArray_cs_1[$currUsrId]); for ($k = 0; $k < $tmpLen; $k++) : $outputLinesArray[] = $tmpOutputLinesArrayUsrData . $tmpOutputLinesArraySwitchMode . $tmpOutputLinesArray_cs_1[$currUsrId][$k]; endfor; endif; endif; endif; if ($stat_cs_2 > 0) : $out .= ""; $tmpOutputLinesArraySwitchMode = "Potentialkunde zu Kunde über Stammblatt" . $delimiter; if ($cs_out) : $out .= $cmpComp_cs_2; if ($fileOutput) : $tmpLen = count($tmpOutputLinesArray_cs_2[$currUsrId]); for ($k = 0; $k < $tmpLen; $k++) : $outputLinesArray[] = $tmpOutputLinesArrayUsrData . $tmpOutputLinesArraySwitchMode . $tmpOutputLinesArray_cs_2[$currUsrId][$k]; endfor; endif; endif; endif; if ($stat_cs_3 > 0) : $out .= ""; $tmpOutputLinesArraySwitchMode = "Wunschkunde zu Kunde über Stammblatt" . $delimiter; if ($cs_out) : $out .= $cmpComp_cs_3; if ($fileOutput) : $tmpLen = count($tmpOutputLinesArray_cs_3[$currUsrId]); for ($k = 0; $k < $tmpLen; $k++) : $outputLinesArray[] = $tmpOutputLinesArrayUsrData . $tmpOutputLinesArraySwitchMode . $tmpOutputLinesArray_cs_3[$currUsrId][$k]; endfor; endif; endif; endif; // ********************************************************************************************************* // * Check for existing customers the sales employee is associated to and add this information to the list * // ********************************************************************************************************* $empIdSales = getFieldValueFromId("employee", "usr_id", $currUsrId, "emp_id"); // Get the emp_id of the current sales user $sqlquery = "SELECT cmp.cmp_comp, cs.cs_id, cs.cs_eid" . " FROM customer AS cs, company AS cmp" . " WHERE cmp.emp_id_sales = '" . $empIdSales . "' AND cmp.cmp_id = cs.cmp_id" . " ORDER BY cmp.cmp_comp"; $result = $db->query($sqlquery); if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage()); $outSales = ""; $outSalesHeader = true; while ($row = $result->fetch_assoc()): if ($outSalesHeader) : $out .= ""; $outSalesHeader = false; endif; $statisticValueCurrent = getCsStatistic($row["cs_id"], $tmpFromDate, $tmpToDate, "", "", "1"); $statisticValueYearBefore = getCsStatistic($row["cs_id"], $tmpFromDateYearBefore, $tmpToDateYearBefore, "", "", "1"); $statisticValue = ($statisticValueCurrent - $statisticValueYearBefore); $statisticValue = number_format(round($statisticValue,2), 2, ",", "."); $out .= ""; if ($fileOutput) : $outputLinesArray[] = $tmpOutputLinesArrayUsrData . "Bestandskunde(n)" . $delimiter . $row["cmp_comp"] . $delimiter . $row["cs_eid"] . $delimiter . ($cs_stat_out == true ? $statisticValue : "") . $delimiter; endif; endwhile; $result->free(); $out .= ""; endif; endfor; $out .= "
" . "  - " . $cmpCompArray[$currUsrId]["jb"]["1"][$k] . " [" . $csEidArray[$currUsrId]["jb"]["1"][$k] . "]". ($cs_stat_out == true ? " [" . $csStatArray[$currUsrId]["jb"]["1"][$k] . "]" : "") ."
" . "  - " . $cmpCompArray[$currUsrId]["jb"]["2"][$k] . " [" . $csEidArray[$currUsrId]["jb"]["2"][$k] . "]". ($cs_stat_out == true ? " [" . $csStatArray[$currUsrId]["jb"]["2"][$k] . "]" : "") ."
" . "  - " . $cmpCompArray[$currUsrId]["jb"]["3"][$k] . " [" . $csEidArray[$currUsrId]["jb"]["3"][$k] . "]". ($cs_stat_out == true ? " [" . $csStatArray[$currUsrId]["jb"]["3"][$k] . "]" : "") ."
" . "  - " . $cmpCompArray[$currUsrId]["cs"]["1"][$k] . " [" . $csEidArray[$currUsrId]["cs"]["1"][$k] . "]". ($cs_stat_out == true ? " [" . $csStatArray[$currUsrId]["cs"]["1"][$k] . "]" : "") ."
" . "  - " . $cmpCompArray[$currUsrId]["cs"]["2"][$k] . " [" . $csEidArray[$currUsrId]["cs"]["2"][$k] . "]". ($cs_stat_out == true ? " [" . $csStatArray[$currUsrId]["cs"]["2"][$k] . "]" : "") ."
" . "  - " . $cmpCompArray[$currUsrId]["cs"]["3"][$k] . " [" . $csEidArray[$currUsrId]["cs"]["3"][$k] . "]". ($cs_stat_out == true ? " [" . $csStatArray[$currUsrId]["cs"]["3"][$k] . "]" : "") ."
" . $usrNameArray[$currUsrId] . "[" . $hqMnemonicArray[$currUsrId] . "]
" . "- Interessent zu Kunde über Auftrag:" . "" . $stat_jb_1 . "
" . "- Potentialkunde zu Kunde über Auftrag:" . "" . $stat_jb_2 . "
" . "- Wunschkunde zu Kunde über Auftrag:" . "" . $stat_jb_3 . "
" . "- Neuanlage eines Kunden:" . "" . $stat_cs_0 . "
" . "- Interessent zu Kunde über Stammblatt:" . "" . $stat_cs_1 . "
" . "- Potentialkunde zu Kunde über Stammblatt:" . "" . $stat_cs_2 . "
" . "- Wunschkunde zu Kunde über Stammblatt:" . "" . $stat_cs_3 . "
" . "- Umsatzzuwachs Bestandskunde(n):" . "" . $stat_cs_3 . "
" . "  - " . $row["cmp_comp"] . " [" . $row["cs_eid"] . "]". ($cs_stat_out == true ? " [" . $statisticValue . "]" : "") ."
 
"; $currentFrameName = ""; // Empty string for "main frame" $filter_dateranges = ""; $js_date = ""; // Date-ranges $filter_dateranges .= "" . getLngt("Von:") . "\n"; $filter_dateranges .= "\n"; $filter_dateranges .= "\n"; $filter_dateranges .= "\n"; $filter_dateranges .= "  " . getLngt("bis:") . "\n"; $filter_dateranges .= "\n"; $filter_dateranges .= "\n"; $filter_dateranges .= "\n"; $filter_dateranges .= ""; // Javascript-function as template only for $js_date .= "\n"; // Optional output to file $outputLinesArrayLen = count($outputLinesArray); $f_secretFileName = ""; $f_path = "../temp/download/"; if ($fileOutput) : // Remove old files foreach (glob($f_path . "*.cs_sc.csv") as $fileNameToBoRemoved) { if ((time() - filemtime($fileNameToBoRemoved)) > 60) : if (file_exists($fileNameToBoRemoved)) : unlink($fileNameToBoRemoved); endif; endif; } if ($outputLinesArrayLen > 0) : $f_fileName = "KUNDENSTATUS_" . date("YmdHis"); // $f_secretFileName = md5($f_fileName) . ".cs_sc.csv"; $f_secretFileName = $f_fileName . ".cs_sc.csv"; if ($outputHeader != "") : writeToFile($f_path . $f_secretFileName, $outputHeader); // write header if requested endif; for ($i = 0; $i < $outputLinesArrayLen; $i++) : writeToFile($f_path . $f_secretFileName, $outputLinesArray[$i]); // write data endfor; else : $statusMessage = "Es wurden keine Daten gefunden! Eine Datei wurde deshalb nicht generiert!"; $fileOutput = false; endif; endif; // Output $onLoadCall = "startTimeout();initForm();displayStatusMessage();"; if ($fileOutput) : $onLoadCall .= "downloadFile();"; endif; ?>


Wechsel der Kundenstatus