if ($prm==`TEFAPtmpHist`)
{
  $CaseId=$_SESSION[`CaseId`];
  $UserId=$_SESSION[`UserId`];
  $ProjectId=$_SESSION[`ProjectId`];

  $Instance=ShowQueryResultScalar(~select rUnique from Responses where CaseID=`$CaseId` and rInstance=`Receipt` and ProjectId=`$ProjectId`~);

  if ($Instance==~~)
     {
        ExecuteSQL(~insert into Responses (CaseID,qID,uID,rInstance,ProjectId) select `$CaseId`,`TEFAPdate`,`$UserId`,`Receipt`,`$ProjectId`~);
        $Instance=ShowQueryResultScalar(~select rUnique from Responses where CaseID=`$CaseId` and rInstance=`Receipt` and ProjectId=`$ProjectId`~);
        ExecuteSQL(~update Responses set rInstance=`$Instance` where rUnique=`$Instance`~);
     }
  $_SESSION[`Instance`]=$Instance;

  SetInstanceCaseForm($Instance,$CaseId,`TEFAPreceipt`);
}

$stat=1;