Bläddra i källkod

PDF Improvements

Benjamin Harris 2 månader sedan
förälder
incheckning
f3a82a22a9

+ 10 - 15
client-assets/css/graphPrint.css

@@ -6,29 +6,24 @@
 @media print {
     @page {
             size: A4 portrait;
+            margin: 0;
         }
-    @page :left {
-        margin-left: 0.5cm;
-    }
-    @page :right {
-        margin-right: 0.5cm;
-    }
-    @page :top {
-        margin-top: 0cm;
+    html, body {
+        margin: 0;
+        padding: 0;
+        background: #fff;
     }
-    @page :bottom {
-        margin-bottom: 0cm;
+    .page {
+        padding: 10mm;
+        box-sizing: border-box;
     }
     body {
         min-width: 992px !important;
+        font-size: 0.75em;
     }
     .container {
         min-width: 992px !important;
     }
-
-    body {
-        font-size: 0.75em;
-    }
     .pagebreak { 
         page-break-before: always;
         break-before: page;
@@ -109,7 +104,7 @@
     }
     
     .sub-chart td {
-        padding: 2px 0 2px 0;
+        padding: 3px 0 3ch 0;
         page-break-after: avoid;
     }
 

+ 3 - 6
controllers/ollamaGenerate.php

@@ -569,13 +569,10 @@ if ($recordType === 'plant') {
             . "TASK: Write a detailed technical interpretation of the tissue analysis for THIS SPECIFIC CROP: {$cropType}. "
             . "Do NOT mention or compare to any other crop type — your entire response must be about {$cropType} only. "
             . "Use these headings:\n"
-            . "1. MAJOR ELEMENTS (N, P, K, S, Mg, Ca, Na)\n"
-            . "2. TRACE ELEMENTS (Fe, Mn, Zn, Cu, B)\n"
-            . "3. OTHER ELEMENTS (Mo, Co, Se, Cl, C)\n"
-            . "4. NUTRIENT INTERACTIONS & ANTAGONISMS\n"
-            . "5. OVERALL NUTRITIONAL ASSESSMENT FOR {$cropType}\n"
+            . "1. NUTRIENT INTERACTIONS & ANTAGONISMS\n"
+            . "2. OVERALL NUTRITIONAL ASSESSMENT FOR {$cropType}\n"
             . (!empty($historicalRows)
-                ? "6. TREND ANALYSIS (compare current results to the HISTORICAL RECORDS provided above — "
+                ? "3. TREND ANALYSIS (compare current results to the HISTORICAL RECORDS provided above — "
                   . "note which elements have improved, declined, or remained stable, and what this trend means for {$cropType} health)\n"
                 : '')
             . "For each element marked [DEFICIENT] or [EXCESS], explain the agronomic significance "

+ 3 - 2
dashboard/crop-analysis/plant-test-data/plant-report-pdf.php

@@ -100,7 +100,8 @@ function formatReportText(string $text): string
 <head>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1">
-    <title>Soil Analysis Report | Crop Monitor</title>
+    <title>Plant Analysis Report | Crop Monitor</title>
+    <link rel="icon" href="/favicon.ico?v=2" type="image/x-icon">
     <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
     <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.css" rel="stylesheet" crossorigin="anonymous">
     <link href="/client-assets/css/dashboard.css" rel="stylesheet">
@@ -155,7 +156,7 @@ function formatReportText(string $text): string
 </head>
 <body>
 
-<div class="container" id="pdf-content">
+<div class="container page" id="pdf-content">
 
     <?php if (!$row): ?>
         <div class="alert alert-danger mt-4">Record not found or access denied.</div>

+ 1 - 1
dashboard/crop-analysis/plant-test-data/plant-report.php

@@ -115,7 +115,7 @@ include __DIR__ . '/../../../layouts/header.php';
                            class="btn btn-outline-secondary btn-sm">
                             &larr; Analysis
                         </a>
-                        <a href="/dashboard/crop-analysis/plant-test-data/plant-report-pdf.php?rid=<?= $record_id ?>&rand=<?= urlencode($rand_id) ?>"
+                        <a href="/dashboard/crop-analysis/plant-test-data/plant-report-pdf.php?rid=<?= $recordId ?>&rand=<?= urlencode($randId) ?>&cid=<?= $clientId ?>"
                         class="btn btn-outline-success btn-sm" target="_blank">
                             <i class="fas fa-file-pdf me-1"></i>PDF — Report
                         </a>

+ 76 - 9
dashboard/crop-analysis/soil-test-data/soil-analysis.php

@@ -74,13 +74,23 @@ include __DIR__.'/../../../layouts/header.php';
 <link rel="stylesheet" href="/client-assets/home/css/graphPrint.css" media="print">
 <style>
     .progress { border-radius: 0 !important; }
+    @media print {
+        .section + .section {
+            break-before: page;
+            page-break-before: always;
+        }
+    }
 </style>
 
 <div class="container" id="content">
 
-    <div class="row mb-2">
-        <div class="col-md-3">
-            <img class="img-fluid" src="/client-assets/images/crop-monitor.png" alt="Crop Monitor">
+    <div class="row align-items-center mb-1 mt-3">
+        <div class="col-3">
+            <img class="img-fluid" src="/client-assets/images/crop-monitor.png" alt="Crop Monitor" style="max-height:55px;">
+        </div>
+        <div class="col-9 text-end">
+            <div class="fw-bold h5 mb-0">Soil Analysis</div>
+            <div class="text-muted small"></div>
         </div>
     </div>
 
@@ -154,7 +164,8 @@ include __DIR__.'/../../../layouts/header.php';
         <div class="col-md-12 text-center fw-bold h4">Soil Analysis Summary</div>
     </div>
 
-    <table class="chart">
+    <div class="section" id="page-1">
+    <table class="chart mb-0">
         <tbody>
           <!-- ── CHART HEADER ──────────────────────────────────────────── -->
           <tr class="chart-header">
@@ -237,7 +248,54 @@ include __DIR__.'/../../../layouts/header.php';
           soilRow($row, $spec, ['element'=>'al',       'sbl'=>'Al', 'nutrient'=>'Aluminium', 'type'=>'ppm', 'text'=>'c', 'rec_text'=>'r', 'decimal'=>2, 'graph'=>'lightredGraph']);
           soilRow($row, $spec, ['element'=>'sl_cacl2', 'sbl'=>'Si', 'nutrient'=>'Silicon',   'type'=>'ppm', 'text'=>'c', 'rec_text'=>'r', 'decimal'=>2, 'graph'=>'lightredGraph']);
           ?>
+        </tbody>
+    </table>
+    </div>
+    
+    <div class="section" id="page-2">
+    <div class="row">
+        <table class="title w-100 mb-3 small">
+        <tbody>
+            <tr>
+                <th class="col-20"></th>
+                <th class="col-20"></th>
+                <th class="col-20"></th>
+                <th class="col-20"></th>
+            </tr>
+            
+            <tr>
+                <td class="right"><b>DATE SAMPLED:</b></td>
+                <td class="left"><?= $sampleDate ?></td>
+                <td class="right"><b>CROP:</b></td>
+                <td class="left"><?= $crop ?></td>
+            </tr>
+        </tbody>
+    </table>
+    </div>
 
+    <table class="chart mb-0">
+        <tbody>
+          <!-- ── CHART HEADER ──────────────────────────────────────────── -->
+          <tr class="chart-header">
+            <th colspan="3" class="text-center col-md-6 border-left border-right border-top">ELEMENT</th>
+            <th colspan="3" class="text-center col-md-6 border-right border-top">STATUS</th>
+          </tr>
+          <tr class="chart-header-sub">
+            <th class="text-center col-18 border-left"></th>
+            <th class="text-center col-15">DESIRED</th>
+            <th class="text-center col-15">FOUND</th>
+            <th class="text-center col-16 stripe-1">LIGHT</th>
+            <th class="text-center col-16 stripe-1">MEDIUM</th>
+            <th class="text-center col-16 border-right stripe-1">HEAVY</th>
+          </tr>
+          <tr>
+            <td class="border-left"></td>
+            <td class="border-left"></td>
+            <td class="border-left nutrient-balance"></td>
+            <td class="border-left"></td>
+            <td class="border-left"></td>
+            <td class="border-left border-right"></td>
+          </tr>
           <!-- ── BASE SATURATION ────────────────────────────────────────── -->
           <tr class="chart-header-sub">
             <th colspan="3" class="col-16 border-left text-center lightpurple">BASE SATURATION</th>
@@ -308,19 +366,28 @@ include __DIR__.'/../../../layouts/header.php';
         </tbody>
     </table>
 
-    <footer class="py-4 bg-light mt-auto">
+    <footer class="py-4 mt-auto mb-0">
         <div class="container-fluid px-4">
             <div class="d-flex align-items-center justify-content-between small">
                 <div class="text-muted">&copy; <?= date('Y') ?> Crop Management Platform. All Rights Reserved.</div>
-                <div>
-                    <a href="/privacy-policy">Privacy Policy</a> &middot;
-                    <a href="/terms">Terms &amp; Conditions</a>
-                </div>
             </div>
         </div>
     </footer>
 
 </div><!-- /.container -->
+<script>
+(function () {
+    // Set #page-1 height to exactly one A4 page so the print break falls cleanly.
+    // A4 at 96 dpi = 1122px tall; subtract ~60px for the container top margin/padding.
+    var A4_PX   = 1300;
+    var OFFSET  = 60;
+    var page1   = document.getElementById('page-1');
+    if (page1) {
+        page1.style.minHeight = (A4_PX - OFFSET) + 'px';
+        page1.style.overflow  = 'hidden';
+    }
+})();
+</script>
 
 <script>
 $(document).ready(function () {

+ 23 - 25
dashboard/crop-analysis/soil-test-data/soil-print-combined.php

@@ -76,27 +76,26 @@ function h(string $v): string {
 
         @media print {
             @page {
-                size: A4 portrait;
-            }
-            @page :left {
-                margin-left: 0.5cm;
-            }
-            @page :right {
-                margin-right: 0.5cm;
-            }
-            @page :top {
-                margin-top: 0cm;
-            }
-            @page :bottom {
-                margin-bottom: 0cm;
-            }
-            body {
-                min-width: 992px !important;
-            }
-            .container {
-                min-width: 992px !important;
-            }
-            .report-textarea {
+            size: A4 portrait;
+            margin: 0;
+        }
+        html, body {
+            margin: 0;
+            padding: 0;
+            background: #fff;
+        }
+        .page {
+            padding: 0;
+            box-sizing: border-box;
+        }
+        body {
+            min-width: 1030px !important;
+            font-size: 0.75em;
+        }
+        .container {
+            min-width: 1030px !important;
+        }
+        .report-textarea {
                 border:none;
             }
         }
@@ -104,11 +103,11 @@ function h(string $v): string {
 </head>
 <body>
 
-<div class="page-section">
+<div class="page-section page">
     <iframe id="frame-analysis" src="<?= h($analysisUrl) ?>" scrolling="no"></iframe>
 </div>
 
-<div class="page-section">
+<div class="page-section page">
     <iframe id="frame-report" src="<?= h($reportUrl) ?>" scrolling="no"></iframe>
 </div>
 
@@ -131,5 +130,4 @@ function h(string $v): string {
 </script>
 
 </body>
-</html>
-nt=`1`]]
+</html>

+ 6 - 2
dashboard/crop-analysis/soil-test-data/soil-report-pdf.php

@@ -117,6 +117,7 @@ function formatReportText(string $text): string
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1">
     <title>Soil Analysis Report | Crop Monitor</title>
+    <link rel="icon" href="/favicon.ico?v=2" type="image/x-icon">
     <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
     <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.css" rel="stylesheet" crossorigin="anonymous">
     <link href="/client-assets/css/dashboard.css" rel="stylesheet">
@@ -127,6 +128,9 @@ function formatReportText(string $text): string
             .page-break    { page-break-before: always; }
             body           { font-size: 11px; }
             .report-section p { font-size: 11px; }
+            .section {page-break-inside: avoid;break-inside: avoid;}
+            .section-header {page-break-after: avoid;break-after: avoid;}
+            .section-header + * {page-break-before: avoid;break-before: avoid;}
         }
         .report-section p   { margin-bottom: 0.6rem; line-height: 1.6; }
         .report-section h1,
@@ -171,14 +175,14 @@ function formatReportText(string $text): string
 </head>
 <body>
 
-<div class="container" id="pdf-content">
+<div class="container page" id="pdf-content">
 
     <?php if (!$row): ?>
         <div class="alert alert-danger mt-4">Record not found or access denied.</div>
     <?php else: ?>
 
     <!-- ── Header ──────────────────────────────────────────────────────────── -->
-    <div class="row align-items-center mb-3 mt-3">
+    <div class="row align-items-center mb-1 mt-3">
         <div class="col-3">
             <img class="img-fluid" src="/client-assets/images/crop-monitor.png"
                  alt="Crop Monitor" style="max-height:55px;">

+ 1 - 1
layouts/header.php

@@ -10,7 +10,7 @@
         <meta name="keywords" content="Crop Management, Agriculture, Soil Analysis, Weather Monitoring, Crop Health, Farm Management, Agricultural Technology">
         <meta name="author" content="Crop Management Platform Team">
         
-        <link rel="icon" href="./favicon.ico?v=2" type="image/x-icon">
+        <link rel="icon" href="/favicon.ico?v=2" type="image/x-icon">
 
         <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
         <link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />