Exemple #1
0
        public ActionResult LoadAttacheDocs(Model.PurchaseOrder model)
        {
            //Run another check on funds availability
            List <BudgetCheckResult> bcrList = poService.RunFundsAvailableCheck(model.Id);

            if (bcrList.Count > 0)
            {
                return(LoadPOItems(model.Id, bcrList));//Render PO with message saying funds not sufficient
            }
            Model.PurchaseOrder po = poService.GetPurchaseOrderById(model.Id);
            po.ProformaRequired          = model.ProformaRequired;
            po.CommercialInvoiceRequired = model.CommercialInvoiceRequired;
            po.WayBillRequired           = model.WayBillRequired;
            po.PackingListRequired       = model.PackingListRequired;
            po.DeliveryNoteRequired      = model.DeliveryNoteRequired;
            po.ManualsRequired           = model.ManualsRequired;
            po.CertificatesReqired       = model.CertificatesReqired;
            po.OtherRequired             = model.OtherRequired;
            if (po.OtherRequired == true)
            {
                po.OtherSpecify = model.OtherSpecify;
            }
            po.ShippingMarks    = model.ShippingMarks;
            po.ConsigneeAddress = model.ConsigneeAddress;
            po.ConsigneeEmail1  = model.ConsigneeEmail1;
            po.ConsigneeEmail2  = model.ConsigneeEmail2;
            po.PrefinancingGuaranteeRequired = model.PrefinancingGuaranteeRequired;
            if (po.PrefinancingGuaranteeRequired == true)
            {
                po.PFGPercentage = model.PFGPercentage;
            }
            poService.SaveReviewedPO(po);
            return(LoadAttachDocs(po.Id));
        }
        public bool UpdatePurchaseOrder(Model.PurchaseOrder po)
        {
            List <bool> statuses = new List <bool>();

            List <ParmStruct> parms = new List <ParmStruct>()
            {
                new ParmStruct("@TimeStamp", po.TimeStamp, SqlDbType.Timestamp, ParameterDirection.InputOutput),
                new ParmStruct("@PurchaseOrderId", po.PurchaseOrderId, SqlDbType.Int),
                new ParmStruct("@Status", po.Status, SqlDbType.Int),
                new ParmStruct("@Subtotal", po.Subtotal, SqlDbType.Decimal),
                new ParmStruct("@Tax", po.Tax, SqlDbType.Decimal),
                new ParmStruct("@TotalAfterTax", po.TotalAfterTax, SqlDbType.Decimal)
            };

            statuses.Add(db.ExecuteNonQuery("PO_Update", CommandType.StoredProcedure, parms) > 0);

            po.TimeStamp = (byte[])(parms[0].Value);

            foreach (Item item in po.Items)
            {
                if (item.ItemId == 0)
                {
                    statuses.Add(ItemInsert(item));
                }
                else
                {
                    statuses.Add(ItemUpdate(item));
                }
            }

            return(statuses.Contains(false) ? false : true);
        }
Exemple #3
0
        public ActionResult LoadPO()
        {
            var model = new Model.PurchaseOrder()
            {
                PODate             = DateTime.Today,
                LatestDeliveryDate = DateTime.Today,
                Currencies         = new SelectList(orService.GetCurrencies(), "Id", "ShortName",
                                                    UserSession.CurrentSession.NewOR != null ? UserSession.CurrentSession.NewOR.CurrencyId : Guid.Empty),
                Projects = new SelectList(orService.GetProject(), "Id", "Name",
                                          UserSession.CurrentSession.NewOR != null ? UserSession.CurrentSession.NewOR.ProjectId : Guid.Empty),
                ProjectDonors = new SelectList(orService.GetProjectNos(UserSession.CurrentSession.NewOR != null ? UserSession.CurrentSession.NewOR.ProjectId : Guid.Empty), "Id", "ProjectNumber",
                                               UserSession.CurrentSession.NewOR != null ? UserSession.CurrentSession.NewOR.ProjectDonorId : Guid.Empty),
                Suppliers     = new SelectList(poService.GetSuppliers(), "Id", "Name"),
                ShippingTerms = new SelectList(poService.GetShippingTerms(), "Id", "Description"),
                Locations     = new SelectList(orService.GetLocations(), "Id", "Name"),
                PaymentTerms  = new SelectList(poService.GetPaymentTerms(), "Id", "Description"),
                RefNumber     = string.Format("--{0}--", Resources.Global_String_NewPO)
            };

            if (UserSession.CurrentSession.NewOR != null)
            {
                model.ProjectDonorId = UserSession.CurrentSession.NewOR.ProjectDonorId;
                model.CurrencyId     = UserSession.CurrentSession.NewOR.CurrencyId;
                model.ProjectId      = UserSession.CurrentSession.NewOR.ProjectId;
            }
            return(View("LoadPO", model));
        }
