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); }
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 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 BillCreditRoot SageCreditNoteToMTBillCredit(string companyid, PostedPurchaseAccountEntry creditnote, string sessiontoken) { BillCreditRoot billcreditroot = new BillCreditRoot(); BillCredit billcredit = new BillCredit(); billcredit.transactionDate = creditnote.InstrumentDate.ToString("yyyy-MM-dd"); billcredit.amountApplied = new Amount() { amount = PriceConverter.FromDecimal(Math.Abs(creditnote.DocumentGrossValue), 2), precision = 2 }; billcreditroot.billCredit = billcredit; return(billcreditroot); }
public static CreditRoot SageCreditNoteToMTCredit(string companyid, PostedPurchaseAccountEntry creditnote, string sessiontoken) { CreditRoot creditroot = new CreditRoot(); Credit credit = new Credit(); credit.id = ""; credit.externalId = creditnote.PrimaryKey.DbValue.ToString(); credit.creditNumber = creditnote.SecondReferenceNo; // THIS WILL BE THE INVOICE NUMBER credit.transactionDate = creditnote.InstrumentDate.ToString("yyyy-MM-dd"); // GET THE VENDOR ID FROM MINERAL TREE Vendor vendor = MTApi.GetVendorByExternalID(companyid, sessiontoken, creditnote.Supplier.PrimaryKey.DbValue.ToString()); if (vendor == null) { return(null); } credit.vendor = new ObjID() { id = vendor.id }; credit.amount = new Amount() { amount = PriceConverter.FromDecimal(Math.Abs(creditnote.DocumentGrossValue), 2), precision = 2 }; credit.status = "Open"; if (creditnote.MemoNotes.Count > 0) { credit.memo = creditnote.MemoNotes[0].Note; // JUST USE THE FIRST MEMO } else { credit.memo = ""; } creditroot.credit = credit; return(creditroot); }
public static Sage.Accounting.PurchaseLedger.PostedPurchaseAccountEntry GetInvoiceByInvoiceNumber(string invoicenumber) { Sage.Accounting.PurchaseLedger.PostedPurchaseAccountEntry result = null; if (application != null) { // 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); invoices.Find(query); result = invoices.First; } return(result); }
public static BillRoot SageInvoiceToMTBill(string companyid, PostedPurchaseAccountEntry invoice, string sessiontoken) { BillRoot billroot = new BillRoot(); Bill bill = new Bill(); bill.id = ""; bill.externalId = invoice.PrimaryKey.DbValue.ToString(); bill.dueDate = invoice.DueDate.ToString("yyyy-MM-dd"); bill.transactionDate = invoice.InstrumentDate.ToString("yyyy-MM-dd"); //?? bill.invoiceNumber = invoice.InstrumentNo; // THIS IS REFERENCE IN SAGE UI (INVOICE SCREEN) bill.amount = new Amount() { amount = PriceConverter.FromDecimal(invoice.CoreDocumentGrossValue, 2), precision = 2 }; bill.balance = new Amount() { amount = 0 }; // ??? bill.totalTaxAmount = new Amount() { amount = PriceConverter.FromDecimal(invoice.CoreDocumentTaxValue, 2), precision = 2 }; // NOT POSSIBLE TO ADD LINE ITEMS BECAUSE SAGE SPLITS TRANSACTIONS INTO 2, VAT AND GLCODE/GOODSAMOUNT AND THEY ARE NOT RELATED // NOMINAL ANALYSIS /* * bill.items = new List<CompanyItem>(); * * int count = invoice.TradingTransactionDrillDown.NominalEntries.Count(); * foreach (Sage.Accounting.NominalLedger.NominalAccountEntryView view in invoice.TradingTransactionDrillDown.NominalEntries) * { * CompanyItem ci = new CompanyItem(); * ci.glAccount = MTReferenceData.FindGlAccountByAccountNumber(view.AccountNumber); * ci.netAmount = new Amount() { amount = PriceConverter.FromDecimal(view.GoodsValueInBaseCurrency, 2), precision = 2 }; * ci.taxAmount = new Amount() { amount = 0, precision = 2 }; * * bill.items.Add(ci); * * // CREATE THE NOMINAL ANALYSIS * * //NominalCode nominalcode = SageApi.GetNominalCodeByPrimaryKey(lineitem.GLAccountID); * //nominal.NominalSpecification = nominalcode.NominalSpecification; * //nominal.Narrative = lineitem.Description; * //nominal.Amount = lineitem.NetAmount; * * // CREATE THE VAT ANALYSIS * //TaxCode taxcode = SageApi.GetVatRateByPrimaryKey(lineitem.ClassificationID); * //tax.TaxCode = taxcode; * //tax.Goods = lineitem.NetAmount; * //tax.TaxAmount = lineitem.TaxAmount; * } * * // TAX/VAT ANALYSIS * /* * foreach (Sage.Accounting.TaxModule.Views.TaxAccountEntryView view in invoice.TradingTransactionDrillDown.TaxEntries) * { * CompanyItem ci = new CompanyItem(); * //view.GoodsAmount; * //view.TaxAmount; * //view.TaxRate; * //view. * } * // */ if (invoice.MemoNotes.Count > 0) { bill.memo = invoice.MemoNotes[0].Note; // JUST USE THE FIRST MEMO } else { bill.memo = ""; } bill.poNumber = ""; // ?? bill.state = EnumMapper.SageDocumentStatusEnumToMTState(invoice.DocumentStatus); // GET THE VENDOR ID FROM MINERAL TREE Vendor vendor = MTApi.GetVendorByExternalID(companyid, sessiontoken, invoice.Supplier.PrimaryKey.DbValue.ToString()); if (vendor == null) { return(null); } bill.vendor = new ObjID() { id = vendor.id }; bill.expenses = null; bill.items = null; billroot.bill = bill; return(billroot); }