<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <template id="portal_my_erp" name="Mis Tickets">
            <t t-call="portal.portal_layout">
                <t t-set="breadcrumbs_searchbar" t-value="True" />

                <t t-call="portal.portal_searchbar">
                    <t t-set="title">Asistencia ERP</t>
                </t>
                <input type="hidden" name="mdl_shw" id="mdl_shw" t-att-value="created"/>
                <div id="createticketModal" class="modal fade" role="dialog">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-body">
                                <div class="row">
                                    <div class="col-sm-12 col-md-6 col-lg-6 border-right">
                                        <h4>Crear Ticket</h4>
                                        <form action="/portal-create-ticket-erp" method="POST"  id="form_id" class="form-horizontal mt32" enctype="multipart/form-data">
                                            <input type="hidden" name="tck_type" id="tck_type" value="erp"/>
                                            <input type="hidden" name="sh_file_size" id="sh_file_size" t-att-value="request.env.company.sh_file_size"/>
                                            <div class="form-group">
                                                <t t-if="request.env.user.has_group('base.group_portal') and request.env.user.sh_portal_user_access or not request.env.user.has_group('base.group_portal')">
                                                    <label class="control-label" for="partner">Usuario:</label>
                                                    <input class="form-control" list="partner_ids" name="partner" id="partner" />
                                                    <input type="hidden" name="partner_id" id="partner_id" />
                                                    <datalist id="partner_ids"> </datalist>
                                                </t>
                                            </div>
                                            <t t-if="request.env.user.has_group('base.group_portal') and not request.env.user.sh_portal_user_access">
                                                <div t-attf-class="form-group #{error and 'portal_contact_name' in error and 'has-error' or ''}">
                                                    <label class="control-label" for="portal_contact_name">Nombre:</label>
                                                    <input type="text" class="form-control" id="portal_contact_name" name="portal_contact_name" t-att-value="request.env.user.partner_id.name" readonly="True" />
                                                </div>
                                                <div name="portal_email_from_container" t-attf-class="form-group #{error and 'portal_email' in error and 'has-error' or ''}">
                                                    <label class="control-label" for="portal_email">Correo:</label>
                                                    <input type="email" class="form-control" id="portal_email" name="portal_email" t-att-value="request.env.user.partner_id.email" readonly="True" />
                                                </div>
                                            </t>
                                            <t t-else="">
                                                <div t-attf-class="form-group #{error and 'portal_contact_name' in error and 'has-error' or ''}">
                                                    <label class="control-label" for="portal_contact_name">Nombre:</label>
                                                    <input type="text" class="form-control" id="portal_contact_name" name="portal_contact_name" required="True" />
                                                </div>
                                                <div name="portal_email_from_container" t-attf-class="form-group #{error and 'portal_email' in error and 'has-error' or ''}">
                                                    <label class="control-label" for="portal_email">Correo:</label>
                                                    <input type="email" class="form-control" id="portal_email" name="portal_email" required="True" />
                                                </div>
                                            </t>
                                            <div t-attf-class="form-group s_website_form_required">
                                                <label class="control-label s_website_form_required" for="portal_phone">Teléfono:</label>
                                                <input type="text" class="form-control form-field s_website_form_required" id="portal_phone" name="portal_phone" required="True" />
                                            </div>

                                            <input t-attf-class="form-group s_website_form_required" type="hidden" name="portal_erp_type" id="portal_erp_type" required="True"/>

                                            <div class="form-group">
                                                <h5>Seleccione su tipo de ticket:</h5>
                                            </div>
                                            <div class="form-group">
                                                <a id="supportButton" class="btn btn-primary" data-toggle="collapse" href="#collapseSupport" role="buton" aria-expanded="false" aria-controls="collapseSupport" >Soporte</a>
                                                <a id="improveButton" class="btn btn-primary" data-toggle="collapse" href="#collapseImprove" role="buton" aria-expanded="false" aria-controls="collapseImprove" >Mejora</a>
                                                <a id="reportButton" class="btn btn-primary" data-toggle="collapse" href="#collapseImprove" role="buton" aria-expanded="false" aria-controls="collapseImprove" >Reporte</a>
                                            </div>

                                            <input type="hidden" name="portal_erp_type" id="portal_erp_type" required="True"/>


                                            <div class="collapse" id="collapseSupport">
                                            
                                                <div t-attf-class="form-group o_website_form_required_custom #{error and 'portal_sucursal' in error and 'has-error' or ''} ">
                                                    <label class="control-label" for="portal_sucursal">Sucursal:</label>
                                                    <select class="form-control form-field o_website_form_required_custom" id="portal_sucursal" name="portal_sucursal" t-att-value="request.env.user.warehouse_id.id">
                                                        <option> </option>
                                                        <t t-if="len(request.env['warehouse.helpdesk'].sudo().search([('id','in',request.env.user.warehouse_ids.ids)])) == 1">
                                                            <t t-foreach="request.env['warehouse.helpdesk'].sudo().search([('id','in',request.env.user.warehouse_ids.ids)])" t-as="suc">
                                                                <option t-att-value="suc.id"><t t-esc="suc.name" /></option>
                                                            </t>
                                                        </t>
                                                        <t t-else="">
                                                            <t t-foreach="request.env['warehouse.helpdesk'].sudo().search([('id','in',request.env.user.warehouse_ids.ids)])" t-as="suc">
                                                                <option t-att-value="suc.id"><t t-esc="suc.name" /></option>
                                                            </t>
                                                        </t>
                                                    </select>
                                                </div>
                                                <div t-attf-class="form-group o_website_form_required_custom #{error and 'portal_module' in error and 'has-error' or ''}">
                                                    <label class="control-label" for="portal_module">Módulo:</label>
                                                    <select class="form-control form-field o_website_form_required_custom" id="portal_module" name="portal_module">
                                                        <option></option>
                                                        <t t-foreach="request.env['erp.modules'].sudo().search([])" t-as="module">
                                                            <option t-att-value="module.id"><t t-esc="module.name" /></option>
                                                        </t>
                                                    </select>
                                                </div>
                                                <div name="portal_file_container" t-attf-class="form-group o_website_form_required_custom #{error and 'portal_file' in error and 'has-error' or ''}">
                                                    <label class="control-label" for="portal_file">Adjuntos:</label>
                                                    <label class="custom-file">
                                                        <input class="o_website_form_required_custom" name="portal_file" id="portal_file" type="file" multiple="multiple" />
                                                        <span class="custom-file-control" />
                                                    </label>
                                                </div>
                                                
                                            </div>
                                            <div class="collapse" id="collapseImprove">
                                                <div class="form-group">
                                                    <a href="/helpdesk_morsa/static/src/docs/TI-FOR-02_Solicitud_de_reportes_rev02.xlsx">Descargar solicutd de reporte</a>
                                                </div>
                                                <div class="form-group">
                                                    <a href="/helpdesk_morsa/static/src/docs/TI-FOR-04_Solicitud_de_Mejora_rev02.xlsx">Descargar solicutd de mejora</a>
                                                </div>
                                                
                                                <div t-attf-class="form-group o_website_form_required_custom #{error and 'portal_route' in error and 'has-error' or ''}">
                                                    <label class="control-label" for="portal_route">Ruta de la transacción:</label>
                                                    <input type="text" class="form-control form-field s_website_form_required" id="portal_route" name="portal_route" />
                                                </div>
                                                <div t-attf-class="form-group o_website_form_required_custom #{error and 'portal_process' in error and 'has-error' or ''}">
                                                    <label class="control-label" for="portal_process">¿En que proceso utilizas la transacción?</label>
                                                    <input type="text" class="form-control form-field s_website_form_required" id="portal_process" name="portal_process" />
                                                    
                                                </div>
                                                <div t-attf-class="form-group o_website_form_required_custom #{error and 'portal_validations' in error and 'has-error' or ''}">
                                                    <label class="control-label" for="portal_validations">Cuales son las validaciones que se requieren</label>
                                                    <input type="text" class="form-control form-field s_website_form_required" id="portal_validations" name="portal_validations" />
                                                    
                                                </div>
                                                <div t-attf-class="form-group o_website_form_required_custom #{error and 'portal_essenary' in error and 'has-error' or ''}">
                                                    <label class="control-label" for="portal_scenery">¿Qué escenarios son comunes a trabajar con esta transacción?</label>
                                                    <input type="text" class="form-control form-field s_website_form_required" id="portal_scenery" name="portal_scenery" />
                                                   
                                                </div>
                                                <div t-attf-class="form-group o_website_form_required_custom #{error and 'portal_impact' in error and 'has-error' or ''}">
                                                    <label class="control-label" for="portal_impact">¿Tu solicitud, impacta de algún modo a algún otro Módulo?</label>
                                                    <input type="text" class="form-control form-field s_website_form_required" id="portal_impact" name="portal_impact"/>
                                                </div>
                                                <div t-attf-class="form-group o_website_form_required_custom #{error and 'portal_module' in error and 'has-error' or ''}">
                                                    <label class="control-label" for="portal_module_improve">Módulo:</label>
                                                    <select class="form-control form-field o_website_form_required_custom" id="portal_module_improve" name="portal_module_improve">
                                                        <option></option>
                                                        <t t-foreach="request.env['erp.modules'].sudo().search([])" t-as="module">
                                                            <option t-att-value="module.id"><t t-esc="module.name" /></option>
                                                        </t>
                                                    </select>
                                                </div>



                                                <div name="portal_file_container" t-attf-class="form-group #{error and 'portal_file' in error and 'has-error' or ''}">
                                                    <label class="control-label" for="portal_file_mejora">Adjuntos:</label>
                                                    <label class="custom-file">
                                                        <input name="portal_file_mejora" id="portal_file_mejora" type="file" multiple="multiple" />
                                                        <span class="custom-file-control" />
                                                    </label>
                                                </div>
                                            </div>
                

                                            
                                            <div class="row mb-2">
                                                <div class="col-12 text-center border-top ">
                                                    <button type="submit" id="create_helpdesk_ticket" class="btn btn-primary mt-2 rounded">Crear Ticket</button>
                                                </div>
                                            </div>
                                            
                                        </form>
                                    </div>
                                    <div class="col-sm-12 col-md-6 col-lg-6 o_center_object mt-2">
                                        <button type="button" class="btn btn-secondary rounded" data-dismiss="modal">Acceder</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <t t-if="not tickets">
                    <p>There are currently no tickets for your account.</p>
                </t>
                <t t-if="grouped_tickets" t-call="portal.portal_table">
                    <t t-foreach="grouped_tickets" t-as="ticket">
                        <thead>
                            <tr t-attf-class="{{'thead-light' if not groupby == 'none' else ''}}">
                                <th t-if="groupby == 'create_by'">
                                    <em class="font-weight-normal text-muted">Creado por:</em>
                                    <span t-field="ticket[0].create_uid.name" />
                                </th>
                                <th t-if="groupby == 'ticket_type'">
                                    <em class="font-weight-normal text-muted">Tipo de Ticket:</em>
                                    <span t-field="ticket[0].ticket_type.name" />
                                </th>
                                <th t-if="groupby == 'status'">
                                    <em class="font-weight-normal text-muted">Estado:</em>
                                    <span t-esc="ticket[0].stage_id.name" />
                                </th>
                                <th t-if="groupby == 'category'">
                                    <em class="font-weight-normal text-muted">Categoría:</em>
                                    <span t-esc="ticket[0].category_id.name" />
                                </th>
                                <th t-if="groupby == 'priority'">
                                    <em class="font-weight-normal text-muted">Prioridad:</em>
                                    <span t-esc="ticket[0].priority.name" />
                                </th>
                                <th t-if="groupby == 'state'">
                                    <em class="font-weight-normal text-muted">Estado de respuesta:</em>
                                    <span t-esc="ticket[0].state" />
                                </th>
                                <th t-if="groupby == 'sucursal'">
                                    <em class="font-weight-normal text-muted">Sucursal:</em>
                                    <span t-esc="ticket[0].warehouse_id.name" />
                                </th>
                                <th t-if="groupby == 'modulo'">
                                    <em class="font-weight-normal text-muted">Módulo:</em>
                                    <span t-esc="ticket[0].erp_id.name" />
                                </th>
                                <th>Fecha de creación</th>
                                <th>Última actualización</th>
                                <th>Prioridad</th>
                                <th>Módulo</th>
                                <th>Sucursal</th>
                                <th>Estado</th>
                            </tr>
                        </thead>
                        <tbody>
                            <t t-foreach="ticket" t-as="t">
                                <tr>
                                    <td>
                                        <a t-att-href="t.get_portal_url()" t-att-title="t.name">
                                            <t t-esc="t.name" t-if="t.name" />
                                            <em t-else="">Ticket</em>
                                        </a>
                                    </td>
                                    <td><span t-field="t.create_date"/></td>
                                    <td><span t-field="t.write_date" t-options='{"widget": "date"}' /></td>
                                    <td><span t-field="t.priority"/></td>
                                    <td><span t-field="t.erp_id" /></td>
                                    <td><span t-field="t.warehouse_id" /></td>
                                    <td><span t-field="t.stage_id" /></td>
                                </tr>
                            </t>
                        </tbody>
                    </t>
                </t>
            </t>
        </template>
    
    </data>
</odoo>