New #0002193: Possibilité d'ajouter directement une note aux opérations

Cosmetic : change icon for enlarging operation label
This commit is contained in:
sparkyx 2022-09-11 13:32:44 +02:00
parent faa8543de2
commit 6bc9077b49
9 changed files with 374 additions and 10 deletions

View file

@ -0,0 +1,60 @@
<?php
/*
* 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
*
* Copyright Author Dany De Bontridder danydb@noalyss.eu
*
*/
use PHPUnit\Framework\TestCase;
class Acc_Operation_NoteTest extends TestCase
{
public function testBuild_jrn_id()
{
$note=Acc_Operation_Note::build_jrn_id(165);
$this->assertEquals(7,$note->getJrnNoteSql()->getp("n_id"),' cannot retrieve a note');
$note=Acc_Operation_Note::build_jrn_id(686);
$this->assertEquals(14,$note->getJrnNoteSql()->getp("n_id"),' cannot retrieve a note');
$note=Acc_Operation_Note::build_jrn_id(1000);
$this->assertEquals(-1,$note->getJrnNoteSql()->getp("n_id"),' cannot retrieve a note');
}
public function testSave()
{
$cn=Dossier::connect();
$cn->exec_sql("delete from jrn_note where jr_id=251");
// Add a new note
$note=Acc_Operation_Note::build_jrn_id(251);
$this->assertEquals(-1,$note->getJrnNoteSql()->getp("n_id"),"note already exist");
$note->setNote("Test 1");
$note->setOperation_id(251);
$note->save();
$compare=Acc_Operation_Note::build_jrn_id(251);
$id=$note->getJrnNoteSql()->getp("n_id");
$this->assertGreaterThan(0,$compare->getJrnNoteSql()->getp("n_id"),"note not created");
$this->assertEquals($id,$compare->getJrnNoteSql()->getp("n_id"),"Note not loaded");
$note->setNote("Test 2");
$note->save();
$compare->load();
$this->assertEquals("Test 2",$compare->getJrnNoteSql()->getp("n_text"),"note not updated and loaded");
$this->assertEquals("Test 2",$compare->getNote(),"note not updated, match incorrect");
}
}

View file

