From 6bc9077b49866592194db82bbccf1b6712fffc8b Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sun, 11 Sep 2022 13:32:44 +0200 Subject: [PATCH] =?UTF-8?q?New=20#0002193:=20Possibilit=C3=A9=20d'ajouter?= =?UTF-8?q?=20directement=20une=20note=20aux=20op=C3=A9rations=20Cosmetic?= =?UTF-8?q?=20:=20change=20icon=20for=20enlarging=20operation=20label?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Acc_Operation_NoteTest.php | 60 +++++++++ include/class/acc_ledger.class.php | 29 ++++ include/class/acc_ledger_purchase.class.php | 20 ++- include/class/acc_ledger_sale.class.php | 18 ++- include/class/acc_operation_note.class.php | 126 ++++++++++++++++++ include/database/jrn_note_sql.class.php | 66 +++++++++ include/lib/icon_action.class.php | 12 +- include/template/acc_operation_note-input.php | 37 +++++ include/template/form_ledger_detail.php | 16 ++- 9 files changed, 374 insertions(+), 10 deletions(-) create mode 100644 Acc_Operation_NoteTest.php create mode 100644 include/class/acc_operation_note.class.php create mode 100644 include/database/jrn_note_sql.class.php create mode 100644 include/template/acc_operation_note-input.php diff --git a/Acc_Operation_NoteTest.php b/Acc_Operation_NoteTest.php new file mode 100644 index 000000000..7a7706672 --- /dev/null +++ b/Acc_Operation_NoteTest.php @@ -0,0 +1,60 @@ +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"); + } +} diff --git a/include/class/acc_ledger.class.php b/include/class/acc_ledger.class.php index 8f422529f..0595a7998 100644 --- a/include/class/acc_ledger.class.php +++ b/include/class/acc_ledger.class.php @@ -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.=' '.td(_('Période Comptable')).td($date_limit['p_start'].'-'.$date_limit['p_end']).''; $ret.=""._('Libellé')." ".h($desc).""; + $ret.=""; + $ret.=_('Note').'
'. h($p_array['jrn_note_input']).'
'; + $ret.=""; $ret.=""._('PJ Num')." ".h($e_pj).""; $ret.=''; $ret.=""; @@ -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.=''; $ret.=''; + $ret.=''; + $ret.=''; + $ret.=''; // 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.='
'; + $ret.=_("Note"). + Icon_Action::show_note('jrn_note_div'); + $ret.='
'; +// 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) { diff --git a/include/class/acc_ledger_purchase.class.php b/include/class/acc_ledger_purchase.class.php index 926b3930b..2deb670e5 100644 --- a/include/class/acc_ledger_purchase.class.php +++ b/include/class/acc_ledger_purchase.class.php @@ -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.=' ' . _('Fournisseur') . ' ' . hb($e_client . ':' . $client_name) . ''; $r.=''; $r.=''; + $r.='
'._('Note').' '.h($p_array['jrn_note_input']).'
'; $r.=''; $r.='
'; $r.='
'; @@ -1846,7 +1854,7 @@ EOF; if ( $g_parameter->MY_ANALYTIC!='nu' && !$p_summary) // use of AA $r.=''; - $r.=(! $p_summary )?'
':'
'; + $r.='
'; $r.='

Totaux

'; $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); diff --git a/include/class/acc_ledger_sale.class.php b/include/class/acc_ledger_sale.class.php index 9ca68cd19..f7bb493bc 100644 --- a/include/class/acc_ledger_sale.class.php +++ b/include/class/acc_ledger_sale.class.php @@ -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 '' . @@ -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.=' ' . _('Client') . ' ' . hb($e_client . ':' . $client_name) . ''; $r.=''; $r.=''; + $r.='
'._('Note').' '.h($p_array['jrn_note_input']).'
'; $r.='
'; $r.='
'; $r.='
'; @@ -1101,7 +1111,7 @@ EOF; $r.='

'; if ($g_parameter->MY_ANALYTIC != 'nu' && ! $p_summary) // use of AA $r.=''; - $r.=(! $p_summary )?'
':'
'; + $r.='
'; $r.='

Totaux

'; $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 */ diff --git a/include/class/acc_operation_note.class.php b/include/class/acc_operation_note.class.php new file mode 100644 index 000000000..47f829a33 --- /dev/null +++ b/include/class/acc_operation_note.class.php @@ -0,0 +1,126 @@ +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 ''; + } +} \ No newline at end of file diff --git a/include/database/jrn_note_sql.class.php b/include/database/jrn_note_sql.class.php new file mode 100644 index 000000000..08604a4a5 --- /dev/null +++ b/include/database/jrn_note_sql.class.php @@ -0,0 +1,66 @@ +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); + } + +} \ No newline at end of file diff --git a/include/lib/icon_action.class.php b/include/lib/icon_action.class.php index 6e865164a..65a3485ee 100644 --- a/include/lib/icon_action.class.php +++ b/include/lib/icon_action.class.php @@ -458,7 +458,17 @@ class Icon_Action $r=sprintf('%s', - $p_domid,$p_domid,$p_size,""); + $p_domid,$p_domid,$p_size,""); + 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=''; return $r; } } diff --git a/include/template/acc_operation_note-input.php b/include/template/acc_operation_note-input.php new file mode 100644 index 000000000..17efd9ad7 --- /dev/null +++ b/include/template/acc_operation_note-input.php @@ -0,0 +1,37 @@ + + + \ No newline at end of file diff --git a/include/template/form_ledger_detail.php b/include/template/form_ledger_detail.php index 12ad9303b..ed6a7c342 100644 --- a/include/template/form_ledger_detail.php +++ b/include/template/form_ledger_detail.php @@ -67,6 +67,16 @@ + + + + + + +

+        
+    
+
     
         
             
@@ -78,7 +88,11 @@
         
     
 
-     
+