Showing
3 changed files
with
83 additions
and
6 deletions
| ... | @@ -67,11 +67,11 @@ class OcrController extends Controller | ... | @@ -67,11 +67,11 @@ class OcrController extends Controller |
| 67 | { | 67 | { |
| 68 | try { | 68 | try { |
| 69 | // Lấy template name từ request hoặc mặc định | 69 | // Lấy template name từ request hoặc mặc định |
| 70 | - $templateName = $request->get('template_name', 'nemo12'); | 70 | + $templateName = $request->get('template_name', ''); |
| 71 | 71 | ||
| 72 | // Giả sử file OCR JSON & ảnh nằm trong storage/app/public/image/ | 72 | // Giả sử file OCR JSON & ảnh nằm trong storage/app/public/image/ |
| 73 | - $jsonPath = public_path("image/data_picking_detail_1754967679.json"); | 73 | + $jsonPath = public_path("image/3_1757295841_with_table.json"); |
| 74 | - $imgPath = ("image/data_picking_detail_1754967679.jpg"); | 74 | + $imgPath = ("image/3_1757295841.jpg"); |
| 75 | 75 | ||
| 76 | if (!file_exists($jsonPath)) { | 76 | if (!file_exists($jsonPath)) { |
| 77 | return response()->json(['error' => 'File OCR JSON không tìm thấy'], 404); | 77 | return response()->json(['error' => 'File OCR JSON không tìm thấy'], 404); |
| ... | @@ -82,6 +82,14 @@ class OcrController extends Controller | ... | @@ -82,6 +82,14 @@ class OcrController extends Controller |
| 82 | return response()->json(['error' => 'File OCR JSON không hợp lệ'], 400); | 82 | return response()->json(['error' => 'File OCR JSON không hợp lệ'], 400); |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | + if (!empty($ocrData)) { | ||
| 86 | + foreach ($ocrData['tables'] as $item_data) { | ||
| 87 | + $table_box = $item_data['table_box']; | ||
| 88 | + $total_rows = $item_data['total_rows'] - 1; | ||
| 89 | + $table_detail = $item_data['cells']; | ||
| 90 | + } | ||
| 91 | + } | ||
| 92 | + | ||
| 85 | $dataMapping = []; | 93 | $dataMapping = []; |
| 86 | $is_template = false; | 94 | $is_template = false; |
| 87 | 95 | ||
| ... | @@ -111,9 +119,14 @@ class OcrController extends Controller | ... | @@ -111,9 +119,14 @@ class OcrController extends Controller |
| 111 | } | 119 | } |
| 112 | } | 120 | } |
| 113 | 121 | ||
| 122 | + | ||
| 114 | return response()->json([ | 123 | return response()->json([ |
| 115 | 'success' => true, | 124 | 'success' => true, |
| 116 | - 'ocrData' => $ocrData, | 125 | + 'ocrData' => $ocrData['ocr_data'] ?? [], |
| 126 | + 'tableInfo' => $table_detail ?? [], | ||
| 127 | + 'table_box' => $table_box ?? [], | ||
| 128 | + 'total_rows' => $total_rows ?? 0, | ||
| 129 | + 'rows_box' => $rows_box ?? [], | ||
| 117 | 'pdfImageUrl' => $imgPath, | 130 | 'pdfImageUrl' => $imgPath, |
| 118 | 'dataMapping' => $dataMapping, | 131 | 'dataMapping' => $dataMapping, |
| 119 | 'is_template' => $is_template, | 132 | 'is_template' => $is_template, | ... | ... |
| ... | @@ -175,3 +175,22 @@ select { | ... | @@ -175,3 +175,22 @@ select { |
| 175 | opacity: 1; | 175 | opacity: 1; |
| 176 | transform: scale(1.02); | 176 | transform: scale(1.02); |
| 177 | } | 177 | } |
| 178 | + | ||
| 179 | + | ||
| 180 | +.data-table { | ||
| 181 | + width: 100%; | ||
| 182 | + border-collapse: collapse; | ||
| 183 | +} | ||
| 184 | +.data-table th, | ||
| 185 | +.data-table td { | ||
| 186 | + border: 1px solid #ccc; | ||
| 187 | + padding: 6px; | ||
| 188 | +} | ||
| 189 | +.data-table input { | ||
| 190 | + width: 100%; | ||
| 191 | + box-sizing: border-box; | ||
| 192 | +} | ||
| 193 | + | ||
| 194 | +.mt-10 { | ||
| 195 | + margin-top: 10px; | ||
| 196 | +} | ... | ... |
| ... | @@ -106,7 +106,46 @@ | ... | @@ -106,7 +106,46 @@ |
| 106 | @blur="removeAllFocus()" | 106 | @blur="removeAllFocus()" |
| 107 | > | 107 | > |
| 108 | </div> | 108 | </div> |
| 109 | - <button @click="saveTemplate">💾Save</button> | 109 | + |
| 110 | + <!-- Table mapping --> | ||
| 111 | + <table class="data-table" v-if="total_rows > 0"> | ||
| 112 | + <thead> | ||
| 113 | + <tr> | ||
| 114 | + <th>Product Name</th> | ||
| 115 | + <th>Product Code</th> | ||
| 116 | + <th>Quantity</th> | ||
| 117 | + </tr> | ||
| 118 | + </thead> | ||
| 119 | + <tbody> | ||
| 120 | + <tr class="table-detail" | ||
| 121 | + v-for="(row, rowIndex) in total_rows" | ||
| 122 | + :key="rowIndex" | ||
| 123 | + :data-row="rowIndex" | ||
| 124 | + > | ||
| 125 | + <td class="form-group"> | ||
| 126 | + <input | ||
| 127 | + :data-row="rowIndex" | ||
| 128 | + :data-field="'product_name'" | ||
| 129 | + placeholder="Enter name"> | ||
| 130 | + </td> | ||
| 131 | + <td class="form-group"> | ||
| 132 | + <input | ||
| 133 | + :data-row="rowIndex" | ||
| 134 | + :data-field="'product_code'" | ||
| 135 | + placeholder="Enter code"> | ||
| 136 | + </td> | ||
| 137 | + <td class="form-group"> | ||
| 138 | + <input | ||
| 139 | + :data-row="rowIndex" | ||
| 140 | + :data-field="'quantity'" | ||
| 141 | + type="number" | ||
| 142 | + placeholder="0"> | ||
| 143 | + </td> | ||
| 144 | + </tr> | ||
| 145 | + </tbody> | ||
| 146 | + </table> | ||
| 147 | + | ||
| 148 | + <button class="mt-10" @click="saveTemplate">💾Save</button> | ||
| 110 | </div> | 149 | </div> |
| 111 | 150 | ||
| 112 | </div> | 151 | </div> |
| ... | @@ -124,6 +163,9 @@ | ... | @@ -124,6 +163,9 @@ |
| 124 | activeIndex: null, | 163 | activeIndex: null, |
| 125 | manualField: "", | 164 | manualField: "", |
| 126 | formData: {}, | 165 | formData: {}, |
| 166 | + tableInfo: {}, | ||
| 167 | + total_rows: 0, | ||
| 168 | + table_box: [], | ||
| 127 | manualBoxData: {}, | 169 | manualBoxData: {}, |
| 128 | fieldOptions: [], | 170 | fieldOptions: [], |
| 129 | customer_name_xy: '', | 171 | customer_name_xy: '', |
| ... | @@ -836,11 +878,14 @@ | ... | @@ -836,11 +878,14 @@ |
| 836 | } | 878 | } |
| 837 | 879 | ||
| 838 | this.ocrData = data.ocrData; | 880 | this.ocrData = data.ocrData; |
| 881 | + this.tableInfo = data.tableInfo; | ||
| 882 | + this.table_box = data.table_box; | ||
| 883 | + this.total_rows = data.total_rows; | ||
| 839 | this.pdfImageUrl = data.pdfImageUrl; | 884 | this.pdfImageUrl = data.pdfImageUrl; |
| 840 | this.fieldOptions = data.fieldOptions; | 885 | this.fieldOptions = data.fieldOptions; |
| 841 | this.dataMapping = data.dataMapping; | 886 | this.dataMapping = data.dataMapping; |
| 842 | this.is_template = data.is_template; | 887 | this.is_template = data.is_template; |
| 843 | - console.log('Loaded OCR data:', this.ocrData); | 888 | + //console.log('Loaded OCR data:', this.ocrData); |
| 844 | 889 | ||
| 845 | } catch (error) { | 890 | } catch (error) { |
| 846 | console.error('Error in loadOCRData:', error); | 891 | console.error('Error in loadOCRData:', error); | ... | ... |
-
Please register or sign in to post a comment