Esempio n. 1
0
        public async Task <ActionResult> CreateDebitMemo(CreateDebitMemoDto dto)
        {
            await _debitMemoService.CreateAsync(dto);

            if (dto.Warehouse == "Main")
            {
                foreach (var items in dto.DebitMemoDetails)
                {
                    var check = await _stockService.CheckIfExist(items.ProductId);

                    if (check != null)
                    {
                        check.TotalPieces -= items.TotalPieces;
                        check.Amount      -= items.Amount;
                        await _stockService.UpdateAsync(check);
                    }
                }
            }
            else
            {
                foreach (var items in dto.DebitMemoDetails)
                {
                    var check = await _badStockService.CheckIfExist(items.ProductId);

                    if (check != null)
                    {
                        check.TotalPieces -= items.TotalPieces;
                        check.Amount      -= items.Amount;
                        await _badStockService.UpdateAsync(check);
                    }
                }
            }
            return(Ok(dto));
        }
Esempio n. 2
0
        public async Task <ActionResult> CreatePurchaseOrder(CreatePurchaseOrderDto dto)
        {
            await _purchaseOderService.CreateAsync(dto);

            foreach (var items in dto.PurchaseOrderDetails)
            {
                var check = await _stockService.CheckIfExist(items.ProductId);

                if (check != null)
                {
                    check.TotalPieces += items.TotalPieces;
                    check.Amount      += items.Amount;
                    await _stockService.UpdateAsync(check);
                }
                else
                {
                    var stocks = new StockDto
                    {
                        ProductId     = items.ProductId,
                        TotalPieces   = items.TotalPieces,
                        PricePerPiece = items.PricePerPiece,
                        Amount        = items.Amount
                    };

                    await _stockService.CreateAsync(stocks);
                }
            }

            return(Ok(dto));
        }
        public async Task <ActionResult> CreateUnload(CreateUnloadDto dto)
        {
            var created = await _unloadService.CreateAsync(dto);

            foreach (var items in dto.UnloadDetails)
            {
                var check = await _vanStockService.CheckIfExist(items.ProductId, dto.VanId);

                var check2 = await _stockService.CheckIfExist(items.ProductId);

                if (check2 != null)
                {
                    check2.TotalPieces += items.TotalPieces;
                    check2.Amount      += items.Amount;
                    await _stockService.UpdateAsync(check2);
                }

                if (check != null)
                {
                    check.TotalPieces -= items.TotalPieces;
                    check.Amount      -= items.Amount;
                    await _vanStockService.UpdateAsync(check);
                }
            }

            return(Ok(created));
        }
        public async Task <ActionResult> CreateStocks(CreateStockDto input)
        {
            foreach (var items in input.Stocks)
            {
                var check = await _stockService.CheckIfExist(items.ProductId);

                if (check != null)
                {
                    check.TotalPieces += items.TotalPieces;
                    check.Amount      += items.Amount;

                    await _stockService.UpdateAsync(check);
                }
                else
                {
                    var stocks = new StockDto
                    {
                        ProductId     = items.ProductId,
                        TotalPieces   = items.TotalPieces,
                        PricePerPiece = items.PricePerPiece,
                        Amount        = items.Amount
                    };

                    await _stockService.CreateAsync(stocks);
                }
            }
            return(Ok(input.Stocks));
        }
        public async Task <ActionResult> CreateCreditMemo(CreateCreditMemoDto dto)
        {
            await _creditMemoAppService.CreateAsync(dto);

            if (dto.CreditMemoMode == "Good")
            {
                foreach (var items in dto.CreditMemoDetails)
                {
                    var check = await _stockService.CheckIfExist(items.ProductId);

                    if (check != null)
                    {
                        check.TotalPieces += items.TotalPieces;
                        check.Amount      += items.Amount;
                        await _stockService.UpdateAsync(check);
                    }
                }
            }
            else
            {
                foreach (var items in dto.CreditMemoDetails)
                {
                    var check = await _badStockService.CheckIfExist(items.ProductId);

                    if (check != null)
                    {
                        check.TotalPieces += items.TotalPieces;
                        check.Amount      += items.Amount;
                        await _badStockService.UpdateAsync(check);
                    }
                    else
                    {
                        var stocks = new BadStockDto
                        {
                            ProductId     = items.ProductId,
                            TotalPieces   = items.TotalPieces,
                            PricePerPiece = items.PricePerPiece,
                            Amount        = items.Amount
                        };

                        await _badStockService.CreateAsync(stocks);
                    }
                }
            }
            return(Ok(dto));
        }
Esempio n. 6
0
        public async Task <ActionResult> CreateInvoice(CreateInvoiceDto dto)
        {
            await _invoiceAppService.CreateAsync(dto);

            foreach (var items in dto.InvoiceDetails)
            {
                var check = await _stockService.CheckIfExist(items.ProductId);

                if (check != null)
                {
                    check.TotalPieces -= items.TotalPieces;
                    check.Amount      -= items.Amount;
                    await _stockService.UpdateAsync(check);
                }
            }

            return(Ok(dto));
        }
Esempio n. 7
0
        public async Task <ActionResult> CreateWithdrawal(CreateWithdrawalDto dto)
        {
            var created = await _withdrawalService.CreateAsync(dto);

            foreach (var items in dto.WithdrawalDetails)
            {
                var check = await _vanStockService.CheckIfExist(items.ProductId, dto.VanId);

                var check2 = await _stockService.CheckIfExist(items.ProductId);

                if (check2 != null)
                {
                    check2.TotalPieces -= items.TotalPieces;
                    check2.Amount      -= items.Amount;
                    await _stockService.UpdateAsync(check2);
                }

                if (check != null)
                {
                    check.TotalPieces += items.TotalPieces;
                    check.Amount      += items.Amount;
                    await _vanStockService.UpdateAsync(check);
                }
                else
                {
                    var stocks = new VanStockDto
                    {
                        ProductId     = items.ProductId,
                        TotalPieces   = items.TotalPieces,
                        PricePerPiece = items.PricePerPiece,
                        Amount        = items.Amount,
                        VanId         = dto.VanId
                    };
                    await _vanStockService.CreateAsync(stocks);
                }
            }

            return(Ok(created));
        }