/* =========================================================================================== */
/* Transfert Cdes - Phase 2 - Update des lignes pr�sentes dans DW, � partir des valeurs de HA+ */
/* =========================================================================================== */

update doc
set 
/* En-t�te */
DOC_AVENANT                  = ent.AVENANT,
DOC_DATE_CREATION_CDE        = CASE WHEN (ent.DTE_CREAT = ' ' OR ent.DTE_CREAT = '00000000' ) THEN NULL WHEN (ent.DTE_CREAT < '17530101') THEN CONVERT (datetime,'19000101' ,103) ELSE CONVERT (datetime,ent.DTE_CREAT ,103) END,
DOC_DATE_PERIODE_CDE         = CASE WHEN (ent.DTE_PERIO = ' ' OR ent.DTE_PERIO = '00000000' ) THEN NULL WHEN (ent.DTE_PERIO < '17530101') THEN CONVERT (datetime,'19000101' ,103) ELSE CONVERT (datetime,ent.DTE_PERIO ,103) END,
   /* DOC_ID_DATE : Date r�f�rence = Date p�riode */
DOC_DATE_PERIODE             = CASE WHEN (ent.DTE_PERIO = ' ' OR ent.DTE_PERIO = '00000000' ) THEN NULL WHEN (ent.DTE_PERIO < '17530101') THEN CONVERT (datetime,'19000101' ,103) ELSE CONVERT (datetime,ent.DTE_PERIO ,103) END,   
DOC_ID_DATE                  = CASE WHEN (ent.DTE_PERIO = ' ' OR ent.DTE_PERIO = '00000000' ) THEN NULL WHEN (ent.DTE_PERIO < '17530101') THEN CONVERT (datetime,'19000101' ,103) ELSE CONVERT (datetime,ent.DTE_PERIO ,103) END,
DOC_DATE_VALIDATION_CDE      = CASE WHEN (ent.DTE_VALID = ' ' OR ent.DTE_VALID = '00000000' ) THEN NULL WHEN (ent.DTE_VALID < '17530101') THEN CONVERT (datetime,'19000101' ,103) ELSE CONVERT (datetime,ent.DTE_VALID ,103) END,
DOC_DATE_AR_CDE              = CASE WHEN (ent.DTE_AR = ' ' OR ent.DTE_AR = '00000000' ) THEN NULL WHEN (ent.DTE_AR < '17530101') THEN CONVERT (datetime,'19000101' ,103) ELSE CONVERT (datetime,ent.DTE_AR ,103) END,  
DOC_OBJET_CDE                = ent.OBJET_CA,
DOC_ETAT_CDE                 = ent.ETAT_CDE,
DOC_ETAT_FINANCIER           = ent.ETAT_FIN,
DOC_DEVISE_CDE               = ent.DEVISE,
DOC_TAUX_DEVISE              = ent.VAL_DEVIS,
DOC_CODE_MODE_PAIEMENT_CDE   = ent.MODE_PAIE,
DOC_CODE_MODE_LIVRAISON_CDE  = ent.MODE_LIV,
DOC_CODE_CONDITION_PAIE_CDE  = ent.COND_PAIE,
DOC_CODE_FOURNISSEUR         = ent.CODE_FOU, 
DOC_CODE_ACHETEUR            = ent.ACH, 
DOC_CODE_DEMANDEUR           = ent.DEMANDEUR, 
DOC_STATUT_CDE               = CASE WHEN SIGNEE = 0x54 THEN 'SIGNEE' WHEN REFUSEE = 0x54 THEN 'REFUSEE' ELSE ' ' END,
DOC_ZONE_LIBRE_NUMERIQUE     = ent.ZNLIBNUM,
DOC_TYPE_DOCUMENT_CDE        = ent.TYP_DOC,
DOC_CODE_SOCIETE             = ent.CODE_STE,
DOC_CODE_CE_CDE              = ent.CTR_EMETT,
DOC_CODE_CF_CDE              = ent.CTR_FACTU,
DOC_CODE_CL_CDE              = ent.CTR_LIV,
DOC_REFERENCE_OFFRE_FOURNISSEUR_CDE = ent.REFOFFOU,
DOC_CODE_PAYS_CDE            = ' ', /* Pays du CTR Livr de la Cde */
DOC_MODE_TRANSPORT_CDE       = ent.MOD_TRS,
DOC_FOURN_EXPORTATEUR_CDE    = CASE WHEN ent.FRNEXPORT = 0x54 THEN 1 ELSE 0 END,
DOC_FRANCHISE_TVA_CDE        = CASE WHEN ent.FRANCTVA  = 0x54 THEN 1 ELSE 0 END,
DOC_LANGUE_CDE               = ent.COD_LNG,
DOC_CODE_LOGISTICIEN_CDE     = ent.LOGIST,
DOC_CONTACT1_LIVRAISON_CDE   = ent.NMCTC1L,
DOC_CONTACT2_LIVRAISON_CDE   = ent.NMCTC2L,
DOC_MODELE_CDE               = ent.MODELE,
DOC_MOTIF_AVENANT_CDE        = ent.MOT_AVNT,
/* Lignes ou planning */
/*DOC_COMPTEUR_LIG             = convert(varchar(9),pla.NO_CA) + '-' + convert(varchar(3),pla.NO_PO_CA) + '-' + '000',  Pour compteur lignes : P0?, encore utile? */
DOC_CODE_ARTICLE             = lig.CODE_ART,
DOC_DESIGNATION_ARTICLE_CDE  = replace(replace(lig.DES_SOMM,char(10),' '),char(13),'')                  ,
DOC_PRIX_UNITAIRE_CDE        = lig.PU, /* en Devise R�f : conversion �ventuelle req. suivante */
DOC_PRIX_UNITAIRE_CDE_DEV    = lig.PU, /* en Devise Cde */
DOC_QUANTITE_CDE             = pla.QTE_COMM,
DOC_REMISE_CDE               = lig.REMISE,
DOC_TAUX_TVA_DA              = lig.TVA,
DOC_MONTANT_LIGNE_CDE        = pla.QTE_COMM * lig.PU *(1-lig.REMISE/100), /* en Devise R�f : conversion �ventuelle req. suivante */
DOC_MONTANT_LIGNE_TTC_CDE    = pla.QTE_COMM * lig.PU *(1-lig.REMISE/100) + (pla.QTE_COMM * lig.PU *(1-lig.REMISE/100) * (lig.TVA /100) ),
DOC_MONTANT_LIGNE_TTC_DEV_CDE= pla.QTE_COMM * lig.PU *(1-lig.REMISE/100) + (pla.QTE_COMM * lig.PU *(1-lig.REMISE/100) * (lig.TVA /100) ),
DOC_MONTANT_LIGNE_CDE_DEV    = pla.QTE_COMM * lig.PU *(1-lig.REMISE/100), /* en Devise Cde */
DOC_TVA_CDE                  = lig.TVA,
DOC_QUANTITE_UNITE_ARTICLE_CDE = pla.QTE_COMM, /* Qt� de la ligne de planning de Cde, convertie en unit� d'article par req. suivante (OXADW_DOC_UPDREF.SQL) */ 
DOC_QTE_TOT_LIG_CDE          = lig.QTE_COMM,   /* Qt� totale de la ligne de Cde */
DOC_QTE_TOT_LIG_UA_CDE       = lig.QTE_COMM,   /* Qt� totale de la ligne de Cde, convertie en unit� d'article par req. suivante (OXADW_DOC_UPDREF.SQL) */
DOC_UNITE_LIGNE              = lig.UNITE,
DOC_CODE_SOUS_FAMILLE        = lig.SSFAM,
DOC_CODE_SECTION_IMPUTATION  = lig.SECTIMP,
DOC_CODE_COMPLEMENTAIRE      = lig.CODE_COMP,
DOC_CODE_SOUS_CPTE_ANALYSE   = lig.SSCPTEANA,
DOC_CODE_ACCORD_CADRE        = lig.ACCORCA, 
DOC_NUMERO_DA                = lig.NO_DA,
DOC_AR_NON_CONFORME_CDE      = case WHEN   ent.AR_NCONF=0x54 then 1 ELSE 0 END,
DOC_NUMERO_LIGNE_DA          = lig.NO_PO_DA,
DOC_TYPE_ACHAT_CDE  		     = ent.COD_TAC,
DOC_REFERENCE_FOURNISSEUR_CDE= lig.REF_FOUR,
DOC_CODE_FABRICANT_CDE       = lig.COD_FAB,
DOC_CODE_GAME_CDE            = lig.COD_GAM,
DOC_REFERENCE_FABRICANT_CDE = lig.REF_FAB,
DOC_CODE_GESTION_CDE         = lig.CODGES,
DOC_CODE_GESTION_LIBELLE_CDE = lig.LIBGES,
DOC_CODE_GESTION_INTERNE     = lig.ID_CG,
DOC_CODE_GESTION_AFFICHE     = lig.CODGES,
DOC_STATUT_LIGNE_CDE         = lig.ET_CDELIG,
DOC_DATEMODI                 = pla.DATEMODI
/* Tables */
from <PREFIXE_DW>DOCUMENTS doc,  
     <PREFIXE_HA>CA_PL_CT<SUFFIXE_HA> pla <WITHNOLOCK>, <PREFIXE_HA>CA_LIGNE<SUFFIXE_HA> lig <WITHNOLOCK>, <PREFIXE_HA>CA_ENTET<SUFFIXE_HA> ent <WITHNOLOCK>
where 
/* Crit�res */
    doc.DOC_TYPE_TRANSACTION     = 'CA' 
and doc.DOC_NUMERO_DOC           = pla.NO_CA
and doc.DOC_NUMERO_LIGNE_1       = pla.NO_PO_CA
and doc.DOC_NUMERO_LIGNE_2       = 0
and doc.DOC_MAGIC_DSTR_LIVRAISON = pla.DTE_LIV
/* Jointure interne pla/lig */
and pla.NO_CA    = lig.NO_CDE
and pla.NO_PO_CA = lig.NO_PO
/* Jointure interne pla/ent */
and pla.NO_CA    = ent.NO_CDE
and lig.NO_CDE   = ent.NO_CDE
/* Diff�rentiel */
and pla.DATEMODI >= '<DATEMODIMIN>' and pla.DATEMODI <= '<DATEMODIMAX>'
<SEPARATEUR>

/* Pays du CTR Livr de la Cde */
update doc
set 
DOC_CODE_PAYS_CDE  = ctr.CL_PAYS 
from <PREFIXE_DW>DOCUMENTS doc,  
     <PREFIXE_DW>CENTRES_LIVRAISON ctr <WITHNOLOCK> 
where 
/* Crit�res */
    doc.DOC_TYPE_TRANSACTION     = 'CA' 
/* Jointure interne ctr/doc */
and ctr.CL_CODE_CENTRE_LIVRAISON = doc.DOC_CODE_CL_CDE 
/* le champs destination est en not null */
and ctr.CL_PAYS is not null 
and DOC_DATEMODI>= '<DATEMODIMIN>' and DOC_DATEMODI <='<DATEMODIMAX>'
and DOC_CODE_PAYS_CDE  <> ctr.CL_PAYS 
<SEPARATEUR>

/* Conversion de devises */
update doc 
set 
DOC_PRIX_UNITAIRE_CDE = DOC_PRIX_UNITAIRE_CDE_DEV * 
 (
 CASE 
  /* Devise in euro */
  WHEN dev.INEURO = 0x54 and <EUROACTIF> = 1 and ( doc.DOC_DATE_PERIODE_CDE >= (CASE WHEN (dev.DTEENTEUR = ' ' OR dev.DTEENTEUR = '00000000' ) THEN NULL WHEN (dev.DTEENTEUR < '17530101') THEN CONVERT (datetime,'19000101' ,103) ELSE CONVERT (datetime,dev.DTEENTEUR ,103) END ) OR doc.DOC_TAUX_DEVISE =0 ) THEN 1/dev.TXFROMEUR
 ELSE
  /* Devise hors euro */
  CASE WHEN doc.DOC_TAUX_DEVISE = 0  THEN dev.VALEUR ELSE doc.DOC_TAUX_DEVISE END
 END
 ),
DOC_MONTANT_LIGNE_CDE = DOC_MONTANT_LIGNE_CDE_DEV * 
 (
 CASE 
  /* Devise in euro */
  WHEN dev.INEURO = 0x54 and <EUROACTIF> = 1 and ( doc.DOC_DATE_PERIODE_CDE >= (CASE WHEN (dev.DTEENTEUR = ' ' OR dev.DTEENTEUR = '00000000' ) THEN NULL WHEN (dev.DTEENTEUR < '17530101') THEN CONVERT (datetime,'19000101' ,103) ELSE CONVERT (datetime,dev.DTEENTEUR ,103) END ) OR doc.DOC_TAUX_DEVISE =0 ) THEN 1/dev.TXFROMEUR
 ELSE
  /* Devise hors euro */
  CASE WHEN doc.DOC_TAUX_DEVISE = 0  THEN dev.VALEUR ELSE doc.DOC_TAUX_DEVISE END
 END
 )
