Parcourir la source

FIX generation of document for supplie rinvoice

Laurent Destailleur il y a 6 ans
Parent
commit
340412ed00
2 fichiers modifiés avec 20 ajouts et 4 suppressions
  1. 2 0
      htdocs/admin/supplier_invoice.php
  2. 18 4
      htdocs/core/tpl/card_presend.tpl.php

+ 2 - 0
htdocs/admin/supplier_invoice.php

@@ -43,6 +43,8 @@ accessforbidden();
 $type=GETPOST('type', 'alpha');
 $value=GETPOST('value', 'alpha');
 $action=GETPOST('action', 'alpha');
+
+$label = GETPOST('label', 'alpha');
 $scandir = GETPOST('scan_dir','alpha');
 
 $specimenthirdparty=new Societe($db);

+ 18 - 4
htdocs/core/tpl/card_presend.tpl.php

@@ -48,12 +48,15 @@ if ($action == 'presend')
 
 		$ref = dol_sanitizeFileName($object->ref);
 		include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
-		$fileparams = dol_most_recent_file($diroutput . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
-		//
+		// Special case
 		if ($object->element == 'invoice_supplier')
 		{
 			$fileparams = dol_most_recent_file($diroutput . '/' . get_exdir($object->id,2,0,0,$object,$object->element).$ref, preg_quote($ref,'/').'([^\-])+');
 		}
+		else
+		{
+		    $fileparams = dol_most_recent_file($diroutput . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
+		}
 
 		$file = $fileparams['fullname'];
 	}
@@ -86,7 +89,10 @@ if ($action == 'presend')
 	}
 
 	// Build document if it not exists
-	if (! in_array($object->element, array('societe', 'user', 'member')))
+	$forcebuilddoc=true;
+	if (in_array($object->element, array('societe', 'user', 'member'))) $forcebuilddoc=false;
+	if ($object->element == 'invoice_supplier' && empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF)) $forcebuilddoc=false;
+	if ($forcebuilddoc)    // If there is no default value for supplier invoice, we do not generate file, even if modelpdf was set by a manual generation
 	{
 		if ((! $file || ! is_readable($file)) && method_exists($object, 'generateDocument'))
 		{
@@ -95,7 +101,15 @@ if ($action == 'presend')
 				dol_print_error($db, $object->error, $object->errors);
 				exit();
 			}
-			$fileparams = dol_most_recent_file($diroutput . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
+			if ($object->element == 'invoice_supplier')
+			{
+			    $fileparams = dol_most_recent_file($diroutput . '/' . get_exdir($object->id,2,0,0,$object,$object->element).$ref, preg_quote($ref,'/').'([^\-])+');
+			}
+			else
+			{
+			    $fileparams = dol_most_recent_file($diroutput . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
+			}
+
 			$file = $fileparams['fullname'];
 		}
 	}