Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }