Пример #1
0
        public void TestFakturering()
        {
            InvoiceAPI invoiceAPI = new InvoiceAPI(m_api);

            var taskDebtorOrder = m_api.Query <DebtorOrderClient>();

            taskDebtorOrder.Wait();
            var DebtorOrders = taskDebtorOrder.Result;

            foreach (var DebtorOrder in DebtorOrders)
            {
                List <DebtorOrderClient> Masters = new List <DebtorOrderClient>();
                Masters.Add(DebtorOrder);
                var taskDebtorOrderLines = m_api.Query <DebtorOrderLineClient>(Masters, null);
                taskDebtorOrderLines.Wait();
                var DebtorOrderLines = taskDebtorOrderLines.Result;
                var taskInvoice      = invoiceAPI.PostInvoice(DebtorOrder, DebtorOrderLines, DateTime.Now, 0, true, null, null);
                taskInvoice.Wait();
                InvoicePostingResult   resultInvoice = taskInvoice.Result;
                ErrorCodes             Err           = resultInvoice.Err;
                DCInvoice              Header        = resultInvoice.Header;
                IEnumerable <InvTrans> Lines         = resultInvoice.Lines;
                PostingResult          ledgerRes     = resultInvoice.ledgerRes;
                if (Err == ErrorCodes.Succes)
                {
                    var xxx = DebtorOrder.InvoiceInterval;
                    var yyy = DebtorOrder.Invoices;
                }
            }
        }
        async void GetSearchOpenInvoice(BankStatementLineGridClient line, GLJournalAccountType type)
        {
            InvoiceAPI InvApi     = new InvoiceAPI(api);
            string     strAccount = (string)await InvApi.SearchOpenInvoice(type, line._Invoice);

            if (strAccount != null)
            {
                line.Account = strAccount;
            }
        }
Пример #3
0
        private void PickingListReport(DebtorOrderClient dbOrder)
        {
            InvoiceAPI Invapi = new InvoiceAPI(api);
            var        debtor = dbOrder.Debtor;
            string     debtorName = string.Empty, accountName = string.Empty;
            bool       showSendByMail = false;

            if (debtor != null)
            {
                debtorName     = debtor._Name ?? dbOrder._DCAccount;
                accountName    = string.Format("{0} ({1})", dbOrder._DCAccount, dbOrder.Name);
                showSendByMail = !string.IsNullOrEmpty(debtor.InvoiceEmail) || debtor.EmailDocuments;
            }

#if !SILVERLIGHT
            var cwPickingList = new CWGeneratePickingList(accountName, true, true, debtorName, showSendByMail);
            cwPickingList.DialogTableId = 2000000049;
#else
            var cwPickingList = new CWGeneratePickingList();
#endif
            cwPickingList.Closed += async delegate
            {
                if (cwPickingList.DialogResult == true)
                {
                    var selectedDate = cwPickingList.SelectedDate;

#if !SILVERLIGHT
                    var printDoc = cwPickingList.PrintDocument;
#else
                    var printDoc = false;
#endif
                    var invoicePostingResult = new InvoicePostingPrintGenerator(api, this);
                    invoicePostingResult.SetUpInvoicePosting(dbOrder, null, CompanyLayoutType.PickingList, selectedDate, null, false, cwPickingList.ShowDocument, false, printDoc, cwPickingList.NumberOfPages,
                                                             cwPickingList.SendByEmail, cwPickingList.SendByOutlook, cwPickingList.sendOnlyToThisEmail, cwPickingList.EmailList, false, null, false);

                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("GeneratingPage");
                    busyIndicator.IsBusy      = true;
                    var result = await invoicePostingResult.Execute();

                    busyIndicator.IsBusy = false;

                    if (result)
                    {
                        Updatedata(dbOrder, CompanyLayoutType.PickingList);
                    }
                    else
                    {
                        Utility.ShowJournalError(invoicePostingResult.PostingResult.ledgerRes, dgDebtorOrdersGrid);
                    }
                }
            };
            cwPickingList.Show();
        }
        private void PrintOffer(DebtorOfferClient dbOrder)
        {
            InvoiceAPI Invapi         = new InvoiceAPI(api);
            var        debtor         = dbOrder.Debtor;
            bool       showSendByMail = true;
            string     debtorName;

            if (debtor != null)
            {
                debtorName     = debtor._Name ?? dbOrder._DCAccount;
                showSendByMail = !string.IsNullOrEmpty(debtor.InvoiceEmail);
            }
            else if (dbOrder._Prospect == 0)
            {
                UtilDisplay.ShowErrorCode(ErrorCodes.AccountIsMissing);
                return;
            }
            else
            {
                debtorName     = Uniconta.ClientTools.Localization.lookup("Prospect");
                showSendByMail = true;
            }

            CWGenerateInvoice GenrateOfferDialog = new CWGenerateInvoice(false, Uniconta.ClientTools.Localization.lookup("Offer"), askForEmail: true, showNoEmailMsg: !showSendByMail, debtorName: debtorName, isDebtorOrder: true);

#if !SILVERLIGHT
            GenrateOfferDialog.DialogTableId = 2000000006;
#endif
            GenrateOfferDialog.Closed += async delegate
            {
                if (GenrateOfferDialog.DialogResult == true)
                {
                    var showOrPrintOffer     = GenrateOfferDialog.InvoiceQuickPrint || GenrateOfferDialog.ShowInvoice;
                    var invoicePostingResult = new InvoicePostingPrintGenerator(api, this, dbOrder, null, GenrateOfferDialog.GenrateDate, 0, true, CompanyLayoutType.Offer, showOrPrintOffer, GenrateOfferDialog.InvoiceQuickPrint,
                                                                                GenrateOfferDialog.NumberOfPages, GenrateOfferDialog.SendByEmail, GenrateOfferDialog.Emails, GenrateOfferDialog.sendOnlyToThisEmail, false, GenrateOfferDialog.PostOnlyDelivered, null);

                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("GeneratingPage");
                    busyIndicator.IsBusy      = true;
                    var result = await invoicePostingResult.Execute();

                    busyIndicator.IsBusy = false;

                    if (!result)
                    {
                        Utility.ShowJournalError(invoicePostingResult.PostingResult.ledgerRes, dgDebtorOffers);
                    }
                }
            };
            GenrateOfferDialog.Show();
        }
Пример #5
0
        private void OrderConfirmation(DebtorOrderClient dbOrder, CompanyLayoutType doctype)
        {
            InvoiceAPI Invapi         = new InvoiceAPI(api);
            var        debtor         = dbOrder.Debtor;
            bool       showSendByMail = true;

            if (debtor != null)
            {
                showSendByMail = !string.IsNullOrEmpty(debtor.InvoiceEmail);
            }
            string            debtorName         = debtor?._Name ?? dbOrder._DCAccount;
            bool              showUpdateInv      = api.CompanyEntity.Storage || (doctype == CompanyLayoutType.Packnote && api.CompanyEntity.Packnote);
            CWGenerateInvoice GenrateOfferDialog = new CWGenerateInvoice(false, Uniconta.ClientTools.Localization.lookup(doctype.ToString()), isShowInvoiceVisible: true, askForEmail: true, showNoEmailMsg: !showSendByMail, debtorName: debtorName, isShowUpdateInv: showUpdateInv, isDebtorOrder: true);

#if !SILVERLIGHT
            if (doctype == CompanyLayoutType.OrderConfirmation)
            {
                GenrateOfferDialog.DialogTableId = 2000000009;
            }
            else if (doctype == CompanyLayoutType.Packnote)
            {
                GenrateOfferDialog.DialogTableId = 2000000018;
            }
#endif
            GenrateOfferDialog.SetInvPrintPreview(showPrintPreview);
            GenrateOfferDialog.Closed += async delegate
            {
                if (GenrateOfferDialog.DialogResult == true)
                {
                    showPrintPreview = GenrateOfferDialog.ShowInvoice || GenrateOfferDialog.InvoiceQuickPrint;
                    var invoicePostingResult = new InvoicePostingPrintGenerator(api, this, dbOrder, null, GenrateOfferDialog.GenrateDate, 0, !GenrateOfferDialog.UpdateInventory, doctype, showPrintPreview, GenrateOfferDialog.InvoiceQuickPrint,
                                                                                GenrateOfferDialog.NumberOfPages, GenrateOfferDialog.SendByEmail, GenrateOfferDialog.Emails, GenrateOfferDialog.sendOnlyToThisEmail, false, GenrateOfferDialog.PostOnlyDelivered, null);
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("GeneratingPage");
                    busyIndicator.IsBusy      = true;
                    var result = await invoicePostingResult.Execute();

                    busyIndicator.IsBusy = false;

                    if (result)
                    {
                        Updatedata(dbOrder, doctype);
                    }
                    else
                    {
                        Utility.ShowJournalError(invoicePostingResult.PostingResult.ledgerRes, dgDebtorOrdersGrid);
                    }
                }
            };
            GenrateOfferDialog.Show();
        }
