コード例 #1
0
        public static HistoryReceivedLineItem HistoryReceivedLineItem(int?counter)
        {
            var rtValue = new HistoryReceivedLineItem();

            rtValue.NewReceivedQuantity = counter.HasValue ? counter.Value : 0;
            rtValue.LineItem            = new LineItem();
            rtValue.User = new User();

            return(rtValue);
        }
コード例 #2
0
        public static HistoryReceivedLineItem HistoryReceivedLineItem(int? counter)
        {
            var rtValue = new HistoryReceivedLineItem();
            rtValue.NewReceivedQuantity = counter.HasValue ? counter.Value : 0;
            rtValue.LineItem = new LineItem();
            rtValue.User = new User();

            return rtValue;
        }
コード例 #3
0
ファイル: OrderController.cs プロジェクト: ucdavis/Purchasing
        public ActionResult PayAll(int id)
        {
            var order = _repositoryFactory.OrderRepository.Queryable.Single(a => a.Id == id);

            if (!order.StatusCode.IsComplete || order.StatusCode.Id == OrderStatusCode.Codes.Cancelled || order.StatusCode.Id == OrderStatusCode.Codes.Denied)
            {
                Message = string.Format("Order must be complete before {0} line items.", "paying for");
                return this.RedirectToAction(a => a.Review(id));
            }
            if (order.ApUser != null && order.ApUser.Id != CurrentUser.Identity.Name)
            {
                Message = "Permission Denied to update";
            }
            else
            {
                foreach (var lineItem in order.LineItems)
                {
                    var history = new HistoryReceivedLineItem();
                    history.User = _repositoryFactory.UserRepository.Queryable.Single(a => a.Id == CurrentUser.Identity.Name);
                    history.OldReceivedQuantity = lineItem.QuantityPaid ;
                    history.NewReceivedQuantity = (lineItem.Quantity);
                    history.LineItem = lineItem;
                    history.PayInvoice = true;

                    lineItem.QuantityPaid = lineItem.Quantity;

                    _repositoryFactory.LineItemRepository.EnsurePersistent(lineItem);
                    if (history.NewReceivedQuantity != history.OldReceivedQuantity)
                    {
                        _repositoryFactory.HistoryReceivedLineItemRepository.EnsurePersistent(history);
                    }
                }

                    _eventService.OrderPaid(order, null, 0, "Paid all line items");
                    Message = "All Line Items Paid";
                _repositoryFactory.OrderRepository.EnsurePersistent(order);
            }

            return this.RedirectToAction(a => a.PayInvoice(id));
        }
