Files
citrus-cms/resources/views/cron/incoming_control_paints-pdf-db-incoming-control-sync.blade.php
T
2026-04-28 21:15:09 +03:00

111 lines
3.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
$tableName = "incoming_control_paints";
// Verileri çek
$list = db($tableName)
->select("id", "certificate_no", "akt_number")
->orderBy("id", "DESC");
if(isset($lineNumber)) {
$_GET['q'] = $lineNumber;
$commitSize = 1;
}
// Eğer belirli bir kayıt için çalıştırılıyorsa (q parametresi veya lineNumber)
if(!getesit("q","")) {
$q = get("q");
$list = $list->where(function($query) use ($q) {
$query->where("certificate_no", $q)
->orWhere("akt_number", $q);
});
// Güncelleme öncesi ilgili kayıtları sıfırla
$resetData = [];
$resetData['pdf_certificate'] = null;
$resetData['pdf_akt'] = null;
db($tableName)
->where("certificate_no", $q)
->orWhere("akt_number", $q)
->update($resetData);
}
$list = $list->get();
DB::beginTransaction();
$say = 0;
$k = 0;
Log::debug("📄Incoming Control Paint PDF Link to DB Start " . simdi());
try {
foreach($list as $item) {
$updateData = [];
// 1. Certificate File Logic
// Path: 002_Project_Materials/002_Material Certificate/
// Pattern: {certificate_no}*.pdf
if($item->certificate_no) {
// Dosya sistemi araması için slash ve boşlukları joker (*) ile değiştir
$certData = str_replace(["/", " "], "*", $item->certificate_no);
if(trim($certData) != "") {
$pathCert = "storage/documents/002_Project_Materials/002_Material Certificate/*{$certData}*.pdf";
$searchCert = glob($pathCert);
if(isset($searchCert[0])) {
$updateData['pdf_certificate'] = $searchCert[0];
} else {
// Eğer bulunamazsa null yap (manuel silinmiş olabilir)
$updateData['pdf_certificate'] = null;
}
}
}
// 2. AKT File Logic
// Path: 002_Project_Materials/001_Material Akt/
// Pattern: {akt_number}*.pdf
if($item->akt_number) {
$aktData = str_replace(["/", " "], "*", $item->akt_number);
if(trim($aktData) != "") {
$pathAkt = "storage/documents/002_Project_Materials/001_Material Akt/*{$aktData}*.pdf";
$searchAkt = glob($pathAkt);
if(isset($searchAkt[0])) {
$updateData['pdf_akt'] = $searchAkt[0];
} else {
$updateData['pdf_akt'] = null;
}
}
}
// Eğer güncellenecek veri varsa güncelle
if(count($updateData) > 0) {
db($tableName)
->where("id", $item->id)
->update($updateData);
$k++;
}
// Transaction commit check
if($say == $commitSize) {
DB::commit();
DB::beginTransaction();
$say = 0;
}
$say++;
}
DB::commit();
Log::debug("Incoming Control Paint update PDF link for $k rows");
} catch (\Throwable $th) {
DB::rollback();
Log::error("Incoming Control Paint PDF Sync Error: " . $th->getMessage());
}
Log::debug("📄Incoming Control Paint PDF Link to DB Finish " . simdi());
?>