Exemplo n.º 1
0
        public static UpdateResult SaveConfiguredRecords(string sourceId, string sourceLineNo, string sourceSite, string rootId, List <Advantech.Myadvantech.DataAccess.DataCore.ConfigurationHub.ConfiguredItems> selectedItems, string companyId, string currency, string reconfigData)
        {
            UpdateResult result = new UpdateResult();

            try
            {
                HubConfiguredResult myEntity = new HubConfiguredResult();
                myEntity.ID            = sourceId;
                myEntity.Source        = sourceSite;
                myEntity.ParentLineNo  = int.Parse(sourceLineNo);
                myEntity.RootID        = rootId;
                myEntity.Result        = Convert.ToInt32(true);
                myEntity.SelectedItems = Newtonsoft.Json.JsonConvert.SerializeObject(selectedItems);
                myEntity.CompanyID     = companyId;
                myEntity.Currency      = currency;
                myEntity.ReConfigData  = reconfigData;
                myEntity.CreatedTime   = System.DateTime.Now;
                MyAdvantechDAL.AddConfigurationHubConfiguredRecords(myEntity);
                result.IsUpdated = true;
            }
            catch (Exception ex)
            {
                result.IsUpdated     = false;
                result.ServerMessage = ex.ToString();
            }

            return(result);
        }
Exemplo n.º 2
0
        public static decimal GetBBWebPrice(String PartNo)
        {
            decimal _webprice = 0;

            DataTable _dt = MyAdvantechDAL.GetBBWebPrice(PartNo);

            if (_dt != null && _dt.Rows.Count > 0)
            {
                decimal.TryParse(_dt.Rows[0]["L1Price"].ToString(), out _webprice);
            }
            _dt = null;
            return(_webprice);
        }
