<?php

class ProductsUnits extends Window
{
    protected $template = 'window/products.units.tpl';
    protected $tableName = 'products_units';
    protected $nameField = 'short_name';

    public function getData()
    {
        $data = parent::getData();

        if (getVal('Submit')) {
            if (!empty($data['pieces_in_package']) && $data['pieces_precision'] > 1) {
                $data['pieces_precision'] = $data['pieces_in_package'];
            }

            if (empty($data['short_name_admin'])) {
                $data['short_name_admin'] = $data['short_name'];
            }
        }

        return $data;
    }

    public function handleDelete()
    {
        if ($this->getID() == 1) {
            $this->returnError('Základní jednotku nelze smazat!');
        }

        parent::handleDelete();
    }
}

return ProductsUnits::class;