Exemple #4
0
 public bool SavePuchaseOrder(Model.PurchaseOrder entity)
 {
     using (var context = new SCMSEntities())
     {
         if (entity.Id.Equals(Guid.Empty))
         {
             entity.Id = Guid.NewGuid();
             context.PurchaseOrders.Add(entity);
         }
         else
         {
             var po = context.PurchaseOrders.FirstOrDefault(p => p.Id == entity.Id);
             po.CurrencyId         = entity.CurrencyId;
             po.DeliveryAddress    = entity.DeliveryAddress;
             po.LatestDeliveryDate = entity.LatestDeliveryDate;
             po.PaymentTermId      = entity.PaymentTermId;
             po.PODate             = entity.PODate;
             po.ProjectDonorId     = entity.ProjectDonorId;
             po.QuotationRef       = entity.QuotationRef;
             po.Remarks            = entity.Remarks;
             po.ShippingTermId     = entity.ShippingTermId;
             po.SupplierId         = entity.SupplierId;
             po.IsInternational    = entity.IsInternational;
         }
         ClearPOSessionData();
         return(context.SaveChanges() > 0);
     }
 }
Exemple #5
0
        public ActionResult ViewPurchaseOrdersDetails(Guid id)
        {
            Model.PurchaseOrder model = poService.GetPurchaseOrderById(id);
            model.AttachedDocuments = poService.GetPOAttachedDocuments(model.Id);

            model.POItems = model.PurchaseOrderItems.ToList();

            model.CanEdit = (!model.IsSubmitted && !model.IsRejected && model.Staff1.Id == currentStaff.Id) ||
                            (model.IsSubmitted && model.IsRejected && model.Staff1.Id == currentStaff.Id);
            //Check number of ORs/PPs
            var ors = poService.GetPOrderORs(id).Count;
            var pps = poService.GetPOrderPPs(id).Count;

            model.HasMoreThanOneOR = (ors + pps) > 1;

            //Manage approval link
            string actionType = null;

            if (!model.IsApproved)
            {
                actionType = NotificationHelper.approvalCode;
            }
            if (actionType != null)
            {
                model.CanApprove = notificationService.CanApprove(currentUser, NotificationHelper.poCode, actionType, model.Id);
            }
            else
            {
                model.CanApprove = false;
            }

            return(View("ViewPurchaseOrdersDetails", model));
        }
Exemple #6
0
 public ActionResult AddPPItemsToPO(Model.ProcurementPlan pp)
 {
     Model.PurchaseOrder       po = poService.GetPurchaseOrderById(pp.PurchaseOrderId);
     Model.PurchaseOrderItem   poItem;
     Model.ProcurementPlanItem item;
     if (po.TotalAmount == null)
     {
         po.TotalAmount = 0;
     }
     foreach (var ppItem in pp.PPItemList)
     {
         if (ppItem.AddedToOR)
         {
             item   = ppService.GetProcurementPlanItemById(ppItem.Id);
             poItem = new PurchaseOrderItem
             {
                 BudgetLineId          = item.BudgetLineId,
                 ProcurementPlanItemId = item.Id,
                 PurchaseOrderId       = po.Id,
                 Quantity   = ppItem.QuantityToOrder,
                 TotalPrice = ppItem.TotalCost,
                 UnitPrice  = (double)ppItem.UnitCost
             };
             po.TotalAmount += ppItem.TotalCost;
             poService.SavePOItem(poItem);
         }
     }
     poService.SaveReviewedPO(po);
     return(LoadPOItems(po.Id));
 }
