From 5627345e7e96848cdd43d4fddf6097e6cfce1347 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Fri, 30 Sep 2022 03:30:19 +0800 Subject: [PATCH] convert 1688 purchase order to po on document upload --- routes/web.php | 41 +++++++---------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/routes/web.php b/routes/web.php index 84980320..1e676c62 100644 --- a/routes/web.php +++ b/routes/web.php @@ -380,46 +380,19 @@ Route::get('/payments/manual', function(){ echo ''; }); + + Route::get('/1688/fix', function(){ $purchaseOrderDocuments = \App\Models\Document::where('document_type', DocumentType::ECOMMERCE_PURCHASE_ORDER)->get(); - $bookings = []; foreach($purchaseOrderDocuments as $document){ - foreach($document->files as $file) { - $parser = new \Smalot\PdfParser\Parser(); - try { - $pdf = $parser->parseFile(Storage::disk('documents')->path($file->file->file_info->original->file)); - } catch (Exception $e) { - continue; - } + $booking = $document->owner; + $booking->status = ApprovalStatus::APPROVED; + $booking->save(); - $text = $pdf->getText(); - if(str_contains($text, '订单详情单')) continue; + $booking->documents()->whereIn('document_type', [DocumentType::INVOICE, DocumentType::PURCHASE_ORDER, DocumentType::DELIVER_ORDER, DocumentType::SUPPLIER_DELIVER_ORDER])->delete(); - $tables = explode('Amount (yuan)', $text); - array_shift($tables); - - 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); - - $adjuster = (count($product) - 7); - $descriptionIndex = 3 + $adjuster; - - $bookings[$document->owner->marking][] = [ - 'description' => str_replace("\n","",$product[$descriptionIndex]), - 'quantity' => (int) str_replace("\n","",$product[$descriptionIndex + 2]), - 'unit_price' => (float) str_replace("\n","",$product[$descriptionIndex + 3]) - ]; - } - } - } -// if($document->owner->status === ApprovalStatus::COMPLETED) continue; -// (App()->make(createPurchaseOrderFor1688OrderProcessor::class))->execute($document->owner); + (App()->make(createPurchaseOrderFor1688OrderProcessor::class))->execute($document->owner); } - dd($bookings); });