Ejemplo n.º 1
0
        public List <MaterialDistributionNoteDetail> GetNewData(MaterialsRequestNote materialsRequestNote)
        {
            List <MaterialDistributionNoteDetail> list = new List <MaterialDistributionNoteDetail>();
            SupplierViewModel supplier = SupplierDataUtil.GetSupplier(client);

            foreach (MaterialsRequestNote_Item item in materialsRequestNote.MaterialsRequestNote_Items)
            {
                MaterialDistributionNoteDetail detail = new MaterialDistributionNoteDetail();
                detail.MaterialsRequestNoteItemId = item.Id;
                detail.ProductionOrderId          = item.ProductionOrderId;
                detail.ProductionOrderNo          = item.ProductionOrderNo;
                detail.ProductionOrderIsCompleted = item.ProductionOrderIsCompleted;
                detail.ProductId   = item.ProductId;
                detail.ProductCode = item.ProductCode;
                detail.ProductName = item.ProductName;
                detail.Grade       = item.Grade;
                detail.Quantity    = 1;
                detail.MaterialRequestNoteItemLength = item.Length;
                detail.ReceivedLength = 1;
                detail.IsDisposition  = false;
                detail.IsCompleted    = false;
                detail.SupplierId     = supplier._id;
                detail.SupplierCode   = supplier.code;
                detail.SupplierName   = supplier.name;

                list.Add(detail);
            }

            return(list);
        }
Ejemplo n.º 2
0
        public async Task <MaterialsRequestNote> CustomCodeGenerator(MaterialsRequestNote model)
        {
            model.Type = string.Equals(model.UnitName.ToUpper(), "PRINTING") ? "P" : "F";
            var lastData = await _dbSet.Where(w => w.UnitCode == model.UnitCode).OrderByDescending(o => o.CreatedUtc).FirstOrDefaultAsync();

            DateTime Now   = DateTime.Now;
            string   year  = Now.ToString("yy");
            string   month = Now.ToString("MM");

            if (lastData == null)
            {
                model.AutoIncrementNumber = 1;
                string number = model.AutoIncrementNumber.ToString().PadLeft(4, '0');
                model.Code = $"SPB{model.Type}{month}{year}{number}";
            }
            else
            {
                if (lastData.CreatedUtc.Year < Now.Year)
                {
                    model.AutoIncrementNumber = 1;
                    string number = model.AutoIncrementNumber.ToString().PadLeft(4, '0');
                    model.Code = $"SPB{model.Type}{month}{year}{number}";
                }
                else
                {
                    model.AutoIncrementNumber = lastData.AutoIncrementNumber + 1;
                    string number = model.AutoIncrementNumber.ToString().PadLeft(4, '0');
                    model.Code = $"SPB{model.Type}{month}{year}{number}";
                }
            }

            return(model);
        }
        public MaterialsRequestNote GetNewData()
        {
            MaterialsRequestNote TestData = new MaterialsRequestNote
            {
                UnitId        = "1",
                UnitCode      = "a",
                UnitName      = "name",
                Remark        = "",
                RequestType   = "AWAL",
                IsDistributed = false,
                IsCompleted   = false,
                MaterialsRequestNote_Items = new List <MaterialsRequestNote_Item> {
                    new MaterialsRequestNote_Item()
                    {
                        Grade                      = "a",
                        Length                     = 1,
                        OrderQuantity              = 1,
                        OrderTypeCode              = "code",
                        OrderTypeId                = "1",
                        OrderTypeName              = "name",
                        ProductCode                = "code",
                        ProductionOrderNo          = "c",
                        Remark                     = "a",
                        ProductId                  = "1",
                        ProductionOrderId          = "1",
                        ProductionOrderIsCompleted = true,
                        ProductName                = "name"
                    }
                }
            };

            return(TestData);
        }
