Example #1
0
        public Task <int> Update(Client client)
        {
            lock (_sageDataAccess.DatabaseLock)
            {
                if (Utility.ComObject.Open(_sageDataAccess) == false)
                {
                    throw new Exception("Error while opening the com database");
                }
                if (_sageDataAccess.GetSageDatabase.CptaApplication.FactoryClient.ExistNumero(client.SageCode) == false)
                {
                    Utility.ComObject.Close(_sageDataAccess);
                    throw new Exception("Error client not found");
                }

                try
                {
                    IBOClient3 sageClient = _sageDataAccess.GetSageDatabase.CptaApplication.FactoryClient.ReadNumero(client.SageCode);
                    sageClient = ObjectMapper.UpdateClientToIboClient(client, sageClient);
                    Utility.ComObject.Close(_sageDataAccess);
                    return(Task.FromResult(1));
                }catch (Exception e)
                {
                    Utility.ComObject.Close(_sageDataAccess);
                    throw;
                }
            }
        }
Example #2
0
        public static IBOClient3 UpdateClientToIboClient(Client client, IBOClient3 sageClient)
        {
            sageClient.CT_Siret       = client.Siret;       // check
            sageClient.CT_Intitule    = client.CompanyName; // check
            sageClient.CT_Qualite     = client.LegalForm;
            sageClient.CT_Ape         = client.Naf;
            sageClient.CT_Classement  = client.CompanyName.Length > 17 ? client.CompanyName.Substring(0, 17) : client.CompanyName;
            sageClient.CT_Identifiant = client.VatIdentifier;

            sageClient.Telecom.EMail     = client.CompanyEmail;
            sageClient.Telecom.Telephone = client.OwnerPhoneNumber;
            sageClient.Telecom.EMail     = client.CompanyEmail;
            sageClient.Telecom.Portable  = client.CompanyMobile;
            sageClient.Telecom.Telecopie = client.CompanyFax;
            sageClient.Telecom.Telephone = client.CompanyMobile;

            sageClient.Adresse.Adresse    = client.MainAddress.MainAddress;
            sageClient.Adresse.Complement = client.MainAddress.AdressAdditional;
            sageClient.Adresse.CodePostal = client.MainAddress.ZipCode;
            sageClient.Adresse.Ville      = client.MainAddress.City;
            sageClient.Adresse.Pays       = client.MainAddress.Country;
            sageClient.CT_Identifiant     = client.VatIdentifier;
            sageClient.WriteDefault();
            // To do add delivery add
            return(sageClient);
        }
Example #3
0
 public Task <int> Delete(string ct_num)
 {
     lock (_sageDataAccess.DatabaseLock)
     {
         if (Utility.ComObject.Open(_sageDataAccess) == false)
         {
             throw new Exception("Error while opening the com database");
         }
         if (_sageDataAccess.GetSageDatabase.CptaApplication.FactoryClient.ExistNumero(ct_num) == false)
         {
             Utility.ComObject.Close(_sageDataAccess);
             throw new Exception("Error client not found");
         }
         try
         {
             IBOClient3 client = _sageDataAccess.GetSageDatabase.CptaApplication.FactoryClient.ReadNumero(ct_num);
             client.Remove();
             Utility.ComObject.Close(_sageDataAccess);
             return(Task.FromResult(1));
         }catch (Exception e)
         {
             Utility.ComObject.Close(_sageDataAccess);
             throw;
         }
     }
 }
Example #4
0
        public Task <string> Create(Client client)
        {
            lock (_sageDataAccess.DatabaseLock)
            {
                if (Utility.ComObject.Open(_sageDataAccess) == false)
                {
                    throw new Exception("Error while opening the com database");
                }

                try
                {
                    IBOClient3 sageClient = (IBOClient3)_sageDataAccess.GetSageDatabase.CptaApplication.FactoryClient.Create();
                    sageClient.CT_Num          = _sageDataAccess.GetSageDatabase.CptaApplication.FactoryTiersType.ReadTypeTiers(TiersType.TiersTypeClient).NextCT_Num;
                    sageClient.CategorieCompta = _sageDataAccess.GetSageDatabase.FactoryCategorieComptaVente.ReadIntitule("France"); // TO DO add other country and new VAT ID EU / EXO / FR / DOM 7,5.5,20,0 %
                    sageClient.CompteGPrinc    = (IBOCompteG3)_sageDataAccess.GetSageDatabase.CptaApplication.FactoryCompteG.ReadNumero("411000");
                    sageClient = ObjectMapper.CreateClientToIboClient(client, sageClient);
                    Utility.ComObject.Close(_sageDataAccess);
                    return(Task.FromResult(sageClient.CT_Num));
                }
                catch (Exception ex) when((ex.Message.Equals("Cet élément est en cours d'utilisation !")))
                {
                    Utility.ComObject.Close(_sageDataAccess);
                    throw new Exception("Element in use");
                }
                catch (Exception e)
                {
                    Utility.ComObject.Close(_sageDataAccess);
                    throw new Exception($"Error while creating user {e}");
                }
            }
        }
