private List <AM_SAP> getDivizionOrganization(Dictionary <string, string> openWith, string parentExternalCode, string organizationId) { try { RfcDestinationManager.RegisterDestinationConfiguration(new ZSMK_SAP_Config()); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } RfcDestination destination = RfcDestinationManager.GetDestination("RFC_EAH"); IRfcFunction function = null; string strDate = DateTime.Today.ToString("yyyyMMdd"); IFormatProvider culture = new System.Globalization.CultureInfo("ru-RU", true); string format = "yyyy-MM-dd"; List <AM_SAP> list = new List <AM_SAP>(); string prefix = ""; try { function = destination.Repository.CreateFunction("ZP_GET_OSP"); foreach (KeyValuePair <string, string> kvp in openWith) { function.SetValue(kvp.Key, kvp.Value); if (kvp.Key == "IM_WERKS") { prefix = kvp.Value; } } function.Invoke(destination); } catch (RfcBaseException e) { System.Diagnostics.Debug.WriteLine(e.ToString()); } if (function != null) { //Get the function table parameter COMPANYCODE_LIST IRfcTable codes = function.GetTable("PIT_OBJECTS"); if (codes.RowCount == 0) { System.Diagnostics.Debug.WriteLine("Данные не выбраны"); } else { //Iterate over all rows in the table COMPANYCODE_LIST DateTime dt = DateTime.MinValue; for (int i = 0; i < codes.RowCount; i++) { codes.CurrentIndex = i; AM_SAP amSap = new AM_SAP(); if (codes.GetString("OTYPE") == "P") { amSap.OBJID = "1111" + codes.GetString("OBJID").TrimStart('0'); } else { amSap.OBJID = prefix + codes.GetString("OBJID"); } amSap.SOBID = prefix + codes.GetString("SOBID"); amSap.OTYPE = codes.GetString("OTYPE"); amSap.PRIOX = codes.GetString("PRIOX"); amSap.PROZT = codes.GetDouble("PROZT"); dt = DateTime.MinValue; DateTime.TryParseExact(codes.GetString("SBEGDA"), format, culture, DateTimeStyles.AssumeLocal, out dt); amSap.SBEGDA = dt; amSap.SCLAS = codes.GetString("SCLAS"); dt = DateTime.MinValue; DateTime.TryParseExact(codes.GetString("SENDDA"), format, culture, DateTimeStyles.AssumeLocal, out dt); amSap.SENDDA = dt; amSap.SHORT = codes.GetString("SHORT"); amSap.STEXT = codes.GetString("STEXT"); amSap.LEV_HIE = codes.GetInt("LEV_HIE"); dt = DateTime.MinValue; DateTime.TryParseExact(codes.GetString("BEGDA"), format, culture, DateTimeStyles.AssumeLocal, out dt); amSap.BEGDA = dt; dt = DateTime.MinValue; DateTime.TryParseExact(codes.GetString("ENDDA"), format, culture, DateTimeStyles.AssumeLocal, out dt); amSap.ENDDA = dt; amSap.BUKRS = ""; amSap.PERNR = codes.GetString("PERNR"); amSap.R_01 = codes.GetString("R_01"); amSap.R_02 = codes.GetString("R_02"); amSap.R_03 = codes.GetString("R_03"); amSap.R_04 = codes.GetString("R_04"); amSap.R_05 = codes.GetString("R_05"); amSap.R_06 = codes.GetString("R_06"); amSap.R_07 = codes.GetString("R_07"); amSap.GESCH = codes.GetString("GESCH"); amSap.PERSK = codes.GetString("PERSK"); amSap.PERSG = codes.GetString("PERSG"); amSap.STRINF_ID = codes.GetString("STRINF_ID"); dt = DateTime.MinValue; DateTime.TryParseExact(codes.GetString("DATP"), format, culture, DateTimeStyles.AssumeLocal, out dt); amSap.DATP = dt; amSap.VERB = codes.GetString("VERB"); amSap.SHOPNUMBER = prefix; amSap.ISSHOP = false; if (amSap.SHORT == "EAH") { amSap.ISSHOP = true; amSap.SOBID = parentExternalCode; } dt = DateTime.MinValue; DateTime.TryParseExact(codes.GetString("BEGDA_D"), format, culture, DateTimeStyles.AssumeLocal, out dt); amSap.BEGDA_D = dt; dt = DateTime.MinValue; DateTime.TryParseExact(codes.GetString("ENDDA_D"), format, culture, DateTimeStyles.AssumeLocal, out dt); amSap.ENDDA_D = dt; amSap.MVZ = DataGlobals.MVZ_EVRAZRUDA_DIVIZION; amSap.MVZ_NAME = getMVZName(organizationId); list.Add(amSap); } } } return(list); }
public List <COMING_SAP> GetInvoice(Organization currentOrganization, StorageName currentStorage, ICriteriaRepository <Nomenclature> nomenRepository, ICriteriaRepository <NomGroup> nomGroupRepository, int DocTypeId, string docNumber, int docYear, string docDate, out string Message) { String INCOMING_RFC = ConfigurationManager.AppSettings["SAP_ERP_" + currentOrganization.Id]; RfcDestination destination = RfcDestinationManager.GetDestination(INCOMING_RFC); IRfcFunction function = null; List <COMING_SAP> list = new List <COMING_SAP>(); // string docDate = "01.01." + docYear; docDate = "01.01." + docYear; if (currentStorage == null) { currentStorage = new StorageName(); } try { function = destination.Repository.CreateFunction("BAPI_GOODSMVT_GETDETAIL"); function.SetValue("MATERIALDOCUMENT", docNumber); function.SetValue("MATDOCUMENTYEAR", docYear); function.Invoke(destination); } catch (RfcBaseException e) { Message = e.StackTrace; // Console.WriteLine(e.ToString()); } Dictionary <string, Nomenclature> MaterialName = new Dictionary <string, Nomenclature>(); Dictionary <string, string> NomenclatureGroupName = new Dictionary <string, string>(); Message = "OK"; IRfcStructure tableHeader = function.GetStructure("GOODSMVT_HEADER"); if (tableHeader.Count > 0) { if (tableHeader.GetString("DOC_DATE") != "0000-00-00") { docDate = tableHeader.GetString("DOC_DATE"); try { docDate = DateTime.ParseExact(docDate, "yyyy-MM-dd", new System.Globalization.CultureInfo("ru-RU", true)).ToString(DataGlobals.DATE_FORMAT_FULL_YEAR); } catch { } } } IRfcTable table = function.GetTable("GOODSMVT_ITEMS"); if (table.RowCount == 0) { IRfcTable retTable = function.GetTable("RETURN"); retTable.CurrentIndex = 0; Message = retTable.GetString("MESSAGE"); } else { for (int i = 0; i < table.RowCount; i++) { table.CurrentIndex = i; if ((table.GetString("PLANT") == "" + currentStorage.Plant) && (table.GetString("STGE_LOC") == "" + currentStorage.Externalcode)) { //if (getKnownMove(table.GetString("MOVE_TYPE"), currentStorage) != MoveType.Unknown) //{ COMING_SAP incomingSap = new COMING_SAP(i + 1); incomingSap.DocTypeId = DocTypeId; incomingSap.DocNumber = docNumber; //incomingSap.DocDate = "01.01." + docYear; incomingSap.DocDate = docDate; incomingSap.MaterialId = table.GetString("MATERIAL").TrimStart('0'); Nomenclature defValue = null; if (MaterialName.TryGetValue(incomingSap.MaterialId, out defValue)) { incomingSap.MATERIAL = defValue.Name; incomingSap.ExternalCode = defValue.ExternalCode; if (defValue.Growth != null) { incomingSap.GrowthId = defValue.Growth.Id; incomingSap.GrowthName = defValue.Growth.SizeNumber; } if (defValue.NomBodyPartSize != null) { incomingSap.SizeId = defValue.NomBodyPartSize.Id; incomingSap.SizeName = defValue.NomBodyPartSize.SizeNumber; } if (defValue.NomGroup != null) { incomingSap.NomGroupId = defValue.NomGroup.Id; incomingSap.NomGroupName = defValue.NomGroup.Name; incomingSap.IsWinter = defValue.NomGroup.IsWinter; } if (defValue.Sex != null) { incomingSap.SexId = defValue.Sex.Id; incomingSap.SexName = defValue.Sex.Name; } if (defValue.Unit != null) { incomingSap.UnitId = defValue.Unit.Id; incomingSap.UnitName = defValue.Unit.Name; } if (defValue.NomBodyPart != null) { incomingSap.NomBodyPartId = defValue.NomBodyPart.Id; incomingSap.NomBodyPartName = defValue.NomBodyPart.Name; } } else { Dictionary <string, object> queryParams = new Dictionary <string, object>(); queryParams.Add("Organization", currentOrganization); queryParams.Add("ExternalCode", incomingSap.MaterialId.TrimStart('0')); queryParams.Add("IsActive", true); // Nomenclature currentNomenclature = nomenRepository.FindOne(queryParams); IList <Nomenclature> currentNomenclatures = nomenRepository.GetByLikeCriteria(queryParams); Nomenclature currentNomenclature = null; if (currentNomenclatures.Count > 0) { currentNomenclature = currentNomenclatures[0]; } if (currentNomenclature != null) { // TODO: Требуется обновить группу номенклатуры из SAP? defValue = currentNomenclature; incomingSap.MATERIAL = defValue.Name; incomingSap.ExternalCode = defValue.ExternalCode; if (defValue.NomGroup != null) { incomingSap.NomGroupId = defValue.NomGroup.Id; incomingSap.NomGroupName = defValue.NomGroup.Name; incomingSap.IsWinter = defValue.NomGroup.IsWinter; } if (defValue.Sex != null) { incomingSap.SexId = defValue.Sex.Id; incomingSap.SexName = defValue.Sex.Name; } if (defValue.Unit != null) { incomingSap.UnitId = defValue.Unit.Id; incomingSap.UnitName = defValue.Unit.Name; } if (defValue.NomBodyPart != null) { incomingSap.NomBodyPartId = defValue.NomBodyPart.Id; incomingSap.NomBodyPartName = defValue.NomBodyPart.Name; } } else { //Группу из сапа пока не запрашиваю!!!! /* defValue = getMaterialName(destination, incomingSap.MaterialId); * if (NomenclatureGroupName.TryGetValue(incomingSap.NomrnclatureGroupId, out defStringValue)) * { * incomingSap.NomrnclatureGroupName = defStringValue; * } * else * { * defStringValue = getNomenclatureGroupName(destination, incomingSap.NomrnclatureGroupId); * incomingSap.NomrnclatureGroupName = defStringValue; * NomenclatureGroupName.Add(incomingSap.NomrnclatureGroupId, defStringValue); * }*/ if (Message == "OK") { Message = ""; } defValue = new Nomenclature(int.Parse(incomingSap.MaterialId)); String[] strArray = getMaterialName(destination, table.GetString("MATERIAL")); defValue.Name = strArray[0]; defValue.ExternalCode = strArray[1].TrimStart('0'); Message = Message + "Номенклатура: [" + incomingSap.MaterialId + "]" + defValue.Name + "не найдена.\n"; incomingSap.MATERIAL = defValue.Name; incomingSap.ExternalCode = incomingSap.MaterialId; queryParams.Clear(); queryParams.Add("Organization", currentOrganization); queryParams.Add("ExternalCode", strArray[1].TrimStart('0')); NomGroup nGroup = nomGroupRepository.FindOne(queryParams); if (nGroup != null) { incomingSap.NomGroupId = nGroup.Id; incomingSap.NomGroupName = nGroup.Name; incomingSap.IsWinter = nGroup.IsWinter; incomingSap.NomBodyPartId = nGroup.NomBodyPart.Id; incomingSap.NomBodyPartName = nGroup.NomBodyPart.Name; } incomingSap.SAPNomGroupId = strArray[1].TrimStart('0'); incomingSap.SAPNomGroupName = getNomenclatureGroupName(destination, strArray[1]); defValue.NomGroup = nGroup; } if (defValue != null) { MaterialName.Add(incomingSap.MaterialId, defValue); } } incomingSap.QUANTITY = (int)Math.Truncate(table.GetDouble("ENTRY_QNT")); incomingSap.UOM = table.GetString("ENTRY_UOM"); incomingSap.LC = table.GetString("AMOUNT_LC"); incomingSap.SV = table.GetString("AMOUNT_SV"); incomingSap.MoveType = table.GetString("MOVE_TYPE"); //NomenclatureInfo nInfo = getMaterialDetail(destination, incomingSap.MaterialId); list.Add(incomingSap); //} //else { // Message = table.GetString("MOVE_TYPE") + " вид движения не поддерживается!"; //} } } } return(list); }