20 require_once NOALYSS_INCLUDE.
'/class/class_own.php';
21 require_once NOALYSS_INCLUDE.
'/class/class_acc_account_ledger.php';
22 require_once NOALYSS_INCLUDE.
'/class/class_follow_up.php';
23 require_once NOALYSS_INCLUDE.
'/class/class_acc_tva.php';
24 require_once NOALYSS_INCLUDE.
'/class/class_user.php';
25 require_once NOALYSS_INCLUDE.
'/lib/class_zip_extended.php';
56 $this->d_id=$this->
db->get_next_seq(
"document_d_id_seq");
58 $this->d_number=$this->
db->get_next_seq(
"seq_doc_type_".$this->md_type);
59 $sql=sprintf(
'insert into document(d_id,ag_id,d_number) values(%d,%d,%d)',
75 foreach (array(
'/',
'*',
'<',
'>',
';',
',',
'\\',
'.',
':',
'(',
')',
' ',
'[',
']') as $i) {
76 $pj= str_replace($i,
"-",$pj);
79 $pos_prefix=strrpos($filename,
".");
80 if ($pos_prefix == 0) $pos_prefix=strlen($filename);
81 $filename_no=substr($filename,0,$pos_prefix);
82 $filename_suff=substr($filename,$pos_prefix,strlen($filename));
83 $new_filename= strtolower($filename_no.
"-".$pj.$filename_suff);
97 $dirname=tempnam($_ENV[
'TMP'],
'doc_');
104 $dm_info=
"select md_name,md_type,md_lob,md_filename,md_mimetype
105 from document_modele where md_id=".$this->md_id;
106 $Res=$this->
db->exec_sql($dm_info);
109 $this->d_lob=
$row[
'md_lob'];
110 $this->d_filename=
$row[
'md_filename'];
111 $this->d_mimetype=
$row[
'md_mimetype'];
112 $this->d_name=
$row[
'md_name'];
116 $filename=
$row[
'md_filename'];
117 $exp=$this->
db->lo_export(
$row[
'md_lob'],
$dirname.DIRECTORY_SEPARATOR.$filename);
118 if ( $exp ===
false )
echo_warning( __FILE__.
":".__LINE__.
"Export NOK $filename");
123 if ( strpos(
$row[
'md_mimetype'],
'vnd.oasis') != 0 )
127 if ($zip->open($filename) === TRUE) {
128 $zip->extractTo(
$dirname.DIRECTORY_SEPARATOR);
131 echo __FILE__.
":".__LINE__.
"cannot unzip model ".$filename;
137 $file_to_parse=
"content.xml";
141 $file_to_parse=$filename;
143 $this->d_number=$this->
db->get_next_seq(
"seq_doc_type_".
$row[
'md_type']);
150 if ( strpos(
$row[
'md_mimetype'],
'vnd.oasis') != 0 )
154 $res = $zip->open($filename, ZipArchive::CREATE);
157 throw new Exception ( __FILE__.
":".__LINE__.
"cannot recreate zip");
159 $zip->add_recurse_folder(
$dirname.DIRECTORY_SEPARATOR);
164 $file_to_parse=$filename;
166 if ( $p_filename !=
"") {
171 $href=http_build_query(array(
'gDossier'=>
Dossier::id(),
"d_id"=>$this->d_id,
'act'=>
'RAW:document'));
172 $ret=
'<A class="mtitle" HREF="export.php?'.$href.
'">'._(
'Document').
'</A>';
198 $infile_name=$p_dir.DIRECTORY_SEPARATOR.$p_file;
199 $h=fopen($infile_name,
"r");
202 $temp_dir=$_ENV[
'TMP'];
203 if ( is_dir($temp_dir) ==
false )
205 if ( mkdir($temp_dir) ==
false )
207 $msg=_(
"Ne peut pas créer le répertoire ".$temp_dir);
208 throw new Exception(
$msg);
212 $output_name=tempnam($temp_dir,
"gen_doc_");
213 $output_file=fopen($output_name,
"w+");
217 echo __FILE__.
":".__LINE__.
"cannot open $p_dir $p_file ";
218 $msg=_(
"Ne peut pas ouvrir $p_dir $p_file");
219 throw new Exception(
$msg);
221 if ( $output_file ==
false)
223 $msg=_(
"Ne peut pas ouvrir $p_dir $p_file");
225 throw new Exception($msg);
230 $regex=
"/=*<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*>>/i";
236 $regex=
"/=*<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*>>/i";
248 while ( preg_match_all ($regex,$buffer,
$f) >0 )
252 foreach (
$f as $apattern )
256 foreach($apattern as $pattern)
262 $tag=str_replace($lt,
'',$pattern);
275 $searched=
'/office:value-type="string"><text:p>'.$pattern.
'/';
276 $replaced=
'office:value-type="float" office:value="'.$value.
'"><text:p>'.$pattern;
277 $buffer=preg_replace($searched, $replaced, $buffer,1);
281 $pos=strpos($buffer,$to_remove);
283 $len=strlen($to_remove);
292 $buffer=substr_replace($buffer,
$value,$pos,$len);
299 fwrite($output_file,$buffer);
303 fclose($output_file);
304 if ( (
$ret=copy ($output_name,$infile_name)) == FALSE )
306 echo _(
'Ne peut pas sauver '.$output_name.
' vers '.$infile_name.
' code d\'erreur ='.
$ret);
323 $this->d_lob=$this->
db->lo_import($p_file);
324 if ( $this->d_lob ==
false )
326 echo
"ne peut pas importer [$p_file]";
330 $sql=
"insert into document(ag_id,d_lob,d_number,d_filename,d_mimetype)
331 values ($1,$2,$3,$4,$5)";
338 $this->d_id=$this->
db->get_current_seq(
"document_d_id_seq");
354 if (
sizeof($_FILES) == 0 )
return;
360 $name=$_FILES[
'file_upload'][
'name'];
361 for ($i = 0; $i <
sizeof(
$name);$i++)
363 $new_name=tempnam($_ENV[
'TMP'],
'doc_');
365 if ( strlen($_FILES[
'file_upload'][
'tmp_name'][$i]) != 0 )
368 if ( move_uploaded_file($_FILES[
'file_upload'][
'tmp_name'][$i],$new_name))
370 $oid=$this->
db->lo_import($new_name);
374 $this->
db->rollback();
380 $this->d_filename=$_FILES[
'file_upload'][
'name'][$i];
381 $this->d_mimetype=$_FILES[
'file_upload'][
'type'][$i];
382 $this->d_description= strip_tags(
$_POST[
'input_desc'][$i]);
384 $sql=
"insert into document (ag_id, d_lob,d_filename,d_mimetype,d_number,d_description) values ($1,$2,$3,$4,$5,$6)";
385 $this->
db->exec_sql(
$sql,array($p_ag_id,$this->d_lob,$this->d_filename,$this->d_mimetype,1,$this->d_description));
404 $sql =
"insert into document (ag_id, d_lob,d_filename,d_mimetype,d_number,d_description) values ($1,$2,$3,$4,$5,$6)";
405 $cn->exec_sql(
$sql, array($p_ag_id, $p_lob, $p_filename, $p_mimetype, 1, $p_description));
415 if ( $this->d_id == 0 )
417 $image=
'<IMG SRC="image/insert_table.gif" title="'.$this->d_filename.
'" border="0">';
419 $href=http_build_query(array(
'gDossier'=>
Dossier::id(),
"d_id"=>$this->d_id,
'act'=>
'RAW:document'));
421 $r=
'<A class="mtitle" HREF="export.php?'.$href.
'">'.$image.
'</A>';
432 "select d_id,d_lob,d_filename,d_mimetype from document where d_id=".$this->d_id );
437 $tmp=tempnam($_ENV[
'TMP'],
'document_');
439 $this->d_mimetype=
$row[
'd_mimetype'];
440 $this->d_filename=
$row[
'd_filename'];
443 ini_set(
'zlib.output_compression',
'Off');
444 header(
"Pragma: public");
445 header(
"Expires: Mon, 26 Jul 1997 05:00:00 GMT");
446 header(
"Last-Modified: " . gmdate(
"D, d M Y H:i:s") .
" GMT");
447 header(
"Cache-Control: must-revalidate");
448 header(
'Content-type: '.$this->d_mimetype);
449 header(
'Content-Disposition: attachment;filename="'.$this->d_filename.
'"',FALSE);
450 header(
"Accept-Ranges: bytes");
452 while ( !feof (
$file) )
454 echo fread(
$file,8192);
469 $res=$this->
db->get_array(
'select d_id, ag_id, d_lob, d_number, d_filename,'.
470 ' d_mimetype,d_description from document where ag_id=$1',array(
$ag_id));
472 for ($i=0;$i<
sizeof(
$res); $i++ )
478 $doc->d_number=
$res[$i][
'd_number'];
479 $doc->d_filename=
$res[$i][
'd_filename'];
480 $doc->d_mimetype=
$res[$i][
'd_mimetype'];
481 $doc->d_description=
$row[
'd_description'];
491 $sql=
"select * from document where d_id=".$this->d_id;
497 $this->d_mimetype=
$row[
'd_mimetype'];
498 $this->d_filename=
$row[
'd_filename'];
499 $this->d_lob=
$row[
'd_lob'];
500 $this->d_number=
$row[
'd_number'];
501 $this->d_description=
$row[
'd_description'];
565 $p_tag=strtoupper($p_tag);
566 $p_tag=str_replace(
'=',
'',$p_tag);
575 $r=
' Date inconnue ';
578 if ( isset (
$p_array[
'ag_timestamp'])) {
591 $r=$g_parameter->MY_NAME;
594 $r=$g_parameter->MY_CP;
597 $r=$g_parameter->MY_COMMUNE;
600 $r=$g_parameter->MY_TVA;
603 $r=$g_parameter->MY_STREET;
606 $r=$g_parameter->MY_NUMBER;
609 $r=$g_parameter->MY_TEL;
612 $r=$g_parameter->MY_FAX;
615 $r=$g_parameter->MY_PAYS;
625 $tiers->get_by_qcode(
$qcode,
false);
633 $tiers->get_by_qcode(
$qcode,
false);
639 $tiers->get_by_qcode(
$qcode,
false);
647 $tiers->get_by_qcode(
$qcode,
false);
655 $tiers->get_by_qcode(
$qcode,
false);
664 $tiers->get_by_qcode(
$qcode,
false);
674 $tiers->get_by_qcode(
$qcode,
false);
680 $tiers->get_by_qcode(
$qcode,
false);
683 case 'CUST_BANQUE_NO':
686 $tiers->get_by_qcode(
$qcode,
false);
689 case 'CUST_BANQUE_NAME':
692 $tiers->get_by_qcode(
$qcode,
false);
705 $tiers->get_by_qcode(
$qcode,
false);
716 $tiers->get_by_qcode(
$qcode,
false);
729 $tiers->get_by_qcode(
$qcode,
false);
742 $tiers->get_by_qcode(
$qcode,
false);
756 $tiers->get_by_qcode(
$qcode,
false);
771 $tiers->get_by_qcode(
$qcode,
false);
782 $tiers->get_by_qcode(
$qcode,
false);
785 case 'BENEF_BANQUE_NO':
793 $tiers->get_by_qcode(
$qcode,
false);
796 case 'BENEF_BANQUE_NAME':
804 $tiers->get_by_qcode(
$qcode,
false);
815 return $_SESSION[
'use_name'].
', '.$_SESSION[
'use_first_name'];
837 case 'DATE_LIMIT_CALC':
840 if ( !isset (${
$id}) )
return "";
846 if ( !isset (${
$id}) )
return "";
856 $id=
'e_march'.$this->counter;
858 if ( ! isset (${
$id}))
return "";
860 if ( ${
'e_march'.$this->counter.
'_price'} != 0 && ${
'e_quant'.$this->counter} != 0 )
863 $f->get_by_qcode(${
$id},
false);
868 case 'VEN_ART_LABEL':
870 $id=
'e_march'.$this->counter.
"_label";
873 if (! isset (${
$id}) || (isset (${
$id}) && strlen(
trim(${
$id})) == 0))
875 $id =
'e_march' . $this->counter;
882 if (${
'e_march' . $this->counter .
'_price'} != 0 && ${
'e_quant' . $this->counter} != 0)
885 $f->get_by_qcode(${
$id},
false);
892 $r=${
'e_march'.$this->counter.
'_label'};
894 case 'VEN_ART_STOCK_CODE':
896 $id =
'e_march' . $this->counter;
903 if (${
'e_march' . $this->counter .
'_price'} != 0 && ${
'e_quant' . $this->counter} != 0)
906 $f->get_by_qcode(${
$id},
false);
912 case 'VEN_ART_PRICE':
914 $id=
'e_march'.$this->counter.
'_price' ;
915 if ( !isset (${
$id}) )
return "";
916 if (${
$id} == 0 )
return "";
921 case 'VEN_ART_TVA_RATE':
923 $id=
'e_march'.$this->counter.
'_tva_id';
924 if ( !isset (${
$id}) )
return "";
925 if ( ${
$id} == -1 || ${
$id}==
'' )
return "";
926 $march_id=
'e_march'.$this->counter.
'_price' ;
927 if ( ! isset (${$march_id}))
return '';
929 $tva->set_parameter(
"id",${
$id});
930 if ( $tva->load() == -1)
return '';
931 return $tva->get_parameter(
"rate");
935 case 'VEN_ART_TVA_CODE':
937 $id=
'e_march'.$this->counter.
'_tva_id';
938 if ( !isset (${
$id}) )
return "";
939 if ( ${
$id} == -1 )
return "";
940 $qt=
'e_quant'.$this->counter;
941 $price=
'e_march'.$this->counter.
'_price' ;
942 if ( ${$price} == 0 || ${$qt} == 0
943 || strlen(
trim( $price )) ==0
944 || strlen(
trim($qt)) ==0)
952 $id=
'e_march'.$this->counter.
'_tva_id';
953 if ( !isset (${
$id}) )
return "";
954 $march_id=
'e_march'.$this->counter.
'_price' ;
955 if ( ! isset (${$march_id}))
return '';
956 if ( ${$march_id} == 0)
return '';
958 if ($tva->load() == -1 )
return "";
959 $r=$tva->get_parameter(
'label');
967 $qt=
'e_quant'.$this->counter;
968 $price=
'e_march'.$this->counter.
'_price' ;
969 $tva=
'e_march'.$this->counter.
'_tva_id';
971 if ( !isset(${$tva}) )
return '';
972 if ( !isset (${
'e_march'.$this->counter}) )
return "";
974 if ( ${$price} == 0 || ${$qt} == 0
975 || strlen(
trim( $price )) ==0
976 || strlen(
trim($qt)) ==0)
978 $r=${
'e_march'.$this->counter.
'_tva_amount'};
984 $qt=
'e_quant'.$this->counter;
985 $price=
'e_march'.$this->counter.
'_price' ;
986 $tva=
'e_march'.$this->counter.
'_tva_id';
987 if ( !isset (${
'e_march'.$this->counter}) )
return "";
989 if ( ${$price} == 0 || ${$qt} == 0
990 || strlen(
trim( $price )) ==0
991 || strlen(
trim($qt)) ==0)
994 if ($oTva->load() == -1 )
return "";
995 $r=round(${$price},2)*$oTva->get_parameter(
'rate');
1001 $qt=
'e_quant'.$this->counter;
1002 $price=
'e_march'.$this->counter.
'_price' ;
1003 $tva=
'e_march'.$this->counter.
'_tva_id';
1004 if ( !isset (${
'e_march'.$this->counter}) )
return "";
1006 if ( ${$price} == 0 || ${$qt} == 0
1007 || strlen(
trim( $price )) ==0
1008 || strlen(
trim($qt)) ==0)
1010 if ( ! isset (${$tva}) )
return '';
1012 if ($tva->load() == -1 )
1014 $r=round(${$price},2);
1018 $r=round(${$price}*$tva->get_parameter(
'rate')+${$price},2);
1023 case 'VEN_ART_QUANT':
1025 $id=
'e_quant'.$this->counter;
1026 if ( !isset (${
$id}) )
return "";
1028 if ( ${
'e_march'.$this->counter.
'_price'} == 0
1029 || ${
'e_quant'.$this->counter} == 0
1030 || strlen(
trim( ${
'e_march'.$this->counter.
'_price'} )) ==0
1031 || strlen(
trim(${
'e_quant'.$this->counter})) ==0 )
1038 $id=
'e_march'.$this->counter.
'_price' ;
1039 $quant=
'e_quant'.$this->counter;
1040 if ( !isset (${
$id}) )
return "";
1043 if ( ${
'e_march'.$this->counter.
'_price'} == 0 || ${
'e_quant'.$this->counter} == 0
1044 || strlen(
trim( ${
'e_march'.$this->counter.
'_price'} )) ==0
1045 || strlen(
trim(${
'e_quant'.$this->counter})) ==0)
1048 $r=bcmul(${
$id},${$quant});
1054 $id=
'e_march'.$this->counter.
'_tva_amount' ;
1055 $price=
'e_march'.$this->counter.
'_price' ;
1056 $quant=
'e_quant'.$this->counter;
1057 if ( ! isset(${
'e_march'.$this->counter.
'_price'})|| !isset(${
'e_quant'.$this->counter}))
return "";
1059 if ( ${
'e_march'.$this->counter.
'_price'} == 0 || ${
'e_quant'.$this->counter} == 0 )
return "";
1062 if ( ! isset(${
$id}))
1063 $r= bcmul(${$price},${$quant});
1065 $r= bcmul(${$price},${$quant});
1066 $r=bcadd($r,${
$id});
1072 case 'TOTAL_VEN_HTVA':
1076 for ($i=0;$i<$nb_item;$i++)
1078 $sell=
'e_march'.$i.
'_price';
1081 if ( ! isset (${$sell}) )
break;
1083 if ( strlen(
trim(${$sell})) == 0 ||
1084 strlen(
trim(${$qt})) == 0 ||
1085 ${$qt}==0 || ${$sell}==0)
1087 $tmp1=bcmul(${$sell},${$qt});
1088 $sum=bcadd($sum,$tmp1);
1094 case 'TOTAL_VEN_TVAC':
1098 for ($i=0;$i<$nb_item;$i++)
1100 $tva=
'e_march'.$i.
'_tva_amount';
1103 if ( isset(${$tva}) )
1105 $tva_amount=${$tva};
1107 $sell=${
'e_march'.$i.
'_price'};
1108 $qt=${
'e_quant'.$i};
1109 $tot=bcmul($sell,$qt);
1111 $sum=bcadd($sum,
$tot);
1119 for ($i=0;$i<$nb_item;$i++)
1121 $tva=
'e_march'.$i.
'_tva_amount';
1122 if (! isset(${$tva})) $tva_amount=0.0;
1133 case 'BON_COMMANDE':
1146 if ( isset(
$p_array[
'other_info']))
1161 if ( ! isset (
$p_array[
'repo']))
return "";
1162 $ret=$this->
db->get_value(
'select r_name from public.stock_repository where r_id=$1',array(
$p_array[
'repo']));
1164 case 'STOCK_ADRESS':
1165 if ( ! isset (
$p_array[
'repo']))
return "";
1166 $ret=$this->
db->get_value(
'select r_adress from public.stock_repository where r_id=$1',array(
$p_array[
'repo']));
1168 case 'STOCK_COUNTRY':
1169 if ( ! isset (
$p_array[
'repo']))
return "";
1170 $ret=$this->
db->get_value(
'select r_country from public.stock_repository where r_id=$1',array(
$p_array[
'repo']));
1173 if ( ! isset (
$p_array[
'repo']))
return "";
1174 $ret=$this->
db->get_value(
'select r_city from public.stock_repository where r_id=$1',array(
$p_array[
'repo']));
1177 if ( ! isset (
$p_array[
'repo']))
return "";
1178 $ret=$this->
db->get_value(
'select r_phone from public.stock_repository where r_id=$1',array(
$p_array[
'repo']));
1183 case 'COMM_PAYMENT':
1184 if ( isset(
$p_array[
"e_comm_paiement"])) {
1185 return $p_array[
"e_comm_paiement"];
1191 if (preg_match(
'/^ATTR/', $p_tag) == 1)
1195 if ( isset (
$p_array[
'e_march'.$this->counter]))
1204 if (preg_match(
'/^BENEFATTR/', $p_tag) == 1)
1211 if (preg_match(
'/^CUSTATTR/', $p_tag) == 1)
1227 $d_lob=$this->
db->get_value(
'select d_lob from document where d_id=$1',
1228 array($this->d_id));
1229 $sql=
'delete from document where d_id='.$this->d_id;
1230 $this->
db->exec_sql(
$sql);
1242 $sql=
"update jrn set jr_pj=$1,jr_pj_name=$2,jr_pj_type=$3 where jr_internal=$4";
1244 $this->
db->exec_sql(
$sql,array($this->d_lob,$this->d_filename,$this->d_mimetype,$p_internal));
1246 $sql=
'delete from document where d_id='.$this->d_id;
1247 $this->
db->exec_sql(
$sql);
1266 $found =
$f->get_by_qcode($p_qcode,
false);
1272 $attr=preg_replace(
"/^.*ATTR/",
"",$p_tag);
1274 if (
isNumber($attr) == 0)
return "";
1275 $ad_type=$this->
db->get_value(
"select ad_type from attr_def where ad_id=$1",array($attr));
1278 $ad_value=$this->
db->get_value(
"select ad_value from fiche_detail where f_id=$1 and ad_id=$2",array(
$f->id,$attr));
1281 if ( $ad_type==
"select")
1283 $sql=$this->
db->get_value(
"select ad_extra from attr_def where ad_id=$1",array($attr));
1287 if (
$array[
$a][
'value']==$ad_value)
1297 $this->
db->exec_sql(
'update document set d_description = $1 where d_id=$2',
1298 array($p_desc,$this->d_id));
update_description($p_desc)
Generate($p_array, $p_filename="")
Generate the document, Call $this->Replace to replace tag by value.
static num_row($ret)
wrapper for the function pg_NumRows
Class Document corresponds to the table document.
blank()
insert a minimal document and set the d_id
Manage the account from the table jrn, jrnx or tmp_pcmn.
format_date($p_date, $p_from_format= 'YYYY-MM-DD', $p_to_format='DD.MM.YYYY')
format the date, when taken from the database the format is MM-DD-YYYY
Replace($p_tag, $p_array)
replace the TAG by the real value, this value can be into the database or in $_POST The possible tags...
ParseDocument($p_dir, $p_file, $p_type, $p_array)
This function parse a document and replace all the predefined tags by a value. This functions generat...
if($_GET['clear']==1) $tag
Acc_Tva is used for to map the table tva_rate parameter are.
replace_special_tag($p_qcode, $p_tag)
Replace a special tag *TAGxxxx with the value from fiche_detail, the xxxx is the ad_value.
static fetch_array($ret, $p_indice=0)
wrapper for the function pg_fetch_array
class_action for manipulating actions action can be :
if(!isset($_REQUEST['act'])||!isset($_REQUEST['jr_id'])||!isset($_REQUEST['div'])) global $g_parameter
static insert_existing_document($p_ag_id, $p_lob, $p_filename, $p_mimetype, $p_description="")
Copy a existing OID (LOB) into the table document.
MoveDocumentPj($p_internal)
Move a document from the table document into the concerned row the document is not copied : it is onl...
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
get_all($ag_id)
get all the document of a given action
function trim(s)
remove trailing and heading space
static id()
return the $_REQUEST['gDossier'] after a check
anchor()
create and compute a string for reference the doc <A ...>
__construct($p_cn, $p_d_id=0)
Upload($p_ag_id)
Upload a file into document all the needed data are in $_FILES we don't increment the seq...
SaveGenerated($p_file)
Save the generated Document.
echo_warning($p_string)
warns
compute_filename($pj, $filename)
Insert the receipt number into the filename , each generated file will have the name of the template ...
const ATTR_DEF_NUMBER_CUSTOMER