コード例 #4
0
ファイル: OrderController.cs プロジェクト: ucdavis/Purchasing
        public JsonNetResult PayInvoice(int id, int lineItemId, decimal? receivedQuantity)
        {
            var success = true;
            var message = "Succeeded";
            var lastUpdatedBy = string.Empty;

            var order = _repositoryFactory.OrderRepository.Queryable.Single(a => a.Id == id);
            if (order.ApUser != null && order.ApUser.Id != CurrentUser.Identity.Name)
            {
                success = false;
                message = "Permission Denied to update";
                return new JsonNetResult(new { success, lineItemId, message, lastUpdatedBy });
            }

                var showRed = false;
                var unaccounted = string.Empty;
                var receivedQuantityReturned = receivedQuantity.HasValue ? receivedQuantity.Value.ToString() : string.Empty;

                var lineItem = _repositoryFactory.LineItemRepository.GetNullableById(lineItemId);
                if (lineItem == null)
                {
                    success = false;
                    message = "Line Item not found";
                    return new JsonNetResult(new { success, lineItemId, receivedQuantity, message, showRed, unaccounted, lastUpdatedBy });
                }

                if (lineItem.Order.Id != id)
                {
                    success = false;
                    message = "Order Id does not match";
                    return new JsonNetResult(new { success, lineItemId, receivedQuantity, message, showRed, unaccounted, lastUpdatedBy });
                }

                if (!lineItem.Order.StatusCode.IsComplete)
                {
                    success = false;
                    message = "Order is not complete";
                    return new JsonNetResult(new { success, lineItemId, receivedQuantity, message, showRed, unaccounted, lastUpdatedBy });
                }

                try
                {
                    var history = new HistoryReceivedLineItem();
                    history.User = _repositoryFactory.UserRepository.Queryable.Single(a => a.Id == CurrentUser.Identity.Name);
                    history.OldReceivedQuantity = lineItem.QuantityPaid;
                    history.NewReceivedQuantity = receivedQuantity;
                    history.CommentsUpdated = false;
                    history.LineItem = lineItem;
                    history.PayInvoice = true;

                    lineItem.QuantityPaid = receivedQuantity;

                    _repositoryFactory.LineItemRepository.EnsurePersistent(lineItem);
                    if (history.NewReceivedQuantity != history.OldReceivedQuantity)
                    {
                        _repositoryFactory.HistoryReceivedLineItemRepository.EnsurePersistent(history);
                        lastUpdatedBy = history.User.FullName;
                    }
                    receivedQuantityReturned = string.Format("{0:0.###}", lineItem.QuantityReceived);
                    success = true;
                    message = "Updated";
                    var diff = (lineItem.Quantity - lineItem.QuantityPaid);
                    if (diff > 0)
                    {
                        unaccounted = string.Format("({0})", string.Format("{0:0.###}", diff));
                        showRed = true;
                    }
                    else
                    {
                        unaccounted = string.Format("{0}", string.Format("{0:0.###}", (diff * -1)));
                        showRed = false;
                    }

                    var updatedAmount = 0m;
                    if (history.OldReceivedQuantity.HasValue && history.NewReceivedQuantity.HasValue)
                    {
                        updatedAmount = history.NewReceivedQuantity.Value - history.OldReceivedQuantity.Value;
                    }
                    else if (history.OldReceivedQuantity.HasValue == false && history.NewReceivedQuantity.HasValue)
                    {
                        updatedAmount = history.NewReceivedQuantity.Value;
                    }
                    _eventService.OrderPaid(lineItem.Order, lineItem, updatedAmount);

                    _repositoryFactory.OrderRepository.EnsurePersistent(lineItem.Order);
                }
                catch
                {
                    success = false;
                    message = "There was a problem updating the quantity."; //ex.Message;
                }
                return new JsonNetResult(new { success, lineItemId, receivedQuantityReturned, message, showRed, unaccounted, lastUpdatedBy });
        }
コード例 #5
0
ファイル: OrderController.cs プロジェクト: ucdavis/Purchasing
        public JsonNetResult ReceiveItemsNotes(int id, int lineItemId, string note)
        {
            var success = true;
            var message = "Succeeded";
            var lastUpdatedBy = string.Empty;

            var order = _repositoryFactory.OrderRepository.Queryable.Single(a => a.Id == id);
            if (order.ApUser != null && order.ApUser.Id != CurrentUser.Identity.Name)
            {
                success = false;
                message = "Permission Denied to update";
                return new JsonNetResult(new { success, lineItemId, message, lastUpdatedBy });
            }

                var lineItem = _repositoryFactory.LineItemRepository.GetNullableById(lineItemId);
                if (lineItem == null)
                {
                    success = false;
                    message = "Line Item not found";
                    return new JsonNetResult(new { success, lineItemId, message, lastUpdatedBy });
                }

                if (lineItem.Order.Id != id)
                {
                    success = false;
                    message = "Order Id does not match";
                    return new JsonNetResult(new { success, lineItemId, message, lastUpdatedBy });
                }

                if (!lineItem.Order.StatusCode.IsComplete)
                {
                    success = false;
                    message = "Order is not complete";
                    return new JsonNetResult(new { success, lineItemId, message, lastUpdatedBy });
                }

                try
                {
                        var saveNote = lineItem.ReceivedNotes;
                        lineItem.ReceivedNotes = note;
                        _repositoryFactory.LineItemRepository.EnsurePersistent(lineItem);
                        var history = new HistoryReceivedLineItem();
                        history.LineItem = lineItem;
                        history.User = _repositoryFactory.UserRepository.Queryable.Single(a => a.Id == CurrentUser.Identity.Name);
                        history.CommentsUpdated = true;
                        history.OldReceivedQuantity = lineItem.QuantityPaid; //These don't matter because it is the note being updated.
                        history.NewReceivedQuantity = lineItem.QuantityPaid;
                        history.PayInvoice = false;
                        if (lineItem.ReceivedNotes != saveNote)
                        {
                            _repositoryFactory.HistoryReceivedLineItemRepository.EnsurePersistent(history);
                            lastUpdatedBy = history.User.FullName;
                        }

                    message = "Updated";
                    success = true;
                }
                catch
                {
                    success = false;
                    message = "There was a problem updating the notes."; //ex.Message;
                }

                return new JsonNetResult(new { success, lineItemId, message, lastUpdatedBy });
        }