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


include_once ("../include/mcglobal.inc.php");
include_once ("../include/auth.inc.php");
include_once ("../geo/geocode.inc.php");
// include_once ("../tools/co2e_sendReq.php");
include_once ("../include/caglobal.inc.php");
// include_once ("../include/services_func.inc.php");


// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "customerId", "cscIdRoot", "cscIdActual", "f_srvpaa_mode", "f_del_assoc", "f_jbb_sort", 
                  "g_cs_id", "g_csc_id", "g_csc_name", "initCsSearch", "f_filter", "sendMailFutureDate", "statusMessage", "deactivateMenu"));

$pageTitel = "LISTENERFASSUNG";
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
include_once ("../include/services_func.inc.php");   // Attention: File includes menu.php !!!

$numOfEditRows = 20;
$numOfInputFieldsPerRows = 14;
$numOfRows = 0;
// Init input fields
$timeToEditHourDefault = "10";
$timeToEditMinuteDefault = "00";

for ($i = 1; $i <= $numOfEditRows; $i++) :
    for ($j = 1; $j <= $numOfInputFieldsPerRows; $j++) :
        getSecHttpVars("1",array("f_field_" . $i . "_" . $j));
    endfor;
endfor;

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

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

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

// Get company data
$g_cmp_id = getFieldValueFromId("customer", "cs_id", $g_cs_id, "cmp_id");
$g_cs_eid = getFieldValueFromId("customer", "cs_id", $g_cs_id, "cs_eid");
$g_cmp_comp = getFieldValueFromId("company", "cmp_id", $g_cmp_id, "cmp_comp");
$g_cmp_comp2 = getFieldValueFromId("company", "cmp_id", $g_cmp_id, "cmp_comp2");

// Filter
$currentYear = getDateTime("year");
$lfdToEditShow = "checked";
$yearToEditShow = "";
$timeToEditShow = "";
$deactivateMarkup = "";
$presetDateFields = "";
if ($f_filter != "") :
   if (!(array_search("lfdToEditShow",$f_filter) === FALSE)) : $lfdToEditShow = "checked"; endif;
   if (!(array_search("yearToEditShow",$f_filter) === FALSE)) : $yearToEditShow = "checked"; endif;
   if (!(array_search("timeToEditShow",$f_filter) === FALSE)) : $timeToEditShow = "checked"; endif;
   if (!(array_search("deactivateMarkup",$f_filter) === FALSE)) : $deactivateMarkup = "checked"; endif;
   if (!(array_search("presetDateFields",$f_filter) === FALSE)) : $presetDateFields = "checked"; endif;
endif;

// Init
$out = "";
$g_cs_discount = "";


// Get $f_jbb_id from $f_jbb_sort and $g_cs_id
function getJbbData($sqlField = "jbb_id") {
   global $db, $PHP_SELF, $f_jbb_sort, $g_cs_id;
   $retVal = "";
   if ($f_jbb_sort != "" && $g_cs_id != "") :
      $retVal = $db->getOne("SELECT " . $sqlField . " FROM jobbatch WHERE cs_id = '" . $g_cs_id . "' AND jbb_sort = '" . $f_jbb_sort . "'");
   endif;
   return $retVal;
}
$f_jbb_id = getJbbData("jbb_id");

// echo "g_cs_id: " . $g_cs_id . "<br>g_cs_eid: " . $g_cs_eid . "<br>f_jbb_id: " . $f_jbb_id . "<br>f_jbb_sort: " . $f_jbb_sort . "<br>";

// Check for absolute customer discount (ATTENTION: Parameter means DISABLED !!!) and check for markup
$csDiscountAbsolute = "0";
$csMarkupFlag = "0";
if ($g_cs_id != "") :
   // Discount
   $csDiscountAbsolute = getFieldValueFromId("customer", "cs_id", $g_cs_id, "cs_discount");
   $useDicountDisabled = getParameterValue("0", "JB_EDITBATCH_DISCOUNT_DISABLED");
   if ($useDicountDisabled == "1") :
      $csDiscountAbsolute = "0";
   endif;

   // Markup
   $csMarkupFlag = getFieldValueFromId("customer", "cs_id", $g_cs_id, "cs_markup");
endif;


// Store new jobs
if ($f_act == "storeJobs") :
   if ($g_cs_id != "") :

      // Get data for storing the job
      $currentTime = getDateTime("0");
      $usrId = getFieldValueFromId("employee", "emp_id", $emp_id, "usr_id");
      
     /*    Moved upside
      $csDiscountAbsolute = getFieldValueFromId("customer", "cs_id", $g_cs_id, "cs_discount");
      $useDicountDisabled = getParameterValue("0", "JB_EDITBATCH_DISCOUNT_DISABLED");
      if ($useDicountDisabled == "1") :
         $csDiscountAbsolute = 0;
      endif;
      */

      // Check for customer provision, amount to be stored in "jb_cr_price"
      $csProv = 0;
      $useCsProvEnabled = getParameterValue("0", "JB_EDITBATCH_CS_PROV_ENABLED", "0");
      if ($useCsProvEnabled == "1") :
         $csProv = getFieldValueFromId("customer", "cs_id", $g_cs_id, "cs_prov");
         if ($csProv == "" || $csProv == 0) :
             $csProv = getParameterValue("0", "MASK_CS_PROV_DEFAULT", $hq_id);
             $csProv = str_replace (",", ".", $csProv);
             if ($csProv == "") :
                $csProv = 0;
             endif;
         endif;
      endif;      

      // Default value of the type of job to be stored (e.g. "0" = "K" = "Kurier" / "2" = "G" = "Gütertaxi" / ...)
      $constJbType = getParameterValue("0", "JB_EDITBATCH_JBTYPE");
      if (!is_numeric($constJbType)) : $constJbType = "0"; endif;

      $rowComplete = array();
      $vhtId = array(); $crId = array(); $crSid = array(); $cscIdPayer = array(); $jbFinishtime = array(); $price = array(); $price2 = array();
      $cmpId = array(); $cmpPostage = array(); $csInvmode = array(); $jbFreetext1 = array(); $txId = array(); $txValue = array(); 
      $txSign = array(); $cmpAdId = array(); $cmpHsno = array(); $cmpComp = array(); $cmpComp2 = array(); $jbType = array();
      $csDiscount = array(); $csMarkup = array(); $jbKM = array(); 
      
      // [1.] Iterate all fields and check the row to be complete   
      for ($i = 1; $i <= $numOfEditRows; $i++) :
          $rowComplete[$i] = FALSE;
          
          $vhtId[$i] = getFieldValueFromId("couriervehicle", "crvh_sid", ${("f_field_" . $i . "_10")}, "vht_id");
          $crId[$i] = getFieldValueFromId("couriervehicle", "crvh_sid", ${("f_field_" . $i . "_10")}, "cr_id");
          $crSid[$i] = ${("f_field_" . $i . "_10")};

          // Check for courier authenticated
          if ($crSid[$i] != "" && $crId[$i] != "") :
             $crCmpId = getFieldValueFromId("courier", "cr_id", $crId[$i], "cmp_id");
             $crCmpAuthenticated = getFieldValueFromId("company", "cmp_id", $crCmpId, "cmp_authenticated");
             if ($crCmpAuthenticated != "1") :
                $statusMessage .= "INFO: Der Transporteur des eingetragenen Fahrzeugs " . $crSid[$i] . " ist GESPERRT! ";
             endif;
          endif;

          // If paying costcenter does not exist then get the root costcenter
          if ($g_csc_id == "") :
             $cscIdPayer[$i] = getFieldValueFromId("customer", "cs_id", $g_cs_id, "csc_id");
          else :
             $cscIdPayer[$i] = $g_csc_id;
          endif;

          if (${("f_field_" . $i . "_4")} == "") : ${("f_field_" . $i . "_4")} = $currentYear; endif;
          if (${("f_field_" . $i . "_5")} == "") : ${("f_field_" . $i . "_5")} = $timeToEditHourDefault; endif;
          if (${("f_field_" . $i . "_6")} == "") : ${("f_field_" . $i . "_6")} = $timeToEditMinuteDefault; endif;          
          $jbFinishtime[$i] = ${("f_field_" . $i . "_4")} . "-" . pad(${("f_field_" . $i . "_3")},2) . "-" . pad(${("f_field_" . $i . "_2")},2) . " " .
                              pad(${("f_field_" . $i . "_5")},2) . ":" . pad(${("f_field_" . $i . "_6")},2) . ":00";

          $lfd[$i] = ${("f_field_" . $i . "_1")};
          if (!is_numeric($lfd[$i])) : $lfd[$i] = ""; endif;
          
          $price[$i] = str_replace (",", ".", ${("f_field_" . $i . "_9")});
          $price2[$i] = str_replace (",", ".", ${("f_field_" . $i . "_13")});
          $jbKM[$i] = str_replace (",", ".", ${("f_field_" . $i . "_14")});
          $cmpId[$i] = getFieldValueFromId("customer", "cs_id", $g_cs_id, "cmp_id");
          $cmpPostage[$i] = getFieldValueFromId("company", "cmp_id", $cmpId[$i], "cmp_postage");
          $csInvmode[$i] = getFieldValueFromId("customer", "cs_id", $g_cs_id, "cs_invmode");
          $trCommissionNo[$i] = my_str_check_js(${("f_field_" . $i . "_8")});
          $jbInvoiceText[$i] = my_str_check_js(${("f_field_" . $i . "_7")});
          $jbFreetext1[$i] = $jbInvoiceText[$i];    // . " " . $trCommissionNo[$i];
          $txId[$i] = getFieldValueFromId("company", "cmp_id", $cmpId[$i], "tx_id");
          $txValue[$i] = getFieldValueFromId("tax", "tx_id", $txId[$i], "tx_value");
          $txSign[$i] = getFieldValueFromId("tax", "tx_id", $txId[$i], "tx_sign");
          $cmpAdId[$i] = getFieldValueFromId("company", "cmp_id", $cmpId[$i], "ad_id");
          $cmpHsno[$i] = getFieldValueFromId("company", "cmp_id", $cmpId[$i], "cmp_hsno");
          $cmpComp[$i] = getFieldValueFromId("company", "cmp_id", $cmpId[$i], "cmp_comp");
          $cmpComp2[$i] = getFieldValueFromId("company", "cmp_id", $cmpId[$i], "cmp_comp2");
          $jbType[$i] = $constJbType;

	        $csDiscount[$i] = "0";
	        if ($csDiscountAbsolute != "0" && ${("f_field_" . $i . "_11")} == "1") :
	           $csDiscount[$i] = $csDiscountAbsolute;
	        endif;

	        $csMarkup[$i] = "0";
	        if ($csMarkupFlag == "1" && ${("f_field_" . $i . "_12")} == "1") :
	           $csMarkup[$i] = "1";
	        endif;

          if ($vhtId[$i] != "" && $crId[$i] != "" && $crSid[$i] != "" && $cscIdPayer[$i] != "" && $jbFinishtime[$i] != "" && 
              ($price[$i] != "" || $price2[$i] != "") && is_numeric($price[$i]) && $cmpId[$i] != "" && $jbFreetext1[$i] != "" && $cmpAdId[$i] != "" && 
              $cmpComp[$i] != "" && $csDiscount[$i] != "" && $csMarkup[$i] != "") :  //  && $jbKM[$i] != ""

             $rowComplete[$i] = TRUE;
          endif;
      endfor;

      // Transaction control starts here
      TA("B");

      // [2.] Generate a new list ($f_jbb_id == "") with current timestamp or use an old one
      //      and check if at least one job has to be stored
      if ($f_jbb_sort == "") :
         $atLeastOneJobOk = FALSE;
         $atLeastOneJobNotOk = FALSE;
         for ($i = 1; $i <= $numOfEditRows; $i++) :
             if ($rowComplete[$i]) :
                $atLeastOneJobOk = TRUE;
             else :
                $atLeastOneJobNotOk = TRUE;
             endif;
         endfor;
         if ($atLeastOneJobOk) :

            // Get maximum list number of the special customer from jbb_sort
            $f_jbb_sort = getMaxOfField("jobbatch", "jbb_sort", "cs_id = '" . $g_cs_id . "'");
            if (is_numeric($f_jbb_sort)) :
               ++$f_jbb_sort;   // Increment because of the next free number
             else : 
               $f_jbb_sort = "1";
            endif;

            insertStmt("jobbatch", array("cs_id", $g_cs_id, "jbb_sort", $f_jbb_sort, "jbb_createtime", $currentTime));
            $f_jbb_id = getLastInsertId();    // IMPORTANT to use parameter $f_jbb_id because of loop and following search below... !!!
         endif;
      endif;

      // [3.] Iterate all jobs and insert
      for ($i = 1; $i <= $numOfEditRows; $i++) :

          if ($rowComplete[$i]) :                   

             // Check prices because one of them has to be set only (!!!)
             if ($price[$i] == "") : $price[$i] = 0; endif;
             if ($price2[$i] == "") : $price2[$i] = 0; endif;
             if ($jbKM[$i] == "") : $jbKM[$i] = 0; endif;

             // Fixprice without markup and without customer discount
             $fixPrice = $price[$i];

             // Service price
             $servicePrice = $price2[$i];             

             // Compute markup
             // $constMarkupMode = getParameterValue("0", "MASK_MARKUP_MODE", $hq_id);
             $subTotalPrice = $price[$i];    // Price without markup

             $tmpSrvt = $db->getOne("SELECT mt_value FROM metatype WHERE mt_sort = '$vhtId[$i]' AND mt_type= 'vehicletype'");
             $final_markup = getFuelMarkup($tmpSrvt, $g_cs_id, $hq_id, $jbFinishtime[$i]);
             if ($csMarkup[$i] == "0" && $final_markup > 0) :
                $final_markup = "0";
             endif;

             // New price containing markup
             if ($final_markup > 0) :
                $price[$i] *= (1 + ($final_markup / 100));
             endif;

             // Price with markup but without customer discount
             $trsPrice = $price[$i];

             // Check for absolute customer discount
             if ($csDiscountAbsolute > 0) :
                $price[$i] = ($price[$i] * ((100 - $csDiscount[$i]) / 100));
		            $subTotalPrice = ($subTotalPrice * ((100 - $csDiscount[$i]) / 100));
             endif;

             // Total price and subtotal price containing the service price
             $subTotalPrice = $subTotalPrice + $servicePrice;
             $totalPrice = $price[$i] + $servicePrice;

             // Courier price
             $jbCrPrice = 0;
             /*
             if (is_numeric($csProv) && $csProv > 0) :
                $jbCrPrice = ($price[$i] * ((100 - $csProv) / 100));
             endif;
             */
             $parCrPriceMode = getParameterValue("0", "MASK_CR_PRICE_MODE", $hq_id);
             if ($parCrPriceMode == "1") :
                // list($jbCrPrice, $jbCrPriceRate) = getCr_price_global($totalPrice, $hq_id, $g_cs_id, $jbFinishtime[$i], "", $vhtId[$i]);
                list($jbCrPrice, $jbCrPriceRate) = getCr_price_global($subTotalPrice, $hq_id, $g_cs_id, $jbFinishtime[$i], "", $vhtId[$i]);
                if ($jbCrPrice == "" || !is_numeric($jbCrPrice)) : $jbCrPrice = 0; endif;

                $jbCrSubprice = $jbCrPrice;

                $final_cr_markup = getFuelMarkupCr($tmpSrvt, $g_cs_id, $hq_id, $jbFinishtime[$i]);
                if ($csMarkup[$i] == "0" && $final_cr_markup > 0) :
                   $final_cr_markup = "0";
                endif;

                if ($final_cr_markup > 0) :
                   $jbCrPrice *= (1 + ($final_cr_markup / 100));
                endif;

                list($tmp1, $tmp2) = getCr_price_global($servicePrice, $hq_id, $g_cs_id, $jbFinishtime[$i], "", $vhtId[$i]);
                if ($tmp1 == "" || !is_numeric($tmp1)) : $tmp1 = 0; endif;
                $jbCrPrice += $tmp1;
             endif;

             $jbHqIdExec = $hq_id;
             if ($crId[$i] != "" && $crId[$i] > "0") :
                $jbHqIdExec = getFieldValueFromId("courier", "cr_id", $crId[$i], "hq_id");
             endif;
             $jbHqIdSales = $hq_id;
             if ($cscIdPayer[$i] != "" && $cscIdPayer[$i] > "0") :
                $tmpCsId = getFieldValueFromId("costcenter", "csc_id", $cscIdPayer[$i], "cs_id");
                if ($tmpCsId != "" && $tmpCsId > "0") :
                   $jbHqIdSales = getFieldValueFromId("customer", "cs_id", $tmpCsId, "hq_id");
                endif;
             endif;

             insertStmt("job", array("hq_id", $hq_id, "hq_id_exec", $jbHqIdExec, "hq_id_dispo", $hq_id, "hq_id_sales", $jbHqIdSales, "vht_id", $vhtId[$i], "vht_id_real", $vhtId[$i], "csc_id_payer", $cscIdPayer[$i], "jb_payment", "0",
                                     "jb_ordertime", $jbFinishtime[$i], "cr_id", $crId[$i], "cr_sid", $crSid[$i], "cr_id_order", $crId[$i],
                                     "jb_taketime", $jbFinishtime[$i], "jb_status", "2", "jb_autoranking", "0", "jb_type", $jbType[$i], 
                                     "jb_finishtime", $jbFinishtime[$i], "emp_id", $usrId, "jb_fixprice", $fixPrice, "jb_serviceprice", $servicePrice, "jb_totalprice", $totalPrice, "jb_cr_price", $jbCrPrice,
                                     "jb_subtotalprice", $subTotalPrice, "jb_markup", $final_markup, "jb_postage", $cmpPostage[$i], "jb_invmode", $csInvmode[$i], "jb_freetext_1", $jbFreetext1[$i],
                                     "jb_sales_tax_rate", $txValue[$i], "jb_sales_tax_rate_sign", $txSign[$i], "jb_origin", "7", "jb_orderer", "Listenbuchung", "jb_createtime", $currentTime,
                                     "jb_automailsent", "997", "jb_service ", "1", "jb_booktime", $currentTime));
             $jbIdNew = getLastInsertId();

             insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $cmpAdId[$i], "tr_sort", "1", "tr_comp", my_str_check($cmpComp[$i]), "tr_comp2", my_str_check($cmpComp2[$i]),
                                      "tr_hsno", $cmpHsno[$i], "csc_id", $cscIdPayer[$i], "tr_status", "1", "tr_signname", "Listenbuchung",
                                      "tr_finishtime", $jbFinishtime[$i], "tr_commission_no", $trCommissionNo[$i], "tr_cs_freetext", ""));

             if ($trsPrice != 0) :
                insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer[$i], "tr_sort", "0", 
                                                "srv_id", "0", "trs_srv_name", "Fixpreis", "srvt_id", "0", "trs_srvt_name", "", 
                                                "trs_price", $trsPrice, "trs_discount", $csDiscount[$i]));
             endif;
             if ($servicePrice != 0) :
                insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer[$i], "tr_sort", "0", 
                                                "srv_id", "0", "trs_srv_name", "Servicepreis", "srvt_id", "0", "trs_srvt_name", "", 
                                                "trs_price", $servicePrice, "trs_discount", "0"));
             endif;
             insertStmt("jobprice", array("jb_id", $jbIdNew, "mt_sort", "1", "jbprc_price", $final_cr_markup));
             insertStmt("jobprice", array("jb_id", $jbIdNew, "mt_sort", "3", "jbprc_price", $tmp1));
             insertStmt("jobprice", array("jb_id", $jbIdNew, "mt_sort", "10", "jbprc_price", $jbCrSubprice));
             insertStmt("jobprice", array("jb_id", $jbIdNew, "mt_sort", "11", "jbprc_price", $jbKM[$i], "jbprc_remark", "jbb"));

             // Insert into GDC regarding "jb_origin = 6"
             // insertStmt("genericdatacontainer", array("gdc_obj_type", "jb", "gdc_obj_id", $jbIdNew, "gdc_gen_fieldname", "jb_origin_other", "gdc_content", "Listenbuchung", "gdc_context", "")); 

             check_cr_agio($jbIdNew);
             
             // Write logdata into log database
             writeToLogDB("1",$hq_id,$jbIdNew,$usrId,$crId[$i],$crSid[$i],"","");

             // Take lfd of the input field and get maximum of the lfd of the special list if necessary
             $jbblLfdMaxval = $lfd[$i];
             if ($jbblLfdMaxval == "" || existsEntry("jobbatchlist", array("jbb_id", $f_jbb_id, "jbbl_lfd", $jbblLfdMaxval))) :
                $jbblLfdMaxval = getMaxOfField("jobbatchlist", "jbbl_lfd", "jbb_id = '" . $f_jbb_id . "'");
                if (is_numeric($jbblLfdMaxval)) :
                   ++$jbblLfdMaxval;   // Increment because of the next free number
                else : 
                   $jbblLfdMaxval = "1";
                endif;
             endif;

             insertStmt("jobbatchlist", array("jbb_id", $f_jbb_id, "jbbl_lfd", $jbblLfdMaxval, "jb_id", $jbIdNew));

             // Generate invoice text
             mk_jb_invtext($jbIdNew, false);
             
             // Reset input fields of the row stored correctly
             for ($j = 1; $j <= $numOfInputFieldsPerRows; $j++) :
                 if (!($presetDateFields == "checked" && ($j == "2" || $j == "3"))) :
                    ${("f_field_" . $i . "_" . $j)} = '';
                 endif;
             endfor;
          endif;
      endfor;

      TA("C");
      TA("E");

      if (isset($sendMailFutureDate) && $sendMailFutureDate == "1") :
          $mailTo = getParameterValue("0", "JB_EDITBATCH_MAIL_JOBDATE", $hq_id);
          if ($mailTo == "")  : $mailTo = getParameterValue("0", "JB_EDITBATCH_MAIL_JOBDATE", "0"); endif;
          if ($mailTo != "")  :
             $csEid = getFieldValueFromId("customer","cs_id",$g_cs_id,"cs_eid");
             $mailSubject = "LISTENERFASSUNG :: Mindestens ein Datum liegt in der Zukunft!";
             $mailText = "Kunde: " . $csEid . " => Listennummer: " . $f_jbb_sort;
             sendExternalMail($mailText, $mailSubject, $mailTo);
             $sendMailFutureDate = "0";
          endif;
      endif;

      $f_act = "loadSpecialListOfCustomer";
   else :
      $statusMessage = "Sie haben noch keinen Kunden ausgewählt!";
   endif;   
