/// <summary>
        /// Gets the oldest lot in a facility of the specified <paramref name="gtin"/>
        /// </summary>
        /// <param name="facility">The facility in which the oldest lot should be found</param>
        /// <param name="gtin">The GTIN of the item to be found</param>
        /// <returns>The <see cref="T:GIIS.DataLayer.ItemLot"/> with the earliest expiry date</returns>
        public ItemLot GetOldestLot(HealthFacility facility, String gtin)
        {
            var oldestLot = from l in
                            (from v in HealthFacilityBalance.GetHealthFacilityBalanceByHealthFacilityCode(facility.Code)
                             where gtin == v.Gtin
                             select new { il = ItemLot.GetItemLotByGtinAndLotNo(gtin, v.LotNumber), hfb = v })
                            where l.il != null
                            orderby l.il.ExpireDate
                            select l;
            var candidateLot = (oldestLot.FirstOrDefault(o => o.hfb.Balance > 0) ?? oldestLot.FirstOrDefault());

            // Candidate lot is null when there is demand (from a kit item) with no lot available!
            if (candidateLot == null)
            {
                // Is it becaues there is no lot in existence?
                var itemLot = ItemLot.GetItemLotByGtin(gtin);
                if (itemLot == null)
                {
                    itemLot = new ItemLot()
                    {
                        Gtin      = gtin,
                        LotNumber = String.Format("N/A-{0}", gtin),
                        Notes     = "Automatically inserted by order system",
                        ItemId    = ItemManufacturer.GetItemManufacturerByGtin(gtin).ItemId
                    };
                    itemLot.Id = ItemLot.Insert(itemLot);
                }

                // Is there no balance?
                var balanceLot = HealthFacilityBalance.GetHealthFacilityBalanceByLotNumber(itemLot.LotNumber);
                if (balanceLot == null)
                {
                    HealthFacilityBalance.Insert(new HealthFacilityBalance()
                    {
                        Gtin = gtin,
                        HealthFacilityCode = facility.Code,
                        LotNumber          = itemLot.LotNumber
                    });
                }
                return(itemLot);
            }
            else
            {
                return(candidateLot.il);
            }
        }
Пример #2
0
    protected void cvGtinLotNumber_ServerValidate(object source, ServerValidateEventArgs args)
    {
        args.IsValid = true;
        string _gtin  = "";
        string _lotno = "";
        string gtin   = Request.QueryString["gtin"];
        string lotno  = Request.QueryString["lotno"];

        if (String.IsNullOrEmpty(gtin) && String.IsNullOrEmpty(lotno))
        {
            if (!String.IsNullOrEmpty(ddlGtin.SelectedValue) && !String.IsNullOrEmpty(txtLotNumber.Text))
            {
                _gtin  = ddlGtin.SelectedValue;
                _lotno = txtLotNumber.Text;
                if (ItemLot.GetItemLotByGtinAndLotNo(_gtin, _lotno) != null)
                {
                    args.IsValid = false;
                }
                lblSuccess.Visible = false;
            }
        }
    }
    protected void gvHealthFacilityBalance_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        string dateformat = ConfigurationDate.GetConfigurationDateById(int.Parse(Configuration.GetConfigurationByName("DateFormat").Value)).DateFormat;

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label   lblExpireDate = (Label)e.Row.FindControl("lblExpireDate");
            ItemLot lot           = ItemLot.GetItemLotByGtinAndLotNo(e.Row.Cells[1].Text, e.Row.Cells[3].Text);
            if (lot != null)
            {
                lblExpireDate.Text = lot.ExpireDate.ToString("dd-MMM-yyyy");
            }
            int days = int.Parse(Configuration.GetConfigurationByName("LimitNumberOfDaysBeforeExpire").Value);
            if (lot.ExpireDate < DateTime.Today.Date)
            {
                e.Row.Cells[4].BackColor = System.Drawing.Color.OrangeRed;
            }
            else if (lot.ExpireDate < DateTime.Today.Date.AddDays(days))
            {
                e.Row.Cells[4].BackColor = System.Drawing.Color.Yellow;
            }
        }
    }
Пример #4
0
    protected void btnRemove_Click(object sender, EventArgs e)
    {
        try
        {
            int    id     = -1;
            int    userId = CurrentEnvironment.LoggedUser.Id;
            string gtin   = Request.QueryString["gtin"];
            string lotno  = Request.QueryString["lotno"];

            if (!String.IsNullOrEmpty(gtin) && !String.IsNullOrEmpty(lotno))
            {
                ItemLot o = ItemLot.GetItemLotByGtinAndLotNo(gtin, lotno);

                int i = ItemLot.Remove(o.Id);
                if (i > 0)
                {
                    lblSuccess.Visible = true;
                    lblWarning.Visible = false;
                    lblError.Visible   = false;
                    ClearControls(this);
                    gvItemLotNew.Visible = false;
                }
                else
                {
                    lblSuccess.Visible = false;
                    lblWarning.Visible = false;
                    lblError.Visible   = true;
                }
            }
        }
        catch (Exception ex)
        {
            lblSuccess.Visible = false;
            lblWarning.Visible = false;
            lblError.Visible   = true;
        }
    }
