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); }
// NEEDS TO BE CHECKED AGAINST API WHEN DOCS AVAILABLE public static TermRoot SagePaymentTermsToMTTerms(SageSupplier supplier) { TermRoot termroot = new TermRoot(); Term term = new Term(); term.id = ""; term.subsidiaries = null; term.discountPercent = supplier.EarlySettlementDiscountPercent; term.discountDays = supplier.EarlySettlementDiscountDays; term.dueDays = supplier.PaymentTermsDays; term.externalId = supplier.PrimaryKey.DbValue.ToString(); term.name = string.Format("Due Days: {0}, Discount Days: {0}, Discount Percent: {0}", supplier.PaymentTermsDays, supplier.EarlySettlementDiscountDays, supplier.EarlySettlementDiscountPercent); term.active = true; // ?? termroot.term = term; return(termroot); }
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); }
public static VendorRoot SageSupplierToMTVendor(SageSupplier supplier) { VendorRoot vendorroot = new VendorRoot(); Vendor vendor = new Vendor(); vendor.id = ""; vendor.externalId = supplier.PrimaryKey.DbValue.ToString(); vendor.form1099Enabled = false; vendor.name = supplier.Name; vendor.active = !supplier.OnHold; vendor.address = new Address { name = "", address1 = supplier.MainAddress.AddressLine1, address2 = supplier.MainAddress.AddressLine2, address3 = "", address4 = "", postalCode = supplier.MainAddress.PostCode, town = supplier.MainAddress.AddressLine3, ctrySubDivision = supplier.MainAddress.AddressLine4, country = supplier.MainAddress.Country }; vendor.legalName = supplier.Name; vendor.vendorType = "CORPORATION"; vendor.phones = new List <Phone>() { new Phone { number = supplier.MainTelephone, isFax = false }, new Phone { number = supplier.MainFax, isFax = true } }; vendor.fundingMethods = new List <FundingMethod>() { new FundingMethod() { type = "ACH", bankAccount = new BankAccount() { accountNumber = supplier.SupplierBanks.PrimaryBank.BankAccountReference, routingNumber = supplier.SupplierBanks.PrimaryBank.BankSortCode } } }; vendor.emails = new List <string>() { supplier.Contacts[0].Emails[0].Value }; Sage.Accounting.SystemManager.SYSTraderContactRole role = Sage.Accounting.SystemManager.SYSTraderContactRoleFactory.Factory.FetchSendRemittanceToRole(); Sage.Accounting.TradeLedger.TraderContact contact = supplier.GetPreferredContact(role); vendor.remittanceEmails = null; vendor.remittanceEnabled = false; if (contact.Emails[0].Value.Length > 0) { vendor.remittanceEmails = new List <string>() { contact.Emails[0].Value }; vendor.remittanceEnabled = true; } vendor.memo = ""; if (supplier.Memos.Count > 0) { vendor.memo = supplier.Memos[0].Note; // JUST USE THE FIRST MEMO } vendor.customerAccount = supplier.SupplierBanks.PrimaryBank.BankAccountReference; vendor.taxId = ""; vendor.vatNumber = supplier.TaxRegistrationCode; // VENDOR COMPANY DEFAULT IS NOT CURRENTLY SUPPORTED BY MT - EVEN THOUGH ITS IN THE DOCUMENTATION!!!! //vendor.vendorCompanyDefault = new VendorCompanyDefault(); vendorroot.vendor = vendor; return(vendorroot); }