238 lines
7.5 KiB
PHP
238 lines
7.5 KiB
PHP
<?php
|
|
use App\Models\WelderTest;
|
|
use Barryvdh\DomPDF\Facade\Pdf;
|
|
use Carbon\Carbon;
|
|
|
|
set_time_limit(-1);
|
|
ini_set('max_execution_time', -1);
|
|
|
|
setlocale(LC_ALL, 'ru_RU.utf8');
|
|
App::setLocale("ru");
|
|
$documentInfo = document_template(get("document"));
|
|
$j = j($documentInfo->json);
|
|
|
|
function mb_str_replace($search, $replace, $subject) {
|
|
return implode($replace, explode($search, $subject, 2));
|
|
}
|
|
|
|
$weldLogs = db("weld_logs");
|
|
$weldLogs = $weldLogs->join("subcontractors", "weld_logs.general_contractor", "subcontractors.company_name_en");
|
|
|
|
$montajContractor = db("subcontractors")->where("job_description", "MONTAJ")->first();
|
|
$constructionContractor = db("subcontractors")->where("job_description", "CONSTRUCTION")->first();
|
|
|
|
$weldLogs = $weldLogs->groupBy("line_number")->get();
|
|
|
|
$prefix = "📂 {$documentInfo->title}";
|
|
Log::debug("$prefix start " . simdi());
|
|
|
|
$k = 0;
|
|
|
|
$projectNameRu = setting('project_name_ru');
|
|
|
|
foreach($weldLogs AS $weldLog) {
|
|
$contractorInfo = db("subcontractors")->where("company_name_en", $weldLog->contractor)->first();
|
|
$lineList = db("line_lists")->where([
|
|
'line_no' => $weldLog->line_number
|
|
])->first();
|
|
|
|
|
|
|
|
|
|
|
|
$fileName = $weldLog->line_number . " - " . $documentInfo->title2;
|
|
$string = $documentInfo->html;
|
|
$string = pdf_html_content($string);
|
|
|
|
$string = str_replace("{project_name}", $projectNameRu, $string);
|
|
|
|
|
|
$string = workPermitReplacer($string, $weldLog, $documentInfo);
|
|
|
|
|
|
$date = (new Carbon($weldLog->date_test));
|
|
$c1 = $contractorInfo?->project_city_ru;
|
|
$c2 = $date->translatedFormat('d');
|
|
$c3 = $date->translatedFormat('F');
|
|
$c4 = $date->translatedFormat('y');
|
|
$c5 = $weldLog->general_contractor . "<hr>" . $weldLog->address;
|
|
$c6 = $montajContractor?->company_name_ru;
|
|
$c7 = $contractorInfo?->company_name_ru ;
|
|
|
|
$c11 = $contractorInfo?->company_name_ru;
|
|
$c12 = $constructionContractor?->company_name_ru;
|
|
$c13 = $weldLog->iso_number;
|
|
|
|
$spoolReleaseNumbers = db("weld_logs")
|
|
->where("line_number", $weldLog->line_number)
|
|
->where("spool_status", "Spool Release")
|
|
->get()->pluck("spool_number")->toArray();
|
|
|
|
$spoolReleaseNumbers = implode(", ", $spoolReleaseNumbers);
|
|
|
|
$c14 = "вода";
|
|
if($weldLog->type_of_test == "Hydraulic") {
|
|
$c14 = "водой";
|
|
}
|
|
|
|
$c15 = $weldLog->design_pressure_mpa;
|
|
$c16 = $weldLog->test_pressure;
|
|
$c17 = "0,5";
|
|
|
|
$string = str_replace("{c1}", $c1, $string);
|
|
$string = str_replace("{c2}", $c2, $string);
|
|
$string = str_replace("{c3}", $c3, $string);
|
|
$string = str_replace("{c4}", $c4, $string);
|
|
$string = str_replace("{c5}", $c5, $string);
|
|
$string = str_replace("{c6}", $c6, $string);
|
|
$string = str_replace("{c7}", $c7, $string);
|
|
$string = str_replace("{c11}", $c11, $string);
|
|
$string = str_replace("{c12}", $c12, $string);
|
|
$string = str_replace("{c13}", $c13, $string);
|
|
$string = str_replace("{c14}", $c14, $string);
|
|
$string = str_replace("{c15}", $c15, $string);
|
|
$string = str_replace("{c16}", $c16, $string);
|
|
$string = str_replace("{c17}", $c17, $string);
|
|
$string = str_replace("{plant}", $lineList?->plant, $string);
|
|
$string = str_replace("{p_id}", $lineList?->p_id, $string);
|
|
|
|
|
|
$first_welding_date = db("weld_logs")->where("line_number", $weldLog->line_number)->whereNotNull("welding_date")->orderBy("welding_date", "ASC")->value("welding_date");
|
|
$first_welding_date = df($first_welding_date);
|
|
|
|
$last_welding_date = db("weld_logs")->where("line_number", $weldLog->line_number)->whereNotNull("welding_date")->orderBy("welding_date", "DESC")->value("welding_date");
|
|
$last_welding_date = df($last_welding_date);
|
|
|
|
$string = str_replace("{first_welding_date}", $first_welding_date, $string);
|
|
$string = str_replace("{last_welding_date}", $last_welding_date, $string);
|
|
|
|
$engineering_ru = db("subcontractors")->where("company_name_en", $lineList?->engineering)->value("company_name_ru");
|
|
$string = str_replace("{engineering_ru}", $engineering_ru, $string);
|
|
|
|
$string = str_replace("{spoolReleaseNumbers}", $spoolReleaseNumbers, $string);
|
|
|
|
if($documentInfo->title == "AOSR NDT Reports List")
|
|
{
|
|
$aosr_table_row = "";
|
|
$logTypes = log_test_types();
|
|
|
|
$sameWeldLogs = db("weld_logs")->where("line_number", $weldLog->line_number)->get();
|
|
|
|
foreach($sameWeldLogs AS $sameWeldLog)
|
|
{
|
|
foreach($logTypes AS $logType => $logTable)
|
|
{
|
|
$reportNo = $sameWeldLog->{$logType."_report"};
|
|
$reportDate = df($sameWeldLog->{$logType."_test_date"});
|
|
if($reportNo != "")
|
|
{
|
|
$aosr_table_row .= "
|
|
<tr>
|
|
<td>ВИК</td>
|
|
<td>$reportNo от $reportDate</td>
|
|
</tr>
|
|
";
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
$string = str_replace("<!-- aosr_table_row -->", $aosr_table_row, $string);
|
|
}
|
|
|
|
|
|
if($documentInfo->title == "AOSR Materials List")
|
|
{
|
|
$aosr_table_row = "";
|
|
$logTypes = log_test_types();
|
|
$addedElement = [];
|
|
|
|
$sameWeldLogs = db("weld_logs")->where("line_number", $weldLog->line_number)->get();
|
|
|
|
foreach($sameWeldLogs AS $sameWeldLog)
|
|
{
|
|
for($codeCount=1; $codeCount<=2; $codeCount++)
|
|
{
|
|
$elementCode = $sameWeldLog->{"element_code_" . $codeCount};
|
|
$material = $sameWeldLog->{"material_no_" . $codeCount};
|
|
|
|
$certificateDate = db("incoming_controls")->where("certificate_no", $sameWeldLog->{"certificate_number_of_" . $codeCount})->value("certificate_date");
|
|
|
|
if(!rejected_date($certificateDate)) {
|
|
$certificateDate = df($certificateDate);
|
|
} else {
|
|
$certificateDate = "-";
|
|
}
|
|
|
|
$certificate = $sameWeldLog->{"certificate_number_of_" . $codeCount} . " " . $certificateDate;
|
|
|
|
if($elementCode == "") $elementCode = "-";
|
|
if($material == "") $material = "-";
|
|
if($certificate == "") $certificate = "-";
|
|
|
|
if(!in_array($elementCode, $addedElement))
|
|
{
|
|
$aosr_table_row .= "
|
|
<tr>
|
|
<td>$elementCode</td>
|
|
<td>$material</td>
|
|
<td>$certificate</td>
|
|
</tr>
|
|
";
|
|
$addedElement[] = $elementCode;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$string = str_replace("<!-- aosr_table_row -->", $aosr_table_row, $string);
|
|
}
|
|
|
|
|
|
|
|
|
|
$path = $documentInfo->kid; //"005_PTO/06_Прочность и плотность";
|
|
|
|
/*
|
|
$pdf = App::make('dompdf.wrapper');
|
|
$pdf->setPaper('A4',$j['paper']);
|
|
$pdf->setOption(['dpi' => $j['dpi'], ]);
|
|
$pdf->loadHTML($string);
|
|
|
|
|
|
$path = "$path/$fileName.pdf";
|
|
|
|
Storage::put($path, $pdf->output());
|
|
*/
|
|
|
|
$path = "$path/$fileName";
|
|
html_create($path, $string);
|
|
|
|
|
|
/*
|
|
echo $string;
|
|
exit();
|
|
*/
|
|
|
|
$k++;
|
|
|
|
|
|
}
|
|
|
|
e2("The process is completed: a total of :count documents have been processed into the :folder folder.",
|
|
[
|
|
'folder' => $documentInfo->kid,
|
|
'count' => $k
|
|
]);
|
|
Log::debug("$prefix finish processed $k " . simdi());
|
|
?>
|
|
|