+ Automatische Verlaengerung Vertrag
authorBettina Schwarzer <schwarzer@fhi-berlin.mpg.de>
Mon, 12 Sep 2011 10:34:07 +0200
changeset 8 908abe8cec4d
parent 7 d2fe4fb36670
child 9 f3ee378f9631
+ Automatische Verlaengerung Vertrag
fhiiqm/form/vertrag_form.inc.php
fhiiqm/inc/file_upload.inc.php
fhiiqm/inc/vertrag_dat_show.inc.php
fhiiqm/inc/vertragtab_ins.inc.php
fhiiqm/info_upd.php
fhiiqm/vertrag_flist1.php
fhiiqm/vertrag_flist2.php
fhiiqm/vertrag_ins.php
fhiiqm/vertrag_upd.php
--- a/fhiiqm/form/vertrag_form.inc.php	Thu Sep 08 15:25:25 2011 +0200
+++ b/fhiiqm/form/vertrag_form.inc.php	Mon Sep 12 10:34:07 2011 +0200
@@ -235,6 +235,10 @@
              ?>
         </td>
     </tr>
+    <tr>
+        <td>automatische Verl&auml;ngerung</td>
+        <td><input name="vertrag[cautoend]" type="checkbox" value="1" <?php if ($vtr["cautoend"]) echo "checked";?>/></td>
+    </tr>
 	<tr>
         <td>K&uuml;ndigungsfrist<br />(Monate vor Ablauf)</td>
         <td><input name="vertrag[cnot]" type="text" size="10" maxlength="3" value="<?php echo $vtr['cnot']; ?>"/></td>
@@ -272,6 +276,7 @@
         <td>
             <select name="vertrag[cpers][]" size="7" multiple="multiple">
                 <?php
+                    $select = null;
                     if (is_array($vtr['cpers'])) $select = in_array( "-1", $vtr['cpers'] ) ? ' selected' : null;
                     echo "<option $select value=\"-1\"></option>\n";
                     $sql = "SELECT persknr, CONCAT (nachname, ', ',vorname) as pname FROM fhiiqm.Mitarbeiter ORDER BY 2";
@@ -294,12 +299,18 @@
                     <td>j&auml;hrliche Kosten (&euro;)</td><br />
                     <td>";
                 $j=0;
-                if ($vtr['ejahr'])
+                if ($vtr['ejahr']) 
+                    $ejahr = $vtr['ejahr'];
+                elseif ($vtr["cautoend"] && !$vtr['ejahr']) // automatische Vertragsverlaengerung und kein Endjahr angegeben
+                    $ejahr = date("Y");
+                else 
+                    $ejahr = null;
+                if ($ejahr)
                 {
-                    for ($i=(int)$vtr['bjahr']; $i<(int)$vtr['ejahr']+1; $i++ )
+                    for ($i=(int)$vtr['bjahr']; $i<(int)$ejahr+1; $i++ )
                     {
                         echo "<input name=\"vertrag[kjahr][$j]\" type=\"text\" size=\"4\" value=\"$i\"/>&nbsp;&nbsp;&nbsp;";
-                        echo "<input name=\"vertrag[kost][$j]\" type=\"text\" value=\"" . $vtr['kost'][$j] . "\"/><br />";
+                        echo "<input name=\"vertrag[kost][$j]\" type=\"text\" value=\"" . $vtr['kost'][$j] . "\"/><br />\n";
                         $j++;
                     }
                 }
--- a/fhiiqm/inc/file_upload.inc.php	Thu Sep 08 15:25:25 2011 +0200
+++ b/fhiiqm/inc/file_upload.inc.php	Mon Sep 12 10:34:07 2011 +0200
@@ -73,43 +73,50 @@
     *    $ufile  -   Name aus Upload-Feld Formular
     *    $id     -   ID
     */
-            switch ($id) 
-            {
-                case ($id < 10):
-                    $len = 2;
-                    break;
-                case ($id < 100):
-                    $len = 3;
-                    break;
-                case ($id < 1000):
-                    $len = 4;
-                    break;
-            }
+
+        $su = array("ä","ö","ü","ß","Ä","Ö","Ü");
+        $er = array("ae","oe","ue","ss","Ae","Oe","Ue");
+    
+        switch ($id) 
+        {
+            case ($id < 10):
+                $len = 2;
+                break;
+            case ($id < 100):
+                $len = 3;
+                break;
+            case ($id < 1000):
+                $len = 4;
+                break;
+        }
 //            echo "cid, len : $cid, $len<br><br>\n";          
-    		// Dokument-Typ aus Dateibezeichnung bzw. Uploadfile, wenn nicht angegeben
-    		$filea = explode(".",$nfile);
-    		$anz    = count($filea);
-          	if ($anz>1) // File-Typ im Eingabenamen angegeben
-            {   
-                $typ = $filea[$anz-1]; 
-                for ($i=0; $i<$anz-1; $i++)
-                {
-                    $fname .= "." . $filea[$i];
-                }
+		// Dokument-Typ aus Dateibezeichnung bzw. Uploadfile, wenn nicht angegeben
+		$filea = explode(".",$nfile);
+		$anz    = count($filea);
+      	if ($anz>1) // File-Typ im Eingabenamen angegeben
+        {   
+            $typ = $filea[$anz-1]; 
+            for ($i=0; $i<$anz-1; $i++)
+            {
+                $fname .= "." . $filea[$i];
             }
-            else // File-Typ aus Uploadfile
-            {
-                $filep = explode(".",$_FILES[$ufile]["name"]);
-                $anz    = count($filep);
-                if ($anz>1) $typ = $filep[$anz-1]; else $typ = "pdf";
-                $fname = $nfile;
-            }
-            if (strlen($typ) != 3) $typ="pdf";
-            if (substr($fname,0,1) == ".")
-                $fname = substr($fname,1,50-(4+$len)) . "." .$typ;
-            else
-                $fname = substr($fname,0,50-(4+$len)) . "." .$typ;
-            if (substr($fname,0,$len) == "$id" . "_") $fname = substr($fname,$len,50);
+        }
+        else // File-Typ aus Uploadfile
+        {
+            $filep = explode(".",$_FILES[$ufile]["name"]);
+            $anz    = count($filep);
+            if ($anz>1) $typ = $filep[$anz-1]; else $typ = "pdf";
+            $fname = $nfile;
+        }
+        // ev. vorhandene gaengige Umlaute ersetzen
+        $fname = str_replace($su,$er,$fname);
+        
+        if (strlen($typ) != 3) $typ="pdf";
+        if (substr($fname,0,1) == ".")
+            $fname = substr($fname,1,50-(4+$len)) . "." .$typ;
+        else
+            $fname = substr($fname,0,50-(4+$len)) . "." .$typ;
+        if (substr($fname,0,$len) == "$id" . "_") $fname = substr($fname,$len,50);
             
         return $fname;
 }
--- a/fhiiqm/inc/vertrag_dat_show.inc.php	Thu Sep 08 15:25:25 2011 +0200
+++ b/fhiiqm/inc/vertrag_dat_show.inc.php	Mon Sep 12 10:34:07 2011 +0200
@@ -26,6 +26,9 @@
             echo "<tr><td>Vertrag-Beginn: </td><td>" . $vbd. "</td></tr>\n";
             echo "<tr><td>Vertrag-Ende: </td><td>" . $ved. "</td></tr>\n";
 
+            if ($vtr["cautoend"])
+                echo "<tr><td>automatische Verl&auml;ngerung:</td><td>ja</td><tr>";
+                
             echo "<tr><td>Kündigungsfrist (mon vor V-Ende): </td><td>" . $vtr['cnot'] . "</td></tr>\n";
             // Partner
             $sql = "SELECT part_firma FROM Partner WHERE part_ID = $pid";
@@ -51,9 +54,16 @@
             // Kosten
             echo "<tr><td>j&auml;hrliche Kosten: </td><td>";
             $j=0;
