diff --git a/go/internal/cmc/documents/order_ack_builder.go b/go/internal/cmc/documents/order_ack_builder.go index 62402a7b..a406ad77 100644 --- a/go/internal/cmc/documents/order_ack_builder.go +++ b/go/internal/cmc/documents/order_ack_builder.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "html/template" + "log" "path/filepath" "strconv" ) @@ -23,7 +24,14 @@ type OrderAckLineItemTemplateData struct { // BuildOrderAckHTML generates the complete HTML for an order acknowledgement using templates func (g *HTMLDocumentGenerator) BuildOrderAckHTML(data *OrderAckPDFData, totalPages int, currentPage int) string { - orderAckNumber := data.OrderAcknowledgement.CmcReference + // Log the CmcReference for debugging + log.Printf("=== BuildOrderAckHTML: data.CmcReference='%s', data.OrderAcknowledgement.CmcReference='%s' ===", data.CmcReference, data.OrderAcknowledgement.CmcReference) + + orderAckNumber := data.CmcReference + if orderAckNumber == "" { + // Fallback to document's CMC reference if data.CmcReference is empty + orderAckNumber = data.OrderAcknowledgement.CmcReference + } // Calculate totals subtotal := 0.0 diff --git a/go/internal/cmc/handlers/documents/documents_api.go b/go/internal/cmc/handlers/documents/documents_api.go index 4f0ea352..a0abbba9 100644 --- a/go/internal/cmc/handlers/documents/documents_api.go +++ b/go/internal/cmc/handlers/documents/documents_api.go @@ -534,6 +534,10 @@ func GenerateOrderAckPDF(w http.ResponseWriter, r *http.Request) { http.Error(w, "invalid JSON payload", http.StatusBadRequest) return } + + // Log the request for debugging + log.Printf("=== GenerateOrderAckPDF: Received request with CmcReference='%s' ===", req.CmcReference) + if req.CustomerName == "" { http.Error(w, "customer_name is required", http.StatusBadRequest) return @@ -571,6 +575,8 @@ func GenerateOrderAckPDF(w http.ResponseWriter, r *http.Request) { } } + log.Printf("=== GenerateOrderAckPDF: About to create OrderAckPDFData with CmcReference='%s' ===", req.CmcReference) + data := &pdf.OrderAckPDFData{ OrderAcknowledgement: doc, Customer: cust, @@ -594,6 +600,8 @@ func GenerateOrderAckPDF(w http.ResponseWriter, r *http.Request) { LineItems: lineItems, } + log.Printf("=== GenerateOrderAckPDF: Created OrderAckPDFData with CmcReference='%s' ===", data.CmcReference) + // Use HTML generator gen := pdf.NewHTMLDocumentGenerator(outputDir) filename, err := gen.GenerateOrderAckPDF(data) diff --git a/php/app/views/documents/pdf_orderack.ctp b/php/app/views/documents/pdf_orderack.ctp index 6c6c8f15..a7a1d4cb 100755 --- a/php/app/views/documents/pdf_orderack.ctp +++ b/php/app/views/documents/pdf_orderack.ctp @@ -45,6 +45,21 @@ if (!empty($document['Document']['cmc_reference'])) { $orderAckNumber = $document['OrderAcknowledgement']['title']; } +error_log("=== pdf_orderack.ctp: document['Document']['cmc_reference']='" . (isset($document['Document']['cmc_reference']) ? $document['Document']['cmc_reference'] : 'NOT SET') . "' ==="); +error_log("=== pdf_orderack.ctp: document['Document'] keys: " . implode(', ', array_keys($document['Document'])) . " ==="); + +// Use enquiry title (reference) as cmc_reference if not already set +if (empty($document['Document']['cmc_reference'])) { + if (isset($enquiry['Enquiry']['title']) && !empty($enquiry['Enquiry']['title'])) { + $document['Document']['cmc_reference'] = $enquiry['Enquiry']['title']; + error_log("=== pdf_orderack.ctp: Set cmc_reference to enquiry title: " . $document['Document']['cmc_reference'] . " ==="); + } else { + error_log("=== pdf_orderack.ctp: ERROR - Cannot determine cmc_reference: enquiry title not available ==="); + echo "ERROR: Cannot determine CMC Reference - enquiry information missing."; + exit; + } +} + $orderAckTitle = isset($document['OrderAcknowledgement']['title']) && !empty($document['OrderAcknowledgement']['title']) ? $document['OrderAcknowledgement']['title'] : 'OrderAck-' . $document['Document']['id']; @@ -80,7 +95,7 @@ $payload = array( 'document_id' => intval($document['Document']['id']), 'title' => $orderAckTitle, 'customer_name' => $customerName, - 'cmc_reference' => isset($document['Document']['cmc_reference']) ? $document['Document']['cmc_reference'] : '', + 'cmc_reference' => $document['Document']['cmc_reference'], 'email_to' => $contactEmail, 'attention' => $contactName, 'your_reference' => $yourReference, @@ -106,6 +121,8 @@ $payload = array( 'output_dir' => $outputDir ); +error_log("=== pdf_orderack.ctp: payload['cmc_reference']='" . $payload['cmc_reference'] . "' ==="); + $ch = curl_init($goEndpoint); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); diff --git a/start-development.sh b/start-development.sh index 29910af9..042d0e27 100755 --- a/start-development.sh +++ b/start-development.sh @@ -1,125 +1,69 @@ #!/bin/bash # CMC Sales Development Environment Setup Script +# Simple, straightforward startup without docker compose watch mode set -e -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color - -echo -e "${BLUE}🚀 Starting CMC Sales Development Environment${NC}" -echo "" - -# Function to check if command exists -command_exists() { - command -v "$1" >/dev/null 2>&1 -} +# Parse command line arguments +BUILD_CACHE=true +for arg in "$@"; do + if [[ "$arg" == "--no-cache" ]]; then + BUILD_CACHE=false + fi +done # Check prerequisites -echo -e "${YELLOW}📋 Checking prerequisites...${NC}" - -if ! command_exists docker; then - echo -e "${RED}❌ Docker is not installed${NC}" +if ! command -v docker >/dev/null 2>&1; then + echo "Error: Docker is not installed" exit 1 fi -if ! command_exists docker-compose; then - echo -e "${RED}❌ Docker Compose is not installed${NC}" +if ! command -v docker-compose >/dev/null 2>&1; then + echo "Error: Docker Compose is not installed" exit 1 fi -echo -e "${GREEN}✅ Prerequisites satisfied${NC}" +echo "Starting CMC Sales Development Environment..." echo "" -# Check Docker Compose version for watch support -DOCKER_COMPOSE_VERSION=$(docker compose version --short 2>/dev/null || echo "unknown") -SUPPORTS_WATCH=false - -if [[ "$DOCKER_COMPOSE_VERSION" != "unknown" ]]; then - # Check if version is 2.22.0 or higher (when watch was introduced) - if docker compose version 2>/dev/null | grep -q "Docker Compose version v2\.\([2-9][2-9]\|[3-9][0-9]\)"; then - SUPPORTS_WATCH=true - fi +# Build and start services +BUILD_FLAG="" +if [[ "$BUILD_CACHE" == "false" ]]; then + BUILD_FLAG="--no-cache" + echo "Building with --no-cache (this may take a while)..." +else + echo "Building services..." fi -echo "" -echo -e "${YELLOW}đŸ—ī¸ Building and starting services...${NC}" - -# Ask user about watch mode -if [[ "$SUPPORTS_WATCH" == "true" ]]; then - echo -e "${BLUE}💡 Docker Compose watch mode is available for automatic rebuilds on file changes.${NC}" - read -p "Would you like to enable watch mode? (Y/n): " enable_watch - if [[ ! $enable_watch =~ ^[Nn]$ ]]; then - USE_WATCH=true - else - USE_WATCH=false - fi +if [[ "$BUILD_CACHE" == "false" ]]; then + docker compose build $BUILD_FLAG + docker compose up -d else - echo -e "${YELLOW}âš ī¸ Docker Compose watch mode not available (requires v2.22.0+)${NC}" - USE_WATCH=false -fi - -if [[ "$USE_WATCH" == "true" ]]; then - echo -e "${GREEN}🔄 Starting services with watch mode enabled...${NC}" - echo -e "${BLUE} 📁 Watching for changes in: go/, php/app/webroot/css/, php/app/webroot/js/${NC}" - echo -e "${BLUE} 🔄 Services will automatically rebuild on file changes${NC}" - echo -e "${BLUE} âšī¸ Press Ctrl+C to stop all services${NC}" - echo "" - - # Start with watch mode (this will run in foreground) - docker compose up --build --watch -else - # Traditional mode docker compose up --build -d +fi - echo "" - echo -e "${YELLOW}âŗ Waiting for services to be ready...${NC}" - sleep 10 +echo "" +echo "Waiting for services to be ready..." +sleep 5 - # Check service health - echo -e "${YELLOW}đŸĨ Checking service health...${NC}" +# Check database +if docker compose exec -T db mariadb-admin ping -h localhost -u cmc -p'xVRQI&cA?7AU=hqJ!%au' --silent 2>/dev/null; then + echo "Database is ready" +else + echo "Warning: Database may still be starting..." +fi - # Check database - if docker compose exec -T db mariadb-admin ping -h localhost -u cmc -p'xVRQI&cA?7AU=hqJ!%au' --silent; then - echo -e "${GREEN}✅ Database is ready${NC}" - else - echo -e "${RED}❌ Database is not ready${NC}" - fi - - # Check Go app - if curl -s http://localhost:8080/api/v1/health > /dev/null; then - echo -e "${GREEN}✅ Go application is ready${NC}" - else - echo -e "${YELLOW}âš ī¸ Go application might still be starting...${NC}" - fi - - echo "" - echo -e "${GREEN}🎉 Development environment is running!${NC}" - echo "" - echo -e "${BLUE}📱 Access your applications:${NC}" - echo -e " đŸ›ī¸ CakePHP (Legacy): ${GREEN}http://cmclocal${NC} (add to /etc/hosts: 127.0.0.1 cmclocal)" - echo -e " 🚀 Go (Modern): ${GREEN}http://localhost:8080${NC}" - echo -e " đŸ—„ī¸ Database: ${GREEN}localhost:3306${NC} (user: cmc, pass: xVRQI&cA?7AU=hqJ!%au)" - echo "" - echo -e "${BLUE}🔧 Useful commands:${NC}" - echo -e " View logs: ${YELLOW}docker compose logs -f${NC}" - echo -e " Stop services: ${YELLOW}docker compose down${NC}" - echo -e " Restart Go app: ${YELLOW}docker compose restart cmc-go${NC}" - echo -e " Restart PHP app: ${YELLOW}docker compose restart cmc-php${NC}" - echo -e " Enable watch mode: ${YELLOW}docker compose up --watch${NC}" - echo "" - echo -e "${BLUE}📚 Documentation:${NC}" - echo -e " Go app README: ${YELLOW}go/README.md${NC}" - echo -e " Project guide: ${YELLOW}CLAUDE.md${NC}" - echo "" - - # Optional: Follow logs - read -p "Would you like to follow the logs? (y/N): " follow_logs - if [[ $follow_logs =~ ^[Yy]$ ]]; then - echo -e "${YELLOW}📝 Following logs (Ctrl+C to exit)...${NC}" - docker compose logs -f - fi -fi \ No newline at end of file +echo "" +echo "Development environment is running." +echo "" +echo "Available services:" +echo " CakePHP (Legacy): http://cmclocal (add to /etc/hosts: 127.0.0.1 cmclocal)" +echo " Go (Modern): http://localhost:8080" +echo " Database: localhost:3306 (user: cmc)" +echo "" +echo "Useful commands:" +echo " View logs: docker compose logs -f" +echo " Stop services: docker compose down" +echo " Restart Go app: docker compose restart cmc-go" +echo " Restart PHP app: docker compose restart cmc-php" +echo "" \ No newline at end of file