diff --git a/include/ajax/ajax_ledger.php b/include/ajax/ajax_ledger.php index 056088938..478436e13 100644 --- a/include/ajax/ajax_ledger.php +++ b/include/ajax/ajax_ledger.php @@ -256,6 +256,11 @@ switch ($action) { $filename = mb_substr($obj->det->jr_pj_name, 0, 60); } echo HtmlInput::show_receipt_document($jr_id, h($filename)); + // if using the XML Belgian format, add a tab for showing it + $acc_document=new Acc_Document($cn,$jr_id); + echo ''. + $acc_document->link_download_xml() + .''; echo $x; echo '
'; echo ''; @@ -268,9 +273,8 @@ switch ($action) { case 'loadfile': if ($access == 'W' && isset ($_FILES)) { $cn->start(); - // remove the file - $grpt = $cn->get_value('select jr_grpt_id from jrn where jr_id=$1', array($jr_id)); - $cn->save_receipt($grpt); + $acc_document=new \Acc_Document($cn,$jr_id); + $acc_document->save_receipt(); $cn->commit(); // Show a link to the new file $op->get(); diff --git a/include/class/acc_document.class.php b/include/class/acc_document.class.php index f2c4ff03b..167a3f830 100644 --- a/include/class/acc_document.class.php +++ b/include/class/acc_document.class.php @@ -221,5 +221,79 @@ class Acc_Document extends Document { return $destination_file; } + /** + * \brief 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 + * + * + * \return $oid of the lob file if success null if a error occurs + * + */ + function save_receipt() + { + $this->db->start(); + /** + * pj is the $_FILES key + */ + $oid = $this->db->upload('pj'); + if ($oid == false) { + return false; + } + // Remove old document if any + $old_oid = $this->db->get_value("select jr_pj from jrn where jr_id=$1" + ,[$this->d_id]); + + if ( $old_oid != "") + { + $this->lo_unlink( $old_oid); + } + // save new document + $this->db->exec_sql("update jrn set jr_pj=$1 , jr_pj_name=$2, + jr_pj_type=$3 where jr_id=$4", + array( + $oid + , $_FILES['pj']['name'] + , $_FILES['pj']['type'] + , $this->d_id + ) + ); + $this->db->commit(); + // if there is a e-invoice in XML +// if ( $_FILES['pj']['type'] == 'text/xml' +// || $_FILES['pj']['type'] == 'application/xml' +// ) +// { +// $xmlreader= Noalyss\XMLDocument\XMLInvoice_Reader::build_from_file($_FILES['pj']['tmp_name']); +// // $xmlreader->save_xml +// } + $this->d_name=$_FILES['pj']['name']; + $this->d_description=$_FILES['pj']['name']; + $this->d_lob=$oid; + $this->d_mimetype=$_FILES['pj']['type']; + return $oid; + } + /** + * @brief return a string with a link download XML or an empty string + * if there is no XML to download + */ + function link_download_xml():string + { + $xml_oid=$this->db->get_value("select jr_document_xml from jrn where jr_id=$1", + [$this->d_id]); + if ($xml_oid == "") { return "";} + $url= "export.php?".http_build_query( + [ + "gDossier"=>\Dossier::id(), + "jr_id"=>$this->d_id, + "act"=>'RAW:xml-invoice' + ]); + $r = sprintf('',$url); + $r .= _("XML") + .'' + .'' + .''; + return $r; + } } \ No newline at end of file diff --git a/include/class/acc_ledger.class.php b/include/class/acc_ledger.class.php index ef68df361..12e6e336d 100644 --- a/include/class/acc_ledger.class.php +++ b/include/class/acc_ledger.class.php @@ -1610,6 +1610,7 @@ class Acc_Ledger extends jrn_def_sql $acc_end->currency_rate=$currency_rate; $acc_end->currency_rate_ref=$currency_rate_ref->get_rate(); + // @var $jr_id (int) JRN.JR_ID $jr_id=$acc_end->insert_jrn(); $this->jr_id=$jr_id; @@ -1651,7 +1652,8 @@ class Acc_Ledger extends jrn_def_sql */ if (isset($_FILES["pj"])) { - $this->db->save_receipt($seq); + $acc_document=new Acc_Document($this->db, $jr_id); + $acc_document->save_receipt(); } /*---------------------------------------------- * Save the note diff --git a/include/class/acc_ledger_fin.class.php b/include/class/acc_ledger_fin.class.php index 0f7ce0b88..b5a9a8cee 100644 --- a/include/class/acc_ledger_fin.class.php +++ b/include/class/acc_ledger_fin.class.php @@ -983,6 +983,7 @@ class Acc_Ledger_Fin extends Acc_Ledger throw new Exception (_("Erreur de balance"),EXC_BALANCE); // $acc_operation->update_receipt(); + $this->jr_id=&$jr_id; $this->db->exec_sql('update jrn set jr_pj_number=$1 where jr_id=$2', array($acc_operation->pj, $jr_id)); $internal=$this->compute_internal_code($seq); @@ -1073,21 +1074,18 @@ class Acc_Ledger_Fin extends Acc_Ledger $class=($i%2==0)?' class="even" ':' class="odd" '; $ret.=tr($row, $class); - if ($i==0) + if ($i==0 && isset($_FILES['pj']) ) { // first record we upload the files and // keep variable to update other row of jrn - if (isset($_FILES['pj'])) - $oid=$this->db->save_receipt($seq); + $acc_document=new Acc_Document($this->db,$jr_id); + $oid=$acc_document->save_receipt(); } - else + elseif ($oid != 0 ) { - if ($oid!=0) - { - $this->db->exec_sql("update jrn set jr_pj=$1 , jr_pj_name=$2, - jr_pj_type=$3 where jr_grpt_id=$4", - array($oid, $_FILES['pj']['name'], $_FILES['pj']['type'], $seq)); - } + $this->db->exec_sql("update jrn set jr_pj=$1 , jr_pj_name=$2, + jr_pj_type=$3 where jr_grpt_id=$4", + array($oid, $_FILES['pj']['name'], $_FILES['pj']['type'], $seq)); } } // for nbitem // increment pj diff --git a/include/class/acc_ledger_purchase.class.php b/include/class/acc_ledger_purchase.class.php index 736e3da61..089301c39 100644 --- a/include/class/acc_ledger_purchase.class.php +++ b/include/class/acc_ledger_purchase.class.php @@ -1055,7 +1055,9 @@ class Acc_Ledger_Purchase extends Acc_Ledger if ( isset ($_FILES)) { if ( sizeof($_FILES) != 0 ) - $this->db->save_receipt($seq); + $acc_document=new \Acc_Document($this->db, $this->jr_id); + $acc_document->save_receipt(); + $this->doc=HtmlInput::show_receipt_document($this->jr_id,h($_FILES['pj']['name'])); } $str_file=""; /* Generate an document and save it into the database (Note de frais only) diff --git a/include/class/database.class.php b/include/class/database.class.php index 6ecc504b3..22e4009eb 100644 --- a/include/class/database.class.php +++ b/include/class/database.class.php @@ -81,44 +81,6 @@ class Database extends DatabaseCore . ",dbname = ".$this->get_dbname() . "]"; } - /*** - * \brief Save a "piece justificative" , the name must be a receipt - * - * \param $seq jr_grpt_id - * \return $oid of the lob file if success - * null if a error occurs - * - */ - function save_receipt($seq) - { - /** - * pj is the $_FILES key - */ - $oid = $this->upload('pj'); - if ($oid == false) { - return false; - } - // Remove old document - $ret = $this->exec_sql("select jr_pj from jrn where jr_grpt_id=$1" - ,[$seq]); - if (pg_num_rows($ret) != 0) { - $r = pg_fetch_array($ret, 0); - $old_oid = $r['jr_pj']; - if (strlen($old_oid??"") != 0) - $this->lo_unlink( $old_oid); - } - // Load new document - $this->exec_sql("update jrn set jr_pj=$1 , jr_pj_name=$2, - jr_pj_type=$3 where jr_grpt_id=$4", - array($oid, $_FILES['pj']['name'], $_FILES['pj']['type'], $seq)); - if ( $_FILES['pj']['type'] == 'text/xml' - || $_FILES['pj']['type'] == 'application/xml' - ) - { - - } - return $oid; - } /** * \brief Get version of a database, the content of the diff --git a/include/class/operation_exercice.class.php b/include/class/operation_exercice.class.php index 9a5831ce6..7867f5d00 100644 --- a/include/class/operation_exercice.class.php +++ b/include/class/operation_exercice.class.php @@ -227,10 +227,10 @@ select sum(signed_amount) delta,sum(debit) debit,sum(credit) credit from saldo_d $ledger->save($oe_data); $oe_result=_("Détail opération"); $oe_result.=sprintf('%s