Merge branch 'devel' into dev9101
This commit is contained in:
commit
40bc3fc489
6 changed files with 279 additions and 23 deletions
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -34,11 +34,13 @@ class Document_modele
|
|||
var $sequence; /*!< $sequence sequence number used by the create sequence start with */
|
||||
var $md_affect; /*!< $md_affect if you can use it in VEN for sale, ACH for purchase or GES for follow-up */
|
||||
var $md_filename; /*! < $md_filename is the filename of the template */
|
||||
var $start; /*! < $md_filename is the filename of the template */
|
||||
//Constructor parameter = database connexion
|
||||
function __construct($p_cn,$p_id=-1)
|
||||
{
|
||||
$this->cn=$p_cn;
|
||||
$this->md_id=$p_id;
|
||||
$this->start=0;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -157,7 +159,7 @@ class Document_modele
|
|||
$new_name=tempnam($_ENV['TMP'],'document_');
|
||||
if ( strlen ($_FILES['doc']['tmp_name']) != 0 )
|
||||
{
|
||||
if (move_uploaded_file($_FILES['doc']['tmp_name'],
|
||||
if ($this->move_uploaded_file($_FILES['doc']['tmp_name'],
|
||||
$new_name))
|
||||
{
|
||||
// echo "Image saved";
|
||||
|
|
@ -174,7 +176,7 @@ class Document_modele
|
|||
{
|
||||
$r=Database::fetch_array($ret,0);
|
||||
$old_oid=$r['md_lob'];
|
||||
if (strlen($old_oid) != 0)
|
||||
if (strlen(""??$old_oid) != 0)
|
||||
$this->cn->lo_unlink($old_oid);
|
||||
}
|
||||
// Load new document
|
||||
|
|
@ -196,6 +198,10 @@ class Document_modele
|
|||
return ;
|
||||
}
|
||||
}
|
||||
function move_uploaded_file($temporary_name, $target_path)
|
||||
{
|
||||
return move_uploaded_file ($temporary_name, $target_path);
|
||||
}
|
||||
/*!
|
||||
* \brief Remove a template
|
||||
* \return nothing
|
||||
|
|
@ -204,19 +210,18 @@ class Document_modele
|
|||
{
|
||||
$this->cn->start();
|
||||
// first we unlink the document
|
||||
$sql="select md_lob from document_modele where md_id=".$this->md_id;
|
||||
$res=$this->cn->exec_sql($sql);
|
||||
$sql="select md_lob from document_modele where md_id=$1";
|
||||
$res=$this->cn->exec_sql($sql,[$this->md_id]);
|
||||
$r=Database::fetch_array($res,0);
|
||||
// if a lob is found
|
||||
if ( strlen ($r['md_lob']) &&
|
||||
$this->cn->exist_blob($r['md_lob']) )
|
||||
if ( !empty ($r['md_lob']) &&$this->cn->exist_blob($r['md_lob']) )
|
||||
{
|
||||
// we remove it first
|
||||
$this->cn->lo_unlink($r['md_lob']);
|
||||
}
|
||||
// now we can delete the row
|
||||
$sql="delete from document_modele where md_id =".$this->md_id;
|
||||
$sql=$this->cn->exec_sql($sql);
|
||||
$sql="delete from document_modele where md_id =$1";
|
||||
$res=$this->cn->exec_sql($sql,[$this->md_id]);
|
||||
$this->cn->commit();
|
||||
}
|
||||
|
||||
|
|
@ -258,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>';
|
||||
|
|
@ -280,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;
|
||||
}
|
||||
|
|
@ -323,7 +330,7 @@ class Document_modele
|
|||
$new_name=tempnam($_ENV['TMP'],'document_');
|
||||
if ( strlen ($_FILES['doc']['tmp_name']) != 0 )
|
||||
{
|
||||
if (move_uploaded_file($_FILES['doc']['tmp_name'],
|
||||
if ($this->move_uploaded_file($_FILES['doc']['tmp_name'],
|
||||
$new_name))
|
||||
{
|
||||
// echo "Image saved";
|
||||
|
|
@ -344,7 +351,16 @@ class Document_modele
|
|||
$this->cn->lo_unlink($old_oid);
|
||||
}
|
||||
// Load new document
|
||||
$this->cn->exec_sql("update document_modele set md_lob=".$oid.", md_mimetype='".$_FILES['doc']['type']."' ,md_filename='".$_FILES['doc']['name']."' where md_id=".$this->md_id);
|
||||
|
||||
$this->cn->exec_sql("update document_modele
|
||||
set md_lob=$1,
|
||||
md_mimetype=$2,
|
||||
md_filename=$3
|
||||
where md_id=$4",[
|
||||
$oid,
|
||||
$_FILES['doc']['type'],
|
||||
$_FILES['doc']['name'],
|
||||
$this->md_id]);
|
||||
$this->cn->commit();
|
||||
}
|
||||
else
|
||||
|
|
@ -357,8 +373,8 @@ class Document_modele
|
|||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
record_log($e);
|
||||
rollback($this->cn);
|
||||
record_log($e);
|
||||
$this->cn->rollback();
|
||||
return ;
|
||||
}
|
||||
$this->cn->commit();
|
||||
|
|
|
|||
|
|
@ -427,6 +427,7 @@ class Follow_Up
|
|||
$aDocMod->name='doc_mod';
|
||||
$aDocMod->value=$this->db->make_array('select md_id,dt_value||\' : \'||md_name as md_name'.
|
||||
' from document_modele join document_type on (md_type=dt_id)'.
|
||||
" where md_affect ='GES' and md_type = ".$this->dt_id.
|
||||
' order by md_name');
|
||||
$str_select_doc=$aDocMod->input();
|
||||
/* if no document then do not show the generate button */
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
196
unit-test/include/class/Document_ModeleTest.php
Normal file
196
unit-test/include/class/Document_ModeleTest.php
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* * Copyright (C) 2022 Dany De Bontridder <dany@alchimerys.be>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*
|
||||
* Author : Dany De Bontridder danydb@noalyss.eu
|
||||
* 27/04/23
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief noalyss
|
||||
*/
|
||||
namespace NOALYSS\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
require DIRTEST . '/global.php';
|
||||
|
||||
class Document_Modele extends \Document_modele
|
||||
{
|
||||
function move_uploaded_file($temporary_name, $target_path)
|
||||
{
|
||||
return copy ($temporary_name, $target_path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @backupGlobals enabled
|
||||
* @coversDefaultClass
|
||||
*/
|
||||
class Document_ModeleTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Fiche
|
||||
*/
|
||||
protected $object_id;
|
||||
protected $type_id;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test method is executed.
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$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'");
|
||||
|
||||
$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)
|
||||
values ($1,$2,$3,$4)";
|
||||
$g_connection->exec_sql($sql,[$md_id,'UNIT TEST',$this->type_id,'TST']);
|
||||
$this->object_id=$md_id;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test method is executed.
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
|
||||
$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'");
|
||||
}
|
||||
|
||||
/**
|
||||
* the setUpBeforeClass() template methods is called before the first test of the test case
|
||||
* class is run
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
// include 'global.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDownAfterClass() template methods is calleafter the last test of the test case class is run,
|
||||
*
|
||||
*/
|
||||
static function tearDownAfterClass(): void
|
||||
{
|
||||
$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'");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testSaveDeleteUpate()
|
||||
{
|
||||
$g_connection=\Dossier::connect();
|
||||
$document_modele=new Document_modele($g_connection);
|
||||
$document_modele->md_name="SAVETESTPHPUNIT";
|
||||
$document_modele->md_type=$this->type_id;
|
||||
$document_modele->md_affect="TST";
|
||||
// make file
|
||||
$_FILES=array();
|
||||
$_FILES['doc']=[];
|
||||
$_FILES['doc']['name']="test-lob.bin";
|
||||
$_FILES['doc']['error']=0;
|
||||
$this->assertFileExists(__DIR__."/data/".$_FILES['doc']['name'],
|
||||
$_FILES['doc']['name']." file absent , pls create it");
|
||||
|
||||
$_FILES['doc']['size']=stat(__DIR__."/data/".$_FILES['doc']['name'])['size'];
|
||||
$_FILES['doc']['tmp_name']=tempnam("/tmp","rsult");
|
||||
|
||||
|
||||
|
||||
// dd if=/dev/zero of=test-lob.bin bs=4096 count=1
|
||||
$_FILES['doc']['type']="app/bin";
|
||||
// save file
|
||||
$document_modele->save();
|
||||
|
||||
|
||||
|
||||
$this->assertTrue($g_connection->get_value("select count(*) from document_modele where md_id=$1 ",[$document_modele->md_id])>0,'Document Modele not created');
|
||||
|
||||
// is the file really loaded ?
|
||||
$lob_save=$g_connection->get_value("select md_lob from document_modele where md_id=$1 ",[$document_modele->md_id]);
|
||||
|
||||
$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]);
|
||||
|
||||
$this->assertEquals( 'XXXX',$g_connection->get_value("select md_name from document_modele where md_id=$1",[$document_modele->md_id]) ,'update md_name failed');
|
||||
$this->assertTrue($g_connection->get_value("select md_type from document_modele where md_id=$1",[$document_modele->md_id]) == '1','update md_type failed');
|
||||
|
||||
// is the file really loaded ?
|
||||
$lob=$g_connection->get_value("select md_lob from document_modele where md_id=$1 ",[$document_modele->md_id]);
|
||||
|
||||
$this->assertTrue(! empty($lob),"Document no loaded");
|
||||
$this->assertTrue($lob <> $lob_save, "LOB not updated");
|
||||
|
||||
// file correct ? file size = 0 kb ,PHP bug ?
|
||||
//=========================================================
|
||||
/*
|
||||
$g_connection->start();
|
||||
$this->assertTrue($g_connection->lo_export($lob,__DIR__."/data/result.bin")," can not export LOB");
|
||||
$g_connection->commit();
|
||||
|
||||
$this->assertFileEquals(__DIR__."/data/".$_FILES['doc']['name'],__DIR__."/data/result.bin","file corrupted");
|
||||
*/
|
||||
$document_modele->delete();
|
||||
$this->assertTrue($g_connection->get_value("select count(*) from document_modele where md_id=$1 ",[$document_modele->md_id]) == 0,'Document Modele not deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testLoad()
|
||||
{
|
||||
$g_connection=\Dossier::connect();
|
||||
$document_modele=new Document_Modele($g_connection,$this->object_id);
|
||||
$document_modele->load();
|
||||
//UNIT TEST',$this->type_id,'TST']
|
||||
$this->assertEquals($document_modele->md_name,'UNIT TEST');
|
||||
$this->assertEquals($document_modele->md_type,$this->type_id);
|
||||
$this->assertEquals($document_modele->md_affect,'TST');
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue