Esempio n. 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);
                }
            }
        }
Esempio n. 2
0
        public bool MergePayment(Company company, IEnumerable <DebtorTransDirectDebit> lstDebtorTransDirectDebit, DebtorPaymentFormat debtorPaymFormat)
        {
            try
            {
                foreach (var rec in lstDebtorTransDirectDebit)
                {
                    var currencyLocal = rec.Currency ?? company._CurrencyId;
                    if (rec._OnHold || rec._Paid || rec._PaymentFormat != debtorPaymFormat._Format || rec._ErrorInfo != DirectDebitPaymentHelper.VALIDATE_OK || (currencyLocal != Currencies.DKK))
                    {
                        rec._MergeDataId = Uniconta.ClientTools.Localization.lookup("Excluded");
                        rec.NotifyMergeDataIdSet();
                        continue;
                    }

                    StringBuilder mergeDataId = new StringBuilder();

                    mergeDataId.Append(rec.Account).Append('-').Append(rec._PaymentDate.ToString("yyyyMMdd"));

                    rec._MergeDataId = mergeDataId.ToString();
                    rec.NotifyMergeDataIdSet();
                }

                var duplicates = lstDebtorTransDirectDebit.Where(x => x._MergeDataId != Uniconta.ClientTools.Localization.lookup("Excluded")).GroupBy(s => s._MergeDataId).Where(grp => grp.Count() == 1).SelectMany(x => x);  //TODO:Find et nyt navn i stedet for duplicates

                foreach (var rec in duplicates)
                {
                    rec._MergeDataId = "Not merged";
                }

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Uniconta.ClientTools.Localization.lookup("Warning"), System.Windows.MessageBoxButton.OK);
                return(false);
            }
        }
Esempio n. 3
0
        private bool ValidatePayments(IEnumerable <DebtorTransDirectDebit> queryPaymentTrans, bool paymentMerged, DebtorPaymentFormat debPaymFormat, bool validateOnly = false, bool skipPrevalidate = false)
        {
            var paymentHelper = Common.DirectPaymentHelperInstance(debPaymFormat);

            paymentHelper.DirectDebitId = debPaymFormat._CredDirectDebitId;

            if (skipPrevalidate == false)
            {
                var preValErrors = new List <DirectPaymentError>();
                paymentHelper.PreValidate(api.CompanyEntity, BankAccountCache, JournalCache, debPaymFormat, out preValErrors);

                if (preValErrors.Count() > 0)
                {
                    var preErrors = new List <string>();
                    foreach (DirectPaymentError error in preValErrors)
                    {
                        preErrors.Add(error.Message);
                    }

                    if (preErrors.Count() != 0)
                    {
                        CWErrorBox cwError = new CWErrorBox(preErrors.ToArray());
                        cwError.Show();
                        return(false);
                    }
                }
            }

            var valErrors = new List <DirectPaymentError>();

            paymentHelper.ValidatePayments(api.CompanyEntity, queryPaymentTrans, debPaymFormat, MandateCache, paymentMerged, out valErrors);

            foreach (var rec in queryPaymentTrans.Where(s => s._PaymentStatus != PaymentStatusLevel.FileSent))
            {
                rec.ErrorInfo = Common.VALIDATE_OK;
            }

            foreach (DirectPaymentError error in valErrors)
            {
                var rec = queryPaymentTrans.Where(s => s.PrimaryKeyId == error.RowId).First();
                if (rec.ErrorInfo == Common.VALIDATE_OK)
                {
                    rec.ErrorInfo = error.Message;
                }
                else
                {
                    rec.ErrorInfo += Environment.NewLine + error.Message;
                }
            }

            if (queryPaymentTrans.Where(s => s.ErrorInfo == Common.VALIDATE_OK).Count() == 0 && validateOnly == false)
            {
                if (doMergePaym == false)
                {
                    UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("NoRecordSelected"), Uniconta.ClientTools.Localization.lookup("Message"));
                }
                return(false);
            }

            if (validateOnly)
            {
                var countErr = queryPaymentTrans.Where(s => (s.ErrorInfo != Common.VALIDATE_OK) && (s.ErrorInfo != null)).Count();

                if (countErr == 0)
                {
                    UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("ValidateNoError"), Uniconta.ClientTools.Localization.lookup("Validation"), MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("ValidateFailInLines"), countErr), Uniconta.ClientTools.Localization.lookup("Validation"), MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }

            return(true);
        }
        private bool ValidateMandate(IEnumerable <DebtorMandateDirectDebit> queryDebMandate, DebtorPaymentFormat debPaymFormat, MandateStatus mandateStatus, bool validateOnly = false)
        {
            try
            {
                var mandateHelper = Common.MandateHelperInstance(debPaymFormat);
                mandateHelper.DirectDebitId = debPaymFormat._CredDirectDebitId;

                var preValErrors = new List <MandateError>();
                var result       = mandateHelper.PreValidateMandates(api.CompanyEntity, debPaymFormat, out preValErrors);

                if (result == DirectMandateResults.Error)
                {
                    var preErrors = new List <string>();
                    foreach (MandateError error in preValErrors)
                    {
                        preErrors.Add(error.Message);
                    }

                    if (preErrors.Count != 0)
                    {
                        CWErrorBox cwError = new CWErrorBox(preErrors.ToArray());
                        cwError.Show();
                        return(false);
                    }
                }

                var valErrors = new List <MandateError>();
                if (mandateStatus == Uniconta.DataModel.MandateStatus.Register)
                {
                    mandateHelper.ValidateRegister(api.CompanyEntity, queryDebMandate, DebtorCache, debPaymFormat, out valErrors);
                }
                else if (mandateStatus == Uniconta.DataModel.MandateStatus.Unregister)
                {
                    mandateHelper.ValidateUnregister(api.CompanyEntity, queryDebMandate, DebtorCache, debPaymFormat, out valErrors);
                }
                else if (mandateStatus == Uniconta.DataModel.MandateStatus.Registered)
                {
                    mandateHelper.ValidateActivate(api.CompanyEntity, queryDebMandate, DebtorCache, debPaymFormat, out valErrors);
                }
                else
                {
                    mandateHelper.ValidateChange(api.CompanyEntity, queryDebMandate, DebtorCache, debPaymFormat, out valErrors);
                }

                foreach (var rec in queryDebMandate)
                {
                    rec.ErrorInfo = Common.VALIDATE_OK;
                }

                foreach (MandateError error in valErrors)
                {
                    var recErr = queryDebMandate.First(s => s.RowId == error.RowId);

                    if (recErr.ErrorInfo == Common.VALIDATE_OK)
                    {
                        recErr.ErrorInfo = error.Message;
                    }
                    else
                    {
                        recErr.ErrorInfo += Environment.NewLine + error.Message;
                    }
                }

                if (queryDebMandate.Any(s => s.ErrorInfo == Common.VALIDATE_OK) == false && validateOnly == false)
                {
                    UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("NoRecordSelected"), Uniconta.ClientTools.Localization.lookup("Warning"));
                    return(false);
                }

                if (validateOnly)
                {
                    var countErr = queryDebMandate.Where(s => (s.ErrorInfo != Common.VALIDATE_OK) && (s.ErrorInfo != null)).Count();
                    var infoTxt  = countErr != 0 ? string.Format(Uniconta.ClientTools.Localization.lookup("ValidateFailInLines"), countErr) : Uniconta.ClientTools.Localization.lookup("ValidateNoError");
                    UnicontaMessageBox.Show(infoTxt, Uniconta.ClientTools.Localization.lookup("Warning"));
                }
            }
            catch (Exception ex)
            {
                UnicontaMessageBox.Show(ex);
            }

            return(true);
        }