Пример #1
0
 public ActivityDocument Create(CostCentre hub, CostCentre clerk, CostCentre supplier, CommodityProducer commodityProducer, ActivityType activityType, Route route, Centre centre, Season season, string documentReference, Guid documentIssueCostCentreApplicationId, DateTime documentDate, DateTime activityDate, string description = "", string note = "")
 {
     Guid id = Guid.NewGuid();
     ActivityDocument doc = DocumentPrivateConstruct<ActivityDocument>(id);
    
     doc.DocumentDate = documentDate;
     doc.DocumentDateIssued = activityDate;
     doc.Description = description;
     doc.Hub = hub;
     doc.FieldClerk = clerk;
     doc.Supplier = supplier;
     doc.Producer = commodityProducer;
     doc.ActivityType = activityType;
     doc.Route = route;
     doc.Centre = centre;
     doc.DocumentReference = documentReference;
     doc.DocumentIssuerCostCentreApplicationId = documentIssueCostCentreApplicationId;
     doc.Hub = hub;
     doc.FieldClerk = clerk;
     doc.Supplier = supplier;
     doc.DocumentReference = documentReference;
     doc.ActivityDate = activityDate;
     doc.DocumentDateIssued = DateTime.Now;
     doc.Season = season;
     SetDefaultDates(doc);
     doc.EnableAddCommands();
     return doc;
 }
 public bool AddCommodityProducer(CommodityProducer commodityProducerToEdit, out CommodityProducer commodityProducerReturned)
 {
     _vm = DataContext as EditCommodityProducerModalViewModel;
     _vm.Load(commodityProducerToEdit);
     _vm.CloseDialog += (s, e) => this.Close();
     ShowDialog();
     commodityProducerReturned = _vm.CommodityProducer;
     return _vm.DialogResult; ;
 }
       public CommodityPurchaseNote Create(CostCentre documentIssuerCostCentre, 
           Guid documentIssueCostCentreApplicationId,
           CostCentre documentRecipientCostCentre,
           User documentIssuerUser, string documentReference, 
           Guid documentParentId, 
           string deliveredBy, 
           CommodityProducer commodityProducer,
           CommoditySupplier commoditySupplier, 
           CommodityOwner owner,
           DateTime documentDate,
           DateTime documentDateIssued, string description,string note)
       {
           Guid id = Guid.NewGuid();
           var doc = DocumentPrivateConstruct<CommodityPurchaseNote>(id);
           if (documentParentId == null || documentParentId == Guid.Empty)
               doc.DocumentParentId = id;
           else
               doc.DocumentParentId = documentParentId;

           doc.DeliveredBy = deliveredBy;
           doc.CommodityOwner = owner;
           doc.CommodityProducer = commodityProducer;
           doc.CommoditySupplier = commoditySupplier;
           doc.DocumentIssuerCostCentre = documentIssuerCostCentre;
           doc.DocumentIssuerCostCentreApplicationId = documentIssueCostCentreApplicationId;
           doc.DocumentRecipientCostCentre = documentRecipientCostCentre;
           doc.DocumentReference = documentReference;
           doc.DocumentIssuerUser = documentIssuerUser;
           doc.Description = description;
           doc.Note = note;
           doc.DocumentDate = documentDate;
           doc.DocumentDateIssued = documentDateIssued;

           Map(doc, documentIssuerCostCentre, documentIssueCostCentreApplicationId, documentRecipientCostCentre, documentIssuerUser, documentReference, null, null);
           SetDefaultDates(doc);
           doc.EnableAddCommands();
           return doc;
       }
Пример #4
0
 public CommodityProducerDTO Map(CommodityProducer commodityProducer)
 {
     if (commodityProducer == null) return null;
     var commodityProducerDto = Mapper.Map<CommodityProducer, CommodityProducerDTO>(commodityProducer);
     return commodityProducerDto;
 }
