質問編集履歴
3
正解
test
CHANGED
File without changes
|
test
CHANGED
@@ -126,7 +126,95 @@
|
|
126
126
|
|
127
127
|
{
|
128
128
|
|
129
|
+
|
130
|
+
|
131
|
+
$test = storage_path('app/public/study05.csv');
|
132
|
+
|
133
|
+
$pf = fopen($test, 'r');
|
134
|
+
|
135
|
+
$test1 = fopen('public/storage/test.csv', 'w');
|
136
|
+
|
137
|
+
if ($pf === false) {
|
138
|
+
|
139
|
+
echo "ファイルオープン時に失敗したので処理終了します。" . PHP_EOL;
|
140
|
+
|
141
|
+
exit;
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
$now = Carbon::today();
|
148
|
+
|
149
|
+
$out_year = substr($now, 0, 4);
|
150
|
+
|
151
|
+
$out_month = substr($now, 5, 2);
|
152
|
+
|
153
|
+
$i = 0;
|
154
|
+
|
155
|
+
$old_year = $out_year -2;
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
while ($line1 = fgets($pf)) {
|
160
|
+
|
161
|
+
$i++;
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
// カンマ分割
|
168
|
+
|
169
|
+
$test_field = explode(',', $line1);
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
// 日付分割
|
174
|
+
|
175
|
+
$test_date = explode('/', $test_field[0]);
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
$test2 = $test_field[0].','.$test_field[1].','.$test_field[2];
|
184
|
+
|
185
|
+
$test3 = mb_convert_encoding("$test2", "SJIS-win");
|
186
|
+
|
187
|
+
// fwrite($test1, $test3);
|
188
|
+
|
189
|
+
if($test_date[0] < $out_year || $test_date[1] <= $out_month){
|
190
|
+
|
191
|
+
fwrite($test1, $test3);
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
fclose($pf);
|
200
|
+
|
201
|
+
fclose($test1);
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
129
|
-
$filename = storage_path('app/public/st
|
217
|
+
$filename = storage_path('app/public/test.csv');
|
130
218
|
|
131
219
|
$fp = fopen($filename, 'r');
|
132
220
|
|
2
インデント調整
test
CHANGED
File without changes
|
test
CHANGED
@@ -134,262 +134,262 @@
|
|
134
134
|
|
135
135
|
if ($fp === false) {
|
136
136
|
|
137
|
-
echo "ファイルオープン時に失敗したので処理終了します。".PHP_EOL;
|
137
|
+
echo "ファイルオープン時に失敗したので処理終了します。" . PHP_EOL;
|
138
|
-
|
138
|
+
|
139
|
-
exit;
|
139
|
+
exit;
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
$is_error = false;
|
146
|
+
|
147
|
+
$break_key_year = '';
|
148
|
+
|
149
|
+
$break_key_month = '';
|
150
|
+
|
151
|
+
$i = 0;
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
$nyukin = 0; // 入金
|
156
|
+
|
157
|
+
$syukin = 0; // 出金
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
$a = 0;
|
162
|
+
|
163
|
+
$b = 0;
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
while ($line = fgets($fp)) {
|
168
|
+
|
169
|
+
$i++;
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
// ファイル読込終了判定
|
174
|
+
|
175
|
+
if (feof($fp)) {
|
176
|
+
|
177
|
+
break;
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
// ファイル読込エラー判定
|
184
|
+
|
185
|
+
if ($line === false) {
|
186
|
+
|
187
|
+
echo "ファイル読込時に失敗したので処理終了します。" . PHP_EOL;
|
188
|
+
|
189
|
+
$is_error = true;
|
190
|
+
|
191
|
+
break;
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
// カンマ分割
|
198
|
+
|
199
|
+
$work_field = explode(',', $line);
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
// 日付分割
|
204
|
+
|
205
|
+
$work_date = explode('/', $work_field[0]);
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
$stock_nyukin[] = $work_field[1];
|
210
|
+
|
211
|
+
$total_nyukin = array_sum($stock_nyukin);
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
$stock_syukin[] = $work_field[2];
|
216
|
+
|
217
|
+
$total_syukin = array_sum($stock_syukin);
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
$now = Carbon::today();
|
222
|
+
|
223
|
+
$out_year = substr($now, 0, 4);
|
224
|
+
|
225
|
+
$out_month = substr($now, 5, 2);
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
// if($break_key_year = $out_year && $break_key_month = $out_month){
|
230
|
+
|
231
|
+
// break;
|
232
|
+
|
233
|
+
// }
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
// if($work_date[0] = $out_year && $work_date[1] = $out_month){
|
238
|
+
|
239
|
+
// break;
|
240
|
+
|
241
|
+
// }
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
if (($break_key_year != $work_date[0]) || ($break_key_month != $work_date[1])) {
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
if ($i != 1) {
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
echo $break_key_year . '年' . $break_key_month . '月' . '入金集計:' . $nyukin . '、出金合計:' . $syukin . PHP_EOL;
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
$stock_year_nyukin[] = $nyukin;
|
258
|
+
|
259
|
+
$year_nyukin = array_sum($stock_year_nyukin);
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
$stock_year_syukin[] = $syukin;
|
264
|
+
|
265
|
+
$year_syukin = array_sum($stock_year_syukin);
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
$nyukin = 0;
|
270
|
+
|
271
|
+
$syukin = 0;
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
if (($break_key_year != $work_date[0])) {
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
echo '---------------------------------------------------' . PHP_EOL;
|
280
|
+
|
281
|
+
echo $break_key_year . '年:' . '入金合計:' . $year_nyukin . '、出金合計:' . $year_syukin . PHP_EOL;
|
282
|
+
|
283
|
+
echo PHP_EOL;
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
$keep1 = $year_nyukin;
|
288
|
+
|
289
|
+
$keep2 = $year_syukin;
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
$break_key_year = $work_date[0];
|
302
|
+
|
303
|
+
$break_key_month = $work_date[1];
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
$w_nyukin = trim($work_field[1]);
|
312
|
+
|
313
|
+
$w_syukin = trim($work_field[2]);
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
if (empty($w_nyukin) && empty($w_syukin)) {
|
318
|
+
|
319
|
+
echo $i . '行目のデータがありませんのでデータをスキップします。' . PHP_EOL;
|
320
|
+
|
321
|
+
continue;
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
//通常処理
|
328
|
+
|
329
|
+
if (empty($w_nyukin)) {
|
330
|
+
|
331
|
+
$syukin += $w_syukin;
|
332
|
+
|
333
|
+
} else {
|
334
|
+
|
335
|
+
$nyukin += $w_nyukin;
|
336
|
+
|
337
|
+
}
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
// if($break_key_year = $out_year && $break_key_month = $out_month){
|
342
|
+
|
343
|
+
// break;
|
344
|
+
|
345
|
+
// }
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
}
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
$a = $total_nyukin - $keep1;
|
354
|
+
|
355
|
+
$b = $total_syukin - $keep2;
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
echo $break_key_year . '年' . $break_key_month . '月' . '入金集計:' . $nyukin . '、出金合計:' . $syukin . PHP_EOL;
|
360
|
+
|
361
|
+
echo '---------------------------------------------------' . PHP_EOL;
|
362
|
+
|
363
|
+
echo $break_key_year . '年:' . '入金合計:' . $a . '、出金合計:' . $b . PHP_EOL;
|
364
|
+
|
365
|
+
echo PHP_EOL;
|
366
|
+
|
367
|
+
echo '=========================================' . PHP_EOL;
|
368
|
+
|
369
|
+
echo 'トータル:' . '入金合計:' . $total_nyukin . '、出金合計:' . $total_syukin . PHP_EOL;
|
370
|
+
|
371
|
+
fclose($fp);
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
if ($i == 0) {
|
376
|
+
|
377
|
+
echo "指定されたファイルは空ファイルでした。" . PHP_EOL;
|
378
|
+
|
379
|
+
}
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
return 0;
|
140
384
|
|
141
385
|
}
|
142
386
|
|
143
387
|
|
144
388
|
|
145
|
-
$is_error = false;
|
146
|
-
|
147
|
-
$break_key_year = '';
|
148
|
-
|
149
|
-
$break_key_month = '';
|
150
|
-
|
151
|
-
$i=0;
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
$nyukin = 0; // 入金
|
156
|
-
|
157
|
-
$syukin = 0; // 出金
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
$a =0;
|
162
|
-
|
163
|
-
$b =0;
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
while ($line = fgets($fp)) {
|
168
|
-
|
169
|
-
$i++;
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
// ファイル読込終了判定
|
174
|
-
|
175
|
-
if (feof($fp)) {
|
176
|
-
|
177
|
-
break;
|
178
|
-
|
179
|
-
}
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
// ファイル読込エラー判定
|
184
|
-
|
185
|
-
if ($line === false) {
|
186
|
-
|
187
|
-
echo "ファイル読込時に失敗したので処理終了します。".PHP_EOL;
|
188
|
-
|
189
|
-
$is_error = true;
|
190
|
-
|
191
|
-
break;
|
192
|
-
|
193
|
-
}
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
// カンマ分割
|
198
|
-
|
199
|
-
$work_field = explode(',', $line);
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
// 日付分割
|
204
|
-
|
205
|
-
$work_date = explode('/', $work_field[0]);
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
$stock_nyukin[] = $work_field[1];
|
210
|
-
|
211
|
-
$total_nyukin = array_sum($stock_nyukin);
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
$stock_syukin[] = $work_field[2];
|
216
|
-
|
217
|
-
$total_syukin = array_sum($stock_syukin);
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
$now = Carbon::today();
|
222
|
-
|
223
|
-
$out_year = substr($now,0,4);
|
224
|
-
|
225
|
-
$out_month = substr($now,5,2);
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
if (($break_key_year != $work_date[0]) || ($break_key_month != $work_date[1])) {
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
if($break_key_year = $out_year && $break_key_month > $out_month){
|
236
|
-
|
237
|
-
break;
|
238
|
-
|
239
|
-
}
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
if ($i != 1) {
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
echo $break_key_year.'年'.$break_key_month.'月'.'入金集計:'.$nyukin.'、出金合計:'.$syukin.PHP_EOL;
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
$stock_year_nyukin[] = $nyukin;
|
254
|
-
|
255
|
-
$year_nyukin = array_sum($stock_year_nyukin);
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
$stock_year_syukin[] = $syukin;
|
260
|
-
|
261
|
-
$year_syukin = array_sum($stock_year_syukin);
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
$nyukin = 0;
|
266
|
-
|
267
|
-
$syukin = 0;
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
if(($break_key_year != $work_date[0])){
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
echo '---------------------------------------------------'.PHP_EOL;
|
276
|
-
|
277
|
-
echo $break_key_year.'年:'.'入金合計:'.$year_nyukin.'、出金合計:'.$year_syukin.PHP_EOL;
|
278
|
-
|
279
|
-
echo PHP_EOL;
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
$keep1 = $year_nyukin;
|
284
|
-
|
285
|
-
$keep2 = $year_syukin;
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
}
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
}
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
$break_key_year = $work_date[0];
|
298
|
-
|
299
|
-
$break_key_month = $work_date[1];
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
}
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
$w_nyukin = trim($work_field[1]);
|
310
|
-
|
311
|
-
$w_syukin = trim($work_field[2]);
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
if(empty($w_nyukin) && empty($w_syukin)){
|
316
|
-
|
317
|
-
echo $i.'行目のデータがありませんのでデータをスキップします。'.PHP_EOL;
|
318
|
-
|
319
|
-
continue;
|
320
|
-
|
321
|
-
}
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
//通常処理
|
326
|
-
|
327
|
-
if (empty($w_nyukin)) {
|
328
|
-
|
329
|
-
$syukin += $w_syukin;
|
330
|
-
|
331
|
-
} else {
|
332
|
-
|
333
|
-
$nyukin += $w_nyukin;
|
334
|
-
|
335
|
-
}
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
389
|
}
|
342
390
|
|
343
391
|
|
344
392
|
|
345
|
-
$a = $total_nyukin - $keep1;
|
346
|
-
|
347
|
-
$b = $total_syukin - $keep2;
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
echo $break_key_year.'年'.$break_key_month.'月'.'入金集計:'.$nyukin.'、出金合計:'.$syukin.PHP_EOL;
|
352
|
-
|
353
|
-
echo '---------------------------------------------------'.PHP_EOL;
|
354
|
-
|
355
|
-
echo $break_key_year.'年:'.'入金合計:'.$a.'、出金合計:'.$b.PHP_EOL;
|
356
|
-
|
357
|
-
echo PHP_EOL;
|
358
|
-
|
359
|
-
echo '========================================='.PHP_EOL;
|
360
|
-
|
361
|
-
echo 'トータル:'.'入金合計:'.$total_nyukin.'、出金合計:'.$total_syukin.PHP_EOL;
|
362
|
-
|
363
|
-
fclose($fp);
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
if ($i == 0) {
|
370
|
-
|
371
|
-
echo "指定されたファイルは空ファイルでした。".PHP_EOL;
|
372
|
-
|
373
|
-
}
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
return 0;
|
380
|
-
|
381
|
-
}
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
}
|
390
|
-
|
391
|
-
|
392
|
-
|
393
393
|
```
|
394
394
|
|
395
395
|
|
1
インデント調整
test
CHANGED
File without changes
|
test
CHANGED
@@ -158,15 +158,15 @@
|
|
158
158
|
|
159
159
|
|
160
160
|
|
161
|
-
$a =0;
|
161
|
+
$a =0;
|
162
|
-
|
162
|
+
|
163
|
-
$b =0;
|
163
|
+
$b =0;
|
164
|
-
|
165
|
-
|
166
|
-
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
-
while ($line = fgets($fp)) {
|
167
|
+
while ($line = fgets($fp)) {
|
168
|
-
|
168
|
+
|
169
|
-
$i++;
|
169
|
+
$i++;
|
170
170
|
|
171
171
|
|
172
172
|
|
@@ -286,11 +286,11 @@
|
|
286
286
|
|
287
287
|
|
288
288
|
|
289
|
-
|
289
|
+
}
|
290
|
-
|
291
|
-
|
292
|
-
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
-
|
293
|
+
}
|
294
294
|
|
295
295
|
|
296
296
|
|
@@ -306,9 +306,9 @@
|
|
306
306
|
|
307
307
|
|
308
308
|
|
309
|
-
$w_nyukin = trim($work_field[1]);
|
309
|
+
$w_nyukin = trim($work_field[1]);
|
310
|
-
|
310
|
+
|
311
|
-
$w_syukin = trim($work_field[2]);
|
311
|
+
$w_syukin = trim($work_field[2]);
|
312
312
|
|
313
313
|
|
314
314
|
|
@@ -342,13 +342,13 @@
|
|
342
342
|
|
343
343
|
|
344
344
|
|
345
|
-
$a = $total_nyukin - $keep1;
|
345
|
+
$a = $total_nyukin - $keep1;
|
346
|
-
|
346
|
+
|
347
|
-
$b = $total_syukin - $keep2;
|
347
|
+
$b = $total_syukin - $keep2;
|
348
|
-
|
349
|
-
|
350
|
-
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
-
echo $break_key_year.'年'.$break_key_month.'月'.'入金集計:'.$nyukin.'、出金合計:'.$syukin.PHP_EOL;
|
351
|
+
echo $break_key_year.'年'.$break_key_month.'月'.'入金集計:'.$nyukin.'、出金合計:'.$syukin.PHP_EOL;
|
352
352
|
|
353
353
|
echo '---------------------------------------------------'.PHP_EOL;
|
354
354
|
|
@@ -356,38 +356,38 @@
|
|
356
356
|
|
357
357
|
echo PHP_EOL;
|
358
358
|
|
359
|
-
echo '========================================='.PHP_EOL;
|
359
|
+
echo '========================================='.PHP_EOL;
|
360
|
-
|
360
|
+
|
361
|
-
echo 'トータル:'.'入金合計:'.$total_nyukin.'、出金合計:'.$total_syukin.PHP_EOL;
|
361
|
+
echo 'トータル:'.'入金合計:'.$total_nyukin.'、出金合計:'.$total_syukin.PHP_EOL;
|
362
|
-
|
362
|
+
|
363
|
-
fclose($fp);
|
363
|
+
fclose($fp);
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
-
if ($i == 0) {
|
369
|
+
if ($i == 0) {
|
370
370
|
|
371
371
|
echo "指定されたファイルは空ファイルでした。".PHP_EOL;
|
372
372
|
|
373
|
+
}
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
return 0;
|
380
|
+
|
373
381
|
}
|
374
382
|
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
383
|
+
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
|
380
388
|
|
381
389
|
}
|
382
390
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
}
|
390
|
-
|
391
391
|
|
392
392
|
|
393
393
|
```
|