void SetCreditorFilterUserFields()
        {
            var Comp        = api.CompanyEntity;
            var creditorRow = new CreditorClient();

            creditorRow.SetMaster(Comp);
            var creditorUserField = creditorRow.UserFieldDef();

            if (creditorUserField != null)
            {
                CreditorUserFields = creditorUserField;
            }
        }
        void InitPage(CrudAPI crudapi)
        {
            BusyIndicator   = busyIndicator;
            dAddress.Header = Uniconta.ClientTools.Localization.lookup("DeliveryAddr");
            layoutControl   = layoutItems;
            cbDeliveryCountry.ItemsSource            = cbCountry.ItemsSource = Enum.GetValues(typeof(Uniconta.Common.CountryCode));
            ItemNameGrouplookupeditior.api           =
                Withholdinglookupeditior.api         =
                    Vatlookupeditior.api             = VatOprlookupeditior.api = Employeelookupeditor.api = leInvoiceAccount.api =
                        dim1lookupeditior.api        = dim2lookupeditior.api = dim3lookupeditior.api = dim4lookupeditior.api = dim5lookupeditior.api =
                            Paymentlookupeditior.api = grouplookupeditor.api = PriceListlookupeditior.api = lePostingAccount.api = lePaymtFormat.api =
                                leShipment.api       = leDeliveryTerm.api = LayoutGrouplookupeditior.api = prCategoryLookUpeditor.api = leD2CAccount.api = leCrmGroup.api = crudapi;

            AdjustLayout();
            Task t;

            if (crudapi.CompanyEntity.CRM)
            {
                t = GetInterestAndProduct();
            }
            else
            {
                t = null;
            }

            if (LoadedRow == null)
            {
                frmRibbon.DisableButtons("Delete");
                if (!isCopiedRow)
                {
                    editrow = CreateNew() as CreditorClient;
                }
                else
                {
                    editrow._D2CAccount = null;
                }
                editrow.Country = crudapi.CompanyEntity._CountryId;
            }

            layoutItems.DataContext  = editrow;
            frmRibbon.OnItemClicked += frmRibbon_OnItemClicked;
            StartLoadCache(t);
            if (editrow.RowId != 0)
            {
                leD2CAccount.IsReadOnly = true;
            }
            editrow.PropertyChanged          += Editrow_PropertyChanged;
            txtCompanyRegNo.EditValueChanged += TxtCVR_EditValueChanged;
#if !SILVERLIGHT
            txtCompanyRegNo.LostFocus += TxtCompanyRegNo_LostFocus;
        }
Exemplo n.º 3
0
        void CopyRecord(CreditorClient selectedItem)
        {
            if (selectedItem == null)
            {
                return;
            }
            var creditor = Activator.CreateInstance(selectedItem.GetType()) as CreditorClient;

            CorasauDataGrid.CopyAndClearRowId(selectedItem, creditor);
            creditor._Created    = DateTime.MinValue;
            creditor._D2CAccount = null;
            AddDockItem(TabControls.CreditorAccountPage2, new object[2] {
                creditor, IdObject.get(false)
            }, Uniconta.ClientTools.Localization.lookup("Creditorsaccount"), "Add_16x16.png");
        }
 public CreditorOrdersPage2(CrudAPI crudApi, UnicontaBaseEntity master) /* called for edit from particular account */
     : base(crudApi, "")
 {
     InitializeComponent();
     if (master != null)
     {
         Creditor = master as CreditorClient;
         if (Creditor == null)
         {
             Contact  = master as ContactClient;
             Creditor = Contact?.Creditor;
         }
     }
     InitPage(api);
 }
