private Tuple <string, int> GetDocumentNo(VBRequestDocumentNonPOFormDto form, VBRequestDocumentModel existingData)
        {
            var now   = form.Date.GetValueOrDefault().AddHours(_identityService.TimezoneOffset);
            var year  = now.ToString("yy");
            var month = now.ToString("MM");


            //var unit = model.UnitCode.ToString().Split(" - ");

            var unitCode = "T";

            if (form.SuppliantUnit.Division.Name.ToUpper() == "GARMENT")
            {
                unitCode = "G";
            }


            var documentNo = $"VB-{unitCode}-{month}{year}-";

            var index = 1;

            if (existingData != null)
            {
                index = existingData.Index + 1;
            }

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

            //var countSameDocumentNo = _dbContext.VBRequestDocuments.IgnoreQueryFilters().Where(a => a.Date.AddHours(_identityService.TimezoneOffset).Month == form.Date.GetValueOrDefault().AddHours(_identityService.TimezoneOffset).Month).Count();

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

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

            return(new Tuple <string, int>(documentNo, index));
        }
        //public int CreateNonPO(VBRequestDocumentNonPOFormDto form)
        public async Task <int> CreateNonPO(VBRequestDocumentNonPOFormDto form)
        {
            var internalTransaction = _dbContext.Database.CurrentTransaction == null;
            var transaction         = !internalTransaction ? _dbContext.Database.CurrentTransaction : _dbContext.Database.BeginTransaction();

            try
            {
                var unitCode     = GetDocumentUnitCode(form.SuppliantUnit.Division.Name.ToUpper(), form.IsInklaring);
                var existingData = _dbContext.VBRequestDocuments.Where(a => a.Date.AddHours(_identityService.TimezoneOffset).Month == form.Date.GetValueOrDefault().AddHours(_identityService.TimezoneOffset).Month&& a.DocumentNo.StartsWith(unitCode)).OrderByDescending(s => s.Index).FirstOrDefault();
                var documentNo   = GetDocumentNo(form, existingData);
                var model        = new VBRequestDocumentModel(
                    documentNo.Item1,
                    form.Date.GetValueOrDefault(),
                    form.RealizationEstimationDate.GetValueOrDefault(),
                    form.SuppliantUnit.Id.GetValueOrDefault(),
                    form.SuppliantUnit.Code,
                    form.SuppliantUnit.Name,
                    form.SuppliantUnit.Division.Id.GetValueOrDefault(),
                    form.SuppliantUnit.Division.Code,
                    form.SuppliantUnit.Division.Name,
                    form.Currency.Id.GetValueOrDefault(),
                    form.Currency.Code,
                    form.Currency.Symbol,
                    form.Currency.Description,
                    form.Currency.Rate.GetValueOrDefault(),
                    form.Purpose,
                    form.Amount.GetValueOrDefault(),
                    false,
                    false,
                    VBType.NonPO,
                    documentNo.Item2,
                    form.IsInklaring,
                    form.NoBL,
                    form.NoPO,
                    null
                    );

                model.FlagForCreate(_identityService.Username, UserAgent);
                _dbContext.VBRequestDocuments.Add(model);
                await _dbContext.SaveChangesAsync();

                var items = AddNonPOItems(model.Id, form.Items);

                _dbContext.VBRequestDocumentItems.AddRange(items);
                await _dbContext.SaveChangesAsync();

                if (internalTransaction)
                {
                    transaction.Commit();
                }

                return(model.Id);
            }
            catch (Exception ex)
            {
                if (internalTransaction)
                {
                    transaction.Rollback();
                }
                throw ex;
            }
        }