Esempio n. 1
0
        private Document GetDocument(DataSets.Order.CalculatedOrdersRow row,
            DataSets.Order.CalculatedOrderDetailsDataTable detailDataTable,
            DataSets.Order.DeletedOrderDetailsDataTable deletedOrderDetailsDataTable,
            Token lastToken, NorthwindConfig config)
        {
            #region Declarations
            OrderDocument doc;
            string id;
            LogState logState = LogState.Updated;
            Document lineItemDoc;
            CountryCodes countryCodes = new CountryCodes();
            #endregion

            id = row.OrderID.ToString();

            if (lastToken.InitRequest)
                logState = LogState.Created;

            else if (row.IsCreateIDNull() || row.IsModifyIDNull()
                || row.IsCreateUserNull() || row.IsModifyUserNull())
                logState = LogState.Created;

            else if ((row.CreateID > lastToken.SequenceNumber)
                   && (row.CreateUser != config.CrmUser))
                logState = LogState.Created;

            else if ((row.CreateID == lastToken.SequenceNumber)
                && (row.CreateUser != config.CrmUser)
                && (id.CompareTo(lastToken.Id.Id) > 0))
                logState = LogState.Created;

            else if ((row.ModifyID >= lastToken.SequenceNumber) && (row.ModifyUser != config.CrmUser))
                logState = LogState.Updated;

            doc = new OrderDocument();
            doc.Id = id;
            doc.LogState = logState;

            doc.currency.Value = config.CurrencyCode;
            doc.pricinglistid.Value = Constants.DefaultValues.PriceList.ID;
            doc.reference.Value = id;

            if (row.IsCustomerIDNull())
                doc.accountid.Value = null;
            else
                doc.accountid.Value = Constants.CustomerIdPrefix + row.CustomerID;

            if (row.IsOrderDateNull())
                doc.opened.Value = null;
            else
                doc.opened.Value = row.OrderDate;

            if (row.IsShippedDateNull())
                doc.status.Value = Constants.OrderStatus.Active;
            else
                doc.status.Value = Constants.OrderStatus.Completed;

            //doc.DiscountPercentage.Value = new decimal(0);

            //doc.grossamt.Value = row.IsTotalQuotedPriceNull() ? new decimal(0) : Convert.ToDecimal(row.TotalQuotedPrice);
            doc.discountamt.Value = new decimal(0);
            doc.lineitemdisc.Value = row.IsDiscountAmountNull() ? new decimal(0) : Convert.ToDecimal(row.DiscountAmount);
            doc.nettamt.Value = row.IsTotalNetPriceNull() ? new decimal(0) : Convert.ToDecimal(row.TotalNetPrice);
            doc.freight.Value = row.IsFreightNull() ? new decimal(0) : row.Freight;

            doc.tax.Value = new decimal(0);
            doc.grossamt.Value = doc.nettamt.Value;

            if (row.IsRequiredDateNull())
                doc.deliverydate.Value = null;
            else
                doc.deliverydate.Value = row.RequiredDate;
            if (row.IsEmployeeIDNull())
                doc.salesrepr.Value = null;
            else
                doc.salesrepr.Value = Convert.ToString(row.EmployeeID);

            if (row.IsShipViaNull())
                doc.shippedvia.Value = null;
            else
                doc.shippedvia.Value = row.ShipVia;

            OrderAddress orderAddress = new OrderAddress();
            orderAddress.SetNorthwindAddress(row.IsShipAddressNull() ? "" : row.ShipAddress,
                row.IsShipCityNull() ? "" : row.ShipCity,
                row.IsShipPostalCodeNull() ? "" : row.ShipPostalCode,
                row.IsShipCountryNull() ? "" : row.ShipCountry);

            doc.shipaddress.Value = orderAddress.CrmOrderAddress;

            foreach (DataSets.Order.CalculatedOrderDetailsRow detailRow in detailDataTable.Rows)
            {
                lineItemDoc = GetDocumentLineItem(detailRow, lastToken, config);
                if ((doc.LogState != LogState.Created) && (lineItemDoc.HasNoLogStatus))
                    continue;

                doc.orderitems.Add(lineItemDoc);
            }

            foreach (DataSets.Order.DeletedOrderDetailsRow deletedRow in deletedOrderDetailsDataTable.Rows)
            {
                lineItemDoc = new LineItemDocument();
                lineItemDoc.Id = deletedRow[0].ToString();
                lineItemDoc.LogState = LogState.Deleted;
                doc.orderitems.Add(lineItemDoc);
            }

            return doc;
        }
