示例#1
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);
        }
示例#2
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);
        }
示例#3
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);
        }