Пример #1
0
        public async Task <IActionResult> CreateDocument(SimpleDocumentModel simpleModel)
        {
            var model = await _documentViewModelService.PrepareDocumentModel(null, null, simpleModel);

            //ACL
            await model.PrepareACLModel(null, false, _customerService);

            //Stores
            await model.PrepareStoresMappingModel(null, _storeService, false, "");

            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> CreateDocument(SimpleDocumentModel simpleModel)
        {
            var model = await _documentViewModelService.PrepareDocumentModel(null, null, simpleModel);

            if (!string.IsNullOrEmpty(simpleModel.CustomerId))
            {
                model.CustomerEmail = (await _customerService.GetCustomerById(simpleModel.CustomerId))?.Email;
            }

            //ACL
            await model.PrepareACLModel(null, false, _customerService);

            //Stores
            await model.PrepareStoresMappingModel(null, _storeService, false, "");

            return(View(model));
        }
Пример #3
0
        public async Task <IActionResult> CreateDocument(SimpleDocumentModel simpleModel)
        {
            var model = await _documentViewModelService.PrepareDocumentModel(null, null, simpleModel);

            return(View(model));
        }
Пример #4
0
        public virtual async Task <DocumentModel> PrepareDocumentModel(DocumentModel documentModel, Document document, SimpleDocumentModel simpleModel)
        {
            var model = documentModel == null ? new DocumentModel()
            {
                Published = true
            } : documentModel;

            if (document != null)
            {
                model = document.ToModel();
            }
            else
            {
                if (simpleModel != null)
                {
                    model.ReferenceId = simpleModel.Reference;
                    model.ObjectId    = simpleModel.ObjectId;
                    if (!string.IsNullOrEmpty(simpleModel.CustomerId))
                    {
                        model.CustomerEmail = (await _customerService.GetCustomerById(simpleModel.CustomerId))?.Email;
                    }

                    if (!string.IsNullOrEmpty(simpleModel.ObjectId))
                    {
                        switch (simpleModel.Reference)
                        {
                        case (int)Reference.Order:
                            var order = await _orderService.GetOrderById(simpleModel.ObjectId);

                            if (order != null)
                            {
                                model.Number         = order.OrderNumber.ToString();
                                model.TotalAmount    = order.OrderTotal;
                                model.OutstandAmount = order.PaymentStatus == Domain.Payments.PaymentStatus.Paid ? 0 : order.OrderTotal;
                                model.CurrencyCode   = order.CustomerCurrencyCode;
                                model.Name           = string.Format(_localizationService.GetResource("Order.Document"), model.Number);
                                model.DocDate        = order.CreatedOnUtc;
                                model.DueDate        = order.CreatedOnUtc;
                                model.Quantity       = 1;
                                model.Username       = $"{order.BillingAddress?.FirstName} {order.BillingAddress?.LastName}";
                                model.CustomerEmail  = order.CustomerEmail;
                            }
                            break;

                        case (int)Reference.Product:
                            var product = await _productService.GetProductById(simpleModel.ObjectId);

                            if (product != null)
                            {
                                model.Name     = product.Name;
                                model.Number   = product.Sku;
                                model.Quantity = 1;
                            }
                            break;

                        case (int)Reference.Category:
                            var category = await _categoryService.GetCategoryById(simpleModel.ObjectId);

                            if (category != null)
                            {
                                model.Name     = category.Name;
                                model.Quantity = 1;
                            }
                            break;

                        case (int)Reference.Manufacturer:
                            var manufacturer = await _manufacturerService.GetManufacturerById(simpleModel.ObjectId);

                            if (manufacturer != null)
                            {
                                model.Name     = manufacturer.Name;
                                model.Quantity = 1;
                            }
                            break;

                        case (int)Reference.Vendor:
                            var vendor = await _vendorService.GetVendorById(simpleModel.ObjectId);

                            if (vendor != null)
                            {
                                model.Name     = vendor.Name;
                                model.Quantity = 1;
                            }
                            break;

                        case (int)Reference.Shipment:
                            var shipment = await _shipmentService.GetShipmentById(simpleModel.ObjectId);

                            if (shipment != null)
                            {
                                model.DocDate = shipment.CreatedOnUtc;
                                model.Number  = shipment.ShipmentNumber.ToString();
                                model.Name    = string.Format(_localizationService.GetResource("Shipment.Document"), shipment.ShipmentNumber);
                                var sorder = await _orderService.GetOrderById(shipment.OrderId);

                                if (sorder != null)
                                {
                                    model.CustomerId    = sorder.CustomerId;
                                    model.CustomerEmail = sorder.CustomerEmail;
                                }
                            }
                            break;

                        case (int)Reference.ReturnRequest:
                            var returnrequest = await _returnRequestService.GetReturnRequestById(simpleModel.ObjectId);

                            if (returnrequest != null)
                            {
                                model.DocDate = returnrequest.CreatedOnUtc;
                                model.Number  = returnrequest.ReturnNumber.ToString();
                                model.Name    = string.Format(_localizationService.GetResource("ReturnRequests.Document"), returnrequest.ReturnNumber);
                                var sorder = await _orderService.GetOrderById(returnrequest.OrderId);

                                if (sorder != null)
                                {
                                    model.CustomerId    = sorder.CustomerId;
                                    model.CustomerEmail = sorder.CustomerEmail;
                                }
                            }
                            break;
                        }
                    }
                }
            }
            //fill document types
            var types = await _documentTypeService.GetAll();

            foreach (var item in types)
            {
                model.AvailableDocumentTypes.Add(new SelectListItem {
                    Text  = item.Name,
                    Value = item.Id
                });
            }

            //fill sales employees
            model.AvailableSelesEmployees.Add(new SelectListItem {
                Text  = _localizationService.GetResource("Admin.Documents.Document.Fields.SeId.None"),
                Value = ""
            });
            var salesEmployees = await _salesEmployeeService.GetAll();

            foreach (var item in salesEmployees.Where(x => x.Active))
            {
                model.AvailableSelesEmployees.Add(new SelectListItem {
                    Text  = item.Name,
                    Value = item.Id
                });
            }
            return(model);
        }
Пример #5
0
        public virtual async Task <DocumentModel> PrepareDocumentModel(DocumentModel documentModel, Document document, SimpleDocumentModel simpleModel)
        {
            var model = documentModel == null ? new DocumentModel()
            {
                Published = true
            } : documentModel;

            if (document != null)
            {
                model = document.ToModel();
            }
            else
            {
                if (simpleModel != null)
                {
                    model.CustomerId = simpleModel.CustomerId;
                    if (!string.IsNullOrEmpty(simpleModel.OrderId))
                    {
                        model.ObjectId    = simpleModel.OrderId;
                        model.ReferenceId = (int)Reference.Order;
                        var order = await _orderService.GetOrderById(simpleModel.OrderId);

                        if (order != null)
                        {
                            model.Number         = order.OrderNumber.ToString();
                            model.TotalAmount    = order.OrderTotal;
                            model.OutstandAmount = order.PaymentStatus == Core.Domain.Payments.PaymentStatus.Paid ? 0 : order.OrderTotal;
                            model.CurrencyCode   = order.CustomerCurrencyCode;
                            model.Name           = string.Format(_localizationService.GetResource("Order.Document"), model.Number);
                            model.DocDate        = order.CreatedOnUtc;
                            model.DueDate        = order.CreatedOnUtc;
                            model.Quantity       = 1;
                            model.Username       = $"{order.BillingAddress?.FirstName} {order.BillingAddress?.LastName}";
                        }
                    }
                    if (!string.IsNullOrEmpty(model.CustomerId))
                    {
                        model.CustomerEmail = (await _customerService.GetCustomerById(simpleModel.CustomerId))?.Email;
                    }

                    if (!string.IsNullOrEmpty(simpleModel.ProductId))
                    {
                        model.ObjectId    = simpleModel.ProductId;
                        model.ReferenceId = (int)Reference.Product;
                        var product = await _productService.GetProductById(simpleModel.ProductId);

                        if (product != null)
                        {
                            model.Name     = product.Name;
                            model.Number   = product.Sku;
                            model.Quantity = 1;
                        }
                    }
                }
            }
            var types = await _documentTypeService.GetAll();

            foreach (var item in types)
            {
                model.AvailableDocumentTypes.Add(new SelectListItem {
                    Text = item.Name, Value = item.Id
                });
            }
            return(model);
        }
Пример #6
0
        public virtual async Task <DocumentModel> PrepareDocumentModel(DocumentModel documentModel, Document document, SimpleDocumentModel simpleModel)
        {
            var model = documentModel == null ? new DocumentModel()
            {
                Published = true
            } : documentModel;

            if (document != null)
            {
                model = document.ToModel();
            }
            else
            {
                model.CustomerId = simpleModel?.CustomerId;
            }
            var types = await _documentTypeService.GetAll();

            foreach (var item in types)
            {
                model.AvailableDocumentTypes.Add(new SelectListItem {
                    Text = item.Name, Value = item.Id
                });
            }
            return(model);
        }