Exemplo n.º 1
0
        private void UpdateDocument(CompanyLayoutType documentType)
        {
            bool showUpdateInv = api.CompanyEntity.Storage;
            var  generateDoc   = new CWGenerateInvoice(false, documentType.ToString(), false, true, true, false, isQuickPrintVisible: false, isShowUpdateInv: showUpdateInv);

#if !SILVERLIGHT
            generateDoc.DialogTableId = 2000000000;
            generateDoc.HideOutlookOption(true);
#endif
            generateDoc.Closed += async delegate
            {
                if (generateDoc.DialogResult == true)
                {
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("SendingWait");
                    busyIndicator.IsBusy      = true;

                    var crVisibleOrders = dgMultiInvGrid.GetVisibleRows() as IEnumerable <CreditorOrderClient>;

                    var invoicePostingPrintGenerator = new InvoicePostingPrintGenerator(api, this);
                    invoicePostingPrintGenerator.SetUpInvoicePosting(crVisibleOrders, generateDoc.GenrateDate, !generateDoc.UpdateInventory, documentType, false, false, false,
                                                                     generateDoc.SendByEmail, generateDoc.sendOnlyToThisEmail, generateDoc.Emails, false);

                    await invoicePostingPrintGenerator.Execute();

                    busyIndicator.IsBusy = false;
                }
            };
            generateDoc.Show();
        }
Exemplo n.º 2
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) || debtor.EmailDocuments);
            }
            string            debtorName         = debtor?._Name ?? dbOrder._DCAccount;
            bool              showUpdateInv      = api.CompanyEntity.Storage || (doctype == CompanyLayoutType.Packnote && api.CompanyEntity.Packnote);
            var               accountName        = string.Format("{0} ({1})", dbOrder._DCAccount, dbOrder.Name);
            CWGenerateInvoice GenrateOfferDialog = new CWGenerateInvoice(false, doctype.ToString(), isShowInvoiceVisible: true, askForEmail: true, showNoEmailMsg: !showSendByMail, debtorName: debtorName,
                                                                         isShowUpdateInv: showUpdateInv, isDebtorOrder: true, AccountName: accountName);

#if !SILVERLIGHT
            if (doctype == CompanyLayoutType.OrderConfirmation)
            {
                GenrateOfferDialog.DialogTableId = 2000000009;
            }
            else if (doctype == CompanyLayoutType.Packnote)
            {
                GenrateOfferDialog.DialogTableId = 2000000018;
            }
#endif
            GenrateOfferDialog.SetInvPrintPreview(showPrintPreview);
            var additionalOrdersList = Utility.GetAdditionalOrders(api, dbOrder);
            if (additionalOrdersList != null)
            {
                GenrateOfferDialog.SetAdditionalOrders(additionalOrdersList);
            }
            GenrateOfferDialog.Closed += async delegate
            {
                if (GenrateOfferDialog.DialogResult == true)
                {
                    showPrintPreview = GenrateOfferDialog.ShowInvoice || GenrateOfferDialog.InvoiceQuickPrint || GenrateOfferDialog.SendByOutlook;
                    var invoicePostingResult = new InvoicePostingPrintGenerator(api, this);
                    var openOutlook          = doctype == CompanyLayoutType.Packnote ? GenrateOfferDialog.UpdateInventory && GenrateOfferDialog.SendByOutlook : GenrateOfferDialog.SendByOutlook;
                    invoicePostingResult.SetUpInvoicePosting(dbOrder, null, doctype, GenrateOfferDialog.GenrateDate, null, !GenrateOfferDialog.UpdateInventory, GenrateOfferDialog.ShowInvoice, GenrateOfferDialog.PostOnlyDelivered,
                                                             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)
                    {
                        Updatedata(dbOrder, doctype);
                    }
                    else
                    {
                        Utility.ShowJournalError(invoicePostingResult.PostingResult.ledgerRes, dgDebtorOrdersGrid);
                    }
                }
            };
            GenrateOfferDialog.Show();
        }
Exemplo n.º 3
0
        void ShowMultipleOrderToPrint(CompanyLayoutType docType, bool isQuickPrint)
        {
            DispatcherTimer timer = new DispatcherTimer();

            timer.Interval = new TimeSpan(1000);
            timer.Tick    += async delegate
            {
                timer.Stop();
#if SILVERLIGHT
                int top          = 200;
                int left         = 300;
                int invoiceCount = 1;
                int itemcount    = confirmOrder.Count();
#else
                List <IPrintReport> xtraReports = new List <IPrintReport>();
#endif
                busyIndicator.IsBusy = true;
                foreach (var item in confirmOrder)
                {
#if SILVERLIGHT
                    if (item.Header == null)
                    {
                        continue;
                    }

                    var deb         = (DebtorInvoiceClient)item.Header;
                    var printHeader = string.Format("{0}: {1}, {2}", Uniconta.ClientTools.Localization.lookup("ShowPrint") + "-" + invoiceCount.ToString(), deb._DCAccount, deb.Name);

                    object[] ob = new object[2] {
                        item, docType
                    };

                    AddDockItem(TabControls.ProformaInvoice, ob, true, printHeader, null, new Point(top, left));
                    left = left - left / itemcount;
                    top  = top - top / itemcount;
                    invoiceCount++;
                }
                busyIndicator.IsBusy = false;
#else
                    if (item.Key.Header == null)
                    {
                        continue;
                    }
                    var standardPrint = await ValidateStandardPrint(item.Key, item.Value, docType, isQuickPrint);

                    if (standardPrint?.Report != null)
                    {
                        xtraReports.Add(standardPrint);
                    }
                }
                busyIndicator.IsBusy = false;

                if (xtraReports.Count > 0)
                {
                    if (!isQuickPrint)
                    {
                        var reportName = Uniconta.ClientTools.Localization.lookup(docType.ToString());
                        AddDockItem(UnicontaTabs.StandardPrintReportPage, new object[] { xtraReports, reportName }, string.Format("{0}: {1}", Uniconta.ClientTools.Localization.lookup("ShowPrint"),
                                                                                                                                  reportName));
                    }
                    else
                    {
                        QuickPrintReports(xtraReports);
                    }
                }
#endif
            };
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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();
        }
        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);
            }
        }
Exemplo n.º 7
0
 private void PreInitMulitplePreviewDocument(string message, CompanyLayoutType documentType, bool showInvoice, bool quickPrintInvoice, int docCount, bool sendBymail, bool sendOnlyToMail)
 {
     if (docCount > 0)
     {
         if (showInvoice || quickPrintInvoice)
         {
             InitMultiplePreviewDocument(message, documentType, quickPrintInvoice);
         }
         else if (sendBymail || sendOnlyToMail)
         {
             UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("SendEmailMsgOBJ"), string.Format("{0} {1}", docCount, Uniconta.ClientTools.Localization.lookup(documentType.ToString()))),
                                     Uniconta.ClientTools.Localization.lookup("Message"));
         }
     }
 }
Exemplo n.º 8
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();
        }
        /// <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);
            }
        }