INT32 CJSKMakeInvoice::FPKJ_Proc(CInvHead *pInvhead, string &strErr, UINT8 wasteflag) { DBG_PRINT(("===== FPKJ_Proc Begin() ======")); DBG_ASSERT_EXIT((pInvhead != NULL), (" pInvhead == NULL!")); INT32 retcode = JSK_SUCCESS; UINT8 tmpBuf[16]; INT8 sqlbuf[128]; //获取可滚动表的记录数 UINT8 nIfRolled=0; retcode = g_globalArgLib->RollData(nIfRolled); if(retcode!= SUCCESS) { strErr = "中间件数据库滚动失败!"; DBG_PRINT((" Roll() error !")); return JSK_FAILURE; } if(wasteflag == 0) { DBG_PRINT(("kplx = %u", pInvhead->m_kplx)); if(pInvhead->m_kplx == 0) { DBG_PRINT(("m_maxSign = %lld", g_globalArgLib->m_invKind->m_maxSign)); DBG_PRINT(("pInvhead->m_kphjje = %lld", pInvhead->m_kphjje)); if(pInvhead->m_kphjje > g_globalArgLib->m_invKind->m_maxSign) { strErr = "开票单张金额超限!"; return JSK_FAILURE; } if(pInvhead->m_kphjje <= 0) { strErr = "正数发票金额不能为零"; return JSK_FAILURE; } pInvhead->m_kplx = JSK_NORMAL_INV; } else if(pInvhead->m_kplx == 1) { pInvhead->m_kplx = JSK_RETURN_INV; } else { strErr = "发票类型错误!"; return JSK_FAILURE; } } else { if(pInvhead->m_kplx != JSK_WASTE_INV) { strErr = "发票类型错误!"; return JSK_FAILURE; } } //当前开票时间 UINT8 curTime[MAX_DATETIME_LEN+1]; retcode = CJSKInfoFunc::GetJSPCurDate(curTime, strErr); if( retcode != JSK_SUCCESS ) { return retcode; } TDateTime tmpDateTime((INT8 *)curTime, DATETIME_POS); pInvhead->m_kprq = tmpDateTime.FormatInt(YYYYMMDD); pInvhead->m_kpsj = tmpDateTime.FormatInt(HHMMSS); pInvhead->m_CurTime = tmpDateTime.FormatString(YYYYMMDDHHMMSS, "%u%02u%02u%02u%02u%02u"); if(pInvhead->m_kplx == JSK_WASTE_INV) { pInvhead->m_zfsj = (INT8 *)curTime; } //权限控制 retcode = MakeInvAuthority(pInvhead, strErr); if( retcode != JSK_SUCCESS ) { //retcode = JSK_COMMON_ERR_NO; return retcode; } CJSKInvManageProc::fplxdm2fplx(pInvhead->m_fplxdm, pInvhead->m_fplb); pInvhead->m_xfyhzh = g_globalArgLib->m_corpInfo->m_Khzh; //销方银行账号 DBG_PRINT(("pInvhead->fplb = %u", pInvhead->m_fplb)); //取发票代码、号码 CInvVol invVol; retcode = CJSKInfoFunc::GetCurInvInfo(&invVol, strErr); if( retcode != JSK_SUCCESS ) { return retcode; } pInvhead->m_fpdm = invVol.m_code; pInvhead->m_fphm = invVol.m_curInvNo; //调用金税盘函数获取税控码、CA签名、索引号 retcode = CJSKInfoFunc::MakeInvHandInfo(pInvhead, strErr); DBG_PRINT(("retcode = %d", retcode)); if( retcode != JSK_SUCCESS ) { return retcode; } //数据库事务开始 pInvhead->BeginTransaction(); //存数据库 UINT32 errorcode; errorcode = pInvhead->Save(); if (errorcode != SUCCESS) { // retcode = JSK_COMMON_ERR_NO; // DBG_PRINT(("pInvhead->Save() wrong")); // return retcode; } DBG_PRINT(("pInvhead->Save() SUCCESS")); //将该发票记录存储到DB的INV_SERV CInvServ invServ; DBG_PRINT(("m_InvServNum = %lu, m_InvServSum = %lld", g_globalArgLib->m_InvServNum, g_globalArgLib->m_InvServSum)); errorcode = invServ.Save(pInvhead, g_globalArgLib->m_InvServNum, g_globalArgLib->m_InvServSum, strErr); DBG_PRINT(("存储到DB的INV_SERV, errorcode = %u", errorcode)); //更新RT_INV表 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; errorcode = pRtInv->AddNew(); //写已退发票信息表 if( errorcode != SQLITE_OK ) { DBG_PRINT((" pRtInv->AddNew() error!")); //retcode = JSK_COMMON_ERR_NO; //return retcode; } } //数据库事务结束 pInvhead->EndTransaction(); return JSK_SUCCESS; }
INT32 CJSKMakeInvoice::FPZF_Proc(CInvHead *pInvhead, UINT8 zflx, string &strErr) { DBG_PRINT(("===== FPZF_Proc Begin() ======")); DBG_ASSERT_EXIT((pInvhead != NULL), (" pInvhead == NULL!")); INT32 retcode = JSK_SUCCESS; if(zflx == 0) //空白票作废 { pInvhead->m_kplx = JSK_WASTE_INV; pInvhead->m_xfmc = g_globalArgLib->m_corpInfo->m_Nsrmc; retcode = FPKJ_Proc(pInvhead, strErr, 1); return retcode; } ////////////////////////////////////////////////////////////////////////// if(zflx != 1) { strErr = "发票作废类型错误!"; return JSK_FAILURE; } CJSKInvManageProc::fplxdm2fplx(pInvhead->m_fplxdm, pInvhead->m_fplb); //已开票作废 //查询数据库中已开发票信息 INT8 sqlbuf[256]; UINT32 errorcode; CInvHead tmpInvHead; memset(sqlbuf, 0, sizeof(sqlbuf)); sprintf(sqlbuf, "where FPDM='%s' and FPHM=%u", pInvhead->m_fpdm.c_str(), pInvhead->m_fphm); DBG_PRINT(("sqlbuf = %s", sqlbuf)); pInvhead->m_filter.append(sqlbuf); if(pInvhead->Load() != SQLITE_OK) { DBG_PRINT(("here find by jsp")); //数据库查询不到,从盘中查询 retcode = CJSKInfoFunc::GetInvDetailInfoNO(pInvhead, strErr); if(retcode != JSK_SUCCESS) { return retcode; } pInvhead->Save(); } //已开发票作废控制 if(pInvhead->m_kplx == JSK_NORMAL_INV) { pInvhead->m_kplx = JSK_WASTE_NOR; } else if(pInvhead->m_kplx == JSK_RETURN_INV) { pInvhead->m_kplx = JSK_WASTE_RET; } else { retcode = JSK_COMMON_ERR_NO; strErr = "废票不能再次作废!"; return retcode; } //权限控制 retcode = MakeInvAuthority(pInvhead, strErr); if( retcode != JSK_SUCCESS ) { return retcode; } retcode = CJSKInfoFunc::WasteInvHandInfo(pInvhead, strErr); if( retcode != JSK_SUCCESS ) { return retcode; } //数据库事务开始 pInvhead->BeginTransaction(); //修改数据库对应信息 tmpInvHead.m_kplx = pInvhead->m_kplx; tmpInvHead.m_fpsyh = pInvhead->m_fpsyh; tmpInvHead.m_casign = pInvhead->m_casign; tmpInvHead.m_zfsj = pInvhead->m_zfsj; retcode = tmpInvHead.Update(sqlbuf, &tmpInvHead.m_kplx, &tmpInvHead.m_fpsyh, &tmpInvHead.m_zfsj, &tmpInvHead.m_casign, NULL); DBG_PRINT(("更新DB的INV_HEAD:retcode = %d", retcode)); CInvDet invDet; invDet.m_kplx = pInvhead->m_kplx; retcode = invDet.Update(sqlbuf, &invDet.m_kplx, NULL); DBG_PRINT(("更新DB的INV_DET:retcode = %d", retcode)); if(pInvhead->m_kplx == JSK_WASTE_RET ) { DBG_PRINT(("更新RT_INV表")); CRtInv curRtInv; CRtInv *pRtInv = &curRtInv; memset(sqlbuf, 0, sizeof(sqlbuf)); sprintf(sqlbuf, "where FPDM='%s' and FPHM=%u ", pInvhead->m_yfpdm.c_str(), pInvhead->m_yfphm); DBG_PRINT(("sqlbuf = %s", sqlbuf)); pRtInv->m_filter.append(sqlbuf); pRtInv->Delete(); } //处理INV_SERV表,如果已上传发票,需要重新记录INV_SERV??? CInvServ invServ; errorcode = invServ.Save(pInvhead, g_globalArgLib->m_InvServNum, g_globalArgLib->m_InvServSum, strErr); DBG_PRINT(("存储到DB的INV_SERV, errorcode = %u", errorcode)); //数据库事务结束 pInvhead->EndTransaction(); return JSK_SUCCESS; }