<?php
/**
 * Palletforce – Create Consignment View
 */

use yii\helpers\Html;
use yii\bootstrap4\ActiveForm;

/* @var $this  yii\web\View */
/* @var $model PortalPeople\palletforce\models\ConsignmentForm */

$this->title = 'Create Palletforce Consignment';
$this->params['breadcrumbs'][] = ['label' => 'Palletforce', 'url' => ['/palletforce/config']];
$this->params['breadcrumbs'][] = $this->title;

$serviceOptions = [
    'A' => 'A – 24 Hours',
    'B' => 'B – 48 Hours',
    'C' => 'C – 72 Hours',
    'D' => 'D – 3–5 Days',
];

$palletTypeOptions = [
    'F' => 'F – Full pallet (max 2.44m / 1250kg)',
    'H' => 'H – Half pallet (max 2.0m / 500kg)',
    'Q' => 'Q – Quarter pallet (max 1.0m / 250kg)',
    'O' => 'O – Oversize',
];

$consignmentTypeOptions = [
    '0' => 'Standard',
    '1' => 'Reverse',
    '2' => '3-Way',
];
?>

<div class="palletforce-consignment-create">

    <h1><?= Html::encode($this->title) ?></h1>

    <?php if (Yii::$app->session->hasFlash('success')): ?>
        <div class="alert alert-success"><?= Html::encode(Yii::$app->session->getFlash('success')) ?></div>
    <?php endif; ?>
    <?php if (Yii::$app->session->hasFlash('error')): ?>
        <div class="alert alert-danger"><?= Html::encode(Yii::$app->session->getFlash('error')) ?></div>
    <?php endif; ?>

    <?php $form = ActiveForm::begin(['id' => 'consignment-form']); ?>

    <div class="row">

        <!-- Collection address -->
        <div class="col-md-6">
            <div class="panel panel-default">
                <div class="panel-heading">Collection Address</div>
                <div class="panel-body">
                    <?= $form->field($model, 'collectionName')->textInput(['maxlength' => 30]) ?>
                    <?= $form->field($model, 'collectionStreet')->textInput(['maxlength' => 30]) ?>
                    <?= $form->field($model, 'collectionLocation')->textInput(['maxlength' => 30]) ?>
                    <?= $form->field($model, 'collectionTown')->textInput(['maxlength' => 30]) ?>
                    <?= $form->field($model, 'collectionCounty')->textInput(['maxlength' => 30]) ?>
                    <?= $form->field($model, 'collectionPostcode')->textInput(['maxlength' => 10]) ?>
                    <?= $form->field($model, 'collectionCountryCode')->textInput(['maxlength' => 2]) ?>
                    <?= $form->field($model, 'collectionPhone')->textInput(['maxlength' => 16]) ?>
                    <?= $form->field($model, 'collectionContact')->textInput(['maxlength' => 30]) ?>
                </div>
            </div>
        </div>

        <!-- Delivery address -->
        <div class="col-md-6">
            <div class="panel panel-default">
                <div class="panel-heading">Delivery Address</div>
                <div class="panel-body">
                    <?= $form->field($model, 'deliveryName')->textInput(['maxlength' => 30]) ?>
                    <?= $form->field($model, 'deliveryStreet')->textInput(['maxlength' => 30]) ?>
                    <?= $form->field($model, 'deliveryLocation')->textInput(['maxlength' => 30]) ?>
                    <?= $form->field($model, 'deliveryTown')->textInput(['maxlength' => 30]) ?>
                    <?= $form->field($model, 'deliveryCounty')->textInput(['maxlength' => 30]) ?>
                    <?= $form->field($model, 'deliveryPostcode')->textInput(['maxlength' => 10]) ?>
                    <?= $form->field($model, 'deliveryCountryCode')->textInput(['maxlength' => 2]) ?>
                    <?= $form->field($model, 'deliveryPhone')->textInput(['maxlength' => 16]) ?>
                    <?= $form->field($model, 'deliveryContact')->textInput(['maxlength' => 30]) ?>
                </div>
            </div>
        </div>

    </div><!-- .row -->

    <div class="panel panel-default">
        <div class="panel-heading">Consignment Details</div>
        <div class="panel-body">
            <div class="row">
                <div class="col-md-4">
                    <?= $form->field($model, 'collectionDate')->textInput([
                        'placeholder' => 'YYYYMMDD',
                        'maxlength'   => 8,
                    ])->hint('Format: YYYYMMDD') ?>
                </div>
                <div class="col-md-4">
                    <?= $form->field($model, 'serviceName')->dropDownList($serviceOptions) ?>
                </div>
                <div class="col-md-4">
                    <?= $form->field($model, 'consignmentType')->dropDownList($consignmentTypeOptions) ?>
                </div>
            </div>
            <div class="row">
                <div class="col-md-3">
                    <?= $form->field($model, 'palletType')->dropDownList($palletTypeOptions) ?>
                </div>
                <div class="col-md-3">
                    <?= $form->field($model, 'numberOfPallets')->textInput(['type' => 'number', 'min' => 1]) ?>
                </div>
                <div class="col-md-3">
                    <?= $form->field($model, 'palletSpaces')->textInput(['type' => 'number', 'min' => 1]) ?>
                </div>
                <div class="col-md-3">
                    <?= $form->field($model, 'weight')->textInput(['type' => 'number', 'min' => 1, 'step' => '0.1'])->hint('Rounded up to nearest kg') ?>
                </div>
            </div>
            <div class="row">
                <div class="col-md-6">
                    <?= $form->field($model, 'customerReference')->textInput() ?>
                </div>
                <div class="col-md-6">
                    <?= $form->field($model, 'customerReference2')->textInput() ?>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4">
                    <?= $form->field($model, 'surcharges')->textInput([
                        'placeholder' => 'e.g. TL AM',
                    ])->hint('Space-separated surcharge codes. E.g. TL AM SA') ?>
                </div>
                <div class="col-md-4">
                    <?= $form->field($model, 'insuranceCode')->textInput(['maxlength' => 8]) ?>
                </div>
                <div class="col-md-4">
                    <?= $form->field($model, 'acceptedStatus')->dropDownList([
                        'Y' => 'Y – Accept immediately',
                        'N' => 'N – Pending acceptance',
                    ]) ?>
                </div>
            </div>
            <?= $form->field($model, 'notes')->textarea(['rows' => 3])->hint('Appears as NOTE1 on the label.') ?>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">Notifications</div>
        <div class="panel-body">
            <div class="row">
                <div class="col-md-6">
                    <?= $form->field($model, 'notificationEmail')->input('email') ?>
                </div>
                <div class="col-md-6">
                    <?= $form->field($model, 'notificationSms')->textInput() ?>
                </div>
            </div>
        </div>
    </div>

    <div class="form-group">
        <?= Html::submitButton('Create Consignment', ['class' => 'btn btn-success']) ?>
        <?= Html::a('Cancel', ['/palletforce/config'], ['class' => 'btn btn-default']) ?>
    </div>

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

</div>
