Esempio n. 1
0
        // Creating new entry
        public string SubmitInventoryRetrieval(List <WCF_TempInventoryRetrieval> tempList, string token)
        {
            //Check if user is authorizated to use this method. If is not authorized, it will return a json with -1 in the primary key
            if (!IsAuthanticateUser(token))
            {
                List <WCF_TempInventoryRetrieval> wcf_UnAuthObj = new List <WCF_TempInventoryRetrieval>();
                WCF_TempInventoryRetrieval        wcfUnAuth     = new WCF_TempInventoryRetrieval();
                wcfUnAuth.RequestID = -1;
                wcf_UnAuthObj.Add(wcfUnAuth);
                return("Invalid user.");
            }

            bool anyErrors1 = false;
            bool anyErrors2 = true;

            // Checking against existing quantity in the store currently
            string itemID            = "";
            int    totalRetrievedQty = 0;

            foreach (var item in tempList)
            {
                itemID             = item.ItemID;
                totalRetrievedQty += item.ActualQty;
            }
            int currentQty = InventoryLogic.GetQuantity(itemID);

            if (totalRetrievedQty > currentQty)
            {
                anyErrors1 = true;
            }

            bool isEnough = true;

            // If still no errors, will perform more checks till an error is found.
            if (!anyErrors1)
            {
                foreach (var item in tempList)
                {
                    InventoryCatalogue ic = InventoryLogic.FindItemByItemID(itemID);

                    //Check if there is insufficient quantity in the inventory
                    if (ic.UnitsInStock < item.RequestedQty || ic.UnitsInStock < item.RequestedQty)
                    {
                        isEnough = false;

                        if (!isEnough && ic.UnitsInStock < item.RequestedQty)
                        {
                            anyErrors1 = true;
                        }
                    }

                    //If inventory is not enough and isOverride is true
                    if (item.IsOverride)
                    {
                        isEnough   = false;
                        anyErrors2 = false;
                    }

                    //Check if user is withdrawing more than requested
                    if (item.RequestedQty < item.ActualQty)
                    {
                        anyErrors1 = true;
                    }

                    //Check if user is withdrawing less than requested despite having enough in the inventory
                    if (isEnough && item.RequestedQty > item.ActualQty && !item.IsOverride)
                    {
                        anyErrors1 = true;
                    }


                    if (anyErrors1)
                    {
                        break;
                    }
                }
            }

            // If there is a single error, the process will terminate without updating any of the entries
            if (anyErrors1 && anyErrors2)
            {
                return("Failure.");
            }
            else
            {
                foreach (WCF_TempInventoryRetrieval item in tempList)
                {
                    string str = InventoryLogic.CreateNewInventoryRetrievalEntry(item.RequestID, item.RequestDetailID, item.ItemID, item.DepartmentID, item.RequestedQty, item.ActualQty, item.IsOverride);
                }

                return("Success.");
            }
        }
        // This will retrieve all the necessary values and use it to generate our report
        protected void BtnGenerate_Click(object sender, EventArgs e)
        {
            // Resets all controls to default first
            LblHeader.Visible   = false;
            LblErrorMsg.Text    = "";
            LblErrorMsg.Visible = false;

            // Declare our attr to perform our validation
            bool anyErrors = false;

            // Retrieve Item id
            string itemID = LblItemID.Text;

            // Retrieve both of our dates
            string   temp1    = DateFrom.Value;
            DateTime dateFrom = DateTime.ParseExact(temp1, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);

            string   temp2  = DateTo.Value;
            DateTime dateTo = DateTime.ParseExact(temp2, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);


            // Gotta perform our server-side validation here...
            // Ensure that dateFrom is before dateTo
            if (dateTo < dateFrom)
            {
                LblErrorMsg.Visible = true;
                LblErrorMsg.Text    = "Error. Ensure that the date selected is in the right order.";
                anyErrors           = true;
            }
            //Ensure that dateFrom cannot be below Jan 1st 2014 cos no data for it
            if (dateFrom.Year < 2014 && !anyErrors)
            {
                LblErrorMsg.Visible = true;
                LblErrorMsg.Text    = "Error. No data found before 2014.";
                anyErrors           = true;
            }
            // Ensure that dateTo cannot be beyond the latest date in the actual data table
            bool check = ReportLogic.CheckIfBeyondLatestData(dateTo);

            if (!check && !anyErrors)
            {
                LblErrorMsg.Visible = true;
                LblErrorMsg.Text    = "Error. No data beyond the selected date.";
                anyErrors           = true;
            }
            // Ensure that its 6 months apart
            DateTime tempDate = dateFrom.AddMonths(6);

            if (tempDate > dateTo && !anyErrors)
            {
                LblErrorMsg.Visible = true;
                LblErrorMsg.Text    = "Error. Period selected must be at least 6 months apart.";
                anyErrors           = true;
            }


            // If no errors, run our main logic
            if (!String.IsNullOrWhiteSpace(itemID) && !anyErrors)
            {
                // Retrieve our number of periods
                int numPeriods = Convert.ToInt32(DdlNoForeacast.SelectedItem.Value);

                // Retrieve our type of chart to generate
                int typeOfChart = Convert.ToInt32(DdlTypeChart.SelectedItem.Value);

                // Pass our value to the method in the biz logic side
                ReportLogic.GetChart(itemID, dateFrom, dateTo, numPeriods, typeOfChart);


                // Populating our Images
                ImgChart.Visible          = true;
                ImgChart.ImageUrl         = "~/images/Charts/chart1.png" + "?time=" + DateTime.Now.ToString();
                ImgTableResult.Visible    = true;
                ImgTableResult.ImageUrl   = "~/images/Charts/tableResults.png" + "?time=" + DateTime.Now.ToString();
                ImgTableAccuracy.Visible  = true;
                ImgTableAccuracy.ImageUrl = "~/images/Charts/tableAccuracy.png" + "?time=" + DateTime.Now.ToString();
                ImgTableModel.Visible     = true;
                ImgTableModel.ImageUrl    = "~/images/Charts/tableModel.png" + "?time=" + DateTime.Now.ToString();


                // Populating misc controls
                LblHeader.Visible         = true;
                LblChartHeader.Visible    = true;
                LblExpectedDemand.Visible = true;
                var item = InventoryLogic.FindItemByItemID(itemID);
                LblCode.Visible            = true;
                LblItemCode.Visible        = true;
                LblItemCode.Text           = item.ItemID;
                LblDescription.Visible     = true;
                LblItemDescription.Visible = true;
                LblItemDescription.Text    = item.Description;
                LblCategory.Visible        = true;
                LblItemCategory.Visible    = true;
                LblItemCategory.Text       = InventoryLogic.GetCatalogueName(item.CategoryID);
                BtnPrint.Visible           = true;
                LblAccuracy.Visible        = true;
                LblModel.Visible           = true;
            }

            // Updating the UpdatePanel
            UpdatePanelChart.Update();
        }