convert 1688 purchase order to po on document upload

This commit is contained in:
Omair Saleh
2022-09-30 03:30:19 +08:00
parent 2873a08256
commit 5627345e7e
+7 -34
View File
@@ -380,46 +380,19 @@ Route::get('/payments/manual', function(){
echo '</table>';
});
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);
});