예제 #1
0
        public override DateTime?GetNextExecuteTimeAfterSpecificTime(DateTime time)
        {
            if (time > ToDate)
            {
                return(default(DateTime?));
            }
            if (time < FromDate)
            {
                time = FromDate;
            }
            DateTime fromDate = FromDate.AddDays(DayOfWeek.Sunday - FromDate.DayOfWeek).Date;
            DateTime nowDate  = time.AddDays(DayOfWeek.Sunday - time.DayOfWeek).Date;
            int      diff     = nowDate.Subtract(fromDate).Days;
            int      x        = diff % (m_IntervalWeeks * 7);
            DateTime rst;

            if (x != 0)
            {
                rst = nowDate.AddDays(m_IntervalWeeks * 7 - x);
            }
            else
            {
                rst = nowDate;
            }
            rst.AddDays(ExecuteWeekDay - rst.DayOfWeek);
            rst = new DateTime(rst.Year, rst.Month, rst.Day).Add(TimeSpan.Parse(ExecuteTime));
            if (rst < time)
            {
                rst = rst.AddDays(m_IntervalWeeks * 7);
            }
            return(rst);
        }
예제 #2
0
        private bool IsWeekValid(DateTime time)
        {
            DateTime fromDate = FromDate.AddDays(DayOfWeek.Sunday - FromDate.DayOfWeek).Date;
            DateTime nowDate  = time.AddDays(DayOfWeek.Sunday - time.DayOfWeek).Date;
            int      diff     = nowDate.Subtract(fromDate).Days;

            return((diff % (m_IntervalWeeks * 7)) == 0);
        }
예제 #3
0
 public OrderViewModel(int cookerID, string cookerName)
 {
     _cookerID   = cookerID;
     _cookerName = cookerName;
     FromDate    = Utility.FirstDateOfWeek(DateTime.Today.Year, Utility.GetWeekOfYear(DateTime.Now), CultureInfo.CurrentCulture);
     ToDate      = FromDate.AddDays(6);
     LoadData();
 }
예제 #4
0
 public SingleCookerViewModel(CookerViewModel model)
 {
     Cooker     = model;
     cookerID   = model.ID;
     cookerName = model.Name;
     FromDate   = Utility.FirstDateOfWeek(DateTime.Today.Year, Utility.GetWeekOfYear(DateTime.Now), CultureInfo.CurrentCulture);
     ToDate     = FromDate.AddDays(6);
     FilldData();
 }
예제 #5
0
        private async void GetTimeTable(int weekChange)
        {
            IsBusy = true;
            OnPropertyChangedModel(nameof(IsBusy));

            FromDate  = FromDate.AddDays(weekChange);
            ToDate    = ToDate.AddDays(weekChange);
            TimeTable = await _model.GetTimeTable(cookerID, FromDate);

            OnPropertyChangedModel(nameof(TimeTable));
            OnPropertyChangedModel(nameof(FromDate));
            OnPropertyChangedModel(nameof(ToDate));

            IsBusy = false;
            OnPropertyChangedModel(nameof(IsBusy));
        }
예제 #6
0
        public CRMContext()
        {
            IsMuted          = false;
            _serverIP        = ConfigurationManager.AppSettings["CallCenterIP"];
            LineNum          = 0;
            _canRegistration = true;
            _canExecute      = true;
            _refreshTimer    = new DispatcherTimer();
            ActiveChannels   = new ObservableCollection <ActiveChannelsDto>();
            NotAnsweredCalls = new ObservableCollection <NotAnsweredDto>();
            CallsList        = new ObservableCollection <CallsListDto>();
            var uri = new Uri(@"pack://application:,,,/Resources/ringin.wav");

            _ringPlayer         = new SoundPlayer(Application.GetResourceStream(uri).Stream);
            FromDate            = DateTime.Now.Date;
            ToDate              = FromDate.AddDays(1);
            EnablePhone         = false;
            _requestDataContext = new RequestControlContext();
        }
예제 #7
0
        public void UpdateEntries(ShowtimeGroup updatedGroup)
        {
            if (updatedGroup.FromDate < FromDate)
            {
                foreach (ShowtimeGroupEntry entry in ShowtimeGroupEntries)
                {
                    DateTime earlier = updatedGroup.ToDate < FromDate.AddDays(-1) ? ToDate : FromDate.AddDays(-1);
                    entry.GenerateShowtimes(Movie, updatedGroup.FromDate, earlier);
                }
            }
            else if (updatedGroup.FromDate > FromDate)
            {
                foreach (ShowtimeGroupEntry entry in ShowtimeGroupEntries)
                {
                    entry.RemoveShowtimes(FromDate, updatedGroup.FromDate.AddDays(-1));
                }
            }
            FromDate = updatedGroup.FromDate;

            if (updatedGroup.ToDate < ToDate)
            {
                foreach (ShowtimeGroupEntry entry in ShowtimeGroupEntries)
                {
                    entry.RemoveShowtimes(updatedGroup.ToDate.AddDays(1), ToDate);
                }
            }
            else if (updatedGroup.ToDate > ToDate)
            {
                foreach (ShowtimeGroupEntry entry in ShowtimeGroupEntries)
                {
                    DateTime later = ToDate.AddDays(1) > updatedGroup.FromDate ? ToDate.AddDays(1) : updatedGroup.FromDate;
                    entry.GenerateShowtimes(Movie, later, updatedGroup.ToDate);
                }
            }
            ToDate = updatedGroup.ToDate;

            UpdateGroupEntries(updatedGroup);
        }
예제 #8
0
        public List <List <string> > GetItems()
        {
            List <List <string> > items   = new List <List <string> >();
            List <ValutaControl>  contos  = new List <ValutaControl>(Context.GetAllContoValuta(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, FromDate, ToDate, VidVal, 1, CodeClient));
            List <ValutaControl>  contos1 = new List <ValutaControl>(Context.GetAllContoValuta(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, FromDate, ToDate, VidVal, 2, CodeClient));

            decimal sumad = 0, sumac = 0;
            decimal sumavald = 0, sumavalc = 0;
            decimal sumavalddf = 0, sumavalcdf = 0;
            decimal sumadm      = 0;
            decimal sumavaldm   = 0;
            decimal sumavalddfm = 0;

            sumad      = contos.Sum(e => e.Oborot);
            sumac      = contos1.Sum(e => e.Oborot);
            sumavald   = contos.Sum(e => e.ValSum);
            sumavalc   = contos1.Sum(e => e.ValSum);
            sumavalddf = contos.Sum(e => e.KursDif);
            sumavalcdf = contos1.Sum(e => e.KursDif);

            string currec = "", oldrec = "";
            string lastcode = "", lastname = "";

            contos.AddRange(contos1);
            foreach (
                var co in
                contos.OrderBy(e => e.ClienCode))
            {
                if (oldrec == "")
                {
                    oldrec = co.ClienCode;
                }
                currec = co.ClienCode;
                if (oldrec != currec)
                {
                    var item = new List <string>();
                    items.Add(NewMethod());
                    items.Add(item);
                    item = new List <string>();
                    item.Add("");
                    item.Add("");
                    item.Add("");
                    item.Add("");
                    item.Add("");
                    item.Add("");
                    item.Add(string.Format(Vf.LevFormat, sumadm));
                    item.Add("");
                    item.Add("");
                    item.Add(string.Format(Vf.ValFormat, sumavaldm));
                    item.Add("");
                    item.Add("");
                    item.Add(string.Format(Vf.LevFormat, sumavalddfm));
                    item.Add("");
                    item.Add("");
                    item.Add("");
                    item.Add("");
                    item.Add(lastcode);
                    item.Add(lastname);
                    item.Add("");
                    item.Add("");
                    items.Add(item);
                    items.Add(NewMethod());
                    sumadm      = 0;
                    sumavaldm   = 0;
                    sumavalddfm = 0;
                    oldrec      = currec;
                }
                List <string> item2 = new List <string>();
                item2.Add(co.PorNom);
                item2.Add(co.DocNum);
                item2.Add(co.Data);
                item2.Add(co.Folder);
                item2.Add(co.User);
                item2.Add(co.KindVal);
                item2.Add(string.Format(Vf.LevFormat, co.Oborot));
                var dac = Allacc.FirstOrDefault(e => e.Id == co.DebitAccount);
                if (dac != null)
                {
                    item2.Add(dac.Short);
                }
                dac = Allacc.FirstOrDefault(e => e.Id == co.CreditAccount);
                if (dac != null)
                {
                    item2.Add(dac.Short);
                }
                item2.Add(string.Format(Vf.ValFormat, co.ValSum));
                item2.Add(string.Format(Vf.KursFormat, co.Kurs));
                item2.Add(string.Format(Vf.KursFormat, co.MainKurs));
                item2.Add(string.Format(Vf.LevFormat, co.KursDif));
                item2.Add(co.Reason);
                item2.Add(co.Note);
                item2.Add(co.Pr1);
                item2.Add(co.Pr2);
                item2.Add(co.ClienCode); lastcode  = co.ClienCode;
                item2.Add(co.NameClient); lastname = co.NameClient;
                item2.Add(co.User);
                item2.Add(co.Id);
                items.Add(item2);
                sumadm      += co.Oborot;
                sumavaldm   += co.ValSum;
                sumavalddfm += co.KursDif;
            }
            var item1 = new List <string>();

            items.Add(NewMethod());
            items.Add(item1);
            item1 = new List <string>();
            item1.Add("");
            item1.Add("");
            item1.Add("");
            item1.Add("");
            item1.Add("");
            item1.Add("");
            item1.Add(string.Format(Vf.LevFormat, sumadm));
            item1.Add("");
            item1.Add("");
            item1.Add(string.Format(Vf.ValFormat, sumavaldm));
            item1.Add("");
            item1.Add("");
            item1.Add(string.Format(Vf.LevFormat, sumavalddfm));
            item1.Add("");
            item1.Add("");
            item1.Add("");
            item1.Add("");
            item1.Add(lastcode);
            item1.Add(lastname);
            item1.Add("");
            item1.Add("");
            items.Add(item1);
            items.Add(NewMethod());
            decimal nsd  = 0;
            decimal nsc  = 0;
            decimal nsdv = 0;
            decimal nscv = 0;

            if (FromDate.Month > 1)
            {
                var begcontosd =
                    new List <ValutaControl>(Context.GetAllContoValuta(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, new DateTime(FromDate.Year, 1, 1), FromDate.AddDays(-1), VidVal, 1, CodeClient));
                var begcontosc =
                    new List <ValutaControl>(Context.GetAllContoValuta(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, new DateTime(FromDate.Year, 1, 1), FromDate.AddDays(-1), VidVal, 2, CodeClient));
                nsd  = begcontosd.Sum(e => e.Oborot);
                nsc  = begcontosc.Sum(e => e.Oborot);
                nsdv = begcontosd.Sum(e => e.ValSum);
                nscv = begcontosc.Sum(e => e.ValSum);
            }
            if (CurrenAcc.TypeAccount == 1)
            {
                if (FromDate.Month == 1)
                {
                    BeginSaldoD = CurrenAcc.BeginSaldoL;
                    BeginValSd  = CurrenAcc.BeginSaldoV;
                }
                else
                {
                    BeginSaldoD = (nsd + CurrenAcc.BeginSaldoL) - (nsc);
                    BeginValSd  = (nsdv + CurrenAcc.BeginSaldoV) - (nscv);
                }
            }
            if (CurrenAcc.TypeAccount == 2)
            {
                if (FromDate.Month == 1)
                {
                    BeginSaldoK = CurrenAcc.BeginSaldoL;
                    BeginValSc  = CurrenAcc.BeginSaldoV;
                }
                else
                {
                    BeginSaldoK = (nsc + CurrenAcc.BeginSaldoL) - (nsd);
                    BeginValSc  = (nscv + CurrenAcc.BeginSaldoV) - (nsdv);
                }
            }
            OborotsDebit  = string.Format(Vf.LevFormat, sumad);
            OborotsCredit = string.Format(Vf.LevFormat, sumac);
            Oborotsvald   = string.Format(Vf.ValFormat, sumavald);
            Oborotsvalc   = string.Format(Vf.ValFormat, sumavalc);
            Sumavald      = string.Format(Vf.ValFormat, sumavald);
            Sumavalc      = string.Format(Vf.ValFormat, sumavalc);
            KursDifd      = string.Format(Vf.LevFormat, sumavalddf);
            KursDifc      = string.Format(Vf.LevFormat, sumavalcdf);


            TotalD = CurrenAcc.TypeAccount == 1
                ? string.Format(Vf.LevFormat, sumad + BeginSaldoD)
                : string.Format(Vf.LevFormat, sumad);
            TotalC = CurrenAcc.TypeAccount == 2
                ? string.Format(Vf.LevFormat, sumac + BeginSaldoK)
                : string.Format(Vf.LevFormat, sumac);
            if (CurrenAcc.TypeAccount == 1)
            {
                KrainoSaldoD  = (sumad + BeginSaldoD) - (sumac);
                KrainoSaldoDV = (sumavald + BeginValSd) - (sumavalc);
                KrainoSaldoKV = 0;
                Sad           = string.Format(Vf.KursFormat, KrainoSaldoDV != 0 ? KrainoSaldoD / KrainoSaldoDV : 0);
                Sak           = "";
            }
            if (CurrenAcc.TypeAccount == 2)
            {
                KrainoSaldoK  = (sumac + BeginSaldoK) - (sumad);
                KrainoSaldoKV = (sumavalc + BeginValSc) - (sumavald);
                KrainoSaldoDV = 0;
                Sad           = "";
                Sak           = string.Format(Vf.KursFormat, KrainoSaldoKV != 0 ? KrainoSaldoK / KrainoSaldoKV : 0);
            }
            return(items);
        }
