예제 #1
0
        private void ValidateDeadline(DebtorTransDirectDebit rec)
        {
            if (err)
            {
                return;
            }

            DateTime deadline = new DateTime(rec._PaymentDate.Year, rec._PaymentDate.Month, rec._PaymentDate.Day - 1, DirectDebitPaymentHelper.DEADLINE_TIMEOFDAY, 0, 0);

            deadline = DirectDebitBankHolidays.AdjustBankDay(comp._CountryId, deadline, false);

            if (todayDateTime >= deadline)
            {
                //TODO:Kan erstattes af en linje når Enum for Status bliver oprettet
                switch (rec._PaymentStatus)
                {
                case PaymentStatusLevel.None:
                    rec._ErrorInfo = string.Format("'Sent payment' not possible (Deadline {0}", deadline.ToString("dd-MM-yyyy kl. HH:mm"));
                    break;

                case PaymentStatusLevel.Resend:
                    rec._ErrorInfo = string.Format("'Resend payment' not possible (Deadline {0}", deadline.ToString("dd-MM-yyyy kl. HH:mm"));
                    break;

                case PaymentStatusLevel.StopPayment:
                    rec._ErrorInfo = string.Format("'Stop payment' not possible (Deadline {0}", deadline.ToString("dd-MM-yyyy kl. HH:mm"));
                    break;
                }
            }
        }
예제 #2
0
        private void ValidateBankholiday(DebtorTransDirectDebit rec)
        {
            if (err)
            {
                return;
            }

            if (!DirectDebitBankHolidays.IsBankDay(comp._CountryId, rec.PaymentDate))
            {
                rec._ErrorInfo = String.Format("Payment date {0} is not a bank day", rec._PaymentDate.ToString("dd-MM-yyyy"));
                err            = true;
            }
        }
예제 #3
0
        public static void ChangeStatus(Company comp, DebtorTransDirectDebit rec, PaymentStatusLevel changeToStatus)
        {
            var statusInfoTxt = rec._StatusInfo;

            if (changeToStatus == PaymentStatusLevel.None)
            {
                if (rec._PaymentStatus != PaymentStatusLevel.Sent && rec._PaymentStatus != PaymentStatusLevel.Processed && rec._PaymentStatus != PaymentStatusLevel.PaymentReceived && rec._PaymentStatus != changeToStatus)
                {
                    statusInfoTxt      = string.Format("({0}) Status changed '{1}'->{2}\n{3}", DateTime.Now.ToString("dd.MM.yy HH:mm"), rec._PaymentStatus, changeToStatus, statusInfoTxt);
                    rec._PaymentStatus = changeToStatus;
                    rec._SendTime      = DateTime.MinValue;
                }
                else
                {
                    rec._ErrorInfo = string.Format("Change status from '{0}'->'{1}' not possible", rec._PaymentStatus, changeToStatus);
                }
            }
            else if (changeToStatus == PaymentStatusLevel.Resend)
            {
                if (rec._PaymentStatus != PaymentStatusLevel.Sent && rec._PaymentStatus != PaymentStatusLevel.Processed && rec._PaymentStatus != PaymentStatusLevel.PaymentReceived && rec._PaymentStatus != changeToStatus)
                {
                    statusInfoTxt      = string.Format("({0}) Status changed '{1}'->{2}\n{3}", DateTime.Now.ToString("dd.MM.yy HH:mm"), rec._PaymentStatus, changeToStatus, statusInfoTxt);
                    rec._PaymentStatus = changeToStatus;
                    rec._SendTime      = DateTime.MinValue;
                }
                else
                {
                    rec._ErrorInfo = string.Format("Change status from '{0}'->'{1}' not possible", rec._PaymentStatus, changeToStatus);
                }
            }
            else if (changeToStatus == PaymentStatusLevel.StopPayment)
            {
                if (rec._PaymentStatus == PaymentStatusLevel.Sent)
                {
                    var      today    = BasePage.GetSystemDefaultDate();
                    DateTime deadline = new DateTime(rec._PaymentDate.Year, rec._PaymentDate.Month, rec._PaymentDate.Day - 1, DirectDebitPaymentHelper.DEADLINE_TIMEOFDAY, 0, 0);
                    deadline = DirectDebitBankHolidays.AdjustBankDay(comp._CountryId, deadline, false);

                    if (today >= deadline)
                    {
                        rec._ErrorInfo = string.Format("'Stop Payment' not possible (Deadline {0}", deadline.ToString("dd-MM-yyyy kl. HH:mm"));
                        rec.NotifyErrorSet();
                    }
                    else
                    {
                        statusInfoTxt      = string.Format("({0}) Status changed '{1}'->{2}\n{3}", DateTime.Now.ToString("dd.MM.yy HH:mm"), rec._PaymentStatus, changeToStatus, statusInfoTxt);
                        rec._PaymentStatus = changeToStatus;
                        rec._SendTime      = DateTime.MinValue;
                    }
                }
                else
                {
                    rec._ErrorInfo = string.Format("Change status from '{0}'->'{1}' not possible", rec._PaymentStatus, changeToStatus);
                }
            }
            else if (changeToStatus == PaymentStatusLevel.OnHold)
            {
                if (rec._PaymentStatus != PaymentStatusLevel.Sent && rec._PaymentStatus != PaymentStatusLevel.Processed && rec._PaymentStatus != PaymentStatusLevel.PaymentReceived && rec._PaymentStatus != changeToStatus)
                {
                    statusInfoTxt      = string.Format("({0}) Status changed '{1}'->{2}\n{3}", DateTime.Now.ToString("dd.MM.yy HH:mm"), rec._PaymentStatus, changeToStatus, statusInfoTxt);
                    rec._PaymentStatus = changeToStatus;
                    rec._SendTime      = DateTime.MinValue;
                }
                else
                {
                    rec._ErrorInfo = string.Format("Change status from '{0}'->'{1}' not possible", rec._PaymentStatus, changeToStatus);
                }
            }

            while (statusInfoTxt != null && statusInfoTxt.Length > 1000)
            {
                statusInfoTxt = statusInfoTxt.Remove(statusInfoTxt.TrimEnd().LastIndexOf("\n"));
            }

            rec._StatusInfo = statusInfoTxt;
            rec.NotifyErrorSet();
        }
예제 #4
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();
        }
예제 #5
0
        private void ExportFile()
        {
            GetNextPaymentFileId();

            CWDirectDebit cwwin = new CWDirectDebit(api, Uniconta.ClientTools.Localization.lookup("Export"));

            cwwin.Closing += async delegate
            {
                if (cwwin.DialogResult == true)
                {
                    var debPaymentFormat = cwwin.PaymentFormat;

                    ExpandCollapseAllGroups();
                    List <DebtorTransDirectDebit> ListDebTransPaym = new List <DebtorTransDirectDebit>();
                    int index = 0;
                    foreach (var rec in (IEnumerable <DebtorTransDirectDebit>)dgDebtorTranOpenGrid.ItemsSource)
                    {
                        int rowHandle = dgDebtorTranOpenGrid.GetRowHandleByListIndex(index);
                        index++;
                        if (dgDebtorTranOpenGrid.IsRowVisible(rowHandle) && rec._PaymentFormat == debPaymentFormat._Format && (rec._PaymentStatus == PaymentStatusLevel.None || rec._PaymentStatus == PaymentStatusLevel.Resend || rec._PaymentStatus == PaymentStatusLevel.StopPayment))
                        {
                            ListDebTransPaym.Add(rec);
                        }
                        else
                        {
                            continue;
                        }
                    }

                    IEnumerable <DebtorTransDirectDebit> queryPaymentTrans = ListDebTransPaym.AsEnumerable();

                    if (queryPaymentTrans.Count() == 0)
                    {
                        UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("NoRecordSelected"), Uniconta.ClientTools.Localization.lookup("Warning"));
                        return;
                    }

                    if (ValidatePayments(queryPaymentTrans, doMergePaym, debPaymentFormat, false, false))
                    {
                        try
                        {
                            List <DebtorTransDirectDebit> paymentListMerged = null;
                            var dictPaym = new Dictionary <String, DebtorTransDirectDebit>();
                            DebtorTransDirectDebit mergePayment;

                            var  paymNumSeqRefId  = nextPaymentRefId;
                            bool stopPaymentTrans = false;
                            bool netsBS           = false;

                            if (doMergePaym)
                            {
                                queryPaymentTrans = queryPaymentTrans.OrderBy(x => x.MergeDataId).OrderBy(x => x.Invoice).ToList();
                            }

                            foreach (var rec in queryPaymentTrans.Where(s => s.ErrorInfo == Common.VALIDATE_OK))
                            {
                                stopPaymentTrans = rec._PaymentStatus == PaymentStatusLevel.StopPayment;
                                netsBS           = debPaymentFormat._ExportFormat == (byte)DebtorPaymFormatType.NetsBS;

                                if (doMergePaym || stopPaymentTrans)
                                {
                                    var keyValue = stopPaymentTrans ? rec.PaymentRefId.ToString() : rec.MergeDataId;

                                    if (dictPaym.TryGetValue(keyValue, out mergePayment))
                                    {
                                        mergePayment.MergedAmount += netsBS ? rec.Amount : rec.PaymentAmount;
                                        mergePayment.hasBeenMerged = true;

                                        if (rec.TransactionText != null)
                                        {
                                            mergePayment.TransactionText += mergePayment.TransactionText != null?string.Format("{0}{1}{2}{3}", Environment.NewLine, Environment.NewLine, Environment.NewLine, rec.TransactionText) : rec.TransactionText;
                                        }

                                        if (stopPaymentTrans)
                                        {
                                            rec.MergeDataId  = rec.PaymentRefId.ToString();
                                            rec.PaymentRefId = rec.PaymentRefId;
                                        }
                                        else
                                        {
                                            if (keyValue == Common.MERGEID_SINGLEPAYMENT)
                                            {
                                                paymNumSeqRefId++;
                                            }

                                            rec.PaymentRefId = paymNumSeqRefId;
                                        }
                                    }
                                    else
                                    {
                                        if (!stopPaymentTrans)
                                        {
                                            paymNumSeqRefId++;
                                            rec._PaymentRefId = paymNumSeqRefId;
                                        }

                                        mergePayment = new DebtorTransDirectDebit();
                                        StreamingManager.Copy(rec, mergePayment);
                                        mergePayment.MergeDataId     = keyValue;
                                        mergePayment._PaymentRefId   = rec._PaymentRefId;
                                        mergePayment.MergedAmount    = netsBS ? rec.Amount : rec.PaymentAmount;
                                        mergePayment.TransactionText = rec.TransactionText;

                                        mergePayment.ErrorInfo = rec.ErrorInfo;

                                        dictPaym.Add(keyValue, mergePayment);
                                    }
                                    paymentListMerged = dictPaym.Values.ToList();
                                }
                                else
                                {
                                    paymNumSeqRefId++;
                                    rec.MergedAmount = 0;
                                    rec.PaymentRefId = paymNumSeqRefId;
                                }
                            }

                            List <DebtorTransDirectDebit> paymentList = null;
                            if (doMergePaym)
                            {
                                paymentList = paymentListMerged.Where(s => s.MergeDataId != Uniconta.ClientTools.Localization.lookup("Excluded") && s.MergeDataId != Common.MERGEID_SINGLEPAYMENT && s._PaymentStatus != PaymentStatusLevel.StopPayment).ToList();
                                foreach (var rec in queryPaymentTrans.Where(s => (s.MergeDataId == Common.MERGEID_SINGLEPAYMENT && s._PaymentStatus != PaymentStatusLevel.StopPayment)))
                                {
                                    paymentList.Add(rec);
                                }
                            }
                            else
                            {
                                paymentList = queryPaymentTrans.Where(s => s.ErrorInfo == Common.VALIDATE_OK && s._PaymentStatus != PaymentStatusLevel.StopPayment).ToList();
                            }

                            if (paymentListMerged != null)
                            {
                                foreach (var rec in paymentListMerged.Where(s => (s._PaymentStatus == PaymentStatusLevel.StopPayment)))
                                {
                                    paymentList.Add(rec);
                                }
                            }

                            var paymentListTotal = queryPaymentTrans.Where(s => s.ErrorInfo == Common.VALIDATE_OK).ToList();

                            var err = await Common.CreatePaymentFile(api, paymentList, MandateCache, DebtorCache, nextPaymentFileId, debPaymentFormat, BankAccountCache);

                            if (err != ErrorCodes.Succes)
                            {
                                UtilDisplay.ShowErrorCode(err);
                            }
                            else
                            {
                                Common.InsertPaymentReference(paymentListTotal.Where(s => s.ErrorInfo == Common.VALIDATE_OK).ToList(), api, nextPaymentFileId);
                            }
                        }
                        catch (Exception ex)
                        {
                            UnicontaMessageBox.Show(ex.Message, Uniconta.ClientTools.Localization.lookup("Exception"));
                        }
                    }
                }
            };
            cwwin.Show();
        }