예제 #1
0
 private ICON.SAP.API.SAPB1 oSAPB1(string CompanyDB = "")
 {
     ICON.Configuration.SAPServer SAPServer = ICON.Configuration.Database.SAP_Server;
     ICON.SAP.API.SAPB1           SAPB1     = new ICON.SAP.API.SAPB1(
         SAPServer.DBServer,
         SAPServer.DBServerType,
         string.IsNullOrEmpty(CompanyDB) ? SAPServer.CompanyDB : CompanyDB,
         SAPServer.UserName,
         SAPServer.Password,
         SAPServer.LicenseServer,
         SAPServer.SLDAddress,
         SAPServer.Language
         );
     return(SAPB1);
 }
예제 #2
0
        public object CheckLockPeriod(dynamic data)
        {
            DateTime TranDate = DateTime.Now;
            DBHelper DBHelper = new DBHelper(ICON.Configuration.Database.REM_ConnectionString, null);

            SAP_Interface_Log Log = ICON.Interface.Transaction.CreateSAPLog("AP_REM", "CheckLockPeriod", TranDate.ToString("yyyyMMdd_HHmmssfff"), "DATETIME", null, null, Newtonsoft.Json.JsonConvert.SerializeObject(data), TranBy);

            bool   IsConnectSAP  = false;
            int    ResponseCode  = 500;
            object ResponseData  = null;
            string ErrrorMessage = string.Empty;

            ICON.SAP.API.SAPB1 SAPB1 = oSAPB1();

            try
            {
                List <string> Errors     = new List <string>();
                string        ProjectID  = (string)data.project_id;
                string        DocDateStr = (string)data.doc_date;

                DateTime DocDate = DateTime.Now;
                DateTime.TryParse(DocDateStr, out DocDate);

                if (string.IsNullOrEmpty(ProjectID))
                {
                    Errors.Add("missing value for parameter : 'project_id'");
                }
                if (string.IsNullOrEmpty(DocDateStr))
                {
                    Errors.Add("missing value for parameter : 'doc_date'");
                }
                if (DocDate.ToString("yyyy-MM-dd") != DocDateStr)
                {
                    Errors.Add("invalid format for parameter : 'doc_date'");
                }
                if (Errors.Count > 0)
                {
                    throw new Exception(string.Join("\n", Errors));
                }

                System.Text.StringBuilder SQL = new System.Text.StringBuilder();
                SQL.AppendLine("SELECT");
                SQL.AppendLine("	C.CompanyID			    AS CompanyID");
                SQL.AppendLine("	, PJ.ProjectID			AS ProjectID");
                SQL.AppendLine("	, ISNULL(C.Value, '')	AS DBName");
                SQL.AppendLine("FROM");
                SQL.AppendLine("	Sys_Conf_RealEstate C");
                SQL.AppendLine("	LEFT JOIN Sys_Master_Projects PJ ON C.CompanyID = PJ.CompanyID");
                SQL.AppendLine("WHERE 1 = 1");
                SQL.AppendLine("	AND C.CompanyID IS NOT NULL");
                SQL.AppendLine("	AND C.CompanyID <> '0'");
                SQL.AppendLine("	AND C.KEYNAME = 'DBName'");
                SQL.AppendLine($"	AND PJ.ProjectID = '{ProjectID}'");
                DataTable DT_Company = DBHelper.ExecuteDataTable(SQL.ToString());
                if (DT_Company.Rows.Count == 0)
                {
                    throw new Exception("none config for connecting to SAP of project " + ProjectID);
                }

                SAPB1 = oSAPB1(DT_Company.Rows[0]["DBName"].ToString());
                SAPB1.ConnectCompanyDB();
                IsConnectSAP = true;

                bool IsLock = SAPB1.GetIsLock(DocDate);

                object resp = new
                {
                    project_id = ProjectID,
                    doc_date   = DocDateStr,
                    is_lock    = IsLock
                };

                ResponseCode = 200;
                ResponseData = new { status = true, message = "success", data = resp };
            }
            catch (Exception ex)
            {
                ErrrorMessage = ex.Message;
                ResponseData  = new { status = false, message = ex.Message };
            }
            finally
            {
                ICON.Interface.Transaction.UpdateSAPLog(Log.TranID, Newtonsoft.Json.JsonConvert.SerializeObject(ResponseData), ResponseCode, ErrrorMessage);
                if (IsConnectSAP)
                {
                    SAPB1.DisConnectCompanyDB();
                }
            }
            return(ResponseData);
        }
