<?php
/*=======================================================================
 *
 * stock.php
 *
 * Autor: Marc Vollmann
 *
 =======================================================================*/
 

include_once ("../include/mcglobal.inc.php");
include_once ("../include/auth.inc.php");
include_once ("../include/inc_dbfields2array.inc.php");


// Check HTTP-Parameters
// Stocks
getSecHttpVars("1",array("f_act", "customerId", "cscIdRoot", "cscIdCurrent", "statusMessage", "deactivateMenu",
                         "stkIdRoot", "stkIdCurrent", "deleteStock", "nameStock", "stkNameCurrent", "stkPathCurrent",
                         "stkVisibleCurrent", "f_show_invisible", "f_stk_maxquantity", "f_ad_id", "g_cs_id", "g_csc_id",
                         "day_from", "month_from", "year_from", "day_to", "month_to", "year_to", "dbhistory",
                         "stkmv_day_from", "stkmv_month_from", "stkmv_year_from",
                         "f_cscad_comp","f_cscad_comp2", "js_execute_cmd", "js_execute_data",
                         "v_adt_id", "f_ad_street", "f_stk_hsno", "f_ad_zipcode", "f_ad_city", "f_ad_country",
                         "f_noaddressvalidation", "f_stk_planning", "f_stk_barcode", "f_mv_sort_stockArticle", 
                         "f_stkat_search_at_misc", "f_stkat_search_atg", "f_at_search_atg",
                         "f_stkat_export", "f_stkmv_export", "f_mv_sort_journal",
                         "f_displayModeStockArticle", "f_journal_modeStockEntries",
                         "f_mv_stk_from", "f_mv_at", "f_mv_search_atg", "f_mv_stk_itemquantity", "f_mv_stk_to", 
                         "f_mv_tan", "f_mv_remark", "f_mv_serialno", "f_mv_serialno_old", "f_mv_jb_id",
                         "f_mv_modeStockEntries", "f_mv_modeArticleEntries", "stkmv_id_storno",
                         "maskDisplayDataSwitch", "maskDisplayNavSwitch", "maskDisplayArticleSwitch", "maskDisplayAtSearchSwitch",
                         "maskDisplayMoveSwitch", "maskDisplayMoveDataFieldsSwitch", "maskDisplayJournalSwitch",
                         "f_mv_search_stk_name_from", "f_mv_search_stk_name_to",
                         "f_mv_search_at_misc", "f_mv_search_tan_from", "f_mv_search_tan_to", "f_mv_search_remark",
                         "f_mv_search_serialno", "f_mv_search_data", "f_mv_search_jb_id", "f_mv_search_misc",
                         "f_mv_search_stk_from_sub", "f_mv_search_stk_to_sub",
                         "f_mv_search_day_from", "f_mv_search_month_from", "f_mv_search_year_from", 
                         "f_mv_datafield_01", "f_mv_datafield_02", "f_mv_datafield_03", "f_mv_datafield_04", "f_mv_datafield_05", 
                         "f_mv_datafield_06", "f_mv_datafield_07", "f_mv_datafield_08", "f_mv_datafield_09", "f_mv_datafield_10", 
                         "f_mv_datafield_11", "f_mv_datafield_12", "f_mv_datafield_13", "f_mv_datafield_14", "f_mv_datafield_15", 
                         "f_stkat_scanmode", "job_id", "searchMode", "stkSearchMode", "f_journal_headlines", "f_journal_orderby"));

// Id of the current employee and the costcenter (individual root-node) logged in
if ($cscIdRoot == ""): $cscIdRoot = getFieldValueFromId("employee","emp_id",$emp_id,"csc_id"); endif;
if ($customerId == ""): $customerId = getFieldValueFromId("costcenter","csc_id",$cscIdRoot,"cs_id"); endif;

// Get the rights of the employee logged in
$empRights = getRights($emp_id);

// Init
if ($cscIdCurrent == ""): $cscIdCurrent = $cscIdRoot; endif;
if ($hqId == ""): $hqId = $hq_id; endif;
if ($customerId == ""): $customerId = "0"; endif;

// Job handling
if ($job_id != "" && is_numeric($job_id)) :
   $f_mv_jb_id = $job_id;
else :
   $job_id = "";
endif;
if ($f_mv_jb_id != "") :
   $deactivateMenuStatic = "1";
endif;

getLanguage(__FILE__);

// Attention: Definition AFTER definitions of $customerId, $cscIdRoot and $cscIdCurrent
$pageTitel = getLngt("LÄGER");

mcIsSet($g_cmp_comp);
mcIsSet($g_cmp_comp2);
mcIsSet($g_cs_eid);
mcIsSet($g_csc_name);

mcIsSet($generatePDF);
if ($generatePDF != "1") :
   include_once ("../geo/geocode.inc.php");
endif;
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
include_once ("../include/inc_stock.inc.php");

getCurrentScript(__FILE__);

// Get the rights of the employee logged in and check the accessibility
// authCheckEmployeeRights($emp_id, "14", "1");

// Select user-type for mode of security check 
$userType = getFieldValueFromId("user","usr_id",$usr_id,"usr_type");
$userTypeName = getUserTypeName($userType);

// Parameters have to exist for both: customer and headquarter
if (($userTypeName != "stk") && ($customerId == "" || $cscIdRoot == "" || $cscIdCurrent == "")) :
   gotoReferer("1");  // Parameter missing
endif;

// Check authentication verifying emmployee an his/her costcenter- and customer-association
if ( !( ($userType == "1") || ($userType == "4") || authCheck($hq_id,$usr_id,$emp_id,$cscIdRoot,$customerId,$cscIdActual) ) ) :
   gotoReferer("1");
endif;

// Get the emp_id of the root admin because he/she is allowed to change a password of an employee
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);

// Currrent user logged in
$stkRootAccessIDsEmpIdArray = array();
$whereClauseRootStockIDs = "";
$stkRootAccessIDsEmpId = getParameterValue($emp_id, "MASK_STK_ROOT_ACCESS");
if ($emp_id != $empIdRootAdmin) :
   if ($stkRootAccessIDsEmpId != "") :
      $stkRootAccessIDsEmpIdArray = spliti(",",$stkRootAccessIDsEmpId);
      $whereClauseRootStockIDs = " AND stk_id IN (" . $stkRootAccessIDsEmpId . ")";
   else :
      // No access to any root stock. Exclude all stocks !!!
      $whereClauseRootStockIDs = " AND stk_id = '0' ";
   endif;
endif;

// If activated, no disposition will be possible and will be hidden in the mask
$maskStkReadonly = getParameterValue($emp_id, "MASK_STK_READONLY");

// Special parameter for the current user to rule the defined write access handled only as read access.
$stkReadonlyWhereDefinedWriteaccess = getParameterValue($emp_id, "MASK_STK_READONLY_WHERE_DEFINED_WRITEACCESS");
if ($stkReadonlyWhereDefinedWriteaccess == "") : $stkReadonlyWhereDefinedWriteaccess = "0"; endif;



// Check range of date. All fields have to be set
if ($day_from == "" || $month_from == "" || $year_from == "" || 
    $day_to == "" || $month_to == "" || $year_to == "") :
 
    // Initialize date-ranges to the current date
    $fromDateRange = getDateTime("3") . " 00:00:00";
    $toDateRange = getDateTime("3") . " 23:59:59";
 
    $day_from = getDateTime("day");
    $month_from = getDateTime("month");
    $year_from = getDateTime("year");
    $day_to = getDateTime("day");
    $month_to = getDateTime("month");
    $year_to = getDateTime("year");
else :
    $fromDateRange = $year_from . "-" . pad($month_from,2) . "-" . pad($day_from,2) . " 00:00:00";
    $toDateRange = $year_to . "-" . pad($month_to,2) . "-" . pad($day_to,2) . " 23:59:59";
endif;

if ($stkmv_day_from == "" || $stkmv_month_from == "" || $stkmv_year_from == "") :
   $stkmvSpecialDatetime2 = getDateTime("3") . " 00:00:00";
   $stkmv_day_from = $day_from;
   $stkmv_month_from = $month_from;
   $stkmv_year_from = $year_from;
else :
   $stkmvSpecialDatetime2 = $stkmv_year_from . "-" . pad($stkmv_month_from,2) . "-" . pad($stkmv_day_from,2) . " 00:00:00";
endif;

$journalSearchDatetime = "";
if ($f_mv_search_day_from != "" && $f_mv_search_month_from != "" && $f_mv_search_year_from != "") :
   $journalSearchDatetime = $f_mv_search_year_from . "-" . pad($f_mv_search_month_from,2) . "-" . pad($f_mv_search_day_from,2) . " 00:00:00";
endif;

// Get right status of the current employee
$stockRight = false;
if ($userTypeName == "hq") :
   if (substr($empRights,14,1) == "1") : $stockRight = true; endif;
endif;

// Flag for "show invisible stocks"
if ($f_show_invisible == "" || count($f_show_invisible) == 0) :
   $f_show_invisible = "0";
else: 
   $f_show_invisible = "1";
endif;
// Display area configuration for planning the stock capacities
if ($f_stk_planning == "" || count($f_stk_planning) == 0) :
   $f_stk_planning = "0";
else: 
   $f_stk_planning = "1";
endif;
// Export stock article data as CSV file
if ($f_stkat_export == "" || count($f_stkat_export) == 0) :
   $f_stkat_export = false;
else: 
   $f_stkat_export = true;
endif;
// Export stock journal data as CSV file
if ($f_stkmv_export == "" || count($f_stkmv_export) == 0) :
   $f_stkmv_export = false;
else: 
   $f_stkmv_export = true;
endif;
// Scan mode (incoming or outgoing goods)
if ($f_stkat_scanmode == "" || $f_stkat_scanmode == "1") :
   $f_stkat_scanmode = "1";
else: 
   $f_stkat_scanmode = "0";
endif;
// Display also all article of the sub stocks of the selected incoming stock 
if ($f_mv_search_stk_from_sub == "" || count($f_mv_search_stk_from_sub) == 0) :
   $f_mv_search_stk_from_sub = "0";
else: 
   $f_mv_search_stk_from_sub = "1";
endif;
// Display also all article of the sub stocks of the selected outgoing stock 
if ($f_mv_search_stk_to_sub == "" || count($f_mv_search_stk_to_sub) == 0) :
   $f_mv_search_stk_to_sub = "0";
else: 
   $f_mv_search_stk_to_sub = "1";
endif;


// Customized columns
if ($f_journal_headlines == "") : $f_journal_headlines = array(); endif;
if ($f_journal_orderby == "") : $f_journal_orderby = array(); endif;


// Search mode (AND or OR search for the stocks of the journal)
if ($stkSearchMode == "") : $stkSearchMode = "1"; endif;

// Search mode (AND or OR search for the special fields of the journal)
if ($searchMode == "") : $searchMode = "0"; endif;

// Display containers
if ($userTypeName == "stk") :
   if ($maskDisplayDataSwitch == "") : $maskDisplayDataSwitch = "0"; endif;
   if ($maskDisplayNavSwitch == "") : $maskDisplayNavSwitch = "0"; endif;
   if ($maskDisplayArticleSwitch == "") : $maskDisplayArticleSwitch = "1"; endif;
   if ($maskDisplayMoveSwitch == "") : $maskDisplayMoveSwitch = "0"; endif;
   if ($maskDisplayMoveDataFieldsSwitch == "") : $maskDisplayMoveDataFieldsSwitch = "0"; endif;
   if ($maskDisplayJournalSwitch == "") : $maskDisplayJournalSwitch = "0"; endif;

   // Default value of the warehousemen
   if ($stkIdRoot == "" || $stkIdRoot == "0") :
      $tmpStkIdOfStkUsr = getFieldValueFromId("stockuser","usr_id",$usr_id,"stk_id");
      if ($tmpStkIdOfStkUsr != "" && is_numeric($tmpStkIdOfStkUsr)) :
         $pos = array_search($tmpStkIdOfStkUsr, $stkRootAccessIDsEmpIdArray);
         if (!($pos === FALSE)) :
            $stkIdRoot = $tmpStkIdOfStkUsr;
            $stkIdCurrent = $stkIdRoot;
         endif;
      endif;
   endif;
else :
   if ($maskDisplayDataSwitch == "") : $maskDisplayDataSwitch = "0"; endif;
   if ($maskDisplayNavSwitch == "") : $maskDisplayNavSwitch = "0"; endif;
   if ($maskDisplayArticleSwitch == "") : $maskDisplayArticleSwitch = "0"; endif;
     $tmpStkIdRoot = getStkPathId($stkIdRoot);  // Makes it safe to have a real root stock
     $maskStkatShowPermanent = getParameterValue("0", "MASK_STKAT_SHOW_PERMANENT_" . $tmpStkIdRoot, "0");
     if ($maskStkatShowPermanent == "1") : $maskDisplayArticleSwitch = "1"; endif;
   if ($maskDisplayMoveSwitch == "") : $maskDisplayMoveSwitch = "1"; endif;
   if ($maskDisplayMoveDataFieldsSwitch == "") : $maskDisplayMoveDataFieldsSwitch = "0"; endif;
   if ($maskDisplayJournalSwitch == "") : $maskDisplayJournalSwitch = "1"; endif;
   if ($maskDisplayAtSearchSwitch == "") : $maskDisplayAtSearchSwitch = "0"; endif;
endif;


// Global parameter 
$numOfArticles = 0;
$numOfPlaces = 0;
$numOfJournalEntries = 0;

if ($f_displayModeStockArticle == "") : $f_displayModeStockArticle = "1"; endif;
if ($f_mv_modeStockEntries == "") : $f_mv_modeStockEntries = "0"; endif;
if ($f_mv_modeArticleEntries == "") : $f_mv_modeArticleEntries = "1"; endif;
if ($f_journal_modeStockEntries == "") : $f_journal_modeStockEntries = "0"; endif;


// Enter the max quantity of the current stock
if ($f_stk_maxquantity == "") : $f_stk_maxquantity = "0"; endif;

$nameStock = trim($nameStock);
$deleteStock = trim($deleteStock);

$f_stk_barcode = trim($f_stk_barcode);
if ($f_stk_barcode == "") :
   $f_stk_barcode = $nameStock;
endif;

// Default fields of the disposition to be displayed
$stkmvTitleArray = array(getLngt("von Lager"),getLngt("Artikel"),getLngt("Menge"),getLngt("nach Lager"),getLngt("Transaktionsnr."),getLngt("Bemerkung"),getLngt("Seriennummer"),getLngt("Auftrag"),getLngt("Zusatzdatum"));
// Default fields of the journal to be displayed
$stkJournalFieldArray = array("stkmv.stkmv_id","stkmv.stkmv_timestamp","stk_name_from","stk_name_to","at.at_eid","at.at_name","stkmv.stkmv_itemquantity","stkmv_tan",
                              "stkmv.stkmv_remark","stkmv.stkmv_serialno","stkmv.stkmv_data","stkmv.at_eid_bundle","stkmv.jb_id","stkmv.stkmv_datetime2","stkmv_x");
$stkJournalTitleArray = array(getLngt("Lfd.&nbsp;"), getLngt("Zeitstempel&nbsp;"), getLngt("Quelle&nbsp;"), getLngt("Ziel&nbsp;"), getLngt("Artikelnr.&nbsp;"), getLngt("Artikelbez.&nbsp;"), getLngt("Artikelzusatz&nbsp;"), getLngt("Stückzahl&nbsp;"), getLngt("Transaktionsnr.&nbsp;"), getLngt("Bemerkung&nbsp;"), getLngt("Seriennummer&nbsp;"), getLngt("Zusatzdaten&nbsp;"), getLngt("Gebindeartikel&nbsp;"), getLngt("Auftrag&nbsp;"), getLngt("Zusatzdatum&nbsp;"), getLngt("Mitarbeiter&nbsp;"), getLngt("Aktion&nbsp;"));
$stkJournalTitleDisplayedArray = array("1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1");
$stkJournalOrderByDirectionArray = array("0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0");


if ($userTypeName == "hq" && $stockRight) :

   // Insert new stock
   if ($f_act == "newStock" && $nameStock != "") :
   
      // Check for insert a new main stock
      if (($stkIdRoot == "" || $stkIdRoot == "0") && ($stkIdCurrent == "" || $stkIdCurrent == "0")) :
         $stkPathCurrent = "";
         $stkPathToStore = "";
         $stkIdCurrent = "";
      else :
         if (!isset($stkPathCurrent) || $stkPathCurrent == ""): $stkPathCurrent = "//"; endif;
         $stkPathToStore = $stkPathCurrent.$stkIdCurrent."//";
      endif;
      
      // Check for double stock names. They have to be unique for each customer and headquarters
      // if (!existsEntry("stock",array("hq_id",$hqId,"cs_id",$customerId,"stk_name",$nameStock))) :

         TA("B");

         // The new path is the concatenation of the path of the current stock and id of the current stock
         insertStmt("stock",array("hq_id",$hqId,"stk_pre_id",$stkIdCurrent,"stk_name",$nameStock,"stk_path",$stkPathToStore,"cs_id",$customerId,"stk_visible","1","stk_barcode", $f_stk_barcode));

         $stkIdNew = getLastInsertId();

         // Only execute if new stock is a root stock
         if ($stkIdRoot == "" || $stkIdRoot == "0") :

            // Extend inividual parameter of the current employee (only not being admin)
            // $empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);      // Done before ...!!!
            if ($empIdRootAdmin != $emp_id) :
               $stkRootAccessIDsEmpId = getParameterValue($emp_id, "MASK_STK_ROOT_ACCESS");
               $stkRootAccessIDsEmpId .= "," . $stkIdNew;
               updateStmt("parameter","emp_id",$emp_id,array("par_value",$stkRootAccessIDsEmpId),"par_key = 'MASK_STK_ROOT_ACCESS' AND hq_id = '". $hq_id . "'");
            endif;

            // Generate a new parameter for the headlines of the extra data fields
            insertStmt("parameter",array("emp_id","0","hq_id","0","par_key","MASK_STK_DATAFIELDHEADLINES_" . $stkIdNew,"par_value","01,02,03,04,05,06,07,08,09,10,11,12,13,14,15"));
            
            // Generate a new parameter for the extra fields have to be displayed WITHOUT existing serial number
            insertStmt("parameter",array("emp_id","0","hq_id","0","par_key","MASK_STK_DATAFIELDS_" . $stkIdNew,"par_value","0"));
         endif;

         // Write logdata into log database
         writeToLogDB("87",$hq_id,"",$usr_id,"","",$customerId,"HQ_ID=".$hqId."|STK_ID_NEW=".$stkIdNew."|STK_ID_PARENT=".$stkIdCurrent."|STK_NAME_NEW=".$nameStock."|STK_BARCODE_NEW=".$f_stk_barcode);

         TA("C");
         TA("E");      
      // else :
      //   $statusMessage = getLngt("Ein Lagerort mit demselben Namen") . " " . $nameStock . " " . getLngt("existiert schon. Bitte umbenennen!");
      // endif;        
   endif;
   
   
   // Delete selected stock
   if ($f_act == "deleteStock" && $deleteStock != "") :
   
      // First check assigned articles to the stock to be deleted
      if (!existsEntry("stockarticle",array("stk_id",$deleteStock))) :
      
        $fieldsLength = count($deleteStock);
        for ($i = 0; $i < $fieldsLength; $i++) :
          if (!existsEntry("stock",array("cs_id",$customerId,"stk_pre_id",$deleteStock))) :
   
             // Check for articles on the stock to be deleted
             if (!existsEntry("stockarticle",array("stk_id",$deleteStock))) :
   
                // Get the name of the stock (ONLY for logging!)
                $stkNameToBeDeleted = getFieldValueFromId("stock","stk_id",$deleteStock,"stk_name");
                
                deleteStmt("stock","stk_id = '$deleteStock'");
                
                // Write logdata into log database
                writeToLogDB("88",$hq_id,"",$usr_id,"","",$customerId,"HQ_ID=".$hqId."|STK_ID=".$deleteStock."|STK_NAME=".$stkNameToBeDeleted);
             else: 
                $statusMessage = getLngt("Eintrag kann nicht entfernt werden, da mindestens ein Artikel darauf gebucht ist!");
             endif;
          else: 
             $statusMessage = getLngt("Eintrag kann nicht entfernt werden, da mindestens ein Unterlagerort existiert!");
          endif;
        endfor;
      else :
        $statusMessage = getLngt("Eintrag kann nicht entfernt werden, da mindestens ein Artikel auf den Lagerort gebucht ist!");
      endif;
   endif;
   
   
   // Rename current stock
   if ($f_act == "renameStock" && $nameStock != "" && $stkIdCurrent != "") :

      // Check for double stock names. They have to be unique for each customer and headquarters
      // if (!existsEntry("stock",array("hq_id",$hqId,"cs_id",$customerId,"stk_name",$nameStock))) :   

         TA("B");

         updateStmt("stock","stk_id",$stkIdCurrent,array("stk_name",$nameStock));

         // Write logdata into log database
         writeToLogDB("89",$hq_id,"",$usr_id,"","",$customerId,"HQ_ID=".$hqId."|STK_ID=".$stkIdCurrent."|STK_NAME=".$nameStock);      

         TA("C");
         TA("E");
      // else :
      //   $statusMessage = getLngt("Ein Lagerort mit demselben Namen") . " " . $nameStock . " " . getLngt("existiert schon. Bitte einen anderen wählen!");
      // endif;
   endif;


   // Set status of visibility of the stock
   if ($f_act == "setVisibility") :

      // Check for existence
      if (existsEntry("stock",array("cs_id",$customerId,"stk_id",$stkIdCurrent))) :

         // Update visible status
         updateStmt("stock","stk_id",$stkIdCurrent,array("stk_visible",$stkVisibleCurrent));

         // Write logdata into log database
         writeToLogDB("90",$hq_id,"",$usr_id,"","",$customerId,"HQ_ID=".$hqId."|STK_ID=".$stkIdCurrent."|STATUS_VISIBILITY=".$stkVisibleCurrent);
      else :
         $statusMessage = getLngt("Die Sichtbarkeitsstatus des Lagerortes wurde nicht geändert!");
      endif;
   endif;


   // Storno of a set of journal entries
   if ($f_act == "journalStorno") :

      if ($stkmv_id_storno != "") :

         // Get data from the journal entry
         $stkmvAtIdBundle = getFieldValueFromId("stockmove","stkmv_id",$stkmv_id_storno,"at_id_bundle");
         $stkmvDatetime = getFieldValueFromId("stockmove","stkmv_id",$stkmv_id_storno,"stkmv_datetime");

         if ($stkmvDatetime != "" && $stkmvAtIdBundle != "") :
         
            $stkmvAtEidBundle = getFieldValueFromId("article","at_id",$stkmvAtIdBundle,"at_eid");

            // Get ONLY the set of journal entries according to the requested disposition
            $sqlStmt = getStmtStockJournal("stkmv.at_id_bundle = '" . $stkmvAtIdBundle . "' AND stkmv.stkmv_datetime = '" . $stkmvDatetime . "'");
            $result = $db->query($sqlStmt);
            if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());

            TA("B");                   
            $currentTime = getDateTime("0");

            while ($row = $result->fetch_assoc()):

                  $moveResult = stockMoveTA (($row["stk_id_to"] == "" ? "0" : $row["stk_id_to"]), ($row["stk_id_from"] == "" ? "0" : $row["stk_id_from"]), $row["at_id"], $row["stkmv_itemquantity"], $row["stkmv_tan"], "Storno " . $row["stkmv_id"], $row["stkmv_serialno"], "", $usr_id, $stkmvAtIdBundle, $currentTime, $stkmvSpecialDatetime2);

                  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                  // !!! Check for associations to jobs ... removal of tourarticles and so on ... !!!!!!!!!!!!!!!!!!!!!!!!
                  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

                  if (trim($moveResult[1]) != "") :
                     $statusMessage .= $row["stkmv_id"] . ": " . $moveResult[1] . "  ";
                  endif;
            endwhile;
            $result->free();
            
            TA("C");
            TA("E");
         else :
            $statusMessage = getLngt("Journalfehler! Es besteht kein Bezug (mehr) zur angeforderten Gesamtmenge!");
         endif;
      else :
         $statusMessage = getLngt("Journalfehler! Ein Storno kann nicht stattfinden, da der angefragte Journaleintrag nicht gefunden wurde!");
      endif;
   endif;
