Redoing start development to make it simpler, fixing OA not having CMC reference

This commit is contained in:
Finley Ghosh 2026-01-28 21:11:34 +11:00
parent ab17a17f25
commit ca83ea078d
4 changed files with 82 additions and 105 deletions

View file

@ -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

View file

@ -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)

View file

@ -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);

View file

@ -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
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
# 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
USE_WATCH=false
fi
else
echo -e "${YELLOW}⚠️ Docker Compose watch mode not available (requires v2.22.0+)${NC}"
USE_WATCH=false
echo "Building services..."
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
if [[ "$BUILD_CACHE" == "false" ]]; then
docker compose build $BUILD_FLAG
docker compose up -d
else
# Traditional mode
docker compose up --build -d
fi
echo ""
echo -e "${YELLOW}⏳ Waiting for services to be ready...${NC}"
sleep 10
# Check service health
echo -e "${YELLOW}🏥 Checking service health...${NC}"
echo "Waiting for services to be ready..."
sleep 5
# 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}"
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 -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}"
echo "Warning: Database may still be starting..."
fi
echo ""
echo -e "${GREEN}🎉 Development environment is running!${NC}"
echo "Development environment is running."
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 "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 -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 "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 ""
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