Esempio n. 1
0
 public COMPTA_AccountingEntries CreateAccountingEntry(COMPTA_AccountingEntries accountingEntryToAdd)
 {
     using(SUPERPEntities context = new SUPERPEntities(false))
     {
         var accountingEntry = context.COMPTA_AccountingEntries.Add(accountingEntryToAdd);
         context.SaveChanges();
         return accountingEntry;
     }
 }
Esempio n. 2
0
        private void CreateBilanComptableModeYear(IEnumerable<COMPTA_AccountingEntries> accountLines, DateTime Debut, DateTime Fin, out List<BilanComptable> bilan)
        {
            DateTime refTime = Debut;
            DateTime refEndTime = Fin;

            int Capacity = 0;

            Capacity = ( Debut.Year - Fin.Year ) + 1;

            bilan = new List<BilanComptable>(Capacity);

            int count = 0;

            while ( refTime.Year != refEndTime.Year + 1 )
            {
                // On récupère les lignes correspondante à notre année de réfèrence
                var result = accountLines.Where(x => x.postingDate.HasValue && x.postingDate.Value.Year == refTime.Year && x.chartOfAccount_id == 449);

                List<COMPTA_AccountingEntries> tempList = new List<COMPTA_AccountingEntries>(result);

                tempList.ForEach(delegate( COMPTA_AccountingEntries entry )
                {
                    var resultTemp = comptabilityDal.GetAccountingEntriesPeriodicityById(entry.id);

                    if ( resultTemp != null )
                    {
                        // on recupere la periodicite
                        Periodicity periode = new Periodicity()
                        {
                            startDate = resultTemp.startDate.Value,
                            endDate = resultTemp.endDate.Value,
                            Libelle = resultTemp.COMPTA_Periodicity.Libelle
                        };

                        int iteratorMonth = 0;

                        if ( periode.Libelle == "Mensuelle" )
                            iteratorMonth = 1;
                        if ( periode.Libelle == "Annuelle" )
                            iteratorMonth = 12;
                        if ( periode.Libelle == "Trimestrielle" )
                            iteratorMonth = 3;

                        for ( int i = iteratorMonth ; i < Capacity - iteratorMonth ; i = +iteratorMonth )
                        {
                            int month2 = entry.postingDate.Value.Month + i;
                            int addYear = 0;
                            while ( month2 > 12 )
                            {
                                month2 += -12;
                                addYear++;
                            }

                            DateTime newDateTime = new DateTime(entry.postingDate.Value.Year + addYear, month2, entry.postingDate.Value.Day);

                            if ( newDateTime < periode.endDate )
                            {
                                COMPTA_AccountingEntries newEntry = new COMPTA_AccountingEntries()
                                {
                                    amount = entry.amount,
                                    chartOfAccount_id = entry.chartOfAccount_id,
                                    direction = entry.direction,
                                    postingDate = newDateTime
                                };

                                tempList.Add(newEntry);
                            }
                        }

                    }
                });

                //accountLines = tempList;
                result = tempList;

                if ( result != null )
                {
                    // On instancie un nouveau bilanComptable
                    BilanComptable tempBilan = new BilanComptable();
                    tempBilan.TimePoint = new DateTime(refTime.Year, 1, 1);

                    // Pour chaque ligne récupère on affecte ça valeur positive ou négative selon sa direction
                    foreach ( var lineAccount in result )
                    {
                        decimal temp = tempBilan.Amount;
                        decimal income = lineAccount.direction == false ? -lineAccount.amount.Value : lineAccount.amount.Value;
                        tempBilan.Amount = temp + income;
                    }

                    // On assigne la valeur du Bilan temporaire à la listeFinale au niveau de l'index courant
                    bilan.Add(tempBilan);
                    // On incrémente l'index
                    count++;

                    // On recalcule la date de réfèrence et on ré-assigne la valeur au temps de réfèrence
                    int refYear = refTime.Year + 1;

                    refTime = new DateTime(refYear, 1, 1);
                }

            }
        }
