From 7f51142b6d030c3d7ea8ebf82b8c1caa34750d04 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Thu, 29 Sep 2022 03:23:09 +0800 Subject: [PATCH] convert 1688 purchase order to po --- routes/web.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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);