public PartialViewResult ViewInvoiceDetails(long deliveryId)
        {
            var delivery        = _iDeliveryManager.GetOrderByDeliveryId(deliveryId);
            var deliveryDetails = _iDeliveryManager.GetDeliveryDetailsInfoByDeliveryId(deliveryId);
            var orderInfo       = _iOrderManager.GetOrderInfoByTransactionRef(delivery.TransactionRef);
            var client          = _iClientManager.GetClientDeailsById(delivery.ClientId);
            var model           = new ViewInvoiceModel
            {
                Client          = client,
                Order           = orderInfo,
                Delivery        = delivery,
                DeliveryDetails = deliveryDetails
            };

            return(PartialView("_InvoiceDetailPartialPage", model));
        }
        public ActionResult Invoice(int id)
        {
            var invocedOrder = _iInvoiceManager.GetInvoicedOrderByInvoiceId(id);
            var orderInfo    = _iOrderManager.GetOrderInfoByTransactionRef(invocedOrder.TransactionRef);
            IEnumerable <InvoiceDetails> details = _iInvoiceManager.GetInvoicedOrderDetailsByInvoiceId(id);
            var client = _iClientManager.GetClientDeailsById(orderInfo.ClientId);

            ViewInvoiceModel model = new ViewInvoiceModel
            {
                Client           = client,
                Order            = orderInfo,
                Invoice          = invocedOrder,
                InvoiceDetailses = details
            };

            return(View(model));
        }
Example #3
0
        public ActionResult Invoice(int deliveryId)
        {
            var delivery        = _iDeliveryManager.GetOrderByDeliveryId(deliveryId);
            var deliveryDetails = _iDeliveryManager.GetDeliveryDetailsInfoByDeliveryId(deliveryId);
            var orderInfo       = _iOrderManager.GetOrderInfoByTransactionRef(delivery.TransactionRef);
            var client          = _iClientManager.GetClientDeailsById(delivery.ClientId);

            var model = new ViewInvoiceModel
            {
                Client          = client,
                Order           = orderInfo,
                Delivery        = delivery,
                DeliveryDetails = deliveryDetails
            };

            return(View(model));
        }
        public ActionResult ApproveBySalesAdmin(long salesReturnId)
        {
            try
            {
                ViewBag.ApproverActionId = _iCommonManager.GetAllApprovalActionList().ToList();
                ViewBag.SalesReturnId    = salesReturnId;
                var returnById = _iProductReturnManager.GetSalesReturnBySalesReturnId(salesReturnId);
                List <ViewReturnDetails> models;
                ViewReturnModel          model = new ViewReturnModel();
                if (returnById.ClientId != null)
                {
                    models = _iProductReturnManager.GetReturnDetailsBySalesReturnId(salesReturnId).ToList();
                    var firstOrdefault = models.FirstOrDefault();
                    if (firstOrdefault != null)
                    {
                        var delivery        = _iDeliveryManager.GetOrderByDeliveryId(firstOrdefault.DeliveryId);
                        var deliveryDetails = _iDeliveryManager.GetDeliveryDetailsInfoByDeliveryId(firstOrdefault.DeliveryId);
                        var orderInfo       = _iOrderManager.GetOrderInfoByTransactionRef(delivery.TransactionRef);
                        var client          = _iClientManager.GetClientDeailsById(orderInfo.ClientId);

                        ViewInvoiceModel invoice = new ViewInvoiceModel
                        {
                            Client          = client,
                            Order           = orderInfo,
                            Delivery        = delivery,
                            DeliveryDetails = deliveryDetails
                        };
                        model.InvoiceModel = invoice;
                    }
                }
                else
                {
                    models = _iProductReturnManager.GetGeneralReqReturnDetailsById(salesReturnId).ToList();
                }
                model.ReturnModel     = returnById;
                model.ReturnDetailses = models;

                return(View(model));
            }
            catch (Exception exception)
            {
                Log.WriteErrorLog(exception);
                return(PartialView("_ErrorPartial", exception));
            }
        }
 public ActionResult OrderDetails(string id)
 {
     try
     {
         ViewInvoiceModel anInvoicedOrder = new ViewInvoiceModel();
         var invoicedOrders = _iInvoiceManager.GetInvoicedOrderDetailsByInvoiceRef(id).ToList();
         var details        = invoicedOrders.FirstOrDefault();
         var invoice        = _iInvoiceManager.GetInvoicedOrderByInvoiceId(details.InvoiceId);
         anInvoicedOrder.InvoiceDetailses = invoicedOrders;
         anInvoicedOrder.Invoice          = invoice;
         return(View(anInvoicedOrder));
     }
     catch (Exception exception)
     {
         Log.WriteErrorLog(exception);
         return(PartialView("_ErrorPartial", exception));
     }
 }
        public ActionResult ApproveByNsm(long salesReturnId)
        {
            try
            {
                ViewBag.ApproverActionId = _iCommonManager.GetAllApprovalActionList().ToList();
                ViewBag.SalesReturnId    = salesReturnId;
                var returnById = _iProductReturnManager.GetSalesReturnBySalesReturnId(salesReturnId);
                List <ViewReturnDetails> models      = _iProductReturnManager.GetReturnDetailsBySalesReturnId(salesReturnId).ToList();
                ViewReturnModel          returnModel = new ViewReturnModel
                {
                    ReturnDetailses = models,
                    ReturnModel     = returnById,
                };
                var firstOrdefault = models.FirstOrDefault();
                if (firstOrdefault != null)
                {
                    var delivery = _iDeliveryManager.GetOrderByDeliveryId(firstOrdefault.DeliveryId);
                    //var chalan = _iDeliveryManager.GetChalanByDeliveryId(deliveryId);
                    var deliveryDetails = _iDeliveryManager.GetDeliveryDetailsInfoByDeliveryId(firstOrdefault.DeliveryId);

                    // var invocedOrder = _iInvoiceManager.GetInvoicedOrderByInvoiceId(deliveryId);
                    var orderInfo = _iOrderManager.GetOrderInfoByTransactionRef(delivery.TransactionRef);
                    //IEnumerable<InvoiceDetails> details = _iInvoiceManager.GetInvoicedOrderDetailsByInvoiceId(deliveryId);
                    var client = _iClientManager.GetClientDeailsById(orderInfo.ClientId);

                    ViewInvoiceModel model = new ViewInvoiceModel
                    {
                        Client          = client,
                        Order           = orderInfo,
                        Delivery        = delivery,
                        DeliveryDetails = deliveryDetails
                    };

                    returnModel.InvoiceModel = model;
                }

                return(View(returnModel));
            }
            catch (Exception exception)
            {
                Log.WriteErrorLog(exception);
                return(PartialView("_ErrorPartial", exception));
            }
        }
Example #7
0
        public ActionResult Invoice(int deliveryId)
        {
            var delivery = _iDeliveryManager.GetOrderByDeliveryId(deliveryId);
            //var chalan = _iDeliveryManager.GetChalanByDeliveryId(deliveryId);
            var deliveryDetails = _iDeliveryManager.GetDeliveryDetailsInfoByDeliveryId(deliveryId);

            // var invocedOrder = _iInvoiceManager.GetInvoicedOrderByInvoiceId(deliveryId);
            var orderInfo = _iOrderManager.GetOrderInfoByTransactionRef(delivery.TransactionRef);
            //IEnumerable<InvoiceDetails> details = _iInvoiceManager.GetInvoicedOrderDetailsByInvoiceId(deliveryId);
            var client = _iClientManager.GetClientDeailsById(orderInfo.ClientId);

            ViewInvoiceModel model = new ViewInvoiceModel
            {
                Client          = client,
                Order           = orderInfo,
                Delivery        = delivery,
                DeliveryDetails = deliveryDetails
            };

            return(View(model));
        }
        public ActionResult Invoice(long id)
        {
            try
            {
                var invocedOrder = _iInvoiceManager.GetInvoicedOrderByInvoiceId(id);
                var orderInfo    = _iOrderManager.GetOrderInfoByTransactionRef(invocedOrder.TransactionRef);
                IEnumerable <InvoiceDetails> details = _iInvoiceManager.GetInvoicedOrderDetailsByInvoiceId(id);
                var client = _iClientManager.GetClientDeailsById(orderInfo.ClientId);

                ViewInvoiceModel model = new ViewInvoiceModel
                {
                    Client           = client,
                    Order            = orderInfo,
                    Invoice          = invocedOrder,
                    InvoiceDetailses = details
                };
                return(View(model));
            }
            catch (Exception exception)
            {
                Log.WriteErrorLog(exception);
                return(PartialView("_ErrorPartial", exception));
            }
        }
        public ActionResult Receive(long salesReturnId, FormCollection collection)
        {
            try
            {
                var user       = (ViewUser)Session["user"];
                var returnById = _iProductReturnManager.GetSalesReturnBySalesReturnId(salesReturnId);
                List <ViewReturnDetails> models = _iProductReturnManager.GetReturnDetailsBySalesReturnId(salesReturnId).ToList();

                List <ViewReturnDetails> newReturnDetailsList = new List <ViewReturnDetails>();
                var firstOrdefault = models.FirstOrDefault();

                if (firstOrdefault != null)
                {
                    var delivery        = _iDeliveryManager.GetOrderByDeliveryId(firstOrdefault.DeliveryId);
                    var invoicedOrder   = _iInvoiceManager.GetInvoicedOrderByInvoiceId(delivery.InvoiceId);
                    var deliveryDetails = _iDeliveryManager.GetDeliveryDetailsInfoByDeliveryId(firstOrdefault.DeliveryId);
                    var orderInfo       = _iOrderManager.GetOrderInfoByTransactionRef(delivery.TransactionRef);
                    var client          = _iClientManager.GetClientDeailsById(orderInfo.ClientId);

                    int branchId = Convert.ToInt32(Session["BranchId"]);
                    var filePath = GetReceiveProductFilePath(salesReturnId, branchId);
                    //------------read Scanned barcode form text file---------
                    var barcodeList = _iProductManager.GetScannedProductListFromTextFile(filePath).ToList();

                    var invoice = new ViewInvoiceModel
                    {
                        Order           = orderInfo,
                        DeliveryDetails = deliveryDetails,
                        Client          = client
                    };



                    foreach (ViewReturnDetails item in models)
                    {
                        item.UnitPrice = invoice.DeliveryDetails.ToList().Find(n => n.ProductId == item.ProductId)
                                         .UnitPrice;
                        item.VatAmount = invoice.DeliveryDetails.ToList().Find(n => n.ProductId == item.ProductId)
                                         .VatAmount;
                        item.DiscountAmount = invoice.DeliveryDetails.ToList().Find(n => n.ProductId == item.ProductId)
                                              .UnitDiscount;
                        newReturnDetailsList.Add(item);
                    }


                    var grossAmount     = newReturnDetailsList.Sum(n => (n.UnitPrice + n.VatAmount) * n.Quantity);
                    var tradeDiscount   = newReturnDetailsList.Sum(n => n.DiscountAmount * n.Quantity);
                    var invoiceDiscount = (invoicedOrder.SpecialDiscount / invoicedOrder.Quantity) * newReturnDetailsList.Sum(n => n.Quantity);
                    var grossDiscount   = tradeDiscount + invoiceDiscount;
                    var vat             = newReturnDetailsList.Sum(n => n.VatAmount * n.Quantity);


                    var financialModel =
                        new FinancialTransactionModel
                    {
                        //--------Cr -------------------
                        ClientCode          = invoice.Client.SubSubSubAccountCode,
                        ClientCrAmount      = grossAmount - grossDiscount,
                        GrossDiscountAmount = grossDiscount,
                        GrossDiscountCode   = "2102018",

                        //--------Dr -------------------
                        SalesRevenueCode   = "2001021",
                        SalesRevenueAmount = grossAmount - vat,
                        VatCode            = "2102013",
                        VatAmount          = vat,


                        //--------------Sales Return---------
                        SalesReturnAmount = returnById.LessAmount,
                        SalesReturnCode   = "1001022",
                        ClientDrAmount    = returnById.LessAmount,


                        TradeDiscountCode     = "2102012",
                        TradeDiscountAmount   = tradeDiscount,
                        InvoiceDiscountAmount = invoiceDiscount,
                        InvoiceDiscountCode   = "2102011"
                    };

                    var result = _iInventoryManager.ReceiveProduct(barcodeList, branchId, user.UserId, financialModel, returnById);

                    if (result)
                    {
                        System.IO.File.Create(filePath).Close();
                        return(RedirectToAction("PendingReturnList"));
                    }
                }
                return(View());
            }
            catch (Exception exception)
            {
                Log.WriteErrorLog(exception);
                return(PartialView("_ErrorPartial", exception));
            }
        }
