public void GetNewDeliveryOrderNo_ExistingId_Valid()
        {
            // Arrange
            string expectedPrefix = $"DO-{DateTime.Now.Year}{DateTime.Now.Month:00}";
            var    previous       = IdService.GetNewDeliveryOrderNo(context);

            new DeliveryOrderRepository(context).Save(new DeliveryOrder()
            {
                DeliveryOrderNo = previous,
                InvoiceFileName = "IDSERVICETEST",
                CreatedDateTime = DateTime.Now.AddDays(1 - DateTime.Today.Day),
            });

            // Act
            var current = IdService.GetNewDeliveryOrderNo(context);

            new DeliveryOrderRepository(context).Save(new DeliveryOrder()
            {
                DeliveryOrderNo = current,
                InvoiceFileName = "IDSERVICETEST",
                CreatedDateTime = DateTime.Now,
            });
            var previousSerialNoParseResult = Int32.TryParse(previous.Substring(previous.Length - 3), out int previousSerialNo);
            var resultSerialNoParseResult   = Int32.TryParse(current.Substring(current.Length - 3), out int resultSerialNo);

            // Assert
            Assert.AreEqual(1, resultSerialNo - previousSerialNo);
        }
        public void GetNewDeliveryOrderNoTest()
        {
            // Arrange
            string expectedPrefix = $"DO-{DateTime.Now.Year}{DateTime.Now.Month:00}";

            // Act
            var result = IdService.GetNewDeliveryOrderNo(context);
            var serialNoParseResult = Int32.TryParse(result.Substring(result.Length - 3), out int serialNo);

            // Assert
            Assert.AreEqual(expectedPrefix, result.Substring(0, 9));
            Assert.IsTrue(serialNoParseResult);
        }
Beispiel #3
0
        public ActionResult Save(List <DeliveryOrderDetailsViewModel> deliveryOrderDetailViewList)
        {
            int count = 0;

            foreach (DeliveryOrderDetailsViewModel dodvm in deliveryOrderDetailViewList)
            {
                if (dodvm.ReceivedQty != 0)
                {
                    count++;
                }
            }
            if (count != 0)
            {
                DeliveryOrder deliveryOrder = new DeliveryOrder();

                deliveryOrder.DeliveryOrderDetails = new List <DeliveryOrderDetail>();

                deliveryOrder.PurchaseOrder = purchaseOrderService.FindPurchaseOrderById(deliveryOrderDetailViewList[0].PurchaseOrderNo);


                deliveryOrder.DeliveryOrderNo = IdService.GetNewDeliveryOrderNo(context);
                deliveryOrder.CreatedDateTime = DateTime.Now;


                deliveryOrder.CreatedBy = userService.FindUserByEmail(System.Web.HttpContext.Current.User.Identity.GetUserName());

                deliveryOrder.Supplier = supplierService.FindSupplierById(deliveryOrder.PurchaseOrder.SupplierCode);

                deliveryOrder.DeliveryOrderFileName = Path.GetFileName(deliveryOrderDetailViewList[0].DeliveryOrderFileName);

                deliveryOrder.InvoiceFileName = Path.GetFileName(deliveryOrderDetailViewList[0].InvoiceFileName);


                deliveryOrder.Status = statusService.FindStatusByStatusId(1);

                deliveryOrderService.Save(deliveryOrder);

                deliveryOrder.PurchaseOrder.DeliveryOrders.Add(deliveryOrder);

                deliveryOrderService.Save(deliveryOrder);



                foreach (DeliveryOrderDetailsViewModel dovm in deliveryOrderDetailViewList)
                {
                    PurchaseOrderDetail purchaseOrderDetail = purchaseOrderService.FindPurchaseOrderDetailbyIdItem(deliveryOrder.PurchaseOrder.PurchaseOrderNo, dovm.ItemCode);

                    if (dovm.ReceivedQty != 0)
                    {
                        DeliveryOrderDetail deliveryOrderDetail = new DeliveryOrderDetail();

                        deliveryOrderDetail.DeliveryOrderNo = deliveryOrder.DeliveryOrderNo;

                        deliveryOrderDetail.Item = itemService.FindItemByItemCode(dovm.ItemCode);

                        deliveryOrderDetail.ItemCode = dovm.ItemCode;

                        deliveryOrderDetail.PlanQuantity = dovm.QtyOrdered;

                        deliveryOrderDetail.ActualQuantity = dovm.ReceivedQty;

                        deliveryOrderDetail.Status = statusService.FindStatusByStatusId(1);

                        deliveryOrderDetail.UpdatedBy = userService.FindUserByEmail(System.Web.HttpContext.Current.User.Identity.GetUserName());

                        deliveryOrderDetail.UpdatedDateTime = DateTime.Now;

                        deliveryOrder.DeliveryOrderDetails.Add(deliveryOrderDetail);
                    }
                }

                deliveryOrderService.CheckSave(deliveryOrder);
            }
            return(new JsonResult {
                Data = new { status = "Saved" }
            });
        }