예제 #3
0
        public object Calculate_AllocatePercent(dynamic data)
        {
            bool   IsConnectSAP  = false;
            int    ResponseCode  = 500;
            object ResponseData  = null;
            string ErrrorMessage = string.Empty;

            ICON.SAP.API.SAPB1 SAPB1 = oSAPB1();

            DateTime TranDate = DateTime.Now;
            DBHelper DBHelper = new DBHelper(ICON.Configuration.Database.REM_ConnectionString, null);

            SAP_Interface_Log Log = ICON.Interface.Transaction.CreateSAPLog("AP_REM", "Calculate_AllocatePercent", TranDate.ToString("yyyyMMdd_HHmmssfff"), "DATETIME", null, null, Newtonsoft.Json.JsonConvert.SerializeObject(data), TranBy);

            try
            {
                List <string> Errors    = new List <string>();
                int           Year      = 0;
                int           Month     = 0;
                string        ProjectID = (string)data.project_id;

                Int32.TryParse((string)data.year, out Year);
                Int32.TryParse((string)data.month, out Month);

                //if (string.IsNullOrEmpty(ProjectID)) Errors.Add("missing value for parameter : 'project_id'");
                if (Year.ToString() != (string)data.year)
                {
                    Errors.Add("invalid format for parameter : 'year'");
                }
                if (Month.ToString() != (string)data.month)
                {
                    Errors.Add("invalid format for parameter : 'month'");
                }
                if (Errors.Count > 0)
                {
                    throw new Exception(string.Join("\n", Errors));
                }


                DateTime NOW      = DateTime.Today;
                DateTime SendDate = new DateTime(Year, Month, 1);
                int      Start    = ((SendDate.Year - NOW.Year) * 12) + SendDate.Month - NOW.Month;

                #region SQL
                System.Text.StringBuilder SQL = new System.Text.StringBuilder();
                SQL.AppendLine($"DECLARE @Start INT = {Start}");
                SQL.AppendLine($"DECLARE @End INT = {Start}");
                SQL.AppendLine("");
                SQL.AppendLine("CREATE TABLE #Temp (");
                SQL.AppendLine("	[ProjectID]				NVARCHAR(50)");
                SQL.AppendLine("	 ,[ProjectName]			NVARCHAR(MAX)");
                SQL.AppendLine("	 ,[TotalArea]			NUMERIC(18,2)");
                SQL.AppendLine("	 ,[CalculateArea]		NUMERIC(18,2)");
                SQL.AppendLine("	 ,[Ratio]				NUMERIC(18,2)");
                SQL.AppendLine("	 ,[CalculatePeriodM]	INT");
                SQL.AppendLine("	 ,[CalculatePeriodY]	INT");
                SQL.AppendLine("	 ,[CalculateDate]		DATETIME");
                SQL.AppendLine("	 ,[UsePeriodM]			INT");
                SQL.AppendLine("	 ,[UsePeriodY]			INT");
                SQL.AppendLine("	 ,[TransferInPeriod]	NUMERIC(18,2)");
                SQL.AppendLine("CONSTRAINT [PK_Temp] PRIMARY KEY CLUSTERED ");
                SQL.AppendLine("(");
                SQL.AppendLine("	[ProjectID] ASC,");
                SQL.AppendLine("	CalculateDate ASC");
                SQL.AppendLine(")WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");
                SQL.AppendLine(") ON [PRIMARY]");
                SQL.AppendLine("");
                SQL.AppendLine(";WITH ROWYear AS (");
                SQL.AppendLine("  SELECT DATEADD(MONTH,@Start - 1 ,DATEADD(DAY,1,EOMONTH(GETDATE())))  as n");
                SQL.AppendLine("");
                SQL.AppendLine("  UNION ALL");
                SQL.AppendLine("");
                SQL.AppendLine("  SELECT DATEADD(MONTH,1,n) FROM ROWYear WHERE n < DATEADD(MONTH,@End - 1,DATEADD(DAY,1,EOMONTH(GETDATE())))");
                SQL.AppendLine(")");
                SQL.AppendLine("");
                SQL.AppendLine("INSERT INTO #Temp(ProjectID,ProjectName,CalculatePeriodM,CalculatePeriodY,CalculateDate,UsePeriodM,UsePeriodY)");
                SQL.AppendLine("SELECT PJ.ProjectID,PJ.ProjectName, MONTH(R.n), YEAR(R.n), EOMONTH(R.n), MONTH(DATEADD(MONTH,1,R.n)), YEAR(DATEADD(MONTH,1,R.n))");
                SQL.AppendLine("FROM ROWYear R, Sys_Master_Projects PJ");
                SQL.AppendLine("WHERE 1=1");
                if (!string.IsNullOrEmpty(ProjectID))
                {
                    SQL.AppendLine($"    AND PJ.ProjectID = '{ProjectID}'");
                }
                SQL.AppendLine("option (maxrecursion 0)");
                SQL.AppendLine("");
                SQL.AppendLine("");
                SQL.AppendLine("UPDATE TMP SET TMP.TotalArea = PJ.TotalArea");
                SQL.AppendLine("FROM #Temp TMP");
                SQL.AppendLine("INNER JOIN ");
                SQL.AppendLine("(");
                SQL.AppendLine("	SELECT PJ.ProjectID");
                SQL.AppendLine("	, SUM(UN.TitledeedArea) TotalArea");
                SQL.AppendLine("	FROM");
                SQL.AppendLine("		Sys_Master_Projects	PJ");
                SQL.AppendLine("		INNER JOIN Sys_Master_Units UN ON UN.ProjectID = PJ.ProjectID");
                SQL.AppendLine("	WHERE");
                SQL.AppendLine("		1=1");
                SQL.AppendLine("		AND ISNULL(UN.isDelete,0) = 0");
                SQL.AppendLine("	GROUP BY PJ.ProjectID");
                SQL.AppendLine(") PJ ON TMP.ProjectID = PJ.ProjectID");
                SQL.AppendLine("");
                SQL.AppendLine("--SELECT TEMP1.ProjectID, TEMP1.CalculateDate");
                SQL.AppendLine("--, ISNULL(TEMP2.TitledeedArea,0) AS CalculateArea");
                SQL.AppendLine("--, ISNULL(TEMP2.TitledeedArea,0) / TEMP1.TotalArea * 100 AS Ratio");
                SQL.AppendLine("--, ISNULL(TEMP2.TitledeedArea,0) - ISNULL(TEMP2.TitledeedAreaOld,0) AS TransferInPeriod");
                SQL.AppendLine("UPDATE TEMP1 SET");
                SQL.AppendLine("	TEMP1.CalculateArea = ISNULL(TEMP2.TitledeedArea,0)");
                SQL.AppendLine("	, Ratio = ISNULL(TEMP2.TitledeedArea,0) / TEMP1.TotalArea * 100");
                SQL.AppendLine("	, TransferInPeriod = ISNULL(TEMP2.TitledeedArea,0) - ISNULL(TEMP2.TitledeedAreaOld,0)");
                SQL.AppendLine("FROM ");
                SQL.AppendLine("#Temp TEMP1");
                SQL.AppendLine("LEFT JOIN (");
                SQL.AppendLine("	SELECT TMP.ProjectID, TMP.CalculateDate");
                SQL.AppendLine("	, SUM(CASE WHEN TMP.CalculateDate >= ISNULL(CO.TransferDate,CO.ContractDate) THEN UN.TitledeedArea ELSE 0 END) TitledeedArea");
                SQL.AppendLine("	, SUM(CASE WHEN EOMONTH(DATEADD(MONTH,-1,TMP.CalculateDate)) >= ISNULL(CO.TransferDate,CO.ContractDate) THEN UN.TitledeedArea ELSE 0 END) TitledeedAreaOld");
                SQL.AppendLine("	FROM #Temp TMP");
                SQL.AppendLine("	INNER JOIN Sys_REM_Contracts CO ON TMP.ProjectID = CO.ProjectID ");
                SQL.AppendLine("	INNER JOIN Sys_Master_Units UN ON TMP.ProjectID = UN.ProjectID ");
                SQL.AppendLine("	WHERE ");
                SQL.AppendLine("		1=1");
                SQL.AppendLine("		AND ISNULL(CO.isTmp,0) = 0");
                SQL.AppendLine("		AND CO.ContractID IS NOT NULL");
                SQL.AppendLine("		AND UN.UnitID IS NOT NULL");
                SQL.AppendLine("		AND CO.SBUID = 'PM001'");
                SQL.AppendLine("		AND CO.UnitID = UN.UnitID");
                SQL.AppendLine("		AND ISNULL(UN.isDelete,0) = 0");
                SQL.AppendLine("		AND ISNULL(CO.SaleOrderStatus,'') NOT IN ('C')");
                SQL.AppendLine("		AND TMP.CalculateDate >= ISNULL(CO.TransferDate,CO.ContractDate)");
                SQL.AppendLine("	GROUP BY TMP.ProjectID, TMP.CalculateDate");
                SQL.AppendLine(") TEMP2 ON TEMP1.ProjectID = TEMP2.ProjectID AND TEMP1.CalculateDate = TEMP2.CalculateDate");
                SQL.AppendLine("");
                SQL.AppendLine("UPDATE TMP SET TMP.Ratio = 100");
                SQL.AppendLine("FROM #Temp TMP");
                SQL.AppendLine("INNER JOIN Sys_Master_Projects PJ ON TMP.ProjectID = PJ.ProjectID AND ISNULL(PJ.ProjectType,'') = 'C'");
                SQL.AppendLine("WHERE 1=1");
                SQL.AppendLine("    AND ISNULL(PJ.JuristicStatus,'') = 'A'");
                SQL.AppendLine("");
                SQL.AppendLine("SELECT [ProjectID]          AS project_id");
                SQL.AppendLine("	 ,[ProjectName]         AS project_name");
                SQL.AppendLine("	 ,[TotalArea]           AS total_area");
                SQL.AppendLine("	 ,[CalculateArea]       AS calculate_area");
                SQL.AppendLine("	 ,[Ratio]               AS ratio");
                SQL.AppendLine("	 ,[CalculatePeriodM]    AS calculate_period_m");
                SQL.AppendLine("	 ,[CalculatePeriodY]    AS calculate_period_y");
                SQL.AppendLine("	 ,[UsePeriodM]          AS use_period_m");
                SQL.AppendLine("	 ,[UsePeriodY]          AS use_period_y");
                SQL.AppendLine("	 ,[TransferInPeriod]    AS transfer_in_period");
                SQL.AppendLine("FROM #Temp");
                SQL.AppendLine("ORDER BY");
                SQL.AppendLine("	ProjectID, CalculateDate");
                SQL.AppendLine("");
                SQL.AppendLine("DROP TABLE #Temp");
                #endregion

                List <Dictionary <string, object> > AllocateList = GlobalDatabase.LoadDictByQuery(DBHelper, SQL.ToString());
                List <string> ProjectList = AllocateList.GroupBy(x => x["project_id"].ToString()).Select(x => x.Key).ToList();

                System.Text.StringBuilder SQL_Company = new System.Text.StringBuilder();
                SQL_Company.AppendLine("SELECT");
                SQL_Company.AppendLine("	C.CompanyID			    AS CompanyID");
                SQL_Company.AppendLine("	, PJ.ProjectID			AS ProjectID");
                SQL_Company.AppendLine("	, ISNULL(C.Value, '')	AS DBName");
                SQL_Company.AppendLine("FROM");
                SQL_Company.AppendLine("	Sys_Conf_RealEstate C");
                SQL_Company.AppendLine("	LEFT JOIN Sys_Master_Projects PJ ON C.CompanyID = PJ.CompanyID");
                SQL_Company.AppendLine("WHERE 1 = 1");
                SQL_Company.AppendLine("	AND C.CompanyID IS NOT NULL");
                SQL_Company.AppendLine("	AND C.CompanyID <> '0'");
                SQL_Company.AppendLine("	AND C.KEYNAME = 'DBName'");
                SQL_Company.AppendLine($"	AND PJ.ProjectID IN ('{string.Join("','", ProjectList)}')");
                List <Dictionary <string, object> > CompanyConfigList = GlobalDatabase.LoadDictByQuery(DBHelper, SQL_Company.ToString());
                List <string> CompanyList = CompanyConfigList.GroupBy(x => x["CompanyID"].ToString()).Select(x => x.Key).ToList();

                foreach (string Company in CompanyList)
                {
                    Dictionary <string, object> CompanyConfig = CompanyConfigList.Find(x => x["CompanyID"].ToString() == Company);
                    if (CompanyConfig == null || CompanyConfig["DBName"].ToString() == "")
                    {
                        bool IsLock = true;
                        foreach (Dictionary <string, object> Item in CompanyConfigList.FindAll(x => x["CompanyID"].ToString() == Company))
                        {
                            Item["IsLock"] = IsLock;
                        }
                    }
                    else
                    {
                        string DBName = CompanyConfig["DBName"].ToString();

                        SAPB1 = oSAPB1(DBName);
                        SAPB1.ConnectCompanyDB();
                        IsConnectSAP = true;

                        bool IsLock = SAPB1.GetIsLock(SendDate);

                        SAPB1.DisConnectCompanyDB();
                        IsConnectSAP = false;

                        foreach (Dictionary <string, object> Item in CompanyConfigList.FindAll(x => x["CompanyID"].ToString() == Company))
                        {
                            Item["IsLock"] = IsLock;
                        }
                    }
                }

                foreach (Dictionary <string, object> Allocate in AllocateList)
                {
                    string Project = Allocate["project_id"].ToString();
                    Dictionary <string, object> CompanyConfig = CompanyConfigList.Find(x => x["ProjectID"].ToString() == Project);
                    if (CompanyConfig == null)
                    {
                        Allocate["is_lock"] = false;
                    }
                    else
                    {
                        Allocate["is_lock"] = Convert.ToBoolean(CompanyConfig["IsLock"]);
                    }
                }


                object resp = new
                {
                    year             = Year,
                    month            = Month,
                    allocate_percent = AllocateList,
                };

                ResponseCode = 200;
                ResponseData = new { status = true, message = "success", data = resp };
            }
            catch (Exception ex)
            {
                ErrrorMessage = ex.Message;
                ResponseData  = new { status = false, message = ex.Message };
            }
            finally
            {
                ICON.Interface.Transaction.UpdateSAPLog(Log.TranID, Newtonsoft.Json.JsonConvert.SerializeObject(ResponseData), ResponseCode, ErrrorMessage);
                if (IsConnectSAP)
                {
                    SAPB1.DisConnectCompanyDB();
                }
            }
            return(ResponseData);
        }
예제 #4
0
        private string CreateREMJournalEntry(dynamic Data)
        {
            string GLVoucherID    = (string)Data.GLVoucherID;
            string methodName     = "REMCreateJournalEntry";
            string refDescription = "SAPB1JV2";
            string VatCode        = "NOG";
            string dbName         = "";
            string series         = "";

            string SiteType = "";

            if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["SiteType"]))
            {
                SiteType = System.Configuration.ConfigurationManager.AppSettings["SiteType"].ToString();
            }
            else
            {
                throw new Exception("SiteType Invalid!!!!");
            }

            string TranID   = string.Empty;
            string DocNum   = string.Empty;
            string GLDocNum = string.Empty;

            ErrorMessage = string.Empty;
            HttpStatusCode ResponseCode = HttpStatusCode.OK;

            DBHelper dbHelp = new DBHelper(ICON.Configuration.Database.REM_ConnectionString, null);

            List <SAP_Interface_Log_Detail> LogDetail = new List <SAP_Interface_Log_Detail>();
            SAP_Interface_Log Log = ICON.Interface.Transaction.CreateSAPLog(
                "JournalEntry_REM",
                methodName,
                GLVoucherID,
                refDescription,
                null,
                "OJDT.TransId",
                Newtonsoft.Json.JsonConvert.SerializeObject(Data),
                TranBy);

            try
            {
                List <dynamic> details = new List <dynamic>();

                DataTable dtDetails = dbHelp.ExecuteDataTable(GetSqlSAPB1JV(Data.GLVoucherID, refDescription));

                string SQL = GetSqlREMDBConnect((string)Data.Project, SiteType);
                System.Data.DataTable dt = dbHelp.ExecuteDataTable(SQL);

                if (dt.Rows.Count > 0)
                {
                    dbName = dt.Rows[0]["DBName"].ToString();
                }
                else
                {
                    throw new Exception("company_value not found!!!!");
                }

                string GLType = "";
                //if ((string)Data.GLVoucherID.Substring(0, 2).ToLower() == "jv" || (string)Data.GLVoucherID.Substring(0, 2).ToLower() == "rv")
                //{
                //    GLType = (string)Data.GLVoucherID.Substring(0, 2);
                //}
                if (!string.IsNullOrEmpty(Data.GLType))
                {
                    GLType = (string)Data.GLType;
                }


                DateTime           PostingDate       = (DateTime)Data.PostingDate;
                string             PostingDateString = PostingDate.ToString("yyyy-MM");
                ICON.SAP.API.SAPB1 SAPB1             = oSAPB1(dbName);
                series = SAPB1.GetSeries("30", PostingDateString, GLType);
                ICON.SAP.API.SAPB1.Document Doc = new ICON.SAP.API.SAPB1.Document
                {
                    PostingDate = (DateTime)Data.PostingDate, //DateID
                    DocDueDate  = (DateTime)Data.DocDueDate,  //DueDate
                    TaxDate     = (DateTime)Data.TaxDate,     //TaxDate
                    DocType     = SAPbobsCOM.BoObjectTypes.oJournalVouchers,
                    UDF_RefNo   = (string)Data.ICON_RefNo,
                    //IsAutoReverse = (string)Data.IsAutoReverse,
                    //StornoDate = (DateTime)Data.StornoDate,
                    Remark  = (string)Data.Remark,
                    Project = (string)Data.Project,
                    Series  = series,
                    Ref1    = (string)Data.Ref1
                };

                foreach (dynamic d in dtDetails.Rows)
                {
                    //check item that service or not

                    if (string.IsNullOrEmpty(d["VatPercent"].ToString()) || Convert.ToDecimal(d["VatPercent"].ToString()) == 0)
                    {
                        VatCode = "NIG";
                    }
                    else
                    {
                        VatCode = "OG";
                    }

                    Doc.Lines.Add(new ICON.SAP.API.SAPB1.DocumentLine
                    {
                        AccountCode = (string)d["Account"],
                        //ShortName = "",
                        TaxCode     = VatCode,
                        Credit      = string.IsNullOrEmpty(d["Credit"].ToString()) ? 0 : Convert.ToDouble(d["Credit"].ToString()),
                        Debit       = string.IsNullOrEmpty(d["Debit"].ToString()) ? 0 : Convert.ToDouble(d["Debit"].ToString()),
                        LineMemo    = string.IsNullOrEmpty(d["LineMemo"].ToString()) ? "" : d["LineMemo"].ToString().Length > 50 ? d["LineMemo"].ToString().Substring(0, 50) : d["LineMemo"].ToString(),
                        ProjectCode = string.IsNullOrEmpty((string)Data.Project) ? "" : (string)Data.Project,
                        OcrCode     = string.IsNullOrEmpty((string)d["Ref1"].ToString()) ? "" : (string)d["Ref1"].ToString(),
                        OcrCode2    = string.IsNullOrEmpty((string)d["Ref2"].ToString()) ? "" : (string)d["Ref2"].ToString(),
                        OcrCode3    = string.IsNullOrEmpty((string)d["Ref3"].ToString()) ? "" : (string)d["Ref3"].ToString(),
                        OcrCode4    = string.IsNullOrEmpty((string)d["Ref4"].ToString()) ? "" : (string)d["Ref4"].ToString(),
                        OcrCode5    = string.IsNullOrEmpty((string)d["Ref5"].ToString()) ? "" : (string)d["Ref5"].ToString(),

                        //Reference1 = string.IsNullOrEmpty((string)d["Ref1"].ToString()) ? "" : (string)d["Ref1"].ToString(),
                        //Reference2 = string.IsNullOrEmpty((string)d["Ref2"].ToString()) ? "" : (string)d["Ref2"].ToString(),
                        //Reference3 = string.IsNullOrEmpty((string)d["Ref3"].ToString()) ? "" : (string)d["Ref3"].ToString(),
                        //WhsCode = (string)d.WhsCode,

                        //TAX_BASE = (string)d.TAX_BASE,
                        //TAX_NO = (string)d.TAX_NO,
                        //TAX_REFNO = (string)d.TAX_REFNO,
                        //TAX_PECL = (string)d.TAX_PECL,
                        //TAX_TYPE = (string)d.TAX_TYPE,
                        //TAX_BOOKNO = (string)d.TAX_BOOKNO,
                        //TAX_CARDNAME = (string)d.TAX_CARDNAME,
                        //TAX_ADDRESS = (string)d.TAX_ADDRESS,
                        //TAX_TAXID = (string)d.TAX_TAXID,
                        ////TAX_DATE = Doc.TaxDate,
                        //TAX_CODE = (string)d.TAX_CODE,
                        //TAX_CODENAME = (string)d.TAX_CODENAME,
                        //TAX_RATE = (string)d.TAX_RATE,
                        ////TAX_DEDUCT = string.IsNullOrEmpty((string)d.TAX_DEDUCT) ? "1" : (string)d.TAX_DEDUCT,
                        //TAX_OTHER = (string)d.TAX_OTHER,
                    });
                }

                try
                {
                    SAPB1.CreateJournalEntry(Doc, out TranID, out DocNum, out SAPStatusCode, out SAPErrorMessage, out LogDetail);
                    SAPStatus = SAPStatusCode.ToString();

                    dbHelp.ExecuteNonQuery("update Sys_ACC_GeneralLedgers set poststatus = 'P', modifydate = getdate() where (glvoucher = '" + GLVoucherID + "' or GLVoucher in (select GLVoucher from Sys_ACC_PostGLManualGroup where GroupID = '" + GLVoucherID + "'))");
                }
                catch (Exception ex)
                {
                    SAPStatus = SAPStatusCode.ToString();
                    throw ex;
                }

                return(DocNum);
            }
            catch (Exception ex)
            {
                ResponseCode = HttpStatusCode.InternalServerError;
                ErrorMessage = ex.Message + " " + ex.StackTrace;
                throw new Exception(ex.Message);
            }
            finally
            {
                ICON.Interface.Transaction.UpdateSAPLog(
                    Log.TranID,
                    Data.GLVoucherID,
                    DocNum,
                    TranID,
                    GLDocNum,
                    (int)ResponseCode,
                    (int)ResponseCode == 200 ? "" : ErrorMessage,
                    SAPStatus,
                    (int)ResponseCode == 200 ? "" : SAPErrorMessage,
                    LogDetail
                    );
            }
        }
