";
if($res["DO_Domaine"] != 1){
$insert = "INSERT INTO f_livraison(CT_Num,LI_Intitule,LI_Adresse,LI_Complement,LI_CodePostal,LI_Ville,N_Expedition,N_Condition,LI_Principal,
LI_Telephone,LI_Telecopie,LI_EMail)
VALUES('".$tiers."','".$CT_Intitule."','".$CT_Adresse."','".$CT_Complement."','".$res_tiers["CT_CodePostal"]."','".$CT_Ville."',
1,1,1,'".$CT_Telephone."','".$CT_Telecopie."','".$CT_EMail."')";
if(odbc_exec($conn_siege, $insert)) {
} else echo $insert."
";
}
$cg_num_princ = $res_tiers["CG_NumPrinc"];
} else {
$verif_tiers = "SELECT CT_Type, CT_Num, CT_Facture, CT_Intitule, CT_Adresse, CT_Complement, CT_CodePostal, CT_Ville, CT_Telecopie,
CT_Telephone, CT_EMail, CT_Type, CG_NumPrinc FROM f_comptet WHERE CT_Num = '".$tiers."'";
$req_tiers = odbc_exec($conn_siege_sql, $verif_tiers);
$res_tiers = odbc_fetch_row($req_tiers);
$CT_Facture = odbc_result($req_tiers, "CT_Facture");
$CT_Intitule = mssql_addslashes(odbc_result($req_tiers, "CT_Intitule"));
$CT_Adresse = mssql_addslashes(odbc_result($req_tiers, "CT_Adresse"));
$CT_Complement = mssql_addslashes(odbc_result($req_tiers, "CT_Complement"));
$CT_CodePostal = odbc_result($req_tiers, "CT_CodePostal");
$CT_Ville = mssql_addslashes(odbc_result($req_tiers, "CT_Ville"));
$CT_Telecopie = odbc_result($req_tiers, "CT_Telecopie");
$CT_Telephone = odbc_result($req_tiers, "CT_Telephone");
$CT_EMail = odbc_result($req_tiers, "CT_EMail");
$cg_num_princ = odbc_result($req_tiers, "CG_NumPrinc");
if($ct_type == "") $ct_type = odbc_result($req_tiers,"CT_Type");
}
// if($ct_type == "1") $cg_num_princ = getCollectifFournisseur();
// else $cg_num_princ = getCollectifClient();
$DO_Type = $res["DO_Type"];
$DO_Type_sage = substr($DO_Type,-1);
$date_sage = "{d ".substr($res["DO_Date"],0,4)."-".substr($res["DO_Date"],5,2)."-".substr($res["DO_Date"],8,2)."}";
$recup_lino = "SELECT LI_No FROM f_livraison WHERE CT_Num = '".$tiers."' AND LI_Principal = 1";
$exec_lino = odbc_exec($conn_siege_sql, $recup_lino);
$lino = odbc_result($exec_lino, "LI_No");
/**** Création du LI_No si il n'existe pas ****/
if($lino == "" OR $lino == NULL) {
if($res["DO_Domaine"] != 1){
$insert_liv = "INSERT INTO f_livraison(CT_Num,LI_Intitule,LI_Adresse,LI_Complement,LI_CodePostal,LI_Ville,N_Expedition,N_Condition,LI_Principal,
LI_Telephone,LI_Telecopie,LI_EMail)
VALUES('".$tiers."','".$CT_Intitule."','".$CT_Adresse."','".$CT_Complement."','".$CT_CodePostal."','".$CT_Ville."',
1,1,1,'".$CT_Telephone."','".$CT_Telecopie."','".$CT_EMail."')";
$exec_insert = odbc_exec($conn_siege, $insert_liv);
$recup_lino = "SELECT LI_No FROM f_livraison WHERE CT_Num = '".$tiers."' AND LI_Principal = 1";
$exec_lino = odbc_exec($conn_siege_sql, $recup_lino);
$lino = odbc_result($exec_lino, "LI_No");
}
}
$do_piece_encours = $res["DO_Piece"];
$do_type_encours = $res["DO_Type"];
$tab_regl[] = $do_piece_encours."-".$tiers."-".$res["DO_Domaine"]."-".$DO_Type;
if($do_piece_encours != $do_piece_ancien) {
$id = $res["DO_Domaine"]."|".$res["DO_Type"]."|".$res["DO_Piece"];
mysql_query("ALTER TABLE `m_erreur` DROP PRIMARY KEY , ADD PRIMARY KEY ( `id` , `ligne` ) ;", $conn_siege_mysql);
$delete = "DELETE FROM m_erreur WHERE id = '".$id."'";
mysql_query($delete, $conn_siege_mysql);
/*** Création du F_DOCENTETE (MISE A JOUR SI IL EXISTE) ***/
$select_siege_entete = "SELECT COUNT(DO_Piece) AS NB_DOC FROM F_DOCENTETE
WHERE (piece_caisse = '".$res["DO_Piece"]."' OR DO_Piece = '".$res["DO_Piece"]."') AND DO_Domaine = ".$res["DO_Domaine"]." AND DO_Type = ".$DO_Type." AND piece_caisse <> ''";
$exec_siege_entete = odbc_exec($conn_siege_sql, $select_siege_entete);
$nb_exec_siege_entete = odbc_result($exec_siege_entete, "NB_DOC");
// echo $nb_exec_siege_entete." - ";
// if($DO_Type == 3) {
// $DO_Souche = getSouche();
$recup_souche = "SELECT DC_Piece FROM f_doccurrentpiece WHERE DC_Domaine = ".$res["DO_Domaine"]." AND DC_IdCol = ".$DO_Type_sage." AND DC_Souche = ".$DO_Souche;
$query_souche = odbc_exec($conn_siege_sql, $recup_souche);
$piece_souche = odbc_result($query_souche, "DC_Piece");
// if($type_connexion == "SQL") $piece_du_document = $res["DO_Piece"];
$piece_du_document = $piece_souche;
// } else {
// $DO_Souche = getSouche();
// }
$delete_document = 0;
// Si document existe déjà
if($nb_exec_siege_entete > 0) {
// Récupération du vrai DO_Piece côté serveur SAGE
$select_siege_recup_piece = "SELECT DO_Piece FROM F_DOCENTETE
WHERE (piece_caisse = '".$res["DO_Piece"]."' OR DO_Piece = '".$res["DO_Piece"]."') AND DO_Domaine = ".$res["DO_Domaine"]." AND DO_Type = ".$DO_Type." AND piece_caisse <> ''";
$exec_siege_recup_piece = odbc_exec($conn_siege_sql, $select_siege_recup_piece);
$piece_sage = odbc_result($exec_siege_recup_piece, "DO_Piece");
// Suppression des lignes avec piece_caisse ou do_piece (car piece_caisse == "" si document crée sur serveur)
$requete_delete = "DELETE FROM f_docligne WHERE DO_Piece = '".$piece_sage."' AND DO_Domaine = ".$res["DO_Domaine"]." AND DO_Type = ".$DO_Type."";
$exec_delete = odbc_exec($conn_siege, $requete_delete);
// Suppression de l'entête
// $requete_delete = "DELETE FROM F_DOCENTETE WHERE DO_Piece = '".$piece_sage."' AND DO_Domaine = ".$res["DO_Domaine"]." AND DO_Type = ".$DO_Type."";
// $exec_delete = odbc_exec($conn_siege, $requete_delete);
$piece_du_document = $piece_sage;
$delete_document = 1;
}
// if($piece_du_document == $res["DO_Piece"]) die("Erreur: numéro de pièce identique".$piece_du_document);
$re_no = $res["RE_No"];
if($re_no == "") $re_no = 0;
$requete_code_postal = "SELECT code_postal FROM z_adresse WHERE DO_Piece = '".$res["DO_Piece"]."' AND DO_Domaine = '".$res["DO_Domaine"]."' AND DO_Type = '".$res["DO_Type"]."'";
$exec_code_postal = mysql_query($requete_code_postal, $conn_mag);
$res_code_postal = mysql_fetch_array($exec_code_postal);
$code_postal = $res_code_postal["code_postal"];
$do_date_livr = "{d ".substr($res["DO_DateLivr"],0,4)."-".substr($res["DO_DateLivr"],5,2)."-".substr($res["DO_DateLivr"],8,2)."}";
if($do_date_livr == "{d 0000-00-00}" || $do_date_livr == "{d --}") $do_date_livr = $date_sage;
switch($res["DO_Domaine"]) {
case 2:
$reference = $res["CT_Num"]."-".substr($re_no,0,2)."-".substr($res["DO_Date"],0,4)."-".substr($res["DO_Date"],5,2)."-".substr($res["DO_Date"],8,2);
$insert_mvt = "INSERT INTO F_DOCENTETE (DO_Domaine, DO_Type, DO_Piece, DO_Date, DO_Tiers, DO_Ref, piece_caisse)
VALUES (".$res["DO_Domaine"].", ".$DO_Type.", '".$piece_du_document."', '".$date_sage."', '".$res["CT_Num"]."', '".$reference."', '".$res["DO_Piece"]."')";
if(odbc_exec($conn_siege, $insert_mvt)) {
} else echo $insert_mvt."
";
break;
case 1:
$insert_docentete = "insert into f_docentete (do_domaine, do_type, do_piece, do_date, do_tiers, de_no,do_statut, ct_numpayeur,do_period,do_expedit,
do_condition,do_tarif,do_typecolis,n_catcompta, cg_num,do_ref, DO_BlFact, MR_No, DO_Souche, top_bascule, co_no, piece_caisse)
VALUES (".$res["DO_Domaine"].", ".$DO_Type.", '".$piece_du_document."', '".$date_sage."',
'".$res["CT_Num"]."', ".$res["DE_No"].", 2, '".$res["CT_Num"]."',1,1,1,1,1,1,'".$cg_num_princ."',
'".$reference."',0, -1, 0, 'N', ".$re_no.",'".$res["DO_Piece"]."')";
if(odbc_exec($conn_siege, $insert_docentete)){
} else {
echo $insert_docentete."
";
}
break;
default:
$select_regl = "SELECT P_REGLEMENT.R_Intitule, Z_DOCREGL.DR_Montant, Z_DOCREGL.DR_Equil FROM Z_DOCREGL, P_REGLEMENT
WHERE Z_DOCREGL.DO_Piece = '".$res["DO_Piece"]."' AND Z_DOCREGL.DO_Domaine = '".$res["DO_Domaine"]."' AND Z_DOCREGL.DO_Type = '".$res["DO_Type"]."'
AND P_REGLEMENT.cbIndice = Z_DOCREGL.N_Reglement";
$exec_regl = mysql_query($select_regl, $conn_mag);
$libelle_reglement = array("", "", "", "", "", "", "", "", "", "");
$acompte = array(0, 0, 0);
$libelle_acompte = array("", "", "");
$cpt_reglement = 0;
$cpt_acompte = 0;
while($res_regl = mysql_fetch_array($exec_regl)) {
$is_acompte = $res_regl["DR_Equil"];
$libelle_regl = mssql_addslashes($res_regl["R_Intitule"]);
$tab_lib = explode("&", $libelle_regl);
if($is_acompte == 1) {
$libelle_reglement[$cpt_reglement] = $tab_lib[0]."&".$res_regl["DR_Montant"];
$cpt_reglement++;
} else {
$libelle_acompte[$cpt_acompte] = $tab_lib[0];
$acompte[$cpt_acompte] = $res_regl["DR_Montant"];
$cpt_acompte++;
}
}
if($gestion_analytique == "O") {
$CA_Num = str_pad($res["DE_No"], 3, "0", STR_PAD_LEFT);
$insert_docentete = "insert into f_docentete (do_domaine, do_type, do_piece, do_date, do_tiers, de_no,do_statut, ct_numpayeur,do_period,do_expedit,
do_condition,do_tarif,do_typecolis,n_catcompta, cg_num,li_no,do_ref, DO_NbFacture, DO_Souche, top_bascule, ".$intitule_no.", DO_Coord03, piece_caisse, DO_DateLivr,
reglement_1, reglement_2, reglement_3, reglement_4, reglement_5, reglement_6, reglement_7, reglement_8, reglement_9, reglement_10,
acompte_1, libelle_acompte_1, acompte_2, libelle_acompte_2, acompte_3, libelle_acompte_3, CA_Num)
VALUES (".$res["DO_Domaine"].", ".$DO_Type.", '".$piece_du_document."', '".$date_sage."',
'".$res["CT_Num"]."', ".$res["DE_No"].", 2, '".$res["CT_Num"]."',1,1,1,1,1,".$n_catcompta_entete.",'".$cg_num_princ."',".$lino.",
'".$res["DO_Piece"]."',".$CT_Facture.", ".$DO_Souche.", 'N', ".$re_no.", '".$code_postal."', '".$res["DO_Piece"]."', '".$do_date_livr."',
'".$libelle_reglement[0]."', '".$libelle_reglement[1]."', '".$libelle_reglement[2]."', '".$libelle_reglement[3]."',
'".$libelle_reglement[4]."', '".$libelle_reglement[5]."', '".$libelle_reglement[6]."', '".$libelle_reglement[7]."',
'".$libelle_reglement[8]."', '".$libelle_reglement[9]."', ".$acompte[0].", '".$libelle_acompte[0]."',
".$acompte[1].", '".$libelle_acompte[1]."', ".$acompte[2].", '".$libelle_acompte[2]."', '".$CA_Num."')";
} else {
$insert_docentete = "insert into f_docentete (do_domaine, do_type, do_piece, do_date, do_tiers, de_no,do_statut, ct_numpayeur,do_period,do_expedit,
do_condition,do_tarif,do_typecolis,n_catcompta, cg_num,li_no,do_ref, DO_NbFacture, DO_Souche, top_bascule, ".$intitule_no.", DO_Coord03, piece_caisse, DO_DateLivr,
reglement_1, reglement_2, reglement_3, reglement_4, reglement_5, reglement_6, reglement_7, reglement_8, reglement_9, reglement_10,
acompte_1, libelle_acompte_1, acompte_2, libelle_acompte_2, acompte_3, libelle_acompte_3)
VALUES (".$res["DO_Domaine"].", ".$DO_Type.", '".$piece_du_document."', '".$date_sage."',
'".$res["CT_Num"]."', ".$res["DE_No"].", 2, '".$res["CT_Num"]."',1,1,1,1,1,".$n_catcompta_entete.",'".$cg_num_princ."',".$lino.",
'".$res["DO_Piece"]."',".$CT_Facture.", ".$DO_Souche.", 'N', ".$re_no.", '".$code_postal."', '".$res["DO_Piece"]."', '".$do_date_livr."',
'".$libelle_reglement[0]."', '".$libelle_reglement[1]."', '".$libelle_reglement[2]."', '".$libelle_reglement[3]."',
'".$libelle_reglement[4]."', '".$libelle_reglement[5]."', '".$libelle_reglement[6]."', '".$libelle_reglement[7]."',
'".$libelle_reglement[8]."', '".$libelle_reglement[9]."', ".$acompte[0].", '".$libelle_acompte[0]."',
".$acompte[1].", '".$libelle_acompte[1]."', ".$acompte[2].", '".$libelle_acompte[2]."')";
}
if($delete_document == 0) {
if(odbc_exec($conn_siege, $insert_docentete)) {
} else echo $insert_docentete."
";
}
break;
}
if($ligne_vide == 0 && $do_piece_ancien != "") {
// Suppression de l'entête
echo $requete_delete = "DELETE FROM F_DOCENTETE WHERE piece_caisse = '".$do_piece_ancien."' AND DO_Domaine = ".$res["DO_Domaine"]." AND DO_Type = ".$do_type_ancien."";
$exec_delete = odbc_exec($conn_siege, $requete_delete);
}
$do_piece_ancien = $do_piece_encours;
$do_type_ancien = $do_type_encours;
if($delete == 1 && $type_connexion == "SQL") {
echo $recup_souche = "UPDATE f_doccurrentpiece SET DC_Piece = '".$piece_souche."' WHERE DC_Domaine = ".$res["DO_Domaine"]." AND DC_IdCol = ".$DO_Type." AND DC_Souche = ".$DO_Souche;
$query_souche = odbc_exec($conn_siege_sql, $recup_souche);
}
if($res["DL_PieceBL"] != "" && $res["DL_PieceBL"] != " " && $res["DL_PieceBL"] != NULL) {
$select_siege_recup_piece_ancien = "SELECT DO_Piece FROM F_DOCENTETE
WHERE DO_Piece = '".$res["DL_PieceBL"]."' AND DO_Domaine = ".$res["DO_Domaine"]." AND DO_Type = ".$res["type_ancien"]."";
$exec_siege_recup_piece_ancien = odbc_exec($conn_siege_sql, $select_siege_recup_piece_ancien);
$piece_sage_ancien = odbc_result($exec_siege_recup_piece_ancien, "DO_Piece");
echo $requete_delete = "DELETE FROM f_docligne WHERE DO_Piece = '".$res["DL_PieceBL"]."' AND DO_Domaine = ".$res["DO_Domaine"]." AND DO_Type = ".$res["type_ancien"]."";
$exec_delete = odbc_exec($conn_siege, $requete_delete);
echo $requete_delete = "DELETE FROM F_DOCENTETE WHERE DO_Piece = '".$res["DL_PieceBL"]."' AND DO_Domaine = ".$res["DO_Domaine"]." AND DO_Type = ".$res["type_ancien"]."";
$exec_delete = odbc_exec($conn_siege, $requete_delete);
} else $piece_sage_ancien = "";
$ligne_vide = 0;
}
if($Z_Solde == "N") {
$AR_Ref = $res["AR_Ref"];
if($AR_Ref == " ") $AR_Ref = "";
$dl_valorise = $res["DL_Valorise"];
$dl_ttc = $res["DL_TTC"];
$dl_taxe1 = $res["DL_Taxe1"];
$select_suivistock = "SELECT AR_SuiviStock, AR_Nomencl FROM f_article WHERE AR_Ref = '".$AR_Ref."'";
$query_suivistock = odbc_exec($conn_siege_sql, $select_suivistock);
$ar_suivistock = odbc_result($query_suivistock, "AR_SuiviStock");
$AR_Nomencl = odbc_result($query_suivistock, "AR_Nomencl");
if($ar_suivistock == 0) $DE_No = "0";
else $DE_No = $res["DE_No"];
if($AR_Nomencl == 2) $AR_Ref_Compose = $AR_Ref;
else $AR_Ref_Compose = $res["AR_RefCompose"];
$ls_noserie = $res["LS_NoSerie"];
if($AR_Ref == "") {
$insert = "insert into f_docligne (DO_Domaine, DO_Type, CT_Num, DO_Piece, DO_Date, DL_Ligne, DL_Design, piece_caisse)
VALUES(".$res["DO_Domaine"].", ".$DO_Type.", '".$res["CT_Num"]."', '".$piece_du_document."', '".$date_sage."', ".$res["DL_Ligne"].",
'".mssql_addslashes($res["DL_Design"])."','".$res["DO_Piece"]."')";
} else {
$DL_QteOrigine = $res["DL_QteBL"];
if($DL_QteOrigine == "" || $DL_QteOrigine == " ") $DL_QteOrigine = 0;
$DateBL = $res["DL_DateBL"];
if($DateBL == "" || $DateBL == " " || $DateBL == "0000-00-00 00:00:00") $DateBL = $date_sage;
else $DateBL = "{d ".substr($DateBL,0,4)."-".substr($DateBL,5,2)."-".substr($DateBL,8,2)."}";
switch($res["DO_Domaine"]) {
case 2:
$insert = "INSERT INTO f_docligne (DO_Domaine, DO_Type, CT_Num, DO_Piece, DL_Design, DL_Ligne, AR_Ref, DL_Qte, EU_Qte, DL_Valorise, DO_Date, DE_No,
DL_No, DL_PrixRU, DL_PrixUnitaire, DL_TTC, DL_Remise01REM_Valeur, DL_Remise01REM_Type, piece_caisse, CA_Num)
VALUES (".$res["DO_Domaine"].", ".$DO_Type.", '".$res["CT_Num"]."', '".$piece_du_document."', '".mssql_addslashes($res["DL_Design"])."',
".$res["DL_Ligne"].", '".$AR_Ref."', ".$res["DL_Qte"].", ".$res["EU_Qte"].", 1, '".$date_sage."', ".$DE_No.",
0, 0, 0, 0, 0, 0,'".$res["DO_Piece"]."', '".$CA_Num."')";
break;
case 1:
//if($res["DO_Domaine"] == "1"){ $DE_No = "0"; }
$insert = "insert into f_docligne (DO_Domaine, DO_Type, CT_Num, DO_Piece, DO_Date, DL_Ligne, AR_Ref, DL_Design,
DL_Remise01REM_Valeur, DL_Remise01REM_Type,dl_remise02REM_Valeur,dl_remise02REM_Type, DL_PrixUnitaire, DL_Qte, EU_Qte,
".$intitule_no.", DE_No, ag_no1, ag_no2, dl_valorise, dl_no, DL_Taxe1, DL_PieceBC, DL_DateBC, DL_QteBC, Z_Parc, ".$champ_serie.", AR_RefCompose, piece_caisse, DO_DateLivr, CA_Num)
VALUES(".$res["DO_Domaine"].", ".$DO_Type.", '".$res["CT_Num"]."', '".$piece_du_document."', '".$date_sage."', ".$res["DL_Ligne"].", '".$AR_Ref."',
'".mssql_addslashes($res["DL_Design"])."', ".$res["DL_Remise01REM_Valeur"].", 1, 0, 1, ".$res["DL_PrixUnitaire"].", ".$res["DL_Qte"].", ".$res["DL_Qte"].",
".$re_no.", ".$DE_No.", ".$res["AG_No1"].", ".$res["AG_No2"].", ".$dl_valorise.", 0,
".$dl_taxe1.", '".$piece_sage_ancien."', '".$date_sage."', ".$res["DL_Qte"].", '".$res["Z_Parc"]."', '".$ls_noserie."', '".$AR_Ref_Compose."','".$res["DO_Piece"]."', '".$do_date_livr."', '".$CA_Num."')";
break;
default:
$insert = "insert into f_docligne (DO_Domaine, DO_Type, CT_Num, DO_Piece, DO_Date, DL_Ligne, AR_Ref,
DL_Design, DL_Remise01REM_Valeur, DL_Remise01REM_Type,dl_remise02REM_Valeur,dl_remise02REM_Type, DL_PrixUnitaire, DL_PUTTC,
DL_TTC, DL_MontantHT, DL_MontantTTC, DL_Qte, EU_Qte,
".$intitule_no.", DE_No, ag_no1, ag_no2, dl_valorise, dl_no, DL_Taxe1, DL_PieceBC, DL_DateBC, DL_QteBC, Z_Parc, ".$champ_serie.", AR_RefCompose, piece_caisse, DO_DateLivr, CA_Num)
VALUES(".$res["DO_Domaine"].", ".$DO_Type.", '".$res["CT_Num"]."', '".$piece_du_document."', '".$date_sage."', ".$res["DL_Ligne"].", '".$AR_Ref."',
'".mssql_addslashes($res["DL_Design"])."', ".$res["DL_Remise01REM_Valeur"].", 1, 0, 1, ".$res["DL_PrixUnitaire"].", ".$res["DL_PUTTC"].",
".$dl_ttc.", 0, 0, ".$res["DL_Qte"].", ".$res["DL_Qte"].",
".$re_no.", ".$DE_No.", ".$res["AG_No1"].", ".$res["AG_No2"].", ".$dl_valorise.", 0,
".$dl_taxe1.", '".$piece_sage_ancien."', '".$date_sage."', ".$res["DL_Qte"].", '".$res["Z_Parc"]."', '".$ls_noserie."', '".$AR_Ref_Compose."','".$res["DO_Piece"]."', '".$do_date_livr."', '".$CA_Num."')";
break;
}
}
if($Z_Supprime != "A") {
if(odbc_exec($conn_siege, $insert)) {
if($ls_noserie != "" && $ls_noserie != " ") {
$select_serie = "SELECT COUNT(AR_Ref) AS NB_REF FROM f_article WHERE AR_Ref= '".$Z_Parc."'";
$exec_serie = odbc_exec($conn_siege_sql, $select_serie);
$res_serie = odbc_fetch_row($exec_serie);
$nb_serie = odbc_result($exec_serie, "NB_REF");
if($nb_serie == 0) {
$select_num_serie = "SELECT AR_Ref, AR_Design, AR_Garantie, FA_CodeFamille, AR_UniteVen, Z_NoSerie, Z_NoSerie2, Z_InfosComp, ZCT_Num
FROM f_article WHERE AR_Ref = '".$Z_Parc."'";
$exec_num_serie = mysql_query($select_num_serie, $conn_mag);
$res_num_serie = mysql_fetch_array($exec_num_serie);
$design = mssql_addslashes($res_num_serie["AR_Design"]);
$insert_parc = "INSERT INTO f_article (AR_Ref, AR_Design, AR_Garantie, FA_CodeFamille, AR_UniteVen, Z_NoSerie, Z_NoSerie2, Z_InfosComp, ZCT_Num, AR_Sommeil)
VALUES ('".$res_num_serie["AR_Ref"]."', '".$design."', ".$res_num_serie["AR_Garantie"].", '".$res_num_serie["FA_CodeFamille"]."', 1, '".$res_num_serie["Z_NoSerie"]."', '".$res_num_serie["Z_NoSerie2"]."',
'".$res_num_serie["Z_InfosComp"]."', '".$res_num_serie["ZCT_Num"]."', 1)";
$exec_parc = odbc_exec($conn_siege, $insert_parc);
}
}
$update_piece = "UPDATE f_docligne SET Z_TOP = 'O' WHERE DO_Piece = '".$res["DO_Piece"]."' AND DL_Ligne = ".$res["DL_Ligne"]." AND DO_Domaine = ".$res["DO_Domaine"]." AND DO_Type = ".$res["DO_Type"]." AND Z_Top = 'N'";
$exec_piece = mysql_query($update_piece, $conn_mag);
} else {
echo $insert."
";
// die($insert);
// Suppresion des lignes
echo $requete_delete = "DELETE FROM f_docligne WHERE DO_Piece = '".$piece_du_document."' AND DO_Domaine = ".$res["DO_Domaine"]." AND DO_Type = ".$DO_Type;
$exec_delete = odbc_exec($conn_siege, $requete_delete);
// Suppression de l'entête
echo $requete_delete = "DELETE FROM F_DOCENTETE WHERE DO_Piece = '".$piece_du_document."' AND DO_Domaine = ".$res["DO_Domaine"]." AND DO_Type = ".$DO_Type;
$exec_delete = odbc_exec($conn_siege, $requete_delete);
$update_piece = "UPDATE f_docligne SET Z_TOP = 'N' WHERE DO_Piece = '".$res["DO_Piece"]."' AND DO_Domaine = ".$res["DO_Domaine"]." AND DO_Type = ".$res["DO_Type"]." AND Z_Top NOT IN ('A', 'S')";
$exec_piece = mysql_query($update_piece, $conn_mag);
$err = odbc_errormsg($conn_siege);
$date_err = date("Ymd H:i:s");
$insert = mssql_addslashes($insert);
$err = mssql_addslashes($err);
// if($mail == 0 && $mail_erreur != "") {
// $smtp = getMailSMTP();
// $err = str_replace("'", " ",$err);
// $err = str_replace(",", " ",$err);
// $err = str_replace(".", " ",$err);
// require(dirname(__FILE__)."/../../script/plugin/phpmailer/class.phpmailer.php");
// $mail = new PHPmailer();
// $mail->IsSMTP();
// $mail->IsHTML(true);
// $mail->Host=$smtp;
// $mail->From=$mail_erreur;
// $mail->AddAddress($mail_erreur);
// $mail->Body=$err;
// $mail->SMTPAuth = true; // turn on SMTP authentication
// $mail->Username = "ton adresse mail"; // SMTP username
// $mail->Password = "ton mdp messagerie";
// $mail->Send();
// $mail->SmtpClose();
// unset($mail);
// $mail++;
// }
/***** VERIF STRUCTURE m_erreur *****/
// Pour vérifier que la table «personne» contient bien les colonnes «id», «nom», «prenom».
$nomTable = 'm_erreur';
$nomColonnes = array('id','requete','erreur','date','ligne');
// $nomColonnes = sort($nomColonnes);
$resultat = mysql_query("SELECT * FROM $nomTable", $conn_siege_mysql); // Le «LIMIT 1» peut être enlevé, car je crois qu’il n’accélère pas la requête.
if ($resultat && mysql_num_rows($resultat) !== 0) {
if(array_keys(mysql_fetch_assoc($resultat)) == $nomColonnes) echo "";
else {
mysql_query("DROP TABLE m_erreur", $conn_siege_mysql);
mysql_query("CREATE TABLE IF NOT EXISTS `m_erreur` (
`id` varchar(30) NOT NULL,
`requete` varchar(500) NOT NULL,
`erreur` varchar(500) NOT NULL,
`date` varchar(14) NOT NULL,
`ligne` INT(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;",$conn_siege_mysql);
}
} else {
mysql_query("CREATE TABLE IF NOT EXISTS `m_erreur` (
`id` varchar(30) NOT NULL,
`requete` varchar(500) NOT NULL,
`erreur` varchar(500) NOT NULL,
`date` varchar(14) NOT NULL,
`ligne` INT(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;",$conn_siege_mysql);
}
/**************************/
$id = $res["DO_Domaine"]."|".$res["DO_Type"]."|".$res["DO_Piece"];
$insert_erreur = "INSERT INTO m_erreur (id, requete, erreur, date, ligne) VALUES ('".$id."','".$insert."', '".$err."', '".$date_err."','".$res["DL_Ligne"]."')";
$exec_erreur = mysql_query($insert_erreur, $conn_siege_mysql);
}
$ligne_vide++;
}
} else {
$update_piece = "UPDATE f_docligne SET Z_TOP = 'O' WHERE DO_Piece = '".$res["DO_Piece"]."' AND DL_Ligne = ".$res["DL_Ligne"]." AND DO_Domaine = ".$res["DO_Domaine"]." AND DO_Type = ".$res["DO_Type"]." AND Z_Top = 'N'";
$exec_piece = mysql_query($update_piece, $conn_mag);
}
$do_piece = $res["DO_Piece"];
if($nb_exec == $cpt && $ligne_vide == 0) {
echo $requete_delete = "DELETE FROM F_DOCENTETE WHERE piece_caisse = '".$do_piece_ancien."' AND DO_Domaine = ".$res["DO_Domaine"]." AND DO_Type = ".$do_type_ancien."";
$exec_delete = odbc_exec($conn_siege, $requete_delete);
$update_piece = "UPDATE f_docligne SET Z_TOP = 'O' WHERE DO_Piece = '".$do_piece_ancien."' AND DO_Domaine = ".$res["DO_Domaine"]." AND DO_Type = ".$do_type_ancien." AND Z_Top = 'N'";
$exec_piece = mysql_query($update_piece, $conn_mag);
}
}
?>