예제 #1
0
        public static DeliveryDto ToDto(this Delivery model)
        {
            var dto = new DeliveryDto
            {
                ID                   = model.ID,
                SupplierID           = model.SupplierID,
                Supplier             = model.Supplier?.ToDto(),
                LocationID           = model.LocationID,
                Location             = model.DeliveryLocation?.ToDto(),
                BillNumber           = model.BillNumber,
                DeliveryDate         = model.DeliveryDate,
                PaymentDate          = model.PaymentDate,
                DollarRate           = model.DollarRate,
                EuroRate             = model.EuroRate,
                TotalGrossPrice      = model.TotalGrossPrice,
                TotalDiscount        = model.TotalDiscount,
                TotalDiscountedPrice = model.TotalDiscountedPrice,
                IsSubmitted          = model.IsSubmitted,
                ItemsCount           = model.Items?.Count ?? 0,
                Items                = model.Items?.Where(di => !di.IsDeleted).Select(i => i.ToDto())
            };

            dto.MapDetails(model);
            dto.CanBeDeleted = !(model.IsSubmitted || model.IsDeleted);

            return(dto);
        }
예제 #2
0
 public DeliveryReceiptPdf(DeliveryDto receipt, InventorySummary inventorySummary, string fileNameDrTemplate)
     : base(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false), PageSize.LETTER.Rotate())
 {
     deliveryReceipt       = receipt;
     fileNameTemplate      = fileNameDrTemplate;
     this.inventorySummary = inventorySummary;
 }
예제 #3
0
        public DeliveryDto New(int jobID, int empid)
        {
            string  name    = ctx.Employee.Find(empid).firstname + ' ' + ctx.Employee.Find(empid).lastname;
            JobSite jobsite = ctx.JobSite.Where(p => p.JobID == jobID).FirstOrDefault();

            Delivery newEntity = new Delivery
            {
                JobID        = jobID,
                JobSiteID    = jobsite.JobSiteID,
                DeliveryDate = DateTime.Now,
                EmployeeID   = empid
            };

            ctx.Delivery.Add(newEntity);
            ctx.SaveChanges();

            DeliveryDto dto = new DeliveryDto
            {
                JobID        = newEntity.JobID,
                DeliveryDate = newEntity.DeliveryDate,
                EmployeeID   = newEntity.EmployeeID,
                DriverName   = name,
                JobSiteID    = newEntity.JobSiteID
            };

            return(dto);
        }
예제 #4
0
 public DeliveryDto Update(DeliveryDto delivery)
 {
     var delvery = mapper.Map<Delivery.Core.Delivery>(delivery);
     var updatedDelvery = _delviryRepository.Update(delvery);
     _unitOfWork.Commit();
     return mapper.Map<DeliveryDto>(updatedDelvery);
 }
        public void ToExpectMapAllProperties()
        {
            var dto = new DeliveryDto
            {
                Id           = "expectedId",
                Recipient    = new RecipientDto(),
                AccessWindow = new AccessWindowDto(),
                Order        = new OrderDto(),
                State        = DeliveryState.Completed
            };

            var expectedRecipient = new Recipient();

            _mockRecipientMapper.Setup(mapper => mapper.To(dto.Recipient)).Returns(expectedRecipient);

            var expectedAccessWindow = new AccessWindow();

            _mockAccessWindowMapper.Setup(mapper => mapper.To(dto.AccessWindow)).Returns(expectedAccessWindow);

            var expectedOrder = new Order();

            _mockOrderMapper.Setup(mapper => mapper.To(dto.Order)).Returns(expectedOrder);

            var actual = _deliveryMapper.To(dto);

            Assert.NotNull(actual);
            Assert.Equal(dto.Id, actual.Id);
            Assert.Equal(expectedOrder, actual.Order);
            Assert.Equal(expectedRecipient, actual.Recipient);
            Assert.Equal(expectedAccessWindow, actual.AccessWindow);
            Assert.Equal(dto.State, actual.State);
        }