Пример #6
0
        void SendInvoice(IEnumerable <CreditorInvoiceLocal> invoiceEmails)
        {
            int icount = invoiceEmails.Count();

            UnicontaClient.Pages.CWSendInvoice cwSendInvoice = new UnicontaClient.Pages.CWSendInvoice();
#if !SILVERLIGHT
            cwSendInvoice.DialogTableId = 2000000063;
#endif
            cwSendInvoice.Closed += async delegate
            {
                if (cwSendInvoice.DialogResult == true)
                {
                    busyIndicator.IsBusy      = true;
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("SendingWait");
                    InvoiceAPI    Invapi = new InvoiceAPI(api);
                    List <string> errors = new List <string>();

                    var sendInBackgroundOnly = CWSendInvoice.sendInBackgroundOnly;
                    foreach (var inv in invoiceEmails)
                    {
                        var errorCode = await Invapi.SendInvoice(inv, cwSendInvoice.Emails, cwSendInvoice.sendOnlyToThisEmail, sendInBackgroundOnly);

                        sendInBackgroundOnly = true;
                        if (errorCode != ErrorCodes.Succes)
                        {
                            var standardError = await api.session.GetErrors(errorCode);

                            var stformattedErr = UtilDisplay.GetFormattedErrorCode(errorCode, standardError);
                            var errorStr       = string.Format("{0}({1}): \n{2}", Uniconta.ClientTools.Localization.lookup("InvoiceNumber"), inv.InvoiceNum,
                                                               Uniconta.ClientTools.Localization.lookup(stformattedErr));
                            errors.Add(errorStr);
                        }
                    }

                    busyIndicator.IsBusy = false;
                    if (errors.Count == 0)
                    {
                        UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("SendEmailMsgOBJ"), icount == 1 ? Uniconta.ClientTools.Localization.lookup("Invoice") :
                                                              Uniconta.ClientTools.Localization.lookup("Invoices")), Uniconta.ClientTools.Localization.lookup("Message"));
                    }
                    else
                    {
                        CWErrorBox errorDialog = new CWErrorBox(errors.ToArray(), true);
                        errorDialog.Show();
                    }
                }
            };
            cwSendInvoice.Show();
        }
        async void MarkLineAsInvoiced()
        {
            var lst = mainList ?? dgProjectTransClientInvoiceGrid.ItemsSource as IEnumerable <ProjectTransClient>;

            if (lst != null && lst.Count() > 0)
            {
                InvoiceAPI Invapi = new InvoiceAPI(api);
                busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("BusyMessage");
                busyIndicator.IsBusy      = true;
                var result = await Invapi.MarkAsInvoiced(this.master as Uniconta.DataModel.Project, lst);

                busyIndicator.IsBusy = false;
                UtilDisplay.ShowErrorCode(result);
            }
        }
Пример #8
0
        private void GenerateRecordInvoice(DebtorOrderClient dbOrder)
        {
            InvoiceAPI Invapi         = new InvoiceAPI(api);
            var        debtor         = dbOrder.Debtor;
            bool       showSendByMail = true;

            if (debtor != null)
            {
                showSendByMail = (!string.IsNullOrEmpty(debtor.InvoiceEmail) || debtor.EmailDocuments);
            }
            else
            {
                api.LoadCache(typeof(Debtor), true);
            }

            string debtorName   = debtor?.Name ?? dbOrder._DCAccount;
            bool   invoiceInXML = debtor?._InvoiceInXML ?? false;

            UnicontaClient.Pages.CWGenerateInvoice GenrateInvoiceDialog = new UnicontaClient.Pages.CWGenerateInvoice(true, string.Empty, false, true, true, showNoEmailMsg: !showSendByMail, debtorName: debtorName, isDebtorOrder: true, isOrderOrQuickInv: true, InvoiceInXML: invoiceInXML);
#if !SILVERLIGHT
            GenrateInvoiceDialog.DialogTableId = 2000000013;
#endif
            GenrateInvoiceDialog.SetOIOUBLLabelText(api.CompanyEntity._OIOUBLSendOnServer);
            GenrateInvoiceDialog.Closed += async delegate
            {
                if (GenrateInvoiceDialog.DialogResult == true)
                {
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("SendingWait");
                    busyIndicator.IsBusy      = true;
                    var isSimulated          = GenrateInvoiceDialog.IsSimulation;
                    var invoicePostingResult = new InvoicePostingPrintGenerator(api, this);
                    invoicePostingResult.SetUpInvoicePosting(dbOrder, null, CompanyLayoutType.Invoice, GenrateInvoiceDialog.GenrateDate, null, isSimulated, GenrateInvoiceDialog.ShowInvoice, GenrateInvoiceDialog.PostOnlyDelivered,
                                                             GenrateInvoiceDialog.InvoiceQuickPrint, GenrateInvoiceDialog.NumberOfPages, GenrateInvoiceDialog.SendByEmail, !isSimulated && GenrateInvoiceDialog.SendByOutlook, GenrateInvoiceDialog.sendOnlyToThisEmail,
                                                             GenrateInvoiceDialog.Emails, GenrateInvoiceDialog.GenerateOIOUBLClicked, null, false);
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("GeneratingPage");
                    var result = await invoicePostingResult.Execute();

                    busyIndicator.IsBusy = true;
                    busyIndicator.IsBusy = false;

                    if (!result)
                    {
                        Utility.ShowJournalError(invoicePostingResult.PostingResult.ledgerRes, dgMultiInvGrid);
                    }
                }
            };
            GenrateInvoiceDialog.Show();
        }
Пример #9
0
        private void PickingListReport(DebtorOrderClient dbOrder)
        {
            InvoiceAPI Invapi     = new InvoiceAPI(api);
            var        debtor     = dbOrder.Debtor;
            string     debtorName = debtor?._Name ?? dbOrder._DCAccount;

            var cwPickingList = new CWGeneratePickingList();

#if !SILVERLIGHT
            cwPickingList.DialogTableId = 2000000049;
#endif
            cwPickingList.Closed += async delegate
            {
                if (cwPickingList.DialogResult == true)
                {
                    var selectedDate = cwPickingList.SelectedDate;

#if !SILVERLIGHT
                    var printDoc = cwPickingList.PrintDocument;
#else
                    var printDoc = false;
#endif
                    var invoicePostingResult = new InvoicePostingPrintGenerator(api, this, dbOrder, null, selectedDate, 0, false, CompanyLayoutType.PickingList, true, printDoc,
                                                                                cwPickingList.NumberOfPages, cwPickingList.EmailList);

                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("GeneratingPage");
                    busyIndicator.IsBusy      = true;
                    var result = await invoicePostingResult.Execute();

                    busyIndicator.IsBusy = false;

                    if (result)
                    {
                        Updatedata(dbOrder, CompanyLayoutType.PickingList);
                    }
                    else
                    {
                        Utility.ShowJournalError(invoicePostingResult.PostingResult.ledgerRes, dgDebtorOrdersGrid);
                    }
                }
            };
            cwPickingList.Show();
        }
        async void RegenerateOrderFromProjectTrans()
        {
            var transLst         = dgGenerateOrder.GetVisibleRows() as IEnumerable <ProjectTransClientLocal>;
            var excludedTransLst = transLst?.Where(x => x._remove);

            if (excludedTransLst == null || !excludedTransLst.Any())
            {
                UtilDisplay.ShowErrorCode(ErrorCodes.NoLinesFound);
                return;
            }
            busyIndicator.IsBusy = true;
            var invApi = new InvoiceAPI(api);
            var result = await invApi.RegenerateOrderFromProject(dgGenerateOrder.masterRecord as Uniconta.DataModel.DCOrder, excludedTransLst);

            busyIndicator.IsBusy = false;
            UtilDisplay.ShowErrorCode(result);
            if (result == ErrorCodes.Succes)
            {
                globalEvents.OnRefresh(NameOfControl, null);
                dockCtrl.CloseDockItem();
            }
        }
Пример #11
0
        private void PostCost(IEnumerable <Uniconta.DataModel.CreditorOrderCostLine> lst)
        {
            CWConfirmationBox dialog = new CWConfirmationBox(Uniconta.ClientTools.Localization.lookup("AreYouSureToContinue"), Uniconta.ClientTools.Localization.lookup("Confirmation"), false);

            dialog.Closing += async delegate
            {
                if (dialog.ConfirmationResult == CWConfirmationBox.ConfirmationResultEnum.Yes)
                {
                    busyIndicator.IsBusy = true;
                    InvoiceAPI invoiceApi = new InvoiceAPI(this.api);
                    var        errorCodes = await invoiceApi.InvoiceAddCost(master as Uniconta.DataModel.DCInvoice, lst);

                    busyIndicator.IsBusy = false;
                    UtilDisplay.ShowErrorCode(errorCodes);

                    if (errorCodes == ErrorCodes.Succes)
                    {
                        dgCreditorOrderCostLine.ItemsSource = null;
                        CloseDockItem();
                    }
                }
            };
            dialog.Show();
        }
Пример #12
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);
                }
            };
        }
Пример #13
0
        static public async void GenerateOIOXml(CrudAPI api, InvoicePostingResult res)
        {
            var Comp     = api.CompanyEntity;
            var InvCache = api.GetCache(typeof(Uniconta.DataModel.InvItem)) ?? await api.LoadCache(typeof(Uniconta.DataModel.InvItem));

            var VatCache = api.GetCache(typeof(Uniconta.DataModel.GLVat)) ?? await api.LoadCache(typeof(Uniconta.DataModel.GLVat));

            //SystemInfo.Visible = true;

            int            countErr   = 0;
            SaveFileDialog saveDialog = null;
            InvoiceAPI     Invapi     = new InvoiceAPI(api);

            var invClient = (DebtorInvoiceClient)res.Header;

            var Debcache = Comp.GetCache(typeof(Debtor)) ?? await api.LoadCache(typeof(Debtor));

            var debtor = (Debtor)Debcache.Get(invClient._DCAccount);

            var layoutGroupCache = api.GetCache(typeof(DebtorLayoutGroup)) ?? await api.LoadCache(typeof(DebtorLayoutGroup));

            var invoiceLines = (InvTransClient[])res.Lines;

            Contact contactPerson = null;

            if (invClient._ContactRef != 0)
            {
                var Contacts = api.GetCache(typeof(Uniconta.DataModel.Contact)) ?? await api.LoadCache(typeof(Uniconta.DataModel.Contact));

                foreach (var contact in (Uniconta.DataModel.Contact[])Contacts.GetRecords)
                {
                    if (contact.RowId == invClient._ContactRef)
                    {
                        contactPerson = contact;
                        break;
                    }
                }
            }

            DebtorOrders.SetDeliveryAdress(invClient, debtor, api);

            Debtor deliveryAccount;

            if (invClient._DeliveryAccount != null)
            {
                deliveryAccount = (Debtor)Debcache.Get(invClient._DeliveryAccount);
            }
            else
            {
                deliveryAccount = null;
            }

            WorkInstallation workInstallation = null;

            if (invClient._Installation != null)
            {
                var workInstallCache = api.GetCache(typeof(Uniconta.DataModel.WorkInstallation)) ?? await api.LoadCache(typeof(Uniconta.DataModel.WorkInstallation));

                workInstallation = (WorkInstallation)workInstallCache.Get(invClient._Installation);
            }

            CreationResult result;

            if (Comp._CountryId == CountryCode.Norway || Comp._CountryId == CountryCode.Netherlands)
            {
                result = EHF.GenerateEHFXML(Comp, debtor, deliveryAccount, invClient, invoiceLines, InvCache, VatCache, null, contactPerson);
            }
            else if (Comp._CountryId == CountryCode.Iceland)
            {
                var paymFormatCache = Comp.GetCache(typeof(DebtorPaymentFormatClientIceland)) ?? await api.LoadCache(typeof(DebtorPaymentFormatClientIceland));

                TableAddOnData[] attachments = await UBL.Iceland.Attachments.CollectInvoiceAttachments(invClient, api);

                result = TS136137.GenerateTS136137XML(Comp, debtor, deliveryAccount, invClient, invoiceLines, InvCache, VatCache, null, contactPerson, paymFormatCache, attachments);
            }
            else
            {
                var attachments = await FromXSDFile.OIOUBL.ExportImport.Attachments.CollectInvoiceAttachments(invClient, api);

                result = Uniconta.API.DebtorCreditor.OIOUBL.GenerateOioXML(Comp, debtor, deliveryAccount, invClient, invoiceLines, InvCache, VatCache, null, contactPerson, attachments, layoutGroupCache, workInstallation);
            }

            bool createXmlFile = true;

            var errorInfo = "";

            if (result.HasErrors)
            {
                countErr++;
                createXmlFile = false;
                foreach (FromXSDFile.OIOUBL.ExportImport.PrecheckError error in result.PrecheckErrors)
                {
                    errorInfo += error.ToString() + "\n";
                }
            }

            var  applFilePath  = string.Empty;
            bool hasUserFolder = false;

            if (result.Document != null && createXmlFile)
            {
                var filename = string.Format("{0}_{1}", Uniconta.ClientTools.Localization.lookup("Invoice"), invClient.InvoiceNumber);

                if (session.User._AppDocPath != string.Empty && Directory.Exists(session.User._AppDocPath))
                {
                    try
                    {
                        applFilePath = string.Format("{0}\\OIOUBL", session.User._AppDocPath);
                        Directory.CreateDirectory(applFilePath);

                        filename      = string.Format("{0}\\{1}.xml", applFilePath, filename);
                        hasUserFolder = true;
                    }
                    catch (Exception ex)
                    {
                        UnicontaMessageBox.Show(ex);
                    }
                }
                else
                {
                    saveDialog          = UtilDisplay.LoadSaveFileDialog;
                    saveDialog.FileName = filename;
                    saveDialog.Filter   = "XML-File | *.xml";
                    bool?dialogResult = saveDialog.ShowDialog();
                    if (dialogResult != true)
                    {
                        return;
                    }

                    filename = saveDialog.FileName;
                }

                result.Document.Save(filename);
                await Invapi.MarkSendInvoiceOIO(invClient);

                if (hasUserFolder)
                {
                    UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("SaveFileMsgOBJ"), 1, Uniconta.ClientTools.Localization.lookup("Invoice"), applFilePath)
                                            , Uniconta.ClientTools.Localization.lookup("Information"));
                }
            }

            if (countErr != 0 && !string.IsNullOrWhiteSpace(errorInfo))
            {
                UnicontaMessageBox.Show(errorInfo, Uniconta.ClientTools.Localization.lookup("Error"));
            }
        }
Пример #14
0
        /// <summary>
        /// Method to Update Properties for Print Report
        /// </summary>
        /// <returns></returns>
        async public Task <bool> InstantiateFields()
        {
            try
            {
                var       Comp = crudApi.CompanyEntity;
                var       debtorInvoiceLineUserType   = ReportUtil.GetUserType(typeof(DebtorInvoiceLines), Comp);
                var       debtorInvoiceClientUserType = ReportUtil.GetUserType(typeof(DebtorInvoiceClient), Comp);
                DCInvoice dcInv;

                if (!isRePrint)
                {
                    var invApi = new InvoiceAPI(crudApi);
                    var invoiceLIneInstance = Activator.CreateInstance(debtorInvoiceLineUserType) as DebtorInvoiceLines;
                    dcInv = debtorInvoice;
                    InvTransInvoiceLines = (DebtorInvoiceLines[])await invApi.GetInvoiceLines(dcInv, invoiceLIneInstance);

                    PreviousAddressClient = isMultipleInvoicePrint ? LayoutPrintReport.GetPreviousAddressClientForInvoice(previousAddressLookup, debtorInvoice) :
                                            await LayoutPrintReport.GetPreviousAddressClientForInvoice(dcInv, crudApi);
                }
                else
                {
                    dcInv = invoicePostingResult.Header;

                    if (invoicePostingResult?.Lines != null && invoicePostingResult.Lines.Count() > 0)
                    {
                        var linesCount = invoicePostingResult.Lines.Count();
                        var lines      = invoicePostingResult.Lines;
                        InvTransInvoiceLines = Array.CreateInstance(debtorInvoiceLineUserType, linesCount) as DebtorInvoiceLines[];
                        int i = 0;
                        foreach (var invtrans in invoicePostingResult.Lines)
                        {
                            DebtorInvoiceLines debtorInvoiceLines;
                            if (invtrans.GetType() != debtorInvoiceLineUserType)
                            {
                                debtorInvoiceLines = Activator.CreateInstance(debtorInvoiceLineUserType) as DebtorInvoiceLines;
                                StreamingManager.Copy(invtrans, debtorInvoiceLines);
                            }
                            else
                            {
                                debtorInvoiceLines = invtrans as DebtorInvoiceLines;
                            }
                            InvTransInvoiceLines[i++] = debtorInvoiceLines;
                        }
                    }
                }

                //For Getting User-Fields for DebtorInvoice
                DebtorInvoiceClient debtorInvoiceClientUser;
                if (dcInv.GetType() != debtorInvoiceClientUserType)
                {
                    debtorInvoiceClientUser = Activator.CreateInstance(debtorInvoiceClientUserType) as DebtorInvoiceClient;
                    StreamingManager.Copy(dcInv, debtorInvoiceClientUser);
                }
                else
                {
                    debtorInvoiceClientUser = dcInv as DebtorInvoiceClient;
                }
                DebtorInvoice = debtorInvoiceClientUser;

                //For Getting User fields for Debtor
                var debtorClietUserType = ReportUtil.GetUserType(typeof(DebtorClient), Comp);
                var debtorClientUser    = Activator.CreateInstance(debtorClietUserType) as DebtorClient;
                var dcCache             = Comp.GetCache(typeof(Uniconta.DataModel.Debtor)) ?? await crudApi.LoadCache(typeof(Uniconta.DataModel.Debtor));

                var debtor = dcCache.Get(DebtorInvoice._DCAccount);
                if (debtor != null)
                {
                    StreamingManager.Copy((UnicontaBaseEntity)debtor, debtorClientUser);
                }
                else if (DebtorInvoice._Prospect != 0)
                {
                    //Check for Prospect. Create a Debtor for Prospect
                    var prosCache = Comp.GetCache(typeof(Uniconta.DataModel.CrmProspect)) ?? await crudApi.LoadCache(typeof(Uniconta.DataModel.CrmProspect));

                    var prospect = prosCache?.Get(DebtorInvoice._Prospect) as CrmProspect;
                    if (prospect != null)
                    {
                        debtorClientUser.CopyFrom(prospect);
                    }
                }

                if (PreviousAddressClient != null) //Setting the Previous Address if Exist for current invoice
                {
                    debtorClientUser._Name     = PreviousAddressClient._Name;
                    debtorClientUser._Address1 = PreviousAddressClient._Address1;
                    debtorClientUser._Address2 = PreviousAddressClient._Address2;
                    debtorClientUser._Address3 = PreviousAddressClient._Address3;
                    debtorClientUser._City     = PreviousAddressClient._City;
                    debtorClientUser._ZipCode  = PreviousAddressClient._ZipCode;
                }

                //to Contact listing for the current debtor
                if (Comp.Contacts)
                {
                    var ContactsCache = Comp.GetCache(typeof(Uniconta.DataModel.Contact)) ?? await crudApi.LoadCache(typeof(Uniconta.DataModel.Contact)).ConfigureAwait(false);

                    var contactCacheFilter = new ContactCacheFilter(ContactsCache, debtorClientUser.__DCType(), debtorClientUser._Account);
                    if (contactCacheFilter.Any())
                    {
                        try
                        {
                            debtorClientUser.Contacts = contactCacheFilter.Cast <ContactClient>().ToArray();
                        }
                        catch { }
                    }
                }
                Debtor = debtorClientUser;

                if (dcInv._Installation != null && Comp.GetCache(typeof(Uniconta.DataModel.WorkInstallation)) == null)
                {
                    await Comp.LoadCache(typeof(Uniconta.DataModel.WorkInstallation), crudApi);
                }

                UnicontaClient.Pages.DebtorOrders.SetDeliveryAdress(debtorInvoiceClientUser, debtorClientUser, crudApi);
                debtorInvoiceClientUser.SetInvoiceAddress(debtorClientUser);

                /*In case debtor order is null, fill from DCInvoice*/
                if (DebtorOrder == null)
                {
                    var debtorOrderUserType = ReportUtil.GetUserType(typeof(DebtorOrderClient), Comp);
                    var debtorOrderUser     = Activator.CreateInstance(debtorOrderUserType) as DebtorOrderClient;
                    debtorOrderUser.CopyFrom(debtorInvoiceClientUser, debtorClientUser);
                    DebtorOrder = debtorOrderUser;
                }

                Company = Utility.GetCompanyClientUserInstance(Comp);

                var InvCache = Comp.GetCache(typeof(InvItem)) ?? await crudApi.LoadCache(typeof(InvItem));

                CompanyLogo = await Uniconta.ClientTools.Util.UtilDisplay.GetLogo(crudApi);

                Language lang = ReportGenUtil.GetLanguage(debtorClientUser, Comp);
                InvTransInvoiceLines = LayoutPrintReport.SetInvTransLines(DebtorInvoice, InvTransInvoiceLines, InvCache, crudApi, debtorInvoiceLineUserType, lang, false);

                //Setting ReportName and Version
                var invoiceNumber = DebtorInvoice._InvoiceNumber;
                var lineTotal     = DebtorInvoice._LineTotal;
                IsCreditNote = (lineTotal < -0.0001d);

                ReportName = layoutType != CompanyLayoutType.Invoice ? layoutType.ToString() : invoiceNumber == 0 ? IsCreditNote ? "ProformaCreditNote" : "ProformaInvoice"
                    : IsCreditNote ? "Creditnote" : "Invoice";

                MessageClient = isMultipleInvoicePrint ? LayoutPrintReport.GetDebtorMessageClient(debtorMessageLookup, lang, GetDebtorEmailType()) :
                                await Utility.GetDebtorMessageClient(crudApi, lang, GetDebtorEmailType());

                var _LayoutGroup = DebtorInvoice._LayoutGroup ?? Debtor._LayoutGroup;
                if (_LayoutGroup != null)
                {
                    var cache = crudApi.GetCache(typeof(DebtorLayoutGroup)) ?? await crudApi.LoadCache(typeof(DebtorLayoutGroup));

                    var layClient = (DebtorLayoutGroup)cache.Get(_LayoutGroup);
                    layClient?.SetCompanyBank(Company);
                }

                return(true);
            }
            catch (Exception ex)
            {
                crudApi?.ReportException(ex, "Error Occured in DebtorInvoicePrintReport");
                return(false);
            }
        }
Пример #15
0
        private void OrderConfirmation(CompanyLayoutType docType)
        {
#if SILVERLIGHT
            confirmOrder = new List <InvoicePostingResult>();
#else
            confirmOrder = new Dictionary <InvoicePostingResult, DebtorOrderClient>();
#endif
            UnicontaClient.Pages.CWGenerateInvoice GenrateInvoiceDialog = new UnicontaClient.Pages.CWGenerateInvoice(false, Uniconta.ClientTools.Localization.lookup(docType.ToString()),
                                                                                                                     isShowInvoiceVisible: true, askForEmail: true, showInputforInvNumber: false, showInvoice: true, isShowUpdateInv: true, isQuickPrintVisible: true, isDebtorOrder: true, isPageCountVisible: false);
#if !SILVERLIGHT
            GenrateInvoiceDialog.DialogTableId = 2000000012;
#endif
            GenrateInvoiceDialog.SetInvPrintPreview(printPreview);
            GenrateInvoiceDialog.Closed += async delegate
            {
                if (GenrateInvoiceDialog.DialogResult == true)
                {
                    printPreview = GenrateInvoiceDialog.ShowInvoice;
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("SendingWait");
                    busyIndicator.IsBusy      = true;
                    var           InvoiceDate    = GenrateInvoiceDialog.GenrateDate;
                    var           updateStatus   = GenrateInvoiceDialog.UpdateInventory;
                    InvoiceAPI    Invapi         = new InvoiceAPI(api);
                    int           cnt            = 0;
                    List <string> errorList      = new List <string>();
                    var           dgOrderVisible = dgMultiInvGrid.GetVisibleRows() as IEnumerable <DebtorOrderClient>;
                    foreach (var dbOrder in dgOrderVisible)
                    {
                        var result = await Invapi.PostInvoice(dbOrder, null, GenrateInvoiceDialog.GenrateDate, 0,
                                                              !updateStatus, new DebtorInvoiceClient(),
                                                              new DebtorInvoiceLines(), GenrateInvoiceDialog.SendByEmail, GenrateInvoiceDialog.ShowInvoice || GenrateInvoiceDialog.InvoiceQuickPrint, docType,
                                                              GenrateInvoiceDialog.Emails, GenrateInvoiceDialog.sendOnlyToThisEmail, null, null, GenrateInvoiceDialog.PostOnlyDelivered);

                        if (result != null && result.Err == 0 && (GenrateInvoiceDialog.ShowInvoice || GenrateInvoiceDialog.InvoiceQuickPrint))
                        {
                            DebtorOrders.Updatedata(dbOrder, docType);

                            var dc = dbOrder.Debtor;
                            if (dc == null)
                            {
                                await api.CompanyEntity.LoadCache(typeof(Debtor), api, true);

                                dc = dbOrder.Debtor;
                            }
                            DebtorOrders.SetDeliveryAdress(result.Header, dc, api);
#if SILVERLIGHT
                            confirmOrder.Add(result);
#else
                            confirmOrder.Add(result, dbOrder);
#endif
                            cnt++;
                        }
                        else
                        {
                            string error = string.Format("{0}:{1}", dbOrder._OrderNumber, Uniconta.ClientTools.Localization.lookup(result.Err.ToString()));
                            errorList.Add(error);
                        }
                    }
                    busyIndicator.IsBusy = false;
                    string updatedMsg = Uniconta.ClientTools.Localization.lookup("Succes");


                    if (!GenrateInvoiceDialog.IsSimulation)
                    {
                        updatedMsg = string.Format(Uniconta.ClientTools.Localization.lookup("RecordsUpdated"), cnt, Uniconta.ClientTools.Localization.lookup("DebtorOrders"));
                    }

                    int documentsPreviewPrint = confirmOrder.Count;
                    updatedMsg = updatedMsg + "\n" + string.Format(Uniconta.ClientTools.Localization.lookup("MulitDocPrintConfirmationMsg"), documentsPreviewPrint,
                                                                   string.Format("{0} {1}", Uniconta.ClientTools.Localization.lookup(docType.ToString()), Uniconta.ClientTools.Localization.lookup("Documents")));

                    if (errorList.Count == 0)
                    {
                        if ((GenrateInvoiceDialog.ShowInvoice || GenrateInvoiceDialog.InvoiceQuickPrint) && confirmOrder.Count > 0)
                        {
                            InitMultiplePreviewDocument(updatedMsg, docType, GenrateInvoiceDialog.InvoiceQuickPrint);
                        }
                    }
                    else
                    {
                        CWErrorBox errorDialog = new CWErrorBox(errorList.ToArray(), true);
                        errorDialog.Closed += delegate
                        {
                            if ((GenrateInvoiceDialog.ShowInvoice || GenrateInvoiceDialog.InvoiceQuickPrint) && confirmOrder.Count > 0)
                            {
                                InitMultiplePreviewDocument(updatedMsg, docType, GenrateInvoiceDialog.InvoiceQuickPrint);
                            }
                        };
                        errorDialog.Show();
                    }
                }
            };
            GenrateInvoiceDialog.Show();
        }
Пример #16
0
        private void GenerateInvoice()
        {
#if SILVERLIGHT
            invoicePosted = new List <InvoicePostingResult>();
#else
            invoicePosted = new Dictionary <InvoicePostingResult, DebtorOrderClient>();
#endif
            UnicontaClient.Pages.CWGenerateInvoice GenrateInvoiceDialog = new UnicontaClient.Pages.CWGenerateInvoice(true, string.Empty, false, true, true, isOrderOrQuickInv: true, isQuickPrintVisible: true, isPageCountVisible: false, isDebtorOrder: true);
#if !SILVERLIGHT
            GenrateInvoiceDialog.DialogTableId = 2000000011;
#endif
            GenrateInvoiceDialog.SetInvPrintPreview(printPreview);
            GenrateInvoiceDialog.Closed += async delegate
            {
                if (GenrateInvoiceDialog.DialogResult == true)
                {
                    printPreview = GenrateInvoiceDialog.ShowInvoice;
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("SendingWait");
                    busyIndicator.IsBusy      = true;
                    var           InvoiceDate     = GenrateInvoiceDialog.GenrateDate;
                    InvoiceAPI    Invapi          = new InvoiceAPI(api);
                    int           cnt             = 0;
                    List <string> errorList       = new List <string>();
                    var           dbVisibleOrders = dgMultiInvGrid.GetVisibleRows() as IEnumerable <DebtorOrderClient>;
                    foreach (var dbOrder in dbVisibleOrders)
                    {
                        if (dbOrder._SubscriptionEnded != DateTime.MinValue && dbOrder._SubscriptionEnded < InvoiceDate)
                        {
                            continue;
                        }

                        var result = await Invapi.PostInvoice(dbOrder, null, InvoiceDate,
                                                              0, GenrateInvoiceDialog.IsSimulation, new DebtorInvoiceClient(),
                                                              new DebtorInvoiceLines(), GenrateInvoiceDialog.SendByEmail, (GenrateInvoiceDialog.ShowInvoice || GenrateInvoiceDialog.InvoiceQuickPrint || GenrateInvoiceDialog.GenerateOIOUBLClicked), 0,
                                                              GenrateInvoiceDialog.Emails, GenrateInvoiceDialog.sendOnlyToThisEmail, null, null, GenrateInvoiceDialog.PostOnlyDelivered);

                        if (result != null && result.Err == 0)
                        {
#if SILVERLIGHT
                            invoicePosted.Add(result);
#else
                            invoicePosted.Add(result, dbOrder);
#endif
                            cnt++;

                            var dc = dbOrder.Debtor;
                            if (dc == null)
                            {
                                await api.CompanyEntity.LoadCache(typeof(Debtor), api, true);

                                dc = dbOrder.Debtor;
                            }

                            DebtorOrders.SetDeliveryAdress(result.Header, dc, api);
                        }
                        else
                        {
                            string error = string.Format("{0}:{1}", dbOrder._OrderNumber, Uniconta.ClientTools.Localization.lookup(result.Err.ToString()));
                            errorList.Add(error);
                        }
                    }

                    busyIndicator.IsBusy = false;
                    string updatedMsg = Uniconta.ClientTools.Localization.lookup("Succes");
                    if (!GenrateInvoiceDialog.IsSimulation)
                    {
                        updatedMsg = string.Format(Uniconta.ClientTools.Localization.lookup("RecordsUpdated"), cnt, Uniconta.ClientTools.Localization.lookup("DebtorOrders"));
                    }

#if !SILVERLIGHT
                    if (GenrateInvoiceDialog.GenerateOIOUBLClicked && !GenrateInvoiceDialog.IsSimulation)
                    {
                        GenerateOIOXmlForAll(errorList, !GenrateInvoiceDialog.SendByEmail);
                    }
#endif
                    int previewInvoiceCount = invoicePosted.Count;
                    updatedMsg = updatedMsg + "\n" + string.Format(Uniconta.ClientTools.Localization.lookup("MulitDocPrintConfirmationMsg"), previewInvoiceCount, Uniconta.ClientTools.Localization.lookup("Invoices"));

                    if (errorList.Count == 0)
                    {
                        if ((GenrateInvoiceDialog.ShowInvoice || GenrateInvoiceDialog.InvoiceQuickPrint) && previewInvoiceCount > 0)
                        {
                            InitMultiplePreviewDocument(updatedMsg, CompanyLayoutType.Invoice, GenrateInvoiceDialog.InvoiceQuickPrint);
                        }
                    }
                    else
                    {
                        CWErrorBox errorDialog = new CWErrorBox(errorList.ToArray(), true);
                        errorDialog.Closed += delegate
                        {
                            if ((GenrateInvoiceDialog.ShowInvoice || GenrateInvoiceDialog.InvoiceQuickPrint) && previewInvoiceCount > 0)
                            {
                                InitMultiplePreviewDocument(updatedMsg, CompanyLayoutType.Invoice, GenrateInvoiceDialog.InvoiceQuickPrint);
                            }
                        };
                        errorDialog.Show();
                    }
                }
            };
            GenrateInvoiceDialog.Show();
        }
