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

  include_once ("../include/mcglobal.inc.php");
  include_once ("../include/inc_stock.inc.php");
 
  // Check HTTP-Parameters
  // Stocks
  getSecHttpVars("1",array("f_act", "customerId", "cscIdRoot", "cscIdCurrent", "statusMessage", "deactivateMenu",
                           "stkIdRoot", "f_sort"));

  getLanguage(__FILE__);

  $deactivateMenuStatic = "1";
  $pageTitel = getLngt("LAGERAUFTRÄGE");
  include_once ("../admin/menu.php");
  include_once ("../include/html.inc.php");
  getCurrentScript(__FILE__);

  // Get the array for formatting the database-values for the output according to the defined type
  $outputFormatField = defineOutputFormats();

  $numOfJobEntries = 0;

  // Get all stocks of the current root stock
  $jobListOut = "";
  if ($stkIdRoot != "" && is_numeric($stkIdRoot)) :
  
     $sqlStmt = getStmtAllStocksByStkId($stkIdRoot);
     $result = $db->query($sqlStmt);     
     if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
     
     $stkIdArray = array();
     $stkAdIdArray = array();
     $stkHsnoArray = array();
     while ($row = $result->fetch_assoc()):
       if ($row["ad_id"] != "0") :
          $stkIdArray[]      = $row["stk_id"];
          $stkAddressArray[] = $row["ad_id"] . "-" . $row["stk_hsno"];
       endif;
     endwhile;
     $result->free();
     
     $stkIdArrayLen = count($stkIdArray);
     
     // Initialize date-ranges to the current date
     // $fromDateRange = getDateTime("3") . " 00:00:00";
     $fromDateRange = getDateTime("date_plus_offset", array(0,-3,0), "Y-m-d") . " 00:00:00";
     $toDateRange = getDateTime("3") . " 23:59:59";

     if (count($stkAddressArray) > 0) :
        $jobListOut = getStockJobs("jb.jb_ordertime >= '" . $fromDateRange . "' AND jb.jb_ordertime <= '" . $toDateRange . "' AND CONCAT(ad.ad_id,'-',tr.tr_hsno) IN ('" . implode("','", $stkAddressArray) . "')", $f_sort);
     endif;
  endif;
?>  

<html>

<head>
<title><?php echo $pageTitel ?></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 type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>

function finishPageJobAction(jobId) {
  opener.document.forms[0].f_mv_jb_id.value = jobId;
  this.close();
};

function finishPageSortStockJobs(num) {
	var sortVal = '';
	if (num == '0') {sortVal = 'jb.jb_id';};
	if (num == '1') {sortVal = 'jb.jb_ordertime';};
	if (num == '2') {sortVal = 'jb.jb_totalprice';};
	if (num == '3') {sortVal = 'comp_1';};
	if (num == '4') {sortVal = 'address_1';};
	if (num == '5') {sortVal = 'comp_2';};
	if (num == '6') {sortVal = 'address_2';};
	if (num == '7') {sortVal = '';};
	document.forms[0].f_sort.value = sortVal;
	document.forms[0].submit();
}
-->
</script>

</head>

<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>">

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

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

<form name="stock_jobs" action="../stock/stock_jobs.php" method="post">
	
  <?php echo $phpCurrentNavigationInputHidden ?>
  <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
  <input type="hidden" name="f_sort" value="">

  <?php echo htmlDivLineSpacer("10px"); ?>

  <div class="f10bp1_blue">
    <?php echo getLngt("LAGERAUFTRÄGE"); ?>
  </div>
  
  <?php echo htmlDivLineSpacer("10px"); ?>

<table>
  <?php echo $jobListOut ?>
</table>

</form>

</div>
</body>

</html>