Ejemplo n.º 1
0
        /*
         * public static TermRoot SagePaymentTermsToMTTerms(Tuple<decimal, int, int> terms)
         * {
         *      TermRoot termroot = new TermRoot();
         *      Term term = new Term();
         *
         *      term.id = "";
         *      term.subsidiaries = null;
         *      term.discountPercent = terms.Item1;
         *      term.discountDays = terms.Item2;
         *      term.dueDays = terms.Item3;
         *      term.externalId = string.Format("{0}-{1}-{2}", terms.Item1, terms.Item2, terms.Item3);
         *      term.name = string.Format("Due Days: {0}", terms.Item3);
         *      term.active = true;
         *
         *      termroot.term = term;
         *      return termroot;
         * }
         */

        #endregion

        #region BANK ACCOUNT / PAYMENT METHOD

        public static PaymentMethodRoot SageBankAccountToMTPaymentMethod(Bank bank)
        {
            PaymentMethodRoot methodroot = new PaymentMethodRoot();
            PaymentMethod     method     = new PaymentMethod();

            method.id         = "";
            method.type       = "ACH";
            method.externalId = bank.PrimaryKey.DbValue.ToString();
            method.active     = true;         // NO MATCHING FIELD IN SAGE

            BankAccount bankaccount = new BankAccount()
            {
                name           = bank.Name,
                accountNumber  = bank.BankAccount.BankAccountNumber,
                accountBalance = new AccountBalance()
                {
                    availableBalance = new AvailableBalance()
                    {
                        amount = PriceConverter.FromDecimal(bank.BankAccount.BaseCurrencyBalance, 2)
                    }
                }
            };

            method.bankAccount = bankaccount;

            methodroot.paymentMethod = method;
            return(methodroot);
        }
Ejemplo n.º 2
0
        public static ItemRoot SageStockItemToMTItem(SageStockItem sagestockitem)
        {
            ItemRoot itemroot = new ItemRoot();
            Item     item     = new Item();

            item.id     = "";
            item.active = sagestockitem.StockItemStatus == Sage.Accounting.Stock.StockItemStatusEnum.EnumStockItemStatusTypeActive ? true : false;

            item.externalId = sagestockitem.PrimaryKey.DbValue.ToString();
            item.name       = sagestockitem.Name;
            item.type       = "INVENTORY";       // ???

            Cost cost = new Cost()
            {
                amount    = PriceConverter.FromDecimal(sagestockitem.PriceBands[0].StockItemPrices[0].Price, 2),
                precision = 2
            };

            item.cost = cost;

            Residual residual = new Residual()
            {
                amount = 0                 // ???
            };

            item.residual = residual;

            itemroot.item = item;
            return(itemroot);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        public static PurchaseOrderRoot SagePurchaseOrderToMTPurchaseOrder(string companyid, POPOrder poporder, string sessiontoken)
        {
            PurchaseOrderRoot purchaseorderroot = new PurchaseOrderRoot();
            PurchaseOrder     purchaseorder     = new PurchaseOrder();

            purchaseorder.id         = "";
            purchaseorder.externalId = poporder.PrimaryKey.DbValue.ToString();

            // GET THE VENDOR ID FROM MINERAL TREE
            Vendor vendor = MTApi.GetVendorByExternalID(companyid, sessiontoken, poporder.Supplier.PrimaryKey.DbValue.ToString());

            if (vendor == null)
            {
                return(null);
            }
            purchaseorder.vendor = new ObjID()
            {
                id = vendor.id
            };

            purchaseorder.dueDate  = poporder.DocumentDate.ToString("yyyy-MM-dd");
            purchaseorder.poNumber = poporder.DocumentNo;
            purchaseorder.memo     = "";
            purchaseorder.state    = "PendingBilling";
            purchaseorder.poType   = "Standard";

            // PURCHASE ORDER ITEMS
            List <PurchaseOrderItem> items = new List <PurchaseOrderItem>();
            int linenumber = 1;

            foreach (Sage.Accounting.POP.POPOrderReturnLine line in poporder.Lines)
            {
                PurchaseOrderItem item = new PurchaseOrderItem();

                //
                // FIGURE OUT THE MT ID OF THE LINE ITEM
                SageStockItem ssi = Sage200Api.GetStockItemByCode(line.ItemCode);
                if (ssi != null)
                {
                    Item mtitem = MTApi.GetItemByExternalID(companyid, sessiontoken, ssi.PrimaryKey.DbValue.ToString());
                    if (mtitem != null)
                    {
                        item.companyItem = new ObjID()
                        {
                            id = mtitem.id
                        };
                    }
                }
                //

                item.name     = line.LineDescription;
                item.quantity = new Quantity()
                {
                    value = PriceConverter.FromDecimal(line.LineQuantity, 2), precision = 2
                };
                item.quantityReceived = new Quantity()
                {
                    value = 1, precision = 0
                };                                                                                   // no value in sage
                item.billedQuantity = new Quantity()
                {
                    value = PriceConverter.FromDecimal(line.LineQuantity, 2), precision = 2
                };

                item.cost = new Cost()
                {
                    amount    = PriceConverter.FromDecimal(line.UnitBuyingPrice, 2),
                    precision = 2
                };

                item.amountDue = new Amount()
                {
                    amount    = PriceConverter.FromDecimal(line.LineTotalValue, 2),
                    precision = 2
                };

                item.lineNumber   = linenumber;      // no value in sage
                item.closed       = false;           // no value in sage
                item.description  = line.ItemDescription;
                item.poItemStatus = "New";

                items.Add(item);
                linenumber++;
            }

            purchaseorder.items = items;

            purchaseorderroot.purchaseOrder = purchaseorder;
            return(purchaseorderroot);
        }