/**
  * 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;
 }
 /**
  * @param Collection of entries to be passed into the adapter
  * @param String The config key to read from
  * @param Int The sequence number for file name generation. If multiple files are generated in a day, this number should be incremented.
  * @return COSUploadProcessor
  */
 public static function create($beneficiaries, $config_key, $sequence_number = 1)
 {
     $config = new Repository(config($config_key));
     $adapter_class = $config['beneficiary_adapter'];
     $beneficiaries = $beneficiaries->map(function ($payment) use($adapter_class) {
         return new $adapter_class($payment);
     })->toArray();
     $beneficiary_lines = collect($beneficiaries)->map(function (BeneficiaryAdapterInterface $beneficiary) use($config_key) {
         return UOBBeneficiaryFactory::create($beneficiary, $config_key);
     })->toArray();
     $cos = new COSUploadProcessor($beneficiaries, $config_key);
     $file_name = static::getFileName($sequence_number);
     $cos->setFileName($file_name);
     $cos->setFileExtension('txt');
     $file_header = new UOBFileHeader($beneficiaries, $config_key);
     $file_header->setFileName($file_name);
     //UOB uses fixed length strings, so no column delimiters are needed
     $file_header->setColumnDelimiter("");
     $batch_header = new UOBBatchHeader($beneficiaries, $config_key);
     $batch_header->setColumnDelimiter("");
     $batch_trailer = new UOBBatchTrailer($beneficiaries, $config_key);
     $batch_trailer->setColumnDelimiter("");
     $cos->setFileHeader($file_header);
     $cos->setBatchHeader($batch_header);
     $cos->setBatchTrailer($batch_trailer);
     $cos->setBeneficiaryLines($beneficiary_lines);
     $cos->setIdentifier($file_header->getCheckSum());
     return $cos;
 }