Пример #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            List <string> actionList        = null;
            string        sessionNameAction = "";
            if (CurrentEnvironment.LoggedUser != null)
            {
                sessionNameAction = "__GIS_actionList_" + CurrentEnvironment.LoggedUser.Id;
                actionList        = (List <string>)Session[sessionNameAction];
            }

            if ((actionList != null) && actionList.Contains("ViewItemLot") && (CurrentEnvironment.LoggedUser != null))
            {
                int    userId     = CurrentEnvironment.LoggedUser.Id;
                string language   = CurrentEnvironment.Language;
                int    languageId = int.Parse(language);
                Dictionary <string, string> wtList = (Dictionary <string, string>)HttpContext.Current.Cache["ItemLot-dictionary" + language];
                if (wtList == null)
                {
                    List <WordTranslate> wordTranslateList = WordTranslate.GetWordByLanguage(languageId, "ItemLot");
                    wtList = new Dictionary <string, string>();
                    foreach (WordTranslate vwt in wordTranslateList)
                    {
                        wtList.Add(vwt.Code, vwt.Name);
                    }
                    HttpContext.Current.Cache.Insert("ItemLot-dictionary" + language, wtList);
                }

                //controls
                lblItemCategory.Text = wtList["ItemLotItemCategory"];
                lblItem.Text         = wtList["ItemLotItem"];
                lblGTIN.Text         = wtList["ItemLotGTIN"];
                lblLotNumber.Text    = wtList["ItemLotLotNumber"];
                lblExpireDate.Text   = wtList["ItemLotExpireDate"];
                lblNotes.Text        = wtList["ItemLotNotes"];

                //grid header text
                gvItemLotNew.Columns[0].HeaderText = wtList["ItemLotGTIN"];
                gvItemLotNew.Columns[1].HeaderText = wtList["ItemLotLotNumber"];
                gvItemLotNew.Columns[2].HeaderText = wtList["ItemLotItem"];
                gvItemLotNew.Columns[3].HeaderText = wtList["ItemLotExpireDate"];
                gvItemLotNew.Columns[4].HeaderText = wtList["ItemLotNotes"];

                //validators
                string format    = ConfigurationDate.GetConfigurationDateById(int.Parse(Configuration.GetConfigurationByName("DateFormat").Value)).DateFormat;
                string expresion = ConfigurationDate.GetConfigurationDateById(int.Parse(Configuration.GetConfigurationByName("DateFormat").Value)).DateExpresion;
                ceExpireDate.Format                = format;
                revExpireDate.ErrorMessage         = format;
                revExpireDate.ValidationExpression = expresion;

                //actions
                btnEdit.Visible = actionList.Contains("EditItemLot");
                //btnRemove.Visible = actionList.Contains("RemoveItemLot");

                //buttons
                btnEdit.Text = wtList["ItemLotEditButton"];
                //btnRemove.Text = wtList["ItemLotRemoveButton"];

                ////message
                lblSuccess.Text              = wtList["ItemLotSuccessText"];
                lblWarning.Text              = wtList["ItemLotWarningText"];
                lblError.Text                = wtList["ItemLotErrorText"];
                cvItemLotNew.ErrorMessage    = wtList["ItemLotMandatory"];
                cvDate.ErrorMessage          = wtList["ItemLotDateValidator"];
                cvGtinLotNumber.ErrorMessage = wtList["ItemLotDuplicateCheck"];

                //Page Title
                lblTitle.Text = wtList["ItemLotPageTitle"];

                //selected object
                string _gtin  = Request.QueryString["gtin"];
                string _lotNo = Request.QueryString["lotno"];

                if (!String.IsNullOrEmpty(_gtin) && !String.IsNullOrEmpty(_lotNo))
                {
                    ItemLot o = ItemLot.GetItemLotByGtinAndLotNo(_gtin, _lotNo);

                    if (o != null)
                    {
                        ddlItemCategory.DataBind();
                        ddlItemCategory.SelectedValue = o.ItemObject.ItemCategoryId.ToString();
                        ddlItem.DataBind();
                        ddlItem.SelectedValue = o.ItemId.ToString();
                        ddlGtin.DataBind();
                        ddlGtin.SelectedValue     = o.Gtin;
                        txtLotNumber.Text         = o.LotNumber;
                        txtExpireDate.Text        = o.ExpireDate.ToString(ConfigurationDate.GetConfigurationDateById(int.Parse(Configuration.GetConfigurationByName("DateFormat").Value)).DateFormat);
                        txtNotes.Text             = o.Notes;
                        rblIsActive.SelectedValue = o.IsActive.ToString();

                        gvItemLotNew.Visible = true;
                        odsItemLotNew.SelectParameters.Clear();
                        odsItemLotNew.SelectParameters.Add("gtin", _gtin);
                        odsItemLotNew.SelectParameters.Add("lotNumber", _lotNo);
                        odsItemLotNew.DataBind();
                        gvItemLotNew.DataBind();

                        btnEdit.Visible = true;
                    }
                }
                else
                {
                    gvItemLotNew.Visible = false;
                    //btnRemove.Visible = false;
                }
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
    }
Пример #6
0
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {
                int    i     = 0;
                string gtin  = Request.QueryString["gtin"];
                string lotno = Request.QueryString["lotno"];

                if (!String.IsNullOrEmpty(gtin) && !String.IsNullOrEmpty(lotno))
                {
                    ItemLot o = ItemLot.GetItemLotByGtinAndLotNo(gtin, lotno);

                    int itemId = -1;
                    if (ddlItem.SelectedIndex != -1)
                    {
                        int.TryParse(ddlItem.SelectedValue, out itemId);
                        o.ItemId = itemId;
                    }
                    if (!String.IsNullOrEmpty(ddlGtin.SelectedValue))
                    {
                        o.Gtin = ddlGtin.SelectedValue;
                    }
                    if (!String.IsNullOrEmpty(txtLotNumber.Text))
                    {
                        o.LotNumber = txtLotNumber.Text;
                    }
                    if (!String.IsNullOrEmpty(txtExpireDate.Text))
                    {
                        o.ExpireDate = DateTime.ParseExact(txtExpireDate.Text, ConfigurationDate.GetConfigurationDateById(int.Parse(Configuration.GetConfigurationByName("DateFormat").Value)).DateFormat.ToString(), CultureInfo.CurrentCulture);
                    }
                    if (!String.IsNullOrEmpty(txtNotes.Text))
                    {
                        o.Notes = txtNotes.Text;
                    }
                    o.IsActive = bool.Parse(rblIsActive.SelectedValue);

                    i = ItemLot.Update(o);
                }
                else
                {
                    ItemLot o = new ItemLot();

                    int itemId = -1;
                    if (ddlItem.SelectedIndex != -1)
                    {
                        int.TryParse(ddlItem.SelectedValue, out itemId);
                        o.ItemId = itemId;
                    }
                    if (!String.IsNullOrEmpty(ddlGtin.SelectedValue))
                    {
                        o.Gtin = ddlGtin.SelectedValue;
                        gtin   = o.Gtin;
                    }
                    if (!String.IsNullOrEmpty(txtLotNumber.Text))
                    {
                        o.LotNumber = txtLotNumber.Text;
                        lotno       = o.LotNumber;
                    }
                    if (!String.IsNullOrEmpty(txtExpireDate.Text))
                    {
                        o.ExpireDate = DateTime.ParseExact(txtExpireDate.Text, ConfigurationDate.GetConfigurationDateById(int.Parse(Configuration.GetConfigurationByName("DateFormat").Value)).DateFormat.ToString(), CultureInfo.CurrentCulture);
                    }
                    if (!String.IsNullOrEmpty(txtNotes.Text))
                    {
                        o.Notes = txtNotes.Text;
                    }

                    i = ItemLot.Insert(o);
                }

                if (i > 0)
                {
                    ClearControls(this);
                    BindGrid(gtin, lotno);
                    lblSuccess.Visible = true;
                    lblWarning.Visible = false;
                    lblError.Visible   = false;
                }
                else
                {
                    lblSuccess.Visible = false;
                    lblWarning.Visible = false;
                    lblError.Visible   = true;
                }
            }
        }
        catch (Exception ex)
        {
            lblSuccess.Visible = false;
            lblWarning.Visible = false;
            lblError.Visible   = true;
        }
    }
        /// <summary>
        /// Add an order line to the order defined by <paramref name="order"/>
        /// </summary>
        /// <param name="order">The order to which the line should be added</param>
        /// <param name="gtin">The global trade identification number of the item in the line</param>
        /// <param name="lot">(Optional) The lot number to be used. Note if null is passed in <paramref name="lot"/> then the oldest lot is used first</param>
        /// <param name="qty">The quantity of the item to be added to the order</param>
        /// <param name="uom">(Optional) The base unit of measure. If <paramref name="uom"/> is null then the default UOM for the item described by <paramref name="gtin"/> is used</param>
        /// <returns>The constructed and saved <see cref="T:GIIS.DataLayer.TransferOrderDetail"/></returns>
        /// <remarks>
        /// The add order line function is responsible for adding a new order line to the order detail. This function operates in the following manner:
        /// <list type="ordered">
        /// <item>
        ///     <description>[Guard Condition] If the order passed into the function IS in the “Packed” or “Shipped” state then throw an invalid state exception (sanity check)</description>
        /// </item>
        /// <item>
        ///     <description>Lookup the item by the GTIN provided in the function call.</description>
        /// </item>
        /// <item>
        ///     <description>[Guard Condition] If the lot number is provided, and the lot number is not a valid lot number for the item provided then throw an error code</description>
        /// </item>
        /// <item>
        ///     <description>If the current status of the order to which the detail is to be attached is “Released” then
        ///         <list type="ordered">
        ///             <item>
        ///                 <description>Instantiate a StockManagementLogic BLL class</description>
        ///             </item>
        ///             <item>Allocate the stock using the Allocate method</item>
        ///         </list>
        ///     </description>
        /// </item>
        /// <item>
        ///     <description>Set the unit of measure, quantity, gtin, etc. fields of the TransferOrderDetail instance to the parameters and fields derived from loaded Item.</description>
        /// </item>
        /// <item>
        ///     <description>Save the order line.</description>
        /// </item>
        ///</list>
        /// </remarks>
        public TransferOrderDetail AddOrderLine(TransferOrderHeader order, String gtin, String lot, Int32 qty, Uom uom, Int32 modifiedBy)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }
            if (String.IsNullOrEmpty(gtin))
            {
                throw new ArgumentNullException("gtin");
            }

            // Sanity check
            if (order.OrderStatus == (int)OrderStatusType.Shipped ||
                order.OrderStatus == (int)OrderStatusType.Cancelled)
            {
                throw new IllegalStateException((OrderStatusType)order.OrderStatus, "TransferOrderHeader", "AddOrderLine");
            }

            // Lookup item by GTIN and optionally lot
            ItemLot item = null;

            if (!String.IsNullOrEmpty(lot))
            {
                item = ItemLot.GetItemLotByGtinAndLotNo(gtin, lot);
            }
            if (item == null)
            {               // not found - We get the item by lot
                item = ItemLot.GetItemLotByGtin(gtin);
                lot  = "*"; // null;
            }

            // Item still null?
            if (item == null)
            {
                throw new InvalidOperationException(String.Format("Cannot locate item with GTIN {0}", gtin));
            }

            // Construct the order detail
            TransferOrderDetail retVal = new TransferOrderDetail()
            {
                ModifiedBy             = modifiedBy,
                ModifiedOn             = DateTime.Now,
                OrderCustomItem        = false,
                OrderDetailDescription = item.ItemObject.Name,
                OrderDetailStatus      = order.OrderStatus,
                OrderGtin         = gtin,
                OrderGtinLotnum   = lot,
                OrderNum          = order.OrderNum,
                OrderQty          = qty,
                OrderQtyInBaseUom = qty,
                OrderUom          = uom.Name
            };

            // HACK: Overcome lack of transaction processing we have to be careful about how we do this
            ItemTransaction allocateTransaction = null;

            // Current state of order is released? We need to allocate this line item
            if (order.OrderStatus == (int)OrderStatusType.Released)
            {
                StockManagementLogic stockLogic = new StockManagementLogic();
                // We need to release this order ... If the lot was null we'll use the oldest lot number
                if (String.IsNullOrEmpty(lot))
                {
                    item = this.GetOldestLot(order.OrderFacilityFromObject, gtin);
                }

                // Allocation of specified lot
                allocateTransaction = stockLogic.Allocate(order.OrderFacilityFromObject, gtin, item.LotNumber, qty, null, modifiedBy);

                // Update order
                retVal.OrderGtinLotnum = item.LotNumber;
            }

            // Save
            retVal.OrderDetailNum = TransferOrderDetail.Insert(retVal);

            // HACK: Update the allocate transaction. This would be cleaned up with a transaction to back out changes (basically do the order detail then allocate)
            if (allocateTransaction != null)
            {
                allocateTransaction.RefId    = retVal.OrderNum.ToString();
                allocateTransaction.RefIdNum = retVal.OrderDetailNum;
                ItemTransaction.Update(allocateTransaction);
            }

            return(retVal);
        }