コード例 #1
0
        /// <summary>
        /// Performs a stock count for the specified <paramref name="gtin"/> at <paramref name="facility"/>
        /// </summary>
        /// <param name="facility">The facility in which the count occurred</param>
        /// <param name="gtin">The GTIN of the item being counted</param>
        /// <param name="lot">The lot number of the item being counted</param>
        /// <param name="count">The count of items</param>
        /// <returns>The <see cref="T:GIIS.DataLayer.ItemTransaction"/> representing the count</returns>
        public ItemTransaction StockCount(HealthFacility facility, String gtin, String lot, UInt32 count, Int32 modifiedBy, DateTime date)
        {
            // Validate
            if (facility == null)
            {
                throw new ArgumentNullException("facility");
            }
            else if (String.IsNullOrEmpty(gtin))
            {
                throw new ArgumentNullException("gtin");
            }
            else if (String.IsNullOrEmpty(lot))
            {
                throw new ArgumentNullException("lot");
            }

            // Stock Count
            TransactionType stockCountType = TransactionType.GetTransactionTypeList().FirstOrDefault(o => o.Name == "Stock Count");

            if (stockCountType == null)
            {
                throw new InvalidOperationException("Cannot find transaction type 'Stock Count'");
            }

            // Balance
            var balance = this.GetCurrentBalance(facility, gtin, lot);

            // Now we want to create transaction for count operation
            ItemTransaction retVal = new ItemTransaction()
            {
                Gtin                    = gtin,
                GtinLot                 = lot,
                HealthFacilityCode      = facility.Code,
                ModifiedBy              = modifiedBy,
                ModifiedOn              = DateTime.Now,
                TransactionDate         = date,
                TransactionQtyInBaseUom = count,
                TransactionTypeId       = stockCountType.Id
            };

            // Overwrite the values
            int qty = (int)(balance.Balance - count);

            if (qty > 0)
            {
                Adjust(facility, gtin, lot, qty, AdjustmentReason.GetAdjustmentReasonById(99), modifiedBy, date);
            }
            balance.StockCount = balance.Balance = count;

            // Save
            HealthFacilityBalance.Update(balance);
            int i = ItemTransaction.Insert(retVal);

            return(ItemTransaction.GetItemTransactionById(i));
        }
