示例#1
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();
        }
示例#2
0
        private void localMenu_OnItemClicked(string ActionType)
        {
            var selectedItem = dgDebtorTranOpenGrid.SelectedItem as DebtorTransOpenClient;

            switch (ActionType)
            {
            case "DeleteRow":
                dgDebtorTranOpenGrid.RemoveFocusedRowFromGrid();
                break;

            case "SaveGrid":
                saveGrid();
                break;

            case "ViewDownloadRow":
                if (selectedItem != null)
                {
                    DebtorTransactions.ShowVoucher(dgDebtorTranOpenGrid.syncEntity, api, busyIndicator);
                }
                break;

            case "GenerateJournalLines":
                if (dgDebtorTranOpenGrid.ItemsSource == null)
                {
                    return;
                }
                CWImportToLine cwLine = new CWImportToLine(api, GetSystemDefaultDate());
#if !SILVERLIGHT
                cwLine.DialogTableId = 2000000034;
#endif
                cwLine.Closed
                    += async delegate
                    {
                    if (cwLine.DialogResult == true && !string.IsNullOrEmpty(cwLine.Journal))
                    {
                        busyIndicator.IsBusy = true;
                        Uniconta.API.GeneralLedger.PostingAPI posApi = new Uniconta.API.GeneralLedger.PostingAPI(api);
                        var LineNumber = (int)(await posApi.MaxLineNumber(cwLine.Journal)) + 2;

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

                        SQLCache payments = api.GetCache(typeof(Uniconta.DataModel.PaymentTerm));
                        string   payment  = (from pay in (IEnumerable <Uniconta.DataModel.PaymentTerm>)payments.GetNotNullArray where pay._UseForCollection select pay._Payment).FirstOrDefault();

                        SQLCache journalCache   = api.GetCache(typeof(Uniconta.DataModel.GLDailyJournal));
                        var      DJclient       = (Uniconta.DataModel.GLDailyJournal)journalCache.Get(cwLine.Journal);
                        var      listLineClient = new List <Uniconta.DataModel.GLDailyJournalLine>();

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

                        var visibleRows = dgDebtorTranOpenGrid.GetVisibleRows() as IEnumerable <DebtorTransPayment>;
                        var rows        = visibleRows.Where(p => p._FeeAmount > 0.0d && p._OnHold == false);
                        if (cwLine.AggregateAmount)
                        {
                            string lastAcc     = null;
                            var    rowsGroupBy = rows.GroupBy(a => a.Account);
                            foreach (var group in rowsGroupBy)
                            {
                                string invoice;
                                double FeeAmount, Charge;
                                var    rec = group.FirstOrDefault();
                                if (group.Count() > 1)
                                {
                                    FeeAmount = group.Sum(p => p._FeeAmount);
                                    Charge    = group.Sum(p => p._PaymentCharge);
                                    invoice   = null;
                                }
                                else
                                {
                                    FeeAmount = rec._FeeAmount;
                                    Charge    = rec._PaymentCharge;
                                    invoice   = rec.InvoiceAN;
                                }
                                if (group.Key == lastAcc)
                                {
                                    continue;
                                }
                                lastAcc = group.Key;
                                CreateGLDailyJournalLine(listLineClient, lastAcc, FeeAmount, Charge, invoice, DJclient, LineNumber, cwLine.Date, cwLine.TransType, cwLine.BankAccount, rec.Currency, nextVoucherNumber, payment);
                                if (nextVoucherNumber != 0)
                                {
                                    nextVoucherNumber++;
                                }
                            }
                        }
                        else
                        {
                            DebtorTransPayment lastRec = null;
                            foreach (var row in rows)
                            {
                                if (!object.ReferenceEquals(row, lastRec))
                                {
                                    lastRec = row;
                                    CreateGLDailyJournalLine(listLineClient, row.Account, row._FeeAmount, row._PaymentCharge, row.InvoiceAN, DJclient, LineNumber, cwLine.Date, cwLine.TransType, cwLine.BankAccount, row.Currency, nextVoucherNumber, payment);
                                    if (nextVoucherNumber != 0)
                                    {
                                        nextVoucherNumber++;
                                    }
                                }
                            }
                        }

                        if (listLineClient.Count > 0)
                        {
                            ErrorCodes errorCode = await api.Insert(listLineClient);

                            busyIndicator.IsBusy = false;
                            if (errorCode != ErrorCodes.Succes)
                            {
                                UtilDisplay.ShowErrorCode(errorCode);
                            }
                            else
                            {
                                if (nextVoucherNumber != 0)
                                {
                                    numberserieApi.SetNumber(DJclient._NumberSerie, nextVoucherNumber - 1);
                                }

                                var text = string.Concat(Uniconta.ClientTools.Localization.lookup("GenerateJournalLines"), "; ", Uniconta.ClientTools.Localization.lookup("Completed"),
                                                         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);
                                }
                            }
                        }
                    }
                    busyIndicator.IsBusy = false;
                    };
                cwLine.Show();
                break;

            case "AddInterest":
                if (selectedItem != null)
                {
                    SetFee(true);
                }
                break;

            case "AddCollection":
                if (selectedItem != null)
                {
                    SetFee(false);
                }
                break;

            case "SendAllEmail":
                SendReport((IEnumerable <DebtorTransPayment>)dgDebtorTranOpenGrid.GetVisibleRows());
                break;

            case "SendMarkedEmail":
                var markedRows = dgDebtorTranOpenGrid.SelectedItems?.Cast <DebtorTransPayment>();
                if (markedRows != null)
                {
                    SendReport(markedRows);
                }
                break;

            case "SendCurrentEmail":
                if (dgDebtorTranOpenGrid.SelectedItem != null)
                {
                    var cwSendInvoice = new CWSendInvoice();
#if !SILVERLIGHT
                    cwSendInvoice.DialogTableId = 2000000031;
#endif
                    cwSendInvoice.Closed += delegate
                    {
                        var selectedRow = new DebtorTransPayment[] { (DebtorTransPayment)dgDebtorTranOpenGrid.SelectedItem };
                        SendReport(selectedRow, cwSendInvoice.Emails, cwSendInvoice.sendOnlyToThisEmail);
                    };
                    cwSendInvoice.Show();
                }
                break;

#if !SILVERLIGHT
            case "SendAsOutlook":
                if (dgDebtorTranOpenGrid.SelectedItem != null)
                {
                    OpenOutlook();
                }
                break;
#endif
            default:
                gridRibbon_BaseActions(ActionType);
                break;
            }
        }