public override CommandHandlerResponse Handle(IFiscalPrinterState fiscalPrinterState)
        {
            var state = fiscalPrinterState as FiscalPrinterState;

            var responseCommand = new ThermalFiscalPrinterCommand(new string[] { "1" }, "#U", state.FiscalPrinterHeader);

            return(new CommandHandlerResponse(responseCommand));
        }
        public override CommandHandlerResponse Handle(IFiscalPrinterState fiscalPrinterState)
        {
            var state = fiscalPrinterState as FiscalPrinterState;

            if (state.TimeDiffrenceInMinutes == int.MinValue)
            {
                throw new FiscalPrinterSimulatorLibraries.Exceptions.FP_IllegalOperationException("RTC not initialized.");
            }
            var actualRTCTime        = DateTime.Now.AddMinutes(state.TimeDiffrenceInMinutes);
            var arrayOfRTCParameters = new List <int> {
                actualRTCTime.Year,
                actualRTCTime.Month,
                actualRTCTime.Day,
                actualRTCTime.Hour,
                actualRTCTime.Minute,
                0
            };

            var commandParameters = string.Join(";", arrayOfRTCParameters);
            var outputCommand     = new ThermalFiscalPrinterCommand(new string[] { "1" }, "#C", commandParameters);

            return(new CommandHandlerResponse(outputCommand));
        }
Ejemplo n.º 3
0
        public override CommandHandlerResponse Handle(IFiscalPrinterState fiscalPrinterState)
        {
            var state = fiscalPrinterState as FiscalPrinterState;

            if (command.PnArguments is null || !command.PnArguments.Any())
            {
                throw new FP_WrongNumberOfArgumentsException("Arguments missing");
            }

            if (!int.TryParse(command.PnArguments.First(), out int numberOfRates))
            {
                throw new FP_BadFormatOfArgumentException("First argument is not in numeric format");
            }

            if (numberOfRates > state.PTURates.Count)
            {
                throw new FP_IllegalOperationException("Maximum of PTU Rates is 7.");
            }

            var ptuParameters = command.Parameters.Split('/').Where(m => !string.IsNullOrEmpty(m)).ToArray();

            if (ptuParameters.Length != numberOfRates)
            {
                throw new FP_WrongNumberOfArgumentsException("First argument not contain right number of PTU rates.");
            }



            StringBuilder sb = new StringBuilder();

            sb.AppendLine("N I E F I S K A L N Y".PadCenter(Constants.ReciptWidth));
            sb.AppendLine("Z m i a n a  s t a w e k  P T U".PadCenter(Constants.ReciptWidth));
            sb.AppendLine("Stare PTU:".PadRight(Constants.ReciptWidth));
            state.PTURates.ForEach(key =>
            {
                sb.AppendLine(PrintPTUValuesOnRecipt(key.Type, state));
            });
            sb.AppendLine("-".PadRight(Constants.ReciptWidth, '-'));

            ChangePTURatesByCommand(state, ptuParameters);

            sb.AppendLine("Nowe PTU:".PadRight(Constants.ReciptWidth));
            state.PTURates.ForEach(key =>
            {
                sb.AppendLine(PrintPTUValuesOnRecipt(key.Type, state));
            });
            sb.AppendLine("N I E F I S K A L N Y".PadCenter(Constants.ReciptWidth));

            var lastErrorCode        = "0";
            var fiscalState          = state.IsInFiscalState ? "1" : "0";
            var transactionState     = state.IsInTransactionState ? "1" : "0";
            var lastTransactionState = state.LastTransactionSuccess ? "1" : "0";

            var outputCommandArguments = new string[]
            {
                lastErrorCode,
                fiscalState,
                transactionState,
                lastTransactionState,
                "0",
                "1",
                DateTime.Now.Year.ToString().Substring(2, 2),
                DateTime.Now.Month.ToString(),
                DateTime.Now.Day.ToString()
            };

            var outputCommandParametersString =
                string.Join(";", outputCommandArguments) + "/" +
                string.Join("/", state.PTURates.Select(m => m.ActualPercentageValue)) + (state.NextFiscalPrinterReciptId - 1) + "/" +
                string.Join("/", state.PTURates.Select(m => m.TotalValueOfSalesInType)) + "/" + state.ActualDrawerAmmount + "ABC12345678";

            var outputCommand = new ThermalFiscalPrinterCommand(outputCommandArguments, "#X", outputCommandParametersString);


            return(new CommandHandlerResponse(outputCommand, sb.ToString()));
        }