Example #5
0
        public Task <string> Create(Order order)
        {
            lock (_sageAccess.DatabaseLock)
            {
                if (Utility.ComObject.Open(_sageAccess) == false)
                {
                    Utility.ComObject.Close(_sageAccess);
                    return(null);
                }
                IBODocumentVente3      orderHeader = _sageAccess.GetSageDatabase.FactoryDocumentVente.CreateType(DocumentType.DocumentTypeVenteCommande);
                IBOClient3             tiersPayeur = _sageAccess.GetSageDatabase.CptaApplication.FactoryClient.ReadNumero(order.DO_Tiers);
                IBODocumentVenteLigne3 orderLines;

                try
                {
                    orderHeader.SetDefaultClient(tiersPayeur);
                    orderHeader.DO_Ref    = order.DO_Ref;
                    orderHeader.DO_Date   = DateTime.Now;
                    orderHeader.DO_Statut = DocumentStatutType.DocumentStatutTypeConfirme;
                    orderHeader.SetDefaultDO_Piece();
                    orderHeader.WriteDefault();
                    orderHeader.CouldModified();
                    orderHeader.Write();

                    foreach (DocLine docLine in order.DocLines)
                    {
                        if (_sageAccess.GetSageDatabase.FactoryArticle.ExistReference(docLine.AR_Ref))
                        {
                            orderLines = (IBODocumentVenteLigne3)orderHeader.FactoryDocumentLigne.Create();
                            orderLines.SetDefaultArticle(_sageAccess.GetSageDatabase.FactoryArticle.ReadReference(docLine.AR_Ref), docLine.DL_Qte);
                            orderLines.WriteDefault();
                        }
                        else
                        {
                            //Log
                        }
                    }
                    string result = orderHeader.DO_Piece;
                    Utility.ComObject.Close(_sageAccess);
                    return(Task.FromResult(result));
                }
                catch (Exception e)
                {
                    Utility.ComObject.Close(_sageAccess);
                    return(null);
                }
            }
        }
Example #6
0
        public static IBOClient3 CreateClientToIboClient(Client client, IBOClient3 sageClient)
        {
            sageClient.CT_Siret       = client.Siret;
            sageClient.CT_Intitule    = client.CompanyName;
            sageClient.CT_Qualite     = client.LegalForm;
            sageClient.CT_Classement  = client.CompanyName.Length > 17 ? client.CompanyName.Substring(0, 17) : client.CompanyName;
            sageClient.CT_Identifiant = client.VatIdentifier;
            sageClient.CT_Ape         = client.Naf;

            sageClient.Telecom.EMail     = client.CompanyEmail;
            sageClient.Telecom.Portable  = client.CompanyPhoneNumber;
            sageClient.Telecom.Telecopie = client.CompanyFax;
            sageClient.Telecom.Telephone = client.CompanyMobile;

            sageClient.Adresse.Adresse    = client.MainAddress.MainAddress;
            sageClient.Adresse.Complement = client.MainAddress.AdressAdditional;
            sageClient.Adresse.CodePostal = client.MainAddress.ZipCode;
            sageClient.Adresse.Ville      = client.MainAddress.City;
            sageClient.Adresse.Pays       = client.MainAddress.Country;
            sageClient.WriteDefault();

            foreach (var contact in client.Contacts)
            {
                IBOTiersContact3 sageContact = (IBOTiersContact3)sageClient.FactoryTiersContact.Create();
                sageContact.CouldModified();
                sageContact.Civilite          = (ContactCivilite)contact.Civility;
                sageContact.Nom               = contact.LastName;
                sageContact.Prenom            = contact.FirstName;
                sageContact.Telecom.Telephone = contact.PhoneNumber;
                sageContact.Telecom.Portable  = contact.MobileNumber;
                sageContact.Telecom.EMail     = contact.Email;
                sageContact.Fonction          = contact.Position;
                sageContact.Write();
            }
            sageClient.Read();
            return(sageClient);
        }