endif;


// Show all lists of the customer
$outStoredBatchListsOfCustomer = "";
if ($f_act == "getListsOfCustomer") :
   if ($g_cs_id != "") :
      
      // Only for output get length of the max jbb_sort value for pad()
      $jbbSortPadlLength = strlen(getMaxOfField("jobbatch", "jbb_sort", "cs_id = '" . $g_cs_id . "'"));
      if ($jbbSortPadlLength == "0") : $jbbSortPadlLength = "1"; endif;
   
      // Get lists of the customer
      $sqlquery = "SELECT jbb.jbb_id, jbb.cs_id, jbb.jbb_sort, jbb.jbb_createtime " .
                  " FROM jobbatch AS jbb" . 
                  " WHERE jbb.cs_id = '" . $g_cs_id . "' " .
                  " ORDER BY jbb.jbb_createtime DESC";
      
      $result = $db->query($sqlquery);
      if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());

      while ($row = $result->fetch_assoc()):
            $outStoredBatchListsOfCustomer .= "<div><a href=\"javascript:finishPage('loadSpecialListOfCustomer','" . $row["jbb_sort"] . "');\">" . 
                                              pad($row["jbb_sort"],$jbbSortPadlLength) . " - " . formatOutput($row["jbb_createtime"],"datetime","3") . "</a></div>";
      endwhile;
      $result->free();

      if ($outStoredBatchListsOfCustomer != "") : 
         $outStoredBatchListsOfCustomer = "<div>Listenbestand: <br></div>" . $outStoredBatchListsOfCustomer . "<div><br></div>";
         
         if ($f_jbb_id != "") :
            $f_act = "loadSpecialListOfCustomer";
         endif;
      else :
         $statusMessage = "Für den Kunden existiert noch keine Liste!";
      endif;
   else :
      $statusMessage = "Sie haben noch keinen Kunden ausgewählt!";
   endif;
endif;


// Show all jobs of a selected list of the customer
$outCurrentListOfCustomer = "";
if ($f_act == "loadSpecialListOfCustomer") :
   if ($g_cs_id != "") :   
      if ($f_jbb_id != "") :

         $sqlquery = "SELECT jbbl.jbbl_lfd, jb.jb_id, jb.jb_export_time, jb.jb_finishtime, jb.jb_freetext_1, jb.cr_sid, tr.tr_commission_no, csc.csc_name,"
                      . " " . $priceFormular . " AS price, jb.jb_cr_price, jb.jb_subtotalprice, jb.jb_markup, jb.jb_serviceprice, jbprc.jbprc_price"
                      . " FROM jobbatch AS jbb, jobbatchlist AS jbbl, tour AS tr,"
                      . "      job AS jb LEFT JOIN tourservice AS trs ON trs.jb_id = jb.jb_id "
                      . "                LEFT JOIN jobprice AS jbprc ON jbprc.jb_id = jb.jb_id AND jbprc.mt_sort = '11',"
                      . "      costcenter AS csc"
                      . " WHERE jbb.jbb_id = '" . $f_jbb_id . "' AND"
                      . "       jbb.jbb_id = jbbl.jbb_id         AND"
                      . "       jbbl.jb_id = jb.jb_id            AND"
                      . "       jb.jb_id = tr.jb_id              AND"
                      . "       tr.tr_sort = '1'                 AND"
                      . "       jb.csc_id_payer = csc.csc_id        "
                      . " GROUP BY trs.jb_id"
                      . " ORDER BY jbbl.jbbl_lfd";

         $result = $db->query($sqlquery);
         if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());

         while ($row = $result->fetch_assoc()):
               $numOfRows++;

               $out .= "<tr class=\"f10np1\">";
               $out .= "<td align=\"center\"> ". $row["jbbl_lfd"] . "</td> ";
               
               $tmpDateTime = formatOutput($row["jb_finishtime"],"datetime","3");
               $out .= "<td align=\"center\"> ". substr($tmpDateTime,0,8) . "</td>";
               $out .= "<td align=\"center\"> ". substr($tmpDateTime,11,5) . "</td>";
               $out .= "<td> ". $row["jb_freetext_1"] . "<br>[Kst.: " . $row["csc_name"] . "]</td> ";
               $out .= "<td> ". $row["tr_commission_no"] . "</td> ";
               $out .= "<td align=\"right\" colspan=\"2\"><b>" . formatOutput($row["price"],"float_rounded_2") . "</b>&nbsp;";
               if ($row["jb_cr_price"] != "0") :
                  $out .= "<br>FL:&nbsp;&nbsp;" . formatOutput($row["jb_cr_price"],"float_rounded_2") . "&nbsp;";
               endif;
               if ($row["jb_markup"] != "0") :
                  $out .= "<br>[inkl.&nbsp;" . formatOutput($row["jb_markup"],"float_rounded_2") . "&nbsp;%]&nbsp;";
               endif;
               if ($row["jb_serviceprice"] != "0") :
                  $out .= "<br>inkl.&nbsp;Servicepreis:&nbsp;&nbsp;" . formatOutput($row["jb_serviceprice"],"float_rounded_2") . "&nbsp;";
               endif;
               $out .= "</td> ";
               $out .= "<td align=\"center\"> ". $row["cr_sid"] . "</td> ";
               $out .= "<td align=\"right\"> ". $row["jbprc_price"] . "</td> ";
               $out .= "<td align=\"right\" colspan=\"3\">";
               if ($row["jb_export_time"] == "" || $row["jb_export_time"] == "0000-00-00 00:00:00") :
                   $out .= "<a href=\"../jobs/job_edit.php?jb_id=" . ec($row["jb_id"]) . "\" target=\"_blank\">" . $row["jb_id"] . "</a>";
               else :
                   $out .= "Exportiert";
               endif;
               $out .= "&nbsp;&nbsp;</td>";
               $out .= "</tr>\n";
         endwhile;
         $result->free();

         $outCurrentListOfCustomer = $f_jbb_sort . " - " . formatOutput(getJbbData("jbb_createtime"),3);
      else :
         $statusMessage = "Es wurde entweder keine Liste gewählt ODER Eingaben sind für die Anlage eine neue Liste nicht korrekt!";
      endif;      
   else :
      $statusMessage = "Sie haben noch keinen Kunden ausgewählt!";
   endif;
