Showing
2 changed files
with
12 additions
and
7 deletions
| ... | @@ -17,13 +17,11 @@ class OcrController extends Controller | ... | @@ -17,13 +17,11 @@ class OcrController extends Controller |
| 17 | public function store(Request $request) | 17 | public function store(Request $request) |
| 18 | { | 18 | { |
| 19 | 19 | ||
| 20 | +// dd($request->all()); | ||
| 20 | $request->validate([ | 21 | $request->validate([ |
| 21 | 'customer_name_text' => 'required|string', | 22 | 'customer_name_text' => 'required|string', |
| 22 | 'customer_name_xy' => 'required|string', | 23 | 'customer_name_xy' => 'required|string', |
| 23 | 'template_name' => 'required|string|unique:mst_template,tpl_name', | 24 | 'template_name' => 'required|string|unique:mst_template,tpl_name', |
| 24 | - 'fields' => 'required|array', | ||
| 25 | - 'fields.*.name' => 'required|string', | ||
| 26 | - 'fields.*.xy' => 'required|string', | ||
| 27 | ]); | 25 | ]); |
| 28 | 26 | ||
| 29 | try { | 27 | try { |
| ... | @@ -35,11 +33,11 @@ class OcrController extends Controller | ... | @@ -35,11 +33,11 @@ class OcrController extends Controller |
| 35 | ]); | 33 | ]); |
| 36 | 34 | ||
| 37 | // Lưu các field khác vào dt_template | 35 | // Lưu các field khác vào dt_template |
| 38 | - foreach ($request->fields as $field) { | 36 | + foreach ($request->fields as $field => $value) { |
| 39 | DtTemplate::create([ | 37 | DtTemplate::create([ |
| 40 | 'tpl_id' => $mst->id, | 38 | 'tpl_id' => $mst->id, |
| 41 | - 'field_name' => $field['name'], | 39 | + 'field_name' => $field, |
| 42 | - 'field_xy' => $field['xy'], | 40 | + 'field_xy' => is_array($value['coords']) ? implode(',', $value['coords']) : $value['coords'], |
| 43 | ]); | 41 | ]); |
| 44 | } | 42 | } |
| 45 | 43 | ||
| ... | @@ -61,7 +59,7 @@ class OcrController extends Controller | ... | @@ -61,7 +59,7 @@ class OcrController extends Controller |
| 61 | { | 59 | { |
| 62 | try { | 60 | try { |
| 63 | // Lấy template name từ request hoặc mặc định | 61 | // Lấy template name từ request hoặc mặc định |
| 64 | - $templateName = $request->get('template_name', 'nemo'); | 62 | + $templateName = $request->get('template_name', 'A'); |
| 65 | 63 | ||
| 66 | // Giả sử file OCR JSON & ảnh nằm trong storage/app/public/image/ | 64 | // Giả sử file OCR JSON & ảnh nằm trong storage/app/public/image/ |
| 67 | $jsonPath = public_path("image/data_picking_detail_1754967679.json"); | 65 | $jsonPath = public_path("image/data_picking_detail_1754967679.json"); |
| ... | @@ -77,6 +75,7 @@ class OcrController extends Controller | ... | @@ -77,6 +75,7 @@ class OcrController extends Controller |
| 77 | } | 75 | } |
| 78 | 76 | ||
| 79 | $formData = []; | 77 | $formData = []; |
| 78 | + $dataMapping = []; | ||
| 80 | 79 | ||
| 81 | if ($templateName) { | 80 | if ($templateName) { |
| 82 | $mst = MstTemplate::where('tpl_name', $templateName)->first(); | 81 | $mst = MstTemplate::where('tpl_name', $templateName)->first(); |
| ... | @@ -94,6 +93,11 @@ class OcrController extends Controller | ... | @@ -94,6 +93,11 @@ class OcrController extends Controller |
| 94 | 93 | ||
| 95 | // field_name => text | 94 | // field_name => text |
| 96 | $formData[$detail->field_name] = $text; | 95 | $formData[$detail->field_name] = $text; |
| 96 | + | ||
| 97 | + $dataMapping[$detail->field_name] = [ | ||
| 98 | + 'text' => $text, | ||
| 99 | + 'coords' => $coords | ||
| 100 | + ]; | ||
| 97 | } | 101 | } |
| 98 | } else { | 102 | } else { |
| 99 | $formData = [ | 103 | $formData = [ |
| ... | @@ -112,6 +116,7 @@ class OcrController extends Controller | ... | @@ -112,6 +116,7 @@ class OcrController extends Controller |
| 112 | 'ocrData' => $ocrData, | 116 | 'ocrData' => $ocrData, |
| 113 | 'pdfImageUrl' => $imgPath, | 117 | 'pdfImageUrl' => $imgPath, |
| 114 | 'formData' => $formData, | 118 | 'formData' => $formData, |
| 119 | + 'dataMapping' => $dataMapping, | ||
| 115 | 'fieldOptions' => [ | 120 | 'fieldOptions' => [ |
| 116 | [ 'value' => 'template_name', 'label' => 'Tên Mẫu PDF' ], | 121 | [ 'value' => 'template_name', 'label' => 'Tên Mẫu PDF' ], |
| 117 | [ 'value' => 'customer_name', 'label' => 'Tên khách hàng' ], | 122 | [ 'value' => 'customer_name', 'label' => 'Tên khách hàng' ], | ... | ... |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment