public async void LoadCloseProfitLosss()
        {
            IsBusy          = true;
            AccDocumentItem = new AccDocumentItem();
            var dateDocument = _appContextService.CurrentFinancialYear;

            Close = await _openingClosingsService.GetCloseAccAsync(dateDocument);

            EndFinancialYear = await _currencyExchangesService.GetEndFinancialYear(dateDocument);

            PersianCalendar persianCalendar = new PersianCalendar();

            var accDate = persianCalendar.GetYear(DateTime.Now);

            StartFinancialYear = await _currencyExchangesService.GetStartFinancialYear(dateDocument);

            if (Close == false)
            {
                IsEnable = true;

                if (dateDocument == accDate)
                {
                    AccHeaderDate = DateTime.Now;
                }
                else
                {
                    AccHeaderDate = EndFinancialYear;
                }


                if (SLs == null)
                {
                    _allSLs = await _sLsService.GetSLsActiveAsync();

                    SLs = new ObservableCollection <SL>(_allSLs);
                }



                AccDocumentItems = new ObservableCollection <AccDocumentItemGroupedDTO>(_closeProfitLossAccountsService.GetGroupedAccDocumentItems(dateDocument));
                IsBusy           = false;
            }
            else
            {
                IsEnable = false;
            }
            IsBusy = false;
            _appContextService.PropertyChanged += async(sender, eventArgs) =>
            {
                var appContextService = sender as IAppContextService;
                if (eventArgs.PropertyName == "CurrentFinancialYear")
                {
                    dateDocument = _appContextService.CurrentFinancialYear;
                }
                if (Close == false)
                {
                    IsEnable           = true;
                    IsBusy             = true;
                    StartFinancialYear = _currencyExchangesService.GetStartFinancialYear1(dateDocument);

                    EndFinancialYear = _currencyExchangesService.GetEndFinancialYear1(dateDocument);
                    AccDocumentItems = new ObservableCollection <AccDocumentItemGroupedDTO>(_closeProfitLossAccountsService.GetGroupedAccDocumentItems(_appContextService.CurrentFinancialYear));
                    IsBusy           = false;
                }
                else
                {
                    IsEnable = false;
                }
            };
            SelectedAccDocumentItems = new ObservableCollection <AccDocumentItemGroupedDTO>();
            AccDocumentItems1        = new ObservableCollection <AccDocumentItemGroupedDTO>();
        }
