public IList <Document> GetReceivingDocuments(string sWhere) { IList <Document> list = new List <Document>(); DocumentClass docClass = new DocumentClass(); Document tmpData = null; try { sWhere = string.IsNullOrEmpty(sWhere) ? "POSTATUS IN (1,2,3,4,5,6)" : "POSTATUS IN (1,2,3,4,5,6) AND " + sWhere; //Lamar los documents que necesita del Erp usando econnect ds = DynamicsGP_ec.GetDataSet(DynamicsGP_ec.RetreiveData("Purchase_Order_Transaction", false, 2, 0, sWhere, true)); if (ds.Tables.Count == 0) { return(null); } DocumentConcept docConcept = WType.GetDefaultConcept(new DocumentClass { DocClassID = SDocClass.Receiving }); DocumentType docType = WType.GetDocumentType(new DocumentType { DocTypeID = SDocType.PurchaseOrder }); //Status docStatus = WType.GetStatus(new Status { StatusID = DocStatus.New }); Account defAccount = WType.GetAccount(new Account { AccountCode = WmsSetupValues.DEFAULT }); SysUser user = WType.GetUser(new SysUser { UserName = WmsSetupValues.AdminUser }); Company company = CurCompany; //WType.GetDefaultCompany(); //Location location = WType.GetDefaultLocation(); //En el dataset, Tables: 1 - DocumentHeader, 2 - DocumentLine, 3 - DocumentComments foreach (DataRow dr in ds.Tables[1].Rows) { try { //Map Properties tmpData = new Document(); tmpData.Date1 = DateTime.Parse(dr["DOCDATE"].ToString()); tmpData.Date2 = DateTime.Parse(dr["PRMDATE"].ToString()); tmpData.Date3 = DateTime.Parse(dr["PRMSHPDTE"].ToString()); tmpData.Date4 = DateTime.Parse(dr["REQDATE"].ToString()); //tmpData.Date5 = DateTime.Parse(dr["DUEDATE"].ToString()); //USADA PARA NOtification en IMAGE tmpData.DocNumber = dr["PONUMBER"].ToString(); tmpData.DocStatus = GetReceivingStatus(int.Parse(dr["POSTATUS"].ToString())); tmpData.DocType = docType; tmpData.PickMethod = docType.PickMethod; tmpData.DocConcept = docConcept; try { tmpData.CustPONumber = dr["POPCONTNUM"].ToString(); } catch { } tmpData.LastChange = GetDocumentLastChange("POP10100", "PONUMBER", dr["PONUMBER"].ToString()); try { tmpData.Comment = GetDocumentNotesPurchase("", dr["COMMNTID"].ToString(), dr["PONUMBER"].ToString()); } catch { } tmpData.Vendor = WType.GetAccount( new Account { AccountCode = dr["VENDORID"].ToString(), BaseType = new AccountType { AccountTypeID = AccntType.Vendor }, Company = company }); //Vendor Account; tmpData.Customer = defAccount; tmpData.CreatedBy = dr["USER2ENT"].ToString(); try { tmpData.ShippingMethod = WType.GetShippingMethod(new ShippingMethod { ErpCode = dr["SHIPMTHD"].ToString(), Company = company }); } catch { } tmpData.IsFromErp = true; tmpData.CrossDocking = false; //tmpData.Location = WType.GetLocation(new Location { ErpCode = dr["LOCNCODE"].ToString(), Company = company }); //location; tmpData.Company = CurCompany; //Asignacion de Lines tmpData.DocumentLines = GetReceivingDocumentLines(tmpData, company, ds.Tables[2].Select("PONUMBER='" + dr["PONUMBER"].ToString() + "'")); if (tmpData.DocumentLines != null && tmpData.DocumentLines.Count > 0) { if (tmpData.Location == null) { tmpData.Location = tmpData.DocumentLines[0].Location; } list.Add(tmpData); } } catch (Exception ex) { ExceptionMngr.WriteEvent("GetReceiptDocuments: " + tmpData.DocNumber, ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection); } } //retornar la lista return(list); } catch (Exception ex) { ExceptionMngr.WriteEvent("GetReceiptDocuments", ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection); //throw; return(null); } }