Working on quote logic
This commit is contained in:
parent
72a4b87193
commit
fd3935e42e
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue