diff --git a/conf/nginx-site.conf b/conf/nginx-site.conf index 2fc1e93f..7d98b19d 100644 --- a/conf/nginx-site.conf +++ b/conf/nginx-site.conf @@ -1,7 +1,7 @@ resolver 127.0.0.11 valid=10s; server { - server_name cmclocal; + server_name cmclocal localhost; auth_basic_user_file /etc/nginx/userpasswd; auth_basic "Restricted"; client_max_body_size 200M; diff --git a/go/internal/cmc/handlers/attachments/attachments.go b/go/internal/cmc/handlers/attachments/attachments.go index 9008db42..bc0a3167 100644 --- a/go/internal/cmc/handlers/attachments/attachments.go +++ b/go/internal/cmc/handlers/attachments/attachments.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "log" "net/http" "os" "path/filepath" @@ -130,21 +129,16 @@ func (h *AttachmentHandler) Create(w http.ResponseWriter, r *http.Request) { // Get attachments directory from environment or use default attachDir := os.Getenv("ATTACHMENTS_DIR") - log.Printf("=== Upload Debug: ATTACHMENTS_DIR env var = '%s'", attachDir) if attachDir == "" { attachDir = "webroot/attachments_files" - log.Printf("=== Upload Debug: Using fallback path: %s", attachDir) } - log.Printf("=== Upload Debug: Final attachDir = '%s'", attachDir) if err := os.MkdirAll(attachDir, 0755); err != nil { - log.Printf("=== Upload Debug: Failed to create directory: %v", err) http.Error(w, "Failed to create attachments directory", http.StatusInternalServerError) return } // Save file to disk filePath := filepath.Join(attachDir, filename) - log.Printf("=== Upload Debug: Saving file to: %s", filePath) dst, err := os.Create(filePath) if err != nil { http.Error(w, "Failed to save file", http.StatusInternalServerError) @@ -196,8 +190,6 @@ func (h *AttachmentHandler) Create(w http.ResponseWriter, r *http.Request) { params.Name = handler.Filename } - log.Printf("=== Upload Debug: Storing in database - File path: %s, Name: %s", params.File, params.Name) - result, err := h.queries.CreateAttachment(r.Context(), params) if err != nil { // Clean up file on error diff --git a/go/internal/cmc/handlers/pdf_api.go b/go/internal/cmc/handlers/pdf_api.go index 1af1795c..c9ee797f 100644 --- a/go/internal/cmc/handlers/pdf_api.go +++ b/go/internal/cmc/handlers/pdf_api.go @@ -228,6 +228,8 @@ func GenerateQuotePDF(w http.ResponseWriter, r *http.Request) { http.Error(w, fmt.Sprintf("invalid JSON payload: %v", err), http.StatusBadRequest) return } + log.Printf("GenerateQuotePDF: Received request - DocumentID=%d, CmcReference='%s', Revision=%d, CustomerName='%s'", + req.DocumentID, req.CmcReference, req.Revision, req.CustomerName) if req.CmcReference == "" || req.CustomerName == "" { log.Printf("GenerateQuotePDF: missing required fields - cmc_reference='%s', customer_name='%s'", req.CmcReference, req.CustomerName) http.Error(w, "cmc_reference and customer_name are required", http.StatusBadRequest) diff --git a/go/internal/cmc/pdf/html_generator.go b/go/internal/cmc/pdf/html_generator.go index 327a3a35..372d00b2 100644 --- a/go/internal/cmc/pdf/html_generator.go +++ b/go/internal/cmc/pdf/html_generator.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io/ioutil" + "log" "os" "path/filepath" "time" @@ -197,10 +198,13 @@ func (g *HTMLDocumentGenerator) GenerateQuotePDF(data *QuotePDFData) (string, er quoteNumber = fmt.Sprintf("%s_%d", quoteNumber, data.Document.Revision) } } + log.Printf("=== HTML Generator: Quote number before fallback: '%s', Document ID: %d, Revision: %d", + quoteNumber, data.Document.ID, data.Document.Revision) filenameBase := quoteNumber if filenameBase == "" { filenameBase = "CMC Quote" } + log.Printf("=== HTML Generator: Final filename base: '%s'", filenameBase) filename := fmt.Sprintf("%s.pdf", filenameBase) pdfPath := filepath.Join(g.outputDir, filename) diff --git a/php/app/views/documents/pdf_invoice.ctp b/php/app/views/documents/pdf_invoice.ctp index 8d6fb88c..9ee39df1 100755 --- a/php/app/views/documents/pdf_invoice.ctp +++ b/php/app/views/documents/pdf_invoice.ctp @@ -36,17 +36,49 @@ if (!empty($document['Document']['cmc_reference'])) { $invoiceNumber = $document['Invoice']['title']; } +// Add fallback logic for missing fields +$invoiceTitle = isset($document['Invoice']['title']) && !empty($document['Invoice']['title']) + ? $document['Invoice']['title'] + : 'Invoice-' . $document['Document']['id']; + +$customerName = 'Customer'; +if (isset($enquiry['Customer']['name']) && !empty($enquiry['Customer']['name'])) { + $customerName = $enquiry['Customer']['name']; +} elseif (isset($document['Document']['cmc_reference']) && !empty($document['Document']['cmc_reference'])) { + $customerName = $document['Document']['cmc_reference']; +} + +// Add fallback logic for all enquiry-dependent fields +$contactEmail = isset($enquiry['Contact']['email']) ? $enquiry['Contact']['email'] : ''; +$contactName = ''; +if (isset($enquiry['Contact']['first_name']) && isset($enquiry['Contact']['last_name'])) { + $contactName = $enquiry['Contact']['first_name'] . ' ' . $enquiry['Contact']['last_name']; +} + +$userFirstName = isset($enquiry['User']['first_name']) ? $enquiry['User']['first_name'] : ''; +$userLastName = isset($enquiry['User']['last_name']) ? $enquiry['User']['last_name'] : ''; +$userEmail = isset($enquiry['User']['email']) ? $enquiry['User']['email'] : ''; + +$yourReference = ''; +if (isset($enquiry['Enquiry']['customer_reference']) && !empty($enquiry['Enquiry']['customer_reference'])) { + $yourReference = $enquiry['Enquiry']['customer_reference']; +} else if (isset($enquiry['Enquiry']['created'])) { + $yourReference = 'Enquiry on ' . date('j M Y', strtotime($enquiry['Enquiry']['created'])); +} else { + $yourReference = 'Enquiry on ' . date('j M Y'); +} + $payload = array( 'document_id' => intval($document['Document']['id']), 'invoice_number' => $invoiceNumber, - 'invoice_title' => $document['Invoice']['title'], - 'customer_name' => $enquiry['Customer']['name'], - 'contact_email' => $enquiry['Contact']['email'], - 'contact_name' => $enquiry['Contact']['first_name'].' '.$enquiry['Contact']['last_name'], - 'user_first_name' => $enquiry['User']['first_name'], - 'user_last_name' => $enquiry['User']['last_name'], - 'user_email' => $enquiry['User']['email'], - 'your_reference' => isset($enquiry['Enquiry']['customer_reference']) ? $enquiry['Enquiry']['customer_reference'] : ('Enquiry on '.date('j M Y', strtotime($enquiry['Enquiry']['created']))), + 'invoice_title' => $invoiceTitle, + 'customer_name' => $customerName, + 'contact_email' => $contactEmail, + 'contact_name' => $contactName, + 'user_first_name' => $userFirstName, + 'user_last_name' => $userLastName, + 'user_email' => $userEmail, + 'your_reference' => $yourReference, 'ship_via' => $document['Invoice']['ship_via'], 'fob' => $fob, 'issue_date' => $document['Invoice']['issue_date'], // expects YYYY-MM-DD