1 package com.srv4pos.server.api.sale;
2
3 import com.srv4pos.server.api.ServiceFactory;
4 import com.srv4pos.server.api.activation.ActivationServiceSample;
5 import com.srv4pos.server.api.day.DayInfo;
6 import com.srv4pos.server.api.day.DayService;
7 import com.srv4pos.server.api.infrastructure.credentials.Credentials;
8 import com.srv4pos.server.api.infrastructure.http.Transport;
9 import com.srv4pos.server.api.posplus.PrintType;
10 import com.srv4pos.server.api.seller.SellerService;
11
12 import java.net.URL;
13 import java.util.Collections;
14 import java.util.Date;
15
16
17
18
19 public class SaleServiceSample {
20 private final SaleService saleService;
21 private final SellerService sellerService;
22 private final Credentials credentials;
23 private final DayService dayService;
24
25 public SaleServiceSample(URL url, Credentials credentials, Transport transport) {
26 ServiceFactory serviceFactory = new ServiceFactory(url, credentials, transport);
27 saleService = serviceFactory.getSaleService();
28 dayService = serviceFactory.getDayService();
29 sellerService = serviceFactory.getSellerService();
30 this.credentials = credentials;
31 }
32
33 public void test() {
34 int version = sellerService.getThisVersion().getVersion();
35
36 DayInfo dayInfo = new DayInfo();
37
38 dayInfo.setCashAtClose(100);
39 dayInfo.setCash(110);
40 dayInfo.setCashRegisterName("Cash22");
41 dayInfo.setClose(null);
42 dayInfo.setModified(new Date(1000000000001L));
43 dayInfo.setGrandTotal(120);
44 dayInfo.setOpen(new Date(1000000000002L));
45 dayInfo.setOpened(true);
46 dayInfo.setReportPrinted(false);
47 dayInfo.setDayNumber(10);
48 dayInfo.setGrandTotalRefund(130);
49
50 String dayIdentifier = dayService.create(version, dayInfo).getIdentifier();
51
52 dayInfo.setIdentifier(dayIdentifier);
53 dayInfo.setCash(200);
54
55 dayService.put(version, dayInfo);
56
57 SaleInfo saleInfo = new SaleInfo();
58 saleInfo.setAbsoluteDiscount(0);
59 saleInfo.setRelativeDiscount(1000);
60 saleInfo.setDay(dayIdentifier);
61 saleInfo.setDiscount(3700);
62 saleInfo.setClose(new Date());
63 saleInfo.setRefund(true);
64 saleInfo.setVat(6660);
65 saleInfo.setRefundFor(123);
66 saleInfo.setBrutto(33300);
67 saleInfo.setVanillaBrutto(37000);
68 saleInfo.setControlUnitId(ActivationServiceSample.CONTROL_UNIT_SERIAL_NUMBER);
69 saleInfo.setIdentifier(Integer.toHexString(new Date().toString().hashCode()));
70
71 saleInfo.setSaleState(SaleState.Open);
72
73 SaleProductInfo saleProductInfo = new SaleProductInfo();
74 saleProductInfo.setAbsoluteDiscount(500);
75 saleProductInfo.setRelativeDiscount(0);
76 saleProductInfo.setDiscount(500);
77 saleProductInfo.setDeltaUnit(true);
78 saleProductInfo.setDelta(300);
79 saleProductInfo.setNetto(29600);
80 saleProductInfo.setVat(7400);
81 saleProductInfo.setBrutto(37000);
82 saleProductInfo.setEffectiveBrutto(33300);
83 saleProductInfo.setCreated(new Date());
84 saleProductInfo.setVanillaBrutto(37500);
85 saleProductInfo.setProductBrutto(12500);
86 saleProductInfo.setVatRate(2500);
87 saleProductInfo.setProductIdentifier("PRODUCT1");
88
89 PrintInfo printInfo = new PrintInfo();
90 printInfo.setReceiptNumber(0);
91 printInfo.setPrintType(PrintType.Proforma);
92 printInfo.setControlNumber("123");
93 printInfo.setDeliveryType(DeliveryType.Display);
94 printInfo.setCreated(new Date());
95
96 PaymentInfo paymentInfo = new PaymentInfo();
97 paymentInfo.setPaymentType(PaymentType.EmvStandalone);
98 paymentInfo.setPaymentState(PaymentState.PENDING);
99 paymentInfo.setAmount(10);
100
101 VatRateSumInfo vatRateSumInfo = new VatRateSumInfo();
102 vatRateSumInfo.setBrutto(33300);
103 vatRateSumInfo.setNetto(26640);
104 vatRateSumInfo.setVat(6660);
105 vatRateSumInfo.setVanillaBrutto(37000);
106 vatRateSumInfo.setVanillaNetto(29600);
107 vatRateSumInfo.setVanillaVat(7400);
108 vatRateSumInfo.setVatRate(2500);
109
110 saleInfo.setSaleProducts(Collections.singletonList(saleProductInfo));
111 saleInfo.setPrints(Collections.singletonList(printInfo));
112 saleInfo.setPayments(Collections.singletonList(paymentInfo));
113 saleInfo.setVatRateSums(Collections.singletonList(vatRateSumInfo));
114
115 saleInfo.setSellerIdentifier(credentials.getSellerId());
116
117 saleService.put(version, saleInfo);
118 }
119 }