Esempio n. 1
0
        /// <summary>
        /// 庫存異動資料-申請覆核
        /// </summary>
        /// <param name="saveData"></param>
        /// <param name="searchModel"></param>
        /// <returns></returns>
        public MSGReturnModel <IEnumerable <ICDCItem> > CDCApplyAudit(IEnumerable <ICDCItem> saveData, CDCSearchViewModel searchModel)
        {
            MSGReturnModel <IEnumerable <ICDCItem> > result = new MSGReturnModel <IEnumerable <ICDCItem> >();

            result.RETURN_FLAG = false;
            string   logStr = string.Empty;
            DateTime dt     = DateTime.Now;

            using (TreasuryDBEntities db = new TreasuryDBEntities())
            {
                bool changFlag = false;
                var  _data     = SaveINVENTORY_CHG_APLY(db, searchModel, logStr, dt);
                logStr = _data.Item2;
                foreach (CDCBillViewModel model in saveData)
                {
                    var _Bill = db.ITEM_BLANK_NOTE.FirstOrDefault(x => x.ITEM_ID == model.vItemId);
                    if (_Bill != null && !changFlag)
                    {
                        if (_Bill.LAST_UPDATE_DT > model.vLast_Update_Time || _Bill.INVENTORY_STATUS != "1")
                        {
                            changFlag = true;
                        }
                        if (!changFlag)
                        {
                            _Bill.INVENTORY_STATUS   = "8"; //庫存狀態改為「8」資料庫異動中。
                            _Bill.ISSUING_BANK_AFT   = model.vBill_Issuing_Bank_AFT;
                            _Bill.CHECK_TYPE_AFT     = model.vBill_Check_Type_AFT;
                            _Bill.CHECK_NO_TRACK_AFT = model.vBill_Check_No_Track_AFT;
                            _Bill.CHECK_NO_B_AFT     = model.vBill_Check_No_B_AFT;
                            _Bill.CHECK_NO_E_AFT     = model.vBill_Check_No_E_AFT;
                            _Bill.LAST_UPDATE_DT     = dt;

                            logStr += _Bill.modelToString(logStr);

                            var _BNA = new BLANK_NOTE_APLY()
                            {
                                APLY_NO        = _data.Item1,
                                ITEM_ID        = _Bill.ITEM_ID,
                                ISSUING_BANK   = model.vBill_Issuing_Bank_AFT,
                                CHECK_TYPE     = model.vBill_Check_Type_AFT.IsNullOrEmpty() ? string.Empty : model.vBill_Check_Type_AFT,
                                CHECK_NO_TRACK = model.vBill_Check_No_Track_AFT.IsNullOrEmpty() ? string.Empty : model.vBill_Check_No_Track_AFT,
                                CHECK_NO_B     = model.vBill_Check_No_B_AFT.IsNullOrEmpty() ? string.Empty : model.vBill_Check_No_B_AFT,
                                CHECK_NO_E     = model.vBill_Check_No_E_AFT.IsNullOrEmpty() ? string.Empty : model.vBill_Check_No_E_AFT
                            };

                            db.BLANK_NOTE_APLY.Add(_BNA);

                            logStr += _BNA.modelToString(logStr);
                        }
                    }
                    else
                    {
                        changFlag = true;
                    }
                }
                if (changFlag)
                {
                    result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription();
                }
                else
                {
                    db.SaveChanges();
                    #region LOG
                    //新增LOG
                    Log log = new Log();
                    log.CFUNCTION = "申請覆核-資料庫異動:空白票據";
                    log.CACTION   = "A";
                    log.CCONTENT  = logStr;
                    LogDao.Insert(log, searchModel.vCreate_Uid);
                    #endregion
                    result.RETURN_FLAG = true;
                    result.DESCRIPTION = Ref.MessageType.Apply_Audit_Success.GetDescription(null, $@"申請單號:{_data.Item1}");
                    result.Datas       = GetCDCSearchData(searchModel);
                }
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 申請覆核動作
        /// </summary>
        /// <param name="insertDatas"></param>
        /// <param name="taData"></param>
        /// <returns></returns>
        public MSGReturnModel <IEnumerable <ITreaItem> > ApplyAudit(IEnumerable <ITreaItem> insertDatas, TreasuryAccessViewModel taData)
        {
            var result = new MSGReturnModel <IEnumerable <ITreaItem> >();

            result.RETURN_FLAG = false;
            DateTime dt = DateTime.Now;

            try
            {
                if (insertDatas != null)
                {
                    //取得流水號
                    SysSeqDao sysSeqDao = new SysSeqDao();
                    String    qPreCode  = DateUtil.getCurChtDateTime().Split(' ')[0];
                    var       datas     = (List <BillViewModel>)insertDatas;
                    string    logStr    = string.Empty;       //log
                    var       item_Seq  = "E2";               //空白票卷流水號開頭編碼
                    if (!taData.vAplyNo.IsNullOrWhiteSpace()) //修改已存在申請單
                    {
                        if (datas.Any())
                        {
                            using (TreasuryDBEntities db = new TreasuryDBEntities())
                            {
                                var _APLY_STATUS = Ref.AccessProjectFormStatus.A01.ToString(); //表單申請

                                #region 申請單紀錄檔
                                var _TAR = db.TREA_APLY_REC.First(x => x.APLY_NO == taData.vAplyNo);
                                if (CustodyAppr.Contains(_TAR.APLY_STATUS))
                                {
                                    _APLY_STATUS     = CustodyConfirmStatus;
                                    _TAR.CUSTODY_UID = AccountController.CurrentUserId; //保管單位直接帶使用者
                                    _TAR.CUSTODY_DT  = dt;
                                }
                                else
                                {
                                    if (_TAR.APLY_STATUS != _APLY_STATUS)                          //申請紀錄檔狀態不是在表單申請狀態
                                    {
                                        _APLY_STATUS = Ref.AccessProjectFormStatus.A05.ToString(); //為重新申請案例
                                    }
                                }
                                _TAR.APLY_STATUS    = _APLY_STATUS;
                                _TAR.LAST_UPDATE_DT = dt;
                                logStr += _TAR.modelToString(logStr);
                                #endregion

                                #region 申請單歷程檔
                                var _ARH = new APLY_REC_HIS()
                                {
                                    APLY_NO     = taData.vAplyNo,
                                    APLY_STATUS = _APLY_STATUS,
                                    PROC_DT     = dt,
                                    PROC_UID    = taData.vCreateUid
                                };
                                logStr += _ARH.modelToString(logStr);
                                db.APLY_REC_HIS.Add(_ARH);
                                #endregion

                                #region 空白票據申請資料檔
                                List <BLANK_NOTE_APLY> updates = new List <BLANK_NOTE_APLY>();
                                List <BLANK_NOTE_APLY> inserts = new List <BLANK_NOTE_APLY>();

                                foreach (var item in datas)
                                {
                                    if (item.vItemId.StartsWith(item_Seq)) // 舊有資料
                                    {
                                        var _BNA = db.BLANK_NOTE_APLY.First(
                                            x => x.ITEM_ID == item.vItemId &&
                                            x.APLY_NO == taData.vAplyNo);
                                        _BNA.CHECK_TYPE     = item.vCheckType;
                                        _BNA.ISSUING_BANK   = item.vIssuingBank;
                                        _BNA.CHECK_NO_TRACK = item.vCheckNoTrack;
                                        _BNA.CHECK_NO_B     = item.vCheckNoB;
                                        _BNA.CHECK_NO_E     = item.vCheckNoE;
                                        updates.Add(_BNA);
                                        logStr += _BNA.modelToString(logStr);
                                    }
                                    else
                                    {
                                        var item_id = sysSeqDao.qrySeqNo(item_Seq, string.Empty).ToString().PadLeft(8, '0');
                                        var _BNA    = new BLANK_NOTE_APLY()
                                        {
                                            APLY_NO        = _TAR.APLY_NO,
                                            ITEM_ID        = $@"{item_Seq}{item_id}",
                                            CHECK_TYPE     = item.vCheckType,
                                            ISSUING_BANK   = item.vIssuingBank,
                                            CHECK_NO_TRACK = item.vCheckNoTrack,
                                            CHECK_NO_B     = item.vCheckNoB,
                                            CHECK_NO_E     = item.vCheckNoE
                                        };
                                        inserts.Add(_BNA);
                                        logStr += _BNA.modelToString(logStr);
                                    }
                                }

                                var ups = updates.Select(x => x.ITEM_ID).ToList();

                                db.BLANK_NOTE_APLY.RemoveRange(
                                    db.BLANK_NOTE_APLY.Where(x => x.APLY_NO == taData.vAplyNo && !ups.Contains(x.ITEM_ID)).ToList());
                                db.BLANK_NOTE_APLY.AddRange(inserts);

                                #endregion

                                #region Save Db

                                var validateMessage = db.GetValidationErrors().getValidateString();
                                if (validateMessage.Any())
                                {
                                    result.DESCRIPTION = validateMessage;
                                }
                                else
                                {
                                    try
                                    {
                                        db.SaveChanges();

                                        #region LOG
                                        //新增LOG
                                        Log log = new Log();
                                        log.CFUNCTION = "申請覆核-修改空白票據";
                                        log.CACTION   = "U";
                                        log.CCONTENT  = logStr;
                                        LogDao.Insert(log, _TAR.CREATE_UID);
                                        #endregion

                                        result.RETURN_FLAG = true;
                                        result.DESCRIPTION = Ref.MessageType.Apply_Audit_Success.GetDescription(null, $@"單號為{_TAR.APLY_NO}");
                                    }
                                    catch (DbUpdateException ex)
                                    {
                                        result.DESCRIPTION = ex.exceptionMessage();
                                    }
                                }
                                #endregion
                            }
                        }
                        else
                        {
                            result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                        }
                    }
                    else //新增申請單
                    {
                        //取出只抓狀態為預約取出的資料
                        if (taData.vAccessType == Ref.AccessProjectTradeType.G.ToString())
                        {
                            datas = datas.Where(x => x.vStatus == Ref.AccessInventoryType._4.GetDescription()).ToList();
                        }
                        if (datas.Any())
                        {
                            using (TreasuryDBEntities db = new TreasuryDBEntities())
                            {
                                #region 申請單紀錄檔 & 申請單歷程檔

                                var data = SaveTREA_APLY_REC(db, taData, logStr, dt);

                                logStr = data.Item2;

                                #endregion

                                string _ITEM_BLANK_NOTE_ITEM_ID = null; //紀錄空白票據申請資料檔 對應空白票據庫存資料檔 物品編號

                                bool _changFlag = false;
                                datas.ForEach(x =>
                                {
                                    #region 取出時要把空白票據資料 做切段動作
                                    if (taData.vAccessType == Ref.AccessProjectTradeType.G.ToString()) //取出時要把空白票據資料 做切段動作
                                    {
                                        var _blank_Note = db.ITEM_BLANK_NOTE.FirstOrDefault(y => y.ITEM_ID == x.vItemId);
                                        if (_blank_Note != null)
                                        {
                                            if (_blank_Note.LAST_UPDATE_DT > x.vLast_Update_Time || _blank_Note.INVENTORY_STATUS != "1")
                                            {
                                                _changFlag = true;
                                            }
                                            else
                                            {
                                                _ITEM_BLANK_NOTE_ITEM_ID = _blank_Note.ITEM_ID;
                                                //全部取出
                                                if (x.vTakeOutE == _blank_Note.CHECK_NO_E)
                                                {
                                                    _blank_Note.INVENTORY_STATUS = "4"; //預約取出
                                                }
                                                //分段取出
                                                else
                                                {
                                                    _blank_Note.CHECK_NO_B = (TypeTransfer.stringToInt(x.vTakeOutE) + 1).ToString().PadLeft(7, '0');
                                                }
                                                _blank_Note.LAST_UPDATE_DT = dt;
                                            }
                                        }
                                        else
                                        {
                                            _changFlag = true;
                                        }
                                    }
                                    #endregion

                                    #region 空白票據申請資料檔
                                    var item_id = sysSeqDao.qrySeqNo(item_Seq, string.Empty).ToString().PadLeft(8, '0');
                                    var _BNA    = new BLANK_NOTE_APLY()
                                    {
                                        APLY_NO                 = data.Item1,
                                        ITEM_ID                 = $@"{item_Seq}{item_id}",
                                        CHECK_TYPE              = x.vCheckType,
                                        ISSUING_BANK            = x.vIssuingBank,
                                        CHECK_NO_TRACK          = x.vCheckNoTrack,
                                        CHECK_NO_B              = x.vCheckNoB,
                                        CHECK_NO_E              = taData.vAccessType == Ref.AccessProjectTradeType.P.ToString() ? x.vCheckNoE : x.vTakeOutE,
                                        ITEM_BLANK_NOTE_ITEM_ID = _ITEM_BLANK_NOTE_ITEM_ID
                                    };
                                    db.BLANK_NOTE_APLY.Add(_BNA);
                                    logStr += _BNA.modelToString(logStr);
                                    #endregion
                                });
                                if (_changFlag)
                                {
                                    result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription();
                                    return(result);
                                }
                                #region Save Db

                                var validateMessage = db.GetValidationErrors().getValidateString();
                                if (validateMessage.Any())
                                {
                                    result.DESCRIPTION = validateMessage;
                                }
                                else
                                {
                                    try
                                    {
                                        db.SaveChanges();

                                        #region LOG
                                        //新增LOG
                                        Log log = new Log();
                                        log.CFUNCTION = "申請覆核-新增空白票據";
                                        log.CACTION   = "A";
                                        log.CCONTENT  = logStr;
                                        LogDao.Insert(log, taData.vCreateUid);
                                        #endregion

                                        result.RETURN_FLAG = true;
                                        result.DESCRIPTION = Ref.MessageType.Apply_Audit_Success.GetDescription(null, $@"單號為{data.Item1}");
                                    }
                                    catch (DbUpdateException ex)
                                    {
                                        result.DESCRIPTION = ex.exceptionMessage();
                                    }
                                }
                                #endregion
                            }
                        }
                        else
                        {
                            result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                        }
                    }
                }
                else
                {
                    result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                }
            }
            catch (Exception ex)
            {
                result.DESCRIPTION = ex.exceptionMessage();
            }

            return(result);
        }