예제 #5
0
        /****cancel****/
        private string CancelREMGoodReceiptPO(dynamic Data)
        {
            string po_reccode     = (string)Data.po_reccode;
            string methodName     = "CancelGoodReceiptPOCM";
            string refDescription = "masteri1_icon.grch.po_reccode";

            if (!string.IsNullOrEmpty((string)Data.methodName))
            {
                methodName = (string)Data.methodName;
            }

            string DocEntry = string.Empty;
            string DocNum   = string.Empty;
            string GLDocNum = string.Empty;

            ErrorMessage = string.Empty;
            HttpStatusCode ResponseCode = HttpStatusCode.OK;

            DBHelper dbHelp = new DBHelper(ICON.Configuration.Database.REM_ConnectionString, null);

            List <SAP_Interface_Log_Detail> LogDetail = new List <SAP_Interface_Log_Detail>();
            SAP_Interface_Log Log = ICON.Interface.Transaction.CreateSAPLog(
                "GoodReceiptPO_CM",
                methodName,
                po_reccode,
                refDescription,
                DocEntry,
                "OPDN.DocEntry",
                Newtonsoft.Json.JsonConvert.SerializeObject(Data),
                TranBy);

            try
            {
                string    sql = GetSqlInterfaceLog((string)Data.po_reccode, "create");
                DataTable dt  = dbHelp.ExecuteDataTable(sql);

                ICON.SAP.API.SAPB1          SAPB1 = oSAPB1();
                ICON.SAP.API.SAPB1.Document Doc   = new ICON.SAP.API.SAPB1.Document();

                if (!string.IsNullOrEmpty(dt.Rows[0]["SAPRefID"].ToString()) && !string.IsNullOrEmpty(dt.Rows[0]["SAPRefNo"].ToString()))
                {
                    Doc.DocEntry = Convert.ToInt32(dt.Rows[0]["SAPRefID"]);
                }
                else
                {
                    throw new Exception("SAP Ref No. is require");
                }

                Doc.DocType      = SAPbobsCOM.BoObjectTypes.oPurchaseDeliveryNotes;
                Doc.DocumentDate = (DateTime)Data.canceldate;

                try
                {
                    SAPB1.CancelDocument(Doc, out DocEntry, out DocNum, out GLDocNum, out SAPStatusCode, out SAPErrorMessage, out LogDetail);
                    SAPStatus = SAPStatusCode.ToString();
                }
                catch (Exception ex)
                {
                    SAPStatus = SAPStatusCode.ToString();
                    throw ex;
                }

                return(DocNum);
            }
            catch (Exception ex)
            {
                ResponseCode = HttpStatusCode.InternalServerError;
                ErrorMessage = ex.Message + " " + ex.StackTrace;
                throw new Exception(ex.Message);
            }
            finally
            {
                ICON.Interface.Transaction.UpdateSAPLog(
                    Log.TranID,
                    po_reccode,
                    DocEntry,
                    DocNum,
                    GLDocNum,
                    (int)ResponseCode,
                    ErrorMessage,
                    SAPStatus,
                    SAPErrorMessage,
                    LogDetail
                    );
            }
        }