Exemplo n.º 3
0
        public static Boolean IsCartPriceUpdated(String _CartID)
        {
            MyAdvantechDAL        my      = new MyAdvantechDAL();
            List <cart_DETAIL_V2> list_cd = my.GetCartDetailV2ByCartID(_CartID);

            if (list_cd.Where(d => d.otype != (int)LineItemType.BTOSParent && d.oUnit_Price != d.Unit_Price).Any())
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        public static void GetSalesOfficeAndGroupCodeBySalesCode(String SalesCode, out String SalesOffice, out String SalesGroup)
        {
            List <SAP_EMPLOYEE> se = new MyAdvantechDAL().GetSAPEmployeeBySalesCode(SalesCode);

            if (se != null && se.Count > 0)
            {
                SalesOffice = (from d in se select(String.IsNullOrEmpty(d.SALESOFFICE) ? "" : d.SALESOFFICE)).FirstOrDefault();
                SalesGroup  = (from d in se select(String.IsNullOrEmpty(d.SALESGROUP) ? "" : d.SALESGROUP)).FirstOrDefault();
            }
            else
            {
                SalesOffice = "";
                SalesGroup  = "";
            }
        }
Exemplo n.º 5
0
        public static Boolean IsODMTPart(string _PartNo)
        {
            SAP_PRODUCT sp = MyAdvantechDAL.GetSAPProduct(_PartNo);

            // ODM/T parts materail group is defined in ACLSQL7-[ePricerV2].[dbo].[ItemNoProductType]
            if (
                (sp != null && !String.IsNullOrEmpty(sp.MATERIAL_GROUP))
                &&
                (sp.MATERIAL_GROUP.ToUpper().Equals("ODM") || sp.MATERIAL_GROUP.ToUpper().Equals("T") ||
                 sp.MATERIAL_GROUP.ToUpper().Equals("170-ODM") || sp.MATERIAL_GROUP.ToUpper().Equals("CM-ASSY") ||
                 sp.MATERIAL_GROUP.ToUpper().Equals("CM-PRDT"))
                )
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 6
0
 /// <summary>
 /// For part No to check CheckCompatibility
 /// </summary>
 /// <param name="partNos"></param>
 /// <param name="type"></param>
 /// <returns>True 表示產品內有不相容!,False 則可加入購物車!</returns>
 public static Tuple <bool, string> CheckCompatibility(List <string> partNos, Compatibility type)
 {
     if (partNos != null && type != null)
     {
         List <PRODUCT_COMPATIBILITY> pcList = MyAdvantechDAL.GetProductCompatibility(type);
         foreach (string partNo in partNos)
         {
             var checkList = partNos.ToList();
             checkList.Remove(partNo);
             Tuple <bool, string> result = DataAccess.DataCore.CBOMV2_ConfiguratorDAL.CheckCompatibility(partNo, checkList, pcList);
             if (result.Item1 == true)
             {
                 return(new Tuple <bool, string>(true, string.Format("This part - {0} is {1} with {2}", partNo, type.ToString().ToLower(), result.Item2)));
             }
         }
         return(new Tuple <bool, string>(false, string.Empty));
     }
     else
     {
         return(new Tuple <bool, string>(true, "No data!"));
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Web background job - Create Siebel Opportunity
        /// </summary>
        /// <param name="active"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        public static bool BatchCreateSiebelOpportunity(SiebelActive active)
        {
            string row_id   = string.Empty;
            string wsparas  = string.Empty;
            string wserrmsg = string.Empty;

            try {
                //先把狀態更新成Processing以免任何失敗造成job一直執行這筆指令
                active.UpdateActiveProcessing(SiebelActiveUpdatedUser.System);

                row_id = SiebelDAL.CreateSiebelOptyV2(active, ref wsparas, ref wserrmsg);

                if (!string.IsNullOrEmpty(wserrmsg))
                {
                    active.UpdateActiveFailed(SiebelActiveUpdatedUser.System, "Create Siebel Opportunity through Siebel web service failed: " + wserrmsg, wsparas);
                    return(false);
                }


                if (string.IsNullOrEmpty(row_id))
                {
                    active.UpdateActiveFailed(SiebelActiveUpdatedUser.System, "Opportunity Row id Siebel WS returned is string.isNullOrEmpty", wsparas);
                    return(false);
                }

                if (row_id.Equals("NULL", StringComparison.InvariantCultureIgnoreCase))
                {
                    active.UpdateActiveFailed(SiebelActiveUpdatedUser.System, "Opportunity Row id Siebel WS returned is Null string!", wsparas);
                    return(false);
                }
            }
            catch (Exception e) {
                active.UpdateActiveFailed(SiebelActiveUpdatedUser.System, "Create Siebel Opportunity failed: " + e.Message, wsparas);
                return(false);
            }

            try
            {
                /*
                 * 檢查SiebelActive裡面,是否有別的數據(同quoteID),
                 * 預防同一批次作業中,還要再Create Quote或Update Opty的情況
                 * Case 1: Create Opty後 還要Create Quote
                 * Case 2: Create Opty後 還要Update Opty
                 * Case 3: Create Opty後 先Update Opty 再Create Quote
                 */
                List <SiebelActive> list = SiebelDAL.GetSiebelActiveByQuoteID(active.QuoteID, active.ID); //必須排除自己這筆紀錄

                if (list != null)
                {
                    foreach (SiebelActive sa in list)
                    {
                        //sa.OptyID = row_id;
                        //sa.Update();
                        SiebelDAL.updateOptyID(sa.ID, row_id);
                    }
                }

                //2015/4/27 Also have to check and update [MyAdvantechGlobal].[CARTMASTERV2].[optyID] after creating Opportunity successfully
                MyAdvantechDAL.UpdateOptyID(active.QuoteID, row_id);

                /*
                 * end
                 */

                //建立Siebel opty成功
                active.UpdateActiveSuccess(SiebelActiveUpdatedUser.System, wsparas);

                active.UpdateOptyIDtoOptyQuote(active.QuoteID, row_id);

                ////檢查optyQuote table 把optyId跟相關的數據一併更新過去
                //if (active.SiebelOpty == null)
                //{
                //    optyQuote opty = new optyQuote();
                //    opty.quoteId = active.QuoteID;
                //    opty.optyId = active.OptyID;
                //    opty.optyStage = active.OptyStage;
                //    opty.Opty_Owner_Email = active.OptyOwnerEmail;
                //    opty.Add();
                //}
                //else
                //{
                //    active.SiebelOpty.optyId = active.OptyID;
                //    active.SiebelOpty.optyName = active.OptyName;
                //    active.SiebelOpty.optyStage = active.OptyStage;
                //    active.SiebelOpty.Opty_Owner_Email = active.OptyOwnerEmail;
                //    active.SiebelOpty.Update();
                //}
                return(true);
            }
            catch (Exception ex)
            {
                active.UpdateActiveFailed(SiebelActiveUpdatedUser.System, "Create Siebel Opportunity failed: " + ex.ToString(), wsparas);
                return(false);
            }
        }
Exemplo n.º 8
0
        public static Boolean isATWPartsWithoutZMIP(List <String> _parts, String _org, String _companyID, ref List <String> _invalidparts)
        {
            List <String> StandardParts            = new List <String>();
            List <String> StandardPartsProductType = new List <string> {
                "ZFIN", "ZOEM", "T"
            };

            foreach (String part in _parts)
            {
                List <String> temp = new List <string>();

                // Split pipeline items
                if (part.Contains("|"))
                {
                    foreach (var i in part.Split('|').ToList())
                    {
                        temp.Add(i);
                    }
                }
                else
                {
                    temp.Add(part);
                }

                foreach (String t in temp)
                {
                    SAP_PRODUCT sp = MyAdvantechDAL.GetSAPProduct(t);
                    if (sp != null && StandardPartsProductType.Contains(sp.PRODUCT_TYPE))
                    {
                        StandardParts.Add(t);
                    }
                }
            }

            if (StandardParts.Count > 0)
            {
                SAP_DIMCOMPANY sc = DataAccess.DataCore.MyAdvantech.SAPCompanyHelper.GetSAPDIMCompanyByID(_companyID).FirstOrDefault();

                Order _order = new Order();
                _order.Currency    = (sc != null && !String.IsNullOrEmpty(sc.CURRENCY)) ? sc.CURRENCY : "TWD";
                _order.OrgID       = _org;
                _order.DistChannel = "10";
                _order.Division    = "00";
                foreach (String part in StandardParts)
                {
                    _order.AddLooseItem(part);
                }
                _order.SetOrderPartnet(new OrderPartner(_companyID, _org, OrderPartnerType.SoldTo));
                _order.SetOrderPartnet(new OrderPartner(_companyID, _org, OrderPartnerType.ShipTo));
                _order.SetOrderPartnet(new OrderPartner(_companyID, _org, OrderPartnerType.BillTo));

                // Do order simulation
                String _errMsg = String.Empty;
                Advantech.Myadvantech.DataAccess.SAPDAL.SimulateOrder(ref _order, ref _errMsg);

                if (_order != null && String.IsNullOrEmpty(_errMsg))
                {
                    foreach (Product p in _order.LineItems)
                    {
                        if (p.MinimumPrice != null && (p.MinimumPrice == -1 || p.MinimumPrice == 0))
                        {
                            _invalidparts.Add(p.PartNumber);
                        }
                    }
                }
            }

            if (_invalidparts.Count > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 9
0
        public static Boolean IsInvalidParts(String _CompanyID, String _ORGID, String _PartNo, String _Plant, String _CountryCode, Boolean _isInternalUser, ref String _Msg)
        {
            // Bypass all parts validation for ACN per Jingjing's request.
            if (_ORGID.ToString().ToUpper().StartsWith("CN"))
            {
                return(false);
            }


            // 1. Check 968T
            if (_PartNo.StartsWith("968T"))
            {
                if (!Business.UserRoleBusinessLogic.CanSee968TParts(_CompanyID))
                {
                    _Msg = "Due to MS licenses policy it is not allowed to add part numbers start with 968T.";
                    return(true);
                }
            }
            //-------------------------------------------------------------------------------------------------------------


            // 2. Check T/P
            if (!_isInternalUser)
            {
                SAP_PRODUCT sp = MyAdvantechDAL.GetSAP_ProductByOrg(_PartNo, _ORGID);
                if (sp != null && !String.IsNullOrEmpty(sp.MATERIAL_GROUP))
                {
                    if (sp.MATERIAL_GROUP.ToUpper().Equals("PRODUCT") || sp.MATERIAL_GROUP.ToUpper().Equals("ADLOGPROD"))
                    {
                        if (IsTPPart(_PartNo, _Plant))
                        {
                            _Msg = "This item is an ODM/OEM item, for detail please contact your sales representative.";
                            return(true);
                        }
                    }
                    else if (sp.MATERIAL_GROUP.ToUpper().Equals("ODM") || sp.MATERIAL_GROUP.ToUpper().Equals("ODM-P") || sp.MATERIAL_GROUP.ToUpper().Equals("T"))
                    {
                        _Msg = "This item is an ODM/T item, for detail please contact your sales representative.";
                        return(true);
                    }
                }
            }
            //-------------------------------------------------------------------------------------------------------------


            // 3. Check X/Y
            if (!_isInternalUser)
            {
                if (_PartNo.StartsWith("X", StringComparison.OrdinalIgnoreCase) || _PartNo.StartsWith("Y", StringComparison.OrdinalIgnoreCase))
                {
                    _Msg = "X/Y products are not available, for detail please contact your sales representative.";
                    return(true);
                }
            }
            //-------------------------------------------------------------------------------------------------------------

            // Ryan 20160921 Mark out litigation check logic, pull it as a independent validation in OrderInfo page.
            // 4. Check Patent Litigation
            //if (Business.PartBusinessLogic.PatentLitigationParts(_PartNo, _CountryCode, ref msg4))
            //{
            //    result4 = true;

            //    _Msg = msg4;
            //    return result4;
            //}
            //-------------------------------------------------------------------------------------------------------------

            return(false);
        }
Exemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="SystemPartNo"></param>
        /// <returns></returns>
        public static void ExpandSchneiderSystemPartToCart(String SystemPartNo, String cart_id, String user_id, String erp_id, String org_id)
        {
            String _plant = "TWH1"; string _Currency = "USD";

            //1. Expanding BOM
            DataTable dt = Advantech.Myadvantech.DataAccess.SAPDAL.ExpandSystemPartToBOM(SystemPartNo, 1);

            //1.5 Get deliveryplant from SAP_Product_Org. Ryan 20160316
            dt.Columns.Add("DELIVERYPLANT", typeof(String));
            List <String> list_partno = new List <String>();

            foreach (DataRow d in dt.Rows)
            {
                list_partno.Add("'" + d["Idnrk"].ToString() + "'");
            }
            String    sql_in   = string.Join(",", list_partno);
            String    sql_str  = "select PART_NO,ORG_ID,DELIVERYPLANT from SAP_PRODUCT_ORG where ORG_ID = 'TW01' AND PART_NO IN (" + sql_in + ")";
            DataTable dt_plant = SqlProvider.dbGetDataTable("MY", sql_str);

            foreach (DataRow d in dt.Rows)
            {
                DataRow[] rows = dt_plant.Select("PART_NO='" + d["Idnrk"].ToString() + "'");
                if (rows.Count() > 0)
                {
                    d["DELIVERYPLANT"] = dt_plant.Select("PART_NO='" + d["Idnrk"].ToString() + "'")[0][2];
                }
                else
                {
                    d["DELIVERYPLANT"] = _plant;
                }
            }


            //2. Get system part's unit price by order simulation
            Order _order = new Order();

            _order.Currency    = _Currency;
            _order.OrgID       = org_id;
            _order.DistChannel = "10";
            _order.Division    = "00";

            int i = 0;

            foreach (DataRow d in dt.Rows)
            {
                _order.AddLooseItem(Advantech.Myadvantech.DataAccess.SAPDAL.RemovePrecedingZeros(d["Idnrk"].ToString()), 1);
                _order.LineItems[i].PlantID = d["DELIVERYPLANT"].ToString();
                i++;
            }
            _order.SetOrderPartnet(new OrderPartner(erp_id, org_id, OrderPartnerType.SoldTo));
            _order.SetOrderPartnet(new OrderPartner(erp_id, org_id, OrderPartnerType.ShipTo));
            _order.SetOrderPartnet(new OrderPartner(erp_id, org_id, OrderPartnerType.BillTo));

            String _errMsg = String.Empty;

            Advantech.Myadvantech.DataAccess.SAPDAL.SimulateOrder(ref _order, ref _errMsg);
            List <Product> pr = _order.LineItems;

            //3.
            //_UnitPrice = 1000;
            //var totalcost = dt.AsEnumerable().Sum(x => x.Field<decimal>("Stprs"));

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

            // Get Bto_Parent Line_No
            List <cart_DETAIL_V2> cd = new MyAdvantechDAL().GetCartDetailV2ByCartID(cart_id);
            int Bto_LineNo           = 0;

            do
            {
                Bto_LineNo += 100;
            } while ((from d in cd where d.Cart_Id == cart_id && d.Line_No == Bto_LineNo select d).Any());

            // Set Bto_Parent
            cart_DETAIL_V2 CartDetail = new cart_DETAIL_V2();

            CartDetail.Cart_Id        = cart_id;
            CartDetail.Line_No        = Bto_LineNo;
            CartDetail.Part_No        = "PTRADE-BTO";
            CartDetail.Description    = SystemPartNo;
            CartDetail.Qty            = 1;
            CartDetail.CustMaterial   = "";
            CartDetail.Ew_Flag        = 0;
            CartDetail.SatisfyFlag    = 0;
            CartDetail.QUOTE_ID       = "";
            CartDetail.Delivery_Plant = _plant;
            CartDetail.higherLevel    = 0;
            CartDetail.otype          = (int)QuoteItemType.BtosParent;
            CartDetail.List_Price     = 0;
            CartDetail.Unit_Price     = 0;
            CartDetail.Itp            = 0;
            CartDetail.Description    = SystemPartNo;

            CartDetail.req_date = DateTime.Now.AddDays(1);
            String   LandStr = SAPDAL.SAPDAL.GetCalendarIDbyOrg(org_id.Substring(0, 1));
            DateTime reqdate = CartDetail.req_date.Value;

            SAPDAL.SAPDAL.Get_Next_WorkingDate_ByCode(ref reqdate, WebConfigurationManager.AppSettings["TWBTOSWorkingDay"].ToString(), LandStr);
            CartDetail.req_date = reqdate;
            CartDetail.due_date = reqdate;

            MyAdvantechContext.Current.cart_DETAIL_V2.Add(CartDetail);

            // Set Bto_Part
            Bto_LineNo++;
            foreach (DataRow d in dt.Rows)
            {
                CartDetail = new cart_DETAIL_V2();

                CartDetail.Cart_Id        = cart_id;
                CartDetail.Line_No        = Bto_LineNo;
                CartDetail.Part_No        = Advantech.Myadvantech.DataAccess.SAPDAL.RemovePrecedingZeros(d["Idnrk"].ToString());
                CartDetail.Description    = d["Ojtxp"].ToString();
                CartDetail.Qty            = Convert.ToInt32(d["Menge"]);
                CartDetail.CustMaterial   = "";
                CartDetail.Ew_Flag        = 0;
                CartDetail.SatisfyFlag    = 0;
                CartDetail.QUOTE_ID       = "";
                CartDetail.Delivery_Plant = d["DELIVERYPLANT"].ToString();
                CartDetail.higherLevel    = 100;
                CartDetail.otype          = (int)QuoteItemType.Part;

                // Get req_date
                CartDetail.req_date = DateTime.Now.AddDays(1);
                LandStr             = SAPDAL.SAPDAL.GetCalendarIDbyOrg(org_id.Substring(0, 1));
                reqdate             = CartDetail.req_date.Value;
                SAPDAL.SAPDAL.Get_Next_WorkingDate_ByCode(ref reqdate, "0", LandStr);
                CartDetail.req_date = reqdate;
                CartDetail.due_date = reqdate;

                // Set list price
                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;
                Bto_LineNo++;
                MyAdvantechContext.Current.cart_DETAIL_V2.Add(CartDetail);
            }
            MyAdvantechContext.Current.SaveChanges();

            //With BOMTable.Columns
            //    .Remove("Mandt")
            //    '.Remove("Alprf") : .Remove("Alpgr") : .Remove("Ewahr")
            //    .Item("Alprf").ColumnName = "Alt. Item Rank Order" : .Item("Alpgr").ColumnName = "Alt. Item Grp." : .Item("Ewahr").ColumnName = "Usage Prob (%)"
            //    .Item("Matnr").ColumnName = "Parent Item" : .Item("Bstmi").ColumnName = "MoQ" : .Item("Ojtxb").ColumnName = "Parent Desc."
            //    .Item("Idnrk").ColumnName = "Child Item" : .Item("Ojtxp").ColumnName = "Child Desc." : .Item("Stprs").ColumnName = "Cost"
            //    .Item("Stprs_Usd").ColumnName = "USD Cost" : .Item("Werks").ColumnName = "Plant" : .Item("Waers").ColumnName = "Currency"
            //    .Item("Stufe").ColumnName = "Level" : .Item("Menge").ColumnName = "Component Qty." : .Item("Peinh").ColumnName = "Price Unit"
            //    .Item("Peinh_Usd").ColumnName = "USD Price Unit" : .Add("MPN") : .Add("Manufacture Name")
            //End With
        }
Exemplo n.º 11
0
        public static UpdateDBResult Configurator2Cart(String SelectedItems, String ERPID, String CartID, String Currency, String Org_ID, bool isPrj = false)
        {
            UpdateDBResult         updateresult = new UpdateDBResult();
            List <ConfiguredItems> items        = new List <ConfiguredItems>();

            try
            {
                // Remove all items in current cart for ACN
                if (Org_ID.StartsWith("CN"))
                {
                    CartDetailHelper.RemoveCartDetailByID(CartID);
                }

                List <ConfiguredItems> toAdditems = Newtonsoft.Json.JsonConvert.DeserializeObject <List <ConfiguredItems> >(SelectedItems);

                if (toAdditems == null || toAdditems.Count == 0)
                {
                    updateresult.IsUpdated     = false;
                    updateresult.ServerMessage = "No item was selected.";
                    return(updateresult);
                }

                // Split pipeline items
                foreach (ConfiguredItems c in toAdditems)
                {
                    if (c.name.Contains("|"))
                    {
                        //List<String> pipelineitems = c.name.Split('|').ToList();
                        //while (pipelineitems.Count > 0)
                        //{
                        //    ConfiguredItems newitem = new ConfiguredItems();
                        //    newitem.name = pipelineitems.First();
                        //    newitem.desc = c.desc;
                        //    newitem.qty = c.qty;
                        //    pipelineitems.RemoveAt(0);
                        //    toAdditems.Add(newitem);
                        //}
                        foreach (var i in c.name.Split('|').ToList())
                        {
                            SAP_PRODUCT sp = MyAdvantechDAL.GetSAPProduct(i);

                            ConfiguredItems newitem = new ConfiguredItems();
                            newitem.name        = i;
                            newitem.desc        = (sp != null && !String.IsNullOrEmpty(sp.PRODUCT_DESC)) ? sp.PRODUCT_DESC : c.desc;
                            newitem.qty         = c.qty;
                            newitem.isLooseItem = c.isLooseItem;
                            items.Add(newitem);
                        }
                    }
                    else
                    {
                        items.Add(c);
                    }
                }
                //if (toAdditems.Count > 0)
                //{
                //    items.RemoveAll(d => d.name.Contains("|"));
                //    items.AddRange(toAdditems);
                //}

                //ICC 2017/4/7 Add product compatibility check. To make sure all items are not incompatible.
                List <PRODUCT_COMPATIBILITY> pcList = MyAdvantechDAL.GetProductCompatibility(Compatibility.Incompatible);
                foreach (ConfiguredItems c in items)
                {
                    List <ConfiguredItems> copy = new List <ConfiguredItems>(items);
                    copy.Remove(c);
                    Tuple <bool, string> result = CheckCompatibility(c.name, copy.Select(p => p.name).ToList(), pcList);
                    if (result.Item1 == true)
                    {
                        updateresult.IsUpdated     = false;
                        updateresult.ServerMessage = string.Format("This part - {0} is {1} with {2}.", c.name, Compatibility.Incompatible.ToString().ToLower(), result.Item2);
                        return(updateresult);
                    }
                }

                //111
                //var _result = "'" + String.Join("','", items) + "'";
            }
            catch (Exception ex)
            {
                updateresult.IsUpdated     = false;
                updateresult.ServerMessage = ex.ToString();
                return(updateresult);
            }

            int NextHigherLevel    = 100;
            var objNextHigherLevel = SqlProvider.dbExecuteScalar("MY", "select max(line_no) from cart_DETAIL_V2 where cart_id = '" + CartID + "' and (otype = 0 or otype = 1)");

            if (objNextHigherLevel != null && !String.IsNullOrEmpty(objNextHigherLevel.ToString()))
            {
                NextHigherLevel = (Convert.ToInt32(objNextHigherLevel.ToString()) / 100 + 1) * 100;
            }
            int NextLooseItemLineNo    = 1;
            var objNextLooseItemLineNo = SqlProvider.dbExecuteScalar("MY", "select max(line_no) from cart_DETAIL_V2 where cart_id = '" + CartID + "' and otype = 0 ");

            if (objNextLooseItemLineNo != null && !String.IsNullOrEmpty(objNextLooseItemLineNo.ToString()))
            {
                NextLooseItemLineNo = Convert.ToInt32(objNextLooseItemLineNo.ToString()) + 1;
            }

            if (items.Count > 0)
            {
                try
                {
                    // For ACN, need to split BOTS root name with "/", ex: IPC-510-BTO/P4
                    items.Where(c => c.name.Contains("-BTO/")).ToList().ForEach(c => c.name = c.name.Split(new string[] { "/" }, StringSplitOptions.None)[0]);

                    // Simulate Product List to get price
                    Order _order = new Order();
                    _order.Currency    = Currency;
                    _order.OrgID       = Org_ID;
                    _order.DistChannel = "10";
                    _order.Division    = "00";
                    if (Org_ID.StartsWith("CN"))
                    {
                        if (System.Configuration.ConfigurationManager.AppSettings["ACNTaxRate"] != null)
                        {
                            _order.Tax = Convert.ToDecimal(System.Configuration.ConfigurationManager.AppSettings["ACNTaxRate"]);
                        }
                        else
                        {
                            _order.Tax = (Decimal)0.16;
                        }
                    }

                    foreach (ConfiguredItems c in items)
                    {
                        //Frank 20171222, if part's material is BTO then identify it as BTOS parent item
                        SAP_PRODUCT sap_p = MyAdvantechDAL.GetSAPProduct(c.name);

                        if (Org_ID.Equals("EU80") && c.isLooseItem)
                        {
                            _order.AddLooseItem(c.name, SAPDAL.GetPlantByOrg(Org_ID), NextLooseItemLineNo, c.qty);
                            NextLooseItemLineNo++;
                        }
                        else if (sap_p != null && (sap_p.MATERIAL_GROUP.Equals("BTOS", StringComparison.InvariantCultureIgnoreCase) || c.name.EndsWith("-BTO", StringComparison.OrdinalIgnoreCase)))
                        {
                            _order.AddBTOSParentItem(c.name, SAPDAL.GetPlantByOrg(Org_ID), NextHigherLevel, c.qty);
                        }
                        else
                        {
                            _order.AddBTOSChildItem(c.name, NextHigherLevel, SAPDAL.GetPlantByOrg(Org_ID), c.qty);
                        }
                    }
                    _order.SetOrderPartnet(new OrderPartner(ERPID, Org_ID, OrderPartnerType.SoldTo));
                    _order.SetOrderPartnet(new OrderPartner(ERPID, Org_ID, OrderPartnerType.ShipTo));
                    _order.SetOrderPartnet(new OrderPartner(ERPID, Org_ID, OrderPartnerType.BillTo));

                    String _errMsg = String.Empty;
                    Advantech.Myadvantech.DataAccess.SAPDAL.SimulateOrder(ref _order, ref _errMsg);
                    // End order simulation


                    if (_order != null && String.IsNullOrEmpty(_errMsg))
                    {
                        foreach (Product p in _order.LineItems)
                        {
                            cart_DETAIL_V2 CartDetail = new cart_DETAIL_V2();
                            CartDetail.Cart_Id = CartID;

                            if (p.LineItemType == LineItemType.LooseItem)
                            {
                                CartDetail.Line_No     = p.LineNumber;
                                CartDetail.higherLevel = 0;
                            }
                            else if (p.LineItemType == LineItemType.BTOSParent)
                            {
                                CartDetail.Line_No     = NextHigherLevel;
                                CartDetail.higherLevel = 0;
                            }
                            else
                            {
                                CartDetail.Line_No     = p.LineNumber;
                                CartDetail.higherLevel = NextHigherLevel;
                            }

                            CartDetail.Part_No     = p.PartNumber;
                            CartDetail.Description = items.Where(i => i.name == p.PartNumber).FirstOrDefault().desc;
                            CartDetail.Qty         = p.Quantity;
                            CartDetail.Ew_Flag     = 0;
                            CartDetail.SatisfyFlag = 0;
                            CartDetail.QUOTE_ID    = "";
                            CartDetail.Category    = items.Where(i => i.name == p.PartNumber).FirstOrDefault().category;

                            //For ACN project, set customer material value = original customer part No.
                            if (isPrj == true && p.LineItemType == LineItemType.BTOSParent && !string.IsNullOrEmpty(CartDetail.Category) && CartDetail.Category.ToUpper().StartsWith("CM-"))
                            {
                                CartDetail.CustMaterial = CartDetail.Category;
                            }
                            else
                            {
                                CartDetail.CustMaterial = "";
                            }

                            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;
                            }
                            else if (CartDetail.Line_No % 100 > 0 && CartDetail.Line_No > 100)
                            {
                                CartDetail.otype = (int)QuoteItemType.BtosPart;
                            }
                            CartDetail.due_date = CartDetail.req_date;

                            CartDetail.Delivery_Plant = GetDeliveryPlant(ERPID, 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
                            {
                                CartDetail.List_Price = p.ListPrice;
                                CartDetail.Unit_Price = p.UnitPrice;
                                CartDetail.Itp        = 0;
                            }

                            // Get product info from sap_product table
                            DataTable sapproduct_dt = SqlProvider.dbGetDataTable("MY", "select * from sap_product where part_no = '" + p.PartNumber + "'");
                            if (sapproduct_dt != null && sapproduct_dt.Rows.Count > 0)
                            {
                                CartDetail.Model_No = sapproduct_dt.Rows[0]["Model_No"].ToString();
                            }


                            MyAdvantechContext.Current.cart_DETAIL_V2.Add(CartDetail);
                        }
                        MyAdvantechContext.Current.SaveChanges();
                        updateresult.IsUpdated = true;
                    }
                    else
                    {
                        updateresult.IsUpdated     = false;
                        updateresult.ServerMessage = _errMsg;
                    }
                }
                catch (Exception ex)
                {
                    updateresult.IsUpdated     = false;
                    updateresult.ServerMessage = ex.ToString();
                }
            }
            else
            {
                updateresult.IsUpdated = false;
            }

            return(updateresult);
        }
Exemplo n.º 12
0
        public void SetQuoteItems(List <QuotationDetail> quoteDetails)
        {
            this.QuoteItems.Clear();

            this.QuoteItems = quoteDetails
                              .Select(x => new QuoteItemViewModel()
            {
                QuoteId                      = x.quoteId,
                LineNo                       = x.line_No.Value,
                PartNo                       = x.partNo,
                Description                  = x.description,
                ListPrice                    = x.listPrice.Value,
                UnitPrice                    = x.unitPrice.Value,
                QuotingPrice                 = x.newUnitPrice.Value,
                Itp                          = x.itp.Value,
                NewItp                       = x.newItp.Value,
                Qty                          = x.qty.Value,
                CurrentQty                   = x.qty.Value,
                SprNo                        = x.sprNo,
                HigherLevel                  = x.HigherLevel.Value,
                DMF_Flag                     = x.DMF_Flag,
                ItemType                     = x.ItemType.Value,
                DeliveryPlant                = x.deliveryPlant,
                NCNR                         = Convert.ToBoolean(x.NCNR.GetValueOrDefault(0)),
                RecyclingFee                 = x.RecyclingFee.GetValueOrDefault(0),
                Category                     = x.category,
                ClassABC                     = x.classABC,
                Rohs                         = x.rohs.GetValueOrDefault(1),
                EWFlag                       = x.ewFlag.GetValueOrDefault(0),
                RequiredDate                 = x.reqDate.GetValueOrDefault(DateTime.Now.AddDays(5)),
                DueDate                      = x.dueDate.GetValueOrDefault(DateTime.Now.AddDays(5)),
                SatisfyFlag                  = x.satisfyFlag.GetValueOrDefault(0),
                CanBeConfirmed               = x.canBeConfirmed.GetValueOrDefault(1),
                CusMaterial                  = x.custMaterial,
                Inventory                    = x.inventory.GetValueOrDefault(0),
                ModelNo                      = x.modelNo,
                VirtualPartNo                = x.VirtualPartNo,
                Recfigid                     = x.RECFIGID,
                SequenceNo                   = x.SequenceNo.GetValueOrDefault(0),
                IsEWPart                     = x.IsEWpartnoX,
                EWDrpIsEditable              = (!x.IsEWpartnoX && x.ItemType != (int)LineItemType.BTOSChild && x.IsServicePartX == false && x.IsSoftwarePart == false),
                PostTaxListPrice             = x.PostTaxListPrice,
                PostTaxUnitPrice             = x.PostTaxUnitPrice,
                PostTaxQuotingPrice          = x.PostTaxNewUnitPrice,
                PostTaxBtoParentListPrice    = quoteDetails.Where(d => d.quoteId.Equals(x.quoteId) && d.HigherLevel == x.line_No).Sum(d => d.PostTaxListPrice),
                PostTaxBtoParentUnitPrice    = quoteDetails.Where(d => d.quoteId.Equals(x.quoteId) && d.HigherLevel == x.line_No).Sum(d => d.PostTaxUnitPrice),
                PostTaxBtoParentQuotingPrice = quoteDetails.Where(d => d.quoteId.Equals(x.quoteId) && d.HigherLevel == x.line_No).Sum(d => d.PostTaxNewUnitPrice),
                PostTaxBtoParentSubTotal     = quoteDetails.Where(d => d.quoteId.Equals(x.quoteId) && d.HigherLevel == x.line_No).Sum(d => d.PostTaxSubTotal)
            })
                              .ToList();

            //Extend warranty options
            var ExWarrantyList = MyAdvantechDAL.GetExtendedWarrantyByOrg(this.Org);

            foreach (var ewItem in ExWarrantyList)
            {
                foreach (var quoteItem in this.QuoteItems)
                {
                    quoteItem.EWPartOptions.Add(new SelectListItem()
                    {
                        Text     = ewItem.EW_PartNO,
                        Value    = ewItem.ID.ToString(),
                        Selected = ewItem.ID == quoteItem.EWFlag
                    });
                }
            }

            //Prepare parent items
            foreach (var item in this.QuoteItems)
            {
                if (item.PartNo.IndexOf("-BTO", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    this.ParentItemOptions.Add(new SelectListItem()
                    {
                        Text     = item.PartNo,
                        Value    = item.LineNo.ToString(),
                        Selected = item.PartNo == this.currentPartentOption
                    });
                }
            }
        }
Exemplo n.º 13
0
        public static UpdateResult Configurator2Cart(string cartId, int parentLineNo, string orgId)
        {
            UpdateResult           updateResult = new UpdateResult();
            List <ConfiguredItems> items        = new List <ConfiguredItems>();

            try
            {
                HubConfiguredResult hcr = MyAdvantechDAL.GetHubConfiguredResultsWithLineNo(cartId, parentLineNo);
                if (hcr != null)
                {
                    // Remove all items in current cart for ACN
                    if (orgId.StartsWith("CN"))
                    {
                        CartDetailHelper.RemoveCartDetailByID(cartId);
                    }

                    List <ConfiguredItems> toAdditems = Newtonsoft.Json.JsonConvert.DeserializeObject <List <ConfiguredItems> >(hcr.SelectedItems);

                    if (toAdditems == null || toAdditems.Count == 0)
                    {
                        updateResult.IsUpdated     = false;
                        updateResult.ServerMessage = "No item was selected.";
                        return(updateResult);
                    }

                    // Split pipeline items
                    foreach (ConfiguredItems c in toAdditems)
                    {
                        if (c.name.Contains("|"))
                        {
                            foreach (var i in c.name.Split('|').ToList())
                            {
                                SAP_PRODUCT sp = MyAdvantechDAL.GetSAPProduct(i);

                                ConfiguredItems newitem = new ConfiguredItems();
                                newitem.name = i;
                                newitem.desc = (sp != null && !String.IsNullOrEmpty(sp.PRODUCT_DESC)) ? sp.PRODUCT_DESC : c.desc;
                                newitem.qty  = c.qty;
                                //newitem.isLooseItem = c.isLooseItem;
                                items.Add(newitem);
                            }
                        }
                        else
                        {
                            items.Add(c);
                        }
                    }

                    // Get next higherlevel & next loose line no.
                    int NextHigherLevel    = hcr.ParentLineNo;
                    var objNextHigherLevel = SqlProvider.dbExecuteScalar("MY", "select max(line_no) from cart_DETAIL_V2 where cart_id = '" + cartId + "' and (otype = 0 or otype = 1)");
                    if (objNextHigherLevel != null && !String.IsNullOrEmpty(objNextHigherLevel.ToString()))
                    {
                        NextHigherLevel = (Convert.ToInt32(objNextHigherLevel.ToString()) / 100 + 1) * 100;
                    }
                    int NextLooseItemLineNo    = 1;
                    var objNextLooseItemLineNo = SqlProvider.dbExecuteScalar("MY", "select max(line_no) from cart_DETAIL_V2 where cart_id = '" + cartId + "' and otype = 0 ");
                    if (objNextLooseItemLineNo != null && !String.IsNullOrEmpty(objNextLooseItemLineNo.ToString()))
                    {
                        NextLooseItemLineNo = Convert.ToInt32(objNextLooseItemLineNo.ToString()) + 1;
                    }

                    if (items.Count > 0)
                    {
                        // For ACN, need to split BOTS root name with "/", ex: IPC-510-BTO/P4
                        items.Where(c => c.name.Contains("-BTO/")).ToList().ForEach(c => c.name = c.name.Split(new string[] { "/" }, StringSplitOptions.None)[0]);

                        // Simulate Product List to get price
                        Order _order = new Order();
                        _order.Currency    = hcr.Currency;
                        _order.OrgID       = orgId;
                        _order.DistChannel = "10";
                        _order.Division    = "00";
                        if (orgId.StartsWith("CN"))
                        {
                            if (System.Configuration.ConfigurationManager.AppSettings["ACNTaxRate"] != null)
                            {
                                _order.Tax = Convert.ToDecimal(System.Configuration.ConfigurationManager.AppSettings["ACNTaxRate"]);
                            }
                            else
                            {
                                _order.Tax = (Decimal)0.16;
                            }
                        }

                        foreach (ConfiguredItems c in items)
                        {
                            //Frank 20171222, if part's material is BTO then identify it as BTOS parent item
                            SAP_PRODUCT sap_p = MyAdvantechDAL.GetSAPProduct(c.name);

                            if (orgId.Equals("EU80") && c.isLooseItem)
                            {
                                _order.AddLooseItem(c.name, SAPDAL.GetPlantByOrg(orgId), NextLooseItemLineNo, c.qty);
                                NextLooseItemLineNo++;
                            }
                            else if (sap_p != null && (sap_p.MATERIAL_GROUP.Equals("BTOS", StringComparison.InvariantCultureIgnoreCase) || c.name.EndsWith("-BTO", StringComparison.OrdinalIgnoreCase)))
                            {
                                _order.AddBTOSParentItem(c.name, SAPDAL.GetPlantByOrg(orgId), NextHigherLevel, c.qty);
                            }
                            else
                            {
                                _order.AddBTOSChildItem(c.name, NextHigherLevel, SAPDAL.GetPlantByOrg(orgId), c.qty);
                            }
                        }
                        _order.SetOrderPartnet(new OrderPartner(hcr.CompanyID, orgId, OrderPartnerType.SoldTo));
                        _order.SetOrderPartnet(new OrderPartner(hcr.CompanyID, orgId, OrderPartnerType.ShipTo));
                        _order.SetOrderPartnet(new OrderPartner(hcr.CompanyID, orgId, OrderPartnerType.BillTo));

                        String _errMsg = String.Empty;
                        Advantech.Myadvantech.DataAccess.SAPDAL.SimulateOrder(ref _order, ref _errMsg);
                        // End order simulation


                        if (_order != null && String.IsNullOrEmpty(_errMsg))
                        {
                            foreach (Product p in _order.LineItems)
                            {
                                cart_DETAIL_V2 CartDetail = new cart_DETAIL_V2();
                                CartDetail.Cart_Id = cartId;

                                if (p.LineItemType == LineItemType.LooseItem)
                                {
                                    CartDetail.Line_No     = p.LineNumber;
                                    CartDetail.higherLevel = 0;
                                }
                                else if (p.LineItemType == LineItemType.BTOSParent)
                                {
                                    CartDetail.Line_No     = NextHigherLevel;
                                    CartDetail.higherLevel = 0;
                                }
                                else
                                {
                                    CartDetail.Line_No     = p.LineNumber;
                                    CartDetail.higherLevel = NextHigherLevel;
                                }

                                CartDetail.Part_No      = p.PartNumber;
                                CartDetail.Description  = items.Where(i => i.name == p.PartNumber).FirstOrDefault().desc;
                                CartDetail.Qty          = p.Quantity;
                                CartDetail.Ew_Flag      = 0;
                                CartDetail.SatisfyFlag  = 0;
                                CartDetail.QUOTE_ID     = "";
                                CartDetail.Category     = items.Where(i => i.name == p.PartNumber).FirstOrDefault().category;
                                CartDetail.CustMaterial = "";

                                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;
                                }
                                else if (CartDetail.Line_No % 100 > 0 && CartDetail.Line_No > 100)
                                {
                                    CartDetail.otype = (int)QuoteItemType.BtosPart;
                                }
                                CartDetail.due_date = CartDetail.req_date;

                                CartDetail.Delivery_Plant = SAPDAL.GetDeliveryPlant(hcr.CompanyID, orgId, 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
                                {
                                    CartDetail.List_Price = p.ListPrice;
                                    CartDetail.Unit_Price = p.UnitPrice;
                                    CartDetail.Itp        = 0;
                                }

                                // Get product info from sap_product table
                                DataTable sapproduct_dt = SqlProvider.dbGetDataTable("MY", "select * from sap_product where part_no = '" + p.PartNumber + "'");
                                if (sapproduct_dt != null && sapproduct_dt.Rows.Count > 0)
                                {
                                    CartDetail.Model_No = sapproduct_dt.Rows[0]["Model_No"].ToString();
                                }


                                MyAdvantechContext.Current.cart_DETAIL_V2.Add(CartDetail);
                            }
                            MyAdvantechContext.Current.SaveChanges();
                            updateResult.IsUpdated = true;
                        }
                        else
                        {
                            updateResult.IsUpdated     = false;
                            updateResult.ServerMessage = _errMsg;
                        }
                    }
                }
                else
                {
                    updateResult.IsUpdated     = false;
                    updateResult.ServerMessage = "No matched record found.";
                }
            }
            catch (Exception ex)
            {
                updateResult.IsUpdated     = false;
                updateResult.ServerMessage = ex.ToString();
            }

            return(updateResult);
        }