Ejemplo n.º 1
0
        public SaleTransaction Update(SaleTransaction modifiedSale)
        {
            var entity = dbContext.SaleTransactions.AsNoTracking().FirstOrDefault(a => a.SaleId == modifiedSale.SaleId);

            if (entity == null)
            {
                throw new Exception("Selected Record does not exists.");
            }
            var auditLog = initAuditLogUpdate(entity, modifiedSale);

            updateRelatedTableColumns(ref modifiedSale);


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

            entity.BaleCount    = modifiedSale.BaleCount;
            entity.BaleTypeDesc = modifiedSale.BaleTypeDesc;
            entity.BaleTypeId   = modifiedSale.BaleTypeId;
            entity.CategoryDesc = modifiedSale.CategoryDesc;
            entity.CategoryId   = modifiedSale.CategoryId;
            entity.Corrected10  = correctedMC.Corrected10;
            entity.Corrected12  = correctedMC.Corrected12;
            entity.Corrected14  = correctedMC.Corrected14;
            entity.Corrected15  = correctedMC.Corrected15;
            entity.CustomerId   = modifiedSale.CustomerId;
            entity.CustomerName = modifiedSale.CustomerName;
            entity.DriverName   = modifiedSale.DriverName;
            entity.HaulerId     = modifiedSale.HaulerId;
            entity.HaulerName   = modifiedSale.HaulerName;
            entity.MC           = modifiedSale.MC;
            //entity.MCStatus = modifiedSale.MCStatus;
            entity.MoistureReaderId   = modifiedSale.MoistureReaderId;
            entity.MoistureReaderDesc = modifiedSale.MoistureReaderDesc;
            entity.OT              = modifiedSale.OT;
            entity.PM              = modifiedSale.PM;
            entity.PaperMillId     = modifiedSale.PaperMillId;
            entity.PaperMillCode   = modifiedSale.PaperMillCode;
            entity.ProductId       = modifiedSale.ProductId;
            entity.ProductDesc     = modifiedSale.ProductDesc;
            entity.Remarks         = modifiedSale.Remarks;
            entity.SealNum         = modifiedSale.SealNum;
            entity.Trip            = modifiedSale.Trip;
            entity.VehicleNum      = modifiedSale.VehicleNum;
            entity.VehicleTypeId   = modifiedSale.VehicleTypeId;
            entity.VehicleTypeCode = modifiedSale.VehicleTypeCode;
            entity.WeigherOutId    = modifiedSale.WeigherOutId;
            entity.WeigherOutName  = modifiedSale.WeigherOutName;

            dbContext.SaleTransactions.Update(entity);
            dbContext.SaveChanges();

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

            return(entity);
        }
Ejemplo n.º 2
0
        public SaleTransaction Create(long SaleId, ReturnedVehicle model)
        {
            var saleTransaction = saleTransactionRepository.GetById(SaleId);

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

            //model.MCStatus = correctedMC.MCStatus;
            model.Corrected10 = correctedMC.Corrected10;
            model.Corrected12 = correctedMC.Corrected12;
            model.Corrected14 = correctedMC.Corrected14;
            //model.Corrected15 = correctedMC.Corrected15;

            saleTransaction.ReturnedVehicle = model;
            dbContext.Update(saleTransaction);
            dbContext.SaveChanges();

            return(saleTransaction);
        }
