public static Sage.Accounting.PurchaseLedger.PostedPurchaseAccountEntry GetInvoiceByInvoiceNumberAndSupplierPrimaryKey(string id, string invoicenumber)
        {
            Sage.Accounting.PurchaseLedger.PostedPurchaseAccountEntry result = null;
            if (application != null)
            {
                try
                {
                    // PURCHASE INVOICES
                    Sage.Accounting.PurchaseLedger.PostedPurchaseAccountEntries invoices = Sage.Accounting.PurchaseLedger.PostedPurchaseAccountEntriesFactory.Factory.CreateNew();
                    Sage.ObjectStore.Query query = new Sage.ObjectStore.Query();

                    Sage.ObjectStore.Filter filter = new Sage.ObjectStore.Filter(Sage.Accounting.PurchaseLedger.PostedPurchaseAccountEntry.FIELD_ENTRYTYPE, Sage.Accounting.TradingAccountEntryTypeEnum.TradingAccountEntryTypeInvoice);
                    query.Filters.Add(filter);

                    Sage.ObjectStore.Filter filter1 = new Sage.ObjectStore.Filter(Sage.Accounting.PurchaseLedger.PostedPurchaseAccountEntry.FIELD_INSTRUMENTNO, invoicenumber);
                    query.Filters.Add(filter1);

                    Sage.Common.Data.DbKey  key     = new Sage.Common.Data.DbKey(Convert.ToInt32(id));
                    Sage.ObjectStore.Filter filter2 = new Sage.ObjectStore.Filter(Sage.Accounting.PurchaseLedger.PostedPurchaseAccountEntry.FIELD_SUPPLIERACCOUNTDBKEY, key);
                    query.Filters.Add(filter2);

                    invoices.Find(query);

                    result = invoices.First;
                }
                catch (Exception ex)
                {
                    result = null;
                    Logger.WriteLog(ex);
                }
            }

            return(result);
        }
        public static Supplier GetSupplierByPrimaryKey(string key)
        {
            Supplier supplier = null;

            if (application != null)
            {
                Sage.Common.Data.DbKey dbkey = new Sage.Common.Data.DbKey(Convert.ToInt32(key));
                supplier = Sage.Accounting.PurchaseLedger.SupplierFactory.Factory.Fetch(dbkey);
            }
            return(supplier);
        }
        public static Sage.Accounting.PurchaseLedger.PurchaseBankPaymentPosting GetPaymentByPrimaryKey(string id)
        {
            Sage.Accounting.PurchaseLedger.PurchaseBankPaymentPosting payment = null;
            if (application != null)
            {
                Sage.Common.Data.DbKey key = new Sage.Common.Data.DbKey(Convert.ToInt32(id));
                payment = Sage.Accounting.PurchaseLedger.PurchaseBankPaymentPostingFactory.Factory.Fetch(key);
            }

            return(payment);
        }
        public static Sage.Accounting.PurchaseLedger.PostedPurchaseAccountEntry GetInvoiceByPrimaryKey(string id)
        {
            Sage.Accounting.PurchaseLedger.PostedPurchaseAccountEntry entry = null;
            if (application != null)
            {
                Sage.Common.Data.DbKey key = new Sage.Common.Data.DbKey(Convert.ToInt32(id));
                entry = Sage.Accounting.PurchaseLedger.PostedPurchaseAccountEntryFactory.Factory.Fetch(key);
            }

            return(entry);
        }
        public static Department GetDepartmentByPrimaryKey(string key)
        {
            Department department = null;

            if (application != null)
            {
                Sage.Common.Data.DbKey dbkey = new Sage.Common.Data.DbKey(Convert.ToInt32(key));
                department = Sage.Accounting.SystemManager.DepartmentFactory.Factory.Fetch(dbkey);
            }
            return(department);
        }
        public static Bank GetBankByPrimaryKey(string key)
        {
            Bank bank = null;

            if (application != null)
            {
                Sage.Common.Data.DbKey dbkey = new Sage.Common.Data.DbKey(Convert.ToInt32(key));
                bank = Sage.Accounting.CashBook.BankFactory.Factory.Fetch(dbkey);
            }
            return(bank);
        }
        public static TaxCode GetVatRateByPrimaryKey(string key)
        {
            TaxCode taxcode = null;

            if (application != null)
            {
                Sage.Common.Data.DbKey dbkey = new Sage.Common.Data.DbKey(Convert.ToInt32(key));
                taxcode = Sage.Accounting.TaxModule.TaxCodeFactory.Factory.Fetch(dbkey);
            }

            return(taxcode);
        }
        public static POPOrder GetPurchaseOrderByPrimaryKey(string key)
        {
            POPOrder poporder = null;

            if (application != null)
            {
                Sage.Common.Data.DbKey dbkey = new Sage.Common.Data.DbKey(Convert.ToInt32(key));
                poporder = Sage.Accounting.POP.POPOrder.Fetch(key);
            }

            return(poporder);
        }
        public static NominalCode GetNominalCodeByPrimaryKey(string key)
        {
            NominalCode nominalcode = null;

            if (application != null)
            {
                Sage.Common.Data.DbKey dbkey = new Sage.Common.Data.DbKey(Convert.ToInt32(key));
                nominalcode = Sage.Accounting.NominalLedger.NominalCodeFactory.Factory.Fetch(dbkey);
            }

            return(nominalcode);
        }