Example #1
0
 /// <summary>
 /// Retourne un client
 /// </summary>
 /// <param name="bsc"></param>
 /// <param name="dt"></param>
 /// <returns></returns>
 private IBOClient3 getClient(BSCIALApplication100c bsc, string abrege)
 {
     using (SqlConnection cnx = new SqlConnection(getCnxString(bsc)))
     {
         cnx.Open();
         using (SqlCommand cmd = cnx.CreateCommand())
         {
             cmd.CommandText = "SELECT CT_Num FROM F_COMPTET WHERE CT_Classement = @ctClassement AND CT_Type = 0";
             cmd.Parameters.AddWithValue("@ctClassement", abrege);
             using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
             {
                 if (reader.HasRows)
                 {
                     reader.Read();
                     return(bsc.CptaApplication.FactoryClient.ReadNumero(reader["CT_Num"].ToString()));
                 }
                 else
                 {
                     throw new Exception(string.Format("Client '{0}' non trouvé", abrege));
                 }
             }
         }
     }
 }
Example #2
0
 /// <summary>
 /// Retourne la chaine de connexion SQL à partir d'une instance Gescom ou Compta
 /// </summary>
 /// <param name="bsCial"></param>
 /// <returns></returns>
 public string getCnxString(BSCIALApplication100c bsCial)
 {
     return($"server={bsCial.DatabaseInfo.ServerName};Trusted_Connection=yes;database={bsCial.DatabaseInfo.DatabaseName};MultipleActiveResultSets=True");
 }
Example #3
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 #4
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();
                }
            }
        }