Explorar el Código

NEW category of operation in PDF

VESSILLER hace 2 años
padre
commit
c3dc10f2e5

+ 1 - 1
htdocs/admin/pdf_other.php

@@ -36,7 +36,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
 
 // Load translation files required by the page
-$langs->loadLangs(array('admin', 'bills', 'companies', 'languages', 'members', 'other', 'products', 'receptions', 'stocks', 'trips'));
+$langs->loadLangs(array('admin', 'bills', 'companies', 'languages', 'members', 'other', 'products', 'propal', 'receptions', 'stocks', 'trips'));
 
 if (!$user->admin) {
 	accessforbidden();

+ 47 - 23
htdocs/core/modules/facture/doc/pdf_sponge.modules.php

@@ -160,6 +160,11 @@ class pdf_sponge extends ModelePDFFactures
 	 */
 	public $cols;
 
+	/**
+	 * @var int Category of operation
+	 */
+	public $categoryOfOperation = -1; // unknown by default
+
 
 	/**
 	 *	Constructor
@@ -430,12 +435,35 @@ class pdf_sponge extends ModelePDFFactures
 				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
 
 				// Set $this->atleastonediscount if you have at least one discount
+				// and determine category of operation
+				$categoryOfOperation = 0;
+				$nbProduct = 0;
+				$nbService = 0;
 				for ($i = 0; $i < $nblines; $i++) {
 					if ($object->lines[$i]->remise_percent) {
 						$this->atleastonediscount++;
 					}
-				}
 
+					// determine category of operation
+					$lineProductType = $object->lines[$i]->product_type;
+					if ($lineProductType == Product::TYPE_PRODUCT) {
+						$nbProduct++;
+					} elseif ($lineProductType == Product::TYPE_SERVICE) {
+						$nbService++;
+					}
+					if ($nbProduct > 0 && $nbService > 0) {
+						// mixed products and services
+						$categoryOfOperation = 2;
+					}
+				}
+				// determine category of operation
+				if ($categoryOfOperation <= 0) {
+					// only services
+					if ($nbProduct == 0 && $nbService > 0) {
+						$categoryOfOperation = 1;
+					}
+				}
+				$this->categoryOfOperation = $categoryOfOperation;
 
 				// Situation invoice handling
 				if ($object->situation_cycle_ref) {
@@ -1242,6 +1270,21 @@ class pdf_sponge extends ModelePDFFactures
 			$posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
 		}
 
+		// Show category of operations
+		if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
+			$pdf->SetFont('', 'B', $default_font_size - 2);
+			$pdf->SetXY($this->marge_gauche, $posy);
+			$categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : ';
+			$pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L');
+
+			$pdf->SetFont('', '', $default_font_size - 2);
+			$pdf->SetXY($posxval, $posy);
+			$categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
+			$pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L');
+
+			$posy = $pdf->GetY() + 3; // for 2 lines
+		}
+
 		if ($object->type != 2) {
 			// Check a payment mode is defined
 			if (empty($object->mode_reglement_code)
@@ -1290,16 +1333,6 @@ class pdf_sponge extends ModelePDFFactures
 				$posy = $pdf->GetY();
 			}
 
-			// Show category of operations
-			if ($conf->global->INVOICE_CATEGORY_OF_OPERATION == 2) {
-				$nbCategoryOfOperations = 0;
-				$categoryOfOperations = $outputlangs->trans("MentionCategoryOfOperations") . ': ' . $outputlangs->trans("MentionCategoryOfOperations" . $nbCategoryOfOperations);
-				$pdf->SetXY($this->marge_gauche, $posy);
-				$pdf->writeHTMLCell(80, 5, '', '', $outputlangs->transnoentities($categoryOfOperations), 0, 1);
-
-				$posy = $pdf->GetY() + 1;
-			}
-
 			// Show if Option VAT debit option is on also if transmitter is french
 			// Decret n°2099-1299 2022-10-07
 			// French mention : "Option pour le paiement de la taxe d'après les débits"
@@ -1958,10 +1991,9 @@ class pdf_sponge extends ModelePDFFactures
 	 *   @param		int			$hidebottom		Hide bottom bar of array
 	 *   @param		string		$currency		Currency code
 	 *   @param		Translate	$outputlangsbis	Langs object bis
-	 *   @param		Facture		$object     	Object to show
 	 *   @return	void
 	 */
-	protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null, $object)
+	protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
 	{
 		global $conf;
 
@@ -1980,16 +2012,8 @@ class pdf_sponge extends ModelePDFFactures
 
 		if (empty($hidetop)) {
 			// Show category of operations
-			if ($conf->global->INVOICE_CATEGORY_OF_OPERATION == 1) {
-				$nbCategoryOfOperations = 0;
-				if (count($object->product_type == 0) >= 1) {
-					$nbCategoryOfOperations = 0;
-				} elseif (count($object->product_type == 1) >= 1) {
-					$nbCategoryOfOperations = 1;
-				} elseif (count($object->product_type == 0) >= 1 && count($object->product_type == 1) >= 1) {
-					$nbCategoryOfOperations = 2;
-				}
-				$categoryOfOperations = $outputlangs->trans("MentionCategoryOfOperations") . ': ' . $outputlangs->trans("MentionCategoryOfOperations" . $nbCategoryOfOperations);
+			if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
+				$categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
 				$pdf->SetXY($this->marge_gauche, $tab_top - 4);
 				$pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
 			}

+ 1 - 1
htdocs/master.inc.php

@@ -218,7 +218,7 @@ if (!defined('NOREQUIREDB') && !defined('NOREQUIRESOC')) {
 		// For FR, default value of option to show profid SIRET is on by default. Decret n°2099-1299 2022-10-07
 		$conf->global->MAIN_PROFID1_IN_ADDRESS = 1;
 	}
-	if ($mysoc->country_code == 'FR' && (!isset($conf->global->INVOICE_CATEGORY_OF_OPERATION) || empty($conf->global->INVOICE_CATEGORY_OF_OPERATION))) {
+	if ($mysoc->country_code == 'FR' && !isset($conf->global->INVOICE_CATEGORY_OF_OPERATION)) {
 		// For FR, default value of option to show category of operations is on by default. Decret n°2099-1299 2022-10-07
 		$conf->global->INVOICE_CATEGORY_OF_OPERATION = 1;
 	}