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
', - $ledger->jr_id, dossier::id(), $ledger->internal); + $ledger->jr_id, dossier::id(), $ledger->jr_internal); $cn->exec_sql("update operation_exercice set oe_transfer_date=to_timestamp($1,'DD.MM.YY HH24:MI') , jr_internal=$2 where oe_id=$3", - [date('d.m.Y H:i'),$ledger->internal,$this->operation_exercice_sql->oe_id]); + [date('d.m.Y H:i'),$ledger->jr_internal,$this->operation_exercice_sql->oe_id]); $cn->commit(); return true; diff --git a/include/compta_ods.inc.php b/include/compta_ods.inc.php index a749e448b..b4468737d 100644 --- a/include/compta_ods.inc.php +++ b/include/compta_ods.inc.php @@ -92,7 +92,7 @@ if (!isset($_POST['summary']) && !isset($_POST['save'])) { echo _("Détail opération"); echo " "; printf('%s
', - $jr_id, dossier::id(), $ledger->internal); + $jr_id, dossier::id(), $ledger->jr_internal); echo ''; // show feedback diff --git a/include/compta_ven.inc.php b/include/compta_ven.inc.php index cd1d4136e..f1634df06 100644 --- a/include/compta_ven.inc.php +++ b/include/compta_ven.inc.php @@ -33,7 +33,8 @@ $http=new HttpInput(); $strac=$http->request('ac'); $ac="ac=".$strac; $p_msg=""; -$post_jrn=$http->post("p_jrn", "string",""); +//@var $post_jrn (int) Ledger id JRN_DEF.JRN_DEF_ID +$post_jrn=$http->post("p_jrn", "number",""); //---------------------------------------------------------------------- // Encode a new invoice // empty form for encoding @@ -143,7 +144,7 @@ if ( isset($_POST['record']) ) else echo '
'; - $Ledger=new Acc_Ledger_Sale($cn,$_POST['p_jrn']); + $Ledger=new Acc_Ledger_Sale($cn,$post_jrn); try { $internal=$Ledger->insert($_POST); @@ -164,8 +165,11 @@ if ( isset($_POST['record']) ) $flag_invoice=0; /* Save the attachment or generate doc */ if (isset($_FILES['pj']) && noalyss_strlentrim($_FILES['pj']['name']) != 0) - { - $cn->save_receipt($seq); + { + $acc_document=new Acc_Document($cn,$Ledger->jr_id); + $acc_document->save_receipt(); + $receipt= HtmlInput::show_receipt_document($Ledger->jr_id + ,h($_FILES['pj']['name'])); } else /* Generate an invoice and save it into the database */ @@ -232,8 +236,8 @@ if ( isset($_POST['record']) ) } $acc_document->update_document_xml($oid); - $receipt= HtmlInput::show_receipt_document($Ledger->jr_id,$acc_document->d_filename); - + $receipt= HtmlInput::show_receipt_document($Ledger->jr_id,$acc_document->d_filename) + . $acc_document->link_download_xml(); } } diff --git a/include/constant.php b/include/constant.php index c5c41f252..bb1a6014a 100644 --- a/include/constant.php +++ b/include/constant.php @@ -432,7 +432,8 @@ function noalyss_class_autoloader($class) 'noalyss\xmldocument\facturx'=>'XMLDocument/FacturX.php', 'noalyss\xmldocument\invoiceubl21'=>'XMLDocument/InvoiceUBL21.php', 'noalyss\xmldocument\error_message'=>'XMLDocument/Error_Message.php', - "noalyss\invoice_pdf"=>"class/invoice_pdf.class.php" + "noalyss\invoice_pdf"=>"class/invoice_pdf.class.php", + 'noalyss\xmldocument\xmlinvoice_reader'=>'XMLDocument/xmlinvoice_reader.class.php' ); if (isset ($aClass[$class])) { require_once NOALYSS_INCLUDE . "/" . $aClass[$class]; diff --git a/include/lib/database_core.class.php b/include/lib/database_core.class.php index 12f328d95..a04706c04 100644 --- a/include/lib/database_core.class.php +++ b/include/lib/database_core.class.php @@ -760,6 +760,7 @@ class DatabaseCore $this->rollback(); return false; } + if ( $a == 1 ) { $this->commit(); } return $oid; } else { \record_log("DC754: move_uploaded fails".var_export($_FILES, true)); @@ -769,7 +770,7 @@ class DatabaseCore } \record_log("DC576: Files error names empty".var_export($_FILES, true)); - if ( $a==1) { $this->commit(); } + if ( $a == 1) { $this->commit(); } return false; } /** diff --git a/include/template/ledger_detail_bottom.php b/include/template/ledger_detail_bottom.php index afd7307d8..cdea88b46 100644 --- a/include/template/ledger_detail_bottom.php +++ b/include/template/ledger_detail_bottom.php @@ -46,17 +46,7 @@ $a_tab['linked_action_div']=array('id'=>'linked_action_div'.$div,'label'=>_('Act $a_tab['analytic_div']=array('id'=>'analytic_div'.$div,'label'=>_('Comptabilité Analytique'),'display'=>'none'); //var $g_parameter \Noalyss_Parameter_Folder global $g_parameter; -// if using the XML Belgian format, add a tab for showing it -if ($obj->det->jr_document_xml != "") -{ - $a_tab['xml_document_div']= - [ - "id"=>"xml_document_div".$div - , "label"=>_("XML - UBL21") - , "display"=>'none' - ]; - -} + // show tabs @@ -333,29 +323,6 @@ require_once NOALYSS_TEMPLATE.'/ledger_detail_file.php';
det->jr_document_xml != "") { - printf ('
',$div,$a_tab['xml_document_div']['display']); - $url= "export.php?".http_build_query( - [ - "gDossier"=>$gDossier, - "jr_id"=>$jr_id, - "act"=>'RAW:xml-invoice' - ]); - printf('',$url); - print '' - ._("XML") - .''; - print ''; - - echo '
'; -}?> -
-'; if ( $div != 'popup' ) {