Example #1
0
DataMangler::DataMangler(DatabaseManager* db, const DrawInfoList& di, wxDateTime start_time, wxDateTime end_time, PeriodType period, XYDialog *dialog, bool average) :
		DBInquirer(db),
		m_di(di),
		m_period(period),
		m_start_time(m_period, start_time),
		m_current_time(m_period, start_time),
		m_end_time(m_period, end_time) {

	m_start_time.AdjustToPeriod();
	m_current_time.AdjustToPeriod();
	m_end_time.AdjustToPeriod();

	assert (m_start_time <= m_end_time);
	
	int vs = m_start_time.GetDistance(m_end_time) + 1;

	DTime tmpdate(PERIOD_T_OTHER, wxDateTime::Now());
	std::pair<std::vector<ValueInfo> , DTime> tmptuple(std::vector<ValueInfo>(di.size(), ValueInfo()), tmpdate);
	m_draw_vals.resize(vs, tmptuple);

	m_dialog = dialog;

	m_average = average;

}	
INT32 CJSKMakeInvoice::FPBL_Proc(string nsrsbh, string sksbbh, UINT32 SDate, UINT32 EDate, string &strErr)
{
	DBG_PRINT(("FPBL_Proc Begin()"));
	CInvHead invHead;
	INT8 sqlbuf[128];
	INT8 tmpBuf[128];
	INT32 errcode = 0;
	XMLConstruct pXmlBuild;
	UINT32 nCount = 1;
	string filename("");

	memset(tmpBuf, 0, sizeof(tmpBuf));
	UINT8 ret = UsbDiskMount(tmpBuf);
	if (SUCCESS != ret)
	{
		DBG_PRINT(("挂载U盘失败"));
		strErr = "挂载U盘失败";
		UsbDiskUnMount();
		return JSK_FAILURE;
	}

	UINT32 uDate = SDate/100;
	DBG_PRINT(("uDate= %u",uDate));
	sprintf(tmpBuf, "/mnt/%s%s%s_%s_%u_%s%s.DAT", XML_FILE_NAME_CGLPLBL,XML_FILE_NAME_KFSBM,nsrsbh.c_str(),sksbbh.c_str(),uDate,XML_FILE_NAME_ENCODE,"0001");
	filename = tmpBuf;
	DBG_PRINT(("filename = %s", filename.c_str()));

	memset(sqlbuf, 0, sizeof(sqlbuf));
	sprintf(sqlbuf, "where KPRQ>=%u and KPRQ<=%u", SDate, EDate);
	DBG_PRINT(("sqlbuf = %s", sqlbuf));
	invHead.m_filter.append(sqlbuf);
	INT32 m_InvNum = invHead.GetRecordNum();
	DBG_PRINT(("m_InvNum = %ld", m_InvNum));
	if(m_InvNum  > 0 )
	{
		pXmlBuild.XMLConstructBegin("1.0", "gbk", "business");
		pXmlBuild.m_RootElement->SetAttribute("id", "JSZZP");
		pXmlBuild.m_RootElement->SetAttribute("comment", "卷式增普票");
		pXmlBuild.m_RootElement->SetAttribute("version", "1.0");
	}
	else
	{
		strErr = "该时间段没有开票信息!";
		return JSK_FAILURE;
	}

	UINT32 date_StartNo = 0;	//当天的发票起始号码
	TDateTime tmpDateTime(SDate, 0);
	UINT32 TempDate = tmpDateTime.FormatInt(YYYYMMDD);	
	DBG_PRINT(("TempDate = %u", TempDate));
	while(TempDate <= EDate)
	{
		DBG_PRINT(("补录日期: %u", TempDate));
		date_StartNo = 0;

		memset(sqlbuf, 0, sizeof(sqlbuf));
		sprintf(sqlbuf, "WHERE KPRQ=%u order by NO limit 1", TempDate);
		DBG_PRINT(("sqlbuf = %s", sqlbuf));
		invHead.m_filter.append(sqlbuf);
		errcode = invHead.Load();
		DBG_PRINT(("errcode = %u", errcode));	

		while (errcode == SQLITE_OK)	//查到记录
		{
			DBG_PRINT(("查询invhead表有内容!"));
			pXmlBuild.AddNode(pXmlBuild.m_RootElement, "body");
			memset(tmpBuf, 0, sizeof(tmpBuf));
			sprintf(tmpBuf, "%u", nCount);
			pXmlBuild.AddAttr("no", tmpBuf);
			pXmlBuild.m_parentElement[1] = pXmlBuild.m_NewElement;
			
			pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "fpdm");
			pXmlBuild.AddText(invHead.m_fpdm);
			
			pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "fphm");
			memset(tmpBuf, 0, sizeof(tmpBuf));
			sprintf(tmpBuf, "%08u", invHead.m_fphm);
			pXmlBuild.AddText(tmpBuf);


			TDateTime tmpdate(invHead.m_kprq, invHead.m_kpsj);
			string tmpKprq = tmpdate.FormatString(YYYYMMDD);
			DBG_PRINT(("tmpKprq= %s",tmpKprq.c_str()));
			string tmpKpsj = tmpdate.FormatString(HHMMSS);
			DBG_PRINT(("tmpKpsj= %s",tmpKpsj.c_str()));

			pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "kprq");
			//memset(tmpBuf, 0, sizeof(tmpBuf));
			//sprintf(tmpBuf, "%08u", invHead.m_kprq);
			pXmlBuild.AddText(tmpKprq);			
			
			pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "kpsj");
