public IActionResult Update([FromBody] CrudViewModel <PaymentReceive> payload)
        {
            PaymentReceive paymentReceive = payload.value;

            _context.PaymentReceive.Update(paymentReceive);
            _context.SaveChanges();
            return(Ok(paymentReceive));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("PaymentReceiveId,InvoiceId,IsFullPayment,PaymentAmount,PaymentDate,PaymentReceiveName,PaymentTypeId,createdAt,EmployeeId,CashRepositoryId")] PaymentReceive paymentReceive)
        {
            var username = HttpContext.User.Identity.Name;

            if (ModelState.IsValid)
            {
                paymentReceive.PaymentReceiveName = _numberSequence.GetNumberSequence("ΕΙΣ");

                _context.Add(paymentReceive);
                await _context.SaveChangesAsync();

                var invoice = await _context.Invoice
                              .Include(i => i.Shipment)
                              .Include(p => p.PaymentReceive)
                              .SingleOrDefaultAsync(m => m.InvoiceId == paymentReceive.InvoiceId);

                var cashRepository = await _context.CashRepository.Where(x => x.CashRepositoryId == paymentReceive.CashRepositoryId).FirstOrDefaultAsync();

                cashRepository.TotalReceipts += paymentReceive.PaymentAmount;
                cashRepository.Balance        = cashRepository.TotalReceipts - cashRepository.TotalPayments;
                _context.Update(cashRepository);
                await _context.SaveChangesAsync();

                invoice.totalPaymentReceive = invoice.PaymentReceive.Sum(x => x.PaymentAmount);
                invoice.InvoiceBalance      = invoice.totalOrderAmount - invoice.totalPaymentReceive;

                if (invoice.InvoiceBalance == 0)
                {
                    invoice.Paid = true;
                }
                _context.Update(invoice);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Invoice", new { id = paymentReceive.InvoiceId }));

                //return RedirectToAction(nameof(Index));
            }
            var query =
                from Invoice in _context.Invoice
                select new
            {
                Invoice.InvoiceId,
                description = (Invoice.InvoiceNumber + " (" + Invoice.customerName + ")"),
                Invoice.Paid
            };

            ViewData["InvoiceId"]        = new SelectList(query.Where(x => x.Paid == false), "InvoiceId", "description", paymentReceive.InvoiceId);
            ViewData["PaymentTypeId"]    = new SelectList(_context.PaymentType, "PaymentTypeId", "PaymentTypeName", paymentReceive.PaymentTypeId);
            ViewData["employeeId"]       = new SelectList(_context.Employee, "EmployeeId", "DisplayName");
            ViewData["CashRepositoryId"] = new SelectList(_context.CashRepository, "CashRepositoryId", "CashRepositoryName");

            if (!(HttpContext.User.IsInRole("ApplicationUser") || HttpContext.User.IsInRole("Secretary")))
            {
                ViewData["EmployeeId"]       = new SelectList(_context.Employee.Where(x => x.PaymentReceiver == true && x.UserName == username), "EmployeeId", "DisplayName");
                ViewData["CashRepositoryId"] = new SelectList(_context.CashRepository.Where(x => x.Employee.UserName == username), "CashRepositoryId", "CashRepositoryName");
            }
            return(View(paymentReceive));
        }
        public IActionResult Insert([FromBody] CrudViewModel <PaymentReceive> payload)
        {
            PaymentReceive paymentReceive = payload.value;

            paymentReceive.PaymentReceiveName = _numberSequence.GetNumberSequence("PAYRCV");
            _context.PaymentReceive.Add(paymentReceive);
            _context.SaveChanges();
            return(Ok(paymentReceive));
        }
        public IActionResult Remove([FromBody] CrudViewModel <PaymentReceive> payload)
        {
            PaymentReceive paymentReceive = _context.PaymentReceive
                                            .Where(x => x.PaymentReceiveId == (int)payload.key)
                                            .FirstOrDefault();

            _context.PaymentReceive.Remove(paymentReceive);
            _context.SaveChanges();
            return(Ok(paymentReceive));
        }
