<?php

use kartik\date\DatePicker;
use kartik\file\FileInput;
use kartik\time\TimePicker;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use yii\widgets\Pjax;
use modules\users\models\User;
use modules\custom\models\Accounts;
/* @var $this yii\web\View */
/* @var $model modules\forms\models\Dt198 */
/* @var $form yii\widgets\ActiveForm */
//$model->shiftstart = date('H:i', $model->shiftstart);
//$model->shiftend = date('H:i', $model->shiftend);
$users = User::Employeesu();
?>
<style>
.toppad {
    padding-top: 3px;
    padding-bottom: 3px;
}
</style>

<script>
function deleteRow(id) {

    $.ajax({
            type: "POST",
            url: "/dt198/deleterow",
            data: {
                id: id,
                _csrf: "<?=\yii::$app->request->csrfToken;?>"
            },
        })
        .done(function(result) {
            if (result == 'Success') {
                data = "<div>Deleted</div>"
            } else {
                data = result;
            }
            $('#message').html(data);
            $('#flashmessage').delay(500).fadeIn('normal', function() {
                $(this).delay(2500).fadeOut();
            });
            $.pjax.reload('#rows');



        });
}
</script>

<div class="dt198-form">

    <?php $form = ActiveForm::begin();?>
    <div class="row">
        <div class="col-md-3">

            <table class="Table notbb nolb norb">

                <tr>
                    <th class="DarkerBlue">Gauge Corner Restoration Delivered by :</th>
                    <th class="DarkerBlue">Inline Track Welding</th>
                </tr>
                <tr>
                    <th class="DarkerBlue">Client</th>
                    <td><?=$form->field($model, 'client')->dropdownlist(Accounts::getActive(), ['prompt' => 'Please Select'])->label(false)?>
                    </td>
                </tr>
                <tr>
                    <th class="DarkerBlue">Job No</th>
                    <td><?=$form->field($model, 'jobno')->textinput()->label(false)?></td>
                </tr>

                <tr>
                    <th class="DarkerBlue">Location</th>
                    <td><?=$form->field($model, 'location')->textInput()->label(false)?></td>
                </tr>
                <tr>
                    <th class="DarkerBlue">Date</th>
                    <td><?=$form->field($model, 'insdate')->widget(DatePicker::class, [
    'options' => ['placeholder' => 'Enter event time ...'],
    'pluginOptions' => [
        'autoclose' => true,
        'format' => 'dd/mm/yyyy',
    ],
])->label(false)?></td>
                </tr>
                <tr>
                    <th class="DarkerBlue">Curve radii, m</th>
                    <td><?=$form->field($model, 'curveradii')->textInput()->label(false)?></td>
                </tr>
                <tr>
                    <th class="DarkerBlue">Rail grade</th>
                    <td><?=$form->field($model, 'railgrade')->textInput()->label(false)?></td>
                </tr>
                <tr>
                    <th class="DarkerBlue">Shift Start Time</th>
                    <td><?=$form->field($model, 'shiftstart')->widget(TimePicker::class, [
    'options' => ['placeholder' => 'Enter event time ...'],
    'pluginOptions' => [
        'showMeridian' => false,
        'autoclose' => true,
    ],
])->label(false)?></td>

                </tr>
                <tr>
                    <th class="DarkerBlue">Shift End Time</th>
                    <td><?=$form->field($model, 'shiftend')->widget(TimePicker::class, [
    'options' => ['placeholder' => 'Enter event time ...'],
    'pluginOptions' => [
        'showMeridian' => false,
        'autoclose' => true,
    ],
])->label(false)?></td>
                </tr>
                <tr>
                    <th class="DarkerBlue">Planned meterage</th>
                    <td><?=$form->field($model, 'plannedmeterage')->textInput()->label(false)?></td>
                </tr>
                <tr>
                    <th class="DarkerBlue">Actual Meterage</th>
                    <td><?=$form->field($model, 'actualmeterage')->textInput()->label(false)?></td>
                </tr>
                <tr>
                    <th class="DarkerBlue">Senior Welder</th>
                    <td><?=$form->field($model, 'seniorwelder')->dropdownlist($users, ['prompt' => 'Please Select'])->label(false)?>
                    </td>
                </tr>
                <tr>
                    <th class="DarkerBlue">Assistant 1</th>
                    <td><?=$form->field($model, 'assistant1')->dropdownlist($users, ['prompt' => 'Please Select'])->label(false)?>
                    </td>
                </tr>
                <tr>
                    <th class="DarkerBlue">Assistant 2</th>
                    <td><?=$form->field($model, 'assistant2')->dropdownlist($users, ['prompt' => 'Please Select'])->label(false)?>
                    </td>
                </tr>
                <tr>
                    <th class="DarkerBlue">Assistant 3</th>
                    <td><?=$form->field($model, 'assistant3')->dropdownlist($users, ['prompt' => 'Please Select'])->label(false)?>
                    </td>
                </tr>
            </table>

        </div>
        <div class="col-md-9">
            <table class="Table notbb norb nolb">
                <tr>
                    <th class="DarkerBlueC" colspan="2">Gauge Corner Restoration - Specified Welding Parameters &
                        Process
                        Route</th>
                </tr>
                <tr>
                    <th class="DarkerBlue toppad">Welding Current</th>
                    <td class="text-center">380A +/- 30A</td>
                </tr>
                <tr>
                    <th class="DarkerBlue toppad">Welding Voltage:</th>
                    <td class="text-center">32V +/- 2V</td>
                </tr>
                <tr>
                    <th class="DarkerBlue toppad">Wire Feed Speed:</th>
                    <td class="text-center">2.3m/min</td>
                </tr>

                <tr>
                    <th class="DarkerBlue toppad" rowspan="3">Welding Speed; cm/min</th>
                    <td>
                        <table class="table notbb nolb norb">
                            <tr>
                                <th class="DarkerBlueC">Root Bead</th>
                                <th class="DarkerBlueC">Subsequent Beads</th>
                                <th class="DarkerBlueC">Sacrificial Beads</th>
                            </tr>
                            <tr>
                                <td class="text-center">48 +/- 2</td>
                                <td class="text-center">60 +/- 2</td>
                                <td class="text-center">72 +/- 2</td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td class="toppad">
                        Single, non-consecutive weld beads may be laid down at up to 0.72m/min if a smaller weld deposit
                        is
                        required.
                    </td>
                </tr>
                <tr>
                    <td class="toppad">
                        Sacrificial bead MUST NOT create a new HAZ on the rail running surface: bead must be displaced
                        towards the gauge corner by ~2mm compared to the previous bead
                    </td>
                </tr>
                <tr>
                    <th class="DarkerBlue toppad">Low Preheat Temperature (Soaked NOT Peak Value):</th>
                    <td class="text-center">60-80 °C</td>
                </tr>
                <tr>
                    <th class="DarkerBlue toppad">Minimum Inter-pass Temperature at start & finish of pass:</th>
                    <td class="text-center">60°C</td>
                </tr>
                <tr>
                    <th class="DarkerBlue toppad">Maximum Inter-pass Temperature at start of pass:</th>
                    <td class="text-center">130˚C</td>
                </tr>
                <tr>
                    <th class="DarkerBlue toppad">Welding Wire (Name & Wire Diameter):</th>
                    <td class="text-center">LWS 307</td>
                </tr>
                <tr>
                    <th class="DarkerBlue toppad">Welding Flux:</th>
                    <td class="text-center">&nbsp;</td>
                </tr>
            </table>
        </div>
    </div>

    <?php if ($this->context->action->id == 'update') {?>

    <div class="row">
        <div class="col-md-12">

            <?php Pjax::begin(['id' => 'rows'])?>
            <table class="table table-hover table-borderless">

                <tr class="DarkerBlue">
                    <th class="Title" colspan="20">Process Control Data</th>
                </tr>
                <tr class="DarkerBlue">
                    <th colspan="2">Welding Beads</th>
                    <th rowspan="2" style="vertical-align: top;">Distance</th>
                    <th colspan="3">Volts, V</th>
                    <th colspan="3">Amps, A</th>
                    <th colspan="3">Welding Speed; mm/sec</th>
                    <th colspan="3">Heat Input, Kj/mm</th>
                    <th colspan="3">Interpass Temperature; &deg;C</th>
                    <th rowspan="2" style="vertical-align: top;">Strike on<br />Temperature &deg;C</th>
                    <th rowspan="2" style="vertical-align: top;">Strike off<br />Temperature &deg;C</th>
                </tr>
                <tr class="DarkerBlue ">
                    <td class="toppad">Type</td>
                    <td>No</td>
                    <td>Avg</td>
                    <td>Max</td>
                    <td>Min</td>
                    <td>Avg</td>
                    <td>Max</td>
                    <td>Min</td>
                    <td>Avg</td>
                    <td>Max</td>
                    <td>Min</td>
                    <td>Avg</td>
                    <td>Max</td>
                    <td>Min</td>
                    <td>Avg</td>
                    <td>Max</td>
                    <td>Min</td>

                </tr>
                <?php $x = 1; ?>
                <?php while($x <= count($model->rowtype)) { ?>
                <?php if(isset($model->rowstatus[$x])){ ?>
                    <tr id="row-<?= $x ?>"  class="<?= $model->rowstatus[$x] == 'Deleted' ? 'd-none' : '' ?>" >
                        <td class="toppad">
                            <span class="fa fa-trash" onClick="deleterow('<?= $x ?>')" ></span>
                            <?= $model->rowtype[$x] ?>
                            <?= $form->field($model, "rowstatus[$x]")->hiddenInput(['id' => 'rowstatus'.$x])->label(false) ?>
                        </td>

                        <td><?= $model->rowno[$x] ?></td>
                        <td><?= isset($model->rowdistance[$x]) ? number_format((float)$model->rowdistance[$x], 3, '.', '') : null; ?>
                        </td>
                        <td><?= isset($model->rowvoltsavg[$x]) ? number_format((float)$model->rowvoltsavg[$x], 3, '.', '') : null; ?>
                        </td>
                        <td><?= isset($model->rowvoltsmax[$x]) ? number_format((float)$model->rowvoltsmax[$x], 3, '.', '') : null; ?>
                        </td>
                        <td><?= isset($model->rowvoltsmin[$x]) ? number_format((float)$model->rowvoltsmin[$x], 3, '.', '') : null;  ?>
                        </td>
                        <td><?= isset($model->rowampsavg[$x]) ? number_format((float)$model->rowampsavg[$x], 3, '.', '') : null;  ?>
                        </td>
                        <td><?= isset($model->rowampsmax[$x]) ? number_format((float)$model->rowampsmax[$x], 3, '.', '') : null; ?>
                        </td>
                        <td><?= isset($model->rowampsmin[$x]) ? number_format((float)$model->rowampsmin[$x], 3, '.', '') : null; ?>
                        </td>
                        <td><?= isset($model->rowspeedavg[$x]) ? number_format((float)$model->rowspeedavg[$x], 3, '.', '') : null; ?>
                        </td>
                        <td><?= isset($model->rowspeedmax[$x]) ? number_format((float)$model->rowspeedmax[$x], 3, '.', '') : null; ?>
                        </td>
                        <td><?= isset($model->rowspeedmin[$x]) ? number_format((float)$model->rowspeedmin[$x], 3, '.', '') : null; ?>
                        </td>
                        <td><?= isset($model->rowinputkjavg[$x]) ? number_format((float)$model->rowinputkjavg[$x], 3, '.', '') : null; ?>
                        </td>
                        <td><?= isset($model->rowinputkjmax[$x]) ? number_format((float)$model->rowinputkjmax[$x], 3, '.', '') : null; ?>
                        </td>
                        <td><?= isset($model->rowinputkjmin[$x]) ? number_format((float)$model->rowinputkjmin[$x], 3, '.', '') : null; ?>
                        </td>
                        <td><?= isset($model->rowinterpassavg[$x]) ? number_format((float)$model->rowinterpassavg[$x], 3, '.', '') : null; ?>
                        </td>
                        <td><?= isset($model->rowinterpassmax[$x]) ? number_format((float)$model->rowinterpassmax[$x], 3, '.', '') : null; ?>
                        </td>
                        <td><?= isset($model->rowinterpassmin[$x]) ? number_format((float)$model->rowinterpassmin[$x], 3, '.', '') : null; ?>
                        </td>
                        <td><?= isset($model->rowstrikeonavg[$x]) ? number_format((float)$model->rowstrikeonavg[$x], 3, '.', '') : null; ?>
                        </td>
                        <td><?= isset($model->rowstrikeoffavg[$x]) ? number_format((float)$model->rowstrikeoffavg[$x], 3, '.', '') : null; ?>
                        </td>
                        <?php /*
                                <td><?= number_format((float)$model->rowstrikeonmax, 3, '.', ''); ?></td>
                        <td><?= number_format((float)$model->rowstrikeonmin, 3, '.', ''); ?></td>
                        <td><?= number_format((float)$model->rowstrikeoffmax, 3, '.', ''); ?></td>
                        <td><?= number_format((float)$model->rowstrikeoffmin, 3, '.', ''); ?></td>
                        */ ?>
                    </tr>
                <?php } ?>
                <?php $x ++; ?>
                <?php } ?>
            </table>
            <?php Pjax::end();?>

            <table class="nolb norb notbb">
                <tr class="DarkerBlue">
                    <td rowspan="2" class="toppad">Welding Heat Input =</td>
                    <td style="padding-left: 25px;" class="toppad">(60VI)/1000v =  Kj/mm </td>
                    <td style="padding-left: 25px;" class="toppad"> Amp * Volt * 60 * factor / (1000*welding Speed in
                        mm/min)</td>
                </tr>
                <tr class="DarkerBlue">
                    <td style="padding-left: 25px;" colspan="2">Factor for submerged arc welding = 1</td>
                </tr>
            </table>


        </div>

        <?php }?>


        <div class="form-group col-md-12">
            <?=Html::submitButton('Save', ['class' => 'btn btn-primary'])?>
        </div>
    </div>

    <?php ActiveForm::end();?>

</div>
<style>
.fa-trash {
    cursor: pointer;
}
</style>
<script>

function deleterow(id)
{
    $('#rowstatus'+id).val('Deleted');
    $('#row-'+id).addClass('d-none');
}
</script>