| Current Path : /var/www/html/crm/views/invoice/ |
| Current File : /var/www/html/crm/views/invoice/_form.php |
<?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\Product;
use app\models\DeliveryOrderItem;
use app\models\User;
/* @var $this yii\web\View */
/* @var $model app\models\Invoice */
/* @var $form yii\widgets\ActiveForm */
$ParamList = new ParamList();
$Product = new Product();
?>
<div class="invoice-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']]); ?>
<div class="row">
<div class="col-3">
<div class='form-group-custom'>
<?=
$form->field($model, 'doc_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, 'onchange' => 'calcpaymentdue()']);
?>
</div>
</div>
<div class="col-3">
<div class='form-group-custom'>
<?=
$form->field($model, 'term', [
'template' => "{label}<span class='required'>*</span>{input}<span class='kt-font-danger font-weight-bold'>{error}</span>"])
->dropDownList($ParamList->getparamlist(26), ['class' => 'form-control kt-selectpicker', 'onchange' => 'calcpaymentdue()']);
?>
</div>
</div>
<div class="col-3">
<div class='form-group-custom'>
<?=
$form->field($model, 'payment_due', [
'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, 'sales_pic', [
'template' => "{label}<span class='required'>*</span>{input}<span class='kt-font-danger font-weight-bold'>{error}</span>"])
->dropDownList(ArrayHelper::map(User::find()->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'), [
'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, '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-3">
<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-3">
<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-3">
<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-3">
<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-3">
<div class='form-group-custom'>
<?=
$form->field($model, 'po_ref', [
'template' => "{label}{input}<span class='kt-font-danger font-weight-bold'>{error}</span>"
])->textInput(['maxlength' => true]);
?>
</div>
</div>
<div class="col-12">
<div class='form-group-custom'>
<?= $form->field($model, 'remarks', ['template' => "{label}{input}{error}"])->textarea(['rows' => 6]); ?>
</div>
</div>
</div>
<table class="table table-striped table-bordered">
<thead>
<tr class="thead-dark">
<th width="1%">No</th>
<th>Product</th>
<th width="10%">Quantity</th>
<th width="10%">UoM</th>
<th width="10%">Unit Price (MYR)</th>
<th width="10%">Discount (%)</th>
<th width="10%">Total (MYR)</th>
</tr>
</thead>
<tbody>
<?php
$modelItem = DeliveryOrderItem::find()->where(['doc_id' => $model->do_no])->orderBy(['id' => SORT_ASC])->all();
if (!empty($modelItem)) {
$countItem = 0;
foreach ($modelItem as $rowItem) {
$countItem++;
echo '<tr>
<td align="center" style="vertical-align:middle;">' . $countItem . '<input type="hidden" name="item_id[]" value="' . $rowItem->id . '"></td>
<td style="vertical-align:middle;">' . $Product->getname($rowItem->product_id) . '</td>
<td><input type="text" class="form-control" value="' . $rowItem->quantity . '" name="item_quantity_' . $rowItem->id . '" onchange="updatetotal(' . $rowItem->id . ')"></td>
<td><input type="text" class="form-control" value="' . $rowItem->uom . '" name="item_uom_' . $rowItem->id . '"></td>
<td><input type="text" class="form-control" value="' . $rowItem->unit_price . '" name="item_unitprice_' . $rowItem->id . '" onchange="updatetotal(' . $rowItem->id . ')"></td>
<td><input type="text" class="form-control" value="' . $rowItem->discount . '" name="item_discount_' . $rowItem->id . '" onchange="updatetotal(' . $rowItem->id . ')"></td>
<td><input type="text" class="form-control item_total" value="' . $rowItem->total . '" name="item_total_' . $rowItem->id . '"></td>
</tr>';
}
} else {
echo '<tr><td colspan="7">No record found</td></tr>';
}
?>
</tbody>
<tfoot>
<tr style="height:60px;">
<th colspan="6" class="text-right" style="vertical-align: middle;">Sub Total</th>
<td style="vertical-align: middle;"><span id="subtotal"></span></td>
</tr>
<tr>
<th colspan="5" class="text-right" style="vertical-align: middle;">
Tax
<span data-toggle="kt-tooltip" data-placement="top" data-original-title="Fill the TAX input if needed only">
<i class="fas fa-info-circle"></i>
</span>
</th>
<td class="pb-0">
<div class='form-group-custom'>
<?=
$form->field($model, 'tax', ['template' => "{label}
<div class='input-group'>{input}
<div class='input-group-append'><span class='input-group-text'>%</span></div>
</div>
<span class='kt-font-danger font-weight-bold'>{error}</span>"
])->textInput(['maxlength' => true, 'onchange' => 'updategrandtotal()'])->label(false);
?>
</div>
</td>
<td style="vertical-align: middle;"><span id="taxvalue"></span></td>
</tr>
<tr style="height:60px;">
<th colspan="6" class="text-right" style="vertical-align: middle;">Grand Total</th>
<td class="pb-0">
<div class='form-group-custom'>
<?=
$form->field($model, 'grandtotal', ['template' => "{label}{input}<span class='kt-font-danger font-weight-bold'>{error}</span>"
])->textInput(['maxlength' => true, 'readonly' => true])->label(false);
?>
</div>
</td>
<!--<td style="vertical-align: middle;"><span id="grandtotal"></span></td>-->
</tr>
</tfoot>
</table>
</div>
<div class="kt-portlet__foot">
<div class="kt-form__actions">
<?= Html::a('<i class="fas fa-arrow-left"></i> Back', [Yii::$app->getRequest()->getQueryParam('returnUrl') . '/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'), 'returnUrl' => Yii::$app->getRequest()->getQueryParam('returnUrl')], ['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::a('<i class="far fa-file-pdf"></i> View Invoice', ['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>
<?php $this->registerJs("updategrandtotal();"); ?>
<?php
$this->registerJs("$('#invoice-doc_dt').datepicker({
rtl: KTUtil.isRTL(),
todayHighlight: true,
orientation: 'bottom left',
format: 'yyyy-mm-dd',
clearBtn: true,
todayHighlight: true,
});");
$this->registerJs("$('#invoice-payment_due').datepicker({
rtl: KTUtil.isRTL(),
todayHighlight: true,
orientation: 'bottom left',
format: 'yyyy-mm-dd',
clearBtn: true,
todayHighlight: true,
});");
?>
<script>
function changecustomer(id) {
if (id !== '') {
$.ajax({
url: "index.php?r=invoice/getcustomerdetails",
method: "POST",
data: {"id": id},
success: function (response) {
if (response !== '') {
var arr = response.split("<->");
$('#invoice-customer_name').val(arr[0]);
$('#invoice-customer_address1').val(arr[1]);
$('#invoice-customer_address2').val(arr[2]);
$('#invoice-customer_postcode').val(arr[3]);
$('#invoice-customer_city').val(arr[4]);
$('#invoice-customer_state').val(arr[5]);
$('#invoice-customer_state').selectpicker('refresh');
$('#invoice-customer_pic').val(arr[6]);
$('#invoice-customer_phone').val(arr[7]);
}
},
});
}
}
function choosecontact() {
var type = 'ctc_cust';
var data_id = $('#invoice-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("<->");
$('#invoice-customer_pic').val(arr[0]);
$('#invoice-customer_phone').val(arr[1]);
$('#modalContact').modal('hide');
}
function updatetotal(item_id) {
var quantity = parseInt($("input[name=item_quantity_" + item_id + "]").val());
var unitprice = parseFloat($("input[name=item_unitprice_" + item_id + "]").val());
var discount = parseFloat($("input[name=item_discount_" + item_id + "]").val());
var total = quantity * unitprice - (discount / 100 * (unitprice * quantity));
$("input[name=item_total_" + item_id + "]").val(total.toFixed(2));
updategrandtotal();
}
function updategrandtotal() {
var subtotal = 0;
$('.item_total').each(function () {
subtotal += parseFloat($(this).val());
});
var subtotal_label = subtotal.toFixed(2);
//subtotal_label = subtotal_label.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
var tax = $('#invoice-tax').val();
var tax_value = tax / 100 * subtotal;
var tax_label = tax_value.toFixed(2);
//tax_label = tax_label.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
var grandtotal = tax_value + subtotal;
var grandtotal_label = grandtotal.toFixed(2);
//grandtotal_label = grandtotal_label.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
$('#subtotal').html(subtotal_label);
$('#taxvalue').html(tax_label);
//$('#grandtotal').html(grandtotal_label);
$('#invoice-grandtotal').val(grandtotal_label);
}
function calcpaymentdue() {
var invoice_dt = $('#invoice-doc_dt').val();
var invoice_term = $('#invoice-term').val();
$.ajax({
url: "index.php?r=invoice/calcpaymentdue",
method: "POST",
data: {"invoice_dt": invoice_dt, "invoice_term": invoice_term},
success: function (response) {
$('#invoice-payment_due').val(response);
$("#invoice-payment_due").datepicker("destroy");
$('#invoice-payment_due').datepicker({
rtl: KTUtil.isRTL(),
todayHighlight: true,
orientation: 'bottom left',
format: 'yyyy-mm-dd',
clearBtn: true,
});
$('#invoice-payment_due').datepicker("refresh");
},
});
}
</script>