Esempio n. 1
0
        public void AuthorizeOrderRequest(Model.OrderRequest or)
        {
            try
            {
                decimal?amount;
                decimal?currAmount; //Amount in ProjectBudget currency
                using (var context = new SCMSEntities())
                {
                    var orItems = context.OrderRequestItems.Where(i => i.OrderRequestId == or.Id).ToList();
                    foreach (var orItem in orItems)
                    {
                        amount     = orItem.EstimatedPrice;
                        currAmount = exchangeRateService.GetForeignCurrencyValue(orItem.ProjectBudget.BudgetCategory.ProjectDonor.Currency, orItem.OrderRequest.Currency, amount, (Guid)or.CountryProgrammeId);
                        orItem.ProjectBudget.TotalCommitted += currAmount;

                        //Add to BudgetCommitment
                        var budgetCommitment = new BudgetCommitment();
                        budgetCommitment.Id = Guid.NewGuid();
                        budgetCommitment.OrderRequestItemId = orItem.Id;
                        budgetCommitment.AmountCommitted    = (decimal)currAmount;
                        budgetCommitment.DateCommitted      = DateTime.Now;
                        budgetCommitment.BudgetLineId       = orItem.ProjectBudget.Id;
                        context.BudgetCommitments.Add(budgetCommitment);
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 2
0
 private static String AuthSignature(Model.OrderRequest or, String authourisation)
 {
     authourisation += "<tr><th>Signature:</th><td>";
     if (or.Staff2 != null && or.Staff2.Person.SignatureImage != null)
     {
         authourisation += string.Format("<img src=\"{0}\" alt=\"\" style=\"max-width: 100px;\" />", "data:image/png;base64," + Convert.ToBase64String(or.Staff2.Person.SignatureImage));
     }
     authourisation += "</td><td>";
     if (or.Staff != null && or.Staff.Person.SignatureImage != null)
     {
         authourisation += string.Format("<img src=\"{0}\" alt=\"\" style=\"max-width: 100px;\" />", "data:image/png;base64," + Convert.ToBase64String(or.Staff.Person.SignatureImage));
     }
     authourisation += "</td><td>";
     if (or.IsReviewed.HasValue && or.IsReviewed.Value && or.Staff3.Person.SignatureImage != null)
     {
         authourisation += string.Format("<img src=\"{0}\" alt=\"\" style=\"max-width: 100px;\" />", "data:image/png;base64," + Convert.ToBase64String(or.Staff3.Person.SignatureImage));
     }
     authourisation += "</td><td>";
     if (or.IsAuthorized.HasValue && or.IsAuthorized.Value && or.Staff1.Person.SignatureImage != null)
     {
         authourisation += string.Format("<img src=\"{0}\" alt=\"\" style=\"max-width: 100px;\" />", "data:image/png;base64," + Convert.ToBase64String(or.Staff1.Person.SignatureImage));
     }
     authourisation += "</td><tr>";
     return(authourisation);
 }
Esempio n. 3
0
 public void BackDateOR(Model.OrderRequest or)
 {
     using (var context = new SCMSEntities())
     {
         using (TransactionScope scope = new TransactionScope())
         {
             try
             {
                 //Get Current OR from DB
                 var currentOR = context.OrderRequests.FirstOrDefault(o => o.Id == or.Id);
                 //Initialize BackDate object
                 var backDate = new DocumentBackDating();
                 backDate.Id             = Guid.NewGuid();
                 backDate.BackDatedBy    = or.BackDatedBy;
                 backDate.BackDatedOn    = DateTime.Now;
                 backDate.NewDate        = or.OrderDate.Value;
                 backDate.OrderRequestId = or.Id;
                 backDate.PreviousDate   = currentOR.OrderDate.Value;
                 backDate.Reason         = or.BackDatingReason;
                 //Insert BackDate details into db
                 context.DocumentBackDatings.Add(backDate);
                 //Update date on OR in db
                 currentOR.OrderDate = or.OrderDate;
                 context.SaveChanges();
                 scope.Complete();
                 ClearORSessionData();
             }
             catch (Exception ex)
             {
                 scope.Dispose();
                 throw ex;
             }
         }
     }
 }
Esempio n. 4
0
        public ActionResult AddPPItems2OR(ProcurementPlan model)
        {
            Model.OrderRequest     or = UserSession.CurrentSession.NewOR != null ? UserSession.CurrentSession.NewOR : orderRequestService.GetOrderRequestById(model.OrderRequestId);
            Model.OrderRequestItem orItem;
            ProcurementPlanItem    ppItem;

            foreach (ProcurementPlanItem ppItemModel in model.PPItemList)
            {
                if (!ppItemModel.AddedToOR)
                {
                    continue;
                }
                ppItem = ppService.GetProcurementPlanItemById(ppItemModel.Id);
                orItem = new OrderRequestItem();
                orItem.BudgetLineId          = ppItem.BudgetLineId;
                orItem.EstimatedUnitPrice    = exchangeRateService.GetForeignCurrencyValue(or.CurrencyId, ppItem.CurrencyId, ppItemModel.UnitCost, countryProg.Id);
                orItem.EstimatedPrice        = orItem.EstimatedUnitPrice * ppItemModel.QuantityToOrder;
                orItem.Quantity              = ppItemModel.QuantityToOrder;
                orItem.ItemDescription       = ppItem.ItemDescription;
                orItem.ItemId                = ppItem.ItemId;
                orItem.OrderRequestId        = model.OrderRequestId;
                orItem.ProcurementPlanItemId = ppItem.Id;
                orderRequestService.AddOrderRequstItem(orItem, UserSession.CurrentSession.NewOR);
                if (UserSession.CurrentSession.NewOR != null)
                {
                    UserSession.CurrentSession.NewOR = null;
                }
            }

            return(ViewOrderRequestItems(model.OrderRequestId));
        }
Esempio n. 5
0
        public ActionResult ViewOrderRequestItems(Guid id, List <BudgetCheckResult> brcList = null)
        {
            Model.OrderRequest model = orderRequestService.GetOrderRequestById(id);
            model.BudgetCheckResults = brcList;
            //Manage Edit/Delete Link
            model.CanEdit = (!model.IsSubmitted && model.IsRejected != true && model.Staff2.Id == currentStaff.Id) ||
                            (model.IsSubmitted && model.IsRejected == true && model.IsReviewed != true && model.Staff2.Id == currentStaff.Id);
            //Manage approval link
            string actionType = null;

            if (model.IsReviewed == true && model.IsAuthorized == false)
            {
                actionType = NotificationHelper.authorizationCode;
            }
            else if (model.IsApproved && model.IsReviewed == false)
            {
                actionType = NotificationHelper.reviewCode;
            }
            else if (model.IsSubmitted && !model.IsApproved)
            {
                actionType = NotificationHelper.approvalCode;
            }
            if (actionType != null)
            {
                model.CanApprove = notificationService.CanApprove(currentUser, NotificationHelper.orCode, actionType, model.Id);
            }
            else
            {
                model.CanApprove = false;
            }
            model.CanPreparePO = orderRequestService.CanPreparePO(id) && userContext.HasPermission(StandardPermissionProvider.PurchaseOrderManage);

            return(View("ViewOrderRequestItems", model));
        }
Esempio n. 6
0
        public void UndoAuthorization(Model.OrderRequest or)
        {
            try
            {
                decimal?amount;
                decimal?currAmount; //Amount in ProjectBudget currency
                using (var context = new SCMSEntities())
                {
                    var orItems = context.OrderRequestItems.Where(i => i.OrderRequestId == or.Id).ToList();
                    foreach (var orItem in orItems)
                    {
                        amount     = orItem.EstimatedPrice;
                        currAmount = exchangeRateService.GetForeignCurrencyValue(orItem.ProjectBudget.BudgetCategory.ProjectDonor.Currency, orItem.OrderRequest.Currency, amount, (Guid)or.CountryProgrammeId);
                        orItem.ProjectBudget.TotalCommitted -= currAmount;

                        var budgetCommitmentList = context.BudgetCommitments.Where(b => b.OrderRequestItemId == orItem.Id).ToList();

                        foreach (var budgetCommitment in budgetCommitmentList)
                        {
                            context.BudgetCommitments.Remove(budgetCommitment);
                        }
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 7
0
        private DataTable GetTable(Guid orderId)
        {
            var dbContext   = new SCMSEntities();
            var orderDetail = dbContext.OrderRequests.First(r => r.Id == orderId);

            Model.OrderRequest     myOrder  = (Model.OrderRequest)orderDetail;
            Model.Currency         currency = dbContext.Currencies.First(c => c.Id == myOrder.CurrencyId);
            Model.CountryProgramme prgm     = dbContext.CountryProgrammes.First(p => p.Id == myOrder.CountryProgrammeId);
            Model.Project          subP     = dbContext.Projects.FirstOrDefault(p => p.Id == myOrder.ProjectId);
            Model.Donor            donor    = dbContext.ProjectDonors.First(d => d.Id == myOrder.ProjectDonorId).Donor;
            Model.Location         reqDes   = dbContext.Locations.First(l => l.Id == myOrder.RequestedDestinationId);
            Model.Location         finDes   = dbContext.Locations.First(l => l.Id == myOrder.FinalDestinationId);

            DataTable table = new DataTable();

            table.Columns.Add("Order Request", typeof(string));
            table.Columns.Add("Date", typeof(string));
            table.Columns.Add("Currency of OR", typeof(string));

            table.Rows.Add(myOrder.RefNumber, myOrder.OrderDate.Value.ToShortDateString(), currency.Name);
            table.Rows.Add("Program:", "Project:", "Donor");
            table.Rows.Add(prgm.ProgrammeName, subP.Name, donor.Name);
            table.Rows.Add("Requested Delivery Date:", "Requested Delivery Destination:", "Final Delivery Destination:");
            table.Rows.Add(myOrder.DeliveryDate.HasValue ? ((DateTime)myOrder.DeliveryDate).ToString("dd.MMM.yyyy") : "-",
                           reqDes.Name, finDes.Name);

            return(table); // Return reference.
        }
Esempio n. 8
0
 public ActionResult BackDateOR(Model.OrderRequest model)
 {
     if (model.OrderDate.Value > DateTime.Today)
     {
         return(ViewOrderRequestItems(model.Id));
     }
     model.BackDatedBy = currentStaff.Id;
     orderRequestService.BackDateOR(model);
     return(ViewOrderRequestItems(model.Id));
 }
Esempio n. 9
0
        private ViewPOs ViewPurchaseOrdersDetails(Guid id)
        {
            ViewPOrderItems        POItmz;
            List <ViewPOrderItems> POItemList = new List <ViewPOrderItems>();

            using (var context = new SCMSEntities())
            {
                Model.PurchaseOrder             Po      = context.PurchaseOrders.SingleOrDefault(p => p.Id == id);
                ICollection <PurchaseOrderItem> POItemz = Po.PurchaseOrderItems;
                foreach (PurchaseOrderItem item in POItemz)
                {
                    POItmz = new ViewPOrderItems();
                    POItmz.EntityPOItem = item;
                    POItmz.BudgetLine   =
                        context.ProjectBudgets.SingleOrDefault(p => p.Id == item.BudgetLineId).LineNumber;
                    POItmz.ProjectNo  = item.PurchaseOrder.OrderRequest.ProjectDonor.ProjectNumber;
                    POItmz.Unitmessue = context.UnitOfMeasures.SingleOrDefault(p => p.Id == item.OrderRequestItem.Item.UnitOfMessureId).Code;
                    OrderRequestItem orit = item.OrderRequestItem;
                    Item             itm  = orit.Item;
                    POItemList.Add(POItmz);
                }

                ViewPOs model = new ViewPOs();

                model.POEntiy        = Po;
                model.supplier       = context.Suppliers.SingleOrDefault(p => p.Id == Po.SupplierId).Name;
                model.paymentTerm    = context.PaymentTerms.SingleOrDefault(p => p.Id == Po.PaymentTermId).Code;
                model.shippingTerm   = context.ShippingTerms.SingleOrDefault(p => p.Id == Po.ShippingTermId).Name;
                model.POItems        = POItemList;
                model.deleliveryDate = (DateTime)Po.LatestDeliveryDate;
                model.PODate         = (DateTime)Po.PreparedOn;
                model.StaffEntity    = context.Staffs.SingleOrDefault(p => p.Id == Po.PreparedBy);
                model.TotalAmount    = Po.TotalAmount;
                model.MBValue        = Po.MBValue;
                Person      ps = model.StaffEntity.Person;
                Designation ds = model.StaffEntity.Designation;
                if ((bool)Po.IsApproved)
                {
                    Staff authoriz = context.Staffs.SingleOrDefault(p => p.Id == Po.ApprovedBy);
                    model.AuthorizTitle = authoriz.Designation.Name;
                    model.AuthorizdBy   = authoriz.Person.FirstName + " " + authoriz.Person.OtherNames;
                    model.AuthorizDate  = Po.ApprovedOn.Value.ToString(Constants.DATETIME_FORMAT);
                }

                Model.OrderRequest or  = Po.OrderRequest;
                Location           loc = Po.Location;
                model.Currency   = or.Currency.ShortName;
                model.MBCurrency = or.CountryProgramme.Currency.ShortName;
                return(model);
            }
        }
Esempio n. 10
0
        public void DeleteOrderRequst(Guid id)
        {
            ClearORSessionData();
            ClearPPItemSessionData();

            using (var dbContext = new SCMSEntities())
            {
                Model.OrderRequest odaRequest = dbContext.OrderRequests.FirstOrDefault(o => o.Id == id);

                odaRequest.OrderRequestItems.ToArray().ForEach(s => dbContext.OrderRequestItems.Remove(s));
                dbContext.OrderRequests.Remove(odaRequest);
                dbContext.SaveChanges();
            }
        }
Esempio n. 11
0
        public ActionResult AddItemInEditMode(Guid id)
        {
            Model.OrderRequest    or     = orderRequestService.GetOrderRequestById(id);
            List <BudgetLineView> blList = orderRequestService.GetProjectBugdetLines((Guid)or.ProjectDonorId);
            OrderRequestItem      model  = new OrderRequestItem
            {
                Id             = Guid.Empty,
                BudgetLines    = new SelectList(blList, "Id", "Description"),
                Items          = new SelectList(orderRequestService.GetItems(), "Id", "Name"),
                OrderRequestId = id
            };

            ViewBag.Action = Resources.Global_String_Add;
            return(View("AddItemInEditMode", model));
        }
Esempio n. 12
0
 public bool UpdateOrderRequest(Model.OrderRequest entity)
 {
     using (var context = new SCMSEntities())
     {
         var existing = context.OrderRequests.FirstOrDefault(o => o.Id == entity.Id);
         context.Entry(existing).CurrentValues.SetValues(entity);
         if (context.SaveChanges() > 0)
         {
             //Clear session data
             ClearORSessionData();
             return(true);
         }
         return(false);
     }
 }
Esempio n. 13
0
        public ActionResult SelectOR(Guid PoId, Guid OrId, Guid PdId)
        {
            Model.PurchaseOrder model = poService.GetPurchaseOrderById(PoId);
            //G Order Requests with unprocessed items
            List <Model.OrderRequest> orList = poService.GetOrderRequestsForPO(countryProg.Id).Where(o => o.ProjectDonorId == PdId).ToList();

            Model.OrderRequest selectedOR = null;
            foreach (var or in orList)
            {
                if (or.Id == OrId)
                {
                    selectedOR = or;
                    break;
                }
            }
            if (orList.Count > 0)
            {
                if (selectedOR == null)
                {
                    selectedOR = orList[0];
                }
                var projectList = UserSession.CurrentSession.OrderRequestList.OrderBy(o => o.ProjectDonor.Project.Name).Select(o => o.ProjectDonor.Project).Distinct().ToList();
                var pdList      = orList.Where(o => o.ProjectDonor.ProjectId == selectedOR.ProjectDonor.ProjectId).Select(o => o.ProjectDonor).Distinct().ToList();
                model.ProjectId      = selectedOR.ProjectDonor.ProjectId;
                model.ProjectDonorId = PdId;

                model.Projects       = new SelectList(projectList, "Id", "Name", model.ProjectId);
                model.ProjectDonors  = new SelectList(pdList, "Id", "ProjectNumber", PdId);
                model.OrderRequest   = selectedOR;
                model.OrderRequestId = selectedOR.Id;
                model.OrderRequests  = new SelectList(orList, "Id", "RefNumber", selectedOR.Id);
                model.POItems        = model.PurchaseOrderItems.ToList();
                //model.ORItems = poService.GetUnprocessedORItems(selectedOR.Id);
                model.ORItems = selectedOR.OrderRequestItems.Where(i => i.Quantity > i.PurchaseOrderItems.Sum(p => p.Quantity)).ToList();

                foreach (var orItem in model.ORItems)
                {
                    ConvertORItemNumbersToPOCurrency(model, orItem);
                    orItem.AddToPO        = true;
                    orItem.Quantity       = (int)orItem.Quantity - orItem.PurchaseOrderItems.Sum(p => p.Quantity);
                    orItem.EstimatedPrice = orItem.EstimatedUnitPrice * orItem.Quantity;
                    orItem.BudgetLines    = new SelectList(orService.GetProjectBugdetLines((Guid)selectedOR.ProjectDonorId), "Id", "Description", orItem.BudgetLineId);
                }
                model.SameCurrency = model.Currency.Id.Equals(selectedOR.Currency.Id);
            }
            return(View("AddPOItems", model));
        }
Esempio n. 14
0
        public ActionResult SaveOrderRequest(Model.OrderRequest entity)
        {
            entity.Id = Guid.NewGuid();
            entity.CountryProgrammeId = countryProg.Id;
            entity.PreparedBy         = currentStaff.Id;
            entity.TotalAmount        = 0;
            entity.IsReviewed         = false;
            entity.IsAuthorized       = false;
            entity.PreparedOn         = DateTime.Now;

            UserSession.CurrentSession.NewOR = entity;
            if (entity.FromPP)
            {
                return(AddPPItems2OR(entity.ProjectDonorId.Value, entity));
            }
            return(PopulateCreateItem(entity.Id));
        }
Esempio n. 15
0
 public ActionResult EditOrderRequest(Guid id)
 {
     Model.OrderRequest model = orderRequestService.GetOrderRequestById(id);
     if (model == null)
     {
         if (UserSession.CurrentSession.NewOR.Id.Equals(id))
         {
             model = UserSession.CurrentSession.NewOR;
             model.ProjectDonor = orderRequestService.GetProjectDonorById(model.ProjectDonorId.Value);
         }
     }
     model.Currencies    = new SelectList(orderRequestService.GetCurrencies(), "Id", "ShortName");
     model.Projects      = new SelectList(orderRequestService.GetProject(), "Id", "Name");
     model.ProjectDonors = new SelectList(orderRequestService.GetProjectNos(model.ProjectId), "Id", "ProjectNumber");
     model.Locations     = new SelectList(orderRequestService.GetLocations(), "Id", "Name");
     return(View("EditOrderRequest", model));
 }
Esempio n. 16
0
        public ActionResult LoadOrderRequest(bool fromPP = false)
        {
            List <Model.Project> projects = fromPP ? orderRequestService.GetProjectsWithPP() : orderRequestService.GetProject();

            Model.OrderRequest model = new Model.OrderRequest
            {
                OrderDate     = DateTime.Today,
                Currencies    = new SelectList(orderRequestService.GetCurrencies(), "Id", "ShortName"),
                Projects      = new SelectList(projects, "Id", "Name"),
                ProjectDonors = new SelectList(orderRequestService.GetProjectNos(Guid.Empty), "Id", "ProjectNumber"),
                Locations     = new SelectList(orderRequestService.GetLocations(), "Id", "Name"),
                RefNumber     = string.Format("--{0}--", Resources.Global_String_NewOR),
                CurrencyId    = countryProg.Country.CurrencyId.HasValue ? countryProg.Country.CurrencyId.Value : mbCurrency.Id,
                FromPP        = fromPP
            };
            return(View("LoadOrderRequest", model));
        }
Esempio n. 17
0
        private ActionResult PopulateCreateItem(Guid id, string errormessage = "", Guid?selectedItem = null)
        {
            Model.OrderRequest or = UserSession.CurrentSession.NewOR == null?orderRequestService.GetOrderRequestById(id) : UserSession.CurrentSession.NewOR;

            List <BudgetLineView> blList = orderRequestService.GetProjectBugdetLines((Guid)or.ProjectDonorId);
            OrderRequestItem      model  = new OrderRequestItem
            {
                BudgetLines    = new SelectList(blList, "Id", "Description"),
                Items          = new SelectList(orderRequestService.GetItems(), "Id", "Name"),
                OrderRequestId = id
            };

            if (selectedItem.HasValue)
            {
                model.ItemId = selectedItem.Value;
            }
            return(View("LoadRequestItem", model));
        }
Esempio n. 18
0
        public string GenerateUniquNumber(CountryProgramme cp)
        {
            string code      = "OR/DRC/" + cp.Country.ShortName + "/";
            string refNumber = "";
            long   count     = 1;

            using (var dbContext = new SCMSEntities())
            {
                var total = SessionData.CurrentSession.OrderRequestList.Where(p => p.IsSubmitted).Count();
                count = total;
                Model.OrderRequest m = null;
                do
                {
                    count++;
                    if (count < 100000)
                    {
                        if (count < 10)
                        {
                            refNumber = code + "0000" + count;
                        }
                        if (count < 100 && count >= 10)
                        {
                            refNumber = code + "000" + count;
                        }
                        if (count < 1000 && count >= 100)
                        {
                            refNumber = code + "00" + count;
                        }
                        if (count < 10000 && count >= 1000)
                        {
                            refNumber = code + "0" + count;
                        }
                        if (count < 100000 && count >= 10000)
                        {
                            refNumber = code + count;
                        }
                    }
                    m = SessionData.CurrentSession.OrderRequestList.FirstOrDefault(p => p.RefNumber == refNumber);
                } while (m != null);
                return(refNumber);
            }
        }
Esempio n. 19
0
        public ActionResult UpdateOrderRequest(Model.OrderRequest entity)
        {
            bool projectChange = false;

            Model.OrderRequest or = orderRequestService.GetOrderRequestById(entity.Id);
            or.ProjectId  = entity.ProjectId;
            or.CurrencyId = entity.CurrencyId;
            //check if project changed
            if (!or.ProjectDonorId.Value.Equals(entity.ProjectDonorId.Value))
            {
                projectChange = true;
            }
            or.ProjectDonorId         = entity.ProjectDonorId;
            or.RequestedDestinationId = entity.RequestedDestinationId;
            or.FinalDestinationId     = entity.FinalDestinationId;
            or.OrderDate    = entity.OrderDate;
            or.DeliveryDate = entity.DeliveryDate;
            orderRequestService.UpdateORWithPossibleProjectChange(or, projectChange);
            return(ViewOrderRequestItems(or.Id));
        }
Esempio n. 20
0
        public ActionResult SubmitOR(Guid Id)
        {
            Model.OrderRequest or = orderRequestService.GetOrderRequestById(Id);
            //Run another check on funds availability
            List <BudgetCheckResult> bcrList = orderRequestService.RunFundsAvailableCheck(Id);

            if (bcrList.Count > 0)
            {
                return(ViewOrderRequestItems(Id, bcrList));//Render OR with message saying funds not sufficient
            }
            or.IsRejected   = false;
            or.IsAuthorized = false;
            or.IsReviewed   = false;
            or.IsSubmitted  = true;
            or.PreparedBy   = currentStaff.Id;
            or.PreparedOn   = or.OrderDate = DateTime.Now;
            or.RefNumber    = orderRequestService.GenerateUniquNumber(countryProg);
            orderRequestService.UpdateOrderRequest(or);
            //Send notification
            notificationService.SendToAppropriateApprover(NotificationHelper.orCode, NotificationHelper.approvalCode, or.Id);
            return(ViewOrderRequests());
        }
Esempio n. 21
0
        public ActionResult AddPPItems2OR(Guid pdId, Model.OrderRequest or)
        {
            ProcurementPlan model = ppService.GetProcurementPlanByProjectId(pdId);

            if (model == null)
            {
                return(Content("<i style=\"color: Red\">" + Resources.OrderRequestController_String_NoPPItems + "</i>", "text/html"));
            }
            model.PPItemList     = model.ProcurementPlanItems.Where(p => (p.Quantity - p.ProcuredAmount) > 0).OrderBy(p => p.Item.Name).ToList();
            model.OrderRequestId = or.Id;
            Currency orCurr = currencyService.GetCurrency(or.CurrencyId);

            foreach (ProcurementPlanItem ppItem in model.PPItemList)
            {
                ppItem.UnitCost        = Math.Round(exchangeRateService.GetForeignCurrencyValue(or.CurrencyId, ppItem.CurrencyId, ppItem.UnitCost, countryProg.Id), 2);
                ppItem.QuantityToOrder = ppItem.Quantity - ppItem.ProcuredAmount;
                ppItem.TotalCost       = Math.Round((ppItem.UnitCost * ppItem.QuantityToOrder), 2);
            }
            //model.PPItemList = model.ProcurementPlanItems.Where(p => !p.AddedToOR && p.IsApproved && !p.IsRemoved).OrderBy(p => p.Item.Name).ToList();
            ViewBag.Currency = orCurr.ShortName;
            return(View("AddPPItems2OR", model));
        }
Esempio n. 22
0
 private static String AuthDate(Model.OrderRequest or, String authourisation)
 {
     authourisation += "<tr><th>Date:</th><td>";
     authourisation += or.PreparedOn.HasValue ? or.PreparedOn.Value.ToString(Constants.DATETIME_FORMAT) : string.Empty;
     authourisation += "</td><td>";
     if (or.IsApproved)
     {
         authourisation += or.ApprovedOn.Value.ToString(Constants.DATETIME_FORMAT);
     }
     authourisation += "</td><td>";
     if (or.IsReviewed.HasValue && or.IsReviewed.Value)
     {
         authourisation += or.ReviewedOn.Value.ToString(Constants.DATETIME_FORMAT);
     }
     authourisation += "</td><td>";
     if (or.IsAuthorized.HasValue && or.IsAuthorized.Value)
     {
         authourisation += or.AuthorizedOn.Value.ToString(Constants.DATETIME_FORMAT);
     }
     authourisation += "</td><tr>";
     return(authourisation);
 }
Esempio n. 23
0
 private static String AuthTitle(Model.OrderRequest or, String authourisation)
 {
     authourisation += "<tr><th>Title:</th><td>";
     authourisation += or.Staff2 != null ? or.Staff2.Designation.Name : string.Empty;
     authourisation += "</td><td>";
     if (or.Staff != null)
     {
         authourisation += or.Staff != null ? or.Staff.Designation.Name : string.Empty;
     }
     authourisation += "</td><td>";
     if (or.Staff3 != null)
     {
         authourisation += or.Staff3.Designation.Name;
     }
     authourisation += "</td><td>";
     if (or.Staff1 != null)
     {
         authourisation += or.Staff1.Designation.Name;
     }
     authourisation += "</td><tr>";
     return(authourisation);
 }
Esempio n. 24
0
 private static String AuthName(Model.OrderRequest or, String authourisation)
 {
     authourisation += "<tr><th>Name:</th><td>";
     authourisation += or.Staff2 != null ? or.Staff2.Person.FirstName + " " + or.Staff2.Person.OtherNames : string.Empty;
     authourisation += "</td><td>";
     if (or.Staff != null)
     {
         authourisation += or.Staff != null ? or.Staff.Person.FirstName + " " + or.Staff.Person.OtherNames : string.Empty;
     }
     authourisation += "</td><td>";
     if (or.Staff3 != null)
     {
         authourisation += or.Staff3.Person.FirstName + " " + or.Staff3.Person.OtherNames;
     }
     authourisation += "</td><td>";
     if (or.Staff1 != null)
     {
         authourisation += or.Staff1.Person.FirstName + " " + or.Staff1.Person.OtherNames;
     }
     authourisation += "</td><tr>";
     return(authourisation);
 }
Esempio n. 25
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();
             }
         }
     }
 }
Esempio n. 26
0
 public bool UpdateORWithPossibleProjectChange(Model.OrderRequest or, bool projectChanged)
 {
     ClearORSessionData();
     if (!projectChanged)
     {
         return(this.UpdateOrderRequest(or));
     }
     using (var context = new SCMSEntities())
     {
         var entity      = context.OrderRequests.FirstOrDefault(o => o.Id == or.Id);
         var defaultBLId = SessionData.CurrentSession.ProjectDonorList.FirstOrDefault(p => p.Id == or.ProjectDonorId).BudgetCategories.FirstOrDefault().ProjectBudgets.FirstOrDefault();
         if (defaultBLId == null)
         {
             return(false);
         }
         foreach (var orItem in entity.OrderRequestItems)
         {
             orItem.BudgetLineId = defaultBLId.Id;
         }
         context.Entry(entity).CurrentValues.SetValues(or);
         return(context.SaveChanges() > 0);
     }
 }
Esempio n. 27
0
        public List <Model.OrderRequest> Search(Model.OrderRequest entity)
        {
            List <Model.OrderRequest> orlist = SessionData.CurrentSession.OrderRequestList.Where(p => p.RefNumber.Contains(entity.RefNumber)).OrderByDescending(p => p.PreparedOn).ToList();

            return(orlist);
        }
Esempio n. 28
0
        private ActionResult PreparePdf(Guid orId, int pagecount)
        {
            string original = "original", copy = "copy";
            Dictionary <String, String> data = new Dictionary <string, string>();

            Model.OrderRequest model         = orderRequestService.GetOrderRequestById(orId);
            //prepare labels
            PrepareLabels(data);
            data.Add("{REQ_NO.}", model.RefNumber);
            data.Add("{ISSUE-DATE}", model.OrderDate.HasValue ? model.OrderDate.Value.ToString(Constants.DATE_FORMAT) : string.Empty);
            data.Add("{CURRENCY}", model.Currency != null ? model.Currency.ShortName : string.Empty);

            data.Add("{PROJECT-NAME}", model.ProjectDonor.Project.Name);
            data.Add("{PROJECT-NO}", model.ProjectDonor.ProjectNumber);
            data.Add("{DONOR}", model.ProjectDonor.Donor.ShortName);

            data.Add("{DELIVERY-DATE}", model.DeliveryDate.HasValue ? model.DeliveryDate.Value.ToString(Constants.DATE_FORMAT) : string.Empty);
            data.Add("{DELIVERY-DESTINATION}", model.Location1 != null ? model.Location1.Name : string.Empty);
            data.Add("{FINAL-DESTINATION}", model.Location != null ? model.Location.Name : string.Empty);

            int    count      = 1;
            String detailHtml = "";

            foreach (var item in model.OrderRequestItems.ToList())
            {
                detailHtml += "<tr ><td align=\"center\">" + count++ + "</td><td>";
                detailHtml += item.Item.Name;
                detailHtml += "</td><td>";
                detailHtml += item.ItemDescription;
                detailHtml += "</td><td>";
                detailHtml += item.Item.UnitOfMeasure.Code;
                detailHtml += "</td><td align=\"center\">";
                detailHtml += item.Quantity.ToString(Constants.NUMBER_FORMAT_NO_DECIMAL);
                detailHtml += "</td><td align=\"right\">";
                detailHtml += item.EstimatedUnitPrice.ToString(Constants.NUMBER_FORMAT_TWO_DECIMAL);
                detailHtml += "</td><td align=\"right\">";
                detailHtml += item.EstimatedPrice.ToString(Constants.NUMBER_FORMAT_TWO_DECIMAL);
                detailHtml += "</td><td align=\"center\">";
                detailHtml += item.ProjectBudget.BudgetCategory.ProjectDonor.ProjectNumber;
                detailHtml += "</td><td align=\"center\">";
                detailHtml += item.ProjectBudget.LineNumber;
                detailHtml += "</td><td>";
                detailHtml += item.Remarks;
                detailHtml += "</td></tr>";
            }
            while (count < 18)
            {
                detailHtml += "<tr ><td align=\"center\">" + count++ + "</td><td>";
                detailHtml += "</td><td>";
                detailHtml += "</td><td>";
                detailHtml += "</td><td align=\"center\">";
                detailHtml += "</td><td align=\"right\">";
                detailHtml += "</td><td align=\"right\">";
                detailHtml += "</td><td align=\"center\">";
                detailHtml += "</td><td align=\"center\">";
                detailHtml += "</td><td>";
                detailHtml += "</td></tr>";
            }
            data.Add("{DETAILS}", detailHtml);

            data.Add("{OR-CURRENCY}", model.Currency != null ? model.Currency.ShortName : string.Empty);
            data.Add("{OR-VALUE}", model.TotalAmount.HasValue ? model.TotalAmount.Value.ToString(Constants.NUMBER_FORMAT_TWO_DECIMAL) : string.Empty);

            data.Add("{MB-CURRENCY}", model.Currency1 != null ? model.Currency1.ShortName : string.Empty);
            data.Add("{MB-VALUE}", model.MBValue.HasValue ? model.MBValue.Value.ToString(Constants.NUMBER_FORMAT_TWO_DECIMAL) : string.Empty);

            data.Add("{REMARKS}", model.Remarks);

            String authourisation = "";

            authourisation = AuthName(model, authourisation);
            authourisation = AuthTitle(model, authourisation);
            authourisation = AuthDate(model, authourisation);
            authourisation = AuthSignature(model, authourisation);
            data.Add("{AUTHORISATION}", authourisation);

            //data.Add("{PAGETYPE}", pagecount == 1 ? original : copy);
            List <String> options = new List <string>();

            options.Add(" --copies 2 ");
            //options.Add(" --footer-center page 1 of 1 – original ");

            Byte[] output = WkHtml2Pdf.CreateReport(data, "Order-Request.htm", options);
            //if (pagecount == 1)
            //    return PreparePdf(orId, ++pagecount);
            //else
            return(File(output, "application/pdf", "OR_" + DateTime.Now.FormatDDMMMYYYYHHmm()));
        }
Esempio n. 29
0
 public ActionResult BackDateOR(Guid id)
 {
     Model.OrderRequest model = orderRequestService.GetOrderRequestById(id);
     return(View("BackDateOR", model));
 }
Esempio n. 30
0
        private string ORStatus(Model.OrderRequest or, out DateTime statusDate)
        {
            string orStatus;

            if (or.IsAuthorized == true)
            {
                orStatus = Resources.Global_String_StatusAU;
            }
            else if (or.IsRejected == true)
            {
                orStatus = Resources.Global_String_StatusRJ;
            }
            else if (or.IsReviewed == true)
            {
                orStatus = Resources.Global_String_StatusRV;
            }
            else if (or.IsApproved)
            {
                orStatus = Resources.Global_String_StatusAP;
            }
            else if (or.IsSubmitted == true)
            {
                orStatus = Resources.Global_String_StatusCR;
            }
            else
            {
                orStatus = Resources.Global_String_StatusNEW;
            }

            //Get OR Status date
            if (or.IsAuthorized == true)
            {
                statusDate = or.AuthorizedOn.Value;
            }
            else if (or.IsRejected == true)
            {
                if (or.AuthorizedOn.HasValue)
                {
                    statusDate = or.AuthorizedOn.Value;
                }
                else if (or.ReviewedOn.HasValue)
                {
                    statusDate = or.ReviewedOn.Value;
                }
                else
                {
                    statusDate = or.ApprovedOn.Value;
                }
            }
            else if (or.IsReviewed == true)
            {
                statusDate = or.ReviewedOn.Value;
            }
            else if (or.IsApproved)
            {
                statusDate = or.ApprovedOn.Value;
            }
            else if (or.IsSubmitted == true)
            {
                statusDate = or.PreparedOn.Value;
            }
            else
            {
                statusDate = or.PreparedOn.Value;
            }

            return(orStatus);
        }