Blog PlanningPME

Suivez l'actualité de votre logiciel de planning

Synchronisation des clients avec Batigest

Voici le script qui vous permettra de synchroniser les clients à partir du logiciel Batigest en base Access vers PlanningPME.

'Connection to PlanningPME
'Register PlanningPME.dll before -> c:\windows\system32\regsvr32 PlanningPME.dll
Set ppme = CreateObject("PlanningPME.Application")
ppme.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=P:\Documentation\Intégrations\Access\BATIGEST\Batigest2.pp"
ppme.Connect

'Connection to Excel
Set Connection = CreateObject("ADODB.Connection")
'VB
Connection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=P:\Documentation\Intégrations\Access\BATIGEST\BatigArt.mdb"

Set rs = CreateObject("ADODB.Recordset")

Set search = CreateObject("ADODB.Recordset")

rs.Open "select Code, Nom, Civilite, Interloc, Adr, SuiteAdr, CP, Ville, Pays, Tel, Portable, Fax, EMail, Compte, ModeReg, Domiciliation,T VAIntracom from [Client]", Connection

'Parse Excel file and create custumer if not exist

While rs.EOF = False

    Set c = ppme.CreateItem(4) 'PpDoCustumer
   
    ' CUSTOMER_ID non vide
    If IsNull(rs.Fields("Code")) = False Then
   
        c.Number = rs.Fields("Code")
       
        ' search the custumer in planningpme
        search.Open "select IDX_CLIENT from CLIENT where NUMERO_CLIENT='" & c.Number & "'", ppme.Connection
        ' if exist load the object
        If search.EOF = False Then
            c.Key = search.Fields("IDX_CLIENT")
            c.Load2
        End If
   
        'Create Custumer with PlanningPME object
        If IsNull(rs.Fields("NOM")) = False Then
            c.Company = rs.Fields("NOM") & " " & rs.Fields("Civilite")
        End If
       
        If IsNull(rs.Fields("Interloc")) = False Then
           c.LastName = rs.Fields("Interloc")
        End If
         
           c.FirstName = ""
                 
        If IsNull(rs.Fields("Adr")) = False Then
            c.Adress = rs.Fields("Adr") & "" & rs.Fields("SuiteAdr")
        End If
       
        If IsNull(rs.Fields("CP")) = False Then
            c.ZIP = rs.Fields("CP")
        End If
              
        If IsNull(rs.Fields("Ville")) = False Then
            c.City = rs.Fields("Ville")
        End If
       
        If IsNull(rs.Fields("PAYS")) = False Then
            c.Country = rs.Fields("PAYS")
        End If

        If IsNull(rs.Fields("EMAIL")) = False Then
            c.Email = rs.Fields("EMAIL")
        End If
       
        If IsNull(rs.Fields("Tel")) = False Then
            c.Phone = rs.Fields("Tel")
        End If

        If IsNull(rs.Fields("Portable")) = False Then
            c.Mobile = rs.Fields("Portable")
        End If
       
        If IsNull(rs.Fields("FAX")) = False Then
            c.Fax = rs.Fields("FAX")
        End If
       
        'Declaration AddFields
        Compte = rs.Fields("Compte")
        ModeReg = rs.Fields("ModeReg")
        Domiciliation = rs.Fields("Domiciliation")
        TVA = rs.Fields("TVAIntracom")
               
        If c.Fields.Count > 3 Then
            c.Fields.Item(0).Value = Compte
            c.Fields.Item(1).Value = ModeReg
            c.Fields.Item(2).Value = Domiciliation
            c.Fields.Item(3).Value = TVA
        End If
                   
           
        c.Save
       
        search.Close
       
    End If
   
rs.MoveNext

Wend

 

Ajouter un commentaire

Loading