<?php
$movements = DB::table('stock_movements')->get();
foreach ($movements as $m) {
    $change = $m->type === 'out' ? $m->qty : -$m->qty;
    DB::table('warehouse_stock')
        ->where('warehouse_id', $m->warehouse_id)
        ->where('product_id', $m->product_id)
        ->increment('current_stock', $change);
    DB::table('products')
        ->where('id', $m->product_id)
        ->increment('current_stock', $change);
}
DB::statement('SET FOREIGN_KEY_CHECKS=0');
DB::table('sales')->truncate();
DB::table('sale_items')->truncate();
DB::table('purchases')->truncate();
DB::table('purchase_items')->truncate();
DB::table('purchase_trackings')->truncate();
DB::table('stock_movements')->truncate();
DB::statement('SET FOREIGN_KEY_CHECKS=1');
echo "TRANSACTIONS_RESET_AND_STOCKS_REVERTED\n";
