Ejemplo n.º 1
0
        public ActionResult EditPurchaseOrder(PurchaseOrderObject purchaseOrder)
        {
            var gVal = new GenericValidator();

            try
            {
                var valStatus = ValidatePurchaseOrder(purchaseOrder);
                if (valStatus.Code < 1)
                {
                    gVal.Code  = 0;
                    gVal.Error = valStatus.Error;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var k = new PurchaseOrderServices().UpdatePurchaseOrder(purchaseOrder);
                if (k < 1)
                {
                    gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Update_Failure;
                    gVal.Code  = 0;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = 5;
                gVal.Error = message_Feedback.Update_Success;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Process_Failed;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 2
0
        public ActionResult GetMyPurchaseOrders(JQueryDataTableParamModel param)
        {
            try
            {
                var userInfo = GetSignedOnUser();
                if (userInfo == null || userInfo.UserProfile.Id < 1)
                {
                    return(Json(new List <PurchaseOrderObject>(), JsonRequestBehavior.AllowGet));
                }


                IEnumerable <PurchaseOrderObject> filteredPurchaseOrderObjects;
                int countG;

                var pagedParentMenuObjects = new PurchaseOrderServices().GetPurchaseOrdersByEmployee(param.iDisplayLength, param.iDisplayStart, out countG, userInfo.UserProfile.EmployeeId);

                if (!string.IsNullOrEmpty(param.sSearch))
                {
                    filteredPurchaseOrderObjects = new PurchaseOrderServices().SearchEmployeePurchaseOrder(param.sSearch, userInfo.UserProfile.Id);
                    countG = filteredPurchaseOrderObjects.Count();
                }
                else
                {
                    filteredPurchaseOrderObjects = pagedParentMenuObjects;
                }

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

                var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
                Func <PurchaseOrderObject, string> orderingFunction = (c => sortColumnIndex == 1 ? c.SupplierName : sortColumnIndex == 2 ? c.DerivedTotalCostStr : sortColumnIndex == 3 ? c.DateTimePlacedStr : sortColumnIndex == 4 ? c.ActualDeliveryDateStr : c.DeliveryStatus);

                var sortDirection = Request["sSortDir_0"]; // asc or desc
                filteredPurchaseOrderObjects = sortDirection == "desc" ? filteredPurchaseOrderObjects.OrderBy(orderingFunction) : filteredPurchaseOrderObjects.OrderByDescending(orderingFunction);

                var displayedPersonnels = filteredPurchaseOrderObjects;

                var result = from c in displayedPersonnels
                             select new[] { Convert.ToString(c.PurchaseOrderId), c.PurchaseOrderNumber,
                                            c.SupplierName, c.GeneratedByEmployeeName, c.DerivedTotalCostStr,
                                            c.DateTimePlacedStr, c.ActualDeliveryDateStr, c.DeliveryStatus };

                return(Json(new
                {
                    param.sEcho,
                    iTotalRecords = countG,
                    iTotalDisplayRecords = countG,
                    aaData = result
                },
                            JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new List <PurchaseOrderObject>(), JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 3
0
        public ActionResult GetSelectables(string subdomain)
        {
            var gVal = new GenericValidator();

            try
            {
                var selectables = new PurchaseOrderServices().GetSelectables();
                return(Json(selectables, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new StockGenericObject(), JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 4
0
        public ActionResult AddPurchaseOrder(PurchaseOrderObject purchaseOrder)
        {
            var gVal = new GenericValidator();

            try
            {
                var valStatus = ValidatePurchaseOrder(purchaseOrder);
                if (valStatus.Code < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = valStatus.Error;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var userInfo = GetSignedOnUser();
                if (userInfo == null || userInfo.UserProfile.Id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Your session has timed out.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                purchaseOrder.StoreOutletId  = userInfo.UserProfile.StoreOutletId;
                purchaseOrder.StatusCode     = (int)PurchaseOrderDeliveryStatus.Pending;
                purchaseOrder.GeneratedById  = userInfo.UserProfile.EmployeeId;
                purchaseOrder.DateTimePlaced = DateTime.Now;

                string purchaseOrderNumber;
                var    k = new PurchaseOrderServices().AddPurchaseOrder(purchaseOrder, out purchaseOrderNumber);
                if (k < 1)
                {
                    gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Insertion_Failure;
                    gVal.Code  = -1;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code = k;
                gVal.PurchaseOrderNumber = purchaseOrderNumber;
                gVal.Error = message_Feedback.Insertion_Success;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Process_Failed;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 5
0
 public ActionResult GetPurchaseOrder(long id)
 {
     try
     {
         if (id < 1)
         {
             return(Json(new PurchaseOrderObject(), JsonRequestBehavior.AllowGet));
         }
         var purchaseOrder = new PurchaseOrderServices().GetPurchaseOrder(id);
         return(Json(purchaseOrder, JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json(new PurchaseOrderObject(), JsonRequestBehavior.AllowGet));
     }
 }
Ejemplo n.º 6
0
        public ActionResult GetPurchaseOrderDetails(long id)
        {
            var gVal = new GenericValidator();

            try
            {
                if (id < 1)
                {
                    return(Json(new PurchaseOrderObject(), JsonRequestBehavior.AllowGet));
                }
                var purchaseOrderDetails = new PurchaseOrderServices().GetPurchaseOrderDetails(id);
                return(Json(purchaseOrderDetails, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new PurchaseOrderObject(), JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 7
0
        public ActionResult ProcessPurchaseorderDelivery(POrderInfo delivery)
        {
            var gVal = new GenericValidator();

            try
            {
                var retStatus = ValidatePurchaseOrderItemDelivery(delivery.DeliveredItems);
                if (retStatus.Code < 1)
                {
                    return(Json(retStatus, JsonRequestBehavior.AllowGet));
                }

                var userInfo = GetSignedOnUser();
                if (userInfo == null || userInfo.UserProfile.Id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Your session has timed out.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                delivery.DeliveredItems.ForEach(d =>
                {
                    d.ReceivedById = userInfo.UserProfile.EmployeeId;
                });

                var status = new PurchaseOrderServices().ProcessPurchaseOrderDeliveries(delivery);
                if (status < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Process failed. Please try again later.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }
                gVal.Code  = status;
                gVal.Error = "Process was successfully completed.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "An unknown error was encountered. Please try again later.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 8
0
        public ActionResult DeletePurchaseOrderItemDelivery(long id)
        {
            var gVal = new GenericValidator();

            try
            {
                if (id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Invalid selection!";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var status = new PurchaseOrderServices().DeletePurchaseOrderItemDelivery(id);
                return(Json(status, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new StockGenericObject(), JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 9
0
        public ActionResult ProcessPurchaseorderInvoice(HttpPostedFileBase file, long invoiceId, long purchaseOrderId, string referenceCode, int statusCode, String dueDate, string dateSent, string attachment)
        {
            var gVal = new GenericValidator();

            try
            {
                if (purchaseOrderId < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Invoice information could not be processed.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var invoiceItem = new InvoiceJson
                {
                    InvoiceId       = invoiceId,
                    PurchaseOrderId = purchaseOrderId,
                    ReferenceCode   = referenceCode,
                    StatusCode      = statusCode
                };

                if (!string.IsNullOrEmpty(dueDate))
                {
                    DateTime d1;
                    var      res1 = DateTime.TryParse(dueDate, out d1);
                    if (res1 && d1.Year > 1)
                    {
                        invoiceItem.DueDate = d1;
                    }
                    else
                    {
                        gVal.Code  = -1;
                        gVal.Error = "Request could not be processed. Please try again later.";
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }
                }

                if (!string.IsNullOrEmpty(dateSent))
                {
                    DateTime d2;
                    var      res2 = DateTime.TryParse(dateSent, out d2);
                    if (res2 && d2.Year > 1)
                    {
                        invoiceItem.DateSent = d2;
                    }
                    else
                    {
                        gVal.Code  = -1;
                        gVal.Error = "Invalid invoice reception date.";
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }
                }

                var path = "";
                if (file != null && file.ContentLength > 0)
                {
                    path = PrepareAndSaveFile(file, attachment);
                    if (string.IsNullOrEmpty(path) || path == "/")
                    {
                        gVal.Code  = -1;
                        gVal.Error = "Invoice information Could not be saved.";
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(attachment))
                    {
                        gVal.Code  = -1;
                        gVal.Error = "Please select an invoice file to upload.";
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    path = attachment;
                }

                invoiceItem.Attachment = path;

                invoiceItem.StatusCode = (int)PurchaseOrderInvoiceStatus.Accepted;
                invoiceItem.Attachment = path;

                var tx = new PurchaseOrderServices().ProcessPurchaseOrderInvoice(invoiceItem);
                if (tx < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Invoice information Could not be processed.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Error    = "Invoice was successfully procesed";
                gVal.FilePath = path.Replace("~", "");
                gVal.Code     = tx;

                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                gVal.Code = -1;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
 public PurchaseOrderController(SupplierService supService, PurchaseOrderServices poService)
 {
     this.supService = supService;
     this.poService  = poService;
 }