1097 lines
37 KiB
C++
1097 lines
37 KiB
C++
//---------------------------------------------------------------------------
|
||
#pragma hdrstop
|
||
|
||
#include "PrinterOPOS.h"
|
||
//#include "OposFiscalPrinter_1_7_Lib_OCX.h"
|
||
//#include "ud_Module.h"
|
||
//#include <Registry.hpp>
|
||
#include <Math.h>
|
||
#include <exception>
|
||
#include <winreg.h>
|
||
//#include <DateUtils.hpp>
|
||
//#include <Dialogs.hpp>
|
||
|
||
#include "inifile.h"
|
||
#include "stdTools.h"
|
||
//---------------------------------------------------------------------------
|
||
|
||
//#pragma package(smart_init)
|
||
//---------------------------------------------------------------------------
|
||
//FiscalPrinter* g_printer;
|
||
//---------------------------------------------------------------------------
|
||
wchar_t * kkm_err_msg_ru[] = {
|
||
L"OK", //0
|
||
L"ÔÏ ID îøèáêà", //1 FM ID Error
|
||
L"Îøèáêà çàïèñè â ÔÏ ", //2 FM Rec Error
|
||
L"Flash Chip íå ìîæåò áûòü î÷èùåí", //3 Flash Chip cant clear
|
||
L"ÔÏ íå ïóñòà", //4 FM not empty
|
||
L"Äàííûå â ÔÏ ðàçðóøåííû", //5 FM Data destroyed
|
||
L"Ðåæ ïðèíòåð èãíîðèð êìä", //6 Cmd ignor prn mode
|
||
L"Íåò êîäà îïåðàòîðà", //7 Oper code is absent
|
||
L"Íåò òèïà äîêóìåíòà", //8 Doc type is absent
|
||
L"Ñåð. íîìåð ÊÊÌ", //9 Ser num CR
|
||
L"Îøèáêà ïàðîëÿ", //10 Password error
|
||
L"Îøèáêà äàòà/âðåìÿ", //11 Data/Time error
|
||
L"Çàâîä. ðåã. ðàíåå", //12 Factory registration has already pass
|
||
L"Ñåð íîì ÊÊÌ ðàçðóøåí", //13 Ser num CR destroyed
|
||
L"Ôèñêàëèçàöèÿ ðàíåå", //14 Fiscalize has already pass
|
||
L"ÊÊÌ íå ôèñê ðåæèì", //15 Not fisc mode CR
|
||
L"Ôèñêàë ÊÊÌ ðàçðóøåí", //16 Fiscalize Data destroyed
|
||
L"Ïåðåðåã ÊÊÌ èñ÷åðïàí", //17 Rewrite is conclude
|
||
L"Ïåðåðåã ÊÊÌ ðàçðóøåí", //18 Rewrite is destroyed
|
||
L"Ñìåíà îòêðûòà", //19 Shift already open
|
||
L"Ñì íå áûëà îòêðûòà", //20 Shift not opened
|
||
L"Ìíîãî òîâàðà â ÷åêå", //21 Many goods in receipt
|
||
L"ÑÌ â ÔÏ ðàçðóøåííà", //22 EOD data in FM destroyed
|
||
L"Ôîðìàò äîêóìåíòà", //23 Document format error
|
||
L"Ïåðåçàïèñü òåêñòà", //24 Text rewrite
|
||
L"Ìíîãî ïàð-ðîâ äîê", //25 Many parameters in document
|
||
L"Îø ïàðàìåòð äîê-òà", //26 Document parameters error
|
||
L"Îø çíà÷åíèÿ ïàð-ðà", //27 Parameters value error
|
||
L"Íåñóùåñòâóþù îáúåêò", //28 Object non-existent
|
||
L"Äîê íå áûë çàâåðøåí", //29 Document is not finished
|
||
L"Òîâàð/îïåð íå ïîëíî", //30 goods/operation description not enough
|
||
L"Êîíòðîë ñóììà ïàêåòà", //31 Check sum packet
|
||
L"Ïðèíòåð íå ãîòîâ", //32 Prn not ready
|
||
L"Âëîæåííûå ïðåðûâàíèÿ", //33 Nested interrupts
|
||
L"Áàéò ïîäòâ ïðèåì äàííûõ", //34 Check Sum Error
|
||
L"Ïåðåïîëíåííèå â ÔÏ", //35 Overflow if FM
|
||
L"Íåèçâåñòíàÿ êîììàíäà", //36 Unknown command
|
||
L"CRC ÎÇÓ", //37 CRC RAM
|
||
L"CRC ÔÏ", //38 CRC FM
|
||
L"Ïîðò äàííûõ íåèñïðàâ", //39 Data port defective
|
||
L"Ïîðÿäîê ðåêâ ÷åêà", //40 Receipts parameters sequence
|
||
L"0xy äëÿ îáÿçàò ðåêâ", //41 0xy for required properties
|
||
L"Äëèííà çàïðîñà", //42 Length request
|
||
L"Ðàçðÿäíîñòü ÷èñëà", //43 number capacity
|
||
L"Ïåðåïîëíåíèå", //44 Overflow
|
||
L"Íåò ÷èñëà", //45 Number is absent
|
||
L"Íåò îòâåòà", //46 Not response
|
||
L"Îøèáêà ïåðåäà÷è", //47 Transmission error
|
||
L"Ìàò. ïåðåïîëíåíèå", //48 Math overflow
|
||
L"Íåò áóìàãè...", //49 Paper out...
|
||
L"ÊÊÌ íå ãîòîâà!!!", //50 CR not ready!!!
|
||
L"Ñáîé ïàìÿòè!!", //51 Memory error!!
|
||
L"Ïðèíòåð âûêëþ÷åí", //52 Printer off
|
||
L"Íåäîñòàòî÷íî ïàìÿòè", //53 Insufficient memory
|
||
L"Äëèííà íîìåðà ìåíüøå", //54 Lenght number less
|
||
L"Íóëåâàÿ äëèííà íîìåðà", //55 Zero lenght number
|
||
L"Äëèííà ïàðîëÿ ìåíüøå äîïóñòèìîé", //56 Password lenght less permissible
|
||
L"Íóëåâàÿ äëèííà ïàðîëÿ", //57 Zero lenght password
|
||
L"Íåäîïóñòèìàÿ âåëè÷èíà", //58 Impossible value
|
||
L"Ïðåâûøåí òàéì-àóò", //59 Time-out overdraw
|
||
L"",
|
||
L"Îø.ÝÊËÇ",
|
||
L"Íåäîïóñòèìîå ñîñòîÿíèå ÝÊËÇ",
|
||
L"Äàííûå ó÷òåíû",
|
||
L"",L"",L"",L"",L"",L"",//69
|
||
L"",L"",L"",L"",L"",L"",L"",L"",L"",L"",//79
|
||
L"",L"",L"",L"",L"",L"",L"",L"",L"",L"",//89
|
||
L"",L"",L"",L"",L"",L"",L"",L"",L"",L"",//99
|
||
L"",L"",L"",L"",L"",L"",L"",L"",L"",L"",//109
|
||
L"",L"",L"",L"",L"",L"",L"",L"",L"",L"",//119
|
||
L"",L"",L"",L"",L"",L"",L"",L"",L"",L"",//129
|
||
L"",L"",L"",L"",L"",L"",L"",L"",L"",L"",//139
|
||
L"",L"",L"",L"",L"",L"",L"",L"",L"",L"",//149
|
||
L"",L"",L"",L"",L"",L"",L"",L"",L"",L"",//159
|
||
|
||
L"",L"",L"",L"",L"",L"",L"",L"",L"",L"",//169
|
||
L"",L"",L"",L"",L"",L"",L"",L"",L"",L"",//179
|
||
L"",L"",L"",L"",L"",L"",L"",L"",L"",L"",//189
|
||
L"",L"",L"",L"",L"",L"",L"",L"",L"",L"",//199
|
||
L"",L"",L"",L"",L"",L"",L"",L"",L"",L"",//209
|
||
L"",L"",L"",L"",L"",L"",L"",L"",L"",L"",//219
|
||
L"",L"",L"",L"",L"",L"",L"",L"",L"",L"",//229
|
||
L"",L"",L"",L"",L"",L"",L"",L"",L"",L"",//239
|
||
L"Êîìàíäû íåò",//240 Cmd not init
|
||
L"Îø. ïîñûëêè êîìàíäû",//241 Cmd write err
|
||
L"Êîìàíäà íå îòîñëàíà ÊÊÌ-íåãîòîâ(DSR=0)",//242 Prn not ready (DSR=0)
|
||
L"Êîìàíäà îòîñëàíà, íî îòâåò ÷òî ÊÊÌ-íåãîòîâ",//243 Cmd ok
|
||
L"Ïðåâûøåíî âðåìÿ îæèäàíèÿ îòâåòà",//244 Cmd resp timeout
|
||
L"Îøèáêà",//245 Prn error
|
||
L"Ïðèøëî áîëüøå äàííûõ, ÷åì îæèäàëè",//246 Cmd resp large
|
||
L"Ïðèøëî ìåíüøå äàííûõ, ÷åì îæèäàëè",//247 Cmd resp small
|
||
L"Ïðèøëè íåêèå äàííûå",//248
|
||
L"Ïîðò çàêðûò",//249
|
||
L"Ïîðò çàêðûò âî âðåìÿ âûïîëíåíèÿ",//250 Cmd break
|
||
L"ÊÊÌ âûêëþ÷åí èëè ñëîìàí",//251
|
||
L"ÊÊÌ íåãîòîâ",//252
|
||
L"Îøèáêà â ïàðàìåòðàõ êîìàíäû",//253
|
||
L"Íåñóùåñòâóþùèé íîìåð êîìàíäû",//254
|
||
L"ÊÊÌ çàíÿò(ïðåäûäóùàÿ êîìàíäà)!"//255 Previous cmd run
|
||
};
|
||
//------------------------------------------------------------------------------
|
||
bool FiscalPrinter::getNextCheckId(int &id)
|
||
{
|
||
CheckId++; //Íîìåð ÷åêà
|
||
SaveSetup(); //ñîõðàíÿåì íîìåð ÷åêà
|
||
id=CheckId;
|
||
return true;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
bool FiscalPrinter::SaveCheck(int CheckId) //Ñîõðàíåíèå ÷åêà äëÿ ïîñëåäóþùåé ðàñïå÷àòêè (ñóììû)
|
||
{
|
||
/*if(dModule->UserType) //true - Þðåäè÷åñêîå ëèöî; false - ôèçè÷åñêîå ëèöî
|
||
dModule->SaveCheck(CheckId,dModule->UserId,0,getGoodsPrice());
|
||
else
|
||
dModule->SaveCheck(CheckId,0,dModule->UserId,getGoodsPrice());*/
|
||
return true;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
bool FiscalPrinter::deleteCheck(int CheckId) //Óäàëåíèå ÷åêà
|
||
{
|
||
//dModule->UpdateChek(CheckId);
|
||
return true;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
int FiscalPrinter::getCOMPort()
|
||
{
|
||
HKEY keyHandle;
|
||
char rgValue[1024];
|
||
char fnlRes[1024];
|
||
DWORD size1;
|
||
DWORD Type;
|
||
|
||
std::string str = "-1";
|
||
|
||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,L"\\SOFTWARE\\OLEforRetail\\ServiceOPOS\\FiscalPrinter\\MbsFiscalPrinter", 0, KEY_QUERY_VALUE, &keyHandle) == ERROR_SUCCESS)
|
||
{
|
||
size1 = 1023;
|
||
RegQueryValueEx(keyHandle, L"COM Num", NULL, &Type, (LPBYTE)rgValue, &size1);
|
||
str = rgValue;
|
||
RegCloseKey(keyHandle);
|
||
}
|
||
return Utility::StdStrToInt(str);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
bool FiscalPrinter::setBaudRate(std::wstring data)
|
||
{
|
||
HKEY keyHandle;
|
||
bool result;
|
||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"\\SOFTWARE\\OLEforRetail\\ServiceOPOS\\FiscalPrinter\\MbsFiscalPrinter", 0, KEY_QUERY_VALUE, &keyHandle) == ERROR_SUCCESS)
|
||
{
|
||
LONG nError = RegSetValueEx(keyHandle, L"COM Speed", NULL, REG_DWORD, (LPBYTE)data.c_str(), sizeof(DWORD));
|
||
RegCloseKey(keyHandle);
|
||
result = true;
|
||
} else result = false;
|
||
return result;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
int FiscalPrinter::getBaudRate()
|
||
{
|
||
HKEY keyHandle;
|
||
char rgValue[1024];
|
||
char fnlRes[1024];
|
||
DWORD size1;
|
||
DWORD Type;
|
||
|
||
std::string str = "-1";
|
||
|
||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"\\SOFTWARE\\OLEforRetail\\ServiceOPOS\\FiscalPrinter\\MbsFiscalPrinter", 0, KEY_QUERY_VALUE, &keyHandle) == ERROR_SUCCESS)
|
||
{
|
||
size1 = 1023;
|
||
RegQueryValueEx(keyHandle, L"COM Speed", NULL, &Type, (LPBYTE)rgValue, &size1);
|
||
str = rgValue;
|
||
RegCloseKey(keyHandle);
|
||
}
|
||
return Utility::StdStrToInt(str);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
bool PrinterOPOS::setCOMPort(std::wstring data)
|
||
{
|
||
HKEY keyHandle;
|
||
bool result;
|
||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"\\SOFTWARE\\OLEforRetail\\ServiceOPOS\\FiscalPrinter\\MbsFiscalPrinter", 0, KEY_QUERY_VALUE, &keyHandle) == ERROR_SUCCESS)
|
||
{
|
||
LONG nError = RegSetValueEx(keyHandle, L"COM Num", NULL, REG_DWORD, (LPBYTE)data.c_str(), sizeof(DWORD));
|
||
RegCloseKey(keyHandle);
|
||
result = true;
|
||
}
|
||
else result = false;
|
||
return result;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void FiscalPrinter::LoadSetup()
|
||
{
|
||
TIniFile* ini = new TIniFile();
|
||
ini->Load("settings.ini");
|
||
|
||
//TIniFile* ini=new TIniFile(ExtractFilePath(ParamStr(0))+"\\Setup.ini");
|
||
// cPort->port=ini->ReadString("Printer","Port","");
|
||
// cPort->BaudRate=ini->ReadInteger("Printer","BaudRate",0);
|
||
CheckId=ini->ReadLong("Printer","CheckCount","0");
|
||
TestMode=ini->ReadBool("Printer","TestMode","1");
|
||
HeadLine=ini->ReadString(L"Printer",L"HeadLine",L"");
|
||
GoodsName=ini->ReadString(L"Printer",L"GoodsName",L"");
|
||
CasireName=ini->ReadString(L"Printer",L"CasireName",L"");
|
||
AutoOpenShift=ini->ReadBool("Printer","AutoOpenShift","0");
|
||
delete ini;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void FiscalPrinter::SaveSetup()
|
||
{
|
||
TIniFile* ini = new TIniFile();
|
||
ini->Load("settings.ini");
|
||
// ini->WriteString("Printer","Port",cPort->port); //Çà÷åì êîìåíòèë ðàíüøå:
|
||
// ini->WriteInteger("Printer","BaudRate",cPort->BaudRate); //Çà÷åì êîìåíòèë ðàíüøå:
|
||
ini->WriteLong("Printer","CheckCount",CheckId);
|
||
ini->WriteBool("Printer","TestMode",TestMode);
|
||
ini->WriteString(L"Printer",L"GoodsName",GoodsName);
|
||
ini->WriteString(L"Printer",L"CasireName",CasireName);
|
||
ini->WriteBool("Printer","AutoOpenShift",AutoOpenShift);
|
||
delete ini;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
int FiscalPrinter::getGoodsPrice()
|
||
{
|
||
int sum=0;
|
||
for(int i=0;i<FListGoods->count();i++)
|
||
sum+=((Goods*)FListGoods->get(i))->price;
|
||
return sum;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
//---------------------------------------------------------------------------
|
||
//---------------------------------------------------------------------------
|
||
PrinterOPOS::PrinterOPOS():FiscalPrinter()
|
||
{
|
||
Crashed=false;
|
||
AutoOpenShift=false;
|
||
//fp=new TOPOSFiscalPrinter(AOwner);
|
||
fp.CreateInstance(L"OposFiscalPrinter_1_7.OPOSFiscalPrinter");
|
||
fp->DeviceEnabled = 0; /// 0 == FALSE, -1 == TRUE
|
||
LoadSetup();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
PrinterOPOS::~PrinterOPOS()
|
||
{
|
||
delete FListGoods;
|
||
delete fp;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
//Ñîåäåíèòüñÿ ïî COM ïîðòó è ïðîèíèöèàëèçèðîâàòü ïðèíòåð
|
||
bool PrinterOPOS::Start()
|
||
{
|
||
if(fp->DeviceEnabled) return true;
|
||
|
||
FState = fp->Open(L"MbsFiscalPrinter");
|
||
if(FState!=0)
|
||
{
|
||
Utility::logrotateW(m_LogFileWPath + std::wstring(L"\\log.txt"), Utility::IntToStdWStr(FState)+std::wstring(L"(PrinterOPOS::Start)")+GetStatusDescription(FState));
|
||
return false;
|
||
}
|
||
FState = fp->ClaimDevice(1000);
|
||
if(FState!=0)
|
||
{
|
||
Utility::logrotateW(m_LogFileWPath + std::wstring(L"\\log.txt"), Utility::IntToStdWStr(FState)+ std::wstring(L"(PrinterOPOS::Start)")+GetStatusDescription(FState));
|
||
return false;
|
||
}
|
||
fp->DeviceEnabled = -1; // 0 == FALSE, -1 == TRUE
|
||
return true;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void PrinterOPOS::setHeader(TSimpleList2<std::wstring>* Text)
|
||
{
|
||
long err=0;
|
||
try
|
||
{
|
||
if(Crashed) throw std::runtime_error("Äðàéâåð ïðèíòåðà ðàçðóøåí!");
|
||
|
||
for(int i=0;i<Text->count();i++)
|
||
{
|
||
std::wstring str=Text->get(i);
|
||
err=fp->SetHeaderLine(i+1,str.c_str(),VARIANT_FALSE);
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
}
|
||
err=fp->ResetPrinter();
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
}catch(std::exception &exception)
|
||
{
|
||
if(err==251) Crashed=true; //Êàáçäåö
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::setHeader)")+exception.what());
|
||
//dModule->SendError(err,std::string("(PrinterOPOS::setHeader)")+exception);
|
||
}catch(...)
|
||
{
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::setHeader) Íåò îïèñàíèÿ îøèáêè"));
|
||
//dModule->SendError(1,std::string("(PrinterOPOS::setHeader) Íåò îïèñàíèÿ îøèáêè"));
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void PrinterOPOS::getHeader(TSimpleList2<std::wstring>* Text)
|
||
{
|
||
|
||
TIniFile* ini=new TIniFile();
|
||
ini->Load("settings.ini");
|
||
Text->add(ini->ReadString(L"Printer",L"HeadLine1",L""));
|
||
Text->add(ini->ReadString(L"Printer",L"HeadLine2",L""));
|
||
Text->add(ini->ReadString(L"Printer",L"HeadLine3",L""));
|
||
Text->add(ini->ReadString(L"Printer",L"HeadLine4",L""));
|
||
Text->add(ini->ReadString(L"Printer",L"HeadLine5",L""));
|
||
delete ini;
|
||
|
||
//Óäàëÿþ ïåðâûå ïóñòûå ñòðîêè åñëè îíè åñòü
|
||
for(int i=Text->count()-1;i>=0;i--)
|
||
if(Text->get(i)==L"") Text->del(i); else break;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void PrinterOPOS::setTrailer(TSimpleList2<std::wstring>* Text)
|
||
{
|
||
long err=0;
|
||
try
|
||
{ if(Crashed) throw std::runtime_error("Äðàéâåð ïðèíòåðà ðàçðóøåí!");
|
||
for(int i=0;i<Text->count();i++)
|
||
{
|
||
std::wstring str=Text->get(i);
|
||
err=fp->SetTrailerLine(i+1,str.c_str(),false);
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
}
|
||
err=fp->ResetPrinter();
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
}catch(std::exception &exception)
|
||
{
|
||
if(err==251) Crashed=true; //Êàáçäåö
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::setTrailer)")+exception.what());
|
||
//dModule->SendError(err,std::string("(PrinterOPOS::setTrailer)")+exception);
|
||
}catch(...)
|
||
{
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::setTrailer) Íåò îïèñàíèÿ îøèáêè"));
|
||
//dModule->SendError(1,std::string("(PrinterOPOS::setTrailer) Íåò îïèñàíèÿ îøèáêè"));
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void PrinterOPOS::getTrailer(TSimpleList2<std::wstring>* Text)
|
||
{
|
||
TIniFile* ini=new TIniFile();
|
||
ini->Load("settings.ini");
|
||
Text->add(ini->ReadString(L"Printer",L"TailLine1",L""));
|
||
Text->add(ini->ReadString(L"Printer",L"TailLine2",L""));
|
||
Text->add(ini->ReadString(L"Printer",L"TailLine3",L""));
|
||
Text->add(ini->ReadString(L"Printer",L"TailLine4",L""));
|
||
Text->add(ini->ReadString(L"Printer",L"TailLine5",L""));
|
||
delete ini;
|
||
|
||
for(int i=Text->count()-1;i>=0;i--)
|
||
if(Text->get(i)==L"") Text->del(i); else break;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
bool PrinterOPOS::PrintLine(std::wstring line)
|
||
{
|
||
//Íå ôèñêàëüíàÿ ïå÷àòü
|
||
long err=0;
|
||
try
|
||
{ if(Crashed) throw std::runtime_error("Äðàéâåð ïðèíòåðà ðàçðóøåí!");
|
||
|
||
std::wstring str = L"";
|
||
str += WCHAR(0x1B);
|
||
str += WCHAR(0x7C);
|
||
str += line;
|
||
str += L"\n";
|
||
|
||
BSTR bstr = SysAllocString(str.c_str());
|
||
err = fp->PrintNormal(2, bstr);
|
||
SysFreeString(bstr);
|
||
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
}catch(std::exception &exception)
|
||
{
|
||
if(err==251) Crashed=true; //Êàáçäåö
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::PrintLine)")+exception.what());
|
||
//dModule->SendError(err,std::string("(PrinterOPOS::PrintLine)")+exception);
|
||
}catch(...)
|
||
{
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::PrintLine) Íåò îïèñàíèÿ îøèáêè"));
|
||
//dModule->SendError(1,std::string("(PrinterOPOS::PrintLine) Íåò îïèñàíèÿ îøèáêè"));
|
||
}
|
||
return err==0;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
//sales - true ïðîäàæà, false - âîçâðàò
|
||
//check - íîìåð ÷åêà åñëè íå çàäàí =0 òî ãåíåðèòüñÿ
|
||
//TODO Ôè÷à ýòî ôèêñèðîâàòü íå ðàñïå÷àòàííûå ÷åêè ïîòîì ïå÷àòàòü èõ
|
||
bool PrinterOPOS::PrintCheck(bool sales, int check, std::wstring headLine) //Òåñòîâàÿ ïå÷àòü
|
||
{
|
||
long err=0;
|
||
double cur=0;
|
||
double cAllPrice=0;
|
||
bool bOk=true;
|
||
|
||
try
|
||
{ if(Crashed) throw std::runtime_error("Äðàéâåð ïðèíòåðà ðàçðóøåí!");
|
||
|
||
//Ñ÷èòàåì ñóììó â ÷åêå (çàðàíåå íà ñëó÷àé îøèáêè)
|
||
cAllPrice=getGoodsPrice();
|
||
|
||
if(check==0) //åñëè íå çàäàí íîìåð ÷åêà òî ãåíåðèì ñäåñü
|
||
{
|
||
CheckId++; //Íîìåð ÷åêà
|
||
check=CheckId;
|
||
SaveSetup(); //ñîõðàíÿåì íîìåð ÷åêà
|
||
}
|
||
|
||
if(fp->RecEmpty) throw std::runtime_error("Íåò áóìàãè!");
|
||
if(!DayOpened()) throw std::runtime_error("Ñìåíà íå îòêðûòà");
|
||
|
||
double UnitPrice,AllPriceDrb,AllPrice;
|
||
long Qnt,vat;
|
||
BSTR* bstr;
|
||
std::wstring sStr;
|
||
BSTR sTmp=new OLECHAR[255];
|
||
sTmp=L"";
|
||
long MbsResponceCode;
|
||
CURRENCY Amount1,Amount2;
|
||
|
||
//Óñòàíîâêà íîìåðà îòäåëà
|
||
//vat=11; sTmp=L"îòäåë";
|
||
//err = fp->DirectIO(4, &vat, &sTmp);
|
||
//if (err) goto ErrHandler;
|
||
|
||
//Æåëàòåëüüíî ñäåëàòü â íóòðè ÷åêà TODO!!!
|
||
if(headLine.size()>0)
|
||
PrintLine(headLine);
|
||
|
||
|
||
if(sales) fp->FiscalReceiptType = FPTR_RT_SALES; //×åê ïðîäàæè
|
||
else fp->FiscalReceiptType=FPTR_RT_SERVICE; //×åê âîçâðàòà
|
||
|
||
//setTrainingMode(true);
|
||
|
||
//Ôèñêàëüíàÿ ïå÷àòü (ñ çàãîëîâêîì èëè áåç)
|
||
err = fp->BeginFiscalReceipt(true);
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale(""))); //251
|
||
}
|
||
|
||
//Òîâàðû èç ñïèñêà â äðàéâåð (TODO Ïðè ïå÷àòè ÷åêà íå ïå÷àòàåòñÿ óñëóãà)
|
||
for(int i=0;i<FListGoods->count();i++)
|
||
{
|
||
Goods* goods=(Goods*)FListGoods->get(i);
|
||
VarCyFromR8(goods->price*100,&Amount1);
|
||
Amount2.int64=0;
|
||
std::wstring tmp=goods->name1+L"-/--/-0";
|
||
err=fp->PrintRecItem(tmp.c_str(), Amount1, goods->count, goods->VatInfo, Amount2, L"Øò");
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
}
|
||
ClearGoods();
|
||
|
||
//óñòàíîâêà íîìåðà ÷åêà (Ïåðåä PrintRecTotal)
|
||
err = fp->DirectIO(3, &CheckId, &sTmp);
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
|
||
//Óñòàíîâêà çíà÷åíèé ìàññèâà íàëîãîâûõ ñòàâîê
|
||
//setNalog(1,12);
|
||
|
||
//Ôîðìèðîâàíèÿ èòîãà â ÷åêå
|
||
Amount2.int64=0;
|
||
VarCyFromR8(cAllPrice*100,&Amount1);
|
||
err=fp->PrintRecTotal(Amount1, Amount1, L"na");
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
|
||
|
||
err = fp->EndFiscalReceipt(VARIANT_TRUE); //Îêîí÷àíèÿ ïå÷àòè, â íåì ïðîèñõîäèò ïå÷àòü äîïîëíèòåëüíîãî òðåéëåðà (AdditionalTrailer) è îáðåçêà áóìàãè
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
}
|
||
catch(std::exception &exception)
|
||
{
|
||
ClearGoods();
|
||
if(err==251) Crashed=true; //Êàáçäåö
|
||
//Utility::logrotate(m_LogFilePath + "\\log.txt", "Îøèáêà ïðè ïå÷àòè ÷åêà: N: "+IntToStr(dModule->UserId)+" ñóììà: "+CurrToStr(cAllPrice)+" ×åê: "+ std::string(CheckId)+". "+exception);
|
||
//dModule->SendError(err,"Îøèáêà ïðè ïå÷àòè ÷åêà: N: "+IntToStr(dModule->UserId)+" ñóììà: "+IntToStr(cAllPrice)+" ×åê: "+ std::string(CheckId)+". "+exception);
|
||
bOk=false;
|
||
}
|
||
catch(...)
|
||
{
|
||
ClearGoods();
|
||
if(err==251) Crashed=true; //Êàáçäåö
|
||
//Utility::logrotate(m_LogFilePath + "\\log.txt", "Íå îïîçíàííàÿ îøèáêà ïðè ïå÷àòè ÷åêà: N: "+IntToStr(dModule->UserId)+" ñóììà: "+IntToStr(cAllPrice)+" ×åê: "+ std::string(CheckId));
|
||
//dModule->SendError(1,"Íå îïîçíàííàÿ îøèáêà ïðè ïå÷àòè ÷åêà: N: "+IntToStr(dModule->UserId)+" ñóììà: "+IntToStr(cAllPrice)+" ×åê: "+ std::string(CheckId));
|
||
bOk=false;
|
||
}
|
||
//ñáðîñ ÷åêà
|
||
if(!bOk)
|
||
{
|
||
fp->PrintRecVoid(L"");
|
||
}
|
||
|
||
return bOk;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
bool PrinterOPOS::Cut() //Îòðåçàòü áóìàãó
|
||
{
|
||
long err=0;
|
||
try
|
||
{
|
||
if (Crashed)
|
||
{
|
||
throw std::runtime_error("Äðàéâåð ïðèíòåðà ðàçðóøåí!");
|
||
}
|
||
std::wstring wstr = L"";
|
||
wstr += WCHAR(0x1B);
|
||
wstr += WCHAR(0x7C);
|
||
wstr += L"75P";
|
||
err=fp->PrintNormal(2, wstr.c_str());
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
}catch(std::exception &exception)
|
||
{
|
||
if(err==251) Crashed=true; //Êàáçäåö
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::Cut)")+exception.what());
|
||
//dModule->SendError(err,std::string("(PrinterOPOS::Cut)")+exception);
|
||
}catch(...)
|
||
{
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::Cut) Íåò îïèñàíèÿ îøèáêè"));
|
||
//dModule->SendError(1,std::string("(PrinterOPOS::Cut) Íåò îïèñàíèÿ îøèáêè"));
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
//Ïîëó÷èòü òåêóùåå ñîñòîÿíèå ïðèíòåðà (÷òîá ïðîâåðèòü ãîòîâíîñòü ïå÷àòè)
|
||
/*int PrinterOPOS::GetState()
|
||
{
|
||
if(!fp->DeviceEnabled)FState=245;
|
||
//if(FState!=0) return FState;
|
||
//ïðîâåðÿåì
|
||
//Íàäî äîáàâèòü ëîã
|
||
// fp->ResultCodeExtended
|
||
return 0;
|
||
} */
|
||
//---------------------------------------------------------------------------
|
||
//Ïðîâåðêà ðîáîòîñïîñîáíîñòè ïðèíòåðà
|
||
bool PrinterOPOS::isOk()
|
||
{
|
||
long err=0;
|
||
try
|
||
{
|
||
if(Crashed) throw std::runtime_error("Äðàéâåð ïðèíòåðà ðàçðóøåí!");
|
||
if(fp->RecEmpty) throw "Íåò áóìàãè!";
|
||
err=fp->ResetPrinter();
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale(""))); //Î÷èùàåò î÷åðåäü ñ ñîáûòèÿìè
|
||
}
|
||
|
||
std::wstring str;
|
||
|
||
//if(!dModule->getDayShift())throw std::runtime_error("Ñìåíà â áàçå íå îòêðûòà!"); //Ïðîâåðÿåì â áàçå îòêðûòà ëè ñìåí
|
||
|
||
bool dOpen=DayOpened();
|
||
if(!dOpen && AutoOpenShift && OpenShift()) dOpen=true;
|
||
if(!dOpen) throw std::runtime_error("Ñìåíà íå îòêðûòà!");
|
||
|
||
if(DayOpened())
|
||
{
|
||
//Ïðîâåðêà íà äëèíó ñìåíû
|
||
std::wstring dt=getDateOpenShift();
|
||
str=getLastError(&err);
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
|
||
//dModule->getDate();
|
||
//if(HoursBetween(dt,dModule->date)>24) //Ðàçíèöà íå áîëåå 24 ÷àñîâ
|
||
// throw std::runtime_error("[1]Ñìåíà íå çàêðûòà");
|
||
|
||
} else throw std::runtime_error("Ïðèíòåð íå ðàáîòàåò!");
|
||
BSTR bstr=new OLECHAR[50];
|
||
err=fp->GetDate(&bstr);
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
}
|
||
catch(std::exception &exception)
|
||
{
|
||
if(err==251) Crashed=true; //Êàáçäåö
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::isOk)")+exception.what());
|
||
//dModule->SendError(err,std::string("(PrinterOPOS::isOk)")+exception);
|
||
return false;
|
||
}
|
||
catch (...)
|
||
{
|
||
if(err==251) Crashed=true; //Êàáçäåö
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::isOk)Íåîïîçíàííàÿ îøèáêà"));
|
||
//dModule->SendError(1,std::string("(PrinterOPOS::isOk)Íåîïîçíàííàÿ îøèáêà"));
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
//Ïîëó÷èòü äàòó îòêðûòèÿ ñìåíû
|
||
std::wstring PrinterOPOS::getDateOpenShift()
|
||
{
|
||
long err=0;
|
||
std::wstring date=0;
|
||
try
|
||
{
|
||
if(Crashed) throw std::runtime_error("Äðàéâåð ïðèíòåðà ðàçðóøåí!");
|
||
|
||
long iTmp;
|
||
BSTR sTmp=new OLECHAR[50];
|
||
err=fp->DirectIO(13, &iTmp, &sTmp); //ÌÌ/ÄÄ/ÃÃ ××:ÌÌ:ÑÑ
|
||
if (err) {
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
date=sTmp;
|
||
}catch(std::exception &exception)
|
||
{
|
||
if(err==251) Crashed=true; //Êàáçäåö
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::getDateOpenShift)")+exception.what());
|
||
//dModule->SendError(err,std::string("(PrinterOPOS::getDateOpenShift)")+exception);
|
||
}catch(...)
|
||
{
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::getDateOpenShift) Íåò îïèñàíèÿ îøèáêè"));
|
||
//dModule->SendError(1,std::string("(PrinterOPOS::getDateOpenShift) Íåò îïèñàíèÿ îøèáêè"));
|
||
}
|
||
return date;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
//Îïèñàíèå ñòàòóñà
|
||
std::wstring PrinterOPOS::GetStatusDescription(long err)
|
||
{
|
||
std::wstring str;
|
||
try
|
||
{
|
||
if(err<256)
|
||
str=kkm_err_msg_ru[err];
|
||
if(str==L"") str=L"Íåò îïèñàíèÿ îøèáêè";
|
||
}catch(...)
|
||
{
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::GetStatusDescription) Íåò îïèñàíèÿ îøèáêè"));
|
||
return L"Íåò îïèñàíèÿ îøèáêè";
|
||
}
|
||
return str;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
//Ïîëó÷èòü êîä ïîñëåäíåé îøèáêè
|
||
std::wstring PrinterOPOS::getLastError(long* err)
|
||
{
|
||
BSTR str=new OLECHAR[255];
|
||
str=L"Íåò îïèñàíèÿ îøèáêè!";
|
||
try
|
||
{
|
||
fp->DirectIO(1, err, &str);
|
||
}catch(...)
|
||
{
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::getLastError) Íåò îïèñàíèÿ îøèáêè"));
|
||
}
|
||
if(str==L"") return GetStatusDescription(*err);
|
||
return std::wstring(str);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
std::wstring PrinterOPOS::getLastError()
|
||
{
|
||
long err;
|
||
return getLastError(&err);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
//Ïå÷àòü îò÷¸òà è çàêðûòèå ñìåíû
|
||
bool PrinterOPOS::PrintZReport()
|
||
{
|
||
long err=0;
|
||
try
|
||
{
|
||
if(Crashed) throw std::runtime_error("Äðàéâåð ïðèíòåðà ðàçðóøåí!");
|
||
|
||
int sum=getDaySum();
|
||
err=fp->PrintZReport();
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
//dModule->addZReport(sum);//Ïîñëàòü íà ñåðâåð âðåìÿ ñíÿòèÿ Z îò÷¸òà
|
||
//dModule->addPaper(-142*2);//Äëÿ ïîäñ÷¸òà êîíöà áóìàãè
|
||
}catch(std::exception &exception)
|
||
{
|
||
if(err==251) Crashed=true; //Êàáçäåö
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::PrintZReport)")+exception.what());
|
||
//dModule->SendError(err,std::string("(PrinterOPOS::PrintZReport)")+exception);
|
||
}catch(...)
|
||
{
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::PrintZReport) Íåò îïèñàíèÿ îøèáêè"));
|
||
//dModule->SendError(1,std::string("(PrinterOPOS::PrintZReport) Íåò îïèñàíèÿ îøèáêè"));
|
||
}
|
||
return err==0;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
//Ïå÷àòü ñóòî÷íîãî îò÷¸òà áåç çàêðûòèÿ ñìåíû
|
||
void PrinterOPOS::PrintXReport()
|
||
{
|
||
long err=0;
|
||
try
|
||
{ if(Crashed) throw std::runtime_error("Äðàéâåð ïðèíòåðà ðàçðóøåí!");
|
||
err=fp->PrintXReport();
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
}catch(std::exception &exception)
|
||
{
|
||
if(err==251) Crashed=true; //Êàáçäåö
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::PrintXReport)")+exception.what());
|
||
//dModule->SendError(err,std::string("(PrinterOPOS::PrintXReport)")+exception);
|
||
}catch(...)
|
||
{
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::PrintXReport) Íåò îïèñàíèÿ îøèáêè"));
|
||
//dModule->SendError(1,std::string("(PrinterOPOS::PrintXReport) Íåò îïèñàíèÿ îøèáêè"));
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
//Îòêðûòèå ñìåíû
|
||
bool PrinterOPOS::OpenShift()
|
||
{
|
||
long err;
|
||
try
|
||
{ if(Crashed) throw std::runtime_error("Äðàéâåð ïðèíòåðà ðàçðóøåí!");
|
||
long n=1;
|
||
//if(CasireName==NULL) CasireName=L" ";
|
||
BSTR str= SysAllocString(CasireName.c_str());
|
||
err=fp->DirectIO (6,&n,&str);
|
||
SysFreeString(str);
|
||
if (err) {
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale(""))); //Ïåðåäàë íîìåð è íàçâàíèå êàññèðà
|
||
}
|
||
err=fp->SetVatValue(1,L"120");
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
}catch(std::exception &exception)
|
||
{
|
||
if(err==251) Crashed=true; //Êàáçäåö
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::OpenShift)")+exception.what());
|
||
//dModule->SendError(err,std::string("(PrinterOPOS::OpenShift)")+exception);
|
||
}catch(...)
|
||
{
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::OpenShift) Íåò îïèñàíèÿ îøèáêè"));
|
||
//dModule->SendError(1,std::string("(PrinterOPOS::OpenShift) Íåò îïèñàíèÿ îøèáêè"));
|
||
}
|
||
return err==0;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
bool PrinterOPOS::DayOpened()
|
||
{
|
||
return fp->DayOpened;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
bool PrinterOPOS::setTrainingMode(bool val)
|
||
{
|
||
long err;
|
||
try
|
||
{ if(Crashed) throw std::runtime_error("Äðàéâåð ïðèíòåðà ðàçðóøåí!");
|
||
if(getTrainingMode()==val) return true;
|
||
if(val) err=fp->BeginTraining(); else err=fp->EndTraining();
|
||
if (err)
|
||
{
|
||
throw std::runtime_error(Utility::WStringToString(getLastError(&err), std::locale("")));
|
||
}
|
||
}catch(std::exception &exception)
|
||
{
|
||
if(err==251) Crashed=true; //Êàáçäåö
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::setTrainingMode)")+exception.what());
|
||
//dModule->SendError(err,std::string("(PrinterOPOS::setTrainingMode)")+exception);
|
||
}catch(...)
|
||
{
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::setTrainingMode) Íåò îïèñàíèÿ îøèáêè"));
|
||
//dModule->SendError(1,std::string("(PrinterOPOS::setTrainingMode) Íåò îïèñàíèÿ îøèáêè"));
|
||
}
|
||
return err==0;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
bool PrinterOPOS::getTrainingMode()
|
||
{
|
||
return fp->TrainingModeActive;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
//Çàïîëíåíèå ìàññèâà ñ ñóììàìè ïî íàëîãîâûì ñòàâêàì
|
||
bool PrinterOPOS::setNalog(long n,float stavka)
|
||
{
|
||
long err;
|
||
try
|
||
{ if(Crashed) throw std::runtime_error("Äðàéâåð ïðèíòåðà ðàçðóøåí!");
|
||
long s=stavka*10;
|
||
std::wstring str= Utility::IntToStdWStr(s);
|
||
BSTR bstr = SysAllocString(str.c_str());
|
||
err = fp->DirectIO(2, &n, &bstr);
|
||
SysFreeString(bstr);
|
||
|
||
if (err) {
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
}catch(std::exception &exception)
|
||
{
|
||
if(err==251) Crashed=true; //Êàáçäåö
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::setNalog)")+exception.what());
|
||
//dModule->SendError(err,std::string("(PrinterOPOS::setNalog)")+exception);
|
||
return true;
|
||
}catch(...)
|
||
{
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::setNalog) Íåò îïèñàíèÿ îøèáêè"));
|
||
//dModule->SendError(1,std::string("(PrinterOPOS::setNalog) Íåò îïèñàíèÿ îøèáêè"));
|
||
return true;
|
||
}
|
||
|
||
return err==0;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
//Äíåâíîé èòîã
|
||
int PrinterOPOS::getDaySum()
|
||
{
|
||
long err;
|
||
try
|
||
{ if(Crashed) throw std::runtime_error("Äðàéâåð ïðèíòåðà ðàçðóøåí!");
|
||
long n=1;
|
||
BSTR str=new OLECHAR[20];
|
||
err=fp->DirectIO (300,&n,&str);
|
||
if (err)
|
||
{
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
return Utility::StdWStrToInt(str)/100.0;
|
||
}catch(std::exception &exception)
|
||
{
|
||
if(err==251) Crashed=true; //Êàáçäåö
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::getDaySum)")+exception.what());
|
||
//dModule->SendError(err,std::string("(PrinterOPOS::getDaySum)")+exception);
|
||
return 0;
|
||
}catch(...)
|
||
{
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::getDaySum) Íåò îïèñàíèÿ îøèáêè"));
|
||
//dModule->SendError(1,std::string("(PrinterOPOS::getDaySum) Íåò îïèñàíèÿ îøèáêè"));
|
||
return 0;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
//Ñóììà â êàññå
|
||
int PrinterOPOS::getAllSum()
|
||
{
|
||
long err=0;
|
||
try
|
||
{ if(Crashed) throw std::runtime_error("Äðàéâåð ïðèíòåðà ðàçðóøåí!");
|
||
long n=2;
|
||
BSTR str=new OLECHAR[20];
|
||
err=fp->DirectIO (300,&n,&str);
|
||
if (err) {
|
||
std::wstring estr = getLastError(&err);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
std::wstring wstr = str;
|
||
return Utility::StdWStrToInt(wstr)/100.0;
|
||
}catch(std::exception &exception)
|
||
{
|
||
if(err==251) Crashed=true; //Êàáçäåö
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::getAllSum)")+exception.what());
|
||
//dModule->SendError(err,std::string("(PrinterOPOS::getAllSum)")+exception);
|
||
return 0;
|
||
}catch(...)
|
||
{
|
||
Utility::logrotate(m_LogFilePath + "\\log.txt", std::string("(PrinterOPOS::getAllSum) Íåò îïèñàíèÿ îøèáêè"));
|
||
//dModule->SendError(1,std::string("(PrinterOPOS::getAllSum) Íåò îïèñàíèÿ îøèáêè"));
|
||
return 0;
|
||
}
|
||
}
|
||
|
||
//---------------------------------------------------------------------------
|
||
//sales - true ïðîäàæà, false - âîçâðàò
|
||
//check - íîìåð ÷åêà åñëè íå çàäàí =0 òî ãåíåðèòüñÿ
|
||
//Ôè÷à: ôèêñèðîâàòü íå ðàñïå÷àòàííûå ÷åêè ïîòîì ïå÷àòàòü èõ
|
||
bool FiscalPrinterPort::PrintCheck(bool sales, int check, std::wstring headLine )
|
||
{
|
||
//bool err=0;
|
||
double cur=0;
|
||
double cAllPrice=0;
|
||
bool bOk=true;
|
||
|
||
try
|
||
{
|
||
//Ñ÷èòàåì ñóììó â ÷åêå (çàðàíåå íà ñëó÷àé îøèáêè)
|
||
cAllPrice=getGoodsPrice();
|
||
|
||
double UnitPrice,AllPriceDrb,AllPrice;
|
||
long Qnt,vat;
|
||
BSTR* bstr;
|
||
std::wstring sStr;
|
||
BSTR sTmp=new OLECHAR[255];
|
||
sTmp=L"";
|
||
long MbsResponceCode;
|
||
double Amount1,Amount2;
|
||
|
||
//Ôèñêàëüíûé ÷åê ïðîäàæè èëè âîçâðàòà
|
||
if(sales) bOk = fp->OpenFiscalInv(1,"0000",1).ErrorCode==0;
|
||
else bOk = fp->OpenBackInv(1,"0000",1).ErrorCode==0;
|
||
if (!bOk)
|
||
{
|
||
std::wstring estr = getLastError();
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
|
||
if(headLine.size()>0)
|
||
PrintLine(headLine);
|
||
|
||
//Òîâàðû èç ñïèñêà â äðàéâåð
|
||
for(int i=0;i<FListGoods->count();i++)
|
||
{
|
||
Goods* goods=(Goods*)FListGoods->get(i);
|
||
bOk=fp->RegisterSale(goods->name1.c_str(),goods->name2.c_str(),0,"À",goods->price,goods->count,0,0).ErrorCode==0; //Ðåãèñòðàöèÿ ïðîäàæè (ëèáî âîçâðàòà)
|
||
if (!bOk)
|
||
{
|
||
std::wstring estr = getLastError();
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
}
|
||
ClearGoods();
|
||
|
||
//Ôîðìèðîâàíèÿ èòîãà â ÷åêå (îïëàòà)
|
||
double Change;
|
||
bOk=fp->Total("","","P",cAllPrice,Change).ErrorCode==0;
|
||
if (!bOk)
|
||
{
|
||
std::wstring estr = getLastError();
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
//Çàêðûâàåì ÷åê
|
||
bOk = fp->CloseFiscalInv().ErrorCode==0;
|
||
if (!bOk)
|
||
{
|
||
std::wstring estr = getLastError();
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
}
|
||
catch(std::exception &exception)
|
||
{
|
||
ClearGoods();
|
||
//Utility::logrotate(m_LogFilePath + "\\log.txt", "Îøèáêà ïðè ïå÷àòè ÷åêà: N: "+IntToStr(dModule->UserId)+" ñóììà: "+CurrToStr(cAllPrice)+" ×åê: "+ std::string(CheckId)+". "+exception);
|
||
//dModule->SendError(bOk,"Îøèáêà ïðè ïå÷àòè ÷åêà: N: "+IntToStr(dModule->UserId)+" ñóììà: "+FloatToStr(cAllPrice)+" ×åê: "+ std::string(CheckId)+". "+exception);
|
||
bOk=false;
|
||
}
|
||
catch(...)
|
||
{
|
||
ClearGoods();
|
||
//Utility::logrotate(m_LogFilePath + "\\log.txt", "Íå îïîçíàííàÿ îøèáêà ïðè ïå÷àòè ÷åêà: N: "+IntToStr(dModule->UserId)+" ñóììà: "+FloatToStr(cAllPrice)+" ×åê: "+ std::string(CheckId));
|
||
//dModule->SendError(1,"Íå îïîçíàííàÿ îøèáêà ïðè ïå÷àòè ÷åêà: N: "+IntToStr(dModule->UserId)+" ñóììà: "+FloatToStr(cAllPrice)+" ×åê: "+ std::string(CheckId));
|
||
bOk=false;
|
||
}
|
||
//ñáðîñ ÷åêà
|
||
if(!bOk)
|
||
{
|
||
fp->CancelFiscalInv();
|
||
}
|
||
return bOk;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
bool FiscalPrinterPort::PrintZReport()
|
||
{
|
||
bool bOk;
|
||
try
|
||
{
|
||
double Amount=0,CashSum=0,ServIn=0,ServOut=0;
|
||
std::string Oper,Password,ExitCode="";
|
||
std::wstring strH,strF;
|
||
bOk=fp->ParishOrConsumption(Oper,Password,Amount,strH,strF,ExitCode,CashSum,ServIn,ServOut).ErrorCode==0;
|
||
if (!bOk)
|
||
{
|
||
std::wstring estr = getLastError();
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
bOk=fp->PrintZReport().ErrorCode==0;
|
||
if (!bOk)
|
||
{
|
||
std::wstring estr = getLastError();
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
//dModule->addZReport(CashSum);//Ïîñëàòü íà ñåðâåð âðåìÿ ñíÿòèÿ Z îò÷¸òà
|
||
}
|
||
catch(std::exception &exception)
|
||
{
|
||
ClearGoods();
|
||
Utility::logrotate(m_LogFilePath + std::string("\\log.txt"), std::string("Îøèáêà ïðè ïå÷àòè Z îò÷¸òà ")+exception.what());
|
||
//dModule->SendError(bOk,"Îøèáêà ïðè ïå÷àòè Z îò÷¸òà "+exception);
|
||
bOk=false;
|
||
}
|
||
catch(...)
|
||
{
|
||
ClearGoods();
|
||
Utility::logrotate(m_LogFilePath + std::string("\\log.txt"), std::string("Íå îïîçíàííàÿ îøèáêà ïðè ïå÷àòè Z îò÷¸òà."));
|
||
//dModule->SendError(1,"Íå îïîçíàííàÿ îøèáêà ïðè ïå÷àòè Z îò÷¸òà.");
|
||
bOk=false;
|
||
}
|
||
|
||
return bOk;
|
||
};
|
||
//---------------------------------------------------------------------------
|
||
bool FiscalPrinterPort::isOk()
|
||
{
|
||
try
|
||
{
|
||
MyError err = fp->DiagnosticInfo();
|
||
if (err.ErrorCode!=0)
|
||
{
|
||
std::wstring estr = Utility::convUTF8ToUTF16(err.ErrorMessage);
|
||
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
||
}
|
||
//if(!dModule->getDayShift())throw std::runtime_error("Ñìåíà â áàçå íå îòêðûòà!"); //Ïðîâåðÿåì â áàçå îòêðûòà ëè ñìåí
|
||
}
|
||
catch(std::exception &exception)
|
||
{
|
||
Utility::logrotate(m_LogFilePath + std::string("\\log.txt"), std::string("(PrinterOPOS::isOk)")+exception.what());
|
||
//dModule->SendError(1,std::string("(PrinterOPOS::isOk)")+exception);
|
||
return false;
|
||
}
|
||
catch (...)
|
||
{
|
||
Utility::logrotate(m_LogFilePath + std::string("\\log.txt"), std::string("(PrinterOPOS::isOk)Íåîïîçíàííàÿ îøèáêà"));
|
||
//dModule->SendError(1,std::string("(PrinterOPOS::isOk)Íåîïîçíàííàÿ îøèáêà"));
|
||
return false;
|
||
}
|
||
return true;
|
||
};
|
||
//---------------------------------------------------------------------------
|