예제 #1
0
        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);
            }
        }
        public IList <Document> GetReceivingDocuments(string sWhere)
        {
            IList <Document> list     = new List <Document>();
            DocumentClass    docClass = new DocumentClass();
            Document         tmpData  = null;

            try
            {
                /*
                 * 401	0	En elaboración
                 * 401	1	Aprobado
                 * 401	2	Parcial
                 * 401	3	Cumplido
                 * 401	9	Anulado
                 */

                //Console.WriteLine("Entramos");

                sWhere = string.IsNullOrEmpty(sWhere) ? " t420.f420_ind_estado IN (1,2,3,9) " : " t420.f420_ind_estado IN (1,2,3,9) AND " + sWhere;


                Command.Connection = new SqlConnection(CurCompany.ErpConnection.CnnString);

                Query = GetErpQuery("PURCHASEORDER");

                //Console.WriteLine(Query);

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


                Console.WriteLine(ds.Tables.Count);

                if (ds == null || 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[0].Rows)
                {
                    try
                    {
                        //Map Properties
                        tmpData       = new Document();
                        tmpData.Date1 = DateTime.Parse(dr["f420_fecha"].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["f420_ind_estado"].ToString()));
                        tmpData.DocType         = docType;
                        tmpData.PickMethod      = docType.PickMethod;
                        tmpData.DocConcept      = docConcept;
                        tmpData.QuoteNumber     = dr["f420_id_sucursal_prov"].ToString();
                        tmpData.Reference       = dr["f420_num_docto_referencia"].ToString();
                        tmpData.SalesPersonName = dr["id_comprador"].ToString();
                        tmpData.UserDef1        = dr["f420_id_moneda_docto"].ToString();


                        //try { tmpData.LastChange = DateTime.Parse(dr["f420_fecha_ts_actualizacion"].ToString()); }
                        //catch { }

                        tmpData.Comment = dr["f420_notas"].ToString();


                        tmpData.Vendor = WType.GetAccount(
                            new Account
                        {
                            AccountCode = dr["id_proveedor"].ToString(),
                            BaseType    = new AccountType {
                                AccountTypeID = AccntType.Vendor
                            },
                            Company = company
                        });     //Vendor Account;

                        tmpData.Customer  = defAccount;
                        tmpData.CreatedBy = dr["f420_usuario_creacion"].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, dr["f420_rowid"].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);
            }
        }