Пример #17
0
        private void PickList()
        {
#if SILVERLIGHT
            packListPosted = new List <InvoicePostingResult>();
#else
            packListPosted = new Dictionary <InvoicePostingResult, DebtorOrderClient>();
#endif
            var cwPickingList = new CWGeneratePickingList(false, false);
#if !SILVERLIGHT
            cwPickingList.DialogTableId = 2000000024;
#endif
            cwPickingList.Closed += async delegate
            {
                if (cwPickingList.DialogResult == true)
                {
                    var selectedDate = cwPickingList.SelectedDate;
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("LoadingMsg");
                    busyIndicator.IsBusy      = true;
                    InvoiceAPI Invapi          = new InvoiceAPI(api);
                    int        cnt             = 0;
                    var        errorList       = new List <string>();
                    var        dbVisibleOrders = dgMultiInvGrid.GetVisibleRows() as IEnumerable <DebtorOrderClient>;
                    foreach (var dbOrder in dbVisibleOrders)
                    {
                        var result = await Invapi.PostInvoice(dbOrder, null, selectedDate, 0, false, new DebtorInvoiceClient(), new DebtorInvoiceLines(), false, cwPickingList.ShowDocument || cwPickingList.PrintDocument,
                                                              CompanyLayoutType.PickingList);

                        if (result.Err == ErrorCodes.Succes)
                        {
#if SILVERLIGHT
                            packListPosted.Add(result);
#else
                            packListPosted.Add(result, dbOrder);
#endif
                            cnt++;
                        }
                        else
                        {
                            string error = string.Format("{0}:{1}", dbOrder.OrderNumber, Uniconta.ClientTools.Localization.lookup(result.Err.ToString()));
                            errorList.Add(error);
                        }
                    }
                    busyIndicator.IsBusy = false;

                    int    picklistPreviewCount = packListPosted.Count;
                    string updatedMsg           = string.Format(Uniconta.ClientTools.Localization.lookup("MulitDocPrintConfirmationMsg"), picklistPreviewCount,
                                                                string.Format("{0} {1}", Uniconta.ClientTools.Localization.lookup(CompanyLayoutType.PickingList.ToString()), Uniconta.ClientTools.Localization.lookup("Documents")));

                    if (errorList.Count == 0)
                    {
                        InitMultiplePreviewDocument(updatedMsg, CompanyLayoutType.PickingList, cwPickingList.PrintDocument);
                    }
                    else
                    {
                        CWErrorBox errorDialog = new CWErrorBox(errorList.ToArray(), true);
                        errorDialog.Closed += delegate { InitMultiplePreviewDocument(updatedMsg, CompanyLayoutType.PickingList, cwPickingList.PrintDocument); };
                        errorDialog.Show();
                    }
                }
            };
            cwPickingList.Show();
        }
        async public Task <bool> InstantiateFields()
        {
            try
            {
                var crudApi = this.crudApi;
                var Comp    = crudApi.CompanyEntity;
                var creditorInvoiceLineUserType = ReportUtil.GetUserType(typeof(CreditorInvoiceLines), Comp);
                var creditorInvoiceUserType     = ReportUtil.GetUserType(typeof(CreditorInvoiceClient), Comp);
                if (!isRePrint)
                {
                    var invApi = new InvoiceAPI(crudApi);
                    var invoiceLIneInstance = Activator.CreateInstance(creditorInvoiceLineUserType) as CreditorInvoiceLines;
                    InvTransInvoiceLines = (CreditorInvoiceLines[])await invApi.GetInvoiceLines(CreditorInvoice, invoiceLIneInstance);
                }
                else
                {
                    //for Gettting user firlds for Creditor Invoice
                    var dcInvoice = (DCInvoiceClient)invoicePostingResult.Header;
                    CreditorInvoice = new CreditorInvoiceClient();
                    StreamingManager.Copy(dcInvoice, CreditorInvoice);

                    var linesCount = invoicePostingResult.Lines.Count();
                    if (linesCount > 0)
                    {
                        var lines = invoicePostingResult.Lines;
                        InvTransInvoiceLines = Array.CreateInstance(creditorInvoiceLineUserType, linesCount) as CreditorInvoiceLines[];
                        int i = 0;
                        foreach (var invtrans in invoicePostingResult.Lines)
                        {
                            CreditorInvoiceLines creditorInvoiceLines;
                            if (invtrans.GetType() != creditorInvoiceLineUserType)
                            {
                                creditorInvoiceLines = Activator.CreateInstance(creditorInvoiceLineUserType) as CreditorInvoiceLines;
                                StreamingManager.Copy(invtrans, creditorInvoiceLines);
                            }
                            else
                            {
                                creditorInvoiceLines = invtrans as CreditorInvoiceLines;
                            }
                            InvTransInvoiceLines[i++] = creditorInvoiceLines;
                        }
                    }
                }

                //For Getting User-Fields for CreditorInvoice
                CreditorInvoiceClient creditorInvoiceClientUser;
                if (CreditorInvoice.GetType() != creditorInvoiceUserType)
                {
                    creditorInvoiceClientUser = Activator.CreateInstance(creditorInvoiceUserType) as CreditorInvoiceClient;
                    StreamingManager.Copy(CreditorInvoice, creditorInvoiceClientUser);
                }
                else
                {
                    creditorInvoiceClientUser = CreditorInvoice as CreditorInvoiceClient;
                }
                CreditorInvoice = creditorInvoiceClientUser;

                //for Gettting user fields for Creditor
                var dcCahce = Comp.GetCache(typeof(Uniconta.DataModel.Creditor)) ?? await crudApi.LoadCache(typeof(Uniconta.DataModel.Creditor));

                var cred = dcCahce.Get(CreditorInvoice._DCAccount);

                var creditorUserType = ReportUtil.GetUserType(typeof(CreditorClient), Comp);
                if (creditorUserType != cred?.GetType())
                {
                    var creditorClientUser = Activator.CreateInstance(creditorUserType) as CreditorClient;
                    if (cred != null)
                    {
                        StreamingManager.Copy((UnicontaBaseEntity)cred, creditorClientUser);
                    }
                    Creditor = creditorClientUser;
                }
                else
                {
                    Creditor = cred as CreditorClient;
                }

                if (Comp.Contacts)
                {
                    var contactCache = Comp.GetCache(typeof(Contact)) ?? await crudApi.LoadCache(typeof(Contact));

                    var contactCacheFilter = new ContactCacheFilter(contactCache, Creditor.__DCType(), Creditor._Account);
                    if (contactCacheFilter.Any())
                    {
                        try
                        {
                            Creditor.Contacts = contactCacheFilter.Cast <ContactClient>().ToArray();
                        }
                        catch { }
                    }
                }
                UnicontaClient.Pages.DebtorOrders.SetDeliveryAdress(creditorInvoiceClientUser, Creditor, crudApi);

                /*In case debtor order is null, fill from DCInvoice*/
                if (CreditorOrder == null)
                {
                    var creditorOrderUserType = ReportUtil.GetUserType(typeof(CreditorOrderClient), Comp);
                    var creditorOrderUser     = Activator.CreateInstance(creditorOrderUserType) as CreditorOrderClient;
                    creditorOrderUser.CopyFrom(creditorInvoiceClientUser, Creditor);
                    CreditorOrder = creditorOrderUser;
                }

                Company = Utility.GetCompanyClientUserInstance(Comp);

                var InvCache = Comp.GetCache(typeof(InvItem)) ?? await crudApi.LoadCache(typeof(InvItem));

                CompanyLogo = await Uniconta.ClientTools.Util.UtilDisplay.GetLogo(crudApi);

                Language lang = ReportGenUtil.GetLanguage(Creditor, Comp);
                InvTransInvoiceLines = LayoutPrintReport.SetInvTransLines(CreditorInvoice, InvTransInvoiceLines, InvCache, crudApi, creditorInvoiceLineUserType, lang, false);

                var lineTotal = CreditorInvoice._LineTotal;
                IsCreditNote = CreditorInvoice._LineTotal < -0.0001d && layoutType == CompanyLayoutType.PurchaseInvoice;
                ReportName   = IsCreditNote ? "CreditNote" : layoutType.ToString();

                CreditorMessage = isMultiInvoice? LayoutPrintReport.GetDebtorMessageClient(debtorMessageLookup, lang, GetEmailTypeForCreditor())?._Text:
                                  await GetMessageClientText(lang);

                return(true);
            }
            catch (Exception ex)
            {
                crudApi.ReportException(ex, "Error Occured in CreditorPrintReport");
                return(false);
            }
        }