@ -626,6 +626,7 @@ class Acc_Ledger extends jrn_def_sql
return _("Aucun résultat");
$anc=null;
extract($p_array, EXTR_SKIP);
if ( !isset($p_array['jrn_note_input'])) {$p_array['jrn_note_input']='';}
$lPeriode=new Periode($this->db);
if ($this->check_periode()==true)
{
@ -651,6 +652,9 @@ class Acc_Ledger extends jrn_def_sql
$date_limit=$lPeriode->get_date_limit();
$ret.='<tr> '.td(_('Période Comptable')).td($date_limit['p_start'].'-'.$date_limit['p_end']).'</tr>';
$ret.="<tr><td>"._('Libellé')." </td><td>".h($desc)."</td></tr>";
$ret.="<tr><td>";
$ret.=_('Note').'</td><td><pre>'. h($p_array['jrn_note_input']).'</pre>';
$ret.="</td></tr>";
$ret.="<tr><td>"._('PJ Num')." </td><td>".h($e_pj)."</td></tr>";
$ret.='</table>';
$ret.="<table class=\"result\">";
@ -679,6 +683,8 @@ class Acc_Ledger extends jrn_def_sql
$ret.=HtmlInput::hidden('period', $lPeriode->p_id);
$ret.=HtmlInput::hidden('e_pj', $e_pj);
$ret.=HtmlInput::hidden('e_pj_suggest', $e_pj_suggest);
$ret.=HtmlInput::hidden('jrn_note_input',h($p_array['jrn_note_input']));
$mt=microtime(true);
$ret.=HtmlInput::hidden('mt', $mt);
// For predefined operation
@ -943,6 +949,12 @@ class Acc_Ledger extends jrn_def_sql
$ret.=Icon_Action::longer("desc",20);
$ret.='</td>';
$ret.='</tr>';
$ret.='<tr>';
$ret.='<td>';
$ret.=_("Note").
Icon_Action::show_note('jrn_note_div');
$ret.='</td>';
$ret.='<td> <pre id="jrn_note_td"></pre></td>';
// Currency
$currency_select = $this->CurrencyInput("currency_code", "p_currency_rate" , "p_currency_euro");
$currency_select->selected=$http->request('p_currency_code','string',0);
@ -958,6 +970,13 @@ class Acc_Ledger extends jrn_def_sql
$ret.='</table>';
// note for operation
$note = (isset($p_array['jrn_note_input'])) ? $p_array['jrn_note_input'] : '';
ob_start();
Acc_Operation_Note::input($note);
$ret.=ob_get_contents();
ob_end_clean();
$ret.=HtmlInput::hidden('e_pj_suggest', $default_pj);
@ -1314,6 +1333,7 @@ class Acc_Ledger extends jrn_def_sql
bcscale(4);
$http=new HttpInput();
extract($p_array, EXTR_SKIP);
if ( !isset($p_array['jrn_note_input'])) {$p_array['jrn_note_input']='';}
try
{
$msg=$this->verify($p_array);
@ -1530,6 +1550,15 @@ class Acc_Ledger extends jrn_def_sql
{
$this->db->save_receipt($seq);
}
/*----------------------------------------------
* Save the note
----------------------------------------------*/
if (isset($p_array['jrn_note_input']) && !empty($p_array['jrn_note_input'])) {
$acc_operation_note=Acc_Operation_Note::build_jrn_id(-1);
$acc_operation_note->setNote($p_array['jrn_note_input']);
$acc_operation_note->setOperation_id( $jr_id);
$acc_operation_note->save();
}
}
catch (Exception $e)
{

View file

@ -508,7 +508,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
global $g_parameter;
extract ($p_array, EXTR_SKIP);
$this->verify($p_array) ;
if ( !isset($p_array['jrn_note_input'])) {$p_array['jrn_note_input']='';}
$group=$this->db->get_next_seq("s_oa_group"); /* for analytic */
$seq=$this->db->get_next_seq('s_grpt');
$this->id=$p_jrn;
@ -1078,8 +1078,15 @@ class Acc_Ledger_Purchase extends Acc_Ledger
}
/*----------------------------------------------
* Save the note
----------------------------------------------*/
if (isset($p_array['jrn_note_input']) && !empty($p_array['jrn_note_input'])) {
$acc_operation_note=Acc_Operation_Note::build_jrn_id(-1);
$acc_operation_note->setNote($p_array['jrn_note_input']);
$acc_operation_note->setOperation_id( $this->jr_id);
$acc_operation_note->save();
}
}//end try
catch (Exception $e)
{
@ -1519,7 +1526,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
{
global $g_parameter;
extract ($p_array,EXTR_SKIP);
if ( !isset($p_array['jrn_note_input'])) {$p_array['jrn_note_input']='';}
// we don't need to verify if we need only a feedback
if ( ! $p_summary ){$this->verify($p_array) ;}
@ -1600,6 +1607,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
$r.='<td> ' . _('Fournisseur') . '</td><td> ' . hb($e_client . ':' . $client_name) . '</td>';
$r.='</tr>';
$r.='</table>';
$r.='<pre>'._('Note').' '.h($p_array['jrn_note_input']).'</pre>';
$r.='</div>';
$r.='<div style="position:float;clear:both">';
$r.='</div>';
@ -1846,7 +1854,7 @@ EOF;
if ( $g_parameter->MY_ANALYTIC!='nu' && !$p_summary) // use of AA
$r.='<input type="button" class="button" value="'._('Vérifiez imputation analytique').'" onClick="verify_ca(\'\');">';
$r.=(! $p_summary )?'<div id="total_div_id" >':'<div>';
$r.='<div id="total_div_id" >';
$r.='<h2>Totaux</h2>';
$other_tax_label="";
$other_tax_amount="";
@ -1885,6 +1893,8 @@ EOF;
$r.=HtmlInput::hidden('e_client',$e_client);
$r.=HtmlInput::hidden('nb_item',$nb_item);
$r.=HtmlInput::hidden('p_jrn',$p_jrn);
$r.=HtmlInput::hidden('jrn_note_input',h($p_array['jrn_note_input']));
if ( isset($period))
$r.=HtmlInput::hidden('period',$period);
$r.=HtmlInput::hidden('e_comm',$e_comm);

View file

@ -768,6 +768,15 @@ class Acc_Ledger_Sale extends Acc_Ledger {
$ledger->insert_quant_fin($acfiche->id, $mp_jr_id, $cust->id, bcmul($famount, 1),$let_other);
}
}
/*----------------------------------------------
* Save the note
----------------------------------------------*/
if (isset($p_array['jrn_note_input']) && !empty($p_array['jrn_note_input'])) {
$acc_operation_note=Acc_Operation_Note::build_jrn_id(-1);
$acc_operation_note->setNote($p_array['jrn_note_input']);
$acc_operation_note->setOperation_id( $this->jr_id);
$acc_operation_note->save();
}
} catch (Exception $e) {
record_log($e);
echo '<span class="error">' .
@ -796,7 +805,7 @@ class Acc_Ledger_Sale extends Acc_Ledger {
function confirm($p_array, $p_summary = false) {
global $g_parameter;
extract($p_array, EXTR_SKIP);
if ( !isset($p_array['jrn_note_input'])) {$p_array['jrn_note_input']='';}
// don't need to verify for a summary
if (!$p_summary)
{
@ -874,6 +883,7 @@ class Acc_Ledger_Sale extends Acc_Ledger {
$r.='<td> ' . _('Client') . '</td><td> ' . hb($e_client . ':' . $client_name) . '</td>';
$r.='</tr>';
$r.='</table>';
$r.='<pre>'._('Note').' '.h($p_array['jrn_note_input']).'</pre>';
$r.='</div>';
$r.='<div style="float:none;clear:both">';
$r.='</div>';
@ -1101,7 +1111,7 @@ EOF;
$r.='</p>';
if ($g_parameter->MY_ANALYTIC != 'nu' && ! $p_summary) // use of AA
$r.='<input type="button" class="button" value="' . _('Vérifiez Imputation Analytique') . '" onClick="verify_ca(\'\');">';
$r.=(! $p_summary )?'<div id="total_div_id" >':'<div>';
$r.='<div id="total_div_id" >';
$r.='<h2>Totaux</h2>';
$other_tax_label="";
$other_tax_amount="";
@ -1142,6 +1152,7 @@ EOF;
$r.=HtmlInput::hidden('e_client', $e_client);
$r.=HtmlInput::hidden('nb_item', $nb_item);
$r.=HtmlInput::hidden('p_jrn', $p_jrn);
$r.=HtmlInput::hidden('jrn_note_input',h($p_array['jrn_note_input']));
$mt = microtime(true);
$r.=HtmlInput::hidden('mt', $mt);
$r.=HtmlInput::post_to_hidden(['p_currency_rate','p_currency_code']);
@ -1259,11 +1270,12 @@ EOF;
// load ledger definition
$this->load();
$http=new HttpInput();
$http->set_array([]);
if ($p_array != null) {
extract($p_array, EXTR_SKIP);
$http->set_array($p_array);
}
$http->set_array([]);
if ( !isset($p_array['jrn_note_input'])) {$p_array['jrn_note_input']='';}
$flag_tva = $g_parameter->MY_TVA_USE;
/* Add button */

View file

@ -0,0 +1,126 @@
<?php
/*
* 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
*/
// Copyright Author Dany De Bontridder danydb@noalyss.eu
/*!
* \file
* \brief Manage the note attached to an operation
*/
/*!
* \class
* \brief Manage the note attached to an operation
*/
class Acc_Operation_Note
{
private $note;
private $id;
private $operation_id; //!< jrn.jr_id
private $jrn_note_sql;
function __construct(Jrn_Note_SQL $p_Jrn_Note_SQL)
{
$this->jrn_note_sql = $p_Jrn_Note_SQL;
$this->id=$p_Jrn_Note_SQL->n_id;
$this->note=$p_Jrn_Note_SQL->n_text;
$this->operation_id=$p_Jrn_Note_SQL->jr_id;
}
/**
* @return Jrn_Note_SQL
*/
public function getJrnNoteSql(): Jrn_Note_SQL
{
return $this->jrn_note_sql;
}
/**
* @param Jrn_Note_SQL $jrn_note_sql
*/
public function setJrnNoteSql(Jrn_Note_SQL $jrn_note_sql): Acc_Operation_Note
{
$this->jrn_note_sql = $jrn_note_sql;
return $this;
}
/**
* @param $p_jr_id
* @return void
*/
static function build_jrn_id($p_jr_id) {
$cn=Dossier::connect();
$n_id=$cn->get_value("select n_id from jrn_note where jr_id=$1",[$p_jr_id]);
if ( $cn->count() == 0) {
$n_id=-1;
}
return new Acc_Operation_Note(new Jrn_Note_SQL($cn,$n_id));
}
function save()
{
$cn=Dossier::connect();
$this->jrn_note_sql->setp("jr_id",$this->operation_id);
$this->jrn_note_sql->setp("n_text",$this->note);
if ( empty($this->jrn_note_sql->n_text) && $this->id > -1 ) {
$this->jrn_note_sql->delete();
return $this;
}
$this->jrn_note_sql->save();
$this->id=$this->jrn_note_sql->n_id;
return $this;
}
function setNote($p_note) {
$this->note=$p_note;
return $this;
}
function setOperation_id($p_jrid) {
$this->operation_id=$p_jrid;
return $this;
}
function getNote() {
return $this->note;
}
function getOperation_id() {
return $this->operation_id;
}
function load()
{
$this->jrn_note_sql->load();
$this->operation_id=$this->jrn_note_sql->jr_id;
$this->note=$this->jrn_note_sql->n_text;
$this->id=$this->jrn_note_sql->n_id;
}
static function input($p_current)
{
require NOALYSS_TEMPLATE.'/acc_operation_note-input.php';
}
function fromPost()
{
}
function print()
{
echo '<pre id="print_note">'.h($this->note).'</pre>';
}
}

View file

@ -0,0 +1,66 @@
<?php
/**
* Autogenerated file
* 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
*/
/**
* jrn_tax_sql.class.php
*
* @file
* @brief abstract of the table public.jrn_tax */
/**
* @class Jrn_Tax_SQL
* @brief ORM of the table public.jrn_tax
*/
class Jrn_Note_SQL extends Table_Data_SQL
{
function __construct(DatabaseCore $p_cn, $p_id=-1)
{
$this->table="public.jrn_note";
$this->primary_key="n_id";
/*
* List of columns
*/
$this->name=array(
"n_id"=>"n_id"
, "jr_id"=>"jr_id"
,"n_text"=>"n_text"
);
/*
* Type of columns
*/
$this->type=array(
"n_id"=>"number"
, "jr_id"=>"number"
,"n_text"=>"text"
);
$this->default=array(
"n_id"=>"auto"
);
$this->date_format="DD.MM.YYYY";
parent::__construct($p_cn, $p_id);
}
}

View file

@ -458,7 +458,17 @@ class Icon_Action
$r=sprintf('<span id="%s_longer" '.
' onclick="enlarge_text(\'%s\',\'%s\') "'.
' class="icon smallicon">%s</span>',
$p_domid,$p_domid,$p_size,"&#xe81c");
$p_domid,$p_domid,$p_size,"&#xf138");
return $r;
}
/**
* @brief Increase size of input_text (p_domid) with p_domid
* @param $p_domid domid of the input "text" element
* @param $p_size size of the element
* @return string HTML string
*/
static function show_note($p_domid) {
$r='<span id="'.uniqid().'" class="smallicon icon" style="background-color:yellow" onclick="document.getElementById(\''.$p_domid.'\').show()">&#xf0f6;</span>';
return $r;
}
}

View file

@ -0,0 +1,37 @@
<?php
/*
* 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
*
* Copyright Author Dany De Bontridder danydb@noalyss.eu 2002-2022
*/
/**
* \brief display input textarea for operation note
* \see Acc_Operation_Note
*/
?>
<div class="inner_box" style="display:none;width:40em" id="jrn_note_div">
<?=\HtmlInput::title_box(_("Note"),"jrn_note_div","hide")?>
<textarea id="jrn_note_input" name= "jrn_note_input" class="input_text" cols="60" rows="7"><?=$p_current?></textarea>
<ul class="aligned-block">
<li>
<?=HtmlInput::button_hide("jrn_note_div")?>
</li>
</ul>
</div>

View file

@ -67,6 +67,16 @@
<?php echo $f_desc, Icon_Action::longer("e_comm",20)?>
</td>
</tr>
<tr>
<td>
<?=_("Note")?>
<?php echo Icon_Action::show_note('jrn_note_div') ?>
</td>
<td >
<pre id="jrn_note_td"></pre>
</td>
</tr>
<tr>
<td>
<?=_("Devise")?>
@ -78,7 +88,11 @@
</td>
</tr>
</table>
<?php
// note for operation
$note=(isset($p_array['jrn_note_input']))?$p_array['jrn_note_input']:'';
Acc_Operation_Note::input($note)
?>
<br>
<?php