<?php      
/*=======================================================================
 *
 * cron_export.php
 *
  =======================================================================*/


include_once ("../include/mcglobal.inc.php");
include_once ("../include/ftp.inc.php");


if ($argv[1] == "acapella7890") :

   // Error reporting
   error_reporting(E_ERROR | E_WARNING | E_PARSE);

   $path = getAbsoluteSystemPath();
   $passwd = "acapella7890";
   $logFile = $path . "/log/sys_auto_export.log";
   $emptyArgument = "\"\"";
   $fileNamePrefix = substr(getDateTime("6"), 0, 12);  // Format: "YmdHi"

   if ($argv[2] == "today") :
      $toDay = getDateTime("day");   
      $toMonth = getDateTime("month");
      $toYear = getDateTime("year");
   else :
      $toDay = getDateTime("day_yesterday");   
      $toMonth = getDateTime("month_yesterday");
      $toYear = getDateTime("year_yesterday");
   endif;


   // Arguments
   // $hq_id $usr_id $dummy_01 $f_act $f_exp_category $f_delimiter $f_parname $f_parname_export $f_fileName $day_to $month_to $year_to $f_cs_eid_filter $f_jbp_filter $specialJbPayment $jbpc_id

   $exportPars = array();
/*
   $exportPars["HTG_HB_DEB"]  = array("101","5546","_","export","1","|","RETRANS Debitorenstammsatz","RETRANS Debitorenstammsatz",$fileNamePrefix . ".003.deb",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_HB_KRED"] = array("101","5546","_","export","2","|","RETRANS Kreditorenstammsatz","RETRANS Kreditorenstammsatz",$fileNamePrefix . ".003.kred",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_HB_FZG"]  = array("101","5546","_","export","3","|","RETRANS Fahrzeugstammsatz","RETRANS Fahrzeugstammsatz",$fileNamePrefix . ".003.fzg",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_HB_ABR"]  = array("101","5546","_","export","5","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".003.abr",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_HB_GUT"]  = array("101","5546","_","export","6","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".003.gut",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
*/
   $exportPars["HTG_HH_DEB"]  = array("102","7657","_","export","1","|","RETRANS Debitorenstammsatz","RETRANS Debitorenstammsatz",$fileNamePrefix . ".001.deb",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_HH_KRED"] = array("102","7657","_","export","2","|","RETRANS Kreditorenstammsatz","RETRANS Kreditorenstammsatz",$fileNamePrefix . ".001.kred",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_HH_FZG"]  = array("102","7657","_","export","3","|","RETRANS Fahrzeugstammsatz","RETRANS Fahrzeugstammsatz",$fileNamePrefix . ".001.fzg",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_HH_ABR"]  = array("102","7657","_","export","5","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".001.abr",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_HH_GUT"]  = array("102","7657","_","export","6","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".001.gut",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");

   $exportPars["HTG_B_DEB"]   = array("103","6726","_","export","1","|","RETRANS Debitorenstammsatz","RETRANS Debitorenstammsatz",$fileNamePrefix . ".007.deb",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_B_KRED"]  = array("103","6726","_","export","2","|","RETRANS Kreditorenstammsatz","RETRANS Kreditorenstammsatz",$fileNamePrefix . ".007.kred",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_B_FZG"]   = array("103","6726","_","export","3","|","RETRANS Fahrzeugstammsatz","RETRANS Fahrzeugstammsatz",$fileNamePrefix . ".007.fzg",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_B_ABR"]   = array("103","6726","_","export","5","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".007.abr",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_B_GUT"]   = array("103","6726","_","export","6","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".007.gut",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
                              
   $exportPars["HTG_H_DEB"]   = array("104","7329","_","export","1","|","RETRANS Debitorenstammsatz","RETRANS Debitorenstammsatz",$fileNamePrefix . ".006.deb",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_H_KRED"]  = array("104","7329","_","export","2","|","RETRANS Kreditorenstammsatz","RETRANS Kreditorenstammsatz",$fileNamePrefix . ".006.kred",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_H_FZG"]   = array("104","7329","_","export","3","|","RETRANS Fahrzeugstammsatz","RETRANS Fahrzeugstammsatz",$fileNamePrefix . ".006.fzg",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_H_ABR"]   = array("104","7329","_","export","5","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".006.abr",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_H_GUT"]   = array("104","7329","_","export","6","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".006.gut",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
                              
   $exportPars["HTG_F_DEB"]   = array("105","9540","_","export","1","|","RETRANS Debitorenstammsatz","RETRANS Debitorenstammsatz",$fileNamePrefix . ".002.deb",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_F_KRED"]  = array("105","9540","_","export","2","|","RETRANS Kreditorenstammsatz","RETRANS Kreditorenstammsatz",$fileNamePrefix . ".002.kred",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_F_FZG"]   = array("105","9540","_","export","3","|","RETRANS Fahrzeugstammsatz","RETRANS Fahrzeugstammsatz",$fileNamePrefix . ".002.fzg",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_F_ABR"]   = array("105","9540","_","export","5","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".002.abr",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_F_GUT"]   = array("105","9540","_","export","6","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".002.gut",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");

   $exportPars["HTG_DD_DEB"]  = array("106","6449","_","export","1","|","RETRANS Debitorenstammsatz","RETRANS Debitorenstammsatz",$fileNamePrefix . ".005.deb",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_DD_KRED"] = array("106","6449","_","export","2","|","RETRANS Kreditorenstammsatz","RETRANS Kreditorenstammsatz",$fileNamePrefix . ".005.kred",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_DD_FZG"]  = array("106","6449","_","export","3","|","RETRANS Fahrzeugstammsatz","RETRANS Fahrzeugstammsatz",$fileNamePrefix . ".005.fzg",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_DD_ABR"]  = array("106","6449","_","export","5","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".005.abr",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_DD_GUT"]  = array("106","6449","_","export","6","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".005.gut",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");

   $exportPars["HTG_E_DEB"]   = array("107","9755","_","export","1","|","RETRANS Debitorenstammsatz","RETRANS Debitorenstammsatz",$fileNamePrefix . ".009.deb",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_E_KRED"]  = array("107","9755","_","export","2","|","RETRANS Kreditorenstammsatz","RETRANS Kreditorenstammsatz",$fileNamePrefix . ".009.kred",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_E_FZG"]   = array("107","9755","_","export","3","|","RETRANS Fahrzeugstammsatz","RETRANS Fahrzeugstammsatz",$fileNamePrefix . ".009.fzg",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_E_ABR"]   = array("107","9755","_","export","5","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".009.abr",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_E_GUT"]   = array("107","9755","_","export","6","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".009.gut",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");

   $exportPars["HTG_L_DEB"]   = array("108","9248","_","export","1","|","RETRANS Debitorenstammsatz","RETRANS Debitorenstammsatz",$fileNamePrefix . ".008.deb",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_L_KRED"]  = array("108","9248","_","export","2","|","RETRANS Kreditorenstammsatz","RETRANS Kreditorenstammsatz",$fileNamePrefix . ".008.kred",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_L_FZG"]   = array("108","9248","_","export","3","|","RETRANS Fahrzeugstammsatz","RETRANS Fahrzeugstammsatz",$fileNamePrefix . ".008.fzg",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_L_ABR"]   = array("108","9248","_","export","5","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".008.abr",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_L_GUT"]   = array("108","9248","_","export","6","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".008.gut",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");

   $exportPars["HTG_M_DEB"]   = array("109","10041","_","export","1","|","RETRANS Debitorenstammsatz","RETRANS Debitorenstammsatz",$fileNamePrefix . ".013.deb",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_M_KRED"]  = array("109","10041","_","export","2","|","RETRANS Kreditorenstammsatz","RETRANS Kreditorenstammsatz",$fileNamePrefix . ".013.kred",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_M_FZG"]   = array("109","10041","_","export","3","|","RETRANS Fahrzeugstammsatz","RETRANS Fahrzeugstammsatz",$fileNamePrefix . ".013.fzg",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_M_ABR"]   = array("109","10041","_","export","5","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".013.abr",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_M_GUT"]   = array("109","10041","_","export","6","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".013.gut",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");

   $exportPars["HTG_N_DEB"]   = array("110","10316","_","export","1","|","RETRANS Debitorenstammsatz","RETRANS Debitorenstammsatz",$fileNamePrefix . ".023.deb",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_N_KRED"]  = array("110","10316","_","export","2","|","RETRANS Kreditorenstammsatz","RETRANS Kreditorenstammsatz",$fileNamePrefix . ".023.kred",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_N_FZG"]   = array("110","10316","_","export","3","|","RETRANS Fahrzeugstammsatz","RETRANS Fahrzeugstammsatz",$fileNamePrefix . ".023.fzg",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_N_ABR"]   = array("110","10316","_","export","5","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".023.abr",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_N_GUT"]   = array("110","10316","_","export","6","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".023.gut",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");

   $exportPars["HTG_S_DEB"]   = array("111","10569","_","export","1","|","RETRANS Debitorenstammsatz","RETRANS Debitorenstammsatz",$fileNamePrefix . ".014.deb",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_S_KRED"]  = array("111","10569","_","export","2","|","RETRANS Kreditorenstammsatz","RETRANS Kreditorenstammsatz",$fileNamePrefix . ".014.kred",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_S_FZG"]   = array("111","10569","_","export","3","|","RETRANS Fahrzeugstammsatz","RETRANS Fahrzeugstammsatz",$fileNamePrefix . ".014.fzg",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_S_ABR"]   = array("111","10569","_","export","5","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".014.abr",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_S_GUT"]   = array("111","10569","_","export","6","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".014.gut",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");

   $exportPars["HTG_K_DEB"]   = array("112","23403","_","export","1","|","RETRANS Debitorenstammsatz","RETRANS Debitorenstammsatz",$fileNamePrefix . ".015.deb",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_K_KRED"]  = array("112","23403","_","export","2","|","RETRANS Kreditorenstammsatz","RETRANS Kreditorenstammsatz",$fileNamePrefix . ".015.kred",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_K_FZG"]   = array("112","23403","_","export","3","|","RETRANS Fahrzeugstammsatz","RETRANS Fahrzeugstammsatz",$fileNamePrefix . ".015.fzg",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_K_ABR"]   = array("112","23403","_","export","5","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".015.abr",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_K_GUT"]   = array("112","23403","_","export","6","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".015.gut",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");

   $exportPars["HTG_LG_DEB"]  = array("203","12573","_","export","1","|","RETRANS Debitorenstammsatz","RETRANS Debitorenstammsatz",$fileNamePrefix . ".010.deb",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_LG_KRED"] = array("203","12573","_","export","2","|","RETRANS Kreditorenstammsatz","RETRANS Kreditorenstammsatz",$fileNamePrefix . ".010.kred",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_LG_FZG"]  = array("203","12573","_","export","3","|","RETRANS Fahrzeugstammsatz","RETRANS Fahrzeugstammsatz",$fileNamePrefix . ".010.fzg",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_LG_ABR"]  = array("203","12573","_","export","5","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".010.abr",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");
   $exportPars["HTG_LG_GUT"]  = array("203","12573","_","export","6","|","RETRANS Abrechnungen","RETRANS Abrechnungen",$fileNamePrefix . ".010.gut",$toDay,$toMonth,$toYear,$emptyArgument,$emptyArgument,"","");

   $exportParsKeys = array_keys($exportPars);
   $exportParsKeysLen = count($exportParsKeys);
   if ($exportParsKeysLen != "" && is_numeric($exportParsKeysLen)) :

      // Exports
      for ($i = 0; $i < $exportParsKeysLen; $i++) :

          list($hq_id,$usr_id,$dummy_01,$f_act,$f_exp_category,$f_delimiter,$f_parname,$f_parname_export,$f_fileName,
               $day_to,$month_to,$year_to,$f_cs_eid_filter,$f_jbp_filter,$specialJbPayment,$jbpc_id) = $exportPars[$exportParsKeys[$i]];

          $cmd = "php " . $path . "/export/export.php " . $passwd . " " . $hq_id . " " . $usr_id . " " . $dummy_01 . " " . $f_act . " " . $f_exp_category . " " . "\"" . $f_delimiter. "\"" . " " 
                                                        . "\"" . $f_parname . "\"" . " " . "\"" . $f_parname_export . "\"" . " " . "\"" . $f_fileName . "\"" . " " . $day_to . " " . $month_to . " " . $year_to . " " 
                                                        . $f_cs_eid_filter . " " . $f_jbp_filter . " " . $specialJbPayment . " " . $jbpc_id . " &";
// echo $exportParsKeys[$i] . ":\n";
// echo $cmd . "\n\n\n";
          $cmdOutput = null;
          exec($cmd, $cmdOutput);
          // list($errNo, $errDesc) = $cmdOutput;

          $currentTime = getDateTime("0");
          writeToFile($logFile, "OP=AUTO_EXPORT|DATETIME=" . $currentTime . "|CUST=" . $exportParsKeys[$i]);

          sleep(5);  // Avoid too many tasks
      endfor;
   endif;
endif;      
?>