public Bale Create(Bale model)
        {
            model.DTCreated   = DateTime.Now;
            model.DT          = model.DT;
            model.FIFORemarks = "First In, First Out";
            model.IsReject    = false;

            var product = productRepository.Get().Select(a =>
                                                         new
            {
                a.ProductId,
                a.ProductDesc,
                CategoryId   = a.Category == null ? 0 : a.Category.CategoryId,
                CategoryDesc = a.Category == null ? "" : a.Category.CategoryDesc
            })
                          .FirstOrDefault(b => b.ProductId == model.ProductId);

            model.ProductId    = product?.ProductId ?? 0;
            model.ProductDesc  = product?.ProductDesc;
            model.CategoryId   = product?.CategoryId ?? 0;
            model.CategoryDesc = product?.CategoryDesc;

            dbContext.Bales.Add(model);
            dbContext.SaveChanges();
            dbContext.Entry <Bale>(model).State = EntityState.Detached;

            CheckAndCreateBaleOverageReminder();
            baleStationRepository.CheckAndCreateStockStatusReminder();

            return(model);
        }
Example #2
0
        public PurchaseTransaction Update(PurchaseTransaction modifiedPurchase)
        {
            var entity = dbContext.PurchaseTransactions.AsNoTracking().FirstOrDefault(a => a.PurchaseId == modifiedPurchase.PurchaseId);

            if (entity == null)
            {
                throw new Exception("Selected Record does not exists.");
            }

            var auditLog = initAuditLogUpdate(entity, modifiedPurchase);

            updateRelatedTableColumns(ref modifiedPurchase);

            var correctedMC = mcRepository.GetCorrectedMC(modifiedPurchase.MC, entity.NetWt);

            entity.BaleCount          = modifiedPurchase.BaleCount;
            entity.BaleTypeDesc       = modifiedPurchase.BaleTypeDesc;
            entity.BaleTypeId         = modifiedPurchase.BaleTypeId;
            entity.CategoryDesc       = modifiedPurchase.CategoryDesc;
            entity.CategoryId         = modifiedPurchase.CategoryId;
            entity.Corrected10        = correctedMC.Corrected10;
            entity.Corrected12        = correctedMC.Corrected12;
            entity.Corrected14        = correctedMC.Corrected14;
            entity.Corrected15        = correctedMC.Corrected15;
            entity.DriverName         = modifiedPurchase.DriverName;
            entity.MC                 = modifiedPurchase.MC;
            entity.MCStatus           = modifiedPurchase.MCStatus;
            entity.MoistureReaderId   = modifiedPurchase.MoistureReaderId;
            entity.MoistureReaderDesc = modifiedPurchase.MoistureReaderDesc;
            entity.OT                 = modifiedPurchase.OT;
            entity.PM                 = modifiedPurchase.PM;
            entity.PurchaseOrderId    = modifiedPurchase.PurchaseOrderId;
            entity.PONum              = modifiedPurchase.PONum;
            entity.POType             = modifiedPurchase.POType;
            entity.Price              = modifiedPurchase.Price;
            entity.RawMaterialId      = modifiedPurchase.RawMaterialId;
            entity.RawMaterialDesc    = modifiedPurchase.RawMaterialDesc;
            entity.Remarks            = modifiedPurchase.Remarks;
            entity.SourceId           = modifiedPurchase.SourceId;
            entity.SourceName         = modifiedPurchase.SourceName;
            entity.SourceCategoryId   = modifiedPurchase.SourceCategoryId;
            entity.SourceCategoryDesc = modifiedPurchase.SourceCategoryDesc;
            entity.SubSupplierName    = modifiedPurchase.SubSupplierName;
            entity.SupplierId         = modifiedPurchase.SupplierId;
            entity.SupplierName       = modifiedPurchase.SupplierName;
            entity.Trip               = modifiedPurchase.Trip;
            entity.VehicleNum         = modifiedPurchase.VehicleNum;
            entity.VehicleTypeId      = modifiedPurchase.VehicleTypeId;
            entity.VehicleTypeCode    = modifiedPurchase.VehicleTypeCode;
            entity.WeigherOutId       = modifiedPurchase.WeigherOutId;
            entity.WeigherOutName     = modifiedPurchase.WeigherOutName;

            entity.MoistureReaderLogsModified = modifiedPurchase.MoistureReaderLogsModified;

            dbContext.PurchaseTransactions.Update(entity);

            if (modifiedPurchase.MoistureReaderLogsModified)
            {
                dbContext.RemoveRange(dbContext.moistureReaderLogs.Where(a => a.TransactionId == modifiedPurchase.PurchaseId));
            }

            dbContext.SaveChanges();

            if (auditLog != null)
            {
                auditLogRepository.Create(auditLog);
            }

            balingStationRepository.CheckAndCreateStockStatusReminder();

            return(entity);
        }
