From 05ed715d3446890ae9b6fea3eff56ce7505e21fc Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Wed, 19 Jun 2019 13:23:48 +0200 Subject: [PATCH] suite --- app/assets/javascripts/nested_fields.coffee | 12 + .../admin/p_documents_controller.rb | 4 + app/models/p_customer.rb | 1 + app/models/p_document.rb | 9 +- app/models/p_payment.rb | 7 +- .../p_documents/_search_to_affect.html.haml | 272 ++++++++++++++++ .../admin/p_documents/search_to_affect.js.erb | 2 + .../admin/p_payment_documents/_form.html.haml | 32 +- .../p_payment_documents/_form.old.html.haml | 14 + .../p_payments/_essentials_form.html.haml | 32 ++ app/views/admin/p_payments/_form.html.haml | 291 +++++++----------- .../admin/p_payments/_form.old.html.haml | 199 ++++++++++++ config/routes.rb | 1 + 13 files changed, 682 insertions(+), 194 deletions(-) create mode 100644 app/views/admin/p_documents/_search_to_affect.html.haml create mode 100644 app/views/admin/p_documents/search_to_affect.js.erb create mode 100755 app/views/admin/p_payment_documents/_form.old.html.haml create mode 100644 app/views/admin/p_payments/_essentials_form.html.haml create mode 100755 app/views/admin/p_payments/_form.old.html.haml diff --git a/app/assets/javascripts/nested_fields.coffee b/app/assets/javascripts/nested_fields.coffee index 6f6ddd1..daac239 100644 --- a/app/assets/javascripts/nested_fields.coffee +++ b/app/assets/javascripts/nested_fields.coffee @@ -15,5 +15,17 @@ form_element.append content_final + $(".new_field").removeClass "new_field" + false + +@qi_add_fields = (link, association, content) -> + new_id = new Date().getTime() + regexp = new RegExp("new_" + association, "g") + content_final = content.replace(regexp, new_id).replace(association + "_class", "new_field") + + form_element = $("." + association + "_form") + + form_element.append content_final + $(".new_field").removeClass "new_field" false \ No newline at end of file diff --git a/app/controllers/admin/p_documents_controller.rb b/app/controllers/admin/p_documents_controller.rb index dee3ee6..aba42ff 100755 --- a/app/controllers/admin/p_documents_controller.rb +++ b/app/controllers/admin/p_documents_controller.rb @@ -11,6 +11,10 @@ class Admin::PDocumentsController < ApplicationController @admin_space = "documents" end + def search_to_affect + @p_customer = PCustomer.where(:id => params[:p_customer_id]).first + end + def index @p_documents = PDocument.order("created_at DESC") diff --git a/app/models/p_customer.rb b/app/models/p_customer.rb index 561c8d6..a552045 100644 --- a/app/models/p_customer.rb +++ b/app/models/p_customer.rb @@ -21,6 +21,7 @@ class PCustomer < ActiveRecord::Base validates :siren, :presence => true, :if => :valid_siren? validates :ape, :presence => true, :if => :valid_siren? + has_many :p_documents belongs_to :p_price_cat diff --git a/app/models/p_document.rb b/app/models/p_document.rb index 2af439b..5d0790e 100644 --- a/app/models/p_document.rb +++ b/app/models/p_document.rb @@ -15,6 +15,7 @@ class PDocument < ActiveRecord::Base + has_many :p_payment_documents, :dependent => :destroy belongs_to :element, :polymorphic => true @@ -239,8 +240,12 @@ class PDocument < ActiveRecord::Base PSheetLine.totals(self.p_sheet_lines) end + def total_ttc + self.totals[:total_ttc] + end + def total_paid - self.p_payment_documents.joins(:p_payment).where(:p_payments => {:paid => true, :canceled => false}).sum(:amount) + self.p_payment_documents.joins(:p_payment).where(:p_payments => {:canceled => false}).sum(:amount) end def total_paid_at @@ -248,7 +253,7 @@ class PDocument < ActiveRecord::Base end def total_paid_th - self.p_payment_documents.joins(:p_payment).where(:p_payments => {:paid => false, :canceled => false}).sum(:amount) + self.p_payment_documents.joins(:p_payment).where(:p_payments => { :canceled => false}).sum(:amount) end diff --git a/app/models/p_payment.rb b/app/models/p_payment.rb index 6e33390..53d317d 100644 --- a/app/models/p_payment.rb +++ b/app/models/p_payment.rb @@ -3,8 +3,8 @@ class PPayment < ActiveRecord::Base belongs_to :p_customer validates :p_customer_id, :presence => true validates :amount, :presence => true - validates :paid_at, :presence => true, :if => :paid_date_needed? - validates :theo_date, :presence => true, :if => :theo_date_needed? + validates :paid_at, :presence => true #, :if => :paid_date_needed? + #validates :theo_date, :presence => true, :if => :theo_date_needed? has_many :p_payment_documents accepts_nested_attributes_for :p_payment_documents, allow_destroy: true @@ -19,10 +19,11 @@ class PPayment < ActiveRecord::Base self.affected = true end - if self.total_affected > self.amount.to_f + if self.amount and ((self.amount.to_f < 0.0 and self.total_affected.to_f < self.amount.to_f) or (self.amount.to_f > 0 and self.total_affected.to_f > self.amount.to_f))# and !self.imported errors.add(:amount, "Ne doit pas être inférieur aux affectations (manque #{(self.total_affected - self.amount.to_f)}€)") end + true end diff --git a/app/views/admin/p_documents/_search_to_affect.html.haml b/app/views/admin/p_documents/_search_to_affect.html.haml new file mode 100644 index 0000000..dbb4946 --- /dev/null +++ b/app/views/admin/p_documents/_search_to_affect.html.haml @@ -0,0 +1,272 @@ +-params[:solde] = params[:solde] || "0" +-p_customer = @p_customer +-if p_customer + + + -@p_documents = p_customer.p_documents + + + + -date_regex = /^(0[1-9]|[12][0-9]|3[01])[\/](0[1-9]|1[012])[\/](19|20)\d\d$/i + -if params[:start] and params[:start] =~ date_regex + -@start = Date.parse(params[:start]).beginning_of_day + -params[:start]= @start.strftime('%d/%m/%Y') + -else + -@start = nil + + + -if params[:stop].to_s != "" and params[:stop] =~ date_regex + -@stop = Date.parse(params[:stop]).end_of_day + -params[:stop]= @stop.strftime('%d/%m/%Y') + + -else + -@stop = nil + + -@p_documents = @p_documents.where("created_at >= ?", @start) if @start + -@p_documents = @p_documents.where("created_at <= ?", @stop.end_of_day) if @stop + + -if params[:solde].to_s != "" + + -if params[:solde].to_s == "0" + -#@p_documents = @p_documents.where("cache_to_paid != 0.0 and (i_archive = 0 or i_archive is null)") + -else + -#@p_documents = @p_documents.where("cache_to_paid = 0.0 or i_archive = 1") + + + + -@p_documents = @p_documents.where("d_number is not null") + -@p_documents = @p_documents.order("created_at DESC") + + -per_page = (params[:per_page] and params[:per_page] != "") ? params[:per_page] : 20 + -page = (params[:page] and params[:page] != "") ? params[:page] : 1 + -@p_documents = @p_documents.page(page).per(per_page) + + + + + + + #search_to_affect{:style => ("display:none" if false)} + .header_table + -if true + #search_to_affect_form + =form_tag search_to_affect_admin_p_documents_path(), :method => "get", :onsubmit => "", :autocomplete => "off", :remote => true do + =hidden_field_tag :p_customer_id, (@p_customer.id if @p_customer) + + + + %table.search_table + %tr + %td.search_label + Début + %td + .input-group + =text_field_tag :start, params[:start],:class => "form-control datepicker", :placeholder => "Début" + %span.input-group-addon.btn{:onclick => "$(this).prev('input').val('');"} + =ic(:times) + + + -if @start and @stop + + =link_to "< Mois précédent",request.query_parameters.merge({start: ((@start - 1.month).beginning_of_month.strftime('%d/%m/%Y')), stop: ((@stop - 1.month).end_of_month.strftime('%d/%m/%Y'))}), :class => "btn btn-default" + + %td.search_op + + + %td.search_label + Fin + %td + .input-group + =text_field_tag :stop, params[:stop],:class => "form-control datepicker", :placeholder => "Fin" + %span.input-group-addon.btn{:onclick => "$(this).prev('input').val('');"} + =ic(:times) + + -if @start and @stop + =link_to "Mois suivant >",request.query_parameters.merge({start: ((@start + 1.month).beginning_of_month.strftime('%d/%m/%Y')), stop: ((@stop + 1.month).end_of_month.strftime('%d/%m/%Y'))}), :class => "btn btn-default" + %td.search_op + %td.search_label + Soldé ? + %td=select_tag :solde, options_for_select([["Non","0"], ["Oui","1"]], params[:solde]), :include_blank => true + %td.search_op + %td + =submit_tag "Rechercher", :class => "btn btn-primary" + + %table.table.table-stripped.table-hover + %tr + %th{:style => "width:30px"} + %th{:style => "width:100px"} Date + %th{:style => "width:90px"} Offre + %th Numéro de doc. + %th.numeraire{:style => "width:90px"} Montant TTC + %th.numeraire{:style => "width:90px"} Solde TTC + %th.numeraire{:style => "width:30px"} + %th{:style => "width:10px"} + + + + .inner_panel + + %table.table.table-stripped.table-hover + + -@p_documents.where(:label => "Facture").each do |p_document| + %tr.p_document_search#p_document_search{:data => {:id => p_document.id}} + %td{:style => "width:30px;text-align:center;"}=ic :check if p_document.paid + %td{:style => "width:100px"}=l p_document.created_at, :format => "%y/%m/%Y" + %td{:style => "width:90px"} + =link_to p_document.element.id, [:admin,p_document.element], :target => "_blank" if p_document.element + %td + -if p_document.d_number? + =link_to p_document.d_number, admin_p_document_path(:id => p_document.token), :target => "_blank" + -else + =link_to "brouillon", admin_p_document_path(:id => p_document.token), :target => "_blank" + + + + %td.numeraire{:style => "width:90px"}=number_to_currency p_document.total_ttc + + %td.numeraire{:style => "width:90px"} + =number_to_currency p_document.total_ttc.to_f - p_document.total_paid.to_f + %td{:style => "width:30px;text-align:center;"} + -if true + -@fields = nil + -new_object = PPaymentDocument.new(:p_document_id => p_document.id) + -semantic_form_for([:admin, PPayment.new]) do |form| + -@fields = form.semantic_fields_for(:p_payment_documents, new_object, :child_index => "new_p_payment_documents") do |builder| + -render("admin/p_payment_documents/form", :form => builder) + + + =link_to ic(:plus) ,"#", :onclick => "qi_add_fields(this, 'p_payment_documents', \"#{escape_javascript(@fields)}\");return false;", :class => "add_to_affects" + + + + %td{:style => "width:10px;text-align:center;"} + + + .qi_pagination + = paginate @p_documents, :remote => true +-else + #search_to_affect + +:scss + + #search_to_affect{ + + width:600px; + height:400px; + margin:auto; + overflow:hidden; + position:relative; + background:white; + box-shadow:0 0 5px rgba(0,0,0,0.5); + + + .add_to_affects{ + cursor:pointer; + + &:hover{ + color:white; + background:#428bca; + padding:1px 3px; + margin:2px; + } + } + + .header_table{ + position:absolute; + top:0px; + height:50px; + right:0; + left:0; + background:white; + box-shadow:0 0 5px rgba(0,0,0,0.5); + + } + + .qi_pagination{ + box-shadow:0 0 5px rgba(0,0,0,0.5); + margin:0; + position:absolute; + background:white; + right:0; + left:0; + bottom:0px; + height:30px; + padding:2px; + font-size:11px; + .gap, .current, a{ + padding:4px 8px !important; + } + } + + + + .inner_panel{ + position:absolute; + top:50px; + right:0; + left:0; + bottom:30px; + overflow:auto; + + } + + .table{ + font-size:11px; + td,th{ + padding:2px 4px; + } + } + } + + //dddd + #search_to_affect_form{ + font-size:0.9em; + width:600px; + margin:auto; + background:white; + margin-bottom:4px; + .btn{ + padding:3px 4px !important; + font-size:0.9em !important; + + + } + .input-group{ + .form-control, .btn{ + padding:3px 4px !important; + font-size:0.9em !important; + height:20px !important; + + } + + .form-control{ + width:100px !important; + } + + } + + .search_table{ + td{ + vertical-align:middle; + } + } + + .search_label{ + text-align:right; + padding-right:5px; + + } + .search_op{ + width:25px; + text-align:center; + color:rgba(0,0,0,0.5); + + } + + + + } + + + + \ No newline at end of file diff --git a/app/views/admin/p_documents/search_to_affect.js.erb b/app/views/admin/p_documents/search_to_affect.js.erb new file mode 100644 index 0000000..cb6bc2d --- /dev/null +++ b/app/views/admin/p_documents/search_to_affect.js.erb @@ -0,0 +1,2 @@ +$('#search_to_affect').replaceWith("<%= escape_javascript(render(:partial => "admin/p_documents/search_to_affect"))%>"); + diff --git a/app/views/admin/p_payment_documents/_form.html.haml b/app/views/admin/p_payment_documents/_form.html.haml index 01e5470..7b1812f 100755 --- a/app/views/admin/p_payment_documents/_form.html.haml +++ b/app/views/admin/p_payment_documents/_form.html.haml @@ -1,14 +1,18 @@ -.p_payment_document_form.field - %hr - %table{:style => "width:100%;"} - %tr - %td - -p_documents = PDocument.where(:p_document_type_id => 4) - -if @p_customer - -p_documents = p_documents.where(:p_customer_id => @p_customer.id) - = form.input :p_document_id, :label => "Document :", :collection => p_documents.all, :as => :select, :include_blank => false, :member_label => :name_for_payment - %td - = form.input :amount, :label => "Montant" - - %td{:style => "padding:10px"} - =link_to_remove_fields ic(:"trash-o"), form \ No newline at end of file +-p_document = form.object.p_document +%tr.p_payment_document_form.field + %td{:style => "width:30px;text-align:center;"}=ic :check if p_document.paid + %td{:style => "width:100px"}=l p_document.created_at, :format => "%y/%m/%Y" + %td{:style => "width:90px"} + =link_to p_document.element.id, [:admin,p_document.element], :target => "_blank" if p_document.element + %td + =link_to p_document.d_number, admin_p_document_path(:id => p_document.token), :target => "_blank" + = form.hidden_field :p_document_id + %td.numeraire{:style => "width:120px"}=number_to_currency p_document.cache_total_ttc + + %td.numeraire{:style => "width:120px"} + =number_to_currency(p_document.total_ttc.to_f - p_document.total_paid.to_f) + %td.numeraire{:style => "width:120px"} + = form.input :amount, :label => false, :placeholder => "Montant" + %td{:style => "width:30px;text-align:center;"} + =link_to_remove_fields ic(:"trash-o"), form + diff --git a/app/views/admin/p_payment_documents/_form.old.html.haml b/app/views/admin/p_payment_documents/_form.old.html.haml new file mode 100755 index 0000000..01e5470 --- /dev/null +++ b/app/views/admin/p_payment_documents/_form.old.html.haml @@ -0,0 +1,14 @@ +.p_payment_document_form.field + %hr + %table{:style => "width:100%;"} + %tr + %td + -p_documents = PDocument.where(:p_document_type_id => 4) + -if @p_customer + -p_documents = p_documents.where(:p_customer_id => @p_customer.id) + = form.input :p_document_id, :label => "Document :", :collection => p_documents.all, :as => :select, :include_blank => false, :member_label => :name_for_payment + %td + = form.input :amount, :label => "Montant" + + %td{:style => "padding:10px"} + =link_to_remove_fields ic(:"trash-o"), form \ No newline at end of file diff --git a/app/views/admin/p_payments/_essentials_form.html.haml b/app/views/admin/p_payments/_essentials_form.html.haml new file mode 100644 index 0000000..7ee2c93 --- /dev/null +++ b/app/views/admin/p_payments/_essentials_form.html.haml @@ -0,0 +1,32 @@ +-field_form = field_form || false +.p_payment_form.field + + + =form.inputs do + + %table{:style => "width:100%;"} + %tr + %td{:style => "width:200px;"} + = form.input :p_payment_type_id, :label => "Type de paiement :", :include_blank => false, :collection => PPaymentType.order(:name).all, :as => :select, :input_html => {:class => "payment_type_id_select"} + + %td{:style => "width:160px;"} + = form.input :paid_at, :label => "Date de paiement :" , :as => :date + %td{:style => "width:160px;"} + .not_comptant{:style => ("display:none" if !PPaymentType.where(:comptant => false).ids.include?(form.object.p_payment_type_id))} + = form.input :theo_date, :label => "Date paiement th. :" , :as => :date + + -if false + %td{:style => "width:100px;"} + %br + = form.input :paid, :label => "Encaissé ?" + + %td{:style => "width:100px;"} + = form.input :amount, :label => "Montant :", :input_html => {:class => "payment_amount"} + %td + = form.input :number, :label => "N° / réf. :" + + + -if !@p_payment + %td{:style => "width:40px;padding-top:28px;text-align:center;"} + + =link_to_remove_fields ic(:"trash-o"), form \ No newline at end of file diff --git a/app/views/admin/p_payments/_form.html.haml b/app/views/admin/p_payments/_form.html.haml index 3dc8ac6..db19302 100755 --- a/app/views/admin/p_payments/_form.html.haml +++ b/app/views/admin/p_payments/_form.html.haml @@ -1,199 +1,140 @@ -=semantic_form_for [:admin, @p_payment], :remote => true do |f| - -@p_customer = @p_payment.p_customer if @p_payment.p_customer +#p_payment_form_wrapper .content =debug @p_payment.errors.messages - =f.inputs do + =semantic_form_for [:admin, @p_payment], :remote => true, :html => {:id => "p_payment_general_form",:onsubmit => "$this = $(this); if ($this.data().isSubmitted) { alert('La sauvegarde est en cours, merci de patienter.');return false; } $this.data().isSubmitted = true; return true;"} do |f| + -@p_customer = @p_payment.p_customer if @p_payment.p_customer - =hidden_field_tag :last_p_customer_id, @p_payment.p_customer_id + =f.inputs do - %label Client : - %input.p_customer_autocomplete_input.form-control{:type => "text", :value => ("#{f.object.p_customer.show_name}" if f.object.p_customer)} - - - = f.hidden_field :p_customer_id, :class => "p_customer_id" + =hidden_field_tag :last_p_customer_id, @p_payment.p_customer_id + + + %label Client : + %input.p_customer_autocomplete_input.form-control{:type => "text", :value => ("#{f.object.p_customer.show_name}" if f.object.p_customer)} + - :javascript - $( function() { - - + = f.hidden_field :p_customer_id, :class => "p_customer_id" + + :javascript + $( function() { + + - $('.p_customer_autocomplete_input').autocomplete({ - source: function( request, response ) { - $.ajax( { - - - url: "/admin/p_customers/autocomplete.json", - dataType: "json", - data: { - search: request.term, - - }, - success: function(data){ - - arr = jQuery.map( data, function( item ) { - return { - label: item.show_name, - value: item.show_name, - id: item.id - } - }); + $('.p_customer_autocomplete_input').autocomplete({ + source: function( request, response ) { + $.ajax( { - response(arr) - - } - - } ); - }, - minLength: 2, - select: function( event, ui ) { - - $(this).next(".p_customer_id").val(ui.item.id) - - var change_address = false; - - if (parseInt($("#last_p_customer_id").val()) != parseInt(ui.item.id)){ - change_address = true; - + + url: "/admin/p_customers/autocomplete.json", + dataType: "json", + data: { + search: request.term, + + }, + success: function(data){ + + arr = jQuery.map( data, function( item ) { + return { + label: item.show_name, + value: item.show_name, + id: item.id + } + }); + + response(arr) + + } + + } ); + }, + minLength: 2, + select: function( event, ui ) { + + $(this).next(".p_customer_id").val(ui.item.id) + + var change_address = false; + + if (parseInt($("#last_p_customer_id").val()) != parseInt(ui.item.id)){ + change_address = true; + + } + + $.ajax({ + url:"/admin/p_customers/"+ui.item.id+"/autocomplete_apercu.js", + type : "GET", + data : { change_address : change_address} + + }); + + $.ajax({ + url:"/admin/p_documents/search_to_affect?p_customer_id="+ui.item.id+".js", + type : "GET" + //data : { change_address : change_address} + + }); + + $("#last_p_customer_id").val(ui.item.id); + + + //return false } - - $.ajax({ - url:"/admin/p_customers/"+ui.item.id+"/autocomplete_apercu.js", - type : "GET", - data : { change_address : change_address} - - }); - - $("#last_p_customer_id").val(ui.item.id); - - - //return false - } - }); - - - - } ); - - - - -if false - .qi_autocomplete - %input.qi_autocomplete_input.form-control{:type => "text"} - - .qi_list - - = f.hidden_field :p_customer_id, :id => "p_customer_id" - - :coffeescript - $(document).on "click", ".autocomplete_line", -> - - id = $(this).data('value') - - $(this).closest(".qi_autocomplete").next("input").val(id) - - $(this).closest(".qi_list").hide() - $(this).closest(".qi_autocomplete").find(".qi_autocomplete_input").val("") - - change_address = false - - if (parseInt($("#last_p_customer_id").val()) != parseInt(id)) - change_address = true - - - $.ajax - url:"/admin/p_customers/"+id+"/autocomplete_apercu.js", - type : "GET", - data : {search : $(this).val(), change_address : change_address} - - $("#last_p_customer_id").val(id) - - return false - - $(".qi_autocomplete_input").keyup -> - input = $(this) - $.ajax - url:"/admin/p_customers/autocomplete.js", - type : "GET", - data : {search : $(this).val()} + }); + + + } ); - :scss - .qi_autocomplete{ - position:relative; + + %br + + =render :partial => "admin/p_payments/essentials_form", :locals => {:form => f} + + + #lettrage_panel + =f.inputs do + + %hr + + Lettrage : + #lettrage_table + %table.table + %thead + %tr + %th{:style => "width:30px"} + %th{:style => "width:100px"} Date + %th{:style => "width:90px"} Offre + %th Numéro de doc. + %th.numeraire{:style => "width:90px"} Montant TTC + %th.numeraire{:style => "width:90px"} Solde TTC + %th.numeraire{:style => "width:30px"} Montant à lettrer + %th{:style => "width:10px"} + + %tbody.p_payment_documents_form - .qi_autocomplete_input{ - width:100%; - box-sizing:border-box; - - - } - - .qi_list{ - position:absolute; - left:1px; - right:1px; - background:rgba(255,255,255,0.9); - box-shadow:0 0 5px rgba(0,0,0,0.3); - - a{ - display:block; - padding:5px 7px; - box-sizing:border-box; - border-bottom:1px solid rgba(0,0,0,0.2); - - &:hover{ - text-decoration:none; + =f.semantic_fields_for :p_payment_documents do |form| + =render :partial => "admin/p_payment_documents/form", :locals => {:form => form} + + :scss + #lettrage_table{ + font-size:14px; + td,th{ + padding:2px 4px; + vertical-align:middle; + .form-group{ + margin:0; } } } - } - - .p_customer_sheet_customer - - - -if @p_payment.p_customer and @p_payment.p_customer.particular - =render :partial => "admin/p_customers/apercu", :locals => {:particular => @p_payment.p_customer.particular} + %p Pour sélectionner un document avec lequel lettrer ce paiement, cliquer sur le + dans la liste des paiements ci-dessous : + =render :partial => "admin/p_documents/search_to_affect" - %br - = f.input :p_payment_type_id, :label => "Type de paiement :", :include_blank => false, :collection => PPaymentType.order(:name).all, :as => :select, :input_html => {:id => "payment_type_id_select"} - - = f.input :paid, :label => "Encaissé ?" - = f.input :paid_at, :label => "Date de paiement :" - .not_comptant{:style => ("display:none" if ![3].include?(@p_payment.p_payment_type_id))} - = f.input :theo_date, :label => "Date de paiement théorique :" - = f.input :amount, :label => "Montant :" - = f.input :number, :label => "Numéro / référence :" - - - %hr - - .p_payment_documents_form - =f.semantic_fields_for :p_payment_documents do |form| - =render :partial => "admin/p_payment_documents/form", :locals => {:form => form} - - %p= link_to_add_fields "Ajouter une ligne", f, :p_payment_documents - - - - :coffeescript - not_comptant_ids = [3] - - $('#payment_type_id_select').change -> - val = $(this).val() - if $.inArray(parseInt(val), not_comptant_ids) isnt -1 - $(".not_comptant").show() - else - $(".not_comptant").hide() - - - - .actions=f.submit "sauvegarder", :class => "btn btn-primary" + .actions=submit_tag "sauvegarder", :class => "btn btn-primary", :onclick => "$(this).val('Sauvegarde en cours...');$(this).closest('#p_payment_form_wrapper').find('#p_payment_general_form').submit();" \ No newline at end of file diff --git a/app/views/admin/p_payments/_form.old.html.haml b/app/views/admin/p_payments/_form.old.html.haml new file mode 100755 index 0000000..3dc8ac6 --- /dev/null +++ b/app/views/admin/p_payments/_form.old.html.haml @@ -0,0 +1,199 @@ +=semantic_form_for [:admin, @p_payment], :remote => true do |f| + -@p_customer = @p_payment.p_customer if @p_payment.p_customer + + .content + =debug @p_payment.errors.messages + =f.inputs do + + + =hidden_field_tag :last_p_customer_id, @p_payment.p_customer_id + + + %label Client : + %input.p_customer_autocomplete_input.form-control{:type => "text", :value => ("#{f.object.p_customer.show_name}" if f.object.p_customer)} + + + = f.hidden_field :p_customer_id, :class => "p_customer_id" + + :javascript + $( function() { + + + + $('.p_customer_autocomplete_input').autocomplete({ + source: function( request, response ) { + $.ajax( { + + + url: "/admin/p_customers/autocomplete.json", + dataType: "json", + data: { + search: request.term, + + }, + success: function(data){ + + arr = jQuery.map( data, function( item ) { + return { + label: item.show_name, + value: item.show_name, + id: item.id + } + }); + + response(arr) + + } + + } ); + }, + minLength: 2, + select: function( event, ui ) { + + $(this).next(".p_customer_id").val(ui.item.id) + + var change_address = false; + + if (parseInt($("#last_p_customer_id").val()) != parseInt(ui.item.id)){ + change_address = true; + + } + + $.ajax({ + url:"/admin/p_customers/"+ui.item.id+"/autocomplete_apercu.js", + type : "GET", + data : { change_address : change_address} + + }); + + $("#last_p_customer_id").val(ui.item.id); + + + //return false + } + }); + + + + } ); + + + + -if false + .qi_autocomplete + %input.qi_autocomplete_input.form-control{:type => "text"} + + .qi_list + + = f.hidden_field :p_customer_id, :id => "p_customer_id" + + :coffeescript + $(document).on "click", ".autocomplete_line", -> + + id = $(this).data('value') + + $(this).closest(".qi_autocomplete").next("input").val(id) + + $(this).closest(".qi_list").hide() + $(this).closest(".qi_autocomplete").find(".qi_autocomplete_input").val("") + + change_address = false + + if (parseInt($("#last_p_customer_id").val()) != parseInt(id)) + change_address = true + + + $.ajax + url:"/admin/p_customers/"+id+"/autocomplete_apercu.js", + type : "GET", + data : {search : $(this).val(), change_address : change_address} + + $("#last_p_customer_id").val(id) + + return false + + $(".qi_autocomplete_input").keyup -> + input = $(this) + $.ajax + url:"/admin/p_customers/autocomplete.js", + type : "GET", + data : {search : $(this).val()} + + + + + :scss + .qi_autocomplete{ + position:relative; + + .qi_autocomplete_input{ + width:100%; + box-sizing:border-box; + + + } + + .qi_list{ + position:absolute; + left:1px; + right:1px; + background:rgba(255,255,255,0.9); + box-shadow:0 0 5px rgba(0,0,0,0.3); + + a{ + display:block; + padding:5px 7px; + box-sizing:border-box; + border-bottom:1px solid rgba(0,0,0,0.2); + + &:hover{ + text-decoration:none; + } + } + } + } + + .p_customer_sheet_customer + + + -if @p_payment.p_customer and @p_payment.p_customer.particular + =render :partial => "admin/p_customers/apercu", :locals => {:particular => @p_payment.p_customer.particular} + + %br + + = f.input :p_payment_type_id, :label => "Type de paiement :", :include_blank => false, :collection => PPaymentType.order(:name).all, :as => :select, :input_html => {:id => "payment_type_id_select"} + + = f.input :paid, :label => "Encaissé ?" + = f.input :paid_at, :label => "Date de paiement :" + .not_comptant{:style => ("display:none" if ![3].include?(@p_payment.p_payment_type_id))} + = f.input :theo_date, :label => "Date de paiement théorique :" + = f.input :amount, :label => "Montant :" + = f.input :number, :label => "Numéro / référence :" + + + %hr + + .p_payment_documents_form + =f.semantic_fields_for :p_payment_documents do |form| + =render :partial => "admin/p_payment_documents/form", :locals => {:form => form} + + %p= link_to_add_fields "Ajouter une ligne", f, :p_payment_documents + + + + :coffeescript + not_comptant_ids = [3] + + $('#payment_type_id_select').change -> + val = $(this).val() + if $.inArray(parseInt(val), not_comptant_ids) isnt -1 + $(".not_comptant").show() + else + $(".not_comptant").hide() + + + + + + .actions=f.submit "sauvegarder", :class => "btn btn-primary" + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index acf057b..10bd581 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -153,6 +153,7 @@ Rails.application.routes.draw do end collection do get :multiple + get :search_to_affect end end resources :p_trucks