Skip to main content

Overview

The Orders Service (jea-pedidos) manages customer orders with fulfillment tracking, delivery scheduling, and order status management. It serves as a pre-sales process before converting orders to actual sales. Database: MySQL (pedido-ms) Port: Dynamic (configured via Eureka)

Core Entities

Pedido

Customer order header. Location: jea-pedidos/src/main/java/com/example/jeapedidos/entity/Pedido.java:13 Fields:
  • id (Integer) - Primary key
  • codigo (String) - Unique order code
  • serie (String) - Unique order series
  • descripcion (String) - Order description
  • estado (String) - Order status (default: “PENDIENTE”)
  • clienteId (Long) - Customer ID reference
  • cliente (Cliente) - Customer data (transient, from Cliente service)
  • detalle (List<PedidoDetalle>) - Order line items
  • fechaPedido (LocalDateTime) - Order creation timestamp (auto-set)
  • fechaEntrega (LocalDate) - Delivery date (auto-set to 1 week after order)
  • baseImponible (Double) - Taxable base amount
  • igv (Double) - Tax amount (IGV)
  • total (Double) - Total amount
  • formapagoId (Long) - Payment method ID reference
  • formaPago (FormaPago) - Payment method data (transient)
Table: pedido Default Values:
  • fechaPedido: Current timestamp
  • fechaEntrega: Order date + 1 week
  • estado: “PENDIENTE”
Relationships:
  • One-to-many with PedidoDetalle via pedido_id
  • References Cliente (external service)
  • References FormaPago (external service)

PedidoDetalle

Order line item. Location: jea-pedidos/src/main/java/com/example/jeapedidos/entity/PedidoDetalle.java Fields:
  • id (Long) - Primary key
  • cantidad (Integer) - Quantity ordered
  • precioUnitario (Double) - Unit price
  • baseImponible (Double) - Line taxable base
  • igv (Double) - Line tax amount (18%)
  • total (Double) - Line total
  • productoId (Long) - Product ID reference
  • producto (Producto) - Product data (transient)
Table: pedido_detalle Relationships:
  • Many-to-one with Pedido via pedido_id
  • References Producto (from Catalog service)

Key Components

Controllers

PedidoController

Location: jea-pedidos/src/main/java/com/example/jeapedidos/controller/PedidoController.java:13 Endpoints:
  • POST /pedido - Create new order
  • GET /pedido - List all orders
  • GET /pedido/{id} - Get order by ID
  • PUT /pedido/{id} - Update order
  • DELETE /pedido/{id} - Delete order

Services

PedidoService

Location: jea-pedidos/src/main/java/com/example/jeapedidos/service/PedidoService.java Implementation: PedidoServiceImpl.java Key Methods:
  • createPedido() - Create order with validation
  • getAllPedidos() - List all orders with customer/payment data
  • getPedidoById() - Get order with full details
  • updatePedido() - Update order details
  • deletePedido() - Delete order

Repositories

PedidoRepository

Location: jea-pedidos/src/main/java/com/example/jeapedidos/repository/PedidoRepository.java Extends JpaRepository<Pedido, Integer> Provides data access for order management.

Feign Clients

ProductoFeign

Location: jea-pedidos/src/main/java/com/example/jeapedidos/feing/ProductoFeign.java Integrates with Catalog service for product data.

ClienteFeign

Location: jea-pedidos/src/main/java/com/example/jeapedidos/feing/ClienteFeign.java Integrates with Customer service for customer data.

FormaPagoFeign

Location: jea-pedidos/src/main/java/com/example/jeapedidos/feing/FormaPagoFeign.java Integrates with Payment service for payment method data.

CategoriaFeign

Location: jea-pedidos/src/main/java/com/example/jeapedidos/feing/CategoriaFeign.java Integrates with Catalog service for category data.

Configuration

OpenAPIConfig

Location: jea-pedidos/src/main/java/com/example/jeapedidos/config/OpenAPIConfig.java Swagger/OpenAPI documentation configuration.

