Esempio n. 1
0
        public List <ZMMInvoiceCnTh> GetHandHeldCounterMainHoldZMMInvoiceCnThFromSap(string officerID)
        {
            using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (var prx = new SAPProxyIII.UWProxy())
                {
                    prx.Connection = sapConnection;
                    SAPProxyIII.PERNR pernr = new SAPProxyIII.PERNR();
                    SAPProxyIII.ZMM_INV_CNTH_UWTable tables = new SAPProxyIII.ZMM_INV_CNTH_UWTable();
                    pernr.Pernr = officerID;
                    prx.Zdd_Handheld_Checkdoc(pernr, ref tables);

                    var ZMMInvoiceCnThList = new List <ZMMInvoiceCnTh>();
                    foreach (SAPProxyIII.ZMM_INV_CNTH_UW item in tables)
                    {
                        var zmm = new ZMMInvoiceCnTh();
                        zmm.iblnr       = item.Iblnr;
                        zmm.gjahr       = item.Gjahr;
                        zmm.budat       = DateTime.ParseExact(item.Budat, "yyyyMMdd", new System.Globalization.CultureInfo("en-US"));
                        zmm.DisplayText = string.Format("{0} : {1} : {2:dd.MM.yyyy}", zmm.iblnr, zmm.gjahr, zmm.budat);
                        ZMMInvoiceCnThList.Add(zmm);
                    }


                    return(ZMMInvoiceCnThList);
                }
            }
        }
