コード例 #1
0
ファイル: PlanComptableBLL.cs プロジェクト: LeonGuo1/SupErp
        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);
                }

            }
        }
コード例 #2
0
        private void CreateBilanComptableModeMonth(IEnumerable <COMPTA_AccountingEntries> accountLines, DateTime Debut, DateTime Fin, out List <BilanComptable> bilan)
        {
            DateTime refTime    = Debut;
            DateTime refEndTime = Fin;

            int Capacity = 0;

            int yearDifference;

            yearDifference = Debut.Year - Fin.Year;

            if (yearDifference == 0)
            {
                Capacity = (12 - (Debut.Month - 1) + 12 * yearDifference);
            }
            else
            {
                Capacity = (12 - (Debut.Month - 1) + 12 * yearDifference + Fin.Month);
            }

            int count = 0;

            bilan = new List <BilanComptable>(Capacity);

            while (refTime.Month != refEndTime.Month + 1 && refTime.Year == refEndTime.Year)
            {
                // On récupère les lignes correspondante à notre mois et notre année de réfèrence
                var result = accountLines.Where(x => x.postingDate.HasValue && x.postingDate.Value.Month == refTime.Month && 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 month   = entry.postingDate.Value.Month + i;
                            int addYear = 0;
                            while (month > 12)
                            {
                                month += -12;
                                addYear++;
                            }

                            DateTime newDateTime = new DateTime(entry.postingDate.Value.Year + addYear, month, 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, refTime.Month, 1);

                    // Pour chaque ligne récupère on affecte ça valeur positive ou négative selon sa direction
                    foreach (var lineAccount in result)
                    {
                        if (lineAccount.amount.HasValue && lineAccount.direction.HasValue)
                        {
                            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 refMonth = refTime.Month + 1;
                    int refYear  = refTime.Year;

                    if (refMonth == 13)
                    {
                        refMonth = 1;
                        refYear += 1;
                    }

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