DTOs

Transient DTOs (from other services)

  • Producto - Product data from Catalog service
  • Cliente - Customer data from Customer service
  • FormaPago - Payment method from Payment service
  • Categoria - Category data from Catalog service

Dependencies

Spring Boot Version: 3.1.3 Spring Cloud Version: 2022.0.2 Key Dependencies:
  • spring-boot-starter-data-jpa - JPA/Hibernate
  • spring-boot-starter-web - REST API
  • spring-boot-starter-validation - Bean validation
  • spring-cloud-starter-netflix-eureka-client:4.0.3 - Service discovery
  • spring-cloud-starter-config:4.0.4 - Centralized configuration
  • spring-cloud-starter-openfeign - Feign client for microservice communication
  • spring-cloud-starter-circuitbreaker-resilience4j - Circuit breaker pattern
  • springdoc-openapi-starter-webmvc-ui:2.0.2 - OpenAPI/Swagger UI
  • mysql-connector-j - MySQL driver
  • lombok - Code generation

Configuration

Config File: config-data/jea-pedido-service.yml Key Settings:
server:
  port: ${PORT:${SERVER_PORT:0}}

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/pedido-ms
    username: root
    password: ""
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8090/eureka

Database Schema

Main Tables:
  • pedido - Order header
    • Primary key: id
    • Unique constraints: codigo, serie
    • Foreign keys: cliente_id, formapago_id (references external services)
  • pedido_detalle - Order line items
    • Primary key: id
    • Foreign keys: pedido_idpedido.id, producto_id (external)

Business Logic

Order Status Management

Orders track their lifecycle through the estado field:
  • PENDIENTE - Default state for new orders
  • Can be updated to other statuses (e.g., EN_PROCESO, ENTREGADO, CANCELADO)

Delivery Date Calculation

When an order is created:
  • fechaPedido: Set to current timestamp
  • fechaEntrega: Automatically set to 1 week after order date
  • Both dates can be manually updated

Tax Calculation

Same as Sales and Purchase services:
  • Base Imponible: Sum of line item bases
  • IGV (Tax): 18% of base imponible
  • Total: Base imponible + IGV

Order vs Sale Distinction

  • Orders (Pedidos): Pre-sales commitments, can be modified/cancelled
  • Sales (Ventas): Completed transactions with invoice numbers
  • Orders may be converted to sales after fulfillment

Key Features

  • Customer order management with CRUD operations
  • Order status tracking (PENDIENTE, etc.)
  • Automatic delivery date calculation (1 week default)
  • Multi-line item support
  • Integration with Customer, Product, and Payment services
  • Tax calculation (IGV at 18%)
  • Unique order codes and series
  • Circuit breaker for fault tolerance
  • OpenAPI/Swagger documentation
  • Eureka service discovery integration

Integration Points

Consumes:

  • Catalog Service (ProductoFeign, CategoriaFeign) - Product data and availability
  • Customer Service (ClienteFeign) - Customer information
  • Payment Service (FormaPagoFeign) - Payment method details

APIs Exposed:

  • Order CRUD operations
  • Order listing and retrieval
  • Order status updates

Order Lifecycle

  1. Order Creation - Customer places order with PENDIENTE status
  2. Order Processing - Status updated as order is prepared
  3. Order Fulfillment - Delivery scheduled (fechaEntrega)
  4. Conversion to Sale - Order may be converted to Venta (Sale) upon completion
  5. Inventory Impact - No immediate inventory changes (reserved on conversion)

Differences from Sales Service

FeatureOrders (Pedidos)Sales (Ventas)
PurposePre-sales, quotationsCompleted transactions
Document TypeOrder code/serieInvoice serie/numero
StatusTracked (PENDIENTE, etc.)Not tracked
Delivery DateScheduled (fechaEntrega)Not applicable
InventoryNo immediate impactReduces inventory
ModificationCan be updated/cancelledGenerally immutable

Build docs developers (and LLMs) love