endif;

$stkNameRoot = getFieldValueFromId("stock","stk_id",$stkIdRoot,"stk_name");

$tmpFields = getFieldsValueFromId("stock","stk_id",$stkIdCurrent,array("stk_path","stk_name","stk_visible"));
$stkPathCurrent = mcArrIsSet($tmpFields, 0);
$stkNameCurrent = mcArrIsSet($tmpFields, 1);
$stkVisibleCurrent = mcArrIsSet($tmpFields, 2);

$stkVisibleCurrent2 = 0;
if ($stkVisibleCurrent != "1") :
   $stkVisibleCurrent = 0; 
   $stkVisibleCurrent2 = 1;
endif;

/*
echo "customerId: " . $customerId . "<br><br>" . "stkIdRoot: " . $stkIdRoot . "<br>" . "stkIdCurrent: " . $stkIdCurrent . "<br>";
echo "stkNameCurrent: " . $stkNameCurrent . "<br>" . "stkPathCurrent: " . $stkPathCurrent . "<br>" . "nameStock: " . $nameStock . "<br><br>";
echo "Date range: " . $fromDateRange . " - " . $toDateRange . "<br>";
echo "f_act: " . $f_act . "<br>";
*/

// Selection of all CHILDREN of the current stock

$whereClauseVisibility = " AND stk_visible = '1' ";
if ($f_show_invisible == "1") : $whereClauseVisibility = ""; endif;

$sqlquery = "SELECT stk_id, stk_name, stk_path FROM stock"
             . " WHERE stk_pre_id != '0' AND stk_pre_id = '" . $stkIdCurrent . "'" . $whereClauseVisibility
             . " ORDER BY stk_name";

$result = $db->query($sqlquery);
if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
$listOfChildren = "";
while ($row = $result->fetch_assoc()):
      $stk_id   = $row["stk_id"];
      $stk_name = $row["stk_name"];
      $stk_path = $row["stk_path"];

      $listOfChildren .= "<option value=\"" . ec($stk_id) . "\">" . $stk_name . "</option>\n";
endwhile;
if ($listOfChildren != "") : $listOfChildren = "<option value=\"\">Lagerorte:</option>\n" . $listOfChildren; endif;
$result->free();


// Output of the path links for navigation in the stock tree
$stkPathCurrentOut = "";
$fields = spliti("//",$stkPathCurrent);
$len = count($fields);
$pathDelimiter = "<img src=\"../images/arrow_right.jpg\" border=\"0\" height=\"10\" width=\"25\">";
$rootFlag = FALSE;
$maxPathLength = 4;
$pathPrefix = "";
$pathPrefixFlag = FALSE;
for ($i = 0; $i < $len; $i++) :
  if ($fields[$i] != "") :
     // Only show the subpath from the "current root" of the employee
     // if ($fields[$i] == $stkIdRoot) : $rootFlag = TRUE; endif;
     $rootFlag = TRUE;
     if ($rootFlag) :
        // Only output of the last <maxPathLength> elements
        if ($i > $len - $maxPathLength) :
           $stk_name = getFieldValueFromClause("stock","stk_name","stk_id = '" . $fields[$i] . "'");	   

           $stkPathCurrentOut .= "<a href=\"javascript:stkFinishPerNavLink('" . ec($fields[$i]) . "');\">" . $stk_name . "</a>";
           $stkPathCurrentOut .= $pathDelimiter;
        
        else :
           if (!$pathPrefixFlag && ($i > $len - $maxPathLength - 1)) :     
              $stk_name = getFieldValueFromClause("stock","stk_name","stk_id = '" . $fields[$i] . "'");

              $pathPrefix .= "<a href=\"javascript:stkFinishPerNavLink('" . ec($fields[$i]) . "');\">" . "<img src=\"../images/arrow_left.jpg\" border=\"0\" height=\"10\" width=\"25\">" . "</a>";
              $pathPrefix .= $pathDelimiter;
              $pathPrefixFlag = TRUE;
           endif;
        endif;        
     endif;
  endif;
endfor;
$stkPathCurrentOut = $pathPrefix . $stkPathCurrentOut . $stkNameCurrent;



// Check for the right to administrate the stocks, only for output
$stkAdminDisabled = "";
if ($userTypeName == "cs") :
   if (substr($empRights,9,1) != "1") : $stkAdminDisabled = "disabled"; endif;
else :
   if (substr($empRights,14,1) != "1") : $stkAdminDisabled = "disabled"; endif;
endif;

// Definition of the select-fields, only for output
$selectFieldSelectStock = "";
$selectFieldSelectStock2 = "";
$selectFieldDeleteStock = "";
if ($listOfChildren != "") :
   // Check for the right to navigate in the subtree

   $selectFieldSelectStock = "<span class=\"f8np1\">\n" .
                            "<select name=\"selectStock\" onChange=\"xReload();\">\n" .
                            $listOfChildren . "\n" .
                            "</select>\n" .
                            "</span>\n";
   $selectFieldSelectStock2 = "<span class=\"f8np1\">\n" .
                            "<select name=\"selectStock2\" onChange=\"x2Reload();\">\n" .
                            $listOfChildren . "\n" .
                            "</select>\n" .
                            "</span>\n";

   $selectFieldDeleteStock = "<div style=\"width:100%; height:3px;\"> </div>" .
                            "<div style=\"float:left\"><span class=\"f8np1\">\n" .
                            "<select name=\"deleteStock\">\n" .
                            $listOfChildren . "\n" .
                            "</select>\n" .
                            "</span>&nbsp;&nbsp;</div>\n" .
                              defineButtonType10(getLngt("Löschen"), "action_remove", "stkFinishPage('" . ec("deleteStock") . "');", "100", "left", "2");
endif;

// Check the status of the visibility of the current stock
$buttonVisibility = "";
$displayTextVisibility = "";
$confirmTextVisibility = "";
if ($stkIdRoot != $stkIdCurrent) :   // NOT for the root stock !!!    (Check $userTypeName == "hq" ???)
   $buttonVisibility = defineButtonType10(getLngt("Ausblenden"), "action_invisible", "visibilityFinishPage();", "100", "left", "2");
   $confirmTextVisibility = getLngt("Soll der aktuelle Lagerort wirklich ausgeblendet werden?");
   if ($stkVisibleCurrent != "1") : 
      $buttonVisibility = defineButtonType10(getLngt("Einblenden"), "action_visible", "visibilityFinishPage();", "100", "left", "2");
      $displayTextVisibility = getLngt("(ausgeblendet)");
      $confirmTextVisibility = getLngt("Soll der aktuelle Lagerort wirklich eingeblendet werden?");
   endif;
endif;
// Checkbox for displaying all stocks
$showInvisibles = getLngt("Alle&nbsp;anz.") . "&nbsp;<input type=\"checkbox\" name=\"f_show_invisible[]\" value=\"1\" " . ($f_show_invisible == "1" ? "checked" : "") . " onChange=\"javascript:stkFinishPage('');\" tabindex=\"\">";

// Check for the right to make the stocks (in)visible, only for output
if (($userTypeName == "cs" && substr($empRights,9,1) != "1") || ($userTypeName == "hq" && substr($empRights,14,1) != "1")) :
   $buttonVisibility = "";
   $showInvisibles = "";
endif;


// Currently ONLY for headquarters
if ($userTypeName == "hq" && $stockRight) :

   // **************
   // * STOCK DATA *
   // **************

   // Enter the max quantity of the current stock
   if ($f_stk_maxquantity == "") : $f_stk_maxquantity = "0"; endif;
   if ($g_cs_id == "") : $g_cs_id = "0"; endif;
   if ($g_csc_id == "") : $g_csc_id = "0"; endif;

   if ($f_act == "saveStockData") :

      // *** Save the quantity (Begin) ***

      // Check quantity according to the tree consistence
      $doUpdate = true;
      /*   SEMANTIC IS NOT CORRECT !!!
      if (!checkStockQuantitySubtree($stkIdCurrent, $f_stk_maxquantity, "")) :
         $statusMessage = getLngt("Die Summe aller maximalen Kapazitäten des gesamten Lagerortbaums unterhalb des aktuellen Lagerortes ist größer als die eingegebene Größe!");
         $doUpdate = false;
      endif;
      */
      if ($stkIdCurrent != $stkIdRoot && !checkStockQuantitySameLevel($stkIdCurrent, $f_stk_maxquantity, "")) :
         $statusMessage = getLngt("Die Summe aller maximalen Kapazitäten der Lagerorte, die sich in derselben Ebene des aktuellen Lagerortes befinden, übersteigt die Kapazität im übergeordneten Knoten!");
         $doUpdate = false;
      endif;
      if ($doUpdate && !checkStockQuantityNextSubLevel($stkIdCurrent, $f_stk_maxquantity, "")) :
         $statusMessage = getLngt("Die Summe aller maximalen Kapazitäten der Lagerorte, die sich in der nächsten Unterebene des aktuellen Lagerortes befinden, übersteigt die eingegebene Kapazität des aktuellen Knotens!");
         $doUpdate = false;
      endif;
      if ($doUpdate && $f_stk_planning == "1" && !checkStockArticleQuantitySubtree($stkIdCurrent, $f_stk_maxquantity, "")) :
         $statusMessage = getLngt("Die Summe aller Artikelbestände des gesamten Lagerortbaums unterhalb des aktuellen Lagerortes ist größer als die eingegebene Größe!");
         $doUpdate = false;
      endif;
      if ($doUpdate) :
         // Update stock with quantity
         updateStmt("stock", "stk_id", $stkIdCurrent, array("stk_maxquantity", $f_stk_maxquantity, "stk_planning", $f_stk_planning, "ad_id", $f_ad_id, "cs_id", $g_cs_id, "csc_id", $g_csc_id, "stk_barcode", $f_stk_barcode));
      
         // Write logdata into log database
         writeToLogDB("91",$hq_id,"",$usr_id,"","",$customerId,"HQ_ID=".$hqId."|STK_ID=".$stkIdCurrent."|STK_NAME=".$stkNameCurrent."|STK_QUANTITY=".$f_stk_maxquantity."|AD_ID=".$f_ad_id."|CS_ID=".$g_cs_id."|CSC_ID=".$g_csc_id."|STK_BARCODE=".$f_stk_barcode);
      endif;
   endif;
   // *** Save the quantity (End) ***


   // *** Save the adress (Begin) ***
   if ($f_act == "saveAddress") :

      // *** Save the adress (Begin) *** 
      $f_ad_street = trim($f_ad_street);
      $f_ad_zipcode = trim($f_ad_zipcode);
      $f_ad_city = trim($f_ad_city);
      $f_ad_country = trim($f_ad_country);
      $f_stk_hsno = trim($f_stk_hsno);

      // Check for empty entries in address-fields
      if ($f_ad_street != "" && $f_ad_zipcode != "" && $f_ad_city != "" && $f_ad_country != "") :

         // Check validity according to the address-server
         $addressValid = getGeoCoordinates($f_ad_street, $f_ad_zipcode, $f_ad_city, $f_cscad_hsno, $f_ad_country, "");
         if ($addressValid != "") :

            // Check zipcode and city
            $addressValidityArray = checkCityZipcode($f_ad_zipcode, $f_ad_city, $f_ad_street);
            if ($noValidationOfAddress || $addressValidityArray[0] >= 1) :

               TA("B");

               // Check for existing entry in address (because of redundance)
               if ($f_ad_country == "") : $f_ad_country = "DE"; endif;
               $tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
               $ad_id_new = $tmpArray[0];                     

               // Check for address data in stock
               $adIdCurrent = getFieldValueFromId("stock","stk_id",$stkIdCurrent,"ad_id");
               $stkHsnoCurrent = getFieldValueFromId("stock","stk_id",$stkIdCurrent,"stk_hsno");

               if ($ad_id_new != $adIdCurrent || $f_stk_hsno != $stkHsnoCurrent) :
                  $sqlStmt = "UPDATE stock SET ad_id = '" . $ad_id_new . "', stk_hsno = '" . $f_stk_hsno . "' WHERE stk_id = '" . $stkIdCurrent . "'";
                  $res = $db->query($sqlStmt);
                  
                  // Write logdata into log database
                  writeToLogDB("92",$hq_id,"",$usr_id,"","",$customerId,"STK_ID=".$stkIdCurrent."|AD_ID_OLD=".$adIdCurrent."|AD_ID_NEW=".$ad_id_new."|ADDRESS=".$f_ad_street.";".$f_ad_zipcode.";".$f_ad_city.";".$f_ad_country.";".$f_stk_hsno);                  
               endif;

               TA("C");    
               TA("E");
            else :
              $statusMessage = getLngt("Die Postleitzahl passt nicht zu dem angegebenen Ort!");
              $addressValidationErr = "1";
            endif;               
         else :
            $statusMessage = getLngt("Der Adress-Server kennt die eingebene Adresse nicht! Bitte korrekt erfassen!");
         endif;
      else :
         $statusMessage = getLngt("Bitte geben Sie mindestens Straße, Hausnummer, Stadt und Land an!");
      endif;
   endif;
   // *** Save the adress (End) ***

   if ($f_act == "saveJournalTitles") :
      $stkJournalTitleArrayLen = count($stkJournalTitleArray);   // Max. number of columns to be displayed
      $f_journal_headlines_len = count($f_journal_headlines);      
      if ($f_journal_headlines_len > 0) :
         $journalHeadlinesArray = array("0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0");
         $journalOrderByArray = array("0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0");
         $journalHeadlinesArrayLen = count($journalHeadlinesArray);
         for ($i = 0; $i < $journalHeadlinesArrayLen; $i++) :
             if (in_array($i, $f_journal_headlines)) :
                $journalHeadlinesArray[$i] = "1";
             endif;
             if (in_array($i, $f_journal_orderby)) :
                $journalOrderByArray[$i] = "1";
             endif;
         endfor;
         $journalHeadlinesStr = implode(",", $journalHeadlinesArray);
         $tmpStkIdRoot = getStkPathId($stkIdRoot);  // Makes it safe to have a real root stock
         if (existsEntry("parameter",array("par_key","MASK_STK_JOURNALHEADLINES_DISPLAYED_" . $tmpStkIdRoot))) :
            updateStmt("parameter","emp_id","0",array("par_value",$journalHeadlinesStr),"par_key = 'MASK_STK_JOURNALHEADLINES_DISPLAYED_" . $tmpStkIdRoot . "' AND hq_id = '0'");
         else :
            insertStmt("parameter",array("emp_id","0","hq_id","0","par_key","MASK_STK_JOURNALHEADLINES_DISPLAYED_" . $tmpStkIdRoot,"par_value",$journalHeadlinesStr));
         endif;
         $journalOrderByStr = implode(",", $journalOrderByArray);
         if (existsEntry("parameter",array("par_key","MASK_STK_JOURNAL_ORDERBY_DIRECTION_" . $tmpStkIdRoot))) :
            updateStmt("parameter","emp_id","0",array("par_value",$journalOrderByStr),"par_key = 'MASK_STK_JOURNAL_ORDERBY_DIRECTION_" . $tmpStkIdRoot . "' AND hq_id = '0'");
         else :
            insertStmt("parameter",array("emp_id","0","hq_id","0","par_key","MASK_STK_JOURNAL_ORDERBY_DIRECTION_" . $tmpStkIdRoot,"par_value",$journalOrderByStr));
         endif;
      else :
         $statusMessage = getLngt("Sie müssen mindestens eine Spalte in der Listenanzeige des Journals haben!");
      endif;
   endif;
endif;


