<?php
function deleteVat( $iVat ){
	$oDB = DataBase::getInstance( );
	$oDB->deleteInFile( DB_VAT, $iVat, 'iVat' );
}
function saveVat( $aForm ){
	$oDB = DataBase::getInstance( );
	if( isset( $aForm['iVat'] ) && is_numeric( $aForm['iVat'] ) ){
		$sParam = 'iVat';
	} else{
		$sParam = null;
	}
	$aForm = changeMassTxt( $aForm, '' );
	$aForm['fVatValue'] = sscanf( $aForm['sVatValue'], '%f' );
	$aForm['fVatValue'] = $aForm['fVatValue'][0];
	$aForm['iVat'] = $oDB->save( DB_VAT, $aForm, $sParam, 'sort' );
	return $aForm['iVat'];
}
function throwVatIdByValue( $fVatValue ){
	$oDB = DataBase::getInstance( );
	$aData = $oDB->throwData( DB_VAT, $fVatValue, 'fVatValue' );
	return $aData['iVat'];
}
function throwVats( ){
	$oDB = DataBase::getInstance( );
	$aVats = $oDB->throwFileArray( DB_VAT );
	if( is_array( $aVats ) ) foreach( $aVats as &$aVat ) $aVat['sVatValue'] = sprintf( '%01.2f', $aVat['fVatValue'] );
	return $aVats;
}
function throwVatsForSelect( ){
	$oDB = DataBase::getInstance( );
	return $oDB->throwFileArraySmall( DB_VAT, 'iVat', 'sVatText' );
}
?>