Valider 69a62022 rédigé par cerdic's avatar cerdic
Parcourir les fichiers

refactor: nommages des cles de retour de l'API plus génériques. Les entrées...

refactor: nommages des cles de retour de l'API plus génériques. Les entrées d'infos pour la livraison ou la facturation ne sont pas forcement QUE l'adresse, il peut y en avoir d'autres, le nom, le numéro TVA, etc.. L'adresse est maintenant dans un sous tableau adresse
+ mise à jour du modeles/client_adresse_facture en consequence
+ normalisation du code pays sur 3 char après le retour du pipeline, comme ça on est certain que c'est toujours en iso-3-char
parent 30cdd057
Chargement en cours
Chargement en cours
Chargement en cours
Chargement en cours
+46 −36
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
@@ -28,9 +28,10 @@ if (!defined('_ECRIRE_INC_VERSION')) { return;
 *   Retourne un tableau avec les clés possibles suivantes, optionnelles suivant ce qui est trouvé :
 *   - int id_auteur : compte utilisateur de la personne qui a fait la commande
 *   - string nom : nom complet de la personne ou orga qui a fait la commande
 *   - array adresse_livraison
 *   - array livraison
 *     - string nom : nom complet de la personne à qui livrer
 *     - string organisation : nom complet de l'organisation à qui livrer
 *     - array adresse
 *       - string voie
 *       - string complement
 *       - string code_postal
@@ -39,9 +40,10 @@ if (!defined('_ECRIRE_INC_VERSION')) { return;
 *       - string zone_administrative
 *       - string pays : code international
 *     - string telephone : numero de téléphone pour la livraison
 *   - array adresse_facturation
 *   - array facturation
 *     - string nom : nom complet de la personne à qui facturer
 *     - string organisation : nom complet de l'organisation à qui facturer
 *     - array adresse
 *       - string voie
 *       - string complement
 *       - string code_postal
@@ -91,31 +93,30 @@ function commandes_infos_client_dist($id_commande, $forcer_calcul = false) {
			foreach (['facturation', 'livraison'] as $type) {
				// On cherche directement lié à la commande avec le bon type
				if ($liens = objet_trouver_liens(['adresse' => '*'], ['commande' => $id_commande], ['type = ' . sql_quote($type)])) {
					$infos[$id_commande]["adresse_$type"] = sql_fetsel('*', 'spip_adresses', 'id_adresse = ' . $liens[0]['id_adresse']);
					if (!isset($infos[$id_commande]["adresse_$type"]['nom'])) {
						$infos[$id_commande]["adresse_$type"]['nom'] = ($objet_nom === 'organisation' ? '' : $infos[$id_commande]['nom']);
					$infos[$id_commande][$type] = [];
					$infos[$id_commande][$type]['adresse'] = sql_fetsel('*', 'spip_adresses', 'id_adresse = ' . $liens[0]['id_adresse']);
					if (!isset($infos[$id_commande][$type]['nom'])) {
						$infos[$id_commande][$type]['nom'] = ($objet_nom === 'organisation' ? '' : $infos[$id_commande]['nom']);
					}
					if (!isset($infos[$id_commande]["adresse_$type"]['organisation'])) {
						$infos[$id_commande]["adresse_$type"]['organisation'] = ($objet_nom === 'organisation' ? $infos[$id_commande]['nom'] : '');
					if (!isset($infos[$id_commande][$type]['organisation'])) {
						$infos[$id_commande][$type]['organisation'] = ($objet_nom === 'organisation' ? $infos[$id_commande]['nom'] : '');
					}
					$infos[$id_commande]["adresse_$type"]['telephone'] = '';
					$infos[$id_commande][$type]['telephone'] = '';
					if ($liens = objet_trouver_liens(['numero' => '*'], ['commande' => $id_commande], ['type = ' . sql_quote($type)])) {
						$telephones = sql_allfetsel('numero', 'spip_numeros', sql_in('id_numero', array_column($liens, 'id_numero')));
						$telephones = array_column($telephones, 'numero');
						$telephones = array_filter($telephones);
						if (!empty($telephones)) {
							$infos[$id_commande]["adresse_$type"]['telephone'] = reset($telephones);
							$infos[$id_commande][$type]['telephone'] = reset($telephones);
						}
					}
					// si on a un code_pays sur 2 lettres ou numerique, le convertir en code ISO 3
					$infos[$id_commande]["adresse_$type"]['pays'] = commandes_normalise_code_pays($infos[$id_commande]["adresse_$type"]['pays']);
				}
			}
		}

		if (!empty($infos[$id_commande]["adresse_facturation"])) {
		if (!empty($infos[$id_commande]['facturation'])) {
			// provisionner le no_tva_intra
			$infos[$id_commande]["adresse_facturation"]['no_tva_intra'] = '';
			$infos[$id_commande]['facturation']['no_tva_intra'] = '';
		}

		$infos[$id_commande] = pipeline(
@@ -128,17 +129,26 @@ function commandes_infos_client_dist($id_commande, $forcer_calcul = false) {

		// si on a une seule adresse, repercuter sur l'autre (adresse de livraison identique à la facturation, ou le contraire...)
		// on fait ça après le pipeline, pour laisser les plugins gérer l'absence d'une des adresses si besoin
		if (empty($infos[$id_commande]["adresse_facturation"])
			and !empty($infos[$id_commande]["adresse_livraison"])) {
			$infos[$id_commande]["adresse_facturation"] = $infos[$id_commande]["adresse_livraison"];
		if (empty($infos[$id_commande]['facturation'])
			and !empty($infos[$id_commande]['livraison'])) {
			$infos[$id_commande]['facturation'] = $infos[$id_commande]['livraison'];
			// provisionner le no_tva_intra
			$infos[$id_commande]["adresse_facturation"]['no_tva_intra'] = '';
			$infos[$id_commande]['facturation']['no_tva_intra'] = '';
		}
		elseif (empty($infos[$id_commande]["adresse_livraison"])
			and !empty($infos[$id_commande]["adresse_facturation"])) {
			$infos[$id_commande]["adresse_livraison"] = $infos[$id_commande]["adresse_facturation"];
		elseif (empty($infos[$id_commande]['livraison'])
			and !empty($infos[$id_commande]['facturation'])) {
			$infos[$id_commande]['livraison'] = $infos[$id_commande]['facturation'];
			// supprimer le no_tva_intra
			unset($infos[$id_commande]["adresse_livraison"]['no_tva_intra']);
			unset($infos[$id_commande]['livraison']['no_tva_intra']);
		}

		// normaliser le code pays en ISO 3char
		foreach (['facturation', 'livraison'] as $type) {
			if (!empty($infos[$id_commande][$type]['adresse']['pays'])) {
				// si on a un code_pays sur 2 lettres ou numerique, le convertir en code ISO 3
				$infos[$id_commande][$type]['adresse']['pays'] = commandes_normalise_code_pays($infos[$id_commande][$type]['adresse']['pays']);
			}

		}

	}
+12 −13
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
<BOUCLE_transaction(TRANSACTIONS){id_transaction}>
<BOUCLE_commande(COMMANDES){id_commande}{tout}>
#SET{adresse,#ID_COMMANDE|generer_commande_infos_client{adresse_#ENV{adresse,facturation}}}
<div class="client-nom">[(#GET{adresse/nom})]</div>
[<div class="client-organisation">(#GET{adresse/organisation})</div>]
#SET{facturation,#ID_COMMANDE|generer_commande_infos_client{#ENV{adresse,facturation}}}
<div class="client-nom">[(#GET{facturation/nom})]</div>
[<div class="client-organisation">(#GET{facturation/organisation})</div>]
<div class="client-adresse">
[(#GET{adresse/voie}|propre|PtoBR)]
[<br />(#GET{adresse/complement}|propre|PtoBR)]
[<br />(#GET{adresse/code_postal}|concat{' ',#GET{adresse/ville}}|trim)]
[<br />(#GET{adresse/localite_dependante}|trim)]
[<br />(#GET{adresse/zone_administrative}|trim)]
<BOUCLE_pays_auteur(PAYS?){code=#GET{adresse/pays}}>#NOM</BOUCLE_pays_auteur><//B>
<BOUCLE_pays_code(PAYS?){code_alpha3=#GET{adresse/pays}}><br />#NOM</BOUCLE_pays_code>#GET{adresse/pays}<//B_pays_code>
[(#GET{facturation/adresse/voie}|propre|PtoBR)]
[<br />(#GET{facturation/adresse/complement}|propre|PtoBR)]
[<br />(#GET{facturation/adresse/code_postal}|concat{' ',#GET{facturation/adresse/ville}}|trim)]
[<br />(#GET{facturation/adresse/localite_dependante}|trim)]
[<br />(#GET{facturation/adresse/zone_administrative}|trim)]
<BOUCLE_pays(PAYS?){code_alpha3=#GET{facturation/adresse/pays}}><br />#NOM</BOUCLE_pays><br />#GET{facturation/adresse/pays}<//B_pays>
</div>

<div class="client-telephone">
[<strong>Tel</strong> (#GET{adresse/telephone}|trim)]
[<strong>Tel</strong> (#GET{facturation/telephone}|trim)]
</div>
<div class="client-no-tva-intra">
[<strong>No TVA</strong> (#GET{adresse/no_tva_intra}|trim)]
[<strong>No TVA</strong> (#GET{facturation/no_tva_intra}|trim)]
</div>
</BOUCLE_commande>
</BOUCLE_transaction>
 No newline at end of file