public static NominalCode GetNominalCodeByAccountNumber(string accountnumber)
        {
            NominalCode nominalcode = null;

            if (application != null)
            {
                Sage.Accounting.NominalLedger.NominalCodes codes = Sage.Accounting.NominalLedger.NominalCodesFactory.Factory.FetchWithAccountNumber(accountnumber);

                nominalcode = codes.First;
            }
            return(nominalcode);
        }
        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);
        }
Beispiel #3
0
        public static GlAccountRoot SageNominalCodeToMTGlAccount(SageNominalCode sagenominalcode)
        {
            GlAccountRoot glaccountroot = new GlAccountRoot();
            GlAccount     glaccount     = new GlAccount();

            glaccount.id                 = "";
            glaccount.externalId         = sagenominalcode.PrimaryKey.DbValue.ToString();
            glaccount.subsidiaries       = null;
            glaccount.departmentRequired = false;
            glaccount.locationRequired   = false;
            glaccount.projectRequired    = false;
            glaccount.customerRequired   = false;
            glaccount.vendorRequired     = false;
            glaccount.employeeRequired   = false;
            glaccount.itemRequired       = false;
            glaccount.classRequired      = false;
            glaccount.ledgerType         = "EXPENSE_ACCOUNT";
            glaccount.accountNumber      = sagenominalcode.Reference;
            glaccount.name               = sagenominalcode.Name;
            glaccount.active             = true; // NO MATCHING FIELD IN SAGE

            glaccountroot.glAccount = glaccount;
            return(glaccountroot);
        }
        public static string CreateInvoice(string supplierid, string invoicenumber, string invoicedate, decimal amount, decimal taxamount, List <LineItem> lineitems)
        {
            string newid = "";

            try
            {
                Sage.Accounting.PurchaseLedger.PurchaseInvoiceInstrument invoice = Sage.Accounting.PurchaseLedger.PurchaseInvoiceInstrumentFactory.Factory.CreateNew();

                invoice.SuppressExceedsCreditLimitException = true;
                invoice.Supplier     = Sage200Api.GetSupplierByPrimaryKey(supplierid);
                invoice.InstrumentNo = invoicenumber;

                invoice.InstrumentDate = DateTime.ParseExact(invoicedate, "MM/dd/yyyy hh:mm:ss", CultureInfo.InvariantCulture);

                invoice.NetValue = amount - taxamount;
                invoice.TaxValue = taxamount;

                invoice.Authorised = Sage.Accounting.AuthorisationTypeEnum.AuthorisationTypeNotRequired;

                // ADD IN THE LINE ITEMS - GLACCOUNT, DEPARTMENT, CLASSIFICATION (VAT Rate), LINE AMOUNT
                NominalAnalysisItem nominal = (Sage.Accounting.TradeLedger.NominalAnalysisItem)invoice.NominalAnalysisItems[0];
                TaxAnalysisItem     tax     = (Sage.Accounting.TradeLedger.TaxAnalysisItem)invoice.TaxAnalysisItems[0];

                bool first = true;

                foreach (LineItem lineitem in lineitems)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        nominal = (NominalAnalysisItem)invoice.NominalAnalysisItems.AddNew();
                        tax     = (TaxAnalysisItem)invoice.TaxAnalysisItems.AddNew();
                    }

                    // CREATE THE NOMINAL ANALYSIS
                    NominalCode nominalcode = Sage200Api.GetNominalCodeByPrimaryKey(lineitem.GLAccountID);
                    nominal.NominalSpecification = nominalcode.NominalSpecification;
                    nominal.Narrative            = lineitem.Description;
                    nominal.Amount = lineitem.NetAmount;

                    // CREATE THE VAT ANALYSIS
                    TaxCode taxcode = Sage200Api.GetVatRateByPrimaryKey(lineitem.ClassificationID);
                    tax.TaxCode   = taxcode;
                    tax.Goods     = lineitem.NetAmount;
                    tax.TaxAmount = lineitem.TaxAmount;
                }

                //
                invoice.Validate();
                invoice.Update();                 // NO WAY TO TELL IF THIS SUCCEEDS!
                newid = invoice.ActualPostedAccountEntry.PrimaryKey.DbValue.ToString();
            }
            catch (Exception ex)
            {
                newid = "";
                Logger.WriteLog(ex);
            }

            return(newid);
        }