from <PREFIXE_DW>DOCUMENTS doc, <PREFIXE_HA>DEVISES<SUFFIXE_HA> dev <WITHNOLOCK> 
/* Crit�res */
where doc.DOC_TYPE_TRANSACTION     = 'CA' 
and   doc.DOC_DEVISE_CDE          <> '<DEVISEREF>' 
/* Jointure interne dev/doc */
and dev.CODE_DEVI = doc.DOC_DEVISE_CDE
and DOC_DATEMODI>= '<DATEMODIMIN>' and DOC_DATEMODI <='<DATEMODIMAX>'

<SEPARATEUR>
/*Recalcul Montant TVA*/
update <PREFIXE_DW>DOCUMENTS set DOC_MONTANT_LIGNE_TTC_CDE=DOC_MONTANT_LIGNE_CDE+ (DOC_MONTANT_LIGNE_CDE * (DOC_TVA_CDE /100) ) where DOC_MONTANT_LIGNE_TTC_CDE<>DOC_MONTANT_LIGNE_CDE+ (DOC_MONTANT_LIGNE_CDE * (DOC_TVA_CDE /100) )

<SEPARATEUR>
/*Remise � blanc d�signation comp de ligne si pas de N�ligne au cas ou */
update <PREFIXE_DW>DOCUMENTS set DOC_DESIGNATION_COMP_CDE='' where DOC_NUMERO_LIGNE_CDE=0

<SEPARATEUR>
/* Memo Designation complementaire ligne de Cde sans RC*/
update doc
set 
 DOC_DESIGNATION_COMP_CDE =replace( replace( substring(mem.CONTMEMO,1,200),char(10),' '),char(13),'')
from  
 <PREFIXE_DW>DOCUMENTS doc,
 <PREFIXE_HA>CA_LIGNE<SUFFIXE_HA> lig <WITHNOLOCK>,
 <PREFIXE_HA>MEMOS<SUFFIXE_HA>    mem <WITHNOLOCK>
where 
/* Crit�res */
      lig.NM_DCOMP <> 0 
/* Jointure interne lig/doc */
and   lig.NO_CDE    = doc.DOC_NUMERO_DOC 
and   lig.NO_PO     = doc.DOC_NUMERO_LIGNE_CDE 
/* Jointure interne mem/lig */
and   mem.NODEMEMO  = lig.NM_DCOMP 
/* Diff�rentiel */
and DOC_DATEMODI>= '<DATEMODIMIN>' and DOC_DATEMODI <='<DATEMODIMAX>'
and DOC_DESIGNATION_COMP_CDE <> replace( replace( substring(mem.CONTMEMO,1,200),char(10),' '),char(13),'')

<SEPARATEUR>
/* Recherche TITRE CA */
update doc
set 
DOC_TITRE_CDE  = replace(replace(substring(m.CONTMEMO,1,100) ,char(10),' ') ,char(13),'')
from <PREFIXE_DW>DOCUMENTS doc,  
     <PREFIXE_HA>MEMOS<SUFFIXE_HA> m ,
	 <PREFIXE_HA>CA_ENTET<SUFFIXE_HA> d	
where 
doc.DOC_TYPE_TRANSACTION     = 'CA' 
and m.NODEMEMO = d.NM_TITRE
and DOC_NUMERO_DOC=d.NO_CDE
and DOC_TITRE_CDE  <> replace(replace(substring(m.CONTMEMO,1,100) ,char(10),' ') ,char(13),'')
and DOC_DATEMODI>= '<DATEMODIMIN>' and DOC_DATEMODI <='<DATEMODIMAX>'

<SEPARATEUR>
/* Recherche Libelle Type Achat 10/2025*/
update doc set DOC_TYPE_ACHAT_LIBELLE_CDE=LIB_TAC
from <PREFIXE_DW>DOCUMENTS doc with (nolock),  <PREFIXE_HA>TYPEACHAT d	with (nolock)
where DOC_TYPE_ACHAT_CDE=d.TYP_ACH 
and DOC_DATEMODI>= '' and DOC_DATEMODI <='20501231'
and DOC_TYPE_ACHAT_LIBELLE_CDE<>LIB_TAC