Example #10
0
        public IHttpActionResult insertAsync([FromBody] ViewInvoiceModel viewInvoiceModel)
        {
            Response response = new Response();
            //if (Service.invoiceDAO.checkExist(viewInvoiceModel) != null)
            //{
            //    response = new Response("409", "Hóa đơn này đã tồn tại", null);
            //    return Content<Response>(HttpStatusCode.Conflict, response);
            //}
            List <Product> products = new List <Product>();

            for (var i = 0; i < viewInvoiceModel.products.Count(); i++)
            {
                var     product     = viewInvoiceModel.products[i];
                Product saleProduct = Service.productDAO.getProduct(product.productId);
                saleProduct.attributes = Service.productAttributeDAO.getProAttrsByProId(saleProduct.id);
                products.Add(saleProduct);
            }

            List <Int16> salers = new List <Int16>();

            for (var i = 0; i < products.Count(); i++)
            {
                Int16 saler = products[i].createdBy;
                if (viewInvoiceModel.buyer == saler)
                {
                    response.code   = "409";
                    response.status = "Bạn không thể mua sản phẩm của chính mình";
                    return(Content <Response>(HttpStatusCode.Conflict, response));
                }
                bool existSaler = salers.Contains(saler);
                if (existSaler == false)
                {
                    salers.Add(saler);
                }
            }

            for (var i = 0; i < salers.Count(); i++)
            {
                var code = "HD" + salers[i].ToString() + Utils.RandomString(6);
                IEnumerable <Product> saleProducts = products.Where(p => p.createdBy == salers[i]);
                List <Product>        lists        = saleProducts.ToList();
                Double  total         = 0;
                Invoice createInvoice = new Invoice(code, viewInvoiceModel.buyer, salers[i], total);
                Service.invoiceDAO.insertInvoice(createInvoice);

                for (var j = 0; j < lists.Count(); j++)
                {
                    InvoiceProducts         invoiceProduct = viewInvoiceModel.products.First(p => p.productId == lists[j].id);
                    List <ProductAttribute> proAttrs       = Service.productAttributeDAO.getProAttrsByProId(lists[j].id);
                    var amount        = invoiceProduct.amount;
                    var price         = proAttrs[0].value;
                    var discount      = proAttrs[2].value;
                    var productAmount = short.Parse(proAttrs[1].value) - amount;

                    ProductAttribute updateAttrs = new ProductAttribute(); //Update Amount of product after create Invoice
                    updateAttrs       = Service.productAttributeDAO.getProductAttributeById(proAttrs[1].id);
                    updateAttrs.value = productAmount.ToString();
                    Service.productAttributeDAO.updateProductAttribute(updateAttrs);

                    InvoiceDetail invoiceDetail = null;
                    if (double.Parse(discount) > 0)
                    {
                        invoiceDetail = new InvoiceDetail(createInvoice.id, lists[j].id, amount, double.Parse(discount));
                    }
                    else
                    {
                        invoiceDetail = new InvoiceDetail(createInvoice.id, lists[j].id, amount, double.Parse(price));
                    }
                    total = total + invoiceDetail.subTotal; //tính Total của cái hóa đơn
                    Service.invoiceDetailDAO.insertInvoiceDetail(invoiceDetail);
                }
                Invoice updateInvoice = createInvoice;
                updateInvoice.total = total;
                Service.invoiceDAO.updateInvoice(updateInvoice);

                //var message = "<p>Thông tin đơn hàng của bạn</p> " +
                //              "<p>Mã hóa đơn: " + createInvoice.id +"</p>" +
                //              "<p></p>";
            }
            //await Service._userManager.SendEmailAsync(viewInvoiceModel.buyer, "Thông tin đơn hàng", );
            response = new Response("201", "Hóa đơn đã được thêm", products);
            return(Content <Response>(HttpStatusCode.Created, response));
        }