if (true) :

   // *** Save the stock article movement (Begin) ***
   if ($f_act == "moveArticle") :

      $f_mv_data = array($f_mv_datafield_01, $f_mv_datafield_02, $f_mv_datafield_03, $f_mv_datafield_04, $f_mv_datafield_05, $f_mv_datafield_06, $f_mv_datafield_07, $f_mv_datafield_08, $f_mv_datafield_09, $f_mv_datafield_10, $f_mv_datafield_11, $f_mv_datafield_12, $f_mv_datafield_13, $f_mv_datafield_14, $f_mv_datafield_15);

      $moveResult = stockMoveTA ($f_mv_stk_from, $f_mv_stk_to, $f_mv_at, $f_mv_stk_itemquantity, $f_mv_tan, $f_mv_remark, $f_mv_serialno, $f_mv_data, $f_mv_jb_id, $usr_id, "0", "", $stkmvSpecialDatetime2, $f_mv_serialno_old);
      if ($moveResult[0]) :
         // TA executed
         $f_mv_stk_itemquantity = 0;   // Reset quantity value (only for display)
	       $f_mv_tan = "";
	       $f_mv_remark = "";
	       $f_mv_serialno = "";
	       $f_mv_serialno_old = "";   // $f_mv_serialno_old ONLY is used for the case stk_from eq. stk_to !!! Not relevant for other cases !!!
	       
	       $f_mv_datafield_01 = ""; $f_mv_datafield_02 = ""; $f_mv_datafield_03 = ""; $f_mv_datafield_04 = ""; $f_mv_datafield_05 = "";
	       $f_mv_datafield_06 = ""; $f_mv_datafield_07 = ""; $f_mv_datafield_08 = ""; $f_mv_datafield_09 = ""; $f_mv_datafield_10 = "";
         $f_mv_datafield_11 = ""; $f_mv_datafield_12 = ""; $f_mv_datafield_13 = ""; $f_mv_datafield_14 = ""; $f_mv_datafield_15 = "";
      endif;
      if (trim($moveResult[1]) != "") :
         $statusMessage = $moveResult[1];
      endif;
   endif;
   // *** Save the stock article movement (End) ***

   
   // ************************************
   // * Data settings of the current stock *
   // ************************************
   $sqlquery = "SELECT stk.stk_pre_id, stk.stk_maxquantity, stk.stk_planning, stk.stk_barcode, stk.ad_id, ad.ad_street, ad.ad_zipcode, stk.stk_hsno, ad.ad_city, ad.ad_country,"
                 . "   stk.csc_id, csc.csc_name, cs.cs_id, cs.cs_eid, cmp.cmp_comp, cmp.cmp_comp2"
                 . " FROM stock AS stk LEFT JOIN address AS ad ON stk.ad_id = ad.ad_id"
		             . "                   LEFT JOIN costcenter AS csc ON stk.csc_id = csc.csc_id"
		             . "                   LEFT JOIN customer AS cs ON csc.cs_id = cs.cs_id"
		             . "                   LEFT JOIN company AS cmp ON cs.cmp_id = cmp.cmp_id"
                 . " WHERE stk.stk_id = '" . $stkIdCurrent . "'";
   $result = $db->query($sqlquery);
   
   if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
   while ($row = $result->fetch_assoc()):
         $f_stk_pre_id = $row["stk_pre_id"];
	       $f_stk_maxquantity = $row["stk_maxquantity"];
         // $f_stk_planning    = $row["stk_planning"];
         $f_stk_barcode     = $row["stk_barcode"];
         $f_ad_id           = $row["ad_id"];
         $f_ad_street       = $row["ad_street"];
         $f_stk_hsno        = $row["stk_hsno"];
         $f_ad_zipcode      = $row["ad_zipcode"];
         $f_ad_city         = $row["ad_city"];
         $f_ad_country      = $row["ad_country"];
	       $g_csc_id          = $row["csc_id"];
	       $g_csc_name        = $row["csc_name"];
	       $g_cs_id           = $row["cs_id"];
	       $g_cs_eid          = $row["cs_eid"];
	       $g_cmp_comp        = $row["cmp_comp"];
	       $g_cmp_comp2       = $row["cmp_comp2"];
   endwhile;
   $result->free();
   
   // Only it is possible to enable/disable the stock area planning for the whole tree
   $f_stk_planning = getFieldValueFromId("stock","stk_id",$stkIdRoot,"stk_planning");



   // *************************
   // * STOCK ARTICLE DATA *
   // *************************
   
   $stockArticles = "";
   
   // * SPECIAL USAGE AFTER BARCODE SCAN *
   // Use article id for filter
   $whereClause = "";
   $executeCommand = false;
   if ($js_execute_cmd == "2") :
      $whereClause = "at.at_id = '" . $js_execute_data . "'";
      $executeCommand = true;
      $f_stkat_search_at_misc = "";   // Remove article filter
      $f_stkat_search_atg = "";       // Remove special article group filter
   endif;
   if ($js_execute_cmd == "3") :
      $whereClause = "stk.stk_id = '" . $js_execute_data . "'";
      $executeCommand = true;
      $f_stkat_search_at_misc = "";   // Remove article filter
      $f_stkat_search_atg = "";       // Remove special article group filter
   endif;

   if ($f_act == "stockArticleList" || $executeCommand || $maskStkatShowPermanent == "1") :

      $f_stkat_search_at_misc = trim($f_stkat_search_at_misc);

      if ($f_stkat_search_at_misc != "") :
         // First step: Only get article item rows matching
         $tmpWhereClause = "(ati.ati_serialno LIKE '%" . $f_stkat_search_at_misc . "%' OR "
                         . "ati.ati_data_01 LIKE '%" . $f_stkat_search_at_misc . "%' OR ati.ati_data_02 LIKE '%" . $f_stkat_search_at_misc . "%' OR "
                         . "ati.ati_data_03 LIKE '%" . $f_stkat_search_at_misc . "%' OR ati.ati_data_04 LIKE '%" . $f_stkat_search_at_misc . "%' OR "
                         . "ati.ati_data_05 LIKE '%" . $f_stkat_search_at_misc . "%' OR ati.ati_data_06 LIKE '%" . $f_stkat_search_at_misc . "%' OR "
                         . "ati.ati_data_07 LIKE '%" . $f_stkat_search_at_misc . "%' OR ati.ati_data_08 LIKE '%" . $f_stkat_search_at_misc . "%' OR "
                         . "ati.ati_data_09 LIKE '%" . $f_stkat_search_at_misc . "%' OR ati.ati_data_10 LIKE '%" . $f_stkat_search_at_misc . "%' OR "
                         . "ati.ati_data_11 LIKE '%" . $f_stkat_search_at_misc . "%' OR ati.ati_data_12 LIKE '%" . $f_stkat_search_at_misc . "%' OR "
                         . "ati.ati_data_13 LIKE '%" . $f_stkat_search_at_misc . "%' OR ati.ati_data_14 LIKE '%" . $f_stkat_search_at_misc . "%' OR "
                         . "ati.ati_data_15 LIKE '%" . $f_stkat_search_at_misc . "%')";
         $sqlStmt = getStmtStockArticleItemSearch($tmpWhereClause);
         $result = $db->query($sqlStmt);
         if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());

         $whereClauseArticleItemsArray = array();
         while ($row = $result->fetch_assoc()):
            $whereClauseArticleItemsArray[] = "(stkat.at_id = '" . $row["at_id"] . "' AND stkat.stk_id = '" . $row["stk_id"] . "')";
         endwhile;
         $result->free();
         if (count($whereClauseArticleItemsArray) > 0) :
            $whereClauseArticleItems = "(" . implode(" OR ", $whereClauseArticleItemsArray) . ")";
         endif;
      
         // Second step: Search for article attributes matching
         if ($whereClause != "") : $whereClause .= " AND "; endif;

         $whereClauseArticle = "(at.at_eid LIKE '%" . $f_stkat_search_at_misc . "%' OR at.at_name LIKE '%" . $f_stkat_search_at_misc . "%' OR at.at_match LIKE '%" . $f_stkat_search_at_misc . "%' OR at.at_description LIKE '%" . $f_stkat_search_at_misc . "%' OR at.at_barcode LIKE '%" . $f_stkat_search_at_misc . "%')";
         if ($whereClauseArticleItems != "") :
            $whereClause = "(" . $whereClauseArticle . " OR " . $whereClauseArticleItems . ")";
         else : 
            $whereClause .= $whereClauseArticle;
         endif;
      endif;

      if ($f_stkat_search_atg != "") :
         if ($whereClause != "") : $whereClause .= " AND "; endif;
         $whereClause .= "atgi.atg_id = '" . $f_stkat_search_atg . "'";
      endif;

      // Check for accessible substocks according to the rights of the current user
      if ($stkReadonlyWhereDefinedWriteaccess != "0") :
            $whereClauseAccessibleStocks .= getAccessibleSubstocks("1");
            if ($whereClauseAccessibleStocks != "") :
               if ($whereClause != "") : $whereClause .= " AND "; endif;
               $whereClause .= " (" . $whereClauseAccessibleStocks . ") ";
            endif;
      endif;

      if ($f_displayModeStockArticle == "0") :
         $stockArticles = showStockArticles($stkIdCurrent, "0", $whereClause, $f_mv_sort_stockArticle);   // All articles with used areas of the current stock
      elseif ($f_displayModeStockArticle == "1") :      
         $stockArticles = showStockArticles($stkIdCurrent, "1", $whereClause, $f_mv_sort_stockArticle);   // All articles with used areas of the whole subtree including the current stock
      elseif ($f_displayModeStockArticle == "2") :
         $stockArticles = showArticleSum($stkIdCurrent, $whereClause, $f_mv_sort_stockArticle);                     // All stocks with used areas but without articles
      elseif ($f_displayModeStockArticle == "3") :
         $stockArticles = showStockSum($stkIdCurrent, $whereClause);               // All stocks with used areas but without articles
      elseif ($f_displayModeStockArticle == "4") :
         $stockArticles = showStockInventory($stkIdCurrent, "1", $whereClause, $f_mv_sort_stockArticle);   // All articles with used areas of the whole subtree including the current stock and containing item data
      endif;      
      $executeCommand = false;
   endif;
   
   
   // ******************
   // * STOCK MOVEMENT *
   // ******************

   // To enter a transaction (article movement) it would be easier to have a reduced list of stocks in relation to the root stock.
   $whereClauseMovementStocks = "";
   if ($f_mv_modeStockEntries == "0") :
      // Display only stocks belonging to the current stock
      $whereClauseMovementStocks = "stk_id = '" . $stkIdCurrent . "' OR stk_path LIKE '%//" . $stkIdCurrent . "//%'";
   elseif ($f_mv_modeStockEntries == "1") :
      // Display only stocks belonging to the current ROOT stock
      $whereClauseMovementStocks = "stk_id = '" . $stkIdRoot . "' OR stk_path LIKE '%//" . $stkIdRoot . "//%'";
   elseif ($f_mv_modeStockEntries == "2") :
      // Display all stocks of ALL ROOT stocks (of the whole system)
      $whereClauseMovementStocks = "";
   endif;

   $fromClauseMovementArticles = "article AS at, stock AS stk, stockarticle AS stkat";
   $whereClauseMovementArticles = "";
   if ($f_mv_modeArticleEntries == "0") :
      // Display only articles belonging to the current stock (all stocks of the current tree)
      $fromClauseMovementArticles = "article AS at, stock AS stk, stockarticle AS stkat";
      $whereClauseMovementArticles = "at.at_id = stkat.at_id AND stkat.stk_id = stk.stk_id AND (stk.stk_id = '" . $stkIdCurrent . "' OR stk.stk_path LIKE '%//" . $stkIdCurrent . "//%') AND stkat.stkat_itemquantity > 0";
   elseif ($f_mv_modeArticleEntries == "1") :
      // Display only articles belonging to the current ROOT stock (all stocks of the current tree)
      $fromClauseMovementArticles = "article AS at, stock AS stk, stockarticle AS stkat";
      $whereClauseMovementArticles = "at.at_id = stkat.at_id AND stkat.stk_id = stk.stk_id AND (stk.stk_id = '" . $stkIdRoot . "' OR stk.stk_path LIKE '%//" . $stkIdRoot . "//%') AND stkat.stkat_itemquantity > 0";
   elseif ($f_mv_modeArticleEntries == "2") :
      // Display all articles belonging to any root stocks (of the whole system)
      $fromClauseMovementArticles = "article AS at, stock AS stk, stockarticle AS stkat";
      $whereClauseMovementArticles = "at.at_id = stkat.at_id AND stkat.stk_id = stk.stk_id";
   elseif ($f_mv_modeArticleEntries == "3") :
      // Display all "NEW" articles NOT belonging to ANY stock (of the whole system)
      $fromClauseMovementArticles = "article AS at";
      $whereClauseMovementArticles = "at.at_id NOT IN (SELECT DISTINCT stkat.at_id FROM stockarticle AS stkat)";
   elseif ($f_mv_modeArticleEntries == "4") :
      // Display all articles (of the whole system), containing articles never booked before
      $fromClauseMovementArticles = "article AS at";
      $whereClauseMovementArticles = "";
   elseif ($f_mv_modeArticleEntries == "5") :
      // Display all articles of the specified article group
      if ($f_at_search_atg == "") : $f_at_search_atg = "0"; endif;
      $fromClauseMovementArticles = "article AS at, articlegroup AS atg, articlegroupitem AS atgi";
      $whereClauseMovementArticles = "at.at_id = atgi.at_id AND atgi.md_id = '" . $md_id . "' AND atgi.atg_id = atg.atg_id AND atg.atg_id = '" . $f_at_search_atg. "'";
   endif;


   // *****************
   // * STOCK JOURNAL *
   // *****************

   // Per default only the journal entries of the current stock will be displayed in the select box
   $whereClauseJournalStocks = "";
   if ($f_journal_modeStockEntries == "0") :
      // Display only journal entries belonging to the current stock
      $whereClauseJournalStocks = "stk_id = '" . $stkIdCurrent . "'";
   elseif ($f_journal_modeStockEntries == "1") :
      // Display only journal entries belonging to the current root stock (all stocks of the current tree)
      $whereClauseJournalStocks = "stk_id = '" . $stkIdCurrent . "' OR stk_path LIKE '%//" . $stkIdCurrent . "//%'";
   elseif ($f_journal_modeStockEntries == "2") :
      // Display only journal entries belonging to the current root stock (all stocks of the current tree)
      $whereClauseJournalStocks = "stk_id = '" . $stkIdRoot . "' OR stk_path LIKE '%//" . $stkIdRoot . "//%'";
   elseif ($f_journal_modeStockEntries == "3") :
      // Display all stocks of all root stocks (of the whole system)
      $whereClauseJournalStocks = "";
   endif;

   // * SPECIAL USAGE AFTER BARCODE SCAN *
   // Use article id for filter
   $whereClauseBarcodeScan = "";
   if ($js_execute_cmd == "1") :
      $whereClauseBarcodeScan = "stkmv.stkmv_serialno = '" . $js_execute_data . "'";
      $executeCommand = true;
   endif;

   $showJournal = true;
   $whereClauseJournal = "";
   $whereClauseJournalArray = array();
   if ($f_act == "journalSearch" || $executeCommand) :

      if ($whereClauseBarcodeScan != "") :
         $whereClauseJournalArray[] = $whereClauseBarcodeScan;
      endif;      

      // Filter according to access rights
      if ($emp_id != $empIdRootAdmin) :
         if ($stkRootAccessIDsEmpId != "") :
	          $tmpClause  = "(stk.stk_id IN (" . $stkRootAccessIDsEmpId . ")";
            $tmpClause .= " OR stk2.stk_id IN (" . $stkRootAccessIDsEmpId . ")";
	          $stkRootAccessIDsEmpIdArrayLen = count($stkRootAccessIDsEmpIdArray);
	          for ($i = 0; $i < $stkRootAccessIDsEmpIdArrayLen; $i++) :
	               $tmpClause .= " OR stk.stk_path LIKE '%//" . $stkRootAccessIDsEmpIdArray[$i] . "//%'";
                 $tmpClause .= " OR stk2.stk_path LIKE '%//" . $stkRootAccessIDsEmpIdArray[$i] . "//%'";
            endfor;
	          $tmpClause .=  ")";
	          $whereClauseJournalArray[] = $tmpClause;
         else :
            // No access to any root stock. Exclude all stocks !!!
            $whereClauseJournalArray[] = "stk.stk_id = '0'";
            $showJournal = false;
         endif;
      endif;

      // Check for accessible substocks according to the rights of the current user
      if ($stkReadonlyWhereDefinedWriteaccess != "0") :
            $whereClauseAccessibleStocks .= getAccessibleSubstocks("1");
            if ($whereClauseAccessibleStocks != "") :
               $whereClauseJournalArray[] .= " (" . $whereClauseAccessibleStocks . ") ";
            endif;
      endif;

      // Search mode for source and target stock
      if ($stkSearchMode == "1") :
         $tmpWhereClauseStkFrom = "";
         if ($f_mv_search_stk_name_from != "") :
            if ($f_mv_search_stk_from_sub == "1") :
               $tmpWhereClauseStkFrom = "(stk.stk_id = '" . $f_mv_search_stk_name_from . "' OR stk.stk_path LIKE '%//" . $f_mv_search_stk_name_from . "//%')";
            else :
               $tmpWhereClauseStkFrom = "stk.stk_id = '" . $f_mv_search_stk_name_from . "'";
            endif;
         endif;
         $tmpWhereClauseStkTo = "";
         if ($f_mv_search_stk_name_to != "") :
            if ($f_mv_search_stk_to_sub == "1") :
               $tmpWhereClauseStkTo = "(stk2.stk_id = '" . $f_mv_search_stk_name_to . "' OR stk2.stk_path LIKE '%//" . $f_mv_search_stk_name_to . "//%')";
            else :
               $tmpWhereClauseStkTo = "stk2.stk_id = '" . $f_mv_search_stk_name_to . "'";
            endif;
         endif;
         $tmpWhereClauseStk = "";
         if ($tmpWhereClauseStkFrom != "") : $tmpWhereClauseStk .= $tmpWhereClauseStkFrom; endif;
         if ($tmpWhereClauseStkFrom != "" && $tmpWhereClauseStkTo != "") : $tmpWhereClauseStk .= " OR "; endif;
         if ($tmpWhereClauseStkTo != "") : $tmpWhereClauseStk .= $tmpWhereClauseStkTo; endif;
         if ($tmpWhereClauseStk != "") :
            $whereClauseJournalArray[] = "(" . $tmpWhereClauseStk . ")";
         endif;
      else :
         if ($f_mv_search_stk_name_from != "") :
            if ($f_mv_search_stk_from_sub == "1") :
               $whereClauseJournalArray[] = "(stk.stk_id = '" . $f_mv_search_stk_name_from . "' OR stk.stk_path LIKE '%//" . $f_mv_search_stk_name_from . "//%')";
            else :
               $whereClauseJournalArray[] = "stk.stk_id = '" . $f_mv_search_stk_name_from . "'";
            endif;
         endif;
         
         if ($f_mv_search_stk_name_to != "") :
            if ($f_mv_search_stk_to_sub == "1") :
               $whereClauseJournalArray[] = "(stk2.stk_id = '" . $f_mv_search_stk_name_to . "' OR stk2.stk_path LIKE '%//" . $f_mv_search_stk_name_to . "//%')";
            else :
               $whereClauseJournalArray[] = "stk2.stk_id = '" . $f_mv_search_stk_name_to . "'";
            endif;
         endif;
      endif;

      $f_mv_search_at_misc = trim($f_mv_search_at_misc);
      if ($f_mv_search_at_misc != "") :
         $whereClauseJournalArray[] = "(at.at_eid LIKE '%" . $f_mv_search_at_misc . "%' OR at.at_name LIKE '%" . $f_mv_search_at_misc . "%' OR at.at_match LIKE '%" . $f_mv_search_at_misc . "%' OR at.at_description LIKE '%" . $f_mv_search_at_misc . "%' OR at.at_barcode LIKE '%" . $f_mv_search_at_misc . "%')";
      endif;

      if ($f_mv_search_atg != "") :
         $whereClauseJournalArray[] = "atgi.atg_id = '" . $f_mv_search_atg . "'";
      endif;

      // Search mode
      if ($searchMode == "1") :
         $f_mv_search_misc = trim($f_mv_search_misc);
         if ($f_mv_search_misc != "") :
            $whereClauseJournalArray[] = "(stkmv.stkmv_tan LIKE '%" . $f_mv_search_misc . "%' OR stkmv.stkmv_remark LIKE '%" . $f_mv_search_misc . "%' OR stkmv.stkmv_serialno LIKE '%" . $f_mv_search_misc . "%' OR stkmv.stkmv_data LIKE '%" . $f_mv_search_misc . "%')";
         endif;
      else :
         $f_mv_search_tan_from = trim($f_mv_search_tan_from);
         if ($f_mv_search_tan_from != "") :
            $whereClauseJournalArray[] = "stkmv.stkmv_tan >= '" . $f_mv_search_tan_from . "'";
         endif;
         
         $f_mv_search_tan_to = trim($f_mv_search_tan_to);
         if ($f_mv_search_tan_to != "") :
            $whereClauseJournalArray[] = "stkmv.stkmv_tan <= '" . $f_mv_search_tan_to . "'";
         endif;
         
         $f_mv_search_remark = trim($f_mv_search_remark);
         if ($f_mv_search_remark != "") :
            $whereClauseJournalArray[] = "stkmv.stkmv_remark LIKE '%" . $f_mv_search_remark . "%'";
         endif;
         
         $f_mv_search_serialno = trim($f_mv_search_serialno);
         if ($f_mv_search_serialno != "") :
            $whereClauseJournalArray[] = "stkmv.stkmv_serialno LIKE '%" . $f_mv_search_serialno . "%'";
         endif;

         $f_mv_search_data = trim($f_mv_search_data);
         if ($f_mv_search_data != "") :
            $whereClauseJournalArray[] = "stkmv.stkmv_data LIKE '%" . $f_mv_search_data . "%'";
         endif;
      endif;

      $f_mv_search_jb_id = trim($f_mv_search_jb_id);
      if ($f_mv_search_jb_id != "") :
         $whereClauseJournalArray[] = "stkmv.jb_id LIKE '%" . $f_mv_search_jb_id . "%'";
      endif;

      // Ignore date interval
      if ($executeCommand || ($f_mv_search_tan_from != "" && $f_mv_search_tan_to != "") || $f_mv_search_serialno != "" || $f_mv_search_data != "" || $f_mv_search_jb_id != "" || $f_mv_search_misc != "") :
         $fromDateRange = "";
         $toDateRange = "";
      endif;

      if ($fromDateRange != "") :
         $whereClauseJournalArray[] = "stkmv.stkmv_timestamp >= '" . $fromDateRange . "'";
      endif;

      if ($toDateRange != "") :
         $whereClauseJournalArray[] = "stkmv.stkmv_timestamp <= '" . $toDateRange . "'";
      endif;
      
      if ($journalSearchDatetime != "") :
         $whereClauseJournalArray[] = "stkmv.stkmv_datetime2 = '" . $journalSearchDatetime . "'";
      endif;
      
      if (count($whereClauseJournalArray) > 0) :
         $whereClauseJournal = implode(" AND ", $whereClauseJournalArray);
      endif;

      $executeCommand = false;
   else :
      $showJournal = false;

      // No search operation requested. Only take journal of the current stock to be displayed according to the date interval
      if ($stkIdCurrent != "") :
         $whereClauseJournal .= "stkmv.stkmv_timestamp >= '" . $fromDateRange . "' AND ";
         $whereClauseJournal .= "stkmv.stkmv_timestamp <= '" . $toDateRange . "' AND ";
         $whereClauseJournal .= "(stk.stk_id = '" . $stkIdCurrent . "' OR stk2.stk_id = '" . $stkIdCurrent . "')";

         $showJournal = true;
 
         // Automatic preset of search parameters
         // $f_mv_search_stk_name_from = $stkNameCurrent
         // $f_mv_search_stk_name_to = $stkNameCurrent
      endif;
   endif;
   // Generate journal output
   $stockJournal = "";
   if ($showJournal) :
      // Get configuration according ORDER BY field and direction (ASC/DESC)
      if ($f_mv_sort_journal == "") : $f_mv_sort_journal = "stkmv.stkmv_id"; endif;
      $maskStkJournalOrderByDirection = getParameterValue("0", "MASK_STK_JOURNAL_ORDERBY_DIRECTION_" . $tmpStkIdRoot, "0");
      if ($maskStkJournalOrderByDirection == "") : 
         $maskStkJournalOrderByDirection = $stkJournalOrderByDirectionArray;
      else :
         $maskStkJournalOrderByDirection = spliti(",",$maskStkJournalOrderByDirection);
      endif;
      $tmpOrderByDirection = "";
      $pos = array_search($f_mv_sort_journal, $stkJournalFieldArray);
      if (!($pos === FALSE)) :
         if ($maskStkJournalOrderByDirection[$pos] == "1") :
            $tmpOrderByDirection = " DESC ";
         endif;
      endif;
      // Get journal
      $stockJournal = getStockJournal($whereClauseJournal, $f_mv_sort_journal, "", $tmpOrderByDirection);
   endif;
   if ($f_act == "journalSearch" && $numOfJournalEntries == 0) :
      $stockJournal .= "<tr><td colspan=\"5\"><span class=\"f8np1_red\">" . getLngt("Kein Eintrag im Suchergebnis!") . "</span></td></tr>";
   else :
     $stockJournal .= "<tr><td colspan=\"5\">" . getLngt("Anzahl angezeigter Einträge:") . " " . $numOfJournalEntries . "</td></tr>";
   endif;


   // ************
   // * OUTPUT *
   // ************

   // Display
   $f_stk_planning_0 = "";
   if ($f_stk_planning == "1") :
      $f_stk_planning_0 = "checked";

      // Get max quantity of the whole subtree of the current stock
      $stkNextSublevelMaxQuantity = getFieldSumOfNextSubLevelOfTree("stk_maxquantity", $stkIdCurrent, "stock", "stk_pre_id", "");

      // Get quantity of places occupied by articles
      $articlePlaceQuantityOfCurrentStock = getStockArticleQuantitySubtree($stkIdCurrent, "1", "", "");
   endif;

   // Special treatment of the data fields of the article move to be displayed
   if ($f_mv_serialno == "") :
      $maskDisplayMoveDataFieldsSwitch = "0";
   endif;

   // Date range for stock journal
   $currentFrameName = "";  // Empty string for "main frame"
   $filter_dateranges = "";
   $stkmvSpecialDate = "";
   $js_date = "";
   if (true) :
      // Date-ranges for journal search
      $filter_dateranges .= "<td>" . getLngt("Von:") . "\n";
      $filter_dateranges .= "<select name=\"day_from\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $currentFrameName . "', 'stock', 'day_from', 'day_from', 'month_from', 'year_from', '', '', '')\"></select>\n";
      $filter_dateranges .= "<select name=\"month_from\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $currentFrameName . "', 'stock', 'month_from', 'day_from', 'month_from', 'year_from', '', '', '')\"></select>\n";
      $filter_dateranges .= "<select name=\"year_from\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $currentFrameName . "', 'stock', 'year_from', 'day_from', 'month_from', 'year_from', '', '', '')\"></select>\n";
      $filter_dateranges .= "</td><td>&nbsp;&nbsp;" . getLngt("bis:") . "\n";
      $filter_dateranges .= "<select name=\"day_to\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $currentFrameName . "', 'stock', 'day_to', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
      $filter_dateranges .= "<select name=\"month_to\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $currentFrameName . "', 'stock', 'month_to', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
      $filter_dateranges .= "<select name=\"year_to\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $currentFrameName . "', 'stock', 'year_to', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
      $filter_dateranges .= "</td>";
      
      // Special date fields associated to the disposition of a stock movement
      $stkmvSpecialDate .= "<select name=\"stkmv_day_from\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $currentFrameName . "', 'stock', 'stkmv_day_from', 'stkmv_day_from', 'stkmv_month_from', 'stkmv_year_from', '', '', '')\"></select>\n";
      $stkmvSpecialDate .= "<select name=\"stkmv_month_from\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $currentFrameName . "', 'stock', 'stkmv_month_from', 'stkmv_day_from', 'stkmv_month_from', 'stkmv_year_from', '', '', '')\"></select>\n";
      $stkmvSpecialDate .= "<select name=\"stkmv_year_from\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $currentFrameName . "', 'stock', 'stkmv_year_from', 'stkmv_day_from', 'stkmv_month_from', 'stkmv_year_from', '', '', '')\"></select>\n";
      
      // Javascript-function as template only for
      $js_date .= "<script type=\"text/javascript\">\n";
      $js_date .= "<!--\n";
      $js_date .= "function initForm() {\n";
      $js_date .= "  fillDateFields(1,\"" . $currentFrameName . "\",\"stock\",\"\",\"day_from\",\"month_from\",\"year_from\",\"\",\"\",\"\");\n";
      $js_date .= "  setDateTimeFields(\"" . $currentFrameName . "\",\"stock\",".$day_from.",".$month_from.",".$year_from.", \"\", \"\", \"day_from\", \"month_from\", \"year_from\", \"\", \"\", \"\");\n";
      $js_date .= "  fillDateFields(1,\"" . $currentFrameName . "\",\"stock\", \"\", \"day_to\", \"month_to\", \"year_to\", \"\", \"\", \"\");\n";
      $js_date .= "  setDateTimeFields(\"" . $currentFrameName . "\",\"stock\",".$day_to.",".$month_to.",".$year_to.", \"\", \"\", \"day_to\", \"month_to\", \"year_to\", \"\", \"\", \"\");\n";

      // Init date fields for disposition
      $js_date .= "  fillDateFields(1,\"" . $currentFrameName . "\",\"stock\",\"\",\"stkmv_day_from\",\"stkmv_month_from\",\"stkmv_year_from\",\"\",\"\",\"\");\n";
      $js_date .= "  setDateTimeFields(\"" . $currentFrameName . "\",\"stock\",".$stkmv_day_from.",".$stkmv_month_from.",".$stkmv_year_from.", \"\", \"\", \"stkmv_day_from\", \"stkmv_month_from\", \"stkmv_year_from\", \"\", \"\", \"\");\n";

      $js_date .= "}\n";
      $js_date .= "-->\n";
      $js_date .= "</script>\n";
   endif;   
