diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml index 2ef5d7b..0e7a91f 100644 --- a/app/views/admin/price_documents/show.html.haml +++ b/app/views/admin/price_documents/show.html.haml @@ -191,6 +191,16 @@ %h3 Lignes de produits + .mb-3 + - if @price_document.cc_label == "Consultation fournisseur" + = link_to ic(:clipboard) + " Copier le text", "#", class: "btn btn-primary", "data-document" => @price_document.id, onclick: 'copyPriceLines(event)' + - existing_order = PriceDocument.where(doc_ref_id: @price_document.id, cc_label: "Commande achat") + + - if existing_order.present? + = link_to ic(:eye) + " Afficher la commande", admin_price_document_path(existing_order.first), class: "btn btn-tertiary" + - else + = link_to "Generer la commande", buy_order_create_admin_price_document_path(@price_document), class: "btn btn-primary" + %table.table %thead %tr @@ -213,16 +223,17 @@ + %td =price_line.p_product_ref.p_product.s_brand.name - %td + %td{class: "p_product_ref_cc_name_#{@price_document.id}"} =link_to price_line.p_product_ref.cc_name, edit_admin_p_product_path(price_line.p_product_ref.p_product) if price_line.p_product_ref and price_line.p_product_ref.p_product - %td.numeraire + %td.numeraire{class: "price_line_qte_#{@price_document.id}"} =price_line.qte - %td.numeraire + %td.numeraire{class: "price_line_price_u_ht_#{@price_document.id}"} =number_to_currency price_line.price_u_ht @@ -382,7 +393,7 @@ = semantic_form_for [:admin, price_document_consult], :html => {:class => "qi_price_form"}, :remote => false do |form| = form.button "Valider modifications", type: :submit, class: "btn btn-primary m-2" = link_to ic(:clipboard) + " Copier le text", "#", class: "btn btn-primary", "data-document" => price_document_consult.id, onclick: 'copyPriceLines(event)' - - existing_order = PriceDocument.where(doc_ref_id: price_document_consult.id) + - existing_order = PriceDocument.where(doc_ref_id: price_document_consult.id, cc_label: "Commande achat") - if existing_order.present? = link_to ic(:eye) + " Afficher la commande", admin_price_document_path(existing_order.first), class: "btn btn-tertiary" - else @@ -399,41 +410,45 @@ - :javascript - const copyPriceLines = (event) => { - event.preventDefault() - let priceDocumentId = event.target.dataset.document - let names = $(`.p_product_ref_cc_name_${priceDocumentId}`) - let qtes = $(`.input_price_line_qte_${priceDocumentId}`) - let prices = $(`.price_line_price_u_ht_${priceDocumentId}`) +:javascript + const copyPriceLines = (event) => { + event.preventDefault() + let priceDocumentId = event.target.dataset.document + let names = $(`.p_product_ref_cc_name_${priceDocumentId}`) + let qtes_input = $(`.input_price_line_qte_${priceDocumentId}`) + let qtes = $(`.price_line_qte_${priceDocumentId}`) + let prices = $(`.price_line_price_u_ht_${priceDocumentId}`) + let table = [] + names.each(function( i ) { + let row = [] + if(qtes_input.length > 0) { + row.push(qtes_input[i].valueAsNumber) + }else{ + row.push(qtes[i].innerText.slice(0, -2)) + } + row.push(" X ") + row.push(names[i].innerText) + row.push(" @ ") + row.push(prices[i].innerText) + table.push(row.join(' ')) + }) + copyStringToClipboard(table.join('\r\n')) + } - let table = [] - names.each(function( i ) { - let row = [] - row.push(qtes[i].valueAsNumber) - row.push(" X ") - row.push(names[i].innerText) - row.push(" @ ") - row.push(prices[i].innerText) - table.push(row.join(' ')) - }) - copyStringToClipboard(table.join('\r\n')) - } - - function copyStringToClipboard (str) { - // Create new element - var el = document.createElement('textarea'); - // Set value (string to be copied) - el.value = str; - // Set non-editable to avoid focus and move outside of view - el.setAttribute('readonly', ''); - el.style = {position: 'absolute', left: '-9999px'}; - document.body.appendChild(el); - // Select text inside element - el.select(); - // Copy text to clipboard - document.execCommand('copy'); - // Remove temporary element - document.body.removeChild(el); - } + function copyStringToClipboard (str) { + // Create new element + var el = document.createElement('textarea'); + // Set value (string to be copied) + el.value = str; + // Set non-editable to avoid focus and move outside of view + el.setAttribute('readonly', ''); + el.style = {position: 'absolute', left: '-9999px'}; + document.body.appendChild(el); + // Select text inside element + el.select(); + // Copy text to clipboard + document.execCommand('copy'); + // Remove temporary element + document.body.removeChild(el); + }