Exemple #7
0
 private void ResetForm()
 {
     po = new PurchaseOrder();
     dgvItems.Rows.Clear();
     dgvItems.DataSource = null;
     dgvResults.Rows.Clear();
     dgvResults.DataSource = null;
     if (dgvResults.Columns.Contains("Items"))
     {
         dgvResults.Columns.Remove("Items");
     }
     grpItems.Enabled       = false;
     btnNotRequired.Enabled = false;
     lblPOStatus.Text       = "";
     lblReason.Visible      = false;
     txtReason.Visible      = false;
     txtEmployeeName.Text   = "";
     txtSupervisorName.Text = "";
     txtStatus.Text         = "";
     txtDepartment.Text     = "";
     txtPoNumber.Text       = "";
     txtCreationDate.Text   = "";
     txtSubtotal.Text       = "$0.00";
     txtTax.Text            = "$0.00";
     txtTotalAfterTax.Text  = "$0.00";
     //txtSearch.Text = string.Empty;
 }
Exemple #8
0
 public ActionResult AddItemsToPO(Model.PurchaseOrder model)
 {
     Model.PurchaseOrder     po = poService.GetPurchaseOrderById(model.Id);
     Model.PurchaseOrderItem poItem;
     if (po.TotalAmount == null)
     {
         po.TotalAmount = 0;
     }
     foreach (var orItem in model.ORItems)
     {
         if (orItem.AddToPO)
         {
             poItem = new PurchaseOrderItem
             {
                 BudgetLineId       = orItem.BudgetLineId,
                 OrderRequestItemId = orItem.Id,
                 PurchaseOrderId    = po.Id,
                 Quantity           = (int)orItem.Quantity,
                 Remarks            = orItem.Remarks,
                 TotalPrice         = orItem.EstimatedPrice,
                 UnitPrice          = (double)orItem.EstimatedUnitPrice
             };
             po.TotalAmount += orItem.EstimatedPrice;
             poService.SavePOItem(poItem);
         }
     }
     if (po.OrderRequest == null)
     {
         po.OrderRequestId = model.OrderRequestId;
     }
     poService.SaveReviewedPO(po);
     return(LoadPOItems(po.Id));
 }
Exemple #9
0
 public void BackDatePO(Model.PurchaseOrder po)
 {
     using (var context = new SCMSEntities())
     {
         using (TransactionScope scope = new TransactionScope())
         {
             try
             {
                 //Get Current OR from DB
                 var currentPO = context.PurchaseOrders.FirstOrDefault(o => o.Id == po.Id);
                 //Initialize BackDate object
                 var backDate = new DocumentBackDating();
                 backDate.Id              = Guid.NewGuid();
                 backDate.BackDatedBy     = po.BackDatedBy;
                 backDate.BackDatedOn     = DateTime.Now;
                 backDate.NewDate         = po.PODate;
                 backDate.PurchaseOrderId = po.Id;
                 backDate.PreviousDate    = currentPO.PODate;
                 backDate.Reason          = po.BackDatingReason;
                 //Insert BackDate details into db
                 context.DocumentBackDatings.Add(backDate);
                 //Update date on OR in db
                 currentPO.PODate = po.PODate;
                 context.SaveChanges();
                 scope.Complete();
             }
             catch (Exception ex)
             {
                 scope.Dispose();
                 throw ex;
             }
         }
     }
 }
Exemple #10
0
        public ActionResult LoadAddItems(Guid Id)
        {
            Model.PurchaseOrder model = poService.GetPurchaseOrderById(Id);
            //G Order Requests with unprocessed items
            List <Model.OrderRequest> orList = poService.GetOrderRequestsForPO(countryProg.Id);

            UserSession.CurrentSession.OrderRequestList = orList;

            var projectList = orList.OrderBy(o => o.ProjectDonor.Project.Name).Select(o => o.ProjectDonor.Project).Distinct().ToList();
            var pdList      = orList.Where(o => projectList != null && projectList.Count > 0 && o.ProjectDonor.ProjectId == projectList[0].Id).Select(o => o.ProjectDonor).Distinct().ToList();

            if (orList.Count > 0)
            {
                model.OrderRequest   = orList[0];
                model.OrderRequestId = orList[0].Id;
                model.OrderRequests  = new SelectList(orList.Where(o => o.ProjectDonorId == pdList[0].Id).ToList(), "Id", "RefNumber", orList[0].Id);
                model.Projects       = new SelectList(projectList, "Id", "Name");
                model.ProjectDonors  = new SelectList(pdList, "Id", "ProjectNumber");
                model.POItems        = model.PurchaseOrderItems.ToList();
                //model.ORItems = poService.GetUnprocessedORItems(orList[0].Id);
                model.ORItems = orList[0].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)orList[0].ProjectDonorId), "Id", "Description", orItem.BudgetLineId);
                }
                model.SameCurrency = model.Currency.Id.Equals(orList[0].Currency.Id);
            }
            return(View("AddPOItems", model));
        }
Exemple #11
0
        public TenderingType DetermineTenderingType(Model.PurchaseOrder po)
        {
            decimal poValue;

            foreach (var tt in SessionData.CurrentSession.TenderingTypeList)
            {
                if (tt.CurrencyId == po.CurrencyId)
                {
                    if (po.TotalAmount >= tt.MinValue && po.TotalAmount <= tt.MaxValue)
                    {
                        return(tt);
                    }
                    if (po.TotalAmount >= tt.MinValue && tt.MaxValue == 0)
                    {
                        return(tt);
                    }
                }
                else
                {
                    poValue = (decimal)exchangeRateService.GetForeignCurrencyValue(tt.CurrencyId, po.CurrencyId, po.TotalAmount.Value, po.CountryProgrammeId.Value);
                    if (poValue >= tt.MinValue && po.TotalAmount <= tt.MaxValue)
                    {
                        return(tt);
                    }
                    if (poValue >= tt.MinValue && tt.MaxValue == 0)
                    {
                        return(tt);
                    }
                }
            }
            return(null);
        }
Exemple #12
0
 public ActionResult LoadAttachDocs(Guid id)
 {
     Model.PurchaseOrder po = poService.GetPurchaseOrderById(id);
     return(View("LoadAttacheDocs", new AttachedDocument()
     {
         POEntity = poService.GetPurchaseOrderById(po.Id), DocList = poService.GetList(po.Id, countryProg.Id)
     }));
 }
Exemple #13
0
 public ICollection <PurchaseOrderItem> GetPurchaseOItems(string PORefNumber)
 {
     using (var context = new SCMSEntities())
     {
         Model.PurchaseOrder             po     = context.PurchaseOrders.SingleOrDefault(p => p.RefNumber == PORefNumber);
         ICollection <PurchaseOrderItem> poitem = po.PurchaseOrderItems;
         return(poitem);
     }
 }
Exemple #14
0
 public ActionResult EditPO(Guid Id)
 {
     Model.PurchaseOrder model = poService.GetPurchaseOrderById(Id);
     model.Currencies    = new SelectList(orService.GetCurrencies(), "Id", "ShortName", model.CurrencyId);
     model.Suppliers     = new SelectList(poService.GetSuppliers(), "Id", "Name", model.SupplierId);
     model.ShippingTerms = new SelectList(poService.GetShippingTerms(), "Id", "Description", model.ShippingTermId);
     model.Locations     = new SelectList(orService.GetLocations(), "Id", "Name", model.DeliveryAddress);
     model.PaymentTerms  = new SelectList(poService.GetPaymentTerms(), "Id", "Description", model.PaymentTermId);
     return(View("LoadPO", model));
 }
Exemple #15
0
 public ActionResult BackDatePO(Model.PurchaseOrder model)
 {
     if (model.PODate > DateTime.Today)
     {
         return(ViewPurchaseOrdersDetails(model.Id));
     }
     model.BackDatedBy = currentStaff.Id;
     poService.BackDatePO(model);
     return(ViewPurchaseOrdersDetails(model.Id));
 }
Exemple #16
0
 public bool SaveReviewedPO(Model.PurchaseOrder po)
 {
     using (var context = new SCMSEntities())
     {
         var pOrder = context.PurchaseOrders.FirstOrDefault(p => p.Id == po.Id);
         context.Entry(pOrder).CurrentValues.SetValues(po);
         ClearPOSessionData();
         ClearORSessionData();
         return(context.SaveChanges() > 0);
     }
 }
