public void LogJournalTransaction(oJournal obj, bool isPosted, string action, string origin, ErrorLog errLog = null)
        {
            try
            {
                log.TransactionNo = obj.TransId.ToString();
                log.Origin        = origin;
                log.Type          = TransactionLog.SBOType.JE;
                log.LogDate       = DateTime.Now;
                log.IsPosted      = isPosted;

                TransactionData rawData = new TransactionData();
                rawData.PostedOn = obj.DocDate;
                rawData.RawData  = JsonConvert.SerializeObject(obj);

                log.RawData   = rawData;
                log.Action    = action;
                log.CreatedBy = obj.CreatedBy;
                log.CreatedOn = obj.CreateDate;
                repo.AddOrUpdate(log);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #2
0
        public int Add(oJournal obj)
        {
            JournalEntries jrnls = (JournalEntries)SboComObject.GetBusinessObject(BoObjectTypes.oJournalEntries);

            try
            {
                SboComObject.StartTransaction();

                int retCode = 0;

                jrnls.DueDate       = obj.DocDueDate;
                jrnls.TaxDate       = obj.TaxDate;
                jrnls.ReferenceDate = obj.DocDate;
                jrnls.Memo          = obj.JournalMemo;
                jrnls.ProjectCode   = obj.Project;

                if (obj.JournalLines.Count > 0)
                {
                    foreach (oJournalLine jrnlLine in obj.JournalLines)
                    {
                        jrnls.Lines.DueDate        = obj.DocDueDate;
                        jrnls.Lines.TaxDate        = obj.TaxDate;
                        jrnls.Lines.ReferenceDate1 = obj.DocDate;
                        jrnls.Lines.ShortName      = jrnlLine.GLCode;
                        jrnls.Lines.BPLID          = jrnlLine.Segment;
                        jrnls.Lines.Debit          = jrnlLine.Debit;
                        jrnls.Lines.Credit         = jrnlLine.Credit;
                        jrnls.Lines.Add();
                    }
                }

                retCode = jrnls.Add();
                if (retCode != 0)
                {
                    int    errCode    = 0;
                    string errMessage = "";
                    SboComObject.GetLastError(out errCode, out errMessage);
                    GlobalInstance.Instance.SBOErrorCode    = errCode;
                    GlobalInstance.Instance.SBOErrorMessage = errMessage;

                    SboComObject.EndTransaction(BoWfTransOpt.wf_RollBack);
                }
                else
                {
                    SboComObject.EndTransaction(BoWfTransOpt.wf_Commit);
                }

                return(retCode);
            }
            catch (Exception ex)
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(jrnls);
                throw new Exception(GlobalInstance.Instance.SBOErrorMessage == null? ex.Message: GlobalInstance.Instance.SBOErrorMessage);
            }
            finally
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(jrnls);
            }
        }
Пример #3
0
        public async Task <IHttpActionResult> UpdateJournal(oJournal jrnal)
        {
            try
            {
                if (!GlobalInstance.Instance.IsConnected)
                {
                    GlobalInstance.Instance.InitializeSboComObject();
                }

                var j = await repo.GetByTransId(jrnal.TransId);

                if (j == null)
                {
                    errMsg = string.Format("Journal {0} does exist.", jrnal.TransId);
                    var resp = new HttpResponseMessage(HttpStatusCode.NotFound);
                    resp.Content      = new StringContent(errMsg);
                    resp.ReasonPhrase = "Object not found.";
                    var err = ErrorLogger.Log(new ErrorLog
                    {
                        ErrorCode  = (int)HttpStatusCode.Conflict,
                        Message    = errMsg,
                        StackTrace = Environment.StackTrace
                    });

                    transactionLogger.LogJournalTransaction(jrnal, false, err);

                    throw new HttpResponseException(resp);
                }

                if (repo.Update(jrnal) != 0)
                {
                    errMsg = GlobalInstance.Instance.SBOErrorMessage;
                    var resp = new HttpResponseMessage(HttpStatusCode.Conflict);
                    resp.Content      = new StringContent(errMsg);
                    resp.ReasonPhrase = "SBO Error";
                    var err = ErrorLogger.Log(new ErrorLog
                    {
                        ErrorCode  = GlobalInstance.Instance.SBOErrorCode,
                        Message    = errMsg,
                        StackTrace = Environment.StackTrace
                    });

                    transactionLogger.LogJournalTransaction(jrnal, false, err);

                    throw new HttpResponseException(resp);
                }

                return(Ok(string.Format("Journal {0} succesfully updated.", jrnal.TransId)));
            }
            catch (HttpResponseException ex)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }
Пример #4
0
        public async Task <List <oJournal> > GetList(Func <oJournal, bool> fltr)
        {
            try
            {
                List <oJournal> jrnals = new List <oJournal>();

                if (SqlObject != null)
                {
                    //var param = new DynamicParameters();
                    //param.Add("@TransId", dbType: System.Data.DbType.Int32, value: 0, direction: System.Data.ParameterDirection.Input);

                    var jDictionary = new Dictionary <int, oJournal>();
                    var _j          = await SqlObject.QueryAsync <oJournal, oJournalLine, oJournal>("sp_getjournals", map : (j, jl) =>
                    {
                        oJournal jrnl = null;
                        if (!jDictionary.TryGetValue(j.TransId, out jrnl))
                        {
                            jrnl = j;
                            jrnl.JournalLines = new List <oJournalLine>();
                            jDictionary.Add(jrnl.TransId, jrnl);
                        }

                        jrnl.JournalLines.Add(jl);

                        return(jrnl);
                    }, param : null, transaction : null, buffered : true, splitOn : "JournalLinesId", commandTimeout : null, commandType : System.Data.CommandType.StoredProcedure);

                    if (fltr != null)
                    {
                        jrnals = _j.Distinct().Where(fltr).ToList();
                    }
                    else
                    {
                        jrnals = _j.Distinct().ToList();
                    }
                }

                return(jrnals);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #5
0
 public void LogJournalTransaction(oJournal obj, bool isPosted, ErrorLog errLog = null)
 {
     try
     {
         log.TransactionNo     = obj.TransId.ToString();
         log.Origin            = string.Format("{0}-{1}", HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.UserHostName);
         log.Type              = TransactionLog.SBOType.JE;
         log.LogDate           = DateTime.Now;
         log.IsPosted          = isPosted;
         log.TransactionDataID = obj.TransId;
         log.RawData.PostedOn  = obj.DocDate;
         log.RawData.RawData   = JsonConvert.SerializeObject(obj);
         repo.AddOrUpdate(log);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Пример #6
0
        public async Task <List <object> > AddMultipleJournals(List <oJournal> jrnals)
        {
            HttpResponseMessage _resp   = new HttpResponseMessage();
            List <object>       retList = new List <object>();


            try
            {
                if (!GlobalInstance.Instance.IsConnected)
                {
                    GlobalInstance.Instance.InitializeSboComObject();
                }
                oJournal j = null;
                foreach (oJournal jrnal in jrnals)
                {
                    j = await repo.GetByRDTransId(jrnal.TransactionId);

                    string validationStr = ModelValidator.ValidateModel(jrnal);

                    if (!string.IsNullOrEmpty(validationStr))
                    {
                        errMsg = string.Format(validationStr);
                        var resp = new HttpResponseMessage(HttpStatusCode.Conflict);
                        resp.Content      = new StringContent(errMsg);
                        resp.ReasonPhrase = "Object property validation error";

                        ErrorLog _err = new ErrorLog();
                        _err.ErrorCode  = (int)HttpStatusCode.Conflict;
                        _err.Message    = errMsg;
                        _err.StackTrace = Environment.StackTrace;

                        var err = ErrorLogger.Log(_err);

                        transactionLogger.LogJournalTransaction(jrnal, false, "A", HttpContext.Current.Request.UserHostAddress, _err);
                        _resp = resp;
                        throw new HttpResponseException(resp);
                    }

                    if (j != null)
                    {
                        errMsg = string.Format("Journal {0} already exist.", jrnal.TransactionId);
                        var resp = new HttpResponseMessage(HttpStatusCode.Conflict);
                        resp.Content      = new StringContent(errMsg);
                        resp.ReasonPhrase = "Object already exist.";

                        ErrorLog _err = new ErrorLog();
                        _err.ErrorCode  = (int)HttpStatusCode.Conflict;
                        _err.Message    = errMsg;
                        _err.StackTrace = Environment.StackTrace;

                        var err = ErrorLogger.Log(_err);

                        transactionLogger.LogJournalTransaction(jrnal, false, "A", HttpContext.Current.Request.UserHostAddress, _err);
                        _resp = resp;
                        throw new HttpResponseException(resp);
                    }

                    if (repo.Add(jrnal) != 0)
                    {
                        errMsg = GlobalInstance.Instance.SBOErrorMessage;
                        var resp = new HttpResponseMessage(HttpStatusCode.Conflict);
                        resp.Content      = new StringContent(errMsg);
                        resp.ReasonPhrase = "SBO Error";
                        ErrorLog _err = new ErrorLog();
                        _err.ErrorCode  = (int)HttpStatusCode.Conflict;
                        _err.Message    = errMsg;
                        _err.StackTrace = Environment.StackTrace;

                        var err = ErrorLogger.Log(_err);

                        transactionLogger.LogJournalTransaction(jrnal, false, "A", HttpContext.Current.Request.UserHostAddress, _err);
                        _resp = resp;
                        throw new HttpResponseException(resp);
                    }

                    transactionLogger.LogJournalTransaction(jrnal, true, "A", HttpContext.Current.Request.UserHostAddress);
                    var _j = await repo.GetByRDTransId(jrnal.TransactionId);

                    retList.Add(new { SAPTransactionId = _j.TransId, ReturnMessage = $"Journal {jrnal.TransactionId} successfully added." });
                }

                return(retList);
            }
            catch (HttpResponseException ex)
            {
                throw new HttpResponseException(ex.Response);
            }
        }