Add default tax rates to check data

This commit is contained in:
Hillel Coren 2017-04-30 16:16:48 +03:00
parent 33c51091b8
commit fa9b68063d

View File

@ -248,6 +248,7 @@ class CheckData extends Command
], ],
'products' => [ 'products' => [
ENTITY_USER, ENTITY_USER,
ENTITY_TAX_RATE,
], ],
'vendors' => [ 'vendors' => [
ENTITY_USER, ENTITY_USER,
@ -262,14 +263,28 @@ class CheckData extends Command
ENTITY_USER, ENTITY_USER,
ENTITY_CLIENT, ENTITY_CLIENT,
], ],
'accounts' => [
ENTITY_TAX_RATE,
]
]; ];
foreach ($tables as $table => $entityTypes) { foreach ($tables as $table => $entityTypes) {
foreach ($entityTypes as $entityType) { foreach ($entityTypes as $entityType) {
$tableName = Utils::pluralizeEntityType($entityType); $tableName = Utils::pluralizeEntityType($entityType);
if ($entityType == ENTITY_TAX_RATE) {
$field = 'default_' . $entityType;
} else {
$field = $entityType;
}
if ($table == 'accounts') {
$accountId = 'id';
} else {
$accountId = 'account_id';
}
$records = DB::table($table) $records = DB::table($table)
->join($tableName, "{$tableName}.id", '=', "{$table}.{$entityType}_id") ->join($tableName, "{$tableName}.id", '=', "{$table}.{$field}_id")
->where("{$table}.account_id", '!=', DB::raw("{$tableName}.account_id")) ->where("{$table}.{$accountId}", '!=', DB::raw("{$tableName}.account_id"))
->get(["{$table}.id"]); ->get(["{$table}.id"]);
if (count($records)) { if (count($records)) {