diff --git a/routes/web.php b/routes/web.php index fb3dc155..e23afe64 100644 --- a/routes/web.php +++ b/routes/web.php @@ -384,7 +384,29 @@ Route::get('/1688/fix', function(){ foreach($purchaseOrderDocuments as $document){ foreach($document->files as $file) { + $parser = new \Smalot\PdfParser\Parser(); + $pdf = $parser->parseFile($file>file->file_info->original->file); + $text = $pdf->getText(); + $tables = explode('Amount (yuan)', $text); + array_shift($tables); + + $purchaseOrder = []; + foreach ($tables as $table){ + $products = preg_split('/(yuan\/|yuan \/)/', str_replace("\r\n","",$table)); + + array_pop($products); + foreach ($products as $product){ + $product = preg_split('/[\t]/',$product); + $type = count($product) === 10 ? 2 : 1; + $purchaseOrder[] = [ + 'description' => str_replace("\n","",$product[$type === 2 ? 6 : 3]), + 'quantity' => (int) str_replace("\n","",$product[$type === 2 ? 8 : 5]), + 'unit_price' => (float) str_replace("\n","",$product[$type === 2 ? 9 : 6]) + ]; + } + } + dd($purchaseOrder); } // if($document->owner->status === ApprovalStatus::COMPLETED) continue; // (App()->make(createPurchaseOrderFor1688OrderProcessor::class))->execute($document->owner);