Example #3
0
        public PurchaseTransaction WeighoutPurchase(Inyard model)
        {
            var refNum = dbContext.ReferenceNumbers.FirstOrDefault();

            updateRelatedTableColumns(ref model);

            var weekDetail = new WeekDetail(model.DateTimeOut.Value);

            var correctedMC = mcRepo.GetCorrectedMC(model.MC, model.NetWt);

            var newPurchase = new PurchaseTransaction()
            {
                BaleCount         = model.BaleCount,
                BaleTypeDesc      = baleTypeRepository.Get().Where(a => a.BaleTypeId == model.BaleTypeId).Take(1).Select(a => a.BaleTypeDesc).FirstOrDefault(),
                BaleTypeId        = model.BaleTypeId,
                BalingStationNum  = model.BalingStationNum,
                BalingStationCode = model.BalingStationCode,
                BalingStationName = model.BalingStationName,
                CategoryDesc      = model.CategoryDesc,
                CategoryId        = model.CategoryId,
                Corrected10       = correctedMC.Corrected10,
                Corrected12       = correctedMC.Corrected12,
                Corrected14       = correctedMC.Corrected14,
                Corrected15       = correctedMC.Corrected15,
                DateTimeIn        = model.DateTimeIn,
                DateTimeOut       = model.IsOfflineOut ?? false ? model.DateTimeIn : DateTime.Now,
                DriverName        = model.DriverName?.ToUpper(),
                DRNum             = model.DRNum?.ToUpper(),
                FirstDay          = weekDetail.FirstDay,
                FactoryWt         = model.PlantNetWt,
                GrossWt           = model.GrossWt,
                IsOfflineIn       = model.IsOfflineIn,
                IsOfflineOut      = model.IsOfflineOut ?? false,
                LastDay           = weekDetail.LastDay,
                MC       = model.MC,
                MCDate   = model.MoistureReaderLogs.FirstOrDefault()?.DTLog,
                MCStatus = model.MCStatus,
                MoistureReaderProcess = model.MoistureReaderProcess,
                MoistureReaderDesc    = model.MoistureReaderDesc,
                MoistureReaderId      = model.MoistureReaderId,
                MoistureReaderLogs    = model.MoistureReaderLogs,
                MoistureSettingsId    = 1,
                OT                 = model.OT,
                NetWt              = model.NetWt,
                PM                 = model.PM,
                PurchaseOrderId    = model.PurchaseOrderId,
                PONum              = model.PONum,
                POType             = model.POType,
                Price              = model.Price,
                PrintCount         = 0,
                RawMaterialDesc    = model.CommodityDesc,
                RawMaterialId      = model.CommodityId,
                ReceiptNum         = refNum.PurchaseReceiptNum,
                Remarks            = model.Remarks?.ToUpper(),
                SignatoryId        = 1,
                SourceCategoryDesc = model.SourceCategoryDesc,
                SourceCategoryId   = model.SourceCategoryId,
                SourceId           = model.SourceId,
                SourceName         = model.SourceName,
                SupplierId         = model.ClientId,
                SupplierName       = model.ClientName,
                SubSupplierName    = model.SubSupplierName?.ToUpper(),
                TareWt             = model.TareWt,
                TimeZoneIn         = model.DateTimeIn.GetTimeZone(),
                TimeZoneOut        = model.DateTimeOut.GetTimeZone(),
                Trip               = model.Trip?.ToUpper(),
                VehicleNum         = model.VehicleNum?.ToUpper(),
                VehicleTypeCode    = model.VehicleTypeCode,
                VehicleTypeId      = model.VehicleTypeId,
                WeekDay            = weekDetail.WeekDay,
                WeekNum            = weekDetail.WeekNum,
                WeigherInId        = model.WeigherInId,
                WeigherInName      = model.WeigherInName,
                WeigherOutId       = model.WeigherOutId,
                WeigherOutName     = model.WeigherOutName
            };

            dbContext.PurchaseTransactions.Add(newPurchase);

            if (subSupplierRepository.Get().Count(a => a.SubSupplierName == model.SubSupplierName) == 0)
            {
                dbContext.SubSuppliers.Add(new SubSupplier()
                {
                    SubSupplierName = model.SubSupplierName?.Trim(), IsActive = true
                });
            }

            refNum.PurchaseReceiptNum = String.Format(StringFormats.REFNO_FORMAT, Convert.ToInt32(refNum.PurchaseReceiptNum) + 1);
            dbContext.ReferenceNumbers.Update(refNum);

            dbContext.Inyards.Remove(model);

            dbContext.SaveChanges();

            if (model.IsOfflineOut ?? false)
            {
                var auditLog = new AuditLog()
                {
                    AuditLogEventId = auditLogEventRepository.GetOfflineOutEventId(),
                    UserAccountId   = model.WeigherInId,
                    Notes           = formatPurchaseOfflineOutEvent(newPurchase)
                };
                auditLogRepository.Create(auditLog);
            }

            balingStationRepository.CheckAndCreateStockStatusReminder();

            return(newPurchase);
        }