Exemple #1
0
        public void SuccessfulCompleteOrderManagementFlowTest()
        {
            try
            {
                // Order logic
                OrderManagementLogic orderLogic = new OrderManagementLogic();


                HealthFacility from      = HealthFacility.GetHealthFacilityByCode("HF888");
                HealthFacility to        = HealthFacility.GetHealthFacilityByCode("HF999");
                DateTime       orderDate = DateTime.Now;

                // Step 1 : Create an Order
                var orderHeader = orderLogic.RequestOrder(from, to, orderDate, 1);

                // Assert that Step 1 actually creates the Order Header
                Assert.IsNotNull(orderHeader.OrderNum);
                Assert.AreEqual(from.Id, orderHeader.OrderFacilityFromObject.Id);
                Assert.AreEqual(to.Id, orderHeader.OrderFacilityToObject.Id);
                Assert.AreEqual(orderDate, orderHeader.OrderSchedReplenishDate);
                Assert.AreEqual((int)OrderStatusType.Requested, orderHeader.OrderStatus);

                // Step 2 : Create order line items
                var orderLine = orderLogic.AddOrderLine(orderHeader, TestData.GTIN_UNDER_TEST, null, 100, Uom.GetUomById(1), 1);
                // Assert line item was created with most recent lot #
                Assert.AreEqual(orderHeader.OrderNum, orderLine.OrderNum);
                Assert.AreEqual(TestData.GTIN_UNDER_TEST, orderLine.OrderGtin);
                Assert.AreEqual(TestData.GTIN_LOT_USE_FIRST, orderLine.OrderGtinLotnum);
                Assert.AreEqual((int)OrderStatusType.Requested, orderLine.OrderDetailStatus);

                // Step 3 : Release the order
                orderHeader = orderLogic.ReleaseOrder(orderHeader, 1);

                // Assert header is updated
                Assert.AreEqual(from.Id, orderHeader.OrderFacilityFromObject.Id);
                Assert.AreEqual(to.Id, orderHeader.OrderFacilityToObject.Id);
                Assert.AreEqual((int)OrderStatusType.Released, orderHeader.OrderStatus);

                // Assert lines are updated
                orderLine = TransferOrderDetail.GetTransferOrderDetailByOrderNum(orderHeader.OrderNum)[0];
                Assert.AreEqual((int)OrderStatusType.Released, orderHeader.OrderStatus);

                // Assert that there was a stock transaction for allocation
                var txAllocate = TransactionType.GetTransactionTypeList().First(o => o.Name == "Allocation");
                Assert.IsTrue(ItemTransaction.GetItemTransactionList().Exists(o => o.HealthFacilityCode == "HF888" &&
                                                                              o.Gtin == TestData.GTIN_UNDER_TEST &&
                                                                              o.GtinLot == TestData.GTIN_LOT_USE_FIRST &&
                                                                              o.TransactionTypeId == txAllocate.Id &&
                                                                              o.RefId == orderHeader.OrderNum.ToString() &&
                                                                              o.RefIdNum == orderLine.OrderDetailNum &&
                                                                              o.TransactionQtyInBaseUom == 100), "No allocation could be found");

                // Step 4: Pack the order
                orderHeader = orderLogic.PackOrder(orderHeader, 1);
                Assert.AreEqual(from.Id, orderHeader.OrderFacilityFromObject.Id);
                Assert.AreEqual(to.Id, orderHeader.OrderFacilityToObject.Id);
                Assert.AreEqual((int)OrderStatusType.Packed, orderHeader.OrderStatus);

                // Assert lines are updated
                orderLine = TransferOrderDetail.GetTransferOrderDetailByOrderNum(orderHeader.OrderNum)[0];
                Assert.AreEqual((int)OrderStatusType.Packed, orderHeader.OrderStatus);

                // Step 5: Ship the order
                orderHeader = orderLogic.ShipOrder(orderHeader, 1);
                Assert.AreEqual(from.Id, orderHeader.OrderFacilityFromObject.Id);
                Assert.AreEqual(to.Id, orderHeader.OrderFacilityToObject.Id);
                Assert.AreEqual((int)OrderStatusType.Shipped, orderHeader.OrderStatus);

                // Assert lines are updated
                orderLine = TransferOrderDetail.GetTransferOrderDetailByOrderNum(orderHeader.OrderNum)[0];
                Assert.AreEqual((int)OrderStatusType.Shipped, orderHeader.OrderStatus);

                // Assert allocations are made
                var txTrasnfer = TransactionType.GetTransactionTypeList().First(o => o.Name == "Transfer");
                Assert.IsTrue(ItemTransaction.GetItemTransactionList().Exists(o => o.HealthFacilityCode == "HF888" &&
                                                                              o.Gtin == TestData.GTIN_UNDER_TEST &&
                                                                              o.GtinLot == TestData.GTIN_LOT_USE_FIRST &&
                                                                              o.TransactionTypeId == txAllocate.Id &&
                                                                              o.RefId == orderHeader.OrderNum.ToString() &&
                                                                              o.RefIdNum == orderLine.OrderDetailNum &&
                                                                              o.TransactionQtyInBaseUom == -100), "No de-allocation could be found");
                Assert.IsTrue(ItemTransaction.GetItemTransactionList().Exists(o => o.HealthFacilityCode == "HF888" &&
                                                                              o.Gtin == TestData.GTIN_UNDER_TEST &&
                                                                              o.GtinLot == TestData.GTIN_LOT_USE_FIRST &&
                                                                              o.TransactionTypeId == txTrasnfer.Id &&
                                                                              o.RefId == orderHeader.OrderNum.ToString() &&
                                                                              o.RefIdNum == orderLine.OrderDetailNum &&
                                                                              o.TransactionQtyInBaseUom == -100), "No transfer out could be found");
                Assert.IsTrue(ItemTransaction.GetItemTransactionList().Exists(o => o.HealthFacilityCode == "HF999" &&
                                                                              o.Gtin == TestData.GTIN_UNDER_TEST &&
                                                                              o.GtinLot == TestData.GTIN_LOT_USE_FIRST &&
                                                                              o.TransactionTypeId == txTrasnfer.Id &&
                                                                              o.RefId == orderHeader.OrderNum.ToString() &&
                                                                              o.RefIdNum == orderLine.OrderDetailNum &&
                                                                              o.TransactionQtyInBaseUom == 100), "No transfer in could be found");
            }
            catch (Exception e)
            {
                Assert.Fail(e.ToString());
            }
        }
    protected void btnAddDetail_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {
                string orderNumber = "";
                if (Request.QueryString["orderNum"] != null)
                {
                    orderNumber = Request.QueryString["orderNum"].ToString();
                }
                TransferOrderHeader toh = TransferOrderHeader.GetTransferOrderHeaderByOrderNum(int.Parse(orderNumber));

                OrderManagementLogic oml = new OrderManagementLogic();
                string gtin = ddlGtin.SelectedValue;
                string lot  = "*";
                if (ddlItemLot.SelectedIndex > 0)
                {
                    lot = ddlItemLot.SelectedValue;
                }

                int qty      = 0;
                int quantity = 0;
                if (!String.IsNullOrEmpty(txtQuantity.Text))
                {
                    qty = int.Parse(txtQuantity.Text);
                    string uom = ddlUom.SelectedValue;

                    ItemManufacturer im = ItemManufacturer.GetItemManufacturerByGtin(gtin);
                    if (uom.Equals(im.BaseUom))
                    {
                        quantity = qty;
                    }
                    else if (uom.Equals(im.Alt1Uom))
                    {
                        quantity = qty * im.Alt1QtyPer;
                    }
                    else if (uom.Equals(im.Alt2Uom))
                    {
                        quantity = qty * im.Alt2QtyPer;
                    }
                }
                Uom u = Uom.GetUomByName(ddlUom.SelectedValue); //GetuomByName

                TransferOrderDetail tod = TransferOrderDetail.GetTransferOrderDetailByOrderNumGtinLotNumber(int.Parse(orderNumber), gtin, lot);
                if (tod == null)
                {
                    TransferOrderDetail td = oml.AddOrderLine(toh, gtin, lot, quantity, u, CurrentEnvironment.LoggedUser.Id);

                    if (td != null)
                    {
                        //ClearControls(this);
                        gvGtinValue.DataBind();
                        ddlGtin.SelectedIndex = 0;
                        //ddlItemLot.SelectedIndex = 0;
                        txtQuantity.Text   = string.Empty;
                        lblSuccess.Visible = true;
                        lblWarning.Visible = false;
                        lblError.Visible   = false;
                    }
                    else
                    {
                        lblSuccess.Visible = false;
                        lblWarning.Visible = false;
                        lblError.Visible   = true;
                    }
                }
                else
                {
                    lblSuccess.Visible = false;
                    lblWarning.Visible = true;
                    lblError.Visible   = false;
                }
            }
        }
        catch (Exception ex)
        {
            lblSuccess.Visible = false;
            lblWarning.Visible = false;
            lblError.Visible   = true;
        }
    }