예제 #5
0
 public ActionResult NhanThanhToan(PaymentReceive item)
 {
     using (Models.VTEntities db = new Models.VTEntities())
     {
         item.PaymentDate = DateTime.Now;
         db.PaymentReceives.Add(item);
         db.SaveChanges();
     }
     return(Json("", JsonRequestBehavior.AllowGet));
 }
        public IActionResult Insert([FromBody] CrudViewModel <PaymentReceive> payload)
        {
            PaymentReceive paymentReceive = payload.value;

            paymentReceive.PaymentReceiveName = _numberSequence.GetNumberSequence("PAYRCV");
            var result = _functionalService.Insert <PaymentReceive>(paymentReceive);

            paymentReceive = (PaymentReceive)result.Data;
            return(Ok(paymentReceive));
        }
예제 #7
0
        public async Task <IActionResult> Edit(string id, [Bind("PaymentReceiveId,InvoiceId,IsFullPayment,PaymentAmount,PaymentDate,PaymentReceiveName,PaymentTypeId,createdAt,EmployeeId,CashRepositoryId")] PaymentReceive paymentReceive)
        {
            var username = HttpContext.User.Identity.Name;
            var query    =
                from Invoice in _context.Invoice
                select new
            {
                Invoice.InvoiceId,
                description = (Invoice.InvoiceNumber + " (" + Invoice.customerName + ")"),
                Invoice.Paid
            };

            if (id != paymentReceive.PaymentReceiveId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(paymentReceive);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PaymentReceiveExists(paymentReceive.PaymentReceiveId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            if (!(HttpContext.User.IsInRole("ApplicationUser") || HttpContext.User.IsInRole("Secretary")))
            {
                ViewData["EmployeeId"]       = new SelectList(_context.Employee.Where(x => x.PaymentReceiver == true && x.UserName == username), "EmployeeId", "DisplayName");
                ViewData["CashRepositoryId"] = new SelectList(_context.CashRepository.Where(x => x.Employee.UserName == username), "CashRepositoryId", "CashRepositoryName", paymentReceive.CashRepositoryId);
            }


            ViewData["InvoiceId"]        = new SelectList(query.Where(x => x.Paid == false), "InvoiceId", "description", paymentReceive.InvoiceId);
            ViewData["PaymentTypeId"]    = new SelectList(_context.PaymentType, "PaymentTypeId", "PaymentTypeName", paymentReceive.PaymentTypeId);
            ViewData["employeeId"]       = new SelectList(_context.Employee, "EmployeeId", "DisplayName");
            ViewData["CashRepositoryId"] = new SelectList(_context.CashRepository, "CashRepositoryId", "CashRepositoryName", paymentReceive.CashRepositoryId);
            return(View(paymentReceive));
        }
예제 #8
0
        private void PopulateModel(PaymentReceive model, IDictionary values)
        {
            string PAYMENT_RECEIVE_ID   = nameof(PaymentReceive.PaymentReceiveId);
            string SalesOrderId         = nameof(PaymentReceive.SalesOrderId);
            string IS_FULL_PAYMENT      = nameof(PaymentReceive.IsFullPayment);
            string PAYMENT_AMOUNT       = nameof(PaymentReceive.PaymentAmount);
            string PAYMENT_DATE         = nameof(PaymentReceive.PaymentDate);
            string PAYMENT_RECEIVE_NAME = nameof(PaymentReceive.PaymentReceiveName);
            string PAYMENT_TYPE_ID      = nameof(PaymentReceive.PaymentTypeId);

            if (values.Contains(PAYMENT_RECEIVE_ID))
            {
                model.PaymentReceiveId = Convert.ToInt32(values[PAYMENT_RECEIVE_ID]);
            }

            if (values.Contains(SalesOrderId))
            {
                model.SalesOrderId = Convert.ToInt32(values[SalesOrderId]);
            }

            if (values.Contains(IS_FULL_PAYMENT))
            {
                model.IsFullPayment = Convert.ToBoolean(values[IS_FULL_PAYMENT]);
            }

            if (values.Contains(PAYMENT_AMOUNT))
            {
                model.PaymentAmount = Convert.ToDouble(values[PAYMENT_AMOUNT], CultureInfo.InvariantCulture);
            }

            if (values.Contains(PAYMENT_DATE))
            {
                model.PaymentDate = (System.DateTimeOffset)Convert.ChangeType(values[PAYMENT_DATE], typeof(System.DateTimeOffset));
            }

            if (values.Contains(PAYMENT_RECEIVE_NAME))
            {
                model.PaymentReceiveName = Convert.ToString(values[PAYMENT_RECEIVE_NAME]);
            }

            if (values.Contains(PAYMENT_TYPE_ID))
            {
                model.PaymentTypeId = Convert.ToInt32(values[PAYMENT_TYPE_ID]);
            }
        }
예제 #9
0
        public HttpResponseMessage Post(FormDataCollection form)
        {
            var model  = new PaymentReceive();
            var values = JsonConvert.DeserializeObject <IDictionary>(form.Get("values"));

            PopulateModel(model, values);

            Validate(model);
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, GetFullErrorMessage(ModelState)));
            }

            var result = _context.PaymentReceives.Add(model);

            _context.SaveChanges();

            return(Request.CreateResponse(HttpStatusCode.Created, result.PaymentReceiveId));
        }
        public ActionResult AddInvoice(SalesOrderModel SalesOrderModel)
        {
            SalesOrder salesOrder = new SalesOrder();
            bool       result     = false;
            string     massege    = "";

            try
            {
                if (SalesOrderModel.SalesOrder.Id == 0)
                {
                    if (SalesOrderModel.SalesOrder.PaymentAmount >= 0 && SalesOrderModel.SalesOrder.Total >= SalesOrderModel.SalesOrder.PaymentAmount)
                    {
                        SalesOrderModel.SalesOrder.SalesOrderId = Guid.NewGuid();
                        SalesOrderModel.SalesOrder.CreatedDate  = DateTime.Now;
                        SalesOrderModel.SalesOrder.WarehouseId  = Guid.NewGuid();
                        SalesOrderModel.SalesOrder.OrderDate    = DateTime.Now;
                        SalesOrderModel.SalesOrder.DelivaryDate = DateTime.Now;
                        SalesOrderModel.SalesOrder.SubTotal     = SalesOrderModel.SalesOrder.Amount - SalesOrderModel.SalesOrder.PaymentAmount;
                        salesFacade.Insert(SalesOrderModel.SalesOrder);
                        if (SalesOrderModel.SalesOrderDetails.Count > 0)
                        {
                            foreach (var item in SalesOrderModel.SalesOrderDetails)
                            {
                                item.SalesOrderDetailId = Guid.NewGuid();
                                item.SalesOrderId       = SalesOrderModel.SalesOrder.SalesOrderId;
                                #region Product Deduct
                                ProductWarehouseMap checkWarehouseProduct = pWMFacade.GetAll().Where(x => x.ProductId == item.ProductId && x.WarehouseId == item.WarehouseId).FirstOrDefault();
                                checkWarehouseProduct.Quantity = checkWarehouseProduct.Quantity - item.Quantity;
                                pWMFacade.Update(checkWarehouseProduct);

                                Product oldProduct = productsFacade.GetByProductId(item.ProductId);
                                oldProduct.Quantity = oldProduct.Quantity - item.Quantity;
                                productsFacade.Update(oldProduct);
                                #endregion
                                salesDetailFacade.Insert(item);
                            }
                        }

                        #region PaymentReceive

                        PaymentReceive payment = new PaymentReceive();
                        payment.PaymentId     = Guid.NewGuid();
                        payment.SalesOrderId  = SalesOrderModel.SalesOrder.SalesOrderId;
                        payment.BalanceDue    = SalesOrderModel.SalesOrder.Amount - SalesOrderModel.SalesOrder.PaymentAmount;
                        payment.PaymentAmount = SalesOrderModel.SalesOrder.PaymentAmount;
                        if (payment.BalanceDue == 0)
                        {
                            payment.PaymentStatus = "Paid";
                        }
                        else if (payment.BalanceDue == SalesOrderModel.SalesOrder.Amount)
                        {
                            payment.PaymentStatus = "UnPaid";
                        }
                        else
                        {
                            payment.PaymentStatus = "Partialy Paid";
                        }

                        payment.PaymentDate = SalesOrderModel.SalesOrder.PaymentDate != null ? SalesOrderModel.SalesOrder.PaymentDate.Value : DateTime.Now;
                        payment.Note        = SalesOrderModel.SalesOrder.PaymentNote;
                        payFacade.Insert(payment);
                    }
                    else
                    {
                        result  = false;
                        massege = "Payment amount should be less or equal to the Total amount";
                        return(Json(new { result = result, message = massege }));
                    }
                    #endregion
                }
                else
                {
                    PaymentReceive oldPayment = payFacade.GetPaymentBySOId(SalesOrderModel.SalesOrder.SalesOrderId);
                    SalesOrder     sales      = salesFacade.Get(SalesOrderModel.SalesOrder.Id);
                    if (SalesOrderModel.SalesOrder.PaymentAmount >= 0 && sales.Amount >= (oldPayment.PaymentAmount + SalesOrderModel.SalesOrder.PaymentAmount))
                    {
                        sales.OrderDate      = SalesOrderModel.SalesOrder.OrderDate;
                        sales.DelivaryDate   = SalesOrderModel.SalesOrder.DelivaryDate;
                        sales.DiscountAmount = SalesOrderModel.SalesOrder.DiscountAmount;
                        sales.Amount         = SalesOrderModel.SalesOrder.Amount;
                        sales.Freight        = SalesOrderModel.SalesOrder.Freight;
                        sales.Total          = SalesOrderModel.SalesOrder.Total;
                        salesFacade.Update(sales);
                        List <SalesOrderDetailVM> salesdetaillist = salesDetailFacade.GetAllSalesDetailsBySaleOrderId(sales.SalesOrderId);
                        if (SalesOrderModel.SalesOrderDetails.Count > 0)
                        {
                            foreach (var item in salesdetaillist)
                            {
                                ProductWarehouseMap productWarehouseMap = pWMFacade.GetAll().Where(x => x.ProductId == item.ProductId && x.WarehouseId == item.WarehouseId).FirstOrDefault();
                                if (productWarehouseMap != null)
                                {
                                    productWarehouseMap.Quantity = productWarehouseMap.Quantity + item.Quantity;
                                    pWMFacade.Update(productWarehouseMap);
                                }

                                Product oldProduct = productsFacade.GetByProductId(item.ProductId);
                                if (oldProduct != null)
                                {
                                    oldProduct.Quantity = oldProduct.Quantity + item.Quantity;
                                    productsFacade.Update(oldProduct);
                                }

                                salesDetailFacade.Delete(item.Id);
                            }
                            foreach (var item in SalesOrderModel.SalesOrderDetails)
                            {
                                SalesOrderDetail tempSalesOrderDetail = new SalesOrderDetail();
                                tempSalesOrderDetail.Price              = item.Price;
                                tempSalesOrderDetail.ProductId          = item.ProductId;
                                tempSalesOrderDetail.Quantity           = item.Quantity;
                                tempSalesOrderDetail.SalesOrderDetailId = Guid.NewGuid();
                                tempSalesOrderDetail.SalesOrderId       = SalesOrderModel.SalesOrder.SalesOrderId;
                                tempSalesOrderDetail.SubTotal           = item.SubTotal;
                                tempSalesOrderDetail.Total              = item.Total;
                                tempSalesOrderDetail.Amount             = item.Amount;
                                tempSalesOrderDetail.WarehouseId        = item.WarehouseId;

                                #region Product Deduct
                                ProductWarehouseMap checkWarehouseProduct = pWMFacade.GetAll().Where(x => x.ProductId == item.ProductId && x.WarehouseId == item.WarehouseId).FirstOrDefault();
                                if (checkWarehouseProduct != null)
                                {
                                    checkWarehouseProduct.Quantity = checkWarehouseProduct.Quantity - item.Quantity;
                                    pWMFacade.Update(checkWarehouseProduct);
                                }

                                Product oldProduct = productsFacade.GetByProductId(item.ProductId);
                                if (oldProduct != null)
                                {
                                    oldProduct.Quantity = oldProduct.Quantity - item.Quantity;
                                    productsFacade.Update(oldProduct);
                                }
                                #endregion

                                salesDetailFacade.Insert(tempSalesOrderDetail);
                            }
                        }

                        #region PaymentReceive



                        oldPayment.BalanceDue    = SalesOrderModel.SalesOrder.Amount - SalesOrderModel.SalesOrder.PaymentAmount;
                        oldPayment.PaymentAmount = (oldPayment.PaymentAmount + SalesOrderModel.SalesOrder.PaymentAmount);
                        oldPayment.BalanceDue    = SalesOrderModel.SalesOrder.Amount - oldPayment.PaymentAmount;
                        sales.SubTotal           = oldPayment.BalanceDue;
                        salesFacade.Update(sales);

                        if (oldPayment.BalanceDue == 0)
                        {
                            oldPayment.PaymentStatus = "Paid";
                        }
                        else if (oldPayment.BalanceDue == SalesOrderModel.SalesOrder.Amount)
                        {
                            oldPayment.PaymentStatus = "UnPaid";
                        }
                        else
                        {
                            oldPayment.PaymentStatus = "Partially Paid";
                        }

                        oldPayment.PaymentDate = SalesOrderModel.SalesOrder.PaymentDate != null ? SalesOrderModel.SalesOrder.PaymentDate.Value : DateTime.Now;
                        oldPayment.Note        = SalesOrderModel.SalesOrder.PaymentNote;
                        payFacade.Update(oldPayment);
                    }
                    else
                    {
                        result  = false;
                        massege = "Payment amount should be less or equal to the Total amount";
                        return(Json(new { result = result, message = massege }));
                    }
                    #endregion
                }
                result  = true;
                massege = "Invoice saved successfully";
            }
            catch (Exception ex)
            {
                result  = false;
                massege = "Invoice not saved";
            }
            return(Json(new { result = result, message = massege }));
        }
