public async Task <int> CreateAsync(RealizationVbModel model, RealizationVbWithPOViewModel viewmodel)
        {
            model.VBNoRealize = GetVbRealizePoNo(model);

            var updateTotalRequestVb = _dbContext.VbRequests.FirstOrDefault(x => x.VBNo == model.VBNo && x.IsDeleted == false);

            if (updateTotalRequestVb != null)
            {
                model.RequestVbName = viewmodel.numberVB.CreateBy;
                updateTotalRequestVb.Realization_Status = true;
            }

            decimal totalAmount = 0;

            foreach (var item1 in viewmodel.Items)
            {
                foreach (var item2 in item1.item)
                {
                    var temp = item2.unitReceiptNote;

                    foreach (var item3 in temp.items)
                    {
                        totalAmount += item3.PriceTotal;
                    }
                }
            }
            ;

            model.Amount            = totalAmount;
            model.VBRealizeCategory = "PO";
            model.isVerified        = false;
            model.isClosed          = false;
            model.isNotVeridied     = false;

            EntityExtension.FlagForCreate(model, _identityService.Username, UserAgent);

            _dbContext.RealizationVbs.Add(model);

            //return _dbContext.SaveChangesAsync();

            await _dbContext.SaveChangesAsync();

            return(await _iVBRealizationDocumentExpeditionService.InitializeExpedition(model.Id));
        }
        private string GetVbRealizePoNo(RealizationVbModel model)
        {
            var now   = model.Date.LocalDateTime;
            var year  = now.ToString("yy");
            var month = now.ToString("MM");

            var documentNo = $"R-{month}{year}-";

            var countSameDocumentNo = _dbContext.RealizationVbs.Where(a => a.Date.Month == model.Date.Month).Count();

            if (countSameDocumentNo >= 0)
            {
                countSameDocumentNo += 1;

                documentNo += string.Format("{0:000}", countSameDocumentNo);
            }

            return(documentNo);
        }