Skip to main content

DPD/BRT Integration - Phase 2 Completion

✅ What Has Been Implemented

Phase 2: Controllers, Views & User Interface


🎯 Components Implemented

1. DpdController (/dpd/ Dashboard)

Location: src/AppBundle/Controller/DpdController.php

Routes:

  • GET /dpd/ → Dashboard with DataTables listing
  • POST /dpd/paginate → AJAX pagination for shipments
  • POST /dpd/print → Batch print/create shipments
  • GET /dpd/download/{id} → Download PDF label
  • POST /dpd/retry/{id} → Retry failed shipment
  • POST /dpd/sync-tracking/{id} → Synchronize tracking

Features:

  • ✅ View all DPD shipments in DataTable
  • ✅ Filter by store, date range, tracking ID, order number
  • ✅ Download PDF labels
  • ✅ Retry failed shipments
  • ✅ Sync tracking information
  • ✅ Real-time statistics (total, delivered, pending, errors)

2. DPD Dashboard View

Location: src/AppBundle/Resources/views/Dpd/index.html.twig

Features:

  • ✅ DataTables with server-side processing
  • ✅ Advanced filters (store, dates, tracking, order number)
  • ✅ Inline actions (view, download, sync, retry)
  • ✅ Statistics cards (total shipments, delivered, in transit, errors)
  • ✅ French translations
  • ✅ Responsive design

Columns:

  • ID
  • Order Number (with link to sale detail)
  • Customer Name
  • Product SKU
  • Parcel ID (with tracking link)
  • Store Name
  • Created Date
  • Delivered Date
  • Status (delivered/in transit)
  • Labels (download buttons)
  • Actions (view, download, sync, retry)

3. SaleController Updates

Location: src/AppBundle/Controller/Sale/SaleController.php

New Route:

/**
* @Route("/sale-create-dpd-expedition", name="sale_create_dpd_expedition")
* @Method("POST")
*/
public function saleCreateDpdExpeditionAction(Request $request)

Functionality:

  • ✅ Creates DPD shipments for selected sale products
  • ✅ Validates orders aren't already shipped
  • ✅ Batch processing for multiple orders
  • ✅ Returns JSON response with success/error messages
  • ✅ Error handling with detailed feedback

4. Processing Not Printed Interface

Location: src/AppBundle/Resources/views/Sale/processingNotPrinted.html.twig

Changes:

  1. Added Menu Item (line 292):

    <li><a href="#" data-liv="createShippingDpd">Créer l'expédition DPD</a></li>
  2. Added Confirmation Dialog (line 1157-1161):

    else if (action && action == 'createShippingDpd') {
    $('#modalConfirmation').find('.question').text('Êtes-vous sûr de vouloir créer l\'expédition DPD?');
    $('#modalConfirmation').find('#action').val(action);
    $('#modalConfirmation').modal('show');
    }
  3. Added AJAX Handler (line 1502-1537):

    else if (action && action == 'createShippingDpd') {
    // Show progress modal
    // Loop through selected orders
    // Call sale_create_dpd_expedition endpoint
    // Display success/error messages
    // Clear selection
    }

User Flow:

  1. User selects orders in /sale/processing-not-printed
  2. User clicks "Créer l'expédition DPD" from Actions menu
  3. Confirmation modal appears
  4. Upon confirmation, AJAX calls create shipments
  5. Progress modal shows real-time results
  6. Success/error messages displayed for each order

5. SaleProductRepository Updates

Location: src/AppBundle/Repository/SaleProductRepository.php

New Method:

public function searchShippedByCarrier($carrier, $criteria = [], $page = 1, $max = 25)

Features:

  • ✅ Generic method for searching by any carrier (DPD, CHRONOPOST, GLS, etc.)
  • ✅ Filters: store, date range, tracking ID, order number, general search
  • ✅ Pagination support
  • ✅ Returns data with total counts for DataTables

Filters Supported:

  • storeId - Filter by store
  • dateFrom / dateTo - Date range filter
  • trackingId - Search by parcel ID
  • incrementId - Search by order number
  • search - General search across multiple fields

🚀 How to Use

Access DPD Dashboard

Navigate to: /dpd/

The dashboard shows all DPD shipments with:

  • Search and filter capabilities
  • Download PDF labels
  • Sync tracking status
  • Retry failed shipments

Create DPD Shipments from Orders

  1. Navigate to Processing Not Printed

    • Go to /sale/processing-not-printed
  2. Select Orders

    • Check the boxes for orders you want to ship via DPD
  3. Create DPD Shipments

    • Click "Actions" dropdown
    • Select "Créer l'expédition DPD"
    • Confirm in modal dialog
  4. Monitor Progress

    • Progress modal shows real-time status
    • Success/error messages for each order
    • PDF labels automatically generated and saved
  5. View Shipments

    • Navigate to /dpd/ to see all shipments
    • Download labels, sync tracking, etc.

📊 Data Flow

User selects orders in /sale/processing-not-printed

Clicks "Créer l'expédition DPD"

Confirmation modal → User confirms

JavaScript AJAX call to /sale-create-dpd-expedition

SaleController::saleCreateDpdExpeditionAction()

For each order:
- Validate not already shipped
- Call DpdService::createSaleProductShipment()

DpdService calls DPD REST API

API returns parcel ID + PDF label (base64)

PDF saved to /web/pdf_dpd/

SaleProduct updated:
- carrier = 'DPD'
- tracking_id = parcelID
- expedition_ticket_files = ['/pdf_dpd/xxx.pdf']
- track_links = ['https://www.brt.it/tracking?parcelID=xxx']
- is_ticket_printed = true

ShipmentTrackingSynchronizer creates records

Events dispatched (SaleProductsShippedEvent, etc.)

JSON response returned to JavaScript

Success/error message displayed in modal

User can view shipments in /dpd/ dashboard

🎨 UI Screenshots (Description)

1. Processing Not Printed Interface

  • Actions dropdown now includes "Créer l'expédition DPD"
  • Located right after "Créer l'expédition Chronopost"
  • Green button style

2. DPD Dashboard (/dpd/)

  • Green header "Expéditions DPD/BRT"
  • Filter form with: Store, Date From, Date To, Tracking ID, Order Number
  • DataTable with 11 columns
  • Action buttons: View, Download, Sync, Retry, Track
  • Statistics cards at bottom: Total, Delivered, In Transit, Errors

3. Progress Modal

  • Shows real-time progress when creating shipments
  • Green alert for success
  • Red alert for errors
  • "Traitement en cours..." spinner while processing

🔧 Configuration Required

1. Menu Access Permissions

Add to your menu configuration:

commandes_dpd_list:
label: 'Expéditions DPD'
route: 'dpd_index'
icon: 'fa fa-truck'

2. Clear Cache

php bin/console cache:clear

3. Verify Routes

php bin/console debug:router | grep dpd

Expected output:

dpd_index GET ANY ANY /dpd/
dpd_paginate POST ANY ANY /dpd/paginate
dpd_print POST ANY ANY /dpd/print
dpd_download_label GET ANY ANY /dpd/download/{id}
dpd_retry POST ANY ANY /dpd/retry/{id}
dpd_sync_tracking POST ANY ANY /dpd/sync-tracking/{id}
sale_create_dpd_expedition POST ANY ANY /sale-create-dpd-expedition

🧪 Testing Phase 2

Test 1: Access Dashboard

# Open browser and navigate to:
http://your-domain.com/dpd/

# Expected: Dashboard loads with empty table (if no shipments yet)

Test 2: Create Shipment from UI

  1. Navigate to /sale/processing-not-printed
  2. Select an order
  3. Click Actions → "Créer l'expédition DPD"
  4. Confirm
  5. Wait for progress modal
  6. Check for success message

