public bool DeleteGiftCertificate(GiftCertificate giftCertificate) { if (giftCertificate == null) return false; _unitOfWork.GiftCertificateRepository.Delete(giftCertificate); _unitOfWork.Save(); return true; }
public ActionResult Edit(GiftCertificateViewModel giftcertificate) { //just incase the user meses with the the hidden GiftCertificateID field Cats.Models.Hubs.GiftCertificate giftcert = _giftCertificateService.FindById(giftcertificate.GiftCertificateID); if (ModelState.IsValid && giftcert != null) { Cats.Models.Hubs.GiftCertificate giftCertificateModel = giftcertificate.GenerateGiftCertificate(); List <Cats.Models.Hubs.GiftCertificateDetailsViewModel> insertCommodities = GetSelectedGiftCertificateDetails(giftcertificate.JSONInsertedGiftCertificateDetails); List <Cats.Models.Hubs.GiftCertificateDetailsViewModel> deletedCommodities = GetSelectedGiftCertificateDetails(giftcertificate.JSONDeletedGiftCertificateDetails); List <Cats.Models.Hubs.GiftCertificateDetailsViewModel> updateCommodities = GetSelectedGiftCertificateDetails(giftcertificate.JSONUpdatedGiftCertificateDetails); _giftCertificateService.Update(giftCertificateModel, GenerateGiftCertificate(insertCommodities), GenerateGiftCertificate(updateCommodities), GenerateGiftCertificate(deletedCommodities)); return(RedirectToAction("Index")); } ViewBag.Commodities = _commodityService.GetAllCommodity().OrderBy(o => o.Name); ViewBag.DCurrencies = _detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.CURRENCY).OrderBy(o => o.SortOrder); ViewBag.DFundSources = _detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.FUND_SOURCE).OrderBy(o => o.SortOrder); ViewBag.DBudgetTypes = _detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.BUDGET_TYPE).OrderBy(o => o.SortOrder); ViewBag.CommodityTypes = new SelectList(_commodityTypeService.GetAllCommodityType().OrderBy(o => o.Name), "CommodityTypeID", "Name", giftcert.GiftCertificateDetails.FirstOrDefault().Commodity.CommodityTypeID); ViewBag.Donors = new SelectList(_donorService.GetAllDonor().OrderBy(o => o.Name), "DonorID", "Name", giftcertificate.DonorID); ViewBag.Programs = new SelectList(_programService.GetAllProgram(), "ProgramID", "Name", giftcertificate.ProgramID); ViewBag.DModeOfTransports = new SelectList(_detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.TRANSPORT_MODE).OrderBy(o => o.SortOrder), "DetailID", "Name", giftcertificate.DModeOfTransport); return(View(giftcertificate)); }
/// <summary> /// Gifts the certificate model. /// </summary> /// <param name="GiftCertificateModel">The gift certificate model.</param> /// <returns></returns> public static GiftCertificateViewModel GiftCertificateModel(GiftCertificate GiftCertificateModel) { GiftCertificateViewModel giftCertificateViewModel = new GiftCertificateViewModel(); giftCertificateViewModel.GiftCertificateID = GiftCertificateModel.GiftCertificateID; giftCertificateViewModel.GiftDate = GiftCertificateModel.GiftDate; giftCertificateViewModel.DonorID = GiftCertificateModel.DonorID; giftCertificateViewModel.ShippingInstructionID = GiftCertificateModel.ShippingInstructionID; giftCertificateViewModel.ReferenceNo = GiftCertificateModel.ReferenceNo; giftCertificateViewModel.Vessel = GiftCertificateModel.Vessel; giftCertificateViewModel.ETA = GiftCertificateModel.ETA; giftCertificateViewModel.ProgramID = GiftCertificateModel.ProgramID; giftCertificateViewModel.PortName = GiftCertificateModel.PortName; giftCertificateViewModel.DModeOfTransport = GiftCertificateModel.DModeOfTransport; var giftCertificateDetail = GiftCertificateModel.GiftCertificateDetails.FirstOrDefault(); if (giftCertificateDetail != null) { giftCertificateViewModel.CommodityTypeID = giftCertificateDetail.Commodity.CommodityTypeID; } else { giftCertificateViewModel.CommodityTypeID = 1;//by default 'food' } giftCertificateViewModel.GiftCertificateDetails = GiftCertificateDetailsViewModel.GenerateListOfGiftCertificateDetailsViewModel( GiftCertificateModel.GiftCertificateDetails.ToList()); return(giftCertificateViewModel); }
public ActionResult Edit(int id) { Cats.Models.Hubs.GiftCertificate giftcertificate = _giftCertificateService.Get(t => t.GiftCertificateID == id, null, "GiftCertificateDetails,GiftCertificateDetails.Commodity").FirstOrDefault(); ViewBag.Commodities = _commodityService.GetAllCommodity().OrderBy(o => o.Name); ViewBag.DCurrencies = _detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.CURRENCY).OrderBy(o => o.SortOrder); ViewBag.DFundSources = _detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.FUND_SOURCE).OrderBy(o => o.SortOrder); ViewBag.DBudgetTypes = _detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.BUDGET_TYPE).OrderBy(o => o.SortOrder); var giftCertificateDetails = giftcertificate.GiftCertificateDetails.FirstOrDefault(); ViewBag.CommodityTypes = new SelectList(_commodityTypeService.GetAllCommodityType().OrderBy(o => o.Name), "CommodityTypeID", "Name", giftCertificateDetails == null?string.Empty:giftCertificateDetails.Commodity.CommodityTypeID.ToString()); ViewBag.Donors = new SelectList(_donorService.GetAllDonor().OrderBy(o => o.Name), "DonorID", "Name", giftcertificate.DonorID); ViewBag.Programs = new SelectList(_programService.GetAllProgram(), "ProgramID", "Name"); ViewBag.DModeOfTransports = new SelectList(_detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.TRANSPORT_MODE).OrderBy(o => o.SortOrder), "DetailID", "Name"); return(View(GiftCertificateViewModel.GiftCertificateModel(giftcertificate))); }
public void CanCreateNewGiftcertificate() { var giftcertificate=new GiftCertificate { GiftCertificateID = 1, GiftDate = new DateTime(12/12/2013), DonorID = 2, SINumber = "12121", ReferenceNo = "45461212", Vessel = "MAERSK UTAH", ETA = new DateTime(11/11/2012), IsPrinted = false, ProgramID = 1, DModeOfTransport = 14, PortName = "Djibouti" }; // var result = _giftCertificateController.Create(giftcertificate); }
/// <summary> /// Generates the gift certificate. /// </summary> /// <returns></returns> public GiftCertificate GenerateGiftCertificate() { GiftCertificate giftCertificate = new GiftCertificate() { GiftCertificateID = this.GiftCertificateID, GiftDate = this.GiftDate, ShippingInstructionID = this.ShippingInstructionID, DonorID = this.DonorID, ReferenceNo = this.ReferenceNo, Vessel = this.Vessel, ETA = this.ETA, IsPrinted = this.IsPrinted, DModeOfTransport = this.DModeOfTransport, ProgramID = this.ProgramID, PortName = this.PortName }; return(giftCertificate); }
public virtual ActionResult NotUnique(string SINumber, int GiftCertificateID) { var shippingInstruction = _shippingInstructionService.FindBy(t => t.Value == SINumber).FirstOrDefault(); var gift = new Cats.Models.Hubs.GiftCertificate(); if (shippingInstruction != null) { gift = _giftCertificateService.FindBySINumber(shippingInstruction.ShippingInstructionID); } UserProfile user = _userProfileService.GetUser(User.Identity.Name); bool inReceiptAllocation = _receiptAllocationService.FindBySINumber(SINumber).Any(p => p.CommoditySourceID == CommoditySource.Constants.LOCALPURCHASE); if ((gift == null || (gift.GiftCertificateID == GiftCertificateID)) && !(inReceiptAllocation))// new one or edit no problem { return(Json(true, JsonRequestBehavior.AllowGet)); } else { return(Json(string.Format("{0} is invalid, there is an existing record with the same SI Number ", SINumber), JsonRequestBehavior.AllowGet)); } }
public ActionResult Create(Cats.Models.Hubs.GiftCertificateViewModel giftcertificate) { if (ModelState.IsValid) { Cats.Models.Hubs.GiftCertificate giftCertificateModel = giftcertificate.GenerateGiftCertificate(); InsertGiftCertificate(giftcertificate, giftCertificateModel); //repository.Add( giftCertificate ); return(RedirectToAction("Index")); } ViewBag.Commodities = _commodityService.GetAllCommodity().OrderBy(o => o.Name); ViewBag.CommodityTypes = _commodityTypeService.GetAllCommodityType().OrderBy(o => o.Name); ViewBag.DCurrencies = _detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.CURRENCY).OrderBy(o => o.SortOrder); ViewBag.DFundSources = _detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.FUND_SOURCE).OrderBy(o => o.SortOrder); ViewBag.DBudgetTypes = _detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.BUDGET_TYPE).OrderBy(o => o.SortOrder); ViewBag.Donors = new SelectList(_donorService.GetAllDonor().OrderBy(o => o.Name), "DonorID", "Name"); ViewBag.Programs = new SelectList(_programService.GetAllProgram(), "ProgramID", "Name"); ViewBag.DModeOfTransports = new SelectList(_detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.TRANSPORT_MODE).OrderBy(o => o.SortOrder), "DetailID", "Name"); //return the model with the values pre-populated return(Create()); //GiftCertificateViewModel.GiftCertificateModel(giftcertificate)); }
private string PopulateCertificate(string templateString, GiftCertificate cert) { templateString = SearchAndReplace(CertificateFields.DONOR, GetValue(CertificateFields.DONOR, cert), templateString); templateString = SearchAndReplace(CertificateFields.ETA, GetValue(CertificateFields.ETA, cert), templateString); templateString = SearchAndReplace(CertificateFields.GIFTDATE, GetValue(CertificateFields.GIFTDATE, cert), templateString); templateString = SearchAndReplace(CertificateFields.REFERENCENO, GetValue(CertificateFields.REFERENCENO, cert), templateString); templateString = SearchAndReplace(CertificateFields.SINUMBER, GetValue(CertificateFields.SINUMBER, cert), templateString); templateString = SearchAndReplace(CertificateFields.VESSEL, GetValue(CertificateFields.VESSEL, cert), templateString); return templateString; }
/// <summary> /// Updates the specified gift certificate model. /// </summary> /// <param name="giftCertificateModel">The gift certificate model.</param> /// <param name="inserted">The inserted gift certificate detail.</param> /// <param name="updated">The updated gift certificate detail.</param> /// <param name="deleted">The deleted gift certificate detail.</param> public void Update(GiftCertificate giftCertificateModel, List<GiftCertificateDetail> inserted, List<GiftCertificateDetail> updated, List<GiftCertificateDetail> deleted) { // DRMFSSEntities1 db = new DRMFSSEntities1(); GiftCertificate orginal = _unitOfWork.GiftCertificateRepository.Get(p => p.GiftCertificateID == giftCertificateModel.GiftCertificateID).SingleOrDefault(); if (orginal != null) { orginal.GiftDate = giftCertificateModel.GiftDate; orginal.DonorID = giftCertificateModel.DonorID; orginal.ShippingInstructionID = giftCertificateModel.ShippingInstructionID; orginal.ReferenceNo = giftCertificateModel.ReferenceNo; orginal.Vessel = giftCertificateModel.Vessel; orginal.ETA = giftCertificateModel.ETA; orginal.ProgramID = giftCertificateModel.ProgramID; orginal.PortName = giftCertificateModel.PortName; orginal.DModeOfTransport = giftCertificateModel.DModeOfTransport; foreach (GiftCertificateDetail insert in inserted) { orginal.GiftCertificateDetails.Add(insert); } foreach (GiftCertificateDetail delete in deleted) { GiftCertificateDetail deletedGiftDetails = _unitOfWork.GiftCertificateDetailRepository.FindBy(p => p.GiftCertificateDetailID == delete.GiftCertificateDetailID).SingleOrDefault(); if (deletedGiftDetails != null) { _unitOfWork.GiftCertificateDetailRepository.Delete(deletedGiftDetails); } } foreach (GiftCertificateDetail update in updated) { GiftCertificateDetail updatedGiftDetails = _unitOfWork.GiftCertificateDetailRepository.Get(p => p.GiftCertificateDetailID == update.GiftCertificateDetailID).SingleOrDefault(); if (updatedGiftDetails != null) { updatedGiftDetails.CommodityID = update.CommodityID; updatedGiftDetails.BillOfLoading = update.BillOfLoading; updatedGiftDetails.YearPurchased = update.YearPurchased; updatedGiftDetails.AccountNumber = update.AccountNumber; updatedGiftDetails.WeightInMT = update.WeightInMT; updatedGiftDetails.EstimatedPrice = update.EstimatedPrice; updatedGiftDetails.EstimatedTax = update.EstimatedTax; updatedGiftDetails.DCurrencyID = update.DCurrencyID; updatedGiftDetails.DFundSourceID = update.DFundSourceID; updatedGiftDetails.DBudgetTypeID = update.DBudgetTypeID; updatedGiftDetails.ExpiryDate = update.ExpiryDate; } } _unitOfWork.Save(); } }
private void InsertGiftCertificate(Cats.Models.Hubs.GiftCertificateViewModel giftcertificate, Cats.Models.Hubs.GiftCertificate giftCertificateModel) { List <Cats.Models.Hubs.GiftCertificateDetailsViewModel> giftCertificateDetails = GetSelectedGiftCertificateDetails(giftcertificate.JSONInsertedGiftCertificateDetails); var giftDetails = GenerateGiftCertificate(giftCertificateDetails); foreach (GiftCertificateDetail giftDetail in giftDetails) { giftCertificateModel.GiftCertificateDetails.Add(giftDetail); } _giftCertificateService.AddGiftCertificate(giftCertificateModel); }
private void InsertGiftCertificate(Cats.Models.Hubs.GiftCertificateViewModel giftcertificate, GiftCertificate giftCertificateModel) { List<Cats.Models.Hubs.GiftCertificateDetailsViewModel> giftCertificateDetails = GetSelectedGiftCertificateDetails(giftcertificate.JSONInsertedGiftCertificateDetails); var giftDetails = GenerateGiftCertificate(giftCertificateDetails); foreach (GiftCertificateDetail giftDetail in giftDetails) { giftCertificateModel.GiftCertificateDetails.Add(giftDetail); } _giftCertificateService.AddGiftCertificate(giftCertificateModel); }
/// <summary> /// Generates the gift certificate. /// </summary> /// <returns></returns> public GiftCertificate GenerateGiftCertificate() { GiftCertificate giftCertificate = new GiftCertificate() { GiftCertificateID = this.GiftCertificateID, GiftDate = this.GiftDate, ShippingInstructionID = this.ShippingInstructionID, DonorID = this.DonorID, ReferenceNo = this.ReferenceNo, Vessel = this.Vessel, ETA = this.ETA, IsPrinted = this.IsPrinted, DModeOfTransport = this.DModeOfTransport, ProgramID = this.ProgramID, PortName = this.PortName }; return giftCertificate; }
public ActionResult SIMustBeInGift(string SINUmber, int? CommoditySourceID) { if (CommoditySourceID.HasValue && CommoditySourceID.Value ==CommoditySource.Constants.DONATION) { var shippingInstruction = _shippingInstructionService.FindBy(t => t.Value == SINUmber).FirstOrDefault(); var mustBeInGift = new Cats.Models.Hubs.GiftCertificate(); if(shippingInstruction!=null) mustBeInGift = _giftCertificateService.FindBySINumber(shippingInstruction.ShippingInstructionID); return Json((mustBeInGift != null), JsonRequestBehavior.AllowGet); } return Json(true, JsonRequestBehavior.AllowGet); }
public ActionResult SINotUnique(string SINUmber, int CommoditySourceID) { var shippingInstruction = _shippingInstructionService.FindBy(t => t.Value == SINUmber).FirstOrDefault(); var fromGc = new GiftCertificate(); if(shippingInstruction!=null) //check allocation and gc for the same record fromGc = _giftCertificateService.FindBySINumber(shippingInstruction.ShippingInstructionID); var fromRall = _receiptAllocationService.FindBySINumber(SINUmber).FirstOrDefault( p => p.CommoditySourceID == CommoditySource.Constants.DONATION); if (CommoditySourceID == CommoditySource.Constants.LOCALPURCHASE) { return Json ((fromGc == null) && (fromRall == null), JsonRequestBehavior.AllowGet); } //just incase the user is bad var fromRallt = _receiptAllocationService.FindBySINumber(SINUmber).FirstOrDefault( p => p.CommoditySourceID == CommoditySource.Constants.LOCALPURCHASE); if (CommoditySourceID == CommoditySource.Constants.DONATION) { return Json ((fromRallt == null), JsonRequestBehavior.AllowGet); } return Json(true, JsonRequestBehavior.AllowGet); }
//, int? hubID) public ActionResult GetBalance(string siNumber, int? commodityId) { if (siNumber != null) // && commodityId.HasValue) { UserProfile user = _userProfileService.GetUser(User.Identity.Name); decimal GCbalance = 0; decimal allocateBalance = 0; string commodity = ""; var shippingInstruction = _shippingInstructionService.FindBy(t => t.Value == siNumber).FirstOrDefault(); var GC = new Cats.Models.Hubs.GiftCertificate(); if(shippingInstruction!=null) GC = _giftCertificateService.FindBySINumber(shippingInstruction.ShippingInstructionID); if (GC != null && shippingInstruction!=null) { foreach (var GCD in GC.GiftCertificateDetails) { GCbalance = GCbalance + GCD.WeightInMT; commodity = GCD.Commodity.Name; } allocateBalance = _receiptAllocationService.GetBalanceForSI(shippingInstruction.Value); //, commodityId.Value); } //else //{ // GCbalance = 1; // allocateBalance = 0; // //balance = 1; //} decimal balance = GCbalance - allocateBalance; //TODO: make sure this function works for multi row gift certificate details. return Json(new {commodity, total = GCbalance, balance = balance}, JsonRequestBehavior.AllowGet); } return new EmptyResult(); }
private string GetValue(string key, GiftCertificate certificate) { if (!string.IsNullOrEmpty(key) && certificate != null) { switch (key.ToUpper()) { case CertificateFields.DONOR: return certificate.Donor.Name; case CertificateFields.ETA: return certificate.ETA.ToShortDateString(); case CertificateFields.GIFTDATE: return certificate.GiftDate.ToShortDateString(); case CertificateFields.REFERENCENO: return certificate.ReferenceNo; case CertificateFields.SINUMBER: return certificate.ShippingInstruction.Value; case CertificateFields.VESSEL: return certificate.Vessel; } } return string.Empty; }
public ActionResult Edit(String allocationId) { var receiptAllocation = _receiptAllocationService.FindById(Guid.Parse(allocationId)); UserProfile user = _userProfileService.GetUser(User.Identity.Name); var receiptAllocationViewModel =BindReceiptAllocaitonViewModel(); if (receiptAllocation != null) // && receiptAllocation.IsCommited == false) { receiptAllocationViewModel.IsCommited = receiptAllocation.IsCommited; receiptAllocationViewModel.ReceiptAllocationID = receiptAllocation.ReceiptAllocationID; receiptAllocationViewModel.PartitionID = receiptAllocation.PartitionID; receiptAllocationViewModel.ProjectNumber = receiptAllocation.ProjectNumber; receiptAllocationViewModel.CommodityID = receiptAllocation.CommodityID; //LOAD THE respective type and //TODO remove the other Types receiptAllocationViewModel.CommodityTypeID = receiptAllocation.Commodity.CommodityTypeID; receiptAllocationViewModel.SINumber = receiptAllocation.SINumber; receiptAllocationViewModel.QuantityInMT = receiptAllocation.QuantityInMT; if (receiptAllocation.QuantityInUnit == null) receiptAllocationViewModel.QuantityInUnit = 0; else receiptAllocationViewModel.QuantityInUnit = receiptAllocation.QuantityInUnit.Value; receiptAllocationViewModel.HubID = receiptAllocation.HubID; receiptAllocationViewModel.ETA = receiptAllocation.ETA; receiptAllocationViewModel.DonorID = receiptAllocation.DonorID; receiptAllocationViewModel.GiftCertificateDetailID = receiptAllocation.GiftCertificateDetailID; receiptAllocationViewModel.ReceiptAllocationID = receiptAllocation.ReceiptAllocationID; receiptAllocationViewModel.ProgramID = receiptAllocation.ProgramID; receiptAllocationViewModel.CommoditySourceID = receiptAllocation.CommoditySourceID; receiptAllocationViewModel.SourceHubID = receiptAllocation.SourceHubID; receiptAllocationViewModel.PurchaseOrder = receiptAllocation.PurchaseOrder; receiptAllocationViewModel.SupplierName = receiptAllocation.SupplierName; receiptAllocationViewModel.OtherDocumentationRef = receiptAllocation.OtherDocumentationRef; receiptAllocationViewModel.Remark = receiptAllocation.Remark; var shippingInstruction = _shippingInstructionService.FindBy(t => t.Value == receiptAllocationViewModel.SINumber). FirstOrDefault(); var GC = new Cats.Models.Hubs.GiftCertificate(); if(shippingInstruction!=null) GC = _giftCertificateService.FindBySINumber(shippingInstruction.ShippingInstructionID); if (GC != null && receiptAllocation.CommoditySourceID ==CommoditySource.Constants.DONATION) { receiptAllocationViewModel.Commodities.Clear(); receiptAllocationViewModel.Donors.Clear(); receiptAllocationViewModel.Programs.Clear(); foreach (GiftCertificateDetail giftCertificateDetail in GC.GiftCertificateDetails) { receiptAllocationViewModel.Commodities.Add(giftCertificateDetail.Commodity); } //Commodity commodity = receiptAllocationViewModel.Commodities.FirstOrDefault(); //if (commodity != null) receiptAllocationViewModel.CommodityID = commodity.CommodityID; receiptAllocationViewModel.Donors.Add(GC.Donor); receiptAllocationViewModel.DonorID = GC.DonorID; receiptAllocationViewModel.Programs.Add(GC.Program); receiptAllocationViewModel.ProgramID = GC.ProgramID; receiptAllocationViewModel.CommoditySources.Clear(); receiptAllocationViewModel.CommoditySources.Add( _commoditySourceService.FindById(CommoditySource.Constants.DONATION)); receiptAllocationViewModel.CommoditySourceID =CommoditySource.Constants.DONATION; } //else //{ int sourceType = receiptAllocation.CommoditySourceID; if (CommoditySource.Constants.DONATION == sourceType) { receiptAllocationViewModel.CommoditySources.Clear(); receiptAllocationViewModel.CommoditySources.Add( _commoditySourceService.FindById(CommoditySource.Constants.DONATION)); } //else if (CommoditySource.Constants.TRANSFER == sourceType) //{ // receiptAllocationViewModel.CommoditySources.Clear(); // receiptAllocationViewModel.CommoditySources.Add( // _commoditySourceService.FindById(CommoditySource.Constants.TRANSFER)); //} else if (CommoditySource.Constants.LOCALPURCHASE == sourceType) { receiptAllocationViewModel.CommoditySources.Clear(); receiptAllocationViewModel.CommoditySources.Add( _commoditySourceService.FindById(CommoditySource.Constants.LOCALPURCHASE)); } else if (CommoditySource.Constants.TRANSFER == sourceType || CommoditySource.Constants.REPAYMENT == sourceType || CommoditySource.Constants.LOAN == sourceType || CommoditySource.Constants.SWAP == sourceType) { receiptAllocationViewModel.CommoditySources.Clear(); receiptAllocationViewModel.CommoditySources.Add( _commoditySourceService.FindById(CommoditySource.Constants.REPAYMENT)); receiptAllocationViewModel.CommoditySources.Add( _commoditySourceService.FindById(CommoditySource.Constants.LOAN)); receiptAllocationViewModel.CommoditySources.Add( _commoditySourceService.FindById(CommoditySource.Constants.SWAP)); receiptAllocationViewModel.CommoditySources.Add( _commoditySourceService.FindById(CommoditySource.Constants.TRANSFER)); } // } } ViewBag.CommoditySourceType = receiptAllocation != null ? receiptAllocation.CommoditySourceID :CommoditySource.Constants.DONATION; if (receiptAllocation != null && receiptAllocation.Receives.Any()) ViewBag.receiveUnderAllocation = true; return PartialView("Edit", receiptAllocationViewModel); }
public ActionResult Create(ReceiptAllocationViewModel receiptAllocationViewModel) { if (receiptAllocationViewModel.CommoditySourceID ==CommoditySource.Constants.DONATION) { ModelState.Remove("SourceHubID"); ModelState.Remove("SupplierName"); ModelState.Remove("PurchaseOrder"); } else if (receiptAllocationViewModel.CommoditySourceID ==CommoditySource.Constants.LOCALPURCHASE) { ModelState.Remove("DonorID"); ModelState.Remove("SourceHubID"); } else { ModelState.Remove("DonorID"); ModelState.Remove("SupplierName"); ModelState.Remove("PurchaseOrder"); } if (!(IsSIValid(receiptAllocationViewModel.SINumber, receiptAllocationViewModel.CommoditySourceID))) { ModelState.AddModelError("SINumber", ""); } if (ModelState.IsValid) { ReceiptAllocation receiptAllocation = receiptAllocationViewModel.GenerateReceiptAllocation(); //for creation make the giftCetificate null if it's from if (receiptAllocationViewModel.GiftCertificateDetailID == 0 || receiptAllocationViewModel.GiftCertificateDetailID == null ) { var shippingInstruction = _shippingInstructionService.FindBy(t => t.Value == receiptAllocationViewModel.SINumber). FirstOrDefault(); var GC = new Cats.Models.Hubs.GiftCertificate(); if(shippingInstruction!=null) GC = _giftCertificateService.FindBySINumber(shippingInstruction.ShippingInstructionID); if (GC != null) { var GCD = GC.GiftCertificateDetails.FirstOrDefault( p => p.CommodityID == receiptAllocationViewModel.CommodityID); if (GCD != null) //&& GCD.GiftCertificateDetailID; { receiptAllocation.GiftCertificateDetailID = GCD.GiftCertificateDetailID; } } else { receiptAllocation.GiftCertificateDetailID = null; } } int typeOfGridToReload = receiptAllocation.CommoditySourceID; int commType = _commodityService.FindById(receiptAllocation.CommodityID).CommodityTypeID; //override to default hub UserProfile user = _userProfileService.GetUser(User.Identity.Name); receiptAllocation.HubID = user.DefaultHub.HubID; if (typeOfGridToReload != Cats.Models.Hubs.CommoditySource.Constants.DONATION && typeOfGridToReload != Cats.Models.Hubs.CommoditySource.Constants.LOCALPURCHASE) { typeOfGridToReload = Cats.Models.Hubs.CommoditySource.Constants.LOAN; } receiptAllocation.ReceiptAllocationID = Guid.NewGuid(); _receiptAllocationService.AddReceiptAllocation(receiptAllocation); return Json(new {gridId = typeOfGridToReload, CommodityTypeID = commType}, JsonRequestBehavior.AllowGet); //return RedirectToAction("Index"); } //check this out later //return this.Create(receiptAllocationViewModel.CommoditySourceID); //ModelState.Remove("SINumber"); //TODO:Check if commenting out has any effect //================================================= //receiptAllocationViewModel.InitalizeViewModel(); //================================================ return PartialView(receiptAllocationViewModel); }
public virtual ActionResult NotUnique(string SINumber, int GiftCertificateID) { var shippingInstruction = _shippingInstructionService.FindBy(t => t.Value == SINumber).FirstOrDefault(); var gift = new Cats.Models.Hubs.GiftCertificate(); if(shippingInstruction!=null) gift = _giftCertificateService.FindBySINumber(shippingInstruction.ShippingInstructionID); UserProfile user = _userProfileService.GetUser(User.Identity.Name); bool inReceiptAllocation = _receiptAllocationService.FindBySINumber(SINumber).Any(p => p.CommoditySourceID == CommoditySource.Constants.LOCALPURCHASE); if ((gift == null || (gift.GiftCertificateID == GiftCertificateID)) && !(inReceiptAllocation))// new one or edit no problem { return Json(true, JsonRequestBehavior.AllowGet); } else { return Json(string.Format("{0} is invalid, there is an existing record with the same SI Number ", SINumber), JsonRequestBehavior.AllowGet); } }
public ActionResult Delete(int id) { Cats.Models.Hubs.GiftCertificate giftcertificate = _giftCertificateService.FindById(id); return(View(giftcertificate)); }
private bool IsSIValid(string SINumber, int CommoditySourceID) { //check allocation and gc for the same record var shippingInstruction = _shippingInstructionService.FindBy(t => t.Value == SINumber).FirstOrDefault(); var fromGc = new Cats.Models.Hubs.GiftCertificate(); if(shippingInstruction!=null) fromGc = _giftCertificateService.FindBySINumber(shippingInstruction.ShippingInstructionID); bool fromRall = _receiptAllocationService.IsSINSource(CommoditySource.Constants.DONATION, SINumber); if (CommoditySourceID ==CommoditySource.Constants.LOCALPURCHASE) { if (!((fromGc == null) && !(fromRall))) { return false; } } //just incase the user is bad bool fromRallt = _receiptAllocationService.IsSINSource(CommoditySource.Constants.LOCALPURCHASE, SINumber); if (CommoditySourceID ==CommoditySource.Constants.DONATION) { //var mustBeInGift = _giftCertificateService.FindBySINumber(SINumber); if (fromRallt) { //) && (mustBeInGift != null))) return false; } } return true; }
// // GET: /Receive/Create public virtual ActionResult Create(string receiveId) { UserProfile user = _userProfileService.GetUser(User.Identity.Name); var commodities = _commodityService.GetAllCommodity().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var commodityGrades = _commodityGradeService.GetAllCommodityGrade().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var transporters = _transporterService.GetAllTransporter().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var commoditySources = _commoditySourceService.GetAllCommoditySource().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var commodityTypes = _commodityTypeService.GetAllCommodityType().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var programs = _programService.GetAllProgram().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var donors = _donorService.GetAllDonor().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var units = _unitService.GetAllUnit().OrderBy(o => o.Name).ToList(); var hubs = _hubService.GetAllWithoutId(user.DefaultHub.HubID).DefaultIfEmpty().OrderBy(o => o.Name).ToList(); if (receiveId != "" && receiveId != null) { Receive receive = _receiveService.FindById(Guid.Parse(receiveId)); var stacks = new List<AdminUnitItem>(); if (receive != null && (receive.HubID == user.DefaultHub.HubID)) { var rViewModel= ReceiveViewModel.GenerateReceiveModel(receive, commodities, commodityGrades, transporters, commodityTypes, commoditySources, programs, donors, hubs, user, units); //TODO:=====================================Refactored from viewmodel needs refactor============================ if (rViewModel.StoreID != 0) { Store store = _storeService.FindById(rViewModel.StoreID); foreach (var i in store.Stacks) { stacks.Add(new AdminUnitItem { Name = i.ToString(), Id = i }); } } rViewModel.Stacks = stacks; //=============================================================================================================== return View("Create", rViewModel); } else if (receive != null && (receive.HubID != user.DefaultHub.HubID)) { ViewBag.Message = string.Format( "The selected GRN Number {0} doesn't exist in your default warehouse. Try changing your default warehouse.", receive.GRN); } } // Hack ViewBag.Stacks = new SelectList(Enumerable.Empty<SelectListItem>()); List<ReceiveDetailViewModel> receiveCommodities = new List<ReceiveDetailViewModel>(); ViewBag.ReceiveCommodities = receiveCommodities; //TODO:Stacks shuld be sent basend storeID var receiveViewModel = new ReceiveViewModel(commodities, commodityGrades, transporters, commodityTypes, commoditySources, programs, donors, hubs, user,units); if (Request["type"] != null) { receiveViewModel.CommoditySourceID = Convert.ToInt32(Request["type"]); } else { receiveViewModel.CommoditySourceID = 1; } //receiveViewModel.SINumber = Request["SINumber"]; if (Request["ReceiptAllocationID"] != null) { Guid receiptAllocationID = Guid.Parse(Request["ReceiptAllocationID"]); //Added (p.HubID == user.DefaultHub.HubID) check to load allocation only for the current user's defalt Hub //get populate using allocation by current hub,comsource and and si number,and not closed //TODO use the merge function to have swap,repay,..and others //var rAllocation = repository.ReceiptAllocation.GetAllByTypeMerged(receiveViewModel.CommoditySourceID) // .FirstOrDefault(p => p.SINumber == receiveViewModel.SINumber && p.HubID == user.DefaultHub.HubID // && p.IsClosed == false); //TODO we can load all the sub-commodites here //var rAllocation = repository.ReceiptAllocation.FindBySINumber(receiveViewModel.SINumber).FirstOrDefault( // p => p.CommoditySourceID == receiveViewModel.CommoditySourceID && p.HubID == user.DefaultHub.HubID && p.IsClosed == false); var rAllocation = _receiptAllocationService.FindById(receiptAllocationID); if (rAllocation != null) { var shippingInstruction = _shippingInstructionService.FindBy(t => t.Value == rAllocation.SINumber).FirstOrDefault(); var gCertificate = new GiftCertificate(); if(shippingInstruction!=null) //Only for loading Waybill no gCertificate = _giftCertificateService.FindBySINumber(shippingInstruction.ShippingInstructionID); if (gCertificate != null) { var giftCertificateDetail = gCertificate.GiftCertificateDetails.FirstOrDefault(); if (giftCertificateDetail != null) { receiveViewModel.WayBillNo = giftCertificateDetail.BillOfLoading; } receiveViewModel.PortName = gCertificate.PortName; receiveViewModel.VesselName = gCertificate.Vessel; } if (rAllocation.HubID == user.DefaultHub.HubID) { //if the allocation is for the current hub allocation receiveViewModel.ReceiptAllocationID = rAllocation.ReceiptAllocationID; receiveViewModel.SINumber = rAllocation.SINumber; receiveViewModel.ProjectNumber = rAllocation.ProjectNumber; receiveViewModel.ProgramID = rAllocation.ProgramID; receiveViewModel.CommodityTypeID = rAllocation.Commodity.CommodityTypeID; receiveViewModel.ResponsibleDonorID = rAllocation.DonorID; //receiveViewModel.CommoditySourceID = rAllocation.DonorID; receiveViewModel.SupplierName = rAllocation.SupplierName; receiveViewModel.SourceHubID = rAllocation.SourceHubID; receiveViewModel.PurchaseOrder = rAllocation.PurchaseOrder; if (rAllocation.Commodity.ParentID != null) { //TODO if we were to load multiple commoditites don't forget to derecement the allocation id in the neative direction receiveCommodities.Add(new ReceiveDetailViewModel() {ReceiveDetailID = null, ReceiveDetailCounter = -1, CommodityID = rAllocation.CommodityID}); receiveViewModel.JSONPrev = JsonConvert.SerializeObject(receiveCommodities); } } else { ViewBag.Message = string.Format( "The selected Receipt Allocation {0} doesn't exist in your default warehouse. Try changing your default warehouse.", rAllocation.ReceiptAllocationID); } } } return View("Create", receiveViewModel); }
/// <summary> /// Gifts the certificate model. /// </summary> /// <param name="GiftCertificateModel">The gift certificate model.</param> /// <returns></returns> public static GiftCertificateViewModel GiftCertificateModel(GiftCertificate GiftCertificateModel) { GiftCertificateViewModel giftCertificateViewModel = new GiftCertificateViewModel(); giftCertificateViewModel.GiftCertificateID = GiftCertificateModel.GiftCertificateID; giftCertificateViewModel.GiftDate = GiftCertificateModel.GiftDate; giftCertificateViewModel.DonorID = GiftCertificateModel.DonorID; giftCertificateViewModel.ShippingInstructionID = GiftCertificateModel.ShippingInstructionID; giftCertificateViewModel.ReferenceNo = GiftCertificateModel.ReferenceNo; giftCertificateViewModel.Vessel = GiftCertificateModel.Vessel; giftCertificateViewModel.ETA = GiftCertificateModel.ETA; giftCertificateViewModel.ProgramID = GiftCertificateModel.ProgramID; giftCertificateViewModel.PortName = GiftCertificateModel.PortName; giftCertificateViewModel.DModeOfTransport = GiftCertificateModel.DModeOfTransport; var giftCertificateDetail = GiftCertificateModel.GiftCertificateDetails.FirstOrDefault(); if (giftCertificateDetail != null) giftCertificateViewModel.CommodityTypeID = giftCertificateDetail.Commodity.CommodityTypeID; else giftCertificateViewModel.CommodityTypeID = 1;//by default 'food' giftCertificateViewModel.GiftCertificateDetails = GiftCertificateDetailsViewModel.GenerateListOfGiftCertificateDetailsViewModel( GiftCertificateModel.GiftCertificateDetails.ToList()); return giftCertificateViewModel; }
public ActionResult LoadBySIPartial(string SInumber, int? type) { UserProfile user = _userProfileService.GetUser(User.Identity.Name); var receiptAllocationViewModel = BindReceiptAllocaitonViewModel();; receiptAllocationViewModel.HubID = user.DefaultHub.HubID; if (SInumber != null) { var shippingInstruction = _shippingInstructionService.FindBy(t => t.Value == SInumber).FirstOrDefault(); var GC = new Cats.Models.Hubs.GiftCertificate(); if(shippingInstruction!=null) GC = _giftCertificateService.FindBySINumber(shippingInstruction.ShippingInstructionID); if (GC != null && type ==CommoditySource.Constants.DONATION) { receiptAllocationViewModel.Commodities.Clear(); receiptAllocationViewModel.Donors.Clear(); receiptAllocationViewModel.Programs.Clear(); foreach (GiftCertificateDetail giftCertificateDetail in GC.GiftCertificateDetails) { receiptAllocationViewModel.Commodities.Add(giftCertificateDetail.Commodity); } //Commodity commodity = receiptAllocationViewModel.Commodities.FirstOrDefault(); //receiptAllocationViewModel.CommodityID = commodity.CommodityID; receiptAllocationViewModel.Donors.Add(GC.Donor); receiptAllocationViewModel.DonorID = GC.DonorID; receiptAllocationViewModel.Programs.Add(GC.Program); receiptAllocationViewModel.ProgramID = GC.ProgramID; receiptAllocationViewModel.CommoditySources.Clear(); receiptAllocationViewModel.CommoditySources.Add( _commoditySourceService.FindById(CommoditySource.Constants.DONATION)); receiptAllocationViewModel.CommoditySourceID =CommoditySource.Constants.DONATION; var hubs = new List<Cats.Models.Hubs.Hub>(); //foreach (var c in receiptAllocationViewModel.Hubs) //{ // var bySI = _receiptAllocationService.FindBySINumber(SInumber); // if(bySI.Find(p=>p.HubID == c.HubID) == null ) // { // hubs.Add(c); // } //} //if(hubs.Count() != 0) //{ // receiptAllocationViewModel.Hubs.Clear(); // receiptAllocationViewModel.Hubs = hubs; //} hubs.Add(user.DefaultHub); receiptAllocationViewModel.Hubs = hubs; receiptAllocationViewModel.ETA = GC.ETA; receiptAllocationViewModel.SINumber = SInumber; } else { receiptAllocationViewModel.CommoditySources.Remove( _commoditySourceService.FindById(CommoditySource.Constants.DONATION)); //remove the donor and add the } } int sourceType =CommoditySource.Constants.DONATION; if (Request["type"] != null) { sourceType = Convert.ToInt32(Request["type"]); } //List<ReceiptAllocation> list = _receiptAllocationService.GetAllByType(sourceType); ViewBag.CommoditySourceType = sourceType; if (CommoditySource.Constants.DONATION == sourceType) { ViewBag.CommoditySourceTypeText = _commoditySourceService.FindById(sourceType).Name; receiptAllocationViewModel.CommoditySources.Clear(); receiptAllocationViewModel.CommoditySources.Add( _commoditySourceService.FindById(CommoditySource.Constants.DONATION)); receiptAllocationViewModel.CommoditySourceID =CommoditySource.Constants.DONATION; } //else if (CommoditySource.Constants.TRANSFER == sourceType) //{ // ViewBag.CommoditySourceTypeText = _commoditySourceService.FindById(sourceType).Name; // receiptAllocationViewModel.CommoditySources.Clear(); // receiptAllocationViewModel.CommoditySources.Add( // _commoditySourceService.FindById(CommoditySource.Constants.TRANSFER)); // receiptAllocationViewModel.CommoditySourceID =CommoditySource.Constants.TRANSFER; //} else if (CommoditySource.Constants.LOCALPURCHASE == sourceType) { ViewBag.CommoditySourceTypeText = _commoditySourceService.FindById(sourceType).Name; receiptAllocationViewModel.CommoditySources.Clear(); receiptAllocationViewModel.CommoditySources.Add( _commoditySourceService.FindById(CommoditySource.Constants.LOCALPURCHASE)); receiptAllocationViewModel.CommoditySourceID =CommoditySource.Constants.LOCALPURCHASE; } else if (CommoditySource.Constants.TRANSFER == sourceType || CommoditySource.Constants.REPAYMENT == sourceType || CommoditySource.Constants.LOAN == sourceType || CommoditySource.Constants.SWAP == sourceType) { ViewBag.CommoditySourceTypeText = "Loan, Repayment, transfer and Swap"; receiptAllocationViewModel.CommoditySources.Clear(); receiptAllocationViewModel.CommoditySources.Add( _commoditySourceService.FindById(CommoditySource.Constants.REPAYMENT)); receiptAllocationViewModel.CommoditySources.Add( _commoditySourceService.FindById(CommoditySource.Constants.LOAN)); receiptAllocationViewModel.CommoditySources.Add( _commoditySourceService.FindById(CommoditySource.Constants.SWAP)); receiptAllocationViewModel.CommoditySources.Add( _commoditySourceService.FindById(CommoditySource.Constants.TRANSFER)); } receiptAllocationViewModel.SINumber = SInumber; return PartialView("Create", receiptAllocationViewModel); }
public bool EditGiftCertificate(GiftCertificate giftCertificate) { _unitOfWork.GiftCertificateRepository.Edit(giftCertificate); _unitOfWork.Save(); return true; }