INT32 CJSKMakeInvoice::FPSC_Proc(UINT8 czlx, UINT32 &fpzx, string &strInvInfo, string &strErr) { INT8 sqlbuf[128]; CInvServ invServ; CInvHead invHead; INT32 retcode = JSK_SUCCESS; INT32 errcode = 0; string tmpErr(""); // CJSKDeclareProc::DelUploadInv(); memset(sqlbuf, 0, sizeof(sqlbuf)); sprintf(sqlbuf, "where UP_FLAG=0 or UP_FLAG=1 "); invServ.m_filter.append(sqlbuf); invServ.Requery(); errcode = invServ.LoadOneRecord(); DBG_PRINT(("errcode = %d", errcode)); if(errcode == SQLITE_OK) { if((invServ.m_code=="") || (invServ.m_InvNo==0)) errcode = SQLITE_DONE; } if(errcode != SQLITE_OK) { retcode = CJSKInfoFunc::GetFirstOffInvInfo(&invHead, tmpErr); if((invHead.m_fpdm=="") || (invHead.m_fphm==0)) retcode = JSK_FAILURE; if(retcode != JSK_SUCCESS) { g_globalArgLib->m_pthreadFlag = 0; g_globalArgLib->m_InvServNum = 0; retcode = JSK_COMMON_ERR_NO; strErr = "所有发票都已上传!"; return retcode; } memset(sqlbuf, 0, sizeof(sqlbuf)); sprintf(sqlbuf, "where FPDM='%s' and FPHM=%u ", invHead.m_fpdm.c_str(), invHead.m_fphm); DBG_PRINT(("sqlbuf = %s", sqlbuf)); invServ.m_filter.append(sqlbuf); invServ.Requery(); if(invServ.LoadOneRecord() == SQLITE_OK) { if(invServ.m_upFlag == INV_UPLOAD_FLAG2) { g_globalArgLib->m_pthreadFlag = 0; retcode = JSK_COMMON_ERR_NO; strErr = "发票上传错误,请核对!"; return retcode; } } invServ.m_code = invHead.m_fpdm; invServ.m_InvNo = invHead.m_fphm; invServ.m_fpsyh = invHead.m_fpsyh; } UINT32 invLen = 0; fpzx = 1; //发票张数 memset(sqlbuf, 0, sizeof(sqlbuf)); sprintf(sqlbuf, "where FPDM='%s' and FPHM=%u ", invServ.m_code.c_str(), invServ.m_InvNo); DBG_PRINT(("sqlbuf = %s", sqlbuf)); invHead.m_filter.append(sqlbuf); retcode = invHead.Load(); if(retcode != SQLITE_OK) { DBG_PRINT(("here query from JSK")); invHead.m_fpdm = invServ.m_code; invHead.m_fphm = invServ.m_InvNo; invHead.m_fpsyh = invServ.m_fpsyh; retcode = CJSKInfoFunc::GetInvDetailInfoNO(&invHead, g_invInfo, invLen, strErr); if(retcode != JSK_SUCCESS) { return retcode; } // if(invHead.Save() != SQLITE_OK) // { // retcode = JSK_COMMON_ERR_NO; // strErr = "发票信息保存数据库错误"; // return retcode; // } } else { DBG_PRINT(("here query from DB success")); //将invHead类转换成string类型输出 CJSKInfoFunc::MutexLock(); CJSKInfoFunc::InvDetail2Data(&invHead, g_invInfo, invLen); CJSKInfoFunc::MutexUnlock(); DBG_PRINT(("invLen = %u", invLen)); } DBG_PRINT(("invLen = %u", invLen)); AddInvDetail2Data(&invHead, g_invInfo, invLen); strInvInfo.append((INT8 *)g_invInfo); DBG_PRINT(("invLen = %u", invLen)); //更新上传标志 invServ.m_upFlag = INV_UPLOAD_FLAG1; DBG_PRINT(("sqlbuf = %s", sqlbuf)); invServ.Update(sqlbuf, &invServ.m_upFlag, NULL); return JSK_SUCCESS; }
INT32 CJSKMakeInvoice::ParseFpscjg(string scqrbw, string &mxjgmw, string &strErr) { UINT8 upInfo[JSK_MAKE_INV_SIGN_LEN]; memset(upInfo, 0, sizeof(upInfo)); sprintf((INT8 *)upInfo, "%s", scqrbw.c_str()); int nLen = scqrbw.length(); DBG_PRINT(("nLen = %d", nLen)); Base64_Decode_2((INT8 *)upInfo, &nLen); DBG_PRINT(("nLen = %d", nLen)); DBG_PRINT(("upInfo = %s", upInfo)); //接收数据写文件 FILE *fp; if( (fp = fopen(XML_FPSCJGHQ_FILE, "wb")) == NULL ) { strErr = "解析发票上传结果错误!"; return JSK_FAILURE; } fwrite( (void *)upInfo, nLen, 1, fp); fclose(fp); XMLParse xmlParse; int res = 0; string tmpCode(""); string strFphm(""); res = xmlParse.XMLParseBegin(XML_FPSCJGHQ_FILE); xmlParse.LocateNodeByName(xmlParse.m_RootElement, "OUTPUT"); xmlParse.m_parentElement[1] = xmlParse.m_Child; xmlParse.LocateNodeByName(xmlParse.m_parentElement[1], "CODE"); tmpCode = xmlParse.GetText(); if(tmpCode != "0000") { xmlParse.LocateNodeByName(xmlParse.m_parentElement[1], "MESS"); strErr = xmlParse.GetText(); xmlParse.XMLParseEnd(); return JSK_FAILURE; } xmlParse.LocateNodeByName(xmlParse.m_parentElement[1], "DATA"); xmlParse.m_parentElement[2] = xmlParse.m_Child; res = xmlParse.LocateNodeByName(xmlParse.m_parentElement[2], "FP_SUCC"); xmlParse.m_parentElement[3] = xmlParse.m_Child; string tempStr; xmlParse.LocateNodeByName(xmlParse.m_parentElement[3], "FPXX"); tempStr = xmlParse.GetText(); DBG_PRINT(("FPXX = %s", tempStr.c_str())); xmlParse.LocateNodeByName(xmlParse.m_parentElement[3], "FLAG"); mxjgmw = xmlParse.GetText(); DBG_PRINT(("mxjgmw = %s", mxjgmw.c_str())); if(mxjgmw != "") { return JSK_SUCCESS; } xmlParse.LocateNodeByName(xmlParse.m_parentElement[2], "FP_ERR"); xmlParse.m_parentElement[3] = xmlParse.m_Child; xmlParse.LocateNodeByName(xmlParse.m_parentElement[3], "FP"); xmlParse.m_parentElement[4] = xmlParse.m_Child; xmlParse.LocateNodeByName(xmlParse.m_parentElement[4], "FPDM"); string tmpfpdm = xmlParse.GetText(); DBG_PRINT(("tmpfpdm = %s", tmpfpdm.c_str())); xmlParse.LocateNodeByName(xmlParse.m_parentElement[4], "FPHM"); strFphm = xmlParse.GetText(); UINT32 tmpfphm = atoi(xmlParse.GetText().c_str()); DBG_PRINT(("tmpfphm = %u", tmpfphm)); xmlParse.LocateNodeByName(xmlParse.m_parentElement[4], "CODE"); tmpCode = xmlParse.GetText(); xmlParse.LocateNodeByName(xmlParse.m_parentElement[4], "MESS"); strErr = xmlParse.GetText(); // strErr = strFphm + ":" + strErr; DBG_PRINT(("strErr = %s", strErr.c_str())); xmlParse.XMLParseEnd(); INT8 sqlbuf[128]; memset(sqlbuf, 0, sizeof(sqlbuf)); sprintf(sqlbuf, "where FPDM='%s' and FPHM=%u ", tmpfpdm.c_str(), tmpfphm); CInvServ invServ; invServ.m_upFlag = INV_UPLOAD_FLAG2; //上传错误 if(strErr.length() > MAX_ERR_MSG_LEN) strErr.erase(MAX_ERR_MSG_LEN, strErr.length()-MAX_ERR_MSG_LEN); invServ.m_errMsg = tmpCode + ":" + strErr; DBG_PRINT(("m_errMsg = %s", invServ.m_errMsg.c_str())); invServ.Update(sqlbuf, &invServ.m_upFlag, &invServ.m_errMsg, NULL); return JSK_FAILURE; }
INT32 CJSKMakeInvoice::FPCX_Proc(UINT8 cxfs, string cxtj, UINT32 &invNum, CInvHead *pInvhead, string &strErr) { DBG_ASSERT_EXIT((pInvhead != NULL), (" pInvhead == NULL!")); INT32 retcode = JSK_SUCCESS; INT8 sqlbuf[128]; string fpdm(""); UINT32 fphm = 0; string tmpStr; INT32 errcode = 0; invNum = 1; //cxfs为0时:12发票代码+8位起始号码+8位终止号码; cxfs if(cxfs == 0) { fpdm = cxtj.substr(0, 12); tmpStr = cxtj.substr(12, 8); fphm = atoi(tmpStr.c_str()); memset(sqlbuf, 0, sizeof(sqlbuf)); sprintf(sqlbuf, "where FPDM='%s' and FPHM=%u", fpdm.c_str(), fphm); DBG_PRINT(("sqlbuf = %s", sqlbuf)); pInvhead->m_filter.append(sqlbuf); errcode = pInvhead->Load(); if(errcode != SQLITE_OK) { DBG_PRINT(("here search JSK=========")); pInvhead->m_fpdm = fpdm; pInvhead->m_fphm = fphm; retcode = CJSKInfoFunc::GetInvDetailInfoNO(pInvhead, strErr); if(retcode != JSK_SUCCESS) { return retcode; } if(pInvhead->Save() != SUCCESS) { DBG_PRINT(("InvHead Save Error!")); //retcode = JSK_COMMON_ERR_NO; //strErr = "发票信息保存数据库错误"; //return retcode; } if(pInvhead->m_kplx == JSK_RETURN_INV) { DBG_PRINT(("更新RT_INV表")); CRtInv curRtInv; CRtInv *pRtInv = &curRtInv; pRtInv-> m_fpdm = pInvhead->m_yfpdm; pRtInv-> m_fphm = pInvhead->m_yfphm; if( pRtInv->AddNew() != SQLITE_OK ) { DBG_PRINT((" pRtInv->AddNew() error!")); } } } CInvServ invServ; DBG_PRINT(("sqlbuf = %s", sqlbuf)); invServ.m_filter.append(sqlbuf); invServ.Requery(); if(invServ.LoadOneRecord() != SQLITE_OK) pInvhead->m_scbz = 1; else { if(invServ.m_upFlag == INV_UPLOAD_FLAG2) { invServ.m_upFlag = INV_UPLOAD_FLAG0; DBG_PRINT(("sqlbuf = %s", sqlbuf)); invServ.Update(sqlbuf, &invServ.m_upFlag, NULL); } } } //为1是:起始日期(YYYYMMDD)+终止日期(YYYYMMDD) else if(cxfs == 1) { retcode = JSK_COMMON_ERR_NO; strErr = "不支持时间段查询方式!"; return retcode; } else { retcode = JSK_COMMON_ERR_NO; strErr = "非法查询方式!"; return retcode; } return JSK_SUCCESS; }