Ejemplo n.º 4
0
        public override async Task <int> CreateModel(MaterialDistributionNote Model)
        {
            int Created = 0;

            using (var transaction = this.DbContext.Database.BeginTransaction())
            {
                try
                {
                    Model = await this.CustomCodeGenerator(Model);

                    Created = await this.CreateAsync(Model);

                    MaterialsRequestNoteService      materialsRequestNoteService      = ServiceProvider.GetService <MaterialsRequestNoteService>();
                    MaterialsRequestNote_ItemService materialsRequestNote_ItemService = ServiceProvider.GetService <MaterialsRequestNote_ItemService>();
                    materialsRequestNoteService.Username      = Username;
                    materialsRequestNoteService.Token         = Token;
                    materialsRequestNote_ItemService.Username = Username;

                    foreach (MaterialDistributionNoteItem materialDistributionNoteItem in Model.MaterialDistributionNoteItems)
                    {
                        MaterialsRequestNote materialsRequestNote = await materialsRequestNoteService.ReadModelById(materialDistributionNoteItem.MaterialRequestNoteId);

                        materialsRequestNote.IsDistributed = true;

                        if (Model.Type.ToUpper().Equals("PRODUKSI"))
                        {
                            foreach (MaterialDistributionNoteDetail materialDistributionNoteDetail in materialDistributionNoteItem.MaterialDistributionNoteDetails)
                            {
                                materialsRequestNote.MaterialsRequestNote_Items.Where(w => w.ProductionOrderId.Equals(materialDistributionNoteDetail.ProductionOrderId)).Select(s => { s.DistributedLength += materialDistributionNoteDetail.ReceivedLength; return(s); }).ToList();
                            }
                            materialsRequestNoteService.UpdateDistributedQuantity(materialsRequestNote.Id, materialsRequestNote);

                            foreach (MaterialsRequestNote_Item materialRequestNoteItem in materialsRequestNote.MaterialsRequestNote_Items)
                            {
                                materialsRequestNote_ItemService.OnUpdating(materialRequestNoteItem.Id, materialRequestNoteItem);
                                materialsRequestNote_ItemService.DbSet.Update(materialRequestNoteItem);
                            }
                        }

                        materialsRequestNoteService.OnUpdating(materialsRequestNote.Id, materialsRequestNote);
                        materialsRequestNoteService.DbSet.Update(materialsRequestNote);
                    }
                    DbContext.SaveChanges();

                    CreateInventoryDocument(Model, "OUT");
                    transaction.Commit();
                }
                catch (ServiceValidationExeption e)
                {
                    transaction.Rollback();
                    throw new ServiceValidationExeption(e.ValidationContext, e.ValidationResults);
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new ServiceValidationExeption(null, null);
                }
            }
            return(Created);
        }
Ejemplo n.º 5
0
        public async Task <int> CreateAsync(MaterialsRequestNote model)
        {
            int created = 0;

            using (var transaction = _inventoryDbContext.Database.BeginTransaction())
            {
                try
                {
                    List <string> productionOrderIds = new List <string>();
                    model = await CustomCodeGenerator(model);

                    model.FlagForCreate(_identityInterface.Username, UserAgent);
                    model.FlagForUpdate(_identityInterface.Username, UserAgent);
                    foreach (var item in model.MaterialsRequestNoteItems)
                    {
                        item.FlagForCreate(_identityInterface.Username, UserAgent);
                        item.FlagForUpdate(_identityInterface.Username, UserAgent);
                        productionOrderIds.Add(item.ProductionOrderId);
                    }
                    _dbSet.Add(model);

                    created = await _inventoryDbContext.SaveChangesAsync();

                    UpdateIsRequestedProductionOrder(productionOrderIds, "CREATE");
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw e;
                }
            }
            return(created);
        }
Ejemplo n.º 6
0
        public async Task <MaterialsRequestNote> GetTestData()
        {
            MaterialsRequestNote data = GetNewData();
            await _materialRequestNoteRepository.CreateAsync(data);

            return(data);
        }
        public async Task <MaterialsRequestNote> GetTestData()
        {
            MaterialsRequestNote Data = GetNewData();

            await this.Service.CreateAsync(Data);

            return(Data);
        }
Ejemplo n.º 8
0
        public async Task <int> DeleteAsync(int id)
        {
            int count = 0;

            using (var trans = _inventoryDbContext.Database.BeginTransaction())
            {
                try
                {
                    MaterialDistributionNote materialDistributionNote = await ReadByIdAsync(id);

                    materialDistributionNote.FlagForDelete(_identityInterface.Username, UserAgent);
                    foreach (var item in materialDistributionNote.MaterialDistributionNoteItems)
                    {
                        item.FlagForDelete(_identityInterface.Username, UserAgent);

                        foreach (var detail in item.MaterialDistributionNoteDetails)
                        {
                            detail.FlagForDelete(_identityInterface.Username, UserAgent);
                        }
                    }

                    count = await _inventoryDbContext.SaveChangesAsync();

                    IMaterialRequestNoteRepository materialsRequestNoteService = _serviceProvider.GetService <IMaterialRequestNoteRepository>();

                    foreach (MaterialDistributionNoteItem materialDistributionNoteItem in materialDistributionNote.MaterialDistributionNoteItems)
                    {
                        MaterialsRequestNote materialsRequestNote = await materialsRequestNoteService.ReadByIdAsync(materialDistributionNoteItem.MaterialRequestNoteId);

                        materialsRequestNote.IsDistributed = true;

                        if (materialDistributionNote.Type.ToUpper().Equals("PRODUCTION"))
                        {
                            foreach (MaterialDistributionNoteDetail materialDistributionNoteDetail in materialDistributionNoteItem.MaterialDistributionNoteDetails)
                            {
                                materialsRequestNote.MaterialsRequestNoteItems
                                .Where(w => w.ProductionOrderId
                                       .Equals(materialDistributionNoteDetail.ProductionOrderId))
                                .Select(s => { s.DistributedLength -= materialDistributionNoteDetail.ReceivedLength; return(s); }).ToList();
                            }
                            materialsRequestNoteService.UpdateDistributedQuantity(materialsRequestNote.Id, materialsRequestNote);
                        }
                        await materialsRequestNoteService.UpdateAsync(materialsRequestNote.Id, materialsRequestNote);
                    }

                    await CreateInventoryDocument(materialDistributionNote, "IN");

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw ex;
                }
            }

            return(count);
        }
