M110 Verkoop van artikelen

Project Setup

We are building on the knowledge we got from the Getting Started tutorial.

Create a project and register the Checkbox(es) in code.
 

Bash
        
mkdir Mt110_SignSale
cd Mt110_SignSale
dotnet new sln -n Mt110_SignSale
mkdir src
cd src
dotnet new console -n Mt110_SignSale
cd ..
dotnet sln add ./src/Mt110_SignSale

        
    

Voeg de nodige nuget packages toe aan het project. en voeg ook volgend test package toe. Dit is enkel en alleen nodig als voorbeeld om deze usecases te kunnen aanmaken. In een finaal project is dit package dus niet nodig!

Checkbox.Fdm.UseCases

Bash
        
cd src/Mt110_SignSale
dotnet add package Checkbox.Fdm.Sdk
dotnet add package Checkbox.Fdm.UseCases
dotnet add package Microsoft.Extensions.Hosting
        
    

Basis structuur Pos

Laten we voor onze console applicatie een basis structuur opzetten om deze dan verder uit te werken voor alle voorbeelden.

In eerste instantie maken we een nieuwe class aan FpsExample.cs in de root van het project.

Het project heeft nu twee c# files (Program.cs en FpsExample.cs)

FpsExample.cs starting point

C#
        
using Checkbox.Fdm.Core.PosModels;
using Checkbox.Fdm.Sdk;
using Checkbox.Fdm.UseCases;

namespace Mt110_SignSale;

//Inject the Service into this example
internal class FpsExample(ICheckboxService checkboxService)
{
    //Use the example pos from the example nuget package
    private readonly PosSystem _myFpsPos = FpsFinancesModels.Pos567;

    //Initialize the pos
    public async Task Init(CancellationToken cancellationToken = default)
    {

    }

    //Run the pos
    public async Task Run(CancellationToken cancellationToken = default)
    {
        
    }
}

        
    

Program.cs starting point

C#
        
using Checkbox.Fdm.Sdk;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Mt110_SignSale;

Console.WriteLine("Fps Finances Pos Examples");

try
{
    var host = CreateHostBuilder(args).Build();

    //Inject the Checkbox Service
    var myFpsExample = host.Services.GetRequiredService<FpsExample>();
    await myFpsExample.Init();
    await myFpsExample.Run();
}
catch(Exception ex)
{
    Console.WriteLine(ex.ToString());
}

return;


static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureServices(services =>
        {
            services.AddCheckbox("YOUR CHECKBOX API KEY");
            services.AddSingleton<FpsExample>();
        });

        
    

Initialiseer je Checkboxes

In het init gedeelte van de voorbeeld FpsPos moet je eerst de instellingen ophalen van de Checkboxes die je wenst te gebruiken. Het voorbeeld gebruikt 2 Checkboxes. (Aangezien deze fictieve Id's zijn) zullen deze worden vervangen door effectieve Checkbox Id's. Neem 2 checkbox units en connecteer ze zodanig dat er internet beschikbaar is op de units. verder hoef je niets te doen, behalve deze checkboxen te koppelen aan het voorbeeld programma. 

Belangrijk: Om dit voorbeeld volledig te kunnen uitvoeren heb je effectief 2 Checkboxes nodig!

Plaats volgende code in het Init gedeelte

C#
        
        //This is an optional step
        //In the example there are 2 checkboxes connected, you can change this to your own checkbox Id's
        _myFpsPos.CheckboxUnits[0].CheckboxId = "ACTUAL CHECKBOX ID";
        _myFpsPos.CheckboxUnits[1].CheckboxId = "ACTUAL CHECKBOX ID";

        // Try to Initializes the Checkbox devices,
        // This configures their destination network addresses automatically
        await checkboxService.InitializeCheckboxesAsync(
            _myFpsPos.CheckboxIdentifiers,
            CheckboxLoadbalancingMode.Manual,
            cancellationToken);
        
    

M110 Verkoop voorbeeld

In de Run() functie van het voorbeeld kunnen we nu onze effectieve code plaatsen die de acties zal uitvoeren. We gaan van start met de eerste Usecase

In de Dining Room gaan we een directe verkoop registeren van volgende producten

  • 2 Dry Martini (unit price 12 Eur, Vat code A)
  • 1 Burger of the Chef (unit price 28 Eur, Vat code B)

Er wordt met Cash betaald, het totaal bedraagt 52 Eur

C#
        
        //Create the correct action according to the example
        var newSalesAction = new PosSalesAction(
            FpsFinancesModels.Company,
            _myFpsPos,
            FpsFinancesModels.TerminalTer2Din,
            FpsFinancesModels.EmployeeElisa)
        {
            TicketMedium = TicketMedium.PAPER,
            SalesActionNumber = 1000,
            BookingDate = DateTime.Now,
            BookingPeriodId = Guid.Parse("dffcd829-a0e5-41ca-a0ae-9eb887f95637"),
            TransactionLines =
            [
                new SaleLine(TransactionLineType.SINGLE_PRODUCT, 2, FpsFinancesModels.ProdDryMartini),
                new SaleLine(TransactionLineType.SINGLE_PRODUCT, 1, FpsFinancesModels.ProdBurgerOfTheChef)
            ],
            Payments = [
                new Payment
                {
                    Id = "1",
                    Name = "CONTANT",
                    Type = PaymentType.CASH,
                    InputMethod = InputMethod.MANUAL,
                    Amount = 52,
                    AmountType = PaymentLineType.PAYMENT
                }
            ]
        };

        //Sign the action
        var result = await checkboxService.SignPosAction(newSalesAction, false, null, cancellationToken);

        //Handle the result accordingly
        Console.WriteLine($"Result with Signature {result.SignResult?.DigitalSignature}");