Exemplo n.º 5
0
        private void karKartotekBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            var api = UCInitializer.GetBaseAPI;

            //var task = api.Query<CreditorClient>();
            //task.Wait();
            //var col1 = task.Result;

            foreach (var recKartotek in this.karKartotekBindingSource.DataSource as KarKartotek)
            {
                if (recKartotek.DK == "1") //Kreditor
                {
                    var crit = new List <PropValuePair>();
                    var pair = PropValuePair.GenereteWhereElements("Account", typeof(String), recKartotek.Kontonr.ToString());
                    crit.Add(pair);
                    var taskQueryCreditor = api.Query <CreditorClient>(null, crit);
                    taskQueryCreditor.Wait();
                    var col = taskQueryCreditor.Result;
                    if (col.Count() == 0)
                    {
                        CreditorClient recCreditor = new CreditorClient()
                        {
                            Account       = recKartotek.Kontonr.ToString(),
                            Name          = recKartotek.Kontonavn,
                            Address1      = recKartotek.Adresse,
                            ZipCode       = recKartotek.Postnr,
                            City          = recKartotek.Bynavn,
                            ContactEmail  = recKartotek.Email,
                            CompanyRegNo  = recKartotek.Cvrnr,
                            PaymentMethod = "Kreditors bankkonto",
                            //PaymentId = recKartotek.bankkonto,
                        };
                        var taskInsertCreditor = api.Insert(recCreditor);
                        taskInsertCreditor.Wait();
                        var err = taskInsertCreditor.Result;
                    }
                }
                else //Debitor
                {
                    var crit = new List <PropValuePair>();
                    var pair = PropValuePair.GenereteWhereElements("Account", typeof(String), recKartotek.Kontonr.ToString());
                    crit.Add(pair);
                    var taskQueryDebtor = api.Query <DebtorClient>(null, crit);
                    taskQueryDebtor.Wait();
                    var col = taskQueryDebtor.Result;
                    if (col.Count() == 0)
                    {
                        DebtorClient recDebtor = new DebtorClient()
                        {
                            Account      = recKartotek.Kontonr.ToString(),
                            Name         = recKartotek.Kontonavn,
                            Address1     = recKartotek.Adresse,
                            ZipCode      = recKartotek.Postnr,
                            City         = recKartotek.Bynavn,
                            ContactEmail = recKartotek.Email,
                            CompanyRegNo = recKartotek.Cvrnr,
                        };
                        var taskInsertDebtor = api.Insert(recDebtor);
                        taskInsertDebtor.Wait();
                        var err = taskInsertDebtor.Result;
                    }
                }
            }
        }
        private async void ReadFromBilagscan(UnicontaBaseEntity selectedItem)
        {
#if !SILVERLIGHT
            if (!readingFromBilagscan)
            {
                readingFromBilagscan = true;

                bool processLines = false;
                var  accessToken  = await Bilagscan.Account.GetBilagscanAccessToken(api);

                var noOfVouchers    = 0;
                var companySettings = await api.Query <CompanySettingsClient>();

                var orgNo = companySettings.FirstOrDefault()._OrgNumber;

                var journal = dgGldailyJournal.SelectedItem as GLDailyJournalClient;

                //  UnicontaBaseEntity[] baseEntityArray = new UnicontaBaseEntity[1] { selectedItem };

                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                    var response = await client.GetAsync($"https://api.bilagscan.dk/v1/organizations/" + orgNo.ToString() + "/vouchers?seen=false&count=100&offset=0&sorts=-upload_date&status=successful");

                    var content = await response.Content.ReadAsStringAsync();

                    var vouchers = Bilagscan.Voucher.GetVouchers(content);

                    var credCache = api.CompanyEntity.GetCache(typeof(Uniconta.DataModel.Creditor)) ?? await api.CompanyEntity.LoadCache(typeof(Uniconta.DataModel.Creditor), api);

                    var offsetCache = api.CompanyEntity.GetCache(typeof(Uniconta.DataModel.GLAccount)) ?? await api.CompanyEntity.LoadCache(typeof(Uniconta.DataModel.GLAccount), api);

                    var vouchersSeen = new CommaDelimitedStringCollection();

                    var master = new List <UnicontaBaseEntity>
                    {
                        journal
                    };

                    var newLines       = new List <UnicontaBaseEntity>();
                    var updateCreditor = new List <UnicontaBaseEntity>();

                    if (vouchers?.data != null)
                    {
                        var creditors = credCache.GetKeyStrRecords as Uniconta.DataModel.Creditor[];

                        foreach (var voucher in vouchers.data)
                        {
                            vouchersSeen.Add(NumberConvert.ToString(voucher.id));
                            var journalLine = new GLDailyJournalLineClient()
                            {
                                Approved        = false,
                                ForceSettlement = false
                            };

                            var postingType = BilagscanVoucherType.Invoice;

                            var hint = Bilagscan.Voucher.GetHint(voucher.note);

                            var bilagscanRefID = voucher.id;
                            journalLine.ReferenceNumber = bilagscanRefID != 0 ? NumberConvert.ToString(bilagscanRefID) : null;

                            var bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "voucher_number", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                journalLine.Invoice = bsItem.value;
                            }

                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "voucher_type", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                switch (bsItem.value)
                                {
                                case "invoice": postingType = BilagscanVoucherType.Invoice; break;

                                case "creditnote": postingType = BilagscanVoucherType.Creditnote; break;

                                case "receipt": postingType = BilagscanVoucherType.Receipt; break;
                                }
                            }

                            var creditorCVR = string.Empty;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "company_vat_reg_no", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                creditorCVR = bsItem.value;
                            }

                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "total_amount_incl_vat", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                journalLine.Amount = Math.Abs(NumberConvert.ToDoubleNoThousandSeperator(bsItem.value));

                                if (postingType != BilagscanVoucherType.Creditnote)
                                {
                                    journalLine.Amount = -journalLine.Amount;
                                }
                            }

                            CountryCode countryCode = CountryCode.Denmark;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "country", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                CountryISOCode countryISO;
                                countryCode = CountryCode.Denmark; //default
                                if (Enum.TryParse(bsItem.value, true, out countryISO))
                                {
                                    countryCode = (CountryCode)countryISO;
                                }
                            }

                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "invoice_date", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                var invoiceDate = bsItem.value == string.Empty ? GetSystemDefaultDate() : StringSplit.DateParse(bsItem.value, DateFormat.ymd);
                                journalLine.Date = invoiceDate;

                                if (journalLine.Date == DateTime.MinValue)
                                {
                                    journalLine.Date = GetSystemDefaultDate();
                                }
                            }

                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_date", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                var paymentDate = bsItem.value == string.Empty ? DateTime.MinValue : StringSplit.DateParse(bsItem.value, DateFormat.ymd);
                                journalLine._DueDate = paymentDate;
                            }

                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "currency", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                Currencies currencyISO;
                                if (!Enum.TryParse(bsItem.value, true, out currencyISO))
                                {
                                    currencyISO = Currencies.DKK; //default
                                }
                                journalLine._Currency = (byte)currencyISO;
                            }

                            string bbanAcc = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_account_number", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                bbanAcc = bsItem.value;
                            }

                            string bbanRegNum = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_reg_number", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                bbanRegNum = bsItem.value;
                            }

                            string ibanNo = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_iban", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                ibanNo = bsItem.value;
                            }

                            string swiftNo = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_swift_bic", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                swiftNo = bsItem.value;
                            }

                            string paymentCodeId = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_code_id", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                paymentCodeId = bsItem.value;
                            }

                            string paymentId = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_id", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                paymentId = bsItem.value;
                            }

                            string jointPaymentId = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "joint_payment_id", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                jointPaymentId = bsItem.value;
                            }

                            var paymentMethod = PaymentTypes.VendorBankAccount;
                            switch (paymentCodeId)
                            {
                            case "71": paymentMethod = PaymentTypes.PaymentMethod3; break;

                            case "73": paymentMethod = PaymentTypes.PaymentMethod4; break;

                            case "75": paymentMethod = PaymentTypes.PaymentMethod5; break;

                            case "04":
                            case "4": paymentMethod = PaymentTypes.PaymentMethod6; break;
                            }

                            if (paymentMethod != PaymentTypes.VendorBankAccount && (paymentId != null || jointPaymentId != null))
                            {
                                journalLine._PaymentMethod = paymentMethod;
                                journalLine._PaymentId     = string.Format("{0} +{1}", paymentId, jointPaymentId);
                            }
                            else if (bbanRegNum != null && bbanAcc != null)
                            {
                                journalLine._PaymentMethod = PaymentTypes.VendorBankAccount;
                                journalLine._PaymentId     = string.Format("{0}-{1}", bbanRegNum, bbanAcc);
                            }
                            else if (swiftNo != null && ibanNo != null)
                            {
                                journalLine._PaymentMethod = PaymentTypes.IBAN;
                                journalLine._PaymentId     = ibanNo;
                            }

                            journalLine.SettleValue = "Voucher";

                            Uniconta.DataModel.Creditor creditor = null;

                            if (hint != null)
                            {
                                journalLine._DocumentRef = hint.RowId;
                                //if (hint.CreditorAccount != null)
                                //    creditor = (Uniconta.DataModel.Creditor)credCache.Get(hint.CreditorAccount);
                                //if (hint.Amount != 0)
                                //    journalLine.Amount = hint.Amount;
                                //if (hint.Currency != null && hint.Currency != "-")
                                //    journalLine.Currency = hint.Currency;
                                //if (hint.PaymentId != null)
                                //{
                                //    journalLine._PaymentId = hint.PaymentId;
                                //    journalLine.PaymentMethod = hint.PaymentMethod;
                                //}
                            }

                            journalLine._AccountType = 2;

                            var creditorCVRNum = Regex.Replace(creditorCVR, "[^0-9]", string.Empty);

                            if (creditorCVRNum != string.Empty)
                            {
                                creditor = creditors.Where(s => (Regex.Replace(s._LegalIdent ?? string.Empty, "[^0-9.]", "") == creditorCVRNum)).FirstOrDefault();
                            }

                            if (creditorCVRNum == string.Empty)
                            {
                                journalLine.Text = Uniconta.ClientTools.Localization.lookup("NotValidVatNo");
                            }
                            else if (creditor == null)
                            {
                                var newCreditor = new CreditorClient()
                                {
                                    _Account       = creditorCVR,
                                    _LegalIdent    = creditorCVR,
                                    _PaymentMethod = journalLine._PaymentMethod,
                                    _PaymentId     = journalLine._PaymentId,
                                    _SWIFT         = swiftNo
                                };

                                CompanyInfo companyInformation = null;
                                try
                                {
                                    companyInformation = await CVR.CheckCountry(creditorCVR, countryCode);
                                }
                                catch (Exception ex)
                                {
                                    UnicontaMessageBox.Show(ex);
                                    return;
                                }

                                if (companyInformation != null)
                                {
                                    if (companyInformation.life != null)
                                    {
                                        newCreditor._Name = companyInformation.life.name;
                                    }

                                    if (companyInformation.address != null)
                                    {
                                        newCreditor._Address1 = companyInformation.address.CompleteStreet;
                                        newCreditor._ZipCode  = companyInformation.address.zipcode;
                                        newCreditor._City     = companyInformation.address.cityname;
                                        newCreditor._Country  = companyInformation.address.Country;
                                    }

                                    if (companyInformation.contact != null)
                                    {
                                        newCreditor._Phone        = companyInformation.contact.phone;
                                        newCreditor._ContactEmail = companyInformation.contact.email;
                                    }

                                    journalLine.Text = newCreditor.Name;
                                }
                                else
                                {
                                    newCreditor.Name = Uniconta.ClientTools.Localization.lookup("NotValidVatNo");
                                }

                                await api.Insert(newCreditor);

                                journalLine.Account = creditorCVR;
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(creditor._PostingAccount))
                                {
                                    var account = (GLAccountClient)offsetCache.Get(creditor._PostingAccount);
                                    if (!string.IsNullOrEmpty(account.Vat))
                                    {
                                        var dailyJournal = (GLDailyJournalClient)master[0];
                                        if (dailyJournal.TwoVatCodes)
                                        {
                                            journalLine._OffsetVat = account.Vat;
                                        }
                                        else
                                        {
                                            journalLine._Vat = account.Vat;
                                        }
                                    }

                                    journalLine._OffsetAccount = creditor._PostingAccount;
                                }
                                else
                                {
                                    journalLine.Vat = creditor._Vat;
                                }


                                if (journalLine._DueDate == DateTime.MinValue && creditor._Payment != string.Empty)
                                {
                                    var paymentTermsCache = api.GetCache(typeof(PaymentTerm)) ?? await api.LoadCache(typeof(PaymentTerm));

                                    var paymentTerm = (PaymentTerm)paymentTermsCache.Get(creditor._Payment);

                                    if (paymentTerm != null)
                                    {
                                        journalLine._DueDate = paymentTerm.GetDueDate(journalLine.DueDate);
                                    }
                                }

                                journalLine.Account = creditor._Account;
                                journalLine.Text    = creditor._Name;

                                if (creditor._SWIFT == null && swiftNo != null)
                                {
                                    creditor._SWIFT = swiftNo;
                                    updateCreditor.Add(creditor);
                                }
                            }

                            journalLine.SetMaster(master[0]);
                            newLines.Add(journalLine);

                            noOfVouchers += 1;
                        }
                    }
                    var errorCode = await api.Insert(newLines);

                    api.UpdateNoResponse(updateCreditor);

                    if (vouchersSeen.Count != 0)
                    {
                        // Mark voucher as seen
                        string serializedRequest = "{ \"vouchers\": [ " + vouchersSeen.ToString() + " ] }";
                        var    vContent          = new StringContent(serializedRequest, Encoding.UTF8, "application/json");
                        response = await client.PostAsync($"https://api.bilagscan.dk/v1/organizations/" + NumberConvert.ToString(orgNo) + "/vouchers/seen", vContent);

                        var res = await response.Content.ReadAsStringAsync();
                    }
                }

                if (noOfVouchers == 0)
                {
                    UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("StillProcessingTryAgain"), Uniconta.ClientTools.Localization.lookup("Bilagscan")), Uniconta.ClientTools.Localization.lookup("Bilagscan"), MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    var messageText = string.Concat(string.Format("{0} {1}", Uniconta.ClientTools.Localization.lookup("NumberOfImportedVouchers"), noOfVouchers),
                                                    Environment.NewLine, Environment.NewLine,
                                                    string.Format(Uniconta.ClientTools.Localization.lookup("GoTo"), Uniconta.ClientTools.Localization.lookup("Journallines")), "?");
                    if (UnicontaMessageBox.Show(messageText, Uniconta.ClientTools.Localization.lookup("BilagscanRead"), MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.OK)
                    {
                        AddDockItem(TabControls.GL_DailyJournalLine, journal, null, null, true);
                    }
                }
                readingFromBilagscan = false;
            }
#endif
        }