1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Fixes for string delimiters

This commit is contained in:
David Bomba 2023-07-26 14:44:39 +10:00
parent 67c34f80a9
commit 84885837ab
2 changed files with 13 additions and 5 deletions

View File

@ -170,20 +170,27 @@ class ImportController extends Controller
return $data;
}
public function detectDelimiter($csvfile)
/**
* Returns the best delimiter
*
* @param string $csvfile
* @return string
*/
public function detectDelimiter($csvfile): string
{
$delimiters = [',', '.', ';'];
$bestDelimiter = ' ';
$count = 0;
foreach ($delimiters as $delimiter) {
if (substr_count(strstr($csvfile, "\n", true), $delimiter) >= $count) {
$count = substr_count($csvfile, $delimiter);
$bestDelimiter = $delimiter;
$count = substr_count(strstr($csvfile, "\n", true), $delimiter);
$bestDelimiter = $delimiter;
}
}
return $bestDelimiter;
}
}

View File

@ -28,9 +28,10 @@ class PreImportRequest extends Request
public function rules()
{
return [
'files.*' => 'file|mimes:csv,txt',
'files.*' => 'file|mimetypes:text/csv,text/plain,application/octet-stream',
'files' => 'required|array|min:1|max:6',
'import_type' => 'required',
];
}
}