Exemple #17
0
        public decimal CalculateSubtotal(Model.PurchaseOrder po)
        {
            decimal subtotal = 0.0m;

            foreach (Item item in po.Items)
            {
                if (item.PurchaseOrderId != -1)
                {
                    subtotal += item.Price * item.Quantity;
                }
            }
            return(subtotal);
        }
        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);
            }
        }
Exemple #19
0
 public ActionResult SubmitPO(Model.AttachedDocument model)
 {
     Model.PurchaseOrder po = poService.GetPurchaseOrderById(model.POEntity.Id);
     po.PreparedOn  = DateTime.Now;
     po.PODate      = DateTime.Now;
     po.PreparedBy  = currentStaff.Id;
     po.IsSubmitted = true;
     po.IsApproved  = po.IsRejected = false;
     po.RefNumber   = poService.GenerateUniquNumber(countryProg);
     poService.SaveReviewedPO(po);
     //Send notification
     notificationService.SendToAppropriateApprover(NotificationHelper.poCode, NotificationHelper.approvalCode, po.Id);
     return(ViewPurchaseOrders());
 }
Exemple #20
0
        private bool IsValidEntity(Model.PurchaseOrder po)
        {
            po.Errors = new List <Error>();
            ValidationContext       context = new ValidationContext(po);
            List <ValidationResult> results = new List <ValidationResult>();

            bool isValid = Validator.TryValidateObject(po, context, results, true);

            foreach (ValidationResult r in results)
            {
                po.AddError(new Error(po.Errors.Count, r.ErrorMessage, "Model"));
            }

            return(isValid);
        }
Exemple #21
0
        public bool AuthorizePurchaseOrder(Model.PurchaseOrder po)
        {
            decimal?         amount;
            decimal?         currAmount;//Amount in ProjectBudget currency
            BudgetCommitment orCommit;

            using (var context = new SCMSEntities())
            {
                var poItems = context.PurchaseOrderItems.Where(p => p.PurchaseOrderId == po.Id).ToList();
                foreach (var poItem in poItems)
                {
                    amount = poItem.TotalPrice;
                    //Get PO Item amount in Budget Currency
                    currAmount = exchangeRateService.GetForeignCurrencyValue(poItem.ProjectBudget.BudgetCategory.ProjectDonor.Currency, poItem.PurchaseOrder.Currency, amount, (Guid)po.CountryProgrammeId);
                    orCommit   = new BudgetCommitment();
                    orCommit.AmountCommitted = 0;
                    //Get amount committed by OrderRequestItem
                    if (poItem.OrderRequestItem != null)
                    {
                        var commitmentList = poItem.OrderRequestItem.BudgetCommitments.ToList <BudgetCommitment>();
                        if (commitmentList.Count > 0)
                        {
                            //List should have exactly one item
                            foreach (var commitment in commitmentList)
                            {
                                orCommit = commitment;
                                break;
                            }
                            //Remove initial commitment by OR Item
                            poItem.OrderRequestItem.ProjectBudget.TotalCommitted -= orCommit.AmountCommitted;
                            context.BudgetCommitments.Remove(orCommit);
                        }
                    }
                    //Add commitment by PO Item
                    poItem.ProjectBudget.TotalCommitted += currAmount;

                    //Add to BudgetCommitment table
                    var budgetCommitment = new BudgetCommitment();
                    budgetCommitment.Id = Guid.NewGuid();
                    budgetCommitment.PurchaseOrderItemId = poItem.Id;
                    budgetCommitment.AmountCommitted     = (decimal)currAmount;
                    budgetCommitment.DateCommitted       = DateTime.Now;
                    budgetCommitment.BudgetLineId        = poItem.ProjectBudget.Id;
                    context.BudgetCommitments.Add(budgetCommitment);
                }
                return((context.SaveChanges() > 0) ? true : false);
            }
        }
Exemple #22
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));
        }
Exemple #23
0
        public string GenerateUniquNumber(CountryProgramme cp)
        {
            string code      = "PO/DRC/" + cp.Country.ShortName + "/";
            string refNumber = "";
            long   count     = 1;

            using (var dbContext = new SCMSEntities())
            {
                var total = dbContext.PurchaseOrders.Where(p => p.CountryProgrammeId == cp.Id && p.IsSubmitted == true).Count();
                //Model.PurchaseOrder m = dbContext.PurchaseOrders.OrderByDescending(p => p.RecordCount).FirstOrDefault();
                //if (m != null)
                //    count = m.RecordCount + 1;
                count = total;
                Model.PurchaseOrder 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 = dbContext.PurchaseOrders.FirstOrDefault(p => p.RefNumber == refNumber);
                } while (m != null);
                return(refNumber);
            }
        }
