Ejemplo n.º 1
0
        public IList <Location> GetLocations(string sWhere)
        {
            Location         tmpData;
            IList <Location> list = new List <Location>();

            try
            {
                //Lamar los documents que necesita del Erp usando econnect
                ds = DynamicsGP_ec.GetDataSet(DynamicsGP_ec.RetreiveData("WSWarehouse", false, 2, 0, sWhere, true));

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


                Status status = WType.GetStatus(new Status {
                    StatusID = EntityStatus.Active
                });

                //En el dataset, Tables: 1 - Locations
                foreach (DataRow dr in ds.Tables[1].Rows)
                {
                    if (string.IsNullOrEmpty(dr["LOCNCODE"].ToString()))
                    {
                        continue;
                    }

                    //Map Properties
                    tmpData = new Location();

                    tmpData.Company      = CurCompany;
                    tmpData.ErpCode      = dr["LOCNCODE"].ToString();
                    tmpData.Name         = dr["LOCNDSCR"].ToString();
                    tmpData.AddressLine1 = dr["ADDRESS1"].ToString();
                    tmpData.AddressLine2 = dr["ADDRESS2"].ToString();
                    tmpData.AddressLine3 = dr["ADDRESS3"].ToString();
                    tmpData.City         = dr["CITY"].ToString();
                    tmpData.State        = dr["STATE"].ToString();
                    tmpData.ZipCode      = dr["ZIPCODE"].ToString();
                    tmpData.Phone1       = dr["PHONE1"].ToString();
                    tmpData.Phone2       = dr["PHONE2"].ToString();
                    tmpData.Phone3       = dr["FAXNUMBR"].ToString();
                    //tmpData.ContactPerson = dr[""].ToString();
                    tmpData.IsDefault = false;
                    tmpData.Status    = status;
                    tmpData.IsFromErp = true;

                    list.Add(tmpData);
                }

                return(list);
            }
            catch (Exception ex)
            {
                ExceptionMngr.WriteEvent("GetLocations", ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                //throw;
                return(null);
            }
        }
Ejemplo n.º 2
0
        private IList <ProductAccountRelation> GetProductVendors(Product product)
        {
            IList <ProductAccountRelation> productVendor = new List <ProductAccountRelation>();
            ProductAccountRelation         curId         = null;
            AccountType accType = WType.GetAccountType(new AccountType {
                AccountTypeID = 2
            });

            string curItemVendor = "";

            try
            {
                //Ask for the vendor Item record
                string sWhere = " ITEMNMBR = '" + product.ProductCode + "'";
                ds = DynamicsGP_ec.GetDataSet(DynamicsGP_ec.RetreiveData("VendorItem", false, 2, 0, sWhere, true));

                if (ds.Tables.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[1].Rows)
                    {
                        curId = new ProductAccountRelation();

                        curId.ItemNumber = dr["VNDITNUM"].ToString();

                        //Si esta vacio se sale al proximo
                        if (string.IsNullOrEmpty(curId.ItemNumber))
                        {
                            continue;
                        }

                        curItemVendor = dr["VENDORID"].ToString() + ":" + curId.ItemNumber;

                        curId.IsFromErp   = true;
                        curId.AccountType = accType;
                        curId.Account     = WType.GetAccount(new Account {
                            AccountCode = dr["VENDORID"].ToString(), BaseType = new AccountType {
                                AccountTypeID = AccntType.Vendor
                            }
                        });
                        curId.Product      = product;
                        curId.CreatedBy    = WmsSetupValues.SystemUser;
                        curId.CreationDate = DateTime.Now;

                        productVendor.Add(curId);
                    }
                }

                return(productVendor);
            }
            catch (Exception ex)
            {
                ExceptionMngr.WriteEvent("GetProductVendors:" + curItemVendor, ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                //throw;
                return(null);
            }
        }
Ejemplo n.º 3
0
        //UNITS
        /// <summary>
        /// Get Unit from Dynamics GP
        /// </summary>
        /// <returns></returns>
        public IList <Unit> GetAllUnits()
        {
            Unit         tmpData;
            IList <Unit> list = new List <Unit>();

            try
            {
                ds = DynamicsGP_ec.GetDataSet(DynamicsGP_ec.RetreiveData("WSUofMSchedule", false, 2, 0, "", true)); //WSUofMSchedule

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


                //En el dataset, Tables: 1 - UOFM
                foreach (DataRow dr in ds.Tables[2].Rows)
                {
                    //Solo para unidades equivalentes en unidad base
                    if (Double.Parse(dr["QTYBSUOM"].ToString(), ListValues.DoubleFormat()) > 0)
                    {
                        //Map Properties
                        tmpData = new Unit();

                        tmpData.Company      = CurCompany; // WType.GetDefaultCompany();
                        tmpData.Name         = dr["UOFM"].ToString();
                        tmpData.ErpCode      = dr["UOFM"].ToString();
                        tmpData.ErpCodeGroup = dr["UOMSCHDL"].ToString();
                        tmpData.BaseAmount   = double.Parse(dr["QTYBSUOM"].ToString(), ListValues.DoubleFormat());
                        tmpData.IsFromErp    = true;
                        list.Add(tmpData);
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                ExceptionMngr.WriteEvent("GetUnits", ListValues.EventType.Error, ex, null,
                                         ListValues.ErrorCategory.ErpConnection);
                //throw;
                return(null);
            }
        }
Ejemplo n.º 4
0
        //PRODUCTS


        public IList <ProductCategory> GetAllProductCategories()
        {
            ProductCategory         tmpData;
            IList <ProductCategory> list = new List <ProductCategory>();

            try
            {
                ds = DynamicsGP_ec.GetDataSet(DynamicsGP_ec.RetreiveData("WSItemClass", false, 2, 0, "", true)); //WSUofMSchedule

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


                //En el dataset, Tables: 1 - UOFM
                foreach (DataRow dr in ds.Tables[1].Rows)
                {
                    //Solo para unidades equivalentes en unidad base
                    if (!string.IsNullOrEmpty(dr["ITMCLSCD"].ToString()))
                    {
                        //Map Properties
                        tmpData = new ProductCategory();

                        tmpData.Company   = CurCompany; // WType.GetDefaultCompany();
                        tmpData.Name      = dr["ITMCLSDC"].ToString().ToUpper();
                        tmpData.ErpCode   = dr["ITMCLSCD"].ToString();
                        tmpData.IsFromErp = true;
                        list.Add(tmpData);
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                ExceptionMngr.WriteEvent("GetAllProductCategory", ListValues.EventType.Error, ex, null,
                                         ListValues.ErrorCategory.ErpConnection);
                //throw;
                return(null);
            }
        }
Ejemplo n.º 5
0
        //SHIPPING METHODS
        /// <summary>
        /// Get Shipping Methods from Dynamics GP
        /// </summary>
        /// <returns></returns>
        public IList <ShippingMethod> GetAllShippingMethods()
        {
            ShippingMethod         tmpData;
            IList <ShippingMethod> list = new List <ShippingMethod>();

            try
            {
                //Lamar los documents que necesita del Erp usando econnect
                ds = DynamicsGP_ec.GetDataSet(DynamicsGP_ec.RetreiveData("WSShippingMethod", false, 2, 0, "", true));

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

                //En el dataset, Tables: 1 - Methods
                foreach (DataRow dr in ds.Tables[1].Rows)
                {
                    //Map Properties
                    tmpData = new ShippingMethod();

                    tmpData.Company   = CurCompany;
                    tmpData.Name      = dr["SHIPMTHD"].ToString() + ", " + dr["SHMTHDSC"].ToString();
                    tmpData.ErpCode   = dr["SHIPMTHD"].ToString();
                    tmpData.IsFromErp = true;

                    list.Add(tmpData);
                }

                return(list);
            }
            catch (Exception ex)
            {
                ExceptionMngr.WriteEvent("GetAllShippingMethods", ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                //throw;
                return(null);
            }
        }
Ejemplo n.º 6
0
        private IList <Account> GetCustomers(string sWhere)
        {
            IList <Account>     list = new List <Account>();
            Account             tmpData;
            AccountTypeRelation tmpAccTypeRel;

            try
            {
                //Lamar los documents que necesita del Erp usando econnect
                //TODO: Revisar obtener solo lo modificado last X days
                ds = DynamicsGP_ec.GetDataSet(DynamicsGP_ec.RetreiveData("Customer", false, 2, 0, sWhere, true));

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

                //Company company = WType.GetDefaultCompany();
                AccountType accType = WType.GetAccountType(new AccountType {
                    AccountTypeID = AccntType.Customer
                });
                Status status = WType.GetStatus(new Status {
                    StatusID = EntityStatus.Active
                });

                //En el dataset, Tables: 1 - CustomerHeader, 2 - CustomerAddress
                foreach (DataRow dr in ds.Tables[1].Rows)
                {
                    //Map Properties
                    tmpData = new Account();

                    try
                    {
                        tmpData.AccountCode = dr["CUSTNMBR"].ToString();

                        if (string.IsNullOrEmpty(tmpData.AccountCode))
                        {
                            continue;
                        }

                        tmpData.Company       = CurCompany;
                        tmpData.ContactPerson = dr["CNTCPRSN"].ToString();

                        tmpData.Name        = dr["CUSTNAME"].ToString();
                        tmpData.Phone       = dr["PHONE1"].ToString();
                        tmpData.UserDefine1 = dr["USERDEF1"].ToString();
                        tmpData.UserDefine2 = dr["USERDEF2"].ToString();

                        //Account Type
                        tmpAccTypeRel              = new AccountTypeRelation();
                        tmpAccTypeRel.Account      = tmpData;
                        tmpAccTypeRel.AccountType  = accType;
                        tmpAccTypeRel.ErpCode      = dr["CUSTNMBR"].ToString();
                        tmpAccTypeRel.Status       = status;
                        tmpAccTypeRel.CreationDate = DateTime.Now;
                        tmpAccTypeRel.CreatedBy    = WmsSetupValues.SystemUser;
                        tmpData.AccountTypes       = new AccountTypeRelation[] { tmpAccTypeRel };
                        tmpData.IsFromErp          = true;
                        tmpData.BaseType           = accType;

                        //Asignacion de Lines
                        tmpData.AccountAddresses = GetCustomerAddress(tmpData,
                                                                      ds.Tables[2].Select("CUSTNMBR='" + dr["CUSTNMBR"].ToString() + "'"));

                        list.Add(tmpData);
                    }

                    catch (Exception ex) {
                        ExceptionMngr.WriteEvent("GetCustomers:" + tmpData.AccountCode + "-" +
                                                 tmpData.Name, ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                    }
                }

                //retornar la lista
                return(list);
            }
            catch (Exception ex)
            {
                ExceptionMngr.WriteEvent("GetCustomers", ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                //throw;
                return(null);
            }
        }
Ejemplo n.º 7
0
        private IList <Product> GetProducts(string sWhere)
        {
            Product         tmpData  = null;
            IList <Product> list     = new List <Product>();
            IList <Unit>    unitList = GetAllUnits();
            IList <Unit>    curList  = unitList;
            Unit            curUnit;
            ProductCategory curCategory;
            string          flag = "";


            try
            {
                //Lamar los documents que necesita del Erp usando econnect
                //sWhere = string.IsNullOrEmpty(sWhere) ? "ITEMTYPE=1" : "ITEMTYPE=1 AND " + sWhere;

                ds = DynamicsGP_ec.GetDataSet(DynamicsGP_ec.RetreiveData("Item", false, 2, 0, sWhere, true));

                Console.WriteLine(ds.Tables.Count.ToString());

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

                //Company company = WType.GetDefaultCompany();
                //Status status = WType.GetStatus(new Status { StatusID = EntityStatus.Active });

                //En el dataset, Tables: 1 - Item
                foreach (DataRow dr in ds.Tables[1].Rows)
                {
                    try
                    {
                        //Map Properties
                        tmpData = new Product();

                        flag = "BASE";

                        tmpData.Company     = CurCompany;
                        tmpData.Name        = dr["ITEMDESC"].ToString();
                        tmpData.ProductCode = dr["ITEMNMBR"].ToString();
                        tmpData.Description = dr["ITEMDESC"].ToString();
                        tmpData.IsKit       = (dr["ITEMTYPE"].ToString() == "4") ? true : false;
                        tmpData.ErpTrackOpt = short.Parse(dr["ITMTRKOP"].ToString());

                        tmpData.Manufacturer = dr["ITMSHNAM"].ToString();
                        tmpData.Reference    = dr["ITMGEDSC"].ToString();


                        try { tmpData.CountRank = short.Parse(dr["ABCCODE"].ToString()); }
                        catch { }

                        try { tmpData.ProductCost = double.Parse(dr["CURRCOST"].ToString()); }
                        catch { }

                        tmpData.Status = GetProductStatus(int.Parse(dr["ITEMTYPE"].ToString()));
                        try { tmpData.Weight = double.Parse(dr["ITEMSHWT"].ToString()) / 100; }
                        catch { }

                        //Basic Unit
                        flag                 = "BASEUNIT";
                        curUnit              = new Unit();
                        curUnit.Company      = CurCompany;
                        curUnit.ErpCodeGroup = dr["UOMSCHDL"].ToString();
                        curUnit.BaseAmount   = 1;
                        tmpData.BaseUnit     = WType.GetUnit(curUnit);
                        tmpData.IsFromErp    = true;
                        tmpData.PrintLabel   = true;


                        //Product Category
                        if (!string.IsNullOrEmpty(dr["ITMCLSCD"].ToString()))
                        {
                            flag = "CATEGORY";
                            try
                            {
                                curCategory         = new ProductCategory();
                                curCategory.Company = CurCompany;
                                curCategory.ErpCode = dr["ITMCLSCD"].ToString();
                                tmpData.Category    = WType.GetProductCategory(curCategory);
                            }
                            catch { }
                        }

                        //Purchase Units
                        if (!string.IsNullOrEmpty(dr["PRCHSUOM"].ToString()))
                        {
                            try
                            {
                                curUnit              = new Unit();
                                curUnit.Company      = CurCompany;
                                curUnit.ErpCodeGroup = dr["UOMSCHDL"].ToString();
                                curUnit.ErpCode      = dr["PRCHSUOM"].ToString();
                                tmpData.PurchaseUnit = WType.GetUnit(curUnit);
                            }
                            catch { }
                        }

                        //Sale Unit
                        if (!string.IsNullOrEmpty(dr["SELNGUOM"].ToString()))
                        {
                            try
                            {
                                curUnit              = new Unit();
                                curUnit.Company      = CurCompany;
                                curUnit.ErpCodeGroup = dr["UOMSCHDL"].ToString();
                                curUnit.ErpCode      = dr["SELNGUOM"].ToString();
                                tmpData.SaleUnit     = WType.GetUnit(curUnit);
                            }
                            catch { }
                        }

                        //Obteniendo las unidades que ese producto puede tener
                        flag    = "UNITLIST";
                        curList = unitList.Where(unit => unit.ErpCodeGroup == dr["UOMSCHDL"].ToString()).ToList();

                        flag = "PRODUCT_TRACK";
                        tmpData.ProductTrack = GetProductTrack(int.Parse(dr["ITMTRKOP"].ToString()), tmpData);

                        flag = "PRODUCT_UNITS";
                        tmpData.ProductUnits = GetProductUnits(tmpData, curList);

                        flag = "VENDORS";
                        tmpData.ProductAccounts = GetProductVendors(tmpData);

                        //Productos Alternos.
                        flag = "ALTERN";
                        try
                        {
                            tmpData.AlternProducts = GetAlternateProducts(tmpData, dr["ALTITEM1"].ToString().Trim(),
                                                                          dr["ALTITEM2"].ToString().Trim());
                        }
                        catch (Exception ex) { Console.WriteLine(flag + " " + ex.Message); }

                        list.Add(tmpData);
                    }
                    catch (Exception ex) {
                        Console.WriteLine(flag + " " + ex.Message);
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                ExceptionMngr.WriteEvent("GetProducts" + tmpData.ProductCode + "," + flag, ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                //throw;
                return(null);
            }
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
0
        public String CreatePurchaseOrder(Document document)
        {
            string Flag = "";



            if (document.DocumentLines == null || document.DocumentLines.Count <= 0)
            {
                throw new Exception("Purchase order does not contains lines.");
            }


            try
            {
                string POPNumber;
                //string DocPrefix = "SWEB"; //ej: SWEB o como se deban crear las ordenes
                //string Batch = "BATCH"; //Numero de Batch de las ordenes a Crear

                // Next consecutive for a P.O.
                Flag = "PO Sequence";

                GetNextDocNumbers nextPopNumber = new GetNextDocNumbers();
                POPNumber = nextPopNumber.GetNextPONumber(GetNextDocNumbers.IncrementDecrement.Increment,
                                                          CurCompany.ErpConnection.CnnString);

                taPoLine_ItemsTaPoLine[] docLines = new taPoLine_ItemsTaPoLine[document.DocumentLines.Count];

                //Create an object that holds XML node object
                taPoLine_ItemsTaPoLine curLine;
                int i = 1;

                // Next consecutive for a Purchase Receipt
                foreach (DocumentLine dr in document.DocumentLines)
                {
                    //Debe ser active, para garantizar que no es Misc, o service Item
                    if (dr.Product.Status.StatusID == EntityStatus.Active)
                    {
                        curLine = new taPoLine_ItemsTaPoLine();

                        //Validate Item/Vendor, GP requires that the Vendor has assigned the ItemNumber
                        ValidateItemAndVendor(document.Vendor.AccountCode, dr.Product.ProductCode);


                        //Validate Item/Location, GP requires that the Location has assigned the ItemNumber
                        ValidateItemAndLocation(document.Location.ErpCode, dr.Product.ProductCode);

                        // Populate Lines
                        Flag                      = "Line Info";
                        curLine.PONUMBER          = POPNumber;
                        curLine.POTYPE            = GP_DocType.PO_Standard;
                        curLine.VENDORID          = document.Vendor.AccountCode;
                        curLine.QUANTITY          = (decimal)dr.Quantity;
                        curLine.QUANTITYSpecified = true;
                        curLine.REQDATE           = DateTime.Today.ToString("yyyy-MM-dd");
                        curLine.ITEMNMBR          = dr.Product.ProductCode;
                        curLine.LOCNCODE          = document.Location.ErpCode;
                        curLine.ORD               = i;
                        curLine.UOFM              = dr.Unit.ErpCode;
                        curLine.POLNESTA          = 1; //NEW


                        docLines[i - 1] = curLine;
                        i++;
                    }
                }

                //Create a SOPTransactionType schema object and populate its taSopLineIvcInsert_Items poperty
                POPTransactionType docType = new POPTransactionType();

                //Adicionado Track Lists
                docType.taPoLine_Items = docLines;

                //Create a taSopHdrIvcInsert XML node object
                taPoHdr docHdr = new taPoHdr();

                //Populate Header
                Flag = "Header Info";

                docHdr.PONUMBER = POPNumber;
                docHdr.POSTATUS = 1; //NEW
                docHdr.POTYPE   = GP_DocType.PO_Standard;
                docHdr.REQDATE  = DateTime.Today.ToString("yyyy-MM-dd");
                docHdr.VENDORID = document.Vendor.AccountCode;
                docHdr.NOTETEXT = document.Comment;

                docType.taPoHdr = docHdr;

                POPTransactionType[] docTypeArray = new POPTransactionType[1];
                docTypeArray[0] = docType;

                //Create an eConnect XML document object and populate its docType property with
                //the docType schema object
                Flag = "eConnect";

                eConnectType eConnect = new eConnectType();
                eConnect.POPTransactionType = docTypeArray;


                //Serialize the XML document to the file
                XmlSerializer serializer = new XmlSerializer(typeof(eConnectType));
                StringWriter  writer     = new StringWriter();
                serializer.Serialize(writer, eConnect);

                DynamicsGP_ec.SendData(writer.ToString());

                return(POPNumber);
            }

            catch (Exception ex)
            {
                //ExceptionMngr.WriteEvent("CreatePurchaseOrder: ", ListValues.EventType.Error, ex, null,
                //    ListValues.ErrorCategory.ErpConnection);

                throw new Exception(Flag + ". " + WriteLog.GetTechMessage(ex));
            }
        }
Ejemplo n.º 10
0
        public IList <Document> GetPurchaseReturns(string sWhere, int docType)
        {
            IList <Document> list     = new List <Document>();
            DocumentClass    docClass = new DocumentClass();
            Document         tmpData  = null;
            string           pos      = "0";

            try
            {
                //Lamar los documents que necesita del Erp usando econnect
                sWhere = string.IsNullOrEmpty(sWhere) ? "POPTYPE IN (7,6,5,4)" : "POPTYPE IN (7,6,5,4) AND " + sWhere;
                string xmlData = DynamicsGP_ec.RetreiveData("PO_Receiving_Transaction", false, 2, 0, sWhere, true);

                pos = "1";

                int rem = 0x02;
                xmlData = xmlData.Replace((char)rem, ' ');
                ds      = DynamicsGP_ec.GetDataSet(xmlData);

                pos = "2";


                Console.WriteLine("\t" + ds.Tables.Count);

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


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

                //Definiendo los tipos de documento de return
                DocumentType prtType = WType.GetDocumentType(new DocumentType {
                    DocTypeID = SDocType.PurchaseReturn
                });


                //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
                });


                //Console.WriteLine(ds.GetXml());

                //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["receiptdate"].ToString());
                        tmpData.Date2 = DateTime.Parse(dr["DUEDATE"].ToString());


                        tmpData.DocNumber = dr["POPRCTNM"].ToString();
                        tmpData.DocStatus = GetShippingStatus(0);

                        //try
                        //{
                        //    tmpData.Comment = GetDocumentNotes(dr["NOTEINDX"].ToString(), dr["COMMNTID"].ToString());
                        //}
                        //catch { }

                        tmpData.CreatedBy    = dr["USER2ENT"].ToString();
                        tmpData.CustPONumber = dr["VNDDOCNM"].ToString();

                        tmpData.DocConcept = docConcept;

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

                        //Console.WriteLine("1");

                        try
                        {
                            if (!string.IsNullOrEmpty(dr["SHIPMTHD"].ToString()))
                            {
                                tmpData.ShippingMethod = WType.GetShippingMethod(
                                    new ShippingMethod {
                                    ErpCode = dr["SHIPMTHD"].ToString(), Company = company
                                });
                            }
                        }
                        catch { }
                        //tmpData.User = user;

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

                        tmpData.Company = CurCompany;

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

                        //Console.WriteLine("2");

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

                        DocumentAddress billAddress = null;
                        try { billAddress = GetBillAddress(tmpData, "", dr["VENDORID"].ToString(), AccntType.Vendor); }
                        catch { }

                        tmpData.DocumentAddresses = new List <DocumentAddress>();

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


                        tmpData.DocType = prtType;
                        try { tmpData.PickMethod = prtType.PickMethod; }
                        catch { }

                        //Console.WriteLine("3");

                        //Asignacion de Lines - Seguen el tipo de orden
                        tmpData.DocumentLines = GetPurchaseReturnsLines(tmpData, ds.Tables[2].Select("POPRCTNM='" + dr["POPRCTNM"].ToString() + "'"),
                                                                        ds.Tables[3]);


                        //Console.WriteLine("4");

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

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