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'] : '';
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 }
00054 /* * ********************************************************************
00055  * Save the modification mod_cat_save
00056  *
00057  *
00058  * ******************************************************************** */
00059 if (isset($_POST['mod_cat_save']))
00060 {
00061     /*
00062      * We save the forecast
00063      */
00064     $anti = new Forecast($cn, $_POST['f_id']);
00065     try
00066     {
00067         $cn->start();
00068         /* Save forecast */
00069         $anti->set_parameter('name', $_POST['an_name']);
00070         $anti->set_parameter('start_date', $_POST['start_date']);
00071         $anti->set_parameter('end_date', $_POST['end_date']);
00072 
00073         $anti->save();
00074 
00075         /* add new category */
00076         for ($i = 0; $i < MAX_CAT; $i++)
00077         {
00078             if (isset($_POST['fr_cat_new' . $i]))
00079             {
00080                 if (strlen(trim($_POST['fr_cat_new' . $i])) != 0)
00081                 {
00082                     $c = new Forecast_Cat($cn);
00083                     $c->set_parameter('order', $_POST['fc_order_new' . $i]);
00084                     $c->set_parameter('desc', $_POST['fr_cat_new' . $i]);
00085                     $c->set_parameter('forecast', $_POST['f_id']);
00086                     $c->save();
00087                 }
00088             }
00089         }
00090 
00091         /* update existing cat */
00092         foreach ($_POST as $key => $value)
00093         {
00094             $var = sscanf($key, 'fr_cat%d');
00095             $idx = sprintf("fr_cat%d", $var[0]);
00096             if (isset($_POST[$idx]))
00097             {
00098                 $fc = new Forecast_Cat($cn, $var[0]);
00099                 if (strlen(trim($_POST[$idx])) == 0)
00100                 {
00101                     $fc->delete();
00102                 }
00103                 else
00104                 {
00105                     $fc->set_parameter('order', $_POST['fc_order' . $var[0]]);
00106                     $fc->set_parameter('desc', $_POST['fr_cat' . $var[0]]);
00107                     $fc->set_parameter('forecast', $_POST['f_id']);
00108                     $fc->save();
00109                 }
00110             }
00111         }
00112 
00113         $cn->commit();
00114     }
00115     catch (Exception $e)
00116     {
00117         alert($e->getMessage());
00118         $cn->rollback();
00119     }
00120     $sa = 'vw';
00121 }
00122 /* * ********************************************************************
00123  * Save first the data for new
00124  *
00125  *
00126  * ******************************************************************** */
00127 if ($sa == 'new' || isset($_POST['step3']))
00128 {
00129     $correct = 0;
00130     if (isset($_POST['step3']))
00131     {
00132         /* save all the items */
00133         try
00134         {
00135             $cn->start();
00136             for ($i = 0; $i < $_POST['nbrow']; $i++)
00137             {
00138 
00139                 // Delete if needed
00140                 if (isset($_POST['fi_id' . $i]))
00141                 {
00142                     if (strlen(trim($_POST['an_cat_acc' . $i])) == 0 && strlen(trim($_POST['an_qc' . $i])) == 0)
00143                     {
00144                         $e = new Forecast_item($cn);
00145                         $e->set_parameter("id", $_POST['fi_id' . $i]);
00146                         $e->delete();
00147                     }
00148                 }
00149 
00150                 if (strlen(trim($_POST['an_cat_acc' . $i])) != 0 || strlen(trim($_POST['an_qc' . $i])) != 0)
00151                 {
00152                     /* we save only if there is something */
00153                     $e = new Forecast_item($cn);
00154                     if (isset($_POST['fi_id' . $i]))
00155                     {
00156                         $e->set_parameter("id", $_POST['fi_id' . $i]);
00157                     }
00158                     $e->set_parameter('text', $_POST['an_label' . $i]);
00159                     $e->set_parameter('amount', $_POST['an_cat_amount' . $i]);
00160                     $e->set_parameter('debit', $_POST['an_deb' . $i]);
00161                     $e->set_parameter('cat_id', $_POST['an_cat' . $i]);
00162                     $e->set_parameter('account', $_POST['an_cat_acc' . $i]);
00163                     $e->set_parameter('periode', $_POST['month' . $i]);
00164                     $f = new Fiche($cn);
00165                     if ($f->get_by_qcode($_POST['an_qc' . $i], false) == 0)
00166                         $e->set_parameter('card', $f->id);
00167                     else
00168                         $e->set_parameter('card', null);
00169                     $e->set_parameter('order', $i);
00170                     $e->save();
00171                 }
00172             }
00173             $cn->commit();
00174             $sa = 'vw'; // to avoid to restart the add of new anticipation
00175         }
00176         catch (Exception $e)
00177         {
00178             $cn->rollback();
00179             alert($e->getMessage());
00180             $correct = 1;
00181         }
00182     }
00183     /* Second step : we save the name and category
00184      * and propose the items we add the item */
00185     if ($correct == 2 || isset($_POST['step2']))
00186     {
00187         try
00188         {
00189             $cn->start();
00190             /* Save forecast */
00191             $a = new Forecast($cn);
00192             $a->set_parameter('name', $_POST['an_name']);
00193             $a->set_parameter('start_date', $_POST['start_date']);
00194             $a->set_parameter('end_date', $_POST['end_date']);
00195 
00196 
00197             $a->save();
00198             $id = $a->get_parameter("id");
00199             /* save cat */
00200             for ($i = 0; $i < MAX_CAT; $i++)
00201             {
00202                 if (strlen(trim($_POST['fr_cat' . $i])) != 0)
00203                 {
00204                     $c = new Forecast_Cat($cn);
00205                     $c->set_parameter('order', $_POST['fr_order' . $i]);
00206                     $c->set_parameter('desc', $_POST['fr_cat' . $i]);
00207                     $c->set_parameter('forecast', $id);
00208                     $c->save();
00209                 }
00210             }
00211             $cn->commit();
00212         }
00213         catch (Exception $e)
00214         {
00215             alert($e->getMessage());
00216             $correct = 1;
00217             unset($_POST['step2']);
00218             $cn->rollback();
00219         }
00220     }
00221 }
00222 /* * ********************************************************************
00223  * Display menu
00224  *
00225  *
00226  * ******************************************************************** */
00227 // display button add and list of forecast to display
00228 $aForecast = Forecast::load_all($cn);
00229 $menu = array();
00230 $get_dossier = dossier::get();
00231 
00232 
00233 for ($i = 0; $i < count($aForecast); $i++)
00234 {
00235     $href = "?ac=" . $_REQUEST['ac'] . "&sa=vw&" . $get_dossier . '&f_id=' . $aForecast[$i]['f_id'];
00236     $name = h($aForecast[$i]['f_name']);
00237     $menu[] = array($href, $name, $name, $aForecast[$i]['f_id']);
00238 }
00239 
00240 $href = "?ac=" . $_REQUEST['ac'] . "&sa=new&" . $get_dossier;
00241 $menu[] = array($href, _("Ajout prévision"), _("Ajout d'une prévision"), 0);
00242 $def = (isset($_REQUEST['f_id'])) ? $_REQUEST['f_id'] : -1;
00243 echo '<div class="topmenu2">';
00244 echo ShowItem($menu, 'H', 'mtitle', 'mtitle', $def,' class="mtitle" ');
00245 echo '</div>';
00246 /* * ********************************************************************
00247  * Ask for a new anticipation (forecast)
00248  *
00249  *
00250  * ******************************************************************** */
00251 if ($sa == 'new')
00252 {
00253     /* Second step : we save the name and category
00254      * and propose the items we add the item */
00255     if ($correct == 2 || isset($_POST['step2']))
00256     {
00257         /* Propose a form for the items
00258          */
00259         $anticip = new Anticipation($cn, $a->get_parameter("id"));
00260         echo '<div class="content">';
00261         echo ICard::ipopup('ipopcard');
00262         echo IPoste::ipopup('ipop_account');
00263         $search_card = new IPopup('ipop_card');
00264         $search_card->title = _('Recherche de fiche');
00265         $search_card->value = '';
00266         echo $search_card->input();
00267 
00268         echo '<form method="post" action="?">';
00269         echo dossier::hidden();
00270         echo HtmlInput::hidden('sa', 'new');
00271         echo HtmlInput::hidden('ac', $_REQUEST['ac']);
00272         echo HtmlInput::hidden('f_id', $id);
00273         echo $anticip->form_item();
00274         echo HtmlInput::submit('step3', _('Sauver'));
00275         echo '</form>';
00276         echo '</div>';
00277     }
00278     /* First step, the name and the category */
00279     if (!isset($_POST['step2']) || $correct == 1)
00280     {
00281         $anc = new Anticipation($cn);
00282         echo '<div class="content">';
00283         /* display a blank form for name and category */
00284         echo '<form method="post" action="?">';
00285         echo dossier::hidden();
00286         echo HtmlInput::hidden('sa', 'new');
00287         echo HtmlInput::hidden('ac', $_REQUEST['ac']);
00288         echo $anc->form_cat();
00289         echo HtmlInput::submit('step2', _('Sauver'));
00290         echo '</form>';
00291         echo '</div>';
00292     }
00293 }
00294 /* * ********************************************************************
00295  * If we request to modify the category or the name
00296  *
00297  *
00298  * ******************************************************************** */
00299 if (isset($_GET['mod_cat']))
00300 {
00301     $anc = new Anticipation($cn, $_GET['f_id']);
00302     echo '<div class="content">';
00303     /* display a blank form for name and category */
00304     echo '<form method="post" action="?">';
00305     echo dossier::hidden();
00306     echo HtmlInput::hidden('sa', 'mod');
00307     echo HtmlInput::hidden('ac', $_REQUEST['ac']);
00308     echo $anc->form_cat();
00309     echo HtmlInput::submit('mod_cat_save', _('Sauver'));
00310 
00311     echo '</form>';
00312     echo '</div>';
00313 }
00314 /* * ********************************************************************
00315  * If we request to modify the items
00316  *
00317  *
00318  * ******************************************************************** */
00319 if (isset($_GET['mod_item']))
00320 {
00321 
00322     /* Propose a form for the items
00323      */
00324     $anticip = new Anticipation($cn, $_GET['f_id']);
00325     echo '<div class="content">';
00326     echo ICard::ipopup('ipopcard');
00327     echo IPoste::ipopup('ipop_account');
00328     $search_card = new IPopup('ipop_card');
00329     $search_card->title = _('Recherche de fiche');
00330     $search_card->value = '';
00331     echo $search_card->input();
00332 
00333     echo '<form method="post" action="?">';
00334     echo dossier::hidden();
00335     echo HtmlInput::hidden('sa', 'new');
00336     echo HtmlInput::hidden('ac', $_REQUEST['ac']);
00337     echo HtmlInput::hidden('f_id', $_GET['f_id']);
00338     echo $anticip->form_item();
00339     echo HtmlInput::submit('step3', _('Sauver'));
00340     echo '</form>';
00341     echo '</div>';
00342 }
00343 /* * ********************************************************************
00344  * if a forecast is asked we display the result
00345  *
00346  *
00347  * ******************************************************************** */
00348 if (isset($_REQUEST['f_id']) && $sa == "vw")
00349 {
00350     echo '<div class="content">';
00351     $forecast = new Anticipation($cn);
00352     $forecast->set_parameter("id", $_REQUEST['f_id']);
00353     try
00354     {
00355         echo $forecast->display();
00356         echo '<div class="noprint">';
00357         echo '<form method="get">';
00358         echo dossier::hidden();
00359         echo HtmlInput::hidden('f_id', $_REQUEST['f_id']);
00360         echo HtmlInput::submit('mod_cat', _('Modifier nom ou catégories'));
00361         echo HtmlInput::submit('mod_item', _('Modifier éléments'));
00362         //echo HtmlInput::submit('cvs',_('Export CVS'));
00363         echo HtmlInput::submit('del', _('Effacer'), 'onclick="return confirm(\'' . _('Vous confirmez l\\\' effacement') . '\')"');
00364         echo HtmlInput::submit('clone', _('Cloner'), 'onclick="return confirm(\'' . _('Vous confirmez le clonage ') . '\')"');
00365         echo HtmlInput::hidden('ac', $_REQUEST['ac']);
00366         echo '</form>';
00367         echo '</div>';
00368         echo '</div>';
00369         exit();
00370     }
00371     catch (Exception $e)
00372     {
00373         echo "<div class=\"error\"><p>" . _("Erreur")." : " . $e->getMessage() . '</p><p>' . _('Vous devez corriger') . '</p></div>';
00374         $anc = new Anticipation($cn, $_GET['f_id']);
00375         echo '<div class="content">';
00376         /* display a blank form for name and category */
00377         echo '<form method="post" action="?">';
00378         echo dossier::hidden();
00379         echo HtmlInput::hidden('sa', 'mod');
00380         echo HtmlInput::hidden('ac', $_REQUEST['ac']);
00381         echo $anc->form_cat();
00382         echo HtmlInput::submit('mod_cat_save', _('Sauver'));
00383         echo '</form>';
00384         echo '</div>';
00385     }
00386 }
00387 ?>
00388 </div>
 All Data Structures Namespaces Files Functions Variables Enumerations