endif;


?>

<html>

<head>
<title><?php echo getLngt("LAGERORTE") ?></title>

<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
  <?php include_once ("../css/navigation.css.php"); ?>
</style>

<?php include_once ("../include/js_framework.inc.php"); ?>

<script src="../include/lib_global.js" type="text/javascript"></script>
<script src="../include/searchLists.js" type="text/javascript"></script>
<script src="../include/checkFormTags.js" type="text/javascript"></script>

<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>


// Part for STOCKS
function rootStockReload() {  
 for(i=0;i<document.forms[0].selectRootStock.length;++i) {
   if (document.forms[0].selectRootStock.options[i].selected == true) {
      stk_id_root = document.forms[0].selectRootStock.options[i].value;
      stkFinishPerNavLink2(stk_id_root);
   }
 }
};

function xReload() {  
 for(i=0;i<document.forms[0].selectStock.length;++i) {
   if (document.forms[0].selectStock.options[i].selected == true) {  	
      stk_id = document.forms[0].selectStock.options[i].value;
      document.forms[0].selectStock2.options[i].selected = true;
      stkFinishPerNavLink(stk_id);
   }
 } 
};

function x2Reload() {  
 for(i=0;i<document.forms[0].selectStock2.length;++i) {
   if (document.forms[0].selectStock2.options[i].selected == true) {
      stk_id = document.forms[0].selectStock2.options[i].value;
      document.forms[0].selectStock.options[i].selected = true;
      stkFinishPerNavLink(stk_id);
   }
 } 
};

function visibilityFinishPage() {
  if (confirm('<?php echo $confirmTextVisibility ?>')) {
     document.forms[0].stkVisibleCurrent.value='<?php echo ec($stkVisibleCurrent2) ?>';
     stkFinishPage('setVisibility');
  }
};

function stkFinishPage(f_act) {
  document.forms[0].f_act.value=f_act;
  submitPage('lager');
}

function stkFinishPerNavLink(stkIdCurrent) {
  document.forms[0].deactivateMenu.value = '<?php echo ec($deactivateMenu) ?>';
  document.forms[0].customerId.value = '<?php echo ec($customerId) ?>';
  document.forms[0].stkIdRoot.value = '<?php echo ec($stkIdRoot) ?>';
  document.forms[0].stkIdCurrent.value = stkIdCurrent;
  stkFinishPage('');
}

function stkFinishPerNavLink2(stkIdRoot) {
  document.forms[0].deactivateMenu.value = '<?php echo ec($deactivateMenu)  ?>';
  document.forms[0].customerId.value = '<?php echo ec($customerId)  ?>';
  document.forms[0].stkIdRoot.value = stkIdRoot;
  document.forms[0].stkIdCurrent.value = stkIdRoot;
  stkFinishPage('');
}

function settingsFinishPage() {
  stkFinishPage('saveStockData');
};