Ejemplo n.º 3
0
        public Dictionary <string, string> ValidateInyardWeighing(Inyard model)
        {
            var modelStateDict = new Dictionary <string, string>();

            if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_IN ||
                model.TransactionProcess == SysUtility.Enums.TransactionProcess.UPDATE_WEIGH_IN)
            {
                if (model.IsOfflineIn == false)
                {
                    if (model.VehicleNum != model.VehicleNumOld || model.VehicleNumOld == null)
                    {
                        var vehicleDeliverRestriction = new VehicleDeliveryRestriction(model.VehicleNum, model.CommodityId)
                        {
                            DateTimeIn = model.DateTimeIn
                        };
                        var vehicleDeliveryRestrictionResult = vehicleDeliveryRestrictionRepository.CheckRestriction(vehicleDeliverRestriction);
                        if (vehicleDeliveryRestrictionResult != null)
                        {
                            modelStateDict.Add(nameof(Inyard.VehicleNum), ValidationMessages.VehicleDeliveryInvalid(vehicleDeliveryRestrictionResult.DTRestriction));
                        }

                        var purchaseGrossRestrictionresult = new PurchaseGrossWtRestriction(model.VehicleNum, model.CommodityId)
                        {
                            DateTimeIn = model.DateTimeIn
                        };
                        var purchaseGrossRestrictionResult = purchaseGrossWtRestrictionRepository.CheckRestriction(purchaseGrossRestrictionresult);
                        if (purchaseGrossRestrictionResult != null)
                        {
                            modelStateDict.Add(nameof(Inyard.GrossWt), ValidationMessages.PurchaseGrossInvalid(purchaseGrossRestrictionResult.DTRestriction));
                        }
                    }
                }

                #region VALIDATE INSPECTOR/WEIGHER
                if (model.WeigherInId.IsNull())
                {
                    modelStateDict.Add(nameof(model.WeigherInId), ValidationMessages.Required("Inspector is required."));
                }
                else if (UserAccountExists(model.WeigherInId) == false)
                {
                    modelStateDict.Add(nameof(model.BaleTypeId), ValidationMessages.UserNotExists);
                }
                #endregion

                if (modelStateDict.Count > 0)
                {
                    return(modelStateDict);
                }
            }
            else
            {
                #region VALIDATE INSPECTOR/WEIGHER
                if (model.WeigherOutId.IsNull())
                {
                    modelStateDict.Add(nameof(model.WeigherOutId), ValidationMessages.Required("Inspector is required."));
                }
                else if (UserAccountExists(model.WeigherOutId) == false)
                {
                    modelStateDict.Add(nameof(model.WeigherOutId), ValidationMessages.UserNotExists);
                }
                #endregion
            }

            #region VALIDATE VEHICLE NUM
            if (model.VehicleNum.IsNull())
            {
                modelStateDict.Add(nameof(model.VehicleNum), ValidationMessages.Required("Vehicle Number"));
            }
            #endregion

            #region VALIDATE BALE TYPE
            if (model.BaleTypeId.IsNullOrZero())
            {
                modelStateDict.Add(nameof(model.BaleTypeId), ValidationMessages.Required("Bale Type"));
            }
            else if (BaleTypeExists(model.BaleTypeId) == false)
            {
                modelStateDict.Add(nameof(model.BaleTypeId), ValidationMessages.BaleTypeNotExists);
            }
            #endregion

            if (model.TransactionTypeCode == "I")
            {
                if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_IN)
                {
                    if (model.GrossWt == 0)
                    {
                        modelStateDict.Add(nameof(model.GrossWt), ValidationMessages.InvalidWeight);
                    }
                }
                else if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_OUT)
                {
                    if (model.MC == 0)
                    {
                        modelStateDict.Add(nameof(model.MC), ValidationMessages.Required("MC"));
                    }
                    if (model.TareWt == 0 || model.NetWt == 0)
                    {
                        modelStateDict.Add(nameof(model.TareWt), ValidationMessages.InvalidWeight);
                    }

                    var corrected10 = 0M;
                    if (model.MC != 0 & model.NetWt != 0)
                    {
                        var correctedMC = moistureSettingsRepository.GetCorrectedMC(model.MC, model.NetWt);
                        corrected10 = correctedMC.Corrected10;
                    }

                    #region VALIDATE RECEIPT NUM
                    //var receiptNum = refNumRepository.Get().FirstOrDefault().PurchaseReceiptNum;
                    if (dbContext.PurchaseTransactions.AsNoTracking().Count(a => a.ReceiptNum == model.InyardNum) > 0)
                    {
                        modelStateDict.Add(nameof(model.InyardNum), ValidationMessages.InvalidReceiptNum);
                    }
                    #endregion

                    #region VALIDATE MOISTURE READER
                    if (model.MoistureReaderId.IsNullOrZero())
                    {
                        modelStateDict.Add(nameof(model.MoistureReaderId), ValidationMessages.Required("Moisture Reader"));
                    }
                    else if (MoistureReaderExists(model.MoistureReaderId ?? 0) == false)
                    {
                        modelStateDict.Add(nameof(model.MoistureReaderId), ValidationMessages.MoistureReaderNotExists);
                    }
                    #endregion

                    #region VALIDATE MC FILE
                    if (ValidateMCFile(model) == false)
                    {
                        modelStateDict.Add(nameof(model.MC), ValidationMessages.MCFileInvalid);
                    }
                    #endregion
                }

                #region VALIDATE DR
                if (model.DRNum.IsNull())
                {
                    modelStateDict.Add(nameof(model.DRNum), ValidationMessages.Required("DR Number"));
                }
                #endregion
                #region VALIDATE SUPPLIER
                if (model.ClientId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.ClientId), ValidationMessages.Required("Supplier"));
                }
                else if (SupplierExists(model.ClientId) == false)
                {
                    modelStateDict.Add(nameof(model.ClientName), ValidationMessages.SupplierNotExists);
                }
                #endregion

                #region VALIDATE MATERIAL
                if (model.CommodityId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.CommodityId), ValidationMessages.Required("Material"));
                }
                else if (RawMaterialExists(model.CommodityId) == false)
                {
                    modelStateDict.Add(nameof(model.CommodityId), ValidationMessages.RawMaterialNotExists);
                }
                #endregion

                #region VALIDATE SOURCE
                if (model.SourceId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.SourceId), ValidationMessages.Required("Source"));
                }
                else if (SourceExists(model.SourceId) == false)
                {
                    modelStateDict.Add(nameof(model.SourceId), ValidationMessages.SourceNotExists);
                }
                #endregion

                #region VALIDATE PO

                var po = purchaseOrderRepository.ValidatePO(new PurchaseOrder()
                {
                    PurchaseOrderId = model.PurchaseOrderId ?? 0
                });
                if (po == null)
                {
                    modelStateDict.Add(nameof(model.PurchaseOrderId), ValidationMessages.POInvalid);
                }
                else if (po.BalanceRemainingKg < -5000)
                {
                    modelStateDict.Add(nameof(model.PurchaseOrderId), ValidationMessages.PORemainingBalanceInvalid);
                }

                #endregion
            }

            if (model.TransactionTypeCode == "O")
            {
                if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_IN)
                {
                    if (model.TareWt == 0)
                    {
                        modelStateDict.Add(nameof(model.TareWt), ValidationMessages.InvalidWeight);
                    }
                }
                else if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_OUT)
                {
                    if (model.MC == 0)
                    {
                        modelStateDict.Add(nameof(model.MC), ValidationMessages.Required("MC"));
                    }
                    if (model.TareWt == 0 || model.NetWt == 0)
                    {
                        modelStateDict.Add(nameof(model.TareWt), ValidationMessages.InvalidWeight);
                    }

                    var receiptNum = refNumRepository.Get().FirstOrDefault().PurchaseReceiptNum;
                    if (dbContext.SaleTransactions.AsNoTracking().Count(a => a.ReceiptNum == receiptNum) > 0)
                    {
                        modelStateDict.Add(nameof(model.InyardNum), ValidationMessages.InvalidReceiptNum);
                    }
                    if (model.BaleCount == 0)
                    {
                        modelStateDict.Add(nameof(model.BaleCount), ValidationMessages.Required("Bale Count"));
                    }

                    #region VALIDATE MOISTURE READER
                    if (model.MoistureReaderId.IsNullOrZero())
                    {
                        modelStateDict.Add(nameof(model.MoistureReaderId), ValidationMessages.Required("Moisture Reader"));
                    }
                    else if (MoistureReaderExists(model.MoistureReaderId ?? 0) == false)
                    {
                        modelStateDict.Add(nameof(model.MoistureReaderId), ValidationMessages.MoistureReaderNotExists);
                    }
                    #endregion
                }

                #region VALIDATE CUSTOMER / HAULER
                if (model.ClientId.IsNullOrZero() && model.HaulerId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.ClientId), ValidationMessages.Required("Customer/Hauler"));
                }
                if (model.ClientId.IsNullOrZero() == false)
                {
                    if (CustomerExists(model.ClientId) == false)
                    {
                        modelStateDict.Add(nameof(model.ClientId), ValidationMessages.CustomerNotExists);
                    }
                }
                if (model.HaulerId.IsNullOrZero() == false)
                {
                    if (HaulerExists(model.HaulerId ?? 0) == false)
                    {
                        modelStateDict.Add(nameof(model.HaulerId), ValidationMessages.HaulerNotExists);
                    }
                }
                #endregion

                #region VALIDATE PRODUCT
                if (model.CommodityId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.CommodityId), ValidationMessages.Required("Product"));
                }
                else if (ProductExists(model.CommodityId) == false)
                {
                    modelStateDict.Add(nameof(model.CommodityId), ValidationMessages.ProductNotExists);
                }
                #endregion

                #region VALIDATE BALES
                if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_OUT)
                {
                    if (model.Bales.Count() > 0)
                    {
                        var unRelatedBalesCount = model.Bales.Count(a => a.ProductId != model.CommodityId);
                        if (unRelatedBalesCount > 0)
                        {
                            modelStateDict.Add(nameof(model.CommodityId), "Selected bales must match the product type.");
                        }
                        ;
                    }
                }
                #endregion

                #region VALIDATE PAPER MILL
                if (model.PaperMillId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.PaperMillId), ValidationMessages.Required("Paper Mill"));
                }
                else if (PaperMillExists(model.PaperMillId ?? 0) == false)
                {
                    modelStateDict.Add(nameof(model.PaperMillId), ValidationMessages.ProductNotExists);
                }
                #endregion
            }

            return(modelStateDict);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
        public IActionResult GetCorrected([FromQuery] decimal mc, [FromQuery] decimal wt)
        {
            var result = repository.GetCorrectedMC(mc, wt);

            return(Ok(result));
        }