ETA date search on buylist

This commit is contained in:
Barnabé 2021-09-17 10:09:22 +02:00
parent 2f2cfb344e
commit 0020ee07ec
2 changed files with 73 additions and 19 deletions

View File

@ -33,35 +33,61 @@ class Admin::BuyListsController < ApplicationController
date_regex = /^(0[1-9]|[12][0-9]|3[01])[\/](0[1-9]|1[012])[\/](19|20)\d\d$/i
params[:start] = Date.today.beginning_of_month.strftime('%d/%m/%Y') if !params[:start]
params[:cc_creation_date_start] = Date.today.beginning_of_month.strftime('%d/%m/%Y') if !params[:cc_creation_date_start]
if params[:start] and params[:start] =~ date_regex
if params[:cc_creation_date_start] and params[:cc_creation_date_start] =~ date_regex
#fsfds = sdfsfd
@start = Date.parse(params[:start]).beginning_of_day
params[:start]= @start.strftime('%d/%m/%Y')
@cc_creation_date_start = Date.parse(params[:cc_creation_date_start]).beginning_of_day
params[:cc_creation_date_start]= @cc_creation_date_start.strftime('%d/%m/%Y')
else
@start = nil
@cc_creation_date_start = nil
end
if true
params[:stop] = Date.today.end_of_month.strftime('%d/%m/%Y') if !params[:stop]
params[:cc_creation_date_stop] = Date.today.end_of_month.strftime('%d/%m/%Y') if !params[:cc_creation_date_stop]
if params[:stop].to_s != "" # and params[:stop] =~ date_regex
@stop = Date.parse(params[:stop]).end_of_day
if params[:cc_creation_date_stop].to_s != "" # and params[:stop] =~ date_regex
@cc_creation_date_stop = Date.parse(params[:cc_creation_date_stop]).end_of_day
params[:stop]= @stop.strftime('%d/%m/%Y')
params[:cc_creation_date_stop]= @cc_creation_date_stop.strftime('%d/%m/%Y')
else
@stop = nil
@cc_creation_date_stop = nil
end
end
@price_lines = @price_lines.where("price_lines.cc_creation_date >= ?", @start) if @start
@price_lines = @price_lines.where("price_lines.cc_creation_date <= ?", @stop.end_of_day) if @stop
@price_lines = @price_lines.where("price_lines.cc_creation_date >= ?", @cc_creation_date_start) if @cc_creation_date_start
@price_lines = @price_lines.where("price_lines.cc_creation_date <= ?", @cc_creation_date_stop.end_of_day) if @cc_creation_date_stop
params[:wish_date_start] = Date.today.beginning_of_month.strftime('%d/%m/%Y') if !params[:wish_date_start]
if params[:wish_date_start] and params[:wish_date_start] =~ date_regex
#fsfds = sdfsfd
@wish_date_start = Date.parse(params[:wish_date_start]).beginning_of_day
params[:wish_date_start]= @wish_date_start.strftime('%d/%m/%Y')
else
@wish_date_start = nil
end
if true
params[:wish_date_stop] = Date.today.end_of_month.strftime('%d/%m/%Y') if !params[:wish_date_stop]
if params[:wish_date_stop].to_s != "" # and params[:stop] =~ date_regex
@wish_date_stop = Date.parse(params[:wish_date_stop]).end_of_day
params[:wish_date_stop]= @wish_date_stop.strftime('%d/%m/%Y')
else
@wish_date_stop = nil
end
end
@price_lines = @price_lines.joins(:price_line_block).where("price_line_blocks.wish_date >= ?", @wish_date_start) if @wish_date_start
@price_lines = @price_lines.joins(:price_line_block).where("price_line_blocks.wish_date <= ?", @wish_date_stop.end_of_day) if @wish_date_stop
respond_to do |format|
format.html{

View File

@ -11,20 +11,20 @@
=form_tag "", :method => "get", :onsubmit => "" do
-params[:search] =params[:search] || {}
%p Date de consultation :
%table
%tr.form-inline
%td
Date saisie commande :
Début
%td.input-group
=text_field_tag :start, params[:start],:class => "form-control datepicker", :placeholder => "Début"
=text_field_tag :cc_creation_date_start, params[:cc_creation_date_start],:class => "form-control datepicker", :placeholder => "Début"
.input-group-append
%span.input-group-text{:onclick => "$(this).prev('input').val('');"}
=ic(:times)
%td.pl-4
Fin
%td.input-group
=text_field_tag :stop, params[:stop],:class => "form-control datepicker", :placeholder => "Fin"
=text_field_tag :cc_creation_date_stop, params[:cc_creation_date_stop],:class => "form-control datepicker", :placeholder => "Fin"
.input-group-append
%span.input-group-text{:onclick => "$(this).prev('input').val('');"}
=ic(:times)
@ -39,17 +39,45 @@
Code client :
=text_field_tag "search[p_customer_code]", params[:search][:p_customer_code],:class => "form-control"
%tr.form-inline
%td{width: "110px"}
%td.right.mx-4
-if @cc_creation_date_start and @cc_creation_date_stop
=link_to "< Mois précédent",request.query_parameters.merge({cc_creation_date_start: ((@cc_creation_date_start - 1.month).beginning_of_month.strftime('%d/%m/%Y')), cc_creation_date_stop: ((@cc_creation_date_stop - 1.month).end_of_month.strftime('%d/%m/%Y'))}), :class => "btn btn-tertiary"
%td{width: "20px"}
%td.mr-auto
-if @cc_creation_date_start and @cc_creation_date_stop
=link_to "Mois suivant >",request.query_parameters.merge({cc_creation_date_start: ((@cc_creation_date_start + 1.month).beginning_of_month.strftime('%d/%m/%Y')), cc_creation_date_stop: ((@cc_creation_date_stop + 1.month).end_of_month.strftime('%d/%m/%Y'))}), :class => "btn btn-tertiary"
%tr.form-inline
%td
Date ETA :
Début
%td.input-group
=text_field_tag :wish_date_start, params[:wish_date_start],:class => "form-control datepicker", :placeholder => "Début"
.input-group-append
%span.input-group-text{:onclick => "$(this).prev('input').val('');"}
=ic(:times)
%td.pl-4
Fin
%td.input-group
=text_field_tag :wish_date_stop, params[:wish_date_stop],:class => "form-control datepicker", :placeholder => "Fin"
.input-group-append
%span.input-group-text{:onclick => "$(this).prev('input').val('');"}
=ic(:times)
%tr.form-inline
%td{width: "110px"}
%td.right.mx-4
-if @start and @stop
-if @wish_date_start and @wish_date_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-tertiary"
=link_to "< Mois précédent",request.query_parameters.merge({wish_date_start: ((@wish_date_start - 1.month).beginning_of_month.strftime('%d/%m/%Y')), wish_date_stop: ((@wish_date_stop - 1.month).end_of_month.strftime('%d/%m/%Y'))}), :class => "btn btn-tertiary"
%td{width: "20px"}
%td.mr-auto
-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-tertiary"
-if @wish_date_start and @wish_date_stop
=link_to "Mois suivant >",request.query_parameters.merge({wish_date_start: ((@wish_date_start + 1.month).beginning_of_month.strftime('%d/%m/%Y')), wish_date_stop: ((@wish_date_stop + 1.month).end_of_month.strftime('%d/%m/%Y'))}), :class => "btn btn-tertiary"
=link_to ic(:search)+" Rechercher", "#", :class => "btn btn-default btn-qi-search", :onclick => "$(this).closest('form').submit();$(this).html('...');return false;"