Klärungsbedarf vorhanden
* (Bsp.: Wöchentlicher Dauerauftrag wird auf übernächste Woche verschoben, wenn
* nächste Woche an dem normalen nächsten Termin ein Feiertag ist ...)
* Es wird zur Zeit auch noch nicht geprüft, ob der nächste Termin nicht schon längst verstrichen ist!
*/
// Execution-Time for script
set_time_limit(0);
// diese Art der Bearbeitung schafft leider nur ca. einen Auftrag pro SEKUNDE,
// mit set_time_limit (300) können ca. 250 Aufträge bearbeitet werden
//set_time_limit (300);
include_once("../include/dbglobal.inc.php");
$hq_id = $HTTP_GET_VARS["hq_id"];
if ($hq_id == ""):
// writeLog_("../log/check_jb_permanent_standing_", "Fehler: 'hq_id' fehlt!");
// exit();
$hq_id = HQ_ID_DEFAULT;
endif;
include_once("../include/inc_check_publicholiday.inc.php");
include_once("../include/caglobal.inc.php");
$ph = getPublicHolidays(getDateTime("year"), "1", "0");
// "get_saved_tour.php" holt die Daten eines gespeicherten Jobs $jb_id
// voher muss aber die jobList initialisiert werden (macht sonst javascript)
//echo $argc;
//$jb_id = $argv[1];
//var_dump ($argv);
//var_dump ( ini_get("register_argc_argv"));
$jb_id = getenv ("JB_ID");
$jb_finishtime = getenv ("JB_FINISHTIME_DAY") . " " . getenv ("JB_FINISHTIME_TIME");
//$jb_id = $HTTP_GET_VARS["jb_id"];
if ($jb_id == "")
{
$yesterday = getdate(mktime(0, 0, 0, date("m"), date("d") - 1, date("Y")));
$jb_finishtime_start = $yesterday['year'] . "-" . sprintf("%02d", $yesterday['mon']) . "-" . sprintf("%02d", $yesterday['mday']) . " 00:00:01";
// $jb_finishtime_start = "2005-08-30 00:00:01";
// Endless loop
while (TRUE):
// Set execution time for keepalive
$currentTime = getDateTime("0");
updateStmt("keepalive", "ka_process", "standing_orders", array("ka_lastexecutiontime", $currentTime),"");
$today = getdate();
$today_date = $today['year'] . "-" . sprintf("%02d", $today['mon']) . "-" . sprintf("%02d", $today['mday']);
// JB_ID nicht angegeben -> kein expliziter Aufruf
// Alle Daueraufträge finden, die erledigt sind
$sqlquery = "SELECT job.jb_id, job.jb_finishtime FROM job WHERE ((jb_storno != 3 AND jb_storno != 4) OR jb_storno IS NULL) " .
" AND job.jb_status = 2 AND jb_permanent IN (1, 2, 3, 4, 5, 6, 7, 8, 9) AND (jb_id_copy_permanent IS NULL OR jb_id_copy_permanent = 0) " .
" AND (job.jp_permenddat >= '$today_date" . " 00:00:00' OR job.jp_permenddat IS NULL OR job.jp_permenddat = '00.00.0000 00:00:00')" .
" ORDER BY job.jb_id";
writeLog_("../log/check_jb_permanent_standing_", "Querying for finished jobs to be continued [$sqlquery]");
$res = $db->query($sqlquery);
if (DB::isError($res))
myDie ("$PHP_SELF: '$sqlquery' : " . $res->getMessage());
while ($row = $res->fetch_assoc())
{
if ($row["jb_id"] != "")
{
// writeCmd($row["jb_id"]);
// $jobList = array();
copy_job($row["jb_id"], $row["jb_finishtime"]);
// Aufruf des Batch
// $ausgabe = system("..\jobs\check_jb_permanent.cmd " . $row["jb_id"] . " " . $row["jb_finishtime"] . " >>..\log\check_jb_permanent.stdout", $result);
// echo "Result:", $result;
// echo "Ausgabe:", $ausgabe;
}
}
// Weitere Funktion:
// Wenn zwischenzeitlich Kommissionsnummern eingetragen wurden, dann werden diese
// vom PDAServer nicht im Rechnungstext eingetragen. Es muss also (einmal am Tag)
// der Rechnungstext aller eledigten Aufträge neu erzeugt werden!
// Das wird der Einfachheit halber gleich hier eledigt.
$today = getdate();
$now = $today['year'] . "-" . sprintf("%02d", $today['mon']) . "-" . sprintf("%02d", $today['mday']) . " " .
sprintf("%02d", $today['hours']) . ":" . sprintf("%02d", $today['minutes'] . ":" . sprintf("%02d", $today['seconds']));
$jb_finishtime_today = $today['year'] . "-" . sprintf("%02d", $today['mon']) . "-" . sprintf("%02d", $today['mday']) . " 00:00:01";
if ($jb_finishtime_today > $jb_finishtime_start && $jb_finishtime_today < $now):
// Alle Aufträge seit dem letzten Mal finden, die erledigt sind
$sqlquery = "SELECT job.jb_id, job.jb_finishtime FROM job WHERE ((jb_storno != 3 AND jb_storno != 4) OR jb_storno IS NULL) " .
" AND job.jb_status = 2 AND (jb_finishtime BETWEEN '$jb_finishtime_start' AND '$jb_finishtime_today') ORDER BY job.jb_id";
writeLog_("../log/check_jb_permanent_invtext_", "Querying for finished jobs to rebuild `jb_invtext` [$sqlquery]");
$res = $db->query($sqlquery);
if (DB::isError($res))
myDie ("$PHP_SELF: '$sqlquery' : " . $res->getMessage());
while ($row = $res->fetch_assoc())
{
if ($row["jb_id"] != "")
{
writeLog_("../log/check_jb_permanent_invtext_", "Writing new invoice text in job " . $row["jb_id"] . " (jb_finishtime: '". $row["jb_finishtime"] . "', \$jb_finishtime_start: '$jb_finishtime_start', \$jb_finishtime_today = '$jb_finishtime_today')");
mk_jb_invtext($row["jb_id"], true);
$dummy = $db->query("UPDATE job SET jb_freetext_2 = '' WHERE jb_id = " . $row["jb_id"]);
}
}
$jb_finishtime_start = $jb_finishtime_today;
endif;
// Noch eine weitere Funktion:
// Javascript-Arrays mit selten veränderlichen Variablen werden in eine extra .js-Datei geschrieben, die
// mind. einmal am Tag upgedatet werden sollte
include("../jobs/job_options.js.inc.php");
sleep(500);
endwhile; // Endless loop
} else {
// JB_ID angegeben -> expliziter Aufruf
// Nur den angegebenen Auftrag verarzten
$jobList = array();
copy_job($jb_id, $jb_finishtime);
}
function copy_job($jb_id, $jb_finishtime)
{
global $db, $hq_id, $jobList;
$tmpJobList = array();
$tmpJobListJoin = array();
// writeLog_("../log/check_jb_permanent_standing_", "Duplicating job " . $jb_id . ", finishtime " . $jb_finishtime);
// echo $jb_id . "
\n";
for ($i = 0; $i < 6; $i++):
$tmpJobList[$i] = array();
for ($j = 0; $j < 9; $j++)
$tmpJobList[$i][$j] = "";
$tmpJobListJoin[$i] = implode("²", $tmpJobList[$i]);
endfor;
$jobList = implode("¹", $tmpJobListJoin);
$check_jb_permanent_flag = true;
include("../jobs/get_saved_tour.php");
//echo "$jb_id, $csc_id, $vht_id, $jb_weight, $jb_ordertime, $jb_reserv, 3, $vht_id, " .
// "$cr_id_order, $jb_waitstorno, $jb_waittime, $jb_fixprice, $csc_id_payer br>\n";
//echo "'$jobList'\n";
// Ist aktueller Job ein Dauerauftrag?
if (in_array($jb_permanent, array(4, 5, 6, 7, 8, 9))
|| (in_array($jb_permanent, array(1, 2, 3)) && $jb_permanent2 != "0000000"))
{
//echo "$jb_id '$jb_permanent' br>\n";
// gültiger Dauerauftragsparameter vorhanden
// Auswertung des Dauerauftrags-Parameters:
// Neuberechnung des Reservierungsdatums (benötigen Kalenderfunktionen)
include_once("../include/calendar.inc.php");
$tempDate = array($jahr, sprintf("%d", $monat), sprintf("%d", $tag));
$tempDateMonth = array($jahr, sprintf("%d", $monat));
//echo "$jahr.$monat.$tag
";
//myDie ($jb_permanent);
writeLog_("../log/check_jb_permanent_standing_", "* Continuing: jb_id = $jb_id, jb_permanent = $jb_permanent, jb_finishtime = $jb_finishtime, jb_ordertime = $jahr-$monat-$tag $stunde:$minute:00, jb_permanent2 = $jb_permanent2, jp_permenddat = $jp_permenddat");
switch ($jb_permanent)
{
// die ersten drei Fälle werden gleich behandelt, da es hier nur auf den Wert in jb_permanent2 ankommt
case 1: // werktags
case 2: // werktags mit Samstag
case 3: // täglich
do {
$tempDate = addDaysComplete($tempDate[0], $tempDate[1], $tempDate[2], 1);
// Nummer des nächgsten Wochentages ermitteln
$dayNo = date("w", mktime(0, 0, 0, $tempDate[1], $tempDate[2], $tempDate[0]));
// Nummer umrechnen, damit mit dem Wert in jb_permanent2 verglichen werden kann
// date() : Montag = 1, Dienstag = 2, ..., Samstag = 6, Sonntag = 0
// jb_permanent2: Montag = 0, Dienstag = 1, ..., Samstag = 5, Sonntag = 6
if ($dayNo == 0):
$dayNo = 6;
else:
$dayNo -= 1;
endif;
writeLog_("../log/check_jb_permanent_standing_", " next date: " . $tempDate[0] . "-" . $tempDate[1] . "-" . $tempDate[2] . ", dayNo: $dayNo");
// Überprüfen, ob der nächste Wochentag in jb_permanent2 vorhanden ist
$jb_permanent_ok = false;
if (substr($jb_permanent2, $dayNo, 1) == "1")
$jb_permanent_ok = true;
} while (isPublicHoliday($tempDate[0], $tempDate[1], $tempDate[2]) != ""
|| !$jb_permanent_ok);
break;
case 4: // wöchentlich
$tempDate = addDaysComplete($tempDate[0], $tempDate[1], $tempDate[2], 7);
while (isPublicHoliday($tempDate[0], $tempDate[1], $tempDate[2]) != "")
$tempDate = addDaysComplete($tempDate[0], $tempDate[1], $tempDate[2], 1);
break;
case 5: // vierzehntägig
$tempDate = addDaysComplete($tempDate[0], $tempDate[1], $tempDate[2], 14);
while (isPublicHoliday($tempDate[0], $tempDate[1], $tempDate[2]) != "")
$tempDate = addDaysComplete($tempDate[0], $tempDate[1], $tempDate[2], 1);
break;
case 6: // monatlich
$tempDateMonth = addMonths($tempDateMonth[0], $tempDateMonth[1], 1);
$tempDate[0] = $tempDateMonth[0];
$tempDate[1] = $tempDateMonth[1];
if ($tempDate[2] > daysPerMonth($tempDateMonth[0], $tempDateMonth[1]))
$tempDate[2] = daysPerMonth($tempDateMonth[0], $tempDateMonth[1]);
while (isPublicHoliday($tempDate[0], $tempDate[1], $tempDate[2]) != "")
$tempDate = addDaysComplete($tempDate[0], $tempDate[1], $tempDate[2], 1);
break;
case 7: // monatlich zum Monatsende
$tempDateMonth = addMonths($tempDateMonth[0], $tempDateMonth[1], 1);
$tempDate[0] = $tempDateMonth[0];
$tempDate[1] = $tempDateMonth[1];
$tempDate[2] = daysPerMonth($tempDateMonth[0], $tempDateMonth[1]);
while (isPublicHoliday($tempDate[0], $tempDate[1], $tempDate[2]) != "")
$tempDate = addDaysComplete($tempDate[0], $tempDate[1], $tempDate[2], -1);
break;
case 8: // vierzehntätig zum Monatsende (15. und 31.)
if ($tempDate[2] < 20):
// nächster Termin ist Monatsende desselben Monats
// wie monatlich zum Monatsende
$tempDate[0] = $tempDateMonth[0];
$tempDate[1] = $tempDateMonth[1];
$tempDate[2] = daysPerMonth($tempDateMonth[0], $tempDateMonth[1]);
while (isPublicHoliday($tempDate[0], $tempDate[1], $tempDate[2]) != "")
$tempDate = addDaysComplete($tempDate[0], $tempDate[1], $tempDate[2], -1);
break;
else:
// nächster Termin ist der 15. des nächsten Monats
$tempDateMonth = addMonths($tempDateMonth[0], $tempDateMonth[1], 1);
$tempDate[0] = $tempDateMonth[0];
$tempDate[1] = $tempDateMonth[1];
$tempDate[2] = 15;
while (isPublicHoliday($tempDate[0], $tempDate[1], $tempDate[2]) != "")
$tempDate = addDaysComplete($tempDate[0], $tempDate[1], $tempDate[2], -1);
break;
endif;
// case 9: // quartalsweise
// do
// $tempDateMonth = addMonths($tempDateMonth[0], $tempDateMonth[1], 3);
// while (isPublicHoliday($tempDateMonth[0], $tempDateMonth[1], $tempDate[2]) != "");
// $tempDate[0] = $tempDateMonth[0];
// $tempDate[1] = $tempDateMonth[1];
// break;
// case 10: // halbjährlich
// do
// $tempDateMonth = addMonths($tempDateMonth[0], $tempDateMonth[1], 6);
// while (isPublicHoliday($tempDateMonth[0], $tempDateMonth[1], $tempDate[2]) != "");
// $tempDate[0] = $tempDateMonth[0];
// $tempDate[1] = $tempDateMonth[1];
// break;
// case 11: // jährlich
// do
// $tempDateMonth = addMonths($tempDateMonth[0], $tempDateMonth[1], 12);
// while (isPublicHoliday($tempDateMonth[0], $tempDateMonth[1], $tempDate[2]) != "");
// $tempDate[0] = $tempDateMonth[0];
// $tempDate[1] = $tempDateMonth[1];
}
$jb_ordertime_old = "";
// Alten Tag, Monat, Jahr für log_file speichern
// Überprüfen, ob der Dauerauftrag nicht schon an seinem Enddatum angekomen ist!
list($endejahr, $endemonat, $endetag, $dummy1, $dummy2) = getValsFromDate($jp_permenddat);
if (mktime(0, 0, 0, $tempDate[1], $tempDate[2], $tempDate[0])
< mktime(0, 0, 0, $endemonat, $endetag, $endejahr) || trim($jp_permenddat) == "") {
$jobListOri = $jobList;
$jahr = $tempDate[0]; // ermittelten Tag, Monat, Jahr setzen
$monat = sprintf("%02d", $tempDate[1]);
$tag = sprintf("%02d", $tempDate[2]);
$cr_id_order = $cr_id_permanent; // Kurier löschen bzw. usrsprünglichen Wunschkurier wieder einstellen
// jb_status wird daher = 9 gesetzt (kein Kurier eingetragen)
//echo "$jahr.$monat.$tag
";
// jetzt wird das Senden eines jobs mit dem neuen Datum "simuliert",
// woraufhin der Auftrag neu gespeichert wird
$toursubmit = "Senden"; // Senden simulieren
$csc_id_orderer = '0'; // Zentralenmodus
// $hq_id = 1; // Hansetrans
$getPriceOnly = 0; // Keine Nur-Preisabfrage
$jb_id_copy = $jb_id;
$jb_id = ""; // jetzt neuer Auftrag
// Als emp_id (eingebender Mitarbeiter) wird 0 eingetragen,
// da niemand angemeldet ist
// $jb_globaljob = 0; // darf natürlich niemals an alle Kuriere gehen!!!
$jb_status_manual = 0;
if (MASK_MANUAL_DISPOSITION == "1"):
$jb_status_manual = 1;
endif;
include("../jobs/job_options.php");
$jb_tourname = getFieldValueFromId("job", "jb_id", $jb_id_copy, "jb_tourname");
updateStmt("job", "jb_id", $jb_id_copy, array("jb_id_copy", $jb_id, "jb_id_copy_permanent", $jb_id, "jb_tourname", NULL));
updateStmt("job", "jb_id", $jb_id, array("cr_id_permanent", $cr_id_permanent, "jb_tourname", $jb_tourname));
if ($cr_id_permanent != "" && $cr_id_permanent != 0)
updateStmt("job", "jb_id", $jb_id, array("cr_sid", $cr_id_permanent));
// überprüfen, ob sich die tx_id nicht zwischenzeitlich geändert hat...
$cmp_tx_id = $db->getOne("SELECT cmp.tx_id FROM company AS cmp, customer AS cs WHERE cs.hq_id = '$hq_id' AND cmp.cmp_id = cs.cmp_id AND cs.cs_id = $csc_id_payer");
if ($cmp_tx_id > 0):
//echo "SELECT cmp.tx_id FROM company AS cmp, customer AS cs WHERE cs.hq_id = '$hq_id' AND cmp.cmp_id = cs.cmp_id AND cs.cs_id = $csc_id_payer";
//echo "csc_id_payer: '$csc_id_payer'";
//echo "cmp_tx_id: '$cmp_tx_id'";
//echo "jb_sales_tax_rate: " . $db->getOne("SELECT tx_value FROM tax WHERE tx_id = '$cmp_tx_id'");
//echo "jb_sales_tax_rate_sign: " . $db->getOne("SELECT tx_sign FROM tax WHERE tx_id = '$cmp_tx_id'");
updateStmt("job", "jb_id", $jb_id,
array("jb_sales_tax_rate", $db->getOne("SELECT tx_value FROM tax WHERE tx_id = '$cmp_tx_id'"),
"jb_sales_tax_rate_sign", $db->getOne("SELECT tx_sign FROM tax WHERE tx_id = '$cmp_tx_id'")));
endif;
writeLog_("../log/check_jb_permanent_standing_", "Continuation: jb_id = $jb_id, jb_permanent = $jb_permanent, jb_ordertime = $jb_ordertime, jb_permanent2 = $jb_permanent2, jp_permenddat = $jp_permenddat: $statusMessageTxt");
} else {
writeLog_("../log/check_jb_permanent_standing_", "NO CONTINUATION (finishdate reached): jb_id = $jb_id, jb_permanent = $jb_permanent, jb_permanent2 = $jb_permanent2, jp_permenddat = $jp_permenddat, jb_ordertime = $jb_ordertime: $statusMessageTxt");
}
}
}
//function delCmd() {
// $fileHandle = @fopen("../log/call_check_jb_permanent.cmd", 'w');
// @fclose($fileHandle);
// return;
//}
//function writeCmd($jb_id) {
// $fileHandle = @fopen("../log/call_check_jb_permanent.cmd", 'a');
// @fwrite($fileHandle, "call check_jb_permanent.cmd " . $jb_id . "\n");
// @fclose($fileHandle);
// return;
//}
function isPublicHoliday($year, $month, $day)
{
global $ph;
for ($i = 0; $i < count($ph); $i++):
if ($ph[$i][0] == $year && $ph[$i][1] == $month && $ph[$i][2] == $day):
writeLog_("../log/check_jb_permanent_standing_", " isPublicHoliday($year, $month, $day) = true");
return true;
endif;
endfor;
writeLog_("../log/check_jb_permanent_standing_", " isPublicHoliday($year, $month, $day) = false");
return false;
}
// Funktion wird in get_saved_tour.php benötigt
function setJobList($tourNo, $fldNo, $newVal)
{
global $jobList;
//echo "$tourNo, $fldNo, $newVal
\n";
$tmpJobListJoin = explode("¹", $jobList);
$tmpJobList = explode("²", $tmpJobListJoin[$tourNo - 1]);
$tmpJobList[$fldNo] = $newVal;
$tmpJobListJoin[$tourNo - 1] = implode("²", $tmpJobList);
$jobList = implode("¹", $tmpJobListJoin);
}
?>