Exemplo n.º 1
0
        //!Public actions & methods
        #region API


        public Facture CreateFactureRetour(CreateModes mode)
        {
            if (!EnsureIsSavedSubmit())
            {
                return(null);
            }

            if (!IsReturn)
            {
                Facture fac = new Facture();
                fac = DataHelpers.MapProperties(fac, this) as Facture;
                fac.ArticleFacture.ForEach(a => a.Qts = (a.Qts * -1));
                fac.IsReturn           = true;
                fac.RefOriginalFacture = this.Id;
                fac = this.MapRefsTo(fac) as Facture;

                fac = CreateModesHandler.Handle(fac, mode) as Facture;
                return(fac);
            }
            else
            {
                MessageBox.Show("Vous pouvez pas retourner une facture de retour");
                return(null);
            }
        }
Exemplo n.º 2
0
        public BonReception CreateBonReceptionRetour(CreateModes mode)
        {
            if (EnsureIsSavedSubmit() && IsReturn == true)
            {
                //if (this.RefBonLivraison.IsValideAndSubmited<BonLivraison>())
                //{
                //    var res = MessageBox.Show( $"Facture déja fait référencer a un Bon de livraison #{this.RefBonLivraison.GetObject("BonLivraison")?.Name}! Annuler ce document avant de continuer!", "Confirmation", MessageBoxButton.OK);
                //    return null;
                //}

                BonReception f = new BonReception();
                f        = DataHelpers.MapProperties(f, this) as BonReception;
                f.DateBL = DateTime.Now;

                foreach (var item in this.ArticleFacture)
                {
                    item.Qts = Math.Abs(item.Qts);
                    var line = new LigneEcritureStock();
                    line = DataHelpers.MapProperties(line, item) as LigneEcritureStock;
                    f.Articles.Add(line);
                }

                f = this.MapRefsTo(f) as BonReception;
                f = CreateModesHandler.Handle(f, mode) as BonReception;
                return(f);
            }
            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create Journal Entries For the Invoice
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        private List <EcritureJournal> CreateEcritureJournal(CreateModes mode)
        {
            var ej_result = new List <EcritureJournal>();

            if (this.EnsureIsSavedSubmit())
            {
                if (this.IsReturn == false)
                {
                    EcritureJournal credit = new EcritureJournal();
                    credit.DateEcriture  = this.DateCreation;
                    credit.CompteJournal = this.CompteCredit.IsValide() ? this.CompteCredit : CompteSettings.getInstance().CompteVente;
                    credit.MontantCredit = this.MontantTotalHT;
                    credit.MontantDebit  = 0;
                    credit.ObjetEcriture = "Facture de vente";
                    credit.RefDate       = this.DateCreation;
                    credit.RefNumber     = this.Name;
                    credit.RefFacture    = this.Id;
                    credit.CompteContre  = this.NomTier;
                    credit.Tier          = this.Tier;
                    credit.Utilisateur   = DataHelpers.ConnectedUser?.Id;

                    EcritureJournal debit = new EcritureJournal();
                    debit.CompteJournal = this.CompteDebit.IsValide() ? this.CompteDebit : CompteSettings.getInstance().CompteTier;
                    debit.CompteContre  = this.NomTier;
                    debit.DateEcriture  = this.DateCreation;
                    debit.MontantCredit = 0;
                    debit.MontantDebit  = this.MontantGlobalTTC;
                    debit.ObjetEcriture = "Facture de vente";
                    debit.RefDate       = this.DateCreation;
                    debit.RefFacture    = this.Id;
                    debit.RefNumber     = this.Name;
                    debit.Tier          = this.Tier;
                    debit.Utilisateur   = DataHelpers.ConnectedUser?.Id;

                    ej_result.Add(debit);
                    ej_result.Add(credit);
                    // Enregsitrement TVA

                    var taxes = this.TaxeLigne;
                    if (taxes.Any())
                    {
                        foreach (var taxe in taxes)
                        {
                            EcritureJournal credit_tva = new EcritureJournal();
                            credit_tva.CompteJournal = CompteSettings.getInstance().CompteTVA;
                            credit_tva.DateEcriture  = this.DateCreation;
                            credit_tva.MontantCredit = taxe.MontantTaxe;
                            credit_tva.MontantDebit  = 0;
                            credit_tva.ObjetEcriture = "TVA Collectée";
                            credit_tva.RefDate       = this.DateCreation;
                            credit_tva.RefNumber     = this.Name;
                            credit_tva.RefFacture    = this.Id;
                            credit_tva.CompteContre  = this.NomTier;
                            credit_tva.Tier          = this.Tier;
                            credit_tva.Utilisateur   = DataHelpers.ConnectedUser?.Id;
                            ej_result.Add(credit_tva);
                        }
                    }
                }
                else
                {
                    // Enregistrement this

                    // Normalisé les qts positif

                    this.ArticleFacture.ForEach(a => a.Qts = System.Math.Abs(a.Qts));

                    EcritureJournal credit = new EcritureJournal();
                    credit.CompteJournal = this.CompteCredit.IsValide() ? this.CompteCredit : CompteSettings.getInstance().CompteVente;
                    //CompteSettings.getInstance().CompteVente;
                    credit.DateEcriture  = this.DateCreation;
                    credit.MontantDebit  = this.MontantTotalHT;
                    credit.MontantCredit = 0;
                    credit.ObjetEcriture = "Retour vente";
                    credit.RefDate       = this.DateCreation;
                    credit.RefNumber     = this.Name;
                    credit.RefFacture    = this.Id;
                    credit.CompteContre  = this.NomTier;
                    credit.Tier          = this.Tier;
                    credit.Utilisateur   = DataHelpers.ConnectedUser?.Id;

                    EcritureJournal debit = new EcritureJournal();
                    debit.CompteJournal = this.CompteDebit.IsValide() ? this.CompteDebit : CompteSettings.getInstance().CompteTier;
                    //CompteSettings.getInstance().CompteTier;
                    debit.DateEcriture  = this.DateCreation;
                    debit.CompteContre  = this.NomTier;
                    debit.MontantDebit  = 0;
                    debit.MontantCredit = this.MontantGlobalTTC;
                    debit.ObjetEcriture = "Retour vente";
                    debit.RefDate       = this.DateCreation;
                    debit.RefFacture    = this.Id;
                    debit.RefNumber     = this.Name;
                    debit.Tier          = this.Tier;
                    debit.Utilisateur   = DataHelpers.ConnectedUser?.Id;

                    ej_result.Add(debit);
                    ej_result.Add(credit);
                    // Enregsitrement TVA

                    var taxes = this.TaxeLigne;
                    if (taxes.Any())
                    {
                        foreach (var taxe in taxes)
                        {
                            EcritureJournal credit_tva = new EcritureJournal();
                            credit_tva.CompteJournal = CompteSettings.getInstance().CompteTVA;
                            credit_tva.MontantDebit  = taxe.MontantTaxe;
                            credit_tva.DateEcriture  = this.DateCreation;
                            credit_tva.MontantCredit = 0;
                            credit_tva.ObjetEcriture = "TVA Remboursée";
                            credit_tva.RefDate       = this.DateCreation;
                            credit_tva.RefNumber     = this.Name;
                            credit_tva.RefFacture    = this.Id;
                            credit_tva.CompteContre  = this.NomTier;
                            credit_tva.Tier          = this.Tier;
                            credit_tva.Utilisateur   = DataHelpers.ConnectedUser?.Id;
                            ej_result.Add(credit_tva);
                        }
                    }
                }
            }

            ej_result.ForEach(a => a = CreateModesHandler.Handle(a, mode) as EcritureJournal);
            return(ej_result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create paiement Entry for the invoice
        /// </summary>
        /// <param name="mode">Creating Mode</param>
        /// <returns></returns>
        public EcriturePaiment CreatePaiement(CreateModes mode, decimal MontantPaye)
        {
            if (this.RefEcriturePaiment.IsValide())
            {
                var res = MessageBox.Show($"Facture déja fait référencer a un paiement #{this.RefEcriturePaiment.GetObject<EcriturePaiment>()?.Name}! voulez-vous continuer?", "Confirmation", MessageBoxButton.YesNo);
                if (res == MessageBoxResult.No)
                {
                    return(null);
                }
            }

            if (EnsureIsSavedSubmit())
            {
                // validate mode de paiment par default
                var modePaiementParDefault = CompteSettings.getInstance().DefaultModelPaiement;
                if (!modePaiementParDefault.HasValue || modePaiementParDefault == ObjectId.Empty)
                {
                    MessageBox.Show("Mode de paiement par default introuvable, éditer les paramétres comptabilité");
                    return(null);
                }

                var ecritureapiemenrt = new EcriturePaiment();
                if (this.IsReturn == false)
                {
                    ecritureapiemenrt               = DataHelpers.MapProperties(ecritureapiemenrt, this) as EcriturePaiment;
                    ecritureapiemenrt.Tier          = this.Tier;
                    ecritureapiemenrt.DateEcriture  = this.DateEcheance;
                    ecritureapiemenrt.ModeDePiement = modePaiementParDefault;
                    ecritureapiemenrt.MontantPaye   = MontantPaye;
                    ecritureapiemenrt.ObjetEcriture = "Recevoir";
                    ecritureapiemenrt.Factures      = new List <Facture>()
                    {
                        this
                    };
                    ecritureapiemenrt.ComtpeDebit  = modePaiementParDefault.GetObject <ModePaiement>()?.CompteCredit;
                    ecritureapiemenrt.ComtpeCredit = CompteSettings.getInstance().CompteTier;
                    ecritureapiemenrt.Remarques    = "Enregistrer depuis facture " + this.Name;

                    // return ecritureapiemenrt;
                }
                else
                {
                    ecritureapiemenrt               = DataHelpers.MapProperties(ecritureapiemenrt, this) as EcriturePaiment;
                    ecritureapiemenrt.Tier          = this.Tier;
                    ecritureapiemenrt.DateEcriture  = this.DateEcheance;
                    ecritureapiemenrt.ModeDePiement = modePaiementParDefault;
                    ecritureapiemenrt.MontantPaye   = Math.Abs(this.MontantReste);
                    ecritureapiemenrt.ComtpeCredit  = modePaiementParDefault.GetObject <ModePaiement>()?.CompteCredit;
                    ecritureapiemenrt.ComtpeDebit   = CompteSettings.getInstance().CompteTier;
                    ecritureapiemenrt.ObjetEcriture = "Payer";
                    ecritureapiemenrt.Factures      = new List <Facture>()
                    {
                        this
                    };
                    ecritureapiemenrt.Remarques = "Enregistrer depuis facture retour " + this.Name;

                    // return ecritureapiemenrt;
                }

                ecritureapiemenrt = this.MapRefsTo(ecritureapiemenrt) as EcriturePaiment;
                ecritureapiemenrt = CreateModesHandler.Handle(ecritureapiemenrt, mode) as EcriturePaiment;
                return(ecritureapiemenrt);
            }
            return(null);
        }