Exemple #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);
        }
Exemple #2
0
        private SalesInvoicePayload GetPayload(DataSets.Order.CalculatedOrdersRow row,
                                               DataSets.Order.CalculatedOrderDetailsDataTable detailDataTable,
                                               //DataSets.Order.DeletedOrderDetailsDataTable deletedOrderDetailsDataTable,
                                               NorthwindConfig config)
        {
            #region Declarations
            SalesInvoicePayload payload;
            string       id;
            CountryCodes countryCodes = new CountryCodes();
            #endregion

            id = row.OrderID.ToString();

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

            payload.SalesInvoicetype.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.SalesInvoicetype.date          = row.OrderDate;
                payload.SalesInvoicetype.dateSpecified = true;
            }

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

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

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

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

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



            if (!row.IsRequiredDateNull())
            {
                payload.SalesInvoicetype.deliveryDateSpecified = true;
                payload.SalesInvoicetype.deliveryDate          = row.RequiredDate;
            }



            if (!row.IsShipViaNull())
            {
                payload.SalesInvoicetype.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.SalesInvoicetype.postalAddresses    = new postalAddresstype[1];
            payload.SalesInvoicetype.postalAddresses[0] = address;


            payload.SalesInvoicetype.salesInvoiceLines = new salesInvoiceLinetype[detailDataTable.Rows.Count];
            int index = 0;
            foreach (DataSets.Order.CalculatedOrderDetailsRow detailRow in detailDataTable.Rows)
            {
                SalesInvoiceLinePayload soPayload = GetLineItem(detailRow, config);
                payload.ForeignIds.Add(
                    String.Format("salesInvoiceLines[{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("salesInvoiceLines[{0}]/{1}",
                                          index.ToString(),
                                          key),
                            value);
                    }
                }
                payload.SalesInvoicetype.salesInvoiceLines[index] = soPayload.SalesInvoiceLinetype;
                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);
        }