예제 #6
0
        public static Delivery ToEntity(this DeliveryDto dto)
        {
            var entity = new Delivery
            {
                ID                   = dto.ID,
                SupplierID           = dto.SupplierID,
                LocationID           = dto.LocationID,
                BillNumber           = dto.BillNumber,
                DeliveryDate         = dto.DeliveryDate,
                PaymentDate          = dto.PaymentDate,
                DollarRate           = dto.DollarRate,
                EuroRate             = dto.EuroRate,
                TotalGrossPrice      = dto.TotalGrossPrice,
                TotalDiscount        = dto.TotalDiscount,
                TotalDiscountedPrice = dto.TotalDiscountedPrice,
                IsSubmitted          = dto.IsSubmitted,
                Items                = dto.Items?.Select(i => i.ToEntity()).ToList(),
                Recommendations      = dto.Recommendations?.Select(r => r.ToEntity()).ToList(),
                Attachments          = dto.Attachments?.Select(a => a.ToEntity()).ToList()
            };

            if (!string.IsNullOrEmpty(dto.MainPicture?.FullPath))
            {
                entity.Attachments.Add(dto.MainPicture.ToEntity());
            }

            return(entity);
        }
예제 #7
0
        public async Task <ServiceResponse <int> > CreateAsync(DeliveryDto delivery, int userId)
        {
            if (delivery == null)
            {
                throw new ArgumentNullException(nameof(delivery));
            }

            var entity = delivery.ToEntity();

            entity.UpdateCreatedFields(userId).UpdateModifiedFields(userId);

            var supplier = await UnitOfWork.Get <Supplier>().GetAsync(s => s.ID == delivery.SupplierID);

            supplier.UpdateModifiedFields(userId);

            var location = await UnitOfWork.Get <Location>().GetAsync(l => l.ID == delivery.LocationID);

            location.UpdateModifiedFields(userId);

            entity.Recommendations?.UpdateCreatedFields(userId).UpdateModifiedFields(userId);
            entity.Attachments?.UpdateCreatedFields(userId).UpdateModifiedFields(userId);

            var saved = UnitOfWork.Get <Delivery>().Add(entity);

            await UnitOfWork.SaveAsync();

            return(new SuccessResponse <int>(saved.ID));
        }
예제 #8
0
        public async Task UpdateChangeForStateIsNotAllowed()
        {
            const Role expectedRole = Role.Partner;

            _mockExecutionContext.SetupGet(executionContext => executionContext.UserRole).Returns(expectedRole);

            const string        expectedId = "expectedId";
            const DeliveryState newState   = DeliveryState.Approved;
            var expectedDto = new DeliveryDto {
                Id = expectedId, State = newState
            };

            const DeliveryState oldState = DeliveryState.Created;
            var existedDelivery          = new Delivery
            {
                Id    = expectedId,
                State = oldState
            };

            _mockRepo.Setup(repo => repo.Get(expectedId)).Returns(Task.FromResult(existedDelivery));

            _mockPermissionChecker.Setup(checker => checker.RoleHasChangePermission(expectedRole,
                                                                                    oldState, newState)).Returns(false);

            await Assert.ThrowsAsync <UnauthorizedException>(async() =>
                                                             await _deliveryService.Update(_mockExecutionContext.Object, expectedDto));
        }
예제 #9
0
 public ComprobanteDelivery(long id) : this(new DeliveryServicio(), new ArticuloServicio(), new EmpleadoServicio(), new ClienteServicio())
 {
     InitializeComponent();
     comprobante = _deliveryServicio.ObtenerPorId(id);
     _edicion    = true;
     ActualizarGrilla();
 }
        public async Task <DeliveryDto> Update(IExecutionContext executionContext, DeliveryDto entity)
        {
            AssertExecutionContext(executionContext);

            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var existedEntity = await _deliveryRepo.Get(entity.Id);

            if (existedEntity == null)
            {
                return(null);
            }

            var oldState = existedEntity.State;
            var newState = entity.State;

            if (!_permissionChecker.RoleHasChangePermission(executionContext.UserRole,
                                                            oldState, newState))
            {
                throw new UnauthorizedException(
                          $"This role has no permission to change the role from {oldState} to {newState}");
            }

            var dbEntity = await _deliveryRepo.Update(_deliveryMapper.To(entity));

            return(_deliveryMapper.From(dbEntity));
        }