Exemple #24
0
        private bool IsValid(Model.PurchaseOrder po)
        {
            List <bool> validations = new List <bool>();

            validations.Add(IsValidEntity(po));
            foreach (Item item in po.Items)
            {
                if (item.Status == ItemStatus.NoLongerRequired)
                {
                    ItemStatus status = GetItemStatus(item.ItemId);
                    if (status != ItemStatus.Pending)
                    {
                        validations.Add(false);
                        po.AddError(new Error(111, "The item status cannot be changed, it has already been processed", "Business"));
                    }
                    else
                    {
                        item.Quantity    = 0;
                        item.Price       = 0;
                        item.Description = "No longer needed";
                        item.Status      = ItemStatus.Denied;
                    }
                }
            }

            if (po.PurchaseOrderId > 0)
            {
                PurchaseOrder poFromDatabase = GetPurchaseOrder(po.PurchaseOrderId);

                //if (po.IsProcess == false && poFromDatabase.Status == POStatus.UnderReview)
                //{
                //    validations.Add(false);
                //    po.Errors.Add(new Error(111, "This Purchase Order is currently under review and cannot be modified", "Business"));
                //}

                if (poFromDatabase.Status == POStatus.Closed)
                {
                    validations.Add(false);
                    po.Errors.Add(new Error(112, "This Purchase Order is closed and cannot be modified", "Business"));
                }
            }

            return(validations.Contains(false) ? false : true);
        }
Exemple #25
0
 private static String AuthName(SCMSEntities db, Model.PurchaseOrder POentity, String authourisation, Model.Staff s)
 {
     authourisation += "<tr><td class=\"gridheader\">Name:</td><td>";
     authourisation += s.Person.FirstName + " " + s.Person.OtherNames;
     authourisation += "</td><td>";
     //if ((bool)POentity.IsReviewed && POentity.ReviewedBy != null)
     //{
     //    Model.Staff r = db.Staffs.FirstOrDefault(p => p.Id == POentity.ReviewedBy);
     //    authourisation += r.Person.FirstName + " " + r.Person.OtherNames;
     //}
     authourisation += "</td><td>";
     if ((bool)POentity.IsApproved && POentity.ApprovedBy != null)
     {
         Model.Staff auth = db.Staffs.FirstOrDefault(p => p.Id == POentity.ApprovedBy);
         authourisation += auth.Person.FirstName + " " + auth.Person.OtherNames;
     }
     authourisation += "</td><tr>";
     return(authourisation);
 }
Exemple #26
0
 private static String AuthDate(SCMSEntities db, Model.PurchaseOrder POentity, String authourisation)
 {
     authourisation += "<tr><td class=\"gridheader\">Date:</td><td>";
     authourisation += POentity.PreparedOn.Value.ToString("dd/MM/yyyy h:mm tt");
     authourisation += "</td><td>";
     //if ((bool)POentity.IsReviewed && POentity.ReviewedBy != null)
     //{
     //    Model.Staff r = db.Staffs.FirstOrDefault(p => p.Id == POentity.ReviewedBy);
     //    authourisation += POentity.ReviewedOn.Value.ToString("dd/MM/yyyy h:mm tt");
     //}
     authourisation += "</td><td>";
     if ((bool)POentity.IsApproved && POentity.ApprovedBy != null)
     {
         Model.Staff auth = db.Staffs.FirstOrDefault(p => p.Id == POentity.ApprovedBy);
         authourisation += POentity.ApprovedOn.Value.ToString(Constants.DATETIME_FORMAT);
     }
     authourisation += "</td><tr>";
     return(authourisation);
 }