Ejemplo n.º 2
0
        private async void OnAddAccDocument()
        {
            AccDocumentHeader = new AccDocumentHeader();

            var getDocumentNumbering = await _accDocumentHeadersService.GetDocumentNumberingAsync();

            var dateDocument = _appContextService.CurrentFinancialYear;

            StartYear = await _currencyExchangesService.GetStartFinancialYear(dateDocument);

            EndYear = await _currencyExchangesService.GetEndFinancialYear(dateDocument);

            EndNumber = getDocumentNumbering.EndNumber;
            var lastAccDocumentHeaderCode = _accDocumentHeadersService.GetLastAccDocumentHeaderCode(_appContextService.CurrentFinancialYear);

            if (lastAccDocumentHeaderCode > EndNumber)
            {
                Error("شماره گذاری اسناد به پایان رسیده،لطفا شماره گذاری اسناد را بررسی نمایید");
            }
            else
            {
                if (DocumentDate == null)
                {
                    Error(".تاریخ سند خالی می باشد");
                }
                else if (DocumentDate != null)
                {
                    PersianCalendar persianCalendar = new PersianCalendar();

                    var accHeaderDate = persianCalendar.GetYear(DocumentDate.Date);

                    if (accHeaderDate != dateDocument)
                    {
                        Error("تاریخ سند را درست وارد نمایید");
                    }


                    else
                    {
                        var getHeader = _tLDocumentsService.GetAccDocumentHeaders(StartYear.Date, DocumentDate.Date);
                        if (getHeader == true)
                        {
                            Information?.Invoke("در بین اسناد وضعیت پیش نویس وجود دارد");
                        }
                        else
                        {
                            var startNumber = getDocumentNumbering.StartNumber;

                            if (lastAccDocumentHeaderCode == 0)
                            {
                                lastAccDocumentHeaderCode = startNumber;
                            }
                            else
                            {
                                lastAccDocumentHeaderCode++;
                            }

                            var accountDocumentId = getDocumentNumbering.AccountDocumentId;
                            var style             = getDocumentNumbering.StyleId;
                            var countingWayId     = getDocumentNumbering.CountingWayId;

                            //  var lastAccDocumentHeaderCode = _accDocumentHeadersService.GetLastAccDocumentHeaderCode(_appContextService.CurrentFinancialYear);
                            var lastDailyNumberCode = await _accDocumentHeadersService.GetLastDailyNumberCode();

                            if (lastAccDocumentHeaderCode == 0)
                            {
                                lastAccDocumentHeaderCode = startNumber;
                            }
                            else
                            {
                                lastAccDocumentHeaderCode++;
                            }
                            var stringLastAccDocumentHeaderCode = lastAccDocumentHeaderCode.ToString();
                            var stringlastDailyNumberCode       = lastDailyNumberCode.ToString();
                            var lastAccDocumentHeadersCode      = stringLastAccDocumentHeaderCode;
                            var lastDayAccDocumentHeadersCode   = stringLastAccDocumentHeaderCode;
                            if (lastAccDocumentHeaderCode <= EndNumber)
                            {
                                //  var accDocumentHeader = Mapper.Map<EditableAccDocumentHeader, AccDocumentHeader>(AccDocumentHeader);
                                AccDocumentHeader.DailyNumber          = int.Parse($"{stringlastDailyNumberCode}");
                                AccDocumentHeader.DocumentNumber       = int.Parse($"{lastAccDocumentHeadersCode}");
                                AccDocumentHeader.ManualDocumentNumber = int.Parse($"{lastAccDocumentHeadersCode}");
                                AccDocumentHeader.SystemFixNumber      = int.Parse($"{lastAccDocumentHeadersCode}");
                                AccDocumentHeader.SystemName           = Environment.MachineName;
                                AccDocumentHeader.Exporter             = _appContextService.CurrentUser.FriendlyName;
                                AccDocumentHeader.Status       = StatusEnum.Temporary;
                                AccDocumentHeader.DocumentDate = DocumentDate;
                                AccRow = 1;
                                string AccRowCode = AccRow.ToString();
                                if (TypeHeader == 4)
                                {
                                    AccDocumentItems = new ObservableCollection <AccDocumentItemOpenCloseDTO>(await _openingClosingsService.AddCloseAccAsync(StartYear.Date, EndYear.Date));

                                    AccDocumentHeader.HeaderDescription = "بابت سند اختتامیه";
                                    AccDocumentHeader.TypeDocumentId    = 4;
                                    await _accDocumentHeadersService.AddAccDocumentHeaderAsync(AccDocumentHeader);

                                    var accItems = new ObservableCollection <AccDocumentItemOpenCloseDTO>(await _openingClosingsService.AddCloseAccAsync(StartYear.Date, EndYear.Date));
                                    var accList  = AccDocumentItems.Select((xd, i) => new AccDocumentItem
                                    {
                                        AccDocumentHeaderId = AccDocumentHeader.AccDocumentHeaderId,
                                        SLId           = (xd.SLId),
                                        DL1Id          = (xd.DL1Id),
                                        DL2Id          = (xd.DL2Id),
                                        Description1   = "بابت سند اختتامیه",
                                        Description2   = "بابت سند اختتامیه",
                                        Credit         = (xd.SumDebit - xd.SumCredit) < 0 ? Math.Abs(xd.SumDebit - xd.SumCredit) : 0,
                                        Debit          = (xd.SumDebit - xd.SumCredit) > 0 ? Math.Abs(xd.SumDebit - xd.SumCredit) : 0,
                                        CurrencyId     = xd.CurrencyId,
                                        CurrencyAmount = xd.SumCurrencyAmount
                                    });
                                    _accDocumentItemsService.AddAccDocumentItemsAsync(accList);
                                }
                                else if (TypeHeader == 3)
                                {
                                    AccDocumentItems = new ObservableCollection <AccDocumentItemOpenCloseDTO>(await _openingClosingsService.AddOpenAccAsync(StartYear.Date, EndYear.Date));
                                    AccDocumentHeader.DocumentDate      = StartYear.AddYears(1);
                                    AccDocumentHeader.HeaderDescription = "بابت سند افتتاحیه";
                                    AccDocumentHeader.TypeDocumentId    = 3;

                                    await _accDocumentHeadersService.AddAccDocumentHeaderAsync(AccDocumentHeader);

                                    var accItems = new ObservableCollection <AccDocumentItemOpenCloseDTO>(await _openingClosingsService.AddOpenAccAsync(StartYear.Date, EndYear.Date));
                                    var accList  = AccDocumentItems.Select((xd, i) => new AccDocumentItem
                                    {
                                        AccDocumentHeaderId = AccDocumentHeader.AccDocumentHeaderId,
                                        SLId           = (xd.SLId),
                                        DL1Id          = (xd.DL1Id),
                                        DL2Id          = (xd.DL2Id),
                                        Description1   = "بابت سند افتتاحیه",
                                        Description2   = "بابت سند افتتاحیه",
                                        Credit         = (xd.SumDebit - xd.SumCredit) < 0 ? Math.Abs(xd.SumDebit - xd.SumCredit) : 0,
                                        Debit          = (xd.SumDebit - xd.SumCredit) > 0 ? Math.Abs(xd.SumDebit - xd.SumCredit) : 0,
                                        CurrencyId     = xd.CurrencyId,
                                        CurrencyAmount = xd.SumCurrencyAmount
                                    });
                                    _accDocumentItemsService.AddAccDocumentItemsAsync(accList);
                                }
                                // await _accDocumentHeadersService.AddAccDocumentHeaderAsync(AccDocumentHeader);


                                dateDocument = _appContextService.CurrentFinancialYear;

                                var getAcc = await _openingClosingsService.GetAccDocumentItemsAsync(dateDocument);

                                GetAcc  = getAcc.Count;
                                Opening = await _openingClosingsService.GetCloseAccAsync(dateDocument);

                                var newOpening = await _openingClosingsService.GetOpenAccAsync(dateDocument + 1);

                                Closing = await _openingClosingsService.GetCloseProfitLossAccountAsync(dateDocument);

                                if (GetAcc > 0 && Closing == true && Opening == false)
                                {
                                    CheckType = "اختتامیه";
                                    Enable    = true;
                                }

                                else if (GetAcc > 0 && Opening == true && newOpening == false)
                                {
                                    CheckType = "افتتاحیه";
                                    Enable    = true;
                                }

                                else if (GetAcc > 0 && Opening == true && newOpening == true)
                                {
                                    CheckType = "سند افتتاحیه و اختتامیه صادر شده است";
                                    Enable    = false;
                                }
                                else if (GetAcc > 0 && Closing == false)
                                {
                                    CheckType = "سندهای سود و زیانی بسته نشده است";
                                    Enable    = false;
                                }
                                else if (GetAcc == 0)
                                {
                                    CheckType = "هیچ سندی صادر نشده است.";
                                    Enable    = false;
                                }
                                Information("سند با موفقیت ثبت شد");
                            }
                        }
                    }
                }
            }
        }