You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
300 lines
10 KiB
300 lines
10 KiB
3 years ago
|
var materialModal = $('#modal-material > .modal-dialog > .modal-content');
|
||
|
|
||
|
function resetFormAssignMaterial() {
|
||
|
$('#select-material').val(null).trigger("change");
|
||
|
$('#select-material').find('option').remove();
|
||
|
$('#select-material').val("");
|
||
|
$('#form-assign-material').trigger("reset");
|
||
|
$('#btn-assign-material').html('Assign');
|
||
|
$('#btn-assign-material').prop("disabled", false);
|
||
|
};
|
||
|
|
||
2 years ago
|
|
||
|
var rupiah = document.getElementById('price-req-material');
|
||
|
rupiah.addEventListener('keyup', function (e) {
|
||
|
rupiah.value = formatRibuanInput(this.value);
|
||
3 years ago
|
});
|
||
2 years ago
|
|
||
|
var qty = document.getElementById('qty-req-material');
|
||
|
qty.addEventListener('keyup', function (e) {
|
||
|
qty.value = formatRibuanInput(this.value);
|
||
2 years ago
|
});
|
||
3 years ago
|
|
||
2 years ago
|
$(document).ready(function () {
|
||
3 years ago
|
var tableMaterial = $("#table-material").DataTable({
|
||
|
"processing": true,
|
||
|
"serverSide": true,
|
||
|
"ajax": {
|
||
|
"url": `${base_url}assign-material/datatables`,
|
||
|
"data": function (d) {
|
||
|
d.idact = activityId;
|
||
|
}
|
||
|
},
|
||
|
"columns": [
|
||
|
|
||
|
{ data: 'material_name', name: 'material_name' },
|
||
2 years ago
|
{
|
||
|
data: 'qty_planning', render: function (data, type) {
|
||
|
return data ? formatRupiah(data) : '-'
|
||
|
}
|
||
|
},
|
||
3 years ago
|
{ data: 'uom', name: 'uom' },
|
||
|
{
|
||
|
data: 'budget', render: function (data, type) {
|
||
2 years ago
|
return data ? "Rp. " + formatRupiah(data) : '-'
|
||
3 years ago
|
}
|
||
|
},
|
||
|
{
|
||
|
data: 'plan_date', render: function (data, type) {
|
||
|
return data ? formatDate(data) : '-'
|
||
|
}
|
||
|
},
|
||
|
{
|
||
|
data: 'action',
|
||
|
name: 'action',
|
||
|
orderable: true,
|
||
|
searchable: true
|
||
|
},
|
||
|
]
|
||
|
});
|
||
|
|
||
|
function deleteMaterialAssign(id) {
|
||
|
$.ajax({
|
||
|
url: `${base_url}assign-material/delete/${id}`,
|
||
|
type: "DELETE",
|
||
|
success: function (data) {
|
||
|
actionHappen = true;
|
||
|
gantt.alert("Delete Material Assign Success!");
|
||
|
tableMaterial.draw();
|
||
|
},
|
||
|
error: function (data) {
|
||
|
gantt.alert("Delete Material Assign Failed, try again later!");
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
$("#modal-material").on("click", "#show-form-material", function () {
|
||
|
$(this).hide();
|
||
|
$("#hide-form-material").show();
|
||
|
$("#form-assign-material").show();
|
||
|
});
|
||
|
|
||
|
$("#modal-material").on("click", "#hide-form-material", function () {
|
||
|
$(this).hide();
|
||
|
resetFormAssignMaterial()
|
||
|
$("#show-form-material").show();
|
||
|
});
|
||
|
|
||
|
$('#modal-material').on('show.bs.modal', function (event) {
|
||
3 years ago
|
$('#modal-material-title').html("Material Resource " + activityName);
|
||
3 years ago
|
tableMaterial.draw();
|
||
|
});
|
||
|
|
||
|
$('#modal-material').on('hide.bs.modal', function (event) {
|
||
|
// $("#hide-form-material").hide();
|
||
|
$("#show-form-material").show();
|
||
|
console.log("there's before action change ", actionHappen);
|
||
|
if (actionHappen) {
|
||
|
console.log("there's action change ", actionHappen);
|
||
|
updateActivity(activityId);
|
||
|
}
|
||
|
resetFormAssignMaterial();
|
||
|
});
|
||
|
|
||
|
$('#select-material').select2({
|
||
|
dropdownParent: materialModal,
|
||
|
placeholder: 'Pilih material resource',
|
||
|
allowClear: true,
|
||
|
ajax: {
|
||
|
url: `${base_url}material-resource/select`,
|
||
|
dataType: 'json',
|
||
|
data: function (params) {
|
||
|
var query = {
|
||
|
search: params.term,
|
||
|
type: 'public',
|
||
|
idProyek: proyekId,
|
||
|
idact: activityId
|
||
|
}
|
||
|
return query;
|
||
|
},
|
||
|
processResults: function (result) {
|
||
|
return {
|
||
|
results: $.map(result, function (item) {
|
||
|
// console.log("cek item", item)
|
||
|
return {
|
||
|
text: item.description,
|
||
|
id: item.id
|
||
|
}
|
||
|
})
|
||
|
};
|
||
|
},
|
||
|
cache: false
|
||
|
}
|
||
|
});
|
||
|
|
||
2 years ago
|
$('#select-material-integration').select2({
|
||
|
dropdownParent: materialModal,
|
||
|
placeholder: 'Pilih material',
|
||
|
allowClear: true,
|
||
|
ajax: {
|
||
2 years ago
|
url: `${adwIntegrationUrl}/request-material/get-material-integration`,
|
||
|
type: "get",
|
||
2 years ago
|
delay: 1000,
|
||
2 years ago
|
data: function (params) {
|
||
|
var query = {
|
||
|
'name': params.term,
|
||
|
}
|
||
|
return query;
|
||
|
},
|
||
2 years ago
|
headers: {
|
||
2 years ago
|
'Authorization': `Bearer ${token}`
|
||
2 years ago
|
},
|
||
|
processResults: function (data) {
|
||
|
var dataIntegrasiMaterial = [];
|
||
2 years ago
|
if (data.data) {
|
||
2 years ago
|
for(var i = 0; i < data.data.length; i++){
|
||
|
var newData = {
|
||
|
id: data.data[i].description,
|
||
|
text: data.data[i].description,
|
||
|
}
|
||
|
dataIntegrasiMaterial.push(newData);
|
||
|
}
|
||
|
}
|
||
|
return {
|
||
|
results: dataIntegrasiMaterial
|
||
|
};
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
3 years ago
|
$("#form-assign-material").on('submit', function (e) {
|
||
|
e.preventDefault();
|
||
|
|
||
|
$('#btn-assign-material').html('Assign...');
|
||
|
$('#btn-assign-material').prop("disabled", true);
|
||
|
|
||
|
// /request-material/add
|
||
2 years ago
|
let desc_req_material = $("#select-material-integration").val();
|
||
3 years ago
|
let required_date = $("#required-date-req-material").val();
|
||
|
let plan_date = $("#required-date-plan-material").val();
|
||
|
let uom = $("#uom-req-material").val();
|
||
|
let price = $("#price-req-material").val();
|
||
2 years ago
|
let qty_planning = $("#qty-req-material").val();
|
||
3 years ago
|
let material_id = null;
|
||
|
|
||
|
let payload = {
|
||
|
description: desc_req_material,
|
||
|
fom_date: required_date,
|
||
|
required_date: required_date,
|
||
|
proyek_id: proyekId,
|
||
|
uom: uom,
|
||
2 years ago
|
qty: formatReplaceTitikRibuan(qty_planning),
|
||
3 years ago
|
price: formatReplaceTitikRibuan(price)
|
||
3 years ago
|
}
|
||
|
$.ajax({
|
||
|
data: JSON.stringify(payload),
|
||
|
url: `${base_url}request-material/add`,
|
||
|
type: "POST",
|
||
|
processData: false,
|
||
|
contentType: false,
|
||
|
success: function (data) {
|
||
|
if (data && data.code === 200) {
|
||
|
material_id = data.data.id;
|
||
|
// actionHappen = true;
|
||
|
// gantt.alert("Material Request Success!");
|
||
|
// tableMaterial.draw();
|
||
|
resetFormAssignMaterial();
|
||
|
|
||
|
let payloadAssign = {
|
||
|
proyek_id: proyekId,
|
||
|
activity_id: activityId,
|
||
|
material_id: material_id,
|
||
|
qty_planning: qty_planning,
|
||
|
plan_date: plan_date
|
||
|
// budget: budget
|
||
|
}
|
||
|
$.ajax({
|
||
|
data: JSON.stringify(payloadAssign),
|
||
|
url: `${base_url}assign-material/add`,
|
||
|
type: "POST",
|
||
|
processData: false,
|
||
|
contentType: false,
|
||
|
success: function (data) {
|
||
|
if (data && data.code === 200) {
|
||
|
actionHappen = true;
|
||
|
gantt.alert("Material Assign Success!");
|
||
|
tableMaterial.draw();
|
||
|
resetFormAssignMaterial();
|
||
|
}
|
||
|
else {
|
||
|
gantt.alert({ type: "error", text: data.message });
|
||
|
$('#btn-assign-material').html('Assign');
|
||
|
$('#btn-assign-material').prop("disabled", false);
|
||
|
}
|
||
|
},
|
||
|
error: function (data) {
|
||
|
gantt.alert("Material Assign Failed, try again later!");
|
||
|
resetFormAssignMaterial();
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
else {
|
||
|
gantt.alert({ type: "error", text: data.message });
|
||
|
$('#btn-assign-material').html('Assign');
|
||
|
$('#btn-assign-material').prop("disabled", false);
|
||
|
}
|
||
|
},
|
||
|
error: function (data) {
|
||
|
gantt.alert("Material Request Failed, try again later!");
|
||
|
resetFormAssignMaterial();
|
||
|
}
|
||
|
});
|
||
|
|
||
2 years ago
|
// let material_id = $("#select-material").val();
|
||
3 years ago
|
|
||
|
// if (!material_id || material_id < 0) {
|
||
|
// gantt.alert("Please choose material to assign!");
|
||
|
// $('#btn-assign-material').html('Assign');
|
||
|
// $('#btn-assign-material').prop("disabled", false);
|
||
|
// return false
|
||
|
// }
|
||
|
|
||
|
// if (!qty_planning || qty_planning < 0) {
|
||
|
// gantt.alert("Please input qty material!");
|
||
|
// $('#btn-assign-material').html('Assign');
|
||
|
// $('#btn-assign-material').prop("disabled", false);
|
||
|
// return false
|
||
|
// }
|
||
|
|
||
|
// if(!budget || budget < 0){
|
||
|
// gantt.alert("Please input price per-unit!");
|
||
|
// $('#btn-assign-material').html('Assign');
|
||
|
// $('#btn-assign-material').prop("disabled",false);
|
||
|
// return false
|
||
|
// }
|
||
|
|
||
|
// if(material_id === null){
|
||
|
// gantt.alert("Material Assign Failed, try again later!");
|
||
|
// resetFormAssignMaterial();
|
||
|
// }else{
|
||
|
|
||
|
// }
|
||
|
|
||
|
});
|
||
|
|
||
|
// delete from row
|
||
|
$("#table-material").on("click", ".btn-material-delete", function () {
|
||
|
let id = $(this).data('id');
|
||
|
var box = gantt.confirm({
|
||
|
text: "Material resource will be deleted from activity, continue?",
|
||
|
ok: "Delete",
|
||
|
cancel: "Cancel",
|
||
|
callback: function (result) {
|
||
|
if (result) {
|
||
|
deleteMaterialAssign(id);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
});
|
||
2 years ago
|
});
|