Пример #1
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
                    );
            }
        }
Пример #2
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
                    );
            }
        }
Пример #3
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
                    );
            }
        }