Files
citrus-cms/resources/views/cron-documents/line-specification-generator.blade.php
T
2026-04-28 21:15:09 +03:00

169 lines
4.4 KiB
PHP

<?php
use App\Models\WelderTest;
use Barryvdh\DomPDF\Facade\Pdf;
use Carbon\Carbon;
setlocale(LC_ALL, 'ru_RU.utf8');
App::setLocale("ru");
$documentInfo = document_template("Line_Specification");
$j = j($documentInfo->json);
$tableName = "m_t_o_s";
$mtos = db($tableName);
$mtos = $mtos->groupBy("line")
//->where("line","NI-80-AH01JL-FA00.830")
->get();
$prefix = "📂 line-specification";
Log::debug("$prefix start " . simdi());
$k = 0;
foreach($mtos AS $mto) {
$tableRows1 = "";
$tableRows2 = "";
$tableRows3 = "";
$fileName = $mto->line;
$string = $documentInfo->html;
$string = pdf_html_content($string);
$string .= "<style> table td {
border: solid 1px #000;
}</style>";
$c1 = $mto->line;
$c2 = "";
$string = str_replace("{c1}", $c1, $string);
$string = str_replace("{c2}", $c2, $string);
$pipes = db($tableName)
->where("line", $mto->line)
->where(function($query) use($tableName) {
$types = ['PIPE'];
foreach($types AS $type) {
$query->orWhere("$tableName.longdescription", "like", "%$type%");
}
$types = ['ТРУБА'];
foreach($types AS $type) {
$query->orWhere("$tableName.description_ru", "like", "%$type%");
}
})
->get();
$others = db($tableName)
->where("line", $mto->line)
->where(function($query) {
$types = ['flange', 'elbow', 'Tee', 'reducer'];
foreach($types AS $type) {
$query->orWhere("longdescription", "like", "%$type%");
}
})
->get();
$others2 = db($tableName)
->where("line", $mto->line)
->where(function($query) {
$types = ['support', 'gasket', 'nuts', 'bolt'];
foreach($types AS $type) {
$query->orWhere("longdescription", "like", "%$type%");
}
})
->get();
foreach($pipes AS $pipe) {
$weldLog = db("weld_logs")
->where("line_number", $pipe->line)
->where("element_code_1", $pipe->component_code_id)
->first();
$tableRow1 = "
<tr border='1' style='border:solid 1px #000'>
<td style='text-align:center;'>{$weldLog?->pose_no_1} <br> ({$pipe->component_code_id}) </td>
<td width='30%'>{$pipe->description_ru}</td>
<td style='text-align:center;'>{$pipe->odmm_1}x{$pipe->thicknessmm_1}</td>
<td style='text-align:center;'>{$pipe->material}</td>
<td>{$pipe->quantity} m</td>
</tr>
";
$tableRows1 .= $tableRow1;
}
foreach($others AS $pipe) {
$weldLog = db("weld_logs")
->where("line_number", $pipe->line)
->where("element_code_1", $pipe->component_code_id)
->first();
$dn1 = "{$pipe->dn_1}x{$pipe->dn_2}";
if($pipe->dn_2 == "") {
$dn1 = $pipe->dn_1;
}
$tableRow2 = "
<tr border=1>
<td style='text-align:center;'>{$weldLog?->pose_no_1} <br> ({$pipe->component_code_id}) </td>
<td width='30%'>{$pipe->description_ru}</td>
<td style='text-align:center;'>$dn1</td>
<td style='text-align:center;'>{$pipe->pn_mpa}</td>
<td>{$pipe->material}</td>
<td>{$pipe->quantity} шт</td>
</tr>
";
$tableRows2 .= $tableRow2;
}
foreach($others2 AS $pipe) {
$weldLog = db("weld_logs")
->where("line_number", $pipe->line)
->where("element_code_1", $pipe->component_code_id)
->first();
$dn1 = "{$pipe->dn_1}x{$pipe->dn_2}";
if($pipe->dn_2 == "") {
$dn1 = $pipe->dn_1;
}
$tableRow3 = "
<tr border=1>
<td style='text-align:center;'>{$weldLog?->pose_no_1} <br> ({$pipe->component_code_id}) </td>
<td width='30%'>{$pipe->description_ru}</td>
<td style='text-align:center;'>{$pipe->material}</td>
<td style='text-align:center;'>{$pipe->quantity} шт</td>
</tr>
";
$tableRows3 .= $tableRow3;
}
$string = str_replace("<!-- table_row_1 -->", $tableRows1, $string);
$string = str_replace("<!-- table_row_2 -->", $tableRows2, $string);
$string = str_replace("<!-- table_row_3 -->", $tableRows3, $string);
$string = workPermitReplacer($string, null, $documentInfo);
$path = $documentInfo->kid; //"005_PTO/08_Спецификация";
$path = "$path/$fileName";
html_create($path, $string);
$k++;
}
echo $k;
Log::debug("$prefix finish processed $k " . simdi());
?>