Ejemplo n.º 1
0
        public ActionResult RefreshDetails(string numTransaction, string terminalId, TrDetailsViewModel vmodel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ////Add detail
                    if (Session["Language"] == null)
                    {
                        Session["Language"] = ConfigurationManager.AppSettings["Language"];
                    }
                    string language = Session["Language"].ToString();
                    TransactionBL.AddNewTransactionDetail(vmodel.AddProduct, terminalId, numTransaction, vmodel.Minus, language);
                }
                //Find details with id transaction  + Add itemSubTotal
                var detailsListTot = TransactionBL.ListDetailsWithTot(numTransaction);
                //Sum subTotItems
                ViewBag.subTot1           = TransactionBL.SumItemsSubTot(detailsListTot);
                vmodel.DetailsListWithTot = detailsListTot;
                return(PartialView("_PartialTransactionDetail", vmodel));
            }
            catch (InvalidOperationException ex)
            {
                //to do insert to log file
                var e1 = ex.GetBaseException(); // --> log
                var e4 = ex.Message;            // --> log
                var e5 = ex.Source;             // --> log
                var e8 = ex.GetType();          // --> log
                var e9 = ex.GetType().Name;     // --> log

                ViewBag.ErrorAdd = "N° de produit invalide";
                return(PartialView("_PartialTransactionDetail", vmodel));
            }
            catch (Exception ex)
            {
                //to do insert to log file
                var e1 = ex.GetBaseException(); // --> log
                var e4 = ex.Message;            // --> log
                var e5 = ex.Source;             // --> log
                var e8 = ex.GetType();          // --> log
                var e9 = ex.GetType().Name;     // --> log

                return(View("Error"));
            }
        }
Ejemplo n.º 2
0
        internal static IList <TrDetailsViewModel> AddSubTotalPerDetailToList(IList <TRANSACTION_DETAILS> detailsList)
        {
            IList <TrDetailsViewModel> vmList = new List <TrDetailsViewModel>();

            foreach (var item in detailsList)
            {
                var     p = item.price;
                var     q = item.quantity;
                var     d = item.discount;
                decimal?st;
                if (p == 0 || q == 0)
                {
                    st = 0;
                }
                else if (d == 0 || d == null)
                {
                    st = (p * q);
                }
                else
                {
                    //ex: (100*2)*0.05 = 10
                    var temp = (p * q) * d;
                    st = (p * q) - temp;
                }

                //find code product
                int                id   = item.productId;
                string             code = ProductBL.FindCodeProductById(id);
                TrDetailsViewModel vm   = new TrDetailsViewModel
                {
                    ProductName = item.nameItem,
                    ProductCode = code,
                    Price       = p,
                    Quantity    = q,
                    ProductVat  = item.vatItem,
                    Discount    = item.discount,
                    TotalItem   = st
                };
                vmList.Add(vm);
            }

            return(vmList);
        }
Ejemplo n.º 3
0
        public void SumItemsSubTot_4detailsListTot25_Return100()
        {
            TrDetailsViewModel detail1 = new TrDetailsViewModel();
            TrDetailsViewModel detail2 = new TrDetailsViewModel();
            TrDetailsViewModel detail3 = new TrDetailsViewModel();
            TrDetailsViewModel detail4 = new TrDetailsViewModel();

            detail1.TotalItem = 25;
            detail2.TotalItem = 25;
            detail3.TotalItem = 25;
            detail4.TotalItem = 25;

            IList <TrDetailsViewModel> detailsListTot = new List <TrDetailsViewModel>
            {
                detail1,
                detail2,
                detail3,
                detail4
            };

            decimal result = (decimal)TransactionBL.SumItemsSubTot(detailsListTot);

            Assert.AreEqual(100, result);
        }