diff --git a/htdocs/core/class/fileupload.class.php b/htdocs/core/class/fileupload.class.php
index 075a6d2dab0..34aa394998e 100644
--- a/htdocs/core/class/fileupload.class.php
+++ b/htdocs/core/class/fileupload.class.php
@@ -76,7 +76,7 @@ class FileUpload
elseif ($element == 'order_supplier') {
$pathname = 'fourn'; $filename='fournisseur.commande';
$dir_output=$conf->fournisseur->commande->dir_output;
- }
+ }
elseif ($element == 'invoice_supplier') {
$pathname = 'fourn'; $filename='fournisseur.facture';
$dir_output=$conf->fournisseur->facture->dir_output;
@@ -99,10 +99,15 @@ class FileUpload
$object->fetch($fk_element);
$object->fetch_thirdparty();
+ $object_ref = dol_sanitizeFileName($object->ref);
+ if ($element == 'invoice_supplier') {
+ $object_ref = get_exdir($object->id, 2) . $object_ref;
+ }
+
$this->options = array(
'script_url' => $_SERVER['PHP_SELF'],
- 'upload_dir' => $dir_output . '/' . $object->ref . '/',
- 'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object->ref.'/',
+ 'upload_dir' => $dir_output . '/' . $object_ref . '/',
+ 'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object_ref.'/',
'param_name' => 'files',
// Set the following option to 'POST', if your server does not support
// DELETE requests. This is a parameter sent to the client:
@@ -135,8 +140,8 @@ class FileUpload
),
*/
'thumbnail' => array(
- 'upload_dir' => $dir_output . '/' . $object->ref . '/thumbs/',
- 'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object->ref.'/thumbs/',
+ 'upload_dir' => $dir_output . '/' . $object_ref . '/thumbs/',
+ 'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object_ref.'/thumbs/',
'max_width' => 80,
'max_height' => 80
)
diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php
index 626cbb5dd23..d17b97393d0 100644
--- a/htdocs/fourn/class/fournisseur.facture.class.php
+++ b/htdocs/fourn/class/fournisseur.facture.class.php
@@ -584,34 +584,73 @@ class FactureFournisseur extends CommonInvoice
$this->db->begin();
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn_det WHERE fk_facture_fourn = '.$rowid.';';
- dol_syslog("FactureFournisseur sql=".$sql, LOG_DEBUG);
+ dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn WHERE rowid = '.$rowid;
- dol_syslog("FactureFournisseur sql=".$sql, LOG_DEBUG);
+ dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
$resql2 = $this->db->query($sql);
- if (! $resql2) $error++;
+ if (! $resql2) {
+ $error++;
+ }
+ }
+ else {
+ $error++;
+ }
- if (! $error)
- {
- $this->db->commit();
- return 1;
- }
- else
- {
- $this->db->rollback();
- $this->error=$this->db->lasterror();
- dol_syslog("FactureFournisseur::delete ".$this->error, LOG_ERR);
- return -1;
- }
+ if (! $error)
+ {
+ // Appel des triggers
+ include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+ $interface=new Interfaces($this->db);
+ $result=$interface->run_triggers('INVOICE_SUPPLIER_DELETE',$this,$user,$langs,$conf);
+ if ($result < 0) {
+ $error++; $this->errors=$interface->errors;
+ }
+ // Fin appel triggers
+ }
+
+ if (! $error)
+ {
+ // We remove directory
+ if ($conf->fournisseur->facture->dir_output)
+ {
+ $ref = dol_sanitizeFileName($this->ref);
+ $dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2).$ref;
+ $file = $dir . "/" . $ref . ".pdf";
+ if (file_exists($file))
+ {
+ if (! dol_delete_file($file,0,0,0,$this)) // For triggers
+ {
+ $this->error='ErrorFailToDeleteFile';
+ $error++;
+ }
+ }
+ if (file_exists($dir))
+ {
+ $res=@dol_delete_dir_recursive($dir);
+ if (! $res)
+ {
+ $this->error='ErrorFailToDeleteDir';
+ $error++;
+ }
+ }
+ }
+ }
+
+ if (! $error)
+ {
+ dol_syslog(get_class($this)."::delete $this->id by $user->id", LOG_DEBUG);
+ $this->db->commit();
+ return 1;
}
else
{
- $this->db->rollback();
- $this->error=$this->db->lasterror();
- dol_syslog("FactureFournisseur::delete ".$this->error, LOG_ERR);
- return -1;
+ $this->error=$this->db->lasterror();
+ dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
+ $this->db->rollback();
+ return -$error;
}
}
diff --git a/htdocs/fourn/facture/document.php b/htdocs/fourn/facture/document.php
index b122c627123..229828c9065 100644
--- a/htdocs/fourn/facture/document.php
+++ b/htdocs/fourn/facture/document.php
@@ -36,8 +36,9 @@ $langs->load('bills');
$langs->load('other');
$langs->load("companies");
-$facid = GETPOST('facid','int')?GETPOST('facid','int'):GETPOST('id','int');
-$action=empty($_GET['action']) ? (empty($_POST['action']) ? '' : $_POST['action']) : $_GET['action'];
+$id = GETPOST('facid','int')?GETPOST('facid','int'):GETPOST('id','int');
+$action=GETPOST('action','alpha');
+$confirm=GETPOST('confirm','alpha');
// Security check
if ($user->societe_id) $socid=$user->societe_id;
@@ -57,6 +58,12 @@ if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="name";
$object = new FactureFournisseur($db);
+if ($object->fetch($id))
+{
+ $object->fetch_thirdparty();
+ $ref=dol_sanitizeFileName($object->ref);
+ $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref;
+}
/*
@@ -66,43 +73,24 @@ $object = new FactureFournisseur($db);
// Envoi fichier
if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
- require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
-
- $facture = new FactureFournisseur($db);
- if ($facture->fetch($facid))
- {
- $ref=dol_sanitizeFileName($facture->ref);
- $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($facture->id,2).$ref;
- dol_add_file_process($upload_dir,0,1,'userfile');
+ if ($object->id > 0) {
+ dol_add_file_process($upload_dir, 0, 1, 'userfile');
}
}
// Delete
-if ($action=='delete')
+else if ($action == 'confirm_deletefile' && $confirm == 'yes')
{
- $facid=$_GET['id'];
-
- $facture = new FactureFournisseur($db);
- if ($facture->fetch($facid))
- {
- $langs->load("other");
- $ref=dol_sanitizeFileName($facture->ref);
- $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($facture->id,2).$ref;
-
- $file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
- $ret=dol_delete_file($file);
- if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
- else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
- }
-}
-
-// Set label
-if ($action == 'setlabel' && $user->rights->fournisseur->facture->creer)
-{
- $object->fetch($facid);
- $object->label=$_POST['label'];
- $result=$object->update($user);
- if ($result < 0) dol_print_error($db);
+ if ($object->id > 0)
+ {
+ $langs->load("other");
+ $file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
+ $ret=dol_delete_file($file,0,0,0,$object);
+ if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
+ else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
+ Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
+ exit;
+ }
}
@@ -114,119 +102,113 @@ $form = new Form($db);
llxHeader();
-if ($facid > 0)
+if ($object->id > 0)
{
- if ($object->fetch($facid))
- {
- $object->fetch_thirdparty();
+ $head = facturefourn_prepare_head($object);
+ dol_fiche_head($head, 'documents', $langs->trans('SupplierInvoice'), 0, 'bill');
- $ref=dol_sanitizeFileName($object->ref);
- $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref;
+ // Construit liste des fichiers
+ $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
+ $totalsize=0;
+ foreach($filearray as $key => $file)
+ {
+ $totalsize+=$file['size'];
+ }
- $head = facturefourn_prepare_head($object);
- dol_fiche_head($head, 'documents', $langs->trans('SupplierInvoice'), 0, 'bill');
+ /*
+ * Confirm delete file
+ */
+ if ($action == 'delete')
+ {
+ $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
+ if ($ret == 'html') print '
';
+ }
+
+ print '
';
+
+ $linkback = ''.$langs->trans("BackToList").'';
+
+ // Ref
+ print '| '.$langs->trans("Ref").' | ';
+ print $form->showrefnav($object, 'facid', $linkback, 1, 'rowid', 'ref', $morehtmlref);
+ print ' | ';
+ print "
\n";
+
+ // Ref supplier
+ print '| '.$langs->trans("RefSupplier").' | '.$object->ref_supplier.' | ';
+ print "
\n";
+
+ // Thirdparty
+ print '| '.$langs->trans('Supplier').' | '.$object->thirdparty->getNomUrl(1).' |
';
+
+ // Type
+ print '| '.$langs->trans('Type').' | ';
+ print $object->getLibType();
+ if ($object->type == 1)
+ {
+ $facreplaced=new FactureFournisseur($db);
+ $facreplaced->fetch($object->fk_facture_source);
+ print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')';
+ }
+ if ($object->type == 2)
+ {
+ $facusing=new FactureFournisseur($db);
+ $facusing->fetch($object->fk_facture_source);
+ print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')';
+ }
+
+ $facidavoir=$object->getListIdAvoirFromInvoice();
+ if (count($facidavoir) > 0)
+ {
+ print ' ('.$langs->transnoentities("InvoiceHasAvoir");
+ $i=0;
+ foreach($facidavoir as $id)
+ {
+ if ($i==0) print ' ';
+ else print ',';
+ $facavoir=new FactureFournisseur($db);
+ $facavoir->fetch($id);
+ print $facavoir->getNomUrl(1);
+ }
+ print ')';
+ }
+ if ($facidnext > 0)
+ {
+ $facthatreplace=new FactureFournisseur($db);
+ $facthatreplace->fetch($facidnext);
+ print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
+ }
+ print ' |
';
+
+ // Label
+ print '| '.$form->editfieldkey("Label",'label',$object->label,$object,0).' | ';
+ print $form->editfieldval("Label",'label',$object->label,$object,0);
+ print ' | ';
+
+ // Nb of files
+ print '
| '.$langs->trans('NbOfAttachedFiles').' | '.count($filearray).' |
';
+
+ print '| '.$langs->trans('TotalSizeOfAttachedFiles').' | '.$totalsize.' '.$langs->trans('bytes').' |
';
+
+ print '
';
+ print '';
+
+ // Affiche formulaire upload
+ $formfile=new FormFile($db);
+ $formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?facid='.$object->id,'',0,0,$user->rights->fournisseur->facture->creer, 50, $object);
- // Construit liste des fichiers
- $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
- $totalsize=0;
- foreach($filearray as $key => $file)
- {
- $totalsize+=$file['size'];
- }
+ // List of document
+ $param='&facid='.$object->id;
+ $formfile->list_of_documents($filearray,$object,'facture_fournisseur',$param,0,get_exdir($object->id,2,0).$object->id.'/');
-
- print '';
-
- $linkback = ''.$langs->trans("BackToList").'';
-
- // Ref
- print '| '.$langs->trans("Ref").' | ';
- print $form->showrefnav($object, 'facid', $linkback, 1, 'rowid', 'ref', $morehtmlref);
- print ' | ';
- print "
\n";
-
- // Ref supplier
- print '| '.$langs->trans("RefSupplier").' | '.$object->ref_supplier.' | ';
- print "
\n";
-
- // Thirdparty
- print '| '.$langs->trans('Supplier').' | '.$object->thirdparty->getNomUrl(1).' |
';
-
- // Type
- print '| '.$langs->trans('Type').' | ';
- print $object->getLibType();
- if ($object->type == 1)
- {
- $facreplaced=new FactureFournisseur($db);
- $facreplaced->fetch($object->fk_facture_source);
- print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')';
- }
- if ($object->type == 2)
- {
- $facusing=new FactureFournisseur($db);
- $facusing->fetch($object->fk_facture_source);
- print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')';
- }
-
- $facidavoir=$object->getListIdAvoirFromInvoice();
- if (count($facidavoir) > 0)
- {
- print ' ('.$langs->transnoentities("InvoiceHasAvoir");
- $i=0;
- foreach($facidavoir as $id)
- {
- if ($i==0) print ' ';
- else print ',';
- $facavoir=new FactureFournisseur($db);
- $facavoir->fetch($id);
- print $facavoir->getNomUrl(1);
- }
- print ')';
- }
- if ($facidnext > 0)
- {
- $facthatreplace=new FactureFournisseur($db);
- $facthatreplace->fetch($facidnext);
- print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
- }
- print ' |
';
-
- // Label
- print '| '.$form->editfieldkey("Label",'label',$object->label,$object,0).' | ';
- print $form->editfieldval("Label",'label',$object->label,$object,0);
- print ' | ';
-
- // Nb of files
- print '
| '.$langs->trans('NbOfAttachedFiles').' | '.count($filearray).' |
';
-
- print '| '.$langs->trans('TotalSizeOfAttachedFiles').' | '.$totalsize.' '.$langs->trans('bytes').' |
';
-
- print '
';
- print '';
-
- // Affiche formulaire upload
- $formfile=new FormFile($db);
- $formfile->form_attach_new_file(DOL_URL_ROOT.'/fourn/facture/document.php?facid='.$object->id,'',0,0,$user->rights->fournisseur->facture->creer,50,$object);
-
-
- // List of document
- $param='&facid='.$object->id;
- $formfile->list_of_documents($filearray,$object,'facture_fournisseur',$param,0,get_exdir($object->id,2,0).$object->id.'/');
-
- }
- else
- {
- print 'facid='.$facid.'
';
- dol_print_error($db);
- }
}
else
{
print $langs->trans('UnkownError');
}
-$db->close();
llxFooter();
-?>
+$db->close();
+?>
\ No newline at end of file
diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php
index 2bb9907be29..55fc63df8d0 100644
--- a/htdocs/fourn/facture/fiche.php
+++ b/htdocs/fourn/facture/fiche.php
@@ -126,6 +126,7 @@ elseif ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->fourni
elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->facture->supprimer)
{
$object->fetch($id);
+ $object->fetch_thirdparty();
$result=$object->delete($id);
if ($result > 0)
{
@@ -796,6 +797,7 @@ elseif ($action == 'builddoc')
{
// Save modele used
$object->fetch($id);
+ $object->fetch_thirdparty();
if ($_REQUEST['model'])
{
$object->setDocModel($user, $_REQUEST['model']);
@@ -827,9 +829,10 @@ elseif ($action == 'remove_file')
if ($object->fetch($id))
{
+ $object->fetch_thirdparty();
$upload_dir = $conf->fournisseur->facture->dir_output . "/";
$file = $upload_dir . '/' . GETPOST('file');
- $ret=dol_delete_file($file);
+ $ret=dol_delete_file($file,0,0,0,$object);
if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
}