<?php
include('../Common/Global.php');
GlobalInit();

/* @var $System System */
$System->Database->query('TRUNCATE TABLE StockItem');
$System->Database->query('TRUNCATE TABLE Product');

$DbResult = $System->Database->select('ProductOld', '*');
while($DbRow = $DbResult->fetch_assoc())
{
  echo($DbRow['Name'].', ');
  
  $System->Database->insert('Product', array('Name' => $DbRow['Name'], 'SellPrice' => $DbRow['Price'],
     'Consumption' => $DbRow['Consumption'], 'UnitOfMeasure' => 1, 'VAT' => 20));
  $ProductId = $System->Database->insert_id;
  $Database->insert('StockItem', array('Stock' => 1, 'Product' => $ProductId, 'Amount' => $DbRow['Count'],
    'Segment' => $DbRow['Segment'], 'TimeEnlistment' => $DbRow['Date'], 'SerialNumber' => $DbRow['DeviceId'],
      'Location' => $DbRow['User'], 'Info' => $DbRow['Info']));
}

?>