<?php
/*=======================================================================
 *
 * statistic_interface_cs.inc.php
 *
 * Autor: Marc Vollmann
 *
 =======================================================================*/
?>

<html>

<head>
<title>STATISTIK</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 finishPage(f_act_value) {  
  document.forms[0].f_act.value=f_act_value;
  document.forms[0].submit();
};

function finishPageSort(col) {
	document.forms[0].f_sort.value=col;
  finishPage('calculate');
};

function searchCsCsc() {
  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=0000000000001",
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes");
};

function clearSpecialCustomer() {	
  document.forms[0].g_cs_eid.value='';
};

function searchCourier(mode) {
  var f_act = 'search';

  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("../admin/courier_list.php?f_act=" + f_act + "&f_mode=" + mode, "","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function clearCourier() {	
  document.forms[0].g_cr_id.value='';
  document.forms[0].g_cr_eid.value='';
};

function downloadFile() {
  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("../statistic/statistic_data_download.php?f_fileName=<?php echo $f_secretFileName ?>", "","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

// Shows/Hides the group list
function groupList(displayState) {
  if (displayState == 'on') {
  	 myshow('groupList');
  	 myhide('groupListReduced');
  };
  if (displayState == 'off') {
  	 myshow('groupListReduced');
  	 myhide('groupList');
  };
}

function openCustomerFilters() {
  var widthPopupWin = 900;
  var heightPopupWin = 700;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  var f_crvh_filter_str = document.forms[0].g_crvh_filter.value;
  popupWin = window.open("../admin/filter.php?f_crvh_filter_str=" + f_crvh_filter_str,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};
-->
</script>

<?php echo $js_date ?>


</head>

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

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

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

<form name="statistic" action="../statistic/statistic_MC.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="cscIdActual" value="<?php echo ec($cscIdActual) ?>">  
  <input type="hidden" name="dbhistory" value="<?php echo $dbhistory ?>">
  <input type="hidden" name="outputTitle" value="<?php echo $outputTitle ?>">
  <?php echo $phpCurrentNavigationInputHidden ?>
  <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">

  <input type="hidden" name="f_category" value="<?php echo ec($f_category) ?>">
  <input type="hidden" name="g_cs_eid" value="<?php echo ec($g_cs_eid) ?>">

  <input type="hidden" name="f_sort" value="">
  <?php echo htmlDivLineSpacer("20px"); ?>

  <!-- Output of the calculated values -->  
  <div>
    <div class="f12bp1_blue">Optionen</div>
  </div>

  <?php echo htmlDivLineSpacer("15px"); ?>
    
  <div>
    <div <?php echo $htmlDivFixedWidth; ?>>Statistik-Format:</div>
    <div>
      <select name="f_statistic">
        <option value="0" <?php if ($f_statistic == "0") : echo "selected"; endif; ?>>---</option>
        <option value="60" <?php if ($f_statistic == "60") : echo "selected"; endif; ?>>Anzahl und Nettoumsätze aller erledigten Aufträge pro Kunde</option>
        <option value="61" <?php if ($f_statistic == "61") : echo "selected"; endif; ?>>Anzahl und Nettoumsätze erledigter Aufträge pro Monat pro Kunde</option>
      </select>
    </div>
  </div>

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

  <!-- Headquarters checkboxes -->
  <?php if ($isMeta == "1") : ?>
    <?php echo getHeadquartersCheckboxes($f_hq_id, "200px"); ?>
    <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
  <?php endif; ?>

  <div>
    <div <?php echo $htmlDivFixedWidth; ?>>Datums-Filter:</div>
    <div>
      <?php 
      // Date ranges
      $categoryFilter  = "von:\n";      
      $categoryFilter .= "<select name=\"day_from\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'statistic', 'day_from', 'day_from', 'month_from', 'year_from', '', '', '', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
      $categoryFilter .= "<select name=\"month_from\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'statistic', 'month_from', 'day_from', 'month_from', 'year_from', '', '', '', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
      $categoryFilter .= "<select name=\"year_from\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'statistic', 'year_from', 'day_from', 'month_from', 'year_from', '', '', '', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";      
      $categoryFilter .= "&nbsp;&nbsp;bis:\n";     
      $categoryFilter .= "<select name=\"day_to\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'statistic', 'day_to', 'day_from', 'month_from', 'year_from', '', '', '', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
      $categoryFilter .= "<select name=\"month_to\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'statistic', 'month_to', 'day_from', 'month_from', 'year_from', '', '', '', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
      $categoryFilter .= "<select name=\"year_to\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'statistic', 'year_to', 'day_from', 'month_from', 'year_from', '', '', '', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
      $categoryFilter .= "&nbsp;<br>";
      echo $categoryFilter;
      ?>
      <?php echo htmlDivLineSpacer("5px"); ?>
    <div <?php echo $htmlDivFixedWidth; ?>>&nbsp;</div>
    <div>
      <?php 
      // Time ranges
      $categoryFilter  = "[";
      $categoryFilter .= "Ohne<input class=\"smaller\" type=\"radio\" name=\"f_showDateAndTime\" value=\"0\" " . ($f_showDateAndTime == "0" ? "checked" : "") . ">|";
      $categoryFilter .= "Mit<input class=\"smaller\" type=\"radio\" name=\"f_showDateAndTime\" value=\"1\" " . ($f_showDateAndTime == "1" ? "checked" : "") . ">";
      $categoryFilter .= "Einschränkung auf Zeitintervall von:\n";
      $categoryFilter .= "<select name=\"hour_from\" class=\"f8np1\">" . addOptionsFromRange("0","23",$hour_from,"1") . "</select>\n";
      $categoryFilter .= "<select name=\"minute_from\" class=\"f8np1\">" . addOptionsFromRange("0","59",$minute_from,"1") . "</select>\n";
      $categoryFilter .= "Uhr&nbsp;&nbsp;bis:\n";      
      $categoryFilter .= "<select name=\"hour_to\" class=\"f8np1\">" . addOptionsFromRange("0","23",$hour_to,"1") . "</select>\n";
      $categoryFilter .= "<select name=\"minute_to\" class=\"f8np1\">" . addOptionsFromRange("0","59",$minute_to,"1") . "</select>\n";
      $categoryFilter .= "Uhr]\n";
      echo $categoryFilter;
      ?>
    </div>
  </div>

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

  <?php if ($constIntervalsEnabled == "1") : ?>
  <div>
    <div <?php echo $htmlDivFixedWidth; ?>>Vergleichszeiträume:</div>
    <div>
      <select class="f8np1" name="f_numOfIntervals">
        <?php echo addOptionsFromRange("1",$constIntervalsNumOf,$f_numOfIntervals,"1"); ?>
      </select>
    </div>
  </div>
  <?php endif; ?>

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

  <div>
    <div <?php echo $htmlDivFixedWidth; ?>>Weitere Filter:</div>
    <div>
       <!-- Aufteilung nach Zeitintervallen: -->
       Keine Auswahl
       <input type="radio" name="f_filter_interval" value="0" <?php if ($f_filter_interval == "0") : echo "checked"; endif; ?>>
       &nbsp;&nbsp;&nbsp;&nbsp;Zeitliche&nbsp;Aufteilung:&nbsp;&nbsp;&nbsp;&nbsp;halbstündlich:
       <input type="radio" name="f_filter_interval" value="1" <?php if ($f_filter_interval == "1") : echo "checked"; endif; ?>>
       &nbsp;&nbsp;&nbsp;&nbsp;stündlich:
       <input type="radio" name="f_filter_interval" value="2" <?php if ($f_filter_interval == "2") : echo "checked"; endif; ?>>
       &nbsp;&nbsp;&nbsp;&nbsp;zweistündlich:
       <input type="radio" name="f_filter_interval" value="3" <?php if ($f_filter_interval == "3") : echo "checked"; endif; ?>>
    </div>
    <?php echo htmlDivLineSpacer("5px"); ?>
    
    <div <?php echo $htmlDivFixedWidth; ?>>&nbsp;</div>
    <div>
       <!-- Aufteilung nach Fahrzeugtyp: <input type="checkbox" name="f_filter[]" value="split_vehicletype" <?php if ($f_split_vehicletype == "1") : echo "checked"; endif; ?>> -->
       Keine Auswahl
       <input type="radio" name="f_filter" value="0" <?php if ($f_filter == "0") : echo "checked"; endif; ?>>
       &nbsp;&nbsp;&nbsp;&nbsp;Aufteilung nach:&nbsp;&nbsp;&nbsp;&nbsp;Fahrzeugtyp:
       <input type="radio" name="f_filter" value="1" <?php if ($f_filter == "1") : echo "checked"; endif; ?>>
       &nbsp;&nbsp;&nbsp;&nbsp;Start-PLZ:
       <input type="radio" name="f_filter" value="2" <?php if ($f_filter == "2") : echo "checked"; endif; ?>>
       &nbsp;&nbsp;&nbsp;&nbsp;Ziel-PLZ:
       <input type="radio" name="f_filter" value="3" <?php if ($f_filter == "3") : echo "checked"; endif; ?>>
       &nbsp;&nbsp;&nbsp;&nbsp;Fahrzeug und Start-PLZ:
       <input type="radio" name="f_filter" value="4" <?php if ($f_filter == "4") : echo "checked"; endif; ?>>
       &nbsp;&nbsp;&nbsp;&nbsp;Fahrzeug und Ziel-PLZ:
       <input type="radio" name="f_filter" value="5" <?php if ($f_filter == "5") : echo "checked"; endif; ?>>
    </div>
    <?php echo htmlDivLineSpacer("5px"); ?>

    <?php if ($isMeta == "1") : ?>
      <div <?php echo $htmlDivFixedWidth; ?>>&nbsp;</div>
      <div>
        Keine Auswahl
        <input type="radio" name="f_filter4" value="0" <?php if ($f_filter4 == "0") : echo "checked"; endif; ?>>
        &nbsp;&nbsp;&nbsp;&nbsp;Aufteilung nach Niederlassungen:
        <input type="radio" name="f_filter4" value="1" <?php if ($f_filter4 == "1") : echo "checked"; endif; ?>>
      </div>
      <?php echo htmlDivLineSpacer("5px"); ?>
    <?php endif; ?>

    <!--
    <div <?php echo $htmlDivFixedWidth; ?>>&nbsp;</div>
    <div>
       Alle
       <input type="radio" name="f_filter2" value="0" <?php if ($f_filter2 == "0") : echo "checked"; endif; ?>>
       &nbsp;&nbsp;&nbsp;&nbsp;Nur Aufträge (Betrag > 0):
       <input type="radio" name="f_filter2" value="1" <?php if ($f_filter2 == "1") : echo "checked"; endif; ?>>
       &nbsp;&nbsp;&nbsp;&nbsp;Nur Gutschriften:
       <input type="radio" name="f_filter2" value="2" <?php if ($f_filter2 == "2") : echo "checked"; endif; ?>>
    </div>
    <?php echo htmlDivLineSpacer("5px"); ?>
    -->

    <div <?php echo $htmlDivFixedWidth; ?>>&nbsp;</div>
    <div>
      Keine Auswahl
      <input type="radio" name="f_filter10" value="0" <?php if ($f_filter10 == "0") : echo "checked"; endif; ?>>
      &nbsp;&nbsp;&nbsp;&nbsp;Aufteilung nach bezahlende Kostenstelle:
      <input type="radio" name="f_filter10" value="1" <?php if ($f_filter10 == "1") : echo "checked"; endif; ?>>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>    

  <div>
    <div <?php echo $htmlDivFixedWidth; ?>>Fahrzeug (SID):</div>
    <div>
      <input type="text" name="f_crvh_sid" value="<?php echo $f_crvh_sid ?>" size="10">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo $htmlDivFixedWidth; ?>>Sortierung:</div>
    <div>
      <input type="radio" name="f_direction_sort" value="0" <?php if ($f_direction_sort == "0") : echo "checked"; endif; ?>> Aufsteigend &nbsp;
      <input type="radio" name="f_direction_sort" value="1" <?php if ($f_direction_sort == "1") : echo "checked"; endif; ?>> Absteigend &nbsp;
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo $htmlDivFixedWidth; ?>>Kundennummer:</div>
    <div>
      Ohne Gruppenkunden
      <input type="radio" name="f_cs_meta" value="0" <?php if ($f_cs_meta == "0") : echo "checked"; endif; ?>>
      &nbsp;&nbsp;&nbsp;&nbsp;Aufteilung nach zugeordneten Kunden
      <input type="radio" name="f_cs_meta" value="1" <?php if ($f_cs_meta == "1") : echo "checked"; endif; ?>>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo $htmlDivFixedWidth; ?>>Statistik berechnen:</div>
    <div>
      <?php echo defineButton("Berechnen", "action_statistic", "finishPage('calculate');", "left", "", "", "", "100px"); ?>
      <?php if (authCheckEmployeeRights($emp_id, "10")) : ?>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
         <input type="checkbox" name="fileOutput" value="1" <?php /* if ($fileOutput) : echo "checked"; endif; */ ?>>&nbsp;Zusätzlicher&nbsp;Download&nbsp;der&nbsp;Daten
      <?php endif; ?>
    </div>
  </div>
  
  <?php echo htmlDivLineSpacer("40px"); ?>
 


  <!-- Display calculated values -->
  <div>
    <div class="f12bp1_blue"><?php if ($outputTitle != "") : echo $outputTitle; else : echo "Aufstellung"; endif; ?></div>
  </div>

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

  <div>
    <table>
      <?php echo $tableHeader ?>
      <?php echo $tableBody ?>
      <?php 
         echo "<tr>";
         for ($i = 1; $i < ($posOfLastSummationField); $i++) :
             echo "<td>&nbsp;</td>";
         endfor;
         echo "<td align=\"right\" class=\"f8np1_red\">" . $sumOfSummationField . "&nbsp;&nbsp;</td>";
         if ($numOfSummationCols > 1) :
            echo "<td align=\"right\" class=\"f8np1_red\">" . $sumOfSummationField2 . "&nbsp;&nbsp;</td>";
         endif;

         if ($summationFieldArrayLen > 0) :
            for ($i = 0; $i < $summationFieldArrayLen; $i++) :
                echo "<td align=\"right\" class=\"f8np1_red\">&nbsp;" . $sumOfSummationFieldArray[$i] . "&nbsp;&nbsp;</td>";
                if ($numOfSummationCols > 1) :
                   echo "<td align=\"right\" class=\"f8np1_red\">&nbsp;" . $sumOfSummationFieldArray2[$i] . "&nbsp;&nbsp;</td>";
                endif;
            endfor;
         endif;
         echo "</tr>";
      ?> 
    </table>
  </div>
    
</form>