コード例 #2
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("ViewStockCount") && (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["ItemTransaction-dictionary" + language];
                if (wtList == null)
                {
                    List <WordTranslate> wordTranslateList = WordTranslate.GetWordByLanguage(languageId, "ItemTransaction");
                    wtList = new Dictionary <string, string>();
                    foreach (WordTranslate vwt in wordTranslateList)
                    {
                        wtList.Add(vwt.Code, vwt.Name);
                    }
                    HttpContext.Current.Cache.Insert("ItemTransaction-dictionary" + language, wtList);
                }
                //controls
                lblItemCategoryId.Text = wtList["ItemTransactionItemCategory"];
                lblGtin.Text           = wtList["ItemTransactionGtin"];
                lblItemId.Text         = wtList["ItemTransactionItem"];
                lblItemLot.Text        = wtList["ItemTransactionItemLot"];
                lblStockCountDate.Text = wtList["ItemTransactionDate"];
                lblQuantity.Text       = wtList["ItemTransactionQuantity"];
                lblNotes.Text          = wtList["ItemTransactionNotes"];

                //grid header text
                gvTransactionLines.Columns[1].HeaderText = wtList["ItemTransactionItemLot"];
                gvTransactionLines.Columns[2].HeaderText = wtList["ItemTransactionGtin"];
                gvTransactionLines.Columns[3].HeaderText = wtList["ItemTransactionItem"];
                gvTransactionLines.Columns[4].HeaderText = wtList["ItemTransactionDate"];
                gvTransactionLines.Columns[5].HeaderText = wtList["ItemTransactionQuantity"];
                gvTransactionLines.Columns[6].HeaderText = wtList["ItemTransactionNotes"];

                //actions
                this.btnAdd.Visible  = actionList.Contains("AddStockCount");
                this.btnEdit.Visible = actionList.Contains("EditStockCount");

                //buttons
                this.btnAdd.Text   = wtList["ItemTransactionAddButton"];
                this.btnEdit.Text  = wtList["ItemTransactionEditButton"];
                this.btnExcel.Text = wtList["ItemTransactionExcelButton"];

                //message
                this.lblSuccess.Text = wtList["ItemTransactionSuccessText"];
                //this.lblWarning.Text = wtList["ItemTransactionWarningText"];
                this.lblError.Text = wtList["ItemTransactionErrorText"];

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

                //validators
                cvStock.ErrorMessage     = wtList["ItemTransactionMandatory"];
                revQuantity.ErrorMessage = wtList["ItemTransactionQuantityValidator"];

                ConfigurationDate dateformat = ConfigurationDate.GetConfigurationDateById(int.Parse(Configuration.GetConfigurationByName("DateFormat").Value));
                ceStockCountDate.Format                = dateformat.DateFormat;
                revStockCountDate.ErrorMessage         = dateformat.DateFormat;
                revStockCountDate.ValidationExpression = dateformat.DateExpresion;
                ceStockCountDate.EndDate               = DateTime.Today.Date;

                if (Request.QueryString["id"] != null)
                {
                    int             id = int.Parse(Request.QueryString["id"].ToString());
                    ItemTransaction o  = ItemTransaction.GetItemTransactionById(id);
                    ddlItemCategory.SelectedValue = o.GtinObject.ItemObject.ItemCategoryId.ToString();
                    ddlItemCategory.DataBind();
                    odsItem.DataBind();
                    ddlItems.SelectedValue = o.GtinObject.ItemId.ToString();
                    ddlItems.DataBind();
                    odsGtin.DataBind();
                    ddlGtin.SelectedValue = o.Gtin;
                    ddlGtin.DataBind();
                    odsItemLot.SelectParameters.Clear();
                    odsItemLot.SelectParameters.Add("gtin", o.Gtin);
                    odsItemLot.SelectParameters.Add("hfId", o.HealthFacilityCode);
                    odsItemLot.DataBind();
                    ddlItemLot.DataSource = odsItemLot;
                    ddlItemLot.DataBind();
                    ddlItemLot.SelectedValue = o.GtinLot;
                    txtQuantity.Text         = o.TransactionQtyInBaseUom.ToString();
                    txtStockCountDate.Text   = o.TransactionDate.ToString(dateformat.DateFormat);
                    txtNotes.Text            = o.Notes;
                    btnEdit.Visible          = true;
                    btnAdd.Visible           = false;

                    odsTransactionLines.SelectParameters.Clear();
                    odsTransactionLines.SelectParameters.Add("i", id.ToString());
                    odsTransactionLines.DataBind();
                }
                else
                {
                    btnEdit.Visible        = false;
                    btnAdd.Visible         = true;
                    txtStockCountDate.Text = DateTime.Today.Date.ToString(dateformat.DateFormat);
                }
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
    }
