| Current Path : /var/www/html/crm/views/quotation/ |
| Current File : /var/www/html/crm/views/quotation/_form.php.20210816 |
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use app\models\ParamList;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
use app\models\Vendor;
use app\models\Company;
use app\models\Customer;
use app\models\QuotationItem;
/* @var $this yii\web\View */
/* @var $model app\models\Quotation */
/* @var $form yii\widgets\ActiveForm */
$ParamList = new ParamList();
$this->registerJs("$('.datepicker').datepicker({
rtl: KTUtil.isRTL(),
todayHighlight: true,
orientation: 'bottom left',
format: 'yyyy-mm-dd',
clearBtn: true,
todayHighlight: true,
});");
$this->registerJs("$('#quotation-doc_date').datepicker({
rtl: KTUtil.isRTL(),
todayHighlight: true,
orientation: 'bottom left',
format: 'yyyy-mm-dd',
clearBtn: true,
todayHighlight: true,
});
$('#quotation-valid_dt').datepicker({
rtl: KTUtil.isRTL(),
todayHighlight: true,
orientation: 'bottom left',
format: 'yyyy-mm-dd',
clearBtn: true,
todayHighlight: true,
});");
?>
<div class="quotation-form">
<div class="kt-container kt-container--fluid kt-grid__item kt-grid__item--fluid">
<div class="kt-portlet kt-portlet--mobile">
<div class="kt-portlet__body kt-portlet__body--fit">
<div class="kt-portlet__head">
<div class="kt-portlet__head-label">
<span class="kt-font-info"><i class="fas fa-info-circle"></i> Field with <span class="required">*</span> is required</span>
</div>
</div>
<div class="kt-portlet__body">
<?php $form = ActiveForm::begin(['options' => ['class' => 'kt-form kt-form--label-right']]); ?>
<?php $form->errorSummary($model); ?>
<div class="row">
<div class="col-6">
<div class='form-group-custom'>
<?php
$disabled = false;
if (Yii::$app->controller->action->id == 'update')
$disabled = true;
echo $form->field($model, 'company_id', [
'template' => "{label}<span class='required'>*</span>{input}<span class='kt-font-danger font-weight-bold'>{error}</span>"])
->dropDownList(ArrayHelper::map(Company::find()->alias('c')->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'), [
'disabled' => $disabled, 'prompt' => '- Please choose -',
'class' => 'form-control kt-selectpicker', 'data-live-search' => 'true']);
?>
</div>
</div>
<div class="col-3">
<div class='form-group-custom'>
<?=
$form->field($model, 'doc_date', [
'template' => "{label}<span class='required'>*</span>
<div class='input-group'>
{input}
<div class='input-group-append'><span class='input-group-text'><i class='la la-calendar-check-o'></i></span></div>
</div>
<span class='kt-font-danger font-weight-bold'>{error}</span>"
])->textInput(['readonly' => true]);
?>
</div>
</div>
<div class="col-3">
<div class='form-group-custom'>
<?=
$form->field($model, 'valid_dt', [
'template' => "{label}<span class='required'>*</span>
<div class='input-group'>
{input}
<div class='input-group-append'><span class='input-group-text'><i class='la la-calendar-check-o'></i></span></div>
</div>
<span class='kt-font-danger font-weight-bold'>{error}</span>"
])->textInput(['readonly' => true]);
?>
</div>
</div>
<div class="col-6">
<div class='form-group-custom'>
<?=
$form->field($model, 'customer_id', [
'template' => "{label}{input}<span class='kt-font-danger font-weight-bold'>{error}</span>"])
->dropDownList(ArrayHelper::map(Customer::find()->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'), [
'prompt' => '- Please choose -', 'class' => 'form-control kt-selectpicker', 'data-live-search' => 'true', 'onchange' => 'changecustomer(this.value)']);
?>
</div>
</div>
<div class="col-6">
<div class='form-group-custom'>
<?=
$form->field($model, 'customer_name', [
'template' => "{label}<span class='required'>*</span>{input}<span class='kt-font-danger font-weight-bold'>{error}</span>"
])->textInput(['maxlength' => true]);
?>
</div>
</div>
<div class="col-6">
<div class='form-group-custom'>
<?=
$form->field($model, 'customer_address1', [
'template' => "{label}<span class='required'>*</span>{input}<span class='kt-font-danger font-weight-bold'>{error}</span>"
])->textInput(['maxlength' => true, 'placeholder' => "Address Line 1"]);
?>
</div>
</div>
<div class="col-6">
<div class='form-group-custom'>
<?=
$form->field($model, 'customer_address2', [
'template' => "<label class='control-label'> </label>{input}<span class='kt-font-danger font-weight-bold'>{error}</span>"
])->textInput(['maxlength' => true, 'placeholder' => "Address Line 2"])->label(false);
?>
</div>
</div>
<div class="col-3">
<div class='form-group-custom'>
<?=
$form->field($model, 'customer_postcode', [
'template' => "{label}<span class='required'>*</span>{input}<span class='kt-font-danger font-weight-bold'>{error}</span>"
])->textInput(['maxlength' => true]);
?>
</div>
</div>
<div class="col-3">
<div class='form-group-custom'>
<?=
$form->field($model, 'customer_city', [
'template' => "{label}<span class='required'>*</span>{input}<span class='kt-font-danger font-weight-bold'>{error}</span>"
])->textInput(['maxlength' => true]);
?>
</div>
</div>
<div class="col-6">
<div class='form-group-custom'>
<?=
$form->field($model, 'customer_state', [
'template' => "{label}<span class='required'>*</span>{input}<span class='kt-font-danger font-weight-bold'>{error}</span>"])
->dropDownList($ParamList->getparamlist(3), ['class' => 'form-control kt-selectpicker']);
?>
</div>
</div>
<div class="col-3">
<div class='form-group-custom'>
<?=
$form->field($model, 'customer_pic', [
'template' => "{label}<span class='required'>*</span>
<div class='input-group'>
{input}
<div class='input-group-append'>
<button class='btn btn-warning' type='button' onclick='choosecontact()'>Select</button>
</div>
</div>
<span class='kt-font-danger font-weight-bold'>{error}</span>"
])->textInput(['maxlength' => true, 'placeholder' => 'Click "Select" to choose from "Contact Person"']);
?>
</div>
</div>
<div class="col-3">
<div class='form-group-custom'>
<?=
$form->field($model, 'customer_phone', [
'template' => "{label}<span class='required'>*</span>{input}<span class='kt-font-danger font-weight-bold'>{error}</span>"
])->textInput(['maxlength' => true]);
?>
</div>
</div>
<div class="col-6">
<div class='form-group-custom'>
<div class='form-group'>
<label class="control-label">Warranty Period</label>
<div class="input-daterange input-group" id="kt_datepicker_4_4">
<?= Html::activeTextInput($model, 'waranty_start', ['placeholder' => 'Start date', 'class' => 'form-control', 'readonly' => true]); ?>
<div class="input-group-append"><span class="input-group-text"><i class="la la-ellipsis-h"></i></span></div>
<?= Html::activeTextInput($model, 'waranty_end', ['placeholder' => 'End date', 'class' => 'form-control', 'readonly' => true]); ?>
</div>
</div>
</div>
</div>
</div>
<?php
$output = '';
$modelItem = QuotationItem::find()->where(['doc_id' => $model->id])->orderBy(['sorting' => SORT_ASC])->all();
if (!empty($modelItem)) {
$output .= '<table class="table table-bordered table-striped" id="tableitem">
<thead>
<tr class="thead-dark">
<th width="10%">No</th>
<th>Description</th>
<th width="10%">UoM</th>
<th width="10%">Qty</th>
<th width="10%">Unit Price (RM)</th>
<th width="10%">Total (RM)</th>
<th width="1%">Action</th>
</tr>
</thead><tbody>';
foreach ($modelItem as $rowItem) {
$output .= '<tr id="rowitem_' . $rowItem->id . '">
<td>
<input type="hidden" value="' . $rowItem->id . '" name="item_no[]">
<input type="text" class="form-control" value="' . $rowItem->sorting . '" name="sorting_' . $rowItem->id . '">
</td>
<td><textarea class="form-control" rows="3" name="product_name_' . $rowItem->id . '">' . $rowItem->product_name . '</textarea></td>
<td><input type="text" class="form-control" name="uom_' . $rowItem->id . '" value="' . $rowItem->uom . '"></td>
<td><input type="text" class="form-control" name="quantity_' . $rowItem->id . '" value="' . $rowItem->quantity . '"></td>
<td><input type="text" class="form-control" name="unit_price_' . $rowItem->id . '" value="' . $rowItem->unit_price . '"></td>
<td><input type="text" class="form-control" name="total_price_' . $rowItem->id . '" value="' . $rowItem->total_price . '"></td>
<td style="text-align:center;">
<i class="fas fa-trash-alt kt-font-danger" style="cursor:pointer;" title="Delete product" onclick="deleteproduct(' . $rowItem->id . ')"></i>
</td>
</tr>';
}
$output .= '</tbody></table>';
echo $output;
}
?>
</div>
<div class="kt-portlet__foot">
<div class="kt-form__actions">
<?= Html::a('<i class="fas fa-arrow-left"></i> Back', ['index'], ['class' => 'btn btn-outline-brand']) ?>
<?= Html::a('<i class="fas fa-sync"></i> Reset', [Yii::$app->controller->action->id, 'uuid' => Yii::$app->getRequest()->getQueryParam('uuid')], ['class' => 'btn btn-outline-success']); ?>
<?= Html::submitButton('<i class="far fa-save"></i> Save', ['class' => 'btn btn-info']); ?>
<?php
if (Yii::$app->controller->action->id == 'update') {
echo Html::button('<i class="fas fa-list"></i> Add Item', ['class' => 'btn btn-outline-warning', 'onclick' => 'additem(' . $model->id . ')']);
echo ' ' . Html::a('<i class="far fa-file-pdf"></i> View Quotation', ['download', 'uuid' => Yii::$app->getRequest()->getQueryParam('uuid')], ['class' => 'btn btn-danger', 'target' => '_blank']);
}
?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="modalContact" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Contact Person List</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body"><div id="contactwrapper"></div></div>
</div>
</div>
</div>
<script>
function changecustomer(id) {
if (id !== '') {
$.ajax({
url: "index.php?r=quotation/getcustomerdetails",
method: "POST",
data: {"id": id},
success: function (response) {
if (response !== '') {
var arr = response.split("<->");
$('#quotation-customer_name').val(arr[0]);
$('#quotation-customer_address1').val(arr[1]);
$('#quotation-customer_address2').val(arr[2]);
$('#quotation-customer_postcode').val(arr[3]);
$('#quotation-customer_city').val(arr[4]);
$('#quotation-customer_state').val(arr[5]);
$('#quotation-customer_state').selectpicker('refresh');
$('#quotation-customer_pic').val(arr[6]);
$('#quotation-customer_phone').val(arr[7]);
}
},
});
}
}
function choosecontact() {
var type = 'ctc_cust';
var data_id = $('#quotation-customer_id').val();
if (data_id !== '') {
$.ajax({
url: "index.php?r=contact/getcontactlist",
method: "POST",
data: {"type": type, "data_id": data_id},
success: function (response) {
$('#contactwrapper').html(response);
$('#modalContact').modal('show');
},
});
} else {
alert("Customer cannot be empty if you want to choose Contact Person");
}
}
function changecontact(val) {
var arr = val.split("<->");
$('#quotation-customer_pic').val(arr[0]);
$('#quotation-customer_phone').val(arr[1]);
$('#modalContact').modal('hide');
}
function deleteproduct(id) {
Swal.fire({
title: 'Are you sure to delete this item?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.value) {
$.ajax({
url: "index.php?r=quotation/deleteproduct",
method: "POST",
data: {"id": id},
success: function (response) {
if (response === 'success') {
swal.fire({
position: 'center-center',
type: 'success',
title: 'Item has been deleted',
showConfirmButton: false,
timer: 1500, }).then(function (result) {
$('#rowitem_' + id).remove();
});
}
},
});
}
});
}
function additem(doc_id) {
$.ajax({
url: "index.php?r=quotation/additem",
method: "POST",
data: {"doc_id": doc_id},
success: function (response) {
$('#tableitem').append(response);
},
});
}
</script>