Exemple #1
0
 public ActionResult EditPOItem(Guid Id)
 {
     Model.PurchaseOrderItem model = poService.GetPurchaseOrderItemById(Id);
     model.BudgetLines = new SelectList(orService.GetProjectBugdetLines((Guid)model.ProjectBudget.BudgetCategory.ProjectDonorId), "Id", "Description", model.BudgetLineId);
     model.UnitPrice   = Math.Round(model.UnitPrice, 2);
     model.TotalPrice  = Math.Round(model.TotalPrice, 2);
     return(View("EditPOItem", model));
 }
Exemple #2
0
 public bool SaveReviewedPOItem(Model.PurchaseOrderItem poItem)
 {
     using (var context = new SCMSEntities())
     {
         var item = context.PurchaseOrderItems.FirstOrDefault(p => p.Id == poItem.Id);
         context.Entry(item).CurrentValues.SetValues(poItem);
         ClearPOSessionData();
         ClearORSessionData();
         return((context.SaveChanges() > 0) ? true : false);
     }
 }
Exemple #3
0
        public bool SavePOItem(Model.PurchaseOrderItem entity)
        {
            using (var context = new SCMSEntities())
            {
                if (entity.Id.Equals(Guid.Empty))
                {
                    var poItem = context.PurchaseOrderItems.FirstOrDefault(p => p.OrderRequestItemId.HasValue && p.OrderRequestItemId == entity.OrderRequestItemId &&
                                                                           p.PurchaseOrderId == entity.PurchaseOrderId && p.BudgetLineId == entity.BudgetLineId && !p.ProcurementPlanItemId.HasValue);
                    var ppPoItem = context.PurchaseOrderItems.FirstOrDefault(p => !p.OrderRequestItemId.HasValue && p.ProcurementPlanItemId.HasValue &&
                                                                             p.ProcurementPlanItemId == entity.ProcurementPlanItemId &&
                                                                             p.PurchaseOrderId == entity.PurchaseOrderId && p.BudgetLineId == entity.BudgetLineId);
                    if (poItem == null && ppPoItem == null)
                    {
                        entity.Id = Guid.NewGuid();
                        context.PurchaseOrderItems.Add(entity);
                    }
                    else if (poItem != null)
                    {
                        poItem.Quantity  += entity.Quantity;
                        poItem.TotalPrice = (decimal)(poItem.Quantity * poItem.UnitPrice);
                    }
                    else if (ppPoItem != null)
                    {
                        ppPoItem.Quantity  += entity.Quantity;
                        ppPoItem.TotalPrice = (decimal)(ppPoItem.Quantity * ppPoItem.UnitPrice);
                    }
                }
                else
                {
                    var poItem = context.PurchaseOrderItems.FirstOrDefault(p => p.Id == entity.Id);
                    //update purchase order total
                    poItem.PurchaseOrder.TotalAmount -= poItem.TotalPrice;
                    poItem.PurchaseOrder.TotalAmount += entity.TotalPrice;

                    poItem.BudgetLineId = entity.BudgetLineId;
                    poItem.Quantity     = entity.Quantity;
                    poItem.Remarks      = entity.Remarks;
                    poItem.TotalPrice   = entity.TotalPrice;
                    poItem.UnitPrice    = entity.UnitPrice;
                }
                ClearPOSessionData();
                ClearORSessionData();
                return(context.SaveChanges() > 0);
            }
        }
Exemple #4
0
 public void AddPOItemsFromOR(Model.OrderRequest or, Guid poId)
 {
     using (var context = new SCMSEntities())
     {
         var po = context.PurchaseOrders.FirstOrDefault(p => p.Id == poId);
         using (TransactionScope scope = new TransactionScope())
         {
             try
             {
                 foreach (var orItem in or.OrderRequestItems.Where(o => o.Quantity > o.PurchaseOrderItems.Sum(p => p.Quantity)))
                 {
                     var poItem = new Model.PurchaseOrderItem
                     {
                         Id                 = Guid.NewGuid(),
                         Quantity           = (int)orItem.Quantity - orItem.PurchaseOrderItems.Sum(p => p.Quantity),
                         OrderRequestItemId = orItem.Id,
                         BudgetLineId       = orItem.BudgetLineId,
                         PurchaseOrderId    = poId,
                         Remarks            = orItem.Remarks,
                         UnitPrice          = (double)exchangeRateService.GetForeignCurrencyValue(po.CurrencyId, or.CurrencyId, orItem.EstimatedUnitPrice, or.CountryProgrammeId.Value)
                     };
                     poItem.TotalPrice = (decimal)(poItem.Quantity * poItem.UnitPrice);
                     context.PurchaseOrderItems.Add(poItem);
                     //Add to PO total amount
                     po.TotalAmount = po.TotalAmount.HasValue ? po.TotalAmount + poItem.TotalPrice : poItem.TotalPrice;
                 }
                 po.OrderRequestId = or.Id;
                 context.SaveChanges();
                 scope.Complete();
                 ClearPOSessionData();
                 ClearORSessionData();
             }
             catch (Exception ex)
             {
                 scope.Dispose();
             }
         }
     }
 }
Exemple #5
0
 public ActionResult UpdatePOItem(Model.PurchaseOrderItem model)
 {
     poService.SavePOItem(model);
     return(LoadPOItems(model.PurchaseOrderId));
 }