private OrderDetail AddOrderDetail(OrderRequestDetail detail, EdiOrderLine ediDetail, OrderHeader header, double lineNumber, bool?partialshipments, JDEDataContext context) { OrderDetail orderDetail = new OrderDetail(); #region Default Values orderDetail.EDICompany = header.EDICompany; orderDetail.EDIDocumentType = header.EDIDocumentType; orderDetail.EDIDocumentNumber = header.EDIDocumentNumber; orderDetail.EDILineNumber = lineNumber; orderDetail.DocumentCompany = header.DocumentCompany; orderDetail.DocumentType = header.DocumentType; orderDetail.EDIMessageType = header.EDIMessageType; orderDetail.PaymentTerms = header.PaymentTerms; orderDetail.PaymentInstrument = header.PaymentInstrument; orderDetail.SubstitutesAllowed = header.SubstitutesAllowed; orderDetail.CarierNumber = header.CarrierNumber; orderDetail.RouteCode = header.RouteCode; orderDetail.ApplyFreight = header.ApplyFreight; orderDetail.ProgramID = header.ProgramID; orderDetail.UserID = header.UserID; orderDetail.EDIUserReference = header.EDIUserReference; orderDetail.CustomerReference = header.CustomerReference; #endregion if (detail != null) { orderDetail.QuantityOrdered = detail.Quantity; orderDetail.ProductID = int.Parse(detail.ProductIdentifier.ProductNumber); orderDetail.CustomerItemNumber = detail.VendorItemNumber; } if (ediDetail != null) { orderDetail.QuantityOrdered = ediDetail.Quantity; orderDetail.ProductID = double.Parse(ediDetail.EdiProductID); orderDetail.CustomerItemNumber = ediDetail.CustomerItemNumber; orderDetail.EDIOrderReference = ediDetail.EdiOrderLineID.ToString(); } orderDetail.Date = JulianDate.FromDate(System.DateTime.Now).Value; orderDetail.Time = double.Parse(System.DateTime.Now.ToString("HHmmss")); if (partialshipments.HasValue && partialshipments.Value) { orderDetail.PartialLineShipmentsAllowed = 'Y'; } orderDetail.BusinessUnit = "DC10".PadLeft(12); if (!string.IsNullOrEmpty(ediDetail.CompanyCode)) { string company = ediDetail.CompanyCode; string businessUnit = string.Empty; if (company.Contains("-")) { businessUnit = company.Split('-')[1]; company = company.Split('-')[0]; } if (!string.IsNullOrEmpty(ediDetail.WareHouseCode)) { orderDetail.Location = ediDetail.WareHouseCode; orderDetail.BusinessUnit = businessUnit.PadLeft(12); orderDetail.SZEMCU = company.PadLeft(12); } } return(orderDetail); }
public int ProcessOrderToVendor(EdiOrder order, ConnectorRelation ediRelation, Configuration config) { string company = ediRelation.EdiVendor.CompanyCode; string businessUnit = string.Empty; if (company.Contains("-")) { businessUnit = company.Split('-')[1]; company = company.Split('-')[0]; } string dcto = ediRelation.EdiVendor.DefaultDocumentType; #region CreateOrder using (JDEDataContext context = new JDEDataContext(ConfigurationManager.ConnectionStrings["JDE"].ConnectionString)) { if (order.isDropShipment.HasValue && order.isDropShipment.Value) { #region DropShipment Addresses address = new Addresses(); address.AdressType = '2'; address.MailingName = order.ShippedToCustomer.CustomerName; address.AddressLine1 = order.ShippedToCustomer.CustomerAddressLine1; address.AddressLine2 = order.ShippedToCustomer.CustomerAddressLine2; address.AddressLine3 = order.ShippedToCustomer.CustomerAddressLine3;; if (!string.IsNullOrEmpty(order.ShippedToCustomer.CustomerEmail)) { address.AddressLine4 = order.ShippedToCustomer.CustomerEmail; } address.ZIPCode = order.ShippedToCustomer.PostCode; address.City = order.ShippedToCustomer.City; if (!string.IsNullOrEmpty(order.ShippedToCustomer.Country)) { switch (order.ShippedToCustomer.Country) { case "Nederland": case "Nederlands": address.Country = "NL"; break; case "United Kingdom": address.Country = "UK"; break; default: address.Country = order.ShippedToCustomer.Country; break; } } //else // address.Country = shipToCustomer.Country; address.EDICompany = company; address.EDIDocumentType = dcto; address.EDIDocumentNumber = order.EdiRequestID; address.DocumentCompany = company; address.DocumentType = dcto; address.FileName = "F47011"; address.TransactionOriginator = ediRelation.EdiVendor.Name; address.UserID = ediRelation.EdiVendor.Name; address.ProgramID = "EDI"; address.Date = JulianDate.FromDate(System.DateTime.Now).Value; address.Time = double.Parse(System.DateTime.Now.ToString("HHmmss")); context.Addresses.InsertOnSubmit(address); #endregion } OrderHeader header = new OrderHeader(); header.EDICompany = company; header.EDIDocumentType = dcto; header.EDIDocumentNumber = order.EdiRequestID; header.DocumentCompany = company; header.DocumentType = dcto; header.BusinessUnit = businessUnit.PadLeft(12); header.IsProcessed = ' '; header.EDIMessageType = "850"; header.EDIOrderReference = order.EdiRequestID.ToString(); header.CustomerReference = JdeUtility.FilterValue(order.CustomerOrderReference, 25); header.EndCustomerReference = JdeUtility.FilterValue(order.WebSiteOrderNumber, 25); //header.SoldToNumber = (double)soldToCustomer.AddressBookNumber.Value; header.ShipToNumber = double.Parse(order.ShippedToCustomer.EANIdentifier); header.ParentNumber = 0; header.IsProcessed = ' '; if (order.RequestDate.HasValue) { header.RequestedDate = JulianDate.FromDate(order.RequestDate.Value).Value; } else { header.RequestedDate = JulianDate.FromDate(DateTime.Now.AddDays(1)).Value; } header.OrderedBy = ediRelation.EdiVendor.Name; header.OrderTakenBy = ediRelation.EdiVendor.OrderBy; header.TransactionOriginator = ediRelation.EdiVendor.Name; header.UserID = ediRelation.EdiVendor.Name; header.ProgramID = "EDI"; header.Date = JulianDate.FromDate(System.DateTime.Now).Value; header.Time = double.Parse(System.DateTime.Now.ToString("HHmmss")); if (!string.IsNullOrEmpty(order.HoldCode)) { header.EDIHoldCode = order.HoldCode; } if (order.BackOrdersAllowed.HasValue) { if (order.BackOrdersAllowed.Value) { header.BackordersAllowed = 'Y'; } } //if (order.OrderExpireDate != null) //{ // header.EDIExpireDate = JulianDate.FromDate(ediDocument.OrderHeader.OrderExpireDate).Value; //} #region Details double lineNumber = 1000; if (!string.IsNullOrEmpty(ediRelation.FreightProduct)) { OrderRequestDetail freightdetail = new OrderRequestDetail(); freightdetail.ProductIdentifier = new ProductIdentifier(); freightdetail.ProductIdentifier.ProductNumber = ediRelation.FreightProduct; freightdetail.Quantity = 1; header.OrderDetails.Add(AddOrderDetail(freightdetail, header, lineNumber, context)); lineNumber += 1000; } if (!string.IsNullOrEmpty(ediRelation.FinChargesProduct)) { OrderRequestDetail finChargesdetail = new OrderRequestDetail(); finChargesdetail.ProductIdentifier = new ProductIdentifier(); finChargesdetail.ProductIdentifier.ProductNumber = ediRelation.FinChargesProduct; finChargesdetail.Quantity = 1; header.OrderDetails.Add(AddOrderDetail(finChargesdetail, header, lineNumber, context)); lineNumber += 1000; } foreach (EdiOrderLine detail in order.EdiOrderLines) { OrderDetail orderDetail = AddOrderDetail(null, detail, header, lineNumber, order.PartialDelivery, context); if (orderDetail != null) { header.OrderDetails.Add(orderDetail); lineNumber += 1000; } } #endregion context.OrderHeaders.InsertOnSubmit(header); context.SubmitChanges(); return(-1); } #endregion }