endif;


// **********************
// * Define edit fields *
// **********************

// Get maximum of the lfd of the special list
$jbblLfdMaxval = 0;
if ($g_cs_id != "" && $f_jbb_id != "") :
   $jbblLfdMaxval = getMaxOfField("jobbatchlist", "jbbl_lfd", "jbb_id = '" . $f_jbb_id . "'");
endif;

$outEditFields = "";
for ($i = 1; $i <= $numOfEditRows; $i++) :

    $outEditFields .= "<tr>";
    
    ${("f_field_" . $i . "_1")} = $jbblLfdMaxval + $i;
    $outEditFields .= "<td valign=\"top\"><input type=\"text\" name=\"f_field_" . $i . "_1\" value=\"" . ${("f_field_" . $i . "_1")} . "\" size=\"3\" onBlur=\"checkDate(this,'lfd','" . $i . "','1')\" " . ($lfdToEditShow == "" ? "disabled" : "") . "></td>";
    
    $outEditFields .= "<td valign=\"top\">";
    $outEditFields .= "<input type=\"text\" name=\"f_field_" . $i . "_2\" value=\"" . ${("f_field_" . $i . "_2")} . "\" size=\"2\" maxlength=\"2\" onBlur=\"checkDate(this,'day','" . $i . "','2')\">";
    $outEditFields .= "<input type=\"text\" name=\"f_field_" . $i . "_3\" value=\"" . ${("f_field_" . $i . "_3")} . "\" size=\"2\" maxlength=\"2\" onBlur=\"checkDate(this,'month','" . $i . "','3')\">";

    // Preset of the year
    if (${("f_field_" . $i . "_4")} == "") : ${("f_field_" . $i . "_4")} = $currentYear; endif;
    $outEditFields .= "<input type=\"text\" name=\"f_field_" . $i . "_4\" value=\"" . ${("f_field_" . $i . "_4")} . "\" size=\"4\" maxlength=\"4\" onBlur=\"checkDate(this,'year','" . $i . "','4')\" " . ($yearToEditShow == "" ? "disabled" : "") . ">";
    
    $outEditFields .= "</td>";
    $outEditFields .= "<td valign=\"top\">";
    
    // Preset of the hour
    if (${("f_field_" . $i . "_5")} == "") : ${("f_field_" . $i . "_5")} = $timeToEditHourDefault; endif;
    $outEditFields .= "<input type=\"text\" name=\"f_field_" . $i . "_5\" value=\"" . ${("f_field_" . $i . "_5")} . "\" size=\"2\" maxlength=\"2\" onBlur=\"checkDate(this,'hour','" . $i . "','5')\" " . ($timeToEditShow == "" ? "disabled" : "") . ">";
    
    // Preset of the minute
    if (${("f_field_" . $i . "_6")} == "") : ${("f_field_" . $i . "_6")} = $timeToEditMinuteDefault; endif;
    $outEditFields .= "<input type=\"text\" name=\"f_field_" . $i . "_6\" value=\"" . ${("f_field_" . $i . "_6")} . "\" size=\"2\" maxlength=\"2\" onBlur=\"checkDate(this,'minute','" . $i . "','6')\" " . ($timeToEditShow == "" ? "disabled" : "") . ">";
    
    $outEditFields .= "</td>";
    $outEditFields .= "<td valign=\"top\"><textarea name=\"f_field_" . $i . "_7\" cols=\"45\" rows=\"2\">" . ${("f_field_" . $i . "_7")} . "</textarea><br><br></td>";
    $outEditFields .= "<td valign=\"top\"><input type=\"text\" name=\"f_field_" . $i . "_8\" value=\"" . ${("f_field_" . $i . "_8")} . "\" size=\"10\"></td>";
    $outEditFields .= "<td valign=\"top\"><input type=\"text\" name=\"f_field_" . $i . "_9\" value=\"" . ${("f_field_" . $i . "_9")} . "\" size=\"7\" onBlur=\"checkIsNumeric(document.forms[0].f_field_" . $i . "_9, 'Den Fuhrbetrag bitte als numerischen Wert erfassen!');\"></td>";
    $outEditFields .= "<td valign=\"top\"><input type=\"text\" name=\"f_field_" . $i . "_13\" value=\"" . ${("f_field_" . $i . "_13")} . "\" size=\"7\" onBlur=\"checkIsNumeric(document.forms[0].f_field_" . $i . "_13, 'Den Servicebetrag bitte als numerischen Wert erfassen!');\"></td>";
    $outEditFields .= "<td valign=\"top\"><input type=\"text\" name=\"f_field_" . $i . "_10\" value=\"" . ${("f_field_" . $i . "_10")} . "\" size=\"10\" onBlur=\"makeUpperCase(document.forms[0].f_field_" . $i . "_10);\"></td>";
    $outEditFields .= "<td valign=\"top\"><input type=\"text\" name=\"f_field_" . $i . "_14\" value=\"" . ${("f_field_" . $i . "_14")} . "\" size=\"7\" onBlur=\"checkIsNumeric(document.forms[0].f_field_" . $i . "_14, 'Die Angabe der Kilometer bitte als numerischen Wert erfassen!');\"></td>";

    if (${("f_field_" . $i . "_11")} == "") :
       if ($csDiscountAbsolute == "0") :
	        ${("f_field_" . $i . "_11")} = "0";
	     else :
	        ${("f_field_" . $i . "_11")} = "1";
	     endif;
    endif;

    $outEditFields .= "<td valign=\"top\">";
    $outEditFields .= "<input type=\"radio\" name=\"f_field_" . $i . "_11\" value=\"0\" " . (${("f_field_" . $i . "_11")} != "1" ? "checked" : "") . ($csDiscountAbsolute == "0" ? " disabled" : "") . ">&nbsp;Nein<br>";
    $outEditFields .= "<input type=\"radio\" name=\"f_field_" . $i . "_11\" value=\"1\" " . (${("f_field_" . $i . "_11")} == "1" ? "checked" : "") . ($csDiscountAbsolute == "0" ? " disabled" : "") . ">&nbsp;Ja";
    $outEditFields .= "</td>";

    if (${("f_field_" . $i . "_12")} == "") :
       if ($csMarkupFlag == "0" || $deactivateMarkup != "") :
	        ${("f_field_" . $i . "_12")} = "0";
	     else :
	        ${("f_field_" . $i . "_12")} = "1";
	     endif;
    endif;

    $outEditFields .= "<td valign=\"top\">";
    $outEditFields .= "<input type=\"radio\" name=\"f_field_" . $i . "_12\" value=\"0\" " . (${("f_field_" . $i . "_12")} != "1" ? "checked" : "") . ($csMarkupFlag == "0" || $deactivateMarkup != "" ? " disabled" : "") . ">&nbsp;Nein<br>";
    $outEditFields .= "<input type=\"radio\" name=\"f_field_" . $i . "_12\" value=\"1\" " . (${("f_field_" . $i . "_12")} == "1" ? "checked" : "") . ($csMarkupFlag == "0" || $deactivateMarkup != "" ? " disabled" : "") . ">&nbsp;Ja";
    $outEditFields .= "</td>";
    
    $outEditFields .= "<td valign=\"top\"><a href=\"javascript:clearJobFields('" . $i . "');\">Zurücksetzen</a></td>";
    $outEditFields .= "</tr>";
