noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
document_type.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * NOALYSS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * NOALYSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with NOALYSS; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21// Copyright Author Dany De Bontridder danydb@aevalys.eu
22/**
23 * \file
24 * \brief class for the table document_type
25 */
26
27/**
28 * @class Document_Type
29 *@brief class for the table document_type , a document_type is a kind of action in the follow up
30 */
32{
33
34 var $db; //!< Database Connection
35 var $dt_id; //!< primary key see SQL DOCUMENT_TYPE.DT_ID
36 var $dt_value; //!< description of the document see SQL DOCUMENT_TYPE.DT_VALUE
37 var $dt_prefix; //!< prefix for numbering see SQL DOCUMENT_TYPE.DT_PREFIX
38
39 /**
40 * \brief constructor document_type
41 * \param $p_cn database connx
42 * \param $dt_id primary key see SQL DOCUMENT_TYPE.DT_ID
43 */
44 function __construct(\Database $p_cn, int $dt_id = -1)
45 {
46 $this->db = $p_cn;
47 $this->dt_id = $dt_id;
48 }
49
50 /**
51 * \brief Get all the data for this dt_id
52 */
53
54 function get()
55 {
56 $sql = "select * from document_type where dt_id=$1";
57 $r = $this->db->get_row($sql, array($this->dt_id));
58 if ( $r == null ) return 1;
59
60 $this->dt_id = $r['dt_id'];
61 $this->dt_value = $r['dt_value'];
62 $this->dt_prefix = $r['dt_prefix'];
63 return 0;
64 }
65
66 /**
67 * @brief get a list
68 * @param $p_cn database connection
69 * @return array of data from document_type
70 */
71 static function get_list($p_cn)
72 {
73 $sql = "select * from document_type order by dt_value";
74 $r = $p_cn->get_array($sql);
75 $array = array();
76 for ($i = 0; $i < count($r); $i++)
77 {
78 $tmp=array();
79 $tmp['dt_value'] = $r[$i]['dt_value'];
80 $tmp['dt_prefix'] = $r[$i]['dt_prefix'];
81
82 $bt = new IButton('M' . $r[$i]['dt_id']);
83 $bt->label = _('Modifier');
84 $bt->javascript = "cat_doc_change('" . $r[$i]['dt_id'] . "','" . Dossier::id() . "');";
85
86 $tmp['js_mod'] = $bt->input();
87 $tmp['dt_id'] = $r[$i]['dt_id'];
88
89 $bt = new IButton('X' . $r[$i]['dt_id']);
90 $bt->label = _('Effacer');
91 $bt->javascript = "confirm_box('X{$r[$i]['dt_id']}','" . _('Vous confirmez') . "',";
92 $bt->javascript.="function () { cat_doc_remove('{$r[$i]['dt_id']}','" . Dossier::id() . "');})";
93
94 $tmp['js_remove'] = $bt->input();
95
96
97 $array[$i] = $tmp;
98 }
99 return $array;
100 }
101
102 /**
103 * Restart the increment of the document
104 * @param type $p_int
105 */
106 function set_number(int $p_int)
107 {
108 try
109 {
110 $this->db->exec_sql("alter sequence seq_doc_type_" . $this->dt_id . " restart " . $p_int);
111 }
112 catch (Exception $e)
113 {
114 alert("Erreur " . $e->getMessage());
115 }
116 }
117
118 function __toString(): string
119 {
120 return sprintf("dt_id : [%d] \n dt_value [%s] \n dt_prefix [%s]\n",$this->dt_id,$this->dt_value,$this->dt_prefix);
121 }
122
123 /**
124 * @brief unit test for Document_Type
125 * @return void
126 */
127 static function test_me()
128 {
129 // if (! defined('TEST_UNIT')) return;
130 $cn=Dossier::connect();
131 function prv_echo_error($msg,int $lineno) {
132 print '<p class="p-2 alert-danger">';
133 print "ERROR : $lineno";
134 print $msg;
135 print '</p>';
136 }
137 // prepare test
138 $old_value=[];
139 try {
140 $cn->start();
141 $old_value[0]=$cn->get_row('select * from document_type where dt_id=$1',[8]);
142 $old_value[1]=$cn->get_row('select * from document_type where dt_id=$1',[6]);
143
144 $cn->exec_sql("update document_type set dt_value='Email' where dt_id=$1",[6]);
145 $cn->exec_sql("update document_type set dt_prefix='PML' where dt_id=$1",[8]);
147 echo $document_type;
148
149 if ( $document_type->get() == 1 ) {
150 }
151
152 if ( $document_type->dt_prefix!='PML') {
153 prv_echo_error("PREFIX :". $document_type,__LINE__);
154 }
155
156 $document_type->set_number(6);
157 $document_type->get();
158
159 if ( $document_type->dt_value!='Email') {
160 prv_echo_error("VALUE :". $document_type,__LINE__);
161 }
163
164 // list array > 1 and key =5
165 if (count ($list) == 0) {
166 prv_echo_error("GET_LIST :EMPTY",__LINE__);
167 } else {
168 foreach (['js_mod','dt_id','dt_value','dt_prefix','js_remove'] as $key) {
169 if ( ! isset ($list[0][$key])) {
170 prv_echo_error ('NOT SET '.$key,__LINE__);
171 } else {
172 echo '<pre>';
173 var_dump( $list[0][$key]);
174 echo '</pre>';
175 }
176 }
177 }
178 } catch (\Exception $e) {
179 prv_echo_error("EXCEPTION :". $document_type,__LINE__);
180 print_r($e->getTraceAsString());
181 }
182 $cn->rollback();
183 }
184}
alert($p_msg, $buffer=false)
alert in javascript
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
_("actif, passif,charge,...")
contains the class for connecting to Noalyss
class for the table document_type , a document_type is a kind of action in the follow up
$dt_prefix
prefix for numbering see SQL DOCUMENT_TYPE.DT_PREFIX
$db
Database Connection.
__construct(\Database $p_cn, int $dt_id=-1)
constructor document_type
$dt_id
primary key see SQL DOCUMENT_TYPE.DT_ID
$dt_value
description of the document see SQL DOCUMENT_TYPE.DT_VALUE
set_number(int $p_int)
Restart the increment of the document.
static test_me()
unit test for Document_Type
static get_list($p_cn)
get a list
Html Input.
$document_type[]
$SecUser db
print
Type of printing.