Beispiel #1
0
        public static void GetPriceForCheckPoint(ref Order _order, String so, String currency, String org_id)
        {
            List <SO_HEADER> sh = new CPDBDAL().GetDistinctSoHeader(so);
            List <SO_DETAIL> sd = new CPDBDAL().GetSoDetail(so);

            _order.Currency    = currency;
            _order.OrgID       = org_id;
            _order.DistChannel = (from d in sh select d.DIST_CHAN).FirstOrDefault().Trim();
            _order.Division    = (from d in sh select d.DIVISION).FirstOrDefault().Trim();

            int i = 0;

            foreach (SO_DETAIL d in sd)
            {
                // Only check for list price, hence the qty is set to 1
                _order.AddLooseItem(Advantech.Myadvantech.DataAccess.SAPDAL.RemovePrecedingZeros(d.MATERIAL), 1);
                _order.LineItems[i].PlantID = "USH1";
                i++;
            }

            _order.SetOrderPartnet(new OrderPartner(GetSoPartnerFunc_Number(so, "AG"), org_id, OrderPartnerType.SoldTo));
            _order.SetOrderPartnet(new OrderPartner(GetSoPartnerFunc_Number(so, "WE"), org_id, OrderPartnerType.ShipTo));
            _order.SetOrderPartnet(new OrderPartner(GetSoPartnerFunc_Number(so, "AG"), org_id, OrderPartnerType.BillTo));

            String _errMsg = String.Empty;

            Advantech.Myadvantech.DataAccess.SAPDAL.SimulateOrder(ref _order, ref _errMsg);

            if (!String.IsNullOrEmpty(_errMsg))
            {
                throw new Exception(_errMsg);
            }
        }
Beispiel #2
0
        public static String GetSoDetail_Currency(String so)
        {
            List <SO_DETAIL> sd     = new CPDBDAL().GetSoDetail(so);
            String           result = (from d in sd
                                       where d.SO == so
                                       select d.CURRENCY).FirstOrDefault();

            return(!String.IsNullOrEmpty(result) ? result : "USD");
        }
Beispiel #3
0
        public static String GetCustPONoByCartID(String cart_id)
        {
            List <CheckPointOrder2Cart> cpoc = new CPDBDAL().CheckPointOrder2Cart();
            String result = (from d in cpoc
                             where d.CartID == cart_id
                             select d.PO_NO).FirstOrDefault();

            return(!String.IsNullOrEmpty(result) ? result : "");
        }
Beispiel #4
0
        public static Boolean CheckPointOrder2Cart_CartIDExist(String cart_id)
        {
            List <CheckPointOrder2Cart> cpoc = new CPDBDAL().CheckPointOrder2Cart();
            Boolean result = (from d in cpoc
                              where d.CartID == cart_id
                              select d.CheckPointOrderNo).Any();

            return(result);
        }
Beispiel #5
0
        public static String CheckPointOrder2Cart_getOrderNo(String cart_id)
        {
            List <CheckPointOrder2Cart> cpoc = new CPDBDAL().CheckPointOrder2Cart();
            String result = (from d in cpoc
                             where d.CartID == cart_id
                             select d.CheckPointOrderNo).FirstOrDefault();

            return(result);
        }
Beispiel #6
0
        public static String GetSoPo_BySo(String so)
        {
            List <SO_HEADER> sh     = new CPDBDAL().GetDistinctSoHeader(so);
            String           result = (from d in sh
                                       where d.SO == so
                                       select d.CUST_PO_NO).FirstOrDefault();

            return(!String.IsNullOrEmpty(result) ? result : "");
        }
Beispiel #7
0
        public static void EditCheckPointOrder2Cart_Status(String cart_id)
        {
            List <CheckPointOrder2Cart> cpoc = new CPDBDAL().CheckPointOrder2Cart();
            CheckPointOrder2Cart        cart = (from d in cpoc
                                                where d.CartID == cart_id
                                                select d).FirstOrDefault();

            if (cart != null)
            {
                cart.OrderStatus = "Finished";
                cart.Remark      = "Turned to finished at " + DateTime.Now;
                MyAdvantechContext.Current.SaveChanges();
            }
        }
Beispiel #8
0
        public static String GetCustDNNoByCartID(String cart_id)
        {
            String result = String.Empty;

            List <CheckPointOrder2Cart> cpoc = new CPDBDAL().CheckPointOrder2Cart();
            String CPNO = (from d in cpoc
                           where d.CartID == cart_id
                           select d.CheckPointOrderNo).FirstOrDefault();

            if (CPNO != null && !String.IsNullOrEmpty(CPNO))
            {
                var objCPDNNo = SqlProvider.dbExecuteScalar("CheckPointDB", String.Format("SELECT top 1 b.DN FROM [CheckPointDB].[dbo].[SO_HEADER] a inner join [CheckPointDB].[dbo].[Shipment_Information] b on a.CUST_PO_NO = b.SO_Number where a.SO = '{0}'", CPNO));
                if (objCPDNNo != null && !String.IsNullOrEmpty(objCPDNNo.ToString()))
                {
                    result = objCPDNNo.ToString();
                }
            }
            return(result);
        }
Beispiel #9
0
        public static String GetSoPartnerFunc_Number(String so, String role_type)
        {
            List <SO_PARTNERFUNC> sp = new CPDBDAL().GetSoPartnerFunc(so);
            String result            = "";

            // get ERPID from SO_Partnumber_function table depend on it's role
            if (role_type.Equals("AG"))
            {
                result = (from number in sp
                          where number.ROLE == "AG"
                          select number.NUMBER).FirstOrDefault();
            }
            else if (role_type.Equals("WE"))
            {
                result = (from number in sp
                          where number.ROLE == "WE"
                          select number.NUMBER).FirstOrDefault();
            }
            return(!String.IsNullOrEmpty(result) ? result : "");
        }
