';
echo '
';
diff --git a/include/class/acc_ledger.class.php b/include/class/acc_ledger.class.php
index a2fda9344..a14640302 100644
--- a/include/class/acc_ledger.class.php
+++ b/include/class/acc_ledger.class.php
@@ -617,459 +617,9 @@ class Acc_Ledger extends jrn_def_sql
return $pj_pref.$pj_seq;
}
- /**
- * @brief Show all the operation
- * @param$sql is the sql stmt, normally created by build_search_sql
- * @param$offset the offset
- * @param$p_paid if we want to see info about payment
- @code
- // Example
- // Build the sql
- list($sql,$where)=$Ledger->build_search_sql($_GET);
- // Count nb of line
- $max_line=$this->db->count_sql($sql);
-
- $step=$_SESSION['g_pagesize'];
- $page=(isset($_GET['offset']))?$_GET['page']:1;
- $offset=(isset($_GET['offset']))?$_GET['offset']:0;
- // create the nav. bar
- $bar=navigation_bar($offset,$max_line,$step,$page);
- // show a part
- list($count,$html)= $Ledger->list_operation($sql,$offset,0);
- echo $html;
- // show nav bar
- echo $bar;
-
- @endcode
- * @see build_search_sql
- * @see display_search_form
- * @see search_form
-
- * @return HTML string
- */
- public function list_operation_to_reconcile($sql, $p_target)
- {
- global $g_parameter, $g_user;
- $gDossier=dossier::id();
- $limit=" LIMIT ".MAX_RECONCILE;
- // Sort
- // Count
- $count=$this->db->count_sql($sql);
- // Add the limit
- $sql.=" order by jr_date asc ".$limit;
-
- // Execute SQL stmt
- $Res=$this->db->exec_sql($sql);
-
- //starting from here we can refactor, so that instead of returning the generated HTML,
- //this function returns a tree structure.
-
- $r="";
-
-
- $Max=Database::num_row($Res);
-
- if ($Max==0)
- return array(0, _("Aucun enregistrement trouvé"));
- $r.=HtmlInput::hidden("target", $p_target);
- $r.='
';
- return array($count, $r);
- }
-
- /**
- * @brief Show all the operation
- * @param$sql is the sql stmt, normally created by build_search_sql
- * @param$offset the offset
- * @param$p_paid if we want to see info about payment
- \code
- // Example
- // Build the sql
- list($sql,$where)=$Ledger->build_search_sql($_GET);
- // Count nb of line
- $max_line=$cn->count_sql($sql);
-
- $step=$_SESSION['g_pagesize'];
- $page=(isset($_GET['offset']))?$_GET['page']:1;
- $offset=(isset($_GET['offset']))?$_GET['offset']:0;
- // create the nav. bar
- $bar=navigation_bar($offset,$max_line,$step,$page);
- // show a part
- list($count,$html)= $Ledger->list_operation($sql,$offset,0);
- echo $html;
- // show nav bar
- echo $bar;
-
- \endcode
- * \see build_search_sql
- * \see display_search_form
- * \see search_form
-
- * \return HTML string
- */
- public function list_operation($sql, $offset, $p_paid=0)
- {
- global $g_parameter, $g_user;
- bcscale(2);
- $table=new Sort_Table();
- $gDossier=dossier::id();
- $amount_paid=0.0;
- $amount_unpaid=0.0;
- $limit=($_SESSION['g_pagesize']!=-1)?" LIMIT ".$_SESSION['g_pagesize']:"";
- $offset=($_SESSION['g_pagesize']!=-1)?" OFFSET ".Database::escape_string($offset):"";
- $order=" order by jr_date_order asc,jr_internal asc";
- // Sort
- $url="?".CleanUrl();
- $str_dossier=dossier::get();
- $table->add(_("Date"), $url,
- 'order by jr_date asc,substring(jr_pj_number,\'[0-9]+$\')::numeric asc',
- 'order by jr_date desc,substring(jr_pj_number,\'[0-9]+$\')::numeric desc',
- "da", "dd");
- $table->add(_('Echeance'), $url, " order by jr_ech asc",
- " order by jr_ech desc", 'ea', 'ed');
- $table->add(_('Paiement'), $url, " order by jr_date_paid asc",
- " order by jr_date_paid desc", 'eap', 'edp');
- $table->add(_('Pièce'), $url,
- ' order by substring(jr_pj_number,\'[0-9]+$\')::numeric asc ',
- ' order by substring(jr_pj_number,\'[0-9]+$\')::numeric desc ',
- "pja", "pjd");
- $table->add(_('Tiers'), $url, " order by name asc",
- " order by name desc", 'na', 'nd');
- $table->add(_('Montant'), $url, " order by jr_montant asc",
- " order by jr_montant desc", "ma", "md");
- $table->add(_("Description"), $url, "order by jr_comment asc",
- "order by jr_comment desc", "ca", "cd");
-
- $ord=(!isset($_GET['ord']))?'da':$_GET['ord'];
- $order=$table->get_sql_order($ord);
-
- // Count
- $count=$this->db->count_sql($sql);
- // Add the limit
- $sql.=$order.$limit.$offset;
- // Execute SQL stmt
- $Res=$this->db->exec_sql($sql);
-
- //starting from here we can refactor, so that instead of returning the generated HTML,
- //this function returns a tree structure.
-
- $r="";
-
-
- $Max=Database::num_row($Res);
-
- if ($Max==0)
- return array(0, _("Aucun enregistrement trouvé"));
-
- $r.='
';
-
-
- $r.="";
- $r.="| "._("n° interne")." | ";
- if ($this->type=='ALL')
- {
- $r.=th('Journal');
- }
- $r.=''.$table->get_header(0).' | ';
- if ($p_paid!=0)
- $r.=''.$table->get_header(1).'';
- if ($p_paid!=0)
- $r.=' | '.$table->get_header(2).' | ';
- $r.=''.$table->get_header(3).' | ';
- $r.=''.$table->get_header(4).' | ';
- $r.=''.$table->get_header(6).' | ';
- $r.=th('Notes', ' style="width:15%"');
- $r.=''.$table->get_header(5).' | ';
- // if $p_paid is not equal to 0 then we have a paid column
- if ($p_paid!=0)
- {
- $r.=" "._('Payé')." | ";
- }
- $r.=""._('Concerne')." | ";
- $r.=""._('Document')." | ";
- $r.="
";
- // Total Amount
- $tot=0.0;
- $gDossier=dossier::id();
- for ($i=0; $i<$Max; $i++)
- {
-
-
- $row=Database::fetch_array($Res, $i);
-
- if ($i%2==0)
- $tr='';
- else
- $tr='
';
- $r.=$tr;
- //internal code
- // button modify
- $r.="| ";
- // If url contains
- //
-
- $href=basename($_SERVER['PHP_SELF']);
-
-
- $r.=sprintf('%s ',
- $row['jr_id'], $gDossier, $row['jr_internal']);
- $r.=" | ";
- if ($this->type=='ALL')
- $r.=td($row['jrn_def_name']);
- // date
- $r.="";
- $r.=$row['str_jr_date'];
- $r.=" | ";
- // echeance
- if ($p_paid!=0)
- {
- $r.="";
- $r.=$row['str_jr_ech'];
- $r.=" | ";
- $r.="";
- $r.=$row['str_jr_date_paid'];
- $r.=" | ";
- }
-
- // pj
- $r.="";
- $r.=$row['jr_pj_number'];
- $r.=" | ";
-
- // Tiers
- $other=($row['quick_code']!='')?'['.$row['quick_code'].'] '.$row['name'].' '.$row['first_name']:'';
- $r.=td($other);
- // comment
- $r.="";
- $tmp_jr_comment=h($row['jr_comment']);
- $r.=$tmp_jr_comment;
- $r.=" | ";
- $r.=td(h($row['n_text']), ' style="font-size:0.87em%"');
- // Amount
- // If the ledger is financial :
- // the credit must be negative and written in red
- $positive=0;
-
- // Check ledger type :
- if ($row['jrn_def_type']=='FIN')
- {
- $positive=$this->db->get_value("select qf_amount from quant_fin where jr_id=$1",
- array($row['jr_id']));
- if ($this->db->count()!=0)
- $positive=($positive<0)?1:0;
- }
- $r.="";
- $t_amount=$row['jr_montant'];
- if ($row['total_invoice']!=null&&$row['total_invoice']!=$row['jr_montant'])
- $t_amount=$row['total_invoice'];
- $tot=($positive!=0)?bcsub($tot, $t_amount):bcadd($tot, $t_amount);
- //STAN $positive always == 0
- if ($row ['jrn_def_type']=='FIN')
- {
- $r.=( $positive!=0 )?" - ".nbm($t_amount)."":nbm($t_amount);
- }
- else
- {
- $r.=( $t_amount<0 )?" ".nbm($t_amount)."":nbm($t_amount);
- }
- $r.=" | ";
-
-
- // Show the paid column if p_paid is not null
- if ($p_paid!=0)
- {
- $w=new ICheckBox();
- $w->name="rd_paid".$row['jr_id'];
- $w->selected=($row['jr_rapt']=='paid')?true:false;
- // if p_paid == 2 then readonly
- $w->readonly=( $p_paid==2)?true:false;
- $h=new IHidden();
- $h->name="set_jr_id".$row['jr_id'];
- $r.=''.$w->input().$h->input().' | ';
- if ($row['jr_rapt']=='paid')
- $amount_paid=bcadd($amount_paid, $t_amount);
- else
- $amount_unpaid=bcadd($amount_unpaid, $t_amount);
- }
-
- // Rapprochement
- $rec=new Acc_Reconciliation($this->db);
- $rec->set_jr_id($row['jr_id']);
- $a=$rec->get();
- $r.="";
- if ($a!=null)
- {
-
- foreach ($a as $key=> $element)
- {
- $operation=new Acc_Operation($this->db);
- $operation->jr_id=$element;
- $l_amount=$this->db->get_value("select jr_montant from jrn ".
- " where jr_id=$1", array($element));
- $r.=" ".$operation->get_internal()."[".nbm($l_amount)."]";
- }//for
- }// if ( $a != null ) {
- $r.=" | ";
-
- if ($row['jr_valid']=='f')
- {
- $r.=""._("Opération annulée")." | ";
- }
- else
- {
-
- } // else
- //document
- if ($row['jr_pj_name']!="")
- {
- $r.=''.HtmlInput::show_receipt_document($row['jr_id']).' | ';
- }
- else
- $r.=" | ";
-
- // end row
- $r.="
";
- }
- $amount_paid=round($amount_paid, 4);
- $amount_unpaid=round($amount_unpaid, 4);
- $tot=round($tot, 4);
- $r.="";
- $r.='| Total | ';
- $r.=''.nbm($tot)." | ";
- $r.="
";
- if ($p_paid!=0)
- {
- $r.="";
- $r.='| '._("Payé").' | ';
- $r.=''.nbm($amount_paid)." | ";
- $r.="
";
- $r.="";
- $r.='| '._("Non payé").' | ';
- $r.=''.nbm($amount_unpaid)." | ";
- $r.="
";
- }
- $r.="
";
-
- return array($count, $r);
- }
+
+
/**
* @brief get_detail gives the detail of row
* this array must contains at least the field
@@ -2575,475 +2125,7 @@ class Acc_Ledger extends jrn_def_sql
$this->db->exec_sql($sql);
}
- /**
- * @brief return a HTML string with the form for the search
- * @param $p_type if the type of ledger possible values=ALL,VEN,ACH,ODS,FIN
- * @param $all_type_ledger
- * values :
- * - 1 means all the ledger of this type
- * - 0 No have the "Tous les journaux" availables
- * @param $div is the div (for reconciliation)
- * @return a HTML String without the tag FORM or DIV
- *
- * @see build_search_sql
- * @see display_search_form
- * @see list_operation
- */
- function search_form($p_type, $all_type_ledger=1, $div="")
- {
- global $g_user;
- $r="";
- $bledger_param=json_encode(array(
- 'dossier'=>$_REQUEST['gDossier'],
- 'type'=>$p_type,
- 'all_type'=>$all_type_ledger,
- 'div'=>$div
- ));
-
- $bledger_param=str_replace('"', "'", $bledger_param);
- $bledger=new ISmallButton('l');
- $bledger->label=_("choix des journaux");
- $bledger->javascript=" show_ledger_choice($bledger_param)";
- $f_ledger=$bledger->input();
- $hid_jrn="";
- if (isset($_REQUEST[$div.'nb_jrn']))
- {
- for ($i=0; $i<$_REQUEST[$div.'nb_jrn']; $i++)
- {
- if (isset($_REQUEST[$div."r_jrn"][$i]))
- $hid_jrn.=HtmlInput::hidden($div.'r_jrn['.$i.']',
- $_REQUEST[$div."r_jrn"][$i]);
- }
- $hid_jrn.=HtmlInput::hidden($div.'nb_jrn', $_REQUEST[$div.'nb_jrn']);
- } else
- {
- $hid_jrn=HtmlInput::hidden($div.'nb_jrn', 0);
- }
- /* Compute date for exercice */
- $period=$g_user->get_periode();
- $per=new Periode($this->db, $period);
- $exercice=$per->get_exercice();
- list($per_start, $per_end)=$per->get_limit($exercice);
- $date_end=$per_end->last_day();
- $date_start=$per_start->first_day();
-
- /* widget for date_start */
- $f_date_start=new IDate('date_start');
- /* all periode or only the selected one */
- if (isset($_REQUEST['date_start']))
- {
- $f_date_start->value=$_REQUEST['date_start'];
- }
- else
- {
- $f_date_start->value=$date_start;
- }
-
- /* widget for date_end */
- $f_date_end=new IDate('date_end');
- /* all date or only the selected one */
- if (isset($_REQUEST['date_end']))
- {
- $f_date_end->value=$_REQUEST['date_end'];
- }
- else
- {
- $f_date_end->value=$date_end;
- }
- /* widget for date term */
- $f_date_paid_start=new IDate('date_paid_start');
- $f_date_paid_end=new IDate('date_paid_end');
-
- $f_date_paid_start->value=(isset($_REQUEST['date_paid_start']))?$_REQUEST['date_paid_start']:'';
- $f_date_paid_end->value=(isset($_REQUEST['date_paid_end']))?$_REQUEST['date_paid_end']:'';
-
- /* widget for desc */
- $f_descript=new IText('desc');
- $f_descript->size=40;
- if (isset($_REQUEST['desc']))
- {
- $f_descript->value=$_REQUEST['desc'];
- }
-
- /* widget for amount */
- $f_amount_min=new INum('amount_min');
- $f_amount_min->value=(isset($_REQUEST['amount_min']))?abs($_REQUEST['amount_min']):0;
- $f_amount_max=new INum('amount_max');
- $f_amount_max->value=(isset($_REQUEST['amount_max']))?abs($_REQUEST['amount_max']):0;
-
- /* input quick code */
- $f_qcode=new ICard('qcode'.$div);
-
- $f_qcode->set_attribute('typecard', 'all');
- /* $f_qcode->set_attribute('p_jrn','0');
-
- $f_qcode->set_callback('filter_card');
- */
- $f_qcode->set_dblclick("fill_ipopcard(this);");
- // Add the callback function to filter the card on the jrn
- //$f_qcode->set_callback('filter_card');
- $f_qcode->set_function('fill_data');
- $f_qcode->javascript=sprintf(' onchange="fill_data_onchange(%s);" ',
- $f_qcode->name);
- $f_qcode->value=(isset($_REQUEST['qcode'.$div]))?$_REQUEST['qcode'.$div]:'';
-
- /* $f_txt_qcode=new IText('qcode');
- $f_txt_qcode->value=(isset($_REQUEST['qcode']))?$_REQUEST['qcode']:'';
- */
-
- /* input poste comptable */
- $f_accounting=new IPoste('accounting');
- $f_accounting->value=(isset($_REQUEST['accounting']))?$_REQUEST['accounting']:'';
- if ($this->id==-1)
- $jrn=0;
- else
- $jrn=$this->id;
- $f_accounting->set_attribute('jrn', $jrn);
- $f_accounting->set_attribute('ipopup', 'ipop_account');
- $f_accounting->set_attribute('label', 'ld');
- $f_accounting->set_attribute('account', 'accounting');
- $info=HtmlInput::infobulle(13);
-
- $f_paid=new ICheckbox('unpaid');
- $f_paid->selected=(isset($_REQUEST['unpaid']))?true:false;
-
- $r.=dossier::hidden();
- $r.=HtmlInput::hidden('ledger_type', $this->type);
- $r.=HtmlInput::hidden('ac', $_REQUEST['ac']);
- ob_start();
- require_once NOALYSS_TEMPLATE.'/ledger_search.php';
- $r.=ob_get_contents();
- ob_end_clean();
- return $r;
- }
-
- /**
- * @brief this function will create a sql stmt to use to create the list for
- * the ledger,
- * @param $p_array is usually the $_GET,
- * @param $p_order the order of the row
- * @param $p_where is the sql condition if not null then the $p_array will not be used
- * \note the p_action will be used to filter the ledger but gl means ALL
- * struct array $p_array
- \verbatim
- (
- [gDossier] => 13
- [p_jrn] => -1
- [date_start] =>
- [date_end] =>
- [amount_min] => 0
- [amount_max] => 0
- [desc] =>
- [search] => Rechercher
- [p_action] => ven
- [sa] => l
- )
- \endverbatim
- * \return an array with a valid sql statement, an the where clause => array[sql] array[where]
- * \see list_operation
- * \see display_search_form
- * \see search_form
- */
- public function build_search_sql($p_array, $p_order="", $p_where="")
- {
- $sql="select jr_id ,
- jr_montant,
- substr(jr_comment,1,60) as jr_comment,
- to_char(jr_ech,'DD.MM.YY') as str_jr_ech,
- to_char(jr_date,'DD.MM.YY') as str_jr_date,
- jr_date as jr_date_order,
- jr_grpt_id,
- jr_rapt,
- jr_internal,
- jrn_def_id,
- jrn_def_name,
- jrn_def_ech,
- jrn_def_type,
- jr_valid,
- jr_tech_per,
- jr_pj_name,
- p_closed,
- jr_pj_number,
- n_text,
- case
- when jrn_def_type='VEN' then
- (select ad_value from fiche_detail where ad_id=1
- and f_id=(select max(qs_client) from quant_sold join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
- when jrn_def_type = 'ACH' then
- (select ad_value from fiche_detail where ad_id=1
- and f_id=(select max(qp_supplier) from quant_purchase join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
- when jrn_def_type = 'FIN' then
- (select ad_value from fiche_detail where ad_id=1
- and f_id=(select qf_other from quant_fin where quant_fin.jr_id=x.jr_id))
- end as name,
- case
- when jrn_def_type='VEN' then (select ad_value from fiche_detail where ad_id=32 and f_id=(select max(qs_client) from quant_sold join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
- when jrn_def_type = 'ACH' then (select ad_value from fiche_detail where ad_id=32 and f_id=(select max(qp_supplier) from quant_purchase join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
- when jrn_def_type = 'FIN' then (select ad_value from fiche_detail where ad_id=32 and f_id=(select qf_other from quant_fin where quant_fin.jr_id=x.jr_id))
- end as first_name,
- case
- when jrn_def_type='VEN' then (select ad_value from fiche_detail where ad_id=23 and f_id=(select max(qs_client) from quant_sold join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
- when jrn_def_type = 'ACH' then (select ad_value from fiche_detail where ad_id=23 and f_id=(select max(qp_supplier) from quant_purchase join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
- when jrn_def_type = 'FIN' then (select ad_value from fiche_detail where ad_id=23 and f_id=(select qf_other from quant_fin where quant_fin.jr_id=x.jr_id))
- end as quick_code,
- case
- when jrn_def_type='VEN' then
- (select sum(qs_price)+sum(vat) from
- (select qs_internal,qs_price,case when qs_vat_sided<>0 then 0 else qs_vat end as vat from quant_sold where qs_internal=X.jr_internal) as ven_invoice
- )
- when jrn_def_type = 'ACH' then
- (
- select sum(qp_price)+sum(vat)+sum(qp_nd_tva)+sum(qp_nd_tva_recup)
- from
- (select qp_internal,qp_price,qp_nd_tva,qp_nd_tva_recup,qp_vat-qp_vat_sided as vat from quant_purchase where qp_internal=X.jr_internal) as invoice_purchase
- )
- else null
- end as total_invoice,
- jr_date_paid,
- to_char(jr_date_paid,'DD.MM.YY') as str_jr_date_paid
- from
- jrn as X left join jrn_note using(jr_id)
- join jrn_def on jrn_def_id=jr_def_id
- join parm_periode on p_id=jr_tech_per";
-
- if (!empty($p_array))
- extract($p_array, EXTR_SKIP);
-
- if (isset($op))
- $r_jrn=(isset(${$op."r_jrn"}))?${$op."r_jrn"}:-1;
- else
- {
- $r_jrn=(isset($r_jrn))?$r_jrn:-1;
- }
-
- /* if no variable are set then give them a default
- * value */
- if ($p_array==null||empty($p_array)||!isset($amount_min))
- {
- $amount_min=0;
- $amount_max=0;
-
- $desc='';
- $qcode=(isset($qcode))?$qcode:"";
- if (isset($qcodesearch_op))
- $qcode=$qcodesearch_op;
- $accounting=(isset($accounting))?$accounting:"";
- $periode=new Periode($this->db);
- $g_user=new User($this->db);
- $p_id=$g_user->get_periode();
- if ($p_id!=null)
- {
- list($date_start, $date_end)=$periode->get_date_limit($p_id);
- }
- }
-
- /* if p_jrn : 0 if means all ledgers, if -1 means all ledger of this
- * type otherwise only one ledger */
- $fil_ledger='';
- $fil_amount='';
- $fil_date='';
- $fil_desc='';
- $fil_sec='';
- $fil_qcode='';
- $fil_account='';
- $fil_paid='';
- $fil_date_paid='';
-
- $and='';
- $g_user=new User($this->db);
- $p_action=$ledger_type;
- if ($p_action=='')
- $p_action='ALL';
- if ($r_jrn==-1)
- {
-
- /* from compta.php the p_action is quick_writing instead of ODS */
- if ($p_action=='quick_writing')
- $p_action='ODS';
-
-
- $fil_ledger=$g_user->get_ledger_sql($p_action, 3);
- $and=' and ';
- }
- else
- {
-
- if ($p_action=='quick_writing')
- $p_action='ODS';
-
- $aLedger=$g_user->get_ledger($p_action, 3);
- $fil_ledger='';
- $sp='';
- for ($i=0; $i
0&&isNumber($amount_min))
- {
- $fil_amount=$and.' jr_montant >='.$amount_min;
- $and=' and ';
- }
- if ($amount_max>0&&isNumber($amount_max))
- {
- $fil_amount.=$and.' jr_montant <='.$amount_max;
- $and=' and ';
- }
- /* -------------------------------------------------------------------------- *
- * if both amount are the same then we need to search into the detail
- * and we reset the fil_amount
- * -------------------------------------------------------------------------- */
- if (isNumber($amount_min)&&
- isNumber($amount_max)&&
- $amount_min>0&&
- bccomp($amount_min, $amount_max, 2)==0)
- {
- $fil_amount=$and.' ( ';
-
- // Look in detail
- $fil_amount.='jr_grpt_id in ( select distinct j_grpt from jrnx where j_montant = '.$amount_min.') ';
-
- //and the total operation
- $fil_amount.=' or ';
- $fil_amount.=' jr_montant = '.$amount_min;
-
- $fil_amount.=')';
- $and=" and ";
- }
- // date
- if (isset($date_start)&&isDate($date_start)!=null)
- {
- $fil_date=$and." jr_date >= to_date('".$date_start."','DD.MM.YYYY')";
- $and=" and ";
- }
- if (isset($date_end)&&isDate($date_end)!=null)
- {
- $fil_date.=$and." jr_date <= to_date('".$date_end."','DD.MM.YYYY')";
- $and=" and ";
- }
- // date paiement
- if (isset($date_paid_start)&&isDate($date_paid_start)!=null)
- {
- $fil_date_paid=$and." jr_date_paid >= to_date('".$date_paid_start."','DD.MM.YYYY')";
- $and=" and ";
- }
- if (isset($date_paid_end)&&isDate($date_paid_end)!=null)
- {
- $fil_date_paid.=$and." jr_date_paid <= to_date('".$date_paid_end."','DD.MM.YYYY')";
- $and=" and ";
- }
- // comment
- if (isset($desc)&&$desc!=null)
- {
- $desc=sql_string($desc);
- $fil_desc=$and." ( upper(jr_comment) like upper('%".$desc."%') or upper(jr_pj_number) like upper('%".$desc."%') ".
- " or upper(jr_internal) like upper('%".$desc."%')
- or jr_grpt_id in (select j_grpt from jrnx where j_text ~* '".$desc."')
- or jr_id in (select jr_id from jrn_info where ji_value is not null and ji_value ~* '$desc')
- )";
- $and=" and ";
- }
- // Poste
- if (isset($accounting)&&$accounting!=null)
- {
- $fil_account=$and." jr_grpt_id in (select j_grpt
- from jrnx where j_poste::text like '".sql_string($accounting)."%' ) ";
- $and=" and ";
- }
- // Quick Code
- if (isset($qcodesearch_op))
- $qcode=$qcodesearch_op;
- if (isset($qcode)&&$qcode!=null)
- {
- $fil_qcode=$and." jr_grpt_id in ( select j_grpt from
- jrnx where trim(j_qcode) = upper(trim('".sql_string($qcode)."')))";
- $and=" and ";
- }
-
- // Only the unpaid
- if (isset($unpaid))
- {
- $fil_paid=$and.SQL_LIST_UNPAID_INVOICE;
- $and=" and ";
- }
- $repo=new Database();
- $g_user=new User($repo);
- $g_user->Check();
- $g_user->check_dossier(dossier::id());
-
- if ($g_user->admin==0&&$g_user->is_local_admin()==0)
- {
- $fil_sec=$and." jr_def_id in ( select uj_jrn_id ".
- " from user_sec_jrn where ".
- " uj_login='".sql_string($_SESSION['g_user'])."'".
- " and uj_priv in ('R','W'))";
- }
- $where=$fil_ledger.$fil_amount.$fil_date.$fil_desc.$fil_sec.$fil_amount.$fil_qcode.$fil_paid.$fil_account.$fil_date_paid;
- $sql.=" where ".$where;
- return array($sql, $where);
- }
-
- /**
- * @brief return a html string with the search_form
- * \return a HTML string with the FORM
- * \see build_search_sql
- * \see search_form
- * \see list_operation
- */
- function display_search_form()
- {
- $r='';
- $type=$this->type;
-
- if ($type=="")
- $type='ALL';
- $r.='';
- $r.=HtmlInput::anchor_hide('⨉',
- '$(\'search_form\').style.display=\'none\';');
- $r.=h2('Recherche', 'class="title"');
- $r.='';
-
- $r.='
';
- $button=new IButton('tfs');
- $button->label=_("Filtrer");
- $button->javascript="toggleHideShow('search_form','tfs');";
-
- $r.=$button->input();
- return $r;
- }
+
/**
* @brief return the last p_limit operation into an array
diff --git a/include/class/acc_ledger_search.class.php b/include/class/acc_ledger_search.class.php
new file mode 100644
index 000000000..d786a56b5
--- /dev/null
+++ b/include/class/acc_ledger_search.class.php
@@ -0,0 +1,1040 @@
+
+
+if (!defined('ALLOWED'))
+ die('Appel direct ne sont pas permis');
+
+/**
+ * @file
+ * @brief
+ * @param type $name Descriptionara
+ */
+class Acc_Ledger_Search
+{
+
+ private $cn; //!< Database Connection
+ private $type; //!< type of ledger : FIN,ODS,VEN,ACH
+ private $all; //!< Flag to indicate if all ledgers must searched (1 for yes)
+ private $div; //! prefix for id of DOM id
+
+ /**
+ * @brief return a HTML string with the form for the search
+ * @param $p_type if the type of ledger possible values=ALL,VEN,ACH,ODS,FIN
+ * @param $all_type_ledger
+ * values :
+ * - 1 means all the ledger of this type
+ * - 0 No have the "Tous les journaux" availables
+ * @param $div is the div (for reconciliation)
+ * @param type $p_type
+ * @param type $p_all
+ * @param type $p_div
+ */
+
+ function __construct($p_type, $p_all=1, $p_div="")
+ {
+ $this->cn=Dossier::connect();
+ $this->type=$p_type;
+ $this->all=$p_all;
+ $this->div=$p_div;
+ }
+
+ public function get_type()
+ {
+ return $this->type;
+ }
+
+ public function get_all()
+ {
+ return $this->all;
+ }
+
+ public function get_div()
+ {
+ return $this->div;
+ }
+
+ public function set_type($type)
+ {
+ $this->type=$type;
+ }
+
+ public function set_all($all)
+ {
+ $this->all=$all;
+ }
+
+ public function set_div($div)
+ {
+ $this->div=$div;
+ }
+
+ /**
+ * @brief return a HTML string with the form for the search
+ * @return a HTML String without the tag FORM or DIV
+ *
+ * @see build_search_sql
+ * @see display_search_form
+ * @see list_operation
+ * @example search_acc_operation.php
+ */
+ function search_form()
+ {
+ global $g_user;
+ $r="";
+ $bledger_param=json_encode(array(
+ 'dossier'=>Dossier::id(),
+ 'type'=>$this->type,
+ 'all_type'=>$this->all,
+ 'div'=>$this->div
+ ));
+
+ $bledger_param=str_replace('"', "'", $bledger_param);
+ $bledger=new ISmallButton('l');
+ $bledger->label=_("choix des journaux");
+ $bledger->javascript=" show_ledger_choice($bledger_param)";
+ $f_ledger=$bledger->input();
+ $hid_jrn="";
+ if (isset($_REQUEST[$this->div.'nb_jrn']))
+ {
+ for ($i=0; $i<$_REQUEST[$this->div.'nb_jrn']; $i++)
+ {
+ if (isset($_REQUEST[$this->div."r_jrn"][$i]))
+ $hid_jrn.=HtmlInput::hidden($this->div.'r_jrn['.$i.']',
+ $_REQUEST[$this->div."r_jrn"][$i]);
+ }
+ $hid_jrn.=HtmlInput::hidden($this->div.'nb_jrn',
+ $_REQUEST[$this->div.'nb_jrn']);
+ } else
+ {
+ $hid_jrn=HtmlInput::hidden($this->div.'nb_jrn', 0);
+ }
+ /* Compute date for exercice */
+ $period=$g_user->get_periode();
+ $per=new Periode($this->cn, $period);
+ $exercice=$per->get_exercice();
+ list($per_start, $per_end)=$per->get_limit($exercice);
+ $date_end=$per_end->last_day();
+ $date_start=$per_start->first_day();
+
+ /* widget for date_start */
+ $f_date_start=new IDate('date_start', '', $this->div."date_start");
+ /* all periode or only the selected one */
+ if (isset($_REQUEST['date_start']))
+ {
+ $f_date_start->value=$_REQUEST['date_start'];
+ }
+ else
+ {
+ $f_date_start->value=$date_start;
+ }
+
+ /* widget for date_end */
+ $f_date_end=new IDate('date_end', '', $this->div."date_end");
+ /* all date or only the selected one */
+ if (isset($_REQUEST['date_end']))
+ {
+ $f_date_end->value=$_REQUEST['date_end'];
+ }
+ else
+ {
+ $f_date_end->value=$date_end;
+ }
+ /* widget for date term */
+ $f_date_paid_start=new IDate('date_paid_start', '',
+ $this->div."date_paid_start");
+ $f_date_paid_end=new IDate('date_paid_end', '',
+ $this->div."date_paid_end");
+
+ $f_date_paid_start->value=(isset($_REQUEST['date_paid_start']))?$_REQUEST['date_paid_start']:'';
+ $f_date_paid_end->value=(isset($_REQUEST['date_paid_end']))?$_REQUEST['date_paid_end']:'';
+
+ /* widget for desc */
+ $f_descript=new IText('desc', "", $this->div."desc");
+ $f_descript->size=40;
+ if (isset($_REQUEST['desc']))
+ {
+ $f_descript->value=$_REQUEST['desc'];
+ }
+
+ /* widget for amount */
+ $f_amount_min=new INum('amount_min', '0', $this->div."amount_min");
+ $f_amount_min->value=(isset($_REQUEST['amount_min']))?abs($_REQUEST['amount_min']):0;
+ $f_amount_max=new INum('amount_max', '0', $this->div."amount_max");
+ $f_amount_max->value=(isset($_REQUEST['amount_max']))?abs($_REQUEST['amount_max']):0;
+
+ /* input quick code */
+ $f_qcode=new ICard($this->div.'qcode');
+
+ $f_qcode->set_attribute('typecard', 'all');
+ /* $f_qcode->set_attribute('p_jrn','0');
+
+ $f_qcode->set_callback('filter_card');
+ */
+ $f_qcode->set_dblclick("fill_ipopcard(this);");
+ // Add the callback function to filter the card on the jrn
+ //$f_qcode->set_callback('filter_card');
+ $f_qcode->set_function('fill_data');
+ $f_qcode->javascript=sprintf(' onchange="fill_data_onchange(%s);" ',
+ $f_qcode->name);
+ $f_qcode->value=(isset($_REQUEST[$this->div.'qcode']))?$_REQUEST[$this->div.'qcode']:'';
+
+ /* $f_txt_qcode=new IText('qcode');
+ $f_txt_qcode->value=(isset($_REQUEST['qcode']))?$_REQUEST['qcode']:'';
+ */
+
+ /* input poste comptable */
+ $f_accounting=new IPoste('accounting', "", $this->div."accounting");
+ $f_accounting->value=(isset($_REQUEST['accounting']))?$_REQUEST['accounting']:'';
+ /*
+ * utile ??? Filtre les postes comptables en fonction du journal
+ * if ($this->id==-1)
+ $jrn=0;
+ else
+ $jrn=$this->id; */
+ $f_accounting->set_attribute('jrn', 0);
+ $f_accounting->set_attribute('ipopup', 'ipop_account');
+ $f_accounting->set_attribute('label', 'ld');
+ $f_accounting->set_attribute('account', $this->div.'accounting');
+ $info=HtmlInput::infobulle(13);
+
+ $f_paid=new ICheckbox('unpaid', null, $this->div.'unpaid');
+ $f_paid->selected=(isset($_REQUEST['unpaid']))?true:false;
+
+ $r.=dossier::hidden();
+ $r.=HtmlInput::hidden('ledger_type', $this->type,
+ $this->div."ledger_type");
+ $r.=HtmlInput::hidden('ac', $_REQUEST['ac']);
+ ob_start();
+ $search_filter=$this->build_search_filter();
+ $save_filter=$this->build_name_filter();
+ require_once NOALYSS_TEMPLATE.'/ledger_search.php';
+ $r.=ob_get_contents();
+ ob_end_clean();
+ return $r;
+ }
+
+ /**
+ * Build the button for managing the filter for search
+ * @param type $p_div id prefix of the div, button, table ..
+ * @param $this->type if the type of ledger possible values=ALL,VEN,ACH,ODS,FIN
+ * @param $all_type_ledger
+ * values :
+ * - 1 means all the ledger of this type
+ * - 0 No have the "Tous les journaux" availables
+ */
+ private function build_search_filter()
+ {
+ $json=json_encode(["div"=>$this->div, "ledger_type"=>$this->type, "all_type"=>$this->all,
+ "dossier"=>Dossier::id()]);
+ $json=str_replace('"', "'", $json);
+ $r=sprintf('manage_search_filter(%s)', $json);
+ return $r;
+ }
+
+ /**
+ * Build the button for saving the filter for search
+ */
+ private function build_name_filter()
+ {
+ $name=new IText($this->div."filter_new");
+ $name->placeholder=_("Nom du filtre");
+ $name->javascript=sprintf("save_filter('%s','%s')",$this->div,Dossier::id());
+ return $name;
+ }
+
+ /**
+ * @brief this function will create a sql stmt to use to create the list for
+ * the ledger,
+ * @param $p_array is usually the $_GET,
+ * @param $p_order the order of the row
+ * @param $p_where is the sql condition if not null then the $p_array will not be used
+ * \note the p_action will be used to filter the ledger but gl means ALL
+ * struct array $p_array
+ \verbatim
+ (
+ [gDossier] => 13
+ [p_jrn] => -1
+ [date_start] =>
+ [date_end] =>
+ [amount_min] => 0
+ [amount_max] => 0
+ [desc] =>
+ [search] => Rechercher
+ [p_action] => ven
+ [sa] => l
+ )
+ \endverbatim
+ * \return an array with a valid sql statement, an the where clause => array[sql] array[where]
+ * \see list_operation
+ * \see display_search_form
+ * \see search_form
+ */
+ public function build_search_sql($p_array, $p_order="", $p_where="")
+ {
+ $sql="select jr_id ,
+ jr_montant,
+ substr(jr_comment,1,60) as jr_comment,
+ to_char(jr_ech,'DD.MM.YY') as str_jr_ech,
+ to_char(jr_date,'DD.MM.YY') as str_jr_date,
+ jr_date as jr_date_order,
+ jr_grpt_id,
+ jr_rapt,
+ jr_internal,
+ jrn_def_id,
+ jrn_def_name,
+ jrn_def_ech,
+ jrn_def_type,
+ jr_valid,
+ jr_tech_per,
+ jr_pj_name,
+ p_closed,
+ jr_pj_number,
+ n_text,
+ case
+ when jrn_def_type='VEN' then
+ (select ad_value from fiche_detail where ad_id=1
+ and f_id=(select max(qs_client) from quant_sold join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+ when jrn_def_type = 'ACH' then
+ (select ad_value from fiche_detail where ad_id=1
+ and f_id=(select max(qp_supplier) from quant_purchase join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+ when jrn_def_type = 'FIN' then
+ (select ad_value from fiche_detail where ad_id=1
+ and f_id=(select qf_other from quant_fin where quant_fin.jr_id=x.jr_id))
+ end as name,
+ case
+ when jrn_def_type='VEN' then (select ad_value from fiche_detail where ad_id=32 and f_id=(select max(qs_client) from quant_sold join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+ when jrn_def_type = 'ACH' then (select ad_value from fiche_detail where ad_id=32 and f_id=(select max(qp_supplier) from quant_purchase join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+ when jrn_def_type = 'FIN' then (select ad_value from fiche_detail where ad_id=32 and f_id=(select qf_other from quant_fin where quant_fin.jr_id=x.jr_id))
+ end as first_name,
+ case
+ when jrn_def_type='VEN' then (select ad_value from fiche_detail where ad_id=23 and f_id=(select max(qs_client) from quant_sold join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+ when jrn_def_type = 'ACH' then (select ad_value from fiche_detail where ad_id=23 and f_id=(select max(qp_supplier) from quant_purchase join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+ when jrn_def_type = 'FIN' then (select ad_value from fiche_detail where ad_id=23 and f_id=(select qf_other from quant_fin where quant_fin.jr_id=x.jr_id))
+ end as quick_code,
+ case
+ when jrn_def_type='VEN' then
+ (select sum(qs_price)+sum(vat) from
+ (select qs_internal,qs_price,case when qs_vat_sided<>0 then 0 else qs_vat end as vat from quant_sold where qs_internal=X.jr_internal) as ven_invoice
+ )
+ when jrn_def_type = 'ACH' then
+ (
+ select sum(qp_price)+sum(vat)+sum(qp_nd_tva)+sum(qp_nd_tva_recup)
+ from
+ (select qp_internal,qp_price,qp_nd_tva,qp_nd_tva_recup,qp_vat-qp_vat_sided as vat from quant_purchase where qp_internal=X.jr_internal) as invoice_purchase
+ )
+ else null
+ end as total_invoice,
+ jr_date_paid,
+ to_char(jr_date_paid,'DD.MM.YY') as str_jr_date_paid
+ from
+ jrn as X left join jrn_note using(jr_id)
+ join jrn_def on jrn_def_id=jr_def_id
+ join parm_periode on p_id=jr_tech_per";
+
+ if (!empty($p_array))
+ extract($p_array, EXTR_SKIP);
+
+ if (isset($op))
+ $r_jrn=(isset(${$op."r_jrn"}))?${$op."r_jrn"}:-1;
+ else
+ {
+ $r_jrn=(isset($r_jrn))?$r_jrn:-1;
+ }
+
+ /* if no variable are set then give them a default
+ * value */
+ if ($p_array==null||empty($p_array)||!isset($amount_min))
+ {
+ $amount_min=0;
+ $amount_max=0;
+
+ $desc='';
+ $qcode=(isset($qcode))?$qcode:"";
+ if (isset($qcodesearch_op))
+ $qcode=$qcodesearch_op;
+ $accounting=(isset($accounting))?$accounting:"";
+ $periode=new Periode($this->cn);
+ $g_user=new User($this->cn);
+ $p_id=$g_user->get_periode();
+ if ($p_id!=null)
+ {
+ list($date_start, $date_end)=$periode->get_date_limit($p_id);
+ }
+ }
+
+ /* if p_jrn : 0 if means all ledgers, if -1 means all ledger of this
+ * type otherwise only one ledger */
+ $fil_ledger='';
+ $fil_amount='';
+ $fil_date='';
+ $fil_desc='';
+ $fil_sec='';
+ $fil_qcode='';
+ $fil_account='';
+ $fil_paid='';
+ $fil_date_paid='';
+
+ $and='';
+ $g_user=new User($this->cn);
+ $p_action=$ledger_type;
+ if ($p_action=='')
+ $p_action='ALL';
+ if ($r_jrn==-1)
+ {
+
+ /* from compta.php the p_action is quick_writing instead of ODS */
+ if ($p_action=='quick_writing')
+ $p_action='ODS';
+
+
+ $fil_ledger=$g_user->get_ledger_sql($p_action, 3);
+ $and=' and ';
+ }
+ else
+ {
+
+ if ($p_action=='quick_writing')
+ $p_action='ODS';
+
+ $aLedger=$g_user->get_ledger($p_action, 3);
+ $fil_ledger='';
+ $sp='';
+ for ($i=0; $i0&&isNumber($amount_min))
+ {
+ $fil_amount=$and.' jr_montant >='.$amount_min;
+ $and=' and ';
+ }
+ if ($amount_max>0&&isNumber($amount_max))
+ {
+ $fil_amount.=$and.' jr_montant <='.$amount_max;
+ $and=' and ';
+ }
+ /* -------------------------------------------------------------------------- *
+ * if both amount are the same then we need to search into the detail
+ * and we reset the fil_amount
+ * -------------------------------------------------------------------------- */
+ if (isNumber($amount_min)&&
+ isNumber($amount_max)&&
+ $amount_min>0&&
+ bccomp($amount_min, $amount_max, 2)==0)
+ {
+ $fil_amount=$and.' ( ';
+
+ // Look in detail
+ $fil_amount.='jr_grpt_id in ( select distinct j_grpt from jrnx where j_montant = '.$amount_min.') ';
+
+ //and the total operation
+ $fil_amount.=' or ';
+ $fil_amount.=' jr_montant = '.$amount_min;
+
+ $fil_amount.=')';
+ $and=" and ";
+ }
+ // date
+ if (isset($date_start)&&isDate($date_start)!=null)
+ {
+ $fil_date=$and." jr_date >= to_date('".$date_start."','DD.MM.YYYY')";
+ $and=" and ";
+ }
+ if (isset($date_end)&&isDate($date_end)!=null)
+ {
+ $fil_date.=$and." jr_date <= to_date('".$date_end."','DD.MM.YYYY')";
+ $and=" and ";
+ }
+ // date paiement
+ if (isset($date_paid_start)&&isDate($date_paid_start)!=null)
+ {
+ $fil_date_paid=$and." jr_date_paid >= to_date('".$date_paid_start."','DD.MM.YYYY')";
+ $and=" and ";
+ }
+ if (isset($date_paid_end)&&isDate($date_paid_end)!=null)
+ {
+ $fil_date_paid.=$and." jr_date_paid <= to_date('".$date_paid_end."','DD.MM.YYYY')";
+ $and=" and ";
+ }
+ // comment
+ if (isset($desc)&&$desc!=null)
+ {
+ $desc=sql_string($desc);
+ $fil_desc=$and." ( upper(jr_comment) like upper('%".$desc."%') or upper(jr_pj_number) like upper('%".$desc."%') ".
+ " or upper(jr_internal) like upper('%".$desc."%')
+ or jr_grpt_id in (select j_grpt from jrnx where j_text ~* '".$desc."')
+ or jr_id in (select jr_id from jrn_info where ji_value is not null and ji_value ~* '$desc')
+ )";
+ $and=" and ";
+ }
+ // Poste
+ if (isset($accounting)&&$accounting!=null)
+ {
+ $fil_account=$and." jr_grpt_id in (select j_grpt
+ from jrnx where j_poste::text like '".sql_string($accounting)."%' ) ";
+ $and=" and ";
+ }
+ // Quick Code
+ if (isset($qcodesearch_op))
+ $qcode=$qcodesearch_op;
+ if (isset($qcode)&&$qcode!=null)
+ {
+ $fil_qcode=$and." jr_grpt_id in ( select j_grpt from
+ jrnx where trim(j_qcode) = upper(trim('".sql_string($qcode)."')))";
+ $and=" and ";
+ }
+
+ // Only the unpaid
+ if (isset($unpaid))
+ {
+ $fil_paid=$and.SQL_LIST_UNPAID_INVOICE;
+ $and=" and ";
+ }
+ $repo=new Database();
+ $g_user=new User($repo);
+ $g_user->Check();
+ $g_user->check_dossier(dossier::id());
+
+ if ($g_user->admin==0&&$g_user->is_local_admin()==0)
+ {
+ $fil_sec=$and." jr_def_id in ( select uj_jrn_id ".
+ " from user_sec_jrn where ".
+ " uj_login='".sql_string($_SESSION['g_user'])."'".
+ " and uj_priv in ('R','W'))";
+ }
+ $where=$fil_ledger.$fil_amount.$fil_date.$fil_desc.$fil_sec.$fil_amount.$fil_qcode.$fil_paid.$fil_account.$fil_date_paid;
+ $sql.=" where ".$where;
+ return array($sql, $where);
+ }
+
+ /**
+ * @brief return a html string with the search_form
+ * \return a HTML string with the FORM
+ * \see build_search_sql
+ * \see search_form
+ * \see list_operation
+ */
+ function display_search_form()
+ {
+ $r='';
+ $r.='';
+ $r.=HtmlInput::anchor_hide('⨉',
+ '$(\'search_form\').style.display=\'none\';');
+ $r.=h2('Recherche', 'class="title"');
+ $r.='';
+
+ $r.='
';
+ $button=new IButton('tfs');
+ $button->label=_("Filtrer");
+ $button->javascript="toggleHideShow('search_form','tfs');";
+
+ $r.=$button->input();
+ return $r;
+ }
+
+ /**
+ * @brief Show all the operation
+ * @param$sql is the sql stmt, normally created by build_search_sql
+ * @param$offset the offset
+ * @param$p_paid if we want to see info about payment
+ \code
+ // Example
+ // Build the sql
+ list($sql,$where)=$Ledger->build_search_sql($_GET);
+ // Count nb of line
+ $max_line=$cn->count_sql($sql);
+
+ $step=$_SESSION['g_pagesize'];
+ $page=(isset($_GET['offset']))?$_GET['page']:1;
+ $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+ // create the nav. bar
+ $bar=navigation_bar($offset,$max_line,$step,$page);
+ // show a part
+ list($count,$html)= $Ledger->list_operation($sql,$offset,0);
+ echo $html;
+ // show nav bar
+ echo $bar;
+
+ \endcode
+ * \see build_search_sql
+ * \see display_search_form
+ * \see search_form
+
+ * \return HTML string
+ */
+ public function list_operation($sql, $offset, $p_paid=0)
+ {
+ global $g_parameter, $g_user;
+ bcscale(2);
+ $table=new Sort_Table();
+ $gDossier=dossier::id();
+ $amount_paid=0.0;
+ $amount_unpaid=0.0;
+ $limit=($_SESSION['g_pagesize']!=-1)?" LIMIT ".$_SESSION['g_pagesize']:"";
+ $offset=($_SESSION['g_pagesize']!=-1)?" OFFSET ".Database::escape_string($offset):"";
+ $order=" order by jr_date_order asc,jr_internal asc";
+ // Sort
+ $url="?".CleanUrl();
+ $str_dossier=dossier::get();
+ $table->add(_("Date"), $url,
+ 'order by jr_date asc,substring(jr_pj_number,\'[0-9]+$\')::numeric asc',
+ 'order by jr_date desc,substring(jr_pj_number,\'[0-9]+$\')::numeric desc',
+ "da", "dd");
+ $table->add(_('Echeance'), $url, " order by jr_ech asc",
+ " order by jr_ech desc", 'ea', 'ed');
+ $table->add(_('Paiement'), $url, " order by jr_date_paid asc",
+ " order by jr_date_paid desc", 'eap', 'edp');
+ $table->add(_('Pièce'), $url,
+ ' order by substring(jr_pj_number,\'[0-9]+$\')::numeric asc ',
+ ' order by substring(jr_pj_number,\'[0-9]+$\')::numeric desc ',
+ "pja", "pjd");
+ $table->add(_('Tiers'), $url, " order by name asc",
+ " order by name desc", 'na', 'nd');
+ $table->add(_('Montant'), $url, " order by jr_montant asc",
+ " order by jr_montant desc", "ma", "md");
+ $table->add(_("Description"), $url, "order by jr_comment asc",
+ "order by jr_comment desc", "ca", "cd");
+
+ $ord=(!isset($_GET['ord']))?'da':$_GET['ord'];
+ $order=$table->get_sql_order($ord);
+
+ // Count
+ $count=$this->cn->count_sql($sql);
+ // Add the limit
+ $sql.=$order.$limit.$offset;
+ // Execute SQL stmt
+ $Res=$this->cn->exec_sql($sql);
+
+ //starting from here we can refactor, so that instead of returning the generated HTML,
+ //this function returns a tree structure.
+
+ $r="";
+
+
+ $Max=Database::num_row($Res);
+
+ if ($Max==0)
+ return array(0, _("Aucun enregistrement trouvé"));
+
+ $r.='';
+
+
+ $r.="";
+ $r.="| "._("n° interne")." | ";
+ if ($this->type=='ALL')
+ {
+ $r.=th('Journal');
+ }
+ $r.=''.$table->get_header(0).' | ';
+ if ($p_paid!=0)
+ $r.=''.$table->get_header(1).'';
+ if ($p_paid!=0)
+ $r.=' | '.$table->get_header(2).' | ';
+ $r.=''.$table->get_header(3).' | ';
+ $r.=''.$table->get_header(4).' | ';
+ $r.=''.$table->get_header(6).' | ';
+ $r.=th('Notes', ' style="width:15%"');
+ $r.=''.$table->get_header(5).' | ';
+ // if $p_paid is not equal to 0 then we have a paid column
+ if ($p_paid!=0)
+ {
+ $r.=" "._('Payé')." | ";
+ }
+ $r.=""._('Concerne')." | ";
+ $r.=""._('Document')." | ";
+ $r.="
";
+ // Total Amount
+ $tot=0.0;
+ $gDossier=dossier::id();
+ for ($i=0; $i<$Max; $i++)
+ {
+
+
+ $row=Database::fetch_array($Res, $i);
+
+ if ($i%2==0)
+ $tr='';
+ else
+ $tr='
';
+ $r.=$tr;
+ //internal code
+ // button modify
+ $r.="| ";
+ // If url contains
+ //
+
+ $href=basename($_SERVER['PHP_SELF']);
+
+
+ $r.=sprintf('%s ',
+ $row['jr_id'], $gDossier, $row['jr_internal']);
+ $r.=" | ";
+ if ($this->type=='ALL')
+ $r.=td($row['jrn_def_name']);
+ // date
+ $r.="";
+ $r.=$row['str_jr_date'];
+ $r.=" | ";
+ // echeance
+ if ($p_paid!=0)
+ {
+ $r.="";
+ $r.=$row['str_jr_ech'];
+ $r.=" | ";
+ $r.="";
+ $r.=$row['str_jr_date_paid'];
+ $r.=" | ";
+ }
+
+ // pj
+ $r.="";
+ $r.=$row['jr_pj_number'];
+ $r.=" | ";
+
+ // Tiers
+ $other=($row['quick_code']!='')?'['.$row['quick_code'].'] '.$row['name'].' '.$row['first_name']:'';
+ $r.=td($other);
+ // comment
+ $r.="";
+ $tmp_jr_comment=h($row['jr_comment']);
+ $r.=$tmp_jr_comment;
+ $r.=" | ";
+ $r.=td(h($row['n_text']), ' style="font-size:0.87em%"');
+ // Amount
+ // If the ledger is financial :
+ // the credit must be negative and written in red
+ $positive=0;
+
+ // Check ledger type :
+ if ($row['jrn_def_type']=='FIN')
+ {
+ $positive=$this->cn->get_value("select qf_amount from quant_fin where jr_id=$1",
+ array($row['jr_id']));
+ if ($this->cn->count()!=0)
+ $positive=($positive<0)?1:0;
+ }
+ $r.="";
+ $t_amount=$row['jr_montant'];
+ if ($row['total_invoice']!=null&&$row['total_invoice']!=$row['jr_montant'])
+ $t_amount=$row['total_invoice'];
+ $tot=($positive!=0)?bcsub($tot, $t_amount):bcadd($tot, $t_amount);
+ //STAN $positive always == 0
+ if ($row ['jrn_def_type']=='FIN')
+ {
+ $r.=( $positive!=0 )?" - ".nbm($t_amount)."":nbm($t_amount);
+ }
+ else
+ {
+ $r.=( $t_amount<0 )?" ".nbm($t_amount)."":nbm($t_amount);
+ }
+ $r.=" | ";
+
+
+ // Show the paid column if p_paid is not null
+ if ($p_paid!=0)
+ {
+ $w=new ICheckBox();
+ $w->name="rd_paid".$row['jr_id'];
+ $w->selected=($row['jr_rapt']=='paid')?true:false;
+ // if p_paid == 2 then readonly
+ $w->readonly=( $p_paid==2)?true:false;
+ $h=new IHidden();
+ $h->name="set_jr_id".$row['jr_id'];
+ $r.=''.$w->input().$h->input().' | ';
+ if ($row['jr_rapt']=='paid')
+ $amount_paid=bcadd($amount_paid, $t_amount);
+ else
+ $amount_unpaid=bcadd($amount_unpaid, $t_amount);
+ }
+
+ // Rapprochement
+ $rec=new Acc_Reconciliation($this->cn);
+ $rec->set_jr_id($row['jr_id']);
+ $a=$rec->get();
+ $r.="";
+ if ($a!=null)
+ {
+
+ foreach ($a as $key=> $element)
+ {
+ $operation=new Acc_Operation($this->cn);
+ $operation->jr_id=$element;
+ $l_amount=$this->cn->get_value("select jr_montant from jrn ".
+ " where jr_id=$1", array($element));
+ $r.=" ".$operation->get_internal()."[".nbm($l_amount)."]";
+ }//for
+ }// if ( $a != null ) {
+ $r.=" | ";
+
+ if ($row['jr_valid']=='f')
+ {
+ $r.=""._("Opération annulée")." | ";
+ }
+ else
+ {
+
+ } // else
+ //document
+ if ($row['jr_pj_name']!="")
+ {
+ $r.=''.HtmlInput::show_receipt_document($row['jr_id']).' | ';
+ }
+ else
+ $r.=" | ";
+
+ // end row
+ $r.="
";
+ }
+ $amount_paid=round($amount_paid, 4);
+ $amount_unpaid=round($amount_unpaid, 4);
+ $tot=round($tot, 4);
+ $r.="";
+ $r.='| Total | ';
+ $r.=''.nbm($tot)." | ";
+ $r.="
";
+ if ($p_paid!=0)
+ {
+ $r.="";
+ $r.='| '._("Payé").' | ';
+ $r.=''.nbm($amount_paid)." | ";
+ $r.="
";
+ $r.="";
+ $r.='| '._("Non payé").' | ';
+ $r.=''.nbm($amount_unpaid)." | ";
+ $r.="
";
+ }
+ $r.="
";
+
+ return array($count, $r);
+ }
+
+ /**
+ * @brief Show all the operation
+ * @param$sql is the sql stmt, normally created by build_search_sql
+ * @param$offset the offset
+ * @param$p_paid if we want to see info about payment
+ @code
+ // Example
+ // Build the sql
+ list($sql,$where)=$Ledger->build_search_sql($_GET);
+ // Count nb of line
+ $max_line=$this->cn->count_sql($sql);
+
+ $step=$_SESSION['g_pagesize'];
+ $page=(isset($_GET['offset']))?$_GET['page']:1;
+ $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+ // create the nav. bar
+ $bar=navigation_bar($offset,$max_line,$step,$page);
+ // show a part
+ list($count,$html)= $Ledger->list_operation($sql,$offset,0);
+ echo $html;
+ // show nav bar
+ echo $bar;
+
+ @endcode
+ * @see build_search_sql
+ * @see display_search_form
+ * @see search_form
+
+ * @return HTML string
+ */
+ public function list_operation_to_reconcile($sql, $p_target)
+ {
+ global $g_parameter, $g_user;
+ $gDossier=dossier::id();
+ $limit=" LIMIT ".MAX_RECONCILE;
+ // Sort
+ // Count
+ $count=$this->cn->count_sql($sql);
+ // Add the limit
+ $sql.=" order by jr_date asc ".$limit;
+
+ // Execute SQL stmt
+ $Res=$this->cn->exec_sql($sql);
+
+ //starting from here we can refactor, so that instead of returning the generated HTML,
+ //this function returns a tree structure.
+
+ $r="";
+
+
+ $Max=Database::num_row($Res);
+
+ if ($Max==0)
+ return array(0, _("Aucun enregistrement trouvé"));
+ $r.=HtmlInput::hidden("target", $p_target);
+ $r.='';
+ return array($count, $r);
+ }
+
+}
diff --git a/include/database/user_filter_sql.class.php b/include/database/user_filter_sql.class.php
new file mode 100644
index 000000000..084c63233
--- /dev/null
+++ b/include/database/user_filter_sql.class.php
@@ -0,0 +1,92 @@
+table="public.user_filter";
+ $this->primary_key="id";
+ /*
+ * List of columns
+ */
+ $this->name=array(
+ "id"=>"id"
+ , "login"=>"login"
+ , "nb_jrn"=>"nb_jrn"
+ , "date_start"=>"date_start"
+ , "date_end"=>"date_end"
+ , "description"=>"description"
+ , "amount_min"=>"amount_min"
+ , "amount_max"=>"amount_max"
+ , "qcode"=>"qcode"
+ , "accounting"=>"accounting"
+ , "r_jrn"=>"r_jrn"
+ , "date_paid_start"=>"date_paid_start"
+ , "date_paid_end"=>"date_paid_end"
+ , "ledger_type"=>"ledger_type"
+ , "all_ledger"=>"all_ledger"
+ ,"unpaid"=>"unpaid"
+ ,'filter_name'=>"filter_name"
+ );
+ /*
+ * Type of columns
+ */
+ $this->type=array(
+ "id"=>"numeric"
+ , "login"=>"text"
+ , "nb_jrn"=>"numeric"
+ , "date_start"=>"text"
+ , "date_end"=>"text"
+ , "description"=>"text"
+ , "amount_min"=>"numeric"
+ , "amount_max"=>"numeric"
+ , "qcode"=>"text"
+ , "accounting"=>"text"
+ , "r_jrn"=>"text"
+ , "date_paid_start"=>"text"
+ , "date_paid_end"=>"text"
+ , "ledger_type"=>"text"
+ , "all_ledger"=>"numeric"
+ ,"unpaid"=>"text"
+ ,"filter_name"=>"text"
+ );
+
+
+ $this->default=array(
+ "id"=>"auto"
+ );
+
+ $this->date_format="DD.MM.YYYY";
+ parent::__construct($p_cn, $p_id);
+ }
+
+}
diff --git a/include/history_operation.inc.php b/include/history_operation.inc.php
index 8564a11a4..cdba89b4f 100644
--- a/include/history_operation.inc.php
+++ b/include/history_operation.inc.php
@@ -32,33 +32,29 @@ require_once NOALYSS_INCLUDE.'/class/acc_ledger_purchase.class.php';
require_once NOALYSS_INCLUDE.'/class/acc_ledger_fin.class.php';
require_once NOALYSS_INCLUDE.'/class/acc_ledger_sold.class.php';
require_once NOALYSS_INCLUDE.'/class/acc_ledger.class.php';
+require_once NOALYSS_INCLUDE.'/class/acc_ledger_search.class.php';
global $g_user,$cn,$http;
$p_array = $_GET;
$ledger_type=$http->get("ledger_type","string", 'ALL');
+
+$Ledger=new Acc_Ledger_Search($ledger_type,0,'search_op');
switch($ledger_type)
{
case 'ACH':
- $Ledger = new Acc_Ledger_Purchase($cn, 0);
$ask_pay=1;
break;
case 'ODS':
- $Ledger=new Acc_Ledger($cn,0);
$ask_pay=0;
$p_array['ledger_type']='ODS';
- $Ledger->type='ODS';
break;
case 'ALL':
- $Ledger=new Acc_Ledger($cn,0);
$ask_pay=0;
$p_array['ledger_type']='ALL';
- $Ledger->type='ALL';
break;
case 'VEN':
- $Ledger=new Acc_Ledger_Sold($cn,0);
$ask_pay=1;
break;
case 'FIN':
- $Ledger=new Acc_Ledger_Fin($cn,0);
$ask_pay=0;
break;
diff --git a/include/template/ledger_search.php b/include/template/ledger_search.php
index d0e418000..ccd65e377 100644
--- a/include/template/ledger_search.php
+++ b/include/template/ledger_search.php
@@ -1,15 +1,17 @@
-
+
-
+div}button","Filtre");
+$box->add_input(_('Ajout'), $save_filter);
+$box->add_javascript(_('Gestion Filtre'), $search_filter);
+echo $box->input();
+?>
diff --git a/scenario/test-iselect-button.php b/scenario/select-box-test.php
similarity index 77%
rename from scenario/test-iselect-button.php
rename to scenario/select-box-test.php
index ae37bed77..991c6fc71 100644
--- a/scenario/test-iselect-button.php
+++ b/scenario/select-box-test.php
@@ -8,23 +8,24 @@
background:white;
width:455px;
max-width:250px;
- position:relative;
- z-index:3;
padding:3px;
margin:0px;
display:none;
top:-17px;
+ position:absolute;
}
div.select_box ul {
list-style:none;
padding:2px;
margin:1px;
width:100%;
+ top:10px;
+
}
div.select_box ul li {
padding-top:2px;
padding-bottom:2px;
- margin:2px;
+ margin:2px;
}
div.select_box a {
text-decoration:none;
@@ -38,6 +39,12 @@ div.select_box a:hover,div.select_box ul li:hover {
+
+
+ Le CSS est important , surtout la position, il faut qu'il soit dans
+ un élément positionné en absolu.
+
+
input();
?>
+
+