Ejemplo n.º 9
0
        public MaterialsRequestNote MapToModel(MaterialsRequestNoteViewModel viewModel)
        {
            MaterialsRequestNote model = new MaterialsRequestNote();

            PropertyCopier <MaterialsRequestNoteViewModel, MaterialsRequestNote> .Copy(viewModel, model);

            model.UnitId      = viewModel.Unit.Id;
            model.UnitCode    = viewModel.Unit.Code;
            model.UnitName    = viewModel.Unit.Name;
            model.RequestType = viewModel.RequestType;
            model.Remark      = viewModel.Remark;

            model.MaterialsRequestNoteItems = new List <MaterialsRequestNoteItem>();

            foreach (MaterialsRequestNoteItemViewModel materialsRequestNoteItemViewModel in viewModel.MaterialsRequestNoteItems)
            {
                MaterialsRequestNoteItem materialsRequestNoteItem = new MaterialsRequestNoteItem();

                PropertyCopier <MaterialsRequestNoteItemViewModel, MaterialsRequestNoteItem> .Copy(materialsRequestNoteItemViewModel, materialsRequestNoteItem);

                if (!viewModel.RequestType.Equals("PURCHASE") && !viewModel.RequestType.Equals("TEST"))
                {
                    materialsRequestNoteItem.ProductionOrderId          = materialsRequestNoteItemViewModel.ProductionOrder.Id;
                    materialsRequestNoteItem.ProductionOrderNo          = materialsRequestNoteItemViewModel.ProductionOrder.OrderNo;
                    materialsRequestNoteItem.ProductionOrderIsCompleted = materialsRequestNoteItemViewModel.ProductionOrder.IsCompleted;
                    materialsRequestNoteItem.OrderQuantity = materialsRequestNoteItemViewModel.ProductionOrder.OrderQuantity.GetValueOrDefault();
                    materialsRequestNoteItem.OrderTypeId   = materialsRequestNoteItemViewModel.ProductionOrder.OrderType.Id;
                    materialsRequestNoteItem.OrderTypeCode = materialsRequestNoteItemViewModel.ProductionOrder.OrderType.Code;
                    materialsRequestNoteItem.OrderTypeName = materialsRequestNoteItemViewModel.ProductionOrder.OrderType.Name;
                }

                materialsRequestNoteItem.ProductId         = materialsRequestNoteItemViewModel.Product.Id;
                materialsRequestNoteItem.ProductCode       = materialsRequestNoteItemViewModel.Product.Code;
                materialsRequestNoteItem.ProductName       = materialsRequestNoteItemViewModel.Product.Name;
                materialsRequestNoteItem.Length            = materialsRequestNoteItemViewModel.Length != null ? (double)materialsRequestNoteItemViewModel.Length : 0;
                materialsRequestNoteItem.DistributedLength = materialsRequestNoteItemViewModel.DistributedLength != null ? (double)materialsRequestNoteItemViewModel.DistributedLength : 0;

                model.MaterialsRequestNoteItems.Add(materialsRequestNoteItem);
            }

            return(model);
        }
Ejemplo n.º 10
0
        public async Task UpdateIsCompleted(int Id, MaterialsRequestNote Model)
        {
            try
            {
                int CountIsIncomplete          = 0;
                List <SppParams> contextAndIds = new List <SppParams>();
                foreach (MaterialsRequestNote_Item item in Model.MaterialsRequestNote_Items)
                {
                    SppParams sppParams = new SppParams();
                    if (!item.ProductionOrderIsCompleted)
                    {
                        CountIsIncomplete += 1;
                        sppParams.context  = "INCOMPLETE";
                        sppParams.id       = item.ProductionOrderId;
                    }
                    else
                    {
                        sppParams.context = "COMPLETE";
                        sppParams.id      = item.ProductionOrderId;
                    }

                    contextAndIds.Add(sppParams);
                    UpdateIsCompletedProductionOrder(item.ProductionOrderId);
                }


                if (CountIsIncomplete == 0)
                {
                    Model.IsCompleted = true;
                }
                else
                {
                    Model.IsCompleted = false;
                }

                await UpdateAsync(Id, Model);
            }
            catch (Exception e)
            {
                throw e;
            };
        }
Ejemplo n.º 11
0
        public async Task <int> DeleteAsync(int id)
        {
            int Deleted = 0;

            using (var transaction = this.DbContext.Database.BeginTransaction())
            {
                try
                {
                    List <string>        productionOrderIds = new List <string>();
                    MaterialsRequestNote Model = await ReadByIdAsync(id);

                    if (Model == null)
                    {
                        throw new Exception("data not found");
                    }
                    Model.FlagForDelete(IdentityService.Username, UserAgent);

                    Deleted = await DbContext.SaveChangesAsync();

                    foreach (var item in Model.MaterialsRequestNote_Items)
                    {
                        await DeleteItem(item);

                        productionOrderIds.Add(item.ProductionOrderId);
                    }


                    UpdateIsRequestedProductionOrder(productionOrderIds, "DELETE");
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw e;
                }
            }

            return(Deleted);
        }
