Beispiel #1
0
        public Task <int> Delete(string id)
        {
            lock (_sageAccess.DatabaseLock)
            {
                if (Utility.ComObject.Open(_sageAccess) == false)
                {
                    return(Task.FromResult(1));
                }

                if (_sageAccess.GetSageDatabase.FactoryDocumentVente.ExistPiece(DocumentType.DocumentTypeVenteCommande, id) == false)
                {
                    return(Task.FromResult(1));
                }
                IBODocumentVente3 docEntete = _sageAccess.GetSageDatabase.FactoryDocumentVente.ReadPiece(DocumentType.DocumentTypeVenteCommande, id);
                try
                {
                    foreach (IBODocumentLigne3 line in docEntete.FactoryDocumentLigne.List)
                    {
                        line.Remove();
                    }
                    docEntete.Remove();

                    Utility.ComObject.Close(_sageAccess);
                    return(Task.FromResult(0));
                }
                catch (Exception e)
                {
                    Utility.ComObject.Close(_sageAccess);
                    return(Task.FromResult(1));
                }
            }
        }
Beispiel #2
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);
                }
            }
        }
Beispiel #3
0
/*
 *      public static Client IboClientToClient(IBOClient3 sageClient)
 *      {
 *          Client client = new Client();
 *          client.SageCode = sageClient.CT_Num;
 *          client.Siret = sageClient.CT_Siret;
 *          client.CompanyName = sageClient.CT_Intitule;
 *          client.LegalForm = sageClient.CT_Qualite;
 *          client.CompanyEmail = sageClient.Telecom.EMail;
 *          client.Portable = sageClient.Telecom.Portable;
 *          client.CompanyFax = sageClient.Telecom.Telecopie;
 *          client.CompanyMobile = sageClient.Telecom.Telephone;
 *          client.MainAddress.MainAddress = sageClient.Adresse.Adresse;
 *          client.MainAddress.AdressAdditional = sageClient.Adresse.Complement;
 *          client.MainAddress.ZipCode = sageClient.Adresse.CodePostal;
 *          client.MainAddress.City = sageClient.Adresse.Ville;
 *          client.MainAddress.Country = sageClient.Adresse.Pays;
 *          client.VatIdentifier = sageClient.CT_Identifiant;
 *          return client;
 *      }*/

        public static Order IboOrderToOrder(IBODocumentVente3 orderHeader)
        {
            Order sageOrder = new Order();

            try
            {
                sageOrder.DO_Piece        = orderHeader.DO_Piece;
                sageOrder.DO_Ref          = orderHeader.DO_Ref;
                sageOrder.DO_Statut       = orderHeader.DO_Statut.ToString();
                sageOrder.DO_Tiers        = orderHeader.Tiers.CT_Num;
                sageOrder.CT_NumPayeur    = orderHeader.TiersPayeur.CT_Num;
                sageOrder.DO_Date         = orderHeader.DO_Date;
                sageOrder.DO_DateLivr     = orderHeader.DO_DateLivr;
                sageOrder.DO_TotalHT      = Convert.ToDecimal(orderHeader.DO_TotalHT);
                sageOrder.DO_TotalHTNet   = Convert.ToDecimal(orderHeader.DO_TotalHTNet);
                sageOrder.DO_TotalTTC     = Convert.ToDecimal(orderHeader.DO_TotalTTC);
                sageOrder.DO_NetAPayer    = Convert.ToDecimal(orderHeader.DO_NetAPayer);
                sageOrder.DO_MontantRegle = Convert.ToDecimal(orderHeader.DO_MontantRegle);

                foreach (IBODocumentVenteLigne3 orderLine in orderHeader.FactoryDocumentLigne.List)
                {
                    DocLine docLine = new DocLine();
                    docLine.AR_Ref          = orderLine.Article.AR_Ref;
                    docLine.DL_Design       = orderLine.DL_Design;
                    docLine.DL_MontantHT    = Convert.ToDecimal(orderLine.DL_MontantHT);
                    docLine.DL_MontantTTC   = Convert.ToDecimal(orderLine.DL_MontantTTC);
                    docLine.DL_PrixUnitaire = Convert.ToDecimal(orderLine.DL_PrixUnitaire);
                    docLine.DL_PUTTC        = Convert.ToDecimal(orderLine.DL_PUTTC);
                    docLine.DL_Qte          = orderLine.DL_Qte;
                    //docLine.DL_Taxe1 = orderLine.Taxe.TA_GrilleTaxe.1
                    //docLine.DL_TypeTaxe1 = orderLine.Taxe.TA_Type;
                    docLine.DO_Date    = orderLine.DO_Date;
                    docLine.DO_Domaine = Convert.ToByte(orderLine.DO_Domaine);
                    docLine.DO_Piece   = orderLine.DL_PieceBC;
                    docLine.DO_Type    = Convert.ToByte(orderLine.DO_Type);

                    sageOrder.DocLines.Add(docLine);
                }
                return(sageOrder);
            }
            catch (Exception e)
            {
                return(sageOrder);
            }
        }
