예제 #1
0
        public Response Add(InvitemInfoDto invitemInfo)
        {
            Response response = new Response();

            try
            {
                var inventory = _inventory.GetInventory(invitemInfo.ProductId);
                if (inventory - invitemInfo.Count >= 0)
                {
                    AddInvitem(invitemInfo);
                    response.Message = "ثبت با موفقیت انجام شد";
                }
                else
                {
                    response.IsSuccess = false;
                    response.Errors    = new Error("", "موجودی ناکافی");
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                response.Errors    = new Error("", "خطا در ثبت اطلاعات");
            }
            return(response);
        }
예제 #2
0
 public Response Post(InvitemInfoDto model)
 {
     if (ModelState.IsValid)
     {
         return(_invItemService.Add(model));
     }
     return(new Response
     {
         IsSuccess = false,
         Errors = new Error("", "اطلاعات ورودی صحیح نمی باشد"),
     });
 }
예제 #3
0
        private void AddAccountingDocument(InvitemInfoDto invitemInfo, long invitmId)
        {
            var totalprice    = _invitemRepository.CalculateSumPrice(invitmId);
            var accountingDoc = _accountingDocument.GetByInvitemId(invitmId);

            if (accountingDoc is null)
            {
                var MaxdocNo = _accountingDocument.GetMaxdocNo();
                var docNo    = (Convert.ToInt64(MaxdocNo) + 1);

                var accountingDocument = _mapper.Map <AccountingDocument>(new AccountingDocDto
                {
                    DocNo = docNo.ToString(), Date = DateTime.Now, Price = totalprice, InvitemId = invitmId
                });
                _accountingDocument.Add(accountingDocument);
            }
            else
            {
                accountingDoc.Price = totalprice;
                _accountingDocument.Update(accountingDoc);
            }
        }
예제 #4
0
        private void AddInvitem(InvitemInfoDto invitemInfo)
        {
            long invitmId = _invitemRepository.GetByCode(invitemInfo.InvitemNo)?.Id ?? 0;

            if (invitmId == 0)
            {
                var model = _mapper.Map <Invitem>(new InvitemDto
                {
                    InvitemNo = invitemInfo.InvitemNo, InvitemDate = invitemInfo.InvitemDate, CustomerId = invitemInfo.CustomerId
                });
                invitmId = (long)_invitemRepository.Add(model);
            }
            if (invitmId > 0)
            {
                var detailmodel = _mapper.Map <InvitemDetail>(new InvitemDetailDto
                {
                    Count = invitemInfo.Count, Price = invitemInfo.Price, Date = invitemInfo.InvitemDate, InvitemId = invitmId, ProductId = invitemInfo.ProductId
                });
                _invitemRepository.AddInvitemDetails(detailmodel);
                AddAccountingDocument(invitemInfo, invitmId);
            }
        }