Ejemplo n.º 1
0
        public SaleSummary GetSaleSummary(DateTime?FromDate, DateTime?ToDate, string CompanyCode, string search, Boolean IsInternal, Boolean IsTax)
        {
            SaleSummary        saleObj         = new SaleSummary();
            List <SaleSummary> saleSummaryList = null;

            try
            {
                saleSummaryList = _reportRepository.GetSaleSummary(FromDate, ToDate, CompanyCode, search, IsInternal, IsTax);
                decimal salesummarySum          = saleSummaryList.Where(SS => SS.RowType != "T").Sum(SS => SS.NetDue);
                decimal salesummaryTax          = saleSummaryList.Where(SS => SS.RowType != "T").Sum(SS => SS.TaxAmount);
                decimal salesummaryInvoice      = saleSummaryList.Where(SS => SS.RowType != "T").Sum(SS => SS.Invoiced);
                decimal salesummaryinvoicetotal = saleSummaryList.Where(SS => SS.RowType != "T").Sum(SS => SS.Total);
                decimal salesummarypaid         = saleSummaryList.Where(SS => SS.RowType != "T").Sum(SS => SS.Paid);


                saleObj.salesummarySum          = _commonBusiness.ConvertCurrency(salesummarySum, 2);
                saleObj.salesummaryInvoiced     = _commonBusiness.ConvertCurrency(salesummaryInvoice, 2);
                saleObj.salesummaryTotalInvoice = _commonBusiness.ConvertCurrency(salesummaryinvoicetotal, 2);
                saleObj.salesummarypaid         = _commonBusiness.ConvertCurrency(salesummarypaid, 2);
                saleObj.salesummaryTax          = _commonBusiness.ConvertCurrency(salesummaryTax, 2);
                saleObj.saleSummaryList         = saleSummaryList;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(saleObj);
        }
        public void PlaceOrder(SaleSummary finalOrder)
        {
            using (var context = new eBikesContext())
            {
                int? couponId = null;
                Guid guid     = Guid.NewGuid();

                if (finalOrder.CouponIdValue != "")
                {
                    couponId = context.Coupons.Where(x => x.CouponIDValue == finalOrder.CouponIdValue).Select(x => x.CouponID).SingleOrDefault();
                }

                //make sale first then sale details
                //create sell
                var newSale = new Sale();


                newSale.SaleDate    = DateTime.Today;
                newSale.UserName    = finalOrder.UserName;
                newSale.EmployeeID  = 1;
                newSale.TaxAmount   = finalOrder.TaxAmount;
                newSale.SubTotal    = finalOrder.SubTotal;
                newSale.CouponID    = couponId;
                newSale.PaymentType = finalOrder.PaymentType;

                foreach (var partDetail in finalOrder.Parts)
                {
                    var newSaleDetail = new SaleDetail();


                    int partId    = context.Parts.Where(x => x.Description == partDetail.PartDesc).Select(x => x.PartID).SingleOrDefault();
                    var qtyOnHand = context.Parts.Where(x => x.PartID == partId).Select(x => x.QuantityOnHand).SingleOrDefault();


                    var partToUpdate = context.Parts.Find(partId);

                    // backorder the order
                    if (partDetail.Qty > qtyOnHand)
                    {
                        newSaleDetail.PartID       = partId;
                        newSaleDetail.Quantity     = partDetail.Qty;
                        newSaleDetail.SellingPrice = partDetail.SellPrice;
                        newSaleDetail.Backordered  = true;
                        newSaleDetail.ShippedDate  = null;
                    }
                    else
                    {
                        newSaleDetail.PartID       = partId;
                        newSaleDetail.Quantity     = partDetail.Qty;
                        newSaleDetail.SellingPrice = partDetail.SellPrice;
                        newSaleDetail.Backordered  = false;
                        newSale.PaymentToken       = guid;
                        newSaleDetail.ShippedDate  = DateTime.Today;

                        partToUpdate.QuantityOnHand = qtyOnHand - partDetail.Qty;
                        //if (qtyOnHand - partDetail.Qty == 0)
                        //{
                        //    partToUpdate.Discontinued = true;
                        //}
                    }
                    //changing stock qty in Parts table
                    var existing = context.Entry(partToUpdate);
                    existing.State = EntityState.Modified;

                    newSale.SaleDetails.Add(newSaleDetail);
                }
                //remove cart itmes and cart
                var cartItemId = finalOrder.Parts.Select(x => x.CartItemId).FirstOrDefault();
                var cartId     = context.ShoppingCartItems.Find(cartItemId).ShoppingCartID;

                foreach (var item in finalOrder.Parts)
                {
                    var existing = context.ShoppingCartItems.Find(item.CartItemId);
                    context.ShoppingCartItems.Remove(existing);
                }
                //One save for all changes
                var existingCart = context.ShoppingCarts.Find(cartId);
                context.ShoppingCarts.Remove(existingCart);


                context.Sales.Add(newSale);
                context.SaveChanges();
            }
        }
Ejemplo n.º 3
0
 public CheckoutSummary()
 {
     SaleSummary   = new SaleSummary();
     TenderSummary = new TenderSummary();
 }