Explorar o código

MMIDocuments : Add socpeople fields tva_intra, SIREN, SIRET in contacts to display in documents

Mathieu Moulin hai 1 ano
pai
achega
61dcf27c14

+ 16 - 6
htdocs/core/lib/pdf.lib.php

@@ -635,25 +635,35 @@ function pdf_build_address($outputlangs, $sourcecompany, $targetcompany = '', $t
 
 			// Intra VAT
 			if (empty($conf->global->MAIN_TVAINTRA_NOT_IN_ADDRESS)) {
-				if ($targetcompany->tva_intra) {
+				// MMI Hack
+				if ($usecontact && is_object($targetcontact) && !empty($targetcontact->array_options['tva_intra']))
+					$stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($targetcontact->array_options['tva_intra']);
+				elseif ($targetcompany->tva_intra)
 					$stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($targetcompany->tva_intra);
-				}
 			}
 
 			// Professionnal Ids
-			if (!empty($conf->global->MAIN_PROFID1_IN_ADDRESS) && !empty($targetcompany->idprof1)) {
+			if (!empty($conf->global->MAIN_PROFID1_IN_ADDRESS)) {
 				$tmp = $outputlangs->transcountrynoentities("ProfId1", $targetcompany->country_code);
 				if (preg_match('/\((.+)\)/', $tmp, $reg)) {
 					$tmp = $reg[1];
 				}
-				$stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof1);
+				// MMI Hack
+				if ($usecontact && is_object($targetcontact) && !empty($targetcontact->array_options['options_siren']))
+					$stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcontact->array_options['options_siren']);
+				elseif (!empty($targetcompany->idprof1))
+					$stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof1);
 			}
-			if (!empty($conf->global->MAIN_PROFID2_IN_ADDRESS) && !empty($targetcompany->idprof2)) {
+			if (!empty($conf->global->MAIN_PROFID2_IN_ADDRESS)) {
 				$tmp = $outputlangs->transcountrynoentities("ProfId2", $targetcompany->country_code);
 				if (preg_match('/\((.+)\)/', $tmp, $reg)) {
 					$tmp = $reg[1];
 				}
-				$stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof2);
+				// MMI Hack
+				if ($usecontact && is_object($targetcontact) && !empty($targetcontact->array_options['options_siret']))
+					$stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcontact->array_options['options_siret']);
+				elseif (!empty($targetcompany->idprof2))
+					$stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof2);
 			}
 			if (!empty($conf->global->MAIN_PROFID3_IN_ADDRESS) && !empty($targetcompany->idprof3)) {
 				$tmp = $outputlangs->transcountrynoentities("ProfId3", $targetcompany->country_code);

+ 9 - 1
htdocs/core/modules/facture/doc/pdf_sponge.modules.php

@@ -2410,9 +2410,17 @@ class pdf_sponge extends ModelePDFFactures
 					$usecontact = true;
 					$result = $object->fetch_contact($arrayidcontact[0]);
 				}
+				// If BILLING contact defined, we use it
+				if (! $usecontact) {
+					$arrayidcontact = $object->getIdContact('external', 'BILLING');
+					if (count($arrayidcontact) > 0) {
+						$usecontact = true;
+						$result = $object->fetch_contact($arrayidcontact[0]);
+					}
+				}
 
 				// Recipient name
-				if ($usecontact && ($object->contact->socid == $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
+				if ($usecontact && ($object->contact->socid == $object->thirdparty->id && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT))) {
 					$thirdparty = $object->contact;
 				} else {
 					$thirdparty = $object->thirdparty;

+ 1 - 1
htdocs/custom/mmidocuments

@@ -1 +1 @@
-Subproject commit d498264a6713adeabe6761bb72336686a6ec7e77
+Subproject commit 6abd62e8b68ee16f2fe54d39da91d33458879615