|
@@ -61,24 +61,20 @@ public function formDataCsvFileAjax() {
|
|
|
// parsujemy csv to tablicy
|
|
|
$arrayDataCsv = $this->csvToArray($file, ';', '"', '\n\r');
|
|
|
|
|
|
+
|
|
|
+
|
|
|
$i = 0;
|
|
|
// tworzymy rekordy
|
|
|
foreach ( $arrayDataCsv as $line ) {
|
|
|
//$viewFormCol .= '<div style="margin: 10px 0"><span>'.($i + 1).'. </span>';
|
|
|
|
|
|
- $lenArrayLine = count($line); // sprawdzenie długości tablicy
|
|
|
$viewFormCol .= '<tr>';
|
|
|
- $j = 0;
|
|
|
foreach ( $line as $keyData => $rowData ) {
|
|
|
// utworzenie nagłówków tabeli
|
|
|
if( $i == 0) { $header .= '<td>' . $keyData . '</td>'; }
|
|
|
// utworzenie inputa do edycji
|
|
|
$viewFormCol .= '<td><input type="text" name="item['.$i.']['.$keyData.']" value="'.$rowData .'" class="form-control input-lg" /></td>';
|
|
|
|
|
|
- if ($j == $lenArrayLine - 1) {
|
|
|
- $viewFormCol .= '<td><input type="checkbox" name="item['.$i.'][update]" value="1" /></td>';
|
|
|
- }
|
|
|
- $j++;
|
|
|
}
|
|
|
$viewFormCol .= '</tr>';
|
|
|
|
|
@@ -87,7 +83,8 @@ public function formDataCsvFileAjax() {
|
|
|
|
|
|
}
|
|
|
|
|
|
- $viewFormHtml = '<div id="smad-window-modal" style="overflow-x: scroll;"><form method="POST" id="formDataFromCsv" class="form-horizontal"><table class="table table-bordered table-hover table-striped" height="5"><thead><tr>'. $header .'<td>Zaktualizuj</td></tr></thead><tbody id="smad-csv-data">'. $viewFormCol .'</tbody></table></form></div>';
|
|
|
+ $viewFormCol .= '<div style="margin: 10px 0"><input type="checkbox" name="override" value="1" /> Nadpisz wszystkie rekordy w bazie danych</div';
|
|
|
+ $viewFormHtml = '<div id="smad-window-modal" style="overflow-x: scroll;"><form method="POST" id="formDataFromCsv" class="form-horizontal"><table class="table table-bordered table-hover table-striped" height="5"><thead><tr>'. $header .'</tr></thead><tbody id="smad-csv-data">'. $viewFormCol .'</tbody></table></form></div>';
|
|
|
|
|
|
//return $viewFormHtml;
|
|
|
return [
|
|
@@ -120,6 +117,7 @@ public function formDataCsvFileAjax() {
|
|
|
$formData = V::get('formData', '', $args);
|
|
|
$enumType = V::get('enumType', '', $args);
|
|
|
|
|
|
+ $override = false; // false - nie nadpisujemy danych
|
|
|
$arrayInfo = array();
|
|
|
$arrayInfo['insert'] = 0;
|
|
|
$arrayInfo['update'] = 0;
|
|
@@ -136,20 +134,25 @@ public function formDataCsvFileAjax() {
|
|
|
throw new Exception("Wystapił problem podczas przesyłania danych - brak przesłanych danych.");
|
|
|
}
|
|
|
|
|
|
+ // ustawienie true jeśli wyrabno nadpisanie danych
|
|
|
+ if ( isset($resultArrayFormdata['override']) ) { $override = true; } // aktualizuj rekordy/nadpisz istniejace
|
|
|
+
|
|
|
+
|
|
|
// dodanie/aktualizacjia wpisu
|
|
|
foreach ( $resultArrayFormdata['item'] as $line ) {
|
|
|
- // aktualizuj
|
|
|
- if ( array_key_exists('update', $line) ) {
|
|
|
- $response = $this->updateDataToDb($table, $line);
|
|
|
- } else {
|
|
|
- $response = $this->saveDataToDb($table, $line);
|
|
|
- }
|
|
|
- // tworzymy listę informacji o liczbie nowych/zaktualizowanych/z błedami rekordów
|
|
|
+
|
|
|
+ $response = $this->saveDataToDb($table, $line, $override);
|
|
|
+
|
|
|
+ // tworzymy listę informacji o liczbie nowych/zaktualizowanych/z błedami rekordów
|
|
|
$arrayInfo = $this->responseCountListInfoAboutSaveData($response, $arrayInfo);
|
|
|
}
|
|
|
|
|
|
+ // utworzenie komunikatów
|
|
|
+ if ( isset($arrayInfo['insert']) ) { $textInsert = "Liczba nowych rekordów: (" . $arrayInfo['insert'] . ");"; }
|
|
|
+ if ( isset($arrayInfo['error']) ) { $textError = "Liczba nie zapisanych rekordów (" . $arrayInfo['insert'] . ");"; }
|
|
|
+
|
|
|
return [
|
|
|
- 'msg' => "Zapisano dane. Liczba nowych rekordów: (" . $arrayInfo['insert'] . "); Liczba zaktualizowanych rekordów: (" . $arrayInfo['update'] . ")'; Liczba rekordów nie zapisanych: (" . $arrayInfo['error'] . ")" ,
|
|
|
+ 'msg' => "Zapisano dane. " . $textInsert . " " . $textError ,
|
|
|
'type' => "success",
|
|
|
];
|
|
|
|
|
@@ -161,17 +164,14 @@ public function formDataCsvFileAjax() {
|
|
|
public function responseCountListInfoAboutSaveData($response, $arrayInfo) {
|
|
|
|
|
|
if (!is_array($response)) throw new Exception('Wystapił bład podczas zapisu danych');
|
|
|
-
|
|
|
+ $countData = array();
|
|
|
|
|
|
switch(key($response)) {
|
|
|
case 'insert':
|
|
|
- $arrayInfo['insert'] = $arrayInfo['insert'] + 1;
|
|
|
- break;
|
|
|
- case 'update':
|
|
|
- $arrayInfo['update'] = $arrayInfo['insert'] + 1;
|
|
|
+ $countData['insert'] = $arrayInfo['insert'] + 1;
|
|
|
break;
|
|
|
case 'error':
|
|
|
- $arrayInfo['error'] = $arrayInfo['insert'] + 1;
|
|
|
+ $countData['error'] = $arrayInfo['insert'] + 1;
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -228,35 +228,14 @@ public function formDataCsvFileAjax() {
|
|
|
$response['insert'] = 1;
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
- // aktualizacja
|
|
|
- //$response = $this->updateDataToDb( $table, $arrayData );
|
|
|
+ DBG::log($e);
|
|
|
+ $response['error'] = 1;
|
|
|
}
|
|
|
|
|
|
return $response;
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * Update data in database
|
|
|
- */
|
|
|
- // public function updateDataToDb( $table, $arrayData ) {
|
|
|
- // $response = array();
|
|
|
- //
|
|
|
- // // aktualizacja
|
|
|
- // try {
|
|
|
- // $responseInsert = DB::getPDO()->update($table, 'ID', $primaryKey, $arrayData);
|
|
|
- // $response['update'] = 1;
|
|
|
- //
|
|
|
- // } catch (Exception $e) {
|
|
|
- // DBG::log($e);
|
|
|
- // $response['error'] = 1;
|
|
|
- // }
|
|
|
- //
|
|
|
- // return $response;
|
|
|
- // }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* Get name table by enum
|
|
|
*/
|
|
@@ -477,7 +456,7 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
|
|
|
$idGroup = V::get('filterIdGroup', 0, $_REQUEST, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
|
|
|
if ($idGroup < 0) $idGroup = 0;
|
|
|
|
|
|
- $limit = 5;
|
|
|
+ $limit = 20;
|
|
|
|
|
|
$limitstart = V::get('limitstart', 0, $_REQUEST, 'int');
|
|
|
if ($limitstart < 0) $limitstart = 0;
|
|
@@ -582,36 +561,6 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- // public function fetchKontrahenciAjaxOld($args) {
|
|
|
- // //$id = V::get('ID', 1, $_REQUEST, 'int');
|
|
|
- // $items = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI')->buildQuery([
|
|
|
- // 'cols' => [ // TODO:? propertyName = []
|
|
|
- // 'ID',
|
|
|
- // 'Nazwa_grupy_kapitalowej',
|
|
|
- // 'Pelna_nazwa_kontrahenta',
|
|
|
- // 'NIP',
|
|
|
- // 'KRS',
|
|
|
- // 'REGON',
|
|
|
- // 'Miejscowosc',
|
|
|
- // 'Kod_pocztowy',
|
|
|
- // 'Telefon'
|
|
|
- // ],
|
|
|
- // //'f_ID' => $id,
|
|
|
- // ])->getItems([
|
|
|
- // 'limit' => 10
|
|
|
- // ]);
|
|
|
- //
|
|
|
- // return [
|
|
|
- // 'type' => 'success',
|
|
|
- // 'msg' => 'showKontrahenci',
|
|
|
- // '__req_args' => $_REQUEST,
|
|
|
- // '__args' => $args,
|
|
|
- // 'body' => [
|
|
|
- // 'items' => $items,
|
|
|
- // 'view' => $this->htmlViewFormBiAudit($items, 'KONTRAHENCI')
|
|
|
- // ]
|
|
|
- // ];
|
|
|
- // }
|
|
|
|
|
|
public function showTableKontrahenci($items) {
|
|
|
$view = '<form class="form-horizontal" method="post">
|
|
@@ -776,7 +725,7 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
|
|
|
$idGroup = V::get('filterIdGroup', 0, $_REQUEST, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
|
|
|
if ($idGroup < 0) $idGroup = 0;
|
|
|
|
|
|
- $limit = 2;
|
|
|
+ $limit = 20;
|
|
|
|
|
|
$limitstart = V::get('limitstart', 0, $_REQUEST, 'int');
|
|
|
if ($limitstart < 0) $limitstart = 0;
|
|
@@ -917,7 +866,6 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
|
|
|
// tworzenie grupy pracowników
|
|
|
public function createPracownicyGroupAjaxAction() {
|
|
|
Response::sendTryCatchJson(array($this, 'createPracownicyGroupAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // użyj tej wersji jeśli chcesz wysyłać z przelgądarki JSON-a post-em
|
|
|
- // Response::sendTryCatchJson(array($this, 'createPracownicyGroupAjax'));
|
|
|
}
|
|
|
public function createPracownicyGroupAjax($args) {
|
|
|
$nazwa = V::get('NAZWA', '', $args);
|