fattureincloud / fattureincloud-java-sdk

Fatture in Cloud SDK (Software Development Kit) for Java
MIT License
6 stars 0 forks source link

Email and Phone are NULL in CreateIssuedDocumentResponse #72

Closed juice77 closed 1 year ago

juice77 commented 1 year ago

Describe the bug When creating a new invoice, on the Entity inside the IssuedDocument email and phone are setted, but they are lost after createIssuedDocument method in IssuedDocumentsApi is invoked.

Env info openjdk version "15.0.6" 2022-01-18 OpenJDK Runtime Environment Zulu15.38+17-CA (build 15.0.6+5-MTS) OpenJDK 64-Bit Server VM Zulu15.38+17-CA (build 15.0.6+5-MTS, mixed mode)

To Reproduce


public void newFICinvoice() throws IOException {
    Order order = orderRepository.findOne(780L);
    User user = userRepository.findOne(603);
        List<LeadProducts> leadProducts = leadProductsRepository.findByIdLead( order.getIdLead() );
    String country = "IT";
        refreshFICToken();
        String token = getFICToken();

        ApiClient defaultClient = Configuration.getDefaultApiClient();
        defaultClient.setBasePath("https://api-v2.fattureincloud.it");

        // Configure OAuth2 access token for authorization: OAuth2AuthenticationCodeFlow
        OAuth OAuth2AuthenticationCodeFlow = (OAuth) defaultClient.getAuthentication("OAuth2AuthenticationCodeFlow");
        OAuth2AuthenticationCodeFlow.setAccessToken(token);

        IssuedDocumentsApi apiInstance = new IssuedDocumentsApi(defaultClient);
        //set your company id
        Integer companyId = 7XXXX5;

    String name = user.getName()!=null?user.getName():"";
        if (user.getLastName() != null) {
            name += " " + user.getLastName();
        }
        Entity entity = new Entity()
            .name(name)
        .firstName(user.getName())
        .lastName(user.getLastName())
            .vatNumber(user.getVatNumber())
            .taxCode(user.getCodiceFiscale())
            .addressStreet(user.getAddress())
            .addressPostalCode(user.getZipCode())
            .addressCity(user.getCity())
            .countryIso(user.getCountry())
        .email(user.getEmail())
        .phone(user.getPhone());

        System.out.println("ENTITY:"+ entity.toString());

        IssuedDocument invoice = new IssuedDocument()
            .type(IssuedDocumentType.RECEIPT)
            .entity(entity)
            // Below you can find this section fields:
            .date(LocalDate.now())
            .useGrossPrices(true)
            //.subject("internal subject")
            //.visibleSubject("visible subject")
            // Retrieve the currencies: https://github.com/fattureincloud/fattureincloud-java-sdk/blob/master/docs/InfoApi.md#listCurrencies
            .currency(new Currency().id("EUR"))
            // Retrieve the languages: https://github.com/fattureincloud/fattureincloud-csharp-sdk/blob/master/docs/InfoApi.md#listLanguages
            .language(new Language()
                .code("it")
                .name("italiano"))
            // Here we set e_invoice and ei_data
            //.eInvoice(true)
            //.eiData(
            //    new IssuedDocumentEiData()
            //        .paymentMethod("MP05"))
            ;
        Integer codiceIva = 0;
        for (LeadProducts lp : leadProducts) {
            Product product = productService.findOne(lp.getIdProduct());
            Double iva = product.getIva();
            if (iva == 22) {
                codiceIva = 0;
            } else if (iva == 21) {
                codiceIva = 1;
            } else if (iva == 20) {
                codiceIva = 2;
            } else if (iva == 10) {
                codiceIva = 3;
            } else if (iva == 4) {
                codiceIva = 4;
            } else {
                codiceIva = 6;
            }
            if (country.equalsIgnoreCase("IT") || country.equalsIgnoreCase("SM") || country.equalsIgnoreCase("VA")) {
                // non faccio niente, codiceIva va bene così com'è
            } else if (country.equalsIgnoreCase("EU")) {
                if (order.getTotalIVA() == null || order.getTotalIVA() == 0) {
                    // Art. 41
                    codiceIva = 49;
                } else {
                    // non faccio niente, codiceIva va bene così com'è
                }
            } else {
                // Art. 8
                codiceIva = 51;
            }
            // se c'è la spedizione non facciamo pagare il prodotto
            BigDecimal grossPrice;
            if (order.getShippingCosts() == 0.0) {
                BigDecimal priceProduct = BigDecimal.valueOf(order.getDropshipperTotal());
                grossPrice = priceProduct.divide(BigDecimal.valueOf(lp.getQuantity()));
            } else {
                grossPrice = BigDecimal.valueOf(0);
            }
            invoice.addItemsListItem(
                new IssuedDocumentItemsListItem()
                        .productId(product.getFattureInCloudId().intValue())
                        .code(product.getCode())
                        .name(product.getName())
                        //.netPrice(BigDecimal.valueOf(100))
                        .grossPrice(grossPrice)
                        //.category("cucina")
                        //.discount(BigDecimal.valueOf(0))
                        .qty(BigDecimal.valueOf(lp.getQuantity()))
                        .vat(new VatType().id(codiceIva)) );
        }
        Integer shipID;
        String shipName;
        switch(user.getCountry()) {
            case "IT": case "SM": case "VA":
                //requestString = requestString.replaceAll("###LANGUAGE###", "it");
                shipID = 21308379;
                shipName = "Spedizione";
                break;
            case "DE":
                //requestString = requestString.replaceAll("###LANGUAGE###", "de");
                shipID = 21351026;
                shipName = "Versand";
                break;
            default:
                //requestString = requestString.replaceAll("###LANGUAGE###", "en");
                shipID = 21351022;
                shipName = "Shipping";
        }
        BigDecimal shipGrossPrice = BigDecimal.valueOf(0);
        if (order.getShippingCosts() != null) {
            shipGrossPrice = BigDecimal.valueOf(order.getShippingCosts());
        }
        invoice.addItemsListItem(
            new IssuedDocumentItemsListItem()
                    .productId(shipID)
                    .code("SPE-01")
                    .name(shipName)
                    .grossPrice(shipGrossPrice)
                    .qty(BigDecimal.valueOf(1))
                    .vat(new VatType().id(codiceIva)) );
        invoice.addPaymentsListItem(
            new IssuedDocumentPaymentsListItem()
                    .amount(BigDecimal.valueOf(order.getDropshipperTotal()))
                    .dueDate(LocalDate.now())
                    .paidDate(LocalDate.now())
                    .status(IssuedDocumentStatus.PAID)
                    .paymentAccount(new PaymentAccount().id(653312)) );
        invoice.paymentMethod(new it.fattureincloud.sdk.model.PaymentMethod().id(1692980));
        // Here we put our invoice in the request object
        CreateIssuedDocumentRequest createIssuedDocumentRequest = new CreateIssuedDocumentRequest()
                .data(invoice);
        // Now we are all set for the final call
        // Create the invoice: https://github.com/fattureincloud/fattureincloud-java-sdk/blob/master/docs/IssuedDocumentsApi.md#createissueddocument
        try {
            CreateIssuedDocumentResponse result = apiInstance.createIssuedDocument(companyId, createIssuedDocumentRequest);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling IssuedDocumentsApi#createIssuedDocument");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
valmoz commented 1 year ago

Hi @juice77 this is not a Java SDK issue, so it should not be added here. Also, this is an intended behavior, as explained in our FAQs.

You can also check the existing discussions talking about the same topic:

Feel free to open a Discussion on our Community or to contact our Customer Support if you have further questions.

Thanks Mauro