diff --git a/include/ajax/ajax_ledger.php b/include/ajax/ajax_ledger.php
index 6898b4a61..2ce5c27bb 100644
--- a/include/ajax/ajax_ledger.php
+++ b/include/ajax/ajax_ledger.php
@@ -301,7 +301,7 @@ case 'loadfile':
$cn->start();
// remove the file
$grpt=$cn->get_value('select jr_grpt_id from jrn where jr_id=$1',array($jr_id));
- $cn->save_upload_document($grpt);
+ $cn->save_receipt($grpt);
$cn->commit();
// Show a link to the new file
$op->get();
diff --git a/include/class/class_acc_ledger.php b/include/class/class_acc_ledger.php
index 318feaba2..598abf63b 100644
--- a/include/class/class_acc_ledger.php
+++ b/include/class/class_acc_ledger.php
@@ -2140,7 +2140,7 @@ class Acc_Ledger extends jrn_def_sql
*/
if (isset($_FILES["pj"]))
{
- $this->db->save_upload_document($seq);
+ $this->db->save_receipt($seq);
}
}
diff --git a/include/class/class_acc_ledger_fin.php b/include/class/class_acc_ledger_fin.php
index 247166d63..f472cd8de 100644
--- a/include/class/class_acc_ledger_fin.php
+++ b/include/class/class_acc_ledger_fin.php
@@ -941,7 +941,7 @@ class Acc_Ledger_Fin extends Acc_Ledger
// first record we upload the files and
// keep variable to update other row of jrn
if (isset($_FILES))
- $oid = $this->db->save_upload_document($seq);
+ $oid = $this->db->save_receipt($seq);
}
else
{
diff --git a/include/class/class_acc_ledger_purchase.php b/include/class/class_acc_ledger_purchase.php
index 8639b8061..738f8b91d 100644
--- a/include/class/class_acc_ledger_purchase.php
+++ b/include/class/class_acc_ledger_purchase.php
@@ -795,7 +795,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
if ( isset ($_FILES))
{
if ( sizeof($_FILES) != 0 )
- $this->db->save_upload_document($seq);
+ $this->db->save_receipt($seq);
}
$str_file="";
/* Generate an document and save it into the database (Note de frais only)
diff --git a/include/class/class_acc_ledger_sold.php b/include/class/class_acc_ledger_sold.php
index a8de2035b..aa1733435 100644
--- a/include/class/class_acc_ledger_sold.php
+++ b/include/class/class_acc_ledger_sold.php
@@ -479,7 +479,7 @@ class Acc_Ledger_Sold extends Acc_Ledger {
/* Save the attachment or generate doc */
if (isset($_FILES['pj'])) {
if (strlen(trim($_FILES['pj']['name'])) != 0)
- $this->db->save_upload_document($seq);
+ $this->db->save_receipt($seq);
else
/* Generate an invoice and save it into the database */
if (isset($_POST['gen_invoice'])) {
diff --git a/include/compta_fin_rec.inc.php b/include/compta_fin_rec.inc.php
index b3c1f5e83..966458a4c 100644
--- a/include/compta_fin_rec.inc.php
+++ b/include/compta_fin_rec.inc.php
@@ -30,6 +30,68 @@ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
global $g_failed,$g_succeed;
require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_fin.php';
bcscale(2);
+?>
+
+';
$Ledger = new Acc_Ledger_Fin($cn, 0);
if (!isset($_REQUEST['p_jrn']))
@@ -45,6 +107,22 @@ if (isset($_GET["p_jrn"]) && $jrn_priv == "X")
NoAccess();
return;
}
+$end_extrait=HtmlInput::default_value_post("end_extrait", 0);
+$start_extrait=HtmlInput::default_value_post("start_extrait", 0);
+if ( isNumber($end_extrait) == 0 )
+{
+ echo '';
+ echo _('Donnée invalide');
+ echo '';
+ $end_extrait=0;
+}
+if ( isNumber($start_extrait) == 0 )
+{
+ echo '';
+ echo _('Donnée invalide');
+ echo '';
+ $start_extrait=0;
+}
//-------------------------
// save
//-------------------------
@@ -60,7 +138,7 @@ if (isset($_POST['save']))
$cn->exec_sql('update jrn set jr_pj_number=$1 where jr_id=$2', array($_POST['ext'], $array[$i]));
$tot = bcadd($tot, $cn->get_value('select qf_amount from quant_fin where jr_id=$1', array($array[$i])));
}
- $diff = bcsub($_POST['end_extrait'], $_POST['start_extrait']);
+ $diff = bcsub($end_extrait, $start_extrait);
if ($diff != 0 && $diff != $tot)
{
$remain=bcsub($tot,$diff);
@@ -68,11 +146,26 @@ if (isset($_POST['save']))
alert("D'après l'extrait il y aurait du avoir un montant de $diff à rapprocher alors qu'il y a $tot rapprochés, mise à jour annulée, la différence est de $remain");
echo '
';
echo '
'.$g_failed._("D'après l'extrait il y aurait du avoir un montant de $diff à rapprocher alors qu'il y a $tot rapprochés, la différence est de $remain
mise à jour annulée").'
';
+ /* if file : warning that file is not uploaded*/
+ echo '
'.
+ _('Attention : Fichier non chargé').
+ '
';
echo '
';
}
else
{
echo ''.$g_succeed.' Mise à jour extrait '.$_POST['ext'].'
';
+ // -- chargement fichier
+ $oid=$cn->upload('file_receipt');
+
+ if ( $oid != false ) {
+ for ($i = 0; $i < count($array); $i++)
+ {
+ $cn->exec_sql("update jrn set jr_pj=$1 , jr_pj_name=$2,
+ jr_pj_type=$3 where jr_id=$4",
+ array($oid,$_FILES['file_receipt']['name'] ,$_FILES['file_receipt']['type'],$array[$i]));
+ }
+ }
}
$cn->commit();
@@ -97,7 +190,7 @@ echo HtmlInput::submit('ref', 'Rafraîchir');
echo '';
echo '' . hb(h($Ledger->get_bank_name())) . '';
-echo '';
echo '';
return;
?>
+
diff --git a/include/lib/class_database.php b/include/lib/class_database.php
index 07de6b061..054605e30 100644
--- a/include/lib/class_database.php
+++ b/include/lib/class_database.php
@@ -808,66 +808,84 @@ class Database
return $r;
}
-
- /**
- * \brief Save a "piece justificative"
+ /***
+ * \brief Save a "piece justificative" , the name must be pj
*
* \param $seq jr_grpt_id
* \return $oid of the lob file if success
* null if a error occurs
*
*/
-
- function save_upload_document($seq)
+ function save_receipt($seq)
{
- /* there is
- no file to
- upload */
- if ($_FILES["pj"]["error"]==UPLOAD_ERR_NO_FILE)
+ $oid=$this->upload('pj');
+ if ($oid==false)
{
- return;
+ return false;
+ }
+ // Remove old document
+ $ret=$this->exec_sql("select jr_pj from jrn where jr_grpt_id=$seq");
+ if (pg_num_rows($ret)!=0)
+ {
+ $r=pg_fetch_array($ret, 0);
+ $old_oid=$r['jr_pj'];
+ if (strlen($old_oid)!=0)
+ pg_lo_unlink($cn, $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));
+ return $oid;
+ }
+ /***
+ * \brief Save a document into the database , it just puts the file in the database
+ * and returns the corresponding OID , the mimetype , size ... of the document
+ * must be set in the calling function.
+ *
+ * \param name of the variable in $_FILES
+ * \return $oid of the lob file if success
+ * false if a error occurs or if there is no file to upload
+ *
+ */
+
+ function upload($p_name)
+ {
+ /* there is no file to upload */
+ if ($_FILES[$p_name]["error"]==UPLOAD_ERR_NO_FILE)
+ {
+ return false;
}
- $new_name=tempnam($_ENV['TMP'], 'pj');
- if ($_FILES["pj"]["error"]>0)
+ $new_name=tempnam($_ENV['TMP'], $p_name);
+ if ($_FILES[$p_name]["error"]>0)
{
print_r($_FILES);
- echo_error(__FILE__.":".__LINE__."Error: ".$_FILES["pj"]["error"]);
+ echo_error(__FILE__.":".__LINE__."Error: ".$_FILES[$p_name]["error"]);
+ return false;
}
- if (strlen($_FILES['pj']['tmp_name'])!=0)
+ if (strlen($_FILES[$p_name]['tmp_name'])!=0)
{
- if (move_uploaded_file($_FILES['pj']['tmp_name'], $new_name))
+ if (move_uploaded_file($_FILES[$p_name]['tmp_name'], $new_name))
{
// echo "Image saved";
$oid=pg_lo_import($this->db, $new_name);
if ($oid==false)
{
- echo_error('postgres.php', __LINE__, "cannot upload document");
+ echo_error(__FILE__, __LINE__, "cannot upload document");
$this->rollback();
- return;
+ return false;
}
- // Remove old document
- $ret=$this->exec_sql("select jr_pj from jrn where jr_grpt_id=$seq");
- if (pg_num_rows($ret)!=0)
- {
- $r=pg_fetch_array($ret, 0);
- $old_oid=$r['jr_pj'];
- if (strlen($old_oid)!=0)
- pg_lo_unlink($cn, $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));
return $oid;
}
else
{
echo "Error
";
$this->rollback();
+ return false;
}
}
- return 0;
+ return false;
}
/**\brief wrapper for the function pg_NumRows
diff --git a/unit-test/include/class_databaseTest.php b/unit-test/include/class_databaseTest.php
index f876962cc..1efb91b22 100644
--- a/unit-test/include/class_databaseTest.php
+++ b/unit-test/include/class_databaseTest.php
@@ -378,10 +378,10 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
}
/**
- * @covers Database::save_upload_document
- * @todo Implement testSave_upload_document().
+ * @covers Database::save_receipt
+ * @todo Implement testsave_receipt().
*/
- public function testSave_upload_document()
+ public function testsave_receipt()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(