Esempio n. 1
0
 private void InitPage()
 {
     InitializeComponent();
     dgDebtorTranOpenGrid.api = api;
     SetRibbonControl(localMenu, dgDebtorTranOpenGrid);
     dgDebtorTranOpenGrid.BusyIndicator = busyIndicator;
     localMenu.OnItemClicked           += localMenu_OnItemClicked;
     dgDebtorTranOpenGrid.OnPrintClick += DgDebtorTranOpenGrid_OnPrintClick;
     statementList = new List <DebtorPaymentStatementList>();
     if (toDate == DateTime.MinValue)
     {
         toDate = txtDateTo.DateTime.Date;
     }
     txtDateTo.DateTime  = toDate;
     txtDateFrm.DateTime = fromDate;
     neDunningDays.Text  = NumberConvert.ToStringNull(noDaysSinceLastDunning);
     dgDebtorTranOpenGrid.ShowTotalSummary();
     cmbPrintintPreview.ItemsSource   = new string[] { Uniconta.ClientTools.Localization.lookup("Internal"), Uniconta.ClientTools.Localization.lookup("External") };
     cmbPrintintPreview.SelectedIndex = 0;
     tbDateFrom.Text = string.Format("{0} {1}", Uniconta.ClientTools.Localization.lookup("From"), Uniconta.ClientTools.Localization.lookup("DueDate"));
     tbDateTo.Text   = string.Format(Uniconta.ClientTools.Localization.lookup("ToOBJ"), Uniconta.ClientTools.Localization.lookup("DueDate"));
 }
 public void SetInvoiceNumber(long Number)
 {
     SetInvoiceNumber(NumberConvert.ToStringNull(Number));
 }
Esempio n. 3
0
        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)
                {
                    CreditorOrder = Comp.GetCache(typeof(Uniconta.DataModel.CreditorOrder))?.Get(NumberConvert.ToStringNull(creditorInvoiceClientUser._OrderNumber)) as CreditorOrderClient;
                    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);
            }
        }
        public static string InternalMessage(string messageFormat, CreditorTransPayment rec, Company company, Uniconta.DataModel.Creditor creditor)
        {
            var sbAdvText = StringBuilderReuse.Create();

            var advText = string.Empty;
            var country = company._CountryId;
            var tuple   = MessageLabel(country);

            if (messageFormat != null)
            {
                sbAdvText.Append(messageFormat);

                if (rec.invoiceNumbers != null && rec.MergePaymId != MERGEID_SINGLEPAYMENT)
                {
                    sbAdvText.Remove("Fak:%1").Trim(); //Removes invoicenumbers for merge payment due to limitation of characters
                    sbAdvText.Remove("Fak: %1").Trim();
                    sbAdvText.Remove("%1").Trim();
                }

                sbAdvText.Replace("%1", "{0}").Replace("%2", "{1}").Replace("%3", "{2}").Replace("%4", "{3}").Replace("%5", "{4}");
                advText = string.Format(sbAdvText.ToStringAndRelease(), rec.InvoiceAN, creditor?._Account, creditor?._Name, NumberConvert.ToStringNull(rec.Voucher), NumberConvert.ToStringNull(rec.PaymentRefId));
            }
            else //Default message
            {
                BuildBankAdviceText(sbAdvText, NumberConvert.ToString(rec.PaymentEndToEndId), tuple.Item3);
                if (rec.invoiceNumbers == null || rec.MergePaymId == MERGEID_SINGLEPAYMENT)
                {
                    BuildBankAdviceText(sbAdvText, rec.InvoiceAN ?? string.Empty, tuple.Item2);
                }

                BuildBankAdviceText(sbAdvText, creditor?._Account, tuple.Item1);

                advText = sbAdvText.ToStringAndRelease();
            }

            return(advText);
        }
        /// <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);

                    if (ContactsCache != null)
                    {
                        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)
                {
                    DebtorOrder = Comp.GetCache(typeof(Uniconta.DataModel.DebtorOrder))?.Get(NumberConvert.ToStringNull(debtorInvoiceClientUser._OrderNumber)) as DebtorOrderClient;
                    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);
            }
        }