endfor;
?>

<html>

<head>
<title>LISTENERFASSUNG</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/searchLists.js" type="text/javascript"></script>
<script src="../include/checkFormTags.js" type="text/javascript"></script>

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

function clearJobFields(line) {
  for (var i = 1; i <= <?php echo $numOfInputFieldsPerRows ?>; i++) {
     if (i == 2 || i == 3 || i == 7 || i == 8 || i == 9 || i == 10 || i == 13 || i == 14)  {
       eval('document.forms[0].f_field_' + line + '_' + i).value = '';
     };
     if (i == 11 || i == 12)  {
       // cs_discount: do not change the values
     };
     if (i == 4 || i == 5 || i == 6)  {
        if (eval('document.forms[0].f_field_' + line + '_' + i).disabled == false) {
	         eval('document.forms[0].f_field_' + line + '_' + i).value = '';
	      };
     };
  };
};

function clearFields() {
  for (var j = 1; j <= <?php echo $numOfEditRows ?>; j++) {
      clearJobFields(j);
      eval('document.forms[0].f_field_' + j + '_1').value = j;
      eval('document.forms[0].f_field_' + j + '_4').value = <?php echo $currentYear ?>;
      eval('document.forms[0].f_field_' + j + '_5').value = <?php echo $timeToEditHourDefault ?>;
      eval('document.forms[0].f_field_' + j + '_6').value = <?php echo $timeToEditMinuteDefault ?>;
  }
  document.forms[0].f_act.value = '';
  document.forms[0].f_jbb_sort.value = '';
}

function checkDateFieldsBeingEmpty() {
	var notEmpty = true;
  for (var j = 1; j <= <?php echo $numOfEditRows ?>; j++) {
      if (trim(eval('document.forms[0].f_field_' + j + '_7').value) != '' &&
          (trim(eval('document.forms[0].f_field_' + j + '_9').value) != '' || trim(eval('document.forms[0].f_field_' + j + '_13').value) != '') &&
          trim(eval('document.forms[0].f_field_' + j + '_10').value) != '') {
         if (trim(eval('document.forms[0].f_field_' + j + '_2').value) == '' ||
             trim(eval('document.forms[0].f_field_' + j + '_3').value) == '' ||
             trim(eval('document.forms[0].f_field_' + j + '_4').value) == '' ||
             trim(eval('document.forms[0].f_field_' + j + '_5').value) == '' ||
             trim(eval('document.forms[0].f_field_' + j + '_6').value) == '') {
             notEmpty = false;
         }                   
      }
  }
  return notEmpty;
}

function checkDateFieldsBeingPastTime() {
	var ok = true;
  for (var j = 1; j <= <?php echo $numOfEditRows ?>; j++) {
  	  var today = new Date();
  	  var date1 = new Date(trim(eval('document.forms[0].f_field_' + j + '_4').value) + '-' + trim(eval('document.forms[0].f_field_' + j + '_3').value) + '-' + trim(eval('document.forms[0].f_field_' + j + '_2').value));
  	  // var date2 = new Date(trim(eval('document.forms[0].f_field_' + j + '_4').value), trim(eval('document.forms[0].f_field_' + j + '_3').value), trim(eval('document.forms[0].f_field_' + j + '_2').value));
      if (date1 && (today < date1)) {
          ok = false;          
      }
  }
  return ok;
}

function resetColoumnValues(mode) {
  for (var j = 1; j <= <?php echo $numOfEditRows ?>; j++) {
      eval('document.forms[0].f_field_' + j + '_11[0]').checked = false;
      eval('document.forms[0].f_field_' + j + '_11[1]').checked = false;
      
      eval('document.forms[0].f_field_' + j + '_12[0]').checked = false;
      eval('document.forms[0].f_field_' + j + '_12[1]').checked = false;
  }
  if (mode == '1') {
     document.forms[0].submit();
  };
}