Пример #19
0
        private void GenerateInvoice(DebtorOrderClient dbOrder)
        {
            InvoiceAPI Invapi         = new InvoiceAPI(api);
            bool       showSendByMail = false;

            var debtor = ClientHelper.GetRef(dbOrder.CompanyId, typeof(Debtor), dbOrder._DCAccount) as Debtor;

            if (debtor != null)
            {
                var InvoiceAccount = dbOrder._InvoiceAccount ?? debtor._InvoiceAccount;
                if (InvoiceAccount != null)
                {
                    debtor = ClientHelper.GetRef(dbOrder.CompanyId, typeof(Debtor), InvoiceAccount) as Debtor;
                }
                if (debtor != null)
                {
                    if (debtor._PricesInclVat != dbOrder._PricesInclVat)
                    {
                        var confirmationMsgBox = UnicontaMessageBox.Show(string.Format("{0}.\n{1}", string.Format(Uniconta.ClientTools.Localization.lookup("DebtorAndOrderMix"), Uniconta.ClientTools.Localization.lookup("InclVat")),
                                                                                       Uniconta.ClientTools.Localization.lookup("ProceedConfirmation")), Uniconta.ClientTools.Localization.lookup("Confirmation"), MessageBoxButton.OKCancel);
                        if (confirmationMsgBox != MessageBoxResult.OK)
                        {
                            return;
                        }
                    }
                    if (!api.CompanyEntity.SameCurrency(dbOrder._Currency, debtor._Currency))
                    {
                        var confirmationMsgBox = UnicontaMessageBox.Show(string.Format("{0}.\n{1}", string.Format(Uniconta.ClientTools.Localization.lookup("CurrencyMismatch"), AppEnums.Currencies.ToString((int)debtor._Currency), dbOrder.Currency),
                                                                                       Uniconta.ClientTools.Localization.lookup("ProceedConfirmation")), Uniconta.ClientTools.Localization.lookup("Confirmation"), MessageBoxButton.OKCancel);
                        if (confirmationMsgBox != MessageBoxResult.OK)
                        {
                            return;
                        }
                    }
                    showSendByMail = (!string.IsNullOrEmpty(debtor._InvoiceEmail) || debtor._EmailDocuments);
                }
            }
            else
            {
                api.LoadCache(typeof(Debtor), true);
            }

            string            debtorName           = debtor?._Name ?? dbOrder._DCAccount;
            bool              invoiceInXML         = debtor?._InvoiceInXML ?? false;
            var               accountName          = string.Format("{0} ({1})", dbOrder._DCAccount, dbOrder.Name);
            CWGenerateInvoice GenrateInvoiceDialog = new CWGenerateInvoice(true, string.Empty, false, true, true, showNoEmailMsg: !showSendByMail, debtorName: debtorName, isOrderOrQuickInv: true, isDebtorOrder: true,
                                                                           InvoiceInXML: invoiceInXML, AccountName: accountName);

#if !SILVERLIGHT
            GenrateInvoiceDialog.DialogTableId = 2000000010;
#endif
            if (dbOrder._InvoiceDate != DateTime.MinValue)
            {
                GenrateInvoiceDialog.SetInvoiceDate(dbOrder._InvoiceDate);
            }
            var additionalOrdersList = Utility.GetAdditionalOrders(api, dbOrder);
            if (additionalOrdersList != null)
            {
                GenrateInvoiceDialog.SetAdditionalOrders(additionalOrdersList);
            }
            GenrateInvoiceDialog.SetOIOUBLLabelText(api.CompanyEntity._OIOUBLSendOnServer);

            GenrateInvoiceDialog.Closed += async delegate
            {
                if (GenrateInvoiceDialog.DialogResult == true)
                {
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("SendingWait");
                    busyIndicator.IsBusy      = true;
                    var isSimulated          = GenrateInvoiceDialog.IsSimulation;
                    var invoicePostingResult = new InvoicePostingPrintGenerator(api, this);
                    invoicePostingResult.SetUpInvoicePosting(dbOrder, null, CompanyLayoutType.Invoice, GenrateInvoiceDialog.GenrateDate, null, isSimulated, GenrateInvoiceDialog.ShowInvoice, GenrateInvoiceDialog.PostOnlyDelivered,
                                                             GenrateInvoiceDialog.InvoiceQuickPrint, GenrateInvoiceDialog.NumberOfPages, GenrateInvoiceDialog.SendByEmail, !isSimulated && GenrateInvoiceDialog.SendByOutlook, GenrateInvoiceDialog.sendOnlyToThisEmail,
                                                             GenrateInvoiceDialog.Emails, GenrateInvoiceDialog.GenerateOIOUBLClicked, null, false);
                    invoicePostingResult.SetAdditionalOrders(GenrateInvoiceDialog.AdditionalOrders?.Cast <DCOrder>().ToList());
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("GeneratingPage");
                    busyIndicator.IsBusy      = true;
                    var result = await invoicePostingResult.Execute();

                    busyIndicator.IsBusy = false;

                    if (result)
                    {
                        if (invoicePostingResult.PostingResult.OrderDeleted)
                        {
                            dgDebtorOrdersGrid.UpdateItemSource(3, dgDebtorOrdersGrid.SelectedItem as DebtorOrderClient);
                        }
                    }
                    else
                    {
                        Utility.ShowJournalError(invoicePostingResult.PostingResult.ledgerRes, dgDebtorOrdersGrid);
                    }
                }
            };
            GenrateInvoiceDialog.Show();
        }
        /// <summary>
        /// Method to Update Properties for Print Report
        /// </summary>
        /// <returns></returns>
        async public Task <bool> InstantiateFields()
        {
            try
            {
                var Comp = crudApi.CompanyEntity;
                var debtorInvoiceLineUserType   = ReportUtil.GetUserType(typeof(DebtorInvoiceLines), Comp);
                var debtorInvoiceClientUserType = ReportUtil.GetUserType(typeof(DebtorInvoiceClient), Comp);
                DCPreviousAddressClient previousAddressClient = null;
                DCInvoiceClient         dcInv;

                if (!isRePrint)
                {
                    var invApi = new InvoiceAPI(crudApi);
                    var invoiceLIneInstance = Activator.CreateInstance(debtorInvoiceLineUserType) as DebtorInvoiceLines;
                    dcInv = debtorInvoice;
                    InvTransInvoiceLines = (DebtorInvoiceLines[])await invApi.GetInvoiceLines(dcInv, invoiceLIneInstance);

                    previousAddressClient = await GetPreviousAddressForInvoice(dcInv);
                }
                else
                {
                    dcInv = (DCInvoiceClient)invoicePostingResult.Header;

                    var linesCount = invoicePostingResult.Lines.Count();
                    if (linesCount > 0)
                    {
                        var lines = invoicePostingResult.Lines;
                        InvTransInvoiceLines = Array.CreateInstance(debtorInvoiceLineUserType, linesCount) as DebtorInvoiceLines[];
                        int i = 0;
                        foreach (var invtrans in invoicePostingResult.Lines)
                        {
                            DebtorInvoiceLines debtorInvoiceLines;
                            if (invtrans.GetType() != debtorInvoiceLineUserType)
                            {
                                debtorInvoiceLines = Activator.CreateInstance(debtorInvoiceLineUserType) as DebtorInvoiceLines;
                                StreamingManager.Copy(invtrans, debtorInvoiceLines);
                            }
                            else
                            {
                                debtorInvoiceLines = invtrans as DebtorInvoiceLines;
                            }
                            InvTransInvoiceLines[i++] = debtorInvoiceLines;
                        }
                    }
                }

                //For Getting User-Fields for DebtorInvoice
                DebtorInvoiceClient debtorInvoiceClientUser;
                if (dcInv.GetType() != debtorInvoiceClientUserType)
                {
                    debtorInvoiceClientUser = Activator.CreateInstance(debtorInvoiceClientUserType) as DebtorInvoiceClient;
                    StreamingManager.Copy(dcInv, debtorInvoiceClientUser);
                }
                else
                {
                    debtorInvoiceClientUser = dcInv as DebtorInvoiceClient;
                }
                DebtorInvoice = debtorInvoiceClientUser;

                //For Getting User fields for Debtor
                var debtorClietUserType = ReportUtil.GetUserType(typeof(DebtorClient), Comp);
                var debtorClientUser    = Activator.CreateInstance(debtorClietUserType) as DebtorClient;
                var dcCache             = Comp.GetCache(typeof(Uniconta.DataModel.Debtor)) ?? await Comp.LoadCache(typeof(Uniconta.DataModel.Debtor), crudApi);

                var debtor = dcCache.Get(DebtorInvoice._DCAccount);
                if (debtor != null)
                {
                    StreamingManager.Copy((UnicontaBaseEntity)debtor, debtorClientUser);
                }
                else if (DebtorInvoice._Prospect != 0)
                {
                    //Check for Prospect. Create a Debtor for Prospect
                    var prosCache = Comp.GetCache(typeof(Uniconta.DataModel.CrmProspect)) ?? await Comp.LoadCache(typeof(Uniconta.DataModel.CrmProspect), crudApi);

                    var prospect = prosCache?.Get(DebtorInvoice._Prospect) as CrmProspect;
                    if (prospect != null)
                    {
                        debtorClientUser.CopyFrom(prospect);
                    }
                }

                if (previousAddressClient != null) //Setting the Previous Address if Exist for current invoice
                {
                    debtorClientUser._Name     = previousAddressClient._Name;
                    debtorClientUser._Address1 = previousAddressClient._Address1;
                    debtorClientUser._Address2 = previousAddressClient._Address2;
                    debtorClientUser._Address3 = previousAddressClient._Address3;
                    debtorClientUser._City     = previousAddressClient._City;
                    debtorClientUser._ZipCode  = previousAddressClient._ZipCode;
                }

                Debtor = debtorClientUser;

                if (dcInv._Installation != null && Comp.GetCache(typeof(Uniconta.DataModel.WorkInstallation)) == null)
                {
                    await Comp.LoadCache(typeof(Uniconta.DataModel.WorkInstallation), crudApi);
                }

                UnicontaClient.Pages.DebtorOrders.SetDeliveryAdress(debtorInvoiceClientUser, debtorClientUser, crudApi);
                debtorInvoiceClientUser.SetInvoiceAddress(debtorClientUser);

                Company = Utility.GetCompanyClientUserInstance(Comp);

                var InvCache = Comp.GetCache(typeof(InvItem)) ?? await Comp.LoadCache(typeof(InvItem), crudApi);

                CompanyLogo = await Uniconta.ClientTools.Util.UtilDisplay.GetLogo(crudApi);

                Language lang = ReportGenUtil.GetLanguage(debtorClientUser, Comp);
                InvTransInvoiceLines = LayoutPrintReport.SetInvTransLines(DebtorInvoice, InvTransInvoiceLines, InvCache, debtorInvoiceLineUserType, lang, false);

                //Setting ReportName and Version
                var invoiceNumber = DebtorInvoice._InvoiceNumber;
                var lineTotal     = DebtorInvoice._LineTotal;
                IsCreditNote = (lineTotal < -0.0001d);

                ReportName = layoutType != CompanyLayoutType.Invoice ? layoutType.ToString() : invoiceNumber == 0 ? "ProformaInvoice"
                    : IsCreditNote ? "Creditnote" : "Invoice";

                MessageClient = await GetMessageClient(lang);

                return(true);
            }
            catch (Exception ex)
            {
                crudApi?.ReportException(ex, "Error Occured in DebtorInvoicePrintReport");
                return(false);
            }
        }
Пример #21
0
        private void GenerateInvoice(DCOrder dbOrder)
        {
            InvoiceAPI Invapi         = new InvoiceAPI(api);
            bool       showSendByMail = false;
            var        debtor         = ClientHelper.GetRef(dbOrder.CompanyId, typeof(Debtor), dbOrder._DCAccount) as Debtor;

            if (debtor != null)
            {
                var InvoiceAccount = dbOrder._InvoiceAccount ?? debtor._InvoiceAccount;
                if (InvoiceAccount != null)
                {
                    debtor = ClientHelper.GetRef(dbOrder.CompanyId, typeof(Debtor), InvoiceAccount) as Debtor;
                }
                if (debtor != null)
                {
                    if (debtor._PricesInclVat != dbOrder._PricesInclVat)
                    {
                        var confirmationMsgBox = UnicontaMessageBox.Show(string.Format("{0}.\n{1}", string.Format(Uniconta.ClientTools.Localization.lookup("DebtorAndOrderMix"), Uniconta.ClientTools.Localization.lookup("InclVat")),
                                                                                       Uniconta.ClientTools.Localization.lookup("ProceedConfirmation")), Uniconta.ClientTools.Localization.lookup("Confirmation"), MessageBoxButton.OKCancel);
                        if (confirmationMsgBox != MessageBoxResult.OK)
                        {
                            return;
                        }
                    }
                    if (!api.CompanyEntity.SameCurrency(dbOrder._Currency, debtor._Currency))
                    {
                        var confirmationMsgBox = UnicontaMessageBox.Show(string.Format("{0}.\n{1}", string.Format(Uniconta.ClientTools.Localization.lookup("CurrencyMismatch"), AppEnums.Currencies.ToString((int)debtor._Currency), dbOrder.Currency),
                                                                                       Uniconta.ClientTools.Localization.lookup("ProceedConfirmation")), Uniconta.ClientTools.Localization.lookup("Confirmation"), MessageBoxButton.OKCancel);
                        if (confirmationMsgBox != MessageBoxResult.OK)
                        {
                            return;
                        }
                    }
                    showSendByMail = !string.IsNullOrEmpty(debtor._InvoiceEmail);
                }
            }
            else
            {
                api.CompanyEntity.LoadCache(typeof(Debtor), api, true);
            }

            string            debtorName           = debtor?._Name ?? dbOrder._DCAccount;
            bool              invoiceInXML         = debtor?._InvoiceInXML ?? false;
            CWGenerateInvoice GenrateInvoiceDialog = new CWGenerateInvoice(true, string.Empty, false, true, true, showNoEmailMsg: !showSendByMail, debtorName: debtorName, isOrderOrQuickInv: true, isDebtorOrder: true, InvoiceInXML: invoiceInXML);

#if !SILVERLIGHT
            GenrateInvoiceDialog.DialogTableId = 2000000010;
#endif
            GenrateInvoiceDialog.Closed += async delegate
            {
                if (GenrateInvoiceDialog.DialogResult == true)
                {
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("SendingWait");
                    busyIndicator.IsBusy      = true;
                    var showOrPrint = GenrateInvoiceDialog.ShowInvoice || GenrateInvoiceDialog.InvoiceQuickPrint;

                    var invoicePostingResult = new InvoicePostingPrintGenerator(api, this, dbOrder, null, GenrateInvoiceDialog.GenrateDate, 0, GenrateInvoiceDialog.IsSimulation, CompanyLayoutType.Invoice, showOrPrint,
                                                                                GenrateInvoiceDialog.InvoiceQuickPrint, GenrateInvoiceDialog.NumberOfPages, GenrateInvoiceDialog.SendByEmail, GenrateInvoiceDialog.Emails, GenrateInvoiceDialog.sendOnlyToThisEmail,
                                                                                GenrateInvoiceDialog.GenerateOIOUBLClicked, GenrateInvoiceDialog.PostOnlyDelivered, null);

                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("GeneratingPage");
                    busyIndicator.IsBusy      = true;
                    var result = await invoicePostingResult.Execute();

                    busyIndicator.IsBusy = false;

                    if (result)
                    {
                        Task reloadTask = null;
                        if (!GenrateInvoiceDialog.IsSimulation && dbOrder._DeleteLines)
                        {
                            reloadTask = BindGrid();
                        }

                        if (invoicePostingResult.PostingResult.Header._InvoiceNumber != 0)
                        {
                            var msg = string.Format(Uniconta.ClientTools.Localization.lookup("InvoiceHasBeenGenerated"), invoicePostingResult.PostingResult.Header._InvoiceNumber);
                            msg = string.Format("{0}{1}{2} {3}", msg, Environment.NewLine, Uniconta.ClientTools.Localization.lookup("LedgerVoucher"), invoicePostingResult.PostingResult.Header._Voucher);
                            UnicontaMessageBox.Show(msg, Uniconta.ClientTools.Localization.lookup("Message"), MessageBoxButton.OK);

#if !SILVERLIGHT
                            if (GenrateInvoiceDialog.GenerateOIOUBLClicked && !GenrateInvoiceDialog.IsSimulation)
                            {
                                GenerateOIOXml(this.api, invoicePostingResult.PostingResult);
                            }
#endif
                        }
                    }
                    else
                    {
                        Utility.ShowJournalError(invoicePostingResult.PostingResult.ledgerRes, dgDebtorOrdersGrid);
                    }
                }
            };
            GenrateInvoiceDialog.Show();
        }
Пример #22
0
        private void OrderConfirmation(CreditorOrderClient dbOrder, CompanyLayoutType doctype)
        {
            InvoiceAPI Invapi         = new InvoiceAPI(api);
            var        creditor       = dbOrder.Creditor;
            bool       showSendByMail = true;

            if (creditor != null)
            {
                showSendByMail = !string.IsNullOrEmpty(creditor._InvoiceEmail);
            }
            string            creditorName       = creditor?._Name ?? dbOrder._DCAccount;
            var               comp               = api.CompanyEntity;
            bool              showUpdateInv      = comp.Storage || (doctype == CompanyLayoutType.PurchasePacknote && comp.CreditorPacknote);
            CWGenerateInvoice GenrateOfferDialog = new CWGenerateInvoice(false, doctype.ToString(), showInputforInvNumber: doctype == CompanyLayoutType.PurchasePacknote ? true : false,
                                                                         isShowInvoiceVisible: true, askForEmail: true, showNoEmailMsg: !showSendByMail, debtorName: creditorName, isShowUpdateInv: showUpdateInv);

#if !SILVERLIGHT
            switch (doctype)
            {
            case CompanyLayoutType.PurchaseOrder:
                GenrateOfferDialog.DialogTableId = 2000000003;
                break;

            case CompanyLayoutType.PurchasePacknote:
                GenrateOfferDialog.DialogTableId = 2000000056;
                break;

            case CompanyLayoutType.Requisition:
                GenrateOfferDialog.DialogTableId = 2000000057;
                break;
            }
#endif
            GenrateOfferDialog.SetInvPrintPreview(showInvPrintPreview);
            var additionalOrdersList = Utility.GetAdditionalOrders(api, dbOrder);
            if (additionalOrdersList != null)
            {
                GenrateOfferDialog.SetAdditionalOrders(additionalOrdersList);
            }
            GenrateOfferDialog.Closed += async delegate
            {
                if (GenrateOfferDialog.DialogResult == true)
                {
                    showInvPrintPreview = GenrateOfferDialog.ShowInvoice || GenrateOfferDialog.InvoiceQuickPrint || GenrateOfferDialog.SendByOutlook;
                    string documentNumber = null;
                    if (doctype == CompanyLayoutType.PurchasePacknote)
                    {
                        documentNumber         = GenrateOfferDialog.InvoiceNumber;
                        dbOrder._InvoiceNumber = documentNumber;
                    }
                    var openOutlook          = doctype == CompanyLayoutType.PurchasePacknote ? GenrateOfferDialog.UpdateInventory && GenrateOfferDialog.SendByOutlook : GenrateOfferDialog.SendByOutlook;
                    var invoicePostingResult = new InvoicePostingPrintGenerator(api, this);
                    invoicePostingResult.SetUpInvoicePosting(dbOrder, null, doctype, GenrateOfferDialog.GenrateDate, documentNumber, !GenrateOfferDialog.UpdateInventory, GenrateOfferDialog.ShowInvoice, false,
                                                             GenrateOfferDialog.InvoiceQuickPrint, GenrateOfferDialog.NumberOfPages, GenrateOfferDialog.SendByEmail, openOutlook, GenrateOfferDialog.sendOnlyToThisEmail, GenrateOfferDialog.Emails,
                                                             false, null, false);
                    invoicePostingResult.SetAdditionalOrders(GenrateOfferDialog.AdditionalOrders?.Cast <DCOrder>().ToList());

                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("GeneratingPage");
                    busyIndicator.IsBusy      = true;
                    var result = await invoicePostingResult.Execute();

                    busyIndicator.IsBusy = false;

                    if (result)
                    {
                        DebtorOrders.Updatedata(dbOrder, doctype);
                    }

                    else
                    {
                        Utility.ShowJournalError(invoicePostingResult.PostingResult.ledgerRes, dgCreditorOrdersGrid);
                    }
                }
            };
            GenrateOfferDialog.Show();
        }
Пример #23
0
        private void FrmRibbon_OnItemClicked(string ActionType)
        {
            editrow._smtpPassword = txtSmptPwd.Text;
            switch (ActionType)
            {
            case "TestMail":
                CWCommentsDialogBox dialog = new CWCommentsDialogBox(Uniconta.ClientTools.Localization.lookup("VerifyPOP3"), Uniconta.ClientTools.Localization.lookup("Email"));
#if !SILVERLIGHT
                dialog.DialogTableId = 2000000043;
#endif
                dialog.Closing += async delegate
                {
                    if (dialog.DialogResult == true)
                    {
                        if (!string.IsNullOrEmpty(dialog.Comments) && Utilities.Utility.EmailValidation(dialog.Comments))
                        {
                            InvoiceAPI invapi = new InvoiceAPI(api);
                            busyIndicator.IsBusy = true;
                            var err = await invapi.TestSMTP(editrow, dialog.Comments);

                            if (err == ErrorCodes.Succes)
                            {
                                UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("SendEmailMsgOBJ"), Uniconta.ClientTools.Localization.lookup("Email")),
                                                        Uniconta.ClientTools.Localization.lookup("Message"));
                                isSMTPValidated            = true;
                                itemHost.IsEnabled         = false;
                                itemPort.IsEnabled         = false;
                                itemSmtpUser.IsEnabled     = false;
                                itemSmtpPassword.IsEnabled = false;
                                itemUseSSL.IsEnabled       = false;
                            }
                            else
                            {
                                ShowErrorMsg(err, editrow._host);
                            }
                            busyIndicator.IsBusy = false;
                        }
                        else
                        {
                            UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("InvalidValue"), Uniconta.ClientTools.Localization.lookup("Email"), dialog.Comments), Uniconta.ClientTools.Localization.lookup("Error"));
                        }
                    }
                };
                dialog.Show();
                break;

            case "SetUpEMail":
                var objWizardWindow = new WizardWindow(new UnicontaClient.Pages.EmailSetupWizard(), string.Format(Uniconta.ClientTools.Localization.lookup("CreateOBJ"),
                                                                                                                  Uniconta.ClientTools.Localization.lookup("EmailSetup")));
#if !SILVERLIGHT
                objWizardWindow.Width  = System.Convert.ToDouble(System.Windows.SystemParameters.PrimaryScreenWidth) * 0.14;
                objWizardWindow.Height = System.Convert.ToDouble(System.Windows.SystemParameters.PrimaryScreenHeight) * 0.20;
#else
                objWizardWindow.Width  = System.Convert.ToDouble(System.Windows.Browser.HtmlPage.Window.Eval("screen.width")) * 0.18;
                objWizardWindow.Height = System.Convert.ToDouble(System.Windows.Browser.HtmlPage.Window.Eval("screen.height")) * 0.16;
#endif
                objWizardWindow.MinHeight = 120.0d;
                objWizardWindow.MinWidth  = 350.0d;

                objWizardWindow.Closed += delegate
                {
                    if (objWizardWindow.DialogResult == true)
                    {
                        var emailSetup = objWizardWindow.WizardData as ServerInformation;
                        if (!string.IsNullOrEmpty(emailSetup?.User) && Utilities.Utility.EmailValidation(emailSetup?.User))
                        {
                            editrow.Host          = emailSetup.Host;
                            editrow.SmtpUser      = emailSetup.User;
                            editrow._smtpPassword = txtSmptPwd.Text = emailSetup.Password;
                            editrow.Port          = emailSetup.Port;
                            editrow.UseSSL        = emailSetup.SSL;
                        }
                        else
                        {
                            UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("InvalidValue"), Uniconta.ClientTools.Localization.lookup("Email"), emailSetup.User),
                                                    Uniconta.ClientTools.Localization.lookup("Warning"));
                        }
                    }
                };
                objWizardWindow.Show();
                break;

            case "Save":
                if (ValidateSMTP())
                {
                    //if (editrow.Html)
                    //{
                    //    if (!ContainsHTML(editrow.Body))
                    //        editrow.Html = false;
                    //}
                    frmRibbon_BaseActions(ActionType);
                }
                break;

            default:
                frmRibbon_BaseActions(ActionType);
                break;
            }
        }
Пример #24
0
        private void GenerateInvoice(ProjectInvoiceProposalClient dbOrder, bool showProformaInvoice)
        {
            var savetask = saveGridLocal();
            var curpanel = dockCtrl.Activpanel;

            bool showSendByMail = false;
            var  debtor         = ClientHelper.GetRef(dbOrder.CompanyId, typeof(Debtor), dbOrder._DCAccount) as Debtor;

            if (debtor != null)
            {
                var InvoiceAccount = dbOrder._InvoiceAccount ?? debtor._InvoiceAccount;
                if (InvoiceAccount != null)
                {
                    debtor = ClientHelper.GetRef(dbOrder.CompanyId, typeof(Debtor), InvoiceAccount) as Debtor;
                }
                if (debtor != null)
                {
                    if (debtor._PricesInclVat != dbOrder._PricesInclVat)
                    {
                        var confirmationMsgBox = UnicontaMessageBox.Show(string.Format("{0}.\n{1}", string.Format(Uniconta.ClientTools.Localization.lookup("DebtorAndOrderMix"), Uniconta.ClientTools.Localization.lookup("InclVat")),
                                                                                       Uniconta.ClientTools.Localization.lookup("ProceedConfirmation")), Uniconta.ClientTools.Localization.lookup("Warning"), MessageBoxButton.OKCancel);
                        if (confirmationMsgBox != MessageBoxResult.OK)
                        {
                            return;
                        }
                    }
                    if (!api.CompanyEntity.SameCurrency(dbOrder._Currency, debtor._Currency))
                    {
                        var confirmationMsgBox = UnicontaMessageBox.Show(string.Format("{0}.\n{1}", string.Format(Uniconta.ClientTools.Localization.lookup("CurrencyMismatch"), AppEnums.Currencies.ToString((int)debtor._Currency), dbOrder.Currency),
                                                                                       Uniconta.ClientTools.Localization.lookup("ProceedConfirmation")), Uniconta.ClientTools.Localization.lookup("Warning"), MessageBoxButton.OKCancel);
                        if (confirmationMsgBox != MessageBoxResult.OK)
                        {
                            return;
                        }
                    }
                    showSendByMail = (!string.IsNullOrEmpty(debtor._InvoiceEmail) || debtor._EmailDocuments);
                }
            }

            if (showProformaInvoice)
            {
                ShowProformaInvoice(dbOrder);
                return;
            }

            string            debtorName           = debtor?._Name ?? dbOrder._DCAccount;
            bool              invoiceInXML         = debtor?._InvoiceInXML ?? false;
            var               accountName          = string.Format("{0} ({1})", dbOrder._DCAccount, dbOrder.Name);
            CWGenerateInvoice GenrateInvoiceDialog = new CWGenerateInvoice(true, string.Empty, false, true, true, showNoEmailMsg: !showSendByMail, debtorName: debtorName, isOrderOrQuickInv: true, isDebtorOrder: true, InvoiceInXML: invoiceInXML, AccountName: accountName);

            GenrateInvoiceDialog.DialogTableId = 2000000086;
            if (dbOrder._InvoiceDate != DateTime.MinValue)
            {
                GenrateInvoiceDialog.SetInvoiceDate(dbOrder._InvoiceDate);
            }
            var additionalOrdersList = Utility.GetAdditionalOrders(api, dbOrder);

            if (additionalOrdersList != null)
            {
                GenrateInvoiceDialog.SetAdditionalOrders(additionalOrdersList);
            }
            GenrateInvoiceDialog.SetOIOUBLLabelText(api.CompanyEntity._OIOUBLSendOnServer);

            GenrateInvoiceDialog.Closed += async delegate
            {
                if (GenrateInvoiceDialog.DialogResult == true)
                {
                    if (savetask != null)
                    {
                        var err = await savetask;
                        if (err != ErrorCodes.Succes)
                        {
                            return;
                        }
                    }
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("SendingWait");
                    busyIndicator.IsBusy      = true;
                    InvoiceAPI Invapi               = new InvoiceAPI(api);
                    var        isSimulated          = GenrateInvoiceDialog.IsSimulation;
                    var        invoicePostingResult = SetupInvoicePostingPrintGenerator(dbOrder, GenrateInvoiceDialog.GenrateDate, isSimulated, GenrateInvoiceDialog.ShowInvoice, GenrateInvoiceDialog.PostOnlyDelivered, GenrateInvoiceDialog.InvoiceQuickPrint,
                                                                                        GenrateInvoiceDialog.NumberOfPages, GenrateInvoiceDialog.SendByEmail, !isSimulated && GenrateInvoiceDialog.SendByOutlook, GenrateInvoiceDialog.sendOnlyToThisEmail, GenrateInvoiceDialog.Emails,
                                                                                        GenrateInvoiceDialog.GenerateOIOUBLClicked);
                    invoicePostingResult.SetAdditionalOrders(GenrateInvoiceDialog.AdditionalOrders?.Cast <DCOrder>().ToList());

                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("GeneratingPage");
                    busyIndicator.IsBusy      = true;
                    var result = await invoicePostingResult.Execute();

                    busyIndicator.IsBusy = false;

                    if (!result)
                    {
                        Utility.ShowJournalError(invoicePostingResult.PostingResult.ledgerRes, dgProjInvProposedLineGrid);
                    }
                    else
                    {
                        Task reloadTask = null;
                        if (!GenrateInvoiceDialog.IsSimulation && dbOrder._DeleteLines)
                        {
                            reloadTask = Filter(null);
                        }

                        if (reloadTask != null)
                        {
                            CloseOrderLineScreen(reloadTask, curpanel);
                        }
                    }
                }
            };
            GenrateInvoiceDialog.Show();
        }