function articleMoveFinishPage() {
	frm = document.forms[0];

  // Get the information of current article to be disposed being a bundled article
  var currentAtId = "0";
  for(i=0;i<frm.f_mv_at.length;++i) {
    if (frm.f_mv_at.options[i].selected) {
       currentAtId = frm.f_mv_at.options[i].value;
    }
  }
  scan_request('../stock/ajaxReqStock.php', 'mode=0&atId=' + currentAtId);

  if (isBundledArticle == '0') {
     if (frm.f_mv_stk_itemquantity.value && !checkIsNaNIgnoreSpace(frm.f_mv_stk_itemquantity.value, '<?php echo getLngt("Bitte tragen Sie eine Zahl bei der Menge ein!") ?>')){
        frm.f_mv_stk_itemquantity.focus();
        return;
     }
     if (frm.f_mv_stk_itemquantity.value < 0) {
     	 frm.f_mv_stk_itemquantity.value = 0;
     	 alert('<?php echo getLngt("Bitte beachten Sie, dass negative Mengen nicht kommissioniert werden dürfen! Ggfs. vertauschen Sie Quell- und Ziellagerort.") ?>');
     	 return;
     }
     if (frm.f_mv_serialno.value != '' && frm.f_mv_stk_itemquantity.value > 1) {
     	 frm.f_mv_stk_itemquantity.value = 1;
     	 alert('<?php echo getLngt("Bitte beachten Sie, dass bei der Vergabe einer Seriennummer die Menge auf 1 gesetzt wurde! Der Vorgang wurde noch nicht ausgeführt.") ?>');
     	 return;
     }
     stkFinishPage('moveArticle');
  } else {
     var widthPopupWin = 1280;
     var heightPopupWin = 768;
     var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
     var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
     var popupWin;
     var callParams = "&f_mv_at=" + currentAtId + "&f_mv_stk_itemquantity=" + frm.f_mv_stk_itemquantity.value + "&f_mv_stk_from=" + frm.f_mv_stk_from.value + "&f_mv_stk_to=" + frm.f_mv_stk_to.value;
     popupWin = window.open("../stock/stock_move.php?stkIdRoot=<?php echo $stkIdRoot ?>&stkIdCurrent=<?php echo $stkIdCurrent ?>" + callParams, "","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
  }
}

function checkFields() {  
  frm = document.forms[0];
  if (!frm.f_ad_street.value){		
     alert('<?php echo getLngt("Bitte geben Sie die Straße ein!") ?>');
     frm.f_ad_street.focus();
     return;
  }
  if (!frm.f_stk_hsno.value){		
     alert('<?php echo getLngt("Bitte geben Sie die Hausnummer ein!") ?>');
     frm.f_stk_hsno.focus();
     return;
  }
  if (!frm.f_ad_zipcode.value){		
     alert('<?php echo getLngt("Bitte tragen Sie die Postleitzahl ein!") ?>');
     frm.f_ad_zipcode.focus();
     return;
  }
  if (!frm.f_ad_city.value){
     alert('<?php echo getLngt("Bitte geben Sie die Stadt ein!") ?>');
     frm.f_ad_city.focus();
     return;
  }
  /*
  if (frm.f_cscad_phone.value && !checkIsNaNIgnoreSpace(frm.f_cscad_phone.value, '<?php echo getLngt("Bitte tragen Sie eine Nummer bei Telefon ein!") ?>')){
     frm.f_cscad_phone.focus();
     return;
  }  
  if (frm.f_cscad_email.value.length != 0) {
     // if e-mail has content then check syntax
     if (!checkMailAddress(frm.f_cscad_email, '<?php echo getLngt("Bitte tragen Sie eine gültige Email-Adresse ein!") ?>')) {return;};
  }
  */ 
  if (frm.currentNavigationItem) {
     frm.currentNavigationItem.value='lager';
  }
  stkFinishPage('saveAddress');
};

// Shows/Hides display areas
// function changeHideShow(areaSwitched,displayState) {
// ... Defined in "checkFormTags.js"
// }

// Shows/Hides display areas
function changeHideShow2(areaShow,areaReduced,displayState) {

  if (displayState == 'on') {
  	 myshow(areaShow);
     myhide(areaReduced);
     elem = eval('document.forms[0].' + areaShow + 'Switch');
     elem.value = '1';
     // document.forms[0].maskDisplayData.value = '1';
  };
  if (displayState == 'off') {
  	 myshow(areaReduced);
  	 myhide(areaShow);
     elem = eval('document.forms[0].' + areaShow + 'Switch');
     elem.value = '0';
     // document.forms[0].maskDisplayData.value = '0';
  };
}

// Shows/Hides one special area
function changeHideShowSpecialElement(areaDisplayed,displayState) {
	// Special part
  <?php
    $tmpdataFieldsEnabled = getParameterValue("0", "MASK_STK_DATAFIELDS_" . $stkIdRoot, "0");
    if ($tmpdataFieldsEnabled == "1") :
       echo "if (areaDisplayed == 'maskDisplayMoveDataFields') {displayState = 'on'};";
    endif;
  ?>  
  if (areaDisplayed == 'maskDisplayAtSearch') {
  	 if (document.forms[0].f_mv_modeArticleEntries.options[5].selected == true) {
  	    displayState = 'on';
  	 };
  };
  // Generic part
  if (displayState == 'on') {
  	 myshow(areaDisplayed);
     elem = eval('document.forms[0].' + areaDisplayed + 'Switch');
     elem.value = '1';
  };
  if (displayState == 'off') {
  	 myhide(areaDisplayed);
     elem = eval('document.forms[0].' + areaDisplayed + 'Switch');
     elem.value = '0';
  };
}

function searchCsCsc(genVal,genNum) {
  var f_act = 'search';
  
  var widthPopupWin = 950;
  var heightPopupWin = 600;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/cs_csc_list.php?f_act=" + f_act + "&generic=" + genVal + "&genNum=" + genNum,
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes");
};

function clearCustomerCostcenter() {
  document.forms[0].g_cs_id.value='';
  document.forms[0].g_csc_id.value='';
  // document.forms[0].g_cscad_comp.value='';
};

function clearJournalSearchFields() {
  if (document.forms[0].f_mv_search_stk_name_from) {document.forms[0].f_mv_search_stk_name_from.value = ''};
  if (document.forms[0].f_mv_search_at_misc) {document.forms[0].f_mv_search_at_misc.value = ''};
  if (document.forms[0].f_mv_search_atg) {document.forms[0].f_mv_search_atg.options[0].selected = true};
  if (document.forms[0].f_mv_search_stk_name_to) {document.forms[0].f_mv_search_stk_name_to.value = ''};
  if (document.forms[0].f_mv_search_misc) {document.forms[0].f_mv_search_misc.value = ''};
  if (document.forms[0].f_mv_search_tan_from) {document.forms[0].f_mv_search_tan_from.value = ''};
  if (document.forms[0].f_mv_search_tan_to) {document.forms[0].f_mv_search_tan_to.value = ''};
  if (document.forms[0].f_mv_search_remark) {document.forms[0].f_mv_search_remark.value = ''};
  if (document.forms[0].f_mv_search_serialno) {document.forms[0].f_mv_search_serialno.value = ''};
  if (document.forms[0].f_mv_search_data) {document.forms[0].f_mv_search_data.value = ''};
  if (document.forms[0].f_mv_search_jb_id) {document.forms[0].f_mv_search_jb_id.value = ''};
};

// Set page parameters according to the requested journal entry to move the article again
function finishPageJournalAction(op, stk_id, stk2_id, at_id, stkmv_tan, stkmv_serialno, stkmv_itemquantity, stkmv_id, at_id_bundle, stkmv_datetime, stkmv_data) {
	frm = document.forms[0];
	
	// * Storno *
  if (op == '0') {
  	 clearArticleMoveFields();

  	 // Check for journal entry was a bundled insertion
  	 var tmpIsBundledArticle = false;
  	 if (at_id_bundle != '' && at_id_bundle != '0') {  	   	 
  	    // Check for the potential bundle article in "at_id_bundle" being a bundle article presently
  	    // isBundledArticle = '0';
        scan_request('../stock/ajaxReqStock.php', 'mode=0&atId=' + at_id_bundle);
        if (isBundledArticle == '1') {
           tmpIsBundledArticle = true;
        }
     }

     if (tmpIsBundledArticle == true) {
     	  // Make a storno of all article items of the bundle
     	  if (confirm('<?php echo getLngt("Der selektierte Buchungssatz gehört zu einer Menge von Einzelbuchungen auf Basis einer Gebindebuchung. Sollen ALLE zugehörigen Buchungssätze rückgängig gemacht werden?") ?>')) {
     	  	 if (confirm('<?php echo getLngt("Sind Sie wirklich sicher?") ?>')) {
     	  	    frm.stkmv_id_storno.value = stkmv_id;
              stkFinishPage('journalStorno');
           }
        }
     } else {
       if (frm.f_mv_stk_from) {frm.f_mv_stk_from.value = stk2_id};
       if (frm.f_mv_stk_to) {frm.f_mv_stk_to.value = stk_id};

       scan_request('../include/ajaxReqLib.php', 'mode=0&db_table=article&db_id_field=at_id&db_return_field=at_name&search_value=' + at_id);
       insertNewOption('f_mv_at', at_id, retValue, true, true);
       setSelectedValue('f_mv_at', at_id);

       if (frm.f_mv_stk_itemquantity) {frm.f_mv_stk_itemquantity.value = stkmv_itemquantity};
       if (frm.f_mv_tan) {frm.f_mv_tan.value = stkmv_tan};
       if (frm.f_mv_remark) {frm.f_mv_remark.value = '<?php echo "Storno " ?>' + stkmv_id};
       if (frm.f_mv_serialno) {frm.f_mv_serialno.value = stkmv_serialno};
       if (frm.f_mv_serialno_old) {frm.f_mv_serialno_old.value = stkmv_serialno};   // Set the same value, ONLY relevant if stk_from eq. stk_to !!!


       // Fill extra data fields if they are set
       if (stkmv_data != '') {
          var stkmvDataArray = stkmv_data.split("<br>");
          // var stkmvDataArrayLen = stkmvDataArray.length;
          if (stkmvDataArray[0] != '') {frm.f_mv_datafield_01.value = stkmvDataArray[0];};
          if (stkmvDataArray[1] != '') {frm.f_mv_datafield_02.value = stkmvDataArray[1];};
          if (stkmvDataArray[2] != '') {frm.f_mv_datafield_03.value = stkmvDataArray[2];};
          if (stkmvDataArray[3] != '') {frm.f_mv_datafield_04.value = stkmvDataArray[3];};
          if (stkmvDataArray[4] != '') {frm.f_mv_datafield_05.value = stkmvDataArray[4];};
          if (stkmvDataArray[5] != '') {frm.f_mv_datafield_06.value = stkmvDataArray[5];};
          if (stkmvDataArray[6] != '') {frm.f_mv_datafield_07.value = stkmvDataArray[6];};
          if (stkmvDataArray[7] != '') {frm.f_mv_datafield_08.value = stkmvDataArray[7];};
          if (stkmvDataArray[8] != '') {frm.f_mv_datafield_09.value = stkmvDataArray[8];};
          if (stkmvDataArray[9] != '') {frm.f_mv_datafield_10.value = stkmvDataArray[9];};
          if (stkmvDataArray[10] != '') {frm.f_mv_datafield_11.value = stkmvDataArray[10];};
          if (stkmvDataArray[11] != '') {frm.f_mv_datafield_12.value = stkmvDataArray[11];};
          if (stkmvDataArray[12] != '') {frm.f_mv_datafield_13.value = stkmvDataArray[12];};
          if (stkmvDataArray[13] != '') {frm.f_mv_datafield_14.value = stkmvDataArray[13];};
          if (stkmvDataArray[14] != '') {frm.f_mv_datafield_15.value = stkmvDataArray[14];};
       };
       checkSerialno();   // Serial number field has to be set before call
       
       // stkFinishPage('journalSearch');
     }  	
  }
  
  // * Prepare for outgoing disposition *
	if (op == '1') {
		 clearArticleMoveFields();

     if (frm.f_mv_stk_from) {frm.f_mv_stk_from.value = stk2_id};
     if (frm.f_mv_stk_to) {frm.f_mv_stk_to.value = '0'};
     <?php
     // Get parameter to set the "stock to" equal to "stock from" if link "Disposition" has been selected
     $tmpStkIdRoot = getStkPathId($stkIdRoot);  // Makes it safe to have a real root stock
     $maskStkatShowPermanent = getParameterValue("0", "MASK_LINK_DISPOSITION_STKTO_EQ_STKFROM_" . $tmpStkIdRoot, "0");
     if ($maskStkatShowPermanent == "1") :
        echo "if (frm.f_mv_stk_to) {frm.f_mv_stk_to.value = stk2_id};";
     endif;
     ?>
     
     // if (frm.f_mv_at) {frm.f_mv_at.value = at_id};
     for(i=0;i<frm.f_mv_at.length;++i) {
       if (frm.f_mv_at.options[i].value == at_id) {
          frm.f_mv_at.options[i].selected = true;
       }
     }
     if (frm.f_mv_stk_itemquantity) {frm.f_mv_stk_itemquantity.value = 0};
     if (frm.f_mv_tan) {frm.f_mv_tan.value = stkmv_tan};
     if (frm.f_mv_remark) {frm.f_mv_remark.value = ''};
     if (frm.f_mv_serialno) {
     	  frm.f_mv_serialno.value = stkmv_serialno;
     	  if (stkmv_serialno != '') {
     	  	 if (frm.f_mv_stk_itemquantity) {frm.f_mv_stk_itemquantity.value = '1'};
        }
     };
     if (frm.f_mv_serialno_old) {frm.f_mv_serialno_old.value = stkmv_serialno};   // Set the same value, ONLY relevant if stk_from eq. stk_to !!!
     
     // Fill extra data fields if they are set
     if (stkmv_data != '') {
        var stkmvDataArray = stkmv_data.split("<br>");
        // var stkmvDataArrayLen = stkmvDataArray.length;
        if (stkmvDataArray[0] != '') {frm.f_mv_datafield_01.value = stkmvDataArray[0];};
        if (stkmvDataArray[1] != '') {frm.f_mv_datafield_02.value = stkmvDataArray[1];};
        if (stkmvDataArray[2] != '') {frm.f_mv_datafield_03.value = stkmvDataArray[2];};
        if (stkmvDataArray[3] != '') {frm.f_mv_datafield_04.value = stkmvDataArray[3];};
        if (stkmvDataArray[4] != '') {frm.f_mv_datafield_05.value = stkmvDataArray[4];};
        if (stkmvDataArray[5] != '') {frm.f_mv_datafield_06.value = stkmvDataArray[5];};
        if (stkmvDataArray[6] != '') {frm.f_mv_datafield_07.value = stkmvDataArray[6];};
        if (stkmvDataArray[7] != '') {frm.f_mv_datafield_08.value = stkmvDataArray[7];};
        if (stkmvDataArray[8] != '') {frm.f_mv_datafield_09.value = stkmvDataArray[8];};
        if (stkmvDataArray[9] != '') {frm.f_mv_datafield_10.value = stkmvDataArray[9];};
        if (stkmvDataArray[10] != '') {frm.f_mv_datafield_11.value = stkmvDataArray[10];};
        if (stkmvDataArray[11] != '') {frm.f_mv_datafield_12.value = stkmvDataArray[11];};
        if (stkmvDataArray[12] != '') {frm.f_mv_datafield_13.value = stkmvDataArray[12];};
        if (stkmvDataArray[13] != '') {frm.f_mv_datafield_14.value = stkmvDataArray[13];};
        if (stkmvDataArray[14] != '') {frm.f_mv_datafield_15.value = stkmvDataArray[14];};
     };
     checkSerialno();   // Serial number field has to be set before call
        
     // stkFinishPage('journalSearch');
  }
}

function finishPageSortStockArticle(num) {
	var sortVal = '';
	var stk_planning = '<?php echo $f_stk_planning ?>';
	if (num == '0') {sortVal = 'stk.stk_name';};
	if (num == '1') {sortVal = 'at.at_eid';};
	if (num == '2') {sortVal = 'at.at_name';};
	if (num == '3') {sortVal = 'at.at_match';};
	if (stk_planning == '1') {
	   if (num == '4') {sortVal = 'stkat.stkat_quantity';};
	   if (num == '5') {sortVal = 'stkat.stkat_itemquantity';};
	   // if (num == '6') {sortVal = 'bundlequantity';};
	   if (num == '6') {sortVal = 'atg.atg_name';};
	} else {
	   if (num == '4') {sortVal = 'stkat.stkat_itemquantity';};
	   // if (num == '5') {sortVal = 'bundlequantity';};
	   if (num == '5') {sortVal = 'atg.atg_name';};
  }
	if (document.forms[0].f_mv_sort_stockArticle) {document.forms[0].f_mv_sort_stockArticle.value = sortVal};
	stkFinishPage('stockArticleList');
}

function finishPageSortArticleSum(num) {
	var sortVal = '';
	if (num == '0') {sortVal = 'at.at_eid';};
	if (num == '1') {sortVal = 'at.at_name';};
	if (num == '2') {sortVal = 'at.at_match';};
	if (num == '3') {sortVal = 'itemquantity';};
	if (num == '4') {sortVal = 'atg.atg_name';};
	if (num == '5') {sortVal = '';};
	if (document.forms[0].f_mv_sort_stockArticle) {document.forms[0].f_mv_sort_stockArticle.value = sortVal};
	stkFinishPage('stockArticleList');
}

function finishPageSortInventory(num) {
	var sortVal = '';
	if (num == '0') {sortVal = 'stk.stk_name';};
	if (num == '1') {sortVal = 'at.at_eid';};
	if (num == '2') {sortVal = 'at.at_name';};
	if (num == '3') {sortVal = 'at.at_match';};
	if (num == '4') {sortVal = 'stkat.stkat_itemquantity';};
	if (num == '5') {sortVal = 'ati.ati_serialno';};
	if (num == '6') {sortVal = 'atg.atg_name';};
	if (num == '7') {sortVal = 'ati.ati_data_01';};
	if (num == '8') {sortVal = 'ati.ati_data_02';};
	if (num == '9') {sortVal = 'ati.ati_data_03';};
	if (num == '10') {sortVal = 'ati.ati_data_04';};
	if (num == '11') {sortVal = 'ati.ati_data_05';};
	if (num == '12') {sortVal = 'ati.ati_data_06';};
	if (num == '13') {sortVal = 'ati.ati_data_07';};
	if (num == '14') {sortVal = 'ati.ati_data_08';};
	if (num == '15') {sortVal = 'ati.ati_data_09';};
	if (num == '16') {sortVal = 'ati.ati_data_10';};
	if (num == '17') {sortVal = 'ati.ati_data_11';};
	if (num == '18') {sortVal = 'ati.ati_data_12';};
	if (num == '19') {sortVal = 'ati.ati_data_13';};
	if (num == '20') {sortVal = 'ati.ati_data_14';};
	if (num == '21') {sortVal = 'ati.ati_data_15';};
	if (num == '22') {sortVal = 'ati.ati_data_16';};
	if (num == '23') {sortVal = 'ati.ati_data_17';};
	if (num == '24') {sortVal = 'ati.ati_data_18';};
	if (num == '25') {sortVal = 'ati.ati_data_19';};
	if (num == '26') {sortVal = 'ati.ati_data_20';};
	if (num == '27') {sortVal = '';};
	if (document.forms[0].f_mv_sort_stockArticle) {document.forms[0].f_mv_sort_stockArticle.value = sortVal};
	stkFinishPage('stockArticleList');
}

function finishPageSortJournal(num) {
	var sortVal = '';
  <?php 
    $stkJournalFieldArrayLen = count($stkJournalFieldArray);
    for ($i = 0; $i < $stkJournalFieldArrayLen; $i++) :
        echo "if (num == '" . $i . "') {sortVal = '" . $stkJournalFieldArray[$i] . "';};\n";
    endfor;
  ?>
	if (document.forms[0].f_mv_sort_journal) {document.forms[0].f_mv_sort_journal.value = sortVal};
	stkFinishPage('journalSearch');
}

function setSearchTanToNum(elem) {
  document.forms[0].f_mv_search_tan_to.value = elem.value;
}

function downloadStockFile() {
  var widthPopupWin = 850;
  var heightPopupWin = 600;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;

  popupWin = window.open("../include/data_download.php?f_path=../temp/download/&f_fileName=<?php echo $f_secretFileName ?>", "","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function barcodeList() {
	// if (stkIdRoot != '') {  
     var widthPopupWin = 850;
     var heightPopupWin = 600;
     var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
     var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
     var popupWin;
     
     popupWin = window.open("../stock/stock_barcodelist.php?stkIdRoot=<?php echo $stkIdRoot ?>&stkIdCurrent=<?php echo $stkIdCurrent ?>", "","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
  // } else {
  // 	 alert('<?php echo getLngt("Bitte wählen Sie erst ein Hauptlager aus!") ?>');
  // }
};

function commandList() {
  var widthPopupWin = 850;
  var heightPopupWin = 600;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;

  popupWin = window.open("../stock/stock_scancommandlist.php", "","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};


// ********
// * AJAX *
// ********

// Init
var stkIdRoot = '<?php echo $stkIdRoot ?>';
var listLenth;
var stkIdList;
var stkNameList;
var stkBarcodeList;
var scanCodeIsSerialNo = false;
var scanCodeIsArticleBarcode = false;
var scanCodeIsStockBarcode = false;
var stkMvData = new Array ();
var stkMvArticleData = new Array ();
var stkMvStockData = new Array ();
var isBundledArticle = '0';

// Init global JS-parameters
function initGlobals () {
  scanCodeIsSerialNo = false;
  scanCodeIsArticleBarcode = false;
  scanCodeIsStockBarcode = false;
  stkMvData = new Array ();
  stkMvArticleData = new Array ();
  stkMvStockData = new Array ();
}

<?php if ($usedFramework == "2") : ?>

// Prototype.Request
function scan_request(specificURL, parms) {
    var myAjax = new Ajax.Request(
        specificURL,        
        {method: 'get', asynchronous: false, parameters: parms}
    );
    eval(myAjax.transport.responseText);
}

<?php else : ?>

// JQuery.Request
function scan_request(url, data) {
  $.ajax({
     type: "GET",
     url: url,
     data: data,
     async: false,
     success: function(msg){eval(msg);}
  });
}

<?php endif; ?>

function clearArticleMoveFields() {
	frm = document.forms[0];
	frm.f_mv_stk_from.options[0].selected = true;
	frm.f_mv_stk_to.options[0].selected = true;
	frm.f_mv_at.options[0].selected = true;
  frm.f_mv_stk_itemquantity.value = '';
  frm.f_mv_tan.value = '';
  frm.f_mv_remark.value = '';
  frm.f_mv_serialno.value = '';
  frm.f_mv_serialno_old.value = '';
  
  frm.f_mv_datafield_01.value = '';
  frm.f_mv_datafield_02.value = '';
  frm.f_mv_datafield_03.value = '';
  frm.f_mv_datafield_04.value = '';
  frm.f_mv_datafield_05.value = '';
  frm.f_mv_datafield_06.value = '';
  frm.f_mv_datafield_07.value = '';
  frm.f_mv_datafield_08.value = '';
  frm.f_mv_datafield_09.value = '';
  frm.f_mv_datafield_10.value = '';
  frm.f_mv_datafield_11.value = '';
  frm.f_mv_datafield_12.value = '';
  frm.f_mv_datafield_13.value = '';
  frm.f_mv_datafield_14.value = '';
  frm.f_mv_datafield_15.value = '';
  
  frm.f_mv_jb_id.value = '';
  <?php if ($usedFramework == "2") : ?>
    $('mvJobId').setStyle({borderColor: '#FF0000', borderWidth: '0px', borderStyle: 'solid', padding: '0px'});
  <?php else : ?>
  	$('#mvJobId').css({'borderColor': '#FF0000', 'borderWidth': '0px', 'borderStyle': 'solid', 'padding': '0px'});
  <?php endif; ?>
    
  if (frm.f_store) { frm.f_store.value = ''};
}

function executeScanCode() {
	frm = document.forms[0];
  var elem = document.forms[0].f_scan;
  var ev = elem.value;

  // Init Ajax call ...
  scan_request('../stock/ajaxReqScanExecution.php', 'mode=0');

  // Reset article selection to "only articles associated to the current root stock" because of the automatic recognition of the article by article barcode
  // setSelectedValue('f_mv_modeArticleEntries', '0');

  // Check command
  if (ev == '') {
  	 return;
  } else if (ev == 'MV-RESET') {
  	 // Reset of all booking fields
  	 clearArticleMoveFields();
  } else if (ev == 'MV-IN') {
  	 // Incoming goods
  	 frm.f_stkat_scanmode[0].checked = true;
     clearArticleMoveFields();
  } else if (ev == 'MV-OUT') {
  	 // Outgoing goods
  	 frm.f_stkat_scanmode[1].checked = true;
     clearArticleMoveFields();
  } else if (ev == 'MV-DISPOSAL') {
  	 // Disposal
     articleMoveFinishPage();
  } else if (ev == 'MV-QUANTITY') {
  	 // Set quantity field (source f_store)
     frm.f_mv_stk_itemquantity.value = frm.f_store.value;
     frm.f_store.value = '';
  } else if (ev == 'MV-TAN') {
  	 // Set tan field (source f_store)
     frm.f_mv_tan.value = frm.f_store.value;
     frm.f_store.value = '';
  } else if (ev == 'MV-REMARK') {
  	 // Set remark field (source f_store)
     frm.f_mv_remark.value = frm.f_store.value;
     frm.f_store.value = '';
  } else if (ev == 'MV-SERNO') {
  	 // Set serial number field (source f_store)
     frm.f_mv_serialno.value = frm.f_store.value;
     // frm.f_mv_serialno_old.value = frm.f_store.value;
     frm.f_mv_stk_itemquantity.value = '1';
     frm.f_store.value = '';
  } else if (ev == 'MV-JOB') {
  	 // Set serial number field (source f_store)
     frm.f_mv_jb_id.value = frm.f_store.value;
     frm.f_store.value = '';
     if (frm.f_mv_jb_id.value.length > 0) {        
        <?php if ($usedFramework == "2") : ?>
          $('mvJobId').setStyle({borderColor: '#FF0000', borderWidth: '2px', borderStyle: 'solid', padding: '4px'});
        <?php else : ?>
        	$('#mvJobId').css({'borderColor': '#FF0000', 'borderWidth': '2px', 'borderStyle': 'solid', 'padding': '4px'});
        <?php endif; ?>
     };
  } else if (ev == 'MV-OPENJOBS') {
  	 frm.f_store.value = '';
     openCurrentListOfStockJobs();
  } else if (ev == '-0-' || ev == '-1-' || ev == '-2-' || ev == '-3-' || ev == '-4-' ||
             ev == '-5-' || ev == '-6-' || ev == '-7-' || ev == '-8-' || ev == '-9-') {
  	 // Number
	 var numCmd = ev.substr(1, 1);
	 frm.f_store.value = frm.f_store.value + numCmd;
  } else if (ev == '-BACK-') {
  	 // Remove last character
     var tmpLen = frm.f_store.value.length;
     tmpLen = tmpLen - 1;
     frm.f_store.value = frm.f_store.value.substr(0, tmpLen);
  } else if (ev == '-CLR-') {
  	 // Remove last character
     frm.f_store.value = '';
  } else {

  	 // **********************
     // *** INCOMING GOODS ***
     // **********************

     if (frm.f_stkat_scanmode[0].checked == true) {

  	    // First check scan value is an article barcode
	      scan_request('../stock/ajaxReqScanExecution.php', 'mode=2&scanCode=' + ev);

  	    if (!scanCodeIsArticleBarcode) {  	    	  	    	
  	       // Check scan value is a stock barcode.
	         scan_request('../stock/ajaxReqScanExecution.php', 'mode=3&scanCode=' + ev + '&stkIdRoot=' + stkIdRoot);
  	    }

  	    if (!scanCodeIsArticleBarcode && !scanCodeIsStockBarcode) {
  	       // Check scan value is a serial no.
	         scan_request('../stock/ajaxReqScanExecution.php', 'mode=1&scanCode=' + ev);
  	    }
  	    
  	    if (!scanCodeIsArticleBarcode && !scanCodeIsStockBarcode && !scanCodeIsSerialNo) {
  	       // Store unknown scanned barcode to storage
	         frm.f_store.value = frm.f_scan.value;
  	    }

  	    // Execute if an article does exist according to the barcode
  	    if (scanCodeIsArticleBarcode) {
  	    	  // Prepare article search in all stocks
  	    	  // Execute after reload
  	    	  frm.js_execute_cmd.value = '2';
  	    	  frm.js_execute_data.value = stkMvArticleData[0];  // Article ID
  	    	  
  	    	  // Display the stock articles, filtered accorting to this specified article
  	    	  frm.maskDisplayArticleSwitch.value = '1';
  	    	  
  	    	  // Set current stock to root stock (top level)
  	    	  frm.stkIdCurrent.value = stkIdRoot;
  	    	  
  	    	  // Show ALL stocks (whole tree)
  	    	  setSelectedValue('f_displayModeStockArticle', '1');

            if (stkMvArticleData[0]!= '') {
            	 setSelectedValue('f_mv_at', stkMvArticleData[0]);
            }

  	    	  // Reload page
  	    	  stkFinishPage('');
        }

        // Execute if a stock does exist according to the barcode
        if (scanCodeIsStockBarcode) {
  	    	  // Prepare stock search
  	    	  // Execute after reload
  	    	  frm.js_execute_cmd.value = '3';
  	    	  frm.js_execute_data.value = stkMvArticleData[0];  // Stock ID
  	    	  
            if (stkMvStockData[0]!= '') {
            	 setSelectedValue('f_mv_stk_to', stkMvStockData[0]);
            }

  	    	  // Set current stock to the selected stock
  	    	  frm.stkIdCurrent.value = stkMvStockData[0];
  	    	  
  	    	  // Show ONLY current stock
  	    	  setSelectedValue('f_displayModeStockArticle', '0');
  	    	  
  	    	  // Reload page
  	    	  stkFinishPage('');
        }
     }
     
     // **********************
     // *** OUTGOING GOODS ***
     // **********************
     
     if (frm.f_stkat_scanmode[1].checked == true) {

  	    // First check scan value is a serial no.  	 
	      scan_request('../stock/ajaxReqScanExecution.php', 'mode=1&scanCode=' + ev);

  	    if (!scanCodeIsSerialNo) {
  	       // Check scan value is an article barcode
	         scan_request('../stock/ajaxReqScanExecution.php', 'mode=2&scanCode=' + ev);
  	    }

  	    if (!scanCodeIsSerialNo && !scanCodeIsArticleBarcode) {
  	       // Check scan value is a serial no.
	         scan_request('../stock/ajaxReqScanExecution.php', 'mode=3&scanCode=' + ev + '&stkIdRoot=' + stkIdRoot);
  	    }

  	    if (!scanCodeIsArticleBarcode && !scanCodeIsStockBarcode && !scanCodeIsSerialNo) {
  	       // Store unknown scanned barcode to storage
	         frm.f_store.value = frm.f_scan.value;
  	    }

  	    // Execute if a serial number does exist
  	    if (scanCodeIsSerialNo) {
  	    	 // *** Fill fields for the article movement ***
  	    	  
  	    	 // Execute after reload
  	    	 frm.js_execute_cmd.value = '1';
  	    	 frm.js_execute_data.value = stkMvData[5];  // Serial number
  	    	  
           // Switch incoming journal stock (stk_to) to the outgoing stock of the new movement (stk_from)
  	    	 if (stkMvData[3]!= '') {
  	    	 	  setSelectedValue('f_mv_stk_from', stkMvData[3]);
           }
           if (stkMvData[2]!= '') {
           	  setSelectedValue('f_mv_at', stkMvData[2]);
           }
           // if (stkMvData[3]!= '') {
              setSelectedValue('f_mv_stk_to', '0');
           // }
           // frm.f_mv_stk_itemquantity.value = '';
           frm.f_mv_tan.value = stkMvData[4];
           // frm.f_mv_remark.value = '';
           frm.f_mv_serialno.value = stkMvData[5];
           
           // Set quantity to "1"
           frm.f_mv_stk_itemquantity.value = '1';
        
  	    	 // Reload page
  	    	 stkFinishPage('');
  	    }

  	    // Execute if an article does exist according to the barcode
  	    if (scanCodeIsArticleBarcode) {
  	    	  // Prepare article search in all stocks
  	    	  // Execute after reload
  	    	  frm.js_execute_cmd.value = '2';
  	    	  frm.js_execute_data.value = stkMvArticleData[0];  // Article ID
  	    	  
  	    	  // Display the stock articles, filtered accorting to this specified article
  	    	  frm.maskDisplayArticleSwitch.value = '1';
  	    	  
  	    	  // Set current stock to root stock (top level)
  	    	  frm.stkIdCurrent.value = stkIdRoot;
  	    	  
  	    	  // Show ALL stocks (whole tree)
  	    	  setSelectedValue('f_displayModeStockArticle', '1');

           // Set outgoing stock of the new movement (stk_from = '0')
  	    	 // if () {
  	    	    setSelectedValue('f_mv_stk_to', '0');
           // }

           if (stkMvArticleData[0]!= '') {
           	  setSelectedValue('f_mv_at', stkMvArticleData[0]);
           }
  	    	  
  	    	  // Reload page
  	    	  stkFinishPage('');
        }
        
        // Execute if a stock does exist according to the barcode
        if (scanCodeIsStockBarcode) {
  	    	  // Prepare stock search
  	    	  // Execute after reload
  	    	  frm.js_execute_cmd.value = '3';
  	    	  frm.js_execute_data.value = stkMvArticleData[0];  // Stock ID
  	    	  
            if (stkMvStockData[0]!= '') {
            	 setSelectedValue('f_mv_stk_from', stkMvStockData[0]);
            }

  	    	  // Set current stock to the selected stock
  	    	  frm.stkIdCurrent.value = stkMvStockData[0];
  	    	  
  	    	  // Show ONLY current stock
  	    	  setSelectedValue('f_displayModeStockArticle', '0');
  	    	  
  	    	  // Reload page
  	    	  stkFinishPage('');
        }
     }
/*
  } else if (stkIdRoot != '') {
  	 evuc = ev.toUpperCase();
     scan_request('../stock/ajaxReqScanExecution.php?stkIdRoot=' + stkIdRoot, '');
     if (listLenth && listLenth > 0) {
        for(i=0; i<listLenth; ++i) {
          if (evuc == stkBarcodeList[i]) {
          	 frm.f_stk_id.value = stkIdList[i];
          	 frm.f_stk_name.value = stkNameList[i];
          }
        }
     }
*/     
  }
  // Init global JS
  initGlobals();
  
  elem.value = '';
  <?php if ($usedFramework == "2") : ?>
    $('f_scan').focus();
  <?php else : ?>
  	$('#f_scan').focus();
  <?php endif; ?>
}

function setScanFocus() {
  <?php if ($usedFramework == "2") : ?>
    if ($('f_scan')) {
       $('f_scan').focus();
    }
  <?php else : ?>
    if ($('#f_scan')) {
       $('#f_scan').focus();
    }
  <?php endif; ?>
}

function checkSerialno() {
  if (document.forms[0].f_mv_serialno) {
     if (document.forms[0].f_mv_serialno.value != '') {
     	  changeHideShowSpecialElement('maskDisplayMoveDataFields','on');
     } else {
     	  changeHideShowSpecialElement('maskDisplayMoveDataFields','off');
     }
  }
// maskDisplayMoveDataFieldsSwitch
}


// *** Handling of jobs ***

function openCurrentListOfStockJobs() {
  var widthPopupWin = 900;
  var heightPopupWin = 700;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../stock/stock_jobs.php?stkIdRoot=" + stkIdRoot + "&deactivateMenu=1",
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes");
};

function clearJob() {	
  document.forms[0].f_mv_jb_id.value='';
};

function execBodyOnLoad() {
<?php 
  echo $phpCurrentNavigationOnLoad;
  if ($maskStkReadonly != "1") :
     if ($maskDisplayDataSwitch == "1") : echo "changeHideShow('maskDisplayData','on');"; else : echo "changeHideShow('maskDisplayData','off');"; endif;
  endif;
  if ($maskDisplayNavSwitch == "1") : echo "changeHideShow2('maskDisplayNav','maskDisplayNavReduced','on');"; else : echo "changeHideShow2('maskDisplayNav','maskDisplayNavReduced','off');"; endif;
  if ($maskDisplayArticleSwitch == "1") : echo "changeHideShow('maskDisplayArticle','on');"; else : echo "changeHideShow('maskDisplayArticle','off');"; endif;
  if ($maskStkReadonly != "1") :
     if ($maskDisplayMoveSwitch == "1") : echo "changeHideShow('maskDisplayMove','on');"; else : echo "changeHideShow('maskDisplayMove','off');"; endif;
  endif;
  if ($maskDisplayJournalSwitch == "1") : echo "changeHideShow('maskDisplayJournal','on');"; else : echo "changeHideShow('maskDisplayJournal','off');"; endif;
  if ($maskStkReadonly != "1") :
     if ($f_stkat_export || $f_stkmv_export) : echo "downloadStockFile();"; endif;
     if ($maskDisplayMoveDataFieldsSwitch == "1") : echo "changeHideShowSpecialElement('maskDisplayMoveDataFields','on');"; else : echo "changeHideShowSpecialElement('maskDisplayMoveDataFields','off');"; endif;
  endif;
  if ($maskDisplayAtSearchSwitch == "1") : echo "changeHideShowSpecialElement('maskDisplayAtSearch', 'on');"; else : echo "changeHideShowSpecialElement('maskDisplayAtSearch', 'off');"; endif;
?>
initForm();
displayStatusMessage();
setScanFocus();
}
-->
</script>

<?php echo $js_date ?>

</head>

<body onLoad="execBodyOnLoad();">

<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>

<div class="maincontent" name="maincontent" id="maincontent">

<form name="stock" action="../stock/stock.php" method="post">
  <input type="hidden" name="f_act" value="">
  <input type="hidden" name="customerId" value="<?php echo ec($customerId) ?>">
  <input type="hidden" name="cscIdRoot" value="<?php echo ec($cscIdRoot) ?>">
  <input type="hidden" name="cscIdCurrent" value="<?php echo ec($cscIdCurrent) ?>">
  <input type="hidden" name="cscNameCurrent" value="<?php echo $cscNameCurrent ?>">
  <input type="hidden" name="stkIdRoot" value="<?php echo ec($stkIdRoot) ?>">
  <input type="hidden" name="stkIdCurrent" value="<?php echo ec($stkIdCurrent) ?>">
  <input type="hidden" name="stkNameCurrent" value="<?php echo $stkNameCurrent ?>">  
  <input type="hidden" name="stkPathCurrent" value="<?php echo $stkPathCurrent ?>">
  <input type="hidden" name="stkVisibleCurrent" value="<?php echo ec($stkVisibleCurrent) ?>">
  <?php echo $phpCurrentNavigationInputHidden ?>
  <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
  <input type="hidden" name="statusMessage" value="">

  <input type="hidden" name="ad_id" value="<?php echo ec(mcIsSet($ad_id)) ?>">
  <input type="hidden" name="g_cs_id" value="<?php echo $g_cs_id ?>">
  <input type="hidden" name="g_csc_id" value="<?php echo $g_csc_id ?>">

  <input type="hidden" name="f_mv_sort_journal" value="<?php echo $f_mv_sort_journal ?>">
  <input type="hidden" name="f_mv_sort_stockArticle" value="<?php echo $f_mv_sort_stockArticle ?>">

  <input type="hidden" name="js_execute_cmd" value="">
  <input type="hidden" name="js_execute_data" value="">
  
  <input type="hidden" name="stkmv_id_storno" value="">

  <input type="hidden" name="maskDisplayDataSwitch" value="<?php echo $maskDisplayDataSwitch ?>">
  <input type="hidden" name="maskDisplayNavSwitch" value="<?php echo $maskDisplayNavSwitch ?>">  
  <input type="hidden" name="maskDisplayArticleSwitch" value="<?php echo $maskDisplayArticleSwitch ?>">
  <input type="hidden" name="maskDisplayMoveSwitch" value="<?php echo $maskDisplayMoveSwitch ?>">
  <input type="hidden" name="maskDisplayMoveDataFieldsSwitch" value="<?php echo $maskDisplayMoveDataFieldsSwitch ?>">
  <input type="hidden" name="maskDisplayJournalSwitch" value="<?php echo $maskDisplayJournalSwitch ?>">
  <input type="hidden" name="maskDisplayAtSearchSwitch" value="<?php echo $maskDisplayAtSearchSwitch ?>">

  <?php echo htmlDivLineSpacer("10px"); ?>
  
  <div class="f10bp1_blue">
    <div style="float:left">
       <?php echo getLngt("Hauptläger:") ?>&nbsp;&nbsp;&nbsp;
       <select name="selectRootStock" onChange="rootStockReload();">
       	 <option value=""><?php echo getLngt("Hauptläger:") ?></option>
         <?php echo addOptionsFromTable("stock","stk_id","stk_name","stk_name","stk_pre_id = '0' AND stk_path = ''" . $whereClauseRootStockIDs,$stkIdRoot); ?>
       </select>
       &nbsp;&nbsp;&nbsp;
    </div>


    <!-- Lagerortdaten -->
    <?php if ($maskStkReadonly != "1") : ?>
      <div id="maskDisplayDataAction" name="maskDisplayDataAction">
        <?php echo defineButtonType08("-", "action_data", "changeHideShow('maskDisplayData','off');", "20", "left", "2") ?>
        <div class="f10bp1_blue" style="float:left">
          <?php echo getLngt("Lagerortdaten") ?>&nbsp;&nbsp;&nbsp;&nbsp;
        </div>      
      </div>    
      <div id="maskDisplayDataReducedAction" name="maskDisplayDataReducedAction">
        <?php echo defineButtonType08("+", "action_data", "changeHideShow('maskDisplayData','on');", "20", "left", "2") ?>
        <div class="f10bp1_blue" style="float:left">
          <?php echo getLngt("Lagerortdaten") ?>&nbsp;&nbsp;&nbsp;&nbsp;
        </div>
      </div>
    <?php endif; ?>
      
    <!-- Lagerartikelbestand -->
    <div id="maskDisplayArticleAction" name="maskDisplayArticleAction">
      <?php echo defineButtonType08("-", "action_article", "changeHideShow('maskDisplayArticle','off');", "20", "left", "2") ?>
      <div class="f10bp1_blue" style="float:left">
        <?php echo getLngt("Lagerartikelbestand") ?>&nbsp;&nbsp;&nbsp;&nbsp;
      </div>      
    </div>
    <div id="maskDisplayArticleReducedAction" name="maskDisplayArticleReducedAction">
      <?php echo defineButtonType08("+", "action_article", "changeHideShow('maskDisplayArticle','on');", "20", "left", "2") ?>
      <div class="f10bp1_blue" style="float:left">
        <?php echo getLngt("Lagerartikelbestand") ?>&nbsp;&nbsp;&nbsp;&nbsp;
      </div>
    </div>    

    <!-- Artikelbewegung -->
    <?php if ($maskStkReadonly != "1") : ?>
      <div id="maskDisplayMoveAction" name="maskDisplayMoveAction">
        <?php echo defineButtonType08("-", "action_move", "changeHideShow('maskDisplayMove','off');", "20", "left", "2") ?>
        <div class="f10bp1_blue" style="float:left">
          <?php echo getLngt("Artikelbewegung") ?>&nbsp;&nbsp;&nbsp;&nbsp;
        </div>      
      </div>
      <div id="maskDisplayMoveReducedAction" name="maskDisplayMoveReducedAction">
        <?php echo defineButtonType08("+", "action_move", "changeHideShow('maskDisplayMove','on');", "20", "left", "2") ?>
        <div class="f10bp1_blue" style="float:left">
          <?php echo getLngt("Artikelbewegung") ?>&nbsp;&nbsp;&nbsp;&nbsp;
        </div>
      </div>
    <?php endif; ?>

    <!-- Lagerjournal -->
    <div id="maskDisplayJournalAction" name="maskDisplayJournalAction">
      <?php echo defineButtonType08("-", "action_journal", "changeHideShow('maskDisplayJournal','off');", "20", "left", "2") ?>
      <div class="f10bp1_blue" style="float:left">
        <?php echo getLngt("Lagerjournal") ?>&nbsp;&nbsp;&nbsp;&nbsp;
      </div>
    </div>
    <div id="maskDisplayJournalReducedAction" name="maskDisplayJournalReducedAction">
      <?php echo defineButtonType08("+", "action_journal", "changeHideShow('maskDisplayJournal','on');", "20", "left", "2") ?>
      <div class="f10bp1_blue" style="float:left">
        <?php echo getLngt("Lagerjournal") ?>&nbsp;&nbsp;&nbsp;&nbsp;
      </div>
    </div>
  </div>

  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <?php echo htmlDivLineSpacer("1px","100%","","1"); ?>
  <?php echo htmlDivLineSpacer("5px"); ?>
  
  <?php echo htmlDivLineSpacer("10px"); ?>


<!-- *** STOCK NAVIGATION *********************************************************************************** -->


<div id="maskDisplayNav" name="maskDisplayNav">
	<?php if ($userTypeName == "hq" && $stockRight) : ?>
    <?php echo defineButtonType08("-", "action_lock", "changeHideShow2('maskDisplayNav','maskDisplayNavReduced','off');", "20", "left", "3") ?>
  <?php endif; ?>
    
  <div class="f10bp1_blue">
    <div style="float:left">
       <?php echo getLngt("Aktueller Lagerort:") ?>&nbsp;<span class="f10bp1_red"><?php echo $stkPathCurrentOut ?></span>&nbsp;&nbsp;&nbsp;<?php echo $selectFieldSelectStock ?>&nbsp;&nbsp;&nbsp;
    </div>
    <?php if ($userTypeName == "hq" && $stockRight) : ?>
      <?php echo $buttonVisibility ?>
      <div style="float:left">
        <?php echo $showInvisibles ?>
      </div>
    <?php endif; ?>
  </div>
  
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <?php // echo htmlDivLineSpacer("1px","100%","","1"); ?>
  <?php echo htmlDivLineSpacer("5px"); ?>
	
	<?php if ($userTypeName == "hq" && $stockRight) : ?>
    <div>
      <div style="float:left">
        <?php echo htmlDivLineSpacer("3px"); ?>
        <?php 
          if ($stkAdminDisabled == "disabled") :
             $selectFieldDeleteStock = "";
          else :
             echo "<div style=\"float:left\">";
             echo "<input type=\"text\" name=\"nameStock\" value=\"\" size=\"25\" maxlength=\"50\" class=\"input\">&nbsp;&nbsp;";
             echo "</div>";
             echo defineButtonType10(getLngt("Anlegen"), "action_new", "stkFinishPage('" . ec("newStock") . "');", "100", "left", "2");
             echo defineButtonType10(getLngt("Umbenennen"), "action_rename", "stkFinishPage('" . ec("renameStock") . "');", "100", "left", "2");
          endif;
        ?> 
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      </div>
      <?php echo $selectFieldDeleteStock ?>
    </div>
  <?php endif; ?>
</div>
  
<div id="maskDisplayNavReduced" name="maskDisplayNavReduced">
	<?php if ($userTypeName == "hq" && $stockRight) : ?>
    <?php echo defineButtonType08("+", "action_lock", "changeHideShow2('maskDisplayNav','maskDisplayNavReduced','on');", "20", "left", "3") ?>
  <?php endif; ?>
  <div>
    <div style="width:100%; height:3px;"></div>
    <div  class="f10bp1_blue">
      <?php echo getLngt("Aktueller Lagerort:") ?>&nbsp;<span class="f10bp1_red"><?php echo $stkPathCurrentOut ?></span>&nbsp;&nbsp;&nbsp;<?php echo $selectFieldSelectStock2 ?>&nbsp;&nbsp;&nbsp;
    </div>
  </div>
</div>

<?php echo htmlDivLineSpacer("10px", "", "left"); ?>
<?php echo htmlDivLineSpacer("1px","100%","","1"); ?>
<?php echo htmlDivLineSpacer("10px"); ?>


<!-- *** STOCK DATA *********************************************************************************** -->

<?php if ($maskStkReadonly != "1") : ?>

  <div id="maskDisplayData" name="maskDisplayData">
    <?php echo htmlDivLineSpacer("3px"); ?>
    <?php echo defineButtonType08("-", "action_lock", "changeHideShow('maskDisplayData','off');", "20", "left", "3") ?>
  
    <div class="f10bp1_blue">
      <?php echo getLngt("Daten über Lagerort") ?> <span class="f10bp1_red"><?php echo $stkNameCurrent ?></span>:
    </div>
    <?php echo htmlDivLineSpacer("10px"); ?>
  
    <?php if ($userTypeName == "hq" && substr($empRights,0,1) == "1") : ?>
      
      <div>
      	<div <?php echo setStyleHtmlDiv("150px","left"); ?>><?php echo getLngt("Anzahl Lagerplätze:") ?></div>
        <div style="float:left">
          <input type="text" name="f_stk_maxquantity" value="<?php echo $f_stk_maxquantity ?>" size="8" maxlength="8">
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <?php if ($stkIdCurrent == $stkIdRoot) : ?>
            <?php echo getLngt("Stellplatzplanung aktiviert:") ?>&nbsp;&nbsp;
            <input class="f8np1" type="checkbox" name="f_stk_planning[]" value="1" <?php echo $f_stk_planning_0 ?>>
          <?php endif; ?>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </div>
        <?php if ($userTypeName == "hq" && $stockRight) : ?>
          <?php echo defineButtonType10(getLngt("Daten speichern"), "action_save_settings", "settingsFinishPage();", "150", "left", "2") ?>
        <?php endif; ?>
      </div>
      <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
  
    <?php endif; ?>
  
          
    <div>
      <div <?php echo setStyleHtmlDiv("150px","left"); ?>><?php echo getLngt("Zugeordneter Kunde, Kostenstelle:") ?></div>
      <div style="float:left">
        <input type="text" name="g_cmp_comp" value="<?php echo $g_cmp_comp ?>" size="30" readonly >
        <input type="text" name="g_cmp_comp2" value="<?php echo $g_cmp_comp2 ?>" size="30" readonly >
        <input type="text" name="g_cs_eid" value="<?php echo $g_cs_eid ?>" size="10" readonly >
        <input type="text" name="g_csc_name" value="<?php echo $g_csc_name ?>" size="25" readonly >
        &nbsp;&nbsp;
      </div>
      <?php if ($userTypeName == "hq" || ($userTypeName == "cs" && substr($empRights,3,1) == "1")) : ?>
         <?php echo defineButtonType08("...", "action_cscsc", "searchCsCsc('111000000000111','');", "20", "left", "2"); ?>
      <?php endif; ?>       
    </div>
    <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
    
  
    <div>
      <div <?php echo setStyleHtmlDiv("150px","left"); ?>><?php echo getLngt("Barcode:") ?></div>
      <div style="float:left">
      	<div>
          <input type="text" name="f_stk_barcode" value="<?php echo $f_stk_barcode ?>" size="50">&nbsp;&nbsp;
        </div>
        <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
        <?php if ($stkIdRoot != "") : ?>
          <?php echo defineButtonType10(getLngt("Barcode-Liste"), "action_list_barcodes", "barcodeList();", "150", "left", "2") ?>
          <?php if ($stkIdCurrent == $stkIdRoot) : ?>
            <?php echo defineButtonType10(getLngt("Befehlsliste"), "action_list_commands", "commandList();", "150", "left", "2") ?>
          <?php endif; ?>
        <?php endif; ?>
      </div>
      <div>
      	<?php if ($f_stk_barcode != "") : ?>
          <img src="../include/barcode_BCGcode39.php?text=<?php echo $f_stk_barcode ?>">
        <?php endif; ?>
      </div>
    </div>
  
    <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
    <?php echo htmlDivLineSpacer("1px","100%","","1"); ?>
    <?php echo htmlDivLineSpacer("10px"); ?>
  
  
    <div>
      <div>
        <?php echo getLngt("Adresse des Lagerortes:") ?>
      </div>
      <?php echo htmlDivLineSpacer("5px"); ?>
      <div <?php echo setStyleHtmlDiv("150px","left"); ?>><?php echo getLngt("Strasse, Hausnr.:") ?></div>
      <div style="float:left">
        <input type="text" name="f_ad_street" value="<?php echo $f_ad_street ?>">&nbsp;
        <input type="text" name="f_stk_hsno" size="5" value="<?php echo $f_stk_hsno ?>">&nbsp;&nbsp;&nbsp;&nbsp;
      </div>
      <?php 
        if ($userTypeName == "hq" && $stockRight) :
           echo defineButtonType10("...", "action_ad_search", "searchAddress('');", "23", "left");
           echo "&nbsp;&nbsp;";
      ?>
           <div style="float:left">
             &nbsp;&nbsp;<input type="checkbox" name="f_noaddressvalidation[]" value="1">Keine Prüfung &nbsp;&nbsp;&nbsp;&nbsp;
           </div>
      <?php 
           echo defineButtonType10(getLngt("Adresse speichern"), "action_ad_save", "checkFields();", "150", "left", "2");
        else :
           echo "<div>&nbsp;</div>";
        endif; 
      ?>
    </div>
    <?php echo htmlDivLineSpacer("10px"); ?>
    
    <div>
      <div <?php echo setStyleHtmlDiv("150px","left"); ?>><?php echo getLngt("PLZ, Ort, Land:") ?></div>
      <div>
         <input type="text" name="f_ad_zipcode" value="<?php echo $f_ad_zipcode ?>">&nbsp;
         <input type="text" name="f_ad_city" value="<?php echo $f_ad_city ?>">&nbsp;&nbsp;
         <select class="f8np1" name="f_ad_country">
           <?php echo getCountryCodesAsOptions($f_ad_country); ?>
         </select>
      </div>
    </div>
    <?php echo htmlDivLineSpacer("5px"); ?>

    <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
    <?php echo htmlDivLineSpacer("1px","100%","","1"); ?>
    <?php echo htmlDivLineSpacer("10px"); ?>
    
    <div>
      <?php 
        $tmpStkIdRoot = getStkPathId($stkIdRoot);  // Makes it safe to have a real root stock
        // $stkJournalTitleArray = array(getLngt("Lfd.&nbsp;"), getLngt("Zeitstempel&nbsp;"), ...);
        // $stkJournalOrderByDirectionArray = array("0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0");
        // $stkJournalTitleDisplayedArray = array("1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1");

        $maskStkJournalHeadlines = getParameterValue("0", "MASK_STK_JOURNALHEADLINES_" . $tmpStkIdRoot, "0");
        if ($maskStkJournalHeadlines == "") : 
           $maskStkJournalHeadlines = $stkJournalTitleArray; 
        else :
           $maskStkJournalHeadlines = spliti(",",$maskStkJournalHeadlines);
        endif;

        $maskStkJournalOrderByDirection = getParameterValue("0", "MASK_STK_JOURNAL_ORDERBY_DIRECTION_" . $tmpStkIdRoot, "0");
        if ($maskStkJournalOrderByDirection == "") : 
           $maskStkJournalOrderByDirection = $stkJournalOrderByDirectionArray;
        else :
           $maskStkJournalOrderByDirection = spliti(",",$maskStkJournalOrderByDirection);
        endif;

        $maskStkJournalHeadlinesDisplayed = getParameterValue("0", "MASK_STK_JOURNALHEADLINES_DISPLAYED_" . $tmpStkIdRoot, "0");
        if ($maskStkJournalHeadlinesDisplayed == "") : 
           $maskStkJournalHeadlinesDisplayed = $stkJournalTitleDisplayedArray;
        else :
           $maskStkJournalHeadlinesDisplayed = spliti(",",$maskStkJournalHeadlinesDisplayed);
        endif;
        echo "<div><table>\n";
        echo "<tr><td>" . getLngt("Angezeigte Spalten im Journal:") . "&nbsp;&nbsp;&nbsp;</td><td>" . getLngt("Absteigende Sortierung:") . "</td></tr>";
        $stkJournalTitleArrayLen = count($stkJournalTitleArray);
        for ($i = 0; $i < $stkJournalTitleArrayLen; $i++) :
            if ($maskStkJournalHeadlines[$i] != "") :
               $stkJournalTitleArray[$i] = $maskStkJournalHeadlines[$i];
            endif;
            echo "<tr>";
            echo "<td>&nbsp;<input type=\"checkbox\" name=\"f_journal_headlines[]\" value=\"" . $i . "\" " . ($maskStkJournalHeadlinesDisplayed[$i] == "1" ? "checked" : "") . " tabindex=\"\">&nbsp;" . $stkJournalTitleArray[$i] . "&nbsp;</td>\n";
            echo "<td>&nbsp;<input type=\"checkbox\" name=\"f_journal_orderby[]\" value=\"" . $i . "\" " . ($maskStkJournalOrderByDirection[$i] == "1" ? "checked" : "") . " tabindex=\"\"></td>\n";
            echo "</tr>";
        endfor;
        echo "</table></div>\n";
      ?>
    </div>
    <?php echo htmlDivLineSpacer("5px"); ?>
    <?php echo defineButtonType10(getLngt("Speichern"), "action_journal_headlines", "stkFinishPage('saveJournalTitles');", "150", "", ""); ?>
    <?php echo htmlDivLineSpacer("5px"); ?>
    
    <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
    <?php echo htmlDivLineSpacer("1px","100%","","1"); ?>
    <?php echo htmlDivLineSpacer("10px"); ?>
  </div>

<?php endif; ?>


<!-- *** STOCK ARTICLE LIST *********************************************************************************** -->

<div id="maskDisplayArticle" name="maskDisplayArticle">
    <?php echo defineButtonType08("-", "action_lock", "changeHideShow('maskDisplayArticle','off');", "20", "left", "3") ?>

  <div>
    <div style="width:100%; height:3px;"></div>
    <div class="f10bp1_blue">
      <?php echo getLngt("Lagerartikelbestand:") ?>&nbsp;<span class="f10bp1_red"><?php echo $stkNameCurrent ?></span>&nbsp;&nbsp;&nbsp;
      <?php 
        if ($f_stk_planning == "1") :
           if ($stkIdCurrent != "") :
      ?>
        <?php echo getLngt("Stellplätze:") ?>&nbsp;&nbsp;&nbsp; <?php echo getLngt("gesamt:") ?> <?php echo $f_stk_maxquantity ?>&nbsp;&nbsp;=&nbsp;&nbsp;(<?php echo getLngt("belegt:") ?> <?php echo $articlePlaceQuantityOfCurrentStock ?>&nbsp;&nbsp;+&nbsp;&nbsp;<?php echo getLngt("reserviert:") ?> <?php echo $stkNextSublevelMaxQuantity ?>)&nbsp;&nbsp;+&nbsp;&nbsp;frei: <?php echo ($f_stk_maxquantity - $articlePlaceQuantityOfCurrentStock - $stkNextSublevelMaxQuantity) ?>&nbsp;&nbsp;
      <?php 
          endif;
        else :
      ?>
        <span class="f8np1_blue"><?php echo getLngt("(Keine Verbindung zwischen den belegten Lagerplätzen und der Artikelstückzahl.)") ?></span>
      <?php 
        endif;
      ?>
      <?php if ($f_stk_planning == "1" && $stkIdCurrent != "" && $f_stk_maxquantity > 0 && ($articlePlaceQuantityOfCurrentStock + $stkNextSublevelMaxQuantity) == $f_stk_maxquantity) : echo "<span class=\"f10bp1_red\">" . getLngt("KAPAZITÄT ERSCHÖPFT!") . "</span>"; endif; ?>
      <?php if ($f_stk_planning == "1" && $stkIdCurrent != "" && $f_stk_maxquantity > 0 && ($f_stk_maxquantity - $stkNextSublevelMaxQuantity) > 0 && $articlePlaceQuantityOfCurrentStock == 0) : echo getLngt("(Alle nicht reservierten Plätze frei!)"); endif; ?>&nbsp;&nbsp;
    </div>
    <?php echo htmlDivLineSpacer("10px"); ?>
    <div>
    	<div style="float:left">
    	  <select name="f_displayModeStockArticle" onChange="stkFinishPage('stockArticleList');">
       	  <option value="0" <?php if ($f_displayModeStockArticle == "0") : echo "selected"; endif; ?>><?php echo getLngt("Artikelliste aktuelles Lager") ?></option>
          <option value="1" <?php if ($f_displayModeStockArticle == "1") : echo "selected"; endif; ?>><?php echo getLngt("Artikelliste aller Unterläger") ?></option>
	        <option value="2" <?php if ($f_displayModeStockArticle == "2") : echo "selected"; endif; ?>><?php echo getLngt("Zusammengefasste Artikelliste aller Unterläger") ?></option>
	        <?php if ($f_stk_planning == "1") : ?>
            <option value="3" <?php if ($f_displayModeStockArticle == "3") : echo "selected"; endif; ?>><?php echo getLngt("Lagerliste aller Unterläger") ?></option>
	        <?php endif; ?>
	        <option value="4" <?php if ($f_displayModeStockArticle == "4") : echo "selected"; endif; ?>><?php echo getLngt("Inventurliste") ?></option>
        </select>
        &nbsp;&nbsp;&nbsp;
      </div>
      <div style="float:left">
        <input type="text" name="f_stkat_search_at_misc" value="<?php echo $f_stkat_search_at_misc ?>" size="20">
        &nbsp;
        <select name="f_stkat_search_atg">
          <option value=""><?php echo getLngt("Artikelgruppe:") ?></option>
          <?php echo addOptionsFromTable("articlegroup","atg_id","atg_name","atg_key","md_id = '" . $md_id . "' AND (hq_id = '0' OR hq_id = '" . $hq_id . "')",$f_stkat_search_atg); ?>
        </select>
        &nbsp;&nbsp;&nbsp;
      </div>
      <?php echo defineButtonType10(getLngt("Auflisten"), "action_list", "stkFinishPage('stockArticleList');", "100", "left", "3"); ?>
      <div style="float:left">
        <?php echo getLngt("Bestand exportieren:") ?>&nbsp;
        <input class="f8np1" type="checkbox" name="f_stkat_export[]" value="1" <?php if (!($userTypeName == "hq" && $stockRight)) : echo "disabled"; endif; ?>>
      </div>
    </div>
    <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
    <div>
      <?php echo $stockArticles; ?> 
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
  <?php echo htmlDivLineSpacer("1px","100%","","1"); ?>
  <?php echo htmlDivLineSpacer("10px"); ?>
</div>


<!-- *** STOCK ARTICLE MOVEMENT *********************************************************************************** -->

<?php if ($maskStkReadonly != "1") : ?>

  <div id="maskDisplayMove" name="maskDisplayMove">
    <?php echo defineButtonType08("-", "action_move", "changeHideShow('maskDisplayMove','off');", "20", "left", "3") ?>
  
    <div>
      <div style="width:100%; height:3px;"></div>
      <div class="f10bp1_blue">
        <?php echo getLngt("Artikelbewegung:") ?>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <select name="f_mv_modeStockEntries" onChange="stkFinishPage('');">
        	<option value="0" <?php if ($f_mv_modeStockEntries == "0") : echo "selected"; endif; ?>><?php echo getLngt("Lägerauswahl für das aktuelle Lager und Unterläger") ?></option>
          <option value="1" <?php if ($f_mv_modeStockEntries == "1") : echo "selected"; endif; ?>><?php echo getLngt("Lägerauswahl für das aktuelle Hauptlager und Unterläger") ?></option>
  	      <?php if ($empIdRootAdmin == $emp_id) : ?>
                  <option value="2" <?php if ($f_mv_modeStockEntries == "2") : echo "selected"; endif; ?>><?php echo getLngt("Lägerauswahl übergreifend für alle Hauptläger") ?></option>
  	      <?php endif; ?>
        </select>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <select name="f_mv_modeArticleEntries" onChange="changeHideShowSpecialElement('maskDisplayAtSearch', 'off'); stkFinishPage('');">
        	<option value="0" <?php if ($f_mv_modeArticleEntries == "0") : echo "selected"; endif; ?>><?php echo getLngt("Artikelauswahl für das aktuelle Lager und Unterläger") ?></option>
          <option value="1" <?php if ($f_mv_modeArticleEntries == "1") : echo "selected"; endif; ?>><?php echo getLngt("Artikelauswahl für das aktuelle Hauptlager und Unterläger") ?></option>
          <option value="2" <?php if ($f_mv_modeArticleEntries == "2") : echo "selected"; endif; ?>><?php echo getLngt("Artikelauswahl übergreifend für alle Hauptläger") ?></option>
          <option value="3" <?php if ($f_mv_modeArticleEntries == "3") : echo "selected"; endif; ?>><?php echo getLngt("Nur neue Artikel in der Artikelauswahl") ?></option>
          <option value="4" <?php if ($f_mv_modeArticleEntries == "4") : echo "selected"; endif; ?>><?php echo getLngt("Alle Artikel in der Artikelauswahl") ?></option>
          <option value="5" <?php if ($f_mv_modeArticleEntries == "5") : echo "selected"; endif; ?>><?php echo getLngt("Alle Artikel der gewählten Artikelgruppe in der Artikelauswahl") ?></option>
        </select>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <span id="maskDisplayAtSearch" name="maskDisplayAtSearch" onChange="stkFinishPage('');">
          <select name="f_at_search_atg">
            <option value=""><?php echo getLngt("Artikelgruppe:") ?></option>
            <?php echo addOptionsFromTable("articlegroup","atg_id","atg_name","atg_key","md_id = '" . $md_id . "' AND (hq_id = '0' OR hq_id = '" . $hq_id . "')",$f_at_search_atg); ?>
          </select>
        </span>
      </div>
      <?php echo htmlDivLineSpacer("10px"); ?>
      <div>
      	<div style="float:left">
      		<table>
      			<?php 
      			  $tmpStkIdRoot = getStkPathId($stkIdRoot);  // Makes it safe to have a real root stock
      			  $maskStkMoveHeadlines = getParameterValue("0", "MASK_STK_MOVEHEADLINES_" . $tmpStkIdRoot, "0");
              $tmpStkmvTitleArray = spliti(",",$maskStkMoveHeadlines);
              // $stkmvTitleArray = array("von Lager","Artikel",...);  Default fields to be displayed, defined above
              $stkmvTitleArrayLen = count($stkmvTitleArray);
              for ($i = 0; $i < $stkmvTitleArrayLen; $i++) :
                  mcArrIsSet($tmpStkmvTitleArray, $i);
                  if ($tmpStkmvTitleArray[$i] != "") :
                     $stkmvTitleArray[$i] = $tmpStkmvTitleArray[$i];
                  endif;
              endfor;
      			?>
      			<tr>
      				<td><?php echo $stkmvTitleArray[0] ?></td>
      				<td><?php echo $stkmvTitleArray[1] ?></td>
      				<td><?php echo $stkmvTitleArray[2] ?></td>
      				<td><?php echo $stkmvTitleArray[3] ?></td>
      				<td rowspan="2" valign="bottom">
      				  <?php echo defineButtonType10(getLngt("Disponieren"), "action_move", "articleMoveFinishPage();", "150", "left", "2") ?>
      				</td>
      				<td><?php echo $stkmvTitleArray[4] ?></td>
              <td><?php echo $stkmvTitleArray[5] ?></td>
              <td><?php echo $stkmvTitleArray[6] ?></td>
              <td colspan="3"><?php echo $stkmvTitleArray[7] ?></td>
              <td><?php echo $stkmvTitleArray[8] ?></td>
      			</tr>
      			<tr>
      			  <td>
                <select name="f_mv_stk_from">
         	        <option value="0"><?php echo getLngt("Eingangslieferung") ?></option>
                  <?php echo addOptionsFromTable("stock","stk_id","stk_name","stk_name",$whereClauseMovementStocks,$f_mv_stk_from); ?>
                </select>
              </td>
      			  <td>
                <select name="f_mv_at">
         	        <option value="">---</option>
         	        <?php echo addOptionsFromTable($fromClauseMovementArticles,"at.at_id","at.at_name","at.at_name",$whereClauseMovementArticles,$f_mv_at, "1"); ?>
                </select>
              </td>
      			  <td>
                <input type="text" name="f_mv_stk_itemquantity" value="<?php echo $f_mv_stk_itemquantity; ?>" size="5">
              </td>
      			  <td>
                <select name="f_mv_stk_to">
         	        <option value="0"><?php echo getLngt("Ausgangslager") ?></option>
                  <?php echo addOptionsFromTable("stock","stk_id","stk_name","stk_name",$whereClauseMovementStocks,$f_mv_stk_to); ?>
                </select>
                &nbsp;&nbsp;
              </td>
      			  <td>
      			  	<input type="text" name="f_mv_tan" value="<?php echo $f_mv_tan ?>" size="10">
                &nbsp;&nbsp;
              </td>
      			  <td>
      			  	<input type="text" name="f_mv_remark" value="<?php echo $f_mv_remark ?>">
                &nbsp;&nbsp;
              </td>
      			  <td>
      			  	<input type="text" name="f_mv_serialno" value="<?php echo $f_mv_serialno ?>" onblur="javascript:checkSerialno();">
      			  	<input type="hidden" name="f_mv_serialno_old" value="">
                &nbsp;&nbsp;
              </td>
      			  <td id="mvJobId" name="mvJobId" <?php if ($f_mv_jb_id != "") : echo "style=\"border-color:#FF0000; border-width:2px; border-style:solid; padding:4px\""; endif; ?>>
      			  	<input type="text" name="f_mv_jb_id" value="<?php echo $f_mv_jb_id ?>" readonly>
      			  </td>
      			  <td>
      			  	<?php echo defineButtonType10("...", "action_job", "openCurrentListOfStockJobs();", "20", "", ""); ?>    			  	
              </td>
              <td>
              	<a href="javascript:clearJob();" tabindex="310"><img src="../images/waste.png" border="0" height="15" width="12"></a>&nbsp;&nbsp;
              </td>
      			  <td>
      			  	<?php echo $stkmvSpecialDate ?>
      			  </td>
            </tr>
          </table>
        </div>
        <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
        <div id="maskDisplayMoveDataFields" name="maskDisplayMoveDataFields">
        	<?php 
        	  $tmpHeadlines = getParameterValue("0", "MASK_STK_DATAFIELDHEADLINES_" . $stkIdRoot, "0");
            $tmpHeadlinesArray = spliti(",", $tmpHeadlines);
            $tmpHeadlinesArrayLen = max(count($tmpHeadlinesArray), 15);
            $tmpHL = array();
            for ($i = 0; $i < $tmpHeadlinesArrayLen; $i++) :
                $tmpHL[$i] = "";
                mcArrIsSet($tmpHeadlinesArray, $i);
                if ($tmpHeadlinesArray[$i] != "") :
                   $tmpHL[$i] = "<td>" . $tmpHeadlinesArray[$i] . ":</td>";
                endif;
            endfor;
        	?>
      		<table>
      			<tr>
      				<td colspan="5">Weitere Datenfelder:</td>
      			</tr>
      			<tr>
      				<?php echo $tmpHL[0]; ?><td><input type="text" name="f_mv_datafield_01" value="<?php echo $f_mv_datafield_01 ?>">&nbsp;&nbsp;</td>
      				<?php echo $tmpHL[1]; ?><td><input type="text" name="f_mv_datafield_02" value="<?php echo $f_mv_datafield_02 ?>">&nbsp;&nbsp;</td>
      				<?php echo $tmpHL[2]; ?><td><input type="text" name="f_mv_datafield_03" value="<?php echo $f_mv_datafield_03 ?>">&nbsp;&nbsp;</td>
      				<?php echo $tmpHL[3]; ?><td><input type="text" name="f_mv_datafield_04" value="<?php echo $f_mv_datafield_04 ?>">&nbsp;&nbsp;</td>
      				<?php echo $tmpHL[4]; ?><td><input type="text" name="f_mv_datafield_05" value="<?php echo $f_mv_datafield_05 ?>">&nbsp;&nbsp;</td>
      			</tr>
      			<tr>
      				<?php echo $tmpHL[5]; ?><td><input type="text" name="f_mv_datafield_06" value="<?php echo $f_mv_datafield_06 ?>">&nbsp;&nbsp;</td>
      				<?php echo $tmpHL[6]; ?><td><input type="text" name="f_mv_datafield_07" value="<?php echo $f_mv_datafield_07 ?>">&nbsp;&nbsp;</td>
      				<?php echo $tmpHL[7]; ?><td><input type="text" name="f_mv_datafield_08" value="<?php echo $f_mv_datafield_08 ?>">&nbsp;&nbsp;</td>
      				<?php echo $tmpHL[8]; ?><td><input type="text" name="f_mv_datafield_09" value="<?php echo $f_mv_datafield_09 ?>">&nbsp;&nbsp;</td>
      				<?php echo $tmpHL[9]; ?><td><input type="text" name="f_mv_datafield_10" value="<?php echo $f_mv_datafield_10 ?>">&nbsp;&nbsp;</td>
      			</tr>
      			<tr>
      				<?php echo $tmpHL[10]; ?><td><input type="text" name="f_mv_datafield_11" value="<?php echo $f_mv_datafield_11 ?>">&nbsp;&nbsp;</td>
      				<?php echo $tmpHL[11]; ?><td><input type="text" name="f_mv_datafield_12" value="<?php echo $f_mv_datafield_12 ?>">&nbsp;&nbsp;</td>
      				<?php echo $tmpHL[12]; ?><td><input type="text" name="f_mv_datafield_13" value="<?php echo $f_mv_datafield_13 ?>">&nbsp;&nbsp;</td>
      				<?php echo $tmpHL[13]; ?><td><input type="text" name="f_mv_datafield_14" value="<?php echo $f_mv_datafield_14 ?>">&nbsp;&nbsp;</td>
      				<?php echo $tmpHL[14]; ?><td><input type="text" name="f_mv_datafield_15" value="<?php echo $f_mv_datafield_15 ?>">&nbsp;&nbsp;</td>
      			</tr>
          </table>
        </div>
      </div>
    </div>
    
    <?php if ($userType == "4") : ?>
      <?php echo htmlDivLineSpacer("20px", "", "left"); ?> 
      <div style="width:900px; border: 3px;border-color:#FF0000; border-style:solid; padding: 10px; margin: 0px;"> 
        <div class="f10bp1_blue" style="float:left; vertical-align:middle;" valign="center">
          <?php echo getLngt("BARCODE-SCAN:") ?>&nbsp;<input type="text" id="f_scan" name="f_scan" value="" size="20" onblur="javascript:executeScanCode();" border="2">&nbsp;&nbsp;
        </div>
        <div style="float:left; vertical-align:middle;" valign="center">
            <input type="radio" name="f_stkat_scanmode" value="0" <?php if ($f_stkat_scanmode == "0") : echo "checked"; endif; ?> onfocus="javascript:setScanFocus();">&nbsp;<?php echo getLngt("Wareneingang") ?>
            <input type="radio" name="f_stkat_scanmode" value="1" <?php if ($f_stkat_scanmode == "1") : echo "checked"; endif; ?> onfocus="javascript:setScanFocus();" >&nbsp;<?php echo getLngt("Warenausgang") ?>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </div>
        <div class="f10bp1" style="vertical-align:middle;" valign="center">
          <?php echo getLngt("Zwischenspeicher:") ?>&nbsp;<input type="text" id="f_store" name="f_store" value="" size="20" onfocus="javascript:setScanFocus();">&nbsp;&nbsp;
        </div>
      </div> 
      <?php echo htmlDivLineSpacer("10px", "", "left"); ?> 
    <?php endif; ?>
    
    <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
    <?php echo htmlDivLineSpacer("1px","100%","","1"); ?>
    <?php echo htmlDivLineSpacer("10px"); ?>
  </div>

<?php endif; ?>


<!-- *** STOCK JOURNAL *********************************************************************************** -->

<div id="maskDisplayJournal" name="maskDisplayJournal">
  <?php echo defineButtonType08("-", "action_journal", "changeHideShow('maskDisplayJournal','off');", "20", "left", "3") ?>

  <div>
    <div style="width:100%; height:3px;"></div>
    <div class="f10bp1_blue" style="float:left">
      <?php echo getLngt("Lagerjournal:") ?>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <span class="f8np1"><?php echo $filter_dateranges ?></span>
      &nbsp;&nbsp;&nbsp;&nbsp;
      <select name="f_journal_modeStockEntries" onChange="stkFinishPage('');">
      	<option value="0" <?php if ($f_journal_modeStockEntries == "0") : echo "selected"; endif; ?>><?php echo getLngt("Das aktuelle Lager in der Lagerauswahl") ?></option>
      	<option value="1" <?php if ($f_journal_modeStockEntries == "1") : echo "selected"; endif; ?>><?php echo getLngt("Das aktuelle Lager und Unterläger in der Lagerauswahl") ?></option>
        <option value="2" <?php if ($f_journal_modeStockEntries == "2") : echo "selected"; endif; ?>><?php echo getLngt("Lägerauswahl für das aktuelle Hauptlager und Unterläger") ?></option>
	      <?php if ($empIdRootAdmin == $emp_id) : ?>
                <option value="3" <?php if ($f_journal_modeStockEntries == "3") : echo "selected"; endif; ?>><?php echo getLngt("Lägerauswahl übergreifend für alle Hauptläger mit Unterlägern") ?></option>
	      <?php endif; ?>
      </select>
      &nbsp;&nbsp;&nbsp;&nbsp;
    </div>
    <?php echo defineButtonType10(getLngt("Suchen"), "action_new", "stkFinishPage('journalSearch');", "100", "left", "3"); ?>
    <div>
      <?php echo getLngt("Journal exportieren:") ?>&nbsp;
      <input class="f8np1" type="checkbox" name="f_stkmv_export[]" value="1" <?php if (!($userTypeName == "hq" && $stockRight)) : echo "disabled"; endif; ?>>
    </div>
    <?php echo htmlDivLineSpacer("10px"); ?>
    <div>
      <?php echo htmlDivLineSpacer("5px"); ?>
      <div>
      	<?php if ($showJournal) : ?>
      	  <?php
      	    $tmpStkIdRoot = getStkPathId($stkIdRoot);  // Makes it safe to have a real root stock
            $maskStkJournalHeadlinesDisplayed = getParameterValue("0", "MASK_STK_JOURNALHEADLINES_DISPLAYED_" . $tmpStkIdRoot, "0");
            if ($maskStkJournalHeadlinesDisplayed == "") : 
               $maskStkJournalHeadlinesDisplayed = $stkJournalTitleDisplayedArray;
            else :
               $maskStkJournalHeadlinesDisplayed = spliti(",",$maskStkJournalHeadlinesDisplayed);
            endif;
      	  ?>
          <table>
          	<tr>
          		<?php if ($maskStkJournalHeadlinesDisplayed[0] == "1" || $maskStkJournalHeadlinesDisplayed[1] == "1") : ?>
            		<td style="vertical-align:top; text-align: center;" colspan="2"><a href="javascript:clearJournalSearchFields();"><?php echo getLngt("Felder zurücksetzen") ?></a>&nbsp;</td>
        		  <?php endif; ?>
          		<?php if ($maskStkJournalHeadlinesDisplayed[2] == "1") : ?>
          		  <td style="vertical-align:top; text-align: center;">
                  <select name="f_mv_search_stk_name_from">
                  	<option value=""><?php echo getLngt("Alle") ?></option>
       	            <option value="0"><?php echo getLngt("Eingangslieferung") ?></option>
                    <?php echo addOptionsFromTable("stock","stk_id","stk_name","stk_name",$whereClauseJournalStocks,$f_mv_search_stk_name_from); ?>
                  </select>
                  <br>
            	    <input class="f8np1" type="checkbox" name="f_mv_search_stk_from_sub[]" value="1" <?php echo ($f_mv_search_stk_from_sub == "1" ? "checked" : "") ?>>&nbsp;<?php echo getLngt("mit&nbsp;Unterlägern") ?>
          		  </td>
          		<?php endif; ?>
          		<?php if ($maskStkJournalHeadlinesDisplayed[3] == "1") : ?>
          		  <td style="vertical-align:top; text-align: center;">
                  <select name="f_mv_search_stk_name_to">
                  	<option value=""><?php echo getLngt("Alle") ?></option>
       	            <option value="0"><?php echo getLngt("Ausgangslager") ?></option>
                    <?php echo addOptionsFromTable("stock","stk_id","stk_name","stk_name",$whereClauseJournalStocks,$f_mv_search_stk_name_to); ?>
                  </select>
                  <br>
                  <input class="f8np1" type="checkbox" name="f_mv_search_stk_to_sub[]" value="1" <?php echo ($f_mv_search_stk_to_sub == "1" ? "checked" : "") ?>>&nbsp;<?php echo getLngt("mit&nbsp;Unterlägern") ?>
          		  </td>
          		<?php endif; ?>
          		<?php if ($maskStkJournalHeadlinesDisplayed[4] == "1" || $maskStkJournalHeadlinesDisplayed[5] == "1" || $maskStkJournalHeadlinesDisplayed[6] == "1") : ?>
          		  <td style="vertical-align:top; text-align: center;" colspan="<?php echo ($maskStkJournalHeadlinesDisplayed[4] + $maskStkJournalHeadlinesDisplayed[5] + $maskStkJournalHeadlinesDisplayed[6]) ?>"><input type="text" name="f_mv_search_at_misc" value="<?php echo $f_mv_search_at_misc ?>" size="20">&nbsp;</td>
          		<?php endif; ?>
          		<?php if ($maskStkJournalHeadlinesDisplayed[7] == "1") : ?>
          		  <td style="vertical-align:top; text-align: center;">&nbsp;</td>
          		<?php endif; ?>
          		<?php if ($searchMode == "1") : ?>
          		  <?php if ($maskStkJournalHeadlinesDisplayed[8] == "1" || $maskStkJournalHeadlinesDisplayed[9] == "1" || $maskStkJournalHeadlinesDisplayed[10] == "1" || $maskStkJournalHeadlinesDisplayed[11] == "1") : ?>
          		    <td style="vertical-align:top; text-align: center;" colspan="<?php echo ($maskStkJournalHeadlinesDisplayed[8] + $maskStkJournalHeadlinesDisplayed[9] + $maskStkJournalHeadlinesDisplayed[10] + $maskStkJournalHeadlinesDisplayed[11]) ?>">          		   	
          		      <input type="text" name="f_mv_search_misc" value="<?php echo $f_mv_search_misc ?>" size="40">&nbsp;
          		      <input type="hidden" name="f_mv_search_tan_from" value="">
          		      <input type="hidden" name="f_mv_search_tan_to" value="">
          		      <input type="hidden" name="f_mv_search_remark" value="">
          		      <input type="hidden" name="f_mv_search_serialno" value="">
          		      <input type="hidden" name="f_mv_search_data" value="">
          		    </td>
          		  <?php endif; ?>
          		<?php else : ?>
          		   <input type="hidden" name="f_mv_search_misc" value="">
          		   <?php if ($maskStkJournalHeadlinesDisplayed[8] == "1") : ?>
          		     <td style="vertical-align:top; text-align: center;">
          		   	   <input type="text" name="f_mv_search_tan_from" value="<?php echo $f_mv_search_tan_from ?>" onBlur="javascript:setSearchTanToNum(this)" size="10">
          		   	   -
          		   	   <input type="text" name="f_mv_search_tan_to" value="<?php echo $f_mv_search_tan_to ?>" size="10">          		   	 
          		     </td>
          		   <?php endif; ?>
          		   <?php if ($maskStkJournalHeadlinesDisplayed[9] == "1") : ?>
          		     <td style="vertical-align:top; text-align: center;"><input type="text" name="f_mv_search_remark" value="<?php echo $f_mv_search_remark ?>" size="20">&nbsp;</td>
          		   <?php endif; ?>
          		   <?php if ($maskStkJournalHeadlinesDisplayed[10] == "1") : ?>
                   <td style="vertical-align:top; text-align: center;"><input type="text" name="f_mv_search_serialno" value="<?php echo $f_mv_search_serialno ?>" size="20">&nbsp;</td>
                 <?php endif; ?>
                 <?php if ($maskStkJournalHeadlinesDisplayed[11] == "1") : ?>
                   <td style="vertical-align:top; text-align: center;"><input type="text" name="f_mv_search_data" value="<?php echo $f_mv_search_data ?>" size="20">&nbsp;</td>
                 <?php endif; ?>
              <?php endif; ?>
              <?php if ($maskStkJournalHeadlinesDisplayed[12] == "1") : ?>
                <td style="vertical-align:top; text-align: center;">&nbsp;</td>
              <?php endif; ?>
              <?php if ($maskStkJournalHeadlinesDisplayed[13] == "1") : ?>
                <td style="vertical-align:top; text-align: center;"><input type="text" name="f_mv_search_jb_id" value="<?php echo $f_mv_search_jb_id ?>" size="15">&nbsp;</td>
              <?php endif; ?>
              <?php if ($maskStkJournalHeadlinesDisplayed[14] == "1") : ?>
                <td>
              	  <select class="f8np1" name="f_mv_search_day_from"><option value=""></option><?php echo addOptionsFromRange("1","31",$f_mv_search_day_from,"") ?></select>&nbsp;
              	  <select class="f8np1" name="f_mv_search_month_from"><option value=""></option><?php echo addOptionsFromRange("1","12",$f_mv_search_month_from,"") ?></select>&nbsp;
              	  <select class="f8np1" name="f_mv_search_year_from"><option value=""></option><?php echo addOptionsFromRange((getDateTime("year")-5),(getDateTime("year")+2),$f_mv_search_year_from,"") ?></select>&nbsp;
                </td>
              <?php endif; ?>
            </tr>
            <tr>
            	<?php if ($maskStkJournalHeadlinesDisplayed[0] == "1" || $maskStkJournalHeadlinesDisplayed[1] == "1") : ?>
            	  <td colspan="2">&nbsp;</td>
            	<?php endif; ?>
            	<?php if ($maskStkJournalHeadlinesDisplayed[2] == "1" || $maskStkJournalHeadlinesDisplayed[3] == "1" ) : ?>
            	  <td colspan="<?php echo ($maskStkJournalHeadlinesDisplayed[2] + $maskStkJournalHeadlinesDisplayed[3]) ?>" align="center">
            		  Suche&nbsp;
         		      <input type="radio" name="stkSearchMode" value="0" <?php echo ($stkSearchMode == "0" ? "checked" : "") ?> onChange="stkFinishPage('');"><?php echo getLngt("UNDiert") ?>&nbsp;
                  <input type="radio" name="stkSearchMode" value="1" <?php echo ($stkSearchMode == "1" ? "checked" : "") ?> onChange="stkFinishPage('');"><?php echo getLngt("geODERt") ?>
            	  </td>
            	<?php endif; ?>
            	<?php if ($maskStkJournalHeadlinesDisplayed[4] == "1" || $maskStkJournalHeadlinesDisplayed[5] == "1" || $maskStkJournalHeadlinesDisplayed[6] == "1") : ?>
            	  <td style="vertical-align:top; text-align: center;" colspan="<?php echo ($maskStkJournalHeadlinesDisplayed[4] + $maskStkJournalHeadlinesDisplayed[5] + $maskStkJournalHeadlinesDisplayed[6]) ?>">
            	    <select name="f_mv_search_atg">
       	            <option value=""><?php echo getLngt("Artikelgruppe:") ?></option>
                    <?php echo addOptionsFromTable("articlegroup","atg_id","atg_name","atg_key","md_id = '" . $md_id . "' AND (hq_id = '0' OR hq_id = '" . $hq_id . "')",$f_mv_search_atg); ?>
                  </select>
                </td>
              <?php endif; ?>
              <?php if ($maskStkJournalHeadlinesDisplayed[7] == "1") : ?>
            	  <td>&nbsp;</td>
            	<?php endif; ?>
            	<?php if ($maskStkJournalHeadlinesDisplayed[8] == "1" || $maskStkJournalHeadlinesDisplayed[9] == "1" || $maskStkJournalHeadlinesDisplayed[10] == "1" || $maskStkJournalHeadlinesDisplayed[11] == "1") : ?>
            	<td colspan="<?php echo ($maskStkJournalHeadlinesDisplayed[8] + $maskStkJournalHeadlinesDisplayed[9] + $maskStkJournalHeadlinesDisplayed[10] + $maskStkJournalHeadlinesDisplayed[11]) ?>" align="center">
            		<?php echo getLngt("Suche") ?>&nbsp;
         		    <input type="radio" name="searchMode" value="0" <?php echo ($searchMode == "0" ? "checked" : "") ?> onChange="stkFinishPage('');">UNDiert&nbsp;
                <input type="radio" name="searchMode" value="1" <?php echo ($searchMode == "1" ? "checked" : "") ?> onChange="stkFinishPage('');">geODERt
            	</td>
            	<?php endif; ?>
            	<?php if ($maskStkJournalHeadlinesDisplayed[12] == "1") : ?>
                <td>&nbsp;</td>
              <?php endif; ?>
            	<?php if ($maskStkJournalHeadlinesDisplayed[13] == "1") : ?>
                <td>&nbsp;</td>
              <?php endif; ?>
            	<?php if ($maskStkJournalHeadlinesDisplayed[14] == "1") : ?>
                <td>&nbsp;</td>
              <?php endif; ?>
            </tr>
            <?php echo $stockJournal; ?>
          </table>
        <?php endif; ?>
      </div>
    </div>
  </div>  
  <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
  <?php echo htmlDivLineSpacer("1px","100%","","1"); ?>
  <?php echo htmlDivLineSpacer("10px"); ?>
</div>


</form>
</div>
</body>

</html>