function searchCs() {
  // var openerFunction = 
  searchCsCscGeneric('11100000000011101','resetColoumnValues(1)');
}

function finishPage(mode,jbb_sort) {
  if (mode == 'storeJobs') {
     if (document.forms[0].g_cs_id.value != '') {
        if (confirm('Möchten Sie die eingetragenen Neuaufträge speichern?')) {        	
        	 if (checkDateFieldsBeingEmpty()) {
        	 	  if (checkDateFieldsBeingPastTime()) {        	 	
     	           document.forms[0].f_act.value = mode;
     	           document.forms[0].action.disabled = true;
                 document.forms[0].submit();
              } else {
           	    alert('Mindestens ein Datum liegt in der Zukunft!');
           	    if (confirm('Möchten Sie dennoch speichern?')) {
           	    	 document.forms[0].sendMailFutureDate.value = 1;
     	             document.forms[0].f_act.value = mode;
     	             document.forms[0].action.disabled = true;
                   document.forms[0].submit();
           	    }
              }
           } else {
           	  alert('Eines der Felder bei Datum oder Uhrzeit ist nicht gesetzt!');
           }
        }
     } else {
       alert('Sie müssen zuvor bitte einen Kunden wählen!');
     }
  }
  if (mode == 'getListsOfCustomer') {
     // if (confirm('Möchten Sie die Listen einsehen?')) {
     	document.forms[0].f_act.value = mode;
        document.forms[0].submit();
     // }
  }
  if (mode == 'loadSpecialListOfCustomer') {
     if (document.forms[0].g_cs_id.value != '') {
        if (confirm('Möchten Sie die Liste laden?')) {
     	   document.forms[0].f_act.value = mode;
     	   document.forms[0].f_jbb_sort.value = jbb_sort;
           document.forms[0].submit();
        }
     } else {
       alert('Sie müssen zuvor bitte einen Kunden wählen!');
     }
  }    
  if (mode == 'clearPage') {
     if (confirm('Möchten Sie die komplette Seite zurücksetzen?')) {     	
        document.location.href = "jb_edit_batch.php?currentNavigationItem=listenerfassung";
     }
  }
  if (mode == 'clearPageAndCustomerSearch') {
     if (document.forms[0].g_cs_id.value != '' && document.forms[0].f_jbb_sort.value != '') {
        if (confirm('Möchten Sie einen neuen Kunden wählen? Die Seiteninformationen gehen verloren!')) {
           document.location.href = "jb_edit_batch.php?initCsSearch=1&currentNavigationItem=listenerfassung";
        }
     } else {
     	clearFields();
     	searchCs();
     };
  }
  if (mode == 'newCustomerList') {
     if (document.forms[0].g_cs_id.value != '' && document.forms[0].f_jbb_sort.value != '') {
        if (confirm('Möchten Sie eine neue Liste beginnen?')) {
           clearFields();
           document.forms[0].submit();
        }
     } else {     	
     	if (document.forms[0].g_cs_id.value == '') {
           alert('Es ist kein Kunde ausgewählt!');
        } else {
           clearFields();
        }
     }   
  }  
};

function checkDate(checkObj,mode,i,j) {
  var resetValue = checkDateFields(checkObj,mode);
  if (resetValue) {
     eval('document.forms[0].f_field_' + i + '_' + j).value = '';
     eval('document.forms[0].f_field_' + i + '_' + j).focus();
  }
}

function setFieldEditStatus(checkObj,mode) {

  var doContinue = true;
  if (checkObj.checked == false) {  
     doContinue = false;
     if (confirm('Achtung: Beim Deaktivieren werden alle Einträge der Spalte zurückgesetzt! Fortfahren?')) {
     	doContinue = true;
     } else {
     	checkObj.checked = true;
     }
  }

  if (doContinue) {
     for (var i = 1; i <= <?php echo $numOfEditRows ?>; i++) {
         if (mode == 'lfd') {
            if (checkObj.checked == true) {
               eval('document.forms[0].f_field_' + i + '_1').disabled = false;
            } else {            
               eval('document.forms[0].f_field_' + i + '_1').disabled = true;
            }
         }
         if (mode == 'year') {
            if (checkObj.checked == true) {
               eval('document.forms[0].f_field_' + i + '_4').disabled = false;
            } else {            
               eval('document.forms[0].f_field_' + i + '_4').disabled = true;
               eval('document.forms[0].f_field_' + i + '_4').value = <?php echo $currentYear ?>;
            }
         }
         if (mode == 'time') {
            if (checkObj.checked == true) {
               eval('document.forms[0].f_field_' + i + '_5').disabled = false;
               eval('document.forms[0].f_field_' + i + '_6').disabled = false;
            } else {
               eval('document.forms[0].f_field_' + i + '_5').disabled = true;
               eval('document.forms[0].f_field_' + i + '_6').disabled = true;
               eval('document.forms[0].f_field_' + i + '_5').value = <?php echo $timeToEditHourDefault ?>;
               eval('document.forms[0].f_field_' + i + '_6').value = <?php echo $timeToEditMinuteDefault ?>;
            }
         }
     }
  }
}

function changeColState(checkObj,mode) {

  var doContinue = false;
  var checkState = checkObj.checked;
  if (confirm('Achtung: Beim Aktivieren und Deaktivieren wird bei allen Aufträgen der Zuschlag entfernt bzw. gesetzt! Fortfahren?')) {
  	 doContinue = true;
  }

  if (doContinue) {
     for (var i = 1; i <= <?php echo $numOfEditRows ?>; i++) {
         if (mode == 'markup') {
            if (checkObj.checked == true) {
               eval('document.forms[0].f_field_' + i + '_12[0]').disabled = true;
               eval('document.forms[0].f_field_' + i + '_12[1]').disabled = true;
               eval('document.forms[0].f_field_' + i + '_12[0]').checked = true;
               eval('document.forms[0].f_field_' + i + '_12[1]').checked = false;
               eval('document.forms[0].f_field_' + i + '_12').value = '0';
            } else {
               eval('document.forms[0].f_field_' + i + '_12[0]').disabled = false;
               eval('document.forms[0].f_field_' + i + '_12[1]').disabled = false;
               eval('document.forms[0].f_field_' + i + '_12[0]').checked = false;
               eval('document.forms[0].f_field_' + i + '_12[1]').checked = true;
               eval('document.forms[0].f_field_' + i + '_12').value = '1';
            }
         }
     }
  } else {
  	checkObj.checked = !checkState;
  }
}

function showPageStatus() {
  alert('g_cs_id: ' + document.forms[0].g_cs_id.value);
  alert('g_csc_id: ' + document.forms[0].g_csc_id.value);
  alert('g_csc_name: ' + document.forms[0].g_csc_name.value);
  alert('g_cs_discount: ' + document.forms[0].g_cs_discount.value);
  alert('f_jbb_sort: ' + document.forms[0].f_jbb_sort.value);
}

function makeUpperCase(obj) {
  obj.value = obj.value.toUpperCase();
}

function presetDateFields(checkObj) {

  var dateDay = trim(eval('document.forms[0].f_field_1_2').value);
  var dateMonth = trim(eval('document.forms[0].f_field_1_3').value);

  var doContinue = true;
  if (checkObj.checked == true) {
     doContinue = false;
     
     if (confirm('Soll der Tag und der Monat in der 1. Zeile in alle Zeilen übernommen werden?')) {
     
        if (dateDay != '' && dateMonth != '') {
            doContinue = true;
        } else {
        	 alert('Tragen Sie bitte in der 1. Zeile einen Tag und einen Monat ein');
        	 checkObj.checked = false;
        }
     } else {
     	  checkObj.checked = false;
     }
  }

  if (doContinue) {
     for (var i = 1; i <= <?php echo $numOfEditRows ?>; i++) {
         if (checkObj.checked == true) {
            eval('document.forms[0].f_field_' + i + '_2').value = dateDay;
            eval('document.forms[0].f_field_' + i + '_3').value = dateMonth;
         } else {
            eval('document.forms[0].f_field_' + i + '_2').value = '';
            eval('document.forms[0].f_field_' + i + '_3').value = '';
         }
     }
  }
}
-->
</script>

<style>
table { border-collapse: collapse;}
td { border: 1px solid black; padding: 8px; }
</style>

</head>

<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>displayStatusMessage(); <?php if ($initCsSearch == "1") : echo "searchCs();" ; endif; ?>">

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

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

  <form action="jb_edit_batch.php" method="post">

  <input type="hidden" name="f_act" value="">  
  <input type="hidden" name="customerId" value="<?php echo $customerId ?>">
  <input type="hidden" name="cscIdRoot" value="<?php echo $cscIdRoot ?>">
  <input type="hidden" name="cscIdActual" value="<?php echo $cscIdActual ?>">  
  <input type="hidden" name="g_cs_id" value="<?php echo $g_cs_id ?>">
  <input type="hidden" name="f_jbb_sort" value="<?php echo $f_jbb_sort ?>">
  <input type="hidden" name="g_csc_id" value="<?php echo $g_csc_id ?>">  
  <input type="hidden" name="g_cs_discount" value="<?php echo $g_cs_discount ?>">
  <input type="hidden" name="sendMailFutureDate" value="">
  <?php echo $phpCurrentNavigationInputHidden ?>
  <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">

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

  <div class="f12bp1_blue">
    <div style="float:left">
      Liste der Firma:&nbsp;&nbsp;
      <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;
<!-- <input type="button" value="!!!" onClick="showPageStatus();"> -->
    </div>
    <?php echo defineButtonType10("Kunde&nbsp;suchen", "action_list", "finishPage('clearPageAndCustomerSearch');", "120", "left", "5"); ?>
  </div>
  <?php echo htmlDivLineSpacer("40px", "", "left"); ?>
  
  <div>
    <!-- Search, reset and store -->
    <div style="float:left">
      <a href="javascript:finishPage('clearPage');">Seite komplett zurücksetzen</a>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <a href="javascript:finishPage('getListsOfCustomer');">Listen des Kunden</a>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <a href="javascript:finishPage('newCustomerList');">Neue Liste des Kunden beginnen</a>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </div>
    <?php echo defineButtonType10("Neuaufträge&nbsp;speichern", "action_list", "finishPage('storeJobs');", "170", "left", "5"); ?>
    
    <!-- 
    <div>
      <a href="javascript:document.forms[0].f_act.value='search';document.forms[0].submit();">Suchen</a>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <a href="javascript:clearJobFields('0');">Suchfelder zurücksetzen</a>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </div>
    -->              
  </div>
  <?php echo htmlDivLineSpacer("20px", "", "left"); ?>
  
  <div>
    <?php echo $outStoredBatchListsOfCustomer ?>
  </div>
  <?php echo htmlDivLineSpacer("20px", "", "left"); ?>

  <div>
    <span class="f10bp1_blue">Aktuelle Liste:</span> &nbsp;&nbsp;&nbsp;<?php echo $outCurrentListOfCustomer ?>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <!--
    <input type="checkbox" name="f_filter[]" value="lfdToEditShow" onClick="javascript:setFieldEditStatus(this,'lfd');" <?php echo $lfdToEditShow ?>> Spalte Lfd aktiviert
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    -->
    <input type="checkbox" name="f_filter[]" value="yearToEditShow" onClick="javascript:setFieldEditStatus(this,'year');" <?php echo $yearToEditShow ?>> Spalte Jahreszahl aktiviert
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="checkbox" name="f_filter[]" value="timeToEditShow" onClick="javascript:setFieldEditStatus(this,'time');" <?php echo $timeToEditShow ?>> Spalten Uhrzeit aktiviert
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="checkbox" name="f_filter[]" value="deactivateMarkup" onClick="javascript:changeColState(this,'markup');" <?php echo $deactivateMarkup ?> <?php if ($csMarkupFlag == "0"): echo "disabled"; endif; ?>> Kein Zuschlag
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="checkbox" name="f_filter[]" value="presetDateFields" onClick="javascript:presetDateFields(this);" <?php echo $presetDateFields ?>> Tag und Monat vorbelegen
  </div>
  <?php echo htmlDivLineSpacer("10px", "", "left"); ?>

  <div>
    <table>
      <tr>
        <td>Lfd</td> <td>Datum</td> <td>Uhrzeit</td> <td>Auftrag / Tourenverlauf</td> <td>Kst./Referenz</td> <td>Fuhrbetrag</td> <td>Servicebetrag</td> <td>Fahrzeug</td> <td>KM</td> <td>Rabatt [<?php echo $csDiscountAbsolute ?>]&nbsp;%&nbsp;</td> <td>Zuschlag [<?php echo ($csMarkupFlag == "0" ? "NEIN" : "JA") ?>]&nbsp;</td> <td>Aktion</td>
        <!--
        <td><a href="javascript:document.forms[0].orderClause.value='ad_street, srvpaa.srvpaa_hsno_from';document.forms[0].f_act.value='search';document.forms[0].submit();">Straße</a></td>
        <td>&nbsp;</td>
        -->
      </tr>              
    
      <?php echo $outEditFields ?>
    
      <!-- Stored jobs -->
      <?php echo $out ?>
    </table>

    <!--
    <br><br>
    Anzahl Einträge: <?php echo $numOfRows ?><?php if ($numOfRows == "0" && $f_act == "search" && $statusMessage == "") : echo " (Keine Einträge gefunden.)"; endif; ?>              
    -->
  </div>

  </form>
</div>

</body>

</html>