Example #7
0
        /// <summary>
        /// Crée une commande dépot
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="targetDb"></param>
        /// <returns></returns>
        public string createCommandeDepot(DataTable dt, string targetDb)
        {
            BSCIALApplication100c bsc = GetInstance();

            try
            {
                bsc.Open();
                IBOClient3 client = getClient(bsc, dt.Rows[0]["DBCLIENT"].ToString() + " DEPOT");

                string doRef = dt.Rows[0]["DO_Piece"].ToString();

                CheckCommandeClientExiste(client.CT_Num, doRef, targetDb);

                // Crée le bon de commande client
                IPMDocument       procDocV   = bsc.CreateProcess_Document(DocumentType.DocumentTypeVenteCommande);
                IBODocumentVente3 docVEntete = (IBODocumentVente3)procDocV.Document;

                docVEntete.DO_Ref = doRef;

                // Affecte le numéro de pièce
                docVEntete.SetDefaultDO_Piece();

                docVEntete.SetDefaultClient(client);
                docVEntete.CategorieTarif = bsc.FactoryCategorieTarif.ReadIntitule("Tarif Article N° 6");

                IBODocumentVenteLigne3 docVLigne;
                foreach (DataRow row in dt.Rows)
                {
                    string arRef             = row["AR_Ref"].ToString();
                    string gamme1            = row["Gamme1"].ToString();
                    string gamme2            = row["Gamme2"].ToString();
                    double qt                = double.Parse(row["DL_Qte"].ToString(), System.Globalization.CultureInfo.InvariantCulture);
                    string refFourn          = row["AF_RefFourniss"].ToString();
                    string design            = row["DL_Design"].ToString();
                    string txtComplementaire = row["DT_Text"].ToString();
                    string unite             = row["EU_Enumere"].ToString();

                    if (arRef != "")
                    {
                        docVLigne = (IBODocumentVenteLigne3)addArticleToLigne(procDocV, arRef, gamme1, gamme2, qt, unite);
                        // Si pas de ref fourn, on essaie de recup la ref fourn principal
                        if (refFourn == "" && docVLigne.Article.FournisseurPrincipal != null)
                        {
                            refFourn = docVLigne.Article.FournisseurPrincipal.Reference;
                        }
                        docVLigne.AF_RefFourniss = refFourn;
                        docVLigne.SetDefaultRemise();
                        docVLigne.DO_Ref            = doRef;
                        docVLigne.DL_Design         = design;
                        docVLigne.TxtComplementaire = txtComplementaire;
                        docVLigne.Write();
                    }
                    else
                    {
                        // Sinon c'est une ligne de commentaire
                        docVLigne           = (IBODocumentVenteLigne3)docVEntete.FactoryDocumentLigne.Create();
                        docVLigne.DL_Design = design;
                        docVLigne.Write();
                    }
                }

                if (procDocV.CanProcess)
                {
                    procDocV.Process();
                    // Cherche les divers pour forcer la maj du texte complémentaire
                    // Ne peut pas être effectué pendant le process car les info libres n'existent pas encore

                    foreach (IBODocumentVenteLigne3 ligne in GetDocument(docVEntete.DO_Piece).FactoryDocumentLigne.List)
                    {
                        if (ligne.Article != null && (ligne.Article.AR_Ref == "DIVERS" || ligne.Article.Famille.FA_CodeFamille == "UNIQUE"))
                        {
                            new DiversRepository().saveLigneVente(ligne);
                        }
                    }
                }
                else
                {
                    throw new Exception(GetProcessError(procDocV));
                }

                string subject = $"[INTERMAG] Commande Dépôt {client.CT_Classement} {docVEntete.DO_Piece}";
                string body    = $@"<p>Le magasin {client.CT_Classement} vous a passé une commande dépôt n° <b>{docVEntete.DO_Piece}</b></p>
                                 <p>Collaborateur : {dt.Rows[0]["Collaborateur"].ToString()}</p>
                                 <p>Merci de vous référer à Sage pour en connaître le contenu.</p>";
                sendMail(dt.Rows[0]["DBCLIENT"].ToString(), bsc.DatabaseInfo.DatabaseName, subject, body);

                EventLog.WriteEntry(log, subject, EventLogEntryType.Information, 100);

                return(string.Format(
                           "[OK];{0};{1}: Commande client {2} créée",
                           docVEntete.DO_Piece,
                           bsc.DatabaseInfo.DatabaseName,
                           docVEntete.DO_Piece
                           ));
            }
            catch (Exception e)
            {
                EventLog.WriteEntry(log, e.ToString(), EventLogEntryType.Error, 100);
                throw new Exception(e.Message);
            }
            finally
            {
                if (bsc != null)
                {
                    bsc.Close();
                }
            }
        }
