Esempio n. 1
0
 public static InvoiceDetail FromDto(InvoiceDetailDto dto)
 => new InvoiceDetail(new Code(dto.ProductCode)
                      , new Name(dto.ProductDescription)
                      , dto.Qty
                      , dto.Amount
                      , dto.TaxPercent
                      , null);
Esempio n. 2
0
        public async Task <ContentResult> GetInvoiceItem(GetInvoiceInput input)
        {
            try
            {
                List <ExtraDto> extralist = new List <ExtraDto>();
                ReturnMessage   rm        = new ReturnMessage(1, "Success");
                var             invoices  = await Task.Run(() => _unitOfWork.Invoices.GetAsync(filter: w => input.Id != 0 ? (w.Id == input.Id) : true, includeProperties: "Customer,Booking"));

                var invoicesToReturn = _mapper.Map <IEnumerable <InvoiceDto> >(invoices);
                //  var extra = _unitOfWork.BookingExtras.Find(x => x.BookingId == invoices.First().Booking.Id);
                var extra = await Task.Run(() => _unitOfWork.BookingExtras.GetAsync(filter: w => w.BookingId == invoices.First().BookingId, includeProperties: "Extra"));

                var cars = await Task.Run(() => _unitOfWork.Cars.GetAsync(filter: w => w.Id == invoices.First().Booking.CarId, includeProperties: "CarClassification"));

                var        car        = _mapper.Map <IEnumerable <CarDto> >(cars).First();
                var        payment    = _unitOfWork.Payments.Find(x => x.InvoiceId == input.Id).SingleOrDefault();
                PaymentDto paymentDto = _mapper.Map <PaymentDto>(payment);
                if (paymentDto != null)
                {
                    paymentDto.PaymentType = ((Utility.PaymentType)Convert.ToInt32(paymentDto.PaymentType)).ToString();
                }
                foreach (var item in extra)
                {
                    var extraDto = _mapper.Map <ExtraDto>(item.Extra);
                    extraDto.Count = item.Count ?? 0;
                    extralist.Add(extraDto);
                }
                InvoiceDetailDto invoiceDetail = new InvoiceDetailDto()
                {
                    Invoice          = invoicesToReturn.First(),
                    InvoiceId        = invoicesToReturn.First().Id,
                    Booking          = invoicesToReturn.First().Booking,
                    BookingExtraList = extralist,
                    Car     = car,
                    Payment = paymentDto
                };

                List <InvoiceDetailDto> invoicedetailList = new List <InvoiceDetailDto>();
                invoicedetailList.Add(invoiceDetail);

                return(this.Content(rm.returnMessage(new PagedResultDto <InvoiceDetailDto>
                                                         (invoicedetailList.AsQueryable(), input.pagenumber, input.pagesize)),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                return(this.Content(JsonConvert.SerializeObject(new
                {
                    msgCode = -3,
                    msg = ex.Message
                }), "application/json"));
            }
        }
Esempio n. 3
0
    public async Task <ActionResult> Post([FromBody] InvoiceDetailDto itemDto)
    {
        if (itemDto == null)
        {
            return(await Task.Run(() => BadRequest()));
        }

        itemDto.Created = DateTime.Now;

        var item = _mapper.Map <InvoiceDetail>(itemDto);

        _context.InvoiceDetails.Add(item);
        _context.SaveChanges();

        itemDto = _mapper.Map <InvoiceDetailDto>(item);
        return(await Task.Run(() => new ObjectResult(itemDto)));
    }
        public IHttpActionResult GetInvoiceDetail([FromUri] int invoiceDetailId)
        {
            var invoiceDetailIdInDb = _context.InvoiceDetails.Find(invoiceDetailId);

            var invoiceDetailDto = new InvoiceDetailDto
            {
                DateOfCost   = invoiceDetailIdInDb.DateOfCost,
                Activity     = invoiceDetailIdInDb.Activity,
                ChargingType = invoiceDetailIdInDb.ChargingType,
                Cost         = invoiceDetailIdInDb.Cost,
                Rate         = invoiceDetailIdInDb.Rate,
                Quantity     = invoiceDetailIdInDb.Quantity,
                Memo         = invoiceDetailIdInDb.Memo,
                Amount       = invoiceDetailIdInDb.Amount,
                Unit         = invoiceDetailIdInDb.Unit
            };

            return(Ok(invoiceDetailDto));
        }
Esempio n. 5
0
    public async Task <ActionResult> Put(int id, [FromBody] InvoiceDetailDto itemDto)
    {
        if (itemDto == null)
        {
            return(await Task.Run(() => BadRequest()));
        }

        var item = _context.InvoiceDetails
                   .SingleOrDefault(e => e.Id == id);

        if (item == null)
        {
            return(await Task.Run(() => NotFound()));
        }

        item = _mapper.Map(itemDto, item);
        _context.SaveChanges();

        return(await Task.Run(() => new ObjectResult(itemDto)));
    }
Esempio n. 6
0
        public async Task <ActionResult> EditInvoice(InvoiceHeaderDto dto)
        {
            foreach (var dtoItem in dto.InvoiceDetails)
            {
                var check = await _stockService.CheckIfExist(dtoItem.ProductId);

                var old = await _invoiceDetailsAppService.GetDetailsAsync(dtoItem.Id);

                if (old != null)
                {
                    if (dtoItem.TotalPieces > old.TotalPieces)
                    {
                        var change  = dtoItem.TotalPieces - old.TotalPieces;
                        var tAmount = dtoItem.PricePerPiece * change;
                        check.TotalPieces -= change;
                        check.Amount      -= tAmount;

                        await _stockService.UpdateAsync(check);
                    }
                    else if (dtoItem.TotalPieces < old.TotalPieces)
                    {
                        var change  = old.TotalPieces - dtoItem.TotalPieces;
                        var tAmount = dtoItem.PricePerPiece * change;
                        check.TotalPieces += change;
                        check.Amount      += tAmount;

                        await _stockService.UpdateAsync(check);
                    }
                }
                else
                {
                    check.TotalPieces -= dtoItem.TotalPieces;
                    check.Amount      -= dtoItem.Amount;

                    await _stockService.UpdateAsync(check);
                }
            }
            var updated = await _invoiceAppService.UpdateAsync(dto);

            foreach (var items in dto.InvoiceDetails)
            {
                var getCheck = await _invoiceDetailsAppService.GetAsync(new EntityDto <int>(items.Id));

                if (getCheck == null)
                {
                    var toCreate = new InvoiceDetailDto
                    {
                        InvoiceHeaderId   = dto.InvoiceId,
                        ProductId         = items.ProductId,
                        Case              = items.Case,
                        ProdCase          = items.ProdCase,
                        Box               = items.Box,
                        ProdPiece         = items.ProdPiece,
                        Piece             = items.Piece,
                        Gross             = items.Gross,
                        Discount          = items.Discount,
                        Net               = items.Net,
                        TotalProductPrice = items.TotalProductPrice,
                    };
                    await _invoiceDetailsAppService.CreateAsync(toCreate);
                }
                else if (getCheck != null)
                {
                    var toUpdate = new InvoiceDetailDto
                    {
                        Id                = items.Id,
                        CreationTime      = items.CreationTime,
                        CreatorUserId     = items.CreatorUserId,
                        TenantId          = items.TenantId,
                        InvoiceHeaderId   = items.InvoiceHeaderId,
                        ProductId         = items.ProductId,
                        Case              = items.Case,
                        ProdCase          = items.ProdCase,
                        Box               = items.Box,
                        ProdPiece         = items.ProdPiece,
                        Piece             = items.Piece,
                        Gross             = items.Gross,
                        Discount          = items.Discount,
                        Net               = items.Net,
                        TotalProductPrice = items.TotalProductPrice,
                    };
                    await _invoiceDetailsAppService.UpdateAsync(toUpdate);
                }
            }

            return(Ok(updated));
        }
Esempio n. 7
0
 public void DeleteDetailById(InvoiceDetailDto Detail)
 {
     _manager.DeleteDetailById(_transform.Transform <InvoiceDetailDto, InvoiceDetail>(Detail));
 }
Esempio n. 8
0
 public void SaveDetails(InvoiceDetailDto Detail)
 {
     _manager.AddDetail(_transform.Transform <InvoiceDetailDto, InvoiceDetail>(Detail));
 }