Esempio n. 2
0
        public List <ProductPosition> GetProductPosition(string sProductCode, string sWarehouse)
        {
            var ProdReturn = new List <ProductPosition>();

            try
            {
                using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
                {
                    using (var prx = new SAPProxyIII.UWProxy())
                    {
                        prx.Connection = sapConnection;
                        SAPProxyIII.ZMM_ASSIGNLOCTable tables = new SAPProxyIII.ZMM_ASSIGNLOCTable();
                        prx.Zdd_Handheld_Get_Zmm_Assignloc("", sWarehouse, sProductCode, ref tables);
                        DataTable dt = tables.ToADODataTable();
                        foreach (DataRow item in dt.Rows)
                        {
                            if (item["LOCTYPE"].ToString().ToUpper() != "T")
                            {
                                ProdReturn.Add(new ProductPosition {
                                    PositionCode = item["BIN_CODE"].ToString(), ProductCode = item["MATERIAL"].ToString(), UnitCode = item["UNITOFMEASURE"].ToString()
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
            return(ProdReturn);
        }
Esempio n. 3
0
        public List <TopstockFormItem> GetTopstockForms()
        {
            var VReturn = new List <TopstockFormItem>();

            try
            {
                using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
                {
                    using (var prx = new SAPProxyReqTopstock.SAPProxyReqTopstock())
                    {
                        prx.Connection = sapConnection;
                        var itIn = new SAPProxyReqTopstock.ZFORM_TSTTable();
                        prx.Z_Gtopstock_Forms(ref itIn);
                        foreach (SAPProxyReqTopstock.ZFORM_TST item in itIn)
                        {
                            VReturn.Add(new TopstockFormItem {
                                FormCode = item.Vtext, FromName = item.Ttext
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(VReturn);
        }
Esempio n. 4
0
        public void AddMajorHandHeldCounterMainHoldToSap(string branchCode, string documentNo, string officerID1, string officerID2)
        {
            var    counterHolds   = GetHandHeldCounterMainHoldByDocumentNo(branchCode, documentNo);
            string accountingYear = string.Empty;
            string officerID      = string.Empty;

            SAPProxyIII.ZDD_HH_CHKSTOCKTable tables = new SAPProxyIII.ZDD_HH_CHKSTOCKTable();

            using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (var prx = new SAPProxyIII.UWProxy())
                {
                    prx.Connection = sapConnection;

                    foreach (var item in counterHolds)
                    {
                        var zdd = new SAPProxyIII.ZDD_HH_CHKSTOCK();
                        zdd.Iblnr       = item.Iblnr;
                        zdd.Gjahr       = item.Gjahr;
                        zdd.Zeili       = item.Zeili;
                        zdd.Matnr       = item.Matnr;
                        zdd.Ean11       = item.Ean11;
                        zdd.Maktx       = item.Maktx;
                        zdd.Shelf       = item.Shelf;
                        zdd.Bin_Code    = item.BinCode;
                        zdd.Erfmg_Sku   = item.ErfmgSku;
                        zdd.Erfme_Sku   = item.ErfmeSku;
                        zdd.Ratio       = item.Ratio;
                        zdd.Erfmg_Sales = item.ErfmgSales;
                        zdd.Erfme_Sales = item.ErfmeSales;

                        accountingYear = item.Gjahr;
                        officerID      = item.Createuser;

                        tables.Add(zdd);
                    }

                    try
                    {
                        prx.Zdd_Handheld_Checkstock(accountingYear, documentNo, "X", officerID1, officerID1, ref tables);

                        using (var db = new DbManager(branchCode))
                        {
                            db.SetCommand(GetSql(33), db.Parameter("@DocumentNo", documentNo)).ExecuteNonQuery();
                        }

                        prx.CommitWork();
                    }
                    catch (Exception ex)
                    {
                        prx.RollbackWork();
                        throw ex;
                    }
                }
            }
        }
        public bool ProductLocationAdd(string branchCode, string locationCode, string warehouseCode, List <ProductLocation> productLocations)
        {
            bool isSaved = false;

            try
            {
                using (SAP.Connector.SAPConnection sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
                {
                    using (SAPProxyII.UWProxy prx = new SAPProxyII.UWProxy())
                    {
                        prx.Connection = sapConnection;

                        SAPProxyII.ZMM_ASSIGNLOCTable productLocationTable = new SAPProxyII.ZMM_ASSIGNLOCTable();


                        // clear old data in SAP.
                        prx.Zdd_Handheld_Del_Zmm_Assignloc(locationCode, warehouseCode, ref productLocationTable);

                        foreach (var item in productLocations)
                        {
                            if (string.IsNullOrEmpty(item.ProductCode))
                            {
                                var product = ProductBarcodeGetByProductCodeOrBarcode3(branchCode, item.ProductBarcode);
                                if (product == null)
                                {
                                    continue;
                                }
                                item.ProductCode     = product.ProductCode;
                                item.ProductUnitCode = product.UnitCode;
                            }

                            productLocationTable = new SAPProxyII.ZMM_ASSIGNLOCTable();
                            prx.Zdd_Handheld_Set_Zmm_Assignloc(locationCode,
                                                               "X",
                                                               item.LocationType,
                                                               SapProductCodeFormated(item.ProductCode),
                                                               item.PutLevel,
                                                               item.PutQuantity,
                                                               item.DisplayOrder,
                                                               warehouseCode,
                                                               item.ProductUnitCode,
                                                               ref productLocationTable);
                        }

                        isSaved = true;
                    }
                }
            }
            catch
            {
                isSaved = false;
            }

            return(isSaved);
        }
Esempio n. 6
0
        private string SAPGetLocation(string productCode, string unitCode, string wareHouseCode, string branchCode)
        {
            string location = string.Empty;

            using (SAP.Connector.SAPConnection sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (SAPProxy.UWProxy prx = new SAPProxy.UWProxy())
                {
                    productCode = SapProductCodeFormated(productCode);

                    prx.Connection = sapConnection;

                    SAPProxy.ZSTRC_MATERIAL_MASTER strc          = new SAPProxy.ZSTRC_MATERIAL_MASTER();
                    SAPProxy.MEANTable             MeanTB        = new SAPProxy.MEANTable();
                    SAPProxy.MARDTable             MardTB        = new SAPProxy.MARDTable();
                    SAPProxy.MARATable             MaraTB        = new SAPProxy.MARATable();
                    SAPProxy.MARMTable             MarmTB        = new SAPProxy.MARMTable();
                    SAPProxy.ZMM_ASSIGNLOCTable    TB_MMLOCATION = new SAPProxy.ZMM_ASSIGNLOCTable();
                    SAPProxy.MLGTTable             TB_WHLOCATION = new SAPProxy.MLGTTable();

                    var ProductCode            = productCode;
                    var ProductMain            = productCode;
                    SAPProxy.MARATable MaraTB2 = new SAPProxy.MARATable();
                    prx.Zdd_Get_Material_Master(ProductCode, out strc, ref MeanTB, ref TB_MMLOCATION, ref MardTB, ref MaraTB2, ref MarmTB, ref TB_WHLOCATION);

                    foreach (SAPProxy.ZMM_ASSIGNLOC item in TB_MMLOCATION)
                    {
                        string sWH = "11";
                        if (branchCode == "1200")
                        {
                            sWH = "12";
                        }
                        if (item.Unitofmeasure == unitCode && item.Storage_Loc == wareHouseCode)
                        {
                            location = item.Bin_Code;
                            break;
                        }
                        else if (item.Unitofmeasure == unitCode && item.Storage_Loc.Substring(0, 2) == sWH)
                        {
                            location = item.Bin_Code;
                            break;
                        }
                    }

                    foreach (SAPProxy.MLGT item in TB_WHLOCATION)
                    {
                        location = item.Lgpla;
                        break;
                    }
                }
            }

            return(location);
        }
 public SapConnectorClientToBC establecerConeccionSap()
 {
     SAP.Connector.Destination destinationG = new SAP.Connector.Destination();
     destinationG.Username = this.User; // SAP username
     destinationG.Password = this.Password; // SAP username's password
     destinationG.AppServerHost = this.AppServerHost; // SAP application server's ip number or id
     destinationG.Client = this.Client; // Client number
     destinationG.SystemNumber = this.SystemNumber; // application server system number
     sapConnection = new SAP.Connector.SAPConnection(destinationG);
     proxy = new SapConnectorClientToBC();
     proxy.Connection = sapConnection;
     return proxy;
 }
 public SapConnectorClientToBC establecerConeccionSap()
 {
     SAP.Connector.Destination destinationG = new SAP.Connector.Destination();
     destinationG.Username      = this.User;          // SAP username
     destinationG.Password      = this.Password;      // SAP username's password
     destinationG.AppServerHost = this.AppServerHost; // SAP application server's ip number or id
     destinationG.Client        = this.Client;        // Client number
     destinationG.SystemNumber  = this.SystemNumber;  // application server system number
     sapConnection    = new SAP.Connector.SAPConnection(destinationG);
     proxy            = new SapConnectorClientToBC();
     proxy.Connection = sapConnection;
     return(proxy);
 }
        public ProductLocation ProductLocationGetByBarcode(string barcode, string locationCode, string warehouseCode, string branchCode)
        {
            var product = ProductBarcodeGetByProductCodeOrBarcode3(branchCode, barcode);

            if (product == null)
            {
                return(null);
            }

            ProductLocation productLocation = new ProductLocation();

            using (SAP.Connector.SAPConnection sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (SAPProxyII.UWProxy prx = new SAPProxyII.UWProxy())
                {
                    prx.Connection = sapConnection;

                    SAPProxyII.ZMM_ASSIGNLOCTable tables = new SAPProxyII.ZMM_ASSIGNLOCTable();
                    prx.Zdd_Handheld_Set_Zmm_Assignloc(locationCode, "", "", "", 0, 0, 0, "", "", ref tables);
                    DataTable locationTable = tables.ToADODataTable();

                    string productCode = SapProductCodeFormated(product.ProductCode);

                    var condition = new StringBuilder();
                    condition.AppendFormat(" STORAGE_LOC='{0}'", warehouseCode);
                    condition.AppendFormat(" AND BIN_CODE='{0}'", locationCode);
                    condition.AppendFormat(" AND MATERIAL='{0}'", productCode);
                    condition.AppendFormat(" AND UNITOFMEASURE='{0}'", product.UnitCode);

                    var rows = locationTable.Select(condition.ToString());
                    if (rows.Length > 0)
                    {
                        productLocation.StatusText = "พบ";
                    }
                    else
                    {
                        productLocation.StatusText = "ไม่พบ";
                    }
                }
            }

            productLocation.LocationCode    = locationCode;
            productLocation.ProductCode     = product.ProductCode;
            productLocation.ProductName     = product.ProductName;
            productLocation.ProductBarcode  = product.Barcode;
            productLocation.ProductUnitCode = product.UnitCode;
            productLocation.ProductUnitName = product.UnitName;

            return(productLocation);
        }
Esempio n. 10
0
        private double SAPGetBalanceQuantity(string productCode, string warehouseCode, string unitCode, string branchCode)
        {
            using (SAP.Connector.SAPConnection sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (SAPProxy.UWProxy prx = new SAPProxy.UWProxy())
                {
                    prx.Connection = sapConnection;
                    double dQty = 0.00;
                    SAPProxy.BAPIRETURN     Return       = new SAPProxy.BAPIRETURN();
                    SAPProxy.BAPIMGVMATNR   Material_Evg = new SAPProxy.BAPIMGVMATNR();
                    SAPProxy.BAPIWMDVETable tbWmdVex     = new SAPProxy.BAPIWMDVETable();
                    SAPProxy.BAPIWMDVSTable tbWmdVsx     = new SAPProxy.BAPIWMDVSTable();
                    var     sapProductCode     = SapProductCodeFormated(productCode);
                    string  sPlant             = branchCode;
                    var     sCheck_Rule        = "B";
                    var     sItm_Number        = "000000";
                    var     sBatch             = "";
                    var     sCustomer          = "";
                    var     sDoc_Number        = "";
                    string  sRead_Atp_Lock_X   = "";
                    var     sWbs_Elem          = "";
                    var     sStock_Ind         = "";
                    string  sDialogFlag        = "";
                    var     sEndLeadTme        = "";
                    var     sDec_ForRounding_X = "";
                    var     sRead_Atp_Lock     = "";
                    decimal dlAv_Qty_Plt       = 0;
                    short   shDec_ForRounding  = 0;
                    prx.Bapi_Material_Availability(sBatch, sCheck_Rule, sCustomer, shDec_ForRounding
                                                   , sDec_ForRounding_X, sDoc_Number, sItm_Number
                                                   , sapProductCode, Material_Evg, sPlant, sRead_Atp_Lock
                                                   , sRead_Atp_Lock_X, warehouseCode, sStock_Ind, unitCode
                                                   , sWbs_Elem, out dlAv_Qty_Plt, out sDialogFlag
                                                   , out sEndLeadTme, out Return, ref tbWmdVex, ref tbWmdVsx);

                    foreach (SAPProxy.BAPIWMDVE item in tbWmdVex)
                    {
                        dQty = Convert.ToDouble(item.Com_Qty);
                    }


                    return(dQty);
                }
            }
        }
        //public Location LocationGetByCode(string locationCode)
        //{
        //    using (DbManager db = new DbManager())
        //    {
        //        return db
        //            .SetCommand("SELECT * FROM TBUnit Where Code = @UnitCode;",
        //            db.Parameter("@UnitCode", unitCode))
        //            .ExecuteObject<ProductUnit>();
        //    }
        //}

        public List <ProductLocation> ProductLocationGetByLocation(string branchCode, string locationCode, string warehouseCode)
        {
            using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (var prx = new SAPProxyIII.UWProxy())
                {
                    prx.Connection = sapConnection;

                    var Tables = new SAPProxyIII.ZMM_ASSIGNLOCTable();

                    prx.Zdd_Handheld_Get_Zmm_Assignloc(locationCode, warehouseCode, string.Empty, ref Tables);

                    var locations = (List <SAPProxyIII.ZMM_ASSIGNLOC>)CollectionHelper.ConvertTo <SAPProxyIII.ZMM_ASSIGNLOC>(Tables.ToADODataTable());

                    List <ProductLocation> productLocations = new List <ProductLocation>();
                    var         productCode = string.Empty;
                    Product     product     = null;
                    ProductUnit productUnit = null;
                    foreach (var item in locations)
                    {
                        productCode = SystemProductCodeFormated(item.Material);

                        product     = GetProductByCode(branchCode, productCode);
                        productUnit = ProductUnitGetByCode(branchCode, item.Unitofmeasure);
                        productLocations.Add(new ProductLocation
                        {
                            LocationCode    = item.Bin_Code,
                            ProductCode     = productCode,
                            ProductBarcode  = GetProductBarcodeByProductCode(branchCode, productCode, item.Unitofmeasure),
                            ProductName     = product.NameTh,
                            ProductUnitCode = item.Unitofmeasure,
                            ProductUnitName = productUnit.Name,
                            PutLevel        = item.Putlevel,
                            PutQuantity     = item.Putqty,
                            DisplayOrder    = Convert.ToInt32(item.Roworder)
                        });
                    }

                    productLocations.Sort(delegate(ProductLocation p1, ProductLocation p2) { return(p1.DisplayOrder.CompareTo(p2.DisplayOrder)); });

                    return(productLocations);
                }
            }
        }
Esempio n. 12
0
        private double SAPGetBalanceQuantity(string productCode, string warehouseCode, string unitCode, string branchCode)
        {
            using (SAP.Connector.SAPConnection sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (SAPProxy.UWProxy prx = new SAPProxy.UWProxy())
                {
                    prx.Connection = sapConnection;
                    double dQty = 0.00;
                    SAPProxy.BAPIRETURN     Return       = new SAPProxy.BAPIRETURN();
                    SAPProxy.BAPIMGVMATNR   Material_Evg = new SAPProxy.BAPIMGVMATNR();
                    SAPProxy.BAPIWMDVETable tbWmdVex     = new SAPProxy.BAPIWMDVETable();
                    SAPProxy.BAPIWMDVSTable tbWmdVsx     = new SAPProxy.BAPIWMDVSTable();
                    productCode = SapProductCodeFormated(productCode);
                    var     checkRule       = "B";
                    var     itemNumber      = "000000";
                    var     batch           = "";
                    var     customer        = "";
                    var     docNumber       = "";
                    string  readAtpLockX    = "";
                    var     wbsElement      = "";
                    var     stockIndex      = "";
                    string  dialogFlag      = "";
                    var     endLeadTime     = "";
                    var     decForRoundingX = "";
                    var     readAtpLock     = "";
                    decimal dlAv_Qty_Plt    = 0;
                    short   decForRounding  = 0;
                    prx.Bapi_Material_Availability(batch, checkRule, customer, decForRounding
                                                   , decForRoundingX, docNumber, itemNumber
                                                   , productCode, Material_Evg, branchCode, readAtpLock
                                                   , readAtpLockX, warehouseCode, stockIndex, unitCode
                                                   , wbsElement, out dlAv_Qty_Plt, out dialogFlag
                                                   , out endLeadTime, out Return, ref tbWmdVex, ref tbWmdVsx);

                    foreach (SAPProxy.BAPIWMDVE item in tbWmdVex)
                    {
                        dQty = Convert.ToDouble(item.Com_Qty);
                    }

                    return(dQty);
                }
            }
        }
Esempio n. 13
0
        private List <Location> SAPGetLocationAllUnit(string productCode, string unitCode, string wareHouseCode)
        {
            List <Location> locations = new List <Location>();

            using (SAP.Connector.SAPConnection sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (SAPProxy.UWProxy prx = new SAPProxy.UWProxy())
                {
                    var sapProductCode = SapProductCodeFormated(productCode);

                    prx.Connection = sapConnection;

                    SAPProxy.ZSTRC_MATERIAL_MASTER strc          = new SAPProxy.ZSTRC_MATERIAL_MASTER();
                    SAPProxy.MEANTable             MeanTB        = new SAPProxy.MEANTable();
                    SAPProxy.MARDTable             MardTB        = new SAPProxy.MARDTable();
                    SAPProxy.MARATable             MaraTB        = new SAPProxy.MARATable();
                    SAPProxy.MARMTable             MarmTB        = new SAPProxy.MARMTable();
                    SAPProxy.ZMM_ASSIGNLOCTable    TB_MMLOCATION = new SAPProxy.ZMM_ASSIGNLOCTable();
                    SAPProxy.MLGTTable             TB_WHLOCATION = new SAPProxy.MLGTTable();

                    var ProductCode            = productCode;
                    var ProductMain            = productCode;
                    SAPProxy.MARATable MaraTB2 = new SAPProxy.MARATable();
                    prx.Zdd_Get_Material_Master(sapProductCode, out strc, ref MeanTB, ref TB_MMLOCATION, ref MardTB, ref MaraTB2, ref MarmTB, ref TB_WHLOCATION);

                    DataTable dt = TB_MMLOCATION.ToADODataTable();
                    //เอาหน่วยออก พี่เอ็มแจ้งให้แสดงทุกหน่วยของสินค้า 2012-11-09
                    //string condition = string.Format("Storage_Loc='{0}' AND Unitofmeasure='{1}'", wareHouseCode, unitCode);
                    string    condition = string.Format("Storage_Loc='{0}'", wareHouseCode);
                    DataRow[] rows      = dt.Select(condition);
                    foreach (DataRow row in rows)
                    {
                        Location location = new Location();
                        location.Code = row["bin_code"] as string;
                        locations.Add(location);
                    }
                }
            }

            return(locations);
        }
        private bool SapLocationGetIsContains(string productCode, string unitCode, string locationCode, string warehouseCode, out int displayOrder)
        {
            bool isContain = false;

            displayOrder = 0;
            using (SAP.Connector.SAPConnection sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (SAPProxyII.UWProxy prx = new SAPProxyII.UWProxy())
                {
                    prx.Connection = sapConnection;

                    SAPProxyII.ZMM_ASSIGNLOCTable tables = new SAPProxyII.ZMM_ASSIGNLOCTable();
                    prx.Zdd_Handheld_Set_Zmm_Assignloc(locationCode, "", "", "", 0, 0, 0, "", "", ref tables);
                    DataTable locationTable = tables.ToADODataTable();


                    string sapProductCode = SapProductCodeFormated(productCode);

                    var condition = new StringBuilder();
                    condition.AppendFormat(" STORAGE_LOC='{0}'", warehouseCode);
                    condition.AppendFormat(" AND BIN_CODE='{0}'", locationCode);
                    condition.AppendFormat(" AND MATERIAL='{0}'", sapProductCode);
                    condition.AppendFormat(" AND UNITOFMEASURE='{0}'", unitCode);

                    var rows = locationTable.Select(condition.ToString());
                    if (rows.Length > 0)
                    {
                        isContain    = true;
                        displayOrder = Convert.ToInt32(rows[0]["ROWORDER"]);
                    }
                    else
                    {
                        isContain = false;
                    }
                }
            }


            return(isContain);
        }
Esempio n. 15
0
        public List <HandHeldCounterMainHold> GetHandHeldCounterMainHoldZDDHandHeldCheckStockFromSap(string branchCode, string iblnr, string Gjahr, string officerID)
        {
            using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (var prx = new SAPProxyIII.UWProxy())
                {
                    prx.Connection = sapConnection;
                    SAPProxyIII.PERNR pernr = new SAPProxyIII.PERNR();
                    SAPProxyIII.ZDD_HH_CHKSTOCKTable tables = new SAPProxyIII.ZDD_HH_CHKSTOCKTable();
                    pernr.Pernr = officerID;
                    prx.Zdd_Handheld_Checkstock(Gjahr, iblnr, string.Empty, string.Empty, string.Empty, ref tables);

                    var zDDHandHeldCheckStockList = new List <HandHeldCounterMainHold>();
                    foreach (SAPProxyIII.ZDD_HH_CHKSTOCK item in tables)
                    {
                        var zdd = new HandHeldCounterMainHold();
                        zdd.Matnr           = item.Matnr;
                        zdd.ProductCode     = FormatedProductCode(item.Matnr);
                        zdd.Maktx           = item.Maktx;
                        zdd.BinCode         = item.Bin_Code;
                        zdd.ErfmeSales      = item.Erfme_Sales;
                        zdd.UnitNameForSale = GetUnitByCode(branchCode, item.Erfme_Sales);
                        zdd.ErfmeSku        = item.Erfme_Sku;
                        zdd.UnitNameForSKU  = GetUnitByCode(branchCode, item.Erfme_Sku);
                        zdd.Iblnr           = item.Iblnr;
                        zdd.Gjahr           = item.Gjahr;
                        zdd.Zeili           = item.Zeili;
                        zdd.Ean11           = item.Ean11;
                        zdd.Shelf           = zdd.Shelf;
                        zdd.ErfmgSku        = item.Erfmg_Sku;
                        zdd.Ratio           = item.Ratio;
                        zdd.ErfmgSales      = item.Erfmg_Sales;

                        zDDHandHeldCheckStockList.Add(zdd);
                    }

                    return(zDDHandHeldCheckStockList);
                }
            }
        }
Esempio n. 16
0
        public List <ProductPosition> GetProductPosition(string sProductCode, string sWarehouse, string sUnitCode)
        {
            List <ProductPosition> ProdReturn = new  List <ProductPosition>();

            try
            {
                using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
                {
                    using (var prx = new SAPProxyAssignloc.SAPProxyAssignloc())
                    {
                        prx.Connection = sapConnection;
                        SAPProxyAssignloc.ZMM_ASSIGNLOCTable tables = new SAPProxyAssignloc.ZMM_ASSIGNLOCTable();
                        prx.Zhh_Get_Bin_Assignloc("", sWarehouse, sProductCode, ref tables);
                        DataTable dt       = tables.ToADODataTable();
                        DataRow[] drNormal = dt.Select("Storage_Loc='" + sWarehouse + "' and unitofmeasure = '" + sUnitCode + "' ");
                        foreach (DataRow item in drNormal)
                        {
                            if (item["LOCTYPE"].ToString().ToUpper() != "T")
                            {
                                var Idd = new ProductPosition();
                                Idd.PositionCode = item["BIN_CODE"].ToString();
                                Idd.ProductCode  = item["MATERIAL"].ToString();
                                Idd.UnitCode     = item["UNITOFMEASURE"].ToString();
                                ProdReturn.Add(Idd);
                            }
                            // ProdReturn.Add(new ProductPosition { PositionCode = item["BIN_CODE"].ToString(), ProductCode = item["MATERIAL"].ToString(), UnitCode = item["UNITOFMEASURE"].ToString() });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
            return(ProdReturn);
        }
Esempio n. 17
0
        public List <ProductBarcode> ProductBarcodeGetByProductCodeOrBarcode5(string branchCode, string productCodeOrBarcode, string warehouseCode)
        {
            var product    = new List <ProductBarcode>();
            var tmpproduct = new List <ProductBarcode>();

            using (DbManager db = new DbManager(branchCode))
            {
                product = db
                          .SetCommand(GetSql(104),
                                      db.Parameter("@Barcode", productCodeOrBarcode),
                                      db.Parameter("@Branchcode", branchCode),
                                      db.Parameter("@Warehousecode", warehouseCode)
                                      )
                          .ExecuteList <ProductBarcode>();

                if (product != null)
                {
                    var Result = product.Where(x => x.Barcode == productCodeOrBarcode && x.ProductCode != productCodeOrBarcode).Take(1).ToList();
                    if (Result.Count > 0)
                    {
                        product = product.Where(x => x.UnitCode != Result.First().UnitCode).ToList();
                        product.Add(Result.First());
                    }

                    //List<UnitBarcode> barcode = new List<UnitBarcode>();
                    //var results = (product.GroupBy(p => p.UnitCode, (key, g) => new { Unit = key, Products = g.ToList() })).ToList();
                    //foreach (var item in results)
                    //{
                    //    if (item.Products.Count>1)
                    //    {
                    //        foreach (var itemin in item.Products)
                    //        {
                    //            if (itemin.Barcode == productCodeOrBarcode)
                    //            {
                    //                barcode.Add(new UnitBarcode { BarCode = itemin.Barcode, UnitCode = itemin.UnitCode });
                    //            }
                    //        }
                    //        if (barcode.Count> 1)
                    //        {
                    //            //product = from o in product where o.Barcode != productCodeOrBarcode  select o;
                    //        }
                    //    }
                    //}
                    //tmpproduct.Clear();
                    SAPProxyII.UWProxy          prx    = new SAPProxyII.UWProxy();
                    SAP.Connector.SAPConnection cnnSAP = new SAP.Connector.SAPConnection(GlobalContext.SapDestination);
                    cnnSAP.Open();
                    prx.Connection = cnnSAP;
                    SAPProxyII.MARCTable  marcs  = new SAPProxyII.MARCTable();
                    SAPProxyII.TLOGTTable tlogts = new SAPProxyII.TLOGTTable();
                    SAPProxyII.WERKS      werks  = new SAPProxyII.WERKS();
                    werks.Werks = branchCode;
                    foreach (var item in product)
                    {
                        var price = ProductPriceGetCurrentPrice(branchCode, item.ProductCode, item.UnitCode);
                        if (price != null)
                        {
                            item.ProductPrice     = price.Saleprice;
                            item.ProductPriceText = price.Saleprice.ToString("N2");
                        }
                        var Li = product.Where(x => x.ProductCode == item.ProductCode && x.LOGGR != null).ToList();
                        if (Li.Count == 0)
                        {
                            try
                            {
                                prx.Zdd_Export_Pos_Marc(AddZero(item.ProductCode, 18), werks, ref marcs, ref tlogts);
                                foreach (SAPProxyII.TLOGT itemin in tlogts)
                                {
                                    item.LOGGR = itemin.Loggr + "-" + itemin.Ltext;
                                    break;
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else
                        {
                            item.LOGGR = Li.First().LOGGR;
                        }
                        try
                        {
                            var Position = GetProductPosition(item.ProductCode, warehouseCode, item.UnitCode);
                            var i        = 0;
                            foreach (var items in Position)
                            {
                                if (i == 0)
                                {
                                    item.PositionCode = items.PositionCode;
                                }
                                else
                                {
                                    var TmpItem = new ProductBarcode()
                                    {
                                        Barcode          = item.Barcode,
                                        BinCode          = item.BinCode,
                                        LOGGR            = item.LOGGR,
                                        PositionCode     = item.PositionCode,
                                        ProductCode      = item.ProductCode,
                                        ProductName      = item.ProductName,
                                        ProductPrice     = item.ProductPrice,
                                        ProductPriceText = item.ProductPriceText,
                                        Quantity         = item.Quantity,
                                        Status           = item.Status,
                                        StockQuantity    = item.StockQuantity,
                                        StoreLocation    = item.StoreLocation,
                                        UnitCode         = item.UnitCode,
                                        UnitName         = item.UnitName,
                                        UnitRate         = item.UnitRate
                                    };
                                    TmpItem.PositionCode = items.PositionCode;
                                    tmpproduct.Add(TmpItem);
                                }
                                i += 1;
                            }
                            //if (Position != null)
                            //{
                            //    item.PositionCode = Position.PositionCode;
                            //}
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                foreach (var item in tmpproduct)
                {
                    product.Add(item);
                }
                return(product);
            }
        }
Esempio n. 18
0
        public List <OrderAccrual> OrderAccrualGetByProductCode(string productCode, string branchCode)
        {
            List <OrderAccrual> orderAccrual = new List <OrderAccrual>();

            try
            {
                using (SAP.Connector.SAPConnection sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
                {
                    using (SAPProxyII.UWProxy prx = new SAPProxyII.UWProxy())
                    {
                        prx.Connection = sapConnection;


                        var sapProductCode = SapProductCodeFormated(productCode);


                        //prepare Sale Profit
                        var     stockUnit    = GetProductStockUnit(branchCode, productCode);
                        var     productPrice = GetProductPrice(productCode, stockUnit, branchCode);
                        decimal stockCost    = 0;

                        SAPProxyII.EKETTable eket = new SAPProxyII.EKETTable();
                        SAPProxyII.EKKOTable ekko = new SAPProxyII.EKKOTable();
                        SAPProxyII.EKPOTable ekpo = new SAPProxyII.EKPOTable();
                        prx.Zdd_Export_Po_Not_Rec(sapProductCode, branchCode, out stockCost, ref eket, ref ekko, ref ekpo);

                        foreach (SAPProxyII.EKPO po in ekpo)
                        {
                            DateTime?appointDate = null;
                            DateTime?orderDate   = null;

                            string sAppointDate = "", sPoDocNo = "", sPoDocDate = "", sUser = "";
                            //วันที่นัดรับ
                            foreach (SAPProxyII.EKET ek in eket)
                            {
                                if (ek.Ebeln == po.Ebeln && ek.Ebelp == po.Ebelp)
                                {
                                    // appointDate = DateTime.Parse(ek.Eindt, new System.Globalization.CultureInfo("en-US"));
                                    appointDate = DateTime.ParseExact(ek.Eindt, "yyyyMMdd", new System.Globalization.CultureInfo("en-US"));
                                    //sAppointDate = ek.Eindt.Substring(6, 2) + "/" + ek.Eindt.Substring(4, 2) + "/" + ek.Eindt.Substring(0, 4);
                                    //sAppointDate = Convert.ToDateTime(sAppointDate).ToString("dd/MM/yyyy");
                                }
                            }
                            //เลขที่ใบสั่งซื้อ - วันที่สั่งซื้อ
                            sPoDocNo  = po.Ebeln;
                            orderDate = DateTime.ParseExact(po.Aedat, "yyyyMMdd", new System.Globalization.CultureInfo("en-US"));

                            //พนักงานจัดซื้อ
                            foreach (SAPProxyII.EKKO ko in ekko)
                            {
                                if (ko.Ebeln == po.Ebeln)
                                {
                                    sUser = ko.Ernam;
                                }
                            }

                            orderAccrual.Add(new OrderAccrual {
                                OrderNo = sPoDocNo, OrderDate = orderDate, AppointDate = appointDate, EmployeeNo = sUser
                            });
                            ////เช็คว่ามีใบสั่งซื้อเลขที่ๆเลือกไว้แล้วหรือยัง
                            //bool IsHased = false;
                            //foreach (ListViewItem olt in this.lvwPoNotRec.Items)
                            //{
                            //    SAPProxyII.EKKO opo = (SAPProxyII.EKKO)olt.Tag;
                            //    if (sPoDocNo == opo.Ebeln)
                            //    {
                            //        IsHased = true;
                            //        break;
                            //    }
                            //}
                            //if (!IsHased)
                            //{
                            //    ListViewItem item = new ListViewItem(sAppointDate);
                            //    item.SubItems.Add(sPoDocNo);
                            //    item.SubItems.Add(sPoDocDate);
                            //    item.SubItems.Add(sUser);
                            //    item.Tag = po;
                            //    this.lvwPoNotRec.Items.Add(item);
                            //}
                        }
                    }
                }
            }
            catch
            {
                orderAccrual = null;
            }

            return(orderAccrual);
        }
Esempio n. 19
0
        public ShipmentHeader GetItemShipment(string TKNUM)
        {
            var Return = new ShipmentHeader();

            try
            {
                using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
                {
                    using (var prx = new SAPGetShipmentForPC.SAPGetShipmentForPC())
                    {
                        prx.Connection = sapConnection;
                        SAPGetShipmentForPC.ZRA_VTTP_LGORT_DTable I_Lgort       = new SAPGetShipmentForPC.ZRA_VTTP_LGORT_DTable();
                        SAPGetShipmentForPC.ZRA_VTTP_VBELNTable   I_Vbeln       = new SAPGetShipmentForPC.ZRA_VTTP_VBELNTable();
                        SAPGetShipmentForPC.ZRA_VTTP_VSTELTable   I_Vstel       = new SAPGetShipmentForPC.ZRA_VTTP_VSTELTable();
                        SAPGetShipmentForPC.LIKPTable             It_Likp       = new SAPGetShipmentForPC.LIKPTable();
                        SAPGetShipmentForPC.ZLIKP_ADDTable        It_LikpAdd    = new SAPGetShipmentForPC.ZLIKP_ADDTable();
                        SAPGetShipmentForPC.LIPSTable             It_Lips       = new SAPGetShipmentForPC.LIPSTable();
                        SAPGetShipmentForPC.ZLIPS_ADDTable        It_LipsAdd    = new SAPGetShipmentForPC.ZLIPS_ADDTable();
                        SAPGetShipmentForPC.VTTKTable             It_Vttk       = new SAPGetShipmentForPC.VTTKTable();
                        SAPGetShipmentForPC.ZVTTK_ADDTable        It_VttkAdd    = new SAPGetShipmentForPC.ZVTTK_ADDTable();
                        SAPGetShipmentForPC.VTTPTable             It_Vttp       = new SAPGetShipmentForPC.VTTPTable();
                        SAPGetShipmentForPC.ZLIPS_UNITTable       It_Lips_Unit  = new SAPGetShipmentForPC.ZLIPS_UNITTable();
                        SAPGetShipmentForPC.ZLIPS_UNITTable       It_Lips_UnitU = new SAPGetShipmentForPC.ZLIPS_UNITTable();
                        var Msg    = "";
                        var Status = "";
                        prx.Zm_Getshipment_Pcs(TKNUM, out Msg
                                               , ref I_Lgort
                                               , ref I_Vbeln
                                               , ref I_Vstel
                                               , ref It_Likp
                                               , ref It_LikpAdd
                                               , ref It_Lips
                                               , ref It_LipsAdd
                                               , ref It_Vttk
                                               , ref It_VttkAdd
                                               , ref It_Vttp
                                               , ref It_Lips_Unit
                                               , ref It_Lips_UnitU);
                        if (Msg.Trim().ToLower() == "ok")
                        {
                            Return.Status = true;
                            Return.Items  = new List <ShipmentItems>();
                            foreach (SAPGetShipmentForPC.ZLIPS_ADD item in It_LipsAdd)
                            {
                                Return.Items.Add(new ShipmentItems
                                {
                                    BRGEW        = item.Brgew,
                                    GEWEI        = item.Gewei,
                                    ISPARA       = item.Ispara,
                                    LFIMG        = item.Lfimg,
                                    LGORT        = item.Lgort,
                                    LGORT_TXT    = item.Lgort_Txt,
                                    MAKTX        = item.Maktx,
                                    MATNR        = item.Matnr.TrimStart('0'),
                                    MEINS        = item.Meins,
                                    MEINS_TXT    = item.Meins_Txt,
                                    NTGEW        = item.Ntgew,
                                    PARAUNIT     = item.Paraunit,
                                    PARAUNIT_TXT = item.Paraunit_Txt,
                                    POSNR        = item.Posnr.TrimStart('0'),
                                    TKNUM        = TKNUM,
                                    VBELN        = item.Vbeln.TrimStart('0'),
                                    VRKME        = item.Vrkme,
                                    VRKME_TXT    = item.Vrkme_Txt,
                                    WBSTA        = item.Wbsta,
                                    WERKS        = item.Werks,
                                    WERKS_TXT    = item.Werks_Txt,
                                    ZMAXPL       = item.Zmaxpl,
                                    ZMINPL       = item.Zminpl
                                });
                            }
                        }
                        else
                        {
                            Return.Status  = false;
                            Return.Message = Msg;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Return.Status  = false;
                Return.Message = ex.Message;
            }
            return(Return);
        }
        public List <ProductLocation> ProductLocationGetAllByBarcode(string barcode, string branchCode, string warehouseCode)
        {
            List <ProductLocation> productLocations = new List <ProductLocation>();

            using (SAP.Connector.SAPConnection sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (SAPProxyII.UWProxy prx = new SAPProxyII.UWProxy())
                {
                    prx.Connection = sapConnection;
                    var productBarcode = ProductBarcodeGetByBarcode(barcode, branchCode);
                    var sapProductCode = SapProductCodeFormated(productBarcode.ProductCode);

                    SAPProxyII.MARDTable Tables = new SAPProxyII.MARDTable();
                    prx.Zdd_Handheld_Get_Mard(sapProductCode, ref Tables);
                    string          branchCodePrefix = branchCode.Substring(0, 2);
                    double          balanceQuantity1 = 0;
                    double          balanceQuantity2 = 0;
                    List <Location> locations        = null;
                    int             index            = 0;
                    // old logic by P' Tommy
                    foreach (SAPProxyII.MARD tbl in Tables)
                    {
                        if (tbl.Werks.Substring(2, 2) != "99" && tbl.Werks.Substring(0, 2) == branchCodePrefix)
                        {
                            var productLocation = new ProductLocation();
                            productLocation.ProductUnitCode = productBarcode.UnitCode;
                            productLocation.ProductUnitName = productBarcode.UnitName;
                            productLocation.WarehouseCode   = tbl.Lgort;
                            productLocation.WarehouseName   = WareHouseGetSingle(tbl.Lgort, branchCode).Name;
                            balanceQuantity1 = SAPGetBalanceQuantity(productBarcode.ProductCode, tbl.Lgort, productBarcode.UnitCode, branchCodePrefix + "00");
                            balanceQuantity2 = SAPGetBalanceQuantity(productBarcode.ProductCode, tbl.Lgort, productBarcode.UnitCode, branchCodePrefix + "99");

                            //productLocation.LocationCode = location.Code;
                            productLocation.BalanceQuantity     = (balanceQuantity1 + balanceQuantity2);
                            productLocation.BalanceQuantityText = productLocation.BalanceQuantity.ToString("N2");
                            productLocations.Add(productLocation);

                            locations = SAPGetLocation(productBarcode.ProductCode, productBarcode.UnitCode, tbl.Lgort);
                            index     = 0;
                            foreach (var location in locations)
                            {
                                //productLocation = productLocations.Find(p => p.WarehouseCode == location.Code);

                                if (index == 0)
                                {
                                    productLocation.LocationCode = location.Code;
                                    //balanceQuantity1 = SAPGetBalanceQuantity(productBarcode.ProductCode, location.Code, productBarcode.UnitCode, branchCodePrefix + "00");
                                    //balanceQuantity2 = SAPGetBalanceQuantity(productBarcode.ProductCode, location.Code, productBarcode.UnitCode, branchCodePrefix + "99");
                                    //productLocation.BalanceQuantity = (balanceQuantity1 + balanceQuantity2);
                                }
                                else
                                {
                                    productLocation = new ProductLocation();
                                    productLocation.BalanceQuantityText = string.Empty;
                                    //productLocation.WarehouseCode = tbl.Lgort;
                                    //productLocation.WarehouseName = WareHouseGetSingle(tbl.Lgort, branchCode).Name;
                                    productLocation.LocationCode = location.Code;
                                    //balanceQuantity1 = SAPGetBalanceQuantity(productBarcode.ProductCode, location.Code, productBarcode.UnitCode, branchCodePrefix + "00");
                                    //balanceQuantity2 = SAPGetBalanceQuantity(productBarcode.ProductCode, location.Code, productBarcode.UnitCode, branchCodePrefix + "99");
                                    //productLocation.BalanceQuantity = (balanceQuantity1 + balanceQuantity2);
                                    productLocations.Add(productLocation);
                                }
                                //if (index == 0)
                                //{
                                //    productLocation = productLocations.Find(p => p.WarehouseCode == location.Code);
                                //}
                                //else {
                                //    productLocation = new ProductLocation();
                                //    productLocation.WarehouseCode = tbl.Lgort;
                                //    productLocation.WarehouseName = WareHouseGetSingle(tbl.Lgort, branchCode).Name;
                                //    balanceQuantity1 = SAPGetBalanceQuantity(productBarcode.ProductCode, location.Code, productBarcode.UnitCode, branchCodePrefix + "00");
                                //    balanceQuantity2 = SAPGetBalanceQuantity(productBarcode.ProductCode, location.Code, productBarcode.UnitCode, branchCodePrefix + "99");

                                //    productLocation.LocationCode = location.Code;
                                //    productLocation.BalanceQuantity = (balanceQuantity1 + balanceQuantity2);
                                //    productLocations.Add(productLocation);
                                //}

                                index++;
                            }
                        }
                    }
                }
            }

            //var productBarcode = ProductBarcodeGetByBarcode(barcode);
            //List<ProductLocation> productLocations = new List<ProductLocation>();
            //var productLocation = new ProductLocation();
            //productLocation.LocationCode = SAPGetLocation(productBarcode.ProductCode, productBarcode.UnitCode, warehouseCode, branchCode);
            //productLocation.BalanceQuantity = SAPGetBalanceQuantity(productBarcode.ProductCode, warehouseCode, productBarcode.UnitCode, branchCode);
            //productLocation.ProductUnitCode = productBarcode.UnitCode;
            //productLocation.ProductUnitName = productBarcode.UnitName;
            //productLocations.Add(productLocation);

            return(productLocations);
        }
        public ProductSaleDetail ProductSaleDetailGetByProductCode(string productCode, string branchCode, bool isShowProfit)
        {
            //log.Debug("ProductSaleDetailGetByProductCode start " + DateTime.Now);

            ProductSaleDetail productSaleDetail;

            try
            {
                using (SAP.Connector.SAPConnection sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
                {
                    using (SAPProxyII.UWProxy prx = new SAPProxyII.UWProxy())
                    {
                        prx.Connection = sapConnection;

                        string  saleProductType = string.Empty;
                        decimal salePerDay      = 0;
                        decimal saleAmount      = 0;
                        decimal saleBackOffice  = 0;
                        decimal SalePos         = 0;
                        decimal saleQuantity    = 0;
                        decimal saleRate        = 0;
                        string  lastGrDate      = "";
                        decimal lastGrQty       = 0;
                        string  lastSaleDate    = "";
                        decimal lastSaleQty     = 0;

                        var sapProductCode = SapProductCodeFormated(productCode);
                        //prx.Zdd_Export_Pos_Saleinfo(sapProductCode,
                        //    branchCode,
                        //    out saleProductType,
                        //    out salePerDay,
                        //    out saleAmount,
                        //    out saleBackOffice,
                        //    out SalePos,
                        //    out saleQuantity,
                        //    out saleRate);

                        using (PrxHandheld.PrxHandheld prx2 = new PrxHandheld.PrxHandheld())
                        {
                            prx2.Connection = sapConnection;

                            prx2.Zdd_Export_Pos_Saleinfo(sapProductCode,
                                                         branchCode,
                                                         out lastGrDate,
                                                         out lastGrQty,
                                                         out lastSaleDate,
                                                         out lastSaleQty,
                                                         out saleProductType,
                                                         out salePerDay,
                                                         out saleAmount,
                                                         out saleBackOffice,
                                                         out SalePos,
                                                         out saleQuantity,
                                                         out saleRate);
                        }

                        productSaleDetail = new ProductSaleDetail();
                        productSaleDetail.SaleProductType = saleProductType;
                        productSaleDetail.SalePerDay      = salePerDay;
                        //productSaleDetail.SaleProfit
                        productSaleDetail.SaleQuantity = saleQuantity;
                        productSaleDetail.SaleRate     = saleRate;

                        productSaleDetail.LastGrDate   = lastGrDate;
                        productSaleDetail.LastGrQty    = lastGrQty;
                        productSaleDetail.LastSaleDate = lastSaleDate;
                        productSaleDetail.LastSaleQty  = lastSaleQty;

                        if (isShowProfit)
                        {
                            //prepare Sale Profit
                            var     stockUnit    = GetProductStockUnit(branchCode, productCode);
                            var     productPrice = GetProductPrice(productCode, stockUnit, branchCode);
                            decimal stockCost    = 0;
                            decimal profit       = 0;

                            SAPProxyII.EKETTable eket = new SAPProxyII.EKETTable();
                            SAPProxyII.EKKOTable ekko = new SAPProxyII.EKKOTable();
                            SAPProxyII.EKPOTable ekpo = new SAPProxyII.EKPOTable();
                            prx.Zdd_Export_Po_Not_Rec(sapProductCode, branchCode, out stockCost, ref eket, ref ekko, ref ekpo);
                            eket = null;
                            ekko = null;
                            ekpo = null;

                            //คำนวนกำไรที่ได้ของหน่วยย่อยสุด
                            if (productPrice != 0)
                            {
                                profit = 100 * (productPrice - stockCost) / productPrice;
                            }

                            if (profit >= 10)
                            {
                                productSaleDetail.SaleProfit = "++";
                            }
                            else if (profit < 0)
                            {
                                productSaleDetail.SaleProfit = "-";
                            }
                            else
                            {
                                productSaleDetail.SaleProfit = "+";
                            }
                        }
                        else
                        {
                            productSaleDetail.SaleProfit = "*******";
                        }
                    }
                }
            }
            catch
            {
                productSaleDetail = null;
            }

            //log.Debug("ProductSaleDetailGetByProductCode end " + DateTime.Now);

            return(productSaleDetail);
        }
        public string ProductLocationAddHandHeldLocation(string branchCode, List <ProductLocation> products)
        {
            var documentNo = string.Empty;

            if (string.IsNullOrEmpty(products[0].DocumentNo))
            {
                documentNo = ProductLocationHandHeldLocationGetDocumentNo(branchCode);
            }
            else
            {
                documentNo = products[0].DocumentNo;
            }

            var createdDate       = DateTime.Now;
            var createdDateFormat = createdDate.ToString("yyyy.MM.dd", new System.Globalization.CultureInfo("en-US"));
            var createdTimeFormat = createdDate.ToString("HH:mm:ss");
            int displayOrder      = 0;
            var isContains        = false;

            SAPProxyII.ZHANDHELD_LOCTable locationTable = new SAPProxyII.ZHANDHELD_LOCTable();

            using (DbManager db = new DbManager(branchCode))
            {
                try
                {
                    SqlQuery <ProductLocation> productQuery = new SqlQuery <ProductLocation>(db);
                    db.BeginTransaction();

                    //Clear old data for location and employee.
                    db.SetCommand(GetSql(40)
                                  , db.Parameter("@DocumentNo", documentNo))
                    .ExecuteNonQuery();

                    foreach (var item in products)
                    {
                        // modify for offline mode.
                        if (string.IsNullOrEmpty(item.ProductCode))
                        {
                            var product = ProductBarcodeGetByProductCodeOrBarcode3(branchCode, item.ProductBarcode);
                            if (product == null)//if not exists skip to next row.
                            {
                                continue;
                            }

                            item.SalePrice       = GetProductPrice(product.ProductCode, product.UnitCode, branchCode);
                            item.ProductCode     = product.ProductCode;
                            item.ProductName     = product.ProductName;
                            item.ProductUnitCode = product.UnitCode;
                            item.ProductUnitName = product.UnitName;
                        }

                        if (item.SalePrice != item.ShopPrice)
                        {
                            item.PriceStatus = "ราคาไม่ตรง";
                        }
                        else
                        {
                            item.PriceStatus = "ราคาถูกต้อง";
                        }

                        isContains = SapLocationGetIsContains(item.ProductCode, item.ProductUnitCode, item.LocationCode, item.WarehouseCode, out displayOrder);
                        if (!isContains)
                        {
                            item.LocationStatus = "ไม่พบสินค้าในตำแหน่งนี้";
                        }
                        else
                        {
                            if (displayOrder == item.DisplayOrder)
                            {
                                item.LocationStatus = "ตำแหน่งถูกต้อง";
                            }
                            else
                            {
                                item.LocationStatus = "ลำดับไม่ตรง";
                            }
                        }

                        item.DocumentNo   = documentNo;
                        item.DocumentDate = createdDate.Date;
                        item.CreateDate   = createdDate;
                        item.Remark       = string.Concat(item.PriceStatus, ",", item.LocationStatus);
                        var locationItem = new SAPProxyII.ZHANDHELD_LOC();
                        locationItem.Docno = documentNo;
                        //string sDocDate = DateTime.Today.Year.ToString() + DateTime.Today.ToString(".MM.dd");
                        //string sTime = DateTime.Now.ToString("HH:mm:ss");
                        locationItem.Docdate      = createdDateFormat;
                        locationItem.Createdate   = createdDateFormat;
                        locationItem.Createtime   = createdTimeFormat;
                        locationItem.Roworder     = item.DisplayOrder;
                        locationItem.Productcode  = item.ProductCode;// SapProductCodeFormated(item.ProductCode);
                        locationItem.Productname  = item.ProductName;
                        locationItem.Warehouse    = item.WarehouseCode;
                        locationItem.Location     = item.LocationCode;
                        locationItem.Unitcode     = item.ProductUnitCode;
                        locationItem.Unitname     = item.ProductUnitName;
                        locationItem.Barcode      = item.ProductBarcode;
                        locationItem.Sys_Price    = item.SalePrice;
                        locationItem.Pos_Price    = item.ShopPrice;
                        locationItem.Remark       = item.Remark;
                        locationItem.Userid       = item.UserID;
                        locationItem.Officerid    = item.OfficerID;
                        locationItem.Res_Location = item.LocationStatus;
                        locationItem.Res_Price    = item.PriceStatus;

                        locationTable.Add(locationItem);

                        productQuery.Insert(item);

                        displayOrder = 0;
                    }

                    //commit transaction to SQL Server.
                    db.CommitTransaction();
                }
                catch (Exception ex)
                {
                    db.RollbackTransaction();
                    throw ex;
                }

                using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
                {
                    using (var prx = new SAPProxyII.UWProxy())
                    {
                        prx.Connection = sapConnection;
                        prx.Zdd_Export_Tbhandheldlocation(ref locationTable);
                    }
                }
            }

            return(documentNo);
        }
Esempio n. 23
0
        public TopStockHeader GetTopstockItems(string _ItemId, string _Barcode, string _Position, string _Branch, string _Warhouse, string _Status)
        {
            var VReturn = new TopStockHeader();

            try
            {
                using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
                {
                    using (var prx = new SAPProxyReqTopstock.SAPProxyReqTopstock())
                    {
                        prx.Connection = sapConnection;
                        var itIn   = new SAPProxyReqTopstock.ZREQTOPSTOCKTable();
                        var Msg    = "";
                        var Status = "";
                        prx.Z_Gtopstock_Items(_Branch, _Barcode, _ItemId, _Position, _Status, _Warhouse, out Msg, out Status, ref itIn);
                        if (Status.Trim().ToLower() == "y")
                        {
                            VReturn.Status = true;
                            VReturn.Items  = new List <TopStockItem>();
                            foreach (SAPProxyReqTopstock.ZREQTOPSTOCK item in itIn)
                            {
                                VReturn.Items.Add(new TopStockItem
                                {
                                    BAR         = item.Bar,
                                    BARCODE     = item.Barcode,
                                    FNAME       = item.Fname,
                                    LGORT       = item.Lgort,
                                    LGORT_TXT   = item.Lgort_Txt,
                                    LOCATION_S  = item.Location_S,
                                    LOCATION_T  = item.Location_T,
                                    LOCCLASS    = item.Locclass,
                                    LOCHOLE     = item.Lochole,
                                    LOCHSHELF   = item.Lochshelf,
                                    LOCSIDE     = item.Locside,
                                    LOCSIDE_TXT = item.Locside_Txt,
                                    LOCZONE     = item.Loczone,
                                    LOGGR       = item.Loggr,
                                    LOGGR_TXT   = item.Loggr_Txt,
                                    MATNR       = item.Matnr,
                                    MATNR_TXT   = item.Matnr_Txt,
                                    MEINH       = item.Meinh,
                                    MEINH_TXT   = item.Meinh_Txt,
                                    MSG         = item.Msg,
                                    QTY         = item.Qty,
                                    STATUS      = item.Status,
                                    UMREZ       = item.Umrez,
                                    WERKS       = item.Werks
                                });
                            }
                        }
                        else
                        {
                            VReturn.Status  = false;
                            VReturn.Message = Msg;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                VReturn.Status  = false;
                VReturn.Message = ex.Message;
            }
            return(VReturn);
        }
Esempio n. 24
0
        private void AddHandHeldCheckProductToSAP(string userCode, string userName, string employeeID, string locationCode, string warehouseCode, string branchCode, List <LocationDescription> locationDescriptions, List <ProductBarcode> products, string remark)
        {
            using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (var prx = new SAPProxyIII.UWProxy())
                {
                    prx.Connection = sapConnection;


                    SAPProxyIII.ZDD_HH_CHECKAREATable zdd_hh_checkarea = new SAPProxyIII.ZDD_HH_CHECKAREATable();
                    SAPProxyIII.ZDD_HH_CHECKAREA      area             = new SAPProxyIII.ZDD_HH_CHECKAREA();

                    foreach (var item in locationDescriptions)
                    {
                        #region เก็บข้อมูลลง Internal Table
                        area.Bin_Code = locationCode;
                        switch (item.ID + 1)
                        {
                        case 1:
                            area.F01 = " ";
                            if (item.Checked)
                            {
                                area.F01 = "X";
                            }
                            break;

                        case 2:
                            area.F02 = " ";
                            if (item.Checked)
                            {
                                area.F02 = "X";
                            }
                            break;

                        case 3:
                            area.F03 = " ";
                            if (item.Checked)
                            {
                                area.F03 = "X";
                            }
                            break;

                        case 4:
                            area.F04 = " ";
                            if (item.Checked)
                            {
                                area.F04 = "X";
                            }
                            break;

                        case 5:
                            area.F05 = " ";
                            if (item.Checked)
                            {
                                area.F05 = "X";
                            }
                            break;

                        case 6:
                            area.F06 = " ";
                            if (item.Checked)
                            {
                                area.F06 = "X";
                            }
                            break;

                        case 7:
                            area.F07 = " ";
                            if (item.Checked)
                            {
                                area.F07 = "X";
                            }
                            break;

                        case 8:
                            area.F08 = " ";
                            if (item.Checked)
                            {
                                area.F08 = "X";
                            }
                            break;

                        case 9:
                            area.F09 = " ";
                            if (item.Checked)
                            {
                                area.F09 = "X";
                            }
                            break;

                        case 10:
                            area.F10 = 0;
                            if (item.Checked)
                            {
                                short areaF10 = 0;
                                Int16.TryParse(item.BlankNumber, out areaF10);
                                area.F10 = areaF10;
                            }
                            break;

                        case 11:
                            area.F11 = " ";
                            if (item.Checked)
                            {
                                area.F11 = "X";
                            }
                            break;

                        case 12:
                            area.F12 = " ";
                            if (item.Checked)
                            {
                                area.F12 = "X";
                            }
                            break;

                        case 13:
                            area.F13 = " ";
                            if (item.Checked)
                            {
                                area.F13 = "X";
                            }
                            break;

                        case 14:
                            area.F14 = " ";
                            if (item.Checked)
                            {
                                area.F14 = "X";
                            }
                            break;

                        case 15:
                            area.F15 = " ";
                            if (item.Checked)
                            {
                                area.F15 = "X";
                            }
                            break;

                        case 16:
                            area.F16 = " ";
                            if (item.Checked)
                            {
                                area.F16 = "X";
                            }
                            break;

                        case 17:
                            area.F17 = " ";
                            if (item.Checked)
                            {
                                area.F17 = "X";
                            }
                            break;

                        case 18:
                            area.F18 = " ";
                            if (item.Checked)
                            {
                                area.F18 = "X";
                            }
                            break;

                        case 19:
                            area.F19 = " ";
                            if (item.Checked)
                            {
                                area.F19 = "X";
                            }
                            break;

                        case 20:
                            area.Expoint = 0;
                            if (item.Checked)
                            {
                                short areaExpoint = 0;
                                Int16.TryParse(item.BlankNumber, out areaExpoint);
                                area.Expoint = areaExpoint;
                            }
                            break;

                        default:
                            break;
                        }
                        #endregion
                    }

                    area.Remark = remark;
                    area.Lgort  = warehouseCode;
                    area.Werks  = branchCode;

                    using (DbManager db = new DbManager(branchCode))
                    {
                        db.Command.CommandTimeout = 200;
                        var sql        = GetSql(28);
                        var documentNo = this.GetHandHeldCheckProductDocumentNo(branchCode);
                        try
                        {
                            db.BeginTransaction();

                            foreach (var item in products)
                            {
                                area.Matnr = item.ProductCode;
                                area.Meins = item.UnitCode;
                                zdd_hh_checkarea.Add(area);
                                prx.Zdd_Handheld_Checkarea(userName, employeeID, ref zdd_hh_checkarea);
                                if (zdd_hh_checkarea.Count > 0)
                                {
                                    if (!string.IsNullOrEmpty(zdd_hh_checkarea[0].Chkareano))
                                    {
                                        db.SetCommand(sql,
                                                      db.Parameter("@DOCNO", documentNo),
                                                      db.Parameter("@LOCATION", locationCode),
                                                      db.Parameter("@DOCDATE", DateTime.Now.Date),
                                                      db.Parameter("@USERID", userCode),
                                                      db.Parameter("@OFFICERID", employeeID),
                                                      db.Parameter("@CHKAREANO", zdd_hh_checkarea[0].Chkareano))
                                        .ExecuteNonQuery();

                                        documentNo = PrepareHandHeldCheckProductDocumentNo(documentNo);
                                    }
                                }
                            }

                            prx.CommitWork();
                            db.CommitTransaction();
                        }
                        catch (Exception ex)
                        {
                            prx.RollbackWork();
                            db.RollbackTransaction();
                            throw ex;
                        }
                    }
                }
            }
        }
Esempio n. 25
0
        public TopStockHeader CreateTopstockDoc(TopStockHeader TopIn)
        {
            var VReturn = new TopStockHeader();

            try
            {
                using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
                {
                    using (var prx = new SAPProxyReqTopstock.SAPProxyReqTopstock())
                    {
                        prx.Connection = sapConnection;
                        var itIn   = new SAPProxyReqTopstock.ZREQTOPSTOCKTable();
                        var Msg    = "";
                        var ZDocNo = "";
                        foreach (var item in TopIn.Items)
                        {
                            var ItemAdd = new SAPProxyReqTopstock.ZREQTOPSTOCK();
                            ItemAdd.Bar         = item.BAR;
                            ItemAdd.Barcode     = item.BARCODE;
                            ItemAdd.Fname       = item.FNAME;
                            ItemAdd.Lgort       = item.LGORT;
                            ItemAdd.Lgort_Txt   = item.LGORT_TXT;
                            ItemAdd.Location_S  = item.LOCATION_S;
                            ItemAdd.Location_T  = item.LOCATION_T;
                            ItemAdd.Locclass    = item.LOCCLASS;
                            ItemAdd.Lochole     = item.LOCHOLE;
                            ItemAdd.Lochshelf   = item.LOCHSHELF;
                            ItemAdd.Locside     = item.LOCSIDE;
                            ItemAdd.Locside_Txt = item.LOCSIDE_TXT;
                            ItemAdd.Loczone     = item.LOCZONE;
                            ItemAdd.Loggr       = item.LOGGR;
                            ItemAdd.Loggr_Txt   = item.LOGGR_TXT;
                            ItemAdd.Matnr       = item.MATNR;
                            ItemAdd.Matnr_Txt   = item.MATNR_TXT;
                            ItemAdd.Meinh       = item.MEINH;
                            ItemAdd.Meinh_Txt   = item.MEINH_TXT;
                            ItemAdd.Qty         = item.QTY;
                            ItemAdd.Status      = item.STATUS;
                            ItemAdd.Msg         = item.MSG;
                            ItemAdd.Umrez       = item.UMREZ;
                            ItemAdd.Werks       = item.WERKS;
                            itIn.Add(ItemAdd);
                        }
                        prx.Z_Ctopstock_Hh(TopIn.EmpId, TopIn.WarhouseId, out ZDocNo, ref itIn);
                        if (ZDocNo.Trim() != "")
                        {
                            VReturn.Status  = true;
                            VReturn.ZDocNo  = ZDocNo;
                            VReturn.Message = Msg;
                        }
                        else
                        {
                            VReturn.Status  = false;
                            VReturn.Message = Msg;
                            VReturn.Items   = new List <TopStockItem>();
                            foreach (SAPProxyReqTopstock.ZREQTOPSTOCK item in itIn)
                            {
                                VReturn.Items.Add(new TopStockItem
                                {
                                    BAR         = item.Bar,
                                    BARCODE     = item.Barcode,
                                    FNAME       = item.Fname,
                                    LGORT       = item.Lgort,
                                    LGORT_TXT   = item.Lgort_Txt,
                                    LOCATION_S  = item.Location_S,
                                    LOCATION_T  = item.Location_T,
                                    LOCCLASS    = item.Locclass,
                                    LOCHOLE     = item.Lochole,
                                    LOCHSHELF   = item.Lochshelf,
                                    LOCSIDE     = item.Locside,
                                    LOCSIDE_TXT = item.Locside_Txt,
                                    LOCZONE     = item.Loczone,
                                    LOGGR       = item.Loggr,
                                    LOGGR_TXT   = item.Loggr_Txt,
                                    MATNR       = item.Matnr,
                                    MATNR_TXT   = item.Matnr_Txt,
                                    MEINH       = item.Meinh,
                                    MEINH_TXT   = item.Meinh_Txt,
                                    MSG         = item.Msg,
                                    QTY         = item.Qty,
                                    STATUS      = item.Status,
                                    UMREZ       = item.Umrez,
                                    WERKS       = item.Werks
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                VReturn.Status  = false;
                VReturn.Message = ex.Message;
            }
            return(VReturn);
        }