public static decimal GetACNPostTaxTotalMargin(List <Product> _items, Decimal _TaxRate)
        {
            decimal r      = -99999;
            decimal sumAmt = 0;
            decimal sumITP = 0;

            foreach (Product p in _items)
            {
                sumAmt += p.UnitPrice * _TaxRate * p.Quantity;

                if (PartBusinessLogic.isACNOSParts(p.PartNumber))
                {
                    sumITP += p.ITP * Convert.ToDecimal(1.20) * p.Quantity;
                }
                else if (PartBusinessLogic.IsPTD(p.PartNumber))
                {
                    sumITP += p.ITP * Convert.ToDecimal(1.22) * p.Quantity;
                }
                else
                {
                    sumITP += p.ITP * Convert.ToDecimal(1.24) * p.Quantity;
                }
            }
            if (sumAmt != 0)
            {
                r = (sumAmt - sumITP) / sumAmt;
            }
            return(r);
        }
Example #2
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();
            }
        }