feat(05-finances-fakturownia-import): complete Fakturownia mapping corrections
Phase 5 complete: - add category mapping edit from operation edit for Fakturownia operations - update current operation category immediately after mapping change - support optional bulk update for matching imported operations - close 05-05 and 05-06 PAUL summaries Co-Authored-By: Codex <noreply@openai.com>
This commit is contained in:
@@ -222,13 +222,21 @@ class FinancesController
|
||||
|
||||
$repo = self::repo();
|
||||
|
||||
$operationId = (int)\S::get( 'operation-id' );
|
||||
$fakturowniaContext = null;
|
||||
|
||||
if ( $operationId > 0 )
|
||||
$fakturowniaContext = $repo -> fakturowniaOperationContext( $operationId );
|
||||
|
||||
return \Tpl::view( 'finances/operation-edit', [
|
||||
'operation' => $repo -> operationDetails( \S::get( 'operation-id' ) ),
|
||||
'category_id' => \S::get( 'category-id' ),
|
||||
'tags' => $repo -> tagsList( \S::get_session( 'finance-group' ) ),
|
||||
'tags_json' => $repo -> tagsJson( \S::get_session( 'finance-group' ) ),
|
||||
'operation_date' => \S::get_session( 'operation-date' ),
|
||||
'clients' => $repo -> clientsList()
|
||||
'clients' => $repo -> clientsList(),
|
||||
'fakturownia_operation_context' => $fakturowniaContext,
|
||||
'fakturownia_categories' => self::prepareCategoryOptions( $repo -> categoriesFlatList() )
|
||||
] );
|
||||
}
|
||||
|
||||
@@ -448,4 +456,53 @@ class FinancesController
|
||||
header( 'Location: /finances/main_view/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function fakturowniaOperationMappingSave()
|
||||
{
|
||||
if ( !self::requireAuth() )
|
||||
return false;
|
||||
|
||||
if ( !\S::csrf_verify() )
|
||||
{
|
||||
\S::alert( 'Nieprawidlowy token bezpieczenstwa. Odswiez strone i sproboj ponownie.' );
|
||||
header( 'Location: /finances/main_view/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
$operationId = (int)\S::get( 'operation_id' );
|
||||
$financeCategoryId = (int)\S::get( 'finance_category_id' );
|
||||
$applyToAll = (int)\S::get( 'apply_to_all' ) === 1;
|
||||
$returnCategoryId = (int)\S::get( 'return_category_id' );
|
||||
|
||||
$repo = self::repo();
|
||||
if ( $operationId <= 0 || $financeCategoryId <= 0 || !$repo -> categoryExists( $financeCategoryId ) )
|
||||
{
|
||||
\S::alert( 'Nie udalo sie zapisac dopasowania. Sprawdz dane formularza.' );
|
||||
header( 'Location: /finances/main_view/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
$context = $repo -> fakturowniaOperationContext( $operationId );
|
||||
if ( !$context )
|
||||
{
|
||||
\S::alert( 'Ta operacja nie jest powiazana z mapowaniem Fakturownia.' );
|
||||
header( 'Location: /finances/operations_list/category-id=' . $returnCategoryId );
|
||||
exit;
|
||||
}
|
||||
|
||||
$importRepo = self::importRepo();
|
||||
$importRepo -> ensureTables();
|
||||
$importRepo -> saveItemMapping( $context['external_item_key'], $context['external_name'], $financeCategoryId );
|
||||
|
||||
$repo -> updateOperationCategory( $operationId, $financeCategoryId );
|
||||
$updatedCount = $repo -> updateFakturowniaOperationsCategoryByItemName( $context['item_name'], $financeCategoryId, $applyToAll );
|
||||
|
||||
if ( $applyToAll )
|
||||
\S::alert( 'Dopasowanie zmienione. Zaktualizowano operacje: ' . (int)$updatedCount . '.' );
|
||||
else
|
||||
\S::alert( 'Dopasowanie zmienione dla tej operacji.' );
|
||||
|
||||
header( 'Location: /finances/operations_list/category-id=' . $financeCategoryId );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user