<SEPARATEUR>
/* Recherche Bloc Note*/
update doc
set 
DOC_BLOC_NOTE_CDE  = substring(m.CONTMEMO,1,100)
from <PREFIXE_DW>DOCUMENTS doc,  
     <PREFIXE_HA>MEMOS m <WITHNOLOCK> ,
	 <PREFIXE_HA>CABNOTE d <WITHNOLOCK>
where 
doc.DOC_TYPE_TRANSACTION     = 'CA' 
and m.NODEMEMO = d.CA_NOTE
and DOC_NUMERO_DOC=d.NO_CA
<SEPARATEUR>
/* Calcul Num ligne de planning*/
if  exists (select * from sysobjects where name='TMP_CA_PL_CT' and xtype='U') drop table TMP_CA_PL_CT
<SEPARATEUR>
select max(NO_CA) AS NO_CA,max(NO_PO_CA) as NO_PO_CA,  min(DTE_LIV) as DTE_LIV,0 as NO_LIGNE_PL  into TMP_CA_PL_CT from <PREFIXE_HA>CA_PL_CT <WITHNOLOCK> group by NO_CA,NO_PO_CA
<SEPARATEUR>
update TMP_CA_PL_CT set NO_LIGNE_PL=1
<SEPARATEUR>
update doc set DOC_NUMERO_LIGNE_PLANNING_CDE=NO_LIGNE_PL from <PREFIXE_DW>DOCUMENTS doc,TMP_CA_PL_CT tmp where DOC_NUMERO_CDE=NO_CA and DOC_NUMERO_LIGNE_1=NO_PO_CA and DOC_MAGIC_DSTR_LIVRAISON=DTE_LIV 
<SEPARATEUR>
if  exists (select * from sysobjects where name='TMP_CA_PL_CT' and xtype='U') drop table TMP_CA_PL_CT
<SEPARATEUR>
/* Calcul uniquement sur ligne planning 1*/
update doc
set 
DOC_QUANTITE_RESTANT_CDE  = RAL,DOC_MONTANT_DEJA_FACTURE_CDE=SOMFACVAL
from <PREFIXE_DW>DOCUMENTS doc,  
     <PREFIXE_HA>CA_LIGNE c <WITHNOLOCK> 
where 
doc.DOC_TYPE_TRANSACTION     = 'CA' 
and DOC_NUMERO_DOC = NO_CDE
and DOC_NUMERO_LIGNE_CDE=NO_PO
and DOC_NUMERO_LIGNE_PLANNING_CDE=1

<SEPARATEUR>
/*On remet tout � blanc*/
/*update <PREFIXE_DW>DOCUMENTS set DOC_STATUT_CDE=''*/