Пример #5
0
 public async Task<ResponseBool> CommodityProducerAddAsync(CommodityProducer commodityProducer)
 {
     ResponseBool _response = new ResponseBool { Success = false, ErrorInfo = "" };
     string url = string.Format("api/distributorservices/commodityproduceradd");
     var httpClient = setupHttpClient();
     httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
     try
     {
         var response = await httpClient.PostAsJsonAsync(url, commodityProducer);
         _response = await response.Content.ReadAsAsync<ResponseBool>();
     }
     catch (Exception ex)
     {
         _log.Error("Failed to update commodity producer.", ex);
     }
     return _response;
 }
        private async Task<ResponseBool> SaveCommodityProducer(CommodityProducer commodityproducer)
        {
            var response = new ResponseBool {Success = false};
            var logs = new List<string>();

            string log = string.Format("Created farm: {0}; Code {1}; In Account {2} ",
                                       commodityproducer.Name, commodityproducer.Code,
                                       commodityproducer.CommoditySupplier.Name);
            logs.Add(log);
            using(var c=NestedContainer)
            {
                var mapper = Using<IMasterDataToDTOMapping>(c);
                var commodityProducerDto = mapper.Map(commodityproducer);
                response = await _proxy.CommodityProducerAddAsync(commodityProducerDto);
                if(response.Success)
                    logs.ForEach(n=>Using<IAuditLogWFManager>(c).AuditLogEntry("Farm Management",n));
            }
            return response;
        }
        private async void Save()
        {
            
            CommodityProducer commodityProducer;
            string responseMsg = string.Empty;
            var response = new ResponseBool {Success = false};
                using(var c=NestedContainer)
                {
                    commodityProducer = Using<ICommodityProducerRepository>(c).GetById(Id);
                    //commodityProducer.Code = Code;
                    if(commodityProducer==null)
                        commodityProducer = new CommodityProducer(Id);
                    
                    commodityProducer.CommodityProducerCentres.Clear();
                    commodityProducer.CommodityProducerCentres.AddRange(AssignedCentresList.Select(n => n.Centre));
                    commodityProducer.Code = Code;
                    commodityProducer.Name = Name;
                    commodityProducer.RegNo = RegistrationNumber;
                    commodityProducer.PhysicalAddress = PhysicalAddress;
                    commodityProducer.Description = Description;
                    commodityProducer.Acrage = Acerage;
                    commodityProducer.CommodityProducerCentres.AddRange(AssignedCentresList.Select(n => n.Centre));
                    commodityProducer._Status = EntityStatus.Active;

                var commoditySupplier = Using<ICommoditySupplierRepository>(c).GetById(SupplierId) as CommoditySupplier;
                if(commoditySupplier!=null)
                {
                    commodityProducer.CommoditySupplier = commoditySupplier;
                }

                if (!IsValid(commodityProducer)) return;
                
                _proxy = Using<IDistributorServiceProxy>(c);
                response = await SaveCommodityProducer(commodityProducer);
                if (response.ErrorInfo != "")
                {
                    responseMsg += response.ErrorInfo + "\n";
                    if (!response.Success)
                    {
                        MessageBox.Show(response.ErrorInfo, "Agrimanager :" + PageTitle, MessageBoxButton.OK);
                        return;
                    }
                }
                
                if (!string.IsNullOrWhiteSpace(responseMsg)) //responseMsg.Equals(string.Empty))
                    if(IsEdit)
                    {
                        responseMsg = "Farmer Edited Successfully!";
                        IsEdit = false;
                    }
                    else
                    {
                        responseMsg = "Farmer Added Successfully!";
                    }
                MessageBox.Show(responseMsg, "Agrimanager :" + PageTitle, MessageBoxButton.OK,
                                MessageBoxImage.Information);

                if (response.Success)
                    SendNavigationRequestMessage(new Uri("Views/Admin/Producer/ListingMemberCommodityProducers.xaml",
                                                         UriKind.Relative));
            }
        }
        protected override void LoadPage(Page page)
        {
            Guid commodityOwnerId = PresentationUtility.ParseIdFromUrl(page.NavigationService.CurrentSource);
            ContactsList.Clear();
            using (var c = NestedContainer)
            {
                if (commodityOwnerId == Guid.Empty)
                {
                    PageTitle = "Add Farmer";
                    CommoditySupplier = Using<CostCentreFactory>(c).CreateCostCentre(Guid.NewGuid(), CostCentreType.CommoditySupplier,
                                                                     Using<ICostCentreRepository>(c).GetById(
                                                                         GetConfigParams().CostCentreId)) as
                        CommoditySupplier;
                    CommodityOwner = new CommodityOwner(Guid.NewGuid()) {CommoditySupplier = CommoditySupplier};
                    CommodityProducer = new CommodityProducer(Guid.NewGuid())
                                            {
                                                CommoditySupplier = CommoditySupplier,
                                                CommodityProducerCentres = new List<Centre>()
                                            };
                }
                else
                {
                    PageTitle = "Edit Farmer";
                    var commodityOwner = Using<ICommodityOwnerRepository>(c).GetById(commodityOwnerId);
                    CommodityOwner = commodityOwner.DeepClone<CommodityOwner>();
                    CommoditySupplier = commodityOwner.CommoditySupplier.DeepClone<CommoditySupplier>();
                    CommodityProducer =
                        Using<ICommodityProducerRepository>(c).GetAll().FirstOrDefault(
                            n => n.CommoditySupplier.Id == CommoditySupplier.Id);

                }
                Setup();
            }
        }
