{% extends 'role/user/ticket/intervention/index.html.twig' %}
{% block title %}Ticket - Intervento - Attività{% endblock %}
{% block pageTitleH1 %}Ticket - Intervento - Attività{% endblock %}
{% block pageTitleBreadcrumb %}
<li class="breadcrumb-item"><a href="{{ path ('user_ticket_sheet', {'ticketId':ticket.id}) }}">Ticket</a></li>
<li class="breadcrumb-item"><a href="javascript:void(0)">Intervento</a></li>
<li class="breadcrumb-item"><a href="javascript:void(0)">Attività</a></li>
{% endblock %}
{% block subMenuLeft %}
<li class="nav-item"><a class="nav-link" href="{{ path ('user_ticket_intervention_activity_summary', {'interventionId':intervention.id}) }}">Riassunto</a></li>
{% endblock %}
{% block subMenuRight %}
{% endblock %}
{% block interventionContent %}
<div class="row">
<div class="col-12">
<h4 class="form_title"><a onclick="showClientWarehouse()" class="cursor_p">Visualizza/Nascondi magazzino cliente</a></h4>
<hr class="m_t_none">
<div id="clientWarehouse" style="display:none">
{% if ticket.client.warehouse.products|length > 0 %}
<table class="table table_no_padding responsive_font_size">
<tbody>
{% for p in ticket.client.warehouse.products %}
{% if loop.index > 1 %}
<tr><th colspan="2" style="padding-top: 10px!important; padding-bottom: 10px!important;border-bottom-width: 0px;"><hr style="height:1px !important; margin:0px"></th></tr>
{% endif %}
<tr>
<th class="td_w_100p" style="border-bottom: 0px">Modello</th>
<td style="border-bottom: 0px">{{ p.model.name }} ({{ p.model.sku }})</td>
</tr>
<tr>
<th style="border-bottom: 0px">Termid</th>
<td style="border-bottom: 0px">{{ p.termid }}</td>
</tr>
<tr>
<th style="border-bottom: 0px">Matr. Produttore</th>
<td style="border-bottom: 0px">{% if p.codeProducer != null %}<a href="javascript: copyToClipboard({{ p.id }}, 'producer')" class="underline" data-bs-toggle="tooltip" title="Copia matricola">{{ p.codeProducer }}</a>{% else %}---{% endif %}</td>
</tr>
<tr>
<th style="border-bottom: 0px">Matr. Fornitore</th>
<td style="border-bottom: 0px">{% if p.codeSupplier != null %}<a href="javascript: copyToClipboard({{ p.id }}, 'supplier')" class="underline" data-bs-toggle="tooltip" title="Copia matricola">{{ p.codeSupplier }}</a>{% else %}---{% endif %}</td>
</tr>
<input type="hidden" id="product_{{ p.id }}_producer" value="{{ p.codeProducer }}">
<input type="hidden" id="product_{{ p.id }}_supplier" value="{{ p.codeSupplier }}">
{% endfor %}
</tbody>
</table>
{% else %}
<div class="style-msg infomsg">
<div class="sb-msg responsive_font_size">
<i class="icon-info-sign"></i><strong>Info:</strong> Nessuna matricola registrata presente su questo cliente!
</div>
</div>
{% endif %}
</div>
</div>
</div>
<input type="hidden" id="can_submit_withdraw" value="0">
<input type="hidden" id="can_submit_installation" value="0">
<input type="hidden" id="can_submit_actual" value="0">
{{ form_start(form, {'attr': {'novalidate': 'novalidate', 'id':'form'}}) }}
<div class="row">
<div class="col-12">
<h4 class="form_title">Dettaglia l'attività: {{ activityType.value }}</h4>
<hr class="m_t_none">
</div>
</div>
{# Ritiro #}
{% if activityType.producerWithdrawMandatory or activityType.supplierWithdrawMandatory %}
{% if activityType.producerWithdrawMandatory %}
<div class="row form-group">
<div class="col-10 col-lg-11">
<label class="form_label">Ritiro - Matricola produttore*</label>
<div {{ form_errors(form.producerWithdraw) }}>
{{ form_widget(form.producerWithdraw, {'attr':{'inputmode':'search', 'onKeyDown':'updateButtonSubmit()', 'onBlur':'onBlurManageBarcode("producer_withdraw")'}}) }}
</div>
</div>
<div class="col-2 col-lg-1 txt_a_c">
<a href="javascript:openScanditModal('producer_withdraw', 'produttore')"><img src="{{ asset (icon_frame) }}" width="38" class="icon_pr m_t_33p" data-bs-toggle="tooltip" title="Scansiona"></a>
</div>
</div>
{% else %}
{{ form_widget(form.producerWithdraw, {'attr':{'class':'display_n'}}) }}
{% endif %}
{% if activityType.supplierWithdrawMandatory %}
<div class="row form-group">
<div class="col-10 col-lg-11">
<label class="form_label">Ritiro - Matricola fornitore*</label>
<div {{ form_errors(form.supplierWithdraw) }}>
{{ form_widget(form.supplierWithdraw, {'attr':{'onKeyDown':'updateButtonSubmit()', 'onBlur':'onBlurManageBarcode("supplier_withdraw")'}}) }}
</div>
</div>
<div class="col-2 col-lg-1 txt_a_c">
<a href="javascript:openScanditModal('supplier_withdraw', 'fornitore')"><img src="{{ asset (icon_frame) }}" width="38" class="icon_pr m_t_33p" data-bs-toggle="tooltip" title="Scansiona"></a>
</div>
</div>
{% else %}
{{ form_widget(form.supplierWithdraw, {'attr':{'class':'display_n'}}) }}
{% endif %}
<div class="row form-group" id="row_model_withdraw">
<div class="col-10 col-lg-11">
<label class="form_label">Ritiro - Modello</label>
<div {{ form_errors(form.modelWithdraw) }}>
{{ form_widget(form.modelWithdraw, {'attr':{'class':'form-control', 'readonly':true}} ) }}
</div>
</div>
<div class="col-2 col-lg-1 txt_a_c">
<a href="javascript: selectFromWarehouse('withdraw')"><img src="{{ asset (icon_selection) }}" width="38" class="icon_pr m_t_33p" data-bs-toggle="tooltip" title="Seleziona"></a>
</div>
<div class="col-12 switch" id="row_component_withdraw" style="display: none">
</div>
</div>
{% else %}
{{ form_widget(form.modelWithdraw, {'attr':{'class':'display_n'}}) }}
{{ form_widget(form.producerWithdraw, {'attr':{'class':'display_n'}}) }}
{{ form_widget(form.supplierWithdraw, {'attr':{'class':'display_n'}}) }}
{% endif %}
{# Installazione #}
{% if activityType.producerInstallationMandatory or activityType.supplierInstallationMandatory %}
{% if activityType.producerInstallationMandatory %}
<div class="row form-group">
<div class="col-10 col-lg-11">
<label class="form_label">Installazione - Matricola produttore*</label>
<div {{ form_errors(form.producerInstallation) }}>
{{ form_widget(form.producerInstallation, {'attr':{'inputmode':'search','onKeyDown':'updateButtonSubmit()', 'onBlur':'onBlurManageBarcode("producer_installation")'}}) }}
</div>
</div>
<div class="col-2 col-lg-1 txt_a_c">
<a href="javascript:openScanditModal('producer_installation', 'produttore')"><img src="{{ asset (icon_frame) }}" width="38" class="icon_pr m_t_33p" data-bs-toggle="tooltip" title="Scansiona"></a>
</div>
</div>
{% else %}
{{ form_widget(form.producerInstallation, {'attr':{'class':'display_n'}}) }}
{% endif %}
{% if activityType.supplierInstallationMandatory %}
<div class="row form-group">
<div class="col-10 col-lg-11">
<label class="form_label">Installazione - Matricola fornitore*</label>
<div {{ form_errors(form.supplierInstallation) }}>
{{ form_widget(form.supplierInstallation, {'attr':{'onKeyDown':'updateButtonSubmit()', 'onBlur':'onBlurManageBarcode("supplier_installation")'}}) }}
</div>
</div>
<div class="col-2 col-lg-1 txt_a_c">
<a href="javascript:openScanditModal('supplier_installation', 'fornitore')"><img src="{{ asset (icon_frame) }}" width="38" class="icon_pr m_t_33p" data-bs-toggle="tooltip" title="Scansiona"></a>
</div>
</div>
{% else %}
{{ form_widget(form.supplierInstallation, {'attr':{'class':'display_n'}}) }}
{% endif %}
<div class="row form-group" id="row_model_installation">
<div class="col-10 col-lg-11">
<label class="form_label">Installazione - Prodotto</label>
<div {{ form_errors(form.modelInstallation) }}>
{{ form_widget(form.modelInstallation, {'attr':{'readonly':true}} ) }}
</div>
</div>
<div class="col-2 col-lg-1 txt_a_c">
<a href="tel:{{ company.phoneSupportTechnician }}"><img class="icon_red m_t_33p" width="38" src="{{ asset (icon_telephone) }}" data-bs-toggle="tooltip" title="Ho un problema"/></a>
</div>
</div>
{% else %}
{{ form_widget(form.modelInstallation, {'attr':{'class':'display_n'}}) }}
{{ form_widget(form.producerInstallation, {'attr':{'class':'display_n'}}) }}
{{ form_widget(form.supplierInstallation, {'attr':{'class':'display_n'}}) }}
{% endif %}
{# Attuale #}
{% if activityType.producerActualMandatory or activityType.supplierActualMandatory %}
{% if activityType.producerActualMandatory %}
<div class="row form-group">
<div class="col-10 col-lg-11">
<label class="form_label">Attuale - Matricola produttore*</label>
<div {{ form_errors(form.producerActual) }}>
{{ form_widget(form.producerActual, {'attr':{'inputmode':'search', 'onKeyDown':'updateButtonSubmit()', 'onBlur':'onBlurManageBarcode("producer_actual")'}}) }}
</div>
</div>
<div class="col-2 col-lg-1 txt_a_c">
<a href="javascript:openScanditModal('producer_actual', 'produttore')"><img src="{{ asset (icon_frame) }}" width="38" class="icon_pr m_t_33p" data-bs-toggle="tooltip" title="Scansiona"></a>
</div>
</div>
{% else %}
{{ form_widget(form.producerActual, {'attr':{'class':'display_n'}}) }}
{% endif %}
{% if activityType.supplierActualMandatory %}
<div class="row form-group">
<div class="col-10 col-lg-11">
<label class="form_label">Attuale - Matricola fornitore*</label>
<div {{ form_errors(form.supplierActual) }}>
{{ form_widget(form.supplierActual, {'attr':{'onKeyDown':'updateButtonSubmit()', 'onBlur':'onBlurManageBarcode("supplier_actual")'}}) }}
</div>
</div>
<div class="col-2 col-lg-1 txt_a_c">
<a href="javascript:openScanditModal('supplier_actual', 'fornitore')"><img src="{{ asset (icon_frame) }}" width="38" class="icon_pr m_t_33p" data-bs-toggle="tooltip" title="Scansiona"></a>
</div>
</div>
{% else %}
{{ form_widget(form.supplierActual, {'attr':{'class':'display_n'}}) }}
{% endif %}
<div class="row form-group" id="row_model_actual">
<div class="col-10 col-lg-11">
<label class="form_label">Attuale - Modello</label>
<div {{ form_errors(form.modelActual) }}>
{{ form_widget(form.modelActual, {'attr':{'readonly':true}} ) }}
</div>
</div>
<div class="col-2 col-lg-1 txt_a_c">
<a href="javascript: selectFromWarehouse('actual')"><img src="{{ asset (icon_selection) }}" width="38" class="icon_pr m_t_33p" data-bs-toggle="tooltip" title="Seleziona"></a>
</div>
</div>
{% else %}
{{ form_widget(form.modelActual, {'attr':{'class':'display_n'}}) }}
{{ form_widget(form.producerActual, {'attr':{'class':'display_n'}}) }}
{{ form_widget(form.supplierActual, {'attr':{'class':'display_n'}}) }}
{% endif %}
<div class="row m_t_50p">
<div class="col-12 txt_a_c">
<a id="button_submit" href="javascript: void()" class="button button-3d button-small button-grey">Inserisci</a>
</div>
</div>
{{ form_widget(form.productWithdrawId) }}
{{ form_widget(form.modelWithdrawId) }}
{{ form_widget(form.scanOrManualProducerWithdraw) }}
{{ form_widget(form.scanOrManualProducerWithdrawCode) }}
{{ form_widget(form.scanOrManualSupplierWithdraw) }}
{{ form_widget(form.scanOrManualSupplierWithdrawCode) }}
{{ form_widget(form.productActualId) }}
{{ form_widget(form.modelActualId) }}
{{ form_widget(form.scanOrManualProducerActual) }}
{{ form_widget(form.scanOrManualProducerActualCode) }}
{{ form_widget(form.scanOrManualSupplierActual) }}
{{ form_widget(form.scanOrManualSupplierActualCode) }}
{{ form_widget(form.productInstallationId) }}
{{ form_widget(form.scanOrManualProducerInstallation) }}
{{ form_widget(form.scanOrManualProducerInstallationCode) }}
{{ form_widget(form.scanOrManualSupplierInstallation) }}
{{ form_widget(form.scanOrManualSupplierInstallationCode) }}
<input type="hidden" name="activityTypeId" value="{{ activityType.id }}">
<input type="hidden" name="ticketId" value="{{ ticket.id }}">
{{ form_end(form) }}
<div id="selectProductModal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header"><h3 class="modal-title">Seleziona prodotto dal magazzino cliente</h3></div>
<div class="modal-body">
<div class="row">
<div class="col-12 overflow_a">
<table id="table_products" class="table table-sm responsive_font_size">
<thead>
<tr>
<td colspan="2"><input type="text" class="form-control font_12" id="filter_search_product" onKeyPress="searchProducts()" onBlur="searchProducts()"/></td>
</tr>
</thead>
<tbody id="tbody_products">
</tbody>
</table>
</div>
</div>
</div>
<div class="modal-footer txt_a_c">
<a href="javascript:void(0)" class="button button-3d button-mini button-pr" data-bs-dismiss="modal">Chiudi</a>
</div>
</div>
</div>
</div>
<div id="selectModelModal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header"><h3 class="modal-title">Seleziona modello</h3></div>
<div class="modal-body">
<div class="row">
<div class="col-12 overflow_a">
<table id="table_models" class="table table-sm responsive_font_size">
<thead>
<tr>
<td colspan="5" class="txt_a_c"><a href="javascript: updateSelectCodeModal('products')" class="button button-3d button-mini button-pr">Cerca prodotto nel magazzino cliente</a></td>
</tr>
<tr>
<td><input type="text" class="form-control font_12" id="filter_search_model" onKeyPress="searchModels()" onBlur="searchModels()"/></td>
<td class="td_action"><a href="tel:{{ company.phoneSupportTechnician }}" data-bs-toggle="tooltip" title="Richiedi inserimento nuovo"><img class="icon_red" src="{{ asset (icon_telephone) }}" /></a></td>
</tr>
</thead>
<tbody id="tbody_models">
</tbody>
</table>
</div>
</div>
</div>
<div class="modal-footer txt_a_c">
<a href="javascript:void(0)" class="button button-3d button-mini button-pr" data-bs-dismiss="modal">Chiudi</a>
</div>
</div>
</div>
</div>
<input type="hidden" id="selected_type">
<input type="hidden" id="scanned_type">
<div id="modalWarehouseOther" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header"><h3 class="modal-title">Magazzino non corrispondente</h3></div>
<div class="modal-body">
<input type="hidden" id="move_product_id">
<input type="hidden" id="move_type">
<div class="row">
<div class="col-12 txt_a_c">
<input type="hidden" id="move_product_type" />
<label class="modal_subtitle">Attenzione!</label>
<p class="modal_paragraph">La matricola corrisponde a un prodotto che è presente nel magazzino <span id="move_warehouse_nickname" class="f_w_b"></span>!</p>
{% if app.user.accountTypology != "technician" %}
<p class="modal_paragraph">Cliccando sul bottone <a class='button button-3d button-mini button-green' href='javascript:void(0)'>sposta</a> lo inserirai nel magazzino corretto per poter chiudere l'intervento.<br>Si è sicuri di voler proseguire?</p>
{% else %}
<a href="tel:{{ company.phoneSupportTechnician }}"><img class="icon_red m_t_33p" width="38" src="{{ asset (icon_telephone) }}" data-bs-toggle="tooltip" title="Ho un problema"/></a>
{% endif %}
</div>
</div>
</div>
<div class="modal-footer">
{% if app.user.accountTypology != "technician" %}
<a href="javascript:void(0)" class="button button-3d button-mini button-red f_left" data-bs-dismiss="modal">Annulla</a>
<a href="javascript:moveProduct()" class="button button-3d button-mini button-green f_right">Sposta</a>
{% else %}
<a href="javascript:void(0)" class="button button-3d button-mini button-red" data-bs-dismiss="modal">Annulla</a>
{% endif %}
</div>
</div>
</div>
</div>
<div id="scanditReaderModal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header"><h3 class="modal-title">Inquadra matricola <span id="scandit_code_type" class="color_w"></span></h3></div>
<div class="modal-body">
<input type="hidden" id="scandit_reader_active" value="0">
<div id="data-capture-view"></div>
<a id="scandit_button_scan" href="javascript: scanditUpdateScan(1)" class="button button-3d button-mini button-green" style="position: fixed; bottom: 30%; right: 10px;">Attiva scansione</a>
</div>
<div class="modal-footer txt_a_c">
<a href="javascript:void(0)" class="button button-3d button-mini button-pr" data-bs-dismiss="modal">Chiudi</a>
</div>
</div>
</div>
</div>
{% endblock %}
{% block javascripts %}
{{ parent() }}
{% include 'components/js/scandit_js.html.twig' with {'action':'intervention'} %}
{% if activityType.pos %}{% set posAccessory = "POS" %}{% else %}{% set posAccessory = "Accessorio" %}{% endif %}
<script>
$(document).ready(function(){
{% if activityType.producerWithdrawMandatory or activityType.supplierWithdrawMandatory %}
showWithdrawModelComponent(document.getElementById('form_intervention_activity_modelWithdrawId').value);
{% endif %}
{% if activityType.producerWithdrawMandatory == false and activityType.supplierWithdrawMandatory == false %}
updateCanSubmitField("producer_withdraw", 1);
{% endif %}
{% if activityType.producerActualMandatory == false and activityType.supplierActualMandatory == false %}
updateCanSubmitField("producer_actual", 1);
{% endif %}
{% if activityType.producerInstallationMandatory == false and activityType.supplierInstallationMandatory == false %}
updateCanSubmitField("producer_installation", 1);
{% endif %}
updateButtonSubmit();
});
document.body.addEventListener("keypress", function(e) {
if(e.key == 'Enter' || e.key == 'Tab'){
switch(document.activeElement.id){
case 'form_intervention_activity_producerWithdraw': var type = 'producer_withdraw'; break;
case 'form_intervention_activity_supplierWithdraw': var type = 'supplier_withdraw'; break;
case 'form_intervention_activity_producerInstallation': var type = 'producer_installation'; break;
case 'form_intervention_activity_supplierInstallation': var type = 'supplier_installation'; break;
case 'form_intervention_activity_producerActual': var type = 'producer_actual'; break;
case 'form_intervention_activity_supplierActual': var type = 'supplier_actual'; break;
default: break;
}
document.activeElement.blur();
}
});
function openScanditModal(type, label){
document.getElementById('scanned_type').value = type;
document.getElementById('scandit_code_type').innerHTML = label;
$('#scanditReaderModal').modal({backdrop: 'static', keyboard: false}).modal("show");
}
function closeModal(){
document.getElementById('scandit_reader_active').value = 0;
$('#scanditReaderModal').modal('hide');
}
function selectFromWarehouse(type){
var typeVal = '';
document.getElementById('selected_type').value = type;
switch(type){
case 'actual': typeVal = 'Actual'; break;
case 'withdraw': typeVal = 'Withdraw'; break;
default: break;
}
if(document.getElementById('form_intervention_activity_producer' + typeVal).value != '' || document.getElementById('form_intervention_activity_supplier' + typeVal).value != ''){
searchModels();
$('#selectModelModal').modal({backdrop: 'static', keyboard: false}).modal("show");
}
else{
searchProducts();
$('#selectProductModal').modal({backdrop: 'static', keyboard: false}).modal("show");
}
}
function updateSelectCodeModal(table){
if(table == 'models'){
searchModels();
$('#selectProductModal').modal('hide');
$('#selectModelModal').modal({backdrop: 'static', keyboard: false}).modal("show");
}
else{
searchProducts();
$('#selectModelModal').modal('hide');
$('#selectProductModal').modal({backdrop: 'static', keyboard: false}).modal("show");
}
}
{# PRODUCTS #}
function searchProducts(){
var type = document.getElementById('selected_type').value;
var filter = document.getElementById('filter_search_product').value;
$.post('{{ path ("user_ticket_intervention_activity_product_search") }}', {ticketId:"{{ ticket.id }}", interventionId:"{{ intervention.id }}", activityTypeId:"{{ activityType.id }}", type:type, filter: filter, isPos:"{{ isPos }}"}, function(response){
if(response.code == 200 && response.success){
var tbody = document.getElementById('tbody_products');
tbody.innerHTML = '';
var products = JSON.parse(response.products);
if(products.length > 0){
for(i=0; i<products.length; i++){
var tr = document.createElement('tr');
var td = document.createElement('td');
var tdSel = document.createElement('td');
td.innerHTML = '<table class="table table_no_padding b_none m_b_none"><tr><th class="td_w_120p">Modello</th><td id="model_' + products[i].id + '">' + products[i].modelName + '</td></tr><tr><th>Matr. produttore</th><td id="code_producer_' + products[i].id + '">' + products[i].codeProducer + '</td></tr><tr><th id="code_supplier_' + products[i].id + '">Matr. fornitore</th><td>' + products[i].codeSupplier + '</td></tr></table>';
tdSel.className = 'td_action';
tdSel.innerHTML = '<a href="javascript: selectProduct(' + products[i].id + ')" data-bs-toggle="tooltip" title="Seleziona"><img class="icon_green" src="{{ asset (icon_select) }}" /></a>';
tr.appendChild(td);
tr.appendChild(tdSel);
tbody.appendChild(tr);
}
}
else{
var tr = document.createElement('tr');
var td = document.createElement('td');
td.setAttribute('colspan', '2');
td.innerHTML = 'La ricerca non ha trovato prodotti, <a href="javascript: updateSelectCodeModal(\'models\')" class="button button-3d button-mini button-pr">Inserisci nuovo modello</a>';
tr.appendChild(td);
tbody.appendChild(tr);
}
}
}, "json");
}
function selectProduct(productId){
if(document.getElementById('selected_type').value == 'withdraw'){
document.getElementById('form_intervention_activity_modelWithdrawId').value = null;
document.getElementById('form_intervention_activity_productWithdrawId').value = productId;
document.getElementById('form_intervention_activity_modelWithdraw').value = document.getElementById('model_' + productId).innerHTML;
document.getElementById('form_intervention_activity_producerWithdraw').value = document.getElementById('code_producer_' + productId).innerHTML;
document.getElementById('form_intervention_activity_supplierWithdraw').value = document.getElementById('code_supplier_' + productId).innerHTML;
}
if(document.getElementById('selected_type').value == 'installation'){
document.getElementById('form_intervention_activity_modelInstallationId').value = null;
document.getElementById('form_intervention_activity_productInstallationId').value = productId;
document.getElementById('form_intervention_activity_modelInstallation').value = document.getElementById('model_' + productId).innerHTML;
document.getElementById('form_intervention_activity_producerInstallation').value = document.getElementById('code_producer_' + productId).innerHTML;
document.getElementById('form_intervention_activity_supplierInstallation').value = document.getElementById('code_supplier_' + productId).innerHTML;
}
if(document.getElementById('selected_type').value == 'actual'){
document.getElementById('form_intervention_activity_modelActualId').value = null;
document.getElementById('form_intervention_activity_productActualId').value = productId;
document.getElementById('form_intervention_activity_modelActual').value = document.getElementById('model_' + productId).innerHTML;
document.getElementById('form_intervention_activity_producerActual').value = document.getElementById('code_producer_' + productId).innerHTML;
document.getElementById('form_intervention_activity_supplierActual').value = document.getElementById('code_supplier_' + productId).innerHTML;
}
$('#selectProductModal').modal({backdrop: 'static', keyboard: false}).modal("hide");
}
{# MODELS #}
function searchModels(){
var filter = document.getElementById('filter_search_model').value;
$.post('{{ path ("user_ticket_intervention_activity_model_search") }}', {interventionId: "{{ intervention.id }}", activityTypeId:"{{ activityType.id }}", isPos:"{{ isPos }}", filter: filter}, function(response){
if(response.code == 200 && response.success){
var tbody = document.getElementById('tbody_models');
tbody.innerHTML = '';
var models = JSON.parse(response.models);
if(models.length > 0){
for(i=0; i<models.length; i++){
var tr = document.createElement('tr');
var td = document.createElement('td');
var tdName = document.createElement('td');
var tdSel = document.createElement('td');
td.innerHTML = '<table class="table table_no_padding b_none m_b_none"><tr><th class="td_w_70p">Modello</th><td id="name_' + models[i].id + '">' + models[i].name + '<td><tr><th>Cat/S.Cat</th><td>' + models[i].category + '/' + models[i].subcategory + '</td></tr><tr><th>Produttore</th><td>' + models[i].producer + '</td></tr></table>';
tdSel.className = 'td_action';
tdSel.innerHTML = '<a href="javascript: selectModel(' + models[i].id + ')" data-bs-toggle="tooltip" title="Seleziona"><img class="icon_green" src="{{ asset (icon_select) }}" /></a>';
tr.appendChild(td);
tr.appendChild(tdSel);
tbody.appendChild(tr);
}
}
else{
var tr = document.createElement('tr');
var td = document.createElement('td');
td.setAttribute('colspan', '2');
td.innerHTML = 'La ricerca non ha trovato modelli. Controlla la correttezza della ricerca o richiedi di inserire il modello attraverso il pulsante telefono.';
tr.appendChild(td);
tbody.appendChild(tr);
}
}
}, "json");
}
function selectModel(modelId){
if(document.getElementById('selected_type').value == 'withdraw'){
document.getElementById('form_intervention_activity_modelWithdrawId').value = modelId;
document.getElementById('form_intervention_activity_modelWithdraw').value = document.getElementById('name_' + modelId).innerHTML;
showWithdrawModelComponent(modelId);
}
if(document.getElementById('selected_type').value == 'installation'){
document.getElementById('form_intervention_activity_modelInstallationId').value = modelId;
document.getElementById('form_intervention_activity_modelInstallation').value = document.getElementById('name_' + modelId).innerHTML;
}
if(document.getElementById('selected_type').value == 'actual'){
document.getElementById('form_intervention_activity_modelActualId').value = modelId;
document.getElementById('form_intervention_activity_modelActual').value = document.getElementById('name_' + modelId).innerHTML;
}
$('#selectModelModal').modal({backdrop: 'static', keyboard: false}).modal("hide");
}
function showWithdrawModelComponent(modelId){
$.post('{{ path ("user_ticket_intervention_activity_model_components") }}', {activityTypeId: "{{ activityType.id }}", modelId: modelId}, function(response){
if(response.code == 200 && response.success){
var components = JSON.parse(response.components);
var rowComponent = document.getElementById('row_component_withdraw');
rowComponent.innerHTML = '';
rowComponent.className = 'col-12 switch m_t_20p';
var table = document.createElement('table');
table.className = "table b_none table_no_padding m_none";
if(components.length == 0){
var tr = document.createElement('tr');
tr.innerHTML = '<td style="border-bottom: 2px solid #fff!important;"><label class="m_b_none l_s_none f_w_500 p_tb_0p">Nessun componente associato a questo modello</label></td>';
table.appendChild(tr);
}
else{
var label = document.createElement('label');
label.className = 'm_b_none l_s_none f_w_500';
label.innerHTML = 'Seleziona i componenti che hai ritirato insieme al prodotto/modello';
for(i=0; i<components.length; i++){
var tr = document.createElement('tr');
tr.innerHTML = '<td class="td_w_40p" style="border-bottom: 2px solid #fff!important;"><input id="component_' + components[i].id + '" class="switch-toggle switch-flat-mini switch-toggle-flat" type="checkbox" name="component_' + components[i].id + '"><label for="component_' + components[i].id + '" class="m_b_none p_tb_0p"></label></td><td class="txt_a_l" style="border-bottom: 2px solid #fff!important;"><label class="m_b_none l_s_none f_w_500 p_tb_0p">' + components[i].name + '</label></td>';
table.appendChild(tr);
}
rowComponent.appendChild(label);
}
rowComponent.appendChild(table);
rowComponent.style.display = 'block';
}
}, "json");
}
function onBlurManageBarcode(type){
document.getElementById("move_type").value = type;
switch(type){
case 'producer_withdraw':
document.getElementById("move_product_type").value = "withdraw";
var codeTypeLabel = "produttore";
var code = document.getElementById('form_intervention_activity_producerWithdraw').value;
if(document.getElementById('form_intervention_activity_scanOrManualProducerWithdrawCode').value != code){
document.getElementById('form_intervention_activity_scanOrManualProducerWithdrawCode').value = code;
document.getElementById('form_intervention_activity_scanOrManualProducerWithdraw').value = 'manual';
}
break;
case 'supplier_withdraw':
document.getElementById("move_product_type").value = "withdraw";
var codeTypeLabel = "fornitore";
var code = document.getElementById('form_intervention_activity_supplierWithdraw').value;
if(document.getElementById('form_intervention_activity_scanOrManualSupplierWithdrawCode').value != code){
document.getElementById('form_intervention_activity_scanOrManualSupplierWithdrawCode').value = code;
document.getElementById('form_intervention_activity_scanOrManualSupplierWithdraw').value = 'manual';
}
break;
case 'producer_installation':
document.getElementById("move_product_type").value = "installation";
var codeTypeLabel = "produttore";
var code = document.getElementById('form_intervention_activity_producerInstallation').value;
if(document.getElementById('form_intervention_activity_scanOrManualProducerInstallationCode').value != code){
document.getElementById('form_intervention_activity_scanOrManualProducerInstallationCode').value = code;
document.getElementById('form_intervention_activity_scanOrManualProducerInstallation').value = 'manual';
}
break;
case 'supplier_installation':
document.getElementById("move_product_type").value = "installation";
var codeTypeLabel = "fornitore";
var code = document.getElementById('form_intervention_activity_supplierInstallation').value;
if(document.getElementById('form_intervention_activity_scanOrManualSupplierInstallationCode').value != code){
document.getElementById('form_intervention_activity_scanOrManualSupplierInstallationCode').value = code;
document.getElementById('form_intervention_activity_scanOrManualSupplierInstallation').value = 'manual';
}
break;
case 'producer_actual':
document.getElementById("move_product_type").value = "actual";
var codeTypeLabel = "produttore";
var code = document.getElementById('form_intervention_activity_producerActual').value;
if(document.getElementById('form_intervention_activity_scanOrManualProducerActualCode').value != code){
document.getElementById('form_intervention_activity_scanOrManualProducerActualCode').value = code;
document.getElementById('form_intervention_activity_scanOrManualProducerActual').value = 'manual';
}
break;
case 'supplier_actual':
document.getElementById("move_product_type").value = "actual";
var codeTypeLabel = "fornitore";
var code = document.getElementById('form_intervention_activity_supplierActual').value;
if(document.getElementById('form_intervention_activity_scanOrManualSupplierActualCode').value != code){
document.getElementById('form_intervention_activity_scanOrManualSupplierActualCode').value = code;
document.getElementById('form_intervention_activity_scanOrManualSupplierActual').value = 'manual';
}
break;
default: break;
}
checkCodePost(type, code, codeTypeLabel);
}
function manageBarcode(code){
var type = document.getElementById('scanned_type').value;
switch(type){
case 'producer_withdraw':
document.getElementById("move_product_type").value = "withdraw";
var codeTypeLabel = "produttore";
document.getElementById('form_intervention_activity_scanOrManualProducerWithdrawCode').value = code;
document.getElementById('form_intervention_activity_scanOrManualProducerWithdraw').value = 'scan';
break;
case 'supplier_withdraw':
document.getElementById("move_product_type").value = "withdraw";
var codeTypeLabel = "fornitore";
document.getElementById('form_intervention_activity_scanOrManualSupplierWithdrawCode').value = code;
document.getElementById('form_intervention_activity_scanOrManualSupplierWithdraw').value = 'scan';
break;
case 'producer_installation':
document.getElementById("move_product_type").value = "installation";
var codeTypeLabel = "produttore";
document.getElementById('form_intervention_activity_scanOrManualProducerInstallationCode').value = code;
document.getElementById('form_intervention_activity_scanOrManualProducerInstallation').value = 'scan';
break;
case 'supplier_installation':
document.getElementById("move_product_type").value = "installation";
var codeTypeLabel = "fornitore";
document.getElementById('form_intervention_activity_scanOrManualSupplierInstallationCode').value = code;
document.getElementById('form_intervention_activity_scanOrManualSupplierInstallation').value = 'scan';
break;
case 'producer_actual':
document.getElementById("move_product_type").value = "actual";
var codeTypeLabel = "produttore";
document.getElementById('form_intervention_activity_scanOrManualProducerActualCode').value = code;
document.getElementById('form_intervention_activity_scanOrManualProducerActual').value = 'scan';
break;
case 'supplier_actual':
document.getElementById("move_product_type").value = "actual";
var codeTypeLabel = "fornitore";
document.getElementById('form_intervention_activity_scanOrManualSupplierActualCode').value = code;
document.getElementById('form_intervention_activity_scanOrManualSupplierActual').value = 'scan';
break;
default: break;
}
checkCodePost(type, code, codeTypeLabel);
}
function checkCodePost(type, code, codeTypeLabel){
var code = code.toUpperCase();
$.post('{{ path ("user_ticket_intervention_activity_product_search_code") }}', {ticketId:"{{ ticket.id }}", interventionId:"{{ intervention.id }}", activityTypeId:"{{ activityType.id }}", type:type, code:code}, function(response){
var response = JSON.parse(response);
var canSubmit = false;
if(response.code == 200 && response.success)
{
if(response.found){
// Se trovato prodotto
var product = JSON.parse(response.product);
if(product.posAccessoryOk){
// Se POS o Accessorio coerente con il tipo di attività
if(product.supplierOk){
// Se il fornitore è tra quelli del prodotto
if(product.otherWarehouse == 1){
// Se non è nel magazzino corretto
if(product.canMove == 1){
document.getElementById('move_product_id').value = product.id;
document.getElementById('move_warehouse_nickname').innerHTML = product.otherWarehouseNickname;
$('#modalWarehouseOther').modal({backdrop: 'static', keyboard: false}).modal('show');
updateCanSubmitField(type, 0);
}
else{
// Se installazione e non posso muovere
printAlertWarning("Il prodotto trovato con codice " + codeTypeLabel + " \"" + code + "\" non può essere spostato perché non è nello stato corretto!");
updateCanSubmitField(type, 0);
}
}
else{
// Se in magazzino corretto
switch(type){
case 'producer_withdraw':
case 'supplier_withdraw':
document.getElementById('form_intervention_activity_productWithdrawId').value = product.id;
document.getElementById('form_intervention_activity_modelWithdraw').value = product.model;
document.getElementById('form_intervention_activity_producerWithdraw').value = product.codeProducer;
document.getElementById('form_intervention_activity_supplierWithdraw').value = product.codeSupplier;
showWithdrawModelComponent(product.model.id);
updateCanSubmitField(type, 1);
break;
case 'producer_installation':
case 'supplier_installation':
// Faccio canMove solo qua perché negli altri 2 casi è sul magazzino cliente e non hanno i trasferimenti
if(product.canMove == 1){
document.getElementById('form_intervention_activity_productInstallationId').value = product.id;
document.getElementById('form_intervention_activity_modelInstallation').value = product.model;
document.getElementById('form_intervention_activity_producerInstallation').value = product.codeProducer;
document.getElementById('form_intervention_activity_supplierInstallation').value = product.codeSupplier;
updateCanSubmitField(type, 1);
}
else{
// Se installazione e non posso muovere
printAlertWarning("Il prodotto trovato con codice " + codeTypeLabel + " \"" + code + "\" non può essere spostato perché non è in stato disponibile!");
updateCanSubmitField(type, 0);
}
break;
case 'producer_actual':
case 'supplier_actual':
document.getElementById('form_intervention_activity_productActualId').value = product.id;
document.getElementById('form_intervention_activity_modelActual').value = product.model;
document.getElementById('form_intervention_activity_producerActual').value = product.codeProducer;
document.getElementById('form_intervention_activity_supplierActual').value = product.codeSupplier;
updateCanSubmitField(type, 1);
break;
default: break;
}
}
}
else{
// Se fornitore ticket non è tra i fornitori prodotto
printAlertWarning("Il prodotto trovato con codice " + codeTypeLabel + " \"" + code + "\" non può essere usato per il fornitore {{ ticket.supplier.name }}!");
updateCanSubmitField(type, 0);
}
}
else{
// Se POS o Accessorio non coerente con l'attività
printAlertWarning("Il prodotto trovato con codice " + codeTypeLabel + " \"" + code + "\" non può essere usato per questo tipo di intervento, selezionare un {{ posAccessory }}!");
updateCanSubmitField(type, 0);
}
}
else{
// Se non ho trovato prodotto
if(code != ''){
switch(type){
case 'producer_withdraw':
document.getElementById('form_intervention_activity_producerWithdraw').value = code;
document.getElementById('form_intervention_activity_modelWithdraw').value = '';
document.getElementById('row_component_withdraw').className = 'col-12';
document.getElementById('row_component_withdraw').innerHTML = '';
printAlertInfo("Il codice " + codeTypeLabel + " è utilizzabile, seleziona il modello prima di proseguire!");
updateCanSubmitField(type, 1);
break;
case 'supplier_withdraw':
document.getElementById('form_intervention_activity_supplierWithdraw').value = code;
document.getElementById('form_intervention_activity_modelWithdraw').value = '';
document.getElementById('row_component_withdraw').className = 'col-12';
document.getElementById('row_component_withdraw').innerHTML = '';
printAlertInfo("Il codice " + codeTypeLabel + " è utilizzabile, seleziona il modello prima di proseguire!");
updateCanSubmitField(type, 1);
break;
case 'producer_installation':
document.getElementById('form_intervention_activity_producerInstallation').value = code;
document.getElementById('form_intervention_activity_modelInstallation').value = '';
printAlertWarning("Nessun prodotto trovato con codice " + codeTypeLabel + " nel magazzino tecnico!");
updateCanSubmitField(type, 0);
break;
case 'supplier_installation':
document.getElementById('form_intervention_activity_supplierInstallation').value = code;
document.getElementById('form_intervention_activity_modelInstallation').value = '';
printAlertWarning("Nessun prodotto trovato con codice " + codeTypeLabel + " nel magazzino tecnico!");
updateCanSubmitField(type, 0);
break;
case 'producer_actual':
document.getElementById('form_intervention_activity_producerActual').value = code;
document.getElementById('form_intervention_activity_modelActual').value = '';
printAlertInfo("Il codice " + codeTypeLabel + " è utilizzabile, seleziona il modello prima di proseguire!");
updateCanSubmitField(type, 1);
break;
case 'supplier_actual':
document.getElementById('form_intervention_activity_supplierActual').value = code;
document.getElementById('form_intervention_activity_modelActual').value = '';
printAlertInfo("Il codice " + codeTypeLabel + " è utilizzabile, seleziona il modello prima di proseguire!");
updateCanSubmitField(type, 1);
break;
default: break;
}
}
}
}
closeModal();
updateButtonSubmit();
});
}
function showClientWarehouse(){
if(document.getElementById("clientWarehouse").style.display == "block")
document.getElementById("clientWarehouse").style.display = "none";
else
document.getElementById("clientWarehouse").style.display = "block";
}
function moveProduct(){
var productId = document.getElementById('move_product_id').value;
var type = document.getElementById("move_product_type").value;
$.post('{{ path ("user_ticket_intervention_activity_move_product", {"interventionId": intervention.id }) }}', {productId:productId, type: type}, function(response){
if(response.code == 200 && response.success){
printAlertSuccess('Prodotto spostato correttamente!');
$('#modalWarehouseOther').modal('hide');
onBlurManageBarcode(document.getElementById("move_type").value);
}
}, "json");
}
function submitForm(){
triggerLoading();
$('#form').submit();
}
function updateCanSubmitField(type, value){
switch(type){
case 'producer_withdraw':
case 'supplier_withdraw':
document.getElementById('can_submit_withdraw').value = value;
break;
case 'producer_installation':
case 'supplier_installation':
document.getElementById('can_submit_installation').value = value;
break;
case 'producer_actual':
case 'supplier_actual':
document.getElementById('can_submit_actual').value = value;
break;
default: break;
}
}
function updateButtonSubmit(){
var csW = document.getElementById('can_submit_withdraw').value;
var csA = document.getElementById('can_submit_actual').value;
var csI = document.getElementById('can_submit_installation').value;
var buttonSubmit = document.getElementById('button_submit');
if(csW == 1 && csA == 1 && csI == 1){
buttonSubmit.className = "button button-3d button-small button-green";
buttonSubmit.href = "javascript: submitForm()";
}
else{
buttonSubmit.className = "button button-3d button-small button-grey";
buttonSubmit.href = "javascript: void()";
}
}
</script>
{% endblock %}