diff --git a/html/ajax_misc.php b/html/ajax_misc.php index 8674b2265..4b83100ae 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -283,7 +283,13 @@ $path = array( // Operations tag remove 'operation_tag_remove'=>"ajax_operation_tag", // Operations tag select - 'operation_tag_select'=>"ajax_operation_tag" + 'operation_tag_select'=>"ajax_operation_tag", + // add or update forecast_item + "forecast_item"=>"ajax_forecast_item", + // add or update forecast_category + "forecast_category"=>"ajax_forecast_category", + // manage forecast + "forecast"=>"ajax_forecast" ) ; if (array_key_exists($op, $path)) { diff --git a/html/js/forecast.js b/html/js/forecast.js deleted file mode 100644 index 8195bd1aa..000000000 --- a/html/js/forecast.js +++ /dev/null @@ -1,25 +0,0 @@ - -/* - * This file is part of NOALYSS. - * - * NOALYSS 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. - * - * NOALYSS 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 NOALYSS; 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 danydb@aevalys.eu - -/*!\file - * \brief - */ diff --git a/html/js/managetable.js b/html/js/managetable.js index 215067125..ba54f184e 100644 --- a/html/js/managetable.js +++ b/html/js/managetable.js @@ -199,6 +199,7 @@ var ManageTable = function (p_table_name) answer['html'] = getNodeText(html[0]); return answer; } catch (e) { + console.error("managetable:parseXML") throw e; } }; diff --git a/include/ajax/ajax_forecast.php b/include/ajax/ajax_forecast.php new file mode 100644 index 000000000..fc6f20418 --- /dev/null +++ b/include/ajax/ajax_forecast.php @@ -0,0 +1,77 @@ +request("input"); +$action = $http->request("ieaction", "string", "display"); + +if ($action == "display") { + $ajax = Inplace_Edit::build($input); + $f_id = $http->request("f_id", "number"); + + $ajax->set_callback("ajax_misc.php"); + $ajax->add_json_param("op", "forecast"); + $ajax->add_json_param("gDossier", Dossier::id()); + $ajax->add_json_param("f_id", $f_id); + echo $ajax->ajax_input(); +} +if ($action == "ok") { + $f_id = $http->request("f_id", "number"); + $ajax = Inplace_Edit::build($input); + $ajax->set_callback("ajax_misc.php"); + $ajax->add_json_param("op", "forecast"); + $ajax->add_json_param("gDossier", Dossier::id()); + $ajax->add_json_param("f_id", $f_id); + + $value = $http->request("value"); + $ajax->set_value($value); + $input = $ajax->get_input(); + + $data_sql = new Forecast_SQL($cn, $f_id); + switch ($input->name) { + case 'f_name': + $data_sql->setp($input->name, $value); + break; + case 'p_start': + $data_sql->setp("f_start_date", $value); + break; + case 'p_end': + $data_sql->setp("f_end_date", $value); + break; + } + + $data_sql->update(); + echo $ajax->value(); +} +if ($action == "cancel") { + $ajax = Inplace_Edit::build($input); + $f_id = $http->request("f_id", "number"); + + $ajax->set_callback("ajax_misc.php"); + $ajax->add_json_param("op", "forecast"); + $ajax->add_json_param("gDossier", Dossier::id()); + $f_id = $http->request("f_id", "number"); + $ajax->add_json_param("f_id", $f_id); + + echo $ajax->value(); +} diff --git a/include/ajax/ajax_forecast_category.php b/include/ajax/ajax_forecast_category.php new file mode 100644 index 000000000..018344bde --- /dev/null +++ b/include/ajax/ajax_forecast_category.php @@ -0,0 +1,60 @@ +check_module("FORECAST")==0) die(); + +$http=new HttpInput(); +try { + $table=$http->request('table'); + $action=$http->request('action'); + $p_id=$http->request('p_id', "number"); + $ctl_id=$http->request('ctl'); + +} catch(Exception $e) { + echo $e->getMessage(); + return; +} +$forecast_category = Forecast_Category_MTable::build($p_id); +$forecast_category->set_object_name($ctl_id); +if ($action=="input") +{ + $forecast_category->send_header(); + $forecast_category->set_forecast_id($http->request("forecast_id")); + echo $forecast_category->ajax_input()->saveXML(); + return; +}elseif ($action == "save") { + $forecast_category->send_header(); + $forecast_category->set_forecast_id($http->request("forecast_id")); + echo $forecast_category->ajax_save()->saveXML(); + return; +} elseif ($action == "delete") { + $forecast_category->send_header(); + echo $forecast_category->ajax_delete()->saveXML(); + return; +} \ No newline at end of file diff --git a/include/ajax/ajax_forecast_item.php b/include/ajax/ajax_forecast_item.php new file mode 100644 index 000000000..5b92b7891 --- /dev/null +++ b/include/ajax/ajax_forecast_item.php @@ -0,0 +1,59 @@ +check_module("FORECAST")==0) die(); + +$http=new HttpInput(); +try { + $table=$http->request('table'); + $action=$http->request('action'); + $p_id=$http->request('p_id', "number"); + $ctl_id=$http->request('ctl'); + +} catch(Exception $e) { + echo $e->getMessage(); + return; +} +$forecast_item = Forecast_Item_MTable::build($p_id); +$forecast_item->set_object_name($ctl_id); +if ($action=="input") +{ + $forecast_item->send_header(); + $forecast_item->set_forecast_id($http->request("forecast_id")); + echo $forecast_item->ajax_input()->saveXML(); + return; +}elseif ($action == "save") { + $forecast_item->send_header(); + echo $forecast_item->ajax_save()->saveXML(); + return; +} elseif ($action == "delete") { + $forecast_item->send_header(); + echo $forecast_item->ajax_delete()->saveXML(); + return; +} \ No newline at end of file diff --git a/include/class/anticipation.class.php b/include/class/anticipation.class.php index 711fda986..67360c17b 100644 --- a/include/class/anticipation.class.php +++ b/include/class/anticipation.class.php @@ -25,426 +25,286 @@ * */ /** - *@brief Manage the anticipation of expense, sales,... - *@see Forecast Forecast_Cat Forecast_Item + * @brief Manage the anticipation of expense, sales,... + * @see Forecast Forecast_Cat Forecast_Item * */ -require_once NOALYSS_INCLUDE.'/class/forecast.class.php'; -require_once NOALYSS_INCLUDE.'/class/forecast_cat.class.php'; -require_once NOALYSS_INCLUDE.'/class/forecast_item.class.php'; -require_once NOALYSS_INCLUDE.'/class/fiche.class.php'; -require_once NOALYSS_INCLUDE.'/class/acc_account_ledger.class.php'; -require_once NOALYSS_INCLUDE.'/class/periode.class.php'; -require_once NOALYSS_INCLUDE.'/lib/impress.class.php'; +require_once NOALYSS_INCLUDE . '/class/forecast.class.php'; +require_once NOALYSS_INCLUDE . '/class/fiche.class.php'; +require_once NOALYSS_INCLUDE . '/class/acc_account_ledger.class.php'; +require_once NOALYSS_INCLUDE . '/class/periode.class.php'; +require_once NOALYSS_INCLUDE . '/lib/impress.class.php'; +require_once NOALYSS_INCLUDE . '/database/forecast_sql.class.php'; +require_once NOALYSS_INCLUDE . '/class/forecast_category_mtable.class.php'; class Anticipation { /* example private $variable=array("val1"=>1,"val2"=>"Seconde valeur","val3"=>0); */ - private static $variable=array ("id"=>"f_id","name"=>"f_name"); private $cn; - var $cat; /*!< array of object categorie (forecast_cat)*/ + var $cat; /*!< array of object categorie (forecast_category)*/ var $item; /*< array of object item (forecast_item) */ + private $forecast_id; //!< forecast.f_id + /** * @brief constructor * @param $p_init Database object */ - function __construct ($p_init,$p_id=0) + function __construct($p_init, $p_id = 0) { - $this->cn=$p_init; - $this->f_id=$p_id; - } - public function get_parameter($p_string) - { - if ( array_key_exists($p_string,self::$variable) ) - { - $idx=self::$variable[$p_string]; - return $this->$idx; - } - else - throw new Exception("Attribut inexistant $p_string"); - } - public function set_parameter($p_string,$p_value) - { - if ( array_key_exists($p_string,self::$variable) ) - { - $idx=self::$variable[$p_string]; - $this->$idx=$p_value; - } - else - throw new Exception("Attribut inexistant $p_string"); - - - } - public function get_info() - { - return var_export(self::$variable,true); - } - public function verify() - { - // Verify that the elt we want to add is correct - // the f_name must be unique (case insensitive) - return 0; - } - public function save() - { - /* please adapt */ - if ( $this->get_parameter("id") == 0 ) - $this->insert(); - else - $this->update(); + $this->cn = $p_init; + $this->forecast_id = $p_id; } - public function insert() - { - if ( $this->verify() != 0 ) return; - } - - public function update() -{} - - public function load() - {} /** - *@brief Display the result of the forecast - *@param $p_periode - *@return HTML String with the code + * @return mixed + */ + public function getCat() + { + return $this->cat; + } + + /** + * @param mixed $cat + */ + public function setCat($cat) + { + $this->cat = $cat; + } + + /** + * @return mixed + */ + public function getItem() + { + return $this->item; + } + + /** + * @param mixed $item + */ + public function setItem($item) + { + $this->item = $item; + } + + /** + * @return int|mixed + */ + public function getForecastId() + { + return $this->forecast_id; + } + + /** + * @param int|mixed $forecast_id + */ + public function setForecastId($forecast_id) + { + $this->forecast_id = $forecast_id; + } + + public function input_title() + { + require_once NOALYSS_TEMPLATE . "/anticipation-input_title.php"; + } + + public function input_category() + { + $visible=uniqid(); + echo '
" . _("Erreur")." : " . $e->getMessage() . '
' . _('Vous devez corriger') . '
"._("Erreur")." : ".$e->getMessage(). + '
'._('Vous devez corriger').'
| '._("Ajout d'une prévision").' | |||||
| '._("Ajout d'une prévision").' | '.h($name).' | '; diff --git a/include/lib/function_javascript.php b/include/lib/function_javascript.php index 0b8ce6c23..c6afeeb4a 100644 --- a/include/lib/function_javascript.php +++ b/include/lib/function_javascript.php @@ -2775,7 +2775,6 @@ function load_all_script() echo js_include('card.js'); echo js_include('compute_direct.js'); echo js_include('compute.js'); - echo js_include('forecast.js'); echo js_include('gestion.js'); echo js_include('todo_list.js'); echo js_include('anc_script.js'); diff --git a/include/lib/impress.class.php b/include/lib/impress.class.php index 8ea617f11..e03a1a4d8 100644 --- a/include/lib/impress.class.php +++ b/include/lib/impress.class.php @@ -57,7 +57,7 @@ class Impress else $cond="( j_date >= to_date('$p_start','DD.MM.YYYY') and j_date <= to_date('$p_end','DD.MM.YYYY'))"; - while (preg_match_all("(\[[0-9]*[A-Z]*%*c*d*s*\])",$p_formula,$e) == true) + while (preg_match_all("(\[[0-9]*[A-Z]*%*c*d*s*S*\])",$p_formula,$e) == true) { // remove the [ ] $x=$e[0]; @@ -70,11 +70,14 @@ class Impress $compute='cred'; if ( strpos($line,'s') != 0 ) $compute='signed'; + if ( strpos($line,'S') != 0 ) + $compute='cdsigned'; $line=str_replace ("[","",$line); $line=str_replace ("]","",$line); $line=str_replace ("d","",$line); $line=str_replace ("c","",$line); $line=str_replace ("s","",$line); + $line=str_replace ("S","",$line); // If there is a FROM clause we must recompute // the time cond @@ -145,7 +148,9 @@ class Impress if ( $compute=='cred') $i=$detail['credit']; if ( $compute=='signed') - $i=$detail['debit']-$detail['credit']; + $i=bcsub($detail['debit'],$detail['credit'],4); + if ( $compute=='cdsigned') + $i=bcsub($detail['credit'],$detail['debit'],4); $p_formula=str_replace($x[0],$i,$p_formula); } } @@ -215,28 +220,29 @@ class Impress $p_string=str_replace("c","",$p_string); $p_string=str_replace("d","",$p_string); $p_string=str_replace("s","",$p_string); + $p_string=str_replace("S","",$p_string); // Remove T,t $p_string=str_replace("t","",$p_string); - // remove date - $p_string= preg_replace("/FROM*=*[0-9]+/", "", $p_string); - // remove comment - $p_string= preg_replace("/#.*/", "", $p_string); - // remove $C= - $p_string= preg_replace('/\$[a-z]*[A-Z]*[0-9]*[A-Z]*[a-z]*/', "", $p_string); - $p_string= preg_replace('/=/', "", $p_string); + // remove date + $p_string= preg_replace("/FROM*=*[0-9]+/", "", $p_string); + // remove comment + $p_string= preg_replace("/#.*/", "", $p_string); + // remove $C= + $p_string= preg_replace('/\$[a-z]*[A-Z]*[0-9]*[A-Z]*[a-z]*/', "", $p_string); + $p_string= preg_replace('/=/', "", $p_string); - // remove account - $p_string= preg_replace("/\[[0-9]*[A-Z]*%*\]/", "", $p_string); + // remove account + $p_string= preg_replace("/\[[0-9]*[A-Z]*%*\]/", "", $p_string); - $p_string= preg_replace("/\+|-|\/|\*/", "", $p_string); - $p_string= preg_replace("/[0-9]*\.*[0-9]/", "", $p_string); + $p_string= preg_replace("/\+|-|\/|\*/", "", $p_string); + $p_string= preg_replace("/[0-9]*\.*[0-9]/", "", $p_string); - //******************************************************************************************************************** - // If the string is empty then formula should be good - // - //******************************************************************************************************************** - if ($p_string == '') + //******************************************************************************************************************** + // If the string is empty then formula should be good + // + //******************************************************************************************************************** + if ($p_string == '') { return true; } diff --git a/include/lib/manage_table_sql.class.php b/include/lib/manage_table_sql.class.php index 8962ca162..fc14cb026 100644 --- a/include/lib/manage_table_sql.class.php +++ b/include/lib/manage_table_sql.class.php @@ -354,7 +354,7 @@ function check() * select must supply an array of possible values [val=> , label=>] with * the variable $this->key_name->a_value * @param $p_key col name - * @param $p_type is SELECT NUMERIC TEXT , DATE or custom + * @param $p_type is "text", "numeric", "date", "select", "timestamp","custom" * @param $p_array if type is SELECT an array is expected * @note if $p_type is custom then a function named input_custom($p_key,$p_value) must be implemented * in the class @@ -918,9 +918,16 @@ function check() $td=($i == $this->col_sort ) ? sprintf('',$p_row[$v]):" | "; echo $td.HtmlInput::anchor($p_row[$v], "", $js).' | '; } - elseif ( $i == $this->col_sort && $this->get_property_visible($v)) + elseif ( $i == $this->col_sort && $this->get_property_visible($v) ) { - echo td($p_row[$v],sprintf(' sort_value="X%s" ',$p_row[$v])); + if ( $this->get_col_type($v) == 'text') { + echo td($p_row[$v],sprintf(' sort_value="X%s" ',$p_row[$v])); + } elseif ( $this->get_col_type($v) == 'numeric') { + echo td($p_row[$v],sprintf(' sort_value="%s" ',$p_row[$v])); + } else { + echo td($p_row[$v],sprintf(' sort_value="X%s" ',$p_row[$v])); + + } } elseif ( ! $this->get_property_visible($v)) { continue; diff --git a/include/template/forecast_result.php b/include/template/anticipation-display.php similarity index 62% rename from include/template/forecast_result.php rename to include/template/anticipation-display.php index f272f9327..393df5a86 100644 --- a/include/template/forecast_result.php +++ b/include/template/anticipation-display.php @@ -41,15 +41,48 @@ Période du à $amount=$aItem[$i][$e]['fi_amount']; if (count($aPerMonth[$i]) != 0 ){ for ($x=0;$x- + |
diff --git a/include/template/anticipation-input_title.php b/include/template/anticipation-input_title.php
new file mode 100644
index 000000000..2bb823d5e
--- /dev/null
+++ b/include/template/anticipation-input_title.php
@@ -0,0 +1,74 @@
+cn, $this->forecast_id);
+$fc_name = new IText("f_name", $forecast_sql->getp("f_name"));
+$fc_name->id="fc_name";
+$is_start = new ISelect("p_start");
+$is_start->value = $this->cn->make_array("select p_id,p_start from parm_periode order by p_start");
+$is_end = new ISelect("p_end");
+$is_end->value = $this->cn->make_array("select p_id,p_end from parm_periode order by p_end");
+
+$is_start->selected = $forecast_sql->getp("f_start_date");
+$is_end->selected = $forecast_sql->getp("f_end_date");
+$is_start->id=uniqid("sel");
+$is_end->id=uniqid("sel");
+
+
+$ip_name = new Inplace_Edit($fc_name);
+$ip_start = new Inplace_Edit($is_start);
+$ip_end = new Inplace_Edit($is_end);
+
+$ip_name->add_json_param("op", "forecast");
+$ip_start->add_json_param("op", "forecast");
+$ip_end->add_json_param("op", "forecast");
+
+$ip_name->add_json_param("gDossier", Dossier::id());
+$ip_start->add_json_param("gDossier", Dossier::id());
+$ip_end->add_json_param("gDossier", Dossier::id());
+
+$ip_name->add_json_param("f_id", $this->forecast_id);
+$ip_start->add_json_param("f_id", $this->forecast_id);
+$ip_end->add_json_param("f_id", $this->forecast_id);
+
+$ip_name->set_callback("ajax_misc.php");
+$ip_start->set_callback("ajax_misc.php");
+$ip_end->set_callback("ajax_misc.php");
+
+?>
++ input(); + ?> ++
+
+
+= $ip_start->input(); ?>
+
+= $ip_end->input() ?>
+
+
diff --git a/include/template/forecast-new.php b/include/template/forecast-new.php
new file mode 100644
index 000000000..2150d8949
--- /dev/null
+++ b/include/template/forecast-new.php
@@ -0,0 +1,90 @@
+
+
+if (!defined('ALLOWED'))
+ die('Appel direct ne sont pas permis');
+
+/**
+ * @file
+ * @brief form to enter a new Forecast
+ */
+$cn=Dossier::connect();
+global $g_user;
+$exercice=$g_user->get_exercice();
+$t_periode=new Periode($cn);
+list($per_max, $per_min)=$t_periode->get_limit($exercice);
+
+
+$fc_name=new IText("f_name");
+$fc_name->id="fc_name";
+$is_start=new ISelect("p_start");
+$is_start->value=$cn->make_array("select p_id,p_start from parm_periode order by p_start");
+$is_start->selected=$per_max->p_id;
+$is_end=new ISelect("p_end");
+$is_end->selected=$per_min->p_id;
+$is_end->value=$cn->make_array("select p_id,p_end from parm_periode order by p_end");
+?>
+
diff --git a/include/template/forecast_cat.php b/include/template/forecast_cat-delete.php
similarity index 100%
rename from include/template/forecast_cat.php
rename to include/template/forecast_cat-delete.php
diff --git a/include/template/forecast_item_mtable-display_table.php b/include/template/forecast_item_mtable-display_table.php
new file mode 100644
index 000000000..ab515bef6
--- /dev/null
+++ b/include/template/forecast_item_mtable-display_table.php
@@ -0,0 +1,71 @@
+object_name, '0,1,2,3,4', 1);
+?>
+
|