Esempio n. 3
0
        /// <summary>
        /// Récupère les entrées et sorties des comptes comptables
        /// </summary>
        /// <param name="type">Type d'entrée : Crédit ou Débit</param>
        /// <param name="paye"></param>
        /// <param name="impaye"></param>
        /// <param name="Debut"></param>
        /// <param name="Fin"></param>
        /// <returns></returns>
        public IEnumerable<Entries> GetEntries( EntriesTypeEnum? type, bool? paye, bool? impaye, DateTime? Debut, DateTime? Fin )
        {
            IEnumerable<COMPTA_BankJournalLine> bankResult = null;// comptabilityDal.GetBankJournalLines();
            IEnumerable<COMPTA_SupplierJournalLine> supplierResult = null;// comptabilityDal.GetSupplierJournalLines();
            IEnumerable<COMPTA_CustomerJournalLine> customerResult = null;// comptabilityDal.GetCustomerJournalLines();
            var accountingResult = comptabilityDal.GetAccountingEntries();

            List<COMPTA_BankJournalLine> resultBank = new List<COMPTA_BankJournalLine>();
            List<COMPTA_CustomerJournalLine> resultCustomer = new List<COMPTA_CustomerJournalLine>();
            List<COMPTA_SupplierJournalLine> resultSupplier = new List<COMPTA_SupplierJournalLine>();
            List<COMPTA_AccountingEntries> resultAccounting = new List<COMPTA_AccountingEntries>();

            List<Entries> finalEntries = new List<Entries>();

            bool noFilter = false;

            if ( !type.HasValue && !paye.HasValue && !impaye.HasValue && !Debut.HasValue && !Fin.HasValue )
                noFilter = true;

            #region Bank Journal

            if ( resultBank != null )
            {
                if(type.HasValue)
                {
                    switch(type)
                    {
                        case EntriesTypeEnum.Credit:
                            resultBank = new List<COMPTA_BankJournalLine>(bankResult.Where(x => x.direction.Value == true));
                            break;
                        case EntriesTypeEnum.Debit:
                            resultBank = new List<COMPTA_BankJournalLine>(bankResult.Where(x => x.direction.Value == false));
                            break;
                    }
                }

                if ( Debut.HasValue && Fin.HasValue )
                    resultBank = new List<COMPTA_BankJournalLine>(resultBank.Where(x => Debut.Value < x.postingDate.Value && x.postingDate.Value < Fin.Value));
                else if ( Debut.HasValue )
                    resultBank = new List<COMPTA_BankJournalLine>(resultBank.Where(x => Debut.Value < x.postingDate.Value));
                else if ( Fin.HasValue )
                    resultBank = new List<COMPTA_BankJournalLine>(resultBank.Where(x => x.postingDate.Value < Fin.Value));

                if ( noFilter )
                    resultBank = new List<COMPTA_BankJournalLine>(bankResult);

                resultBank.ForEach(delegate( COMPTA_BankJournalLine entry )
                {
                    Entries finalEntry = new Entries()
                    {
                        amount = entry.amount,
                        EntryType = entry.direction == false ? EntriesTypeEnum.Debit : EntriesTypeEnum.Credit,
                        Foreign_id = entry.bankAccount_id,
                        id = entry.id,
                        postingDate = entry.postingDate,
                        SourceType = SourceEntriesEnum.Bank
                    };

                    //finalEntries.Add(finalEntry);
                });
            }

            #endregion

            #region Customer Journal

            if ( customerResult != null )
            {
                if ( type.HasValue )
                {
                    switch ( type )
                    {
                        case EntriesTypeEnum.Credit:
                            resultCustomer = new List<COMPTA_CustomerJournalLine>(customerResult.Where(x => x.direction.Value == true));
                            break;
                        case EntriesTypeEnum.Debit:
                            resultCustomer = new List<COMPTA_CustomerJournalLine>(customerResult.Where(x => x.direction.Value == false));
                            break;
                    }
                }

                if ( Debut.HasValue && Fin.HasValue )
                    resultCustomer = new List<COMPTA_CustomerJournalLine>(resultCustomer.Where(x => Debut.Value < x.postingDate.Value && x.postingDate.Value < Fin.Value));
                else if ( Debut.HasValue )
                    resultCustomer = new List<COMPTA_CustomerJournalLine>(resultCustomer.Where(x => Debut.Value < x.postingDate.Value));
                else if ( Fin.HasValue )
                    resultCustomer = new List<COMPTA_CustomerJournalLine>(resultCustomer.Where(x => x.postingDate.Value < Fin.Value));

                if ( noFilter )
                    resultCustomer = new List<COMPTA_CustomerJournalLine>(customerResult);

                resultCustomer.ForEach(delegate( COMPTA_CustomerJournalLine entry )
                {
                    Entries finalEntry = new Entries()
                    {
                        amount = entry.amount,
                        EntryType = entry.direction == false ? EntriesTypeEnum.Debit : EntriesTypeEnum.Credit,
                        Foreign_id = entry.clientAccount_id,
                        id = entry.id,
                        postingDate = entry.postingDate,
                        SourceType = SourceEntriesEnum.Customer
                    };

                    //finalEntries.Add(finalEntry);
                });
            }

            #endregion

            #region  Supplier Journal

            if ( supplierResult != null )
            {
                if ( type.HasValue )
                {
                    switch ( type )
                    {
                        case EntriesTypeEnum.Credit:
                            resultSupplier = new List<COMPTA_SupplierJournalLine>(supplierResult.Where(x => x.direction.Value == true));
                            break;
                        case EntriesTypeEnum.Debit:
                            resultSupplier = new List<COMPTA_SupplierJournalLine>(supplierResult.Where(x => x.direction.Value == false));
                            break;
                    }
                }

                if ( Debut.HasValue && Fin.HasValue )
                    resultSupplier = new List<COMPTA_SupplierJournalLine>(resultSupplier.Where(x => Debut.Value < x.postingDate.Value && x.postingDate.Value < Fin.Value));
                else if ( Debut.HasValue )
                    resultSupplier = new List<COMPTA_SupplierJournalLine>(resultSupplier.Where(x => Debut.Value < x.postingDate.Value));
                else if ( Fin.HasValue )
                    resultSupplier = new List<COMPTA_SupplierJournalLine>(resultSupplier.Where(x => x.postingDate.Value < Fin.Value));

                if ( noFilter )
                    resultSupplier = new List<COMPTA_SupplierJournalLine>(supplierResult);

                resultSupplier.ForEach(delegate( COMPTA_SupplierJournalLine entry )
                {
                    Entries finalEntry = new Entries()
                    {
                        amount = entry.amount,
                        EntryType = entry.direction == false ? EntriesTypeEnum.Debit : EntriesTypeEnum.Credit,
                        Foreign_id = entry.SupplierAccount_id,
                        id = entry.id,
                        postingDate = entry.postingDate,
                        SourceType = SourceEntriesEnum.Supplier
                    };

                    //finalEntries.Add(finalEntry);
                });
            }

            #endregion

            #region Accounting Journal

            if ( accountingResult != null )
            {
                List<COMPTA_AccountingEntries> tempList = new List<COMPTA_AccountingEntries>();

                foreach ( var item in accountingResult )
                {
                    COMPTA_AccountingEntries newEntry = new COMPTA_AccountingEntries()
                    {
                        amount = item.amount,
                        chartOfAccount_id = item.chartOfAccount_id,
                        direction = item.direction,
                        id = item.id,
                        postingDate = item.postingDate
                    };

                    tempList.Add(newEntry);
                }

                List<COMPTA_AccountingEntries> tempResult = new List<COMPTA_AccountingEntries>();

                tempList.ForEach(delegate( COMPTA_AccountingEntries entry )
                {
                    var resultTemp = comptabilityDal.GetAccountingEntriesPeriodicityById(entry.id);

                    if ( resultTemp != null )
                    {
                        // on recupere la periodicite
                        Periodicity periode = new Periodicity()
                        {
                            startDate = resultTemp.startDate.Value,
                            endDate = resultTemp.endDate.Value,
                            Libelle = resultTemp.COMPTA_Periodicity.Libelle
                        };

                        int iteratorMonth = 0;

                        if ( periode.Libelle == "Mensuelle" )
                            iteratorMonth = 1;
                        if ( periode.Libelle == "Annuelle" )
                            iteratorMonth = 12;
                        if ( periode.Libelle == "Trimestrielle" )
                            iteratorMonth = 3;

                        DateTime refTime = new DateTime(entry.postingDate.Value.Year, entry.postingDate.Value.Month, entry.postingDate.Value.Day);
                        DateTime refEndTime = new DateTime(periode.endDate.Year, periode.endDate.Month, periode.endDate.Day);

                        int month = entry.postingDate.Value.Month;
                        //tant que refTime n'est pas supérieure ou égal a EndTime
                        // Je crée des nouvelles entrée tout les X Mois
                        //j'incrémente refTime de X mois
                        int previousYear = 0;
                        int count = 0;
                        while ( refTime <= refEndTime)
                        {
                            if ( count > 6424 )
                                count = 6424;
                            month += iteratorMonth;
                            int addYear = 0;
                            while ( month > 12 )
                            {
                                month += -12;
                                addYear++;
                            }

                            DateTime newDateTime;

                            if ( previousYear == 0 )
                                newDateTime = new DateTime(refTime.Year + addYear, month, refTime.Day);
                            else
                                newDateTime = new DateTime(refTime.Year + addYear, month, refTime.Day);

                            COMPTA_AccountingEntries newEntry = new COMPTA_AccountingEntries()
                            {
                                amount = entry.amount,
                                chartOfAccount_id = entry.chartOfAccount_id,
                                direction = entry.direction,
                                postingDate = newDateTime
                            };

                            previousYear = newDateTime.Year;
                            tempResult.Add(newEntry);

                            refTime = newDateTime;
                            count++;
                        }

                    }

                });

                tempList.AddRange(tempResult);

                accountingResult = tempList;

                if ( type.HasValue )
                {
                    switch ( type )
                    {
                        case EntriesTypeEnum.Credit:
                            resultAccounting = new List<COMPTA_AccountingEntries>(accountingResult.Where(x => x.direction.Value == true));
                            break;
                        case EntriesTypeEnum.Debit:
                            resultAccounting = new List<COMPTA_AccountingEntries>(accountingResult.Where(x => x.direction.Value == false));
                            break;
                    }
                }

                if ( Debut.HasValue && Fin.HasValue )
                    resultAccounting = new List<COMPTA_AccountingEntries>(resultAccounting.Where(x => Debut.Value < x.postingDate.Value && x.postingDate.Value < Fin.Value));
                else if ( Debut.HasValue )
                    resultAccounting = new List<COMPTA_AccountingEntries>(resultAccounting.Where(x => Debut.Value < x.postingDate.Value));
                else if ( Fin.HasValue )
                    resultAccounting = new List<COMPTA_AccountingEntries>(resultAccounting.Where(x => x.postingDate.Value < Fin.Value));

                resultAccounting = new List<COMPTA_AccountingEntries>(accountingResult);

                resultAccounting.ForEach(delegate( COMPTA_AccountingEntries entry )
                {
                    Entries finalEntry = new Entries()
                    {
                        amount = entry.amount,
                        EntryType = entry.direction == false ? EntriesTypeEnum.Debit : EntriesTypeEnum.Credit,
                        Foreign_id = entry.chartOfAccount_id,
                        id = entry.id,
                        postingDate = entry.postingDate,
                        SourceType = SourceEntriesEnum.Accounting
                    };

                    finalEntries.Add(finalEntry);
                });
            }

            #endregion

            return finalEntries;
        }
Esempio n. 4
0
        public COMPTA_AccountingEntries EditAccountingEntry(COMPTA_AccountingEntries accountingEntryToEdit)
        {
            using(SUPERPEntities context = new SUPERPEntities(false))
            {
                var accountingEntry = context.COMPTA_AccountingEntries.Find(accountingEntryToEdit.id);

                if (accountingEntry == null)
                    return null;

                accountingEntry = accountingEntryToEdit;
                context.SaveChanges();
                return accountingEntry;
            }
        }