예제 #6
0
        /****create****/
        private string CreateREMGoodReceiptPO(dynamic Data)
        {
            string HeaderID       = (string)Data.HeaderID;
            string MethodName     = "REMCreateGoodsReceiptPO";
            string RefDescription = "SAP_RW_Header";
            string VatCode        = "NOG";
            bool   IsService      = false;
            bool   IsDeferVat     = true;

            if (!string.IsNullOrEmpty((string)Data.MethodName))
            {
                MethodName = (string)Data.MethodName;
            }
            if (!string.IsNullOrEmpty((string)Data.RefDescription))
            {
                RefDescription = (string)Data.RefDescription;
            }
            //if (!string.IsNullOrEmpty((string)Data.VatCode))
            //{
            //    VatCode = (string)Data.VatCode;
            //}
            if (Data.IsService != null)
            {
                IsService = (bool)Data.IsService;
            }

            string SiteType = "";

            if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["SiteType"]))
            {
                SiteType = System.Configuration.ConfigurationManager.AppSettings["SiteType"].ToString();
            }
            else
            {
                throw new Exception("SiteType Invalid!!!!");
            }

            string DocEntry = string.Empty;
            string DocNum   = string.Empty;

            ErrorMessage = string.Empty;
            HttpStatusCode ResponseCode = HttpStatusCode.OK;

            DBHelper       dbHelp = new DBHelper(ICON.Configuration.Database.REM_ConnectionString, null);
            IDbTransaction trans  = dbHelp.BeginTransaction();

            List <SAP_Interface_Log_Detail> LogDetail = new List <SAP_Interface_Log_Detail>();
            SAP_Interface_Log Log = ICON.Interface.Transaction.CreateSAPLog(
                "GoodReceiptPO_REM",
                MethodName,
                (string)Data.ICON_RefNo,
                RefDescription,
                DocEntry,
                "OPDN.DocEntry",
                Newtonsoft.Json.JsonConvert.SerializeObject(Data),
                TranBy);

            try
            {
                var    details           = (dynamic)Data.Details;
                string SQL               = GetSqlREMDBConnect((string)details[0].Project, SiteType);
                System.Data.DataTable dt = dbHelp.ExecuteDataTable(SQL, trans);

                ICON.SAP.API.SAPB1 SAPB1 = oSAPB1(dt.Rows[0]["DBName"].ToString());

                ICON.SAP.API.SAPB1.Document Doc = new ICON.SAP.API.SAPB1.Document
                {
                    //CardCode = (string)Data.vendercode,
                    //NumAtCard = (string)Data.taxno,    // Vendor Ref. No.
                    //PostingDate = (DateTime)Data.po_recdate,
                    //DocDueDate = (DateTime)Data.po_recdate,
                    //DocumentDate = (DateTime)Data.po_recdate,
                    DocType      = SAPbobsCOM.BoObjectTypes.oPurchaseDeliveryNotes,
                    UDF_RefNo    = (string)Data.ICON_RefNo,
                    UDF_TAX_PECL = (string)Data.TAX_PECL,
                    //UDF_CustName = dt.Rows[0]["CustomerName"].ToString(),
                    //UDF_UnitRef = dt.Rows[0]["UnitNumber"].ToString(),
                    //UDF_Project = dt.Rows[0]["ProjectID"].ToString(),
                    //UDF_ProjectName = dt.Rows[0]["ProjectName"].ToString(),
                    //UDF_TaxID = dt.Rows[0]["TaxID"].ToString(),
                    //UDF_Address = dt.Rows[0]["Address"].ToString(),
                    //IsDeferVAT = Convert.ToBoolean(dt.Rows[0]["IsDeferVAT"])


                    HeaderID     = HeaderID,
                    PostingDate  = (DateTime)Data.DocDate,
                    DocDueDate   = (DateTime)Data.DocDueDate,
                    DocumentDate = (DateTime)Data.TaxDate,
                    CardCode     = (string)Data.CardCode,
                    CardName     = (string)Data.CardName,
                    //Address = (string)Data.Address,
                    //NumAtCard = (string)Data.NumAtCard,
                    VatPercent = (string)Data.VatPercent,
                    VatSum     = (string)Data.VatSum,
                    DiscPrcnt  = (string)Data.DiscPrcnt,
                    DocCur     = (string)Data.DocCur,
                    //DocRate = (string)Data.DocRate,
                    DocTotal = (string)Data.DocTotal,
                    Remark   = (string)Data.Comments,
                    //JrnlMemo = (string)Data.JrnlMemo,
                    //GroupNum = (string)Data.GroupNum,
                    //SlpCode = (string)Data.SlpCode,
                    //Address2 = (string)Data.Address2,
                    //LicTradNum = (string)Data.LecTradNum,
                    //DeferrTax = (string)Data.DeferrTax,
                    //OwnerCode = (string)Data.OwnerCode,
                    //VatBrance = (string)Data.VatBranch,
                    //Module = "REMCreateGoodsReceiptPO",
                    //MethodName = "REMCreateGoodsReceiptPO",
                    //RefDescription = "A_NEXT_AP.SAP_RW_Header.HeaderID",
                    //TableName = TableName,
                    //IsService = false,
                };

                foreach (var d in (dynamic)Data.Details)
                {
                    string itemName = (string)d.Dscription;

                    //ICON.SAP.API.SAPTABLE Items = new SAPTABLE(Convert.ToInt32(SAPbobsCOM.BoObjectTypes.oItems));
                    //itemName += " " + SAPB1.GetDataColumn("ItemName", Items, "ItemCode", dr["poi_matcode"].ToString());
                    //check item that service or not
                    if (string.IsNullOrEmpty((string)d.VatGroup) || Convert.ToDecimal((string)d.VatGroup) == 0)
                    {
                        VatCode = "NOG";
                    }
                    else
                    {
                        IsDeferVat = IsService ? true : false; //ถ้าไอเทมเป็นบริการจะกำหนดให้ defervat = 'Y'
                        VatCode    = "OG";
                    }

                    Doc.Lines.Add(new ICON.SAP.API.SAPB1.DocumentLine
                    {
                        ItemCode        = (string)d.ItemCode,
                        ItemDescription = itemName,
                        Qty             = Convert.ToDouble((string)d.Quantity),
                        TaxCode         = VatCode,
                        UnitPrice       = (string)d.Price,
                        LineTotal       = (string)d.LineTotal,
                        TotalFrgn       = (string)d.TotalFrgn,
                        WhsCode         = (string)d.WhsCode,
                        IsDeferVAT      = IsDeferVat,
                        VatSum          = (string)d.VatSum,
                        ProjectCode     = string.IsNullOrEmpty((string)d.Project) ? (string)d.WhsCode : (string)d.Project,
                        OcrCode         = string.IsNullOrEmpty((string)d.Ocrcode) ? "" : (string)d.Ocrcode,
                        OcrCode2        = string.IsNullOrEmpty((string)d.Ocrcode2) ? "" : (string)d.Ocrcode2,
                        OcrCode3        = string.IsNullOrEmpty((string)d.Ocrcode3) ? "" : (string)d.Ocrcode3,
                        OcrCode4        = string.IsNullOrEmpty((string)d.Ocrcode4) ? "" : (string)d.Ocrcode4,
                        OcrCode5        = string.IsNullOrEmpty((string)d.Ocrcode5) ? "" : (string)d.Ocrcode5,
                    });
                }

                try
                {
                    SAPB1.CreateDocumentAP(Doc, out DocEntry, out DocNum, out SAPStatusCode, out SAPErrorMessage, out LogDetail);
                    SAPStatus = SAPStatusCode.ToString();
                }
                catch (Exception ex)
                {
                    SAPStatus = SAPStatusCode.ToString();
                    throw ex;
                }

                return(DocNum);
            }
            catch (Exception ex)
            {
                ResponseCode = HttpStatusCode.InternalServerError;
                ErrorMessage = ex.Message + " " + ex.StackTrace;
                throw new Exception(ErrorMessage);
            }
            finally
            {
                ICON.Interface.Transaction.UpdateSAPLog(
                    Log.TranID,
                    HeaderID,
                    DocEntry,
                    DocNum,
                    "",
                    (int)ResponseCode,
                    ErrorMessage,
                    SAPStatus,
                    SAPErrorMessage,
                    LogDetail
                    );
            }
        }