noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
Acc_Document Class Reference

Document used in accountancy : invoice , credit note, ... It is a specialization of Document used in Follow-UP. More...

+ Inheritance diagram for Acc_Document:
+ Collaboration diagram for Acc_Document:

Public Member Functions

 __construct ($cn, $jr_id=0)
 constructor
 
 create_document ($internal, $p_array)
 create the invoice and saved it as attachment to the operation,
 
 export_file ($destination_file)
 export the file to the file system and complet $this->d_mimetype, d_filename and
 
 get_document_xml ()
 
 link_download_xml ()
 return a string with a link download XML or an empty string if there is no XML to download
 
 replace_receipt ($new_oid)
 for FACTURX we replace the PDF save in DB by this one, always a PDF (since it is a FACTURX document)
 
 save_receipt ()
 Save a "piece justificative" , the name must be a receipt.
 
 set_document_xml ($document_xml)
 
 set_id ($jr_id)
 set_id fill up d_filename, d_mimetype,d_lob,d_description,jr_pj_number
 
 update ($filename)
 save the file into DB, will create a large object if there is no document to replace.
 
 update_document_xml ($oid)
 save the Large Object $oid in the column JRN.JR_DOCUMENT_XML
 
- Public Member Functions inherited from Document
 __toString ()
 
 anchor ()
 create and compute a string for reference the doc <A ...>
 
 blank ()
 insert a minimal document and set the d_id
 
 compute_filename ($pj, $filename)
 Insert the receipt number into the filename , each generated file will have the name of the template (model) + receipt number)
 
 download ($aDocument)
 Download all documents in a ZIP files.
 
 get ()
 Get complete all the data member thx info from the database.
 
 get_all ($ag_id)
 get all the document of a given action
 
 parseDocument ($p_dir, $p_file, $p_type, $p_array)
 This function parse a document and replace all the predefined tags by a value.
 
 remove ()
 remove a row from the table document, the lob object is not deleted because can be linked elsewhere
 
 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 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
 
 send ()
 send the document
 
 transform2pdf ()
 transform the current Document to a PDF, returns the full path of the PDF from the TMP folder if the file IS a pdf , then export it and return the path to the file.
 
 update_description ($p_desc)
 
 upload ($p_ag_id)
 upload a file into document all the needed data are in $_FILES we don't increment the seq $_FILES : array containing by default $_FILES
 

Static Public Member Functions

static display_supplementary_doc ($cn, $div, $jr_id)
 
- Static Public Member Functions inherited from Document
static insert_existing_document ($p_ag_id, $p_lob, $p_filename, $p_mimetype, $p_description="")
 Copy a existing OID (LOB) into the table document.
 
static replace_value ($p_buffer, $p_pattern, $p_value, $p_limit=-1, $p_type='OOo')
 replace a pattern with a value in the buffer , handle the change for OOo type file and amount
 

Protected Member Functions

 saveGenerated ($p_file)
 insert the generated Document into the database, update the $this->d_id that is the PK of document. and load the PDF into the database.
 

Private Attributes

 $document_xml
 $document_xml (oid) XML document e-invoice
 

Additional Inherited Members

- Data Fields inherited from Document
 $ag_id
 
 $d_description
 
 $d_filename
 
 $d_id
 
 $d_lob
 
 $d_mimetype
 
 $d_name
 
 $d_number
 
 $db
 
 $f_id
 
 $md_id
 
 $md_type
 
- Protected Attributes inherited from Document
 $counter
 

Detailed Description

Document used in accountancy : invoice , credit note, ... It is a specialization of Document used in Follow-UP.

property :

  • d_id JRN.JR_ID
  • d_name name Receipt number
  • d_description Comment of the operation
  • d_mimetype mimetype of the document JRN.JR_PJ_TYPE
  • d_filename filename JRN.JR_PJ_NAME
  • document_xml oid of the XML invoice (including PDF) JRN.JR_DOCUMENT_XML
  • d_lob = JRN.JR_PJ

Definition at line 43 of file acc_document.class.php.

Constructor & Destructor Documentation

◆ __construct()

Acc_Document::__construct ( $cn,
$jr_id = 0 )

constructor

