public static TOTMASTR ConvertToWarehouseDTO(Container container, TOTMASTR totMastr, TotMastrActions currentTotMastrAction, TotMastrActions newTotMastrAction) { if (totMastr.ACTION != (short)currentTotMastrAction) { return(totMastr); } return(ConvertToWarehouseDTO(container, totMastr, newTotMastrAction)); }
public void UpdateManualShipments() { ControllerUtils.PreSync(false); try { EventNotificationClient.Instance.PostMessage(string.Format("{0}.{1}", MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name), IntegrationConfig.InstanceID, CategoryType.General, "Beginning manual shipment updates..."); IList <IntegrationSync> integrationSyncs = ShipIntegrationSyncAdapter.ReadFromShip(ShipIntegrationType.AccellosOneWarehouse); if (integrationSyncs == null || integrationSyncs.Count == 0) { return; } foreach (IntegrationSync integrationSync in integrationSyncs) { try { if (!integrationSync.ShipmentId.HasValue) { continue; } Shipment shipment = ShipShipmentAdapter.ReadFromShip((Guid)integrationSync.ShipmentId); if (shipment == null || shipment.AOSSStatus == null || (shipment.AOSSStatus.Id != (int)AOSSStatusID.Completed && shipment.AOSSStatus.Id != (int)AOSSStatusID.Void)) { continue; } EventNotificationClient.Instance.PostMessage(string.Format("{0}.{1}", MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name), IntegrationConfig.InstanceID, CategoryType.Data, string.Format("Updating manual shipping information for shipment number {0}...", shipment.ShipmentNumber), new Variable("shipment", IFUtils.SerializeToString(shipment))); List <TOTMASTR> totMastrsToUpdate = new List <TOTMASTR>(); foreach (Container container in shipment.Containers) // Build TOTMASTRs for Update { IList <TOTMASTR> currentTotMastrs = WarehouseToShipAdapter.ReadFromWarehouse(container.IdentityField, TotMastrActions.ShipmentDataSync, UniqueIdentifierType.CartonASN, true); if (currentTotMastrs == null || currentTotMastrs.Count == 0) { throw new Exception(string.Format("No TOTMASTR record for carton ASN {0} could be found!", container.IdentityField)); } if (shipment.AOSSStatus.Id == (int)AOSSStatusID.Completed) { totMastrsToUpdate.Add(ShipToWarehouseAdapter.ConvertToWarehouseDTO(container, currentTotMastrs[0], TotMastrActions.ShipmentComplete)); } else if (shipment.AOSSStatus.Id == (int)AOSSStatusID.Void) { totMastrsToUpdate.Add(ShipToWarehouseAdapter.ConvertToWarehouseDTO(container, currentTotMastrs[0], TotMastrActions.VoidComplete)); } } EventNotificationClient.Instance.PostMessage(string.Format("{0}.{1}", MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name), IntegrationConfig.InstanceID, CategoryType.Info, string.Format("Finished building updated TOTMASTR objects for shipment number {0}...", shipment.ShipmentNumber), new Variable("updatedTotMastrs", IFUtils.SerializeToString(totMastrsToUpdate))); foreach (TOTMASTR totMastrToUpdate in totMastrsToUpdate) // Write each TOTMASTR update { TOTMASTR updatedTotMastr = WarehouseTotMastrAdapter.WriteToWarehouse(totMastrToUpdate); EventNotificationClient.Instance.PostMessage(string.Format("{0}.{1}", MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name), IntegrationConfig.InstanceID, CategoryType.Data, string.Format("TOTMASTR record for shipment number {0} and carton ASN {1} updated...", shipment.ShipmentNumber, updatedTotMastr.CARTON_ASN), new Variable("updatedTotMastr", IFUtils.SerializeToString(updatedTotMastr))); } ShipIntegrationSyncAdapter.DeleteFromShip(integrationSync); // Delete IntegrationSync record from Ship EventNotificationClient.Instance.PostMessage(string.Format("{0}.{1}", MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name), IntegrationConfig.InstanceID, CategoryType.General, string.Format("Manual shipment updates for shipment number {0} complete!", shipment.ShipmentNumber)); } catch (Exception innerCatchEx) { EventNotificationClient.Instance.PostMessage(string.Format("{0}.{1}.Error", MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name), IntegrationConfig.InstanceID, CategoryType.Error, string.Format("Shipment ID {0} failed sending manual updates from Ship to Warehouse! IntegrationSync record will be deleted!", integrationSync.ShipmentId), new Variable("innerCatchEx", innerCatchEx)); ShipIntegrationSyncAdapter.DeleteFromShip(integrationSync); // Delete IntegrationSync record from Ship } } } catch (Exception outerCatchEx) { EventNotificationClient.Instance.PostMessage(string.Format("{0}.{1}.Error", MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name), IntegrationConfig.InstanceID, CategoryType.Error, "Manual update sync from Ship to Warehouse failed!", new Variable("outerCatchEx", outerCatchEx)); } finally { ControllerUtils.PostSync(false); } }
public static Container ConvertToShipDTO(TOTMASTR totMastr) { if (!string.IsNullOrWhiteSpace(totMastr.PALLET_ASN)) // Ship only needs to know about the pallet records if the given carton is on a pallet { return(null); } if ((totMastr.ACCUM_QTY == null || totMastr.ACCUM_QTY == 0) && (totMastr.ACTION != (short)TotMastrActions.PrePrintCartonLabel && totMastr.ACTION != (short)TotMastrActions.PreRateOrder)) // Don't send Ship records with no quantity associated, unless it is a pre-print or pre-rate { return(null); } Container container = new Container(); string ltlPackageType = null; WarehouseSyncClient warehouseSyncClient = WarehouseConnectionAdapter.GetNewWarehouseSyncClient(); try { #region Load External Data IList <TOTEDETL> totDetls = null; List <string> toteLabelsOnPallet = new List <string>() { totMastr.TOTLABEL }; if (!string.IsNullOrWhiteSpace(totMastr.IS_PALLET) && totMastr.IS_PALLET == "1") { IList <TOTMASTR> totMastrsOnPallet = warehouseSyncClient.FindAllTOTMASTRPaged(TOTMASTRHydration.None, string.Format("TOTMASTR.Where(item => item.PALLET_ASN == \"{0}\" && item.ACCUM_QTY > 0 && item.SHP_CNSLDT == \"{1}\")", totMastr.CARTON_ASN, totMastr.SHP_CNSLDT)); if (totMastrsOnPallet != null && totMastrsOnPallet.Count > 0) { toteLabelsOnPallet.AddRange(totMastrsOnPallet.Select(tmp => tmp.TOTLABEL).Distinct()); } } string totDetlQuery = "TOTEDETL.Where(item => "; foreach (string toteLabelOnPallet in toteLabelsOnPallet) { totDetlQuery += string.Format("item.TOTLABEL == \"{0}\" || ", toteLabelOnPallet); } totDetlQuery = totDetlQuery.Substring(0, totDetlQuery.Length - 4) + ")"; totDetls = warehouseSyncClient.FindAllTOTEDETLPaged(TOTEDETLHydration.None, string.Format("{0}.Take({1})", totDetlQuery, WarehouseIntegrationConfig.Instance.PageSize)); int i = 0; while (totDetls != null && totDetls.Count > 0) { i++; IList <TOTEDETL> remainingTotdetls = warehouseSyncClient.FindAllTOTEDETLPaged(TOTEDETLHydration.None, string.Format("{0}.Take({1}).Skip({2})", totDetlQuery, WarehouseIntegrationConfig.Instance.PageSize, (i * WarehouseIntegrationConfig.Instance.PageSize))); if (remainingTotdetls == null || remainingTotdetls.Count == 0) { break; } foreach (TOTEDETL remainingTotdetl in remainingTotdetls) { totDetls.Add(remainingTotdetl); } } #endregion #region ContainerOption container.ContainerOption = new ContainerOption(); container.ContainerOption.AdditionalHandling = (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("H")) ? true : false; container.ContainerOption.AdultSignatureRequired = (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("A")) ? true : false; container.ContainerOption.AppointmentDelivery = (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("D")) ? true : false; container.ContainerOption.DoNotSafeDrop = (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("1")) ? true : false; container.ContainerOption.ProofRequireSignatureAdult19 = (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("2")) ? true : false; container.ContainerOption.LeaveAtDoor = (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("3")) ? true : false; if (!string.IsNullOrWhiteSpace(totMastr.COD) && totMastr.COD == "C") { container.CODContainer = true; container.ContainerOption.CODAmount = totMastr.SHIP_COD; if (!string.IsNullOrWhiteSpace(totMastr.COD_PAY)) { container.ContainerOption.CODPaymentType = ShipXMLMapsAdapter.GetShipCODPaymentTypeCode(totMastr.COD_PAY); } } container.ContainerOption.DeliveryConfirmation = (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("C")) ? true : false; container.ContainerOption.FedExDirectSignatureRequired = (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("T")) ? true : false; if (!string.IsNullOrWhiteSpace(totMastr.IS_PALLET) && totMastr.IS_PALLET == "1") { container.ContainerOption.InnerPackageCount = warehouseSyncClient.FindAllTOTMASTRCount( string.Format("TOTMASTR.Where(item => item.PALLET_ASN == \"{0}\" && item.ACCUM_QTY > 0 && item.SHP_CNSLDT == \"{1}\")", totMastr.CARTON_ASN, totMastr.SHP_CNSLDT)); ltlPackageType = "Pallet"; } else { container.ContainerOption.InnerPackageCount = 1; ltlPackageType = "Carton"; } if (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("I")) { container.ContainerOption.InsuranceType = 1; container.TransmitDeclaredValue = true; } container.ContainerOption.SignatureRequired = (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("S")) ? true : false; #endregion #region ContainerReferenceFields container.ContainerReferenceFields = new ContainerReferenceFields() { ReferenceField1 = StringUtils.Left(totMastr.MESSAGE1, 50), ReferenceField2 = StringUtils.Left(totMastr.MESSAGE2, 50), ReferenceField3 = StringUtils.Left(totMastr.MESSAGE3, 50), ReferenceField4 = StringUtils.Left(totMastr.MESSAGE4, 50), ReferenceField5 = StringUtils.Left(totMastr.MESSAGE5, 50) }; #endregion container.DeclaredValueAmount = totMastr.SHIP_DV; container.DocumentNumber = StringUtils.Left(totMastr.PACKSLIP, 30); container.Height = totMastr.SHIP_HEIGHT; container.IdentityField = StringUtils.Left(totMastr.CARTON_ASN, 50); container.Length = totMastr.SHIP_LENGTH; #region PackageType if (totMastr.SHP_OPTION.Contains("F")) { container.PackageType = "LETTER"; } if (totMastr.SHP_OPTION.Contains("G")) { container.PackageType = "SBOX"; } if (totMastr.SHP_OPTION.Contains("K")) { container.PackageType = "MBOX"; } if (totMastr.SHP_OPTION.Contains("J")) { container.PackageType = "LBOX"; } if (totMastr.SHP_OPTION.Contains("X")) { container.PackageType = "BOX"; } if (totMastr.SHP_OPTION.Contains("N")) { container.PackageType = "USPSRRBA"; } if (totMastr.SHP_OPTION.Contains("O")) { container.PackageType = "USPSRRBB"; } if (totMastr.SHP_OPTION.Contains("P")) { container.PackageType = "USPSRRBC"; } if (totMastr.SHP_OPTION.Contains("U")) { container.PackageType = "PAK"; } if (totMastr.SHP_OPTION.Contains("V")) { container.PackageType = "MDEXBX"; } if (totMastr.SHP_OPTION.Contains("Y")) { container.PackageType = "LGEXBX"; } if (totMastr.SHP_OPTION.Contains("?")) { container.PackageType = "TUBE"; } if (totMastr.SHP_OPTION.Contains("!")) { container.PackageType = "FRE"; } if (totMastr.SHP_OPTION.Contains("Q")) { container.PackageType = "EXLGEXBX"; } if (totMastr.SHP_OPTION.Contains("$")) { container.PackageType = "SMEXBX"; } if (string.IsNullOrWhiteSpace(container.PackageType)) { container.PackageType = "CUSTOM"; } #endregion container.PONumber = StringUtils.Left(totMastr.CUST_ORDER, 50); container.Shippable = true; // Currently hard-coded since this is a "ship" integration as of today, not a "pack" integration if (totMastr.ACTION == (short)TotMastrActions.RateManifestShipment || totMastr.ACTION == (short)TotMastrActions.DeleteCarton) { if (ShipIntegrationConfig.Instance.UseLastMileTrackingNumber) { container.TrackingNumber = string.IsNullOrWhiteSpace(totMastr.CAPTUREDBC) ? StringUtils.Left(totMastr.TRACKTRACE, 50) : StringUtils.Left(totMastr.CAPTUREDBC, 50); } else { container.TrackingNumber = StringUtils.Left(totMastr.TRACKTRACE, 50); } } container.UOM = new UOM() { Name = StringUtils.Left(ShipIntegrationConfig.Instance.WeightUnitOfMeasure, 50) }; container.Weight = totMastr.WEIGHT == null || totMastr.WEIGHT == 0 ? ShipIntegrationConfig.Instance.DefaultContainerWeight : totMastr.WEIGHT; container.Width = totMastr.SHIP_WIDTH; #region AmazonItems, ContainerCIs, and LTLData if ((totDetls == null || totDetls.Count == 0) && totMastr.ACTION == (short)TotMastrActions.PreRateOrder) { LTLData ltlData = new LTLData() { CommodityClass = StringUtils.Left(ShipIntegrationConfig.Instance.ForcedPreRateCommodityClass, 50) }; container.LTLDatas.Add(ltlData); } foreach (TOTEDETL totDetl in totDetls) { IList <Config> configs = null; IList <ProdMstr> ciLTLProdMstrs = null; IList <CUBISCAN> cubiscans = null; ContainerCI containerCI = new ContainerCI(); LTLData ltlData = new LTLData(); #region Load External Data configs = warehouseSyncClient.FindAllConfigPaged(ConfigHydration.None, "Config.Where(item => item.ConfigKey.StartsWith(\"PACKSIZE_\"))"); ciLTLProdMstrs = warehouseSyncClient.FindProdMstrsBySearchCriteriaPaged(new ProdMstrsBySearchCriteria() { Extended = totDetl.EXTENDED }, ProdMstrHydration.None, 0, 1); cubiscans = warehouseSyncClient.FindAllCUBISCANPaged(CUBISCANHydration.None, string.Format("CUBISCAN.Where(item => item.PRODUCT == \"{0}\" && item.PACKSIZE == {1}).Take(1)", totDetl.PRODUCT, totDetl.PACKSIZE)); #endregion #region AmazonItems if (IsAmazonOrder(totMastr.SHP_OPTION)) { AmazonItem amazonItem = new AmazonItem(); amazonItem.Container = container; var pickDetls = warehouseSyncClient.FindAllPickDetlPaged(PickDetlHydration.None, string.Format("PickDet.Where(item => item.PackSlip == \"{0}\" && item.LineNumber == \"{1}\")", totDetl.PACKSLIP, totDetl.ORDER_SEQ)); if (pickDetls == null || pickDetls.Count == 0) { throw new Exception("One or more items on the shipment did not provide an Amazon item identifier!"); } if (ShipIntegrationConfig.Instance.AmazonAssumeBoxPerLine && pickDetls[0].IS_CMPN == "E") // This is a kit component, thus the kit parent needs looking up for the Amazon item ID { string[] splitKitLineNum = totDetl.ORDER_SEQ.Split('.'); // Kit component line numbers look like this: 1.001 string parentLineNum = splitKitLineNum[0]; // Putting this into a variable for code readability var parentPickDetls = warehouseSyncClient.FindAllPickDetlPaged(PickDetlHydration.None, string.Format("PickDet.Where(item => item.PackSlip == \"{0}\" && item.LineNumber == \"{1}\")", totDetl.PACKSLIP, parentLineNum)); if (parentPickDetls == null || parentPickDetls.Count == 0 || string.IsNullOrWhiteSpace(parentPickDetls[0].CustomerCrossReference)) { throw new Exception("One or more items on the shipment did not provide an Amazon item identifier!"); } amazonItem.ItemId = StringUtils.Left(parentPickDetls[0].CustomerCrossReference, 128); amazonItem.Quantity = parentPickDetls[0].QuantityPicked; } else // This is a regular item, not a kit { if (string.IsNullOrWhiteSpace(pickDetls[0].CustomerCrossReference)) { throw new Exception("One or more items on the shipment did not provide an Amazon item identifier!"); } amazonItem.ItemId = StringUtils.Left(pickDetls[0].CustomerCrossReference, 128); amazonItem.Quantity = totDetl.QTY; } container.AmazonItems.Add(amazonItem); } #endregion #region ContainerCI containerCI.Container = container; containerCI.CountryOfManufacture = StringUtils.Left(totDetl.CTRY_ORIG, 2); containerCI.HarmonizedTariffCode = StringUtils.Left(totDetl.TariffClass, 10); containerCI.Quantity = totDetl.QTY; containerCI.UnitValue = totDetl.SELL_PRICE; if (!string.IsNullOrWhiteSpace(totMastr.SHIP_VIA) && !string.IsNullOrWhiteSpace(totMastr.SHIP_SERVC) && (totMastr.SHIP_VIA.StartsWith("DHLGM") || totMastr.SHIP_VIA.StartsWith("DHLAMP") || totMastr.SHIP_VIA.StartsWith("GLOBEG"))) { containerCI.CIDescription = StringUtils.Left(string.Format("{0} - {1}", StringUtils.Left(totDetl.PRODUCT, 20), totDetl.DESCRIPT), 250); } else { containerCI.CIDescription = StringUtils.Left(totDetl.CommodityDescription, 250); } if (ciLTLProdMstrs != null && ciLTLProdMstrs.Count > 0) { containerCI.UnitWeight = ciLTLProdMstrs[0].Weight; if (totDetl.PACKSIZE.HasValue && configs != null && configs.Count > 0) { if (ciLTLProdMstrs[0].Size1 == totDetl.PACKSIZE && configs.Any(item => item.ConfigKey == "PACKSIZE_1")) { containerCI.QuantityUOM = StringUtils.Left(configs.Where(item => item.ConfigKey == "PACKSIZE_1").First().CValue, 10); } else if (ciLTLProdMstrs[0].Size2 == totDetl.PACKSIZE && configs.Any(item => item.ConfigKey == "PACKSIZE_2")) { containerCI.QuantityUOM = StringUtils.Left(configs.Where(item => item.ConfigKey == "PACKSIZE_2").First().CValue, 10); } else if (ciLTLProdMstrs[0].Size3 == totDetl.PACKSIZE && configs.Any(item => item.ConfigKey == "PACKSIZE_3")) { containerCI.QuantityUOM = StringUtils.Left(configs.Where(item => item.ConfigKey == "PACKSIZE_3").First().CValue, 10); } else if (ciLTLProdMstrs[0].Size4 == totDetl.PACKSIZE && configs.Any(item => item.ConfigKey == "PACKSIZE_4")) { containerCI.QuantityUOM = StringUtils.Left(configs.Where(item => item.ConfigKey == "PACKSIZE_4").First().CValue, 10); } else if (ciLTLProdMstrs[0].Size5 == totDetl.PACKSIZE && configs.Any(item => item.ConfigKey == "PACKSIZE_5")) { containerCI.QuantityUOM = StringUtils.Left(configs.Where(item => item.ConfigKey == "PACKSIZE_5").First().CValue, 10); } } } if (cubiscans != null && cubiscans.Count > 0) { containerCI.UnitWeight = cubiscans[0].WEIGHT; } container.ContainerCIs.Add(containerCI); #endregion #region LTLDatas ltlData.CommodityClassDescription = StringUtils.Left(totDetl.CommodityDescription, 100); ltlData.Container = container; ltlData.InnerPackageCount = 1; ltlData.PackageType = ltlPackageType; if (totMastr.ACTION == (short)TotMastrActions.PreRateOrder && !string.IsNullOrWhiteSpace(ShipIntegrationConfig.Instance.ForcedPreRateCommodityClass)) { ltlData.CommodityClass = StringUtils.Left(ShipIntegrationConfig.Instance.ForcedPreRateCommodityClass, 50); } else { ltlData.CommodityClass = StringUtils.Left(!string.IsNullOrWhiteSpace(totDetl.FreightClass) ? totDetl.FreightClass : ShipIntegrationConfig.Instance.DefaultCommodityClass, 50); } if (!string.IsNullOrWhiteSpace(totDetl.NMFCNumber)) { if (totDetl.NMFCNumber.Contains("-")) { string[] splitNMFC = totDetl.NMFCNumber.Split('-'); ltlData.NMFCCode = StringUtils.Left(splitNMFC[0], 50); ltlData.NMFCItemSub = StringUtils.Left(splitNMFC[1], 10); } else { ltlData.NMFCCode = StringUtils.Left(totDetl.NMFCNumber, 50); } } if (ciLTLProdMstrs != null && ciLTLProdMstrs.Count > 0) { //if (totDetls.Count > 1) // ltlData.Weight = ciLTLProdMstrs[0].Weight; //else // ltlData.Weight = container.Weight; if (ciLTLProdMstrs[0].Weight != null && totDetl.QTY != null) { ltlData.Weight = ciLTLProdMstrs[0].Weight * totDetl.QTY; } } container.LTLDatas.Add(ltlData); #endregion } #endregion } catch (Exception ex) { throw new Exception(ex.ToString()); } finally { if (warehouseSyncClient != null) { warehouseSyncClient.Close(); warehouseSyncClient = null; } } return(container); }
public static Shipment ConvertToShipDTO(TOTMASTR totMastr, IList <Container> containers) { #region Load External Data IList <PickHead> pickHeads = null; WarehouseSyncClient warehouseSyncClient = WarehouseConnectionAdapter.GetNewWarehouseSyncClient(); try { pickHeads = warehouseSyncClient.FindPickHeadsByCriteriaPaged(new PickHeadsByCriteria() { PACKSLIP = totMastr.PACKSLIP }, PickHeadHydration.None, 0, 1); } catch (Exception ex) { throw new Exception(ex.ToString()); } finally { if (warehouseSyncClient != null) { warehouseSyncClient.Close(); warehouseSyncClient = null; } } #endregion Shipment shipment = new Shipment(); shipment.AccountNumber = StringUtils.Left(totMastr.SHIP_ACCT, 50); shipment.BOLNumber = StringUtils.Left(totMastr.PICKUP_NUM, 50); #region Containers if (containers == null || containers.Count == 0) { throw new Exception(string.Format("There are no valid containers associated with Warehouse shipment {0}, so the shipment will not be sent to Ship!", totMastr.SHP_CNSLDT)); } shipment.ContainerCount = containers.Count; shipment.Containers = new List <Container>(containers); shipment.WeightUOM = StringUtils.Left(containers[0].UOM.Name, 10); foreach (Container container in containers) { container.Shipment = shipment; } #endregion shipment.DeliverBeforeDate = totMastr.DATE_REQD; if (containers[0].ContainerCIs != null && containers[0].ContainerCIs.Count > 0) { shipment.Description = StringUtils.Left(containers[0].ContainerCIs[0].CIDescription, 50); } shipment.DocumentNumber = StringUtils.Left(totMastr.PACKSLIP, 30); shipment.EmailAddresses = totMastr.E_MAIL; // varchar(max) shipment.IdentityField = StringUtils.Left(totMastr.SHP_CNSLDT, 255); shipment.IntegrationTypeId = (int)ShipIntegrationType.AccellosOneWarehouse; #region LTL Accessorials StringBuilder ltlAccessorials = new StringBuilder(); foreach (char shipOption in totMastr.SHP_OPTION.ToCharArray()) { string shipLTLAccessorial = ShipXMLMapsAdapter.GetShipLTLAccessorial(shipOption.ToString()); if (!string.IsNullOrWhiteSpace(shipLTLAccessorial)) { ltlAccessorials.AppendFormat("{0}||", shipLTLAccessorial); } } if (ltlAccessorials.Length > 0) { shipment.LtlAccessories = StringUtils.Left(ltlAccessorials.Remove(ltlAccessorials.Length - 2, 2).ToString(), 1024); } #endregion if (IsAmazonOrder(totMastr.SHP_OPTION)) { shipment.OrderId = StringUtils.Left(totMastr.CUST_ORDER, 30); } shipment.PaymentTerms = StringUtils.Left(ShipXMLMapsAdapter.GetShipPaymentTermsCode(string.IsNullOrWhiteSpace(totMastr.SHIP_PAY) ? string.Empty : totMastr.SHIP_PAY), 25); shipment.PrintCarrierLabel = true; // Currently always set to true shipment.ProNumber = StringUtils.Left(totMastr.SHIP_NUM, 50); shipment.ReasonForExport = StringUtils.Left(ShipIntegrationConfig.Instance.DefaultReasonForExport, 25); #region ReturnAddress if (WarehouseIntegrationConfig.Instance.UseCustomerAddressForReturns) { shipment.ReturnAddress = new ShipAddress(); shipment.ReturnAddress.Address1 = StringUtils.Left(totMastr.CUST_ADD1, 100); shipment.ReturnAddress.Address2 = StringUtils.Left(totMastr.CUST_ADD2, 100); shipment.ReturnAddress.Address3 = StringUtils.Left(totMastr.CUST_ADD3, 100); shipment.ReturnAddress.City = StringUtils.Left(totMastr.CUST_CITY, 50); shipment.ReturnAddress.Company = StringUtils.Left(totMastr.CUST_NAME, 50); shipment.ReturnAddress.Contact = StringUtils.Left(totMastr.CUST_ATTN, 100); shipment.ReturnAddress.State = StringUtils.Left(totMastr.CUST_PROV, 3); shipment.ReturnAddress.ZipCode = StringUtils.Left(totMastr.CUST_ZIP, 50); } else //if (!string.IsNullOrWhiteSpace(totMastr.CUST_NUM)) { shipment.ReturnAddress = ShipXMLMapsAdapter.GetShipAlternateReturnAddress(string.IsNullOrWhiteSpace(totMastr.CLIENTNAME) ? string.Empty : totMastr.CLIENTNAME, string.IsNullOrWhiteSpace(totMastr.CUST_NUM) ? string.Empty : totMastr.CUST_NUM); } #endregion #region Services if (!string.IsNullOrWhiteSpace(totMastr.SHIP_VIA))// && !string.IsNullOrWhiteSpace(totMastr.SHIP_SERVC)) { shipment.CarrierServiceCode = StringUtils.Left(string.Format("{0};{1}", totMastr.SHIP_VIA, totMastr.SHIP_SERVC), 50); shipment.CarrierServiceCode = shipment.CarrierServiceCode.EndsWith(";") ? shipment.CarrierServiceCode.Substring(0, shipment.CarrierServiceCode.Length - 1) : shipment.CarrierServiceCode; shipment.Services = new List <string>(); shipment.Services.Add(shipment.CarrierServiceCode); } #endregion #region Ship Date DateTime now = DateTime.Now; shipment.ShipDate = DateTime.SpecifyKind(totMastr.DATE_SHIP ?? now, DateTimeKind.Local); if (ShipIntegrationConfig.Instance.ShipDateCarrierWaiver && shipment.ShipDate < now) { shipment.ShipDate = DateTime.SpecifyKind(now, DateTimeKind.Local); } shipment.ShipDate = DateTime.SpecifyKind(shipment.ShipDate.Value.Date, DateTimeKind.Utc); #endregion shipment.ShipFromAddress = null; #region ShipmentLevelOptions shipment.ShipmentLevelOptions = new ShipmentLevelOptions(); if (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("5")) { shipment.ShipmentLevelOptions.AncillaryEndorsementType = (int)AncillaryEndorsementType.NoEndorsement; } else if (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("6")) { shipment.ShipmentLevelOptions.AncillaryEndorsementType = (int)AncillaryEndorsementType.CarrierLeaveIfNoResponse; } else if (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("7")) { shipment.ShipmentLevelOptions.AncillaryEndorsementType = (int)AncillaryEndorsementType.AddressServiceRequested; } else if (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("8")) { shipment.ShipmentLevelOptions.AncillaryEndorsementType = (int)AncillaryEndorsementType.ForwardingServiceRequested; } else if (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("9")) { shipment.ShipmentLevelOptions.AncillaryEndorsementType = (int)AncillaryEndorsementType.ReturnServiceRequested; } else if (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("0")) { shipment.ShipmentLevelOptions.AncillaryEndorsementType = (int)AncillaryEndorsementType.ChangeServiceRequested; } shipment.ShipmentLevelOptions.CurrencyCode = ShipIntegrationConfig.Instance.DefaultCurrencyCode; shipment.ShipmentLevelOptions.DeclaredValueCustoms = (double)shipment.Containers .Where(c => c.ContainerCIs != null && c.ContainerCIs.Count > 0) .SelectMany(c => c.ContainerCIs) .Sum(c => (c.UnitValue ?? 0m) * (c.Quantity ?? 0m)); shipment.ShipmentLevelOptions.DimensionUOM = ShipIntegrationConfig.Instance.DimensionUnitOfMeasure; shipment.ShipmentLevelOptions.InsideDelivery = (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("E")) ? true : false; shipment.ShipmentLevelOptions.IsAlcohol = (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("W")) ? true : false; if (shipment.ShipmentLevelOptions.IsAlcohol) { shipment.ShipmentLevelOptions.AlcoholRecipientType = 1; // 1 = Consumer } shipment.ShipmentLevelOptions.LiftgateDelivery = (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("L")) ? true : false; shipment.ShipmentLevelOptions.Residential = (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("R")) ? true : false; shipment.ShipmentLevelOptions.ReturnDeliveryMethod = (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("M")) ? 5 : 0; // 5 = print labels shipment.ShipmentLevelOptions.SaturdayDelivery = (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("B")) ? true : false; shipment.ShipmentLevelOptions.CardForPickup = (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("4")) ? true : false; // New 2.1 option - "Do Not Safe Drop" shipment.ShipmentLevelOptions. = (!string.IsNullOrWhiteSpace(totMastr.SHP_OPTION) && totMastr.SHP_OPTION.Contains("Q")) ? true : false; #endregion if (totMastr.ACTION.HasValue && totMastr.ACTION == (short)TotMastrActions.PreRateOrder) { shipment.ShipmentNumber = "PRERATE"; // For other actions, shipment number is auto-generated by Ship } else if (!string.IsNullOrWhiteSpace(totMastr.SHIPMENT)) { shipment.ShipmentNumber = totMastr.SHIPMENT; } #region ShipmentReferenceFields //shipment.ShipmentReferenceFields = new ShipmentReferenceFields(); //shipment.ShipmentReferenceFields.LocationReference = ""; #endregion shipment.Shipper = StringUtils.Left(string.IsNullOrWhiteSpace(totMastr.SHIPPER) ? ShipIntegrationConfig.Instance.DefaultShipper : totMastr.SHIPPER, 50); #region ShipToAddress if (!string.IsNullOrWhiteSpace(totMastr.SHIP_ADD1)) { shipment.ShipToAddress = new ShipAddress() { Address1 = StringUtils.Left(totMastr.SHIP_ADD1, 100), Address2 = StringUtils.Left(totMastr.SHIP_ADD2, 100), Address3 = StringUtils.Left(totMastr.SHIP_ADD3, 100), City = StringUtils.Left(totMastr.SHIP_CITY, 50), Company = StringUtils.Left(totMastr.SHIP_NAME, 50), Contact = StringUtils.Left(totMastr.SHIP_ATTN, 100), Country = StringUtils.Left(totMastr.SHIP_CNTRY, 50), EmailAddresses = totMastr.E_MAIL, // varchar(max) in Ship DB Phone = StringUtils.Left(totMastr.SHIP_TELNO, 50), State = StringUtils.Left(totMastr.SHIP_PROV, 3), ZipCode = StringUtils.Left(totMastr.SHIP_ZIP, 50) }; } #endregion shipment.ShipToHold = totMastr.ACTION.HasValue && totMastr.ACTION == (short)TotMastrActions.PrePrintCartonLabel ? true : false; #region ThirdPartyAddress if (!string.IsNullOrWhiteSpace(totMastr.BILL_ADD1)) { shipment.ThirdPartyAddress = new ShipAddress() { Address1 = StringUtils.Left(totMastr.BILL_ADD1, 100), Address2 = StringUtils.Left(totMastr.BILL_ADD2, 100), Address3 = StringUtils.Left(totMastr.BILL_ADD3, 100), City = StringUtils.Left(totMastr.BILL_CITY, 50), Company = StringUtils.Left(totMastr.BILL_NAME, 50), State = StringUtils.Left(totMastr.BILL_PROV, 3), ZipCode = StringUtils.Left(totMastr.BILL_ZIP, 50) }; } #endregion #region PickHead Mappings if (pickHeads != null && pickHeads.Count > 0) { if (WarehouseIntegrationConfig.Instance.UseCustomerAddressForReturns) { shipment.ReturnAddress.Country = StringUtils.Left(pickHeads[0].SHPR_CNTRY, 50); shipment.ReturnAddress.Phone = StringUtils.Left(pickHeads[0].BUS_TELNO, 50); } shipment.SenderEIN = StringUtils.Left(pickHeads[0].SHIPPER_EIN, 20); shipment.ShipToEIN = StringUtils.Left(pickHeads[0].SHIP_TO_EIN, 20); shipment.SpecialInstructions = string.Concat( pickHeads[0].INSTRUCT1 ?? string.Empty, " ", pickHeads[0].INSTRUCT2 ?? string.Empty, " ", pickHeads[0].INSTRUCT3 ?? string.Empty, " ", pickHeads[0].INSTRUCT4 ?? string.Empty, " ", pickHeads[0].INSTRUCT5 ?? string.Empty, " ", pickHeads[0].INSTRUCT6 ?? string.Empty, " ", pickHeads[0].INSTRUCT7 ?? string.Empty); shipment.SpecialInstructions = StringUtils.Left(shipment.SpecialInstructions, 250); if (shipment.ThirdPartyAddress != null) { shipment.ThirdPartyAddress.Country = StringUtils.Left(pickHeads[0].BILL_CNTRY, 50); } shipment.TrailerNumber = StringUtils.Left(pickHeads[0].TRAILER_NO, 50); if (!string.IsNullOrWhiteSpace(pickHeads[0].HANDLE)) { shipment.ShipmentKeywordXReves = new List <ShipmentKeywordXRef>(); shipment.ShipmentKeywordXReves.Add(new ShipmentKeywordXRef() { Keyword = new Keyword() { WordContent = pickHeads[0].HANDLE }, Shipment = shipment }); } } #endregion return(shipment); }
public static TOTMASTR ConvertToWarehouseDTO(Container container, TOTMASTR totMastr, TotMastrActions newTotMastrAction) { #region Label if (container.Labels != null && container.Labels.Count > 0) { IEnumerable <byte> labelImage = null; foreach (Label label in container.Labels) { labelImage = labelImage == null?Convert.FromBase64String(label.LabelBuffer) : labelImage.Concat(Convert.FromBase64String(label.LabelBuffer)); } totMastr.LABEL_IMAGE = ShipIntegrationConfig.Instance.UseBase64Labels ? Convert.ToBase64String(labelImage.ToArray()) : Encoding.UTF8.GetString(labelImage.ToArray()); } #endregion totMastr.ACTION = (short)newTotMastrAction; #region Shipment Costs if (container.Shipment.ShipmentCostDetails != null && container.Shipment.ShipmentCostDetails.Count > 0) { ShipmentCostDetail overriddenFreightCost = container.Shipment.ShipmentCostDetails.FirstOrDefault(c => c.Type == (int)CostDetailType.OverriddenFreightCost); ShipmentCostDetail listedFreightCost = container.Shipment.ShipmentCostDetails.FirstOrDefault(c => c.Type == (int)CostDetailType.ListedFreightCost); ShipmentCostDetail freightCost = null; if (overriddenFreightCost == null) // Standard logic { freightCost = container.Shipment.ShipmentCostDetails.FirstOrDefault(c => c.Type == (int)CostDetailType.TotalFreightCost); if (freightCost != null && listedFreightCost != null) { totMastr.CHRG_SHIP = ShipIntegrationConfig.Instance.PassOnFreightDiscount ? freightCost.Value : listedFreightCost.Value; } } else // Override logic { freightCost = overriddenFreightCost; totMastr.CHRG_SHIP = overriddenFreightCost.Value; } if (freightCost != null) { totMastr.BAS_CHARGE = freightCost.Value; totMastr.TOTAL_CHG = freightCost.Value; totMastr.EST_CHARGE = freightCost.Value; } } #endregion #region Carrier/Service if (container.Shipment.CarrierServiceCode.Contains(";")) { totMastr.CARRIER = container.Shipment.CarrierServiceCode.Substring(0, container.Shipment.CarrierServiceCode.IndexOf(";")); totMastr.CARR_SRVC = StringUtils.Left(container.Shipment.CarrierServiceCode.Substring(container.Shipment.CarrierServiceCode.IndexOf(";") + 1), 25); } else { totMastr.CARRIER = container.Shipment.CarrierServiceCode; totMastr.CARR_SRVC = string.Empty; } totMastr.CARRIER = StringUtils.Left(totMastr.CARRIER, 10); #endregion totMastr.DATE_SHIP = container.Shipment.ShipDate; totMastr.ERR_CODE = string.Empty; if (container.Shipment.ChildShipmentXRefChilds != null && container.Shipment.ChildShipmentXRefChilds.Count > 0) { totMastr.MASTER_BOL = StringUtils.Left(container.Shipment.ChildShipmentXRefChilds[0].Shipment.BOLNumber, 20); } totMastr.MAN_NUMBER = StringUtils.Left(container.Shipment.BOLNumber, 20); totMastr.SHIPFIELD1 = StringUtils.Left(container.ModifiedBy, 30); #region Tracking and Pro Number Handling totMastr.SHIP_NUM = StringUtils.Left(string.IsNullOrWhiteSpace(container.Shipment.ProNumber) ? container.Shipment.ShipmentNumber : container.Shipment.ProNumber, 22); if (newTotMastrAction == TotMastrActions.PreRateComplete) { totMastr.SHIP_NUM = string.Empty; } else if (newTotMastrAction == TotMastrActions.VoidComplete) { if (totMastr.SHIP_NUM == container.Shipment.ShipmentNumber) { totMastr.SHIP_NUM = string.Empty; } totMastr.SHIPMENT = string.Empty; totMastr.TRACKTRACE = container.Shipment.VoidId; } else { totMastr.SHIPMENT = StringUtils.Left(container.Shipment.ShipmentNumber, 22); if (string.IsNullOrWhiteSpace(container.TrackingNumber)) { totMastr.TRACKTRACE = container.Shipment.ProNumber; } else if (ShipIntegrationConfig.Instance.UseLastMileTrackingNumber && !string.IsNullOrWhiteSpace(container.LastMileTrackingNumber)) { totMastr.CAPTUREDBC = container.TrackingNumber; totMastr.TRACKTRACE = container.LastMileTrackingNumber; } else { totMastr.CAPTUREDBC = string.IsNullOrWhiteSpace(container.ReturnTrackingNumber) ? container.LastMileTrackingNumber : container.ReturnTrackingNumber; totMastr.TRACKTRACE = container.TrackingNumber; } } totMastr.CAPTUREDBC = StringUtils.Left(totMastr.CAPTUREDBC, 30); totMastr.TRACKTRACE = StringUtils.Left(totMastr.TRACKTRACE, 34); #endregion if (newTotMastrAction != TotMastrActions.PrePrintComplete) { if (WarehouseIntegrationConfig.Instance.UseContainerWeights) { totMastr.WEIGHT_PC = "1"; totMastr.WEIGHT_SHP = container.Weight; } else { totMastr.WEIGHT_SHP = container.Shipment.Containers.Sum(c => c.Weight ?? 0m); } } return(totMastr); }