コード例 #3
0
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {
                int    id  = -1;
                string _id = Request.QueryString["id"].ToString();
                int.TryParse(_id, out id);
                int userId = CurrentEnvironment.LoggedUser.Id;

                ItemTransaction o = ItemTransaction.GetItemTransactionById(id);

                DateTime date = DateTime.ParseExact(txtStockCountDate.Text, ConfigurationDate.GetConfigurationDateById(int.Parse(Configuration.GetConfigurationByName("DateFormat").Value)).DateFormat.ToString(), CultureInfo.CurrentCulture);
                o.TransactionDate = date;
                o.Gtin            = ddlGtin.SelectedValue;
                if (ddlItemLot.SelectedIndex != 0)
                {
                    o.GtinLot = ddlItemLot.SelectedValue;
                }
                o.TransactionTypeId = 3; //Stock Count

                double qty  = double.Parse(txtQuantity.Text);
                int    diff = 0;
                if (o.TransactionQtyInBaseUom != qty)
                {
                    diff = (int)(qty - o.TransactionQtyInBaseUom);
                }

                o.TransactionQtyInBaseUom = double.Parse(txtQuantity.Text);
                o.Notes      = txtNotes.Text;
                o.ModifiedOn = DateTime.Now;
                o.ModifiedBy = userId;

                int i = ItemTransaction.Update(o);


                if (i > 0)
                {
                    UpdateBalance(o, diff);

                    lblSuccess.Visible = true;
                    lblWarning.Visible = false;
                    lblError.Visible   = false;
                    odsTransactionLines.SelectParameters.Clear();
                    odsTransactionLines.SelectParameters.Add("i", o.Id.ToString());
                    odsTransactionLines.DataBind();
                    ClearControls(this);
                    btnEdit.Visible = false;
                    btnAdd.Visible  = true;
                }
                else
                {
                    lblSuccess.Visible = false;
                    lblWarning.Visible = false;
                    lblError.Visible   = true;
                }
            }
        }
        catch (Exception ex)
        {
            lblSuccess.Visible = false;
            lblWarning.Visible = false;
            lblError.Visible   = true;
        }
    }
コード例 #4
0
        /// <summary>
        /// Make an adjustment
        /// </summary>
        /// <param name="facility">The facility in which the adjustment is being made</param>
        /// <param name="gtin">The GTIN of the stock item being adjusted</param>
        /// <param name="lot">The lot number of the stock being adjusted</param>
        /// <param name="qty">The amount of the adjustment</param>
        /// <param name="reason">The reason for the adjustment</param>
        /// <returns>The <see cref="T:GIIS.DataLayer.ItemTransaction"/> representing the transaction created</returns>
        /// <remarks>This method updates the ItemTransaction and HealthFacility Balances</remarks>
        public ItemTransaction Adjust(HealthFacility facility, String gtin, String lot, Int32 qty, AdjustmentReason reason, Int32 modifiedBy, DateTime date)
        {
            if (facility == null)
            {
                throw new ArgumentNullException("facility");
            }
            else if (String.IsNullOrEmpty(gtin))
            {
                throw new ArgumentNullException("gtin");
            }

            // Adjustment type
            TransactionType adjustmentType = TransactionType.GetTransactionTypeList().FirstOrDefault(o => o.Name == "Adjustment");

            if (adjustmentType == null)
            {
                throw new InvalidOperationException("Cannot find transaction type 'Adjustment'");
            }

            var balance = this.GetCurrentBalance(facility, gtin, lot);

            // Sanity check, is there a balance of this?
            //if (qty < 0 && -qty > balance.Balance)
            //    throw new InvalidOperationException("Quantity is a negative adjustment on a balance which exceeds the current balance");
            int quantity;

            if (reason.Positive)
            {
                quantity = qty;
            }
            else
            {
                quantity = -qty;
            }
            // Create the item transaction
            ItemTransaction retVal = new ItemTransaction()
            {
                ModifiedBy              = modifiedBy,
                AdjustmentId            = reason.Id,
                Gtin                    = gtin,
                GtinLot                 = lot,
                HealthFacilityCode      = facility.Code,
                ModifiedOn              = DateTime.Now,
                TransactionDate         = date,
                TransactionQtyInBaseUom = quantity,
                TransactionTypeId       = adjustmentType.Id
            };

            // Adjust the balance
            // An adjustment reason can be positive - results in increased balance
            if (reason.Id != 99)
            {
                if (reason.Positive)
                {
                    balance.Balance += qty;
                }
                else
                {
                    balance.Balance -= qty;
                    balance.Wasted  += qty;
                }
            }
            // Adjust the balances of other reasons
            //if(adjustmentType != null)
            //{
            //    switch(adjustmentType.Name)
            //    {
            //        case "Adjustments":
            //            balance.Wasted += -qty;
            //            break;
            //    }
            //}

            // Save the balances
            HealthFacilityBalance.Update(balance);
            int i = ItemTransaction.Insert(retVal);

            return(ItemTransaction.GetItemTransactionById(i));
        }