Parameters
$cn\Database
$jr_id(int) JRN.JRID will be in d_id

Reimplemented from Document.

Definition at line 85 of file acc_document.class.php.

86 {
87 $this->db=$cn;
88 $this->set_id($jr_id);
89 // counter for MARCH_NEXT
90 $this->counter=0;
91
92 }
$jr_id
set_id($jr_id)
set_id fill up d_filename, d_mimetype,d_lob,d_description,jr_pj_number
$SecUser db

References $cn, $jr_id, db, and set_id().

+ Here is the call graph for this function:

Member Function Documentation

◆ create_document()

Acc_Document::create_document ( $internal,
$p_array )

create the invoice and saved it as attachment to the operation,

Parameters
$p_arrayis normally the $_POST
 Array
 (
 [ledger_type] => VEN
 [gDossier] => x
 [nb_item] => 1 (number of item used to numerate e_marchX, e_quantX ,...)
 [p_jrn] => 2
 [p_jrn_predef] => 2
 [jrn_type] => VEN or ACH
 [e_date] => 10.06.2025 (date)
 [e_ech] => limite date
 [e_client] => CLIENT
 [e_pj] => 25.827
 [e_pj_suggest] => 25.827
 [e_comm] => E-INVOICE
 [p_currency_code] => 0
 [p_currency_rate] => 1 (rate if 1 for EURO)
 [jrn_note_input] =>
 [e_march0] => 7DVINV
 [e_march0_label] => Label of the operation
 [e_march0_price] => 10.0000
 [e_quant0] => 1.0000
 [htva_march0] => 10
 [e_march0_tva_id] => 1
 [e_march0_tva_amount] => 2.1
 [tva_march0] => 2.1
 [tvac_march0] => 12.1
 ...
 [mp_date] => (dd.mm.yyyy date of payment)
 [acompte] => 0 (amount to deduce as    advance payment)
 [e_comm_paiement] => (string : comment of the payment)
 [e_mp] => 0 (method of payment it is the XX in e_mp_qcode_XX)
 [e_mp_qcode_16] => Banque 1
 [e_mp_qcode_17] => Banque 2
 [view_invoice] => Enregistrer
 [gen_doc] => int DOCUMENT_MODELE.MD_ID , document template to use
 )
* 
Todo
rewrite code : remove extract and +SQL value
Returns
void

Definition at line 231 of file acc_document.class.php.

231 {
232 $this->f_id = $p_array['e_client'];
233 // var md_id (int) DOCUMENT_MODELE.MD_ID
234 $this->md_id = $p_array['gen_doc'];
235 // var ag_id == 0 fake follow-up
236 $this->ag_id = 0;
237 // var e_pj (string) receipt nb
238 $p_array['e_pj'] = $this->db->get_value("select jr_pj_number from jrn where jr_id=$1"
239 , [$this->d_id]);
240
241 // $filename (string) compute filename based on the template
242 $filename=$this->db->get_value ("select md_filename from document_modele where md_id=$1",
243 [$this->md_id]);
244 $filename = $p_array['e_pj']."-".$filename;
245 // generate the document and set d_lob,d_mimetype,
246 // this function will call saveGenerated and save in DB
247 $this->generate($p_array, $filename);
248
249 // Update the comment with invoice number, if the comment is empty
250 if (!isset($p_array['e_comm']) || noalyss_strlentrim($p_array['e_comm']) == 0) {
251 $sql = "update jrn set jr_comment=' document " . $this->d_number . "' where jr_internal=$1";
252 $this->db->exec_sql($sql, [$internal]);
253 }
254 }
noalyss_strlentrim($p_string)

References $p_array, $sql, ag_id, db, and noalyss_strlentrim().

+ Here is the call graph for this function:

◆ display_supplementary_doc()

static Acc_Document::display_supplementary_doc ( $cn,
$div,
$jr_id )
static

Definition at line 416 of file acc_document.class.php.

