public IList <Document> GetShippingDocuments(string sWhere, int docType, bool useRemain)
        {
            IList <Document> list     = new List <Document>();
            DocumentClass    docClass = new DocumentClass();
            Document         tmpData  = null;
            string           pos      = "0";


            try
            {
                sWhere             = "";
                Command.Connection = new SqlConnection(CurCompany.ErpConnection.CnnString);

                Query = GetErpQuery("SALESORDER");

                //Console.WriteLine(Query);

                DataSet ds = ReturnDataSet(Query, null, "SALESORDER", Command.Connection);


                pos = "1";


                if (ds.Tables.Count == 0)
                {
                    return(null);
                }


                DocumentConcept docConcept = WType.GetDefaultConcept(new DocumentClass {
                    DocClassID = SDocClass.Shipping
                });

                //Definiendo los tipos de documento de shipping
                DocumentType soType = WType.GetDocumentType(new DocumentType {
                    DocTypeID = SDocType.SalesOrder
                });
                DocumentType siType = WType.GetDocumentType(new DocumentType {
                    DocTypeID = SDocType.SalesInvoice
                });
                DocumentType bkType = WType.GetDocumentType(new DocumentType {
                    DocTypeID = SDocType.BackOrder
                });
                DocumentType returnType = WType.GetDocumentType(new DocumentType {
                    DocTypeID = SDocType.Return
                });


                //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();
                Status  cancelled = WType.GetStatus(new Status {
                    StatusID = DocStatus.Cancelled
                });

                //En el dataset, Tables: 1 - DocumentHeader, 2 - DocumentLine, 3 - DocumentComments
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    try
                    {
                        //Map Properties
                        tmpData       = new Document();
                        tmpData.Date1 = DateTime.Parse(dr["f430_id_fecha"].ToString());
                        tmpData.Date2 = DateTime.Parse(dr["f430_fecha_entrega"].ToString());
                        tmpData.Date3 = DateTime.Parse(dr["f430_fecha_ts_cumplido"].ToString());


                        tmpData.DocNumber       = dr["documento"].ToString();
                        tmpData.ErpMaster       = int.Parse(dr["f430_rowid"].ToString());
                        tmpData.DocStatus       = GetShippingStatus(0);
                        tmpData.Comment         = dr["f430_notas"].ToString();
                        tmpData.SalesPersonName = dr["f200_razon_social"].ToString();

                        //LAs ordenes con status void en GP, salen como canceladas.
                        try
                        {
                            if (int.Parse(dr["f430_ind_estado"].ToString()) == 9) //9 Anulado.
                            {
                                tmpData.DocStatus = cancelled;
                            }
                        }
                        catch { }

                        tmpData.CreatedBy    = dr["f430_usuario_creacion"].ToString();
                        tmpData.CustPONumber = dr["f430_num_docto_referencia"].ToString();

                        tmpData.DocConcept = docConcept;
                        tmpData.Vendor     = defAccount;

                        tmpData.Customer = WType.GetAccount(
                            new Account
                        {
                            AccountCode = dr["id_cliente"].ToString(),
                            BaseType    = new AccountType {
                                AccountTypeID = AccntType.Customer
                            },
                            Company = company
                        });
                        try
                        {
                            if (!string.IsNullOrEmpty(dr["id_ruta"].ToString()))
                            {
                                tmpData.ShippingMethod = WType.GetShippingMethod(
                                    new ShippingMethod {
                                    ErpCode = dr["id_ruta"].ToString(), Company = company
                                });
                            }
                        }
                        catch { }
                        //tmpData.User = user;

                        tmpData.IsFromErp    = true;
                        tmpData.CrossDocking = false;
                        tmpData.Company      = CurCompany;

                        tmpData.Reference = dr["f430_referencia"].ToString();
                        //tmpData.Notes = dr["BACHNUMB"].ToString();

                        //Asignacion de Address
                        tmpData.DocumentAddresses = GetShippingDocumentAddress(tmpData, null, dr);

                        DocumentAddress billAddress = null;
                        if (!string.IsNullOrEmpty(dr["f430_id_sucursal_fact"].ToString()))
                        {
                            billAddress = GetBillAddress(tmpData, dr["f430_id_sucursal_fact"].ToString(), dr["id_cliente"].ToString(), AccntType.Customer);
                        }

                        if (billAddress != null)
                        {
                            tmpData.DocumentAddresses.Add(billAddress);
                        }

                        tmpData.DocType    = soType;
                        tmpData.PickMethod = soType.PickMethod;

                        //Asignacion de Lines - Seguen el tipo de orden
                        tmpData.DocumentLines = GetShippingDocumentLines(tmpData, company, dr["f430_rowid"].ToString(), useRemain);


                        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("GetShippingDocuments: " + tmpData.DocNumber, ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                    }
                }

                //retornar la lista
                return(list);
            }
            catch (Exception ex)
            {
                ExceptionMngr.WriteEvent("GetShippingDocuments:" + pos + ":", ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                //throw;
                return(null);
            }
        }