[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 02/04: Document_Modele : add document_compone
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 02/04: Document_Modele : add document_component to ease generating document from plugin. |
Date: |
Thu, 27 Apr 2023 12:03:35 -0400 (EDT) |
sparkyx pushed a commit to branch devel
in repository noalyss.
commit 639f739b67dca6e75901a2234694a9ad1566a389
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Thu Apr 27 17:39:37 2023 +0200
Document_Modele : add document_component to ease
generating document from plugin.
---
include/ajax/ajax_mod_document.php | 1 +
include/class/document_modele.class.php | 12 ++++---
include/template/modele_document.php | 10 +++---
sql/upgrade.sql | 44 +++++++++++++++++++++++++
unit-test/include/class/Document_ModeleTest.php | 16 +++++----
5 files changed, 66 insertions(+), 17 deletions(-)
diff --git a/include/ajax/ajax_mod_document.php
b/include/ajax/ajax_mod_document.php
index 50a214bfe..059af8b4d 100644
--- a/include/ajax/ajax_mod_document.php
+++ b/include/ajax/ajax_mod_document.php
@@ -27,6 +27,7 @@ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas
permis');
/* 1. Check security */
$cn=Dossier::connect();
/* 2. find the document */
+global $doc;
$doc=new Document_Modele($cn,$id);
/* 3. display it */
diff --git a/include/class/document_modele.class.php
b/include/class/document_modele.class.php
index 19ae172e0..1bf5938a5 100644
--- a/include/class/document_modele.class.php
+++ b/include/class/document_modele.class.php
@@ -263,11 +263,7 @@ class Document_modele
$r.=td(_('Affectation'));
$waffect=new ISelect();
$waffect->name='md_affect';
- $waffect->value=array(
- array('value'=>'ACH','label'=>_('Uniquement
journaux achat')),
- array('value'=>'VEN','label'=>_('Uniquement
journaux vente')),
- array('value'=>'GES','label'=>_('Partie gestion'))
- );
+ $waffect->value=$this->cn->make_array("select dc_code,dc_comment from
public.document_component order by dc_code");
$r.=td($waffect->input());
$r.='</tr>';
@@ -285,7 +281,13 @@ class Document_modele
$r.='<td class="notice">Si vous laissez à 0, la
numérotation ne changera pas, la prochaine facture sera n+1, n étant le
n° que vous avez donné</td>';
$r.="</tr>";
$r.='</table>';
+ $r.='<ul class="aligned-block">';
+ $r.='<li>';
$r.=HtmlInput::submit('add_document','Ajout');
+ $r.='</li>';
+ $r.='<li>';
+ $r.=HtmlInput::button_hide("add_modele");
+ $r.='</li>';
$r.="</form></p>";
return $r;
}
diff --git a/include/template/modele_document.php
b/include/template/modele_document.php
index 7a248128f..60136e14c 100644
--- a/include/template/modele_document.php
+++ b/include/template/modele_document.php
@@ -1,6 +1,7 @@
<?php
//This file is part of NOALYSS and is under GPL
//see licence.txt
+global $doc,$cn;
?>
<?php echo HtmlInput::title_box("Modèle de document","mod_doc",'hide')?>
<form method="post" enctype="multipart/form-data">
@@ -44,12 +45,9 @@ echo $a->input();
$waffect=new ISelect();
$waffect->name='md_affect';
- $waffect->value=array(
- array('value'=>'ACH','label'=>_('Uniquement
journaux achat')),
- array('value'=>'VEN','label'=>_('Uniquement
journaux vente')),
- array('value'=>'GES','label'=>_('Partie gestion'))
- );
- $waffect->selected=$doc->md_affect;
+ $waffect->value=$cn->make_array("select dc_code,dc_comment from
public.document_component order by dc_code");
+
+ $waffect->selected=$doc->md_affect;
echo $waffect->input();
?>
</td>
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index c964a7685..d167abe17 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -1,2 +1,46 @@
update menu_ref set me_menu='Journal' where me_code='CFGLED';
+CREATE OR REPLACE FUNCTION comptaproc.four_upper_letter()
+ RETURNS trigger
+AS $function$
+begin
+ new.dc_code=transform_to_code(new.dc_code);
+ new.dc_code:=substr(new.dc_code,1,4);
+ return new;
+END;
+$function$
+LANGUAGE plpgsql;
+
+COMMENT ON FUNCTION comptaproc.four_upper_letter() IS 'Cut to the 4 first
letter in uppercase';
+
+
+DROP TABLE if exists document_component ;
+
+CREATE TABLE document_component (
+ dc_id int4 NOT NULL GENERATED BY DEFAULT
AS IDENTITY, -- PK
+ dc_code text NOT NULL, -- Code used in
document_modele
+ dc_comment text not null , -- description
+ CONSTRAINT document_component_pk PRIMARY
KEY (dc_id),
+ CONSTRAINT document_component_un UNIQUE
(dc_code)
+);
+COMMENT ON TABLE public.document_component IS 'Give the component of NOALYSS
that is using is';
+
+-- Column comments
+
+COMMENT ON COLUMN public.document_component.dc_id IS 'PK';
+COMMENT ON COLUMN public.document_component.dc_code IS 'Code used in
document_modele';
+COMMENT ON COLUMN public.document_component.dc_comment IS 'Code used in
document_modele';
+
+-- Table Triggers
+
+create trigger t_code before insert
+ or update on
+ public.document_component for each row execute function
comptaproc.four_upper_letter();
+
+
+INSERT INTO document_component (dc_comment, dc_code) VALUES('Journaux achat',
'ACH');
+INSERT INTO document_component (dc_comment, dc_code) VALUES('Journaux vente',
'VEN');
+INSERT INTO document_component (dc_comment, dc_code) VALUES('Gestion', 'GES');
+
+ALTER TABLE public.document_modele ADD CONSTRAINT document_modele_fk FOREIGN
KEY (md_affect) REFERENCES public.document_component(dc_code) ON UPDATE CASCADE;
+
diff --git a/unit-test/include/class/Document_ModeleTest.php
b/unit-test/include/class/Document_ModeleTest.php
index 314f12e57..a978d95e3 100644
--- a/unit-test/include/class/Document_ModeleTest.php
+++ b/unit-test/include/class/Document_ModeleTest.php
@@ -63,8 +63,10 @@ class Document_ModeleTest extends TestCase
$g_connection->exec_sql("delete from document_modele where
md_affect='TST'");
$g_connection->exec_sql("delete from document_type where
dt_value='PHPUNIT'");
+ $g_connection->exec_sql("delete from document_component where
dc_code='TST'");
$this->type_id=$g_connection->get_value("insert into document_type
(dt_value,dt_prefix) values ('PHPUNIT','TST')returning dt_id");
+ $g_connection->get_value("insert into document_component
(dc_code,dc_comment) values ('TST','PHPUnit Test')");
$md_id=$g_connection->get_next_seq('document_modele_md_id_seq');
$sql="insert into document_modele(md_id,md_name,md_type,md_affect)
@@ -102,13 +104,13 @@ class Document_ModeleTest extends TestCase
*/
static function tearDownAfterClass(): void
{
- // include 'global.php';
+ $g_connection=\Dossier::connect();
+
+ $g_connection->exec_sql("delete from document_modele where
md_affect='TST'");
+ $g_connection->exec_sql("delete from document_type where
dt_value='PHPUNIT'");
+ $g_connection->exec_sql("delete from document_component where
dc_code='TST'");
+ $g_connection->exec_sql("delete from document_component where
dc_code='E'");
}
-//
-// public function dataExample()
-// {
-// return array([1], [2], [3]);
-// }
/**
*
@@ -149,6 +151,7 @@ class Document_ModeleTest extends TestCase
$this->assertTrue(! empty($lob_save),"Document no loaded");
//unset ($_FILES);
+ $g_connection->get_value("insert into document_component
(dc_code,dc_comment) values ('E','PHPUnit Test')");
$document_modele->update(['md_name'=>'XXXX',"md_type"=>"1","md_affect"=>'E','seq'=>0]);
@@ -188,5 +191,6 @@ class Document_ModeleTest extends TestCase
$this->assertEquals($document_modele->md_type,$this->type_id);
$this->assertEquals($document_modele->md_affect,'TST');
+
}
}
\ No newline at end of file