예제 #11
0
        // GET: PaymentReceive/Create
        public IActionResult Create(string id)
        {
            PaymentReceive pr = new PaymentReceive();

            var username = HttpContext.User.Identity.Name;
            var invoice  = (
                from Invoice in _context.Invoice
                select new
            {
                Invoice.InvoiceId,
                description = (Invoice.InvoiceNumber + " (" + Invoice.customerName + ")"),
                Invoice.Paid,
                Invoice.InvoiceBalance,
            }).ToList();

            invoice.Insert(0,
                           new
            {
                InvoiceId      = "0000",
                description    = "Επιλέξτε",
                Paid           = false,
                InvoiceBalance = 0.0m
            });

            var employee = (from Employee in _context.Employee
                            select new
            {
                Employee.EmployeeId,
                Employee.DisplayName,
                Employee.UserName,
                Employee.PaymentReceiver
            }).ToList();

            employee.Insert(0,
                            new
            {
                EmployeeId      = "0000",
                DisplayName     = "Επιλέξτε",
                UserName        = "",
                PaymentReceiver = true
            });

            if (id != null)
            {
                ViewData["InvoiceId"] = new SelectList(invoice, "InvoiceId", "description", id);
                pr.PaymentDate        = DateTime.Today;
                pr.InvoiceId          = id;
                pr.EmployeeId         = _context.Invoice.Where(x => x.InvoiceId == id).Include(x => x.Shipment).FirstOrDefault().Shipment.EmployeeId;
                pr.PaymentAmount      = _context.Invoice.Where(x => x.InvoiceId == id).FirstOrDefault().InvoiceBalance;
            }
            else
            {
                ViewData["InvoiceId"] = new SelectList(invoice, "InvoiceId", "description");
            }

            ViewData["PaymentTypeId"] = new SelectList(_context.PaymentType, "PaymentTypeId", "PaymentTypeName");
            if (!(HttpContext.User.IsInRole("ApplicationUser") || HttpContext.User.IsInRole("Secretary")))
            {
                ViewData["EmployeeId"] = new SelectList(employee.Where(x => x.PaymentReceiver == true && x.UserName == username), "EmployeeId", "DisplayName");
            }
            else
            {
                ViewData["employeeId"] = new SelectList(employee.Where(x => x.PaymentReceiver == true), "EmployeeId", "DisplayName");
            }
            ViewData["CashRepositoryId"] = new SelectList(_context.CashRepository.Where(x => x.EmployeeId == pr.EmployeeId), "CashRepositoryId", "CashRepositoryName");

            return(View(pr));
        }