private void SendEmail(DebtorTransOpenClient debtorTransOpen)
        {
            var             postType   = debtorTransOpen.Trans._PostType;
            DebtorEmailType emailType  = DebtorEmailType.InterestNote;
            bool            isInterest = false;

            if (postType != (byte)DCPostType.Collection && postType != (byte)DCPostType.CollectionLetter && postType != (byte)DCPostType.InterestFee && postType != (byte)DCPostType.PaymentCharge)
            {
                if (postType == (byte)DCPostType.Invoice || postType == (byte)DCPostType.Creditnote)
                {
                    AddDockItem(TabControls.Invoices, debtorTransOpen, string.Format("{0}: {1}", postType == (byte)DCPostType.Invoice ? Uniconta.ClientTools.Localization.lookup("Invoice") :
                                                                                     Uniconta.ClientTools.Localization.lookup("Creditnote"), debtorTransOpen.Invoice));
                }

                return;
            }

            if (postType == (byte)DCPostType.InterestFee)
            {
                isInterest = true;
            }
            if (postType == (byte)DCPostType.Collection)
            {
                emailType = DebtorEmailType.Collection;
            }
            else
            {
                CWCollectionLetter collectionLetterWin = new CWCollectionLetter();
                collectionLetterWin.Closed += delegate
                {
                    if (collectionLetterWin.DialogResult == true)
                    {
                        if (!Enum.TryParse(collectionLetterWin.Result, out emailType))
                        {
                            return;
                        }
                    }
                };
                collectionLetterWin.Show();
            }


            var cwSendInvoice = new CWSendInvoice();

#if !SILVERLIGHT
            cwSendInvoice.DialogTableId = 2000000031;
#endif
            cwSendInvoice.Closed += delegate
            {
                var selectedRow = new DebtorTransOpenClient[] { debtorTransOpen };
                var feelist     = new[] { debtorTransOpen.Amount };

                if (cwSendInvoice.DialogResult == true)
                {
                    DebtorPayments.ExecuteDebtorCollection(api, busyIndicator, selectedRow, feelist, null, false, emailType, cwSendInvoice.Emails,
                                                           cwSendInvoice.sendOnlyToThisEmail, isInterest);
                }
            };
            cwSendInvoice.Show();
        }
Exemple #2
0
        private void SendDeliveryNote(CreditorDeliveryNoteLocal credDeliverNoteClient)
        {
            CWSendInvoice cwsendInvoice = new CWSendInvoice();

#if !SILVERLIGHT
            cwsendInvoice.DialogTableId = 2000000066;
#endif
            cwsendInvoice.Closed += async delegate
            {
                busyIndicator.IsBusy = true;
                InvoiceAPI invApi = new InvoiceAPI(api);
                ErrorCodes result = await invApi.SendInvoice(credDeliverNoteClient, cwsendInvoice.Emails, cwsendInvoice.sendOnlyToThisEmail, CWSendInvoice.sendInBackgroundOnly);

                busyIndicator.IsBusy = false;
                if (result == ErrorCodes.Succes)
                {
                    UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("SendEmailMsgOBJ"), Uniconta.ClientTools.Localization.lookup("CreditorPackNote")), Uniconta.ClientTools.Localization.lookup("Message"));
                }
                else
                {
                    UtilDisplay.ShowErrorCode(result);
                }
            };
        }
Exemple #3
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;
            }
        }