Beispiel #10
0
        public static void Detail2Cart(String so, String cart_id, String erp_id, String user_id, String currency, String org_id)
        {
            SqlProvider.dbExecuteNoQuery("MY", String.Format("delete from ORDER_MASTER where ORDER_ID = '{0}'", so));
            SqlProvider.dbExecuteNoQuery("MY", String.Format("delete from ORDER_DETAIL where ORDER_ID = '{0}'", so));
            SqlProvider.dbExecuteNoQuery("MY", String.Format("delete from ORDER_PARTNERS where ORDER_ID = '{0}'", so));
            SqlProvider.dbExecuteNoQuery("MY", String.Format("delete from order_Master_ExtensionV2 where ORDER_ID = '{0}'", so));

            // SO_Header to CartMaster
            CARTMASTERV2 CartMaster = new CARTMASTERV2();

            CartMaster.CartID          = cart_id;
            CartMaster.ErpID           = erp_id;
            CartMaster.CreatedDate     = DateTime.Now;
            CartMaster.Currency        = currency;
            CartMaster.CreatedBy       = user_id;
            CartMaster.LastUpdatedDate = DateTime.Now;
            CartMaster.LastUpdatedBy   = user_id;
            MyAdvantechContext.Current.CARTMASTERV2.Add(CartMaster);

            // SO_Detail to CartDetail
            List <SO_DETAIL> sd = new CPDBDAL().GetSoDetail(so); // get a list from SO_Detail table

            // Simulate Product List to get the correct list price
            Order _order = new Order();

            GetPriceForCheckPoint(ref _order, so, currency, org_id);

            if (_order != null)
            {
                List <Product> pr = _order.LineItems;
                foreach (SO_DETAIL d in sd)
                {
                    cart_DETAIL_V2 CartDetail = new cart_DETAIL_V2();

                    CartDetail.Cart_Id      = cart_id;
                    CartDetail.Line_No      = int.Parse(d.LINE_NO);
                    CartDetail.Part_No      = Advantech.Myadvantech.DataAccess.SAPDAL.RemovePrecedingZeros(d.MATERIAL);
                    CartDetail.Qty          = int.Parse(d.QTY);
                    CartDetail.CustMaterial = d.CUST_MATERIAL;
                    CartDetail.Ew_Flag      = 0;
                    CartDetail.SatisfyFlag  = 0;
                    CartDetail.QUOTE_ID     = "";

                    // higherlevel value validate, if is null then set it as 0 to avoid further error
                    if (d.HIGHER_LEVEL == null)
                    {
                        CartDetail.higherLevel = 0;
                    }
                    else
                    {
                        CartDetail.higherLevel = int.Parse(d.HIGHER_LEVEL);
                    }

                    // item type validate, set it's type, req_date, due_date
                    CartDetail.otype    = 0;
                    CartDetail.req_date = DateTime.Now.AddDays(2);
                    if (CartDetail.Line_No < 100)
                    {
                        CartDetail.otype = (int)QuoteItemType.Part;
                    }
                    else if (CartDetail.Line_No % 100 == 0 && CartDetail.higherLevel == 0)
                    {
                        CartDetail.otype    = (int)QuoteItemType.BtosParent;
                        CartDetail.req_date = getCompNextWorkDate(CartDetail.req_date.Value, org_id, getBTOWorkingDate(org_id));
                    }
                    else if (CartDetail.Line_No % 100 > 0 && CartDetail.Line_No > 100)
                    {
                        CartDetail.otype    = (int)QuoteItemType.BtosPart;
                        CartDetail.req_date = getCompNextWorkDate(CartDetail.req_date.Value, org_id, getBTOWorkingDate(org_id));
                    }
                    CartDetail.due_date = CartDetail.req_date;

                    //Ryan 20160421 Revise Delivery Plant Logic, *Must behind partno & otype processing.
                    CartDetail.Delivery_Plant = PartBusinessLogic.GetDeliveryPlant(erp_id, org_id, CartDetail.Part_No, (QuoteItemType)Enum.Parse(typeof(QuoteItemType), CartDetail.otype.ToString()));

                    // set price according to it's item type
                    if (CartDetail.otype == (int)QuoteItemType.BtosParent)
                    {
                        CartDetail.List_Price = 0;
                        CartDetail.Unit_Price = 0;
                        CartDetail.Itp        = 0;
                    }
                    else
                    {
                        // Get the list price only if CartDetail's Part_NO is equal to _Order's Part_NO
                        Decimal list_price = 0, unit_price = 0;
                        if ((from p in pr where p.PartNumber == CartDetail.Part_No select p.ListPrice).Any())
                        {
                            list_price = (from p in pr where p.PartNumber == CartDetail.Part_No select p.ListPrice).FirstOrDefault();
                        }
                        if ((from p in pr where p.PartNumber == CartDetail.Part_No select p.UnitPrice).Any())
                        {
                            unit_price = (from p in pr where p.PartNumber == CartDetail.Part_No select p.UnitPrice).FirstOrDefault();
                        }

                        CartDetail.List_Price = list_price;
                        CartDetail.Unit_Price = unit_price;
                        CartDetail.Itp        = 0;
                    }
                    MyAdvantechContext.Current.cart_DETAIL_V2.Add(CartDetail);
                }
                MyAdvantechContext.Current.SaveChanges();
            }
        }