예제 #9
0
        private async void LoadVatReport()
        {
            DateTime FromDate, ToDate;

            if (txtDateFrm.Text == string.Empty)
            {
                FromDate = DateTime.Today;
                FromDate = FromDate.AddDays(1 - FromDate.Day); // first day in current month
            }
            else
            {
                FromDate = localFromDate = txtDateFrm.DateTime.Date;
            }
            if (txtDateTo.Text == string.Empty)
            {
                ToDate = DateTime.Today.AddMonths(1);
                ToDate = ToDate.AddDays(-ToDate.Day); // last day in current month
            }
            else
            {
                ToDate = localToDate = txtDateTo.DateTime.Date;
            }

            busyIndicator.IsBusy = true;

            var    qapi    = api;
            var    country = qapi.CompanyEntity._CountryId;
            var    rapi    = new ReportAPI(qapi);
            string journal = cmbJournal.Text;
            var    vatTask = rapi.VatCodeSum(FromDate, ToDate, journal);

            SQLCache accounts = qapi.GetCache(typeof(Uniconta.DataModel.GLAccount)) ?? await qapi.LoadCache(typeof(Uniconta.DataModel.GLAccount));

            SQLCache vats = qapi.GetCache(typeof(Uniconta.DataModel.GLVat)) ?? await qapi.LoadCache(typeof(Uniconta.DataModel.GLVat));

            SQLCache vattypes = qapi.GetCache(typeof(Uniconta.DataModel.GLVatType)) ?? await qapi.LoadCache(typeof(Uniconta.DataModel.GLVatType));

            FinancialBalance[] sumVat = await vatTask;
            if (sumVat == null || accounts == null || vats == null || vattypes == null)
            {
                busyIndicator.IsBusy = false;
                UtilDisplay.ShowErrorCode(rapi.LastError);
                return;
            }

            Array.Sort(sumVat, new AccountSorter());

            VatReportLine v;
            var           lst = new List <VatReportLine>(sumVat.Length);

            int  decm       = 2;
            bool RoundTo100 = false;

            if (!qapi.CompanyEntity.HasDecimals)
            {
                CalculatedVAT.HasDecimals = PostedVAT.HasDecimals = WithoutVAT.HasDecimals = Accumulated.HasDecimals = false;
                RoundTo100 = true;
                decm       = 0;
            }

            var countrySelected = (CountryCode)Math.Max(0, vatCountry.SelectedIndex);

            var       AccsFound = new HashSet <int>();
            GLAccount Account;
            GLVat     Vat;
            int       i;
            bool      HasOffsetType0 = false, HasOffsetType1 = false;
            int       PrevAccount = 0;

            for (i = 0; (i < sumVat.Length); i++)
            {
                var sum = sumVat[i];
                Account = (GLAccount)accounts.Get(sum.AccountRowId);
                if (Account == null) // || Account._SystemAccount == (byte)SystemAccountTypes.SalesTaxOffset)
                {
                    continue;
                }
                //if (sum._Debit == 0 && sum._Credit == 0)
                //    continue;

                Vat = (GLVat)vats.Get(sum.VatRowId);
                if (Vat == null)
                {
                    continue;
                }

                var acStr = Account._Account;
                v = new VatReportLine();
                v.AmountWithVat = sum.Debit;
                v._PostedVAT    = sum.Credit;
                v._BaseVAT      = sum.AmountBase;

                v.AccountNumber = acStr;
                v.Account       = Account;
                v.AccountIsVat  = Account._SystemAccount == (byte)SystemAccountTypes.SalesTaxPayable || Account._SystemAccount == (byte)SystemAccountTypes.SalesTaxReceiveable ? (byte)1 : (byte)0;

                if (Vat._Account == acStr || Vat._OffsetAccount == acStr)
                {
                    if (Vat._Account == acStr)
                    {
                        v.AccountIsVat    = 1;
                        v.IsOffsetAccount = 0;
                    }
                    else
                    {
                        v.AccountIsVat    = 1;
                        v.IsOffsetAccount = 1;
                        if (Vat._VatType == 0)
                        {
                            HasOffsetType0 = true;
                        }
                        else
                        {
                            HasOffsetType1 = true;
                        }
                    }
                }
                else
                {
                    foreach (var va in (IEnumerable <GLVat>)vats.GetNotNullArray)
                    {
                        if (va._Account == acStr)
                        {
                            v.AccountIsVat    = 1;
                            v.IsOffsetAccount = 0;
                            break;
                        }
                        if (va._OffsetAccount == acStr)
                        {
                            v.AccountIsVat    = 1;
                            v.IsOffsetAccount = 1;
                            if (va._VatType == 0)
                            {
                                HasOffsetType0 = true;
                            }
                            else
                            {
                                HasOffsetType1 = true;
                            }
                            // do not break in case we foind the same account as _Account
                        }
                    }
                }

                v.Vat     = Vat;
                v.VatType = (byte)Vat._VatType;
                if (v.IsOffsetAccount == 1 && Vat._OffsetVatOperation != null)
                {
                    v._VatOperation = (byte)vattypes.Get(Vat._OffsetVatOperation).RowId;
                }
                else
                {
                    v._VatOperation = sum.VatOperation != 0 ? sum.VatOperation : Vat._VatOperationCode;
                }
                v._CalculatedVAT = Vat.VatAmount1(v.AmountWithVat, FromDate, RoundTo100, GLVatCalculationMethod.Netto);

                v.FromDate = FromDate;
                v.CalcRate(RoundTo100);

                var vattp = (GLVatType)vattypes.Get(v._VatOperation);
                if (vattp != null)
                {
                    v.VatOpr       = vattp;
                    v.vatOperation = vattp._Code;
                    v.BaseVatText  = vattp._Name;
                }
                lst.Add(v);

                if (PrevAccount != sum.AccountRowId)
                {
                    PrevAccount = sum.AccountRowId;
                    AccsFound.Add(sum.AccountRowId);
                }
            }

            foreach (var acc in (GLAccount[])accounts.GetNotNullArray)
            {
                if (acc._Vat != null)
                {
                    Vat = (GLVat)vats.Get(acc._Vat);
                    if (Vat == null)
                    {
                        continue;
                    }
                    if (countrySelected != 0 && countrySelected != (Vat._VatCountry != 0 ? Vat._VatCountry : country))
                    {
                        continue;
                    }
                    AccsFound.Add(acc.RowId);
                }
            }

            List <int> AccLst = AccsFound.ToList();

            AccsFound.Clear();

            FinancialBalance[] AccTotals = await rapi.GenerateTotal(AccLst, FromDate, ToDate, journal, null, 0, true, false);

            SQLCacheTemplate <FinancialBalance> AccLookup = null;

            if (AccTotals != null && AccTotals.Length > 0)
            {
                AccLookup = new SQLCacheTemplate <FinancialBalance>(AccTotals, false);
            }

            lst.Sort(new VatAccountSort());

            FinancialBalance AccTotal;
            int           AccountRowId = 0;
            double        AmountDif    = 0d;
            VatReportLine vDif         = new VatReportLine();

            for (i = lst.Count; (--i >= 0);)
            {
                v = lst[i];
                if (v.Account.RowId != AccountRowId)
                {
                    if (AmountDif > 0.005d || AmountDif < -0.005d)
                    {
                        vDif.AmountWithout = GLVat.Round(AmountDif);
                        lst.Add(vDif);
                        vDif = new VatReportLine();
                    }

                    AccountRowId = v.Account.RowId;
                    AccTotal     = AccLookup?.Get(AccountRowId);
                    if (AccTotal != null)
                    {
                        AmountDif = (AccTotal._Debit - AccTotal._Credit) / 100d;
                    }
                    else
                    {
                        AmountDif = 0d;
                    }

                    AccsFound.Add(AccountRowId);
                }
                AmountDif           -= v.AmountWithVat;
                vDif.Account         = v.Account;
                vDif.AccountNumber   = v.AccountNumber;
                vDif.VatType         = v.VatType;
                vDif.AccountIsVat    = v.AccountIsVat;
                vDif.IsOffsetAccount = v.IsOffsetAccount;
            }

            if (AmountDif > 0.005d || AmountDif < -0.005d)
            {
                vDif.AmountWithout = GLVat.Round(AmountDif);
                lst.Add(vDif);
            }

            if (AccLookup != null)
            {
                // Add account, that has a VAT-code but no transactios with VAT.
                for (i = 0; (i < AccTotals.Length); i++)
                {
                    AccTotal = AccTotals[i];
                    if (!AccsFound.Contains(AccTotal.RowId) && (AccTotal._Debit - AccTotal._Credit) != 0)
                    {
                        Account = (GLAccount)accounts.Get(AccTotal.RowId);
                        if (Account?._Vat == null)
                        {
                            continue;
                        }
                        Vat = (GLVat)vats.Get(Account._Vat);
                        if (Vat == null)
                        {
                            continue;
                        }

                        vDif = new VatReportLine();
                        vDif.AmountWithout = (AccTotal._Debit - AccTotal._Credit) / 100d;
                        vDif.Account       = Account;
                        vDif.AccountNumber = Account._Account;
                        vDif.VatType       = (byte)Vat._VatType;
                        lst.Add(vDif);
                    }
                }
            }

            if (countrySelected != 0)
            {
                for (i = lst.Count; (--i >= 0);)
                {
                    Vat = (GLVat)vats.Get(lst[i].VatCode);
                    if (Vat != null)
                    {
                        if (countrySelected != (Vat._VatCountry != 0 ? Vat._VatCountry : country))
                        {
                            lst.RemoveAt(i);
                            continue;
                        }
                    }
                }
            }

            vDif = null;

            for (int k = 0; (k < 4); k++)
            {
                string helptext;
                if (k == 0)
                {
                    helptext = "sales";
                }
                else if (k == 1)
                {
                    helptext = "buy";
                }
                else if (k == 2)
                {
                    helptext = "sales vat";
                }
                else
                {
                    helptext = "buy vat";
                }

                for (int n = 0; n < 3; n++)
                {
                    vDif              = new VatReportLine();
                    vDif.helptext     = helptext;
                    vDif.Order        = (n > 0) ? n : -1; // header, total, empty
                    vDif.VatType      = (byte)(k % 2);
                    vDif.AccountIsVat = (byte)(k / 2);
                    vDif.isvatotal    = (k >= 2 && n == 1);
                    lst.Add(vDif);

                    if (vDif.AccountIsVat == 1)
                    {
                        if ((HasOffsetType0 && vDif.VatType == 0) || (HasOffsetType1 && vDif.VatType == 1))
                        {
                            vDif                 = new VatReportLine();
                            vDif.helptext        = "import vat";
                            vDif.Order           = (n > 0) ? n : -1; // header, total, empty
                            vDif.VatType         = (byte)(k % 2);
                            vDif.AccountIsVat    = 1;
                            vDif.IsOffsetAccount = 1;
                            vDif.isvatotal       = true;
                            lst.Add(vDif);
                        }
                    }
                }
            }
            vDif = null;

            lst.Sort(new VatTotalsSort());
            double d1 = 0d, d2 = 0d, d3 = 0d, d4 = 0d;

            double[] VatOperationValues = new double[256];
            double[] VatOperationBases  = new double[256];

            double[] VatValues          = new double[256];
            double[] VatBases           = new double[256];

            VatSumOperationReport[] vatReportSum = new VatSumOperationReport[127];

            for (i = 0; (i < lst.Count); i++)
            {
                v = lst[i];

                if (v.Order == 1) // total
                {
                    v.AmountWithVat = Math.Round(d1, decm);
                    var AmountWithout = Math.Round(d2, decm);
                    v.AmountWithout  = AmountWithout;
                    v._CalculatedVAT = Math.Round(d3, decm);
                    v._PostedVAT     = Math.Round(d4, decm);
                    d1 = d2 = d3 = d4 = 0d;

                    if (country == CountryCode.Denmark && AmountWithout != 0 && v.AccountIsVat == 1)
                    {
                        if (v.IsOffsetAccount == 0)
                        {
                            // here we sum up the amount without vatcodes
                            if (v.VatType == 0)
                            {
                                var sumLine = CreateSum(vatReportSum, 33);
                                sumLine._Amount -= AmountWithout;
                            }
                            else
                            {
                                var sumLine = CreateSum(vatReportSum, 23);
                                sumLine._Amount += AmountWithout;
                                sumLine          = CreateSum(vatReportSum, 31);
                                sumLine._Amount += AmountWithout;
                            }
                        }
                        else
                        {
                            if (v.VatType == 1)
                            {
                                var sumLine = CreateSum(vatReportSum, 34);
                                sumLine._Amount -= AmountWithout;
                            }
                        }
                    }
                }
                else
                {
                    d1 += v.AmountWithVat;
                    d2 += v.AmountWithout;
                    d3 += v._CalculatedVAT;
                    d4 += v._PostedVAT;

                    if (v.AccountIsVat == 1)
                    {
                        if (v.IsOffsetAccount == 0)
                        {
                            VatOperationValues[v._VatOperation] += v.AmountWithVat;
                            if (v.Vat != null)
                            {
                                VatValues[v.Vat.RowId] += v.AmountWithVat;
                            }
                        }
                    }
                    else
                    {
                        VatOperationBases[v._VatOperation] += v.AmountWithVat;
                        if (v.Vat != null)
                        {
                            VatBases[v.Vat.RowId] += v.AmountWithVat;
                        }
                    }
                }
            }

            vDif      = new VatReportLine();
            vDif.Text = string.Format("{0}: {1}, {2}", Uniconta.ClientTools.Localization.lookup("FinalVatStatus"), Uniconta.ClientTools.Localization.lookup("AmountBase"), Uniconta.ClientTools.Localization.lookup("VATamount"));
            lst.Add(vDif);

            foreach (var c in (GLVatType[])vattypes.GetNotNullArray)
            {
                if (c == null)
                {
                    continue;
                }

                vDif = new VatReportLine();
                vDif.vatOperation  = c._Code;
                vDif._Rate         = c._Pct1;
                vDif.Text          = string.Concat(c._Code, ", ", c._Name);
                vDif.AmountWithVat = VatOperationBases[c._RowNo];
                vDif._PostedVAT    = VatOperationValues[c._RowNo];
                vDif.AccountIsVat  = 1;
                lst.Add(vDif);

                int pos = c._Position1;
                if (pos > 0)
                {
                    UpdateSum(vatReportSum, vDif, pos, c._Position2, c._Position3);
                }
                pos = c._Position4;
                if (pos > 0)
                {
                    UpdateSum(vatReportSum, vDif, pos, c._Position5, c._Position6);
                }
                pos = c._Position7;
                if (pos > 0)
                {
                    UpdateSum(vatReportSum, vDif, pos, c._Position8, c._Position9);
                }
                pos = c._Position10;
                if (pos > 0)
                {
                    UpdateSum(vatReportSum, vDif, pos, c._Position11, c._Position12);
                }
                pos = c._Position13;
                if (pos > 0)
                {
                    UpdateSum(vatReportSum, vDif, pos, c._Position14, c._Position15);
                }
            }

            List <VatReportLine> vatlst = new List <VatReportLine>();

            this.vatlst = vatlst;

            for (int k = 0; (k < 2); k++)
            {
                vDif      = new VatReportLine();
                vDif.Text = string.Empty;
                lst.Add(vDif);

                vDif              = new VatReportLine();
                vDif.VatType      = (byte)k;
                vDif.Order        = -1;
                vDif.AccountIsVat = 1;
                lst.Add(vDif);

                foreach (var c in (GLVat[])vats.GetNotNullArray)
                {
                    if (c != null && (int)c._VatType == k)
                    {
                        if (countrySelected != 0 && countrySelected != (c._VatCountry != 0 ? c._VatCountry : country))
                        {
                            continue;
                        }

                        vDif               = new VatReportLine();
                        vDif.Vat           = c;
                        vDif.Text          = string.Concat(c._Vat, ", ", c._Name);
                        vDif.AmountWithVat = VatBases[c.RowId];
                        vDif._PostedVAT    = VatValues[c.RowId];
                        vDif.AccountIsVat  = 1;
                        vDif.FromDate      = FromDate;
                        vDif.CalcRate(RoundTo100);
                        lst.Add(vDif);
                        vatlst.Add(vDif);
                    }
                }
            }

            dgVatReport.ItemsSource = lst;
            if (lst.Count > 0)
            {
                SetMenuItem();
            }

            if (country == CountryCode.Denmark)
            {
                AccLst.Clear();
                foreach (var acc in (GLAccount[])accounts.GetNotNullArray)
                {
                    if (acc._SystemAccount == (byte)SystemAccountTypes.OtherTax)
                    {
                        AccLst.Add(acc.RowId);
                    }
                }
                if (AccLst != null && AccLst.Count > 0)
                {
                    AccTotals = await rapi.GenerateTotal(AccLst, FromDate, ToDate);

                    if (AccTotals != null && AccTotals.Length > 0)
                    {
                        var otherTaxList = new ReportDataDenmark[AccTotals.Length];
                        i = 14;
                        foreach (var acTot in AccTotals)
                        {
                            var Acc = accounts.Get(acTot.AccountRowId);
                            var lin = new VatSumOperationReport()
                            {
                                _Text   = Acc.KeyName,
                                _Amount = (acTot._Debit - acTot._Credit) / 100d,
                                _Line   = i
                            };
                            vatReportSum[i] = lin;
                            i++;
                            if (i == 19)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            for (i = vatReportSumSize + 1; (--i >= 1);)
            {
                if (vatReportSum[i] == null)
                {
                    vatReportSum[i] = new VatSumOperationReport()
                    {
                        _Line = i
                    }
                }
            }
            ;

            this.vatReportSum = vatReportSum.Where(r => r != null).ToList();

            dgVatReport.Visibility = Visibility.Visible;
            busyIndicator.IsBusy   = false;
        }
예제 #10
0
        public List <List <string> > GetItems()
        {
            Rowfoother = new Dictionary <int, List <string> >();
            List <List <string> > items    = new List <List <string> >();
            List <ValutaControl>  contos   = new List <ValutaControl>(Context.GetAllContoValuta(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, FromDate, ToDate, VidVal, 1, CodeClient));
            List <ValutaControl>  contos1  = new List <ValutaControl>(Context.GetAllContoValuta(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, FromDate, ToDate, VidVal, 2, CodeClient));
            List <ValutaControl>  contos3  = new List <ValutaControl>(Context.GetAllContoValuta(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, FromDate, ToDate, VidVal, 1, CodeClient));
            List <ValutaControl>  contos4  = new List <ValutaControl>(Context.GetAllContoValuta(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, FromDate, ToDate, VidVal, 2, CodeClient));
            List <ValutaControl>  contosb  = null;
            List <ValutaControl>  contos1b = null;
            var rezil = Context.GetAllAnaliticSaldos(CurrenAcc.Id, CurrenAcc.FirmaId, !string.IsNullOrWhiteSpace(VidVal) ? VidVal : null);

            if (!string.IsNullOrWhiteSpace(CodeClient))
            {
                rezil = rezil.Where(e => e.Code == CodeClient).ToList();
            }
            var rezi = (from t in rezil
                        group t by new { t.Code }
                        into grp
                        select new SaldoFactura
            {
                Code = grp.Key.Code,
                BeginSaldoCredit = grp.Sum(t => t.BeginSaldoCredit),
                BeginSaldoCreditValuta = grp.Sum(t => t.BeginSaldoCreditValuta),
                BeginSaldoDebit = grp.Sum(t => t.BeginSaldoDebit),
                BeginSaldoDebitValuta = grp.Sum(t => t.BeginSaldoDebitValuta),
                BeginSaldoDebitKol = grp.Sum(t => t.BeginSaldoDebitKol),
                BeginSaldoCreditKol = grp.Sum(t => t.BeginSaldoDebitKol),
            }).ToList();

            if (fromDate.Month > 1 && !string.IsNullOrWhiteSpace(CodeClient))
            {
                contosb  = new List <ValutaControl>(Context.GetAllContoValuta(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, new DateTime(FromDate.Year, 1, 1), FromDate.AddDays(-1), VidVal, 1, CodeClient));
                contos1b = new List <ValutaControl>(Context.GetAllContoValuta(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, new DateTime(FromDate.Year, 1, 1), FromDate.AddDays(-1), VidVal, 2, CodeClient));

                if (contosb != null)
                {
                    var query = (from t in contosb
                                 group t by new { t.ClienCode }
                                 into grp
                                 select new ValutaControl
                    {
                        ClienCode = grp.Key.ClienCode,
                        Oborot = grp.Sum(t => t.Oborot),
                        ValSum = grp.Sum(t => t.ValSum)
                    }).ToList();
                    foreach (var item in query)
                    {
                        if (rezi.FirstOrDefault(e => e.Code == item.ClienCode) != null)
                        {
                            rezi.FirstOrDefault(e => e.Code == item.ClienCode).BeginSaldoDebit       += item.Oborot;
                            rezi.FirstOrDefault(e => e.Code == item.ClienCode).BeginSaldoDebitValuta += item.ValSum;
                        }
                        else
                        {
                            rezi.Add(new SaldoFactura {
                                Code = item.ClienCode, BeginSaldoDebit = item.Oborot, BeginSaldoDebitValuta = item.ValSum
                            });
                        }
                    }
                }
                if (contos1b != null)
                {
                    var query1 = (from t in contos1b
                                  group t by new { t.ClienCode }
                                  into grp
                                  select new ValutaControl
                    {
                        ClienCode = grp.Key.ClienCode,
                        Oborot = grp.Sum(t => t.Oborot),
                        ValSum = grp.Sum(t => t.ValSum)
                    }).ToList();
                    foreach (var item in query1)
                    {
                        if (rezi.FirstOrDefault(e => e.Code == item.ClienCode) != null)
                        {
                            rezi.FirstOrDefault(e => e.Code == item.ClienCode).BeginSaldoCredit       += item.Oborot;
                            rezi.FirstOrDefault(e => e.Code == item.ClienCode).BeginSaldoCreditValuta += item.ValSum;
                        }
                        else
                        {
                            rezi.Add(new SaldoFactura {
                                Code = item.ClienCode, BeginSaldoCredit = item.Oborot, BeginSaldoCreditValuta = item.ValSum
                            });
                        }
                    }
                }
            }
            decimal sumad = 0, sumac = 0;
            decimal sumavald = 0, sumavalc = 0;
            decimal sumavalddf = 0, sumavalcdf = 0;
            decimal sumadm      = 0;
            decimal sumavaldm   = 0;
            decimal sumavalddfm = 0;

            sumad      = contos.Sum(e => e.Oborot);
            sumac      = contos1.Sum(e => e.Oborot);
            sumavald   = contos.Sum(e => e.ValSum);
            sumavalc   = contos1.Sum(e => e.ValSum);
            sumavalddf = contos.Sum(e => e.KursDif);
            sumavalcdf = contos1.Sum(e => e.KursDif);

            string currec = "", oldrec = "";
            string lastcode = "", lastname = "";

            contos3.AddRange(contos4);
            int currentrow = 0;

            foreach (
                var co in
                contos3.OrderBy(e => e.ClienCode))
            {
                if (oldrec == "")
                {
                    oldrec = co.ClienCode;
                }
                currec = co.ClienCode;
                if (oldrec != currec)
                {
                    var lsumad1      = contos.Where(e => e.ClienCode == oldrec).Sum(e => e.Oborot);
                    var lsumac1      = contos1.Where(e => e.ClienCode == oldrec).Sum(e => e.Oborot);
                    var lsumavald1   = contos.Where(e => e.ClienCode == oldrec).Sum(e => e.ValSum);
                    var lsumavalc1   = contos1.Where(e => e.ClienCode == oldrec).Sum(e => e.ValSum);
                    var lsumavalddf1 = contos.Where(e => e.ClienCode == oldrec).Sum(e => e.KursDif);
                    var lsumavalcdf1 = contos1.Where(e => e.ClienCode == oldrec).Sum(e => e.KursDif);
                    var saldo1       = rezi.FirstOrDefault(e => e.Code == oldrec);
                    if (saldo1 != null)
                    {
                        rezi.Remove(saldo1);
                    }
                    var lnsd1  = saldo1 != null ? saldo1.BeginSaldoDebit : 0;
                    var lnsc1  = saldo1 != null ? saldo1.BeginSaldoCredit : 0;
                    var lnsdv1 = saldo1 != null ? saldo1.BeginSaldoDebitValuta : 0;
                    var lnscv1 = saldo1 != null ? saldo1.BeginSaldoCreditValuta : 0;
                    if (CurrenAcc.TypeAccount == 1)
                    {
                        lnsd1  = lnsd1 - lnsc1;
                        lnsdv1 = lnsdv1 - lnscv1;
                        lnsc1  = 0;
                        lnscv1 = 0;
                    }
                    else
                    {
                        lnsc1  = lnsc1 - lnsd1;
                        lnscv1 = lnscv1 - lnsdv1;
                        lnsd1  = 0;
                        lnsdv1 = 0;
                    }
                    var     lsbord1  = lnsd1 + lsumad1;
                    var     lsborc1  = lnsc1 + lsumac1;
                    var     lsbordv1 = lnsdv1 + lsumavald1;
                    var     lsborcv1 = lnscv1 + lsumavalc1;
                    decimal lksd1    = 0;
                    decimal lksc1    = 0;
                    decimal lksdv1   = 0;
                    decimal lkscv1   = 0;
                    if (CurrenAcc.TypeAccount == 1)
                    {
                        lksd1  = (lsumad1 + lnsd1) - (lsumac1 + lnsc1);
                        lksdv1 = (lsumavald1 + lnsdv1) - (lsumavalc1 + lnsc1);
                    }
                    else
                    {
                        lksc1  = (lsumac1 + lnsc1) - (lsumad1 + lnsd1);
                        lkscv1 = (lsumavalc1 + lnscv1) - (lsumavald1 + lnsdv1);
                    }

                    var row2 = new List <string>();
                    row2.Add("----------------------------------------------------------------------------------");
                    row2.Add("|Сборно          |          л е в а              |           валута              |");
                    row2.Add("|                |    дебит      |    кредит     |    дебит      |    кредит     |");
                    row2.Add("----------------------------------------------------------------------------------");
                    row2.Add($"|Начални салда   |{lnsd1.ToString(Vf.LevFormatUI),15}|{lnsc1.ToString(Vf.LevFormatUI),15}|{lnsdv1.ToString(Vf.ValFormatUI),15}|{lnscv1.ToString(Vf.ValFormatUI),15}|");
                    row2.Add($"|Oбороти         |{lsumad1.ToString(Vf.LevFormatUI),15}|{lsumac1.ToString(Vf.LevFormatUI),15}|{lsumavald1.ToString(Vf.ValFormatUI),15}|{lsumavalc1.ToString(Vf.ValFormatUI),15}|");
                    row2.Add($"|Сборове         |{lsbord1.ToString(Vf.LevFormatUI),15}|{lsborc1.ToString(Vf.LevFormatUI),15}|{lsbordv1.ToString(Vf.ValFormatUI),15}|{lsborcv1.ToString(Vf.ValFormatUI),15}|");
                    row2.Add($"|Крайни салда    |{lksd1.ToString(Vf.LevFormatUI),15}|{lksc1.ToString(Vf.LevFormatUI),15}|{lksdv1.ToString(Vf.ValFormatUI),15}|{lkscv1.ToString(Vf.ValFormatUI),15}|");
                    row2.Add("----------------------------------------------------------------------------------");

                    Rowfoother.Add(currentrow - 1, row2);
                    oldrec = currec;
                }
                List <string> item2 = new List <string>();
                item2.Add(co.PorNom);
                item2.Add(co.DocNum);
                item2.Add(co.Data);
                item2.Add(co.Folder);
                item2.Add(co.User);
                item2.Add(co.KindVal);
                item2.Add(string.Format(Vf.LevFormat, co.Oborot));
                var dac = Allacc.FirstOrDefault(e => e.Id == co.DebitAccount);
                if (dac != null)
                {
                    item2.Add(dac.Short);
                }
                dac = Allacc.FirstOrDefault(e => e.Id == co.CreditAccount);
                if (dac != null)
                {
                    item2.Add(dac.Short);
                }
                item2.Add(string.Format(Vf.ValFormat, co.ValSum));
                item2.Add(string.Format(Vf.KursFormat, co.Kurs));
                item2.Add(string.Format(Vf.KursFormat, co.MainKurs));
                item2.Add(string.Format(Vf.LevFormat, co.KursDif));
                item2.Add(co.Reason);
                item2.Add(co.Note);
                item2.Add(co.Pr1);
                item2.Add(co.Pr2);
                item2.Add(co.ClienCode); lastcode  = co.ClienCode;
                item2.Add(co.NameClient); lastname = co.NameClient;
                item2.Add(co.NInvoice);
                item2.Add(co.DInvoce);
                item2.Add(co.User);
                item2.Add(co.Id);
                items.Add(item2);
                sumadm      += co.Oborot;
                sumavaldm   += co.ValSum;
                sumavalddfm += co.KursDif;
                currentrow++;
            }

            var lsumad      = contos.Where(e => e.ClienCode == currec).Sum(e => e.Oborot);
            var lsumac      = contos1.Where(e => e.ClienCode == currec).Sum(e => e.Oborot);
            var lsumavald   = contos.Where(e => e.ClienCode == currec).Sum(e => e.ValSum);
            var lsumavalc   = contos1.Where(e => e.ClienCode == currec).Sum(e => e.ValSum);
            var lsumavalddf = contos.Where(e => e.ClienCode == currec).Sum(e => e.KursDif);
            var lsumavalcdf = contos1.Where(e => e.ClienCode == currec).Sum(e => e.KursDif);
            var saldo       = rezi.FirstOrDefault(e => e.Code == currec);

            var lnsd  = saldo != null ? saldo.BeginSaldoDebit : 0;
            var lnsc  = saldo != null ? saldo.BeginSaldoCredit : 0;
            var lnsdv = saldo != null ? saldo.BeginSaldoDebitValuta : 0;
            var lnscv = saldo != null ? saldo.BeginSaldoCreditValuta : 0;

            if (saldo != null)
            {
                rezi.Remove(saldo);
            }
            if (CurrenAcc.TypeAccount == 1)
            {
                lnsd  = lnsd - lnsc;
                lnsdv = lnsdv - lnscv;
                lnsc  = 0;
                lnscv = 0;
            }
            else
            {
                lnsc  = lnsc - lnsd;
                lnscv = lnscv - lnsdv;
                lnsd  = 0;
                lnsdv = 0;
            }
            var     lsbord  = lnsd + lsumad;
            var     lsborc  = lnsc + lsumac;
            var     lsbordv = lnsdv + lsumavald;
            var     lsborcv = lnscv + lsumavalc;
            decimal lksd    = 0;
            decimal lksc    = 0;
            decimal lksdv   = 0;
            decimal lkscv   = 0;

            if (CurrenAcc.TypeAccount == 1)
            {
                lksd  = (lsumad + lnsd) - (lsumac + lnsc);
                lksdv = (lsumavald + lnsdv) - (lsumavalc + lnsc);
            }
            else
            {
                lksc  = (lsumac + lnsc) - (lsumad + lnsd);
                lkscv = (lsumavalc + lnscv) - (lsumavald + lnsdv);
            }
            if (currentrow > 0)
            {
                var row1 = new List <string>();
                row1.Add("----------------------------------------------------------------------------------");
                row1.Add("|Сборно          |          л е в а              |           валута              |");
                row1.Add("|                |    дебит      |    кредит     |    дебит      |    кредит     |");
                row1.Add("----------------------------------------------------------------------------------");
                row1.Add($"|Начални салда   |{lnsd.ToString(Vf.LevFormatUI),15}|{lnsc.ToString(Vf.LevFormatUI),15}|{lnsdv.ToString(Vf.ValFormatUI),15}|{lnscv.ToString(Vf.ValFormatUI),15}|");
                row1.Add($"|Oбороти         |{lsumad.ToString(Vf.LevFormatUI),15}|{lsumac.ToString(Vf.LevFormatUI),15}|{lsumavald.ToString(Vf.ValFormatUI),15}|{lsumavalc.ToString(Vf.ValFormatUI),15}|");
                row1.Add($"|Сборове         |{lsbord.ToString(Vf.LevFormatUI),15}|{lsborc.ToString(Vf.LevFormatUI),15}|{lsbordv.ToString(Vf.ValFormatUI),15}|{lsborcv.ToString(Vf.ValFormatUI),15}|");
                row1.Add($"|Крайни салда    |{lksd.ToString(Vf.LevFormatUI),15}|{lksc.ToString(Vf.LevFormatUI),15}|{lksdv.ToString(Vf.ValFormatUI),15}|{lkscv.ToString(Vf.ValFormatUI),15}|");
                row1.Add("----------------------------------------------------------------------------------");
                Rowfoother.Add(currentrow - 1, row1);
            }

            foreach (var rez in rezi)
            {
                currentrow++;
                List <string> item2 = new List <string>();
                item2.Add("*****");
                item2.Add("");
                item2.Add("");
                item2.Add("");
                item2.Add("");
                item2.Add("");
                item2.Add("");
                item2.Add("");
                item2.Add("");
                item2.Add("");
                item2.Add("");
                item2.Add("");
                item2.Add("");
                item2.Add("");
                item2.Add("");
                item2.Add("");
                item2.Add("");
                item2.Add(rez.Code);
                item2.Add(rez.NameContragent);
                item2.Add(rez.NumInvoise);
                item2.Add(rez.Date.ToShortDateString());
                item2.Add("");
                item2.Add("");
                items.Add(item2);
                var row1 = new List <string>();
                row1.Add("----------------------------------------------------------------------------------");
                row1.Add("|Сборно          |          л е в а              |           валута              |");
                row1.Add("|                |    дебит      |    кредит     |    дебит      |    кредит     |");
                row1.Add("----------------------------------------------------------------------------------");
                row1.Add($"|Начални салда   |{rez.BeginSaldoDebit.ToString(Vf.LevFormatUI),15}|{rez.BeginSaldoCredit.ToString(Vf.LevFormatUI),15}|{rez.BeginSaldoDebitValuta.ToString(Vf.ValFormatUI),15}|{rez.BeginSaldoCreditValuta.ToString(Vf.ValFormatUI),15}|");
                row1.Add($"|Oбороти         |{0.ToString(Vf.LevFormatUI),15}|{0.ToString(Vf.LevFormatUI),15}|{0.ToString(Vf.ValFormatUI),15}|{0.ToString(Vf.ValFormatUI),15}|");
                row1.Add($"|Сборове         |{0.ToString(Vf.LevFormatUI),15}|{0.ToString(Vf.LevFormatUI),15}|{0.ToString(Vf.ValFormatUI),15}|{0.ToString(Vf.ValFormatUI),15}|");
                row1.Add($"|Крайни салда    |{rez.BeginSaldoDebit.ToString(Vf.LevFormatUI),15}|{rez.BeginSaldoCredit.ToString(Vf.LevFormatUI),15}|{rez.BeginSaldoDebitValuta.ToString(Vf.ValFormatUI),15}|{rez.BeginSaldoCreditValuta.ToString(Vf.ValFormatUI),15}|");
                row1.Add("----------------------------------------------------------------------------------");
                Rowfoother.Add(currentrow - 1, row1);
            }
            decimal nsd  = 0;
            decimal nsc  = 0;
            decimal nsdv = 0;
            decimal nscv = 0;

            if (FromDate.Month > 1)
            {
                var begcontosd =
                    new List <ValutaControl>(Context.GetAllContoValuta(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, new DateTime(FromDate.Year, 1, 1), FromDate.AddDays(-1), VidVal, 1, CodeClient));
                var begcontosc =
                    new List <ValutaControl>(Context.GetAllContoValuta(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, new DateTime(FromDate.Year, 1, 1), FromDate.AddDays(-1), VidVal, 2, CodeClient));
                nsd  = begcontosd.Sum(e => e.Oborot);
                nsc  = begcontosc.Sum(e => e.Oborot);
                nsdv = begcontosd.Sum(e => e.ValSum);
                nscv = begcontosc.Sum(e => e.ValSum);
            }
            if (CurrenAcc.TypeAccount == 1)
            {
                if (FromDate.Month == 1)
                {
                    BeginSaldoD = CurrenAcc.BeginSaldoL;
                    BeginValSd  = CurrenAcc.BeginSaldoV;
                }
                else
                {
                    BeginSaldoD = (nsd + CurrenAcc.BeginSaldoL) - (nsc);
                    BeginValSd  = (nsdv + CurrenAcc.BeginSaldoV) - (nscv);
                }
            }
            if (CurrenAcc.TypeAccount == 2)
            {
                if (FromDate.Month == 1)
                {
                    BeginSaldoK = CurrenAcc.BeginSaldoL;
                    BeginValSc  = CurrenAcc.BeginSaldoV;
                }
                else
                {
                    BeginSaldoK = (nsc + CurrenAcc.BeginSaldoL) - (nsd);
                    BeginValSc  = (nscv + CurrenAcc.BeginSaldoV) - (nsdv);
                }
            }
            OborotsDebit  = string.Format(Vf.LevFormat, sumad);
            OborotsCredit = string.Format(Vf.LevFormat, sumac);
            Oborotsvald   = string.Format(Vf.ValFormat, sumavald);
            Oborotsvalc   = string.Format(Vf.ValFormat, sumavalc);
            Sumavald      = string.Format(Vf.ValFormat, sumavald);
            Sumavalc      = string.Format(Vf.ValFormat, sumavalc);
            KursDifd      = string.Format(Vf.LevFormat, sumavalddf);
            KursDifc      = string.Format(Vf.LevFormat, sumavalcdf);


            TotalD = CurrenAcc.TypeAccount == 1
                ? string.Format(Vf.LevFormat, sumad + BeginSaldoD)
                : string.Format(Vf.LevFormat, sumad);
            TotalC = CurrenAcc.TypeAccount == 2
                ? string.Format(Vf.LevFormat, sumac + BeginSaldoK)
                : string.Format(Vf.LevFormat, sumac);
            if (CurrenAcc.TypeAccount == 1)
            {
                KrainoSaldoD  = (sumad + BeginSaldoD) - (sumac);
                KrainoSaldoDV = (sumavald + BeginValSd) - (sumavalc);
                KrainoSaldoKV = 0;
                Sad           = string.Format(Vf.KursFormat, KrainoSaldoDV != 0 ? KrainoSaldoD / KrainoSaldoDV : 0);
                Sak           = "";
            }
            if (CurrenAcc.TypeAccount == 2)
            {
                KrainoSaldoK  = (sumac + BeginSaldoK) - (sumad);
                KrainoSaldoKV = (sumavalc + BeginValSc) - (sumavald);
                KrainoSaldoDV = 0;
                Sad           = "";
                Sak           = string.Format(Vf.KursFormat, KrainoSaldoKV != 0 ? KrainoSaldoK / KrainoSaldoKV : 0);
            }
            return(items);
        }
예제 #11
0
            public async Task WhenIAskForEventsOutsideTheEventsDateRange_ItReturnsTheEvent()
            {
                var events = await Client.QueryEventsAndAssertOK(fromDate : FromDate.AddDays(-1), toDate : ToDate.AddDays(1));

                Assert.NotEmpty(events);
            }
예제 #12
0
            public async Task WhenIAskForEventsToBeforeThatDate_ItReturnsNoEvents()
            {
                var events = await Client.QueryEventsAndAssertOK(toDate : FromDate.AddDays(-1));

                Assert.Empty(events);
            }
예제 #13
0
        public List <Date_Time> Evaluate(Date_Time StartDate, Date_Time FromDate, Date_Time ToDate)
        {
            List <Date_Time> DateTimes = new List <Date_Time>();

            DateTimes.AddRange(StaticOccurrences);

            // If the Recur is restricted by COUNT, we need to evaluate just
            // after any static occurrences so it's correctly restricted to a
            // certain number. NOTE: fixes bug #13 and bug #16
            if (Count > 0)
            {
                FromDate = StartDate;
                foreach (Date_Time dt in StaticOccurrences)
                {
                    if (FromDate < dt)
                    {
                        FromDate = dt.AddSeconds(1);
                    }
                }
            }

            // Handle "UNTIL" values that are date-only. If we didn't change values here, "UNTIL" would
            // exclude the day it specifies, instead of the inclusive behaviour it should exhibit.
            if (Until != null && !Until.HasTime)
            {
                Until.Value = new DateTime(Until.Year, Until.Month, Until.Day, 23, 59, 59, Until.Value.Kind);
            }

            // Ignore recurrences that occur outside our time frame we're looking at
            if ((Until != null && FromDate > Until) ||
                ToDate < StartDate)
            {
                return(DateTimes);
            }

            // Narrow down our time range further to avoid over-processing
            if (Until != null && Until < ToDate)
            {
                ToDate = Until;
            }
            if (StartDate > FromDate)
            {
                FromDate = StartDate;
            }

            // If the frequency is WEEKLY, and the interval is greater than 1,
            // then we need to ensure that the StartDate occurs in one of the
            // "active" weeks, to ensure that we properly "step" through weeks.
            // NOTE: Fixes bug #1741093 - WEEKLY frequency eval behaves strangely
            if (Frequency == FrequencyType.WEEKLY &&
                Interval > 1)
            {
                // Get the week of year of the time frame we want to calculate
                int firstEvalWeek = m_Calendar.GetWeekOfYear(FromDate.Value, System.Globalization.CalendarWeekRule.FirstFourDayWeek, Wkst);

                // Count backwards in years, calculating how many weeks' difference we have between
                // start date and evaluation period.
                Date_Time evalDate = FromDate;
                while (evalDate.Year > StartDate.Year)
                {
                    firstEvalWeek += m_Calendar.GetWeekOfYear(new DateTime(evalDate.Year - 1, 12, 31), System.Globalization.CalendarWeekRule.FirstFourDayWeek, Wkst);
                    evalDate       = evalDate.AddYears(-1);
                }

                // Determine the difference, in weeks, between the start date and the evaluation period.
                int startWeek       = m_Calendar.GetWeekOfYear(StartDate.Value, System.Globalization.CalendarWeekRule.FirstFourDayWeek, Wkst);
                int weeksDifference = firstEvalWeek - startWeek;

                // Determine how many weeks the evaluation period needs to change
                // in order to "align" to the start date week, given the specified interval.
                int offset = 0;
                while (weeksDifference % Interval != 0)
                {
                    weeksDifference--;
                    offset++;
                }

                // Offset the week back to a "compatible" week for evaluation
                FromDate = FromDate.AddDays(-offset * 7);
            }

            // Create a temporary recurrence for populating
            // missing information using the 'StartDate'.
            Recur r = new Recur();

            r.CopyFrom(this);

            // If an INTERVAL was not specified, default to 1
            r.EnsureInterval();

            // Fill in missing, necessary ByXXX values
            r.EnsureByXXXValues(StartDate);

            // Get the occurrences
            foreach (Date_Time occurrence in r.GetOccurrences(FromDate.Copy(), ToDate, r.Count))
            {
                // NOTE:
                // Used to be DateTime.AddRange(r.GetOccurrences(FromDate.Copy(), ToDate, r.Count))
                // By doing it this way, fixes bug #19.
                if (!DateTimes.Contains(occurrence))
                {
                    DateTimes.Add(occurrence);
                }
            }

            // Limit the count of returned recurrences
            if (Count != int.MinValue &&
                DateTimes.Count > Count)
            {
                DateTimes.RemoveRange(Count, DateTimes.Count - Count);
            }

            // Process the UNTIL, and make sure the DateTimes
            // occur between FromDate and ToDate
            for (int i = DateTimes.Count - 1; i >= 0; i--)
            {
                Date_Time dt = (Date_Time)DateTimes[i];
                if (dt > ToDate ||
                    dt < FromDate)
                {
                    DateTimes.RemoveAt(i);
                }
            }

            // Assign missing values
            foreach (Date_Time dt in DateTimes)
            {
                dt.MergeWith(StartDate);
            }

            // Ensure that DateTimes have an assigned time if they occur less than dailyB
            foreach (Date_Time dt in DateTimes)
            {
                if (Frequency < FrequencyType.DAILY)
                {
                    dt.HasTime = true;
                }
            }

            return(DateTimes);
        }
예제 #14
0
        public override ResultInfoOrders GetOrders(RequestsCounterData requestsCounter)
        {
            var now = DateTime.Now;

            var diffDays = (int)now.Subtract(FromDate).TotalDays;

            WriteToLog("---------------------------------");
            WriteToLog("{0:g} - {1:g}", FromDate, ToDate);
            WriteToLog("Count Days: {0}", diffDays);
            if (diffDays <= MAX_RETURN_DAYS)
            {
                WriteToLog("all.");
                var orders = GetOrders(FromDate, ToDate, requestsCounter);
                WriteToLog("---------------------------------");
                return(orders);
            }

            int rem;
            var iter = Math.DivRem(diffDays, MAX_RETURN_DAYS, out rem);

            WriteToLog("Count Iterations: {0}", iter);
            ResultInfoOrders rez = null;

            for (int i = 0; i < iter; i++)
            {
                DateTime fromDate = i == 0 ? FromDate : FromDate.AddDays(i * MAX_RETURN_DAYS);

                DateTime toDate = FromDate.AddDays((i + 1) * MAX_RETURN_DAYS);

                WriteToLog("iter: {0,3}. {1:g} - {2:g}", i + 1, fromDate, toDate);
                var orders = GetOrders(fromDate, toDate, requestsCounter);

                if (rez == null)
                {
                    rez = new ResultInfoOrders(orders);
                }
                else
                {
                    rez.AddData(orders);
                }
            }

            if (rem > 0)
            {
                DateTime fromDate = FromDate.AddDays(iter * MAX_RETURN_DAYS);
                DateTime toDate   = ToDate;
                WriteToLog("remainder. {0:g} - {1:g}", fromDate, toDate);
                var orders = GetOrders(fromDate, toDate, requestsCounter);

                if (rez == null)
                {
                    rez = new ResultInfoOrders(orders);
                }
                else
                {
                    rez.AddData(orders);
                }
            }
            WriteToLog("---------------------------------");

            return(rez);
        }
예제 #15
0
        public List <List <string> > GetItems()
        {
            BeginSaldoD = 0;
            BeginValSd  = 0;
            Rowfoother  = new Dictionary <int, List <string> >();
            List <List <string> > items = new List <List <string> >();
            var rezi = Context.GetAllAnaliticSaldos(CurrenAcc.Id, CurrenAcc.FirmaId);
            List <QuantityModel> contosb  = null;
            List <QuantityModel> contos1b = null;

            if (!string.IsNullOrWhiteSpace(KindStock))
            {
                rezi = rezi.Where(e => e.CodeMaterial == KindStock).ToList();
            }
            if (fromDate.Month > 1)
            {
                contosb  = new List <QuantityModel>(Context.GetAllContoQuantity(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, new DateTime(FromDate.Year, 1, 1), FromDate.AddDays(-1), 1, KindStock));
                contos1b = new List <QuantityModel>(Context.GetAllContoQuantity(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, new DateTime(FromDate.Year, 1, 1), FromDate.AddDays(-1), 2, KindStock));

                if (contosb != null)
                {
                    var query = (from t in contosb
                                 group t by new { t.StockCode }
                                 into grp
                                 select new QuantityModel
                    {
                        StockCode = grp.Key.StockCode,
                        Stock = grp.First().Stock,
                        Oborot = grp.Sum(t => t.Oborot),
                        Quantity = grp.Sum(t => t.Quantity)
                    }).ToList();
                    foreach (var item in query)
                    {
                        if (rezi.FirstOrDefault(e => e.CodeMaterial == item.StockCode) != null)
                        {
                            rezi.FirstOrDefault(e => e.CodeMaterial == item.StockCode).BeginSaldoDebit    += item.Oborot;
                            rezi.FirstOrDefault(e => e.CodeMaterial == item.StockCode).BeginSaldoDebitKol += item.Quantity;
                        }
                        else
                        {
                            rezi.Add(new SaldoFactura {
                                CodeMaterial = item.StockCode, NameMaterial = item.Stock, BeginSaldoDebit = item.Oborot, BeginSaldoDebitKol = item.Quantity
                            });
                        }
                    }
                }
                if (contos1b != null)
                {
                    var query = (from t in contos1b
                                 group t by new { t.StockCode }
                                 into grp
                                 select new QuantityModel
                    {
                        StockCode = grp.Key.StockCode,
                        Stock = grp.First().Stock,
                        Oborot = grp.Sum(t => t.Oborot),
                        Quantity = grp.Sum(t => t.Quantity)
                    }).ToList();
                    foreach (var item in query)
                    {
                        if (rezi.FirstOrDefault(e => e.CodeMaterial == item.StockCode) != null)
                        {
                            rezi.FirstOrDefault(e => e.CodeMaterial == item.StockCode).BeginSaldoCredit    += item.Oborot;
                            rezi.FirstOrDefault(e => e.CodeMaterial == item.StockCode).BeginSaldoCreditKol += item.Quantity;
                        }
                        else
                        {
                            rezi.Add(new SaldoFactura {
                                CodeMaterial = item.StockCode, NameMaterial = item.Stock, BeginSaldoCredit = item.Oborot, BeginSaldoCreditKol = item.Quantity
                            });
                        }
                    }
                }
            }
            List <QuantityModel> contos  = new List <QuantityModel>(Context.GetAllContoQuantity(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, FromDate, ToDate, 1, KindStock));
            List <QuantityModel> contos1 = new List <QuantityModel>(Context.GetAllContoQuantity(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, FromDate, ToDate, 2, KindStock));
            List <QuantityModel> contos3 = new List <QuantityModel>(Context.GetAllContoQuantity(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, FromDate, ToDate, 1, KindStock));
            List <QuantityModel> contos4 = new List <QuantityModel>(Context.GetAllContoQuantity(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, CurrenAcc.Id, FromDate, ToDate, 2, KindStock));

            decimal sumad = 0, sumac = 0;
            decimal nsd = 0, nskold = 0;
            decimal nsc = 0, nskolc = 0;
            decimal ksd = 0, kskold = 0;
            decimal ksc = 0, kskolc = 0;
            decimal sumamd = 0, sumamc = 0;
            decimal sumacolmd = 0, sumacolmc = 0;

            sumad = contos.Sum(e => e.Oborot);
            sumac = contos1.Sum(e => e.Oborot);
            decimal sumaquantityd = contos.Sum(e => e.Quantity);
            decimal sumaquantityc = contos1.Sum(e => e.Quantity);
            //decimal sumasinglepriced=contos1.Sum(e=>e.SinglePrice);
            //decimal sumasinglepricec = contos1.Sum(e => e.SinglePrice);
            string currec = "", oldrec = "";
            string lastcode = "", lastname = "";

            contos3.AddRange(contos4);
            var currentrow = 0;

            foreach (
                var co in
                contos3.OrderBy(e => e.StockCode))
            {
                if (oldrec == "")
                {
                    oldrec = co.StockCode;
                }
                currec = co.StockCode;
                if (oldrec != currec)
                {
                    var lsumad1    = contos.Where(e => e.StockCode == oldrec).Sum(e => e.Oborot);
                    var lsumac1    = contos1.Where(e => e.StockCode == oldrec).Sum(e => e.Oborot);
                    var lsumavald1 = contos.Where(e => e.StockCode == oldrec).Sum(e => e.Quantity);
                    var lsumavalc1 = contos1.Where(e => e.StockCode == oldrec).Sum(e => e.Quantity);
                    var saldo1     = rezi.FirstOrDefault(e => e.CodeMaterial == oldrec);
                    if (saldo1 != null)
                    {
                        rezi.Remove(saldo1);
                    }
                    var lnsd1  = saldo1 != null ? saldo1.BeginSaldoDebit : 0;
                    var lnsc1  = saldo1 != null ? saldo1.BeginSaldoCredit : 0;
                    var lnsdv1 = saldo1 != null ? saldo1.BeginSaldoDebitKol : 0;
                    var lnscv1 = saldo1 != null ? saldo1.BeginSaldoCreditKol : 0;
                    if (CurrenAcc.TypeAccount == 1)
                    {
                        lnsd1   = lnsd1 - lnsc1;
                        lnsdv1  = lnsdv1 - lnscv1;
                        lnsc1   = 0;
                        lnscv1  = 0;
                        nsd    += lnsd1;
                        nskold += lnsdv1;
                    }
                    else
                    {
                        lnsc1   = lnsc1 - lnsd1;
                        lnscv1  = lnscv1 - lnsdv1;
                        lnsd1   = 0;
                        lnsdv1  = 0;
                        nsc    += lnsc1;
                        nskolc += lnscv1;
                    }
                    var     lsbord1  = lnsd1 + lsumad1;
                    var     lsborc1  = lnsc1 + lsumac1;
                    var     lsbordv1 = lnsdv1 + lsumavald1;
                    var     lsborcv1 = lnscv1 + lsumavalc1;
                    decimal lksd1    = 0;
                    decimal lksc1    = 0;
                    decimal lksdv1   = 0;
                    decimal lkscv1   = 0;
                    if (CurrenAcc.TypeAccount == 1)
                    {
                        lksd1   = (lsumad1 + lnsd1) - (lsumac1 + lnsc1);
                        lksdv1  = (lsumavald1 + lnsdv1) - (lsumavalc1 + lnsc1);
                        ksd    += lksd1;
                        kskold += lksdv1;
                    }
                    else
                    {
                        lksc1   = (lsumac1 + lnsc1) - (lsumad1 + lnsd1);
                        lkscv1  = (lsumavalc1 + lnscv1) - (lsumavald1 + lnsdv1);
                        ksc    += lksc1;
                        kskolc += lkscv1;
                    }

                    var row2 = new List <string>();
                    row2.Add("----------------------------------------------------------------------------------");
                    row2.Add("|Сборно          |          л е в а              |           количество          |");
                    row2.Add("|                |    дебит      |    кредит     |    дебит      |    кредит     |");
                    row2.Add("----------------------------------------------------------------------------------");
                    row2.Add($"|Начални салда   |{lnsd1.ToString(Vf.LevFormatUI),15}|{lnsc1.ToString(Vf.LevFormatUI),15}|{lnsdv1.ToString(Vf.ValFormatUI),15}|{lnscv1.ToString(Vf.ValFormatUI),15}|");
                    row2.Add($"|Oбороти         |{lsumad1.ToString(Vf.LevFormatUI),15}|{lsumac1.ToString(Vf.LevFormatUI),15}|{lsumavald1.ToString(Vf.ValFormatUI),15}|{lsumavalc1.ToString(Vf.ValFormatUI),15}|");
                    row2.Add($"|Сборове         |{lsbord1.ToString(Vf.LevFormatUI),15}|{lsborc1.ToString(Vf.LevFormatUI),15}|{lsbordv1.ToString(Vf.ValFormatUI),15}|{lsborcv1.ToString(Vf.ValFormatUI),15}|");
                    row2.Add($"|Крайни салда    |{lksd1.ToString(Vf.LevFormatUI),15}|{lksc1.ToString(Vf.LevFormatUI),15}|{lksdv1.ToString(Vf.ValFormatUI),15}|{lkscv1.ToString(Vf.ValFormatUI),15}|");
                    row2.Add("----------------------------------------------------------------------------------");
                    Rowfoother.Add(currentrow - 1, row2);
                    oldrec = currec;
                    //var el1 = rezi.FirstOrDefault(e => e.CodeMaterial == oldrec);
                    //if (el1 != null)
                    //{
                    //    nsd = el1.BeginSaldoDebit - el1.BeginSaldoCredit;
                    //    BeginSaldoD += nsd;
                    //    nskold = el1.BeginSaldoDebitKol - el1.BeginSaldoCreditKol;
                    //    BeginValSd += nskold;
                    //    rezi.Remove(el1);
                    //}
                    //else
                    //{
                    //    nsd = 0;
                    //    nskold = 0;
                    //}
                    //var row = new List<string>();
                    //var sbor1 = nsd + sumamd;
                    //var sbork1 = nskold + sumacolmd;
                    //row.Add("----------------------------------------------------------------------------------");
                    //row.Add("|Сборно          |          л е в а              |           количества          |");
                    //row.Add("|                |    дебит      |    кредит     |    дебит      |    кредит     |");
                    //row.Add("----------------------------------------------------------------------------------");
                    //row.Add($"|Начални салда   |{nsd.ToString(Vf.LevFormatUI),15}|               |{nskold.ToString(Vf.KolFormatUI),15}|               |");
                    //row.Add($"|Oбороти         |{sumamd.ToString(Vf.LevFormatUI),15}|{sumamc.ToString(Vf.LevFormatUI),15}|{sumacolmd.ToString(Vf.KolFormatUI),15}|{sumacolmc.ToString(Vf.KolFormatUI),15}|");
                    //row.Add($"|Сборове         |{sbor1.ToString(Vf.LevFormatUI),15}|{sumamc.ToString(Vf.LevFormatUI),15}|{sbork1.ToString(Vf.KolFormatUI),15}|{sumacolmc.ToString(Vf.KolFormatUI),15}|");
                    //row.Add($"|Крайни салда    |{(sbor1 - sumamc).ToString(Vf.LevFormatUI),15}|               |{(sbork1 - sumacolmc).ToString(Vf.KolFormatUI),15}|               |");
                    ////row.Add($"|Средна цена     |{((sumamd + nsd) / (sumacolmd + nskold)).ToString(Vf.LevFormatUI),15}|               |               |               |");
                    //row.Add("----------------------------------------------------------------------------------");
                    //Rowfoother.Add(currentrow-1,row);
                    //sumamd = 0;
                    //sumacolmd = 0;
                    //sumamc = 0;
                    //sumacolmc = 0;
                    //oldrec = currec;
                }
                List <string> item2 = new List <string>();
                item2.Add(co.PorNom);
                item2.Add(co.DocNum);
                item2.Add(co.Data);
                item2.Add(co.Folder);
                item2.Add(co.User);
                item2.Add(string.Format(Vf.LevFormat, co.Oborot));
                var dac = Allacc.FirstOrDefault(e => e.Id == co.DebitAccount);
                if (dac != null)
                {
                    item2.Add(dac.Short);
                }
                dac = Allacc.FirstOrDefault(e => e.Id == co.CreditAccount);
                if (dac != null)
                {
                    item2.Add(dac.Short);
                }
                item2.Add(string.Format(Vf.ValFormat, co.Quantity));
                item2.Add(string.Format(Vf.KolFormat, co.SinglePrice));
                item2.Add(co.Reason);
                item2.Add(co.Note);
                item2.Add(co.StockCode); lastcode = co.StockCode;
                item2.Add(co.Stock); lastname     = co.Stock;
                item2.Add(co.User);
                item2.Add(co.Id);
                items.Add(item2);
                if (co.IsDebit)
                {
                    sumamd    += co.Oborot;
                    sumacolmd += co.Quantity;
                }
                else
                {
                    sumamc    += co.Oborot;
                    sumacolmc += co.Quantity;
                }
                currentrow++;
            }

            //var row1 = new List<string>();
            //var el = rezi.FirstOrDefault(e => e.CodeMaterial == currec);
            //if (el != null)
            //{
            //    nsd = el.BeginSaldoDebit-el.BeginSaldoCredit;
            //    BeginSaldoD += nsd;
            //    nskold = el.BeginSaldoDebitKol-el.BeginSaldoCreditKol;
            //    BeginValSd += nskold;
            //    rezi.Remove(el);
            //}
            //else
            //{
            //    nsd = 0;
            //    nskold = 0;
            //}
            //var sbor = nsd + sumamd;
            //var sbork = nskold + sumacolmd;
            //row1.Add("----------------------------------------------------------------------------------");
            //row1.Add("|Сборно          |          л е в а              |           количества          |");
            //row1.Add("|                |    дебит      |    кредит     |    дебит      |    кредит     |");
            //row1.Add("----------------------------------------------------------------------------------");
            //row1.Add($"|Начални салда   |{nsd.ToString(Vf.LevFormatUI),15}|               |{nskold.ToString(Vf.KolFormatUI),15}|               |");
            //row1.Add($"|Oбороти         |{sumamd.ToString(Vf.LevFormatUI),15}|{sumamc.ToString(Vf.LevFormatUI),15}|{sumacolmd.ToString(Vf.KolFormatUI),15}|{sumacolmc.ToString(Vf.KolFormatUI),15}|");
            //row1.Add($"|Сборове         |{sbor.ToString(Vf.LevFormatUI),15}|{sumamc.ToString(Vf.LevFormatUI),15}|{sbork.ToString(Vf.KolFormatUI),15}|{sumacolmc.ToString(Vf.KolFormatUI),15}|");
            //row1.Add($"|Крайни салда    |{(sbor - sumamc).ToString(Vf.LevFormatUI),15}|               |{(sbork - sumacolmc).ToString(Vf.KolFormatUI),15}|               |");
            ////row1.Add($"|Средна цена     |{((sumamd + nsd) / (sumacolmd + nskold)).ToString(Vf.LevFormatUI),15}|               |               |               |");
            //row1.Add("----------------------------------------------------------------------------------");
            //Rowfoother.Add(currentrow-1, row1);
            var lsumad    = contos.Where(e => e.StockCode == currec).Sum(e => e.Oborot);
            var lsumac    = contos1.Where(e => e.StockCode == currec).Sum(e => e.Oborot);
            var lsumavald = contos.Where(e => e.StockCode == currec).Sum(e => e.Quantity);
            var lsumavalc = contos1.Where(e => e.StockCode == currec).Sum(e => e.Quantity);

            var saldo = rezi.FirstOrDefault(e => e.CodeMaterial == currec);

            var lnsd  = saldo != null ? saldo.BeginSaldoDebit : 0;
            var lnsc  = saldo != null ? saldo.BeginSaldoCredit : 0;
            var lnsdv = saldo != null ? saldo.BeginSaldoDebitKol : 0;
            var lnscv = saldo != null ? saldo.BeginSaldoCreditKol : 0;

            if (saldo != null)
            {
                rezi.Remove(saldo);
            }
            if (CurrenAcc.TypeAccount == 1)
            {
                lnsd    = lnsd - lnsc;
                lnsdv   = lnsdv - lnscv;
                lnsc    = 0;
                lnscv   = 0;
                nsd    += lnsd;
                nskold += lnsdv;
            }
            else
            {
                lnsc    = lnsc - lnsd;
                lnscv   = lnscv - lnsdv;
                lnsd    = 0;
                lnsdv   = 0;
                nsc    += lnsc;
                nskolc += lnscv;
            }
            var     lsbord  = lnsd + lsumad;
            var     lsborc  = lnsc + lsumac;
            var     lsbordv = lnsdv + lsumavald;
            var     lsborcv = lnscv + lsumavalc;
            decimal lksd    = 0;
            decimal lksc    = 0;
            decimal lksdv   = 0;
            decimal lkscv   = 0;

            if (CurrenAcc.TypeAccount == 1)
            {
                lksd    = (lsumad + lnsd) - (lsumac + lnsc);
                lksdv   = (lsumavald + lnsdv) - (lsumavalc + lnsc);
                ksd    += lksd;
                kskold += lksdv;
            }
            else
            {
                lksc    = (lsumac + lnsc) - (lsumad + lnsd);
                lkscv   = (lsumavalc + lnscv) - (lsumavald + lnsdv);
                ksc    += lksc;
                kskolc += lkscv;
            }
            if (currentrow > 0)
            {
                var row1 = new List <string>();
                row1.Add("----------------------------------------------------------------------------------");
                row1.Add("|Сборно          |          л е в а              |           количество          |");
                row1.Add("|                |    дебит      |    кредит     |    дебит      |    кредит     |");
                row1.Add("----------------------------------------------------------------------------------");
                row1.Add($"|Начални салда   |{lnsd.ToString(Vf.LevFormatUI),15}|{lnsc.ToString(Vf.LevFormatUI),15}|{lnsdv.ToString(Vf.ValFormatUI),15}|{lnscv.ToString(Vf.ValFormatUI),15}|");
                row1.Add($"|Oбороти         |{lsumad.ToString(Vf.LevFormatUI),15}|{lsumac.ToString(Vf.LevFormatUI),15}|{lsumavald.ToString(Vf.ValFormatUI),15}|{lsumavalc.ToString(Vf.ValFormatUI),15}|");
                row1.Add($"|Сборове         |{lsbord.ToString(Vf.LevFormatUI),15}|{lsborc.ToString(Vf.LevFormatUI),15}|{lsbordv.ToString(Vf.ValFormatUI),15}|{lsborcv.ToString(Vf.ValFormatUI),15}|");
                row1.Add($"|Крайни салда    |{lksd.ToString(Vf.LevFormatUI),15}|{lksc.ToString(Vf.LevFormatUI),15}|{lksdv.ToString(Vf.ValFormatUI),15}|{lkscv.ToString(Vf.ValFormatUI),15}|");
                if (!string.IsNullOrWhiteSpace(KindStock))
                {
                    if (CurrenAcc.TypeAccount == 1)
                    {
                        row1.Add($"|Средна цена     |{(lksd / (lksdv != 0 ? lksdv : 1)).ToString(Vf.LevFormatUI),15}|               |               |               |");
                    }
                    else
                    {
                        row1.Add($"|Средна цена     |{(lksc / (lkscv != 0 ? lkscv : 1)).ToString(Vf.LevFormatUI),15}|               |               |               |");
                    }
                }
                row1.Add("----------------------------------------------------------------------------------");
                Rowfoother.Add(currentrow - 1, row1);
            }
            if (string.IsNullOrWhiteSpace(KindStock))
            {
                foreach (var item in rezi)
                {
                    List <string> item2 = new List <string>();
                    item2.Add("");
                    item2.Add("");
                    item2.Add("Само салдо");
                    item2.Add("");
                    item2.Add("");
                    item2.Add(string.Format(Vf.LevFormat, item.BeginSaldoDebit - item.BeginSaldoCredit));
                    if (CurrenAcc.TypeAccount == 1)
                    {
                        nsd    += item.BeginSaldoDebit - item.BeginSaldoCredit;
                        nskold += item.BeginSaldoDebitKol - item.BeginSaldoCreditKol;
                    }
                    else
                    {
                        nsc    += item.BeginSaldoCredit - item.BeginSaldoDebit;
                        nskolc += item.BeginSaldoCreditKol - item.BeginSaldoDebitKol;
                    }
                    item2.Add("");
                    item2.Add("");
                    item2.Add(string.Format(Vf.ValFormat, item.BeginSaldoDebitKol - item.BeginSaldoCreditKol));

                    item2.Add("");
                    item2.Add("");
                    item2.Add("");
                    item2.Add(item.CodeMaterial);
                    item2.Add(item.NameMaterial);
                    item2.Add("");
                    item2.Add("");
                    items.Add(item2);
                    sumamd    += item.BeginSaldoDebit - item.BeginSaldoCredit;
                    sumacolmd += item.BeginSaldoDebitKol - item.BeginSaldoCreditKol;
                    currentrow++;
                    var row1 = new List <string>();
                    row1.Add("----------------------------------------------------------------------------------");
                    row1.Add("|Сборно          |          л е в а              |           количества          |");
                    row1.Add("|                |    дебит      |    кредит     |    дебит      |    кредит     |");
                    row1.Add("----------------------------------------------------------------------------------");
                    row1.Add($"|Начални салда   |{(item.BeginSaldoDebit - item.BeginSaldoCredit).ToString(Vf.LevFormatUI),15}|               |{(item.BeginSaldoDebitKol-item.BeginSaldoCreditKol).ToString(Vf.KolFormatUI),15}|               |");
                    row1.Add($"|Oбороти         |{0.ToString(Vf.LevFormatUI),15}|{0.ToString(Vf.LevFormatUI),15}|{0.ToString(Vf.KolFormatUI),15}|{0.ToString(Vf.KolFormatUI),15}|");
                    row1.Add($"|Сборове         |{0.ToString(Vf.LevFormatUI),15}|{0.ToString(Vf.LevFormatUI),15}|{0.ToString(Vf.KolFormatUI),15}|{0.ToString(Vf.KolFormatUI),15}|");
                    row1.Add($"|Крайни салда    |{(item.BeginSaldoDebit - item.BeginSaldoCredit).ToString(Vf.LevFormatUI),15}|               |{(item.BeginSaldoDebitKol - item.BeginSaldoCreditKol).ToString(Vf.KolFormatUI),15}|               |");
                    //row1.Add($"|Средна цена     |{(item.BeginSaldoDebit / (item.BeginSaldoDebitKol != 0 ? item.BeginSaldoDebitKol : 1)).ToString(Vf.LevFormatUI),15}|               |               |               |");
                    row1.Add("----------------------------------------------------------------------------------");
                    Rowfoother.Add(currentrow - 1, row1);
                }
            }
            else
            {
                var item = rezi.FirstOrDefault(e => e.CodeMaterial == KindStock);
                if (item != null)
                {
                    List <string> item2 = new List <string>();
                    item2.Add("Само салдо");
                    item2.Add("");
                    item2.Add("");
                    item2.Add("");
                    item2.Add("");
                    item2.Add(string.Format(Vf.LevFormat, item.BeginSaldoDebit - item.BeginSaldoCredit));
                    BeginSaldoD += item.BeginSaldoDebit - item.BeginSaldoCredit;
                    item2.Add("");
                    item2.Add("");
                    item2.Add(string.Format(Vf.ValFormat, item.BeginSaldoDebitKol - item.BeginSaldoCreditKol));
                    BeginValSd += item.BeginSaldoDebitKol - item.BeginSaldoCreditKol;
                    item2.Add("");
                    item2.Add("");
                    item2.Add("");
                    item2.Add(item.CodeMaterial);
                    item2.Add(item.NameMaterial);
                    item2.Add("");
                    item2.Add("");
                    items.Add(item2);
                    sumamd    += item.BeginSaldoDebit;
                    sumacolmd += item.BeginSaldoDebitKol;
                    currentrow++;
                    var row1 = new List <string>();
                    row1.Add("----------------------------------------------------------------------------------");
                    row1.Add("|Сборно          |          л е в а              |           количества          |");
                    row1.Add("|                |    дебит      |    кредит     |    дебит      |    кредит     |");
                    row1.Add("----------------------------------------------------------------------------------");
                    row1.Add($"|Начални салда   |{(item.BeginSaldoDebit-item.BeginSaldoCredit).ToString(Vf.LevFormatUI),15}|               |{(item.BeginSaldoDebitKol-item.BeginSaldoCreditKol).ToString(Vf.KolFormatUI),15}|               |");
                    row1.Add($"|Oбороти         |{0.ToString(Vf.LevFormatUI),15}|{0.ToString(Vf.LevFormatUI),15}|{0.ToString(Vf.KolFormatUI),15}|{0.ToString(Vf.KolFormatUI),15}|");
                    row1.Add($"|Сборове         |{0.ToString(Vf.LevFormatUI),15}|{0.ToString(Vf.LevFormatUI),15}|{0.ToString(Vf.KolFormatUI),15}|{0.ToString(Vf.KolFormatUI),15}|");
                    row1.Add($"|Крайни салда    |{(item.BeginSaldoDebit-item.BeginSaldoCredit).ToString(Vf.LevFormatUI),15}|               |{(item.BeginSaldoDebitKol - item.BeginSaldoCreditKol).ToString(Vf.KolFormatUI),15}|               |");
                    row1.Add($"|Средна цена     |{(item.BeginSaldoDebit / (item.BeginSaldoDebitKol != 0 ? item.BeginSaldoDebitKol : 1)).ToString(Vf.LevFormatUI),15}|               |               |               |");
                    row1.Add("----------------------------------------------------------------------------------");
                    Rowfoother.Add(currentrow - 1, row1);
                }
            }


            OborotsDebit  = string.Format(Vf.LevFormat, sumad);
            OborotsCredit = string.Format(Vf.LevFormat, sumac);
            Sumavald      = string.Format(Vf.KolFormat, sumaquantityd);
            Sumavalc      = string.Format(Vf.KolFormat, sumaquantityc);
            //Sumavald = string.Format(Vf.ValFormat, sumavald);
            //Sumavalc = string.Format(Vf.ValFormat, sumavalc);
            //KursDifd=string.Format(Vf.LevFormat, sumavalddf);
            //KursDifc=string.Format(Vf.LevFormat, sumavalcdf);


            TotalD = CurrenAcc.TypeAccount == 1
                ? string.Format(Vf.LevFormat, sumad + nsd)
                : string.Format(Vf.LevFormat, sumad);
            TotalC = CurrenAcc.TypeAccount == 2
                ? string.Format(Vf.LevFormat, sumac + nsc)
                : string.Format(Vf.LevFormat, sumac);
            if (CurrenAcc.TypeAccount == 1)
            {
                BeginSaldoD   = nsd;
                BeginValSd    = nskold;
                BeginValSc    = 0;
                BeginSaldoK   = 0;
                KrainoSaldoD  = (sumad + nsd) - (sumac);
                TSumavald     = string.Format(Vf.KolFormat, sumaquantityd + nskold);
                TSumavalc     = string.Format(Vf.KolFormat, sumaquantityc + nskolc);
                KrainoSaldoDV = (sumaquantityd + nskold) - (sumaquantityc);
                KrainoSaldoKV = 0;
                //var test = (sumad + BeginSaldoD) / (sumaquantityd + BeginValSd);
                //Sad = string.Format(Vf.LevFormat,test );
                //Sak ="";
            }
            if (CurrenAcc.TypeAccount == 2)
            {
                BeginSaldoK   = nsc;
                BeginValSc    = nskolc;
                BeginSaldoD   = 0;
                BeginValSd    = 0;
                KrainoSaldoK  = (sumac + nsc) - (sumad);
                KrainoSaldoKV = (sumaquantityc + nskolc) - (sumaquantityd);
                TSumavald     = string.Format(Vf.KolFormat, sumaquantityd + nskold);
                TSumavalc     = string.Format(Vf.KolFormat, sumaquantityc + nskolc);
                KrainoSaldoDV = 0;
                //Sad = "";
                //Sak = string.Format(Vf.KursFormat, KrainoSaldoKV != 0 ? KrainoSaldoK / KrainoSaldoKV : 0);
            }
            return(items);
        }