Example #8
0
        /// <summary>
        /// Crée une commande Retro
        /// TODO utiliser le programme Contremarque pour générer l'APC? eg crée le document de vente en premier puis ajoute une contremarque sur toute les lignes
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public string createCommandeRetro(DataTable dt, string targetDb)
        {
            BSCIALApplication100c bsc = GetInstance();

            try
            {
                bsc.Open();
                IBOClient3 client = getClient(bsc, dt.Rows[0]["DBCLIENT"].ToString() + " RETRO");
                string     doRef  = dt.Rows[0]["DO_Piece"].ToString();
                CheckCommandeClientExiste(client.CT_Num, doRef, targetDb);

                // Crée le bon de commande client
                IPMDocument       procDocV   = bsc.CreateProcess_Document(DocumentType.DocumentTypeVenteCommande);
                IBODocumentVente3 docVEntete = (IBODocumentVente3)procDocV.Document;

                // Affecte le numéro de pièce
                docVEntete.SetDefaultDO_Piece();

                docVEntete.SetDefaultClient(client);
                docVEntete.CategorieTarif = bsc.FactoryCategorieTarif.ReadIntitule("Tarif Article N° 13");

                IBODocumentVenteLigne3 docVLigne;
                foreach (DataRow row in dt.Rows)
                {
                    string arRef             = row["AR_Ref"].ToString();
                    string gamme1            = row["Gamme1"].ToString();
                    string gamme2            = row["Gamme2"].ToString();
                    double montantHT         = double.Parse(row["DL_MontantHT"].ToString(), System.Globalization.CultureInfo.InvariantCulture);
                    double qt                = double.Parse(row["DL_Qte"].ToString(), System.Globalization.CultureInfo.InvariantCulture);
                    double prixUNet          = montantHT / qt;
                    string refFourn          = row["AF_RefFourniss"].ToString();
                    string design            = row["DL_Design"].ToString();
                    string txtComplementaire = row["DT_Text"].ToString();
                    string unite             = row["EU_Enumere"].ToString();

                    docVLigne = null;

                    if (arRef != "")
                    {
                        docVLigne = (IBODocumentVenteLigne3)addArticleToLigne(procDocV, arRef, gamme1, gamme2, qt, unite);
                        docVLigne.DL_PrixUnitaire   = prixUNet;
                        docVLigne.DL_Design         = design;
                        docVLigne.TxtComplementaire = txtComplementaire;
                        docVLigne.Write();
                    }
                    else
                    {
                        // Sinon c'est une ligne de commentaire
                        docVLigne           = (IBODocumentVenteLigne3)docVEntete.FactoryDocumentLigne.Create();
                        docVLigne.DL_Design = design;
                        docVLigne.Write();
                    }
                }

                if (procDocV.CanProcess)
                {
                    procDocV.Process();

                    // Cherche les divers pour forcer la maj du texte complémentaire
                    // Ne peut pas être effectué pendant le process car les info libres n'existent pas encore
                    foreach (IBODocumentVenteLigne3 ligne in GetDocument(docVEntete.DO_Piece).FactoryDocumentLigne.List)
                    {
                        if (ligne.Article != null && (ligne.Article.AR_Ref == "DIVERS" || ligne.Article.Famille.FA_CodeFamille == "UNIQUE"))
                        {
                            new DiversRepository().saveLigneVente(ligne);
                        }
                    }

                    // Ajoute les lignes en contremarque
                    ContremarqueRepository cmRepos = new ContremarqueRepository();
                    cmRepos.Log += Log;
                    Collection <Contremarque> cms = cmRepos.getAll(docVEntete.DO_Piece);
                    cms.Select(c => {
                        c.RowChecked    = true;
                        c.SelectedFourn = "Principal";
                        // On force pour chaque ligne le fournisseur demandé
                        // Cela permet de faire du retro sur un fournisseur secondaire
                        c.FournPrinc = dt.Rows[0]["DO_Tiers"].ToString();
                        return(c);
                    }).ToList();
                    cmRepos.saveAll(cms, docVEntete.DO_Piece, true);
                }
                else
                {
                    throw new Exception(GetProcessError(procDocV));
                }

                string subject = $"[INTERMAG] Commande Retro {client.CT_Classement} {docVEntete.DO_Piece}";
                string body    = $@"<p>Le magasin {client.CT_Classement} vous a passé une commande Retro n° <b>{docVEntete.DO_Piece}</b></p>
                                 <p>Collaborateur : {dt.Rows[0]["Collaborateur"].ToString()}</p>
                                 <p>Merci de vous référer à Sage pour en connaître le contenu.</p>";
                sendMail(dt.Rows[0]["DBCLIENT"].ToString(), bsc.DatabaseInfo.DatabaseName, subject, body);
                EventLog.WriteEntry(log, subject, EventLogEntryType.Information, 100);
                return($"[OK];{docVEntete.DO_Piece};{bsc.DatabaseInfo.DatabaseName}: Commande client {docVEntete.DO_Piece} créée {Environment.NewLine}{cmLogMessage}");
            }
            catch (Exception e)
            {
                EventLog.WriteEntry(log, e.ToString(), EventLogEntryType.Error, 100);
                throw new Exception(e.Message);
            }
            finally
            {
                if (bsc != null)
                {
                    bsc.Close();
                }
            }
        }