Exemplo n.º 1
0
        public static object ImportExternalByProcessDate(SessionInfo sessioninfo)
        {
            OpicsBusiness _opicsBusiness = new OpicsBusiness();
            DealBusiness _dealBusiness = new DealBusiness();
            ReconcileBusiness _reconcileBusiness = new ReconcileBusiness();
            List<DealTranModel> DealTrans = new List<DealTranModel>();
            var results = new List<object>();

            try
            {
                LoggingHelper.Debug("Get OPICS Deal on " + sessioninfo.Process.PreviousDate.ToString());

                //Get data from OPICS
                List<DEALModel> opicsdeals = _opicsBusiness.GetOPICSDealExternal(sessioninfo.Process.PreviousDate);
                List<CASHFLOWModel> opicscashflows = _opicsBusiness.GetOPICSCashflow(sessioninfo.Process.PreviousDate);

                List<DA_TRN> importeddeals = _dealBusiness.GetImportedDealsByProcessDate(sessioninfo.Process.CurrentDate);

                //Ignore imported deals
                var query = from o in opicsdeals
                            where !importeddeals.Any(d => d.EXT_DEAL_NO == o.EXT_DEAL_NO)
                            select o;

                LoggingHelper.Debug("Import Passed OPICS Deal");
                foreach (DEALModel opicdeal in query.ToList())
                {
                    if (ValidateOPICS(opicdeal))
                        ImportPassedOPICSDeal(sessioninfo, opicdeal, sessioninfo.Process.CurrentDate, ref DealTrans);
                }

                LoggingHelper.Debug("End Import Passed OPICS Deal as " + query.Count().ToString());

                if (DealTrans.Count > 0)
                {
                    //Insert to database
                    LoggingHelper.Debug("Insert OPICS deals on " + sessioninfo.Process.PreviousDate.ToString());

                    _reconcileBusiness.UpdateDealReconcile(sessioninfo, DealTrans);
                }

                results.Add(new { Object = "OPICS Deals", Total = DealTrans.Count});

                //Import Cashflows from OPICS
                List<DA_TRN_CASHFLOW> cashflows = null;

                if (opicscashflows != null && opicscashflows.Count > 0)
                {
                    List<DA_TRN> allimporteddeals = importeddeals.Union(from t in DealTrans select t.Transaction).ToList();
                    List<DA_TRN_CASHFLOW> importedcashflows = _dealBusiness.GetFlowsByProcessDate(sessioninfo.Process.CurrentDate);

                    cashflows = GenerateCashflowObject(sessioninfo, opicscashflows, importedcashflows, allimporteddeals);

                    if (cashflows.Count > 0)
                    {
                        _reconcileBusiness.ImportCashflows(sessioninfo, cashflows);
                    }
                }
                results.Add(new { Object = "OPICS Cashflows", Total = cashflows == null ? 0 : cashflows.Count });

                //Return result to jTable
                return new
                {
                    Result = "OK",
                    //Records = count > 0 ? sortedRecords.Skip(startIndex).Take(count).ToList() : sortedRecords,
                    Records = results,
                    TotalRecordCount = results.Count
                };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }