';
$r.=HtmlInput::title_box(_('Recherche'), "search_form", "hide", "", "n");
$r.='';
$r.='
';
$button=new IButton('tfs');
$button->label=_("Chercher");
$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[SESSION_KEY.'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
@note $this->inject_code (string) code into Acc_Ledger_Search::list_operation
* Example of using inject_col to inject a new column
* @code
%s // %s", $param['jr_id'], $param['jr_montant']);
} elseif ($param == 'header')
{
return '';
$r.="";
$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.=th('Journal');
if ( $this->type != "ODS")
{
$r.=''.$table->get_header(4).' | ';
}
$r.=""._("n° interne")." | ";
$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')." | ";
if ( $this->inject_col != null)
{
$r.=call_user_func($this->inject_col,"header");
}
$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;
// 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.=" | ";
// Ledger
$r.=td($row['jrn_def_name']);
if ($this->type != 'ODS')
{
// Tiers
$other=($row['quick_code']!='')?HtmlInput::card_detail($row['quick_code'],h($row['name'].' '.$row['first_name'])):'';
$r.=td($other);
}
// Internal number
$r.="";
$r.=sprintf('%s ',
$row['jr_id'], $gDossier, $row['jr_internal']);
$r.=" | ";
// comment
$r.="";
$tmp_jr_comment=h($row['jr_comment']).$row['tag_operation'];
$r.=$tmp_jr_comment;
if ( $row['analytic_op'] != "")
$r.=sprintf('∋');
$r.=" | ";
// Note
$r.='';
$r.='';
$r.= mb_substr($row['n_text']??"",0,120);
$r.='';
$r.='';
$r.=' | ';
// 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->set_range("paid_operation_ck");
$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;
$w->javascript='onclick="operation_payment.check_item(this)"';
$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.=" | ";
//< inject_code (string) code into list_operation
// to add an extra column
// (see Acc_Ledger_Search::list_operation).
// All the HTML code must be in inject_code, including the TD tag
if ( $this->inject_col != null)
{
$r.=call_user_func($this->inject_col,$row);
}
// end row
$r.="
";
}
$amount_paid=round($amount_paid, 4);
$amount_unpaid=round($amount_unpaid, 4);
$tot=round($tot, 4);
$r.="";
$r.='| Total | ';
$r.=td("").td("");
$r.=''.nbm($tot)." | ";
$r.="
";
if ($p_paid!=0)
{
$r.="";
$r.='| '._("Payé").' | ';
$r.=td("").td("").td("").td('');
$r.=''.nbm($amount_paid)." | ";
$r.="
";
$r.="";
$r.='| '._("Non payé").' | ';
$r.=td("").td("").td("").td('');
$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[SESSION_KEY.'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);
}
/**
* @brief return the html code to create an hidden div and a button
* to show this DIV. This contains all the available ledgers
* for the user in READ or RW
*@param $p_selected is an array of checkbox
*@param $p_div div suffix for the list of ledgers, base for building the DOMID of elements from the DIV
*@note the choosen ledger are stored in the array r_jrn (_GET)
*/
function select_ledger($p_selected,$p_div)
{
global $g_user;
$r = '';
/* security : filter ledger on user */
$p_array = $g_user->get_ledger($this->type, 3,false);
ob_start();
/* create a hidden div for the ledger */
echo '