コード例 #1
0
ファイル: Mapper.cs プロジェクト: Capco-Steve/SageConnector
        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);
        }
コード例 #2
0
ファイル: Mapper.cs プロジェクト: Capco-Steve/SageConnector
        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);
        }