Ejemplo n.º 1
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);
        }
        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);
        }