417 {
418 $gDossier=\Dossier::id();
419 $q=new Jrn_Sup_Document_SQL($cn);
420 $a_row=$q->collect_objects(" where jr_id=$1 order by js_cbc_id", [$jr_id]);
421
422 if ( count($a_row) > 0)
423 {
424 foreach ($a_row as $item) {
425 $export="export.php?";
426 $script="Supplement_Document.delete_document('$gDossier','$div','{$item->js_id}','$jr_id')";
427 $rowid=sprintf("row_js_%s_%s",$div,$item->js_id);
428 // @var $download (url) to send file
429 $download="export.php?". http_build_query(
430 [
431 "act"=>"RAW:suppl-document"
432 ,"js_id"=>$item->js_id
433 ,"gDossier"=>$gDossier
434 ]);
435 ?>
436 <div class="row" id="<?=$rowid?>">
437 <div class="col">
438 <a href="<?=$download?>" download> <?=$item->js_filename?></a>
439 </div>
440 <div class="col">
441 <?=$item->js_description?>
442 </div>
443 <div class="col">
444 <?=\Icon_Action::trash(uniqid("sdd"),$script)?>
445 </div>
446 </div>
447 <?php
448 }// end foreach $a_row
449 }// end if count
450 //download ALL files from this operation
451
452
453 }
download($aDocument)
Download all documents in a ZIP files.
$script
Definition popup.php:131

References $a_row, $cn, $div, $export, $gDossier, $jr_id, $q, $script, Document\download(), and Icon_Action\trash().

+ Here is the call graph for this function:

◆ export_file()

Acc_Document::export_file ( $destination_file)

export the file to the file system and complet $this->d_mimetype, d_filename and

Parameters
$destination_file(string) full path to document
Returns
bool false for failure and string (the full path_name) for success

Reimplemented from Document.

Definition at line 261 of file acc_document.class.php.

261 {
262
263 if (empty($this->d_filename)) {
264 return false;
265 }
266
267 $this->db->start();
268 if ($this->db->lo_export($this->d_lob, $destination_file) == false) {
269 record_log("ACD122. cannot export");
270 $this->db->commit();
271 return false;
272 }
273 $this->db->commit();
274
275 return $destination_file;
276 }
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...

References db, and record_log().

+ Here is the call graph for this function:

◆ get_document_xml()

Acc_Document::get_document_xml ( )

Definition at line 46 of file acc_document.class.php.

46 {
48 }
$document_xml
$document_xml (oid) XML document e-invoice

References $document_xml.

◆ link_download_xml()

Acc_Document::link_download_xml ( )

return a string with a link download XML or an empty string if there is no XML to download

Definition at line 398 of file acc_document.class.php.

398 :string
399 {
400 $xml_oid=$this->db->get_value("select jr_document_xml from jrn where jr_id=$1",
401 [$this->d_id]);
402 if ($xml_oid == "") { return "";}
403 $url= "export.php?".http_build_query(
404 [
405 "gDossier"=>\Dossier::id(),
406 "jr_id"=>$this->d_id,
407 "act"=>'RAW:xml-invoice'
408 ]);
409 $r = sprintf('<a class="mtitle line" href="%s">',$url);
410 $r .= _("XML")
411 .'<i class="icon-download">'
412 .'</i>'
413 .'</a>';
414 return $r;
415 }
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
_("actif, passif,charge,...")

References $r, $url, _, and db.

◆ replace_receipt()

Acc_Document::replace_receipt ( $new_oid)

for FACTURX we replace the PDF save in DB by this one, always a PDF (since it is a FACTURX document)

Definition at line 152 of file acc_document.class.php.

153 {
154 if ($this->d_lob != "")
155 {
156 $this->db->lo_unlink($this->d_lob);
157 }
158 $this->d_lob=$new_oid;
159 $this->db->exec_sql("
160 update jrn
161 set
162 jr_pj = $1
163 ,jr_pj_name =$2
164 ,jr_pj_type =$3
165 where jr_id=$4
166 ",
167 [$this->d_lob
168 ,$this->d_filename
169 ,$this->d_mimetype
170 ,$this->d_id]
171 );
172
173 }

References db.

◆ save_receipt()

Acc_Document::save_receipt ( )

Save a "piece justificative" , the name must be a receipt.

If it is a XML document, split it into 2 parts : PDF and XML the PDF be stored in JR_PJ and the XML into JR_DOCUMENT_XML

Returns
$oid of the lob file if success null if a error occurs

pj is the $_FILES key

Definition at line 286 of file acc_document.class.php.

287 {
288 $this->db->start();
289 /**
290 * pj is the $_FILES key
291 */
292 if ( $_FILES['pj']['name']=="") {
293 return false;
294 }
295 $a_file= $this->db->upload('pj',only_oid:false);
296 if ($a_file == false) {
297 return false;
298 }
299 $oid=$a_file['oid'];
300 // Remove old document if any
301 $old_oid = $this->db->get_value("select jr_pj from jrn where jr_id=$1"
302 ,[$this->d_id]);
303
304 if ( $old_oid != "")
305 {
306 $this->db->lo_unlink( $old_oid);
307 }
308
309 // if there is a e-invoice in XML
310 if ( $_FILES['pj']['type'] == 'text/xml'
311 || $_FILES['pj']['type'] == 'application/xml'
312 )
313 {
314 // save the XML
315 $this->db->exec_sql("update jrn set jr_document_xml = $1
316 where
317 jr_id=$2",
318 [$oid,$this->d_id]);
319
320 $xmlreader= \Noalyss\XMLDocument\XML_Reader::build_from_file($a_file['filename']);
321
322 //@var $embedded_file (array) keys = filecontent: binary data
323 //,mimecode mimetype and filename (string)
324 try
325 {
326
327 // create a PDF with standard information
328 $pdf=$xmlreader->to_pdf();
329 $file_oid=$this->db->lo_write($pdf->Output("S"));
330
331 //@var $file_oid OID of the large object saved in DB
332 $this->d_name="invoice.pdf";
333 $this->d_description="Auto generated invoice";
334 $this->d_lob=$file_oid;
335 $this->d_mimetype="application/pdf";
336
337 // save extracted document into DB
338 $this->db->exec_sql("update jrn set jr_pj=$1 , jr_pj_name=$2,
339 jr_pj_type=$3 where jr_id=$4",
340 array(
341 $this->d_lob
342 , $this->d_name
343 , $this->d_description
344 , $this->d_id
345 )
346 );
347 // save all the documents into the DB
348 // @var embedded_file (array of Noalyss\XML\Document_Reference)
349 $embedded_file=$xmlreader->get_embedded_document();
350 $nb_file = count($embedded_file);
351 for ($i=0;$i <$nb_file ; $i++)
352 {
353 // other documents save in jrn_sup_document
354 // @var $file (Binary File from XML)
355 $binary=$embedded_file[$i]->getBinary_object();
356
357 //@var $sup_oid : oid of the supplemental
358 $sup_oid=$this->db->lo_write($binary->filecontent);
359
360 $jrn_sup_document=new Jrn_Sup_Document_SQL($this->db);
361 $jrn_sup_document->jr_id=$this->d_id;
362 $jrn_sup_document->js_mimetype=$binary->mimecode;
363 $jrn_sup_document->js_filename=$binary->filename;
364 $jrn_sup_document->js_lob=$sup_oid;
365 $jrn_sup_document->js_description=$embedded_file[$i]->getDescription();
366 $jrn_sup_document->js_cbc_id=$embedded_file[$i]->getId();
367 $jrn_sup_document->save();
368 }
369
370 } catch (\Exception $e ) {
371 \record_log($e);
372 throw new \Exception("X281 ",281,$e);
373 }
374 } else {
375 $this->d_lob=$oid;
376 $this->d_name=$_FILES['pj']['name'];
377 $this->d_description=$_FILES['pj']['type'];
378
379 // save extracted document into DB
380 $this->db->exec_sql("update jrn set jr_pj=$1 , jr_pj_name=$2,
381 jr_pj_type=$3 where jr_id=$4",
382 array(
383 $this->d_lob
384 , $this->d_name
385 , $this->d_description
386 , $this->d_id
387 )
388 );
389 }
390 $this->db->commit();
391
392 return $oid;
393 }

References Document\$d_id, $e, $i, $pdf, db, and record_log().

+ Here is the call graph for this function:

◆ saveGenerated()

Acc_Document::saveGenerated ( $p_file)
protected

insert the generated Document into the database, update the $this->d_id that is the PK of document. and load the PDF into the database.

Parameters
$p_fileis the generated file (full path)
Returns
0 if no error otherwise 1

Reimplemented from Document.

Definition at line 60 of file acc_document.class.php.

61 {
62
63 $this->db->start();
64 $this->d_filename= basename($p_file);
65 $this->d_mimetype= mime_content_type($p_file);
66 $this->d_lob=$this->db->lo_import($p_file);
67 if ($this->d_lob==false)
68 {
69 echo "ne peut pas importer [$p_file]";
70 return 1;
71 }
72 $sql="update jrn set jr_pj=$1,jr_pj_name=$2,jr_pj_type=$3 where jr_id=$4 returning jr_id";
73 $id=$this->db->get_value($sql, array($this->d_lob, $this->d_filename, $this->d_mimetype, $this->d_id));
74 $this->db->commit();
75 if ( $id == "") {
76 throw new Exception("AD99 FILE NOT SAVED INTO DB",99);
77 }
78
79 }

References $id, $sql, and db.

◆ set_document_xml()

Acc_Document::set_document_xml ( $document_xml)

Definition at line 50 of file acc_document.class.php.

50 {
51 $this->document_xml = $document_xml;
52 return $this;
53 }

References $document_xml.

◆ set_id()

Acc_Document::set_id ( $jr_id)

set_id fill up d_filename, d_mimetype,d_lob,d_description,jr_pj_number

Definition at line 96 of file acc_document.class.php.

96 {
97 $this->d_id=$jr_id;
98 if ( $jr_id == 0 ){
99 return $this;
100 }
101 $row = $this->db->get_row("select jr_comment
102 ,jr_pj
103 ,jr_pj_name
104 ,jr_pj_type
105 ,jr_pj_number
106 ,jr_document_xml
107 from jrn
108 where
109 jr_id=$1", [$this->d_id]);
110 if ( empty ($row)) {
111 return $this;
112 }
113 $this->d_name=$row['jr_pj_number'];
114 $this->d_description=$row['jr_comment'];
115 $this->d_mimetype=$row['jr_pj_type'];
116 $this->d_filename=$row['jr_pj_name'];
117 $this->d_lob=$row['jr_pj'];
118 $this->document_xml=$row['jr_document_xml'];
119 return $this;
120 }

References $jr_id, $row, and db.

Referenced by __construct().

◆ update()

Acc_Document::update ( $filename)

save the file into DB, will create a large object if there is no document to replace.

It will change the d_filename, d_mimetype

Parameters
$d_filename(string) full path to the file to load into DB
Returns
false if d_id = 0 or the file doesn't exist, true for success

Definition at line 129 of file acc_document.class.php.

129 {
130 if ($this->d_id == 0) return false;
131 if ( ! file_exists($filename)) return false;
132 $this->db->start();
133 $this->d_mimetype= mime_content_type($filename);
134 $this->d_filename= basename($filename);
135 if ( $this->d_lob == "") {
136 $this->db->lo_unlink($this->d_lob);
137 }
138
139 $this->d_lob=$this->db->lo_import($filename);
140 $this->db->exec_sql(
141 "update jrn set jr_pj=$1,jr_pj_name=$2,jr_pj_type=$3
142 where jr_id=$4",
143 [$this->d_lob,$this->d_filename,$this->d_mimetype,$this->d_id]
144 );
145 $this->db->commit();
146 return true;
147 }

References db.

◆ update_document_xml()

Acc_Document::update_document_xml ( $oid)

save the Large Object $oid in the column JRN.JR_DOCUMENT_XML

Parameters
$oid(OID) PostgreSQL Object ID

Definition at line 178 of file acc_document.class.php.

178 {
179 $this->db->exec_sql("update jrn set jr_document_xml=$1 where
180 jr_id=$2",[
181 $oid,
182 $this->d_id
183 ]);
184
185 }

References db.

Field Documentation

◆ $document_xml

Acc_Document::$document_xml
private

$document_xml (oid) XML document e-invoice

Definition at line 44 of file acc_document.class.php.

Referenced by get_document_xml(), and set_document_xml().


The documentation for this class was generated from the following file: