diff --git a/doc/manuel-fr.odt b/doc/manuel-fr.odt index 31137535a..8b8a06676 100644 Binary files a/doc/manuel-fr.odt and b/doc/manuel-fr.odt differ diff --git a/html/js/card.js b/html/js/card.js index 591a6bdd0..7a78dd25d 100644 --- a/html/js/card.js +++ b/html/js/card.js @@ -745,8 +745,16 @@ function save_card(obj) parameters:queryString, onFailure:errorFid, onSuccess:function (req,json) { - fill_box(req,json); + var elt=req.responseXML.getElementsByTagName("eltid"); + var status=req.responseXML.getElementsByTagName("status"); + var status_value='OK'; + if ( status.length !=0) { + status_value=getNodeText(status[0]); + } + if ( status_value == 'OK') { + fill_box(req,json); + } remove_waiting_box(); if ( elt.length != 0) { var eltid=getNodeText(elt[0]); @@ -756,8 +764,16 @@ function save_card(obj) fill_data_onchange(eltid); $(eltid).focus(); } - //$(content).fade({duration:2.0}); - Effect.SlideUp(content, { duration: 1.0 });} + } + if (status_value == "OK") { + Effect.SlideUp(content, { duration: 1.0 }); + } + if ( status_value == 'NOK') { + var xml_message=req.responseXML.getElementsByTagName("code"); + var message=getNodeText(xml_message[0]); + smoke.alert(message); + } + } } diff --git a/include/ajax/ajax_account_update.php b/include/ajax/ajax_account_update.php deleted file mode 100644 index c18529d2f..000000000 --- a/include/ajax/ajax_account_update.php +++ /dev/null @@ -1,215 +0,0 @@ - - -if (!defined('ALLOWED')) die('Appel direct ne sont pas permis'); - -/** - * @file - * @brief delete insert or update data from account_update (need right CFGPCMN) - * called from ajax_misc.php - * @param array - * @code - * 'op' => string 'account_update' (length=14) - 'gDossier' => string '44' (length=2) - 'action' => string 'update' (length=6) - 'p_oldu' => string '4124' (length=4) - 'p_valu' => string '4124' (length=4) - 'p_libu' => string 'Impôt belge sur le résultat' (length=29) - 'p_parentu' => string '412' (length=3) - 'acc_delete' => string '0' (length=1) - 'p_typeu' => string '0' (length=1) - * @endcode - */ -if ($g_user->check_module('CFGPCMN') == 0) - exit(); - -$var=array('action', 'p_oldu', 'p_valu', 'p_libu', 'p_parentu', 'acc_delete', 'p_typeu'); -for ($i=0; $iset_parameter('libelle', $p_lib); - $acc->set_parameter('value', $p_val); - $acc->set_parameter('parent', $p_parent); - $acc->set_parameter('type', $p_type); - $acc->check(); - } - catch (Exception $e) - { - $message=_("Valeurs invalides, pas de changement")." \n ". - $e->getMessage(); - $ctl='nok'; - record_log($e->getTraceAsString()); - } - if (strlen($p_val)!=0&&strlen($p_lib)!=0&&strlen($old_line)!=0) - { - if (strlen($p_val)==1) - { - $p_parent=0; - } - else - { - if (strlen($p_parent)==0) - { - $p_parent=substr($p_val, 0, strlen($p_val)-1); - } - } - /* Parent existe */ - $Ret=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val=$1", array($p_parent)); - if (($p_parent!=0&&Database::num_row($Ret)==0)||$p_parent==$old_line) - { - $message=_("Ne peut pas modifier; aucun poste parent"); - $ctl='nok'; - } - else - { - try - { - $acc->update($old_line); - } - catch (Exception $e) - { - $message=$e->getMessage(); - $ctl='nok'; - record_log($e->getTraceAsString()); - } - } - } - else - { - $message=_('Update Valeurs invalides'); - $ctl='nok'; - } -} -//----------------------------------------------------- -/* Ajout d'une ligne */ -if ($action=="new") -{ - $p_val=trim($p_valu); - $p_parent=trim($p_parentu); - - if (isset($p_valu)&&isset($p_libu)) - { - $p_val=trim($p_valu); - - if (strlen($p_valu)!=0&&strlen($p_libu)!=0) - { - if (strlen($p_valu)==1) - { - $p_parentu=0; - } - else - { - if (strlen(trim($p_parentu))==0&& - (string) $p_parentu!=(string) (int) $p_parentu) - { - $p_parentu=substr($p_val, 0, strlen($p_valu)-1); - } - } - /* Parent existe */ - $Ret=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val=$1", array($p_parentu)); - if ($p_parent!=0&&Database::num_row($Ret)==0) - { - $message=_(" Ne peut pas modifier; aucun poste parent"); - $ctl='nok'; - } - else - { - // Check if the account already exists - - $Count=$cn->get_value("select count(*) from tmp_pcmn where pcm_val=$1", array($p_val)); - if ($Count!=0) - { - // Alert message account already exists - $message=_("Ce poste existe déjà "); - $ctl='nok'; - } - else - { - $Ret=$cn->exec_sql("insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values ($1,$2,$3,$4)", array($p_val, $p_libu, $p_parent, $p_typeu)); - } - } - } - else - { - $message=_("Valeurs invalides "); - $ctl='nok'; - } - } -} - -//----------------------------------------------------- -// Action == remove a line -if ($action=="update"&&$acc_delete==1) -{ - /* Ligne a enfant */ - $R=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val_parent=$1", array($p_valu)); - if (Database::num_row($R)!=0) - { - $message=_("Ne peut pas effacer le poste: d'autres postes en dépendent"); - $ctl='nok'; - } - else - { - /* Vérifier que le poste n'est pas utilisé qq part dans les journaux */ - $Res=$cn->exec_sql("select * from jrnx where j_poste=$1", array($p_valu)); - if (Database::num_row($Res)!=0) - { - $message=_("Ne peut pas effacer le poste: il est utilisé dans les journaux"); - $ctl='nok'; - } - else - { - $Del=$cn->exec_sql("delete from tmp_pcmn where pcm_val=$1", array($p_valu)); - } // if Database::num_row - } // if Database::num_row -} //$action == del -$message=escape_xml($message); - if ( ! headers_sent()) { header('Content-type: text/xml; charset=UTF-8');} else { echo "HTML".unescape_xml($html);} - - echo << - -$ctl -$message - -EOF; -?> diff --git a/include/ajax/ajax_card.php b/include/ajax/ajax_card.php index 1ea6cbd85..995fe751b 100644 --- a/include/ajax/ajax_card.php +++ b/include/ajax/ajax_card.php @@ -335,25 +335,36 @@ case 'sc': if ( $g_user->check_action(FICADD)==1 ) { $f=new Fiche($cn); - $f->insert($fd_id,$_POST); - $f->Get(); - $html.='

'._('Fiche sauvée').'

'; - $html.=$f->Display(true); - $js=""; - if ( isset( $_POST['ref'])) $js=create_script(' window.location.reload()'); - $html.=$js; - if ( isset ($eltid)) { - // after adding a new card, we update some field - $extra="$eltid". - "{$f->get_quick_code ()}"; - + $status="OK"; + try { + $f->insert($fd_id,$_POST); + $f->Get(); + $html.='

'._('Fiche sauvée').'

'; + $html.=$f->Display(true); + $js=""; + if ( isset( $_POST['ref'])) $js=create_script(' window.location.reload()'); + $html.=$js; + if ( isset ($eltid)) { + // after adding a new card, we update some field + $extra="$eltid". + "{$f->get_quick_code ()}"; + + } + $extra.=$status; + $html.=HtmlInput::button_close($ctl); + } catch (Exception $exc) { + $html="

"._("Erreur sauvegarde")."

"; + $html.=$exc->getMessage(); + $status="NOK"; + $extra=$status; } + } else { $html.=alert(_('Action interdite'),true); + $html.=HtmlInput::button_close($ctl); } - $html.=HtmlInput::button_close($ctl); break; /*---------------------------------------------------------------------- * Search a card diff --git a/include/ajax/ajax_pcmn_update.php b/include/ajax/ajax_pcmn_update.php deleted file mode 100644 index fb527364c..000000000 --- a/include/ajax/ajax_pcmn_update.php +++ /dev/null @@ -1,111 +0,0 @@ -check_module('CFGPCMN')==0) -{ - $html=h2(_('Action interdite'), ' class="notice"'); - $html=escape_xml($html); - - header('Content-type: text/xml; charset=UTF-8'); - echo << - -pcmn_update -$html -NOTALLOWED - -EOF; - return; -} -$http=new HttpInput(); -ob_start(); -try -{ - - - $pcmn_val=$http->get('value', "string"); - - $action='new'; - $val=new IText('p_valu'); - $parent=new IText('p_parentu'); - $lib=new IText('p_libu'); - $lib->size="60"; - $type=new ISelect('p_typeu'); - $type->value=Acc_Account::$type; - - if ($pcmn_val!="") - { - $action='update'; - /* - * Not empty, show the default value - */ - $account=new Acc_Account($cn); - $account->set_parameter('value', $pcmn_val); - $account->load(); - - $val->value=$account->get_parameter('value'); - $parent->value=$account->get_parameter('parent'); - $lib->value=$account->get_parameter('libelle'); - $type->selected=$account->get_parameter('type'); - } - - require NOALYSS_TEMPLATE.'/pcmn_update.php'; - $response=ob_get_clean(); - $html=escape_xml($response); - if (headers_sent()) - { - echo $response; - echo $html; - } - else - { - header('Content-type: text/xml; charset=UTF-8'); - echo << - - -$html -ok - -EOF; - } -} -catch (Exception $exc) -{ - $html=$exc->getMessage(); - $html=escape_xml($html); - header('Content-type: text/xml; charset=UTF-8'); - echo << - - -$html -NOTALLOWED - -EOF; -} diff --git a/include/class/acc_ledger.class.php b/include/class/acc_ledger.class.php index 3289eb823..a2fda9344 100644 --- a/include/class/acc_ledger.class.php +++ b/include/class/acc_ledger.class.php @@ -2018,6 +2018,10 @@ class Acc_Ledger extends jrn_def_sql } $msg[]=$str_msg; } + $account=new Acc_Account($this->db,${"poste".$i}); + if ( $account->get_parameter("pcm_direct_use") == "N") { + throw new Exception(_("Utilisation directe interdite du poste comptable ${"poste".$i}")); + } } } $tot_deb=round($tot_deb, 4); diff --git a/include/class/fiche.class.php b/include/class/fiche.class.php index fb464f054..21fead6a0 100644 --- a/include/class/fiche.class.php +++ b/include/class/fiche.class.php @@ -28,6 +28,7 @@ require_once NOALYSS_INCLUDE.'/lib/ihidden.class.php'; require_once NOALYSS_INCLUDE.'/class/fiche_def.class.php'; require_once NOALYSS_INCLUDE.'/lib/iposte.class.php'; require_once NOALYSS_INCLUDE.'/class/acc_operation.class.php'; +require_once NOALYSS_INCLUDE.'/class/acc_account.class.php'; /*! \file * \brief define Class fiche, this class are using @@ -770,6 +771,7 @@ class Fiche try { + $this->cn->start(); $sql=sprintf("insert into fiche(f_id,fd_id)". " values (%d,%d)", $fiche_id, $p_fiche_def); $Ret=$this->cn->exec_sql($sql); @@ -805,19 +807,26 @@ class Fiche $v=mb_substr(sql_string($value), 0, 40); try { - + // Check that the accounting can be used directly if (strlen(trim($v))!=0) { if (strpos($value, ',')==0) { $v=$this->cn->get_value("select format_account($1)", array($value)); + + // Check that the accounting can be used directly + $acc_account=new Acc_Account($this->cn,$v); + if ($acc_account->get_parameter('pcm_direct_use') == 'N') { + throw new Exception(_("Utilisation directe interdite du poste comptable $v")); + } } else { $ac_array=explode(",", $value); if (count($ac_array)<>2) - throw new Exception('Désolé, il y a trop de virgule dans le poste comptable '.h($value)); + throw new Exception(_('Désolé, il y a trop de virgule dans le poste comptable ').h($value)); + $part1=$ac_array[0]; $part2=$ac_array[1]; $part1=$this->cn->get_value('select format_account($1)', @@ -825,6 +834,16 @@ class Fiche $part2=$this->cn->get_value('select format_account($1)', array($part2)); $v=$part1.','.$part2; + // Check that the accounting can be used directly + $acc_account1=new Acc_Account($this->cn,$part1); + if ($acc_account1->get_parameter('pcm_direct_use') == 'N') { + throw new Exception(_("Utilisation directe interdite du poste comptable $part1")); + } + // Check that the accounting can be used directly + $acc_account2=new Acc_Account($this->cn,$part2); + if ($acc_account2->get_parameter('pcm_direct_use') == 'N') { + throw new Exception(_("Utilisation directe interdite du poste comptable $part2")); + } } $parameter=array($this->id, $v); } @@ -837,8 +856,7 @@ class Fiche } catch (Exception $e) { - throw new Exception("Erreur : ce compte [$v] n'a pas de compte parent.". - "L'opération est annulée", 1); + throw ($e); } continue; } @@ -863,6 +881,7 @@ class Fiche $id, strip_tags(trim($value2))); $this->cn->exec_sql($sql); } + $this->cn->commit(); } catch (Exception $e) { @@ -949,11 +968,26 @@ class Fiche $part2=$this->cn->get_value('select format_account($1)', array($part2)); $v=$part1.','.$part2; + // Check that the accounting can be used directly + $acc_account1=new Acc_Account($this->cn,$part1); + if ($acc_account1->get_parameter('pcm_direct_use') == 'N') { + throw new Exception(_("Utilisation directe interdite du poste comptable $part1")); + } + // Check that the accounting can be used directly + $acc_account2=new Acc_Account($this->cn,$part2); + if ($acc_account2->get_parameter('pcm_direct_use') == 'N') { + throw new Exception(_("Utilisation directe interdite du poste comptable $part2")); + } } else { $v=$this->cn->get_value('select format_account($1)', array($value)); + // Check that the accounting can be used directly + $acc_account=new Acc_Account($this->cn,$v); + if ($acc_account->get_parameter('pcm_direct_use') == 'N') { + throw new Exception(_("Utilisation directe interdite du poste comptable $v")); + } } $sql=sprintf("select account_update(%d,'%s')", $this->id, $v); @@ -963,8 +997,7 @@ class Fiche } catch (Exception $e) { - throw new Exception(__LINE__."Erreur : ce compte [$v] n'a pas de compte parent.". - "L'opération est annulée"); + throw new Exception(_("opération annulée")." ".$e->getMessage()); } continue; } diff --git a/unit-test/include/class/acc_accountTest.class.php b/unit-test/include/class/acc_accountTest.class.php deleted file mode 100644 index 519f833ce..000000000 --- a/unit-test/include/class/acc_accountTest.class.php +++ /dev/null @@ -1,144 +0,0 @@ -object=new Acc_Account($g_connection,400); - $this->object->load(); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - - } - - /** - * @covers Acc_Account::get_parameter - * @todo Implement testGet_parameter(). - * @backupGlobals enabled - */ - public function testGet_parameter() - { - $value=$this->object->get_parameter("value"); - $this->assertEquals($value,'400'); - - } - - /** - * @covers Acc_Account::set_parameter - * @todo Implement testSet_parameter(). - * @backupGlobals enabled - */ - public function testSet_parameter() - { - $this->object->set_parameter("value",500); - $value=$this->object->get_parameter("value"); - $this->assertEquals($value,500); - } - - /** - * @covers Acc_Account::get_lib - * @todo Implement testGet_lib(). - */ - public function testGet_lib() - { - $value=$this->object->get_lib(); - $this->assertEquals($value,'Clients'); - } - - /** - * @covers Acc_Account::check - * @todo Implement testCheck(). - */ - public function testCheck() - { - $value=$this->object->check('pcm_val'); - $this->assertTrue($value); - $value=$this->object->check('pcm_lib'); - $this->assertTrue($value); - $value=$this->object->check('pcm_val_parent'); - $this->assertTrue($value); - $value=$this->object->check('pcm_type','CHA'); - $this->assertTrue($value); - $this->setExpectedException("Exception"); - $value=$this->object->check('unknown'); - - } - - /** - * @covers Acc_Account::load - * @todo Implement testLoad(). - */ - public function testLoad() - { - $this->object->load(); - } - - /** - * @covers Acc_Account::form - * @todo Implement testForm(). - */ - public function testForm() - { - $_REQUEST['gDossier']=36; - $this->object->form(); - } - - /** - * @covers Acc_Account::count - * @todo Implement testCount(). - */ - public function testCount() - { - - $this->assertEquals($this->object->count('550'),1); - $this->assertEquals($this->object->count('500'),0); - } - - /** - * @covers Acc_Account::test_me - * @todo Implement testTest_me(). - */ - public function testTest_me() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Acc_Account::update - * @todo Implement testUpdate(). - */ - public function testUpdate() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - -}