----\n"; // Init // ********************************************************** // * FUNCTIONS FOR ASSOCIATED FAKE COURIERS TO THE VEHICLES * // ********************************************************** function insertAssociatedVehicleCourier ($crId, $crSid) { global $db, $PHP_SELF, $hq_id; $retVal = ""; if ($crId != "" && $crSid != "") : $xCmpId = getFieldValueFromId("courier", "cr_id", $crId, "cmp_id"); $xAdId = getFieldValueFromId("company", "cmp_id", $xCmpId, "ad_id"); $xCmpHsno = getFieldValueFromId("company", "cmp_id", $xCmpId, "cmp_hsno"); $xCrEid = "INT_" . $crSid; $xCmpComp = "Fahrzeug " . $crSid; $xUsrAccount = "int_" . $crSid; $xUsrPassword = "jdzu2ebf5dh8"; $xUsrName = "INT_" . $crSid; $xUsrFirstname = $crSid; $currentTime = getDateTime("0"); // Insert user $sqlStmtPwd = "INSERT INTO user (hq_id,usr_type,usr_name,usr_firstname,usr_account,usr_password,usr_password_modify) VALUES ($hq_id,'3','$xUsrName','$xUsrFirstname','$xUsrAccount',PASSWORD('$xUsrPassword'),'$currentTime')"; $res = $db->query($sqlStmtPwd); if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif; $xUsrIdNew = getLastInsertID(); // Insert company insertStmt("company", array("cmp_comp", $xCmpComp, "cmp_comp2", "", "ad_id", $xAdId, "cmp_hsno", $xCmpHsno, "cmp_tax_idno", "0", "cmp_stax_idno", "0", "cmp_authenticated", "1", "cmp_visible", "0", "cmp_visible_internal", "1", "cmp_newsletter", "0", "cmp_new_date", $currentTime, "cmp_modify_status", "0")); $xCmpIdNew = getLastInsertId(); // Insert courier $vhtIdInv = getVhtId("7", "truck_01"); insertStmt("courier", array("cmp_id", $xCmpIdNew, "hq_id", $hq_id, "usr_id", $xUsrIdNew, "cr_sid", $crSid, "cr_eid", $xCrEid, "vht_id_inv", $vhtIdInv, "cr_available", "1", "cr_id_parent", $crId, "cr_imei", "", "cr_mobile_pda", "0")); $xCrIdNew = getLastInsertId(); $retVal = $xCrIdNew; endif; return $retVal; } function updateAssociatedVehicleCourier ($crSid, $crSidOld) { global $hq_id; $retVal = ""; if ($crSid != "" && $crSidOld != "") : $xCrId = getFieldValueFromId("courier", "cr_sid", $crSidOld, "cr_id"); // Get associated fake courier $xCmpId = getFieldValueFromId("courier", "cr_id", $xCrId, "cmp_id"); $xUsrId = getFieldValueFromId("courier", "cr_id", $xCrId, "usr_id"); $xCrEid = "INT_" . $crSid; $xCmpComp = "Fahrzeug " . $crSid; $xUsrAccount = "int_" . $crSid; $xUsrName = "INT_" . $crSid; $xUsrFirstname = $crSid; // Update user, company, courier updateStmt("user","usr_id",$xUsrId,array("usr_name",$xUsrName,"usr_firstname",$xUsrFirstname,"usr_account",$xUsrAccount)); updateStmt("company","cmp_id",$xCmpId,array("cmp_comp",$xCmpComp)); updateStmt("courier","cr_id",$xCrId,array("cr_eid",$xCrEid,"cr_sid",$crSid)); $retVal = $xCrId; endif; return $retVal; } function removeAssociatedVehicleCourier ($crSid) { global $hq_id; $retVal = ""; if ($crSid != "") : $xCrId = getFieldValueFromId("courier", "cr_sid", $crSid, "cr_id"); // Get associated fake courier $xCmpId = getFieldValueFromId("courier", "cr_id", $xCrId, "cmp_id"); $xUsrId = getFieldValueFromId("courier", "cr_id", $xCrId, "usr_id"); // Check existence of reference(s) in job $numOfJobs = getCountOfTable("job", "cr_id = '" . $xCrId . "'"); if ($numOfJobs <= 0) : deleteStmt("courierdatatransfer","cr_id = ".$xCrId); deleteStmt("customercourier","cr_id = ".$xCrId); deleteStmt("user","usr_id = ".$xUsrId . " AND hq_id = '" . $hq_id . "'"); deleteStmt("company","cmp_id = ".$companyId); updateStmt("courier","cr_id_parent",$xCrId,array("cr_id_parent","")); deleteStmt("courier","cr_id = ".$xCrId . " AND hq_id = '" . $hq_id . "'"); endif; endif; return $retVal; } // ********************************************************** // ************************************** // * Operations for the couriervehicles * // ************************************** // Generate log string if ($f_act != "") : // In case of modifying without special right(s) init some fields with existing value(s) if ($f_act == "modifyCourierVehicle" && $courierId != "" && $crHqId != "" && $f_crvh_id != "") : if (!$crvhRgtRule02) : $f_crvh_partner_premium = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_partner_premium"); $f_crvh_partner_text = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_partner_text"); $f_crvh_partner_commission = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_partner_commission"); endif; if (!$crvhRgtRule01) : $f_crvh_advertising_allowance = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_advertising_allowance"); $f_crvh_transport_insurance_amount = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_transport_insurance_amount"); $f_crvh_business_liability_insurance_amount = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_business_liability_insurance_amount"); $f_crvh_business_liability_insurance_date = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_business_liability_insurance_date"); $f_crvh_system_fee_amount = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_system_fee_amount"); $f_crvh_transport_insurance_date = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_transport_insurance_date"); endif; endif; $logArr = array($f_vht_id,$f_crvh_comm_no,$f_crvh_vh_sign,$f_crvh_vh_name,$f_crvh_licence_date,$f_crvh_owner, $f_crvh_env_badge_level,$f_crvh_prov,$f_crvh_payload,$f_crvh_totalweight, $f_crvh_length,$f_crvh_width,$f_crvh_height,$f_crvh_position,$f_crvh_mobile, $f_crvh_insurance_name,$f_crvh_insurance_no,$f_crvh_special,$f_crvh_remark,$f_crvh_freetext_1, $f_crvh_corporate_identity,$f_crvh_funding_state,$f_crvh_funding_final_installment, $f_crvh_funding_residual_value,$f_crvh_aperture_height_side,$f_crvh_aperture_height_rear, $f_crvh_vhd_disabled,$f_crvh_id_inv,$f_crvh_pda_usage,$f_crvh_system_fee,$f_crvh_drivetype, $f_crvh_cr_eid_new,$f_crvh_sid_new,$f_crvh_comm_no_new, $f_crvh_partner_premium,$f_crvh_partner_commission,$f_crvh_advertising_allowance,$f_crvh_transport_insurance_amount, $f_crvh_business_liability_insurance_amount,$f_crvh_business_liability_insurance_date,$f_crvh_system_fee_amount, $f_crvh_partner_text,$f_crvh_transport_insurance_date); $logString = makeLogString($logArr, ";", "0"); endif; // Copy couriervehicle if ($f_act == "copyCourierVehicle") : if ($f_crvh_cr_eid_new != "" && $f_crvh_sid_new != "" && $f_crvh_comm_no_new != "") : // Get courier ID of the existing courier to be associated $courierId = getFieldValueFromId("courier","cr_eid",$f_crvh_cr_eid_new,"cr_id"); if ($courierId != "" && is_numeric($courierId) && $courierId > "0") : $f_crvh_sid = $f_crvh_sid_new; $f_crvh_comm_no = $f_crvh_comm_no_new; $crHqId = getFieldValueFromId("courier","cr_id",$courierId,"hq_id"); $f_act = "newCourierVehicle"; // $statusMessage = getLngt("Nach erfolgreicher Fahrzeuganlage wird das neue Fahrzeugstanmmblatt angezeigt!"); else : $statusMessage = getLngt("Der Transporteursdatensatz für die Zuweisung des kopierten Fahrzeugs existiert nicht!"); endif; else : $statusMessage = getLngt("Die erfassten Daten für die Datensatzkopie des Fahrzeug sind nicht vollständig!"); endif; endif; // Insert new couriervehicle if ($f_act == "newCourierVehicle" && $courierId != "" && $crHqId != "") : if ($f_crvh_sid != "" && $f_vht_id != "" && $f_crvh_vh_sign != "" && $f_crvh_comm_no != "" && $f_crvh_licence_date_month != "" && $f_crvh_licence_date_year != "" && ($parMaskMandatoryFieldTotalweight == "0" || ($f_crvh_totalweight != "" && is_numeric($f_crvh_totalweight) && $f_crvh_totalweight > 0))) : // if ($db->getOne("SELECT crvh_sid FROM couriervehicle WHERE crvh_sid = '" . $f_crvh_sid . "'")) : // $statusMessage = "Die systemweit eindeutige Kuriernummer ist bereits vergeben! Bitte wählen Sie eine andere"; // Check for existence of the unique SID $sqlquery = "SELECT crvh.crvh_sid FROM couriervehicle AS crvh, courier AS cr" . " WHERE crvh.crvh_sid = '" . $f_crvh_sid . "' AND" . " cr.cr_id = crvh.cr_id AND" . " cr.hq_id = '" . $crHqId . "'"; if ($db->getOne($sqlquery)) : $statusMessage = getLngt("Die eindeutige Fahrzeugnummer (SID) ist bereits vergeben! Bitte wählen Sie eine andere"); else : // Check for existence of the unique commission number $sqlquery = "SELECT crvh.crvh_comm_no FROM couriervehicle AS crvh, courier AS cr" . " WHERE crvh.crvh_comm_no = '" . $f_crvh_comm_no . "' AND" . " cr.cr_id = crvh.cr_id AND" . " cr.hq_id = '" . $crHqId . "'"; if ($db->getOne($sqlquery)) : $statusMessage = getLngt("Die eindeutige Kommissionsnummer ist bereits vergeben! Bitte wählen Sie eine andere"); else : TA("B"); $currentTime = getDateTime("0"); // Insert couriervehicle $f_crvh_prov = str_replace (",", ".", $f_crvh_prov); $f_crvh_funding_residual_value = str_replace (",", ".", $f_crvh_funding_residual_value); insertStmt("couriervehicle", array("vht_id",$f_vht_id, "cr_id", $courierId, "crvh_id_inv", $f_crvh_id_inv, "crvh_sort", $f_crvh_sort, "crvh_sid", $f_crvh_sid, "crvh_comm_no", $f_crvh_comm_no, "crvh_vh_sign", $f_crvh_vh_sign, "crvh_vh_name", $f_crvh_vh_name, "crvh_licence_date", $f_crvh_licence_date, "crvh_owner", $f_crvh_owner, "crvh_env_badge_level", $f_crvh_env_badge_level, "crvh_prov", $f_crvh_prov, "crvh_payload", $f_crvh_payload, "crvh_totalweight", $f_crvh_totalweight, "crvh_length", $f_crvh_length, "crvh_width", $f_crvh_width, "crvh_height", $f_crvh_height, "crvh_position", $f_crvh_position, "crvh_aperture_height_side", $f_crvh_aperture_height_side, "crvh_aperture_height_rear", $f_crvh_aperture_height_rear, "crvh_mobile", $f_crvh_mobile, "crvh_insurance_name", $f_crvh_insurance_name, "crvh_insurance_no", $f_crvh_insurance_no, "crvh_filter ", $f_crvh_filter2, "crvh_service", $f_crvh_service2, "crvh_group", "", "crvh_special", $f_crvh_special, "crvh_vhd_disabled", $f_crvh_vhd_disabled, "crvh_corporate_identity", $f_crvh_corporate_identity, "crvh_funding_state", $f_crvh_funding_state, "crvh_funding_final_installment", $f_crvh_funding_final_installment, "crvh_funding_residual_value", $f_crvh_funding_residual_value, "crvh_pda_usage", $f_crvh_pda_usage, "crvh_system_fee", $f_crvh_system_fee, "crvh_drivetype", $f_crvh_drivetype, "crvh_remark ", $f_crvh_remark, "crvh_freetext_1", $f_crvh_freetext_1, "crvh_partner_premium", "0", "crvh_partner_text", "", "crvh_partner_commission", "0", "crvh_advertising_allowance", "0", "crvh_system_fee_amount", "0", "crvh_transport_insurance_amount", "0", "crvh_transport_insurance_date", "0000-00-00", "crvh_business_liability_insurance_amount", "0", "crvh_business_liability_insurance_date", "0000-00-00", "crvh_modify_status", "1", "crvh_modify", $currentTime)); $f_crvh_id = getLastInsertID(); if ($crvhRgtRule01) : $f_crvh_advertising_allowance = str_replace(",", ".", $f_crvh_advertising_allowance); $f_crvh_transport_insurance_amount = str_replace(",", ".", $f_crvh_transport_insurance_amount); $f_crvh_business_liability_insurance_amount = str_replace(",", ".", $f_crvh_business_liability_insurance_amount); $f_crvh_system_fee_amount = str_replace(",", ".", $f_crvh_system_fee_amount); // Insert new values per update $crvhRgtRule01Fields = array("crvh_advertising_allowance", $f_crvh_advertising_allowance, "crvh_system_fee_amount", $f_crvh_system_fee_amount, "crvh_transport_insurance_amount", $f_crvh_transport_insurance_amount, "crvh_transport_insurance_date", $f_crvh_transport_insurance_date, "crvh_business_liability_insurance_amount", $f_crvh_business_liability_insurance_amount, "crvh_business_liability_insurance_date", $f_crvh_business_liability_insurance_date); updateStmt("couriervehicle","crvh_id",$f_crvh_id,$crvhRgtRule01Fields); endif; if ($crvhRgtRule02) : $f_crvh_partner_premium = str_replace(",", ".", $f_crvh_partner_premium); $f_crvh_partner_text = trim($f_crvh_partner_text); $f_crvh_partner_commission = str_replace(",", ".", $f_crvh_partner_commission); $crvhRgtRule02Fields = array("crvh_partner_premium", $f_crvh_partner_premium, "crvh_partner_text", $f_crvh_partner_text, "crvh_partner_commission", $f_crvh_partner_commission); updateStmt("couriervehicle","crvh_id",$f_crvh_id,$crvhRgtRule02Fields); endif; // Write logdata into log database writeToLogDB("85",$hq_id,"",$usr_id,$courierId,$f_crvh_sid,"","OBJ_TYPE=CRVH|STATUS_NEW=" . $logString . "|FILTER=" . $f_crvh_filter2 . "|SERVICES=" . $f_crvh_service2); // Write into "servicepricehistory" insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_partner_commission", "srvprch_context", "", "srvprch_price", $f_crvh_partner_commission, "srvprch_validfrom", $currentTime)); insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_advertising_allowance", "srvprch_context", "", "srvprch_price", $f_crvh_advertising_allowance, "srvprch_validfrom", $currentTime)); insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_transport_insurance_amount", "srvprch_context", "", "srvprch_price", $f_crvh_transport_insurance_amount, "srvprch_validfrom", $currentTime)); insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_business_liability_insurance_amount", "srvprch_context", "", "srvprch_price", $f_crvh_business_liability_insurance_amount, "srvprch_validfrom", $currentTime)); insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_system_fee_amount", "srvprch_context", "", "srvprch_price", $f_crvh_system_fee_amount, "srvprch_validfrom", $currentTime)); insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_partner_premium", "srvprch_context", "", "srvprch_price", $f_crvh_partner_premium, "srvprch_validfrom", $currentTime)); // New entry in the "Fast Disposition Structure" generateVehicleFastDispositionStructure($f_crvh_id, "3"); // Remember: "vehicleavailabilitytimeunits" would not have any entry for this vehicle because there is no relation to any customer yet !!!! // * Insert "active" courier for the vehicle having "cr.cr_sid <=> crvh.crvh_sid" * if ($globalVehicleCourierRelation == "1") : insertAssociatedVehicleCourier($courierId, $f_crvh_sid); endif; if ($globalVehicleStockRelation == "1") : $opVal = objectInsertStock("crvh", $f_crvh_id, $vehicleStockIdParent, "SYSTEM-VEHICLES", getLngt("FZG") . $f_crvh_sid, $dbConnection); if ($opVal == "-1") : $statusMessage = getLngt("Es wurde kein spezielles Objekt bzw. dessen Typ spezifiziert!"); elseif ($opVal == "-2") : $statusMessage = getLngt("ACHTUNG! Es existiert kein notwendiges fahrzeugbezogenes Hauptlager! Bitte den Administrator kontaktieren!"); elseif ($opVal == "-3") : $statusMessage = getLngt("ACHTUNG! Die Anlage des Lagerortes konnte nicht durchgeführt werden! Bitte wiederholen bzw. den Administrator kontaktieren!"); endif; endif; TA("C"); TA("E"); // Reset fields of form-parameters // clearParameters($httpVisualVars); endif; endif; else : $statusMessage = getLngt("Bitte geben Sie alle mit * gekennzeichneten Felder ein!"); endif; endif; // Modify couriervehicle if ($f_act == "modifyCourierVehicle" && $courierId != "" && $crHqId != "") : if ($f_crvh_id != "" && $f_vht_id != "" && $f_crvh_sid != "" && $f_crvh_vh_sign != "" && $f_crvh_comm_no != "" && $f_crvh_licence_date_month != "" && $f_crvh_licence_date_year != "" && ($parMaskMandatoryFieldTotalweight == "0" || ($f_crvh_totalweight != "" && is_numeric($f_crvh_totalweight) && $f_crvh_totalweight > 0))) : // Check for existence of the unique SID (except the current row to be modified) $sqlquery = "SELECT crvh.crvh_sid FROM couriervehicle AS crvh, courier AS cr" . " WHERE crvh.crvh_sid = '" . $f_crvh_sid . "' AND" . " NOT (crvh_id = '" . $f_crvh_id . "') AND " . " cr.cr_id = crvh.cr_id AND" . " cr.hq_id = '" . $crHqId . "'"; if ($db->getOne($sqlquery)) : $statusMessage = getLngt("Die eindeutige Fahrzeugnummer (SID) ist bereits vergeben! Bitte wählen Sie eine andere"); else : // Check for existence of the unique commission number $sqlquery = "SELECT crvh.crvh_comm_no FROM couriervehicle AS crvh, courier AS cr" . " WHERE crvh.crvh_comm_no = '" . $f_crvh_comm_no . "' AND" . " NOT (crvh_id = '" . $f_crvh_id . "') AND " . " cr.cr_id = crvh.cr_id AND" . " cr.hq_id = '" . $crHqId . "'"; if ($db->getOne($sqlquery)) : $statusMessage = getLngt("Die eindeutige Kommissionsnummer ist bereits vergeben! Bitte wählen Sie eine andere"); else : TA("B"); $currentTime = getDateTime("0"); // Get existing (old) "crvh_sid" to compare with new SID, in case of generating a fake courier only $crvhSidCurrent = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_sid"); // Get current specific data (payload, positions, etc.) of the vehicle before update $crvhFieldsCurrent = getFieldsValueFromId("couriervehicle", "crvh_id", $f_crvh_id, array("crvh_payload","crvh_position")); // Get current price values $crvhPriceFieldsCurrent = getFieldsValueFromId("couriervehicle", "crvh_id", $f_crvh_id, array("crvh_partner_commission","crvh_advertising_allowance","crvh_transport_insurance_amount","crvh_business_liability_insurance_amount","crvh_system_fee_amount","crvh_partner_premium")); // Update couriervehicle $f_crvh_prov = str_replace (",", ".", $f_crvh_prov); $f_crvh_funding_residual_value = str_replace (",", ".", $f_crvh_funding_residual_value); $defaultFields = array("vht_id",$f_vht_id, "cr_id", $courierId, "crvh_id_inv", $f_crvh_id_inv, "crvh_sort", $f_crvh_sort, "crvh_sid", $f_crvh_sid, "crvh_comm_no", $f_crvh_comm_no, "crvh_vh_sign", $f_crvh_vh_sign, "crvh_vh_name", $f_crvh_vh_name, "crvh_licence_date", $f_crvh_licence_date, "crvh_owner", $f_crvh_owner, "crvh_env_badge_level", $f_crvh_env_badge_level, "crvh_prov", $f_crvh_prov, "crvh_payload", $f_crvh_payload, "crvh_totalweight", $f_crvh_totalweight, "crvh_length", $f_crvh_length, "crvh_width", $f_crvh_width, "crvh_height", $f_crvh_height, "crvh_position", $f_crvh_position, "crvh_aperture_height_side", $f_crvh_aperture_height_side, "crvh_aperture_height_rear", $f_crvh_aperture_height_rear, "crvh_mobile", $f_crvh_mobile, "crvh_insurance_name", $f_crvh_insurance_name, "crvh_insurance_no", $f_crvh_insurance_no, "crvh_filter ", $f_crvh_filter2, "crvh_service", $f_crvh_service2, "crvh_corporate_identity", $f_crvh_corporate_identity, "crvh_funding_state", $f_crvh_funding_state, "crvh_funding_final_installment", $f_crvh_funding_final_installment, "crvh_funding_residual_value", $f_crvh_funding_residual_value, "crvh_special", $f_crvh_special, "crvh_vhd_disabled", $f_crvh_vhd_disabled, "crvh_pda_usage", $f_crvh_pda_usage, "crvh_system_fee", $f_crvh_system_fee, "crvh_drivetype", $f_crvh_drivetype, "crvh_remark ", $f_crvh_remark, "crvh_freetext_1", $f_crvh_freetext_1, "crvh_modify_status", "2", "crvh_modify", $currentTime); if ($crvhRgtRule01) : $f_crvh_advertising_allowance = str_replace (",", ".", $f_crvh_advertising_allowance); $f_crvh_transport_insurance_amount = str_replace (",", ".", $f_crvh_transport_insurance_amount); $f_crvh_business_liability_insurance_amount = str_replace (",", ".", $f_crvh_business_liability_insurance_amount); $f_crvh_system_fee_amount = str_replace (",", ".", $f_crvh_system_fee_amount); $crvhRgtRule01Fields = array("crvh_advertising_allowance", $f_crvh_advertising_allowance, "crvh_system_fee_amount", $f_crvh_system_fee_amount, "crvh_transport_insurance_amount", $f_crvh_transport_insurance_amount, "crvh_transport_insurance_date", $f_crvh_transport_insurance_date, "crvh_business_liability_insurance_amount", $f_crvh_business_liability_insurance_amount, "crvh_business_liability_insurance_date", $f_crvh_business_liability_insurance_date); $defaultFields = array_merge($defaultFields, $crvhRgtRule01Fields); endif; if ($crvhRgtRule02) : $f_crvh_partner_premium = str_replace(",", ".", $f_crvh_partner_premium); $f_crvh_partner_text = trim($f_crvh_partner_text); $f_crvh_partner_commission = str_replace (",", ".", $f_crvh_partner_commission); $crvhRgtRule02Fields = array("crvh_partner_premium", $f_crvh_partner_premium, "crvh_partner_text", $f_crvh_partner_text, "crvh_partner_commission", $f_crvh_partner_commission); $defaultFields = array_merge($defaultFields, $crvhRgtRule02Fields); endif; updateStmt("couriervehicle","crvh_id",$f_crvh_id,$defaultFields); // Update vehicletype in "courier" if it has been changed in "couriervehicle" $tmpCrSid = getFieldValueFromId("courier","cr_id",$courierId,"cr_sid"); $tmpCrVhtId = getFieldValueFromId("courier","cr_id",$courierId,"vht_id"); if ($tmpCrSid != $f_crvh_sid || $tmpCrVhtId != $f_vht_id) : updateStmt("courier","cr_id",$courierId,array("cr_sid",$f_crvh_sid,"vht_id",$f_vht_id)); endif; // Write logdata into log database writeToLogDB("86",$hq_id,"",$usr_id,$courierId,$f_crvh_sid,"","OBJ_TYPE=CRVH|STATUS_MODIFIED=" . $logString . "|FILTER=" . $f_crvh_filter2 . "|SERVICES=" . $f_crvh_service2); // Write into "servicepricehistory" if ($crvhPriceFieldsCurrent[0] != $f_crvh_partner_commission) : insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_partner_commission", "srvprch_context", "", "srvprch_price", $f_crvh_partner_commission, "srvprch_validfrom", $currentTime)); endif; if ($crvhPriceFieldsCurrent[1] != $f_crvh_advertising_allowance) : insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_advertising_allowance", "srvprch_context", "", "srvprch_price", $f_crvh_advertising_allowance, "srvprch_validfrom", $currentTime)); endif; if ($crvhPriceFieldsCurrent[2] != $f_crvh_transport_insurance_amount) : insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_transport_insurance_amount", "srvprch_context", "", "srvprch_price", $f_crvh_transport_insurance_amount, "srvprch_validfrom", $currentTime)); endif; if ($crvhPriceFieldsCurrent[3] != $f_crvh_business_liability_insurance_amount) : insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_business_liability_insurance_amount", "srvprch_context", "", "srvprch_price", $f_crvh_business_liability_insurance_amount, "srvprch_validfrom", $currentTime)); endif; if ($crvhPriceFieldsCurrent[4] != $f_crvh_system_fee_amount) : insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_system_fee_amount", "srvprch_context", "", "srvprch_price", $f_crvh_system_fee_amount, "srvprch_validfrom", $currentTime)); endif; if ($crvhPriceFieldsCurrent[5] != $f_crvh_partner_premium) : insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_partner_premium", "srvprch_context", "", "srvprch_price", $f_crvh_partner_premium, "srvprch_validfrom", $currentTime)); endif; // Update specific vehicle data (payload, positions, etc.) in the "Fast Disposition Structure" generateVehicleFastDispositionStructure($f_crvh_id, "4", "", $crvhFieldsCurrent); // Call with OLD data of the modified vehicle for checking to be updated in the FDS // * Update "active" courier for the vehicle having "cr.cr_sid <=> crvh.crvh_sid" * if ($globalVehicleCourierRelation == "1") : // In case of changing the vehicle SID only remove existing fake courier and generate a new one if ($crvhSidCurrent != "" && $f_crvh_sid != "" && $crvhSidCurrent != $f_crvh_sid) : updateAssociatedVehicleCourier($f_crvh_sid, $crvhSidCurrent); endif; endif; if ($globalVehicleStockRelation == "1") : $opVal = objectInsertStock("crvh", $f_crvh_id, $vehicleStockIdParent, "SYSTEM-VEHICLES", getLngt("FZG") . $f_crvh_sid, $dbConnection); if ($opVal == "-1") : $statusMessage = getLngt("Es wurde kein spezielles Objekt bzw. dessen Typ spezifiziert!"); elseif ($opVal == "-2") : $statusMessage = getLngt("ACHTUNG! Es existiert kein notwendiges fahrzeugbezogenes Hauptlager! Bitte den Administrator kontaktieren!"); elseif ($opVal == "-3") : $statusMessage = getLngt("ACHTUNG! Die Anlage des Lagerortes konnte nicht durchgeführt werden! Bitte wiederholen bzw. den Administrator kontaktieren!"); endif; endif; TA("C"); TA("E"); endif; endif; else : $statusMessage = getLngt("Bitte geben Sie alle mit * gekennzeichneten Felder ein!"); endif; endif; // Remove couriervehicle if ($f_act == "removeCourierVehicle" && $courierId != "" && $f_crvh_id != "") : TA("B"); $doRemove = true; if ($globalVehicleCourierRelation == "1") : $doRemove = false; // The vehicle will adapt the role of the courier having a vehicle statistic like a courier statistic. Therefore do NOT remove the vehicle if at least one job does exist !!!! $statusMessage = getLngt("Das Fahrzeug darf wg. der Statistik nicht gelöscht werden! Bitte vergeben Sie z.B. eine andere SID!"); $xCrSid = getFieldValueFromId("couriervehicle", "crvh_id", $f_crvh_id, "crvh_sid"); $xCrId = getFieldValueFromId("courier", "cr_sid", $xCrSid, "cr_id"); // Get associated fake courier // Check existence of reference(s) in job for the fake courier $numOfJobs = getCountOfTable("job", "cr_id = '" . $xCrId . "'"); if ($numOfJobs <= 0) : $doRemove = true; $statusMessage = ""; // * Remove "active" courier for the vehicle having "cr.cr_sid <=> crvh.crvh_sid" * removeAssociatedVehicleCourier($xCrSid); endif; endif; if ($doRemove && $globalVehicleStockRelation == "1") : if (existsEntry("stock",array("stk_obj_type","crvh","stk_obj_id",$f_crvh_id))) : // Get all (sub-)stock IDs of the vehicle to be removed $stkIdsToBeRemoved = getColVectorFromDB2ArrayByClause("stock", "stk_id", "stk_obj_type = 'crvh' AND stk_obj_id = '" . $f_crvh_id . "'"); $stkIdsToBeRemovedLen = count($stkIdsToBeRemoved); for ($i = 0; $i < $stkIdsToBeRemovedLen; $i++) : $checkDelStk = checkStockExistingStockarticle($stkIdsToBeRemoved[$i]); if ($checkDelStk) : $doRemove = false; $statusMessage = getLngt("Die Löschung des Fahrzeugs kann nicht durchgeführt werden wegen Beziehungen zu mindestens einem Lagerort! Bitte die Lagerorte bereinigen!"); break; endif; endfor; endif; endif; if ($doRemove) : if ($globalVehicleStockRelation == "1") : // Remove all (sub-)stock IDs of the vehicle for ($i = 0; $i < $stkIdsToBeRemovedLen; $i++) : $opDelStk = deleteStock($stkIdsToBeRemoved[$i]); if ($opDelStk == "" || $opDelStk == "0"): $statusMessage = getLngt("ACHTUNG! Fehler beim Löschvorgang! Bitte den Administrator kontaktieren!"); die(); // The following delete statements may not be executed! endif; endfor; endif; // delete couriervehicle // deleteStmt("couriervehicle", "crvh_id = '$f_crvh_id' AND cr_id = '$courierId'"); // Remove associations to customers deleteStmt("customervehicle", "crvh_id = '$f_crvh_id'"); // On this place only virtual removement // Physical removement follows after export updateStmt("couriervehicle","crvh_id",$f_crvh_id,array("crvh_modify_status","3"),"cr_id = '$courierId'"); // Get crvh_sid from vehicle to be removed $crvhSid = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_sid"); // Remove all cr_sid entries where courier matches the vehicle to be removed updateStmt("courier","cr_sid",$crvhSid,array("cr_sid","")); // Remove vehicle from the "Fast Disposition Structure" generateVehicleFastDispositionStructure($f_crvh_id, "1"); // Write logdata into log database writeToLogDB("125",$hq_id,"",$usr_id,$courierId,$crvhSid,"",""); // Reset fields of form-parameters clearParameters($httpVisualVars); else : // In case of associated fake courier only if ($statusMessage == "") : $statusMessage = getLngt("Das Fahrzeug darf wg. der Statistik nicht gelöscht werden! Bitte vergeben Sie z.B. eine andere SID!"); endif; endif; TA("C"); TA("E"); endif; // Associate vehicle to the selected courier of the same contractor if ($f_act == "associateVehicleToNewCourierOfTheSameContractor" && $f_crvh_id != "" && $f_cr_id_same_contractor != "") : TA("B"); // Remove all cr_sid entries where old courier matches the vehicle to be removed $tmpCrSid = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_sid"); updateStmt("courier","cr_sid",$tmpCrSid,array("cr_sid","")); // Move relation updateStmt("couriervehicle","crvh_id",$f_crvh_id,array("cr_id", $f_cr_id_same_contractor)); // Write logdata into log database writeToLogDB("186",$hq_id,"",$usr_id,$f_cr_id_same_contractor,$tmpCrSid,"",""); TA("C"); TA("E"); endif; // ****************************************************************** // * Selection of the courier data for the current headquarter only * // ****************************************************************** if ($courierId != "" && $crHqId != "") : // Get the vehicles of a specified courier for selection // IMPORTANT: No virtual removed rows (=> clause crvh.crvh_modify_status != '3') $crvhList = getVehicleList("crvh.cr_id = '" . $courierId . "' AND cr.hq_id = '" . $crHqId . "' AND crvh.crvh_modify_status != '3'"); // Get the data of one special vehicle of a specified courier if ($f_crvh_id != "") : // Get (global) vehicle data of the specified vehicle getVehicle($f_crvh_id, "crvh.cr_id = '" . $courierId . "' AND cr.hq_id = '" . $crHqId . "'"); // Transport insurance date if ($f_crvh_transport_insurance_date != "" && $f_crvh_transport_insurance_date != "0000-00-00") : $f_crvh_transport_insurance_date_year = substr($f_crvh_transport_insurance_date,0,4); $f_crvh_transport_insurance_date_month = substr($f_crvh_transport_insurance_date,5,2); $f_crvh_transport_insurance_date_day = substr($f_crvh_transport_insurance_date,8,2); endif; // Business liability insurance date if ($f_crvh_business_liability_insurance_date != "" && $f_crvh_business_liability_insurance_date != "0000-00-00") : $f_crvh_business_liability_insurance_date_year = substr($f_crvh_business_liability_insurance_date,0,4); $f_crvh_business_liability_insurance_date_month = substr($f_crvh_business_liability_insurance_date,5,2); $f_crvh_business_liability_insurance_date_day = substr($f_crvh_business_liability_insurance_date,8,2); endif; // Services associated to the vehicle if ($f_crvh_service != "") : // if (substr($f_crvh_service, 0, 1) == ",") : $f_crvh_service = substr($f_crvh_service, 1); endif; // Remove first comma // if (substr($f_crvh_service, -1) == ",") : $f_crvh_service = substr($f_crvh_service, 0, -1); endif; // Remove last comma // $f_crvh_service = spliti(",", $f_crvh_service); // Convert to an array $f_crvh_service = mcConvertNum2Sel($f_crvh_service); else : $f_crvh_service = array(); endif; $outputService = addCheckboxesFromTable("f_crvh_service","metatype","mt_sort","mt_value","mt_sort","mt_type = 'service' AND mt_objtype = '' AND mt_objid = '0' AND mt_sort != '1'",$f_crvh_service, "
"); // Get path for courier documents (type "CRVH") if ($importPath == "") : $importPath = getFieldValueFromId("mandator","md_id",$md_id,"md_doc_path"); endif; $importPath = getPathForObjectData($importPath, "CRVH"); // Get number of documents for the current customer $crvhNumOfFiles = getNumOfFilesByFilterInFolder($importPath, $f_crvh_id . "_", "1"); // Get the related drivers of the same contractor $crIdParent = getFieldValueFromId("courier", "cr_id", $courierId, "cr_id_parent"); if ($crIdParent != "" && $crIdParent > 0) : $couriersOfTheSameContractorArr = getColVectorFromDB2ArrayByClause("courier", "cr_id", "cr_id_parent = '" . $crIdParent . "' AND cr_id != '" . $courierId . "'"); $couriersOfTheSameContractorArrLen = count($couriersOfTheSameContractorArr); // Prepare display of all couriers of the same contractor if ($couriersOfTheSameContractorArrLen > 0) : for ($i = 0; $i < $couriersOfTheSameContractorArrLen; $i++) : $tmpCrOut = getFieldValueFromId("courier", "cr_id", $couriersOfTheSameContractorArr[$i], "cr_eid"); $tmpUsrId = getFieldValueFromId("courier", "cr_id", $couriersOfTheSameContractorArr[$i], "usr_id"); $tmpUsrName = ""; if ($tmpUsrId != "" && $tmpUsrId > 0) : $tmpUsrName = getFieldValueFromId("user", "usr_id", $tmpUsrId, "usr_name"); $tmpUsrFirstname = getFieldValueFromId("user", "usr_id", $tmpUsrId, "usr_firstname"); if ($tmpUsrName != "" && $tmpUsrFirstname != "") : $tmpUsrName .= ", " . $tmpUsrFirstname; endif; if ($tmpUsrName != "") : $tmpCrOut = $tmpCrOut . " - " . $tmpUsrName; endif; endif; $outputCouriersOfTheSameContractor .= "\n"; endfor; endif; endif; else : if ($f_crvh_sid == "") : $f_crvh_sid = getParameterValue("0", "CR_SID_PREFIX", $crHqId); endif; endif; // Courier filters (mandatory fields ONLY) $outputFilter = getFilters($f_crvh_filter, "0", "1", $f_vht_id, "", "0", "0"); getCurrentScript(__FILE__); // For output only $tmp_usr_id = getFieldValueFromId("courier", "cr_id", $courierId, "usr_id"); $tmpFields = getFieldsValueFromId("user","usr_id",$tmp_usr_id,array("usr_name","usr_firstname")); $tmp_usr_name = $tmpFields[0]; $tmp_usr_firstname = $tmpFields[1]; $title = $pageTitel . " " . $tmp_usr_firstname . " " . $tmp_usr_name; if ($f_crvh_sid != "") : $title .= " (" . $f_crvh_sid . ")"; else : $title .= " " . getLngt("(Neues Fahrzeug)"); endif; else : // Get all vehicles (of the current headquarters the employee is logged in!!!!) // IMPORTANT: No virtual removed rows (=> clause crvh.crvh_modify_status != '3') $crvhList = getVehicleList("cr.hq_id = '" . $hq_id . "' AND crvh.crvh_modify_status != '3'", "crvh.crvh_sid"); endif; // ************************************************************************************************* // Vehicle photo $crvhPhotoPath = ""; $crvhPhotoFilename = ""; if ($f_crvh_id != "") : $crvhPhotoFilename = $f_crvh_id . "_vehicle_photo.png"; $rootDirDefault = "../import/upload/"; $mdRootDirDefault = getFieldValueFromId("mandator","md_id",$md_id,"md_doc_path"); if ($mdRootDirDefault != "") : $rootDirDefault = $mdRootDirDefault; endif; $dirSpecialForObjType = getParameterValue("0", "DATATRANSFER_DIRECTORY_CRVH", $hq_id); if ($dirSpecialForObjType == "") : $dirSpecialForObjType = getParameterValue("0", "DATATRANSFER_DIRECTORY_CRVH", "0"); endif; // Check for headquartes if ($crHqId != "" && $dirSpecialForObjType != "") : $hqMnemonic = getFieldValueFromId("headquarters","hq_id",$crHqId,"hq_mnemonic"); if ($hqMnemonic == "") : $hqMnemonic = "MISC" ; endif; $crvhPhotoPath .= $rootDirDefault . $dirSpecialForObjType . "/" . $hqMnemonic . "/"; $crvhPhotoPath = "EMC2" . substr($crvhPhotoPath, 2); endif; endif; // ************************************************************************************************* // Prepare display of all vehicles (possibly filtered by the current selected courier) $crvhListLen = count($crvhList); $courierVehicles = "\n"; for ($i = 0; $i < $crvhListLen; $i++) : $courierVehicles .= "