diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 2161c10b..6bb4d6fb 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -77,6 +77,8 @@ services: DB_PASSWORD: xVRQI&cA?7AU=hqJ!%au DB_NAME: cmc PORT: 8082 + PDF_OUTPUT_DIR: /var/www/cmc-sales/app/webroot/pdf + ATTACHMENTS_DIR: /var/www/cmc-sales/app/webroot/attachments_files SMTP_HOST: postfix SMTP_PORT: 25 SMTP_USER: "" diff --git a/docker-compose.stg.yml b/docker-compose.stg.yml index b1c3f164..ccc2cea1 100644 --- a/docker-compose.stg.yml +++ b/docker-compose.stg.yml @@ -75,6 +75,8 @@ services: DB_PASSWORD: xVRQI&cA?7AU=hqJ!%au DB_NAME: cmc PORT: 8082 + PDF_OUTPUT_DIR: /var/www/cmc-sales/app/webroot/pdf + ATTACHMENTS_DIR: /var/www/cmc-sales/app/webroot/attachments_files SMTP_HOST: postfix SMTP_PORT: 25 SMTP_USER: "" diff --git a/docker-compose.yml b/docker-compose.yml index d4f2b1f9..371b4c45 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -75,6 +75,8 @@ services: DB_PASSWORD: xVRQI&cA?7AU=hqJ!%au DB_NAME: cmc PORT: 8080 + PDF_OUTPUT_DIR: /var/www/cmc-sales/app/webroot/pdf + ATTACHMENTS_DIR: /var/www/cmc-sales/app/webroot/attachments_files depends_on: db: condition: service_started diff --git a/go/cmd/server/main.go b/go/cmd/server/main.go index 7dae61a2..dd4a260f 100644 --- a/go/cmd/server/main.go +++ b/go/cmd/server/main.go @@ -71,8 +71,12 @@ func main() { // Static files goRouter.PathPrefix("/static/").Handler(http.StripPrefix("/go/static/", http.FileServer(http.Dir("static")))) - // PDF files - goRouter.PathPrefix("/pdf/").Handler(http.StripPrefix("/go/pdf/", http.FileServer(http.Dir("webroot/pdf")))) + // PDF files - use PDF_OUTPUT_DIR env var or fallback to relative path + pdfDir := os.Getenv("PDF_OUTPUT_DIR") + if pdfDir == "" { + pdfDir = "webroot/pdf" + } + goRouter.PathPrefix("/pdf/").Handler(http.StripPrefix("/go/pdf/", http.FileServer(http.Dir(pdfDir)))) // Quote routes goRouter.HandleFunc("/quotes", quoteHandler.QuotesOutstandingView).Methods("GET") @@ -91,6 +95,7 @@ func main() { goRouter.HandleFunc("/pdf/generate-po", handlers.GeneratePurchaseOrderPDF).Methods("POST") goRouter.HandleFunc("/pdf/generate-packinglist", handlers.GeneratePackingListPDF).Methods("POST") goRouter.HandleFunc("/pdf/generate-orderack", handlers.GenerateOrderAckPDF).Methods("POST") + goRouter.HandleFunc("/pdf/count-pages", handlers.CountPages).Methods("POST") // The following routes are currently disabled: /* diff --git a/go/internal/cmc/handlers/attachments/attachments.go b/go/internal/cmc/handlers/attachments/attachments.go index 0b48f3aa..bc0a3167 100644 --- a/go/internal/cmc/handlers/attachments/attachments.go +++ b/go/internal/cmc/handlers/attachments/attachments.go @@ -127,8 +127,11 @@ func (h *AttachmentHandler) Create(w http.ResponseWriter, r *http.Request) { ext := filepath.Ext(handler.Filename) filename := fmt.Sprintf("%d_%s%s", time.Now().Unix(), handler.Filename[:len(handler.Filename)-len(ext)], ext) - // Create attachments directory if it doesn't exist - attachDir := "webroot/attachments_files" + // Get attachments directory from environment or use default + attachDir := os.Getenv("ATTACHMENTS_DIR") + if attachDir == "" { + attachDir = "webroot/attachments_files" + } if err := os.MkdirAll(attachDir, 0755); err != nil { http.Error(w, "Failed to create attachments directory", http.StatusInternalServerError) return @@ -172,13 +175,12 @@ func (h *AttachmentHandler) Create(w http.ResponseWriter, r *http.Request) { } // Create database record - // Store path in PHP format: /var/www/cmc-sales/app/webroot/attachments_files/filename - phpPath := "/var/www/cmc-sales/app/webroot/attachments_files/" + filename + // Store the same path that was used to save the file (works across all environments) params := db.CreateAttachmentParams{ PrincipleID: int32(principleID), Name: name, Filename: handler.Filename, - File: phpPath, // Store PHP container path for compatibility + File: filePath, // Store actual file path Type: handler.Header.Get("Content-Type"), Size: int32(handler.Size), Description: description, diff --git a/go/internal/cmc/handlers/quotes/quotes.go b/go/internal/cmc/handlers/quotes/quotes.go index b9aa368f..b2ed45f3 100644 --- a/go/internal/cmc/handlers/quotes/quotes.go +++ b/go/internal/cmc/handlers/quotes/quotes.go @@ -448,7 +448,11 @@ func (h *QuotesHandler) DailyQuoteExpirationCheck() { // Construct PDF path from filesystem enquiryRef := q["EnquiryRef"].(string) - pdfPath := fmt.Sprintf("/root/webroot/pdf/%s.pdf", enquiryRef) + pdfDir := os.Getenv("PDF_OUTPUT_DIR") + if pdfDir == "" { + pdfDir = "webroot/pdf" + } + pdfPath := fmt.Sprintf("%s/%s.pdf", pdfDir, enquiryRef) pdfFilename := fmt.Sprintf("%s.pdf", enquiryRef) err := h.SendQuoteReminderEmailWithPDF( @@ -680,7 +684,11 @@ func (h *QuotesHandler) SendManualReminder(w http.ResponseWriter, r *http.Reques } // Attach PDF quote from filesystem - pdfPath := fmt.Sprintf("/root/webroot/pdf/%s.pdf", enquiryRef) + pdfDir := os.Getenv("PDF_OUTPUT_DIR") + if pdfDir == "" { + pdfDir = "webroot/pdf" + } + pdfPath := fmt.Sprintf("%s/%s.pdf", pdfDir, enquiryRef) pdfFilename := fmt.Sprintf("%s.pdf", enquiryRef) // Get username from request