Redoing start development to make it simpler, fixing OA not having CMC reference
This commit is contained in:
parent
ab17a17f25
commit
ca83ea078d
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"log"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
@ -23,7 +24,14 @@ type OrderAckLineItemTemplateData struct {
|
||||||
|
|
||||||
// BuildOrderAckHTML generates the complete HTML for an order acknowledgement using templates
|
// BuildOrderAckHTML generates the complete HTML for an order acknowledgement using templates
|
||||||
func (g *HTMLDocumentGenerator) BuildOrderAckHTML(data *OrderAckPDFData, totalPages int, currentPage int) string {
|
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
|
// Calculate totals
|
||||||
subtotal := 0.0
|
subtotal := 0.0
|
||||||
|
|
|
||||||
|
|
@ -534,6 +534,10 @@ func GenerateOrderAckPDF(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Error(w, "invalid JSON payload", http.StatusBadRequest)
|
http.Error(w, "invalid JSON payload", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log the request for debugging
|
||||||
|
log.Printf("=== GenerateOrderAckPDF: Received request with CmcReference='%s' ===", req.CmcReference)
|
||||||
|
|
||||||
if req.CustomerName == "" {
|
if req.CustomerName == "" {
|
||||||
http.Error(w, "customer_name is required", http.StatusBadRequest)
|
http.Error(w, "customer_name is required", http.StatusBadRequest)
|
||||||
return
|
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{
|
data := &pdf.OrderAckPDFData{
|
||||||
OrderAcknowledgement: doc,
|
OrderAcknowledgement: doc,
|
||||||
Customer: cust,
|
Customer: cust,
|
||||||
|
|
@ -594,6 +600,8 @@ func GenerateOrderAckPDF(w http.ResponseWriter, r *http.Request) {
|
||||||
LineItems: lineItems,
|
LineItems: lineItems,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("=== GenerateOrderAckPDF: Created OrderAckPDFData with CmcReference='%s' ===", data.CmcReference)
|
||||||
|
|
||||||
// Use HTML generator
|
// Use HTML generator
|
||||||
gen := pdf.NewHTMLDocumentGenerator(outputDir)
|
gen := pdf.NewHTMLDocumentGenerator(outputDir)
|
||||||
filename, err := gen.GenerateOrderAckPDF(data)
|
filename, err := gen.GenerateOrderAckPDF(data)
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,21 @@ if (!empty($document['Document']['cmc_reference'])) {
|
||||||
$orderAckNumber = $document['OrderAcknowledgement']['title'];
|
$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'])
|
$orderAckTitle = isset($document['OrderAcknowledgement']['title']) && !empty($document['OrderAcknowledgement']['title'])
|
||||||
? $document['OrderAcknowledgement']['title']
|
? $document['OrderAcknowledgement']['title']
|
||||||
: 'OrderAck-' . $document['Document']['id'];
|
: 'OrderAck-' . $document['Document']['id'];
|
||||||
|
|
@ -80,7 +95,7 @@ $payload = array(
|
||||||
'document_id' => intval($document['Document']['id']),
|
'document_id' => intval($document['Document']['id']),
|
||||||
'title' => $orderAckTitle,
|
'title' => $orderAckTitle,
|
||||||
'customer_name' => $customerName,
|
'customer_name' => $customerName,
|
||||||
'cmc_reference' => isset($document['Document']['cmc_reference']) ? $document['Document']['cmc_reference'] : '',
|
'cmc_reference' => $document['Document']['cmc_reference'],
|
||||||
'email_to' => $contactEmail,
|
'email_to' => $contactEmail,
|
||||||
'attention' => $contactName,
|
'attention' => $contactName,
|
||||||
'your_reference' => $yourReference,
|
'your_reference' => $yourReference,
|
||||||
|
|
@ -106,6 +121,8 @@ $payload = array(
|
||||||
'output_dir' => $outputDir
|
'output_dir' => $outputDir
|
||||||
);
|
);
|
||||||
|
|
||||||
|
error_log("=== pdf_orderack.ctp: payload['cmc_reference']='" . $payload['cmc_reference'] . "' ===");
|
||||||
|
|
||||||
$ch = curl_init($goEndpoint);
|
$ch = curl_init($goEndpoint);
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
|
||||||
|
|
@ -1,125 +1,69 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# CMC Sales Development Environment Setup Script
|
# CMC Sales Development Environment Setup Script
|
||||||
|
# Simple, straightforward startup without docker compose watch mode
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Colors for output
|
# Parse command line arguments
|
||||||
RED='\033[0;31m'
|
BUILD_CACHE=true
|
||||||
GREEN='\033[0;32m'
|
for arg in "$@"; do
|
||||||
YELLOW='\033[1;33m'
|
if [[ "$arg" == "--no-cache" ]]; then
|
||||||
BLUE='\033[0;34m'
|
BUILD_CACHE=false
|
||||||
NC='\033[0m' # No Color
|
fi
|
||||||
|
done
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check prerequisites
|
# Check prerequisites
|
||||||
echo -e "${YELLOW}📋 Checking prerequisites...${NC}"
|
if ! command -v docker >/dev/null 2>&1; then
|
||||||
|
echo "Error: Docker is not installed"
|
||||||
if ! command_exists docker; then
|
|
||||||
echo -e "${RED}❌ Docker is not installed${NC}"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! command_exists docker-compose; then
|
if ! command -v docker-compose >/dev/null 2>&1; then
|
||||||
echo -e "${RED}❌ Docker Compose is not installed${NC}"
|
echo "Error: Docker Compose is not installed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${GREEN}✅ Prerequisites satisfied${NC}"
|
echo "Starting CMC Sales Development Environment..."
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Check Docker Compose version for watch support
|
# Build and start services
|
||||||
DOCKER_COMPOSE_VERSION=$(docker compose version --short 2>/dev/null || echo "unknown")
|
BUILD_FLAG=""
|
||||||
SUPPORTS_WATCH=false
|
if [[ "$BUILD_CACHE" == "false" ]]; then
|
||||||
|
BUILD_FLAG="--no-cache"
|
||||||
if [[ "$DOCKER_COMPOSE_VERSION" != "unknown" ]]; then
|
echo "Building with --no-cache (this may take a while)..."
|
||||||
# Check if version is 2.22.0 or higher (when watch was introduced)
|
else
|
||||||
if docker compose version 2>/dev/null | grep -q "Docker Compose version v2\.\([2-9][2-9]\|[3-9][0-9]\)"; then
|
echo "Building services..."
|
||||||
SUPPORTS_WATCH=true
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
if [[ "$BUILD_CACHE" == "false" ]]; then
|
||||||
echo -e "${YELLOW}🏗️ Building and starting services...${NC}"
|
docker compose build $BUILD_FLAG
|
||||||
|
docker compose up -d
|
||||||
# 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
|
|
||||||
else
|
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
|
docker compose up --build -d
|
||||||
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "${YELLOW}⏳ Waiting for services to be ready...${NC}"
|
echo "Waiting for services to be ready..."
|
||||||
sleep 10
|
sleep 5
|
||||||
|
|
||||||
# Check service health
|
# Check database
|
||||||
echo -e "${YELLOW}🏥 Checking service health...${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 "Warning: Database may still be starting..."
|
||||||
|
fi
|
||||||
|
|
||||||
# Check database
|
echo ""
|
||||||
if docker compose exec -T db mariadb-admin ping -h localhost -u cmc -p'xVRQI&cA?7AU=hqJ!%au' --silent; then
|
echo "Development environment is running."
|
||||||
echo -e "${GREEN}✅ Database is ready${NC}"
|
echo ""
|
||||||
else
|
echo "Available services:"
|
||||||
echo -e "${RED}❌ Database is not ready${NC}"
|
echo " CakePHP (Legacy): http://cmclocal (add to /etc/hosts: 127.0.0.1 cmclocal)"
|
||||||
fi
|
echo " Go (Modern): http://localhost:8080"
|
||||||
|
echo " Database: localhost:3306 (user: cmc)"
|
||||||
# Check Go app
|
echo ""
|
||||||
if curl -s http://localhost:8080/api/v1/health > /dev/null; then
|
echo "Useful commands:"
|
||||||
echo -e "${GREEN}✅ Go application is ready${NC}"
|
echo " View logs: docker compose logs -f"
|
||||||
else
|
echo " Stop services: docker compose down"
|
||||||
echo -e "${YELLOW}⚠️ Go application might still be starting...${NC}"
|
echo " Restart Go app: docker compose restart cmc-go"
|
||||||
fi
|
echo " Restart PHP app: docker compose restart cmc-php"
|
||||||
|
echo ""
|
||||||
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
|
|
||||||
Loading…
Reference in a new issue