public ActionResult EditProduction(int id)
        {
            var production = new Production();

            try
            {
                if (id < 1)
                {
                    production.Error     = "Invalid Selection!";
                    production.ErrorCode = -1;
                    return(Json(production, JsonRequestBehavior.AllowGet));
                }

                var myViewObj = new ProductionServices().GetProduction(id);

                if (myViewObj == null || myViewObj.ProductionId < 1)
                {
                    production.Error     = "Production  Information could not be retrieved.";
                    production.ErrorCode = -1;
                    return(Json(production, JsonRequestBehavior.AllowGet));
                }
                Session["_production"] = myViewObj;
                myViewObj.ErrorCode    = myViewObj.ProductionId;
                return(Json(myViewObj, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                production.Error     = "An unknown error was Production  Information could not be retrieved.";
                production.ErrorCode = -1;
                return(Json(production, JsonRequestBehavior.AllowGet));
            }
        }
        public List <Production> GetProducttionsBySearchDate(GenericSearch search)
        {
            try
            {
                var productions = new ProductionServices().GetAllOrderedProductionsByMonth(search.Month, search.Year);

                if (!productions.Any())
                {
                    return(new List <Production>());
                }

                productions.ForEach(m =>
                {
                    m.FieldName   = m.Field.Name;
                    m.ProductName = m.Product.Name;
                    m.MonthName   = Enum.GetName(typeof(MonthList), m.Month);
                    m.Quantity    = Convert.ToDecimal(m.Quantity).ToString("#,##0");
                });
                return(productions);
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                return(new List <Production>());
            }
        }
        public ActionResult GetProductions2(int queryId)
        {
            if (queryId < 1)
            {
                return(Json(new List <ProductionObject>(), JsonRequestBehavior.AllowGet));
            }


            var query = new ProductionQueryBuilderServices().GetProductionQuery(queryId);

            if (query == null || query.ProductionQueryId < 1)
            {
                return(Json(new List <ProductionObject>(), JsonRequestBehavior.AllowGet));
            }

            var productionList = new ProductionServices().GetOrderedProductionReportObjects(query) ?? new List <ProductionObject>();

            if (!productionList.Any())
            {
                return(Json(new List <ProductionObject>(), JsonRequestBehavior.AllowGet));
            }

            var jsonResult = Json(productionList, JsonRequestBehavior.AllowGet);

            jsonResult.MaxJsonLength = int.MaxValue;
            return(jsonResult);
        }
        public ActionResult GetProductions(ProductionQuery queryBuilder)
        {
            if (queryBuilder == null)
            {
                return(Json(new List <ProductionObject>(), JsonRequestBehavior.AllowGet));
            }


            if (queryBuilder.BlockId < 1 && queryBuilder.CompanyId < 1 && ((queryBuilder.StartDate != null && queryBuilder.StartDate.Value.Year == 0001) || (queryBuilder.StartDate == null)) && ((queryBuilder.EndDate != null && queryBuilder.EndDate.Value.Year == 0001) || (queryBuilder.EndDate == null)) && queryBuilder.FieldId < 1 && queryBuilder.ProductId < 1 && queryBuilder.TerrainId < 1 && queryBuilder.ZoneId < 1)
            {
                return(Json(new List <ProductionObject>(), JsonRequestBehavior.AllowGet));
            }

            var productionList = new ProductionServices().GetOrderedProductionReportObjects(queryBuilder) ?? new List <ProductionObject>();

            if (!productionList.Any())
            {
                return(Json(new List <ProductionObject>(), JsonRequestBehavior.AllowGet));
            }
            Session["_successfulProductionQuery"] = queryBuilder;
            var jsonResult = Json(productionList, JsonRequestBehavior.AllowGet);

            jsonResult.MaxJsonLength = int.MaxValue;
            return(jsonResult);
        }
 public ProductionController()
 {
     unitOfWork             = new UnitOfWork();
     productionServices     = new ProductionServices(unitOfWork);
     productDetailsServices = new ProductDetailsServices(unitOfWork);
     productServices        = new ProductServices(unitOfWork);
     itemServices           = new ItemServices(unitOfWork);
 }
        public ActionResult AddProduction(Production production)
        {
            ModelState.Clear();
            ViewBag.LoadStatus = "0";
            try
            {
                if (!ModelState.IsValid)
                {
                    production.Error     = "Please supply all required fields and try again";
                    production.ErrorCode = -1;
                    return(Json(production, JsonRequestBehavior.AllowGet));
                }

                var wx = ValidateControl(production);
                if (wx.Code < 1)
                {
                    production.Error     = wx.Error;
                    production.ErrorCode = -1;
                    return(Json(production, JsonRequestBehavior.AllowGet));
                }
                var ty = production.Quantity.Replace(",", "").Replace(" ", "");
                production.Quantity  = ty;
                production.Year      = production.ProductionDate.Year;
                production.Month     = production.ProductionDate.Month;
                production.MonthName = Enum.GetName(typeof(MonthList), production.Month);
                var k = new ProductionServices().AddProduction(production);
                if (k < 1)
                {
                    production.Error     = "Process Failed! Please contact the Admin or try again later";
                    production.ErrorCode = 0;
                    return(Json(production, JsonRequestBehavior.AllowGet));
                }

                production.Error        = "Record was added successfully";
                production.ErrorCode    = 1;
                production.ProductionId = k;
                return(Json(production, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                production.Error     = "An unknown error was encountered. Request could not be serviced. Please try again later.";
                production.ErrorCode = 0;
                return(Json(production, JsonRequestBehavior.AllowGet));
            }
        }
        private List <ProductionObject> GetProductionObjects(int pageNumber, int itemsPerPage, GenericSearch search)
        {
            try
            {
                var productionObjects = new ProductionServices().GetProductionStaticReportByPeriod(itemsPerPage, pageNumber, search.Month, search.Year);

                if (!productionObjects.Any())
                {
                    return(new List <ProductionObject>());
                }

                return(productionObjects);
            }
            catch (Exception ex)
            {
                return(new List <ProductionObject>());
            }
        }
        private List <ProductionObject> GetWellComletionObjects(int itemsPerPage, int pageNumber)
        {
            try
            {
                var wellCompletions = new ProductionServices().GetMoreProductionObjects(itemsPerPage, pageNumber);

                if (!wellCompletions.Any())
                {
                    return(new List <ProductionObject>());
                }

                return(wellCompletions);
            }
            catch (Exception ex)
            {
                return(new List <ProductionObject>());
            }
        }
        private List <DocObject> GetYears()
        {
            var jxs = new ProductionServices().GetProductionYears();

            if (!jxs.Any())
            {
                return(new List <DocObject>());
            }
            var tdv = new List <DocObject>();

            jxs.ForEach(m =>
            {
                if (!tdv.Exists(t => t.DocId == m))
                {
                    tdv.Add(new DocObject {
                        DocName = m.ToString(CultureInfo.InvariantCulture), DocId = m
                    });
                }
            });
            return(tdv.OrderByDescending(m => m.DocName).ToList());
        }
        private List <Production> GetProductions(int itemsPerPage, int pageNumber, out int dataCount)
        {
            try
            {
                var productionList = new ProductionServices().GetAllOrderedProductions(itemsPerPage, pageNumber, out dataCount);
                ViewBag.PrDataCount = dataCount.ToString(CultureInfo.InvariantCulture);

                var totalPages = dataCount / itemsPerPage;

                // Counting the last page
                if (dataCount % itemsPerPage != 0)
                {
                    totalPages++;
                }

                ViewBag.PrTotalPages = totalPages;
                ViewBag.PrPage       = pageNumber;
                if (!productionList.Any())
                {
                    return(new List <Production>());
                }
                productionList.ForEach(m =>
                {
                    m.FieldName   = m.Field.Name;
                    m.ProductName = m.Product.Name;
                    m.Quantity    = Convert.ToDecimal(m.Quantity).ToString("#,##0");
                    m.MonthName   = Enum.GetName(typeof(MonthList), m.Month);
                });
                return(productionList);
            }
            catch (Exception ex)
            {
                dataCount = 0;
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                return(new List <Production>());
            }
        }
        public ActionResult GetProductionsByField(int fieldId)
        {
            try
            {
                if (fieldId < 1)
                {
                    return(Json(new List <Field>(), JsonRequestBehavior.AllowGet));
                }

                var productionList = new ProductionServices().GetAllOrderedProductionsByFieldId(fieldId);

                if (!productionList.Any())
                {
                    return(Json(new List <Production>(), JsonRequestBehavior.AllowGet));
                }

                return(Json(productionList, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new List <Production>(), JsonRequestBehavior.AllowGet));
            }
        }
        private Production ProcessRecord(DataRowView dv, ref string msg)
        {
            if (dv == null)
            {
                return(null);
            }
            try
            {
                var quantity = dv.Row["Quantity"].ToString().Replace(" ", "").Replace(",", "").Trim();

                var qt = string.IsNullOrEmpty(quantity) ? "0" : quantity;

                var mInfo = new Production
                {
                    Quantity = qt,
                };

                var fieldName = dv.Row["FieldName"].ToString().Trim();
                mInfo.FieldId = new FieldServices().GetFieldIdByName(fieldName);
                var productName = dv.Row["Product"].ToString().Trim();
                mInfo.ProductId = new ProductServices().GetProductIdId(productName);

                var month = dv.Row["Month"].ToString().Trim();
                if (string.IsNullOrEmpty(month))
                {
                    mInfo.Month = DateTime.Now.Month;
                }
                else
                {
                    var monthValue = 0;
                    switch (month.Trim().Replace(" ", string.Empty).ToLower())
                    {
                    case "january":
                        monthValue = 1;
                        break;

                    case "february":
                        monthValue = 2;
                        break;

                    case "march":
                        monthValue = 3;
                        break;

                    case "april":
                        monthValue = 4;
                        break;

                    case "may":
                        monthValue = 5;
                        break;

                    case "june":
                        monthValue = 6;
                        break;

                    case "july":
                        monthValue = 7;
                        break;

                    case "august":
                        monthValue = 8;
                        break;

                    case "september":
                        monthValue = 9;
                        break;

                    case "october":
                        monthValue = 10;
                        break;

                    case "november":
                        monthValue = 11;
                        break;

                    case "december":
                        monthValue = 12;
                        break;
                    }

                    mInfo.Month = monthValue;
                }


                var year = dv.Row["Year"].ToString().Trim();

                if (!string.IsNullOrEmpty(year))
                {
                    long yearValue;
                    var  yearResult = long.TryParse(dv.Row["Year"].ToString().Trim(), out yearValue);
                    if (!yearResult || yearValue < 1)
                    {
                        msg = "Invalid Year of Production";
                        return(null);
                    }

                    if (yearValue < 1)
                    {
                        msg = "Invalid Year of Production";
                        return(null);
                    }

                    mInfo.Year = yearValue;
                }

                else
                {
                    mInfo.Year = 2014;
                }

                if (!string.IsNullOrEmpty(dv.Row["APIGravity"].ToString().Trim()))
                {
                    mInfo.APIGravity = dv.Row["APIGravity"].ToString().Trim();
                }

                var status = new ProductionServices().AddProduction(mInfo);
                return(status > 0 ? mInfo : null);
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                return(null);
            }
        }
Exemple #13
0
 public ProductionsController()
 {
     services = new ProductionServices();
 }
        public ActionResult GetProductionsByQueryDateDate(GenericSearch search)
        {
            try
            {
                if (search.Year < 1)
                {
                    ViewBag.ErrorCode    = -1;
                    ViewBag.ErrorMessage = "Please provide a valid Report Year";
                    return(View("Report", new ProductionViewModel
                    {
                        Products = new List <Product>(),
                        Fields = new List <Field>(),
                        YearList = GetYears(),
                        MonthList = GetMonths(),
                        ProductionObjects = new List <ProductionObject>()
                    }));
                }

                if (search.Month > 0)
                {
                    ViewBag.SearchPeriod = Enum.GetName(typeof(MonthList), search.Month) + "/" + search.Year;
                }

                else
                {
                    ViewBag.SearchPeriod = search.Year;
                }

                var txd = new ProductionServices().GetProductionStaticReportByPeriod(PageNumber, ItemsPerPage, search.Month, search.Year);


                if (!txd.Any())
                {
                    ViewBag.ErrorMessage = "No record found";
                    ViewBag.ErrorCode    = -1;
                    return(View("Report", new ProductionViewModel
                    {
                        Products = new List <Product>(),
                        Fields = new List <Field>(),
                        YearList = GetYears(),
                        MonthList = GetMonths(),
                        ProductionObjects = new List <ProductionObject>()
                    }));
                }

                var txx = new ProductionViewModel
                {
                    Products          = new List <Product>(),
                    Fields            = new List <Field>(),
                    YearList          = GetYears(),
                    MonthList         = GetMonths(),
                    ProductionObjects = txd
                };

                Session["_prodRepoPage"]      = 1;
                Session["_prodRepoGenSearch"] = search;
                return(View("Report", txx));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                ViewBag.ErrorMessage = "No record found";
                ViewBag.ErrorCode    = -1;
                return(View("Report", new ProductionViewModel
                {
                    Products = new List <Product>(),
                    Fields = new List <Field>(),
                    YearList = GetYears(),
                    MonthList = GetMonths(),
                    Productions = new List <Production>()
                }));
            }
        }
        public ActionResult ProductionUpload(HttpPostedFileBase file)
        {
            try
            {
                if (file.ContentLength > 0)
                {
                    const string folderPath = "~/BulkUploadTemplate";

                    var fileName = file.FileName;
                    var path     = folderPath + "/" + fileName;
                    if (System.IO.File.Exists(Server.MapPath(path)))
                    {
                        System.IO.File.Delete(Server.MapPath(path));
                    }

                    file.SaveAs(Server.MapPath(folderPath + "/" + fileName));
                    var mList = new List <Production>();
                    var msg   = string.Empty;
                    if (!new ProductionUploadManager().Import(Server.MapPath(path), "production", ref mList, ref msg))
                    {
                        ViewBag.ErrorCode    = -1;
                        ViewBag.ErrorMessage = "Bulk upload Failed! An unknown error was encountered.";
                        return(View());
                    }

                    if (!mList.Any())
                    {
                        var error = msg.Length > 0 ? msg : "Bulk upload Failed! unknown error occurred";
                        ViewBag.ErrorCode    = -2;
                        ViewBag.ErrorMessage = error;
                        return(View());
                    }

                    var errorList  = new List <Production>();
                    var succesList = new List <Production>();
                    foreach (var production in mList)
                    {
                        //production.FieldId = productionInfo.FieldId;
                        //production.ProductId = productionInfo.ProductId;

                        var processedItem = new ProductionServices().AddProduction(production);

                        if (processedItem < 1)
                        {
                            errorList.Add(production);
                        }
                        else
                        {
                            succesList.Add(production);
                        }
                    }

                    if (errorList.Any() && succesList.Any())
                    {
                        var ts = succesList.Count + " records were successfully uploaded." +
                                 "<br/>" + errorList.Count + " records could not be uploaded due to duplicates/unknown errors encountered.";
                        ViewBag.ErrorCode = -1;

                        if (msg.Length > 0)
                        {
                            ts += "<br/>" + msg;
                        }
                        ViewBag.ErrorMessage = ts;
                        return(View());
                    }

                    if (errorList.Any() && !succesList.Any())
                    {
                        var ts = errorList.Count + " records could not be uploaded due to duplicates/unknown errors encountered.";
                        ViewBag.ErrorCode = -1;

                        if (msg.Length > 0)
                        {
                            ts += "<br/>" + msg;
                        }
                        ViewBag.ErrorMessage = ts;
                        return(View());
                    }

                    if (!errorList.Any() && succesList.Any() && msg.Length > 0)
                    {
                        ViewBag.ErrorCode = -1;
                        //ViewBag.ErrorMessage = mList.Count + " records were successfully uploaded.";

                        var tsx = succesList.Count + " records were successfully uploaded.";
                        tsx += "<br/>" + msg;
                        ViewBag.ErrorMessage = tsx;
                        return(View());
                    }

                    if (!errorList.Any() && succesList.Any() && (string.IsNullOrEmpty(msg) || msg.Length < 1))
                    {
                        ViewBag.ErrorCode = 5;
                        var tsx = succesList.Count + " records were successfully uploaded.";
                        ViewBag.ErrorMessage = tsx;
                        return(View());
                    }
                }

                ViewBag.ErrorCode    = -1;
                ViewBag.ErrorMessage = "Error: File is empty or the content could not be accessed";
                return(View());
            }
            catch (Exception ex)
            {
                ViewBag.ErrorCode    = -1;
                ViewBag.ErrorMessage = "Error: File is empty or the content could not be accessed";
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                return(View());
            }
        }
        public ActionResult EditProduction(Production production)
        {
            ModelState.Clear();
            ViewBag.LoadStatus = "0";
            try
            {
                if (Session["_production"] == null)
                {
                    production.Error     = "Session has expired";
                    production.ErrorCode = 0;
                    return(Json(production, JsonRequestBehavior.AllowGet));
                }

                var oldProduction = Session["_production"] as Production;

                if (oldProduction == null || oldProduction.ProductionId < 1)
                {
                    production.Error     = "Session has expired";
                    production.ErrorCode = 0;
                    return(Json(production, JsonRequestBehavior.AllowGet));
                }

                if (!ModelState.IsValid)
                {
                    production.Error     = "Please supply all required Productions and try again";
                    production.ErrorCode = -1;
                    return(Json(production, JsonRequestBehavior.AllowGet));
                }

                var wx = ValidateControl(production);

                if (wx.Code < 1)
                {
                    production.Error     = wx.Error;
                    production.ErrorCode = -1;
                    return(Json(production, JsonRequestBehavior.AllowGet));
                }
                oldProduction.Remark            = production.Remark;
                oldProduction.FieldId           = production.FieldId;
                oldProduction.ProductId         = production.ProductId;
                oldProduction.Quantity          = production.Quantity.Replace(",", "").Replace(" ", "");;
                oldProduction.APIGravity        = production.APIGravity;
                oldProduction.Year              = production.ProductionDate.Year;
                oldProduction.Month             = production.ProductionDate.Month;
                production.ProductionDateString = production.ProductionDate.ToString("yyyy/MM/dd");
                production.Year      = production.ProductionDate.Year;
                production.Month     = production.ProductionDate.Month;
                production.MonthName = Enum.GetName(typeof(MonthList), production.Month);
                var k = new ProductionServices().UpdateProductionCheckDuplicate(oldProduction);
                if (k < 1)
                {
                    production.Error     = "Process Failed! Please contact the Admin or try again later";
                    production.ErrorCode = 0;
                    return(Json(production, JsonRequestBehavior.AllowGet));
                }

                production.Error     = "Production  Information was successfully updated";
                production.ErrorCode = 1;
                return(Json(production, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                production.Error     = "An unknown error was encountered. Request could not be serviced. Please try again later.";
                production.ErrorCode = 0;
                return(Json(production, JsonRequestBehavior.AllowGet));
            }
        }