public async Task <int> CreateAsync(GarmentLeftoverWarehouseExpenditureFinishedGood model)
        {
            int Created = 0;

            using (var transaction = DbContext.Database.CurrentTransaction ?? DbContext.Database.BeginTransaction())
            {
                try
                {
                    model.FlagForCreate(IdentityService.Username, UserAgent);
                    model.FlagForUpdate(IdentityService.Username, UserAgent);

                    model.FinishedGoodExpenditureNo = GenerateNo(model);

                    foreach (var item in model.Items)
                    {
                        item.FlagForCreate(IdentityService.Username, UserAgent);
                        item.FlagForUpdate(IdentityService.Username, UserAgent);
                    }
                    DbSet.Add(model);

                    Created = await DbContext.SaveChangesAsync();

                    foreach (var item in model.Items)
                    {
                        GarmentLeftoverWarehouseStock stock = new GarmentLeftoverWarehouseStock
                        {
                            ReferenceType        = GarmentLeftoverWarehouseStockReferenceTypeEnum.FINISHED_GOOD,
                            UnitId               = item.UnitId,
                            UnitCode             = item.UnitCode,
                            UnitName             = item.UnitName,
                            RONo                 = item.RONo,
                            Quantity             = item.ExpenditureQuantity,
                            LeftoverComodityCode = item.LeftoverComodityCode,
                            LeftoverComodityId   = item.LeftoverComodityId,
                            LeftoverComodityName = item.LeftoverComodityName
                        };
                        await StockService.StockOut(stock, model.FinishedGoodExpenditureNo, model.Id, item.Id);
                    }

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

            return(Created);
        }
        public async Task <int> DeleteAsync(int id)
        {
            using (var transaction = DbContext.Database.CurrentTransaction ?? DbContext.Database.BeginTransaction())
            {
                try
                {
                    int Deleted = 0;

                    GarmentLeftoverWarehouseReceiptFabric model = await ReadByIdAsync(id);

                    model.FlagForDelete(IdentityService.Username, UserAgent);
                    foreach (var item in model.Items)
                    {
                        item.FlagForDelete(IdentityService.Username, UserAgent);
                    }

                    Deleted = await DbContext.SaveChangesAsync();

                    foreach (var item in model.Items)
                    {
                        GarmentLeftoverWarehouseStock stock = new GarmentLeftoverWarehouseStock
                        {
                            ReferenceType = GarmentLeftoverWarehouseStockReferenceTypeEnum.FABRIC,
                            UnitId        = model.UnitFromId,
                            UnitCode      = model.UnitFromCode,
                            UnitName      = model.UnitFromName,
                            PONo          = item.POSerialNumber,
                            UomId         = item.UomId,
                            UomUnit       = item.UomUnit,
                            Quantity      = item.Quantity,
                            ProductCode   = item.ProductCode,
                            ProductId     = item.ProductId,
                            ProductName   = item.ProductName,
                            BasicPrice    = item.BasicPrice
                        };
                        await StockService.StockOut(stock, model.ReceiptNoteNo, model.Id, item.Id);
                    }

                    await UpdateUnitExpenditureNoteIsReceived(model.UENId, false);

                    transaction.Commit();

                    return(Deleted);
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw e;
                }
            }
        }
        public async Task <int> CreateAsync(GarmentLeftoverWarehouseExpenditureFabric model)
        {
            using (var transaction = DbContext.Database.CurrentTransaction ?? DbContext.Database.BeginTransaction())
            {
                try
                {
                    int Created = 0;

                    model.FlagForCreate(IdentityService.Username, UserAgent);
                    model.FlagForUpdate(IdentityService.Username, UserAgent);

                    model.ExpenditureNo = GenerateNo(model);

                    foreach (var item in model.Items)
                    {
                        item.FlagForCreate(IdentityService.Username, UserAgent);
                        item.FlagForUpdate(IdentityService.Username, UserAgent);
                    }
                    DbSet.Add(model);
                    Created = await DbContext.SaveChangesAsync();

                    foreach (var item in model.Items)
                    {
                        GarmentLeftoverWarehouseStock stock = GenerateStock(item);
                        await StockService.StockOut(stock, model.ExpenditureNo, model.Id, item.Id);
                    }

                    transaction.Commit();

                    return(Created);
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw e;
                }
            }
        }
        public async Task <int> CreateAsync(GarmentLeftoverWarehouseExpenditureAval model)
        {
            int Created = 0;

            using (var transaction = DbContext.Database.CurrentTransaction ?? DbContext.Database.BeginTransaction())
            {
                try
                {
                    model.FlagForCreate(IdentityService.Username, UserAgent);
                    model.FlagForUpdate(IdentityService.Username, UserAgent);

                    model.AvalExpenditureNo = GenerateNo(model);

                    foreach (var item in model.Items)
                    {
                        if (model.AvalType == "AVAL FABRIC" || model.AvalType == "AVAL KOMPONEN")
                        {
                            var receiptAval = DbContext.GarmentLeftoverWarehouseReceiptAvals.Where(a => a.Id == item.AvalReceiptId).Single();
                            receiptAval.IsUsed = true;
                        }


                        item.FlagForCreate(IdentityService.Username, UserAgent);
                        item.FlagForUpdate(IdentityService.Username, UserAgent);
                    }
                    DbSet.Add(model);

                    Created = await DbContext.SaveChangesAsync();

                    foreach (var item in model.Items)
                    {
                        if (model.AvalType == "AVAL FABRIC")
                        {
                            GarmentLeftoverWarehouseStock stock = new GarmentLeftoverWarehouseStock
                            {
                                ReferenceType = GarmentLeftoverWarehouseStockReferenceTypeEnum.AVAL_FABRIC,
                                UnitId        = item.UnitId,
                                UnitCode      = item.UnitCode,
                                UnitName      = item.UnitName,
                                Quantity      = item.Quantity
                            };
                            await StockService.StockOut(stock, model.AvalExpenditureNo, model.Id, item.Id);
                        }
                        else if (model.AvalType == "AVAL KOMPONEN")
                        {
                            GarmentLeftoverWarehouseStock stock = new GarmentLeftoverWarehouseStock
                            {
                                ReferenceType = GarmentLeftoverWarehouseStockReferenceTypeEnum.COMPONENT,
                                UnitId        = item.UnitId,
                                UnitCode      = item.UnitCode,
                                UnitName      = item.UnitName,
                                Quantity      = item.Quantity
                            };
                            await StockService.StockOut(stock, model.AvalExpenditureNo, model.Id, item.Id);
                        }
                        else
                        {
                            GarmentLeftoverWarehouseStock stock = new GarmentLeftoverWarehouseStock
                            {
                                ReferenceType = GarmentLeftoverWarehouseStockReferenceTypeEnum.AVAL_BAHAN_PENOLONG,
                                UnitId        = item.UnitId,
                                UnitCode      = item.UnitCode,
                                UnitName      = item.UnitName,
                                Quantity      = item.Quantity,
                                ProductCode   = item.ProductCode,
                                ProductName   = item.ProductName,
                                ProductId     = item.ProductId,
                                UomId         = item.UomId,
                                UomUnit       = item.UomUnit,
                            };
                            await StockService.StockOut(stock, model.AvalExpenditureNo, model.Id, item.Id);
                        }
                    }

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

            return(Created);
        }
Esempio n. 5
0
        public async Task <int> UpdateAsync(int id, GarmentLeftoverWarehouseReceiptFinishedGood model)
        {
            int Updated = 0;

            using (var transaction = DbContext.Database.CurrentTransaction ?? DbContext.Database.BeginTransaction())
            {
                try
                {
                    GarmentLeftoverWarehouseReceiptFinishedGood existingModel = await ReadByIdAsync(id);

                    if (existingModel.ReceiptDate != model.ReceiptDate)
                    {
                        existingModel.ReceiptDate = model.ReceiptDate;
                    }
                    if (existingModel.Description != model.Description)
                    {
                        existingModel.Description = model.Description;
                    }
                    foreach (var existingItem in existingModel.Items)
                    {
                        GarmentLeftoverWarehouseStock stockOut = new GarmentLeftoverWarehouseStock
                        {
                            ReferenceType        = GarmentLeftoverWarehouseStockReferenceTypeEnum.FINISHED_GOOD,
                            UnitId               = existingModel.UnitFromId,
                            UnitCode             = existingModel.UnitFromCode,
                            UnitName             = existingModel.UnitFromName,
                            RONo                 = existingItem.RONo,
                            Quantity             = existingItem.Quantity,
                            LeftoverComodityCode = existingItem.LeftoverComodityCode,
                            LeftoverComodityId   = existingItem.LeftoverComodityId,
                            LeftoverComodityName = existingItem.LeftoverComodityName,
                            BasicPrice           = existingItem.BasicPrice
                        };

                        await StockService.StockOut(stockOut, model.FinishedGoodReceiptNo, model.Id, existingItem.Id);
                    }

                    foreach (var existingItem in existingModel.Items)
                    {
                        var item = model.Items.FirstOrDefault(i => i.Id == existingItem.Id);
                        if (item == null)
                        {
                            existingItem.FlagForDelete(IdentityService.Username, UserAgent);
                            await UpdateExpenditureGoodIsReceived(existingItem.ExpenditureGoodId, "false");
                        }
                        else
                        {
                            if (existingItem.Quantity != item.Quantity)
                            {
                                existingItem.Quantity = item.Quantity;
                            }
                            existingItem.FlagForUpdate(IdentityService.Username, UserAgent);
                        }
                    }

                    foreach (var item in model.Items.Where(i => i.Id == 0))
                    {
                        item.FlagForCreate(IdentityService.Username, UserAgent);
                        await UpdateExpenditureGoodIsReceived(item.ExpenditureGoodId, "true");

                        item.FlagForUpdate(IdentityService.Username, UserAgent);
                        existingModel.Items.Add(item);
                    }

                    Updated = await DbContext.SaveChangesAsync();

                    foreach (var item in model.Items)
                    {
                        GarmentLeftoverWarehouseStock stock = new GarmentLeftoverWarehouseStock
                        {
                            ReferenceType        = GarmentLeftoverWarehouseStockReferenceTypeEnum.FINISHED_GOOD,
                            UnitId               = existingModel.UnitFromId,
                            UnitCode             = existingModel.UnitFromCode,
                            UnitName             = existingModel.UnitFromName,
                            RONo                 = item.RONo,
                            Quantity             = item.Quantity,
                            LeftoverComodityCode = item.LeftoverComodityCode,
                            LeftoverComodityId   = item.LeftoverComodityId,
                            LeftoverComodityName = item.LeftoverComodityName,
                            BasicPrice           = item.BasicPrice
                        };

                        await StockService.StockIn(stock, model.FinishedGoodReceiptNo, model.Id, item.Id);
                    }
                    existingModel.FlagForUpdate(IdentityService.Username, UserAgent);

                    Updated = await DbContext.SaveChangesAsync();

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

            return(Updated);
        }
        public async Task <int> UpdateAsync(int id, GarmentLeftoverWarehouseReceiptAval model)
        {
            int Updated = 0;

            using (var transaction = DbContext.Database.CurrentTransaction ?? DbContext.Database.BeginTransaction())
            {
                try
                {
                    GarmentLeftoverWarehouseReceiptAval existingModel = await DbSet.Where(w => w.Id == id).FirstOrDefaultAsync();

                    if (existingModel.ReceiptDate != model.ReceiptDate)
                    {
                        existingModel.ReceiptDate = model.ReceiptDate;
                    }
                    if (existingModel.Remark != model.Remark)
                    {
                        existingModel.Remark = model.Remark;
                    }
                    if (existingModel.TotalAval != model.TotalAval)
                    {
                        existingModel.TotalAval = model.TotalAval;
                    }

                    if (model.AvalType == "AVAL FABRIC")
                    {
                        if (existingModel.TotalAval != model.TotalAval)
                        {
                            GarmentLeftoverWarehouseStock stock = new GarmentLeftoverWarehouseStock
                            {
                                ReferenceType = GarmentLeftoverWarehouseStockReferenceTypeEnum.AVAL_FABRIC,
                                UnitId        = model.UnitFromId,
                                UnitCode      = model.UnitFromCode,
                                UnitName      = model.UnitFromName,
                                Quantity      = existingModel.TotalAval
                            };
                            await StockService.StockOut(stock, existingModel.AvalReceiptNo, model.Id, 0);

                            GarmentLeftoverWarehouseStock stock1 = new GarmentLeftoverWarehouseStock
                            {
                                ReferenceType = GarmentLeftoverWarehouseStockReferenceTypeEnum.AVAL_FABRIC,
                                UnitId        = model.UnitFromId,
                                UnitCode      = model.UnitFromCode,
                                UnitName      = model.UnitFromName,
                                Quantity      = model.TotalAval
                            };
                            await StockService.StockIn(stock1, model.AvalReceiptNo, model.Id, 0);

                            existingModel.TotalAval = model.TotalAval;
                        }
                    }
                    else if (model.AvalType == "AVAL KOMPONEN")
                    {
                        if (existingModel.TotalAval != model.TotalAval)
                        {
                            GarmentLeftoverWarehouseStock stock = new GarmentLeftoverWarehouseStock
                            {
                                ReferenceType = GarmentLeftoverWarehouseStockReferenceTypeEnum.COMPONENT,
                                UnitId        = model.UnitFromId,
                                UnitCode      = model.UnitFromCode,
                                UnitName      = model.UnitFromName,
                                Quantity      = existingModel.TotalAval
                            };
                            await StockService.StockOut(stock, existingModel.AvalReceiptNo, model.Id, 0);

                            GarmentLeftoverWarehouseStock stock1 = new GarmentLeftoverWarehouseStock
                            {
                                ReferenceType = GarmentLeftoverWarehouseStockReferenceTypeEnum.COMPONENT,
                                UnitId        = model.UnitFromId,
                                UnitCode      = model.UnitFromCode,
                                UnitName      = model.UnitFromName,
                                Quantity      = model.TotalAval
                            };
                            await StockService.StockIn(stock1, model.AvalReceiptNo, model.Id, 0);

                            existingModel.TotalAval = model.TotalAval;
                        }
                    }


                    existingModel.FlagForUpdate(IdentityService.Username, UserAgent);

                    Updated = await DbContext.SaveChangesAsync();

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

            return(Updated);
        }