예제 #11
0
        /// <summary>Returns the PowerOffice customer code of the organisation that this delivery is associated with. Returns `null` if the code couldn't be found. This can happen if the organisation doesn't exist in PowerOffice.</summary>
        private async Task <long?> GetPowerofficeCustomerCode(
            DeliveryDto webcrmDelivery)
        {
            if (!webcrmDelivery.DeliveryOrganisationId.HasValue)
            {
                throw new ApplicationException("Cannot get PowerOffice organisation ID since DeliveryOrganisationId is null.");
            }

            var webcrmOrganisation = await WebcrmClient.GetOrganisationById(webcrmDelivery.DeliveryOrganisationId.Value);

            long?powerofficeOrganisationId = webcrmOrganisation.GetPowerofficeOrganisationId(Configuration.OrganisationIdFieldName);

            if (!powerofficeOrganisationId.HasValue)
            {
                return(null);
            }

            var powerofficeOrganisation = await PowerofficeClient.GetCustomer(powerofficeOrganisationId.Value);

            if (powerofficeOrganisation == null)
            {
                throw new ApplicationException($"Could not find a PowerOffice organisation with ID {powerofficeOrganisationId.Value}.");
            }

            if (!powerofficeOrganisation.Code.HasValue)
            {
                throw new ApplicationException("PowerOffice organisation code is null.");
            }

            return(powerofficeOrganisation.Code.Value);
        }
예제 #12
0
 public DeliveryDto Add(DeliveryDto delivery)
 {
     delivery.Id = Guid.NewGuid();
     var Newdelvery = mapper.Map<Delivery.Core.Delivery>(delivery);
     var delvery = _delviryRepository.Add(Newdelvery);
     _unitOfWork.Commit();
     return mapper.Map<DeliveryDto>(delivery);
 }
예제 #13
0
 /// <summary>Updates this delivery based on a webCRM delivery, excluding the delivery lines.</summary>
 protected void UpdateExcludingLines(
     DeliveryDto webcrmDelivery,
     long powerofficeCustomerCode)
 {
     CustomerCode = powerofficeCustomerCode;
     OrderDate    = webcrmDelivery.DeliveryOrderDate;
     Status       = OutgoingInvoiceStatus.Approved;
 }
 public UpsertDeliveryToFortnoxPayload(
     DeliveryDto webcrmDelivery,
     List <QuotationLineDto> webcrmDeliveryLines,
     string webcrmSystemId)
     : base(webcrmSystemId)
 {
     WebcrmDelivery      = webcrmDelivery;
     WebcrmDeliveryLines = webcrmDeliveryLines;
 }
예제 #15
0
 private void AssignDefaultPrice(DeliveryDto deliveryDto)
 {
     deliveryDto.SlimUnitPrice =
         LookupDataManager.ProductTypes.First(x => x.ProductTypeId == DataConstants.ProductTypes.Slim).BasePrice;
     deliveryDto.SlimAmount     = deliveryDto.SlimUnitPrice * deliveryDto.SlimQty;
     deliveryDto.RoundUnitPrice =
         LookupDataManager.ProductTypes.First(x => x.ProductTypeId == DataConstants.ProductTypes.Round).BasePrice;
     deliveryDto.RoundAmount = deliveryDto.RoundUnitPrice * deliveryDto.RoundQty;
 }
예제 #16
0
        public Task UpdateDeliveryAsync(DeliveryDto dto) =>
        GetConnectionAsync(con => con.ExecuteAsync(@"
UPDATE Delivery
SET
    MagicItemId = @MagicItemId
    AccountId = @AccountId
    Quantity = @Quantity
    Completed = @Completed
WHERE
    DeliveryId = @DeliveryId", dto));
예제 #17
0
        public DeliveryDto FindDelivery(int deliveryID)
        {
            var entity = ctx.Delivery.AsNoTracking().Include(j => j.Job)
                         .Include(s => s.JobSite).Include(e => e.Employee)
                         .Include(i => i.DeliveryItem).Where(d => d.DeliveryID == deliveryID).FirstOrDefault();
            DeliveryDto Dto = new DeliveryDto();

            deliveryMapper.Map(entity, Dto);
            return(Dto);
        }
예제 #18
0
        public async Task <ServiceResponse <DeliveryDto> > UpdateAsync(DeliveryDto delivery, int userId)
        {
            if (delivery == null)
            {
                throw new ArgumentNullException(nameof(delivery));
            }

            var existentEntity = await UnitOfWork.Get <Delivery>().GetAsync(d => d.ID == delivery.ID, d => d.Items);

            if (existentEntity == null)
            {
                return(new ServiceResponse <DeliveryDto>(ServiceResponseStatus.NotFound));
            }

            var entity = delivery.ToEntity();

            existentEntity.Attachments     = GetAttachments(existentEntity.ID).ToList();
            existentEntity.Recommendations = GetRecommendations(existentEntity.ID).ToList();

            existentEntity
            .UpdateFields(entity)
            .UpdateAttachments(entity, UnitOfWork, userId)
            .UpdateRecommendations(entity, UnitOfWork, userId)
            .UpdateModifiedFields(userId);

            if (entity.IsSubmitted)
            {
                foreach (var item in existentEntity.Items)
                {
                    for (var i = 0; i < item.Quantity; i++)
                    {
                        var goods = new Goods();

                        goods.UpdateCreatedFields(userId).UpdateModifiedFields(userId);

                        var storage = new Storage
                        {
                            LocationID = delivery.LocationID,
                            FromDate   = DateTime.Now
                        };

                        storage.UpdateCreatedFields(userId).UpdateModifiedFields(userId);

                        goods.Storages.Add(storage);
                        item.Goods.Add(goods);
                    }
                }
            }

            UnitOfWork.Get <Delivery>().Update(existentEntity);

            await UnitOfWork.SaveAsync();

            return(new SuccessResponse <DeliveryDto>());
        }
예제 #19
0
        public async Task UpdateExceptionHappenedExpectBadRequestResult()
        {
            var deliveryDto = new DeliveryDto();

            _mockDeliveryService.Setup(service => service.Update(_mockExecutionContext.Object, deliveryDto))
            .Throws <Exception>();

            var result = await _deliveriesController.Update("expectedId", deliveryDto);

            Assert.IsType <BadRequestResult>(result);
        }
예제 #20
0
 public IHttpActionResult CreateFractionedDelivery([FromBody] DeliveryDto fractionedDeliveryDto)
 {
     try
     {
         return(Ok(_createDeliveryBusiness.CreateFractionedDelivery(fractionedDeliveryDto)));
     }
     catch (Exception e)
     {
         return(InternalServerError(e));
     }
 }
예제 #21
0
 public async Task <bool> Remove(DeliveryDto deliveryDto)
 {
     try
     {
         var delivery = _mapper.Map <Delivery>(deliveryDto);
         return(await _service.Remove(delivery));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public async Task <IHttpActionResult> StartDelivery(Guid courierId, DeliveryDto delivery)
        {
            foreach (var order in delivery.Orders)
            {
                await OrderService.ChangeOrderStateAsync(order, OrderStateDto.Fulfillment);
            }
            await RouteService.AddRouteAsync(courierId, delivery.Route);

            await CourierService.ChangeCourierStateAsync(courierId, CourierStateDto.PerformsDelivery);

            return(Ok());
        }
예제 #23
0
 public Response Post(DeliveryDto model)
 {
     if (ModelState.IsValid)
     {
         return(_inventoryService.Add(model));
     }
     return(new Response
     {
         IsSuccess = false,
         Errors = new Error("", "اطلاعات ورودی صحیح نمی باشد"),
     });
 }
예제 #24
0
        public async Task CopyDeliveryToPoweroffice(
            DeliveryDto webcrmDelivery,
            List <QuotationLineDto> webcrmDeliveryLines)
        {
            Guid?powerofficeDeliveryId = webcrmDelivery.GetPowerofficeDeliveryId(Configuration.DeliveryIdFieldName);

            if (powerofficeDeliveryId == null)
            {
                long?powerofficeCustomerCode = await GetPowerofficeCustomerCode(webcrmDelivery);

                if (!powerofficeCustomerCode.HasValue)
                {
                    Logger.LogInformation($"Not copying webCRM delivery with ID {webcrmDelivery.DeliveryId} to PowerOffice because the corresponding PowerOffice organisation could not be found.");
                    return;
                }

                Logger.LogTrace("Copying delivery to PowerOffice, creating a new one.");
                var newPowerofficeDelivery     = new NewOutgoingInvoice(webcrmDelivery, webcrmDeliveryLines, powerofficeCustomerCode.Value, Configuration.ProductIdFieldName);
                var createdPowerofficeDelivery = await PowerofficeClient.CreateInvoice(newPowerofficeDelivery);

                webcrmDelivery.SetPowerofficeDeliveryId(Configuration.DeliveryIdFieldName, createdPowerofficeDelivery.Id);
                await WebcrmClient.UpdateDelivery(webcrmDelivery);

                if (createdPowerofficeDelivery.OutgoingInvoiceLines.Count != webcrmDeliveryLines.Count)
                {
                    throw new ApplicationException($"Sanity check failed: Expected the same number of lines in newly created PowerOffice delivery. Lines in webCRM delivery: {webcrmDeliveryLines.Count}. Lines in PowerOffice delivery: {createdPowerofficeDelivery.OutgoingInvoiceLines.Count}.");
                }
            }
            else
            {
                var matchingPowerofficeDelivery = await PowerofficeClient.GetInvoice(powerofficeDeliveryId.Value);

                if (matchingPowerofficeDelivery == null)
                {
                    Logger.LogWarning($"Could not find PowerOffice delivery (invoice) with id {powerofficeDeliveryId.Value}. Not copying the delivery to PowerOffice.");
                    return;
                }

                // Not comparing the two deliveries, since we're only synchronising deliveries one way.

                long?powerofficeCustomerCode = await GetPowerofficeCustomerCode(webcrmDelivery);

                if (!powerofficeCustomerCode.HasValue)
                {
                    Logger.LogInformation($"Not copying webCRM delivery with ID {webcrmDelivery.DeliveryId} to PowerOffice because the corresponding PowerOffice organisation could not be found.");
                    return;
                }

                Logger.LogTrace("Copying delivery to PowerOffice, updating an existing one.");
                matchingPowerofficeDelivery.UpdateIncludingLines(webcrmDelivery, webcrmDeliveryLines, powerofficeCustomerCode.Value, Configuration.ProductCodeFieldName);
                await PowerofficeClient.UpdateInvoice(matchingPowerofficeDelivery);
            }
        }
예제 #25
0
        public NewOutgoingInvoice(
            DeliveryDto webcrmDelivery,
            List <QuotationLineDto> webcrmDeliveryLines,
            long powerofficeCustomerCode,
            string productCodeFieldName)
            : this()
        {
            UpdateExcludingLines(webcrmDelivery, powerofficeCustomerCode);

            OutgoingInvoiceLines = webcrmDeliveryLines
                                   .Select(webcrmLine => new OutgoingInvoiceLine(webcrmLine, productCodeFieldName))
                                   .ToList();
        }
예제 #26
0
 private void UpdateOrderStatus(DeliveryDto deliveryDto)
 {
     if (deliveryDto.OrderId != null)
     {
         var order = orderService.Get(deliveryDto.OrderId.Value);
         if (order != null)
         {
             var orderDto = Mapper.Map <OrderDto>(order);
             order.OrderStatusId = orderDto.CalculatedStatusId;
             orderService.Update(order);
         }
     }
 }
 public ActionResult Save(DeliveryDto model)
 {
     if (ModelState.IsValid)
     {
         var Delivery = new Delivery();
         _Delivery.Save(model);
         return(RedirectToAction("List"));
     }
     else
     {
         return(RedirectToAction("Create", model));
     }
 }
예제 #28
0
        public async Task <DeliveryDto> Update(DeliveryDto deliveryDto)
        {
            try
            {
                var delivery = _mapper.Map <Delivery>(deliveryDto);
                var result   = await _service.Update(delivery);

                return(_mapper.Map <DeliveryDto>(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #29
0
 public ComprobanteDelivery(IDeliveryServicio deliveryServicio,
                            IArticuloServicio articuloServicio,
                            IEmpleadoServicio empleadoServicio,
                            IClienteServicio clienteServicio)
 {
     if (comprobante == null)
     {
         comprobante = new DeliveryDto();
     }
     _clienteServicio  = clienteServicio;
     _deliveryServicio = deliveryServicio;
     _empleadoServicio = empleadoServicio;
     _articuloServicio = articuloServicio;
 }
예제 #30
0
 public static Delivery CreateEntity(this DeliveryDto deliveryDto)
 {
     return(new Delivery()
     {
         DeliveryId = deliveryDto.deliveryId,
         DateDelivery = deliveryDto.dateDelivery,
         ClientId = deliveryDto.clientId,
         ProductType = deliveryDto.productType,
         QuantityProduct = deliveryDto.quantityProduct,
         DeliveriesTruckTips = deliveryDto.deliveriesTruckTips?.CreateEntity(),
         Client = deliveryDto.client?.CreateEntity(),
         Address = deliveryDto.address?.CreateEntity()
     });
 }