phpcompta-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpcompta-dev] r392 - in tag/rel650/tools: . include include/template


From: phpcompta-dev
Subject: [Phpcompta-dev] r392 - in tag/rel650/tools: . include include/template
Date: Sun, 29 Jul 2012 15:09:32 +0200 (CEST)

Author: danydb
Date: 2012-07-29 15:09:32 +0200 (Sun, 29 Jul 2012)
New Revision: 392

Added:
   tag/rel650/tools/include/class_tool_exercice.php
   tag/rel650/tools/include/template/tool_exercice_input.php
   tag/rel650/tools/include/tools_exercice.inc.php
Modified:
   tag/rel650/tools/index.php
Log:
New Tool for adding exercice

Added: tag/rel650/tools/include/class_tool_exercice.php
===================================================================
--- tag/rel650/tools/include/class_tool_exercice.php                            
(rev 0)
+++ tag/rel650/tools/include/class_tool_exercice.php    2012-07-29 13:09:32 UTC 
(rev 392)
@@ -0,0 +1,130 @@
+<?php
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ * Description of class_tool_exercice
+ *
+ * @author dany
+ */
+class Tool_Exercice
+{
+
+       function __construct($cn)
+       {
+               $this->cn = $cn;
+       }
+
+       /**
+        * Show form to input data for new exercice
+        */
+       function input()
+       {
+               $exercice = new INum('p_exercice');
+               $exercice->prec = 0;
+               $exercice->value = HtmlInput::default_value_post('p_exercice', 
'');
+
+               $year = new INum('year');
+               $year->prec = 0;
+               $year->value = HtmlInput::default_value_post('year', '');
+
+               $nb_month = new INum('nb_month');
+               $nb_month->prec = 0;
+               $nb_month->value = HtmlInput::default_value_post('nb_month', 
'');
+
+               $from = new ISelect('from_month');
+               $from->selected= HtmlInput::default_value_post('from_month', 
'');
+               $amonth = array();
+               for ($i = 1; $i < 13; $i++)
+               {
+                       $amonth[] = array("value" => $i, "label" => $i);
+               }
+               $from->value = $amonth;
+
+               require_once 'template/tool_exercice_input.php';
+       }
+
+       function fromPost()
+       {
+               $this->exercice = $_POST['p_exercice'];
+               $this->nb_month = $_POST['nb_month'];
+               $this->from = $_POST['from_month'];
+               $this->year= $_POST['year'];
+       }
+
+       function verify()
+       {
+               if (isNumber($this->exercice) == 0)
+                       throw new Exception("Exercice n'est pas un nombre");
+
+               if ($this->exercice > COMPTA_MAX_YEAR|| $this->exercice < 
COMPTA_MIN_YEAR)
+                       throw new Exception("Exercice doit être entre 
".COMPTA_MAX_YEAR."& ".COMPTA_MIN_YEAR);
+               if (isNumber($this->year) == 0)
+                       throw new Exception("Année n'est pas un nombre");
+
+               if ($this->year > COMPTA_MAX_YEAR|| $this->year < 
COMPTA_MIN_YEAR)
+                       throw new Exception("Année doit être entre 
".COMPTA_MAX_YEAR."& ".COMPTA_MIN_YEAR);
+
+               if (isNumber($this->nb_month) == 0)
+                       throw new Exception("Nombre de mois n'est pas un 
nombre");
+               if ($this->nb_month < 1 || $this->nb_month > 60)
+                       throw new Exception("Nombre de mois doit être compris 
entre 1 & 60 ");
+               if (isNumber($this->from) == 0)
+                       throw new Exception("Mois de début n'existe pas ");
+               if ($this->from > 13 || $this->from < 1)
+                       throw new Exception("Mois de début n'existe pas ");
+       }
+
+       function save()
+       {
+               try
+               {
+                       $this->verify();
+               }
+               catch (Exception $e)
+               {
+                       alert($e->getMessage());
+                       return -1;
+               }
+               $this->cn->start();
+               try
+               {
+                       $periode = new Periode($this->cn);
+                       $exercice=$this->exercice;
+                       $year=$this->year;
+                       $month=$this->from;
+                       for ($i = 1; $i <= $this->nb_month; $i++)
+                       {
+
+
+                               $date_start = sprintf('01.%02d.%d', $month, 
$year);
+                               $date_end = $this->cn->get_value("select 
to_char(to_date('$date_start','DD.MM.YYYY')+interval '1 month'-interval '1 
day','DD.MM.YYYY')");
+                               if ($periode->insert($date_start, $date_end, 
$this->exercice) != 0)
+                               {
+                                       throw new Exception('Erreur insertion 
période');
+                               }
+                               if ($month>11 )
+                               {
+                                       $year++;
+                                       $month=1;
+                               }
+                               else
+                               {
+                                       $month++;
+                               }
+                       }
+               }
+               catch (Exception $e)
+               {
+                       var_dump($e->getTraceAsString());
+                       return -1;
+               }
+               return 0;
+       }
+
+}
+
+?>

Added: tag/rel650/tools/include/template/tool_exercice_input.php
===================================================================
--- tag/rel650/tools/include/template/tool_exercice_input.php                   
        (rev 0)
+++ tag/rel650/tools/include/template/tool_exercice_input.php   2012-07-29 
13:09:32 UTC (rev 392)
@@ -0,0 +1,69 @@
+<?php
+
+/*
+ *   This file is part of PhpCompta.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/* $Revision$ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief Input data for new Exercice
+ *
+ */
+?>
+<form method="POST">
+       <table>
+               <tr>
+                       <td>
+                               Exercice
+                       </td>
+                       <td>
+                               <?=$exercice->input()?>
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               Année
+                       </td>
+                       <td>
+                               <?=$year->input()?>
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               Nombre de mois
+                       </td>
+                       <td>
+                               <?=$nb_month->input()?>
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               A partir du mois de
+                       </td>
+                       <td>
+                               <?=$from->input()?>
+                       </td>
+               </tr>
+       </table>
+<?
+echo HtmlInput::submit('save','Valider');
+echo HtmlInput::request_to_hidden(array('sa','ac','plugin_code','gDossier'));
+?>
+</form>
\ No newline at end of file

Added: tag/rel650/tools/include/tools_exercice.inc.php
===================================================================
--- tag/rel650/tools/include/tools_exercice.inc.php                             
(rev 0)
+++ tag/rel650/tools/include/tools_exercice.inc.php     2012-07-29 13:09:32 UTC 
(rev 392)
@@ -0,0 +1,47 @@
+<?php
+
+/*
+ *   This file is part of PhpCompta.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/* $Revision$ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief add an exercice of 12 month starting when we want
+ *
+ */
+require_once 'class_tool_exercice.php';
+if (isset ($_POST['save']))
+{
+       try
+       {
+               $exercice=new Tool_Exercice($cn);
+               $exercice->fromPost();
+               $exercice->save();
+       }
+       catch (Exception $e)
+       {
+               var_dump($e->getTraceAsString());
+       }
+
+}
+
+$exercice=new Tool_Exercice($cn);
+echo $exercice->input();
+?>

Modified: tag/rel650/tools/index.php
===================================================================
--- tag/rel650/tools/index.php  2012-07-20 04:44:45 UTC (rev 391)
+++ tag/rel650/tools/index.php  2012-07-29 13:09:32 UTC (rev 392)
@@ -25,7 +25,7 @@
  */
 global $version_plugin;
 $version_plugin=SVNINFO;
-Extension::check_version(4400);
+Extension::check_version(5082);
 
 /*
  * load javascript
@@ -39,7 +39,8 @@
 
$url='?'.dossier::get()."&plugin_code=".$_REQUEST['plugin_code']."&ac=".$_REQUEST['ac'];
 $array=array (
          array($url.'&sa=op',_('Opération'),_('Changer poste comptable ou 
fiche'),1),
-         array($url.'&sa=pj',_('Pièce'),_('Rénuméroter des pièces 
justificative'),2)
+         array($url.'&sa=pj',_('Pièce'),_('Rénuméroter des pièces 
justificative'),2),
+         array($url.'&sa=exe',_('Exercice'),_('Ajouter des années 
comptables'),3)
        );
 
 $sa=(isset($_REQUEST['sa']))?$_REQUEST['sa']:"";
@@ -52,6 +53,9 @@
   case 'pj':
     $def=2;
     break;
+  case 'exe':
+         $def=3;
+         break;
   }
 
 $cn=new Database(dossier::id());
@@ -76,4 +80,10 @@
     require_once('include/receipt.inc.php');
     exit();
   }
+/* Exercice */
+  if ($def == 3 )
+  {
+         require_once 'include/tools_exercice.inc.php';
+         exit();
+  }
 ?>



---
PhpCompta est un logiciel de comptabilité libre en ligne (full web)
Projet opensource http://www.phpcompta.eu



reply via email to

[Prev in Thread] Current Thread [Next in Thread]