コード例 #1
0
        public async Task <int> Add(AddSalesInvoiceDto dto)
        {
            await CheckExistsByNumber(dto.InvoiceNumber);

            var salesInvoice = new SalesInvoice()
            {
                InvoiceDate   = DateTime.Now,
                CustomerName  = dto.CustomerName,
                InvoiceNumber = dto.InvoiceNumber
            };

            decimal totalPrice = 0;
            var     selasItems = new HashSet <SalesItem>();

            foreach (var item in dto.SalesItemDto)
            {
                var warehouse = await _warehouseRepository.FindByGoodCode(item.GoodCode);

                CheckExistsGoodInWarehouse(warehouse);
                CheckStockInWarehouse(warehouse.Count, item.Count);
                selasItems.Add(new SalesItem
                {
                    Count     = item.Count,
                    InvoiceId = salesInvoice.Id,
                    Price     = item.Price,
                    GoodId    = warehouse.GoodId,
                });
                totalPrice      += (item.Price * item.Count);
                warehouse.Count -= item.Count;
            }
            salesInvoice.SalesItems = selasItems;

            var accounting = new HashSet <AccountingDocument>()
            {
                new AccountingDocument()
                {
                    InvoiceId      = salesInvoice.Id,
                    DateOfDocument = DateTime.Now,
                    DocumentNumber = DateTime.Now.ToShortDateString(),
                    InvoiceNumber  = dto.InvoiceNumber,
                    Totalprice     = totalPrice
                }
            };

            salesInvoice.AccountingDocuments = accounting;
            _repository.Add(salesInvoice);
            _unitOfWork.Complate();
            return(salesInvoice.Id);
        }
コード例 #2
0
 public async Task <int> Add(AddSalesInvoiceDto dto)
 {
     return(await _services.Add(dto));
 }