29 lines
1.5 KiB
PHP
29 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Enums\PurchasingRole;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
/** Called only within ReceiptWorkflow's company-locked transaction. */
|
|
final class ReceiptStockMovement
|
|
{
|
|
public function for(User $actor): \Tempo\Inventory\ReceiptMovementWriter
|
|
{
|
|
$root=base_path('packages/inventory-write/releases/0.1.0');
|
|
if(!is_file($root.'/manifest.json')||!hash_equals('f0b99e591f9a4df135e685f64ceffad77bed259222debe0f34c20f95e3cad800',hash_file('sha256',$root.'/manifest.json')))
|
|
throw new \LogicException('Pacote de recepção incompatível; não executar outro escritor.');
|
|
$manifest=json_decode(file_get_contents($root.'/manifest.json'),true,512,JSON_THROW_ON_ERROR);
|
|
foreach(['bootstrap.php','src/ReceiptMovementWriter.php'] as $file)
|
|
if(!is_file($root.'/'.$file)||!hash_equals($manifest['files'][$file]??'',hash_file('sha256',$root.'/'.$file)))throw new \LogicException('Pacote de recepção alterado.');
|
|
require_once $root.'/bootstrap.php';
|
|
$schema=match(DB::connection()->getDriverName()){
|
|
'pgsql'=>'public','sqlite'=>'main','mysql','mariadb'=>DB::connection()->getDatabaseName(),
|
|
default=>throw new \LogicException('Driver de inventário não suportado.'),
|
|
};
|
|
return new \Tempo\Inventory\ReceiptMovementWriter(DB::connection(),$schema,(int)$actor->tenant_id,(int)$actor->id,
|
|
function () use ($actor) {app(CurrentActor::class)->lock($actor,[PurchasingRole::Warehouse]);});
|
|
}
|
|
}
|