-            if ($vtr['ejahr']) // Endjahr angegeben
+            if ($vtr['ejahr']) 
+                $ejahr = $vtr['ejahr'];
+            elseif ($vtr["cautoend"] && !$vtr['ejahr']) // automatische Vertragsverlaengerung und kein Endjahr angegeben
+                $ejahr = date("Y");
+            else 
+                $ejahr = null;
+//            if ($vtr['ejahr']) // Endjahr angegeben
+            if ($ejahr) // Endjahr angegeben
             {
-                for ($i=(int)$vtr['bjahr']; $i< (int)$vtr['ejahr'] +1; $i++)
+                for ($i=(int)$vtr['bjahr']; $i< (int)$ejahr +1; $i++)
                 {
                     if ($vtr['kost'][$j])
                     {
--- a/fhiiqm/inc/vertragtab_ins.inc.php	Thu Sep 08 15:25:25 2011 +0200
+++ b/fhiiqm/inc/vertragtab_ins.inc.php	Mon Sep 12 10:34:07 2011 +0200
@@ -101,9 +101,16 @@
                 if ($retdk)
                 {
                     $j=0;
-                    if ($vtr['ejahr']) // Endjahr angegeben
+                    if ($vtr['ejahr']) 
+                        $ejahr = $vtr['ejahr'];
+                    elseif ($vtr["cautoend"] && !$vtr['ejahr']) // automatische Vertragsverlaengerung und kein Endjahr angegeben
+                        $ejahr = date("Y");
+                    else 
+                        $ejahr = null;
+//                    if ($vtr['ejahr']) // Endjahr angegeben
+                    if ($ejahr) // Endjahr angegeben
                     {
-                        for ($i=(int)$vtr['bjahr']; $i< (int)$vtr['ejahr'] +1; $i++)
+                        for ($i=(int)$vtr['bjahr']; $i< (int)$ejahr +1; $i++)
                         {
                             if ($vtr['kost'][$j])
                             {
--- a/fhiiqm/info_upd.php	Thu Sep 08 15:25:25 2011 +0200
+++ b/fhiiqm/info_upd.php	Mon Sep 12 10:34:07 2011 +0200
@@ -166,7 +166,7 @@
                 // echo "upload-error: " . $_FILES["ifile"]["error"] .  "<br />\n";
             if (is_uploaded_file($_FILES["ifile"]["tmp_name"]) && isset($_FILES["ifile"]["name"]) && $_FILES["ifile"]["name"] )
             {
-                echo "file hochgeladen: " . $_FILES["ifile"]["name"] ."<br />\n";
+//                echo "file hochgeladen: " . $_FILES["ifile"]["name"] ."<br />\n";
                 include ("inc/file_upload.inc.php");
                 $fname = gen_filename($inf['ifname'],"ifile",$infid);
                 $retdf  = mod_file("/var/www/fhiiqm/infos",$infid,"","del");  // Loeschen alte Datei
--- a/fhiiqm/vertrag_flist1.php	Thu Sep 08 15:25:25 2011 +0200
+++ b/fhiiqm/vertrag_flist1.php	Mon Sep 12 10:34:07 2011 +0200
@@ -10,7 +10,7 @@
     <script type="text/javascript">
         function winopen (addr,title) 
         {
-          mywin = window.open(addr,title, "width=1100,height=700,left=400,top=300,menubar=yes,status=yes,scrollbars=yes,resizable=yes,toolbar=yes");
+          mywin = window.open(addr,title, "width=1400,height=700,left=400,top=300,menubar=yes,status=yes,scrollbars=yes,resizable=yes,toolbar=yes");
           mywin.focus();
         }
     </script>
--- a/fhiiqm/vertrag_flist2.php	Thu Sep 08 15:25:25 2011 +0200
+++ b/fhiiqm/vertrag_flist2.php	Mon Sep 12 10:34:07 2011 +0200
@@ -96,8 +96,9 @@
         tab_column(2,"Bezeichnung",$sort,$dir,0,$fnum,$filter,$start,$zeil);
         tab_column(8,"Beginn",$sort,$dir,0,$fnum,$filter,$start,$zeil);
         tab_column(9,"Ende",$sort,$dir,0,$fnum,$filter,$start,$zeil);
-        tab_column(10,"K&uuml;nd.frist",$sort,$dir,0,$fnum,$filter,$start,$zeil);
-        tab_column(11,"Partner",$sort,$dir,0,$fnum,$filter,$start,$zeil);
+        tab_column(10,"Autoend",$sort,$dir,0,$fnum,$filter,$start,$zeil);
+        tab_column(11,"K&uuml;nd.frist",$sort,$dir,0,$fnum,$filter,$start,$zeil);
+        tab_column(12,"Partner",$sort,$dir,0,$fnum,$filter,$start,$zeil);
         echo "<th>Kosten/Jahr(&euro;)</th>";
         echo "<th>Bemerkung</th>";
 
@@ -128,6 +129,7 @@
                     echo "<td>" . $ce->format('d.m.Y')."</td>";    
                 }
                 else  echo "<td>&nbsp;</td>";       
+                if ($row->cautoend) echo "<td>ja</td>"; else echo "<td>&nbsp;</td>"; 
                 echo "<td align='right'>$row->kmon</td>";    
                 echo "<td>$row->partfirma</td>";
                 echo "<td>"; 
--- a/fhiiqm/vertrag_ins.php	Thu Sep 08 15:25:25 2011 +0200
+++ b/fhiiqm/vertrag_ins.php	Mon Sep 12 10:34:07 2011 +0200
@@ -127,10 +127,10 @@
         $stmt = $dbc -> stmtinit();
         if (is_object($stmt))
         {
-            $stmt -> prepare("INSERT INTO Vertrag (contract_name, contract_l,vtyp_ID,contract_begin, contract_end,contract_mon_notice,
-                    contract_file,bemerkung) 
-                    VALUES(?,?,?,?,?,?,?,?)");
-            $stmt -> bind_param('ssississ',$vtr["cname"],$vtr["clong"],$vtr['vtyp'],$vbegin,$vend,$vtr['cnot'],$cfile,$vtr['cbem']);
+            $stmt -> prepare("INSERT INTO Vertrag (contract_name, contract_l,vtyp_ID,contract_begin, contract_end, contract_autoend, 
+                    contract_mon_notice, contract_file, bemerkung) 
+                    VALUES(?,?,?,?,?,?,?,?,?)");
+            $stmt -> bind_param('ssissiiss',$vtr["cname"],$vtr["clong"],$vtr['vtyp'],$vbegin,$vend,$vtr['cautoend'],$vtr['cnot'],$cfile,$vtr['cbem']);
             $result = $stmt -> execute();
         }       
         if ($dbc->error) echo "error: " . $dbc->error . "<br><br>\n";
--- a/fhiiqm/vertrag_upd.php	Thu Sep 08 15:25:25 2011 +0200
+++ b/fhiiqm/vertrag_upd.php	Mon Sep 12 10:34:07 2011 +0200
@@ -42,7 +42,7 @@
         if (!$upd && !$del)
         {
             $sql = "SELECT contract_ID,contract_name,contract_s,contract_l,vtyp_ID,contract_begin,contract_end,
-                    contract_mon_notice,contract_file,Bemerkung 
+                    contract_autoend,contract_mon_notice,contract_file,Bemerkung 
                     FROM fhiiqm.Vertrag WHERE contract_ID = $cid";
             if ($result = $dbc ->queryObjectArray($sql))
             {
@@ -58,6 +58,7 @@
                     $vtr['ejahr']   = substr($row->contract_end,0,4);
                     $vtr['emon']    = substr($row->contract_end,5,2);
                     $vtr['etag']    = substr($row->contract_end,8,2);
+                    $vtr['cautoend']= $row->contract_autoend;
                     $vtr['cnot']    = $row->contract_mon_notice;
                     $vtr['cfname']  = $row->contract_file;
                     $vtr['cbem']    = $row->Bemerkung;
@@ -91,12 +92,22 @@
                 }
             }
             // Kosten
-            $sql = "SELECT kosten FROM Vertrag_Kosten WHERE contract_ID = $cid ORDER BY k_year ";
+            if ($vtr['ejahr']) 
+                $ejahr = $vtr['ejahr'];
+            elseif ($vtr["cautoend"] && !$vtr['ejahr']) // automatische Vertragsverlaengerung und kein Endjahr angegeben
+                $ejahr = date("Y");
+            else 
+                $ejahr = null;
+            for ($i=(int)$vtr['bjahr']; $i< (int)$ejahr +1; $i++)
+            {   $ayear[] = $i;  }
+            $sql = "SELECT k_year, kosten FROM Vertrag_Kosten WHERE contract_ID = $cid ORDER BY k_year ";
             if ($result = $dbc -> queryObjectArray($sql))
             {
                 foreach ($result as $row)
                 {
-                    $vtr['kost'][] = str_replace('.',',',$row->kosten);
+                    $j = array_search($row->k_year,$ayear);
+                    if ( $j > -1 )
+                        $vtr['kost'][$j] = str_replace('.',',',$row->kosten);
                 }
             }
             
@@ -213,15 +224,16 @@
                     contract_l = ?, 
                     vtyp_ID = ?, 
                     contract_begin = ?, 
-                    contract_end = ?, 
+                    contract_end = ?,
+                    contract_autoend = ?, 
                     contract_mon_notice = ?,
                     contract_file = ?,  
                     Bemerkung = ? 
                     WHERE contract_ID = $cid") ;
-            $stmt -> bind_param('ssississ',$vtr["cname"],$vtr["clong"],$vtr['vtyp'],$vbegin,$vend,$vtr['cnot'],$cfile,$vtr['cbem']);
+            $stmt -> bind_param('ssissiiss',$vtr["cname"],$vtr["clong"],$vtr['vtyp'],$vbegin,$vend,$vtr['cautoend'],$vtr['cnot'],$cfile,$vtr['cbem']);
             $retv = $stmt -> execute();
         }       
-//        echo "UPDATE-sql = $sql<br />\n";
+//        echo "UPDATE-sql = \n";print_r($stmt); echo "<br />";
         if (!$retv) echo "error update" . $dbc -> error ."<br />\n";
         if ($retv)
         {