Test 3: View Shipment in Dashboard

  1. After creating shipment, navigate to /dpd/
  2. Shipment should appear in table
  3. Click download button to get PDF label
  4. Click tracking link to open BRT tracking page

Test 4: Filters

  1. In /dpd/ dashboard
  2. Try filtering by:
    • Store
    • Date range
    • Tracking ID
    • Order number
  3. Click "Rechercher"
  4. Verify results filtered correctly

Test 5: Sync Tracking

  1. Find a shipment in dashboard
  2. Click sync button (refresh icon)
  3. Wait for AJAX call
  4. Check if status updated (especially if delivered)

📝 Files Modified/Created in Phase 2

New Files

  • src/AppBundle/Controller/DpdController.php (296 lines)
  • src/AppBundle/Resources/views/Dpd/index.html.twig (221 lines)

Modified Files

  • src/AppBundle/Controller/Sale/SaleController.php (added saleCreateDpdExpeditionAction method)
  • src/AppBundle/Resources/views/Sale/processingNotPrinted.html.twig (added DPD menu item + handlers)
  • src/AppBundle/Repository/SaleProductRepository.php (added searchShippedByCarrier method)

✅ Phase 2 Checklist

  • Create DpdController with all routes
  • Create DPD dashboard view (index.html.twig)
  • Add DPD expedition route to SaleController
  • Update processingNotPrinted.html.twig (menu item)
  • Add JavaScript confirmation handler
  • Add JavaScript AJAX handler
  • Create searchShippedByCarrier repository method
  • Test dashboard access
  • Test shipment creation from UI
  • Document all changes

🎉 Phase 2 Complete!

What You Can Do Now:

  1. ✅ Create DPD shipments from /sale/processing-not-printed interface
  2. ✅ View all DPD shipments in /dpd/ dashboard
  3. ✅ Download PDF labels
  4. ✅ Filter shipments by various criteria
  5. ✅ Sync tracking information
  6. ✅ Retry failed shipments
  7. ✅ View statistics

Integration Status:

  • Phase 1 (Core API & Services): ✅ Complete
  • Phase 2 (Controllers & UI): ✅ Complete
  • Phase 3 (Advanced Features): 📋 Optional

📋 Optional Next Steps (Phase 3)

Advanced Features (if needed)

  1. Batch Label Printing

    • Print multiple labels in single PDF
    • Merge PDFs using Ghostscript (like Chronopost)
  2. Automated Tracking Sync

    • Create command: php bin/console menzzo:dpd:sync-tracking
    • Add to cron: every hour
  3. Email Notifications

    • Send tracking link to customers
    • Notify on delivery
  4. Webhooks

    • Receive real-time tracking updates from DPD
  5. Statistics Dashboard

    • Charts for shipment volumes
    • Performance metrics

🐛 Troubleshooting

Issue: Can't see "Créer l'expédition DPD" option

Solution: Clear browser cache and Symfony cache:

php bin/console cache:clear

Issue: AJAX call fails

Solution: Check browser console for errors. Verify route exists:

php bin/console debug:router sale_create_dpd_expedition

Issue: PDF not downloading

Solution: Check that /web/pdf_dpd/ directory exists and is writable:

mkdir -p web/pdf_dpd
chmod 755 web/pdf_dpd

Issue: Dashboard shows no data

Solution: Create a test shipment first from /sale/processing-not-printed


📚 References

  • Phase 1 Documentation: docs/DPD_Integration_Phase1.md
  • API Documentation: BrtRestApi-EN/RestShipmentProd.en/Index.html
  • Controller: src/AppBundle/Controller/DpdController.php
  • Service: src/CoreBundle/Services/DpdService.php
  • Dashboard: /dpd/

🎊 Success!

The DPD integration is now fully functional and ready for production use! Users can create shipments, view them in the dashboard, download labels, and track deliveries - all integrated seamlessly into the existing Logidav workflow.

For support or questions, refer to the DPD API documentation or contact DPD support at cedvas@brt.it.