noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
forecast.inc.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004  *   This file is part of NOALYSS.
00005  *
00006  *   NOALYSS is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   NOALYSS is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with NOALYSS; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00022 
00023 /**\file
00024  * \brief display, add, delete and modify forecast
00025  */
00026 
00027 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00028 require_once 'class_anticipation.php';
00029 echo '<div class="content">';
00030 
00031 $sa = (isset($_REQUEST['sa'])) ? $_REQUEST['sa'] : 'list';
00032 /* * ********************************************************************
00033  * Remove a anticipation
00034  *
00035  *
00036  * ******************************************************************** */
00037 if (isset($_GET['del']))
00038 {
00039     $forecast = new Forecast($cn, $_GET['f_id']);
00040     $forecast->delete();
00041 }
00042 /*
00043  * Cloning
00044  */
00045 if (isset($_REQUEST ['clone']))
00046 {
00047     echo "<h2> cloning</h2>";
00048     /*
00049      * We need to clone the forecast
00050      */
00051     $anti = new Forecast($cn, $_REQUEST ['f_id']);
00052     $anti->object_clone();
00053     $sa="list";
00054 }
00055 /* * ********************************************************************
00056  * Save the modification mod_cat_save
00057  *
00058  *
00059  * ******************************************************************** */
00060 if (isset($_POST['mod_cat_save']))
00061 {
00062     /*
00063      * We save the forecast
00064      */
00065     $anti = new Forecast($cn, $_POST['f_id']);
00066     try
00067     {
00068         $cn->start();
00069         /* Save forecast */
00070         $anti->set_parameter('name', $_POST['an_name']);
00071         $anti->set_parameter('start_date', $_POST['start_date']);
00072         $anti->set_parameter('end_date', $_POST['end_date']);
00073 
00074         $anti->save();
00075 
00076         /* add new category */
00077         for ($i = 0; $i < MAX_CAT; $i++)
00078         {
00079             if (isset($_POST['fr_cat_new' . $i]))
00080             {
00081                 if (strlen(trim($_POST['fr_cat_new' . $i])) != 0)
00082                 {
00083                     $c = new Forecast_Cat($cn);
00084                     $c->set_parameter('order', $_POST['fc_order_new' . $i]);
00085                     $c->set_parameter('desc', $_POST['fr_cat_new' . $i]);
00086                     $c->set_parameter('forecast', $_POST['f_id']);
00087                     $c->save();
00088                 }
00089             }
00090         }
00091 
00092         /* update existing cat */
00093         foreach ($_POST as $key => $value)
00094         {
00095             $var = sscanf($key, 'fr_cat%d');
00096             $idx = sprintf("fr_cat%d", $var[0]);
00097             if (isset($_POST[$idx]))
00098             {
00099                 $fc = new Forecast_Cat($cn, $var[0]);
00100                 if (strlen(trim($_POST[$idx])) == 0)
00101                 {
00102                     $fc->delete();
00103                 }
00104                 else
00105                 {
00106                     $fc->set_parameter('order', $_POST['fc_order' . $var[0]]);
00107                     $fc->set_parameter('desc', $_POST['fr_cat' . $var[0]]);
00108                     $fc->set_parameter('forecast', $_POST['f_id']);
00109                     $fc->save();
00110                 }
00111             }
00112         }
00113 
00114         $cn->commit();
00115     }
00116     catch (Exception $e)
00117     {
00118         alert($e->getMessage());
00119         $cn->rollback();
00120     }
00121     $sa = 'vw';
00122 }
00123 /* * ********************************************************************
00124  * Save first the data for new
00125  *
00126  *
00127  * ******************************************************************** */
00128 if ($sa == 'new' || isset($_POST['step3']))
00129 {
00130     $correct = 0;
00131     if (isset($_POST['step3']))
00132     {
00133         /* save all the items */
00134         try
00135         {
00136             $cn->start();
00137             for ($i = 0; $i < $_POST['nbrow']; $i++)
00138             {
00139 
00140                 // Delete if needed
00141                 if (isset($_POST['fi_id' . $i]))
00142                 {
00143                     if (strlen(trim($_POST['an_cat_acc' . $i])) == 0 && strlen(trim($_POST['an_qc' . $i])) == 0)
00144                     {
00145                         $e = new Forecast_item($cn);
00146                         $e->set_parameter("id", $_POST['fi_id' . $i]);
00147                         $e->delete();
00148                     }
00149                 }
00150 
00151                 if (strlen(trim($_POST['an_cat_acc' . $i])) != 0 || strlen(trim($_POST['an_qc' . $i])) != 0)
00152                 {
00153                     /* we save only if there is something */
00154                     $e = new Forecast_item($cn);
00155                     if (isset($_POST['fi_id' . $i]))
00156                     {
00157                         $e->set_parameter("id", $_POST['fi_id' . $i]);
00158                     }
00159                     $e->set_parameter('text', $_POST['an_label' . $i]);
00160                     $e->set_parameter('amount', $_POST['an_cat_amount' . $i]);
00161                     $e->set_parameter('debit', $_POST['an_deb' . $i]);
00162                     $e->set_parameter('cat_id', $_POST['an_cat' . $i]);
00163                     $e->set_parameter('account', $_POST['an_cat_acc' . $i]);
00164                     $e->set_parameter('periode', $_POST['month' . $i]);
00165                     $f = new Fiche($cn);
00166                     if ($f->get_by_qcode($_POST['an_qc' . $i], false) == 0)
00167                         $e->set_parameter('card', $f->id);
00168                     else
00169                         $e->set_parameter('card', null);
00170                     $e->set_parameter('order', $i);
00171                     $e->save();
00172                 }
00173             }
00174             $cn->commit();
00175             $sa = 'vw'; // to avoid to restart the add of new anticipation
00176         }
00177         catch (Exception $e)
00178         {
00179             $cn->rollback();
00180             alert($e->getMessage());
00181             $correct = 1;
00182         }
00183     }
00184     /* Second step : we save the name and category
00185      * and propose the items we add the item */
00186     if ($correct == 2 || isset($_POST['step2']))
00187     {
00188         try
00189         {
00190             $cn->start();
00191             /* Save forecast */
00192             $a = new Forecast($cn);
00193             $a->set_parameter('name', $_POST['an_name']);
00194             $a->set_parameter('start_date', $_POST['start_date']);
00195             $a->set_parameter('end_date', $_POST['end_date']);
00196 
00197 
00198             $a->save();
00199             $id = $a->get_parameter("id");
00200             /* save cat */
00201             for ($i = 0; $i < MAX_CAT; $i++)
00202             {
00203                 if (strlen(trim($_POST['fr_cat' . $i])) != 0)
00204                 {
00205                     $c = new Forecast_Cat($cn);
00206                     $c->set_parameter('order', $_POST['fr_order' . $i]);
00207                     $c->set_parameter('desc', $_POST['fr_cat' . $i]);
00208                     $c->set_parameter('forecast', $id);
00209                     $c->save();
00210                 }
00211             }
00212             $cn->commit();
00213         }
00214         catch (Exception $e)
00215         {
00216             alert($e->getMessage());
00217             $correct = 1;
00218             unset($_POST['step2']);
00219             $cn->rollback();
00220         }
00221     }
00222 }
00223 
00224 /* * ********************************************************************
00225  * Ask for a new anticipation (forecast)
00226  *
00227  *
00228  * ******************************************************************** */
00229 if ($sa == 'new')
00230 {
00231     /* Second step : we save the name and category
00232      * and propose the items we add the item */
00233     if ($correct == 2 || isset($_POST['step2']))
00234     {
00235         /* Propose a form for the items
00236          */
00237         $anticip = new Anticipation($cn, $a->get_parameter("id"));
00238         echo '<div class="content">';
00239         echo ICard::ipopup('ipopcard');
00240         echo IPoste::ipopup('ipop_account');
00241         $search_card = new IPopup('ipop_card');
00242         $search_card->title = _('Recherche de fiche');
00243         $search_card->value = '';
00244         echo $search_card->input();
00245 
00246         echo '<form method="post" action="?">';
00247         echo dossier::hidden();
00248         echo HtmlInput::hidden('sa', 'new');
00249         echo HtmlInput::hidden('ac', $_REQUEST['ac']);
00250         echo HtmlInput::hidden('f_id', $id);
00251         echo $anticip->form_item();
00252         echo HtmlInput::submit('step3', _('Sauver'));
00253         echo '</form>';
00254         echo '</div>';
00255     }
00256     /* First step, the name and the category */
00257     if (!isset($_POST['step2']) || $correct == 1)
00258     {
00259         $anc = new Anticipation($cn);
00260         echo '<div class="content">';
00261         /* display a blank form for name and category */
00262         echo '<form method="post" action="?">';
00263         echo dossier::hidden();
00264         echo HtmlInput::hidden('sa', 'new');
00265         echo HtmlInput::hidden('ac', $_REQUEST['ac']);
00266         echo $anc->form_cat();
00267         echo HtmlInput::submit('step2', _('Sauver'));
00268         echo '</form>';
00269         echo '</div>';
00270     }
00271 }
00272 /* * ********************************************************************
00273  * If we request to modify the category or the name
00274  *
00275  *
00276  * ******************************************************************** */
00277 if (isset($_GET['mod_cat']))
00278 {
00279     $anc = new Anticipation($cn, $_GET['f_id']);
00280     echo '<div class="content">';
00281     /* display a blank form for name and category */
00282     echo '<form method="post" action="?">';
00283     echo dossier::hidden();
00284     echo HtmlInput::hidden('sa', 'mod');
00285     echo HtmlInput::hidden('ac', $_REQUEST['ac']);
00286     echo $anc->form_cat();
00287     echo HtmlInput::submit('mod_cat_save', _('Sauver'));
00288 
00289     echo '</form>';
00290     echo '</div>';
00291     return;
00292 }
00293 /* * ********************************************************************
00294  * If we request to modify the items
00295  *
00296  *
00297  * ******************************************************************** */
00298 if (isset($_GET['mod_item']))
00299 {
00300 
00301     /* Propose a form for the items
00302      */
00303     $anticip = new Anticipation($cn, $_GET['f_id']);
00304     echo '<div class="content">';
00305     echo ICard::ipopup('ipopcard');
00306     echo IPoste::ipopup('ipop_account');
00307     $search_card = new IPopup('ipop_card');
00308     $search_card->title = _('Recherche de fiche');
00309     $search_card->value = '';
00310     echo $search_card->input();
00311 
00312     echo '<form method="post" action="?">';
00313     echo dossier::hidden();
00314     echo HtmlInput::hidden('sa', 'new');
00315     echo HtmlInput::hidden('ac', $_REQUEST['ac']);
00316     echo HtmlInput::hidden('f_id', $_GET['f_id']);
00317     echo $anticip->form_item();
00318     echo HtmlInput::submit('step3', _('Sauver'));
00319     echo '</form>';
00320     echo '</div>';
00321     return;
00322 }
00323 /* * ********************************************************************
00324  * if a forecast is asked we display the result
00325  *
00326  *
00327  * ******************************************************************** */
00328 if (isset($_REQUEST['f_id']) && $sa == "vw")
00329 {
00330     echo '<div class="content">';
00331     $forecast = new Anticipation($cn);
00332     $forecast->set_parameter("id", $_REQUEST['f_id']);
00333     try
00334     {
00335         echo $forecast->display();
00336         echo '<div class="noprint">';
00337         echo '<form method="get">';
00338         echo dossier::hidden();
00339         echo HtmlInput::hidden('f_id', $_REQUEST['f_id']);
00340         echo HtmlInput::submit('mod_cat', _('Modifier nom ou catégories'));
00341         echo HtmlInput::submit('mod_item', _('Modifier éléments'));
00342         //echo HtmlInput::submit('cvs',_('Export CVS'));
00343         echo HtmlInput::submit('del', _('Effacer'), 'onclick="return confirm(\'' . _('Vous confirmez l\\\' effacement') . '\')"');
00344         echo HtmlInput::submit('clone', _('Cloner'), 'onclick="return confirm(\'' . _('Vous confirmez le clonage ') . '\')"');
00345         echo HtmlInput::hidden('ac', $_REQUEST['ac']);
00346         $href=http_build_query(array('ac'=>$_REQUEST['ac'],'gDossier'=>$_REQUEST['gDossier']));
00347         echo '<a style="display:inline" class="smallbutton" href="do.php?'.$href.'">'._('Retour').'</a>';
00348         echo '</form>';
00349         echo '</div>';
00350         echo '</div>';
00351         return;
00352     }
00353     catch (Exception $e)
00354     {
00355         echo "<div class=\"error\"><p>" . _("Erreur")." : " . $e->getMessage() . '</p><p>' . _('Vous devez corriger') . '</p></div>';
00356         $anc = new Anticipation($cn, $_GET['f_id']);
00357         echo '<div class="content">';
00358         /* display a blank form for name and category */
00359         echo '<form method="post" action="?">';
00360         echo dossier::hidden();
00361         echo HtmlInput::hidden('sa', 'mod');
00362         echo HtmlInput::hidden('ac', $_REQUEST['ac']);
00363         echo $anc->form_cat();
00364         echo HtmlInput::submit('mod_cat_save', _('Sauver'));
00365         echo '</form>';
00366         echo '</div>';
00367     }
00368 }
00369 /* * ********************************************************************
00370  * Display menu
00371  *
00372  *
00373  * ******************************************************************** */
00374 // display button add and list of forecast to display
00375 if ($sa=='list')
00376 {
00377     $aForecast=Forecast::load_all($cn);
00378     $menu=array();
00379     $get_dossier=dossier::get();
00380 
00381     echo '<div class="content">';
00382     echo _('Filtre')." ".HtmlInput::filter_table("forecast_table_id", '0', 1);
00383     echo '<TABLE id="forecast_table_id" class="vert_mtitle">';
00384     $href="?ac=".$_REQUEST['ac']."&sa=new&".$get_dossier;
00385     echo '<TR><TD class="first"><A HREF="'.$href.'">'._("Ajout d'une prévision").'</A></TD></TR>';
00386     $def=(isset($_REQUEST['f_id']))?$_REQUEST['f_id']:-1;
00387     for ($i=0; $i<count($aForecast); $i++)
00388     {
00389         $href="?ac=".$_REQUEST['ac']."&sa=vw&".$get_dossier.'&f_id='.$aForecast[$i]['f_id'];
00390         $name=h($aForecast[$i]['f_name']);
00391         $menu[]=array($href, $name, $name, $aForecast[$i]['f_id']);
00392         echo '<TR><TD><A HREF="'.$href.'">'.h($name).'</A></TD></TR>';
00393     }
00394 
00395     echo "</TABLE>";
00396     echo '</div>';
00397     return;
00398 }
00399 ?>
00400 </div>
 All Data Structures Namespaces Files Functions Variables Enumerations