Beispiel #1
0
        internal async void LoadPayments(IEnumerable <DebtorTransDirectDebit> lst)
        {
            if (lst == null)
            {
                return;
            }

            var today            = BasePage.GetSystemDefaultDate().Date;
            var company          = api.CompanyEntity;
            var invoiceLineWhere = string.Empty;

            PaymentFormatCache = await company.LoadCache(typeof(Uniconta.DataModel.DebtorPaymentFormat), api);

            foreach (var rec in lst)
            {
                var debtor = (Debtor)DebtorCache.Get(rec.Account);

                DebtorPaymentFormat paymFormatClient = null;

                if (rec.PaymentFormat == null && debtor._PaymentFormat != null)
                {
                    rec.PaymentFormat = debtor._PaymentFormat;
                }

                if (rec.PaymentFormat != null)
                {
                    paymFormatClient = (DebtorPaymentFormat)PaymentFormatCache.Get(rec.PaymentFormat);
                }

                if (rec.PaymentDate < today && rec._PaymentStatus == PaymentStatusLevel.None)
                {
                    var paymDate = rec._PaymentDate == DateTime.MinValue ? rec._DueDate : rec._PaymentDate;
                    rec.PaymentDate = today > paymDate ? today : paymDate;

                    if (paymFormatClient != null && paymFormatClient._PaymentAction != NoneBankDayAction.None)
                    {
                        rec.PaymentDate = Common.AdjustToNextBankDay(company._CountryId, rec._PaymentDate, paymFormatClient._PaymentAction == NoneBankDayAction.After ? true : false);
                    }
                }

                if (paymFormatClient != null && paymFormatClient._ExportFormat == (byte)DebtorPaymFormatType.NetsBS && (rec._PaymentStatus == PaymentStatusLevel.None || rec._PaymentStatus == PaymentStatusLevel.Resend || rec._PaymentStatus == PaymentStatusLevel.StopPayment))
                {
                    rec.TransactionText = await Uniconta.DirectDebitPayment.Common.GetInvoiceText(api, rec, PaymentFormatCache);
                }
            }
        }
Beispiel #2
0
        private void GenerateJournalLines()
        {
            DirectDebitToJournal cwwin = new DirectDebitToJournal(api);

            cwwin.Closed += async delegate
            {
                if (cwwin.DialogResult == true && !string.IsNullOrEmpty(cwwin.Journal))
                {
                    ExpandCollapseAllGroups();

                    busyIndicator.IsBusy = true;
                    Uniconta.API.GeneralLedger.PostingAPI posApi = new Uniconta.API.GeneralLedger.PostingAPI(api);
                    long LineNumber = await posApi.MaxLineNumber(cwwin.Journal);

                    NumberSerieAPI numberserieApi    = new NumberSerieAPI(posApi);
                    int            nextVoucherNumber = 0;

                    var DJclient       = (Uniconta.DataModel.GLDailyJournal)JournalCache.Get(cwwin.Journal);
                    var listLineClient = new List <Uniconta.DataModel.GLDailyJournalLine>();

                    if (!DJclient._GenerateVoucher && !DJclient._ManualAllocation)
                    {
                        nextVoucherNumber = (int)await numberserieApi.ViewNextNumber(DJclient._NumberSerie);
                    }

                    List <DebtorTransDirectDebit> paymentListTransfer = null;
                    var dictPaymTransfer = new Dictionary <int, DebtorTransDirectDebit>();
                    DebtorTransDirectDebit mergePaymentRefId;

                    var netsBS = false;
                    int index  = 0;
                    foreach (var rec in (IEnumerable <DebtorTransDirectDebit>)dgDebtorTranOpenGrid.ItemsSource)
                    {
                        int rowHandle = dgDebtorTranOpenGrid.GetRowHandleByListIndex(index);
                        index++;
                        if (!dgDebtorTranOpenGrid.IsRowVisible(rowHandle) || rec._PaymentStatus == PaymentStatusLevel.OnHold) //TODO: Pt. tillades alle med undtagelse af OnHold
                        {
                            continue;
                        }

                        if (rec.PaymentFormat != null)
                        {
                            var paymFormatClient = (DebtorPaymentFormat)PaymentFormatCache.Get(rec.PaymentFormat);
                            netsBS = rec.PaymentFormat == paymFormatClient._Format;
                        }

                        var paymRefId = rec._PaymentRefId != 0 ? rec._PaymentRefId : -rec.PrimaryKeyId;

                        if (dictPaymTransfer.TryGetValue(paymRefId, out mergePaymentRefId))
                        {
                            mergePaymentRefId.MergedAmount += netsBS ? rec.Amount : rec.PaymentAmount;

                            mergePaymentRefId.settleTypeRowId = true;
                            mergePaymentRefId.rowNumbers.Append(';').Append(rec.PrimaryKeyId);

                            mergePaymentRefId.hasBeenMerged = true;
                        }
                        else
                        {
                            mergePaymentRefId = new DebtorTransDirectDebit();
                            StreamingManager.Copy(rec, mergePaymentRefId);
                            mergePaymentRefId._PaymentRefId = paymRefId;
                            mergePaymentRefId.MergedAmount  = netsBS ? rec.Amount : rec.PaymentAmount;

                            mergePaymentRefId.rowNumbers = new StringBuilder();
                            mergePaymentRefId.rowNumbers.Append(rec.PrimaryKeyId);
                            mergePaymentRefId.settleTypeRowId = true;

                            dictPaymTransfer.Add(paymRefId, mergePaymentRefId);
                        }
                        paymentListTransfer = dictPaymTransfer.Values.ToList();
                    }

                    foreach (var cTOpenClient in paymentListTransfer)
                    {
                        var lineclient = new GLDailyJournalLineClient();
                        lineclient.SetMaster(DJclient);
                        lineclient._DCPostType    = DCPostType.Payment;
                        lineclient._LineNumber    = ++LineNumber;
                        lineclient._Date          = cTOpenClient._PaymentDate != DateTime.MinValue ? cTOpenClient._PaymentDate : cTOpenClient._DueDate;
                        lineclient._TransType     = cwwin.TransType;
                        lineclient._AccountType   = (byte)GLJournalAccountType.Debtor;
                        lineclient._Account       = cTOpenClient.Account;
                        lineclient._OffsetAccount = cwwin.BankAccount;
                        lineclient._Invoice       = cTOpenClient.hasBeenMerged ? 0 : cTOpenClient.Invoice;

                        if (cTOpenClient.settleTypeRowId)
                        {
                            lineclient._SettleValue = SettleValueType.RowId;
                            lineclient._Settlements = cTOpenClient.rowNumbers.ToString();
                        }
                        else
                        {
                            lineclient._Settlements = null;
                        }

                        lineclient._DocumentRef = cTOpenClient.DocumentRef;
                        lineclient.Amount       = netsBS ? -cTOpenClient.Amount : -cTOpenClient.PaymentAmount;

                        if (nextVoucherNumber != 0)
                        {
                            lineclient._Voucher = nextVoucherNumber;
                            nextVoucherNumber++;
                        }

                        listLineClient.Add(lineclient);
                    }
                    if (listLineClient.Count > 0)
                    {
                        if (nextVoucherNumber != 0)
                        {
                            numberserieApi.SetNumber(DJclient._NumberSerie, nextVoucherNumber - 1);
                        }

                        ErrorCodes errorCode = await api.Insert(listLineClient);

                        busyIndicator.IsBusy = false;
                        if (errorCode != ErrorCodes.Succes)
                        {
                            UtilDisplay.ShowErrorCode(errorCode);
                        }
                        else
                        {
                            var text = string.Concat(Uniconta.ClientTools.Localization.lookup("TransferedToJournal"), ": ", DJclient._Journal,
                                                     Environment.NewLine, string.Format(Uniconta.ClientTools.Localization.lookup("GoTo"), Uniconta.ClientTools.Localization.lookup("Journallines")), " ?");
                            var select = UnicontaMessageBox.Show(text, Uniconta.ClientTools.Localization.lookup("Information"), MessageBoxButton.OKCancel);
                            if (select == MessageBoxResult.OK)
                            {
                                AddDockItem(TabControls.GL_DailyJournalLine, DJclient, null, null, true);
                            }
                        }
                    }
                    else
                    {
                        busyIndicator.IsBusy = false;
                        UtilDisplay.ShowErrorCode(ErrorCodes.NoLinesToUpdate);
                    }
                }
            };
            cwwin.Show();
        }