/** * Calculate the checksum of the file * As defined in the UOB documentation * @return String */ public function getCheckSum() { $headers = []; $checksum = 0; $hashcode_index = 1; $record_no = 1; $lines = []; $batch_header = new UOBBatchHeader($this->beneficiaries, $this->configKey); $lines[] = $batch_header->getLine(); foreach ($this->beneficiaries as $beneficiary) { $beneficiary_lines = UOBBeneficiaryFactory::create($beneficiary, $this->configKey); $lines[] = collect($beneficiary_lines->getLines())->first(); } $batch_trailer = new UOBBatchTrailer($this->beneficiaries, $this->configKey); $lines[] = $batch_trailer->getLine(); foreach ($lines as $line) { // printf("\nLine with value %s has length of %d", substr($line -> getString(),0, 100), strlen($line -> getString())); $string = $line->getString(); $record_no++; $column_no = 1; for ($i = 0; $i < 900; $i++) { $byte_code = ord($string[$i]); if ($hashcode_index > 23) { $hashcode_index = 1; } $checksum += $record_no + ($record_no + $column_no) * $byte_code * $this->getHashCodeArray($hashcode_index); $hashcode_index++; $column_no++; } } return $checksum; }