<select id="updatePreviousJobSelectBox" name="parentJob">
    <option></option>
    <?php foreach($jobs as $aJob): ?>
        <option value="<?php echo e($aJob['id']); ?>" data-data='<?php echo e(json_encode(['discipline' => $aJob['discipline'], 'responseTime' => \DateTime::createFromFormat('Y-m-d', $aJob['responseTime']) !== FALSE ? date('d/m/Y', strtotime($aJob['responseTime'])) : $aJob['responseTime'], 'faultReport' => $aJob['faultReport']])); ?>' <?php echo e($aJob['id']==$job['parentJob']?'selected':''); ?>><?php echo e($aJob['reference']); ?>

            (<?php echo e($aJob['clientReference']); ?>)
        </option>
    <?php endforeach; ?>
</select>

<div id="updatePreviousJobDetail">
    <a class="btn btn-xs btn-success col-md-12 previous-job-info edit-job" data-id="<?php echo e($job['id']); ?>" data-url="<?php echo e(URL::action("JobController@generateJobDetail")); ?>" style="display:none"></a>
</div>

<script type="text/javascript">
    $('#updatePreviousJobDetail').on('click', 'a.edit-job', function () {
        generateJobDetail($(this).data("url"), $(this).data("id"), $_token)
    });

    if ($('#updatePreviousJobSelectBox').length > 0) {
        $("#updatePreviousJobSelectBox").selectize({
            render: {
                item: function(item) {
                    return '<div>' + item.text + '</div>';
                },
                option: function(item) {
                    return '<div class="previous-job-option">' +
                            '<div class="pjo-text">' + item.text + '</div>' +
                            '<div class="pjo-details"><span>Discipline: ' + item.discipline + '</span><span>Response: ' + item.responseTime + '</span>' + (item.faultReport.length ? '<span class="full">Fault Report: ' + item.faultReport + '</span>' : '') + '</div>' +
//                            '<div class="pjo-details"><span>Discipline: ' + item.discipline + '</span><span>Response: ' + item.responseTime + '</span><span>Recall: ' + item.recall + '</span><span>Warranty: ' + item.warranty + '</span><span>Compliance: ' + item.compliance + '</span><span>Pay type: ' + item.payType + '</span></div>' +
                            '</div>';
                }
            }
        });

        var previousJob = $("#updatePreviousJobSelectBox")[0].selectize.getValue();

        if (previousJob) {
            $('.previous-job-info').text(previousJob + ' - See details').data('id', previousJob).show();
        }

        $("#updatePreviousJobSelectBox").change(function(){
            previousJob = $(this)[0].selectize.getValue();

            $('.previous-job-info').text(previousJob + ' - See details').data('id', previousJob).show();
        });
    }

    $('#updateBuildingAddress').val("<?php echo e($building['address1']!=='' && $building['postcode']!==''?$building['address1'] . ', ' . $building['address2'] . ', ' . $building['town'] . ' ' . $building['postcode']: $client['address1'] . ', ' . $client['address2'] . ', ' . $client['town'] . ' ' . $client['postcode']); ?>");

    $('#updateClientTelephone').val("<?php echo e($building['telephone']!==''?$building['telephone']:$client['telephone']); ?>");
    $('#updateClientOpeningHours').val("<?php echo e($building['buildingOpenTime']!==''?$building['buildingOpenTime'] . '-' . $building['buildingCloseTime']:$client['openingHours']); ?>");
    $('#updateClientContact').val("<?php echo e($building['buildingContact']!==''?$building['buildingContact']:$client['clientContact']); ?>");

</script>