예제 #1
0
        public async Task <ActionResult> SyncAllData(JournalSourceList journalSourceList)
        {
            Logger.Writer(Newtonsoft.Json.JsonConvert.SerializeObject(journalSourceList));
            string errorData = "";

            foreach (var journalSource in journalSourceList.JournalSources)
            {
                try
                {
                    var item = JournalRelationMap.Create(journalSource);
                    await _JournalRelationMapApp.SaveJournalRelationMapAsync(item);
                }
                catch (Exception ex)
                {
                    errorData = journalSource.TransId + "," + ex.Message + ";";
                }
            }
            if (!string.IsNullOrEmpty(errorData))
            {
                return(Json(new { state = ResultType.error.ToString(), message = "单据:" + errorData.TrimEnd(',') + "同步失败" }));
            }
            else
            {
                return(Json(new { state = ResultType.success.ToString() }));
            }
        }
예제 #2
0
        public async Task <ActionResult> SyncSelectedData(string IDs)
        {
            if (string.IsNullOrEmpty(IDs))
            {
                return(Json(new { state = ResultType.error.ToString(), message = "选择的数据为空" }));
            }
            QueryParam queryParam = new QueryParam();

            queryParam.filter  = string.Format("TransId in ({0})", IDs.TrimEnd(','));
            queryParam.orderby = "BPLId,CreateDate,TransId";
            var rt = await _JournalSourceApp.GetJournalSourceAsync(queryParam);

            Logger.Writer(Newtonsoft.Json.JsonConvert.SerializeObject(rt));
            string errorNum = "";
            string errorMsg = "";

            foreach (var item in rt)
            {
                try
                {
                    JournalRelationMap jrMap = new JournalRelationMap();
                    jrMap = JournalRelationMap.Create(item);
                    var syncResult = await _JournalRelationMapApp.SaveJournalRelationMapAsync(jrMap);

                    if (syncResult.Code != 0)
                    {
                        errorNum += syncResult.UniqueKey + ",";
                        errorMsg += syncResult.Message + ";";
                    }
                }
                catch (Exception ex)
                {
                    errorNum += item.TransId + ",";
                    errorMsg += ex.Message + ";";
                }
            }
            if (!string.IsNullOrEmpty(errorNum) && !string.IsNullOrEmpty(errorMsg))
            {
                return(Json(new { state = ResultType.success.ToString(), message = "" }));
            }
            else
            {
                return(Json(new { state = ResultType.error.ToString(), message = $"失败单号:{errorNum};失败原因:{errorMsg}" }));
            }
        }
예제 #3
0
        public async Task <ActionResult> SearchJournalRelationMapList(ViewParam param)
        {
            try
            {
                /*
                 * 获取查询条件
                 */
                //if(param.MinCreateDate)
                StringBuilder paramStr   = new StringBuilder();
                QueryParam    queryParam = new QueryParam();
                if (param.BeginDate == default(DateTime) || param.BeginDate == null)
                {
                    paramStr.Append($"(CreateDate ge '{DateTime.Now.AddDays(1-DateTime.Now.Day).ToShortDateString()}')");
                }
                else
                {
                    paramStr.Append($" (CreateDate ge '{param.BeginDate.Date.ToShortDateString()}')");
                }
                if (param.EndDate == default(DateTime) || param.EndDate == null)
                {
                    paramStr.Append($" and (CreateDate le '{DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddDays(-1).ToShortDateString()}')");
                }
                else
                {
                    paramStr.Append($" and (CreateDate le '{param.EndDate.Date.ToShortDateString()}')");
                }
                if (!string.IsNullOrEmpty(param.Creator))
                {
                    paramStr.Append($" and (Creator eq '{param.Creator}')");
                }
                if (param.TransId != default(int))
                {
                    paramStr.Append($" and (TransId eq '{param.TransId}')");
                }
                if (param.TransType != default(int))
                {
                    paramStr.Append($" and (TransType eq '{param.TransType}')");
                }
                if (param.HandleStatu != default(int))
                {
                    paramStr.Append($" and (HandleResult eq '{param.HandleStatu}')");
                }
                if (!string.IsNullOrEmpty(param.BPLName))
                {
                    paramStr.Append($" and (BPLName eq '{param.BPLName}')");
                }
                if (param.BPLId != 0)
                {
                    paramStr.Append($" and (BPLId eq '{param.BPLId}')");
                }
                queryParam.filter  = paramStr.ToString();
                queryParam.orderby = "BPLId,CreateDate,TransId";
                var rt = await _journalRelationMapApp.GetJournalRelationMapListAsync(queryParam);

                return(Json(new { state = ResultType.success.ToString(), data = Newtonsoft.Json.JsonConvert.SerializeObject(JournalRelationMap.Hanlde(rt)) }));
            }
            catch (Exception ex)
            {
                return(Json(new { state = ResultType.error.ToString(), message = ex.Message }));
            }
        }
 public async Task <SaveResult> SaveJournalRelationMapAsync(JournalRelationMap JournalRelationMap)
 {
     return(await _JournalRelationMapRepository.SaveJournalRelationMap(JournalRelationMap));
 }
예제 #5
0
        public async Task <SaveResult> SaveJournalRelationMap(JournalRelationMap JournalRelationMap)
        {
            SaveResult saveRlt = new SaveResult();

            saveRlt.UniqueKey = JournalRelationMap.TransId.ToString();//回传接收方的主键
            using (IDbConnection conn = SqlConnectionFactory.CreateSqlConnection())
            {
                conn.Open();
                IDbTransaction dbTransaction = conn.BeginTransaction();
                try
                {
                    string insertSql     = @"INSERT INTO T_JournalRelationMap
                                            (Number,TransId,TransType,BPLId,Series,BaseRef,Memo,RefDate,DueDate,TaxDate,CreateDate,BPLName,Ref1,Ref2,Ref3,Creator,Approver,BtfLine,IsApart)    
                                            VALUES(@Number,@TransId,@TransType,@BPLId,@Series,@BaseRef,@Memo,@RefDate,@DueDate,@TaxDate,@CreateDate,@BPLName,@Ref1,@Ref2,@Ref3,@Creator,@Approver,@BtfLine,@IsApart)
                                            select SCOPE_IDENTITY();";
                    string insertItemSql = @"INSERT INTO T_JournalRelationMapItem
                                            (DocEntry,LineNum,TransId,LineId,BPLId,AcctCode,ShorName,ProfitCode,OcrCode2,OcrCode3,OcrCode4,OcrCode5,LineMemo,CardCode,CardName,Credit,Debit)     
                                            VALUES(@DocEntry,@LineNum,@TransId,@LineId,@BPLId,@AcctCode,@ShorName,@ProfitCode,@OcrCode2,@OcrCode3,@OcrCode4,@OcrCode5,@LineMemo,@CardCode,@CardName,@Credit,@Debit)";

                    object DocEntry = await conn.ExecuteScalarAsync(insertSql,
                                                                    new
                    {
                        Number     = JournalRelationMap.Number,
                        TransId    = JournalRelationMap.TransId,
                        BPLId      = JournalRelationMap.BPLId,
                        Series     = JournalRelationMap.Series,
                        BaseRef    = JournalRelationMap.BaseRef,
                        Memo       = JournalRelationMap.Memo,
                        RefDate    = JournalRelationMap.RefDate,
                        DueDate    = JournalRelationMap.DueDate,
                        TaxDate    = JournalRelationMap.TaxDate,
                        CreateDate = JournalRelationMap.CreateDate,
                        BPLName    = JournalRelationMap.BPLName,
                        Ref1       = JournalRelationMap.Ref1,
                        Ref2       = JournalRelationMap.Ref2,
                        Ref3       = JournalRelationMap.Ref3,
                        Creator    = JournalRelationMap.Creator,
                        Approver   = JournalRelationMap.Approver,
                        BtfLine    = JournalRelationMap.BtfLine,
                        IsApart    = JournalRelationMap.IsApart,
                        TransType  = JournalRelationMap.TransType
                    }, dbTransaction);

                    saveRlt.ReturnUniqueKey = DocEntry.ToString();//回传保存订单的主键
                    await conn.ExecuteAsync(insertItemSql, DocumentItemHandle <JournalRelationMapLine> .GetDocumentItems(JournalRelationMap.JournalRelationMapLines, Convert.ToInt32(DocEntry)), dbTransaction);

                    dbTransaction.Commit();
                    saveRlt.Code = 0;
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    saveRlt.Code    = 1;
                    saveRlt.Message = ex.Message;
                    throw ex;
                }
                finally
                {
                    conn.Close();
                }
                return(saveRlt);
            }
        }
예제 #6
0
        /// <summary>
        /// 拆解正数的分录
        /// </summary>
        /// <param name="JournalRelationMap"></param>
        /// <returns></returns>
        public static DocumentSync ApartPositiveJournal(JournalRelationMap JournalRelationMap)
        {
            DocumentSync rt = new DocumentSync();

            rt.DocEntry = JournalRelationMap.DocEntry.ToString();
            try
            {
                SAPbobsCOM.JournalEntries myJE = SAP.SAPCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalEntries);
                myJE.ReferenceDate = JournalRelationMap.RefDate;
                myJE.TaxDate       = JournalRelationMap.TaxDate;
                myJE.DueDate       = JournalRelationMap.DueDate;
                myJE.UserFields.Fields.Item("U_TransId").Value = JournalRelationMap.TransId;
                if (!string.IsNullOrEmpty(JournalRelationMap.Creator))
                {
                    myJE.UserFields.Fields.Item("U_Creator").Value = JournalRelationMap.Creator;
                }
                if (!string.IsNullOrEmpty(JournalRelationMap.Approver))
                {
                    myJE.UserFields.Fields.Item("U_Approver").Value = JournalRelationMap.Approver;
                }
                myJE.UserFields.Fields.Item("U_PrintTransId").Value = JournalRelationMap.SerialNumber;

                foreach (var item in JournalRelationMap.JournalRelationMapLines)
                {
                    if (item.Debit > 0 || item.Credit > 0)
                    {
                        myJE.Lines.BPLID        = item.BPLId;
                        myJE.Lines.ShortName    = item.ShorName;
                        myJE.Lines.AccountCode  = item.AcctCode;
                        myJE.Lines.LineMemo     = item.LineMemo;
                        myJE.Lines.CostingCode  = item.ProfitCode;
                        myJE.Lines.CostingCode2 = item.OcrCode2;
                        myJE.Lines.CostingCode3 = item.OcrCode3;
                        myJE.Lines.CostingCode4 = item.OcrCode4;
                        myJE.Lines.CostingCode5 = item.OcrCode5;
                        myJE.Lines.UserFields.Fields.Item("U_TransId").Value = item.TransId;
                        myJE.Lines.UserFields.Fields.Item("U_LineId").Value  = item.LineId;

                        //myJE.Lines.UserFields.Fields.Item("U_PAYCODE").Value = item.PayCode;
                        if (!string.IsNullOrEmpty(item.CardCode))
                        {
                            myJE.Lines.UserFields.Fields.Item("U_CardCode").Value = item.CardCode;
                        }
                        if (!string.IsNullOrEmpty(item.CardName))
                        {
                            myJE.Lines.UserFields.Fields.Item("U_CardName").Value = item.CardName;
                        }
                        //myJE.Lines.UserFields.Fields.Item("U_ERPCARDCODE").Value = item.ERPCardCode;
                        //myJE.Lines.UserFields.Fields.Item("U_ERPBASECARDCODE").Value = item.ERPBaseCardCode;
                        //myJE.Lines.PrimaryFormItems.CashFlowLineItemID = item.
                        if (item.Debit > 0 && item.Credit == 0)
                        {
                            myJE.Lines.Debit = Convert.ToDouble(item.Debit);
                        }
                        if (item.Credit > 0 && item.Debit == 0)
                        {
                            myJE.Lines.Credit = Convert.ToDouble(item.Credit);
                        }
                        myJE.Lines.Add();
                    }
                }
                int rtCode = myJE.Add();
                if (rtCode == 0)
                {
                    rt.SyncResult = "Y";
                    rt.SyncMsg    = "sync successfull";
                }
                else
                {
                    rt.SyncResult  = "N";
                    rt.SyncMsg     = SAP.SAPCompany.GetLastErrorCode() + SAP.SAPCompany.GetLastErrorDescription();
                    rt.SAPDocEntry = SAP.SAPCompany.GetNewObjectKey();
                }
            }
            catch (Exception ex)
            {
                rt.SyncResult = "N";
                rt.SyncMsg    = ex.Message;
            }
            return(rt);
        }