Exemple #1
0
 public void AddReceivingItemAsync(ReceivingItem receivingItem)
 {
     _context.ReceivingItems.Add(receivingItem);
 }
Exemple #2
0
 public void UpdateReceivingItem(ReceivingItem receivingItem)
 {
     _context.Entry(receivingItem).State = EntityState.Modified;
 }
Exemple #3
0
        public async Task <ActionResult <GetReceivingHeaderDto> > GetROExist([FromQuery] ReceivingOrderDto receiving)
        {
            var vender = await _venderRepository.GetVenderByNumber(receiving.VenderNo.ToUpper());

            var shippingNo = await _shippingRepository.GetShippingByNumber(receiving.ShippingNumber.ToUpper());

            var po = await _erpRepository.GetReceivingByPO(receiving.PONumber.ToUpper());

            if (vender == null)
            {
                return(BadRequest("Vender does not exist."));
            }

            if (shippingNo == null)
            {
                return(BadRequest("Shipping Number does not exist."));
            }

            if (po == null)
            {
                return(BadRequest("Purchase Order does not exist."));
            }

            var roNumber = "RO" + receiving.PONumber + receiving.ShippingNumber + receiving.VenderNo;

            if (await _receivingRepository.ROExist(roNumber))
            {
                return(BadRequest("RO Number already Exist"));
            }

            var getReceiving = new Receiving
            {
                PONumber       = receiving.PONumber,
                RONumber       = roNumber,
                ShippingNumber = receiving.ShippingNumber,
                LotNumber      = shippingNo.ShippingLot.LotNumber,
                VenderNo       = receiving.VenderNo,
                UserEmail      = receiving.UserEmail,
                // CreateDate
                Status = "DRAFT",
                // GetReceivingItemDtos = getReceivingItemDtos,
                OrderDate = po.OrderDate,
                // Shipping = shippingNo,
            };

            _receivingRepository.AddReceivingAsync(getReceiving);

            if (await _receivingRepository.SaveAllAsync() == false)
            {
                return(BadRequest("Failed to add Receiving Order."));
            }

            var poItem = await _erpRepository.GetReceivingItemByPO(receiving.PONumber.ToUpper());

            var rec = await _receivingRepository.GetReceivingByROAsync(getReceiving.RONumber);

            // if (shippingNo == null)
            //     return BadRequest("Shipping Number does not exist.");

            if (poItem == null)
            {
                return(BadRequest("PO item not found"));
            }

            List <ReceivingItem> roItems = new List <ReceivingItem>();

            foreach (ERP_POitem element in poItem)
            {
                var item = await _itemRepository.GetItemByNumber(element.ItemNumber.ToUpper());

                if (item == null)
                {
                    return(BadRequest("Item Not Found in database"));
                }
                // Console.WriteLine(item.ItemDescription);

                var roItem = new ReceivingItem
                {
                    LotNumber       = shippingNo.ShippingLot.LotNumber,
                    ItemNumber      = element.ItemNumber,
                    ItemDescription = item.ItemDescription,
                    OrderQty        = element.OrderQty,
                    Receiving       = rec
                };
                roItems.Add(roItem);
                _receivingItemRepository.AddReceivingItemAsync(roItem);
            }

            if (await _receivingItemRepository.SaveAllAsync() == false)
            {
                return(BadRequest("Failed to add Receiving Item."));
            }

            getReceiving.ReceivingItems = roItems;


            _receivingRepository.UpdateReceiving(getReceiving);

            if (await _receivingRepository.SaveAllAsync() == false)
            {
                return(BadRequest("Failed to add Receiving Order."));
            }

            return(Ok(_mapper.Map <GetReceivingHeaderDto>(getReceiving)));
        }