<?php

include_once "../class/Config.php";
include_once "../class/Asset.php";
include_once "../class/CheckAsset.php";
$delAsset = new Asset();
$delChkAsset = new CheckAsset();
$db = new Config();
$delId = $_GET["assetId"];
//$delId = "12";
$delAsset->setAssetId($delId);
$arr = $delAsset->getAssetById();
$res = $db->fetch_array($arr);
$DelChkType = $res['assetTypeId'];
$DelChkGroup = $res['assetGroupId'];
$DelChkAsset = $res['assetId'];
$delChkAsset->setAssetTypeId($DelChkType);
$delChkAsset->setAssetGroupId($DelChkGroup);
$delChkAsset->setAssetId($DelChkAsset);
$delChkAsset->delCheckAsset();
$delAsset->delAsset();
$yearD = substr($assetAddDate, 6, 4);
if ($month >= 10 && $month <= 12) {
    $yearD++;
}
$assYear = $yearD + 543;
$year = $text - 543;
$dateType = $dateM . "" . $year;
$datetime = DateTime::createFromFormat('d/m/yy', $dateType);
$dateT = $datetime->format('Y-m-d');
if ($assetNum == "") {
    $addAsset->setValues($assetCode, $assetName, $assetPrice, $assetTypeId, $assetGroupId, $yearD, $assetLocation, $dateT, $remark, $userId);
    $addAsset->addAsset();
    $arr = $addAsset->getAssetIdToCheck($assetTypeId, $assetGroupId, $assetCode);
    $result = $db->fetch_array($arr);
    $addCheck->setAssetTypeId($assetTypeId);
    $addCheck->setAssetGroupId($assetGroupId);
    $addCheck->setAssetId($result['assetId']);
    $addCheck->setAssetYear($yearD);
    $addCheck->setAssetAddDate($dateT);
    $addCheck->setUserId($userId);
    $addCheck->addCheckAsset();
} else {
    if ($assetNum > 1) {
        $i = 1;
        $gens = $assetCode;
        $gen = $gens - 1;
        while ($i <= $assetNum) {
            $genCode = str_pad($gen + 1, 3, "0", STR_PAD_LEFT);
            $addAsset->setValues($genCode, $assetName, $assetPrice, $assetTypeId, $assetGroupId, $yearD, $assetLocation, $dateT, $remark, $userId);
            $addAsset->addAsset();
            $arr = $addAsset->getAssetIdToCheck($assetTypeId, $assetGroupId, $genCode);