// 			memset(tmpBuf, 0, sizeof(tmpBuf));
// 			sprintf(tmpBuf, "%u", invHead.m_kpsj);
			pXmlBuild.AddText(tmpKpsj);			

			pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "sbbh");
			pXmlBuild.AddText(sksbbh);

			if(invHead.m_kplx == JSK_RETURN_INV)
			{
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "hjje");
				memset(tmpBuf, 0, sizeof(tmpBuf));
				sprintf(tmpBuf, "-%.2lf", ((double)(invHead.m_kpje)*1.0)/SUM_EXTENSION);
				pXmlBuild.AddText(tmpBuf);
			
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "se");
				memset(tmpBuf, 0, sizeof(tmpBuf));
				if(invHead.m_kpse == 0)
				{
					sprintf(tmpBuf, "%.2lf", ((double)invHead.m_kpse *1.0)/SUM_EXTENSION);
				}
				else
				{
					sprintf(tmpBuf, "-%.2lf", ((double)invHead.m_kpse *1.0)/SUM_EXTENSION);
				}
				pXmlBuild.AddText(tmpBuf);

				pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "jshj");
				memset(tmpBuf, 0, sizeof(tmpBuf));
				invHead.m_kphjje = invHead.m_kpje + invHead.m_kpse;
				sprintf(tmpBuf, "-%.2lf", ((double)invHead.m_kphjje *1.0)/SUM_EXTENSION);
				pXmlBuild.AddText(tmpBuf);		
			}
			else
			{
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "hjje");
				memset(tmpBuf, 0, sizeof(tmpBuf));
				sprintf(tmpBuf, "%.2lf", ((double)(invHead.m_kpje)*1.0)/SUM_EXTENSION);
				pXmlBuild.AddText(tmpBuf);
				
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "se");
				memset(tmpBuf, 0, sizeof(tmpBuf));
				sprintf(tmpBuf, "%.2lf", ((double)invHead.m_kpse *1.0)/SUM_EXTENSION);
				pXmlBuild.AddText(tmpBuf);
				
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "jshj");
				memset(tmpBuf, 0, sizeof(tmpBuf));
				invHead.m_kphjje = invHead.m_kpje + invHead.m_kpse;
				sprintf(tmpBuf, "%.2lf", ((double)invHead.m_kphjje *1.0)/SUM_EXTENSION);
				pXmlBuild.AddText(tmpBuf);
			}
			
			pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "jym");
			pXmlBuild.AddText(invHead.m_fwm);
			
			pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "xfmc");
			pXmlBuild.AddText(g_globalArgLib->m_corpInfo->m_Nsrmc);
			
			pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "xfsh");
			pXmlBuild.AddText(nsrsbh);
			
			pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "gfmc");
			pXmlBuild.AddText(invHead.m_fkdw);
			
			pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "gfsh");
			pXmlBuild.AddText(invHead.m_payerCode);
			
				
			string fpztbz("");
			switch(invHead.m_kplx)
			{
			case JSK_NORMAL_INV:
					fpztbz = "0";	//正票
				break;
			case JSK_RETURN_INV:
					fpztbz = "1";	//退票
				break;
			case JSK_WASTE_INV:
					fpztbz = "2";	//空白废
				break;
			case JSK_WASTE_NOR:
					fpztbz = "3";	//正废
				break;
			case JSK_WASTE_RET:
					fpztbz = "4";	//负废
				break;
			}
			//发票状态标志(0 正常票1 退票2新发票的作废发票3正常发票的作废发票4已开退票的作废发票)
			pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "fpbz");
			pXmlBuild.AddText(fpztbz);

			pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "skr");
			pXmlBuild.AddText(invHead.m_sky);
			
			pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "bz");
			UINT8 baseBuf[256];
			memset(baseBuf, 0, sizeof(baseBuf));
			sprintf((INT8 *)baseBuf, "%s", invHead.m_backup1.c_str());
			Base64_Encode_2(baseBuf, invHead.m_backup1.length());
			string tmpStr = (INT8 *)baseBuf;
			pXmlBuild.AddText(tmpStr);
			
			if(invHead.m_kplx == JSK_RETURN_INV)
			{
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "yfpdm");
				pXmlBuild.AddText(invHead.m_yfpdm);
				
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "yfphm");
				memset(tmpBuf, 0, sizeof(tmpBuf));
				sprintf(tmpBuf, "%u",  invHead.m_yfphm);
				pXmlBuild.AddText(tmpBuf);
			}
			else
			{
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "yfpdm");
				pXmlBuild.AddText("");
				
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "yfphm");
				pXmlBuild.AddText("");
			}

			if( (invHead.m_kplx == JSK_WASTE_NOR) || (invHead.m_kplx == JSK_WASTE_RET) || (invHead.m_kplx == JSK_WASTE_INV) )
			{
				TDateTime zfDate(invHead.m_zfsj.c_str(), DATETIME_POS);
				string strZfrq =  zfDate.FormatString(YYYYMMDD);
				DBG_PRINT(("strZfrq= %s",strZfrq.c_str()));
				string strZfsj=zfDate.FormatString(HHMMSS);
				DBG_PRINT(("strZfsj= %s",strZfsj.c_str()));

				pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "zfrq");
				memset(tmpBuf, 0, sizeof(tmpBuf));
				//sprintf(tmpBuf, "%u", zfDate.FormatInt(YYYYMMDD));
				pXmlBuild.AddText(strZfrq);
				
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "zfsj");
				memset(tmpBuf, 0, sizeof(tmpBuf));
				//sprintf(tmpBuf, "%u", zfDate.FormatInt(HHMMSS));
				pXmlBuild.AddText(strZfsj);				
			}
			else
			{
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "zfrq");
				pXmlBuild.AddText("");
				
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "zfsj");
				pXmlBuild.AddText("");
			}

			pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "qmz");
			pXmlBuild.AddText(invHead.m_casign);


			CInvDet *pInvDet = invHead.pHead;
			
			for(int j=1; j<=invHead.m_sphsl; j++, pInvDet=pInvDet->pNext)
			{
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[1], "zb");
				pXmlBuild.m_parentElement[2] = pXmlBuild.m_NewElement;
				
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[2], "xh");
				memset(tmpBuf, 0, sizeof(tmpBuf));
				sprintf(tmpBuf, "%u", pInvDet->m_sphxh);
				pXmlBuild.AddText(tmpBuf);
				
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[2], "xm");
				pXmlBuild.AddText(pInvDet->m_spmc);
				
				if(invHead.m_kplx == JSK_RETURN_INV)
				{
					pXmlBuild.AddNode(pXmlBuild.m_parentElement[2], "sl");
					memset(tmpBuf, 0, sizeof(tmpBuf));
					if(pInvDet->m_spsl < 0.001)
					{
						sprintf(tmpBuf, "0.00000000");
					}
					else
					{
						sprintf(tmpBuf, "-%.3lf00000",  pInvDet->m_spsl);
					}
					pXmlBuild.AddText(tmpBuf);
				}
				else
				{
					pXmlBuild.AddNode(pXmlBuild.m_parentElement[2], "sl");
					memset(tmpBuf, 0, sizeof(tmpBuf));
					sprintf(tmpBuf, "%.3lf00000",  pInvDet->m_spsl);
					pXmlBuild.AddText(tmpBuf);
				}
				
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[2], "hsdj");
				memset(tmpBuf, 0, sizeof(tmpBuf));
				sprintf(tmpBuf, "%.3lf00000", pInvDet->m_spdj);
				pXmlBuild.AddText(tmpBuf);
				
				if(invHead.m_kplx == JSK_RETURN_INV)
				{
					pXmlBuild.AddNode(pXmlBuild.m_parentElement[2], "hsje");
					memset(tmpBuf, 0, sizeof(tmpBuf));
					sprintf(tmpBuf, "-%.2lf", ((double)pInvDet->m_spje*1.0)/SUM_EXTENSION);
					pXmlBuild.AddText(tmpBuf);
				}
				else
				{
					pXmlBuild.AddNode(pXmlBuild.m_parentElement[2], "hsje");
					memset(tmpBuf, 0, sizeof(tmpBuf));
					sprintf(tmpBuf, "%.2lf", ((double)pInvDet->m_spje*1.0)/SUM_EXTENSION);
					pXmlBuild.AddText(tmpBuf);
				}
				
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[2], "dj");
				memset(tmpBuf, 0, sizeof(tmpBuf));
				sprintf(tmpBuf, "%.3lf00000", pInvDet->m_dj);
				pXmlBuild.AddText(tmpBuf);
				
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[2], "je");
				memset(tmpBuf, 0, sizeof(tmpBuf));
				sprintf(tmpBuf, "%.2lf", ((double)pInvDet->m_je*1.0)/SUM_EXTENSION);
				pXmlBuild.AddText(tmpBuf);
				
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[2], "zsl");
				memset(tmpBuf, 0, sizeof(tmpBuf));
				sprintf(tmpBuf, "%.2lf", (double)pInvDet->m_sl);
				pXmlBuild.AddText(tmpBuf);
				
				pXmlBuild.AddNode(pXmlBuild.m_parentElement[2], "se");
				memset(tmpBuf, 0, sizeof(tmpBuf));
				sprintf(tmpBuf, "%.2lf", ((double)pInvDet->m_spse*1.0)/SUM_EXTENSION);
				pXmlBuild.AddText(tmpBuf);
			}

			nCount++;
			DBG_PRINT(("nCount = %u", nCount));
			date_StartNo = invHead.m_no;
			sprintf(sqlbuf, "WHERE KPRQ=%u and NO>%u limit 1", TempDate, date_StartNo);
			invHead.m_filter.append(sqlbuf);
			errcode = invHead.Load();			
		}

		//--------------------------------------------------
		//未找到票,查下一天
		//--------------------------------------------------
		if (errcode == SQLITE_DONE)
		{
			tmpDateTime ++;
			TempDate = tmpDateTime.FormatInt(YYYYMMDD);
			continue;
		}
		else
		{
			DBG_PRINT(("读数据库错误"));
			break;
		}
	}


	if( 1 != pXmlBuild.XMLConstructEnd(filename.c_str()) )
	{
		strErr = "报存XML文件错误!";
		return JSK_FAILURE;
	}

	UsbDiskUnMount();
	
	return JSK_SUCCESS;
}