Skip to content

Instantly share code, notes, and snippets.

@dyrkow
Last active March 21, 2023 08:40
Show Gist options
  • Save dyrkow/9e67e84904ce5f179450e2fc1fc8553a to your computer and use it in GitHub Desktop.
Save dyrkow/9e67e84904ce5f179450e2fc1fc8553a to your computer and use it in GitHub Desktop.
Abstract Hardware
/**
* This interface define bank terminal device
*
* @method payByPaymentCard
* @method cancelPayByPaymentCard
* @method settlement
* @method report
*/
export interface IBankTerminal extends IHardware {
/**
* Receives money from the client
*/
payByPaymentCard(value: number): Promise<PayByPaymentCardResult>;
/**
* Makes a refund to the customer
*/
cancelPayByPaymentCard(
request: CancelPayByPaymentCardRequest
): Promise<CancelPayByPaymentCardResult>;
/**
* Closes the card shift
*/
settlement(): Promise<SettlementResult>;
/**
* Returns the totals of the day by cards
*/
report(): Promise<ReportResult>;
}
export type CancelPayByPaymentCardRequest = {
value: number;
rnn: string;
rn?: string;
ac: string;
cn?: string;
};
export type BankTerminalResult = { Slip: string };
export type PayByPaymentCardResult = BankTerminalResult & {
RRN?: string;
RN?: string;
AC?: string;
CN?: string;
};
export type CancelPayByPaymentCardResult = PayByPaymentCardResult;
export type SettlementResult = BankTerminalResult;
export type ReportResult = BankTerminalResult;
/**
* This interface define barcode scanned device
*/
export interface IBarcodeScanner extends IHardware {
/**
* Starts the scanning process
*/
scan(): Promise<ScanResult>;
}
export type ScanResult = {
type: string;
value: string;
};
/**
* This interface define cashbox device
*
* @method open
*/
export interface ICashbox extends IHardware {
/**
* Open cashbox
*/
open(): Promise<void>;
}
/**
* This interface define abstract hardware device
*
* @method connect
* @method disconnect
*/
export interface IHardware {
/**
* Establishes a connection with the device
*/
connect(): Promise<void>;
/**
* Breaks the connection with the device
*/
disconnect(): Promise<void>;
}
/**
* This interface define kkt device
*
* @method registerCheck
* @method openShift
* @method closeShift
* @method printXReport
* @method depositCash
* @method withdrawCash
*/
export interface Ikkt extends IPrinter {
/**
* Print open shift
*/
openShift(request: OpenShiftRequest): Promise<OpenShiftResult>;
/**
* Print ZReport and close shift
*/
closeShift(request: CloseShiftRequest): Promise<CloseShiftResult>;
/**
* Print interim report
*/
printXReport(): Promise<void>;
/**
* Deposit cash sum
*/
depositCash(amount: number): Promise<void>;
/**
* Withdraw cash sum
*/
withdrawCash(amount: number): Promise<void>;
}
export type RegisterCheckResult = FiscalInfo;
export type OpenShiftRequest = Cashier;
export type OpenShiftResult = FiscalInfo;
export type CloseShiftRequest = Cashier;
export type CloseShiftResult = FiscalInfo;
/**
* This interface define printer device
*
* @method print
*/
export interface IPrinter extends IHardware {
/**
* Just print array of printable lines
*/
print(receipt: Printable): Promise<PrintableResult>;
}
export enum BarcodeType {
EAN13 = 'EAN13',
CODE39 = 'CODE39',
CODE128 = 'CODE128',
QR = 'QR',
PDF417 = 'PDF417',
}
export enum FontSize {
num1 = 1, // Самый большой
num2 = 2,
num3 = 3,
num4 = 4, // Самый маленький
}
export enum FontIntensity {
num1 = 1,
num2 = 2,
num3 = 3,
num4 = 4,
num5 = 5,
num6 = 6,
num7 = 7,
num8 = 8,
num9 = 9,
num10 = 10,
num11 = 11,
num12 = 12,
num13 = 13,
num14 = 14,
num15 = 15,
}
export type PrintableBardcode = {
Barcode: {
BarcodeType: BarcodeType;
Barcode: string;
}
};
export type PrintableImage = {
PrintImage: {
Image: string;
}
};
export type PrintableText = {
PrintText: {
Text: string;
Font?: FontSize;
Intensity?: FontIntensity;
}
};
export type PrintableRegister = {
Register: {
Name: string;
Quantity: number;
Price: number;
Amount: number;
Department?: number;
Tax?: VAT;
GoodCodeData?: GoodCodeData;
};
}
export type PrintableLine = PrintableBardcode | PrintableImage | PrintableText | PrintableRegister;
export type GoodCodeData = {
BarCode: string;
ContainsSerialNumber: boolean;
};
export enum VAT {
vat0 = 0, // НДС 0%
vat10 = 10, // НДС 10%
vat18 = 18, // НДС 18%
vatnone = -1, // НДС не облагается
}
export enum TypeCheck {
sell = 0, // подажа
payback = 1, // возврат продажи
sellCorrection = 2, // коррекция продажи
paybackCorrection = 3, // коррекция возврата продажи
buy = 10, // расход
buyback = 11, // возврат расхода
buyCorrection = 12, // коррекция расхода
buybackCorrection = 13, // коррекция возврата расхода
}
export enum TaxVariant {
osn = 0, // общая СНО ОСН
usnIncome = 1, // упрощенная УСН (Доход)
usnIncomeOutcome = 2, // упрощенная УСН (Доход минус Расход)
envd = 3, // единый налог на вмененный доход ЕНВД
esn = 4, // единый сельскохозяйственный налог ЕСН
patent = 5, // патентная система налогообложения
}
export type FiscalInfo = {
CheckNumber: number;
SessionNumber: number;
SessionCheckNumber?: number;
MarkingCodeValidation?: MarkingCodeValidation;
URL: string;
QRCode: string;
};
export type MarkingCodeValidation = {
BarCode: string;
ValidationResult: number;
DecryptionResult: string;
}
export type CashierInfo = {
CashierName: string;
CashierVATIN?: string;
}
export type PrintableResult = FiscalInfo | void;
export type RegisterPrintableLines = CashierInfo & {
IsFiscalCheck: boolean;
CheckStrings: PrintableLine[];
TypeCheck: TypeCheck;
NotPrint?: boolean;
ClientAddress?: string; // email or phone number
TaxVariant: TaxVariant;
}
export type Printable = RegisterPrintableLines | PrintableLine[];
/**
* This interface define printable builder
*
* @method withIsFiscalCheck
* @method withTypeCheck
* @method withNotPrint
* @method withClientAddress
* @method withTaxVarinat
* @method withCheckStrings
* @method addCheckStrings
* @method build
*/
export interface IPrintableBuilder {
withIsFiscalCheck(value: boolean): IPrintableBuilder;
withTypeCheck(value: TypeCheck): IPrintableBuilder;
withNotPrint(value: boolean): IPrintableBuilder;
withClientAddress(value: string): IPrintableBuilder;
withTaxVarinat(value: TaxVariant): IPrintableBuilder;
withCheckStrings(value: PrintableLine[]): IPrintableBuilder;
addCheckStrings(value: PrintableLine | PrintableLine[]): IPrintableBuilder;
build(): Printable;
}
/**
* This interface define director pattern for printable builder
*
* @method getPrintableFromSlipString
* @method getPrecheck
* @method getSell
* @method getPayback
* @method getPackingList
* @method getSbp
*/
export interface IPrintableDirector {
getPrintableFromSlipString(value: string): Printable;
getPrecheck(value: OrderDTO): Printable;
getSell(value: OrderDTO): Printable;
getPayback(value: OrderDTO): Printable;
getPackingList(value: OrderDTO): Printable;
getSbp(value: PaymentDTO): Printable;
}
/**
* This interface define scales devices
*
* @method getWeight
*/
export interface IScales extends IHardware {
/**
* Starts weighing process
*/
getWeight(): Promise<WeighingResult>;
}
export type WeighingResult = number;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment