/// <summary>
        /// TODO Transférer dans MBCore
        /// </summary>
        /// <param name="document"></param>
        internal void CheckDocumentsClosed(Document document)
        {
            if (openBaseCial())
            {
                IBODocument3 doc = GetDocument(document.DoPiece);
                try
                {
                    doc.CouldModified();
                    doc.Read();
                }
                catch (Exception)
                {
                    throw new Exception($"Veuillez fermer le document {doc.DO_Piece}");
                }

                foreach (IBODocumentLigne3 ligne in doc.FactoryDocumentLigne.List)
                {
                    if (ligne.Article != null &&
                        (ligne.Article.AR_Ref == "DIVERS" || ligne.Article.Famille.FA_CodeFamille == "UNIQUE") &&
                        ligne.FactoryDocumentLigneLienCM.List.Count > 0)
                    {
                        foreach (IBODocumentLigneLienCM cmLigne in ligne.FactoryDocumentLigneLienCM.List)
                        {
                            try
                            {
                                cmLigne.DocumentLigneIn.Document.CouldModified();
                                cmLigne.DocumentLigneIn.Document.Read();
                            }
                            catch (Exception)
                            {
                                throw new Exception($"Veuillez fermer le document {cmLigne.DocumentLigneIn.Document.DO_Piece}");
                            }
                            try
                            {
                                cmLigne.DocumentLigneOut.Document.CouldModified();
                                cmLigne.DocumentLigneOut.Document.Read();
                            }
                            catch (Exception)
                            {
                                throw new Exception($"Veuillez fermer le document {cmLigne.DocumentLigneOut.Document.DO_Piece}");
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        public Article DeclareStock(double noteStock, Article article)
        {
            IBOArticle3  OMArticle = GetInstance().FactoryArticle.ReadReference(article.ArRef);
            double       stockReel;
            double       mouvQt;
            IBODocument3 dayDocIn = null, dayDocOut = null;

            using (SqlConnection cnx = new SqlConnection(cnxString))
            {
                cnx.Open();
                using (SqlCommand cmd = cnx.CreateCommand())
                {
                    cmd.CommandText = @"SELECT DO_Piece, DO_Type FROM F_DOCENTETE 
                        WHERE DO_Date = CAST(CURRENT_TIMESTAMP AS DATE) AND DO_Ref = 'REGUL STOCK' AND DO_Type IN (20,21)";
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                short  doType  = (short)reader["DO_Type"];
                                string doPiece = (string)reader["DO_Piece"];

                                switch (doType)
                                {
                                case 20:
                                    dayDocIn = GetInstance().FactoryDocumentStock.ReadPiece(DocumentType.DocumentTypeStockMouvIn, doPiece);
                                    dayDocIn.CouldModified();
                                    removeLigneFromDoc(dayDocIn, OMArticle, article.Gamme1, article.Gamme2);
                                    break;

                                case 21:
                                    dayDocOut = GetInstance().FactoryDocumentStock.ReadPiece(DocumentType.DocumentTypeStockMouvOut, doPiece);
                                    dayDocOut.CouldModified();
                                    removeLigneFromDoc(dayDocOut, OMArticle, article.Gamme1, article.Gamme2);
                                    break;

                                default:
                                    throw new Exception($"Type {doType} non pris en charge");
                                }
                            }
                        }
                    }
                }

                stockReel = getStockReel(OMArticle, article.Gamme1, article.Gamme2);

                // Mouvement d'entrée
                if (noteStock > stockReel)
                {
                    mouvQt = noteStock - stockReel;
                    if (dayDocIn == null)
                    {
                        IPMDocument procDocIn = GetInstance().CreateProcess_Document(DocumentType.DocumentTypeStockMouvIn);
                        dayDocIn = procDocIn.Document;
                        procDocIn.Document.DO_Ref = "REGUL STOCK";
                        addArticleToLigne((IBODocumentLigne3)dayDocIn.FactoryDocumentLigne.Create(), OMArticle, article.Gamme1, article.Gamme2, mouvQt).WriteDefault();
                        procDocIn.Process();
                    }
                    addArticleToLigne((IBODocumentLigne3)dayDocIn.FactoryDocumentLigne.Create(), OMArticle, article.Gamme1, article.Gamme2, mouvQt).WriteDefault();
                }

                // Mouvement de sortie
                if (noteStock < stockReel)
                {
                    mouvQt = stockReel - noteStock;
                    if (dayDocOut == null)
                    {
                        IPMDocument procDocOut = GetInstance().CreateProcess_Document(DocumentType.DocumentTypeStockMouvOut);
                        dayDocOut = procDocOut.Document;
                        procDocOut.Document.DO_Ref = "REGUL STOCK";
                        addArticleToLigne((IBODocumentLigne3)dayDocOut.FactoryDocumentLigne.Create(), OMArticle, article.Gamme1, article.Gamme2, mouvQt).WriteDefault();
                        procDocOut.Process();
                    }
                    addArticleToLigne((IBODocumentLigne3)dayDocOut.FactoryDocumentLigne.Create(), OMArticle, article.Gamme1, article.Gamme2, mouvQt).WriteDefault();
                }
            }

            article.Stock = getStockReel(OMArticle, article.Gamme1, article.Gamme2);
            return(article);
        }