Beispiel #4
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();
                }
            }
        }
Beispiel #5
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();
                }
            }
        }
        /// <summary>
        /// Cde dépot: Met à jour les prix, statut ...
        /// </summary>
        /// <param name="docAOrigin"></param>
        /// <param name="magPiece"></param>
        private void editCommandeDepot(IBODocumentAchat3 docAOrigin, string magPiece)
        {
            try
            {
                // Commande Dépôt
                docAOrigin.DO_Ref    = magPiece;
                docAOrigin.DO_Statut = DocumentStatutType.DocumentStatutTypeConfirme;
                //docAOrigin.InfoLibre["Date Statut"] = DateTime.Now;
                docAOrigin.Write();

                using (SqlConnection cnx = new SqlConnection(cnxString))
                {
                    cnx.Open();
                    using (SqlCommand cmd = cnx.CreateCommand())
                    {
                        cmd.CommandText = "UPDATE F_DOCENTETE SET [Date Statut] = GETDATE() WHERE DO_Piece = @doPiece";
                        cmd.Parameters.AddWithValue("@doPiece", docAOrigin.DO_Piece);

                        cmd.ExecuteNonQuery();
                    }
                }

                docAOrigin.Refresh();

                // Simule une commande client Tarif 6 pour recup les prix remisés
                // et les appliquer au doc d'achat
                IPMDocument       procDocV   = GetInstance().CreateProcess_Document(DocumentType.DocumentTypeVenteCommande);
                IBODocumentVente3 docVEntete = (IBODocumentVente3)procDocV.Document;

                docVEntete.SetDefaultClient(GetInstance().CptaApplication.FactoryClient.ReadNumero("DEVEL"));
                docVEntete.CategorieTarif = GetInstance().FactoryCategorieTarif.ReadIntitule("Tarif Article N° 6");

                IBODocumentVenteLigne3 docVLigne;
                foreach (IBODocumentAchatLigne3 ligneOrigin in docAOrigin.FactoryDocumentLigne.List)
                {
                    if (ligneOrigin.Article != null)
                    {
                        Debug.Print(ligneOrigin.Article.AR_Ref);
                        docVLigne = (IBODocumentVenteLigne3)docVEntete.FactoryDocumentLigne.Create();
                        IBOArticle3 a   = ligneOrigin.Article;
                        double      qte = ligneOrigin.DL_Qte;
                        docVLigne.SetDefaultArticle(a, qte);
                        docVLigne.SetDefaultRemise();

                        ligneOrigin.DL_PrixUnitaire = docVLigne.DL_PrixUnitaire;
                        ligneOrigin.Remise.FromString(docVLigne.Remise.ToString());
                        ligneOrigin.DO_Ref = magPiece;
                        ligneOrigin.Write();

                        if (ligneOrigin.Article.AR_Ref == "DIVERS" || ligneOrigin.Article.Famille.FA_CodeFamille == "UNIQUE")
                        {
                            new DiversRepository().saveLigneAchat(ligneOrigin);
                        }
                    }
                }

                // Déverrouille le doc
                docAOrigin.Read();
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
        }