Пример #9
0
 public bool CommodityProducerHasPurchases(CommodityProducer commodityProducer)
 {
     return _ctx.tblSourcingDocument.Any(n => n.CommodityProducerId == commodityProducer.Id);
 }
Пример #10
0
        private void ChangeAllocation(CommodityProducerDTO dto)
        {
             CommodityProducer entity = new CommodityProducer(dto.MasterId);
             using (var container = NestedContainer)
             {
                 var centreRepository = Using<ICentreRepository>(container);
                 //var _commodityProducerRepository = Using<ICommodityProducerRepository>(container);
                 var masterDataAllocationRepository = Using<IMasterDataAllocationRepository>(container);
                 foreach (var centreId in dto.CenterIds)
                 {
                     entity.CommodityProducerCentres.Add(centreRepository.GetById(centreId));
                 }





                 try
                 {
                     //_commodityProducerRepository.Save(entity);
                     var existingAllocationForThisProducer = masterDataAllocationRepository.GetByAllocationType(
                         MasterDataAllocationType.CommodityProducerCentreAllocation)
                         .Where(n => n.EntityAId == entity.Id);

                     var unallocated =
                         existingAllocationForThisProducer.Where(
                             n =>
                             entity.CommodityProducerCentres.Select(c => c.Id).All(cId => n.EntityBId != cId));

                     //foreach (var centre in entity.CommodityProducerCentres)
                     //{
                     //    var allocation = new MasterDataAllocation(Guid.NewGuid())
                     //                         {
                     //                             _Status = EntityStatus.Active,
                     //                             AllocationType =
                     //                                 MasterDataAllocationType.CommodityProducerCentreAllocation,
                     //                             EntityAId = entity.Id,
                     //                             EntityBId = centre.Id
                     //                         };
                     //    _masterDataAllocationRepository.Save(allocation);
                     //}

                     foreach (var allocation in unallocated)
                     {
                         masterDataAllocationRepository.DeleteAllocation(allocation.Id);
                     }
                 }
                 catch (Exception)
                 {
                     //throw ;
                     //response.ErrorInfo = "Error: An error occurred when saving the commodity producer.\n" +
                     //                        ex.ToString();
                 }
             }
        }
Пример #11
0
        public async Task<ResponseBool> SaveCommodityProducer(CommodityProducer commodityProducer)
        {
            ResponseBool response = new ResponseBool { Success = false };

            string log = string.Format("Created farm: {0}; Code: {1}; In Account {2}",
                                       commodityProducer.Name,
                                       commodityProducer.Code, commodityProducer.CommoditySupplier.Name);

            using (var c = NestedContainer)
            {
                var mapper = Using<IMasterDataToDTOMapping>(c);
                var commodityProducerDto = mapper.Map(commodityProducer);
                response = await _proxy.CommodityProducerAddAsync(commodityProducerDto);
                if (response.Success)
                {
                    ChangeAllocation(commodityProducerDto);
                     Using<IAuditLogWFManager>(c).AuditLogEntry("Farm Management", log);
                }
                   
            }
            return response;
        }
Пример #12
0
        private async void Save()
        {
              var commodityOwner =new CommodityOwner(CommodityOwnerId);
              var commoditySupplier=new CommoditySupplier(Id);
              var  commodityProducer = new CommodityProducer(CommodityProducerId);
              var contact = new Contact(ContactId);

         using (var c = NestedContainer)
            {
                commodityOwner.Code = OwnerCode;
                if (string.IsNullOrEmpty(commodityOwner.Code))
                {
                    MessageBox.Show("Farmer Code is a Required Field", "Agrimanagr: Farmer Management",
                                        MessageBoxButton.OK);
                    return;

                }
                commodityOwner.Surname = Surname;
                commodityOwner.FirstName = FirstName;
                commodityOwner.LastName = MiddleName;
                commodityOwner.IdNo = IdNumber;
                commodityOwner.PinNo = PinNumber;
                //CommodityOwner.Gender =;
                commodityOwner.PhysicalAddress = PhysicalAddress;
                commodityOwner.PostalAddress = PostalAddress;
                commodityOwner.Email = Email;
                commodityOwner.PhoneNumber = PhoneNumber;
                commodityOwner.BusinessNumber = BusinessNumber;
                commodityOwner.FaxNumber = FaxNumber;
                commodityOwner.OfficeNumber = OfficeNumber;
                commodityOwner.Description = Description;
                commodityOwner.DateOfBirth = DateOfBirth;
                commodityOwner.CommoditySupplier = commoditySupplier;
                commodityOwner._Status = EntityStatus.Active;
                if (DateTime.Now.Year - DateOfBirth.Year < 18)
                    {
                        MessageBox.Show("Farmer must be over 18 years old.", "Agrimanagr: Farmer Management",
                                        MessageBoxButton.OK);
                        return;
                    }
            
                commodityOwner.MaritalStatus = SelectedMaritalStatus;
                commodityOwner.CommodityOwnerType = SelectedCommodityOwnerType;

                commoditySupplier.JoinDate = DateTime.Now.Date;
                commoditySupplier.AccountName = AccountName;
                commoditySupplier.AccountNo = AccountNumber;

                commoditySupplier._Status = EntityStatus.Active;
                commoditySupplier.PinNo = PinNumber;
                commoditySupplier.BankId = SelectedBank.Id;
                commoditySupplier.BankBranchId = SelectedBankBranch.Id;
                commoditySupplier.CommoditySupplierType = SelectedCommoditySupplierType;
                commoditySupplier.CostCentreCode = CostCenterCode;
                commoditySupplier.Name = AccountFullName;
                    var config = Using<IConfigService>(c).Load();
                    commoditySupplier.ParentCostCentre = new CostCentreRef {Id = config.CostCentreId};

                if (!IsValid(commoditySupplier))
                    return;

                commodityProducer.CommoditySupplier = commoditySupplier;
                commodityProducer._SetStatus(EntityStatus.Active);
                commodityOwner.BusinessNumber = BusinessNumber;
               if (!IsValid(commodityOwner)) return;

                commodityProducer.CommodityProducerCentres.Clear();
             
             
                commodityProducer.CommodityProducerCentres.AddRange(AssignedCentresList.Select(n => n.Centre));
                commodityProducer.Code = FarmCode;
                if (string.IsNullOrEmpty(commodityProducer.Code))
                {
                    MessageBox.Show("Farm Code is a Required Field", "Agrimanagr: Farmer Management",
                                        MessageBoxButton.OK);
                    return;
                }
                commodityProducer.Acrage = Acerage;
                commodityProducer.Name = FarmName;
                commodityProducer._Status = EntityStatus.Active;
                commodityProducer.RegNo = FarmRegistrationNo;
                commodityProducer.PhysicalAddress = FarmPhysicalAddress;
                commodityProducer.Description = FarmDescription;
                commodityProducer.CommoditySupplier = commoditySupplier;


                contact.BusinessPhone = BusinessNumber;
                contact.Email = Email;
                contact.ContactOwnerMasterId = commoditySupplier.Id;
                contact.Firstname = AccountFullName;
                contact.PostalAddress = PostalAddress;
                contact.MobilePhone = PhoneNumber;
                contact.PhysicalAddress = PhysicalAddress;
                contact.ContactOwnerType=ContactOwnerType.CommoditySupplier;

                if (!IsValid() || !IsValid(commodityProducer)) return;


                   string responseMsg = "";
                   _proxy = Using<IDistributorServiceProxy>(c);
                   var mapper = Using<IMasterDataToDTOMapping>(c);
                    var commoditySupplierdto = mapper.Map(commoditySupplier);
                    ResponseBool response = await _proxy.CommoditySupplierAddAsync(commoditySupplierdto);
                    responseMsg += response.ErrorInfo + "\n";

                    string log = string.Format("Created commodity supplier: {0}; Code: {1}; And Type {2}",
                                               commoditySupplier.Name,
                                               commoditySupplier.CostCentreCode, commoditySupplier.CommoditySupplierType);
                    Using<IAuditLogWFManager>(c).AuditLogEntry("Manage Commodity Suppliers", log);


                    if (response.Success)
                    {
                        ContactsList.Clear();
                        var coResponse = await SaveCommodityOwner(commodityOwner);
                        if (coResponse.ErrorInfo != "") responseMsg += coResponse.ErrorInfo + "\n";

                        var contactResponse = await SaveSupplierContact(contact);
                        if (contactResponse.ErrorInfo != "") responseMsg += contactResponse.ErrorInfo + "\n";

                        var cpResponse = await SaveCommodityProducer(commodityProducer);
                        if (cpResponse.ErrorInfo != "") responseMsg += cpResponse.ErrorInfo + "\n";

                       

                        if (!coResponse.Success || !cpResponse.Success)
                            response.Success = false;
                    }
                    if (response.Success)
                    {
                          responseMsg = "Farmer Successfully Added ";
                        MessageBox.Show(responseMsg, "Agrimanagr: Manage Farmer", MessageBoxButton.OK,
                                    MessageBoxImage.Information);

                         SendNavigationRequestMessage(
                            new Uri("views/admin/Supplier/ListOfSuppliers.xaml", UriKind.Relative));
                    }
                    else
                    {
                        MessageBox.Show(responseMsg, "Agrimanagr: Manage Farmer", MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                    }

            
                       
            }
        }
Пример #13
0
        protected Guid AddCommodityProducer(string acres, string code, string name, string regNu, Guid commSupplierId)
        {
            CommodityProducer cp = new CommodityProducer(Guid.NewGuid())
            {
                Acrage = acres,
                Code = code,
                CommoditySupplier = _commoditySupplierRepository.GetById(commSupplierId) as CommoditySupplier,
                Description = "Farm",
                Name = name,
                PhysicalAddress = "PhAdd",
                RegNo = regNu,
                CommodityProducerCentres = _centreRepository.GetAll().Take(2).ToList(),
                _Status = EntityStatus.Active,
            };

            return _commodityProducerRepository.Save(cp);

        }
 public void Load(CommodityProducer commodityProducer)
 {
     using (var c = NestedContainer)
     {
         if (commodityProducer.Id == Guid.Empty)
         {
             CommodityProducer = new CommodityProducer(Guid.NewGuid()){CommoditySupplier = commodityProducer.CommoditySupplier};
             CommodityProducer.CommodityProducerCentres = new List<Centre>();
             PageTitle = "Add Farm to Account "+ CommodityProducer.CommoditySupplier.Name;
         }
         else
         {
             CommodityProducer = commodityProducer.Clone<CommodityProducer>();
             PageTitle = "Edit Farm for Account " + CommodityProducer.CommoditySupplier.Name;
         }
         Setup();
     }
 }
 protected override void LoadPage(Page page)
 {
     Guid oommodityProducerId = PresentationUtility.ParseIdFromUrl(page.NavigationService.CurrentSource);
     using (var c = NestedContainer)
     {
         if (oommodityProducerId == Guid.Empty)
         {
             CommodityProducer = new CommodityProducer(Guid.NewGuid());
             CommodityProducer.CommodityProducerCentres = new List<Centre>();
             PageTitle = "Create Commodity Producer";
         }
         else
         {
             var commodityProducer = Using<ICommodityProducerRepository>(c).GetById(oommodityProducerId);
             CommodityProducer = commodityProducer.Clone<CommodityProducer>();
             PageTitle = "Edit Commodity Producer";
         }
         Setup();
         if (CommodityProducer._Status != EntityStatus.New)
             SelectedCommoditySupplier =
                 CommoditySupplierList.FirstOrDefault(n => n.Id == CommodityProducer.CommoditySupplier.Id);
     }
 }
        public HttpResponseMessage CommodityProducerAdd(CommodityProducer commodityProducer)
        {
            var response = new ResponseBool { Success = false };
            using (TransactionScope scope = TransactionUtils.CreateTransactionScope())
            {
                try
                {
                    _commodityProducerRepository.Save(commodityProducer);


                    var existingAllocationForThisProducer = _masterDataAllocationRepository.GetByAllocationType(
                        MasterDataAllocationType.CommodityProducerCentreAllocation)
                        .Where(n => n.EntityAId == commodityProducer.Id);

                    var unallocated =
                        existingAllocationForThisProducer.Where(
                            n =>
                            commodityProducer.CommodityProducerCentres.Select(c => c.Id).All(cId => n.EntityBId != cId));

                    foreach (var centre in commodityProducer.CommodityProducerCentres)
                    {
                        var allocation = new MasterDataAllocation(Guid.NewGuid())
                                             {
                                                 _Status = EntityStatus.Active,
                                                 AllocationType =
                                                     MasterDataAllocationType.CommodityProducerCentreAllocation,
                                                 EntityAId = commodityProducer.Id,
                                                 EntityBId = centre.Id
                                             };
                        _masterDataAllocationRepository.Save(allocation);
                    }

                    foreach (var allocation in unallocated)
                    {
                        _masterDataAllocationRepository.DeleteAllocation(allocation.Id);
                    }

                    response.Success = true;
                    response.ErrorInfo = "Commodity producer successfully added.";
                    scope.Complete();
                }
                catch (DomainValidationException dve)
                {
                    string errorMsg =
                        dve.ValidationResults.Results.Aggregate("Error: Invalid commodity producer fields.\n",
                                                                (current, msg) =>
                                                                current + ("\t- " + msg.ErrorMessage + "\n"));
                    response.ErrorInfo = errorMsg;
                    _log.Error(errorMsg, dve);
                }
                catch (Exception ex) //any other
                {
                    response.ErrorInfo = "Error: An error occurred when saving the commodity producer.\n" +
                                         ex.ToString();
                    _log.Error("Error: An error occurred when saving the commodity supplier.", ex);
                }
            }
            return Request.CreateResponse(HttpStatusCode.OK, response);
        }