Esempio n. 1
0
        public override void OnCreating(MaterialDistributionNote model)
        {
            base.OnCreating(model);

            model._CreatedAgent      = "Service";
            model._CreatedBy         = this.Username;
            model._LastModifiedAgent = "Service";
            model._LastModifiedBy    = this.Username;

            MaterialDistributionNoteItemService materialDistributionNoteItemService = ServiceProvider.GetService <MaterialDistributionNoteItemService>();

            materialDistributionNoteItemService.Username = this.Username;

            foreach (MaterialDistributionNoteItem mdni in model.MaterialDistributionNoteItems)
            {
                materialDistributionNoteItemService.OnCreating(mdni);
            }
        }
Esempio n. 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);
        }