";
$disable=($p_mode==0)?"disabled":"";
for ( $i =0 ; $i < sizeof($l_array); $i++) {
$content=$l_array[$i] ;
// for the first line
if ( $i == 0 ) {
$r.="
";
$r.="";
$r.="";
$r.='Postes ';
$r.='Description ';
$r.='Débit ';
$r.='Crédit ';
$head_ca="";
$own = new Own($p_cn);
if ( $own->MY_ANALYTIC != "un" )
{
$plan=new PlanAnalytic($p_cn);
$a_plan=$plan->get_list();
foreach ($a_plan as $r_plan)
{
$head_ca.="".$r_plan['name']." ";
}
}
$r.=$head_ca;
$r.=" ";
}
$r.="";
if ( $content['j_debit'] == 'f' ) $r.=$col_vide;
// $r.="".$content['j_debit']." ";
$r.="".$content['j_poste']." ";
if ( $content['j_debit'] == 't' ) $r.=$col_vide;
$r.="".$content['vw_name']." ";
if ( $content['j_debit'] == 'f' ) $r.=$col_vide;
$r.="".$content['j_montant']." ";
if ( $content['j_debit'] == 't' ) $r.=$col_vide;
//-- add ca
//
if ( $own->MY_ANALYTIC != "un" && ereg("^[6,7]+",$content['j_poste']))
{
echo_debug(__FILE__.":".__LINE__,"Content is ",$content);
$plan=new PlanAnalytic($p_cn);
$a_plan=$plan->get_list();
$null=($own->MY_ANALYTIC=='op')?1:0;
foreach ($a_plan as $r_plan)
{
echo_debug(__FILE__.":".__LINE__,"CA Content is ",$array);
$array=make_array($p_cn,
"select po_id as value,".
" po_name as label from poste_analytique ".
" where pa_id = ".$r_plan['id'].
" order by po_name",$null);
$op=new operation($p_cn);
$op_array=$op->get_operation_by_jid($content['j_id']);
$select = new widget("select","","plan_".$r_plan['id']."_".$content['j_id'],$array);
if ( $op_array != null)
foreach ($op_array as $row) {
echo_debug(__FILE__.":".__LINE__,"row is ",$row);
if ( $r_plan['id'] == $row->pa_id ) {
$select->selected=$row->po_id;
}
}
$select->table=1;
echo_debug(__FILE__.":".__LINE__,"select ",$select);
$select->readonly=($p_mode==0)?true:false;
$r.=$select->IOValue();
}
}
$r.=" ";
// }// foreach ($l_array[$i] as $value=>$content)
}// for ( $i =0 ; $i < sizeof($l_array); $i++)
if ( $p_mode == 1) {
$file=new widget("file");
$file->table=1;
//doc
if ( $content['jr_pj_name'] != "")
$r.='Effacer PJ ';
}
$r.="".sprintf('%s ',
$content['jr_id'],
$content['jr_grpt_id'],
$content['jr_pj_name'])." ";
$r.="
";
if ( $p_mode == 1 ) {
$r.=" ";
$r.= "";
$r.="".$file->IOValue("pj","","Pièce justificative")." ";
$r.="
";
}
$r.=" ";
$r.="";
$r.="Total ".$content['jr_montant']." ";
if ( $p_mode==1) {
// show all the related operation
$a=GetConcerned($p_cn,$content['jr_id']);
$sessid=$_REQUEST["PHPSESSID"];
if ( $a != null ) {
$r.="Operation concernée ";
$r.= '';
foreach ($a as $key => $element) {
$r.=sprintf ('%s ',
GetInternal($p_cn,$element),
$element,
$sessid);
$r.=sprintf(' ',
$content['jr_id'],$element,$sessid);
}//for
$r.= "
";
}// if ( $a != null ) {
$search=' ";
$r.= 'rapprochement
'.$search;
$r.=' ';
} // if mode == 1
return $r;
}
/*!
* \brief Display the form to UPDATE account operation in the user view
*
* \param $p_cn database connection
* \param $jr_id pk of jrn
* \param mode 1 editable, 0 for CA
* \return none
*
*
*/
function ShowOperationUser($p_cn,$p_jr_id,$p_mode=1)
{
echo_debug('jrn.php',__LINE__,"function UpdateJrn");
$l_array=GetDataJrnJrIdUser($p_cn,$p_jr_id);
/* if the operation doesn't exist in the quant_xxx table then we
* show the expert view
*/
if ( $l_array == null ) {
// If the operation is not in quant_sold or quant_purchase
// because those tables comes later
$r=ShowOperationExpert($p_cn,$p_jr_id,$p_mode);
return $r;
}
// own
$own=new own($p_cn);
echo_debug('jrn.php',__LINE__,$l_array);
// Javascript
$r=JS_VIEW_JRN_MODIFY;
// Build the form
$col_vide=" ";
$content=$l_array[0] ;
// for the first line
$internal=$content['jr_internal'];
$r.='';
$r.="";
// Date
$r.='';
$r.=$content['jr_date'];
$disable=($p_mode==0)?"disabled":"";
// for upload document we need the grpt_id
$r.=' ';
// comment can be changed
$comment=new widget("text");
$comment->table=0;
$comment->name="comment";
$comment->readonly=($p_mode==0)?true:false;
$comment->value=$content['jr_comment'];
$comment->size=40;
$r.=$comment->IOValue();
// Internal
$r.=$content['jr_internal'];
$r.=" ";
// Is Paid
$r.="";
$check=( $content['jr_rapt'] != null )?"CHECKED":"UNCHECKED";
$r.=' Payé ';
$r.=" ";
echo_debug(__FILE__.":".__LINE__."jrn_Def_type = ".$content['jrn_def_type']);
// for others lines
// for purchase ledger
if ( $content['jrn_def_type'] == 'ACH' )
{
$r.='';
echo_debug(__FILE__.":".__LINE__." content['qp_supplier'] ".$content['qp_supplier']);
$client=new fiche($p_cn,$content['qp_supplier']);
$r.="Client : ".$client->getName();
echo_debug(__FILE__,__LINE__,$content);
/* now we get the different lines for this operation thanks */
/* the qp_internal == jr_internal */
$r.='';
$r.='Nom ';
$r.='Quantité ';
$r.='tva ';
$r.='code tva ';
$r.='Non Ded. ';
$r.='tva nd ';
$r.='tva d impot ';
$r.='prix ';
$head_ca="";
$own = new Own($p_cn);
if ( $own->MY_ANALYTIC != "un" )
{
$plan=new PlanAnalytic($p_cn);
$a_plan=$plan->get_list();
foreach ($a_plan as $r_plan)
{
$head_ca.="".$r_plan['name']." ";
}
}
$r.=$head_ca;
$r.=' ';
$object=new gestion_purchase($p_cn);
$object->qp_internal=$internal;
$array=$object->get_list();
$tot_tva=0.0;
$tot_amount=0.0;
$tot_nd=0.0;
$tot_tva_nd=0.0;
$tot_tva_nd_recup=0.0;
$i=0;
foreach ($array as $row) {
$fiche=new fiche($p_cn,$row->qp_fiche);
// compute sum
$tot_tva+=$row->qp_vat;
$tot_nd+=$row->qp_nd_amount;
$tot_tva_nd+=$row->qp_nd_tva;
$tot_tva_nd_recup+=$row->qp_nd_tva_recup;
$tot_amount+=$row->qp_price;
// $hid_jid=new widget("hidden","","p_jid_".$row->j_id,$row->j_id);
$r.=($i%2==0)?"":' '; $i++;
$r.=' '.$fiche->strAttribut(ATTR_DEF_NAME).' ';
$r.=''.$row->qp_quantite.' ';
$r.=''.$row->qp_vat.' ';
$r.=''.$row->qp_vat_code.' ';
$r.=''.$row->qp_nd_amount.' ';
$r.=''.$row->qp_nd_tva.' ';
$r.=''.$row->qp_nd_tva_recup.' ';
$r.=''.$row->qp_price.' ';
//-- add ca
//
$content['j_poste']=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
// echo "j_poste= ".$content['j_poste'];
if ( $own->MY_ANALYTIC != "un" && ereg("^[6,7]+",$content['j_poste']))
{
echo_debug(__FILE__.":".__LINE__,"Content is ",$content);
$plan=new PlanAnalytic($p_cn);
$a_plan=$plan->get_list();
$null=($own->MY_ANALYTIC=='op')?1:0;
foreach ($a_plan as $r_plan)
{
echo_debug(__FILE__.":".__LINE__,"CA Content is ",$array);
$array=make_array($p_cn,
"select po_id as value,".
" po_name as label from poste_analytique ".
" where pa_id = ".$r_plan['id'].
" order by po_name",$null);
$op=new operation($p_cn);
$op_array=$op->get_operation_by_jid($content['j_id']);
$select = new widget("select","","plan_".$r_plan['id']."_".$row->j_id,$array);
if ( $op_array != null)
foreach ($op_array as $row) {
echo_debug(__FILE__.":".__LINE__,"row is ",$row);
if ( $r_plan['id'] == $row->pa_id ) {
$select->selected=$row->po_id;
}
}
$select->table=1;
$select->readonly=($p_mode==0)?true:false;
echo_debug(__FILE__.":".__LINE__,"select ",$select);
$r.=$select->IOValue();
}
}
$r.=" ";
}
// display sum
$r.=' ';
$r.=''.
'Total HTVA '.
''.sprintf('% 12.2f',$tot_amount)." ".
" ";
$r.=''.
'Total TVA '.
''.sprintf('%12.2f',$tot_tva)
." ".
" ";
$r.=''.
'Total nd '.
''.sprintf('%12.2f',$tot_nd)." ".
" ";
$r.=''.
'Total tva nd '.
''.sprintf('%12.2f',$tot_tva_nd)." ".
" ";
$r.=''.
'Total tva nd recup. par impot '.
''.sprintf('%12.2f',$tot_tva_nd_recup)." ".
" ";
$r.=''.
'Total '.
''.sprintf('%12.2f',$tot_amount+$tot_tva)." ".
" ";
$r.= '
';
}
// for selling ledger
if ( $content['jrn_def_type'] == 'VEN' )
{
echo_debug(__FILE__.":".__LINE__." content['qs_client'] ".$content['qs_client']);
$client=new fiche($p_cn,$content['qs_client']);
$r.="Client : ".$client->getName();
echo_debug(__FILE__,__LINE__,$content);
/* now we get the different lines for this operation thanks */
/* the qs_internal == jr_internal */
$r.='';
$r.='Nom ';
$r.='Quantité ';
$r.='tva ';
$r.='code tva ';
$r.='prix ';
$head_ca="";
$own = new Own($p_cn);
if ( $own->MY_ANALYTIC != "un" )
{
$plan=new PlanAnalytic($p_cn);
$a_plan=$plan->get_list();
foreach ($a_plan as $r_plan)
{
$head_ca.="".$r_plan['name']." ";
}
}
$r.=$head_ca;
$r.=' ';
$object=new gestion_sold($p_cn);
$object->qs_internal=$internal;
$array=$object->get_list();
$tot_tva=0.0;
$tot_amount=0.0;
$i=0;
foreach ($array as $row) {
$fiche=new fiche($p_cn,$row->qs_fiche);
$tot_tva+=$row->qs_vat;
$tot_amount+=$row->qs_price;
$r.=($i%2==0)?"":' '; $i++;
/* $hid_jid=new widget("hidden","","p_jid_".$row->j_id,$row->j_id); */
/* $r.=$hid_jid->IOValue(); */
$r.=($i%2==0)?" ":' '; $i++;
$r.=' '.$fiche->strAttribut(ATTR_DEF_NAME).' ';
$r.=''.$row->qs_quantite.' ';
$r.=''.$row->qs_vat.' ';
$r.=''.$row->qs_vat_code.' ';
$r.=''.$row->qs_price.' ';
//-- add ca
//
$content['j_poste']=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
// echo "j_poste= ".$content['j_poste'];
if ( $own->MY_ANALYTIC != "un" && ereg("^[6,7]+",$content['j_poste']))
{
echo_debug(__FILE__.":".__LINE__,"Content is ",$content);
$plan=new PlanAnalytic($p_cn);
$a_plan=$plan->get_list();
$null=($own->MY_ANALYTIC=='op')?1:0;
foreach ($a_plan as $r_plan)
{
echo_debug(__FILE__.":".__LINE__,"CA Content is ",$array);
$array=make_array($p_cn,
"select po_id as value,".
" po_name as label from poste_analytique ".
" where pa_id = ".$r_plan['id'].
" order by po_name",$null);
$op=new operation($p_cn);
$op_array=$op->get_operation_by_jid($content['j_id']);
$select = new widget("select","","plan_".$r_plan['id']."_".$row->j_id,$array);
if ( $op_array != null)
foreach ($op_array as $row) {
echo_debug(__FILE__.":".__LINE__,"row is ",$row);
if ( $r_plan['id'] == $row->pa_id ) {
$select->selected=$row->po_id;
}
}
$select->table=1;
$select->readonly=($p_mode==0)?true:false;
echo_debug(__FILE__.":".__LINE__,"select ",$select);
$r.=$select->IOValue();
}
}
$r.=" ";
}
$r.="".
""." ".
""." ".
""." ".
"Total HTVA ".
''.sprintf('% 12.2f',$tot_amount)." ".
" ";
$r.="".
""." ".
""." ".
""." ".
"Total TVA ".
''.sprintf('%12.2f',$tot_tva)
." ".
" ";
$r.="".
""." ".
""." ".
""." ".
"Total ".
''.sprintf('%12.2f',$tot_amount+$tot_tva)." ".
" ";
}
$r.="
";
$file=new widget("file");
$file->table=1;
//doc
if ( $p_mode ==1 && $content['jr_pj_name'] != "")
$r.='Effacer Pj ';
$r.="".sprintf('%s ',
$content['jr_id'],
$content['jr_grpt_id'],
$content['jr_pj_name'])." ";
$r.=" ";
$r.=" ";
if ( $p_mode == 1 ) {
$r.= "";
$r.="".$file->IOValue("pj","","Pièce justificative")." ";
$r.="
";
$r.=" ";
$r.="";
$r.="Total ".$content['jr_montant']." ";
// show all the related operation
$a=GetConcerned($p_cn,$content['jr_id']);
$sessid=$_REQUEST["PHPSESSID"];
if ( $a != null ) {
$r.="Operation concernée ";
$r.= '';
foreach ($a as $key => $element) {
$r.=sprintf ('%s ',
GetInternal($p_cn,$element),
$element,
$sessid);
$r.=sprintf(' ',
$content['jr_id'],$element,$sessid);
}//for
$r.= "
";
}// if ( $a != null ) {
$search=' ";
$r.= 'rapprochement
'.$search;
$r.=' ';
} // if p_mode==1
// echo $r;
return $r;
}
/*!
* \brief Get the properties of a journal
*
* parm :
* - p_dossier the folder id
* - p_jrn the jrn id
* gen :
* - none
* return:
* - an array containing properties
*
*/
function GetJrnProp($p_dossier,$p_jrn,$is_connected=0)
{
echo_debug("jrn.php",__LINE__,"GetJrnProp $p_dossier");
if ( $is_connected == 0 )
$cn=DbConnect($p_dossier);
else
$cn=$p_dossier;
$Res=ExecSql($cn,"select jrn_Def_id,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_def_type,
jrn_deb_max_line,jrn_cred_max_line,jrn_def_ech,jrn_def_ech_lib,jrn_def_code,
jrn_def_fiche_deb,jrn_def_fiche_deb
from jrn_Def
where jrn_def_id=$p_jrn");
$Count=pg_NumRows($Res);
if ( $Count == 0 ) {
echo '
Paramètres journaux non trouvés ';
return null;
}
return pg_fetch_array($Res,0);
}
/*!
* \brief Vue des écritures comptables
*
* parm :
* - p_dossier,
* - p_user,
* - p_jrn
* - p_url for modif
* - array
* gen :
* -
* return:
* -
*
*/
function ViewJrn($p_dossier,$p_user,$p_jrn,$p_url,$p_array=null) {
echo_debug('jrn.php',__LINE__,"function ViewJrn($p_dossier,$p_user,$p_jrn,$p_array=null) ");
$db=sprintf("dossier%d",$p_dossier);
$l_prop=GetJrnProp($p_dossier,$p_jrn);
echo "".$l_prop['jrn_def_name']."( ".$l_prop['jrn_def_code'].")"." ";
$cn=DbConnect($p_dossier);
if ( $p_array == null) {
include_once("preference.php");
$l_periode=GetUserPeriode($cn,$p_user);
$Res=ExecSql($cn,"select jr_id,j_id,jr_internal,to_char(j_date,'DD.MM.YYYY') as j_date,
j_montant,j_poste,pcm_lib,j_grpt,j_debit,j_centralized,j_tech_per,
pcm_lib
from jrnx inner join tmp_pcmn on j_poste=pcm_val
inner join jrn on jr_grpt_id=j_grpt
where
j_jrn_def=$p_jrn and j_tech_per=$l_periode
order by j_id,j_grpt,j_debit desc");
} else {
// Construction Query
foreach ( $p_array as $key=>$element) {
${"l_$key"}=$element;
echo_debug ("l_$key $element");
}
$sql="select j_id,to_char(j_date,'DD.MM.YYYY') as j_date,j_montant,j_poste,
pcm_lib,j_grpt,jr_id,j_debit,j_centralized,j_tech_per,jr_internal
from jrnx inner join tmp_pcmn on j_poste=pcm_val
inner join jrn on jr_grpt_id=j_grpt
where
j_jrn_def=$p_jrn";
$l_and="and ";
if ( ereg("^[0-9]+$", $l_s_montant) || ereg ("^[0-9]+\.[0-9]+$", $l_s_montant) ) {
$sql.=" and jr_montant $l_mont_sel $l_s_montant";
}
if ( isDate($l_date_start) != null ) {
$sql.=$l_and." j_date >= to_date('".$l_date_start."','DD.MM.YYYY')";
}
if ( isDate($l_date_end) != null ) {
$sql.=$l_and." j_date <= to_date('".$l_date_end."','DD.MM.YYYY')";
}
$l_s_comment=FormatString($l_s_comment);
if ( $l_s_comment != null ) {
$sql.=$l_and." upper(jr_comment) like upper('%".$l_s_comment."%') ";
}
$sql.=" order by j_id,j_grpt,j_debit desc";
echo_debug ("search query is $sql");
$Res=ExecSql($cn,$sql);
}
$MaxLine=pg_NumRows($Res);
if ( $MaxLine == 0 ) return;
$col_vide=" ";
echo '';
}
/*!
* \brief Get data from jrnx where p_grpt=jrnx(j_grpt)
*
* parm :
* - connection
* - p_grpt
* gen :
* - none
* return:
* - return array
*
*/
function GetData ($p_cn,$p_grpt) {
echo_debug('jrn.php',__LINE__,"GetData $p_cn $p_grpt");
$Res=ExecSql($p_cn,"select
to_char(j_date,'DD.MM.YYYY') as j_date,
j_text,
j_debit,
j_poste,
j_montant,
j_id,
jr_comment,
to_char(jr_ech,'DD.MM.YYYY') as jr_ech,
to_char(jr_date,'DD.MM.YYYY') as jr_date,
jr_id,jr_internal,jr_def_id,jr_pj
from jrnx inner join jrn on j_grpt=jr_grpt_id where j_grpt=$p_grpt");
$MaxLine=pg_NumRows($Res);
if ( $MaxLine == 0 ) return null;
$deb=0;$cred=0;
for ( $i=0; $i < $MaxLine; $i++) {
$l_line=pg_fetch_array($Res,$i);
$l_array['op_date']=$l_line['j_date'];
if ( $l_line['j_debit'] == 't' ) {
$l_class=sprintf("class_deb%d",$deb);
$l_montant=sprintf("mont_deb%d",$deb);
$l_text=sprintf("text_deb%d",$deb);
$l_array[$l_class]=$l_line['j_poste'];
$l_array[$l_montant]=$l_line['j_montant'];
$l_array[$l_text]=$l_line['j_text'];
$l_id=sprintf("op_deb%d",$deb);
$l_array[$l_id]=$l_line['j_id'];
$deb++;
}
if ( $l_line['j_debit'] == 'f' ) {
$l_class=sprintf("class_cred%d",$cred);
$l_montant=sprintf("mont_cred%d",$cred);
$l_array[$l_class]=$l_line['j_poste'];
$l_array[$l_montant]=$l_line['j_montant'];
$l_id=sprintf("op_cred%d",$cred);
$l_array[$l_id]=$l_line['j_id'];
$l_text=sprintf("text_cred%d",$deb);
$l_array[$l_text]=$l_line['j_text'];
$cred++;
}
$l_array['jr_internal']=$l_line['jr_internal'];
$l_array['comment']=$l_line['jr_comment'];
$l_array['ech']=$l_line['jr_ech'];
$l_array['jr_id']=$l_line['jr_id'];
$l_array['jr_def_id']=$l_line['jr_def_id'];
}
return array($l_array,$deb,$cred);
}
/*!
* \brief
*
* parm :
* -
* gen :
* -
* return:
* - -1 si aucune valeur de trouvée
*
*/
// function GetRapt($p_cn,$p_rappt) {
// $Res=ExecSql($p_cn,"select jr_id from jrn where jr_rapt='$p_rappt'");
// if ( pg_NumRows($Res) == 0 ) return -1;
// $l_line=pg_fetch_array($Res);
// return $l_line['jr_id'];
// }
/*!
* \brief Return the internal value
*
* parm :
* - p_cn database connection
* - p_id : jrn.jr_id
* gen :
* - none
* return:
* - null si aucune valeur de trouvée
*
*/
function GetInternal($p_cn,$p_id) {
$Res=ExecSql($p_cn,"select jr_internal from jrn where jr_id=$p_id");
if ( pg_NumRows($Res) == 0 ) return null;
$l_line=pg_fetch_array($Res);
return $l_line['jr_internal'];
}
/*!
* \brief return the sum of jrn where
* the internal_code is the p_id
*
* parm :
* - $p_cn database connection
* - p_id = jrn.jr_internal
* gen :
* -
* return:
* - number
*
*/
function GetAmount($p_cn,$p_id) {
$Res=ExecSql($p_cn,"select jr_montant from jrn where jr_internal='$p_id'");
if (pg_NumRows($Res)==0) return -1;
$l_line=pg_fetch_array($Res,0);
return $l_line['jr_montant'];
}
/*!
* \brief Verify the data before inserting or
* updating
*
* parm :
* - p_cn connection
* - p_array array with all the values
* - p_user
* gen :
* - none
* return:
* - errorcode or ok
*
*/
function VerifData($p_cn,$p_array,$p_user)
{
if ( ! isset ($p_cn) ||
! isset ($p_array)||
! isset ($p_user)||
$p_array == null ){
echo_error("JRN.PHP VerifData missing parameter");
return BADPARM;
}
// Montre ce qu'on a encodé et demande vérif
$next="";
foreach ( $p_array as $name=>$element ) {
echo_debug('jrn.php',__LINE__,"element $name -> $element ");
// Sauve les données dans des variables
${"p_$name"}=$element;
}
// Verif Date
if ( isDate($p_op_date) == null) {
return BADDATE;
}
// userPref contient la periode par default
$userPref=$p_user->GetPeriode();
list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$userPref);
// Date dans la periode active
echo_debug ("date start periode $l_date_start date fin periode $l_date_end date demandée $p_op_date");
if ( cmpDate($p_op_date,$l_date_start)<0 ||
cmpDate($p_op_date,$l_date_end)>0 )
{
return NOTPERIODE;
}
// Periode fermée
if ( PeriodeClosed ($p_cn,$userPref)=='t' )
{
return PERIODCLOSED;
}
$l_mont=0;
if ( ! isset ($p_ech) ) $p_ech="";
if ($p_ech!='' && isDate ( $p_ech) == null ){
return INVALID_ECH;
}
$tot_deb= 0;
$tot_cred= 0;
for ( $i = 0; $i < $p_MaxCred; $i++) {
if ( isset ( ${"p_mont_cred$i"} ))
$tot_cred+=${"p_mont_cred$i"};
}
for ( $i = 0; $i < $p_MaxDeb; $i++) {
if ( isset ( ${"p_mont_deb$i"} ))
$tot_deb+=${"p_mont_deb$i"};
}
echo_debug('jrn.php',__LINE__,"Amont = $tot_deb $tot_cred");
if ( round($tot_deb,2) != round($tot_cred,2) ) {
return DIFF_AMOUNT;
}
return NOERROR;
}
/*!
* \brief Return the name of the jrn
*
* parm :
* - p_cn connexion resource
* - jrn id
* gen :
* - none
* return:
* - string or null if not found
*
*/
function GetJrnName($p_cn,$p_id) {
$Res=ExecSql($p_cn,"select jrn_def_name from ".
" jrn_def where jrn_def_id=".
$p_id);
$Max=pg_NumRows($Res);
if ($Max==0) return null;
$ret=pg_fetch_array($Res,0);
return $ret['jrn_def_name'];
}
/*!
* \brief
* Get the number of the next jrn
* from the jrn_def.jrn_code
*
* parm :
* - $p_cn connection
* - $p_type jrn type
* gen :
* - none
* return:
* - string containing the next code
*
*/
function NextJrn($p_cn,$p_type)
{
$Ret=CountSql($p_cn,"select * from jrn_def where jrn_def_type='".$p_type."'");
return $Ret+1;
}
/*!
* \brief
*
* parm :
* - $p_cn connection
* - $p_grpt id in jr_grpt_id
* - $p_jrn jrn id jrn_def_id
* - $p_dossier dossier id
* gen :
* -
* return:
* -
*
*/
function SetInternalCode($p_cn,$p_grpt,$p_jrn)
{
//$num=CountSql($p_cn,"select * from jrn where jr_def_id=$p_jrn and jr_internal != 'ANNULE'")+1;
$num = NextSequence($p_cn,'s_internal');
$num=strtoupper(hexdec($num));
$atype=GetJrnProp($_SESSION['g_dossier'],$p_jrn);
$type=$atype['jrn_def_code'];
$internal_code=sprintf("%d%s-%s",$_SESSION['g_dossier'],$type,$num);
echo_debug ("jrn.php",__LINE__,"internal_code = $internal_code");
return $internal_code;
}
/*!
* \brief Get data from jrn and jrnx thanks the jr_id
*
*
* \param connection
* \param p_jr_id (jrn.jr_id)
*
*
* \return array
*
*/
function GetDataJrnJrId ($p_cn,$p_jr_id) {
echo_debug('jrn.php',__LINE__,"GetDataJrn $p_cn $p_jr_id");
$Res=ExecSql($p_cn,"select
j_text,
j_debit,
j_poste,
pcm_lib,
j_montant,
jr_montant,
j_id,
jr_pj_name,
jr_grpt_id,
jr_comment,
to_char(jr_ech,'DD.MM.YYYY') as jr_ech,
to_char(jr_date,'DD.MM.YYYY') as jr_date,
jr_id,jr_internal, jr_rapt,jrn_def_type,
j_qcode
from
jrnx
inner join jrn on j_grpt=jr_grpt_id
inner join jrn_def on jrn_def.jrn_def_id=jrn.jr_def_id
left outer join tmp_pcmn on j_poste=pcm_val
where
jr_id=$p_jr_id
order by j_debit desc");
$MaxLine=pg_NumRows($Res);
echo_debug('jrn.php',__LINE__,"Found $MaxLine lines");
if ( $MaxLine == 0 ) return null;
for ( $i=0; $i < $MaxLine; $i++) {
$line=pg_fetch_array($Res,$i);
$array['j_debit']=$line['j_debit'];
// is there a name from this j_qcode
//
if ( strlen( $line['j_qcode']) != 0 )
{
$fiche=new fiche($p_cn);
$fiche->GetByQCode($line['j_qcode']);
$array['vw_name']=$fiche->getName();
}
else
{
$array['vw_name']=$line['pcm_lib'];
}
$array['jr_comment']=$line['jr_comment'];
$array['j_montant']=$line['j_montant'];
$array['jr_id']=$line['jr_id'];
$array['j_id']=$line['j_id'];
$array['jr_date']=$line['jr_date'];
$array['jr_internal']=$line['jr_internal'];
$array['j_poste']=$line['j_poste'];
$array['jr_montant']=$line['jr_montant'];
$array['jr_rapt']=$line['jr_rapt'];
$array['jrn_def_type']=$line['jrn_def_type'];
$array['jr_grpt_id']=$line['jr_grpt_id'];
$array['jr_pj_name']=$line['jr_pj_name'];
// $array['']=$line[''];
$ret_array[$i]=$array;
}
return $ret_array;
}
/*!
* \brief Get data from quant_sold or quand_purchase for the user
* view mode
*
*
* \param connection
* \param p_jr_id (jrn.jr_id)
*
*
* \return array or null if there is no value
*
*/
function GetDataJrnJrIdUser ($p_cn,$p_jr_id) {
echo_debug(__FILE__.":".__LINE__."GetDataJrnJrIdUser");
$Res=ExecSql($p_cn,"select ".
"*".
" from quant_sold join jrn on (qs_internal=jr_internal) ".
" join jrn_def on (jr_def_id=jrn_def_id) ".
" where jr_id=$p_jr_id");
$MaxLine=pg_NumRows($Res);
echo_debug('jrn.php',__LINE__,"Found $MaxLine lines");
// if no info found in quant_sold try in quant_purchase
if ( $MaxLine == 0 )
{
$Res=ExecSql($p_cn,"select ".
"*".
" from quant_purchase join jrn on (qp_internal=jr_internal)".
" join jrn_def on (jr_def_id=jrn_def_id) ".
" where jr_id=$p_jr_id");
$MaxLine=pg_NumRows($Res);
if ( $MaxLine == 0 ) return null;
}
for ( $i=0; $i < $MaxLine; $i++) {
$line=pg_fetch_array($Res,$i);
$array['j_debit']=$line['j_debit'];
// is there a name from this j_qcode
//
if ( strlen( $line['j_qcode']) != 0 )
{
$fiche=new fiche($p_cn);
$fiche->GetByQCode($line['j_qcode']);
$array['vw_name']=$fiche->getName();
}
else
{
$array['vw_name']=$line['pcm_lib'];
}
if ( isset ($line['qs_client']))
{
/* It is an invoice */
$array['qs_client']=$line['qs_client'];
}
else
{
/* it a purchase */
$array['qp_supplier']=$line['qp_supplier'];
}
$array['jr_comment']=$line['jr_comment'];
$array['j_montant']=$line['j_montant'];
$array['jr_id']=$line['jr_id'];
$array['j_id']=$line['j_id'];
$array['jr_date']=$line['jr_date'];
$array['jr_internal']=$line['jr_internal'];
$array['j_poste']=$line['j_poste'];
$array['jr_montant']=$line['jr_montant'];
$array['jr_rapt']=$line['jr_rapt'];
$array['jrn_def_type']=$line['jrn_def_type'];
$array['jr_grpt_id']=$line['jr_grpt_id'];
$array['jr_pj_name']=$line['jr_pj_name'];
// $array['']=$line[''];
$ret_array[$i]=$array;
}
return $ret_array;
}
?>