|
@@ -66,15 +66,19 @@ public function formDataCsvFileAjax() {
|
|
|
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 .'" /></td>';
|
|
|
-
|
|
|
- if (end($rowData )) { $viewFormCol .= '<td><input type="checkbox" name="item['.$i.']['.$keyData.']" value="'.$rowData.'" /></td>'; }
|
|
|
+ $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>';
|
|
|
|
|
@@ -83,12 +87,7 @@ public function formDataCsvFileAjax() {
|
|
|
|
|
|
}
|
|
|
|
|
|
- $viewFormHtml = '<div id="smad-window-modal" style="overflow-x: scroll;"><form method="POST" id="formDataFromCsv" >';
|
|
|
- $viewFormHtml = ' <thead><tr>'. $header .'
|
|
|
- <td>Zaktualizuj</td>
|
|
|
- </tr>
|
|
|
- </thead>';
|
|
|
- $viewFormHtml .= '<tbody id="smad-csv-data">'. $viewFormCol .'</tbody></table></form></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 .'<td>Zaktualizuj</td></tr></thead><tbody id="smad-csv-data">'. $viewFormCol .'</tbody></table></form></div>';
|
|
|
|
|
|
//return $viewFormHtml;
|
|
|
return [
|
|
@@ -117,54 +116,67 @@ public function formDataCsvFileAjax() {
|
|
|
* Funkcja ajax do zapisania danych z przesłanego formularza z parsowanego CSV
|
|
|
*/
|
|
|
public function saveFormCsvFileAjax($args) {
|
|
|
+ //dane z formularza
|
|
|
$formData = V::get('formData', '', $args);
|
|
|
+ $enumType = V::get('enumType', '', $args);
|
|
|
+
|
|
|
+ $arrayInfo = array();
|
|
|
+ $arrayInfo['insert'] = 0;
|
|
|
+ $arrayInfo['update'] = 0;
|
|
|
+ $arrayInfo['error'] = 0;
|
|
|
+
|
|
|
+ // pobranie nazwy tabeli z db
|
|
|
+ $table = $this->getNameTableByEnum( strtoupper($enumType) );
|
|
|
|
|
|
+ if ( $table == null ) throw new Exception('Błąd zapisu. Tabela w db nie istnieje');
|
|
|
// unserialize data from serialize in javascript
|
|
|
parse_str($formData, $resultArrayFormdata);
|
|
|
- //$formData = V::get('formData', '', $_REQUEST, '');
|
|
|
- //print_r($resultArrayFormdata);
|
|
|
|
|
|
if ( count($resultArrayFormdata['item']) == 0) {
|
|
|
throw new Exception("Wystapił problem podczas przesyłania danych - brak przesłanych danych.");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ // dodanie/aktualizacjia wpisu
|
|
|
foreach ( $resultArrayFormdata['item'] as $line ) {
|
|
|
-
|
|
|
- $insertData = array();
|
|
|
- $insertTemp = array();
|
|
|
- print_r($line);
|
|
|
- // foreach ( $line as $keyData => $rowData) {
|
|
|
- //
|
|
|
- // $insertTemp[$keyData] = $rowData;
|
|
|
- // // print $keyData ."--". $rowData . "<br />";
|
|
|
- // $insertData = array_merge($insertTemp, $insertData);
|
|
|
- //
|
|
|
- // }
|
|
|
-
|
|
|
- // $this->saveDataToDb($table, $arrayData);
|
|
|
+ // 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
|
|
|
+ $arrayInfo = $this->responseCountListInfoAboutSaveData($response, $arrayInfo);
|
|
|
}
|
|
|
- //print_r($insertData);
|
|
|
- exit;
|
|
|
|
|
|
-exit;
|
|
|
- try {
|
|
|
+ return [
|
|
|
+ 'msg' => "Zapisano dane. Liczba nowych rekordów: (" . $arrayInfo['insert'] . "); Liczba zaktualizowanych rekordów: (" . $arrayInfo['update'] . ")'; Liczba rekordów nie zapisanych: (" . $arrayInfo['error'] . ")" ,
|
|
|
+ 'type' => "success",
|
|
|
+ ];
|
|
|
|
|
|
- $responseInsert = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
|
|
|
- 'Pelna_nazwa_kontrahenta' => 'Teste NAZWY FIRMY ',
|
|
|
- 'Skrocona_Nazwa_Kontrahenta' => 'TEST NAZWY SKR.'
|
|
|
- ]);
|
|
|
+ }
|
|
|
|
|
|
- } catch (Exception $e) {
|
|
|
+ /**
|
|
|
+ * Count list
|
|
|
+ */
|
|
|
+ public function responseCountListInfoAboutSaveData($response, $arrayInfo) {
|
|
|
|
|
|
- print_r($e);
|
|
|
- }
|
|
|
+ if (!is_array($response)) throw new Exception('Wystapił bład podczas zapisu danych');
|
|
|
|
|
|
|
|
|
- //print_r($formData);
|
|
|
- //todo: dane do zapisania z formularza
|
|
|
- }
|
|
|
+ switch(key($response)) {
|
|
|
+ case 'insert':
|
|
|
+ $arrayInfo['insert'] = $arrayInfo['insert'] + 1;
|
|
|
+ break;
|
|
|
+ case 'update':
|
|
|
+ $arrayInfo['update'] = $arrayInfo['insert'] + 1;
|
|
|
+ break;
|
|
|
+ case 'error':
|
|
|
+ $arrayInfo['error'] = $arrayInfo['insert'] + 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
+ return $countData;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Function parse csv to array
|
|
@@ -188,17 +200,66 @@ exit;
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
- public function saveDataToDb($table, $arrayData ) {
|
|
|
+ /**
|
|
|
+ * Save data in database
|
|
|
+ */
|
|
|
+ public function saveDataToDb( $table, $arrayData ) {
|
|
|
+ $response = array();
|
|
|
|
|
|
try {
|
|
|
- $responseInsert = DB::getPDO()->insert($table, $arrayData);
|
|
|
+ // dodanie nowego rekordu
|
|
|
+ $responseInsert = DB::getPDO()->insert($table, $arrayData);
|
|
|
+ $response['insert'] = 1;
|
|
|
+
|
|
|
} catch (Exception $e) {
|
|
|
- print_r($e);
|
|
|
+ // aktualizacja
|
|
|
+ $response = $this->updateDataToDb( $table, $arrayData );
|
|
|
}
|
|
|
+
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Update data in database
|
|
|
+ */
|
|
|
+ public function updateDataToDb( $table, $arrayData ) {
|
|
|
+ $response = array();
|
|
|
+
|
|
|
+ // aktualizacja
|
|
|
+ try {
|
|
|
+ $responseInsert = DB::getPDO()->update($table, $arrayData);
|
|
|
+ $response['update'] = 1;
|
|
|
+
|
|
|
+ } catch (Exception $e) {
|
|
|
+ print_r($e);
|
|
|
+ $response['error'] = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $response;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * Get name table by enum
|
|
|
+ */
|
|
|
+ public function getNameTableByEnum($type) {
|
|
|
+
|
|
|
+ $nameTable = null;
|
|
|
+ switch ($type) {
|
|
|
+ case 'PRACOWNICY':
|
|
|
+ $nameTable = 'BI_audit_ENERGA_RUM_KONTRAHENCI';
|
|
|
+ break;
|
|
|
+ case 'KONTRAHENCI':
|
|
|
+ $nameTable = 'BI_audit_ENERGA_PRACOWNICY';
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $nameTable;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
public function fetchEnergaRumKontrahenciPowiazaniaAjaxAction() {
|
|
|
Response::sendTryCatchJson(array($this, 'fetchEnergaRumKontrahenciPowiazaniaAjax')); // , $args = 'JSON_FROM_REQUEST_BODY');
|
|
@@ -1053,7 +1114,7 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
|
|
|
</div>';
|
|
|
|
|
|
$formAddNewData ='
|
|
|
- <li><a title="IMPORT KONTRAHENCI" onClick="showViewUploadFile(event, \'Import kontrahentów\' )" class="btn btn-info">IMPORT KONTRAHENCI</a></li>
|
|
|
+ <li><a title="IMPORT KONTRAHENCI" onClick="showViewUploadFile(event, \'Import kontrahentów\', \'kontrahenci\' )" class="btn btn-info">IMPORT KONTRAHENCI</a></li>
|
|
|
<!--<li><a href="#" title="DODAJ KONTRAHENCI" class="btn btn-info">+ DODAJ KONTRAHENCI</a></li>-->'; //todo: dodać obsługe doddawania kontrahentow
|
|
|
|
|
|
$showButtonNextStep = '<button type="button" class="btn btn-primary" onClick="generateBiAuditRaport(event)" id="button-generate-reaport">SZUKAJ POWIĄZAŃ</button>';
|
|
@@ -1075,7 +1136,7 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
|
|
|
</div>';
|
|
|
|
|
|
$formAddNewData ='
|
|
|
- <li><a href="#" title="IMPORT PRACOWNIKÓW" class="btn btn-info">IMPORT PRACOWNIKÓW</a></li>
|
|
|
+ <li><a title="IMPORT PRACOWNIKÓW" onClick="showViewUploadFile(event, \'Import pracowników\', \'pracownicy\' )" class="btn btn-info">IMPORT PRACOWNIKÓW</a></li>
|
|
|
<!--<li><a href="#" title="DODAJ PRACOWNIKÓW" class="btn btn-info" >+ DODAJ PRACOWNIKÓW</a></li>-->'; //todo: dodać obsługe doddawania pracownikow
|
|
|
|
|
|
$showButtonNextStep = '<a href="index.php?_route=UrlAction_Bocian#KONTRAHENCI" title="DODAJ DO ANALIZY" class="btn btn-primary">DODAJ DO ANALIZY</a>';
|