Esempio n. 1
0
        public async Task <ActionResult <Customer> > SearchCustomer(VmSearchParams customer)
        {
            var data = await db.Customer.Where(c => c.CustomerMobileNo == customer.CustomerMobileNo || c.CustomerId == customer.CustomerId).Select(e => new { e.Address, e.CustomerId, e.CustomerMobileNo, e.CustomerName }).FirstOrDefaultAsync();

            Customer cm = new Customer()
            {
                CustomerId       = data.CustomerId,
                Address          = data.Address,
                CustomerMobileNo = data.CustomerMobileNo,
                CustomerName     = data.CustomerName
            };

            if (cm == null)
            {
                return(NotFound());
            }

            return(cm);
        }
Esempio n. 2
0
        public async Task <ActionResult <VmCustomerBillAndPayment> > CustomerBillAndPaymentDetails(VmSearchParams cm)
        {
            double   totalPaymentCount = 0;
            double   totalBillCount    = 0;
            double   duePaymentCount   = 0;
            Customer customer          = new Customer();

            if (cm.CustomerId > 0)
            {
                var data = await db.Customer.Where(c => c.CustomerId == cm.CustomerId).Select(e => new { e.Address, e.CustomerId, e.CustomerMobileNo, e.CustomerName }).FirstOrDefaultAsync();

                Customer cst = new Customer()
                {
                    CustomerId       = data.CustomerId,
                    CustomerMobileNo = data.CustomerMobileNo,
                    CustomerName     = data.CustomerName,
                    Address          = data.Address
                };
                customer = null;
                customer = cst;
            }
            else if (cm.CustomerMobileNo != null)
            {
                var data = await db.Customer.Where(c => c.CustomerMobileNo == cm.CustomerMobileNo).Select(e => new { e.Address, e.CustomerId, e.CustomerMobileNo, e.CustomerName }).FirstOrDefaultAsync();

                Customer cst = new Customer()
                {
                    CustomerId       = data.CustomerId,
                    CustomerMobileNo = data.CustomerMobileNo,
                    CustomerName     = data.CustomerName,
                    Address          = data.Address
                };
                customer = null;
                customer = cst;
            }
            else if (cm.CustomerName != null)
            {
                var data = await db.Customer.Where(c => c.CustomerName.ToLower() == cm.CustomerName.ToLower()).Select(e => new { e.Address, e.CustomerId, e.CustomerMobileNo, e.CustomerName }).FirstOrDefaultAsync();

                Customer cst = new Customer()
                {
                    CustomerId       = data.CustomerId,
                    CustomerMobileNo = data.CustomerMobileNo,
                    CustomerName     = data.CustomerName,
                    Address          = data.Address
                };
                customer = null;
                customer = cst;
            }
            else if (cm.Address != null)
            {
                var data = await db.Customer.Where(c => c.Address.ToLower() == cm.Address.ToLower()).Select(e => new { e.Address, e.CustomerId, e.CustomerMobileNo, e.CustomerName }).FirstOrDefaultAsync();

                Customer cst = new Customer()
                {
                    CustomerId       = data.CustomerId,
                    CustomerMobileNo = data.CustomerMobileNo,
                    CustomerName     = data.CustomerName,
                    Address          = data.Address
                };
                customer = null;
                customer = cst;
            }



            var customerPayments = await db.CustomerPayment.Where(cp => cp.CustomerId == customer.CustomerId).Select(p => new { p.CustomerId, p.CustomerPaymentId, p.PayAmount, p.PaymentDate }).ToListAsync();

            foreach (var item in customerPayments)
            {
                totalPaymentCount += item.PayAmount;
            }

            var customerBuyingList = await db.Product_Sell.Where(c => c.CustomerId == customer.CustomerId).Select(s => new { s.CategoryId, s.CustomerId, s.DateOfSell, s.Discount_Percentage, s.EmployeeId, s.Product_SellId, s.Quantity, s.SubTotalCost, s.UnitPrice }).ToListAsync();

            foreach (var item in customerBuyingList)
            {
                totalBillCount += item.SubTotalCost;
            }

            duePaymentCount = Convert.ToDouble(totalBillCount - totalPaymentCount);

            VmCustomerBillAndPayment vm = new VmCustomerBillAndPayment()
            {
                CustomerId       = customer.CustomerId,
                CustomerName     = customer.CustomerName,
                Address          = customer.Address,
                CustomerMobileNo = customer.CustomerMobileNo,
                TotalBill        = totalBillCount,
                TotalPayment     = totalPaymentCount,
                DueOfPayment     = duePaymentCount
            };


            return(vm);
        }
        public async Task <ActionResult <IEnumerable <VmProductSellDetails> > > Monthly_Product_SellList(VmSearchParams searchParams)
        {
            List <VmProductSellDetails> vmList          = new List <VmProductSellDetails>();
            List <Product_Sell>         productSellList = new List <Product_Sell>();

            var dataList = await _db.Product_Sell.Where(cp => cp.DateOfSell.Year == searchParams.DateOfSell.Year && cp.DateOfSell.Month == searchParams.DateOfSell.Month).ToListAsync();

            foreach (var data in dataList)
            {
                Product_Sell psel = new Product_Sell()
                {
                    Product_SellId      = data.Product_SellId,
                    Quantity            = data.Quantity,
                    UnitPrice           = data.UnitPrice,
                    Discount_Percentage = data.Discount_Percentage,
                    SubTotalCost        = data.SubTotalCost,
                    DateOfSell          = data.DateOfSell,
                    CategoryId          = data.CategoryId,
                    EmployeeId          = data.EmployeeId,
                    CustomerId          = data.CustomerId
                };

                productSellList.Add(psel);
            }

            foreach (var data in productSellList)
            {
                var emp = await _db.Employee.Where(e => e.EmployeeId == data.EmployeeId).Select(e => new { e.EmpAddress, e.EmployeeId, e.EmpMobileNo, e.EmpName, e.GenderId, e.ReligionId, e.ThanaId }).FirstOrDefaultAsync();

                var category = await _db.Category.Where(c => c.CategoryId == data.CategoryId).Select(c => new { c.CategoryId, c.CategoryName, c.BrandId }).FirstOrDefaultAsync();

                var brand = await _db.Brand.Where(b => b.BrandId == category.BrandId).Select(b => new { b.BrandId, b.BrandName, b.ProductId }).FirstOrDefaultAsync();

                var product = await _db.Product.Where(p => p.ProductId == brand.ProductId).Select(p => new { p.ProductId, p.ProductName }).FirstOrDefaultAsync();

                var customer = await _db.Customer.Where(cs => cs.CustomerId == data.CustomerId).Select(c => new { c.CustomerId, c.Address, c.CustomerMobileNo, c.CustomerName }).FirstOrDefaultAsync();

                VmProductSellDetails vm = new VmProductSellDetails()
                {
                    Product_SellId      = data.Product_SellId,
                    Quantity            = data.Quantity,
                    UnitPrice           = data.UnitPrice,
                    Discount_Percentage = data.Discount_Percentage,
                    SubTotalCost        = data.SubTotalCost,
                    DateOfSell          = data.DateOfSell,
                    CategoryId          = category.CategoryId,
                    CategoryName        = category.CategoryName,
                    BrandId             = brand.BrandId,
                    BrandName           = brand.BrandName,
                    ProductId           = product.ProductId,
                    ProductName         = product.ProductName,
                    EmployeeId          = emp.EmployeeId,
                    EmpName             = emp.EmpName,
                    CustomerId          = customer.CustomerId,
                    CustomerMobileNo    = customer.CustomerMobileNo,
                    CustomerName        = customer.CustomerName
                };
                vmList.Add(vm);
            }


            return(vmList);
        }