Ejemplo n.º 1
0
        /// <summary>
        /// Insert new record into database.
        /// </summary>
        /// <param name="database"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public int AddNew(Database database, ActualOnhandViewDTO data)
        {
            Database db = UseDatabase(database);

            StringBuilder sb = new StringBuilder();

            #region SQL Statement
            sb.AppendLine(" INSERT INTO " + data.TableName + "(");
            sb.AppendLine("  " + ActualOnhandViewDTO.eColumns.ITEM_CD);
            sb.AppendLine("  ," + ActualOnhandViewDTO.eColumns.LOC_CD);
            sb.AppendLine("  ," + ActualOnhandViewDTO.eColumns.LOT_NO);
            sb.AppendLine("  ," + ActualOnhandViewDTO.eColumns.ONHAND_QTY);
            sb.AppendLine(") VALUES(");
            sb.AppendLine("   :ITEM_CD");
            sb.AppendLine("   ,:LOC_CD");
            sb.AppendLine("   ,:LOT_NO");
            sb.AppendLine("   ,:ONHAND_QTY");
            sb.AppendLine(" )");
            #endregion

            DataRequest req = new DataRequest(sb.ToString());
            #region Parameters
            req.Parameters.Add("ITEM_CD", DataType.NVarChar, data.ITEM_CD.Value);
            req.Parameters.Add("LOC_CD", DataType.NVarChar, data.LOC_CD.Value);
            req.Parameters.Add("LOT_NO", DataType.NVarChar, data.LOT_NO.Value);
            req.Parameters.Add("ONHAND_QTY", DataType.Number, data.ONHAND_QTY.Value);
            #endregion

            return(db.ExecuteNonQuery(req));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Update record by using the table's primary key.
        /// </summary>
        /// <param name="database"></param>
        /// <param name="data">Data which to update.</param>
        /// <param name="oldITEM_CD">Old Key #1</param>
        /// <param name="oldLOC_CD">Old Key #2</param>
        /// <param name="oldLOT_NO">Old Key #3</param>
        /// <returns></returns>
        public int UpdateWithPK(Database database, ActualOnhandViewDTO data, NZString oldITEM_CD, NZString oldLOC_CD, NZString oldLOT_NO)
        {
            Database db = UseDatabase(database);

            StringBuilder sb = new StringBuilder();

            #region SQL Statement
            sb.AppendLine(" UPDATE " + data.TableName);
            sb.AppendLine(" SET ");
            sb.AppendLine("  " + ActualOnhandViewDTO.eColumns.ITEM_CD + "=:ITEM_CD");
            sb.AppendLine("  ," + ActualOnhandViewDTO.eColumns.LOC_CD + "=:LOC_CD");
            sb.AppendLine("  ," + ActualOnhandViewDTO.eColumns.LOT_NO + "=:LOT_NO");
            sb.AppendLine("  ," + ActualOnhandViewDTO.eColumns.ONHAND_QTY + "=:ONHAND_QTY");
            sb.AppendLine(" WHERE ");
            sb.AppendLine("  " + ActualOnhandViewDTO.eColumns.ITEM_CD + "=:oldITEM_CD");
            sb.AppendLine("  AND " + ActualOnhandViewDTO.eColumns.LOC_CD + "=:oldActualOnhandView");
            sb.AppendLine("  AND " + ActualOnhandViewDTO.eColumns.LOT_NO + "=:oldActualOnhandView");
            #endregion

            DataRequest req = new DataRequest(sb.ToString());
            #region Parameters
            req.Parameters.Add("ITEM_CD", DataType.NVarChar, data.ITEM_CD.Value);
            req.Parameters.Add("LOC_CD", DataType.NVarChar, data.LOC_CD.Value);
            req.Parameters.Add("LOT_NO", DataType.NVarChar, data.LOT_NO.Value);
            req.Parameters.Add("ONHAND_QTY", DataType.Number, data.ONHAND_QTY.Value);
            req.Parameters.Add("oldITEM_CD", DataType.NVarChar, oldITEM_CD.Value);
            req.Parameters.Add("oldLOC_CD", DataType.NVarChar, oldLOC_CD.Value);
            req.Parameters.Add("oldLOT_NO", DataType.NVarChar, oldLOT_NO.Value);
            #endregion

            return(db.ExecuteNonQuery(req));
        }
Ejemplo n.º 3
0
        public ErrorItem CheckOnhandQty_AfterTR(Database db, EVOFramework.Windows.Forms.IControlIdentify owner, NZString ItemCD, NZString LocationCD, NZString LotNo)
        {
            // FIRST CHECK FOR LOCATION IF IT ALLOW NEGATIVE STOCK
            DealingBIZ bizLoc = new DealingBIZ();
            DealingDTO dtoLoc = bizLoc.LoadLocation(LocationCD);

            if (!dtoLoc.ALLOW_NEGATIVE.IsNull && dtoLoc.ALLOW_NEGATIVE.StrongValue == DataDefine.Convert2ClassCode(DataDefine.eALLOW_NEGATIVE.Yes))
            {
                // IF THE LOCATION IS ALLOW FOR NEGATIVE THEN NOT CHECK ONHAND
                return(null);
            }

            InventoryBIZ        biz = new InventoryBIZ();
            ActualOnhandViewDTO dto = biz.LoadActualInventoryOnHand(db, ItemCD, LocationCD, LotNo);

            SysConfigBIZ bizConfig   = new SysConfigBIZ();
            SysConfigDTO dtoMinusQty = bizConfig.LoadByPK(DataDefine.eSYSTEM_CONFIG.LOCATION.SYS_GROUP_ID, (NZString)DataDefine.eSYSTEM_CONFIG.LOCATION.SYS_KEY.MINUS_QTY.ToString());

            decimal decMinusQty = 0;

            decimal.TryParse(dtoMinusQty.CHAR_DATA.StrongValue, out decMinusQty);

            if (dto.ONHAND_QTY < decMinusQty)
            {
                return(new ErrorItem(owner, TKPMessages.eValidate.VLM0063.ToString(), new[] { ItemCD, LocationCD }));
            }
            return(null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Check On hand Inventory function follow business rule
        /// </summary>
        /// <param name="eOperation"></param>
        /// <param name="eInoutCls"></param>
        /// <param name="QTY"></param>
        /// <param name="ItemCD"></param>
        /// <param name="LocationCD"></param>
        /// <param name="LotNo"></param>
        /// <param name="strTranID">in case of Update, this value must be sent, the others send null.</param>
        /// <returns></returns>
        public ErrorItem CheckOnhandQty(DataDefine.eOperationClass eOperation, DataDefine.eIN_OUT_CLASS eInoutCls, NZDecimal QTY, NZString ItemCD, NZString LocationCD, NZString LotNo, NZString strTranID)
        {
            // FIRST CHECK FOR LOCATION IF IT ALLOW NEGATIVE STOCK
            DealingBIZ bizLoc = new DealingBIZ();
            DealingDTO dtoLoc = bizLoc.LoadLocation(LocationCD);

            if (!dtoLoc.ALLOW_NEGATIVE.IsNull && dtoLoc.ALLOW_NEGATIVE.StrongValue == DataDefine.Convert2ClassCode(DataDefine.eALLOW_NEGATIVE.Yes))
            {
                // IF THE LOCATION IS ALLOW FOR NEGATIVE THEN NOT CHECK ONHAND
                return(null);
            }

            //Operation Class
            switch (eOperation)
            {
            case DataDefine.eOperationClass.Add:
                //Do notting
                break;

            case DataDefine.eOperationClass.Update:
                //Find Diff Qty
                InventoryTransBIZ       biz = new InventoryTransBIZ();
                InventoryTransactionDTO dto = biz.LoadByTransactionID(strTranID);
                if (dto != null)
                {
                    QTY = (QTY - dto.QTY).ToNZDecimal();
                }
                break;

            case DataDefine.eOperationClass.Delete:
                //Delete Inverse Qty
                QTY = (-1 * QTY.StrongValue).ToNZDecimal();
                break;
            }

            //inout Class
            if (eInoutCls == DataDefine.eIN_OUT_CLASS.Out)
            {
                QTY = (-1 * QTY.StrongValue).ToNZDecimal();
            }

            // CHECK FOR ONHAND WITH ACTUAL INVENTORY ONHAND
            InventoryBIZ        bizInv             = new InventoryBIZ();
            ActualOnhandViewDTO dtoActOnhand       = bizInv.LoadActualInventoryOnHand(ItemCD, LocationCD, LotNo);
            decimal             decActualOnhandQty = 0;

            if (dtoActOnhand != null && !dtoActOnhand.ONHAND_QTY.IsNull)
            {
                decActualOnhandQty = dtoActOnhand.ONHAND_QTY.StrongValue;
            }

            decActualOnhandQty = decActualOnhandQty + QTY;

            if (decActualOnhandQty < 0)
            {
                return(new ErrorItem(QTY.Owner, TKPMessages.eValidate.VLM0063.ToString(), new[] { ItemCD, LocationCD }));
            }
            return(null);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Check exist before manipulate data. If found record will update data. Otherwise insert new data.
        /// </summary>
        /// <param name="database"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public int AddNewOrUpdate(Database database, ActualOnhandViewDTO data)
        {
            Database db = UseDatabase(database);

            if (Exist(database, data.ITEM_CD, data.LOC_CD, data.LOT_NO))
            {
                return(UpdateWithoutPK(db, data));
            }

            return(AddNew(db, data));
        }
Ejemplo n.º 6
0
        private decimal GetOnhandQty(NZString ItemCD, NZString LocCD, NZString LotNo)
        {
            // get Onhand Qty

            InventoryBIZ        bizInv = new InventoryBIZ();
            ActualOnhandViewDTO dto    =
                bizInv.LoadActualInventoryOnHand(ItemCD, LocCD, LotNo);

            if (dto != null)
            {
                return(dto.ONHAND_QTY.StrongValue);
            }
            return(0);
        }
Ejemplo n.º 7
0
        public ErrorItem CheckOnhandQty(NZString YearMonth, NZString ItemCD, NZString FromLoc, NZString LotNo)
        {
            InventoryBIZ        bizInv    = new InventoryBIZ();
            InventoryPeriodDTO  dtoPeriod = new InventoryPeriodBIZ().LoadByPK(YearMonth);
            ActualOnhandViewDTO dtoOnhand = bizInv.LoadActualInventoryOnHand(ItemCD, FromLoc, LotNo);

            if (dtoOnhand == null)
            {
                return(new ErrorItem(YearMonth.Owner, TKPMessages.eValidate.VLM0029.ToString()));
            }
            if (dtoOnhand.ONHAND_QTY.IsNull || dtoOnhand.ONHAND_QTY.StrongValue == 0)
            {
                return(new ErrorItem(YearMonth.Owner, TKPMessages.eValidate.VLM0029.ToString()));
            }

            return(null);
        }
Ejemplo n.º 8
0
        public NZDecimal GetOnhandQty(NZDateTime adjustDate, NZString itemCode, NZString locationCode, NZString lotNo)
        {
            InventoryBIZ biz = new InventoryBIZ();

            if (itemCode.IsNull || locationCode.IsNull)
            {
                return((NZDecimal)0);
            }

            ActualOnhandViewDTO dto = biz.LoadActualInventoryOnHand(itemCode, locationCode, lotNo);

            if (dto == null)
            {
                return((NZDecimal)0);
            }

            return(dto.ONHAND_QTY);
        }
Ejemplo n.º 9
0
        public ErrorItem CheckShipQTY(NZString ItemCD, NZString LocCD, NZString LotNo, NZDecimal ShipQTY)
        {
            if (ShipQTY.IsNull || ShipQTY.StrongValue == 0)
            {
                return(new ErrorItem(ShipQTY.Owner, TKPMessages.eValidate.VLM0039.ToString()));
            }

            InventoryBIZ        biz = new InventoryBIZ();
            ActualOnhandViewDTO dto = biz.LoadActualInventoryOnHand(ItemCD, LocCD, LotNo);


            if (dto == null || dto.ONHAND_QTY.IsNull || dto.ONHAND_QTY.StrongValue == 0)
            {
                return(new ErrorItem(null, TKPMessages.eValidate.VLM0029.ToString()));
            }

            if (ShipQTY.StrongValue > dto.ONHAND_QTY.StrongValue)
            {
                return(new ErrorItem(ShipQTY.Owner, TKPMessages.eValidate.VLM0040.ToString()));
            }
            return(null);
        }
Ejemplo n.º 10
0
        private InventoryTransactionDTO CreateDTOForConsumption(WorkResultEntryUIDM model, ActualOnhandViewDTO line)
        {
            InventoryTransactionDTO dto = new InventoryTransactionDTO();

            //dto.TRANS_ID = line.TRANS_ID; // TRANS_ID จะได้มาเองตอน add transaction
            //dto.ITEM_CD = line.ITEM_CD;
            //dto.LOC_CD = model.OrderLoc;
            //dto.LOT_NO = line.LOT_NO;
            //dto.TRANS_DATE = model.WorkResultDate;
            //dto.TRANS_CLS.Value = DataDefine.Convert2ClassCode(DataDefine.eTRANS_TYPE.Consumption);
            //dto.IN_OUT_CLS.Value = DataDefine.Convert2ClassCode(DataDefine.eIN_OUT_CLASS.Out);
            //dto.QTY = line.ONHAND_QTY;
            //dto.OBJ_ITEM_CD = model.ItemCode;
            //dto.OBJ_ORDER_QTY = model.WorkResultQty;
            //dto.REMARK = model.Remark;
            //dto.REF_SLIP_CLS.Value = DataDefine.Convert2ClassCode(DataDefine.eREF_SLIP_CLS.WorkResult);
            //dto.CRT_BY = Common.CurrentUserInfomation.UserCD;
            //dto.CRT_MACHINE = Common.CurrentUserInfomation.Machine;
            //dto.UPD_BY = Common.CurrentUserInfomation.UserCD;
            //dto.UPD_MACHINE = Common.CurrentUserInfomation.Machine;
            //dto.SHIFT_CLS = model.ShipClass;
            //dto.SCREEN_TYPE = DataDefine.ScreenType.WorkResultEntry.ToNZString();
            return(dto);
        }