Example #1
0
        public static bool UpdateInvoice(string invoiceid, string newsupplierid, string newinvoicenumber, string newinvoicedate, decimal newamount, decimal newtaxamount)
        {
            bool result = true;

            try
            {
                Sage.Accounting.PurchaseLedger.PostedPurchaseAccountEntry invoice = Sage200Api.GetInvoiceByPrimaryKey(invoiceid);

                // THESE ARE THE ONLY WRITABLE FIELDS
                invoice.InstrumentNo   = newinvoicenumber;
                invoice.InstrumentDate = DateTime.ParseExact(newinvoicedate, "MM/dd/yyyy hh:mm:ss", CultureInfo.InvariantCulture);

                // THESE FIELDS ARE READ ONLY
                //invoice.Supplier = SageApi.GetSupplierByPrimaryKey(supplierid);
                //invoice.NetValue = amount;
                //invoice.TaxValue = taxamount;
                //invoice.Authorised = Sage.Accounting.AuthorisationTypeEnum.AuthorisationTypeNotRequired;

                invoice.Validate();
                invoice.Update();                 // NO WAY TO TELL IF THIS SUCCEEDS!
            }
            catch (Exception ex)
            {
                result = false;
            }

            return(result);
        }
Example #2
0
        public static string CreatePayment(Supplier supplier, string bankid, string paymentdate, decimal netamount, decimal taxamount, string paymentreference)
        {
            string newid = "";

            try
            {
                if (Sage.Accounting.CashBook.CashBookModuleFactory.Factory.Fetch().Enabled)
                {
                    Sage.Accounting.PurchaseLedger.PurchaseBankPaymentInstrument payment = Sage.Accounting.PurchaseLedger.PurchaseBankPaymentInstrumentFactory.Factory.CreateNew();
                    payment.SuppressExceedsCreditLimitException = true;

                    // SET THE BANK
                    payment.Bank = Sage200Api.GetBankByPrimaryKey(bankid);

                    // SET THE SUPPLIER
                    payment.Supplier = supplier;

                    // REFERENCE
                    payment.InstrumentNo = paymentreference;

                    // SET THE RECEIPT DATE
                    payment.InstrumentDate = DateTime.ParseExact(paymentdate, "MM/dd/yyyy hh:mm:ss", CultureInfo.InvariantCulture);

                    // SET THE AMOUNTS
                    payment.NetValue = netamount;
                    payment.TaxValue = taxamount;

                    payment.Validate();

                    payment.Update();                     // NO WAY TO KNOW IF THIS SUCCEEDS OR NOT!
                    newid = payment.ActualPostedAccountEntry.PrimaryKey.DbValue.ToString();
                }
                else
                {
                    return("");
                }
            }
            catch (Exception ex)
            {
                newid = "";
                Logger.WriteLog(ex);
            }

            return(newid);
        }
Example #3
0
        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);
        }