Esempio n. 2
0
        private SalesOrderPayload GetPayload(DataSets.Order.CalculatedOrdersRow row,
            DataSets.Order.CalculatedOrderDetailsDataTable detailDataTable,
            //DataSets.Order.DeletedOrderDetailsDataTable deletedOrderDetailsDataTable,
            NorthwindConfig config)
        {
            #region Declarations
            SalesOrderPayload payload;
            string id;
            CountryCodes countryCodes = new CountryCodes();
            #endregion

            id = row.OrderID.ToString();

            payload = new SalesOrderPayload();
            payload.LocalID = id;
            payload.SyncUuid = GetUuid(id, "", SupportedResourceKinds.salesOrders);
            payload.SalesOrdertype.active = true;
            payload.SalesOrdertype.applicationID = id;

            payload.SalesOrdertype.currency = config.CurrencyCode;

            payload.ForeignIds.Add("pricelist", Sage.Integration.Northwind.Application.API.Constants.DefaultValues.PriceList.ID);

            if (!row.IsCustomerIDNull())
                payload.ForeignIds.Add("tradingAccount", Sage.Integration.Northwind.Application.API.Constants.CustomerIdPrefix + row.CustomerID);

            if (!row.IsOrderDateNull())
            {
                payload.SalesOrdertype.date = row.OrderDate;
                payload.SalesOrdertype.dateSpecified = true;
            }

            payload.SalesOrdertype.lineCountSpecified = true;
            payload.SalesOrdertype.lineCount = detailDataTable.Rows.Count;

            payload.SalesOrdertype.discountTotalSpecified = true;
            payload.SalesOrdertype.discountTotal = row.IsDiscountAmountNull() ? new decimal(0) : Convert.ToDecimal(row.DiscountAmount);

            payload.SalesOrdertype.netTotalSpecified = true;
            payload.SalesOrdertype.netTotal = row.IsTotalNetPriceNull() ? new decimal(0) : Convert.ToDecimal(row.TotalNetPrice);

            payload.SalesOrdertype.carrierTotalPriceSpecified = true;
            payload.SalesOrdertype.carrierTotalPrice = row.IsFreightNull() ? new decimal(0) : row.Freight;

            payload.SalesOrdertype.grossTotalSpecified = true;
            payload.SalesOrdertype.grossTotal = payload.SalesOrdertype.netTotal;

            if (!row.IsRequiredDateNull())
            {
                payload.SalesOrdertype.dueDateSpecified = true;
                payload.SalesOrdertype.dueDate = row.RequiredDate;
            }

            if (!row.IsShipViaNull())
            {
                payload.SalesOrdertype.deliveryMethod = row.ShipVia.ToString(); ;
            }

            postalAddresstype address = new postalAddresstype();
            address.active = true;
            address.activeSpecified = true;
            address.address1 = row.IsShipAddressNull() ? "" : row.ShipAddress;
            address.applicationID = id;
            address.country = row.IsShipCountryNull() ? "" : row.ShipCountry;
            address.townCity = row.IsShipCityNull() ? "" : row.ShipCity;
            address.zipPostCode = row.IsShipPostalCodeNull() ? "" : row.ShipPostalCode;
            address.type = postalAddressTypeenum.Shipping;

            payload.SalesOrdertype.postalAddresses = new postalAddresstype[1];
            payload.SalesOrdertype.postalAddresses[0] = address;

            payload.SalesOrdertype.salesOrderLines = new salesOrderLinetype[detailDataTable.Rows.Count];
            int index = 0;
            foreach (DataSets.Order.CalculatedOrderDetailsRow detailRow in detailDataTable.Rows)
            {
                SalesOrderLinePayload soPayload = GetLineItem(detailRow, config);
                payload.ForeignIds.Add(
                            String.Format("salesOrderLines[{0}]",
                            index.ToString()),
                            soPayload.LocalID);
                foreach (string key in soPayload.ForeignIds.Keys)//  (int foreignIdIndex = 0; foreignIdIndex <= soPayload.ForeignIds.Count; foreignIdIndex++)
                {
                    string value;
                    if (soPayload.ForeignIds.TryGetValue(key, out value))
                    {
                        payload.ForeignIds.Add(
                            String.Format("salesOrderLines[{0}]/{1}",
                            index.ToString(),
                            key),
                            value);
                    }
                }
                payload.SalesOrdertype.salesOrderLines[index] = soPayload.SalesOrderLinetype;
                index++;
            }

            //foreach (DataSets.Order.DeletedOrderDetailsRow deletedRow in deletedOrderDetailsDataTable.Rows)
            //{
            //    lineItemDoc = new LineItemDocument();
            //    lineItemDoc.Id = deletedRow[0].ToString();
            //    lineItemDoc.LogState = LogState.Deleted;
            //    doc.orderitems.Add(lineItemDoc);
            //}

            return payload;
        }