<SEPARATEUR>
/*En signature = [DOC_ETAT_CDE] = �V� and [DOC_DATE_SIGNATURE_CDE] = NULL*/
update <PREFIXE_DW>DOCUMENTS set DOC_STATUT_CDE='EN_SIGNATURE' where [DOC_ETAT_CDE] = 'V' and [DOC_DATE_SIGNATURE_CDE] is NULL and DOC_STATUT_CDE <>'REFUSEE' and DOC_TYPE_TRANSACTION='CA'
<SEPARATEUR>
/*A envoyer = [DOC_STATUT_CDE] = �A_ENVOYER� AND [DOC_DATE_IMP_CDE] NULL*/
update <PREFIXE_DW>DOCUMENTS set DOC_STATUT_CDE='A_ENVOYER' where [DOC_ETAT_CDE] = 'V' and [DOC_DATE_SIGNATURE_CDE] is not NULL and DOC_STATUT_CDE <>'REFUSEE' and DOC_TYPE_TRANSACTION='CA'
<SEPARATEUR>
/*Envoy�es = [DOC_DATE_IMP_CDE] NON NULL*/
update <PREFIXE_DW>DOCUMENTS set DOC_STATUT_CDE='ENVOYEE' where [DOC_DATE_IMP_CDE] is not NULL and DOC_STATUT_CDE <>'REFUSEE' and DOC_TYPE_TRANSACTION='CA'
<SEPARATEUR>
/*A r�ceptionner = [DOC_DATE_IMP_CDE] NON NULL AND [DOC_ETAT_CDE] in (�E�,�L�) and [DOC_DATE_LIVRAISON_CDE] >= DATE DU JOUR*/
update <PREFIXE_DW>DOCUMENTS set DOC_STATUT_CDE='A_RECEPTIONNER' where [DOC_DATE_IMP_CDE] is not NULL AND [DOC_ETAT_CDE] in ('E','L') and [DOC_DATE_LIVRAISON_CDE] >= GETDATE()  and DOC_STATUT_CDE <>'REFUSEE' and DOC_TYPE_TRANSACTION='CA'
<SEPARATEUR>
/*Calcul DOC_ETAT_CDE='L' livraison partielle*/
update <PREFIXE_DW>DOCUMENTS set DOC_ETAT_CDE='L',DOC_STATUT_CDE='LIVRAISON_PARTIELLE' where DOC_ETAT_CDE='E' and DOC_STATUT_CDE <>'REFUSEE' and DOC_NUMERO_CDE in (select DOC_NUMERO_CDE from <PREFIXE_DW>DOCUMENTS where DOC_TYPE_TRANSACTION='BR')
<SEPARATEUR>
/*R�ceptionn�e - Sold�e = [DOC_ETAT_CDE] =�S�*/
update <PREFIXE_DW>DOCUMENTS set DOC_STATUT_CDE='SOLDEE' where [DOC_ETAT_CDE] = 'S' and DOC_STATUT_CDE <>'REFUSEE' and DOC_TYPE_TRANSACTION='CA'
<SEPARATEUR>
/*Annul�e = [DOC_ETAT_CDE] =�Z�*/
update <PREFIXE_DW>DOCUMENTS set DOC_STATUT_CDE='ANNULEE' where [DOC_ETAT_CDE] = 'Z' and DOC_STATUT_CDE <>'REFUSEE' and DOC_TYPE_TRANSACTION='CA'
<SEPARATEUR>
/*Sign�e sans evt*/
update doc
set DOC_STATUT_CDE  = CASE WHEN EVE_IMP = 0 THEN 'A_ENVOYER'  ELSE DOC_STATUT_CDE END
from <PREFIXE_DW>DOCUMENTS doc, <PREFIXE_HA>CA_ENTET ent <WITHNOLOCK> 
where doc.DOC_TYPE_TRANSACTION     = 'CA' and DOC_NUMERO_DOC = NO_CDE and [SIGNEE] = 0x54 and [EVE_SIG] = 0 and [DOC_ETAT_CDE] = 'V'
<SEPARATEUR>
/*Refus�e (prime sur le reste avant)*/
update doc
set DOC_STATUT_CDE  = 'REFUSEE'
from <PREFIXE_DW>DOCUMENTS doc, <PREFIXE_HA>CA_ENTET ent <WITHNOLOCK> 
where doc.DOC_TYPE_TRANSACTION     = 'CA' and DOC_NUMERO_DOC = NO_CDE and [REFUSEE] = 0x54
<SEPARATEUR>
/*En attente (en dernier)*/
update <PREFIXE_DW>DOCUMENTS set DOC_STATUT_CDE='EN_ATTENTE' where [DOC_ETAT_CDE] = 'A'  and DOC_TYPE_TRANSACTION='CA' 

<SEPARATEUR>
/*lib modele cde*/
update doc set DOC_MODELE_LIBELLE_CDE=left(m.LIB_MOD,100) 
	from <PREFIXE_DW>DOCUMENTS doc , <PREFIXE_HA>M_CA m where doc.DOC_MODELE_CDE=m.COD_MOD and DOC_MODELE_LIBELLE_CDE<>left(m.LIB_MOD,100) 

<SEPARATEUR>
--MAJ    DOC_DATE_LIVRAISON_PREV_CDE 11/2025
update doc set DOC_DATE_LIVRAISON_PREV_CDE=CASE WHEN (c.DTE_LIV = ' ' OR c.DTE_LIV = '00000000' ) THEN NULL WHEN (c.DTE_LIV < '17530101') THEN NULL ELSE TRY_CONVERT (datetime,c.DTE_LIV ,103) END
	from <PREFIXE_DW>DOCUMENTS doc, <PREFIXE_HA>CA_PL_PR c where doc.DOC_NUMERO_CDE=c.NO_CA and DOC_NUMERO_LIGNE_CDE=c.NO_PO_CA
	    
<SEPARATEUR>
/*Recalcul DOC_DATE_SIGNATURE_CDE à null si commande annulee dossier 304340 12/2025*/
update doc set DOC_DATE_SIGNATURE_CDE=null 
	from <PREFIXE_DW>DOCUMENTS doc, <PREFIXE_HA>CA_ENTET ent where doc.DOC_NUMERO_CDE=ent.NO_CDE and ETAT_CDE='Z' and EVE_SIG=0          