<?php
// Contract.php
// Copyright P.Kassel, M.Seliger, G.Trietsch, all Rights Reserved
namespace Docuform\Api\Server;use Docuform\Api\TableMapper;use Docuform\Database\DbDatabase;use Docuform\Database\DbSQL;use Docuform\Api\Exception\ApiHttpForbiddenException;use Docuform\Lib\ApiDateTime;class Contract extends TableMapper{public $id;public function getColumnMappings():array{return[['name'=>'ContractId','type'=>DbSQL::cst_intornull,'alias'=>'id'],['name'=>'UserId','type'=>DbSQL::cst_intornull,'alias'=>'customerId'],['name'=>'ContractNo','type'=>DbSQL::cst_text,'alias'=>'number'],['name'=>'Name','type'=>DbSQL::cst_text,'alias'=>'name'],['name'=>'IsActive','type'=>DbSQL::cst_intornull,'alias'=>'isActive'],['name'=>'IsDefault','type'=>DbSQL::cst_intornull,'alias'=>'isDefault'],['name'=>'ContractStart','type'=>DbSQL::cst_date,'alias'=>'start'],['name'=>'OrderOptId','type'=>DbSQL::cst_intornull,'alias'=>'optimizationId','visible'=>false],['name'=>'ThresholdId','type'=>DbSQL::cst_intornull,'alias'=>'thresholdId','visible'=>false],['name'=>'AlertId','type'=>DbSQL::cst_intornull,'alias'=>'alertId','visible'=>false],['name'=>'sNote','type'=>DbSQL::cst_text,'alias'=>'note'],['name'=>'Info1','type'=>DbSQL::cst_text,'alias'=>['information'=>0]],['name'=>'Info2','type'=>DbSQL::cst_text,'alias'=>['information'=>1]],['name'=>'Info3','type'=>DbSQL::cst_text,'alias'=>['information'=>2]],['name'=>'MonoFreePages','type'=>DbSQL::cst_intornull,'alias'=>['billing'=>'freeMonoPages']],['name'=>'PageChargeMono','type'=>DbSQL::cst_intornull,'alias'=>['billing'=>'costPerMonoPage']],['name'=>'ColorFreePages','type'=>DbSQL::cst_intornull,'alias'=>['billing'=>'freeColorPages']],['name'=>'PageChargeColor','type'=>DbSQL::cst_intornull,'alias'=>['billing'=>'costPerColorPage']],['name'=>'ChargeMonths','type'=>DbSQL::cst_intornull,'alias'=>['billing'=>'billingMonths']],['name'=>'Created','type'=>DbSQL::cst_date,'alias'=>'created'],['name'=>'CreatedBy','type'=>DbSQL::cst_text,'alias'=>'createdBy'],['name'=>'Modified','type'=>DbSQL::cst_date,'alias'=>'modified'],['name'=>'ModifiedBy','type'=>DbSQL::cst_text,'alias'=>'modifiedBy']];}public function getParameterConstraints(string $method):array{return[];}public function create($payload):void{$user=$this->getContainer()->get('user');if($user->isReadOnly){throw new ApiHttpForbiddenException;}$serverApi=$this->getContainer()->get('RestApi');$request=$serverApi->getRequest();$this->checkSetParameters($request,$payload);$database=$this->getContainer()->get('database');$sql=new DbSQL($database);$this->id=DbDatabase::generateUDBID($database);$this->sqlAppendColumnMapping($sql,'id',$this->id);$this->sqlAppendColumnMapping($sql,'customerId',$payload['customerId']);$this->sqlAppendColumnMapping($sql,'number',sprintf('%06d-1',$payload['customerId']));$this->sqlAppendColumnMapping($sql,'name',$serverApi->localize('contract_name_default'));$this->sqlAppendColumnMapping($sql,'isActive',1);$this->sqlAppendColumnMapping($sql,'isDefault',1);$dtStart=new ApiDateTime();$dtStart->setLocalTime(0,0,0);$this->sqlAppendColumnMapping($sql,'start',$database->DbDate($dtStart));$this->sqlAppendColumnMapping($sql,'created',$database->NowDb());$this->sqlAppendColumnMapping($sql,'createdBy',$user->name);$database->Execute('INSERT INTO ACCCONTRACTS '.$sql->getInsertValues(),$sql->getParams());}}