254 lines
7.9 KiB
C++
254 lines
7.9 KiB
C++
//---------------------------------------------------------------------------
|
|
#ifndef PrinterOPOSH
|
|
#define PrinterOPOSH
|
|
//---------------------------------------------------------------------------
|
|
//#include <vcl.h>
|
|
//#include "OposFiscalPrinter_1_7_Lib_OCX.h"
|
|
#import "file:O:\MyDocuments\projects\Workspace_C++Builder\PayTerminal_XE\dist\OPOSFiscalPrinter.ocx"
|
|
#include "../FP300KZ/FP300KZ.h"
|
|
#include "structs.h"
|
|
#include <list>
|
|
//---------------------------------------------------------------------------
|
|
const LONG FPTR_RT_CASH_IN = 1;
|
|
const LONG FPTR_RT_CASH_OUT = 2;
|
|
const LONG FPTR_RT_GENERIC = 3;
|
|
const LONG FPTR_RT_SALES = 4;
|
|
const LONG FPTR_RT_SERVICE = 5;
|
|
const LONG FPTR_RT_SIMPLE_INVOICE = 6;
|
|
//---------------------------------------------------------------------------
|
|
//Ïðîäàâàåìûé òîâàð
|
|
class Goods
|
|
{
|
|
private:
|
|
public:
|
|
std::wstring name1; //Íàçâàíèå òîâàðà 1 ñòðîêà
|
|
std::wstring name2; //Íàçâàíèå òîâàðà 2 ñòðîêà
|
|
double price; //Öåíà çà åäåíèöó
|
|
long count; //Êîëè÷åñòâî
|
|
long VatInfo; //Íîìåð íàëîãîâîé ñòàâêè èç ñïðàâî÷íèêà
|
|
Goods(std::wstring name1, std::wstring name2, double price, long count,long VatInfo)
|
|
{ //if(name1==NULL)
|
|
// this->name1=L"";
|
|
//else
|
|
this->name1=name1;
|
|
//if(name2==NULL)
|
|
// this->name2=L"";
|
|
//else
|
|
this->name2=name2;
|
|
this->price=price;
|
|
this->count=count;
|
|
this->VatInfo=VatInfo;
|
|
};
|
|
};
|
|
//---------------------------------------------------------------------------
|
|
class FiscalPrinter
|
|
{
|
|
protected:
|
|
bool Crashed;
|
|
long FState;
|
|
TSimpleList<Goods*>* FListGoods;
|
|
long CheckId; //Ñêîëüêî ðàñïå÷àòàëè ÷åêîâ íà äàííîì òåðìèíàëå
|
|
public:
|
|
std::wstring HeadLine; //Ïåðâàÿ ñòðîêà â ÷åêå "Îïëàòà çà óñëóãè âîäîñíàáæåíèÿ"
|
|
std::wstring GoodsName; //Íàçâàíèå òîâàðà
|
|
std::wstring CasireName; //Èìÿ êàññèðà
|
|
bool TestMode;
|
|
bool AutoOpenShift; //Àâòî îòêðûòèå ñìåíû
|
|
std::string m_LogFilePath;
|
|
|
|
FiscalPrinter(){ FListGoods= new TSimpleList<Goods*>(); CheckId=0; LoadSetup(); };
|
|
virtual std::string getPrinterName()=0;
|
|
virtual bool Start()=0;
|
|
virtual bool isOk()=0;
|
|
virtual long getCheckId(){ return CheckId; }; //Íîìåð ïîñëåäíåãî îòïå÷àòîíîãî äîêóìåíòà
|
|
void ClearGoods()
|
|
{
|
|
try
|
|
{
|
|
while(FListGoods->count()>0)
|
|
{
|
|
Goods* g=FListGoods->get(0);
|
|
delete g;
|
|
FListGoods->del((unsigned int)0);
|
|
}
|
|
FListGoods->clear();
|
|
}catch(...)
|
|
{
|
|
Crashed=true;
|
|
}
|
|
};
|
|
int getGoodsPrice();
|
|
virtual bool PrintLine(std::wstring line)=0;
|
|
void addGoods(Goods* goods)
|
|
{
|
|
FListGoods->add(goods);
|
|
};
|
|
virtual bool getNextCheckId(int &id);
|
|
|
|
bool SaveCheck(int CheckId);
|
|
virtual bool PrintCheck(bool sales, int check, std::wstring headLine ) { return false; };
|
|
bool deleteCheck(int CheckId);
|
|
virtual std::wstring getLastError(){ return L""; };
|
|
virtual bool DayOpened(){ return false; };
|
|
virtual void setHeader(TSimpleList2<std::wstring>* Text){};
|
|
virtual void getHeader(TSimpleList2<std::wstring>* Text){};
|
|
virtual void setTrailer(TSimpleList2<std::wstring>* Text){};
|
|
virtual void getTrailer(TSimpleList2<std::wstring>* Text){};
|
|
virtual bool OpenShift(){ return true; }; //Îòêðûòèå ñìåíû
|
|
|
|
int getCOMPort();
|
|
int getBaudRate();
|
|
virtual bool setBaudRate(std::wstring data) = 0;
|
|
virtual bool setCOMPort(std::wstring data) = 0;
|
|
virtual bool PrintZReport()=0;
|
|
virtual void PrintXReport()=0;
|
|
|
|
void LoadSetup();
|
|
void SaveSetup();
|
|
virtual bool setTrainingMode(bool val){ return false; };
|
|
virtual bool Cut(){ return false; }; //Îòðåçàòü áóìàãó
|
|
virtual bool setNalog(long n,float stavka){ return false; }; //Çàïîëíåíèå ìàññèâà ñ ñóììàìè ïî íàëîãîâûì ñòàâêàì
|
|
virtual int getAllSum(){ return 0; };
|
|
virtual int PrintDiagnostic() = 0; //Ïå÷àòü äèàãíîñòè÷åñêîé èíôîðìàöèè
|
|
virtual int FeedPaper(int cnt) = 0;
|
|
virtual int Beep() = 0;
|
|
};
|
|
//---------------------------------------------------------------------------
|
|
//Îáâ¸ðòêà äëÿ OPOS ôèñêàëüíîãî ïðèíòåðà
|
|
class PrinterOPOS : public FiscalPrinter
|
|
{
|
|
private:
|
|
//TOPOSFiscalPrinter *fp;
|
|
OposFiscalPrinter_1_7_Lib::IOPOSFiscalPrinterPtr fp;
|
|
public:
|
|
std::string m_LogFilePath; ///<Êóäà ñîõðàíÿòü ëîã ôàéë
|
|
std::wstring m_LogFileWPath; ///<Êóäà ñîõðàíÿòü ëîã ôàéë
|
|
|
|
bool setTrainingMode(bool val);
|
|
bool getTrainingMode();
|
|
|
|
PrinterOPOS();
|
|
virtual ~PrinterOPOS();
|
|
std::string getPrinterName(){ return "Moebius";};
|
|
bool Start(); //Ñîåäåíèòüñÿ ïî COM ïîðòó è ïðîèíèöèàëèçèðîâàòü ïðèíòåð
|
|
bool PrintCheck(bool sales, int check, std::wstring headLine ); //Ïå÷àòü ÷åêà
|
|
|
|
bool SaveCheck(int CheckId); //Ñîõðàíåíèå ÷åêà äëÿ ïîñëåäóþùåé ðàñïå÷àòêè
|
|
bool deleteCheck(int CheckId); //Óäàëåíèå ÷åêà èç áàçû
|
|
|
|
bool Cut(); //Îòðåçàòü áóìàãó
|
|
//int GetState(); //0 - Íåò îøèáîê ãîòîâ ê ïå÷àòè ÷åêà
|
|
bool isOk(); //Ïðîâåðêà ðàáîòîñïîñîáíîñòè ïðèíòåðà
|
|
std::wstring GetStatusDescription(long StatusCode); //Îïèñàíèå ñòàòóñà
|
|
std::wstring getLastError(long* err); //Ïîëó÷èòü êîä ïîñëåäíåé îøèáêè
|
|
std::wstring getLastError(); //Ïîëó÷èòü êîä ïîñëåäíåé îøèáêè
|
|
std::wstring getDateOpenShift(); //Ïîëó÷èòü äàòó îòêðûòèÿ ñìåíû
|
|
|
|
void setHeader(TSimpleList2<std::wstring>* Text);
|
|
void getHeader(TSimpleList2<std::wstring>* Text);
|
|
void setTrailer(TSimpleList2<std::wstring>* Text);
|
|
void getTrailer(TSimpleList2<std::wstring>* Text);
|
|
int getCOMPort();
|
|
bool setCOMPort(std::wstring data);
|
|
int getDaySum(); //Ñóììà â êàññà ñ ïðîøëîãî Z îò÷¸òà
|
|
int getAllSum(); //Îáùèé èòîã ïðîäàæ
|
|
|
|
|
|
bool PrintLine(std::wstring line);
|
|
bool PrintZReport(); //Ïå÷àòü îò÷¸òà è çàêðûòèå ñìåíû
|
|
void PrintXReport(); //Ïå÷àòü ñóòî÷íîãî îò÷¸òà áåç çàêðûòèÿ ñìåíû
|
|
bool OpenShift(); //Îòêðûòèå ñìåíû
|
|
bool DayOpened(); //Îòðûòà ëè ñìåíà
|
|
|
|
bool setNalog(long n,float stavka); //Çàïîëíåíèå ìàññèâà ñ ñóììàìè ïî íàëîãîâûì ñòàâêàì
|
|
|
|
void Push(){}; //Â OPOS äðàéâåðå íåò òàêîé ôóíêöèè
|
|
int PrintDiagnostic() { return 0; };
|
|
int FeedPaper(int cnt)
|
|
{
|
|
return 0;
|
|
};
|
|
int Beep()
|
|
{
|
|
return 0;
|
|
};
|
|
};
|
|
//---------------------------------------------------------------------------
|
|
class FiscalPrinterPort : public FiscalPrinter
|
|
{
|
|
private:
|
|
FP300KZ* fp;
|
|
public:
|
|
FiscalPrinterPort():FiscalPrinter()
|
|
{ fp = new FP300KZ();
|
|
};
|
|
virtual ~FiscalPrinterPort(){ delete fp; };
|
|
std::string getPrinterName(){ return "Port";};
|
|
bool getNextCheckId(int &res)
|
|
{
|
|
int num;
|
|
bool b=fp->GetLastPrintedDocNumber(num).ErrorCode==0;
|
|
res=num+1;
|
|
if (!b)
|
|
{
|
|
std::wstring estr = getLastError();
|
|
throw std::runtime_error(Utility::WStringToString(estr, std::locale("")));
|
|
}
|
|
return b;
|
|
};
|
|
|
|
bool Start()
|
|
{
|
|
//fp->OpenCOMPort(getCOMPort(),getBaudRate());
|
|
//fp->OpenCOMPort(); //Íîìåð êîì ïîðòà è ñêîðîñòü çàäàíû çàðàíåå
|
|
return fp->PrinterInit().ErrorCode==0;
|
|
};
|
|
long getCheckId(){ int num; fp->GetLastPrintedDocNumber(num); return num; }; //Íîìåð ïîñëåäíåãî îòïå÷àòîíîãî äîêóìåíòà
|
|
|
|
bool PrintCheck(bool sales, int check, std::wstring headLine ); //Ïå÷àòü ÷åêà
|
|
|
|
bool isOk();
|
|
bool PrintLine(std::wstring line)
|
|
{
|
|
//if(line!=NULL)
|
|
return fp->PrintLine(line).ErrorCode==0;
|
|
//else
|
|
// return fp->PrintLine(L"");
|
|
};
|
|
std::wstring getLastError()
|
|
{
|
|
std::string str = fp->getLastErrorDest();
|
|
std::wstring result = Utility::StringToWString(str, std::locale(""));
|
|
return result;
|
|
};
|
|
bool DayOpened(){ return true; };
|
|
bool PrintZReport();
|
|
void PrintXReport() { fp->PrintXReport(); };
|
|
bool Cut(){ return fp->CutPaper().ErrorCode==0; };
|
|
int PrintDiagnostic() { return fp->PrintDiagnostic().ErrorCode==0; };
|
|
bool setBaudRate(std::wstring data)
|
|
{
|
|
//fp->cPort->BaudRate = StdWStrToInt(data);
|
|
return false;
|
|
};
|
|
bool setCOMPort(std::wstring data)
|
|
{
|
|
//fp->cPort->ComNumber = StdWStrToInt(data);
|
|
return false;
|
|
};
|
|
int FeedPaper(int cnt)
|
|
{
|
|
return fp->FeedPaper(cnt).ErrorCode==0;
|
|
};
|
|
int Beep()
|
|
{
|
|
MyError err = fp->Beep();
|
|
return err.ErrorCode;
|
|
};
|
|
|
|
};
|
|
//---------------------------------------------------------------------------
|
|
//extern FiscalPrinter* g_printer;
|
|
//---------------------------------------------------------------------------
|
|
#endif
|