Exemple #27
0
        private void dgvResults_SelectionChanged(object sender, EventArgs e)
        {
            if (dgvResults.CurrentRow != null)
            {
                po = service.GetPurchaseOrder(Convert.ToInt32(dgvResults.CurrentRow.Cells["PurchaseOrderId"].Value));
                // Set fields
                txtPONumber.Text   = po.PurchaseOrderId.ToString();
                txtPODate.Text     = po.CreationDate.ToString("yyyy-MM-dd");
                txtPOStatus.Text   = po.Status.ToString();
                txtPOEmployee.Text = service.GetEmployeeName(po.EmployeeId).EmployeeName;
                txtSubtotal.Text   = po.Subtotal.ToString("c2");
                txtTax.Text        = po.Tax.ToString("c2");
                txtTotal.Text      = po.TotalAfterTax.ToString("c2");
                BindingList <Item> items = new BindingList <Item>(po.Items);
                foreach (Item item in items.ToList())
                {
                    item.subtotal = item.Quantity * item.Price;
                }
                dgvItems.DataSource = items;
                dgvItems.Columns["DisplayStatus"].Visible            = false;
                dgvItems.Columns["ItemId"].Visible                   = false;
                dgvItems.Columns["subtotal"].HeaderText              = "Subtotal";
                dgvItems.Columns["PurchaseOrderId"].HeaderText       = "PO Number";
                dgvItems.Columns["Price"].DefaultCellStyle.Format    = "C";
                dgvItems.Columns["subtotal"].DefaultCellStyle.Format = "c2";

                bool showButtonToClose = true;
                if (po.Status == POStatus.Closed)
                {
                    showButtonToClose = false;
                }
                foreach (Item i in po.Items.ToList())
                {
                    if (i.Status != ItemStatus.Approved && i.Status != ItemStatus.Denied)
                    {
                        showButtonToClose = false;
                    }
                }

                btnClosePo.Visible = showButtonToClose ? true : false;
            }
        }
Exemple #28
0
 public ActionResult SavePO(Model.PurchaseOrder model)
 {
     if (model.Id.Equals(Guid.Empty))
     {
         model.TotalAmount        = 0;
         model.CountryProgrammeId = countryProg.Id;
         model.PreparedBy         = currentStaff.Id;
         model.PreparedOn         = DateTime.Now;
     }
     poService.SavePuchaseOrder(model);
     //Check if PO prepare was initiated from OR
     if (UserSession.CurrentSession.NewOR != null)
     {
         //Add OR items to PO
         poService.AddPOItemsFromOR(UserSession.CurrentSession.NewOR, model.Id);
         //Clear OR Session
         UserSession.CurrentSession.NewOR = null;
     }
     return(LoadPOItems(model.Id));
 }
Exemple #29
0
        public ActionResult LoadPOItems(Guid Id, List <BudgetCheckResult> brcList = null)
        {
            Model.PurchaseOrder model = poService.GetPurchaseOrderById(Id);
            model.ORList             = poService.GetPOrderORs(Id);
            model.PPList             = poService.GetPOrderPPs(Id);
            model.BudgetCheckResults = brcList;

            foreach (var or in model.ORList)
            {
                or.POItems = poService.GetPOItemsByOrId(model.Id, or.Id);
            }

            foreach (var pp in model.PPList)
            {
                pp.POItems = poService.GetPOItemsByPPId(model.Id, pp.Id);
            }

            ViewBag.PORefNumber = model.RefNumber;
            return(View("LoadPOItems", model));
        }
Exemple #30
0
        private string POStatus(Model.PurchaseOrder po, out DateTime statusDate)
        {
            string poStatus;

            if (po.IsApproved)
            {
                poStatus = Resources.Global_String_StatusAP;
            }
            else if (po.IsRejected)
            {
                poStatus = Resources.Global_String_StatusRJ;
            }
            else if (po.IsSubmitted == true)
            {
                poStatus = Resources.Global_String_StatusCR;
            }
            else
            {
                poStatus = Resources.Global_String_StatusNEW;
            }

            //Get OR Status date
            if (po.IsApproved == true)
            {
                statusDate = po.ApprovedOn.Value;
            }
            else if (po.IsRejected == true && po.ApprovedOn.HasValue)
            {
                statusDate = po.ApprovedOn.Value;
            }
            else if (po.IsSubmitted == true)
            {
                statusDate = po.PreparedOn.Value;
            }
            else
            {
                statusDate = po.PreparedOn.Value;
            }

            return(poStatus);
        }