where("updated_at", Carbon::today()) ->get(); //dump($weldLogs->count()); $repairLogs = db("repair_logs") //->where("updated_at", Carbon::today()) ->get(); $testPackagesSummary = []; $testPackagesIsoSummary = []; $totalFields = [ 'total_wdi', 'total_complated_wdi', 'welding_progress', 'total_shop_wdi', 'total_complated_shop_wdi', 'total_field_wdi', 'total_complated_field_wdi', ]; $repairLogsSummary = []; $repairLogsSummary2 = []; $repairLogsSummaryCompleted = []; $repairLogsSummaryCompleted2 = []; $repairLogsSummaryRemaining = []; $repairLogsSummaryRemaining2 = []; foreach($repairLogs AS $repairLog) { if(!isset($repairLogsSummary[$repairLog->iso_number][$repairLog->test_package_no])) $repairLogsSummary[$repairLog->iso_number][$repairLog->test_package_no] = 0; if(!isset($repairLogsSummary2[$repairLog->test_package_no])) $repairLogsSummary2[$repairLog->test_package_no] = 0; if(!isset($repairLogsSummaryCompleted[$repairLog->iso_number][$repairLog->test_package_no])) $repairLogsSummaryCompleted[$repairLog->iso_number][$repairLog->test_package_no] = 0; if(!isset($repairLogsSummaryRemaining[$repairLog->iso_number][$repairLog->test_package_no])) $repairLogsSummaryRemaining[$repairLog->iso_number][$repairLog->test_package_no] = 0; if(!isset($repairLogsSummaryCompleted2[$repairLog->test_package_no])) $repairLogsSummaryCompleted2[$repairLog->test_package_no] = 0; if(!isset($repairLogsSummaryRemaining2[$repairLog->test_package_no])) $repairLogsSummaryRemaining2[$repairLog->test_package_no] = 0; // if($repairLog->repair_status == "Not Done") { $repairLogsSummary[$repairLog->iso_number][$repairLog->test_package_no]++; $repairLogsSummary2[$repairLog->test_package_no]++; // } if(!rejected_date($repairLog->repair_date)) { $repairLogsSummaryCompleted[$repairLog->iso_number][$repairLog->test_package_no]++; $repairLogsSummaryCompleted2[$repairLog->test_package_no]++; } else { $repairLogsSummaryRemaining[$repairLog->iso_number][$repairLog->test_package_no]++; $repairLogsSummaryRemaining2[$repairLog->test_package_no]++; } } foreach($weldLogs AS $weldLog) { foreach($totalFields AS $field) { if(!isset($testPackagesSummary[$weldLog->test_package_no][$field])) $testPackagesSummary[$weldLog->test_package_no][$field] = 0; if(!isset($testPackagesIsoSummary[$weldLog->iso_number][$weldLog->test_package_no][$field])) $testPackagesIsoSummary[$weldLog->iso_number][$weldLog->test_package_no][$field] = 0; } $wdi = (float) $weldLog->nps_1; $testPackagesSummary[$weldLog->test_package_no]['total_wdi'] += $wdi ; $testPackagesIsoSummary[$weldLog->iso_number][$weldLog->test_package_no]['total_wdi'] += $wdi; if($weldLog->type_of_joint == "F") { $testPackagesSummary[$weldLog->test_package_no]['total_field_wdi'] += $wdi; $testPackagesIsoSummary[$weldLog->iso_number][$weldLog->test_package_no]['total_field_wdi'] += $wdi ; if(!rejected_date($weldLog->welding_date)) { $testPackagesSummary[$weldLog->test_package_no]['total_complated_field_wdi'] += $wdi; $testPackagesIsoSummary[$weldLog->iso_number][$weldLog->test_package_no]['total_complated_field_wdi'] += $wdi; } } if($weldLog->type_of_joint == "S") { $testPackagesSummary[$weldLog->test_package_no]['total_shop_wdi'] += $wdi; $testPackagesIsoSummary[$weldLog->iso_number][$weldLog->test_package_no]['total_shop_wdi'] += $wdi; if(!rejected_date($weldLog->welding_date)) { $testPackagesSummary[$weldLog->test_package_no]['total_complated_shop_wdi'] += $wdi; $testPackagesIsoSummary[$weldLog->iso_number][$weldLog->test_package_no]['total_complated_shop_wdi'] += $wdi; } } if(!rejected_date($weldLog->welding_date)) { $testPackagesSummary[$weldLog->test_package_no]['total_complated_wdi'] += $wdi; $testPackagesIsoSummary[$weldLog->iso_number][$weldLog->test_package_no]['total_complated_wdi'] += $wdi; } // Welding progress hesaplama $totalWdi = $testPackagesSummary[$weldLog->test_package_no]['total_wdi']; $totalComplatedWdi = $testPackagesSummary[$weldLog->test_package_no]['total_complated_wdi']; if ($totalWdi > 0) { $testPackagesSummary[$weldLog->test_package_no]['welding_progress'] = round(($totalComplatedWdi * 100) / $totalWdi, 2); } else { $testPackagesSummary[$weldLog->test_package_no]['welding_progress'] = 0; // Sıfırsa } } DB::beginTransaction(); $say = 0; try { foreach($testPackagesIsoSummary AS $isoNumber => $data) { foreach($data AS $tpNo => $data2) { if($data2['total_complated_wdi'] == $data2['total_wdi']) { $status = "Completed"; } if($data2['total_complated_wdi'] < $data2['total_wdi']) { $status = "On Going"; } if($data2['total_complated_wdi'] == 0) { $status = "Waiting"; } /* //dump($isoNumber); //dump($tpNo); //dump($data2); */ $updateData = [ 'welding_status' => $status, 'repair_qty' => @$repairLogsSummary[$isoNumber][$tpNo], 'repair_completed' => @$repairLogsSummaryCompleted[$isoNumber][$tpNo], 'repair_remaining' => @$repairLogsSummaryRemaining[$isoNumber][$tpNo], ]; // //dump($updateData); db("test_pack_base_statuses") ->where("drawing_no", $isoNumber) ->where("test_package_no", $tpNo) ->update( $updateData ); $updateData = [ 'welding_status' => $status, 'repair_qty' => @$repairLogsSummary2[$tpNo], 'repair_completed' => @$repairLogsSummaryCompleted2[$tpNo], 'repair_remaining' => @$repairLogsSummaryRemaining2[$tpNo], ]; db("test_packages") ->where("test_package_number", $tpNo) ->update( $updateData ); /* if($say == $commitSize) { DB::commit(); DB::beginTransaction(); $say = 0; } */ $say++; } DB::commit(); } } catch (\Throwable $th) { Log::error($th->getMessage()); DB::rollback(); } $say = 0; DB::beginTransaction(); try { foreach($testPackagesSummary AS $tpNo => $data2) { if($data2['total_complated_wdi'] == $data2['total_wdi']) { $status = "Completed"; } if($data2['total_complated_wdi'] < $data2['total_wdi']) { $status = "On Going"; } if($data2['total_complated_wdi'] == 0) { $status = "Waiting"; } db("test_packages") ->where("test_package_number", $tpNo) ->update( [ 'welding_status' => $status, 'repair_status_total' => @$repairLogsSummary2[$tpNo] ] ); /* if($say == $commitSize) { DB::commit(); DB::beginTransaction(); $say = 0; } $say++; */ } DB::commit(); //code... } catch (\Throwable $th) { Log::error($th->getMessage()); DB::rollback(); } DB::beginTransaction(); $k = 0; $say = 0; try { foreach($testPackages AS $testPackage) { $updateData = []; if(isset($testPackagesSummary[$testPackage->test_package_number])) { foreach($totalFields AS $field) { $testPackage->$field = $testPackagesSummary[$testPackage->test_package_number][$field]; $updateData[$field] = $testPackagesSummary[$testPackage->test_package_number][$field]; } } $updateData = array_merge($updateData, updateTestPackageStatus($testPackage)); db("test_packages")->where("id", $testPackage->id) ->update( $updateData ); db("test_pack_base_statuses")->where("test_package_no", $testPackage->test_package_number) ->update( [ 'tp_status' => $status, 'priority' => $testPackage->priority, 'priority_info' => $testPackage->priority_info, 'responsible_person' => $testPackage->responsible_test, 'target_test_date' => $testPackage->planned_test_date, ] ); /* if($say == $commitSize) { DB::commit(); DB::beginTransaction(); $say = 0; } */ $say++; $k++; } DB::commit(); } catch (\Throwable $th) { ////dump($th->getMessage()); Log::error($th->getMessage()); DB::rollback(); } dump($k); Log::debug("$k Processed " . simdi()); ?>