Ejemplo n.º 12
0
        public void UpdateDistributedQuantity(int Id, MaterialsRequestNote Model)
        {
            {
                try
                {
                    List <SppParams> contextQuantityAndIds = new List <SppParams>();
                    foreach (MaterialsRequestNoteItem item in Model.MaterialsRequestNoteItems)
                    {
                        SppParams sppParams = new SppParams
                        {
                            Id = item.ProductionOrderId,
                            DistributedQuantity = item.DistributedLength
                        };

                        contextQuantityAndIds.Add(sppParams);
                    }
                    UpdateDistributedQuantityProductionOrder(contextQuantityAndIds);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
Ejemplo n.º 13
0
        //public async Task<int> UpdateIsCompleted(int Id, MaterialDistributionNote Model)
        //{
        //    int IsSucceed = 0;

        //    using (var Transaction = this.DbContext.Database.BeginTransaction())
        //    {
        //        try
        //        {
        //            IsSucceed = await UpdateModel(Id, Model);
        //            MaterialDistributionNoteItemService materialDistributionNoteItemService = ServiceProvider.GetService<MaterialDistributionNoteItemService>();
        //            MaterialDistributionNoteDetailService materialDistributionNoteDetailService = ServiceProvider.GetService<MaterialDistributionNoteDetailService>();
        //            MaterialsRequestNoteService materialsRequestNoteService = ServiceProvider.GetService<MaterialsRequestNoteService>();

        //            materialDistributionNoteItemService.Username = this.Username;
        //            materialDistributionNoteDetailService.Username = this.Username;
        //            materialsRequestNoteService.Username = Username;
        //            materialsRequestNoteService.Token = Token;

        //            foreach (MaterialDistributionNoteItem materialDistributionNoteItem in Model.MaterialDistributionNoteItems)
        //            {
        //                MaterialsRequestNote materialsRequestNote = await materialsRequestNoteService.ReadModelById(materialDistributionNoteItem.MaterialRequestNoteId);
        //                await materialDistributionNoteItemService.UpdateModel(materialDistributionNoteItem.Id, materialDistributionNoteItem);

        //                foreach (MaterialDistributionNoteDetail materialDistributionNoteDetail in materialDistributionNoteItem.MaterialDistributionNoteDetails)
        //                {
        //                    await materialDistributionNoteDetailService.UpdateModel(materialDistributionNoteDetail.Id, materialDistributionNoteDetail);
        //                    if (materialDistributionNoteDetail.IsCompleted)
        //                    {
        //                        materialsRequestNote.MaterialsRequestNote_Items.Where(w => w.ProductionOrderId.Equals(materialDistributionNoteDetail.ProductionOrderId)).Select(s => { s.ProductionOrderIsCompleted = true; return s; }).ToList();
        //                    }
        //                }

        //                await materialsRequestNoteService.UpdateIsComplete(materialsRequestNote.Id, materialsRequestNote);

        //            }

        //            Transaction.Commit();
        //        }
        //        catch (Exception)
        //        {
        //            Transaction.Rollback();
        //        }
        //    }

        //    return IsSucceed;
        //}

        public override async Task <int> DeleteModel(int Id)
        {
            int Count = 0;

            using (var Transaction = this.DbContext.Database.BeginTransaction())
            {
                try
                {
                    MaterialDistributionNote materialDistributionNote = await ReadModelById(Id);

                    Count = this.Delete(Id);

                    MaterialDistributionNoteItemService   materialDistributionNoteItemService   = ServiceProvider.GetService <MaterialDistributionNoteItemService>();
                    MaterialDistributionNoteDetailService materialDistributionNoteDetailService = ServiceProvider.GetService <MaterialDistributionNoteDetailService>();
                    materialDistributionNoteItemService.Username   = this.Username;
                    materialDistributionNoteDetailService.Username = this.Username;

                    HashSet <int> MaterialDistributionNoteItems = new HashSet <int>(this.DbContext.MaterialDistributionNoteItems.Where(p => p.MaterialDistributionNoteId.Equals(Id)).Select(p => p.Id));

                    List <InventorySummaryViewModel> data = new List <InventorySummaryViewModel>();

                    foreach (int item in MaterialDistributionNoteItems)
                    {
                        HashSet <int> MaterialDistributionNoteDetails = new HashSet <int>(this.DbContext.MaterialDistributionNoteDetails.Where(p => p.MaterialDistributionNoteItemId.Equals(item)).Select(p => p.Id));

                        foreach (int detail in MaterialDistributionNoteDetails)
                        {
                            await materialDistributionNoteDetailService.DeleteAsync(detail);
                        }

                        await materialDistributionNoteItemService.DeleteAsync(item);
                    }

                    MaterialsRequestNoteService      materialsRequestNoteService      = ServiceProvider.GetService <MaterialsRequestNoteService>();
                    MaterialsRequestNote_ItemService materialsRequestNote_ItemService = ServiceProvider.GetService <MaterialsRequestNote_ItemService>();
                    materialsRequestNoteService.Username      = Username;
                    materialsRequestNoteService.Token         = Token;
                    materialsRequestNote_ItemService.Username = Username;

                    foreach (MaterialDistributionNoteItem materialDistributionNoteItem in materialDistributionNote.MaterialDistributionNoteItems)
                    {
                        MaterialsRequestNote materialsRequestNote = await materialsRequestNoteService.ReadModelById(materialDistributionNoteItem.MaterialRequestNoteId);

                        materialsRequestNote.IsDistributed = true;

                        //inventory summary data

                        if (materialDistributionNote.Type.ToUpper().Equals("PRODUKSI"))
                        {
                            foreach (MaterialDistributionNoteDetail materialDistributionNoteDetail in materialDistributionNoteItem.MaterialDistributionNoteDetails)
                            {
                                materialsRequestNote.MaterialsRequestNote_Items.Where(w => w.ProductionOrderId.Equals(materialDistributionNoteDetail.ProductionOrderId)).Select(s => { s.DistributedLength -= materialDistributionNoteDetail.ReceivedLength; return(s); }).ToList();
                            }
                            materialsRequestNoteService.UpdateDistributedQuantity(materialsRequestNote.Id, materialsRequestNote);

                            foreach (MaterialsRequestNote_Item materialRequestNoteItem in materialsRequestNote.MaterialsRequestNote_Items)
                            {
                                materialsRequestNote_ItemService.OnUpdating(materialRequestNoteItem.Id, materialRequestNoteItem);
                                materialsRequestNote_ItemService.DbSet.Update(materialRequestNoteItem);
                            }
                        }

                        materialsRequestNoteService.OnUpdating(materialsRequestNote.Id, materialsRequestNote);
                        materialsRequestNoteService.DbSet.Update(materialsRequestNote);
                    }

                    DbContext.SaveChanges();

                    CreateInventoryDocument(materialDistributionNote, "IN");
                    Transaction.Commit();
                }
                catch (DbUpdateConcurrencyException)
                {
                    Transaction.Rollback();
                    throw;
                }
            }

            return(Count);
        }
        public async Task <int> DeleteAsync(int id)
        {
            int Count = 0;

            using (var Transaction = this.DbContext.Database.BeginTransaction())
            {
                try
                {
                    MaterialDistributionNote materialDistributionNote = await ReadByIdAsync(id);

                    materialDistributionNote.FlagForDelete(IdentityService.Username, UserAgent);
                    foreach (var item in materialDistributionNote.MaterialDistributionNoteItems)
                    {
                        item.FlagForDelete(IdentityService.Username, UserAgent);

                        foreach (var detail in item.MaterialDistributionNoteDetails)
                        {
                            detail.FlagForDelete(IdentityService.Username, UserAgent);
                        }
                    }

                    Count = await DbContext.SaveChangesAsync();

                    //MaterialDistributionNoteItemService materialDistributionNoteItemService = ServiceProvider.GetService<MaterialDistributionNoteItemService>();
                    //MaterialDistributionNoteDetailService materialDistributionNoteDetailService = ServiceProvider.GetService<MaterialDistributionNoteDetailService>();
                    //materialDistributionNoteItemService.Username = this.Username;
                    //materialDistributionNoteDetailService.Username = this.Username;

                    //HashSet<int> MaterialDistributionNoteItems = new HashSet<int>(this.DbContext.MaterialDistributionNoteItems.Where(p => p.MaterialDistributionNoteId.Equals(Id)).Select(p => p.Id));

                    //List<InventorySummaryViewModel> data = new List<InventorySummaryViewModel>();

                    //foreach (int item in MaterialDistributionNoteItems)
                    //{
                    //    HashSet<int> MaterialDistributionNoteDetails = new HashSet<int>(this.DbContext.MaterialDistributionNoteDetails.Where(p => p.MaterialDistributionNoteItemId.Equals(item)).Select(p => p.Id));

                    //    foreach (int detail in MaterialDistributionNoteDetails)
                    //    {
                    //        await materialDistributionNoteDetailService.DeleteAsync(detail);
                    //    }

                    //    await materialDistributionNoteItemService.DeleteAsync(item);
                    //}

                    IMaterialRequestNoteService materialsRequestNoteService = ServiceProvider.GetService <IMaterialRequestNoteService>();
                    //MaterialsRequestNote_ItemService materialsRequestNote_ItemService = ServiceProvider.GetService<MaterialsRequestNote_ItemService>();
                    //materialsRequestNoteService.Username = Username;
                    //materialsRequestNoteService.Token = Token;
                    //materialsRequestNote_ItemService.Username = Username;

                    foreach (MaterialDistributionNoteItem materialDistributionNoteItem in materialDistributionNote.MaterialDistributionNoteItems)
                    {
                        MaterialsRequestNote materialsRequestNote = await materialsRequestNoteService.ReadByIdAsync(materialDistributionNoteItem.MaterialRequestNoteId);

                        materialsRequestNote.IsDistributed = true;

                        //inventory summary data

                        if (materialDistributionNote.Type.ToUpper().Equals("PRODUKSI"))
                        {
                            foreach (MaterialDistributionNoteDetail materialDistributionNoteDetail in materialDistributionNoteItem.MaterialDistributionNoteDetails)
                            {
                                materialsRequestNote.MaterialsRequestNote_Items.Where(w => w.ProductionOrderId.Equals(materialDistributionNoteDetail.ProductionOrderId)).Select(s => { s.DistributedLength -= materialDistributionNoteDetail.ReceivedLength; return(s); }).ToList();
                            }
                            materialsRequestNoteService.UpdateDistributedQuantity(materialsRequestNote.Id, materialsRequestNote);

                            //foreach (MaterialsRequestNote_Item materialRequestNoteItem in materialsRequestNote.MaterialsRequestNote_Items)
                            //{
                            //    materialsRequestNote_ItemService.OnUpdating(materialRequestNoteItem.Id, materialRequestNoteItem);
                            //    materialsRequestNote_ItemService.DbSet.Update(materialRequestNoteItem);
                            //}
                        }
                        await materialsRequestNoteService.UpdateAsync(materialsRequestNote.Id, materialsRequestNote);

                        //materialsRequestNoteService.OnUpdating(materialsRequestNote.Id, materialsRequestNote);
                        //materialsRequestNoteService.DbSet.Update(materialsRequestNote);
                    }


                    await CreateInventoryDocument(materialDistributionNote, "IN");

                    Transaction.Commit();
                }
                catch (Exception ex)
                {
                    Transaction.Rollback();
                    throw ex;
                }
            }

            return(Count);
        }
Ejemplo n.º 15
0
        public override async Task <int> CreateModel(MaterialDistributionNote Model)
        {
            int Created = 0;

            using (var transaction = this.DbContext.Database.BeginTransaction())
            {
                try
                {
                    Model = await this.CustomCodeGenerator(Model);

                    Created = await this.CreateAsync(Model);

                    MaterialsRequestNoteService      materialsRequestNoteService      = ServiceProvider.GetService <MaterialsRequestNoteService>();
                    MaterialsRequestNote_ItemService materialsRequestNote_ItemService = ServiceProvider.GetService <MaterialsRequestNote_ItemService>();
                    materialsRequestNoteService.Username      = Username;
                    materialsRequestNoteService.Token         = Token;
                    materialsRequestNote_ItemService.Username = Username;

                    List <InventorySummaryViewModel> data = new List <InventorySummaryViewModel>();


                    foreach (MaterialDistributionNoteItem materialDistributionNoteItem in Model.MaterialDistributionNoteItems)
                    {
                        //inventory summary data
                        //if (!(Model.Type.ToUpper().Equals("RE - GRADING")))
                        //{
                        //    foreach (MaterialDistributionNoteDetail materialDistributionNoteDetail in materialDistributionNoteItem.MaterialDistributionNoteDetails)
                        //    {
                        //        var Distributed = DbContext.MaterialsRequestNotes.Single(p => p.Id == materialDistributionNoteItem.MaterialRequestNoteId);
                        //        //InventorySummaryViewModel InventorySummary = new InventorySummaryViewModel();
                        //        //InventorySummary.quantity = Distributed.IsDistributed ? materialDistributionNoteDetail.ReceivedLength * -1 : materialDistributionNoteDetail.ReceivedLength;
                        //        //InventorySummary.productCode = materialDistributionNoteDetail.ProductCode;
                        //        //InventorySummary.productId = materialDistributionNoteDetail.ProductId;
                        //        //InventorySummary.productName = materialDistributionNoteDetail.ProductName;
                        //        //InventorySummary.storageName = Model.UnitName;
                        //        //InventorySummary.uom = "MTR";

                        //        materialDistributionNoteDetail.ReceivedLength = Distributed.IsDistributed ? materialDistributionNoteDetail.ReceivedLength * -1 : materialDistributionNoteDetail.MaterialRequestNoteItemLength - materialDistributionNoteDetail.ReceivedLength;

                        //        data.Add(InventorySummary);
                        //    }
                        //}

                        MaterialsRequestNote materialsRequestNote = await materialsRequestNoteService.ReadModelById(materialDistributionNoteItem.MaterialRequestNoteId);

                        materialsRequestNote.IsDistributed = true;

                        if (Model.Type.ToUpper().Equals("PRODUKSI"))
                        {
                            foreach (MaterialDistributionNoteDetail materialDistributionNoteDetail in materialDistributionNoteItem.MaterialDistributionNoteDetails)
                            {
                                materialsRequestNote.MaterialsRequestNote_Items.Where(w => w.ProductionOrderId.Equals(materialDistributionNoteDetail.ProductionOrderId)).Select(s => { s.DistributedLength += materialDistributionNoteDetail.ReceivedLength; return(s); }).ToList();
                            }
                            materialsRequestNoteService.UpdateDistributedQuantity(materialsRequestNote.Id, materialsRequestNote);

                            foreach (MaterialsRequestNote_Item materialRequestNoteItem in materialsRequestNote.MaterialsRequestNote_Items)
                            {
                                materialsRequestNote_ItemService.OnUpdating(materialRequestNoteItem.Id, materialRequestNoteItem);
                                materialsRequestNote_ItemService.DbSet.Update(materialRequestNoteItem);
                            }
                        }

                        materialsRequestNoteService.OnUpdating(materialsRequestNote.Id, materialsRequestNote);
                        materialsRequestNoteService.DbSet.Update(materialsRequestNote);
                    }

                    DbContext.SaveChanges();

                    CreateInventoryDocument(Model, "OUT");

                    //this.UpdateInventorySummary(data);

                    transaction.Commit();
                }
                catch (ServiceValidationExeption e)
                {
                    transaction.Rollback();
                    throw new ServiceValidationExeption(e.ValidationContext, e.ValidationResults);
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new ServiceValidationExeption(null, null);
                }
            }
            return(Created);
        }
Ejemplo n.º 16
0
        public async Task <int> UpdateAsync(int id, MaterialsRequestNote model)
        {
            int updated             = 0;
            var internalTransaction = _inventoryDbContext.Database.CurrentTransaction == null;
            var transaction         = !internalTransaction ? _inventoryDbContext.Database.CurrentTransaction : _inventoryDbContext.Database.BeginTransaction();

            try
            {
                var dbModel = await ReadByIdAsync(id);

                if (dbModel == null)
                {
                    throw new Exception("data not found");
                }

                dbModel.Remark        = model.Remark;
                dbModel.IsCompleted   = model.IsCompleted;
                dbModel.IsDistributed = model.IsDistributed;
                dbModel.RequestType   = model.RequestType;
                dbModel.Type          = model.Type;
                dbModel.UnitCode      = model.UnitCode;
                dbModel.UnitId        = model.UnitId;
                dbModel.UnitName      = model.UnitName;
                dbModel.FlagForUpdate(_identityInterface.Username, UserAgent);
                updated = await _inventoryDbContext.SaveChangesAsync();

                var           deletedDetails            = dbModel.MaterialsRequestNoteItems.Where(x => !model.MaterialsRequestNoteItems.Any(y => x.Id == y.Id));
                var           updatedDetails            = dbModel.MaterialsRequestNoteItems.Where(x => model.MaterialsRequestNoteItems.Any(y => x.Id == y.Id));
                var           addedDetails              = model.MaterialsRequestNoteItems.Where(x => !dbModel.MaterialsRequestNoteItems.Any(y => y.Id == x.Id));
                List <string> deletedProductionOrderIds = new List <string>();
                List <string> newProductionOrderIds     = new List <string>();
                foreach (var item in deletedDetails)
                {
                    updated += await DeleteItem(item);

                    deletedProductionOrderIds.Add(item.ProductionOrderId);
                }

                foreach (var item in updatedDetails)
                {
                    var selectedDetail = model.MaterialsRequestNoteItems.FirstOrDefault(x => x.Id == item.Id);

                    if (item.ProductionOrderId != selectedDetail.ProductionOrderId)
                    {
                        newProductionOrderIds.Add(selectedDetail.ProductionOrderId);
                        deletedProductionOrderIds.Add(item.ProductionOrderId);
                    }

                    item.ProductionOrderId          = selectedDetail.ProductionOrderId;
                    item.ProductionOrderIsCompleted = selectedDetail.ProductionOrderIsCompleted;
                    item.ProductionOrderNo          = selectedDetail.ProductionOrderNo;
                    item.ProductId         = selectedDetail.ProductId;
                    item.ProductCode       = selectedDetail.ProductCode;
                    item.ProductName       = selectedDetail.ProductName;
                    item.Grade             = selectedDetail.Grade;
                    item.Length            = selectedDetail.Length;
                    item.Remark            = selectedDetail.Remark;
                    item.DistributedLength = selectedDetail.DistributedLength;
                    item.OrderQuantity     = selectedDetail.OrderQuantity;
                    item.OrderTypeCode     = selectedDetail.OrderTypeCode;
                    item.OrderTypeId       = selectedDetail.OrderTypeId;
                    item.OrderTypeName     = selectedDetail.OrderTypeName;

                    updated += await UpdateItem(item);
                }

                foreach (var item in addedDetails)
                {
                    item.MaterialsRequestNoteId = id;
                    updated += await CreateItem(item);

                    newProductionOrderIds.Add(item.ProductionOrderId);
                }
                UpdateIsRequestedProductionOrder(deletedProductionOrderIds, "DELETE");
                UpdateIsRequestedProductionOrder(newProductionOrderIds, "CREATE");

                if (internalTransaction)
                {
                    transaction.Commit();
                }
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }

            return(updated);
        }
Ejemplo n.º 17
0
        public MaterialsRequestNoteViewModel MapToViewModel(MaterialsRequestNote model)
        {
            MaterialsRequestNoteViewModel viewModel = new MaterialsRequestNoteViewModel();

            PropertyCopier <MaterialsRequestNote, MaterialsRequestNoteViewModel> .Copy(model, viewModel);

            CodeNameViewModel Unit = new CodeNameViewModel()
            {
                Id   = model.UnitId,
                Code = model.UnitCode,
                Name = model.UnitName
            };

            viewModel.Code        = model.Code;
            viewModel.Unit        = Unit;
            viewModel.RequestType = model.RequestType;
            viewModel.Remark      = model.Remark;

            viewModel.MaterialsRequestNoteItems = new List <MaterialsRequestNoteItemViewModel>();
            if (model.MaterialsRequestNoteItems != null)
            {
                foreach (MaterialsRequestNoteItem materialsRequestNoteItem in model.MaterialsRequestNoteItems)
                {
                    MaterialsRequestNoteItemViewModel materialsRequestNoteItemViewModel = new MaterialsRequestNoteItemViewModel();
                    PropertyCopier <MaterialsRequestNoteItem, MaterialsRequestNoteItemViewModel> .Copy(materialsRequestNoteItem, materialsRequestNoteItemViewModel);

                    CodeNameViewModel OrderType = new CodeNameViewModel()
                    {
                        Id   = materialsRequestNoteItem.OrderTypeId,
                        Code = materialsRequestNoteItem.OrderTypeCode,
                        Name = materialsRequestNoteItem.OrderTypeName
                    };

                    ProductionOrderViewModel ProductionOrder = new ProductionOrderViewModel()
                    {
                        Id                  = materialsRequestNoteItem.ProductionOrderId,
                        OrderNo             = materialsRequestNoteItem.ProductionOrderNo,
                        OrderQuantity       = materialsRequestNoteItem.OrderQuantity,
                        IsCompleted         = materialsRequestNoteItem.ProductionOrderIsCompleted,
                        DistributedQuantity = materialsRequestNoteItem.DistributedLength,
                        OrderType           = OrderType
                    };
                    materialsRequestNoteItemViewModel.ProductionOrder = ProductionOrder;

                    CodeNameViewModel Product = new CodeNameViewModel()
                    {
                        Id   = materialsRequestNoteItem.ProductId,
                        Code = materialsRequestNoteItem.ProductCode,
                        Name = materialsRequestNoteItem.ProductName
                    };
                    materialsRequestNoteItemViewModel.Product = Product;

                    materialsRequestNoteItemViewModel.Length            = materialsRequestNoteItem.Length;
                    materialsRequestNoteItemViewModel.DistributedLength = materialsRequestNoteItem.DistributedLength;

                    viewModel.MaterialsRequestNoteItems.Add(materialsRequestNoteItemViewModel);
                }
            }

            return(viewModel);
        }
Ejemplo n.º 18
0
        public async Task <int> CreateAsync(MaterialDistributionNote model)
        {
            int created = 0;

            using (var transaction = _inventoryDbContext.Database.BeginTransaction())
            {
                try
                {
                    model = await this.CustomCodeGenerator(model);

                    model.FlagForCreate(_identityInterface.Username, UserAgent);
                    model.FlagForUpdate(_identityInterface.Username, UserAgent);
                    foreach (var item in model.MaterialDistributionNoteItems)
                    {
                        item.FlagForCreate(_identityInterface.Username, UserAgent);
                        item.FlagForUpdate(_identityInterface.Username, UserAgent);
                        foreach (var detail in item.MaterialDistributionNoteDetails)
                        {
                            detail.FlagForCreate(_identityInterface.Username, UserAgent);
                            detail.FlagForUpdate(_identityInterface.Username, UserAgent);
                        }
                    }

                    _dbSet.Add(model);

                    created = await _inventoryDbContext.SaveChangesAsync();

                    IMaterialRequestNoteRepository materialsRequestNoteService = _serviceProvider.GetService <IMaterialRequestNoteRepository>();

                    List <ViewModels.InventoryViewModel.InventorySummaryViewModel> data = new List <ViewModels.InventoryViewModel.InventorySummaryViewModel>();


                    foreach (MaterialDistributionNoteItem materialDistributionNoteItem in model.MaterialDistributionNoteItems)
                    {
                        MaterialsRequestNote materialsRequestNote = await materialsRequestNoteService.ReadByIdAsync(materialDistributionNoteItem.MaterialRequestNoteId);

                        materialsRequestNote.IsDistributed = true;

                        if (model.Type.ToUpper().Equals("PRODUCTION"))
                        {
                            foreach (MaterialDistributionNoteDetail materialDistributionNoteDetail in materialDistributionNoteItem.MaterialDistributionNoteDetails)
                            {
                                materialsRequestNote.MaterialsRequestNoteItems.Where(w => w.ProductionOrderId.Equals(materialDistributionNoteDetail.ProductionOrderId)).Select(s => { s.DistributedLength += materialDistributionNoteDetail.ReceivedLength; return(s); }).ToList();
                            }
                            materialsRequestNoteService.UpdateDistributedQuantity(materialsRequestNote.Id, materialsRequestNote);
                        }
                        await materialsRequestNoteService.UpdateAsync(materialsRequestNote.Id, materialsRequestNote);
                    }

                    _inventoryDbContext.SaveChanges();

                    await CreateInventoryDocument(model, "OUT");

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw e;
                }
            }
            return(created);
        }