';
- ImportCSV($cn,$_FILES['fupload']['tmp_name'],$_POST['import_bq'],$_POST['format_csv'],$_POST['import_jrn']);
- echo "
";
- } else {
- echo '';
+ ImportCSV($cn,$_FILES['fupload']['tmp_name'],$_POST['import_bq'],$_POST['format_csv'],$_POST['import_jrn']);
+ echo "
";
+ }
+ else
+ {
+ echo '';
- /* show the possible period */
- $default_period=$User->get_periode();
- $ip=new IPeriod('period');
- $ip->filter_year=true;
- $ip->user=$User;
- $ip->value=(isset($_GET['period']))?$_GET['period']:$default_period;
- $ip->cn=$cn;
- $ip->type=OPEN;
- $ip->javascript="onchange=submit(this)";
- echo '';
- // TransferCSV($cn,
- ConfirmTransfert($cn,$ip->value);
- echo "
";
- }
-}
+ echo '';
+ /* show the possible period */
+ $default_period=$User->get_periode();
+ $ip=new IPeriod('period');
+ $ip->filter_year=true;
+ $ip->user=$User;
+ $ip->value=(isset($_GET['period']))?$_GET['period']:$default_period;
+ $ip->cn=$cn;
+ $ip->type=OPEN;
+ $ip->javascript="onchange=submit(this)";
+ echo '';
+ // TransferCSV($cn,
+ ConfirmTransfert($cn,$ip->value);
+ echo "
";
+ }
+}
/*-----------------------------------------------
* transfert or remove the wrong record
*
*-----------------------------------------------*/
-if ( isset ($_POST['action'])) {
- $action=$_POST['action'];
- if ($action == "transfer" ) {
- echo '';
- RemoveCSV($cn);
- ConfirmTransfert($cn,$User->get_periode());
- echo "
";
- }
+ if ($action == "remove" )
+ {
+ echo '';
+ RemoveCSV($cn);
+ ConfirmTransfert($cn,$User->get_periode());
+ echo "
";
+ }
}
-if ( isset($_REQUEST['action']) && $_REQUEST['action']=='purge') {
- if ( isset($_POST['ok'])) {
- echo '';
- echo h2info('Toutes les données CSV sont effacées');
- $cn->exec_sql('truncate import_tmp');
- echo '
';
+if ( isset($_REQUEST['action']) && $_REQUEST['action']=='purge')
+{
+ if ( isset($_POST['ok']))
+ {
+ echo '';
+ echo h2info('Toutes les données CSV sont effacées');
+ $cn->exec_sql('truncate import_tmp');
+ echo '
';
- } else {
- echo '
Pour une meilleure expérience web, nous vous conseillons firefox
diff --git a/html/jrn_csv.php b/html/jrn_csv.php
index 72ea45fa8..dea2b6b9e 100644
--- a/html/jrn_csv.php
+++ b/html/jrn_csv.php
@@ -42,8 +42,11 @@ $User->Check();
$User->can_request(IMPJRN,0);
$User->check_dossier($gDossier);
-if ($_GET['jrn_id']!=0 && $User->check_jrn($_GET['jrn_id']) =='X') {
- NoAccess(); exit();}
+if ($_GET['jrn_id']!=0 && $User->check_jrn($_GET['jrn_id']) =='X')
+{
+ NoAccess();
+ exit();
+}
$Jrn=new Acc_Ledger($cn,$_GET['jrn_id']);
@@ -52,135 +55,140 @@ $jrn_type=$Jrn->get_type();
// Detailled printing
//---
-if ( $_GET['p_simple'] == 0 )
- {
+if ( $_GET['p_simple'] == 0 )
+{
$Jrn->get_row( $_GET['from_periode'],
- $_GET['to_periode']
- );
+ $_GET['to_periode']
+ );
- if ( count($Jrn->row) == 0)
- exit;
- foreach ( $Jrn->row as $op ) {
- // should clean description : remove
tag and '; char
- $desc=$op['description'];
- $desc=str_replace("","",$desc);
- $desc=str_replace(" ","",$desc);
- $desc=str_replace("","",$desc);
- $desc=str_replace(" ","",$desc);
- $desc=str_replace('"',"'",$desc);
- $desc=str_replace(";",",",$desc);
+ if ( count($Jrn->row) == 0)
+ exit;
+ foreach ( $Jrn->row as $op )
+ {
+ // should clean description : remove tag and '; char
+ $desc=$op['description'];
+ $desc=str_replace("","",$desc);
+ $desc=str_replace(" ","",$desc);
+ $desc=str_replace("","",$desc);
+ $desc=str_replace(" ","",$desc);
+ $desc=str_replace('"',"'",$desc);
+ $desc=str_replace(";",",",$desc);
+
+ printf("\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";%s;%s\n",
+ $op['j_id'],
+ $op['internal'],
+ $op['j_date'],
+ $op['poste'],
+ $desc,
+ nb($op['deb_montant']),
+ nb($op['cred_montant'])
+ );
- printf("\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";%s;%s\n",
- $op['j_id'],
- $op['internal'],
- $op['j_date'],
- $op['poste'],
- $desc,
- nb($op['deb_montant']),
- nb($op['cred_montant'])
- );
-
}
exit;
- }
- else
- {
- $Row=$Jrn->get_rowSimple($_GET['from_periode'],
- $_GET['to_periode'],
- 0);
+}
+else
+{
+ $Row=$Jrn->get_rowSimple($_GET['from_periode'],
+ $_GET['to_periode'],
+ 0);
//-----------------------------------------------------
- if ( $jrn_type == 'ODS' || $jrn_type == 'FIN' || $jrn_type=='GL')
- {
- printf ('" operation";'.
- '"Date";'.
- '"commentaire";'.
- '"internal";'.
- '"montant";'.
- "\r\n");
- // set a filter for the FIN
- $a_parm_code=$cn->get_array("select p_value from parm_code where p_code in ('BANQUE','COMPTE_COURANT','CAISSE')");
- $sql_fin="(";
- $or="";
- foreach ($a_parm_code as $code) {
- $sql_fin.="$or j_poste::text like '".$code['p_value']."%'";
- $or=" or ";
- }
- $sql_fin.=")";
+ if ( $jrn_type == 'ODS' || $jrn_type == 'FIN' || $jrn_type=='GL')
+ {
+ printf ('" operation";'.
+ '"Date";'.
+ '"commentaire";'.
+ '"internal";'.
+ '"montant";'.
+ "\r\n");
+ // set a filter for the FIN
+ $a_parm_code=$cn->get_array("select p_value from parm_code where p_code in ('BANQUE','COMPTE_COURANT','CAISSE')");
+ $sql_fin="(";
+ $or="";
+ foreach ($a_parm_code as $code)
+ {
+ $sql_fin.="$or j_poste::text like '".$code['p_value']."%'";
+ $or=" or ";
+ }
+ $sql_fin.=")";
- foreach ($Row as $line)
- {
-
- echo $line['num'].";";
- echo $line['date'].";";
- echo $line['comment'].";";
- echo $line['jr_internal'].";";
- // echo " ".$line['pj'].";";
- // If the ledger is financial :
- // the credit must be negative and written in red
- // Get the jrn type
- if ( $line['jrn_def_type'] == 'FIN' ) {
- $positive = $cn->get_value("select qf_amount from quant_fin ".
- " where jr_id=".$line['jr_id']);
-
- echo nb($positive);
- echo ";";
- }
- else
- {
- echo nb($line['montant']).";";
- }
-
- printf("\r\n");
- }
- }
+ foreach ($Row as $line)
+ {
+
+ echo $line['num'].";";
+ echo $line['date'].";";
+ echo $line['comment'].";";
+ echo $line['jr_internal'].";";
+ // echo " ".$line['pj'].";";
+ // If the ledger is financial :
+ // the credit must be negative and written in red
+ // Get the jrn type
+ if ( $line['jrn_def_type'] == 'FIN' )
+ {
+ $positive = $cn->get_value("select qf_amount from quant_fin ".
+ " where jr_id=".$line['jr_id']);
+
+ echo nb($positive);
+ echo ";";
+ }
+ else
+ {
+ echo nb($line['montant']).";";
+ }
+
+ printf("\r\n");
+ }
+ }
//-----------------------------------------------------
- if ( $jrn_type=='ACH' || $jrn_type=='VEN')
- {
- $own=new Own($cn);
- $col_tva="";
+ if ( $jrn_type=='ACH' || $jrn_type=='VEN')
+ {
+ $own=new Own($cn);
+ $col_tva="";
- if ( $own->MY_TVA_USE=='Y') {
- $a_Tva=$cn->get_array("select tva_id,tva_label from tva_rate where tva_rate != 0.0000 order by tva_rate");
- foreach($a_Tva as $line_tva)
- {
- $col_tva.='"Tva '.$line_tva['tva_label'].'";';
- }
- }
- echo '"Date";"operation";"Client/Fourn.";"Commentaire";"inter.";"HTVA";'.$col_tva.'"TVAC"'."\n\r";
- foreach ($Row as $line)
- {
- printf('"%s";"%s";"%s";"%s";"%s";%s;',
- $line['date'],
- $line['num'],
- $line['client'],
- $line['comment'],
- $line['jr_internal'],
- nb($line['HTVA']));
- $a_tva_amount=array();
- foreach ($line['TVA'] as $lineTVA)
- {
- foreach ($a_Tva as $idx=>$line_tva)
- {
-
- if ($line_tva['tva_id'] == $lineTVA[1][0])
- {
- $a=$line_tva['tva_id'];
- $a_tva_amount[$a]=$lineTVA[1][2];
- }
- }
- }
- if ($own->MY_TVA_USE == 'Y' ) {
- foreach ($a_Tva as $line_tva)
- {
- $a=$line_tva['tva_id'];
- if ( isset($a_tva_amount[$a]))
- echo nb($a_tva_amount[$a]);
- else
- printf("0;");
- }
- }
- echo nb ($line['TVAC']);
- }
- }
- }
+ if ( $own->MY_TVA_USE=='Y')
+ {
+ $a_Tva=$cn->get_array("select tva_id,tva_label from tva_rate where tva_rate != 0.0000 order by tva_rate");
+ foreach($a_Tva as $line_tva)
+ {
+ $col_tva.='"Tva '.$line_tva['tva_label'].'";';
+ }
+ }
+ echo '"Date";"operation";"Client/Fourn.";"Commentaire";"inter.";"HTVA";'.$col_tva.'"TVAC"'."\n\r";
+ foreach ($Row as $line)
+ {
+ printf('"%s";"%s";"%s";"%s";"%s";%s;',
+ $line['date'],
+ $line['num'],
+ $line['client'],
+ $line['comment'],
+ $line['jr_internal'],
+ nb($line['HTVA']));
+ $a_tva_amount=array();
+ foreach ($line['TVA'] as $lineTVA)
+ {
+ foreach ($a_Tva as $idx=>$line_tva)
+ {
+
+ if ($line_tva['tva_id'] == $lineTVA[1][0])
+ {
+ $a=$line_tva['tva_id'];
+ $a_tva_amount[$a]=$lineTVA[1][2];
+ }
+ }
+ }
+ if ($own->MY_TVA_USE == 'Y' )
+ {
+ foreach ($a_Tva as $line_tva)
+ {
+ $a=$line_tva['tva_id'];
+ if ( isset($a_tva_amount[$a]))
+ echo nb($a_tva_amount[$a]);
+ else
+ printf("0;");
+ }
+ }
+ echo nb ($line['TVAC']);
+ }
+ }
+}
?>
diff --git a/html/jrn_pdf.php b/html/jrn_pdf.php
index 1fe200f28..fd8252815 100644
--- a/html/jrn_pdf.php
+++ b/html/jrn_pdf.php
@@ -1,30 +1,30 @@
check_dossier($gDossier);
$User->can_request(IMPJRN,0);
// Security
-if ( $_GET['jrn_id']!=0 && $User->check_jrn($_GET['jrn_id']) == 'X' ){
- /* Cannot Access */
- NoAccess();
+if ( $_GET['jrn_id']!=0 && $User->check_jrn($_GET['jrn_id']) == 'X' )
+{
+ /* Cannot Access */
+ NoAccess();
}
$ret="";
@@ -72,8 +73,8 @@ $jrn_type=$Jrn->get_type();
//----------------------------------------------------------------------
// Detailled Printing
//---------------------------------------------------------------------
-if ( $_REQUEST['p_simple']== 0 )
- {
+if ( $_REQUEST['p_simple']== 0 )
+{
$pdf=new Print_Ledger_Detail($cn);
$pdf->setDossierInfo($Jrn->name);
$pdf->AliasNbPages();
@@ -85,77 +86,81 @@ if ( $_REQUEST['p_simple']== 0 )
$pdf->Output('journal-'.$fDate.'.pdf','I');
exit(0);
- } // impression detaillé
+} // impression detaillé
//----------------------------------------------------------------------
// Simple Printing Purchase Ledger
//---------------------------------------------------------------------
-if ( $_REQUEST['p_simple']== 1 )
- {
+if ( $_REQUEST['p_simple']== 1 )
+{
if ( $jrn_type=='ACH' || $jrn_type=='VEN')
- {
- if ( $jrn_type=='ACH' && $cn->get_value('select count(qp_id) from quant_purchase') == 0 ) {
- $pdf= new Print_Ledger_Simple_without_vat($cn,$Jrn);
- $pdf->setDossierInfo($Jrn->name);
- $pdf->AliasNbPages();
- $pdf->AddPage();
- $pdf->Cell(0,6,'Ce journal ne peut être imprimé en mode simple');
- $pdf->output('erreur.pdf','I');
- exit();
- }
- if ( $jrn_type=='VEN' && $cn->get_value('select count(qs_id) from quant_sold') == 0 ) {
- $pdf= new Print_Ledger_Simple_without_vat($cn,$Jrn);
- $pdf->setDossierInfo($Jrn->name);
- $pdf->AliasNbPages();
- $pdf->AddPage();
- $pdf->Cell(0,6,'Ce journal ne peut être imprimé en mode simple');
- $pdf->output('erreur.pdf','I');
- exit();
- }
+ {
+ if ( $jrn_type=='ACH' && $cn->get_value('select count(qp_id) from quant_purchase') == 0 )
+ {
+ $pdf= new Print_Ledger_Simple_without_vat($cn,$Jrn);
+ $pdf->setDossierInfo($Jrn->name);
+ $pdf->AliasNbPages();
+ $pdf->AddPage();
+ $pdf->Cell(0,6,'Ce journal ne peut être imprimé en mode simple');
+ $pdf->output('erreur.pdf','I');
+ exit();
+ }
+ if ( $jrn_type=='VEN' && $cn->get_value('select count(qs_id) from quant_sold') == 0 )
+ {
+ $pdf= new Print_Ledger_Simple_without_vat($cn,$Jrn);
+ $pdf->setDossierInfo($Jrn->name);
+ $pdf->AliasNbPages();
+ $pdf->AddPage();
+ $pdf->Cell(0,6,'Ce journal ne peut être imprimé en mode simple');
+ $pdf->output('erreur.pdf','I');
+ exit();
+ }
- if ( $own->MY_TVA_USE=='Y')
- {
- $pdf= new Print_Ledger_Simple($cn,$Jrn);
- $pdf->setDossierInfo($Jrn->name);
- $pdf->AliasNbPages();
- $pdf->AddPage();
- $pdf->export();
- $fDate=date('dmy-Hi');
- $pdf->Output('journal-'.$fDate.'.pdf','I');
- exit(0);
- }
- if ( $own->MY_TVA_USE=='N')
- {
- $pdf= new Print_Ledger_Simple_without_vat($cn,$Jrn);
- $pdf->setDossierInfo($Jrn->name);
- $pdf->AliasNbPages();
- $pdf->AddPage();
- $pdf->export($Jrn);
- $fDate=date('dmy-Hi');
- $pdf->Output('journal-'.$fDate.'.pdf','I');
- exit(0);
- }
+ if ( $own->MY_TVA_USE=='Y')
+ {
+ $pdf= new Print_Ledger_Simple($cn,$Jrn);
+ $pdf->setDossierInfo($Jrn->name);
+ $pdf->AliasNbPages();
+ $pdf->AddPage();
+ $pdf->export();
+ $fDate=date('dmy-Hi');
+ $pdf->Output('journal-'.$fDate.'.pdf','I');
+ exit(0);
+ }
+ if ( $own->MY_TVA_USE=='N')
+ {
+ $pdf= new Print_Ledger_Simple_without_vat($cn,$Jrn);
+ $pdf->setDossierInfo($Jrn->name);
+ $pdf->AliasNbPages();
+ $pdf->AddPage();
+ $pdf->export($Jrn);
+ $fDate=date('dmy-Hi');
+ $pdf->Output('journal-'.$fDate.'.pdf','I');
+ exit(0);
+ }
- }
-
- if ($jrn_type=='FIN') {
- $pdf= new Print_Ledger_Financial($cn,$Jrn);
- $pdf->setDossierInfo($Jrn->name);
- $pdf->AliasNbPages();
- $pdf->AddPage();
- $pdf->export();
- $fDate=date('dmy-Hi');
- $pdf->Output('journal-'.$fDate.'.pdf','I');
- exit(0);
}
- if ( $jrn_type=='ODS' || $Jrn->id==0) {
- $pdf= new Print_Ledger_Misc($cn,$Jrn);
- $pdf->setDossierInfo($Jrn->name);
- $pdf->AliasNbPages();
- $pdf->AddPage();
- $pdf->export();
- $fDate=date('dmy-Hi');
- $pdf->Output('journal-'.$fDate.'.pdf','I');
- exit(0);
+
+ if ($jrn_type=='FIN')
+ {
+ $pdf= new Print_Ledger_Financial($cn,$Jrn);
+ $pdf->setDossierInfo($Jrn->name);
+ $pdf->AliasNbPages();
+ $pdf->AddPage();
+ $pdf->export();
+ $fDate=date('dmy-Hi');
+ $pdf->Output('journal-'.$fDate.'.pdf','I');
+ exit(0);
}
- }
+ if ( $jrn_type=='ODS' || $Jrn->id==0)
+ {
+ $pdf= new Print_Ledger_Misc($cn,$Jrn);
+ $pdf->setDossierInfo($Jrn->name);
+ $pdf->AliasNbPages();
+ $pdf->AddPage();
+ $pdf->export();
+ $fDate=date('dmy-Hi');
+ $pdf->Output('journal-'.$fDate.'.pdf','I');
+ exit(0);
+ }
+}
?>
diff --git a/html/jrn_search.php b/html/jrn_search.php
index 99552f5db..c1df05064 100644
--- a/html/jrn_search.php
+++ b/html/jrn_search.php
@@ -40,9 +40,10 @@ $gDossier=dossier::id();
// Javascript
echo JS_LEDGER;
-if ( isset( $p_jrn )) {
- $p_jrn=$p_jrn;
- $_SESSION[ "p_jrn"]=$p_jrn;
+if ( isset( $p_jrn ))
+{
+ $p_jrn=$p_jrn;
+ $_SESSION[ "p_jrn"]=$p_jrn;
}
if (isset ($_GET['p_ctl'])) $p_ctl=$_GET['p_ctl'];
@@ -62,64 +63,76 @@ $condition="";
$part=" where ";
$cn=new Database($gDossier);
// if search then build the condition
-if ( isset ($_GET["search"]) ) {
- $c1=0;
- foreach( $_GET as $key=>$element){
- ${"$key"}=$element;
- }
- $c_comment="";
- if ( isset ($p_comment) && strlen(trim($p_comment)) != 0 ) {
- $c_comment=" $part upper(jr_comment) like upper('%$p_comment%')";
- $part=" and ";
- }
- $c_montant="";
- if ( isset ($p_montant) && strlen($p_montant) != 0 && isNumber($p_montant) )
- {
- $p_montant=abs($p_montant);
- $opt_montant.=''.$p_montant_sel;
- $part=" and ";
- /* if the sign is equal then we look into the details */
- if ( $p_montant_sel != '=' ) {
- $c_montant=sprintf(" $part jr_montant %s abs(%s)",$p_montant_sel,$p_montant);
- } else {
- $c_montant=$part.' jr_grpt_id in (select j_grpt from jrnx where j_montant = '.$p_montant.')';
- }
- }
- if ( isset ($p_date) && strlen(trim($p_date)) != 0 ) {
- $c_date=sprintf(" $part j_date %s to_date('%s','DD.MM.YYYY')",$p_date_sel,$p_date);
- $part=" and ";
- $opt_date.=' '.$p_date_sel;
- }
- $c_internal="";
- if ( isset($p_internal) && strlen(trim($p_internal)) != 0 ) {
- $c_internal=$part." jr_internal like ('%".$p_internal."%')";
- $part=" and ";
+if ( isset ($_GET["search"]) )
+{
+ $c1=0;
+ foreach( $_GET as $key=>$element)
+ {
+ ${"$key"}=$element;
+ }
+ $c_comment="";
+ if ( isset ($p_comment) && strlen(trim($p_comment)) != 0 )
+ {
+ $c_comment=" $part upper(jr_comment) like upper('%$p_comment%')";
+ $part=" and ";
+ }
+ $c_montant="";
+ if ( isset ($p_montant) && strlen($p_montant) != 0 && isNumber($p_montant) )
+ {
+ $p_montant=abs($p_montant);
+ $opt_montant.=' '.$p_montant_sel;
+ $part=" and ";
+ /* if the sign is equal then we look into the details */
+ if ( $p_montant_sel != '=' )
+ {
+ $c_montant=sprintf(" $part jr_montant %s abs(%s)",$p_montant_sel,$p_montant);
+ }
+ else
+ {
+ $c_montant=$part.' jr_grpt_id in (select j_grpt from jrnx where j_montant = '.$p_montant.')';
+ }
+ }
+ if ( isset ($p_date) && strlen(trim($p_date)) != 0 )
+ {
+ $c_date=sprintf(" $part j_date %s to_date('%s','DD.MM.YYYY')",$p_date_sel,$p_date);
+ $part=" and ";
+ $opt_date.=' '.$p_date_sel;
+ }
+ $c_internal="";
+ if ( isset($p_internal) && strlen(trim($p_internal)) != 0 )
+ {
+ $c_internal=$part." jr_internal like ('%".$p_internal."%')";
+ $part=" and ";
- }
- $c_paid="";
- if (isset($paid)) {
- $c_paid=$part." (jr_rapt != 'paid' or jr_rapt is null) ";
- $part=" and ";
- }
- $condition=$c_comment.$c_montant.$c_date.$c_internal.$c_paid;
- }
+ }
+ $c_paid="";
+ if (isset($paid))
+ {
+ $c_paid=$part." (jr_rapt != 'paid' or jr_rapt is null) ";
+ $part=" and ";
+ }
+ $condition=$c_comment.$c_montant.$c_date.$c_internal.$c_paid;
+}
$condition=$condition." ".$part;
// If the usr is admin he has all right
-if ( $User->admin != 1 && $User->is_local_admin()!=1) {
- $condition.=" uj_priv in ('W','R') and uj_login='".$User->login."'" ;
-} else {
- $condition.=" true ";
-}
+if ( $User->admin != 1 && $User->is_local_admin()!=1)
+{
+ $condition.=" uj_priv in ('W','R') and uj_login='".$User->login."'" ;
+}
+else
+{
+ $condition.=" true ";
+}
?>
-';
+ ';
echo dossier::hidden();
if (isset($paid))
- echo '
Uniquement les non opérations non payées
';
- else
- echo '
Toutes les opérations
';
+ echo '
Uniquement les non opérations non payées
';
+else
+ echo '
Toutes les opérations
';
echo '
';
echo '';
@@ -152,120 +165,134 @@ echo ' ';
// if a search is asked otherwise don't show all the rows
-if ( isset ($_GET["search"]) ) {
+if ( isset ($_GET["search"]) )
+{
// If the usr is admin he has all right
- if ( $User->admin != 1 && $User->is_local_admin()!=1) {
- $jnt=" inner join user_sec_jrn on uj_jrn_id=j_jrn_def";
- } else {
- $jnt=" ";
- }
- $sql="select j_id,to_char(j_date,'DD.MM.YYYY') as j_date,
- j_montant,jr_montant,j_poste,j_debit,j_tech_per,jr_id,jr_comment,j_grpt,pcm_lib,jr_internal,jr_rapt,j_qcode from jrnx inner join
- jrn on jr_grpt_id=j_grpt inner join tmp_pcmn on j_poste=pcm_val ".
- $jnt.
- $condition." order by jr_date,jr_id,j_debit desc";
- $Res=$cn->exec_sql($sql);
+ if ( $User->admin != 1 && $User->is_local_admin()!=1)
+ {
+ $jnt=" inner join user_sec_jrn on uj_jrn_id=j_jrn_def";
+ }
+ else
+ {
+ $jnt=" ";
+ }
+ $sql="select j_id,to_char(j_date,'DD.MM.YYYY') as j_date,
+ j_montant,jr_montant,j_poste,j_debit,j_tech_per,jr_id,jr_comment,j_grpt,pcm_lib,jr_internal,jr_rapt,j_qcode from jrnx inner join
+ jrn on jr_grpt_id=j_grpt inner join tmp_pcmn on j_poste=pcm_val ".
+ $jnt.
+ $condition." order by jr_date,jr_id,j_debit desc";
+ $Res=$cn->exec_sql($sql);
- $MaxLine=Database::num_row($Res);
- $offset=(isset($_GET['offset']))?$_GET['offset']:0;
- $limit=$_SESSION['g_pagesize'];
- $sql_limit="";
- $sql_offset="";
- $bar="";
- if ( $limit != -1) {
- $page=(isset($_GET['page']))?$_GET['page']:0;
- $sql_limit=" LIMIT $limit ";
- $sql_offset=" OFFSET $offset ";
- $bar=jrn_navigation_bar($offset,$MaxLine,$limit,$page,'onClick="return go_next_concerned();"');
+ $MaxLine=Database::num_row($Res);
+ $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+ $limit=$_SESSION['g_pagesize'];
+ $sql_limit="";
+ $sql_offset="";
+ $bar="";
+ if ( $limit != -1)
+ {
+ $page=(isset($_GET['page']))?$_GET['page']:0;
+ $sql_limit=" LIMIT $limit ";
+ $sql_offset=" OFFSET $offset ";
+ $bar=jrn_navigation_bar($offset,$MaxLine,$limit,$page,'onClick="return go_next_concerned();"');
- }
- $sql.=$sql_limit.$sql_offset;
- if ( $MaxLine==0) {
- html_page_stop();
- return;
- }
- $Res=$cn->exec_sql($sql);
- $MaxLine=Database::num_row($Res);
+ }
+ $sql.=$sql_limit.$sql_offset;
+ if ( $MaxLine==0)
+ {
+ html_page_stop();
+ return;
+ }
+ $Res=$cn->exec_sql($sql);
+ $MaxLine=Database::num_row($Res);
- $col_vide=" ";
-echo '';
+ echo '';
}// if $_POST [search]
?>
diff --git a/html/js/acc_ledger.js b/html/js/acc_ledger.js
index c82220e76..662d5cd54 100644
--- a/html/js/acc_ledger.js
+++ b/html/js/acc_ledger.js
@@ -28,140 +28,160 @@ var layer=1;
/**
* @brief update the list of available predefined operation when we change the ledger.
*/
-function update_predef(p_type,p_direct) {
+function update_predef(p_type,p_direct)
+{
var jrn=g("p_jrn").value;
var dossier=g("gDossier").value;
var querystring='?&gDossier='+dossier+'&l='+jrn+'&t='+p_type+'&d='+p_direct;
g("p_jrn_predef").value=jrn;
- var action=new Ajax.Request(
- "get_predef.php",
- {
- method:'get',
- parameters:querystring,
- onFailure:error_get_predef,
- onSuccess:success_get_predef
- }
- );
+ var action=new Ajax.Request(
+ "get_predef.php",
+ {
+ method:'get',
+ parameters:querystring,
+ onFailure:error_get_predef,
+ onSuccess:success_get_predef
+ }
+ );
}
/**
* @brief update the field predef
*/
-function success_get_predef(request,json) {
+function success_get_predef(request,json)
+{
var i=0;
- var answer=request.responseText.evalJSON(true);
+ var answer=request.responseText.evalJSON(true);
obj=g("pre_def");
obj.innerHTML='';
if ( answer.count == 0 ) return;
- for ( i = 0 ; i < answer.count;i++) {
- value=answer['value'+i];
- label=answer['label'+i];
- obj.options[obj.options.length]=new Option(label,value);
+ for ( i = 0 ; i < answer.count;i++)
+ {
+ value=answer['value'+i];
+ label=answer['label'+i];
+ obj.options[obj.options.length]=new Option(label,value);
}
}
/**
* @brief update the field predef
*/
-function error_get_predef(request,json) {
+function error_get_predef(request,json)
+{
alert ("Erreur mise à jour champs non possible");
}
/**
* @brief update the list of available predefined operation when we change the ledger.
*/
-function update_pj() {
+function update_pj()
+{
var jrn=g("p_jrn").value;
var dossier=g("gDossier").value;
var querystring='?&gDossier='+dossier+'&l='+jrn;
- var action=new Ajax.Request(
- "get_pj.php",
- {
- method:'get',
- parameters:querystring,
- onFailure:error_get_pj,
- onSuccess:success_get_pj
- }
- );
+ var action=new Ajax.Request(
+ "get_pj.php",
+ {
+ method:'get',
+ parameters:querystring,
+ onFailure:error_get_pj,
+ onSuccess:success_get_pj
+ }
+ );
}
-/**
+/**
*ask the name, quick_code of the bank for the ledger
*/
-function update_bank() {
+function update_bank()
+{
var jrn=g('p_jrn').value;
var dossier=g('gDossier').value;
var qs='?&gDossier='+dossier+'&op=bkname&p_jrn='+jrn;
- var action=new Ajax.Request(
- "ajax_misc.php",
- {
- method:'get',
- parameters:qs,
- onFailure:error_get_pj,
- onSuccess:success_update_bank
- }
- );
-
+ var action=new Ajax.Request(
+ "ajax_misc.php",
+ {
+ method:'get',
+ parameters:qs,
+ onFailure:error_get_pj,
+ onSuccess:success_update_bank
+ }
+ );
+
}
/**
* Put into the span, the name of the bank, the bank account
* and the quick_code
*/
-function success_update_bank(req)
+function success_update_bank(req)
{
- try{
- var answer=req.responseXML;
- var a=answer.getElementsByTagName('code');
- var html=answer.getElementsByTagName('value');
- if ( a.length == 0 ) { var rec=req.responseText;alert ('erreur :'+rec);}
- var name_ctl=a[0].firstChild.nodeValue;
- var code_html=getNodeText(html[0]);
- code_html=unescape_xml(code_html);
- $(name_ctl).innerHTML=code_html;
+ try
+ {
+ var answer=req.responseXML;
+ var a=answer.getElementsByTagName('code');
+ var html=answer.getElementsByTagName('value');
+ if ( a.length == 0 )
+ {
+ var rec=req.responseText;
+ alert ('erreur :'+rec);
+ }
+ var name_ctl=a[0].firstChild.nodeValue;
+ var code_html=getNodeText(html[0]);
+ code_html=unescape_xml(code_html);
+ $(name_ctl).innerHTML=code_html;
}
- catch (e) {
- alert("success_update_bank".e.message);
+ catch (e)
+ {
+ alert("success_update_bank".e.message);
}
}
/**
* call ajax, ask what is the last date for the current ledger
*/
-function get_last_date() {
+function get_last_date()
+{
var jrn=g('p_jrn').value;
var dossier=g('gDossier').value;
var qs='?&gDossier='+dossier+'&op=lastdate&p_jrn='+jrn;
var action=new Ajax.Request(
- "ajax_misc.php",
- {
- method:'get',
- parameters:qs,
- onFailure:error_get_pj,
- onSuccess:success_get_last_date
- }
- );
+ "ajax_misc.php",
+ {
+ method:'get',
+ parameters:qs,
+ onFailure:error_get_pj,
+ onSuccess:success_get_last_date
+ }
+ );
}
/**
* callback ajax, set the ctl with the last date from the ledger
*/
-function success_get_last_date(req)
+function success_get_last_date(req)
{
- try{
- var answer=req.responseXML;
- var a=answer.getElementsByTagName('code');
- var html=answer.getElementsByTagName('value');
- if ( a.length == 0 ) { var rec=req.responseText;alert ('erreur :'+rec);}
- var name_ctl=a[0].firstChild.nodeValue;
- var code_html=getNodeText(html[0]);
- code_html=unescape_xml(code_html);
- $(name_ctl).value=code_html;
+ try
+ {
+ var answer=req.responseXML;
+ var a=answer.getElementsByTagName('code');
+ var html=answer.getElementsByTagName('value');
+ if ( a.length == 0 )
+ {
+ var rec=req.responseText;
+ alert ('erreur :'+rec);
+ }
+ var name_ctl=a[0].firstChild.nodeValue;
+ var code_html=getNodeText(html[0]);
+ code_html=unescape_xml(code_html);
+ $(name_ctl).value=code_html;
}
- catch (e) {
- alert(e.message);
+ catch (e)
+ {
+ alert(e.message);
}
}
/**
* @brief update the field predef
*/
-function success_get_pj(request,json) {
+function success_get_pj(request,json)
+{
var answer=request.responseText.evalJSON(true);
obj=g("e_pj");
@@ -173,14 +193,16 @@ function success_get_pj(request,json) {
/**
* @brief update the field predef
*/
-function error_get_pj(request,json) {
- alert("Ajax a echoue");
+function error_get_pj(request,json)
+{
+ alert("Ajax a echoue");
}
/**
* @brief add a line in the form for the ledger fin
*/
-function ledger_fin_add_row(){
+function ledger_fin_add_row()
+{
var style='class="input_text"';
var mytable=g("fin_item").tBodies[0];
var line=mytable.rows.length;
@@ -188,17 +210,18 @@ function ledger_fin_add_row(){
var nb=g("nb_item");
var rowToCopy=mytable.rows[1];
var nNumberCell=rowToCopy.cells.length;
- for ( var e=0;e < nNumberCell;e++) {
- var newCell=row.insertCell(e);
- var tt=rowToCopy.cells[e].innerHTML;
- var new_tt=tt.replace(/e_other0/g,"e_other"+nb.value);
- new_tt=new_tt.replace(/e_other0_comment/g,"e_other"+nb.value+'_comment');
- new_tt=new_tt.replace(/e_other0_amount/g,"e_other"+nb.value+'_amount');
- new_tt=new_tt.replace(/e_concerned0/g,"e_concerned"+nb.value);
- new_tt=new_tt.replace(/e_other0_label/g,"e_other"+nb.value+'_label');
- newCell.innerHTML=new_tt;
- new_tt.evalScripts();
- }
+ for ( var e=0;e < nNumberCell;e++)
+ {
+ var newCell=row.insertCell(e);
+ var tt=rowToCopy.cells[e].innerHTML;
+ var new_tt=tt.replace(/e_other0/g,"e_other"+nb.value);
+ new_tt=new_tt.replace(/e_other0_comment/g,"e_other"+nb.value+'_comment');
+ new_tt=new_tt.replace(/e_other0_amount/g,"e_other"+nb.value+'_amount');
+ new_tt=new_tt.replace(/e_concerned0/g,"e_concerned"+nb.value);
+ new_tt=new_tt.replace(/e_other0_label/g,"e_other"+nb.value+'_label');
+ newCell.innerHTML=new_tt;
+ new_tt.evalScripts();
+ }
g("e_other"+nb.value).value="";
g("e_other"+nb.value+'_amount').value="0";
g("e_other"+nb.value+'_comment').value="";
@@ -207,34 +230,36 @@ function ledger_fin_add_row(){
/**
* @brief add a line in the form for the purchase ledger
*/
-function ledger_add_row(){
- style='class="input_text"';
- var mytable=g("sold_item").tBodies[0];
- var ofirstRow=mytable.rows[1];
- var line=mytable.rows.length;
- var nCell=9;
- var row=mytable.insertRow(line);
- var nb=g("nb_item");
- for (var e=0;e';
+ var row=table.insertRow(line);
+ // left cell
+ var cellPos = row.insertCell(0);
+ cellPos.innerHTML=' ';
- // right cell
- var cellName = row.insertCell(1);
- cellName.innerHTML=' ';
+ // right cell
+ var cellName = row.insertCell(1);
+ cellName.innerHTML=' ';
- // button + formula
+ // button + formula
var cellbutton = row.insertCell(2);
var but_html=table.rows[1].cells[2].innerHTML;
but_html=but_html.replace(/form0/g,"form"+line);
@@ -55,27 +56,29 @@ function rapport_add_row(p_dossier){
* @brief create a file to export a report
* @param p_dossier the dossier id
*/
-function report_export(p_dossier,p_fr_id) {
- var queryString="?&gDossier="+p_dossier+"&f="+p_fr_id;
- var action=new Ajax.Request(
- "ajax_report.php",
- {
- method:'get',
- parameters:queryString,
- onSuccess:report_export_success
- }
- );
-
+function report_export(p_dossier,p_fr_id)
+{
+ var queryString="?&gDossier="+p_dossier+"&f="+p_fr_id;
+ var action=new Ajax.Request(
+ "ajax_report.php",
+ {
+ method:'get',
+ parameters:queryString,
+ onSuccess:report_export_success
+ }
+ );
+
}
/**
* @brief callback function for exporting a report
* @param request object request
* @param json json answer
*/
-function report_export_success(request,json) {
- var answer = request.responseText.evalJSON(true);
- var ok=answer.answer;
- var link=answer.link;
- $('export').hide();
- $('export_link').innerHTML=' Cliquez ici pour télécharger le rapport ';
+function report_export_success(request,json)
+{
+ var answer = request.responseText.evalJSON(true);
+ var ok=answer.answer;
+ var link=answer.link;
+ $('export').hide();
+ $('export_link').innerHTML=' Cliquez ici pour télécharger le rapport ';
}
\ No newline at end of file
diff --git a/html/js/accounting_item.js b/html/js/accounting_item.js
index 42747f22e..4fb2902fb 100644
--- a/html/js/accounting_item.js
+++ b/html/js/accounting_item.js
@@ -24,17 +24,20 @@
* containing the javascript for opening a windows to search an account (poste comptable)
*/
-function set_poste_parent(p_ctl,p_value) {
- var f=g(p_ctl);
- f.value+='['+p_value+']';
+function set_poste_parent(p_ctl,p_value)
+{
+ var f=g(p_ctl);
+ f.value+='['+p_value+']';
}
-function set_jrn_parent(p_ctl,p_value) {
- var f=g(p_ctl);
- if ( f ) {
- if ( trim(f.value)!="") f.value+=' ';
- f.value+=p_value;
- }
+function set_jrn_parent(p_ctl,p_value)
+{
+ var f=g(p_ctl);
+ if ( f )
+ {
+ if ( trim(f.value)!="") f.value+=' ';
+ f.value+=p_value;
+ }
}
@@ -60,43 +63,76 @@ function PcmnUpdate(p_value,p_lib,p_parent,p_type,p_dossier)
* - acc_query for the initial query
*\see ajax_poste.php
*/
-function search_poste(obj) {
+function search_poste(obj)
+{
showIPopup(obj.ipopup);
var dossier=$('gDossier').value;
var queryString="?gDossier="+dossier;
queryString+="&op=sf";
- try {
- if ( obj.jrn) { queryString+="&j="+obj.jrn;}
- if ( obj.account) { queryString+="&c="+obj.account;}
- if ( obj.label) { queryString+="&l="+obj.label;}
- if ( obj.bracket) { queryString+="&b="+obj.bracket;}
- if( obj.noquery) {queryString+="&nq";}
- if( obj.no_overwrite) {queryString+="&nover";}
- if( obj.bracket) {queryString+="&bracket";}
- if ( ! obj.noquery) {
- if( obj.acc_query) {queryString+="&q="+obj.acc_query;}
- else {
- if ($(obj).account) {
- var e=$(obj).account;
- var str_account=$(e).value;
- queryString+="&q="+str_account;
- }
- }
- }
+ try
+ {
+ if ( obj.jrn)
+ {
+ queryString+="&j="+obj.jrn;
+ }
+ if ( obj.account)
+ {
+ queryString+="&c="+obj.account;
+ }
+ if ( obj.label)
+ {
+ queryString+="&l="+obj.label;
+ }
+ if ( obj.bracket)
+ {
+ queryString+="&b="+obj.bracket;
+ }
+ if( obj.noquery)
+ {
+ queryString+="&nq";
+ }
+ if( obj.no_overwrite)
+ {
+ queryString+="&nover";
+ }
+ if( obj.bracket)
+ {
+ queryString+="&bracket";
+ }
+ if ( ! obj.noquery)
+ {
+ if( obj.acc_query)
+ {
+ queryString+="&q="+obj.acc_query;
+ }
+ else
+ {
+ if ($(obj).account)
+ {
+ var e=$(obj).account;
+ var str_account=$(e).value;
+ queryString+="&q="+str_account;
+ }
+ }
+ }
- queryString+="&ctl="+obj.ipopup;
- queryString=encodeURI(queryString);
- var action=new Ajax.Request ( 'ajax_poste.php',
- {
- method:'get',
- parameters:queryString,
- onFailure:errorPoste,
- onSuccess:result_poste_search
- }
- );
- } catch (e) { alert(e.getMessage());}
+ queryString+="&ctl="+obj.ipopup;
+ queryString=encodeURI(queryString);
+ var action=new Ajax.Request ( 'ajax_poste.php',
+ {
+ method:'get',
+ parameters:queryString,
+ onFailure:errorPoste,
+ onSuccess:result_poste_search
+ }
+ );
+ }
+ catch (e)
+ {
+ alert(e.getMessage());
+ }
}
/**
*@brief when you submit the form for searching a accounting item
@@ -104,60 +140,98 @@ function search_poste(obj) {
*@note the same as search_poste, except it answer to a FORM and not
* to a click event
*/
-function search_get_poste(obj) {
+function search_get_poste(obj)
+{
var dossier=$('gDossier').value;
var queryString="?gDossier="+dossier;
queryString+="&op=sf";
- if ( obj.elements['jrn'] ) { queryString+="&j="+$F('jrn');}
- if ( obj.elements['account']) { queryString+="&c="+$F('account');}
- if ( obj.elements['label']) { queryString+="&l="+$F('label');}
- if( obj.elements['acc_query']) {queryString+="&q="+$F('acc_query');}
- if (obj.ctl ) {queryString+="&ctl="+obj.ctl;}
- if( obj.elements['nosearch']) {queryString+="&nq";}
- if( obj.elements['nover']) {queryString+="&nover";}
- if( obj.elements['bracket']) {queryString+="&bracket";}
+ if ( obj.elements['jrn'] )
+ {
+ queryString+="&j="+$F('jrn');
+ }
+ if ( obj.elements['account'])
+ {
+ queryString+="&c="+$F('account');
+ }
+ if ( obj.elements['label'])
+ {
+ queryString+="&l="+$F('label');
+ }
+ if( obj.elements['acc_query'])
+ {
+ queryString+="&q="+$F('acc_query');
+ }
+ if (obj.ctl )
+ {
+ queryString+="&ctl="+obj.ctl;
+ }
+ if( obj.elements['nosearch'])
+ {
+ queryString+="&nq";
+ }
+ if( obj.elements['nover'])
+ {
+ queryString+="&nover";
+ }
+ if( obj.elements['bracket'])
+ {
+ queryString+="&bracket";
+ }
$('asearch').innerHTML=loading();
var action=new Ajax.Request ( 'ajax_poste.php',
- {
- method:'get',
- parameters:queryString,
- onFailure:errorPoste,
- onSuccess:result_poste_search
- }
- );
+ {
+ method:'get',
+ parameters:queryString,
+ onFailure:errorPoste,
+ onSuccess:result_poste_search
+ }
+ );
}
/**
*@brief show the answer of ajax request
*@param answer in XML
*/
-function result_poste_search(req) {
- try{
- var answer=req.responseXML;
- var a=answer.getElementsByTagName('ctl');
- if ( a.length == 0 ) { var rec=req.responseText;alert ('erreur :'+rec);}
- var html=answer.getElementsByTagName('code');
+function result_poste_search(req)
+{
+ try
+ {
+ var answer=req.responseXML;
+ var a=answer.getElementsByTagName('ctl');
+ if ( a.length == 0 )
+ {
+ var rec=req.responseText;
+ alert ('erreur :'+rec);
+ }
+ var html=answer.getElementsByTagName('code');
- var name_ctl=a[0].firstChild.nodeValue;
- var nodeXml=html[0];
- var code_html=getNodeText(nodeXml);
- code_html=unescape_xml(code_html);
- $(name_ctl).innerHTML=code_html;
- }
- catch (e) {
- alert(e.message);}
- try{
- code_html.evalScripts();}
- catch(e){
- alert("Impossible executer script de la reponse\n"+e.message);}
+ var name_ctl=a[0].firstChild.nodeValue;
+ var nodeXml=html[0];
+ var code_html=getNodeText(nodeXml);
+ code_html=unescape_xml(code_html);
+ $(name_ctl).innerHTML=code_html;
+ }
+ catch (e)
+ {
+ alert(e.message);
+ }
+ try
+ {
+ code_html.evalScripts();
+ }
+ catch(e)
+ {
+ alert("Impossible executer script de la reponse\n"+e.message);
+ }
}
/**
*@brief error for ajax
*/
-function errorPoste() {
- alert('Ajax failed');
+function errorPoste()
+{
+ alert('Ajax failed');
}
diff --git a/html/js/anc_script.js b/html/js/anc_script.js
index 4df07830b..d8d44ed35 100644
--- a/html/js/anc_script.js
+++ b/html/js/anc_script.js
@@ -26,72 +26,89 @@
* \param p_table_id
* \param p_amount amount to reach
*/
-function add_row(p_table,p_seq) {
- var mytable=g(p_table).tBodies[0];
+function add_row(p_table,p_seq)
+{
+ var mytable=g(p_table).tBodies[0];
- if ( ! mytable ) {return;}
+ if ( ! mytable )
+ {
+ return;
+ }
var new_value=mytable.rows.length+1;
- if ( mytable.rows.length > 5 ) {
- alert("Maximum 5 lignes ");
- return;
- }
- // For the detail view (modify_op) there is several form and then several time the
- // element
- var rowToCopy=mytable.rows[1];
- var row=mytable.insertRow(mytable.rows.length);
+ if ( mytable.rows.length > 5 )
+ {
+ alert("Maximum 5 lignes ");
+ return;
+ }
+ // For the detail view (modify_op) there is several form and then several time the
+ // element
+ var rowToCopy=mytable.rows[1];
+ var row=mytable.insertRow(mytable.rows.length);
- for ( var i=0;i< rowToCopy.cells.length;i++) {
- var cell=row.insertCell(i);
- var txt=rowToCopy.cells[i].innerHTML;
+ for ( var i=0;i< rowToCopy.cells.length;i++)
+ {
+ var cell=row.insertCell(i);
+ var txt=rowToCopy.cells[i].innerHTML;
// txt=txt.replace(/row_1/g,"row_"+new_value);
- cell.innerHTML=txt;
- }
+ cell.innerHTML=txt;
+ }
}
-/*!
+/*!
* \brief Check the amount of the CA
* \param p_style : error or ok, if ok show a ok box if the amount are equal
*
*
* \return true if the amounts are equal
*/
-function verify_ca(div) {
- var idx=0;var amount_error=0;
+function verify_ca(div)
+{
+ var idx=0;
+ var amount_error=0;
// put a maximum
- while (idx < 50 ) {
- var table=div+'t'+idx;
- if ( g(table) ) {
- var total_amount=0;
- // table is found compute the different val[]
- var array_value=document.getElementsByName('val['+idx+'][]');
-
- for (var i=0;i < array_value.length;i++ ) {
- if ( isNaN(array_value[i].value)) {
- array_value[i].value=0;
- }
+ while (idx < 50 )
+ {
+ var table=div+'t'+idx;
+ if ( g(table) )
+ {
+ var total_amount=0;
+ // table is found compute the different val[]
+ var array_value=document.getElementsByName('val['+idx+'][]');
- total_amount+=parseFloat(array_value[i].value);
- }
- var amount=parseFloat(g('amount_t'+idx).value);
- var diff=amount-total_amount;
+ for (var i=0;i < array_value.length;i++ )
+ {
+ if ( isNaN(array_value[i].value))
+ {
+ array_value[i].value=0;
+ }
- if ( Math.round(diff,2)!= 0.0) {
- g(table).style.backgroundColor='red';
- amount_error++;
- } else {
- g(table).style.backgroundColor='lightgreen';
+ total_amount+=parseFloat(array_value[i].value);
+ }
+ var amount=parseFloat(g('amount_t'+idx).value);
+ var diff=amount-total_amount;
- }
- idx++;
- } else break;
+ if ( Math.round(diff,2)!= 0.0)
+ {
+ g(table).style.backgroundColor='red';
+ amount_error++;
+ }
+ else
+ {
+ g(table).style.backgroundColor='lightgreen';
+
+ }
+ idx++;
+ }
+ else break;
}
- if ( amount_error != 0 ) {
- alert('Désolé, les montants pour la comptabilité analytique sont incorrects');
- return false;
+ if ( amount_error != 0 )
+ {
+ alert('Désolé, les montants pour la comptabilité analytique sont incorrects');
+ return false;
}
return true;
}
-/*!
+/*!
* \brief open a window for searching a CA account,
* \param p_dossier dossier id
* \param p_target ctrl to update
@@ -102,57 +119,72 @@ function verify_ca(div) {
*/
function search_ca (p_dossier,p_target,p_source)
{
- var pa_id=g(p_source).value;
- var url="?gDossier="+p_dossier+"&c1="+p_target+"&c2="+pa_id;
- var a=window.open("search_ca.php"+url,"CA recherche",'statusbar=no,scrollbars=yes,toolbar=no');
- a.focus();
+ var pa_id=g(p_source).value;
+ var url="?gDossier="+p_dossier+"&c1="+p_target+"&c2="+pa_id;
+ var a=window.open("search_ca.php"+url,"CA recherche",'statusbar=no,scrollbars=yes,toolbar=no');
+ a.focus();
}
-function caod_checkTotal() {
- var ie4=false;
- if ( document.all ) {
- ie4=true;
- }// Ajouter getElementById par document.all[str]
- var total_deb=0.0;
- var total_cred=0.0;
- var nb_item=g('nbrow').value;
+function caod_checkTotal()
+{
+ var ie4=false;
+ if ( document.all )
+ {
+ ie4=true;
+ }// Ajouter getElementById par document.all[str]
+ var total_deb=0.0;
+ var total_cred=0.0;
+ var nb_item=g('nbrow').value;
- for (var i=0;i '+p_variable;
- p_history+="="+result.toString();
- var str_sub=" Total :"+p_variable+" = "+result.toString()+" ";
+ p_variable=this.document.getElementById('inp').value;
+ if (p_variable.search(/^\s*$/) !=-1)
+ {
+ return;
+ }
+ try
+ {
+ Compute();
+ sub=eval(p_variable);
+ var result=parseFloat(sub);
+ result=Math.round(result*100)/100;
+ }
+ catch(exception)
+ {
+ alert("Mauvaise formule\n"+p_variable);
+ return false;
+ }
+ p_history=p_history+' '+p_variable;
+ p_history+="="+result.toString();
+ var str_sub=" Total :"+p_variable+" = "+result.toString()+" ";
this.document.getElementById("sub_total").innerHTML=str_sub;
this.document.getElementById("listing").innerHTML=p_history;
this.document.getElementById('inp').value="";
}
-// Clean
-//
-function Clean()
+// Clean
+//
+function Clean()
{
- this.document.getElementById('listing').innerHTML="";
- this.document.getElementById('result').innerHTML="";
- this.document.getElementById('sub_total').innerHTML="";
- this.document.getElementById('inp').value="";
- this.document.getElementById('inp').focus();
+ this.document.getElementById('listing').innerHTML="";
+ this.document.getElementById('result').innerHTML="";
+ this.document.getElementById('sub_total').innerHTML="";
+ this.document.getElementById('inp').value="";
+ this.document.getElementById('inp').focus();
}
@@ -66,7 +70,7 @@ function Compute()
{
var tot=0;
var ret="";
-
+
this.document.getElementById('inp').value="";
this.document.getElementById('inp').focus();
}
diff --git a/html/js/card.js b/html/js/card.js
index 0ec07ff6c..10ebb7e77 100644
--- a/html/js/card.js
+++ b/html/js/card.js
@@ -19,7 +19,7 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*! \file
+/*! \file
* \brief javascript for searching a card
*/
@@ -34,37 +34,42 @@
* - label field to update with the name
* - ctl the id to fill with the HTML answer (ending with _content)
*/
-function search_card(obj) {
- try{
- var gDossier=$('gDossier').value;
- var inp=obj.inp;
- var string_to_search=$(inp).value;
- var label=obj.label;
- var typecard=obj.typecard;
- var price=obj.price;
- var tvaid=obj.tvaid;
- var jrn=obj.jrn;
- if ( jrn==undefined) {
- if ( g('p_jrn')) jrn=$('p_jrn').value;
- else jrn=-1;
- }
- var query=encodeJSON({'gDossier':gDossier,
- 'inp':inp,'label':label,'price':price,'tvaid':tvaid,
- 'ctl':obj.popup,'op':'fs','jrn':jrn,
- 'typecard':typecard,'query':string_to_search
- });
- showIPopup(obj.popup);
+function search_card(obj)
+{
+ try
+ {
+ var gDossier=$('gDossier').value;
+ var inp=obj.inp;
+ var string_to_search=$(inp).value;
+ var label=obj.label;
+ var typecard=obj.typecard;
+ var price=obj.price;
+ var tvaid=obj.tvaid;
+ var jrn=obj.jrn;
+ if ( jrn==undefined)
+ {
+ if ( g('p_jrn')) jrn=$('p_jrn').value;
+ else jrn=-1;
+ }
+var query=encodeJSON({'gDossier':gDossier,
+ 'inp':inp,'label':label,'price':price,'tvaid':tvaid,
+ 'ctl':obj.popup,'op':'fs','jrn':jrn,
+ 'typecard':typecard,'query':string_to_search
+ });
+ showIPopup(obj.popup);
- var action=new Ajax.Request ( 'ajax_card.php',
- {
- method:'get',
- parameters:query,
- onFailure:errorFid,
- onSuccess:result_card_search
- }
- );
- }catch(e) {
- alert('search_card failed'+e.message);
+ var action=new Ajax.Request ( 'ajax_card.php',
+ {
+ method:'get',
+ parameters:query,
+ onFailure:errorFid,
+ onSuccess:result_card_search
+ }
+ );
+ }
+ catch(e)
+ {
+ alert('search_card failed'+e.message);
}
}
/**
@@ -73,53 +78,90 @@ function search_card(obj) {
*@note the same as search_card, except it answer to a FORM and not
* to a click event
*/
-function search_get_card(obj) {
+function search_get_card(obj)
+{
var dossier=$('gDossier').value;
var queryString="?gDossier="+dossier;
queryString+="&op=fs";
-
- if ( obj.elements['inp'] ) { queryString+="&inp="+$F('inp');}
- if ( obj.elements['typecard'] ) { queryString+="&typecard="+$F('typecard');}
- if ( obj.elements['jrn'] ) { queryString+="&jrn="+$F('jrn');}
- if ( obj.elements['label']) { queryString+="&label="+$F('label');}
- if ( obj.elements['price']) { queryString+="&price="+$F('price');}
- if ( obj.elements['tvaid']) { queryString+="&tvaid="+$F('tvaid');}
- if( obj.elements['query']) {queryString+="&query="+$F('query');}
- if (obj.ctl ) {queryString+="&ctl="+obj.ctl;}
+
+ if ( obj.elements['inp'] )
+ {
+ queryString+="&inp="+$F('inp');
+ }
+ if ( obj.elements['typecard'] )
+ {
+ queryString+="&typecard="+$F('typecard');
+ }
+ if ( obj.elements['jrn'] )
+ {
+ queryString+="&jrn="+$F('jrn');
+ }
+ if ( obj.elements['label'])
+ {
+ queryString+="&label="+$F('label');
+ }
+ if ( obj.elements['price'])
+ {
+ queryString+="&price="+$F('price');
+ }
+ if ( obj.elements['tvaid'])
+ {
+ queryString+="&tvaid="+$F('tvaid');
+ }
+ if( obj.elements['query'])
+ {
+ queryString+="&query="+$F('query');
+ }
+ if (obj.ctl )
+ {
+ queryString+="&ctl="+obj.ctl;
+ }
$('asearch').innerHTML=loading();
var action=new Ajax.Request ( 'ajax_card.php',
- {
- method:'get',
- parameters:queryString,
- onFailure:errorFid,
- onSuccess:result_card_search
- }
- );
+ {
+ method:'get',
+ parameters:queryString,
+ onFailure:errorFid,
+ onSuccess:result_card_search
+ }
+ );
}
/**
*@brief show the answer of ajax request
*@param answer in XML
*/
-function result_card_search(req) {
- try{
- var answer=req.responseXML;
- var a=answer.getElementsByTagName('ctl');
- if ( a.length == 0 ) { var rec=req.responseText;alert ('erreur :'+rec);}
- var html=answer.getElementsByTagName('code');
+function result_card_search(req)
+{
+ try
+ {
+ var answer=req.responseXML;
+ var a=answer.getElementsByTagName('ctl');
+ if ( a.length == 0 )
+ {
+ var rec=req.responseText;
+ alert ('erreur :'+rec);
+ }
+ var html=answer.getElementsByTagName('code');
- var name_ctl=a[0].firstChild.nodeValue;
- var nodeXml=html[0];
- var code_html=getNodeText(nodeXml);
- code_html=unescape_xml(code_html);
- $(name_ctl).innerHTML=code_html;
- }
- catch (e) {
- alert(e.message);}
- try{
- code_html.evalScripts();}
- catch(e){
- alert("Impossible executer script de la reponse\n"+e.message);}
+ var name_ctl=a[0].firstChild.nodeValue;
+ var nodeXml=html[0];
+ var code_html=getNodeText(nodeXml);
+ code_html=unescape_xml(code_html);
+ $(name_ctl).innerHTML=code_html;
+ }
+ catch (e)
+ {
+ alert(e.message);
+ }
+ try
+ {
+ code_html.evalScripts();
+ }
+ catch(e)
+ {
+ alert("Impossible executer script de la reponse\n"+e.message);
+ }
}
@@ -135,11 +177,18 @@ function result_card_search(req) {
*\param p_ctrlname the name of the input field with the label
*\param p_label the label of the quickcode
*/
-function setCtrl(p_ctrl,p_quickcode,p_ctrlname,p_label){
- var ctrl=g(p_ctrl);
- if ( ctrl ) { ctrl.value=p_quickcode; }
- var ctrl_name=g(p_ctrlname);
- if ( ctrl_name ) { ctrl_name.value=p_label; }
+function setCtrl(p_ctrl,p_quickcode,p_ctrlname,p_label)
+{
+ var ctrl=g(p_ctrl);
+ if ( ctrl )
+ {
+ ctrl.value=p_quickcode;
+ }
+ var ctrl_name=g(p_ctrlname);
+ if ( ctrl_name )
+ {
+ ctrl_name.value=p_label;
+ }
}
@@ -149,27 +198,38 @@ function setCtrl(p_ctrl,p_quickcode,p_ctrlname,p_label){
*/
function clean_Fid(p_ctl)
{
- nSell=p_ctl+"_price";
- nBuy=p_ctl+"_price";
- nTva_id=p_ctl+"_tva_id";
- if ( $(nSell) ) { $(nSell).value=""; }
- if ( $(nBuy) ) { $(nBuy).value="";}
- if ( $(nTva_id) ) { $(nTva_id).value="-1"; }
-
+ nSell=p_ctl+"_price";
+ nBuy=p_ctl+"_price";
+ nTva_id=p_ctl+"_tva_id";
+ if ( $(nSell) )
+ {
+ $(nSell).value="";
+ }
+ if ( $(nBuy) )
+ {
+ $(nBuy).value="";
+ }
+ if ( $(nTva_id) )
+ {
+ $(nTva_id).value="-1";
+ }
+
}
-function errorFid(request,json) {
- alert('erreur : ajax fiche');
+function errorFid(request,json)
+{
+ alert('erreur : ajax fiche');
}
-function update_value(text,li) {
-
+function update_value(text,li)
+{
}
/**
*@brief is called when something change in ICard
*@param the input field
*@see ICard
*/
-function fill_data_onchange(ctl) {
- ajaxFid(ctl);
+function fill_data_onchange(ctl)
+{
+ ajaxFid(ctl);
}
/**
@@ -177,8 +237,9 @@ function fill_data_onchange(ctl) {
*@param the input field
*@see ICard
*/
-function fill_data(text,li) {
- ajaxFid(text);
+function fill_data(text,li)
+{
+ ajaxFid(text);
}
/**
@@ -186,18 +247,20 @@ function fill_data(text,li) {
*@param the input field
*@see ICard
*/
-function fill_fin_data_onchange(ctl) {
- ajaxFid(ctl);
-ajax_saldo(ctl.id);
+function fill_fin_data_onchange(ctl)
+{
+ ajaxFid(ctl);
+ ajax_saldo(ctl.id);
}
/**
*@brief is called when something change in ICard
*@param the input field
*@see ICard
*/
-function fill_fin_data(text,li) {
- ajaxFid(text);
-ajax_saldo($(text.id));
+function fill_fin_data(text,li)
+{
+ ajaxFid(text);
+ ajax_saldo($(text.id));
}
/**
*@brief show the ipopup window and display the details of a card,
@@ -207,17 +270,25 @@ ajax_saldo($(text.id));
*
*@see ajax_card.php
*/
-function fill_ipopcard(obj) {
- if ( ! $(obj).ipopup) { alert('Erreur pas d\' attribut ipopup '+obj.id);return;};
+function fill_ipopcard(obj)
+{
+ if ( ! $(obj).ipopup)
+ {
+ alert('Erreur pas d\' attribut ipopup '+obj.id);
+ return;
+ };
var content=$(obj).ipopup+'_content';
$(content).innerHTML=loading();
showIPopup($(obj).ipopup);
var dossier=$('gDossier').value;
var qcode='';
- if ( $(obj).qcode != undefined ) {
- qcode=obj.qcode;
- } else {
- qcode=$(obj).value;
+ if ( $(obj).qcode != undefined )
+ {
+ qcode=obj.qcode;
+ }
+ else
+ {
+ qcode=$(obj).value;
}
// ctl=$(obj).id;
var queryString='?gDossier='+dossier;
@@ -226,13 +297,17 @@ function fill_ipopcard(obj) {
queryString+='&op=dc'; // dc for detail card
var action=new Ajax.Request ( 'ajax_card.php',
- {
- method:'get',
- parameters:queryString,
- onFailure:errorFid,
- onSuccess:successFill_ipopcard
- }
- );
+ {
+ method:'get'
+ ,
+ parameters:
+ queryString,
+ onFailure:
+ errorFid,
+ onSuccess:
+ successFill_ipopcard
+ }
+ );
}
/**
*@brief
@@ -241,19 +316,37 @@ function fill_ipopcard(obj) {
\code
\endcode
*/
-function successFill_ipopcard(req,json){
- try{
- var answer=req.responseXML;
- var a=answer.getElementsByTagName('ctl');
- var html=answer.getElementsByTagName('code');
+function successFill_ipopcard(req,json)
+{
+ try
+ {
+ var answer=req.responseXML;
+ var a=answer.getElementsByTagName('ctl');
+ var html=answer.getElementsByTagName('code');
- if ( a.length == 0 ) { var rec=req.responseText;alert ('erreur :'+rec);}
- var name_ctl=a[0].firstChild.nodeValue;
- var code_html=getNodeText(html[0]);
- code_html=unescape_xml(code_html);
+ if ( a.length == 0 )
+ {
+ var rec=req.responseText;
+ alert ('erreur :'+rec);
+ }
+ var name_ctl=a[0].firstChild.nodeValue;
+ var code_html=getNodeText(html[0]);
+ code_html=unescape_xml(code_html);
- $(name_ctl).innerHTML=code_html;} catch (e) {alert(e.message);}
- try{code_html.evalScripts();}catch(e){alert("Impossible executer script de la reponse\n"+e.message);}
+ $(name_ctl).innerHTML=code_html;
+ }
+ catch (e)
+ {
+ alert(e.message);
+ }
+ try
+ {
+ code_html.evalScripts();
+ }
+ catch(e)
+ {
+ alert("Impossible executer script de la reponse\n"+e.message);
+ }
}
/**
*@brief show the ipopup for selecting a card type, it is a needed step before adding
@@ -265,8 +358,13 @@ function successFill_ipopcard(req,json){
* - type type of card (supplier, customer...)
*@see ajax_card.php
*/
-function select_card_type(obj) {
- if ( ! $(obj).ipopup) { alert('Erreur pas d\' attribut ipopup '+obj.id);return;};
+function select_card_type(obj)
+{
+ if ( ! $(obj).ipopup)
+ {
+ alert('Erreur pas d\' attribut ipopup '+obj.id);
+ return;
+ };
var content=$(obj).ipopup+'_content';
$(content).innerHTML=loading();
showIPopup($(obj).ipopup);
@@ -274,30 +372,46 @@ function select_card_type(obj) {
// give a filter, -1 if not
var filter=$(obj).filter;
- if ( filter==undefined) {filter=-1;}
+ if ( filter==undefined)
+ {
+ filter=-1;
+ }
var queryString='?gDossier='+dossier;
queryString+='&ctl='+content;
queryString+='&op=st'; // st for selecting type
- if ( $(obj).win_refresh!=undefined) { queryString+='&ref';}
+ if ( $(obj).win_refresh!=undefined)
+ {
+ queryString+='&ref';
+ }
queryString+='&fil='+filter;
// filter on the ledger, -1 if not
var oledger=$(obj).jrn;
- if (oledger==undefined) {ledger=-1;} else {ledger=$(obj).jrn;}
+ if (oledger==undefined)
+ {
+ ledger=-1;
+ }
+ else
+ {
+ ledger=$(obj).jrn;
+ }
queryString+='&ledger='+ledger;
- if ( obj.type_cat) { queryString+='&cat='+obj.type_cat;}
+ if ( obj.type_cat)
+ {
+ queryString+='&cat='+obj.type_cat;
+ }
var action=new Ajax.Request ( 'ajax_card.php',
- {
- method:'get',
- parameters:queryString,
- onFailure:errorFid,
- onSuccess:successFill_ipopcard
- }
- );
+ {
+ method:'get',
+ parameters:queryString,
+ onFailure:errorFid,
+ onSuccess:successFill_ipopcard
+ }
+ );
}
/**
*@brief Show a blank card
@@ -307,13 +421,19 @@ function select_card_type(obj) {
* - ref : reload the window after adding card
*@see ajax_card.php
*/
-function dis_blank_card(obj) {
- if ( ! $(obj).ipopup) { alert('Erreur pas d\' attribut ipopup '+obj.id);return;};
+function dis_blank_card(obj)
+{
+ if ( ! $(obj).ipopup)
+ {
+ alert('Erreur pas d\' attribut ipopup '+obj.id);
+ return;
+ };
// first we have to take the form elt we need
var fd_id=$F('fd_id');
var ref="";
- if ( obj.elements['ref'] ) {
- ref='&ref';
+ if ( obj.elements['ref'] )
+ {
+ ref='&ref';
}
var content=$(obj).ipopup+'_content';
$(content).innerHTML=loading();
@@ -327,13 +447,13 @@ function dis_blank_card(obj) {
queryString+='&op=bc'; // bc for blank card
var action=new Ajax.Request ( 'ajax_card.php',
- {
- method:'get',
- parameters:queryString,
- onFailure:errorFid,
- onSuccess:successFill_ipopcard
- }
- );
+ {
+ method:'get',
+ parameters:queryString,
+ onFailure:errorFid,
+ onSuccess:successFill_ipopcard
+ }
+ );
}
/**
*@brief save the data contained into the form 'save_card'
@@ -341,8 +461,13 @@ function dis_blank_card(obj) {
* possible attribute :
*@see ajax_card.php
*/
-function save_card(obj) {
- if ( ! $(obj).ipopup) { alert('Erreur pas d\' attribut ipopup '+obj.id);return;};
+function save_card(obj)
+{
+ if ( ! $(obj).ipopup)
+ {
+ alert('Erreur pas d\' attribut ipopup '+obj.id);
+ return;
+ };
var content=$(obj).ipopup+'_content';
// Data must be taken here
data=$('save_card').serialize(false);
@@ -355,13 +480,13 @@ function save_card(obj) {
queryString+='&op=sc'; // sc for save card
var action=new Ajax.Request ( 'ajax_card.php',
- {
- method:'post',
- parameters:queryString,
- onFailure:errorFid,
- onSuccess:successFill_ipopcard
- }
- );
+ {
+ method:'post',
+ parameters:queryString,
+ onFailure:errorFid,
+ onSuccess:successFill_ipopcard
+ }
+ );
}
/**
*@brief add a category of card,
@@ -369,30 +494,39 @@ function save_card(obj) {
* - ipopup the ipopup to show
* - type_cat the category of card we want to add
*/
-function add_category(obj){
+function add_category(obj)
+{
// show ipopup
showIPopup(obj.ipopup);
var dossier=$('gDossier').value;
var queryString='?gDossier='+dossier;
queryString+='&op=ac';
queryString+='&ctl='+obj.ipopup+'_content';
- if ( obj.type_cat) { queryString+='&cat='+obj.type_cat;}
+ if ( obj.type_cat)
+ {
+ queryString+='&cat='+obj.type_cat;
+ }
var action=new Ajax.Request ( 'ajax_card.php',
- {
- method:'get',
- parameters:queryString,
- onFailure:errorFid,
- onSuccess:successFill_ipopcard
- }
- );
+ {
+ method:'get',
+ parameters:queryString,
+ onFailure:errorFid,
+ onSuccess:successFill_ipopcard
+ }
+ );
}
/**
* @brief save the form and add a new category of card
* @param obj if the form object
*/
-function save_card_category(obj) {
- if ( ! $(obj).ipopup) { alert('Erreur pas d\' attribut ipopup '+obj.id);return;};
+function save_card_category(obj)
+{
+ if ( ! $(obj).ipopup)
+ {
+ alert('Erreur pas d\' attribut ipopup '+obj.id);
+ return;
+ };
var content=$(obj).ipopup+'_content';
// Data must be taken here
data=$('newcat').serialize(false);
@@ -405,13 +539,13 @@ function save_card_category(obj) {
queryString+='&op=scc'; // sc for save card
var action=new Ajax.Request ( 'ajax_card.php',
- {
- method:'post',
- parameters:queryString,
- onFailure:errorFid,
- onSuccess:successFill_ipopcard
- }
- );
+ {
+ method:'post',
+ parameters:queryString,
+ onFailure:errorFid,
+ onSuccess:successFill_ipopcard
+ }
+ );
}
/**
*@brief Remove a definition of an attribut
@@ -421,19 +555,20 @@ function save_card_category(obj) {
*@param special this pointer of the row
*/
-function removeCardAttribut(ad_id,gDossier,table_id,row) {
+function removeCardAttribut(ad_id,gDossier,table_id,row)
+{
var queryString='?gDossier='+gDossier;
queryString+='&op=rmfa';
queryString+='&ctl=debug'; // debug id
queryString+='&ad_id='+ad_id;
var action=new Ajax.Request ( 'ajax_card.php',
- {
- method:'get',
- parameters:queryString,
- onFailure:null,
- onSuccess:null
- }
- );
+ {
+ method:'get',
+ parameters:queryString,
+ onFailure:null,
+ onSuccess:null
+ }
+ );
deleteRowRec(table_id,row);
diff --git a/html/js/compute.js b/html/js/compute.js
index 487026852..11a506ef3 100644
--- a/html/js/compute.js
+++ b/html/js/compute.js
@@ -18,63 +18,82 @@
/*!\file
*\brief common function for accountancy module
*/
-function checkTotal() {
- var ie4=false;
- if ( document.all ) {
- ie4=true;
- }// Ajouter getElementById par document.all[str]
- var total_deb=0.0;
- var total_cred=0.0;
+function checkTotal()
+{
+ var ie4=false;
+ if ( document.all )
+ {
+ ie4=true;
+ }// Ajouter getElementById par document.all[str]
+ var total_deb=0.0;
+ var total_cred=0.0;
- var nb_item_id=document.getElementById('nb_item');
- if ( ! nb_item_id )
- {return; }
- var nb_item=nb_item_id.value;
-
- for (var i=0;i <'") by their HTML representation
*@return a string without the offending char.
*/
-function unescape_xml(code_html) {
+function unescape_xml(code_html)
+{
code_html=code_html.replace(/\</,'<');
code_html=code_html.replace(/\>/,'>');
code_html=code_html.replace(/\"/,'"');
@@ -255,144 +355,210 @@ function unescape_xml(code_html) {
*@param xmlNode a node (result of var data = =answer.getElementsByTagName('code'))
*@return all the content of the XML node
*/
-function getNodeText(xmlNode)
- {
- if(!xmlNode) return '';
- if(typeof(xmlNode.textContent) != "undefined") { return xmlNode.textContent; }
- if ( xmlNode.firstChild && xmlNode.firstChild.nodeValue ) return xmlNode.firstChild.nodeValue;
- return "";
- }
+function getNodeText(xmlNode)
+{
+ if(!xmlNode) return '';
+ if(typeof(xmlNode.textContent) != "undefined")
+ {
+ return xmlNode.textContent;
+ }
+ if ( xmlNode.firstChild && xmlNode.firstChild.nodeValue ) return xmlNode.firstChild.nodeValue;
+ return "";
+}
/**
*@brief change the periode in the calendar of the dashboard
*@param object select
*/
-function change_month(obj) {
+function change_month(obj)
+{
var queryString="gDossier="+obj.gDossier+"&op=cal"+"&per="+obj.value;
var action = new Ajax.Request(
- "ajax_misc.php" , { method:'get', parameters:queryString,onFailure:ajax_misc_failure,onSuccess:change_month_success}
- );
-
+ "ajax_misc.php" , { method:'get', parameters:queryString,onFailure:ajax_misc_failure,onSuccess:change_month_success}
+ );
+
}
-function change_month_success(req) {
- try{
- var answer=req.responseXML;
- var html=answer.getElementsByTagName('code');
- if ( html.length == 0 ) { var rec=req.responseText;alert ('erreur :'+rec);}
- var nodeXml=html[0];
- var code_html=getNodeText(nodeXml);
- code_html=unescape_xml(code_html);
- $("user_cal").innerHTML=code_html;
- }
- catch (e) {
- alert(e.message);}
- try{
- code_html.evalScripts();}
- catch(e){
- alert("Impossible executer script de la reponse\n"+e.message);}
+function change_month_success(req)
+{
+ try
+ {
+ var answer=req.responseXML;
+ var html=answer.getElementsByTagName('code');
+ if ( html.length == 0 )
+ {
+ var rec=req.responseText;
+ alert ('erreur :'+rec);
+ }
+ var nodeXml=html[0];
+ var code_html=getNodeText(nodeXml);
+ code_html=unescape_xml(code_html);
+ $("user_cal").innerHTML=code_html;
+ }
+ catch (e)
+ {
+ alert(e.message);
+ }
+ try
+ {
+ code_html.evalScripts();
+ }
+ catch(e)
+ {
+ alert("Impossible executer script de la reponse\n"+e.message);
+ }
}
-function loading() { return 'un instant... ';}
+function loading()
+{
+ return 'un instant... ';
+}
-function ajax_misc_failure() {
+function ajax_misc_failure()
+{
alert('Ajax Misc failed');
}
/**
*@brief remove a document_modele
*/
-function cat_doc_remove(p_dt_id,p_dossier) {
+function cat_doc_remove(p_dt_id,p_dossier)
+{
var queryString="gDossier="+p_dossier+"&op=rem_cat_doc"+"&dt_id="+p_dt_id;
var action = new Ajax.Request(
- "ajax_misc.php" , { method:'get', parameters:queryString,onFailure:ajax_misc_failure,onSuccess:success_cat_doc_remove}
- );
+ "ajax_misc.php" , { method:'get', parameters:queryString,onFailure:ajax_misc_failure,onSuccess:success_cat_doc_remove}
+ );
}
-function success_cat_doc_remove(req) {
- try{
- var answer=req.responseXML;
- var html=answer.getElementsByTagName('dtid');
- if ( html.length == 0 ) { var rec=req.responseText;alert ('erreur :'+rec);}
- nodeXML=html[0];
- row_id=getNodeText(nodeXML);
- if ( row_id == 'nok') {alert('Error');return;}
- $('row'+row_id).style.textDecoration="line-through";
- $('X'+row_id).style.display='none';
- }
- catch (e) { alert(e.message);}
+function success_cat_doc_remove(req)
+{
+ try
+ {
+ var answer=req.responseXML;
+ var html=answer.getElementsByTagName('dtid');
+ if ( html.length == 0 )
+ {
+ var rec=req.responseText;
+ alert ('erreur :'+rec);
+ }
+ nodeXML=html[0];
+ row_id=getNodeText(nodeXML);
+ if ( row_id == 'nok')
+ {
+ alert('Error');
+ return;
+ }
+ $('row'+row_id).style.textDecoration="line-through";
+ $('X'+row_id).style.display='none';
+ }
+ catch (e)
+ {
+ alert(e.message);
+ }
}
/**
*@brief display the popup with vat and explanation
*@param obj with 4 attributes gdossier, ctl,popup
*/
-function popup_select_tva(obj) {
- try {
- showIPopup(obj.popup);
- var queryString="gDossier="+obj.gDossier+"&op=dsp_tva"+"&ctl="+obj.ctl+'&popup='+obj.popup;
- if ( obj.jcode )
- queryString+='&code='+obj.jcode;
- if (obj.compute)
- queryString+='&compute='+obj.compute;
- var action = new Ajax.Request(
- "ajax_misc.php" ,
- { method:'get',
- parameters:queryString,
- onFailure:ajax_misc_failure,
- onSuccess:success_popup_select_tva
- }
- );
- } catch (e) {alert("popup_select_tva "+e.message);}
+function popup_select_tva(obj)
+{
+ try
+ {
+ showIPopup(obj.popup);
+ var queryString="gDossier="+obj.gDossier+"&op=dsp_tva"+"&ctl="+obj.ctl+'&popup='+obj.popup;
+ if ( obj.jcode )
+ queryString+='&code='+obj.jcode;
+ if (obj.compute)
+ queryString+='&compute='+obj.compute;
+ var action = new Ajax.Request(
+ "ajax_misc.php" ,
+ { method:'get',
+ parameters:queryString,
+ onFailure:ajax_misc_failure,
+ onSuccess:success_popup_select_tva
+ }
+ );
+ }
+ catch (e)
+ {
+ alert("popup_select_tva "+e.message);
+ }
}
/**
*@brief display the popup with vat and explanations
*/
-function success_popup_select_tva(req) {
- try {
- var answer=req.responseXML;
- var popup=answer.getElementsByTagName('popup');
- if ( popup.length == 0 ) { var rec=req.responseText;alert ('erreur :'+rec);}
- var html=answer.getElementsByTagName('code');
+function success_popup_select_tva(req)
+{
+ try
+ {
+ var answer=req.responseXML;
+ var popup=answer.getElementsByTagName('popup');
+ if ( popup.length == 0 )
+ {
+ var rec=req.responseText;
+ alert ('erreur :'+rec);
+ }
+ var html=answer.getElementsByTagName('code');
- var name_ctl=popup[0].firstChild.nodeValue+'_content';
- var nodeXml=html[0];
- var code_html=getNodeText(nodeXml);
- code_html=unescape_xml(code_html);
- $(name_ctl).innerHTML=code_html;
- } catch (e) {alert("success_popup_select_tva "+e.message);}
+ var name_ctl=popup[0].firstChild.nodeValue+'_content';
+ var nodeXml=html[0];
+ var code_html=getNodeText(nodeXml);
+ code_html=unescape_xml(code_html);
+ $(name_ctl).innerHTML=code_html;
+ }
+ catch (e)
+ {
+ alert("success_popup_select_tva "+e.message);
+ }
}
/**
*@brief display the popup with vat and explanation
*@param obj with 4 attributes gdossier, ctl,popup
*/
-function set_tva_label(obj) {
- try {
- var queryString="gDossier="+obj.gDossier+"&op=label_tva"+"&id="+obj.value;
- if ( obj.jcode )
- queryString+='&code='+obj.jcode;
- var action = new Ajax.Request(
- "ajax_misc.php" ,
- { method:'get',
- parameters:queryString,
- onFailure:ajax_misc_failure,
- onSuccess:success_set_tva_label
- }
- );
- } catch (e) {alert("set_tva_label "+e.message);}
+function set_tva_label(obj)
+{
+ try
+ {
+ var queryString="gDossier="+obj.gDossier+"&op=label_tva"+"&id="+obj.value;
+ if ( obj.jcode )
+ queryString+='&code='+obj.jcode;
+ var action = new Ajax.Request(
+ "ajax_misc.php" ,
+ { method:'get',
+ parameters:queryString,
+ onFailure:ajax_misc_failure,
+ onSuccess:success_set_tva_label
+ }
+ );
+ }
+ catch (e)
+ {
+ alert("set_tva_label "+e.message);
+ }
}
/**
*@brief display the popup with vat and explanations
*/
-function success_set_tva_label(req) {
- try {
- var answer=req.responseXML;
- var code=answer.getElementsByTagName('code');
- var value=answer.getElementsByTagName('value');
+function success_set_tva_label(req)
+{
+ try
+ {
+ var answer=req.responseXML;
+ var code=answer.getElementsByTagName('code');
+ var value=answer.getElementsByTagName('value');
- if ( code.length == 0 ) { var rec=req.responseText;alert ('erreur :'+rec);}
+ if ( code.length == 0 )
+ {
+ var rec=req.responseText;
+ alert ('erreur :'+rec);
+ }
- var label_code=code[0].firstChild.nodeValue;
- var label_value=value[0].firstChild.nodeValue;
- set_value(label_code,label_value);
- } catch (e) {alert("success_set_tva_label "+e.message);}
+ var label_code=code[0].firstChild.nodeValue;
+ var label_value=value[0].firstChild.nodeValue;
+ set_value(label_code,label_value);
+ }
+ catch (e)
+ {
+ alert("success_set_tva_label "+e.message);
+ }
}
/**
@@ -400,7 +566,8 @@ function success_set_tva_label(req) {
*@param name of ipopup
*@see showIPopup
*/
-function set_wait(name) {
+function set_wait(name)
+{
var content=name+"_content";
$(content).innerHTML= 'Un instant...';
}
@@ -412,39 +579,63 @@ function set_wait(name) {
* - id to add an id
* - class to add a class
*/
-function add_div(obj) {
- try {
- var top=document;
- var elt=top.createElement('div');
- if (obj.id ) { elt.setAttribute('id',obj.id);}
- if (obj.style) {
- if (elt.style.setAttribute) { /* IE7 bug */
- elt.style.setAttribute('cssText',obj.style);
- } else { /* good Browser */
- elt.setAttribute('style',obj.style);
- }
- }
- if (obj.cssclass ) {
- elt.setAttribute('class',obj.cssclass);/* FF */
- elt.setAttribute('className',obj.cssclass); /* IE */
- }
- if (obj.html) { elt.innerHTML=obj.html;}
+function add_div(obj)
+{
+ try
+ {
+ var top=document;
+ var elt=top.createElement('div');
+ if (obj.id )
+ {
+ elt.setAttribute('id',obj.id);
+ }
+ if (obj.style)
+ {
+ if (elt.style.setAttribute)
+ { /* IE7 bug */
+ elt.style.setAttribute('cssText',obj.style);
+ }
+ else
+ { /* good Browser */
+ elt.setAttribute('style',obj.style);
+ }
+ }
+ if (obj.cssclass )
+ {
+ elt.setAttribute('class',obj.cssclass);/* FF */
+ elt.setAttribute('className',obj.cssclass); /* IE */
+ }
+ if (obj.html)
+ {
+ elt.innerHTML=obj.html;
+ }
- var bottom_div=document.body;
- bottom_div.appendChild(elt);
- if ( obj.drag ) {
- new Draggable(obj.id,{starteffect:function(){
- new Effect.Highlight(obj.id,{scroll:window,queue:'end'}); } }
- );
- }
- } catch (e) { alert("add_div"+e.message);}
+ var bottom_div=document.body;
+ bottom_div.appendChild(elt);
+ if ( obj.drag )
+ {
+new Draggable(obj.id,{starteffect:function()
+ {
+ new Effect.Highlight(obj.id,{scroll:window,queue:'end'});
+ } }
+ );
+ }
+ }
+ catch (e)
+ {
+ alert("add_div"+e.message);
+ }
}
/**
* remove a object created with add_div
* @param elt id of the elt
*/
-function removeDiv(elt) {
- if (g(elt) ){ document.body.removeChild(g(elt)); }
+function removeDiv(elt)
+{
+ if (g(elt) )
+ {
+ document.body.removeChild(g(elt));
+ }
}
/**
*@brief call add_div to add a DIV and after call the ajax
@@ -458,26 +649,36 @@ function removeDiv(elt) {
* - obj.fixed optional let you determine the position, otherwise works like IPopup
*@see add_div IBox
*/
-function show_box(obj) {
+function show_box(obj)
+{
add_div(obj) ;
- if ( ! obj.fixed ) {
- var sx=0;
- if ( window.scrollY) { sx=window.scrollY+40;}
- else { sx=document.body.scrollTop+40;}
- g(obj.id).style.top=sx;
- show(obj.id);
- } else {
- show(obj.id);
+ if ( ! obj.fixed )
+ {
+ var sx=0;
+ if ( window.scrollY)
+ {
+ sx=window.scrollY+40;
+ }
+ else
+ {
+ sx=document.body.scrollTop+40;
+ }
+ g(obj.id).style.top=sx;
+ show(obj.id);
+ }
+ else
+ {
+ show(obj.id);
}
var action=new Ajax.Request (
- obj.callback,
- {
- method:'GET',
- parameters:obj.qs,
- onFailure:eval(obj.js_error),
- onSuccess:eval(obj.js_success)
- });
+ obj.callback,
+ {
+ method:'GET',
+ parameters:obj.qs,
+ onFailure:eval(obj.js_error),
+ onSuccess:eval(obj.js_success)
+ });
}
/**
*@brief receive answer from ajax and just display it into the IBox
@@ -486,62 +687,79 @@ function show_box(obj) {
*/
function success_box(req,json)
{
- try{
- var answer=req.responseXML;
- var a=answer.getElementsByTagName('ctl');
- var html=answer.getElementsByTagName('code');
- if ( a.length == 0 ) { var rec=req.responseText;alert ('erreur :'+rec);}
- var name_ctl=a[0].firstChild.nodeValue;
- var code_html=getNodeText(html[0]);
-
- code_html=unescape_xml(code_html);
- g(name_ctl).innerHTML=code_html;
- g(name_ctl).style.height='auto';
- // if IE set to 60 %
- if(name_ctl != 'popup')
- g(name_ctl).style.width='45%';
- else
- g(name_ctl).style.width='auto';
- }
- catch (e) {
- alert("success_box"+e.message);}
- try{
- code_html.evalScripts();}
- catch(e){
- alert("answer_box Impossible executer script de la reponse\n"+e.message);}
+ try
+ {
+ var answer=req.responseXML;
+ var a=answer.getElementsByTagName('ctl');
+ var html=answer.getElementsByTagName('code');
+ if ( a.length == 0 )
+ {
+ var rec=req.responseText;
+ alert ('erreur :'+rec);
+ }
+ var name_ctl=a[0].firstChild.nodeValue;
+ var code_html=getNodeText(html[0]);
+
+ code_html=unescape_xml(code_html);
+ g(name_ctl).innerHTML=code_html;
+ g(name_ctl).style.height='auto';
+ // if IE set to 60 %
+ if(name_ctl != 'popup')
+ g(name_ctl).style.width='45%';
+ else
+ g(name_ctl).style.width='auto';
+ }
+ catch (e)
+ {
+ alert("success_box"+e.message);
+ }
+ try
+ {
+ code_html.evalScripts();
+ }
+ catch(e)
+ {
+ alert("answer_box Impossible executer script de la reponse\n"+e.message);
+ }
}
-function error_box () {
+function error_box ()
+{
alert('IBOX : error_box ajax not implemented');
}
/**
* show the ledger choice
*/
-function show_ledger_choice() {
+function show_ledger_choice()
+{
g('div_jrn').style.visibility='visible';
}
/**
* hide the ledger choice
*/
-function hide_ledger_choice() {
+function hide_ledger_choice()
+{
g('div_jrn').style.visibility='hidden';
}
/**
* show the cat of ledger choice
*/
-function show_cat_choice() {
+function show_cat_choice()
+{
g('div_cat').style.visibility='visible';
}
/**
* hide the cat of ledger choice
*/
-function hide_cat_choice() {
+function hide_cat_choice()
+{
g('div_cat').style.visibility='hidden';
}
/**
* add a row for the forecast item
*/
-function for_add_row(tableid) {
+function for_add_row(tableid)
+{
style='class="input_text"';
var mytable=g(tableid).tBodies[0];
var nNumberRow=mytable.rows.length;
@@ -550,75 +768,102 @@ function for_add_row(tableid) {
var nNumberCell=rowToCopy.cells.length;
var nb=g("nbrow");
var oNewRow = mytable.insertRow(nNumberRow);
- for ( var e=0;e < nNumberCell;e++) {
- var newCell=oRow.insertCell(e);
- var tt=rowToCopy.cells[e].innerHTML;
- new_tt=tt.replace(/an_cat0/g,"an_cat"+nb.value);
- new_tt=new_tt.replace(/an_cat_acc0/g,"an_cat_acc"+nb.value);
- new_tt=new_tt.replace(/an_qc0/g,"an_qc"+nb.value);
- new_tt=new_tt.replace(/an_label0/g,"an_label"+nb.value);
- new_tt=new_tt.replace(/month0/g,"month"+nb.value);
- new_tt=new_tt.replace(/an_cat_amount0/g,"an_cat_amount"+nb.value);
- new_tt=new_tt.replace(/an_deb0/g,"an_deb"+nb.value);
- newCell.innerHTML=new_tt;
- new_tt.evalScripts();
- }
- $("an_cat_acc"+nb.value).value="";
- $("an_qc"+nb.value).value="";
- $("an_label"+nb.value).value="";
- $("an_cat_amount"+nb.value).value="0";
- nb.value++;
+ for ( var e=0;e < nNumberCell;e++)
+ {
+ var newCell=oRow.insertCell(e);
+ var tt=rowToCopy.cells[e].innerHTML;
+ new_tt=tt.replace(/an_cat0/g,"an_cat"+nb.value);
+ new_tt=new_tt.replace(/an_cat_acc0/g,"an_cat_acc"+nb.value);
+ new_tt=new_tt.replace(/an_qc0/g,"an_qc"+nb.value);
+ new_tt=new_tt.replace(/an_label0/g,"an_label"+nb.value);
+ new_tt=new_tt.replace(/month0/g,"month"+nb.value);
+ new_tt=new_tt.replace(/an_cat_amount0/g,"an_cat_amount"+nb.value);
+ new_tt=new_tt.replace(/an_deb0/g,"an_deb"+nb.value);
+ newCell.innerHTML=new_tt;
+ new_tt.evalScripts();
+ }
+ $("an_cat_acc"+nb.value).value="";
+ $("an_qc"+nb.value).value="";
+ $("an_label"+nb.value).value="";
+ $("an_cat_amount"+nb.value).value="0";
+ nb.value++;
}
/**
* toggle all the checkbox in a given form
* @param form_id id of the form
*/
-function toggle_checkbox(form_id) {
+function toggle_checkbox(form_id)
+{
var form=g(form_id);
- for (var i=0;iCette calculatrice vous permet de calculer, écrivez simplement les opérations que vous voulez puis la touche retour. exemple : 1+2+3*(1/5) ';
-shtml+=' Taper une formule (ex 20*5.1) puis enter ';
+ shtml+=' Taper une formule (ex 20*5.1) puis enter ';
- var obj={id:sid,html:shtml,drag:true,style:'position:absolute;display:block;top:30px;left:150px;width:250px;border:1px solid black;background-color:#99b1df;font-size:12;padding: 2 2 2 2;'};
+var obj={id:
+ sid,html:
+ shtml,drag:
+ true,style:'position:absolute;display:block;top:30px;left:150px;width:250px;border:1px solid black;background-color:#99b1df;font-size:12;padding: 2 2 2 2;'
+ };
add_div(obj);
- this.document.getElementById('inp').focus();
-}
\ No newline at end of file
+ this.document.getElementById('inp').focus();
+}
diff --git a/html/js/todo_list.js b/html/js/todo_list.js
index a586022b5..1317cb210 100644
--- a/html/js/todo_list.js
+++ b/html/js/todo_list.js
@@ -25,47 +25,68 @@
* the gDossier
*
*/
-function todo_list_show(p_id) {
+function todo_list_show(p_id)
+{
var gDossier=$('gDossier').value;
- $('add_todo_list').style.top=posY+offsetY;
+ $('add_todo_list').style.top=posY+offsetY;
$('add_todo_list').style.left=posX+offsetX-200;
- try {
- var action=new Ajax.Request(
- 'todo_list.php',
- {
- method:'get',
- parameters:{'show':1,'id':p_id,'gDossier':gDossier},
- onFailure:todo_list_show_error,
- onSuccess:todo_list_show_success
- }
- );
- } catch (e) {
- alert(" Envoi ajax non possible" + e.message);
+ try
+ {
+ var action=new Ajax.Request(
+ 'todo_list.php',
+ {
+ method:'get',
+ parameters:
+ {'show':
+ 1,'id':
+ p_id,'gDossier':
+ gDossier
+ },
+ onFailure:todo_list_show_error,
+ onSuccess:todo_list_show_success
+ }
+ );
+ }
+ catch (e)
+ {
+ alert(" Envoi ajax non possible" + e.message);
}
return false;
}
-function todo_list_show_success(req) {
- try {
- var answer=req.responseXML;
- var tl_id=answer.getElementsByTagName('tl_id');
- var tl_title=answer.getElementsByTagName('tl_title');
- var tl_desc=answer.getElementsByTagName('tl_desc');
- var tl_date=answer.getElementsByTagName('tl_date');
-
- if ( tl_id.length == 0 ) { var rec=req.responseText;alert ('erreur :'+rec);}
+function todo_list_show_success(req)
+{
+ try
+ {
+ var answer=req.responseXML;
+ var tl_id=answer.getElementsByTagName('tl_id');
+ var tl_title=answer.getElementsByTagName('tl_title');
+ var tl_desc=answer.getElementsByTagName('tl_desc');
+ var tl_date=answer.getElementsByTagName('tl_date');
- $('p_title').value=getNodeText(tl_title[0]);
- $('p_date_todo').value=getNodeText(tl_date[0]);
- $('p_desc').value=getNodeText(tl_desc[0]);
- $('tl_id').value=getNodeText(tl_id[0]);
- $('add_todo_list').style.display='block';
- } catch (e) { alert(e.message);}
+ if ( tl_id.length == 0 )
+ {
+ var rec=req.responseText;
+ alert ('erreur :'+rec);
+ }
+
+ $('p_title').value=getNodeText(tl_title[0]);
+ $('p_date_todo').value=getNodeText(tl_date[0]);
+ $('p_desc').value=getNodeText(tl_desc[0]);
+ $('tl_id').value=getNodeText(tl_id[0]);
+ $('add_todo_list').style.display='block';
+ }
+ catch (e)
+ {
+ alert(e.message);
+ }
}
-function todo_list_show_error(request_json) {
+function todo_list_show_error(request_json)
+{
alert ('failure');
}
-function add_todo() {
+function add_todo()
+{
$('add_todo_list').style.top=posY+offsetY;
$('add_todo_list').style.left=posX+offsetX;
@@ -76,18 +97,27 @@ function add_todo() {
$('p_desc').value='';
$('tl_id').value=0;
}
-function todo_list_remove(p_ctl) {
- if ( confirm('Effacer ?') == false ) {return;}
+function todo_list_remove(p_ctl)
+{
+ if ( confirm('Effacer ?') == false )
+ {
+ return;
+ }
$("tr"+p_ctl).hide();
var gDossier=$('gDossier').value;
var action=new Ajax.Request(
- 'todo_list.php',
- {
- method:'get',
- parameters:{'del':1,'id':p_ctl,'gDossier':gDossier}
- }
- );
+ 'todo_list.php',
+ {
+ method:'get',
+ parameters:
+ {'del':
+ 1,'id':
+ p_ctl,'gDossier':
+ gDossier
+ }
+ }
+ );
return false;
}
diff --git a/html/listing_client.php b/html/listing_client.php
index e5aa63cec..6e950e9d5 100644
--- a/html/listing_client.php
+++ b/html/listing_client.php
@@ -46,14 +46,15 @@ header('Content-Disposition: attachment;filename="declaration.bin"',FALSE);
// Submit for a magnetic declaration
// Belgium only
//-----------------------------------------------------
-if ( isset($_POST['bt_disk'])) {
- require_once("class_customer.php");
- $customer=new Customer($cn);
- $a_Res=$customer->VatListing($_POST['year']);
+if ( isset($_POST['bt_disk']))
+{
+ require_once("class_customer.php");
+ $customer=new Customer($cn);
+ $a_Res=$customer->VatListing($_POST['year']);
- require_once("decla.BE.inc.php");
- $a=MakeListingVat($cn,$a_Res,$_POST['year']);
- echo "$a";
- return;
- }
+ require_once("decla.BE.inc.php");
+ $a=MakeListingVat($cn,$a_Res,$_POST['year']);
+ echo "$a";
+ return;
+}
?>
diff --git a/html/login.php b/html/login.php
index dcb25525f..2e9c1de29 100644
--- a/html/login.php
+++ b/html/login.php
@@ -26,29 +26,31 @@ include_once ("ac_common.php");
require_once('class_database.php');
-if ( isset ($_POST["p_user"] ) ) {
- $g_user=FormatString($_POST["p_user"]);
- $g_pass=$_POST["p_pass"];
- $_SESSION['g_user']=$g_user;
- $_SESSION['g_pass']=$g_pass;
-
- // Verif if User and Pass match DB
- // if no, then redirect to the login page
- $rep=new Database();
- include_once ("class_user.php");
- $User=new User($rep);
- $User->Check();
-
- echo " ";
-
-} else
+if ( isset ($_POST["p_user"] ) )
{
- $rep=new Database();
- include_once ("class_user.php");
- $User=new User($rep);
- $User->Check();
-
- echo " ";
+ $g_user=FormatString($_POST["p_user"]);
+ $g_pass=$_POST["p_pass"];
+ $_SESSION['g_user']=$g_user;
+ $_SESSION['g_pass']=$g_pass;
+
+ // Verif if User and Pass match DB
+ // if no, then redirect to the login page
+ $rep=new Database();
+ include_once ("class_user.php");
+ $User=new User($rep);
+ $User->Check();
+
+ echo " ";
+
+}
+else
+{
+ $rep=new Database();
+ include_once ("class_user.php");
+ $User=new User($rep);
+ $User->Check();
+
+ echo " ";
// }
}
html_page_stop();
diff --git a/html/parametre.php b/html/parametre.php
index f2e700c0a..d2eeed6e4 100644
--- a/html/parametre.php
+++ b/html/parametre.php
@@ -53,57 +53,61 @@ echo '';
@@ -111,267 +115,282 @@ echo '';
// sub action
$action="";
-if ( isset ($_POST['action']) ) {
- $action=$_POST['action'];
+if ( isset ($_POST['action']) )
+{
+ $action=$_POST['action'];
}
//-----------------------------------------------------
-// divers
+// divers
//-----------------------------------------------------
-if ( $p_action == 'divers') {
- $s=dossier::get();
+if ( $p_action == 'divers')
+{
+ $s=dossier::get();
- $array = array (
- array('parametre.php?p_action=divers&sa=mp&'.$s,_('Moyen de paiement'),_('Moyen de paiement'),2),
- array('parametre.php?p_action=divers&sa=tva&'.$s,_('Tva'),_('Taux et poste comptable tva'),4),
- array('parametre.php?p_action=divers&sa=poste&'.$s,_('Poste Comptable'),_('Poste comptable constant'),7),
- array('parametre.php?p_action=divers&sa=fiche&'.$s,_('Catégorie de fiche'),_('Modifie les classe de base, les attribut,...'),5),
- array('parametre.php?p_action=divers&sa=cdoc&'.$s,_('Catégorie de documents'),_('Ajoute des catégories de documents,...'),6),
- array('parametre.php?p_action=divers&sa=fat&'.$s,_('Attribut de fiche'),_('Modifie les attributs des catégories de fiches'),10)
- );
- $sa=(isset($_REQUEST['sa']))?$_REQUEST['sa']:'';
- $sb=(isset($_REQUEST['sb']))?$_REQUEST['sb']:'';
- $def=0;
- switch ($sa) {
+ $array = array (
+ array('parametre.php?p_action=divers&sa=mp&'.$s,_('Moyen de paiement'),_('Moyen de paiement'),2),
+ array('parametre.php?p_action=divers&sa=tva&'.$s,_('Tva'),_('Taux et poste comptable tva'),4),
+ array('parametre.php?p_action=divers&sa=poste&'.$s,_('Poste Comptable'),_('Poste comptable constant'),7),
+ array('parametre.php?p_action=divers&sa=fiche&'.$s,_('Catégorie de fiche'),_('Modifie les classe de base, les attribut,...'),5),
+ array('parametre.php?p_action=divers&sa=cdoc&'.$s,_('Catégorie de documents'),_('Ajoute des catégories de documents,...'),6),
+ array('parametre.php?p_action=divers&sa=fat&'.$s,_('Attribut de fiche'),_('Modifie les attributs des catégories de fiches'),10)
+ );
+ $sa=(isset($_REQUEST['sa']))?$_REQUEST['sa']:'';
+ $sb=(isset($_REQUEST['sb']))?$_REQUEST['sb']:'';
+ $def=0;
+ switch ($sa)
+ {
case 'mp':
- $def=2;
- break;
+ $def=2;
+ break;
case 'tva':
- $def=4;
- break;
- case 'poste':
- $def=7;
- break;
- case 'fiche':
- $def=5;
- break;
- case 'cdoc':
- $def=6;
- break;
- case 'fat':
- $def=10;
- break;
- }
- echo '';
-
- if ( $sa=='mp') {
- $User->can_request(PARMP,1);
- require_once('payment_middle.inc.php');
- exit;
- }
- //---------------------------------------------------------------------------
- // Add or remove attribut of card
- //---------------------------------------------------------------------------
- if ( $sa=='fat') {
- $User->can_request('FICCAT');
- require_once('card_attr.inc.php');
- exit();
- }
- //-----------------------------------------------------
- // TVA RATE
- //-----------------------------------------------------
- if ( $sa == "tva" )
- {
- echo '';
- $User->can_request(PARTVA,1);
- require_once("tva.inc.php");
- //
+ $def=4;
+ break;
+ case 'poste':
+ $def=7;
+ break;
+ case 'fiche':
+ $def=5;
+ break;
+ case 'cdoc':
+ $def=6;
+ break;
+ case 'fat':
+ $def=10;
+ break;
}
- //-----------------------------------------------------
- // Accounting item
- //-----------------------------------------------------
- if ( $sa == "poste" )
+ echo '';
+
+ if ( $sa=='mp')
{
- $User->can_request(PARPOS,1);
- require_once('poste.inc.php');
+ $User->can_request(PARMP,1);
+ require_once('payment_middle.inc.php');
+ exit;
+ }
+ //---------------------------------------------------------------------------
+ // Add or remove attribut of card
+ //---------------------------------------------------------------------------
+ if ( $sa=='fat')
+ {
+ $User->can_request('FICCAT');
+ require_once('card_attr.inc.php');
+ exit();
+ }
+ //-----------------------------------------------------
+ // TVA RATE
+ //-----------------------------------------------------
+ if ( $sa == "tva" )
+ {
+ echo '';
+ $User->can_request(PARTVA,1);
+ require_once("tva.inc.php");
+ //
+ }
+ //-----------------------------------------------------
+ // Accounting item
+ //-----------------------------------------------------
+ if ( $sa == "poste" )
+ {
+ $User->can_request(PARPOS,1);
+ require_once('poste.inc.php');
}
- //-----------------------------------------------------
- // fiche
- //-----------------------------------------------------
- if ( $sa == "fiche" )
+ //-----------------------------------------------------
+ // fiche
+ //-----------------------------------------------------
+ if ( $sa == "fiche" )
{
- $User->can_request(PARFIC,1);
- require_once('fiche_def.inc.php');
- return;
+ $User->can_request(PARFIC,1);
+ require_once('fiche_def.inc.php');
+ return;
+ }
+ //----------------------------------------------------
+ // Cat. Document
+ //----------------------------------------------------
+ if ( $def== 6)
+ {
+ $User->can_request(PARCATDOC,1);
+ require_once('cat_document.inc.php');
+ return;
}
- //----------------------------------------------------
- // Cat. Document
- //----------------------------------------------------
- if ( $def== 6) {
- $User->can_request(PARCATDOC,1);
- require_once('cat_document.inc.php');
- return;
- }
- }
+}
//-----------------------------------------------------
// Extension
//-----------------------------------------------------
-if ( $p_action=='ext') {
- $User->can_request(EXTENSION,1);
- require_once('extension.inc.php');
- exit;
- }
+if ( $p_action=='ext')
+{
+ $User->can_request(EXTENSION,1);
+ require_once('extension.inc.php');
+ exit;
+}
//-----------------------------------------------------
// Coord societe
//-----------------------------------------------------
-if ( $p_action=='company') {
- $User->can_request(PARCOORD,1);
- echo '';
- require_once("class_own.php");
- if ( isset ($_POST['record_company'] )) {
- $m=new Own($cn);
- extract($_POST);
- $m->MY_NAME=$p_name;
- $m->MY_TVA=$p_tva;
- $m->MY_STREET=$p_street;
- $m->MY_NUMBER=$p_no;
- $m->MY_CP=$p_cp;
- $m->MY_COMMUNE=$p_Commune;
- $m->MY_TEL=$p_tel;
- $m->MY_FAX=$p_fax;
- $m->MY_PAYS=$p_pays;
- $m->MY_CHECK_PERIODE=$p_check_periode;
- $m->MY_DATE_SUGGEST=$p_date_suggest;
- if ( $User->check_action(PARCA)!=0)$m->MY_ANALYTIC=$p_compta;
- if ( $User->check_action(PARSTR)!=0) $m->MY_STRICT=$p_strict;
- if ( $User->check_action(PARTVA)!=0)$m->MY_TVA_USE=$p_tva_use;
- $m->MY_PJ_SUGGEST=$p_pj;
- $m->Update();
- }
+if ( $p_action=='company')
+{
+ $User->can_request(PARCOORD,1);
+ echo '
';
+ require_once("class_own.php");
+ if ( isset ($_POST['record_company'] ))
+ {
+ $m=new Own($cn);
+ extract($_POST);
+ $m->MY_NAME=$p_name;
+ $m->MY_TVA=$p_tva;
+ $m->MY_STREET=$p_street;
+ $m->MY_NUMBER=$p_no;
+ $m->MY_CP=$p_cp;
+ $m->MY_COMMUNE=$p_Commune;
+ $m->MY_TEL=$p_tel;
+ $m->MY_FAX=$p_fax;
+ $m->MY_PAYS=$p_pays;
+ $m->MY_CHECK_PERIODE=$p_check_periode;
+ $m->MY_DATE_SUGGEST=$p_date_suggest;
+ if ( $User->check_action(PARCA)!=0)$m->MY_ANALYTIC=$p_compta;
+ if ( $User->check_action(PARSTR)!=0) $m->MY_STRICT=$p_strict;
+ if ( $User->check_action(PARTVA)!=0)$m->MY_TVA_USE=$p_tva_use;
+ $m->MY_PJ_SUGGEST=$p_pj;
+ $m->Update();
+ }
- $my=new Own($cn);
- ///// Compta analytic
- $array=array (
- array("value"=>"ob",'label'=>_("obligatoire")),
- array("value"=>"op",'label'=>_("optionnel")),
- array("value"=>"nu",'label'=>_("non utilisé"))
- );
- $strict_array=array(
- array('value'=>'N','label'=>_('Non')),
- array('value'=>'Y','label'=>_('Oui'))
- );
+ $my=new Own($cn);
+ ///// Compta analytic
+ $array=array (
+ array("value"=>"ob",'label'=>_("obligatoire")),
+ array("value"=>"op",'label'=>_("optionnel")),
+ array("value"=>"nu",'label'=>_("non utilisé"))
+ );
+ $strict_array=array(
+ array('value'=>'N','label'=>_('Non')),
+ array('value'=>'Y','label'=>_('Oui'))
+ );
- $compta=new ISelect();
- $compta->table=1;
- $compta->selected=$my->MY_ANALYTIC;
+ $compta=new ISelect();
+ $compta->table=1;
+ $compta->selected=$my->MY_ANALYTIC;
- $strict=new ISelect();
- $strict->table=1;
- $strict->selected=$my->MY_STRICT;
+ $strict=new ISelect();
+ $strict->table=1;
+ $strict->selected=$my->MY_STRICT;
- $tva_use=new ISelect();
- $tva_use->table=1;
- $tva_use->selected=$my->MY_TVA_USE;
+ $tva_use=new ISelect();
+ $tva_use->table=1;
+ $tva_use->selected=$my->MY_TVA_USE;
- $pj_suggest=new ISelect();
- $pj_suggest->table=1;
- $pj_suggest->selected=$my->MY_PJ_SUGGEST;
-
- $date_suggest=new ISelect();
- $date_suggest->table=1;
- $date_suggest->selected=$my->MY_DATE_SUGGEST;
-
- $check_periode=new ISelect();
- $check_periode->table=1;
- $check_periode->selected=$my->MY_CHECK_PERIODE;
+ $pj_suggest=new ISelect();
+ $pj_suggest->table=1;
+ $pj_suggest->selected=$my->MY_PJ_SUGGEST;
- // other parameters
- $all=new IText();
- $all->table=1;
- echo '
';
- echo dossier::hidden();
- echo "";
- echo "".td(_('Nom société'),'style="text-align:right"').$all->input("p_name",$my->MY_NAME)." ";
- $all->value='';
- echo "".td(_("Téléphone"),'style="text-align:right"').$all->input("p_tel",$my->MY_TEL)." ";
- $all->value='';
- echo "".td(_("Fax"),'style="text-align:right"').$all->input("p_fax",$my->MY_FAX)." ";
- $all->value='';
- echo "".td(_("Rue "),'style="text-align:right"').$all->input("p_street",$my->MY_STREET)." ";
- $all->value='';
- echo "".td(_("Numéro"),'style="text-align:right"').$all->input("p_no",$my->MY_NUMBER)." ";
- $all->value='';
- echo "".td(_("Code Postal"),'style="text-align:right"').$all->input("p_cp",$my->MY_CP)." ";
- $all->value='';
- echo "".td(_("Commune"),'style="text-align:right"').$all->input("p_Commune",$my->MY_COMMUNE)." ";
- $all->value='';
- echo "".td(_("Pays"),'style="text-align:right"').$all->input("p_pays",$my->MY_PAYS)." ";
- $all->value='';
- echo "".td(_("Numéro de Tva"),'style="text-align:right"').$all->input("p_tva",$my->MY_TVA)." ";
- if ( $User->check_action(PARCA)==0) $compta->setReadonly(true);
- echo "".td(_("Utilisation de la compta. analytique"),'style="text-align:right"').$compta->input("p_compta",$array)." ";
- if ( $User->check_action(PARSTR)==0) $strict->setReadonly(true);
- echo "".td(_("Utilisation du mode strict "),'style="text-align:right"').$strict->input("p_strict",$strict_array)." ";
- if ( $User->check_action(PARTVA)==0) $tva_use->setReadonly(true);
- echo "".td(_("Assujetti à la tva"),'style="text-align:right"').$tva_use->input("p_tva_use",$strict_array)." ";
- echo "".td(_("Suggérer le numéro de pièce justificative"),'style="text-align:right"').$pj_suggest->input("p_pj",$strict_array)." ";
- echo "".td(_("Suggérer la date"),'style="text-align:right"').$date_suggest->input("p_date_suggest",$strict_array)." ";
- echo ''.td(_('Afficher la période comptable pour éviter les erreurs de date'),'style="text-align:right"').$check_periode->input('p_check_periode',$strict_array).' ';
- echo "
";
- echo HtmlInput::submit("record_company",_("Sauve"));
- echo " ";
- echo '
';
- exit();
- }
+ $date_suggest=new ISelect();
+ $date_suggest->table=1;
+ $date_suggest->selected=$my->MY_DATE_SUGGEST;
+
+ $check_periode=new ISelect();
+ $check_periode->table=1;
+ $check_periode->selected=$my->MY_CHECK_PERIODE;
+
+ // other parameters
+ $all=new IText();
+ $all->table=1;
+ echo '
';
+ echo dossier::hidden();
+ echo "";
+ echo "".td(_('Nom société'),'style="text-align:right"').$all->input("p_name",$my->MY_NAME)." ";
+ $all->value='';
+ echo "".td(_("Téléphone"),'style="text-align:right"').$all->input("p_tel",$my->MY_TEL)." ";
+ $all->value='';
+ echo "".td(_("Fax"),'style="text-align:right"').$all->input("p_fax",$my->MY_FAX)." ";
+ $all->value='';
+ echo "".td(_("Rue "),'style="text-align:right"').$all->input("p_street",$my->MY_STREET)." ";
+ $all->value='';
+ echo "".td(_("Numéro"),'style="text-align:right"').$all->input("p_no",$my->MY_NUMBER)." ";
+ $all->value='';
+ echo "".td(_("Code Postal"),'style="text-align:right"').$all->input("p_cp",$my->MY_CP)." ";
+ $all->value='';
+ echo "".td(_("Commune"),'style="text-align:right"').$all->input("p_Commune",$my->MY_COMMUNE)." ";
+ $all->value='';
+ echo "".td(_("Pays"),'style="text-align:right"').$all->input("p_pays",$my->MY_PAYS)." ";
+ $all->value='';
+ echo "".td(_("Numéro de Tva"),'style="text-align:right"').$all->input("p_tva",$my->MY_TVA)." ";
+ if ( $User->check_action(PARCA)==0) $compta->setReadonly(true);
+ echo "".td(_("Utilisation de la compta. analytique"),'style="text-align:right"').$compta->input("p_compta",$array)." ";
+ if ( $User->check_action(PARSTR)==0) $strict->setReadonly(true);
+ echo "".td(_("Utilisation du mode strict "),'style="text-align:right"').$strict->input("p_strict",$strict_array)." ";
+ if ( $User->check_action(PARTVA)==0) $tva_use->setReadonly(true);
+ echo "".td(_("Assujetti à la tva"),'style="text-align:right"').$tva_use->input("p_tva_use",$strict_array)." ";
+ echo "".td(_("Suggérer le numéro de pièce justificative"),'style="text-align:right"').$pj_suggest->input("p_pj",$strict_array)." ";
+ echo "".td(_("Suggérer la date"),'style="text-align:right"').$date_suggest->input("p_date_suggest",$strict_array)." ";
+ echo ''.td(_('Afficher la période comptable pour éviter les erreurs de date'),'style="text-align:right"').$check_periode->input('p_check_periode',$strict_array).' ';
+ echo "
";
+ echo HtmlInput::submit("record_company",_("Sauve"));
+ echo " ";
+ echo '
';
+ exit();
+}
//-----------------------------------------------------
-// Document
+// Document
//-----------------------------------------------------
echo "";
-if ( $p_action == 'document' ) {
- $User->can_request(PARDOC,1);
- echo '';
- require_once('document_modele.inc.php');
- echo '
';
-}
+if ( $p_action == 'document' )
+{
+ $User->can_request(PARDOC,1);
+ echo '';
+ require_once('document_modele.inc.php');
+ echo '
';
+}
//----------------------------------------------------------------------
// Plan Comptable
//----------------------------------------------------------------------
-if ( $p_action == 'pcmn' ) {
- $User->can_request(PARPCMN,1);
- require_once('param_pcmn.inc.php');
-}
+if ( $p_action == 'pcmn' )
+{
+ $User->can_request(PARPCMN,1);
+ require_once('param_pcmn.inc.php');
+}
//----------------------------------------------------------------------
// Security
//----------------------------------------------------------------------
-if ( $p_action == 'sec' ) {
- $User->can_request(PARSEC,1);
- require_once('param_sec.inc.php');
-}
+if ( $p_action == 'sec' )
+{
+ $User->can_request(PARSEC,1);
+ require_once('param_sec.inc.php');
+}
//----------------------------------------------------------------------
// Predefined operation
//----------------------------------------------------------------------
-if ( $p_action == 'preod' ) {
- $User->can_request(PARPREDE,1);
- require_once('preod.inc.php');
-}
+if ( $p_action == 'preod' )
+{
+ $User->can_request(PARPREDE,1);
+ require_once('preod.inc.php');
+}
//---------------------------------------------------------------------------
// Definition of report
//---------------------------------------------------------------------------
-if ( $p_action == 'defrapport' ) {
- $User->can_request(PARRAP,1);
- require_once('report.inc.php');
+if ( $p_action == 'defrapport' )
+{
+ $User->can_request(PARRAP,1);
+ require_once('report.inc.php');
}
//----------------------------------------------------------------------
// Ledger parameter
//----------------------------------------------------------------------
-if ( $p_action == 'jrn' ) {
- $User->can_request(PARJRN,1);
- $sa=(isset($_REQUEST['sa']))?$_REQUEST['sa']:"";
- // echo '';
- if ( $sa == "add")
- require_once ('param_jrn_add.inc.php');
- elseif ($sa=='detail')
+if ( $p_action == 'jrn' )
+{
+ $User->can_request(PARJRN,1);
+ $sa=(isset($_REQUEST['sa']))?$_REQUEST['sa']:"";
+ // echo '
';
+ if ( $sa == "add")
+ require_once ('param_jrn_add.inc.php');
+ elseif ($sa=='detail')
require_once ('param_jrn_detail.inc.php');
- else
- require_once('param_jrn.inc.php');
- // echo '
';
-}
+ else
+ require_once('param_jrn.inc.php');
+ // echo '
';
+}
diff --git a/html/popup.php b/html/popup.php
index 4c8b3b9fc..e3b56392c 100644
--- a/html/popup.php
+++ b/html/popup.php
@@ -22,8 +22,10 @@ echo js_include('card.js');
$str="?".$_SERVER['QUERY_STRING']."&div=popup";
$script="
-var obj={'id':'popup','fixed':1,'class':'content',style:'width:auto','html':loading(),'qs':'$str',js_success:'success_box','js_error':null,'callback':'".$_GET['ajax']."'};
-show_box(obj);
-";
+ var obj={'id':'popup','fixed':1,'class':'content',style:'width:auto','html':loading(),'qs':'$str',js_success:'success_box','js_error':null,'callback':'".$_GET['ajax']."'};
+ show_box(obj);
+ ";
echo create_script($script);
+?>
+?>
?>
\ No newline at end of file
diff --git a/html/poste_csv.php b/html/poste_csv.php
index ec83e0065..9737638b2 100644
--- a/html/poste_csv.php
+++ b/html/poste_csv.php
@@ -44,109 +44,115 @@ $User->can_request(IMPPOSTE,0);
if ( isset ( $_REQUEST['poste_fille']) )
{ //choisit de voir tous les postes
- $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text like '".$_REQUEST["poste_id"]."%'");
-}
-else
+ $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text like '".$_REQUEST["poste_id"]."%'");
+}
+else
{
- $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val = '".$_REQUEST['poste_id']."'");
+ $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val = '".$_REQUEST['poste_id']."'");
}
-if ( ! isset ($_REQUEST['oper_detail'])) {
- if ( count($a_poste) == 0 )
- exit;
-
- foreach ($a_poste as $pos)
- {
- $Poste=new Acc_Account_Ledger($cn,$pos['pcm_val']);
- $name=$Poste->get_name();
- list($array,$tot_deb,$tot_cred)=$Poste->get_row_date( $_REQUEST['from_periode'],
- $_REQUEST['to_periode'],
- $_GET['ople']
- );
- if ( count($Poste->row ) == 0 )
- continue;
-
- echo '"Poste";'.'"Lib.";'.
- "\"Code interne\";".
- "\"Date\";".
- "\"Description\";".
- "\"Débit\";".
- "\"Crédit\";".
- "\"Prog.\"";
- printf("\n");
-
- $prog=0;
- foreach ( $Poste->row as $op ) {
- $prog+=$op['deb_montant']-$op['cred_montant'];
- echo '"'.$pos['pcm_val'].'";'.
- '"'.$name.'";'.
- '"'.$op['jr_internal'].'"'.";".
- '"'.$op['j_date_fmt'].'"'.";".
- '"'.$op['description']." ".$op['jr_pj_number'].'"'.";".
- nb($op['deb_montant']).";".
- nb($op['cred_montant']).";".
- nb(abs($prog));
- printf("\n");
-
-
- }
- $solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde créditeur";
- $diff=abs($tot_deb-$tot_cred);
- printf(
- '"'."$solde_type".'"'.";".
- nb($diff).";".
- nb($tot_deb).";".
- nb($tot_cred)."\n");
- }
- } else {
- /* detail of all operation */
- if ( count($a_poste) == 0 )
- exit;
-
- foreach ($a_poste as $pos)
- {
- $Poste=new Acc_Account_Ledger($cn,$pos['pcm_val']);
- $Poste->get_name();
- list($array,$tot_deb,$tot_cred)=$Poste->get_row_date( $_REQUEST['from_periode'],
- $_REQUEST['to_periode']
- );
- if ( count($Poste->row ) == 0 )
- continue;
-
- echo '"Poste";'.
- '"Lib.";'.
- '"QuickCode";'.
- "\"Code interne\";".
- "\"Date\";".
- "\"Description\";".
- "\"Montant\";".
- "\"D/C\"";
- printf("\n");
-
-
- foreach ( $Poste->row as $a ) {
- $op=new Acc_Operation($cn);
- $op->jr_id=$a['jr_id'];
- $result=$op->get_jrnx_detail();
- foreach ( $result as $r) {
- printf('"%s";"%s";"%s";"%s";"%s";"%s";"%s";%12.2f;"%s"',
- $r['j_poste'],
- $r['pcm_lib'],
- $r['j_qcode'],
- $r['jr_internal'],
- $r['jr_date'],
- $a['description'],
- $a['jr_pj_number'],
- nb($r['j_montant']),
- $r['debit']);
- printf("\r\n");
+if ( ! isset ($_REQUEST['oper_detail']))
+{
+ if ( count($a_poste) == 0 )
+ exit;
- }
+ foreach ($a_poste as $pos)
+ {
+ $Poste=new Acc_Account_Ledger($cn,$pos['pcm_val']);
+ $name=$Poste->get_name();
+ list($array,$tot_deb,$tot_cred)=$Poste->get_row_date( $_REQUEST['from_periode'],
+ $_REQUEST['to_periode'],
+ $_GET['ople']
+ );
+ if ( count($Poste->row ) == 0 )
+ continue;
-
-
- }
+ echo '"Poste";'.'"Lib.";'.
+ "\"Code interne\";".
+ "\"Date\";".
+ "\"Description\";".
+ "\"Débit\";".
+ "\"Crédit\";".
+ "\"Prog.\"";
+ printf("\n");
+
+ $prog=0;
+ foreach ( $Poste->row as $op )
+ {
+ $prog+=$op['deb_montant']-$op['cred_montant'];
+ echo '"'.$pos['pcm_val'].'";'.
+ '"'.$name.'";'.
+ '"'.$op['jr_internal'].'"'.";".
+ '"'.$op['j_date_fmt'].'"'.";".
+ '"'.$op['description']." ".$op['jr_pj_number'].'"'.";".
+ nb($op['deb_montant']).";".
+ nb($op['cred_montant']).";".
+ nb(abs($prog));
+ printf("\n");
+
+
+ }
+ $solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde créditeur";
+ $diff=abs($tot_deb-$tot_cred);
+ printf(
+ '"'."$solde_type".'"'.";".
+ nb($diff).";".
+ nb($tot_deb).";".
+ nb($tot_cred)."\n");
}
- exit;
- }
+}
+else
+{
+ /* detail of all operation */
+ if ( count($a_poste) == 0 )
+ exit;
+
+ foreach ($a_poste as $pos)
+ {
+ $Poste=new Acc_Account_Ledger($cn,$pos['pcm_val']);
+ $Poste->get_name();
+ list($array,$tot_deb,$tot_cred)=$Poste->get_row_date( $_REQUEST['from_periode'],
+ $_REQUEST['to_periode']
+ );
+ if ( count($Poste->row ) == 0 )
+ continue;
+
+ echo '"Poste";'.
+ '"Lib.";'.
+ '"QuickCode";'.
+ "\"Code interne\";".
+ "\"Date\";".
+ "\"Description\";".
+ "\"Montant\";".
+ "\"D/C\"";
+ printf("\n");
+
+
+ foreach ( $Poste->row as $a )
+ {
+ $op=new Acc_Operation($cn);
+ $op->jr_id=$a['jr_id'];
+ $result=$op->get_jrnx_detail();
+ foreach ( $result as $r)
+ {
+ printf('"%s";"%s";"%s";"%s";"%s";"%s";"%s";%12.2f;"%s"',
+ $r['j_poste'],
+ $r['pcm_lib'],
+ $r['j_qcode'],
+ $r['jr_internal'],
+ $r['jr_date'],
+ $a['description'],
+ $a['jr_pj_number'],
+ nb($r['j_montant']),
+ $r['debit']);
+ printf("\r\n");
+
+ }
+
+
+
+ }
+ }
+ exit;
+}
?>
diff --git a/html/poste_pdf.php b/html/poste_pdf.php
index 656a4fc2c..69bdf77a4 100644
--- a/html/poste_pdf.php
+++ b/html/poste_pdf.php
@@ -43,11 +43,13 @@ $User->can_request(IMPPOSTE,0);
extract($_GET);
- if ( isset ( $poste_fille) ){ //choisit de voir tous les postes
- $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text like '$poste_id%' order by pcm_val");
- } else
- $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text = '$poste_id'");
-
+if ( isset ( $poste_fille) )
+{ //choisit de voir tous les postes
+ $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text like '$poste_id%' order by pcm_val");
+}
+else
+ $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text = '$poste_id'");
+
$ret="";
@@ -56,109 +58,146 @@ $pdf->setDossierInfo(" Periode : ".$_GET['from_periode']." - ".$_GET['to_period
$pdf->AliasNbPages();
$pdf->AddPage();
-if ( count($a_poste) == 0 ) {
- $pdf->Output('poste.pdf','I');
- exit;
+if ( count($a_poste) == 0 )
+{
+ $pdf->Output('poste.pdf','I');
+ exit;
}
$size=array(13,25,20,60,12,20,20,20);
$align=array('L','C','C','L','R','R','R','R');
-foreach ($a_poste as $poste)
+foreach ($a_poste as $poste)
{
- $Poste=new Acc_Account_Ledger($cn,$poste['pcm_val']);
- list($array,$tot_deb,$tot_cred)=$Poste->get_row_date($from_periode,$to_periode,$_GET['ople']);
- // don't print empty account
- if ( count($array) == 0 ) {
- continue;
- }
- $Libelle=sprintf("(%s) %s ",$Poste->id,$Poste->get_name());
- $pdf->SetFont('DejaVuCond','',10);
- $pdf->Cell(0,8,$Libelle,1,0,'C');
- $pdf->Ln();
-
- $pdf->SetFont('DejaVuCond','',8);
- $l=0;
- $pdf->Cell($size[$l],6,'Date',0,0,'L');$l++;
- $pdf->Cell($size[$l],6,'Ref',0,0,'C');$l++;
- $pdf->Cell($size[$l],6,'Journal',0,0,'C');$l++;
- $pdf->Cell($size[$l],6,'Libellé',0,0,'L');$l++;
- $pdf->Cell($size[$l],6,'Let',0,0,'R');$l++;
- $pdf->Cell($size[$l],6,'Debit',0,0,'R');$l++;
- $pdf->Cell($size[$l],6,'Credit',0,0,'R');$l++;
- $pdf->Cell($size[$l],6,'Prog',0,0,'R');$l++;
- $pdf->ln();
- $tot_deb=0;$tot_cred=0;$prog=0;
- for ($e=0;$eCell($size[$l],6,$date,0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,$row['jr_internal'],0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,substr($row['jrn_name'],0,14),0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,$row['description'],0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,(($row['letter']!=-1)?$row['letter']:''),0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$row['deb_montant'])),0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$row['cred_montant'])),0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,(sprintf('% 12.2f',abs($prog))),0,0,$align[$l]);$l++;
- $pdf->ln();
- $tot_deb+=$row['deb_montant'];
- $tot_cred+=$row['cred_montant'];
- /* -------------------------------------- */
- /* if details are asked we show them here */
- /* -------------------------------------- */
- if ( isset($_GET['oper_detail'])){
- $detail=new Acc_Operation($cn);
- $detail->jr_id=$row['jr_id'];
- $a_detail=$detail->get_jrnx_detail();
- for ($f=0;$fCell($size[$l],6,'',0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,$a_detail[$f]['j_qcode'],0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,$a_detail[$f]['j_poste'],0,0,$align[$l]);$l++;
- if ( $a_detail[$f]['j_qcode']=='')
- $lib=$a_detail[$f]['pcm_lib'];
- else
- {
- $f_id=$cn->get_value('select f_id from vw_poste_qcode where j_qcode=$1',array($a_detail[$f]['j_qcode'])) ;
- $lib=$cn->get_value('select av_text from jnt_fic_att_value join attr_value using (jft_id) where ad_id=$1 and f_id=$2',
- array(ATTR_DEF_NAME,$f_id));
- }
- $pdf->Cell($size[$l],6,$lib,0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,(($a_detail[$f]['letter']!=-1)?$a_detail[$f]['letter']:''),0,0,$align[$l]);$l++;
-
- $deb=($a_detail[$f]['debit']=='D')?$a_detail[$f]['j_montant']:'';
- $cred=($a_detail[$f]['debit']=='C')?$a_detail[$f]['j_montant']:'';
-
- $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$deb)),0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$cred)),0,0,$align[$l]);$l++;
- $pdf->ln();
- }
- }
- }
- $str_debit=sprintf("% 12.2f €",$tot_deb);
- $str_credit=sprintf("% 12.2f €",$tot_cred);
- $diff_solde=$tot_deb-$tot_cred;
- if ( $diff_solde < 0 ) {
- $solde=" créditeur ";
- $diff_solde*=-1;
- } else
+ $Poste=new Acc_Account_Ledger($cn,$poste['pcm_val']);
+ list($array,$tot_deb,$tot_cred)=$Poste->get_row_date($from_periode,$to_periode,$_GET['ople']);
+ // don't print empty account
+ if ( count($array) == 0 )
{
- $solde=" débiteur ";
+ continue;
}
- $str_diff_solde=sprintf("%12.2f €",$diff_solde);
-
- $pdf->SetFont('DejaVu','B',8);
-
- $pdf->Cell(160,5,'Débit',0,0,'R');
- $pdf->Cell(30,5,$str_debit,0,0,'R');$pdf->Ln();
- $pdf->Cell(160,5,'Crédit',0,0,'R');
- $pdf->Cell(30,5,$str_credit,0,0,'R');$pdf->Ln();
- $pdf->Cell(160,5,'Solde '.$solde,0,0,'R');
- $pdf->Cell(30,5,$str_diff_solde,0,0,'R');$pdf->Ln();
+ $Libelle=sprintf("(%s) %s ",$Poste->id,$Poste->get_name());
+ $pdf->SetFont('DejaVuCond','',10);
+ $pdf->Cell(0,8,$Libelle,1,0,'C');
+ $pdf->Ln();
-}
+ $pdf->SetFont('DejaVuCond','',8);
+ $l=0;
+ $pdf->Cell($size[$l],6,'Date',0,0,'L');
+ $l++;
+ $pdf->Cell($size[$l],6,'Ref',0,0,'C');
+ $l++;
+ $pdf->Cell($size[$l],6,'Journal',0,0,'C');
+ $l++;
+ $pdf->Cell($size[$l],6,'Libellé',0,0,'L');
+ $l++;
+ $pdf->Cell($size[$l],6,'Let',0,0,'R');
+ $l++;
+ $pdf->Cell($size[$l],6,'Debit',0,0,'R');
+ $l++;
+ $pdf->Cell($size[$l],6,'Credit',0,0,'R');
+ $l++;
+ $pdf->Cell($size[$l],6,'Prog',0,0,'R');
+ $l++;
+ $pdf->ln();
+ $tot_deb=0;
+ $tot_cred=0;
+ $prog=0;
+ for ($e=0;$eCell($size[$l],6,$date,0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,$row['jr_internal'],0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,substr($row['jrn_name'],0,14),0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,$row['description'],0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,(($row['letter']!=-1)?$row['letter']:''),0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$row['deb_montant'])),0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$row['cred_montant'])),0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,(sprintf('% 12.2f',abs($prog))),0,0,$align[$l]);
+ $l++;
+ $pdf->ln();
+ $tot_deb+=$row['deb_montant'];
+ $tot_cred+=$row['cred_montant'];
+ /* -------------------------------------- */
+ /* if details are asked we show them here */
+ /* -------------------------------------- */
+ if ( isset($_GET['oper_detail']))
+ {
+ $detail=new Acc_Operation($cn);
+ $detail->jr_id=$row['jr_id'];
+ $a_detail=$detail->get_jrnx_detail();
+ for ($f=0;$fCell($size[$l],6,'',0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,$a_detail[$f]['j_qcode'],0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,$a_detail[$f]['j_poste'],0,0,$align[$l]);
+ $l++;
+ if ( $a_detail[$f]['j_qcode']=='')
+ $lib=$a_detail[$f]['pcm_lib'];
+ else
+ {
+ $f_id=$cn->get_value('select f_id from vw_poste_qcode where j_qcode=$1',array($a_detail[$f]['j_qcode'])) ;
+ $lib=$cn->get_value('select av_text from jnt_fic_att_value join attr_value using (jft_id) where ad_id=$1 and f_id=$2',
+ array(ATTR_DEF_NAME,$f_id));
+ }
+ $pdf->Cell($size[$l],6,$lib,0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,(($a_detail[$f]['letter']!=-1)?$a_detail[$f]['letter']:''),0,0,$align[$l]);
+ $l++;
+
+ $deb=($a_detail[$f]['debit']=='D')?$a_detail[$f]['j_montant']:'';
+ $cred=($a_detail[$f]['debit']=='C')?$a_detail[$f]['j_montant']:'';
+
+ $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$deb)),0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$cred)),0,0,$align[$l]);
+ $l++;
+ $pdf->ln();
+ }
+ }
+ }
+ $str_debit=sprintf("% 12.2f €",$tot_deb);
+ $str_credit=sprintf("% 12.2f €",$tot_cred);
+ $diff_solde=$tot_deb-$tot_cred;
+ if ( $diff_solde < 0 )
+ {
+ $solde=" créditeur ";
+ $diff_solde*=-1;
+ }
+ else
+ {
+ $solde=" débiteur ";
+ }
+ $str_diff_solde=sprintf("%12.2f €",$diff_solde);
+
+ $pdf->SetFont('DejaVu','B',8);
+
+ $pdf->Cell(160,5,'Débit',0,0,'R');
+ $pdf->Cell(30,5,$str_debit,0,0,'R');
+ $pdf->Ln();
+ $pdf->Cell(160,5,'Crédit',0,0,'R');
+ $pdf->Cell(30,5,$str_credit,0,0,'R');
+ $pdf->Ln();
+ $pdf->Cell(160,5,'Solde '.$solde,0,0,'R');
+ $pdf->Cell(30,5,$str_diff_solde,0,0,'R');
+ $pdf->Ln();
+
+}
$fDate=date('dmy-Hi');
$pdf->Output('poste-'.$fDate.'.pdf','I');
+?>
+?>
?>
\ No newline at end of file
diff --git a/html/print_balance.php b/html/print_balance.php
index 74dd24961..d9c3333ca 100644
--- a/html/print_balance.php
+++ b/html/print_balance.php
@@ -30,7 +30,7 @@
*/
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
// $Revision$
-
+
include_once("ac_common.php");
require_once('class_database.php');
include_once("class_acc_balance.php");
@@ -50,23 +50,26 @@ $User->can_request(IMPBAL,1);
extract ($_GET);
$bal->jrn=null;
-switch( $_GET['p_filter']){
+switch( $_GET['p_filter'])
+{
case 0:
- $bal->jrn=null;
- break;
+ $bal->jrn=null;
+ break;
case 1:
- if ( isset($_GET['r_jrn'])) {
- $selected=$_GET['r_jrn'];
- $array_ledger=$User->get_ledger('ALL',3);
- for ($e=0;$ejrn[]=$array_ledger[$e]['jrn_def_id'];
+ if ( isset($_GET['r_jrn']))
+ {
+ $selected=$_GET['r_jrn'];
+ $array_ledger=$User->get_ledger('ALL',3);
+ for ($e=0;$ejrn[]=$array_ledger[$e]['jrn_def_id'];
+ }
}
- }
- break;
+ break;
case 2:
- if ( isset($_GET['r_cat'])) $bal->filter_cat($_GET['r_cat']);
- break;
+ if ( isset($_GET['r_cat'])) $bal->filter_cat($_GET['r_cat']);
+ break;
}
$bal->from_poste=$_GET['from_poste'];
@@ -74,10 +77,11 @@ $bal->to_poste=$_GET['to_poste'];
$array=$bal->get_row($from_periode,$to_periode);
-if ( sizeof($array) == 0 ) {
- exit();
-
- }
+if ( sizeof($array) == 0 )
+{
+ exit();
+
+}
$pPeriode=new Periode($cn);
$a=$pPeriode->get_date_limit($from_periode);
@@ -97,27 +101,34 @@ $pdf->Cell(20,6,'Solde Créditeur',0,0,'R');
$pdf->Ln();
$pdf->SetFont('DejaVuCond','',8);
-$tp_deb=0;$tp_cred=0;$tp_sold=0;$tp_solc=0;
-for ($i=0;$iSetFillColor(220,221,255);
- $fill=1;
- } else {
- $pdf->SetFillColor(0,0,0);
- $fill=0;
- }
- if ( ! isset($array[$i]))continue;
- $pdf->Cell(30,6,$array[$i]['poste'],0,0,'L',$fill);
- $pdf->Cell(80,6,$array[$i]['label'],0,0,'L',$fill);
- $pdf->Cell(20,6,$array[$i]['sum_deb'],0,0,'R',$fill);
- $pdf->Cell(20,6,$array[$i]['sum_cred'],0,0,'R',$fill);
- $pdf->Cell(20,6,$array[$i]['solde_deb'],0,0,'R',$fill);
- $pdf->Cell(20,6,$array[$i]['solde_cred'],0,0,'R',$fill);
- $pdf->Ln();
- $tp_deb+=$array[$i]['sum_deb'];
- $tp_cred+=$array[$i]['sum_cred'];
- $tp_sold+=$array[$i]['solde_deb'];
- $tp_solc+=$array[$i]['solde_cred'];
+$tp_deb=0;
+$tp_cred=0;
+$tp_sold=0;
+$tp_solc=0;
+for ($i=0;$iSetFillColor(220,221,255);
+ $fill=1;
+ }
+ else
+ {
+ $pdf->SetFillColor(0,0,0);
+ $fill=0;
+ }
+ if ( ! isset($array[$i]))continue;
+ $pdf->Cell(30,6,$array[$i]['poste'],0,0,'L',$fill);
+ $pdf->Cell(80,6,$array[$i]['label'],0,0,'L',$fill);
+ $pdf->Cell(20,6,$array[$i]['sum_deb'],0,0,'R',$fill);
+ $pdf->Cell(20,6,$array[$i]['sum_cred'],0,0,'R',$fill);
+ $pdf->Cell(20,6,$array[$i]['solde_deb'],0,0,'R',$fill);
+ $pdf->Cell(20,6,$array[$i]['solde_cred'],0,0,'R',$fill);
+ $pdf->Ln();
+ $tp_deb+=$array[$i]['sum_deb'];
+ $tp_cred+=$array[$i]['sum_cred'];
+ $tp_sold+=$array[$i]['solde_deb'];
+ $tp_solc+=$array[$i]['solde_cred'];
}
// Totaux
diff --git a/html/priv_user.php b/html/priv_user.php
index b74c4facf..f93cfb5a0 100644
--- a/html/priv_user.php
+++ b/html/priv_user.php
@@ -31,22 +31,25 @@ $User=new User($rep);
$User->Check();
/* only the global admin can modify something here
*/
-if ($User->admin != 1) {
- html_page_stop();
- return;
+if ($User->admin != 1)
+{
+ html_page_stop();
+ return;
}
-if (! isset ($_REQUEST['UID']) ) {
- html_page_stop();
- exit();
+if (! isset ($_REQUEST['UID']) )
+{
+ html_page_stop();
+ exit();
}
$uid=$_REQUEST['UID'];
$UserChange=new User($rep,$uid);
$r_UID=$UserChange->id;
-if ( $r_UID == false ) {
- // Message d'erreur
- html_page_stop();
+if ( $r_UID == false )
+{
+ // Message d'erreur
+ html_page_stop();
}
echo ' Administration Globale ';
@@ -65,82 +68,99 @@ echo 'Gestion Utilisateurs ';
exec_sql( "update ac_users set use_pass='$l_pass' where use_id=$uid");
- echo ' Password remis à phpcompta ';
+if ( isset ( $_GET['reset_passwd']) )
+{
+ $cn=new Database();
+ $l_pass=md5('phpcompta');
+ $Res=$cn->exec_sql( "update ac_users set use_pass='$l_pass' where use_id=$uid");
+ echo ' Password remis à phpcompta ';
}
/* Save the changes */
-if ( isset ($_POST['SAVE']) ){
- $uid = $_POST['UID'];
+if ( isset ($_POST['SAVE']) )
+{
+ $uid = $_POST['UID'];
- // Update User
- $cn=new Database();
- $last_name=$_POST['fname'];
- $first_name=$_POST['lname'];
- $UserChange=new User($cn,$uid);
- if ( $UserChange->load()==-1) {
- alert("Cet utilisateur n'existe pas");}
- else {
- $UserChange->first_name=$first_name;
- $UserChange->last_name=$last_name;
- $UserChange->active=$_POST['Actif'];
- $UserChange->admin=$_POST['Admin'];
- $UserChange->save();
-
- // Update Priv on Folder
- foreach ($_POST as $name=>$elem)
- {
- if ( substr_count($name,'PRIV')!=0 )
- {
- $db_id=substr($name,4);
- $cn=new Database();
- $UserChange->set_folder_access($db_id,$elem);
-
- }
-
- }
- }
-} else {
- if ( isset ($_POST["DELETE"]) ) {
+ // Update User
$cn=new Database();
- $Res=$cn->exec_sql("delete from priv_user where priv_jnt in ( select jnt_id from jnt_use_dos where use_id=$1",array($uid));
- $Res=$cn->exec_sql("delete from jnt_use_dos where use_id=$1",array($uid));
- $Res=$cn->exec_sql("delete from ac_users where use_id=$1",array($uid));
+ $last_name=$_POST['fname'];
+ $first_name=$_POST['lname'];
+ $UserChange=new User($cn,$uid);
+ if ( $UserChange->load()==-1)
+ {
+ alert("Cet utilisateur n'existe pas");
+ }
+ else
+ {
+ $UserChange->first_name=$first_name;
+ $UserChange->last_name=$last_name;
+ $UserChange->active=$_POST['Actif'];
+ $UserChange->admin=$_POST['Admin'];
+ $UserChange->save();
- echo " User ".h($_POST['fname'])." ".h($_POST['lname'])." (".
- h($_POST['login']).") est effacé ";
-require_once("class_iselect.php");
- require_once("user.inc.php");
- return;
- }
+ // Update Priv on Folder
+ foreach ($_POST as $name=>$elem)
+ {
+ if ( substr_count($name,'PRIV')!=0 )
+ {
+ $db_id=substr($name,4);
+ $cn=new Database();
+ $UserChange->set_folder_access($db_id,$elem);
+
+ }
+
+ }
+ }
+}
+else
+{
+ if ( isset ($_POST["DELETE"]) )
+ {
+ $cn=new Database();
+ $Res=$cn->exec_sql("delete from priv_user where priv_jnt in ( select jnt_id from jnt_use_dos where use_id=$1",array($uid));
+ $Res=$cn->exec_sql("delete from jnt_use_dos where use_id=$1",array($uid));
+ $Res=$cn->exec_sql("delete from ac_users where use_id=$1",array($uid));
+
+ echo " User ".h($_POST['fname'])." ".h($_POST['lname'])." (".
+ h($_POST['login']).") est effacé ";
+ require_once("class_iselect.php");
+ require_once("user.inc.php");
+ return;
+ }
}
$UserChange->load();
?>
-',$uid); ?>
+ ',$uid);
+?>
active == 1 ) {
- $ACT="CHECKED";$NACT="UNCHECKED";
-} else {
- $ACT="UNCHECKED";$NACT="CHECKED";
+if ( $UserChange->active == 1 )
+{
+ $ACT="CHECKED";
+ $NACT="UNCHECKED";
+}
+else
+{
+ $ACT="UNCHECKED";
+ $NACT="CHECKED";
}
echo "";
printf(' Actif',$ACT);
@@ -153,10 +173,15 @@ echo " ";
admin == 1 ) {
- $ACT="CHECKED";$NACT="UNCHECKED";
-} else {
- $ACT="UNCHECKED";$NACT="CHECKED";
+if ( $UserChange->admin == 1 )
+{
+ $ACT="CHECKED";
+ $NACT="UNCHECKED";
+}
+else
+{
+ $ACT="UNCHECKED";
+ $NACT="CHECKED";
}
echo "";
printf(' Administrateur global',$ACT);
@@ -171,56 +196,59 @@ echo " ";
Droit sur les dossiers pour les utilisateurs normaux
-
-Les autres droits doivent être réglés dans les dossiers (paramètre->sécurité)
-
-
-'X','label'=>'Aucun Accès'),
- array('value'=>'R','label'=>'Utilisateur normal'),
- array('value'=>'P','label'=>'Utilisateur uniquement extension'),
- array('value'=>'L','label'=>'Administrateur local(Tous les droits)')
- );
+
+ Les autres droits doivent être réglés dans les dossiers (paramètre->sécurité)
+
+
+ 'X','label'=>'Aucun Accès'),
+ array('value'=>'R','label'=>'Utilisateur normal'),
+ array('value'=>'P','label'=>'Utilisateur uniquement extension'),
+ array('value'=>'L','label'=>'Administrateur local(Tous les droits)')
+ );
$repo=new Dossier(0);
$Dossier=$repo->show_dossier('all',1,0);
-if ( empty ( $Dossier )) {
- echo hb('* Aucun Dossier *');
- echo '';
- exit();
+if ( empty ( $Dossier ))
+{
+ echo hb('* Aucun Dossier *');
+ echo '';
+ exit();
}
$mod_user=new User(new Database(),$uid);
-foreach ( $Dossier as $rDossier) {
+foreach ( $Dossier as $rDossier)
+{
- $priv=$mod_user->get_folder_access($rDossier['dos_id']);
- printf(" Dossier : %s ",h($rDossier['dos_name']));
+ $priv=$mod_user->get_folder_access($rDossier['dos_id']);
+ printf(" Dossier : %s ",h($rDossier['dos_name']));
- $select=new ISelect();
- $select->table=1;
- $select->name=sprintf('PRIV%s',$rDossier['dos_id']);
- $select->value=$array;
- $select->selected=$priv;
- echo $select->input();
- echo " ";
+ $select=new ISelect();
+ $select->table=1;
+ $select->name=sprintf('PRIV%s',$rDossier['dos_id']);
+ $select->value=$array;
+ $select->selected=$priv;
+ echo $select->input();
+ echo "";
}
?>
-
+
-
- echo HtmlInput::button_anchor('Retour','admin_repo.php?action=user_mgt'); ?>
+
+ echo HtmlInput::button_anchor('Retour','admin_repo.php?action=user_mgt');
+?>
diff --git a/html/quick_code_csv.php b/html/quick_code_csv.php
index 100bbd33f..d02ef03a9 100644
--- a/html/quick_code_csv.php
+++ b/html/quick_code_csv.php
@@ -41,78 +41,84 @@ $User->Check();
$Fiche=new Fiche($cn,$_REQUEST['f_id']);
$Fiche->getName();
-list($array,$tot_deb,$tot_cred)=$Fiche->get_row_date(
- $_GET['from_periode'],
- $_GET['to_periode'],
- $_GET['ople']
- );
-if ( count($Fiche->row ) == 0 )
+list($array,$tot_deb,$tot_cred)=$Fiche->get_row_date(
+ $_GET['from_periode'],
+ $_GET['to_periode'],
+ $_GET['ople']
+ );
+if ( count($Fiche->row ) == 0 )
{
- echo "Aucune donnée";
- return;
+ echo "Aucune donnée";
+ return;
}
-if ( ! isset ($_REQUEST['oper_detail'])) {
-echo '"Qcode";'.
-"\"Code interne\";".
-"\"Date\";".
-"\"Description\";".
-"\"Débit\";".
-"\"Crédit\";".
-"\"Prog.\"";
-printf("\n");
-$progress=0;
- foreach ( $Fiche->row as $op ) {
- $progress+=$op['deb_montant']-$op['cred_montant'];
-
- echo '"'.$op['j_qcode'].'";'.
- '"'.$op['jr_internal'].'"'.";".
- '"'.$op['j_date_fmt'].'"'.";".
- '"'.$op['description'].'"'.";".
- nb($op['deb_montant']).";".
- nb($op['cred_montant']).";".
- nb(abs($progress));
+if ( ! isset ($_REQUEST['oper_detail']))
+{
+ echo '"Qcode";'.
+ "\"Code interne\";".
+ "\"Date\";".
+ "\"Description\";".
+ "\"Débit\";".
+ "\"Crédit\";".
+ "\"Prog.\"";
printf("\n");
-
- }
-}else {
+ $progress=0;
+ foreach ( $Fiche->row as $op )
+ {
+ $progress+=$op['deb_montant']-$op['cred_montant'];
+
+ echo '"'.$op['j_qcode'].'";'.
+ '"'.$op['jr_internal'].'"'.";".
+ '"'.$op['j_date_fmt'].'"'.";".
+ '"'.$op['description'].'"'.";".
+ nb($op['deb_montant']).";".
+ nb($op['cred_montant']).";".
+ nb(abs($progress));
+ printf("\n");
+
+ }
+}
+else
+{
echo '"Poste";"Qcode";"internal";';
echo '"Date";'.
- "\"Description\";".
- "\"Montant\";".
- "\"D/C\"";
+ "\"Description\";".
+ "\"Montant\";".
+ "\"D/C\"";
printf("\r\n");
- foreach ( $Fiche->row as $op ) {
- $acc=new Acc_Operation($cn);
- $acc->jr_id=$op['jr_id'];
- $result= $acc->get_jrnx_detail();
- foreach ( $result as $r) {
- printf('"%s";"%s";"%s";"%s";"%s";%s;"%s"',
- $r['j_poste'],
- $r['j_qcode'],
- $r['jr_internal'],
- $r['jr_date'],
- $r['description'],
- nb($r['j_montant']),
- $r['debit']);
- printf("\r\n");
+ foreach ( $Fiche->row as $op )
+ {
+ $acc=new Acc_Operation($cn);
+ $acc->jr_id=$op['jr_id'];
+ $result= $acc->get_jrnx_detail();
+ foreach ( $result as $r)
+ {
+ printf('"%s";"%s";"%s";"%s";"%s";%s;"%s"',
+ $r['j_poste'],
+ $r['j_qcode'],
+ $r['jr_internal'],
+ $r['jr_date'],
+ $r['description'],
+ nb($r['j_montant']),
+ $r['debit']);
+ printf("\r\n");
- }
+ }
- }
- }
+ }
+}
$solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde créditeur";
- $diff=abs($tot_deb-$tot_cred);
+$diff=abs($tot_deb-$tot_cred);
printf(
- '"'."$solde_type".'"'.";".
- nb($diff).";".
- nb($tot_deb).";".
- nb($tot_cred)."\n");
+ '"'."$solde_type".'"'.";".
+ nb($diff).";".
+ nb($tot_deb).";".
+ nb($tot_cred)."\n");
exit;
?>
diff --git a/html/quick_code_pdf.php b/html/quick_code_pdf.php
index a0d132a07..676daade5 100644
--- a/html/quick_code_pdf.php
+++ b/html/quick_code_pdf.php
@@ -49,102 +49,136 @@ $Fiche=new Fiche($cn,$f_id);
list($array,$tot_deb,$tot_cred)=$Fiche->get_row_date($from_periode,$to_periode,$_GET['ople']);
// don't print empty account
-if ( count($array) == 0 ) {
- exit;
+if ( count($array) == 0 )
+{
+ exit;
}
$size=array(13,25,20,60,12,20,20,20);
$align=array('L','C','C','L','R','R','R','R');
$Libelle=sprintf("(%s) %s ",$Fiche->id,$Fiche->getName());
$pdf->SetFont('DejaVu','',10);
-$pdf->Cell(0,8,$Libelle,1,0,'C');
+$pdf->Cell(0,8,$Libelle,1,0,'C');
$pdf->Ln();
- $pdf->SetFont('DejaVuCond','',8);
- $l=0;
- $pdf->Cell($size[$l],6,'Date',0,0,'L');$l++;
- $pdf->Cell($size[$l],6,'Ref',0,0,'C');$l++;
- $pdf->Cell($size[$l],6,'Journal',0,0,'C');$l++;
- $pdf->Cell($size[$l],6,'Libellé',0,0,'L');$l++;
- $pdf->Cell($size[$l],6,'Let',0,0,'R');$l++;
- $pdf->Cell($size[$l],6,'Debit',0,0,'R');$l++;
- $pdf->Cell($size[$l],6,'Credit',0,0,'R');$l++;
- $pdf->Cell($size[$l],6,'Prog',0,0,'R');$l++;
- $pdf->ln();
-$tot_deb=0;$tot_cred=0;$progress=0;
- for ($e=0;$eSetFont('DejaVuCond','',8);
+$l=0;
+$pdf->Cell($size[$l],6,'Date',0,0,'L');
+$l++;
+$pdf->Cell($size[$l],6,'Ref',0,0,'C');
+$l++;
+$pdf->Cell($size[$l],6,'Journal',0,0,'C');
+$l++;
+$pdf->Cell($size[$l],6,'Libellé',0,0,'L');
+$l++;
+$pdf->Cell($size[$l],6,'Let',0,0,'R');
+$l++;
+$pdf->Cell($size[$l],6,'Debit',0,0,'R');
+$l++;
+$pdf->Cell($size[$l],6,'Credit',0,0,'R');
+$l++;
+$pdf->Cell($size[$l],6,'Prog',0,0,'R');
+$l++;
+$pdf->ln();
+$tot_deb=0;
+$tot_cred=0;
+$progress=0;
+for ($e=0;$eCell($size[$l],6,$date,0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,$row['jr_internal'],0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,substr($row['jrn_name'],0,14),0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,$row['description'],0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,(($row['letter']!=-1)?$row['letter']:''),0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$row['deb_montant'])),0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$row['cred_montant'])),0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,(sprintf('% 12.2f',abs($progress))),0,0,$align[$l]);$l++;
+ $pdf->Cell($size[$l],6,$date,0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,$row['jr_internal'],0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,substr($row['jrn_name'],0,14),0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,$row['description'],0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,(($row['letter']!=-1)?$row['letter']:''),0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$row['deb_montant'])),0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$row['cred_montant'])),0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,(sprintf('% 12.2f',abs($progress))),0,0,$align[$l]);
+ $l++;
$pdf->ln();
$tot_deb+=$row['deb_montant'];
$tot_cred+=$row['cred_montant'];
/* -------------------------------------- */
/* if details are asked we show them here */
/* -------------------------------------- */
- if ( isset($_GET['oper_detail'])){
- $detail=new Acc_Operation($cn);
- $detail->jr_id=$row['jr_id'];
- $a_detail=$detail->get_jrnx_detail();
- for ($f=0;$fCell($size[$l],6,'',0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,$a_detail[$f]['j_qcode'],0,0,'L');$l++;
- $pdf->Cell($size[$l],6,$a_detail[$f]['j_poste'],0,0,'R');$l++;
- if ( $a_detail[$f]['j_qcode']=='')
- $lib=$a_detail[$f]['pcm_lib'];
- else
- {
- $f_id=$cn->get_value('select f_id from vw_poste_qcode where j_qcode=$1',array($a_detail[$f]['j_qcode'])) ;
- $lib=$cn->get_value('select av_text from jnt_fic_att_value join attr_value using (jft_id) where ad_id=$1 and f_id=$2',
- array(ATTR_DEF_NAME,$f_id));
- }
- $pdf->Cell($size[$l],6,$lib,0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,(($a_detail[$f]['letter']!=-1)?$a_detail[$f]['letter']:''),0,0,$align[$l]);$l++;
-
- $deb=($a_detail[$f]['debit']=='D')?$a_detail[$f]['j_montant']:'';
- $cred=($a_detail[$f]['debit']=='C')?$a_detail[$f]['j_montant']:'';
-
- $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$deb)),0,0,$align[$l]);$l++;
- $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$cred)),0,0,$align[$l]);$l++;
- $pdf->ln();
- }
+ if ( isset($_GET['oper_detail']))
+ {
+ $detail=new Acc_Operation($cn);
+ $detail->jr_id=$row['jr_id'];
+ $a_detail=$detail->get_jrnx_detail();
+ for ($f=0;$fCell($size[$l],6,'',0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,$a_detail[$f]['j_qcode'],0,0,'L');
+ $l++;
+ $pdf->Cell($size[$l],6,$a_detail[$f]['j_poste'],0,0,'R');
+ $l++;
+ if ( $a_detail[$f]['j_qcode']=='')
+ $lib=$a_detail[$f]['pcm_lib'];
+ else
+ {
+ $f_id=$cn->get_value('select f_id from vw_poste_qcode where j_qcode=$1',array($a_detail[$f]['j_qcode'])) ;
+ $lib=$cn->get_value('select av_text from jnt_fic_att_value join attr_value using (jft_id) where ad_id=$1 and f_id=$2',
+ array(ATTR_DEF_NAME,$f_id));
+ }
+ $pdf->Cell($size[$l],6,$lib,0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,(($a_detail[$f]['letter']!=-1)?$a_detail[$f]['letter']:''),0,0,$align[$l]);
+ $l++;
+
+ $deb=($a_detail[$f]['debit']=='D')?$a_detail[$f]['j_montant']:'';
+ $cred=($a_detail[$f]['debit']=='C')?$a_detail[$f]['j_montant']:'';
+
+ $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$deb)),0,0,$align[$l]);
+ $l++;
+ $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$cred)),0,0,$align[$l]);
+ $l++;
+ $pdf->ln();
+ }
}
-
- }
- $str_debit=sprintf("% 12.2f €",$tot_deb);
- $str_credit=sprintf("% 12.2f €",$tot_cred);
- $diff_solde=$tot_deb-$tot_cred;
- if ( $diff_solde < 0 ) {
+
+}
+$str_debit=sprintf("% 12.2f €",$tot_deb);
+$str_credit=sprintf("% 12.2f €",$tot_cred);
+$diff_solde=$tot_deb-$tot_cred;
+if ( $diff_solde < 0 )
+{
$solde=" créditeur ";
$diff_solde*=-1;
- } else
- {
- $solde=" débiteur ";
- }
- $str_diff_solde=sprintf("%12.2f €",$diff_solde);
-
- $pdf->SetFont('DejaVu','B',8);
-
- $pdf->Cell(160,5,'Débit',0,0,'R');
- $pdf->Cell(30,5,$str_debit,0,0,'R');$pdf->Ln();
- $pdf->Cell(160,5,'Crédit',0,0,'R');
- $pdf->Cell(30,5,$str_credit,0,0,'R');$pdf->Ln();
- $pdf->Cell(160,5,'Solde '.$solde,0,0,'R');
- $pdf->Cell(30,5,$str_diff_solde,0,0,'R');$pdf->Ln();
-
+}
+else
+{
+ $solde=" débiteur ";
+}
+$str_diff_solde=sprintf("%12.2f €",$diff_solde);
+
+$pdf->SetFont('DejaVu','B',8);
+
+$pdf->Cell(160,5,'Débit',0,0,'R');
+$pdf->Cell(30,5,$str_debit,0,0,'R');
+$pdf->Ln();
+$pdf->Cell(160,5,'Crédit',0,0,'R');
+$pdf->Cell(30,5,$str_credit,0,0,'R');
+$pdf->Ln();
+$pdf->Cell(160,5,'Solde '.$solde,0,0,'R');
+$pdf->Cell(30,5,$str_diff_solde,0,0,'R');
+$pdf->Ln();
+
$fDate=date('dmy-Hi');
$pdf->Output('fiche-'.$fDate.'.pdf','I');
diff --git a/html/recherche.php b/html/recherche.php
index 83cc6e625..c192e1bec 100644
--- a/html/recherche.php
+++ b/html/recherche.php
@@ -71,27 +71,28 @@ echo '';
//-----------------------------------------------------
// Display search result
//-----------------------------------------------------
-if ( isset ($_GET['viewsearch'])) {
+if ( isset ($_GET['viewsearch']))
+{
- // Navigation bar
- $step=$_SESSION['g_pagesize'];
- $page=(isset($_GET['offset']))?$_GET['page']:1;
- $offset=(isset($_GET['offset']))?$_GET['offset']:0;
- if (count ($_GET) == 0)
- $array=null;
- else
- $array=$_GET;
- $array['p_action']='ALL';
- list($sql,$where)=$ledger->build_search_sql($array);
- // Count nb of line
- $max_line=$cn->count_sql($sql);
+ // Navigation bar
+ $step=$_SESSION['g_pagesize'];
+ $page=(isset($_GET['offset']))?$_GET['page']:1;
+ $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+ if (count ($_GET) == 0)
+ $array=null;
+ else
+ $array=$_GET;
+ $array['p_action']='ALL';
+ list($sql,$where)=$ledger->build_search_sql($array);
+ // Count nb of line
+ $max_line=$cn->count_sql($sql);
- list($count,$a)=$ledger->list_operation($sql,$offset,0);
- $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
+ list($count,$a)=$ledger->list_operation($sql,$offset,0);
+ $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
- echo $bar;
- echo $a;
- echo $bar;
+ echo $bar;
+ echo $a;
+ echo $bar;
}
echo '';
diff --git a/html/remove_op.php b/html/remove_op.php
index 7d3263d2f..3dc0f4203 100644
--- a/html/remove_op.php
+++ b/html/remove_op.php
@@ -20,7 +20,7 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*!\file
+/*!\file
*
*
* \brief from ajax, remove op. CA
@@ -36,6 +36,6 @@ $gDossier=dossier::id();
$cn=new Database($gDossier);
$User=new User($cn);
$User->Check();
-if ($User->check_action(CAOD))
- $cn->exec_sql("delete from operation_analytique where oa_group=$1",array($_GET['oa']));
+if ($User->check_action(CAOD))
+ $cn->exec_sql("delete from operation_analytique where oa_group=$1",array($_GET['oa']));
?>
diff --git a/html/search_ca.php b/html/search_ca.php
index 50c2ce3cb..a0e9d2868 100644
--- a/html/search_ca.php
+++ b/html/search_ca.php
@@ -26,8 +26,8 @@
*
*/
- // parameter are gDossier , c1 : the control id to update,
- // c2 the control id which contains the pa_id
+// parameter are gDossier , c1 : the control id to update,
+// c2 the control id which contains the pa_id
require_once("class_itext.php");
require_once("class_ihidden.php");
require_once("class_ibutton.php");
@@ -56,42 +56,43 @@ echo $hid->input("go");
echo HtmlInput::submit("go",_("Recherche"));
echo '';
//------------- FORM ----------------------------------
-if ( isset($_REQUEST['go'])) {
- $cn=new Database(dossier::id());
- $plan=new Anc_Plan($cn,$_REQUEST['c2']);
- $plan->pa_id=$_REQUEST['c2'];
- if ( $plan->exist()==false)
- exit("Ce plan n'existe pas");
+if ( isset($_REQUEST['go']))
+{
+ $cn=new Database(dossier::id());
+ $plan=new Anc_Plan($cn,$_REQUEST['c2']);
+ $plan->pa_id=$_REQUEST['c2'];
+ if ( $plan->exist()==false)
+ exit("Ce plan n'existe pas");
- $sql="select po_name , po_description from poste_analytique ".
- "where pa_id=".$_REQUEST['c2']." and ".
- " upper (po_name) like upper('%".Database::escape_string($_REQUEST['label'])."%') order by po_name";
- $res=$cn->exec_sql($sql);
- $array=Database::fetch_all($res);
- if (empty($array) == true)
- {
- echo "Désolé aucun poste trouvé";
- return;
- }
- $button=new IButton();
- $button->name="Choix";
- $button->label="Choix";
+ $sql="select po_name , po_description from poste_analytique ".
+ "where pa_id=".$_REQUEST['c2']." and ".
+ " upper (po_name) like upper('%".Database::escape_string($_REQUEST['label'])."%') order by po_name";
+ $res=$cn->exec_sql($sql);
+ $array=Database::fetch_all($res);
+ if (empty($array) == true)
+ {
+ echo "Désolé aucun poste trouvé";
+ return;
+ }
+ $button=new IButton();
+ $button->name="Choix";
+ $button->label="Choix";
- echo '';
- foreach ($array as $line)
- {
- $button->javascript=sprintf("set_inparent('%s','%s');window.close();",
- $_REQUEST['c1'],
- $line['po_name']);
- echo ''.
- ''.
- $button->input().
- ' '.
- ''.
- $line['po_name'].
- ' '.
- $line['po_description'].
- ' ';
- }
- echo '
';
- }
+ echo '';
+ foreach ($array as $line)
+ {
+ $button->javascript=sprintf("set_inparent('%s','%s');window.close();",
+ $_REQUEST['c1'],
+ $line['po_name']);
+ echo ''.
+ ''.
+ $button->input().
+ ' '.
+ ''.
+ $line['po_name'].
+ ' '.
+ $line['po_description'].
+ ' ';
+ }
+ echo '
';
+}
diff --git a/html/sec_pdf.php b/html/sec_pdf.php
index b275edc0f..9fc10e29b 100755
--- a/html/sec_pdf.php
+++ b/html/sec_pdf.php
@@ -30,7 +30,7 @@ require_once('class_database.php');
require_once("class_pdf.php");
$cn=new Database($gDossier);
//-----------------------------------------------------
-// Security
+// Security
// Check User
$rep=new Database();
@@ -42,24 +42,32 @@ $User->can_request(PARSEC,1);
//-----------------------------------------------------
// Get User's info
-if ( ! isset($_GET['user_id']) )
- return;
+if ( ! isset($_GET['user_id']) )
+ return;
$SecUser=new User($rep,$_GET['user_id']);
$admin=0;
$access=$SecUser->get_folder_access($gDossier);
-if ( $access == 'L') {
- $str='Local Admin';$admin=1;
-} elseif ($access=='R') {
- $str=' Utilisateur normal';
-} elseif ($access=='P') {
- $str=' Extension uniquement';
+if ( $access == 'L')
+{
+ $str='Local Admin';
+ $admin=1;
+}
+elseif ($access=='R')
+{
+ $str=' Utilisateur normal';
+}
+elseif ($access=='P')
+{
+ $str=' Extension uniquement';
}
-if ( $SecUser->admin==1 ) {
- $str=' Super Admin';$admin=1;
+if ( $SecUser->admin==1 )
+{
+ $str=' Super Admin';
+ $admin=1;
}
@@ -72,27 +80,29 @@ $pdf->AliasNbPages();
$pdf->AddPage();
$str_user=sprintf("( %d ) %s %s [ %s ] - %s",
- $SecUser->id,
- $SecUser->first_name,
- $SecUser->name,
- $SecUser->login,
- $str);
+ $SecUser->id,
+ $SecUser->first_name,
+ $SecUser->name,
+ $SecUser->login,
+ $str);
$pdf->SetFont('DejaVu','B',9);
$pdf->Cell(0,7,$str_user,'B',0,'C');
$pdf->Ln();
-if ( $SecUser->active==0) {
+if ( $SecUser->active==0)
+{
$pdf->SetTextColor(255,0,34);
- $pdf->Cell(0,7,'Bloqué',0,0,'R');
- $pdf->Ln();
- }
+ $pdf->Cell(0,7,'Bloqué',0,0,'R');
+ $pdf->Ln();
+}
-if ( $SecUser->admin==1) {
- $pdf->SetTextColor(0,0,0);
- $pdf->setFillColor(239,251,255);
- $pdf->Cell(40,7,'Administrateur',1,1,'R');
- $pdf->Ln();
- }
+if ( $SecUser->admin==1)
+{
+ $pdf->SetTextColor(0,0,0);
+ $pdf->setFillColor(239,251,255);
+ $pdf->Cell(40,7,'Administrateur',1,1,'R');
+ $pdf->Ln();
+}
$pdf->SetTextColor(0,0,0);
//-----------------------------------------------------
@@ -102,33 +112,35 @@ $pdf->Ln();
$pdf->SetFont('DejaVu','',6);
$Res=$cn->exec_sql("select jrn_def_id,jrn_def_name from jrn_def ");
$SecUser->db=$cn;
-for ($e=0;$e < Database::num_row($Res);$e++) {
- $row=Database::fetch_array($Res,$e);
- $pdf->Cell(40,6,$row['jrn_def_name']);
- $priv=$SecUser->check_jrn($row['jrn_def_id']);
- switch($priv) {
- case 'X':
- $pdf->SetTextColor(255,0,34);
- $pdf->Cell(30,6,"Pas d'accès");
- break;
- case 'R':
- $pdf->SetTextColor(54,233,0);
- $pdf->Cell(30,6,"Lecture");
- break;
- case 'O':
- /**
- *non implemente
- */
- $pdf->Cell(30,6,"Opérations prédéfinies uniquement");
- break;
- case 'W':
- $pdf->SetTextColor(54,233,0);
- $pdf->Cell(30,6,'Ecriture');
- break;
- }
- $pdf->SetTextColor(0);
- $pdf->Ln();
- }
+for ($e=0;$e < Database::num_row($Res);$e++)
+{
+ $row=Database::fetch_array($Res,$e);
+ $pdf->Cell(40,6,$row['jrn_def_name']);
+ $priv=$SecUser->check_jrn($row['jrn_def_id']);
+ switch($priv)
+ {
+ case 'X':
+ $pdf->SetTextColor(255,0,34);
+ $pdf->Cell(30,6,"Pas d'accès");
+ break;
+ case 'R':
+ $pdf->SetTextColor(54,233,0);
+ $pdf->Cell(30,6,"Lecture");
+ break;
+ case 'O':
+ /**
+ *non implemente
+ */
+ $pdf->Cell(30,6,"Opérations prédéfinies uniquement");
+ break;
+ case 'W':
+ $pdf->SetTextColor(54,233,0);
+ $pdf->Cell(30,6,'Ecriture');
+ break;
+ }
+ $pdf->SetTextColor(0);
+ $pdf->Ln();
+}
//-----------------------------------------------------
// Action
@@ -137,30 +149,32 @@ $pdf->Cell(0,7,'Accès action',1,0,'C');
$pdf->Ln();
$pdf->SetFont('DejaVu','',6);
$Res=$cn->exec_sql(
- "select ac_id, ac_description from action order by ac_description ");
+ "select ac_id, ac_description from action order by ac_description ");
$Max=Database::num_row($Res);
-for ( $i =0 ; $i < $Max; $i++ ) {
- $l_line=Database::fetch_array($Res,$i);
- $pdf->Cell(90,6,$l_line['ac_description']);
- $right=$SecUser->check_action($l_line['ac_id']);
- switch ($right) {
- case 0:
- $pdf->SetTextColor(255,0,34);
+for ( $i =0 ; $i < $Max; $i++ )
+{
+ $l_line=Database::fetch_array($Res,$i);
+ $pdf->Cell(90,6,$l_line['ac_description']);
+ $right=$SecUser->check_action($l_line['ac_id']);
+ switch ($right)
+ {
+ case 0:
+ $pdf->SetTextColor(255,0,34);
- $pdf->Cell(30,6,"Pas d'accès");
- break;
- case 1:
- case 2:
- $pdf->SetTextColor(54,233,0);
- $pdf->Cell(30,6,"Accès");
- break;
- }
- $pdf->SetTextColor(0);
+ $pdf->Cell(30,6,"Pas d'accès");
+ break;
+ case 1:
+ case 2:
+ $pdf->SetTextColor(54,233,0);
+ $pdf->Cell(30,6,"Accès");
+ break;
+ }
+ $pdf->SetTextColor(0);
- $pdf->Ln();
- }
+ $pdf->Ln();
+}
$fDate=date('dmy-HI');
$pdf->Output('security-'.$fDate.'pdf','I');
?>
diff --git a/html/show_document.php b/html/show_document.php
index 8764a36ae..522d48808 100644
--- a/html/show_document.php
+++ b/html/show_document.php
@@ -37,16 +37,18 @@ $User->Check();
$User->check_dossier($gDossier);
$User->can_request(GECOUR);
/* Show the document */
-if ( $action == 'sh') {
- // retrieve the document
- $doc=new Document($cn,$_REQUEST['d_id']);
- $doc->Send();
+if ( $action == 'sh')
+{
+ // retrieve the document
+ $doc=new Document($cn,$_REQUEST['d_id']);
+ $doc->Send();
}
/* remove the document */
-if ( $action == 'rm' ) {
- $doc=new Document($cn,$_REQUEST['d_id']);
- $doc->remove();
- $json=sprintf('{"d_id":"%s"}',$_REQUEST['d_id']);
- header("Content-type: text/html; charset: utf8",true);
- print $json;
-}
\ No newline at end of file
+if ( $action == 'rm' )
+{
+ $doc=new Document($cn,$_REQUEST['d_id']);
+ $doc->remove();
+ $json=sprintf('{"d_id":"%s"}',$_REQUEST['d_id']);
+ header("Content-type: text/html; charset: utf8",true);
+ print $json;
+}
diff --git a/html/show_document_modele.php b/html/show_document_modele.php
index a681da250..306fe2d9a 100644
--- a/html/show_document_modele.php
+++ b/html/show_document_modele.php
@@ -37,12 +37,13 @@ $User=new User(new Database());
*/
$User->Check();
// retrieve the document
-$r=$cn->exec_sql("select md_id,md_lob,md_filename,md_mimetype
+$r=$cn->exec_sql("select md_id,md_lob,md_filename,md_mimetype
from document_modele where md_id=".$_REQUEST['md_id']);
-if ( Database::num_row($r) == 0 ) {
- echo_error("Invalid Document");
- exit;
- }
+if ( Database::num_row($r) == 0 )
+{
+ echo_error("Invalid Document");
+ exit;
+}
$row=Database::fetch_array($r,0);
@@ -60,7 +61,7 @@ header('Content-Disposition: attachment;filename="'.$row['md_filename'].'"',FALS
header("Accept-Ranges: bytes");
$file=fopen($tmp,'r');
while ( !feof ($file) )
- echo fread($file,8192);
+ echo fread($file,8192);
fclose($file);
diff --git a/html/show_pj.php b/html/show_pj.php
index f8990fc5c..aa4de92df 100644
--- a/html/show_pj.php
+++ b/html/show_pj.php
@@ -27,8 +27,9 @@ require_once('class_dossier.php');
$gDossier=dossier::id();
if ( !isset ($_GET['jrn'] ) ||
- !isset($_GET['jr_grpt_id'])) {
- echo_error("Missing parameters");
+ !isset($_GET['jr_grpt_id']))
+{
+ echo_error("Missing parameters");
}
require_once('class_database.php');
@@ -46,37 +47,40 @@ $User->check_dossier($gDossier);
// retrieve the jrn
$r=$cn->exec_sql("select jr_def_id from jrn where jr_grpt_id=$jr_grpt_id");
-if ( Database::num_row($r) == 0 ) {
- echo_error("Invalid operation id jr_grpt_id=$jr_grpt_id");
- exit;
- }
+if ( Database::num_row($r) == 0 )
+{
+ echo_error("Invalid operation id jr_grpt_id=$jr_grpt_id");
+ exit;
+}
$a=Database::fetch_array($r,0);
$jrn=$a['jr_def_id'];
-if ($User->check_jrn($jrn) == 'X' ){
- /* Cannot Access */
- NoAccess();
- exit -1;
- }
+if ($User->check_jrn($jrn) == 'X' )
+{
+ /* Cannot Access */
+ NoAccess();
+ exit -1;
+}
$cn->start();
$ret=$cn->exec_sql("select jr_pj,jr_pj_name,jr_pj_type from jrn where jr_grpt_id=$jr_grpt_id");
if ( Database::num_row ($ret) == 0 )
- return;
+ return;
$row=Database::fetch_array($ret,0);
-if ( $row['jr_pj']==null ) {
- ini_set('zlib.output_compression','Off');
- header("Pragma: public");
- header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
- header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
- header("Cache-Control: must-revalidate");
- header('Content-type: '.'text/plain');
- header('Content-Disposition: attachment;filename=vide.txt',FALSE);
- header("Accept-Ranges: bytes");
- echo "******************";
- echo _("Fichier effacé");
- echo "******************";
- exit();
+if ( $row['jr_pj']==null )
+{
+ ini_set('zlib.output_compression','Off');
+ header("Pragma: public");
+ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+ header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
+ header("Cache-Control: must-revalidate");
+ header('Content-type: '.'text/plain');
+ header('Content-Disposition: attachment;filename=vide.txt',FALSE);
+ header("Accept-Ranges: bytes");
+ echo "******************";
+ echo _("Fichier effacé");
+ echo "******************";
+ exit();
}
$tmp=tempnam($_ENV['TMP'],'document_');
@@ -92,7 +96,7 @@ header('Content-Disposition: attachment;filename="'.$row['jr_pj_name'].'"',FALSE
header("Accept-Ranges: bytes");
$file=fopen($tmp,'r');
while ( !feof ($file) )
- echo fread($file,8192);
+ echo fread($file,8192);
fclose($file);
diff --git a/html/show_tva.php b/html/show_tva.php
index f61c1a5bf..f1b663a57 100644
--- a/html/show_tva.php
+++ b/html/show_tva.php
@@ -35,10 +35,11 @@ $gDossier=dossier::id();
html_min_page_start($User->theme,"onLoad='window.focus();'");
?>
exec_sql("select * from tva_rate order by tva_rate desc");
$Max=Database::num_row($Res);
echo "";
-for ($i=0;$i<$Max;$i++) {
- $row=Database::fetch_array($Res,$i);
- $set=sprintf( ' ',
- $_GET['ctl'],$row['tva_id']);
- printf("%s %d %s %s ",
- $set,
- $row['tva_id'],
- $row['tva_label'],
- $row['tva_comment']);
+for ($i=0;$i<$Max;$i++)
+{
+ $row=Database::fetch_array($Res,$i);
+ $set=sprintf( ' ',
+ $_GET['ctl'],$row['tva_id']);
+ printf("%s %d %s %s ",
+ $set,
+ $row['tva_id'],
+ $row['tva_label'],
+ $row['tva_comment']);
}
echo '
';
?>
-
diff --git a/html/test.php b/html/test.php
index ec2f23f87..755299055 100644
--- a/html/test.php
+++ b/html/test.php
@@ -29,57 +29,60 @@ require_once('class_database.php');
require_once ('class_dossier.php');
require_once('class_html_input.php');
-if ( ! file_exists('authorized_debug') ) {
-echo "Pour pouvoir utiliser ce fichier vous devez creer un fichier nomme authorized_debug
-dans le repertoire html du server";
-exit();
+if ( ! file_exists('authorized_debug') )
+{
+ echo "Pour pouvoir utiliser ce fichier vous devez creer un fichier nomme authorized_debug
+ dans le repertoire html du server";
+ exit();
}
html_page_start();
// Test the connection
echo __FILE__.":".__LINE__;
print_r($_REQUEST);
-if ( ! isset($_REQUEST['gDossier'])) {
- echo "Vous avez oublie de specifier le gDossier ;)";
- echo "L'url aurait du etre test.php?gDossier=xx";
- exit();
- }
+if ( ! isset($_REQUEST['gDossier']))
+{
+ echo "Vous avez oublie de specifier le gDossier ;)";
+ echo "L'url aurait du etre test.php?gDossier=xx";
+ exit();
+}
$array=array(
- array(1,'Plan Analytic'),
- array(2,'Poste Analytic'),
- array(3,'Opération Analytic'),
- array(11,'Periode'),
- array(12,'verif.inc.php'),
- array(13,'Rapport(class_acc_report'),
- array(14,'Tva(class_acc_tav'),
- array(15,'Compute(class_acc_compute'),
- array(16,'widget'),
- array(17,'Ledger info(class_acc_ledger_info'),
- array(18,'Toddo list(class_todo'),
- array(19,'Payment (class_acc_payment'),
- array(20,'Form Acc_Ledger_Sold'),
- array(21,'Javascript') ,
- array(22,'DIV IPopup'),
- array(23,'Détection Navigateur') ,
- array(24,'Search Card'),
- array(25,'Search Ledger'),
- array(26,'Gettext'),
- array(27,'Card (class_fiche)'),
- array(28,'Extension'),
- array(29,'ITVA popup'),
- array(30,'Ereg and preg_match'),
- array(31,'IBOX'),
- array(32,'Acc_Operation & children'),
- array(33,'Ledger : reverse op'),
- array(34,'Reconciliation')
- );
+ array(1,'Plan Analytic'),
+ array(2,'Poste Analytic'),
+ array(3,'Opération Analytic'),
+ array(11,'Periode'),
+ array(12,'verif.inc.php'),
+ array(13,'Rapport(class_acc_report'),
+ array(14,'Tva(class_acc_tav'),
+ array(15,'Compute(class_acc_compute'),
+ array(16,'widget'),
+ array(17,'Ledger info(class_acc_ledger_info'),
+ array(18,'Toddo list(class_todo'),
+ array(19,'Payment (class_acc_payment'),
+ array(20,'Form Acc_Ledger_Sold'),
+ array(21,'Javascript') ,
+ array(22,'DIV IPopup'),
+ array(23,'Détection Navigateur') ,
+ array(24,'Search Card'),
+ array(25,'Search Ledger'),
+ array(26,'Gettext'),
+ array(27,'Card (class_fiche)'),
+ array(28,'Extension'),
+ array(29,'ITVA popup'),
+ array(30,'Ereg and preg_match'),
+ array(31,'IBOX'),
+ array(32,'Acc_Operation & children'),
+ array(33,'Ledger : reverse op'),
+ array(34,'Reconciliation')
+ );
$r='';
$r.='';
-foreach ($array as $value) {
- $sel="";
- if ( isset($_REQUEST['test_select']) && $_REQUEST['test_select']==$value[0])
- $sel=' selected ';
- $r.=''.$value[1];
+foreach ($array as $value)
+{
+ $sel="";
+ if ( isset($_REQUEST['test_select']) && $_REQUEST['test_select']==$value[0])
+ $sel=' selected ';
+ $r.=' '.$value[1];
}
$r.=' ';
$r.= Dossier::hidden();
@@ -89,274 +92,299 @@ $r.=' ';
echo $r;
if ( ! isset($_REQUEST['test_select']))
- exit();
+ exit();
$act=$_REQUEST['test_select'];
-switch ($act) {
+switch ($act)
+{
case 1:
- require_once('class_anc_plan.php');
- Anc_Plan::test_me();
- break;
+ require_once('class_anc_plan.php');
+ Anc_Plan::test_me();
+ break;
case 2:
- require_once("class_anc_account.php");
- Anc_Account::test_me();
- break;
+ require_once("class_anc_account.php");
+ Anc_Account::test_me();
+ break;
case 3:
- require_once ('class_anc_operation.php');
- Anc_Operation::test_me();
- break;
+ require_once ('class_anc_operation.php');
+ Anc_Operation::test_me();
+ break;
case 11:
- require_once ('class_periode.php');
- Periode::test_me();
- break;
+ require_once ('class_periode.php');
+ Periode::test_me();
+ break;
case 13:
- require_once('class_acc_report.php');
- Acc_Report::test_me();
- require_once('class_acc_report_row.php');
- Acc_Report_Row::test_me();
- break;
+ require_once('class_acc_report.php');
+ Acc_Report::test_me();
+ require_once('class_acc_report_row.php');
+ Acc_Report_Row::test_me();
+ break;
case 14:
- require_once('class_acc_tva.php');
- Acc_Tva::test_me();
- break;
+ require_once('class_acc_tva.php');
+ Acc_Tva::test_me();
+ break;
case 15:
- require('class_acc_compute.php');
- Acc_Compute::test_me();
- break;
+ require('class_acc_compute.php');
+ Acc_Compute::test_me();
+ break;
case 16:
- echo HtmlInput::button_anchor("On y va",'login.php');
- require_once('constant.php');
- require_once('class_icard.php');
- ICard::test_me();
- break;
+ echo HtmlInput::button_anchor("On y va",'login.php');
+ require_once('constant.php');
+ require_once('class_icard.php');
+ ICard::test_me();
+ break;
case 17:
- require_once('class_acc_ledger_info.php');
- Acc_Ledger_Info::test_me();
- break;
+ require_once('class_acc_ledger_info.php');
+ Acc_Ledger_Info::test_me();
+ break;
case 18:
- require_once('class_todo_list.php');
- require_once ('constant.php');
- echo JS_PROTOTYPE;
- Todo_List::test_me();
- echo '';
- echo '';
- echo dossier::hidden();
- echo 'title : ';
- echo 'desc : ';
- echo 'date : ';
- echo ' ';
- echo ' ';
- break;
+ require_once('class_todo_list.php');
+ require_once ('constant.php');
+ echo JS_PROTOTYPE;
+ Todo_List::test_me();
+ echo '';
+ echo '';
+ echo dossier::hidden();
+ echo 'title : ';
+ echo 'desc : ';
+ echo 'date : ';
+ echo ' ';
+ echo ' ';
+ break;
case 19:
- require_once('class_acc_payment.php');
- Acc_Payment::test_me();
- break;
+ require_once('class_acc_payment.php');
+ Acc_Payment::test_me();
+ break;
case 20:
- require_once('class_acc_ledger_sold.php');
- Acc_Ledger_Sold::test_me();
- break;
+ require_once('class_acc_ledger_sold.php');
+ Acc_Ledger_Sold::test_me();
+ break;
case 21:
- test_javascript();
- break;
+ test_javascript();
+ break;
case 22:
- require_once('class_ipopup.php');
- IPopup::test_me();
- break;
+ require_once('class_ipopup.php');
+ IPopup::test_me();
+ break;
case 23:
- $browser= $_SERVER['HTTP_USER_AGENT'];
- echo $browser;
- if ( strpos ($browser,'MSIE 6.0') != 0 ) {
- echo "Vous ne pouvez pas utiliser Internet Explorer 6";
- }
- break;
+ $browser= $_SERVER['HTTP_USER_AGENT'];
+ echo $browser;
+ if ( strpos ($browser,'MSIE 6.0') != 0 )
+ {
+ echo "Vous ne pouvez pas utiliser Internet Explorer 6";
+ }
+ break;
case 24:
- require_once('class_icard.php');
- require_once ('constant.php');
- echo JS_PROTOTYPE;
- echo JS_AJAX_FICHE;
- echo JS_CARD;
- ICard::test_me();
- break;
+ require_once('class_icard.php');
+ require_once ('constant.php');
+ echo JS_PROTOTYPE;
+ echo JS_AJAX_FICHE;
+ echo JS_CARD;
+ ICard::test_me();
+ break;
case 25:
- require_once('class_acc_ledger.php');
- echo JS_PROTOTYPE;
+ require_once('class_acc_ledger.php');
+ echo JS_PROTOTYPE;
- Acc_Ledger::test_me('search');
- break;
- case 26:
- /* gettext */
- $dir="";
- if ( isset($_REQUEST['l'])) {
- $dir=setlocale(LC_MESSAGES,$_REQUEST['l']);
- }else {
- $dir=setlocale(LC_MESSAGES,"fr_FR.utf8");
- }
- print_r("dir =[$dir]");
- if ( $dir == "") {
- echo 'Désolé mais ce domaine n\'est pas supporté ';
- }
- echo ' ';
- bindtextdomain('messages','./lang');
- textdomain('messages');
- bind_textdomain_codeset('messages','UTF8');
- echo _('Bienvenu sur mon site');
- echo _('Essayer de vous y amuser');
- echo '';
- echo dossier::hidden();
- echo HtmlInput::hidden('test_select',$act);
- echo _('Choississez votre langue');
- $aLang=array(array(_('Français'),'fr_FR.utf8'),
- array(_('Anglais'),'en_US.utf8'),
- array(_('Néerlandais'),'nl_NL.utf8'),
- );
- echo '';
- for ($i =0;$i < count($aLang);$i++) {
- printf('%s ',
- $aLang[$i][1],$aLang[$i][0]);
+ Acc_Ledger::test_me('search');
+ break;
+case 26:
+ /* gettext */
+ $dir="";
+ if ( isset($_REQUEST['l']))
+ {
+ $dir=setlocale(LC_MESSAGES,$_REQUEST['l']);
+ }
+ else
+ {
+ $dir=setlocale(LC_MESSAGES,"fr_FR.utf8");
+ }
+ print_r("dir =[$dir]");
+ if ( $dir == "")
+ {
+ echo 'Désolé mais ce domaine n\'est pas supporté ';
+ }
+ echo ' ';
+ bindtextdomain('messages','./lang');
+ textdomain('messages');
+ bind_textdomain_codeset('messages','UTF8');
+ echo _('Bienvenu sur mon site');
+ echo _('Essayer de vous y amuser');
+ echo '';
+ echo dossier::hidden();
+ echo HtmlInput::hidden('test_select',$act);
+ echo _('Choississez votre langue');
+ $aLang=array(array(_('Français'),'fr_FR.utf8'),
+ array(_('Anglais'),'en_US.utf8'),
+ array(_('Néerlandais'),'nl_NL.utf8'),
+ );
+ echo '';
+ for ($i =0;$i < count($aLang);$i++)
+ {
+ printf('%s ',
+ $aLang[$i][1],$aLang[$i][0]);
- }
- echo ' ';
- echo ' ';
- echo ' ';
- echo "Div 5/10 = ";
- echo 5/10;
- echo ' ';
- $test_num=10000/3;
- echo 'Div num '.$test_num;
- echo ' ';
- echo _('Fin de programme');
- break;
+ }
+ echo ' ';
+ echo ' ';
+ echo ' ';
+ echo "Div 5/10 = ";
+ echo 5/10;
+ echo ' ';
+ $test_num=10000/3;
+ echo 'Div num '.$test_num;
+ echo ' ';
+ echo _('Fin de programme');
+ break;
case 27:
- require_once('class_fiche.php');
- Fiche::test_me();
- break;
+ require_once('class_fiche.php');
+ Fiche::test_me();
+ break;
case 28:
- require_once('class_extension.php');
- Extension::test_me();
- break;
+ require_once('class_extension.php');
+ Extension::test_me();
+ break;
case 29:
- require_once('class_itva_popup.php');
- echo JS_PROTOTYPE;
- echo JS_AJAX_FICHE;
- echo JS_CARD;
- echo js_include('scripts.js');
- echo js_include('scriptaculous.js');
- echo js_include('effects.js');
- echo js_include("controls.js");
- echo js_include('dragdrop.js');
- ITva_Popup::test_me();
- break;
+ require_once('class_itva_popup.php');
+ echo JS_PROTOTYPE;
+ echo JS_AJAX_FICHE;
+ echo JS_CARD;
+ echo js_include('scripts.js');
+ echo js_include('scriptaculous.js');
+ echo js_include('effects.js');
+ echo js_include("controls.js");
+ echo js_include('dragdrop.js');
+ ITva_Popup::test_me();
+ break;
case 30:
- // Test on ereg and preg_match
- $aString=array('[7%]','[67%]','[7%]-[6%]+[67%]','[7%]-[6%]','[55%] FROM=00.000');
- echo ' EREG ';
- foreach ($aString as $str) {
- echo $str." ====>";
- @ereg ("^(\\$[a-zA-Z]*[0-9]*=){0,1}((\[{0,1}[0-9]+\.*[0-9]*%{0,1}\]{0,1})+*([+-\*/]){0,1} *(\[{0,1}[0-9]+\.*[0-9]*%{0,1}\]{0,1})*)*(([+-\*/])*\\$([a-zA-Z])+[0-9]*([+-\*/])*)* *( *FROM=[0-9][0-0].20[0-9][0-9]){0,1}$",$str,$p_result);
- var_dump($p_result);
- }
- echo ' EREG ';
- foreach ($aString as $str) {
- echo $str." ====>";
- /// $a=70%+60%+... FROM=00.000
- preg_match("/^(\\$[a-zA-Z]+[0-9]*=){0,1}(\[{0,1}[0-9]+\.*[0-9]*%{0,1}\]{0,1})(+|-|\*|\/)*/",$str,$p_result);
- // preg_match ("/^(\\$[a-zA-Z]+[0-9]*=){0,1}((\[{0,1}[0-9]+\.*[0-9]*%{0,1}\]{0,1})+ *([+-\*/])* *(\[{0,1}[0-9]+\.*[0-9]*%{0,1}\]{0,1})*)*(([+-\*/])*\\$([a-zA-Z])+[0-9]*([+-\*/])*)* *( *FROM=[0-9][0-0].20[0-9][0-9]){0,1}\$/",$str,$p_result);
- var_dump($p_result);
- }
+ // Test on ereg and preg_match
+ $aString=array('[7%]','[67%]','[7%]-[6%]+[67%]','[7%]-[6%]','[55%] FROM=00.000');
+ echo ' EREG ';
+ foreach ($aString as $str)
+ {
+ echo $str." ====>";
+ @ereg ("^(\\$[a-zA-Z]*[0-9]*=){0,1}((\[{0,1}[0-9]+\.*[0-9]*%{0,1}\]{0,1})+*([+-\*/]){0,1} *(\[{0,1}[0-9]+\.*[0-9]*%{0,1}\]{0,1})*)*(([+-\*/])*\\$([a-zA-Z])+[0-9]*([+-\*/])*)* *( *FROM=[0-9][0-0].20[0-9][0-9]){0,1}$",$str,$p_result);
+ var_dump($p_result);
+ }
+ echo ' EREG ';
+ foreach ($aString as $str)
+ {
+ echo $str." ====>";
+ /// $a=70%+60%+... FROM=00.000
+ preg_match("/^(\\$[a-zA-Z]+[0-9]*=){0,1}(\[{0,1}[0-9]+\.*[0-9]*%{0,1}\]{0,1})(+|-|\*|\/)*/",$str,$p_result);
+ // preg_match ("/^(\\$[a-zA-Z]+[0-9]*=){0,1}((\[{0,1}[0-9]+\.*[0-9]*%{0,1}\]{0,1})+ *([+-\*/])* *(\[{0,1}[0-9]+\.*[0-9]*%{0,1}\]{0,1})*)*(([+-\*/])*\\$([a-zA-Z])+[0-9]*([+-\*/])*)* *( *FROM=[0-9][0-0].20[0-9][0-9]){0,1}\$/",$str,$p_result);
+ var_dump($p_result);
+ }
case 31:
- require_once('class_ibox.php');
- IBox::test_me();
- break;
+ require_once('class_ibox.php');
+ IBox::test_me();
+ break;
case 32:
- require_once('class_acc_operation.php');
- Acc_Operation::test_me();
- break;
+ require_once('class_acc_operation.php');
+ Acc_Operation::test_me();
+ break;
case 33:
- require_once('class_acc_ledger.php');
- Acc_Ledger::test_me('reverse');
- break;
+ require_once('class_acc_ledger.php');
+ Acc_Ledger::test_me('reverse');
+ break;
case 34:
- require_once('class_acc_reconciliation.php');
- Acc_Reconciliation::test_me();
- break;
+ require_once('class_acc_reconciliation.php');
+ Acc_Reconciliation::test_me();
+ break;
}
-function test_javascript(){
-echo <<
-
+
- Ajax get - post
-
-
-
-
- encodeParameter
-
-
-set_value
-
-
p_id
-
p_span
-
-p_txtarea
-
-
-
+
+
Ajax get - post
+
+
+
+
+
encodeParameter
+
-
-
+
+
JS;
}
diff --git a/html/todo_list.php b/html/todo_list.php
index fe9d481e6..5ddfd7308 100644
--- a/html/todo_list.php
+++ b/html/todo_list.php
@@ -38,22 +38,24 @@ require_once ('class_dossier.php');
require_once ('class_todo_list.php');
require_once ('class_database.php');
- /*!\todo needs security for the users */
-if (isset($_REQUEST['show'])) {
- $cn=new Database(dossier::id());
- $todo=new Todo_list($cn);
- $todo->set_parameter('id',$_REQUEST['id']);
- $todo->load();
- header('Content-type: text/xml; charset=UTF-8');
- header ('');
- echo $todo->toXML();
- exit();
+/*!\todo needs security for the users */
+if (isset($_REQUEST['show']))
+{
+ $cn=new Database(dossier::id());
+ $todo=new Todo_list($cn);
+ $todo->set_parameter('id',$_REQUEST['id']);
+ $todo->load();
+ header('Content-type: text/xml; charset=UTF-8');
+ header ('');
+ echo $todo->toXML();
+ exit();
}
- /*!\todo needs security for the users */
-if (isset($_REQUEST['del'])) {
- $cn=new Database(dossier::id());
- $todo=new Todo_list($cn);
- $todo->set_parameter('id',$_REQUEST['id']);
- $todo->delete();
- exit();
+/*!\todo needs security for the users */
+if (isset($_REQUEST['del']))
+{
+ $cn=new Database(dossier::id());
+ $todo=new Todo_list($cn);
+ $todo->set_parameter('id',$_REQUEST['id']);
+ $todo->delete();
+ exit();
}
diff --git a/html/user_advanced.php b/html/user_advanced.php
index e19b7b679..9971922d8 100644
--- a/html/user_advanced.php
+++ b/html/user_advanced.php
@@ -52,7 +52,7 @@ echo $search_card->input();
// We don't check permissions here in fact, permission are tested in the
-// functions
+// functions
// Show the top menus
include_once ("user_menu.php");
@@ -65,61 +65,67 @@ $p_action="";
$p_action=(isset($_REQUEST['p_action']))?$_REQUEST['p_action']:"";
-switch ($p_action) {
+switch ($p_action)
+{
case 'preod':
- $high=9;
- break;
+ $high=9;
+ break;
case 'periode';
-$high=2;
-break;
+ $high=2;
+ break;
case 'verif';
-$high=10;
-break;
+ $high=10;
+ break;
case 'defreport':
- $high=6;
- break;
+ $high=6;
+ break;
case 'ouv':
- $high=8;
- break;
+ $high=8;
+ break;
default:
- $high=0;
-
- }
+ $high=0;
+
+}
echo ShowMenuAdvanced($high);
-if ($p_action == "periode" ) {
+if ($p_action == "periode" )
+{
- if ( $User->check_action(PARPER) == 0 && $User->check_action(PARCLO) == 0 )
- NoAccess();
-
- $p_action=$_REQUEST['p_action'];
- include_once("periode.inc.php");
+ if ( $User->check_action(PARPER) == 0 && $User->check_action(PARCLO) == 0 )
+ NoAccess();
+
+ $p_action=$_REQUEST['p_action'];
+ include_once("periode.inc.php");
}
//--------------------------------------------------
// Predefined operation
//--------------------------------------------------
-if ($p_action=="preod") {
- require_once('preod.inc.php');
+if ($p_action=="preod")
+{
+ require_once('preod.inc.php');
- exit();
- }
+ exit();
+}
//----------------------------------------------------------------------
// Verification solde
//----------------------------------------------------------------------
-if ( $p_action=='verif' ) {
- require_once ('verif_bilan.inc.php');
- exit();
- }
+if ( $p_action=='verif' )
+{
+ require_once ('verif_bilan.inc.php');
+ exit();
+}
-if ($p_action=='defreport') {
- require_once('report.inc.php');
+if ($p_action=='defreport')
+{
+ require_once('report.inc.php');
}
/* --------------------------------------------------
Import writing (opening exercice)
-------------------------------------------------- */
-if ( $p_action == 'ouv') {
- require_once('opening.inc.php');
+if ( $p_action == 'ouv')
+{
+ require_once('opening.inc.php');
}
html_page_stop();
?>
diff --git a/html/user_login.php b/html/user_login.php
index 6de33ae63..3e635696f 100644
--- a/html/user_login.php
+++ b/html/user_login.php
@@ -33,44 +33,47 @@ $User->Check();
/* Check Browser version if < IE6 then unsupported */
$browser=$_SERVER['HTTP_USER_AGENT'];
if ( strpos($browser,'MSIE 6')!=false ||
- strpos($browser,'MSIE 5')!=false ) {
- $nav=_('Vous utilisez un navigateur dépassé depuis près de 8 ans!');
- $nav2=_("Pour une meilleure expérience web, prenez le temps de mettre votre navigateur à jour");
-echo <<
-
-
-
+ strpos($browser,'MSIE 5')!=false )
+{
+ $nav=_('Vous utilisez un navigateur dépassé depuis près de 8 ans!');
+ $nav2=_("Pour une meilleure expérience web, prenez le temps de mettre votre navigateur à jour");
+ echo <<
+
+
+
-
$nav
-
$nav2.
+
$nav
+
$nav2.
-
-
-
+
+
+
EOF;
-exit();
+ exit();
}
$ac=new Database();
/* check if repo valid */
-if ( $ac->exist_table('version') == false) {
- echo ''._("Base de donnée invalide").' ';
- $base=dirname($_SERVER['REQUEST_URI']);
- exit();
+if ( $ac->exist_table('version') == false)
+{
+ echo ''._("Base de donnée invalide").' ';
+ $base=dirname($_SERVER['REQUEST_URI']);
+ exit();
}
/* check repo version */
$version = $ac->get_value('select val from version');
-if ( $version < DBVERSIONREPO ) {
- echo ''._("Votre base de données n'est pas à jour").' ';
- $a=_("cliquez ici pour appliquer le patch");
- $base=dirname($_SERVER['REQUEST_URI']).'/admin/setup.php';
- echo ''.$a.' ';
+if ( $version < DBVERSIONREPO )
+{
+ echo ''._("Votre base de données n'est pas à jour").' ';
+ $a=_("cliquez ici pour appliquer le patch");
+ $base=dirname($_SERVER['REQUEST_URI']).'/admin/setup.php';
+ echo ''.$a.' ';
}
@@ -85,27 +88,31 @@ echo ' ';
* so it will be directly redirected to this folder or to the plugins of this
* folder if he's an "plugin user"
*/
-if ( $User->admin == 0 ) {
- // how many folder ?
- $folder=GetAvailableFolder($_SESSION['g_user'],0);
- if ( $folder != null && count($folder) == 1 ) {
+if ( $User->admin == 0 )
+{
+ // how many folder ?
+ $folder=GetAvailableFolder($_SESSION['g_user'],0);
+ if ( $folder != null && count($folder) == 1 )
+ {
- if ( $User->check_dossier($folder[0]['dos_id']) == 'P') {
- redirect('extension.php?gDossier='.$folder[0]['dos_id']);
- exit();
+ if ( $User->check_dossier($folder[0]['dos_id']) == 'P')
+ {
+ redirect('extension.php?gDossier='.$folder[0]['dos_id']);
+ exit();
+ }
+ else
+ {
+ redirect('access.php?gDossier='.$folder[0]['dos_id']);
+ exit();
+ }
}
- else
- {
- redirect('access.php?gDossier='.$folder[0]['dos_id']);
- exit();
- }
- }
}
$result="
";
$result.='';
-if ( $User->Admin() == 1 ) {
- $result.=" Administration ";
+if ( $User->Admin() == 1 )
+{
+ $result.=" Administration ";
}
$result.=''._('Préférence').' ';
$result.=''._('Deconnexion').' ';
@@ -118,23 +125,24 @@ echo ''.$result.' ';
echo '';
?>
-
-">
+ input('p_nom',$p_nom);
?>
-
Check();
// Met a jour le theme utilisateur (style)
-if ( isset ( $_POST['style_user']) )
- {
+if ( isset ( $_POST['style_user']) )
+{
$User->update_global_pref('THEME',$_POST['style_user']);
$_SESSION['g_theme']=$_POST['style_user'];
-
- }
+
+}
// Update the language
-if ( isset($_POST ['lang'])) {
- $User->update_global_pref('LANG',$_POST['lang']);
- $_SESSION['g_lang']=$_POST['lang'];
- }
-
+if ( isset($_POST ['lang']))
+{
+ $User->update_global_pref('LANG',$_POST['lang']);
+ $_SESSION['g_lang']=$_POST['lang'];
+}
+
html_page_start($_SESSION['g_theme']);
// Met a jour le pagesize
-if ( isset ( $_POST['p_size']) ) {
- $User->update_global_pref('PAGESIZE',$_POST['p_size']);
- $_SESSION['g_pagesize']=$_POST['p_size'];
+if ( isset ( $_POST['p_size']) )
+{
+ $User->update_global_pref('PAGESIZE',$_POST['p_size']);
+ $_SESSION['g_pagesize']=$_POST['p_size'];
}
// Topmenu
-// not used for the moment
+// not used for the moment
//---------------------------------------------------------------------------
// Here we put all the changes
//---------------------------------------------------------------------------
-if ( isset ($_POST['val']) ){
- // Change the mini report
- if ( isset ($_POST['minirap'])) $User->set_mini_report($_POST['minirap']);
+if ( isset ($_POST['val']) )
+{
+ // Change the mini report
+ if ( isset ($_POST['minirap'])) $User->set_mini_report($_POST['minirap']);
}
// show the top menu depending of the use_style
// comta style
include_once ("user_menu.php");
-if ( isset ($_REQUEST['gDossier']) )
- {
- if ( $_REQUEST['gDossier'] != 0 )
- {
- echo '";
- }
- }
- else
- {
+if ( isset ($_REQUEST['gDossier']) )
+{
+ if ( $_REQUEST['gDossier'] != 0 )
+ {
+ echo '";
+ }
+}
+else
+{
echo " Préférences ";
- }
+}
require_once("pref.inc.php");
html_page_stop();
?>
diff --git a/include/ac_common.php b/include/ac_common.php
index 74fb34603..4309b8c15 100644
--- a/include/ac_common.php
+++ b/include/ac_common.php
@@ -29,29 +29,58 @@ require_once('class_periode.php');
/*!\brief to protect again bad characters which can lead to a cross scripting attack
the string to be diplayed must be protected
*/
-function h($p_string) { return htmlspecialchars($p_string);}
-function span($p_string,$p_extra='') { return ''.$p_string.' ';}
-function hi($p_string) { return ''.htmlspecialchars($p_string).' ';}
-function hb($p_string) { return ''.htmlspecialchars($p_string).' ';}
-function th($p_string,$p_extra='') { return ''.htmlspecialchars($p_string).' ';}
-function h2info($p_string) { return ''.htmlspecialchars($p_string).' ';}
+function h($p_string)
+{
+ return htmlspecialchars($p_string);
+}
+function span($p_string,$p_extra='')
+{
+ return ''.$p_string.' ';
+}
+function hi($p_string)
+{
+ return ''.htmlspecialchars($p_string).' ';
+}
+function hb($p_string)
+{
+ return ''.htmlspecialchars($p_string).' ';
+}
+function th($p_string,$p_extra='')
+{
+ return ''.htmlspecialchars($p_string).' ';
+}
+function h2info($p_string)
+{
+ return ''.htmlspecialchars($p_string).' ';
+}
/*!\brief surround the string with td
*\param $p_string string to surround by TD
*\param $p_extra extra info (class, style, javascript...)
* \return string surrounded by td
*/
-function td($p_string='',$p_extra=''){ return ''.$p_string.' ';}
-function tr($p_string,$p_extra=''){ return ' '.$p_string.' ';}
+function td($p_string='',$p_extra='')
+{
+ return ''.$p_string.' ';
+}
+function tr($p_string,$p_extra='')
+{
+ return ''.$p_string.' ';
+}
/*!\brief escape correctly php string to javascript */
-function j($p_string) { $a=preg_replace("/\r?\n/", "\\n", addslashes($p_string)); return $a;}
+function j($p_string)
+{
+ $a=preg_replace("/\r?\n/", "\\n", addslashes($p_string));
+ return $a;
+}
/**
* format the number for the CSV export
*@param $p_number number
*/
-function nb($p_number) {
- $r=sprintf('%.2f',$p_number);
- $r=str_replace('.',',',$r);
- return $r;
+function nb($p_number)
+{
+ $r=sprintf('%.2f',$p_number);
+ $r=str_replace('.',',',$r);
+ return $r;
}
/*!
@@ -64,13 +93,15 @@ function nb($p_number) {
* \return nothing
*
*/
-function echo_error ($p_log, $p_line="", $p_message="") {
- echo "ERREUR :".$p_log." ".$p_line." ".$p_message;
- $fdebug=fopen($_ENV['TMP'].DIRECTORY_SEPARATOR."phpcompta_error.log","a+");
- if ($fdebug != null ) {
- fwrite($fdebug,date("Ymd H:i:s").$p_log." ".$p_line." ".$p_message."\n");
- fclose($fdebug);
- }
+function echo_error ($p_log, $p_line="", $p_message="")
+{
+ echo "ERREUR :".$p_log." ".$p_line." ".$p_message;
+ $fdebug=fopen($_ENV['TMP'].DIRECTORY_SEPARATOR."phpcompta_error.log","a+");
+ if ($fdebug != null )
+ {
+ fwrite($fdebug,date("Ymd H:i:s").$p_log." ".$p_line." ".$p_message."\n");
+ fclose($fdebug);
+ }
}
/*!
@@ -83,20 +114,22 @@ function echo_error ($p_log, $p_line="", $p_message="") {
* - > 0 date1 > date2
* - < 0 date1 < date2
*/
-function cmpDate ($p_date,$p_date_oth) {
- date_default_timezone_set ('Europe/Brussels');
+function cmpDate ($p_date,$p_date_oth)
+{
+ date_default_timezone_set ('Europe/Brussels');
- $l_date=isDate($p_date);
- $l2_date=isDate($p_date_oth);
- if ($l_date == null || $l2_date == null ) {
- throw new Exception ("erreur date [$p_date] [$p_date_oth]");
- }
- $l_adate=explode(".",$l_date);
- $l2_adate=explode(".",$l2_date);
- $l_mkdate=mktime(0,0,0,$l_adate[1],$l_adate[0],$l_adate[2]);
- $l2_mkdate=mktime(0,0,0,$l2_adate[1],$l2_adate[0],$l2_adate[2]);
- // si $p_date > $p_date_oth return > 0
- return $l_mkdate-$l2_mkdate;
+ $l_date=isDate($p_date);
+ $l2_date=isDate($p_date_oth);
+ if ($l_date == null || $l2_date == null )
+ {
+ throw new Exception ("erreur date [$p_date] [$p_date_oth]");
+ }
+ $l_adate=explode(".",$l_date);
+ $l2_adate=explode(".",$l2_date);
+ $l_mkdate=mktime(0,0,0,$l_adate[1],$l_adate[0],$l_adate[2]);
+ $l2_mkdate=mktime(0,0,0,$l2_adate[1],$l2_adate[0],$l2_adate[2]);
+ // si $p_date > $p_date_oth return > 0
+ return $l_mkdate-$l2_mkdate;
}
/*!
* \brief check if the argument is a number
@@ -107,12 +140,13 @@ function cmpDate ($p_date,$p_date_oth) {
* - 1 it's a number
* - 0 it is not
*/
-function isNumber(&$p_int) {
- if ( strlen (trim($p_int)) == 0 ) return 0;
- if ( is_numeric($p_int) === true)
- return 1;
- else
- return 0;
+function isNumber(&$p_int)
+{
+ if ( strlen (trim($p_int)) == 0 ) return 0;
+ if ( is_numeric($p_int) === true)
+ return 1;
+ else
+ return 0;
}
@@ -128,27 +162,33 @@ function isNumber(&$p_int) {
*
*/
-function isDate ( $p_date) {
- if ( strlen (trim($p_date)) == 0 ) return null;
- if (! myereg ("^[0-9]{1,2}\.[0-9]{1,2}\.20[0-9]{2}",$p_date) ) {
+function isDate ( $p_date)
+{
+ if ( strlen (trim($p_date)) == 0 ) return null;
+ if (! myereg ("^[0-9]{1,2}\.[0-9]{1,2}\.20[0-9]{2}",$p_date) )
+ {
- return null;
- } else {
- $l_date=explode(".",$p_date);
-
- if ( sizeof ($l_date) != 3 )
- return null;
-
- if ( $l_date[2] > 2020 ) {
- return null;
+ return null;
}
+ else
+ {
+ $l_date=explode(".",$p_date);
- if ( checkdate ($l_date[1],$l_date[0],$l_date[2]) == false) {
- return null;
- }
+ if ( sizeof ($l_date) != 3 )
+ return null;
- }// !ereg
- return $p_date;
+ if ( $l_date[2] > 2020 )
+ {
+ return null;
+ }
+
+ if ( checkdate ($l_date[1],$l_date[0],$l_date[2]) == false)
+ {
+ return null;
+ }
+
+ }// !ereg
+ return $p_date;
}
/*!
* \brief Default page header for each page
@@ -162,49 +202,55 @@ function isDate ( $p_date) {
function html_page_start($p_theme="",$p_script="",$p_script2="")
{
- $cn=new Database();
- if ( $p_theme != "") {
- $Res=$cn->exec_sql("select the_filestyle from theme
- where the_name='".$p_theme."'");
- if (Database::num_row($Res)==0)
- $style="style.css";
- else {
- $s=Database::fetch_array($Res,0);
- $style=$s['the_filestyle'];
+ $cn=new Database();
+ if ( $p_theme != "")
+ {
+ $Res=$cn->exec_sql("select the_filestyle from theme
+ where the_name='".$p_theme."'");
+ if (Database::num_row($Res)==0)
+ $style="style.css";
+ else
+ {
+ $s=Database::fetch_array($Res,0);
+ $style=$s['the_filestyle'];
+ }
}
- }else {
- $style="style.css";
- } // end if
- echo '';
- echo "";
+ else
+ {
+ $style="style.css";
+ } // end if
+ echo '';
+ echo "";
- if ( $p_script2 != "" )
- $p_script2='';
+ if ( $p_script2 != "" )
+ $p_script2='';
- echo "
- PhpCompta
-
-
- ".
- $p_script2. "
- ";
- echo '
-
-
-
-
-';
+ echo "
+ PhpCompta
+
+
+ ".
+ $p_script2. "
+ ";
+ echo '
+
+
+
+
+ ';
- echo "";
- // language
- if ( isset($_SESSION['g_lang'])){
- set_language();
- }
+ echo "";
+// language
+ if ( isset($_SESSION['g_lang']))
+ {
+ set_language();
+ }
- /* If we are on the user_login page */
- if ( basename($_SERVER['PHP_SELF']) == 'user_login.php') {
- return;
- }
+ /* If we are on the user_login page */
+ if ( basename($_SERVER['PHP_SELF']) == 'user_login.php')
+ {
+ return;
+ }
}
/*!
@@ -219,41 +265,46 @@ function html_page_start($p_theme="",$p_script="",$p_script2="")
function html_min_page_start($p_theme="",$p_script="",$p_script2="")
{
- $cn=new Database();
- if ( $p_theme != "") {
- $Res=$cn->exec_sql("select the_filestyle from theme
- where the_name='".$p_theme."'");
- if (Database::num_row($Res)==0)
- $style="style.css";
- else {
- $s=Database::fetch_array($Res,0);
- $style=$s['the_filestyle'];
+ $cn=new Database();
+ if ( $p_theme != "")
+ {
+ $Res=$cn->exec_sql("select the_filestyle from theme
+ where the_name='".$p_theme."'");
+ if (Database::num_row($Res)==0)
+ $style="style.css";
+ else
+ {
+ $s=Database::fetch_array($Res,0);
+ $style=$s['the_filestyle'];
+ }
}
- }else {
- $style="style.css";
- } // end if
- echo '';
- echo "";
+ else
+ {
+ $style="style.css";
+ } // end if
+ echo '';
+ echo "";
- if ( $p_script2 != "" )
- $p_script2='';
+ if ( $p_script2 != "" )
+ $p_script2='';
- echo "
- PhpCompta
-
-
- ".
- $p_script2. "
- ";
- echo '
-';
+ echo "
+ PhpCompta
+
+
+ ".
+ $p_script2. "
+ ";
+ echo '
+ ';
- echo "";
- /* If we are on the user_login page */
- if ( basename($_SERVER['PHP_SELF']) == 'user_login.php') {
- return;
- }
+ echo "";
+ /* If we are on the user_login page */
+ if ( basename($_SERVER['PHP_SELF']) == 'user_login.php')
+ {
+ return;
+ }
}
@@ -263,8 +314,8 @@ function html_min_page_start($p_theme="",$p_script="",$p_script2="")
*/
function html_page_stop()
{
- echo "";
- echo "";
+ echo "";
+ echo "";
}
/*!
* \brief Echo no access and stop
@@ -275,19 +326,19 @@ function html_page_stop()
function NoAccess($js=1)
{
- if ( $js == 1 )
+ if ( $js == 1 )
{
- echo "";
+ echo "";
}
- else
+ else
{
- echo '';
- echo '
'._(' Cette action ne vous est pas autorisée Contactez votre responsable').' ';
- echo '';
+ echo '';
+ echo '
'._(' Cette action ne vous est pas autorisée Contactez votre responsable').' ';
+ echo '';
}
- exit -1;
+ exit -1;
}
/*!
* \brief Fix the problem with the quote char for the database
@@ -297,12 +348,12 @@ function NoAccess($js=1)
*/
function FormatString($p_string)
{
- $p_string=trim($p_string);
- if (strlen($p_string) == 0 ) return null;
- $p_string=str_replace("\'","'",$p_string);
- $p_string=str_replace("''","'",$p_string);
- $p_string=str_replace("'","\'",$p_string);
- return $p_string;
+ $p_string=trim($p_string);
+ if (strlen($p_string) == 0 ) return null;
+ $p_string=str_replace("\'","'",$p_string);
+ $p_string=str_replace("''","'",$p_string);
+ $p_string=str_replace("'","\'",$p_string);
+ return $p_string;
}
/*!
@@ -321,50 +372,57 @@ function FormatString($p_string)
function ShowItem($p_array,$p_dir='V',$class="mtitle",$class_ref="mtitle",$default="",$p_extra="")
{
- $ret="";
- // direction Vertical
- if ( $p_dir == 'V') {
- foreach ($p_array as $all=>$href){
- $javascript=(isset ($href[4]))?$href[4]:"";
- $title="";
- $set="XX";
- if ( isset ($href[2] ))
- $title=$href[2];
- if ( isset($href[3] ))
- $set=$href[3];
+ $ret="";
+ // direction Vertical
+ if ( $p_dir == 'V')
+ {
+ foreach ($p_array as $all=>$href)
+ {
+ $javascript=(isset ($href[4]))?$href[4]:"";
+ $title="";
+ $set="XX";
+ if ( isset ($href[2] ))
+ $title=$href[2];
+ if ( isset($href[3] ))
+ $set=$href[3];
- if ( $set == $default )
- $ret.=''.$href[1].' ';
- else
- $ret.=''.$href[1].' ';
+ if ( $set == $default )
+ $ret.=''.$href[1].' ';
+ else
+ $ret.=''.$href[1].' ';
+ }
}
- }
- //direction Horizontal
- else if ( $p_dir == 'H' ) {
+ //direction Horizontal
+ else if ( $p_dir == 'H' )
+ {
- $ret.="";
- foreach ($p_array as $all=>$href){
- $title="";
- $javascript=(isset ($href[4]))?$href[4]:"";
-
- $set="A";
- if ( isset ($href[2] ))
- $title=$href[2];
+ $ret.=" ";
+ foreach ($p_array as $all=>$href)
+ {
+ $title="";
+ $javascript=(isset ($href[4]))?$href[4]:"";
- if ( isset($href[3]))
- $set=$href[3];
+ $set="A";
+ if ( isset ($href[2] ))
+ $title=$href[2];
- if ( $default=== $href[0]||$set===$default ) {
- $ret.=''.$href[1].' ';
- } else {
- $ret.=''.$href[1].' ';
- }
+ if ( isset($href[3]))
+ $set=$href[3];
+ if ( $default=== $href[0]||$set===$default )
+ {
+ $ret.=''.$href[1].' ';
+ }
+ else
+ {
+ $ret.=''.$href[1].' ';
+ }
+
+ }
+ $ret.=" ";
}
- $ret.="";
- }
$ret.="
";
- return $ret;
+ return $ret;
}
/*!
* \brief warns
@@ -377,7 +435,7 @@ function ShowItem($p_array,$p_dir='V',$class="mtitle",$class_ref="mtitle",$defau
*/
function echo_warning($p_string)
{
- echo ''.$p_string." ";
+ echo ''.$p_string." ";
}
/*!
* \brief Show the periode which found thanks its id
@@ -389,12 +447,13 @@ function echo_warning($p_string)
*
* \return: string
*/
-function getPeriodeName($p_cn,$p_id,$pos='p_start') {
- if ( $pos != 'p_start' and
- $pos != 'p_end')
- echo_error('ac_common.php'."-".__LINE__.' UNDEFINED PERIODE');
- $ret=$p_cn->get_value("select to_char($pos,'Mon YYYY') as t from parm_periode where p_id=$p_id");
- return $ret;
+function getPeriodeName($p_cn,$p_id,$pos='p_start')
+{
+ if ( $pos != 'p_start' and
+ $pos != 'p_end')
+ echo_error('ac_common.php'."-".__LINE__.' UNDEFINED PERIODE');
+ $ret=$p_cn->get_value("select to_char($pos,'Mon YYYY') as t from parm_periode where p_id=$p_id");
+ return $ret;
}
@@ -408,23 +467,25 @@ function getPeriodeName($p_cn,$p_id,$pos='p_start') {
* \return:
* parm_periode.p_id
*/
-function getPeriodeFromMonth($p_cn,$p_date) {
- $R=$p_cn->get_value("select p_id from parm_periode where
- to_char(p_start,'DD.MM.YYYY') = '01.$p_date'");
- if ( $R == "" )
- return -1;
- return $R;
+function getPeriodeFromMonth($p_cn,$p_date)
+{
+ $R=$p_cn->get_value("select p_id from parm_periode where
+ to_char(p_start,'DD.MM.YYYY') = '01.$p_date'");
+ if ( $R == "" )
+ return -1;
+ return $R;
}
/*!\brief Decode the html for the widegt richtext and remove newline
*\param $p_html string to decode
* \return the html code without new line
*/
-function Decode($p_html){
- $p_html=str_replace('%0D','',$p_html);
- $p_html=str_replace('%0A','',$p_html);
- $p_html=urldecode($p_html);
- return $p_html;
+function Decode($p_html)
+{
+ $p_html=str_replace('%0D','',$p_html);
+ $p_html=str_replace('%0A','',$p_html);
+ $p_html=urldecode($p_html);
+ return $p_html;
}
/*!\brief Create the condition to filter on the j_tech_per
* thanks a from and to date.
@@ -438,35 +499,35 @@ function Decode($p_html){
function sql_filter_per($p_cn,$p_from,$p_to,$p_form='p_id',$p_field='jr_tech_per')
{
- if ( $p_form != 'p_id' &&
- $p_form != 'date' )
+ if ( $p_form != 'p_id' &&
+ $p_form != 'date' )
{
- echo_error (__FILE__,__LINE__,'Mauvais parametres ');
- exit(-1);
+ echo_error (__FILE__,__LINE__,'Mauvais parametres ');
+ exit(-1);
}
- if ( $p_form == 'p_id' )
+ if ( $p_form == 'p_id' )
{
- // retrieve the date
- $pPeriode=new Periode($p_cn);
- $a_start=$pPeriode->get_date_limit($p_from);
- $a_end=$pPeriode->get_date_limit($p_to);
- if ( $a_start == null || $a_end == null )
- throw new Exception(__FILE__.__LINE__.'Attention periode '.
- ' non trouvee periode p_from='.$p_from.
- 'p_to_periode = '.$p_to);
+ // retrieve the date
+ $pPeriode=new Periode($p_cn);
+ $a_start=$pPeriode->get_date_limit($p_from);
+ $a_end=$pPeriode->get_date_limit($p_to);
+ if ( $a_start == null || $a_end == null )
+ throw new Exception(__FILE__.__LINE__.'Attention periode '.
+ ' non trouvee periode p_from='.$p_from.
+ 'p_to_periode = '.$p_to);
- $p_from=$a_start['p_start'];
- $p_to=$a_end['p_end'];
+ $p_from=$a_start['p_start'];
+ $p_to=$a_end['p_end'];
}
- if ( $p_from == $p_to )
- $periode=" $p_field = (select p_id from parm_periode ".
- " where ".
- " p_start = to_date('$p_from','DD.MM.YYYY')) ";
- else
- $periode = "$p_field in (select p_id from parm_periode ".
- " where p_start >= to_date('$p_from','DD.MM.YYYY') and p_end <= to_date('$p_to','DD.MM.YYYY')) ";
- return $periode;
+ if ( $p_from == $p_to )
+ $periode=" $p_field = (select p_id from parm_periode ".
+ " where ".
+ " p_start = to_date('$p_from','DD.MM.YYYY')) ";
+ else
+ $periode = "$p_field in (select p_id from parm_periode ".
+ " where p_start >= to_date('$p_from','DD.MM.YYYY') and p_end <= to_date('$p_to','DD.MM.YYYY')) ";
+ return $periode;
}
/*!\brief alert in javascript
@@ -477,39 +538,42 @@ function sql_filter_per($p_cn,$p_from,$p_to,$p_form='p_id',$p_field='jr_tech_per
*/
function alert($p_msg,$buffer=false)
{
- $r= '';
+ $r= '';
- if ($buffer) return $r;
- echo $r;
+ if ($buffer) return $r;
+ echo $r;
}
/**
*@brief set the lang thanks the _SESSION['g_lang'] var.
*/
-function set_language() {
- $dir="";
- // set differently the language depending of the operating system
- if( what_os() == 1 ) {
- $dir=setlocale(LC_MESSAGES,$_SESSION['g_lang']);
- if ( $dir == "") {
- $g_lang='fr_FR.utf8';
- $dir=setlocale(LC_MESSAGES,$g_lang);
- echo ''.$_SESSION['g_lang'].' domaine non supporté';
- }
- bindtextdomain('messages','./lang');
- textdomain('messages');
- bind_textdomain_codeset('messages','UTF8');
-
- return;
- }
- // for windows
- putenv('LANG='.$_SESSION['g_lang']);
- $dir=setlocale(LC_ALL,$_SESSION['g_lang']);
- bindtextdomain('messages','.\\lang');
- textdomain('messages');
- bind_textdomain_codeset('messages','UTF8');
+function set_language()
+{
+ $dir="";
+ // set differently the language depending of the operating system
+ if( what_os() == 1 )
+ {
+ $dir=setlocale(LC_MESSAGES,$_SESSION['g_lang']);
+ if ( $dir == "")
+ {
+ $g_lang='fr_FR.utf8';
+ $dir=setlocale(LC_MESSAGES,$g_lang);
+ echo ''.$_SESSION['g_lang'].' domaine non supporté';
+ }
+ bindtextdomain('messages','./lang');
+ textdomain('messages');
+ bind_textdomain_codeset('messages','UTF8');
+
+ return;
+ }
+ // for windows
+ putenv('LANG='.$_SESSION['g_lang']);
+ $dir=setlocale(LC_ALL,$_SESSION['g_lang']);
+ bindtextdomain('messages','.\\lang');
+ textdomain('messages');
+ bind_textdomain_codeset('messages','UTF8');
}
/**
*@brief try to determine on what os you are running the pĥpcompte
@@ -518,37 +582,43 @@ function set_language() {
* 0 it is a windows
* 1 it is a Unix like
*/
-function what_os() {
- $inc_path=get_include_path();
-
- if ( strpos($inc_path,";") != 0 ) {
- $os=0; /* $os is 0 for windoz */
- } else {
- $os=1; /* $os is 1 for unix */
- }
- return $os;
+function what_os()
+{
+ $inc_path=get_include_path();
+
+ if ( strpos($inc_path,";") != 0 )
+ {
+ $os=0; /* $os is 0 for windoz */
+ }
+ else
+ {
+ $os=1; /* $os is 1 for unix */
+ }
+ return $os;
}
- /**
- *@brief shrink the date, make a date shorter for the printing
- *@param $p_date format DD.MM.YYYY
- *@return date in the format DDMMYY (size = 13 mm in arial 8)
- */
-function shrink_date ($p_date) {
+/**
+ *@brief shrink the date, make a date shorter for the printing
+ *@param $p_date format DD.MM.YYYY
+ *@return date in the format DDMMYY (size = 13 mm in arial 8)
+ */
+function shrink_date ($p_date)
+{
$date=str_replace('.','',$p_date);
$str_date=substr($date,0,4).substr($date,6,2);
return $str_date;
}
- /**
- *@brief format the date, when taken from the database the format
- * is MM-DD-YYYY
- *@param $p_date format YYYY-MM-DD
- *@return date in the format DD.MM.YYYY
- */
-function format_date ($p_date) {
- $date=explode('-',$p_date);
- if ( count($date) != 3) return $p_date;
- $str_date=$date[2].'.'.$date[1].'.'.$date[0];
- return $str_date;
+/**
+ *@brief format the date, when taken from the database the format
+ * is MM-DD-YYYY
+ *@param $p_date format YYYY-MM-DD
+ *@return date in the format DD.MM.YYYY
+ */
+function format_date ($p_date)
+{
+ $date=explode('-',$p_date);
+ if ( count($date) != 3) return $p_date;
+ $str_date=$date[2].'.'.$date[1].'.'.$date[0];
+ return $str_date;
}
/**
*@brief ereg is not supported from the version 5.3 and is marked as
@@ -559,31 +629,36 @@ function format_date ($p_date) {
*@return
*@see
*/
-function myereg($p_pattern,$p_string,&$p_array=null) {
- $version=phpversion();
- if ( substr($version,0,3) == '5.2' ) {
- /* mimic old ereg */
- return ereg($p_pattern,$p_string,$p_array);
- } else {
- /* use the new preg_match */
- /**
- *@todo ereg are obsolete from the version 5.3.0
- * we have to emulate it
- */
- /* $a=preg_match_all($p_pattern,$p_string,$p_array);
- if ( $a == 0 ) return false;
- return true;*/
- $a=@ereg($p_pattern,$p_string,$p_array);
- return $a;
- }
+function myereg($p_pattern,$p_string,&$p_array=null)
+{
+ $version=phpversion();
+ if ( substr($version,0,3) == '5.2' )
+ {
+ /* mimic old ereg */
+ return ereg($p_pattern,$p_string,$p_array);
+ }
+ else
+ {
+ /* use the new preg_match */
+ /**
+ *@todo ereg are obsolete from the version 5.3.0
+ * we have to emulate it
+ */
+ /* $a=preg_match_all($p_pattern,$p_string,$p_array);
+ if ( $a == 0 ) return false;
+ return true;*/
+ $a=@ereg($p_pattern,$p_string,$p_array);
+ return $a;
+ }
}
/**
*@brief remove the quote or double quote them
*@param $q string
*@return string correctly quoted
*/
-function sql_string($q) {
- $ret=str_replace("'","''",$q);
- return $ret;
+function sql_string($q)
+{
+ $ret=str_replace("'","''",$q);
+ return $ret;
}
?>
diff --git a/include/action.common.inc.php b/include/action.common.inc.php
index e57e4c1ca..0caff02b1 100644
--- a/include/action.common.inc.php
+++ b/include/action.common.inc.php
@@ -38,36 +38,40 @@ echo $pop_tva->input();
$supl_hidden='';
if( isset($_REQUEST['sc']))
- $supl_hidden.=HtmlInput::hidden('sc',$_REQUEST['sc']);
+ $supl_hidden.=HtmlInput::hidden('sc',$_REQUEST['sc']);
if( isset($_REQUEST['f_id']))
- $supl_hidden.=HtmlInput::hidden('f_id',$_REQUEST['f_id']);
+ $supl_hidden.=HtmlInput::hidden('f_id',$_REQUEST['f_id']);
if( isset($_REQUEST['sb']))
- $supl_hidden.=HtmlInput::hidden('sb',$_REQUEST['sb']);
+ $supl_hidden.=HtmlInput::hidden('sb',$_REQUEST['sb']);
/*--------------------------------------------------------------------------- */
/* We ask to generate the document */
/*--------------------------------------------------------------------------- */
-if ( isset($_POST['generate'])){
- $act=new Action($cn);
- $act->fromArray($_POST);
- if ($act->ag_id == 0 ) {
- $act->save();
- $ag_id=$act->ag_id;
- } else {
- $act->Update();
- }
- $act->generate_document($_POST['doc_mod']);
- $sub_action='detail';
+if ( isset($_POST['generate']))
+{
+ $act=new Action($cn);
+ $act->fromArray($_POST);
+ if ($act->ag_id == 0 )
+ {
+ $act->save();
+ $ag_id=$act->ag_id;
+ }
+ else
+ {
+ $act->Update();
+ }
+ $act->generate_document($_POST['doc_mod']);
+ $sub_action='detail';
}
/* for delete */
if ( isset($_POST['delete'] )) $sub_action='delete';
if ( $sub_action == "" ) $sub_action="list";
// if correction is asked go to directly to add_action
-if (isset($_POST['corr'] ))
+if (isset($_POST['corr'] ))
{
- $ag_comment=urldecode($_POST['ag_comment']);
- $sub_action="add_action";
+ $ag_comment=urldecode($_POST['ag_comment']);
+ $sub_action="add_action";
}
// if this page is called from another menu (customer, supplier,...)
// a button back is added
@@ -75,304 +79,328 @@ if (isset($_POST['corr'] ))
//----------------------------------------------------------------------
// Update the detail
-// Add a new action related to this one or update
+// Add a new action related to this one or update
//----------------------------------------------------------------------
if ( $sub_action=="update" )
{
- // Update the modification
- if ( isset($_POST['save']))
+ // Update the modification
+ if ( isset($_POST['save']))
{
- $act2=new Action($cn);
- $act2->fromArray($_POST );
+ $act2=new Action($cn);
+ $act2->fromArray($_POST );
- if ( $act2->Update() == false ) {
- $sub_action="detail";
- }
- else
- {
- ShowActionList($cn,$base);
- $url="?$base&sa=detail&ag_id=".$act2->ag_id.'&'.dossier::get();
- echo ''.hb(_('Action sauvée').' : '.$act2->ag_ref).'
';
- }
+ if ( $act2->Update() == false )
+ {
+ $sub_action="detail";
+ }
+ else
+ {
+ ShowActionList($cn,$base);
+ $url="?$base&sa=detail&ag_id=".$act2->ag_id.'&'.dossier::get();
+ echo ''.hb(_('Action sauvée').' : '.$act2->ag_ref).'
';
+ }
}
- //----------------------------------------------------------------------
- // Add a related action
- //----------------------------------------------------------------------
- if ( isset ($_POST['add_action_here']) )
+ //----------------------------------------------------------------------
+ // Add a related action
+ //----------------------------------------------------------------------
+ if ( isset ($_POST['add_action_here']) )
{
- $act=new Action($cn);
+ $act=new Action($cn);
-
- //----------------------------------------
- // puis comme ajout normal (copier / coller )
- $act->fromArray($_POST);
- $act->ag_id=0;
- $act->d_id=0;
- $act->ag_ref_ag_id=$_POST['ag_id'];
- echo '';
-
}
-
-
+
+
}
//--------------------------------------------------------------------------------
// Show the detail of an action
// permit the update
if ( $sub_action=='detail' )
{
- echo '';
- $act=new Action($cn);
- $act->ag_id=$ag_id;
- echo $act->get();
- $act->ag_comment=Decode($act->ag_comment);
- echo '
';
- echo $supl_hidden;
- echo HtmlInput::hidden('p_action',$_REQUEST['p_action']);
- echo dossier::hidden();
- echo JS_LEDGER;
- echo $act->Display('UPD',false,$base,$retour);
- echo ' ';
- echo ' ';
- echo HtmlInput::submit("save","Sauve");
- echo HtmlInput::submit("add_action_here",_("Ajoute une action à celle-ci"));
- echo HtmlInput::submit("delete",_("Efface cette action")," onclick=\"return confirm("._('Vous confirmez l\'effacement').")\" )");
- echo ' ';
- echo '';
+ echo '';
+ $act=new Action($cn);
+ $act->ag_id=$ag_id;
+ echo $act->get();
+ $act->ag_comment=Decode($act->ag_comment);
+ echo '
';
+ echo $supl_hidden;
+ echo HtmlInput::hidden('p_action',$_REQUEST['p_action']);
+ echo dossier::hidden();
+ echo JS_LEDGER;
+ echo $act->Display('UPD',false,$base,$retour);
+ echo ' ';
+ echo ' ';
+ echo HtmlInput::submit("save","Sauve");
+ echo HtmlInput::submit("add_action_here",_("Ajoute une action à celle-ci"));
+ echo HtmlInput::submit("delete",_("Efface cette action")," onclick=\"return confirm("._('Vous confirmez l\'effacement').")\" )");
+ echo ' ';
+ echo '';
}
//-------------------------------------------------------------------------------
// Delete an action
-if ( $sub_action == 'delete' )
+if ( $sub_action == 'delete' )
{
- // confirmed
- $cn->start();
- $act=new Action($cn);
- $act->ag_id=$_REQUEST['ag_id'];
- $act->get();
- $act->remove();
- $sub_action="list";
- $cn->commit();
- ShowActionList($cn,$base);
- if ( isset( $act->ag_ref) )
- echo hb(_('Action ').$act->ag_ref._(' effacée'));
- exit();
+ // confirmed
+ $cn->start();
+ $act=new Action($cn);
+ $act->ag_id=$_REQUEST['ag_id'];
+ $act->get();
+ $act->remove();
+ $sub_action="list";
+ $cn->commit();
+ ShowActionList($cn,$base);
+ if ( isset( $act->ag_ref) )
+ echo hb(_('Action ').$act->ag_ref._(' effacée'));
+ exit();
}
//--------------------------------------------------------------------------------
// Show a list of the action
-if ( $sub_action == "list" ) {
- ShowActionList($cn,$base);
+if ( $sub_action == "list" )
+{
+ ShowActionList($cn,$base);
}
//--------------------------------------------------------------------------------
// Add an action
-if ( $sub_action == "add_action" )
+if ( $sub_action == "add_action" )
{
- $act=new Action($cn);
- $act->fromArray($_POST );
- $act->ag_id=0;
- $act->d_id=0;
- echo '';
}
//--------------------------------------------------------------------------------
// Save Action
// Stage 2 : Save the action + Files and generate eventually a document
//--------------------------------------------------------------------------------
-if ( $sub_action == "save_action_st2" )
+if ( $sub_action == "save_action_st2" )
{
- $act=new Action($cn);
- $act->fromArray($_POST);
- $act->d_id=0;
- $act->ag_ref_ag_id=(isset($_POST['ag_ref_ag_id']))?$_POST['ag_ref_ag_id']:0;
- $act->md_id=(isset($_POST['gen_doc']))?$_POST['gen_doc']:0;
+ $act=new Action($cn);
+ $act->fromArray($_POST);
+ $act->d_id=0;
+ $act->ag_ref_ag_id=(isset($_POST['ag_ref_ag_id']))?$_POST['ag_ref_ag_id']:0;
+ $act->md_id=(isset($_POST['gen_doc']))?$_POST['gen_doc']:0;
- // insert into action_gestion
- echo $act->save();
- ShowActionList($cn,$base);
- $url="?$base&sa=detail&ag_id=".$act->ag_id.'&'.dossier::get();
- echo ''.hb('Action Sauvée : '.$act->ag_ref).'
';
+ // insert into action_gestion
+ echo $act->save();
+ ShowActionList($cn,$base);
+ $url="?$base&sa=detail&ag_id=".$act->ag_id.'&'.dossier::get();
+ echo ''.hb('Action Sauvée : '.$act->ag_ref).'
';
}
//---------------------------------------------------------------------
function ShowActionList($cn,$p_base)
{
- // show the search menu
- ?>
-
-
-
- =_('Recherche avancée')?>
-
-
-
+
+
+
+ =_('Recherche avancée')?>
+
+
+ get_quick_code());
- }
- if( isset($_REQUEST['sb']))
- $supl_hidden.=HtmlInput::hidden('sb',$_REQUEST['sb']);
+ $supl_hidden='';
+ if( isset($_REQUEST['sc']))
+ $supl_hidden.=HtmlInput::hidden('sc',$_REQUEST['sc']);
+ if( isset($_REQUEST['f_id']))
+ {
+ $supl_hidden.=HtmlInput::hidden('f_id',$_REQUEST['f_id']);
+ $f=new Fiche($cn,$_REQUEST['f_id']);
+ $supl_hidden.=HtmlInput::hidden('qcode_dest',$f->get_quick_code());
+ }
+ if( isset($_REQUEST['sb']))
+ $supl_hidden.=HtmlInput::hidden('sb',$_REQUEST['sb']);
- echo JS_LEDGER;
- $w=new ICard();
- $w->name='qcode';
- $w->value=$qcode;
- $w->extra="all";
- $w->typecard='all';
- $w->jrn=0;
- $w->table=0;
- $list=$cn->make_list("select fd_id from fiche_def where frd_id in (4,8,9,14,15,16,25)");
- $w->extra=$list;
- echo _('Fiche').' :'.$w->search().$w->input().' ';
- printf (_('Titre ou référence').': ',
- $a);
- echo ' ';
+ echo JS_LEDGER;
+ $w=new ICard();
+ $w->name='qcode';
+ $w->value=$qcode;
+ $w->extra="all";
+ $w->typecard='all';
+ $w->jrn=0;
+ $w->table=0;
+ $list=$cn->make_list("select fd_id from fiche_def where frd_id in (4,8,9,14,15,16,25)");
+ $w->extra=$list;
+ echo _('Fiche').' :'.$w->search().$w->input().' ';
+ printf (_('Titre ou référence').': ',
+ $a);
+ echo ' ';
- /* type of documents */
- $type_doc=new ISelect ('tdoc');
- $aTDoc=$cn->make_array('select dt_id,dt_value from document_type');
- $aTDoc[]=array('value'=>'-1','label'=>_('Tous les types'));
- $type_doc->value=$aTDoc;
- $type_doc->selected=(isset ($_GET['tdoc']))?$_GET['tdoc']:-1;
- echo 'Type de document';
- echo $type_doc->input();
- echo ' ';
+ /* type of documents */
+ $type_doc=new ISelect ('tdoc');
+ $aTDoc=$cn->make_array('select dt_id,dt_value from document_type');
+ $aTDoc[]=array('value'=>'-1','label'=>_('Tous les types'));
+ $type_doc->value=$aTDoc;
+ $type_doc->selected=(isset ($_GET['tdoc']))?$_GET['tdoc']:-1;
+ echo 'Type de document';
+ echo $type_doc->input();
+ echo ' ';
- $see_all=new ICheckBox('see_all');
- $see_all->selected= (isset($_REQUEST['see_all']))?true:false;
- echo _('les actions fermées aussi:').$see_all->input().' ';
- $my_action=new ICheckBox('all_action');
- $my_action->selected= (isset($_REQUEST['all_action']))?true:false;
- echo _('affecté à d\'autre:').$my_action->input().' ';
-?>
-
-
-
-=$supl_hidden?>
-
+ $see_all=new ICheckBox('see_all');
+ $see_all->selected= (isset($_REQUEST['see_all']))?true:false;
+ echo _('les actions fermées aussi:').$see_all->input().' ';
+ $my_action=new ICheckBox('all_action');
+ $my_action->selected= (isset($_REQUEST['all_action']))?true:false;
+ echo _('affecté à d\'autre:').$my_action->input().' ';
+ ?>
+
+
+
+ =$supl_hidden?>
+
-
-
+
+
-
-
-
-
- ">
-
-
-=$supl_hidden?>
-
+
+
+
+
+ ">
+
+
+ =$supl_hidden?>
+
-
+ }
+ catch (error)
+ {
+ alert(error);
+ }
+
+ }
+
+
-
-
+
+
-get_by_qcode($_REQUEST['qcode']);
- // if quick code not found then nothing
- if ( $fiche->id == 0 )
- $str=' and false ';
- else
- $str=" and (f_id_dest= ".$fiche->id." ) ";
- }
- }
- if (isset($_GET['tdoc']) && $_GET['tdoc'] != -1 ){
- $query .= ' and dt_id = '.Formatstring($_GET['tdoc']);
- }
- if ( ! isset($_REQUEST['see_all'])) $query .= ' and ag_state in (2,3) ';
- if ( ! isset($_REQUEST['all_action'])) $query .= " and (ag_owner='".$_SESSION['g_user']."' or ag_dest='".$_SESSION['g_user']."')";
- $r=$act->myList($p_base,"",$query.$str);
- echo $r;
- }
+ $fiche=new Fiche($cn);
+ $fiche->get_by_qcode($_REQUEST['qcode']);
+ // if quick code not found then nothing
+ if ( $fiche->id == 0 )
+ $str=' and false ';
+ else
+ $str=" and (f_id_dest= ".$fiche->id." ) ";
+ }
+ }
+ if (isset($_GET['tdoc']) && $_GET['tdoc'] != -1 )
+ {
+ $query .= ' and dt_id = '.Formatstring($_GET['tdoc']);
+ }
+ if ( ! isset($_REQUEST['see_all'])) $query .= ' and ag_state in (2,3) ';
+ if ( ! isset($_REQUEST['all_action'])) $query .= " and (ag_owner='".$_SESSION['g_user']."' or ag_dest='".$_SESSION['g_user']."')";
+ $r=$act->myList($p_base,"",$query.$str);
+ echo $r;
+}
diff --git a/include/action.inc.php b/include/action.inc.php
index f6a46fcbe..c1da19ffc 100644
--- a/include/action.inc.php
+++ b/include/action.inc.php
@@ -1,4 +1,4 @@
-can_request(GECUST);
$href=basename($_SERVER['PHP_SELF']);
// by default open liste
-if ( $low_action == "" )
- $low_action="list";
+if ( $low_action == "" )
+ $low_action="list";
//-----------------------------------------------------
@@ -68,16 +68,17 @@ if ( $low_action == "" )
//-----------------------------------------------------
if ( isset($_POST['delete'] ) )
{
- if ( $User->check_action(FICADD) == 0 ) {
- alert('Vous ne pouvez pas enlever de fiche');
- return;
- }
+ if ( $User->check_action(FICADD) == 0 )
+ {
+ alert('Vous ne pouvez pas enlever de fiche');
+ return;
+ }
- $f_id=$_REQUEST['f_id'];
+ $f_id=$_REQUEST['f_id'];
- $fiche=new Customer($cn,$f_id);
- $fiche->remove();
- $low_action="list";
+ $fiche=new Customer($cn,$f_id);
+ $fiche->remove();
+ $low_action="list";
}
@@ -87,61 +88,62 @@ if ( isset($_POST['delete'] ) )
if ( $low_action == "list" )
{
-?>
-
-
-
-',
- $a);
- $sel_card=new ISelect('cat');
- $sel_card->value=$cn->make_array('select fd_id, fd_label from fiche_def '.
- ' where frd_id='.FICHE_TYPE_ADM_TAX.
- ' order by fd_label ',1);
- $sel_card->selected=(isset($_GET['cat']))?$_GET['cat']:-1;
- $sel_card->javascript=' onchange="submit(this);"';
- echo _('Catégorie :').$sel_card->input();
+ ?>
+
+
+
+ ',
+ $a);
+ $sel_card=new ISelect('cat');
+ $sel_card->value=$cn->make_array('select fd_id, fd_label from fiche_def '.
+ ' where frd_id='.FICHE_TYPE_ADM_TAX.
+ ' order by fd_label ',1);
+ $sel_card->selected=(isset($_GET['cat']))?$_GET['cat']:-1;
+ $sel_card->javascript=' onchange="submit(this);"';
+ echo _('Catégorie :').$sel_card->input();
-?>
-
-
-
-
-
+
+
+
+
+ ';
- echo $adm->Summary($search,'adm',$sql);
+ echo '
';
+ echo $adm->Summary($search,'adm',$sql);
- echo ' ';
- echo ' ';
- echo ' ';
- /* Add button */
- $f_add_button=new IButton('add_card');
- $f_add_button->label=_('Créer une nouvelle fiche');
- $f_add_button->set_attribute('ipopup','ipop_newcard');
- $f_add_button->set_attribute('win_refresh','yes');
+ echo ' ';
+ echo ' ';
+ echo ' ';
+ /* Add button */
+ $f_add_button=new IButton('add_card');
+ $f_add_button->label=_('Créer une nouvelle fiche');
+ $f_add_button->set_attribute('ipopup','ipop_newcard');
+ $f_add_button->set_attribute('win_refresh','yes');
- $f_add_button->set_attribute('type_cat',FICHE_TYPE_ADM_TAX);
- $f_add_button->javascript=" select_card_type(this);";
- echo $f_add_button->input();
+ $f_add_button->set_attribute('type_cat',FICHE_TYPE_ADM_TAX);
+ $f_add_button->javascript=" select_card_type(this);";
+ echo $f_add_button->input();
- $f_cat_button=new IButton('add_cat');
- $f_cat_button->set_attribute('ipopup','ipop_cat');
- $f_cat_button->set_attribute('type_cat',FICHE_TYPE_ADM_TAX);
- $f_cat_button->label=_('Ajout d\'une catégorie');
- $f_cat_button->javascript='add_category(this)';
- echo $f_cat_button->input();
- echo '
';
- echo '
';
+ $f_cat_button=new IButton('add_cat');
+ $f_cat_button->set_attribute('ipopup','ipop_cat');
+ $f_cat_button->set_attribute('type_cat',FICHE_TYPE_ADM_TAX);
+ $f_cat_button->label=_('Ajout d\'une catégorie');
+ $f_cat_button->javascript='add_category(this)';
+ echo $f_cat_button->input();
+ echo ' ';
+ echo '
';
}
@@ -149,31 +151,33 @@ if ( $low_action == "list" )
* Detail for a card, Suivi, Contact, Operation,... *
* cc stands for customer card
*----------------------------------------------------------------------*/
-if ( $low_action == 'detail') {
- /* Menu */
- require_once('adm_card.inc.php');
- exit();
+if ( $low_action == 'detail')
+{
+ /* Menu */
+ require_once('adm_card.inc.php');
+ exit();
}
if ( $low_action=="insert" )
{
- /* security : check if user can add card */
- if ( $User->check_action(FICADD) == 0 ) {
- alert('Vous ne pouvez pas ajouter de fiche');
- return;
- }
+ /* security : check if user can add card */
+ if ( $User->check_action(FICADD) == 0 )
+ {
+ alert('Vous ne pouvez pas ajouter de fiche');
+ return;
+ }
- $customer=new Customer($cn);
- $customer->Save($_REQUEST['fd_id']);
- echo '';
- echo "
";
- echo $customer->Display(true);
- echo "
";
- $retour=new IAction();
- $retour->label="Retour";
- $retour->value="?p_action=adm&".dossier::get();
- echo $retour->input();
- echo '
';
+ $customer=new Customer($cn);
+ $customer->Save($_REQUEST['fd_id']);
+ echo '';
+ echo "
";
+ echo $customer->Display(true);
+ echo "
";
+ $retour=new IAction();
+ $retour->label="Retour";
+ $retour->value="?p_action=adm&".dossier::get();
+ echo $retour->input();
+ echo '
';
}
diff --git a/include/adm_card.inc.php b/include/adm_card.inc.php
index a4ac46159..9cf2df5ec 100644
--- a/include/adm_card.inc.php
+++ b/include/adm_card.inc.php
@@ -31,41 +31,42 @@ require_once('class_ipopup.php');
echo ICard::ipopup('ipopcard');
- /* $sub_action = sb = detail */
- /* $cn database conx */
+/* $sub_action = sb = detail */
+/* $cn database conx */
$return=new IAction();
$return->name='retour';
$return->label='Retour';
$return->value='?p_action=adm&'.$str_dossier;
$root="?p_action=adm&sb=detail&f_id=".$_REQUEST["f_id"].'&'.$str_dossier;
$ss_action=( isset ($_REQUEST['sc'] ))? $_REQUEST['sc']: '';
-switch ($ss_action) {
+switch ($ss_action)
+{
case 'dc':
- $def=1;
- break;
+ $def=1;
+ break;
case 'sv': /* all the actions (mail,meeting...) */
- $def=2;
- break;
+ $def=2;
+ break;
case 'cn':
- $def=3;
- break;
+ $def=3;
+ break;
case 'op':
- $def=4;
- break;
+ $def=4;
+ break;
default:
- $def=1;
- $ss_action='dc';
+ $def=1;
+ $ss_action='dc';
}
$f=new Fiche($cn,$_REQUEST['f_id']);
echo '';
echo '';
echo '
'.$f->get_quick_code()." ".$f->strAttribut(ATTR_DEF_NAME).' ';
@@ -77,49 +78,53 @@ echo '';
//---------------------------------------------------------------------------
if ( $ss_action == 'dc' )
{
- require_once('detail_adm.inc.php');
+ require_once('detail_adm.inc.php');
}
//---------------------------------------------------------------------------
// Follow up : mail, bons de commande, livraison, rendez-vous...
//---------------------------------------------------------------------------
-if ( $ss_action == 'sv' ) {
- require_once('suivi_adm.inc.php');
+if ( $ss_action == 'sv' )
+{
+ require_once('suivi_adm.inc.php');
}
/*----------------------------------------------------------------------
* Operation all the operation of this customer
*
* ----------------------------------------------------------------------*/
-if ( $ss_action == 'op') {
- require_once('operation_adm.inc.php');
+if ( $ss_action == 'op')
+{
+ require_once('operation_adm.inc.php');
}
/*----------------------------------------------------------------------
* All the contact
*
*----------------------------------------------------------------------*/
-if ( $ss_action == 'cn') {
- echo '';
- echo dossier::hidden();
- $f=new Fiche($cn,$_REQUEST['f_id']);
- $contact=new Contact($cn);
- $contact->company=$f->get_quick_code();
- echo $contact->summary("");
+if ( $ss_action == 'cn')
+{
+ echo '
';
+ echo dossier::hidden();
+ $f=new Fiche($cn,$_REQUEST['f_id']);
+ $contact=new Contact($cn);
+ $contact->company=$f->get_quick_code();
+ echo $contact->summary("");
- $sql=' select fd_id from fiche_def where frd_id='.FICHE_TYPE_CONTACT;
- $filter=$cn->make_list($sql);
- if ( empty ($filter)) {
- echo '';
- echo _("Vous devez aller dans fiche et créer une catégorie pour les contacts");
- echo ' ';
- exit();
- }
- /* Add button */
- $f_add_button=new IButton('add_card');
- $f_add_button->label=_('Créer une nouvelle fiche');
- $f_add_button->set_attribute('ipopup','ipopcard');
-
- $f_add_button->set_attribute('filter',$filter);
- $f_add_button->javascript=" select_card_type(this);";
+ $sql=' select fd_id from fiche_def where frd_id='.FICHE_TYPE_CONTACT;
+ $filter=$cn->make_list($sql);
+ if ( empty ($filter))
+ {
+ echo '';
+ echo _("Vous devez aller dans fiche et créer une catégorie pour les contacts");
+ echo ' ';
+ exit();
+ }
+ /* Add button */
+ $f_add_button=new IButton('add_card');
+ $f_add_button->label=_('Créer une nouvelle fiche');
+ $f_add_button->set_attribute('ipopup','ipopcard');
- echo $f_add_button->input();
- echo '
';
+ $f_add_button->set_attribute('filter',$filter);
+ $f_add_button->javascript=" select_card_type(this);";
+
+ echo $f_add_button->input();
+ echo '
';
}
diff --git a/include/anc_group.inc.php b/include/anc_group.inc.php
index 9a7652007..99bf3e006 100644
--- a/include/anc_group.inc.php
+++ b/include/anc_group.inc.php
@@ -20,7 +20,7 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*!\file
+/*!\file
*\brief manage the group
*
*/
@@ -32,23 +32,27 @@ $r=new Anc_Group($cn);
//----------------------------------------------------------------------
// REMOVE
-if ( isset ($_POST['remove'])) {
- if (isset($_POST['ck'] )) {
- foreach ($_POST['ck'] as $m ) {
- $obj=new Anc_Group($cn);
- $obj->ga_id=$m;
- $obj->remove();
- }
+if ( isset ($_POST['remove']))
+{
+ if (isset($_POST['ck'] ))
+ {
+ foreach ($_POST['ck'] as $m )
+ {
+ $obj=new Anc_Group($cn);
+ $obj->ga_id=$m;
+ $obj->remove();
+ }
}
- }
+}
//----------------------------------------------------------------------
// INSERT
-if ( isset($_POST['add'])) {
- $obj=new Anc_Group($cn);
- $obj->get_from_array($_POST);
- echo $obj->insert();
- }
+if ( isset($_POST['add']))
+{
+ $obj=new Anc_Group($cn);
+ $obj->get_from_array($_POST);
+ echo $obj->insert();
+}
$array=$r->myList();
echo '';
@@ -56,13 +60,14 @@ echo '
';
echo dossier::hidden();
echo '';
diff --git a/include/anc_imp.inc.php b/include/anc_imp.inc.php
index 9c858136b..4066226c9 100644
--- a/include/anc_imp.inc.php
+++ b/include/anc_imp.inc.php
@@ -34,9 +34,9 @@ require_once('ac_common.php');
//-- the menu
$menu=array(array("?p_action=ca_imp&sub=listing&$str_dossier",_("Listing"),_("Listing des opérations"),"listing"),
- array("?p_action=ca_imp&sub=bs&$str_dossier",_("Balance simple"),_("Balance simple d'un plan analytique"),"bs"),
- array("?p_action=ca_imp&sub=bc2&$str_dossier",_("Balance croisée"),_("Balance croisée de 2 plans analytiques"),"bc2")
- );
+ array("?p_action=ca_imp&sub=bs&$str_dossier",_("Balance simple"),_("Balance simple d'un plan analytique"),"bs"),
+ array("?p_action=ca_imp&sub=bc2&$str_dossier",_("Balance croisée"),_("Balance croisée de 2 plans analytiques"),"bc2")
+ );
$sub=(isset($_GET['sub']))?$_GET['sub']:'no';
echo '';
echo ShowItem($menu,"H","mtitle","mtitle",$sub);
@@ -48,52 +48,58 @@ $str_hidden.=$hidden->input("sub",$sub);
// select following the sub action
//------------------------------------------------------------------------------
// listing
-if ( $sub=='listing') {
- require_once ('class_anc_listing.php');
- $list=new Anc_Listing($cn);
- $list->get_request();
+if ( $sub=='listing')
+{
+ require_once ('class_anc_listing.php');
+ $list=new Anc_Listing($cn);
+ $list->get_request();
- echo $list->display_form($str_hidden);
- //---- result
- if ( isset($_GET['result']) ){
- echo '
';
+ echo $list->display_form($str_hidden);
+ //---- result
+ if ( isset($_GET['result']) )
+ {
+ echo '
';
- //--------------------------------
- // export Buttons
- //---------------------------------
- echo $list->show_button($str_hidden);
- echo $list->display_html();
- echo '
';
- }
- }
+ //--------------------------------
+ // export Buttons
+ //---------------------------------
+ echo $list->show_button($str_hidden);
+ echo $list->display_html();
+ echo '
';
+ }
+}
//------------------------------------------------------------------------------
// Simple balance
-if ($sub == 'bs') {
- require_once ('class_anc_balance_simple.php');
- $bs=new Anc_Balance_Simple($cn);
- $bs->get_request();
- echo '
';
- echo $bs->display_form($str_hidden);
- echo ' ';
- if ( isset($_GET['result'])) {
- echo $bs->show_button('ca_bs_csv.php','ca_bs_pdf.php',$str_hidden);
- echo $bs->display_html();
- }
- }
+if ($sub == 'bs')
+{
+ require_once ('class_anc_balance_simple.php');
+ $bs=new Anc_Balance_Simple($cn);
+ $bs->get_request();
+ echo '
';
+ echo $bs->display_form($str_hidden);
+ echo ' ';
+ if ( isset($_GET['result']))
+ {
+ echo $bs->show_button('ca_bs_csv.php','ca_bs_pdf.php',$str_hidden);
+ echo $bs->display_html();
+ }
+}
//------------------------------------------------------------------------------
// crossed balance
-if ( $sub == 'bc2') {
- require_once ('class_anc_balance_double.php');
- $bc=new Anc_Balance_Double($cn);
- $bc->get_request ();
- echo '
';
- echo $bc->display_form($str_hidden);
- echo ' ';
- if ( isset($_GET['result'])) {
- echo $bc->show_button('ca_bc_csv.php','ca_bc_pdf.php',$str_hidden);
- echo $bc->display_html();
- }
- }
+if ( $sub == 'bc2')
+{
+ require_once ('class_anc_balance_double.php');
+ $bc=new Anc_Balance_Double($cn);
+ $bc->get_request ();
+ echo '
';
+ echo $bc->display_form($str_hidden);
+ echo ' ';
+ if ( isset($_GET['result']))
+ {
+ echo $bc->show_button('ca_bc_csv.php','ca_bc_pdf.php',$str_hidden);
+ echo $bc->display_html();
+ }
+}
diff --git a/include/anc_od.inc.php b/include/anc_od.inc.php
index bc8f9d701..92a5ab88e 100644
--- a/include/anc_od.inc.php
+++ b/include/anc_od.inc.php
@@ -36,7 +36,11 @@ require_once ("class_anc_group_operation.php");
$pa=new Anc_Plan($cn);
$m=$pa->get_list();
-if ( ! $m ) { echo '
'._('Aucun plan analytique défini').' ';exit();}
+if ( ! $m )
+{
+ echo '
'._('Aucun plan analytique défini').' ';
+ exit();
+}
@@ -48,104 +52,107 @@ echo '
';
-
+
//----------------------------------------------------------------------
// the pa_id is set
//
//----------------------------------------------------------------------
-if ( isset($_GET['see'])) {
+if ( isset($_GET['see']))
+{
- // Show the list for the period
- // and exit
- //-----------------------------
- $a=new Anc_Operation($cn);
+ // Show the list for the period
+ // and exit
+ //-----------------------------
+ $a=new Anc_Operation($cn);
-echo '
-
-
-';
+ echo '
+
+
+ ';
- echo dossier::hidden();
- $hid=new IHidden();
+ echo dossier::hidden();
+ $hid=new IHidden();
- $hid->name="p_action";
- $hid->value="ca_od";
- echo $hid->input();
+ $hid->name="p_action";
+ $hid->value="ca_od";
+ echo $hid->input();
- $hid->name="see";
- $hid->value="";
- echo $hid->input();
+ $hid->name="see";
+ $hid->value="";
+ echo $hid->input();
- $w=new ISelect();
- $w->name="p_periode";
- // filter on the current year
- $filter_year=" where p_exercice='".$User->get_exercice()."'";
+ $w=new ISelect();
+ $w->name="p_periode";
+// filter on the current year
+ $filter_year=" where p_exercice='".$User->get_exercice()."'";
- $periode_start=$cn->make_array("select p_id,to_char(p_start,'DD-MM-YYYY') from parm_periode $filter_year order by p_start,p_end",1);
- $User=new User($cn);
- $current=(isset($_GET['p_periode']))?$_GET['p_periode']:$User->get_periode();
- $w->value=$periode_start;
- $w->selected=$current;
- echo $w->input();
- echo 'Période '.HtmlInput::submit('gl_submit','Valider').' ';
+ $periode_start=$cn->make_array("select p_id,to_char(p_start,'DD-MM-YYYY') from parm_periode $filter_year order by p_start,p_end",1);
+ $User=new User($cn);
+ $current=(isset($_GET['p_periode']))?$_GET['p_periode']:$User->get_periode();
+ $w->value=$periode_start;
+ $w->selected=$current;
+ echo $w->input();
+ echo 'Période '.HtmlInput::submit('gl_submit','Valider').'';
- echo '
';
- echo $a->html_table($current);
- echo '
';
- exit();
- }
-if ( isset($_POST['save'])) {
- // record the operation and exit
- // and exit
- //-----------------------------
- echo '
'.
- _('Opération sauvée');
- $a=new Anc_Group_Operation($cn);
+ echo '
';
+ echo $a->html_table($current);
+ echo '
';
+ exit();
+}
+if ( isset($_POST['save']))
+{
+ // record the operation and exit
+ // and exit
+ //-----------------------------
+ echo '
'.
+ _('Opération sauvée');
+ $a=new Anc_Group_Operation($cn);
- $a->get_from_array($_POST);
+ $a->get_from_array($_POST);
- $a->save();
- echo $a->show();
- echo '
';
- exit();
- }
+ $a->save();
+ echo $a->show();
+ echo '
';
+ exit();
+}
-if ( isset($_GET['new'])) {
- //show the form for entering a new Anc_Operation
- //------------------------------------------
- $a=new Anc_Group_Operation($cn);
- echo JS_CAOD_COMPUTE;
- $wSubmit=new IHidden("p_action","ca_od");
- $wSubmit->table=0;
- echo '
';
- echo '
';
- echo dossier::hidden();
- echo $wSubmit->input();
- echo $a->form();
- echo HtmlInput::submit("save","Sauver");
- echo ' ';
- echo '
+if ( isset($_GET['new']))
+{
+ //show the form for entering a new Anc_Operation
+ //------------------------------------------
+ $a=new Anc_Group_Operation($cn);
+ echo JS_CAOD_COMPUTE;
+ $wSubmit=new IHidden("p_action","ca_od");
+ $wSubmit->table=0;
+ echo '
';
+ echo '
';
+ echo dossier::hidden();
+ echo $wSubmit->input();
+ echo $a->form();
+ echo HtmlInput::submit("save","Sauver");
+ echo ' ';
+ echo '
Débit =
Crédit =
Difference =
-
+
';
- echo '
';
- exit();
- }
+ echo '
';
+ exit();
+}
?>
diff --git a/include/anc_pa.inc.php b/include/anc_pa.inc.php
index a85460712..32a42540a 100644
--- a/include/anc_pa.inc.php
+++ b/include/anc_pa.inc.php
@@ -34,206 +34,208 @@ $ret="";
// Compute the u_redcontent div
//---------------------------------------------------------------------------
if ( isset($_REQUEST['sa']))
- {
- $sa=$_REQUEST['sa'];
+{
+ $sa=$_REQUEST['sa'];
- // show the form for adding a pa
- if ( $sa == "add_pa")
- {
- $new=new Anc_Plan($cn);
- if ( $new->isAppend() == true)
- {
- $ret.= '
';
- $ret.= '
Nouveau plan ';
- $ret.= '';
- $ret.=dossier::hidden();
- $ret.= $new->form();
- $ret.= HtmlInput::hidden("sa","pa_write");
- $ret.=HtmlInput::hidden("p_action","ca_pa"); ;
- $ret.=HtmlInput::submit("submit","Enregistre");
- $ret.= ' ';
- $ret.= '';
- }
- else
- {
- $ret.= '
'.
- '
'.
- "Maximum de plan analytique est atteint".
- " ";
- }
- }
- // Add
- if ( $sa == "pa_write")
- {
- $new=new Anc_Plan($cn);
+ // show the form for adding a pa
+ if ( $sa == "add_pa")
+ {
+ $new=new Anc_Plan($cn);
+ if ( $new->isAppend() == true)
+ {
+ $ret.= '
';
+ $ret.= '
Nouveau plan ';
+ $ret.= '';
+ $ret.=dossier::hidden();
+ $ret.= $new->form();
+ $ret.= HtmlInput::hidden("sa","pa_write");
+ $ret.=HtmlInput::hidden("p_action","ca_pa");
+ ;
+ $ret.=HtmlInput::submit("submit","Enregistre");
+ $ret.= ' ';
+ $ret.= '';
+ }
+ else
+ {
+ $ret.= '
'.
+ '
'.
+ "Maximum de plan analytique est atteint".
+ " ";
+ }
+ }
+ // Add
+ if ( $sa == "pa_write")
+ {
+ $new=new Anc_Plan($cn);
- if ( $new->isAppend() == false)
- {
- $ret.= '
'.
- "Maximum de plan analytique est atteint".
- " ";
- }
- else
- {
- $new=new Anc_Plan($cn);
- $new->name=$_POST['pa_name'];
- $new->description=$_POST['pa_description'];
- $new->add();
- }
- }
- // show the detail
- if ( $sa == "pa_detail" )
- {
- $new=new Anc_Plan($cn,$_GET['pa_id']);
- $wAction=HtmlInput::hidden("p_action","ca_pa");
- $wSa=HtmlInput::hidden("sa","pa_update");
+ if ( $new->isAppend() == false)
+ {
+ $ret.= '
'.
+ "Maximum de plan analytique est atteint".
+ " ";
+ }
+ else
+ {
+ $new=new Anc_Plan($cn);
+ $new->name=$_POST['pa_name'];
+ $new->description=$_POST['pa_description'];
+ $new->add();
+ }
+ }
+ // show the detail
+ if ( $sa == "pa_detail" )
+ {
+ $new=new Anc_Plan($cn,$_GET['pa_id']);
+ $wAction=HtmlInput::hidden("p_action","ca_pa");
+ $wSa=HtmlInput::hidden("sa","pa_update");
- $new->get();
+ $new->get();
- $ret.= '
';
- $ret.= '
Mise à jour ';
- $ret.= '
';
- $ret.=dossier::hidden();
+ $ret.= '';
+ $ret.= '
Mise à jour ';
+ $ret.= '
';
+ $ret.=dossier::hidden();
- $ret.= $new->form();
- $ret.= $wSa;
- $ret.= $wAction;
- $ret.=HtmlInput::submit("submit","Enregistre");
-/* $ret.=sprintf(''.
- ' ',
- "?p_action=ca_pa&pa_id=".$_GET['pa_id']."&sa=pa_delete&$str_dossier");
-*/
- $ret.=HtmlInput::button_anchor('Efface',"?p_action=ca_pa&pa_id=".$_GET['pa_id']."&sa=pa_delete&$str_dossier",'Efface','onclick="return confirm(\'Effacer ?\')"');
- $ret.= ' ';
- $ret.= '
';
+ $ret.= $new->form();
+ $ret.= $wSa;
+ $ret.= $wAction;
+ $ret.=HtmlInput::submit("submit","Enregistre");
+ /* $ret.=sprintf(''.
+ ' ',
+ "?p_action=ca_pa&pa_id=".$_GET['pa_id']."&sa=pa_delete&$str_dossier");
+ */
+ $ret.=HtmlInput::button_anchor('Efface',"?p_action=ca_pa&pa_id=".$_GET['pa_id']."&sa=pa_delete&$str_dossier",'Efface','onclick="return confirm(\'Effacer ?\')"');
+ $ret.= ' ';
+ $ret.= '
';
- }
- // Update the PA
- if ( $sa == "pa_update" )
- {
- $new=new Anc_Plan($cn,$_GET['pa_id']);
- $new->name=$_POST['pa_name'];
- $new->description=$_POST['pa_description'];
- $new->update();
- $ret='
';
- $ret.='
Mis à jour ';
- $ret.="";
- }
- // show the form for add a poste
- if ( $sa=='po_add')
- {
- $po=new Anc_Account($cn);
- $po->pa_id=$_REQUEST['pa_id'];
- $wSa=HtmlInput::hidden("sa","po_write");
- $ret.='
';
- $ret.='
';
- $ret.=dossier::hidden();
- $ret.=$po->form();
- $ret.=$wSa;
- $ret.=HtmlInput::submit("add","Ajout");
- $ret.=" ";
- $ret.="";
- }
- // record the poste
- if ( $sa=="po_write")
- {
- // var_dump($_POST);
- $po=new Anc_Account($cn);
- $po->get_from_array($_POST);
- $po->add();
- $sa="list";
+ }
+ // Update the PA
+ if ( $sa == "pa_update" )
+ {
+ $new=new Anc_Plan($cn,$_GET['pa_id']);
+ $new->name=$_POST['pa_name'];
+ $new->description=$_POST['pa_description'];
+ $new->update();
+ $ret='
';
+ $ret.='
Mis à jour ';
+ $ret.="";
+ }
+ // show the form for add a poste
+ if ( $sa=='po_add')
+ {
+ $po=new Anc_Account($cn);
+ $po->pa_id=$_REQUEST['pa_id'];
+ $wSa=HtmlInput::hidden("sa","po_write");
+ $ret.='
';
+ $ret.='
';
+ $ret.=dossier::hidden();
+ $ret.=$po->form();
+ $ret.=$wSa;
+ $ret.=HtmlInput::submit("add","Ajout");
+ $ret.=" ";
+ $ret.="";
+ }
+ // record the poste
+ if ( $sa=="po_write")
+ {
+ // var_dump($_POST);
+ $po=new Anc_Account($cn);
+ $po->get_from_array($_POST);
+ $po->add();
+ $sa="list";
- }
- /* delete pa */
- if ( $sa == "pa_delete")
- {
- $delete=new Anc_Plan($cn,$_GET['pa_id']);
- $delete->delete();
- }
- /* po detail
- *
- */
- if ( $sa=="po_detail")
- {
- $po=new Anc_Account($cn,$_GET['po_id']);
- $po->get_by_id();
- $ret.='
';
- $ret.='
';
- $ret.=dossier::hidden();
+ }
+ /* delete pa */
+ if ( $sa == "pa_delete")
+ {
+ $delete=new Anc_Plan($cn,$_GET['pa_id']);
+ $delete->delete();
+ }
+ /* po detail
+ *
+ */
+ if ( $sa=="po_detail")
+ {
+ $po=new Anc_Account($cn,$_GET['po_id']);
+ $po->get_by_id();
+ $ret.='';
- }
- if ( $sa=="po_update")
- {
- $po=new Anc_Account($cn);
- $po->get_from_array($_POST);
- $po->update();
- $sa="list";
- }
- if ( $sa=="po_delete")
- {
- $po=new Anc_Account($cn,$_REQUEST['po_id']);
- $po->delete();
- $sa="list";
- }
- /* List poste */
- if ( $sa == "list" )
- {
- $count=0;
+ $ret.=' ';
+ $ret.='
';
+ }
+ if ( $sa=="po_update")
+ {
+ $po=new Anc_Account($cn);
+ $po->get_from_array($_POST);
+ $po->update();
+ $sa="list";
+ }
+ if ( $sa=="po_delete")
+ {
+ $po=new Anc_Account($cn,$_REQUEST['po_id']);
+ $po->delete();
+ $sa="list";
+ }
+ /* List poste */
+ if ( $sa == "list" )
+ {
+ $count=0;
- $new=new Anc_Plan($cn,$_REQUEST['pa_id']);
- $new->get();
- $array=$new->get_poste_analytique();
- $ret.='
';
- $ret.='
';
- $ret.="";
- $ret.=" Nom ";
- $ret.=" Montant ";
- $ret.=" Description ";
- $ret.=" Groupe ";
- $ret.=" Plan A ";
- $ret.=" ";
- $class="";
- foreach ($array as $obj)
- {
- $count++;
- if ( $count %2 == 0 )
- $class="even";
- else
- $class="odd";
+ $new=new Anc_Plan($cn,$_REQUEST['pa_id']);
+ $new->get();
+ $array=$new->get_poste_analytique();
+ $ret.='';
+ $ret.='
';
+ $ret.="";
+ $ret.=" Nom ";
+ $ret.=" Montant ";
+ $ret.=" Description ";
+ $ret.=" Groupe ";
+ $ret.=" Plan A ";
+ $ret.=" ";
+ $class="";
+ foreach ($array as $obj)
+ {
+ $count++;
+ if ( $count %2 == 0 )
+ $class="even";
+ else
+ $class="odd";
- $ret.="";
- $ret.="".
- ''.
- h($obj->name).
- ' ';
- " ";
- $ret.="".$obj->amount." ";
- $ret.="".h($obj->description)." ";
- $ret.="".$obj->ga_id." ";
- $ret.="".h($new->name)." ";
- $ret.=" ";
+ $ret.="";
+ $ret.="".
+ ''.
+ h($obj->name).
+ ' ';
+ " "
+ ;
+ $ret.="".$obj->amount." ";
+ $ret.="".h($obj->description)." ";
+ $ret.="".$obj->ga_id." ";
+ $ret.="".h($new->name)." ";
+ $ret.=" ";
- }
- $ret.="
";
- $ret.=HtmlInput::button_anchor('Ajout',"?p_action=ca_pa&sa=po_add&pa_id=".$_GET['pa_id']."&".$str_dossier);
- $ret.='
';
+ }
+ $ret.="
";
+ $ret.=HtmlInput::button_anchor('Ajout',"?p_action=ca_pa&sa=po_add&pa_id=".$_GET['pa_id']."&".$str_dossier);
+ $ret.='
';
- }
+ }
- }
+}
//---------------------------------------------------------------------------
@@ -247,53 +249,53 @@ $list=$obj->get_list();
if ( empty($list) )
- {
- echo '';
+ if ( ! isset ( $_REQUEST['sa']))
+ echo '
'.
+ "Aucun plan analytique n'est défini".
+ '
';
- }
- else
- {
- echo '';
+}
//---------------------------------------------------------------------------
// show the u_redcontent part
//
diff --git a/include/argenta_be.inc.php b/include/argenta_be.inc.php
index e030d1625..8a8a12219 100644
--- a/include/argenta_be.inc.php
+++ b/include/argenta_be.inc.php
@@ -1,4 +1,4 @@
-set_encoding('latin1');
-while (($data = fgetcsv($handle, 2000,"!")) !== FALSE) {
- $num = count($data);
- for ($c=0; $c < $num; $c++) {
- if ( $line==1) {
- $row=explode(';',$data[$c]);
- $num_compte=$row[1];
- }
- if ( $line < 2 )
- continue;
+while (($data = fgetcsv($handle, 2000,"!")) !== FALSE)
+{
+ $num = count($data);
+ for ($c=0; $c < $num; $c++)
+ {
+ if ( $line==1)
+ {
+ $row=explode(';',$data[$c]);
+ $num_compte=$row[1];
+ }
+ if ( $line < 2 )
+ continue;
//-----------------------------------------------------
// Parsing CSV comes here
//-----------------------------------------------------
- $row=explode(';',$data[$c]);
- echo 'ici sizeof $row = '.sizeof($row);
- if ( sizeof ($row) < 9 )
- continue;
-
+ $row=explode(';',$data[$c]);
+ echo 'ici sizeof $row = '.sizeof($row);
+ if ( sizeof ($row) < 9 )
+ continue;
- $date_exec=$row[5];
- $date_val=$row[5];
- $code=$row[1]."/".$row[0];
- // remove first the thousand sep.
- $montant=str_replace('.','',$row[3]);
- // replace the coma by a period
- $montant=str_replace(',','.',$montant);
- // remove the sign
- $montant=str_replace('+','',$montant);
- $devise=$row[4];
- $compte_ordre=$row[6];
- $detail='virement du compte:'.$compte_ordre.trim($row[2]).' '.trim($row[7]).' '.trim($row[8]).' '.trim($row[9]);
+
+ $date_exec=$row[5];
+ $date_val=$row[5];
+ $code=$row[1]."/".$row[0];
+ // remove first the thousand sep.
+ $montant=str_replace('.','',$row[3]);
+ // replace the coma by a period
+ $montant=str_replace(',','.',$montant);
+ // remove the sign
+ $montant=str_replace('+','',$montant);
+ $devise=$row[4];
+ $compte_ordre=$row[6];
+ $detail='virement du compte:'.$compte_ordre.trim($row[2]).' '.trim($row[7]).' '.trim($row[8]).' '.trim($row[9]);
//----------------------------------------------------
// Skip dubbel
//----------------------------------------------------
- $code=FormatString($code);
- $num_compte=FormatString($num_compte);
- if ( $p_cn->count_sql(utf8_encode("select * from import_tmp where code='$code' and num_compte='$num_compte' limit 2")) != 0 )
-{
- /* Skip it it already encoded */
- echo "Doublon éliminé ".$detail;
- echo "
";
- continue;
-}
-echo "Ajout de $detail";
-echo "
";
+ $code=FormatString($code);
+ $num_compte=FormatString($num_compte);
+ if ( $p_cn->count_sql(utf8_encode("select * from import_tmp where code='$code' and num_compte='$num_compte' limit 2")) != 0 )
+ {
+ /* Skip it it already encoded */
+ echo "Doublon éliminé ".$detail;
+ echo "
";
+ continue;
+ }
+ echo "Ajout de $detail";
+ echo "
";
//-----------------------------------------------------
// insert into import_tmp
//-----------------------------------------------------
- $Sql="insert into import_tmp (code,
- date_exec ,
- date_valeur,
- montant,
- devise,
- compte_ordre,
- num_compte,
- detail,
- bq_account ,
- jrn,
- status)
- values ('$code',
- to_date('$date_exec','DD-MM-YYYY'),
- to_date('$date_exec','DD-MM-YYYY'),
- $montant,
- '$devise',
- '".addslashes($compte_ordre)."',
- '".$num_compte."',
- '".addslashes($detail)." ',
- '$p_bq_account',
- $p_jrn,
- 'n')";
- try
- {
- $p_cn->exec_sql($Sql);
- }
+ $Sql="insert into import_tmp (code,
+ date_exec ,
+ date_valeur,
+ montant,
+ devise,
+ compte_ordre,
+ num_compte,
+ detail,
+ bq_account ,
+ jrn,
+ status)
+ values ('$code',
+ to_date('$date_exec','DD-MM-YYYY'),
+ to_date('$date_exec','DD-MM-YYYY'),
+ $montant,
+ '$devise',
+ '".addslashes($compte_ordre)."',
+ '".$num_compte."',
+ '".addslashes($detail)." ',
+ '$p_bq_account',
+ $p_jrn,
+ 'n')";
+ try
+ {
+ $p_cn->exec_sql($Sql);
+ }
- catch(Exception $e)
- {
- echo(__FILE__.":".__LINE__." Erreur : ".$e->getCode()." msg ".$e->getMessage());
- rollback($p_cn);
- break;
- }
+ catch(Exception $e)
+ {
+ echo(__FILE__.":".__LINE__." Erreur : ".$e->getCode()." msg ".$e->getMessage());
+ rollback($p_cn);
+ break;
+ }
- } // for ($c=0;$c<$num;$c++)
- $line++;
+ } // for ($c=0;$c<$num;$c++)
+ $line++;
} // file is read
diff --git a/include/balance.inc.php b/include/balance.inc.php
index 927ef3d1f..f1505c24d 100644
--- a/include/balance.inc.php
+++ b/include/balance.inc.php
@@ -1,4 +1,4 @@
-show_start_date=false;
$input_to->filter_year;
$input_to->type=ALL;
-$input_to->cn=$cn;
+$input_to->cn=$cn;
$input_to->user=$User;
echo ' jusque :'.$input_to->input();
@@ -76,11 +76,14 @@ $select_cat=(isset($_GET['r_cat']))?$_GET['r_cat']:null;
$array_cat=Acc_Ledger::array_cat();
echo '
';
-if ( ! isset($_GET['p_filter']) || $_GET['p_filter']==0) $rad->selected='t';else $rad->selected=false;
+if ( ! isset($_GET['p_filter']) || $_GET['p_filter']==0) $rad->selected='t';
+else $rad->selected=false;
echo ''.$rad->input('p_filter',0).'Aucun filtre, tous les journaux'.' ';
-if ( isset($_GET['p_filter']) && $_GET['p_filter']==1) $rad->selected='t'; else $rad->selected=false;
+if ( isset($_GET['p_filter']) && $_GET['p_filter']==1) $rad->selected='t';
+else $rad->selected=false;
echo ''.$rad->input('p_filter',1).'Filtré par journal'.HtmlInput::select_ledger($array_ledger,$selected).' ';
-if ( isset($_GET['p_filter']) && $_GET['p_filter']==2) $rad->selected='t';else $rad->selected=false;
+if ( isset($_GET['p_filter']) && $_GET['p_filter']==2) $rad->selected='t';
+else $rad->selected=false;
echo ''.$rad->input('p_filter',2).'Filtré par catégorie'.HtmlInput::select_cat($array_cat).' ';
echo ' ';
@@ -116,110 +119,116 @@ echo '
';
// Form
//-----------------------------------------------------
// Show the export button
-if ( isset ($_GET['view'] ) ) {
+if ( isset ($_GET['view'] ) )
+{
- $hid=new IHidden();
+ $hid=new IHidden();
- echo "
";
- echo '';
- echo ''.
- dossier::hidden().
+ echo "";
+ echo '';
+ echo ''.
+ dossier::hidden().
HtmlInput::submit('bt_pdf',"Export PDF").
HtmlInput::hidden("p_action","impress").
HtmlInput::hidden("from_periode",$_GET['from_periode']).
HtmlInput::hidden("to_periode",$_GET['to_periode']);
- echo HtmlInput::hidden('p_filter',$_GET['p_filter']);
- for ($e=0;$e ";
+ echo "";
- echo ''.
+ echo ''.
HtmlInput::submit('bt_csv',"Export CSV").
- dossier::hidden().
+ dossier::hidden().
HtmlInput::hidden("p_action","impress").
HtmlInput::hidden("from_periode",$_GET['from_periode']).
HtmlInput::hidden("to_periode",$_GET['to_periode']);
- echo HtmlInput::hidden('p_filter',$_GET['p_filter']);
- if (isset($_GET ['r_jrn']))
- if (isset($selected[$e]))
- echo HtmlInput::hidden("r_jrn[$e]",$e);
- for ($e=0;$e ";
+ echo " ";
- echo " ";
+ echo "";
- echo "
";
+ echo "
";
}
//-----------------------------------------------------
// Display result
//-----------------------------------------------------
-if ( isset($_GET['view'] ) ) {
- $bal=new Acc_Balance($cn);
- if ( $_GET['p_filter']==1) {
- for ($e=0;$e
jrn[]=$array_ledger[$e]['jrn_def_id'];
- }
- if ( $_GET['p_filter'] == 0 ) {
- $bal->jrn=null;
- }
- if ( $_GET['p_filter'] == 2 && isset ($_GET['r_cat'])) {
- $bal->filter_cat($_GET['r_cat']);
- }
- $bal->from_poste=$_GET['from_poste'];
- $bal->to_poste=$_GET['to_poste'];
+if ( isset($_GET['view'] ) )
+{
+ $bal=new Acc_Balance($cn);
+ if ( $_GET['p_filter']==1)
+ {
+ for ($e=0;$ejrn[]=$array_ledger[$e]['jrn_def_id'];
+ }
+ if ( $_GET['p_filter'] == 0 )
+ {
+ $bal->jrn=null;
+ }
+ if ( $_GET['p_filter'] == 2 && isset ($_GET['r_cat']))
+ {
+ $bal->filter_cat($_GET['r_cat']);
+ }
+ $bal->from_poste=$_GET['from_poste'];
+ $bal->to_poste=$_GET['to_poste'];
- $row=$bal->get_row($_GET['from_periode'],
- $_GET['to_periode']);
- $periode=new Periode($cn);
- $a=$periode->get_date_limit($_GET['from_periode']);
- $b=$periode->get_date_limit($_GET['to_periode']);
- echo " période du ".$a['p_start']." au ".$b['p_end']." ";
+ $row=$bal->get_row($_GET['from_periode'],
+ $_GET['to_periode']);
+ $periode=new Periode($cn);
+ $a=$periode->get_date_limit($_GET['from_periode']);
+ $b=$periode->get_date_limit($_GET['to_periode']);
+ echo " période du ".$a['p_start']." au ".$b['p_end']." ";
- echo '';
- echo 'Poste Comptable ';
- echo 'Libellé ';
- echo 'Débit ';
- echo 'Crédit ';
- echo 'Solde Débiteur ';
- echo 'Solde Créditeur ';
+ echo '';
+ echo 'Poste Comptable ';
+ echo 'Libellé ';
+ echo 'Débit ';
+ echo 'Crédit ';
+ echo 'Solde Débiteur ';
+ echo 'Solde Créditeur ';
- $i=0;
- foreach ($row as $r) {
- $i++;
- if ( $i%2 == 0 )
- $tr="even";
- else
- $tr="odd";
- $view_history= sprintf('%s ',
- $r['poste'], $gDossier, $r['poste']);
+ $i=0;
+ foreach ($row as $r)
+ {
+ $i++;
+ if ( $i%2 == 0 )
+ $tr="even";
+ else
+ $tr="odd";
+ $view_history= sprintf('%s ',
+ $r['poste'], $gDossier, $r['poste']);
- echo '';
- echo td($view_history);
- echo td(h($r['label']));
- echo td($r['sum_deb']);
- echo td($r['sum_cred']);
- echo td($r['solde_deb']);
- echo td($r['solde_cred']);
- echo ' ';
- }
- echo '
';
+ echo '';
+ echo td($view_history);
+ echo td(h($r['label']));
+ echo td($r['sum_deb']);
+ echo td($r['sum_cred']);
+ echo td($r['solde_deb']);
+ echo td($r['solde_cred']);
+ echo ' ';
+ }
+ echo '
';
- }// end submit
- echo " ";
+}// end submit
+echo "
";
?>
diff --git a/include/card_attr.inc.php b/include/card_attr.inc.php
index c8d3142ec..f9540e36a 100644
--- a/include/card_attr.inc.php
+++ b/include/card_attr.inc.php
@@ -32,25 +32,32 @@ $fa=new Fiche_Attr($cn);
/////////////////////////////////////////////////////////////////////////////
// If data are post we save them first
/////////////////////////////////////////////////////////////////////////////
-if ( isset($_POST['save'])) {
- $ad_id=$_POST['ad_id'];
- $ad_text=$_POST['desc'];
- $ad_type=$_POST['type'];
- $ad_size=$_POST['size'];
- try {
- $cn->start();
- for ($e=0;$eset_parameter('id',$ad_id[$e]);
- $fa->set_parameter('desc',$ad_text[$e]);
- $fa->set_parameter('type',$ad_type[$e]);
- $fa->set_parameter('size',$ad_size[$e]);
- if ( trim($ad_text[$e])!='' && trim($ad_type[$e])!='')
- $fa->save();
+if ( isset($_POST['save']))
+{
+ $ad_id=$_POST['ad_id'];
+ $ad_text=$_POST['desc'];
+ $ad_type=$_POST['type'];
+ $ad_size=$_POST['size'];
+ try
+ {
+ $cn->start();
+ for ($e=0;$eset_parameter('id',$ad_id[$e]);
+ $fa->set_parameter('desc',$ad_text[$e]);
+ $fa->set_parameter('type',$ad_type[$e]);
+ $fa->set_parameter('size',$ad_size[$e]);
+ if ( trim($ad_text[$e])!='' && trim($ad_type[$e])!='')
+ $fa->save();
+ }
+ $cn->commit();
}
- $cn->commit();
- }
- catch (Exception $e)
- { $e->getMessage();$cn->rollback();}
+ catch (Exception $e)
+ {
+ $e->getMessage();
+ $cn->rollback();
+ }
+
}
/* show list of existing */
$gDossier=dossier::id();
@@ -64,11 +71,11 @@ $size=new INum('size[]');
$size->size=5;
$select_type->value=array(
- array('value'=>'text','label'=>'Texte'),
- array('value'=>'numeric','label'=>'Nombre'),
- array('value'=>'date','label'=>'Date'),
- array('value'=>'zone','label'=>'Zone de texte')
- );
+ array('value'=>'text','label'=>'Texte'),
+ array('value'=>'numeric','label'=>'Nombre'),
+ array('value'=>'date','label'=>'Date'),
+ array('value'=>'zone','label'=>'Zone de texte')
+ );
$remove=new IButton('rmfa');
$remove->label='Effacer';
echo '';
@@ -78,46 +85,52 @@ echo HtmlInput::hidden('sa','fat');
echo HtmlInput::hidden('p_action','divers');
echo '
';
-for ($e=0;$eget_parameter('id')));
- $select_type->selected=$row->get_parameter('type');
- $desc->value=$row->get_parameter('desc');
- $size->value=$row->get_parameter('size');
+for ($e=0;$eget_parameter('id')));
+ $select_type->selected=$row->get_parameter('type');
+ $desc->value=$row->get_parameter('desc');
+ $size->value=$row->get_parameter('size');
- if ( $row->get_parameter('id')>= 9000) {
- $select_type->readOnly=false;
- $desc->readOnly=false;
- $size->readOnly=false;
+ if ( $row->get_parameter('id')>= 9000)
+ {
+ $select_type->readOnly=false;
+ $desc->readOnly=false;
+ $size->readOnly=false;
- $desc->style=' class="input_text" ';
- $r.=td($desc->input());
- $r.=td($select_type->input());
- $r.=td($size->input());
+ $desc->style=' class="input_text" ';
+ $r.=td($desc->input());
+ $r.=td($select_type->input());
+ $r.=td($size->input());
- $remove->javascript=sprintf('if ( confirm(\'Vous confirmez ?\')) { removeCardAttribut(%d,%d,\'tb_rmfa\',this);}',
- $row->get_parameter('id'),$gDossier);
- $msg=' Attention : effacera les données qui y sont liées ';
- $r.=td($remove->input().$msg);
- } else {
- $select_type->readOnly=true;
- $desc->readOnly=true;
- $size->readOnly=true;
+ $remove->javascript=sprintf('if ( confirm(\'Vous confirmez ?\')) { removeCardAttribut(%d,%d,\'tb_rmfa\',this);}',
+ $row->get_parameter('id'),$gDossier);
+ $msg=' Attention : effacera les données qui y sont liées ';
+ $r.=td($remove->input().$msg);
+ }
+ else
+ {
+ $select_type->readOnly=true;
+ $desc->readOnly=true;
+ $size->readOnly=true;
- $r.=td($desc->input().HtmlInput::hidden('type[]',''));
- $r.=td($select_type->input());
- $r.=td($size->input());
- $r.=td("");
- }
+ $r.=td($desc->input().HtmlInput::hidden('type[]',''));
+ $r.=td($select_type->input());
+ $r.=td($size->input());
+ $r.=td("");
+ }
- echo tr($r);
-
+ echo tr($r);
+
}
-$desc->readOnly=false;$select_type->readOnly=false;$size->readOnly=false;
+$desc->readOnly=false;
+$select_type->readOnly=false;
+$size->readOnly=false;
$desc->value='';
$select_type->selected=-1;
$r=td(HtmlInput::hidden('ad_id[]','0'));
diff --git a/include/cat_document.inc.php b/include/cat_document.inc.php
index 99559b686..73ffaf60a 100644
--- a/include/cat_document.inc.php
+++ b/include/cat_document.inc.php
@@ -25,11 +25,12 @@
* table document_type
*/
- // show list of document
+// show list of document
require_once ('class_document_type.php');
-if ( isset($_POST['add']) ) {
- $catDoc=new Document_Type($cn);
- $catDoc->insert($_POST['cat']);
+if ( isset($_POST['add']) )
+{
+ $catDoc=new Document_Type($cn);
+ $catDoc->insert($_POST['cat']);
}
$aList=Document_Type::get_list($cn);
$addCat=new IText('cat');
@@ -38,4 +39,6 @@ $str_submit=HtmlInput::submit('add',_('Ajout'));
echo '';
require_once('template/list_category_document.php');
echo '
';
+?>
+?>
?>
\ No newline at end of file
diff --git a/include/cbc_be.inc.php b/include/cbc_be.inc.php
index 2c108bdfd..882af595f 100644
--- a/include/cbc_be.inc.php
+++ b/include/cbc_be.inc.php
@@ -1,4 +1,4 @@
-start();
$p_cn->set_encoding('latin1');
-while (($data = fgetcsv($handle, 2000,'@')) !== FALSE) {
- $num = count($data);
- for ($c=0; $c < $num; $c++) {
+while (($data = fgetcsv($handle, 2000,'@')) !== FALSE)
+{
+ $num = count($data);
+ for ($c=0; $c < $num; $c++)
+ {
//-----------------------------------------------------
// Parsing CSV comes here
//-----------------------------------------------------
- $row=explode(';',$data[$c]);
- if ( sizeof ($row) < 13 )
- continue;
+ $row=explode(';',$data[$c]);
+ if ( sizeof ($row) < 13 )
+ continue;
- $num_compte=$row[0];
- $date_exec=$row[3];
- $date_val=$row[4];
- // remove first the thousand sep.
- $montant=str_replace('.','',$row[6]);
- // replace the coma by a period
- $montant=str_replace(',','.',$montant);
- // remove the sign
- $montant=str_replace('+','',$montant);
- $devise=$row[1];
- $compte_ordre=$row[0];
- $detail=trim($row[7]).' '.trim($row[8]).' '.trim($row[9]).' '.trim($row[10]);
- if ( myereg('[0-9]{3}-[0-9]{7}-[0-9]{2}',$row[7],$r) )
- {
- $compte_ordre=$r[0];
- }
+ $num_compte=$row[0];
+ $date_exec=$row[3];
+ $date_val=$row[4];
+ // remove first the thousand sep.
+ $montant=str_replace('.','',$row[6]);
+ // replace the coma by a period
+ $montant=str_replace(',','.',$montant);
+ // remove the sign
+ $montant=str_replace('+','',$montant);
+ $devise=$row[1];
+ $compte_ordre=$row[0];
+ $detail=trim($row[7]).' '.trim($row[8]).' '.trim($row[9]).' '.trim($row[10]);
+ if ( myereg('[0-9]{3}-[0-9]{7}-[0-9]{2}',$row[7],$r) )
+ {
+ $compte_ordre=$r[0];
+ }
//-----------------------------------------------------
// insert into import_tmp
//-----------------------------------------------------
- $Sql="insert into import_tmp (code,
- date_exec ,
- date_valeur,
- montant,
- devise,
- compte_ordre,
- detail,
- bq_account ,
- jrn,
- status)
- values (nextval('s_cbc'),
- to_date('$date_exec','YYYYMMDD'),
- to_date('$date_exec','YYYYMMDD'),
- $montant,
- '$devise',
- '".addslashes($compte_ordre)."',
- '".addslashes($detail).$num_compte." ',
- '$p_bq_account',
- $p_jrn,
- 'n')";
- try
- {
- $p_cn->exec_sql($Sql) ;
- }
- catch(Exception $e)
- {
- $p_cn->rollback();
- break;
- }
- } // for ($c=0;$c<$num;$c++)
- $row++;
+ $Sql="insert into import_tmp (code,
+ date_exec ,
+ date_valeur,
+ montant,
+ devise,
+ compte_ordre,
+ detail,
+ bq_account ,
+ jrn,
+ status)
+ values (nextval('s_cbc'),
+ to_date('$date_exec','YYYYMMDD'),
+ to_date('$date_exec','YYYYMMDD'),
+ $montant,
+ '$devise',
+ '".addslashes($compte_ordre)."',
+ '".addslashes($detail).$num_compte." ',
+ '$p_bq_account',
+ $p_jrn,
+ 'n')";
+ try
+ {
+ $p_cn->exec_sql($Sql) ;
+ }
+ catch(Exception $e)
+ {
+ $p_cn->rollback();
+ break;
+ }
+ } // for ($c=0;$c<$num;$c++)
+ $row++;
} // file is read
fclose($handle);
echo "Encore rien désolé";
diff --git a/include/cbc_be_ol.inc.php b/include/cbc_be_ol.inc.php
index 7be276caf..7b4b7d91c 100644
--- a/include/cbc_be_ol.inc.php
+++ b/include/cbc_be_ol.inc.php
@@ -1,92 +1,93 @@
-start();
$p_cn->set_encoding('latin1');
-while (($row = fgetcsv($handle, 2000,';')) !== FALSE) {
+while (($row = fgetcsv($handle, 2000,';')) !== FALSE)
+{
- $num = count($row);
- if ( $num != 11 ) continue;
- if ( $row[3] != 'EUR') continue;
- $line++;
- //-----------------------------------------------------
- // Parsing CSV comes here
- //-----------------------------------------------------
- $num_compte=$row[0];
- $date_exec=$row[5];
- $date_val=$row[7];
- // remove first the thousand sep.
- $montant=str_replace(' ','',$row[8]);
- // replace the coma by a period
- $montant=str_replace(',','.',$montant);
- // remove the sign
- $montant=str_replace('+','',$montant);
- $devise=$row[3];
- $ref_extrait=$row[4].'-'.$line;
- $detail=$line.'/'.$row[4].' '.$row[6];
- $pj=$row[10];
- //
- //-----------------------------------------------------
- // insert into import_tmp
- //-----------------------------------------------------
- $Sql="insert into import_tmp (code,
- date_exec ,
- date_valeur,
- montant,
- devise,
- detail,
- bq_account ,
- jrn,
- status,
- it_pj)
- values ('$ref_extrait',
- to_date('$date_exec','DD/MM/YYYY'),
- to_date('$date_exec','DD/MM/YYYY'),
- $montant,
- '$devise',
- '$detail',
- '$p_bq_account',
- $p_jrn,
- 'n',$pj)";
- try
+ $num = count($row);
+ if ( $num != 11 ) continue;
+ if ( $row[3] != 'EUR') continue;
+ $line++;
+ //-----------------------------------------------------
+ // Parsing CSV comes here
+ //-----------------------------------------------------
+ $num_compte=$row[0];
+ $date_exec=$row[5];
+ $date_val=$row[7];
+ // remove first the thousand sep.
+ $montant=str_replace(' ','',$row[8]);
+ // replace the coma by a period
+ $montant=str_replace(',','.',$montant);
+ // remove the sign
+ $montant=str_replace('+','',$montant);
+ $devise=$row[3];
+ $ref_extrait=$row[4].'-'.$line;
+ $detail=$line.'/'.$row[4].' '.$row[6];
+ $pj=$row[10];
+ //
+ //-----------------------------------------------------
+ // insert into import_tmp
+ //-----------------------------------------------------
+ $Sql="insert into import_tmp (code,
+ date_exec ,
+ date_valeur,
+ montant,
+ devise,
+ detail,
+ bq_account ,
+ jrn,
+ status,
+ it_pj)
+ values ('$ref_extrait',
+ to_date('$date_exec','DD/MM/YYYY'),
+ to_date('$date_exec','DD/MM/YYYY'),
+ $montant,
+ '$devise',
+ '$detail',
+ '$p_bq_account',
+ $p_jrn,
+ 'n',$pj)";
+ try
{
- $p_cn->exec_sql($Sql) ;
+ $p_cn->exec_sql($Sql) ;
}
- catch(Exception $e)
+ catch(Exception $e)
{
- $p_cn->rollback();
- break;
+ $p_cn->rollback();
+ break;
}
} // file is read
fclose($handle);
if ($line ==0 )
- echo "Encore rien désolé";
-else
- echo "$line lignes sont importées";
+ echo "Encore rien désolé";
+else
+ echo "$line lignes sont importées";
echo ' ';
?>
diff --git a/include/class_acc_account.php b/include/class_acc_account.php
index 85b12c52c..15e2796e7 100644
--- a/include/class_acc_account.php
+++ b/include/class_acc_account.php
@@ -1,4 +1,4 @@
-'pcm_val',
- 'type'=>'pcm_type',
- 'parent'=>'pcm_val_parent',
- 'libelle'=>'pcm_lib');
- private $pcm_val;
- private $pcm_type;
- private $pcm_parent;
- private $pcm_lib;
- static public $type=array(
- array('label'=>'Actif','value'=>'ACT'),
- array('label'=>'Passif','value'=>'PAS'),
- array('label'=>'Actif c. inverse','value'=>'ACTINV'),
- array('label'=>'Passif c.inverse','value'=>'PASINV'),
- array('label'=>'Produit','value'=>'PRO'),
- array('label'=>'Produit Inverse','value'=>'PROINV'),
- array('label'=>'Charge','value'=>'CHA'),
- array('label'=>'Charge Inverse','value'=>'CHAINV'),
- array('label'=>'Non defini','value'=>'CON')
- );
+class Acc_Account
+{
+ var $db; /*!< $db database connection */
+ static private $variable = array("value"=>'pcm_val',
+ 'type'=>'pcm_type',
+ 'parent'=>'pcm_val_parent',
+ 'libelle'=>'pcm_lib');
+ private $pcm_val;
+ private $pcm_type;
+ private $pcm_parent;
+ private $pcm_lib;
+ static public $type=array(
+ array('label'=>'Actif','value'=>'ACT'),
+ array('label'=>'Passif','value'=>'PAS'),
+ array('label'=>'Actif c. inverse','value'=>'ACTINV'),
+ array('label'=>'Passif c.inverse','value'=>'PASINV'),
+ array('label'=>'Produit','value'=>'PRO'),
+ array('label'=>'Produit Inverse','value'=>'PROINV'),
+ array('label'=>'Charge','value'=>'CHA'),
+ array('label'=>'Charge Inverse','value'=>'CHAINV'),
+ array('label'=>'Non defini','value'=>'CON')
+ );
- function __construct ($p_cn,$p_id=0) {
- $this->db=$p_cn;
- $this->pcm_val=$p_id;
- }
- public function get_parameter($p_string) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- return $this->$idx;
+ function __construct ($p_cn,$p_id=0)
+ {
+ $this->db=$p_cn;
+ $this->pcm_val=$p_id;
}
- else
- exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
- }
-
- function set_parameter($p_string,$p_value) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- if ($this->check($idx,$p_value) == true ) $this->$idx=$p_value;
+ public function get_parameter($p_string)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ return $this->$idx;
+ }
+ else
+ exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
}
- else
- exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
-
-
- }
- /*!\brief Return the name of a account
- * it doesn't change any data member
- * \return string with the pcm_lib
- */
- function get_lib() {
- $ret=$this->db->exec_sql(
- "select pcm_lib from tmp_pcmn where
- pcm_val=$1",array($this->pcm_val));
- if ( Database::num_row($ret) != 0) {
- $r=Database::fetch_array($ret);
- $this->pcm_lib=$r['pcm_lib'];
- } else {
- $this->pcm_lib="Poste inconnu";
- }
- return $this->pcm_lib;
- }
- /*!\brief Check that the value are valid
- *\return true if all value are valid otherwise false
- */
- function check ($p_member='',$p_value='')
- {
- // if there is no argument we check all the member
- if ($p_member == '' && $p_value== '' ) {
- foreach (self::$variable as $l=>$k) {
- $this->check($k,$this->$k);
- }
- } else {
- // otherwise we check only the value
- if ( strcmp ($p_member,'pcm_val') == 0 ) {
- if (is_numeric($p_value) ==0 )
- throw new Exception('Poste comptable incorrect '.$p_value);
- else
- return true;
- } else if ( strcmp ($p_member,'pcm_val_parent') == 0 ) {
- if ( is_numeric($p_value) == 0 || ($this->count($p_value) == 0 && $p_value !=0))
- throw new Exception('Poste comptable parent incorrect '.$p_value);
- else
- return true;
- } else if ( strcmp ($p_member,'pcm_lib') == 0 ) {
- return true;
- } else if ( strcmp ($p_member,'pcm_type') == 0 ) {
- foreach (self::$type as $l=>$k) {
- if ( strcmp ($k['value'],$p_value) == 0 ) return true;
- }
- throw new Exception('type de compte incorrect '.$p_value);
- }
- throw new Exception ('Donnee member inconnue '.$p_member);
- }
-
- }
- /*!\brief Get all the value for this object from the database
- * the data member are set
- * \return false if this account doesn't exist otherwise true
- */
- function load()
- {
- $ret=$this->db->exec_sql("select pcm_lib,pcm_val_parent,pcm_type from
- tmp_pcmn where pcm_val=$1",array($this->pcm_val));
- $r=Database::fetch_all($ret);
-
- if ( ! $r ) return false;
- $this->pcm_lib=$r[0]['pcm_lib'];
- $this->pcm_val_parent=$r[0]['pcm_val_parent'];
- $this->pcm_type=$r[0]['pcm_type'];
- return true;
-
- }
- function form($p_table=true){
- $wType=new ISelect();
- $wType->name='p_type';
- $wType->value=self::$type;
-
- if ( ! $p_table ) {
- $ret='
-
-
-
-
-
-
-
-
-
-';
+ function set_parameter($p_string,$p_value)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ if ($this->check($idx,$p_value) == true ) $this->$idx=$p_value;
+ }
+ else
+ exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
- $ret.=$wType->input().' ';
- return $ret;
- }
- else {
- $ret='";
- $ret.=dossier::hidden();
- return $ret;
}
- }
- function count($p_value) {
- $sql="select count(*) from tmp_pcmn where pcm_val=$1";
- return $this->db->get_value($sql,array($p_value));
- }
- /*!\brief for developper only during test */
- static function test_me() {
- $cn=new Database(dossier::id());
+ /*!\brief Return the name of a account
+ * it doesn't change any data member
+ * \return string with the pcm_lib
+ */
+ function get_lib()
+ {
+ $ret=$this->db->exec_sql(
+ "select pcm_lib from tmp_pcmn where
+ pcm_val=$1",array($this->pcm_val));
+ if ( Database::num_row($ret) != 0)
+ {
+ $r=Database::fetch_array($ret);
+ $this->pcm_lib=$r['pcm_lib'];
+ }
+ else
+ {
+ $this->pcm_lib="Poste inconnu";
+ }
+ return $this->pcm_lib;
+ }
+ /*!\brief Check that the value are valid
+ *\return true if all value are valid otherwise false
+ */
+ function check ($p_member='',$p_value='')
+ {
+ // if there is no argument we check all the member
+ if ($p_member == '' && $p_value== '' )
+ {
+ foreach (self::$variable as $l=>$k)
+ {
+ $this->check($k,$this->$k);
+ }
+ }
+ else
+ {
+ // otherwise we check only the value
+ if ( strcmp ($p_member,'pcm_val') == 0 )
+ {
+ if (is_numeric($p_value) ==0 )
+ throw new Exception('Poste comptable incorrect '.$p_value);
+ else
+ return true;
+ }
+ else if ( strcmp ($p_member,'pcm_val_parent') == 0 )
+ {
+ if ( is_numeric($p_value) == 0 || ($this->count($p_value) == 0 && $p_value !=0))
+ throw new Exception('Poste comptable parent incorrect '.$p_value);
+ else
+ return true;
+ }
+ else if ( strcmp ($p_member,'pcm_lib') == 0 )
+ {
+ return true;
+ }
+ else if ( strcmp ($p_member,'pcm_type') == 0 )
+ {
+ foreach (self::$type as $l=>$k)
+ {
+ if ( strcmp ($k['value'],$p_value) == 0 ) return true;
+
+ }
+ throw new Exception('type de compte incorrect '.$p_value);
+ }
+ throw new Exception ('Donnee member inconnue '.$p_member);
+ }
- }
- /**
- *@brief update an accounting, but you can update pcm_val only if
- * this accounting has never been used before */
- function update($p_old) {
- if (strcmp(trim($p_old), trim($this->pcm_val)) !=0 ) {
- $count=$this->db->get_value('select count(*) from jrnx where j_poste=$1',
- array($p_old)
- );
- if ($count != 0)
- throw new Exception('Impossible de changer la valeur: poste déjà utilisé');
}
- $this->pcm_lib=substr($this->pcm_lib,0,150);
- $this->check();
- $sql="update tmp_pcmn set pcm_val=$1, pcm_lib=$2,pcm_val_parent=$3,pcm_type=$4 where pcm_val=$5";
- $Ret=$this->db->exec_sql($sql,array($this->pcm_val,
- $this->pcm_lib,
- $this->pcm_val_parent,
- $this->pcm_type,
- $p_old));
- }
+ /*!\brief Get all the value for this object from the database
+ * the data member are set
+ * \return false if this account doesn't exist otherwise true
+ */
+ function load()
+ {
+ $ret=$this->db->exec_sql("select pcm_lib,pcm_val_parent,pcm_type from
+ tmp_pcmn where pcm_val=$1",array($this->pcm_val));
+ $r=Database::fetch_all($ret);
+
+ if ( ! $r ) return false;
+ $this->pcm_lib=$r[0]['pcm_lib'];
+ $this->pcm_val_parent=$r[0]['pcm_val_parent'];
+ $this->pcm_type=$r[0]['pcm_type'];
+ return true;
+
+ }
+ function form($p_table=true)
+ {
+ $wType=new ISelect();
+ $wType->name='p_type';
+ $wType->value=self::$type;
+
+ if ( ! $p_table )
+ {
+ $ret='
+
+
+
+
+
+
+
+
+
+ ';
+
+ $ret.=$wType->input().' ';
+ return $ret;
+ }
+ else
+ {
+ $ret='";
+ $ret.=dossier::hidden();
+
+ return $ret;
+ }
+ }
+ function count($p_value)
+ {
+ $sql="select count(*) from tmp_pcmn where pcm_val=$1";
+ return $this->db->get_value($sql,array($p_value));
+ }
+ /*!\brief for developper only during test */
+ static function test_me()
+ {
+ $cn=new Database(dossier::id());
+
+ }
+ /**
+ *@brief update an accounting, but you can update pcm_val only if
+ * this accounting has never been used before */
+ function update($p_old)
+ {
+ if (strcmp(trim($p_old), trim($this->pcm_val)) !=0 )
+ {
+ $count=$this->db->get_value('select count(*) from jrnx where j_poste=$1',
+ array($p_old)
+ );
+ if ($count != 0)
+ throw new Exception('Impossible de changer la valeur: poste déjà utilisé');
+ }
+ $this->pcm_lib=substr($this->pcm_lib,0,150);
+ $this->check();
+ $sql="update tmp_pcmn set pcm_val=$1, pcm_lib=$2,pcm_val_parent=$3,pcm_type=$4 where pcm_val=$5";
+ $Ret=$this->db->exec_sql($sql,array($this->pcm_val,
+ $this->pcm_lib,
+ $this->pcm_val_parent,
+ $this->pcm_type,
+ $p_old));
+ }
}
diff --git a/include/class_acc_account_ledger.php b/include/class_acc_account_ledger.php
index c0de94bc4..8dc121892 100644
--- a/include/class_acc_account_ledger.php
+++ b/include/class_acc_account_ledger.php
@@ -28,452 +28,484 @@ require_once("class_ihidden.php");
require_once ('class_database.php');
require_once ('class_dossier.php');
-class Acc_Account_Ledger {
- var $db; /*!< $db database connection */
- var $id; /*!< $id poste_id (pcm_val)*/
- var $label; /*!< $label label of the poste */
- var $parent; /*!< $parent parent account */
- var $row; /*!< $row double array see get_row */
- var $tot_deb; /*!< value set by get_row */
- var $tot_cred; /*!< value by get_row */
- function __construct ($p_cn,$p_id) {
- $this->db=$p_cn;
- $this->id=$p_id;
- }
- /**
- *@brief get the row thanks the resource
- *@return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
- * (tot_deb,tot_credit)
- */
- private function get_row_sql($Res) {
- $array=array();
- $tot_cred=0.0;
- $tot_deb=0.0;
- $Max=Database::num_row($Res);
- if ( $Max == 0 ) return null;
- for ($i=0;$i<$Max;$i++) {
- $array[]=Database::fetch_array($Res,$i);
- if ($array[$i]['j_debit']=='t') {
- $tot_deb+=$array[$i]['deb_montant'] ;
- } else {
- $tot_cred+=$array[$i]['cred_montant'] ;
- }
- }
- $this->row=$array;
- $this->tot_deb=$tot_deb;
- $this->tot_cred=$tot_cred;
- return array($array,$tot_deb,$tot_cred);
-
- }
- /*!
- * \brief Get data for accounting entry between 2 periode
- *
- * \param $p_from periode from
- * \param $p_to end periode
- * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
- * (tot_deb,tot_credit
- *
- */
- function get_row($p_from,$p_to)
+class Acc_Account_Ledger
+{
+ var $db; /*!< $db database connection */
+ var $id; /*!< $id poste_id (pcm_val)*/
+ var $label; /*!< $label label of the poste */
+ var $parent; /*!< $parent parent account */
+ var $row; /*!< $row double array see get_row */
+ var $tot_deb; /*!< value set by get_row */
+ var $tot_cred; /*!< value by get_row */
+ function __construct ($p_cn,$p_id)
{
- $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per');
-
- $Res=$this->db->exec_sql("select distinct j_id,jr_id,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_date,".
- "case when j_debit='t' then j_montant else 0 end as deb_montant,".
- "case when j_debit='f' then j_montant else 0 end as cred_montant,".
- " jr_comment as description,jrn_def_name as jrn_name,".
- "j_debit, jr_internal,jr_pj_number ".
- " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ".
- " left join jrn on jr_grpt_id=j_grpt".
- " where j_poste=".$this->id." and ".$periode.
- " order by j_date");
- return $this->get_row_sql($Res);
+ $this->db=$p_cn;
+ $this->id=$p_id;
}
- /*!
- * \brief Get data for accounting entry between 2 date
- *
- * \param $p_from date from
- * \param $p_to end date
- *\note the data are filtered by the access of the current user
- * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
- * (tot_deb,tot_credit
- *
- */
- function get_row_date($p_from,$p_to,$let=0)
+ /**
+ *@brief get the row thanks the resource
+ *@return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
+ * (tot_deb,tot_credit)
+ */
+ private function get_row_sql($Res)
{
- $user=new User($this->db);
- $filter_sql=$user->get_ledger_sql('ALL',3);
- $sql_let='';
- switch ($let) {
- case 0:
- break;
- case 1:
- $sql_let=' and j_id in (select j_id from letter_cred union select j_id from letter_deb)';
- break;
- case '2':
- $sql_let=' and j_id not in (select j_id from letter_cred union select j_id from letter_deb) ';
- break;
- }
- $Res=$this->db->exec_sql("select jr_id,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_date,".
- "case when j_debit='t' then j_montant else 0 end as deb_montant,".
- "case when j_debit='f' then j_montant else 0 end as cred_montant,".
- " jr_comment as description,jrn_def_name as jrn_name,".
- "j_debit, jr_internal,jr_pj_number,coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter ".
- ",pcm_lib ".
- " from jrnx left join jrn_def on (jrn_def_id=j_jrn_def )".
- " left join jrn on (jr_grpt_id=j_grpt)".
- " left join tmp_pcmn on (j_poste=pcm_val)".
- " where j_poste=$1 and ".
- " ( to_date($2,'DD.MM.YYYY') <= j_date and ".
- " to_date($3,'DD.MM.YYYY') >= j_date )".
- " and $filter_sql $sql_let ".
- " order by j_date",array($this->id,$p_from,$p_to));
- return $this->get_row_sql($Res);
+ $array=array();
+ $tot_cred=0.0;
+ $tot_deb=0.0;
+ $Max=Database::num_row($Res);
+ if ( $Max == 0 ) return null;
+ for ($i=0;$i<$Max;$i++)
+ {
+ $array[]=Database::fetch_array($Res,$i);
+ if ($array[$i]['j_debit']=='t')
+ {
+ $tot_deb+=$array[$i]['deb_montant'] ;
+ }
+ else
+ {
+ $tot_cred+=$array[$i]['cred_montant'] ;
+ }
+ }
+ $this->row=$array;
+ $this->tot_deb=$tot_deb;
+ $this->tot_cred=$tot_cred;
+ return array($array,$tot_deb,$tot_cred);
+
+ }
+ /*!
+ * \brief Get data for accounting entry between 2 periode
+ *
+ * \param $p_from periode from
+ * \param $p_to end periode
+ * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
+ * (tot_deb,tot_credit
+ *
+ */
+ function get_row($p_from,$p_to)
+ {
+ $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per');
+
+ $Res=$this->db->exec_sql("select distinct j_id,jr_id,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_date,".
+ "case when j_debit='t' then j_montant else 0 end as deb_montant,".
+ "case when j_debit='f' then j_montant else 0 end as cred_montant,".
+ " jr_comment as description,jrn_def_name as jrn_name,".
+ "j_debit, jr_internal,jr_pj_number ".
+ " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ".
+ " left join jrn on jr_grpt_id=j_grpt".
+ " where j_poste=".$this->id." and ".$periode.
+ " order by j_date");
+ return $this->get_row_sql($Res);
+ }
+ /*!
+ * \brief Get data for accounting entry between 2 date
+ *
+ * \param $p_from date from
+ * \param $p_to end date
+ *\note the data are filtered by the access of the current user
+ * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
+ * (tot_deb,tot_credit
+ *
+ */
+ function get_row_date($p_from,$p_to,$let=0)
+ {
+ $user=new User($this->db);
+ $filter_sql=$user->get_ledger_sql('ALL',3);
+ $sql_let='';
+ switch ($let)
+ {
+ case 0:
+ break;
+ case 1:
+ $sql_let=' and j_id in (select j_id from letter_cred union select j_id from letter_deb)';
+ break;
+ case '2':
+ $sql_let=' and j_id not in (select j_id from letter_cred union select j_id from letter_deb) ';
+ break;
+ }
+ $Res=$this->db->exec_sql("select jr_id,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_date,".
+ "case when j_debit='t' then j_montant else 0 end as deb_montant,".
+ "case when j_debit='f' then j_montant else 0 end as cred_montant,".
+ " jr_comment as description,jrn_def_name as jrn_name,".
+ "j_debit, jr_internal,jr_pj_number,coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter ".
+ ",pcm_lib ".
+ " from jrnx left join jrn_def on (jrn_def_id=j_jrn_def )".
+ " left join jrn on (jr_grpt_id=j_grpt)".
+ " left join tmp_pcmn on (j_poste=pcm_val)".
+ " where j_poste=$1 and ".
+ " ( to_date($2,'DD.MM.YYYY') <= j_date and ".
+ " to_date($3,'DD.MM.YYYY') >= j_date )".
+ " and $filter_sql $sql_let ".
+ " order by j_date",array($this->id,$p_from,$p_to));
+ return $this->get_row_sql($Res);
}
- /*!\brief Return the name of a account
- * it doesn't change any data member
- * \return string with the pcm_lib
- */
- function get_name() {
- $ret=$this->db->exec_sql(
- "select pcm_lib from tmp_pcmn where
- pcm_val=$1",array($this->id));
- if ( Database::num_row($ret) != 0) {
- $r=Database::fetch_array($ret);
- $this->name=$r['pcm_lib'];
- } else {
- $this->name="Poste inconnu";
- }
- return $this->name;
- }
- /*!\brief check if the poste exist in the tmp_pcmn
- *\return the number of line (normally 1 or 0)
- */
- function do_exist() {
- $sql="select pcm_val from tmp_pcmn where pcm_val= $1";
- $ret=$this->db->exec_sql($sql,array($this->id));
- return Database::num_row($ret) ;
- }
- /*!\brief Get all the value for this object from the database
- * the data member are set
- * \return false if this account doesn't exist otherwise true
- */
- function load()
- {
- $ret=$this->db->exec_sql("select pcm_lib,pcm_val_parent from
- tmp_pcmn where pcm_val=$1",array($this->id));
- $r=Database::fetch_all($ret);
-
- if ( ! $r ) return false;
- $this->label=$r[0]['pcm_lib'];
- $this->parent=$r[0]['pcm_val_parent'];
- return true;
-
- }
- /*!\brief Get all the value for this object from the database
- * the data member are set
- * \return false if this account doesn't exist otherwise true
- */
- function get()
+ /*!\brief Return the name of a account
+ * it doesn't change any data member
+ * \return string with the pcm_lib
+ */
+ function get_name()
{
- echo "OBSOLETE Acc_Account_Ledger->get(), a remplacer par Acc_Account_Ledger->load()";
- return $this->load();
+ $ret=$this->db->exec_sql(
+ "select pcm_lib from tmp_pcmn where
+ pcm_val=$1",array($this->id));
+ if ( Database::num_row($ret) != 0)
+ {
+ $r=Database::fetch_array($ret);
+ $this->name=$r['pcm_lib'];
+ }
+ else
+ {
+ $this->name="Poste inconnu";
+ }
+ return $this->name;
+ }
+ /*!\brief check if the poste exist in the tmp_pcmn
+ *\return the number of line (normally 1 or 0)
+ */
+ function do_exist()
+ {
+ $sql="select pcm_val from tmp_pcmn where pcm_val= $1";
+ $ret=$this->db->exec_sql($sql,array($this->id));
+ return Database::num_row($ret) ;
+ }
+ /*!\brief Get all the value for this object from the database
+ * the data member are set
+ * \return false if this account doesn't exist otherwise true
+ */
+ function load()
+ {
+ $ret=$this->db->exec_sql("select pcm_lib,pcm_val_parent from
+ tmp_pcmn where pcm_val=$1",array($this->id));
+ $r=Database::fetch_all($ret);
+
+ if ( ! $r ) return false;
+ $this->label=$r[0]['pcm_lib'];
+ $this->parent=$r[0]['pcm_val_parent'];
+ return true;
+
+ }
+ /*!\brief Get all the value for this object from the database
+ * the data member are set
+ * \return false if this account doesn't exist otherwise true
+ */
+ function get()
+ {
+ echo "OBSOLETE Acc_Account_Ledger->get(), a remplacer par Acc_Account_Ledger->load()";
+ return $this->load();
}
- /*!
- * \brief give the balance of an account
- *
- * \return
- * balance of the account
- *
- */
- function get_solde($p_cond=" true ") {
- $Res=$this->db->exec_sql("select sum(deb) as sum_deb, sum(cred) as sum_cred from
- ( select j_poste,
+ /*!
+ * \brief give the balance of an account
+ *
+ * \return
+ * balance of the account
+ *
+ */
+ function get_solde($p_cond=" true ")
+ {
+ $Res=$this->db->exec_sql("select sum(deb) as sum_deb, sum(cred) as sum_cred from
+ ( select j_poste,
+ case when j_debit='t' then j_montant else 0 end as deb,
+ case when j_debit='f' then j_montant else 0 end as cred
+ from jrnx join tmp_pcmn on j_poste=pcm_val
+ where
+ j_poste::text like ('$this->id'::text) and
+ $p_cond
+ ) as m ");
+ $Max=Database::num_row($Res);
+ if ($Max==0) return 0;
+ $r=Database::fetch_array($Res,0);
+
+ return abs($r['sum_deb']-$r['sum_cred']);
+ }
+ /*!
+ * \brief give the balance of an account
+ * \return
+ * balance of the account
+ *
+ */
+ function get_solde_detail($p_cond="")
+ {
+
+ if ( $p_cond != "") $p_cond=" and ".$p_cond;
+ $sql="select sum(deb) as sum_deb, sum(cred) as sum_cred from
+ ( select j_poste,
case when j_debit='t' then j_montant else 0 end as deb,
case when j_debit='f' then j_montant else 0 end as cred
- from jrnx join tmp_pcmn on j_poste=pcm_val
- where
- j_poste::text like ('$this->id'::text) and
- $p_cond
- ) as m ");
- $Max=Database::num_row($Res);
- if ($Max==0) return 0;
- $r=Database::fetch_array($Res,0);
+ from jrnx
+ where
+ j_poste::text like ('$this->id'::text)
+ $p_cond
+ ) as m ";
- return abs($r['sum_deb']-$r['sum_cred']);
-}
- /*!
- * \brief give the balance of an account
- * \return
- * balance of the account
- *
- */
-function get_solde_detail($p_cond="") {
-
- if ( $p_cond != "") $p_cond=" and ".$p_cond;
- $sql="select sum(deb) as sum_deb, sum(cred) as sum_cred from
- ( select j_poste,
- case when j_debit='t' then j_montant else 0 end as deb,
- case when j_debit='f' then j_montant else 0 end as cred
- from jrnx
- where
- j_poste::text like ('$this->id'::text)
- $p_cond
- ) as m ";
-
- $Res=$this->db->exec_sql($sql);
- $Max=Database::num_row($Res);
-
- if ($Max==0) {
- return array('debit'=>0,
- 'credit'=>0,
- 'solde'=>0) ;
- }
- $r=Database::fetch_array($Res,0);
- // if p_start is < p_end the query returns null to avoid any problem
- // we set it to 0
- if ($r['sum_deb']=='')
- $r['sum_deb']=0.0;
- if ($r['sum_cred']=='')
- $r['sum_cred']=0.0;
-
- return array('debit'=>$r['sum_deb'],
- 'credit'=>$r['sum_cred'],
- 'solde'=>abs($r['sum_deb']-$r['sum_cred']));
-}
-/*!
- * \brief isTva tell is a poste is used for VAT
- * \param none
- *
- *
- * \return 1 is Yes otherwise 0
- */
- function isTVA()
- {
- // Load TVA array
- $a_TVA=$this->db->get_array('select tva_poste
- from tva_rate');
- foreach ( $a_TVA as $line_tva)
- {
- if ( $line_tva['tva_poste'] == '' )
- continue;
- list($tva_deb,$tva_cred)=explode(',',$line_tva['tva_poste']);
- if ( $this->id == $tva_deb ||
- $this->id == $tva_cred )
- {
- return 1;
- }
- }
- return 0;
-
- }
-/*!
- * \brief HtmlTable, display a HTML of a poste for the asked period
- * \param none
- *
- * \return none
- */
-
-
- function HtmlTable($p_array=null,$let=0 )
- {
- if ( $p_array==null)$p_array=$_REQUEST;
- $this->get_name();
- list($array,$tot_deb,$tot_cred)=$this->get_row_date( $p_array['from_periode'],
- $p_array['to_periode'],$let
- );
-
- if ( count($this->row ) == 0 )
- return;
-
- $rep="";
-
- echo ''.$this->id." ".$this->name.' ';
- echo "";
-
- return;
- }
-
- /*!
- * \brief Display HTML Table Header (button)
- *
- * \return none
- */
- static function HtmlTableHeader($actiontarget="poste")
- {
- $hid=new IHidden();
- echo '';
- echo "
";
- echo '';
- $str_ople=(isset($_REQUEST['ople']))?HtmlInput::hidden('ople',$_REQUEST['ople']):'';
- echo ''.
- dossier::hidden().
- HtmlInput::submit('bt_other',"Autre poste").
- $hid->input("type","poste").$hid->input('p_action','impress')." ";
-
- echo ''.
- dossier::hidden().
- HtmlInput::submit('bt_pdf',"Export PDF").
- $hid->input("type","poste").$str_ople.
- $hid->input('p_action','impress').
- $hid->input("from_periode",$_REQUEST['from_periode']).
- $hid->input("to_periode",$_REQUEST['to_periode']);
-
- if (isset($_REQUEST['poste_id'])) echo $hid->input("poste_id",$_REQUEST['poste_id']);
-
- if (isset($_REQUEST['poste_fille']))
- echo $hid->input('poste_fille','on');
- if (isset($_REQUEST['oper_detail']))
- echo $hid->input('oper_detail','on');
-
- echo " ";
-
- echo ''.
- dossier::hidden().
- HtmlInput::submit('bt_csv',"Export CSV").
- $hid->input("type","poste").$str_ople.
- $hid->input('p_action','impress').
- $hid->input("from_periode",$_REQUEST['from_periode']).
- $hid->input("to_periode",$_REQUEST['to_periode']);
- if (isset($_REQUEST['poste_fille']))
- echo $hid->input('poste_fille','on');
- if (isset($_REQUEST['oper_detail']))
- echo $hid->input('oper_detail','on');
- if (isset($_REQUEST['poste_id'])) echo $hid->input("poste_id",$_REQUEST['poste_id']);
-
- echo " ";
- echo "
";
- echo '
';
-
- }
-/*!
- * \brief verify that the poste belong to a ledger
- *
- * \return 0 ok, -1 no
- */
- function belong_ledger($p_jrn) {
- $filter=$this->db->get_value("select jrn_def_class_cred from jrn_def where jrn_def_id=$p_jrn");
- if ( trim ($filter) == '')
- return 0;
-
- $valid_cred=explode(" ",$filter);
- $sql="select count(*) as poste from tmp_pcmn where ";
- // Creation query
- $or="";
- $SqlFilter="";
- foreach ( $valid_cred as $item_cred) {
- if ( strlen (trim($item_cred))) {
- if ( strstr($item_cred,"*") == true ) {
- $item_cred=strtr($item_cred,"*","%");
- $SqlItem="$or pcm_val::text like '$item_cred'";
- $or=" or ";
- } else {
- $SqlItem="$or pcm_val::text = '$item_cred' ";
- $or=" or ";
- }
- $SqlFilter=$SqlFilter.$SqlItem;
- }
- }//foreach
- $sql.=$SqlFilter.' and pcm_val='.$this->id;
- $max=$this->db->get_value($sql);
- if ($max > 0 )
- return 0;
- else
- return -1;
- }
- /*!\brief With the id of the ledger, get the col jrn_def_class_deb
- *\param $p_jrn jrn_id
- *\return array of value, or an empty array if nothing is found
- *\note
- *\see
- */
- function get_account_ledger($p_jrn) {
- $l=new Acc_Ledger($this->db,$p_jrn);
- $row=$l->get_propertie();
- if ( strlen(trim($row['jrn_def_class_deb'])) == 0 ) return array();
- $valid_account=explode(" ",$row['jrn_def_class_deb']);
- return $valid_account;
- }
- /*!\brief build a sql statement thanks a array found with get_account_ledger
- *
- *\param $p_jrn jrn_id
- *\return an emty string if nothing is found or a valid SQL statement like
-\code
-pcm_val like ... or pcm_val like ...
-\endcode
- *\note
- *\see get_account_ledger
- */
- function build_sql_account($p_jrn) {
- $array=$this->get_account_ledger($p_jrn);
- if ( empty($array) ) return "";
- $sql="";
- foreach ( $array as $item_cred) {
- if ( strlen (trim($item_cred))>0 ) {
- if ( strstr($item_cred,"*") == true ) {
- $item_cred=strtr($item_cred,"*","%");
- $sql_tmp=" pcm_val::text like '$item_cred' or";
- } else {
- $sql_tmp=" pcm_val::text = '$item_cred' or";
- }
- $sql.=$sql_tmp;
- }
- }//foreach
- /* remove the last or */
- $sql=substr($sql,0,strlen($sql)-2);
- return $sql;
- }
- static function test_me() {
- $cn=new Database(dossier::id());
- $a=new Acc_Account_Ledger($cn,550);
- echo ' Journal 4 '.$a->belong_ledger(4);
-
- }
+ $Res=$this->db->exec_sql($sql);
+ $Max=Database::num_row($Res);
+
+ if ($Max==0)
+ {
+ return array('debit'=>0,
+ 'credit'=>0,
+ 'solde'=>0) ;
+ }
+ $r=Database::fetch_array($Res,0);
+// if p_start is < p_end the query returns null to avoid any problem
+// we set it to 0
+ if ($r['sum_deb']=='')
+ $r['sum_deb']=0.0;
+ if ($r['sum_cred']=='')
+ $r['sum_cred']=0.0;
+
+ return array('debit'=>$r['sum_deb'],
+ 'credit'=>$r['sum_cred'],
+ 'solde'=>abs($r['sum_deb']-$r['sum_cred']));
+ }
+ /*!
+ * \brief isTva tell is a poste is used for VAT
+ * \param none
+ *
+ *
+ * \return 1 is Yes otherwise 0
+ */
+ function isTVA()
+ {
+ // Load TVA array
+ $a_TVA=$this->db->get_array('select tva_poste
+ from tva_rate');
+ foreach ( $a_TVA as $line_tva)
+ {
+ if ( $line_tva['tva_poste'] == '' )
+ continue;
+ list($tva_deb,$tva_cred)=explode(',',$line_tva['tva_poste']);
+ if ( $this->id == $tva_deb ||
+ $this->id == $tva_cred )
+ {
+ return 1;
+ }
+ }
+ return 0;
+
+ }
+ /*!
+ * \brief HtmlTable, display a HTML of a poste for the asked period
+ * \param none
+ *
+ * \return none
+ */
+
+
+ function HtmlTable($p_array=null,$let=0 )
+ {
+ if ( $p_array==null)$p_array=$_REQUEST;
+ $this->get_name();
+ list($array,$tot_deb,$tot_cred)=$this->get_row_date( $p_array['from_periode'],
+ $p_array['to_periode'],$let
+ );
+
+ if ( count($this->row ) == 0 )
+ return;
+
+ $rep="";
+
+ echo ''.$this->id." ".$this->name.' ';
+ echo "";
+
+ return;
+ }
+
+ /*!
+ * \brief Display HTML Table Header (button)
+ *
+ * \return none
+ */
+ static function HtmlTableHeader($actiontarget="poste")
+ {
+ $hid=new IHidden();
+ echo '';
+ echo "
";
+ echo '';
+ $str_ople=(isset($_REQUEST['ople']))?HtmlInput::hidden('ople',$_REQUEST['ople']):'';
+ echo ''.
+ dossier::hidden().
+ HtmlInput::submit('bt_other',"Autre poste").
+ $hid->input("type","poste").$hid->input('p_action','impress')." ";
+
+ echo ''.
+ dossier::hidden().
+ HtmlInput::submit('bt_pdf',"Export PDF").
+ $hid->input("type","poste").$str_ople.
+ $hid->input('p_action','impress').
+ $hid->input("from_periode",$_REQUEST['from_periode']).
+ $hid->input("to_periode",$_REQUEST['to_periode']);
+
+ if (isset($_REQUEST['poste_id'])) echo $hid->input("poste_id",$_REQUEST['poste_id']);
+
+ if (isset($_REQUEST['poste_fille']))
+ echo $hid->input('poste_fille','on');
+ if (isset($_REQUEST['oper_detail']))
+ echo $hid->input('oper_detail','on');
+
+ echo " ";
+
+ echo ''.
+ dossier::hidden().
+ HtmlInput::submit('bt_csv',"Export CSV").
+ $hid->input("type","poste").$str_ople.
+ $hid->input('p_action','impress').
+ $hid->input("from_periode",$_REQUEST['from_periode']).
+ $hid->input("to_periode",$_REQUEST['to_periode']);
+ if (isset($_REQUEST['poste_fille']))
+ echo $hid->input('poste_fille','on');
+ if (isset($_REQUEST['oper_detail']))
+ echo $hid->input('oper_detail','on');
+ if (isset($_REQUEST['poste_id'])) echo $hid->input("poste_id",$_REQUEST['poste_id']);
+
+ echo " ";
+ echo "
";
+ echo '
';
+
+ }
+ /*!
+ * \brief verify that the poste belong to a ledger
+ *
+ * \return 0 ok, -1 no
+ */
+ function belong_ledger($p_jrn)
+ {
+ $filter=$this->db->get_value("select jrn_def_class_cred from jrn_def where jrn_def_id=$p_jrn");
+ if ( trim ($filter) == '')
+ return 0;
+
+ $valid_cred=explode(" ",$filter);
+ $sql="select count(*) as poste from tmp_pcmn where ";
+ // Creation query
+ $or="";
+ $SqlFilter="";
+ foreach ( $valid_cred as $item_cred)
+ {
+ if ( strlen (trim($item_cred)))
+ {
+ if ( strstr($item_cred,"*") == true )
+ {
+ $item_cred=strtr($item_cred,"*","%");
+ $SqlItem="$or pcm_val::text like '$item_cred'";
+ $or=" or ";
+ }
+ else
+ {
+ $SqlItem="$or pcm_val::text = '$item_cred' ";
+ $or=" or ";
+ }
+ $SqlFilter=$SqlFilter.$SqlItem;
+ }
+ }//foreach
+ $sql.=$SqlFilter.' and pcm_val='.$this->id;
+ $max=$this->db->get_value($sql);
+ if ($max > 0 )
+ return 0;
+ else
+ return -1;
+ }
+ /*!\brief With the id of the ledger, get the col jrn_def_class_deb
+ *\param $p_jrn jrn_id
+ *\return array of value, or an empty array if nothing is found
+ *\note
+ *\see
+ */
+ function get_account_ledger($p_jrn)
+ {
+ $l=new Acc_Ledger($this->db,$p_jrn);
+ $row=$l->get_propertie();
+ if ( strlen(trim($row['jrn_def_class_deb'])) == 0 ) return array();
+ $valid_account=explode(" ",$row['jrn_def_class_deb']);
+ return $valid_account;
+ }
+ /*!\brief build a sql statement thanks a array found with get_account_ledger
+ *
+ *\param $p_jrn jrn_id
+ *\return an emty string if nothing is found or a valid SQL statement like
+ \code
+ pcm_val like ... or pcm_val like ...
+ \endcode
+ *\note
+ *\see get_account_ledger
+ */
+ function build_sql_account($p_jrn)
+ {
+ $array=$this->get_account_ledger($p_jrn);
+ if ( empty($array) ) return "";
+ $sql="";
+ foreach ( $array as $item_cred)
+ {
+ if ( strlen (trim($item_cred))>0 )
+ {
+ if ( strstr($item_cred,"*") == true )
+ {
+ $item_cred=strtr($item_cred,"*","%");
+ $sql_tmp=" pcm_val::text like '$item_cred' or";
+ }
+ else
+ {
+ $sql_tmp=" pcm_val::text = '$item_cred' or";
+ }
+ $sql.=$sql_tmp;
+ }
+ }//foreach
+ /* remove the last or */
+ $sql=substr($sql,0,strlen($sql)-2);
+ return $sql;
+ }
+ static function test_me()
+ {
+ $cn=new Database(dossier::id());
+ $a=new Acc_Account_Ledger($cn,550);
+ echo ' Journal 4 '.$a->belong_ledger(4);
+
+ }
}
diff --git a/include/class_acc_balance.php b/include/class_acc_balance.php
index fb21fbeb3..1d70d0e66 100644
--- a/include/class_acc_balance.php
+++ b/include/class_acc_balance.php
@@ -1,4 +1,4 @@
-get_ledger */
- var $from_poste; /*!< from_poste filter on the post */
- var $to_poste; /*!< to_poste filter on the post*/
- function Acc_Balance($p_cn) {
- $this->db=$p_cn;
- $this->jrn=null;
- $from_poste="";
- $to_poste="";
- }
+class Acc_Balance
+{
+ var $db; /*! < database connection */
+ var $row; /*! < row for ledger*/
+ var $jrn; /*!< idx of a table of ledger create by user->get_ledger */
+ var $from_poste; /*!< from_poste filter on the post */
+ var $to_poste; /*!< to_poste filter on the post*/
+ function Acc_Balance($p_cn)
+ {
+ $this->db=$p_cn;
+ $this->jrn=null;
+ $from_poste="";
+ $to_poste="";
+ }
-/*!
- * \brief retrieve all the row from the ledger in the range of a periode
- * \param $p_from_periode start periode (p_id)
- * \param $p_to_periode end periode (p_id)
- *
- * \return a double array
- * array of
- * - $a['poste']
- * - $a['label']
- * - $a['sum_deb']
- * - $a['sum_cred']
- * - $a['solde_deb']
- * - $a['solde_cred']
- */
- function get_row($p_from_periode,$p_to_periode) {
-
- // filter on requested periode
- $per_sql=sql_filter_per($this->db,$p_from_periode,$p_to_periode,'p_id','j_tech_per');
-
-
- $and=""; $jrn="";
- $from_poste="";$to_poste="";
- /* if several ledgers are asked then we filter here */
- if ($this->jrn!== null){
- $user=new User($this->db);
- /**
- *@file
- *@bug the get_ledger here is not valid and useless we just need a list of the
- * asked ledgers
+ /*!
+ * \brief retrieve all the row from the ledger in the range of a periode
+ * \param $p_from_periode start periode (p_id)
+ * \param $p_to_periode end periode (p_id)
+ *
+ * \return a double array
+ * array of
+ * - $a['poste']
+ * - $a['label']
+ * - $a['sum_deb']
+ * - $a['sum_cred']
+ * - $a['solde_deb']
+ * - $a['solde_cred']
*/
+ function get_row($p_from_periode,$p_to_periode)
+ {
- $jrn=" j_jrn_def in (";$comma='';
- for ($e=0;$ejrn);$e++) {
- $jrn.=$comma.$this->jrn[$e];
- $comma=',';
- }
- $jrn.=')';
- $and=" and ";
- }
+ // filter on requested periode
+ $per_sql=sql_filter_per($this->db,$p_from_periode,$p_to_periode,'p_id','j_tech_per');
- if ( strlen(trim($this->from_poste)) != 0 && $this->from_poste!=-1 ) {
- $from_poste=" $and j_poste::text >= '".$this->from_poste."'"; $and=" and ";
- }
- if ( strlen(trim($this->to_poste)) != 0 && $this->to_poste!=-1 ) {
- $to_poste=" $and j_poste::text <= '".$this->to_poste."'"; $and=" and ";
- }
- $user=new User($this->db);
- $filter_sql=$user->get_ledger_sql('ALL',3);
- // build query
- $sql="select j_poste,sum(deb) as sum_deb, sum(cred) as sum_cred from
- ( select j_poste,
+ $and="";
+ $jrn="";
+ $from_poste="";
+ $to_poste="";
+ /* if several ledgers are asked then we filter here */
+ if ($this->jrn!== null)
+ {
+ $user=new User($this->db);
+ /**
+ *@file
+ *@bug the get_ledger here is not valid and useless we just need a list of the
+ * asked ledgers
+ */
+
+ $jrn=" j_jrn_def in (";
+ $comma='';
+ for ($e=0;$ejrn);$e++)
+ {
+ $jrn.=$comma.$this->jrn[$e];
+ $comma=',';
+ }
+ $jrn.=')';
+ $and=" and ";
+ }
+
+ if ( strlen(trim($this->from_poste)) != 0 && $this->from_poste!=-1 )
+ {
+ $from_poste=" $and j_poste::text >= '".$this->from_poste."'";
+ $and=" and ";
+ }
+ if ( strlen(trim($this->to_poste)) != 0 && $this->to_poste!=-1 )
+ {
+ $to_poste=" $and j_poste::text <= '".$this->to_poste."'";
+ $and=" and ";
+ }
+ $user=new User($this->db);
+ $filter_sql=$user->get_ledger_sql('ALL',3);
+
+ // build query
+ $sql="select j_poste,sum(deb) as sum_deb, sum(cred) as sum_cred from
+ ( select j_poste,
case when j_debit='t' then j_montant else 0 end as deb,
case when j_debit='f' then j_montant else 0 end as cred
from jrnx join tmp_pcmn on (j_poste=pcm_val)
- left join parm_periode on (j_tech_per = p_id)
- join jrn_def on (j_jrn_def=jrn_def_id)
- where
- $jrn $from_poste $to_poste
-$and $filter_sql
+ left join parm_periode on (j_tech_per = p_id)
+ join jrn_def on (j_jrn_def=jrn_def_id)
+ where
+ $jrn $from_poste $to_poste
+ $and $filter_sql
and
- $per_sql ) as m group by j_poste order by j_poste::text";
- $cn=clone $this->db;
- $Res=$this->db->exec_sql($sql);
+ $per_sql ) as m group by j_poste order by j_poste::text";
+ $cn=clone $this->db;
+ $Res=$this->db->exec_sql($sql);
- $tot_cred= 0.0;
- $tot_deb= 0.0;
- $tot_deb_saldo=0.0;
- $tot_cred_saldo=0.0;
- $M=$this->db->size();
+ $tot_cred= 0.0;
+ $tot_deb= 0.0;
+ $tot_deb_saldo=0.0;
+ $tot_cred_saldo=0.0;
+ $M=$this->db->size();
- // Load the array
- for ($i=0; $i <$M;$i++) {
- $r=$this->db->fetch($i);
- $poste=new Acc_Account($cn,$r['j_poste']);
+ // Load the array
+ for ($i=0; $i <$M;$i++)
+ {
+ $r=$this->db->fetch($i);
+ $poste=new Acc_Account($cn,$r['j_poste']);
- $a['poste']=$r['j_poste'];
- $a['label']=substr($poste->get_lib(),0,40);
- $a['sum_deb']=round($r['sum_deb'],2);
- $a['sum_cred']=round($r['sum_cred'],2);
- $a['solde_deb']=round(( $a['sum_deb'] >= $a['sum_cred'] )? $a['sum_deb']- $a['sum_cred']:0,2);
- $a['solde_cred']=round(( $a['sum_deb'] <= $a['sum_cred'] )?$a['sum_cred']-$a['sum_deb']:0,2);
- $array[$i]=$a;
- $tot_cred+= $a['sum_cred'];
- $tot_deb+= $a['sum_deb'];
- $tot_deb_saldo+= $a['solde_deb'];
- $tot_cred_saldo+= $a['solde_cred'];
-
-
- }//for i
- // Add the saldo
- $i+=1;
- $a['poste']="";
- $a['label']="Totaux ";
- $a['sum_deb']=$tot_deb;
- $a['sum_cred']=$tot_cred;
- $a['solde_deb']=$tot_deb_saldo;
- $a['solde_cred']=$tot_cred_saldo;
- $array[$i]=$a;
- $this->row=$array;
- return $array;
+ $a['poste']=$r['j_poste'];
+ $a['label']=substr($poste->get_lib(),0,40);
+ $a['sum_deb']=round($r['sum_deb'],2);
+ $a['sum_cred']=round($r['sum_cred'],2);
+ $a['solde_deb']=round(( $a['sum_deb'] >= $a['sum_cred'] )? $a['sum_deb']- $a['sum_cred']:0,2);
+ $a['solde_cred']=round(( $a['sum_deb'] <= $a['sum_cred'] )?$a['sum_cred']-$a['sum_deb']:0,2);
+ $array[$i]=$a;
+ $tot_cred+= $a['sum_cred'];
+ $tot_deb+= $a['sum_deb'];
+ $tot_deb_saldo+= $a['solde_deb'];
+ $tot_cred_saldo+= $a['solde_cred'];
- }
- /**
- * set the $this->jrn to the cat
- */
- function filter_cat($p_array) {
- if ( empty($p_array) ) { $bal->jn=null;return;}
- /* get the list of jrn of the cat. */
- $array=Acc_Ledger::array_cat();
- $jrn=array();
- for ($e=0;$edb->get_array('select jrn_def_id from jrn_def where jrn_def_type=$1',array($array[$e]['cat']));
- for ( $f=0;$f < count($t_a);$f++) $this->jrn[]=$t_a[$f]['jrn_def_id'];
- }
+ }//for i
+ // Add the saldo
+ $i+=1;
+ $a['poste']="";
+ $a['label']="Totaux ";
+ $a['sum_deb']=$tot_deb;
+ $a['sum_cred']=$tot_cred;
+ $a['solde_deb']=$tot_deb_saldo;
+ $a['solde_cred']=$tot_cred_saldo;
+ $array[$i]=$a;
+ $this->row=$array;
+ return $array;
+
}
+ /**
+ * set the $this->jrn to the cat
+ */
+ function filter_cat($p_array)
+ {
+ if ( empty($p_array) )
+ {
+ $bal->jn=null;
+ return;
+ }
+ /* get the list of jrn of the cat. */
- }
+ $array=Acc_Ledger::array_cat();
+ $jrn=array();
+ for ($e=0;$edb->get_array('select jrn_def_id from jrn_def where jrn_def_type=$1',array($array[$e]['cat']));
+ for ( $f=0;$f < count($t_a);$f++) $this->jrn[]=$t_a[$f]['jrn_def_id'];
+ }
+ }
+
+ }
}
diff --git a/include/class_acc_bilan.php b/include/class_acc_bilan.php
index 5c7ff2406..baebeb382 100644
--- a/include/class_acc_bilan.php
+++ b/include/class_acc_bilan.php
@@ -20,7 +20,7 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*!\file
+/*!\file
* \brief this class handle the different bilan, from the table bilan
*
*/
@@ -35,593 +35,649 @@ require_once ('class_acc_account_ledger.php');
* \brief this class handle the different bilan, from the table bilan, parse the form and replace
* in the template
*/
-class Acc_Bilan {
- var $db; /*!< database connection */
- var $b_id; /*!< id of the bilan (bilan.b_id) */
- var $from; /*!< from periode */
- var $to; /*!< end periode */
+class Acc_Bilan
+{
+ var $db; /*!< database connection */
+ var $b_id; /*!< id of the bilan (bilan.b_id) */
+ var $from; /*!< from periode */
+ var $to; /*!< end periode */
- function Acc_Bilan($p_cn) {
- $this->db=$p_cn;
- }
-/*!
- * \brief return a string with the form for selecting the periode and
- * the type of bilan
- * \param $p_filter_year filter on a year
- *
- * \return a string
- */
- function display_form($p_filter_year="") {
- $r="";
- $r.=dossier::hidden();
- $r.= '';
+ function Acc_Bilan($p_cn)
+ {
+ $this->db=$p_cn;
+ }
+ /*!
+ * \brief return a string with the form for selecting the periode and
+ * the type of bilan
+ * \param $p_filter_year filter on a year
+ *
+ * \return a string
+ */
+ function display_form($p_filter_year="")
+ {
+ $r="";
+ $r.=dossier::hidden();
+ $r.= '';
- $r.='';
+ $r.=' ';
// filter on the current year
- $w=new ISelect();
- $w->table=1;
+ $w=new ISelect();
+ $w->table=1;
- $periode_start=$this->db->make_array("select p_id,to_char(p_start,'DD-MM-YYYY') from parm_periode $p_filter_year order by p_start,p_end");
-
- $periode_end=$this->db->make_array("select p_id,to_char(p_end,'DD-MM-YYYY') from parm_periode $p_filter_year order by p_end,p_start");
+ $periode_start=$this->db->make_array("select p_id,to_char(p_start,'DD-MM-YYYY') from parm_periode $p_filter_year order by p_start,p_end");
- $w->label=_("Depuis");
- $w->value=$this->from;
- $w->selected=$this->from;
- $r.= td($w->input('from_periode',$periode_start));
- $w->label=_(" jusque ");
- $w->value=$this->to;
- $w->selected=$this->to;
- $r.= td($w->input('to_periode',$periode_end));
- $r.= " ";
- $r.="";
- $mod=new ISelect();
- $mod->table=1;
- $mod->value=$this->db->make_array("select b_id, b_name from bilan order by b_name");
- $mod->label=_("Choix du bilan");
- $r.=td($mod->input('b_id'));
- $r.=" ";
- $r.= '
';
- return $r;
- }
- /*!\brief check and warn if an accound has the wrong saldo
- * \param $p_message legend of the fieldset
- * \param $p_type type of the Acccount ACT actif, ACTINV...
- * \param $p_type the saldo must debit or credit
- */
- private function warning($p_message,$p_type,$p_deb) {
- $sql="select pcm_val,pcm_lib from tmp_pcmn where pcm_type='$p_type'";
- $res=$this->db->exec_sql($sql);
- if ( Database::num_row($res) ==0 )
- return;
- $count=0;
- $nRow=Database::num_row($res);
+ $periode_end=$this->db->make_array("select p_id,to_char(p_end,'DD-MM-YYYY') from parm_periode $p_filter_year order by p_end,p_start");
- $ret="";
- $obj=new Acc_Account_Ledger($this->db,0);
- for ($i=0;$i<$nRow;$i++) {
-
- $line=Database::fetch_array($res,$i);
- /* set the periode filter */
- $sql=sql_filter_per($this->db,$this->from,$this->to,'p_id','j_tech_per');
- $obj->id=$line['pcm_val'];
-
- $solde=$obj->get_solde_detail($sql);
- $solde_signed=$solde['debit']-$solde['credit'];
-
- if (
- ($solde_signed < 0 && $p_deb == 'D' ) ||
- ($solde_signed > 0 && $p_deb == 'C' )
- ) {
- $ret.= 'Anomalie pour le compte '.$line['pcm_val'].
- $line['pcm_lib'].
- " D: ".$solde['debit'].
- " C: ".$solde['credit']." diff ".$solde['solde'];
- $count++;
- }
-
+ $w->label=_("Depuis");
+ $w->value=$this->from;
+ $w->selected=$this->from;
+ $r.= td($w->input('from_periode',$periode_start));
+ $w->label=_(" jusque ");
+ $w->value=$this->to;
+ $w->selected=$this->to;
+ $r.= td($w->input('to_periode',$periode_end));
+ $r.= "";
+ $r.="";
+ $mod=new ISelect();
+ $mod->table=1;
+ $mod->value=$this->db->make_array("select b_id, b_name from bilan order by b_name");
+ $mod->label=_("Choix du bilan");
+ $r.=td($mod->input('b_id'));
+ $r.=" ";
+ $r.= '
';
+ return $r;
}
+ /*!\brief check and warn if an accound has the wrong saldo
+ * \param $p_message legend of the fieldset
+ * \param $p_type type of the Acccount ACT actif, ACTINV...
+ * \param $p_type the saldo must debit or credit
+ */
+ private function warning($p_message,$p_type,$p_deb)
+ {
+ $sql="select pcm_val,pcm_lib from tmp_pcmn where pcm_type='$p_type'";
+ $res=$this->db->exec_sql($sql);
+ if ( Database::num_row($res) ==0 )
+ return;
+ $count=0;
+ $nRow=Database::num_row($res);
- echo '';
- echo ''.$p_message.' ';
- if ( $count <> 0 ) {
- echo ''.$ret.' ';
- echo 'Nbres anomalies : '.$count.' ';
- } else
- echo " Pas d'anomalie détectée";
- echo ' ';
-
-
- }
- /*!\brief verify that the saldo is good for the type of account */
- function verify() {
- echo ' Comptes normaux ';
- $this->warning('Actif avec un solde crediteur','ACT','D');
- $this->warning('Passif avec un solde debiteur','PAS','C');
- $this->warning('Compte de resultat : Charge avec un solde crediteur','CHA','D');
- $this->warning('Compte de resultat : produit avec un solde debiteur','PRO','C');
- echo ' ';
- echo ' Comptes inverses ';
- $this->warning('Compte inverse : actif avec un solde debiteur','ACTINV','C');
- $this->warning('Compte inverse : passif avec un solde crediteur','PASINV','D');
- $this->warning('Compte inverse : Charge avec un solde debiteur','CHAINV','C');
- $this->warning('Compte inverse : produit avec un solde crediteur','PROINV','D');
- echo 'Solde ';
- /* set the periode filter */
- $sql_periode=sql_filter_per($this->db,$this->from,$this->to,'p_id','j_tech_per');
- /* debit Actif */
- $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
- " where j_debit='t' and (pcm_type='ACT' or pcm_type='ACTINV')";
- $sql.="and $sql_periode";
- $debit_actif=$this->db->get_value($sql);
+ $ret="";
+ $obj=new Acc_Account_Ledger($this->db,0);
+ for ($i=0;$i<$nRow;$i++)
+ {
- /* Credit Actif */
- $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
- " where j_debit='f' and (pcm_type='ACT' or pcm_type='ACTINV')";
+ $line=Database::fetch_array($res,$i);
+ /* set the periode filter */
+ $sql=sql_filter_per($this->db,$this->from,$this->to,'p_id','j_tech_per');
+ $obj->id=$line['pcm_val'];
- $sql.="and $sql_periode";
+ $solde=$obj->get_solde_detail($sql);
+ $solde_signed=$solde['debit']-$solde['credit'];
- $credit_actif=$this->db->get_value($sql);
- $total_actif=abs($debit_actif-$credit_actif);
- echo '';
- echo tr(td( 'Total actif ').td($total_actif,'style="text-align:right"'));
+ if (
+ ($solde_signed < 0 && $p_deb == 'D' ) ||
+ ($solde_signed > 0 && $p_deb == 'C' )
+ )
+ {
+ $ret.= 'Anomalie pour le compte '.$line['pcm_val'].
+ $line['pcm_lib'].
+ " D: ".$solde['debit'].
+ " C: ".$solde['credit']." diff ".$solde['solde'];
+ $count++;
+ }
- /* debit passif */
- $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
- " where j_debit='t' and (pcm_type='PAS' or pcm_type='PASINV') ";
- $sql.="and $sql_periode";
+ }
- $debit_passif=$this->db->get_value($sql);
+ echo '';
+ echo ''.$p_message.' ';
+ if ( $count <> 0 )
+ {
+ echo ''.$ret.' ';
+ echo 'Nbres anomalies : '.$count.' ';
+ }
+ else
+ echo " Pas d'anomalie détectée";
+ echo ' ';
- /* Credit Actif */
- $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
- " where j_debit='f' and (pcm_type='PAS' or pcm_type='PASINV') ";
- $sql.="and $sql_periode";
- $credit_passif=$this->db->get_value($sql);
- $total_passif=abs($debit_passif-$credit_passif);
- /* diff actif / passif */
- echo tr(td('Total passif ').td($total_passif,'style="text-align:right"'));
- if ( $total_actif != $total_passif ) {
- $diff=$total_actif-$total_passif;
- echo tr(td(' Difference Actif - Passif ').td($diff,'style="text-align:right"'),'style="font-weight:bolder"');
}
+ /*!\brief verify that the saldo is good for the type of account */
+ function verify()
+ {
+ echo ' Comptes normaux ';
+ $this->warning('Actif avec un solde crediteur','ACT','D');
+ $this->warning('Passif avec un solde debiteur','PAS','C');
+ $this->warning('Compte de resultat : Charge avec un solde crediteur','CHA','D');
+ $this->warning('Compte de resultat : produit avec un solde debiteur','PRO','C');
+ echo ' ';
+ echo ' Comptes inverses ';
+ $this->warning('Compte inverse : actif avec un solde debiteur','ACTINV','C');
+ $this->warning('Compte inverse : passif avec un solde crediteur','PASINV','D');
+ $this->warning('Compte inverse : Charge avec un solde debiteur','CHAINV','C');
+ $this->warning('Compte inverse : produit avec un solde crediteur','PROINV','D');
+ echo 'Solde ';
+ /* set the periode filter */
+ $sql_periode=sql_filter_per($this->db,$this->from,$this->to,'p_id','j_tech_per');
+ /* debit Actif */
+ $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
+ " where j_debit='t' and (pcm_type='ACT' or pcm_type='ACTINV')";
+ $sql.="and $sql_periode";
+ $debit_actif=$this->db->get_value($sql);
- /* debit charge */
- $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
- " where j_debit='t' and (pcm_type='CHA' or pcm_type='CHAINV')";
- $sql.="and $sql_periode";
- $debit_charge=$this->db->get_value($sql);
+ /* Credit Actif */
+ $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
+ " where j_debit='f' and (pcm_type='ACT' or pcm_type='ACTINV')";
- /* Credit charge */
- $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
- " where j_debit='f' and (pcm_type='CHA' or pcm_type='CHAINV')";
- $sql.="and $sql_periode";
- $credit_charge=$this->db->get_value($sql);
- $total_charge=abs($debit_charge-$credit_charge);
- echo tr(td('Total charge ').td($total_charge,'style="text-align:right"'));
+ $sql.="and $sql_periode";
+
+ $credit_actif=$this->db->get_value($sql);
+ $total_actif=abs($debit_actif-$credit_actif);
+ echo '';
+ echo tr(td( 'Total actif ').td($total_actif,'style="text-align:right"'));
+
+ /* debit passif */
+ $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
+ " where j_debit='t' and (pcm_type='PAS' or pcm_type='PASINV') ";
+ $sql.="and $sql_periode";
+
+ $debit_passif=$this->db->get_value($sql);
+
+ /* Credit Actif */
+ $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
+ " where j_debit='f' and (pcm_type='PAS' or pcm_type='PASINV') ";
+ $sql.="and $sql_periode";
+ $credit_passif=$this->db->get_value($sql);
+ $total_passif=abs($debit_passif-$credit_passif);
+
+ /* diff actif / passif */
+ echo tr(td('Total passif ').td($total_passif,'style="text-align:right"'));
+ if ( $total_actif != $total_passif )
+ {
+ $diff=$total_actif-$total_passif;
+ echo tr(td(' Difference Actif - Passif ').td($diff,'style="text-align:right"'),'style="font-weight:bolder"');
+ }
+
+ /* debit charge */
+ $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
+ " where j_debit='t' and (pcm_type='CHA' or pcm_type='CHAINV')";
+ $sql.="and $sql_periode";
+ $debit_charge=$this->db->get_value($sql);
+
+ /* Credit charge */
+ $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
+ " where j_debit='f' and (pcm_type='CHA' or pcm_type='CHAINV')";
+ $sql.="and $sql_periode";
+ $credit_charge=$this->db->get_value($sql);
+ $total_charge=abs($debit_charge-$credit_charge);
+ echo tr(td('Total charge ').td($total_charge,'style="text-align:right"'));
- /* debit prod */
- $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
- " where j_debit='t' and (pcm_type='PRO' or pcm_type='PROINV')";
- $sql.="and $sql_periode";
- $debit_pro=$this->db->get_value($sql);
+ /* debit prod */
+ $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
+ " where j_debit='t' and (pcm_type='PRO' or pcm_type='PROINV')";
+ $sql.="and $sql_periode";
+ $debit_pro=$this->db->get_value($sql);
- /* Credit prod */
- $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
- " where j_debit='f' and (pcm_type='PRO' or pcm_type='PROINV')";
- $sql.="and $sql_periode";
- $credit_pro=$this->db->get_value($sql);
- $total_pro=abs($debit_pro-$credit_pro);
- echo tr(td('Total produit ').td($total_pro,'style="text-align:right"'));
+ /* Credit prod */
+ $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
+ " where j_debit='f' and (pcm_type='PRO' or pcm_type='PROINV')";
+ $sql.="and $sql_periode";
+ $credit_pro=$this->db->get_value($sql);
+ $total_pro=abs($debit_pro-$credit_pro);
+ echo tr(td('Total produit ').td($total_pro,'style="text-align:right"'));
- $diff=$total_pro-$total_charge;
+ $diff=$total_pro-$total_charge;
- echo tr( td("Difference Produit - Charge",'style="padding-right:20px"').td($diff,'style="text-align:right"'),'style="font-weight:bolder"');
- echo '
';
- }
-/*!
- * \brief get data from the $_GET
- *
- */
- function get_request_get() {
- $this->b_id=(isset($_GET['b_id']))?$_GET['b_id']:"";
- $this->from=( isset ($_GET['from_periode']))?$_GET['from_periode']:-1;
- $this->to=( isset ($_GET['to_periode']))?$_GET['to_periode']:-1;
- }
- /*!\brief load from the database the document data */
- function load(){
- try {
- if ( $this->b_id=="")
- throw new Exception("le formulaire id n'est pas donnee");
-
- $sql="select b_name,b_file_template,b_file_form,lower(b_type) as b_type from bilan where".
- " b_id = ".$this->b_id;
- $res=$this->db->exec_sql($sql);
-
- if ( Database::num_row($res)==0)
- throw new Exception ('Aucun enregistrement trouve');
- $array=Database::fetch_array($res,0);
- foreach ($array as $name=>$value)
- $this->$name=$value;
-
- }catch(Exception $Ex) {
- echo $Ex->getMessage();
- exit();
- }
- }
- /*!\brief open the file of the form */
- /*\return an handle to this file */
- function file_open_form()
- {
- $form=fopen($this->b_file_form,'r');
- if ( $form == false) {
- echo 'Cannot Open';
- exit();
- }
- return $form;
- }
- /*!\brief open the file with the template */
- /*\return an handle to this file */
- function file_open_template()
- {
- $templ=fopen($this->b_file_template,'r');
- if ( $templ == false) {
- echo 'Cannot Open';
- exit();
- }
- return $templ;
-
- }
-/*!
- * \brief Compute all the formula
- * \param $p_handle the handle to the file
- * \param
- * \param
- *
- *
- * \return
- */
- function compute_formula($p_handle) {
- while (! feof ($p_handle)) {
- $buffer=trim(fgets($p_handle));
- // $a=(CheckFormula($buffer) == true)?"$buffer ok ":''.'Pas ok '.$buffer." ";
- // echo $a;
- // blank line are skipped
- if (strlen(trim($buffer))==0)
- continue;
- // skip comment
- if ( strpos($buffer,'#') === true )
- continue;
- // buffer contains a formula A$=....
- // We need to eval it
- //myereg("\\$[a-zA-Z]+[0-9]*=",$buffer,$e);
- // echo $e[0];
- //echo " ".$form;
- $a=ParseFormula($this->db,"$buffer",$buffer,$this->from,$this->to,false);
- $b=str_replace("$","\$this->",$a);
- if ( eval("$b;") === false )
- echo_debug(__FILE__,__LINE__,"Code failed with $b");
-
-
- }// end read form line per line
- }
- /*!\brief generate the ods document
- * \param the handle to the template file
- * \return the xml
- */
- function generate_odt()
- {
- // create a temp directory in /tmp to unpack file and to parse it
- $dirname=tempnam($_ENV['TMP'],'bilan_');
-
-
- unlink($dirname);
- mkdir ($dirname);
- chdir($dirname);
-
- $file_base=dirname($_SERVER['SCRIPT_FILENAME']).DIRECTORY_SEPARATOR.$this->b_file_template;
- $work_file=basename($file_base);
- if ( copy ($file_base,$work_file) == false )
- {
- echo "Je ne peux pas ouvrir ce fichier ";
- exit();
- }
- ob_start();
- system('unzip "'.$work_file.'"');
- ob_end_clean();
- unlink($work_file);
- // remove the zip file
- $p_file=fopen('content.xml','r');
-
- if ( $p_file == false) {
- echo 'Cannot Open';
- exit();
+ echo tr( td("Difference Produit - Charge",'style="padding-right:20px"').td($diff,'style="text-align:right"'),'style="font-weight:bolder"');
+ echo '
';
}
+ /*!
+ * \brief get data from the $_GET
+ *
+ */
+ function get_request_get()
+ {
+ $this->b_id=(isset($_GET['b_id']))?$_GET['b_id']:"";
+ $this->from=( isset ($_GET['from_periode']))?$_GET['from_periode']:-1;
+ $this->to=( isset ($_GET['to_periode']))?$_GET['to_periode']:-1;
+ }
+ /*!\brief load from the database the document data */
+ function load()
+ {
+ try
+ {
+ if ( $this->b_id=="")
+ throw new Exception("le formulaire id n'est pas donnee");
- $r="";
- $regex="<<\\$[A-Z]*[0-9]*>>";
- $lt="<";
- $gt=">";
- while ( !feof($p_file) ) {
- $line_rtf=fgets($p_file);
+ $sql="select b_name,b_file_template,b_file_form,lower(b_type) as b_type from bilan where".
+ " b_id = ".$this->b_id;
+ $res=$this->db->exec_sql($sql);
- /* replace the header tag */
- while( myereg('<<header>>',$line_rtf,$head) == true ) {
- foreach ($head as $h) {
- // Create the header
- $line_rtf=str_replace($h,header_txt($this->db),$line_rtf);
- }
- }
- // the line contains the magic <<
- $tmp="";
- while (myereg($regex,$line_rtf,$f2) == true) {
+ if ( Database::num_row($res)==0)
+ throw new Exception ('Aucun enregistrement trouve');
+ $array=Database::fetch_array($res,0);
+ foreach ($array as $name=>$value)
+ $this->$name=$value;
- // the f2 array contains all the magic << in the line
- foreach ($f2 as $f2_str) {
+ }
+ catch(Exception $Ex)
+ {
+ echo $Ex->getMessage();
+ exit();
+ }
+ }
+ /*!\brief open the file of the form */
+ /*\return an handle to this file */
+ function file_open_form()
+ {
+ $form=fopen($this->b_file_form,'r');
+ if ( $form == false)
+ {
+ echo 'Cannot Open';
+ exit();
+ }
+ return $form;
+ }
+ /*!\brief open the file with the template */
+ /*\return an handle to this file */
+ function file_open_template()
+ {
+ $templ=fopen($this->b_file_template,'r');
+ if ( $templ == false)
+ {
+ echo 'Cannot Open';
+ exit();
+ }
+ return $templ;
- $to_remove=$f2_str;
- $f2_value=str_replace("<","",$f2_str);
- $f2_value=str_replace(">","",$f2_value);
- $f2_value=str_replace("$","",$f2_value);
+ }
+ /*!
+ * \brief Compute all the formula
+ * \param $p_handle the handle to the file
+ * \param
+ * \param
+ *
+ *
+ * \return
+ */
+ function compute_formula($p_handle)
+ {
+ while (! feof ($p_handle))
+ {
+ $buffer=trim(fgets($p_handle));
+ // $a=(CheckFormula($buffer) == true)?"$buffer ok ":''.'Pas ok '.$buffer." ";
+ // echo $a;
+ // blank line are skipped
+ if (strlen(trim($buffer))==0)
+ continue;
+ // skip comment
+ if ( strpos($buffer,'#') === true )
+ continue;
+ // buffer contains a formula A$=....
+ // We need to eval it
+ //myereg("\\$[a-zA-Z]+[0-9]*=",$buffer,$e);
+ // echo $e[0];
+ //echo " ".$form;
+ $a=ParseFormula($this->db,"$buffer",$buffer,$this->from,$this->to,false);
+ $b=str_replace("$","\$this->",$a);
+ if ( eval("$b;") === false )
+ echo_debug(__FILE__,__LINE__,"Code failed with $b");
- // check for missing variables and labels (N vars)
- if( ! isset($this->$f2_value)) {
- $a = "!!".$f2_value."!!";
- if( substr($f2_value, 0, 1) == "N" ) {
- $ret = $this->db->get_array("SELECT pcm_lib AS acct_name FROM tmp_pcmn WHERE pcm_val::text LIKE ".
- " substr($1, 2)||'%' ORDER BY pcm_val ASC LIMIT 1",array($f2_value));
- if($ret[0]['acct_name']) {
- $a = $ret[0]['acct_name'];
- $a=str_replace('<','<',$a);
- $a=str_replace('>','>',$a);
- }
- }
- } else {
-
- $a=$this->$f2_value;
- }
- if ( $a=='-0' ) $a=0;
- /* allow numeric cel in ODT for the formatting and formula */
- if ( is_numeric($a) ) {
- $searched='office:value-type="string">'.$f2_str;
- $replaced='office:value-type="float" office:value="'.$a.'">'.$f2_str;
- $line_rtf=str_replace($searched, $replaced, $line_rtf);
- }
-
-
- $line_rtf=str_replace($f2_str,$a,$line_rtf);
-
- }// foreach end
- } // while myereg
- $r.=$line_rtf;
-
- }// odt file is read
- return $r;
-
- }
+ }// end read form line per line
+ }
+ /*!\brief generate the ods document
+ * \param the handle to the template file
+ * \return the xml
+ */
+ function generate_odt()
+ {
+ // create a temp directory in /tmp to unpack file and to parse it
+ $dirname=tempnam($_ENV['TMP'],'bilan_');
-/*!
- * \brief generate the plain file (rtf,txt, or html)
- * \param the handle to the template file
- */
- function generate_plain($p_file) {
- $r="";
- if ( $this->b_type=='html') {
- $lt='<';$gt='>';
- } else {
- $lt='<';$gt='>';
- }
- while ( !feof($p_file) ) {
- $line_rtf=fgets($p_file);
- if ( myereg($lt.$lt.'header'.$gt.$gt,$line_rtf) ) {
- // Create the header
- $line_rtf=str_replace($lt.$lt.'header'.$gt.$gt,header_txt($this->db),$line_rtf);
- $r.=$line_rtf;
- continue;
- }
- // the line contains the magic <<
- if (myereg($lt.$lt."\\$[a-zA-Z]*[0-9]*".$gt.$gt,$line_rtf,$f2) == true) {
- // DEBUG
- // echo $r.' ';
- // the f2 array contains all the magic << in the line
- foreach ($f2 as $f2_str) {
- // DEBUG
- // echo "single_f2 = $f2_str ";
- // replace single_f2 by its value
- $f2_value=str_replace($lt,"",$f2_str);
- $f2_value=str_replace($gt,"",$f2_value);
- $f2_value=str_replace("$","",$f2_value);
+ unlink($dirname);
+ mkdir ($dirname);
+ chdir($dirname);
- // check for missing variables and labels (N vars)
- if( ! isset($this->$f2_value)) {
- $a = "!!".$f2_value."!!";
- if( substr($f2_value, 0, 1) == "N" ) {
- $ret = $this->db->get_array("SELECT pcm_lib AS acct_name FROM tmp_pcmn WHERE ".
- " pcm_val::text LIKE substr($1, 2)||'%' ORDER BY pcm_val ASC LIMIT 1",
- array($f2_value));
- if($ret[0]['acct_name']) {
- /* for rtf we have the string to put it in latin1 */
- $a = utf8_decode($ret[0]['acct_name']);
+ $file_base=dirname($_SERVER['SCRIPT_FILENAME']).DIRECTORY_SEPARATOR.$this->b_file_template;
+ $work_file=basename($file_base);
+ if ( copy ($file_base,$work_file) == false )
+ {
+ echo "Je ne peux pas ouvrir ce fichier ";
+ exit();
+ }
+ ob_start();
+ system('unzip "'.$work_file.'"');
+ ob_end_clean();
+ unlink($work_file);
+ // remove the zip file
+ $p_file=fopen('content.xml','r');
+
+ if ( $p_file == false)
+ {
+ echo 'Cannot Open';
+ exit();
+ }
+
+ $r="";
+ $regex="<<\\$[A-Z]*[0-9]*>>";
+ $lt="<";
+ $gt=">";
+ while ( !feof($p_file) )
+ {
+ $line_rtf=fgets($p_file);
+
+ /* replace the header tag */
+ while( myereg('<<header>>',$line_rtf,$head) == true )
+ {
+ foreach ($head as $h)
+ {
+ // Create the header
+ $line_rtf=str_replace($h,header_txt($this->db),$line_rtf);
}
}
- } else {
- // DEBUG
- //echo "f2_value=$f2_value";
- // $a=${"$f2_value"};
- $a=$this->$f2_value;
- }
- // DEBUG echo " a = $a";
- if ( $a=='-0' ) $a=0;
- $line_rtf=str_replace($f2_str,$a,$line_rtf);
-
- }// foreach end
- }
- $r.=$line_rtf;
-
- }// rtf file is read
- // DEBUG
- // fwrite($out,$r);
- return $r;
-
-
+ // the line contains the magic <<
+ $tmp="";
+ while (myereg($regex,$line_rtf,$f2) == true)
+ {
-
- }
- /*!\brief generate the document and send it to the browser
- */
- function generate() {
- // Load the data
- $this->load();
- // Open the files
- $form=$this->file_open_form();
+ // the f2 array contains all the magic << in the line
+ foreach ($f2 as $f2_str)
+ {
- // Compute all the formula and add the value to this
- $this->compute_formula($form);
- fclose($form);
- // open the form
- $templ=$this->file_open_template();
- switch ($this->b_type) {
- case 'rtf':
- $result=$this->generate_plain($templ);
- $this->send($result);
- break;
- case 'txt':
- $result=$this->generate_plain($templ);
- $this->send($result);
- case 'html':
- $result=$this->generate_plain($templ);
- $this->send($result);
+ $to_remove=$f2_str;
+ $f2_value=str_replace("<","",$f2_str);
+ $f2_value=str_replace(">","",$f2_value);
+ $f2_value=str_replace("$","",$f2_value);
- break;
- case 'odt':
- case 'ods':
- $result=$this->generate_odt($templ);
- $this->send($result);
- break;
+ // check for missing variables and labels (N vars)
+ if( ! isset($this->$f2_value))
+ {
+ $a = "!!".$f2_value."!!";
+ if( substr($f2_value, 0, 1) == "N" )
+ {
+ $ret = $this->db->get_array("SELECT pcm_lib AS acct_name FROM tmp_pcmn WHERE pcm_val::text LIKE ".
+ " substr($1, 2)||'%' ORDER BY pcm_val ASC LIMIT 1",array($f2_value));
+ if($ret[0]['acct_name'])
+ {
+ $a = $ret[0]['acct_name'];
+ $a=str_replace('<','<',$a);
+ $a=str_replace('>','>',$a);
+ }
+ }
+ }
+ else
+ {
- }
- fclose($templ);
- }
- /*!\brief send the result of generate plain to the browser
- * \param $p_result is the string returned by generate_...
- */
- function send($p_result) {
- switch ($this->b_type) {
- case 'rtf':
- // A rtf file is generated
- header('Content-type: application/rtf');
- header('Content-Disposition: attachment; filename="'.$this->b_name.'.rtf"');
- echo $p_result;
- break;
+ $a=$this->$f2_value;
+ }
+ if ( $a=='-0' ) $a=0;
- case 'txt':
- // A txt file is generated
- header('Content-type: application/txt');
- header('Content-Disposition: attachment; filename="'.$this->b_name.'.txt"');
-
- echo $p_result;
- break;
- case 'html':
- // A txt file is generated
- header('Content-type: application/html');
- header('Content-Disposition: attachment; filename="'.$this->b_name.'.html"');
-
- echo $p_result;
- break;
- case 'odt':
- case 'ods':
- /* header("Pragma: public");
- header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
- header("Cache-Control: must-revalidate");
- if ( $this->b_type == 'odt' )
- header('Content-type: application/vnd.oasis.opendocument.text');
- if ( $this->b_type == 'ods' )
- header('Content-type: application/vnd.oasis.opendocument.spreadsheet');
- header('Content-Disposition: attachment;filename="'.$this->b_name.'.odt"',FALSE);
- header("Accept-Ranges: bytes");
- */
- ob_start();
- // save the file in a temp folder
- // create a temp directory in /tmp to unpack file and to parse it
- $dirname=tempnam($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'tmp','bilan_');
-
-
- unlink($dirname);
- mkdir ($dirname);
- chdir($dirname);
- // create a temp directory in /tmp to unpack file and to parse it
- $file_base=dirname($_SERVER['SCRIPT_FILENAME']).DIRECTORY_SEPARATOR.$this->b_file_template;
- $work_file=basename($file_base);
- if ( copy ($file_base,$work_file) == false )
- {
- echo "Je ne peux pas ouvrir ce fichier ";
- exit();
- }
- system('unzip "'.$work_file.'"');
- // remove the zip file
- unlink ($work_file);
+ /* allow numeric cel in ODT for the formatting and formula */
+ if ( is_numeric($a) )
+ {
+ $searched='office:value-type="string">'.$f2_str;
+ $replaced='office:value-type="float" office:value="'.$a.'">'.$f2_str;
+ $line_rtf=str_replace($searched, $replaced, $line_rtf);
+ }
- // replace the file
- $p_file=fopen($dirname.DIRECTORY_SEPARATOR.'content.xml','wb');
- if ( $p_file == false ){
- exit('Je ne peux pas ouvrir content.xml');
+ $line_rtf=str_replace($f2_str,$a,$line_rtf);
- }
- $a=fwrite($p_file,$p_result);
- if ( $a==false) {
- echo "Je ne peux pas ecrire dans content.xml";
- exit();
- }
- // repack
- system ('zip -r "'.$this->b_name.'.'.$this->b_type.'" *');
- ob_end_clean();
- fclose($p_file);
- $fdoc=fopen($dirname.DIRECTORY_SEPARATOR.$this->b_name.'.'.$this->b_type,'r');
- if ( $fdoc == false ){
- exit('Je ne peux pas ouvrir ce document');
- }
- $buffer=fread ($fdoc,filesize($dirname.DIRECTORY_SEPARATOR.$this->b_name.'.'.$this->b_type));
- echo $buffer;
+ }// foreach end
+ } // while myereg
+ $r.=$line_rtf;
- break;
- // and send
- }
+ }// odt file is read
+ return $r;
- }
- static function test_me() {
+ }
- if ( isset($_GET['result'])) {
- ob_start();
- $cn=new Database(dossier::id());
- $a=new Acc_Bilan($cn);
- $a->get_request_get();
+ /*!
+ * \brief generate the plain file (rtf,txt, or html)
+ * \param the handle to the template file
+ */
+ function generate_plain($p_file)
+ {
+ $r="";
+ if ( $this->b_type=='html')
+ {
+ $lt='<';
+ $gt='>';
+ }
+ else
+ {
+ $lt='<';
+ $gt='>';
+ }
- $a->load();
- $form=$a->file_open_form();
- $a->compute_formula($form);
- fclose($form);
- // open the form
- $templ=$a->file_open_template();
- $r=$a->generate_odt($templ);
- fclose($templ);
- ob_end_clean();
+ while ( !feof($p_file) )
+ {
+ $line_rtf=fgets($p_file);
+ if ( myereg($lt.$lt.'header'.$gt.$gt,$line_rtf) )
+ {
+ // Create the header
+ $line_rtf=str_replace($lt.$lt.'header'.$gt.$gt,header_txt($this->db),$line_rtf);
+ $r.=$line_rtf;
+ continue;
+ }
+ // the line contains the magic <<
+ if (myereg($lt.$lt."\\$[a-zA-Z]*[0-9]*".$gt.$gt,$line_rtf,$f2) == true)
+ {
+ // DEBUG
+ // echo $r.' ';
+ // the f2 array contains all the magic << in the line
+ foreach ($f2 as $f2_str)
+ {
+ // DEBUG
+ // echo "single_f2 = $f2_str ";
+ // replace single_f2 by its value
+ $f2_value=str_replace($lt,"",$f2_str);
+ $f2_value=str_replace($gt,"",$f2_value);
+ $f2_value=str_replace("$","",$f2_value);
- $a->send($r);
- }
- else {
- $cn=new Database(dossier::id());
- $a=new Acc_Bilan($cn);
- $a->get_request_get();
+ // check for missing variables and labels (N vars)
+ if( ! isset($this->$f2_value))
+ {
+ $a = "!!".$f2_value."!!";
+ if( substr($f2_value, 0, 1) == "N" )
+ {
+ $ret = $this->db->get_array("SELECT pcm_lib AS acct_name FROM tmp_pcmn WHERE ".
+ " pcm_val::text LIKE substr($1, 2)||'%' ORDER BY pcm_val ASC LIMIT 1",
+ array($f2_value));
+ if($ret[0]['acct_name'])
+ {
+ /* for rtf we have the string to put it in latin1 */
+ $a = utf8_decode($ret[0]['acct_name']);
+ }
+ }
+ }
+ else
+ {
+ // DEBUG
+ //echo "f2_value=$f2_value";
+ // $a=${"$f2_value"};
+ $a=$this->$f2_value;
+ }
+ // DEBUG echo " a = $a";
+ if ( $a=='-0' ) $a=0;
+ $line_rtf=str_replace($f2_str,$a,$line_rtf);
- echo '';
- echo $a->display_form();
- echo ' ';
- }
- }
+ }// foreach end
+ }
+ $r.=$line_rtf;
+
+ }// rtf file is read
+ // DEBUG
+ // fwrite($out,$r);
+ return $r;
+
+
+
+
+ }
+ /*!\brief generate the document and send it to the browser
+ */
+ function generate()
+ {
+ // Load the data
+ $this->load();
+ // Open the files
+ $form=$this->file_open_form();
+
+ // Compute all the formula and add the value to this
+ $this->compute_formula($form);
+ fclose($form);
+ // open the form
+ $templ=$this->file_open_template();
+ switch ($this->b_type)
+ {
+ case 'rtf':
+ $result=$this->generate_plain($templ);
+ $this->send($result);
+ break;
+ case 'txt':
+ $result=$this->generate_plain($templ);
+ $this->send($result);
+ case 'html':
+ $result=$this->generate_plain($templ);
+ $this->send($result);
+
+ break;
+ case 'odt':
+ case 'ods':
+ $result=$this->generate_odt($templ);
+ $this->send($result);
+ break;
+
+ }
+ fclose($templ);
+ }
+ /*!\brief send the result of generate plain to the browser
+ * \param $p_result is the string returned by generate_...
+ */
+ function send($p_result)
+ {
+ switch ($this->b_type)
+ {
+ case 'rtf':
+ // A rtf file is generated
+ header('Content-type: application/rtf');
+ header('Content-Disposition: attachment; filename="'.$this->b_name.'.rtf"');
+ echo $p_result;
+ break;
+
+ case 'txt':
+ // A txt file is generated
+ header('Content-type: application/txt');
+ header('Content-Disposition: attachment; filename="'.$this->b_name.'.txt"');
+
+ echo $p_result;
+ break;
+ case 'html':
+ // A txt file is generated
+ header('Content-type: application/html');
+ header('Content-Disposition: attachment; filename="'.$this->b_name.'.html"');
+
+ echo $p_result;
+ break;
+ case 'odt':
+ case 'ods':
+ /* header("Pragma: public");
+ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+ header("Cache-Control: must-revalidate");
+ if ( $this->b_type == 'odt' )
+ header('Content-type: application/vnd.oasis.opendocument.text');
+ if ( $this->b_type == 'ods' )
+ header('Content-type: application/vnd.oasis.opendocument.spreadsheet');
+ header('Content-Disposition: attachment;filename="'.$this->b_name.'.odt"',FALSE);
+ header("Accept-Ranges: bytes");
+ */
+ ob_start();
+ // save the file in a temp folder
+ // create a temp directory in /tmp to unpack file and to parse it
+ $dirname=tempnam($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'tmp','bilan_');
+
+
+ unlink($dirname);
+ mkdir ($dirname);
+ chdir($dirname);
+ // create a temp directory in /tmp to unpack file and to parse it
+ $file_base=dirname($_SERVER['SCRIPT_FILENAME']).DIRECTORY_SEPARATOR.$this->b_file_template;
+ $work_file=basename($file_base);
+ if ( copy ($file_base,$work_file) == false )
+ {
+ echo "Je ne peux pas ouvrir ce fichier ";
+ exit();
+ }
+ system('unzip "'.$work_file.'"');
+ // remove the zip file
+ unlink ($work_file);
+
+
+ // replace the file
+ $p_file=fopen($dirname.DIRECTORY_SEPARATOR.'content.xml','wb');
+ if ( $p_file == false )
+ {
+ exit('Je ne peux pas ouvrir content.xml');
+
+ }
+ $a=fwrite($p_file,$p_result);
+ if ( $a==false)
+ {
+ echo "Je ne peux pas ecrire dans content.xml";
+ exit();
+ }
+ // repack
+ system ('zip -r "'.$this->b_name.'.'.$this->b_type.'" *');
+ ob_end_clean();
+ fclose($p_file);
+ $fdoc=fopen($dirname.DIRECTORY_SEPARATOR.$this->b_name.'.'.$this->b_type,'r');
+ if ( $fdoc == false )
+ {
+ exit('Je ne peux pas ouvrir ce document');
+ }
+ $buffer=fread ($fdoc,filesize($dirname.DIRECTORY_SEPARATOR.$this->b_name.'.'.$this->b_type));
+ echo $buffer;
+
+ break;
+ // and send
+ }
+
+ }
+ static function test_me()
+ {
+
+ if ( isset($_GET['result']))
+ {
+ ob_start();
+ $cn=new Database(dossier::id());
+ $a=new Acc_Bilan($cn);
+ $a->get_request_get();
+
+ $a->load();
+ $form=$a->file_open_form();
+ $a->compute_formula($form);
+ fclose($form);
+ // open the form
+ $templ=$a->file_open_template();
+ $r=$a->generate_odt($templ);
+ fclose($templ);
+ ob_end_clean();
+
+ $a->send($r);
+ }
+ else
+ {
+ $cn=new Database(dossier::id());
+ $a=new Acc_Bilan($cn);
+ $a->get_request_get();
+
+ echo '';
+ echo $a->display_form();
+ echo ' ';
+ }
+ }
}
diff --git a/include/class_acc_compute.php b/include/class_acc_compute.php
index d7a46f370..e2955e6a2 100644
--- a/include/class_acc_compute.php
+++ b/include/class_acc_compute.php
@@ -24,302 +24,322 @@
* \brief to compute the different amount of an invoice of an expense,
*/
- /**
- * @brief this class aims to compute different amount
- *
- * This class compute without decimal error the following amount
- * - vat
- * - amount without vat
- * - no deductible vat
- * - personal part
- * - no deductible amount
- * Nothing won't be saved to the database, this class will just
- * compute and complete the object
- * if you need to compute the vat and in another place all the
- * details you'll have to use the clone function
- private static $variable=array( 'amount'=>'amount',
- 'amount_vat'=>'amount_vat',
- 'amount_vat_rate'=>'amount_vat_rate',
- 'nd_vat'=>'nd_vat',
- 'nd_vat_rate'=>'nd_vat_rate',
- 'nd_ded_vat'=>'nd_ded_vat',
- 'nd_ded_vat_rate'=>'nd_ded_vat_rate',
- 'amount_nd'=>'amount_nd',
- 'amount_nd_rate'=>'amount_nd_rate',
- 'nd_vat_rate'=>'nd_vat_rate',
- 'amount_perso'=>'amount_perso',
- 'amount_perso_rate'=>'amount_perso_rate' );
-
- */
-
-
-class Acc_Compute {
- private static $variable=array( 'amount'=>'amount',
- 'amount_vat'=>'amount_vat',
- 'amount_vat_rate'=>'amount_vat_rate',
- 'nd_vat'=>'nd_vat',
- 'nd_vat_rate'=>'nd_vat_rate',
- 'nd_ded_vat'=>'nd_ded_vat',
- 'nd_ded_vat_rate'=>'nd_ded_vat_rate',
- 'amount_nd'=>'amount_nd',
- 'amount_nd_rate'=>'amount_nd_rate',
- 'nd_vat_rate'=>'nd_vat_rate',
- 'amount_perso'=>'amount_perso',
- 'amount_perso_rate'=>'amount_perso_rate'
- );
-
- private $order; // check that the compute
- // function are called in the
- // good order
-
- var $check; // activate the check of the
- // order, valid value are
- // false or true
- function __construct () {
- bcscale(4);
- foreach (self::$variable as $key=>$value) $this->$key=0;
- $this->order=0;
- $this->check=true;
- }
-
- public function get_parameter($p_string) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- return $this->$idx;
- }
- else
- exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
- }
- public function set_parameter($p_string,$p_value) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- $this->$idx=$p_value;
- }
- else
- exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
-
-
- }
- public function get_info() { return var_export(self::$variable,true); }
-
- function compute_vat() {
- if ( $this->check && $this->order != 0 ) throw new Exception ('ORDER NOT RESPECTED');
- $this->amount_vat=bcmul($this->amount,$this->amount_vat_rate);
- $this->amount_vat=round($this->amount_vat,2);
- $this->order=1;
- }
- /*!\brief Compute the no deductible part of the amount, it reduce
- *also the vat
- */
- function compute_nd() {
- if ( $this->check && $this->order > 2 ) throw new Exception ('ORDER NOT RESPECTED');
-
- $this->amount_nd=bcmul($this->amount,$this->amount_nd_rate);
- $this->amount_nd=round($this->amount_nd,2);
- // the nd part for the vat
- $nd_vat=bcmul($this->amount_vat,$this->amount_nd_rate);
- $nd_vat=round($nd_vat,2);
-
- }
- function compute_nd_vat() {
- if ( $this->check && $this->order > 3 ) throw new Exception ('ORDER NOT RESPECTED');
- $this->order=4;
-
- if ($this->amount_vat == 0 ) $this->compute_vat();
- $this->nd_vat=bcmul($this->amount_vat,$this->nd_vat_rate);
- $this->nd_vat=round($this->nd_vat,2);
- }
-
- function compute_ndded_vat() {
- if ( $this->check && $this->order > 4 ) throw new Exception ('ORDER NOT RESPECTED');
- $this->order=5;
-
- if ($this->amount_vat == 0 ) $this->compute_vat();
- $this->nd_ded_vat=bcmul($this->amount_vat,$this->nd_ded_vat_rate);
- $this->nd_ded_vat=round($this->nd_ded_vat,2);
- }
-
- function compute_perso() {
- if ( $this->check && $this->order != 1 ) throw new Exception ('ORDER NOT RESPECTED');
- $this->order=2;
- if ( $this->amount == 0 ) return;
- $this->amount_perso=bcmul($this->amount,$this->amount_perso_rate);
- $this->amount_perso=round($this->amount_perso,2);
-
-
-
- }
- function correct() {
- $this->amount=bcsub($this->amount,$this->amount_perso);
- // correct the others amount
- $this->amount=bcsub($this->amount,$this->amount_nd);
- $this->amount_vat=bcsub($this->amount_vat,$this->nd_ded_vat);
- $this->amount_vat=round($this->amount_vat,2);
- $this->amount_vat=bcsub($this->amount_vat,$this->nd_vat);
- $this->amount_vat=round($this->amount_vat,2);
-
- }
-
- /*!\brief verify that all the amount are positive or null
- * otherwise throw a exception and the sum of amount + vat must
- * equal to the sum of all the amount of the current object
- * so you have to copy the object before computing anything and pass
- * it as parameter
- * \param compare with a object copied before computing, if null
- * there is no comparison
- */
- function verify($p_obj=null) {
- foreach (self::$variable as $key=>$value)
- if ( $this->$value < 0 )
- throw new Exception ("Montant invalide ");
-
- if ( $p_obj != null ) {
- $sum=0;
- foreach ( array( 'amount','amount_vat','amount_nd','nd_vat','amount_perso','nd_ded_vat') as $value)
- $sum=bcadd($sum,$this->$value);
- if ( $p_obj->amount_vat == 0 ) $p_obj->compute_vat();
- $cmp=bcadd($p_obj->amount,$p_obj->amount_vat);
- $diff=bcsub($sum,$cmp);
- if ( $diff != 0.0 )
- throw new Exception ("ECHEC VERIFICATION : valeur totale = $sum valeur attendue = $cmp diff = $diff");
- }
- }
- function display() {
- foreach (self::$variable as $key=>$value) {
- echo 'key '.$key.' Description '.$value.' value is '.$this->$key.' ';
- }
- }
- public static function test_me () {
- $a=new Acc_Compute();
- echo $a->get_info();
- echo ' ';
-
- // Compute some operation to see if the computed amount are
- // correct
-
- //Test VAT
- $a->set_parameter('amount',1.23);
- $a->set_parameter('amount_vat_rate',0.21);
-
- echo ' Test VAT ';
- echo ' Data ';
- $a->display();
-
- echo ' Result ';
- $a->compute_vat();
- $a->display();
- $a->verify();
- // Test VAT + perso
- $a=new Acc_Compute();
- $a->set_parameter('amount',1.23);
- $a->set_parameter('amount_vat_rate',0.21);
- $a->set_parameter('amount_perso_rate',0.5);
- echo ' Test VAT + Perso ';
- echo ' Data ';
- $a->display();
- $b=clone $a;
- $a->compute_vat();
- $a->compute_perso();
- $a->correct();
- echo ' Result ';
- $a->display();
- $a->verify($b);
- // TEST VAT + ND
- // Test VAT + perso
- $a=new Acc_Compute();
- $a->set_parameter('amount',1.23);
- $a->set_parameter('amount_vat_rate',0.21);
- $a->set_parameter('nd_vat_rate',0.5);
- $b=clone $a;
- echo ' Test VAT + ND VAT ';
- echo ' Data ';
- $a->display();
- $a->compute_vat();
- $a->compute_nd_vat();
- $a->correct();
- echo ' Result ';
- $a->display();
- $a->verify($b);
- // TEST VAT + ND
- // Test VAT + perso
- $a=new Acc_Compute();
- $a->set_parameter('amount',1.23);
- $a->set_parameter('amount_vat_rate',0.21);
- $a->set_parameter('nd_vat_rate',0.5);
- $a->set_parameter('amount_perso_rate',0.5);
-
- $b=clone $a;
- echo ' Test VAT + ND VAT + perso ';
- echo ' Data ';
- $a->display();
- $a->compute_vat();
- $a->compute_perso();
- $a->compute_nd_vat();
- $a->correct();
- echo ' Result ';
- $a->display();
- $a->verify($b);
- // TEST VAT + ND
- $a=new Acc_Compute();
- $a->set_parameter('amount',1.23);
- $a->set_parameter('amount_vat_rate',0.21);
- $a->set_parameter('amount_nd_rate',0.5);
-
- $b=clone $a;
- echo ' Test VAT + ND ';
- echo ' Data ';
- $a->display();
- $a->compute_vat();
- $a->compute_nd();
+/**
+ * @brief this class aims to compute different amount
+ *
+ * This class compute without decimal error the following amount
+ * - vat
+ * - amount without vat
+ * - no deductible vat
+ * - personal part
+ * - no deductible amount
+ * Nothing won't be saved to the database, this class will just
+ * compute and complete the object
+ * if you need to compute the vat and in another place all the
+ * details you'll have to use the clone function
+ private static $variable=array( 'amount'=>'amount',
+ 'amount_vat'=>'amount_vat',
+ 'amount_vat_rate'=>'amount_vat_rate',
+ 'nd_vat'=>'nd_vat',
+ 'nd_vat_rate'=>'nd_vat_rate',
+ 'nd_ded_vat'=>'nd_ded_vat',
+ 'nd_ded_vat_rate'=>'nd_ded_vat_rate',
+ 'amount_nd'=>'amount_nd',
+ 'amount_nd_rate'=>'amount_nd_rate',
+ 'nd_vat_rate'=>'nd_vat_rate',
+ 'amount_perso'=>'amount_perso',
+ 'amount_perso_rate'=>'amount_perso_rate' );
- $a->compute_perso();
- $a->compute_nd_vat();
- $a->correct();
- echo ' Result ';
- $a->display();
- $a->verify($b);
- // TEST VAT + ND
- // + Perso
- $a=new Acc_Compute();
- $a->set_parameter('amount',1.23);
- $a->set_parameter('amount_vat_rate',0.21);
- $a->set_parameter('amount_nd_rate',0.5);
- $a->set_parameter('amount_perso_rate',0.2857);
- $b=clone $a;
- echo ' Test VAT + ND + Perso ';
- echo ' Data ';
- $a->display();
- $a->compute_vat();
- $a->compute_nd();
-
- $a->compute_perso();
- $a->compute_nd_vat();
- $a->correct();
- echo ' Result ';
- $a->display();
- $a->verify($b);
- // TEST VAT + ND
- // + Perso
- $a=new Acc_Compute();
- $a->set_parameter('amount',1.23);
- $a->set_parameter('amount_vat_rate',0.21);
- $a->set_parameter('nd_ded_vat_rate',0.5);
-
- $b=clone $a;
- echo ' Test VAT + TVA ND DED ';
- echo ' Data ';
- $a->display();
- $a->compute_vat();
- $a->compute_nd();
-
- $a->compute_perso();
- $a->compute_nd_vat();
- $a->compute_ndded_vat();
- $a->correct();
- echo ' Result ';
- $a->display();
- $a->verify($b);
+ */
- }
- }
+class Acc_Compute
+{
+ private static $variable=array( 'amount'=>'amount',
+ 'amount_vat'=>'amount_vat',
+ 'amount_vat_rate'=>'amount_vat_rate',
+ 'nd_vat'=>'nd_vat',
+ 'nd_vat_rate'=>'nd_vat_rate',
+ 'nd_ded_vat'=>'nd_ded_vat',
+ 'nd_ded_vat_rate'=>'nd_ded_vat_rate',
+ 'amount_nd'=>'amount_nd',
+ 'amount_nd_rate'=>'amount_nd_rate',
+ 'nd_vat_rate'=>'nd_vat_rate',
+ 'amount_perso'=>'amount_perso',
+ 'amount_perso_rate'=>'amount_perso_rate'
+ );
+
+ private $order; // check that the compute
+ // function are called in the
+ // good order
+
+ var $check; // activate the check of the
+ // order, valid value are
+ // false or true
+ function __construct ()
+ {
+ bcscale(4);
+ foreach (self::$variable as $key=>$value) $this->$key=0;
+ $this->order=0;
+ $this->check=true;
+ }
+
+ public function get_parameter($p_string)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ return $this->$idx;
+ }
+ else
+ exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
+ }
+ public function set_parameter($p_string,$p_value)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ $this->$idx=$p_value;
+ }
+ else
+ exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
+
+
+ }
+ public function get_info()
+ {
+ return var_export(self::$variable,true);
+ }
+
+ function compute_vat()
+ {
+ if ( $this->check && $this->order != 0 ) throw new Exception ('ORDER NOT RESPECTED');
+ $this->amount_vat=bcmul($this->amount,$this->amount_vat_rate);
+ $this->amount_vat=round($this->amount_vat,2);
+ $this->order=1;
+ }
+ /*!\brief Compute the no deductible part of the amount, it reduce
+ *also the vat
+ */
+ function compute_nd()
+ {
+ if ( $this->check && $this->order > 2 ) throw new Exception ('ORDER NOT RESPECTED');
+
+ $this->amount_nd=bcmul($this->amount,$this->amount_nd_rate);
+ $this->amount_nd=round($this->amount_nd,2);
+ // the nd part for the vat
+ $nd_vat=bcmul($this->amount_vat,$this->amount_nd_rate);
+ $nd_vat=round($nd_vat,2);
+
+ }
+ function compute_nd_vat()
+ {
+ if ( $this->check && $this->order > 3 ) throw new Exception ('ORDER NOT RESPECTED');
+ $this->order=4;
+
+ if ($this->amount_vat == 0 ) $this->compute_vat();
+ $this->nd_vat=bcmul($this->amount_vat,$this->nd_vat_rate);
+ $this->nd_vat=round($this->nd_vat,2);
+ }
+
+ function compute_ndded_vat()
+ {
+ if ( $this->check && $this->order > 4 ) throw new Exception ('ORDER NOT RESPECTED');
+ $this->order=5;
+
+ if ($this->amount_vat == 0 ) $this->compute_vat();
+ $this->nd_ded_vat=bcmul($this->amount_vat,$this->nd_ded_vat_rate);
+ $this->nd_ded_vat=round($this->nd_ded_vat,2);
+ }
+
+ function compute_perso()
+ {
+ if ( $this->check && $this->order != 1 ) throw new Exception ('ORDER NOT RESPECTED');
+ $this->order=2;
+ if ( $this->amount == 0 ) return;
+ $this->amount_perso=bcmul($this->amount,$this->amount_perso_rate);
+ $this->amount_perso=round($this->amount_perso,2);
+
+
+
+ }
+ function correct()
+ {
+ $this->amount=bcsub($this->amount,$this->amount_perso);
+ // correct the others amount
+ $this->amount=bcsub($this->amount,$this->amount_nd);
+ $this->amount_vat=bcsub($this->amount_vat,$this->nd_ded_vat);
+ $this->amount_vat=round($this->amount_vat,2);
+ $this->amount_vat=bcsub($this->amount_vat,$this->nd_vat);
+ $this->amount_vat=round($this->amount_vat,2);
+
+ }
+
+ /*!\brief verify that all the amount are positive or null
+ * otherwise throw a exception and the sum of amount + vat must
+ * equal to the sum of all the amount of the current object
+ * so you have to copy the object before computing anything and pass
+ * it as parameter
+ * \param compare with a object copied before computing, if null
+ * there is no comparison
+ */
+ function verify($p_obj=null)
+ {
+ foreach (self::$variable as $key=>$value)
+ if ( $this->$value < 0 )
+ throw new Exception ("Montant invalide ");
+
+ if ( $p_obj != null )
+ {
+ $sum=0;
+ foreach ( array( 'amount','amount_vat','amount_nd','nd_vat','amount_perso','nd_ded_vat') as $value)
+ $sum=bcadd($sum,$this->$value);
+ if ( $p_obj->amount_vat == 0 ) $p_obj->compute_vat();
+ $cmp=bcadd($p_obj->amount,$p_obj->amount_vat);
+ $diff=bcsub($sum,$cmp);
+ if ( $diff != 0.0 )
+ throw new Exception ("ECHEC VERIFICATION : valeur totale = $sum valeur attendue = $cmp diff = $diff");
+ }
+ }
+ function display()
+ {
+ foreach (self::$variable as $key=>$value)
+ {
+ echo 'key '.$key.' Description '.$value.' value is '.$this->$key.' ';
+ }
+ }
+ public static function test_me ()
+ {
+ $a=new Acc_Compute();
+ echo $a->get_info();
+ echo ' ';
+
+ // Compute some operation to see if the computed amount are
+ // correct
+
+ //Test VAT
+ $a->set_parameter('amount',1.23);
+ $a->set_parameter('amount_vat_rate',0.21);
+
+ echo ' Test VAT ';
+ echo ' Data ';
+ $a->display();
+
+ echo ' Result ';
+ $a->compute_vat();
+ $a->display();
+ $a->verify();
+ // Test VAT + perso
+ $a=new Acc_Compute();
+ $a->set_parameter('amount',1.23);
+ $a->set_parameter('amount_vat_rate',0.21);
+ $a->set_parameter('amount_perso_rate',0.5);
+ echo ' Test VAT + Perso ';
+ echo ' Data ';
+ $a->display();
+ $b=clone $a;
+ $a->compute_vat();
+ $a->compute_perso();
+ $a->correct();
+ echo ' Result ';
+ $a->display();
+ $a->verify($b);
+ // TEST VAT + ND
+ // Test VAT + perso
+ $a=new Acc_Compute();
+ $a->set_parameter('amount',1.23);
+ $a->set_parameter('amount_vat_rate',0.21);
+ $a->set_parameter('nd_vat_rate',0.5);
+ $b=clone $a;
+ echo ' Test VAT + ND VAT ';
+ echo ' Data ';
+ $a->display();
+ $a->compute_vat();
+ $a->compute_nd_vat();
+ $a->correct();
+ echo ' Result ';
+ $a->display();
+ $a->verify($b);
+ // TEST VAT + ND
+ // Test VAT + perso
+ $a=new Acc_Compute();
+ $a->set_parameter('amount',1.23);
+ $a->set_parameter('amount_vat_rate',0.21);
+ $a->set_parameter('nd_vat_rate',0.5);
+ $a->set_parameter('amount_perso_rate',0.5);
+
+ $b=clone $a;
+ echo ' Test VAT + ND VAT + perso ';
+ echo ' Data ';
+ $a->display();
+ $a->compute_vat();
+ $a->compute_perso();
+ $a->compute_nd_vat();
+ $a->correct();
+ echo ' Result ';
+ $a->display();
+ $a->verify($b);
+ // TEST VAT + ND
+ $a=new Acc_Compute();
+ $a->set_parameter('amount',1.23);
+ $a->set_parameter('amount_vat_rate',0.21);
+ $a->set_parameter('amount_nd_rate',0.5);
+
+ $b=clone $a;
+ echo ' Test VAT + ND ';
+ echo ' Data ';
+ $a->display();
+ $a->compute_vat();
+ $a->compute_nd();
+
+ $a->compute_perso();
+ $a->compute_nd_vat();
+ $a->correct();
+ echo ' Result ';
+ $a->display();
+ $a->verify($b);
+ // TEST VAT + ND
+ // + Perso
+ $a=new Acc_Compute();
+ $a->set_parameter('amount',1.23);
+ $a->set_parameter('amount_vat_rate',0.21);
+ $a->set_parameter('amount_nd_rate',0.5);
+ $a->set_parameter('amount_perso_rate',0.2857);
+ $b=clone $a;
+ echo ' Test VAT + ND + Perso ';
+ echo ' Data ';
+ $a->display();
+ $a->compute_vat();
+ $a->compute_nd();
+
+ $a->compute_perso();
+ $a->compute_nd_vat();
+ $a->correct();
+ echo ' Result ';
+ $a->display();
+ $a->verify($b);
+// TEST VAT + ND
+ // + Perso
+ $a=new Acc_Compute();
+ $a->set_parameter('amount',1.23);
+ $a->set_parameter('amount_vat_rate',0.21);
+ $a->set_parameter('nd_ded_vat_rate',0.5);
+
+ $b=clone $a;
+ echo ' Test VAT + TVA ND DED ';
+ echo ' Data ';
+ $a->display();
+ $a->compute_vat();
+ $a->compute_nd();
+
+ $a->compute_perso();
+ $a->compute_nd_vat();
+ $a->compute_ndded_vat();
+ $a->correct();
+ echo ' Result ';
+ $a->display();
+ $a->verify($b);
+
+
+ }
+}
diff --git a/include/class_acc_ledger.php b/include/class_acc_ledger.php
index 0f839c88f..2fe8807fc 100644
--- a/include/class_acc_ledger.php
+++ b/include/class_acc_ledger.php
@@ -49,2605 +49,2795 @@ require_once('class_lettering.php');
/*!\brief Class for jrn, class acc_ledger for manipulating the ledger
*
*/
-class Acc_Ledger {
- var $id; /*!< jrn_def.jrn_def_id */
- var $name; /*!< jrn_def.jrn_def_name */
- var $db; /*!< database connextion */
- var $row; /*!< row of the ledger */
- var $type; /*!< type of the ledger ACH ODS FIN
- VEN or GL */
- var $nb; /*!< default number of rows by
- default 10 */
- /**
- *@param $p_cn database connexion
- *@param $p_id jrn.jrn_def_id
- */
- function __construct ($p_cn,$p_id){
- $this->id=$p_id;
- $this->db=$p_cn;
- $this->row=null;
- $this->nb=10;
- }
- function get_last_pj() {
- if ( $this->db->exist_sequence("s_jrn_pj".$this->id) ) {
- $ret= $this->db->get_array("select last_value,is_called from s_jrn_pj".$this->id);
- $last=$ret[0]['last_value'];
- /*!
- *\note With PSQL sequence , the last_value column is 1 when before AND after the first call, to make the difference between them
- * I have to check whether the sequence has been already called or not */
- if ($ret[0]['is_called']=='f' ) $last--;
- return $last;
- }
- else
- $this->db->create_sequence("s_jrn_pj".$this->id);
- return 0;
- }
- /*!
- * \brief Return the type of a ledger (ACH,VEN,ODS or FIN) or GL
- *
- */
- function get_type() {
- if ( $this->id==0 ) {
- $this->name=" Tous les journaux";
- $this->type="GL";
- return "GL";
- }
-
- $Res=$this->db->exec_sql("select jrn_def_type from ".
- " jrn_def where jrn_def_id=".
- $this->id);
- $Max=Database::num_row($Res);
- if ($Max==0) return null;
- $ret=Database::fetch_array($Res,0);
- $this->type=$ret['jrn_def_type'];
- return $ret['jrn_def_type'];
- }
- /**
- *let you delete a operation
- *@note by cascade it will delete also in
- * - jrnx
- * - stock
- * - quant_purchase
- * - quant_fin
- * - quant_sold
- * - operation_analytique
- * - letter
- * - reconciliation
- *@bug the attached document is not deleted
- */
- function delete() {
- if ( $this->id == 0 ) return;
- $grpt_id=$this->db->get_value('select jr_grpt_id from jrn where jr_id=$1',
- array($this->jr_id));
- if ( $this->db->count()==0) return;
- $this->db->exec_sql('delete from jrnx where j_grpt=$1',
- array($grpt_id));
- $this->db->exec_sql('delete from jrn where jr_id=$1',
- array($this->jr_id));
- }
- /**
- * reverse the operation by creating the opposite one,
- * the result is to avoid it
- * it must be done in
- * - jrn
- * - jrnx
- * - quant_fin
- * - quant_sold
- * - quant_purchase
- * - stock
- * - ANC
- *@param $p_date is the date of the reversed op
- *@exception if date is invalid or other prob
- *@note automatically create a reconciliation between operation
- *You must set the ledger_id $this->jrn_def_id
- */
- function reverse($p_date) {
- if ( ! isset ($this->jr_id) || $this->jr_id=='')
- throw new Exception ("this->jr_id is not set ou opération inconnue");
-
- $user=new User($this->db);
- /* check if the date is valid */
- if ( isDate($p_date) == null )
- throw new Exception (_('Date invalide').$p_date);
-
- // if the operation is in a closed or centralized period
- // the operation is voided thanks the opposite operation
- $grp_new=$this->db->get_next_seq('s_grpt');
- $seq=$this->db->get_next_seq("s_jrn");
- $p_internal=$this->compute_internal_code($seq);
- $this->jr_grpt_id=$this->db->get_value('select jr_grpt_id from jrn where jr_id=$1',
- array($this->jr_id));
- if ( $this->db->count()==0)
- throw new Exception (_("Cette opération n'existe pas"));
- $this->jr_internal=$this->db->get_value('select jr_internal from jrn where jr_id=$1',
- array($this->jr_id));
- if ( $this->db->count()==0 || trim($this->jr_internal)=='')
- throw new Exception (_("Cette opération n'existe pas"));
-
- /* find the periode thanks the date */
- $per=new Periode($this->db);
- $per->jrn_def_id=$this->id;
- $per->find_periode($p_date);
-
- if ( $per->is_open() == 0 )
- throw new Exception (_('PERIODE FERMEE'));
-
- $sql= "insert into jrn (
- jr_id,
- jr_def_id,
- jr_montant,
- jr_comment,
- jr_date,
- jr_grpt_id,
- jr_internal
- ,jr_tech_per, jr_valid
- )
- select $1,jr_def_id,jr_montant,'Annulation '||jr_comment,
- to_date($2,'DD.MM.YYYY'),$3,$4,
- $5, true
- from
- jrn
- where jr_id=$6";
- $Res=$this->db->exec_sql($sql,array($seq,$p_date,$grp_new,$p_internal,$per->p_id,$this->jr_id));
- // Check return code
- if ( $Res == false)
- throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]"));
-
-
-
-
- // Mark the operation invalid into the ledger
- // to avoid to nullify twice the same op.
- $sql="update jrn set jr_comment='Annule : '||jr_comment where jr_id=$1";
- $Res=$this->db->exec_sql($sql,array($this->jr_id));
-
- // Check return code
- if ( $Res == false)
- throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]"));
-
- //////////////////////////////////////////////////
- // Reverse in QUANT_* tables
- //////////////////////////////////////////////////
- $a_jid=$this->db->get_array("select j_id,j_debit from jrnx where j_grpt=$1",array($this->jr_grpt_id));
- for ($l=0;$ldb->exec_sql($sql,array($p_date,$grp_new,$p_internal,$user->id,$per->p_id,$row));
- // Check return code
- if ( $Res == false)
- throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]"));
- $aj_id=$this->db->fetch(0);
- $j_id=$aj_id['j_id'];
-
- /* automatic lettering */
- $let=new Lettering($this->db);
- $let->insert_couple($j_id,$row);
-
- // reverse in QUANT_SOLD
- $Res=$this->db->exec_sql("INSERT INTO quant_sold(
- qs_internal, qs_fiche, qs_quantite, qs_price, qs_vat,
- qs_vat_code, qs_client, qs_valid, j_id)
- SELECT $1, qs_fiche, qs_quantite*(-1), qs_price, qs_vat,
- qs_vat_code, qs_client, qs_valid, $2
- FROM quant_sold where j_id=$3",
- array($p_internal,$j_id,$row));
-
- if ( $Res == false)
- throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]"));
- $Res=$this->db->exec_sql("INSERT INTO quant_purchase(
- qp_internal, j_id, qp_fiche, qp_quantite, qp_price, qp_vat,
- qp_vat_code, qp_nd_amount, qp_nd_tva, qp_nd_tva_recup, qp_supplier,
- qp_valid, qp_dep_priv)
- SELECT $1, $2, qp_fiche, qp_quantite*(-1), qp_price, qp_vat,
- qp_vat_code, qp_nd_amount, qp_nd_tva, qp_nd_tva_recup, qp_supplier,
- qp_valid, qp_dep_priv
- FROM quant_purchase where j_id=$3",
- array($p_internal,$j_id,$row));
-
- if ( $Res == false)
- throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]"));
- }
- // reverse in QUANT_FIN table
- $Res=$this->db->exec_sql(" INSERT INTO quant_fin(
- qf_bank, qf_other, qf_amount,jr_id)
-SELECT qf_bank, qf_other, qf_amount*(-1),$1
- FROM quant_fin where jr_id=$2",array($seq,$this->jr_id));
- if ( $Res == false)
- throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]"));
-
- // Add a "concerned operation to bound these op.together
- //
- $rec=new Acc_Reconciliation ($this->db);
- $rec->set_jr_id($seq);
- $rec->insert($this->jr_id);
-
- // Check return code
- if ( $Res == false ) { throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]"));}
-
-
- // the table stock must updated
- // also in the stock table
- $sql="delete from stock_goods where sg_id = any ( select sg_id
- from stock_goods natural join jrnx where j_grpt=".$this->jr_grpt_id.")";
- $Res=$this->db->exec_sql($sql);
- /**
- *@function
- *@todo remove also from ANC */
-
- // Check return code
- if ( $Res == false)
- throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]"));
-
- }
- /*!
- * \brief Return the name of a ledger
- *
- */
- function get_name() {
- if ( $this->id==0 ) {
- $this->name=" Grand Livre ";
- return $this->name;
- }
-
- $Res=$this->db->exec_sql("select jrn_def_name from ".
- " jrn_def where jrn_def_id=".
- $this->id);
- $Max=Database::num_row($Res);
- if ($Max==0) return null;
- $ret=Database::fetch_array($Res,0);
- $this->name=$ret['jrn_def_name'];
- return $ret['jrn_def_name'];
- }
-
-
- /*! \function get_row
- * \brief Get The data
- *
- *
- * \param p_from from periode
- * \param p_to to periode
- * \param p_limit starting line
- * \param p_offset number of lines
- * \return Array with the asked data
- *
- */
- function get_row($p_from,$p_to,$p_limit=-1,$p_offset=-1) {
- /**
- *@todo add a filter for security
- */
-
- $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per');
-
- $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:"";
- // retrieve the type
- $this->get_type();
- // Grand livre == 0
- if ( $this->id != 0 ) {
- $Res=$this->db->exec_sql("select jr_id,j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date,
- jr_internal,
- case j_debit when 't' then j_montant::text else ' ' end as deb_montant,
- case j_debit when 'f' then j_montant::text else ' ' end as cred_montant,
- j_debit as debit,j_poste as poste,jr_montant , ".
- "coalesce(j_text,pcm_lib) as description,j_grpt as grp,
-jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj_number !='' then jr_pj_number else '' end as jr_comment,
- j_qcode,
- jr_rapt as oc, j_tech_per as periode
- from jrnx left join jrn on ".
- "jr_grpt_id=j_grpt ".
- " left join tmp_pcmn on pcm_val=j_poste ".
- " where j_jrn_def=".$this->id.
- " and ".$periode." order by j_date::date asc,jr_internal,j_debit desc ".
- $cond_limite);
-
- } else {
- $Res=$this->db->exec_sql("select jr_id,j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date,
- jr_internal,
- case j_debit when 't' then j_montant::text else ' ' end as deb_montant,
- case j_debit when 'f' then j_montant::text else ' ' end as cred_montant,
- j_debit as debit,j_poste as poste,".
- "coalesce(j_text,pcm_lib) as description,j_grpt as grp,
-jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj_number !='' then 'pj:'||coalesce(jr_pj_number,'-') else '' end as jr_comment,
- jr_montant,
- j_qcode,
- jr_rapt as oc, j_tech_per as periode from jrnx left join jrn on ".
- "jr_grpt_id=j_grpt left join tmp_pcmn on pcm_val=j_poste where ".
- " ".$periode." order by j_date::date,j_grpt,j_debit desc ".
- $cond_limite);
-
- }
-
-
- $array=array();
- $Max=Database::num_row($Res);
- if ($Max==0) return null;
- $case="";
- $tot_deb=0;
- $tot_cred=0;
- $row=Database::fetch_all($Res);
- for ($i=0;$i<$Max;$i++) {
- $fiche=new Fiche($this->db);
- $line=$row[$i];
- $mont_deb=($line['deb_montant']!=0)?sprintf("% 8.2f",$line['deb_montant']):"";
- $mont_cred=($line['cred_montant']!=0)?sprintf("% 8.2f",$line['cred_montant']):"";
- $jr_montant=($line['jr_montant']!=0)?sprintf("% 8.2f",$line['jr_montant']):"";
- $tot_deb+=$line['deb_montant'];
- $tot_cred+=$line['cred_montant'];
- $tot_op=$line['jr_montant'];
-
- /* Check first if there is a quickcode */
- if ( strlen(trim($line['j_qcode'])) != 0 )
- {
- if ( $fiche->get_by_qcode($line['j_qcode'],false) == 0 )
- {
- $line['description']=$fiche->strAttribut(ATTR_DEF_NAME);
- }
- }
- if ( $case != $line['grp'] ) {
- $case=$line['grp'];
- // for financial, we show if the amount is or not in negative
- if ( $this->type=='FIN') {
- $amount=$this->db->get_value('select qf_amount from quant_fin where jr_id=$1',
- array($line['jr_id']));
- /* if nothing is found */
- if ( $this->db->count()==0 )
- $tot_op=$jr_montant;
- else if ( $amount < 0 ) {
- $tot_op=$amount;
- }
- }
- $array[]=array (
- 'jr_id'=>$line['jr_id'],
- 'int_j_id' => $line['int_j_id'],
- 'j_id'=>$line['j_id'],
- 'j_date' => $line['j_date'],
- 'internal'=>$line['jr_internal'],
- 'deb_montant'=>'',
- 'cred_montant'=>' ',
- 'description'=>''.h($line['jr_comment']).' ['.$tot_op.'] ',
- 'poste' => $line['oc'],
- 'qcode' => $line['j_qcode'],
- 'periode' =>$line['periode'] );
-
- $array[]=array (
- 'jr_id'=>'',
- 'int_j_id' => $line['int_j_id'],
- 'j_id'=>'',
- 'j_date' => '',
- 'internal'=>'',
- 'deb_montant'=>$mont_deb,
- 'cred_montant'=>$mont_cred,
- 'description'=>$line['description'],
- 'poste' => $line['poste'],
- 'qcode' => $line['j_qcode'],
- 'periode' => $line['periode']
- );
-
- }else {
- $array[]=array (
- 'jr_id'=>$line['jr_id'],
- 'int_j_id' => $line['int_j_id'],
- 'j_id'=>'',
- 'j_date' => '',
- 'internal'=>'',
- 'deb_montant'=>$mont_deb,
- 'cred_montant'=>$mont_cred,
- 'description'=>$line['description'],
- 'poste' => $line['poste'],
- 'qcode' => $line['j_qcode'],
- 'periode' => $line['periode']);
-
- }
-
-
- }
- $this->row=$array;
- $a=array($array,$tot_deb,$tot_cred);
- return $a;
- }
- /*! \brief Get simplified row from ledger
- *
- * \param from periode
- * \param to periode
- * \param p_limit starting line
- * \param p_offset number of lines
- * \param trunc if data must be truncated (pdf export)
- *
- * \return an Array with the asked data
- */
- function get_rowSimple($p_from,$p_to,$trunc=0,$p_limit=-1,$p_offset=-1)
- {
- // Grand-livre : id= 0
- //---
- $jrn=($this->id == 0 )?"":"and jrn_def_id = ".$this->id;
-
- $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per');
-
- $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:"";
- //---
- $sql="
- SELECT jrn.jr_id as jr_id ,
- jrn.jr_id as num ,
- jrn.jr_def_id as jr_def_id,
- jrn.jr_montant as montant,
- substr(jrn.jr_comment,1,35)|| case when jr_pj_number is not null and jr_pj_number !='' then 'pj:'||coalesce(jr_pj_number,'-') else '' end as comment,
- to_char(jrn.jr_date,'DD-MM-YYYY') as date,
- jr_internal,
- jrn.jr_grpt_id as grpt_id,
- jrn.jr_pj_name as pj,
- jrn_def_type,
- jrn.jr_tech_per
- FROM jrn join jrn_def on (jrn_def_id=jr_def_id)
- WHERE $periode $jrn order by jr_date $cond_limite";
-
- $Res=$this->db->exec_sql($sql);
- $Max=Database::num_row($Res);
- if ( $Max == 0 )
- {
- return null;
- }
- $type=$this->get_type();
- // for type ACH and Ven we take more info
- if ( $type == 'ACH' || $type == 'VEN')
- {
- $a_ParmCode=$this->db->get_array('select p_code,p_value from parm_code');
- $a_TVA=$this->db->get_array('select tva_id,tva_label,tva_poste
- from tva_rate where tva_rate != 0 order by tva_id');
- for ( $i=0;$i<$Max;$i++)
- {
- $array[$i]=Database::fetch_array($Res,$i);
- $p=$this->get_detail($array[$i],$type,$trunc,$a_TVA,$a_ParmCode);
- if ( $array[$i]['dep_priv'] != 0.0) {
- $array[$i]['comment'].="(priv. ".$array[$i]['dep_priv'].")";
- }
- }
-
- }
- else
- {
- $array=Database::fetch_all($Res);
-
- }
-
- return $array;
- }// end function get_rowSimple
-
- /*!\brief guess what the next pj should be
- */
- function guess_pj() {
- $prop=$this->get_propertie();
- $pj_pref=$prop["jrn_def_pj_pref"];
- $pj_seq=$this->get_last_pj()+1;
- 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=$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=jrn_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) {
- $user=new User($this->db);
- $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();
- $image_asc='';
- $image_desc='';
- $image_sel_desc='';
- $image_sel_asc='';
-
- $sort_date=" $image_asc "._('Date')."$image_desc ";
- $sort_description=" $image_asc "._('Description')."$image_desc ";
- $sort_amount=" $image_asc "._('Montant')." $image_desc ";
- $sort_pj=" $image_asc "._('PJ')."$image_desc ";
- $sort_echeance=" $image_asc "._('Ech')." $image_desc ";
-
- $own=new Own($this->db);
- // if an order is asked
- if ( isset ($_GET['o']) )
- {
- switch ($_GET['o'])
- {
- case 'pja':
- // pj asc
- $sort_pj="$image_sel_asc PJ $image_desc ";
- $order=' order by substring(jr_pj_number,\'\\\d+$\')::numeric asc ';
- break;
- case 'pjd':
- $sort_pj=" $image_asc PJ $image_sel_desc ";
- // pj desc
- $order=' order by substring(jr_pj_number,\'\\\d+$\')::numeric desc ';
- break;
-
- case 'da':
- // date asc
- $sort_date="$image_sel_asc Date $image_desc ";
- $order=" order by jr_date_order asc ";
- break;
- case 'dd':
- $sort_date=" $image_asc Date $image_sel_desc ";
- // date desc
- $order=" order by jr_date_order desc ";
- break;
- case 'ma':
- // montant asc
- $sort_amount=" $image_sel_asc Montant $image_desc ";
- $order=" order by jr_montant asc ";
- break;
- case 'md':
- // montant desc
- $sort_amount=" $image_asc Montant $image_sel_desc ";
- $order=" order by jr_montant desc ";
- break;
- case 'ca':
- // jr_comment asc
- $sort_description=" $image_sel_asc Description $image_desc ";
- $order=" order by jr_comment asc ";
- break;
- case 'cd':
- // jr_comment desc
- $sort_description=" $image_asc Description $image_sel_desc ";
- $order=" order by jr_comment desc ";
- break;
- case 'ea':
- // jr_comment asc
- $sort_echeance=" $image_sel_asc Ech. $image_desc ";
- $order=" order by jr_ech asc ";
- break;
- case 'ed':
- // jr_comment desc
- $sort_echeance=" $image_asc Ech. $image_sel_desc ";
- $order=" order by jr_ech desc ";
- break;
-
- }
- } else {
- // date asc
- $sort_date="$image_sel_asc Date $image_desc ";
- $order=" order by jr_date_order asc ";
- }
- // set a filter for the FIN
- $a_parm_code=$this->db->get_array("select p_value from parm_code where p_code in ('BANQUE','COMPTE_COURANT','CAISSE')");
- $sql_fin="(";
- $or="";
- foreach ($a_parm_code as $code) {
- $sql_fin.="$or j_poste::text like '".$code['p_value']."%'";
- $or=" or ";
- }
- $sql_fin.=")";
-
- // 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="";
-
- $r.=JS_LEDGER;
-
- $Max=Database::num_row($Res);
-
- if ($Max==0) return array(0,_("Aucun enregistrement trouvé"));
-
- $r.='';
-
-
- $r.="";
- $r.="Internal ";
- if ( $this->type=='') {
- $r.=th('Journal');
- }
- $r.=$sort_date;
- $r.=$sort_echeance;
- $r.=$sort_pj;
- $r.=$sort_description;
- $r.=$sort_amount;
- // if $p_paid is not equal to 0 then we have a paid column
- if ( $p_paid != 0 )
- {
- $r.=" "._('Payé')." ";
- }
- $r.=""._('Op. Concernée')." ";
- $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']);
- switch ($href)
- {
- // user_jrn.php
- case 'compta.php':
- $vue="S"; //Expert View
- break;
- case 'commercial.php':
- $vue="S"; //Simple View
- break;
- case 'recherche.php':
- $vue=(isset($_GET['expert']))?'E':'S';
- break;
- default:
- echo_error('user_form_ach.php',__LINE__,'Erreur invalid request uri');
- exit (-1);
- }
- //DEBUG
-
- $r.=sprintf('%s ',
- $row['jr_id'], $gDossier, $row['jr_internal']);
- $r.=" ";
- if ( $this->type=='') $r.=td($row['jrn_def_name']);
- // date
- $r.="";
- $r.=$row['jr_date'];
- $r.=" ";
- // echeance
- $r.="";
- $r.=$row['jr_ech'];
- $r.=" ";
-
- // pj
- $r.="";
- $r.=$row['jr_pj_number'];
- $r.=" ";
-
- // comment
- $r.="";
- $tmp_jr_comment=h($row['jr_comment']);
- $r.=$tmp_jr_comment;
- $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->db->get_value("select qf_amount from quant_fin where jr_id=$1",
- array($row['jr_id']));
- $positive=($positive < 0)?1:0;
- }
- $r.="";
-
- $tot=($positive != 0)?$tot-$row['jr_montant']:$tot+$row['jr_montant'];
- //STAN $positive always == 0
- $r.=( $positive != 0 )?" - ".sprintf("%8.2f",$row['jr_montant'])." ":sprintf("%8.2f",$row['jr_montant']);
- $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+=$row['jr_montant'];
- else
- $amount_unpaid+=$row['jr_montant'];
- }
-
- // 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=$element");
- $r.= " ".$operation->get_internal()." [ $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'] != "")
- {
- $image=' ';
- $r.="".sprintf('%s ',
- $row['jrn_def_id'],
- $row['jr_grpt_id'],
- $str_dossier,
- $image)
- ." ";
- }
- 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.=''.$tot." ";
- $r.=" ";
- if ( $p_paid != 0 ) {
- $r.="";
- $r.='Payé ';
- $r.=''.$amount_paid." ";
- $r.=" ";
- $r.="";
- $r.='Non payé ';
- $r.=''.$amount_unpaid." ";
- $r.=" ";
- }
- $r.="
";
-
- return array ($count,$r);
-}
-
- /*!
- * \brief get_detail gives the detail of row
- * this array must contains at least the field
- *
- * montant
- * grpt_id
- *
- * the following field will be added
- *
- * HTVA
- * TVAC
- * TVA array with
- *
- * field 0 idx
- * array containing tva_id,tva_label and tva_amount
- *
- *
- *
- * \param p_array the structure is set in get_rowSimple, this array is
- * modified,
- * \param $trunc if the data must be truncated, usefull for pdf export
- * \param p_jrn_type is the type of the ledger (ACH or VEN)
- * \param $a_TVA TVA Array (default null)
- * \param $a_ParmCode Array (default null)
- * \return p_array
- */
- function get_detail(&$p_array,$p_jrn_type,$trunc=0,$a_TVA=null,$a_ParmCode=null)
- {
- if ( $a_TVA == null )
- {
- //Load TVA array
- $a_TVA=$this->db->get_array('select tva_id,tva_label,tva_poste
- from tva_rate where tva_rate != 0 order by tva_id');
- }
- if ( $a_ParmCode == null )
- {
- //Load Parm_code
- $a_ParmCode=$this->db->get_array('select p_code,p_value from parm_code');
- }
- // init
- $p_array['client']="";
- $p_array['TVAC']=0;
- $p_array['TVA']=array();
- $p_array['AMOUNT_TVA']=0.0;
- $p_array['dep_priv']=0;
- $dep_priv=0.0;
- //
- // Retrieve data from jrnx
- $sql="select j_id,j_poste,j_montant, j_debit,j_qcode from jrnx where ".
- " j_grpt=".$p_array['grpt_id'];
- $Res2=$this->db->exec_sql($sql);
- $data_jrnx=Database::fetch_all($Res2);
- $c=0;
-
- // Parse data from jrnx and fill diff. field
- foreach ( $data_jrnx as $code ) {
- $idx_tva=0;
- $poste=new Acc_Account_Ledger($this->db,$code['j_poste']);
-
- // if card retrieve name if the account is not a VAT account
- if ( strlen(trim($code['j_qcode'] )) != 0 && $poste->isTva() == 0 )
- {
- $fiche=new Fiche($this->db);
- $fiche->get_by_qcode(trim($code['j_qcode']),false);
- $fiche_def_id=$fiche->get_fiche_def_ref_id();
- // Customer or supplier
- if ( $fiche_def_id == FICHE_TYPE_CLIENT ||
- $fiche_def_id == FICHE_TYPE_FOURNISSEUR )
- {
- $p_array['TVAC']=$code['j_montant'];
-
- $p_array['client']=($trunc==0)?$fiche->getName():substr($fiche->getName(),0,20);
- $p_array['reversed']=false;
- if ( $fiche_def_id == FICHE_TYPE_CLIENT && $code['j_debit']=='f')
- {
- $p_array['reversed']=true;
- $p_array['TVAC']*=-1;
-
- }
- if ( $fiche_def_id == FICHE_TYPE_FOURNISSEUR && $code['j_debit']=='t')
- {
- $p_array['reversed']=true;
- $p_array['TVAC']*=-1;
- }
-
-
- } else {
- // if we use the ledger ven / ach for others card than supplier and customer
- if ( $fiche_def_id != FICHE_TYPE_VENTE &&
- $fiche_def_id != FICHE_TYPE_ACH_MAR &&
- $fiche_def_id != FICHE_TYPE_ACH_SER ) {
- $p_array['TVAC']=$code['j_montant'];
-
- $p_array['client']= ($trunc==0)?$fiche->getName():substr($fiche->getName(),0,20);
- $p_array['reversed']=false;
- if ($p_jrn_type == 'ACH' && $code['j_debit']=='t')
- {
- $p_array['reversed']=true;
- $p_array['TVAC']*=-1;
-
- }
- if ($p_jrn_type == 'VEN' && $code['j_debit']=='f')
- {
- $p_array['reversed']=true;
- $p_array['TVAC']*=-1;
- }
-
-
-
-
- }
- }
- }
- // if TVA, load amount, tva id and rate in array
- foreach ( $a_TVA as $line_tva)
- {
- list($tva_deb,$tva_cred)=explode(',',$line_tva['tva_poste']);
- if ( $code['j_poste'] == $tva_deb ||
- $code['j_poste'] == $tva_cred )
- {
-
- // For the reversed operation
- if ( $p_jrn_type == 'ACH' && $code['j_debit'] == 'f')
- {
- $code['j_montant']=-1*$code['j_montant'];
- }
- if ( $p_jrn_type == 'VEN' && $code['j_debit'] == 't')
- {
- $code['j_montant']=-1*$code['j_montant'];
- }
-
- $p_array['AMOUNT_TVA']+=$code['j_montant'];
-
- $p_array['TVA'][$c]=array($idx_tva,array($line_tva['tva_id'],$line_tva['tva_label'],$code['j_montant']));
- $c++;
-
- $idx_tva++;
- }
- }
-
- // isDNA
- // If operation is reversed then amount are negatif
- /* if ND */
- if ( $p_array['jrn_def_type'] == 'ACH') {
- $purchase=new Gestion_Purchase($this->db);
- $purchase->search_by_jid($code['j_id']);
- $purchase->load();
- $dep_priv+=$purchase->qp_dep_priv;
- $p_array['dep_priv']=$dep_priv;
- }
-
- }
- $p_array['TVAC']=sprintf('% 10.2f',$p_array['TVAC']-$dep_priv);
- $p_array['HTVA']=sprintf('% 10.2f',$p_array['TVAC']-$p_array['AMOUNT_TVA']);
- $r="";
- $a_tva_amount=array();
- // inline TVA (used for the PDF)
- foreach ($p_array['TVA'] as $linetva)
- {
- foreach ($a_TVA as $tva)
- {
- if ( $tva['tva_id'] == $linetva[1][0] )
- {
- $a=$tva['tva_id'];
- $a_tva_amount[$a]=$linetva[1][2];
- }
- }
- }
- foreach ($a_TVA as $line_tva)
- {
- $a=$line_tva['tva_id'];
- if ( isset($a_tva_amount[$a]))
- {
- $tmp=sprintf("% 10.2f",$a_tva_amount[$a]);
- $r.="$tmp";
- }
- else
- $r.=sprintf("% 10.2f",0);
- }
- $p_array['TVA_INLINE']=$r;
-
- return $p_array;
- } // retrieve data from jrnx
- /*!
- * \brief Get the properties of a journal
- *
- * \return an array containing properties
- *
- */
- function get_propertie()
- {
- if ( $this->id == 0 ) return;
-
- $Res=$this->db->exec_sql("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_cred,jrn_def_pj_pref
- from jrn_Def
- where jrn_def_id=$1",array($this->id));
- $Count=Database::num_row($Res);
- if ( $Count == 0 ) {
- echo '
'._('Parametres journaux non trouves').' ';
- return null;
- }
- return Database::fetch_array($Res,0);
- }
-
- /*! \function GetDefLine
- * \brief Get the number of lines of a journal
- * \param $p_cred deb or cred
- *
- * \return an integer
- */
- function GetDefLine()
- {
- $sql_cred='jrn_deb_max_line';
- $sql="select jrn_deb_max_line as value from jrn_def where jrn_def_id=$1";
- $r=$this->db->exec_sql($sql,array($this->id));
- $Res=Database::fetch_all($r);
- if ( sizeof($Res) == 0 ) return 1;
- return $Res[0]['value'];
- }
- /*!\brief get the saldo of a ledger for a specific period
- * \param $p_from start period
- * \param $p_to end period
- */
- function get_solde($p_from,$p_to) {
- $ledger="";
- if ( $this->id != 0 ) {
- $ledger=" and j_jrn_def = ".$this->id;
- }
-
- $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','j_tech_per');
- $sql='select j_montant as montant,j_debit as deb from jrnx where '
- .$periode.$ledger;
-
- $ret=$this->db->exec_sql($sql);
- $array=Database::fetch_all($ret);
- $deb=0.0;
- $cred=0.0;
- foreach ($array as $line) {
-
- if ( $line['deb']=='t' )
- $deb+=$line['montant'];
- else
- $cred+=$line['montant'];
- }
- $response=array($deb,$cred);
- return $response;
- }
- /*!
- * \brief Show a select list of the ledgers you can access in
- * writing, reading or simply accessing.
- * \param $p_type = ALL or the type of the ledger (ACH,VEN,FIN,ODS)
- * \param $p_access =3 for READ and WRITE, 2 for write and 1 for readonly
- * \return object HtmlInput select
- */
- function select_ledger($p_type="ALL",$p_access=3) {
- $user=new User($this->db);
- $array=$user->get_ledger($p_type,$p_access);
-
- if ( $array == null ) return null;
- $idx=0;
- $ret=array();
-
- foreach ( $array as $value) {
- $ret[$idx]['value']=$value['jrn_def_id'];
- $ret[$idx]['label']=h($value['jrn_def_name']);
- $idx++;
- }
-
- $select=new ISelect();
- $select->name='p_jrn';
- $select->value=$ret;
- $select->selected=$this->id;
- return $select;
- }
- /*!
- * \brief retrieve the jrn_def_fiche and return them into a array
- * index deb, cred
- * \param
- * \param
- * \param
- *
- *
- * \return return an array ('deb'=> ,'cred'=>)
- */
- function get_fiche_def() {
- $sql="select jrn_def_fiche_deb as deb,jrn_def_fiche_cred as cred ".
- " from jrn_def where ".
- " jrn_def_id = $1 ";
-
- $r=$this->db->exec_sql($sql,array($this->id));
-
- $res=Database::fetch_all($r);
- if ( empty($res) ) return null;
-
- return $res[0];
- }
- /*!
- * \brief retrieve the jrn_def_class_deb and return it
- *
- *
- * \return return an string
- */
- function get_class_def() {
- $sql="select jrn_def_class_deb ".
- " from jrn_def where ".
- " jrn_def_id = $1";
-
- $r=$this->db->exec_sql($sql,array($this->id));
-
- $res=Database::fetch_all($r);
-
- if ( empty($res) ) return null;
-
- return $res[0];
- }
-
- /*!
- * \brief show the result of the array to confirm
- * before inserting
- * \param $p_array array from the form
- * \return string
- */
- function show_summary($p_array) {
- $this->id=$p_array['p_jrn'];
- if ( empty($p_array)) return 'Aucun résultat';
- $anc=null;
- extract($p_array);
- $lPeriode=new Periode($this->db);
- if ($this->check_periode() == true) {
- $lPeriode->p_id=$period;
- } else {
- $lPeriode->find_periode($e_date);
- }
- $owner=new own($this->db);
-
- $ret="";
- $ret.="";
- $ret.=""._('Date')." : $e_date ";
- /* display periode */
- $date_limit=$lPeriode->get_date_limit();
- $ret.=' '._('Période Comptable').' '.$date_limit['p_start'].'-'.$date_limit['p_end'].' ';
- $ret.=""._('Libellé')." ".h($desc)." ";
- $ret.=""._('PJ Num')." ".h($e_pj)." ";
- $ret.='
';
- $ret.="";
- $ret.="";
- $ret.=""._('Quick Code ou');
- $ret.=_("Poste")." ";
- $ret.=" "._("Montant")." ";
- $ret.=""._("Débit")." ";
- /* if we use the AC */
- if ($owner->MY_ANALYTIC!='nu') {
- $anc=new Anc_Plan($this->db);
- $a_anc=$anc->get_list();
- $x=count($a_anc);
- /* set the width of the col */
- $ret.=''._('Compt. Analytique').' ';
-
- /* add hidden variables pa[] to hold the value of pa_id */
- $ret.=Anc_Plan::hidden($a_anc);
- }
- $ret.=" ";
-
- $ret.=HtmlInput::hidden('e_date',$e_date);
- $ret.=HtmlInput::hidden('desc',$desc);
- $ret.=HtmlInput::hidden('period',$lPeriode->p_id);
- $ret.=HtmlInput::hidden('e_pj',$e_pj);
- $ret.=HtmlInput::hidden('e_pj_suggest',$e_pj_suggest);
- $mt=microtime(true);
- $ret.=HtmlInput::hidden('mt',$mt);
- // For predefined operation
- $ret.=HtmlInput::hidden('e_comm',$desc);
- $ret.=HtmlInput::hidden('jrn_type',$this->get_type());
- $ret.=HtmlInput::hidden('p_jrn',$this->id);
- $ret.=HtmlInput::hidden('nb_item',$nb_item);
- if ( $this->with_concerned==true) {
- $ret.=HtmlInput::hidden('jrn_concerned',$jrn_concerned);
- }
- $ret.=dossier::hidden();
- $count=0;
- for ($i=0;$i<$nb_item;$i++) {
- $ret.="";
- if ( trim(${'qc_'.$i})!="") {
- $oqc=new Fiche($this->db);
- $oqc->get_by_qcode(${'qc_'.$i},false);
- $strPoste=$oqc->strAttribut(ATTR_DEF_ACCOUNT);
- $ret.="".
- ${'qc_'.$i}.' - '.
- $oqc->strAttribut(ATTR_DEF_NAME).HtmlInput::hidden('qc_'.$i,${'qc_'.$i}).
- ' ';
- }
-
- if ( trim(${'qc_'.$i})=="" && trim(${'poste'.$i}) != "") {
- $oposte=new Acc_Account_Ledger($this->db,${'poste'.$i});
- $strPoste=$oposte->id;
- $ret.="".h(${"poste".$i}." - ".
- $oposte->get_name()).HtmlInput::hidden('poste'.$i,${'poste'.$i}).
- ' ';
- }
-
- if ( trim(${'qc_'.$i})=="" && trim(${'poste'.$i}) == "")
- continue;
- $ret.="".h(${"ld".$i}).HtmlInput::hidden('ld'.$i,${'ld'.$i})." ";
- $ret.="".${"amount".$i}.HtmlInput::hidden('amount'.$i,${'amount'.$i})." ";
- $ret.="";
- $ret.=(isset(${"ck$i"}))?"D":"C";
- $ret.=(isset(${"ck$i"}))?HtmlInput::hidden('ck'.$i,${'ck'.$i}):"";
- $ret.=" ";
- // CA
-
- if ( $owner->MY_ANALYTIC!='nu') // use of AA
- {
- if ( myereg("^[6,7]+",$strPoste)) {
- // show form
- $op=new Anc_Operation($this->db);
- $null=($owner->MY_ANALYTIC=='op')?1:0;
- $p_array['pa_id']=$a_anc;
- /* op is the operation it contains either a sequence or a jrnx.j_id */
- $ret.=HtmlInput::hidden('op[]=',$i);
-
- $ret.='';
- $ret.=$op->display_form_plan($p_array,$null,1,$count,round(${'amount'.$i},2));
- $ret.=' ';
- $count++;
- }
-
-
- }
-
-
-
- $ret.=" ";
- }
- $ret.="
";
- $ret.=' ';
- return $ret;
- }
-
- /*!
- * \brief Show the form to encode your operation
- * \param $p_array if you correct or use a predef operation (default = null)
- * \param $p_readonly 1 for readonly 0 for writable (default 0)
- *
- * \return a string containing the form
- */
- function show_form($p_array=null,$p_readonly=0)
- {
- $user = new User($this->db);
- $owner=new Own($this->db);
-
- if ( $p_readonly == 1 )
- return $this->show_summary($p_array);
-
- if ( $p_array != null )
- extract($p_array);
-
- $ret="";
- /* Add button */
- $f_add_button=new IButton('add_card');
- $f_add_button->label=_('Créer une nouvelle fiche');
- $f_add_button->set_attribute('ipopup','ipop_newcard');
- $f_add_button->set_attribute('jrn',$this->id);
- $f_add_button->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
- $ret.=$f_add_button->input();
-
- // Load the javascript
- //
- $ret.="";
- $ret.= '';
- $wDate=new IDate('e_date');
- $wDate->readonly=$p_readonly;
- $e_date=(isset($e_date)&&trim($e_date)!='')?$e_date:'';
- $wDate->value=$e_date;
-
- $ret.=_("Date").' : '.$wDate->input();
- $ret.= ' ';
- /* insert periode if needed */
- // Periode
- //--
- if ($this->check_periode() == true) {
- $l_user_per=$user->get_periode();
- $def=(isset($periode))?$periode:$l_user_per;
-
- $period=new IPeriod("period");
- $period->user=$user;
- $period->cn=$this->db;
- $period->value=$def;
- $period->type=OPEN;
- try {
- $l_form_per=$period->input();
- } catch (Exception $e) {
- if ($e->getCode() == 1 ) {
- echo _("Aucune période ouverte");
- exit();
- }
- }
- $label=HtmlInput::infobulle(3);
- $f_periode=_("Période comptable")." $label ".$l_form_per;
- $ret.=td($f_periode);
- }
- $wPJ=new IText('e_pj');
- $wPJ->readonly=false;
- $wPJ->size=10;
-
- /* suggest PJ ? */
- $default_pj='';
- $owner=new Own($this->db);
- if ( $owner->MY_PJ_SUGGEST=='Y') {
- $default_pj=$this->guess_pj();
- }
- $wPJ->value=(isset($e_pj))?$e_pj:$default_pj;
-
- $ret.=' '._('Pièce').' : '.$wPJ->input();
- $ret.=HtmlInput::hidden('e_pj_suggest',$default_pj);
- $ret.= ' ';
- $ret.= ' ';
-
- $ret.= ''._('Libellé');
- $wDescription=new IText('desc');
- $wDescription->readonly=$p_readonly;
- $wDescription->size=100;
- $wDescription->value=(isset($desc))?$desc:'';
- $ret.=' ';
- $ret.=$wDescription->input();
- $ret.= ' ';
- $ret.=' ';
-
- $ret.= '
';
- $nb_row=(isset($nb_item) )?$nb_item:$this->nb;
-
- $ret.=HtmlInput::hidden('nb_item',$nb_row);
- $ret.=dossier::hidden();
-
- $ret.=HtmlInput::hidden('p_jrn',$this->id);
- $ret.=dossier::hidden();
-
- $ret.=HtmlInput::hidden('jrn_type',$this->get_type());
- $info= HtmlInput::infobulle(0);
- $info_poste=HtmlInput::infobulle(9);
- $ret.='';
- $ret.=''.
- 'Quickcode'.$info.' '.
- ''._('Poste').$info_poste.' '.
- ''._('Libellé').' '.
- ''._('Montant').' '.
- ''._('Débit').' '.
- ' ';
-
-
- for ($i = 0 ;$i<$nb_row;$i++){
- // Quick Code
- $quick_code=new ICard('qc_'.$i);
- $quick_code->set_dblclick("fill_ipopcard(this);");
- $quick_code->set_attribute('ipopup','ipopcard');
-
- // name of the field to update with the name of the card
- $quick_code->set_attribute('label',"ld".$i);
- $quick_code->set_attribute('jrn',$this->id);
-
- // name of the field to update with the name of the card
- $quick_code->set_attribute('typecard','filter');
- $quick_code->extra='filter';
- // Add the callback function to filter the card on the jrn
- $quick_code->set_callback('filter_card');
- $quick_code->set_function('fill_data');
- $quick_code->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
- $quick_code->name);
-
- $quick_code->jrn=$this->id;
- $quick_code->value=(isset(${'qc_'.$i}))?${'qc_'.$i}:"";
- $quick_code->readonly=$p_readonly;
-
- $label='';
- if ( $quick_code->value != '' ) {
- $Fiche=new Fiche($this->db);
- $Fiche->get_by_qcode($quick_code->value);
- $label=$Fiche->strAttribut(ATTR_DEF_NAME);
- }
-
-
- // Account
- $poste=new IPoste();
- $poste->name='poste'.$i;
- $poste->set_attribute('jrn',$this->id);
- $poste->set_attribute('ipopup','ipop_account');
- $poste->set_attribute('label','ld'.$i);
- $poste->set_attribute('account','poste'.$i);
-
- $poste->value=(isset(${'poste'.$i}))?${"poste".$i}:'';
- $poste->readonly=$p_readonly;
-
- if ( $poste->value != '' ) {
- $Poste=new Acc_Account($this->db);
- $Poste->set_parameter('value',$poste->value);
- $label=$Poste->get_lib();
- }
-
- // Description of the line
- $line_desc=new IText();
- $line_desc->name='ld'.$i;
- $line_desc->size=30;
- $line_desc->value=(isset(${"ld".$i}))?${"ld".$i}:$label;
-
- // Amount
- $amount=new INum();
- $amount->size=10;
- $amount->name='amount'.$i;
- $amount->value=(isset(${'amount'.$i}))?${"amount".$i}:'';
- $amount->readonly=$p_readonly;
- $amount->javascript=' onChange="format_number(this);checkTotalDirect()"';
- // D/C
- $deb=new ICheckBox();
- $deb->name='ck'.$i;
- $deb->selected=(isset(${'ck'.$i}))?true:false;
- $deb->readonly=$p_readonly;
- $deb->javascript=' onChange="checkTotalDirect()"';
-
- $ret.='';
- $ret.=''.$quick_code->search().$quick_code->input().' ';
- $ret.=''.$poste->input().
- ''.
- ' ';
- $ret.=''.$line_desc->input().' ';
- $ret.=''.$amount->input().' ';
- $ret.=''.$deb->input().' ';
- $ret.=' ';
- // If readonly == 1 then show CA
- }
- $ret.='
';
- if ( isset ($this->with_concerned) && $this->with_concerned==true) {
- $oRapt=new Acc_Reconciliation($this->db);
- $w=$oRapt->widget();
- $w->name='jrn_concerned';
- $w->value=(isset($jrn_concerned))?$jrn_concerned:"";
- $ret.="Réconciliation/rapprochements : ".$w->input();
- }
- return $ret;
- }
-
- /*!\brief
- * check if the current ledger is closed
- *\return 1 for yes, otherwise 0
- *\see Periode::is_closed
- */
- function is_closed($p_periode) {
- $per=new Periode($this->db);
- $per->set_jrn($this->id);
- $per->set_periode($p_periode);
- $ret=$per->is_closed();
- return $ret;
-
- }
- /*!
- * \brief verify that the operation can be saved
- * \param $p_array array of data same layout that the $_POST from show_form
- *
- *
- * \throw the getcode value is 1 incorrect balance, 2 date
- * invalid, 3 invalid amount, 4 the card is not in the range of
- * permitted card, 5 not in the user's period, 6 closed period
- *
- */
- function verify($p_array)
- {
- extract ($p_array);
- $user=new User($this->db);
- $tot_cred=0;$tot_deb=0;
-
- /* check if we can write into this ledger */
- $user=new User($this->db);
- if ( $user->check_jrn($p_jrn) != 'W' )
- throw new Exception (_('Accès interdit'),20);
-
- /* check for a double reload */
- if ( isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1',array($mt)) != 0 )
- throw new Exception ('Double Encodage',5);
-
- // Check the periode and the date
- if ( isDate($e_date) == null ) {
- throw new Exception('Date invalide', 2);
- }
- $periode=new Periode($this->db);
- /* find the periode if we have enabled the check_periode*/
- if ($this->check_periode()==false) {
- $periode->find_periode($e_date);
- } else {
- $periode->p_id=$period;
- list ($min,$max)=$periode->get_date_limit();
- if ( cmpDate($e_date,$min) < 0 ||
- cmpDate($e_date,$max) > 0)
- throw new Exception(_('Date et periode ne correspondent pas'),6);
-
- }
-
-
-
- // Periode ferme
- if ( $this->is_closed($periode->p_id)==1 )
- {
- throw new Exception('Periode fermee',6);
- }
- /* check if we are using the strict mode */
- if( $this->check_strict() == true) {
- /* if we use the strict mode, we get the date of the last
- operation */
- $last_date=$this->get_last_date();
- if ( $last_date !=null && cmpDate($e_date,$last_date) < 0 )
- throw new Exception(_('Vous utilisez le mode strict la dernière operation est la date du ')
- .$last_date.' '._('vous ne pouvez pas encoder à une date antérieure'),15);
-
- }
-
- for ($i=0;$i<$nb_item;$i++)
- {
- $err=0;
-
- // Check the balance
- if ( ! isset (${'amount'.$i}))
- continue;
-
- $amount=round(${'amount'.$i},2);
- $tot_deb+=(isset(${'ck'.$i}))?$amount:0;
- $tot_cred+=(! isset(${'ck'.$i}))?$amount:0;
-
- // Check if the card is permitted
- if ( isset (${'qc_'.$i}) && trim(${'qc_'.$i}) !="") {
- $f=new Fiche($this->db);
- $f->quick_code=${'qc_'.$i};
- if ( $f->belong_ledger($p_jrn) < 0 )
- throw new Exception("La fiche quick_code = ".
- $f->quick_code." n\'est pas dans ce journal",4);
- if ( strlen(trim(${'qc_'.$i}))!=0 && isNumber(${'amount'.$i} ) == 0 )
- throw new Exception('Montant invalide',3);
-
- }
-
- // Check if the account is permitted
- if ( isset (${'poste'.$i}) && strlen (trim(${'poste'.$i})) != 0 ) {
- $p=new Acc_Account_Ledger($this->db,${'poste'.$i});
- if ( $p->belong_ledger ($p_jrn) < 0 )
- throw new Exception(_("Le poste")." ".$p->id." "._("n'est pas dans ce journal"),5);
- if ( strlen(trim(${'poste'.$i}))!=0 && isNumber(${'amount'.$i} ) == 0 )
- throw new Exception(_('Poste invalide ['.${'poste'.$i}.']'),3);
- if ( $p->do_exist() == 0 )
- throw new Exception(_('Poste Inexistant ['.${'poste'.$i}.']'),4);
- }
-
-
- }
- $tot_deb=round($tot_deb,4);
- $tot_cred=round($tot_cred,4);
- if ( $tot_deb != $tot_cred ) {
- throw new Exception(_("Balance incorrecte ")." debit = $tot_deb credit=$tot_cred ",1);
- }
-
- }
- /*!
- * \brief compute the internal code of the saved operation and set the $this->jr_internal to
- * the computed value
- *
- * \param $p_grpt id in jr_grpt_
- *
- * \return string internal_code
- * -
- *
- */
- function compute_internal_code($p_grpt)
- {
- if ( $this->id==0) return;
- $num = $this->db->get_next_seq('s_internal');
- $atype=$this->get_propertie();
- $type=$atype['jrn_def_code'];
- $internal_code=sprintf("%s-%s",$type,$num);
- $this->jr_internal=$internal_code;
- return $internal_code;
- }
-
- /*!
- * \brief save the operation into the jrnx,jrn, ,
- * CA and pre_def
- * \param $p_array
- *
- * \return array with [0] = false if failed otherwise true, [1] error
- * code
- */
- function save ($p_array) {
- extract ($p_array);
- try {
- $this->verify($p_array);
-
- $this->db->start() ;
-
- $seq=$this->db->get_next_seq('s_grpt');
- $internal=$this->compute_internal_code($seq);
-
- $group=$this->db->get_next_seq("s_oa_group");
- $owner=new own($this->db);
- $tot_amount=0;
- $tot_deb=0;
- $tot_cred=0;
- $oPeriode=new Periode($this->db);
- $check_periode=$this->check_periode();
- if ( $check_periode == false) {
- $oPeriode->find_periode($e_date);
- } else {
- $oPeriode->id=$period;
- }
-
- $count=0;
- for ($i=0;$i<$nb_item;$i++)
- {
- if ( ! isset (${'qc_'.$i}) && ! isset(${'poste'.$i}))
- continue;
- $acc_op=new Acc_Operation($this->db);
- $quick_code="";
- // First we save the jrnx
- if ( isset(${'qc_'.$i})) {
- $qc=new Fiche($this->db);
- $qc->get_by_qcode(${'qc_'.$i},false);
- $sposte=$qc->strAttribut(ATTR_DEF_ACCOUNT);
- /* if there are 2 accounts take following the deb or cred */
- if (strpos($sposte,',') != 0 ){
- $array=explode(",",$sposte);
- $poste=(isset(${'ck'.$i}))?$array[0]:$array[1];
- } else {
- $poste=$sposte;
- }
- $quick_code=${'qc_'.$i};
- }
- else {
- $poste=${'poste'.$i};
- }
- $acc_op->date=$e_date;
- // compute the periode is do not check it
- if ($check_periode == false ) $acc_op->periode=$oPeriode->p_id;
- $acc_op->desc=$desc;
- if ( strlen(trim(${'ld'.$i})) != 0 )
- $acc_op->desc=${'ld'.$i};
- $acc_op->amount=round(${'amount'.$i},2);
- $acc_op->grpt=$seq;
- $acc_op->poste=$poste;
- $acc_op->jrn=$this->id;
- $acc_op->type=(isset (${'ck'.$i}))?'d':'c';
- $acc_op->qcode=$quick_code;
- $j_id=$acc_op->insert_jrnx();
- $tot_amount+=round($acc_op->amount,2);
- $tot_deb+=($acc_op->type=='d')?$acc_op->amount:0;
- $tot_cred+=($acc_op->type=='c')?$acc_op->amount:0;
- if ( $owner->MY_ANALYTIC != "nu" )
- {
- if ( myereg("^[6,7]+",$poste)) {
-
- // for each item, insert into operation_analytique */
- $op=new Anc_Operation($this->db);
- $op->oa_group=$group;
- $op->j_id=$j_id;
- $op->oa_date=$e_date;
- $op->oa_debit=($acc_op->type=='d' )?'t':'f';
- $op->oa_description=$desc;
- $op->save_form_plan($p_array,$count,$j_id);
- $count++;
- }
- }
- }// loop for each item
- $acc_end=new Acc_Operation($this->db);
- $acc_end->amount=$tot_deb;
- if ($check_periode == false ) $acc_end->periode=$oPeriode->p_id;
- $acc_end->date=$e_date;
- $acc_end->desc=$desc;
- $acc_end->grpt=$seq;
- $acc_end->jrn=$this->id;
- $acc_end->mt=$mt;
- $jr_id= $acc_end->insert_jrn();
- $this->jr_id=$jr_id;
- if ($jr_id == false )
- throw new Exception('Balance incorrecte');
- $acc_end->pj=$e_pj;
-
- /* if e_suggest != e_pj then do not increment sequence */
- if ( strcmp($e_pj,$e_pj_suggest) == 0 && strlen(trim($e_pj)) !=0) {
- $this->inc_seq_pj();
- }
-
- $this->pj=$acc_end->set_pj();
-
- $this->db->exec_sql("update jrn set jr_internal='".$internal."' where ".
- " jr_grpt_id = ".$seq);
- $this->internal=$internal;
- // Save now the predef op
- //------------------------
- if ( isset($save_opd)) {
- $opd=new Pre_Op_Advanced($this->db);
- $opd->name=(trim($desc)=='')?$internal:$desc;
- $opd->get_post();
- $opd->save();
- }
-
- if ( isset($this->with_concerned) && $this->with_concerned==true) {
- $orap=new acc_reconciliation($this->db);
- $orap->jr_id=$jr_id;
-
- $orap->insert($jrn_concerned);
- }
-
- }
-
- catch (Exception $a) {
- throw $a;
- }
- catch (Exception $e) {
- $this->db->rollback();
- echo 'OPERATION ANNULEE ';
- echo ' ';
- echo __FILE__.__LINE__.$e->getMessage();
- exit();
- }
- $this->db->commit();
- return true;
- }
-
- /*!
- * \brief get all the data from request and build the object
- */
- function get_request()
- {
- $this->id=$_REQUEST['p_jrn'];
-
- }
-
- /*!
- * \brief retrieve the next number for this type of ledger
- * \param p_cn connx
- * \param p_type ledger type
- *
- * \return the number
- *
- *
- */
- static function next_number($p_cn,$p_type)
- {
-
- $Ret=$p_cn->count_sql("select * from jrn_def where jrn_def_type='".$p_type."'");
- return $Ret+1;
- }
- /*!\brief get the first ledger
- *\param the type
- *\return the j_id
- */
- public function get_first($p_type) {
- $user=new User($this->db);
- $all=$user->get_ledger($p_type);
- return $all[0];
- }
-
-
- /*!\brief Update the paiment in the list of operation
- *\param $p_array is normally $_GET
- */
- function update_paid($p_array) {
- // reset all the paid flag because the checkbox is post only
- // when checked
- foreach ($p_array as $name=>$paid)
- {
- list($ad) = sscanf($name,"set_jr_id%d");
- if ( $ad == null ) continue;
- $sql="update jrn set jr_rapt='' where jr_id=$ad";
- $Res=$this->db->exec_sql($sql);
-
- }
- // set a paid flag for the checked box
- foreach ($p_array as $name=>$paid)
- {
- list ($id) = sscanf ($name,"rd_paid%d");
- if ( $id == null ) continue;
-
- $sql="update jrn set jr_rapt='paid' where jr_id=$id";
- $Res=$this->db->exec_sql($sql);
- }
-
- }
- function update_internal_code($p_internal) {
- if ( ! isset($this->grpt_id) )
- exit( 'ERREUR '.__FILE__.":".__LINE__);
- $Res=$this->db->exec_sql("update jrn set jr_internal='".$p_internal."' where ".
- " jr_grpt_id = ".$this->grpt_id);
-
- }
- /*!\brief retrieve all the card for this type of ledger, make them
- *into a string separated by comma
- *\param none
- *\return all the card or null is nothing is found
- */
- function get_all_fiche_def() {
- $sql="select jrn_def_fiche_deb as deb,jrn_def_fiche_cred as cred ".
- " from jrn_def where ".
- " jrn_def_id = $1 ";
-
- $r=$this->db->exec_sql($sql,array($this->id));
-
- $res=Database::fetch_all($r);
- if ( empty($res) ) return null;
- $card="";
- $comma='';
- foreach ($res as $item ) {
- if ( strlen(trim($item['deb'])) != 0 ) {
- $card.=$comma.$item['deb'];
- $comma=',';
- }
- if ( strlen(trim($item['cred'])) != '') {
- $card.=$comma.$item['cred'];
- $comma=',';
- }
-
- }
-
- return $card;
- }
- /*!\brief get the saldo of an exercice, used for the opening of a folder
- *\param $p_exercice is the exercice we want
- *\return an array
- * index =
- * - solde (debit > 0 ; credit < 0)
- * - j_poste
- * - j_qcode
- */
- function get_saldo_exercice($p_exercice) {
- $sql="select sum(a.montant) as solde, j_poste, j_qcode
- from
- (select j_id, case when j_debit='t' then j_montant
- else j_montant * (-1) end as montant
- from jrnx) as a
- join jrnx using (j_id)
- join parm_periode on (j_tech_per = p_id )
- where
- p_exercice=$1
- and j_poste::text not like '7%'
- and j_poste::text not like '6%'
- group by j_poste,j_qcode
- having (sum(a.montant) != 0 )";
- $res=$this->db->get_array($sql,array($p_exercice));
- return $res;
- }
-/*!
- *\brief Check if a Dossier is using the strict mode or not
- * \return true if we are using the strict_mode
- */
-function check_strict() {
- $owner=new Own($this->db);
- if ( $owner->MY_STRICT=='Y') return true;
- if ( $owner->MY_STRICT=='N') return false;
- exit("Valeur invalid ".__FILE__.':'.__LINE__);
-}
-/*!
- *\brief Check if a Dossier is using the check on the periode, if true than the user has to enter the date
- * and the periode, it is a security check
- * \return true if we are using the double encoding (date+periode)
- */
-function check_periode() {
- $owner=new Own($this->db);
- if ( $owner->MY_CHECK_PERIODE=='Y') return true;
- if ( $owner->MY_CHECK_PERIODE=='N') return false;
- exit("Valeur invalid ".__FILE__.':'.__LINE__);
-}
-
-/*!\brief get the date of the last operation
-*/
-function get_last_date()
+class Acc_Ledger
{
- if ( $this->id==0) throw new Exception (__FILE__.":".__LINE__."Journal incorrect ");
- $sql="select to_char(max(jr_date),'DD.MM.YYYY') from jrn where jr_def_id=$1";
- $date=$this->db->get_value($sql,array($this->id));
- return $date;
-}
- /*!\brief retrieve the jr_id thanks the internal code, do not change
- *anything to the current object
- *\param the internal code
- *\return the jr_id or 0 if not found
- */
- function get_id($p_internal) {
- $sql='select jr_id from jrn where jr_internal=$1';
- $value=$this->db->get_value($sql,array($p_internal));
- if ($value=='') $value=0;
- return $value;
- }
- /*!\brief create the invoice and saved it as attachment to the
- *operation,
- *\param $internal is the internal code
- *\param $p_array is normally the $_POST
- *\return a string
- */
- function create_document($internal,$p_array) {
- extract ($p_array);
- $doc=new Document($this->db);
- $doc->f_id=$e_client;
- $doc->md_id=$gen_doc;
- $doc->ag_id=0;
- $doc->Generate();
- // Move the document to the jrn
- $doc->MoveDocumentPj($internal);
- // Update the comment with invoice number, if the comment is empty
- if ( ! isset ($e_comm) || strlen(trim($e_comm))== 0 ) {
- $sql="update jrn set jr_comment=' document ".$doc->d_number."' where jr_internal='$internal'";
- $this->db->exec_sql($sql);
+ var $id; /*!< jrn_def.jrn_def_id */
+ var $name; /*!< jrn_def.jrn_def_name */
+ var $db; /*!< database connextion */
+ var $row; /*!< row of the ledger */
+ var $type; /*!< type of the ledger ACH ODS FIN
+ VEN or GL */
+ var $nb; /*!< default number of rows by
+ default 10 */
+ /**
+ *@param $p_cn database connexion
+ *@param $p_id jrn.jrn_def_id
+ */
+ function __construct ($p_cn,$p_id)
+ {
+ $this->id=$p_id;
+ $this->db=$p_cn;
+ $this->row=null;
+ $this->nb=10;
}
- return h($doc->d_name.' ('.$doc->d_filename.')');
-
- }
- /*!\brief check if the payment method is valid
- *\param $e_mp is the value and $e_mp_qcode is the quickcode
- *\return nothing throw an Exception
- */
- public function check_payment($e_mp,$e_mp_qcode) {
- /* Check if the "paid by" is empty, */
- if ( $e_mp != 0) {
- /* the paid by is not empty then check if valid */
- $empl=new Fiche($this->db);
- $empl->get_by_qcode($e_mp_qcode);
- if ( $empl->empty_attribute(ATTR_DEF_ACCOUNT)== true) {
- throw new Exception('Celui qui paie n\' a pas de poste comptable',20);
- }
- /* get the account and explode if necessary */
- $sposte=$empl->strAttribut(ATTR_DEF_ACCOUNT);
- // if 2 accounts, take only the debit one for customer
- if ( strpos($sposte,',') != 0 ) {
- $array=explode(',',$sposte);
- $poste_val=$array[0];
- } else {
- $poste_val=$sposte;
- }
- $poste=new Acc_Account_Ledger($this->db,$poste_val);
- if ( $poste->load() == false ){
- throw new Exception('Pour la fiche'.$empl->quick_code.' le poste comptable ['.$poste->id.'n\'existe pas',9);
-
- }
+ function get_last_pj()
+ {
+ if ( $this->db->exist_sequence("s_jrn_pj".$this->id) )
+ {
+ $ret= $this->db->get_array("select last_value,is_called from s_jrn_pj".$this->id);
+ $last=$ret[0]['last_value'];
+ /*!
+ *\note With PSQL sequence , the last_value column is 1 when before AND after the first call, to make the difference between them
+ * I have to check whether the sequence has been already called or not */
+ if ($ret[0]['is_called']=='f' ) $last--;
+ return $last;
+ }
+ else
+ $this->db->create_sequence("s_jrn_pj".$this->id);
+ return 0;
}
- }
+ /*!
+ * \brief Return the type of a ledger (ACH,VEN,ODS or FIN) or GL
+ *
+ */
+ function get_type()
+ {
+ if ( $this->id==0 )
+ {
+ $this->name=" Tous les journaux";
+ $this->type="GL";
+ return "GL";
+ }
+
+ $Res=$this->db->exec_sql("select jrn_def_type from ".
+ " jrn_def where jrn_def_id=".
+ $this->id);
+ $Max=Database::num_row($Res);
+ if ($Max==0) return null;
+ $ret=Database::fetch_array($Res,0);
+ $this->type=$ret['jrn_def_type'];
+ return $ret['jrn_def_type'];
+ }
+ /**
+ *let you delete a operation
+ *@note by cascade it will delete also in
+ * - jrnx
+ * - stock
+ * - quant_purchase
+ * - quant_fin
+ * - quant_sold
+ * - operation_analytique
+ * - letter
+ * - reconciliation
+ *@bug the attached document is not deleted
+ */
+ function delete()
+ {
+ if ( $this->id == 0 ) return;
+ $grpt_id=$this->db->get_value('select jr_grpt_id from jrn where jr_id=$1',
+ array($this->jr_id));
+ if ( $this->db->count()==0) return;
+ $this->db->exec_sql('delete from jrnx where j_grpt=$1',
+ array($grpt_id));
+ $this->db->exec_sql('delete from jrn where jr_id=$1',
+ array($this->jr_id));
+ }
+ /**
+ * reverse the operation by creating the opposite one,
+ * the result is to avoid it
+ * it must be done in
+ * - jrn
+ * - jrnx
+ * - quant_fin
+ * - quant_sold
+ * - quant_purchase
+ * - stock
+ * - ANC
+ *@param $p_date is the date of the reversed op
+ *@exception if date is invalid or other prob
+ *@note automatically create a reconciliation between operation
+ *You must set the ledger_id $this->jrn_def_id
+ */
+ function reverse($p_date)
+ {
+ if ( ! isset ($this->jr_id) || $this->jr_id=='')
+ throw new Exception ("this->jr_id is not set ou opération inconnue");
+
+ $user=new User($this->db);
+ /* check if the date is valid */
+ if ( isDate($p_date) == null )
+ throw new Exception (_('Date invalide').$p_date);
+
+ // if the operation is in a closed or centralized period
+ // the operation is voided thanks the opposite operation
+ $grp_new=$this->db->get_next_seq('s_grpt');
+ $seq=$this->db->get_next_seq("s_jrn");
+ $p_internal=$this->compute_internal_code($seq);
+ $this->jr_grpt_id=$this->db->get_value('select jr_grpt_id from jrn where jr_id=$1',
+ array($this->jr_id));
+ if ( $this->db->count()==0)
+ throw new Exception (_("Cette opération n'existe pas"));
+ $this->jr_internal=$this->db->get_value('select jr_internal from jrn where jr_id=$1',
+ array($this->jr_id));
+ if ( $this->db->count()==0 || trim($this->jr_internal)=='')
+ throw new Exception (_("Cette opération n'existe pas"));
+
+ /* find the periode thanks the date */
+ $per=new Periode($this->db);
+ $per->jrn_def_id=$this->id;
+ $per->find_periode($p_date);
+
+ if ( $per->is_open() == 0 )
+ throw new Exception (_('PERIODE FERMEE'));
+
+ $sql= "insert into jrn (
+ jr_id,
+ jr_def_id,
+ jr_montant,
+ jr_comment,
+ jr_date,
+ jr_grpt_id,
+ jr_internal
+ ,jr_tech_per, jr_valid
+ )
+ select $1,jr_def_id,jr_montant,'Annulation '||jr_comment,
+ to_date($2,'DD.MM.YYYY'),$3,$4,
+ $5, true
+ from
+ jrn
+ where jr_id=$6";
+ $Res=$this->db->exec_sql($sql,array($seq,$p_date,$grp_new,$p_internal,$per->p_id,$this->jr_id));
+ // Check return code
+ if ( $Res == false)
+ throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]"));
- /*!\brief increment the sequence for the pj */
- function inc_seq_pj() {
- $sql="select nextval('s_jrn_pj".$this->id."')";
- $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
- *\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) {
- $user=new User($this->db);
- $r='';
- /* security : filter ledger on user */
- $filter_ledger=$user->get_ledger($p_type,3);
- $selected=(isset($_REQUEST['r_jrn']))?$_REQUEST['r_jrn']:null;
- $f_ledger=HtmlInput::select_ledger($filter_ledger,$selected);
-
- /* 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 {
- $period=$user->get_periode();
- $per=new Periode($this->db,$period);
- $exercice=$per->get_exercice();
- list($per_start,$per_end)=$per->get_limit($exercice);
- $f_date_start->value=$per_start->first_day();
- $date_end=$per_end->last_day();
+
+ // Mark the operation invalid into the ledger
+ // to avoid to nullify twice the same op.
+ $sql="update jrn set jr_comment='Annule : '||jr_comment where jr_id=$1";
+ $Res=$this->db->exec_sql($sql,array($this->jr_id));
+
+ // Check return code
+ if ( $Res == false)
+ throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]"));
+
+ //////////////////////////////////////////////////
+ // Reverse in QUANT_* tables
+ //////////////////////////////////////////////////
+ $a_jid=$this->db->get_array("select j_id,j_debit from jrnx where j_grpt=$1",array($this->jr_grpt_id));
+ for ($l=0;$ldb->exec_sql($sql,array($p_date,$grp_new,$p_internal,$user->id,$per->p_id,$row));
+ // Check return code
+ if ( $Res == false)
+ throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]"));
+ $aj_id=$this->db->fetch(0);
+ $j_id=$aj_id['j_id'];
+
+ /* automatic lettering */
+ $let=new Lettering($this->db);
+ $let->insert_couple($j_id,$row);
+
+ // reverse in QUANT_SOLD
+ $Res=$this->db->exec_sql("INSERT INTO quant_sold(
+ qs_internal, qs_fiche, qs_quantite, qs_price, qs_vat,
+ qs_vat_code, qs_client, qs_valid, j_id)
+ SELECT $1, qs_fiche, qs_quantite*(-1), qs_price, qs_vat,
+ qs_vat_code, qs_client, qs_valid, $2
+ FROM quant_sold where j_id=$3",
+ array($p_internal,$j_id,$row));
+
+ if ( $Res == false)
+ throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]"));
+ $Res=$this->db->exec_sql("INSERT INTO quant_purchase(
+ qp_internal, j_id, qp_fiche, qp_quantite, qp_price, qp_vat,
+ qp_vat_code, qp_nd_amount, qp_nd_tva, qp_nd_tva_recup, qp_supplier,
+ qp_valid, qp_dep_priv)
+ SELECT $1, $2, qp_fiche, qp_quantite*(-1), qp_price, qp_vat,
+ qp_vat_code, qp_nd_amount, qp_nd_tva, qp_nd_tva_recup, qp_supplier,
+ qp_valid, qp_dep_priv
+ FROM quant_purchase where j_id=$3",
+ array($p_internal,$j_id,$row));
+
+ if ( $Res == false)
+ throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]"));
+ }
+ // reverse in QUANT_FIN table
+ $Res=$this->db->exec_sql(" INSERT INTO quant_fin(
+ qf_bank, qf_other, qf_amount,jr_id)
+ SELECT qf_bank, qf_other, qf_amount*(-1),$1
+ FROM quant_fin where jr_id=$2",array($seq,$this->jr_id));
+ if ( $Res == false)
+ throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]"));
+
+ // Add a "concerned operation to bound these op.together
+ //
+ $rec=new Acc_Reconciliation ($this->db);
+ $rec->set_jr_id($seq);
+ $rec->insert($this->jr_id);
+
+ // Check return code
+ if ( $Res == false )
+ {
+ throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]"));
+ }
+
+
+ // the table stock must updated
+ // also in the stock table
+ $sql="delete from stock_goods where sg_id = any ( select sg_id
+ from stock_goods natural join jrnx where j_grpt=".$this->jr_grpt_id.")";
+ $Res=$this->db->exec_sql($sql);
+ /**
+ *@function
+ *@todo remove also from ANC */
+
+ // Check return code
+ if ( $Res == false)
+ throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]"));
+
+ }
+ /*!
+ * \brief Return the name of a ledger
+ *
+ */
+ function get_name()
+ {
+ if ( $this->id==0 )
+ {
+ $this->name=" Grand Livre ";
+ return $this->name;
+ }
+
+ $Res=$this->db->exec_sql("select jrn_def_name from ".
+ " jrn_def where jrn_def_id=".
+ $this->id);
+ $Max=Database::num_row($Res);
+ if ($Max==0) return null;
+ $ret=Database::fetch_array($Res,0);
+ $this->name=$ret['jrn_def_name'];
+ return $ret['jrn_def_name'];
}
- /* 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;
+
+ /*! \function get_row
+ * \brief Get The data
+ *
+ *
+ * \param p_from from periode
+ * \param p_to to periode
+ * \param p_limit starting line
+ * \param p_offset number of lines
+ * \return Array with the asked data
+ *
+ */
+ function get_row($p_from,$p_to,$p_limit=-1,$p_offset=-1)
+ {
+ /**
+ *@todo add a filter for security
+ */
+
+ $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per');
+
+ $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:"";
+ // retrieve the type
+ $this->get_type();
+ // Grand livre == 0
+ if ( $this->id != 0 )
+ {
+ $Res=$this->db->exec_sql("select jr_id,j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date,
+ jr_internal,
+ case j_debit when 't' then j_montant::text else ' ' end as deb_montant,
+ case j_debit when 'f' then j_montant::text else ' ' end as cred_montant,
+ j_debit as debit,j_poste as poste,jr_montant , ".
+ "coalesce(j_text,pcm_lib) as description,j_grpt as grp,
+ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj_number !='' then jr_pj_number else '' end as jr_comment,
+ j_qcode,
+ jr_rapt as oc, j_tech_per as periode
+ from jrnx left join jrn on ".
+ "jr_grpt_id=j_grpt ".
+ " left join tmp_pcmn on pcm_val=j_poste ".
+ " where j_jrn_def=".$this->id.
+ " and ".$periode." order by j_date::date asc,jr_internal,j_debit desc ".
+ $cond_limite);
+
+ }
+ else
+ {
+ $Res=$this->db->exec_sql("select jr_id,j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date,
+ jr_internal,
+ case j_debit when 't' then j_montant::text else ' ' end as deb_montant,
+ case j_debit when 'f' then j_montant::text else ' ' end as cred_montant,
+ j_debit as debit,j_poste as poste,".
+ "coalesce(j_text,pcm_lib) as description,j_grpt as grp,
+ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj_number !='' then 'pj:'||coalesce(jr_pj_number,'-') else '' end as jr_comment,
+ jr_montant,
+ j_qcode,
+ jr_rapt as oc, j_tech_per as periode from jrnx left join jrn on ".
+ "jr_grpt_id=j_grpt left join tmp_pcmn on pcm_val=j_poste where ".
+ " ".$periode." order by j_date::date,j_grpt,j_debit desc ".
+ $cond_limite);
+
+ }
+
+
+ $array=array();
+ $Max=Database::num_row($Res);
+ if ($Max==0) return null;
+ $case="";
+ $tot_deb=0;
+ $tot_cred=0;
+ $row=Database::fetch_all($Res);
+ for ($i=0;$i<$Max;$i++)
+ {
+ $fiche=new Fiche($this->db);
+ $line=$row[$i];
+ $mont_deb=($line['deb_montant']!=0)?sprintf("% 8.2f",$line['deb_montant']):"";
+ $mont_cred=($line['cred_montant']!=0)?sprintf("% 8.2f",$line['cred_montant']):"";
+ $jr_montant=($line['jr_montant']!=0)?sprintf("% 8.2f",$line['jr_montant']):"";
+ $tot_deb+=$line['deb_montant'];
+ $tot_cred+=$line['cred_montant'];
+ $tot_op=$line['jr_montant'];
+
+ /* Check first if there is a quickcode */
+ if ( strlen(trim($line['j_qcode'])) != 0 )
+ {
+ if ( $fiche->get_by_qcode($line['j_qcode'],false) == 0 )
+ {
+ $line['description']=$fiche->strAttribut(ATTR_DEF_NAME);
+ }
+ }
+ if ( $case != $line['grp'] )
+ {
+ $case=$line['grp'];
+ // for financial, we show if the amount is or not in negative
+ if ( $this->type=='FIN')
+ {
+ $amount=$this->db->get_value('select qf_amount from quant_fin where jr_id=$1',
+ array($line['jr_id']));
+ /* if nothing is found */
+ if ( $this->db->count()==0 )
+ $tot_op=$jr_montant;
+ else if ( $amount < 0 )
+ {
+ $tot_op=$amount;
+ }
+ }
+ $array[]=array (
+ 'jr_id'=>$line['jr_id'],
+ 'int_j_id' => $line['int_j_id'],
+ 'j_id'=>$line['j_id'],
+ 'j_date' => $line['j_date'],
+ 'internal'=>$line['jr_internal'],
+ 'deb_montant'=>'',
+ 'cred_montant'=>' ',
+ 'description'=>''.h($line['jr_comment']).' ['.$tot_op.'] ',
+ 'poste' => $line['oc'],
+ 'qcode' => $line['j_qcode'],
+ 'periode' =>$line['periode'] );
+
+ $array[]=array (
+ 'jr_id'=>'',
+ 'int_j_id' => $line['int_j_id'],
+ 'j_id'=>'',
+ 'j_date' => '',
+ 'internal'=>'',
+ 'deb_montant'=>$mont_deb,
+ 'cred_montant'=>$mont_cred,
+ 'description'=>$line['description'],
+ 'poste' => $line['poste'],
+ 'qcode' => $line['j_qcode'],
+ 'periode' => $line['periode']
+ );
+
+ }
+ else
+ {
+ $array[]=array (
+ 'jr_id'=>$line['jr_id'],
+ 'int_j_id' => $line['int_j_id'],
+ 'j_id'=>'',
+ 'j_date' => '',
+ 'internal'=>'',
+ 'deb_montant'=>$mont_deb,
+ 'cred_montant'=>$mont_cred,
+ 'description'=>$line['description'],
+ 'poste' => $line['poste'],
+ 'qcode' => $line['j_qcode'],
+ 'periode' => $line['periode']);
+
+ }
+
+
+ }
+ $this->row=$array;
+ $a=array($array,$tot_deb,$tot_cred);
+ return $a;
+ }
+ /*! \brief Get simplified row from ledger
+ *
+ * \param from periode
+ * \param to periode
+ * \param p_limit starting line
+ * \param p_offset number of lines
+ * \param trunc if data must be truncated (pdf export)
+ *
+ * \return an Array with the asked data
+ */
+ function get_rowSimple($p_from,$p_to,$trunc=0,$p_limit=-1,$p_offset=-1)
+ {
+ // Grand-livre : id= 0
+ //---
+ $jrn=($this->id == 0 )?"":"and jrn_def_id = ".$this->id;
+
+ $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per');
+
+ $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:"";
+ //---
+ $sql="
+ SELECT jrn.jr_id as jr_id ,
+ jrn.jr_id as num ,
+ jrn.jr_def_id as jr_def_id,
+ jrn.jr_montant as montant,
+ substr(jrn.jr_comment,1,35)|| case when jr_pj_number is not null and jr_pj_number !='' then 'pj:'||coalesce(jr_pj_number,'-') else '' end as comment,
+ to_char(jrn.jr_date,'DD-MM-YYYY') as date,
+ jr_internal,
+ jrn.jr_grpt_id as grpt_id,
+ jrn.jr_pj_name as pj,
+ jrn_def_type,
+ jrn.jr_tech_per
+ FROM jrn join jrn_def on (jrn_def_id=jr_def_id)
+ WHERE $periode $jrn order by jr_date $cond_limite";
+
+ $Res=$this->db->exec_sql($sql);
+ $Max=Database::num_row($Res);
+ if ( $Max == 0 )
+ {
+ return null;
+ }
+ $type=$this->get_type();
+ // for type ACH and Ven we take more info
+ if ( $type == 'ACH' || $type == 'VEN')
+ {
+ $a_ParmCode=$this->db->get_array('select p_code,p_value from parm_code');
+ $a_TVA=$this->db->get_array('select tva_id,tva_label,tva_poste
+ from tva_rate where tva_rate != 0 order by tva_id');
+ for ( $i=0;$i<$Max;$i++)
+ {
+ $array[$i]=Database::fetch_array($Res,$i);
+ $p=$this->get_detail($array[$i],$type,$trunc,$a_TVA,$a_ParmCode);
+ if ( $array[$i]['dep_priv'] != 0.0)
+ {
+ $array[$i]['comment'].="(priv. ".$array[$i]['dep_priv'].")";
+ }
+ }
+
+ }
+ else
+ {
+ $array=Database::fetch_all($Res);
+
+ }
+
+ return $array;
+ }// end function get_rowSimple
+
+ /*!\brief guess what the next pj should be
+ */
+ function guess_pj()
+ {
+ $prop=$this->get_propertie();
+ $pj_pref=$prop["jrn_def_pj_pref"];
+ $pj_seq=$this->get_last_pj()+1;
+ return $pj_pref.$pj_seq;
}
- /* widget for desc */
- $f_descript=new IText('desc');
- $f_descript->size=40;
- if ( isset($_REQUEST['desc'])) {
- $f_descript->value=$_REQUEST['desc'];
+ /*!\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=jrn_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)
+ {
+ $user=new User($this->db);
+ $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();
+ $image_asc='';
+ $image_desc='';
+ $image_sel_desc='';
+ $image_sel_asc='';
+
+ $sort_date=" $image_asc "._('Date')."$image_desc ";
+ $sort_description=" $image_asc "._('Description')."$image_desc ";
+ $sort_amount=" $image_asc "._('Montant')." $image_desc ";
+ $sort_pj=" $image_asc "._('PJ')."$image_desc ";
+ $sort_echeance=" $image_asc "._('Ech')." $image_desc ";
+
+ $own=new Own($this->db);
+ // if an order is asked
+ if ( isset ($_GET['o']) )
+ {
+ switch ($_GET['o'])
+ {
+ case 'pja':
+ // pj asc
+ $sort_pj="$image_sel_asc PJ $image_desc ";
+ $order=' order by substring(jr_pj_number,\'\\\d+$\')::numeric asc ';
+ break;
+ case 'pjd':
+ $sort_pj=" $image_asc PJ $image_sel_desc ";
+ // pj desc
+ $order=' order by substring(jr_pj_number,\'\\\d+$\')::numeric desc ';
+ break;
+
+ case 'da':
+ // date asc
+ $sort_date="$image_sel_asc Date $image_desc ";
+ $order=" order by jr_date_order asc ";
+ break;
+ case 'dd':
+ $sort_date=" $image_asc Date $image_sel_desc ";
+ // date desc
+ $order=" order by jr_date_order desc ";
+ break;
+ case 'ma':
+ // montant asc
+ $sort_amount=" $image_sel_asc Montant $image_desc ";
+ $order=" order by jr_montant asc ";
+ break;
+ case 'md':
+ // montant desc
+ $sort_amount=" $image_asc Montant $image_sel_desc ";
+ $order=" order by jr_montant desc ";
+ break;
+ case 'ca':
+ // jr_comment asc
+ $sort_description=" $image_sel_asc Description $image_desc ";
+ $order=" order by jr_comment asc ";
+ break;
+ case 'cd':
+ // jr_comment desc
+ $sort_description=" $image_asc Description $image_sel_desc ";
+ $order=" order by jr_comment desc ";
+ break;
+ case 'ea':
+ // jr_comment asc
+ $sort_echeance=" $image_sel_asc Ech. $image_desc ";
+ $order=" order by jr_ech asc ";
+ break;
+ case 'ed':
+ // jr_comment desc
+ $sort_echeance=" $image_asc Ech. $image_sel_desc ";
+ $order=" order by jr_ech desc ";
+ break;
+
+ }
+ }
+ else
+ {
+ // date asc
+ $sort_date="$image_sel_asc Date $image_desc ";
+ $order=" order by jr_date_order asc ";
+ }
+ // set a filter for the FIN
+ $a_parm_code=$this->db->get_array("select p_value from parm_code where p_code in ('BANQUE','COMPTE_COURANT','CAISSE')");
+ $sql_fin="(";
+ $or="";
+ foreach ($a_parm_code as $code)
+ {
+ $sql_fin.="$or j_poste::text like '".$code['p_value']."%'";
+ $or=" or ";
+ }
+ $sql_fin.=")";
+
+ // 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="";
+
+ $r.=JS_LEDGER;
+
+ $Max=Database::num_row($Res);
+
+ if ($Max==0) return array(0,_("Aucun enregistrement trouvé"));
+
+ $r.='';
+
+
+ $r.="";
+ $r.="Internal ";
+ if ( $this->type=='')
+ {
+ $r.=th('Journal');
+ }
+ $r.=$sort_date;
+ $r.=$sort_echeance;
+ $r.=$sort_pj;
+ $r.=$sort_description;
+ $r.=$sort_amount;
+ // if $p_paid is not equal to 0 then we have a paid column
+ if ( $p_paid != 0 )
+ {
+ $r.=" "._('Payé')." ";
+ }
+ $r.=""._('Op. Concernée')." ";
+ $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']);
+ switch ($href)
+ {
+ // user_jrn.php
+ case 'compta.php':
+ $vue="S"; //Expert View
+ break;
+ case 'commercial.php':
+ $vue="S"; //Simple View
+ break;
+ case 'recherche.php':
+ $vue=(isset($_GET['expert']))?'E':'S';
+ break;
+ default:
+ echo_error('user_form_ach.php',__LINE__,'Erreur invalid request uri');
+ exit (-1);
+ }
+ //DEBUG
+
+ $r.=sprintf('%s ',
+ $row['jr_id'], $gDossier, $row['jr_internal']);
+ $r.=" ";
+ if ( $this->type=='') $r.=td($row['jrn_def_name']);
+ // date
+ $r.="";
+ $r.=$row['jr_date'];
+ $r.=" ";
+ // echeance
+ $r.="";
+ $r.=$row['jr_ech'];
+ $r.=" ";
+
+ // pj
+ $r.="";
+ $r.=$row['jr_pj_number'];
+ $r.=" ";
+
+ // comment
+ $r.="";
+ $tmp_jr_comment=h($row['jr_comment']);
+ $r.=$tmp_jr_comment;
+ $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->db->get_value("select qf_amount from quant_fin where jr_id=$1",
+ array($row['jr_id']));
+ $positive=($positive < 0)?1:0;
+ }
+ $r.="";
+
+ $tot=($positive != 0)?$tot-$row['jr_montant']:$tot+$row['jr_montant'];
+ //STAN $positive always == 0
+ $r.=( $positive != 0 )?" - ".sprintf("%8.2f",$row['jr_montant'])." ":sprintf("%8.2f",$row['jr_montant']);
+ $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+=$row['jr_montant'];
+ else
+ $amount_unpaid+=$row['jr_montant'];
+ }
+
+ // 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=$element");
+ $r.= " ".$operation->get_internal()." [ $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'] != "")
+ {
+ $image=' ';
+ $r.="".sprintf('%s ',
+ $row['jrn_def_id'],
+ $row['jr_grpt_id'],
+ $str_dossier,
+ $image)
+ ." ";
+ }
+ 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.=''.$tot." ";
+ $r.=" ";
+ if ( $p_paid != 0 )
+ {
+ $r.="";
+ $r.='Payé ';
+ $r.=''.$amount_paid." ";
+ $r.=" ";
+ $r.="";
+ $r.='Non payé ';
+ $r.=''.$amount_unpaid." ";
+ $r.=" ";
+ }
+ $r.="
";
+
+ return array ($count,$r);
}
- /* widget for amount */
- $f_amount_min=new INum('amount_min');
- $f_amount_min->value=(isset($_REQUEST['amount_min']))?$_REQUEST['amount_min']:0;
- $f_amount_max=new INum('amount_max');
- $f_amount_max->value=(isset($_REQUEST['amount_max']))?$_REQUEST['amount_max']:0;
+ /*!
+ * \brief get_detail gives the detail of row
+ * this array must contains at least the field
+ *
+ * montant
+ * grpt_id
+ *
+ * the following field will be added
+ *
+ * HTVA
+ * TVAC
+ * TVA array with
+ *
+ * field 0 idx
+ * array containing tva_id,tva_label and tva_amount
+ *
+ *
+ *
+ * \param p_array the structure is set in get_rowSimple, this array is
+ * modified,
+ * \param $trunc if the data must be truncated, usefull for pdf export
+ * \param p_jrn_type is the type of the ledger (ACH or VEN)
+ * \param $a_TVA TVA Array (default null)
+ * \param $a_ParmCode Array (default null)
+ * \return p_array
+ */
+ function get_detail(&$p_array,$p_jrn_type,$trunc=0,$a_TVA=null,$a_ParmCode=null)
+ {
+ if ( $a_TVA == null )
+ {
+ //Load TVA array
+ $a_TVA=$this->db->get_array('select tva_id,tva_label,tva_poste
+ from tva_rate where tva_rate != 0 order by tva_id');
+ }
+ if ( $a_ParmCode == null )
+ {
+ //Load Parm_code
+ $a_ParmCode=$this->db->get_array('select p_code,p_value from parm_code');
+ }
+ // init
+ $p_array['client']="";
+ $p_array['TVAC']=0;
+ $p_array['TVA']=array();
+ $p_array['AMOUNT_TVA']=0.0;
+ $p_array['dep_priv']=0;
+ $dep_priv=0.0;
+ //
+ // Retrieve data from jrnx
+ $sql="select j_id,j_poste,j_montant, j_debit,j_qcode from jrnx where ".
+ " j_grpt=".$p_array['grpt_id'];
+ $Res2=$this->db->exec_sql($sql);
+ $data_jrnx=Database::fetch_all($Res2);
+ $c=0;
- /* input quick code */
- $f_qcode=new ICard('qcode');
- $f_qcode->extra='filter';
- $f_qcode->set_attribute('typecard','all');
- $f_qcode->set_callback('filter_card');
- $f_txt_qcode=new IText('qcode');
- $f_txt_qcode->value=(isset($_REQUEST['qcode']))?$_REQUEST['qcode']:'';
+ // Parse data from jrnx and fill diff. field
+ foreach ( $data_jrnx as $code )
+ {
+ $idx_tva=0;
+ $poste=new Acc_Account_Ledger($this->db,$code['j_poste']);
- /* 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);
+ // if card retrieve name if the account is not a VAT account
+ if ( strlen(trim($code['j_qcode'] )) != 0 && $poste->isTva() == 0 )
+ {
+ $fiche=new Fiche($this->db);
+ $fiche->get_by_qcode(trim($code['j_qcode']),false);
+ $fiche_def_id=$fiche->get_fiche_def_ref_id();
+ // Customer or supplier
+ if ( $fiche_def_id == FICHE_TYPE_CLIENT ||
+ $fiche_def_id == FICHE_TYPE_FOURNISSEUR )
+ {
+ $p_array['TVAC']=$code['j_montant'];
- $f_paid=new ICheckbox('unpaid');
- $f_paid->selected=(isset($_REQUEST['unpaid']))?true:false;
+ $p_array['client']=($trunc==0)?$fiche->getName():substr($fiche->getName(),0,20);
+ $p_array['reversed']=false;
+ if ( $fiche_def_id == FICHE_TYPE_CLIENT && $code['j_debit']=='f')
+ {
+ $p_array['reversed']=true;
+ $p_array['TVAC']*=-1;
- $r.=dossier::hidden();
- $r.=HtmlInput::hidden('ledger_type',$this->type);
- ob_start();
- require_once('template/ledger_search.php');
- $r.=ob_get_contents();
- ob_clean();
- return $r;
+ }
+ if ( $fiche_def_id == FICHE_TYPE_FOURNISSEUR && $code['j_debit']=='t')
+ {
+ $p_array['reversed']=true;
+ $p_array['TVAC']*=-1;
+ }
- }
- /*!\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.YYYY') as jr_ech,
- to_char(jr_date,'DD.MM.YYYY') as 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
- from
- jrn
- join jrn_def on jrn_def_id=jr_def_id
- join parm_periode on p_id=jr_tech_per";
- if ( $p_array != null )
- extract($p_array);
- $r_jrn=(isset($r_jrn))?$r_jrn:-1;
+ }
+ else
+ {
+ // if we use the ledger ven / ach for others card than supplier and customer
+ if ( $fiche_def_id != FICHE_TYPE_VENTE &&
+ $fiche_def_id != FICHE_TYPE_ACH_MAR &&
+ $fiche_def_id != FICHE_TYPE_ACH_SER )
+ {
+ $p_array['TVAC']=$code['j_montant'];
- /* 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;
+ $p_array['client']= ($trunc==0)?$fiche->getName():substr($fiche->getName(),0,20);
+ $p_array['reversed']=false;
+ if ($p_jrn_type == 'ACH' && $code['j_debit']=='t')
+ {
+ $p_array['reversed']=true;
+ $p_array['TVAC']*=-1;
- if ( ! isset ($date_start)) {
- $user=new User($this->db);
- $period=$user->get_periode();
- $per=new Periode($this->db);
- list($date_start,$date_end)=$per->get_date_limit();
- }
- $desc='';
- $qcode=(isset($qcode))?$qcode:"";
- $accounting=(isset($accounting))?$accounting:"";
+ }
+ if ($p_jrn_type == 'VEN' && $code['j_debit']=='f')
+ {
+ $p_array['reversed']=true;
+ $p_array['TVAC']*=-1;
+ }
+
+
+
+
+ }
+ }
+ }
+ // if TVA, load amount, tva id and rate in array
+ foreach ( $a_TVA as $line_tva)
+ {
+ list($tva_deb,$tva_cred)=explode(',',$line_tva['tva_poste']);
+ if ( $code['j_poste'] == $tva_deb ||
+ $code['j_poste'] == $tva_cred )
+ {
+
+ // For the reversed operation
+ if ( $p_jrn_type == 'ACH' && $code['j_debit'] == 'f')
+ {
+ $code['j_montant']=-1*$code['j_montant'];
+ }
+ if ( $p_jrn_type == 'VEN' && $code['j_debit'] == 't')
+ {
+ $code['j_montant']=-1*$code['j_montant'];
+ }
+
+ $p_array['AMOUNT_TVA']+=$code['j_montant'];
+
+ $p_array['TVA'][$c]=array($idx_tva,array($line_tva['tva_id'],$line_tva['tva_label'],$code['j_montant']));
+ $c++;
+
+ $idx_tva++;
+ }
+ }
+
+ // isDNA
+ // If operation is reversed then amount are negatif
+ /* if ND */
+ if ( $p_array['jrn_def_type'] == 'ACH')
+ {
+ $purchase=new Gestion_Purchase($this->db);
+ $purchase->search_by_jid($code['j_id']);
+ $purchase->load();
+ $dep_priv+=$purchase->qp_dep_priv;
+ $p_array['dep_priv']=$dep_priv;
+ }
+
+ }
+ $p_array['TVAC']=sprintf('% 10.2f',$p_array['TVAC']-$dep_priv);
+ $p_array['HTVA']=sprintf('% 10.2f',$p_array['TVAC']-$p_array['AMOUNT_TVA']);
+ $r="";
+ $a_tva_amount=array();
+ // inline TVA (used for the PDF)
+ foreach ($p_array['TVA'] as $linetva)
+ {
+ foreach ($a_TVA as $tva)
+ {
+ if ( $tva['tva_id'] == $linetva[1][0] )
+ {
+ $a=$tva['tva_id'];
+ $a_tva_amount[$a]=$linetva[1][2];
+ }
+ }
+ }
+ foreach ($a_TVA as $line_tva)
+ {
+ $a=$line_tva['tva_id'];
+ if ( isset($a_tva_amount[$a]))
+ {
+ $tmp=sprintf("% 10.2f",$a_tva_amount[$a]);
+ $r.="$tmp";
+ }
+ else
+ $r.=sprintf("% 10.2f",0);
+ }
+ $p_array['TVA_INLINE']=$r;
+
+ return $p_array;
+ } // retrieve data from jrnx
+ /*!
+ * \brief Get the properties of a journal
+ *
+ * \return an array containing properties
+ *
+ */
+ function get_propertie()
+ {
+ if ( $this->id == 0 ) return;
+
+ $Res=$this->db->exec_sql("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_cred,jrn_def_pj_pref
+ from jrn_Def
+ where jrn_def_id=$1",array($this->id));
+ $Count=Database::num_row($Res);
+ if ( $Count == 0 )
+ {
+ echo '
'._('Parametres journaux non trouves').' ';
+ return null;
+ }
+ return Database::fetch_array($Res,0);
+ }
+
+ /*! \function GetDefLine
+ * \brief Get the number of lines of a journal
+ * \param $p_cred deb or cred
+ *
+ * \return an integer
+ */
+ function GetDefLine()
+ {
+ $sql_cred='jrn_deb_max_line';
+ $sql="select jrn_deb_max_line as value from jrn_def where jrn_def_id=$1";
+ $r=$this->db->exec_sql($sql,array($this->id));
+ $Res=Database::fetch_all($r);
+ if ( sizeof($Res) == 0 ) return 1;
+ return $Res[0]['value'];
+ }
+ /*!\brief get the saldo of a ledger for a specific period
+ * \param $p_from start period
+ * \param $p_to end period
+ */
+ function get_solde($p_from,$p_to)
+ {
+ $ledger="";
+ if ( $this->id != 0 )
+ {
+ $ledger=" and j_jrn_def = ".$this->id;
+ }
+
+ $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','j_tech_per');
+ $sql='select j_montant as montant,j_debit as deb from jrnx where '
+ .$periode.$ledger;
+
+ $ret=$this->db->exec_sql($sql);
+ $array=Database::fetch_all($ret);
+ $deb=0.0;
+ $cred=0.0;
+ foreach ($array as $line)
+ {
+
+ if ( $line['deb']=='t' )
+ $deb+=$line['montant'];
+ else
+ $cred+=$line['montant'];
+ }
+ $response=array($deb,$cred);
+ return $response;
+ }
+ /*!
+ * \brief Show a select list of the ledgers you can access in
+ * writing, reading or simply accessing.
+ * \param $p_type = ALL or the type of the ledger (ACH,VEN,FIN,ODS)
+ * \param $p_access =3 for READ and WRITE, 2 for write and 1 for readonly
+ * \return object HtmlInput select
+ */
+ function select_ledger($p_type="ALL",$p_access=3)
+ {
+ $user=new User($this->db);
+ $array=$user->get_ledger($p_type,$p_access);
+
+ if ( $array == null ) return null;
+ $idx=0;
+ $ret=array();
+
+ foreach ( $array as $value)
+ {
+ $ret[$idx]['value']=$value['jrn_def_id'];
+ $ret[$idx]['label']=h($value['jrn_def_name']);
+ $idx++;
+ }
+
+ $select=new ISelect();
+ $select->name='p_jrn';
+ $select->value=$ret;
+ $select->selected=$this->id;
+ return $select;
+ }
+ /*!
+ * \brief retrieve the jrn_def_fiche and return them into a array
+ * index deb, cred
+ * \param
+ * \param
+ * \param
+ *
+ *
+ * \return return an array ('deb'=> ,'cred'=>)
+ */
+ function get_fiche_def()
+ {
+ $sql="select jrn_def_fiche_deb as deb,jrn_def_fiche_cred as cred ".
+ " from jrn_def where ".
+ " jrn_def_id = $1 ";
+
+ $r=$this->db->exec_sql($sql,array($this->id));
+
+ $res=Database::fetch_all($r);
+ if ( empty($res) ) return null;
+
+ return $res[0];
+ }
+ /*!
+ * \brief retrieve the jrn_def_class_deb and return it
+ *
+ *
+ * \return return an string
+ */
+ function get_class_def()
+ {
+ $sql="select jrn_def_class_deb ".
+ " from jrn_def where ".
+ " jrn_def_id = $1";
+
+ $r=$this->db->exec_sql($sql,array($this->id));
+
+ $res=Database::fetch_all($r);
+
+ if ( empty($res) ) return null;
+
+ return $res[0];
+ }
+
+ /*!
+ * \brief show the result of the array to confirm
+ * before inserting
+ * \param $p_array array from the form
+ * \return string
+ */
+ function show_summary($p_array)
+ {
+ $this->id=$p_array['p_jrn'];
+ if ( empty($p_array)) return 'Aucun résultat';
+ $anc=null;
+ extract($p_array);
+ $lPeriode=new Periode($this->db);
+ if ($this->check_periode() == true)
+ {
+ $lPeriode->p_id=$period;
+ }
+ else
+ {
+ $lPeriode->find_periode($e_date);
+ }
+ $owner=new own($this->db);
+
+ $ret="";
+ $ret.="";
+ $ret.=""._('Date')." : $e_date ";
+ /* display periode */
+ $date_limit=$lPeriode->get_date_limit();
+ $ret.=' '._('Période Comptable').' '.$date_limit['p_start'].'-'.$date_limit['p_end'].' ';
+ $ret.=""._('Libellé')." ".h($desc)." ";
+ $ret.=""._('PJ Num')." ".h($e_pj)." ";
+ $ret.='
';
+ $ret.="";
+ $ret.="";
+ $ret.=""._('Quick Code ou');
+ $ret.=_("Poste")." ";
+ $ret.=" "._("Montant")." ";
+ $ret.=""._("Débit")." ";
+ /* if we use the AC */
+ if ($owner->MY_ANALYTIC!='nu')
+ {
+ $anc=new Anc_Plan($this->db);
+ $a_anc=$anc->get_list();
+ $x=count($a_anc);
+ /* set the width of the col */
+ $ret.=''._('Compt. Analytique').' ';
+
+ /* add hidden variables pa[] to hold the value of pa_id */
+ $ret.=Anc_Plan::hidden($a_anc);
+ }
+ $ret.=" ";
+
+ $ret.=HtmlInput::hidden('e_date',$e_date);
+ $ret.=HtmlInput::hidden('desc',$desc);
+ $ret.=HtmlInput::hidden('period',$lPeriode->p_id);
+ $ret.=HtmlInput::hidden('e_pj',$e_pj);
+ $ret.=HtmlInput::hidden('e_pj_suggest',$e_pj_suggest);
+ $mt=microtime(true);
+ $ret.=HtmlInput::hidden('mt',$mt);
+ // For predefined operation
+ $ret.=HtmlInput::hidden('e_comm',$desc);
+ $ret.=HtmlInput::hidden('jrn_type',$this->get_type());
+ $ret.=HtmlInput::hidden('p_jrn',$this->id);
+ $ret.=HtmlInput::hidden('nb_item',$nb_item);
+ if ( $this->with_concerned==true)
+ {
+ $ret.=HtmlInput::hidden('jrn_concerned',$jrn_concerned);
+ }
+ $ret.=dossier::hidden();
+ $count=0;
+ for ($i=0;$i<$nb_item;$i++)
+ {
+ $ret.="";
+ if ( trim(${'qc_'.$i})!="")
+ {
+ $oqc=new Fiche($this->db);
+ $oqc->get_by_qcode(${'qc_'.$i},false);
+ $strPoste=$oqc->strAttribut(ATTR_DEF_ACCOUNT);
+ $ret.="".
+ ${'qc_'.$i}.' - '.
+ $oqc->strAttribut(ATTR_DEF_NAME).HtmlInput::hidden('qc_'.$i,${'qc_'.$i}).
+ ' ';
+ }
+
+ if ( trim(${'qc_'.$i})=="" && trim(${'poste'.$i}) != "")
+ {
+ $oposte=new Acc_Account_Ledger($this->db,${'poste'.$i});
+ $strPoste=$oposte->id;
+ $ret.="".h(${"poste".$i}." - ".
+ $oposte->get_name()).HtmlInput::hidden('poste'.$i,${'poste'.$i}).
+ ' ';
+ }
+
+ if ( trim(${'qc_'.$i})=="" && trim(${'poste'.$i}) == "")
+ continue;
+ $ret.="".h(${"ld".$i}).HtmlInput::hidden('ld'.$i,${'ld'.$i})." ";
+ $ret.="".${"amount".$i}.HtmlInput::hidden('amount'.$i,${'amount'.$i})." ";
+ $ret.="";
+ $ret.=(isset(${"ck$i"}))?"D":"C";
+ $ret.=(isset(${"ck$i"}))?HtmlInput::hidden('ck'.$i,${'ck'.$i}):"";
+ $ret.=" ";
+ // CA
+
+ if ( $owner->MY_ANALYTIC!='nu') // use of AA
+ {
+ if ( myereg("^[6,7]+",$strPoste))
+ {
+ // show form
+ $op=new Anc_Operation($this->db);
+ $null=($owner->MY_ANALYTIC=='op')?1:0;
+ $p_array['pa_id']=$a_anc;
+ /* op is the operation it contains either a sequence or a jrnx.j_id */
+ $ret.=HtmlInput::hidden('op[]=',$i);
+
+ $ret.='';
+ $ret.=$op->display_form_plan($p_array,$null,1,$count,round(${'amount'.$i},2));
+ $ret.=' ';
+ $count++;
+ }
+
+
+ }
+
+
+
+ $ret.=" ";
+ }
+ $ret.="
";
+ $ret.=' ';
+ return $ret;
+ }
+
+ /*!
+ * \brief Show the form to encode your operation
+ * \param $p_array if you correct or use a predef operation (default = null)
+ * \param $p_readonly 1 for readonly 0 for writable (default 0)
+ *
+ * \return a string containing the form
+ */
+ function show_form($p_array=null,$p_readonly=0)
+ {
+ $user = new User($this->db);
+ $owner=new Own($this->db);
+
+ if ( $p_readonly == 1 )
+ return $this->show_summary($p_array);
+
+ if ( $p_array != null )
+ extract($p_array);
+
+ $ret="";
+ /* Add button */
+ $f_add_button=new IButton('add_card');
+ $f_add_button->label=_('Créer une nouvelle fiche');
+ $f_add_button->set_attribute('ipopup','ipop_newcard');
+ $f_add_button->set_attribute('jrn',$this->id);
+ $f_add_button->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
+ $ret.=$f_add_button->input();
+
+ // Load the javascript
+ //
+ $ret.="";
+ $ret.= '';
+ $wDate=new IDate('e_date');
+ $wDate->readonly=$p_readonly;
+ $e_date=(isset($e_date)&&trim($e_date)!='')?$e_date:'';
+ $wDate->value=$e_date;
+
+ $ret.=_("Date").' : '.$wDate->input();
+ $ret.= ' ';
+ /* insert periode if needed */
+ // Periode
+ //--
+ if ($this->check_periode() == true)
+ {
+ $l_user_per=$user->get_periode();
+ $def=(isset($periode))?$periode:$l_user_per;
+
+ $period=new IPeriod("period");
+ $period->user=$user;
+ $period->cn=$this->db;
+ $period->value=$def;
+ $period->type=OPEN;
+ try
+ {
+ $l_form_per=$period->input();
+ }
+ catch (Exception $e)
+ {
+ if ($e->getCode() == 1 )
+ {
+ echo _("Aucune période ouverte");
+ exit();
+ }
+ }
+ $label=HtmlInput::infobulle(3);
+ $f_periode=_("Période comptable")." $label ".$l_form_per;
+ $ret.=td($f_periode);
+ }
+ $wPJ=new IText('e_pj');
+ $wPJ->readonly=false;
+ $wPJ->size=10;
+
+ /* suggest PJ ? */
+ $default_pj='';
+ $owner=new Own($this->db);
+ if ( $owner->MY_PJ_SUGGEST=='Y')
+ {
+ $default_pj=$this->guess_pj();
+ }
+ $wPJ->value=(isset($e_pj))?$e_pj:$default_pj;
+
+ $ret.=' '._('Pièce').' : '.$wPJ->input();
+ $ret.=HtmlInput::hidden('e_pj_suggest',$default_pj);
+ $ret.= ' ';
+ $ret.= ' ';
+
+ $ret.= ''._('Libellé');
+ $wDescription=new IText('desc');
+ $wDescription->readonly=$p_readonly;
+ $wDescription->size=100;
+ $wDescription->value=(isset($desc))?$desc:'';
+ $ret.=' ';
+ $ret.=$wDescription->input();
+ $ret.= ' ';
+ $ret.=' ';
+
+ $ret.= '
';
+ $nb_row=(isset($nb_item) )?$nb_item:$this->nb;
+
+ $ret.=HtmlInput::hidden('nb_item',$nb_row);
+ $ret.=dossier::hidden();
+
+ $ret.=HtmlInput::hidden('p_jrn',$this->id);
+ $ret.=dossier::hidden();
+
+ $ret.=HtmlInput::hidden('jrn_type',$this->get_type());
+ $info= HtmlInput::infobulle(0);
+ $info_poste=HtmlInput::infobulle(9);
+ $ret.='';
+ $ret.=''.
+ 'Quickcode'.$info.' '.
+ ''._('Poste').$info_poste.' '.
+ ''._('Libellé').' '.
+ ''._('Montant').' '.
+ ''._('Débit').' '.
+ ' ';
+
+
+ for ($i = 0 ;$i<$nb_row;$i++)
+ {
+ // Quick Code
+ $quick_code=new ICard('qc_'.$i);
+ $quick_code->set_dblclick("fill_ipopcard(this);");
+ $quick_code->set_attribute('ipopup','ipopcard');
+
+ // name of the field to update with the name of the card
+ $quick_code->set_attribute('label',"ld".$i);
+ $quick_code->set_attribute('jrn',$this->id);
+
+ // name of the field to update with the name of the card
+ $quick_code->set_attribute('typecard','filter');
+ $quick_code->extra='filter';
+ // Add the callback function to filter the card on the jrn
+ $quick_code->set_callback('filter_card');
+ $quick_code->set_function('fill_data');
+ $quick_code->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+ $quick_code->name);
+
+ $quick_code->jrn=$this->id;
+ $quick_code->value=(isset(${'qc_'.$i}))?${'qc_'.$i}:""
+ ;
+ $quick_code->readonly=$p_readonly;
+
+ $label='';
+ if ( $quick_code->value != '' )
+ {
+ $Fiche=new Fiche($this->db);
+ $Fiche->get_by_qcode($quick_code->value);
+ $label=$Fiche->strAttribut(ATTR_DEF_NAME);
+ }
+
+
+ // Account
+ $poste=new IPoste();
+ $poste->name='poste'.$i;
+ $poste->set_attribute('jrn',$this->id);
+ $poste->set_attribute('ipopup','ipop_account');
+ $poste->set_attribute('label','ld'.$i);
+ $poste->set_attribute('account','poste'.$i);
+
+ $poste->value=(isset(${'poste'.$i}))?${"poste".$i}:''
+ ;
+ $poste->readonly=$p_readonly;
+
+ if ( $poste->value != '' )
+ {
+ $Poste=new Acc_Account($this->db);
+ $Poste->set_parameter('value',$poste->value);
+ $label=$Poste->get_lib();
+ }
+
+ // Description of the line
+ $line_desc=new IText();
+ $line_desc->name='ld'.$i;
+ $line_desc->size=30;
+ $line_desc->value=(isset(${"ld".$i}))?${"ld".$i}:
+ $label;
+
+ // Amount
+ $amount=new INum();
+ $amount->size=10;
+ $amount->name='amount'.$i;
+ $amount->value=(isset(${'amount'.$i}))?${"amount".$i}:''
+ ;
+ $amount->readonly=$p_readonly;
+ $amount->javascript=' onChange="format_number(this);checkTotalDirect()"';
+ // D/C
+ $deb=new ICheckBox();
+ $deb->name='ck'.$i;
+ $deb->selected=(isset(${'ck'.$i}))?true:false;
+ $deb->readonly=$p_readonly;
+ $deb->javascript=' onChange="checkTotalDirect()"';
+
+ $ret.='';
+ $ret.=''.$quick_code->search().$quick_code->input().' ';
+ $ret.=''.$poste->input().
+ ''.
+ ' ';
+ $ret.=''.$line_desc->input().' ';
+ $ret.=''.$amount->input().' ';
+ $ret.=''.$deb->input().' ';
+ $ret.=' ';
+ // If readonly == 1 then show CA
+ }
+ $ret.='
';
+ if ( isset ($this->with_concerned) && $this->with_concerned==true)
+ {
+ $oRapt=new Acc_Reconciliation($this->db);
+ $w=$oRapt->widget();
+ $w->name='jrn_concerned';
+ $w->value=(isset($jrn_concerned))?$jrn_concerned:"";
+ $ret.="Réconciliation/rapprochements : ".$w->input();
+ }
+ return $ret;
+ }
+
+ /*!\brief
+ * check if the current ledger is closed
+ *\return 1 for yes, otherwise 0
+ *\see Periode::is_closed
+ */
+ function is_closed($p_periode)
+ {
+ $per=new Periode($this->db);
+ $per->set_jrn($this->id);
+ $per->set_periode($p_periode);
+ $ret=$per->is_closed();
+ return $ret;
+
+ }
+ /*!
+ * \brief verify that the operation can be saved
+ * \param $p_array array of data same layout that the $_POST from show_form
+ *
+ *
+ * \throw the getcode value is 1 incorrect balance, 2 date
+ * invalid, 3 invalid amount, 4 the card is not in the range of
+ * permitted card, 5 not in the user's period, 6 closed period
+ *
+ */
+ function verify($p_array)
+ {
+ extract ($p_array);
+ $user=new User($this->db);
+ $tot_cred=0;
+ $tot_deb=0;
+
+ /* check if we can write into this ledger */
+ $user=new User($this->db);
+ if ( $user->check_jrn($p_jrn) != 'W' )
+ throw new Exception (_('Accès interdit'),20);
+
+ /* check for a double reload */
+ if ( isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1',array($mt)) != 0 )
+ throw new Exception ('Double Encodage',5);
+
+ // Check the periode and the date
+ if ( isDate($e_date) == null )
+ {
+ throw new Exception('Date invalide', 2);
+ }
+ $periode=new Periode($this->db);
+ /* find the periode if we have enabled the check_periode*/
+ if ($this->check_periode()==false)
+ {
+ $periode->find_periode($e_date);
+ }
+ else
+ {
+ $periode->p_id=$period;
+ list ($min,$max)=$periode->get_date_limit();
+ if ( cmpDate($e_date,$min) < 0 ||
+ cmpDate($e_date,$max) > 0)
+ throw new Exception(_('Date et periode ne correspondent pas'),6);
+
+ }
+
+
+
+ // Periode ferme
+ if ( $this->is_closed($periode->p_id)==1 )
+ {
+ throw new Exception('Periode fermee',6);
+ }
+ /* check if we are using the strict mode */
+ if( $this->check_strict() == true)
+ {
+ /* if we use the strict mode, we get the date of the last
+ operation */
+ $last_date=$this->get_last_date();
+ if ( $last_date !=null && cmpDate($e_date,$last_date) < 0 )
+ throw new Exception(_('Vous utilisez le mode strict la dernière operation est la date du ')
+ .$last_date.' '._('vous ne pouvez pas encoder à une date antérieure'),15);
+
+ }
+
+ for ($i=0;$i<$nb_item;$i++)
+ {
+ $err=0;
+
+ // Check the balance
+ if ( ! isset (${'amount'.$i}))
+ continue;
+
+ $amount=round(${'amount'.$i},2);
+ $tot_deb+=(isset(${'ck'.$i}))?$amount:0;
+ $tot_cred+=(! isset(${'ck'.$i}))?$amount:0;
+
+ // Check if the card is permitted
+ if ( isset (${'qc_'.$i}) && trim(${'qc_'.$i}) !="")
+ {
+ $f=new Fiche($this->db);
+ $f->quick_code=${'qc_'.$i};
+ if ( $f->belong_ledger($p_jrn) < 0 )
+ throw new Exception("La fiche quick_code = ".
+ $f->quick_code." n\'est pas dans ce journal",4);
+ if ( strlen(trim(${'qc_'.$i}))!=0 && isNumber(${'amount'.$i} ) == 0 )
+ throw new Exception('Montant invalide',3);
+
+ }
+
+ // Check if the account is permitted
+ if ( isset (${'poste'.$i}) && strlen (trim(${'poste'.$i})) != 0 )
+ {
+ $p=new Acc_Account_Ledger($this->db,${'poste'.$i});
+ if ( $p->belong_ledger ($p_jrn) < 0 )
+ throw new Exception(_("Le poste")." ".$p->id." "._("n'est pas dans ce journal"),5);
+ if ( strlen(trim(${'poste'.$i}))!=0 && isNumber(${'amount'.$i} ) == 0 )
+ throw new Exception(_('Poste invalide ['.${'poste'.$i}.']'),3);
+ if ( $p->do_exist() == 0 )
+ throw new Exception(_('Poste Inexistant ['.${'poste'.$i}.']'),4);
+ }
+
+
+ }
+ $tot_deb=round($tot_deb,4);
+ $tot_cred=round($tot_cred,4);
+ if ( $tot_deb != $tot_cred )
+ {
+ throw new Exception(_("Balance incorrecte ")." debit = $tot_deb credit=$tot_cred ",1);
+ }
+
+ }
+ /*!
+ * \brief compute the internal code of the saved operation and set the $this->jr_internal to
+ * the computed value
+ *
+ * \param $p_grpt id in jr_grpt_
+ *
+ * \return string internal_code
+ * -
+ *
+ */
+ function compute_internal_code($p_grpt)
+ {
+ if ( $this->id==0) return;
+ $num = $this->db->get_next_seq('s_internal');
+ $atype=$this->get_propertie();
+ $type=$atype['jrn_def_code'];
+ $internal_code=sprintf("%s-%s",$type,$num);
+ $this->jr_internal=$internal_code;
+ return $internal_code;
+ }
+
+ /*!
+ * \brief save the operation into the jrnx,jrn, ,
+ * CA and pre_def
+ * \param $p_array
+ *
+ * \return array with [0] = false if failed otherwise true, [1] error
+ * code
+ */
+ function save ($p_array)
+ {
+ extract ($p_array);
+ try
+ {
+ $this->verify($p_array);
+
+ $this->db->start() ;
+
+ $seq=$this->db->get_next_seq('s_grpt');
+ $internal=$this->compute_internal_code($seq);
+
+ $group=$this->db->get_next_seq("s_oa_group");
+ $owner=new own($this->db);
+ $tot_amount=0;
+ $tot_deb=0;
+ $tot_cred=0;
+ $oPeriode=new Periode($this->db);
+ $check_periode=$this->check_periode();
+ if ( $check_periode == false)
+ {
+ $oPeriode->find_periode($e_date);
+ }
+ else
+ {
+ $oPeriode->id=$period;
+ }
+
+ $count=0;
+ for ($i=0;$i<$nb_item;$i++)
+ {
+ if ( ! isset (${'qc_'.$i}) && ! isset(${'poste'.$i}))
+ continue;
+ $acc_op=new Acc_Operation($this->db);
+ $quick_code="";
+ // First we save the jrnx
+ if ( isset(${'qc_'.$i}))
+ {
+ $qc=new Fiche($this->db);
+ $qc->get_by_qcode(${'qc_'.$i},false);
+ $sposte=$qc->strAttribut(ATTR_DEF_ACCOUNT);
+ /* if there are 2 accounts take following the deb or cred */
+ if (strpos($sposte,',') != 0 )
+ {
+ $array=explode(",",$sposte);
+ $poste=(isset(${'ck'.$i}))?$array[0]:$array[1];
+ }
+ else
+ {
+ $poste=$sposte;
+ }
+ $quick_code=${'qc_'.$i};
+ }
+ else
+ {
+ $poste=${'poste'.$i};
+ }
+ $acc_op->date=$e_date;
+ // compute the periode is do not check it
+ if ($check_periode == false ) $acc_op->periode=$oPeriode->p_id;
+ $acc_op->desc=$desc;
+ if ( strlen(trim(${'ld'.$i})) != 0 )
+ $acc_op->desc=${'ld'.$i};
+ $acc_op->amount=round(${'amount'.$i},2);
+ $acc_op->grpt=$seq;
+ $acc_op->poste=$poste;
+ $acc_op->jrn=$this->id;
+ $acc_op->type=(isset (${'ck'.$i}))?'d':'c';
+ $acc_op->qcode=$quick_code;
+ $j_id=$acc_op->insert_jrnx();
+ $tot_amount+=round($acc_op->amount,2);
+ $tot_deb+=($acc_op->type=='d')?$acc_op->amount:0;
+ $tot_cred+=($acc_op->type=='c')?$acc_op->amount:0;
+ if ( $owner->MY_ANALYTIC != "nu" )
+ {
+ if ( myereg("^[6,7]+",$poste))
+ {
+
+ // for each item, insert into operation_analytique */
+ $op=new Anc_Operation($this->db);
+ $op->oa_group=$group;
+ $op->j_id=$j_id;
+ $op->oa_date=$e_date;
+ $op->oa_debit=($acc_op->type=='d' )?'t':'f';
+ $op->oa_description=$desc;
+ $op->save_form_plan($p_array,$count,$j_id);
+ $count++;
+ }
+ }
+ }// loop for each item
+ $acc_end=new Acc_Operation($this->db);
+ $acc_end->amount=$tot_deb;
+ if ($check_periode == false ) $acc_end->periode=$oPeriode->p_id;
+ $acc_end->date=$e_date;
+ $acc_end->desc=$desc;
+ $acc_end->grpt=$seq;
+ $acc_end->jrn=$this->id;
+ $acc_end->mt=$mt;
+ $jr_id= $acc_end->insert_jrn();
+ $this->jr_id=$jr_id;
+ if ($jr_id == false )
+ throw new Exception('Balance incorrecte');
+ $acc_end->pj=$e_pj;
+
+ /* if e_suggest != e_pj then do not increment sequence */
+ if ( strcmp($e_pj,$e_pj_suggest) == 0 && strlen(trim($e_pj)) !=0)
+ {
+ $this->inc_seq_pj();
+ }
+
+ $this->pj=$acc_end->set_pj();
+
+ $this->db->exec_sql("update jrn set jr_internal='".$internal."' where ".
+ " jr_grpt_id = ".$seq);
+ $this->internal=$internal;
+ // Save now the predef op
+ //------------------------
+ if ( isset($save_opd))
+ {
+ $opd=new Pre_Op_Advanced($this->db);
+ $opd->name=(trim($desc)=='')?$internal:$desc;
+ $opd->get_post();
+ $opd->save();
+ }
+
+ if ( isset($this->with_concerned) && $this->with_concerned==true)
+ {
+ $orap=new acc_reconciliation($this->db);
+ $orap->jr_id=$jr_id;
+
+ $orap->insert($jrn_concerned);
+ }
+
+ }
+
+ catch (Exception $a)
+ {
+ throw $a;
+ }
+ catch (Exception $e)
+ {
+ $this->db->rollback();
+ echo 'OPERATION ANNULEE ';
+ echo ' ';
+ echo __FILE__.__LINE__.$e->getMessage();
+ exit();
+ }
+ $this->db->commit();
+ return true;
+ }
+
+ /*!
+ * \brief get all the data from request and build the object
+ */
+ function get_request()
+ {
+ $this->id=$_REQUEST['p_jrn'];
}
- /* 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='';
+ /*!
+ * \brief retrieve the next number for this type of ledger
+ * \param p_cn connx
+ * \param p_type ledger type
+ *
+ * \return the number
+ *
+ *
+ */
+ static function next_number($p_cn,$p_type)
+ {
- $and='';
- $user=new User($this->db);
-
- if ( $r_jrn == -1 ) {
- /* Specific action allow to see all the ledgers in once */
- if ( $p_action == 'gl') $p_action='ALL';
- /* actions from commercial.php */
- if ( $p_action == 'client') $p_action='ALL';
- if ( $p_action == 'supplier') $p_action='ALL';
- if ( $p_action == 'adm') $p_action='ALL';
-
- /* from compta.php the p_action is quick_writing instead of ODS */
- if ( $p_action == 'quick_writing') $p_action='ODS';
-
-
- $fil_ledger=$user->get_ledger_sql($p_action,3);
- $and=' and ';
- } else {
- if ( $p_action == 'gl') $p_action='ALL';
- if ( $p_action == 'quick_writing') $p_action='ODS';
-
- $aLedger=$user->get_ledger($p_action,3);
- $fil_ledger='';$sp='';
-
- for ($i=0;$i < count($aLedger) ;$i ++) {
- if ( isset($r_jrn[$i])) {$fil_ledger.=$sp.$aLedger[$i]['jrn_def_id'];$sp=',';}
- }
- $fil_ledger=' jrn_def_id in ('.$fil_ledger.')';
- $and=' and ';
-
- /* no ledger selected */
- if ( $sp == '' ) {
- $fil_ledger='';$and='';
- }
+ $Ret=$p_cn->count_sql("select * from jrn_def where jrn_def_type='".$p_type."'");
+ return $Ret+1;
}
-
- /* format the number */
- $amount_min=toNumber($amount_min);
- $amount_max=toNumber($amount_max);
- if ( $amount_min > 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. 'jr_grpt_id in ( select distinct j_grpt from jrnx where j_montant = '.$amount_min.')';
- $and=" and ";
- }
- // date
- if ( isDate($date_start) != null )
- {
- $fil_date=$and." jr_date >= to_date('".$date_start."','DD.MM.YYYY')";
- $and=" and ";
- }
- if ( isDate($date_end) != null ) {
- $fil_date.=$and." jr_date <= to_date('".$date_end."','DD.MM.YYYY')";
- $and=" and ";
- }
- // comment
- $desc=FormatString($desc);
- if ( $desc != null )
- {
- $fil_desc=$and." ( upper(jr_comment) like upper('%".$desc."%') or upper(jr_pj_number) like upper('%".$desc."%') ".
- " or upper(jr_internal) like upper('%".$desc."%') )";
- $and=" and ";
- }
- // Poste
- if ( $accounting != null ) {
- $fil_account=$and." jr_grpt_id in (select j_grpt
- from jrnx where j_poste::text like '$accounting%' ) ";
- $and=" and ";
- }
- // Quick Code
- if ( $qcode != null )
- {
- $fil_qcode=$and." jr_grpt_id in ( select j_grpt from
- jrnx where trim(j_qcode) = upper(trim('$qcode')))";
- $and=" and ";
- }
-
- // Only the unpaid
- if ( isset($unpaid) ) {
- $fil_paid=$and.SQL_LIST_UNPAID_INVOICE;
- $and =" and ";
+ /*!\brief get the first ledger
+ *\param the type
+ *\return the j_id
+ */
+ public function get_first($p_type)
+ {
+ $user=new User($this->db);
+ $all=$user->get_ledger($p_type);
+ return $all[0];
}
- $User=new User(new Database());
- $User->Check();
- $User->check_dossier(dossier::id());
- if ( $User->admin == 0 && $User->is_local_admin()==0 )
- {
- $fil_sec=$and." jr_def_id in ( select uj_jrn_id ".
- " from user_sec_jrn where ".
- " uj_login='".$_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;
- $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;
+ /*!\brief Update the paiment in the list of operation
+ *\param $p_array is normally $_GET
+ */
+ function update_paid($p_array)
+ {
+ // reset all the paid flag because the checkbox is post only
+ // when checked
+ foreach ($p_array as $name=>$paid)
+ {
+ list($ad) = sscanf($name,"set_jr_id%d");
+ if ( $ad == null ) continue;
+ $sql="update jrn set jr_rapt='' where jr_id=$ad";
+ $Res=$this->db->exec_sql($sql);
- if ( $type=="" || $this->id==0) $type='ALL';
- if ( isset($_GET['amount_min']) ) { $display='block';} else {$display='none';}
- $r.='';
- $r.='
';
- $r.=$this->search_form($type);
- $r.=HtmlInput::submit('search',_('Rechercher'));
- $r.=HtmlInput::hidden('p_action',$_REQUEST['p_action']);
+ }
+ // set a paid flag for the checked box
+ foreach ($p_array as $name=>$paid)
+ {
+ list ($id) = sscanf ($name,"rd_paid%d");
+ if ( $id == null ) continue;
- /* when called from commercial.php some hidden values are needed */
- if (isset($_REQUEST['sa'])) $r.= HtmlInput::hidden("sa",$_REQUEST['sa']);
- if (isset($_REQUEST['sb'])) $r.= HtmlInput::hidden("sb",$_REQUEST['sb']);
- if (isset($_REQUEST['sc'])) $r.= HtmlInput::hidden("sc",$_REQUEST['sc']);
- if (isset($_REQUEST['f_id'])) $r.=HtmlInput::hidden("f_id",$_REQUEST['f_id']);
-
- $r.=' ';
- $button=new IButton('tfs');
- $button->label=_("Afficher recherche");
- $button->javascript="toggleHideShow('search_form','tfs');";
- $r.='';
- $r.=$button->input();
-
- return $r;
- }
-
- /*!\brief return the last p_limit operation into an array
- *\param $p_limit is the max of operation to return
- *\return $p_array of Action object
- */
- function get_last($p_limit) {
- $user=new User($this->db);
- $filter_ledger=$user->get_ledger_sql('ALL',3);
- $filter_ledger=str_replace('jrn_def_id','jr_def_id',$filter_ledger);
- $sql="select jr_id,jr_pj_number,jr_date,to_char(jr_date,'DD.MM.YYYY') as jr_date_fmt,jr_montant, jr_comment,jr_internal from jrn ".
- " where $filter_ledger ".
- " order by jr_date desc limit $p_limit";
- $array=$this->db->get_array($sql);
- return $array;
- }
- /**
- *@brief retreive the jr_grpt_id from a ledger
- *@param $p_what the column to seek
- * possible values are
- * - internal
- *@param $p_value the value of the col.
- */
- function search_group($p_what,$p_value) {
- switch($p_what) {
- case 'internal':
- return $this->db->get_value('select jr_grpt_id from jrn where jr_internal=$1',
- array($p_value));
+ $sql="update jrn set jr_rapt='paid' where jr_id=$id";
+ $Res=$this->db->exec_sql($sql);
+ }
}
- }
- /**
- *@brief retrieve operation from jrn
- *@param $p_from periode (id)
- *@param $p_to periode (id)
- *@return an array
- */
- function get_operation($p_from,$p_to) {
- $jrn=($this->id==0)?'':' and jr_def_id = '.$this->id;
- $sql="select jr_id as id ,jr_internal as internal, ".
- "jr_pj_number as pj,jr_grpt_id,".
- " to_char(jr_date,'DDMMYY') as date_fmt, ".
- " jr_comment as comment, jr_montant as montant ,".
- " jr_grpt_id".
- " from jrn where jr_tech_per >= $1 ".
- ' and jr_tech_per <=$2 '.$jrn.' order by jr_date,substring(jr_pj_number,\'\\\d+$\')::numeric asc';
- $ret=$this->db->get_array($sql,array($p_from,$p_to));
- return $ret;
- }
- /**
- *@brief return the used VAT code with a rate > 0
- *@return an array of tva_id,tva_label,tva_poste
- */
- public function existing_vat(){
- if ( $this->type=='ACH') {
- $array=$this->db->get_array("select tva_id,tva_label,tva_poste from tva_rate where tva_rate != 0.0000 ".
- " and exists (select qp_vat_code from quant_purchase
- where qp_vat_code=tva_id and exists (select j_id from jrnx where j_jrn_def = $1)) order by tva_id",
- array($this->id));
- }
- if ( $this->type=='VEN') {
- $array=$this->db->get_array("select tva_id,tva_label,tva_poste from tva_rate where tva_rate != 0.0000 ".
- " and exists (select qs_vat_code from quant_sold
- where qs_vat_code=tva_id and exists (select j_id from jrnx where j_jrn_def = $1)) order by tva_id",
- array($this->id));
+ function update_internal_code($p_internal)
+ {
+ if ( ! isset($this->grpt_id) )
+ exit( 'ERREUR '.__FILE__.":".__LINE__);
+ $Res=$this->db->exec_sql("update jrn set jr_internal='".$p_internal."' where ".
+ " jr_grpt_id = ".$this->grpt_id);
}
- return $array;
- }
- /**
- *@brief get the amount of vat for a given jr_grpt_id from the table
- * quant_purchase
- *@param the jr_grpt_id
- *@return array price=htva, [1] = vat,
- *@note
- *@see
-@code
-array
- 'price' => string '91.3500' (length=7)
- 'vat' => string '0.0000' (length=6)
- 'priv' => string '0.0000' (length=6)
- 'tva_nd_recup' => string '0.0000' (length=6)
+ /*!\brief retrieve all the card for this type of ledger, make them
+ *into a string separated by comma
+ *\param none
+ *\return all the card or null is nothing is found
+ */
+ function get_all_fiche_def()
+ {
+ $sql="select jrn_def_fiche_deb as deb,jrn_def_fiche_cred as cred ".
+ " from jrn_def where ".
+ " jrn_def_id = $1 ";
-@endcode
- */
- function get_other_amount($p_jr_id) {
- if ( $this->type=='ACH') {
- $array=$this->db->get_array('select sum(qp_price) as price,sum(qp_vat) as vat '.
- ',sum(qp_dep_priv) as priv'.
- ',sum(qp_nd_tva_recup) as tva_nd_recup'.
- ' from quant_purchase join jrnx using(j_id)
- where j_grpt=$1 ',
- array($p_jr_id));
- $ret=$array[0];
+ $r=$this->db->exec_sql($sql,array($this->id));
+
+ $res=Database::fetch_all($r);
+ if ( empty($res) ) return null;
+ $card="";
+ $comma='';
+ foreach ($res as $item )
+ {
+ if ( strlen(trim($item['deb'])) != 0 )
+ {
+ $card.=$comma.$item['deb'];
+ $comma=',';
+ }
+ if ( strlen(trim($item['cred'])) != '')
+ {
+ $card.=$comma.$item['cred'];
+ $comma=',';
+ }
+
+ }
+
+ return $card;
}
- if ( $this->type=='VEN') {
- $array=$this->db->get_array('select sum(qs_price) as price,sum(qs_vat) as vat '.
- ',0 as priv'.
- ',0 as tva_nd_recup'.
- ' from quant_sold join jrnx using(j_id)
- where j_grpt=$1 ',
- array($p_jr_id));
- $ret=$array[0];
+ /*!\brief get the saldo of an exercice, used for the opening of a folder
+ *\param $p_exercice is the exercice we want
+ *\return an array
+ * index =
+ * - solde (debit > 0 ; credit < 0)
+ * - j_poste
+ * - j_qcode
+ */
+ function get_saldo_exercice($p_exercice)
+ {
+ $sql="select sum(a.montant) as solde, j_poste, j_qcode
+ from
+ (select j_id, case when j_debit='t' then j_montant
+ else j_montant * (-1) end as montant
+ from jrnx) as a
+ join jrnx using (j_id)
+ join parm_periode on (j_tech_per = p_id )
+ where
+ p_exercice=$1
+ and j_poste::text not like '7%'
+ and j_poste::text not like '6%'
+ group by j_poste,j_qcode
+ having (sum(a.montant) != 0 )";
+ $res=$this->db->get_array($sql,array($p_exercice));
+ return $res;
+ }
+ /*!
+ *\brief Check if a Dossier is using the strict mode or not
+ * \return true if we are using the strict_mode
+ */
+ function check_strict()
+ {
+ $owner=new Own($this->db);
+ if ( $owner->MY_STRICT=='Y') return true;
+ if ( $owner->MY_STRICT=='N') return false;
+ exit("Valeur invalid ".__FILE__.':'.__LINE__);
+ }
+ /*!
+ *\brief Check if a Dossier is using the check on the periode, if true than the user has to enter the date
+ * and the periode, it is a security check
+ * \return true if we are using the double encoding (date+periode)
+ */
+ function check_periode()
+ {
+ $owner=new Own($this->db);
+ if ( $owner->MY_CHECK_PERIODE=='Y') return true;
+ if ( $owner->MY_CHECK_PERIODE=='N') return false;
+ exit("Valeur invalid ".__FILE__.':'.__LINE__);
+ }
+
+ /*!\brief get the date of the last operation
+ */
+ function get_last_date()
+ {
+ if ( $this->id==0) throw new Exception (__FILE__.":".__LINE__."Journal incorrect ");
+ $sql="select to_char(max(jr_date),'DD.MM.YYYY') from jrn where jr_def_id=$1";
+ $date=$this->db->get_value($sql,array($this->id));
+ return $date;
+ }
+ /*!\brief retrieve the jr_id thanks the internal code, do not change
+ *anything to the current object
+ *\param the internal code
+ *\return the jr_id or 0 if not found
+ */
+ function get_id($p_internal)
+ {
+ $sql='select jr_id from jrn where jr_internal=$1';
+ $value=$this->db->get_value($sql,array($p_internal));
+ if ($value=='') $value=0;
+ return $value;
+ }
+ /*!\brief create the invoice and saved it as attachment to the
+ *operation,
+ *\param $internal is the internal code
+ *\param $p_array is normally the $_POST
+ *\return a string
+ */
+ function create_document($internal,$p_array)
+ {
+ extract ($p_array);
+ $doc=new Document($this->db);
+ $doc->f_id=$e_client;
+ $doc->md_id=$gen_doc;
+ $doc->ag_id=0;
+ $doc->Generate();
+ // Move the document to the jrn
+ $doc->MoveDocumentPj($internal);
+ // Update the comment with invoice number, if the comment is empty
+ if ( ! isset ($e_comm) || strlen(trim($e_comm))== 0 )
+ {
+ $sql="update jrn set jr_comment=' document ".$doc->d_number."' where jr_internal='$internal'";
+ $this->db->exec_sql($sql);
+ }
+ return h($doc->d_name.' ('.$doc->d_filename.')');
}
- return $ret;
- }
+ /*!\brief check if the payment method is valid
+ *\param $e_mp is the value and $e_mp_qcode is the quickcode
+ *\return nothing throw an Exception
+ */
+ public function check_payment($e_mp,$e_mp_qcode)
+ {
+ /* Check if the "paid by" is empty, */
+ if ( $e_mp != 0)
+ {
+ /* the paid by is not empty then check if valid */
+ $empl=new Fiche($this->db);
+ $empl->get_by_qcode($e_mp_qcode);
+ if ( $empl->empty_attribute(ATTR_DEF_ACCOUNT)== true)
+ {
+ throw new Exception('Celui qui paie n\' a pas de poste comptable',20);
+ }
+ /* get the account and explode if necessary */
+ $sposte=$empl->strAttribut(ATTR_DEF_ACCOUNT);
+ // if 2 accounts, take only the debit one for customer
+ if ( strpos($sposte,',') != 0 )
+ {
+ $array=explode(',',$sposte);
+ $poste_val=$array[0];
+ }
+ else
+ {
+ $poste_val=$sposte;
+ }
+ $poste=new Acc_Account_Ledger($this->db,$poste_val);
+ if ( $poste->load() == false )
+ {
+ throw new Exception('Pour la fiche'.$empl->quick_code.' le poste comptable ['.$poste->id.'n\'existe pas',9);
- /**
- *@brief get the amount of vat for a given jr_grpt_id from the table
- * quant_purchase
- *@param the jr_grpt_id
- *@return array of sum_vat, tva_label
- *@note
- *@see
-@code
+ }
+ }
+ }
-@endcode
- */
- function vat_operation($p_jr_id) {
- if ( $this->type=='ACH') {
- $array=$this->db->get_array('select coalesce(sum(qp_vat),0) as sum_vat,tva_id
- from quant_purchase as p right join tva_rate on (qp_vat_code=tva_id) join jrnx using(j_id)
- where tva_rate !=0.0 and j_grpt=$1 group by tva_id',
- array($p_jr_id));
+
+ /*!\brief increment the sequence for the pj */
+ function inc_seq_pj()
+ {
+ $sql="select nextval('s_jrn_pj".$this->id."')";
+ $this->db->exec_sql($sql);
}
- if ( $this->type=='VEN') {
- $array=$this->db->get_array('select coalesce(sum(qs_vat),0) as sum_vat,tva_id
- from quant_sold as p right join tva_rate on (qs_vat_code=tva_id) join jrnx using(j_id)
- where tva_rate !=0.0 and j_grpt=$1 group by tva_id',
- array($p_jr_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
+ *\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)
+ {
+ $user=new User($this->db);
+ $r='';
+ /* security : filter ledger on user */
+ $filter_ledger=$user->get_ledger($p_type,3);
+
+ $selected=(isset($_REQUEST['r_jrn']))?$_REQUEST['r_jrn']:null;
+ $f_ledger=HtmlInput::select_ledger($filter_ledger,$selected);
+
+ /* 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
+ {
+ $period=$user->get_periode();
+ $per=new Periode($this->db,$period);
+ $exercice=$per->get_exercice();
+ list($per_start,$per_end)=$per->get_limit($exercice);
+ $f_date_start->value=$per_start->first_day();
+ $date_end=$per_end->last_day();
+ }
+
+ /* 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 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']))?$_REQUEST['amount_min']:0;
+ $f_amount_max=new INum('amount_max');
+ $f_amount_max->value=(isset($_REQUEST['amount_max']))?$_REQUEST['amount_max']:0;
+
+ /* input quick code */
+ $f_qcode=new ICard('qcode');
+ $f_qcode->extra='filter';
+ $f_qcode->set_attribute('typecard','all');
+ $f_qcode->set_callback('filter_card');
+ $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);
+ ob_start();
+ require_once('template/ledger_search.php');
+ $r.=ob_get_contents();
+ ob_clean();
+ return $r;
+
}
- return $array;
- }
- /**
- *@brief retrieve amount of previous periode
- *@param $p_to frmo the start of the exercise until $p_to
- *@return $array with vat, price,other_amount
- *@note
- *@see
-@code
-array
- 'price' => string '446.1900' (length=8)
- 'vat' => string '21.7600' (length=7)
- 'priv' => string '0.0000' (length=6)
- 'tva_nd_recup' => string '0.0000' (length=6)
- 'tva' =>
+ /*!\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.YYYY') as jr_ech,
+ to_char(jr_date,'DD.MM.YYYY') as 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
+ from
+ jrn
+ join jrn_def on jrn_def_id=jr_def_id
+ join parm_periode on p_id=jr_tech_per";
+
+ if ( $p_array != null )
+ extract($p_array);
+ $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;
+
+ if ( ! isset ($date_start))
+ {
+ $user=new User($this->db);
+ $period=$user->get_periode();
+ $per=new Periode($this->db);
+ list($date_start,$date_end)=$per->get_date_limit();
+ }
+ $desc='';
+ $qcode=(isset($qcode))?$qcode:"";
+ $accounting=(isset($accounting))?$accounting:"";
+
+ }
+
+ /* 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='';
+
+ $and='';
+ $user=new User($this->db);
+
+ if ( $r_jrn == -1 )
+ {
+ /* Specific action allow to see all the ledgers in once */
+ if ( $p_action == 'gl') $p_action='ALL';
+ /* actions from commercial.php */
+ if ( $p_action == 'client') $p_action='ALL';
+ if ( $p_action == 'supplier') $p_action='ALL';
+ if ( $p_action == 'adm') $p_action='ALL';
+
+ /* from compta.php the p_action is quick_writing instead of ODS */
+ if ( $p_action == 'quick_writing') $p_action='ODS';
+
+
+ $fil_ledger=$user->get_ledger_sql($p_action,3);
+ $and=' and ';
+ }
+ else
+ {
+ if ( $p_action == 'gl') $p_action='ALL';
+ if ( $p_action == 'quick_writing') $p_action='ODS';
+
+ $aLedger=$user->get_ledger($p_action,3);
+ $fil_ledger='';
+ $sp='';
+
+ for ($i=0;$i < count($aLedger) ;$i ++)
+ {
+ if ( isset($r_jrn[$i]))
+ {
+ $fil_ledger.=$sp.$aLedger[$i]['jrn_def_id'];
+ $sp=',';
+ }
+
+ }
+ $fil_ledger=' jrn_def_id in ('.$fil_ledger.')';
+ $and=' and ';
+
+ /* no ledger selected */
+ if ( $sp == '' )
+ {
+ $fil_ledger='';
+ $and='';
+ }
+ }
+
+ /* format the number */
+ $amount_min=toNumber($amount_min);
+ $amount_max=toNumber($amount_max);
+ if ( $amount_min > 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. 'jr_grpt_id in ( select distinct j_grpt from jrnx where j_montant = '.$amount_min.')';
+ $and=" and ";
+ }
+ // date
+ if ( isDate($date_start) != null )
+ {
+ $fil_date=$and." jr_date >= to_date('".$date_start."','DD.MM.YYYY')";
+ $and=" and ";
+ }
+ if ( isDate($date_end) != null )
+ {
+ $fil_date.=$and." jr_date <= to_date('".$date_end."','DD.MM.YYYY')";
+ $and=" and ";
+ }
+ // comment
+ $desc=FormatString($desc);
+ if ( $desc != null )
+ {
+ $fil_desc=$and." ( upper(jr_comment) like upper('%".$desc."%') or upper(jr_pj_number) like upper('%".$desc."%') ".
+ " or upper(jr_internal) like upper('%".$desc."%') )";
+ $and=" and ";
+ }
+ // Poste
+ if ( $accounting != null )
+ {
+ $fil_account=$and." jr_grpt_id in (select j_grpt
+ from jrnx where j_poste::text like '$accounting%' ) ";
+ $and=" and ";
+ }
+ // Quick Code
+ if ( $qcode != null )
+ {
+ $fil_qcode=$and." jr_grpt_id in ( select j_grpt from
+ jrnx where trim(j_qcode) = upper(trim('$qcode')))";
+ $and=" and ";
+ }
+
+ // Only the unpaid
+ if ( isset($unpaid) )
+ {
+ $fil_paid=$and.SQL_LIST_UNPAID_INVOICE;
+ $and =" and ";
+ }
+
+ $User=new User(new Database());
+ $User->Check();
+ $User->check_dossier(dossier::id());
+
+ if ( $User->admin == 0 && $User->is_local_admin()==0 )
+ {
+ $fil_sec=$and." jr_def_id in ( select uj_jrn_id ".
+ " from user_sec_jrn where ".
+ " uj_login='".$_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;
+ $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=="" || $this->id==0) $type='ALL';
+ if ( isset($_GET['amount_min']) )
+ {
+ $display='block';
+ }
+ else
+ {
+ $display='none';
+ }
+ $r.='';
+ $r.='
';
+ $r.=$this->search_form($type);
+ $r.=HtmlInput::submit('search',_('Rechercher'));
+ $r.=HtmlInput::hidden('p_action',$_REQUEST['p_action']);
+
+ /* when called from commercial.php some hidden values are needed */
+ if (isset($_REQUEST['sa'])) $r.= HtmlInput::hidden("sa",$_REQUEST['sa']);
+ if (isset($_REQUEST['sb'])) $r.= HtmlInput::hidden("sb",$_REQUEST['sb']);
+ if (isset($_REQUEST['sc'])) $r.= HtmlInput::hidden("sc",$_REQUEST['sc']);
+ if (isset($_REQUEST['f_id'])) $r.=HtmlInput::hidden("f_id",$_REQUEST['f_id']);
+
+ $r.=' ';
+ $button=new IButton('tfs');
+ $button->label=_("Afficher recherche");
+ $button->javascript="toggleHideShow('search_form','tfs');";
+ $r.='';
+ $r.=$button->input();
+
+ return $r;
+ }
+
+ /*!\brief return the last p_limit operation into an array
+ *\param $p_limit is the max of operation to return
+ *\return $p_array of Action object
+ */
+ function get_last($p_limit)
+ {
+ $user=new User($this->db);
+ $filter_ledger=$user->get_ledger_sql('ALL',3);
+ $filter_ledger=str_replace('jrn_def_id','jr_def_id',$filter_ledger);
+ $sql="select jr_id,jr_pj_number,jr_date,to_char(jr_date,'DD.MM.YYYY') as jr_date_fmt,jr_montant, jr_comment,jr_internal from jrn ".
+ " where $filter_ledger ".
+ " order by jr_date desc limit $p_limit";
+ $array=$this->db->get_array($sql);
+ return $array;
+ }
+ /**
+ *@brief retreive the jr_grpt_id from a ledger
+ *@param $p_what the column to seek
+ * possible values are
+ * - internal
+ *@param $p_value the value of the col.
+ */
+ function search_group($p_what,$p_value)
+ {
+ switch($p_what)
+ {
+ case 'internal':
+ return $this->db->get_value('select jr_grpt_id from jrn where jr_internal=$1',
+ array($p_value));
+
+ }
+ }
+ /**
+ *@brief retrieve operation from jrn
+ *@param $p_from periode (id)
+ *@param $p_to periode (id)
+ *@return an array
+ */
+ function get_operation($p_from,$p_to)
+ {
+ $jrn=($this->id==0)?'':' and jr_def_id = '.$this->id;
+ $sql="select jr_id as id ,jr_internal as internal, ".
+ "jr_pj_number as pj,jr_grpt_id,".
+ " to_char(jr_date,'DDMMYY') as date_fmt, ".
+ " jr_comment as comment, jr_montant as montant ,".
+ " jr_grpt_id".
+ " from jrn where jr_tech_per >= $1 ".
+ ' and jr_tech_per <=$2 '.$jrn.' order by jr_date,substring(jr_pj_number,\'\\\d+$\')::numeric asc';
+ $ret=$this->db->get_array($sql,array($p_from,$p_to));
+ return $ret;
+ }
+ /**
+ *@brief return the used VAT code with a rate > 0
+ *@return an array of tva_id,tva_label,tva_poste
+ */
+ public function existing_vat()
+ {
+ if ( $this->type=='ACH')
+ {
+ $array=$this->db->get_array("select tva_id,tva_label,tva_poste from tva_rate where tva_rate != 0.0000 ".
+ " and exists (select qp_vat_code from quant_purchase
+ where qp_vat_code=tva_id and exists (select j_id from jrnx where j_jrn_def = $1)) order by tva_id",
+ array($this->id));
+ }
+ if ( $this->type=='VEN')
+ {
+ $array=$this->db->get_array("select tva_id,tva_label,tva_poste from tva_rate where tva_rate != 0.0000 ".
+ " and exists (select qs_vat_code from quant_sold
+ where qs_vat_code=tva_id and exists (select j_id from jrnx where j_jrn_def = $1)) order by tva_id",
+ array($this->id));
+
+ }
+ return $array;
+ }
+ /**
+ *@brief get the amount of vat for a given jr_grpt_id from the table
+ * quant_purchase
+ *@param the jr_grpt_id
+ *@return array price=htva, [1] = vat,
+ *@note
+ *@see
+ @code
array
- 0 =>
- array
- 'sum_vat' => string '13.7200' (length=7)
- 'tva_id' => string '1' (length=1)
- 1 =>
- array
- 'sum_vat' => string '8.0400' (length=6)
- 'tva_id' => string '3' (length=1)
- 2 =>
- array
- 'sum_vat' => string '0.0000' (length=6)
- 'tva_id' => string '4' (length=1)
+ 'price' => string '91.3500' (length=7)
+ 'vat' => string '0.0000' (length=6)
+ 'priv' => string '0.0000' (length=6)
+ 'tva_nd_recup' => string '0.0000' (length=6)
-@endcode
- */
- function previous_amount($p_to) {
- /* get the first periode of exercise */
- $periode=new Periode($this->db,$p_to);
- $exercise=$periode->get_exercice();
- list ($min,$max)=$periode->get_limit($exercise);
- // min periode
- if ($this->type=='ACH') {
- /* get all amount exclude vat */
- $sql="select coalesce(sum(qp_price),0) as price".
- " ,coalesce(sum(qp_vat),0) as vat ".
- ',coalesce(sum(qp_dep_priv),0) as priv'.
- ',coalesce(sum(qp_nd_tva_recup),0) as tva_nd_recup'.
- ' from quant_purchase join jrnx using(j_id) '.
- ' where j_tech_per >= $1 and j_tech_per < $2';
- $array=$this->db->get_array($sql,array($min->p_id,$p_to));
- $ret=$array[0];
- /* retrieve all vat code */
- $array=$this->db->get_array('select coalesce(sum(qp_vat),0) as sum_vat,tva_id
- from quant_purchase as p right join tva_rate on (qp_vat_code=tva_id) join jrnx using(j_id)
- where tva_rate !=0 and j_tech_per >= $1 and j_tech_per < $2 group by tva_id',
- array($min->p_id,$p_to));
- $ret['tva']=$array;
- }
- if ($this->type=='VEN') {
- /* get all amount exclude vat */
- $sql="select coalesce(sum(qs_price),0) as price".
- " ,coalesce(sum(qs_vat),0) as vat ".
- ',0 as priv'.
- ',0 as tva_nd_recup'.
- ' from quant_sold join jrnx using(j_id) '.
- ' where j_tech_per >= $1 and j_tech_per < $2';
- $array=$this->db->get_array($sql,array($min->p_id,$p_to));
- $ret=$array[0];
- /* retrieve all vat code */
- $array=$this->db->get_array('select coalesce(sum(qs_vat),0) as sum_vat,tva_id
- from quant_sold as p right join tva_rate on (qs_vat_code=tva_id) join jrnx using(j_id)
- where tva_rate !=0 and j_tech_per >= $1 and j_tech_per < $2 group by tva_id',
- array($min->p_id,$p_to));
- $ret['tva']=$array;
- }
- return $ret;
- }
- ////////////////////////////////////////////////////////////////////////////////
- // TEST MODULE
- ////////////////////////////////////////////////////////////////////////////////
- /*!
- * \brief this function is intended to test this class
- */
- static function test_me($pCase='')
- {
- if ( $pCase=='') {
- echo Acc_Reconciliation::$javascript;
- html_page_start();
- $cn=new Database(dossier::id());
- $_SESSION['g_user']='phpcompta';
- $_SESSION['g_pass']='phpcompta';
+ @endcode
+ */
+ function get_other_amount($p_jr_id)
+ {
+ if ( $this->type=='ACH')
+ {
+ $array=$this->db->get_array('select sum(qp_price) as price,sum(qp_vat) as vat '.
+ ',sum(qp_dep_priv) as priv'.
+ ',sum(qp_nd_tva_recup) as tva_nd_recup'.
+ ' from quant_purchase join jrnx using(j_id)
+ where j_grpt=$1 ',
+ array($p_jr_id));
+ $ret=$array[0];
+ }
+ if ( $this->type=='VEN')
+ {
+ $array=$this->db->get_array('select sum(qs_price) as price,sum(qs_vat) as vat '.
+ ',0 as priv'.
+ ',0 as tva_nd_recup'.
+ ' from quant_sold join jrnx using(j_id)
+ where j_grpt=$1 ',
+ array($p_jr_id));
+ $ret=$array[0];
- $id=(isset ($_REQUEST['p_jrn']))?$_REQUEST['p_jrn']:-1;
- $a=new Acc_Ledger($cn,$id);
- $a->with_concerned=true;
- // Vide
- echo '';
- echo $a->select_ledger()->input();
- echo HtmlInput::submit('go','Test it');
- echo ' ';
- if ( isset($_POST['go'])) {
- echo "Ok ";
- echo '';
- echo $a->show_form();
- echo HtmlInput::submit('post_id','Try me');
- echo ' ';
- // Show the predef operation
- // Don't forget the p_jrn
- echo '';
- echo dossier::hidden();
- echo ' ';
- $op=new Pre_operation($cn);
- $op->p_jrn=$id;
- $op->od_direct='t';
- if ($op->count() != 0 ) {
- echo HtmlInput::submit('use_opd','Utilisez une op.prédéfinie');
- echo $op->show_button();
- }
- echo ' ';
- exit();
+ }
+ return $ret;
}
- if ( isset($_POST['post_id' ])) {
+ /**
+ *@brief get the amount of vat for a given jr_grpt_id from the table
+ * quant_purchase
+ *@param the jr_grpt_id
+ *@return array of sum_vat, tva_label
+ *@note
+ *@see
+ @code
- echo '';
- echo $a->show_form($_POST,1);
- echo HtmlInput::button('add','Ajout d\'une ligne','onClick="quick_writing_add_row()"');
- echo HtmlInput::submit('save_it',"Sauver");
- echo ' ';
- exit();
+ @endcode
+ */
+ function vat_operation($p_jr_id)
+ {
+ if ( $this->type=='ACH')
+ {
+ $array=$this->db->get_array('select coalesce(sum(qp_vat),0) as sum_vat,tva_id
+ from quant_purchase as p right join tva_rate on (qp_vat_code=tva_id) join jrnx using(j_id)
+ where tva_rate !=0.0 and j_grpt=$1 group by tva_id',
+ array($p_jr_id));
+ }
+ if ( $this->type=='VEN')
+ {
+ $array=$this->db->get_array('select coalesce(sum(qs_vat),0) as sum_vat,tva_id
+ from quant_sold as p right join tva_rate on (qs_vat_code=tva_id) join jrnx using(j_id)
+ where tva_rate !=0.0 and j_grpt=$1 group by tva_id',
+ array($p_jr_id));
+ }
+ return $array;
}
- if ( isset($_POST['save_it' ])) {
- print 'saving';
- $array=$_POST;
- $array['save_opd']=1;
- try {
- $a->save($array);
- } catch (Exception $e) {
- alert($e->getMessage());
- echo '';
+ /**
+ *@brief retrieve amount of previous periode
+ *@param $p_to frmo the start of the exercise until $p_to
+ *@return $array with vat, price,other_amount
+ *@note
+ *@see
+ @code
+ array
+ 'price' => string '446.1900' (length=8)
+ 'vat' => string '21.7600' (length=7)
+ 'priv' => string '0.0000' (length=6)
+ 'tva_nd_recup' => string '0.0000' (length=6)
+ 'tva' =>
+ array
+ 0 =>
+ array
+ 'sum_vat' => string '13.7200' (length=7)
+ 'tva_id' => string '1' (length=1)
+ 1 =>
+ array
+ 'sum_vat' => string '8.0400' (length=6)
+ 'tva_id' => string '3' (length=1)
+ 2 =>
+ array
+ 'sum_vat' => string '0.0000' (length=6)
+ 'tva_id' => string '4' (length=1)
- echo $a->show_form($_POST);
- echo HtmlInput::submit('post_id','Try me');
- echo ' ';
-
- }
- exit();
+ @endcode
+ */
+ function previous_amount($p_to)
+ {
+ /* get the first periode of exercise */
+ $periode=new Periode($this->db,$p_to);
+ $exercise=$periode->get_exercice();
+ list ($min,$max)=$periode->get_limit($exercise);
+ // min periode
+ if ($this->type=='ACH')
+ {
+ /* get all amount exclude vat */
+ $sql="select coalesce(sum(qp_price),0) as price".
+ " ,coalesce(sum(qp_vat),0) as vat ".
+ ',coalesce(sum(qp_dep_priv),0) as priv'.
+ ',coalesce(sum(qp_nd_tva_recup),0) as tva_nd_recup'.
+ ' from quant_purchase join jrnx using(j_id) '.
+ ' where j_tech_per >= $1 and j_tech_per < $2';
+ $array=$this->db->get_array($sql,array($min->p_id,$p_to));
+ $ret=$array[0];
+ /* retrieve all vat code */
+ $array=$this->db->get_array('select coalesce(sum(qp_vat),0) as sum_vat,tva_id
+ from quant_purchase as p right join tva_rate on (qp_vat_code=tva_id) join jrnx using(j_id)
+ where tva_rate !=0 and j_tech_per >= $1 and j_tech_per < $2 group by tva_id',
+ array($min->p_id,$p_to));
+ $ret['tva']=$array;
+ }
+ if ($this->type=='VEN')
+ {
+ /* get all amount exclude vat */
+ $sql="select coalesce(sum(qs_price),0) as price".
+ " ,coalesce(sum(qs_vat),0) as vat ".
+ ',0 as priv'.
+ ',0 as tva_nd_recup'.
+ ' from quant_sold join jrnx using(j_id) '.
+ ' where j_tech_per >= $1 and j_tech_per < $2';
+ $array=$this->db->get_array($sql,array($min->p_id,$p_to));
+ $ret=$array[0];
+ /* retrieve all vat code */
+ $array=$this->db->get_array('select coalesce(sum(qs_vat),0) as sum_vat,tva_id
+ from quant_sold as p right join tva_rate on (qs_vat_code=tva_id) join jrnx using(j_id)
+ where tva_rate !=0 and j_tech_per >= $1 and j_tech_per < $2 group by tva_id',
+ array($min->p_id,$p_to));
+ $ret['tva']=$array;
+ }
+ return $ret;
}
- // The GET at the end because automatically repost when you don't
- // specify the url in the METHOD field
- if ( isset ($_GET['use_opd'])) {
- $op=new Pre_op_advanced($cn);
- $op->set_od_id($_REQUEST['pre_def']);
- //$op->p_jrn=$id;
+ ////////////////////////////////////////////////////////////////////////////////
+ // TEST MODULE
+ ////////////////////////////////////////////////////////////////////////////////
+ /*!
+ * \brief this function is intended to test this class
+ */
+ static function test_me($pCase='')
+ {
+ if ( $pCase=='')
+ {
+ echo Acc_Reconciliation::$javascript;
+ html_page_start();
+ $cn=new Database(dossier::id());
+ $_SESSION['g_user']='phpcompta';
+ $_SESSION['g_pass']='phpcompta';
- $p_post=$op->compute_array();
+ $id=(isset ($_REQUEST['p_jrn']))?$_REQUEST['p_jrn']:-1;
+ $a=new Acc_Ledger($cn,$id);
+ $a->with_concerned=true;
+ // Vide
+ echo '';
+ echo $a->select_ledger()->input();
+ echo HtmlInput::submit('go','Test it');
+ echo ' ';
+ if ( isset($_POST['go']))
+ {
+ echo "Ok ";
+ echo '';
+ echo $a->show_form();
+ echo HtmlInput::submit('post_id','Try me');
+ echo ' ';
+ // Show the predef operation
+ // Don't forget the p_jrn
+ echo '';
+ echo dossier::hidden();
+ echo ' ';
+ $op=new Pre_operation($cn);
+ $op->p_jrn=$id;
+ $op->od_direct='t';
+ if ($op->count() != 0 )
+ {
+ echo HtmlInput::submit('use_opd','Utilisez une op.prédéfinie');
+ echo $op->show_button();
+ }
+ echo ' ';
+ exit();
+ }
- echo '';
+ if ( isset($_POST['post_id' ]))
+ {
- echo $a->show_form($p_post);
- echo HtmlInput::submit('post_id','Use predefined operation');
- echo ' ';
- exit();
+ echo '';
+ echo $a->show_form($_POST,1);
+ echo HtmlInput::button('add','Ajout d\'une ligne','onClick="quick_writing_add_row()"');
+ echo HtmlInput::submit('save_it',"Sauver");
+ echo ' ';
+ exit();
+ }
+ if ( isset($_POST['save_it' ]))
+ {
+ print 'saving';
+ $array=$_POST;
+ $array['save_opd']=1;
+ try
+ {
+ $a->save($array);
+ }
+ catch (Exception $e)
+ {
+ alert($e->getMessage());
+ echo '';
+ echo $a->show_form($_POST);
+ echo HtmlInput::submit('post_id','Try me');
+ echo ' ';
+
+ }
+ exit();
+ }
+ // The GET at the end because automatically repost when you don't
+ // specify the url in the METHOD field
+ if ( isset ($_GET['use_opd']))
+ {
+ $op=new Pre_op_advanced($cn);
+ $op->set_od_id($_REQUEST['pre_def']);
+ //$op->p_jrn=$id;
+
+ $p_post=$op->compute_array();
+
+ echo '';
+
+ echo $a->show_form($p_post);
+ echo HtmlInput::submit('post_id','Use predefined operation');
+ echo ' ';
+ exit();
+
+ }
+ }// if case = ''
+ ///////////////////////////////////////////////////////////////////////////
+ // search
+ if ( $pCase == 'search')
+ {
+ html_page_start();
+ $cn=new Database(dossier::id());
+ $ledger=new Acc_Ledger($cn,0);
+ $_SESSION['g_user']='phpcompta';
+ $_SESSION['g_pass']='phpcompta';
+ echo $ledger->search_form('ALL');
+ }
+ ///////////////////////////////////////////////////////////////////////////
+ // reverse
+ // Give yourself the var and check in your tables
+ ///////////////////////////////////////////////////////////////////////////
+ if ( $pCase=='reverse')
+ {
+ $cn=new Database (dossier::id());
+ $jr_internal='OD-01-272';
+ try
+ {
+ $cn->start();
+ $jrn_def_id=$cn->get_value('select jr_def_id from jrn where jr_internal=$1',array($jr_internal));
+ $ledger=new Acc_Ledger($cn,$jrn_def_id);
+ $ledger->jr_id=$cn->get_value('select jr_id from jrn where jr_internal=$1',array($jr_internal));
+
+ echo "Ouvrez le fichier ".__FILE__." à la ligne ".__LINE__." pour changer jr_internal et vérifier le résultat de l'extourne";
+
+ $ledger->reverse('01.07.2010');
+ }
+ catch (Exception $e)
+ {
+ $cn->rollback();
+ var_dump($e);
+ }
+ $cn->commit();
+ }
}
- }// if case = ''
- ///////////////////////////////////////////////////////////////////////////
- // search
- if ( $pCase == 'search') {
- html_page_start();
- $cn=new Database(dossier::id());
- $ledger=new Acc_Ledger($cn,0);
- $_SESSION['g_user']='phpcompta';
- $_SESSION['g_pass']='phpcompta';
- echo $ledger->search_form('ALL');
+ /**
+ * create an array of the existing cat, to be used in a checkbox form
+ *
+ */
+ static function array_cat()
+ {
+ $r= array(
+ array('cat'=>'VEN','name'=>'Journaux de vente'),
+ array('cat'=>'ACH','name'=>'Journaux d\'achat'),
+ array('cat'=>'FIN','name'=>'Journaux Financier'),
+ array('cat'=>'ODS','name'=>'Journaux d\'Opérations diverses')
+ );
+ return $r;
}
- ///////////////////////////////////////////////////////////////////////////
- // reverse
- // Give yourself the var and check in your tables
- ///////////////////////////////////////////////////////////////////////////
- if ( $pCase=='reverse') {
- $cn=new Database (dossier::id());
- $jr_internal='OD-01-272';
- try {
- $cn->start();
- $jrn_def_id=$cn->get_value('select jr_def_id from jrn where jr_internal=$1',array($jr_internal));
- $ledger=new Acc_Ledger($cn,$jrn_def_id);
- $ledger->jr_id=$cn->get_value('select jr_id from jrn where jr_internal=$1',array($jr_internal));
-
- echo "Ouvrez le fichier ".__FILE__." à la ligne ".__LINE__." pour changer jr_internal et vérifier le résultat de l'extourne";
-
- $ledger->reverse('01.07.2010');
- } catch (Exception $e) {
- $cn->rollback();
- var_dump($e);
- }
- $cn->commit();
- }
- }
- /**
- * create an array of the existing cat, to be used in a checkbox form
- *
- */
- static function array_cat() {
- $r= array(
- array('cat'=>'VEN','name'=>'Journaux de vente'),
- array('cat'=>'ACH','name'=>'Journaux d\'achat'),
- array('cat'=>'FIN','name'=>'Journaux Financier'),
- array('cat'=>'ODS','name'=>'Journaux d\'Opérations diverses')
- );
- return $r;
- }
}
diff --git a/include/class_acc_ledger_fin.php b/include/class_acc_ledger_fin.php
index af011a70f..bf4290af5 100644
--- a/include/class_acc_ledger_fin.php
+++ b/include/class_acc_ledger_fin.php
@@ -36,858 +36,921 @@ require_once('class_acc_ledger.php');
require_once('ac_common.php');
require_once('class_acc_reconciliation.php');
-class Acc_Ledger_Fin extends Acc_Ledger {
- function __construct ($p_cn,$p_init) {
- parent::__construct($p_cn,$p_init);
- $this->type='FIN';
- }
-
- /*!\brief verify that the data are correct before inserting or confirming
- *\param an array (usually $_POST)
- *\return String
- *\throw Exception on error occurs
- */
- public function verify($p_array) {
- extract ($p_array);
- /* check for a double reload */
- if ( isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1',array($mt)) != 0 )
- throw new Exception (_('Double Encodage'),5);
-
- /* check if we can write into this ledger */
- $user=new User($this->db);
- if ( $user->check_jrn($p_jrn) != 'W' )
- throw new Exception (_('Accès interdit'),20);
-
- /* check if there is a bank account linked to the ledger */
- $bank_id=$this->get_bank();
-
- if ($this->db->count()==0 )
- throw new Exception("Ce journal n'a pas de compte en banque, allez dans paramètre->journal pour régler cela");
- /* check if the accounting of the bank is correct */
- $fBank=new Fiche($this->db,$bank_id);
- $bank_accounting=$fBank->strAttribut(ATTR_DEF_ACCOUNT);
- if ( trim($bank_accounting)=='' )
- throw new Exception ('Le poste comptable du compte en banque de ce journal est invalide');
-
- /* check if the account exists */
- $poste=new Acc_Account_Ledger($this->db,$bank_accounting);
- if ( $poste->load() == false )
- throw new Exception ('Le poste comptable du compte en banque de ce journal est invalide');
-
- /* check if the date is valid */
- if ( isDate($e_date) == null ) {
- throw new Exception('Date invalide', 2);
- }
- $oPeriode=new Periode($this->db);
- if ($this->check_periode()==false) {
- $periode=$oPeriode->find_periode($e_date);
- } else {
- $oPeriode->p_id=$periode;
- list ($min,$max)=$oPeriode->get_date_limit();
- if ( cmpDate($e_date,$min) < 0 ||
- cmpDate($e_date,$max) > 0)
- throw new Exception(_('Date et periode ne correspondent pas'),6);
- }
-
- /* check if the periode is closed */
- if ( $this->is_closed($periode)==1 )
- {
- throw new Exception(_('Periode fermee'),6);
- }
-
- /* check if we are using the strict mode */
- if( $this->check_strict() == true) {
- /* if we use the strict mode, we get the date of the last
- operation */
- $last_date=$this->get_last_date();
- if ( $last_date != null && cmpDate($e_date,$last_date) < 0 )
- throw new Exception(_('Vous utilisez le mode strict la dernière operation est à la date du ')
- .$last_date._(' vous ne pouvez pas encoder à une date antérieure'),15);
-
- }
-
- $acc_pay=new Acc_Operation($this->db);
-
- $nb=0;
- $tot_amount=0;
- //----------------------------------------
- // foreach item
- //----------------------------------------
- for ($i=0;$i< $nb_item;$i++) {
- if ( strlen(trim(${'e_other'.$i}))== 0) continue;
- /* check if amount are numeric and */
- if ( isNumber(${'e_other'.$i.'_amount'}) == 0 )
- throw new Exception('La fiche '.${'e_other'.$i}.'a un montant invalide ['.${'e_other'.$i.'_amount'}.']',6);
-
- /* compute the total */
- $tot_amount+=round(${'e_other'.$i.'_amount'},2);
- /* check if all card has a ATTR_DEF_ACCOUNT*/
- $fiche=new Fiche($this->db);
- $fiche->get_by_qcode(${'e_other'.$i});
- if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
- throw new Exception('La fiche '.${'e_other'.$i}.'n\'a pas de poste comptable',8);
-
- $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
- // if 2 accounts, take only the debit one for customer
- if ( strpos($sposte,',') != 0 ) {
- $array=explode(',',$sposte);
- $poste_val=$array[1];
- } else {
- $poste_val=$sposte;
- }
- /* The account exists */
- $poste=new Acc_Account_Ledger($this->db,$poste_val);
- if ( $poste->load() == false ){
- throw new Exception('Pour la fiche '.${'e_other'.$i}.' le poste comptable ['.$poste->id.'n\'existe pas',9);
- }
- /* Check if the card belong to the ledger */
- $fiche=new Fiche ($this->db);
- $fiche->get_by_qcode(${'e_other'.$i});
- if ( $fiche->belong_ledger($p_jrn,'deb') !=1 )
- throw new Exception('La fiche '.${'e_other'.$i}.'n\'est pas accessible à ce journal',10);
- $nb++;
- }
- if ( $nb == 0 )
- throw new Exception('Il n\'y a aucune opération',12);
-
- /* Check if the last_saldo and first_saldo are correct */
- if ( strlen(trim($last_sold)) != 0 && isNumber($last_sold) &&
- strlen(trim($first_sold)) != 0 && isNumber($first_sold))
- {
- $diff=$last_sold-$first_sold;
- $diff=round($diff,2)-round($tot_amount,2);
- if ( $first_sold != 0 && $last_sold !=0) {
- if ( $diff != 0 )
- throw new Exception('Le montant de l\'extrait est incorrect'.
- $tot_amount.' extrait '.$diff,13);
- }
- }
-
- }
-
-
- /*!\brief
- *\param $p_array contains the value usually it is $_POST
- *\return string with html code
- *\note the form tag are not set here
- */
- function input($p_array=null) {
- if ( $p_array != null)
- extract ($p_array);
- $owner=new Own($this->db);
-
- $pview_only=false;
- $user = new User($this->db);
- $f_add_button=new IButton('add_card');
- $f_add_button->label=_('Créer une nouvelle fiche');
- $f_add_button->set_attribute('ipopup','ipop_newcard');
- $f_add_button->set_attribute('jrn',$this->id);
- $f_add_button->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
- $str_add_button=$f_add_button->input();
-
- // The first day of the periode
- $pPeriode=new Periode($this->db);
- list ($l_date_start,$l_date_end)=$pPeriode->get_date_limit($user->get_periode());
- if ( $owner->MY_DATE_SUGGEST=='Y' )
- $op_date=( ! isset($e_date) ) ?$l_date_start:$e_date;
- else
- $op_date=( ! isset($e_date) ) ?'':$e_date;
-
- $r="";
-
- $r.=dossier::hidden();
- $f_legend='Banque, caisse';
- // Date
- //--
- $Date=new IDate("e_date",$op_date);
- $Date->setReadOnly($pview_only);
- $f_date=$Date->input();
- $f_period='';
- if ($this->check_periode() == true) {
- // Periode
- //--
- $l_user_per=(isset($periode))?$periode:$user->get_periode();
- $period=new IPeriod();
- $period->cn=$this->db;
- $period->type=OPEN;
- $period->value=$l_user_per;
- $period->user=$user;
- $period->name='periode';
- try {
- $l_form_per=$period->input();
- } catch (Exception $e) {
- if ($e->getCode() == 1 ) {
- echo "Aucune période ouverte";
- exit();
- }
- }
- $label=HtmlInput::infobulle(3);
- $f_period="Période comptable $label".$l_form_per;
- }
-
- // Ledger (p_jrn)
- //--
- $add_js="";
-
- if ( $owner->MY_PJ_SUGGEST == 'Y') $add_js="onchange='update_pj();update_bank();get_last_date();'";
-
- $wLedger=$this->select_ledger('FIN',2);
- $wLedger->javascript=$add_js;
-
- if ($wLedger == null) exit ('Pas de journal disponible');
-
- $label=" Journal ".HtmlInput::infobulle(2) ;
- $f_jrn=$label.$wLedger->input();
-
-
- // retrieve bank name, code and account from the jrn_def.jrn_def_bank
-
- $f_bank=''.$this->get_bank_name().' ';
-
- $f_legend_detail='Opérations financières';
- //--------------------------------------------------
- // Saldo begin end
- //-------------------------------------------------
- // Extrait
- $default_pj='';
- if ( $owner->MY_PJ_SUGGEST=='Y') {
- $default_pj=$this->guess_pj();
- }
- $wPJ=new IText('e_pj');
- $wPJ->readonly=false;
- $wPJ->size=10;
- $wPJ->value=(isset($e_pj))?$e_pj:$default_pj;
-
- $f_extrait=$wPJ->input().HtmlInput::hidden('e_pj_suggest',$default_pj);
- $label=HtmlInput::infobulle(7);
-
- $first_sold=(isset($first_sold))?$first_sold:"";
- $wFirst=new INum('first_sold',$first_sold);
-
- $last_sold= isset($last_sold)?$last_sold:"";
- $wLast=new INum('last_sold',$last_sold);
-
-
- $max=(isset($nb_item))?$nb_item:MAX_ARTICLE;
-
- $r.= HtmlInput::hidden('nb_item',$max);
- //--------------------------------------------------
- // financial operation
- //-------------------------------------------------
-
- $array=array();
- // Parse each " tiers"
- for ($i=0; $i < $max; $i++) {
- $tiers=(isset(${"e_other".$i}))?${"e_other".$i}:"";
- $tiers_label="";
- $tiers_amount=(isset(${"e_other$i"."_amount"}))?round(${"e_other$i"."_amount"},2):0;
-
- $tiers_comment=(isset (${"e_other$i"."_comment"}))?${"e_other$i"."_comment"}:"";
- // If $tiers has a value
- if ( $tiers != "" )
- {
- $fTiers=new Fiche($this->db);
- $fTiers->get_by_qcode($tiers);
-
- $tiers_label=$fTiers->strAttribut(ATTR_DEF_NAME);
-
- }
- ${"e_other$i"."_amount"}=(isset (${"e_other$i"."_amount"}))?${"e_other$i"."_amount"}:0;
-
- $W1=new ICard();
- $W1->label="";
- $W1->name="e_other".$i;
- $W1->value=$tiers;
- $W1->extra='deb'; // credits
- $W1->typecard='deb';
- $W1->set_dblclick("fill_ipopcard(this);");
- $W1->set_attribute('ipopup','ipopcard');
-
- // name of the field to update with the name of the card
- $W1->set_attribute('label','e_other'.$i.'_label');
- // name of the field to update with the name of the card
- $W1->set_attribute('typecard','filter');
- // Add the callback function to filter the card on the jrn
- $W1->set_callback('filter_card');
- $W1->set_function('fill_data');
- $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
- $W1->name);
- $W1->readonly=$pview_only;
- $array[$i]['qcode']=$W1->input();
- $array[$i]['search']=$W1->search();
-
- // label
- $other=new ISpan("e_other$i"."_label", $tiers_label);
- $array[$i]['span']=$other->input();
- // Comment
- $wComment=new IText("e_other$i"."_comment",$tiers_comment);
-
- $wComment->size=35;
- $wComment->setReadOnly($pview_only);
- $array[$i]['comment']=$wComment->input();
- // amount
- $wAmount=new INum("e_other$i"."_amount",$tiers_amount);
-
- $wAmount->size=7;
- $wAmount->setReadOnly($pview_only);
- $array[$i]['amount']=$wAmount->input();
- // concerned
- ${"e_concerned".$i}=(isset(${"e_concerned".$i}))?${"e_concerned".$i}:"";
- $wConcerned=new IConcerned("e_concerned".$i,${"e_concerned".$i});
- $wConcerned->setReadOnly($pview_only);
- $wConcerned->extra=0;
-
- $wConcerned->extra2='paid';
- $array[$i]['concerned']=$wConcerned->input();
- }
-
- ob_start();
- require_once('template/form_ledger_fin.php');
- $r.=ob_get_contents();
- ob_clean();
-
-
- return $r;
-
- }
- /*!\brief show the summary before inserting into the database, it
- *calls the function for adding a attachment. The function verify
- *should be called before
- *\param $p_array an array usually is $_POST
- *\return string with code html
- */
- public function confirm($p_array) {
- $r="";
- bcscale(2);
- extract ($p_array);
- $pPeriode=new Periode($this->db);
- if ($this->check_periode() == true) {
- $pPeriode->p_id=$periode;
- } else {
- $pPeriode->find_periode($e_date);
- }
-
- list ($l_date_start,$l_date_end)=$pPeriode->get_date_limit();
- $exercice=$pPeriode->get_exercice();
- $r.='';
- $r.='Banque, caisse ';
- $r.='';
- // Date
- //--
- $r.="";
- $r.=' Date : '.$e_date;
- // Periode
- //--
- $r.=" ";
- $r.="Période comptable ";
- $r.=$l_date_start.' - '.$l_date_end;
- $r.=" ";
- $r.=" ";
- // Ledger (p_jrn)
- //--
- $r.='';
- $r.=' Journal ';
- $this->id=$p_jrn;
- $r.='';
- $r.=h($this->get_name());
- $r.=' ';
- $r.=' ';
-
- //retrieve bank name
- $bk_id=$this->get_bank();
-
- $fBank=new Fiche($this->db,$bk_id);
- $e_bank_account_label=$this->get_bank_name();
-
- $filter_year=" j_tech_per in (select p_id from parm_periode where p_exercice='".$exercice."')";
-
- $acc_account=new Acc_Account_Ledger($this->db,$fBank->strAttribut(ATTR_DEF_ACCOUNT));
- $solde=$acc_account->get_solde($filter_year);
- $new_solde=$solde;
-
- $r.=" Banque ";
- $r.=$e_bank_account_label;
-
- $r.="
";
-
- $r.=' ';
-
- $r.='Opérations financières ';
- //--------------------------------------------------
- // Saldo begin end
- //-------------------------------------------------
- $r.='Extrait de compte ';
- $r.='';
- $r.='';
- // Extrait
- //--
- $r.=' Numéro d\'extrait '.h($e_pj);
- $r.='Solde début extrait ';
- $r.=''.$first_sold.' ';
- $r.='Solde fin extrait ';
- $r.=''.$last_sold.' ';
- $r.='
';
- $r.=' ';
-
- //--------------------------------------------------
- // financial operation
- //-------------------------------------------------
- $r.='';
- $r.="";
- $r.="code ";
- $r.="Commentaire ";
- $r.="Montant ";
- $r.=' Op. Concernée(s) ';
- $r.=" ";
- // Parse each " tiers"
- $tot_amount=0;
- //--------------------------------------------------
- // For each items
- //--------------------------------------------------
- for ($i=0; $i < $nb_item; $i++) {
-
- $tiers=(isset(${"e_other".$i}))?${"e_other".$i}:"";
-
- if ( strlen(trim($tiers))==0)continue;
- $tiers_label="";
- $tiers_amount=round(${"e_other$i"."_amount"},2);
- $tot_amount=bcadd($tot_amount,$tiers_amount);
- $tiers_comment=h(${"e_other$i"."_comment"});
- // If $tiers has a value
- $fTiers=new Fiche($this->db);
- $fTiers->get_by_qcode($tiers);
-
- $tiers_label=$fTiers->strAttribut(ATTR_DEF_NAME);
-
- $r.="".${'e_other'.$i}." ";
- // label
- $other=new ISpan();
- $r.='';
- $r.=$fTiers->strAttribut(ATTR_DEF_NAME);
- $r.=' ';
- // Comment
- $r.=''.$tiers_comment.' ';
- // amount
- $r.=''.$tiers_amount.' ';
- // concerned
- $r.='';
- $r.=${"e_concerned".$i};
- $r.=' ';
- $r.=' ';
- }
- $r.="
";
-
- // saldo
- $r.=' Ancien solde = '.$solde;
- $new_solde+=$tot_amount;
- $r.=' Nouveau solde = '.$new_solde;
- $r.=' Difference ='.$tot_amount;
- // check for upload piece
- $file=new IFile();
-
- $r.=" Ajoutez une pièce justificative ";
- $r.=$file->input("pj","");
-
- $r.=' ';
- //--------------------------------------------------
- // Hidden variables
- //--------------------------------------------------
- $r.=dossier::hidden();
- $r.=HtmlInput::hidden('p_jrn',$this->id);
- $r.=HtmlInput::hidden('nb_item',$nb_item);
- $r.=HtmlInput::hidden('last_sold',$last_sold);
- $r.=HtmlInput::hidden('first_sold',$first_sold);
- $r.=HtmlInput::hidden('e_pj',$e_pj);
- $r.=HtmlInput::hidden('e_pj_suggest',$e_pj_suggest);
- $r.=HtmlInput::hidden('e_date',$e_date);
- $mt=microtime(true);
- $r.=HtmlInput::hidden('mt',$mt);
-
- if (isset($periode)) $r.=HtmlInput::hidden('periode',$periode);
- $r.=dossier::hidden();
- $r.=HtmlInput::hidden('sa','n');
- for ($i=0; $i < $nb_item; $i++) {
- $tiers=(isset(${"e_other".$i}))?${"e_other".$i}:"";
- $r.=HtmlInput::hidden('e_other'.$i,$tiers);
- $r.=HtmlInput::hidden('e_other'.$i.'_comment',${'e_other'.$i.'_comment'});
- $r.=HtmlInput::hidden('e_other'.$i.'_amount',${'e_other'.$i.'_amount'});
- $r.=HtmlInput::hidden('e_concerned'.$i,${'e_concerned'.$i});
- }
-
- return $r;
- }
- /*!\brief save the data into the database, included the attachment,
- *and the reconciliations
- *\param $p_array usually $_POST
- *\return string with HTML code
- */
- public function insert($p_array) {
- $internal_code="";
- $oid=0;
- extract ($p_array);
- $ret='';
- // Debit = banque
- $bank_id=$this->get_bank();
- $fBank=new Fiche($this->db,$bank_id);
- $e_bank_account=$fBank->strAttribut(ATTR_DEF_QUICKCODE);
-
- // Get the saldo
- $pPeriode=new Periode($this->db);
- if ( $this->check_periode() == true ) {
- $pPeriode->p_id=$periode;
- } else {
- $pPeriode->find_periode($e_date);
- }
- $exercice=$pPeriode->get_exercice();
-
- $filter_year=" j_tech_per in (select p_id from parm_periode where p_exercice='".$exercice."')";
- $sposte=$fBank->strAttribut(ATTR_DEF_ACCOUNT);
- // if 2 accounts, take only the debit one for customer
- if ( strpos($sposte,',') != 0 ) {
- $array=explode(',',$sposte);
- $poste_val=$array[0];
- } else {
- $poste_val=$sposte;
- }
-
- $acc_account=new Acc_Account_Ledger($this->db,$poste_val);
- $solde=$acc_account->get_solde($filter_year);
- $new_solde=$solde;
-
- try
- {
- $this->db->start();
- $amount=0.0;
- $idx_operation=0;
- $ret='';
- $ret.=tr(th('Quick Code').th('Nom').th('Libellé').th('Montant'));
- // Credit = goods
- for ( $i = 0; $i < $nb_item;$i++) {
- // if tiers is set and amount != 0 insert it into the database
- // and quit the loop ?
- if ( strlen(trim(${"e_other$i"}))==0 ) continue;
- $fPoste=new Fiche($this->db);
- $fPoste->get_by_qcode(${"e_other$i"});
-
- // round it
- ${"e_other$i"."_amount"}=round( ${"e_other$i"."_amount"},2);
-
- // Compute display
- $row=td(${"e_other$i"}).td($fPoste->strAttribut(ATTR_DEF_NAME)).td(${"e_other".$i."_comment"}).td(${"e_other$i"."_amount"},'class="num"');
-
- $ret.=tr($row);
-
- $amount+=${"e_other$i"."_amount"};
- // Record a line for the bank
- // Compute the j_grpt
- $seq=$this->db->get_next_seq('s_grpt');
-
- $acc_operation=new Acc_Operation($this->db);
- $acc_operation->date=$e_date;
- $sposte=$fPoste->strAttribut(ATTR_DEF_ACCOUNT);
- // if 2 accounts
- if ( strpos($sposte,',') != 0 ) {
- $array=explode(',',$sposte);
- if ( ${"e_other$i"."_amount"} < 0 )
- $poste_val=$array[1];
- else
- $poste_val=$array[0];
- } else {
- $poste_val=$sposte;
- }
-
-
- $acc_operation->poste=$poste_val;
- $acc_operation->amount=${"e_other$i"."_amount"}*(-1);
- $acc_operation->grpt=$seq;
- $acc_operation->jrn=$p_jrn;
- $acc_operation->type='d';
-
- if ( isset($periode))
- $tperiode=$periode;
- else
- {
- $per=new Periode($this->db);
- $tperiode=$per->find_periode($e_date);
-
- }
- $acc_operation->periode=$tperiode;
- $acc_operation->qcode=${"e_other".$i};
- $acc_operation->insert_jrnx();
-
- $acc_operation=new Acc_Operation($this->db);
- $acc_operation->date=$e_date;
- $sposte=$fBank->strAttribut(ATTR_DEF_ACCOUNT);
-
- // if 2 accounts
- if ( strpos($sposte,',') != 0 ) {
- $array=explode(',',$sposte);
- if ( ${"e_other$i"."_amount"} < 0 )
- $poste_val=$array[1];
- else
- $poste_val=$array[0];
- } else {
- $poste_val=$sposte;
- }
-
- $acc_operation->poste=$poste_val;
- $acc_operation->amount=${"e_other$i"."_amount"};
- $acc_operation->grpt=$seq;
- $acc_operation->jrn=$p_jrn;
- $acc_operation->type='d';
- $acc_operation->periode=$tperiode;
- $acc_operation->qcode=$e_bank_account;
- $acc_operation->insert_jrnx();
-
-
- if ( FormatString(${"e_other$i"."_comment"}) == null ) {
- // if comment is blank set a default one
- $comment=" compte : ".$fBank->strAttribut(ATTR_DEF_NAME).' a '.
- $fPoste->strAttribut(ATTR_DEF_NAME);
- } else {
- $comment=${'e_other'.$i.'_comment'};
- }
-
-
- $acc_operation=new Acc_Operation($this->db);
- $acc_operation->jrn=$p_jrn;
- $acc_operation->amount=abs(${"e_other$i"."_amount"});
- $acc_operation->date=$e_date;
- $acc_operation->desc=$comment;
- $acc_operation->grpt=$seq;
- $acc_operation->periode=$tperiode;
- $acc_operation->mt=$mt;
- $idx_operation++;
- $acc_operation->pj='';
-
- if ( trim($e_pj) != '' && $this->numb_operation()==true)
- $acc_operation->pj=$e_pj.str_pad($idx_operation,3,0,STR_PAD_LEFT);
-
- if ( trim($e_pj) != '' && $this->numb_operation()==false)
- $acc_operation->pj=$e_pj;
-
- $jr_id=$acc_operation->insert_jrn();
- // $acc_operation->set_pj();
- $this->db->exec_sql('update jrn set jr_pj_number=$1 where jr_id=$2',
- array($acc_operation->pj,$jr_id));
- $internal=$this->compute_internal_code($seq);
-
-
- if ( trim(${"e_concerned".$i}) != "" ) {
- if ( strpos(${"e_concerned".$i},',') != 0 )
- {
- $aRapt=explode(',',${"e_concerned".$i});
- foreach ($aRapt as $rRapt) {
- // Add a "concerned operation to bound these op.together
- //
- $rec=new Acc_Reconciliation ($this->db);
- $rec->set_jr_id($jr_id);
-
- if ( isNumber($rRapt) == 1 )
- {
- $rec->insert($rRapt);
- }
- }
- } else
- if ( isNumber(${"e_concerned".$i}) == 1 )
- {
- $rec=new Acc_Reconciliation ($this->db);
- $rec->set_jr_id($jr_id);
- $rec->insert(${"e_concerned$i"});
- }
- }
-
- // Set Internal code
- $this->grpt_id=$seq;
- /**
- * save also into quant_fin
- */
- $sql="INSERT INTO quant_fin(
- qf_bank, jr_id, qf_other, qf_amount)
- VALUES ($1, $2, $3, $4);";
-
- $this->db->exec_sql($sql,array($fBank->id,$jr_id,$fPoste->id,${"e_other$i"."_amount"}));
-
- $this->update_internal_code($internal);
-
-
-
- if ( $i == 0 )
- {
- // first record we upload the files and
- // keep variable to update other row of jrn
- if ( isset ($_FILES))
- $oid=$this->db->save_upload_document($seq);
-
- } else {
- if ( $oid != 0 )
- {
- $this->db->exec_sql("update jrn set jr_pj=".$oid.", jr_pj_name='".$_FILES['pj']['name']."', ".
- "jr_pj_type='".$_FILES['pj']['type']."' where jr_grpt_id=$seq");
- }
- }
-
- } // for nbitem
- // increment pj
- if ( strlen(trim($e_pj)) !=0 ) {
- $this->inc_seq_pj();
- }
- $ret.='
';
- }
- catch (Exception $e)
+class Acc_Ledger_Fin extends Acc_Ledger
+{
+ function __construct ($p_cn,$p_init)
{
- echo ''.
- 'Erreur dans l\'enregistrement '.
- __FILE__.':'.__LINE__.' '.
- $e->getMessage();
- $this->db->rollback();
- exit();
-
+ parent::__construct($p_cn,$p_init);
+ $this->type='FIN';
}
- $this->db->commit();
- $r="";
- $r.=" Ancien solde ".$solde;
- $new_solde+=$amount;
- $r.=" Nouveau solde ".$new_solde;
- $ret.=$r;
- return $ret;
- }
- /*!\brief display operation of a FIN ledger
- *\return html code into a string
- */
- function show_ledger() {
- echo dossier::hidden();
- $hid=new IHidden();
-
- $hid->name="p_action";
- $hid->value="bank";
- echo $hid->input();
-
-
- $hid->name="sa";
- $hid->value="l";
- echo $hid->input();
- $User=new User($this->db);
+ /*!\brief verify that the data are correct before inserting or confirming
+ *\param an array (usually $_POST)
+ *\return String
+ *\throw Exception on error occurs
+ */
+ public function verify($p_array)
+ {
+ extract ($p_array);
+ /* check for a double reload */
+ if ( isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1',array($mt)) != 0 )
+ throw new Exception (_('Double Encodage'),5);
- $w=new ISelect();
- // filter on the current year
- $filter_year=" where p_exercice='".$User->get_exercice()."'";
-
- $periode_start=$this->db->make_array("select p_id,to_char(p_start,'DD-MM-YYYY') from parm_periode $filter_year order by p_start,p_end",1);
- // User is already set User=new User($this->db);
- $current=(isset($_GET['p_periode']))?$_GET['p_periode']:-1;
- $w->selected=$current;
+ /* check if we can write into this ledger */
+ $user=new User($this->db);
+ if ( $user->check_jrn($p_jrn) != 'W' )
+ throw new Exception (_('Accès interdit'),20);
+
+ /* check if there is a bank account linked to the ledger */
+ $bank_id=$this->get_bank();
+
+ if ($this->db->count()==0 )
+ throw new Exception("Ce journal n'a pas de compte en banque, allez dans paramètre->journal pour régler cela");
+ /* check if the accounting of the bank is correct */
+ $fBank=new Fiche($this->db,$bank_id);
+ $bank_accounting=$fBank->strAttribut(ATTR_DEF_ACCOUNT);
+ if ( trim($bank_accounting)=='' )
+ throw new Exception ('Le poste comptable du compte en banque de ce journal est invalide');
+
+ /* check if the account exists */
+ $poste=new Acc_Account_Ledger($this->db,$bank_accounting);
+ if ( $poste->load() == false )
+ throw new Exception ('Le poste comptable du compte en banque de ce journal est invalide');
+
+ /* check if the date is valid */
+ if ( isDate($e_date) == null )
+ {
+ throw new Exception('Date invalide', 2);
+ }
+ $oPeriode=new Periode($this->db);
+ if ($this->check_periode()==false)
+ {
+ $periode=$oPeriode->find_periode($e_date);
+ }
+ else
+ {
+ $oPeriode->p_id=$periode;
+ list ($min,$max)=$oPeriode->get_date_limit();
+ if ( cmpDate($e_date,$min) < 0 ||
+ cmpDate($e_date,$max) > 0)
+ throw new Exception(_('Date et periode ne correspondent pas'),6);
+ }
+
+ /* check if the periode is closed */
+ if ( $this->is_closed($periode)==1 )
+ {
+ throw new Exception(_('Periode fermee'),6);
+ }
+
+ /* check if we are using the strict mode */
+ if( $this->check_strict() == true)
+ {
+ /* if we use the strict mode, we get the date of the last
+ operation */
+ $last_date=$this->get_last_date();
+ if ( $last_date != null && cmpDate($e_date,$last_date) < 0 )
+ throw new Exception(_('Vous utilisez le mode strict la dernière operation est à la date du ')
+ .$last_date._(' vous ne pouvez pas encoder à une date antérieure'),15);
+
+ }
+
+ $acc_pay=new Acc_Operation($this->db);
+
+ $nb=0;
+ $tot_amount=0;
+ //----------------------------------------
+ // foreach item
+ //----------------------------------------
+ for ($i=0;$i< $nb_item;$i++)
+ {
+ if ( strlen(trim(${'e_other'.$i}))== 0) continue;
+ /* check if amount are numeric and */
+ if ( isNumber(${'e_other'.$i.'_amount'}) == 0 )
+ throw new Exception('La fiche '.${'e_other'.$i}.'a un montant invalide ['.${'e_other'.$i.'_amount'}.']',6);
+
+ /* compute the total */
+ $tot_amount+=round(${'e_other'.$i.'_amount'},2);
+ /* check if all card has a ATTR_DEF_ACCOUNT*/
+ $fiche=new Fiche($this->db);
+ $fiche->get_by_qcode(${'e_other'.$i});
+ if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
+ throw new Exception('La fiche '.${'e_other'.$i}.'n\'a pas de poste comptable',8);
+
+ $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
+ // if 2 accounts, take only the debit one for customer
+ if ( strpos($sposte,',') != 0 )
+ {
+ $array=explode(',',$sposte);
+ $poste_val=$array[1];
+ }
+ else
+ {
+ $poste_val=$sposte;
+ }
+ /* The account exists */
+ $poste=new Acc_Account_Ledger($this->db,$poste_val);
+ if ( $poste->load() == false )
+ {
+ throw new Exception('Pour la fiche '.${'e_other'.$i}.' le poste comptable ['.$poste->id.'n\'existe pas',9);
+ }
+ /* Check if the card belong to the ledger */
+ $fiche=new Fiche ($this->db);
+ $fiche->get_by_qcode(${'e_other'.$i});
+ if ( $fiche->belong_ledger($p_jrn,'deb') !=1 )
+ throw new Exception('La fiche '.${'e_other'.$i}.'n\'est pas accessible à ce journal',10);
+ $nb++;
+ }
+ if ( $nb == 0 )
+ throw new Exception('Il n\'y a aucune opération',12);
+
+ /* Check if the last_saldo and first_saldo are correct */
+ if ( strlen(trim($last_sold)) != 0 && isNumber($last_sold) &&
+ strlen(trim($first_sold)) != 0 && isNumber($first_sold))
+ {
+ $diff=$last_sold-$first_sold;
+ $diff=round($diff,2)-round($tot_amount,2);
+ if ( $first_sold != 0 && $last_sold !=0)
+ {
+ if ( $diff != 0 )
+ throw new Exception('Le montant de l\'extrait est incorrect'.
+ $tot_amount.' extrait '.$diff,13);
+ }
+ }
- echo JS_LEDGER;
- echo JS_PROTOTYPE;
- echo JS_AJAX_FICHE;
- echo '';
- echo 'Période '.$w->input("p_periode",$periode_start);
- $wLedger=$this->select_ledger('fin',3);
- if ($wLedger == null) exit (_('Pas de journal disponible'));
- if ( count($wLedger->value) > 1) {
- $aValue=$wLedger->value;
- $wLedger->value[0]=array('value'=>-1,'label'=>_('Tous les journaux financiers'));
- $idx=1;
- foreach ($aValue as $a) {
- $wLedger->value[$idx]=$a;
- $idx++;
- }
}
+ /*!\brief
+ *\param $p_array contains the value usually it is $_POST
+ *\return string with html code
+ *\note the form tag are not set here
+ */
+ function input($p_array=null)
+ {
+ if ( $p_array != null)
+ extract ($p_array);
+ $owner=new Own($this->db);
- echo 'Journal '.$wLedger->input();
- $w=new ICard();
- $w->noadd='no';
- $w->jrn=$this->id;
- $qcode=(isset($_GET['qcode']))?$_GET['qcode']:"";
- echo dossier::hidden();
- echo HtmlInput::hidden('p_action','bank');
- echo HtmlInput::hidden('sa','l');
- $w->name='qcode';
- $w->value=$qcode;
- $w->label='';
- $this->type='FIN';
- $all=$this->get_all_fiche_def();
- $w->extra=$all;
- $w->extra2='QuickCode';
- $sp=new ISpan();
- echo $sp->input("qcode_label","",$qcode);
- echo $w->input();
+ $pview_only=false;
+ $user = new User($this->db);
+ $f_add_button=new IButton('add_card');
+ $f_add_button->label=_('Créer une nouvelle fiche');
+ $f_add_button->set_attribute('ipopup','ipop_newcard');
+ $f_add_button->set_attribute('jrn',$this->id);
+ $f_add_button->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
+ $str_add_button=$f_add_button->input();
- echo HtmlInput::submit('gl_submit',_('Rechercher'));
- echo ' ';
+ // The first day of the periode
+ $pPeriode=new Periode($this->db);
+ list ($l_date_start,$l_date_end)=$pPeriode->get_date_limit($user->get_periode());
+ if ( $owner->MY_DATE_SUGGEST=='Y' )
+ $op_date=( ! isset($e_date) ) ?$l_date_start:$e_date;
+ else
+ $op_date=( ! isset($e_date) ) ?'':$e_date;
- // Show list of sell
- // Date - date of payment - Customer - amount
- if ( $current != -1 )
- {
- $filter_per=" and jr_tech_per=".$current;
- }
- else
- {
- $filter_per=" and jr_tech_per in (select p_id from parm_periode where p_exercice::integer=".
- $User->get_exercice().")";
- }
- /* security */
- if( $this->id != -1)
- $available_ledger=" and jr_def_id= ".$this->id." and ".$User->get_ledger_sql();
- else
- $available_ledger=" and ".$User->get_ledger_sql();
- // Show list of sell
- // Date - date of payment - Customer - amount
- $sql=SQL_LIST_ALL_INVOICE.$filter_per." and jr_def_type='FIN'".
- " $available_ledger" ;
- $step=$_SESSION['g_pagesize'];
- $page=(isset($_GET['offset']))?$_GET['page']:1;
- $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+ $r="";
- $l="";
-
- // check if qcode contains something
- if ( $qcode != "" )
- {
- // add a condition to filter on the quick code
- $l=" and jr_grpt_id in (select j_grpt from jrnx where j_qcode=upper('$qcode')) ";
- }
-
- list($max_line,$list)=ListJrn($this->db,"where jrn_def_type='FIN' $filter_per $l $available_ledger "
- ,null,$offset,0);
- $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
-
- echo " $bar";
- echo $list;
- echo "$bar ";
- }
- /**
- * return a string with the bank account, name and quick_code
- */
- function get_bank_name() {
- $bank_id=$this->db->get_value('select jrn_def_bank from jrn_def where jrn_def_id=$1',
- array($this->id));
- $fBank=new Fiche($this->db,$bank_id);
- $e_bank_account=" : ".$fBank->strAttribut(ATTR_DEF_BQ_NO);
- $e_bank_name=" : ".$fBank->strAttribut(ATTR_DEF_NAME);
- $e_bank_qcode=": ".$fBank->strAttribut(ATTR_DEF_QUICKCODE);
- return $e_bank_qcode.$e_bank_name.$e_bank_account;
- }
- /**
- *return the fiche_id of the bank
- */
- function get_bank() {
- $bank_id=$this->db->get_value('select jrn_def_bank from jrn_def where jrn_def_id=$1',
- array($this->id));
- return $bank_id;
- }
- /**
- *return true is we numbere each operation
- */
- function numb_operation() {
- $a=$this->db->get_value('select jrn_def_num_op from jrn_def where jrn_def_id=$1',
- array($this->id));
- if ($a==1) return true;
- return false;
- }
+ $r.=dossier::hidden();
+ $f_legend='Banque, caisse';
+ // Date
+ //--
+ $Date=new IDate("e_date",$op_date);
+ $Date->setReadOnly($pview_only);
+ $f_date=$Date->input();
+ $f_period='';
+ if ($this->check_periode() == true)
+ {
+ // Periode
+ //--
+ $l_user_per=(isset($periode))?$periode:$user->get_periode();
+ $period=new IPeriod();
+ $period->cn=$this->db;
+ $period->type=OPEN;
+ $period->value=$l_user_per;
+ $period->user=$user;
+ $period->name='periode';
+ try
+ {
+ $l_form_per=$period->input();
+ }
+ catch (Exception $e)
+ {
+ if ($e->getCode() == 1 )
+ {
+ echo "Aucune période ouverte";
+ exit();
+ }
+ }
+ $label=HtmlInput::infobulle(3);
+ $f_period="Période comptable $label".$l_form_per;
+ }
+
+ // Ledger (p_jrn)
+ //--
+ $add_js="";
+
+ if ( $owner->MY_PJ_SUGGEST == 'Y') $add_js="onchange='update_pj();update_bank();get_last_date();'";
+
+ $wLedger=$this->select_ledger('FIN',2);
+ $wLedger->javascript=$add_js;
+
+ if ($wLedger == null) exit ('Pas de journal disponible');
+
+ $label=" Journal ".HtmlInput::infobulle(2) ;
+ $f_jrn=$label.$wLedger->input();
+
+
+ // retrieve bank name, code and account from the jrn_def.jrn_def_bank
+
+ $f_bank=''.$this->get_bank_name().' ';
+
+ $f_legend_detail='Opérations financières';
+ //--------------------------------------------------
+ // Saldo begin end
+ //-------------------------------------------------
+ // Extrait
+ $default_pj='';
+ if ( $owner->MY_PJ_SUGGEST=='Y')
+ {
+ $default_pj=$this->guess_pj();
+ }
+ $wPJ=new IText('e_pj');
+ $wPJ->readonly=false;
+ $wPJ->size=10;
+ $wPJ->value=(isset($e_pj))?$e_pj:$default_pj;
+
+ $f_extrait=$wPJ->input().HtmlInput::hidden('e_pj_suggest',$default_pj);
+ $label=HtmlInput::infobulle(7);
+
+ $first_sold=(isset($first_sold))?$first_sold:"";
+ $wFirst=new INum('first_sold',$first_sold);
+
+ $last_sold= isset($last_sold)?$last_sold:"";
+ $wLast=new INum('last_sold',$last_sold);
+
+
+ $max=(isset($nb_item))?$nb_item:MAX_ARTICLE;
+
+ $r.= HtmlInput::hidden('nb_item',$max);
+ //--------------------------------------------------
+ // financial operation
+ //-------------------------------------------------
+
+ $array=array();
+ // Parse each " tiers"
+ for ($i=0; $i < $max; $i++)
+ {
+ $tiers=(isset(${"e_other".$i}))?${"e_other".$i}:""
+ ;
+ $tiers_label="";
+ $tiers_amount=(isset(${"e_other$i"."_amount"}))?round(${"e_other$i"."_amount"},2):0;
+
+ $tiers_comment=(isset (${"e_other$i"."_comment"}))?${"e_other$i"."_comment"}:""
+ ;
+ // If $tiers has a value
+ if ( $tiers != "" )
+ {
+ $fTiers=new Fiche($this->db);
+ $fTiers->get_by_qcode($tiers);
+
+ $tiers_label=$fTiers->strAttribut(ATTR_DEF_NAME);
+
+ }
+ ${"e_other$i"."_amount"}=(isset (${"e_other$i"."_amount"}))?${"e_other$i"."_amount"}:
+ 0;
+
+ $W1=new ICard();
+ $W1->label="";
+ $W1->name="e_other".$i;
+ $W1->value=$tiers;
+ $W1->extra='deb'; // credits
+ $W1->typecard='deb';
+ $W1->set_dblclick("fill_ipopcard(this);");
+ $W1->set_attribute('ipopup','ipopcard');
+
+ // name of the field to update with the name of the card
+ $W1->set_attribute('label','e_other'.$i.'_label');
+ // name of the field to update with the name of the card
+ $W1->set_attribute('typecard','filter');
+ // Add the callback function to filter the card on the jrn
+ $W1->set_callback('filter_card');
+ $W1->set_function('fill_data');
+ $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+ $W1->name);
+ $W1->readonly=$pview_only;
+ $array[$i]['qcode']=$W1->input();
+ $array[$i]['search']=$W1->search();
+
+ // label
+ $other=new ISpan("e_other$i"."_label", $tiers_label);
+ $array[$i]['span']=$other->input();
+ // Comment
+ $wComment=new IText("e_other$i"."_comment",$tiers_comment);
+
+ $wComment->size=35;
+ $wComment->setReadOnly($pview_only);
+ $array[$i]['comment']=$wComment->input();
+ // amount
+ $wAmount=new INum("e_other$i"."_amount",$tiers_amount);
+
+ $wAmount->size=7;
+ $wAmount->setReadOnly($pview_only);
+ $array[$i]['amount']=$wAmount->input();
+ // concerned
+ ${"e_concerned".$i}=(isset(${"e_concerned".$i}))?${"e_concerned".$i}:""
+ ;
+ $wConcerned=new IConcerned("e_concerned".$i,${"e_concerned".$i});
+ $wConcerned->setReadOnly($pview_only);
+ $wConcerned->extra=0;
+
+ $wConcerned->extra2='paid';
+ $array[$i]['concerned']=$wConcerned->input();
+ }
+
+ ob_start();
+ require_once('template/form_ledger_fin.php');
+ $r.=ob_get_contents();
+ ob_clean();
+
+
+ return $r;
+
+ }
+ /*!\brief show the summary before inserting into the database, it
+ *calls the function for adding a attachment. The function verify
+ *should be called before
+ *\param $p_array an array usually is $_POST
+ *\return string with code html
+ */
+ public function confirm($p_array)
+ {
+ $r="";
+ bcscale(2);
+ extract ($p_array);
+ $pPeriode=new Periode($this->db);
+ if ($this->check_periode() == true)
+ {
+ $pPeriode->p_id=$periode;
+ }
+ else
+ {
+ $pPeriode->find_periode($e_date);
+ }
+
+ list ($l_date_start,$l_date_end)=$pPeriode->get_date_limit();
+ $exercice=$pPeriode->get_exercice();
+ $r.='';
+ $r.='Banque, caisse ';
+ $r.='';
+ // Date
+ //--
+ $r.="";
+ $r.=' Date : '.$e_date;
+ // Periode
+ //--
+ $r.=" ";
+ $r.="Période comptable ";
+ $r.=$l_date_start.' - '.$l_date_end;
+ $r.=" ";
+ $r.=" ";
+ // Ledger (p_jrn)
+ //--
+ $r.='';
+ $r.=' Journal ';
+ $this->id=$p_jrn;
+ $r.='';
+ $r.=h($this->get_name());
+ $r.=' ';
+ $r.=' ';
+
+ //retrieve bank name
+ $bk_id=$this->get_bank();
+
+ $fBank=new Fiche($this->db,$bk_id);
+ $e_bank_account_label=$this->get_bank_name();
+
+ $filter_year=" j_tech_per in (select p_id from parm_periode where p_exercice='".$exercice."')";
+
+ $acc_account=new Acc_Account_Ledger($this->db,$fBank->strAttribut(ATTR_DEF_ACCOUNT));
+ $solde=$acc_account->get_solde($filter_year);
+ $new_solde=$solde;
+
+ $r.=" Banque ";
+ $r.=$e_bank_account_label;
+
+ $r.="
";
+
+ $r.=' ';
+
+ $r.='Opérations financières ';
+ //--------------------------------------------------
+ // Saldo begin end
+ //-------------------------------------------------
+ $r.='Extrait de compte ';
+ $r.='';
+ $r.='';
+ // Extrait
+ //--
+ $r.=' Numéro d\'extrait '.h($e_pj);
+ $r.='Solde début extrait ';
+ $r.=''.$first_sold.' ';
+ $r.='Solde fin extrait ';
+ $r.=''.$last_sold.' ';
+ $r.='
';
+ $r.=' ';
+
+ //--------------------------------------------------
+ // financial operation
+ //-------------------------------------------------
+ $r.='';
+ $r.="";
+ $r.="code ";
+ $r.="Commentaire ";
+ $r.="Montant ";
+ $r.=' Op. Concernée(s) ';
+ $r.=" ";
+ // Parse each " tiers"
+ $tot_amount=0;
+ //--------------------------------------------------
+ // For each items
+ //--------------------------------------------------
+ for ($i=0; $i < $nb_item; $i++)
+ {
+
+ $tiers=(isset(${"e_other".$i}))?${"e_other".$i}:""
+ ;
+
+ if ( strlen(trim($tiers))==0)continue;
+ $tiers_label="";
+ $tiers_amount=round(${"e_other$i"."_amount"},2);
+ $tot_amount=bcadd($tot_amount,$tiers_amount);
+ $tiers_comment=h(${"e_other$i"."_comment"});
+ // If $tiers has a value
+ $fTiers=new Fiche($this->db);
+ $fTiers->get_by_qcode($tiers);
+
+ $tiers_label=$fTiers->strAttribut(ATTR_DEF_NAME);
+
+ $r.="".${'e_other'.$i}." ";
+ // label
+ $other=new ISpan();
+ $r.='';
+ $r.=$fTiers->strAttribut(ATTR_DEF_NAME);
+ $r.=' ';
+ // Comment
+ $r.=''.$tiers_comment.' ';
+ // amount
+ $r.=''.$tiers_amount.' ';
+ // concerned
+ $r.='';
+ $r.=${"e_concerned".$i};
+ $r.=' ';
+ $r.=' ';
+ }
+ $r.="
";
+
+ // saldo
+ $r.=' Ancien solde = '.$solde;
+ $new_solde+=$tot_amount;
+ $r.=' Nouveau solde = '.$new_solde;
+ $r.=' Difference ='.$tot_amount;
+ // check for upload piece
+ $file=new IFile();
+
+ $r.=" Ajoutez une pièce justificative ";
+ $r.=$file->input("pj","");
+
+ $r.=' ';
+ //--------------------------------------------------
+ // Hidden variables
+ //--------------------------------------------------
+ $r.=dossier::hidden();
+ $r.=HtmlInput::hidden('p_jrn',$this->id);
+ $r.=HtmlInput::hidden('nb_item',$nb_item);
+ $r.=HtmlInput::hidden('last_sold',$last_sold);
+ $r.=HtmlInput::hidden('first_sold',$first_sold);
+ $r.=HtmlInput::hidden('e_pj',$e_pj);
+ $r.=HtmlInput::hidden('e_pj_suggest',$e_pj_suggest);
+ $r.=HtmlInput::hidden('e_date',$e_date);
+ $mt=microtime(true);
+ $r.=HtmlInput::hidden('mt',$mt);
+
+ if (isset($periode)) $r.=HtmlInput::hidden('periode',$periode);
+ $r.=dossier::hidden();
+ $r.=HtmlInput::hidden('sa','n');
+ for ($i=0; $i < $nb_item; $i++)
+ {
+ $tiers=(isset(${"e_other".$i}))?${"e_other".$i}:""
+ ;
+ $r.=HtmlInput::hidden('e_other'.$i,$tiers);
+ $r.=HtmlInput::hidden('e_other'.$i.'_comment',${'e_other'.$i.'_comment'});
+ $r.=HtmlInput::hidden('e_other'.$i.'_amount',${'e_other'.$i.'_amount'});
+ $r.=HtmlInput::hidden('e_concerned'.$i,${'e_concerned'.$i});
+ }
+
+ return $r;
+ }
+ /*!\brief save the data into the database, included the attachment,
+ *and the reconciliations
+ *\param $p_array usually $_POST
+ *\return string with HTML code
+ */
+ public function insert($p_array)
+ {
+ $internal_code="";
+ $oid=0;
+ extract ($p_array);
+ $ret='';
+ // Debit = banque
+ $bank_id=$this->get_bank();
+ $fBank=new Fiche($this->db,$bank_id);
+ $e_bank_account=$fBank->strAttribut(ATTR_DEF_QUICKCODE);
+
+ // Get the saldo
+ $pPeriode=new Periode($this->db);
+ if ( $this->check_periode() == true )
+ {
+ $pPeriode->p_id=$periode;
+ }
+ else
+ {
+ $pPeriode->find_periode($e_date);
+ }
+ $exercice=$pPeriode->get_exercice();
+
+ $filter_year=" j_tech_per in (select p_id from parm_periode where p_exercice='".$exercice."')";
+ $sposte=$fBank->strAttribut(ATTR_DEF_ACCOUNT);
+ // if 2 accounts, take only the debit one for customer
+ if ( strpos($sposte,',') != 0 )
+ {
+ $array=explode(',',$sposte);
+ $poste_val=$array[0];
+ }
+ else
+ {
+ $poste_val=$sposte;
+ }
+
+ $acc_account=new Acc_Account_Ledger($this->db,$poste_val);
+ $solde=$acc_account->get_solde($filter_year);
+ $new_solde=$solde;
+
+ try
+ {
+ $this->db->start();
+ $amount=0.0;
+ $idx_operation=0;
+ $ret='';
+ $ret.=tr(th('Quick Code').th('Nom').th('Libellé').th('Montant'));
+ // Credit = goods
+ for ( $i = 0; $i < $nb_item;$i++)
+ {
+ // if tiers is set and amount != 0 insert it into the database
+ // and quit the loop ?
+ if ( strlen(trim(${"e_other$i"}))==0 ) continue;
+ $fPoste=new Fiche($this->db);
+ $fPoste->get_by_qcode(${"e_other$i"});
+
+ // round it
+ ${"e_other$i"."_amount"}=round( ${"e_other$i"."_amount"},2);
+
+ // Compute display
+ $row=td(${"e_other$i"}).td($fPoste->strAttribut(ATTR_DEF_NAME)).td(${"e_other".$i."_comment"}).td(${"e_other$i"."_amount"},'class="num"');
+
+ $ret.=tr($row);
+
+ $amount+=${"e_other$i"."_amount"};
+ // Record a line for the bank
+ // Compute the j_grpt
+ $seq=$this->db->get_next_seq('s_grpt');
+
+ $acc_operation=new Acc_Operation($this->db);
+ $acc_operation->date=$e_date;
+ $sposte=$fPoste->strAttribut(ATTR_DEF_ACCOUNT);
+ // if 2 accounts
+ if ( strpos($sposte,',') != 0 )
+ {
+ $array=explode(',',$sposte);
+ if ( ${"e_other$i"."_amount"} < 0 )
+ $poste_val=$array[1];
+ else
+ $poste_val=$array[0];
+ }
+ else
+ {
+ $poste_val=$sposte;
+ }
+
+
+ $acc_operation->poste=$poste_val;
+ $acc_operation->amount=${"e_other$i"."_amount"}*(-1);
+ $acc_operation->grpt=$seq;
+ $acc_operation->jrn=$p_jrn;
+ $acc_operation->type='d';
+
+ if ( isset($periode))
+ $tperiode=$periode;
+ else
+ {
+ $per=new Periode($this->db);
+ $tperiode=$per->find_periode($e_date);
+
+ }
+ $acc_operation->periode=$tperiode;
+ $acc_operation->qcode=${"e_other".$i};
+ $acc_operation->insert_jrnx();
+
+ $acc_operation=new Acc_Operation($this->db);
+ $acc_operation->date=$e_date;
+ $sposte=$fBank->strAttribut(ATTR_DEF_ACCOUNT);
+
+ // if 2 accounts
+ if ( strpos($sposte,',') != 0 )
+ {
+ $array=explode(',',$sposte);
+ if ( ${"e_other$i"."_amount"} < 0 )
+ $poste_val=$array[1];
+ else
+ $poste_val=$array[0];
+ }
+ else
+ {
+ $poste_val=$sposte;
+ }
+
+ $acc_operation->poste=$poste_val;
+ $acc_operation->amount=${"e_other$i"."_amount"};
+ $acc_operation->grpt=$seq;
+ $acc_operation->jrn=$p_jrn;
+ $acc_operation->type='d';
+ $acc_operation->periode=$tperiode;
+ $acc_operation->qcode=$e_bank_account;
+ $acc_operation->insert_jrnx();
+
+
+ if ( FormatString(${"e_other$i"."_comment"}) == null )
+ {
+ // if comment is blank set a default one
+ $comment=" compte : ".$fBank->strAttribut(ATTR_DEF_NAME).' a '.
+ $fPoste->strAttribut(ATTR_DEF_NAME);
+ }
+ else
+ {
+ $comment=${'e_other'.$i.'_comment'};
+ }
+
+
+ $acc_operation=new Acc_Operation($this->db);
+ $acc_operation->jrn=$p_jrn;
+ $acc_operation->amount=abs(${"e_other$i"."_amount"});
+ $acc_operation->date=$e_date;
+ $acc_operation->desc=$comment;
+ $acc_operation->grpt=$seq;
+ $acc_operation->periode=$tperiode;
+ $acc_operation->mt=$mt;
+ $idx_operation++;
+ $acc_operation->pj='';
+
+ if ( trim($e_pj) != '' && $this->numb_operation()==true)
+ $acc_operation->pj=$e_pj.str_pad($idx_operation,3,0,STR_PAD_LEFT);
+
+ if ( trim($e_pj) != '' && $this->numb_operation()==false)
+ $acc_operation->pj=$e_pj;
+
+ $jr_id=$acc_operation->insert_jrn();
+ // $acc_operation->set_pj();
+ $this->db->exec_sql('update jrn set jr_pj_number=$1 where jr_id=$2',
+ array($acc_operation->pj,$jr_id));
+ $internal=$this->compute_internal_code($seq);
+
+
+ if ( trim(${"e_concerned".$i}) != "" )
+ {
+ if ( strpos(${"e_concerned".$i},',') != 0 )
+ {
+ $aRapt=explode(',',${"e_concerned".$i});
+ foreach ($aRapt as $rRapt)
+ {
+ // Add a "concerned operation to bound these op.together
+ //
+ $rec=new Acc_Reconciliation ($this->db);
+ $rec->set_jr_id($jr_id);
+
+ if ( isNumber($rRapt) == 1 )
+ {
+ $rec->insert($rRapt);
+ }
+ }
+ }
+ else
+ if ( isNumber(${"e_concerned".$i}) == 1 )
+ {
+ $rec=new Acc_Reconciliation ($this->db);
+ $rec->set_jr_id($jr_id);
+ $rec->insert(${"e_concerned$i"});
+ }
+ }
+
+ // Set Internal code
+ $this->grpt_id=$seq;
+ /**
+ * save also into quant_fin
+ */
+ $sql="INSERT INTO quant_fin(
+ qf_bank, jr_id, qf_other, qf_amount)
+ VALUES ($1, $2, $3, $4);";
+
+ $this->db->exec_sql($sql,array($fBank->id,$jr_id,$fPoste->id,${"e_other$i"."_amount"}));
+
+ $this->update_internal_code($internal);
+
+
+
+ if ( $i == 0 )
+ {
+ // first record we upload the files and
+ // keep variable to update other row of jrn
+ if ( isset ($_FILES))
+ $oid=$this->db->save_upload_document($seq);
+
+ }
+ else
+ {
+ if ( $oid != 0 )
+ {
+ $this->db->exec_sql("update jrn set jr_pj=".$oid.", jr_pj_name='".$_FILES['pj']['name']."', ".
+ "jr_pj_type='".$_FILES['pj']['type']."' where jr_grpt_id=$seq");
+ }
+ }
+
+ } // for nbitem
+ // increment pj
+ if ( strlen(trim($e_pj)) !=0 )
+ {
+ $this->inc_seq_pj();
+ }
+ $ret.='
';
+ }
+ catch (Exception $e)
+ {
+ echo ''.
+ 'Erreur dans l\'enregistrement '.
+ __FILE__.':'.__LINE__.' '.
+ $e->getMessage();
+ $this->db->rollback();
+ exit();
+
+ }
+ $this->db->commit();
+ $r="";
+ $r.=" Ancien solde ".$solde;
+ $new_solde+=$amount;
+ $r.=" Nouveau solde ".$new_solde;
+ $ret.=$r;
+ return $ret;
+ }
+ /*!\brief display operation of a FIN ledger
+ *\return html code into a string
+ */
+ function show_ledger()
+ {
+ echo dossier::hidden();
+ $hid=new IHidden();
+
+ $hid->name="p_action";
+ $hid->value="bank";
+ echo $hid->input();
+
+
+ $hid->name="sa";
+ $hid->value="l";
+ echo $hid->input();
+
+ $User=new User($this->db);
+
+ $w=new ISelect();
+ // filter on the current year
+ $filter_year=" where p_exercice='".$User->get_exercice()."'";
+
+ $periode_start=$this->db->make_array("select p_id,to_char(p_start,'DD-MM-YYYY') from parm_periode $filter_year order by p_start,p_end",1);
+ // User is already set User=new User($this->db);
+ $current=(isset($_GET['p_periode']))?$_GET['p_periode']:-1;
+ $w->selected=$current;
+
+ echo JS_LEDGER;
+ echo JS_PROTOTYPE;
+ echo JS_AJAX_FICHE;
+ echo '';
+ echo 'Période '.$w->input("p_periode",$periode_start);
+ $wLedger=$this->select_ledger('fin',3);
+ if ($wLedger == null) exit (_('Pas de journal disponible'));
+ if ( count($wLedger->value) > 1)
+ {
+ $aValue=$wLedger->value;
+ $wLedger->value[0]=array('value'=>-1,'label'=>_('Tous les journaux financiers'));
+ $idx=1;
+ foreach ($aValue as $a)
+ {
+ $wLedger->value[$idx]=$a;
+ $idx++;
+ }
+ }
+
+
+
+ echo 'Journal '.$wLedger->input();
+ $w=new ICard();
+ $w->noadd='no';
+ $w->jrn=$this->id;
+ $qcode=(isset($_GET['qcode']))?$_GET['qcode']:"";
+ echo dossier::hidden();
+ echo HtmlInput::hidden('p_action','bank');
+ echo HtmlInput::hidden('sa','l');
+ $w->name='qcode';
+ $w->value=$qcode;
+ $w->label='';
+ $this->type='FIN';
+ $all=$this->get_all_fiche_def();
+ $w->extra=$all;
+ $w->extra2='QuickCode';
+ $sp=new ISpan();
+ echo $sp->input("qcode_label","",$qcode);
+ echo $w->input();
+
+ echo HtmlInput::submit('gl_submit',_('Rechercher'));
+ echo ' ';
+
+ // Show list of sell
+ // Date - date of payment - Customer - amount
+ if ( $current != -1 )
+ {
+ $filter_per=" and jr_tech_per=".$current;
+ }
+ else
+ {
+ $filter_per=" and jr_tech_per in (select p_id from parm_periode where p_exercice::integer=".
+ $User->get_exercice().")";
+ }
+ /* security */
+ if( $this->id != -1)
+ $available_ledger=" and jr_def_id= ".$this->id." and ".$User->get_ledger_sql();
+ else
+ $available_ledger=" and ".$User->get_ledger_sql();
+ // Show list of sell
+ // Date - date of payment - Customer - amount
+ $sql=SQL_LIST_ALL_INVOICE.$filter_per." and jr_def_type='FIN'".
+ " $available_ledger" ;
+ $step=$_SESSION['g_pagesize'];
+ $page=(isset($_GET['offset']))?$_GET['page']:1;
+ $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+
+ $l="";
+
+ // check if qcode contains something
+ if ( $qcode != "" )
+ {
+ // add a condition to filter on the quick code
+ $l=" and jr_grpt_id in (select j_grpt from jrnx where j_qcode=upper('$qcode')) ";
+ }
+
+ list($max_line,$list)=ListJrn($this->db,"where jrn_def_type='FIN' $filter_per $l $available_ledger "
+ ,null,$offset,0);
+ $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
+
+ echo " $bar";
+ echo $list;
+ echo "$bar ";
+ }
+ /**
+ * return a string with the bank account, name and quick_code
+ */
+ function get_bank_name()
+ {
+ $bank_id=$this->db->get_value('select jrn_def_bank from jrn_def where jrn_def_id=$1',
+ array($this->id));
+ $fBank=new Fiche($this->db,$bank_id);
+ $e_bank_account=" : ".$fBank->strAttribut(ATTR_DEF_BQ_NO);
+ $e_bank_name=" : ".$fBank->strAttribut(ATTR_DEF_NAME);
+ $e_bank_qcode=": ".$fBank->strAttribut(ATTR_DEF_QUICKCODE);
+ return $e_bank_qcode.$e_bank_name.$e_bank_account;
+ }
+ /**
+ *return the fiche_id of the bank
+ */
+ function get_bank()
+ {
+ $bank_id=$this->db->get_value('select jrn_def_bank from jrn_def where jrn_def_id=$1',
+ array($this->id));
+ return $bank_id;
+ }
+ /**
+ *return true is we numbere each operation
+ */
+ function numb_operation()
+ {
+ $a=$this->db->get_value('select jrn_def_num_op from jrn_def where jrn_def_id=$1',
+ array($this->id));
+ if ($a==1) return true;
+ return false;
+ }
}
diff --git a/include/class_acc_ledger_info.php b/include/class_acc_ledger_info.php
index 1190c8cb6..737f633c8 100644
--- a/include/class_acc_ledger_info.php
+++ b/include/class_acc_ledger_info.php
@@ -1,29 +1,29 @@
cn=$p_cn;
- $this->ji_id=$p_ji_id;
- }
- function insert() {
- if ( ! isset ($this->jr_id) ||
- ! isset ($this->ji_value) ||
- ! isset ($this->id_type ) )
- {
- echo 'Appel incorrecte '.__FILE__.__LINE__;
- var_dump($this);
- exit();
- }
- try {
- $sql=$this->cn->exec_sql('insert into jrn_info(jr_id,id_type,ji_value) values ($1,$2,$3)'.
- ' returning ji_id ',
- array ($this->jr_id,$this->id_type,$this->ji_value)
- );
- $this->ji_id=Database::fetch_result($sql,0,0);
- } catch (Exception $e) {
- echo "Echec sauvegarde info additionnelles";
- throw $e;
+class Acc_Ledger_Info
+{
+ var $cn; /*!< connection */
+ var $ji_id; /*!< primary key */
+ var $id_type; /*!< type id */
+ var $jr_id; /*!< primary key of the table jrn */
+ var $ji_value; /*!< value for this */
+ function __construct($p_cn,$p_ji_id=0)
+ {
+ $this->cn=$p_cn;
+ $this->ji_id=$p_ji_id;
}
- }
- function update() {
- if ( ! isset ($this->jr_id) ||
- ! isset ($this->ji_value) ||
- ! isset ($this->jr_id ) )
- {
- echo 'Appel incorrecte '.__FILE__.__LINE__;
- var_dump($this);
- exit();
- }
- try {
- $sql=$this->exec_sql('update jrn_info set jr_id=$1 ,id_type=$2,ji_value=$3 where ji_id=$4)'.
- array ($this->jr_id,$this->id_type,$this->ji_value,$this->ji_id)
- );
- } catch (Exception $e) {
- $this->cn->rollback();
- echo "Echec sauvegarde info additionnelles";
- throw $e;
+ function insert()
+ {
+ if ( ! isset ($this->jr_id) ||
+ ! isset ($this->ji_value) ||
+ ! isset ($this->id_type ) )
+ {
+ echo 'Appel incorrecte '.__FILE__.__LINE__;
+ var_dump($this);
+ exit();
+ }
+ try
+ {
+ $sql=$this->cn->exec_sql('insert into jrn_info(jr_id,id_type,ji_value) values ($1,$2,$3)'.
+ ' returning ji_id ',
+ array ($this->jr_id,$this->id_type,$this->ji_value)
+ );
+ $this->ji_id=Database::fetch_result($sql,0,0);
+ }
+ catch (Exception $e)
+ {
+ echo "Echec sauvegarde info additionnelles";
+ throw $e;
+ }
}
- }
- function load() {
- $sql="select jr_id,id_type,ji_value from jrn_info where ji_id=".$this->ji_id;
- $r=$this->cn->exec_sql($sql);
- if (Database::num_row ($r) > 0 ) {
- $this->from_array(Database::fetch_array($r,0));
- return 0;
- }else {
- return 1;
+ function update()
+ {
+ if ( ! isset ($this->jr_id) ||
+ ! isset ($this->ji_value) ||
+ ! isset ($this->jr_id ) )
+ {
+ echo 'Appel incorrecte '.__FILE__.__LINE__;
+ var_dump($this);
+ exit();
+ }
+ try
+ {
+ $sql=$this->exec_sql('update jrn_info set jr_id=$1 ,id_type=$2,ji_value=$3 where ji_id=$4)'.
+ array ($this->jr_id,$this->id_type,$this->ji_value,$this->ji_id)
+ );
+ }
+ catch (Exception $e)
+ {
+ $this->cn->rollback();
+ echo "Echec sauvegarde info additionnelles";
+ throw $e;
+ }
}
-
- }
- function from_array($p_array) {
- foreach ($p_array as $col=>$value) {
- $this->$col=$value;
- }
- }
- function set_id($p_ji_id) {
- $this->$ji_id=$p_ji_id;
- }
- function set_jrn_id($p_id) {
- $this->jr_id=$p_id;
- }
- function set_type($p_id) {
- $this->id_type=$p_id;
- }
- function set_value($p_id) {
- $this->ji_value=$p_id;
- }
- /*!\brief load all the jrn_info thanks the jr_id
- * \return an array of object
- */
- function load_all() {
- if ( ! isset ($this->jr_id) ) { echo "jr_id is not set ".__FILE__.__LINE__;exit();}
+ function load()
+ {
+ $sql="select jr_id,id_type,ji_value from jrn_info where ji_id=".$this->ji_id;
+ $r=$this->cn->exec_sql($sql);
+ if (Database::num_row ($r) > 0 )
+ {
+ $this->from_array(Database::fetch_array($r,0));
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
- $sql="select ji_id from jrn_info where jr_id=".$this->jr_id;
- $r=$this->cn->exec_sql($sql);
- if (Database::num_row($r) == 0 )
- return array();
- $array=Database::fetch_all($r);
- $ret=array();
- foreach ($array as $row) {
- $o=new Acc_Ledger_Info($this->cn,$row['ji_id']);
- $o->load();
- $ret[]=clone $o;
- }
- return $ret;
-
- }
- function count() {
- $sql="select ji_id from jrn_info where jr_id=".$this->jr_id;
- return $this->cn->count_sql($sql);
- }
- function search_id_internal($p_internal) {
- $sql="select jr_id from jrn where jr_internal='$p_internal'";
- $r=$this->cn->exec_sql($sql);
- if (Database::num_row($r) > 0 ) {
- $this->jr_id=Database::fetch_result($r,0,0);
- return $this->jr_id;
- } else {
- $this->jr_id=-1;
- return $this->jr_id;
}
- }
- /**
- *@brief save all extra information in once, called by compta_ven and compta_ach
- *@param $p_jr_id is the jrn.jr_id concerned,
- *@param $p_array is the array with the data usually it is $_POST
- *@note will change this->jr_id
- *@see compta_ven.inc.php compta_ach.inc.php
- */
- function save_extra($p_jr_id,$p_array) {
- $this->jr_id=$p_jr_id;
- if (strlen(trim($p_array['bon_comm'] )) != 0 ) {
- $this->set_type('BON_COMMANDE');
- $this->set_value($p_array['bon_comm']);
- $this->insert();
- }
- if (strlen(trim($p_array['other_info'] )) != 0 ) {
- $this->set_type('OTHER');
- $this->set_value($p_array['other_info']);
- $this->insert();
- }
- }
- static function test_me() {
- echo "Dossier = ".Dossier::id();
- $cn=new Database(Dossier::id());
- $a=new Acc_Ledger_Info($cn);
- $a->jr_id=3;
- $a->id_type='BON_COMMANDE';
- $a->ji_value='BON';
- var_dump($a);
- $a->insert();
+ function from_array($p_array)
+ {
+ foreach ($p_array as $col=>$value)
+ {
+ $this->$col=$value;
+ }
+ }
+ function set_id($p_ji_id)
+ {
+ $this->$ji_id=$p_ji_id;
+ }
+ function set_jrn_id($p_id)
+ {
+ $this->jr_id=$p_id;
+ }
+ function set_type($p_id)
+ {
+ $this->id_type=$p_id;
+ }
+ function set_value($p_id)
+ {
+ $this->ji_value=$p_id;
+ }
+ /*!\brief load all the jrn_info thanks the jr_id
+ * \return an array of object
+ */
+ function load_all()
+ {
+ if ( ! isset ($this->jr_id) )
+ {
+ echo "jr_id is not set ".__FILE__.__LINE__;
+ exit();
+ }
- $a->set_jrn_id(7);
- $a->set_type('OTHER');
- $a->set_value('Autre test');
- $a->insert();
- }
+ $sql="select ji_id from jrn_info where jr_id=".$this->jr_id;
+ $r=$this->cn->exec_sql($sql);
+ if (Database::num_row($r) == 0 )
+ return array();
+ $array=Database::fetch_all($r);
+ $ret=array();
+ foreach ($array as $row)
+ {
+ $o=new Acc_Ledger_Info($this->cn,$row['ji_id']);
+ $o->load();
+ $ret[]=clone $o;
+ }
+ return $ret;
+
+ }
+ function count()
+ {
+ $sql="select ji_id from jrn_info where jr_id=".$this->jr_id;
+ return $this->cn->count_sql($sql);
+ }
+ function search_id_internal($p_internal)
+ {
+ $sql="select jr_id from jrn where jr_internal='$p_internal'";
+ $r=$this->cn->exec_sql($sql);
+ if (Database::num_row($r) > 0 )
+ {
+ $this->jr_id=Database::fetch_result($r,0,0);
+ return $this->jr_id;
+ }
+ else
+ {
+ $this->jr_id=-1;
+ return $this->jr_id;
+ }
+ }
+ /**
+ *@brief save all extra information in once, called by compta_ven and compta_ach
+ *@param $p_jr_id is the jrn.jr_id concerned,
+ *@param $p_array is the array with the data usually it is $_POST
+ *@note will change this->jr_id
+ *@see compta_ven.inc.php compta_ach.inc.php
+ */
+ function save_extra($p_jr_id,$p_array)
+ {
+ $this->jr_id=$p_jr_id;
+ if (strlen(trim($p_array['bon_comm'] )) != 0 )
+ {
+ $this->set_type('BON_COMMANDE');
+ $this->set_value($p_array['bon_comm']);
+ $this->insert();
+ }
+ if (strlen(trim($p_array['other_info'] )) != 0 )
+ {
+ $this->set_type('OTHER');
+ $this->set_value($p_array['other_info']);
+ $this->insert();
+ }
+ }
+ static function test_me()
+ {
+ echo "Dossier = ".Dossier::id();
+ $cn=new Database(Dossier::id());
+ $a=new Acc_Ledger_Info($cn);
+ $a->jr_id=3;
+ $a->id_type='BON_COMMANDE';
+ $a->ji_value='BON';
+ var_dump($a);
+ $a->insert();
+
+ $a->set_jrn_id(7);
+ $a->set_type('OTHER');
+ $a->set_value('Autre test');
+ $a->insert();
+ }
}
diff --git a/include/class_acc_ledger_purchase.php b/include/class_acc_ledger_purchase.php
index d897c5b22..62c69ce91 100644
--- a/include/class_acc_ledger_purchase.php
+++ b/include/class_acc_ledger_purchase.php
@@ -45,1329 +45,1440 @@ require_once('class_acc_ledger_info.php');
*
*
*/
-class Acc_Ledger_Purchase extends Acc_Ledger {
- function __construct ($p_cn,$p_init) {
- $this->type='ACH';
- parent::__construct($p_cn,$p_init);
- }
- /*!\brief verify that the data are correct before inserting or confirming
- *\param an array (usually $_POST)
- *\return String
- *\throw Exception if an error occurs
- */
- public function verify($p_array) {
- extract ($p_array);
- /* check if we can write into this ledger */
- $user=new User($this->db);
- if ( $user->check_jrn($p_jrn) != 'W' )
- throw new Exception (_('Accès interdit'),20);
-
-
- /* check for a double reload */
- if ( isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1',array($mt)) != 0 )
- throw new Exception (_('Double Encodage'),5);
-
- /* check if there is a customer */
- if ( strlen(trim($e_client)) == 0 )
- throw new Exception(_('Vous n\'avez pas donné de fournisseur'),11);
-
- /* check if the date is valid */
- if ( isDate($e_date) == null ) {
- throw new Exception(_('Date invalide'), 2);
+class Acc_Ledger_Purchase extends Acc_Ledger
+{
+ function __construct ($p_cn,$p_init)
+ {
+ $this->type='ACH';
+ parent::__construct($p_cn,$p_init);
}
- $oPeriode=new Periode($this->db);
- if ( $this->check_periode() == false) {
- $tperiode=$oPeriode->find_periode($e_date);
- }else {
- $tperiode=$period;
- $oPeriode->p_id=$tperiode;
- /* check that the datum is in the choosen periode */
- list ($min,$max)=$oPeriode->get_date_limit($tperiode);
- if ( cmpDate($e_date,$min) < 0 ||
- cmpDate($e_date,$max) > 0)
- throw new Exception(_('Date et periode ne correspondent pas'),6);
- }
- /* check if the periode is closed */
- if ( $this->is_closed($tperiode)==1 )
- {
- throw new Exception(_('Periode fermee'),6);
- }
-
- /* check if we are using the strict mode */
- if( $this->check_strict() == true) {
- /* if we use the strict mode, we get the date of the last
- operation */
- $last_date=$this->get_last_date();
- if ( $last_date != null && cmpDate($e_date,$last_date) < 0 )
- throw new Exception(_('Vous utilisez le mode strict la dernière operation est à la date du ')
- .$last_date._(' vous ne pouvez pas encoder à une '.
- ' date antérieure dans ce journal'),13);
-
- }
-
- /* check the account */
- $fiche=new Fiche($this->db);
- $fiche->get_by_qcode($e_client);
-
- if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
- throw new Exception(_('La fiche ').$e_client._('n\'a pas de poste comptable'),8);
-
- /* get the account and explode if necessary */
- $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
- // if 2 accounts, take only the credit one for supplier
- if ( strpos($sposte,',') != 0 ) {
- $array=explode(',',$sposte);
- $poste_val=$array[1];
- } else {
- $poste_val=$sposte;
- }
-
- /* The account exists */
- $poste=new Acc_Account_Ledger($this->db,$poste_val);
- if ( $poste->load() == false ){
- throw new Exception(_('Pour la fiche ').$e_client._(' le poste comptable [').$poste->id.'] '._('n\'existe pas'),9);
- }
- /* Check if the card belong to the ledger */
- $fiche=new Fiche ($this->db);
- $fiche->get_by_qcode($e_client,'cred');
- if ( $fiche->belong_ledger($p_jrn) !=1 )
- throw new Exception(_('La fiche ').$e_client._('n\'est pas accessible à ce journal'),10);
-
- $nb=0;
- //------------------------------------------------------
- // The "Paid By" check
- //------------------------------------------------------
- if ($e_mp != 0 ) $this->check_payment($e_mp,${"e_mp_qcode_".$e_mp});
-
-
- //----------------------------------------
- // foreach item
- //----------------------------------------
- for ($i=0;$i< $nb_item;$i++) {
- if ( strlen(trim(${'e_march'.$i}))== 0) continue;
- /* check if amount are numeric and */
- if ( isNumber(${'e_march'.$i.'_price'}) == 0 )
- throw new Exception(_('La fiche ').${'e_march'.$i}._('a un montant invalide').' ['.${'e_march'.$i}.']',6);
- if ( isNumber(${'e_quant'.$i}) == 0 )
- throw new Exception(_('La fiche ').${'e_march'.$i}._('a une quantité invalide').' ['.${'e_quant'.$i}.']',7);
-
- $owner=new Own($this->db);
- // Check if the given tva id is valid
- if ( $owner->MY_TVA_USE=='Y') {
- if (${'e_march'.$i.'_tva_id'} == 0 )
- throw new Exception(_('La fiche ').${'e_march'.$i}._('a un code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
- $tva_rate=new Acc_Tva($this->db);
- $tva_rate->set_parameter('id',${'e_march'.$i.'_tva_id'});
-
- if ( $tva_rate->load() != 0 )
- throw new Exception(_('La fiche ').${'e_march'.$i}._('a un code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
- }
- /* check if all card has a ATTR_DEF_ACCOUNT*/
- $fiche=new Fiche($this->db);
- $fiche->get_by_qcode(${'e_march'.$i});
- if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
- throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'a pas de poste comptable'),8);
-
- /* get the account and explode if necessary */
- $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
- // if 2 accounts, take only the debit
- if ( strpos($sposte,',') != 0 ) {
- $array=explode(',',$sposte);
- $poste_val=$array[0];
- } else {
- $poste_val=$sposte;
- }
-
- /* The account exists */
- $poste=new Acc_Account_Ledger($this->db,$poste_val);
- if ( $poste->load() == false ){
- throw new Exception(_('Pour la fiche ').${'e_march'.$i}._(' le poste comptable').' ['.$poste->id._('n\'existe pas'),9);
- }
- /* Check if the card belong to the ledger */
- $fiche=new Fiche ($this->db);
- $fiche->get_by_qcode(${'e_march'.$i});
- if ( $fiche->belong_ledger($p_jrn,'deb') !=1 )
- throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'est pas accessible à ce journal'),10);
- /**
- * we have to check also if the different accountings exist
- "ATTR_DEF_DEP_PRIV"
- "ATTR_DEF_DEPENSE_NON_DEDUCTIBLE"
- "ATTR_DEF_TVA_NON_DEDUCTIBLE"
- "ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP"
- */
- foreach (array(
- array(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE,'DNA'),
- array(ATTR_DEF_DEP_PRIV,'DEP_PRIV'),
- array(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP,'TVA_DED_IMPOT'),
- array(ATTR_DEF_TVA_NON_DEDUCTIBLE,'TVA_DNA')) as $key) {
- if ( ! $fiche->empty_attribute($key[0])) {
- $a=new Acc_Parm_Code($this->db,$key[1]);
- if ( $this->db->count_sql('select pcm_val from tmp_pcmn where pcm_val=$1',array($a->p_value))==0)
- throw new Exception ($key._("ce code n'a pas de poste comptable, créez ce poste : [".$a->p_value."]"));
- }
- }
- $nb++;
- }
- if ( $nb == 0 )
- throw new Exception(_('Il n\'y a aucune marchandise'),12);
-
- }
-
- public function save($p_array) {
- echo " Acc_Ledger_Purchase::save Not implemented ";
- }
-
- /*!\brief insert into the database, it calls first the verify function
- * change the value of this->jr_id and this->jr_internal.
- * It generates the document and save the middle of payment, if 'gen_invoice is set
- * and e_mp
- *\param $p_array is usually $_POST or a predefined operation
-\code
- Array
-(
-
- [e_client] =>BELGACOM
- [nb_item] =>9
- [p_jrn] =>3
- [period] =>117
- [e_comm] =>Frais de téléphone
- [e_date] =>01.09.2009
- [e_ech] =>
- [jrn_type] =>ACH
- [e_pj] =>ACH53
- [e_pj_suggest] =>ACH53
- [mt] =>1265318941.39
- [e_mp] =>0
- [e_march0] =>TEL
- [e_march0_price] =>63.6700
- [e_march0_tva_id] =>1
- [e_march0_tva_amount] =>13.3700
- [e_quant0] =>1.000
- ...
- [bon_comm] =>
- [other_info] =>
- [record] =>Enregistrement
-)
-\endcode
- *\return string
- *\note throw an Exception
- */
- public function insert($p_array) {
- extract ($p_array);
- $this->verify($p_array) ;
-
- $owner=new own($this->db);
- $group=$this->db->get_next_seq("s_oa_group"); /* for analytic */
- $seq=$this->db->get_next_seq('s_grpt');
- $this->id=$p_jrn;
-
- $internal=$this->compute_internal_code($seq);
- $this->internal=$internal;
-
- $cust=new Fiche($this->db);
- $cust->get_by_qcode($e_client);
- $sposte=$cust->strAttribut(ATTR_DEF_ACCOUNT);
- // if 2 accounts, take only the credit Supplier
- if ( strpos($sposte,',') != 0 ) {
- $array=explode(',',$sposte);
- $poste=$array[1];
- } else {
- $poste=$sposte;
- }
-
- $oPeriode=new Periode($this->db);
- $check_periode=$this->check_periode();
-
- if ( $check_periode == true )
- $tperiode=$period;
- else
- $tperiode=$oPeriode->find_periode($e_date);
-
- bcscale(4);
- try {
- $tot_amount=0;
- $tot_tva=0;
- $tot_debit=0;
- $this->db->start();
- $tot_nd=0;
- $tot_perso=0;
- $tot_tva_nd=0;
- $tot_tva_ndded=0;
-
- /* Save all the items without vat and no deductible vat and expense*/
- for ($i=0;$i< $nb_item;$i++) {
- if ( strlen(trim(${'e_march'.$i})) == 0 ) continue;
- if ( ${'e_march'.$i.'_price'} == 0 ) continue;
- if ( ${'e_quant'.$i} == 0 ) continue;
-
- /* First we save all the items without vat */
- $fiche=new Fiche($this->db);
- $fiche->get_by_qcode(${"e_march".$i});
-
- /* tva */
- if ($owner->MY_TVA_USE=='Y') {
- $idx_tva=${'e_march'.$i.'_tva_id'};
- $oTva=new Acc_Tva($this->db);
- $oTva->set_parameter('id',$idx_tva);
- $oTva->load();
- }
-
- /* We have to compute all the amount thanks Acc_Compute */
- $amount=bcmul(${'e_march'.$i.'_price'},${'e_quant'.$i});
- $acc_amount=new Acc_Compute();
- $acc_amount->check=false;
- $acc_amount->set_parameter('amount',$amount);
- if ( $owner->MY_TVA_USE=='Y') {
- $acc_amount->set_parameter('amount_vat_rate',$oTva->get_parameter('rate'));
- if ( strlen(trim(${'e_march'.$i.'_tva_amount'})) ==0) {
- $acc_amount->compute_vat();
-
- } else {
- $acc_amount->amount_vat= ${'e_march'.$i.'_tva_amount'};
-
- }
- $tot_tva+=$acc_amount->amount_vat;
- }
-
- $acc_operation=new Acc_Operation($this->db);
- $acc_operation->date=$e_date;
- $acc_operation->grpt=$seq;
- $acc_operation->jrn=$p_jrn;
- $acc_operation->type='d';
- $acc_operation->periode=$tperiode;
- $acc_operation->qcode="";
-
-
-
-
- if ( ! $fiche->empty_attribute(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE)) {
- $acc_amount->amount_nd_rate=$fiche->strAttribut(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE);
- $acc_amount->compute_nd();
- $tot_nd+=$acc_amount->amount_nd;
-
- }
-
- if ( ! $fiche->empty_attribute(ATTR_DEF_DEP_PRIV)) {
- $acc_amount->amount_perso_rate=$fiche->strAttribut(ATTR_DEF_DEP_PRIV);
- $acc_amount->compute_perso();
- $tot_perso+=$acc_amount->amount_perso;
- }
-
- if ( ! $fiche->empty_attribute(ATTR_DEF_TVA_NON_DEDUCTIBLE)) {
- $acc_amount->nd_vat_rate=$fiche->strAttribut(ATTR_DEF_TVA_NON_DEDUCTIBLE);
- $acc_amount->compute_nd_vat();
- $tot_tva_nd+=$acc_amount->nd_vat;
- /* save op. */
-
- }
- if ( ! $fiche->empty_attribute(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP)) {
- $acc_amount->nd_ded_vat_rate=$fiche->strAttribut(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
- $acc_amount->compute_ndded_vat();
- /* save op. */
- $tot_tva_ndded+=$acc_amount->nd_ded_vat;
- }
- $acc_amount->correct();
- $tot_amount+=$amount;
-
- /* get the account and explode if necessary */
- $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
- // if 2 accounts, take only the debit one for customer
- if ( strpos($sposte,',') != 0 ) {
- $array=explode(',',$sposte);
- $poste_val=$array[0];
- } else {
- $poste_val=$sposte;
- }
-
- $acc_operation->poste=$poste_val;
- $acc_operation->amount=$acc_amount->amount;
- $acc_operation->qcode=${"e_march".$i};
- if( $acc_amount->amount > 0 ) $tot_debit=bcadd($tot_debit,$acc_amount->amount);
-
- $j_id=$acc_operation->insert_jrnx();
-
- /* Compute sum vat */
-
- if ( $owner->MY_TVA_USE=='Y') {
- $tva_item=$acc_amount->amount_vat;
-
- if (isset($tva[$idx_tva] ) )
- $tva[$idx_tva]+=$tva_item;
- else
- $tva[$idx_tva]=$tva_item;
-
- }
- /* Save the stock */
- /* if the quantity is < 0 then the stock increase (return of
- * material)
- */
- $nNeg=(${"e_quant".$i}<0)?-1:1;
-
- // always save quantity but in withStock we can find
- // what card need a stock management
-
- InsertStockGoods($this->db,$j_id,${'e_march'.$i},$nNeg*${'e_quant'.$i},'d') ;
-
- if ( $owner->MY_ANALYTIC != "nu" )
- {
- // for each item, insert into operation_analytique */
- $op=new Anc_Operation($this->db);
- $op->oa_group=$group;
- $op->j_id=$j_id;
- $op->oa_date=$e_date;
- $op->oa_debit=($amount < 0 )?'t':'f';
- $op->oa_description=FormatString($e_comm);
- $op->save_form_plan($_POST,$i,$j_id);
- }
- // insert into quant_purchase
- //-----
- if ( $owner->MY_TVA_USE=='Y') {
- $r=$this->db->exec_sql("select insert_quant_purchase ".
- "(null".
- ",".$j_id. /* 2 */
- ",'".${"e_march".$i}."'". /* 3 */
- ",".${"e_quant".$i}.",". /* 4 */
- round($amount,2). /* 5 */
- ",".$acc_amount->amount_vat. /* 6 */
- ",".$oTva->get_parameter('id'). /* 7 */
- ",".$acc_amount->amount_nd. /* 8 */
- ",".$acc_amount->nd_vat. /* 9 */
- ",".$acc_amount->nd_ded_vat. /* 10 */
- ",".$acc_amount->amount_perso. /* 11 */
- ",'".$e_client."')"); /* 12 */
-
- } else {
- $r=$this->db->exec_sql("select insert_quant_purchase ".
- "(null".
- ",".$j_id.
- ",'".${"e_march".$i}."'".
- ",".${"e_quant".$i}.",".
- round($amount,2).
- ",0".
- ",null".
- ",".$acc_amount->amount_nd.
- ",0".
- ",".$acc_amount->nd_ded_vat.
- ",".$acc_amount->amount_perso.
- ",'".$e_client."')");
-
-
- }
-
- } // end loop : save all items
- /* save total customer */
- $cust_amount=round(bcadd($tot_amount,$tot_tva),2);
- $acc_operation=new Acc_Operation($this->db);
- $acc_operation->date=$e_date;
- $acc_operation->poste=$poste;
- $acc_operation->amount=$cust_amount;
- $acc_operation->grpt=$seq;
- $acc_operation->jrn=$p_jrn;
- $acc_operation->type='c';
- $acc_operation->periode=$tperiode;
- $acc_operation->qcode=${"e_client"};
- if ( $cust_amount < 0 ) $tot_debit=bcadd($tot_debit,abs($cust_amount));
- $acc_operation->insert_jrnx();
- /*
- * Save all the no deductible
+ /*!\brief verify that the data are correct before inserting or confirming
+ *\param an array (usually $_POST)
+ *\return String
+ *\throw Exception if an error occurs
*/
- if ( $tot_nd != 0) {
- /* save op. */
- $dna=new Acc_Parm_Code($this->db,'DNA');
- $acc_operation->type='d';
- $acc_operation->amount=$tot_nd;
- $acc_operation->poste=$dna->p_value;
- $acc_operation->qcode='';
- if ( $tot_nd > 0 ) $tot_debit=bcadd($tot_debit,$tot_nd);
- $j_id=$acc_operation->insert_jrnx();
+ public function verify($p_array)
+ {
+ extract ($p_array);
+ /* check if we can write into this ledger */
+ $user=new User($this->db);
+ if ( $user->check_jrn($p_jrn) != 'W' )
+ throw new Exception (_('Accès interdit'),20);
- }
- if ( $tot_perso != 0) {
- /* save op. */
- $acc_operation->type='d';
- $dna=new Acc_Parm_Code($this->db,'DEP_PRIV');
- $acc_operation->amount=$tot_perso;
- $acc_operation->poste=$dna->p_value;
- $acc_operation->qcode='';
- if ( $tot_perso > 0 ) $tot_debit=bcadd($tot_debit,$tot_perso);
- $j_id=$acc_operation->insert_jrnx();
- }
- if ( $tot_tva_nd != 0) {
- /* save op. */
- $acc_operation->type='d';
- $acc_operation->qcode='';
- $dna=new Acc_Parm_Code($this->db,'TVA_DNA');
- $acc_operation->amount=$tot_tva_nd;
- $acc_operation->poste=$dna->p_value;
- if ( $tot_tva_nd > 0 ) $tot_debit=bcadd($tot_debit,$tot_tva_nd);
- $j_id=$acc_operation->insert_jrnx();
+ /* check for a double reload */
+ if ( isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1',array($mt)) != 0 )
+ throw new Exception (_('Double Encodage'),5);
- }
- if ( $tot_tva_ndded != 0) {
- /* save op. */
- $dna=new Acc_Parm_Code($this->db,'TVA_DED_IMPOT');
+ /* check if there is a customer */
+ if ( strlen(trim($e_client)) == 0 )
+ throw new Exception(_('Vous n\'avez pas donné de fournisseur'),11);
- $acc_operation->type='d';
- $acc_operation->qcode='';
- $acc_operation->amount=$tot_tva_ndded;
- $acc_operation->poste=$dna->p_value;
- if ( $tot_tva_ndded > 0 ) $tot_debit=bcadd($tot_debit,$tot_tva_ndded);
- $j_id=$acc_operation->insert_jrnx();
+ /* check if the date is valid */
+ if ( isDate($e_date) == null )
+ {
+ throw new Exception(_('Date invalide'), 2);
+ }
+ $oPeriode=new Periode($this->db);
+ if ( $this->check_periode() == false)
+ {
+ $tperiode=$oPeriode->find_periode($e_date);
+ }
+ else
+ {
+ $tperiode=$period;
+ $oPeriode->p_id=$tperiode;
+ /* check that the datum is in the choosen periode */
+ list ($min,$max)=$oPeriode->get_date_limit($tperiode);
+ if ( cmpDate($e_date,$min) < 0 ||
+ cmpDate($e_date,$max) > 0)
+ throw new Exception(_('Date et periode ne correspondent pas'),6);
+ }
+ /* check if the periode is closed */
+ if ( $this->is_closed($tperiode)==1 )
+ {
+ throw new Exception(_('Periode fermee'),6);
+ }
+ /* check if we are using the strict mode */
+ if( $this->check_strict() == true)
+ {
+ /* if we use the strict mode, we get the date of the last
+ operation */
+ $last_date=$this->get_last_date();
+ if ( $last_date != null && cmpDate($e_date,$last_date) < 0 )
+ throw new Exception(_('Vous utilisez le mode strict la dernière operation est à la date du ')
+ .$last_date._(' vous ne pouvez pas encoder à une '.
+ ' date antérieure dans ce journal'),13);
+
+ }
+
+ /* check the account */
+ $fiche=new Fiche($this->db);
+ $fiche->get_by_qcode($e_client);
+
+ if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
+ throw new Exception(_('La fiche ').$e_client._('n\'a pas de poste comptable'),8);
+
+ /* get the account and explode if necessary */
+ $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
+ // if 2 accounts, take only the credit one for supplier
+ if ( strpos($sposte,',') != 0 )
+ {
+ $array=explode(',',$sposte);
+ $poste_val=$array[1];
+ }
+ else
+ {
+ $poste_val=$sposte;
+ }
+
+ /* The account exists */
+ $poste=new Acc_Account_Ledger($this->db,$poste_val);
+ if ( $poste->load() == false )
+ {
+ throw new Exception(_('Pour la fiche ').$e_client._(' le poste comptable [').$poste->id.'] '._('n\'existe pas'),9);
+ }
+ /* Check if the card belong to the ledger */
+ $fiche=new Fiche ($this->db);
+ $fiche->get_by_qcode($e_client,'cred');
+ if ( $fiche->belong_ledger($p_jrn) !=1 )
+ throw new Exception(_('La fiche ').$e_client._('n\'est pas accessible à ce journal'),10);
+
+ $nb=0;
+ //------------------------------------------------------
+ // The "Paid By" check
+ //------------------------------------------------------
+ if ($e_mp != 0 ) $this->check_payment($e_mp,${"e_mp_qcode_".$e_mp});
+
+
+ //----------------------------------------
+ // foreach item
+ //----------------------------------------
+ for ($i=0;$i< $nb_item;$i++)
+ {
+ if ( strlen(trim(${'e_march'.$i}))== 0) continue;
+ /* check if amount are numeric and */
+ if ( isNumber(${'e_march'.$i.'_price'}) == 0 )
+ throw new Exception(_('La fiche ').${'e_march'.$i}._('a un montant invalide').' ['.${'e_march'.$i}.']',6);
+ if ( isNumber(${'e_quant'.$i}) == 0 )
+ throw new Exception(_('La fiche ').${'e_march'.$i}._('a une quantité invalide').' ['.${'e_quant'.$i}.']',7);
+
+ $owner=new Own($this->db);
+ // Check if the given tva id is valid
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ if (${'e_march'.$i.'_tva_id'} == 0 )
+ throw new Exception(_('La fiche ').${'e_march'.$i}._('a un code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
+ $tva_rate=new Acc_Tva($this->db);
+ $tva_rate->set_parameter('id',${'e_march'.$i.'_tva_id'});
+
+ if ( $tva_rate->load() != 0 )
+ throw new Exception(_('La fiche ').${'e_march'.$i}._('a un code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
+ }
+ /* check if all card has a ATTR_DEF_ACCOUNT*/
+ $fiche=new Fiche($this->db);
+ $fiche->get_by_qcode(${'e_march'.$i});
+ if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
+ throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'a pas de poste comptable'),8);
+
+ /* get the account and explode if necessary */
+ $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
+ // if 2 accounts, take only the debit
+ if ( strpos($sposte,',') != 0 )
+ {
+ $array=explode(',',$sposte);
+ $poste_val=$array[0];
+ }
+ else
+ {
+ $poste_val=$sposte;
+ }
+
+ /* The account exists */
+ $poste=new Acc_Account_Ledger($this->db,$poste_val);
+ if ( $poste->load() == false )
+ {
+ throw new Exception(_('Pour la fiche ').${'e_march'.$i}._(' le poste comptable').' ['.$poste->id._('n\'existe pas'),9);
+ }
+ /* Check if the card belong to the ledger */
+ $fiche=new Fiche ($this->db);
+ $fiche->get_by_qcode(${'e_march'.$i});
+ if ( $fiche->belong_ledger($p_jrn,'deb') !=1 )
+ throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'est pas accessible à ce journal'),10);
+ /**
+ * we have to check also if the different accountings exist
+ "ATTR_DEF_DEP_PRIV"
+ "ATTR_DEF_DEPENSE_NON_DEDUCTIBLE"
+ "ATTR_DEF_TVA_NON_DEDUCTIBLE"
+ "ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP"
+ */
+ foreach (array(
+ array(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE,'DNA'),
+ array(ATTR_DEF_DEP_PRIV,'DEP_PRIV'),
+ array(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP,'TVA_DED_IMPOT'),
+ array(ATTR_DEF_TVA_NON_DEDUCTIBLE,'TVA_DNA')) as $key)
+ {
+ if ( ! $fiche->empty_attribute($key[0]))
+ {
+ $a=new Acc_Parm_Code($this->db,$key[1]);
+ if ( $this->db->count_sql('select pcm_val from tmp_pcmn where pcm_val=$1',array($a->p_value))==0)
+ throw new Exception ($key._("ce code n'a pas de poste comptable, créez ce poste : [".$a->p_value."]"));
+ }
+ }
+ $nb++;
+ }
+ if ( $nb == 0 )
+ throw new Exception(_('Il n\'y a aucune marchandise'),12);
}
- if ( $owner->MY_TVA_USE=='Y') {
- /* save all vat
- * $i contains the tva_id and value contains the vat amount
- */
- foreach ($tva as $i => $value) {
- $oTva=new Acc_Tva($this->db);
- $oTva->set_parameter('id',$i);
- $oTva->load();
-
- $poste_vat=$oTva->get_side('d');
-
- $cust_amount=bcadd($tot_amount,$tot_tva);
- $acc_operation=new Acc_Operation($this->db);
- $acc_operation->date=$e_date;
- $acc_operation->poste=$poste_vat;
- $acc_operation->amount=$value;
- $acc_operation->grpt=$seq;
- $acc_operation->jrn=$p_jrn;
- $acc_operation->type='d';
- $acc_operation->periode=$tperiode;
- if ( $value > 0 ) $tot_debit=bcadd($tot_debit,$value);
- $acc_operation->insert_jrnx();
-
- }
+ public function save($p_array)
+ {
+ echo " Acc_Ledger_Purchase::save Not implemented ";
}
- /* insert into jrn */
- $acc_operation=new Acc_Operation($this->db);
- $acc_operation->date=$e_date;
- $acc_operation->echeance=$e_ech;
- $acc_operation->amount=abs(round($tot_debit,2));
- $acc_operation->desc=$e_comm;
- $acc_operation->grpt=$seq;
- $acc_operation->jrn=$p_jrn;
- $acc_operation->periode=$tperiode;
- $acc_operation->pj=$e_pj;
- $acc_operation->mt=$mt;
- $this->jr_id=$acc_operation->insert_jrn();
- $this->pj=$acc_operation->set_pj();
- // Set Internal code
- $this->grpt_id=$seq;
- $this->update_internal_code($internal);
- /* update quant_purchase */
- $this->db->exec_sql('update quant_purchase set qp_internal = $1 where j_id in (select j_id from jrnx where j_grpt=$2)',
- array($internal,$seq));
-
- /* if e_suggest != e_pj then do not increment sequence */
- if ( strcmp($e_pj,$e_pj_suggest) == 0 && strlen(trim($e_pj)) != 0 ) {
- $this->inc_seq_pj();
- }
+ /*!\brief insert into the database, it calls first the verify function
+ * change the value of this->jr_id and this->jr_internal.
+ * It generates the document and save the middle of payment, if 'gen_invoice is set
+ * and e_mp
+ *\param $p_array is usually $_POST or a predefined operation
+ \code
+ Array
+ (
- /* Save the attachment */
- if ( isset ($_FILES)) {
- if ( sizeof($_FILES) != 0 )
- $this->db->save_upload_document($seq);
- }
- $str_file="";
- /* Generate an document and save it into the database (Note de frais only)
+ [e_client] =>BELGACOM
+ [nb_item] =>9
+ [p_jrn] =>3
+ [period] =>117
+ [e_comm] =>Frais de téléphone
+ [e_date] =>01.09.2009
+ [e_ech] =>
+ [jrn_type] =>ACH
+ [e_pj] =>ACH53
+ [e_pj_suggest] =>ACH53
+ [mt] =>1265318941.39
+ [e_mp] =>0
+ [e_march0] =>TEL
+ [e_march0_price] =>63.6700
+ [e_march0_tva_id] =>1
+ [e_march0_tva_amount] =>13.3700
+ [e_quant0] =>1.000
+ ...
+ [bon_comm] =>
+ [other_info] =>
+ [record] =>Enregistrement
+ )
+ \endcode
+ *\return string
+ *\note throw an Exception
*/
- if ( isset($_POST['gen_invoice']) ) {
- $ref_doc= $this->create_document($internal,$p_array);
- $this->doc= _('Document généré');
- $this->doc.=''.$ref_doc.' ';
+ public function insert($p_array)
+ {
+ extract ($p_array);
+ $this->verify($p_array) ;
+
+ $owner=new own($this->db);
+ $group=$this->db->get_next_seq("s_oa_group"); /* for analytic */
+ $seq=$this->db->get_next_seq('s_grpt');
+ $this->id=$p_jrn;
+
+ $internal=$this->compute_internal_code($seq);
+ $this->internal=$internal;
+
+ $cust=new Fiche($this->db);
+ $cust->get_by_qcode($e_client);
+ $sposte=$cust->strAttribut(ATTR_DEF_ACCOUNT);
+ // if 2 accounts, take only the credit Supplier
+ if ( strpos($sposte,',') != 0 )
+ {
+ $array=explode(',',$sposte);
+ $poste=$array[1];
+ }
+ else
+ {
+ $poste=$sposte;
+ }
+
+ $oPeriode=new Periode($this->db);
+ $check_periode=$this->check_periode();
+
+ if ( $check_periode == true )
+ $tperiode=$period;
+ else
+ $tperiode=$oPeriode->find_periode($e_date);
+
+ bcscale(4);
+ try
+ {
+ $tot_amount=0;
+ $tot_tva=0;
+ $tot_debit=0;
+ $this->db->start();
+ $tot_nd=0;
+ $tot_perso=0;
+ $tot_tva_nd=0;
+ $tot_tva_ndded=0;
+
+ /* Save all the items without vat and no deductible vat and expense*/
+ for ($i=0;$i< $nb_item;$i++)
+ {
+ if ( strlen(trim(${'e_march'.$i})) == 0 ) continue;
+ if ( ${'e_march'.$i.'_price'} == 0 ) continue;
+ if ( ${'e_quant'.$i} == 0 ) continue;
+
+ /* First we save all the items without vat */
+ $fiche=new Fiche($this->db);
+ $fiche->get_by_qcode(${"e_march".$i});
+
+ /* tva */
+ if ($owner->MY_TVA_USE=='Y')
+ {
+ $idx_tva=${'e_march'.$i.'_tva_id'};
+ $oTva=new Acc_Tva($this->db);
+ $oTva->set_parameter('id',$idx_tva);
+ $oTva->load();
+ }
+
+ /* We have to compute all the amount thanks Acc_Compute */
+ $amount=bcmul(${'e_march'.$i.'_price'},${'e_quant'.$i});
+ $acc_amount=new Acc_Compute();
+ $acc_amount->check=false;
+ $acc_amount->set_parameter('amount',$amount);
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ $acc_amount->set_parameter('amount_vat_rate',$oTva->get_parameter('rate'));
+ if ( strlen(trim(${'e_march'.$i.'_tva_amount'})) ==0)
+ {
+ $acc_amount->compute_vat();
+
+ }
+ else
+ {
+ $acc_amount->amount_vat= ${'e_march'.$i.'_tva_amount'};
+
+ }
+ $tot_tva+=$acc_amount->amount_vat;
+ }
+
+ $acc_operation=new Acc_Operation($this->db);
+ $acc_operation->date=$e_date;
+ $acc_operation->grpt=$seq;
+ $acc_operation->jrn=$p_jrn;
+ $acc_operation->type='d';
+ $acc_operation->periode=$tperiode;
+ $acc_operation->qcode="";
+
+
+
+
+ if ( ! $fiche->empty_attribute(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE))
+ {
+ $acc_amount->amount_nd_rate=$fiche->strAttribut(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE);
+ $acc_amount->compute_nd();
+ $tot_nd+=$acc_amount->amount_nd;
+
+ }
+
+ if ( ! $fiche->empty_attribute(ATTR_DEF_DEP_PRIV))
+ {
+ $acc_amount->amount_perso_rate=$fiche->strAttribut(ATTR_DEF_DEP_PRIV);
+ $acc_amount->compute_perso();
+ $tot_perso+=$acc_amount->amount_perso;
+ }
+
+ if ( ! $fiche->empty_attribute(ATTR_DEF_TVA_NON_DEDUCTIBLE))
+ {
+ $acc_amount->nd_vat_rate=$fiche->strAttribut(ATTR_DEF_TVA_NON_DEDUCTIBLE);
+ $acc_amount->compute_nd_vat();
+ $tot_tva_nd+=$acc_amount->nd_vat;
+ /* save op. */
+
+ }
+ if ( ! $fiche->empty_attribute(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP))
+ {
+ $acc_amount->nd_ded_vat_rate=$fiche->strAttribut(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
+ $acc_amount->compute_ndded_vat();
+ /* save op. */
+ $tot_tva_ndded+=$acc_amount->nd_ded_vat;
+ }
+ $acc_amount->correct();
+ $tot_amount+=$amount;
+
+ /* get the account and explode if necessary */
+ $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
+ // if 2 accounts, take only the debit one for customer
+ if ( strpos($sposte,',') != 0 )
+ {
+ $array=explode(',',$sposte);
+ $poste_val=$array[0];
+ }
+ else
+ {
+ $poste_val=$sposte;
+ }
+
+ $acc_operation->poste=$poste_val;
+ $acc_operation->amount=$acc_amount->amount;
+ $acc_operation->qcode=${"e_march".$i};
+ if( $acc_amount->amount > 0 ) $tot_debit=bcadd($tot_debit,$acc_amount->amount);
+
+ $j_id=$acc_operation->insert_jrnx();
+
+ /* Compute sum vat */
+
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ $tva_item=$acc_amount->amount_vat;
+
+ if (isset($tva[$idx_tva] ) )
+ $tva[$idx_tva]+=$tva_item;
+ else
+ $tva[$idx_tva]=$tva_item;
+
+ }
+ /* Save the stock */
+ /* if the quantity is < 0 then the stock increase (return of
+ * material)
+ */
+ $nNeg=($
+ {"e_quant".$i
+ }
+ <0)?-1:1;
+
+ // always save quantity but in withStock we can find
+ // what card need a stock management
+
+ InsertStockGoods($this->db,$j_id,${'e_march'.$i},$nNeg*${'e_quant'.$i},'d') ;
+
+ if ( $owner->MY_ANALYTIC != "nu" )
+ {
+ // for each item, insert into operation_analytique */
+ $op=new Anc_Operation($this->db);
+ $op->oa_group=$group;
+ $op->j_id=$j_id;
+ $op->oa_date=$e_date;
+ $op->oa_debit=($amount < 0 )?'t':'f';
+ $op->oa_description=FormatString($e_comm);
+ $op->save_form_plan($_POST,$i,$j_id);
+ }
+ // insert into quant_purchase
+ //-----
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ $r=$this->db->exec_sql("select insert_quant_purchase ".
+ "(null".
+ ",".$j_id. /* 2 */
+ ",'".${"e_march".$i}."'". /* 3 */
+ ",".${"e_quant".$i}.",". /* 4 */
+ round($amount,2). /* 5 */
+ ",".$acc_amount->amount_vat. /* 6 */
+ ",".$oTva->get_parameter('id'). /* 7 */
+ ",".$acc_amount->amount_nd. /* 8 */
+ ",".$acc_amount->nd_vat. /* 9 */
+ ",".$acc_amount->nd_ded_vat. /* 10 */
+ ",".$acc_amount->amount_perso. /* 11 */
+ ",'".$e_client."')"); /* 12 */
+
+ }
+ else
+ {
+ $r=$this->db->exec_sql("select insert_quant_purchase ".
+ "(null".
+ ",".$j_id.
+ ",'".${"e_march".$i}."'".
+ ",".${"e_quant".$i}.",".
+ round($amount,2).
+ ",0".
+ ",null".
+ ",".$acc_amount->amount_nd.
+ ",0".
+ ",".$acc_amount->nd_ded_vat.
+ ",".$acc_amount->amount_perso.
+ ",'".$e_client."')");
+
+
+ }
+
+ } // end loop : save all items
+ /* save total customer */
+ $cust_amount=round(bcadd($tot_amount,$tot_tva),2);
+ $acc_operation=new Acc_Operation($this->db);
+ $acc_operation->date=$e_date;
+ $acc_operation->poste=$poste;
+ $acc_operation->amount=$cust_amount;
+ $acc_operation->grpt=$seq;
+ $acc_operation->jrn=$p_jrn;
+ $acc_operation->type='c';
+ $acc_operation->periode=$tperiode;
+ $acc_operation->qcode=$
+ {"e_client"
+ };
+ if ( $cust_amount < 0 ) $tot_debit=bcadd($tot_debit,abs($cust_amount));
+ $acc_operation->insert_jrnx();
+ /*
+ * Save all the no deductible
+ */
+ if ( $tot_nd != 0)
+ {
+ /* save op. */
+ $dna=new Acc_Parm_Code($this->db,'DNA');
+ $acc_operation->type='d';
+ $acc_operation->amount=$tot_nd;
+ $acc_operation->poste=$dna->p_value;
+ $acc_operation->qcode='';
+ if ( $tot_nd > 0 ) $tot_debit=bcadd($tot_debit,$tot_nd);
+ $j_id=$acc_operation->insert_jrnx();
+
+ }
+ if ( $tot_perso != 0)
+ {
+ /* save op. */
+ $acc_operation->type='d';
+ $dna=new Acc_Parm_Code($this->db,'DEP_PRIV');
+ $acc_operation->amount=$tot_perso;
+ $acc_operation->poste=$dna->p_value;
+ $acc_operation->qcode='';
+ if ( $tot_perso > 0 ) $tot_debit=bcadd($tot_debit,$tot_perso);
+ $j_id=$acc_operation->insert_jrnx();
+
+ }
+ if ( $tot_tva_nd != 0)
+ {
+ /* save op. */
+ $acc_operation->type='d';
+ $acc_operation->qcode='';
+ $dna=new Acc_Parm_Code($this->db,'TVA_DNA');
+ $acc_operation->amount=$tot_tva_nd;
+ $acc_operation->poste=$dna->p_value;
+ if ( $tot_tva_nd > 0 ) $tot_debit=bcadd($tot_debit,$tot_tva_nd);
+ $j_id=$acc_operation->insert_jrnx();
+
+ }
+ if ( $tot_tva_ndded != 0)
+ {
+ /* save op. */
+ $dna=new Acc_Parm_Code($this->db,'TVA_DED_IMPOT');
+
+ $acc_operation->type='d';
+ $acc_operation->qcode='';
+ $acc_operation->amount=$tot_tva_ndded;
+ $acc_operation->poste=$dna->p_value;
+ if ( $tot_tva_ndded > 0 ) $tot_debit=bcadd($tot_debit,$tot_tva_ndded);
+ $j_id=$acc_operation->insert_jrnx();
+
+
+ }
+
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ /* save all vat
+ * $i contains the tva_id and value contains the vat amount
+ */
+ foreach ($tva as $i => $value)
+ {
+ $oTva=new Acc_Tva($this->db);
+ $oTva->set_parameter('id',$i);
+ $oTva->load();
+
+ $poste_vat=$oTva->get_side('d');
+
+ $cust_amount=bcadd($tot_amount,$tot_tva);
+ $acc_operation=new Acc_Operation($this->db);
+ $acc_operation->date=$e_date;
+ $acc_operation->poste=$poste_vat;
+ $acc_operation->amount=$value;
+ $acc_operation->grpt=$seq;
+ $acc_operation->jrn=$p_jrn;
+ $acc_operation->type='d';
+ $acc_operation->periode=$tperiode;
+ if ( $value > 0 ) $tot_debit=bcadd($tot_debit,$value);
+ $acc_operation->insert_jrnx();
+
+ }
+ }
+ /* insert into jrn */
+ $acc_operation=new Acc_Operation($this->db);
+ $acc_operation->date=$e_date;
+ $acc_operation->echeance=$e_ech;
+ $acc_operation->amount=abs(round($tot_debit,2));
+ $acc_operation->desc=$e_comm;
+ $acc_operation->grpt=$seq;
+ $acc_operation->jrn=$p_jrn;
+ $acc_operation->periode=$tperiode;
+ $acc_operation->pj=$e_pj;
+ $acc_operation->mt=$mt;
+ $this->jr_id=$acc_operation->insert_jrn();
+ $this->pj=$acc_operation->set_pj();
+
+ // Set Internal code
+ $this->grpt_id=$seq;
+ $this->update_internal_code($internal);
+ /* update quant_purchase */
+ $this->db->exec_sql('update quant_purchase set qp_internal = $1 where j_id in (select j_id from jrnx where j_grpt=$2)',
+ array($internal,$seq));
+
+ /* if e_suggest != e_pj then do not increment sequence */
+ if ( strcmp($e_pj,$e_pj_suggest) == 0 && strlen(trim($e_pj)) != 0 )
+ {
+ $this->inc_seq_pj();
+ }
+
+ /* Save the attachment */
+ if ( isset ($_FILES))
+ {
+ if ( sizeof($_FILES) != 0 )
+ $this->db->save_upload_document($seq);
+ }
+ $str_file="";
+ /* Generate an document and save it into the database (Note de frais only)
+ */
+ if ( isset($_POST['gen_invoice']) )
+ {
+ $ref_doc= $this->create_document($internal,$p_array);
+ $this->doc= _('Document généré');
+ $this->doc.=''.$ref_doc.' ';
+ }
+
+ //----------------------------------------
+ // Save the payer
+ //----------------------------------------
+ if ( $e_mp != 0 )
+ {
+ /* mp */
+ $mp=new Acc_Payment($this->db,$e_mp);
+ $mp->load();
+
+ /* fiche */
+ if ($mp->get_parameter('qcode') == '')
+ $fqcode=${'e_mp_qcode_'.$e_mp};
+ else
+ $fqcode=$mp->get_parameter('qcode');
+
+ $acfiche = new Fiche($this->db);
+ $acfiche->get_by_qcode($fqcode);
+
+ /* jrnx */
+ $acseq=$this->db->get_next_seq('s_grpt');
+ $acjrn=new Acc_Ledger($this->db,$mp->get_parameter('ledger'));
+ $acinternal=$acjrn->compute_internal_code($acseq);
+
+ /* Insert paid by */
+ $acc_pay=new Acc_Operation($this->db);
+ $acc_pay->date=$e_date;
+
+ /* get the account and explode if necessary */
+ $sposte=$acfiche->strAttribut(ATTR_DEF_ACCOUNT);
+ // if 2 accounts, take only the debit one for customer
+ if ( strpos($sposte,',') != 0 )
+ {
+ $array=explode(',',$sposte);
+ $poste_val=$array[1];
+ }
+ else
+ {
+ $poste_val=$sposte;
+ }
+ $acc_pay->poste=$poste_val;
+ $acc_pay->qcode=$fqcode;
+ $acc_pay->amount=abs(round($tot_debit,2));
+ $acc_pay->desc=$e_comm;
+ $acc_pay->grpt=$acseq;
+ $acc_pay->jrn=$mp->get_parameter('ledger');
+ $acc_pay->periode=$tperiode;
+ $acc_pay->type='c';
+ $acc_pay->insert_jrnx();
+
+ /* Insert supplier */
+ $acc_pay=new Acc_Operation($this->db);
+ $acc_pay->date=$e_date;
+ $acc_pay->poste=$poste;
+ $acc_pay->qcode=$e_client;
+ $acc_pay->amount=abs(round($tot_debit,2));
+ $acc_pay->desc=$e_comm;
+ $acc_pay->grpt=$acseq;
+ $acc_pay->jrn=$mp->get_parameter('ledger');
+ $acc_pay->periode=$tperiode;
+ $acc_pay->type='d';
+ $acc_pay->insert_jrnx();
+
+ /* insert into jrn */
+ $acc_pay->mt=$mt;
+ $acc_pay->insert_jrn();
+ $acjrn->grpt_id=$acseq;
+ $acjrn->update_internal_code($acinternal);
+
+ $r1=$this->get_id($internal);
+ $r2=$this->get_id($acinternal);
+
+ /* set the flag paid */
+ $Res=$this->db->exec_sql("update jrn set jr_rapt='paid' where jr_id=$1",array($r1));
+
+ /* Reconcialiation */
+ $rec=new Acc_Reconciliation($this->db);
+ $rec->set_jr_id($r1);
+ $rec->insert($r2);
+ }
+ }//end try
+ catch (Exception $e)
+ {
+ echo ''.
+ 'Erreur dans l\'enregistrement '.
+ __FILE__.':'.__LINE__.' '.
+ $e->getMessage().$e->getTrace();
+ $this->db->rollback();
+ exit();
+ }
+ $this->db->commit();
+ return $internal;
}
- //----------------------------------------
- // Save the payer
- //----------------------------------------
- if ( $e_mp != 0 ) {
- /* mp */
- $mp=new Acc_Payment($this->db,$e_mp);
- $mp->load();
-
- /* fiche */
- if ($mp->get_parameter('qcode') == '')
- $fqcode=${'e_mp_qcode_'.$e_mp};
- else
- $fqcode=$mp->get_parameter('qcode');
-
- $acfiche = new Fiche($this->db);
- $acfiche->get_by_qcode($fqcode);
-
- /* jrnx */
- $acseq=$this->db->get_next_seq('s_grpt');
- $acjrn=new Acc_Ledger($this->db,$mp->get_parameter('ledger'));
- $acinternal=$acjrn->compute_internal_code($acseq);
-
- /* Insert paid by */
- $acc_pay=new Acc_Operation($this->db);
- $acc_pay->date=$e_date;
-
- /* get the account and explode if necessary */
- $sposte=$acfiche->strAttribut(ATTR_DEF_ACCOUNT);
- // if 2 accounts, take only the debit one for customer
- if ( strpos($sposte,',') != 0 ) {
- $array=explode(',',$sposte);
- $poste_val=$array[1];
- } else {
- $poste_val=$sposte;
- }
- $acc_pay->poste=$poste_val;
- $acc_pay->qcode=$fqcode;
- $acc_pay->amount=abs(round($tot_debit,2));
- $acc_pay->desc=$e_comm;
- $acc_pay->grpt=$acseq;
- $acc_pay->jrn=$mp->get_parameter('ledger');
- $acc_pay->periode=$tperiode;
- $acc_pay->type='c';
- $acc_pay->insert_jrnx();
-
- /* Insert supplier */
- $acc_pay=new Acc_Operation($this->db);
- $acc_pay->date=$e_date;
- $acc_pay->poste=$poste;
- $acc_pay->qcode=$e_client;
- $acc_pay->amount=abs(round($tot_debit,2));
- $acc_pay->desc=$e_comm;
- $acc_pay->grpt=$acseq;
- $acc_pay->jrn=$mp->get_parameter('ledger');
- $acc_pay->periode=$tperiode;
- $acc_pay->type='d';
- $acc_pay->insert_jrnx();
-
- /* insert into jrn */
- $acc_pay->mt=$mt;
- $acc_pay->insert_jrn();
- $acjrn->grpt_id=$acseq;
- $acjrn->update_internal_code($acinternal);
-
- $r1=$this->get_id($internal);
- $r2=$this->get_id($acinternal);
-
- /* set the flag paid */
- $Res=$this->db->exec_sql("update jrn set jr_rapt='paid' where jr_id=$1",array($r1));
-
- /* Reconcialiation */
- $rec=new Acc_Reconciliation($this->db);
- $rec->set_jr_id($r1);
- $rec->insert($r2);
- }
- }//end try
- catch (Exception $e)
- {
- echo ''.
- 'Erreur dans l\'enregistrement '.
- __FILE__.':'.__LINE__.' '.
- $e->getMessage().$e->getTrace();
- $this->db->rollback();
- exit();
- }
- $this->db->commit();
- return $internal;
- }
-
- public function update() {
- echo " Acc_Ledger_Purchase::update Not implemented ";
- }
-
- public function load() {
- echo " Acc_Ledger_Purchase::load Not implemented ";
-
- }
-
- public function delete() {
- echo " Acc_Ledger_Purchase::delete Not implemented ";
- }
- /*!\brief display the form for entering data for invoice
- *\param $p_array is null or you can put the predef operation or the $_POST
-\code
-array
- 'sa' => string 'n' (length=1)
- 'p_action' => string 'ach' (length=3)
- 'gDossier' => string '28' (length=2)
- 'e_client' => string 'ASEKURA' (length=7)
- 'nb_item' => string '9' (length=1)
- 'p_jrn' => string '3' (length=1)
- 'period' => string '126' (length=3)
- 'e_comm' => string 'descriptio' (length=10)
- 'e_date' => string '01.05.2010' (length=10)
- 'e_ech' => string '' (length=0)
- 'jrn_type' => string 'ACH' (length=3)
- 'e_pj' => string 'ACH37' (length=5)
- 'e_pj_suggest' => string 'ACH37' (length=5)
- 'mt' => string '1273759434.5701' (length=15)
- 'e_mp' => string '0' (length=1)
- 'e_march0' => string 'DOC' (length=3)
- 'e_march0_price' => string '2000' (length=4)
- 'e_march0_tva_id' => string '3' (length=1)
- 'e_march0_tva_amount' => string '120' (length=3)
- 'e_quant0' => string '1' (length=1)
- 'gen_invoice' => string 'on' (length=2)
- 'gen_doc' => string '7' (length=1)
- 'bon_comm' => string '' (length=0)
- 'other_info' => string '' (length=0)
- 'correct' => string 'Corriger' (length=8)
-\endcode
- *\return HTML string
- */
- public function input($p_array=null) {
- if ( $p_array != null ) extract($p_array);
-
- $user = new User($this->db);
- $owner=new Own($this->db);
- $flag_tva=$owner->MY_TVA_USE;
- /* Add button */
- $f_add_button=new IButton('add_card');
- $f_add_button->label=_('Créer une nouvelle fiche');
- $f_add_button->set_attribute('ipopup','ipop_newcard');
- $f_add_button->set_attribute('jrn',$this->id);
- $f_add_button->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
-
- $f_add_button2=new IButton('add_card2');
- $f_add_button2->label=_('Créer une nouvelle fiche');
- $f_add_button2->set_attribute('ipopup','ipop_newcard');
- $f_add_button2->set_attribute('filter',$this->get_all_fiche_def ());
- // $f_add_button2->set_attribute('jrn',$this->id);
- $f_add_button2->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
-
- $str_add_button=$f_add_button->input();
- $str_add_button2=$f_add_button2->input();
-
- // The first day of the periode
- $oPeriode=new Periode($this->db);
- list ($l_date_start,$l_date_end)=$oPeriode->get_date_limit($user->get_periode());
- if ( $owner->MY_DATE_SUGGEST=='Y' )
- $op_date=( ! isset($e_date) ) ?$l_date_start:$e_date;
- else
- $op_date=( ! isset($e_date) ) ?'':$e_date;
-
- $e_ech=(isset($e_ech))?$e_ech:"";
- $e_comm=(isset($e_comm))?$e_comm:"";
-
- $r="";
- $r.=dossier::hidden();
- $f_legend=_("En-tête facture fournisseur");
- $f_legend_detail=_("Détail articles acheté");
-
- // Date
- //--
- $Date=new IDate();
- $Date->setReadOnly(false);
- $Date->table=1;
- $Date->tabindex=1;
- $f_date=$Date->input("e_date",$op_date);
- // Payment limit
- //--
- $Echeance=new IDate();
- $Echeance->setReadOnly(false);
- $Echeance->tabindex=2;
- $label=HtmlInput::infobulle(4);
- $f_echeance=$Echeance->input('e_ech',$e_ech,'Echéance'.$label);
- $f_periode="";
- if ($this->check_periode() == true) {
- // Periode
- //--
- $l_user_per=$user->get_periode();
- $def=(isset($periode))?$periode:$l_user_per;
-
- $period=new IPeriod("period");
- $period->user=$user;
- $period->cn=$this->db;
- $period->value=$def;
- $period->type=OPEN;
- try {
- $l_form_per=$period->input();
- } catch (Exception $e) {
- if ($e->getCode() == 1 ) {
- echo _("Aucune période ouverte");
- exit();
- }
- }
-
- $r.=" ";
- $label=HtmlInput::infobulle(3);
- $f_periode=_("Période comptable")." $label ".$l_form_per;
- }
- // Ledger (p_jrn)
- //--
- /* if we suggest the next pj, then we need a javascript */
- $add_js="";
- if ( $owner->MY_PJ_SUGGEST=='Y') {
- $add_js="update_pj();";
- }
- $add_js.='get_last_date();';
-
- $wLedger=$this->select_ledger('ACH',2);
- if ($wLedger == null) exit (_('Pas de journal disponible'));
- $wLedger->javascript="onChange='update_predef(\"ach\",\"f\");$add_js'";
- $label=" Journal ".HtmlInput::infobulle(2) ;
-
- $f_jrn=$wLedger->input();
-
- // Comment
- //--
- $Commentaire=new IText();
- $Commentaire->table=0;
- $Commentaire->setReadOnly(false);
- $Commentaire->size=60;
- $Commentaire->tabindex=3;
- $label=HtmlInput::infobulle(1) ;
- $f_desc=$label.$Commentaire->input("e_comm",h($e_comm));
-
- // PJ
- //--
- /* suggest PJ ? */
- $default_pj='';
- if ( $owner->MY_PJ_SUGGEST=='Y') {
- $default_pj=$this->guess_pj();
+ public function update()
+ {
+ echo " Acc_Ledger_Purchase::update Not implemented ";
}
- $pj=new IText();
- $pj->value=(isset($e_pj))?$e_pj:$default_pj;
-
-
- $pj->table=0;
- $pj->name="e_pj";
- $pj->size=10;
- $pj->readonly=false;
-
- $f_pj=$pj->input().HtmlInput::hidden('e_pj_suggest',$default_pj);
-
- // Display the customer
- //--
- $fiche='cred';
-
- // Save old value and set a new one
- //--
- $e_client=( isset ($e_client) )?$e_client:"";
- $e_client_label=" ";//str_pad("",100,".");
-
-
- // retrieve e_client_label
- //--
-
- if ( strlen(trim($e_client)) != 0) {
- $fClient=new Fiche($this->db);
- $fClient->get_by_qcode($e_client);
- $e_client_label=$fClient->strAttribut(ATTR_DEF_NAME).' '.
- ' Adresse : '.$fClient->strAttribut(ATTR_DEF_ADRESS).' '.
- $fClient->strAttribut(ATTR_DEF_CP).' '.
- $fClient->strAttribut(ATTR_DEF_CITY).' ';
-
+ public function load()
+ {
+ echo " Acc_Ledger_Purchase::load Not implemented ";
}
- $W1=new ICard();
- $W1->label=_("Fournisseur ").HtmlInput::infobulle(0) ;
- $W1->name="e_client";
- $W1->tabindex=3;
- $W1->value=$e_client;
- $W1->table=0;
- $W1->set_dblclick("fill_ipopcard(this);");
- $W1->set_attribute('ipopup','ipopcard');
-
- // name of the field to update with the name of the card
- $W1->set_attribute('label','e_client_label');
- // name of the field to update with the name of the card
- $W1->set_attribute('typecard','cred');
- $W1->extra='cred';
- // Add the callback function to filter the card on the jrn
- $W1->set_callback('filter_card');
- $W1->set_function('fill_data');
- $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
- $W1->name);
- $f_client_qcode=$W1->input();
- $client_label=new ISpan();
- $client_label->table=0;
- $f_client=$client_label->input("e_client_label",$e_client_label);
- $f_client_bt=$W1->search();
-
-
- // Record the current number of article
- $Hid=new IHidden();
- $p_article= ( isset ($nb_item))?$nb_item:MAX_ARTICLE;
- $r.=$Hid->input("nb_item",$p_article);
- $e_comment=(isset($e_comment))?$e_comment:"";
- $max=($p_article < MAX_ARTICLE)?MAX_ARTICLE:$p_article;
-
- // For each article
- //--
- for ($i=0;$i< $max ;$i++) {
- // Code id, price & vat code
- //--
- $march=(isset(${"e_march$i"}))?${"e_march$i"}:"";
- $march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:"";
- /* use vat */
- if ( $owner->MY_TVA_USE=='Y') {
- $march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
- $march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:"";
- }
-
-
-
- $march_label=" ";
- // retrieve the tva label and name
- //--
- if ( strlen(trim($march))!=0 ) {
- $fMarch=new Fiche($this->db);
- $fMarch->get_by_qcode($march);
- $march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
- /* vat use */
- if ( ! isset($march_tva_id) && $owner->MY_TVA_USE=='Y' )
- $march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
- }
- // Show input
- //--
- $W1=new ICard();
- $W1->label="";
- $W1->name="e_march".$i;
- $W1->value=$march;
- $W1->table=1;
- $W1->set_dblclick("fill_ipopcard(this);");
- $W1->set_attribute('ipopup','ipopcard');
-
- $W1->set_attribute('typecard','deb');
- $W1->extra='deb'; // debits
- // name of the field to update with the name of the card
- $W1->set_attribute('label','e_march'.$i.'_label');
- // name of the field with the price
- $W1->set_attribute('purchase','e_march'.$i.'_price'); /* autocomplete */
- $W1->set_attribute('price','e_march'.$i.'_price'); /* via search */
-
- // name of the field with the TVA_ID
- $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
- // Add the callback function to filter the card on the jrn
- $W1->set_callback('filter_card');
- $W1->set_function('fill_data');
- $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
- $W1->name);
- $W1->readonly=false;
- $array[$i]['quick_code']=$W1->input();
- $array[$i]['bt']=$W1->search();
-
- $array[$i]['hidden']='';
- // For computing we need some hidden field for holding the value
- if ( $owner->MY_TVA_USE=='Y') {
- $array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
- }
-
- if ( $owner->MY_TVA_USE=='Y')
- $tvac=new INum('tvac_march'.$i);
- else
- $tvac=new IHidden('tvac_march'.$i);
-
- $tvac->readOnly=1;
- $tvac->value=0;
- $array[$i]['tvac']=$tvac->input();
-
- $htva=new INum('htva_march'.$i);
- $htva->readOnly=1;
-
- $htva->value=0;
- $array[$i]['htva']=$htva->input();
-
- $Span=new ISpan();
- $Span->setReadOnly(false);
- // card's name, price
- //--
- $array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
- // price
- $Price=new INum();
- $Price->setReadOnly(false);
- $Price->size=9;
- $Price->javascript="onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
- $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
- if ( $owner->MY_TVA_USE=='Y') {
-
- // vat label
- //--
- $Tva=new ITva_Popup($this->db);
- $Tva->js="onblur=\"format_number(this);onChange=clean_tva($i);compute_ledger($i)\"";
- $Tva->in_table=true;
- $Tva->set_attribute('compute',$i);
- $Tva->value=$march_tva_id;
- $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
-
- // Tva_amount
-
- // price
- $Tva_amount=new INum();
- $Tva_amount->setReadOnly(false);
- $Tva_amount->size=9;
- $Tva_amount->javascript="onBlur='format_number(this);compute_ledger($i)'";
- $array[$i]['amount_tva']=$Tva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
- }
- // quantity
- //--
- $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1";
- $Quantity=new INum();
- $Quantity->setReadOnly(false);
- $Quantity->size=9;
- $Quantity->javascript="onChange=format_number(this);clean_tva($i);compute_ledger($i)";
- $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
-
+ public function delete()
+ {
+ echo " Acc_Ledger_Purchase::delete Not implemented ";
}
- $f_type=_('Fournisseur');
+ /*!\brief display the form for entering data for invoice
+ *\param $p_array is null or you can put the predef operation or the $_POST
+ \code
+ array
+ 'sa' => string 'n' (length=1)
+ 'p_action' => string 'ach' (length=3)
+ 'gDossier' => string '28' (length=2)
+ 'e_client' => string 'ASEKURA' (length=7)
+ 'nb_item' => string '9' (length=1)
+ 'p_jrn' => string '3' (length=1)
+ 'period' => string '126' (length=3)
+ 'e_comm' => string 'descriptio' (length=10)
+ 'e_date' => string '01.05.2010' (length=10)
+ 'e_ech' => string '' (length=0)
+ 'jrn_type' => string 'ACH' (length=3)
+ 'e_pj' => string 'ACH37' (length=5)
+ 'e_pj_suggest' => string 'ACH37' (length=5)
+ 'mt' => string '1273759434.5701' (length=15)
+ 'e_mp' => string '0' (length=1)
+ 'e_march0' => string 'DOC' (length=3)
+ 'e_march0_price' => string '2000' (length=4)
+ 'e_march0_tva_id' => string '3' (length=1)
+ 'e_march0_tva_amount' => string '120' (length=3)
+ 'e_quant0' => string '1' (length=1)
+ 'gen_invoice' => string 'on' (length=2)
+ 'gen_doc' => string '7' (length=1)
+ 'bon_comm' => string '' (length=0)
+ 'other_info' => string '' (length=0)
+ 'correct' => string 'Corriger' (length=8)
+ \endcode
+ *\return HTML string
+ */
+ public function input($p_array=null)
+ {
+ if ( $p_array != null ) extract($p_array);
- ob_start();
- require_once('template/form_ledger_detail.php');
- $r.=ob_get_contents();
- ob_clean();
+ $user = new User($this->db);
+ $owner=new Own($this->db);
+ $flag_tva=$owner->MY_TVA_USE;
+ /* Add button */
+ $f_add_button=new IButton('add_card');
+ $f_add_button->label=_('Créer une nouvelle fiche');
+ $f_add_button->set_attribute('ipopup','ipop_newcard');
+ $f_add_button->set_attribute('jrn',$this->id);
+ $f_add_button->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
- // Set correctly the REQUEST param for jrn_type
- $r.= HtmlInput::hidden('jrn_type','ACH');
- $r.= HtmlInput::button('add_item',_('Ajout article'), ' onClick="ledger_add_row()"');
+ $f_add_button2=new IButton('add_card2');
+ $f_add_button2->label=_('Créer une nouvelle fiche');
+ $f_add_button2->set_attribute('ipopup','ipop_newcard');
+ $f_add_button2->set_attribute('filter',$this->get_all_fiche_def ());
+ // $f_add_button2->set_attribute('jrn',$this->id);
+ $f_add_button2->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
+
+ $str_add_button=$f_add_button->input();
+ $str_add_button2=$f_add_button2->input();
+
+ // The first day of the periode
+ $oPeriode=new Periode($this->db);
+ list ($l_date_start,$l_date_end)=$oPeriode->get_date_limit($user->get_periode());
+ if ( $owner->MY_DATE_SUGGEST=='Y' )
+ $op_date=( ! isset($e_date) ) ?$l_date_start:$e_date;
+ else
+ $op_date=( ! isset($e_date) ) ?'':$e_date;
+
+ $e_ech=(isset($e_ech))?$e_ech:"";
+ $e_comm=(isset($e_comm))?$e_comm:"";
+
+ $r="";
+ $r.=dossier::hidden();
+ $f_legend=_("En-tête facture fournisseur");
+ $f_legend_detail=_("Détail articles acheté");
+
+ // Date
+ //--
+ $Date=new IDate();
+ $Date->setReadOnly(false);
+ $Date->table=1;
+ $Date->tabindex=1;
+ $f_date=$Date->input("e_date",$op_date);
+ // Payment limit
+ //--
+ $Echeance=new IDate();
+ $Echeance->setReadOnly(false);
+ $Echeance->tabindex=2;
+ $label=HtmlInput::infobulle(4);
+ $f_echeance=$Echeance->input('e_ech',$e_ech,'Echéance'.$label);
+ $f_periode="";
+ if ($this->check_periode() == true)
+ {
+ // Periode
+ //--
+ $l_user_per=$user->get_periode();
+ $def=(isset($periode))?$periode:$l_user_per;
+
+ $period=new IPeriod("period");
+ $period->user=$user;
+ $period->cn=$this->db;
+ $period->value=$def;
+ $period->type=OPEN;
+ try
+ {
+ $l_form_per=$period->input();
+ }
+ catch (Exception $e)
+ {
+ if ($e->getCode() == 1 )
+ {
+ echo _("Aucune période ouverte");
+ exit();
+ }
+ }
+
+ $r.=" ";
+ $label=HtmlInput::infobulle(3);
+ $f_periode=_("Période comptable")." $label ".$l_form_per;
+ }
+ // Ledger (p_jrn)
+ //--
+ /* if we suggest the next pj, then we need a javascript */
+ $add_js="";
+ if ( $owner->MY_PJ_SUGGEST=='Y')
+ {
+ $add_js="update_pj();";
+ }
+ $add_js.='get_last_date();';
+
+ $wLedger=$this->select_ledger('ACH',2);
+ if ($wLedger == null) exit (_('Pas de journal disponible'));
+ $wLedger->javascript="onChange='update_predef(\"ach\",\"f\");$add_js'";
+ $label=" Journal ".HtmlInput::infobulle(2) ;
+
+ $f_jrn=$wLedger->input();
+
+ // Comment
+ //--
+ $Commentaire=new IText();
+ $Commentaire->table=0;
+ $Commentaire->setReadOnly(false);
+ $Commentaire->size=60;
+ $Commentaire->tabindex=3;
+ $label=HtmlInput::infobulle(1) ;
+ $f_desc=$label.$Commentaire->input("e_comm",h($e_comm));
+
+ // PJ
+ //--
+ /* suggest PJ ? */
+ $default_pj='';
+ if ( $owner->MY_PJ_SUGGEST=='Y')
+ {
+ $default_pj=$this->guess_pj();
+ }
+
+ $pj=new IText();
+ $pj->value=(isset($e_pj))?$e_pj:$default_pj;
+
+
+ $pj->table=0;
+ $pj->name="e_pj";
+ $pj->size=10;
+ $pj->readonly=false;
+
+ $f_pj=$pj->input().HtmlInput::hidden('e_pj_suggest',$default_pj);
+
+ // Display the customer
+ //--
+ $fiche='cred';
+
+ // Save old value and set a new one
+ //--
+ $e_client=( isset ($e_client) )?$e_client:"";
+ $e_client_label=" ";//str_pad("",100,".");
+
+
+ // retrieve e_client_label
+ //--
+
+ if ( strlen(trim($e_client)) != 0)
+ {
+ $fClient=new Fiche($this->db);
+ $fClient->get_by_qcode($e_client);
+ $e_client_label=$fClient->strAttribut(ATTR_DEF_NAME).' '.
+ ' Adresse : '.$fClient->strAttribut(ATTR_DEF_ADRESS).' '.
+ $fClient->strAttribut(ATTR_DEF_CP).' '.
+ $fClient->strAttribut(ATTR_DEF_CITY).' ';
+
+
+ }
+
+ $W1=new ICard();
+ $W1->label=_("Fournisseur ").HtmlInput::infobulle(0) ;
+ $W1->name="e_client";
+ $W1->tabindex=3;
+ $W1->value=$e_client;
+ $W1->table=0;
+ $W1->set_dblclick("fill_ipopcard(this);");
+ $W1->set_attribute('ipopup','ipopcard');
+
+ // name of the field to update with the name of the card
+ $W1->set_attribute('label','e_client_label');
+ // name of the field to update with the name of the card
+ $W1->set_attribute('typecard','cred');
+ $W1->extra='cred';
+ // Add the callback function to filter the card on the jrn
+ $W1->set_callback('filter_card');
+ $W1->set_function('fill_data');
+ $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+ $W1->name);
+ $f_client_qcode=$W1->input();
+ $client_label=new ISpan();
+ $client_label->table=0;
+ $f_client=$client_label->input("e_client_label",$e_client_label);
+ $f_client_bt=$W1->search();
+
+
+ // Record the current number of article
+ $Hid=new IHidden();
+ $p_article= ( isset ($nb_item))?$nb_item:MAX_ARTICLE;
+ $r.=$Hid->input("nb_item",$p_article);
+ $e_comment=(isset($e_comment))?$e_comment:"";
+ $max=($p_article < MAX_ARTICLE)?MAX_ARTICLE:$p_article;
+
+ // For each article
+ //--
+ for ($i=0;$i< $max ;$i++)
+ {
+ // Code id, price & vat code
+ //--
+ $march=(isset(${"e_march$i"}))?${"e_march$i"}:""
+ ;
+ $march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""
+ ;
+ /* use vat */
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ $march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:""
+ ;
+ $march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:""
+ ;
+ }
- /* if we suggest the pj n# the run the script */
- if ( $owner->MY_PJ_SUGGEST=='Y') {
- $r.='';
+ $march_label=" ";
+ // retrieve the tva label and name
+ //--
+ if ( strlen(trim($march))!=0 )
+ {
+ $fMarch=new Fiche($this->db);
+ $fMarch->get_by_qcode($march);
+ $march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
+ /* vat use */
+ if ( ! isset($march_tva_id) && $owner->MY_TVA_USE=='Y' )
+ $march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
+ }
+ // Show input
+ //--
+ $W1=new ICard();
+ $W1->label="";
+ $W1->name="e_march".$i;
+ $W1->value=$march;
+ $W1->table=1;
+ $W1->set_dblclick("fill_ipopcard(this);");
+ $W1->set_attribute('ipopup','ipopcard');
+
+ $W1->set_attribute('typecard','deb');
+ $W1->extra='deb'; // debits
+ // name of the field to update with the name of the card
+ $W1->set_attribute('label','e_march'.$i.'_label');
+ // name of the field with the price
+ $W1->set_attribute('purchase','e_march'.$i.'_price'); /* autocomplete */
+ $W1->set_attribute('price','e_march'.$i.'_price'); /* via search */
+
+ // name of the field with the TVA_ID
+ $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
+ // Add the callback function to filter the card on the jrn
+ $W1->set_callback('filter_card');
+ $W1->set_function('fill_data');
+ $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+ $W1->name);
+ $W1->readonly=false;
+ $array[$i]['quick_code']=$W1->input();
+ $array[$i]['bt']=$W1->search();
+
+ $array[$i]['hidden']='';
+ // For computing we need some hidden field for holding the value
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ $array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
+ }
+
+ if ( $owner->MY_TVA_USE=='Y')
+ $tvac=new INum('tvac_march'.$i);
+ else
+ $tvac=new IHidden('tvac_march'.$i);
+
+ $tvac->readOnly=1;
+ $tvac->value=0;
+ $array[$i]['tvac']=$tvac->input();
+
+ $htva=new INum('htva_march'.$i);
+ $htva->readOnly=1;
+
+ $htva->value=0;
+ $array[$i]['htva']=$htva->input();
+
+ $Span=new ISpan();
+ $Span->setReadOnly(false);
+ // card's name, price
+ //--
+ $array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
+ // price
+ $Price=new INum();
+ $Price->setReadOnly(false);
+ $Price->size=9;
+ $Price->javascript="onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
+ $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+
+ // vat label
+ //--
+ $Tva=new ITva_Popup($this->db);
+ $Tva->js="onblur=\"format_number(this);onChange=clean_tva($i);compute_ledger($i)\"";
+ $Tva->in_table=true;
+ $Tva->set_attribute('compute',$i);
+ $Tva->value=$march_tva_id;
+ $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
+
+ // Tva_amount
+
+ // price
+ $Tva_amount=new INum();
+ $Tva_amount->setReadOnly(false);
+ $Tva_amount->size=9;
+ $Tva_amount->javascript="onBlur='format_number(this);compute_ledger($i)'";
+ $array[$i]['amount_tva']=$Tva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
+ }
+ // quantity
+ //--
+ $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1"
+ ;
+ $Quantity=new INum();
+ $Quantity->setReadOnly(false);
+ $Quantity->size=9;
+ $Quantity->javascript="onChange=format_number(this);clean_tva($i);compute_ledger($i)";
+ $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
+
+ }
+ $f_type=_('Fournisseur');
+
+ ob_start();
+ require_once('template/form_ledger_detail.php');
+ $r.=ob_get_contents();
+ ob_clean();
+
+ // Set correctly the REQUEST param for jrn_type
+ $r.= HtmlInput::hidden('jrn_type','ACH');
+ $r.= HtmlInput::button('add_item',_('Ajout article'), ' onClick="ledger_add_row()"');
+
+
+
+ /* if we suggest the pj n# the run the script */
+ if ( $owner->MY_PJ_SUGGEST=='Y')
+ {
+ $r.='';
+ }
+ return $r;
+ }
+ function input_paid()
+ {
+ $r='';
+ $r.='';
+ $r.=' '._('Payé par').' ';
+ $mp=new Acc_Payment($this->db);
+ $mp->set_parameter('type','ACH');
+ $r.=$mp->select();
+ $r.=' ';
+ return $r;
}
- return $r;
- }
- function input_paid() {
- $r='';
- $r.='';
- $r.=' '._('Payé par').' ';
- $mp=new Acc_Payment($this->db);
- $mp->set_parameter('type','ACH');
- $r.=$mp->select();
- $r.=' ';
- return $r;
- }
- /*!\brief show the summary of the operation and propose to save it
- *\param array contains normally $_POST. It proposes also to save
- * the Analytic accountancy
- *\return string
- *\todo verify also the vat
- */
- function confirm($p_array) {
- extract ($p_array);
- $this->verify($p_array) ;
- $anc=null;
- // to show a select list for the analytic
- // if analytic is op (optionnel) there is a blank line
- $owner = new Own($this->db);
+ /*!\brief show the summary of the operation and propose to save it
+ *\param array contains normally $_POST. It proposes also to save
+ * the Analytic accountancy
+ *\return string
+ *\todo verify also the vat
+ */
+ function confirm($p_array)
+ {
+ extract ($p_array);
+ $this->verify($p_array) ;
+ $anc=null;
+ // to show a select list for the analytic
+ // if analytic is op (optionnel) there is a blank line
+ $owner = new Own($this->db);
- bcscale(4);
- $client=new Fiche($this->db);
- $client->get_by_qcode($e_client,true);
+ bcscale(4);
+ $client=new Fiche($this->db);
+ $client->get_by_qcode($e_client,true);
- $client_name=h($client->getName().
- ' '.$client->strAttribut(ATTR_DEF_ADRESS).' '.
- $client->strAttribut(ATTR_DEF_CP).' '.
- $client->strAttribut(ATTR_DEF_CITY));
- $lPeriode=new Periode($this->db);
- if ($this->check_periode() == true) {
- $lPeriode->p_id=$period;
- } else {
- $lPeriode->find_periode($e_date);
- }
- $date_limit=$lPeriode->get_date_limit();
- $r="";
- $r.="";
- $r.=""._('En-tête facture fournisseur')." ";
- $r.='';
- $r.='';
- $r.=' '._('Date').' '.$e_date.' ';
- $r.=''._('Echeance').' '.$e_ech.' ';
- $r.=' '._('Période Comptable').' '.$date_limit['p_start'].'-'.$date_limit['p_end'].' ';
- $r.=' ';
- $r.=' '._('Journal').' '.h($this->get_name()).' ';
- $r.=' ';
- $r.='';
- $r.=' '._('Libellé').' '.h($e_comm).' Pj :'.h($e_pj).' ';
- $r.=' ';
- $r.='';
- $r.=' '._('Fournisseur').' '.h($e_client.':'.$client_name).' ';
- $r.=' ';
- $r.='
';
- $r.=' ';
- $r.=''._('Détail articles achetés').' ';
- $r.='';
- $r.='';
- $r.="Code ";
- $r.=""._('Dénomination')." ";
- $r.=""._('prix')." ";
+ $client_name=h($client->getName().
+ ' '.$client->strAttribut(ATTR_DEF_ADRESS).' '.
+ $client->strAttribut(ATTR_DEF_CP).' '.
+ $client->strAttribut(ATTR_DEF_CITY));
+ $lPeriode=new Periode($this->db);
+ if ($this->check_periode() == true)
+ {
+ $lPeriode->p_id=$period;
+ }
+ else
+ {
+ $lPeriode->find_periode($e_date);
+ }
+ $date_limit=$lPeriode->get_date_limit();
+ $r="";
+ $r.="";
+ $r.=""._('En-tête facture fournisseur')." ";
+ $r.='';
+ $r.='';
+ $r.=' '._('Date').' '.$e_date.' ';
+ $r.=''._('Echeance').' '.$e_ech.' ';
+ $r.=' '._('Période Comptable').' '.$date_limit['p_start'].'-'.$date_limit['p_end'].' ';
+ $r.=' ';
+ $r.=' '._('Journal').' '.h($this->get_name()).' ';
+ $r.=' ';
+ $r.='';
+ $r.=' '._('Libellé').' '.h($e_comm).' Pj :'.h($e_pj).' ';
+ $r.=' ';
+ $r.='';
+ $r.=' '._('Fournisseur').' '.h($e_client.':'.$client_name).' ';
+ $r.=' ';
+ $r.='
';
+ $r.=' ';
+ $r.=''._('Détail articles achetés').' ';
+ $r.='';
+ $r.='';
+ $r.="Code ";
+ $r.=""._('Dénomination')." ";
+ $r.=""._('prix')." ";
/* vat use */
- if ( $owner->MY_TVA_USE=='Y') {
- $r.=""._('quantité')." ";
- $r.="tva ";
- $r.=' '._('Montant TVA').' ';
- $r.=''._('Montant HTVA').' ';
- } else {
- $r.=""._('quantité')." ";
- $r.=' '._('Total')." ";
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ $r.=""._('quantité')." ";
+ $r.="tva ";
+ $r.=' '._('Montant TVA').' ';
+ $r.=''._('Montant HTVA').' ';
+ }
+ else
+ {
+ $r.=""._('quantité')." ";
+ $r.=' '._('Total')." ";
+ }
+
+ /* if we use the AC */
+ if ($owner->MY_ANALYTIC!='nu')
+ {
+ $anc=new Anc_Plan($this->db);
+ $a_anc=$anc->get_list();
+ $x=count($a_anc);
+ /* set the width of the col */
+ $r.=''._('Compt. Analytique').' ';
+
+ /* add hidden variables pa[] to hold the value of pa_id */
+ $r.=Anc_Plan::hidden($a_anc);
+ }
+
+ $r.=' ';
+ $tot_amount=0.0;
+ $tot_tva=0.0;
+ //--
+ // For each item
+ //--
+ for ($i = 0; $i < $nb_item;$i++)
+ {
+ if ( strlen(trim(${"e_march".$i})) == 0 ) continue;
+
+ /* retrieve information for card */
+ $fiche=new Fiche($this->db);
+ $fiche->get_by_qcode(${"e_march".$i});
+ $fiche_name=h($fiche->getName());
+
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ $idx_tva=${"e_march".$i."_tva_id"};
+ $oTva=new Acc_Tva($this->db);
+ $oTva->set_parameter('id',$idx_tva);
+ $oTva->load();
+ }
+ $amount=bcmul(${"e_march".$i."_price"},${'e_quant'.$i});
+
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ //----- if tva_amount is not given we compute the vat ----
+ if ( strlen (trim (${'e_march'.$i.'_tva_amount'})) == 0)
+ {
+ $op=new Acc_Compute();
+
+ $op->set_parameter("amount",$amount);
+ $op->set_parameter('amount_vat_rate',$oTva->get_parameter('rate'));
+ $op->compute_vat();
+ $tva_item=$op->get_parameter('amount_vat');
+ }
+ else
+ $tva_item=round($
+ {'e_march'.$i.'_tva_amount'
+ }
+ ,2);
+
+ if (isset($tva[$idx_tva] ) )
+ $tva[$idx_tva]+=$tva_item;
+ else
+ $tva[$idx_tva]=$tva_item;
+ $tot_tva=round(bcadd($tva_item,$tot_tva),2);
+ }
+ $tot_amount=round(bcadd($tot_amount,$amount),2);
+
+ $r.='';
+ $r.='';
+ $r.=${"e_march".$i};
+ $r.=' ';
+ $r.='';
+ $r.=$fiche_name;
+ $r.=' ';
+ $r.='';
+ $r.=${"e_march".$i."_price"};
+ $r.=' ';
+ $r.='';
+ $r.=${"e_quant".$i};
+ $r.=' ';
+ if ($owner->MY_TVA_USE == 'Y')
+ {
+ $r.='';
+ $r.=$oTva->get_parameter('label');
+ $r.=' ';
+ $r.='';
+ $r.=$tva_item;
+ $r.=' ';
+ }
+ $r.='';
+ $r.=round($amount,2);
+ $r.=' ';
+
+ // encode the pa
+ if ( $owner->MY_ANALYTIC!='nu') // use of AA
+ {
+ // show form
+ $anc_op=new Anc_Operation($this->db);
+ $null=($owner->MY_ANALYTIC=='op')?1:0;
+ $r.='';
+ $p_mode=1;
+ $p_array['pa_id']=$a_anc;
+ /* op is the operation it contains either a sequence or a jrnx.j_id */
+ $r.=HtmlInput::hidden('op[]=',$i);
+ $r.=$anc_op->display_form_plan($p_array,$null,$p_mode,$i,$amount);
+ $r.=' ';
+ }
+
+
+ $r.=' ';
+
+ }
+
+
+ $r.='
';
+ if ( $owner->MY_ANALYTIC!='nu') // use of AA
+ $r.=' ';
+ $r.=' ';
+
+
+ $r.=' Totaux ';
+ $tot=round(bcadd($tot_amount,$tot_tva),2);
+ $r.='';
+ $r.=' '._('Total HTVA');
+ if ($owner->MY_TVA_USE=='Y')
+ {
+ foreach ($tva as $i=>$value)
+ {
+ $oTva->set_parameter('id',$i);
+ $oTva->load();
+
+ $r.=' '._('TVA à ').$oTva->get_parameter('label');
+ $r.=' '._('Total TVA');
+ }
+
+ $r.=' '._('Total TVAC');
+ }
+ $r.="
";
+
+
+ $r.='';
+ $r.=''.$tot_amount.' ';
+
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ foreach ($tva as $i=>$value)
+ {
+ $r.=' '.$tva[$i];
+ }
+ $r.=''.$tot_tva.' ';
+ $r.=''.$tot.' ';
+ }
+ $r.="
";
+
+
+
+ $r.=' ';
+ /* Add hidden */
+ $r.=HtmlInput::hidden('e_client',$e_client);
+ $r.=HtmlInput::hidden('nb_item',$nb_item);
+ $r.=HtmlInput::hidden('p_jrn',$p_jrn);
+ if ( isset($period))
+ $r.=HtmlInput::hidden('period',$period);
+ $r.=HtmlInput::hidden('e_comm',$e_comm);
+ $r.=HtmlInput::hidden('e_date',$e_date);
+ $r.=HtmlInput::hidden('e_ech',$e_ech);
+ $r.=HtmlInput::hidden('jrn_type',$jrn_type);
+ $r.=HtmlInput::hidden('e_pj',$e_pj);
+ $r.=HtmlInput::hidden('e_pj_suggest',$e_pj_suggest);
+ $mt=microtime(true);
+ $r.=HtmlInput::hidden('mt',$mt);
+
+ $e_mp=(isset($e_mp))?$e_mp:0;
+ $r.=HtmlInput::hidden('e_mp',$e_mp);
+ /* Paid by */
+ /* if the paymethod is not 0 and if a quick code is given */
+ if ( $e_mp!=0 && strlen (trim (${'e_mp_qcode_'.$e_mp})) != 0 )
+ {
+ $r.=HtmlInput::hidden('e_mp_qcode_'.$e_mp,${'e_mp_qcode_'.$e_mp});
+
+ /* needed for generating a invoice */
+ $r.=HtmlInput::hidden('qcode_benef',${'e_mp_qcode_'.$e_mp});
+
+ $r.="Payé par ".${'e_mp_qcode_'.$e_mp};
+ $r.=' ';
+ }
+ for ($i=0;$i < $nb_item;$i++)
+ {
+ $r.=HtmlInput::hidden("e_march".$i,${"e_march".$i});
+ $r.=HtmlInput::hidden("e_march".$i."_price",${"e_march".$i."_price"});
+ if ( $owner->MY_TVA_USE=='Y' )
+ {
+ $r.=HtmlInput::hidden("e_march".$i."_tva_id",${"e_march".$i."_tva_id"});
+ $r.=HtmlInput::hidden('e_march'.$i.'_tva_amount', ${'e_march'.$i.'_tva_amount'});
+ }
+ $r.=HtmlInput::hidden("e_quant".$i,${"e_quant".$i});
+
+ }
+ // check for upload piece
+ $r.=HtmlInput::warnbulle(12);
+ $r.=$this->extra_info();
+
+ return $r;
}
- /* if we use the AC */
- if ($owner->MY_ANALYTIC!='nu') {
- $anc=new Anc_Plan($this->db);
- $a_anc=$anc->get_list();
- $x=count($a_anc);
- /* set the width of the col */
- $r.=''._('Compt. Analytique').' ';
+ /*!\brief the function extra info allows to
+ * - add a attachment
+ * - generate an invoice
+ * - insert extra info
+ *\return html string
+ */
+ public function extra_info()
+ {
+ $r="";
+ $r.='';
+ $r.='
'._('Document à générer').' ';
+ // check for upload piece
+ $file=new IFile();
+ $file->table=0;
+ $r.=_("Ajoutez une pièce justificative ");
+ $r.=$file->input("pj","");
- /* add hidden variables pa[] to hold the value of pa_id */
- $r.=Anc_Plan::hidden($a_anc);
- }
+ if ( $this->db->count_sql("select md_id,md_name from document_modele where md_affect='ACH'") > 0 )
+ {
- $r.=' ';
- $tot_amount=0.0;
- $tot_tva=0.0;
- //--
- // For each item
- //--
- for ($i = 0; $i < $nb_item;$i++) {
- if ( strlen(trim(${"e_march".$i})) == 0 ) continue;
-
- /* retrieve information for card */
- $fiche=new Fiche($this->db);
- $fiche->get_by_qcode(${"e_march".$i});
- $fiche_name=h($fiche->getName());
-
- if ( $owner->MY_TVA_USE=='Y') {
- $idx_tva=${"e_march".$i."_tva_id"};
- $oTva=new Acc_Tva($this->db);
- $oTva->set_parameter('id',$idx_tva);
- $oTva->load();
- }
- $amount=bcmul(${"e_march".$i."_price"},${'e_quant'.$i});
-
- if ( $owner->MY_TVA_USE=='Y') {
- //----- if tva_amount is not given we compute the vat ----
- if ( strlen (trim (${'e_march'.$i.'_tva_amount'})) == 0) {
- $op=new Acc_Compute();
-
- $op->set_parameter("amount",$amount);
- $op->set_parameter('amount_vat_rate',$oTva->get_parameter('rate'));
- $op->compute_vat();
- $tva_item=$op->get_parameter('amount_vat');
- } else
- $tva_item=round(${'e_march'.$i.'_tva_amount'},2);
-
- if (isset($tva[$idx_tva] ) )
- $tva[$idx_tva]+=$tva_item;
- else
- $tva[$idx_tva]=$tva_item;
- $tot_tva=round(bcadd($tva_item,$tot_tva),2);
- }
- $tot_amount=round(bcadd($tot_amount,$amount),2);
-
- $r.='';
- $r.='';
- $r.=${"e_march".$i};
- $r.=' ';
- $r.='';
- $r.=$fiche_name;
- $r.=' ';
- $r.='';
- $r.=${"e_march".$i."_price"};
- $r.=' ';
- $r.='';
- $r.=${"e_quant".$i};
- $r.=' ';
- if ($owner->MY_TVA_USE == 'Y') {
- $r.='';
- $r.=$oTva->get_parameter('label');
- $r.=' ';
- $r.='';
- $r.=$tva_item;
- $r.=' ';
- }
- $r.='';
- $r.=round($amount,2);
- $r.=' ';
-
- // encode the pa
- if ( $owner->MY_ANALYTIC!='nu') // use of AA
- {
- // show form
- $anc_op=new Anc_Operation($this->db);
- $null=($owner->MY_ANALYTIC=='op')?1:0;
- $r.='';
- $p_mode=1;
- $p_array['pa_id']=$a_anc;
- /* op is the operation it contains either a sequence or a jrnx.j_id */
- $r.=HtmlInput::hidden('op[]=',$i);
- $r.=$anc_op->display_form_plan($p_array,$null,$p_mode,$i,$amount);
- $r.=' ';
- }
-
-
- $r.=' ';
+ $r.=' ';
+ $r.=_('ou générer un document').' ';
+ // We propose to generate the fee note
+ $doc_gen=new ISelect();
+ $doc_gen->name="gen_doc";
+ $doc_gen->value=$this->db->make_array(
+ "select md_id,md_name ".
+ " from document_modele where md_affect='ACH'");
+ $r.=$doc_gen->input().' ';
+ }
+ $r.=' ';
+ $obj=new IText();
+ $r.=_('Numero de bon de commande : ').$obj->input('bon_comm').' ';
+ $r.=_('Autre information : ').$obj->input('other_info').' ';
+ $r.="";
+ $r.='';
+ return $r;
}
- $r.='
';
- if ( $owner->MY_ANALYTIC!='nu') // use of AA
- $r.=' ';
- $r.=' ';
+ /*!\brief update the payment
+ */
+ function show_unpaid()
+ {
+ // Show list of unpaid sell
+ // Date - date of payment - Customer - amount
+ // Nav. bar
+ $step=$_SESSION['g_pagesize'];
+ $page=(isset($_GET['offset']))?$_GET['page']:1;
+ $offset=(isset($_GET['offset']))?$_GET['offset']:0;
- $r.=' Totaux ';
- $tot=round(bcadd($tot_amount,$tot_tva),2);
- $r.='';
- $r.=' '._('Total HTVA');
- if ($owner->MY_TVA_USE=='Y') {
- foreach ($tva as $i=>$value) {
- $oTva->set_parameter('id',$i);
- $oTva->load();
+ $sql=SQL_LIST_UNPAID_INVOICE_DATE_LIMIT." and jr_def_id=".$this->id ;
+ list($max_line,$list)=ListJrn($this->db,$sql,null,$offset,1);
+ $sql=SQL_LIST_UNPAID_INVOICE." and jr_def_id=".$this->id ;
+ list($max_line2,$list2)=ListJrn($this->db,$sql,null,$offset,1);
- $r.=' '._('TVA à ').$oTva->get_parameter('label');
- $r.=' '._('Total TVA');
- }
+ // Get the max line
+ $m=($max_line2>$max_line)?$max_line2:$max_line;
+ $bar2=jrn_navigation_bar($offset,$m,$step,$page);
- $r.=' '._('Total TVAC');
- }
- $r.="
";
+ echo $bar2;
+ echo ' '._('Echeance dépassée').' ';
+ echo $list;
+ echo ' '._('Non Payée').' ';
+ echo $list2;
+ echo $bar2;
+ // Add hidden parameter
+ $hid=new IHidden();
+ echo ' ';
- $r.='';
- $r.=''.$tot_amount.' ';
+ if ( $m != 0 )
+ echo HtmlInput::submit('paid',_('Mise à jour paiement'));
- if ( $owner->MY_TVA_USE=='Y') {
- foreach ($tva as $i=>$value) {
- $r.=' '.$tva[$i];
- }
- $r.=''.$tot_tva.' ';
- $r.=''.$tot.' ';
- }
- $r.="
";
-
-
-
- $r.=' ';
- /* Add hidden */
- $r.=HtmlInput::hidden('e_client',$e_client);
- $r.=HtmlInput::hidden('nb_item',$nb_item);
- $r.=HtmlInput::hidden('p_jrn',$p_jrn);
- if ( isset($period))
- $r.=HtmlInput::hidden('period',$period);
- $r.=HtmlInput::hidden('e_comm',$e_comm);
- $r.=HtmlInput::hidden('e_date',$e_date);
- $r.=HtmlInput::hidden('e_ech',$e_ech);
- $r.=HtmlInput::hidden('jrn_type',$jrn_type);
- $r.=HtmlInput::hidden('e_pj',$e_pj);
- $r.=HtmlInput::hidden('e_pj_suggest',$e_pj_suggest);
- $mt=microtime(true);
- $r.=HtmlInput::hidden('mt',$mt);
-
- $e_mp=(isset($e_mp))?$e_mp:0;
- $r.=HtmlInput::hidden('e_mp',$e_mp);
- /* Paid by */
- /* if the paymethod is not 0 and if a quick code is given */
- if ( $e_mp!=0 && strlen (trim (${'e_mp_qcode_'.$e_mp})) != 0 ) {
- $r.=HtmlInput::hidden('e_mp_qcode_'.$e_mp,${'e_mp_qcode_'.$e_mp});
-
- /* needed for generating a invoice */
- $r.=HtmlInput::hidden('qcode_benef',${'e_mp_qcode_'.$e_mp});
-
- $r.="Payé par ".${'e_mp_qcode_'.$e_mp};
- $r.=' ';
- }
- for ($i=0;$i < $nb_item;$i++) {
- $r.=HtmlInput::hidden("e_march".$i,${"e_march".$i});
- $r.=HtmlInput::hidden("e_march".$i."_price",${"e_march".$i."_price"});
- if ( $owner->MY_TVA_USE=='Y' ) {
- $r.=HtmlInput::hidden("e_march".$i."_tva_id",${"e_march".$i."_tva_id"});
- $r.=HtmlInput::hidden('e_march'.$i.'_tva_amount', ${'e_march'.$i.'_tva_amount'});
- }
- $r.=HtmlInput::hidden("e_quant".$i,${"e_quant".$i});
}
- // check for upload piece
- $r.=HtmlInput::warnbulle(12);
- $r.=$this->extra_info();
-
- return $r;
- }
-
- /*!\brief the function extra info allows to
- * - add a attachment
- * - generate an invoice
- * - insert extra info
- *\return html string
- */
- public function extra_info() {
- $r="";
- $r.='';
- $r.='
'._('Document à générer').' ';
- // check for upload piece
- $file=new IFile();
- $file->table=0;
- $r.=_("Ajoutez une pièce justificative ");
- $r.=$file->input("pj","");
-
- if ( $this->db->count_sql("select md_id,md_name from document_modele where md_affect='ACH'") > 0 )
- {
-
- $r.=' ';
- $r.=_('ou générer un document').' ';
- // We propose to generate the fee note
- $doc_gen=new ISelect();
- $doc_gen->name="gen_doc";
- $doc_gen->value=$this->db->make_array(
- "select md_id,md_name ".
- " from document_modele where md_affect='ACH'");
- $r.=$doc_gen->input().' ';
- }
- $r.=' ';
- $obj=new IText();
- $r.=_('Numero de bon de commande : ').$obj->input('bon_comm').' ';
- $r.=_('Autre information : ').$obj->input('other_info').' ';
-
- $r.=" ";
- $r.='';
- return $r;
- }
-
-
- /*!\brief update the payment
- */
- function show_unpaid() {
- // Show list of unpaid sell
- // Date - date of payment - Customer - amount
- // Nav. bar
- $step=$_SESSION['g_pagesize'];
- $page=(isset($_GET['offset']))?$_GET['page']:1;
- $offset=(isset($_GET['offset']))?$_GET['offset']:0;
-
-
- $sql=SQL_LIST_UNPAID_INVOICE_DATE_LIMIT." and jr_def_id=".$this->id ;
- list($max_line,$list)=ListJrn($this->db,$sql,null,$offset,1);
- $sql=SQL_LIST_UNPAID_INVOICE." and jr_def_id=".$this->id ;
- list($max_line2,$list2)=ListJrn($this->db,$sql,null,$offset,1);
-
- // Get the max line
- $m=($max_line2>$max_line)?$max_line2:$max_line;
- $bar2=jrn_navigation_bar($offset,$m,$step,$page);
-
- echo $bar2;
- echo ' '._('Echeance dépassée').' ';
- echo $list;
- echo ' '._('Non Payée').' ';
- echo $list2;
- echo $bar2;
- // Add hidden parameter
- $hid=new IHidden();
-
- echo ' ';
-
- if ( $m != 0 )
- echo HtmlInput::submit('paid',_('Mise à jour paiement'));
-
-
- }
}
diff --git a/include/class_acc_ledger_sold.php b/include/class_acc_ledger_sold.php
index c3b06f7ea..1d019d060 100644
--- a/include/class_acc_ledger_sold.php
+++ b/include/class_acc_ledger_sold.php
@@ -44,1131 +44,1226 @@ require_once('class_itva_popup.php');
*
*
*/
-class Acc_Ledger_Sold extends Acc_Ledger {
- function __construct ($p_cn,$p_init) {
- parent::__construct($p_cn,$p_init);
- $this->type='VEN';
- }
- /*!\brief verify that the data are correct before inserting or confirming
- *\param an array (usually $_POST)
- *\return String
- *\throw Exception if an error occurs
- */
- public function verify($p_array) {
- extract ($p_array);
- /* check for a double reload */
- if ( isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1',array($mt)) != 0 )
- throw new Exception (_('Double Encodage'),5);
-
- /* check if we can write into this ledger */
- $user=new User($this->db);
- if ( $user->check_jrn($p_jrn) != 'W' )
- throw new Exception (_('Accès interdit'),20);
-
- /* check if there is a customer */
- if ( strlen(trim($e_client)) == 0 )
- throw new Exception(_('Vous n\'avez pas donné de client'),11);
-
- /* check if the date is valid */
- if ( isDate($e_date) == null ) {
- throw new Exception(_('Date invalide'), 2);
+class Acc_Ledger_Sold extends Acc_Ledger
+{
+ function __construct ($p_cn,$p_init)
+ {
+ parent::__construct($p_cn,$p_init);
+ $this->type='VEN';
}
-
- $oPeriode=new Periode($this->db);
- if ( $this->check_periode() == true) {
- $tperiode=$period;
- /* check that the datum is in the choosen periode */
- $oPeriode->p_id=$period;
- list ($min,$max)=$oPeriode->get_date_limit();
-
- if ( cmpDate($e_date,$min) < 0 ||
- cmpDate($e_date,$max) > 0)
- throw new Exception(_('Date et periode ne correspondent pas'),6);
- } else {
- $per=new Periode($this->db);
- $tperiode=$per->find_periode($e_date);
- }
-
- /* check if the periode is closed */
- if ( $this->is_closed($tperiode)==1 )
- {
- throw new Exception(_('Periode fermee'),6);
- }
- /* check if we are using the strict mode */
- if( $this->check_strict() == true) {
- /* if we use the strict mode, we get the date of the last
- operation */
- $last_date=$this->get_last_date();
- if ( $last_date != null && cmpDate($e_date,$last_date) < 0 )
- throw new Exception(_('Vous utilisez le mode strict la dernière operation est date du ')
- .$last_date._(' vous ne pouvez pas encoder à une date antérieure'),13);
-
- }
-
-
- $fiche=new Fiche($this->db);
- $fiche->get_by_qcode($e_client);
- if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
- throw new Exception(_('La fiche ').$e_client._('n\'a pas de poste comptable'),8);
-
- /* get the account and explode if necessary */
- $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
- // if 2 accounts, take only the debit one for customer
- if ( strpos($sposte,',') != 0 ) {
- $array=explode(',',$sposte);
- $poste_val=$array[0];
- } else {
- $poste_val=$sposte;
- }
- /* The account exists */
-
- $poste=new Acc_Account_Ledger($this->db,$poste_val);
-
- if ( $poste->load() == false ){
- throw new Exception(_('Pour la fiche ').$e_client._(' le poste comptable [').$poste->id._('] n\'existe pas'),9);
- }
-
- /* Check if the card belong to the ledger */
- $fiche=new Fiche ($this->db);
- $fiche->get_by_qcode($e_client,'deb');
- if ( $fiche->belong_ledger($p_jrn) !=1 )
- throw new Exception(_('La fiche ').$e_client._('n\'est pas accessible à ce journal'),10);
-
- $nb=0;
-
- //----------------------------------------
- // foreach item
- //----------------------------------------
- for ($i=0;$i< $nb_item;$i++) {
- if ( strlen(trim(${'e_march'.$i}))== 0) continue;
- /* check if amount are numeric and */
- if ( isNumber(${'e_march'.$i.'_price'}) == 0 )
- throw new Exception(_('La fiche ').${'e_march'.$i}._('a un montant invalide [').${'e_march'.$i}.']',6);
- if ( isNumber(${'e_quant'.$i}) == 0 )
- throw new Exception(_('La fiche ').${'e_march'.$i}._('a une quantité invalide [').${'e_quant'.$i}.']',7);
-
- /* check if all card has a ATTR_DEF_ACCOUNT*/
- $fiche=new Fiche($this->db);
- $fiche->get_by_qcode(${'e_march'.$i});
- if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
- throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'a pas de poste comptable'),8);
-
- // Check if the given tva id is valid
- $owner=new Own($this->db);
- if ( $owner->MY_TVA_USE=='Y') {
- if ( isNumber(${'e_march'.$i.'_tva_id'}) == 0 )
- throw new Exception(_('La fiche ').${'e_march'.$i}._('a un code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
- $tva_rate=new Acc_Tva($this->db);
- $tva_rate->set_parameter('id',${'e_march'.$i.'_tva_id'});
- if ( $tva_rate->load() != 0 )
- throw new Exception(_('La fiche ').${'e_march'.$i}._('a un code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
- }
- // if 2 accounts, take only the credit one
- /* The account exists */
- $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
-
- if ( strpos($sposte,',') != 0 ) {
- $array=explode(',',$sposte);
- $poste_val=$array[1];
- } else {
- $poste_val=$sposte;
- }
- $poste=new Acc_Account_Ledger($this->db,$poste_val);
- if ( $poste->load() == false ){
- throw new Exception(_('Pour la fiche ').${'e_march'.$i}._(' le poste comptable [').$poste->id._('n\'existe pas'),9);
- }
- /* Check if the card belong to the ledger */
- $fiche=new Fiche ($this->db);
- $fiche->get_by_qcode(${'e_march'.$i});
- if ( $fiche->belong_ledger($p_jrn,'cred') !=1 )
- throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'est pas accessible à ce journal'),10);
- $nb++;
- }
- if ( $nb == 0 )
- throw new Exception(_('Il n\'y a aucune marchandise'),12);
- //------------------------------------------------------
- // The "Paid By" check
- //------------------------------------------------------
- if ($e_mp != 0 ) $this->check_payment($e_mp,${"e_mp_qcode_".$e_mp});
-
- }
-
- public function save($p_array) {
- echo " Acc_Ledger_Sold::save Not implemented ";
- }
-
- /*!\brief insert into the database, it calls first the verify function,
- * change the value of this->jr_id and this->jr_internal
- * * It generates the document if gen_invoice is set and save the middle of payment if any ($e_mp)
- *
- *\param $p_array is usually $_POST or a predefined operation
- *\return string
- *\note throw an Exception
- */
- public function insert($p_array) {
- extract ($p_array);
- $this->verify($p_array) ;
-
- $owner=new own($this->db);
- $group=$this->db->get_next_seq("s_oa_group"); /* for analytic */
- $seq=$this->db->get_next_seq('s_grpt');
- $this->id=$p_jrn;
- $internal=$this->compute_internal_code($seq);
- $this->internal=$internal;
-
- $oPeriode=new Periode($this->db);
- $check_periode=$this->check_periode();
-
- if ( $check_periode == true )
- $tperiode=$period;
- else
- $tperiode=$oPeriode->find_periode($e_date);
-
- $cust=new Fiche($this->db);
- $cust->get_by_qcode($e_client);
- $sposte=$cust->strAttribut(ATTR_DEF_ACCOUNT);
-
- // if 2 accounts, take only the debit one for the customer
- //
- if ( strpos($sposte,',') != 0 ) {
- $array=explode(',',$sposte);
- $poste=$array[0];
- } else {
- $poste=$sposte;
- }
-
- bcscale(4);
- try {
- $tot_amount=0;
- $tot_tva=0;
- $tot_debit=0;
- $this->db->start();
- /* Save all the items without vat */
- for ($i=0;$i< $nb_item;$i++) {
- if ( strlen(trim(${'e_march'.$i})) == 0 ) continue;
- if ( ${'e_march'.$i.'_price'} == 0 ) continue;
- if ( ${'e_quant'.$i} == 0 ) continue;
-
- /* First we save all the items without vat */
- $fiche=new Fiche($this->db);
- $fiche->get_by_qcode(${"e_march".$i});
- $amount=bcmul(${'e_march'.$i.'_price'},${'e_quant'.$i});
- $tot_amount+=$amount;
- $acc_operation=new Acc_Operation($this->db);
- $acc_operation->date=$e_date;
- $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
-
- // if 2 accounts, take only the credit one
- if ( strpos($sposte,',') != 0 ) {
- $array=explode(',',$sposte);
- $poste_val=$array[1];
- } else {
- $poste_val=$sposte;
- }
-
- $acc_operation->poste=$poste_val;
- $acc_operation->amount=$amount;
- $acc_operation->grpt=$seq;
- $acc_operation->jrn=$p_jrn;
- $acc_operation->type='c';
- $acc_operation->periode=$tperiode;
- $acc_operation->qcode=${"e_march".$i};
- if ( $amount < 0 ) $tot_debit=bcadd($tot_debit,abs($amount));
-
- $j_id=$acc_operation->insert_jrnx();
-
- if ($owner->MY_TVA_USE == 'Y' ) {
- /* Compute sum vat */
- $oTva=new Acc_Tva($this->db);
- $idx_tva=${'e_march'.$i.'_tva_id'};
- $tva_item=${'e_march'.$i.'_tva_amount'};
- /* if empty then we need to compute it */
- if (trim($tva_item)=='') {
- /* retrieve tva */
- $l=new Acc_Tva($this->db,$idx_tva);
- $l->load();
- $tva_item=bcmul($amount,$l->get_parameter('rate'));
- }
- if (isset($tva[$idx_tva] ) )
- $tva[$idx_tva]+=$tva_item;
- else
- $tva[$idx_tva]=$tva_item;
- $tot_tva=round(bcadd($tva_item,$tot_tva),2);
- }
-
- /* Save the stock */
- /* if the quantity is < 0 then the stock increase (return of
- * material)
- */
- $nNeg=(${"e_quant".$i}<0)?-1:1;
-
- // always save quantity but in withStock we can find
- // what card need a stock management
- InsertStockGoods($this->db,$j_id,${'e_march'.$i},$nNeg*${'e_quant'.$i},'c') ;
-
- if ( $owner->MY_ANALYTIC != "nu" )
- {
- // for each item, insert into operation_analytique */
- $op=new Anc_Operation($this->db);
- $op->oa_group=$group;
- $op->j_id=$j_id;
- $op->oa_date=$e_date;
- $op->oa_debit=($amount < 0 )?'t':'f';
- $op->oa_description=FormatString($e_comm);
- $op->save_form_plan($_POST,$i,$j_id);
- }
- if ( $owner->MY_TVA_USE=='Y') {
- /* save into quant_sold */
- $r=$this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8)",
- array(null, /* 1 */
- $j_id, /* 2 */
- ${'e_march'.$i} , /* 3 */
- ${'e_quant'.$i}, /* 4 */
- round($amount,2), /* 5 */
- $tva_item, /* 6 */
- $idx_tva, /* 7 */
- $e_client)); /* 8 */
-
- } else {
- $r=$this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8) ",
- array(null, /* 1 */
- $j_id, /* 2 */
- ${'e_march'.$i}, /* 3 */
- ${'e_quant'.$i}, /* 4 */
- $amount, // 5
- 0,
- null,
- $e_client));
-
- } // if ( $owner->MY_TVA_USE=='Y') {
- }// end loop : save all items
-
- /* save total customer */
- $cust_amount=bcadd($tot_amount,$tot_tva);
- $acc_operation=new Acc_Operation($this->db);
- $acc_operation->date=$e_date;
- $acc_operation->poste=$poste;
- $acc_operation->amount=$cust_amount;
- $acc_operation->grpt=$seq;
- $acc_operation->jrn=$p_jrn;
- $acc_operation->type='d';
- $acc_operation->periode=$tperiode;
- $acc_operation->qcode=${"e_client"};
- if ( $cust_amount > 0 ) $tot_debit=bcadd($tot_debit,$cust_amount);
- $acc_operation->insert_jrnx();
-
-
- /** save all vat
- * $i contains the tva_id and value contains the vat amount
- * if if ($owner->MY_TVA_USE == 'Y' )
+ /*!\brief verify that the data are correct before inserting or confirming
+ *\param an array (usually $_POST)
+ *\return String
+ *\throw Exception if an error occurs
*/
- if ($owner->MY_TVA_USE == 'Y' ) {
- foreach ($tva as $i => $value) {
- $oTva=new Acc_Tva($this->db);
- $oTva->set_parameter('id',$i);
- $oTva->load();
+ public function verify($p_array)
+ {
+ extract ($p_array);
+ /* check for a double reload */
+ if ( isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1',array($mt)) != 0 )
+ throw new Exception (_('Double Encodage'),5);
- $poste_vat=$oTva->get_side('c');
+ /* check if we can write into this ledger */
+ $user=new User($this->db);
+ if ( $user->check_jrn($p_jrn) != 'W' )
+ throw new Exception (_('Accès interdit'),20);
- $cust_amount=bcadd($tot_amount,$tot_tva);
- $acc_operation=new Acc_Operation($this->db);
- $acc_operation->date=$e_date;
- $acc_operation->poste=$poste_vat;
- $acc_operation->amount=$value;
- $acc_operation->grpt=$seq;
- $acc_operation->jrn=$p_jrn;
- $acc_operation->type='c';
- $acc_operation->periode=$tperiode;
- if ($value < 0 ) $tot_debit=bcadd($tot_debit,abs($value));
- $acc_operation->insert_jrnx();
+ /* check if there is a customer */
+ if ( strlen(trim($e_client)) == 0 )
+ throw new Exception(_('Vous n\'avez pas donné de client'),11);
+
+ /* check if the date is valid */
+ if ( isDate($e_date) == null )
+ {
+ throw new Exception(_('Date invalide'), 2);
+ }
+
+ $oPeriode=new Periode($this->db);
+ if ( $this->check_periode() == true)
+ {
+ $tperiode=$period;
+ /* check that the datum is in the choosen periode */
+ $oPeriode->p_id=$period;
+ list ($min,$max)=$oPeriode->get_date_limit();
+
+ if ( cmpDate($e_date,$min) < 0 ||
+ cmpDate($e_date,$max) > 0)
+ throw new Exception(_('Date et periode ne correspondent pas'),6);
+ }
+ else
+ {
+ $per=new Periode($this->db);
+ $tperiode=$per->find_periode($e_date);
+ }
+
+ /* check if the periode is closed */
+ if ( $this->is_closed($tperiode)==1 )
+ {
+ throw new Exception(_('Periode fermee'),6);
+ }
+ /* check if we are using the strict mode */
+ if( $this->check_strict() == true)
+ {
+ /* if we use the strict mode, we get the date of the last
+ operation */
+ $last_date=$this->get_last_date();
+ if ( $last_date != null && cmpDate($e_date,$last_date) < 0 )
+ throw new Exception(_('Vous utilisez le mode strict la dernière operation est date du ')
+ .$last_date._(' vous ne pouvez pas encoder à une date antérieure'),13);
+
+ }
- }
- } // if ($owner->MY_TVA_USE=='Y')
- /* insert into jrn */
- $acc_operation=new Acc_Operation($this->db);
- $acc_operation->date=$e_date;
- $acc_operation->echeance=$e_ech;
- $acc_operation->amount=abs(round($tot_debit,2));
- $acc_operation->desc=$e_comm;
- $acc_operation->grpt=$seq;
- $acc_operation->jrn=$p_jrn;
- $acc_operation->periode=$tperiode;
- $acc_operation->pj=$e_pj;
- $acc_operation->mt=$mt;
+ $fiche=new Fiche($this->db);
+ $fiche->get_by_qcode($e_client);
+ if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
+ throw new Exception(_('La fiche ').$e_client._('n\'a pas de poste comptable'),8);
- $this->jr_id=$acc_operation->insert_jrn();
+ /* get the account and explode if necessary */
+ $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
+ // if 2 accounts, take only the debit one for customer
+ if ( strpos($sposte,',') != 0 )
+ {
+ $array=explode(',',$sposte);
+ $poste_val=$array[0];
+ }
+ else
+ {
+ $poste_val=$sposte;
+ }
+ /* The account exists */
- $this->pj=$acc_operation->set_pj();
+ $poste=new Acc_Account_Ledger($this->db,$poste_val);
- /* if e_suggest != e_pj then do not increment sequence */
- /* and e_pj is not null */
- if ( strcmp($e_pj,$e_pj_suggest) == 0 && strlen( trim($e_pj)) != 0 ) {
- $this->inc_seq_pj();
- }
+ if ( $poste->load() == false )
+ {
+ throw new Exception(_('Pour la fiche ').$e_client._(' le poste comptable [').$poste->id._('] n\'existe pas'),9);
+ }
- $this->db->exec_sql("update jrn set jr_internal='".$internal."' where ".
- " jr_grpt_id = ".$seq);
+ /* Check if the card belong to the ledger */
+ $fiche=new Fiche ($this->db);
+ $fiche->get_by_qcode($e_client,'deb');
+ if ( $fiche->belong_ledger($p_jrn) !=1 )
+ throw new Exception(_('La fiche ').$e_client._('n\'est pas accessible à ce journal'),10);
- /* update quant_sold */
- $this->db->exec_sql('update quant_sold set qs_internal = $1 where j_id in (select j_id from jrnx where j_grpt=$2)',
- array($internal,$seq));
+ $nb=0;
- /* Save the attachment or generate doc*/
- if ( isset ($_FILES['pj'])) {
- if ( strlen(trim($_FILES['pj']['name'])) != 0 )
- $this->db->save_upload_document($seq);
- else
- /* Generate an invoice and save it into the database */
- if ( isset($_POST['gen_invoice'])) {
- $file=$this->create_document($internal,$p_array);
- $this->doc= _('Document généré');
- $this->doc.=''.$file.' ';
- }
- }
- //----------------------------------------
- // Save the payer
- //----------------------------------------
- if ( $e_mp != 0 ) {
- /* mp */
- $mp=new Acc_Payment($this->db,$e_mp);
- $mp->load();
+ //----------------------------------------
+ // foreach item
+ //----------------------------------------
+ for ($i=0;$i< $nb_item;$i++)
+ {
+ if ( strlen(trim(${'e_march'.$i}))== 0) continue;
+ /* check if amount are numeric and */
+ if ( isNumber(${'e_march'.$i.'_price'}) == 0 )
+ throw new Exception(_('La fiche ').${'e_march'.$i}._('a un montant invalide [').${'e_march'.$i}.']',6);
+ if ( isNumber(${'e_quant'.$i}) == 0 )
+ throw new Exception(_('La fiche ').${'e_march'.$i}._('a une quantité invalide [').${'e_quant'.$i}.']',7);
- /* fiche */
- $fqcode=${'e_mp_qcode_'.$e_mp};
- $acfiche = new Fiche($this->db);
- $acfiche->get_by_qcode($fqcode);
+ /* check if all card has a ATTR_DEF_ACCOUNT*/
+ $fiche=new Fiche($this->db);
+ $fiche->get_by_qcode(${'e_march'.$i});
+ if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
+ throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'a pas de poste comptable'),8);
- /* jrnx */
- $acseq=$this->db->get_next_seq('s_grpt');
- $acjrn=new Acc_Ledger($this->db,$mp->get_parameter('ledger'));
- $acinternal=$acjrn->compute_internal_code($acseq);
+ // Check if the given tva id is valid
+ $owner=new Own($this->db);
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ if ( isNumber(${'e_march'.$i.'_tva_id'}) == 0 )
+ throw new Exception(_('La fiche ').${'e_march'.$i}._('a un code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
+ $tva_rate=new Acc_Tva($this->db);
+ $tva_rate->set_parameter('id',${'e_march'.$i.'_tva_id'});
+ if ( $tva_rate->load() != 0 )
+ throw new Exception(_('La fiche ').${'e_march'.$i}._('a un code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
+ }
+ // if 2 accounts, take only the credit one
+ /* The account exists */
+ $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
- /* Insert paid by */
- $acc_pay=new Acc_Operation($this->db);
- $acc_pay->date=$e_date;
- /* get the account and explode if necessary */
- $sposte=$acfiche->strAttribut(ATTR_DEF_ACCOUNT);
- // if 2 accounts, take only the debit one for customer
- if ( strpos($sposte,',') != 0 ) {
- $array=explode(',',$sposte);
- $poste_val=$array[0];
- } else {
- $poste_val=$sposte;
- }
-
- $acc_pay->poste=$poste_val;
- $acc_pay->qcode=$fqcode;
- $acc_pay->amount=abs(round($tot_debit,2));
- $acc_pay->desc=$e_comm;
- $acc_pay->grpt=$acseq;
- $acc_pay->jrn=$mp->get_parameter('ledger');
- $acc_pay->periode=$tperiode;
- $acc_pay->type='d';
- $acc_pay->insert_jrnx();
-
- /* Insert supplier */
- $acc_pay=new Acc_Operation($this->db);
- $acc_pay->date=$e_date;
- $acc_pay->poste=$poste;
- $acc_pay->qcode=$e_client;
- $acc_pay->amount=abs(round($tot_debit,2));
- $acc_pay->desc=$e_comm;
- $acc_pay->grpt=$acseq;
- $acc_pay->jrn=$mp->get_parameter('ledger');
- $acc_pay->periode=$tperiode;
- $acc_pay->type='c';
- $acc_pay->insert_jrnx();
-
- /* insert into jrn */
- $acc_pay->insert_jrn();
- $acjrn->grpt_id=$acseq;
- $acjrn->update_internal_code($acinternal);
-
- $r1=$this->get_id($internal);
- $r2=$this->get_id($acinternal);
- /* set the flag paid */
- $Res=$this->db->exec_sql("update jrn set jr_rapt='paid' where jr_id=$1",array($r1));
-
- /* Reconcialiation */
- $rec=new Acc_Reconciliation($this->db);
- $rec->set_jr_id($r1);
- $rec->insert($r2);
- }
-
- }
- catch (Exception $e)
- {
- echo ''.
- 'Erreur dans l\'enregistrement '.
- __FILE__.':'.__LINE__.' '.
- $e->getMessage();
- echo $e->getTrace();
-
- $this->db->rollback();
- exit();
- }
- $this->db->commit();
-
- return $internal;
- }
-
- public function update() {
- echo " Acc_Ledger_Sold::update Not implemented ";
- }
-
- public function load() {
- echo " Acc_Ledger_Sold::load Not implemented ";
-
- }
-
- public function delete() {
- echo " Acc_Ledger_Sold::delete Not implemented ";
- }
-
- /*!\brief show the summary of the operation and propose to save it
- *\param array contains normally $_POST. It proposes also to save
- * the Analytic accountancy
- *\return string
- *\todo verify also the vat
- */
- function confirm($p_array) {
- extract ($p_array);
- $this->verify($p_array) ;
- $anc=null;
- // to show a select list for the analytic & VAT USE
- // if analytic is op (optionnel) there is a blank line
- $owner = new Own($this->db);
-
- bcscale(4);
- $client=new Fiche($this->db);
- $client->get_by_qcode($e_client,true);
-
- $client_name=$client->getName().
- ' '.$client->strAttribut(ATTR_DEF_ADRESS).' '.
- $client->strAttribut(ATTR_DEF_CP).' '.
- $client->strAttribut(ATTR_DEF_CITY);
- $lPeriode=new Periode($this->db);
- if ($this->check_periode() == true) {
- $lPeriode->p_id=$period;
- } else {
- $lPeriode->find_periode($e_date);
- }
- $date_limit=$lPeriode->get_date_limit();
- $r="";
- $r.="";
- $r.=""._('En-tête facture client')." ";
- $r.='';
- $r.='';
- $r.=' '._('Date').' '.$e_date.' ';
- $r.=''._('Echeance').' '.$e_ech.' ';
- $r.=' '._('Période Comptable').' '.$date_limit['p_start'].'-'.$date_limit['p_end'].' ';
- $r.=' ';
- $r.=' '._('Journal').' '.h($this->get_name()).' ';
- $r.=' ';
- $r.='';
- $r.=' '._('Libellé').' '.h($e_comm).' PJ Num: '.h($e_pj).' ';
- $r.=' ';
- $r.='';
- $r.=' '._('Client').' '.h($e_client.':'.$client_name).' ';
- $r.=' ';
- $r.='
';
- $r.=' ';
- $r.=''._('Détail articles vendus').' ';
- $r.='';
- $r.='';
- $r.=""._('Code')." ";
- $r.=""._('Dénomination')." ";
- $r.=""._('prix')." ";
- $r.=""._('quantité')." ";
- $r.=""._('tva')." ";
-
-
- if ( $owner->MY_TVA_USE=='Y') {
- $r.=' '._('Montant TVA').' ';
- $r.=''._('Montant HTVA').' ';
- }
- /* if we use the AC */
- if ($owner->MY_ANALYTIC!='nu') {
- $anc=new Anc_Plan($this->db);
- $a_anc=$anc->get_list();
- $x=count($a_anc);
- /* set the width of the col */
- $r.=''._('Compt. Analytique').' ';
-
- /* add hidden variables pa[] to hold the value of pa_id */
- $r.=Anc_Plan::hidden($a_anc);
- }
- $r.=' ';
- $tot_amount=0.0;
- $tot_tva=0.0;
- for ($i = 0; $i < $nb_item;$i++) {
- if ( strlen(trim(${"e_march".$i})) == 0 ) continue;
-
- /* retrieve information for card */
- $fiche=new Fiche($this->db);
- $fiche->get_by_qcode(${"e_march".$i});
- $fiche_name=h($fiche->getName());
- if ( $owner->MY_TVA_USE=='Y') {
- $oTva=new Acc_Tva($this->db);
- $idx_tva=${"e_march".$i."_tva_id"};
-
- $oTva->set_parameter('id',$idx_tva);
- $oTva->load();
- }
- $op=new Acc_Compute();
- $amount=bcmul(${"e_march".$i."_price"},${'e_quant'.$i});
- $op->set_parameter("amount",$amount);
- if ( $owner->MY_TVA_USE=='Y') {
- $op->set_parameter('amount_vat_rate',$oTva->get_parameter('rate'));
- $op->compute_vat();
- $tva_computed=$op->get_parameter('amount_vat');
- $tva_item=${"e_march".$i."_tva_amount"};
- if (isset($tva[$idx_tva] ) )
- $tva[$idx_tva]+=$tva_item;
- else
- $tva[$idx_tva]=$tva_item;
- $tot_tva=round(bcadd($tva_item,$tot_tva),2);
- }
- $tot_amount=round(bcadd($tot_amount,$amount),2);
-
- $r.='';
- $r.='';
- $r.=${"e_march".$i};
- $r.=' ';
- $r.='';
- $r.=$fiche_name;
- $r.=' ';
- $r.='';
- $r.=${"e_march".$i."_price"};
- $r.=' ';
- $r.='';
- $r.=${"e_quant".$i};
- $r.=' ';
- if ( $owner->MY_TVA_USE=='Y') {
- $r.='';
- $r.=$oTva->get_parameter('label');
- $r.=' ';
- $r.='';
- $r.=$tva_item;
- /* warning if tva_computed and given are not the
- same */
- if ( bcsub($tva_item,$tva_computed) != 0) { echo _("Attention Différence");}
- $r.=' ';
- }
- $r.='';
- $r.=$amount;
- $r.=' ';
-
- // encode the pa
- if ( $owner->MY_ANALYTIC!='nu') // use of AA
- {
- // show form
- $anc_op=new Anc_Operation($this->db);
- $null=($owner->MY_ANALYTIC=='op')?1:0;
- $r.='';
- $p_mode=1;
- $p_array['pa_id']=$a_anc;
- /* op is the operation it contains either a sequence or a jrnx.j_id */
- $r.=HtmlInput::hidden('op[]=',$i);
- $r.=$anc_op->display_form_plan($p_array,$null,$p_mode,$i,$amount);
- $r.=' ';
- }
-
-
- $r.=' ';
+ if ( strpos($sposte,',') != 0 )
+ {
+ $array=explode(',',$sposte);
+ $poste_val=$array[1];
+ }
+ else
+ {
+ $poste_val=$sposte;
+ }
+ $poste=new Acc_Account_Ledger($this->db,$poste_val);
+ if ( $poste->load() == false )
+ {
+ throw new Exception(_('Pour la fiche ').${'e_march'.$i}._(' le poste comptable [').$poste->id._('n\'existe pas'),9);
+ }
+ /* Check if the card belong to the ledger */
+ $fiche=new Fiche ($this->db);
+ $fiche->get_by_qcode(${'e_march'.$i});
+ if ( $fiche->belong_ledger($p_jrn,'cred') !=1 )
+ throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'est pas accessible à ce journal'),10);
+ $nb++;
+ }
+ if ( $nb == 0 )
+ throw new Exception(_('Il n\'y a aucune marchandise'),12);
+ //------------------------------------------------------
+ // The "Paid By" check
+ //------------------------------------------------------
+ if ($e_mp != 0 ) $this->check_payment($e_mp,${"e_mp_qcode_".$e_mp});
}
-
- $r.='
';
- if ( $owner->MY_ANALYTIC!='nu') // use of AA
- $r.=' ';
- $r.=' ';
- $r.=$this->extra_info();
-
-
- $r.='';
- $r.='
Totaux ';
- $tot=round(bcadd($tot_amount,$tot_tva),2);
- $r.='';
- /* use VAT */
- if ($owner->MY_TVA_USE == 'Y' ) {
- $r.=' Total HTVA';
- foreach ($tva as $i=>$value) {
- $oTva->set_parameter('id',$i);
- $oTva->load();
-
- $r.=' TVA à '.$oTva->get_parameter('label');
- }
- $r.=' Total TVA';
- $r.=' Total TVAC';
- } else {
- $r.=' Total ';
- }
- $r.='
';
-
- $r.='';
- $r.=''.$tot_amount.' ';
-
- if ($owner->MY_TVA_USE == 'Y' ) {
- foreach ($tva as $i=>$value) {
- $r.=' '.$tva[$i];
- }
- $r.=''.$tot_tva.' ';
- $r.=''.$tot.' ';
- }
- $r.="
";
-
-
-
- $r.=' ';
- $r.="
";
-
- /* Add hidden */
- $r.=HtmlInput::hidden('e_client',$e_client);
- $r.=HtmlInput::hidden('nb_item',$nb_item);
- $r.=HtmlInput::hidden('p_jrn',$p_jrn);
- $mt=microtime(true);
- $r.=HtmlInput::hidden('mt',$mt);
-
- if ( isset($period))
- $r.=HtmlInput::hidden('period',$period);
- /*\todo comment les types hidden gérent ils des contenus avec des quotes, double quote ou < > ??? */
- $r.=HtmlInput::hidden('e_comm',$e_comm);
- $r.=HtmlInput::hidden('e_date',$e_date);
- $r.=HtmlInput::hidden('e_ech',$e_ech);
- $r.=HtmlInput::hidden('e_pj',$e_pj);
- $r.=HtmlInput::hidden('e_pj_suggest',$e_pj_suggest);
-
- $e_mp=(isset($e_mp))?$e_mp:0;
- $r.=HtmlInput::hidden('e_mp',$e_mp);
- /* Paid by */
- /* if the paymethod is not 0 and if a quick code is given */
- if ( $e_mp!=0 && strlen (trim (${'e_mp_qcode_'.$e_mp})) != 0 ) {
- $r.=HtmlInput::hidden('e_mp_qcode_'.$e_mp,${'e_mp_qcode_'.$e_mp});
-
- /* needed for generating a invoice */
- $r.=HtmlInput::hidden('qcode_dest',${'e_mp_qcode_'.$e_mp});
-
- $r.=_("Payé par ").${'e_mp_qcode_'.$e_mp};
- $r.=' ';
+ public function save($p_array)
+ {
+ echo " Acc_Ledger_Sold::save Not implemented ";
}
- $r.=HtmlInput::hidden('jrn_type',$jrn_type);
- for ($i=0;$i < $nb_item;$i++) {
- $r.=HtmlInput::hidden("e_march".$i,${"e_march".$i});
- $r.=HtmlInput::hidden("e_march".$i."_price",${"e_march".$i."_price"});
- if ( $owner->MY_TVA_USE=='Y') {
- $r.=HtmlInput::hidden("e_march".$i."_tva_id",${"e_march".$i."_tva_id"});
- $r.=HtmlInput::hidden("e_march".$i."_tva_amount",${"e_march".$i."_tva_amount"});
- }
- $r.=HtmlInput::hidden("e_quant".$i,${"e_quant".$i});
+ /*!\brief insert into the database, it calls first the verify function,
+ * change the value of this->jr_id and this->jr_internal
+ * * It generates the document if gen_invoice is set and save the middle of payment if any ($e_mp)
+ *
+ *\param $p_array is usually $_POST or a predefined operation
+ *\return string
+ *\note throw an Exception
+ */
+ public function insert($p_array)
+ {
+ extract ($p_array);
+ $this->verify($p_array) ;
+
+ $owner=new own($this->db);
+ $group=$this->db->get_next_seq("s_oa_group"); /* for analytic */
+ $seq=$this->db->get_next_seq('s_grpt');
+ $this->id=$p_jrn;
+ $internal=$this->compute_internal_code($seq);
+ $this->internal=$internal;
+
+ $oPeriode=new Periode($this->db);
+ $check_periode=$this->check_periode();
+
+ if ( $check_periode == true )
+ $tperiode=$period;
+ else
+ $tperiode=$oPeriode->find_periode($e_date);
+
+ $cust=new Fiche($this->db);
+ $cust->get_by_qcode($e_client);
+ $sposte=$cust->strAttribut(ATTR_DEF_ACCOUNT);
+
+ // if 2 accounts, take only the debit one for the customer
+ //
+ if ( strpos($sposte,',') != 0 )
+ {
+ $array=explode(',',$sposte);
+ $poste=$array[0];
+ }
+ else
+ {
+ $poste=$sposte;
+ }
+
+ bcscale(4);
+ try
+ {
+ $tot_amount=0;
+ $tot_tva=0;
+ $tot_debit=0;
+ $this->db->start();
+ /* Save all the items without vat */
+ for ($i=0;$i< $nb_item;$i++)
+ {
+ if ( strlen(trim(${'e_march'.$i})) == 0 ) continue;
+ if ( ${'e_march'.$i.'_price'} == 0 ) continue;
+ if ( ${'e_quant'.$i} == 0 ) continue;
+
+ /* First we save all the items without vat */
+ $fiche=new Fiche($this->db);
+ $fiche->get_by_qcode(${"e_march".$i});
+ $amount=bcmul(${'e_march'.$i.'_price'},${'e_quant'.$i});
+ $tot_amount+=$amount;
+ $acc_operation=new Acc_Operation($this->db);
+ $acc_operation->date=$e_date;
+ $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
+
+ // if 2 accounts, take only the credit one
+ if ( strpos($sposte,',') != 0 )
+ {
+ $array=explode(',',$sposte);
+ $poste_val=$array[1];
+ }
+ else
+ {
+ $poste_val=$sposte;
+ }
+
+ $acc_operation->poste=$poste_val;
+ $acc_operation->amount=$amount;
+ $acc_operation->grpt=$seq;
+ $acc_operation->jrn=$p_jrn;
+ $acc_operation->type='c';
+ $acc_operation->periode=$tperiode;
+ $acc_operation->qcode=${"e_march".$i};
+ if ( $amount < 0 ) $tot_debit=bcadd($tot_debit,abs($amount));
+
+ $j_id=$acc_operation->insert_jrnx();
+
+ if ($owner->MY_TVA_USE == 'Y' )
+ {
+ /* Compute sum vat */
+ $oTva=new Acc_Tva($this->db);
+ $idx_tva=${'e_march'.$i.'_tva_id'};
+ $tva_item=${'e_march'.$i.'_tva_amount'};
+ /* if empty then we need to compute it */
+ if (trim($tva_item)=='')
+ {
+ /* retrieve tva */
+ $l=new Acc_Tva($this->db,$idx_tva);
+ $l->load();
+ $tva_item=bcmul($amount,$l->get_parameter('rate'));
+ }
+ if (isset($tva[$idx_tva] ) )
+ $tva[$idx_tva]+=$tva_item;
+ else
+ $tva[$idx_tva]=$tva_item;
+ $tot_tva=round(bcadd($tva_item,$tot_tva),2);
+ }
+
+ /* Save the stock */
+ /* if the quantity is < 0 then the stock increase (return of
+ * material)
+ */
+ $nNeg=($
+ {"e_quant".$i
+ }
+ <0)?-1:1;
+
+ // always save quantity but in withStock we can find
+ // what card need a stock management
+ InsertStockGoods($this->db,$j_id,${'e_march'.$i},$nNeg*${'e_quant'.$i},'c') ;
+
+ if ( $owner->MY_ANALYTIC != "nu" )
+ {
+ // for each item, insert into operation_analytique */
+ $op=new Anc_Operation($this->db);
+ $op->oa_group=$group;
+ $op->j_id=$j_id;
+ $op->oa_date=$e_date;
+ $op->oa_debit=($amount < 0 )?'t':'f';
+ $op->oa_description=FormatString($e_comm);
+ $op->save_form_plan($_POST,$i,$j_id);
+ }
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ /* save into quant_sold */
+ $r=$this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8)",
+ array(null, /* 1 */
+ $j_id, /* 2 */
+ ${'e_march'.$i} , /* 3 */
+ ${'e_quant'.$i}, /* 4 */
+ round($amount,2), /* 5 */
+ $tva_item, /* 6 */
+ $idx_tva, /* 7 */
+ $e_client)); /* 8 */
+
+ }
+ else
+ {
+ $r=$this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8) ",
+ array(null, /* 1 */
+ $j_id, /* 2 */
+ ${'e_march'.$i}, /* 3 */
+ ${'e_quant'.$i}, /* 4 */
+ $amount, // 5
+ 0,
+ null,
+ $e_client));
+
+ } // if ( $owner->MY_TVA_USE=='Y') {
+ }// end loop : save all items
+
+ /* save total customer */
+ $cust_amount=bcadd($tot_amount,$tot_tva);
+ $acc_operation=new Acc_Operation($this->db);
+ $acc_operation->date=$e_date;
+ $acc_operation->poste=$poste;
+ $acc_operation->amount=$cust_amount;
+ $acc_operation->grpt=$seq;
+ $acc_operation->jrn=$p_jrn;
+ $acc_operation->type='d';
+ $acc_operation->periode=$tperiode;
+ $acc_operation->qcode=$
+ {"e_client"
+ };
+ if ( $cust_amount > 0 ) $tot_debit=bcadd($tot_debit,$cust_amount);
+ $acc_operation->insert_jrnx();
+
+
+ /** save all vat
+ * $i contains the tva_id and value contains the vat amount
+ * if if ($owner->MY_TVA_USE == 'Y' )
+ */
+ if ($owner->MY_TVA_USE == 'Y' )
+ {
+ foreach ($tva as $i => $value)
+ {
+ $oTva=new Acc_Tva($this->db);
+ $oTva->set_parameter('id',$i);
+ $oTva->load();
+
+ $poste_vat=$oTva->get_side('c');
+
+ $cust_amount=bcadd($tot_amount,$tot_tva);
+ $acc_operation=new Acc_Operation($this->db);
+ $acc_operation->date=$e_date;
+ $acc_operation->poste=$poste_vat;
+ $acc_operation->amount=$value;
+ $acc_operation->grpt=$seq;
+ $acc_operation->jrn=$p_jrn;
+ $acc_operation->type='c';
+ $acc_operation->periode=$tperiode;
+ if ($value < 0 ) $tot_debit=bcadd($tot_debit,abs($value));
+ $acc_operation->insert_jrnx();
+
+
+ }
+ } // if ($owner->MY_TVA_USE=='Y')
+ /* insert into jrn */
+ $acc_operation=new Acc_Operation($this->db);
+ $acc_operation->date=$e_date;
+ $acc_operation->echeance=$e_ech;
+ $acc_operation->amount=abs(round($tot_debit,2));
+ $acc_operation->desc=$e_comm;
+ $acc_operation->grpt=$seq;
+ $acc_operation->jrn=$p_jrn;
+ $acc_operation->periode=$tperiode;
+ $acc_operation->pj=$e_pj;
+ $acc_operation->mt=$mt;
+
+ $this->jr_id=$acc_operation->insert_jrn();
+
+ $this->pj=$acc_operation->set_pj();
+
+ /* if e_suggest != e_pj then do not increment sequence */
+ /* and e_pj is not null */
+ if ( strcmp($e_pj,$e_pj_suggest) == 0 && strlen( trim($e_pj)) != 0 )
+ {
+ $this->inc_seq_pj();
+ }
+
+ $this->db->exec_sql("update jrn set jr_internal='".$internal."' where ".
+ " jr_grpt_id = ".$seq);
+
+ /* update quant_sold */
+ $this->db->exec_sql('update quant_sold set qs_internal = $1 where j_id in (select j_id from jrnx where j_grpt=$2)',
+ array($internal,$seq));
+
+ /* Save the attachment or generate doc*/
+ if ( isset ($_FILES['pj']))
+ {
+ if ( strlen(trim($_FILES['pj']['name'])) != 0 )
+ $this->db->save_upload_document($seq);
+ else
+ /* Generate an invoice and save it into the database */
+ if ( isset($_POST['gen_invoice']))
+ {
+ $file=$this->create_document($internal,$p_array);
+ $this->doc= _('Document généré');
+ $this->doc.=''.$file.' ';
+ }
+ }
+ //----------------------------------------
+ // Save the payer
+ //----------------------------------------
+ if ( $e_mp != 0 )
+ {
+ /* mp */
+ $mp=new Acc_Payment($this->db,$e_mp);
+ $mp->load();
+
+ /* fiche */
+ $fqcode=${'e_mp_qcode_'.$e_mp};
+ $acfiche = new Fiche($this->db);
+ $acfiche->get_by_qcode($fqcode);
+
+ /* jrnx */
+ $acseq=$this->db->get_next_seq('s_grpt');
+ $acjrn=new Acc_Ledger($this->db,$mp->get_parameter('ledger'));
+ $acinternal=$acjrn->compute_internal_code($acseq);
+
+ /* Insert paid by */
+ $acc_pay=new Acc_Operation($this->db);
+ $acc_pay->date=$e_date;
+ /* get the account and explode if necessary */
+ $sposte=$acfiche->strAttribut(ATTR_DEF_ACCOUNT);
+ // if 2 accounts, take only the debit one for customer
+ if ( strpos($sposte,',') != 0 )
+ {
+ $array=explode(',',$sposte);
+ $poste_val=$array[0];
+ }
+ else
+ {
+ $poste_val=$sposte;
+ }
+
+ $acc_pay->poste=$poste_val;
+ $acc_pay->qcode=$fqcode;
+ $acc_pay->amount=abs(round($tot_debit,2));
+ $acc_pay->desc=$e_comm;
+ $acc_pay->grpt=$acseq;
+ $acc_pay->jrn=$mp->get_parameter('ledger');
+ $acc_pay->periode=$tperiode;
+ $acc_pay->type='d';
+ $acc_pay->insert_jrnx();
+
+ /* Insert supplier */
+ $acc_pay=new Acc_Operation($this->db);
+ $acc_pay->date=$e_date;
+ $acc_pay->poste=$poste;
+ $acc_pay->qcode=$e_client;
+ $acc_pay->amount=abs(round($tot_debit,2));
+ $acc_pay->desc=$e_comm;
+ $acc_pay->grpt=$acseq;
+ $acc_pay->jrn=$mp->get_parameter('ledger');
+ $acc_pay->periode=$tperiode;
+ $acc_pay->type='c';
+ $acc_pay->insert_jrnx();
+
+ /* insert into jrn */
+ $acc_pay->insert_jrn();
+ $acjrn->grpt_id=$acseq;
+ $acjrn->update_internal_code($acinternal);
+
+ $r1=$this->get_id($internal);
+ $r2=$this->get_id($acinternal);
+ /* set the flag paid */
+ $Res=$this->db->exec_sql("update jrn set jr_rapt='paid' where jr_id=$1",array($r1));
+
+ /* Reconcialiation */
+ $rec=new Acc_Reconciliation($this->db);
+ $rec->set_jr_id($r1);
+ $rec->insert($r2);
+ }
+
+ }
+ catch (Exception $e)
+ {
+ echo ''.
+ 'Erreur dans l\'enregistrement '.
+ __FILE__.':'.__LINE__.' '.
+ $e->getMessage();
+ echo $e->getTrace();
+
+ $this->db->rollback();
+ exit();
+ }
+ $this->db->commit();
+
+ return $internal;
}
- return $r;
- }
- /*!\brief the function extra info allows to
- * - add a attachment
- * - generate an invoice
- * - insert extra info
- *\return string
- */
- public function extra_info() {
- $r="";
- $r.='';
- $r.='
Facturation ';
- // check for upload piece
- $file=new IFile();
- $file->table=0;
- $r.=_("Ajoutez une pièce justificative ");
- $r.=$file->input("pj","");
-
- if ( $this->db->count_sql("select md_id,md_name from document_modele where md_affect='VEN'") > 0 )
- {
-
-
- $r.=_('ou générer une facture').' ';
- // We propose to generate the invoice and some template
- $doc_gen=new ISelect();
- $doc_gen->name="gen_doc";
- $doc_gen->value=$this->db->make_array(
- "select md_id,md_name ".
- " from document_modele where md_affect='VEN'");
- $r.=$doc_gen->input().' ';
- }
- $r.=' ';
- $obj=new IText();
- $r.=_('Numero de bon de commande : ').$obj->input('bon_comm').' ';
- $r.=_('Autre information : ').$obj->input('other_info').' ';
-
- $r.=" ";
- $r.='';
- return $r;
- }
-
-
- /*!\brief update the payment
- */
- function show_unpaid() {
- // Show list of unpaid sell
- // Date - date of payment - Customer - amount
- // Nav. bar
- $step=$_SESSION['g_pagesize'];
- $page=(isset($_GET['offset']))?$_GET['page']:1;
- $offset=(isset($_GET['offset']))?$_GET['offset']:0;
-
-
- $sql=SQL_LIST_UNPAID_INVOICE_DATE_LIMIT." and jr_def_id=".$this->id ;
- list($max_line,$list)=ListJrn($this->db,$sql,null,$offset,1);
- $sql=SQL_LIST_UNPAID_INVOICE." and jr_def_id=".$this->id ;
- list($max_line2,$list2)=ListJrn($this->db,$sql,null,$offset,1);
-
- // Get the max line
- $m=($max_line2>$max_line)?$max_line2:$max_line;
- $bar2=jrn_navigation_bar($offset,$m,$step,$page);
-
- echo $bar2;
- echo ' '._('Echeance dépassée').' ';
- echo $list;
- echo ' '._('Non Payée').' ';
- echo $list2;
- echo $bar2;
- // Add hidden parameter
- $hid=new IHidden();
-
- echo ' ';
-
- if ( $m != 0 )
- echo HtmlInput::submit('paid',_('Mise à jour paiement'));
-
-
- }
- /*!\brief display the form for entering data for invoice,
- *\param $p_array is null or you can put the predef operation or the $_POST
- *
- *\return HTML string
- */
- function input($p_array=null) {
- if ( $p_array != null ) extract($p_array);
- $user = new User($this->db);
- $owner=new Own($this->db);
- $flag_tva=$owner->MY_TVA_USE;
- /* Add button */
- $f_add_button=new IButton('add_card');
- $f_add_button->label=_('Créer une nouvelle fiche');
- $f_add_button->set_attribute('ipopup','ipop_newcard');
- $f_add_button->set_attribute('jrn',$this->id);
- $f_add_button->javascript="this.jrn=\$('p_jrn').value; select_card_type(this);";
-
- $f_add_button2=new IButton('add_card2');
- $f_add_button2->label=_('Créer une nouvelle fiche');
- $f_add_button2->set_attribute('ipopup','ipop_newcard');
- $f_add_button2->set_attribute('filter',$this->get_all_fiche_def ());
- // $f_add_button2->set_attribute('jrn',$this->id);
- $f_add_button2->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
-
- $str_add_button=$f_add_button->input();
- $str_add_button2=$f_add_button2->input();
-
- // The first day of the periode
- $oPeriode=new Periode($this->db);
- list ($l_date_start,$l_date_end)=$oPeriode->get_date_limit($user->get_periode());
- if ( $owner->MY_DATE_SUGGEST=='Y' )
- $op_date=( ! isset($e_date) ) ?$l_date_start:$e_date;
- else
- $op_date=( ! isset($e_date) ) ?'':$e_date;
-
-
- $e_ech=(isset($e_ech))?$e_ech:"";
- $e_comm=(isset($e_comm))?$e_comm:"";
-
- $r='';
- $r.=dossier::hidden();
- $f_legend=_('En-tête facture client');
-
- $Echeance=new IDate();
- $Echeance->setReadOnly(false);
-
- $Echeance->tabindex=2;
- $label=HtmlInput::infobulle(4);
- $f_echeance=$Echeance->input('e_ech',$e_ech,_('Echéance').$label);
- $Date=new IDate();
- $Date->setReadOnly(false);
-
- $f_date=$Date->input("e_date",$op_date);
-
- $f_periode='';
- // Periode
- //--
- if ($this->check_periode() == true) {
- $l_user_per=$user->get_periode();
- $def=(isset($periode))?$periode:$l_user_per;
-
- $period=new IPeriod("period");
- $period->user=$user;
- $period->cn=$this->db;
- $period->value=$def;
- $period->type=OPEN;
- try {
- $l_form_per=$period->input();
- } catch (Exception $e) {
- if ($e->getCode() == 1 ) {
- echo _("Aucune période ouverte");
- exit();
- }
- }
- $label=HtmlInput::infobulle(3);
- $f_periode=_("Période comptable")." $label ".$l_form_per;
- }
- /* if we suggest the next pj, then we need a javascript */
- $add_js="";
- if ( $owner->MY_PJ_SUGGEST=='Y') {
- $add_js="update_pj();";
- }
- $add_js.='get_last_date();';
-
- $wLedger=$this->select_ledger('VEN',2);
- if ( $wLedger == null )
- exit(_('Pas de journal disponible'));
- $wLedger->table=1;
- $wLedger->javascript="onChange='update_predef(\"ven\",\"f\");$add_js'";
- $wLedger->label=" Journal ".HtmlInput::infobulle(2) ;
-
- $f_jrn=$wLedger->input();
-
- $Commentaire=new IText();
- $Commentaire->table=0;
- $Commentaire->setReadOnly(false);
- $Commentaire->size=60;
- $Commentaire->tabindex=3;
-
- $label=HtmlInput::infobulle(1) ;
-
- $f_desc=$label.$Commentaire->input("e_comm",h($e_comm));
- // PJ
- //--
- /* suggest PJ ? */
- $default_pj='';
- if ( $owner->MY_PJ_SUGGEST=='Y') {
- $default_pj=$this->guess_pj();
+ public function update()
+ {
+ echo " Acc_Ledger_Sold::update Not implemented ";
}
- $pj=new IText();
-
- $pj->table=0;
- $pj->name="e_pj";
- $pj->size=10;
- $pj->value=(isset($e_pj))?$e_pj:$default_pj;
- $f_pj=$pj->input().HtmlInput::hidden('e_pj_suggest',$default_pj);
- // Display the customer
- //--
- $fiche='deb';
-
- // Save old value and set a new one
- //--
- $e_client=( isset ($e_client) )?$e_client:"";
- $e_client_label=" ";//str_pad("",100,".");
-
-
- // retrieve e_client_label
- //--
-
- if ( strlen(trim($e_client)) != 0) {
- $fClient=new Fiche($this->db);
- $fClient->get_by_qcode($e_client);
- $e_client_label=$fClient->strAttribut(ATTR_DEF_NAME).' '.
- ' Adresse : '.$fClient->strAttribut(ATTR_DEF_ADRESS).' '.
- $fClient->strAttribut(ATTR_DEF_CP).' '.
- $fClient->strAttribut(ATTR_DEF_CITY).' ';
-
+ public function load()
+ {
+ echo " Acc_Ledger_Sold::load Not implemented ";
}
- $W1=new ICard();
- $W1->label="Client ".HtmlInput::infobulle(0) ;
- $W1->name="e_client";
- $W1->tabindex=3;
- $W1->value=$e_client;
- $W1->table=0;
- $W1->set_dblclick("fill_ipopcard(this);");
- $W1->set_attribute('ipopup','ipopcard');
+ public function delete()
+ {
+ echo " Acc_Ledger_Sold::delete Not implemented ";
+ }
- // name of the field to update with the name of the card
- $W1->set_attribute('label','e_client_label');
- // name of the field to update with the name of the card
- $W1->set_attribute('typecard','deb');
- $W1->extra='deb';
- // Add the callback function to filter the card on the jrn
- $W1->set_callback('filter_card');
- $W1->set_function('fill_data');
- $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
- $W1->name);
- $f_client_qcode=$W1->input();
- $client_label=new ISpan();
- $client_label->table=0;
- $f_client=$client_label->input("e_client_label",$e_client_label);
- $f_client_bt=$W1->search();
+ /*!\brief show the summary of the operation and propose to save it
+ *\param array contains normally $_POST. It proposes also to save
+ * the Analytic accountancy
+ *\return string
+ *\todo verify also the vat
+ */
+ function confirm($p_array)
+ {
+ extract ($p_array);
+ $this->verify($p_array) ;
+ $anc=null;
+ // to show a select list for the analytic & VAT USE
+ // if analytic is op (optionnel) there is a blank line
+ $owner = new Own($this->db);
+
+ bcscale(4);
+ $client=new Fiche($this->db);
+ $client->get_by_qcode($e_client,true);
+
+ $client_name=$client->getName().
+ ' '.$client->strAttribut(ATTR_DEF_ADRESS).' '.
+ $client->strAttribut(ATTR_DEF_CP).' '.
+ $client->strAttribut(ATTR_DEF_CITY);
+ $lPeriode=new Periode($this->db);
+ if ($this->check_periode() == true)
+ {
+ $lPeriode->p_id=$period;
+ }
+ else
+ {
+ $lPeriode->find_periode($e_date);
+ }
+ $date_limit=$lPeriode->get_date_limit();
+ $r="";
+ $r.="";
+ $r.=""._('En-tête facture client')." ";
+ $r.='';
+ $r.='';
+ $r.=' '._('Date').' '.$e_date.' ';
+ $r.=''._('Echeance').' '.$e_ech.' ';
+ $r.=' '._('Période Comptable').' '.$date_limit['p_start'].'-'.$date_limit['p_end'].' ';
+ $r.=' ';
+ $r.=' '._('Journal').' '.h($this->get_name()).' ';
+ $r.=' ';
+ $r.='';
+ $r.=' '._('Libellé').' '.h($e_comm).' PJ Num: '.h($e_pj).' ';
+ $r.=' ';
+ $r.='';
+ $r.=' '._('Client').' '.h($e_client.':'.$client_name).' ';
+ $r.=' ';
+ $r.='
';
+ $r.=' ';
+ $r.=''._('Détail articles vendus').' ';
+ $r.='';
+ $r.='';
+ $r.=""._('Code')." ";
+ $r.=""._('Dénomination')." ";
+ $r.=""._('prix')." ";
+ $r.=""._('quantité')." ";
+ $r.=""._('tva')." ";
- // Record the current number of article
- $Hid=new IHidden();
- $p_article= ( isset ($nb_item))?$nb_item:MAX_ARTICLE;
- $r.=$Hid->input("nb_item",$p_article);
- $max=($p_article < MAX_ARTICLE)?MAX_ARTICLE:$p_article;
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ $r.=' '._('Montant TVA').' ';
+ $r.=''._('Montant HTVA').' ';
+ }
+ /* if we use the AC */
+ if ($owner->MY_ANALYTIC!='nu')
+ {
+ $anc=new Anc_Plan($this->db);
+ $a_anc=$anc->get_list();
+ $x=count($a_anc);
+ /* set the width of the col */
+ $r.=''._('Compt. Analytique').' ';
+
+ /* add hidden variables pa[] to hold the value of pa_id */
+ $r.=Anc_Plan::hidden($a_anc);
+ }
+ $r.=' ';
+ $tot_amount=0.0;
+ $tot_tva=0.0;
+ for ($i = 0; $i < $nb_item;$i++)
+ {
+ if ( strlen(trim(${"e_march".$i})) == 0 ) continue;
+
+ /* retrieve information for card */
+ $fiche=new Fiche($this->db);
+ $fiche->get_by_qcode(${"e_march".$i});
+ $fiche_name=h($fiche->getName());
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ $oTva=new Acc_Tva($this->db);
+ $idx_tva=${"e_march".$i."_tva_id"};
+
+ $oTva->set_parameter('id',$idx_tva);
+ $oTva->load();
+ }
+ $op=new Acc_Compute();
+ $amount=bcmul(${"e_march".$i."_price"},${'e_quant'.$i});
+ $op->set_parameter("amount",$amount);
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ $op->set_parameter('amount_vat_rate',$oTva->get_parameter('rate'));
+ $op->compute_vat();
+ $tva_computed=$op->get_parameter('amount_vat');
+ $tva_item=${"e_march".$i."_tva_amount"};
+ if (isset($tva[$idx_tva] ) )
+ $tva[$idx_tva]+=$tva_item;
+ else
+ $tva[$idx_tva]=$tva_item;
+ $tot_tva=round(bcadd($tva_item,$tot_tva),2);
+ }
+ $tot_amount=round(bcadd($tot_amount,$amount),2);
+
+ $r.='';
+ $r.='';
+ $r.=${"e_march".$i};
+ $r.=' ';
+ $r.='';
+ $r.=$fiche_name;
+ $r.=' ';
+ $r.='';
+ $r.=${"e_march".$i."_price"};
+ $r.=' ';
+ $r.='';
+ $r.=${"e_quant".$i};
+ $r.=' ';
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ $r.='';
+ $r.=$oTva->get_parameter('label');
+ $r.=' ';
+ $r.='';
+ $r.=$tva_item;
+ /* warning if tva_computed and given are not the
+ same */
+ if ( bcsub($tva_item,$tva_computed) != 0)
+ {
+ echo _("Attention Différence");
+ }
+ $r.=' ';
+ }
+ $r.='';
+ $r.=$amount;
+ $r.=' ';
+
+ // encode the pa
+ if ( $owner->MY_ANALYTIC!='nu') // use of AA
+ {
+ // show form
+ $anc_op=new Anc_Operation($this->db);
+ $null=($owner->MY_ANALYTIC=='op')?1:0;
+ $r.='';
+ $p_mode=1;
+ $p_array['pa_id']=$a_anc;
+ /* op is the operation it contains either a sequence or a jrnx.j_id */
+ $r.=HtmlInput::hidden('op[]=',$i);
+ $r.=$anc_op->display_form_plan($p_array,$null,$p_mode,$i,$amount);
+ $r.=' ';
+ }
- $f_legend_detail=_("Détail articles vendus");
+ $r.=' ';
- // For each article
- //--
- for ($i=0;$i< $max;$i++) {
- // Code id, price & vat code
- //--
- $march=(isset(${"e_march$i"}))?${"e_march$i"}:"";
- $march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:"";
- if ( $flag_tva=='Y') {
- $march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
- $march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:"";
- }
- $march_label=' ';
-
- // retrieve the tva label and name
- //--
- if ( strlen(trim($march))!=0 ) {
- $fMarch=new Fiche($this->db);
- $fMarch->get_by_qcode($march);
- $march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
- if ( $flag_tva=='Y') {
- if ( ! (isset(${"e_march$i"."_tva_id"})))
- $march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
- }
- }
- // Show input
- //--
- $W1=new ICard();
- $W1->label="";
- $W1->name="e_march".$i;
- $W1->value=$march;
- $W1->table=1;
- $W1->set_attribute('typecard','cred');
- $W1->set_dblclick("fill_ipopcard(this);");
- $W1->set_attribute('ipopup','ipopcard');
-
- $W1->extra='cred'; // credits
- // name of the field to update with the name of the card
- $W1->set_attribute('label','e_march'.$i.'_label');
- // name of the field with the price
- $W1->set_attribute('price','e_march'.$i.'_price');
- // name of the field with the TVA_ID
- $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
- // Add the callback function to filter the card on the jrn
- $W1->set_callback('filter_card');
- $W1->set_function('fill_data');
- $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
- $W1->name);
-
- $W1->readonly=false;
-
- $array[$i]['quick_code']=$W1->input();
- $array[$i]['bt']=$W1->search();
- // For computing we need some hidden field for holding the value
- $array[$i]['hidden']='';
- if ( $flag_tva=='Y') $array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
-
- $htva=new INum('htva_march'.$i);
- $htva->readOnly=1;
- $htva->value=0;
- $array[$i]['htva']=$htva->input();
-
- if ( $owner->MY_TVA_USE=='Y')
- $tvac=new INum('tvac_march'.$i);
- else
- $tvac=new IHidden('tvac_march'.$i);
-
- $tvac->readOnly=1;
- $tvac->value=0;
- $array[$i]['tvac']=$tvac->input();
+ }
- $Span=new ISpan();
- $Span->setReadOnly(false);
- // card's name, price
- //--
- $array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
- // price
- $Price=new INum();
- $Price->setReadOnly(false);
- $Price->size=9;
- $Price->javascript="onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
- $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
- $array[$i]['tva']='';
- $array[$i]['amount_tva']='';
- // if tva is not needed then no tva field
- if ( $flag_tva == 'Y' ) {
- // vat label
- //--
- $Tva=new ITva_Popup($this->db);
- $Tva->in_table=true;
- $Tva->set_attribute('compute',$i);
-
- $Tva->js='onblur="format_number(this);clean_tva('.$i.');compute_ledger('.$i.')"';
- $Tva->value=$march_tva_id;
- $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
- // vat amount
- //--
- $wTva_amount=new INum();
- $wTva_amount->readOnly=false;
- $wTva_amount->size=6;
- $wTva_amount->javascript="onBlur='format_number(this);compute_ledger($i)'";
- $array[$i]['amount_tva']=$wTva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
- }
- // quantity
- //--
- $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1";
- $Quantity=new INum();
- $Quantity->setReadOnly(false);
- $Quantity->size=8;
- $Quantity->javascript="onChange='format_number(this);clean_tva($i);compute_ledger($i)'";
- $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
-
- }// foreach article
- $f_type=_('Client');
+ $r.='
';
+ if ( $owner->MY_ANALYTIC!='nu') // use of AA
+ $r.=' ';
+ $r.=' ';
+ $r.=$this->extra_info();
- ob_start();
- require_once('template/form_ledger_detail.php');
- $r.=ob_get_contents();
- ob_clean();
+ $r.='';
+ $r.='
Totaux ';
+ $tot=round(bcadd($tot_amount,$tot_tva),2);
+ $r.='';
+ /* use VAT */
+ if ($owner->MY_TVA_USE == 'Y' )
+ {
+ $r.=' Total HTVA';
+ foreach ($tva as $i=>$value)
+ {
+ $oTva->set_parameter('id',$i);
+ $oTva->load();
+
+ $r.=' TVA à '.$oTva->get_parameter('label');
+ }
+ $r.=' Total TVA';
+ $r.=' Total TVAC';
+ }
+ else
+ {
+ $r.=' Total ';
+ }
+ $r.='
';
+
+ $r.='';
+ $r.=''.$tot_amount.' ';
+
+ if ($owner->MY_TVA_USE == 'Y' )
+ {
+ foreach ($tva as $i=>$value)
+ {
+ $r.=' '.$tva[$i];
+ }
+ $r.=''.$tot_tva.' ';
+ $r.=''.$tot.' ';
+ }
+ $r.="
";
- // Set correctly the REQUEST param for jrn_type
- $r.=HtmlInput::hidden('jrn_type','VEN');
+ $r.=' ';
+ $r.="
";
- $r.=HtmlInput::button('add_item',_('Ajout article'), ' onClick="ledger_add_row()"');
+ /* Add hidden */
+ $r.=HtmlInput::hidden('e_client',$e_client);
+ $r.=HtmlInput::hidden('nb_item',$nb_item);
+ $r.=HtmlInput::hidden('p_jrn',$p_jrn);
+ $mt=microtime(true);
+ $r.=HtmlInput::hidden('mt',$mt);
- $r.="";
- return $r;
- }
- function input_paid() {
- $r='';
- $r.='';
- $r.=' '._('Payé par').' ';
- $mp=new Acc_Payment($this->db);
- $mp->set_parameter('type','VEN');
- $r.=$mp->select();
- $r.=' ';
- return $r;
- }
+ if ( isset($period))
+ $r.=HtmlInput::hidden('period',$period);
+ /*\todo comment les types hidden gérent ils des contenus avec des quotes, double quote ou < > ??? */
+ $r.=HtmlInput::hidden('e_comm',$e_comm);
+ $r.=HtmlInput::hidden('e_date',$e_date);
+ $r.=HtmlInput::hidden('e_ech',$e_ech);
+ $r.=HtmlInput::hidden('e_pj',$e_pj);
+ $r.=HtmlInput::hidden('e_pj_suggest',$e_pj_suggest);
- /*!\brief test function
- */
- static function test_me($p_string='') {
- $cn=new Database(dossier::id());
- $a=new Acc_Ledger_Sold($cn,2);
- echo $a->input();
- }
+ $e_mp=(isset($e_mp))?$e_mp:0;
+ $r.=HtmlInput::hidden('e_mp',$e_mp);
+ /* Paid by */
+ /* if the paymethod is not 0 and if a quick code is given */
+ if ( $e_mp!=0 && strlen (trim (${'e_mp_qcode_'.$e_mp})) != 0 )
+ {
+ $r.=HtmlInput::hidden('e_mp_qcode_'.$e_mp,${'e_mp_qcode_'.$e_mp});
+
+ /* needed for generating a invoice */
+ $r.=HtmlInput::hidden('qcode_dest',${'e_mp_qcode_'.$e_mp});
+
+ $r.=_("Payé par ").${'e_mp_qcode_'.$e_mp};
+ $r.=' ';
+ }
+
+ $r.=HtmlInput::hidden('jrn_type',$jrn_type);
+ for ($i=0;$i < $nb_item;$i++)
+ {
+ $r.=HtmlInput::hidden("e_march".$i,${"e_march".$i});
+ $r.=HtmlInput::hidden("e_march".$i."_price",${"e_march".$i."_price"});
+ if ( $owner->MY_TVA_USE=='Y')
+ {
+ $r.=HtmlInput::hidden("e_march".$i."_tva_id",${"e_march".$i."_tva_id"});
+ $r.=HtmlInput::hidden("e_march".$i."_tva_amount",${"e_march".$i."_tva_amount"});
+ }
+ $r.=HtmlInput::hidden("e_quant".$i,${"e_quant".$i});
+ }
+
+ return $r;
+ }
+ /*!\brief the function extra info allows to
+ * - add a attachment
+ * - generate an invoice
+ * - insert extra info
+ *\return string
+ */
+ public function extra_info()
+ {
+ $r="";
+ $r.='';
+ $r.='
Facturation ';
+ // check for upload piece
+ $file=new IFile();
+ $file->table=0;
+ $r.=_("Ajoutez une pièce justificative ");
+ $r.=$file->input("pj","");
+
+ if ( $this->db->count_sql("select md_id,md_name from document_modele where md_affect='VEN'") > 0 )
+ {
+
+
+ $r.=_('ou générer une facture').' ';
+ // We propose to generate the invoice and some template
+ $doc_gen=new ISelect();
+ $doc_gen->name="gen_doc";
+ $doc_gen->value=$this->db->make_array(
+ "select md_id,md_name ".
+ " from document_modele where md_affect='VEN'");
+ $r.=$doc_gen->input().' ';
+ }
+ $r.=' ';
+ $obj=new IText();
+ $r.=_('Numero de bon de commande : ').$obj->input('bon_comm').' ';
+ $r.=_('Autre information : ').$obj->input('other_info').' ';
+
+ $r.=" ";
+ $r.='';
+ return $r;
+ }
+
+
+ /*!\brief update the payment
+ */
+ function show_unpaid()
+ {
+ // Show list of unpaid sell
+ // Date - date of payment - Customer - amount
+ // Nav. bar
+ $step=$_SESSION['g_pagesize'];
+ $page=(isset($_GET['offset']))?$_GET['page']:1;
+ $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+
+
+ $sql=SQL_LIST_UNPAID_INVOICE_DATE_LIMIT." and jr_def_id=".$this->id ;
+ list($max_line,$list)=ListJrn($this->db,$sql,null,$offset,1);
+ $sql=SQL_LIST_UNPAID_INVOICE." and jr_def_id=".$this->id ;
+ list($max_line2,$list2)=ListJrn($this->db,$sql,null,$offset,1);
+
+ // Get the max line
+ $m=($max_line2>$max_line)?$max_line2:$max_line;
+ $bar2=jrn_navigation_bar($offset,$m,$step,$page);
+
+ echo $bar2;
+ echo ' '._('Echeance dépassée').' ';
+ echo $list;
+ echo ' '._('Non Payée').' ';
+ echo $list2;
+ echo $bar2;
+ // Add hidden parameter
+ $hid=new IHidden();
+
+ echo ' ';
+
+ if ( $m != 0 )
+ echo HtmlInput::submit('paid',_('Mise à jour paiement'));
+
+
+ }
+ /*!\brief display the form for entering data for invoice,
+ *\param $p_array is null or you can put the predef operation or the $_POST
+ *
+ *\return HTML string
+ */
+ function input($p_array=null)
+ {
+ if ( $p_array != null ) extract($p_array);
+ $user = new User($this->db);
+ $owner=new Own($this->db);
+ $flag_tva=$owner->MY_TVA_USE;
+ /* Add button */
+ $f_add_button=new IButton('add_card');
+ $f_add_button->label=_('Créer une nouvelle fiche');
+ $f_add_button->set_attribute('ipopup','ipop_newcard');
+ $f_add_button->set_attribute('jrn',$this->id);
+ $f_add_button->javascript="this.jrn=\$('p_jrn').value; select_card_type(this);";
+
+ $f_add_button2=new IButton('add_card2');
+ $f_add_button2->label=_('Créer une nouvelle fiche');
+ $f_add_button2->set_attribute('ipopup','ipop_newcard');
+ $f_add_button2->set_attribute('filter',$this->get_all_fiche_def ());
+ // $f_add_button2->set_attribute('jrn',$this->id);
+ $f_add_button2->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
+
+ $str_add_button=$f_add_button->input();
+ $str_add_button2=$f_add_button2->input();
+
+ // The first day of the periode
+ $oPeriode=new Periode($this->db);
+ list ($l_date_start,$l_date_end)=$oPeriode->get_date_limit($user->get_periode());
+ if ( $owner->MY_DATE_SUGGEST=='Y' )
+ $op_date=( ! isset($e_date) ) ?$l_date_start:$e_date;
+ else
+ $op_date=( ! isset($e_date) ) ?'':$e_date;
+
+
+ $e_ech=(isset($e_ech))?$e_ech:"";
+ $e_comm=(isset($e_comm))?$e_comm:"";
+
+ $r='';
+ $r.=dossier::hidden();
+ $f_legend=_('En-tête facture client');
+
+ $Echeance=new IDate();
+ $Echeance->setReadOnly(false);
+
+ $Echeance->tabindex=2;
+ $label=HtmlInput::infobulle(4);
+ $f_echeance=$Echeance->input('e_ech',$e_ech,_('Echéance').$label);
+ $Date=new IDate();
+ $Date->setReadOnly(false);
+
+ $f_date=$Date->input("e_date",$op_date);
+
+ $f_periode='';
+ // Periode
+ //--
+ if ($this->check_periode() == true)
+ {
+ $l_user_per=$user->get_periode();
+ $def=(isset($periode))?$periode:$l_user_per;
+
+ $period=new IPeriod("period");
+ $period->user=$user;
+ $period->cn=$this->db;
+ $period->value=$def;
+ $period->type=OPEN;
+ try
+ {
+ $l_form_per=$period->input();
+ }
+ catch (Exception $e)
+ {
+ if ($e->getCode() == 1 )
+ {
+ echo _("Aucune période ouverte");
+ exit();
+ }
+ }
+ $label=HtmlInput::infobulle(3);
+ $f_periode=_("Période comptable")." $label ".$l_form_per;
+ }
+ /* if we suggest the next pj, then we need a javascript */
+ $add_js="";
+ if ( $owner->MY_PJ_SUGGEST=='Y')
+ {
+ $add_js="update_pj();";
+ }
+ $add_js.='get_last_date();';
+
+ $wLedger=$this->select_ledger('VEN',2);
+ if ( $wLedger == null )
+ exit(_('Pas de journal disponible'));
+ $wLedger->table=1;
+ $wLedger->javascript="onChange='update_predef(\"ven\",\"f\");$add_js'";
+ $wLedger->label=" Journal ".HtmlInput::infobulle(2) ;
+
+ $f_jrn=$wLedger->input();
+
+ $Commentaire=new IText();
+ $Commentaire->table=0;
+ $Commentaire->setReadOnly(false);
+ $Commentaire->size=60;
+ $Commentaire->tabindex=3;
+
+ $label=HtmlInput::infobulle(1) ;
+
+ $f_desc=$label.$Commentaire->input("e_comm",h($e_comm));
+ // PJ
+ //--
+ /* suggest PJ ? */
+ $default_pj='';
+ if ( $owner->MY_PJ_SUGGEST=='Y')
+ {
+ $default_pj=$this->guess_pj();
+ }
+
+ $pj=new IText();
+
+ $pj->table=0;
+ $pj->name="e_pj";
+ $pj->size=10;
+ $pj->value=(isset($e_pj))?$e_pj:$default_pj;
+ $f_pj=$pj->input().HtmlInput::hidden('e_pj_suggest',$default_pj);
+ // Display the customer
+ //--
+ $fiche='deb';
+
+ // Save old value and set a new one
+ //--
+ $e_client=( isset ($e_client) )?$e_client:"";
+ $e_client_label=" ";//str_pad("",100,".");
+
+
+ // retrieve e_client_label
+ //--
+
+ if ( strlen(trim($e_client)) != 0)
+ {
+ $fClient=new Fiche($this->db);
+ $fClient->get_by_qcode($e_client);
+ $e_client_label=$fClient->strAttribut(ATTR_DEF_NAME).' '.
+ ' Adresse : '.$fClient->strAttribut(ATTR_DEF_ADRESS).' '.
+ $fClient->strAttribut(ATTR_DEF_CP).' '.
+ $fClient->strAttribut(ATTR_DEF_CITY).' ';
+
+
+ }
+
+ $W1=new ICard();
+ $W1->label="Client ".HtmlInput::infobulle(0) ;
+ $W1->name="e_client";
+ $W1->tabindex=3;
+ $W1->value=$e_client;
+ $W1->table=0;
+ $W1->set_dblclick("fill_ipopcard(this);");
+ $W1->set_attribute('ipopup','ipopcard');
+
+ // name of the field to update with the name of the card
+ $W1->set_attribute('label','e_client_label');
+ // name of the field to update with the name of the card
+ $W1->set_attribute('typecard','deb');
+ $W1->extra='deb';
+ // Add the callback function to filter the card on the jrn
+ $W1->set_callback('filter_card');
+ $W1->set_function('fill_data');
+ $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+ $W1->name);
+ $f_client_qcode=$W1->input();
+ $client_label=new ISpan();
+ $client_label->table=0;
+ $f_client=$client_label->input("e_client_label",$e_client_label);
+ $f_client_bt=$W1->search();
+
+
+ // Record the current number of article
+ $Hid=new IHidden();
+ $p_article= ( isset ($nb_item))?$nb_item:MAX_ARTICLE;
+ $r.=$Hid->input("nb_item",$p_article);
+ $max=($p_article < MAX_ARTICLE)?MAX_ARTICLE:$p_article;
+
+
+ $f_legend_detail=_("Détail articles vendus");
+
+ // For each article
+ //--
+ for ($i=0;$i< $max;$i++)
+ {
+ // Code id, price & vat code
+ //--
+ $march=(isset(${"e_march$i"}))?${"e_march$i"}:""
+ ;
+ $march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""
+ ;
+ if ( $flag_tva=='Y')
+ {
+ $march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:""
+ ;
+ $march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:""
+ ;
+ }
+ $march_label=' ';
+
+ // retrieve the tva label and name
+ //--
+ if ( strlen(trim($march))!=0 )
+ {
+ $fMarch=new Fiche($this->db);
+ $fMarch->get_by_qcode($march);
+ $march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
+ if ( $flag_tva=='Y')
+ {
+ if ( ! (isset(${"e_march$i"."_tva_id"})))
+ $march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
+ }
+ }
+ // Show input
+ //--
+ $W1=new ICard();
+ $W1->label="";
+ $W1->name="e_march".$i;
+ $W1->value=$march;
+ $W1->table=1;
+ $W1->set_attribute('typecard','cred');
+ $W1->set_dblclick("fill_ipopcard(this);");
+ $W1->set_attribute('ipopup','ipopcard');
+
+ $W1->extra='cred'; // credits
+ // name of the field to update with the name of the card
+ $W1->set_attribute('label','e_march'.$i.'_label');
+ // name of the field with the price
+ $W1->set_attribute('price','e_march'.$i.'_price');
+ // name of the field with the TVA_ID
+ $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
+ // Add the callback function to filter the card on the jrn
+ $W1->set_callback('filter_card');
+ $W1->set_function('fill_data');
+ $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+ $W1->name);
+
+ $W1->readonly=false;
+
+ $array[$i]['quick_code']=$W1->input();
+ $array[$i]['bt']=$W1->search();
+ // For computing we need some hidden field for holding the value
+ $array[$i]['hidden']='';
+ if ( $flag_tva=='Y') $array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
+
+ $htva=new INum('htva_march'.$i);
+ $htva->readOnly=1;
+ $htva->value=0;
+ $array[$i]['htva']=$htva->input();
+
+ if ( $owner->MY_TVA_USE=='Y')
+ $tvac=new INum('tvac_march'.$i);
+ else
+ $tvac=new IHidden('tvac_march'.$i);
+
+ $tvac->readOnly=1;
+ $tvac->value=0;
+ $array[$i]['tvac']=$tvac->input();
+
+
+ $Span=new ISpan();
+ $Span->setReadOnly(false);
+ // card's name, price
+ //--
+ $array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
+ // price
+ $Price=new INum();
+ $Price->setReadOnly(false);
+ $Price->size=9;
+ $Price->javascript="onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
+ $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
+ $array[$i]['tva']='';
+ $array[$i]['amount_tva']='';
+ // if tva is not needed then no tva field
+ if ( $flag_tva == 'Y' )
+ {
+ // vat label
+ //--
+ $Tva=new ITva_Popup($this->db);
+ $Tva->in_table=true;
+ $Tva->set_attribute('compute',$i);
+
+ $Tva->js='onblur="format_number(this);clean_tva('.$i.');compute_ledger('.$i.')"';
+ $Tva->value=$march_tva_id;
+ $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
+ // vat amount
+ //--
+ $wTva_amount=new INum();
+ $wTva_amount->readOnly=false;
+ $wTva_amount->size=6;
+ $wTva_amount->javascript="onBlur='format_number(this);compute_ledger($i)'";
+ $array[$i]['amount_tva']=$wTva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
+ }
+ // quantity
+ //--
+ $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1"
+ ;
+ $Quantity=new INum();
+ $Quantity->setReadOnly(false);
+ $Quantity->size=8;
+ $Quantity->javascript="onChange='format_number(this);clean_tva($i);compute_ledger($i)'";
+ $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
+
+ }// foreach article
+ $f_type=_('Client');
+
+
+ ob_start();
+ require_once('template/form_ledger_detail.php');
+ $r.=ob_get_contents();
+ ob_clean();
+
+
+
+ // Set correctly the REQUEST param for jrn_type
+ $r.=HtmlInput::hidden('jrn_type','VEN');
+
+ $r.=HtmlInput::button('add_item',_('Ajout article'), ' onClick="ledger_add_row()"');
+
+ $r.="";
+ return $r;
+ }
+ function input_paid()
+ {
+ $r='';
+ $r.='';
+ $r.=' '._('Payé par').' ';
+ $mp=new Acc_Payment($this->db);
+ $mp->set_parameter('type','VEN');
+ $r.=$mp->select();
+ $r.=' ';
+ return $r;
+ }
+
+ /*!\brief test function
+ */
+ static function test_me($p_string='')
+ {
+ $cn=new Database(dossier::id());
+ $a=new Acc_Ledger_Sold($cn,2);
+ echo $a->input();
+ }
}
diff --git a/include/class_acc_operation.php b/include/class_acc_operation.php
index ea5ed8edd..807a4e0e2 100644
--- a/include/class_acc_operation.php
+++ b/include/class_acc_operation.php
@@ -33,480 +33,526 @@ require_once('class_acc_ledger.php');
*/
class Acc_Operation
{
- var $db; /*!< database connx */
- var $jr_id; /*!< pk of jrn */
- var $jrn_id; /*!< jrn_def_id */
- var $debit; /*!< debit or credit */
- var $user; /*!< current user */
- var $jrn; /*!< the ledger to use */
- var $poste; /*!< account */
- var $date; /*!< the date */
- var $periode; /*!< periode to use */
- var $amount; /*!< amount of the operatoin */
- var $grpt; /*!< the group id */
-/*!
- * \brief constructor set automatically the attributes user and periode
- * \param $p_cn the databse connection
- */
- function __construct($p_cn) {
- $this->db=$p_cn;
- $this->qcode="";
- $this->user=$_SESSION['g_user'];
- $user=new User($this->db);
- $this->periode=$user->get_periode();
- $this->jr_id=0;
- }
- /**
- *@brief retrieve the grpt_id from jrn for a jr_id
- *@return jrn.jr_grpt_id or an empty string if not found
- */
- function seek_group()
- {
- $ret=$this->db->get_value('select jr_grpt_id from jrn where jr_id=$1',
- array($this->jr_id));
- return $ret;
- }
- /**
- *@brief Insert into the table Jrn
- *The needed data are :
- * - this->date
- * - this->amount
- * - this->poste
- * - this->grpt
- * - this->jrn
- * - this->type ( debit or credit)
- * - this->user
- * - this->periode
- * - this->qcode
- * - this->desc optional
- *@note if the amount is less than 0 then side changes, for example debit becomes
- *a credit and vice versa
- */
-
- function insert_jrnx()
- {
- if ( $this->poste == "") return true;
- /* for negative amount the operation is reversed */
- if ( $this->amount < 0 ) {
- $this->type=($this->type=='d')?'c':'d';
+ var $db; /*!< database connx */
+ var $jr_id; /*!< pk of jrn */
+ var $jrn_id; /*!< jrn_def_id */
+ var $debit; /*!< debit or credit */
+ var $user; /*!< current user */
+ var $jrn; /*!< the ledger to use */
+ var $poste; /*!< account */
+ var $date; /*!< the date */
+ var $periode; /*!< periode to use */
+ var $amount; /*!< amount of the operatoin */
+ var $grpt; /*!< the group id */
+ /*!
+ * \brief constructor set automatically the attributes user and periode
+ * \param $p_cn the databse connection
+ */
+ function __construct($p_cn)
+ {
+ $this->db=$p_cn;
+ $this->qcode="";
+ $this->user=$_SESSION['g_user'];
+ $user=new User($this->db);
+ $this->periode=$user->get_periode();
+ $this->jr_id=0;
}
- $this->amount=abs($this->amount);
- $debit=($this->type=='c')?'false':'true';
- $this->desc=(isset($this->desc))?$this->desc:'';
- $Res=$this->db->exec_sql("select insert_jrnx
- ($1::text,abs($2)::numeric,$3::account_type,$4::integer,$5::integer,$6::bool,$7::text,$8::integer,upper($9),$10::text)",
- array(
- $this->date, //$1
- round($this->amount,2), //$2
- $this->poste, //$3
- $this->grpt, //$4
- $this->jrn, //$5
- $debit, //$6
- $this->user, //$7
- $this->periode, //$8
- $this->qcode, // $9
- $this->desc)); //$10
- if ( $Res==false) return $Res;
- $this->jrnx_id=$this->db->get_current_seq('s_jrn_op');
- return $this->jrnx_id;
-
- }
- /*!\brief set the pj of a operation in jrn. the jr_id must be set
- *\note if the jr_id it fails
- */
- function set_pj() {
- if ( strlen(trim($this->pj)) == 0 ) {
- $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
- $this->db->exec_sql($sql,array(null,$this->jr_id));
- return '';
- }
- /* is pj uniq ? */
- if ( $this->db->count_sql("select jr_id from jrn where jr_pj_number=$1 and jr_def_id=$2",
- array($this->pj,$this->jrn)
- ) == 0 ) {
- $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
- $this->db->exec_sql($sql,array($this->pj,$this->jr_id));
- } else {
- /* get pref */
- $pref=$this->db->get_value("select jrn_def_pj_pref from jrn_def where jrn_def_id=$1",
- array($this->jrn));
- /* try another seq */
- $flag=0;$limit=100;
- while ( $flag == 0 ) {
- /* limit the search to $limit */
- if ( $limit < 1 ) { $this->pj='';$flag=2; break;}
-
- $seq=$this->db->get_next_seq('s_jrn_pj'.$this->jrn);
- $this->pj=$pref.$seq;
-
- /* check if the new pj numb exist */
- $c=$this->db->count_sql("select jr_id from jrn where jr_pj_number=$1 and jr_def_id=$2",
- array($this->pj,$this->jrn)
- );
- if ( $c == 0 ) { $flag=1; break;}
- $limit--;
- }
- /* a pj numb is found */
- if ( $flag == 1 ) {
- $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
- $this->db->exec_sql($sql,array($this->pj,$this->jr_id));
- }
+ /**
+ *@brief retrieve the grpt_id from jrn for a jr_id
+ *@return jrn.jr_grpt_id or an empty string if not found
+ */
+ function seek_group()
+ {
+ $ret=$this->db->get_value('select jr_grpt_id from jrn where jr_id=$1',
+ array($this->jr_id));
+ return $ret;
}
- return $this->pj;
- }
+ /**
+ *@brief Insert into the table Jrn
+ *The needed data are :
+ * - this->date
+ * - this->amount
+ * - this->poste
+ * - this->grpt
+ * - this->jrn
+ * - this->type ( debit or credit)
+ * - this->user
+ * - this->periode
+ * - this->qcode
+ * - this->desc optional
+ *@note if the amount is less than 0 then side changes, for example debit becomes
+ *a credit and vice versa
+ */
-/*!
- *\brief Insert into the table Jrn, the amount is computed from jrnx thanks the
- * group id ($p_grpt)
- *
- * \return sequence of jr_id
- *
- */
+ function insert_jrnx()
+ {
+ if ( $this->poste == "") return true;
+ /* for negative amount the operation is reversed */
+ if ( $this->amount < 0 )
+ {
+ $this->type=($this->type=='d')?'c':'d';
+ }
+ $this->amount=abs($this->amount);
+ $debit=($this->type=='c')?'false':'true';
+ $this->desc=(isset($this->desc))?$this->desc:'';
+ $Res=$this->db->exec_sql("select insert_jrnx
+ ($1::text,abs($2)::numeric,$3::account_type,$4::integer,$5::integer,$6::bool,$7::text,$8::integer,upper($9),$10::text)",
+ array(
+ $this->date, //$1
+ round($this->amount,2), //$2
+ $this->poste, //$3
+ $this->grpt, //$4
+ $this->jrn, //$5
+ $debit, //$6
+ $this->user, //$7
+ $this->periode, //$8
+ $this->qcode, // $9
+ $this->desc)); //$10
+ if ( $Res==false) return $Res;
+ $this->jrnx_id=$this->db->get_current_seq('s_jrn_op');
+ return $this->jrnx_id;
- function insert_jrn()
- {
- $p_comment=$this->desc;
+ }
+ /*!\brief set the pj of a operation in jrn. the jr_id must be set
+ *\note if the jr_id it fails
+ */
+ function set_pj()
+ {
+ if ( strlen(trim($this->pj)) == 0 )
+ {
+ $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
+ $this->db->exec_sql($sql,array(null,$this->jr_id));
+ return '';
+ }
+ /* is pj uniq ? */
+ if ( $this->db->count_sql("select jr_id from jrn where jr_pj_number=$1 and jr_def_id=$2",
+ array($this->pj,$this->jrn)
+ ) == 0 )
+ {
+ $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
+ $this->db->exec_sql($sql,array($this->pj,$this->jr_id));
+ }
+ else
+ {
+ /* get pref */
+ $pref=$this->db->get_value("select jrn_def_pj_pref from jrn_def where jrn_def_id=$1",
+ array($this->jrn));
+ /* try another seq */
+ $flag=0;
+ $limit=100;
+ while ( $flag == 0 )
+ {
+ /* limit the search to $limit */
+ if ( $limit < 1 )
+ {
+ $this->pj='';
+ $flag=2;
+ break;
+ }
- $diff=$this->db->get_value("select check_balance ($1)",array($this->grpt));
- if ( $diff != 0 ) {
+ $seq=$this->db->get_next_seq('s_jrn_pj'.$this->jrn);
+ $this->pj=$pref.$seq;
- echo "Erreur : balance incorrecte :diff = $diff";
- return false;
+ /* check if the new pj numb exist */
+ $c=$this->db->count_sql("select jr_id from jrn where jr_pj_number=$1 and jr_def_id=$2",
+ array($this->pj,$this->jrn)
+ );
+ if ( $c == 0 )
+ {
+ $flag=1;
+ break;
+ }
+ $limit--;
+ }
+ /* a pj numb is found */
+ if ( $flag == 1 )
+ {
+ $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
+ $this->db->exec_sql($sql,array($this->pj,$this->jr_id));
+ }
+ }
+ return $this->pj;
}
- $echeance=( isset( $this->echeance) && strlen(trim($this->echeance)) != 0)?$this->echeance:null;
- if ( ! isset($this->mt) ) {
- $this->mt=microtime(true);
+ /*!
+ *\brief Insert into the table Jrn, the amount is computed from jrnx thanks the
+ * group id ($p_grpt)
+ *
+ * \return sequence of jr_id
+ *
+ */
+
+ function insert_jrn()
+ {
+ $p_comment=$this->desc;
+
+ $diff=$this->db->get_value("select check_balance ($1)",array($this->grpt));
+ if ( $diff != 0 )
+ {
+
+ echo "Erreur : balance incorrecte :diff = $diff";
+ return false;
+ }
+
+ $echeance=( isset( $this->echeance) && strlen(trim($this->echeance)) != 0)?$this->echeance:null;
+ if ( ! isset($this->mt) )
+ {
+ $this->mt=microtime(true);
+ }
+ // if amount == -1then the triggers will throw an error
+ //
+ $Res=$this->db->exec_sql("insert into jrn (jr_def_id,jr_montant,jr_comment,".
+ "jr_date,jr_ech,jr_grpt_id,jr_tech_per,jr_mt) values (".
+ "$1,$2,$3,".
+ "to_date($4,'DD.MM.YYYY'),to_date($5,'DD.MM.YYYY'),$6,$7,$8)",
+ array ($this->jrn, $this->amount,$p_comment,
+ $this->date,$echeance,$this->grpt,$this->periode,$this->mt)
+ );
+ if ( $Res == false) return false;
+ $this->jr_id=$this->db->get_current_seq('s_jrn');
+ return $this->jr_id;
}
- // if amount == -1then the triggers will throw an error
- //
- $Res=$this->db->exec_sql("insert into jrn (jr_def_id,jr_montant,jr_comment,".
- "jr_date,jr_ech,jr_grpt_id,jr_tech_per,jr_mt) values (".
- "$1,$2,$3,".
- "to_date($4,'DD.MM.YYYY'),to_date($5,'DD.MM.YYYY'),$6,$7,$8)",
- array ($this->jrn, $this->amount,$p_comment,
- $this->date,$echeance,$this->grpt,$this->periode,$this->mt)
- );
- if ( $Res == false) return false;
- $this->jr_id=$this->db->get_current_seq('s_jrn');
- return $this->jr_id;
- }
-/*!
- * \brief Return the internal value, the property jr_id must be set before
- *
- * \return null si aucune valeur de trouv
- *
- */
-function get_internal() {
- if ( ! isset($this->jr_id) )
- throw new Exception('jr_id is not set',1);
- $Res=$this->db->exec_sql("select jr_internal from jrn where jr_id=".$this->jr_id);
- if ( Database::num_row($Res) == 0 ) return null;
- $l_line=Database::fetch_array($Res);
- $this->jr_internal= $l_line['jr_internal'];
- return $this->jr_internal;
-}
-/*!\brief search an operation thankx it internal code
- * \param internal code
- * \return 0 ok -1 nok
- */
- function seek_internal($p_internal) {
- $res=$this->db->exec_sql('select jr_id from jrn where jr_internal=$1',
- array($p_internal));
- if ( Database::num_row($Res) == 0 ) return -1;
- $this->jr_id=Database::fetch_result($Res,0,0);
- return 0;
- }
- /*!\brief retrieve data from jrnx
- *\note the data are filtered by the access of the current user
- * \return an array
- */
- function get_jrnx_detail() {
- $user=new User($this->db);
- $filter_sql=$user->get_ledger_sql('ALL',3);
- $filter_sql=str_replace('jrn_def_id','jr_def_id',$filter_sql);
- if ( $this->jr_id==0 ) return;
- $sql=" select jr_date,j_qcode,j_poste,j_montant,jr_internal,case when j_debit = 'f' then 'C' else 'D' end as debit,jr_comment as description,
- vw_name,pcm_lib,j_debit,coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter ".
- " from jrnx join jrn on (jr_grpt_id=j_grpt)
- join tmp_pcmn on (j_poste=pcm_val)
- left join vw_fiche_attr on (j_qcode=quick_code)
- where
- jr_id=$1 and $filter_sql order by j_debit desc";
- $res=$this->db->exec_sql($sql,array($this->jr_id));
- if ( Database::num_row ($res) == 0 ) return array();
- $all=Database::fetch_all($res);
- return $all;
- }
- /*!\brief add a comment to the line (jrnx.j_text) */
- function update_comment($p_text)
- {
- $sql="update jrnx set j_text=$1 where j_id=$2";
- $this->db->exec_sql($sql,array($p_text,$this->jrnx_id));
- }
- /*!\brief add a comment to the operation (jrn.jr_text) */
- function operation_update_comment($p_text)
- {
- $sql="update jrn set jr_comment=$1 where jr_id=$2";
- $this->db->exec_sql($sql,array($p_text,$this->jr_id));
- }
- /*!\brief add a limit of payment to the operation (jrn.jr_ech) */
- function operation_update_date_limit($p_text)
- {
- if ( isDate($p_text) == null ) {
- $p_text=null;
- }
- $sql="update jrn set jr_ech=to_date($1,'DD.MM.YYYY') where jr_id=$2";
- $this->db->exec_sql($sql,array($p_text,$this->jr_id));
- }
- /*!\brief return the jrn_def_id from jrn */
- function get_ledger() {
- $sql="select jr_def_id from jrn where jr_id=$1";
- $row=$this->db->get_value($sql,array($this->jr_id));
- return $row;
- }
- /*!\brief display_jrnx_detail : get the data from get_jrnx_data and
- return a string with HTML code
- * \param table(=0 no code for table,1 code for table,2 code for CSV)
+ /*!
+ * \brief Return the internal value, the property jr_id must be set before
+ *
+ * \return null si aucune valeur de trouv
+ *
+ */
+ function get_internal()
+ {
+ if ( ! isset($this->jr_id) )
+ throw new Exception('jr_id is not set',1);
+ $Res=$this->db->exec_sql("select jr_internal from jrn where jr_id=".$this->jr_id);
+ if ( Database::num_row($Res) == 0 ) return null;
+ $l_line=Database::fetch_array($Res);
+ $this->jr_internal= $l_line['jr_internal'];
+ return $this->jr_internal;
+ }
+ /*!\brief search an operation thankx it internal code
+ * \param internal code
+ * \return 0 ok -1 nok
+ */
+ function seek_internal($p_internal)
+ {
+ $res=$this->db->exec_sql('select jr_id from jrn where jr_internal=$1',
+ array($p_internal));
+ if ( Database::num_row($Res) == 0 ) return -1;
+ $this->jr_id=Database::fetch_result($Res,0,0);
+ return 0;
+ }
+ /*!\brief retrieve data from jrnx
+ *\note the data are filtered by the access of the current user
+ * \return an array
+ */
+ function get_jrnx_detail()
+ {
+ $user=new User($this->db);
+ $filter_sql=$user->get_ledger_sql('ALL',3);
+ $filter_sql=str_replace('jrn_def_id','jr_def_id',$filter_sql);
+ if ( $this->jr_id==0 ) return;
+ $sql=" select jr_date,j_qcode,j_poste,j_montant,jr_internal,case when j_debit = 'f' then 'C' else 'D' end as debit,jr_comment as description,
+ vw_name,pcm_lib,j_debit,coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter ".
+ " from jrnx join jrn on (jr_grpt_id=j_grpt)
+ join tmp_pcmn on (j_poste=pcm_val)
+ left join vw_fiche_attr on (j_qcode=quick_code)
+ where
+ jr_id=$1 and $filter_sql order by j_debit desc";
+ $res=$this->db->exec_sql($sql,array($this->jr_id));
+ if ( Database::num_row ($res) == 0 ) return array();
+ $all=Database::fetch_all($res);
+ return $all;
+ }
+ /*!\brief add a comment to the line (jrnx.j_text) */
+ function update_comment($p_text)
+ {
+ $sql="update jrnx set j_text=$1 where j_id=$2";
+ $this->db->exec_sql($sql,array($p_text,$this->jrnx_id));
+ }
+ /*!\brief add a comment to the operation (jrn.jr_text) */
+ function operation_update_comment($p_text)
+ {
+ $sql="update jrn set jr_comment=$1 where jr_id=$2";
+ $this->db->exec_sql($sql,array($p_text,$this->jr_id));
+ }
+ /*!\brief add a limit of payment to the operation (jrn.jr_ech) */
+ function operation_update_date_limit($p_text)
+ {
+ if ( isDate($p_text) == null )
+ {
+ $p_text=null;
+ }
+ $sql="update jrn set jr_ech=to_date($1,'DD.MM.YYYY') where jr_id=$2";
+ $this->db->exec_sql($sql,array($p_text,$this->jr_id));
+ }
+ /*!\brief return the jrn_def_id from jrn */
+ function get_ledger()
+ {
+ $sql="select jr_def_id from jrn where jr_id=$1";
+ $row=$this->db->get_value($sql,array($this->jr_id));
+ return $row;
+ }
+ /*!\brief display_jrnx_detail : get the data from get_jrnx_data and
+ return a string with HTML code
+ * \param table(=0 no code for table,1 code for table,2 code for CSV)
- */
- function display_jrnx_detail($p_table) {
- $show=$this->get_jrnx_detail();
+ */
+ function display_jrnx_detail($p_table)
+ {
+ $show=$this->get_jrnx_detail();
- $r='';
- $r_notable='';
- $csv="";
- foreach ($show as $l) {
- if ( $l['j_poste'] == $this->poste || $l['j_qcode']==$this->qcode)
- $border=' style="border-bottom:1px solid red;"';
- else
- $border='';
- $r.='';
- $r.='';
- $a=$l['j_qcode'];;
- $r_notable.=$a;
- $r.=$a;
- $csv.='"'.$a.'";';
- $r.=' ';
+ $r='';
+ $r_notable='';
+ $csv="";
+ foreach ($show as $l)
+ {
+ if ( $l['j_poste'] == $this->poste || $l['j_qcode']==$this->qcode)
+ $border=' style="border-bottom:1px solid red;"';
+ else
+ $border='';
+ $r.=' ';
+ $r.='';
+ $a=$l['j_qcode'];
+ ;
+ $r_notable.=$a;
+ $r.=$a;
+ $csv.='"'.$a.'";';
+ $r.=' ';
- $r.='';
- $a=$l['j_poste'];
- $r_notable.=$a;
- $r.=$a;
- $csv.='"'.$a.'";';
- $r.=' ';
+ $r.='';
+ $a=$l['j_poste'];
+ $r_notable.=$a;
+ $r.=$a;
+ $csv.='"'.$a.'";';
+ $r.=' ';
- $r.='';
- // $a=($l['vw_name']=="")?$l['j_qcode']:$l['pcm_lib'];
- $a=(strlen(trim($l['j_qcode']))==0)?$l['pcm_lib']:$l['vw_name'];
- $r_notable.=$a;
- $r.=h($a);
- $csv.='"'.$a.'";';
- $r.=' ';
+ $r.='';
+ // $a=($l['vw_name']=="")?$l['j_qcode']:$l['pcm_lib'];
+ $a=(strlen(trim($l['j_qcode']))==0)?$l['pcm_lib']:$l['vw_name'];
+ $r_notable.=$a;
+ $r.=h($a);
+ $csv.='"'.$a.'";';
+ $r.=' ';
- $r.='';
- $a=$l['j_montant'];
- $r_notable.=$a;
- $r.=$a;
- $csv.=$a.';';
- $r.=' ';
+ $r.='';
+ $a=$l['j_montant'];
+ $r_notable.=$a;
+ $r.=$a;
+ $csv.=$a.';';
+ $r.=' ';
- $r.='';
- $a=$l['debit'];
- $r_notable.=$a;
- $r.=$a;
- $csv.='"'.$a.'"';
+ $r.=' ';
+ $a=$l['debit'];
+ $r_notable.=$a;
+ $r.=$a;
+ $csv.='"'.$a.'"';
- $csv.="\r\n";
- $r.=' ';
- $r.='';
- $a=($l['letter']!=-1)?$l['letter']:'';
- $r_notable.=$a;
- $r.=$a;
- $csv.='"'.$a.'"';
+ $csv.="\r\n";
+ $r.=' ';
+ $r.='';
+ $a=($l['letter']!=-1)?$l['letter']:'';
+ $r_notable.=$a;
+ $r.=$a;
+ $csv.='"'.$a.'"';
- $csv.="\r\n";
- $r.=' ';
+ $csv.="\r\n";
+ $r.='';
- $r.=' ';
- }
- switch ($p_table) {
- case 1:
- return $r;
- break;
- case 0:
- return $r_notable;
- break;
- case 2:
- return $csv;
- }
- return "ERROR PARAMETRE";
- }
-/*!
- * @brief Get data from jrnx where p_grpt=jrnx(j_grpt)
- *
- * @param connection
- * @return array of 3 elements
- * - First Element is an array
-@verbatim
-Array
-(
- [op_date] => 01.12.2009
- [class_cred0] => 7000008
- [mont_cred0] => 8880.0000
- [op_cred0] => 754
- [text_cred0] =>
- [jr_internal] => 23VEN-01-302
- [comment] =>
- [ech] =>
- [jr_id] => 302
- [jr_def_id] => 2
- [class_deb0] => 4000005
- [mont_deb0] => 10744.8000
- [text_deb0] =>
- [op_deb0] => 755
- [class_cred1] => 4511
- [mont_cred1] => 1864.8000
- [op_cred1] => 756
- [text_cred1] =>
-)
-@endverbatim
- * - Second : number of line with debit
- * - Third : number of line with credit
- */
- function get_data ($p_grpt) {
- $Res=$this->db->exec_sql("select
- to_char(j_date,'DD.MM.YYYY') as j_date,
- j_text,
- j_debit,
- j_poste,
- coalesce(j_qcode,'-') as qcode,
- 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=$1",array($p_grpt));
- $MaxLine=Database::num_row($Res);
- if ( $MaxLine == 0 ) return null;
- $deb=0;$cred=0;
- for ( $i=0; $i < $MaxLine; $i++) {
+ $r.=' ';
+ }
+ switch ($p_table)
+ {
+ case 1:
+ return $r;
+ break;
+ case 0:
+ return $r_notable;
+ break;
+ case 2:
+ return $csv;
+ }
+ return "ERROR PARAMETRE";
+ }
+ /*!
+ * @brief Get data from jrnx where p_grpt=jrnx(j_grpt)
+ *
+ * @param connection
+ * @return array of 3 elements
+ * - First Element is an array
+ @verbatim
+ Array
+ (
+ [op_date] => 01.12.2009
+ [class_cred0] => 7000008
+ [mont_cred0] => 8880.0000
+ [op_cred0] => 754
+ [text_cred0] =>
+ [jr_internal] => 23VEN-01-302
+ [comment] =>
+ [ech] =>
+ [jr_id] => 302
+ [jr_def_id] => 2
+ [class_deb0] => 4000005
+ [mont_deb0] => 10744.8000
+ [text_deb0] =>
+ [op_deb0] => 755
+ [class_cred1] => 4511
+ [mont_cred1] => 1864.8000
+ [op_cred1] => 756
+ [text_cred1] =>
+ )
+ @endverbatim
+ * - Second : number of line with debit
+ * - Third : number of line with credit
+ */
+ function get_data ($p_grpt)
+ {
+ $Res=$this->db->exec_sql("select
+ to_char(j_date,'DD.MM.YYYY') as j_date,
+ j_text,
+ j_debit,
+ j_poste,
+ coalesce(j_qcode,'-') as qcode,
+ 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=$1",array($p_grpt));
+ $MaxLine=Database::num_row($Res);
+ if ( $MaxLine == 0 ) return null;
+ $deb=0;
+ $cred=0;
+ for ( $i=0; $i < $MaxLine; $i++)
+ {
- $l_line=Database::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_qcode=sprintf("qcode_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_array[$l_qcode]=$l_line['qcode'];
- $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",$cred);
- $l_array[$l_text]=$l_line['j_text'];
- $l_qcode=sprintf("qcode_cred%d",$cred);
- $l_array[$l_qcode]=$l_line['qcode'];
- $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 retrieve data from jrnx and jrn
- *@return return an object
- *@note
- *@see
-@code
+ $l_line=Database::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_qcode=sprintf("qcode_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_array[$l_qcode]=$l_line['qcode'];
+ $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",$cred);
+ $l_array[$l_text]=$l_line['j_text'];
+ $l_qcode=sprintf("qcode_cred%d",$cred);
+ $l_array[$l_qcode]=$l_line['qcode'];
+ $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 retrieve data from jrnx and jrn
+ *@return return an object
+ *@note
+ *@see
+ @code
-@endcode
- */
- function get() {
- $ret=new Acc_Misc($this->db,$this->jr_id);
- $ret->get();
- return $ret;
- }
- /**
- *@brief retrieve data from the table QUANT_*
- *@return return an object or null if there is no
- * data from the QUANT table
- *@see Acc_Sold Acc_Purchase Acc_Fin Acc_Detail Acc_Misc
- */
- function get_quant() {
- $ledger_id=$this->get_ledger();
- if ( $ledger_id=='') throw new Exception('Journal non trouvé');
- $oledger=new Acc_Ledger($this->db,$ledger_id);
+ @endcode
+ */
+ function get()
+ {
+ $ret=new Acc_Misc($this->db,$this->jr_id);
+ $ret->get();
+ return $ret;
+ }
+ /**
+ *@brief retrieve data from the table QUANT_*
+ *@return return an object or null if there is no
+ * data from the QUANT table
+ *@see Acc_Sold Acc_Purchase Acc_Fin Acc_Detail Acc_Misc
+ */
+ function get_quant()
+ {
+ $ledger_id=$this->get_ledger();
+ if ( $ledger_id=='') throw new Exception('Journal non trouvé');
+ $oledger=new Acc_Ledger($this->db,$ledger_id);
- switch($oledger->get_type()) {
- case 'VEN':
- $ret=new Acc_Sold($this->db,$this->jr_id);
- break;
- case 'ACH':
- $ret=new Acc_Purchase($this->db,$this->jr_id);
- break;
- case 'FIN':
- $ret=new Acc_Fin($this->db,$this->jr_id);
- break;
- default:
- return $this->get();
- }
- $ret->get();
- if ( empty($ret->det->array))
- {$ret=new Acc_Misc($this->db,$this->jr_id); $ret->get();}
- return $ret;
- }
- static function test_me() {
- $_SESSION['g_user']='phpcompta';
- $_SESSION['g_pass']='dany';
+ switch($oledger->get_type())
+ {
+ case 'VEN':
+ $ret=new Acc_Sold($this->db,$this->jr_id);
+ break;
+ case 'ACH':
+ $ret=new Acc_Purchase($this->db,$this->jr_id);
+ break;
+ case 'FIN':
+ $ret=new Acc_Fin($this->db,$this->jr_id);
+ break;
+ default:
+ return $this->get();
+ }
+ $ret->get();
+ if ( empty($ret->det->array))
+ {
+ $ret=new Acc_Misc($this->db,$this->jr_id);
+ $ret->get();
+ }
+ return $ret;
+ }
+ static function test_me()
+ {
+ $_SESSION['g_user']='phpcompta';
+ $_SESSION['g_pass']='dany';
- $cn=new Database(dossier::id());
- $a=new Acc_Operation($cn);
- $a->jr_id=11;
- $b=$a->get_quant();
- var_dump($b->det);
- }
+ $cn=new Database(dossier::id());
+ $a=new Acc_Operation($cn);
+ $a->jr_id=11;
+ $b=$a->get_quant();
+ var_dump($b->det);
+ }
}
/////////////////////////////////////////////////////////////////////////////
-class Acc_Detail extends Acc_Operation {
- function __construct($p_cn,$p_jrid=0) {
- parent::__construct($p_cn);
- $this->jr_id=$p_jrid;
- $this->det=new stdClass();
- }
- /**
- *@brief retrieve some common data from jrnx / jrn as
- * the datum, the comment,...
- */
- function get() {
- $sql="SELECT jr_id, jr_def_id, jr_montant, jr_comment, jr_date, jr_grpt_id,
- jr_internal, jr_tech_date, jr_tech_per, jrn_ech, jr_ech, jr_rapt,
- jr_valid, jr_opid, jr_c_opid, jr_pj, jr_pj_name, jr_pj_type,
- jr_pj_number, jr_mt
- FROM jrn where jr_id=$1";
- $array=$this->db->get_array($sql,array($this->jr_id));
- if ( count($array) == 0 ) throw new Exception('Aucune ligne trouvée');
- foreach ($array[0] as $key=>$val) {
- $this->det->$key=$val;
+class Acc_Detail extends Acc_Operation
+{
+ function __construct($p_cn,$p_jrid=0)
+ {
+ parent::__construct($p_cn);
+ $this->jr_id=$p_jrid;
+ $this->det=new stdClass();
+ }
+ /**
+ *@brief retrieve some common data from jrnx / jrn as
+ * the datum, the comment,...
+ */
+ function get()
+ {
+ $sql="SELECT jr_id, jr_def_id, jr_montant, jr_comment, jr_date, jr_grpt_id,
+ jr_internal, jr_tech_date, jr_tech_per, jrn_ech, jr_ech, jr_rapt,
+ jr_valid, jr_opid, jr_c_opid, jr_pj, jr_pj_name, jr_pj_type,
+ jr_pj_number, jr_mt
+ FROM jrn where jr_id=$1";
+ $array=$this->db->get_array($sql,array($this->jr_id));
+ if ( count($array) == 0 ) throw new Exception('Aucune ligne trouvée');
+ foreach ($array[0] as $key=>$val)
+ {
+ $this->det->$key=$val;
+ }
}
- }
}
/////////////////////////////////////////////////////////////////////////////
/**
@@ -516,21 +562,23 @@ class Acc_Detail extends Acc_Operation {
*/
class Acc_Misc extends Acc_Detail
{
- var $signature; /*!< signature of the obj ODS */
- var $array; /*!< an array containing the data from JRNX */
- function __construct($p_cn,$p_jrid=0) {
- parent::__construct($p_cn,$p_jrid);
- $this->signature='ODS';
- $this->det=new stdClass();
- }
- function get() {
- parent::get();
- $sql="SELECT j_id, j_date, j_montant, j_poste, j_grpt, j_rapt, j_jrn_def,
- j_debit, j_text, j_centralized, j_internal, j_tech_user, j_tech_date,
- j_tech_per, j_qcode
- FROM jrnx where j_grpt = $1 order by j_debit desc,j_poste";
- $this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id));
- }
+ var $signature; /*!< signature of the obj ODS */
+ var $array; /*!< an array containing the data from JRNX */
+ function __construct($p_cn,$p_jrid=0)
+ {
+ parent::__construct($p_cn,$p_jrid);
+ $this->signature='ODS';
+ $this->det=new stdClass();
+ }
+ function get()
+ {
+ parent::get();
+ $sql="SELECT j_id, j_date, j_montant, j_poste, j_grpt, j_rapt, j_jrn_def,
+ j_debit, j_text, j_centralized, j_internal, j_tech_user, j_tech_date,
+ j_tech_per, j_qcode
+ FROM jrnx where j_grpt = $1 order by j_debit desc,j_poste";
+ $this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id));
+ }
}
/////////////////////////////////////////////////////////////////////////////
/**
@@ -540,41 +588,45 @@ class Acc_Misc extends Acc_Detail
*/
class Acc_Sold extends Acc_Detail
{
- function __construct($p_cn,$p_jrid=0) {
- parent::__construct($p_cn,$p_jrid);
- $this->signature='VEN';
- $this->det=new stdClass();
- }
- function get() {
- parent::get();
- $sql="SELECT qs_id, qs_internal, qs_fiche, qs_quantite, qs_price, qs_vat,
- qs_vat_code, qs_client, qs_valid, j_id
- FROM quant_sold where j_id in (select j_id from jrnx where j_grpt=$1)";
- $this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id));
- }
+ function __construct($p_cn,$p_jrid=0)
+ {
+ parent::__construct($p_cn,$p_jrid);
+ $this->signature='VEN';
+ $this->det=new stdClass();
+ }
+ function get()
+ {
+ parent::get();
+ $sql="SELECT qs_id, qs_internal, qs_fiche, qs_quantite, qs_price, qs_vat,
+ qs_vat_code, qs_client, qs_valid, j_id
+ FROM quant_sold where j_id in (select j_id from jrnx where j_grpt=$1)";
+ $this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id));
+ }
}
/////////////////////////////////////////////////////////////////////////////
/**
*@brief this class manage data from the QUANT_PURCHASE
* table
*@note Data member are the column of the table
-
+
*/
class Acc_Purchase extends Acc_Detail
{
- function __construct($p_cn,$p_jrid=0) {
- parent::__construct($p_cn,$p_jrid);
- $this->signature='ACH';
- }
+ function __construct($p_cn,$p_jrid=0)
+ {
+ parent::__construct($p_cn,$p_jrid);
+ $this->signature='ACH';
+ }
- function get() {
- parent::get();
- $sql="SELECT qp_id, qp_internal, j_id, qp_fiche, qp_quantite, qp_price, qp_vat,
- qp_vat_code, qp_nd_amount, qp_nd_tva, qp_nd_tva_recup, qp_supplier,
- qp_valid, qp_dep_priv
- FROM quant_purchase where j_id in (select j_id from jrnx where j_grpt=$1)";
- $this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id));
- }
+ function get()
+ {
+ parent::get();
+ $sql="SELECT qp_id, qp_internal, j_id, qp_fiche, qp_quantite, qp_price, qp_vat,
+ qp_vat_code, qp_nd_amount, qp_nd_tva, qp_nd_tva_recup, qp_supplier,
+ qp_valid, qp_dep_priv
+ FROM quant_purchase where j_id in (select j_id from jrnx where j_grpt=$1)";
+ $this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id));
+ }
}
/////////////////////////////////////////////////////////////////////////////
/**
@@ -584,15 +636,17 @@ class Acc_Purchase extends Acc_Detail
*/
class Acc_Fin extends Acc_Detail
{
- function __construct($p_cn,$p_jrid=0) {
- parent::__construct($p_cn,$p_jrid);
- $this->signature='FIN';
- }
+ function __construct($p_cn,$p_jrid=0)
+ {
+ parent::__construct($p_cn,$p_jrid);
+ $this->signature='FIN';
+ }
- function get() {
- parent::get();
- $sql="SELECT qf_id, qf_bank, jr_id, qf_other, qf_amount
- FROM quant_fin where jr_id = $1";
- $this->det->array=$this->db->get_array($sql,array($this->jr_id));
- }
+ function get()
+ {
+ parent::get();
+ $sql="SELECT qf_id, qf_bank, jr_id, qf_other, qf_amount
+ FROM quant_fin where jr_id = $1";
+ $this->det->array=$this->db->get_array($sql,array($this->jr_id));
+ }
}
diff --git a/include/class_acc_parm_code.php b/include/class_acc_parm_code.php
index ea0b2ead8..e89ce8a43 100644
--- a/include/class_acc_parm_code.php
+++ b/include/class_acc_parm_code.php
@@ -1,4 +1,4 @@
-db=$p_cn;
- $this->p_code=$p_id;
- if ( $p_id != -1 )
- $this->load();
+ $this->db=$p_cn;
+ $this->p_code=$p_id;
+ if ( $p_id != -1 )
+ $this->load();
}
-/*!
- **************************************************
- * \brief
- * Load all parmCode
- * return an array of Acc_Parm_Code object
- *
- * \return array
- */
+ /*!
+ **************************************************
+ * \brief
+ * Load all parmCode
+ * return an array of Acc_Parm_Code object
+ *
+ * \return array
+ */
- function load_all() {
- $sql="select * from parm_code order by p_code";
- $Res=$this->db->exec_sql($sql);
- $r= Database::fetch_all($Res);
- $idx=0;
- $array=array();
-
- if ( $r === false ) return null;
- foreach ($r as $row )
- {
- $o=new Acc_Parm_Code($this->db,$row['p_code']);
- $array[$idx]=$o;
- $idx++;
- }
-
- return $array;
- }
- /*!
- **************************************************
- * \brief update a parm_object into the database
- * p_code is _not_ updatable
- * \return
- * nothing
- */
- function save()
+ function load_all()
{
- // if p_code=="" nothing to save
- if ( $this->p_code== -1) return;
- // check if the account exists
- $acc=new Acc_Account_Ledger($this->db,$this->p_value);
- if ( $acc->load() == false ) {
- alert("Ce compte n'existe pas");
- } else {
- $this->p_comment=FormatString($this->p_comment);
- $this->p_value=FormatString($this->p_value);
- $this->p_code=FormatString($this->p_code);
- $sql="update parm_code set ".
- "p_comment='".$this->p_comment."' ".
- ",p_value='".$this->p_value."' ".
- "where p_code='".$this->p_code."'";
- $Res=$this->db->exec_sql($sql);
- }
+ $sql="select * from parm_code order by p_code";
+ $Res=$this->db->exec_sql($sql);
+ $r= Database::fetch_all($Res);
+ $idx=0;
+ $array=array();
+
+ if ( $r === false ) return null;
+ foreach ($r as $row )
+ {
+ $o=new Acc_Parm_Code($this->db,$row['p_code']);
+ $array[$idx]=$o;
+ $idx++;
+ }
+
+ return $array;
}
-/*!
- **************************************************
- * \brief Display an object, with the tag
- *
- * \return
- * string
- */
- function display()
+ /*!
+ **************************************************
+ * \brief update a parm_object into the database
+ * p_code is _not_ updatable
+ * \return
+ * nothing
+ */
+ function save()
{
- $r="";
- $r.= ' '.$this->p_code.' ';
- $r.= ''.h($this->p_comment).' ';
- $r.= ''.$this->p_value.' ';
-
- return $r;
+ // if p_code=="" nothing to save
+ if ( $this->p_code== -1) return;
+ // check if the account exists
+ $acc=new Acc_Account_Ledger($this->db,$this->p_value);
+ if ( $acc->load() == false )
+ {
+ alert("Ce compte n'existe pas");
+ }
+ else
+ {
+ $this->p_comment=FormatString($this->p_comment);
+ $this->p_value=FormatString($this->p_value);
+ $this->p_code=FormatString($this->p_code);
+ $sql="update parm_code set ".
+ "p_comment='".$this->p_comment."' ".
+ ",p_value='".$this->p_value."' ".
+ "where p_code='".$this->p_code."'";
+ $Res=$this->db->exec_sql($sql);
+ }
}
-/*!
- **************************************************
- * \brief Display a form to enter info about
- * a parm_code object with the tag
- *
- * \return string
- */
- function form()
+ /*!
+ **************************************************
+ * \brief Display an object, with the tag
+ *
+ * \return
+ * string
+ */
+ function display()
{
- $comment=new IText();
- $comment->name='p_comment';
- $comment->value=$this->p_comment;
- $comment->size=45;
- $value=new IPoste();
- $value->name='p_value';
- $value->value=$this->p_value;
- $value->size=7;
- $value->set_attribute('ipopup','ipop_account');
- $value->set_attribute('account','p_value');
- $poste=new IText();
- $poste->setReadOnly(true);
- $poste->size=strlen($this->p_code)+1;
- $poste->name='p_code';
- $poste->value=$this->p_code;
- $r="";
- $r.=' ';
- $r.=' Code ';
- $r.= ''.$poste->input().' ';
- $r.=' ';
- $r.='';
- $r.=' Commentaire ';
- $r.= ''.$comment->input().' ';
- $r.=' ';
- $r.='';
- $r.=' Poste comptable ';
- $r.= ''.$value->input();
- $r.=' ';
- $r.=' ';
- $r.=Dossier::hidden();
- return $r;
-
+ $r="";
+ $r.= ''.$this->p_code.' ';
+ $r.= ''.h($this->p_comment).' ';
+ $r.= ''.$this->p_value.' ';
+
+ return $r;
+ }
+ /*!
+ **************************************************
+ * \brief Display a form to enter info about
+ * a parm_code object with the tag
+ *
+ * \return string
+ */
+ function form()
+ {
+ $comment=new IText();
+ $comment->name='p_comment';
+ $comment->value=$this->p_comment;
+ $comment->size=45;
+ $value=new IPoste();
+ $value->name='p_value';
+ $value->value=$this->p_value;
+ $value->size=7;
+ $value->set_attribute('ipopup','ipop_account');
+ $value->set_attribute('account','p_value');
+ $poste=new IText();
+ $poste->setReadOnly(true);
+ $poste->size=strlen($this->p_code)+1;
+ $poste->name='p_code';
+ $poste->value=$this->p_code;
+ $r="";
+ $r.=' ';
+ $r.=' Code ';
+ $r.= ''.$poste->input().' ';
+ $r.=' ';
+ $r.='';
+ $r.=' Commentaire ';
+ $r.= ''.$comment->input().' ';
+ $r.=' ';
+ $r.='';
+ $r.=' Poste comptable ';
+ $r.= ''.$value->input();
+ $r.=' ';
+ $r.=' ';
+ $r.=Dossier::hidden();
+ return $r;
+
}
-/*!
- **************************************************
- * \brief
- * Complete a parm_code object thanks the p_code
- *
- * \return array
- */
+ /*!
+ **************************************************
+ * \brief
+ * Complete a parm_code object thanks the p_code
+ *
+ * \return array
+ */
- function load() {
- if ( $this->p_code == -1 ) return "p_code non initialisé";
- $sql='select * from parm_code where p_code=$1 ';
+ function load()
+ {
+ if ( $this->p_code == -1 ) return "p_code non initialisé";
+ $sql='select * from parm_code where p_code=$1 ';
- $Res=$this->db->exec_sql($sql,array($this->p_code));
+ $Res=$this->db->exec_sql($sql,array($this->p_code));
- if ( Database::num_row($Res) == 0 ) return 'INCONNU';
- $row= Database::fetch_array($Res,0);
- $this->p_value=$row['p_value'];
- $this->p_comment=$row['p_comment'];
+ if ( Database::num_row($Res) == 0 ) return 'INCONNU';
+ $row= Database::fetch_array($Res,0);
+ $this->p_value=$row['p_value'];
+ $this->p_comment=$row['p_comment'];
- }
+ }
}
diff --git a/include/class_acc_payment.php b/include/class_acc_payment.php
index 8c95c3f58..87a821453 100644
--- a/include/class_acc_payment.php
+++ b/include/class_acc_payment.php
@@ -43,341 +43,390 @@ require_once('constant.php');
class Acc_Payment
{
- private static $variable=array("id"=>"mp_id",
- "lib"=>"mp_lib",
- "qcode"=>"mp_qcode",
- "type"=>"mp_type",
- "ledger"=>"mp_jrn_def_id",
- "fiche_def"=>"mp_fd_id");
+ private static $variable=array("id"=>"mp_id",
+ "lib"=>"mp_lib",
+ "qcode"=>"mp_qcode",
+ "type"=>"mp_type",
+ "ledger"=>"mp_jrn_def_id",
+ "fiche_def"=>"mp_fd_id");
-
- private $mp_lib;
- private $mp_qcode;
- private $mp_type;
- private $mp_jrn_def_if;
-
- private $mp_fd_id;
- function __construct ($p_cn,$p_init=0) {
- $this->cn=$p_cn;
- $this->mp_id=$p_init;
- }
- public function get_parameter($p_string) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- return $this->$idx;
+ private $mp_lib;
+ private $mp_qcode;
+ private $mp_type;
+ private $mp_jrn_def_if;
+
+ private $mp_fd_id;
+
+ function __construct ($p_cn,$p_init=0)
+ {
+ $this->cn=$p_cn;
+ $this->mp_id=$p_init;
}
- else
- exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
- }
- public function set_parameter($p_string,$p_value) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- $this->$idx=$p_value;
+ public function get_parameter($p_string)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ return $this->$idx;
+ }
+ else
+ exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
}
- else
- exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
-
-
- }
- public function get_info() { return var_export(self::$variable,true); }
- public function verify() {
- // Verify that the elt we want to add is correct
- }
- public function save() {
- /* please adapt */
- if ( $this->get_parameter("id") == 0 )
- $this->insert();
- else
- $this->update();
- }
+ public function set_parameter($p_string,$p_value)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ $this->$idx=$p_value;
+ }
+ else
+ exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
- public function insert() {
- if ( $this->verify() != 0 ) return;
- $sql='INSERT INTO mod_payment(
- mp_lib, mp_jrn_def_id, mp_type, mp_fd_id, mp_qcode)
- VALUES ($1, $2, $3, $4, upper($5)) returning mp_id';
- $this->mp_id=$this->cn->exec_sql($sql,array(
- $this->mp_lib,
- $this->mp_jrn_def_id,
- $this->mp_type,
- $this->mp_fd_id,
- $this->mp_qcode));
- }
- public function update() {
- if ( $this->verify() != 0 ) return;
-
- $sql="update mod_payment set mp_lib=$1,mp_qcode=$2,mp_type=$3,mp_jrn_def_id=$4,mp_fd_id=$5 ".
- " where mp_id = $6";
- $res=$this->cn->exec_sql(
- $sql,
- array($this->mp_lib,
- $this->mp_qcode,
- $this->mp_type,
- $this->mp_jrn_def_id,
- $this->mp_fd_id,
- $this->mp_id)
- );
- if ( strlen (trim($this->mp_jrn_def_id))==0)
- $this->cn->exec_sql(
- 'update mod_payment '.
- 'set mp_jrn_def_id = null where mp_id=$1',
- array($this->mp_id));
- if ( strlen (trim($this->mp_qcode))==0)
- $this->cn->exec_sql(
- 'update mod_payment '.
- 'set mp_qcode = null where mp_id=$1',
- array($this->mp_id));
- if ( strlen (trim($this->mp_fd_id))==0)
- $this->cn->exec_sql(
- 'update mod_payment '.
- 'set mp_fd_id = null where mp_id=$1',
- array($this->mp_id));
-
- }
-
- public function load() {
- $sql='select mp_id,mp_lib,mp_fd_id,mp_jrn_def_id,mp_qcode,mp_type from mod_payment '.
- ' where mp_id = $1';
- $res=$this->cn->exec_sql(
- $sql,
- array($this->mp_id)
- );
-
- if ( Database::num_row($res) == 0 ) return;
- $row=Database::fetch_array($res,0);
- foreach ($row as $idx=>$value) { $this->$idx=$value; }
- }
- /**
- *@brief remove a middle of payment
- */
- public function delete() {
- $sql="delete from mod_payment where mp_id=$1";
- $this->cn->exec_sql($sql,array($this->mp_id));
- }
- /*!\brief retrieve all the data for a certain type
- *\param non
- *\return an array of row
- */
- public function get_all() {
- $sql='select mp_id '.
- ' from mod_payment '.
- ' where mp_type=$1';
- $array=$this->cn->get_array($sql,array($this->mp_type));
- $ret=array();
- if ( !empty($array) ) {
- foreach ($array as $row) {
- $t=new Acc_Payment($this->cn,$row['mp_id']);
- $t->load();
- $ret[]=$t;
- }
}
- return $ret;
- }
- /*!\brief retrieve all the data for a certain type but filter on the
- *valid record (jrn and fd not null
- *\param non
- *\return an array of row
- */
- public function get_valide() {
- $sql='select mp_id '.
- ' from mod_payment '.
- ' where mp_type=$1 and mp_jrn_def_id is not null and '.
- ' (mp_fd_id is not null or mp_qcode is not null)';
- $array=$this->cn->get_array($sql,array($this->mp_type));
- $ret=array();
- if ( !empty($array) ) {
- foreach ($array as $row) {
- $t=new Acc_Payment($this->cn,$row['mp_id']);
- $t->load();
- $ret[]=$t;
- }
+ public function get_info()
+ {
+ return var_export(self::$variable,true);
}
- return $ret;
- }
-
- public function row() {
- //---------------------------------------------------------------------------
- // Common variable
- $td='';$etd=' ';$tr='';$etr=' ';$th='';$eth=' ';
-
- $r='';
- $r.=$td.$this->mp_lib.$etd;
- if ( $this->mp_fd_id != NULL && $this->mp_fd_id !=0) {
- $fiche=new Fiche_Def($this->cn,$this->mp_fd_id);
- $fiche->Get();
- $r.=$td.$fiche->label.$etd;
- }else
- $r.=$td.$etd;
- $jrn=new Acc_Ledger($this->cn,$this->mp_jrn_def_id);
- $r.=$td.$jrn->get_name().$etd;
- if ( strlen(trim($this->mp_qcode)) != 0 ) {
- $f=new Fiche($this->cn);
- $f->get_by_qcode($this->mp_qcode);
- $r.=$td.$f->strAttribut(ATTR_DEF_NAME).$etd;
-
- }else
- $r.=$td.$etd;
- return $r;
- }
- /*!\brief return a string with a form (into a table)
- *\param none
- *\return a html string
- */
- public function form() {
- $td='';$etd=' ';$tr='';$etr=' ';$th='';$eth=' ';
- $r='';
- $r.=HtmlInput::hidden('id',$this->mp_id);
- $r.='';
- $r.=$tr.$td.'Libellé'.$etd;
- $r.=$td;
- $r.=$this->mp_lib;
- $r.=$etd.$etr;
- $r.=$tr.$td;
- $r.='Type de fiche '.$etd;
- $array=$this->cn->make_array('select fd_id,fd_label from fiche_def join fiche_def_ref '.
- ' using (frd_id) where frd_id in (25,4) order by fd_label');
- $fd=new ISelect();
- $fd->name='mp_fd_id';
- $fd->value=$array;
- $fd->selected=$this->mp_fd_id;
- $r.=$td.$fd->input();
- $r.=$etd;
- $r.=$tr.$td.'Enregistre dans le journal '.$etd;
- $array=$this->cn->make_array('select jrn_def_id,jrn_def_name from '.
- ' jrn_def where jrn_def_type = \'ODS\' or jrn_def_type=\'FIN\'');
- $jrn=new ISelect();
- $jrn->value=$array;
- $jrn->name='mp_jrn_def_id';
- $jrn->selected=(isset ($this->mp_jrn_def_id))?$this->mp_jrn_def_id:0;
- $r.=$td.$jrn->input().$etd;
- $r.=$etr.$tr;
- $r.=$td.'Avec la fiche'.$etd;
- $f=new ICard();
- $f->jrn=$jrn->selected;
- $f->noadd=true;
- $f->name='mp_qcode';
- $list=$this->cn->make_list('select fd_id from fiche_def where frd_id in (25,4)');
- $f->extra=$list;
- $f->extra2=_('Recherche');
- $f->value=(isset($this->mp_qcode))?$this->mp_qcode:'';
- $r.=$td.$f->input().$etd;
- $s=new ISpan();
- $r.=$td.$s->input('mp_qcode_label');
- $r.='
';
- return $r;
-
- }
- /*!\brief show several lines with radio button to select the payment
- *method we want to use, the $_POST['e_mp'] will be set
- *\param none
- *\return html string
- */
- public function select() {
- $r='';
- $array=$this->get_valide();
- $r.=HtmlInput::hidden('gDossier',dossier::id());
- $r.='';
- $r.=' '._('Paiement encodé plus tard');
- if ( empty($array ) == false ){
- foreach ($array as $row) {
- $f='';
- /* if the qcode is null the propose a search button to select
- the card */
- if ( $row->mp_qcode==NULL) {
- $a=new ICard();
- $a->jrn=$row->mp_jrn_def_id;
- $a->extra=$row->mp_fd_id;
- $a->name='e_mp_qcode_'.$row->mp_id;
- $a->set_dblclick("fill_ipopcard(this);");
- $a->set_callback('filter_card');
- $a->set_function('fill_data');
- $a->set_attribute('ipopup','ipopcard');
- $a->set_attribute('label',$a->name.'_label');
-
- $s=new ISpan();
- $s->name=$a->name.'_label';
- $f=_(" paiement par ").$a->input().$s->input();
- }else {
- /* if the qcode is not null then add a hidden variable with
- the qcode */
-
- $fiche=new Fiche($this->cn);
- $fiche->get_by_qcode($row->mp_qcode);
- $f=HtmlInput::hidden('e_mp_qcode_'.$row->mp_id,$row->mp_qcode);
-
- // $f.=$fiche->strAttribut(ATTR_DEF_NAME);
- }
- $r.=' ';
- $r.=$row->mp_lib.' '.$f;
-
- }
+ public function verify()
+ {
+ // Verify that the elt we want to add is correct
+ }
+ public function save()
+ {
+ /* please adapt */
+ if ( $this->get_parameter("id") == 0 )
+ $this->insert();
+ else
+ $this->update();
}
- $r.=' ';
- return $r;
- }
- /*!\brief convert an array into an Acc_Payment object
- *\param array to convert
- */
- public function from_array($p_array) {
- $idx=array('mp_id','mp_lib','mp_fd_id','mp_jrn_def_id','mp_qcode','mp_type');
- foreach ($idx as $l)
- if (isset($p_array[$l])) $this->$l=$p_array[$l];
- }
- /**
- *@brief return an html with a form to add a new middle of payment
- */
- public function blank() {
- //label
- $lib=new IText('mp_lib');
- $f_lib=$lib->input();
- // Type of ledger
- $tledger=new ISelect('mp_type');
- $tledger->value=array(array ('value'=>'ACH','label'=>_('Achat')),
- array ('value'=>'VEN','label'=>_('Vente')));
- $f_type=$tledger->input();
-
- // type of card
- $tcard=new ISelect('mp_fd_id');
- $tcard->value=$this->cn->make_array('select fd_id,fd_label from fiche_def join fiche_def_ref '.
- ' using (frd_id) where frd_id in (25,4) order by fd_label');
- $f_type_fiche=$tcard->input();
- $ledger_record=new ISelect('mp_jrn_def_id');
- $ledger_record->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
- jrn_def where jrn_def_type in ('ODS','FIN')");
- $f_ledger_record=$ledger_record->input();
+ public function insert()
+ {
+ if ( $this->verify() != 0 ) return;
+ $sql='INSERT INTO mod_payment(
+ mp_lib, mp_jrn_def_id, mp_type, mp_fd_id, mp_qcode)
+ VALUES ($1, $2, $3, $4, upper($5)) returning mp_id';
+ $this->mp_id=$this->cn->exec_sql($sql,array(
+ $this->mp_lib,
+ $this->mp_jrn_def_id,
+ $this->mp_type,
+ $this->mp_fd_id,
+ $this->mp_qcode));
+ }
+
+ public function update()
+ {
+ if ( $this->verify() != 0 ) return;
+
+ $sql="update mod_payment set mp_lib=$1,mp_qcode=$2,mp_type=$3,mp_jrn_def_id=$4,mp_fd_id=$5 ".
+ " where mp_id = $6";
+ $res=$this->cn->exec_sql(
+ $sql,
+ array($this->mp_lib,
+ $this->mp_qcode,
+ $this->mp_type,
+ $this->mp_jrn_def_id,
+ $this->mp_fd_id,
+ $this->mp_id)
+ );
+ if ( strlen (trim($this->mp_jrn_def_id))==0)
+ $this->cn->exec_sql(
+ 'update mod_payment '.
+ 'set mp_jrn_def_id = null where mp_id=$1',
+ array($this->mp_id));
+ if ( strlen (trim($this->mp_qcode))==0)
+ $this->cn->exec_sql(
+ 'update mod_payment '.
+ 'set mp_qcode = null where mp_id=$1',
+ array($this->mp_id));
+ if ( strlen (trim($this->mp_fd_id))==0)
+ $this->cn->exec_sql(
+ 'update mod_payment '.
+ 'set mp_fd_id = null where mp_id=$1',
+ array($this->mp_id));
+
+ }
+
+ public function load()
+ {
+ $sql='select mp_id,mp_lib,mp_fd_id,mp_jrn_def_id,mp_qcode,mp_type from mod_payment '.
+ ' where mp_id = $1';
+ $res=$this->cn->exec_sql(
+ $sql,
+ array($this->mp_id)
+ );
+
+ if ( Database::num_row($res) == 0 ) return;
+ $row=Database::fetch_array($res,0);
+ foreach ($row as $idx=>$value)
+ {
+ $this->$idx=$value;
+ }
+
+ }
+ /**
+ *@brief remove a middle of payment
+ */
+ public function delete()
+ {
+ $sql="delete from mod_payment where mp_id=$1";
+ $this->cn->exec_sql($sql,array($this->mp_id));
+ }
+ /*!\brief retrieve all the data for a certain type
+ *\param non
+ *\return an array of row
+ */
+ public function get_all()
+ {
+ $sql='select mp_id '.
+ ' from mod_payment '.
+ ' where mp_type=$1';
+ $array=$this->cn->get_array($sql,array($this->mp_type));
+ $ret=array();
+ if ( !empty($array) )
+ {
+ foreach ($array as $row)
+ {
+ $t=new Acc_Payment($this->cn,$row['mp_id']);
+ $t->load();
+ $ret[]=$t;
+ }
+ }
+ return $ret;
+ }
+ /*!\brief retrieve all the data for a certain type but filter on the
+ *valid record (jrn and fd not null
+ *\param non
+ *\return an array of row
+ */
+ public function get_valide()
+ {
+ $sql='select mp_id '.
+ ' from mod_payment '.
+ ' where mp_type=$1 and mp_jrn_def_id is not null and '.
+ ' (mp_fd_id is not null or mp_qcode is not null)';
+ $array=$this->cn->get_array($sql,array($this->mp_type));
+ $ret=array();
+ if ( !empty($array) )
+ {
+ foreach ($array as $row)
+ {
+ $t=new Acc_Payment($this->cn,$row['mp_id']);
+ $t->load();
+ $ret[]=$t;
+ }
+ }
+ return $ret;
+ }
+
+ public function row()
+ {
+ //---------------------------------------------------------------------------
+ // Common variable
+ $td='';
+ $etd=' ';
+ $tr='';
+ $etr=' ';
+ $th='';
+ $eth=' ';
+
+ $r='';
+ $r.=$td.$this->mp_lib.$etd;
+ if ( $this->mp_fd_id != NULL && $this->mp_fd_id !=0)
+ {
+ $fiche=new Fiche_Def($this->cn,$this->mp_fd_id);
+ $fiche->Get();
+ $r.=$td.$fiche->label.$etd;
+ }
+ else
+ $r.=$td.$etd;
+ $jrn=new Acc_Ledger($this->cn,$this->mp_jrn_def_id);
+ $r.=$td.$jrn->get_name().$etd;
+ if ( strlen(trim($this->mp_qcode)) != 0 )
+ {
+ $f=new Fiche($this->cn);
+ $f->get_by_qcode($this->mp_qcode);
+ $r.=$td.$f->strAttribut(ATTR_DEF_NAME).$etd;
+
+ }
+ else
+ $r.=$td.$etd;
+ return $r;
+ }
+ /*!\brief return a string with a form (into a table)
+ *\param none
+ *\return a html string
+ */
+ public function form()
+ {
+ $td='';
+ $etd=' ';
+ $tr='';
+ $etr=' ';
+ $th='';
+ $eth=' ';
+ $r='';
+ $r.=HtmlInput::hidden('id',$this->mp_id);
+ $r.='';
+ $r.=$tr.$td.'Libellé'.$etd;
+ $r.=$td;
+ $r.=$this->mp_lib;
+ $r.=$etd.$etr;
+ $r.=$tr.$td;
+ $r.='Type de fiche '.$etd;
+ $array=$this->cn->make_array('select fd_id,fd_label from fiche_def join fiche_def_ref '.
+ ' using (frd_id) where frd_id in (25,4) order by fd_label');
+ $fd=new ISelect();
+ $fd->name='mp_fd_id';
+ $fd->value=$array;
+ $fd->selected=$this->mp_fd_id;
+ $r.=$td.$fd->input();
+ $r.=$etd;
+ $r.=$tr.$td.'Enregistre dans le journal '.$etd;
+ $array=$this->cn->make_array('select jrn_def_id,jrn_def_name from '.
+ ' jrn_def where jrn_def_type = \'ODS\' or jrn_def_type=\'FIN\'');
+ $jrn=new ISelect();
+ $jrn->value=$array;
+ $jrn->name='mp_jrn_def_id';
+ $jrn->selected=(isset ($this->mp_jrn_def_id))?$this->mp_jrn_def_id:0;
+ $r.=$td.$jrn->input().$etd;
+ $r.=$etr.$tr;
+ $r.=$td.'Avec la fiche'.$etd;
+ $f=new ICard();
+ $f->jrn=$jrn->selected;
+ $f->noadd=true;
+ $f->name='mp_qcode';
+ $list=$this->cn->make_list('select fd_id from fiche_def where frd_id in (25,4)');
+ $f->extra=$list;
+ $f->extra2=_('Recherche');
+ $f->value=(isset($this->mp_qcode))?$this->mp_qcode:'';
+ $r.=$td.$f->input().$etd;
+ $s=new ISpan();
+ $r.=$td.$s->input('mp_qcode_label');
+ $r.='
';
+ return $r;
+
+ }
+ /*!\brief show several lines with radio button to select the payment
+ *method we want to use, the $_POST['e_mp'] will be set
+ *\param none
+ *\return html string
+ */
+ public function select()
+ {
+ $r='';
+ $array=$this->get_valide();
+ $r.=HtmlInput::hidden('gDossier',dossier::id());
+ $r.='';
+ $r.=' '._('Paiement encodé plus tard');
+ if ( empty($array ) == false )
+ {
+ foreach ($array as $row)
+ {
+ $f='';
+ /* if the qcode is null the propose a search button to select
+ the card */
+ if ( $row->mp_qcode==NULL)
+ {
+ $a=new ICard();
+ $a->jrn=$row->mp_jrn_def_id;
+ $a->extra=$row->mp_fd_id;
+ $a->name='e_mp_qcode_'.$row->mp_id;
+ $a->set_dblclick("fill_ipopcard(this);");
+ $a->set_callback('filter_card');
+ $a->set_function('fill_data');
+ $a->set_attribute('ipopup','ipopcard');
+ $a->set_attribute('label',$a->name.'_label');
+
+ $s=new ISpan();
+ $s->name=$a->name.'_label';
+ $f=_(" paiement par ").$a->input().$s->input();
+ }
+ else
+ {
+ /* if the qcode is not null then add a hidden variable with
+ the qcode */
+
+ $fiche=new Fiche($this->cn);
+ $fiche->get_by_qcode($row->mp_qcode);
+ $f=HtmlInput::hidden('e_mp_qcode_'.$row->mp_id,$row->mp_qcode);
+
+ // $f.=$fiche->strAttribut(ATTR_DEF_NAME);
+ }
+ $r.=' ';
+ $r.=$row->mp_lib.' '.$f;
+
+ }
+ }
+ $r.=' ';
+ return $r;
+ }
+
+ /*!\brief convert an array into an Acc_Payment object
+ *\param array to convert
+ */
+ public function from_array($p_array)
+ {
+ $idx=array('mp_id','mp_lib','mp_fd_id','mp_jrn_def_id','mp_qcode','mp_type');
+ foreach ($idx as $l)
+ if (isset($p_array[$l])) $this->$l=$p_array[$l];
+ }
+ /**
+ *@brief return an html with a form to add a new middle of payment
+ */
+ public function blank()
+ {
+ //label
+ $lib=new IText('mp_lib');
+ $f_lib=$lib->input();
+ // Type of ledger
+ $tledger=new ISelect('mp_type');
+ $tledger->value=array(array ('value'=>'ACH','label'=>_('Achat')),
+ array ('value'=>'VEN','label'=>_('Vente')));
+ $f_type=$tledger->input();
+
+ // type of card
+ $tcard=new ISelect('mp_fd_id');
+ $tcard->value=$this->cn->make_array('select fd_id,fd_label from fiche_def join fiche_def_ref '.
+ ' using (frd_id) where frd_id in (25,4) order by fd_label');
+ $f_type_fiche=$tcard->input();
+ $ledger_record=new ISelect('mp_jrn_def_id');
+ $ledger_record->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
+ jrn_def where jrn_def_type in ('ODS','FIN')");
+ $f_ledger_record=$ledger_record->input();
+
+ // the card
+ $qcode=new ICard();
+ $qcode->noadd=true;
+ $qcode->name='mp_qcode';
+ $list=$this->cn->make_list('select fd_id from fiche_def where frd_id in (25,4)');
+ $qcode->extra=$list;
+ $f_qcode=$qcode->input();
+ ob_start();
+ require_once('template/new_mod_payment.php');
+ $r=ob_get_contents();
+ ob_end_clean();
+ return $r;
+ }
+ /*!\brief test function
+ */
+ static function test_me()
+ {
+ echo JS_LEDGER;
+ $cn=new Database(dossier::id());
+ $ac=new Acc_Payment($cn);
+ $ac->set_parameter('type','ACH');
+ echo '';
+ echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
+ echo $ac->select();
+ echo HtmlInput::submit('go','go');
+ echo ' ';
+ if ( isset($_POST['go']))
+ print_r($_POST);
+ }
- // the card
- $qcode=new ICard();
- $qcode->noadd=true;
- $qcode->name='mp_qcode';
- $list=$this->cn->make_list('select fd_id from fiche_def where frd_id in (25,4)');
- $qcode->extra=$list;
- $f_qcode=$qcode->input();
- ob_start();
- require_once('template/new_mod_payment.php');
- $r=ob_get_contents();
- ob_end_clean();
- return $r;
- }
- /*!\brief test function
- */
- static function test_me() {
- echo JS_LEDGER;
- $cn=new Database(dossier::id());
- $ac=new Acc_Payment($cn);
- $ac->set_parameter('type','ACH');
- echo '';
- echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
- echo $ac->select();
- echo HtmlInput::submit('go','go');
- echo ' ';
- if ( isset($_POST['go']))
- print_r($_POST);
- }
-
}
diff --git a/include/class_acc_reconciliation.php b/include/class_acc_reconciliation.php
index 225c11f7c..5d60f76b3 100644
--- a/include/class_acc_reconciliation.php
+++ b/include/class_acc_reconciliation.php
@@ -20,7 +20,7 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*!\file
+/*!\file
* \brief class acc_reconciliation, this class is new and the code
* must use it
*
@@ -33,274 +33,299 @@ require_once ('class_dossier.php');
* instead of the function InsertRapt, ...
*
*/
-class Acc_Reconciliation {
- var $db; /*!< database connection */
- var $jr_id; /*!< jr_id */
- public static $javascript=JS_LEDGER;
- function __construct($cn) {
- $this->db=$cn;
- $this->jr_id=0;
- }
-
- function set_jr_id($jr_id) {
- $this->jr_id=$jr_id;
- }
- /*! \brief return a widget of type js_concerned
- */
- function widget() {
- $wConcerned=new IConcerned();
- $wConcerned->extra=0; // with 0 javascript search from e_amount... field (see javascript)
-
- return $wConcerned;
-
- }
- /*!
- *\brief Insert into jrn_rapt the concerned operations
- *
- * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned or a string
- * like "jr_id2,jr_id3,jr_id4..."
- *
- * \return none
- *
- */
- function insert($jr_id2) {
- if ( trim($jr_id2) == "" )
- return;
- if ( strpos($jr_id2,',') !== 0 )
- {
- $aRapt=explode(',',$jr_id2);
- foreach ($aRapt as $rRapt) {
- if ( isNumber($rRapt) == 1 )
- {
- $this->insert_rapt($rRapt);
- }
- }
- } else
- if ( isNumber($jr_id2) == 1 )
- {
- $this->insert_rapt($jr_id2);
- }
- }
-
- /*!
- *\brief Insert into jrn_rapt the concerned operations
- * should not be called directly, use insert instead
- *
- * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned
- *
- * \return none
- *
- */
- function insert_rapt($jr_id2) {
- if ( isNumber($this->jr_id) == 0 || isNumber($jr_id2) == 0 )
- {
- return false;
- }
- if ( $this->jr_id==$jr_id2)
- return true;
-
- // verify if exists
- if ( $this->db->count_sql(
- "select jra_id from jrn_rapt where jra_concerned=".$this->jr_id.
- " and jr_id=$jr_id2
- union
- select jra_id from jrn_rapt where jra_id=".$this->jr_id.
- " and jra_concerned=$jr_id2 ")
- ==0)
- {
- // Ok we can insert
- $Res=$this->db->exec_sql("insert into jrn_rapt(jr_id,jra_concerned) values ".
- "(".$this->jr_id.",$jr_id2)");
- }
- return true;
- }
- /*!
- *\brief Insert into jrn_rapt the concerned operations
- *
- * \param $this->jr_id (jrn.jr_id) => jrn_rapt.jr_id
- * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned
- *
- * \return none
- */
- function remove($jr_id2) {
- if ( isNumber($this->jr_id) == 0 or
- isNumber($jr_id2) == 0 )
- {
- return;
- }
- // verify if exists
- if ( $this->db->count_sql("select jra_id from jrn_rapt where ".
- " jra_concerned=".$this->jr_id." and jr_id=$jr_id2
- union
- select jra_id from jrn_rapt where jra_concerned=$jr_id2 ".
- " and jr_id=".$this->jr_id) !=0)
- {
- // Ok we can delete
- $Res=$this->db->exec_sql("delete from jrn_rapt where ".
- "(jra_concerned=$jr_id2 and jr_id=".$this->jr_id.") or
- (jra_concerned=".$this->jr_id." and jr_id=$jr_id2) ");
- }
- }
-
- /*!
- *\brief Return an array of the concerned operation
- *
- *
- *\param database connection
- * \return array if something is found or null
- */
- function get ( ) {
- $sql=" select jr_id as cn from jrn_rapt where jra_concerned=".$this->jr_id.
- " union ".
- " select jra_concerned as cn from jrn_rapt where jr_id=".$this->jr_id;
- $Res=$this->db->exec_sql($sql);
-
- // If nothing is found return null
- $n=Database::num_row($Res);
-
- if ($n ==0 ) return null;
-
- // put everything in an array
- for ($i=0;$i<$n;$i++) {
- $l=Database::fetch_array($Res,$i);
- $r[$i]=$l['cn'];
- }
- return $r;
- }
- function fill_info() {
- $sql="select jr_id,jr_date,jr_comment,jr_internal,jr_montant,jr_pj_number,jr_def_id,jrn_def_name,jrn_def_type
- from jrn join jrn_def on (jrn_def_id=jr_def_id)
- where jr_id=$1";
- $a=$this->db->get_array($sql,array($this->jr_id));
- return $a[0];
- }
- /**
- *@brief return array of not-reconciled operation
- *@param
- *@return
- *@note
- *@see
- @code
-
- @endcode
- */
- function get_not_reconciled() {
- /* create ledger filter */
- $sql_jrn=$this->ledger_filter();
-
- $array=$this->db->get_array("select distinct jr_id,jr_date from jrn where $sql_jrn and jr_id not in (select jr_id from jrn_rapt union select jra_concerned from jrn_rapt) order by jr_date");
- $ret=array();
- for ($i=0;$ijr_id=$array[$i]['jr_id'];
- $ret[$i]['first']=$this->fill_info();
+class Acc_Reconciliation
+{
+ var $db; /*!< database connection */
+ var $jr_id; /*!< jr_id */
+ public static $javascript=JS_LEDGER;
+ function __construct($cn)
+ {
+ $this->db=$cn;
+ $this->jr_id=0;
}
- return $ret;
- }
- /**
- *Create a sql condition to filter by security and by asked ledger
- * based on $this->a_jrn
- *@return a valid sql stmt to include
- *@see get_not_reconciled get_reconciled
- */
- function ledger_filter () {
- /* get the available ledgers for current user */
- $user=new User($this->db);
- $sql=$user->get_ledger_sql('ALL',3);
- $sql=str_replace('jrn_def_id','jr_def_id',$sql);
- $r='';
- /* filter by this->r_jrn */
- if ($this->a_jrn != null ) {
- $sep='';
- $r='and jr_def_id in (';
- foreach( $this->a_jrn as $key=>$value) {
- $r.=$sep.$value;$sep=',';
- }
- $r.=')';
+ function set_jr_id($jr_id)
+ {
+ $this->jr_id=$jr_id;
}
- return $sql.' '.$r;
- }
- /**
- *@brief return array of reconciled operation
- *@return
- *@note
- *@see
- @code
+ /*! \brief return a widget of type js_concerned
+ */
+ function widget()
+ {
+ $wConcerned=new IConcerned();
+ $wConcerned->extra=0; // with 0 javascript search from e_amount... field (see javascript)
- @endcode
- */
- function get_reconciled()
- {
- /* create ledger filter */
- $sql_jrn=$this->ledger_filter();
+ return $wConcerned;
- $array=$this->db->get_array("select distinct jr_id,jr_date from jrn where $sql_jrn and jr_id in (select jr_id from jrn_rapt union select jra_concerned from jrn_rapt) order by jr_date");
- $ret=array();
- for ($i=0;$ijr_id=$array[$i]['jr_id'];
- $ret[$i]['first']=$this->fill_info();
- $atmp=$this->get();
- for ( $e=0;$ejr_id=$atmp[$e];
- $ret[$i]['depend'][$e]=$this->fill_info();
- }
}
- return $ret;
- }
- /**
- *@brief
- *@param
- *@return
- *@note
- *@see
-@code
+ /*!
+ *\brief Insert into jrn_rapt the concerned operations
+ *
+ * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned or a string
+ * like "jr_id2,jr_id3,jr_id4..."
+ *
+ * \return none
+ *
+ */
+ function insert($jr_id2)
+ {
+ if ( trim($jr_id2) == "" )
+ return;
+ if ( strpos($jr_id2,',') !== 0 )
+ {
+ $aRapt=explode(',',$jr_id2);
+ foreach ($aRapt as $rRapt)
+ {
+ if ( isNumber($rRapt) == 1 )
+ {
+ $this->insert_rapt($rRapt);
+ }
+ }
+ }
+ else
+ if ( isNumber($jr_id2) == 1 )
+ {
+ $this->insert_rapt($jr_id2);
+ }
+ }
-@endcode
- */
- function get_reconciled_amount($p_equal=false)
- {
- $array=$this->get_reconciled();
- $ret=array();
- for ($i=0;$iset_jr_id(38);
- $a=$rap->get();
- print_r($a);
- $rap->remove(4);
- $rap->insert("4,5,6");
- $a=$rap->get();
- print_r($a);
- echo Acc_Reconciliation::$javascript;
- $w=$rap->widget();
- $w->name="jr_concerned";
+ /*!
+ *\brief Insert into jrn_rapt the concerned operations
+ * should not be called directly, use insert instead
+ *
+ * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned
+ *
+ * \return none
+ *
+ */
+ function insert_rapt($jr_id2)
+ {
+ if ( isNumber($this->jr_id) == 0 || isNumber($jr_id2) == 0 )
+ {
+ return false;
+ }
+ if ( $this->jr_id==$jr_id2)
+ return true;
- $w->extra2="";
- echo $w->input();
+ // verify if exists
+ if ( $this->db->count_sql(
+ "select jra_id from jrn_rapt where jra_concerned=".$this->jr_id.
+ " and jr_id=$jr_id2
+ union
+ select jra_id from jrn_rapt where jra_id=".$this->jr_id.
+ " and jra_concerned=$jr_id2 ")
+ ==0)
+ {
+ // Ok we can insert
+ $Res=$this->db->exec_sql("insert into jrn_rapt(jr_id,jra_concerned) values ".
+ "(".$this->jr_id.",$jr_id2)");
+ }
+ return true;
+ }
+ /*!
+ *\brief Insert into jrn_rapt the concerned operations
+ *
+ * \param $this->jr_id (jrn.jr_id) => jrn_rapt.jr_id
+ * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned
+ *
+ * \return none
+ */
+ function remove($jr_id2)
+ {
+ if ( isNumber($this->jr_id) == 0 or
+ isNumber($jr_id2) == 0 )
+ {
+ return;
+ }
+ // verify if exists
+ if ( $this->db->count_sql("select jra_id from jrn_rapt where ".
+ " jra_concerned=".$this->jr_id." and jr_id=$jr_id2
+ union
+ select jra_id from jrn_rapt where jra_concerned=$jr_id2 ".
+ " and jr_id=".$this->jr_id) !=0)
+ {
+ // Ok we can delete
+ $Res=$this->db->exec_sql("delete from jrn_rapt where ".
+ "(jra_concerned=$jr_id2 and jr_id=".$this->jr_id.") or
+ (jra_concerned=".$this->jr_id." and jr_id=$jr_id2) ");
+ }
+ }
+
+ /*!
+ *\brief Return an array of the concerned operation
+ *
+ *
+ *\param database connection
+ * \return array if something is found or null
+ */
+ function get ( )
+ {
+ $sql=" select jr_id as cn from jrn_rapt where jra_concerned=".$this->jr_id.
+ " union ".
+ " select jra_concerned as cn from jrn_rapt where jr_id=".$this->jr_id;
+ $Res=$this->db->exec_sql($sql);
+
+ // If nothing is found return null
+ $n=Database::num_row($Res);
+
+ if ($n ==0 ) return null;
+
+ // put everything in an array
+ for ($i=0;$i<$n;$i++)
+ {
+ $l=Database::fetch_array($Res,$i);
+ $r[$i]=$l['cn'];
+ }
+ return $r;
+ }
+ function fill_info()
+ {
+ $sql="select jr_id,jr_date,jr_comment,jr_internal,jr_montant,jr_pj_number,jr_def_id,jrn_def_name,jrn_def_type
+ from jrn join jrn_def on (jrn_def_id=jr_def_id)
+ where jr_id=$1";
+ $a=$this->db->get_array($sql,array($this->jr_id));
+ return $a[0];
+ }
+ /**
+ *@brief return array of not-reconciled operation
+ *@param
+ *@return
+ *@note
+ *@see
+ @code
+
+ @endcode
*/
- //var_dump($rap->get_reconciled(''));
- var_dump($rap->get_reconciled_amount('',false));
- }
+ function get_not_reconciled()
+ {
+ /* create ledger filter */
+ $sql_jrn=$this->ledger_filter();
+
+ $array=$this->db->get_array("select distinct jr_id,jr_date from jrn where $sql_jrn and jr_id not in (select jr_id from jrn_rapt union select jra_concerned from jrn_rapt) order by jr_date");
+ $ret=array();
+ for ($i=0;$ijr_id=$array[$i]['jr_id'];
+ $ret[$i]['first']=$this->fill_info();
+ }
+
+ return $ret;
+ }
+ /**
+ *Create a sql condition to filter by security and by asked ledger
+ * based on $this->a_jrn
+ *@return a valid sql stmt to include
+ *@see get_not_reconciled get_reconciled
+ */
+ function ledger_filter ()
+ {
+ /* get the available ledgers for current user */
+ $user=new User($this->db);
+ $sql=$user->get_ledger_sql('ALL',3);
+ $sql=str_replace('jrn_def_id','jr_def_id',$sql);
+ $r='';
+ /* filter by this->r_jrn */
+ if ($this->a_jrn != null )
+ {
+ $sep='';
+ $r='and jr_def_id in (';
+ foreach( $this->a_jrn as $key=>$value)
+ {
+ $r.=$sep.$value;
+ $sep=',';
+ }
+ $r.=')';
+ }
+ return $sql.' '.$r;
+ }
+ /**
+ *@brief return array of reconciled operation
+ *@return
+ *@note
+ *@see
+ @code
+
+ @endcode
+ */
+ function get_reconciled()
+ {
+ /* create ledger filter */
+ $sql_jrn=$this->ledger_filter();
+
+ $array=$this->db->get_array("select distinct jr_id,jr_date from jrn where $sql_jrn and jr_id in (select jr_id from jrn_rapt union select jra_concerned from jrn_rapt) order by jr_date");
+ $ret=array();
+ for ($i=0;$ijr_id=$array[$i]['jr_id'];
+ $ret[$i]['first']=$this->fill_info();
+ $atmp=$this->get();
+ for ( $e=0;$ejr_id=$atmp[$e];
+ $ret[$i]['depend'][$e]=$this->fill_info();
+ }
+ }
+ return $ret;
+ }
+ /**
+ *@brief
+ *@param
+ *@return
+ *@note
+ *@see
+ @code
+
+ @endcode
+ */
+ function get_reconciled_amount($p_equal=false)
+ {
+ $array=$this->get_reconciled();
+ $ret=array();
+ for ($i=0;$iset_jr_id(38);
+ $a=$rap->get();
+ print_r($a);
+ $rap->remove(4);
+ $rap->insert("4,5,6");
+ $a=$rap->get();
+ print_r($a);
+ echo Acc_Reconciliation::$javascript;
+ $w=$rap->widget();
+ $w->name="jr_concerned";
+
+ $w->extra2="";
+ echo $w->input();
+ */
+ //var_dump($rap->get_reconciled(''));
+ var_dump($rap->get_reconciled_amount('',false));
+ }
}
diff --git a/include/class_acc_report.php b/include/class_acc_report.php
index d0c4c3609..33698d507 100644
--- a/include/class_acc_report.php
+++ b/include/class_acc_report.php
@@ -1,4 +1,4 @@
-db=$p_cn;
- $this->id=$p_id;
- $this->name='Nouveau';
- $this->aAcc_Report_row=null;
- }
- /*!\brief Return the report's name
- */
- function get_name() {
- $ret=$this->db->exec_sql("select fr_label from formdef where fr_id=".$this->id);
- if (Database::num_row($ret) == 0) return $this->name;
- $a=Database::fetch_array($ret,0);
- $this->name=$a['fr_label'];
- return $this->name;
- }
- /*!\brief return all the row and parse formula
- * from a report
- * \param $p_start start periode
- * \param $p_end end periode
- * \param $p_type_date type of the date : periode or calendar
- */
- function get_row($p_start,$p_end,$p_type_date) {
+ var $db; /*!< $db database connx */
+ var $id; /*!< $id formdef.fr_id */
+ var $name; /*!< $name report's name */
+ var $aAcc_Report_row; /*!< array of rapport_row */
+ var $nb;
+ /*!\brief Constructor */
+ function __construct($p_cn,$p_id=0)
+ {
+ $this->db=$p_cn;
+ $this->id=$p_id;
+ $this->name='Nouveau';
+ $this->aAcc_Report_row=null;
+ }
+ /*!\brief Return the report's name
+ */
+ function get_name()
+ {
+ $ret=$this->db->exec_sql("select fr_label from formdef where fr_id=".$this->id);
+ if (Database::num_row($ret) == 0) return $this->name;
+ $a=Database::fetch_array($ret,0);
+ $this->name=$a['fr_label'];
+ return $this->name;
+ }
+ /*!\brief return all the row and parse formula
+ * from a report
+ * \param $p_start start periode
+ * \param $p_end end periode
+ * \param $p_type_date type of the date : periode or calendar
+ */
+ function get_row($p_start,$p_end,$p_type_date)
+ {
- $Res=$this->db->exec_sql("select fo_id ,
- fo_fr_id,
- fo_pos,
- fo_label,
- fo_formula,
- fr_label from form
- inner join formdef on fr_id=fo_fr_id
- where fr_id =".$this->id.
- "order by fo_pos");
- $Max=Database::num_row($Res);
- if ($Max==0) { $this->row=0;return null;}
- $col=array();
- for ($i=0;$i<$Max;$i++) {
- $l_line=Database::fetch_array($Res,$i);
- $col[]=ParseFormula($this->db,
- $l_line['fo_label'],
- $l_line['fo_formula'],
- $p_start,
- $p_end,
- true,
- $p_type_date
- );
-
- } //for ($i
- $this->row=$col;
- return $col;
- }
-/*!
- * \brief Display a form for encoding a new report or update one
- *
- * \param $p_line number of line
- *
- */
-function form($p_line=0) {
+ $Res=$this->db->exec_sql("select fo_id ,
+ fo_fr_id,
+ fo_pos,
+ fo_label,
+ fo_formula,
+ fr_label from form
+ inner join formdef on fr_id=fo_fr_id
+ where fr_id =".$this->id.
+ "order by fo_pos");
+ $Max=Database::num_row($Res);
+ if ($Max==0)
+ {
+ $this->row=0;
+ return null;
+ }
+ $col=array();
+ for ($i=0;$i<$Max;$i++)
+ {
+ $l_line=Database::fetch_array($Res,$i);
+ $col[]=ParseFormula($this->db,
+ $l_line['fo_label'],
+ $l_line['fo_formula'],
+ $p_start,
+ $p_end,
+ true,
+ $p_type_date
+ );
- $r="";
- if ($p_line == 0 ) $p_line=count($this->aAcc_Report_row);
- $r.= dossier::hidden();
- $r.= HtmlInput::hidden('line',$p_line);
- $r.= HtmlInput::hidden('fr_id',$this->id);
- $wForm=new IText();
- $r.="Nom du rapport : ";
- $r.=$wForm->input('form_nom',$this->name);
+ } //for ($i
+ $this->row=$col;
+ return $col;
+ }
+ /*!
+ * \brief Display a form for encoding a new report or update one
+ *
+ * \param $p_line number of line
+ *
+ */
+ function form($p_line=0)
+ {
- $r.= '';
- $r.= "";
- $r.= " Position ";
- $r.= " Texte ";
- $r.= " Formule ";
+ $r="";
+ if ($p_line == 0 ) $p_line=count($this->aAcc_Report_row);
+ $r.= dossier::hidden();
+ $r.= HtmlInput::hidden('line',$p_line);
+ $r.= HtmlInput::hidden('fr_id',$this->id);
+ $wForm=new IText();
+ $r.="Nom du rapport : ";
+ $r.=$wForm->input('form_nom',$this->name);
- $r.= ' ';
- $wName=new IText();
- $wName->size=40;
- $wPos=new IText();
- $wPos->size=3;
- $wForm=new IText();
- $wForm->size=35;
- for ( $i =0 ; $i < $p_line;$i++) {
+ $r.= '';
+ $r.= "";
+ $r.= " Position ";
+ $r.= " Texte ";
+ $r.= " Formule ";
- $r.= " ";
-
- $r.= "";
- $wPos->value=( isset($this->aAcc_Report_row[$i]->fo_pos))?$this->aAcc_Report_row[$i]->fo_pos:$i+1;
- $r.=$wPos->input("pos".$i);
- $r.= ' ';
-
+ $r.= ' ';
+ $wName=new IText();
+ $wName->size=40;
+ $wPos=new IText();
+ $wPos->size=3;
+ $wForm=new IText();
+ $wForm->size=35;
+ for ( $i =0 ; $i < $p_line;$i++)
+ {
- $r.= "";
- $wName->value=( isset($this->aAcc_Report_row[$i]->fo_label))?$this->aAcc_Report_row[$i]->fo_label:"";
- $r.=$wName->input("text".$i);
- $r.= ' ';
+ $r.= "";
- $r.='';
- $search=new IPoste("form".$i);
- $search->size=50;
- $search->value=( isset($this->aAcc_Report_row[$i]->fo_formula))?$this->aAcc_Report_row[$i]->fo_formula:"";
- $search->label=_("Recherche poste");
- $search->set_attribute('gDossier',dossier::id());
- $search->set_attribute('bracket',1);
- $search->set_attribute('no_overwrite',1);
- $search->set_attribute('noquery',1);
- $search->set_attribute('account',$search->name);
- $search->set_attribute('ipopup','ipop_card');
-
- $r.=$search->input();
- $r.=' ';
+ $r.= "";
+ $wPos->value=( isset($this->aAcc_Report_row[$i]->fo_pos))?$this->aAcc_Report_row[$i]->fo_pos:$i+1;
+ $r.=$wPos->input("pos".$i);
+ $r.= ' ';
- $r.= " ";
+ $r.= "";
+ $wName->value=( isset($this->aAcc_Report_row[$i]->fo_label))?$this->aAcc_Report_row[$i]->fo_label:"";
+ $r.=$wName->input("text".$i);
+ $r.= ' ';
+
+ $r.='';
+ $search=new IPoste("form".$i);
+ $search->size=50;
+ $search->value=( isset($this->aAcc_Report_row[$i]->fo_formula))?$this->aAcc_Report_row[$i]->fo_formula:"";
+ $search->label=_("Recherche poste");
+ $search->set_attribute('gDossier',dossier::id());
+ $search->set_attribute('bracket',1);
+ $search->set_attribute('no_overwrite',1);
+ $search->set_attribute('noquery',1);
+ $search->set_attribute('account',$search->name);
+ $search->set_attribute('ipopup','ipop_card');
+
+ $r.=$search->input();
+ $r.=' ';
+
+
+ $r.= "";
+ }
+
+ $r.= "
";
+ $wButton=new IButton();
+ $wButton->javascript=" rapport_add_row('".dossier::id()."')";
+ $wButton->label="Ajout d'une ligne";
+ $r.=$wButton->input();
+ return $r;
+
+ }
+ /*!\brief save into form and form_def
+ */
+ function save()
+ {
+
+ if ( strlen(trim($this->name)) == 0 )
+ return;
+ if ( $this->id == 0 )
+ $this->insert();
+ else
+ $this->update();
+
+ }
+ function insert()
+ {
+ try
+ {
+ $this->db->start();
+ $ret_sql=$this->db->exec_sql(
+ "insert into formdef (fr_label) values($1) returning fr_id",
+ array($this->name)
+ );
+ $this->id=Database::fetch_result($ret_sql,0,0);
+ $ix=1;
+ foreach ( $this->aAcc_Report_row as $row)
+ {
+ if ( strlen(trim($row->get_parameter("name"))) != 0 &&
+ strlen(trim($row->get_parameter("formula"))) != 0 )
+ {
+ $ix=($row->get_parameter("position")!="")?$row->get_parameter("position"):$ix;
+ $row->set_parameter("position",$ix);
+ $ret_sql=$this->db->exec_sql(
+ "insert into form (fo_fr_id,fo_pos,fo_label,fo_formula)".
+ " values($1,$2,$3,$4)",
+ array($this->id,
+ $row->fo_pos,
+ $row->fo_label,
+ $row->fo_formula)
+ );
+ }
+ }
+
+ }
+ catch (Exception $e)
+ {
+ $this->db->rollback();
+ echo $e->getMessage();
+ }
+ $this->db->commit();
+
+ }
+ function update()
+ {
+ try
+ {
+ $this->db->start();
+ $ret_sql=$this->db->exec_sql(
+ "update formdef set fr_label=$1 where fr_id=$2",
+ array($this->name,$this->id));
+ $ret_sql=$this->db->exec_sql(
+ "delete from form where fo_fr_id=$1",
+ array($this->id));
+ $ix=0;
+
+ foreach ( $this->aAcc_Report_row as $row)
+ {
+ if ( strlen(trim($row->get_parameter("name"))) != 0 &&
+ strlen(trim($row->get_parameter("formula"))) != 0 )
+ {
+ $ix=($row->get_parameter("position")!="")?$row->get_parameter("position"):$ix;
+ $row->set_parameter("position",$ix);
+ $ret_sql=$this->db->exec_sql(
+ "insert into form (fo_fr_id,fo_pos,fo_label,fo_formula)".
+ " values($1,$2,$3,$4)",
+ array($this->id,
+ $row->fo_pos,
+ $row->fo_label,
+ $row->fo_formula)
+ );
+ }
+ }
+
+
+ }
+ catch (Exception $e)
+ {
+ $this->db->rollback();
+ echo $e->getMessage();
+ }
+ $this->db->commit();
+ }
+ /*!\brief fill a form thanks an array, usually it is $_POST
+ *\param $p_array keys = fr_id, form_nom,textXX, formXX, posXX where
+ XX is an number
+ */
+ function from_array($p_array)
+ {
+ $this->id=(isset($p_array['fr_id']))?$p_array['fr_id']:0;
+ $this->name=(isset($p_array['form_nom']))?$p_array['form_nom']:"";
+ $ix=0;
+
+ $rr=new Acc_Report_Row();
+ $rr->set_parameter("form_id",$this->id);
+ $rr->set_parameter('database',$this->db);
+
+ $this->aAcc_Report_row=$rr->from_array($p_array);
+
+
+ }
+ /*!\brief the fr_id MUST be set before calling
+ */
+
+
+ function load()
+ {
+ $sql=$this->db->exec_sql(
+ "select fr_label from formdef where fr_id=$1",
+ array($this->id));
+ if ( Database::num_row($sql) == 0 ) return;
+ $this->name=Database::fetch_result($sql,0,0);
+ $sql=$this->db->exec_sql(
+ "select fo_id,fo_pos,fo_label,fo_formula ".
+ " from form ".
+ " where fo_fr_id=$1 order by fo_pos",
+ array($this->id));
+ $f=Database::fetch_all($sql);
+ $array=array();
+ if ( ! empty($f) )
+ {
+ foreach ($f as $r)
+ {
+ $obj=new Acc_Report_Row();
+ $obj->set_parameter("name",$r['fo_label']);
+ $obj->set_parameter("id",$r['fo_id']);
+ $obj->set_parameter("position",$r['fo_pos']);
+ $obj->set_parameter("formula",$r['fo_formula']);
+ $obj->set_parameter('database',$this->db);
+ $obj->set_parameter('form_id',$this->id);
+ $array[]=clone $obj;
+ }
+ }
+ $this->aAcc_Report_row=$array;
+
+ }
+ function delete()
+ {
+ $ret=$this->db->exec_sql(
+ "delete from formdef where fr_id=$1",
+ array($this->id)
+ );
+ }
+ /*!\brief get a list from formdef of all defined form
+ *
+ *\return array of object rapport
+ *
+ */
+ function get_list()
+ {
+ $sql="select fr_id,fr_label from formdef order by fr_label";
+ $ret=$this->db->exec_sql($sql);
+ if ( Database::num_row($ret) == 0 ) return array();
+ $array=Database::fetch_all($ret);
+ $obj=array();
+ foreach ($array as $row)
+ {
+ $tmp=new Acc_Report($this->db);
+ $tmp->id=$row['fr_id'];
+ $tmp->name=$row['fr_label'];
+ $obj[]=clone $tmp;
+ }
+ return $obj;
+ }
+ /*!\brief To make a SELECT button with the needed value, it is used
+ *by the SELECT widget
+ *\return string with html code
+ */
+ function make_array()
+ {
+ $sql=$this->db->make_array("select fr_id,fr_label from formdef order by fr_label");
+ return $sql;
}
- $r.= "
";
- $wButton=new IButton();
- $wButton->javascript=" rapport_add_row('".dossier::id()."')";
- $wButton->label="Ajout d'une ligne";
- $r.=$wButton->input();
- return $r;
-}
- /*!\brief save into form and form_def
- */
- function save() {
+ /*!\brief write to a file the definition of a report
+ * \param p_file is the file name
+ */
+ function export($p_file)
+ {
+ $this->load();
- if ( strlen(trim($this->name)) == 0 )
- return;
- if ( $this->id == 0 )
- $this->insert();
- else
- $this->update();
+ fputcsv($p_file,array($this->name));
+
+ foreach ($this->aAcc_Report_row as $row)
+ {
+ fputcsv($p_file,array($row->get_parameter("name"),
+ $row->get_parameter('position'),
+ $row->get_parameter('formula'))
+ );
+ }
- }
- function insert() {
- try {
- $this->db->start();
- $ret_sql=$this->db->exec_sql(
- "insert into formdef (fr_label) values($1) returning fr_id",
- array($this->name)
- );
- $this->id=Database::fetch_result($ret_sql,0,0);
- $ix=1;
- foreach ( $this->aAcc_Report_row as $row) {
- if ( strlen(trim($row->get_parameter("name"))) != 0 &&
- strlen(trim($row->get_parameter("formula"))) != 0 )
- {
- $ix=($row->get_parameter("position")!="")?$row->get_parameter("position"):$ix;
- $row->set_parameter("position",$ix);
- $ret_sql=$this->db->exec_sql(
- "insert into form (fo_fr_id,fo_pos,fo_label,fo_formula)".
- " values($1,$2,$3,$4)",
- array($this->id,
- $row->fo_pos,
- $row->fo_label,
- $row->fo_formula)
- );
- }
- }
-
- } catch (Exception $e) {
- $this->db->rollback();
- echo $e->getMessage();
}
- $this->db->commit();
-
- }
- function update() {
- try {
- $this->db->start();
- $ret_sql=$this->db->exec_sql(
- "update formdef set fr_label=$1 where fr_id=$2",
- array($this->name,$this->id));
- $ret_sql=$this->db->exec_sql(
- "delete from form where fo_fr_id=$1",
- array($this->id));
- $ix=0;
-
- foreach ( $this->aAcc_Report_row as $row) {
- if ( strlen(trim($row->get_parameter("name"))) != 0 &&
- strlen(trim($row->get_parameter("formula"))) != 0 )
- {
- $ix=($row->get_parameter("position")!="")?$row->get_parameter("position"):$ix;
- $row->set_parameter("position",$ix);
- $ret_sql=$this->db->exec_sql(
- "insert into form (fo_fr_id,fo_pos,fo_label,fo_formula)".
- " values($1,$2,$3,$4)",
- array($this->id,
- $row->fo_pos,
- $row->fo_label,
- $row->fo_formula)
- );
- }
- }
-
-
- }catch (Exception $e) {
- $this->db->rollback();
- echo $e->getMessage();
+ /*!\brief upload a definition of a report and insert it into the
+ * database
+ */
+ function upload()
+ {
+ if ( empty ($_FILES) ) return;
+ if ( strlen(trim($_FILES['report']['tmp_name'])) == 0 )
+ {
+ alert("Nom de fichier est vide");
+ return;
+ }
+ $file_report=tempnam('tmp','file_report');
+ if ( move_uploaded_file($_FILES['report']['tmp_name'],$file_report))
+ {
+ // File is uploaded now we can try to parse it
+ $file=fopen($file_report,'r');
+ $data=fgetcsv($file);
+ if ( empty($data) ) return;
+ $this->name=$data[0];
+ $array=array();
+ while($data=fgetcsv($file))
+ {
+ $obj=new Acc_Report_Row();
+ $obj->set_parameter("name",$data[0]);
+ $obj->set_parameter("id",0);
+ $obj->set_parameter("position",$data[1]);
+ $obj->set_parameter("formula",$data[2]);
+ $obj->set_parameter('database',$this->db);
+ $obj->set_parameter('form_id',0);
+ $array[]=clone $obj;
+ }
+ $this->aAcc_Report_row=$array;
+ $this->insert();
+ }
}
- $this->db->commit();
- }
- /*!\brief fill a form thanks an array, usually it is $_POST
- *\param $p_array keys = fr_id, form_nom,textXX, formXX, posXX where
- XX is an number
- */
- function from_array($p_array) {
- $this->id=(isset($p_array['fr_id']))?$p_array['fr_id']:0;
- $this->name=(isset($p_array['form_nom']))?$p_array['form_nom']:"";
- $ix=0;
-
- $rr=new Acc_Report_Row();
- $rr->set_parameter("form_id",$this->id);
- $rr->set_parameter('database',$this->db);
-
- $this->aAcc_Report_row=$rr->from_array($p_array);
-
-
- }
- /*!\brief the fr_id MUST be set before calling
- */
-
-
- function load() {
- $sql=$this->db->exec_sql(
- "select fr_label from formdef where fr_id=$1",
- array($this->id));
- if ( Database::num_row($sql) == 0 ) return;
- $this->name=Database::fetch_result($sql,0,0);
- $sql=$this->db->exec_sql(
- "select fo_id,fo_pos,fo_label,fo_formula ".
- " from form ".
- " where fo_fr_id=$1 order by fo_pos",
- array($this->id));
- $f=Database::fetch_all($sql);
- $array=array();
- if ( ! empty($f) ) {
- foreach ($f as $r) {
- $obj=new Acc_Report_Row();
- $obj->set_parameter("name",$r['fo_label']);
- $obj->set_parameter("id",$r['fo_id']);
- $obj->set_parameter("position",$r['fo_pos']);
- $obj->set_parameter("formula",$r['fo_formula']);
- $obj->set_parameter('database',$this->db);
- $obj->set_parameter('form_id',$this->id);
- $array[]=clone $obj;
- }
+ /**
+ *@brief check if a report exist
+ *@param $p_id, optional, if given check the report with this fr_id
+ *@return return true if the report exist otherwise false
+ */
+ function exist($p_id=0)
+ {
+ $c=$this->id;
+ if ( $p_id != 0 ) $c=$p_id;
+ $ret=$this->db->exec_sql("select fr_label from formdef where fr_id=$1",array($c));
+ if (Database::num_row($ret) == 0) return false;
+ return true;
}
- $this->aAcc_Report_row=$array;
+ static function test_me()
+ {
+ $cn=new Database(dossier::id());
+ $a=new Acc_Report($cn);
+ print_r($a->get_list());
+ $array=array("text0"=>"test1",
+ "form0"=>"7%",
+ "text1"=>"test2",
+ "form1"=>"6%",
+ "fr_id"=>110,
+ "form_nom"=>"Tableau"
+ );
+ $a->from_array($array);
+ print_r($a);
+ echo '';
+ echo $a->form(10);
- }
- function delete() {
- $ret=$this->db->exec_sql(
- "delete from formdef where fr_id=$1",
- array($this->id)
- );
- }
- /*!\brief get a list from formdef of all defined form
- *
- *\return array of object rapport
- *
- */
- function get_list()
- {
- $sql="select fr_id,fr_label from formdef order by fr_label";
- $ret=$this->db->exec_sql($sql);
- if ( Database::num_row($ret) == 0 ) return array();
- $array=Database::fetch_all($ret);
- $obj=array();
- foreach ($array as $row) {
- $tmp=new Acc_Report($this->db);
- $tmp->id=$row['fr_id'];
- $tmp->name=$row['fr_label'];
- $obj[]=clone $tmp;
+ echo HtmlInput::submit('update','Enregistre');
+ /* Add a line should be a javascript see comptanalytic */
+ // $r.= ' ';
+ echo HtmlInput::submit('del_form','Efface ce rapport');
+ echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
+ echo " ";
+ if ( isset ($_POST['update']))
+ {
+ $b=new Acc_Report($cn);
+ $b->from_array($_POST);
+ echo ' ';
+ print_r($b);
+ }
}
- return $obj;
- }
- /*!\brief To make a SELECT button with the needed value, it is used
- *by the SELECT widget
- *\return string with html code
- */
- function make_array() {
- $sql=$this->db->make_array("select fr_id,fr_label from formdef order by fr_label");
- return $sql;
- }
-
-
- /*!\brief write to a file the definition of a report
- * \param p_file is the file name
- */
- function export($p_file) {
- $this->load();
-
- fputcsv($p_file,array($this->name));
-
- foreach ($this->aAcc_Report_row as $row) {
- fputcsv($p_file,array($row->get_parameter("name"),
- $row->get_parameter('position'),
- $row->get_parameter('formula'))
- );
- }
-
- }
- /*!\brief upload a definition of a report and insert it into the
- * database
- */
- function upload() {
- if ( empty ($_FILES) ) return;
- if ( strlen(trim($_FILES['report']['tmp_name'])) == 0 ) {
- alert("Nom de fichier est vide");
- return;
- }
- $file_report=tempnam('tmp','file_report');
- if ( move_uploaded_file($_FILES['report']['tmp_name'],$file_report)) {
- // File is uploaded now we can try to parse it
- $file=fopen($file_report,'r');
- $data=fgetcsv($file);
- if ( empty($data) ) return;
- $this->name=$data[0];
- $array=array();
- while($data=fgetcsv($file)) {
- $obj=new Acc_Report_Row();
- $obj->set_parameter("name",$data[0]);
- $obj->set_parameter("id",0);
- $obj->set_parameter("position",$data[1]);
- $obj->set_parameter("formula",$data[2]);
- $obj->set_parameter('database',$this->db);
- $obj->set_parameter('form_id',0);
- $array[]=clone $obj;
- }
- $this->aAcc_Report_row=$array;
- $this->insert();
- }
- }
- /**
- *@brief check if a report exist
- *@param $p_id, optional, if given check the report with this fr_id
- *@return return true if the report exist otherwise false
- */
- function exist($p_id=0) {
- $c=$this->id;
- if ( $p_id != 0 ) $c=$p_id;
- $ret=$this->db->exec_sql("select fr_label from formdef where fr_id=$1",array($c));
- if (Database::num_row($ret) == 0) return false;
- return true;
- }
- static function test_me() {
- $cn=new Database(dossier::id());
- $a=new Acc_Report($cn);
- print_r($a->get_list());
- $array=array("text0"=>"test1",
- "form0"=>"7%",
- "text1"=>"test2",
- "form1"=>"6%",
- "fr_id"=>110,
- "form_nom"=>"Tableau"
- );
- $a->from_array($array);
- print_r($a);
- echo '';
- echo $a->form(10);
-
- echo HtmlInput::submit('update','Enregistre');
- /* Add a line should be a javascript see comptanalytic */
- // $r.= ' ';
- echo HtmlInput::submit('del_form','Efface ce rapport');
- echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
- echo " ";
- if ( isset ($_POST['update'])) {
- $b=new Acc_Report($cn);
- $b->from_array($_POST);
- echo ' ';
- print_r($b);
- }
- }
}
?>
diff --git a/include/class_acc_report_row.php b/include/class_acc_report_row.php
index a278fcd17..c5a85b5ba 100644
--- a/include/class_acc_report_row.php
+++ b/include/class_acc_report_row.php
@@ -27,87 +27,97 @@
/*!\brief manipulate the form_def's child table (form) */
class Acc_Report_Row
{
- private static $variable=array(
- "name"=>"fo_label",
- "formula"=>"fo_formula",
- "id"=>"fo_id",
- "position"=>"fo_pos",
- "form_id"=>"fo_fr_id",
- "database"=>"db"
- );
- function __construct ($p_name=null,$p_formula=null) {
- $this->set_parameter("id",0);
+ private static $variable=array(
+ "name"=>"fo_label",
+ "formula"=>"fo_formula",
+ "id"=>"fo_id",
+ "position"=>"fo_pos",
+ "form_id"=>"fo_fr_id",
+ "database"=>"db"
+ );
+ function __construct ($p_name=null,$p_formula=null)
+ {
+ $this->set_parameter("id",0);
- $this->set_parameter("name",$p_name);
- $this->set_parameter("formula",$p_formula);
- }
- public function get_parameter($p_string) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- return $this->$idx;
+ $this->set_parameter("name",$p_name);
+ $this->set_parameter("formula",$p_formula);
}
- else
- exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
- }
- public function set_parameter($p_string,$p_value) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- $this->$idx=$p_value;
+ public function get_parameter($p_string)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ return $this->$idx;
+ }
+ else
+ exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
}
- else
- exit (__FILE__.":".__LINE__."$p_string ".'Erreur attribut inexistant');
-
-
- }
- public function get_info() {
- return var_export(self::$variable,true);
- }
- /*!\brief Convert an array into an array of row_rapport object
- * the fo_id is 0, position = 0, the fo_frd_id (form_id) is
- * the one of the current object, the db is also the current one
- *\param $p_array contains the value
- *\return an array of Acc_Report_Row object
- */
- public function from_array($p_array) {
- extract ($p_array);
- $ret=array();
- $ix=0;
- $found=0;
- foreach ( $p_array as $r) {
+ public function set_parameter($p_string,$p_value)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ $this->$idx=$p_value;
+ }
+ else
+ exit (__FILE__.":".__LINE__."$p_string ".'Erreur attribut inexistant');
- if ( isset(${'form'.$ix}) && isset ( ${'text'.$ix} )) {
- $obj=new Acc_Report_Row( ${'text'.$ix},${'form'.$ix});
-
- if ( isset(${'pos'.$ix}) && isNumber(${'pos'.$ix})==1 )
- $obj->set_parameter("position",${'pos'.$ix});
- else {
- $obj->set_parameter("position",$found);
- $found++;
- }
-
- $obj->fo_id=0;
- $obj->fo_fr_id=$this->fo_fr_id;
- $obj->db=$this->db;
-
- $ret[]=clone $obj;
- }
- $ix++;
}
- return $ret;
- }
- static function test_me()
- {
+ public function get_info()
+ {
+ return var_export(self::$variable,true);
+ }
+ /*!\brief Convert an array into an array of row_rapport object
+ * the fo_id is 0, position = 0, the fo_frd_id (form_id) is
+ * the one of the current object, the db is also the current one
+ *\param $p_array contains the value
+ *\return an array of Acc_Report_Row object
+ */
+ public function from_array($p_array)
+ {
+ extract ($p_array);
+ $ret=array();
+ $ix=0;
+ $found=0;
+ foreach ( $p_array as $r)
+ {
+
+ if ( isset(${'form'.$ix}) && isset ( ${'text'.$ix} ))
+ {
+ $obj=new Acc_Report_Row( ${'text'.$ix},${'form'.$ix});
+
+ if ( isset(${'pos'.$ix}) && isNumber(${'pos'.$ix})==1 )
+ $obj->set_parameter("position",${'pos'.$ix});
+ else
+ {
+ $obj->set_parameter("position",$found);
+ $found++;
+ }
+
+ $obj->fo_id=0;
+ $obj->fo_fr_id=$this->fo_fr_id;
+ $obj->db=$this->db;
+
+ $ret[]=clone $obj;
+ }
+ $ix++;
+
+ }
+ return $ret;
+ }
+ static function test_me()
+ {
$cn=new Database(dossier::id());
- $a=new Acc_Report_Row();
- $array=array("text0"=>"test1",
- "form0"=>"7%",
- "text1"=>"test2",
- "form1"=>"6%"
- );
- $a->db=$cn;
- $b=$a->from_array($array);
- print_r($b);
- echo $a->get_info();
- }
+ $a=new Acc_Report_Row();
+ $array=array("text0"=>"test1",
+ "form0"=>"7%",
+ "text1"=>"test2",
+ "form1"=>"6%"
+ );
+ $a->db=$cn;
+ $b=$a->from_array($array);
+ print_r($b);
+ echo $a->get_info();
+ }
}
diff --git a/include/class_acc_tva.php b/include/class_acc_tva.php
index 6d8a82821..714f4afaa 100644
--- a/include/class_acc_tva.php
+++ b/include/class_acc_tva.php
@@ -26,151 +26,171 @@
require_once('class_dossier.php');
require_once('class_database.php');
- /*!\brief Acc_Tva is used for to map the table tva_rate
- * parameter are
- - private static $cn; database connection
- - private static $variable=array("id"=>"tva_id",
- "label"=>"tva_label",
- "rate"=>"tva_rate",
- "comment"=>"tva_comment",
- "account"=>"tva_poste");
-
+/*!\brief Acc_Tva is used for to map the table tva_rate
+ * parameter are
+- private static $cn; database connection
+- private static $variable=array("id"=>"tva_id",
+ "label"=>"tva_label",
+ "rate"=>"tva_rate",
+ "comment"=>"tva_comment",
+ "account"=>"tva_poste");
+
*/
class Acc_Tva
{
- private $cn; /*!< $cn database connection */
- private static $variable=array("id"=>"tva_id",
- "label"=>"tva_label",
- "rate"=>"tva_rate",
- "comment"=>"tva_comment",
- "account"=>"tva_poste");
+ private $cn; /*!< $cn database connection */
+ private static $variable=array("id"=>"tva_id",
+ "label"=>"tva_label",
+ "rate"=>"tva_rate",
+ "comment"=>"tva_comment",
+ "account"=>"tva_poste");
- function __construct ($p_init,$p_tva_id=0) {
- $this->cn=$p_init;
- $this->tva_id=$p_tva_id;
- $this->poste="";
- }
- public function get_parameter($p_string) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- return $this->$idx;
+ function __construct ($p_init,$p_tva_id=0)
+ {
+ $this->cn=$p_init;
+ $this->tva_id=$p_tva_id;
+ $this->poste="";
+ }
+ public function get_parameter($p_string)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ return $this->$idx;
+ }
+
+ echo (__FILE__.":".__LINE__.'Erreur attribut inexistant');
+ }
+ public function set_parameter($p_string,$p_value)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ $this->$idx=$p_value;
+ }
+ else
+ exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
+
+
+ }
+ public function get_info()
+ {
+ return var_export(self::$variable,true);
}
- echo (__FILE__.":".__LINE__.'Erreur attribut inexistant');
- }
- public function set_parameter($p_string,$p_value) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- $this->$idx=$p_value;
+ public function verify()
+ {
+ // Verify that the elt we want to add is correct
}
- else
- exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
-
-
- }
- public function get_info() { return var_export(self::$variable,true); }
+ public function save()
+ {
- public function verify() {
- // Verify that the elt we want to add is correct
- }
- public function save() {
-
- if ( $this->tva_id == 0 )
- $this->insert();
- else
- $this->update();
- }
-
- public function insert() {
- if ( $this->verify() != 0 ) return;
- $sql="select tva_insert($1,$2,$3,$4)";
-
- $res=$this->cn->exec_sql(
- $sql,
- array($this->tva_label,
- $this->tva_rate,
- $this->tva_comment,
- $this->tva_poste)
- );
- $this->tva_id=$this->cn->get_current_seq('s_tva');
- $err=Database::fetch_result($res);
- }
-
- public function update() {
- if ( $this->verify() != 0 ) return;
- $sql="update tva_rate set tva_label=$1,tva_rate=$2,tva_comment=$3,tva_poste=$4 ".
- " where tva_id = $5";
- $res=$this->cn->exec_sql(
- $sql,
- array($this->tva_label,
- $this->tva_rate,
- $this->tva_comment,
- $this->tva_poste,
- $this->tva_id)
- );
-
- }
-
- public function load() {
- $sql="select tva_label,tva_rate, tva_comment,tva_poste from tva_rate where tva_id=$1";
- $res=$this->cn->exec_sql(
- $sql,
- array($this->tva_id)
- );
-
- if ( $this->cn->size() == 0 ) return -1;
-
- $row=Database::fetch_array($res,0);
- foreach ($row as $idx=>$value) { $this->$idx=$value; }
- return 0;
- }
- /*!\brief get the account of the side (debit or credit)
- *\param $p_side is d or C
- *\return the account to use
- *\note call first load if tva_poste is empty
- */
- public function get_side($p_side) {
- if ( strlen($this->tva_poste) == 0 ) $this->load();
- list($deb,$cred)=explode(",",$this->tva_poste);
- switch ($p_side) {
- case 'd':
- return $deb;
- break;
- case 'c':
- return $cred;
- break;
- default:
- throw (new Exception (__FILE__.':'.__LINE__." param est d ou c, on a recu [ $p_side ]"));
+ if ( $this->tva_id == 0 )
+ $this->insert();
+ else
+ $this->update();
}
- }
- public function delete() {
- $sql="delete from tva_rate where tva_id=$1";
- $res=$this->cn->exec_sql($sql,array($this->tva_id));
- }
- /*!\brief
- * Test function
- */
- static function test_me() {
- $cn=new Database(dossier::id());
- $a=new Acc_Tva($cn);
- echo $a->get_info();
- $a->set_parameter("id",1);
- $a->load();
- $a->set_parameter("id",0);
- $a->set_parameter("rate","0.2222");
- $a->set_parameter("label","test");
- $a->save();
- $a->load();
- print_r($a);
- $a->set_parameter("comment","un cht'it test");
- $a->save();
- $a->load();
- print_r($a);
+ public function insert()
+ {
+ if ( $this->verify() != 0 ) return;
+ $sql="select tva_insert($1,$2,$3,$4)";
+
+ $res=$this->cn->exec_sql(
+ $sql,
+ array($this->tva_label,
+ $this->tva_rate,
+ $this->tva_comment,
+ $this->tva_poste)
+ );
+ $this->tva_id=$this->cn->get_current_seq('s_tva');
+ $err=Database::fetch_result($res);
+ }
+
+ public function update()
+ {
+ if ( $this->verify() != 0 ) return;
+ $sql="update tva_rate set tva_label=$1,tva_rate=$2,tva_comment=$3,tva_poste=$4 ".
+ " where tva_id = $5";
+ $res=$this->cn->exec_sql(
+ $sql,
+ array($this->tva_label,
+ $this->tva_rate,
+ $this->tva_comment,
+ $this->tva_poste,
+ $this->tva_id)
+ );
+
+ }
+
+ public function load()
+ {
+ $sql="select tva_label,tva_rate, tva_comment,tva_poste from tva_rate where tva_id=$1";
+ $res=$this->cn->exec_sql(
+ $sql,
+ array($this->tva_id)
+ );
+
+ if ( $this->cn->size() == 0 ) return -1;
+
+ $row=Database::fetch_array($res,0);
+ foreach ($row as $idx=>$value)
+ {
+ $this->$idx=$value;
+ }
+ return 0;
+ }
+ /*!\brief get the account of the side (debit or credit)
+ *\param $p_side is d or C
+ *\return the account to use
+ *\note call first load if tva_poste is empty
+ */
+ public function get_side($p_side)
+ {
+ if ( strlen($this->tva_poste) == 0 ) $this->load();
+ list($deb,$cred)=explode(",",$this->tva_poste);
+ switch ($p_side)
+ {
+ case 'd':
+ return $deb;
+ break;
+ case 'c':
+ return $cred;
+ break;
+ default:
+ throw (new Exception (__FILE__.':'.__LINE__." param est d ou c, on a recu [ $p_side ]"));
+ }
+ }
+ public function delete()
+ {
+ $sql="delete from tva_rate where tva_id=$1";
+ $res=$this->cn->exec_sql($sql,array($this->tva_id));
+ }
+ /*!\brief
+ * Test function
+ */
+ static function test_me()
+ {
+ $cn=new Database(dossier::id());
+ $a=new Acc_Tva($cn);
+ echo $a->get_info();
+ $a->set_parameter("id",1);
+ $a->load();
+ $a->set_parameter("id",0);
+ $a->set_parameter("rate","0.2222");
+ $a->set_parameter("label","test");
+ $a->save();
+ $a->load();
+ print_r($a);
+
+ $a->set_parameter("comment","un cht'it test");
+ $a->save();
+ $a->load();
+ print_r($a);
+
+ $a->delete();
+ }
- $a->delete();
- }
-
}
/* test::test_me(); */
diff --git a/include/class_action.php b/include/class_action.php
index 98c5b6948..32f39ce23 100644
--- a/include/class_action.php
+++ b/include/class_action.php
@@ -1,4 +1,4 @@
-
@@ -58,958 +58,983 @@ require_once('class_inum.php');
* The table document_type are the possible actions
*/
-class Action
+class Action
{
- var $db; /*!< $db database connexion */
- var $ag_comment; /*!< $ag_comment description (ag_gestion.ag_comment) */
- var $ag_timestamp; /*!< $ag_timestamp document date (ag_gestion.ag_timestamp)*/
- var $dt_id; /*!< $dt_id type of the document (document_type.dt_id)*/
- var $ag_state; /*!< $ag_state stage of the document (printed, send to client...)*/
- var $d_number; /*!< $d_number number of the document*/
- var $d_filename; /*!< $d_filename filename's document */
- var $d_mimetype; /*!< $d_mimetype document's filename */
- var $ag_title; /*!< $ag_title title document */
- var $f_id; /*!< $f_id_dest fiche id (From field ) */
- var $ag_ref_ag_id; /*!< $ag_ref_ag_id concern previous action*/
- var $ag_ref; /*!< $ag_ref is the ref */
- var $ag_hour; /*!< $ag_hour is the hour of the meeting, action */
- var $ag_priority; /*!< $ag_priority is the priority 1 High, 2 medium, 3 low */
- var $ag_dest; /*!< $ag_dest person who is in charged */
- var $ag_contact; /*!< $ag_contact contact */
- /*! constructor
- * \brief constructor
- * \param p_cn database connection
- */
- function __construct ($p_cn)
+ var $db; /*!< $db database connexion */
+ var $ag_comment; /*!< $ag_comment description (ag_gestion.ag_comment) */
+ var $ag_timestamp; /*!< $ag_timestamp document date (ag_gestion.ag_timestamp)*/
+ var $dt_id; /*!< $dt_id type of the document (document_type.dt_id)*/
+ var $ag_state; /*!< $ag_state stage of the document (printed, send to client...)*/
+ var $d_number; /*!< $d_number number of the document*/
+ var $d_filename; /*!< $d_filename filename's document */
+ var $d_mimetype; /*!< $d_mimetype document's filename */
+ var $ag_title; /*!< $ag_title title document */
+ var $f_id; /*!< $f_id_dest fiche id (From field ) */
+ var $ag_ref_ag_id; /*!< $ag_ref_ag_id concern previous action*/
+ var $ag_ref; /*!< $ag_ref is the ref */
+ var $ag_hour; /*!< $ag_hour is the hour of the meeting, action */
+ var $ag_priority; /*!< $ag_priority is the priority 1 High, 2 medium, 3 low */
+ var $ag_dest; /*!< $ag_dest person who is in charged */
+ var $ag_contact; /*!< $ag_contact contact */
+ /*! constructor
+ * \brief constructor
+ * \param p_cn database connection
+ */
+ function __construct ($p_cn)
{
- $this->db=$p_cn;
- $this->f_id=0;
+ $this->db=$p_cn;
+ $this->f_id=0;
}
- //----------------------------------------------------------------------
- /*!
- * \brief Display the object, the tags for the FORM
- * are in the caller. It will be used for adding and updating
- * action
- *\note If ag_id is not equal to zero then it is an update otherwise
- * it is a new document
- *
- * \param $p_view if set to true the form will be in readonly mode (value: true or false)
- * \param $p_gen true we show the tag for generating a doc (value : true or false)
- *\param $p_base is the p_action parameter
- *\param $retour is the html code for the return button
- * \note update the reference number or the document type is not allowed
- *
- *
- * \return string containing the html code
- */
- function Display($p_view,$p_gen,$p_base,$retour="")
+ //----------------------------------------------------------------------
+ /*!
+ * \brief Display the object, the tags for the FORM
+ * are in the caller. It will be used for adding and updating
+ * action
+ *\note If ag_id is not equal to zero then it is an update otherwise
+ * it is a new document
+ *
+ * \param $p_view if set to true the form will be in readonly mode (value: true or false)
+ * \param $p_gen true we show the tag for generating a doc (value : true or false)
+ *\param $p_base is the p_action parameter
+ *\param $retour is the html code for the return button
+ * \note update the reference number or the document type is not allowed
+ *
+ *
+ * \return string containing the html code
+ */
+ function Display($p_view,$p_gen,$p_base,$retour="")
{
- if ( $p_view=='UPD')
- {
- $upd=true;
- $readonly=false;
- }
- elseif ($p_view=="NEW")
- {
- $upd=false;
- $readonly=false;
- }
- elseif ($p_view=='READ')
- {
- $upd=true;
- $readonly=true;
- }
- else
- {
- exit('class_action'.__LINE__.'Action::Display error unknown parameter'.$p_view);
-
- }
- // Compute the widget
- // Date
- $date=new IDate();
- $date->readonly=$readonly;
- $date->name="ag_timestamp";
- $date->value=$this->ag_timestamp;
-
- // for insert mode only
- if ( $upd == false )
- {
- // Doc Type
- $doc_type=new ISelect();
- $doc_type->name="dt_id";
- $doc_type->value=$this->db->make_array("select dt_id,dt_value from document_type");
- $doc_type->selected=$this->dt_id;
- $doc_type->readonly=false;
- $str_doc_type=$doc_type->input();
- }
- else {
- // Doc Type
- $doc_type=new IHidden();
- $doc_type->name="dt_id";
- $doc_type->value=$this->dt_id;
- $str_doc_type=$doc_type->input().$this->db->get_value("select dt_value from document_type where dt_id=".$this->dt_id);
- }
+ if ( $p_view=='UPD')
+ {
+ $upd=true;
+ $readonly=false;
+ }
+ elseif ($p_view=="NEW")
+ {
+ $upd=false;
+ $readonly=false;
+ }
+ elseif ($p_view=='READ')
+ {
+ $upd=true;
+ $readonly=true;
+ }
+ else
+ {
+ exit('class_action'.__LINE__.'Action::Display error unknown parameter'.$p_view);
- // Description
- $desc=new ITextArea();
- $desc->width=70;
- $desc->heigh=5;
- $desc->name="ag_comment";
- $desc->readonly=$readonly;
- $desc->value=$this->ag_comment;
- if ( strlen($desc->value) >300 ) { $desc->width=120;$desc->heigh=40;}
+ }
+ // Compute the widget
+ // Date
+ $date=new IDate();
+ $date->readonly=$readonly;
+ $date->name="ag_timestamp";
+ $date->value=$this->ag_timestamp;
- // state
- // Retrieve the value
- $a=$this->db->make_array("select s_id,s_value from document_state ");
- $state=new ISelect();
- $state->readonly=$readonly;
- $state->name="ag_state";
- $state->value=$a;
- $state->selected=$this->ag_state;
- $str_state=$state->input();
-
- // Retrieve the value if there is an attached doc
- $doc_ref="";
- // Document id
+ // for insert mode only
+ if ( $upd == false )
+ {
+ // Doc Type
+ $doc_type=new ISelect();
+ $doc_type->name="dt_id";
+ $doc_type->value=$this->db->make_array("select dt_id,dt_value from document_type");
+ $doc_type->selected=$this->dt_id;
+ $doc_type->readonly=false;
+ $str_doc_type=$doc_type->input();
+ }
+ else
+ {
+ // Doc Type
+ $doc_type=new IHidden();
+ $doc_type->name="dt_id";
+ $doc_type->value=$this->dt_id;
+ $str_doc_type=$doc_type->input().$this->db->get_value("select dt_value from document_type where dt_id=".$this->dt_id);
+ }
- $h2=new IHidden();
- $h2->name="d_id";
- $h2->value=$this->d_id;
-
- if ( $this->d_id != 0 && $this->d_id != "" )
- {
- $h2->readonly=($p_view=='NEW')?false:true;
- $doc=new Document($this->db,$this->d_id);
- $doc->get();
- if ( strlen(trim($doc->d_lob)) != 0 )
- {
- $d_id=new IHidden();
- $doc_ref=" Document ".$doc->a_ref().'
';
- $doc_ref.=$h2->input().$d_id->input('d_id',$this->d_id);
- }
-
- }
+ // Description
+ $desc=new ITextArea();
+ $desc->width=70;
+ $desc->heigh=5;
+ $desc->name="ag_comment";
+ $desc->readonly=$readonly;
+ $desc->value=$this->ag_comment;
+ if ( strlen($desc->value) >300 )
+ {
+ $desc->width=120;
+ $desc->heigh=40;
+ }
+
+ // state
+ // Retrieve the value
+ $a=$this->db->make_array("select s_id,s_value from document_state ");
+ $state=new ISelect();
+ $state->readonly=$readonly;
+ $state->name="ag_state";
+ $state->value=$a;
+ $state->selected=$this->ag_state;
+ $str_state=$state->input();
+
+ // Retrieve the value if there is an attached doc
+ $doc_ref="";
+ // Document id
+
+ $h2=new IHidden();
+ $h2->name="d_id";
+ $h2->value=$this->d_id;
+
+ if ( $this->d_id != 0 && $this->d_id != "" )
+ {
+ $h2->readonly=($p_view=='NEW')?false:true;
+ $doc=new Document($this->db,$this->d_id);
+ $doc->get();
+ if ( strlen(trim($doc->d_lob)) != 0 )
+ {
+ $d_id=new IHidden();
+ $doc_ref=" Document ".$doc->a_ref().'
';
+ $doc_ref.=$h2->input().$d_id->input('d_id',$this->d_id);
+ }
+
+ }
- // title
- $title=new IText();
- $title->readonly=$readonly;
- $title->name="ag_title";
- $title->value=$this->ag_title;
- $title->size=60;
+ // title
+ $title=new IText();
+ $title->readonly=$readonly;
+ $title->name="ag_title";
+ $title->value=$this->ag_title;
+ $title->size=60;
- // ag_cal
- $ag_cal=new ICheckBox('ag_cal');
- $ag_cal->readonly=$readonly;
- $ag_cal->name="ag_cal";
+ // ag_cal
+ $ag_cal=new ICheckBox('ag_cal');
+ $ag_cal->readonly=$readonly;
+ $ag_cal->name="ag_cal";
- if ( $this->ag_cal=='C' )
- $ag_cal->selected=true;
- else
- $ag_cal->selected=false;
+ if ( $this->ag_cal=='C' )
+ $ag_cal->selected=true;
+ else
+ $ag_cal->selected=false;
- $str_ag_cal=$ag_cal->input();
+ $str_ag_cal=$ag_cal->input();
- // Priority of the ag_priority
- $ag_priority=new ISelect();
- $ag_priority->readonly=$readonly;
- $ag_priority->name="ag_priority";
- $ag_priority->selected=$this->ag_priority;
- $ag_priority->value=array(array('value'=>1,'label'=>'Haute'),
- array('value'=>2,'label'=>'Moyenne'),
- array('value'=>3,'label'=>'Basse')
- );
- $str_ag_priority=$ag_priority->input();
+ // Priority of the ag_priority
+ $ag_priority=new ISelect();
+ $ag_priority->readonly=$readonly;
+ $ag_priority->name="ag_priority";
+ $ag_priority->selected=$this->ag_priority;
+ $ag_priority->value=array(array('value'=>1,'label'=>'Haute'),
+ array('value'=>2,'label'=>'Moyenne'),
+ array('value'=>3,'label'=>'Basse')
+ );
+ $str_ag_priority=$ag_priority->input();
- // hour of the action (meeting) ag_hour
- $ag_hour=new IText();
- $ag_hour->readonly=$readonly;
- $ag_hour->name="ag_hour";
- $ag_hour->value=$this->ag_hour;
- $ag_hour->size=6;
- $ag_hour->javascript=" onblur=check_hour('ag_hour');";
- $str_ag_hour=$ag_hour->input();
+ // hour of the action (meeting) ag_hour
+ $ag_hour=new IText();
+ $ag_hour->readonly=$readonly;
+ $ag_hour->name="ag_hour";
+ $ag_hour->value=$this->ag_hour;
+ $ag_hour->size=6;
+ $ag_hour->javascript=" onblur=check_hour('ag_hour');";
+ $str_ag_hour=$ag_hour->input();
- // Person in charged of the action
- $ag_dest=new ISelect();
- $ag_dest->readonly=$readonly;
- $ag_dest->name="ag_dest";
- $repo=new Database();
- $aAg_dest=$repo->make_array("select use_id as value, ".
- "use_first_name||' '||use_name||'('||use_login||')' as label ".
- " from ac_users natural join jnt_use_dos ".
- " join priv_user on (jnt_id=priv_jnt) ".
- "where dos_id= ".$_REQUEST['gDossier']);
- $aAg_dest[]=array('value'=>0,'label'=>'phpcompta');
- $ag_dest->value=$aAg_dest;
- $ag_dest->selected=$this->ag_dest;
- $str_ag_dest=$ag_dest->input();
+ // Person in charged of the action
+ $ag_dest=new ISelect();
+ $ag_dest->readonly=$readonly;
+ $ag_dest->name="ag_dest";
+ $repo=new Database();
+ $aAg_dest=$repo->make_array("select use_id as value, ".
+ "use_first_name||' '||use_name||'('||use_login||')' as label ".
+ " from ac_users natural join jnt_use_dos ".
+ " join priv_user on (jnt_id=priv_jnt) ".
+ "where dos_id= ".$_REQUEST['gDossier']);
+ $aAg_dest[]=array('value'=>0,'label'=>'phpcompta');
+ $ag_dest->value=$aAg_dest;
+ $ag_dest->selected=$this->ag_dest;
+ $str_ag_dest=$ag_dest->input();
- // ag_ref
- // Always false for update
- $ag_ref=new IText();
- $ag_ref->readonly=$upd;
- $ag_ref->name="ag_ref";
- $ag_ref->value=FormatString($this->ag_ref);
- $client_label=new ISpan();
+ // ag_ref
+ // Always false for update
+ $ag_ref=new IText();
+ $ag_ref->readonly=$upd;
+ $ag_ref->name="ag_ref";
+ $ag_ref->value=FormatString($this->ag_ref);
+ $client_label=new ISpan();
- /* Add button */
- $f_add_button=new IButton('add_card');
- $f_add_button->label=_('Créer une nouvelle fiche');
- $f_add_button->set_attribute('ipopup','ipop_newcard');
- $filter=$this->db->make_list('select fd_id from fiche_def ');
- $f_add_button->set_attribute('filter',$filter);
+ /* Add button */
+ $f_add_button=new IButton('add_card');
+ $f_add_button->label=_('Créer une nouvelle fiche');
+ $f_add_button->set_attribute('ipopup','ipop_newcard');
+ $filter=$this->db->make_list('select fd_id from fiche_def ');
+ $f_add_button->set_attribute('filter',$filter);
- $f_add_button->javascript=" select_card_type(this);";
- $str_add_button=$f_add_button->input();
+ $f_add_button->javascript=" select_card_type(this);";
+ $str_add_button=$f_add_button->input();
- // f_id_dest sender
- if ( $this->qcode_dest != NOTFOUND && strlen(trim($this->qcode_dest)) != 0)
- {
- $tiers=new Fiche($this->db);
- $tiers->get_by_qcode($this->qcode_dest);
- $qcode_dest_label=$tiers->strAttribut(1);
- $this->f_id_dest=$tiers->id;
- } else {
- $qcode_dest_label=($this->f_id_dest==0 || trim($this->qcode_dest)=="")?'Interne ':'Error';
- }
+ // f_id_dest sender
+ if ( $this->qcode_dest != NOTFOUND && strlen(trim($this->qcode_dest)) != 0)
+ {
+ $tiers=new Fiche($this->db);
+ $tiers->get_by_qcode($this->qcode_dest);
+ $qcode_dest_label=$tiers->strAttribut(1);
+ $this->f_id_dest=$tiers->id;
+ }
+ else
+ {
+ $qcode_dest_label=($this->f_id_dest==0 || trim($this->qcode_dest)=="")?'Interne ':'Error';
+ }
- $h_ag_id=new IHidden();
- // if concerns another action : show the link otherwise nothing
- $lag_ref_ag_id=" 00 / 00 ";
-
- if ( $this->ag_ref_ag_id != 0 )
- {
- $supl_hidden='';
- if( isset($_REQUEST['sc']))
- $supl_hidden.='&sc='.$_REQUEST['sc'];
- if( isset($_REQUEST['f_id']))
- $supl_hidden.='&f_id='.$_REQUEST['f_id'];
- if( isset($_REQUEST['sb']))
- $supl_hidden.='&sb='.$_REQUEST['sb'];
+ $h_ag_id=new IHidden();
+ // if concerns another action : show the link otherwise nothing
+ $lag_ref_ag_id=" 00 / 00 ";
- $lag_ref_ag_id=''.
- $this->db->get_value("select ag_ref from action_gestion where ag_id=$1",array($this->ag_ref_ag_id)).
- " ";
- }
- // sender
- $w=new ICard();
- $w->readonly=$readonly;
- $w->jrn=0;
- $w->name='qcode_dest';
- $w->value=($this->f_id_dest != 0)?$this->qcode_dest:"";
- $w->label="";
- $list_recipient=$this->db->make_list('select fd_id from fiche_def where frd_id in (14,25,8,9,16)');
- $w->extra=$list_recipient;
- $w->set_attribute('typecard',$list_recipient);
- $w->set_dblclick("fill_ipopcard(this);");
- $w->set_attribute('ipopup','ipopcard');
+ if ( $this->ag_ref_ag_id != 0 )
+ {
+ $supl_hidden='';
+ if( isset($_REQUEST['sc']))
+ $supl_hidden.='&sc='.$_REQUEST['sc'];
+ if( isset($_REQUEST['f_id']))
+ $supl_hidden.='&f_id='.$_REQUEST['f_id'];
+ if( isset($_REQUEST['sb']))
+ $supl_hidden.='&sb='.$_REQUEST['sb'];
- // name of the field to update with the name of the card
- $w->set_attribute('label','qcode_dest_label');
- // name of the field to update with the name of the card
- $w->set_attribute('typecard',$w->extra);
- $w->set_function('fill_data');
- $w->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
- $w->name);
+ $lag_ref_ag_id=''.
+ $this->db->get_value("select ag_ref from action_gestion where ag_id=$1",array($this->ag_ref_ag_id)).
+ " ";
+ }
+ // sender
+ $w=new ICard();
+ $w->readonly=$readonly;
+ $w->jrn=0;
+ $w->name='qcode_dest';
+ $w->value=($this->f_id_dest != 0)?$this->qcode_dest:"";
+ $w->label="";
+ $list_recipient=$this->db->make_list('select fd_id from fiche_def where frd_id in (14,25,8,9,16)');
+ $w->extra=$list_recipient;
+ $w->set_attribute('typecard',$list_recipient);
+ $w->set_dblclick("fill_ipopcard(this);");
+ $w->set_attribute('ipopup','ipopcard');
- $sp=new ISpan();
- $sp->name='qcode_dest_label';
- $sp->value=$qcode_dest_label;
+ // name of the field to update with the name of the card
+ $w->set_attribute('label','qcode_dest_label');
+ // name of the field to update with the name of the card
+ $w->set_attribute('typecard',$w->extra);
+ $w->set_function('fill_data');
+ $w->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+ $w->name);
- // contact
- $ag_contact=new ICard();
- $ag_contact->readonly=$readonly;
- $ag_contact->jrn=0;
- $ag_contact->name='ag_contact';
- $ag_contact->value='';
- $ag_contact->set_attribute('ipopup','ipopcard');
+ $sp=new ISpan();
+ $sp->name='qcode_dest_label';
+ $sp->value=$qcode_dest_label;
- if( $this->ag_contact != 0 ) {
- $contact=new Fiche($this->db,$this->ag_contact);
- $ag_contact->value=$contact->get_quick_code();
- }
+ // contact
+ $ag_contact=new ICard();
+ $ag_contact->readonly=$readonly;
+ $ag_contact->jrn=0;
+ $ag_contact->name='ag_contact';
+ $ag_contact->value='';
+ $ag_contact->set_attribute('ipopup','ipopcard');
- $ag_contact->label="";
+ if( $this->ag_contact != 0 )
+ {
+ $contact=new Fiche($this->db,$this->ag_contact);
+ $ag_contact->value=$contact->get_quick_code();
+ }
- $list_contact=$this->db->make_list('select fd_id from fiche_def where frd_id=16');
- $ag_contact->extra=$list_contact;
+ $ag_contact->label="";
- $ag_contact->set_dblclick("fill_ipopcard(this);");
- // name of the field to update with the name of the card
- $ag_contact->set_attribute('label','ag_contact_label');
- // name of the field to update with the name of the card
- $ag_contact->set_attribute('typecard',$list_contact);
- $ag_contact->set_function('fill_data');
- $ag_contact->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
- $ag_contact->name);
+ $list_contact=$this->db->make_list('select fd_id from fiche_def where frd_id=16');
+ $ag_contact->extra=$list_contact;
- $spcontact=new ISpan();
- $spcontact->name='ag_contact_label';
- $spcontact->value='';
- $fiche_contact=new Fiche($this->db);
- $fiche_contact->get_by_qcode($this->ag_contact);
- if ( $fiche_contact->id != 0 ) {
- $spcontact->value=$fiche_contact->strAttribut(ATTR_DEF_NAME);
- }
+ $ag_contact->set_dblclick("fill_ipopcard(this);");
+ // name of the field to update with the name of the card
+ $ag_contact->set_attribute('label','ag_contact_label');
+ // name of the field to update with the name of the card
+ $ag_contact->set_attribute('typecard',$list_contact);
+ $ag_contact->set_function('fill_data');
+ $ag_contact->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+ $ag_contact->name);
+
+ $spcontact=new ISpan();
+ $spcontact->name='ag_contact_label';
+ $spcontact->value='';
+ $fiche_contact=new Fiche($this->db);
+ $fiche_contact->get_by_qcode($this->ag_contact);
+ if ( $fiche_contact->id != 0 )
+ {
+ $spcontact->value=$fiche_contact->strAttribut(ATTR_DEF_NAME);
+ }
- $h_agrefid=new IHidden();
- $str_ag_ref="".(($this->ag_ref != "")?$this->ag_ref:" Nouveau ")." ";
- // Preparing the return string
- $r="";
- $r.=JS_LEDGER;
- /* for new files */
- $upload=new IFile();
- $upload->name="file_upload[]";
- $upload->value="";
- $aAttachedFile=$this->db->get_array('select d_id,d_filename,d_mimetype,'.
- '\'show_document.php?'.
- Dossier::get().'&d_id=\'||d_id as link'.
- ' from document where ag_id=$1',
- array($this->ag_id));
- /* create the select for document */
- $aDocMod=new ISelect();
- $aDocMod->name='doc_mod';
- $aDocMod->value=$this->db->make_array('select md_id,dt_value||\' : \'||md_name as md_name'.
- ' from document_modele join document_type on (md_type=dt_id)'.
- ' order by md_name');
- $str_select_doc=$aDocMod->input();
- /* if no document then do not show the generate button */
- if ( empty($aDocMod->value) )
- $str_submit_generate="";
- else
- $str_submit_generate=HtmlInput::submit("generate",_("Génére le document"));
+ $h_agrefid=new IHidden();
+ $str_ag_ref="".(($this->ag_ref != "")?$this->ag_ref:" Nouveau ")." ";
+ // Preparing the return string
+ $r="";
+ $r.=JS_LEDGER;
+ /* for new files */
+ $upload=new IFile();
+ $upload->name="file_upload[]";
+ $upload->value="";
+ $aAttachedFile=$this->db->get_array('select d_id,d_filename,d_mimetype,'.
+ '\'show_document.php?'.
+ Dossier::get().'&d_id=\'||d_id as link'.
+ ' from document where ag_id=$1',
+ array($this->ag_id));
+ /* create the select for document */
+ $aDocMod=new ISelect();
+ $aDocMod->name='doc_mod';
+ $aDocMod->value=$this->db->make_array('select md_id,dt_value||\' : \'||md_name as md_name'.
+ ' from document_modele join document_type on (md_type=dt_id)'.
+ ' order by md_name');
+ $str_select_doc=$aDocMod->input();
+ /* if no document then do not show the generate button */
+ if ( empty($aDocMod->value) )
+ $str_submit_generate="";
+ else
+ $str_submit_generate=HtmlInput::submit("generate",_("Génére le document"));
- $ag_id=$this->ag_id;
+ $ag_id=$this->ag_id;
- /* fid = Icard */
- $icard=new ICard();
- $icard->jrn=0;
- $icard->table=0;
- $icard->extra2='QuickCode';
- $icard->noadd="no";
- $icard->extra='all';
+ /* fid = Icard */
+ $icard=new ICard();
+ $icard->jrn=0;
+ $icard->table=0;
+ $icard->extra2='QuickCode';
+ $icard->noadd="no";
+ $icard->extra='all';
- /* Text desc */
- $text=new IText();
- $num=new INum();
+ /* Text desc */
+ $text=new IText();
+ $num=new INum();
- /* TVA */
- $itva=new ITva_Popup($this->db);
- $itva->in_table=true;
+ /* TVA */
+ $itva=new ITva_Popup($this->db);
+ $itva->in_table=true;
- /* create aArticle for the detail section */
- for ($i=0;$i< MAX_ARTICLE;$i++) {
- /* fid = Icard */
- $icard=new ICard();
- $icard->jrn=0;
- $icard->table=0;
- $icard->noadd="no";
- $icard->extra='all';
- $icard->name="e_march".$i;
- $tmp_ad=(isset($this->aAction_detail[$i]))?$this->aAction_detail[$i]:false;
- $icard->value='';
- if ( $tmp_ad ) {
- $march=new Fiche($this->db);
- $f=$tmp_ad->get_parameter('qcode');
- if ( $f != 0 ) {
- $march->id=$f;
- $icard->value=$march->get_quick_code();
- }
- }
- $icard->set_dblclick("fill_ipopcard(this);");
- // name of the field to update with the name of the card
- $icard->set_attribute('label',"e_march".$i."_label");
- // name of the field to update with the name of the card
- $icard->set_attribute('typecard',$icard->extra);
- $icard->set_attribute('ipopup','ipopcard');
- $icard->set_function('fill_data');
- $icard->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
- $icard->name);
+ /* create aArticle for the detail section */
+ for ($i=0;$i< MAX_ARTICLE;$i++)
+ {
+ /* fid = Icard */
+ $icard=new ICard();
+ $icard->jrn=0;
+ $icard->table=0;
+ $icard->noadd="no";
+ $icard->extra='all';
+ $icard->name="e_march".$i;
+ $tmp_ad=(isset($this->aAction_detail[$i]))?$this->aAction_detail[$i]:false;
+ $icard->value='';
+ if ( $tmp_ad )
+ {
+ $march=new Fiche($this->db);
+ $f=$tmp_ad->get_parameter('qcode');
+ if ( $f != 0 )
+ {
+ $march->id=$f;
+ $icard->value=$march->get_quick_code();
+ }
+ }
+ $icard->set_dblclick("fill_ipopcard(this);");
+ // name of the field to update with the name of the card
+ $icard->set_attribute('label',"e_march".$i."_label");
+ // name of the field to update with the name of the card
+ $icard->set_attribute('typecard',$icard->extra);
+ $icard->set_attribute('ipopup','ipopcard');
+ $icard->set_function('fill_data');
+ $icard->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+ $icard->name);
- $aArticle[$i]['fid']=$icard->search().$icard->input();
+ $aArticle[$i]['fid']=$icard->search().$icard->input();
- $text->javascript=' onchange="clean_tva('.$i.');compute_ledger('.$i.')"';
- $text->name="e_march".$i."_label";
- $text->size=40;
- $text->value=($tmp_ad)?$tmp_ad->get_parameter('text'):"";
- $aArticle[$i]['desc']=$text->input();
+ $text->javascript=' onchange="clean_tva('.$i.');compute_ledger('.$i.')"';
+ $text->name="e_march".$i."_label";
+ $text->size=40;
+ $text->value=($tmp_ad)?$tmp_ad->get_parameter('text'):"";
+ $aArticle[$i]['desc']=$text->input();
- $num->javascript=' onchange="format_number(this);clean_tva('.$i.');compute_ledger('.$i.')"';
- $num->name="e_march".$i."_price";
- $num->size=8;
- $num->value=($tmp_ad)?$tmp_ad->get_parameter('price_unit'):0;
- $aArticle[$i]['pu']=$num->input();
+ $num->javascript=' onchange="format_number(this);clean_tva('.$i.');compute_ledger('.$i.')"';
+ $num->name="e_march".$i."_price";
+ $num->size=8;
+ $num->value=($tmp_ad)?$tmp_ad->get_parameter('price_unit'):0;
+ $aArticle[$i]['pu']=$num->input();
- $num->name="e_quant".$i;
- $num->size=8;
- $num->value=($tmp_ad)?$tmp_ad->get_parameter('quantity'):0;
- $aArticle[$i]['quant']=$num->input();
+ $num->name="e_quant".$i;
+ $num->size=8;
+ $num->value=($tmp_ad)?$tmp_ad->get_parameter('quantity'):0;
+ $aArticle[$i]['quant']=$num->input();
- $itva->name='e_march'.$i.'_tva_id';
- $itva->value=($tmp_ad)?$tmp_ad->get_parameter('tva_id'):0;
- $itva->javascript=' onchange="format_number(this);clean_tva('.$i.');compute_ledger('.$i.')"';
- $itva->set_attribute('compute',$i);
+ $itva->name='e_march'.$i.'_tva_id';
+ $itva->value=($tmp_ad)?$tmp_ad->get_parameter('tva_id'):0;
+ $itva->javascript=' onchange="format_number(this);clean_tva('.$i.');compute_ledger('.$i.')"';
+ $itva->set_attribute('compute',$i);
- $aArticle[$i]['tvaid']=$itva->input();
+ $aArticle[$i]['tvaid']=$itva->input();
- $num->name="e_march".$i."_tva_amount";
- $num->value=($tmp_ad)?$tmp_ad->get_parameter('tva_amount'):0;
- $num->javascript=' onchange="compute_ledger('.$i.')"';
- $num->size=8;
- $aArticle[$i]['tva']=$num->input();
+ $num->name="e_march".$i."_tva_amount";
+ $num->value=($tmp_ad)?$tmp_ad->get_parameter('tva_amount'):0;
+ $num->javascript=' onchange="compute_ledger('.$i.')"';
+ $num->size=8;
+ $aArticle[$i]['tva']=$num->input();
- $num->name="tvac_march".$i;
- $num->value=($tmp_ad)?$tmp_ad->get_parameter('total'):0;
- $num->size=8;
- $aArticle[$i]['tvac']=$num->input();
+ $num->name="tvac_march".$i;
+ $num->value=($tmp_ad)?$tmp_ad->get_parameter('total'):0;
+ $num->size=8;
+ $aArticle[$i]['tvac']=$num->input();
- $aArticle[$i]['hidden_htva']=HtmlInput::hidden('htva_march'.$i,0);
- $aArticle[$i]['hidden_tva']=HtmlInput::hidden('tva_march'.$i,0);
- $aArticle[$i]['ad_id']= ($tmp_ad)?HtmlInput::hidden('ad_id'.$i,$tmp_ad->get_parameter('id')):HtmlInput::hidden('ad_id'.$i,0);
+ $aArticle[$i]['hidden_htva']=HtmlInput::hidden('htva_march'.$i,0);
+ $aArticle[$i]['hidden_tva']=HtmlInput::hidden('tva_march'.$i,0);
+ $aArticle[$i]['ad_id']= ($tmp_ad)?HtmlInput::hidden('ad_id'.$i,$tmp_ad->get_parameter('id')):HtmlInput::hidden('ad_id'.$i,0);
- }
- /* Add the javascript */
- $r.=JS_INFOBULLE;
- $r.=JS_LEDGER;
- $r.=JS_SHOW_TVA;
- $r.=JS_TVA;
- $r.=JS_AJAX_FICHE;
+ }
+ /* Add the javascript */
+ $r.=JS_INFOBULLE;
+ $r.=JS_LEDGER;
+ $r.=JS_SHOW_TVA;
+ $r.=JS_TVA;
+ $r.=JS_AJAX_FICHE;
- /* Add the needed hidden values */
- $r.=dossier::hidden();
+ /* Add the needed hidden values */
+ $r.=dossier::hidden();
- /* add the number of item */
- $Hid=new IHidden();
- $r.=$Hid->input("nb_item",MAX_ARTICLE);
+ /* add the number of item */
+ $Hid=new IHidden();
+ $r.=$Hid->input("nb_item",MAX_ARTICLE);
- /* get template */
- ob_start();
- require_once ('template/detail-action.php');
- $content=ob_get_contents();
- ob_end_clean();
- $r.=$content;
+ /* get template */
+ ob_start();
+ require_once ('template/detail-action.php');
+ $content=ob_get_contents();
+ ob_end_clean();
+ $r.=$content;
- //hidden
- $r.="";
- $r.=$h2->input();
- $r.=$h_agrefid->input("ag_ref_ag_id",$this->ag_ref_ag_id);
- $r.=$h_ag_id->input('ag_id',$this->ag_id);
- $hidden2=new IHidden();
- $r.=$hidden2->input('f_id_dest',$this->f_id_dest);
- $r.="
";
+ //hidden
+ $r.="";
+ $r.=$h2->input();
+ $r.=$h_agrefid->input("ag_ref_ag_id",$this->ag_ref_ag_id);
+ $r.=$h_ag_id->input('ag_id',$this->ag_id);
+ $hidden2=new IHidden();
+ $r.=$hidden2->input('f_id_dest',$this->f_id_dest);
+ $r.="
";
+
+ // show the list of the concern operation
+ if ( $this->db->count_sql('select * from action_gestion where ag_ref_ag_id!=0 and ag_ref_ag_id='.$this->ag_id.
+ " limit 2") > 0 )
+ {
+ $sql=sprintf(" and ag_id in (select action_get_tree from comptaproc.action_get_tree(%s)) ",$this->ag_id);
+ $r.=$this->myList($p_base,"",$sql);
+ }
+ return $r;
- // show the list of the concern operation
- if ( $this->db->count_sql('select * from action_gestion where ag_ref_ag_id!=0 and ag_ref_ag_id='.$this->ag_id.
- " limit 2") > 0 ) {
- $sql=sprintf(" and ag_id in (select action_get_tree from comptaproc.action_get_tree(%s)) ",$this->ag_id);
- $r.=$this->myList($p_base,"",$sql);
- }
- return $r;
-
}
- //----------------------------------------------------------------------
- /*!\brief This function shows the detail of an action thanks the ag_id
- */
- function get()
+ //----------------------------------------------------------------------
+ /*!\brief This function shows the detail of an action thanks the ag_id
+ */
+ function get()
{
- $sql="select ag_id, ag_comment,to_char (ag_timestamp,'DD-MM-YYYY') as ag_timestamp,".
- " f_id_dest,ag_title,ag_comment,ag_ref,d_id,ag_type,ag_state, ".
- " ag_ref_ag_id, ag_dest, ag_hour, ag_priority, ag_cal,ag_contact ".
- " from action_gestion left join document using (ag_id) where ag_id=".$this->ag_id;
- $r=$this->db->exec_sql($sql);
- $row=Database::fetch_all($r);
- if ( $row==false) return;
- $this->ag_comment=$row[0]['ag_comment'];
- $this->ag_timestamp=$row[0]['ag_timestamp'];
- $this->ag_contact=$row[0]['ag_contact'];
- $this->f_id_dest=$row[0]['f_id_dest'];
- $this->ag_title=$row[0]['ag_title'];
- $this->ag_type=$row[0]['ag_type'];
- $this->ag_ref=$row[0]['ag_ref'];
- $this->ag_state=$row[0]['ag_state'];
- $this->ag_ref_ag_id=$row[0]['ag_ref_ag_id'];
- $this->d_id=$row[0]['d_id'];
- $this->ag_dest=$row[0]['ag_dest'];
- $this->ag_hour=$row[0]['ag_hour'];
- $this->ag_priority=$row[0]['ag_priority'];
- $this->ag_cal=$row[0]['ag_cal'];
+ $sql="select ag_id, ag_comment,to_char (ag_timestamp,'DD-MM-YYYY') as ag_timestamp,".
+ " f_id_dest,ag_title,ag_comment,ag_ref,d_id,ag_type,ag_state, ".
+ " ag_ref_ag_id, ag_dest, ag_hour, ag_priority, ag_cal,ag_contact ".
+ " from action_gestion left join document using (ag_id) where ag_id=".$this->ag_id;
+ $r=$this->db->exec_sql($sql);
+ $row=Database::fetch_all($r);
+ if ( $row==false) return;
+ $this->ag_comment=$row[0]['ag_comment'];
+ $this->ag_timestamp=$row[0]['ag_timestamp'];
+ $this->ag_contact=$row[0]['ag_contact'];
+ $this->f_id_dest=$row[0]['f_id_dest'];
+ $this->ag_title=$row[0]['ag_title'];
+ $this->ag_type=$row[0]['ag_type'];
+ $this->ag_ref=$row[0]['ag_ref'];
+ $this->ag_state=$row[0]['ag_state'];
+ $this->ag_ref_ag_id=$row[0]['ag_ref_ag_id'];
+ $this->d_id=$row[0]['d_id'];
+ $this->ag_dest=$row[0]['ag_dest'];
+ $this->ag_hour=$row[0]['ag_hour'];
+ $this->ag_priority=$row[0]['ag_priority'];
+ $this->ag_cal=$row[0]['ag_cal'];
- $action_detail=new Action_Detail($this->db);
- $action_detail->set_parameter('ag_id',$this->ag_id);
- $this->aAction_detail=$action_detail->load_all();
+ $action_detail=new Action_Detail($this->db);
+ $action_detail->set_parameter('ag_id',$this->ag_id);
+ $this->aAction_detail=$action_detail->load_all();
- // if there is no document set 0 to d_id
- if ( $this->d_id == "" )
- $this->d_id=0;
- // if there is a document fill the object
- if ($this->d_id != 0 )
- {
- $this->state=$row['0']['ag_state'];
- $this->ag_state=$row[0]['ag_state'];
- }
- $this->dt_id=$this->ag_type;
- $aexp=new Fiche($this->db,$this->f_id_dest);
- $this->qcode_dest=$aexp->strAttribut(ATTR_DEF_QUICKCODE);
-
- }
-
-/*!
- * \brief Save the document and propose to save the generated document or
- * to upload one, the data are included except the file. Temporary the generated
- * document is save
- *
- * \return
- */
- function save()
- {
-
- // Get The sequence id,
- $seq_name="seq_doc_type_".$this->dt_id;
- $str_file="";
- $add_file='';
-
- // f_id exp
- $exp=new Fiche($this->db);
- $exp->get_by_qcode($this->qcode_dest);
-
- $contact=new Fiche($this->db);
- $contact->get_by_qcode($this->ag_contact);
-
- if ( trim($this->ag_title) == "")
- {
- $doc_mod=new document_type($this->db);
- $doc_mod->dt_id=$this->dt_id;
- $doc_mod->get();
- $this->ag_title=$doc_mod->dt_value;
- }
- $this->ag_id=$this->db->get_next_seq('action_gestion_ag_id_seq');
-
- // Create the reference
- $ref=$this->dt_id.'/'.$this->ag_id;
- $this->ag_ref=$ref;
- if ( $this->ag_cal=='on')
- $ag_cal='C';
- else
- $ag_cal='I';
- $this->ag_ref_ag_id=(strlen(trim($this->ag_ref_ag_id))==0)?0:$this->ag_ref_ag_id;
- // save into the database
- $sql="insert into action_gestion".
- "(ag_id,ag_timestamp,ag_type,ag_title,f_id_dest,ag_comment,ag_ref,ag_ref_ag_id, ag_dest, ".
- " ag_hour, ag_priority,ag_cal,ag_owner,ag_contact,ag_state) ".
- " values ($1,to_date($2,'DD-MM-YYYY'),$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15)";
- $this->db->exec_sql($sql,array($this->ag_id, /* 1 */
- $this->ag_timestamp, /* 2 */
- $this->dt_id, /* 3 */
- $this->ag_title, /* 4 */
- $exp->id, /* 5 */
- $this->ag_comment, /* 6 */
- $ref, /* 7 */
- $this->ag_ref_ag_id, /* 8 */
- $this->ag_dest, /* 9 */
- $this->ag_hour, /* 10 */
- $this->ag_priority, /* 11 */
- $ag_cal, /* 12 */
- $_SESSION['g_user'], /* 13 */
- $contact->id, /* 14 */
- $this->ag_state /* 15 */
- )
- );
-
- /* insert also the details */
- for ( $i = 0; $i < MAX_ARTICLE;$i++) {
- $act=new Action_Detail($this->db);
- $act->from_array($_POST,$i);
- $act->ag_id=$this->ag_id;
- $act->save();
- }
-
- /* Upload the documents */
- $doc=new Document($this->db);
- $doc->Upload($this->ag_id);
- }
-/*! myList($p_filter="")
- * \brief Show list of action by default if sorted on date
- *\param $p_base base url with p_action...
- * \param $p_filter filters on the document_type
- * \param $p_search must a valid sql command ( ex 'and ag_title like upper('%hjkh%'))
- * \return string containing html code
- */
- function myList($p_base,$p_filter="",$p_search="")
- {
- $str_dossier=dossier::get();
- // for the sort
- $sort="";
- $image_asc='';
- $image_desc='';
- $image_sel_desc='';
- $image_sel_asc='';
- $url=CleanUrl();
- $url=$str_dossier.'&'.$p_base;
-
- $sort_date=''.$image_asc.' '.
- 'Date'.
- ''.$image_desc.' ';
- $sort_exp=''.$image_asc.' '.
- 'Expéditeur'.
- ''.$image_desc.' ';
- $sort_titre=''.$image_asc.' '.
- 'Titre'.
- ''.$image_desc.' ';
- $sort_concerne=''.$image_asc.' '.
- 'Concerne'.
- ''.$image_desc.' ';
- $sort_reference=''.$image_asc.' '.
- 'Référence'.
- ''.$image_desc.' ';
-
- if ( isset($_GET['s'])){
- switch ($_GET['s']) {
- case "date_a":
- $sort=" ag_timestamp asc";
- $sort_date=''.$image_sel_asc.''.
- 'Date'.
- ''.$image_desc.' ';
- break;
-
- case "date_d":
- $sort=" ag_timestamp desc";
- $sort_date=''.$image_asc.' '.
- 'Date'.
- $image_sel_desc.' ';
- break;
-
- case "exp":
- $sort_exp=''.$image_sel_asc.''.
- 'Expéditeur'.
- ''.$image_asc.' ';
- $sort=" f_id_dest asc";
- break;
-
- case "exp_d":
- $sort_exp=''.$image_asc.' '.
- 'Expéditeur'.
- $image_sel_desc.' ';
-
- $sort=" f_id_dest desc";
- break;
-
- case "ti":
- $sort_titre=''.$image_sel_asc.
- 'Titre'.
- ''.$image_desc.' ';
-
- $sort=" ag_title asc";
- break;
- case "ti_d":
- $sort_titre=''.$image_asc.' '.
- 'Titre'.
- $image_sel_desc.' ';
-
- $sort=" ag_title desc";
- break;
-
- case "conc":
- $sort_concerne=''.$image_sel_asc.
- 'Concerne'.
- ''.$image_desc.' ';
-
- $sort=" ag_ref_ag_id asc";
- break;
- case "conc_d":
- $sort_concerne=''.$image_asc.' '.
- 'Concerne'.
- $image_sel_desc.' ';
-
- $sort=" ag_ref_ag_id desc";
- break;
-
- case "ref":
- $sort_reference=''.$image_sel_asc.
- 'Référence'.
- ''.$image_desc.' ';
-
- $sort=" ag_ref ";
- break;
-
- case "ref_d":
- $sort_reference=''.$image_asc.' '.
- 'Référence'.
- $image_sel_desc.' ';
-
- $sort=" ag_ref desc";
- break;
-
-
- }
-
- } else {
- $sort=" ag_timestamp desc";
- $sort_date=''.$image_asc.' '.
- 'Date'.
- $image_sel_desc.' ';
- }
-
- $sort=" order by ".$sort;
-
- if ( strlen(trim($p_filter)) != 0 )
- $p_filter_doc=" dt_id in ( $p_filter )";
- else
- $p_filter_doc=" 1=1 ";
-
- $sql="
- select ag_id,to_char(ag_timestamp,'DD-MM-YYYY') as my_date,ag_ref_ag_id,f_id_dest".
- ",ag_title,md_type,dt_value,ag_ref, ag_priority
- from action_gestion
- left outer join document_modele on (ag_type=md_type)
- join document_type on (ag_type=dt_id)
- where $p_filter_doc $p_search $sort";
- $max_line=$this->db->count_sql($sql);
- $step=$_SESSION['g_pagesize'];
- $page=(isset($_GET['offset']))?$_GET['page']:1;
- $offset=(isset($_GET['offset']))?Database::escape_string($_GET['offset']):0;
- if ( $step != -1 ) $limit=" LIMIT $step OFFSET $offset ";
- else $limit='';
- $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
-
- $Res=$this->db->exec_sql($sql.$limit);
- $a_row=Database::fetch_all($Res);
-
- $r="";
- $r.=$bar;
- $r.='";
-
- $r.=$bar;
- //$r.="";
- return $r;
- }
- //----------------------------------------------------------------------
- /*!\brief Update the data into the database
- *
- * \return true on success otherwise false
- */
- function Update()
- {
- // if ag_id == 0 nothing to do
- if ( $this->ag_id == 0 ) return ;
-
- // retrieve customer
- // f_id
-
- if ( trim($this->qcode_dest) =="" )
- {
- // internal document
- $this->f_id_dest=0; // internal document
- }
- else
- {
- $tiers=new Fiche($this->db);
- if ( $tiers->get_by_qcode($this->qcode_dest) == -1 ) // Error we cannot retrieve this qcode
- return false;
- else
- $this->f_id_dest=$tiers->id;
-
- }
- $contact=new Fiche($this->db);
- if ( $contact->get_by_qcode($this->ag_contact) == -1 )
- $contact->id=0;
-
-
- $ref=$this->dt_id.'/'.$this->ag_id;
- if ( $this->ag_cal == 'on') $ag_cal='C'; else $ag_cal='I';
- $this->ag_ref=$ref;
- $this->db->exec_sql("update action_gestion set ag_comment=$1,".
- " ag_timestamp=to_date($2,'DD.MM.YYYY'),".
- " ag_title=$3,".
- " ag_type=$4, ".
- " f_id_dest=$5, ".
- " ag_ref_ag_id=$6 ,".
- "ag_state=$7,".
- " ag_hour = $9 ,".
- " ag_priority = $10 ,".
- " ag_dest = $11 , ".
- " ag_cal = $12 ,".
- " ag_contact = $13 ".
- " where ag_id = $8",
- array ( $this->ag_comment, /* 1 */
- $this->ag_timestamp, /* 2 */
- $this->ag_title, /* 3 */
- $this->dt_id, /* 4 */
- $this->f_id_dest, /* 5 */
- $this->ag_ref_ag_id, /* 6 */
- $this->ag_state, /* 7 */
- $this->ag_id, /* 8 */
- $this->ag_hour, /* 9 */
- $this->ag_priority, /* 10 */
- $this->ag_dest, /* 11 */
- $ag_cal, /* 12 */
- $contact->id /* 13 */
- ));
- // Upload documents
- $doc=new Document($this->db);
- $doc->Upload($this->ag_id);
-
- /* save action details */
- for ( $i = 0; $i < MAX_ARTICLE;$i++) {
- $act=new Action_Detail($this->db);
- $act->from_array($_POST,$i);
- $act->save();
- }
- return true;
+ // if there is no document set 0 to d_id
+ if ( $this->d_id == "" )
+ $this->d_id=0;
+ // if there is a document fill the object
+ if ($this->d_id != 0 )
+ {
+ $this->state=$row['0']['ag_state'];
+ $this->ag_state=$row[0]['ag_state'];
+ }
+ $this->dt_id=$this->ag_type;
+ $aexp=new Fiche($this->db,$this->f_id_dest);
+ $this->qcode_dest=$aexp->strAttribut(ATTR_DEF_QUICKCODE);
}
- /*!\brief generate the document and add it to the action
- * \param md_id is the id of the document_modele
- */
- function generate_document($md_id) {
- $doc=new Document($this->db);
- $mod=new Document_Modele($this->db,$md_id);
- $mod->load();
- $doc->f_id=$this->f_id_dest;
- $doc->md_id=$md_id;
- $doc->ag_id=$this->ag_id;
- $doc->Generate();
- }
- /*!\brief put an array in the variable member, the indice
- * is the member name
- *\param $p_array to parse
- *\return nothing
- */
- function fromArray($p_array) {
- $this->ag_id=(isset($p_array['ag_id']))?$p_array['ag_id']:"";
- $this->qcode_dest=(isset($p_array['qcode_dest']))?$p_array['qcode_dest']:"";
- $this->f_id_dest=(isset($p_array['f_id_dest']))?$p_array['f_id_dest']:0;
- $this->ag_ref_ag_id=(isset($p_array['ag_ref_ag_id']))?$p_array['ag_ref_ag_id']:0;
- $this->ag_timestamp=(isset($p_array['ag_timestamp']))?$p_array['ag_timestamp']:date('d-m-Y');
- $this->qcode_dest=(isset($p_array['qcode_dest']))?$p_array['qcode_dest']:"";
- $this->dt_id=(isset($p_array['dt_id']))?$p_array['dt_id']:"";
- $this->ag_state=(isset($p_array['ag_state']))?$p_array['ag_state']:2;
- $this->ag_ref=(isset($p_array['ag_ref']))?$p_array['ag_ref']:"";
- $this->ag_title=(isset($p_array['ag_title']))?$p_array['ag_title']:"";
- $this->ag_hour=(isset($p_array['ag_hour']))?$p_array['ag_hour']:"";
- $this->ag_dest=(isset($p_array['ag_dest']))?$p_array['ag_dest']:"";
- $this->ag_priority=(isset($p_array['ag_priority']))?$p_array['ag_priority']:2;
- $this->ag_cal=(isset($p_array['ag_cal']))?$p_array['ag_cal']:"";
- $this->ag_contact=(isset($p_array['ag_contact']))?$p_array['ag_contact']:"";
- $this->ag_comment=(isset($p_array['ag_comment']))?$p_array['ag_comment']:"";
+ /*!
+ * \brief Save the document and propose to save the generated document or
+ * to upload one, the data are included except the file. Temporary the generated
+ * document is save
+ *
+ * \return
+ */
+ function save()
+ {
- }
- /*!\brief remove the action
- *
- */
- function remove()
- {
- $this->get();
- // remove the key
- $sql="delete from action_gestion where ag_id=$1";
- $this->db->exec_sql($sql,array($this->ag_id));
-
- // remove the ref of the depending action
- $sql="update action_gestion set ag_ref_ag_id=0 where ag_ref_ag_id=$1";
- $this->db->exec_sql($sql,array($this->ag_id));
+ // Get The sequence id,
+ $seq_name="seq_doc_type_".$this->dt_id;
+ $str_file="";
+ $add_file='';
- /* check the number of attached document */
- $doc=new Document($this->db);
- $aDoc=$doc->get_all($this->ag_id);
- if ( ! empty ($aDoc)) {
- // if there are documents
- for ($i=0;$i remove();
- }
+ // f_id exp
+ $exp=new Fiche($this->db);
+ $exp->get_by_qcode($this->qcode_dest);
+
+ $contact=new Fiche($this->db);
+ $contact->get_by_qcode($this->ag_contact);
+
+ if ( trim($this->ag_title) == "")
+ {
+ $doc_mod=new document_type($this->db);
+ $doc_mod->dt_id=$this->dt_id;
+ $doc_mod->get();
+ $this->ag_title=$doc_mod->dt_value;
+ }
+ $this->ag_id=$this->db->get_next_seq('action_gestion_ag_id_seq');
+
+ // Create the reference
+ $ref=$this->dt_id.'/'.$this->ag_id;
+ $this->ag_ref=$ref;
+ if ( $this->ag_cal=='on')
+ $ag_cal='C';
+ else
+ $ag_cal='I';
+ $this->ag_ref_ag_id=(strlen(trim($this->ag_ref_ag_id))==0)?0:$this->ag_ref_ag_id;
+ // save into the database
+ $sql="insert into action_gestion".
+ "(ag_id,ag_timestamp,ag_type,ag_title,f_id_dest,ag_comment,ag_ref,ag_ref_ag_id, ag_dest, ".
+ " ag_hour, ag_priority,ag_cal,ag_owner,ag_contact,ag_state) ".
+ " values ($1,to_date($2,'DD-MM-YYYY'),$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15)";
+ $this->db->exec_sql($sql,array($this->ag_id, /* 1 */
+ $this->ag_timestamp, /* 2 */
+ $this->dt_id, /* 3 */
+ $this->ag_title, /* 4 */
+ $exp->id, /* 5 */
+ $this->ag_comment, /* 6 */
+ $ref, /* 7 */
+ $this->ag_ref_ag_id, /* 8 */
+ $this->ag_dest, /* 9 */
+ $this->ag_hour, /* 10 */
+ $this->ag_priority, /* 11 */
+ $ag_cal, /* 12 */
+ $_SESSION['g_user'], /* 13 */
+ $contact->id, /* 14 */
+ $this->ag_state /* 15 */
+ )
+ );
+
+ /* insert also the details */
+ for ( $i = 0; $i < MAX_ARTICLE;$i++)
+ {
+ $act=new Action_Detail($this->db);
+ $act->from_array($_POST,$i);
+ $act->ag_id=$this->ag_id;
+ $act->save();
+ }
+
+ /* Upload the documents */
+ $doc=new Document($this->db);
+ $doc->Upload($this->ag_id);
+ }
+ /*! myList($p_filter="")
+ * \brief Show list of action by default if sorted on date
+ *\param $p_base base url with p_action...
+ * \param $p_filter filters on the document_type
+ * \param $p_search must a valid sql command ( ex 'and ag_title like upper('%hjkh%'))
+ * \return string containing html code
+ */
+ function myList($p_base,$p_filter="",$p_search="")
+ {
+ $str_dossier=dossier::get();
+ // for the sort
+ $sort="";
+ $image_asc='';
+ $image_desc='';
+ $image_sel_desc='';
+ $image_sel_asc='';
+ $url=CleanUrl();
+ $url=$str_dossier.'&'.$p_base;
+
+ $sort_date=''.$image_asc.' '.
+ 'Date'.
+ ''.$image_desc.' ';
+ $sort_exp=''.$image_asc.' '.
+ 'Expéditeur'.
+ ''.$image_desc.' ';
+ $sort_titre=''.$image_asc.' '.
+ 'Titre'.
+ ''.$image_desc.' ';
+ $sort_concerne=''.$image_asc.' '.
+ 'Concerne'.
+ ''.$image_desc.' ';
+ $sort_reference=''.$image_asc.' '.
+ 'Référence'.
+ ''.$image_desc.' ';
+
+ if ( isset($_GET['s']))
+ {
+ switch ($_GET['s'])
+ {
+ case "date_a":
+ $sort=" ag_timestamp asc";
+ $sort_date=''.$image_sel_asc.''.
+ 'Date'.
+ ''.$image_desc.' ';
+ break;
+
+ case "date_d":
+ $sort=" ag_timestamp desc";
+ $sort_date=''.$image_asc.' '.
+ 'Date'.
+ $image_sel_desc.' ';
+ break;
+
+ case "exp":
+ $sort_exp=''.$image_sel_asc.''.
+ 'Expéditeur'.
+ ''.$image_asc.' ';
+ $sort=" f_id_dest asc";
+ break;
+
+ case "exp_d":
+ $sort_exp=''.$image_asc.' '.
+ 'Expéditeur'.
+ $image_sel_desc.' ';
+
+ $sort=" f_id_dest desc";
+ break;
+
+ case "ti":
+ $sort_titre=''.$image_sel_asc.
+ 'Titre'.
+ ''.$image_desc.' ';
+
+ $sort=" ag_title asc";
+ break;
+ case "ti_d":
+ $sort_titre=''.$image_asc.' '.
+ 'Titre'.
+ $image_sel_desc.' ';
+
+ $sort=" ag_title desc";
+ break;
+
+ case "conc":
+ $sort_concerne=''.$image_sel_asc.
+ 'Concerne'.
+ ''.$image_desc.' ';
+
+ $sort=" ag_ref_ag_id asc";
+ break;
+ case "conc_d":
+ $sort_concerne=''.$image_asc.' '.
+ 'Concerne'.
+ $image_sel_desc.' ';
+
+ $sort=" ag_ref_ag_id desc";
+ break;
+
+ case "ref":
+ $sort_reference=''.$image_sel_asc.
+ 'Référence'.
+ ''.$image_desc.' ';
+
+ $sort=" ag_ref ";
+ break;
+
+ case "ref_d":
+ $sort_reference=''.$image_asc.' '.
+ 'Référence'.
+ $image_sel_desc.' ';
+
+ $sort=" ag_ref desc";
+ break;
+
+
+ }
+
+ }
+ else
+ {
+ $sort=" ag_timestamp desc";
+ $sort_date=''.$image_asc.' '.
+ 'Date'.
+ $image_sel_desc.' ';
+ }
+
+ $sort=" order by ".$sort;
+
+ if ( strlen(trim($p_filter)) != 0 )
+ $p_filter_doc=" dt_id in ( $p_filter )";
+ else
+ $p_filter_doc=" 1=1 ";
+
+ $sql="
+ select ag_id,to_char(ag_timestamp,'DD-MM-YYYY') as my_date,ag_ref_ag_id,f_id_dest".
+ ",ag_title,md_type,dt_value,ag_ref, ag_priority
+ from action_gestion
+ left outer join document_modele on (ag_type=md_type)
+ join document_type on (ag_type=dt_id)
+ where $p_filter_doc $p_search $sort";
+ $max_line=$this->db->count_sql($sql);
+ $step=$_SESSION['g_pagesize'];
+ $page=(isset($_GET['offset']))?$_GET['page']:1;
+ $offset=(isset($_GET['offset']))?Database::escape_string($_GET['offset']):0;
+ if ( $step != -1 ) $limit=" LIMIT $step OFFSET $offset ";
+ else $limit='';
+ $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
+
+ $Res=$this->db->exec_sql($sql.$limit);
+ $a_row=Database::fetch_all($Res);
+
+ $r="";
+ $r.=$bar;
+ $r.='";
+
+ $r.=$bar;
+ //$r.="";
+ return $r;
+ }
+ //----------------------------------------------------------------------
+ /*!\brief Update the data into the database
+ *
+ * \return true on success otherwise false
+ */
+ function Update()
+ {
+ // if ag_id == 0 nothing to do
+ if ( $this->ag_id == 0 ) return ;
+
+ // retrieve customer
+ // f_id
+
+ if ( trim($this->qcode_dest) =="" )
+ {
+ // internal document
+ $this->f_id_dest=0; // internal document
+ }
+ else
+ {
+ $tiers=new Fiche($this->db);
+ if ( $tiers->get_by_qcode($this->qcode_dest) == -1 ) // Error we cannot retrieve this qcode
+ return false;
+ else
+ $this->f_id_dest=$tiers->id;
+
+ }
+ $contact=new Fiche($this->db);
+ if ( $contact->get_by_qcode($this->ag_contact) == -1 )
+ $contact->id=0;
+
+
+ $ref=$this->dt_id.'/'.$this->ag_id;
+ if ( $this->ag_cal == 'on') $ag_cal='C';
+ else $ag_cal='I';
+ $this->ag_ref=$ref;
+ $this->db->exec_sql("update action_gestion set ag_comment=$1,".
+ " ag_timestamp=to_date($2,'DD.MM.YYYY'),".
+ " ag_title=$3,".
+ " ag_type=$4, ".
+ " f_id_dest=$5, ".
+ " ag_ref_ag_id=$6 ,".
+ "ag_state=$7,".
+ " ag_hour = $9 ,".
+ " ag_priority = $10 ,".
+ " ag_dest = $11 , ".
+ " ag_cal = $12 ,".
+ " ag_contact = $13 ".
+ " where ag_id = $8",
+ array ( $this->ag_comment, /* 1 */
+ $this->ag_timestamp, /* 2 */
+ $this->ag_title, /* 3 */
+ $this->dt_id, /* 4 */
+ $this->f_id_dest, /* 5 */
+ $this->ag_ref_ag_id, /* 6 */
+ $this->ag_state, /* 7 */
+ $this->ag_id, /* 8 */
+ $this->ag_hour, /* 9 */
+ $this->ag_priority, /* 10 */
+ $this->ag_dest, /* 11 */
+ $ag_cal, /* 12 */
+ $contact->id /* 13 */
+ ));
+ // Upload documents
+ $doc=new Document($this->db);
+ $doc->Upload($this->ag_id);
+
+ /* save action details */
+ for ( $i = 0; $i < MAX_ARTICLE;$i++)
+ {
+ $act=new Action_Detail($this->db);
+ $act->from_array($_POST,$i);
+ $act->save();
+ }
+ return true;
+
+ }
+
+ /*!\brief generate the document and add it to the action
+ * \param md_id is the id of the document_modele
+ */
+ function generate_document($md_id)
+ {
+ $doc=new Document($this->db);
+ $mod=new Document_Modele($this->db,$md_id);
+ $mod->load();
+ $doc->f_id=$this->f_id_dest;
+ $doc->md_id=$md_id;
+ $doc->ag_id=$this->ag_id;
+ $doc->Generate();
+ }
+ /*!\brief put an array in the variable member, the indice
+ * is the member name
+ *\param $p_array to parse
+ *\return nothing
+ */
+ function fromArray($p_array)
+ {
+ $this->ag_id=(isset($p_array['ag_id']))?$p_array['ag_id']:"";
+ $this->qcode_dest=(isset($p_array['qcode_dest']))?$p_array['qcode_dest']:"";
+ $this->f_id_dest=(isset($p_array['f_id_dest']))?$p_array['f_id_dest']:0;
+ $this->ag_ref_ag_id=(isset($p_array['ag_ref_ag_id']))?$p_array['ag_ref_ag_id']:0;
+ $this->ag_timestamp=(isset($p_array['ag_timestamp']))?$p_array['ag_timestamp']:date('d-m-Y');
+ $this->qcode_dest=(isset($p_array['qcode_dest']))?$p_array['qcode_dest']:"";
+ $this->dt_id=(isset($p_array['dt_id']))?$p_array['dt_id']:"";
+ $this->ag_state=(isset($p_array['ag_state']))?$p_array['ag_state']:2;
+ $this->ag_ref=(isset($p_array['ag_ref']))?$p_array['ag_ref']:"";
+ $this->ag_title=(isset($p_array['ag_title']))?$p_array['ag_title']:"";
+ $this->ag_hour=(isset($p_array['ag_hour']))?$p_array['ag_hour']:"";
+ $this->ag_dest=(isset($p_array['ag_dest']))?$p_array['ag_dest']:"";
+ $this->ag_priority=(isset($p_array['ag_priority']))?$p_array['ag_priority']:2;
+ $this->ag_cal=(isset($p_array['ag_cal']))?$p_array['ag_cal']:"";
+ $this->ag_contact=(isset($p_array['ag_contact']))?$p_array['ag_contact']:"";
+ $this->ag_comment=(isset($p_array['ag_comment']))?$p_array['ag_comment']:"";
+
+ }
+ /*!\brief remove the action
+ *
+ */
+ function remove()
+ {
+ $this->get();
+ // remove the key
+ $sql="delete from action_gestion where ag_id=$1";
+ $this->db->exec_sql($sql,array($this->ag_id));
+
+ // remove the ref of the depending action
+ $sql="update action_gestion set ag_ref_ag_id=0 where ag_ref_ag_id=$1";
+ $this->db->exec_sql($sql,array($this->ag_id));
+
+ /* check the number of attached document */
+ $doc=new Document($this->db);
+ $aDoc=$doc->get_all($this->ag_id);
+ if ( ! empty ($aDoc))
+ {
+ // if there are documents
+ for ($i=0;$i remove();
+ }
+ }
+ }
+ /*!\brief return the last p_limit operation into an array
+ *\param $p_limit is the max of operation to return
+ *\return $p_array of Action object
+ */
+ function get_last($p_limit)
+ {
+ $sql="select coalesce(vw_name,'Interne') as vw_name,ag_id,ag_title,ag_ref, dt_value,to_char(ag_timestamp,'DD.MM.YYYY') as ag_timestamp_fmt,ag_timestamp ".
+ " from action_gestion join document_type ".
+ " on (ag_type=dt_id) left join vw_fiche_attr on (f_id=f_id_dest) where ag_state in (2,3) order by ag_timestamp desc limit $p_limit";
+ $array=$this->db->get_array($sql);
+ return $array;
}
- }
- /*!\brief return the last p_limit operation into an array
- *\param $p_limit is the max of operation to return
- *\return $p_array of Action object
- */
- function get_last($p_limit) {
- $sql="select coalesce(vw_name,'Interne') as vw_name,ag_id,ag_title,ag_ref, dt_value,to_char(ag_timestamp,'DD.MM.YYYY') as ag_timestamp_fmt,ag_timestamp ".
- " from action_gestion join document_type ".
- " on (ag_type=dt_id) left join vw_fiche_attr on (f_id=f_id_dest) where ag_state in (2,3) order by ag_timestamp desc limit $p_limit";
- $array=$this->db->get_array($sql);
- return $array;
- }
}
diff --git a/include/class_action_detail.php b/include/class_action_detail.php
index 4891d21f6..99e4550a4 100644
--- a/include/class_action_detail.php
+++ b/include/class_action_detail.php
@@ -41,180 +41,207 @@ require_once ('class_database.php');
*/
class Action_Detail
{
- private static $variable=array(
- "id"=>"ad_id",
- "qcode"=>"f_id",
- "text"=>"ad_text",
- "price_unit"=>"ad_pu",
- "quantity"=>"ad_quant",
- "tva_id"=>"ad_tva_id",
- "tva_amount"=>"ad_tva_amount",
- "total"=>"ad_total_amount",
- "ag_id"=>"ag_id"
- );
- function __construct ($p_cn,$p_id=0) {
- $this->db=$p_cn;
- $this->ad_id=$p_id;
- }
- public function get_parameter($p_string) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- return $this->$idx;
+ private static $variable=array(
+ "id"=>"ad_id",
+ "qcode"=>"f_id",
+ "text"=>"ad_text",
+ "price_unit"=>"ad_pu",
+ "quantity"=>"ad_quant",
+ "tva_id"=>"ad_tva_id",
+ "tva_amount"=>"ad_tva_amount",
+ "total"=>"ad_total_amount",
+ "ag_id"=>"ag_id"
+ );
+ function __construct ($p_cn,$p_id=0)
+ {
+ $this->db=$p_cn;
+ $this->ad_id=$p_id;
}
- else
- exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
- }
- public function set_parameter($p_string,$p_value) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- $this->$idx=$p_value;
+ public function get_parameter($p_string)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ return $this->$idx;
+ }
+ else
+ exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
}
- else
- exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
-
-
- }
- public function get_info() { return var_export(self::$variable,true); }
- public function verify() {
- // Verify that the elt we want to add is correct
- return 0;
- }
- public function save() {
- if ( $this->ad_id == 0 )
- $this->insert();
- else
- $this->update();
- }
-
- public function insert() {
- if ( $this->verify() != 0 ) return;
- $sql='INSERT INTO action_detail('.
- ' f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,'.
- ' ad_total_amount, ag_id)'.
- ' VALUES ($1, $2, $3, $4,$5,$6,$7,$8) returning ad_id';
- $this->ad_id=$this->db->get_value($sql,array(
- $this->f_id,
- $this->ad_text,
- $this->ad_pu,
- $this->ad_quant,
- $this->ad_tva_id,
- $this->ad_tva_amount,
- $this->ad_total_amount,
- $this->ag_id
- )
- );
-
- }
-
- public function update() {
- if ( $this->verify() != 0 ) return;
-
- $sql='UPDATE action_detail '.
- ' SET f_id=$1, ad_text=$2, ad_pu=$3, ad_quant=$4, ad_tva_id=$5,'.
- ' ad_tva_amount=$6, ad_total_amount=$7, ag_id=$8'.
- ' WHERE ad_id=$9';
- $this->id=$this->db->exec_sql($sql,array(
- $this->f_id,
- $this->ad_text,
- $this->ad_pu,
- $this->ad_quant,
- $this->ad_tva_id,
- $this->ad_tva_amount,
- $this->ad_total_amount,
- $this->ag_id,
- $this->ad_id
- )
- );
+ public function set_parameter($p_string,$p_value)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ $this->$idx=$p_value;
+ }
+ else
+ exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
- }
- /*!\brief retrieve all the details of an Action
- *\return array of Action_Detail
- *\see Action::get
- */
- public function load_all() {
- $sql="SELECT ad_id, f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,
- ad_total_amount, ag_id FROM action_detail ".
- " where ag_id=$1";
- $res=$this->db->get_array(
- $sql,
- array($this->ag_id)
- );
- if ( $this->db->count() == 0 ) return;
- $aRet=array();
- for($i=0;$idb);
- $row=$res[$i];
- foreach ($row as $idx=>$value) { $a->$idx=$value; }
- $aRet[$i]=clone $a;
}
- return $aRet;
- }
-
- public function load() {
- $sql="SELECT ad_id, f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,
- ad_total_amount, ag_id FROM action_detail".
- " where ad_id=$1";
-
- $res=$this->db->get_array($this->db,
- $sql,
- array($this->ad_id)
- );
- if ( $this->db->count() == 0 ) return;
- $row=$res[0];
- foreach ($row as $idx=>$value) { $this->$idx=$value; }
- }
- public function delete() {
- exit(__FILE__.__LINE__.' : Non implémenté');
- }
- /*!\brief Fill an Action_Detail Object with the data contained in an array
- *\param $array
- - [ad_id7] => ad_id
- - [e_march7] => f_id
- - [e_march7_label] => ad_text
- - [e_march7_price] => ad_pu
- - [e_quant7] => ad_quant
- - [e_march7_tva_id] => ad_tva_id
- - [e_march7_tva_amount] => ad_tva_amount
- - [tvac_march7] => ad_total_amount
- - [ag_id] => ag_id
- *\param $idx is the idx (example 7)
- *\note */
- public function from_array($array,$idx) {
- $row=$array;
- $this->ad_id=(isset($row['ad_id'.$idx]))?$row['ad_id'.$idx]:0;
-
- $qcode=(isset($row['e_march'.$idx]))?$row['e_march'.$idx]:"";
- if (trim($qcode)=='') {
- $this->f_id=0;
- } else {
- $tmp=new Fiche($this->db);
- $tmp->get_by_qcode($qcode,false);
- $this->f_id=$tmp->id;
+ public function get_info()
+ {
+ return var_export(self::$variable,true);
}
- $this->ad_text=(isset($row['e_march'.$idx.'_label']))?$row['e_march'.$idx.'_label']:"";
- $this->ad_pu=(isset($row['e_march'.$idx.'_price']))?$row['e_march'.$idx.'_price']:0;
- $this->ad_quant=(isset($row['e_quant'.$idx]))?$row['e_quant'.$idx]:0;
- $this->ad_tva_id=(isset($row['e_march'.$idx.'_tva_id']))?$row['e_march'.$idx.'_tva_id']:0;
- $this->ad_tva_amount=(isset($row['e_march'.$idx.'_tva_amount']))?$row['e_march'.$idx.'_tva_amount']:0;
- $this->ad_total_amount=(isset($row['tvac_march'.$idx]))?$row['tvac_march'.$idx]:0;
- $this->ag_id=(isset($array['ag_id']))?$array['ag_id']:0;
- /* protect numeric */
- if (trim($this->ad_pu)=="" || isNumber($this->ad_pu)==0) $this->ad_pu=0;
- if (trim($this->ad_quant)=="" || isNumber($this->ad_quant)==0) $this->ad_quant=0;
- if (trim($this->ad_tva_amount)==""||isNumber($this->ad_tva_amount)==0) $this->ad_tva_amount=0;
- if (trim($this->ad_total_amount)==""||isNumber($this->ad_total_amount)==0) $this->ad_total_amount=0;
- if (trim($this->ad_tva_id)=="" || isNumber($this->ad_tva_id)==0) $this->ad_tva_id=0;
- }
- /*!\brief
- *\param
- *\return
- *\note
- *\see
- */
- static function test_me() {
- }
-
+ public function verify()
+ {
+ // Verify that the elt we want to add is correct
+ return 0;
+ }
+ public function save()
+ {
+ if ( $this->ad_id == 0 )
+ $this->insert();
+ else
+ $this->update();
+ }
+
+ public function insert()
+ {
+ if ( $this->verify() != 0 ) return;
+ $sql='INSERT INTO action_detail('.
+ ' f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,'.
+ ' ad_total_amount, ag_id)'.
+ ' VALUES ($1, $2, $3, $4,$5,$6,$7,$8) returning ad_id';
+ $this->ad_id=$this->db->get_value($sql,array(
+ $this->f_id,
+ $this->ad_text,
+ $this->ad_pu,
+ $this->ad_quant,
+ $this->ad_tva_id,
+ $this->ad_tva_amount,
+ $this->ad_total_amount,
+ $this->ag_id
+ )
+ );
+
+ }
+
+ public function update()
+ {
+ if ( $this->verify() != 0 ) return;
+
+ $sql='UPDATE action_detail '.
+ ' SET f_id=$1, ad_text=$2, ad_pu=$3, ad_quant=$4, ad_tva_id=$5,'.
+ ' ad_tva_amount=$6, ad_total_amount=$7, ag_id=$8'.
+ ' WHERE ad_id=$9';
+ $this->id=$this->db->exec_sql($sql,array(
+ $this->f_id,
+ $this->ad_text,
+ $this->ad_pu,
+ $this->ad_quant,
+ $this->ad_tva_id,
+ $this->ad_tva_amount,
+ $this->ad_total_amount,
+ $this->ag_id,
+ $this->ad_id
+ )
+ );
+
+
+ }
+ /*!\brief retrieve all the details of an Action
+ *\return array of Action_Detail
+ *\see Action::get
+ */
+ public function load_all()
+ {
+ $sql="SELECT ad_id, f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,
+ ad_total_amount, ag_id FROM action_detail ".
+ " where ag_id=$1";
+ $res=$this->db->get_array(
+ $sql,
+ array($this->ag_id)
+ );
+ if ( $this->db->count() == 0 ) return;
+ $aRet=array();
+ for($i=0;$idb);
+ $row=$res[$i];
+ foreach ($row as $idx=>$value)
+ {
+ $a->$idx=$value;
+ }
+ $aRet[$i]=clone $a;
+ }
+ return $aRet;
+ }
+
+ public function load()
+ {
+ $sql="SELECT ad_id, f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,
+ ad_total_amount, ag_id FROM action_detail".
+ " where ad_id=$1";
+
+ $res=$this->db->get_array($this->db,
+ $sql,
+ array($this->ad_id)
+ );
+ if ( $this->db->count() == 0 ) return;
+ $row=$res[0];
+ foreach ($row as $idx=>$value)
+ {
+ $this->$idx=$value;
+ }
+
+ }
+ public function delete()
+ {
+ exit(__FILE__.__LINE__.' : Non implémenté');
+ }
+ /*!\brief Fill an Action_Detail Object with the data contained in an array
+ *\param $array
+ - [ad_id7] => ad_id
+ - [e_march7] => f_id
+ - [e_march7_label] => ad_text
+ - [e_march7_price] => ad_pu
+ - [e_quant7] => ad_quant
+ - [e_march7_tva_id] => ad_tva_id
+ - [e_march7_tva_amount] => ad_tva_amount
+ - [tvac_march7] => ad_total_amount
+ - [ag_id] => ag_id
+ *\param $idx is the idx (example 7)
+ *\note */
+ public function from_array($array,$idx)
+ {
+ $row=$array;
+ $this->ad_id=(isset($row['ad_id'.$idx]))?$row['ad_id'.$idx]:0;
+
+ $qcode=(isset($row['e_march'.$idx]))?$row['e_march'.$idx]:"";
+ if (trim($qcode)=='')
+ {
+ $this->f_id=0;
+ }
+ else
+ {
+ $tmp=new Fiche($this->db);
+ $tmp->get_by_qcode($qcode,false);
+ $this->f_id=$tmp->id;
+ }
+ $this->ad_text=(isset($row['e_march'.$idx.'_label']))?$row['e_march'.$idx.'_label']:"";
+ $this->ad_pu=(isset($row['e_march'.$idx.'_price']))?$row['e_march'.$idx.'_price']:0;
+ $this->ad_quant=(isset($row['e_quant'.$idx]))?$row['e_quant'.$idx]:0;
+ $this->ad_tva_id=(isset($row['e_march'.$idx.'_tva_id']))?$row['e_march'.$idx.'_tva_id']:0;
+ $this->ad_tva_amount=(isset($row['e_march'.$idx.'_tva_amount']))?$row['e_march'.$idx.'_tva_amount']:0;
+ $this->ad_total_amount=(isset($row['tvac_march'.$idx]))?$row['tvac_march'.$idx]:0;
+ $this->ag_id=(isset($array['ag_id']))?$array['ag_id']:0;
+ /* protect numeric */
+ if (trim($this->ad_pu)=="" || isNumber($this->ad_pu)==0) $this->ad_pu=0;
+ if (trim($this->ad_quant)=="" || isNumber($this->ad_quant)==0) $this->ad_quant=0;
+ if (trim($this->ad_tva_amount)==""||isNumber($this->ad_tva_amount)==0) $this->ad_tva_amount=0;
+ if (trim($this->ad_total_amount)==""||isNumber($this->ad_total_amount)==0) $this->ad_total_amount=0;
+ if (trim($this->ad_tva_id)=="" || isNumber($this->ad_tva_id)==0) $this->ad_tva_id=0;
+ }
+ /*!\brief
+ *\param
+ *\return
+ *\note
+ *\see
+ */
+ static function test_me()
+{}
+
}
/* test::test_me(); */
diff --git a/include/class_admin.php b/include/class_admin.php
index d1930af76..1f6cf4f28 100644
--- a/include/class_admin.php
+++ b/include/class_admin.php
@@ -1,4 +1,4 @@
-fiche_def_ref=FICHE_TYPE_ADM_TAX;
- parent::__construct($p_cn,$p_id) ;
- }
+ /*! \brief Constructor
+ /* only a db connection is needed */
+ function Admin($p_cn,$p_id=0)
+ {
+ $this->fiche_def_ref=FICHE_TYPE_ADM_TAX;
+ parent::__construct($p_cn,$p_id) ;
+ }
diff --git a/include/class_anc_account.php b/include/class_anc_account.php
index 0a1c0985c..4a8b7748f 100644
--- a/include/class_anc_account.php
+++ b/include/class_anc_account.php
@@ -36,299 +36,314 @@ require_once("class_anc_plan.php");
class Anc_Account
{
- var $id; /*!< $id is po_id */
- var $name; /*!< po_name */
- var $pa_id; /*!< pa_id fk to the plan_analytique(pa_id) */
- var $amount; /*!< po_amount just an amount */
- var $description; /*!< po_description description of the post */
- var $db; /*!< database connection*/
- var $ga_id; /*!< FK to the table groupe analytique */
- function Anc_Account($p_db,$p_id=0)
- {
- $this->db=$p_db;
- $this->id=$p_id;
- $this->ga_id=null;
- }
- /*! \brief retrieve data from the database and
- * fill the object
- * \param $p_where the where clause
- */
- private function fetch_from_db($p_where)
- {
- $sql="select po_id,
- po_name ,
- pa_id,
- po_amount,
- po_description,
- ga_id
- from poste_analytique
- where ".
- $p_where;
+ var $id; /*!< $id is po_id */
+ var $name; /*!< po_name */
+ var $pa_id; /*!< pa_id fk to the plan_analytique(pa_id) */
+ var $amount; /*!< po_amount just an amount */
+ var $description; /*!< po_description description of the post */
+ var $db; /*!< database connection*/
+ var $ga_id; /*!< FK to the table groupe analytique */
+ function Anc_Account($p_db,$p_id=0)
+ {
+ $this->db=$p_db;
+ $this->id=$p_id;
+ $this->ga_id=null;
+ }
+ /*! \brief retrieve data from the database and
+ * fill the object
+ * \param $p_where the where clause
+ */
+ private function fetch_from_db($p_where)
+ {
+ $sql="select po_id,
+ po_name ,
+ pa_id,
+ po_amount,
+ po_description,
+ ga_id
+ from poste_analytique
+ where ".
+ $p_where;
- $ret=$this->db->exec_sql($sql);
- if ( Database::num_row($ret) == 0 )return null;
- $line=Database::fetch_array($ret);
+ $ret=$this->db->exec_sql($sql);
+ if ( Database::num_row($ret) == 0 )return null;
+ $line=Database::fetch_array($ret);
- $this->id=$line['po_id'];
- $this->name=$line['po_name'];
- $this->pa_id=$line['pa_id'];
- $this->amount=$line['po_amount'];
- $this->description=$line['po_description'];
- $this->ga_id=$line['ga_id'];
+ $this->id=$line['po_id'];
+ $this->name=$line['po_name'];
+ $this->pa_id=$line['pa_id'];
+ $this->amount=$line['po_amount'];
+ $this->description=$line['po_description'];
+ $this->ga_id=$line['ga_id'];
- }
- function get_by_id()
- {
- $this->fetch_from_db("po_id=".$this->id);
- }
- /*!
- * \brief retrieve data thanks the name
- * \param $p_name name of the analytic account
- *
- */
- function get_by_name($p_name)
- {
- $p_name=FormatString($p_name);
- if ( $p_name == null )
- $p_name=$this->name;
+ }
+ function get_by_id()
+ {
+ $this->fetch_from_db("po_id=".$this->id);
+ }
+ /*!
+ * \brief retrieve data thanks the name
+ * \param $p_name name of the analytic account
+ *
+ */
+ function get_by_name($p_name)
+ {
+ $p_name=FormatString($p_name);
+ if ( $p_name == null )
+ $p_name=$this->name;
- $this->fetch_from_db("po_name='".$p_name."'");
- echo "id = ".$this->id;
- }
- function add()
- {
- $this->format_data();
- if ( strlen($this->name) == 0)
- return;
- if ( $this->ga_id == null || strlen(trim($this->ga_id)) == 0 )
- $ga_id="NULL";
- else
- $ga_id="'".$this->ga_id."'";
- $sql="insert into poste_analytique (
- po_name ,
- pa_id,
- po_amount,
- po_description,
- ga_id
- ) values ($1,$2,$3,$4,$5)";
+ $this->fetch_from_db("po_name='".$p_name."'");
+ echo "id = ".$this->id;
+ }
+ function add()
+ {
+ $this->format_data();
+ if ( strlen($this->name) == 0)
+ return;
+ if ( $this->ga_id == null || strlen(trim($this->ga_id)) == 0 )
+ $ga_id="NULL";
+ else
+ $ga_id="'".$this->ga_id."'";
+ $sql="insert into poste_analytique (
+ po_name ,
+ pa_id,
+ po_amount,
+ po_description,
+ ga_id
+ ) values ($1,$2,$3,$4,$5)";
- try {
- $this->db->exec_sql($sql,array($this->name,$this->pa_id,$this->amount,$this->description,$ga_id));
+ try
+ {
+ $this->db->exec_sql($sql,array($this->name,$this->pa_id,$this->amount,$this->description,$ga_id));
- } catch (Exception $e) {
- if ( DEBUG ) print_r($e);
- echo "Doublon : l'enregistrement n'est pas sauve
";
- }
+ }
+ catch (Exception $e)
+ {
+ if ( DEBUG ) print_r($e);
+ echo "Doublon : l'enregistrement n'est pas sauve
";
+ }
- }
- static function make_array_name($cn,$pa_id) {
- $a=$cn->make_array("select po_name,po_name from poste_analytique ".
- " where ".
- " pa_id =".$pa_id." order by po_name ");
- return $a;
- }
- function update()
- {
- $this->format_data();
- if ( strlen($this->name) == 0)
- return;
- $sql="update poste_analytique ".
- " set po_name=$1".
- " ,pa_id=$2".
- " ,po_amount=$3".
- " ,po_description=$4".
- " ,ga_id=$5".
- " where po_id=$6";
- try {
- $this->db->exec_sql($sql,array($this->name,$this->pa_id,$this->amount,
- $this->description,$this->ga_id,$this->id));
- } catch (Exception $e) {
- echo "Doublon : l'enregistrement n'est pas sauve
";
- }
+ }
+ static function make_array_name($cn,$pa_id)
+ {
+ $a=$cn->make_array("select po_name,po_name from poste_analytique ".
+ " where ".
+ " pa_id =".$pa_id." order by po_name ");
+ return $a;
+ }
+ function update()
+ {
+ $this->format_data();
+ if ( strlen($this->name) == 0)
+ return;
+ $sql="update poste_analytique ".
+ " set po_name=$1".
+ " ,pa_id=$2".
+ " ,po_amount=$3".
+ " ,po_description=$4".
+ " ,ga_id=$5".
+ " where po_id=$6";
+ try
+ {
+ $this->db->exec_sql($sql,array($this->name,$this->pa_id,$this->amount,
+ $this->description,$this->ga_id,$this->id));
+ }
+ catch (Exception $e)
+ {
+ echo "Doublon : l'enregistrement n'est pas sauve
";
+ }
- }
- private function format_data()
- {
+ }
+ private function format_data()
+ {
- $this->name=FormatString($this->name);
- $this->pa_id=FormatString($this->pa_id);
- $this->amount=FormatString($this->amount);
- if (strlen($this->amount) == 0 )
- $this->amount=0.0;
- if ( isNumber($this->amount) ==0 )
- $this->amount=0;
+ $this->name=FormatString($this->name);
+ $this->pa_id=FormatString($this->pa_id);
+ $this->amount=FormatString($this->amount);
+ if (strlen($this->amount) == 0 )
+ $this->amount=0.0;
+ if ( isNumber($this->amount) ==0 )
+ $this->amount=0;
- $this->description=FormatString($this->description);
- }
- function delete()
- {
- $sql="delete from poste_analytique where po_id=".$this->id;
- $this->db->exec_sql($sql);
- }
- /*! \brief return an array of object Poste_Analytique
- *
- */
- function get_list()
- {
- $sql="select po_id,
- po_name ,
- pa_id,
- po_amount,
- po_description,
- ga_id
- from poste_analytique ".
- " order by po_name";
+ $this->description=FormatString($this->description);
+ }
+ function delete()
+ {
+ $sql="delete from poste_analytique where po_id=".$this->id;
+ $this->db->exec_sql($sql);
+ }
+ /*! \brief return an array of object Poste_Analytique
+ *
+ */
+ function get_list()
+ {
+ $sql="select po_id,
+ po_name ,
+ pa_id,
+ po_amount,
+ po_description,
+ ga_id
+ from poste_analytique ".
+ " order by po_name";
- $ex=$this->db->exec_sql($sql);
- $ret=Database::fetch_all($ex);
- if ( $ret == null )
- return null;
+ $ex=$this->db->exec_sql($sql);
+ $ret=Database::fetch_all($ex);
+ if ( $ret == null )
+ return null;
- $array=array();
- foreach ($ret as $line)
- {
- $object=new Anc_Account($this->db);
+ $array=array();
+ foreach ($ret as $line)
+ {
+ $object=new Anc_Account($this->db);
- $object->id=$line['po_id'];
- $object->name=$line['po_name'];
- $object->pa_id=$line['pa_id'];
- $object->amount=$line['po_amount'];
- $object->description=$line['po_description'];
- $object->ga_id=$line['ga_id'];
- $array[]=clone $object;
- }
+ $object->id=$line['po_id'];
+ $object->name=$line['po_name'];
+ $object->pa_id=$line['pa_id'];
+ $object->amount=$line['po_amount'];
+ $object->description=$line['po_description'];
+ $object->ga_id=$line['ga_id'];
+ $array[]=clone $object;
+ }
- return $array;
- }
- function display_list()
- {
- $array=$this->get_list();
- if ( empty($array) ) { echo "Vide"; return;}
- foreach ($array as $line)
- {
- echo $line->id." / ".$line->name." / ".$line->description."/".
- $line->amount." / ".$line->pa_id."/".$line->ga_id." ";
- }
- }
- function debug()
- {
- echo "id ".$this->id." ";
- echo "name ".$this->name." ";
- echo "pa_id ".$this->pa_id." ";
- echo "amount ".$this->amount." ";
- echo "description ".$this->description." ";
- echo "ga_id ".$this->ga_id." ";
- }
- function form()
- {
- $r='';
- $wName=new IText("po_name",$this->name);
- $wAmount=new INum("po_amount",$this->amount);
- $wDescription=new IText("po_description",$this->description);
- $aGroup_analytic=$this->db->make_array("select ga_id,ga_id from groupe_analytique where pa_id=".$this->pa_id,1);
- if ( count($aGroup_analytic) > 1 ) {
- $wGa_id=new ISelect("ga_id");
- $wGa_id->value=$aGroup_analytic;
- $wGa_id->selected=$this->ga_id;
- $wGa_id->table=1;
- } else {
- $wGa_id=new ISpan();
- }
- $pa=new Anc_Plan($this->db,$this->pa_id);
- $pa->get();
- $wPaName=new IText("",$pa->name);
- $wPaName->table=1;
- $wPaName->readOnly=true;
+ return $array;
+ }
+ function display_list()
+ {
+ $array=$this->get_list();
+ if ( empty($array) )
+ {
+ echo "Vide";
+ return;
+ }
+ foreach ($array as $line)
+ {
+ echo $line->id." / ".$line->name." / ".$line->description."/".
+ $line->amount." / ".$line->pa_id."/".$line->ga_id." ";
+ }
+ }
+ function debug()
+ {
+ echo "id ".$this->id." ";
+ echo "name ".$this->name." ";
+ echo "pa_id ".$this->pa_id." ";
+ echo "amount ".$this->amount." ";
+ echo "description ".$this->description." ";
+ echo "ga_id ".$this->ga_id." ";
+ }
+ function form()
+ {
+ $r='';
+ $wName=new IText("po_name",$this->name);
+ $wAmount=new INum("po_amount",$this->amount);
+ $wDescription=new IText("po_description",$this->description);
+ $aGroup_analytic=$this->db->make_array("select ga_id,ga_id from groupe_analytique where pa_id=".$this->pa_id,1);
+ if ( count($aGroup_analytic) > 1 )
+ {
+ $wGa_id=new ISelect("ga_id");
+ $wGa_id->value=$aGroup_analytic;
+ $wGa_id->selected=$this->ga_id;
+ $wGa_id->table=1;
+ }
+ else
+ {
+ $wGa_id=new ISpan();
+ }
+ $pa=new Anc_Plan($this->db,$this->pa_id);
+ $pa->get();
+ $wPaName=new IText("",$pa->name);
+ $wPaName->table=1;
+ $wPaName->readOnly=true;
- $wName->table=1;
- $wAmount->table=1;
- $wDescription->table=1;
- $r.=HtmlInput::hidden("pa_id",$this->pa_id);
- $r.=HtmlInput::hidden("po_id",$this->id);
+ $wName->table=1;
+ $wAmount->table=1;
+ $wDescription->table=1;
+ $r.=HtmlInput::hidden("pa_id",$this->pa_id);
+ $r.=HtmlInput::hidden("po_id",$this->id);
- $r.="";
+ $r.="";
- $r.="";
- $r.=td(_('Nom'));
- $r.=$wName->input();
- $r.=" ";
+ $r.="";
+ $r.=td(_('Nom'));
+ $r.=$wName->input();
+ $r.=" ";
- $r.="";
- $r.=td(_('Montant'));
- $r.=$wAmount->input();
- $r.=" ";
+ $r.="";
+ $r.=td(_('Montant'));
+ $r.=$wAmount->input();
+ $r.=" ";
- $r.="";
- $r.=td(_('Description'));
- $r.=$wDescription->input();
- $r.=" ";
+ $r.="";
+ $r.=td(_('Description'));
+ $r.=$wDescription->input();
+ $r.=" ";
- $r.="";
- $r.=td(_('Plan Analytique'));
- $r.=$wPaName->input();
- $r.=" ";
+ $r.="";
+ $r.=td(_('Plan Analytique'));
+ $r.=$wPaName->input();
+ $r.=" ";
- $r.="";
- $r.=td(_('Groupe'));
- $r.=$wGa_id->input();
- $r.=" ";
+ $r.="";
+ $r.=td(_('Groupe'));
+ $r.=$wGa_id->input();
+ $r.=" ";
- $r.="
";
- return $r;
+ $r.="
";
+ return $r;
- }
- function get_from_array($p_array)
- {
- $this->name=(isset ($p_array['po_name']))?$p_array['po_name']:"";
- $this->description=(isset ($p_array['po_description']))?$p_array['po_description']:"";
- $this->pa_id=(isset ($p_array['pa_id']))?$p_array['pa_id']:"";
- $this->amount=(isset ($p_array['po_amount']))?$p_array['po_amount']:0;
- $this->id=(isset ($p_array['po_id']))?$p_array['po_id']:-1;
- // $this->ga_id=(isset($p_array['ga_id']) && $p_array['ga_id'] == "-1" )?null:2;
- $this->ga_id=(isset($p_array['ga_id']) && $p_array['ga_id'] != "-1" )?$p_array['ga_id']:null;
- }
- static function test_me() {
- $cn=new Database(dossier::id());
- $pa_id=$cn->get_value("select max(pa_id) from plan_analytique");
- $o=new Anc_Account($cn);
- echo "Poste_Analytique ";
- echo "get_list ";
- $ee=$o->get_list();
- print_r($ee);
- //var_dump($ee);
+ }
+ function get_from_array($p_array)
+ {
+ $this->name=(isset ($p_array['po_name']))?$p_array['po_name']:"";
+ $this->description=(isset ($p_array['po_description']))?$p_array['po_description']:"";
+ $this->pa_id=(isset ($p_array['pa_id']))?$p_array['pa_id']:"";
+ $this->amount=(isset ($p_array['po_amount']))?$p_array['po_amount']:0;
+ $this->id=(isset ($p_array['po_id']))?$p_array['po_id']:-1;
+ // $this->ga_id=(isset($p_array['ga_id']) && $p_array['ga_id'] == "-1" )?null:2;
+ $this->ga_id=(isset($p_array['ga_id']) && $p_array['ga_id'] != "-1" )?$p_array['ga_id']:null;
+ }
+ static function test_me()
+ {
+ $cn=new Database(dossier::id());
+ $pa_id=$cn->get_value("select max(pa_id) from plan_analytique");
+ $o=new Anc_Account($cn);
+ echo "Poste_Analytique ";
+ echo "get_list ";
+ $ee=$o->get_list();
+ print_r($ee);
+ //var_dump($ee);
- echo "Add some ";
- $o->pa_id=$pa_id;
- $o->name="test1";
- $o->add();
+ echo "Add some ";
+ $o->pa_id=$pa_id;
+ $o->name="test1";
+ $o->add();
- $o->name="test2";
- $o->add();
+ $o->name="test2";
+ $o->add();
- $o->name="test3";
- $o->add();
+ $o->name="test3";
+ $o->add();
- $o->name="test4";
- $o->add();
+ $o->name="test4";
+ $o->add();
- $o->name="test5";
- $o->add();
+ $o->name="test5";
+ $o->add();
- echo " remove test1 ";
- $o->get_by_name("test1");
- $o->delete();
- $o->display_list();
+ echo " remove test1 ";
+ $o->get_by_name("test1");
+ $o->delete();
+ $o->display_list();
- $o->get_by_name("test4");
- echo " ".$o->id." ";
- $o->name="Test Four";
- $o->update();
- $o->display_list();
- $o->delete();
- $o->display_list();
- }
+ $o->get_by_name("test4");
+ echo " ".$o->id." ";
+ $o->name="Test Four";
+ $o->update();
+ $o->display_list();
+ $o->delete();
+ $o->display_list();
+ }
}
?>
diff --git a/include/class_anc_balance_double.php b/include/class_anc_balance_double.php
index 48eeb9672..9c4677a3b 100644
--- a/include/class_anc_balance_double.php
+++ b/include/class_anc_balance_double.php
@@ -39,516 +39,538 @@ require_once('class_pdf.php');
class Anc_Balance_Double extends Anc_Print
{
-/*!
- * \brief compute the html display
- *
- *
- * \return string
- */
+ /*!
+ * \brief compute the html display
+ *
+ *
+ * \return string
+ */
- function display_html ()
- {
- $r="";
+ function display_html ()
+ {
+ $r="";
- $array=$this->load();
- $odd=0;
- if ( is_array($array) == false ){
- return $array;
+ $array=$this->load();
+ $odd=0;
+ if ( is_array($array) == false )
+ {
+ return $array;
- }
- $old="";
- $tot_deb=0;
- $tot_cred=0;
+ }
+ $old="";
+ $tot_deb=0;
+ $tot_cred=0;
- foreach ( $array as $row) {
- $odd++;
+ foreach ( $array as $row)
+ {
+ $odd++;
- $r.=($odd%2==0)?'':' ';
+ $r.=($odd%2==0)?'':' ';
- if ( $old == $row['a_po_name'] ) {
- $r.=' ';
- } else {
+ if ( $old == $row['a_po_name'] )
+ {
+ $r.=' ';
+ }
+ else
+ {
- if ( $tot_deb != 0 && $tot_cred !=0 ) {
- $r.="";
- $r.="Total $tot_deb $tot_cred ";
- $s=abs($tot_deb-$tot_cred);
- $d=($tot_deb>$tot_cred)?'debit':'credit';
- $r.="$s $d ";
- $r.=" ";
- }
- $tot_deb=0;
- $tot_cred=0;
+ if ( $tot_deb != 0 && $tot_cred !=0 )
+ {
+ $r.="";
+ $r.="Total $tot_deb $tot_cred ";
+ $s=abs($tot_deb-$tot_cred);
+ $d=($tot_deb>$tot_cred)?'debit':'credit';
+ $r.="$s $d ";
+ $r.=" ";
+ }
+ $tot_deb=0;
+ $tot_cred=0;
- // new
- $r.="
";
- $r.="
";
- $r.="";
- $r.="Poste comptable Analytique ";
- $r.="Poste comptable Analytique ";
- $r.="Débit ";
- $r.="Crédit ";
- $r.="Solde ";
- $r.="D/C ";
- $r.=" ";
+ // new
+ $r.="
";
+ $r.="
";
+ $r.="";
+ $r.="Poste comptable Analytique ";
+ $r.="Poste comptable Analytique ";
+ $r.="Débit ";
+ $r.="Crédit ";
+ $r.="Solde ";
+ $r.="D/C ";
+ $r.=" ";
- $r.=sprintf("%s ",$row['a_po_name']);
- $old=$row['a_po_name'];
- }
- $tot_deb+=$row['a_d'];
- $tot_cred+=$row['a_c'];
+ $r.=sprintf("%s ",$row['a_po_name']);
+ $old=$row['a_po_name'];
+ }
+ $tot_deb+=$row['a_d'];
+ $tot_cred+=$row['a_c'];
- $r.=sprintf("%s ",h($row['b_po_name']));
- $r.=sprintf("%12.2f ",$row['a_d']);
- $r.=sprintf("%12.2f ",$row['a_c']);
- $r.=sprintf("%12.2f ",$row['a_solde']);
- $r.=sprintf("%s ",$row['a_debit']);
- $r.="";
- }
- if ( $tot_deb != 0 || $tot_cred !=0 ) {
- $r.="";
- $r.="Total $tot_deb $tot_cred ";
- $s=abs($tot_deb-$tot_cred);
- $d=($tot_deb>$tot_cred)?'debit':'credit';
- $r.="$s $d ";
- $r.=" ";
- }
+ $r.=sprintf("%s ",h($row['b_po_name']));
+ $r.=sprintf("%12.2f ",$row['a_d']);
+ $r.=sprintf("%12.2f ",$row['a_c']);
+ $r.=sprintf("%12.2f ",$row['a_solde']);
+ $r.=sprintf("%s ",$row['a_debit']);
+ $r.="";
+ }
+ if ( $tot_deb != 0 || $tot_cred !=0 )
+ {
+ $r.="";
+ $r.="Total $tot_deb $tot_cred ";
+ $s=abs($tot_deb-$tot_cred);
+ $d=($tot_deb>$tot_cred)?'debit':'credit';
+ $r.="$s $d ";
+ $r.=" ";
+ }
- $r.="
";
- $r.='
';
- $sum=$this->show_sum($array);
- foreach ($sum as $row) {
- $r.='';
- $r.=''.$row['poste'].' ';
- $r.=''.$row['desc'].' ';
- $r.=''.$row['debit'].' ';
- $r.=''.$row['credit'].' ';
- $r.=''.$row['dc'].' ';
- $r.=' ';
- }
- $r.='
';
+ $r.="
";
+ $r.='';
+ $sum=$this->show_sum($array);
+ foreach ($sum as $row)
+ {
+ $r.='';
+ $r.=''.$row['poste'].' ';
+ $r.=''.$row['desc'].' ';
+ $r.=''.$row['debit'].' ';
+ $r.=''.$row['credit'].' ';
+ $r.=''.$row['dc'].' ';
+ $r.=' ';
+ }
+ $r.='
';
- return $r;
- }
-/*!
- * \brief Display the result in pdf
- *
- * \return none
- */
- function display_pdf()
- {
- $array=$this->load();
- if (empty($array))return;
- $pdf=new PDF($this->db);
- $pdf->Setdossierinfo(dossier::name());
- $pdf->AliasNbPages();
- $pdf->AddPage();
+ return $r;
+ }
+ /*!
+ * \brief Display the result in pdf
+ *
+ * \return none
+ */
+ function display_pdf()
+ {
+ $array=$this->load();
+ if (empty($array))return;
+ $pdf=new PDF($this->db);
+ $pdf->Setdossierinfo(dossier::name());
+ $pdf->AliasNbPages();
+ $pdf->AddPage();
- $pa=new Anc_Plan($this->db,$this->pa_id);
- $pa->get();
- $pb=new Anc_Plan($this->db,$this->pa_id2);
- $pb->get();
- $pdf->SetFont('DejaVu','B',9);
- $pdf->Cell(0,7,sprintf("Balance croise plan %s %s ",
- $pa->name,
- $pb->name),1,0,'C');
- $filtre_date="";
- $filtre_pa="";
- $filtre_pb="";
+ $pa=new Anc_Plan($this->db,$this->pa_id);
+ $pa->get();
+ $pb=new Anc_Plan($this->db,$this->pa_id2);
+ $pb->get();
+ $pdf->SetFont('DejaVu','B',9);
+ $pdf->Cell(0,7,sprintf("Balance croise plan %s %s ",
+ $pa->name,
+ $pb->name),1,0,'C');
+ $filtre_date="";
+ $filtre_pa="";
+ $filtre_pb="";
- if ( $this->from !="" ||$this->to !="")
- $filtre_date=sprintf("Filtre date %s %s",
- $this->from,
- $this->to);
- if ( $this->from_poste !="" ||$this->to_poste !="")
- $filtre_pa=sprintf("Filtre poste plan1 %s %s",
- ($this->from_poste!="")?"de ".$this->from_poste:" ",
- ($this->to_poste!="")?"jusque ".$this->to_poste:"");
+ if ( $this->from !="" ||$this->to !="")
+ $filtre_date=sprintf("Filtre date %s %s",
+ $this->from,
+ $this->to);
+ if ( $this->from_poste !="" ||$this->to_poste !="")
+ $filtre_pa=sprintf("Filtre poste plan1 %s %s",
+ ($this->from_poste!="")?"de ".$this->from_poste:" ",
+ ($this->to_poste!="")?"jusque ".$this->to_poste:"");
- if ( $this->from_poste2 !="" ||$this->to_poste2 !="")
- $filtre_pb=sprintf("Filtre poste plan2 %s %s",
- ($this->from_poste2!="")?"de ".$this->from_poste2:" ",
- ($this->to_poste2!="")?"jusque ".$this->to_poste2:"");
+ if ( $this->from_poste2 !="" ||$this->to_poste2 !="")
+ $filtre_pb=sprintf("Filtre poste plan2 %s %s",
+ ($this->from_poste2!="")?"de ".$this->from_poste2:" ",
+ ($this->to_poste2!="")?"jusque ".$this->to_poste2:"");
- $pdf->SetFont('DejaVu','',8);
- $pdf->Cell(50,7,$filtre_date);
- $pdf->Cell(50,7,$filtre_pa);
- $pdf->Cell(50,7,$filtre_pb);
- $pdf->Ln();
+ $pdf->SetFont('DejaVu','',8);
+ $pdf->Cell(50,7,$filtre_date);
+ $pdf->Cell(50,7,$filtre_pa);
+ $pdf->Cell(50,7,$filtre_pb);
+ $pdf->Ln();
- $pdf->SetFont('DejaVu','',6);
- $pdf->Cell(20,7,'id','B');
- $pdf->Cell(40,7,'Poste Comptable','B');
- $pdf->Cell(20,7,'Débit','B',0,'L');
- $pdf->Cell(20,7,'Crédit','B',0,'L');
- $pdf->Cell(20,7,'Solde','B',0,'L');
- $pdf->Cell(20,7,'D/C','B',0,'L');
- $pdf->Ln();
-
- for ($i=0;$iCell(20,6,$row['a_po_name'],0,0,'L');
- $pdf->Cell(40,6,$row['b_po_name'],0,0,'L');
- $pdf->Cell(20,6,$row['a_d'],0,0,'R');
- $pdf->Cell(20,6,$row['a_c'],0,0,'R');
- $pdf->Cell(20,6,$row['a_solde'],0,0,'R');
- $pdf->Cell(20,6,$row['a_debit'],0,0,'C');
- $pdf->Ln();
+ $pdf->SetFont('DejaVu','',6);
+ $pdf->Cell(20,7,'id','B');
+ $pdf->Cell(40,7,'Poste Comptable','B');
+ $pdf->Cell(20,7,'Débit','B',0,'L');
+ $pdf->Cell(20,7,'Crédit','B',0,'L');
+ $pdf->Cell(20,7,'Solde','B',0,'L');
+ $pdf->Cell(20,7,'D/C','B',0,'L');
+ $pdf->Ln();
+
+ for ($i=0;$iCell(20,6,$row['a_po_name'],0,0,'L');
+ $pdf->Cell(40,6,$row['b_po_name'],0,0,'L');
+ $pdf->Cell(20,6,$row['a_d'],0,0,'R');
+ $pdf->Cell(20,6,$row['a_c'],0,0,'R');
+ $pdf->Cell(20,6,$row['a_solde'],0,0,'R');
+ $pdf->Cell(20,6,$row['a_debit'],0,0,'C');
+ $pdf->Ln();
+ }
+
+ $sum=$this->show_sum($array);
+ $pdf->SetFont('DejaVu','B',8);
+ $pdf->Cell(70,6,'Somme',1,0,'C');
+ $pdf->Ln(5);
+ $pdf->SetFont('DejaVu','',6);
+
+ $pdf->Cell(20,7,'Poste');
+ $pdf->Cell(60,7,'Description','B');
+ $pdf->Cell(20,7,'Débit','B',0,'L');
+ $pdf->Cell(20,7,'Crédit','B',0,'L');
+ $pdf->Cell(20,7,'Solde','B',0,'L');
+ $pdf->Cell(20,7,'D/C','B',0,'L');
+ $pdf->Ln();
+
+ for ($i=0;$iCell(20,6,$row['poste'],0,0,'L');
+ $pdf->Cell(60,6,$row['desc'],0,0,'L');
+ $pdf->Cell(20,6,sprintf('%.2f',$row['debit']),0,0,'R');
+ $pdf->Cell(20,6,sprintf('%.2f',$row['credit']),0,0,'R');
+ $pdf->Cell(20,6,sprintf('%.2f',$row['solde']),0,0,'R');
+ $pdf->Cell(20,6,$row['dc'],0,0,'R');
+ $pdf->Ln();
+ }
+ $fDate=date('dmy-Hi');
+ $pdf->output('crossbalance-'.$fDate.'.pdf','I');
}
- $sum=$this->show_sum($array);
- $pdf->SetFont('DejaVu','B',8);
- $pdf->Cell(70,6,'Somme',1,0,'C');
- $pdf->Ln(5);
- $pdf->SetFont('DejaVu','',6);
- $pdf->Cell(20,7,'Poste');
- $pdf->Cell(60,7,'Description','B');
- $pdf->Cell(20,7,'Débit','B',0,'L');
- $pdf->Cell(20,7,'Crédit','B',0,'L');
- $pdf->Cell(20,7,'Solde','B',0,'L');
- $pdf->Cell(20,7,'D/C','B',0,'L');
- $pdf->Ln();
+ /*!
+ * \brief Compute the csv export
+ * \return string with the csv
+ */
+ function display_csv()
+ {
+ $r="";
+
+ $r.='"Poste comptable Analytique",';
+ $r.='"Poste comptable Analytique",';
+ $r.='"Debit",';
+ $r.='"Credit",';
+ $r.='"Solde",';
+ $r.='"D/C",';
+
+ $r.="\r\n";
+
+ $array=$this->load();
+ if ( is_array($array) == false )
+ {
+ return $array;
+
+ }
+ foreach ( $array as $row)
+ {
+
+ $r.=sprintf('"%s",',$row['a_po_name']);
+ $r.=sprintf('"%s",',$row['b_po_name']);
+ $r.=sprintf("%12.2f,",$row['a_d']);
+ $r.=sprintf("%12.2f,",$row['a_c']);
+ $r.=sprintf("%12.2f,",$row['a_solde']);
+ $r.=sprintf('"%s"',$row['a_debit']);
+ $r.="\r\n";
+ }
+
+ return $r;
- for ($i=0;$iCell(20,6,$row['poste'],0,0,'L');
- $pdf->Cell(60,6,$row['desc'],0,0,'L');
- $pdf->Cell(20,6,sprintf('%.2f',$row['debit']),0,0,'R');
- $pdf->Cell(20,6,sprintf('%.2f',$row['credit']),0,0,'R');
- $pdf->Cell(20,6,sprintf('%.2f',$row['solde']),0,0,'R');
- $pdf->Cell(20,6,$row['dc'],0,0,'R');
- $pdf->Ln();
}
- $fDate=date('dmy-Hi');
- $pdf->output('crossbalance-'.$fDate.'.pdf','I');
- }
-
+ /*!
+ * \brief Compute the form to display
+ * \param $p_hidden hidden tag to be included (gDossier,...)
+ *
+ *
+ * \return string containing the data
+ */
+ function display_form($p_string='')
+ {
+ $r=parent::display_form($p_string);
+ // show the second plan
+ $r.='';
+ $plan=new Anc_Plan($this->db);
+ $plan_id=new ISelect("pa_id2");
+ $plan_id->value=$this->db->make_array("select pa_id, pa_name from plan_analytique order by pa_name");
+ $plan_id->selected=$this->pa_id2;
+ $r.= "Plan Analytique :".$plan_id->input();
-/*!
- * \brief Compute the csv export
- * \return string with the csv
- */
- function display_csv()
- {
- $r="";
+ $poste=new IText();
+ $poste->size=10;
+ $r.="Entre le poste ".$poste->input("from_poste2",$this->from_poste2);
+ $choose=new IButton();
+ $choose->name="Choix Poste";
+ $choose->label=_("Recherche");
+ $choose->javascript="onClick=search_ca(".dossier::id().",'from_poste2','pa_id2')";
+ $r.=$choose->input();
- $r.='"Poste comptable Analytique",';
- $r.='"Poste comptable Analytique",';
- $r.='"Debit",';
- $r.='"Credit",';
- $r.='"Solde",';
- $r.='"D/C",';
+ $r.=" et le poste ".$poste->input("to_poste2",$this->to_poste2);
+ $choose->javascript="onClick=search_ca(".dossier::id().",'to_poste2','pa_id2')";
+ $r.=$choose->input();
+ $r.=''.
+ _('Selectionnez le plan qui vous intéresse avant de cliquer sur Recherche').
+ ' ';
- $r.="\r\n";
+ $r.=' ';
+ $r.=HtmlInput::submit('Affiche','Affiche');
+ return $r;
+ }
+ /*!
+ * \brief Show the button to export in PDF or CSV
+ * \param $url_csv url of the csv
+ * \param $url_pdf url of the pdf
+ * \param $p_string hidden data to include in the form
+ *
+ *
+ * \return string with the button
+ */
+ function show_button($url_csv,$url_pdf,$p_string="")
+ {
+ $r="";
+ $r.= '';
+ $r.= $p_string;
+ $r.= HtmlInput::hidden("to",$this->to);
+ $r.= HtmlInput::hidden("from",$this->from);
+ $r.= HtmlInput::hidden("pa_id",$this->pa_id);
+ $r.= HtmlInput::hidden("from_poste",$this->from_poste);
+ $r.= HtmlInput::hidden("to_poste",$this->to_poste);
+ $r.= HtmlInput::hidden("pa_id2",$this->pa_id2);
+ $r.= HtmlInput::hidden("from_poste2",$this->from_poste2);
+ $r.= HtmlInput::hidden("to_poste2",$this->to_poste2);
+ $r.=dossier::hidden();
+ $r.=HtmlInput::submit('bt_pdf',"Export en PDF");
+ $r.= ' ';
- $array=$this->load();
- if ( is_array($array) == false ){
- return $array;
+ $r.= '';
+ $r.= HtmlInput::hidden("to",$this->to);
+ $r.= HtmlInput::hidden("from",$this->from);
+ $r.= HtmlInput::hidden("pa_id",$this->pa_id);
+ $r.= HtmlInput::hidden("from_poste",$this->from_poste);
+ $r.= HtmlInput::hidden("to_poste",$this->to_poste);
+ $r.= HtmlInput::hidden("pa_id2",$this->pa_id2);
+ $r.= HtmlInput::hidden("from_poste2",$this->from_poste2);
+ $r.= HtmlInput::hidden("to_poste2",$this->to_poste2);
+ $r.= $p_string;
+ $r.= dossier::hidden();
+ $r.=HtmlInput::submit('bt_csv',"Export en CSV");
+ $r.= ' ';
+ return $r;
- }
- foreach ( $array as $row) {
+ }
+ /*!
+ * \brief complete the object with the data in $_REQUEST
+ */
+ function get_request()
+ {
+ parent::get_request();
+ $this->from_poste2=(isset($_REQUEST['from_poste2']))?$_REQUEST['from_poste2']:"";
+ $this->to_poste2=(isset($_REQUEST['to_poste2']))?$_REQUEST['to_poste2']:"";
+ $this->pa_id2=(isset($_REQUEST['pa_id2']))?$_REQUEST['pa_id2']:"";
- $r.=sprintf('"%s",',$row['a_po_name']);
- $r.=sprintf('"%s",',$row['b_po_name']);
- $r.=sprintf("%12.2f,",$row['a_d']);
- $r.=sprintf("%12.2f,",$row['a_c']);
- $r.=sprintf("%12.2f,",$row['a_solde']);
- $r.=sprintf('"%s"',$row['a_debit']);
- $r.="\r\n";
- }
+ }
+ /*!
+ * \brief load the data from the database
+ *
+ * \return array
+ */
+ function load()
+ {
+ $filter_poste="";
+ $and="";
+ if ( $this->from_poste != "" )
+ {
+ $filter_poste.=" $and upper(pa.po_name)>= upper('".Database::escape_string($this->from_poste)."')";
+ $and=" and ";
- return $r;
+ }
+ if ( $this->to_poste != "" )
+ {
+ $filter_poste.=" $and upper(pa.po_name)<= upper('".Database::escape_string($this->to_poste)."')";
+ $and=" and ";
+ }
- }
-/*!
- * \brief Compute the form to display
- * \param $p_hidden hidden tag to be included (gDossier,...)
- *
- *
- * \return string containing the data
- */
- function display_form($p_string='')
- {
- $r=parent::display_form($p_string);
- // show the second plan
- $r.='';
- $plan=new Anc_Plan($this->db);
- $plan_id=new ISelect("pa_id2");
- $plan_id->value=$this->db->make_array("select pa_id, pa_name from plan_analytique order by pa_name");
- $plan_id->selected=$this->pa_id2;
- $r.= "Plan Analytique :".$plan_id->input();
+ if ( $this->from_poste2 != "" )
+ {
+ $filter_poste.=" $and upper(pb.po_name)>= upper('".Database::escape_string($this->from_poste2)."')";
+ $and=" and ";
+ }
+ if ( $this->to_poste2 != "" )
+ {
+ $filter_poste.=" $and upper(pb.po_name)<= upper('".Database::escape_string($this->to_poste2)."')";
+ $and=" and ";
+ }
+ if ( $filter_poste != "")
+ $filter_poste=" where ".$filter_poste;
- $poste=new IText();
- $poste->size=10;
- $r.="Entre le poste ".$poste->input("from_poste2",$this->from_poste2);
- $choose=new IButton();
- $choose->name="Choix Poste";
- $choose->label=_("Recherche");
- $choose->javascript="onClick=search_ca(".dossier::id().",'from_poste2','pa_id2')";
- $r.=$choose->input();
+ $sql="
+ select a_po_id ,
+ pa.po_name as a_po_name,
+ pa.po_description as a_po_description,
+ b_po_id,
+ pb.po_name as b_po_name,
+ sum(a_oa_amount_c) as a_c,
+ sum(a_oa_amount_d) as a_d
+ from (select
+ a.po_id as a_po_id,
+ b.po_id as b_po_id,
+ case when a.oa_debit='t' then a.oa_amount else 0 end as a_oa_amount_d,
+ case when a.oa_debit='f' then a.oa_amount else 0 end as a_oa_amount_c
+ from
+ operation_analytique as a join operation_analytique as b using (j_id)
+ where a.pa_id=".
+ $this->pa_id."
+ and b.pa_id=".$this->pa_id2." ".$this->set_sql_filter()."
+ ) as m join poste_analytique as pa on ( a_po_id=pa.po_id)
+ join poste_analytique as pb on (b_po_id=pb.po_id)
- $r.=" et le poste ".$poste->input("to_poste2",$this->to_poste2);
- $choose->javascript="onClick=search_ca(".dossier::id().",'to_poste2','pa_id2')";
- $r.=$choose->input();
- $r.=''.
- _('Selectionnez le plan qui vous intéresse avant de cliquer sur Recherche').
- ' ';
+ $filter_poste
- $r.=' ';
- $r.=HtmlInput::submit('Affiche','Affiche');
- return $r;
- }
-/*!
- * \brief Show the button to export in PDF or CSV
- * \param $url_csv url of the csv
- * \param $url_pdf url of the pdf
- * \param $p_string hidden data to include in the form
- *
- *
- * \return string with the button
- */
- function show_button($url_csv,$url_pdf,$p_string="")
- {
- $r="";
- $r.= '';
- $r.= $p_string;
- $r.= HtmlInput::hidden("to",$this->to);
- $r.= HtmlInput::hidden("from",$this->from);
- $r.= HtmlInput::hidden("pa_id",$this->pa_id);
- $r.= HtmlInput::hidden("from_poste",$this->from_poste);
- $r.= HtmlInput::hidden("to_poste",$this->to_poste);
- $r.= HtmlInput::hidden("pa_id2",$this->pa_id2);
- $r.= HtmlInput::hidden("from_poste2",$this->from_poste2);
- $r.= HtmlInput::hidden("to_poste2",$this->to_poste2);
- $r.=dossier::hidden();
- $r.=HtmlInput::submit('bt_pdf',"Export en PDF");
- $r.= ' ';
+ group by a_po_id,b_po_id,pa.po_name,pa.po_description,pb.po_name
+ order by 1;
+ ";
- $r.= '';
- $r.= HtmlInput::hidden("to",$this->to);
- $r.= HtmlInput::hidden("from",$this->from);
- $r.= HtmlInput::hidden("pa_id",$this->pa_id);
- $r.= HtmlInput::hidden("from_poste",$this->from_poste);
- $r.= HtmlInput::hidden("to_poste",$this->to_poste);
- $r.= HtmlInput::hidden("pa_id2",$this->pa_id2);
- $r.= HtmlInput::hidden("from_poste2",$this->from_poste2);
- $r.= HtmlInput::hidden("to_poste2",$this->to_poste2);
- $r.= $p_string;
- $r.= dossier::hidden();
- $r.=HtmlInput::submit('bt_csv',"Export en CSV");
- $r.= ' ';
- return $r;
-}
-/*!
- * \brief complete the object with the data in $_REQUEST
- */
- function get_request()
- {
- parent::get_request();
- $this->from_poste2=(isset($_REQUEST['from_poste2']))?$_REQUEST['from_poste2']:"";
- $this->to_poste2=(isset($_REQUEST['to_poste2']))?$_REQUEST['to_poste2']:"";
- $this->pa_id2=(isset($_REQUEST['pa_id2']))?$_REQUEST['pa_id2']:"";
-
- }
-/*!
- * \brief load the data from the database
- *
- * \return array
- */
- function load()
- {
- $filter_poste="";
- $and="";
- if ( $this->from_poste != "" ){
- $filter_poste.=" $and upper(pa.po_name)>= upper('".Database::escape_string($this->from_poste)."')";
- $and=" and ";
-
- }
- if ( $this->to_poste != "" ){
- $filter_poste.=" $and upper(pa.po_name)<= upper('".Database::escape_string($this->to_poste)."')";
- $and=" and ";
- }
-
- if ( $this->from_poste2 != "" ){
- $filter_poste.=" $and upper(pb.po_name)>= upper('".Database::escape_string($this->from_poste2)."')";
- $and=" and ";
- }
- if ( $this->to_poste2 != "" ){
- $filter_poste.=" $and upper(pb.po_name)<= upper('".Database::escape_string($this->to_poste2)."')";
- $and=" and ";
- }
- if ( $filter_poste != "")
- $filter_poste=" where ".$filter_poste;
-
- $sql="
-select a_po_id ,
-pa.po_name as a_po_name,
-pa.po_description as a_po_description,
-b_po_id,
-pb.po_name as b_po_name,
-sum(a_oa_amount_c) as a_c,
-sum(a_oa_amount_d) as a_d
-from (select
-a.po_id as a_po_id,
-b.po_id as b_po_id,
-case when a.oa_debit='t' then a.oa_amount else 0 end as a_oa_amount_d,
-case when a.oa_debit='f' then a.oa_amount else 0 end as a_oa_amount_c
-from
-operation_analytique as a join operation_analytique as b using (j_id)
-where a.pa_id=".
-$this->pa_id."
- and b.pa_id=".$this->pa_id2." ".$this->set_sql_filter()."
-) as m join poste_analytique as pa on ( a_po_id=pa.po_id)
-join poste_analytique as pb on (b_po_id=pb.po_id)
-
-$filter_poste
-
- group by a_po_id,b_po_id,pa.po_name,pa.po_description,pb.po_name
-order by 1;
-";
-
-
- $res=$this->db->exec_sql($sql);
-
- if ( Database::num_row($res) == 0 )
- return null;
- $a=array();
- $count=0;
- $array=Database::fetch_all($res);
- foreach ($array as $row) {
- $a[$count]['a_po_id']=$row['a_po_id'];
- $a[$count]['a_d']=$row['a_d'];
- $a[$count]['a_c']=$row['a_c'];
- $a[$count]['b_po_id']=$row['b_po_id'];
-
- $a[$count]['a_po_name']=$row['a_po_name'];
- $a[$count]['a_po_description']=$row['a_po_description'];
- $a[$count]['b_po_name']=$row['b_po_name'];
- $a[$count]['a_solde']=abs($row['a_d']-$row['a_c']);
- $a[$count]['a_debit']=($row['a_d']>$row['a_c'])?"debit":"credit";
-
- $count++;
- }
- return $a;
-
-
- }
-/*!
- * \brief Set the filter (account_date)
- *
- * \return return the string to add to load
- */
-
- function set_sql_filter()
- {
- $sql="";
- $and=" and ";
- if ( $this->from != "" ){
- $sql.="$and a.oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
- }
- if ( $this->to != "" ){
- $sql.=" $and a.oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
- }
-
- return $sql;
-
- }
-
-/*!
- * \brief add extra lines with sum of each account
- * \param $p_array array returned by load()
- */
- function show_sum ($p_array)
-{
- $tot_deb=0;
- $tot_cred=0;
- $old="";
- $first=true;
- $array=array();
- foreach ( $p_array as $row) {
-
- if ( $old != $row['a_po_name'] && $first==false )
-
- {
- $s=abs($tot_deb-$tot_cred);
- $d=($tot_deb>$tot_cred)?'debit':'credit';
- $array[]=array('poste'=>$old,'desc'=>$old_desc
- ,'debit'=>$tot_deb,'credit'=>$tot_cred,
- 'solde'=>$s,'dc'=>$d);
- /* $r=sprintf(" $old $old_desc Debit %12.2f Credit %12.2f solde %12.2f %s",
- $tot_deb,
- $tot_cred,
- $s,
- $d);
- $pdf->ezText($r,9);
- */
- $tot_deb=0;
- $tot_cred=0;
-
- $old=$row['a_po_name'];
- $old_desc=$row['a_po_description'];
- }
-
- if ( $first ) {
- $first=false;
- $old=$row['a_po_name'];
- $old_desc=$row['a_po_description'];
- }
-
- $tot_deb+=$row['a_d'];
- $tot_cred+=$row['a_c'];
-
-
- }
- $s=abs($tot_deb-$tot_cred);
- $d=($tot_deb>$tot_cred)?'debit':'credit';
- $array[]=array('poste'=>$old,'desc'=>$old_desc
- ,'debit'=>$tot_deb,'credit'=>$tot_cred,
-
- 'solde'=>$s,'dc'=>$d);
-
- /* $r=sprintf(" %s Debit %12.2f Credit %12.2f solde %12.2f %s",
- $old,
- $tot_deb,
- $tot_cred,
- $s,
- $d);
- $pdf->ezText($r,9);
- */
- return $array;
-
-}
-/*!
- * \brief for testing and debuggind the class
- * it must never be called from production system, it is
- * intended only for developpers
- * \param
- * \param
- * \param
- *
- *
- * \return none
- */
- static function test_me()
- {
- $a=new Database(dossier::id());
-
- $bal=new Anc_Balance_Double($a);
- $bal->get_request();
-
- echo '';
-
- echo $bal->display_form();
- echo ' ';
- if ( isset($_GET['result'])) {
- echo $bal->show_button("","");
- echo "HTML ";
- echo $bal->display_html();
- echo "CSV ";
- echo $bal->display_csv();
-
- }
- }
+ $res=$this->db->exec_sql($sql);
+
+ if ( Database::num_row($res) == 0 )
+ return null;
+ $a=array();
+ $count=0;
+ $array=Database::fetch_all($res);
+ foreach ($array as $row)
+ {
+ $a[$count]['a_po_id']=$row['a_po_id'];
+ $a[$count]['a_d']=$row['a_d'];
+ $a[$count]['a_c']=$row['a_c'];
+ $a[$count]['b_po_id']=$row['b_po_id'];
+
+ $a[$count]['a_po_name']=$row['a_po_name'];
+ $a[$count]['a_po_description']=$row['a_po_description'];
+ $a[$count]['b_po_name']=$row['b_po_name'];
+ $a[$count]['a_solde']=abs($row['a_d']-$row['a_c']);
+ $a[$count]['a_debit']=($row['a_d']>$row['a_c'])?"debit":"credit";
+
+ $count++;
+ }
+ return $a;
+
+
+ }
+ /*!
+ * \brief Set the filter (account_date)
+ *
+ * \return return the string to add to load
+ */
+
+ function set_sql_filter()
+ {
+ $sql="";
+ $and=" and ";
+ if ( $this->from != "" )
+ {
+ $sql.="$and a.oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
+ }
+ if ( $this->to != "" )
+ {
+ $sql.=" $and a.oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
+ }
+
+ return $sql;
+
+ }
+
+ /*!
+ * \brief add extra lines with sum of each account
+ * \param $p_array array returned by load()
+ */
+ function show_sum ($p_array)
+ {
+ $tot_deb=0;
+ $tot_cred=0;
+ $old="";
+ $first=true;
+ $array=array();
+ foreach ( $p_array as $row)
+ {
+
+ if ( $old != $row['a_po_name'] && $first==false )
+
+ {
+ $s=abs($tot_deb-$tot_cred);
+ $d=($tot_deb>$tot_cred)?'debit':'credit';
+ $array[]=array('poste'=>$old,'desc'=>$old_desc
+ ,'debit'=>$tot_deb,'credit'=>$tot_cred,
+ 'solde'=>$s,'dc'=>$d);
+ /* $r=sprintf(" $old $old_desc Debit %12.2f Credit %12.2f solde %12.2f %s",
+ $tot_deb,
+ $tot_cred,
+ $s,
+ $d);
+ $pdf->ezText($r,9);
+ */
+ $tot_deb=0;
+ $tot_cred=0;
+
+ $old=$row['a_po_name'];
+ $old_desc=$row['a_po_description'];
+ }
+
+ if ( $first )
+ {
+ $first=false;
+ $old=$row['a_po_name'];
+ $old_desc=$row['a_po_description'];
+ }
+
+ $tot_deb+=$row['a_d'];
+ $tot_cred+=$row['a_c'];
+
+
+ }
+ $s=abs($tot_deb-$tot_cred);
+ $d=($tot_deb>$tot_cred)?'debit':'credit';
+ $array[]=array('poste'=>$old,'desc'=>$old_desc
+ ,'debit'=>$tot_deb,'credit'=>$tot_cred,
+
+ 'solde'=>$s,'dc'=>$d);
+
+ /* $r=sprintf(" %s Debit %12.2f Credit %12.2f solde %12.2f %s",
+ $old,
+ $tot_deb,
+ $tot_cred,
+ $s,
+ $d);
+ $pdf->ezText($r,9);
+ */
+ return $array;
+
+ }
+ /*!
+ * \brief for testing and debuggind the class
+ * it must never be called from production system, it is
+ * intended only for developpers
+ * \param
+ * \param
+ * \param
+ *
+ *
+ * \return none
+ */
+ static function test_me()
+ {
+ $a=new Database(dossier::id());
+
+ $bal=new Anc_Balance_Double($a);
+ $bal->get_request();
+
+ echo '';
+
+ echo $bal->display_form();
+ echo ' ';
+ if ( isset($_GET['result']))
+ {
+ echo $bal->show_button("","");
+ echo "HTML ";
+ echo $bal->display_html();
+ echo "CSV ";
+ echo $bal->display_csv();
+
+ }
+ }
}
diff --git a/include/class_anc_balance_simple.php b/include/class_anc_balance_simple.php
index df8b1c0dd..bb9daa4be 100644
--- a/include/class_anc_balance_simple.php
+++ b/include/class_anc_balance_simple.php
@@ -34,257 +34,272 @@ require_once ('header_print.php');
*
*/
-class Anc_Balance_Simple extends Anc_Print {
+class Anc_Balance_Simple extends Anc_Print
+{
-/*!
- * \brief load the data from the database
- *
- * \return array
- */
- function load()
- {
- $filter=$this->set_sql_filter();
- // sum debit
+ /*!
+ * \brief load the data from the database
+ *
+ * \return array
+ */
+ function load()
+ {
+ $filter=$this->set_sql_filter();
+ // sum debit
- $sql="select m.po_id,sum(deb) as sum_deb,sum(cred) as sum_cred,";
- $sql.=" po_name||' '||po_description as po_name";
- $sql.=" from ";
- $sql.=" (select po_id,case when oa_debit='t' then oa_amount else 0 end as deb,";
- $sql.="case when oa_debit='f' then oa_amount else 0 end as cred ";
- $sql.=" from operation_analytique join poste_analytique using(po_id)";
- $sql.=(empty($filter) == false)?" where ".$filter:"";
- $sql.=" ) as m join poste_analytique using (po_id)";
- $sql.=" where pa_id=".$this->pa_id;
- $sql.=" group by po_id,po_name,po_description";
- $sql.=" order by po_id";
- $res=$this->db->exec_sql($sql);
+ $sql="select m.po_id,sum(deb) as sum_deb,sum(cred) as sum_cred,";
+ $sql.=" po_name||' '||po_description as po_name";
+ $sql.=" from ";
+ $sql.=" (select po_id,case when oa_debit='t' then oa_amount else 0 end as deb,";
+ $sql.="case when oa_debit='f' then oa_amount else 0 end as cred ";
+ $sql.=" from operation_analytique join poste_analytique using(po_id)";
+ $sql.=(empty($filter) == false)?" where ".$filter:"";
+ $sql.=" ) as m join poste_analytique using (po_id)";
+ $sql.=" where pa_id=".$this->pa_id;
+ $sql.=" group by po_id,po_name,po_description";
+ $sql.=" order by po_id";
+ $res=$this->db->exec_sql($sql);
- if ( Database::num_row($res) == 0 )
- return null;
- $a=array();
- $count=0;
- $array=Database::fetch_all($res);
- foreach ($array as $row) {
- $a[$count]['po_id']=$row['po_id'];
- $a[$count]['sum_deb']=$row['sum_deb'];
- $a[$count]['sum_cred']=$row['sum_cred'];
- $a[$count]['po_name']=$row['po_name'];
- $a[$count]['solde']=abs($row['sum_deb']-$row['sum_cred']);
- $a[$count]['debit']=($row['sum_deb']>$row['sum_cred'])?"debit":"credit";
- $count++;
- }
- return $a;
+ if ( Database::num_row($res) == 0 )
+ return null;
+ $a=array();
+ $count=0;
+ $array=Database::fetch_all($res);
+ foreach ($array as $row)
+ {
+ $a[$count]['po_id']=$row['po_id'];
+ $a[$count]['sum_deb']=$row['sum_deb'];
+ $a[$count]['sum_cred']=$row['sum_cred'];
+ $a[$count]['po_name']=$row['po_name'];
+ $a[$count]['solde']=abs($row['sum_deb']-$row['sum_cred']);
+ $a[$count]['debit']=($row['sum_deb']>$row['sum_cred'])?"debit":"credit";
+ $count++;
+ }
+ return $a;
- }
-/*!
- * \brief Set the filter (account_date)
- *
- * \return return the string to add to load
- */
+ }
+ /*!
+ * \brief Set the filter (account_date)
+ *
+ * \return return the string to add to load
+ */
- function set_sql_filter() {
- $sql="";
- $and="";
- if ( $this->from != "" ){
- $sql.=" oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
- $and=" and ";
- }
- if ( $this->to != "" ){
- $sql.=" $and oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
- $and=" and ";
- }
- if ( $this->from_poste != "" ){
- $sql.=" $and upper(po_name)>= upper('".$this->from_poste."')";
- $and=" and ";
- }
- if ( $this->to_poste != "" ){
- $sql.=" $and upper(po_name)<= upper('".$this->to_poste."')";
- $and=" and ";
- }
- return $sql;
+ function set_sql_filter()
+ {
+ $sql="";
+ $and="";
+ if ( $this->from != "" )
+ {
+ $sql.=" oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
+ $and=" and ";
+ }
+ if ( $this->to != "" )
+ {
+ $sql.=" $and oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
+ $and=" and ";
+ }
+ if ( $this->from_poste != "" )
+ {
+ $sql.=" $and upper(po_name)>= upper('".$this->from_poste."')";
+ $and=" and ";
+ }
+ if ( $this->to_poste != "" )
+ {
+ $sql.=" $and upper(po_name)<= upper('".$this->to_poste."')";
+ $and=" and ";
+ }
+ return $sql;
- }
-/*!
- * \brief compute the html display
- *
- *
- * \return string
- */
- function display_html()
- {
- $r="";
- $r.="";
- $r.="Poste comptable Analytique ";
- $r.="Débit ";
- $r.="Crédit ";
- $r.="Solde ";
- $r.="D/C ";
- $r.=" ";
+ }
+ /*!
+ * \brief compute the html display
+ *
+ *
+ * \return string
+ */
+ function display_html()
+ {
+ $r="";
+ $r.="";
+ $r.="Poste comptable Analytique ";
+ $r.="Débit ";
+ $r.="Crédit ";
+ $r.="Solde ";
+ $r.="D/C ";
+ $r.=" ";
- $array=$this->load();
- $odd=0;
- if ( is_array($array) == false ){
- return $array;
+ $array=$this->load();
+ $odd=0;
+ if ( is_array($array) == false )
+ {
+ return $array;
- }
- foreach ( $array as $row) {
- $odd++;
+ }
+ foreach ( $array as $row)
+ {
+ $odd++;
- $r.=($odd%2==0)?'':' ';
- // the name and po_id
- // $r.=sprintf("%s ",$row['po_id']);
- $r.=sprintf("%s ",h($row['po_name']));
- $r.=sprintf("%12.2f ",$row['sum_deb']);
- $r.=sprintf("%12.2f ",$row['sum_cred']);
- $r.=sprintf("%12.2f ",$row['solde']);
- $deb=($row['sum_deb'] > $row['sum_cred'])?"D":"C";
- $deb=($row['solde'] == 0 )?'':$deb;
- $r.=sprintf("%s ",$deb);
- $r.="";
- }
- $r.="
";
- return $r;
- }
-/*!
- * \brief Compute the form to display
- * \param $p_hidden hidden tag to be included (gDossier,...)
- *
- *
- * \return string containing the data
- */
- function display_form($p_string="") {
- $r=parent::display_form($p_string);
+ $r.=($odd%2==0)?'':' ';
+ // the name and po_id
+ // $r.=sprintf("%s ",$row['po_id']);
+ $r.=sprintf("%s ",h($row['po_name']));
+ $r.=sprintf("%12.2f ",$row['sum_deb']);
+ $r.=sprintf("%12.2f ",$row['sum_cred']);
+ $r.=sprintf("%12.2f ",$row['solde']);
+ $deb=($row['sum_deb'] > $row['sum_cred'])?"D":"C";
+ $deb=($row['solde'] == 0 )?'':$deb;
+ $r.=sprintf("%s ",$deb);
+ $r.="";
+ }
+ $r.="
";
+ return $r;
+ }
+ /*!
+ * \brief Compute the form to display
+ * \param $p_hidden hidden tag to be included (gDossier,...)
+ *
+ *
+ * \return string containing the data
+ */
+ function display_form($p_string="")
+ {
+ $r=parent::display_form($p_string);
- $r.= HtmlInput::submit('Affiche','Affiche');
+ $r.= HtmlInput::submit('Affiche','Affiche');
- return $r;
- }
+ return $r;
+ }
-/*!
- * \brief Display the result in pdf
- *
- * \return none
- */
- function display_pdf()
- {
- $array=$this->load();
- $pdf=new PDFBalance_Simple($this->db);
- $pdf->set_info($this->from_poste,$this->to_poste,$this->from,$this->to);
- $pdf->AliasNbPages();
- $pdf->AddPage();
+ /*!
+ * \brief Display the result in pdf
+ *
+ * \return none
+ */
+ function display_pdf()
+ {
+ $array=$this->load();
+ $pdf=new PDFBalance_Simple($this->db);
+ $pdf->set_info($this->from_poste,$this->to_poste,$this->from,$this->to);
+ $pdf->AliasNbPages();
+ $pdf->AddPage();
- $pdf->SetFont('DejaVu','',6);
- for ($i=0;$iCell(20,6,$row['po_id'],0,0,'L');
- $pdf->Cell(90,6,$row['po_name'],0,0,'L');
- $pdf->Cell(20,6,sprintf('%.2f',$row['sum_deb']),0,0,'R');
- $pdf->Cell(20,6,sprintf('%.2f',$row['sum_cred']),0,0,'R');
- $pdf->Cell(20,6,sprintf('%.2f',$row['solde']),0,0,'R');
- $pdf->Cell(20,6,$row['debit'],0,0,'R');
- $pdf->Ln();
- }
- $fDate=date('dmy-Hi');
- $pdf->output('simple-balance-'.$fDate.'.pdf','I');
+ $pdf->SetFont('DejaVu','',6);
+ for ($i=0;$iCell(20,6,$row['po_id'],0,0,'L');
+ $pdf->Cell(90,6,$row['po_name'],0,0,'L');
+ $pdf->Cell(20,6,sprintf('%.2f',$row['sum_deb']),0,0,'R');
+ $pdf->Cell(20,6,sprintf('%.2f',$row['sum_cred']),0,0,'R');
+ $pdf->Cell(20,6,sprintf('%.2f',$row['solde']),0,0,'R');
+ $pdf->Cell(20,6,$row['debit'],0,0,'R');
+ $pdf->Ln();
+ }
+ $fDate=date('dmy-Hi');
+ $pdf->output('simple-balance-'.$fDate.'.pdf','I');
- }
-/*!
- * \brief Compute the csv export
- * \return string with the csv
- */
- function display_csv()
- {
- $array=$this->load();
- if ( is_array($array) == false ){
- return $array;
+ }
+ /*!
+ * \brief Compute the csv export
+ * \return string with the csv
+ */
+ function display_csv()
+ {
+ $array=$this->load();
+ if ( is_array($array) == false )
+ {
+ return $array;
- }
- $r="";
- foreach ( $array as $row) {
- // the name and po_id
- $solde=($row['sum_cred']>$row['sum_deb'])?'C':'D';
- $solde=($row['sum_cred']==$row['sum_deb'])?'':$solde;
- $r.=sprintf("'%s',",$row['po_id']);
- $r.=sprintf("'%s',",$row['po_name']);
- $r.=sprintf("%12.2f,",$row['sum_deb']);
- $r.=sprintf("%12.2f,",$row['sum_cred']);
- $r.=sprintf("%12.2f,",$row['solde']);
- $r.=sprintf("'%s'",$row['debit']);
- $r.="\r\n";
- }
- return $r;
+ }
+ $r="";
+ foreach ( $array as $row)
+ {
+ // the name and po_id
+ $solde=($row['sum_cred']>$row['sum_deb'])?'C':'D';
+ $solde=($row['sum_cred']==$row['sum_deb'])?'':$solde;
+ $r.=sprintf("'%s',",$row['po_id']);
+ $r.=sprintf("'%s',",$row['po_name']);
+ $r.=sprintf("%12.2f,",$row['sum_deb']);
+ $r.=sprintf("%12.2f,",$row['sum_cred']);
+ $r.=sprintf("%12.2f,",$row['solde']);
+ $r.=sprintf("'%s'",$row['debit']);
+ $r.="\r\n";
+ }
+ return $r;
- }
-/*!
- * \brief Show the button to export in PDF or CSV
- * \param $url_csv url of the csv
- * \param $url_pdf url of the pdf
- * \param $p_string hidden data to include in the form
- *
- *
- * \return string with the button
- */
- function show_button($url_csv,$url_pdf,$p_string="")
- {
- $r="";
- $r.= '';
- $r.= $p_string;
- $r.= dossier::hidden();
- $r.= HtmlInput::hidden("to",$this->to);
- $r.= HtmlInput::hidden("from",$this->from);
- $r.= HtmlInput::hidden("pa_id",$this->pa_id);
- $r.= HtmlInput::hidden("from_poste",$this->from_poste);
- $r.= HtmlInput::hidden("to_poste",$this->to_poste);
- $r.=HtmlInput::submit('bt_pdf',"Export en PDF");
- $r.= ' ';
+ }
+ /*!
+ * \brief Show the button to export in PDF or CSV
+ * \param $url_csv url of the csv
+ * \param $url_pdf url of the pdf
+ * \param $p_string hidden data to include in the form
+ *
+ *
+ * \return string with the button
+ */
+ function show_button($url_csv,$url_pdf,$p_string="")
+ {
+ $r="";
+ $r.= '';
+ $r.= $p_string;
+ $r.= dossier::hidden();
+ $r.= HtmlInput::hidden("to",$this->to);
+ $r.= HtmlInput::hidden("from",$this->from);
+ $r.= HtmlInput::hidden("pa_id",$this->pa_id);
+ $r.= HtmlInput::hidden("from_poste",$this->from_poste);
+ $r.= HtmlInput::hidden("to_poste",$this->to_poste);
+ $r.=HtmlInput::submit('bt_pdf',"Export en PDF");
+ $r.= ' ';
- $r.= '';
- $r.= HtmlInput::hidden("to",$this->to);
- $r.= HtmlInput::hidden("from",$this->from);
- $r.= HtmlInput::hidden("pa_id",$this->pa_id);
- $r.= HtmlInput::hidden("from_poste",$this->from_poste);
- $r.= HtmlInput::hidden("to_poste",$this->to_poste);
- $r.= $p_string;
- $r.= dossier::hidden();
- $r.=HtmlInput::submit('bt_csv',"Export en CSV");
- $r.= ' ';
- return $r;
-}
-
-/*!
- * \brief for testing and debuggind the class
- * it must never be called from production system, it is
- * intended only for developpers
- * \param
- * \param
- * \param
- *
- *
- * \return none
- */
-static function test_me () {
- // call the page with ?gDossier=14
- $a=new Database(dossier::id());
-
- $bal=new Anc_Balance_Simple($a);
- $bal->get_request();
-
- echo '';
-
- echo $bal->display_form();
- echo ' ';
- if ( isset($_GET['result'])) {
- echo $bal->show_button("","");
- echo "HTML ";
- echo $bal->display_html();
- echo "CSV ";
- echo $bal->display_csv();
-/* echo "pdf "; */
-/* echo $bal->display_pdf(); */
-
- }
-
-}
+ $r.= '';
+ $r.= HtmlInput::hidden("to",$this->to);
+ $r.= HtmlInput::hidden("from",$this->from);
+ $r.= HtmlInput::hidden("pa_id",$this->pa_id);
+ $r.= HtmlInput::hidden("from_poste",$this->from_poste);
+ $r.= HtmlInput::hidden("to_poste",$this->to_poste);
+ $r.= $p_string;
+ $r.= dossier::hidden();
+ $r.=HtmlInput::submit('bt_csv',"Export en CSV");
+ $r.= ' ';
+ return $r;
+ }
+
+ /*!
+ * \brief for testing and debuggind the class
+ * it must never be called from production system, it is
+ * intended only for developpers
+ * \param
+ * \param
+ * \param
+ *
+ *
+ * \return none
+ */
+ static function test_me ()
+ {
+ // call the page with ?gDossier=14
+ $a=new Database(dossier::id());
+
+ $bal=new Anc_Balance_Simple($a);
+ $bal->get_request();
+
+ echo '';
+
+ echo $bal->display_form();
+ echo ' ';
+ if ( isset($_GET['result']))
+ {
+ echo $bal->show_button("","");
+ echo "HTML ";
+ echo $bal->display_html();
+ echo "CSV ";
+ echo $bal->display_csv();
+ /* echo "pdf "; */
+ /* echo $bal->display_pdf(); */
+
+ }
+
+ }
}
diff --git a/include/class_anc_group.php b/include/class_anc_group.php
index 1a57073d4..f05fa7324 100644
--- a/include/class_anc_group.php
+++ b/include/class_anc_group.php
@@ -20,7 +20,7 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*!\file
+/*!\file
* \brief class for the group of the analytic account
*
*/
@@ -31,106 +31,120 @@ require_once ('class_dossier.php');
/*! \brief class for the group of the analytic account
*
*/
-class Anc_Group {
- var $db;
- var $ga_id;
- var $ga_description;
- var $pa_id;
+class Anc_Group
+{
+ var $db;
+ var $ga_id;
+ var $ga_description;
+ var $pa_id;
- function __construct ( $p_cn ) {
- $this->db=$p_cn;
- $this->ga_id=null;
- $this->ga_description=null;
- $this->pa_id=null;
- }
- /*!
- * \brief insert into the database an object
- * \return message with error otherwise an empty string
- */
-
- function insert() {
- $sql=" insert into groupe_analytique (ga_id,ga_description,pa_id) values ('%s','%s',%d)";
- $sql=sprintf($sql,Database::escape_string($this->ga_id),
- Database::escape_string($this->ga_description),
- $this->pa_id);
- try {
- $this->db->exec_sql($sql);
- } catch (Exception $a) {
- return 'Doublon !! ';
+ function __construct ( $p_cn )
+ {
+ $this->db=$p_cn;
+ $this->ga_id=null;
+ $this->ga_description=null;
+ $this->pa_id=null;
}
- return "";
- }
- /*!
- * \brief remove from the database
- */
-
- function remove() {
- $this->ga_id=str_replace(' ','',$this->ga_id);
- $this->ga_id=strtoupper($this->ga_id);
- $sql=" delete from groupe_analytique where ga_id='".Database::escape_string($this->ga_id)."'";
+ /*!
+ * \brief insert into the database an object
+ * \return message with error otherwise an empty string
+ */
- $this->db->exec_sql($sql);
- }
-
- /*!
- * \brief load from the database and make an object
- */
- function load() {
- $sql="select ga_id, ga_description,pa_id from groupe_analytique where".
- " ga_id = ".$this->ga_id;
- $res=$this->db->exec_sql($sql);
- $array=Database::fetch_all($res);
- if ( ! empty($array) ) {
- $this->ga_id=$array['ga_id'];
- $this->ga_description=$array['ga_description'];
- $this->pa_id=$array['pa_id'];
+ function insert()
+ {
+ $sql=" insert into groupe_analytique (ga_id,ga_description,pa_id) values ('%s','%s',%d)";
+ $sql=sprintf($sql,Database::escape_string($this->ga_id),
+ Database::escape_string($this->ga_description),
+ $this->pa_id);
+ try
+ {
+ $this->db->exec_sql($sql);
+ }
+ catch (Exception $a)
+ {
+ return 'Doublon !! ';
+ }
+ return "";
}
- }
+ /*!
+ * \brief remove from the database
+ */
- /*!
- * \brief fill the object thanks an array
- * \param array
- */
- function get_from_array($p_array) {
- $this->ga_id=$p_array['ga_id'];
- $this->pa_id=$p_array['pa_id'];
- $this->ga_description=$p_array['ga_description'];
- }
- function myList() {
- $sql=" select ga_id,groupe_analytique.pa_id,pa_name,ga_description ".
- " from groupe_analytique ".
- " join plan_analytique using (pa_id)";
- $r=$this->db->exec_sql($sql);
- $array=Database::fetch_all($r);
- $res=array();
- if ( ! empty($array)) {
- foreach ($array as $m ) {
- $obj= new Anc_Group($this->db);
- $obj->get_from_array($m);
- $obj->pa_name=$m['pa_name'];
- $res[]=clone $obj;
- }
+ function remove()
+ {
+ $this->ga_id=str_replace(' ','',$this->ga_id);
+ $this->ga_id=strtoupper($this->ga_id);
+ $sql=" delete from groupe_analytique where ga_id='".Database::escape_string($this->ga_id)."'";
+
+ $this->db->exec_sql($sql);
}
- return $res;
- }
- static function test_me() {
- $cn=new Database(dossier::id());
- print_r($cn);
- $o=new Anc_Group($cn);
- $r=$o->myList();
- print_r($r);
- echo ' ';
- print_r($o);
- $o->ga_id="DD' dd dDD";
- $o->ga_description="Test 1";
- $o->remove();
- // $o->insert();
- $o->ga_id="DD";
- $o->ga_description="Test 1";
- $o->remove();
+ /*!
+ * \brief load from the database and make an object
+ */
+ function load()
+ {
+ $sql="select ga_id, ga_description,pa_id from groupe_analytique where".
+ " ga_id = ".$this->ga_id;
+ $res=$this->db->exec_sql($sql);
+ $array=Database::fetch_all($res);
+ if ( ! empty($array) )
+ {
+ $this->ga_id=$array['ga_id'];
+ $this->ga_description=$array['ga_description'];
+ $this->pa_id=$array['pa_id'];
+ }
+ }
- $r=$o->myList();
- print_r($r);
- }
+ /*!
+ * \brief fill the object thanks an array
+ * \param array
+ */
+ function get_from_array($p_array)
+ {
+ $this->ga_id=$p_array['ga_id'];
+ $this->pa_id=$p_array['pa_id'];
+ $this->ga_description=$p_array['ga_description'];
+ }
+ function myList()
+ {
+ $sql=" select ga_id,groupe_analytique.pa_id,pa_name,ga_description ".
+ " from groupe_analytique ".
+ " join plan_analytique using (pa_id)";
+ $r=$this->db->exec_sql($sql);
+ $array=Database::fetch_all($r);
+ $res=array();
+ if ( ! empty($array))
+ {
+ foreach ($array as $m )
+ {
+ $obj= new Anc_Group($this->db);
+ $obj->get_from_array($m);
+ $obj->pa_name=$m['pa_name'];
+ $res[]=clone $obj;
+ }
+ }
+ return $res;
+ }
+ static function test_me()
+ {
+
+ $cn=new Database(dossier::id());
+ print_r($cn);
+ $o=new Anc_Group($cn);
+ $r=$o->myList();
+ print_r($r);
+ echo ' ';
+ print_r($o);
+ $o->ga_id="DD' dd dDD";
+ $o->ga_description="Test 1";
+ $o->remove();
+ // $o->insert();
+ $o->ga_id="DD";
+ $o->ga_description="Test 1";
+ $o->remove();
+
+ $r=$o->myList();
+ print_r($r);
+ }
}
diff --git a/include/class_anc_group_operation.php b/include/class_anc_group_operation.php
index 6a512f866..8665bab2f 100644
--- a/include/class_anc_group_operation.php
+++ b/include/class_anc_group_operation.php
@@ -38,219 +38,242 @@ require_once ('class_dossier.php');
class Anc_Group_Operation
{
- var $db; /*!< database connection */
- var $id; /*!< oa_group, a group contains
- several rows of
- operation_analytique linked by the
- group id */
+ var $db; /*!< database connection */
+ var $id; /*!< oa_group, a group contains
+ several rows of
+ operation_analytique linked by the
+ group id */
- var $a_operation; /*!< array of operations */
- var $date; /*!< date of the operations */
- var $pa_id; /*!< the concerned pa_id */
+ var $a_operation; /*!< array of operations */
+ var $date; /*!< date of the operations */
+ var $pa_id; /*!< the concerned pa_id */
- /*!\brief constructor */
- function Anc_Group_Operation($p_cn,$p_id=0)
- {
- $this->db=$p_cn;
- $this->id=$p_id;
- $this->date=date("d.m.Y");
- $this->nMaxRow=10;
- }
- /*!\brief add several rows */
- function add() {
-
- $amount=0;
- try {
- $this->db->start();
- foreach ($this->a_operation as $row) {
- $add=round($row->oa_amount,2);
- $add=($row->oa_debit=='t')?$add:$add*(-1);
- $amount+=round($add,2);
- $row->add();
- }
- if ( $amount != 0 ) throw new Exception (_('Operation non equilibrée'));
- } catch (Exception $e) {
- echo $e->getTrace();
- $this->db->rollback();
- exit();
+ /*!\brief constructor */
+ function Anc_Group_Operation($p_cn,$p_id=0)
+ {
+ $this->db=$p_cn;
+ $this->id=$p_id;
+ $this->date=date("d.m.Y");
+ $this->nMaxRow=10;
}
- $this->db->commit();
- }
- /*!\brief show a form for the operation (several rows)
- * \return the string containing the form but without the form tag
- *
- */
- function form($p_readonly=0){
- $wDate=new IDate("pdate",$this->date);
- $wDate->table=1;
- $wDate->size=10;
- $wDate->readonly=$p_readonly;
+ /*!\brief add several rows */
+ function add()
+ {
- $wDescription=new IText("pdesc");
- $wDescription->table=0;
- $wDescription->size=80;
- $wDescription->readonly=$p_readonly;
- // Show an existing operation
- //
- if ( isset ($this->a_operation[0])) {
- $wDate->value=$this->a_operation[0]->oa_date;
- $wDescription->value=$this->a_operation[0]->oa_description;
- }
-
- $ret="";
-
- $ret.='';
-
- $ret.="".$wDate->input()." ";
- $ret.='Description '.
- ''.
- $wDescription->input()." ";
- $Plan=new Anc_Plan($this->db);
- $aPlan=$Plan->get_list();
- $max=(count($this->a_operation)<$this->nMaxRow)?$this->nMaxRow:count($this->a_operation);
- $ret.='
';
- /* show 10 rows */
- $ret.="";
- foreach ($aPlan as $d)
- {
- $idx=$d['id'];
- /* array of possible value for the select */
- $aPoste[$idx]=$this->db->make_array("select po_id as value,".
- " html_quote(po_name||':'||coalesce(po_description,'-')) as label ".
- " from poste_analytique ".
- " where pa_id = ".$idx.
- " order by po_name ");
-
- $ret.=" Poste ";
- }
- $ret.=" ".
- " Montant ".
- "Débit ".
- " ";
-
- for ($i = 0;$i < $max;$i++)
- {
- $ret.="";
-
- foreach ($aPlan as $d)
- {
- $idx=$d['id'];
- // init variable
- $wSelect=new ISelect("pop".$i."plan".$idx);
- $wSelect->value=$aPoste[$idx];
- $wSelect->size=12;
-
- $wSelect->readOnly=$p_readonly;
- if ( isset($this->a_operation[$i])) {
- $wSelect->selected=$this->a_operation[$i]->po_id;
- }
- $ret.=td($wSelect->input());
- }
- $wAmount=new INum("pamount$i",0.0);
- $wAmount->size=12;
- $wAmount->table=1;
- $wAmount->javascript=" onChange=format_number(this);caod_checkTotal()";
- $wAmount->readOnly=$p_readonly;
-
- $wDebit=new ICheckBox("pdeb$i");
- $wDebit->readOnly=$p_readonly;
- $wDebit->javascript=" onChange=caod_checkTotal()";
- if ( isset ($this->a_operation[$i])) {
- $wSelect->selected=$this->a_operation[$i]->po_id;
- $wAmount->value=$this->a_operation[$i]->oa_amount;
- $wDebit->value=$this->a_operation[$i]->oa_debit;
- if ( $wDebit->value=='t') { $wDebit->selected=true;}
- }
-
- // build the table
-
- $ret.=" ";
- $ret.=$wAmount->input();
- $ret.=td($wDebit->input());
-
- $ret.=" ";
- }
- $ret.="
";
- if ( $p_readonly==false) {
- $add_row=new IButton('Ajouter');
- $add_row->label=_('Ajouter une ligne');
- $add_row->javascript='anc_add_row(\'ago\');';
- $ret.=HtmlInput::hidden('nbrow',$max);
-
- $ret.=$add_row->input();
- }
- return $ret;
- }
- /*!\brief fill row from $_POST data
- *
- */
- function get_from_array($p_array) {
- $Plan=new Anc_Plan($this->db);
- $aPlan=$Plan->get_list();
-
-
- for ( $i = 0;$i <$p_array['nbrow'];$i++) {
- foreach ($aPlan as $d)
- {
- $idx=$d['id'];
- $p=new Anc_Operation($this->db);
- $p->oa_amount=$p_array["pamount$i"];
-
- $p->oa_description=$p_array["pdesc"];
- $p->oa_date=$p_array['pdate'];
- $p->j_id=0;
- $p->oa_debit=(isset ($p_array["pdeb$i"]))?'t':'f';
- $p->oa_group=0;
-
- $p->po_id=$p_array["pop$i"."plan".$idx];
- $p->pa_id=$idx;
- $this->a_operation[]=clone $p;
- }
- }
- }
- /*!\brief save the group of operation but only if the amount is
- balanced */
- function save() {
- $this->db->start();
- try {
- $oa_group=$this->db->get_next_seq('s_oa_group');
- for ($i=0;$ia_operation);$i++) {
- $this->a_operation[$i]->oa_group=$oa_group;
- $this->a_operation[$i]->add();
- }
- } catch (Exception $ex) {
- echo ''.
- 'Erreur dans l\'enregistrement '.
- __FILE__.':'.__LINE__.' '.
- $ex->getMessage();
- $p_cn->rollback();
- exit();
-
- }
- $this->db->commit();
- }
- /*!\brief show the form */
- function show() {
- return $this->form(1);
- }
- static function test_me()
- {
- $dossier=dossier::id();
- $cn=new Database($dossier);
-
- if ( isset($_POST['go'])) {
- $b=new Anc_Group_Operation($cn);
- $b->get_from_array($_POST);
- exit();
+ $amount=0;
+ try
+ {
+ $this->db->start();
+ foreach ($this->a_operation as $row)
+ {
+ $add=round($row->oa_amount,2);
+ $add=($row->oa_debit=='t')?$add:$add*(-1);
+ $amount+=round($add,2);
+ $row->add();
+ }
+ if ( $amount != 0 ) throw new Exception (_('Operation non equilibrée'));
+ }
+ catch (Exception $e)
+ {
+ echo $e->getTrace();
+ $this->db->rollback();
+ exit();
+ }
+ $this->db->commit();
}
+ /*!\brief show a form for the operation (several rows)
+ * \return the string containing the form but without the form tag
+ *
+ */
+ function form($p_readonly=0)
+ {
+ $wDate=new IDate("pdate",$this->date);
+ $wDate->table=1;
+ $wDate->size=10;
+ $wDate->readonly=$p_readonly;
- $a=new Anc_Group_Operation($cn);
- echo '';
- echo $a->form();
- echo dossier::hidden();
- echo ' ';
- echo ' ';
+ $wDescription=new IText("pdesc");
+ $wDescription->table=0;
+ $wDescription->size=80;
+ $wDescription->readonly=$p_readonly;
+ // Show an existing operation
+ //
+ if ( isset ($this->a_operation[0]))
+ {
+ $wDate->value=$this->a_operation[0]->oa_date;
+ $wDescription->value=$this->a_operation[0]->oa_description;
+ }
- }
+ $ret="";
+
+ $ret.='';
+
+ $ret.="".$wDate->input()." ";
+ $ret.='Description '.
+ ''.
+ $wDescription->input()." ";
+ $Plan=new Anc_Plan($this->db);
+ $aPlan=$Plan->get_list();
+ $max=(count($this->a_operation)<$this->nMaxRow)?$this->nMaxRow:count($this->a_operation);
+ $ret.='
';
+ /* show 10 rows */
+ $ret.="";
+ foreach ($aPlan as $d)
+ {
+ $idx=$d['id'];
+ /* array of possible value for the select */
+ $aPoste[$idx]=$this->db->make_array("select po_id as value,".
+ " html_quote(po_name||':'||coalesce(po_description,'-')) as label ".
+ " from poste_analytique ".
+ " where pa_id = ".$idx.
+ " order by po_name ");
+
+ $ret.=" Poste ";
+ }
+ $ret.=" ".
+ " Montant ".
+ "Débit ".
+ " ";
+
+ for ($i = 0;$i < $max;$i++)
+ {
+ $ret.="";
+
+ foreach ($aPlan as $d)
+ {
+ $idx=$d['id'];
+ // init variable
+ $wSelect=new ISelect("pop".$i."plan".$idx);
+ $wSelect->value=$aPoste[$idx];
+ $wSelect->size=12;
+
+ $wSelect->readOnly=$p_readonly;
+ if ( isset($this->a_operation[$i]))
+ {
+ $wSelect->selected=$this->a_operation[$i]->po_id;
+ }
+ $ret.=td($wSelect->input());
+ }
+ $wAmount=new INum("pamount$i",0.0);
+ $wAmount->size=12;
+ $wAmount->table=1;
+ $wAmount->javascript=" onChange=format_number(this);caod_checkTotal()";
+ $wAmount->readOnly=$p_readonly;
+
+ $wDebit=new ICheckBox("pdeb$i");
+ $wDebit->readOnly=$p_readonly;
+ $wDebit->javascript=" onChange=caod_checkTotal()";
+ if ( isset ($this->a_operation[$i]))
+ {
+ $wSelect->selected=$this->a_operation[$i]->po_id;
+ $wAmount->value=$this->a_operation[$i]->oa_amount;
+ $wDebit->value=$this->a_operation[$i]->oa_debit;
+ if ( $wDebit->value=='t')
+ {
+ $wDebit->selected=true;
+ }
+
+ }
+
+ // build the table
+
+ $ret.=" ";
+ $ret.=$wAmount->input();
+ $ret.=td($wDebit->input());
+
+ $ret.=" ";
+ }
+ $ret.="
";
+ if ( $p_readonly==false)
+ {
+ $add_row=new IButton('Ajouter');
+ $add_row->label=_('Ajouter une ligne');
+ $add_row->javascript='anc_add_row(\'ago\');';
+ $ret.=HtmlInput::hidden('nbrow',$max);
+
+ $ret.=$add_row->input();
+ }
+ return $ret;
+ }
+ /*!\brief fill row from $_POST data
+ *
+ */
+ function get_from_array($p_array)
+ {
+ $Plan=new Anc_Plan($this->db);
+ $aPlan=$Plan->get_list();
+
+
+ for ( $i = 0;$i <$p_array['nbrow'];$i++)
+ {
+ foreach ($aPlan as $d)
+ {
+ $idx=$d['id'];
+ $p=new Anc_Operation($this->db);
+ $p->oa_amount=$p_array["pamount$i"];
+
+ $p->oa_description=$p_array["pdesc"];
+ $p->oa_date=$p_array['pdate'];
+ $p->j_id=0;
+ $p->oa_debit=(isset ($p_array["pdeb$i"]))?'t':'f';
+ $p->oa_group=0;
+
+ $p->po_id=$p_array["pop$i"."plan".$idx];
+ $p->pa_id=$idx;
+ $this->a_operation[]=clone $p;
+ }
+ }
+ }
+ /*!\brief save the group of operation but only if the amount is
+ balanced */
+ function save()
+ {
+ $this->db->start();
+ try
+ {
+ $oa_group=$this->db->get_next_seq('s_oa_group');
+ for ($i=0;$ia_operation);$i++)
+ {
+ $this->a_operation[$i]->oa_group=$oa_group;
+ $this->a_operation[$i]->add();
+ }
+ }
+ catch (Exception $ex)
+ {
+ echo ''.
+ 'Erreur dans l\'enregistrement '.
+ __FILE__.':'.__LINE__.' '.
+ $ex->getMessage();
+ $p_cn->rollback();
+ exit();
+
+ }
+ $this->db->commit();
+ }
+ /*!\brief show the form */
+ function show()
+ {
+ return $this->form(1);
+ }
+ static function test_me()
+ {
+ $dossier=dossier::id();
+ $cn=new Database($dossier);
+
+ if ( isset($_POST['go']))
+ {
+ $b=new Anc_Group_Operation($cn);
+ $b->get_from_array($_POST);
+ exit();
+ }
+
+ $a=new Anc_Group_Operation($cn);
+ echo '';
+ echo $a->form();
+ echo dossier::hidden();
+ echo ' ';
+ echo ' ';
+
+ }
}
diff --git a/include/class_anc_listing.php b/include/class_anc_listing.php
index df0bff77c..174d9a67b 100644
--- a/include/class_anc_listing.php
+++ b/include/class_anc_listing.php
@@ -34,150 +34,163 @@ require_once ('class_anc_operation.php');
* \return
*/
-class Anc_Listing extends Anc_Print {
- function display_form($p_string="") {
- echo '';
- $r=parent::display_form($p_string);
- $r.=HtmlInput::submit('result','Afficher');
- $r.= ' ';
- return $r;
+class Anc_Listing extends Anc_Print
+{
+ function display_form($p_string="")
+ {
+ echo '';
+ $r=parent::display_form($p_string);
+ $r.=HtmlInput::submit('result','Afficher');
+ $r.= ' ';
+ return $r;
- }
-/*!
- * \brief complete the object with the data in $_REQUEST
- */
+ }
+ /*!
+ * \brief complete the object with the data in $_REQUEST
+ */
- function get_request() {
- parent::get_request();
- $this->pa_id=(isset($_REQUEST['pa_id']))?$_REQUEST['pa_id']:"";
- }
-/*!
- * \brief compute the html display
- *
- *
- * \return string
- */
+ function get_request()
+ {
+ parent::get_request();
+ $this->pa_id=(isset($_REQUEST['pa_id']))?$_REQUEST['pa_id']:"";
+ }
+ /*!
+ * \brief compute the html display
+ *
+ *
+ * \return string
+ */
- function display_html() {
- $r="";
- //---Html
- $array=$this->load();
- if ( is_array($array) == false ){
- return $array;
+ function display_html()
+ {
+ $r="";
+ //---Html
+ $array=$this->load();
+ if ( is_array($array) == false )
+ {
+ return $array;
- }
+ }
- if ( empty($array) ) { $r.= _("aucune donnée"); return $r;}
- $r.= '';
- $r.= ''.
- ''._('Date').' '.
- ''._('Nom').' '.
- ''._('Description').' '.
- ''._('Montant').' '.
- ''._('D/C').' '.
- ' ';
- foreach ( $array as $row ) {
- $r.= '';
- $r.=
- ''.$row['oa_date'].' '.
- ''.h($row['po_name']).' '.
- ''.h($row['oa_description']).' '.
- ''.$row['oa_amount'].' '.
- ''.(($row['oa_debit']=='f')?'CREDIT':'DEBIT').' ';
- $r.= ' ';
- }
- $r.= '
';
- return $r;
- }
-/*!
- * \brief load the data from the database
- *
- * \return array
- */
- function load()
- {
- $op=new Anc_Operation ($this->db);
- $op->pa_id=$this->pa_id;
- $array=$op->get_list($this->from,$this->to,$this->from_poste,$this->to_poste);
- return $array;
- }
-/*!
- * \brief Compute the csv export
- * \return string with the csv
- */
+ if ( empty($array) )
+ {
+ $r.= _("aucune donnée");
+ return $r;
+ }
+ $r.= '';
+ $r.= ''.
+ ''._('Date').' '.
+ ''._('Nom').' '.
+ ''._('Description').' '.
+ ''._('Montant').' '.
+ ''._('D/C').' '.
+ ' ';
+ foreach ( $array as $row )
+ {
+ $r.= '';
+ $r.=
+ ''.$row['oa_date'].' '.
+ ''.h($row['po_name']).' '.
+ ''.h($row['oa_description']).' '.
+ ''.$row['oa_amount'].' '.
+ ''.(($row['oa_debit']=='f')?'CREDIT':'DEBIT').' ';
+ $r.= ' ';
+ }
+ $r.= '
';
+ return $r;
+ }
+ /*!
+ * \brief load the data from the database
+ *
+ * \return array
+ */
+ function load()
+ {
+ $op=new Anc_Operation ($this->db);
+ $op->pa_id=$this->pa_id;
+ $array=$op->get_list($this->from,$this->to,$this->from_poste,$this->to_poste);
+ return $array;
+ }
+ /*!
+ * \brief Compute the csv export
+ * \return string with the csv
+ */
- function display_csv()
- {
- $array=$this->load($this->from,$this->to,$this->from_poste,$this->to_poste);
- if ( empty($array) == true ){
- return $array;
+ function display_csv()
+ {
+ $array=$this->load($this->from,$this->to,$this->from_poste,$this->to_poste);
+ if ( empty($array) == true )
+ {
+ return $array;
- }
- $r="";
- foreach ( $array as $row) {
- // the name and po_id
- $r.=sprintf("'%s',",$row['oa_date']);
- $r.=sprintf("'%s',",$row['po_name']);
- $r.=sprintf("'%s',",$row['oa_description']);
- $r.=sprintf("%12.2f,",$row['oa_amount']);
- $r.=sprintf("'%s'",(($row['oa_debit']=='f')?'CREDIT':'DEBIT'));
- $r.="\r\n";
- }
- return $r;
+ }
+ $r="";
+ foreach ( $array as $row)
+ {
+ // the name and po_id
+ $r.=sprintf("'%s',",$row['oa_date']);
+ $r.=sprintf("'%s',",$row['po_name']);
+ $r.=sprintf("'%s',",$row['oa_description']);
+ $r.=sprintf("%12.2f,",$row['oa_amount']);
+ $r.=sprintf("'%s'",(($row['oa_debit']=='f')?'CREDIT':'DEBIT'));
+ $r.="\r\n";
+ }
+ return $r;
- }
+ }
-/*!
- * \brief show the export button to pdf and CSV
- * \param $p_string string containing some HTML tag as hidden field
- * \param
- * \param
- *
- *
- * \return string containing the html code
- */
- function show_button($p_string='') {
- $r="";
- $submit=HtmlInput::submit('','');
- $hidden=new IHidden();
- /* for the export in PDF
- * Not yet needed, the html print should be enough
- $r.= '';
- $r.= $p_string;
- $r.= dossier::hidden();
- $r.= $hidden->input("to",$this->to);
- $r.= $hidden->input("from",$this->from);
- $r.= $hidden->input("pa_id",$this->pa_id);
- $r.= $hidden->input("from_poste",$this->from_poste);
- $r.= $hidden->input("to_poste",$this->to_poste);
- $r.=HtmlInput::submit('bt_pdf',"Export en PDF");
- $r.= ' ';
- */
+ /*!
+ * \brief show the export button to pdf and CSV
+ * \param $p_string string containing some HTML tag as hidden field
+ * \param
+ * \param
+ *
+ *
+ * \return string containing the html code
+ */
+ function show_button($p_string='')
+ {
+ $r="";
+ $submit=HtmlInput::submit('','');
+ $hidden=new IHidden();
+ /* for the export in PDF
+ * Not yet needed, the html print should be enough
+ $r.= '';
+ $r.= $p_string;
+ $r.= dossier::hidden();
+ $r.= $hidden->input("to",$this->to);
+ $r.= $hidden->input("from",$this->from);
+ $r.= $hidden->input("pa_id",$this->pa_id);
+ $r.= $hidden->input("from_poste",$this->from_poste);
+ $r.= $hidden->input("to_poste",$this->to_poste);
+ $r.=HtmlInput::submit('bt_pdf',"Export en PDF");
+ $r.= ' ';
+ */
- $r.= '';
- $r.= HtmlInput::hidden("to",$this->to);
- $r.= HtmlInput::hidden("from",$this->from);
- $r.= HtmlInput::hidden("pa_id",$this->pa_id);
- $r.= HtmlInput::hidden("from_poste",$this->from_poste);
- $r.= HtmlInput::hidden("to_poste",$this->to_poste);
+ $r.= ' ';
+ $r.= HtmlInput::hidden("to",$this->to);
+ $r.= HtmlInput::hidden("from",$this->from);
+ $r.= HtmlInput::hidden("pa_id",$this->pa_id);
+ $r.= HtmlInput::hidden("from_poste",$this->from_poste);
+ $r.= HtmlInput::hidden("to_poste",$this->to_poste);
- $r.= $p_string;
- $r.= dossier::hidden();
- $r.=HtmlInput::submit('bt_csv',"Export en CSV");
- $r.= ' ';
- return $r;
+ $r.= $p_string;
+ $r.= dossier::hidden();
+ $r.=HtmlInput::submit('bt_csv',"Export en CSV");
+ $r.= '';
+ return $r;
- }
-/*!
- * \brief debugging and test function for dev. only
- * \param
- * \param
- * \param
- *
- *
- * \return
- */
-static function test_me() {
-
- }
+ }
+ /*!
+ * \brief debugging and test function for dev. only
+ * \param
+ * \param
+ * \param
+ *
+ *
+ * \return
+ */
+ static function test_me()
+ {
+ }
}
diff --git a/include/class_anc_operation.php b/include/class_anc_operation.php
index 19f9c5e15..9c3a4f6b8 100644
--- a/include/class_anc_operation.php
+++ b/include/class_anc_operation.php
@@ -37,621 +37,668 @@ require_once ("user_common.php");
*/
class Anc_Operation
{
- var $db; /*!< database connection */
- var $row; /*!< array of row for one operation*/
- var $list; /*!< array of all operation */
- var $id; /*!< = oa_id (one row) */
- var $po_id; /*!< poste analytique */
- var $oa_amount; /*!< amount for one row */
- var $oa_description; /*!< comment for one row */
- var $oa_debit; /*!< true for debit or false */
- var $j_id; /*!< foreign key to a jrnx operation
- (or null if none */
- var $oa_group; /*!< group of operation */
- var $oa_date; /*!< equal to j_date if j_id is not null */
- var $pa_id; /*!< the plan analytique id */
+ var $db; /*!< database connection */
+ var $row; /*!< array of row for one operation*/
+ var $list; /*!< array of all operation */
+ var $id; /*!< = oa_id (one row) */
+ var $po_id; /*!< poste analytique */
+ var $oa_amount; /*!< amount for one row */
+ var $oa_description; /*!< comment for one row */
+ var $oa_debit; /*!< true for debit or false */
+ var $j_id; /*!< foreign key to a jrnx operation
+ (or null if none */
+ var $oa_group; /*!< group of operation */
+ var $oa_date; /*!< equal to j_date if j_id is not null */
+ var $pa_id; /*!< the plan analytique id */
- /*!\brief constructor
- *
- */
- function Anc_Operation ($p_cn,$p_id=0) {
- $this->db=$p_cn;
- $this->id=$p_id;
- }
- /*!\brief add a row to the table operation_analytique
- * \note if $this->oa_group if 0 then a sequence id will be computed for
- * the oa_group, if $this->j_id=0 then it will be null
- *
- */
- function add($p_seq=0) {
+ /*!\brief constructor
+ *
+ */
+ function Anc_Operation ($p_cn,$p_id=0)
+ {
+ $this->db=$p_cn;
+ $this->id=$p_id;
+ }
+ /*!\brief add a row to the table operation_analytique
+ * \note if $this->oa_group if 0 then a sequence id will be computed for
+ * the oa_group, if $this->j_id=0 then it will be null
+ *
+ */
+ function add($p_seq=0)
+ {
- if ( $this->oa_group == 0) {
- $this->oa_group=$this->db->get_next_seq('s_oa_group');
- }
+ if ( $this->oa_group == 0)
+ {
+ $this->oa_group=$this->db->get_next_seq('s_oa_group');
+ }
- if ( $this->j_id == 0 ) {
- $this->j_id="null";
- }
+ if ( $this->j_id == 0 )
+ {
+ $this->j_id="null";
+ }
- // we don't save null operations
- if ( $this->oa_amount == 0 || $this->po_id==-1)
- return;
+ // we don't save null operations
+ if ( $this->oa_amount == 0 || $this->po_id==-1)
+ return;
- $oa_row=(isset($this->oa_row))?$this->oa_row:"NULL";
- $sql='insert into operation_analytique (
- po_id,
- pa_id,
- oa_amount,
- oa_description,
- oa_debit,
- oa_group,
- j_id,
- oa_date,
- oa_row
- ) values ('.
- $this->po_id.",".
- $this->pa_id.",".
- $this->oa_amount.",".
- "' ".Database::escape_string($this->oa_description)."',".
- "'".$this->oa_debit."',".
- $this->oa_group.",".
- $this->j_id.",".
- "to_date('".$this->oa_date."','DD.MM.YYYY'),".$oa_row.")";
+ $oa_row=(isset($this->oa_row))?$this->oa_row:"NULL";
+ $sql='insert into operation_analytique (
+ po_id,
+ pa_id,
+ oa_amount,
+ oa_description,
+ oa_debit,
+ oa_group,
+ j_id,
+ oa_date,
+ oa_row
+ ) values ('.
+ $this->po_id.",".
+ $this->pa_id.",".
+ $this->oa_amount.",".
+ "' ".Database::escape_string($this->oa_description)."',".
+ "'".$this->oa_debit."',".
+ $this->oa_group.",".
+ $this->j_id.",".
+ "to_date('".$this->oa_date."','DD.MM.YYYY'),".$oa_row.")";
- $this->db->exec_sql($sql);
+ $this->db->exec_sql($sql);
- }
- /*!\brief delete a row from the table operation_analytique
- * \note be carefull : do not delete a row when we have a group
- */
- function delete() {
- $sql="delete from operation_analytique where oa_id=$1";
+ }
+ /*!\brief delete a row from the table operation_analytique
+ * \note be carefull : do not delete a row when we have a group
+ */
+ function delete()
+ {
+ $sql="delete from operation_analytique where oa_id=$1";
- $this->db->exec_sql($sql,array($this->oa_id));
- }
+ $this->db->exec_sql($sql,array($this->oa_id));
+ }
- /*!\brief get a list of row from a certain periode
- */
- function get_list($p_from,$p_to,$p_from_poste="",$p_to_poste="") {
- $cond="";
- $cond_poste="";
+ /*!\brief get a list of row from a certain periode
+ */
+ function get_list($p_from,$p_to,$p_from_poste="",$p_to_poste="")
+ {
+ $cond="";
+ $cond_poste="";
- if ($p_from!="")
- $cond="and oa_date >= to_date('$p_from','DD.MM.YYYY') ";
- if ( $p_to!="" )
- $cond.="and oa_date <=to_date('$p_to','DD.MM.YYYY')";
+ if ($p_from!="")
+ $cond="and oa_date >= to_date('$p_from','DD.MM.YYYY') ";
+ if ( $p_to!="" )
+ $cond.="and oa_date <=to_date('$p_to','DD.MM.YYYY')";
- if ($p_from_poste != "" )
- $cond_poste=" and upper(po_name) >= upper('".$p_from_poste."')";
- if ($p_to_poste != "" )
- $cond_poste.=" and upper(po_name) <= upper('".$p_to_poste."')";
- $pa_id_cond="";
- if ( isset ( $this->pa_id) && $this->pa_id !='')
- $pa_id_cond= "B.pa_id=".$this->pa_id." and";
+ if ($p_from_poste != "" )
+ $cond_poste=" and upper(po_name) >= upper('".$p_from_poste."')";
+ if ($p_to_poste != "" )
+ $cond_poste.=" and upper(po_name) <= upper('".$p_to_poste."')";
+ $pa_id_cond="";
+ if ( isset ( $this->pa_id) && $this->pa_id !='')
+ $pa_id_cond= "B.pa_id=".$this->pa_id." and";
- $sql="select oa_id,po_name,oa_description,".
- "oa_debit,to_char(oa_date,'DD.MM.YYYY') as oa_date,oa_amount,oa_group,j_id ".
- " from operation_analytique as B".
- " join poste_analytique using(po_id) ".
- "where $pa_id_cond oa_amount <> 0.0 $cond $cond_poste".
- " order by oa_date ,oa_group,oa_debit desc,oa_id";
- $RetSql=$this->db->exec_sql($sql);
+ $sql="select oa_id,po_name,oa_description,".
+ "oa_debit,to_char(oa_date,'DD.MM.YYYY') as oa_date,oa_amount,oa_group,j_id ".
+ " from operation_analytique as B".
+ " join poste_analytique using(po_id) ".
+ "where $pa_id_cond oa_amount <> 0.0 $cond $cond_poste".
+ " order by oa_date ,oa_group,oa_debit desc,oa_id";
+ $RetSql=$this->db->exec_sql($sql);
- $array=Database::fetch_all($RetSql);
- return $array;
- }
+ $array=Database::fetch_all($RetSql);
+ return $array;
+ }
- /*\brief show the HTML table for the operation
- */
- function html_table($p_from){
- if ($p_from=="")
- { $from="";$to="";}
- else {
- $p=new Periode($this->db);
- list($from,$to)=$p->get_date_limit($p_from);
- }
+ /*\brief show the HTML table for the operation
+ */
+ function html_table($p_from)
+ {
+ if ($p_from=="")
+ {
+ $from="";
+ $to="";
+ }
+ else
+ {
+ $p=new Periode($this->db);
+ list($from,$to)=$p->get_date_limit($p_from);
+ }
- $array=$this->get_list($from,$to);
- if ( empty($array) )
- return "Pas d'enregistrement trouvé";
+ $array=$this->get_list($from,$to);
+ if ( empty($array) )
+ return "Pas d'enregistrement trouvé";
- // jrn_navigation_bar
- $step=$_SESSION['g_pagesize'];
- $page=(isset($_GET['offset']))?$_GET['page']:1;
- $offset=(isset($_GET['offset']))?$_GET['offset']:0;
- $bar=jrn_navigation_bar($offset+1,count($array),$step,$page);
+ // jrn_navigation_bar
+ $step=$_SESSION['g_pagesize'];
+ $page=(isset($_GET['offset']))?$_GET['page']:1;
+ $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+ $bar=jrn_navigation_bar($offset+1,count($array),$step,$page);
- if ( $step !=-1)
- $view=array_splice($array,$offset,$step);
- else
- $view=$array;
+ if ( $step !=-1)
+ $view=array_splice($array,$offset,$step);
+ else
+ $view=$array;
- $gDossier=dossier::id();
- $ret="";
- $ret.=$bar;
- $ret.=JS_LEDGER;
- $count=0;
- $group=0;
- $oldgroup=0;
- $oldjrid=0;
+ $gDossier=dossier::id();
+ $ret="";
+ $ret.=$bar;
+ $ret.=JS_LEDGER;
+ $count=0;
+ $group=0;
+ $oldgroup=0;
+ $oldjrid=0;
- foreach ($view as $row) {
- $group=$row['oa_group'];
- if ( $group !=$oldgroup ) {
- if ( $oldgroup!=0 )
- {
+ foreach ($view as $row)
+ {
+ $group=$row['oa_group'];
+ if ( $group !=$oldgroup )
+ {
+ if ( $oldgroup!=0 )
+ {
- $efface=new IButton();
- $efface->javascript="op_remove(".$gDossier.",".$oldgroup.")";
- $efface->name="Efface";
- $efface->label="Efface";
- $ret.=" ".$efface->input()." ";
+ $efface=new IButton();
+ $efface->javascript="op_remove(".$gDossier.",".$oldgroup.")";
+ $efface->name="Efface";
+ $efface->label="Efface";
+ $ret.="".$efface->input()." ";
- $this->oa_group=$oldgroup;
- $jr_id=$this->get_jrid();
+ $this->oa_group=$oldgroup;
+ $jr_id=$this->get_jrid();
- if ( $jr_id != 0) {
- // get the old jr_id
- $detail=new IButton();
- $detail->javascript="viewOperation($jr_id,$gDossier)";
- $detail->name="Detail";
- $detail->label="Detail";
- $ret.="".$detail->input()." ";
- }
- $ret.='
';
+ if ( $jr_id != 0)
+ {
+ // get the old jr_id
+ $detail=new IButton();
+ $detail->javascript="viewOperation($jr_id,$gDossier)";
+ $detail->name="Detail";
+ $detail->label="Detail";
+ $ret.="
".$detail->input()." ";
+ }
+ $ret.='
';
- }
- $ret.='';
+ }
+ $ret.='';
- $ret.="".
- $row['oa_date'].
- " ".
- "".
- h($row['oa_description']).
- " ";
+ $ret.="".
+ $row['oa_date'].
+ " ".
+ "".
+ h($row['oa_description']).
+ " ";
- $ret.="".
- "Groupe id : ".$row['oa_group'].
- " ";
+ $ret.="".
+ "Groupe id : ".$row['oa_group'].
+ " ";
- $oldgroup=$group;
+ $oldgroup=$group;
- }
+ }
- $class=($count%2==0)?"odd":"";
- $count++;
- $cred= ( $row['oa_debit'] == 'f')?"CREDIT":"DEBIT";
- $ret.="";
- if ( $cred=='CREDIT')
- $ret.=' ';
- $ret.= "".
- h($row['po_name']).
- " ";
- if ( $cred=='DEBIT')
- $ret.=' ';
+ $class=($count%2==0)?"odd":"";
+ $count++;
+ $cred= ( $row['oa_debit'] == 'f')?"CREDIT":"DEBIT";
+ $ret.=" ";
+ if ( $cred=='CREDIT')
+ $ret.=' ';
+ $ret.= "".
+ h($row['po_name']).
+ " ";
+ if ( $cred=='DEBIT')
+ $ret.=' ';
- $ret.=''. $row['oa_amount'].
- " ".
- "".
- $cred.
- " ".
+ $ret.=''. $row['oa_amount'].
+ " ".
+ "".
+ $cred.
+ " ".
- " ";
- }
+ "";
+ }
- $efface=new IButton();
- $efface->javascript="op_remove("."$gDossier,".$oldgroup.")";
- $efface->name="Efface";
- $efface->label="Efface";
- $ret.="".$efface->input()." ";
- // get the old jr_id
- $this->oa_group=$oldgroup;
- $jr_id=$this->get_jrid();
- if ( $jr_id != 0 ){
- $detail=new IButton();
- $detail->javascript="modifyOperation($jr_id,'"."$gDossier)";
- $detail->name="Detail";
- $detail->label="Detail";
- $ret.="".$detail->input()." ";
- }
- $ret.='
';
- $ret.=$bar;
- return $ret;
- }
- /*!\brief retrieve an operation thanks a jrnx.j_id
- * \param the jrnx.j_id
- * \return false if nothing is found other true
- */
- function get_by_jid($p_jid) {
- $sql="select distinct oa_id,
- po_id,
- oa_amount,
- oa_description,
- oa_debit,
- j_id,
- oa_group,
- oa_date,
- pa_id,
- oa_row
- from operation_analytique
- where
- j_id=$p_jid order by j_id,oa_row,pa_id";
- $ret=$this->db->exec_sql($sql);
- $res=Database::fetch_all($ret);
- if ( $res== false) return null;
+ $efface=new IButton();
+ $efface->javascript="op_remove("."$gDossier,".$oldgroup.")";
+ $efface->name="Efface";
+ $efface->label="Efface";
+ $ret.="".$efface->input()." ";
+ // get the old jr_id
+ $this->oa_group=$oldgroup;
+ $jr_id=$this->get_jrid();
+ if ( $jr_id != 0 )
+ {
+ $detail=new IButton();
+ $detail->javascript="modifyOperation($jr_id,'"."$gDossier)";
+ $detail->name="Detail";
+ $detail->label="Detail";
+ $ret.="".$detail->input()." ";
+ }
+ $ret.='
';
+ $ret.=$bar;
+ return $ret;
+ }
+ /*!\brief retrieve an operation thanks a jrnx.j_id
+ * \param the jrnx.j_id
+ * \return false if nothing is found other true
+ */
+ function get_by_jid($p_jid)
+ {
+ $sql="select distinct oa_id,
+ po_id,
+ oa_amount,
+ oa_description,
+ oa_debit,
+ j_id,
+ oa_group,
+ oa_date,
+ pa_id,
+ oa_row
+ from operation_analytique
+ where
+ j_id=$p_jid order by j_id,oa_row,pa_id";
+ $ret=$this->db->exec_sql($sql);
+ $res=Database::fetch_all($ret);
+ if ( $res== false) return null;
- foreach ($res as $row) {
- $a=new Anc_Operation($this->db);
- foreach ( $row as $attr=>$value )
- {
- $a->$attr=$row[$attr];
- }
- $array[]=clone $a;
- }
- return $array;
- }
- /*!\brief modify an op from modify_op.php
- *
- */
- function update_from_jrnx($p_po_id){
- $a=$this->get_by_jid($this->j_id);
- if ( $a == null ) {
- // retrieve data from jrnx
- $sql="select jr_date,j_montant,j_debit from jrnx ".
- " join jrn on (jr_grpt_id = j_grpt) ".
- "where j_id=".$this->j_id;
- $res=$this->db->exec_sql($sql);
- if (Database::num_row($res) == 0 ) return;
- $row=Database::fetch_array($res,0);
- $this->oa_amount=$row['j_amount'];
- $this->oa_date=$row['jr_date'];
- $this->oa_debit=$row['j_debit'];
- $this->oa_description=$row['jr_comment'];
- $this->add();
- } else {
- foreach ($a as $row ) {
- if ( $row->pa_id == $this->pa_id ) {
- $row->po_id=$p_po_id;
- $row->update();
- }
- }
- }
- }
- /*!\brief retrieve the jr_id thanks the oa_group */
- function get_jrid() {
- $sql="select distinct jr_id from jrn join jrnx on (j_grpt=jr_grpt_id) join operation_analytique using (j_id) where j_id is not null and oa_group=".$this->oa_group;
- $res=$this->db->exec_sql($sql);
- if ( Database::num_row($res) == 0 ) return 0;
- $ret=Database::fetch_all($res);
- return $ret[0]['jr_id'];
- }
- /*\brief this function get the balance for a certain period
- *\param $p_from from date (accountancy period)
- *\param $p_to to dat (accountancy period)
- *\param $p_plan_id the plan id
- */
-function get_balance($p_from,$p_to,$p_plan_id)
- {
- // for the operation connected to jrnx
- $cond=sql_filter_per($this->db,$p_from,$p_to,'p_id','j_date');
- $sql="select oa_id, po_id, oa_amount, oa_debit, j_date from jrnx join operation_analytique using (j_id)
- join poste_analytique using (pa_id)
- where
- $cond and j_id is not null and pa_id=$p_plan_id";
+ foreach ($res as $row)
+ {
+ $a=new Anc_Operation($this->db);
+ foreach ( $row as $attr=>$value )
+ {
+ $a->$attr=$row[$attr];
+ }
+ $array[]=clone $a;
+ }
+ return $array;
+ }
+ /*!\brief modify an op from modify_op.php
+ *
+ */
+ function update_from_jrnx($p_po_id)
+ {
+ $a=$this->get_by_jid($this->j_id);
+ if ( $a == null )
+ {
+ // retrieve data from jrnx
+ $sql="select jr_date,j_montant,j_debit from jrnx ".
+ " join jrn on (jr_grpt_id = j_grpt) ".
+ "where j_id=".$this->j_id;
+ $res=$this->db->exec_sql($sql);
+ if (Database::num_row($res) == 0 ) return;
+ $row=Database::fetch_array($res,0);
+ $this->oa_amount=$row['j_amount'];
+ $this->oa_date=$row['jr_date'];
+ $this->oa_debit=$row['j_debit'];
+ $this->oa_description=$row['jr_comment'];
+ $this->add();
+ }
+ else
+ {
+ foreach ($a as $row )
+ {
+ if ( $row->pa_id == $this->pa_id )
+ {
+ $row->po_id=$p_po_id;
+ $row->update();
+ }
+ }
+ }
+ }
+ /*!\brief retrieve the jr_id thanks the oa_group */
+ function get_jrid()
+ {
+ $sql="select distinct jr_id from jrn join jrnx on (j_grpt=jr_grpt_id) join operation_analytique using (j_id) where j_id is not null and oa_group=".$this->oa_group;
+ $res=$this->db->exec_sql($sql);
+ if ( Database::num_row($res) == 0 ) return 0;
+ $ret=Database::fetch_all($res);
+ return $ret[0]['jr_id'];
+ }
+ /*\brief this function get the balance for a certain period
+ *\param $p_from from date (accountancy period)
+ *\param $p_to to dat (accountancy period)
+ *\param $p_plan_id the plan id
+ */
+ function get_balance($p_from,$p_to,$p_plan_id)
+ {
+ // for the operation connected to jrnx
+ $cond=sql_filter_per($this->db,$p_from,$p_to,'p_id','j_date');
+ $sql="select oa_id, po_id, oa_amount, oa_debit, j_date from jrnx join operation_analytique using (j_id)
+ join poste_analytique using (pa_id)
+ where
+ $cond and j_id is not null and pa_id=$p_plan_id";
- // OD
- $cond=sql_filter_per($this->db,$p_from,$p_to,'p_id','oa_date');
- $sql="union select oa_id, po_id, oa_amount, oa_debit,oa_date from
- operation_analytique
- join poste_analytique using (pa_id)
- where j_id is null and
- $cond and pa_id=$p_plan_id ";
- try {
- $res=$this->db->exec_sql($sql);
- $array=Database::fetch_all($res);
- } catch (Exception $e) {
- var_dump($e);
- }
- }
- /*!\brief display the form for PA
- *\param $p_array contains POST (or GET) data (val[] hplan[][] op[])
- * \param $p_null = 1 if PA optional otherwise 0 mandatory
- * \param $p_mode == form 1 ==> read/write otherwise 0==>readonly
- * \param $p_seq number of the row
- * \param $p_amount amount
- * \param $p_id operation is detailled in a HTML popup, if several
- * are opened, the tableid MUST be different. So we need to use a new parameter
- * \see save_form_plan
-@note
-- op is an array containing the line number
-- pa_id is an array of the existing array
-- hplan is an array of the POSTE ANALYTIQUE id used, the size of hplan from 0 to x,
-x can be bigger than the number of plan id
-- val contains the amount by row inside the table. One operation (j_id) you can have several rows
-@code
- 0 =>
- array
- 'op' => int 200
- 'pa_id' =>
- array
- 0 => string '14' (length=2)
- 1 => string '15' (length=2)
- 'hplan' =>
- array
- 1 =>
- array
- 0 => string '25' (length=2)
- 1 => string '26' (length=2)
- 'val' =>
- array
- 1 =>
- array
- 0 => string '100.0000' (length=8)
+ // OD
+ $cond=sql_filter_per($this->db,$p_from,$p_to,'p_id','oa_date');
+ $sql="union select oa_id, po_id, oa_amount, oa_debit,oa_date from
+ operation_analytique
+ join poste_analytique using (pa_id)
+ where j_id is null and
+ $cond and pa_id=$p_plan_id ";
+ try
+ {
+ $res=$this->db->exec_sql($sql);
+ $array=Database::fetch_all($res);
+ }
+ catch (Exception $e)
+ {
+ var_dump($e);
+ }
+ }
+ /*!\brief display the form for PA
+ *\param $p_array contains POST (or GET) data (val[] hplan[][] op[])
+ * \param $p_null = 1 if PA optional otherwise 0 mandatory
+ * \param $p_mode == form 1 ==> read/write otherwise 0==>readonly
+ * \param $p_seq number of the row
+ * \param $p_amount amount
+ * \param $p_id operation is detailled in a HTML popup, if several
+ * are opened, the tableid MUST be different. So we need to use a new parameter
+ * \see save_form_plan
+ @note
+ - op is an array containing the line number
+ - pa_id is an array of the existing array
+ - hplan is an array of the POSTE ANALYTIQUE id used, the size of hplan from 0 to x,
+ x can be bigger than the number of plan id
+ - val contains the amount by row inside the table. One operation (j_id) you can have several rows
+ @code
+ 0 =>
+ array
+ 'op' => int 200
+ 'pa_id' =>
+ array
+ 0 => string '14' (length=2)
+ 1 => string '15' (length=2)
+ 'hplan' =>
+ array
+ 1 =>
+ array
+ 0 => string '25' (length=2)
+ 1 => string '26' (length=2)
+ 'val' =>
+ array
+ 1 =>
+ array
+ 0 => string '100.0000' (length=8)
-@endcode
- */
-function display_form_plan($p_array,$p_null,$p_mode,$p_seq,$p_amount,$p_id='') {
- if ( $p_array != null)
- extract ($p_array);
- $result="";
- $plan=new Anc_Plan($this->db);
- $a_plan=$plan->get_list();
- if ( empty ($a_plan) ) return "";
- $table_id="t".$p_seq;
- $hidden=new IHidden();
+ @endcode
+ */
+ function display_form_plan($p_array,$p_null,$p_mode,$p_seq,$p_amount,$p_id='')
+ {
+ if ( $p_array != null)
+ extract ($p_array);
+ $result="";
+ $plan=new Anc_Plan($this->db);
+ $a_plan=$plan->get_list();
+ if ( empty ($a_plan) ) return "";
+ $table_id="t".$p_seq;
+ $hidden=new IHidden();
- $result.=$hidden->input('amount_'.$table_id,$p_amount);
- if ( $p_mode==1 )
- $result.='';
- else
- $result.='';
- $result.="".$plan->header()."montant ";
+ $result.=$hidden->input('amount_'.$table_id,$p_amount);
+ if ( $p_mode==1 )
+ $result.='';
+ else
+ $result.='';
+ $result.="".$plan->header()."montant ";
- /* compute the number of rows */
- $nb_row=(isset($val[$p_seq]))?count($val[$p_seq]):1;
- $count=0;
+ /* compute the number of rows */
+ $nb_row=(isset($val[$p_seq]))?count($val[$p_seq]):1;
+ $count=0;
- for ( $i=0; $i < $nb_row;$i++) {
- $result.='';
+ for ( $i=0; $i < $nb_row;$i++)
+ {
+ $result.=' ';
- foreach ($a_plan as $r_plan)
- {
+ foreach ($a_plan as $r_plan)
+ {
- $array=$this->db->make_array(
- "select po_id as value,".
- " html_quote(po_name) as label from poste_analytique ".
- " where pa_id = ".$r_plan['id'].
- " order by po_name",$p_null);
- $select =new ISelect("hplan[".$p_seq."][]",$array);
- $select->table=0;
- // view only or editables
- if ( $p_mode==1 ) {
- // editable
- $select->readonly=false;
- if ( isset($hplan) && isset($hplan[$p_seq][$count]) )
- $select->selected=$hplan[$p_seq][$count];
- } else {
- // view only
- $select->readonly=true;
- }
- if ($p_mode==1)
- $result.=''.$select->input().' ';
- else
- $result.=''.$select->display().' ';
- $count++;
+ $array=$this->db->make_array(
+ "select po_id as value,".
+ " html_quote(po_name) as label from poste_analytique ".
+ " where pa_id = ".$r_plan['id'].
+ " order by po_name",$p_null);
+ $select =new ISelect("hplan[".$p_seq."][]",$array);
+ $select->table=0;
+ // view only or editables
+ if ( $p_mode==1 )
+ {
+ // editable
+ $select->readonly=false;
+ if ( isset($hplan) && isset($hplan[$p_seq][$count]) )
+ $select->selected=$hplan[$p_seq][$count];
+ }
+ else
+ {
+ // view only
+ $select->readonly=true;
+ }
+ if ($p_mode==1)
+ $result.=''.$select->input().' ';
+ else
+ $result.=''.$select->display().' ';
+ $count++;
- }
- $value=new INum();
- $value->name="val[".$p_seq."][]";
- $value->size=6;
- $value->value=(isset($val[$p_seq][$i]))?$val[$p_seq][$i]:$p_amount;
- $value->readonly=($p_mode==1)?false:true;
+ }
+ $value=new INum();
+ $value->name="val[".$p_seq."][]";
+ $value->size=6;
+ $value->value=(isset($val[$p_seq][$i]))?$val[$p_seq][$i]:$p_amount;
+ $value->readonly=($p_mode==1)?false:true;
- $result.=''.$value->input().' ';
+ $result.=''.$value->input().' ';
- $result.=" ";
- }
+ $result.="";
+ }
- $result.="
";
- // add a button to add a row
- $button=new IButton();
- $button->javascript="add_row('".$p_id."$table_id',$p_seq);";
- $button->name="js".$p_id.$p_seq;
- $button->label="Nouvelle ligne";
- if ( $p_mode == 1 )
- $result.=$button->input();
- return $result;
- }
- /*!\brief it called for each item, the data are taken from $p_array
- * data and set before in this.
- * \param $p_item if the item nb for each item (purchase or selling
- * merchandise)
- * \param $p_array structure
- * \verbatim
- nb_tA A is the number of the item it contains the number of
- rows of CA for this card
- valAlR amount for the CA (item A row R)
- ta_AoCrow_R contains the value of the pa_id and po_id for this
- row with the form pa_id_po_id %d_%d
- *\endverbatim
- * \attention The idea is one j_id matches several oa_id,
- * serveral data are set before the call :
- * -j_id
- * -oa_debit
- * -oa_group
- * -oa_date
- * -oa_description
- *
- */
- function save_form_plan($p_array,$p_item,$j_id) {
- extract($p_array);
- /* variable for in array
- pa_id array of existing pa_id
- hplan double array with the pa_id (column)
- val double array by row with amount
- op contains sequence
- p_item is used to identify what op is concerned
- */
- /* echo "j_id = $j_id p_item = $p_item hplan=".var_export($hplan[$p_item],true)." val = ".var_export($val[$p_item],true).' '; */
- /* for each row */
- // for ($i=0;$idb);
- $op->po_id=$hplan[$p_item][$e];
- $op->pa_id=$pa_id[$idx_pa_id];
- $op->oa_group=$this->oa_group;
- $op->j_id=$j_id;
- $op->oa_amount=$val[$p_item][$row];
- $op->oa_debit=$this->oa_debit;
- $op->oa_date=$this->oa_date;
-
- $op->oa_description=$this->oa_description;
- $op->oa_row=$row;
- $op->add();
- }
- $idx_pa_id++;
- }
- // }
- }
-
- /**
- *@brief save a whole form from a update box
- *@param $p_array for ALL j_id
- *@return
- *@note
- *@see save_form_plan to_request
-@code
+ $result.="
";
+ // add a button to add a row
+ $button=new IButton();
+ $button->javascript="add_row('".$p_id."$table_id',$p_seq);";
+ $button->name="js".$p_id.$p_seq;
+ $button->label="Nouvelle ligne";
+ if ( $p_mode == 1 )
+ $result.=$button->input();
+ return $result;
+ }
+ /*!\brief it called for each item, the data are taken from $p_array
+ * data and set before in this.
+ * \param $p_item if the item nb for each item (purchase or selling
+ * merchandise)
+ * \param $p_array structure
+ * \verbatim
+ nb_tA A is the number of the item it contains the number of
+ rows of CA for this card
+ valAlR amount for the CA (item A row R)
+ ta_AoCrow_R contains the value of the pa_id and po_id for this
+ row with the form pa_id_po_id %d_%d
+ *\endverbatim
+ * \attention The idea is one j_id matches several oa_id,
+ * serveral data are set before the call :
+ * -j_id
+ * -oa_debit
+ * -oa_group
+ * -oa_date
+ * -oa_description
+ *
+ */
+ function save_form_plan($p_array,$p_item,$j_id)
+ {
+ extract($p_array);
+ /* variable for in array
+ pa_id array of existing pa_id
+ hplan double array with the pa_id (column)
+ val double array by row with amount
+ op contains sequence
+ p_item is used to identify what op is concerned
+ */
+ /* echo "j_id = $j_id p_item = $p_item hplan=".var_export($hplan[$p_item],true)." val = ".var_export($val[$p_item],true).' '; */
+ /* for each row */
+ // for ($i=0;$idb);
+ $op->po_id=$hplan[$p_item][$e];
+ $op->pa_id=$pa_id[$idx_pa_id];
+ $op->oa_group=$this->oa_group;
+ $op->j_id=$j_id;
+ $op->oa_amount=$val[$p_item][$row];
+ $op->oa_debit=$this->oa_debit;
+ $op->oa_date=$this->oa_date;
-@endcode
- */
- function save_update_form($p_array){
- extract ($p_array);
- for ($i=0;$i < count($op);$i++) {
- /* clean jrnx */
- $this->db->exec_sql('delete from operation_analytique where j_id=$1',array($op[$i]));
- /* get missing data for adding */
- $a_missing=$this->db->get_array("select to_char(jr_date,'DD.MM.YYYY') as mdate,j_montant,j_debit,jr_comment from jrnx join jrn on (j_grpt=jr_grpt_id) where j_id=$1",
- array($op[$i]));
- $missing=$a_missing[0];
- $this->oa_debit=$missing['j_debit'];
- $this->oa_description=$missing['jr_comment'];
- $this->j_id=$op[$i];
- $group=$this->db->get_next_seq("s_oa_group"); /* for analytic */
- $this->oa_group=$group;
- $this->oa_date=$missing['mdate'];
- $this->save_form_plan($p_array,$i,$op[$i]);
- }
- }
- /*\brief transform a array of operation into a array usage by
- *display_form_plan & save_form_plan
- *\param $p_array array of operation
- *\param $p_line line
- *\return an array complying with \see save_form_plan
- */
- function to_request ($p_array,$p_line){
- $result=array();
- $result[]=array('op'=>$this->j_id);
- $pa_id=array();
+ $op->oa_description=$this->oa_description;
+ $op->oa_row=$row;
+ $op->add();
+ }
+ $idx_pa_id++;
+ }
+ // }
+ }
- /* First add the pa_id */
- for ($i=0;$i < count($p_array);$i++){
- if ( in_array($p_array[$i]->pa_id,$pa_id)==false)
- $pa_id[]=$p_array[$i]->pa_id;
- }
- $result['pa_id']=$pa_id;
-
- /* add the hplan */
- $seq=0;
- for ($i=0;$i < count($p_array);$i++){
- $hplan[$p_line][$i]=$p_array[$i]->po_id;
- }
- $result['hplan']=$hplan;
- /* Add the amount */
- $idx_pa=0;
- for ($i=0;$i < count($p_array);$i++){
- $val[$p_line][$p_array[$i]->oa_row]=$p_array[$i]->oa_amount;
- }
- $result['val']=$val;
- return $result;
- }
-/*!
- * \brief delete from operation_analytique
- * \param $p_jid the operation_analytique.j_id field
- *
- * \return none
- */
- function delete_by_jid($p_jid) {
- $sql="delete from operation_analytique where j_id=$p_jid";
- $this->db->exec_sql($sql);
- }
-/*\brief Display a table with analytic accounting in
- * detail of operation
- *@note $this->j_id must be set
- *\param $p_mode 0 = readonly or 1=writable
- *\param $p_amount amount
- *\param $p_id unique id
- *@see display_form_plan
- *\return string to display
- */
- function display_table($p_mode,$p_amount,$p_id) {
- static $seq=-1; /* first seq == 0 */
- $seq++;
+ /**
+ *@brief save a whole form from a update box
+ *@param $p_array for ALL j_id
+ *@return
+ *@note
+ *@see save_form_plan to_request
+ @code
- $array=$this->get_by_jid($this->j_id) ;
- if ( $array != null ) {
- $request=$this->to_request($array,$seq);
- return "".$this->display_form_plan($request,1,$p_mode,$seq,$p_amount,$p_id)." ";
- } else {
- return ''.$this->display_form_plan(null,1,$p_mode,$seq,$p_amount,$p_id)." ";
- }
- return "";
+ @endcode
+ */
+ function save_update_form($p_array)
+ {
+ extract ($p_array);
+ for ($i=0;$i < count($op);$i++)
+ {
+ /* clean jrnx */
+ $this->db->exec_sql('delete from operation_analytique where j_id=$1',array($op[$i]));
+ /* get missing data for adding */
+ $a_missing=$this->db->get_array("select to_char(jr_date,'DD.MM.YYYY') as mdate,j_montant,j_debit,jr_comment from jrnx join jrn on (j_grpt=jr_grpt_id) where j_id=$1",
+ array($op[$i]));
+ $missing=$a_missing[0];
+ $this->oa_debit=$missing['j_debit'];
+ $this->oa_description=$missing['jr_comment'];
+ $this->j_id=$op[$i];
+ $group=$this->db->get_next_seq("s_oa_group"); /* for analytic */
+ $this->oa_group=$group;
+ $this->oa_date=$missing['mdate'];
+ $this->save_form_plan($p_array,$i,$op[$i]);
+ }
+ }
+ /*\brief transform a array of operation into a array usage by
+ *display_form_plan & save_form_plan
+ *\param $p_array array of operation
+ *\param $p_line line
+ *\return an array complying with \see save_form_plan
+ */
+ function to_request ($p_array,$p_line)
+ {
+ $result=array();
+ $result[]=array('op'=>$this->j_id);
+ $pa_id=array();
-}
+ /* First add the pa_id */
+ for ($i=0;$i < count($p_array);$i++)
+ {
+ if ( in_array($p_array[$i]->pa_id,$pa_id)==false)
+ $pa_id[]=$p_array[$i]->pa_id;
+ }
+ $result['pa_id']=$pa_id;
+
+ /* add the hplan */
+ $seq=0;
+ for ($i=0;$i < count($p_array);$i++)
+ {
+ $hplan[$p_line][$i]=$p_array[$i]->po_id;
+ }
+ $result['hplan']=$hplan;
+ /* Add the amount */
+ $idx_pa=0;
+ for ($i=0;$i < count($p_array);$i++)
+ {
+ $val[$p_line][$p_array[$i]->oa_row]=$p_array[$i]->oa_amount;
+ }
+ $result['val']=$val;
+ return $result;
+ }
+ /*!
+ * \brief delete from operation_analytique
+ * \param $p_jid the operation_analytique.j_id field
+ *
+ * \return none
+ */
+ function delete_by_jid($p_jid)
+ {
+ $sql="delete from operation_analytique where j_id=$p_jid";
+ $this->db->exec_sql($sql);
+ }
+ /*\brief Display a table with analytic accounting in
+ * detail of operation
+ *@note $this->j_id must be set
+ *\param $p_mode 0 = readonly or 1=writable
+ *\param $p_amount amount
+ *\param $p_id unique id
+ *@see display_form_plan
+ *\return string to display
+ */
+ function display_table($p_mode,$p_amount,$p_id)
+ {
+ static $seq=-1; /* first seq == 0 */
+ $seq++;
+
+ $array=$this->get_by_jid($this->j_id) ;
+ if ( $array != null )
+ {
+ $request=$this->to_request($array,$seq);
+ return "".$this->display_form_plan($request,1,$p_mode,$seq,$p_amount,$p_id)." ";
+ }
+ else
+ {
+ return ''.$this->display_form_plan(null,1,$p_mode,$seq,$p_amount,$p_id)." ";
+ }
+ return "";
+
+ }
///////////////////////////////////////////////////////////////////////////
// TEST
///////////////////////////////////////////////////////////////////////////
- /*\brief test the class
- *\param
- *\param
- *\return
- */
- function test_me() {
- $cn=new Database(dossier::id());
- $anco=new Anc_Operation($cn);
- $j_id=200;
- $anco->j_id=$j_id;
- $array=$anco->get_by_jid($j_id);
- $a=$anco->to_request($array,1);
- echo '';
- echo dossier::hidden();
- echo HtmlInput::hidden('j_id',$j_id);
- echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
- echo $anco->display_table(1,15002,0);
- echo ' ';
- echo ' ';
- if ( isset($_REQUEST['save'])){
- echo "to_save";
- var_dump($_REQUEST);
- }
- var_dump($a);
+ /*\brief test the class
+ *\param
+ *\param
+ *\return
+ */
+ function test_me()
+ {
+ $cn=new Database(dossier::id());
+ $anco=new Anc_Operation($cn);
+ $j_id=200;
+ $anco->j_id=$j_id;
+ $array=$anco->get_by_jid($j_id);
+ $a=$anco->to_request($array,1);
+ echo '';
+ echo dossier::hidden();
+ echo HtmlInput::hidden('j_id',$j_id);
+ echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
+ echo $anco->display_table(1,15002,0);
+ echo ' ';
+ echo ' ';
+ if ( isset($_REQUEST['save']))
+ {
+ echo "to_save";
+ var_dump($_REQUEST);
+ }
+ var_dump($a);
- }
+ }
}
diff --git a/include/class_anc_plan.php b/include/class_anc_plan.php
index 4700b25eb..76e296686 100644
--- a/include/class_anc_plan.php
+++ b/include/class_anc_plan.php
@@ -36,208 +36,214 @@ require_once ('class_dossier.php');
class Anc_Plan
{
- var $db; /*!db=$p_cn;
- $this->id=$p_id;
- $this->name="";
- $this->description="";
- $this->get();
- }
- /*!\brief get the list of all existing PA
- * \return an array of PA (not object)
- *
- */
- function get_list()
- {
- $array=array();
- $sql="select pa_id as id,pa_name as name,".
- "pa_description as description from plan_analytique order by pa_name";
- $ret=$this->db->exec_sql($sql);
- $array=Database::fetch_all($ret);
- return $array;
- }
-
- function get()
- {
- if ( $this->id==0) return;
-
- $sql="select pa_name,pa_description from plan_analytique where pa_id=".$this->id;
- $ret= $this->db->exec_sql($sql);
- if ( Database::num_row($ret) == 0)
- {
- return;
- }
- $a= Database::fetch_array($ret,0);
- $this->name=$a['pa_name'];
- $this->description=$a['pa_description'];
-
- }
-
- function delete()
- {
- if ( $this->id == 0 ) return;
- $this->db->exec_sql("delete from plan_analytique where pa_id=".$this->id);
- }
-
- function update()
- {
- if ( $this->id==0) return;
- $name=FormatString($this->name);
- if ( strlen($name) == 0)
- return;
-
- $description=FormatString($this->description);
- $this->db->exec_sql("update plan_analytique set pa_name=$1,
- pa_description=$2 where pa_id=$3",array($name,$description,$this->id));
- }
-
- function add()
- {
- $name=FormatString($this->name);
- if ( strlen($name) == 0)
- return;
- if ( $this->isAppend() == false) return;
- $description=FormatString($this->description);
- $this->db->exec_sql("insert into plan_analytique(pa_name,pa_description)".
- " values (".
- "'".$name."',".
- "'".$description."')");
- $this->id=$this->db->get_current_seq('plan_analytique_pa_id_seq');
-
- }
- function form()
- {
-
- $wName=new IText('pa_name',$this->name);
-
- $wName->table=1;
- $wDescription=new IText('pa_description',$this->description);
- $wDescription->table=1;
- $wId=new IHidden("pa_id",$this->id);
- $ret="";
- $ret.=''.td(_('Nom')).$wName->input().' ';
- $ret.="".td(_('Description')).$wDescription->input()." ";
- $ret.="
";
- $ret.=$wId->input();
- return $ret;
- }
- function isAppend()
- {
- $count=$this->db->get_value("select count(pa_id) from plan_analytique");
-
- if ( $count > 4)
- return false;
- else
- return true;
- }
- /*!\brief get all the poste related to the current
- * Analytic plan
- * \return an array of Poste_analytic object
- */
- function get_poste_analytique()
- {
- $sql="select po_id from poste_analytique where pa_id=".$this->id;
- $r=$this->db->exec_sql($sql);
- $ret=array();
- if ( Database::num_row($r) == 0 )
- return $ret;
-
- $all=Database::fetch_all($r);
- foreach ($all as $line)
- {
- $obj=new Anc_Account($this->db,$line['po_id']);
- $obj->get_by_id();
- $ret[]=clone $obj;
- }
- return $ret;
- }
- /*!\brief show the header for a table for PA
- * \return string like name ...
- */
- function header() {
- $res="";
- $a_plan=$this->get_list();
- if ( empty($a_plan)) return "";
- foreach ($a_plan as $r_plan)
- {
- $res.="".h($r_plan['name'])." ";
- }
- return $res;
- }
- function count() {
- $a=$this->db->count_sql("select pa_id from plan_analytique");
- return $a;
- }
- function exist() {
- $a=$this->db->count_sql("select pa_id from plan_analytique where pa_id=".
- Database::escape_string($this->pa_id));
-
- return ($a==0)?false:true;
-
- }
- /**
- *@brief return an HTML string containing hidden input type to
- * hold the differant PA_ID
- *@param $p_array contains a array, it is the result of the fct
- * Anc_Plan::get_list
- *@return html string
- *@see Anc_Plan::get_list
- */
- static function hidden($p_array) {
- $r='';
- for ($i_anc=0;$i_anc db=$p_cn;
+ $this->id=$p_id;
+ $this->name="";
+ $this->description="";
+ $this->get();
+ }
+ /*!\brief get the list of all existing PA
+ * \return an array of PA (not object)
+ *
+ */
+ function get_list()
+ {
+ $array=array();
+ $sql="select pa_id as id,pa_name as name,".
+ "pa_description as description from plan_analytique order by pa_name";
+ $ret=$this->db->exec_sql($sql);
+ $array=Database::fetch_all($ret);
+ return $array;
}
- return $r;
- }
- static function test_me() {
- $cn=new Database(dossier::id());
- echo "Plan analytique : test ";
- echo "clean";
- $cn->exec_sql("delete from plan_analytique");
- $p=new Anc_Plan($cn);
- echo "Add ";
- $p->name="Nouveau 1";
- $p->description="C'est un test";
- echo "Add ";
- $p->add();
- $p->name="Nouveau 2";
- $p->add();
- $pa_id=$p->id;
- echo $p->id."/";
- $p->name="Nouveau 3";
- $p->add();
- echo $p->id."/";
+ function get()
+ {
+ if ( $this->id==0) return;
+
+ $sql="select pa_name,pa_description from plan_analytique where pa_id=".$this->id;
+ $ret= $this->db->exec_sql($sql);
+ if ( Database::num_row($ret) == 0)
+ {
+ return;
+ }
+ $a= Database::fetch_array($ret,0);
+ $this->name=$a['pa_name'];
+ $this->description=$a['pa_description'];
+
+ }
+
+ function delete()
+ {
+ if ( $this->id == 0 ) return;
+ $this->db->exec_sql("delete from plan_analytique where pa_id=".$this->id);
+ }
+
+ function update()
+ {
+ if ( $this->id==0) return;
+ $name=FormatString($this->name);
+ if ( strlen($name) == 0)
+ return;
+
+ $description=FormatString($this->description);
+ $this->db->exec_sql("update plan_analytique set pa_name=$1,
+ pa_description=$2 where pa_id=$3",array($name,$description,$this->id));
+ }
+
+ function add()
+ {
+ $name=FormatString($this->name);
+ if ( strlen($name) == 0)
+ return;
+ if ( $this->isAppend() == false) return;
+ $description=FormatString($this->description);
+ $this->db->exec_sql("insert into plan_analytique(pa_name,pa_description)".
+ " values (".
+ "'".$name."',".
+ "'".$description."')");
+ $this->id=$this->db->get_current_seq('plan_analytique_pa_id_seq');
+
+ }
+ function form()
+ {
+
+ $wName=new IText('pa_name',$this->name);
+
+ $wName->table=1;
+ $wDescription=new IText('pa_description',$this->description);
+ $wDescription->table=1;
+ $wId=new IHidden("pa_id",$this->id);
+ $ret="";
+ $ret.=''.td(_('Nom')).$wName->input().' ';
+ $ret.="".td(_('Description')).$wDescription->input()." ";
+ $ret.="
";
+ $ret.=$wId->input();
+ return $ret;
+ }
+ function isAppend()
+ {
+ $count=$this->db->get_value("select count(pa_id) from plan_analytique");
+
+ if ( $count > 4)
+ return false;
+ else
+ return true;
+ }
+ /*!\brief get all the poste related to the current
+ * Analytic plan
+ * \return an array of Poste_analytic object
+ */
+ function get_poste_analytique()
+ {
+ $sql="select po_id from poste_analytique where pa_id=".$this->id;
+ $r=$this->db->exec_sql($sql);
+ $ret=array();
+ if ( Database::num_row($r) == 0 )
+ return $ret;
+
+ $all=Database::fetch_all($r);
+ foreach ($all as $line)
+ {
+ $obj=new Anc_Account($this->db,$line['po_id']);
+ $obj->get_by_id();
+ $ret[]=clone $obj;
+ }
+ return $ret;
+ }
+ /*!\brief show the header for a table for PA
+ * \return string like name ...
+ */
+ function header()
+ {
+ $res="";
+ $a_plan=$this->get_list();
+ if ( empty($a_plan)) return "";
+ foreach ($a_plan as $r_plan)
+ {
+ $res.="".h($r_plan['name'])." ";
+ }
+ return $res;
+ }
+ function count()
+ {
+ $a=$this->db->count_sql("select pa_id from plan_analytique");
+ return $a;
+ }
+ function exist()
+ {
+ $a=$this->db->count_sql("select pa_id from plan_analytique where pa_id=".
+ Database::escape_string($this->pa_id));
+
+ return ($a==0)?false:true;
+
+ }
+ /**
+ *@brief return an HTML string containing hidden input type to
+ * hold the differant PA_ID
+ *@param $p_array contains a array, it is the result of the fct
+ * Anc_Plan::get_list
+ *@return html string
+ *@see Anc_Plan::get_list
+ */
+ static function hidden($p_array)
+ {
+ $r='';
+ for ($i_anc=0;$i_anc Plan analytique : test";
+ echo "clean";
+ $cn->exec_sql("delete from plan_analytique");
+
+ $p=new Anc_Plan($cn);
+ echo "Add ";
+ $p->name="Nouveau 1";
+ $p->description="C'est un test";
+ echo "Add ";
+ $p->add();
+ $p->name="Nouveau 2";
+ $p->add();
+ $pa_id=$p->id;
+ echo $p->id."/";
+ $p->name="Nouveau 3";
+ $p->add();
+ echo $p->id."/";
- $p->name="Nouveau 4";
- $p->add();
- echo $p->id;
+ $p->name="Nouveau 4";
+ $p->add();
+ echo $p->id;
- echo "get ";
- $p->get();
- var_dump($p);
- echo "Update ";
- $p->name="Update ";
- $p->description="c'est change";
- $p->update();
- $p->get();
- var_dump($p);
- echo "get_list ";
- $a=$p->get_list();
- var_dump($a);
- echo "delete ";
- $p->delete();
+ echo "get ";
+ $p->get();
+ var_dump($p);
+ echo "Update ";
+ $p->name="Update ";
+ $p->description="c'est change";
+ $p->update();
+ $p->get();
+ var_dump($p);
+ echo "get_list ";
+ $a=$p->get_list();
+ var_dump($a);
+ echo "delete ";
+ $p->delete();
- }
+ }
}
?>
diff --git a/include/class_anc_print.php b/include/class_anc_print.php
index 3e7afd2b2..0ac515bf6 100644
--- a/include/class_anc_print.php
+++ b/include/class_anc_print.php
@@ -38,103 +38,108 @@ require_once('constant.php');
require_once('class_dossier.php');
require_once ('class_anc_plan.php');
-class Anc_Print {
- var $db; /*!< $db database connection */
- var $to; /*!< $to start date */
- var $from; /*!< $from end date */
- var $from_poste; /*!< $from_poste from poste */
- var $to_poste; /*!< $to_poste to the poste */
+class Anc_Print
+{
+ var $db; /*!< $db database connection */
+ var $to; /*!< $to start date */
+ var $from; /*!< $from end date */
+ var $from_poste; /*!< $from_poste from poste */
+ var $to_poste; /*!< $to_poste to the poste */
- function Anc_Print($p_cn) {
- $this->db=$p_cn;
- $this->from="";
- $this->to="";
- $this->from_poste="";
- $this->to_poste="";
+ function Anc_Print($p_cn)
+ {
+ $this->db=$p_cn;
+ $this->from="";
+ $this->to="";
+ $this->from_poste="";
+ $this->to_poste="";
- }
-/*!
- * \brief complete the object with the data in $_REQUEST
- */
- function get_request() {
- if ( isset($_REQUEST['from']))
- $this->from=$_REQUEST['from'];
+ }
+ /*!
+ * \brief complete the object with the data in $_REQUEST
+ */
+ function get_request()
+ {
+ if ( isset($_REQUEST['from']))
+ $this->from=$_REQUEST['from'];
- if ( isset($_REQUEST['to']))
- $this->to=$_REQUEST['to'];
+ if ( isset($_REQUEST['to']))
+ $this->to=$_REQUEST['to'];
- if ( isset($_REQUEST['from_poste']))
- $this->from_poste=$_REQUEST['from_poste'];
+ if ( isset($_REQUEST['from_poste']))
+ $this->from_poste=$_REQUEST['from_poste'];
- if ( isset($_REQUEST['to_poste']))
- $this->to_poste=$_REQUEST['to_poste'];
- if ( isset($_REQUEST['pa_id']))
- $this->pa_id=$_REQUEST['pa_id'];
- else
- $this->pa_id="";
+ if ( isset($_REQUEST['to_poste']))
+ $this->to_poste=$_REQUEST['to_poste'];
+ if ( isset($_REQUEST['pa_id']))
+ $this->pa_id=$_REQUEST['pa_id'];
+ else
+ $this->pa_id="";
- }
-/*!
- * \brief Compute the form to display
- * \param $p_hidden hidden tag to be included (gDossier,...)
- *
- *
- * \return string containing the data
- */
- function display_form($p_hidden="") {
- /* if there is no analytic plan return */
- $pa=new Anc_Plan($this->db);
- if ( $pa->count() == 0 ) {
- echo ''._('Aucun plan défini').' ';
- exit();
- }
+ }
+ /*!
+ * \brief Compute the form to display
+ * \param $p_hidden hidden tag to be included (gDossier,...)
+ *
+ *
+ * \return string containing the data
+ */
+ function display_form($p_hidden="")
+ {
+ /* if there is no analytic plan return */
+ $pa=new Anc_Plan($this->db);
+ if ( $pa->count() == 0 )
+ {
+ echo ''._('Aucun plan défini').' ';
+ exit();
+ }
- $from=new IDate('from','from');
- $from->size=10;
- $from->value=$this->from;
+ $from=new IDate('from','from');
+ $from->size=10;
+ $from->value=$this->from;
- $to=new IDate('to','to');
- $to->value=$this->to;
- $to->size=10;
+ $to=new IDate('to','to');
+ $to->value=$this->to;
+ $to->size=10;
- $from_poste=new IText('from_poste','from_poste');
- $from_poste->size=10;
- $from_poste->value=$this->from_poste;
+ $from_poste=new IText('from_poste','from_poste');
+ $from_poste->size=10;
+ $from_poste->value=$this->from_poste;
- $to_poste=new IText('to_poste','to_poste');
- $to_poste->value=$this->to_poste;
- $to_poste->size=10;
+ $to_poste=new IText('to_poste','to_poste');
+ $to_poste->value=$this->to_poste;
+ $to_poste->size=10;
- $hidden=new IHidden();
- $r=dossier::hidden();
- $r.=$hidden->input("result","1");
- $r.="Depuis : ".$from->input();
- $r.= "jusque : ".$to->input();
- $r.= ''._('Les dates sont en format DD.MM.YYYY').' ';
+ $hidden=new IHidden();
+ $r=dossier::hidden();
+ $r.=$hidden->input("result","1");
+ $r.="Depuis : ".$from->input();
+ $r.= "jusque : ".$to->input();
+ $r.= ''._('Les dates sont en format DD.MM.YYYY').' ';
- $r.=$p_hidden;
- $r.='';
- $plan=new Anc_Plan($this->db);
- $plan_id=new ISelect("pa_id");
- $plan_id->value=$this->db->make_array("select pa_id, pa_name from plan_analytique order by pa_name");
- $plan_id->selected=$this->pa_id;
- $r.=_( "Plan Analytique :").$plan_id->input();
+ $r.=$p_hidden;
+ $r.='';
+ $plan=new Anc_Plan($this->db);
+ $plan_id=new ISelect("pa_id");
+ $plan_id->value=$this->db->make_array("select pa_id, pa_name from plan_analytique order by pa_name");
+ $plan_id->selected=$this->pa_id;
+ $r.=_( "Plan Analytique :").$plan_id->input();
- $poste=new IText();
- $poste->size=10;
- $r.=_("Entre le poste ").$poste->input("from_poste",$this->from_poste);
- $choose=new IButton();
- $choose->name=_("Choix Poste");
- $choose->label=_("Recherche");
- $choose->javascript="onClick=search_ca(".dossier::id().",'from_poste','pa_id')";
- $r.=$choose->input();
+ $poste=new IText();
+ $poste->size=10;
+ $r.=_("Entre le poste ").$poste->input("from_poste",$this->from_poste);
+ $choose=new IButton();
+ $choose->name=_("Choix Poste");
+ $choose->label=_("Recherche");
+ $choose->javascript="onClick=search_ca(".dossier::id().",'from_poste','pa_id')";
+ $r.=$choose->input();
- $r.=_(" et le poste ").$poste->input("to_poste",$this->to_poste);
- $choose->javascript="onClick=search_ca(".dossier::id().",'to_poste','pa_id')";
- $r.=$choose->input();
- $r.=''._('Selectionnez le plan qui vous intéresse avant de cliquer sur Recherche').' ';
+ $r.=_(" et le poste ").$poste->input("to_poste",$this->to_poste);
+ $choose->javascript="onClick=search_ca(".dossier::id().",'to_poste','pa_id')";
+ $r.=$choose->input();
+ $r.=''._('Selectionnez le plan qui vous intéresse avant de cliquer sur Recherche').' ';
- $r.=' ';
- return $r;
- }
+ $r.=' ';
+ return $r;
+ }
}
diff --git a/include/class_anticipation.php b/include/class_anticipation.php
index 58b00875f..2a5a8755d 100644
--- a/include/class_anticipation.php
+++ b/include/class_anticipation.php
@@ -38,294 +38,325 @@ require_once 'class_acc_account_ledger.php';
require_once 'class_periode.php';
class Anticipation
{
- /* example private $variable=array("val1"=>1,"val2"=>"Seconde valeur","val3"=>0); */
- private static $variable=array ("id"=>"f_id","name"=>"f_name");
- private $cn;
- var $cat; /*!< array of object categorie (forecast_cat)*/
- var $item; /*< array of object item (forecast_item) */
- /**
- * @brief constructor
- * @param $p_init Database object
- */
- function __construct ($p_init,$p_id=0) {
- $this->cn=$p_init;
- $this->f_id=$p_id;
- }
- public function get_parameter($p_string) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- return $this->$idx;
- }
- else
- exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
- }
- public function set_parameter($p_string,$p_value) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- $this->$idx=$p_value;
- }
- else
- exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
+ /* example private $variable=array("val1"=>1,"val2"=>"Seconde valeur","val3"=>0); */
+ private static $variable=array ("id"=>"f_id","name"=>"f_name");
+ private $cn;
+ var $cat; /*!< array of object categorie (forecast_cat)*/
+ var $item; /*< array of object item (forecast_item) */
+ /**
+ * @brief constructor
+ * @param $p_init Database object
+ */
+ function __construct ($p_init,$p_id=0)
+ {
+ $this->cn=$p_init;
+ $this->f_id=$p_id;
+ }
+ public function get_parameter($p_string)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ return $this->$idx;
+ }
+ else
+ exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
+ }
+ public function set_parameter($p_string,$p_value)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ $this->$idx=$p_value;
+ }
+ else
+ exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
- }
- public function get_info() { return var_export(self::$variable,true); }
- public function verify() {
- // Verify that the elt we want to add is correct
- // the f_name must be unique (case insensitive)
- return 0;
- }
- public function save() {
- /* please adapt */
- if ( $this->get_parameter("id") == 0 )
- $this->insert();
- else
- $this->update();
- }
+ }
+ public function get_info()
+ {
+ return var_export(self::$variable,true);
+ }
+ public function verify()
+ {
+ // Verify that the elt we want to add is correct
+ // the f_name must be unique (case insensitive)
+ return 0;
+ }
+ public function save()
+ {
+ /* please adapt */
+ if ( $this->get_parameter("id") == 0 )
+ $this->insert();
+ else
+ $this->update();
+ }
- public function insert() {
- if ( $this->verify() != 0 ) return;
- }
+ public function insert()
+ {
+ if ( $this->verify() != 0 ) return;
+ }
- public function update() {
- }
+ public function update()
+{}
- public function load() {
- }
- /**
- *@brief Display the result of the forecast
- *@param $p_periode
- *@return HTML String with the code
- */
- public function display(){
- $forecast=new Forecast($this->cn,$this->f_id);
- $forecast->load();
- $str_name=h($forecast->get_parameter('name'));
- $r="";
- $aCat=$this->cn->get_array('select fc_id,fc_desc from forecast_cat where f_id=$1 order by fc_order',array($this->f_id));
- $aItem=array();$aReal=array();$poste=new Acc_Account_Ledger($this->cn,0);$fiche=new Fiche($this->cn);
- $aPeriode=$this->cn->get_array("select p_id,to_char(p_start,'MM.YYYY') as myear from parm_periode where to_char(p_start,'DD')!='31' order by p_start;");
- for($j=0;$jcn->get_array('select fi_card,fi_account,fi_text,fi_amount,fi_debit from forecast_item where fc_id=$1 and fi_pid=0 order by fi_order ',array($aCat[$j]['fc_id']));
- $aPerMonth[$j]=$this->cn->get_array('select fi_pid,fi_card,fi_account,fi_text,fi_amount,fi_debit from forecast_item where fc_id=$1 and fi_pid !=0 order by fi_order ',array($aCat[$j]['fc_id']));
- /* compute the real amount for periode */
- for($k=0;$kid=$aItem[$j][$k]['fi_card'];
- $amount=$fiche->get_solde_detail("j_tech_per = ".$aPeriode[$l]['p_id']);
+ public function load()
+ {}
+ /**
+ *@brief Display the result of the forecast
+ *@param $p_periode
+ *@return HTML String with the code
+ */
+ public function display()
+ {
+ $forecast=new Forecast($this->cn,$this->f_id);
+ $forecast->load();
+ $str_name=h($forecast->get_parameter('name'));
+ $r="";
+ $aCat=$this->cn->get_array('select fc_id,fc_desc from forecast_cat where f_id=$1 order by fc_order',array($this->f_id));
+ $aItem=array();
+ $aReal=array();
+ $poste=new Acc_Account_Ledger($this->cn,0);
+ $fiche=new Fiche($this->cn);
+ $aPeriode=$this->cn->get_array("select p_id,to_char(p_start,'MM.YYYY') as myear from parm_periode where to_char(p_start,'DD')!='31' order by p_start;");
+ for($j=0;$jcn->get_array('select fi_card,fi_account,fi_text,fi_amount,fi_debit from forecast_item where fc_id=$1 and fi_pid=0 order by fi_order ',array($aCat[$j]['fc_id']));
+ $aPerMonth[$j]=$this->cn->get_array('select fi_pid,fi_card,fi_account,fi_text,fi_amount,fi_debit from forecast_item where fc_id=$1 and fi_pid !=0 order by fi_order ',array($aCat[$j]['fc_id']));
+ /* compute the real amount for periode */
+ for($k=0;$kid=$aItem[$j][$k]['fi_card'];
+ $amount=$fiche->get_solde_detail("j_tech_per = ".$aPeriode[$l]['p_id']);
- }else {
- $poste->id=$aItem[$j][$k]['fi_account'];
- $amount=$poste->get_solde_detail("j_tech_per= ".$aPeriode[$l]['p_id']);
- }
- if ($aItem[$j][$k]['fi_debit']=='C' && $amount['debit']>$amount['credit']) $amount['solde']=$amount["solde"]*(-1);
- if ($aItem[$j][$k]['fi_debit']=='D' && $amount['debit']<$amount['credit']) $amount['solde']=$amount["solde"]*(-1);
- $aReal[$j][$k][$l]=$amount['solde'];
- }
- }
+ }
+ else
+ {
+ $poste->id=$aItem[$j][$k]['fi_account'];
+ $amount=$poste->get_solde_detail("j_tech_per= ".$aPeriode[$l]['p_id']);
+ }
+ if ($aItem[$j][$k]['fi_debit']=='C' && $amount['debit']>$amount['credit']) $amount['solde']=$amount["solde"]*(-1);
+ if ($aItem[$j][$k]['fi_debit']=='D' && $amount['debit']<$amount['credit']) $amount['solde']=$amount["solde"]*(-1);
+ $aReal[$j][$k][$l]=$amount['solde'];
+ }
+ }
- }
- ob_start();
- require_once('template/forecast_result.php');
- $r.=ob_get_contents();
- ob_clean();
- return $r;
- }
- public static function div() {
- $r='';
- $r.= '
';
- return $r;
- }
- public function delete() {
- }
- /**
- *@brief Display a form for modifying the name or/and the category of an existing
- * anticipation
- *@return html string with the form
- */
- private function form_cat_mod()
- {
- $a=new Forecast($this->cn,$this->f_id);
- $a->load();
- $name=new IText('an_name');
- $name->value=$a->get_parameter("name");
- $str_name=$name->input();
- $str_action=_('Modification');
- $r=HtmlInput::hidden('f_id',$this->f_id);
- $array=Forecast_Cat::load_all($this->cn,$this->f_id);
+ }
+ ob_start();
+ require_once('template/forecast_result.php');
+ $r.=ob_get_contents();
+ ob_clean();
+ return $r;
+ }
+ public static function div()
+ {
+ $r='';
+ $r.= '
';
+ return $r;
+ }
+ public function delete()
+ {}
+ /**
+ *@brief Display a form for modifying the name or/and the category of an existing
+ * anticipation
+ *@return html string with the form
+ */
+ private function form_cat_mod()
+ {
+ $a=new Forecast($this->cn,$this->f_id);
+ $a->load();
+ $name=new IText('an_name');
+ $name->value=$a->get_parameter("name");
+ $str_name=$name->input();
+ $str_action=_('Modification');
+ $r=HtmlInput::hidden('f_id',$this->f_id);
+ $array=Forecast_Cat::load_all($this->cn,$this->f_id);
- for ($i=0;$ivalue=(isset ($array[$i]['fc_desc']))?$array[$i]['fc_desc']:'';
- $aCat[$i]['name']=$name->input();
+ for ($i=0;$ivalue=(isset ($array[$i]['fc_desc']))?$array[$i]['fc_desc']:'';
+ $aCat[$i]['name']=$name->input();
- /* category order */
- $order_name=(isset($array[$i]['fc_id']))?'fc_order'.$array[$i]['fc_id']:'fc_order_new'.$i;
- $order=new IText($order_name);
- $order->value=(isset($array[$i]['fc_order']))?$array[$i]['fc_order']:$i+1;
- $aCat[$i]['order']=$order->input();
- }
+ /* category order */
+ $order_name=(isset($array[$i]['fc_id']))?'fc_order'.$array[$i]['fc_id']:'fc_order_new'.$i;
+ $order=new IText($order_name);
+ $order->value=(isset($array[$i]['fc_order']))?$array[$i]['fc_order']:$i+1;
+ $aCat[$i]['order']=$order->input();
+ }
- ob_start();
- require_once('template/forecast_cat.php');
- $r.=ob_get_contents();
- ob_clean();
- return $r;
- }
- /**
- *@brief Display a form for adding an new anticipation
- *@return html string with the form
- */
- private function form_cat_new()
- {
- $r="";
- $str_action=_('Nouveau');
+ ob_start();
+ require_once('template/forecast_cat.php');
+ $r.=ob_get_contents();
+ ob_clean();
+ return $r;
+ }
+ /**
+ *@brief Display a form for adding an new anticipation
+ *@return html string with the form
+ */
+ private function form_cat_new()
+ {
+ $r="";
+ $str_action=_('Nouveau');
- $name=new IText('an_name');
- $str_name=$name->input();
+ $name=new IText('an_name');
+ $str_name=$name->input();
- $aLabel=array(_('Ventes'),_('Dépense'),_('Banque'));
- $aCat=array();
+ $aLabel=array(_('Ventes'),_('Dépense'),_('Banque'));
+ $aCat=array();
- for ($i=0;$ivalue=(isset($aLabel[$i]))?$aLabel[$i]:'';
- $aCat[$i]['name']=$name->input();
+ for ($i=0;$ivalue=(isset($aLabel[$i]))?$aLabel[$i]:'';
+ $aCat[$i]['name']=$name->input();
- /* category order */
- $order=new IText('fr_order'.$i);
- $order->value=$i+1;
- $aCat[$i]['order']=$order->input();
- }
+ /* category order */
+ $order=new IText('fr_order'.$i);
+ $order->value=$i+1;
+ $aCat[$i]['order']=$order->input();
+ }
- ob_start();
- require_once('template/forecast_cat.php');
- $r.=ob_get_contents();
- ob_clean();
- return $r;
+ ob_start();
+ require_once('template/forecast_cat.php');
+ $r.=ob_get_contents();
+ ob_clean();
+ return $r;
- }
- /**
- * @brief create an empty object anticipation
- * @return html string with the form
- */
- public function form_cat() {
- if ($this->f_id != 0)
- return $this->form_cat_mod();
- else
- return $this->form_cat_new();
- }
- /**
- *@brief display a form for modifying or add a forecast
- *@return HTML code
- */
- public function form_item(){
- $forecast=new Forecast($this->cn,$this->f_id);
- $forecast->load();
- $str_name=$forecast->get_parameter('name');
- $r="";
- $str_action=_("Elements");
- $cat=new Forecast_Cat($this->cn);
- $array=$cat->make_array($this->f_id);
- $periode=new Periode($this->cn);
- $aPeriode=$this->cn->make_array("select p_id,to_char(p_start,'MM.YYYY') as label from parm_periode where to_char(p_start,'DD')!='31' order by p_start");
- $aPeriode[]=array('value'=>0,'label'=>'Mensuel');
- $value=$this->cn->get_array("select fi_id,fi_text,fi_account,fi_card,fc_id,fi_amount,fi_debit,fi_pid ".
- " from forecast_item ".
- " where fc_id in (select fc_id from forecast_cat where f_id = $1)",array($this->f_id));
- $max=(count($value) < MAX_FORECAST_ITEM)?MAX_FORECAST_ITEM:count($value);
- $r.=HtmlInput::hidden('nbrow',$max);
+ }
+ /**
+ * @brief create an empty object anticipation
+ * @return html string with the form
+ */
+ public function form_cat()
+ {
+ if ($this->f_id != 0)
+ return $this->form_cat_mod();
+ else
+ return $this->form_cat_new();
+ }
+ /**
+ *@brief display a form for modifying or add a forecast
+ *@return HTML code
+ */
+ public function form_item()
+ {
+ $forecast=new Forecast($this->cn,$this->f_id);
+ $forecast->load();
+ $str_name=$forecast->get_parameter('name');
+ $r="";
+ $str_action=_("Elements");
+ $cat=new Forecast_Cat($this->cn);
+ $array=$cat->make_array($this->f_id);
+ $periode=new Periode($this->cn);
+ $aPeriode=$this->cn->make_array("select p_id,to_char(p_start,'MM.YYYY') as label from parm_periode where to_char(p_start,'DD')!='31' order by p_start");
+ $aPeriode[]=array('value'=>0,'label'=>'Mensuel');
+ $value=$this->cn->get_array("select fi_id,fi_text,fi_account,fi_card,fc_id,fi_amount,fi_debit,fi_pid ".
+ " from forecast_item ".
+ " where fc_id in (select fc_id from forecast_cat where f_id = $1)",array($this->f_id));
+ $max=(count($value) < MAX_FORECAST_ITEM)?MAX_FORECAST_ITEM:count($value);
+ $r.=HtmlInput::hidden('nbrow',$max);
- for ($i=0;$i<$max;$i++){
- if (isset($value[$i]['fi_id'])){
- $r.=HtmlInput::hidden('fi_id'.$i,$value[$i]['fi_id']);
- }
- /* category*/
- $category=new ISelect();
- $category->name='an_cat'.$i;
- $category->value=$array;
- $category->selected=(isset($value[$i]["fc_id"]))?$value[$i]["fc_id"]:-1;
- $aCat[$i]['cat']=$category->input();
+ for ($i=0;$i<$max;$i++)
+ {
+ if (isset($value[$i]['fi_id']))
+ {
+ $r.=HtmlInput::hidden('fi_id'.$i,$value[$i]['fi_id']);
+ }
+ /* category*/
+ $category=new ISelect();
+ $category->name='an_cat'.$i;
+ $category->value=$array;
+ $category->selected=(isset($value[$i]["fc_id"]))?$value[$i]["fc_id"]:-1;
+ $aCat[$i]['cat']=$category->input();
- /* amount */
- $amount=new INum('an_cat_amount'.$i);
- $amount->value=(isset($value[$i]["fi_amount"]))?$value[$i]["fi_amount"]:0;
- $aCat[$i]['amount']=$amount->input();
+ /* amount */
+ $amount=new INum('an_cat_amount'.$i);
+ $amount->value=(isset($value[$i]["fi_amount"]))?$value[$i]["fi_amount"]:0;
+ $aCat[$i]['amount']=$amount->input();
- /* Accounting*/
- $account=new IPoste('an_cat_acc'.$i);
- $account->set_attribute('ipopup','ipop_account');
- $account->set_attribute('label','an_label'.$i);
- $account->set_attribute('account','an_cat_acc'.$i);
- $account->value=(isset($value[$i]["fi_account"]))?$value[$i]["fi_account"]:"";
- $aCat[$i]['account']=$account->input();
- /*Quick Code */
- $qc=new ICard('an_qc'.$i);
- // If double click call the javascript fill_ipopcard
- $qc->set_dblclick("fill_ipopcard(this);");
+ /* Accounting*/
+ $account=new IPoste('an_cat_acc'.$i);
+ $account->set_attribute('ipopup','ipop_account');
+ $account->set_attribute('label','an_label'.$i);
+ $account->set_attribute('account','an_cat_acc'.$i);
+ $account->value=(isset($value[$i]["fi_account"]))?$value[$i]["fi_account"]:"";
+ $aCat[$i]['account']=$account->input();
+ /*Quick Code */
+ $qc=new ICard('an_qc'.$i);
+ // If double click call the javascript fill_ipopcard
+ $qc->set_dblclick("fill_ipopcard(this);");
- // This attribute is mandatory, it is the name of the IPopup
- $qc->set_attribute('ipopup','ipopcard');
+ // This attribute is mandatory, it is the name of the IPopup
+ $qc->set_attribute('ipopup','ipopcard');
- // name of the field to update with the name of the card
- $qc->set_attribute('label','an_label'.$i);
+ // name of the field to update with the name of the card
+ $qc->set_attribute('label','an_label'.$i);
- // Type of card : all
- $qc->set_attribute('typecard','all');
- $qc->set_attribute('jrn',0);
- $qc->extra='all';
+ // Type of card : all
+ $qc->set_attribute('typecard','all');
+ $qc->set_attribute('jrn',0);
+ $qc->extra='all';
- // when value selected in the autcomplete
- $qc->set_function('fill_data');
- if (isset($value[$i]["fi_card"])) {
- $f=new Fiche($this->cn,$value[$i]["fi_card"]);
- $qc->value=$f->strAttribut(ATTR_DEF_QUICKCODE);;
- }
+ // when value selected in the autcomplete
+ $qc->set_function('fill_data');
+ if (isset($value[$i]["fi_card"]))
+ {
+ $f=new Fiche($this->cn,$value[$i]["fi_card"]);
+ $qc->value=$f->strAttribut(ATTR_DEF_QUICKCODE);
+ ;
+ }
- $aCat[$i]['qc']=$qc->search().$qc->input();
- /* Label */
- $label=new IText('an_label'.$i);
- $label->value=(isset($value[$i]["fi_text"]))?$value[$i]["fi_text"]:"";
- $aCat[$i]['name']=$label->input();
+ $aCat[$i]['qc']=$qc->search().$qc->input();
+ /* Label */
+ $label=new IText('an_label'.$i);
+ $label->value=(isset($value[$i]["fi_text"]))?$value[$i]["fi_text"]:"";
+ $aCat[$i]['name']=$label->input();
- //Deb or Cred
- $deb=new ISelect('an_deb'.$i);
- $deb->selected=(isset($value[$i]["fi_debit"]))?$value[$i]["fi_debit"]:-1;
- $deb->value=array(array('value'=>'D','label'=>_('Débit')),
- array('value'=>'C','label'=>_('Crédit'))
- );
- $aCat[$i]['deb']=$deb->input();
- //Periode
- $isPeriode=new ISelect('month'.$i);
- $isPeriode->value=$aPeriode;
- $isPeriode->selected=(isset($value[$i]["fi_pid"]))?$value[$i]["fi_pid"]:0;
- $aCat[$i]['per']=$isPeriode->input();
- }
- $add_row=new IButton('add_row');
- $add_row->label=_('Ajouter une ligne');
- $add_row->javascript='for_add_row(\'fortable\')';
- $f_add_row=$add_row->input();
- ob_start();
- require_once('template/forecast-detail.php');
- $r.=ob_get_contents();
- ob_clean();
- return $r;
- }
- /**
- * @brief unit test
- */
- static function test_me() {
- $cn=new Database(dossier::id());
- $test=new Anticipation($cn);
+ //Deb or Cred
+ $deb=new ISelect('an_deb'.$i);
+ $deb->selected=(isset($value[$i]["fi_debit"]))?$value[$i]["fi_debit"]:-1;
+ $deb->value=array(array('value'=>'D','label'=>_('Débit')),
+ array('value'=>'C','label'=>_('Crédit'))
+ );
+ $aCat[$i]['deb']=$deb->input();
+ //Periode
+ $isPeriode=new ISelect('month'.$i);
+ $isPeriode->value=$aPeriode;
+ $isPeriode->selected=(isset($value[$i]["fi_pid"]))?$value[$i]["fi_pid"]:0;
+ $aCat[$i]['per']=$isPeriode->input();
+ }
+ $add_row=new IButton('add_row');
+ $add_row->label=_('Ajouter une ligne');
+ $add_row->javascript='for_add_row(\'fortable\')';
+ $f_add_row=$add_row->input();
+ ob_start();
+ require_once('template/forecast-detail.php');
+ $r.=ob_get_contents();
+ ob_clean();
+ return $r;
+ }
+ /**
+ * @brief unit test
+ */
+ static function test_me()
+ {
+ $cn=new Database(dossier::id());
+ $test=new Anticipation($cn);
- }
+ }
}
diff --git a/include/class_calendar.php b/include/class_calendar.php
index 4504d3e04..8e664fd22 100644
--- a/include/class_calendar.php
+++ b/include/class_calendar.php
@@ -23,118 +23,129 @@
/*!\file
* \brief Display the calendar
*/
-class Calendar {
- var $current_date;
- private static $nb_day=array(31,28,31,30,31,30,31,31,30,31,30,31);
-
- function __construct() {
- /* get the current month */
- $this->current_date=getdate();
- $this->month=$this->current_date['mon'];
- $this->day=self::$nb_day[$this->month-1];
- $this->year=$this->current_date['year'];
- if ( $this->year % 4 == 0 && $this->month=2)
- $this->day=29;
- }
-
- /*!\brief fill the array given as parameter with the data from action_gestion
- *\param $p_array array of the date of the month
- */
- function fill_from_action(&$p_array) {
- $cn=new Database(dossier::id());
- $sql="select ag_id,substr(ag_title,0,20) as ag_title_fmt,to_char(ag_timestamp,'DD')::integer as ag_timestamp_day ".
- " from action_gestion ".
- " where ".
- " to_char(ag_timestamp,'MM')::integer=$1 ".
- " and to_char(ag_timestamp,'YYYY')::integer=$2 ".
- " and ag_cal='C' and ag_owner=$3";
- $array=$cn->get_array($sql,array($this->month,$this->year,$_SESSION['g_user']));
- for ($i=0;$i';
- $p_array[$ind].="".h($array[$i]['ag_title_fmt']).' ';
- $p_array[$ind].="";
+class Calendar
+{
+ var $current_date;
+ private static $nb_day=array(31,28,31,30,31,30,31,31,30,31,30,31);
+ function __construct()
+ {
+ /* get the current month */
+ $this->current_date=getdate();
+ $this->month=$this->current_date['mon'];
+ $this->day=self::$nb_day[$this->month-1];
+ $this->year=$this->current_date['year'];
+ if ( $this->year % 4 == 0 && $this->month=2)
+ $this->day=29;
}
- }
- /*!\brief fill the array given as parameter with the data from todo
- *\param $p_array array of the date of the month
- */
- function fill_from_todo(&$p_array) {
- $cn=new Database(dossier::id());
- $sql="select tl_id,substr(tl_title,0,20) as tl_title_fmt,to_char(tl_date,'DD')::integer as tl_date_day ".
- " from todo_list ".
- " where ".
- " to_char(tl_date,'MM')::integer=$1 ".
- " and to_char(tl_date,'YYYY')::integer=$2 ".
- " and use_login=$3";
- $array=$cn->get_array($sql,array($this->month,$this->year,$_SESSION['g_user']));
- for ($i=0;$i".h($array[$i]['tl_title_fmt']).'';
- }
- }
- /*!\brief display a calendar after a call to Calendar::fill
- *\param none
- *\return HTML String
- */
- function display() {
- /* day */
- $cell=array();
- for ($i=0;$i<42;$i++) {
- $cell[$i]="";
+
+ /*!\brief fill the array given as parameter with the data from action_gestion
+ *\param $p_array array of the date of the month
+ */
+ function fill_from_action(&$p_array)
+ {
+ $cn=new Database(dossier::id());
+ $sql="select ag_id,substr(ag_title,0,20) as ag_title_fmt,to_char(ag_timestamp,'DD')::integer as ag_timestamp_day ".
+ " from action_gestion ".
+ " where ".
+ " to_char(ag_timestamp,'MM')::integer=$1 ".
+ " and to_char(ag_timestamp,'YYYY')::integer=$2 ".
+ " and ag_cal='C' and ag_owner=$3";
+ $array=$cn->get_array($sql,array($this->month,$this->year,$_SESSION['g_user']));
+ for ($i=0;$i';
+ $p_array[$ind].="".h($array[$i]['ag_title_fmt']).' ';
+ $p_array[$ind].="";
+
+ }
}
- $this->set_month_year();
- /* weekday */
- $week=array(_('Dimanche'),_('Lundi'),_('Mardi'),_('Mercredi'),_('Jeudi'),_('Vendredi'),_('Samedi'));
+ /*!\brief fill the array given as parameter with the data from todo
+ *\param $p_array array of the date of the month
+ */
+ function fill_from_todo(&$p_array)
+ {
+ $cn=new Database(dossier::id());
+ $sql="select tl_id,substr(tl_title,0,20) as tl_title_fmt,to_char(tl_date,'DD')::integer as tl_date_day ".
+ " from todo_list ".
+ " where ".
+ " to_char(tl_date,'MM')::integer=$1 ".
+ " and to_char(tl_date,'YYYY')::integer=$2 ".
+ " and use_login=$3";
+ $array=$cn->get_array($sql,array($this->month,$this->year,$_SESSION['g_user']));
+ for ($i=0;$i".h($array[$i]['tl_title_fmt']).'';
+ }
+ }
+ /*!\brief display a calendar after a call to Calendar::fill
+ *\param none
+ *\return HTML String
+ */
+ function display()
+ {
+ /* day */
+ $cell=array();
+ for ($i=0;$i<42;$i++)
+ {
+ $cell[$i]="";
+ }
+ $this->set_month_year();
+ /* weekday */
+ $week=array(_('Dimanche'),_('Lundi'),_('Mardi'),_('Mercredi'),_('Jeudi'),_('Vendredi'),_('Samedi'));
- $this->fill_from_action($cell);
- $this->fill_from_todo($cell);
- $wMonth=new ISelect('per');
- $cn=new Database(dossier::id());
- $wMonth->value=$cn->make_array("select p_id,to_char(p_start,'MM/YYYY') from parm_periode order by p_start");
- $wMonth->selected=$this->default_periode;
- $wMonth->javascript="onchange=change_month(this)";
- $wMonth->set_attribute('gDossier',dossier::id());
- $month_year=$wMonth->input().$wMonth->get_js_attr();
+ $this->fill_from_action($cell);
+ $this->fill_from_todo($cell);
+ $wMonth=new ISelect('per');
+ $cn=new Database(dossier::id());
+ $wMonth->value=$cn->make_array("select p_id,to_char(p_start,'MM/YYYY') from parm_periode order by p_start");
+ $wMonth->selected=$this->default_periode;
+ $wMonth->javascript="onchange=change_month(this)";
+ $wMonth->set_attribute('gDossier',dossier::id());
+ $month_year=$wMonth->input().$wMonth->get_js_attr();
- ob_start();
- require_once('template/calendar.php');
- $ret=ob_get_contents();
- ob_end_clean();
- return $ret;
- }
- /**
- *@brief set correctly the month and the year with the default_periode
- */
- function set_month_year() {
- $cn=new Database(dossier::id());
- $array=$cn->get_array("select to_char(p_start,'MM') as month, to_char(p_start,'YYYY') as year ".
- " from parm_periode where p_id=$1",array($this->default_periode));
- $this->month=$array[0]['month'];
- $this->year=$array[0]['year'];
- $this->day=self::$nb_day[$this->month-1];
- if ( $this->year % 4 == 0 && $this->month=2)
- $this->day=29;
- }
- /**
- *@brief get the periode from the preference of the current user
- * change the value of default_periode
- *@return $this->default_periode
- */
- function get_preference() {
- $cn=new Database(dossier::id());
- $user=new User($cn);
- $this->default_periode=$user->get_periode();
- return $this->default_periode;
- }
- /**
- *@brief set the periode to the parameter, change the value of $this->default_periode
- * there is no check on the periode
- */
- function set_periode($p_per) {
- $this->default_periode=$p_per;
- }
+ ob_start();
+ require_once('template/calendar.php');
+ $ret=ob_get_contents();
+ ob_end_clean();
+ return $ret;
+ }
+ /**
+ *@brief set correctly the month and the year with the default_periode
+ */
+ function set_month_year()
+ {
+ $cn=new Database(dossier::id());
+ $array=$cn->get_array("select to_char(p_start,'MM') as month, to_char(p_start,'YYYY') as year ".
+ " from parm_periode where p_id=$1",array($this->default_periode));
+ $this->month=$array[0]['month'];
+ $this->year=$array[0]['year'];
+ $this->day=self::$nb_day[$this->month-1];
+ if ( $this->year % 4 == 0 && $this->month=2)
+ $this->day=29;
+ }
+ /**
+ *@brief get the periode from the preference of the current user
+ * change the value of default_periode
+ *@return $this->default_periode
+ */
+ function get_preference()
+ {
+ $cn=new Database(dossier::id());
+ $user=new User($cn);
+ $this->default_periode=$user->get_periode();
+ return $this->default_periode;
+ }
+ /**
+ *@brief set the periode to the parameter, change the value of $this->default_periode
+ * there is no check on the periode
+ */
+ function set_periode($p_per)
+ {
+ $this->default_periode=$p_per;
+ }
- }
+}
diff --git a/include/class_contact.php b/include/class_contact.php
index d38175d27..34f527686 100644
--- a/include/class_contact.php
+++ b/include/class_contact.php
@@ -1,4 +1,4 @@
-fiche_def_ref=FICHE_TYPE_CONTACT;
- parent::__construct($p_cn,$p_id) ;
- $this->company="";
+ $this->fiche_def_ref=FICHE_TYPE_CONTACT;
+ parent::__construct($p_cn,$p_id) ;
+ $this->company="";
}
-/*! Summary
- **************************************************
- * \brief show the default screen
- *
- * \param p_search (filter)
- *
- * \return string to display
- */
- function Summary($p_search="",$p_action="",$p_sql="")
+ /*! Summary
+ **************************************************
+ * \brief show the default screen
+ *
+ * \param p_search (filter)
+ *
+ * \return string to display
+ */
+ function Summary($p_search="",$p_action="",$p_sql="")
{
- $p_search=FormatString($p_search);
- $extra_sql="";
- if ( $this->company != "")
- {
- $extra_sql="and f_id in (select f_id from jnt_fic_att_value join
-attr_value using (jft_id) where av_text=upper('".$this->company."') and ad_id=".ATTR_DEF_COMPANY.") ";
- }
- $url=urlencode($_SERVER['REQUEST_URI']);
- $script=$_SERVER['PHP_SELF'];
- // Creation of the nav bar
- // Get the max numberRow
- $all_contact=$this->CountByDef($this->fiche_def_ref,$p_search,$extra_sql);
- // Get offset and page variable
- $offset=( isset ($_REQUEST['offset'] )) ?$_REQUEST['offset']:0;
- $page=(isset($_REQUEST['page']))?$_REQUEST['page']:1;
- $bar=jrn_navigation_bar($offset,$all_contact,$_SESSION['g_pagesize'],$page);
- // set a filter ?
- $search="";
- if ( trim($p_search) != "" )
- {
- $search=" and f_id in
-(select f_id from jnt_fic_att_value
- join fiche using (f_id)
- join attr_value using (jft_id)
- where
- ad_id=1 and av_text ~* '$p_search') ";
- }
- // Get The result Array
- $step_contact=$this->GetAll($offset,$search.$extra_sql.$p_sql);
- if ( $all_contact == 0 ) return "";
- $r=$bar;
- $r.='
-
-Quick Code
-Nom
-Téléphone
-email
-Fax
- ';
- $base=$_SERVER['PHP_SELF'];
- // Compute the url
- $url="";
- $and="?";
- $get=$_GET;
- if ( isset ($get) ) {
- foreach ($get as $name=>$value ) {
- // we clean the parameter offset, step, page and size
- if ( ! in_array($name,array('f_id','detail'))) {
- $url.=$and.$name."=".$value;
- $and="&";
- }// if
- }//foreach
- }// if
-$back_url=urlencode($_SERVER['REQUEST_URI']);
- if ( sizeof ($step_contact ) == 0 )
- return $r;
- echo JS_LEDGER;
- foreach ($step_contact as $contact ) {
- $l_company=new Fiche($this->cn);
- $l_company->get_by_qcode($contact->strAttribut(ATTR_DEF_COMPANY),false);
- $l_company_name=$l_company->strAttribut(ATTR_DEF_NAME);
- if ( $l_company_name == NOTFOUND ) $l_company_name="";
- // add popup for detail
- if ( $l_company_name !="")
- {
- $l_company_name=sprintf("%s - %s ",
- $contact->strAttribut(ATTR_DEF_COMPANY),
- $contact->strAttribut(ATTR_DEF_COMPANY),
- $l_company_name
- );
- }
- $r.="";
- $qcode=$contact->strAttribut(ATTR_DEF_QUICKCODE);
- $r.=''.$qcode.
- " ";
- $r.="".$contact->strAttribut(ATTR_DEF_NAME)." ";
- $r.="".$contact->strAttribut(ATTR_DEF_TEL)." ";
- $r.="".$contact->strAttribut(ATTR_DEF_EMAIL)." ".
- " ".$contact->strAttribut(ATTR_DEF_FAX)." ";
+ $p_search=FormatString($p_search);
+ $extra_sql="";
+ if ( $this->company != "")
+ {
+ $extra_sql="and f_id in (select f_id from jnt_fic_att_value join
+ attr_value using (jft_id) where av_text=upper('".$this->company."') and ad_id=".ATTR_DEF_COMPANY.") ";
+ }
+ $url=urlencode($_SERVER['REQUEST_URI']);
+ $script=$_SERVER['PHP_SELF'];
+ // Creation of the nav bar
+ // Get the max numberRow
+ $all_contact=$this->CountByDef($this->fiche_def_ref,$p_search,$extra_sql);
+ // Get offset and page variable
+ $offset=( isset ($_REQUEST['offset'] )) ?$_REQUEST['offset']:0;
+ $page=(isset($_REQUEST['page']))?$_REQUEST['page']:1;
+ $bar=jrn_navigation_bar($offset,$all_contact,$_SESSION['g_pagesize'],$page);
+ // set a filter ?
+ $search="";
+ if ( trim($p_search) != "" )
+ {
+ $search=" and f_id in
+ (select f_id from jnt_fic_att_value
+ join fiche using (f_id)
+ join attr_value using (jft_id)
+ where
+ ad_id=1 and av_text ~* '$p_search') ";
+ }
+ // Get The result Array
+ $step_contact=$this->GetAll($offset,$search.$extra_sql.$p_sql);
+ if ( $all_contact == 0 ) return "";
+ $r=$bar;
+ $r.='
+
+ Quick Code
+ Nom
+ Téléphone
+ email
+ Fax
+ ';
+ $base=$_SERVER['PHP_SELF'];
+ // Compute the url
+ $url="";
+ $and="?";
+ $get=$_GET;
+ if ( isset ($get) )
+ {
+ foreach ($get as $name=>$value )
+ {
+ // we clean the parameter offset, step, page and size
+ if ( ! in_array($name,array('f_id','detail')))
+ {
+ $url.=$and.$name."=".$value;
+ $and="&";
+ }// if
+ }//foreach
+ }// if
+ $back_url=urlencode($_SERVER['REQUEST_URI']);
+ if ( sizeof ($step_contact ) == 0 )
+ return $r;
+ echo JS_LEDGER;
+ foreach ($step_contact as $contact )
+ {
+ $l_company=new Fiche($this->cn);
+ $l_company->get_by_qcode($contact->strAttribut(ATTR_DEF_COMPANY),false);
+ $l_company_name=$l_company->strAttribut(ATTR_DEF_NAME);
+ if ( $l_company_name == NOTFOUND ) $l_company_name="";
+ // add popup for detail
+ if ( $l_company_name !="")
+ {
+ $l_company_name=sprintf("%s - %s ",
+ $contact->strAttribut(ATTR_DEF_COMPANY),
+ $contact->strAttribut(ATTR_DEF_COMPANY),
+ $l_company_name
+ );
+ }
+ $r.="";
+ $qcode=$contact->strAttribut(ATTR_DEF_QUICKCODE);
+ $r.=''.$qcode.
+ " ";
+ $r.="".$contact->strAttribut(ATTR_DEF_NAME)." ";
+ $r.="".$contact->strAttribut(ATTR_DEF_TEL)." ";
+ $r.="".$contact->strAttribut(ATTR_DEF_EMAIL)." ".
+ " ".$contact->strAttribut(ATTR_DEF_FAX)." ";
- $r.=" ";
+ $r.="";
- }
- $r.="
";
- $r.=$bar;
- return $r;
+ }
+ $r.="
";
+ $r.=$bar;
+ return $r;
}
}
diff --git a/include/class_customer.php b/include/class_customer.php
index ac6c5be55..bf036d02f 100644
--- a/include/class_customer.php
+++ b/include/class_customer.php
@@ -1,4 +1,4 @@
-fiche_def_ref=FICHE_TYPE_CLIENT;
- parent::__construct($p_cn,$p_id) ;
+ /*! \brief Constructor
+ /* only a db connection is needed */
+ function Customer($p_cn,$p_id=0)
+ {
+ $this->fiche_def_ref=FICHE_TYPE_CLIENT;
+ parent::__construct($p_cn,$p_id) ;
- }
- /*! \brief Get all info contains in the view
- * thanks to the poste elt (account)
- */
- function get_by_account($p_poste=0) {
- $this->poste=($p_poste==0)?$this->poste:$p_poste;
- $sql="select * from vw_client where poste_comptable=$1";
- $Res=$this->cn->exec_sql($sql,array($this->poste));
- if ( Database::num_row($Res) == 0) return null;
- if ( Database::num_row($Res) > 1 ) throw new Exception ('Plusieurs fiches avec le même poste',1);
- // There is only _one_ row by customer
- $row=Database::fetch_array($Res,0);
- $this->name=$row['name'];
- $this->id=$row['f_id'];
- $this->street=$row['rue'];
- $this->cp=$row['code_postal'];
- $this->country=$row['pays'];
- $this->vat_number=$row['tva_num'];
+ }
+ /*! \brief Get all info contains in the view
+ * thanks to the poste elt (account)
+ */
+ function get_by_account($p_poste=0)
+ {
+ $this->poste=($p_poste==0)?$this->poste:$p_poste;
+ $sql="select * from vw_client where poste_comptable=$1";
+ $Res=$this->cn->exec_sql($sql,array($this->poste));
+ if ( Database::num_row($Res) == 0) return null;
+ if ( Database::num_row($Res) > 1 ) throw new Exception ('Plusieurs fiches avec le même poste',1);
+ // There is only _one_ row by customer
+ $row=Database::fetch_array($Res,0);
+ $this->name=$row['name'];
+ $this->id=$row['f_id'];
+ $this->street=$row['rue'];
+ $this->cp=$row['code_postal'];
+ $this->country=$row['pays'];
+ $this->vat_number=$row['tva_num'];
- }
-/*!
- * \brief Get all the info for making a vat listing
- * for the vat administration
- *
- * \param $p_year
- *
- * \return double array structure is
- * ( j_poste,name,vat_number,amount,tva,customer(object)
- *
- */
- function VatListing($p_year) {
- $cond_sql=" and A.j_date = B.j_date and extract(year from A.j_date) ='$p_year'";
- /* List of customer */
- $aCustomer=$this->cn->get_array('select f_id,name,quick_code,tva_num,poste_comptable from vw_client '.
- " where tva_num !='' ");
+ }
+ /*!
+ * \brief Get all the info for making a vat listing
+ * for the vat administration
+ *
+ * \param $p_year
+ *
+ * \return double array structure is
+ * ( j_poste,name,vat_number,amount,tva,customer(object)
+ *
+ */
+ function VatListing($p_year)
+ {
+ $cond_sql=" and A.j_date = B.j_date and extract(year from A.j_date) ='$p_year'";
+ /* List of customer */
+ $aCustomer=$this->cn->get_array('select f_id,name,quick_code,tva_num,poste_comptable from vw_client '.
+ " where tva_num !='' ");
- /* Use the code */
+ /* Use the code */
- // BASE ACCOUNT
- // for belgium
- $s=new Acc_Parm_Code($this->cn,'VENTE');
- $s->load();
- $SOLD=$s->p_value;
+ // BASE ACCOUNT
+ // for belgium
+ $s=new Acc_Parm_Code($this->cn,'VENTE');
+ $s->load();
+ $SOLD=$s->p_value;
- $c=new Acc_Parm_Code($this->cn,'CUSTOMER');
- $c->load();
- $CUSTOMER=$c->p_value;
+ $c=new Acc_Parm_Code($this->cn,'CUSTOMER');
+ $c->load();
+ $CUSTOMER=$c->p_value;
- $t=new Acc_Parm_Code($this->cn,'COMPTE_TVA');
- $t->load();
- $TVA=$t->p_value;
+ $t=new Acc_Parm_Code($this->cn,'COMPTE_TVA');
+ $t->load();
+ $TVA=$t->p_value;
- $a_Res=array();
- /* for each customer compute VAT, Amount...*/
- foreach ($aCustomer as $l ) {
- // Seek the customer
- //---
- $customer=$l['quick_code'];
- $a_Res[$customer]['name']=$l['name'];
- $a_Res[$customer]['vat_number']=$l['tva_num'];
- $a_Res[$customer]['amount']=0;
- $a_Res[$customer]['tva']=0;
- $a_Res[$customer]['poste_comptable']=$l['poste_comptable'];
- /* retrieve only operation of sold and vat */
- // Get all the sell operation
- //----
- $sql="select distinct j_grpt
- from
-jrnx as A
- join jrnx as B using (j_grpt)
-where
- A.j_qcode = '".$l['quick_code']."' and
- B.j_poste::text like '".$SOLD."%'
- $cond_sql
-";
+ $a_Res=array();
+ /* for each customer compute VAT, Amount...*/
+ foreach ($aCustomer as $l )
+ {
+ // Seek the customer
+ //---
+ $customer=$l['quick_code'];
+ $a_Res[$customer]['name']=$l['name'];
+ $a_Res[$customer]['vat_number']=$l['tva_num'];
+ $a_Res[$customer]['amount']=0;
+ $a_Res[$customer]['tva']=0;
+ $a_Res[$customer]['poste_comptable']=$l['poste_comptable'];
+ /* retrieve only operation of sold and vat */
+ // Get all the sell operation
+ //----
+ $sql="select distinct j_grpt
+ from
+ jrnx as A
+ join jrnx as B using (j_grpt)
+ where
+ A.j_qcode = '".$l['quick_code']."' and
+ B.j_poste::text like '".$SOLD."%'
+ $cond_sql
+ ";
- $Res=$this->cn->exec_sql($sql);
- // Foreach operation
- // where 7% or tva account are involved
- // and store the result in an array (a_Res)
- //---
+ $Res=$this->cn->exec_sql($sql);
+ // Foreach operation
+ // where 7% or tva account are involved
+ // and store the result in an array (a_Res)
+ //---
- for ($i=0; $i < Database::num_row($Res);$i++) {
- // Get each row
- //---
- $row1=Database::fetch_array($Res,$i);
-
+ for ($i=0; $i < Database::num_row($Res);$i++)
+ {
+ // Get each row
+ //---
+ $row1=Database::fetch_array($Res,$i);
- // select the operation
- //----
- $Res2=$this->cn->exec_sql("select j_poste,j_montant,j_debit from jrnx where j_grpt=".$row1['j_grpt']);
- $a_row=Database::fetch_all($Res2);
- // Store the amount in the array
- //---
- foreach ($a_row as $e) {
- $amount=0;
- $tva=0;
- if ( substr($e['j_poste'],0, strlen($SOLD))===$SOLD) {
- $amount=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
- }
- if ( substr($e['j_poste'],0, strlen($TVA))===$TVA) {
- $tva=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
- }
- // store sold
- //---
- $a_Res[$customer]['amount']=(isset($a_Res[$customer]['amount']))?$a_Res[$customer]['amount']:0;
- $a_Res[$customer]['amount']+=$amount;
+ // select the operation
+ //----
+ $Res2=$this->cn->exec_sql("select j_poste,j_montant,j_debit from jrnx where j_grpt=".$row1['j_grpt']);
+ $a_row=Database::fetch_all($Res2);
- // store vat
- //---
- $a_Res[$customer]['tva']=(isset($a_Res[$customer]['tva']))?$a_Res[$customer]['tva']:0;
- $a_Res[$customer]['tva']+=$tva;
-
- // store customef info
- //---
- $a_Res[$customer]['customer']=$customer;
- }
- }// foreach $a
- } // foreach ( customer)
+ // Store the amount in the array
+ //---
+ foreach ($a_row as $e)
+ {
+ $amount=0;
+ $tva=0;
+ if ( substr($e['j_poste'],0, strlen($SOLD))===$SOLD)
+ {
+ $amount=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
+ }
+ if ( substr($e['j_poste'],0, strlen($TVA))===$TVA)
+ {
+ $tva=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
+ }
+ // store sold
+ //---
+ $a_Res[$customer]['amount']=(isset($a_Res[$customer]['amount']))?$a_Res[$customer]['amount']:0;
+ $a_Res[$customer]['amount']+=$amount;
- return $a_Res;
- }
+ // store vat
+ //---
+ $a_Res[$customer]['tva']=(isset($a_Res[$customer]['tva']))?$a_Res[$customer]['tva']:0;
+ $a_Res[$customer]['tva']+=$tva;
+
+ // store customef info
+ //---
+ $a_Res[$customer]['customer']=$customer;
+ }
+ }// foreach $a
+ } // foreach ( customer)
+
+ return $a_Res;
+ }
}
diff --git a/include/class_database.php b/include/class_database.php
index 457f3c5fc..c9a04d3cf 100644
--- a/include/class_database.php
+++ b/include/class_database.php
@@ -1,28 +1,28 @@
5 ) die ("-->Dossier invalide [$p_database_id]");
- $phpcompta_user=phpcompta_user;
- $password=phpcompta_password;
- $port=phpcompta_psql_port;
- $host=( ! defined ("phpcompta_psql_host"))?'127.0.0.1':phpcompta_psql_host;
+ private $db; /*!< database connection */
+ private $ret; /*!< return value */
+ /*!\brief constructor
+ *\param $p_database_id is the id of the dossier, or the modele following the
+ * p_type if = 0 then connect to the repository
+ *\param $p_type is 'DOS' (defaut) for dossier or 'MOD'
+ */
+ function __construct ($p_database_id=0,$p_type='dos')
+ {
+ if ( IsNumber($p_database_id) == false || strlen($p_database_id) > 5 ) die ("-->Dossier invalide [$p_database_id]");
+ $phpcompta_user=phpcompta_user;
+ $password=phpcompta_password;
+ $port=phpcompta_psql_port;
+ $host=( ! defined ("phpcompta_psql_host"))?'127.0.0.1':phpcompta_psql_host;
- if ( $p_database_id == 0 ) { /* connect to the repository */
- $l_dossier=sprintf("%saccount_repository",strtolower(domaine));
- } else if ( $p_type == 'dos') { /* connect to a folder (dossier) */
- $l_dossier=sprintf("%sdossier%d",strtolower(domaine),$p_database_id);
- } else if ($p_type=='mod') { /* connect to a template (modele) */
- $l_dossier=sprintf("%smod%d",strtolower(domaine),$p_database_id);
- } else if ($p_type=='template') {
- $l_dossier='template1';
- } else { throw new Exception ('Connection invalide'); }
+ if ( $p_database_id == 0 )
+ { /* connect to the repository */
+ $l_dossier=sprintf("%saccount_repository",strtolower(domaine));
+ }
+ else if ( $p_type == 'dos')
+ { /* connect to a folder (dossier) */
+ $l_dossier=sprintf("%sdossier%d",strtolower(domaine),$p_database_id);
+ }
+ else if ($p_type=='mod')
+ { /* connect to a template (modele) */
+ $l_dossier=sprintf("%smod%d",strtolower(domaine),$p_database_id);
+ }
+ else if ($p_type=='template')
+ {
+ $l_dossier='template1';
+ }
+ else
+ {
+ throw new Exception ('Connection invalide');
+ }
- ob_start();
- $a=pg_connect("dbname=$l_dossier host='$host' user='$phpcompta_user'
-password='$password' port=$port");
+ ob_start();
+ $a=pg_connect("dbname=$l_dossier host='$host' user='$phpcompta_user'
+ password='$password' port=$port");
- if ( $a == false )
- {
- ob_end_clean();
- echo 'Impossible de se connecter à postgreSql ! ';
- echo '';
- echo "Vos paramètres sont incorrectes : ";
- echo " ";
- echo "base de donnée : $l_dossier ";
- echo "Domaine : ".domaine." ";
- echo "Port $port ";
- echo "Utilisateur : $phpcompta_user ";
- echo '
';
+ if ( $a == false )
+ {
+ ob_end_clean();
+ echo 'Impossible de se connecter à postgreSql ! ';
+ echo '';
+ echo "Vos paramètres sont incorrectes : ";
+ echo " ";
+ echo "base de donnée : $l_dossier ";
+ echo "Domaine : ".domaine." ";
+ echo "Port $port ";
+ echo "Utilisateur : $phpcompta_user ";
+ echo '
';
- exit ("Connection impossible : vérifiez vos paramètres de base
-de données");
+ exit ("Connection impossible : vérifiez vos paramètres de base
+ de données");
- }
- $this->db=$a;
- if ( $this->exist_schema('comptaproc') )
- pg_exec($this->db,'set search_path to public,comptaproc;');
- ob_end_clean();
- }
+ }
+ $this->db=$a;
+ if ( $this->exist_schema('comptaproc') )
+ pg_exec($this->db,'set search_path to public,comptaproc;');
+ ob_end_clean();
+ }
- public function verify() {
- // Verify that the elt we want to add is correct
- }
- function set_encoding($p_charset) {
- pg_set_client_encoding($this->db,$p_charset);
+ public function verify()
+ {
+ // Verify that the elt we want to add is correct
+ }
+ function set_encoding($p_charset)
+ {
+ pg_set_client_encoding($this->db,$p_charset);
}
/*!
* \brief send a sql string to the database
@@ -96,27 +110,39 @@ de données");
* \param $p_array array for the SQL string (see pg_query_params)
* \return false if error otherwise true
*/
- function exec_sql( $p_string,$p_array=null) {
- try {
- $this->sql=$p_string;
- $this->array=$p_array;
- if ( $p_array==null ) {
- $this->ret=pg_query($this->db,$p_string);
- } else {
- $this->ret=pg_query_params($this->db,$p_string,$p_array);
- }
- if ( ! $this->ret ) { throw new Exception (" SQL ERROR $p_string ",1);}
- }catch (Exception $a) {
- if (DEBUG) {
- print_r ($p_string);
- print_r($p_array);
- echo $a->getMessage();
- echo $a->getTrace();
- }
- throw ($a);
- }
+ function exec_sql( $p_string,$p_array=null)
+ {
+ try
+ {
+ $this->sql=$p_string;
+ $this->array=$p_array;
+ if ( $p_array==null )
+ {
+ $this->ret=pg_query($this->db,$p_string);
+ }
+ else
+ {
+ $this->ret=pg_query_params($this->db,$p_string,$p_array);
+ }
+ if ( ! $this->ret )
+ {
+ throw new Exception (" SQL ERROR $p_string ",1);
+ }
- return $this->ret;
+ }
+ catch (Exception $a)
+ {
+ if (DEBUG)
+ {
+ print_r ($p_string);
+ print_r($p_array);
+ echo $a->getMessage();
+ echo $a->getTrace();
+ }
+ throw ($a);
+ }
+
+ return $this->ret;
}
/*! \brief Count the number of row returned by a sql statement
@@ -127,15 +153,15 @@ de données");
function count_sql($p_sql,$p_array=null)
{
- $r_sql=$this->exec_sql($p_sql,$p_array);
- return pg_NumRows($r_sql);
+ $r_sql=$this->exec_sql($p_sql,$p_array);
+ return pg_NumRows($r_sql);
}
/*!\brief get the current sequence value
*/
function get_current_seq($p_seq)
{
- $Res=$this->get_value("select currval('$p_seq') as seq");
- return $Res;
+ $Res=$this->get_value("select currval('$p_seq') as seq");
+ return $Res;
}
@@ -143,109 +169,126 @@ de données");
*/
function get_next_seq($p_seq)
{
- $Res=$this->exec_sql("select nextval('$p_seq') as seq");
- $seq=pg_fetch_array($Res,0);
- return $seq['seq'];
+ $Res=$this->exec_sql("select nextval('$p_seq') as seq");
+ $seq=pg_fetch_array($Res,0);
+ return $seq['seq'];
}
/**
* @ brief : start a transaction
*
*/
- function start() {
- $Res=$this->exec_sql("start transaction");
+ function start()
+ {
+ $Res=$this->exec_sql("start transaction");
}
/**
* Commit the transaction
*
*/
- function commit() {
- $Res=$this->exec_sql("commit");
+ function commit()
+ {
+ $Res=$this->exec_sql("commit");
}
/**
* rollback the current transaction
*/
- function rollback() {
- $Res=$this->exec_sql("rollback");
+ function rollback()
+ {
+ $Res=$this->exec_sql("rollback");
}
/**
* @brief alter the sequence value
* @param $p_name name of the sequence
* @param $min the start value of the sequence
*/
- function alter_seq($p_name,$min) {
- if ($min < 1) $min=1;
- $Res=$this->exec_sql("alter sequence $p_name restart $min");
+ function alter_seq($p_name,$min)
+ {
+ if ($min < 1) $min=1;
+ $Res=$this->exec_sql("alter sequence $p_name restart $min");
}
/*!
* \brief Execute a sql script
* \param $script script name
*/
- function execute_script($script) {
+ function execute_script($script)
+ {
- if ( DEBUG=='false' ) ob_start();
- $hf=fopen($script,'r');
- if ( $hf == false ) {
- echo 'Ne peut ouvrir '.$script;
- exit();
- }
- $sql="";
- $flag_function=false;
- while (!feof($hf)) {
- $buffer=fgets($hf);
- $buffer=str_replace ("$","\$",$buffer);
- print $buffer." ";
- // comment are not execute
- if ( substr($buffer,0,2) == "--" ) {
- //echo "comment $buffer";
- continue;
- }
- // Blank Lines Are Skipped
- If ( Strlen($buffer)==0) {
- //echo "Blank $buffer";
- Continue;
- }
- if ( strpos(strtolower($buffer),"create function")===0 ) {
- echo "found a function";
- $flag_function=true;
- $sql=$buffer;
- continue;
- }
- if ( strpos(strtolower($buffer),"create or replace function")===0 ) {
- echo "found a function";
- $flag_function=true;
- $sql=$buffer;
- continue;
- }
- // No semi colon -> multiline command
- if ( $flag_function== false && strpos($buffer,';') == false ) {
- $sql.=$buffer;
- continue;
- }
- if ( $flag_function ) {
- if ( strpos(strtolower($buffer), "language plpgsql") === false &&
- strpos(strtolower($buffer), "language 'plpgsql'") === false ) {
- $sql.=$buffer;
- continue;
- }
- } else {
- // cut the semi colon
- $buffer=str_replace (';','',$buffer);
- }
- $sql.=$buffer;
- if ( $this->exec_sql($sql) == false ) {
- $this->rollback();
- if ( DEBUG=='false' ) ob_end_clean();
- print "ERROR : $sql";
- exit();
- }
- $sql="";
- $flag_function=false;
- print " ";
- } // while (feof)
- fclose($hf);
- if ( DEBUG=='false' ) ob_end_clean();
+ if ( DEBUG=='false' ) ob_start();
+ $hf=fopen($script,'r');
+ if ( $hf == false )
+ {
+ echo 'Ne peut ouvrir '.$script;
+ exit();
+ }
+ $sql="";
+ $flag_function=false;
+ while (!feof($hf))
+ {
+ $buffer=fgets($hf);
+ $buffer=str_replace ("$","\$",$buffer);
+ print $buffer." ";
+ // comment are not execute
+ if ( substr($buffer,0,2) == "--" )
+ {
+ //echo "comment $buffer";
+ continue;
+ }
+ // Blank Lines Are Skipped
+ If ( Strlen($buffer)==0)
+ {
+ //echo "Blank $buffer";
+ Continue;
+ }
+ if ( strpos(strtolower($buffer),"create function")===0 )
+ {
+ echo "found a function";
+ $flag_function=true;
+ $sql=$buffer;
+ continue;
+ }
+ if ( strpos(strtolower($buffer),"create or replace function")===0 )
+ {
+ echo "found a function";
+ $flag_function=true;
+ $sql=$buffer;
+ continue;
+ }
+ // No semi colon -> multiline command
+ if ( $flag_function== false && strpos($buffer,';') == false )
+ {
+ $sql.=$buffer;
+ continue;
+ }
+ if ( $flag_function )
+ {
+ if ( strpos(strtolower($buffer), "language plpgsql") === false &&
+ strpos(strtolower($buffer), "language 'plpgsql'") === false )
+ {
+ $sql.=$buffer;
+ continue;
+ }
+ }
+ else
+ {
+ // cut the semi colon
+ $buffer=str_replace (';','',$buffer);
+ }
+ $sql.=$buffer;
+ if ( $this->exec_sql($sql) == false )
+ {
+ $this->rollback();
+ if ( DEBUG=='false' ) ob_end_clean();
+ print "ERROR : $sql";
+ exit();
+ }
+ $sql="";
+ $flag_function=false;
+ print " ";
+ } // while (feof)
+ fclose($hf);
+ if ( DEBUG=='false' ) ob_end_clean();
}
/*!
* \brief Get version of a database, the content of the
@@ -254,29 +297,33 @@ de données");
* \return version number
*
*/
- function get_version() {
- $Res=$this->get_value("select val from version");
- return $Res;
+ function get_version()
+ {
+ $Res=$this->get_value("select val from version");
+ return $Res;
}
-/**
- *@brief fetch the $p_indice array from the last query
- *@param $p_indice index
- *
- */
- function fetch($p_indice) {
- if ( $this->ret == false ) throw new Exception ('this->ret is empty');
- return pg_fetch_array($this->ret ) ;
+ /**
+ *@brief fetch the $p_indice array from the last query
+ *@param $p_indice index
+ *
+ */
+ function fetch($p_indice)
+ {
+ if ( $this->ret == false ) throw new Exception ('this->ret is empty');
+ return pg_fetch_array($this->ret ) ;
}
/*!@brief return the number of rows found by the last query,
synomym for count()*/
- function size() {
- return pg_NumRows($this->ret);
+ function size()
+ {
+ return pg_NumRows($this->ret);
}
/*!@brief return the number of rows found by the last query,
synomym for size()*/
- function count() {
- return pg_NumRows($this->ret);
+ function count()
+ {
+ return pg_NumRows($this->ret);
}
/*!\brief loop to apply all the path to a folder or
@@ -287,93 +334,101 @@ de données");
*/
function apply_patch($p_name,$from_setup=1)
{
- $MaxVersion=DBVERSION-1;
- echo '';
- $add=($from_setup==0)?'admin/':'';
- for ( $i = 4;$i <= $MaxVersion;$i++)
- {
- $to=$i+1;
- if ( $this->get_version() <= $i ) {
- echo "Patching ".$p_name.
- " from the version ".$this->get_version()." to $to ";
+ $MaxVersion=DBVERSION-1;
+ echo '';
+ $add=($from_setup==0)?'admin/':'';
+ for ( $i = 4;$i <= $MaxVersion;$i++)
+ {
+ $to=$i+1;
+ if ( $this->get_version() <= $i )
+ {
+ echo "Patching ".$p_name.
+ " from the version ".$this->get_version()." to $to ";
- $this->execute_script($add.'sql/patch/upgrade'.$i.'.sql');
- if ( DEBUG=='false' ) ob_start();
- // specific for version 4
- if ( $i == 4 )
- {
- $sql="select jrn_def_id from jrn_def ";
- $Res=$this->exec_sql($sql);
- $Max=$this->size();
- for ($seq=0;$seq<$Max;$seq++) {
- $row=pg_fetch_array($Res,$seq);
- $sql=sprintf ("create sequence s_jrn_%d",$row['jrn_def_id']);
- $this->exec_sql($sql);
- }
- }
- // specific to version 7
- if ( $i == 7 )
- {
- // now we use sequence instead of computing a max
- //
- $Res2=$this->exec_sql('select coalesce(max(jr_grpt_id),1) as l from jrn');
- $Max2= pg_NumRows($Res2) ;
- if ( $Max2 == 1) {
- $Row=pg_fetch_array($Res2,0);
- var_dump($Row);
- $M=$Row['l'];
- $this->exec_sql("select setval('s_grpt',$M,true)");
- }
- }
- // specific to version 17
- if ( $i == 17 )
- {
- $this->execute_script($add.'sql/patch/upgrade17.sql');
- $max=$this->get_value('select last_value from s_jnt_fic_att_value');
- $this->alter_seq($p_cn,'s_jnt_fic_att_value',$max+1);
- } // version
+ $this->execute_script($add.'sql/patch/upgrade'.$i.'.sql');
+ if ( DEBUG=='false' ) ob_start();
+ // specific for version 4
+ if ( $i == 4 )
+ {
+ $sql="select jrn_def_id from jrn_def ";
+ $Res=$this->exec_sql($sql);
+ $Max=$this->size();
+ for ($seq=0;$seq<$Max;$seq++)
+ {
+ $row=pg_fetch_array($Res,$seq);
+ $sql=sprintf ("create sequence s_jrn_%d",$row['jrn_def_id']);
+ $this->exec_sql($sql);
+ }
+ }
+ // specific to version 7
+ if ( $i == 7 )
+ {
+ // now we use sequence instead of computing a max
+ //
+ $Res2=$this->exec_sql('select coalesce(max(jr_grpt_id),1) as l from jrn');
+ $Max2= pg_NumRows($Res2) ;
+ if ( $Max2 == 1)
+ {
+ $Row=pg_fetch_array($Res2,0);
+ var_dump($Row);
+ $M=$Row['l'];
+ $this->exec_sql("select setval('s_grpt',$M,true)");
+ }
+ }
+ // specific to version 17
+ if ( $i == 17 )
+ {
+ $this->execute_script($add.'sql/patch/upgrade17.sql');
+ $max=$this->get_value('select last_value from s_jnt_fic_att_value');
+ $this->alter_seq($p_cn,'s_jnt_fic_att_value',$max+1);
+ } // version
- // reset sequence in the modele
- //--
- if ( $i == 30 && $p_name=="mod" )
- {
- $a_seq=array('s_jrn','s_jrn_op','s_centralized',
- 's_stock_goods','c_order','s_central');
- foreach ($a_seq as $seq ) {
- $sql=sprintf("select setval('%s',1,false)",$seq);
- $Res=$this->exec_sql($sql);
- }
- $sql="select jrn_def_id from jrn_def ";
- $Res=$this->exec_sql($sql);
- $Max=pg_NumRows($Res);
- for ($seq=0;$seq<$Max;$seq++) {
- $row=pg_fetch_array($Res,$seq);
- $sql=sprintf ("select setval('s_jrn_%d',1,false)",$row['jrn_def_id']);
- $this->exec_sql($sql);
- }
+ // reset sequence in the modele
+ //--
+ if ( $i == 30 && $p_name=="mod" )
+ {
+ $a_seq=array('s_jrn','s_jrn_op','s_centralized',
+ 's_stock_goods','c_order','s_central');
+ foreach ($a_seq as $seq )
+ {
+ $sql=sprintf("select setval('%s',1,false)",$seq);
+ $Res=$this->exec_sql($sql);
+ }
+ $sql="select jrn_def_id from jrn_def ";
+ $Res=$this->exec_sql($sql);
+ $Max=pg_NumRows($Res);
+ for ($seq=0;$seq<$Max;$seq++)
+ {
+ $row=pg_fetch_array($Res,$seq);
+ $sql=sprintf ("select setval('s_jrn_%d',1,false)",$row['jrn_def_id']);
+ $this->exec_sql($sql);
+ }
- }
- if ( $i == 36 ) {
- /* check the country and apply the path */
- $res=$this->exec_sql("select pr_value from parameter where pr_id='MY_COUNTRY'");
- $country=pg_fetch_result($res,0,0);
- $this->execute_script($add."sql/patch/upgrade36.".$country.".sql");
- $this->exec_sql('update tmp_pcmn set pcm_type=find_pcm_type(pcm_val)');
- }
- if ($i == 59 ){
- $res=$this->exec_sql("select pr_value from parameter where pr_id='MY_COUNTRY'");
- $country=pg_fetch_result($res,0,0);
- if ( $country == 'BE') $this->exec_sql("insert into parm_code values ('SUPPLIER',440,'Poste par défaut pour les fournisseurs')");
- if ($country=='FR') $this->exec_sql("insert into parm_code values ('SUPPLIER',400,'Poste par défaut pour les fournisseurs')");
- }
- if ( $i == 61 ) {
- $country=$this->get_value ("select pr_value from parameter where pr_id='MY_COUNTRY'");
- $this->execute_script($add."sql/patch/upgrade61.".$country.".sql");
- }
- if ( DEBUG == 'false') ob_end_clean();
- }
- }
- echo ' ';
+ }
+ if ( $i == 36 )
+ {
+ /* check the country and apply the path */
+ $res=$this->exec_sql("select pr_value from parameter where pr_id='MY_COUNTRY'");
+ $country=pg_fetch_result($res,0,0);
+ $this->execute_script($add."sql/patch/upgrade36.".$country.".sql");
+ $this->exec_sql('update tmp_pcmn set pcm_type=find_pcm_type(pcm_val)');
+ }
+ if ($i == 59 )
+ {
+ $res=$this->exec_sql("select pr_value from parameter where pr_id='MY_COUNTRY'");
+ $country=pg_fetch_result($res,0,0);
+ if ( $country == 'BE') $this->exec_sql("insert into parm_code values ('SUPPLIER',440,'Poste par défaut pour les fournisseurs')");
+ if ($country=='FR') $this->exec_sql("insert into parm_code values ('SUPPLIER',400,'Poste par défaut pour les fournisseurs')");
+ }
+ if ( $i == 61 )
+ {
+ $country=$this->get_value ("select pr_value from parameter where pr_id='MY_COUNTRY'");
+ $this->execute_script($add."sql/patch/upgrade61.".$country.".sql");
+ }
+ if ( DEBUG == 'false') ob_end_clean();
+ }
+ }
+ echo ' ';
}
/*!\brief return the value of the sql, the sql will return only one value
* with the value
@@ -387,11 +442,11 @@ de données");
*/
function get_value($p_sql,$p_array=null)
{
- $this->ret=$this->exec_sql($p_sql,$p_array);
- if ( pg_NumRows($this->ret) == 0 ) return "";
- if ( pg_NumRows($this->ret) > 1 ) throw new Exception( "Attention $p_sql retourne plusieurs valeurs");
- $r=pg_fetch_row($this->ret,0);
- return $r[0];
+ $this->ret=$this->exec_sql($p_sql,$p_array);
+ if ( pg_NumRows($this->ret) == 0 ) return "";
+ if ( pg_NumRows($this->ret) > 1 ) throw new Exception( "Attention $p_sql retourne plusieurs valeurs");
+ $r=pg_fetch_row($this->ret,0);
+ return $r[0];
}
/*!\brief purpose return the result of a sql statment
@@ -400,38 +455,42 @@ de données");
* \param $p_array if not null we use ExecSqlParam
*\return an empty array if nothing is found
*/
- function get_array($p_sql,$p_array=null) {
- $r=$this->exec_sql($p_sql,$p_array);
+ function get_array($p_sql,$p_array=null)
+ {
+ $r=$this->exec_sql($p_sql,$p_array);
- if ( ($Max= pg_NumRows($r)) == 0 ) return array();
- $array=pg_fetch_all($r);
- return $array;
+ if ( ($Max= pg_NumRows($r)) == 0 ) return array();
+ $array=pg_fetch_all($r);
+ return $array;
}
- function create_sequence($p_name,$min=1) {
- if ($min < 1) $min=1;
- $sql="create sequence ".$p_name." minvalue $min";
- $this->exec_sql($sql);
+ function create_sequence($p_name,$min=1)
+ {
+ if ($min < 1) $min=1;
+ $sql="create sequence ".$p_name." minvalue $min";
+ $this->exec_sql($sql);
}
/*!\brief test if a sequence exist */
/* \return true if the seq. exist otherwise false
*/
- function exist_sequence($p_name) {
- $r=$this->count_sql("select relname from pg_class where relname=lower($1)",array($p_name));
- if ( $r==0)
- return false;
- return true;
+ function exist_sequence($p_name)
+ {
+ $r=$this->count_sql("select relname from pg_class where relname=lower($1)",array($p_name));
+ if ( $r==0)
+ return false;
+ return true;
}
- /*!\brief test if a table exist
+ /*!\brief test if a table exist
*\param $p_name table name
*\param $schema name of the schema default public
* \return true if a table exist otherwise false
*/
- function exist_table($p_name,$p_schema='public') {
- $r=$this->count_sql("select table_name from information_schema.tables where table_schema=$1 and table_name=lower($2)", array($p_schema,$p_name));
- if ( $r==0)
- return false;
- return true;
+ function exist_table($p_name,$p_schema='public')
+ {
+ $r=$this->count_sql("select table_name from information_schema.tables where table_schema=$1 and table_name=lower($2)", array($p_schema,$p_name));
+ if ( $r==0)
+ return false;
+ return true;
}
/**
* Check if a column exists in a table
@@ -440,65 +499,76 @@ de données");
* @param $schema :schema name, default public
*@return true or false
*/
- function exist_column($col,$table,$schema) {
- $r=$this->get_value('select count(*) from information_schema.columns where table_name=lower($1) and column_name=lower($2) and table_schema=lower($3)',
- array($col,$table,$schema));
- if ( $r > 0 ) return true;
- return false;
+ function exist_column($col,$table,$schema)
+ {
+ $r=$this->get_value('select count(*) from information_schema.columns where table_name=lower($1) and column_name=lower($2) and table_schema=lower($3)',
+ array($col,$table,$schema));
+ if ( $r > 0 ) return true;
+ return false;
}
/**
*@brief check if the large object exists
*@param $p_oid of the large object
*@return return true if the large obj exist or false if not
*/
- function exist_blob($p_oid) {
- $r=$this->get_value('select count(loid) from pg_largeobject where loid=$1'
- ,array($p_oid) );
- if ($r > 0) return true; else return false;
+ function exist_blob($p_oid)
+ {
+ $r=$this->get_value('select count(loid) from pg_largeobject where loid=$1'
+ ,array($p_oid) );
+ if ($r > 0) return true;
+ else return false;
}
/*
*!\brief test if a view exist
* \return true if the view. exist otherwise false
*/
- function exist_view($p_name) {
- $r=$this->count_sql("select viewname from pg_views where viewname=lower($1)",array($p_name));
- if ( $r==0)
- return false;
- return true;
+ function exist_view($p_name)
+ {
+ $r=$this->count_sql("select viewname from pg_views where viewname=lower($1)",array($p_name));
+ if ( $r==0)
+ return false;
+ return true;
}
/*
*!\brief test if a schema exists
* \return true if the schemas exists otherwise false
*/
- function exist_schema($p_name) {
- $r=$this->count_sql("select nspname from pg_namespace where nspname=lower($1)",array($p_name));
- if ( $r==0)
- return false;
- return true;
- }
+ function exist_schema($p_name)
+ {
+ $r=$this->count_sql("select nspname from pg_namespace where nspname=lower($1)",array($p_name));
+ if ( $r==0)
+ return false;
+ return true;
+ }
/*!
*\brief create a string containing the value separated by comma
* for use in a SQL in statement
*\return the string or empty if nothing is found
*\see fid_card.php
*/
- function make_list($sql,$p_array=null) {
- if ( $p_array == null ) {
- $aArray=$this->get_array($sql);
- } else {
- $aArray=$this->get_array($sql,$p_array);
- }
- if (empty ($aArray) ) return "";
- $aIdx=array_keys($aArray[0]);
- $idx=$aIdx[0];
- $ret="";$f="";
- for ($i = 0; $i < count($aArray);$i++) {
- $row=$aArray[$i];
- $ret.=$f.$aArray[$i][$idx];
- $f=',';
- }
- $ret=trim($ret,',');
- return $ret;
+ function make_list($sql,$p_array=null)
+ {
+ if ( $p_array == null )
+ {
+ $aArray=$this->get_array($sql);
+ }
+ else
+ {
+ $aArray=$this->get_array($sql,$p_array);
+ }
+ if (empty ($aArray) ) return "";
+ $aIdx=array_keys($aArray[0]);
+ $idx=$aIdx[0];
+ $ret="";
+ $f="";
+ for ($i = 0; $i < count($aArray);$i++)
+ {
+ $row=$aArray[$i];
+ $ret.=$f.$aArray[$i][$idx];
+ $f=',';
+ }
+ $ret=trim($ret,',');
+ return $ret;
}
/*!
* \brief make a array with the sql
@@ -510,8 +580,8 @@ de données");
* options
* \return: a double array like
\verbatim
-Array
-(
+ Array
+ (
[0] => Array
(
[value] => 1
@@ -529,30 +599,34 @@ Array
[value] => 3
[label] => Marchandise C
)
-)
+ )
\endverbatim
* \see ISelect
*/
- function make_array($p_sql,$p_null=0) {
- $a=$this->exec_sql($p_sql);
- $max=pg_NumRows($a);
- if ( $max==0) return null;
- for ($i=0;$i<$max;$i++) {
- $row=pg_fetch_row($a);
- $r[$i]['value']=$row[0];
- $r[$i]['label']=$row[1];
- }
- // add a blank item ?
- if ( $p_null == 1 ) {
- for ($i=$max;$i!=0;$i--) {
- $r[$i]['value']= $r[$i-1]['value'];
- $r[$i]['label']= $r[$i-1]['label'];
- }
- $r[0]['value']=-1;
- $r[0]['label']=" ";
- } // if ( $p_null == 1 )
+ function make_array($p_sql,$p_null=0)
+ {
+ $a=$this->exec_sql($p_sql);
+ $max=pg_NumRows($a);
+ if ( $max==0) return null;
+ for ($i=0;$i<$max;$i++)
+ {
+ $row=pg_fetch_row($a);
+ $r[$i]['value']=$row[0];
+ $r[$i]['label']=$row[1];
+ }
+ // add a blank item ?
+ if ( $p_null == 1 )
+ {
+ for ($i=$max;$i!=0;$i--)
+ {
+ $r[$i]['value']= $r[$i-1]['value'];
+ $r[$i]['label']= $r[$i-1]['label'];
+ }
+ $r[0]['value']=-1;
+ $r[0]['label']=" ";
+ } // if ( $p_null == 1 )
- return $r;
+ return $r;
}
/*!
* \brief Save a "piece justificative"
@@ -562,135 +636,174 @@ Array
* null if a error occurs
*
*/
- function save_upload_document ($seq) {
- /* there is
- no file to
- upload */
- if ($_FILES["pj"]["error"] == UPLOAD_ERR_NO_FILE ){ return;}
+ function save_upload_document ($seq)
+ {
+ /* there is
+ no file to
+ upload */
+ if ($_FILES["pj"]["error"] == UPLOAD_ERR_NO_FILE )
+ {
+ return;
+ }
- $new_name=tempnam($_ENV['TMP'],'pj');
- if ($_FILES["pj"]["error"] > 0)
- {
- print_r($_FILES);
- echo_error(__FILE__.":".__LINE__."Error: " . $_FILES["pj"]["error"] );
- }
- if ( strlen ($_FILES['pj']['tmp_name']) != 0 ) {
- if (move_uploaded_file($_FILES['pj']['tmp_name'],
- $new_name)) {
- // echo "Image saved";
- $oid= pg_lo_import($this->db,$new_name);
- if ( $oid == false ) {
- echo_error('postgres.php',__LINE__,"cannot upload document");
- $this->rollback();
- return;
- }
- // Remove old document
- $ret=$this->exec_sql("select jr_pj from jrn where jr_grpt_id=$seq");
- if (pg_num_rows($ret) != 0) {
- $r=pg_fetch_array($ret,0);
- $old_oid=$r['jr_pj'];
- if (strlen($old_oid) != 0)
- pg_lo_unlink($cn,$old_oid);
- }
- // Load new document
- $this->exec_sql("update jrn set jr_pj=".$oid.", jr_pj_name='".$_FILES['pj']['name']."', ".
- "jr_pj_type='".$_FILES['pj']['type']."' where jr_grpt_id=$seq");
- return $oid;
+ $new_name=tempnam($_ENV['TMP'],'pj');
+ if ($_FILES["pj"]["error"] > 0)
+ {
+ print_r($_FILES);
+ echo_error(__FILE__.":".__LINE__."Error: " . $_FILES["pj"]["error"] );
+ }
+ if ( strlen ($_FILES['pj']['tmp_name']) != 0 )
+ {
+ if (move_uploaded_file($_FILES['pj']['tmp_name'],
+ $new_name))
+ {
+ // echo "Image saved";
+ $oid= pg_lo_import($this->db,$new_name);
+ if ( $oid == false )
+ {
+ echo_error('postgres.php',__LINE__,"cannot upload document");
+ $this->rollback();
+ return;
+ }
+ // Remove old document
+ $ret=$this->exec_sql("select jr_pj from jrn where jr_grpt_id=$seq");
+ if (pg_num_rows($ret) != 0)
+ {
+ $r=pg_fetch_array($ret,0);
+ $old_oid=$r['jr_pj'];
+ if (strlen($old_oid) != 0)
+ pg_lo_unlink($cn,$old_oid);
+ }
+ // Load new document
+ $this->exec_sql("update jrn set jr_pj=".$oid.", jr_pj_name='".$_FILES['pj']['name']."', ".
+ "jr_pj_type='".$_FILES['pj']['type']."' where jr_grpt_id=$seq");
+ return $oid;
- } else {
- echo "Error ";
- $this->rollback();
+ }
+ else
+ {
+ echo "Error ";
+ $this->rollback();
- }
- }
- return 0;
+ }
+ }
+ return 0;
+ }
+ /*!\brief wrapper for the function pg_NumRows
+ *\param $ret is the result of a exec_sql
+ *\return number of line affected
+ */
+ static function num_row($ret)
+ {
+ return pg_NumRows($ret);
}
- /*!\brief wrapper for the function pg_NumRows
- *\param $ret is the result of a exec_sql
- *\return number of line affected
- */
- static function num_row($ret) { return pg_NumRows($ret); }
- /*!\brief wrapper for the function pg_fetch_array
- *\param $ret is the result of a pg_exec
- *\param $p_indice is the index
- *\return $array of column
- */
- static function fetch_array($ret,$p_indice=0) { return pg_fetch_array($ret,$p_indice); }
+ /*!\brief wrapper for the function pg_fetch_array
+ *\param $ret is the result of a pg_exec
+ *\param $p_indice is the index
+ *\return $array of column
+ */
+ static function fetch_array($ret,$p_indice=0)
+ {
+ return pg_fetch_array($ret,$p_indice);
+ }
- /*!\brief wrapper for the function pg_fetch_all
- *\param $ret is the result of pg_exec (exec_sql)
- *\return double array (row x col )
- */
- static function fetch_all($ret) { return pg_fetch_all($ret); }
+ /*!\brief wrapper for the function pg_fetch_all
+ *\param $ret is the result of pg_exec (exec_sql)
+ *\return double array (row x col )
+ */
+ static function fetch_all($ret)
+ {
+ return pg_fetch_all($ret);
+ }
- /*!\brief wrapper for the function pg_fetch_all
- *\param $ret is the result of pg_exec (exec_sql)
- *\param $p_row is the indice of the row
- *\param $p_col is the indice of the col
- *\return a string or an integer
- */
- static function fetch_result($ret,$p_row=0,$p_col=0) { return pg_fetch_result($ret,$p_row,$p_col); }
+ /*!\brief wrapper for the function pg_fetch_all
+ *\param $ret is the result of pg_exec (exec_sql)
+ *\param $p_row is the indice of the row
+ *\param $p_col is the indice of the col
+ *\return a string or an integer
+ */
+ static function fetch_result($ret,$p_row=0,$p_col=0)
+ {
+ return pg_fetch_result($ret,$p_row,$p_col);
+ }
/*!\brief wrapper for the function pg_lo_unlink
*\param $p_oid is the of oid
*\return return the result of the operation
*/
- function lo_unlink($p_oid) { return pg_lo_unlink($this->db,$p_oid); }
+ function lo_unlink($p_oid)
+ {
+ return pg_lo_unlink($this->db,$p_oid);
+ }
/*!\brief wrapper for the function pg_prepare
*\param $p_string string name for pg_prepare function
*\param $p_sql is the sql to prepare
*\return return the result of the operation
*/
- function prepare($p_string,$p_sql) { return pg_prepare($this->db,$p_string,$p_sql); }
+ function prepare($p_string,$p_sql)
+ {
+ return pg_prepare($this->db,$p_string,$p_sql);
+ }
/*!\brief wrapper for the function pg_execute
*\param $p_string string name of the stmt given in pg_prepare function
*\param $p_array contains the variables
*\note set this->ret to the return of pg_execute
*\return return the result of the operation,
*/
- function execute($p_string,$p_array) { $this->ret=pg_execute($this->db,$p_string,$p_array); return $this->ret;}
-
- /*!\brief wrapper for the function pg_lo_export
- *\param $p_oid is the oid of the log
- *\param $tmp is the file
- *\return result of the operation
- */
- function lo_export($p_oid,$tmp) {
- return pg_lo_export($this->db,$p_oid,$tmp);
- }
- /*!\brief wrapper for the function pg_lo_export
- *\param $p_oid is the oid of the log
- *\param $tmp is the file
- *\return result of the operation
- */
- function lo_import($p_oid) {
- return pg_lo_import($this->db,$p_oid);
+ function execute($p_string,$p_array)
+ {
+ $this->ret=pg_execute($this->db,$p_string,$p_array);
+ return $this->ret;
}
- /*!\brief wrapper for the function pg_escape_string
- *\param $p_string is the string to escape
- *\return escaped string
- */
- static function escape_string($p_string) {
- return pg_escape_string($p_string);
+ /*!\brief wrapper for the function pg_lo_export
+ *\param $p_oid is the oid of the log
+ *\param $tmp is the file
+ *\return result of the operation
+ */
+ function lo_export($p_oid,$tmp)
+ {
+ return pg_lo_export($this->db,$p_oid,$tmp);
+ }
+ /*!\brief wrapper for the function pg_lo_export
+ *\param $p_oid is the oid of the log
+ *\param $tmp is the file
+ *\return result of the operation
+ */
+ function lo_import($p_oid)
+ {
+ return pg_lo_import($this->db,$p_oid);
+ }
+
+ /*!\brief wrapper for the function pg_escape_string
+ *\param $p_string is the string to escape
+ *\return escaped string
+ */
+ static function escape_string($p_string)
+ {
+ return pg_escape_string($p_string);
+ }
+ /*!\brief wrapper for the function pg_close
+ */
+ function close()
+ {
+ pg_close($this->db);
}
- /*!\brief wrapper for the function pg_close
- */
- function close() { pg_close($this->db);}
/*!\brief
*\param
*\return
*\note
*\see
*/
- function __toString() {
- return "database ";
- }
- static function test_me() {
+ function __toString()
+ {
+ return "database ";
}
+ static function test_me()
+ {}
}
diff --git a/include/class_document.php b/include/class_document.php
index 6adc5ebd0..b6b249eed 100644
--- a/include/class_document.php
+++ b/include/class_document.php
@@ -1,4 +1,4 @@
-db=$p_cn;
- $this->d_id=$p_d_id;
- }
- /*!\brief insert a minimal document and set the d_id
- */
- function blank()
+ $this->db=$p_cn;
+ $this->d_id=$p_d_id;
+ }
+ /*!\brief insert a minimal document and set the d_id
+ */
+ function blank()
{
- $this->d_id=$this->db->get_next_seq("document_d_id_seq");
- // affect a number
- $this->d_number=$this->db->get_next_seq("seq_doc_type_".$this->md_type);
- $sql=sprintf('insert into document(d_id,ag_id,d_number) values(%d,%d,%d)',
- $this->d_id,
- $this->ag_id,
- $this->d_number);
- $this->db->exec_sql($sql);
+ $this->d_id=$this->db->get_next_seq("document_d_id_seq");
+ // affect a number
+ $this->d_number=$this->db->get_next_seq("seq_doc_type_".$this->md_type);
+ $sql=sprintf('insert into document(d_id,ag_id,d_number) values(%d,%d,%d)',
+ $this->d_id,
+ $this->ag_id,
+ $this->d_number);
+ $this->db->exec_sql($sql);
}
- /*!
- * \brief Generate the document, Call $this-\>Replace to replace
- * tag by value
- *
- *
- * \return an array : the url where the generated doc can be found, the name
- * of the file and his mimetype
- */
- function Generate()
+ /*!
+ * \brief Generate the document, Call $this-\>Replace to replace
+ * tag by value
+ *
+ *
+ * \return an array : the url where the generated doc can be found, the name
+ * of the file and his mimetype
+ */
+ function Generate()
{
- // create a temp directory in /tmp to unpack file and to parse it
- $dirname=tempnam($_ENV['TMP'],'doc_');
+ // create a temp directory in /tmp to unpack file and to parse it
+ $dirname=tempnam($_ENV['TMP'],'doc_');
- unlink($dirname);
- mkdir ($dirname);
- // Retrieve the lob and save it into $dirname
- $this->db->start();
- $dm_info="select md_name,md_type,md_lob,md_filename,md_mimetype
- from document_modele where md_id=".$this->md_id;
- $Res=$this->db->exec_sql($dm_info);
+ unlink($dirname);
+ mkdir ($dirname);
+ // Retrieve the lob and save it into $dirname
+ $this->db->start();
+ $dm_info="select md_name,md_type,md_lob,md_filename,md_mimetype
+ from document_modele where md_id=".$this->md_id;
+ $Res=$this->db->exec_sql($dm_info);
- $row=Database::fetch_array($Res,0);
- $this->d_lob=$row['md_lob'];
- $this->d_filename=$row['md_filename'];
- $this->d_mimetype=$row['md_mimetype'];
- $this->d_name=$row['md_name'];
+ $row=Database::fetch_array($Res,0);
+ $this->d_lob=$row['md_lob'];
+ $this->d_filename=$row['md_filename'];
+ $this->d_mimetype=$row['md_mimetype'];
+ $this->d_name=$row['md_name'];
- chdir($dirname);
- $filename=$row['md_filename'];
- $exp=$this->db->lo_export($row['md_lob'],$dirname.DIRECTORY_SEPARATOR.$filename);
- if ( $exp === false ) echo_warning( __FILE__.":".__LINE__."Export NOK $filename");
-
- $type="n";
- // if the doc is a OOo, we need to unzip it first
- // and the name of the file to change is always content.xml
- if ( strpos($row['md_mimetype'],'vnd.oasis') != 0 )
- {
- ob_start();
- system("unzip '".$filename."'");
- // Remove the file we do not need anymore
- unlink($filename);
- ob_end_clean();
- $file_to_parse="content.xml";
- $type="OOo";
- }
- else
- $file_to_parse=$filename;
- // affect a number
- $this->d_number=$this->db->get_next_seq("seq_doc_type_".$row['md_type']);
+ chdir($dirname);
+ $filename=$row['md_filename'];
+ $exp=$this->db->lo_export($row['md_lob'],$dirname.DIRECTORY_SEPARATOR.$filename);
+ if ( $exp === false ) echo_warning( __FILE__.":".__LINE__."Export NOK $filename");
- // parse the document - return the doc number ?
- $this->ParseDocument($dirname,$file_to_parse,$type);
+ $type="n";
+ // if the doc is a OOo, we need to unzip it first
+ // and the name of the file to change is always content.xml
+ if ( strpos($row['md_mimetype'],'vnd.oasis') != 0 )
+ {
+ ob_start();
+ system("unzip '".$filename."'");
+ // Remove the file we do not need anymore
+ unlink($filename);
+ ob_end_clean();
+ $file_to_parse="content.xml";
+ $type="OOo";
+ }
+ else
+ $file_to_parse=$filename;
+ // affect a number
+ $this->d_number=$this->db->get_next_seq("seq_doc_type_".$row['md_type']);
- $this->db->commit();
- // if the doc is a OOo, we need to re-zip it
- if ( strpos($row['md_mimetype'],'vnd.oasis') != 0 )
- {
- ob_start();
- system ("zip -r ".$filename." *");
- ob_end_clean();
- echo " ";
+ // parse the document - return the doc number ?
+ $this->ParseDocument($dirname,$file_to_parse,$type);
- $file_to_parse=$filename;
- }
+ $this->db->commit();
+ // if the doc is a OOo, we need to re-zip it
+ if ( strpos($row['md_mimetype'],'vnd.oasis') != 0 )
+ {
+ ob_start();
+ system ("zip -r ".$filename." *");
+ ob_end_clean();
+ echo " ";
- $this->SaveGenerated($dirname.DIRECTORY_SEPARATOR.$file_to_parse);
- // Invoice
- $ret='Document généré ';
- rmdir($dirname);
- return $ret;
+ $file_to_parse=$filename;
+ }
+
+ $this->SaveGenerated($dirname.DIRECTORY_SEPARATOR.$file_to_parse);
+ // Invoice
+ $ret='Document généré ';
+ rmdir($dirname);
+ return $ret;
}
-
- /*! ParseDocument
- * \brief This function parse a document and replace all
- * the predefined tags by a value. This functions
- * generate diffent documents (invoice, order, letter)
- * with the info from the database
- *
- * \param $p_dir directory name
- * \param $p_file filename
- * \param $p_type For the OOo document the tag are < and > instead of < and >
- */
- function ParseDocument($p_dir,$p_file,$p_type)
+
+ /*! ParseDocument
+ * \brief This function parse a document and replace all
+ * the predefined tags by a value. This functions
+ * generate diffent documents (invoice, order, letter)
+ * with the info from the database
+ *
+ * \param $p_dir directory name
+ * \param $p_file filename
+ * \param $p_type For the OOo document the tag are < and > instead of < and >
+ */
+ function ParseDocument($p_dir,$p_file,$p_type)
{
-
- /*!\note Replace in the doc the tags by their values.
- * - MY_* table parameter
- * - ART_VEN* table quant_sold for invoice
- * - CUST_* table quant_sold and fiche for invoice
- * - e_* for the invoice in the $_POST
- */
- // open the document
- $infile_name=$p_dir.DIRECTORY_SEPARATOR.$p_file;
- $h=fopen($infile_name,"r");
- // check if tmpdir exist otherwise create it
- $temp_dir=$_SERVER["DOCUMENT_ROOT"].DIRECTORY_SEPARATOR.'tmp';
- if ( is_dir($temp_dir) == false )
- {
- if ( mkdir($temp_dir) == false )
- {
- echo "Ne peut pas créer le répertoire ".$temp_dir;
- exit();
- }
- }
- // Compute output_name
- $output_name=tempnam($temp_dir,"gen_doc_");
- $output_file=fopen($output_name,"w+");
- // check if the opening is sucessfull
- if ( $h === false )
- {
- echo __FILE__.":".__LINE__."cannot open $p_dir $p_file ";
- exit();
- }
- if ( $output_file == false)
- {
- echo "ne peut pas ouvrir le fichier de sortie";
- exit();
- }
- // compute the regex
- if ( $p_type=='OOo')
- {
- $regex="=*<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*>>";
- $lt="<";
- $gt=">";
- }
- else
- {
- $regex="=*<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*>>";
- $lt="<";
- $gt=">";
- }
- //read the file
- while(! feof($h))
- {
- // replace the tag
- $buffer=fgets($h);
- // search in the buffer the magic << and >>
- // while myereg finds something to replace
- while ( @eregi ($regex,$buffer,$f) )
- {
- foreach ( $f as $pattern )
- {
- $to_remove=$pattern;
- // we remove the < and > from the pattern
- $pattern=str_replace($lt,'',$pattern);
- $pattern=str_replace($gt,'',$pattern);
+ /*!\note Replace in the doc the tags by their values.
+ * - MY_* table parameter
+ * - ART_VEN* table quant_sold for invoice
+ * - CUST_* table quant_sold and fiche for invoice
+ * - e_* for the invoice in the $_POST
+ */
+ // open the document
+ $infile_name=$p_dir.DIRECTORY_SEPARATOR.$p_file;
+ $h=fopen($infile_name,"r");
+
+ // check if tmpdir exist otherwise create it
+ $temp_dir=$_SERVER["DOCUMENT_ROOT"].DIRECTORY_SEPARATOR.'tmp';
+ if ( is_dir($temp_dir) == false )
+ {
+ if ( mkdir($temp_dir) == false )
+ {
+ echo "Ne peut pas créer le répertoire ".$temp_dir;
+ exit();
+ }
+ }
+ // Compute output_name
+ $output_name=tempnam($temp_dir,"gen_doc_");
+ $output_file=fopen($output_name,"w+");
+ // check if the opening is sucessfull
+ if ( $h === false )
+ {
+ echo __FILE__.":".__LINE__."cannot open $p_dir $p_file ";
+ exit();
+ }
+ if ( $output_file == false)
+ {
+ echo "ne peut pas ouvrir le fichier de sortie";
+ exit();
+ }
+ // compute the regex
+ if ( $p_type=='OOo')
+ {
+ $regex="=*<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*>>";
+ $lt="<";
+ $gt=">";
+ }
+ else
+ {
+ $regex="=*<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*>>";
+ $lt="<";
+ $gt=">";
+ }
+ //read the file
+ while(! feof($h))
+ {
+ // replace the tag
+ $buffer=fgets($h);
+ // search in the buffer the magic << and >>
+ // while myereg finds something to replace
+ while ( @eregi ($regex,$buffer,$f) )
+ {
+ foreach ( $f as $pattern )
+ {
+ $to_remove=$pattern;
+ // we remove the < and > from the pattern
+ $pattern=str_replace($lt,'',$pattern);
+ $pattern=str_replace($gt,'',$pattern);
- // if the pattern if found we replace it
- $value=$this->Replace($pattern);
- if ( strpos($value,'ERROR') != false ) $value="";
- // replace into the $buffer
- // take the position in the buffer
- $pos=strpos($buffer,$to_remove);
- // get the length of the string to remove
- $len=strlen($to_remove);
- if ( $p_type=='OOo' ) {
- $value=str_replace('&','&',$value);
- $value=str_replace('<','<',$value);
- $value=str_replace('>','>',$value);
- $value=str_replace('"','"',$value);
- $value=str_replace("'",''',$value);
- }
- $buffer=substr_replace($buffer,$value,$pos,$len);
+ // if the pattern if found we replace it
+ $value=$this->Replace($pattern);
+ if ( strpos($value,'ERROR') != false ) $value="";
+ // replace into the $buffer
+ // take the position in the buffer
+ $pos=strpos($buffer,$to_remove);
+ // get the length of the string to remove
+ $len=strlen($to_remove);
+ if ( $p_type=='OOo' )
+ {
+ $value=str_replace('&','&',$value);
+ $value=str_replace('<','<',$value);
+ $value=str_replace('>','>',$value);
+ $value=str_replace('"','"',$value);
+ $value=str_replace("'",''',$value);
+ }
+ $buffer=substr_replace($buffer,$value,$pos,$len);
- // if the pattern if found we replace it
- }
- }
- // write into the output_file
- fwrite($output_file,$buffer);
+ // if the pattern if found we replace it
+ }
+ }
+ // write into the output_file
+ fwrite($output_file,$buffer);
- }
- fclose($h);
- fclose($output_file);
- if ( ($ret=copy ($output_name,$infile_name)) == FALSE ){
- echo _('Ne peut pas sauver '.$output_name.' vers '.$infile_name.' code d\'erreur ='.$ret);
- }
+ }
+ fclose($h);
+ fclose($output_file);
+ if ( ($ret=copy ($output_name,$infile_name)) == FALSE )
+ {
+ echo _('Ne peut pas sauver '.$output_name.' vers '.$infile_name.' code d\'erreur ='.$ret);
+ }
}
- /*! SaveGenerated
- * \brief Save the generated Document
- * \param $p_file is the generated file
- *
- *
- * \return 0 if no error otherwise 1
- */
- function SaveGenerated($p_file)
+ /*! SaveGenerated
+ * \brief Save the generated Document
+ * \param $p_file is the generated file
+ *
+ *
+ * \return 0 if no error otherwise 1
+ */
+ function SaveGenerated($p_file)
{
- // We save the generated file
- $doc=new Document($this->db);
- $this->db->start();
- $this->d_lob=$this->db->lo_import($p_file);
- if ( $this->d_lob == false ) { echo "ne peut pas importer [$p_file]";
- return 1; }
-
- $sql="insert into document(ag_id,d_lob,d_number,d_filename,d_mimetype)
- values ($1,$2,$3,$4,$5)";
+ // We save the generated file
+ $doc=new Document($this->db);
+ $this->db->start();
+ $this->d_lob=$this->db->lo_import($p_file);
+ if ( $this->d_lob == false )
+ {
+ echo "ne peut pas importer [$p_file]";
+ return 1;
+ }
- $this->db->exec_sql($sql, array($this->ag_id,
- $this->d_lob,
- $this->d_number,
- $this->d_filename,
- $this->d_mimetype));
- $this->d_id=$this->db->get_current_seq("document_d_id_seq");
- // Clean the file
- unlink ($p_file);
- $this->db->commit();
- return 0;
- }
- /*! Upload
- * \brief Upload a file into document
- * all the needed data are in $_FILES we don't increment the seq
- * \param $p_file : array containing by default $_FILES
- *
- * \return
- */
- function Upload($p_ag_id)
- {
- // nothing to save
- if ( sizeof($_FILES) == 0 ) return;
+ $sql="insert into document(ag_id,d_lob,d_number,d_filename,d_mimetype)
+ values ($1,$2,$3,$4,$5)";
- /* for several files */
- /* $_FILES is now an array */
- // Start Transaction
- $this->db->start();
- $name=$_FILES['file_upload']['name'];
- for ($i = 0; $i < sizeof($name);$i++) {
- $new_name=tempnam($_ENV['TMP'],'doc_');
- // check if a file is submitted
- if ( strlen($_FILES['file_upload']['tmp_name'][$i]) != 0 )
- {
- // upload the file and move it to temp directory
- if ( move_uploaded_file($_FILES['file_upload']['tmp_name'][$i],$new_name))
- {
- $oid=$this->db->lo_import($new_name);
- // check if the lob is in the database
- if ( $oid == false )
- {
- $this->db->rollback();
- return 1;
- }
- }
- // the upload in the database is successfull
- $this->d_lob=$oid;
- $this->d_filename=$_FILES['file_upload']['name'][$i];
- $this->d_mimetype=$_FILES['file_upload']['type'][$i];
-
- // insert into the table
- $sql="insert into document (ag_id, d_lob,d_filename,d_mimetype,d_number) values ($1,$2,$3,$4,5)";
- $this->db->exec_sql($sql,array($p_ag_id,$this->d_lob,$this->d_filename,$this->d_mimetype));
- }
- } /* end for */
- $this->db->commit();
-
+ $this->db->exec_sql($sql, array($this->ag_id,
+ $this->d_lob,
+ $this->d_number,
+ $this->d_filename,
+ $this->d_mimetype));
+ $this->d_id=$this->db->get_current_seq("document_d_id_seq");
+ // Clean the file
+ unlink ($p_file);
+ $this->db->commit();
+ return 0;
}
- /*! a_ref
- * \brief create and compute a string for reference the doc
- *
- * \return a string
- */
- function a_ref()
+ /*! Upload
+ * \brief Upload a file into document
+ * all the needed data are in $_FILES we don't increment the seq
+ * \param $p_file : array containing by default $_FILES
+ *
+ * \return
+ */
+ function Upload($p_ag_id)
{
- if ( $this->d_id == 0 )
- return '';
- $image=' ';
- $r="";
- $r=' '.$image.' ';
- return $r;
- }
- /* ! Get
- * \brief Send the document
- */
- function Send()
- {
- // retrieve the template and generate document
- $this->db->start();
- $ret=$this->db->exec_sql(
- "select d_id,d_lob,d_filename,d_mimetype from document where d_id=".$this->d_id );
- if ( Database::num_row ($ret) == 0 )
- return;
- $row=Database::fetch_array($ret,0);
- //the document is saved into file $tmp
- $tmp=tempnam($_ENV['TMP'],'document_');
- $this->db->lo_export($row['d_lob'],$tmp);
- $this->d_mimetype=$row['d_mimetype'];
- $this->d_filename=$row['d_filename'];
+ // nothing to save
+ if ( sizeof($_FILES) == 0 ) return;
- // send it to stdout
- ini_set('zlib.output_compression','Off');
- header("Pragma: public");
- header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
- header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
- header("Cache-Control: must-revalidate");
- header('Content-type: '.$this->d_mimetype);
- header('Content-Disposition: attachment;filename="'.$this->d_filename.'"',FALSE);
- header("Accept-Ranges: bytes");
- $file=fopen($tmp,'r');
- while ( !feof ($file) )
- {
- echo fread($file,8192);
- }
- fclose($file);
-
- unlink ($tmp);
-
- $this->db->commit();
-
- }
- /*!\brief get all the document of a given action
- *\param $ag_id the ag_id from action::ag_id (primary key)
- *\return an array of objects document or an empty array if nothing found
- */
- function get_all($ag_id) {
- $res=$this->db->get_array('select d_id, ag_id, d_lob, d_number, d_filename,'.
- ' d_mimetype from document where ag_id=$1',array($ag_id));
- $a=array();
- for ($i=0;$idb);
- $doc->d_id=$res[$i]['d_id'];
- $doc->ag_id=$res[$i]['ag_id'];
- $doc->d_lob=$res[$i]['d_lob'];
- $doc->d_number=$res[$i]['d_number'];
- $doc->d_filename=$res[$i]['d_filename'];
- $doc->d_mimetype=$res[$i]['d_mimetype'];
- $a[$i]=clone $doc;
- }
- return $a;
- }
+ /* for several files */
+ /* $_FILES is now an array */
+ // Start Transaction
+ $this->db->start();
+ $name=$_FILES['file_upload']['name'];
+ for ($i = 0; $i < sizeof($name);$i++)
+ {
+ $new_name=tempnam($_ENV['TMP'],'doc_');
+ // check if a file is submitted
+ if ( strlen($_FILES['file_upload']['tmp_name'][$i]) != 0 )
+ {
+ // upload the file and move it to temp directory
+ if ( move_uploaded_file($_FILES['file_upload']['tmp_name'][$i],$new_name))
+ {
+ $oid=$this->db->lo_import($new_name);
+ // check if the lob is in the database
+ if ( $oid == false )
+ {
+ $this->db->rollback();
+ return 1;
+ }
+ }
+ // the upload in the database is successfull
+ $this->d_lob=$oid;
+ $this->d_filename=$_FILES['file_upload']['name'][$i];
+ $this->d_mimetype=$_FILES['file_upload']['type'][$i];
- /*!\brief Get complete all the data member thx info from the database
- */
- function get()
- {
- $sql="select * from document where d_id=".$this->d_id;
- $ret=$this->db->exec_sql($sql);
- if ( Database::num_row($ret) == 0 )
- return;
- $row=Database::fetch_array($ret,0);
- $this->ag_id=$row['ag_id'];
- $this->d_mimetype=$row['d_mimetype'];
- $this->d_filename=$row['d_filename'];
- $this->d_lob=$row['d_lob'];
- $this->d_number=$row['d_number'];
+ // insert into the table
+ $sql="insert into document (ag_id, d_lob,d_filename,d_mimetype,d_number) values ($1,$2,$3,$4,5)";
+ $this->db->exec_sql($sql,array($p_ag_id,$this->d_lob,$this->d_filename,$this->d_mimetype));
+ }
+ } /* end for */
+ $this->db->commit();
}
-/*!
- * \brief replace the TAG by the real value, this value can be into
- * the database or in $_POST
- * The possible tags are
- * - [CUST_NAME] customer's name
- * - [CUST_ADDR_1] customer's address line 1
- * - [CUST_CP] customer's ZIP code
- * - [CUST_CO] customer's country
- * - [CUST_CITY] customer's city
- * - [CUST_VAT] customer's VAT
- * - [MARCH_NEXT] end this item and increment the counter $i
- * - [DATE_LIMIT]
- * - [VEN_ART_NAME]
- * - [VEN_ART_PRICE]
- * - [VEN_ART_QUANT]
- * - [VEN_ART_TVA_CODE]
- * - [VEN_ART_TVA_AMOUNT]
- * - [VEN_ART_STOCK_CODE]
- * - [VEN_HTVA]
- * - [VEN_TVAC]
- * - [VEN_TVA]
- * - [TOTAL_VEN_HTVA]
- * - [DATE]
- * - [NUMBER]
- * - [MY_NAME]
- * - [MY_CP]
- * - [MY_COMMUNE]
- * - [MY_TVA]
- * - [MY_STREET]
- * - [MY_NUMBER]
- * - [TVA_CODE]
- * - [TVA_RATE]
- * - [BON_COMMANDE]
- * - [OTHER_INFO]
- * - [CUST_NUM]
- * - [CUST_BANQUE_NAME]
- * - [CUST_BANQUE_NO]
- * - [USER]
- * - [REFERENCE]
- * - [BENEF_NAME]
- * - [BENEF_BANQUE_NAME]
- * - [BENEF_BANQUE_NO]
- * - [BENEF_ADDR_1]
- * - [BENEF_CP]
- * - [BENEF_CO]
- * - [BENEF_CITY]
- * - [BENEF_VAT]
- *
- * \param $p_tag TAG
- * \return String which must replace the tag
- */
- function Replace($p_tag)
+ /*! a_ref
+ * \brief create and compute a string for reference the doc
+ *
+ * \return a string
+ */
+ function a_ref()
{
- $p_tag=strtoupper($p_tag);
- $p_tag=str_replace('=','',$p_tag);
- $r="Tag inconnu";
- static $counter=0;
- switch ($p_tag)
- {
- case 'DATE':
- $r=' Date inconnue ';
- // Date are in $_REQUEST['ag_date']
- // or $_POST['e_date']
- if ( isset ($_REQUEST['ag_date']))
- $r=$_REQUEST['ag_date'];
- if ( isset ($_REQUEST['e_date']))
- $r=$_REQUEST['e_date'];
-
- break;
- //
- // the company priv
-
- case 'MY_NAME':
- $my=new own($this->db);
- $r=$my->MY_NAME;
- break;
- case 'MY_CP':
- $my=new own($this->db);
- $r=$my->MY_CP;
- break;
- case 'MY_COMMUNE':
- $my=new own($this->db);
- $r=$my->MY_COMMUNE;
- break;
- case 'MY_TVA':
- $my=new own($this->db);
- $r=$my->MY_TVA;
- break;
- case 'MY_STREET':
- $my=new own($this->db);
- $r=$my->MY_STREET;
- break;
- case 'MY_NUMBER':
- $my=new own($this->db);
- $r=$my->MY_NUMBER;
- break;
- case 'MY_TEL':
- $my=new own($this->db);
- $r=$my->MY_TEL;
- break;
- case 'MY_FAX':
- $my=new own($this->db);
- $r=$my->MY_FAX;
- break;
- case 'MY_PAYS':
- $my=new own($this->db);
- $r=$my->MY_PAYS;
- break;
-
- // customer
- /*\note The CUST_* are retrieved thx the $_REQUEST['tiers']
- * which contains the quick_code
- */
- case 'SOLDE':
- $tiers=new Fiche($this->db);
- $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
- $tiers->get_by_qcode($qcode,false);
- $p=$tiers->strAttribut(ATTR_DEF_ACCOUNT);
- $poste=new Acc_Account_Ledger($this->db,$p);
- $r=$poste->get_solde(' true' );
- break;
- case 'CUST_NAME':
- $tiers=new Fiche($this->db);
- $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_NAME);
- break;
- case 'CUST_ADDR_1':
- $tiers=new Fiche($this->db);
- $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_ADRESS);
-
- break ;
- case 'CUST_CP':
- $tiers=new Fiche($this->db);
-
- $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_CP);
-
- break;
- case 'CUST_CITY':
- $tiers=new Fiche($this->db);
-
- $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_CITY);
-
- break;
-
- case 'CUST_CO':
- $tiers=new Fiche($this->db);
-
- $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_PAYS);
-
- break;
- // Marchandise in $_POST['e_march*']
- // \see user_form_achat.php or user_form_ven.php
- case 'CUST_VAT':
- $tiers=new Fiche($this->db);
-
- $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_NUMTVA);
- break;
- case 'CUST_NUM':
- $tiers=new Fiche($this->db);
- $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER);
- break;
- case 'CUST_BANQUE_NO':
- $tiers=new Fiche($this->db);
- $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_BQ_NO);
- break;
- case 'CUST_BANQUE_NAME':
- $tiers=new Fiche($this->db);
- $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_BQ_NAME);
- break;
- /* -------------------------------------------------------------------------------- */
- /* BENEFIT (fee notes */
- case 'BENEF_NAME':
- $tiers=new Fiche($this->db);
- $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
- if ( $qcode=='') {$r='';break;}
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_NAME);
- break;
- case 'BENEF_ADDR_1':
- $tiers=new Fiche($this->db);
- $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
- if ( $qcode=='') {$r='';break;}
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_ADRESS);
-
- break ;
- case 'BENEF_CP':
- $tiers=new Fiche($this->db);
-
- $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
- if ( $qcode=='') {$r='';break;}
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_CP);
-
- break;
- case 'BENEF_CITY':
- $tiers=new Fiche($this->db);
-
- $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
- if ( $qcode=='') {$r='';break;}
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_CITY);
-
- break;
-
- case 'BENEF_CO':
- $tiers=new Fiche($this->db);
-
- $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
- if ( $qcode=='') {$r='';break;}
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_PAYS);
-
- break;
- // Marchandise in $_POST['e_march*']
- // \see user_form_achat.php or user_form_ven.php
- case 'BENEF_VAT':
- $tiers=new Fiche($this->db);
-
- $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
- if ( $qcode=='') {$r='';break;}
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_NUMTVA);
- break;
- case 'BENEF_NUM':
- $tiers=new Fiche($this->db);
- $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
- if ( $qcode=='') {$r='';break;}
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER);
- break;
- case 'BENEF_BANQUE_NO':
- $tiers=new Fiche($this->db);
- $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
- if ( $qcode=='') {$r='';break;}
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_BQ_NO);
- break;
- case 'BENEF_BANQUE_NAME':
- $tiers=new Fiche($this->db);
- $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
- if ( $qcode=='') {$r='';break;}
- $tiers->get_by_qcode($qcode,false);
- $r=$tiers->strAttribut(ATTR_DEF_BQ_NAME);
- break;
-
- // Marchandise in $_POST['e_march*']
- // \see user_form_achat.php or user_form_ven.php
- case 'NUMBER':
- $r=$this->d_number;
- break;
-
- case 'USER' :
- return $_SESSION['use_name'].', '.$_SESSION['use_first_name'];
-
- break;
- case 'REFERENCE':
- $act=new Action($this->db);
- $act->ag_id=$this->ag_id;
- $act->get();
- $r=$act->ag_ref;
- break;
-
- /*
- * - [VEN_ART_NAME]
- * - [VEN_ART_PRICE]
- * - [VEN_ART_QUANT]
- * - [VEN_ART_TVA_CODE]
- * - [VEN_ART_TVA_AMOUNT]
- * - [VEN_ART_STOCK_CODE]
- * - [VEN_HTVA]
- * - [VEN_TVAC]
- * - [VEN_TVA]
- * - [TOTAL_VEN_HTVA]
- * - [DATE_LIMIT]
- */
- case 'DATE_LIMIT':
- extract ($_POST);
- $id='e_ech' ;
- if ( !isset (${$id}) ) return "";
- $r=${$id};
- break;
-
- case 'MARCH_NEXT':
- $counter++;
- $r='';
- break;
-
- case 'VEN_ART_NAME':
- extract ($_POST);
- $id='e_march'.$counter;
- // check if the march exists
- if ( ! isset (${$id})) return "";
- // check that something is sold
- if ( ${'e_march'.$counter.'_price'} != 0 && ${'e_quant'.$counter} != 0 )
- {
- $f=new Fiche($this->db);
- $f->get_by_qcode(${$id},false);
- $r=$f->strAttribut(ATTR_DEF_NAME);
- } else $r = "";
- break;
-
- case 'VEN_ART_PRICE':
- extract ($_POST);
- $id='e_march'.$counter.'_price' ;
- if ( !isset (${$id}) ) return "";
- $r=${$id};
- break;
-
- case 'TVA_RATE':
- case 'VEN_ART_TVA_RATE':
- extract ($_POST);
- $id='e_march'.$counter.'_tva_id';
- if ( !isset (${$id}) ) return "";
- if ( ${$id} == -1 || ${$id}=='' ) return "";
- $march_id='e_march'.$counter.'_price' ;
- if ( ! isset (${$march_id})) return '';
- $tva=new Acc_Tva($this->db);
- $tva->set_parameter("id",${$id});
- if ( $tva->load() == -1) return '';
- return $tva->get_parameter("rate");
- break;
-
- case 'TVA_CODE':
- case 'VEN_ART_TVA_CODE':
- extract ($_POST);
- $id='e_march'.$counter.'_tva_id';
- if ( !isset (${$id}) ) return "";
- if ( ${$id} == -1 ) return "";
- $qt='e_quant'.$counter;
- $price='e_march'.$counter.'_price' ;
- if ( ${$price} == 0 || ${$qt} == 0
- || strlen(trim( $price )) ==0
- || strlen(trim($qt)) ==0)
- return "";
-
- $r=${$id};
- break;
-
- case 'TVA_LABEL':
- extract ($_POST);
- $id='e_march'.$counter.'_tva_id';
- if ( !isset (${$id}) ) return "";
- $march_id='e_march'.$counter.'_price' ;
- if ( ! isset (${$march_id})) return '';
- if ( ${$march_id} == 0) return '';
- $tva=new Acc_Tva($this->db,${$id});
- if ($tva->load() == -1 ) return "";
- $r=$tva->get_parameter('label');
-
- break;
-
- /* total VAT for one sold */
- case 'TVA_AMOUNT':
- extract ($_POST);
- $qt='e_quant'.$counter;
- $price='e_march'.$counter.'_price' ;
- $tva='e_march'.$counter.'_tva_id';
- /* if we do not use vat this var. is not set */
- if ( !isset(${$tva}) ) return '';
- if ( !isset (${'e_march'.$counter}) ) return "";
- // check that something is sold
- if ( ${$price} == 0 || ${$qt} == 0
- || strlen(trim( $price )) ==0
- || strlen(trim($qt)) ==0)
- return "";
- $r=${'e_march'.$counter.'_tva_amount'};
- break;
- /* TVA automatically computed */
- case 'VEN_ART_TVA':
- extract ($_POST);
- $qt='e_quant'.$counter;
- $price='e_march'.$counter.'_price' ;
- $tva='e_march'.$counter.'_tva_id';
- if ( !isset (${'e_march'.$counter}) ) return "";
- // check that something is sold
- if ( ${$price} == 0 || ${$qt} == 0
- || strlen(trim( $price )) ==0
- || strlen(trim($qt)) ==0)
- return "";
- $oTva=new Acc_Tva($this->db,${$tva});
- if ($oTva->load() == -1 ) return "";
- $r=round(${$price},2)*$oTva->get_parameter('rate');
- $r=round($r,2);
- break;
-
- case 'VEN_ART_TVAC':
- extract ($_POST);
- $qt='e_quant'.$counter;
- $price='e_march'.$counter.'_price' ;
- $tva='e_march'.$counter.'_tva_id';
- if ( !isset (${'e_march'.$counter}) ) return "";
- // check that something is sold
- if ( ${$price} == 0 || ${$qt} == 0
- || strlen(trim( $price )) ==0
- || strlen(trim($qt)) ==0)
- return "";
- if ( ! isset (${$tva}) ) return '';
- $tva=new Acc_Tva($this->db,${$tva});
- if ($tva->load() == -1 ) {
- $r=round(${$price},2);
- }else {
- $r=round(${$price}*$tva->get_parameter('rate')+${$price},2);
- }
-
- break;
-
- case 'VEN_ART_QUANT':
- extract ($_POST);
- $id='e_quant'.$counter;
- if ( !isset (${$id}) ) return "";
- // check that something is sold
- if ( ${'e_march'.$counter.'_price'} == 0
- || ${'e_quant'.$counter} == 0
- || strlen(trim( ${'e_march'.$counter.'_price'} )) ==0
- || strlen(trim(${'e_quant'.$counter})) ==0 )
- return "";
- $r=${$id};
- break;
-
- case 'VEN_HTVA':
- extract ($_POST);
- $id='e_march'.$counter.'_price' ;
- $quant='e_quant'.$counter;
- if ( !isset (${$id}) ) return "";
-
- // check that something is sold
- if ( ${'e_march'.$counter.'_price'} == 0 || ${'e_quant'.$counter} == 0
- || strlen(trim( ${'e_march'.$counter.'_price'} )) ==0
- || strlen(trim(${'e_quant'.$counter})) ==0)
- return "";
-
- $r=round(${$id}*${$quant},2);
- break;
-
- case 'VEN_TVAC':
- extract ($_POST);
- $id='e_march'.$counter.'_tva_amount' ;
- $price='e_march'.$counter.'_price' ;
- $quant='e_quant'.$counter;
- if ( ! isset(${'e_march'.$counter.'_price'})|| !isset(${'e_quant'.$counter}))
- return "";
- // check that something is sold
- if ( ${'e_march'.$counter.'_price'} == 0 || ${'e_quant'.$counter} == 0 )
- return "";
-
-
- // if it is exist
- if ( ! isset(${$id}))
- $r=round(${$price}*${$quant},2);
- else
- $r=round(${$price}*${$quant}+$id,2);
- break;
-
- case 'TOTAL_VEN_HTVA':
- extract($_POST);
-
- $sum=0.0;
- for ($i=0;$i<$nb_item;$i++)
- {
- $sell='e_march'.$i.'_price';
- $qt='e_quant'.$i;
-
- if ( ! isset (${$sell}) ) break;
-
- if ( strlen(trim(${$sell})) == 0 ||
- strlen(trim(${$qt})) == 0 ||
- ${$qt}==0 || ${$sell}==0)
- continue;
- $sum+=${$sell}*${$qt};
- $sum=round($sum,2);
-
-
- }
- $r=round($sum,2);
- break;
- case 'TOTAL_VEN_TVAC':
- extract($_POST);
- $sum=0.0;
- for ($i=0;$i<$nb_item;$i++)
- {
- $tva='e_march'.$i.'_tva_amount';
- $tva_amount=0;
- /* if we do not use vat this var. is not set */
- if ( isset(${$tva}) )
- {
- $tva_amount=${$tva};
- }
- $sell=${'e_march'.$i.'_price'};
- $qt=${'e_quant'.$i};
-
-
- $sum+=$sell*$qt+$tva_amount;
- $sum=round($sum,2);
- }
- $r=round($sum,2);
-
- break;
- case 'TOTAL_TVA':
- extract($_POST);
- $sum=0.0;
- for ($i=0;$i<$nb_item;$i++)
- {
- $tva='e_march'.$i.'_tva_amount';
- if (! isset(${$tva})) $tva_amount=0.0; else $tva_amount=${$tva};
- $sum+=$tva_amount;
- $sum=round($sum,2);
- }
- $r=$sum;
-
- break;
- case 'BON_COMMANDE':
- if ( isset($_REQUEST['bon_comm']))
- return $_REQUEST['bon_comm'];
- else
- return "";
- break;
- case 'PJ':
- if ( isset($_REQUEST['e_pj']))
- return $_REQUEST['e_pj'];
- else
- return "";
-
- case 'OTHER_INFO':
- if ( isset($_REQUEST['other_info']))
- return $_REQUEST['other_info'];
- else
- return "";
- break;
- case 'COMMENT':
- if ( isset($_REQUEST['e_comm']))
- return $_REQUEST['e_comm'];
- break;
- }
- return $r;
+ if ( $this->d_id == 0 )
+ return '';
+ $image=' ';
+ $r="";
+ $r=' '.$image.' ';
+ return $r;
}
- /*!\brief remove a row from the table document, the lob object is not deleted
- * because can be linked elsewhere
- */
- function remove()
+ /* ! Get
+ * \brief Send the document
+ */
+ function Send()
{
- $sql='delete from document where d_id='.$this->d_id;
- $this->db->exec_sql($sql);
- if ($this->d_lob != 0 )
- $this->db->lo_unlink($this->d_lob);
+ // retrieve the template and generate document
+ $this->db->start();
+ $ret=$this->db->exec_sql(
+ "select d_id,d_lob,d_filename,d_mimetype from document where d_id=".$this->d_id );
+ if ( Database::num_row ($ret) == 0 )
+ return;
+ $row=Database::fetch_array($ret,0);
+ //the document is saved into file $tmp
+ $tmp=tempnam($_ENV['TMP'],'document_');
+ $this->db->lo_export($row['d_lob'],$tmp);
+ $this->d_mimetype=$row['d_mimetype'];
+ $this->d_filename=$row['d_filename'];
+
+ // send it to stdout
+ ini_set('zlib.output_compression','Off');
+ header("Pragma: public");
+ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+ header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
+ header("Cache-Control: must-revalidate");
+ header('Content-type: '.$this->d_mimetype);
+ header('Content-Disposition: attachment;filename="'.$this->d_filename.'"',FALSE);
+ header("Accept-Ranges: bytes");
+ $file=fopen($tmp,'r');
+ while ( !feof ($file) )
+ {
+ echo fread($file,8192);
+ }
+ fclose($file);
+
+ unlink ($tmp);
+
+ $this->db->commit();
+
}
- /*!\brief Move a document from the table document into the concerned row
- * the document is not copied : it is only a link
- *
- * \param $p_internal internal code
- *
- */
- function MoveDocumentPj($p_internal)
+ /*!\brief get all the document of a given action
+ *\param $ag_id the ag_id from action::ag_id (primary key)
+ *\return an array of objects document or an empty array if nothing found
+ */
+ function get_all($ag_id)
{
- $sql="update jrn set jr_pj=$1,jr_pj_name=$2,jr_pj_type=$3 where jr_internal=$4";
-
- $this->db->exec_sql($sql,array($this->d_lob,$this->d_filename,$this->d_mimetype,$p_internal));
- // clean the table document
- $sql='delete from document where d_id='.$this->d_id;
- $this->db->exec_sql($sql);
+ $res=$this->db->get_array('select d_id, ag_id, d_lob, d_number, d_filename,'.
+ ' d_mimetype from document where ag_id=$1',array($ag_id));
+ $a=array();
+ for ($i=0;$idb);
+ $doc->d_id=$res[$i]['d_id'];
+ $doc->ag_id=$res[$i]['ag_id'];
+ $doc->d_lob=$res[$i]['d_lob'];
+ $doc->d_number=$res[$i]['d_number'];
+ $doc->d_filename=$res[$i]['d_filename'];
+ $doc->d_mimetype=$res[$i]['d_mimetype'];
+ $a[$i]=clone $doc;
+ }
+ return $a;
+ }
+
+ /*!\brief Get complete all the data member thx info from the database
+ */
+ function get()
+ {
+ $sql="select * from document where d_id=".$this->d_id;
+ $ret=$this->db->exec_sql($sql);
+ if ( Database::num_row($ret) == 0 )
+ return;
+ $row=Database::fetch_array($ret,0);
+ $this->ag_id=$row['ag_id'];
+ $this->d_mimetype=$row['d_mimetype'];
+ $this->d_filename=$row['d_filename'];
+ $this->d_lob=$row['d_lob'];
+ $this->d_number=$row['d_number'];
+
+ }
+ /*!
+ * \brief replace the TAG by the real value, this value can be into
+ * the database or in $_POST
+ * The possible tags are
+ * - [CUST_NAME] customer's name
+ * - [CUST_ADDR_1] customer's address line 1
+ * - [CUST_CP] customer's ZIP code
+ * - [CUST_CO] customer's country
+ * - [CUST_CITY] customer's city
+ * - [CUST_VAT] customer's VAT
+ * - [MARCH_NEXT] end this item and increment the counter $i
+ * - [DATE_LIMIT]
+ * - [VEN_ART_NAME]
+ * - [VEN_ART_PRICE]
+ * - [VEN_ART_QUANT]
+ * - [VEN_ART_TVA_CODE]
+ * - [VEN_ART_TVA_AMOUNT]
+ * - [VEN_ART_STOCK_CODE]
+ * - [VEN_HTVA]
+ * - [VEN_TVAC]
+ * - [VEN_TVA]
+ * - [TOTAL_VEN_HTVA]
+ * - [DATE]
+ * - [NUMBER]
+ * - [MY_NAME]
+ * - [MY_CP]
+ * - [MY_COMMUNE]
+ * - [MY_TVA]
+ * - [MY_STREET]
+ * - [MY_NUMBER]
+ * - [TVA_CODE]
+ * - [TVA_RATE]
+ * - [BON_COMMANDE]
+ * - [OTHER_INFO]
+ * - [CUST_NUM]
+ * - [CUST_BANQUE_NAME]
+ * - [CUST_BANQUE_NO]
+ * - [USER]
+ * - [REFERENCE]
+ * - [BENEF_NAME]
+ * - [BENEF_BANQUE_NAME]
+ * - [BENEF_BANQUE_NO]
+ * - [BENEF_ADDR_1]
+ * - [BENEF_CP]
+ * - [BENEF_CO]
+ * - [BENEF_CITY]
+ * - [BENEF_VAT]
+ *
+ * \param $p_tag TAG
+ * \return String which must replace the tag
+ */
+ function Replace($p_tag)
+ {
+ $p_tag=strtoupper($p_tag);
+ $p_tag=str_replace('=','',$p_tag);
+ $r="Tag inconnu";
+ static $counter=0;
+ switch ($p_tag)
+ {
+ case 'DATE':
+ $r=' Date inconnue ';
+ // Date are in $_REQUEST['ag_date']
+ // or $_POST['e_date']
+ if ( isset ($_REQUEST['ag_date']))
+ $r=$_REQUEST['ag_date'];
+ if ( isset ($_REQUEST['e_date']))
+ $r=$_REQUEST['e_date'];
+
+ break;
+ //
+ // the company priv
+
+ case 'MY_NAME':
+ $my=new own($this->db);
+ $r=$my->MY_NAME;
+ break;
+ case 'MY_CP':
+ $my=new own($this->db);
+ $r=$my->MY_CP;
+ break;
+ case 'MY_COMMUNE':
+ $my=new own($this->db);
+ $r=$my->MY_COMMUNE;
+ break;
+ case 'MY_TVA':
+ $my=new own($this->db);
+ $r=$my->MY_TVA;
+ break;
+ case 'MY_STREET':
+ $my=new own($this->db);
+ $r=$my->MY_STREET;
+ break;
+ case 'MY_NUMBER':
+ $my=new own($this->db);
+ $r=$my->MY_NUMBER;
+ break;
+ case 'MY_TEL':
+ $my=new own($this->db);
+ $r=$my->MY_TEL;
+ break;
+ case 'MY_FAX':
+ $my=new own($this->db);
+ $r=$my->MY_FAX;
+ break;
+ case 'MY_PAYS':
+ $my=new own($this->db);
+ $r=$my->MY_PAYS;
+ break;
+
+ // customer
+ /*\note The CUST_* are retrieved thx the $_REQUEST['tiers']
+ * which contains the quick_code
+ */
+ case 'SOLDE':
+ $tiers=new Fiche($this->db);
+ $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
+ $tiers->get_by_qcode($qcode,false);
+ $p=$tiers->strAttribut(ATTR_DEF_ACCOUNT);
+ $poste=new Acc_Account_Ledger($this->db,$p);
+ $r=$poste->get_solde(' true' );
+ break;
+ case 'CUST_NAME':
+ $tiers=new Fiche($this->db);
+ $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_NAME);
+ break;
+ case 'CUST_ADDR_1':
+ $tiers=new Fiche($this->db);
+ $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_ADRESS);
+
+ break ;
+ case 'CUST_CP':
+ $tiers=new Fiche($this->db);
+
+ $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_CP);
+
+ break;
+ case 'CUST_CITY':
+ $tiers=new Fiche($this->db);
+
+ $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_CITY);
+
+ break;
+
+ case 'CUST_CO':
+ $tiers=new Fiche($this->db);
+
+ $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_PAYS);
+
+ break;
+ // Marchandise in $_POST['e_march*']
+ // \see user_form_achat.php or user_form_ven.php
+ case 'CUST_VAT':
+ $tiers=new Fiche($this->db);
+
+ $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_NUMTVA);
+ break;
+ case 'CUST_NUM':
+ $tiers=new Fiche($this->db);
+ $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER);
+ break;
+ case 'CUST_BANQUE_NO':
+ $tiers=new Fiche($this->db);
+ $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_BQ_NO);
+ break;
+ case 'CUST_BANQUE_NAME':
+ $tiers=new Fiche($this->db);
+ $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_BQ_NAME);
+ break;
+ /* -------------------------------------------------------------------------------- */
+ /* BENEFIT (fee notes */
+ case 'BENEF_NAME':
+ $tiers=new Fiche($this->db);
+ $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
+ if ( $qcode=='')
+ {
+ $r='';
+ break;
+ }
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_NAME);
+ break;
+ case 'BENEF_ADDR_1':
+ $tiers=new Fiche($this->db);
+ $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
+ if ( $qcode=='')
+ {
+ $r='';
+ break;
+ }
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_ADRESS);
+
+ break ;
+ case 'BENEF_CP':
+ $tiers=new Fiche($this->db);
+
+ $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
+ if ( $qcode=='')
+ {
+ $r='';
+ break;
+ }
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_CP);
+
+ break;
+ case 'BENEF_CITY':
+ $tiers=new Fiche($this->db);
+
+ $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
+ if ( $qcode=='')
+ {
+ $r='';
+ break;
+ }
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_CITY);
+
+ break;
+
+ case 'BENEF_CO':
+ $tiers=new Fiche($this->db);
+
+ $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
+ if ( $qcode=='')
+ {
+ $r='';
+ break;
+ }
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_PAYS);
+
+ break;
+ // Marchandise in $_POST['e_march*']
+ // \see user_form_achat.php or user_form_ven.php
+ case 'BENEF_VAT':
+ $tiers=new Fiche($this->db);
+
+ $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
+ if ( $qcode=='')
+ {
+ $r='';
+ break;
+ }
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_NUMTVA);
+ break;
+ case 'BENEF_NUM':
+ $tiers=new Fiche($this->db);
+ $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
+ if ( $qcode=='')
+ {
+ $r='';
+ break;
+ }
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER);
+ break;
+ case 'BENEF_BANQUE_NO':
+ $tiers=new Fiche($this->db);
+ $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
+ if ( $qcode=='')
+ {
+ $r='';
+ break;
+ }
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_BQ_NO);
+ break;
+ case 'BENEF_BANQUE_NAME':
+ $tiers=new Fiche($this->db);
+ $qcode=isset($_REQUEST['qcode_benef'])?$_REQUEST['qcode_benef']:'';
+ if ( $qcode=='')
+ {
+ $r='';
+ break;
+ }
+ $tiers->get_by_qcode($qcode,false);
+ $r=$tiers->strAttribut(ATTR_DEF_BQ_NAME);
+ break;
+
+ // Marchandise in $_POST['e_march*']
+ // \see user_form_achat.php or user_form_ven.php
+ case 'NUMBER':
+ $r=$this->d_number;
+ break;
+
+ case 'USER' :
+ return $_SESSION['use_name'].', '.$_SESSION['use_first_name'];
+
+ break;
+ case 'REFERENCE':
+ $act=new Action($this->db);
+ $act->ag_id=$this->ag_id;
+ $act->get();
+ $r=$act->ag_ref;
+ break;
+
+ /*
+ * - [VEN_ART_NAME]
+ * - [VEN_ART_PRICE]
+ * - [VEN_ART_QUANT]
+ * - [VEN_ART_TVA_CODE]
+ * - [VEN_ART_TVA_AMOUNT]
+ * - [VEN_ART_STOCK_CODE]
+ * - [VEN_HTVA]
+ * - [VEN_TVAC]
+ * - [VEN_TVA]
+ * - [TOTAL_VEN_HTVA]
+ * - [DATE_LIMIT]
+ */
+ case 'DATE_LIMIT':
+ extract ($_POST);
+ $id='e_ech' ;
+ if ( !isset (${$id}) ) return "";
+ $r=${$id};
+ break;
+
+ case 'MARCH_NEXT':
+ $counter++;
+ $r='';
+ break;
+
+ case 'VEN_ART_NAME':
+ extract ($_POST);
+ $id='e_march'.$counter;
+ // check if the march exists
+ if ( ! isset (${$id})) return "";
+ // check that something is sold
+ if ( ${'e_march'.$counter.'_price'} != 0 && ${'e_quant'.$counter} != 0 )
+ {
+ $f=new Fiche($this->db);
+ $f->get_by_qcode(${$id},false);
+ $r=$f->strAttribut(ATTR_DEF_NAME);
+ }
+ else $r = "";
+ break;
+
+ case 'VEN_ART_PRICE':
+ extract ($_POST);
+ $id='e_march'.$counter.'_price' ;
+ if ( !isset (${$id}) ) return "";
+ $r=${$id};
+ break;
+
+ case 'TVA_RATE':
+ case 'VEN_ART_TVA_RATE':
+ extract ($_POST);
+ $id='e_march'.$counter.'_tva_id';
+ if ( !isset (${$id}) ) return "";
+ if ( ${$id} == -1 || ${$id}=='' ) return "";
+ $march_id='e_march'.$counter.'_price' ;
+ if ( ! isset (${$march_id})) return '';
+ $tva=new Acc_Tva($this->db);
+ $tva->set_parameter("id",${$id});
+ if ( $tva->load() == -1) return '';
+ return $tva->get_parameter("rate");
+ break;
+
+ case 'TVA_CODE':
+ case 'VEN_ART_TVA_CODE':
+ extract ($_POST);
+ $id='e_march'.$counter.'_tva_id';
+ if ( !isset (${$id}) ) return "";
+ if ( ${$id} == -1 ) return "";
+ $qt='e_quant'.$counter;
+ $price='e_march'.$counter.'_price' ;
+ if ( ${$price} == 0 || ${$qt} == 0
+ || strlen(trim( $price )) ==0
+ || strlen(trim($qt)) ==0)
+ return "";
+
+ $r=${$id};
+ break;
+
+ case 'TVA_LABEL':
+ extract ($_POST);
+ $id='e_march'.$counter.'_tva_id';
+ if ( !isset (${$id}) ) return "";
+ $march_id='e_march'.$counter.'_price' ;
+ if ( ! isset (${$march_id})) return '';
+ if ( ${$march_id} == 0) return '';
+ $tva=new Acc_Tva($this->db,${$id});
+ if ($tva->load() == -1 ) return "";
+ $r=$tva->get_parameter('label');
+
+ break;
+
+ /* total VAT for one sold */
+ case 'TVA_AMOUNT':
+ extract ($_POST);
+ $qt='e_quant'.$counter;
+ $price='e_march'.$counter.'_price' ;
+ $tva='e_march'.$counter.'_tva_id';
+ /* if we do not use vat this var. is not set */
+ if ( !isset(${$tva}) ) return '';
+ if ( !isset (${'e_march'.$counter}) ) return "";
+ // check that something is sold
+ if ( ${$price} == 0 || ${$qt} == 0
+ || strlen(trim( $price )) ==0
+ || strlen(trim($qt)) ==0)
+ return "";
+ $r=${'e_march'.$counter.'_tva_amount'};
+ break;
+ /* TVA automatically computed */
+ case 'VEN_ART_TVA':
+ extract ($_POST);
+ $qt='e_quant'.$counter;
+ $price='e_march'.$counter.'_price' ;
+ $tva='e_march'.$counter.'_tva_id';
+ if ( !isset (${'e_march'.$counter}) ) return "";
+ // check that something is sold
+ if ( ${$price} == 0 || ${$qt} == 0
+ || strlen(trim( $price )) ==0
+ || strlen(trim($qt)) ==0)
+ return "";
+ $oTva=new Acc_Tva($this->db,${$tva});
+ if ($oTva->load() == -1 ) return "";
+ $r=round(${$price},2)*$oTva->get_parameter('rate');
+ $r=round($r,2);
+ break;
+
+ case 'VEN_ART_TVAC':
+ extract ($_POST);
+ $qt='e_quant'.$counter;
+ $price='e_march'.$counter.'_price' ;
+ $tva='e_march'.$counter.'_tva_id';
+ if ( !isset (${'e_march'.$counter}) ) return "";
+ // check that something is sold
+ if ( ${$price} == 0 || ${$qt} == 0
+ || strlen(trim( $price )) ==0
+ || strlen(trim($qt)) ==0)
+ return "";
+ if ( ! isset (${$tva}) ) return '';
+ $tva=new Acc_Tva($this->db,${$tva});
+ if ($tva->load() == -1 )
+ {
+ $r=round(${$price},2);
+ }
+ else
+ {
+ $r=round(${$price}*$tva->get_parameter('rate')+${$price},2);
+ }
+
+ break;
+
+ case 'VEN_ART_QUANT':
+ extract ($_POST);
+ $id='e_quant'.$counter;
+ if ( !isset (${$id}) ) return "";
+ // check that something is sold
+ if ( ${'e_march'.$counter.'_price'} == 0
+ || ${'e_quant'.$counter} == 0
+ || strlen(trim( ${'e_march'.$counter.'_price'} )) ==0
+ || strlen(trim(${'e_quant'.$counter})) ==0 )
+ return "";
+ $r=${$id};
+ break;
+
+ case 'VEN_HTVA':
+ extract ($_POST);
+ $id='e_march'.$counter.'_price' ;
+ $quant='e_quant'.$counter;
+ if ( !isset (${$id}) ) return "";
+
+ // check that something is sold
+ if ( ${'e_march'.$counter.'_price'} == 0 || ${'e_quant'.$counter} == 0
+ || strlen(trim( ${'e_march'.$counter.'_price'} )) ==0
+ || strlen(trim(${'e_quant'.$counter})) ==0)
+ return "";
+
+ $r=round(${$id}*${$quant},2);
+ break;
+
+ case 'VEN_TVAC':
+ extract ($_POST);
+ $id='e_march'.$counter.'_tva_amount' ;
+ $price='e_march'.$counter.'_price' ;
+ $quant='e_quant'.$counter;
+ if ( ! isset(${'e_march'.$counter.'_price'})|| !isset(${'e_quant'.$counter}))
+ return "";
+ // check that something is sold
+ if ( ${'e_march'.$counter.'_price'} == 0 || ${'e_quant'.$counter} == 0 )
+ return "";
+
+
+ // if it is exist
+ if ( ! isset(${$id}))
+ $r=round(${$price}*${$quant},2);
+ else
+ $r=round($
+ {
+ $price
+ }
+ *${$quant}+$id,2);
+ break;
+
+ case 'TOTAL_VEN_HTVA':
+ extract($_POST);
+
+ $sum=0.0;
+ for ($i=0;$i<$nb_item;$i++)
+ {
+ $sell='e_march'.$i.'_price';
+ $qt='e_quant'.$i;
+
+ if ( ! isset (${$sell}) ) break;
+
+ if ( strlen(trim(${$sell})) == 0 ||
+ strlen(trim(${$qt})) == 0 ||
+ ${$qt}==0 || ${$sell}==0)
+ continue;
+ $sum+=${$sell}*${$qt};
+ $sum=round($sum,2);
+
+
+ }
+ $r=round($sum,2);
+ break;
+ case 'TOTAL_VEN_TVAC':
+ extract($_POST);
+ $sum=0.0;
+ for ($i=0;$i<$nb_item;$i++)
+ {
+ $tva='e_march'.$i.'_tva_amount';
+ $tva_amount=0;
+ /* if we do not use vat this var. is not set */
+ if ( isset(${$tva}) )
+ {
+ $tva_amount=${$tva};
+ }
+ $sell=${'e_march'.$i.'_price'};
+ $qt=${'e_quant'.$i};
+
+
+ $sum+=$sell*$qt+$tva_amount;
+ $sum=round($sum,2);
+ }
+ $r=round($sum,2);
+
+ break;
+ case 'TOTAL_TVA':
+ extract($_POST);
+ $sum=0.0;
+ for ($i=0;$i<$nb_item;$i++)
+ {
+ $tva='e_march'.$i.'_tva_amount';
+ if (! isset(${$tva})) $tva_amount=0.0;
+ else $tva_amount=$
+ {
+ $tva
+ };
+ $sum+=$tva_amount;
+ $sum=round($sum,2);
+ }
+ $r=$sum;
+
+ break;
+ case 'BON_COMMANDE':
+ if ( isset($_REQUEST['bon_comm']))
+ return $_REQUEST['bon_comm'];
+ else
+ return "";
+ break;
+ case 'PJ':
+ if ( isset($_REQUEST['e_pj']))
+ return $_REQUEST['e_pj'];
+ else
+ return "";
+
+ case 'OTHER_INFO':
+ if ( isset($_REQUEST['other_info']))
+ return $_REQUEST['other_info'];
+ else
+ return "";
+ break;
+ case 'COMMENT':
+ if ( isset($_REQUEST['e_comm']))
+ return $_REQUEST['e_comm'];
+ break;
+ }
+ return $r;
+ }
+ /*!\brief remove a row from the table document, the lob object is not deleted
+ * because can be linked elsewhere
+ */
+ function remove()
+ {
+ $sql='delete from document where d_id='.$this->d_id;
+ $this->db->exec_sql($sql);
+ if ($this->d_lob != 0 )
+ $this->db->lo_unlink($this->d_lob);
+ }
+ /*!\brief Move a document from the table document into the concerned row
+ * the document is not copied : it is only a link
+ *
+ * \param $p_internal internal code
+ *
+ */
+ function MoveDocumentPj($p_internal)
+ {
+ $sql="update jrn set jr_pj=$1,jr_pj_name=$2,jr_pj_type=$3 where jr_internal=$4";
+
+ $this->db->exec_sql($sql,array($this->d_lob,$this->d_filename,$this->d_mimetype,$p_internal));
+ // clean the table document
+ $sql='delete from document where d_id='.$this->d_id;
+ $this->db->exec_sql($sql);
}
diff --git a/include/class_document_modele.php b/include/class_document_modele.php
index 23d2ddff9..945cfb5ab 100644
--- a/include/class_document_modele.php
+++ b/include/class_document_modele.php
@@ -1,4 +1,4 @@
-cn=$p_cn;
- $this->md_id=$p_id;
- }
-
- /*!
- **************************************************
- * \brief : show all the stored document_modele.
- * return a string containing all the data
- * separate by TD & TR tag
- * \return table in HTML Code
- */
- function myList() {
- $s=dossier::get();
- $sql="select md_id,md_name,md_affect,dt_value from document_modele join document_type on(dt_id=md_type)";
- $Res=$this->cn->exec_sql($sql);
- $all=Database::fetch_all($Res);
- if ( Database::num_row($Res) == 0 ) return "";
- $r='
';
- $r.=dossier::hidden();
- $r.="";
- $r.=" ";
- $r.=th(_('Nom'));
- $r.=th(_('Catégorie'));
- $r.=th(_('Affect.'));
- $r.=th(_('Fichier'));
- $r.=th(_('Effacer'));
- $r.=" ";
- foreach ( $all as $row) {
- $r.="";
- $r.="";
- $r.=h($row['md_name']);
- $r.=" ";
- $r.="";
- $r.=$row['dt_value'];
- $r.=" ";
- $r.=td(h($row['md_affect']));
- $r.="";
- $r.='Document ';
- $r.=" ";
- $r.="";
- $c=new ICheckBox();
- $c->name="dm_remove_".$row['md_id'];
- $r.=$c->input();
- $r.=" ";
- $r.=" ";
- }
- $r.="
";
-
- // need hidden parameter for subaction
- $a=new IHidden();
- $a->name="sa";
- $a->value="rm_template";
- $r.=$a->input();
- $r.=HtmlInput::submit("rm_template","Effacer la sélection");
- $r.=" ";
- return $r;
- }
- /*!
- **************************************************
- * \brief : Save a document_modele in the database,
- * if the document_modele doesn't exist yet it will be
- * first created (-> insert into document_modele)
- * in that case the name and the type must be set
- * set before calling Save, the name will be modified
- * with FormatString
- *
- */
- function Save()
+class Document_modele
+{
+ var $cn; /*!< $cn database connection */
+ var $md_id; /*!< $md_id pk */
+ var $md_name; /*!< $md_name template's name */
+ var $md_type; /*!< $md_type template's type (letter, invoice, order...) */
+ var $md_lob; /*!< $md_lob Document file */
+ var $md_sequence; /*!< $md_sequence sequence name (autogenerate) */
+ var $sequence; /*!< $sequence sequence number used by the create sequence start with */
+ var $md_affect; /*!< $md_affect if you can use it in VEN for sale, ACH for purchase or GES for follow-up */
+ //Constructor parameter = database connexion
+ function Document_modele($p_cn,$p_id=-1)
{
- // if name is empty return immediately
- if ( trim(strlen($this->md_name))==0)
- return;
- try
- {
- // Start transaction
- $this->cn->start();
- // Save data into the table document_modele
- // if $this->md_id == -1 it means it is a new document model
- // so first we have to insert it
- // the name and the type must be set before calling save
- if ( $this->md_id == -1)
- {
-
- // insert into the table document_modele
- $this->md_id=$this->cn->get_next_seq('document_modele_md_id_seq');
- $sql="insert into document_modele(md_id,md_name,md_type,md_affect)
- values ($1,$2,$3,$4)";
-
- $Ret=$this->cn->exec_sql($sql,array($this->md_id,$this->md_name,$this->md_type,$this->md_affect));
- // create the sequence for this modele of document
- $this->md_sequence="document_".$this->cn->get_next_seq("document_seq");
- // if start is not equal to 0 and he's a number than the user
- // request a number change
-
- if ( $this->start != 0 && isNumber($this->start) == 1 )
- {
- $sql="alter sequence seq_doc_type_".$this->md_type." restart ".$this->start;
- $this->cn->exec_sql($sql);
- }
-
- }
- // Save the file
- $new_name=tempnam($_ENV['TMP'],'document_');
- if ( strlen ($_FILES['doc']['tmp_name']) != 0 )
- {
- if (move_uploaded_file($_FILES['doc']['tmp_name'],
- $new_name))
- {
- // echo "Image saved";
- $oid= $this->cn->lo_import($new_name);
- if ( $oid == false )
- {
- echo_error('class_document_modele.php',__LINE__,"cannot upload document");
- $this->cn->rollback();
- return;
- }
- // Remove old document
- $ret=$this->cn->exec_sql("select md_lob from document_modele where md_id=".$this->md_id);
- if (Database::num_row($ret) != 0)
- {
- $r=Database::fetch_array($ret,0);
- $old_oid=$r['md_lob'];
- if (strlen($old_oid) != 0)
- $this->cn->lo_unlink($old_oid);
- }
- // Load new document
- $this->cn->exec_sql("update document_modele set md_lob=".$oid.", md_mimetype='".$_FILES['doc']['type']."' ,md_filename='".$_FILES['doc']['name']."' where md_id=".$this->md_id);
- $this->cn->commit();
- }
- else
- {
- echo "Error ";
- $this->cn->rollback();
- exit;
- }
- }
- }
- catch (Exception $e)
- {
- rollback($this->cn);
- return ;
- }
+ $this->cn=$p_cn;
+ $this->md_id=$p_id;
}
- /*!
- * \brief Remove a template
- * \return nothing
- */
- function Delete()
+
+ /*!
+ **************************************************
+ * \brief : show all the stored document_modele.
+ * return a string containing all the data
+ * separate by TD & TR tag
+ * \return table in HTML Code
+ */
+ function myList()
{
- $this->cn->start();
- // first we unlink the document
- $sql="select md_lob from document_modele where md_id=".$this->md_id;
- $res=$this->cn->exec_sql($sql);
- $r=Database::fetch_array($res,0);
- // if a lob is found
- if ( strlen ($r['md_lob']) &&
- $this->cn->exist_blob($r['md_lob']) )
- {
- // we remove it first
- $this->cn->lo_unlink($r['md_lob']);
- }
- // now we can delete the row
- $sql="delete from document_modele where md_id =".$this->md_id;
- $sql=$this->cn->exec_sql($sql);
- $this->cn->commit();
+ $s=dossier::get();
+ $sql="select md_id,md_name,md_affect,dt_value from document_modele join document_type on(dt_id=md_type)";
+ $Res=$this->cn->exec_sql($sql);
+ $all=Database::fetch_all($Res);
+ if ( Database::num_row($Res) == 0 ) return "";
+ $r='
';
+ $r.=dossier::hidden();
+ $r.="";
+ $r.=" ";
+ $r.=th(_('Nom'));
+ $r.=th(_('Catégorie'));
+ $r.=th(_('Affect.'));
+ $r.=th(_('Fichier'));
+ $r.=th(_('Effacer'));
+ $r.=" ";
+ foreach ( $all as $row)
+ {
+ $r.="";
+ $r.="";
+ $r.=h($row['md_name']);
+ $r.=" ";
+ $r.="";
+ $r.=$row['dt_value'];
+ $r.=" ";
+ $r.=td(h($row['md_affect']));
+ $r.="";
+ $r.='Document ';
+ $r.=" ";
+ $r.="";
+ $c=new ICheckBox();
+ $c->name="dm_remove_".$row['md_id'];
+ $r.=$c->input();
+ $r.=" ";
+ $r.=" ";
+ }
+ $r.="
";
+
+ // need hidden parameter for subaction
+ $a=new IHidden();
+ $a->name="sa";
+ $a->value="rm_template";
+ $r.=$a->input();
+ $r.=HtmlInput::submit("rm_template","Effacer la sélection");
+ $r.=" ";
+ return $r;
}
-
- /*!
- * \brief show the form for loading a template
- * \param p_action for the field action = destination url
- *
- *
- * \return string containing the forms
- */
- function form($p_action)
+ /*!
+ **************************************************
+ * \brief : Save a document_modele in the database,
+ * if the document_modele doesn't exist yet it will be
+ * first created (-> insert into document_modele)
+ * in that case the name and the type must be set
+ * set before calling Save, the name will be modified
+ * with FormatString
+ *
+ */
+ function Save()
{
- $r='';
- $r.='Veuillez introduire les modèles servant à générer vos documents';
- $r.='
';
- $r.='';
- $r.=dossier::hidden();
- // we need to add the sub action as hidden
- $h=new IHidden();
- $h->name="sa";
- $h->value="add_document";
+ // if name is empty return immediately
+ if ( trim(strlen($this->md_name))==0)
+ return;
+ try
+ {
+ // Start transaction
+ $this->cn->start();
+ // Save data into the table document_modele
+ // if $this->md_id == -1 it means it is a new document model
+ // so first we have to insert it
+ // the name and the type must be set before calling save
+ if ( $this->md_id == -1)
+ {
- $r.=$h->input();
+ // insert into the table document_modele
+ $this->md_id=$this->cn->get_next_seq('document_modele_md_id_seq');
+ $sql="insert into document_modele(md_id,md_name,md_type,md_affect)
+ values ($1,$2,$3,$4)";
- $r.='';
- $t=new IText();
- $t->name="md_name";
- $r.=" Nom ".$t->input()." ";
+ $Ret=$this->cn->exec_sql($sql,array($this->md_id,$this->md_name,$this->md_type,$this->md_affect));
+ // create the sequence for this modele of document
+ $this->md_sequence="document_".$this->cn->get_next_seq("document_seq");
+ // if start is not equal to 0 and he's a number than the user
+ // request a number change
- $r.=" ";
- $r.="Catégorie de document ";
- $w=new ISelect();
- $w->name="md_type";
+ if ( $this->start != 0 && isNumber($this->start) == 1 )
+ {
+ $sql="alter sequence seq_doc_type_".$this->md_type." restart ".$this->start;
+ $this->cn->exec_sql($sql);
+ }
- $w->value=$this->cn->make_array('select dt_id,dt_value from document_type');
- $r.="".$w->input()." ";
-
- $r.='';
- $r.=td(_('Affectation'));
- $waffect=new ISelect();
- $waffect->name='md_affect';
- $waffect->value=array(
- array('value'=>'ACH','label'=>_('Uniquement journaux achat')),
- array('value'=>'VEN','label'=>_('Uniquement journaux vente')),
- array('value'=>'GES','label'=>_('Partie gestion'))
- );
-
- $r.=td($waffect->input());
- $r.=' ';
-
- $f=new IFile();
- $f->name="doc";
- $r.="fichier ".$f->input()." ";
-
- $start=new IText();
- $start->name="start_seq";
- $start->size=9;
- $start->value="0";
-
- $r.=" Numerotation commence a ".$start->input()." ";
- $r.='Si vous laissez à 0, la numérotation ne changera pas, la prochaine facture sera n+1, n étant le n° que vous avez donné ';
- $r.=" ";
- $r.='
';
- $r.=HtmlInput::submit('add_document','Ajout');
- $r.=" ";
- return $r;
+ }
+ // Save the file
+ $new_name=tempnam($_ENV['TMP'],'document_');
+ if ( strlen ($_FILES['doc']['tmp_name']) != 0 )
+ {
+ if (move_uploaded_file($_FILES['doc']['tmp_name'],
+ $new_name))
+ {
+ // echo "Image saved";
+ $oid= $this->cn->lo_import($new_name);
+ if ( $oid == false )
+ {
+ echo_error('class_document_modele.php',__LINE__,"cannot upload document");
+ $this->cn->rollback();
+ return;
+ }
+ // Remove old document
+ $ret=$this->cn->exec_sql("select md_lob from document_modele where md_id=".$this->md_id);
+ if (Database::num_row($ret) != 0)
+ {
+ $r=Database::fetch_array($ret,0);
+ $old_oid=$r['md_lob'];
+ if (strlen($old_oid) != 0)
+ $this->cn->lo_unlink($old_oid);
+ }
+ // Load new document
+ $this->cn->exec_sql("update document_modele set md_lob=".$oid.", md_mimetype='".$_FILES['doc']['type']."' ,md_filename='".$_FILES['doc']['name']."' where md_id=".$this->md_id);
+ $this->cn->commit();
+ }
+ else
+ {
+ echo "Error ";
+ $this->cn->rollback();
+ exit;
+ }
+ }
+ }
+ catch (Exception $e)
+ {
+ rollback($this->cn);
+ return ;
+ }
}
- /*!\brief load the value of a document_modele,the ag_id variable must be set
- */
- function load() {
- $array=$this->cn->get_array("SELECT md_id, md_name, md_lob, md_type, md_filename, md_mimetype,md_affect".
- " FROM document_modele where md_id=$1",array($this->md_id));
- if ( count($array) == 0 ) return null;
- foreach ( array('md_name', 'md_lob','md_type', 'md_filename', 'md_mimetype','md_affect') as $idx) {
- $this->$idx=$array[0][$idx];
+ /*!
+ * \brief Remove a template
+ * \return nothing
+ */
+ function Delete()
+ {
+ $this->cn->start();
+ // first we unlink the document
+ $sql="select md_lob from document_modele where md_id=".$this->md_id;
+ $res=$this->cn->exec_sql($sql);
+ $r=Database::fetch_array($res,0);
+ // if a lob is found
+ if ( strlen ($r['md_lob']) &&
+ $this->cn->exist_blob($r['md_lob']) )
+ {
+ // we remove it first
+ $this->cn->lo_unlink($r['md_lob']);
+ }
+ // now we can delete the row
+ $sql="delete from document_modele where md_id =".$this->md_id;
+ $sql=$this->cn->exec_sql($sql);
+ $this->cn->commit();
+ }
+
+ /*!
+ * \brief show the form for loading a template
+ * \param p_action for the field action = destination url
+ *
+ *
+ * \return string containing the forms
+ */
+ function form($p_action)
+ {
+ $r='';
+ $r.='Veuillez introduire les modèles servant à générer vos documents';
+ $r.='
';
+ $r.='';
+ $r.=dossier::hidden();
+ // we need to add the sub action as hidden
+ $h=new IHidden();
+ $h->name="sa";
+ $h->value="add_document";
+
+ $r.=$h->input();
+
+ $r.='';
+ $t=new IText();
+ $t->name="md_name";
+ $r.=" Nom ".$t->input()." ";
+
+ $r.=" ";
+ $r.="Catégorie de document ";
+ $w=new ISelect();
+ $w->name="md_type";
+
+ $w->value=$this->cn->make_array('select dt_id,dt_value from document_type');
+ $r.="".$w->input()." ";
+
+ $r.='';
+ $r.=td(_('Affectation'));
+ $waffect=new ISelect();
+ $waffect->name='md_affect';
+ $waffect->value=array(
+ array('value'=>'ACH','label'=>_('Uniquement journaux achat')),
+ array('value'=>'VEN','label'=>_('Uniquement journaux vente')),
+ array('value'=>'GES','label'=>_('Partie gestion'))
+ );
+
+ $r.=td($waffect->input());
+ $r.=' ';
+
+ $f=new IFile();
+ $f->name="doc";
+ $r.="fichier ".$f->input()." ";
+
+ $start=new IText();
+ $start->name="start_seq";
+ $start->size=9;
+ $start->value="0";
+
+ $r.=" Numerotation commence a ".$start->input()." ";
+ $r.='Si vous laissez à 0, la numérotation ne changera pas, la prochaine facture sera n+1, n étant le n° que vous avez donné ';
+ $r.=" ";
+ $r.='
';
+ $r.=HtmlInput::submit('add_document','Ajout');
+ $r.=" ";
+ return $r;
+ }
+ /*!\brief load the value of a document_modele,the ag_id variable must be set
+ */
+ function load()
+ {
+ $array=$this->cn->get_array("SELECT md_id, md_name, md_lob, md_type, md_filename, md_mimetype,md_affect".
+ " FROM document_modele where md_id=$1",array($this->md_id));
+ if ( count($array) == 0 ) return null;
+ foreach ( array('md_name', 'md_lob','md_type', 'md_filename', 'md_mimetype','md_affect') as $idx)
+ {
+ $this->$idx=$array[0][$idx];
+ }
}
- }
}
?>
diff --git a/include/class_document_type.php b/include/class_document_type.php
index f5d6e1a02..be5663fcc 100644
--- a/include/class_document_type.php
+++ b/include/class_document_type.php
@@ -1,4 +1,4 @@
-db=$p_cn;
- $this->dt_id=-1;
+ $this->db=$p_cn;
+ $this->dt_id=-1;
}
-/*!
- * \brief Get all the data for this dt_id
- */
- function get()
+ /*!
+ * \brief Get all the data for this dt_id
+ */
+ function get()
{
- $sql="select * from document_type where dt_id=$1";
- $R=$this->db->exec_sql($sql,array($this->dt_id));
- $r=Database::fetch_array($R,0);
- $this->dt_id=$r['dt_id'];
- $this->dt_value=$r['dt_value'];
+ $sql="select * from document_type where dt_id=$1";
+ $R=$this->db->exec_sql($sql,array($this->dt_id));
+ $r=Database::fetch_array($R,0);
+ $this->dt_id=$r['dt_id'];
+ $this->dt_value=$r['dt_value'];
}
- /**
- *@brief get a list
- *@parameter $p_cn database connection
- *@return array of data from document_type
- */
- static function get_list($p_cn) {
- $sql="select * from document_type";
- $r=$p_cn->get_array($sql);
- $array=array();
- for ($i=0;$iget_array($sql);
+ $array=array();
+ for ($i=0;$ilabel=_('Effacer');
- $bt->javascript="if (confirm('"._('Vous confirmez')."')==true) {";
- $bt->javascript.="cat_doc_remove('".$r[$i]['dt_id']."','".Dossier::id()."');";
- $bt->javascript.='}';
+ $bt=new IButton('X'.$r[$i]['dt_id']);
+ $bt->label=_('Effacer');
+ $bt->javascript="if (confirm('"._('Vous confirmez')."')==true) {";
+ $bt->javascript.="cat_doc_remove('".$r[$i]['dt_id']."','".Dossier::id()."');";
+ $bt->javascript.='}';
- $tmp['js_remove']=$bt->input();
- $tmp['dt_id']=$r[$i]['dt_id'];
- $array[$i]=$tmp;
+ $tmp['js_remove']=$bt->input();
+ $tmp['dt_id']=$r[$i]['dt_id'];
+ $array[$i]=$tmp;
+ }
+ return $array;
}
- return $array;
- }
- function insert($p_value) {
- $sql="insert into document_type(dt_value) values ($1)";
- try {
- if( $this->db->count_sql('select * from document_type where upper(dt_value)=upper(trim($1))',array($p_value))>0)
- throw new Exception('Nom en double');
- if ( strlen(trim($p_value))>0)
- $this->db->exec_sql($sql,array($p_value));
- }catch (Exception $e){
- alert(j(_("Impossible d'ajouter [$p_value] ").$e->getMessage()));
+ function insert($p_value)
+ {
+ $sql="insert into document_type(dt_value) values ($1)";
+ try
+ {
+ if( $this->db->count_sql('select * from document_type where upper(dt_value)=upper(trim($1))',array($p_value))>0)
+ throw new Exception('Nom en double');
+ if ( strlen(trim($p_value))>0)
+ $this->db->exec_sql($sql,array($p_value));
+ }
+ catch (Exception $e)
+ {
+ alert(j(_("Impossible d'ajouter [$p_value] ").$e->getMessage()));
+ }
}
- }
}
diff --git a/include/class_dossier.php b/include/class_dossier.php
index 1a11deb52..97267f1bc 100644
--- a/include/class_dossier.php
+++ b/include/class_dossier.php
@@ -20,7 +20,7 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*!\file
+/*!\file
* \brief the class for the dossier, everywhere we need to know to
* which folder we are connected, because we can't use $_SESSION, we
* need to pass the dossier_id via a _GET or a POST variable
@@ -37,164 +37,197 @@
require_once('class_database.php');
require_once('ac_common.php');
-class dossier {
- private static $variable=array("id"=>"dos_id",
- "name"=>"dos_name",
- "desc"=>"dos_description");
- function __construct($p_id) {
- $this->cn=new Database(); // Connect to the repository
- $this->dos_id=$p_id;
- }
- /*!\brief return the $_REQUEST['gDossier'] after a check */
- static function id() {
- self::check();
- return $_REQUEST['gDossier'];
- }
-
- /*!
- * \param p_type string : all for all dossiers lim for only the
- * dossier where we've got rights
- *
- * Show the folder where user have access. Return : nothing
- ++*/
- function show_dossier($p_type,$p_first=0,$p_max=10,$p_Num=0) {
- $l_user=$_SESSION['g_user'];
- if ( $p_max == 0 ) {
- $l_step="";
- } else {
- $l_step="LIMIT $p_max OFFSET $p_first";
+class dossier
+{
+ private static $variable=array("id"=>"dos_id",
+ "name"=>"dos_name",
+ "desc"=>"dos_description");
+ function __construct($p_id)
+ {
+ $this->cn=new Database(); // Connect to the repository
+ $this->dos_id=$p_id;
+ }
+ /*!\brief return the $_REQUEST['gDossier'] after a check */
+ static function id()
+ {
+ self::check();
+ return $_REQUEST['gDossier'];
}
- if ( $p_type == "all") {
- $l_sql="select *, 'W' as priv_priv from ac_dossier ORDER BY dos_name ";
- $p_Num=$this->cn->count_sql($l_sql);
- } else {
- $l_sql="select * from jnt_use_dos
- natural join ac_dossier
- natural join ac_users
- inner join priv_user on priv_jnt=jnt_id where
- use_login='".$l_user."' and priv_priv !='NO'
- order by dos_name ";
- $p_Num=$this->cn->count_sql($l_sql);
+ /*!
+ * \param p_type string : all for all dossiers lim for only the
+ * dossier where we've got rights
+ *
+ * Show the folder where user have access. Return : nothing
+ ++*/
+ function show_dossier($p_type,$p_first=0,$p_max=10,$p_Num=0)
+ {
+ $l_user=$_SESSION['g_user'];
+ if ( $p_max == 0 )
+ {
+ $l_step="";
+ }
+ else
+ {
+ $l_step="LIMIT $p_max OFFSET $p_first";
+ }
+
+ if ( $p_type == "all")
+ {
+ $l_sql="select *, 'W' as priv_priv from ac_dossier ORDER BY dos_name ";
+ $p_Num=$this->cn->count_sql($l_sql);
+ }
+ else
+ {
+ $l_sql="select * from jnt_use_dos
+ natural join ac_dossier
+ natural join ac_users
+ inner join priv_user on priv_jnt=jnt_id where
+ use_login='".$l_user."' and priv_priv !='NO'
+ order by dos_name ";
+ $p_Num=$this->cn->count_sql($l_sql);
+ }
+ $l_sql=$l_sql.$l_step;
+ $p_res=$this->cn->exec_sql($l_sql);
+
+
+ $Max=$this->cn->size();
+ if ( $Max == 0 ) return null;
+ for ( $i=0;$i<$Max; $i++)
+ {
+ $row[]=$this->cn->fetch($p_res);
+ }
+ return $row;
}
- $l_sql=$l_sql.$l_step;
- $p_res=$this->cn->exec_sql($l_sql);
-
- $Max=$this->cn->size();
- if ( $Max == 0 ) return null;
- for ( $i=0;$i<$Max; $i++) {
- $row[]=$this->cn->fetch($p_res);
+ /*!
+ * \brief Return all the users
+ * as an array
+ */
+ function get_user()
+ {
+ $sql="select * from ac_users where use_login!='phpcompta'";
+ $Res=$this->cn->exec_sql($sql);
+ $Num=$this->cn->size();
+ if ( $Num == 0 ) return null;
+ for ($i=0;$i < $Num; $i++)
+ {
+ $User[]=$this->cn->fetch($i);
+ }
+ return $User;
}
- return $row;
- }
-/*!
- * \brief Return all the users
- * as an array
- */
-function get_user() {
- $sql="select * from ac_users where use_login!='phpcompta'";
- $Res=$this->cn->exec_sql($sql);
- $Num=$this->cn->size();
- if ( $Num == 0 ) return null;
- for ($i=0;$i < $Num; $i++) {
- $User[]=$this->cn->fetch($i);
- }
- return $User;
-}
-
- /*!\brief check if gDossier is set */
- static function check() {
- if ( ! isset ($_REQUEST['gDossier']) ){
- echo_error ('Dossier inconnu ');
- exit('Dossier invalide ');
- }
- $id=$_REQUEST['gDossier'];
- if ( is_numeric ($id) == 0 ||
- strlen($id)> 6 ||
- $id > 999999)
- exit('gDossier Invalide : '.$id);
-
- }
- /*!\brief return a string to put to gDossier into a GET */
- static function get() {
- self::check();
- return "gDossier=".$_REQUEST['gDossier'];
-
- }
-
- /*!\brief return a string to set gDossier into a FORM */
- static function hidden() {
- self::check();
- return ' ';
- }
- /*!\brief retrieve the name of the current dossier */
- static function name($id=0) {
- self::check();
-
- $cn=new Database();
- $id=($id==0)?$_REQUEST['gDossier']:$id;
- $name=$cn->get_value("select dos_name from ac_dossier where dos_id=$1",array($_REQUEST['gDossier']));
- return $name;
- }
-
- public function get_parameter($p_string) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- return $this->$idx;
- }
- else
- exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
- }
- public function set_parameter($p_string,$p_value) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- $this->$idx=$p_value;
- }
- else
- exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
-
-
- }
- public function get_info() { return var_export(self::$variable,true); }
-
- public function save() {
- $this->update();
- }
-
- public function update() {
- if ( strlen(trim($this->dos_name))== 0 ) return;
-
- if ( $this->cn->get_value("select count(*) from ac_dossier where dos_name=$1 and dos_id<>$2",
- array($this->dos_name,$this->dos_id)) !=0 )
- return ;
-
- $sql="update ac_dossier set dos_name=$1,dos_description=$2 ".
- " where dos_id = $3";
- $res=$this->cn->exec_sql(
- $sql,
- array(trim($this->dos_name),
- trim($this->dos_description),
- $this->dos_id)
- );
- }
-
- public function load() {
-
- $sql="select dos_name,dos_description from ac_dossier where dos_id=$1";
-
- $res=$this->cn->exec_sql(
- $sql,
- array($this->dos_id)
- );
-
- if ( Database::num_row($res) == 0 ) return;
- $row=Database::fetch_array($res,0);
- foreach ($row as $idx=>$value) { $this->$idx=$value; }
- }
-
- static function get_version($p_cn) {
- return $p_cn->get_value('select val from version');
- }
+ /*!\brief check if gDossier is set */
+ static function check()
+ {
+ if ( ! isset ($_REQUEST['gDossier']) )
+ {
+ echo_error ('Dossier inconnu ');
+ exit('Dossier invalide ');
+ }
+ $id=$_REQUEST['gDossier'];
+ if ( is_numeric ($id) == 0 ||
+ strlen($id)> 6 ||
+ $id > 999999)
+ exit('gDossier Invalide : '.$id);
+
+ }
+ /*!\brief return a string to put to gDossier into a GET */
+ static function get()
+ {
+ self::check();
+ return "gDossier=".$_REQUEST['gDossier'];
+
+ }
+
+ /*!\brief return a string to set gDossier into a FORM */
+ static function hidden()
+ {
+ self::check();
+ return ' ';
+ }
+ /*!\brief retrieve the name of the current dossier */
+ static function name($id=0)
+ {
+ self::check();
+
+ $cn=new Database();
+ $id=($id==0)?$_REQUEST['gDossier']:$id;
+ $name=$cn->get_value("select dos_name from ac_dossier where dos_id=$1",array($_REQUEST['gDossier']));
+ return $name;
+ }
+
+ public function get_parameter($p_string)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ return $this->$idx;
+ }
+ else
+ exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
+ }
+ public function set_parameter($p_string,$p_value)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ $this->$idx=$p_value;
+ }
+ else
+ exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
+
+
+ }
+ public function get_info()
+ {
+ return var_export(self::$variable,true);
+ }
+
+ public function save()
+ {
+ $this->update();
+ }
+
+ public function update()
+ {
+ if ( strlen(trim($this->dos_name))== 0 ) return;
+
+ if ( $this->cn->get_value("select count(*) from ac_dossier where dos_name=$1 and dos_id<>$2",
+ array($this->dos_name,$this->dos_id)) !=0 )
+ return ;
+
+ $sql="update ac_dossier set dos_name=$1,dos_description=$2 ".
+ " where dos_id = $3";
+ $res=$this->cn->exec_sql(
+ $sql,
+ array(trim($this->dos_name),
+ trim($this->dos_description),
+ $this->dos_id)
+ );
+ }
+
+ public function load()
+ {
+
+ $sql="select dos_name,dos_description from ac_dossier where dos_id=$1";
+
+ $res=$this->cn->exec_sql(
+ $sql,
+ array($this->dos_id)
+ );
+
+ if ( Database::num_row($res) == 0 ) return;
+ $row=Database::fetch_array($res,0);
+ foreach ($row as $idx=>$value)
+ {
+ $this->$idx=$value;
+ }
+
+ }
+
+ static function get_version($p_cn)
+ {
+ return $p_cn->get_value('select val from version');
+ }
}
diff --git a/include/class_extension.php b/include/class_extension.php
index ac714188c..125eb55a0 100644
--- a/include/class_extension.php
+++ b/include/class_extension.php
@@ -24,260 +24,292 @@
* \brief the extension class manages the plugins for the security, the access
* the inclusion...
*/
- /*!\brief manage the extension, it involves the table extension
- *
- * Data member
- * - $cn database connection
- * - $variable :
- * - id (extension.ex_id)
- * - name (extension.ex_name)
- * - plugin_code (extension.ex_code)
- * - desc (extension.ex_desc)
- * - enable (extension.ex_enable)
- * - filepath (extension.ex_file)
- */
+/*!\brief manage the extension, it involves the table extension
+ *
+ * Data member
+ * - $cn database connection
+ * - $variable :
+ * - id (extension.ex_id)
+ * - name (extension.ex_name)
+ * - plugin_code (extension.ex_code)
+ * - desc (extension.ex_desc)
+ * - enable (extension.ex_enable)
+ * - filepath (extension.ex_file)
+ */
class Extension
{
- private static $variable=array('id'=>'ex_id',
- 'name'=>'ex_name',
- 'code'=>'ex_code',
- 'desc'=>'ex_desc',
- 'enable'=>'ex_enable',
- 'filepath'=>'ex_file');
- /*!\brief constructor
- *\param a database connextion
- */
- function __construct ($p_init) {
- $this->cn=$p_init;
- $this->ex_id=0;
- }
- public function get_parameter($p_string) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- return $this->$idx;
+ private static $variable=array('id'=>'ex_id',
+ 'name'=>'ex_name',
+ 'code'=>'ex_code',
+ 'desc'=>'ex_desc',
+ 'enable'=>'ex_enable',
+ 'filepath'=>'ex_file');
+ /*!\brief constructor
+ *\param a database connextion
+ */
+ function __construct ($p_init)
+ {
+ $this->cn=$p_init;
+ $this->ex_id=0;
}
- else
- exit (__FILE__.":".__LINE__.'Erreur attribut inexistant'.$p_string);
- }
- public function set_parameter($p_string,$p_value) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- $this->$idx=$p_value;
+ public function get_parameter($p_string)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ return $this->$idx;
+ }
+ else
+ exit (__FILE__.":".__LINE__.'Erreur attribut inexistant'.$p_string);
}
- else
- exit (__FILE__.":".__LINE__.'Erreur attribut inexistant '.$p_string);
-
-
- }
- public function get_info() { return var_export(self::$variable,true); }
- public function verify() {
- // Verify that the elt we want to add is correct
- if (trim($this->ex_code)=="") throw new Exception('Le code ne peut pas être vide');
- if (trim($this->ex_name)=="") throw new Exception('Le nom ne peut pas être vide');
- if (trim($this->ex_file)=="") throw new Exception('Chemin incorrect');
- if (file_exists('..'.DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'ext'.DIRECTORY_SEPARATOR.$this->ex_file) == false)
- throw new Exception ('Extension non trouvée, le chemin est-il correct?');
- }
- /*!\brief call insert for a new plugin or update if the plugin exist */
- public function save() {
- if ( $this->get_parameter("id") == 0 )
- $this->insert();
- else
- $this->update();
- }
- /*!\brief insert a plugin
- * \return error = -1 otherwiser the id */
- public function insert() {
- if ( $this->verify() != 0 ) return -1;
- if ( $this->cn->count_sql('select * from extension where upper(ex_code)=upper($1)',
- array($this->ex_code)) > 0)
- throw new Exception ('Ce code existe déjà');
- if ( $this->cn->count_sql('select * from extension where upper(ex_name)=upper($1)',
- array($this->ex_name)) > 0)
- throw new Exception ('Ce nom existe déjà');
+ public function set_parameter($p_string,$p_value)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ $this->$idx=$p_value;
+ }
+ else
+ exit (__FILE__.":".__LINE__.'Erreur attribut inexistant '.$p_string);
- $sql='INSERT INTO extension( ex_code, ex_desc, ex_file, ex_enable,ex_name) '.
- ' VALUES ($1, $2, $3,$4,$5) returning ex_id';
- $res=$this->cn->exec_sql(
- $sql,
- array($this->ex_code,
- $this->ex_desc,
- $this->ex_file,
- $this->ex_enable,
- $this->ex_name)
- );
- $this->ex_id=Database::fetch_result($res,0,0);
- }
- /*!\brief update a plugin
- * \return error = -1 otherwiser 0 */
- public function update() {
- if ( $this->verify() != 0 ) return -1;
- $sql='UPDATE extension '.
- 'SET ex_code=$1, ex_desc=$2, ex_file=$3, ex_enable=$4,ex_name=$5 '.
- ' WHERE ex_id=$6 ';
- $this->cn->exec_sql($sql,
- array($this->ex_code,
- $this->ex_desc,
- $this->ex_file,
- $this->ex_enable,
- $this->ex_name,
- $this->ex_id)
- );
- return 0;
- }
- /*!\brief load a plugin */
- public function load() {
- $sql='SELECT ex_id, ex_name,ex_code, ex_desc, ex_file, ex_enable '.
- ' FROM extension where ex_id=$1';
- $res=$this->cn->exec_sql($sql,array($this->ex_id));
- if ( Database::num_row($res) == 0 ) return -1;
- $row=Database::fetch_array($res,0);
- foreach ($row as $idx=>$value) { $this->$idx=$value; }
- return 0;
- }
- /*!\brief delete a plugin */
- public function delete() {
- $sql="delete from extension where ex_id=$1";
- $res=$this->cn->exec_sql($sql,array($this->ex_id));
- }
- /*!\brief load all the plugin and returns an array
- *\param $p_cn database connx
- */
- static public function listing($p_cn) {
- $sql="SELECT ex_id, ex_name,ex_code, ex_desc, ex_file, ex_enable FROM extension";
- $array=$p_cn->get_array($sql);
- return $array;
- }
- /*!\brief transform an array into a valid object
- *\param $array with the value
- *\verbatim
-code => ''
-desc =>''
-enable=>''
-file=>''
-actif=>''
-ex_id=>''
-\endverbatim
- *\see ajax_extension.php
- */
- function fromArray($p_array) {
- $this->ex_id=$p_array['ex_id'];
- $this->ex_name=$p_array['name'];
- $this->ex_code=$p_array['code'];
- $this->ex_desc=$p_array['desc'];
- $this->ex_enable=$p_array['enable'];
- $this->ex_file=$p_array['file'];
- }
- /*!@brief search a extension, the what is the column (extends_code */
- function search($p_what,$p_value) {
- switch($p_what) {
- case 'code':
- $cond=" where ex_code = upper($1) ";
- break;
- default:
- return -1;
+ }
+ public function get_info()
+ {
+ return var_export(self::$variable,true);
+ }
+ public function verify()
+ {
+ // Verify that the elt we want to add is correct
+ if (trim($this->ex_code)=="") throw new Exception('Le code ne peut pas être vide');
+ if (trim($this->ex_name)=="") throw new Exception('Le nom ne peut pas être vide');
+ if (trim($this->ex_file)=="") throw new Exception('Chemin incorrect');
+ if (file_exists('..'.DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'ext'.DIRECTORY_SEPARATOR.$this->ex_file) == false)
+ throw new Exception ('Extension non trouvée, le chemin est-il correct?');
+ }
+ /*!\brief call insert for a new plugin or update if the plugin exist */
+ public function save()
+ {
+ if ( $this->get_parameter("id") == 0 )
+ $this->insert();
+ else
+ $this->update();
+ }
+ /*!\brief insert a plugin
+ * \return error = -1 otherwiser the id */
+ public function insert()
+ {
+ if ( $this->verify() != 0 ) return -1;
+ if ( $this->cn->count_sql('select * from extension where upper(ex_code)=upper($1)',
+ array($this->ex_code)) > 0)
+ throw new Exception ('Ce code existe déjà');
+ if ( $this->cn->count_sql('select * from extension where upper(ex_name)=upper($1)',
+ array($this->ex_name)) > 0)
+ throw new Exception ('Ce nom existe déjà');
+
+ $sql='INSERT INTO extension( ex_code, ex_desc, ex_file, ex_enable,ex_name) '.
+ ' VALUES ($1, $2, $3,$4,$5) returning ex_id';
+ $res=$this->cn->exec_sql(
+ $sql,
+ array($this->ex_code,
+ $this->ex_desc,
+ $this->ex_file,
+ $this->ex_enable,
+ $this->ex_name)
+ );
+ $this->ex_id=Database::fetch_result($res,0,0);
+ }
+ /*!\brief update a plugin
+ * \return error = -1 otherwiser 0 */
+ public function update()
+ {
+ if ( $this->verify() != 0 ) return -1;
+ $sql='UPDATE extension '.
+ 'SET ex_code=$1, ex_desc=$2, ex_file=$3, ex_enable=$4,ex_name=$5 '.
+ ' WHERE ex_id=$6 ';
+ $this->cn->exec_sql($sql,
+ array($this->ex_code,
+ $this->ex_desc,
+ $this->ex_file,
+ $this->ex_enable,
+ $this->ex_name,
+ $this->ex_id)
+ );
+ return 0;
+ }
+ /*!\brief load a plugin */
+ public function load()
+ {
+ $sql='SELECT ex_id, ex_name,ex_code, ex_desc, ex_file, ex_enable '.
+ ' FROM extension where ex_id=$1';
+ $res=$this->cn->exec_sql($sql,array($this->ex_id));
+ if ( Database::num_row($res) == 0 ) return -1;
+ $row=Database::fetch_array($res,0);
+ foreach ($row as $idx=>$value)
+ {
+ $this->$idx=$value;
+ }
+ return 0;
+ }
+ /*!\brief delete a plugin */
+ public function delete()
+ {
+ $sql="delete from extension where ex_id=$1";
+ $res=$this->cn->exec_sql($sql,array($this->ex_id));
+ }
+ /*!\brief load all the plugin and returns an array
+ *\param $p_cn database connx
+ */
+ static public function listing($p_cn)
+ {
+ $sql="SELECT ex_id, ex_name,ex_code, ex_desc, ex_file, ex_enable FROM extension";
+ $array=$p_cn->get_array($sql);
+ return $array;
+ }
+ /*!\brief transform an array into a valid object
+ *\param $array with the value
+ *\verbatim
+ code => ''
+ desc =>''
+ enable=>''
+ file=>''
+ actif=>''
+ ex_id=>''
+ \endverbatim
+ *\see ajax_extension.php
+ */
+ function fromArray($p_array)
+ {
+ $this->ex_id=$p_array['ex_id'];
+ $this->ex_name=$p_array['name'];
+ $this->ex_code=$p_array['code'];
+ $this->ex_desc=$p_array['desc'];
+ $this->ex_enable=$p_array['enable'];
+ $this->ex_file=$p_array['file'];
+
+ }
+ /*!@brief search a extension, the what is the column (extends_code */
+ function search($p_what,$p_value)
+ {
+ switch($p_what)
+ {
+ case 'code':
+ $cond=" where ex_code = upper($1) ";
+ break;
+ default:
+ return -1;
+ }
+
+ $sql="select ex_id from extension $cond";
+ $res=$this->cn->get_value($sql, array($p_value));
+ if ( $res=="") return -1;
+
+ $this->ex_id=$res;
+ $this->load();
+
+ }
+ /*!\brief return 1 if the user given in parameter can access this extension
+ * otherwise returns 0
+ *\param $p_login the user login
+ *\return 1 has access, 0 has no access
+ */
+ function can_request($p_login)
+ {
+ $sql="select use_access from user_sec_extension where ".
+ "upper(use_login ) = upper($1) and ex_id=$2";
+ $ret=$this->cn->get_value($sql,array($p_login,$this->ex_id));
+ if ( $this->cn->count() == 0 ) return 0;
+ if ( $ret=='Y') return 1;
+ return 0;
+ }
+ /*!@brief save the security in the table
+ *@param $p_array is an array of value
+ * indices are :
+ * - "is_" + login
+ * - value is Y or N
+ * you must add the value of gDossier
+ \code
+ [is_phpcompta]=>N
+ [gDossier]=>xx
+ \endcode
+ */
+ function save_security($p_array)
+ {
+ $d=$p_array['gDossier'];
+ $cn=new Database($d);
+ $list_user=User::get_list($d);
+ for ($i=0;$icount_sql("select ex_id from user_sec_extension where use_login=$1 and ex_id=$2"
+ ,array($list_user[$i]['use_login'],$this->ex_id)) == 0 )
+ {
+ /* insert */
+ $sql="INSERT INTO user_sec_extension(
+ ex_id, use_login, use_access) VALUES ($1,$2,$3)";
+ $cn->exec_sql($sql,array($this->ex_id,$list_user[$i]['use_login'],$p_array[$ix]));
+
+ }
+ else
+ {
+ /* update */
+ $sql="update user_sec_extension set use_access=$1 where ex_id=$2 and use_login=$3";
+ $cn->exec_sql($sql,array($p_array[$ix],$this->ex_id,$list_user[$i]['use_login']));
+ }
+ }
+
+ }
+ }
+ /*!@brief make an array of the available plugin for the current user
+ * @return an array
+ *@see ISelect
+ */
+ static function make_array($cn)
+ {
+ $sql="select ex_code as value, ex_name as label from user_sec_extension ".
+ " join extension using (ex_id) where ex_enable='Y' and use_access='Y' ".
+ " and use_login=$1";
+ $a=$cn->get_array($sql,array($_SESSION['g_user']));
+ return $a;
+ }
+ static function check_version($i)
+ {
+ global $version_phpcompta;
+ if ( ! isset ($version_phpcompta) || $version_phpcompta < $i )
+ {
+ alert('Cette extension ne fonctionne pas sur cette version de PhpCompta'.
+ ' Veuillez mettre votre programme a jour');
+ exit();
+ }
+ }
+ /*!\brief test this class
+ */
+ static function test_me()
+ {
+ $cn=new Database(dossier::id());
+ print 'Save ';
+ $ext=new Extension($cn);
+ /* create a plugin */
+ $ext->set_parameter('code','test');
+ $ext->set_parameter('enable','Y');
+ $ext->set_parameter('desc','plugin de test');
+ $ext->set_parameter('filepath','test.php');
+ $ext->save();
+ print 'Show ';
+ /* show plugins */
+ $res=$cn->get_array('select * from extension');
+ print_r($res);
+ /* delete plugin */
+ print 'Load ';
+ $ext->load();
+ print_r($ext);
+ print 'Delete ';
+ $ext->delete();
}
- $sql="select ex_id from extension $cond";
- $res=$this->cn->get_value($sql, array($p_value));
- if ( $res=="") return -1;
-
- $this->ex_id=$res;
- $this->load();
-
- }
- /*!\brief return 1 if the user given in parameter can access this extension
- * otherwise returns 0
- *\param $p_login the user login
- *\return 1 has access, 0 has no access
- */
- function can_request($p_login) {
- $sql="select use_access from user_sec_extension where ".
- "upper(use_login ) = upper($1) and ex_id=$2";
- $ret=$this->cn->get_value($sql,array($p_login,$this->ex_id));
- if ( $this->cn->count() == 0 ) return 0;
- if ( $ret=='Y') return 1;
- return 0;
- }
- /*!@brief save the security in the table
- *@param $p_array is an array of value
- * indices are :
- * - "is_" + login
- * - value is Y or N
- * you must add the value of gDossier
-\code
-[is_phpcompta]=>N
-[gDossier]=>xx
-\endcode
- */
- function save_security($p_array) {
- $d=$p_array['gDossier'];
- $cn=new Database($d);
- $list_user=User::get_list($d);
- for ($i=0;$icount_sql("select ex_id from user_sec_extension where use_login=$1 and ex_id=$2"
- ,array($list_user[$i]['use_login'],$this->ex_id)) == 0 ) {
- /* insert */
- $sql="INSERT INTO user_sec_extension(
- ex_id, use_login, use_access) VALUES ($1,$2,$3)";
- $cn->exec_sql($sql,array($this->ex_id,$list_user[$i]['use_login'],$p_array[$ix]));
-
- }else {
- /* update */
- $sql="update user_sec_extension set use_access=$1 where ex_id=$2 and use_login=$3";
- $cn->exec_sql($sql,array($p_array[$ix],$this->ex_id,$list_user[$i]['use_login']));
- }
- }
-
- }
- }
- /*!@brief make an array of the available plugin for the current user
- * @return an array
- *@see ISelect
- */
- static function make_array($cn) {
- $sql="select ex_code as value, ex_name as label from user_sec_extension ".
- " join extension using (ex_id) where ex_enable='Y' and use_access='Y' ".
- " and use_login=$1";
- $a=$cn->get_array($sql,array($_SESSION['g_user']));
- return $a;
- }
- static function check_version($i) {
- global $version_phpcompta;
- if ( ! isset ($version_phpcompta) || $version_phpcompta < $i ) {
- alert('Cette extension ne fonctionne pas sur cette version de PhpCompta'.
- ' Veuillez mettre votre programme a jour');
- exit();
- }
- }
- /*!\brief test this class
- */
- static function test_me() {
- $cn=new Database(dossier::id());
- print 'Save ';
- $ext=new Extension($cn);
- /* create a plugin */
- $ext->set_parameter('code','test');
- $ext->set_parameter('enable','Y');
- $ext->set_parameter('desc','plugin de test');
- $ext->set_parameter('filepath','test.php');
- $ext->save();
- print 'Show ';
- /* show plugins */
- $res=$cn->get_array('select * from extension');
- print_r($res);
- /* delete plugin */
- print 'Load ';
- $ext->load();
- print_r($ext);
- print 'Delete ';
- $ext->delete();
- }
-
}
/* test::test_me(); */
diff --git a/include/class_fiche.php b/include/class_fiche.php
index bd1c20985..2ab4398c8 100644
--- a/include/class_fiche.php
+++ b/include/class_fiche.php
@@ -42,1608 +42,1689 @@ require_once('class_iposte.php');
//-----------------------------------------------------
// class fiche
//-----------------------------------------------------
-class Fiche {
- var $cn; /*! < $cn database connection */
- var $id; /*! < $id fiche.f_id */
- var $fiche_def; /*! < $fiche_def fd_id */
- var $attribut; /*! < $attribut array of attribut object */
- var $fiche_def_ref; /*!< $fiche_def_ref Type */
- var $row; /*! < All the row from the ledgers */
- var $quick_code; /*!< quick_code of the card */
- function __construct($p_cn,$p_id=0) {
- $this->cn=$p_cn;
- $this->id=$p_id;
- $this->quick_code='';
- }
- /**
- *@brief used with a usort function, to sort an array of Fiche on the name
- */
- static function cmp_name($o1,$o2) {
- return strcmp($o1->strAttribut(ATTR_DEF_NAME),$o2->strAttribut(ATTR_DEF_NAME));
- }
-
-/*! get_by_qcode($p_qcode)
- * \brief Retrieve a card thx his quick_code
- * complete the object,, set the id member of the object or set it
- * to 0 if no card is found
- * \param $p_qcode quick_code (ad_id=23)
- * \param $p_all retrieve all the attribut of the card, possible value
- * are true or false. false retrieves only the f_id. By default true
- * \return 0 success 1 error not found
- */
- function get_by_qcode($p_qcode=null,$p_all=true)
+class Fiche
+{
+ var $cn; /*! < $cn database connection */
+ var $id; /*! < $id fiche.f_id */
+ var $fiche_def; /*! < $fiche_def fd_id */
+ var $attribut; /*! < $attribut array of attribut object */
+ var $fiche_def_ref; /*!< $fiche_def_ref Type */
+ var $row; /*! < All the row from the ledgers */
+ var $quick_code; /*!< quick_code of the card */
+ function __construct($p_cn,$p_id=0)
{
- if ( $p_qcode == null )
- $p_qcode=$this->quick_code;
- $p_qcode=trim($p_qcode);
- $sql="select f_id from jnt_fic_att_value join attr_value
- using (jft_id) where ad_id=23 and av_text=upper($1)";
- $this->id=$this->cn->get_value($sql,array($p_qcode));
- if ( $this->cn->count()==0) {
- $this->id=0;
- return 1;
- }
-
-
- if ( $p_all )
- $this->getAttribut();
- return 0;
+ $this->cn=$p_cn;
+ $this->id=$p_id;
+ $this->quick_code='';
}
- /**
- *@brief set an attribute by a value, if the attribut array is empty
- * a call to getAttribut is performed
- *@param the AD_ID
- *@param the value
- *@see constant.php table: attr_def
- */
- function setAttribut($p_ad_id,$p_value) {
- if ( sizeof($this->attribut)==0 ) $this->getAttribut();
- for ($e=0;$e attribut);$e++) {
- if ( $this->attribut[$e]->ad_id == $p_ad_id ) {
- $this->attribut[$e]->av_text=$p_value; break;
- }
+ /**
+ *@brief used with a usort function, to sort an array of Fiche on the name
+ */
+ static function cmp_name($o1,$o2)
+ {
+ return strcmp($o1->strAttribut(ATTR_DEF_NAME),$o2->strAttribut(ATTR_DEF_NAME));
}
- }
- /**
- *\brief get all the attribute of a card, add missing ones
- * and sort the array ($this-\>attribut) by ad_id
- */
- function getAttribut() {
- if ( $this->id == 0){
- return;
+
+ /*! get_by_qcode($p_qcode)
+ * \brief Retrieve a card thx his quick_code
+ * complete the object,, set the id member of the object or set it
+ * to 0 if no card is found
+ * \param $p_qcode quick_code (ad_id=23)
+ * \param $p_all retrieve all the attribut of the card, possible value
+ * are true or false. false retrieves only the f_id. By default true
+ * \return 0 success 1 error not found
+ */
+ function get_by_qcode($p_qcode=null,$p_all=true)
+ {
+ if ( $p_qcode == null )
+ $p_qcode=$this->quick_code;
+ $p_qcode=trim($p_qcode);
+ $sql="select f_id from jnt_fic_att_value join attr_value
+ using (jft_id) where ad_id=23 and av_text=upper($1)";
+ $this->id=$this->cn->get_value($sql,array($p_qcode));
+ if ( $this->cn->count()==0)
+ {
+ $this->id=0;
+ return 1;
+ }
+
+
+ if ( $p_all )
+ $this->getAttribut();
+ return 0;
}
- $sql="select *
- from jnt_fic_att_value
- natural join fiche
- natural join attr_value
- join jnt_fic_attr on (jnt_fic_attr.fd_id=fiche.fd_id and jnt_fic_attr.ad_id=jnt_fic_att_value.ad_id)
- join attr_def on (attr_def.ad_id=jnt_fic_att_value.ad_id) where f_id=".$this->id.
- " order by jnt_order";
-
- $Ret=$this->cn->exec_sql($sql);
- if ( ($Max=Database::num_row($Ret)) == 0 )
- return ;
- for ($i=0;$i<$Max;$i++) {
- $row=Database::fetch_array($Ret,$i);
- $this->fiche_def=$row['fd_id'];
- $t=new Fiche_Attr ($this->cn);
- $t->ad_id=$row['ad_id'];
- $t->ad_text=$row['ad_text'];
- $t->av_text=$row['av_text'];
- $t->ad_type=$row['ad_type'];
- $t->ad_size=$row['ad_size'];
- $t->jnt_order=$row['jnt_order'];
- $this->attribut[$i]=$t;
+ /**
+ *@brief set an attribute by a value, if the attribut array is empty
+ * a call to getAttribut is performed
+ *@param the AD_ID
+ *@param the value
+ *@see constant.php table: attr_def
+ */
+ function setAttribut($p_ad_id,$p_value)
+ {
+ if ( sizeof($this->attribut)==0 ) $this->getAttribut();
+ for ($e=0;$e attribut);$e++)
+ {
+ if ( $this->attribut[$e]->ad_id == $p_ad_id )
+ {
+ $this->attribut[$e]->av_text=$p_value;
+ break;
+ }
+ }
}
- $e=new Fiche_Def($this->cn,$this->fiche_def);
- $e->GetAttribut();
+ /**
+ *\brief get all the attribute of a card, add missing ones
+ * and sort the array ($this-\>attribut) by ad_id
+ */
+ function getAttribut()
+ {
+ if ( $this->id == 0)
+ {
+ return;
+ }
+ $sql="select *
+ from jnt_fic_att_value
+ natural join fiche
+ natural join attr_value
+ join jnt_fic_attr on (jnt_fic_attr.fd_id=fiche.fd_id and jnt_fic_attr.ad_id=jnt_fic_att_value.ad_id)
+ join attr_def on (attr_def.ad_id=jnt_fic_att_value.ad_id) where f_id=".$this->id.
+ " order by jnt_order";
- if ( sizeof($this->attribut) != sizeof($e->attribut ) ) {
+ $Ret=$this->cn->exec_sql($sql);
+ if ( ($Max=Database::num_row($Ret)) == 0 )
+ return ;
+ for ($i=0;$i<$Max;$i++)
+ {
+ $row=Database::fetch_array($Ret,$i);
+ $this->fiche_def=$row['fd_id'];
+ $t=new Fiche_Attr ($this->cn);
+ $t->ad_id=$row['ad_id'];
+ $t->ad_text=$row['ad_text'];
+ $t->av_text=$row['av_text'];
+ $t->ad_type=$row['ad_type'];
+ $t->ad_size=$row['ad_size'];
+ $t->jnt_order=$row['jnt_order'];
+ $this->attribut[$i]=$t;
+ }
+ $e=new Fiche_Def($this->cn,$this->fiche_def);
+ $e->GetAttribut();
- // !!! Missing attribute
- foreach ($e->attribut as $f ) {
- $flag=0;
- foreach ($this->attribut as $g ) {
- if ( $g->ad_id == $f->ad_id )
- $flag=1;
- }
- if ( $flag == 0 ) {
- // there's a missing one, we insert it
- $t=new Fiche_Attr ($f->ad_id);
- $t->av_text="";
- $t->ad_text=$f->ad_text;
- $t->jnt_order=$f->jnt_order;
- $t->ad_type=$f->ad_type;
- $t->ad_size=$f->ad_size;
- $t->ad_id=$f->ad_id;
- $this->attribut[$Max]=$t;
- $Max++;
- } // if flag == 0
+ if ( sizeof($this->attribut) != sizeof($e->attribut ) )
+ {
- }// foreach
+ // !!! Missing attribute
+ foreach ($e->attribut as $f )
+ {
+ $flag=0;
+ foreach ($this->attribut as $g )
+ {
+ if ( $g->ad_id == $f->ad_id )
+ $flag=1;
+ }
+ if ( $flag == 0 )
+ {
+ // there's a missing one, we insert it
+ $t=new Fiche_Attr ($f->ad_id);
+ $t->av_text="";
+ $t->ad_text=$f->ad_text;
+ $t->jnt_order=$f->jnt_order;
+ $t->ad_type=$f->ad_type;
+ $t->ad_size=$f->ad_size;
+ $t->ad_id=$f->ad_id;
+ $this->attribut[$Max]=$t;
+ $Max++;
+ } // if flag == 0
+
+ }// foreach
- }//missing attribut
- }
- /**
- * @brief find the card with the p_attribut equal to p_value, it is not case sensitive
- * @param $p_attribut attribute to find see table attr_def
- * @param $p_value value in attr_value.av_text
- * @return return ARRAY OF jft_id,f_id,fd_id,ad_id,av_text
- */
- function seek($p_attribut,$p_value){
- $sql="select jft_id,f_id,fd_id,ad_id,av_text from fiche join jnt_fic_att_value using (f_id) join attr_value
+ }//missing attribut
+ }
+ /**
+ * @brief find the card with the p_attribut equal to p_value, it is not case sensitive
+ * @param $p_attribut attribute to find see table attr_def
+ * @param $p_value value in attr_value.av_text
+ * @return return ARRAY OF jft_id,f_id,fd_id,ad_id,av_text
+ */
+ function seek($p_attribut,$p_value)
+ {
+ $sql="select jft_id,f_id,fd_id,ad_id,av_text from fiche join jnt_fic_att_value using (f_id) join attr_value
using (jft_id) where ad_id=$1 and upper(av_text)=upper($2)";
- $res=$this->cn->get_array($sql,array($p_attribut,$p_value));
- return $res;
- }
-
-/*!
- * \brief give the size of a card object
- *
- * \return size
- */
- function size() {
- if ( isset ($this->ad_id))
- return sizeof($this->ad_id);
- else
- return 0;
- }
-
-
-/*!
- **************************************************
- * \brief Return array of card from the frd family
- *
- * \param $p_frd_id the fiche_def_ref.frd_id
- * \param $p_search p_search is a filter on the name
- * \param $p_sql extra sql condition
- *
- * \return array of fiche object
- */
- function CountByDef($p_frd_id,$p_search="",$p_sql="") {
- $sql="select *
- from
- fiche join fiche_Def using (fd_id)
- where frd_id=".$p_frd_id;
- if ( $p_search != "" )
- {
- $a=FormatString($p_search);
- $sql="select * from vw_fiche_attr where frd_id=".$p_frd_id.
- " and vw_name ~* '$p_search'";
- }
-
- $Ret=$this->cn->exec_sql($sql.$p_sql);
-
- return Database::num_row($Ret) ;
- }
-/*!
- **************************************************
- * \brief Return array of card from the frd family
- *
- *
- * \param $p_frd_id the fiche_def_ref.frd_id
- * \param $p_offset
- * \param $p_search is an optional filter
- *\param $p_order : possible values are name, f_id
- * \return array of fiche object
- */
- function GetByDef($p_frd_id,$p_offset=-1,$p_search="",$p_order='') {
- switch($p_order) {
- case 'name' :
- $order=' order by name';
- break;
- case 'f_id':
- $order='order by f_id';
- break;
- default:
- $order='';
+ $res=$this->cn->get_array($sql,array($p_attribut,$p_value));
+ return $res;
}
- if ( $p_offset == -1 )
- {
- $sql="select *
- from
- fiche join fiche_Def using (fd_id) join vw_fiche_name using(f_id)
- where frd_id=".$p_frd_id." $p_search ".$order;
- }
- else
- {
- $limit=($_SESSION['g_pagesize']!=-1)?"limit ".$_SESSION['g_pagesize']:"";
- $sql="select *
- from
- fiche join fiche_Def using (fd_id) join vw_fiche_name using(f_id)
- where frd_id=".$p_frd_id." $p_search $order "
- .$limit." offset ".$p_offset;
- }
-
- $Ret=$this->cn->exec_sql($sql);
- if ( ($Max=Database::num_row($Ret)) == 0 )
- return ;
- $all[0]=new Fiche($this->cn);
-
- for ($i=0;$i<$Max;$i++) {
- $row=Database::fetch_array($Ret,$i);
- $t=new Fiche($this->cn,$row['f_id']);
- $t->getAttribut();
- $all[$i]=$t;
-
- }
- return $all;
- }
- function ShowTable() {
- echo " ".
- $this->id." ".
- " ".
- $this->attribut_value." ".
- " ".
- $this->attribut_def." ";
- }
-/*!
- **************************************************
- * \brief return the string of the given attribute
- * (attr_def.ad_id)
- * \param $p_ad_id the AD_ID from attr_def.ad_id
- * \see constant.php
- * \return string
- */
- function strAttribut($p_ad_id)
+ /*!
+ * \brief give the size of a card object
+ *
+ * \return size
+ */
+ function size()
{
- if ( sizeof ($this->attribut) == 0 )
- {
-
- if ($this->id==0) return NOTFOUND;
- // object is not in memory we need to look into the database
- $sql="select av_text from attr_value join jnt_fic_att_value using(jft_id)
- where f_id=".FormatString($this->id)." and ad_id=".$p_ad_id;
- $Res=$this->cn->exec_sql($sql);
- $row=Database::fetch_all($Res);
- // if not found return error
- if ( $row == false )
- return NOTFOUND;
-
- return $row[0]['av_text'];
- }
-
- foreach ($this->attribut as $e)
- {
- if ( $e->ad_id == $p_ad_id )
- return $e->av_text;
- }
- return NOTFOUND;
+ if ( isset ($this->ad_id))
+ return sizeof($this->ad_id);
+ else
+ return 0;
}
- /*!\brief make an array of attributes of the category of card (FICHE_DEF.FD_ID)
- *The array can be used with the function insert, it will return a struct like this :
- * in the first key (av_textX), X is the ATTR_DEF::AD_ID
-\verbatim
-Example
-Array
-(
- [av_text1] => Nom
- [av_text12] => Personne de contact
- [av_text5] => Poste Comptable
- [av_text13] => numéro de tva
- [av_text14] => Adresse
- [av_text15] => code postal
- [av_text24] => Ville
- [av_text16] => pays
- [av_text17] => téléphone
- [av_text18] => email
- [av_text23] => Quick Code
-)
-\endverbatim
- *\param $pfd_id FICHE_DEF::FD_ID
- *\return an array of attribute
- *\exception Exception if the cat of card doesn't exist, Exception.getCode()=1
- *\see fiche::insert()
- */
- function toArray($pfd_id) {
- $sql="select 'av_text'||to_char(ad_id,'9999') as key,".
- " ad_text ".
- " from fiche_def join jnt_fic_attr using (fd_id)".
- " join attr_def using (ad_id) ".
- " where fd_id=$1 order by jnt_order";
- $ret=$this->cn->get_array($sql,array($pfd_id));
- if ( empty($ret)) throw new Exception(_('Cette categorie de card n\'existe pas').' '.$pfd_id,1);
- $array=array();
- foreach($ret as $idx=>$val) {
- $a=str_replace(' ','',$val['key']);
- $array[$a]=$val['ad_text'];
- }
- return $array;
- }
-/*!
- * \brief insert a new record
- * show a blank card to be filled
- *
- * \param $p_fiche_def is the fiche_def.fd_id
- *
- * \return HTML Code
- */
- function blank($p_fiche_def)
+ /*!
+ **************************************************
+ * \brief Return array of card from the frd family
+ *
+ * \param $p_frd_id the fiche_def_ref.frd_id
+ * \param $p_search p_search is a filter on the name
+ * \param $p_sql extra sql condition
+ *
+ * \return array of fiche object
+ */
+ function CountByDef($p_frd_id,$p_search="",$p_sql="")
{
- // array = array of attribute object sorted on ad_id
- $f=new Fiche_Def($this->cn,$p_fiche_def);
- $f->Get();
- $array=$f->getAttribut();
- $r='';
- foreach ($array as $attr)
- {
- $table=0;
- $msg="";
- if ( $attr->ad_id == ATTR_DEF_ACCOUNT)
- {
- $w=new IPoste("av_text".$attr->ad_id);
- $w->set_attribute('ipopup','ipop_account');
- $w->set_attribute('account',"av_text".$attr->ad_id);
- // account created automatically
- $sql="select account_auto($p_fiche_def)";
- $ret_sql=$this->cn->exec_sql($sql);
- $a=Database::fetch_array($ret_sql,0);
- $label=new ISpan();
- $label->name="av_text".$attr->ad_id."_label";
+ $sql="select *
+ from
+ fiche join fiche_Def using (fd_id)
+ where frd_id=".$p_frd_id;
+ if ( $p_search != "" )
+ {
+ $a=FormatString($p_search);
+ $sql="select * from vw_fiche_attr where frd_id=".$p_frd_id.
+ " and vw_name ~* '$p_search'";
+ }
- if ( $a['account_auto'] == 't' )
- $msg.="".$label->input()." "._("Rappel: Poste créé automatiquement à partir de ").$f->class_base." ";
- else
- {
- // if there is a class base in fiche_def_ref, this account will be the
- // the default one
- if ( strlen(trim($f->class_base)) != 0 )
- {
- $msg.="".$label->input()." "._("Rappel: Poste par défaut sera ").
- $f->class_base.
- " ! ";
- $w->value=$f->class_base;
- }
+ $Ret=$this->cn->exec_sql($sql.$p_sql);
- }
- $r.="".td("Poste Comptable",' class="input_text" ' ).td($w->input())."$msg ";
- continue;
- }
- elseif ( $attr->ad_id == ATTR_DEF_TVA)
- {
- $w=new ITva_Popup('popup_tva');
- $w->table=1;
- }
- elseif ( $attr->ad_id == ATTR_DEF_COMPANY )
- {
- $w=new ICard("av_text".$attr->ad_id);
- // filter on frd_id
- $sql=' select fd_id from fiche_def where frd_id in ('.FICHE_TYPE_CLIENT.','.FICHE_TYPE_FOURNISSEUR.','.FICHE_TYPE_ADM_TAX.')';
- $filter=$this->cn->make_list($sql);
- $w->set_attribute('ipopup','ipopcard');
- $w->set_attribute('typecard',$filter);
- $w->set_attribute('inp',"av_text".$attr->ad_id);
- $w->set_attribute('label',"av_text".$attr->ad_id."_label");
-
- $w->extra=$filter;
- $w->extra2=0;
- $label=new ISpan();
- $label->name="av_text".$attr->ad_id."_label";
- $msg.=td($w->search().$label->input());
-
-
- }
- else
- {
- switch ($attr->ad_type) {
- case 'text':
- $w=new IText();
- $w->size=$attr->ad_size;
- break;
- case 'numeric':
- $w=new INum();
- $w->size=$attr->ad_size;
- break;
- case 'date':
- $w=new IDate();
- break;
- case 'zone':
- $w=new ITextArea();
- $w->width=$attr->ad_size;
- $w->heigh=2;
- break;
- }
- $w->table=0;
-
- }
- $w->table=$table;
- $w->label=$attr->ad_text;
- $w->name="av_text".$attr->ad_id;
-
- $r.="".td($w->label,' class="input_text" ').td($w->input())."$msg ";
- }
- $r.= '
';
- return $r;
+ return Database::num_row($Ret) ;
}
-
-
-/*!
- * \brief Display object instance, getAttribute
- * sort the attribute and add missing ones
- * \param $p_readonly true= if can not modify, otherwise false
- *
- *
- * \return string to display
- */
- function Display($p_readonly)
+ /*!
+ **************************************************
+ * \brief Return array of card from the frd family
+ *
+ *
+ * \param $p_frd_id the fiche_def_ref.frd_id
+ * \param $p_offset
+ * \param $p_search is an optional filter
+ *\param $p_order : possible values are name, f_id
+ * \return array of fiche object
+ */
+ function GetByDef($p_frd_id,$p_offset=-1,$p_search="",$p_order='')
{
- $this->GetAttribut();
- $attr=$this->attribut;
+ switch($p_order)
+ {
+ case 'name' :
+ $order=' order by name';
+ break;
+ case 'f_id':
+ $order='order by f_id';
+ break;
+ default:
+ $order='';
+ }
+ if ( $p_offset == -1 )
+ {
+ $sql="select *
+ from
+ fiche join fiche_Def using (fd_id) join vw_fiche_name using(f_id)
+ where frd_id=".$p_frd_id." $p_search ".$order;
+ }
+ else
+ {
+ $limit=($_SESSION['g_pagesize']!=-1)?"limit ".$_SESSION['g_pagesize']:"";
+ $sql="select *
+ from
+ fiche join fiche_Def using (fd_id) join vw_fiche_name using(f_id)
+ where frd_id=".$p_frd_id." $p_search $order "
+ .$limit." offset ".$p_offset;
- $ret="";
- if ( empty ($attr) ) {
- return "Fiche non trouvée";
- }
+ }
- foreach ( $attr as $r)
- {
- $msg="";
- $bulle="";
- if ( $p_readonly)
- {
- $w=new IText();
- $w->table=1;
- $w->readOnly=true;
+ $Ret=$this->cn->exec_sql($sql);
+ if ( ($Max=Database::num_row($Ret)) == 0 )
+ return ;
+ $all[0]=new Fiche($this->cn);
- }
- if ($p_readonly==false)
- {
+ for ($i=0;$i<$Max;$i++)
+ {
+ $row=Database::fetch_array($Ret,$i);
+ $t=new Fiche($this->cn,$row['f_id']);
+ $t->getAttribut();
+ $all[$i]=$t;
- if ( $r->ad_id == ATTR_DEF_ACCOUNT)
- {
- $w=new IPoste("av_text".$r->ad_id);
- $w->set_attribute('ipopup','ipop_account');
- $w->set_attribute('account',"av_text".$r->ad_id);
- // account created automatically
- $w->table=1;
- // account created automatically
- $sql="select account_auto($this->fiche_def)";
- $ret_sql=$this->cn->exec_sql($sql);
- $a=Database::fetch_array($ret_sql,0);
- $bulle=HtmlInput::infobulle(10);
-
- if ( $a['account_auto'] == 't' )
- $bulle.=HtmlInput::warnbulle(11);
-
- }
- elseif ( $r->ad_id == ATTR_DEF_TVA)
- {
- $w=new ITva_Popup('popup_tva');
- $w->table=1;
-
- }
- elseif ( $r->ad_id == ATTR_DEF_COMPANY )
- {
- $w=new ICard("av_text".$r->ad_id);
- // filter on frd_id
- $sql=' select fd_id from fiche_def where frd_id in ('.FICHE_TYPE_CLIENT.','.FICHE_TYPE_FOURNISSEUR.','.FICHE_TYPE_ADM_TAX.')';
- $filter=$this->cn->make_list($sql);
- $w->extra=$filter;
- $w->extra2=0;
- $label=new ISpan();
- $label->name="av_text".$r->ad_id."_label";
- $w->set_attribute('ipopup','ipopcard');
- $w->set_attribute('typecard',$filter);
- $w->set_attribute('inp',"av_text".$r->ad_id);
- $w->set_attribute('label',"av_text".$r->ad_id."_label");
-
-
- $msg=$w->search();
- $msg.=$label->input();
-
-
- }
-
- else
- {
- switch ($r->ad_type) {
- case 'text':
- $w=new IText('av_text'.$r->ad_id);
- $w->size=$r->ad_size;
- break;
- case 'numeric':
- $w=new INum('av_text'.$r->ad_id);
- $w->size=$r->ad_size;
- break;
- case 'date':
- $w=new IDate('av_text'.$r->ad_id);
- break;
- case 'zone':
- $w=new ITextArea('av_text'.$r->ad_id);
- $w->width=$r->ad_size;
- $w->heigh=2;
- break;
- default:
- var_dump($r);
- throw new Exception("Type invalide");
- }
- $w->table=0;
- }
- }
- $w->value=$r->av_text;
- $w->name="av_text".$r->ad_id;
- $w->readonly=$p_readonly;
-
-
- $ret.="".td($r->ad_text.$bulle).td($w->input()).td($msg)." ";
- }
-
- $ret.="
";
-
- return $ret;
+ }
+ return $all;
}
- /*!
- * \brief Save a card, call insert or update
- *
- * \param p_fiche_def (default 0)
- */
- function Save($p_fiche_def=0)
- {
- // new card or only a update ?
- if ( $this->id == 0 )
- $this->insert($p_fiche_def);
- else
- $this->update();
+ function ShowTable()
+ {
+ echo " ".
+ $this->id." ".
+ " ".
+ $this->attribut_value." ".
+ " ".
+ $this->attribut_def." ";
}
-/*!
- * \brief insert a new record
- *
- * \param $p_fiche_def fiche_def.fd_id
- * \param $p_array is the array containing the data
- *\param $transation if we want to manage the transaction in this function
- * true for small insert and false for a larger loading, the BEGIN / COMMIT sql
- * must be done into the caller
- av_textX where X is the ad_id
- *\verb
-example
-av_text1=>'name'
-\endverb
- */
- function insert($p_fiche_def,$p_array=null,$transaction=true)
- {
- if ( $p_array == null)
- $p_array=$_POST;
+ /*!
+ **************************************************
+ * \brief return the string of the given attribute
+ * (attr_def.ad_id)
+ * \param $p_ad_id the AD_ID from attr_def.ad_id
+ * \see constant.php
+ * \return string
+ */
+ function strAttribut($p_ad_id)
+ {
+ if ( sizeof ($this->attribut) == 0 )
+ {
- $fiche_id=$this->cn->get_next_seq('s_fiche');
- $this->id=$fiche_id;
- // first we create the card
- if ( $transaction) $this->cn->start();
- try
- {
- $sql=sprintf("insert into fiche(f_id,fd_id)".
- " values (%d,%d)",
- $fiche_id,$p_fiche_def);
- $Ret=$this->cn->exec_sql($sql);
- // parse the $p_array array
- foreach ($p_array as $name=>$value )
- {
- /* avoid the button for searching an accounting item */
- if ( $name=='av_text5_bt') continue;
- list ($id) = sscanf ($name,"av_text%d");
- if ( $id == null ) continue;
+ if ($this->id==0) return NOTFOUND;
+ // object is not in memory we need to look into the database
+ $sql="select av_text from attr_value join jnt_fic_att_value using(jft_id)
+ where f_id=".FormatString($this->id)." and ad_id=".$p_ad_id;
+ $Res=$this->cn->exec_sql($sql);
+ $row=Database::fetch_all($Res);
+ // if not found return error
+ if ( $row == false )
+ return NOTFOUND;
- // Special traitement
- // quickcode
- if ( $id == ATTR_DEF_QUICKCODE)
- {
- $sql=sprintf("select insert_quick_code(%d,'%s')",
- $fiche_id,FormatString($value));
- $this->cn->exec_sql($sql);
- continue;
- }
- // name
- if ( $id == ATTR_DEF_NAME )
- {
- if ( strlen(trim($value)) == 0 )
- $value="pas de nom";
+ return $row[0]['av_text'];
+ }
- }
- // account
- if ( $id == ATTR_DEF_ACCOUNT )
- {
- $v=FormatString($value);
- try {
+ foreach ($this->attribut as $e)
+ {
+ if ( $e->ad_id == $p_ad_id )
+ return $e->av_text;
+ }
+ return NOTFOUND;
+ }
+ /*!\brief make an array of attributes of the category of card (FICHE_DEF.FD_ID)
+ *The array can be used with the function insert, it will return a struct like this :
+ * in the first key (av_textX), X is the ATTR_DEF::AD_ID
+ \verbatim
+ Example
+ Array
+ (
+ [av_text1] => Nom
+ [av_text12] => Personne de contact
+ [av_text5] => Poste Comptable
+ [av_text13] => numéro de tva
+ [av_text14] => Adresse
+ [av_text15] => code postal
+ [av_text24] => Ville
+ [av_text16] => pays
+ [av_text17] => téléphone
+ [av_text18] => email
+ [av_text23] => Quick Code
+ )
- if (isNumber($v) == 1 || strpos($v,',') != 0)
- {
- $parameter=array($this->id,$v);
- }
- else
- {
- $parameter=array($this->id,null);
- }
- $this->cn->exec_sql("select account_insert($1,$2)",$parameter);
- } catch (Exception $e) {
- throw new Exception ("Erreur : ce compte [$v] n'a pas de compte parent.".
- "L'opération est annulée",
- 1);
- }
- continue;
- }
- // TVA
- if ( $id == ATTR_DEF_TVA )
- {
- // Verify if the rate exists, if not then do not update
- if ( strlen(trim($value)) != 0 )
- {
- if ( isNumber($value) == 0 ) continue;
- if ( $this->cn->count_sql("select * from tva_rate where tva_id=".$value) == 0)
- {
- continue;
- }
- }
- }
- // The contact has a company attribut
- if ( $id == ATTR_DEF_COMPANY )
- {
- $exist=$this->cn->count_sql("select f_id from fiche join fiche_def using (fd_id) ".
- " join jnt_fic_att_value using (f_id) join attr_value using (jft_id) ".
- " where frd_id in (8,9,14) and ad_id=".ATTR_DEF_QUICKCODE.
- " and av_text='".FormatString($value)."'");
- if ( $exist == 0 && FormatString($value) != null )
- {
- $value="";
- }
- }
- // Normal traitement
- $value2=FormatString($value);
+ \endverbatim
+ *\param $pfd_id FICHE_DEF::FD_ID
+ *\return an array of attribute
+ *\exception Exception if the cat of card doesn't exist, Exception.getCode()=1
+ *\see fiche::insert()
+ */
+ function toArray($pfd_id)
+ {
+ $sql="select 'av_text'||to_char(ad_id,'9999') as key,".
+ " ad_text ".
+ " from fiche_def join jnt_fic_attr using (fd_id)".
+ " join attr_def using (ad_id) ".
+ " where fd_id=$1 order by jnt_order";
+ $ret=$this->cn->get_array($sql,array($pfd_id));
+ if ( empty($ret)) throw new Exception(_('Cette categorie de card n\'existe pas').' '.$pfd_id,1);
+ $array=array();
+ foreach($ret as $idx=>$val)
+ {
+ $a=str_replace(' ','',$val['key']);
+ $array[$a]=$val['ad_text'];
+ }
+ return $array;
- $sql=sprintf("select attribut_insert(%d,%d,'%s')",
- $fiche_id,$id,trim($value2));
- $this->cn->exec_sql($sql);
- }
- } catch (Exception $e)
- {
- $this->cn->rollback();
- throw ($e);
- return;
- }
- if ( $transaction) $this->cn->commit();
- return;
- }
+ }
+ /*!
+ * \brief insert a new record
+ * show a blank card to be filled
+ *
+ * \param $p_fiche_def is the fiche_def.fd_id
+ *
+ * \return HTML Code
+ */
+ function blank($p_fiche_def)
+ {
+ // array = array of attribute object sorted on ad_id
+ $f=new Fiche_Def($this->cn,$p_fiche_def);
+ $f->Get();
+ $array=$f->getAttribut();
+ $r='';
+ foreach ($array as $attr)
+ {
+ $table=0;
+ $msg="";
+ if ( $attr->ad_id == ATTR_DEF_ACCOUNT)
+ {
+ $w=new IPoste("av_text".$attr->ad_id);
+ $w->set_attribute('ipopup','ipop_account');
+ $w->set_attribute('account',"av_text".$attr->ad_id);
+ // account created automatically
+ $sql="select account_auto($p_fiche_def)";
+ $ret_sql=$this->cn->exec_sql($sql);
+ $a=Database::fetch_array($ret_sql,0);
+ $label=new ISpan();
+ $label->name="av_text".$attr->ad_id."_label";
+
+ if ( $a['account_auto'] == 't' )
+ $msg.="".$label->input()." "._("Rappel: Poste créé automatiquement à partir de ").$f->class_base." ";
+ else
+ {
+ // if there is a class base in fiche_def_ref, this account will be the
+ // the default one
+ if ( strlen(trim($f->class_base)) != 0 )
+ {
+ $msg.="".$label->input()." "._("Rappel: Poste par défaut sera ").
+ $f->class_base.
+ " ! ";
+ $w->value=$f->class_base;
+ }
+
+ }
+ $r.="".td("Poste Comptable",' class="input_text" ' ).td($w->input())."$msg ";
+ continue;
+ }
+ elseif ( $attr->ad_id == ATTR_DEF_TVA)
+ {
+ $w=new ITva_Popup('popup_tva');
+ $w->table=1;
+ }
+ elseif ( $attr->ad_id == ATTR_DEF_COMPANY )
+ {
+ $w=new ICard("av_text".$attr->ad_id);
+ // filter on frd_id
+ $sql=' select fd_id from fiche_def where frd_id in ('.FICHE_TYPE_CLIENT.','.FICHE_TYPE_FOURNISSEUR.','.FICHE_TYPE_ADM_TAX.')';
+ $filter=$this->cn->make_list($sql);
+ $w->set_attribute('ipopup','ipopcard');
+ $w->set_attribute('typecard',$filter);
+ $w->set_attribute('inp',"av_text".$attr->ad_id);
+ $w->set_attribute('label',"av_text".$attr->ad_id."_label");
+
+ $w->extra=$filter;
+ $w->extra2=0;
+ $label=new ISpan();
+ $label->name="av_text".$attr->ad_id."_label";
+ $msg.=td($w->search().$label->input());
+
+
+ }
+ else
+ {
+ switch ($attr->ad_type)
+ {
+ case 'text':
+ $w=new IText();
+ $w->size=$attr->ad_size;
+ break;
+ case 'numeric':
+ $w=new INum();
+ $w->size=$attr->ad_size;
+ break;
+ case 'date':
+ $w=new IDate();
+ break;
+ case 'zone':
+ $w=new ITextArea();
+ $w->width=$attr->ad_size;
+ $w->heigh=2;
+ break;
+ }
+ $w->table=0;
+
+ }
+ $w->table=$table;
+ $w->label=$attr->ad_text;
+ $w->name="av_text".$attr->ad_id;
+
+ $r.="".td($w->label,' class="input_text" ').td($w->input())."$msg ";
+ }
+ $r.= '
';
+ return $r;
+ }
+
+
+ /*!
+ * \brief Display object instance, getAttribute
+ * sort the attribute and add missing ones
+ * \param $p_readonly true= if can not modify, otherwise false
+ *
+ *
+ * \return string to display
+ */
+ function Display($p_readonly)
+ {
+ $this->GetAttribut();
+ $attr=$this->attribut;
+
+ $ret="";
+ if ( empty ($attr) )
+ {
+ return "Fiche non trouvée";
+ }
+
+ foreach ( $attr as $r)
+ {
+ $msg="";
+ $bulle="";
+ if ( $p_readonly)
+ {
+ $w=new IText();
+ $w->table=1;
+ $w->readOnly=true;
+
+ }
+ if ($p_readonly==false)
+ {
+
+ if ( $r->ad_id == ATTR_DEF_ACCOUNT)
+ {
+ $w=new IPoste("av_text".$r->ad_id);
+ $w->set_attribute('ipopup','ipop_account');
+ $w->set_attribute('account',"av_text".$r->ad_id);
+ // account created automatically
+ $w->table=1;
+ // account created automatically
+ $sql="select account_auto($this->fiche_def)";
+ $ret_sql=$this->cn->exec_sql($sql);
+ $a=Database::fetch_array($ret_sql,0);
+ $bulle=HtmlInput::infobulle(10);
+
+ if ( $a['account_auto'] == 't' )
+ $bulle.=HtmlInput::warnbulle(11);
+
+ }
+ elseif ( $r->ad_id == ATTR_DEF_TVA)
+ {
+ $w=new ITva_Popup('popup_tva');
+ $w->table=1;
+
+ }
+ elseif ( $r->ad_id == ATTR_DEF_COMPANY )
+ {
+ $w=new ICard("av_text".$r->ad_id);
+ // filter on frd_id
+ $sql=' select fd_id from fiche_def where frd_id in ('.FICHE_TYPE_CLIENT.','.FICHE_TYPE_FOURNISSEUR.','.FICHE_TYPE_ADM_TAX.')';
+ $filter=$this->cn->make_list($sql);
+ $w->extra=$filter;
+ $w->extra2=0;
+ $label=new ISpan();
+ $label->name="av_text".$r->ad_id."_label";
+ $w->set_attribute('ipopup','ipopcard');
+ $w->set_attribute('typecard',$filter);
+ $w->set_attribute('inp',"av_text".$r->ad_id);
+ $w->set_attribute('label',"av_text".$r->ad_id."_label");
+
+
+ $msg=$w->search();
+ $msg.=$label->input();
+
+
+ }
+
+ else
+ {
+ switch ($r->ad_type)
+ {
+ case 'text':
+ $w=new IText('av_text'.$r->ad_id);
+ $w->size=$r->ad_size;
+ break;
+ case 'numeric':
+ $w=new INum('av_text'.$r->ad_id);
+ $w->size=$r->ad_size;
+ break;
+ case 'date':
+ $w=new IDate('av_text'.$r->ad_id);
+ break;
+ case 'zone':
+ $w=new ITextArea('av_text'.$r->ad_id);
+ $w->width=$r->ad_size;
+ $w->heigh=2;
+ break;
+ default:
+ var_dump($r);
+ throw new Exception("Type invalide");
+ }
+ $w->table=0;
+ }
+ }
+ $w->value=$r->av_text;
+ $w->name="av_text".$r->ad_id;
+ $w->readonly=$p_readonly;
+
+
+ $ret.="".td($r->ad_text.$bulle).td($w->input()).td($msg)." ";
+ }
+
+ $ret.="
";
+
+ return $ret;
+ }
+ /*!
+ * \brief Save a card, call insert or update
+ *
+ * \param p_fiche_def (default 0)
+ */
+ function Save($p_fiche_def=0)
+ {
+ // new card or only a update ?
+ if ( $this->id == 0 )
+ $this->insert($p_fiche_def);
+ else
+ $this->update();
+ }
+ /*!
+ * \brief insert a new record
+ *
+ * \param $p_fiche_def fiche_def.fd_id
+ * \param $p_array is the array containing the data
+ *\param $transation if we want to manage the transaction in this function
+ * true for small insert and false for a larger loading, the BEGIN / COMMIT sql
+ * must be done into the caller
+ av_textX where X is the ad_id
+ *\verb
+ example
+ av_text1=>'name'
+ \endverb
+ */
+ function insert($p_fiche_def,$p_array=null,$transaction=true)
+ {
+ if ( $p_array == null)
+ $p_array=$_POST;
+
+ $fiche_id=$this->cn->get_next_seq('s_fiche');
+ $this->id=$fiche_id;
+ // first we create the card
+ if ( $transaction) $this->cn->start();
+ try
+ {
+ $sql=sprintf("insert into fiche(f_id,fd_id)".
+ " values (%d,%d)",
+ $fiche_id,$p_fiche_def);
+ $Ret=$this->cn->exec_sql($sql);
+ // parse the $p_array array
+ foreach ($p_array as $name=>$value )
+ {
+ /* avoid the button for searching an accounting item */
+ if ( $name=='av_text5_bt') continue;
+ list ($id) = sscanf ($name,"av_text%d");
+ if ( $id == null ) continue;
+
+ // Special traitement
+ // quickcode
+ if ( $id == ATTR_DEF_QUICKCODE)
+ {
+ $sql=sprintf("select insert_quick_code(%d,'%s')",
+ $fiche_id,FormatString($value));
+ $this->cn->exec_sql($sql);
+ continue;
+ }
+ // name
+ if ( $id == ATTR_DEF_NAME )
+ {
+ if ( strlen(trim($value)) == 0 )
+ $value="pas de nom";
+
+ }
+ // account
+ if ( $id == ATTR_DEF_ACCOUNT )
+ {
+ $v=FormatString($value);
+ try
+ {
+
+ if (isNumber($v) == 1 || strpos($v,',') != 0)
+ {
+ $parameter=array($this->id,$v);
+ }
+ else
+ {
+ $parameter=array($this->id,null);
+ }
+ $this->cn->exec_sql("select account_insert($1,$2)",$parameter);
+ }
+ catch (Exception $e)
+ {
+ throw new Exception ("Erreur : ce compte [$v] n'a pas de compte parent.".
+ "L'opération est annulée",
+ 1);
+ }
+ continue;
+ }
+ // TVA
+ if ( $id == ATTR_DEF_TVA )
+ {
+ // Verify if the rate exists, if not then do not update
+ if ( strlen(trim($value)) != 0 )
+ {
+ if ( isNumber($value) == 0 ) continue;
+ if ( $this->cn->count_sql("select * from tva_rate where tva_id=".$value) == 0)
+ {
+ continue;
+ }
+ }
+ }
+ // The contact has a company attribut
+ if ( $id == ATTR_DEF_COMPANY )
+ {
+ $exist=$this->cn->count_sql("select f_id from fiche join fiche_def using (fd_id) ".
+ " join jnt_fic_att_value using (f_id) join attr_value using (jft_id) ".
+ " where frd_id in (8,9,14) and ad_id=".ATTR_DEF_QUICKCODE.
+ " and av_text='".FormatString($value)."'");
+ if ( $exist == 0 && FormatString($value) != null )
+ {
+ $value="";
+ }
+ }
+ // Normal traitement
+ $value2=FormatString($value);
+
+ $sql=sprintf("select attribut_insert(%d,%d,'%s')",
+ $fiche_id,$id,trim($value2));
+ $this->cn->exec_sql($sql);
+ }
+ }
+ catch (Exception $e)
+ {
+ $this->cn->rollback();
+ throw ($e);
+ return;
+ }
+ if ( $transaction) $this->cn->commit();
+ return;
+ }
- /*!\brief update a card
- */
- function update($p_array=null)
- {
- if ( $p_array == null)
- $p_array=$_POST;
+ /*!\brief update a card
+ */
+ function update($p_array=null)
+ {
+ if ( $p_array == null)
+ $p_array=$_POST;
- try {
- $this->cn->start();
- // parse the $p_array array
- foreach ($p_array as $name=>$value )
- {
- list ($id) = sscanf ($name,"av_text%d");
- if ( $id == null ) continue;
+ try
+ {
+ $this->cn->start();
+ // parse the $p_array array
+ foreach ($p_array as $name=>$value )
+ {
+ list ($id) = sscanf ($name,"av_text%d");
+ if ( $id == null ) continue;
- // retrieve jft_id to update table attr_value
- $sql=" select jft_id from jnt_fic_att_value where ad_id=$id and f_id=$this->id";
- $Ret=$this->cn->exec_sql($sql);
- if ( Database::num_row($Ret) != 1 ) {
- // we need to insert this new attribut
- $jft_id=$this->cn->get_next_seq('s_jnt_fic_att_value');
+ // retrieve jft_id to update table attr_value
+ $sql=" select jft_id from jnt_fic_att_value where ad_id=$id and f_id=$this->id";
+ $Ret=$this->cn->exec_sql($sql);
+ if ( Database::num_row($Ret) != 1 )
+ {
+ // we need to insert this new attribut
+ $jft_id=$this->cn->get_next_seq('s_jnt_fic_att_value');
- $sql2=sprintf("insert into jnt_fic_att_value(jft_id,ad_id,f_id) values (%s,%s,%s)",
- $jft_id,$id,$this->id);
+ $sql2=sprintf("insert into jnt_fic_att_value(jft_id,ad_id,f_id) values (%s,%s,%s)",
+ $jft_id,$id,$this->id);
- $ret2=$this->cn->exec_sql($sql2);
- // insert a null value for this attribut
- $sql3=sprintf("insert into attr_value(jft_id,av_text) values (%s,null)",
- $jft_id);
- $ret3=$this->cn->exec_sql($sql3);
- } else
- {
- $tmp=Database::fetch_array($Ret,0);
- $jft_id=$tmp['jft_id'];
- }
- // Special traitement
- // quickcode
- if ( $id == ATTR_DEF_QUICKCODE)
- {
- $sql=sprintf("select update_quick_code(%d,'%s')",
- $jft_id,FormatString($value));
- $this->cn->exec_sql($sql);
- continue;
- }
- // name
- if ( $id == ATTR_DEF_NAME )
- {
- if ( strlen(trim($value)) == 0 )
- continue;
+ $ret2=$this->cn->exec_sql($sql2);
+ // insert a null value for this attribut
+ $sql3=sprintf("insert into attr_value(jft_id,av_text) values (%s,null)",
+ $jft_id);
+ $ret3=$this->cn->exec_sql($sql3);
+ }
+ else
+ {
+ $tmp=Database::fetch_array($Ret,0);
+ $jft_id=$tmp['jft_id'];
+ }
+ // Special traitement
+ // quickcode
+ if ( $id == ATTR_DEF_QUICKCODE)
+ {
+ $sql=sprintf("select update_quick_code(%d,'%s')",
+ $jft_id,FormatString($value));
+ $this->cn->exec_sql($sql);
+ continue;
+ }
+ // name
+ if ( $id == ATTR_DEF_NAME )
+ {
+ if ( strlen(trim($value)) == 0 )
+ continue;
- }
- if ( $id == ATTR_DEF_STOCK ) {
- $st=$this->cn->count_sql('select * from stock_goods where '.
- " f_id=".$this->id);
- if ( $st == 0 ) {
- $user=new User($this->cn);
- $exercice=$user->get_exercice();
- if ( $exercice == 0 ) throw new Exception ('Annee invalide erreur');
+ }
+ if ( $id == ATTR_DEF_STOCK )
+ {
+ $st=$this->cn->count_sql('select * from stock_goods where '.
+ " f_id=".$this->id);
+ if ( $st == 0 )
+ {
+ $user=new User($this->cn);
+ $exercice=$user->get_exercice();
+ if ( $exercice == 0 ) throw new Exception ('Annee invalide erreur');
- $str_stock=sprintf('insert into stock_goods(f_id,sg_quantity,sg_comment,sg_code,sg_type,sg_exercice) '.
- ' values (%d,0,\'%s\',upper(\'%s\'),\'d\',\'%s\')',
- $this->id,
- 'initial',
- FormatString($value),
- $exercice);
+ $str_stock=sprintf('insert into stock_goods(f_id,sg_quantity,sg_comment,sg_code,sg_type,sg_exercice) '.
+ ' values (%d,0,\'%s\',upper(\'%s\'),\'d\',\'%s\')',
+ $this->id,
+ 'initial',
+ FormatString($value),
+ $exercice);
- $this->cn->exec_sql($str_stock);
- }else {
- $str_stock=sprintf("update stock_goods set sg_code=upper('%s') where f_id=%d",
- FormatString($value),
- $this->id);
- $this->cn->exec_sql($str_stock);
- }
- }
+ $this->cn->exec_sql($str_stock);
+ }
+ else
+ {
+ $str_stock=sprintf("update stock_goods set sg_code=upper('%s') where f_id=%d",
+ FormatString($value),
+ $this->id);
+ $this->cn->exec_sql($str_stock);
+ }
+ }
- // account
- if ( $id == ATTR_DEF_ACCOUNT )
- {
- $v=FormatString($value);
- if ( isNumber($v) == 1 || strpos($v,',') != 0 )
- {
- $sql=sprintf("select account_update(%d,'%s')",
- $this->id,$v);
- try {
- $this->cn->exec_sql($sql);
- } catch (Exception $e) {
- throw new Exception(__LINE__."Erreur : ce compte [$v] n'a pas de compte parent.".
- "L'opération est annulée");
- }
- continue;
- }
- if ( strlen (trim($v)) == 0 )
- {
+ // account
+ if ( $id == ATTR_DEF_ACCOUNT )
+ {
+ $v=FormatString($value);
+ if ( isNumber($v) == 1 || strpos($v,',') != 0 )
+ {
+ $sql=sprintf("select account_update(%d,'%s')",
+ $this->id,$v);
+ try
+ {
+ $this->cn->exec_sql($sql);
+ }
+ catch (Exception $e)
+ {
+ throw new Exception(__LINE__."Erreur : ce compte [$v] n'a pas de compte parent.".
+ "L'opération est annulée");
+ }
+ continue;
+ }
+ if ( strlen (trim($v)) == 0 )
+ {
- $sql=sprintf("select account_update(%d,null)",
- $this->id);
- try {
- $Ret=$this->cn->exec_sql($sql);
- /* update also the jrnx */
+ $sql=sprintf("select account_update(%d,null)",
+ $this->id);
+ try
+ {
+ $Ret=$this->cn->exec_sql($sql);
+ /* update also the jrnx */
- /* The jrnx CANNOT BE UPDATED
- $sql='update jrnx set j_poste=$1 where j_qcode in (select quick_code from vw_fiche_attr where f_id=$2)';
- $this->cn->exec_sql(
- $sql,
- array($v,$this->id));
- */
- } catch (Exception $e) {
- throw new Exception(__LINE__."Erreur : ce compte [$v] n'a pas de compte parent.".
- "L'opération est annulée");
- }
+ /* The jrnx CANNOT BE UPDATED
+ $sql='update jrnx set j_poste=$1 where j_qcode in (select quick_code from vw_fiche_attr where f_id=$2)';
+ $this->cn->exec_sql(
+ $sql,
+ array($v,$this->id));
+ */
+ }
+ catch (Exception $e)
+ {
+ throw new Exception(__LINE__."Erreur : ce compte [$v] n'a pas de compte parent.".
+ "L'opération est annulée");
+ }
- continue;
- }
- }
- // TVA
- if ( $id == ATTR_DEF_TVA )
- {
- // Verify if the rate exists, if not then do not update
- if ( strlen(trim($value)) != 0 )
- {
- if ( $this->cn->count_sql("select * from tva_rate where tva_id=".$value) == 0)
- {
- continue;
- }
- }
- }
- if ( $id == ATTR_DEF_COMPANY )
- {
- $exist=$this->cn->count_sql("select f_id from fiche join fiche_def using (fd_id) ".
- " join jnt_fic_att_value using (f_id) join attr_value using (jft_id) ".
- " where frd_id in (8,9,14) and ad_id=".ATTR_DEF_QUICKCODE.
- " and av_text='".FormatString($value)."'");
+ continue;
+ }
+ }
+ // TVA
+ if ( $id == ATTR_DEF_TVA )
+ {
+ // Verify if the rate exists, if not then do not update
+ if ( strlen(trim($value)) != 0 )
+ {
+ if ( $this->cn->count_sql("select * from tva_rate where tva_id=".$value) == 0)
+ {
+ continue;
+ }
+ }
+ }
+ if ( $id == ATTR_DEF_COMPANY )
+ {
+ $exist=$this->cn->count_sql("select f_id from fiche join fiche_def using (fd_id) ".
+ " join jnt_fic_att_value using (f_id) join attr_value using (jft_id) ".
+ " where frd_id in (8,9,14) and ad_id=".ATTR_DEF_QUICKCODE.
+ " and av_text='".FormatString($value)."'");
- if ( $exist == 0 && FormatString($value) != null )
- {
- $value="Attention : pas de société ";
- }
- }
+ if ( $exist == 0 && FormatString($value) != null )
+ {
+ $value="Attention : pas de société ";
+ }
+ }
- // Normal traitement
- $value2=FormatString($value);
- $sql=sprintf("update attr_value set av_text='%s' where jft_id=%d",
- trim($value2),$jft_id);
- $this->cn->exec_sql($sql);
- }
- } catch (Exception $e ) {
- echo ''.
- $e->getMessage().
- ' ';
- $this->cn->rollback();
- return;
- }
- $this->cn->commit();
- return;
+ // Normal traitement
+ $value2=FormatString($value);
+ $sql=sprintf("update attr_value set av_text='%s' where jft_id=%d",
+ trim($value2),$jft_id);
+ $this->cn->exec_sql($sql);
+ }
+ }
+ catch (Exception $e )
+ {
+ echo ''.
+ $e->getMessage().
+ ' ';
+ $this->cn->rollback();
+ return;
+ }
+ $this->cn->commit();
+ return;
- }
- /*!\brief remove a card
- */
- function remove()
- {
- if ( $this->id==0 ) return;
- // verify if that card has not been used is a ledger
- // if the card has its own account in PCMN
- // Get the fiche_def.fd_id from fiche.f_id
- $this->Get();
- $fiche_def=new Fiche_Def($this->cn,$this->fiche_def);
- $fiche_def->Get();
-
- // if the card is used do not removed it
- $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
-
- if ( $this->cn->count_sql("select * from jrnx where j_qcode='".Database::escape_string($qcode)."'") != 0)
- {
- alert('Impossible cette fiche est utilisée dans un journal');
- return;
- }
-
- $this->delete();
- }
-
-
- /*!\brief return the name of a card
- *
+ }
+ /*!\brief remove a card
*/
- function getName()
- {
- $sql="select av_text from jnt_fic_att_value join attr_value
- using (jft_id) where ad_id=1 and f_id=".$this->id;
- $Res=$this->cn->exec_sql($sql);
- $r=Database::fetch_all($Res);
- if ( sizeof($r) == 0 )
- return 1;
- return $r[0]['av_text'];
- }
-
- /*!\brief return the quick_code of a card
- * \return null if not quick_code is found
- */
- function get_quick_code()
- {
- $sql="select av_text from jnt_fic_att_value join attr_value
- using (jft_id) where ad_id=23 and f_id=".$this->id;
- $Res=$this->cn->exec_sql($sql);
- $r=Database::fetch_all($Res);
- if ( sizeof($r) == 0 )
- return null;
- return $r[0]['av_text'];
- }
-
- /*!\brief Synonum of fiche::getAttribut
- */
- function Get()
- {
- $this->getAttribut();
- }
- /*!\brief get all the card thanks the fiche_def_ref
- * \param $p_offset (default =-1)
- * \param $p_search sql condition
- * \return array of fiche object
- */
- function GetAll($p_offset=-1,$p_search="",$p_order='')
- {
- return fiche::GetByDef($this->fiche_def_ref,$p_offset,$p_search,$p_order);
- }
- /*!\brief retrieve the frd_id of the fiche it is the type of the
- * card (bank, purchase...)
- * (fiche_def_ref primary key)
- */
- function get_fiche_def_ref_id()
+ function remove()
{
- $result=$this->cn->get_array("select frd_id from fiche join fiche_Def using (fd_id) where f_id=".$this->id);
- if ( $result == null )
- return null;
+ if ( $this->id==0 ) return;
+ // verify if that card has not been used is a ledger
+ // if the card has its own account in PCMN
+ // Get the fiche_def.fd_id from fiche.f_id
+ $this->Get();
+ $fiche_def=new Fiche_Def($this->cn,$this->fiche_def);
+ $fiche_def->Get();
- return $result[0]['frd_id'];
- }
- /**
- *@brief fetch and return and array
- *@see get_row get_row_date
- */
- private function get_row_result($res) {
- $array=array();
- $tot_cred=0.0;
- $tot_deb=0.0;
- $Max=Database::num_row($res);
- if ( $Max == 0 ) return null;
- for ($i=0;$i<$Max;$i++) {
- $array[]=Database::fetch_array($res,$i);
- if ($array[$i]['j_debit']=='t') {
- $tot_deb+=$array[$i]['deb_montant'] ;
- } else {
- $tot_cred+=$array[$i]['cred_montant'] ;
- }
- }
- $this->row=$array;
- return array($array,$tot_deb,$tot_cred);
- }
- /*!
- * \brief Get data for poste
- *
- * \param $p_from periode from
- * \param $p_to end periodeµ
- *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered one
- * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
- * (tot_deb,tot_credit
- *
- */
- function get_row_date($p_from,$p_to,$op_let=0)
- {
- if ( $this->id == 0 )
- {
- echo_error("class_fiche",__LINE__,"id is 0");
- return;
- }
- $user=new User($this->cn);
- $filter_sql=$user->get_ledger_sql('ALL',3);
- $sql_let='';
- switch ($op_let) {
- case 0:
- break;
- case 1:
- $sql_let=' and j_id in (select j_id from letter_cred union select j_id from letter_deb)';
- break;
- case '2':
- $sql_let=' and j_id not in (select j_id from letter_cred union select j_id from letter_deb) ';
- break;
- }
+ // if the card is used do not removed it
+ $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
- $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
- $Res=$this->cn->exec_sql("select distinct j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_qcode,".
- "case when j_debit='t' then j_montant else 0 end as deb_montant,".
- "case when j_debit='f' then j_montant else 0 end as cred_montant,".
- " jr_comment as description,jrn_def_name as jrn_name,".
- "j_debit, jr_internal,jr_id,coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter ".
- " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ".
- " left join jrn on jr_grpt_id=j_grpt".
- " where j_qcode=$1 and ".
- " ( to_date($2,'DD.MM.YYYY') <= j_date and ".
- " to_date($3,'DD.MM.YYYY') >= j_date )".
- " and $filter_sql $sql_let ".
- " order by j_date",array($qcode,$p_from,$p_to));
+ if ( $this->cn->count_sql("select * from jrnx where j_qcode='".Database::escape_string($qcode)."'") != 0)
+ {
+ alert('Impossible cette fiche est utilisée dans un journal');
+ return;
+ }
- return $this->get_row_result($Res);
+ $this->delete();
}
- /*!
- * \brief Get data for poste
- *
- * \param $p_from periode from
- * \param $p_to end periode
- * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
- * (tot_deb,tot_credit
- *
- */
- function get_row($p_from,$p_to)
- {
- if ( $this->id == 0 )
- {
- echo_error("class_fiche",__LINE__,"id is 0");
- return;
- }
- $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
- $periode=sql_filter_per($this->cn,$p_from,$p_to,'p_id','jr_tech_per');
- $Res=$this->cn->exec_sql("select j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_qcode,".
- "case when j_debit='t' then j_montant else 0 end as deb_montant,".
- "case when j_debit='f' then j_montant else 0 end as cred_montant,".
- " jr_comment as description,jrn_def_name as jrn_name,".
- "j_debit, jr_internal,jr_id ".
- " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ".
- " left join jrn on jr_grpt_id=j_grpt".
- " where j_qcode='".$qcode."' and ".$periode.
- " order by j_date::date");
- return $this->get_row_result($Res);
+ /*!\brief return the name of a card
+ *
+ */
+ function getName()
+ {
+ $sql="select av_text from jnt_fic_att_value join attr_value
+ using (jft_id) where ad_id=1 and f_id=".$this->id;
+ $Res=$this->cn->exec_sql($sql);
+ $r=Database::fetch_all($Res);
+ if ( sizeof($r) == 0 )
+ return 1;
+ return $r[0]['av_text'];
+ }
+
+ /*!\brief return the quick_code of a card
+ * \return null if not quick_code is found
+ */
+ function get_quick_code()
+ {
+ $sql="select av_text from jnt_fic_att_value join attr_value
+ using (jft_id) where ad_id=23 and f_id=".$this->id;
+ $Res=$this->cn->exec_sql($sql);
+ $r=Database::fetch_all($Res);
+ if ( sizeof($r) == 0 )
+ return null;
+ return $r[0]['av_text'];
+ }
+
+ /*!\brief Synonum of fiche::getAttribut
+ */
+ function Get()
+ {
+ $this->getAttribut();
+ }
+ /*!\brief get all the card thanks the fiche_def_ref
+ * \param $p_offset (default =-1)
+ * \param $p_search sql condition
+ * \return array of fiche object
+ */
+ function GetAll($p_offset=-1,$p_search="",$p_order='')
+ {
+ return fiche::GetByDef($this->fiche_def_ref,$p_offset,$p_search,$p_order);
+ }
+ /*!\brief retrieve the frd_id of the fiche it is the type of the
+ * card (bank, purchase...)
+ * (fiche_def_ref primary key)
+ */
+ function get_fiche_def_ref_id()
+ {
+ $result=$this->cn->get_array("select frd_id from fiche join fiche_Def using (fd_id) where f_id=".$this->id);
+ if ( $result == null )
+ return null;
+
+ return $result[0]['frd_id'];
+ }
+ /**
+ *@brief fetch and return and array
+ *@see get_row get_row_date
+ */
+ private function get_row_result($res)
+ {
+ $array=array();
+ $tot_cred=0.0;
+ $tot_deb=0.0;
+ $Max=Database::num_row($res);
+ if ( $Max == 0 ) return null;
+ for ($i=0;$i<$Max;$i++)
+ {
+ $array[]=Database::fetch_array($res,$i);
+ if ($array[$i]['j_debit']=='t')
+ {
+ $tot_deb+=$array[$i]['deb_montant'] ;
+ }
+ else
+ {
+ $tot_cred+=$array[$i]['cred_montant'] ;
+ }
+ }
+ $this->row=$array;
+ return array($array,$tot_deb,$tot_cred);
+ }
+ /*!
+ * \brief Get data for poste
+ *
+ * \param $p_from periode from
+ * \param $p_to end periodeµ
+ *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered one
+ * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
+ * (tot_deb,tot_credit
+ *
+ */
+ function get_row_date($p_from,$p_to,$op_let=0)
+ {
+ if ( $this->id == 0 )
+ {
+ echo_error("class_fiche",__LINE__,"id is 0");
+ return;
+ }
+ $user=new User($this->cn);
+ $filter_sql=$user->get_ledger_sql('ALL',3);
+ $sql_let='';
+ switch ($op_let)
+ {
+ case 0:
+ break;
+ case 1:
+ $sql_let=' and j_id in (select j_id from letter_cred union select j_id from letter_deb)';
+ break;
+ case '2':
+ $sql_let=' and j_id not in (select j_id from letter_cred union select j_id from letter_deb) ';
+ break;
+ }
+
+ $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
+ $Res=$this->cn->exec_sql("select distinct j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_qcode,".
+ "case when j_debit='t' then j_montant else 0 end as deb_montant,".
+ "case when j_debit='f' then j_montant else 0 end as cred_montant,".
+ " jr_comment as description,jrn_def_name as jrn_name,".
+ "j_debit, jr_internal,jr_id,coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter ".
+ " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ".
+ " left join jrn on jr_grpt_id=j_grpt".
+ " where j_qcode=$1 and ".
+ " ( to_date($2,'DD.MM.YYYY') <= j_date and ".
+ " to_date($3,'DD.MM.YYYY') >= j_date )".
+ " and $filter_sql $sql_let ".
+ " order by j_date",array($qcode,$p_from,$p_to));
+
+ return $this->get_row_result($Res);
+ }
+
+ /*!
+ * \brief Get data for poste
+ *
+ * \param $p_from periode from
+ * \param $p_to end periode
+ * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
+ * (tot_deb,tot_credit
+ *
+ */
+ function get_row($p_from,$p_to)
+ {
+ if ( $this->id == 0 )
+ {
+ echo_error("class_fiche",__LINE__,"id is 0");
+ return;
+ }
+ $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
+ $periode=sql_filter_per($this->cn,$p_from,$p_to,'p_id','jr_tech_per');
+
+ $Res=$this->cn->exec_sql("select j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_qcode,".
+ "case when j_debit='t' then j_montant else 0 end as deb_montant,".
+ "case when j_debit='f' then j_montant else 0 end as cred_montant,".
+ " jr_comment as description,jrn_def_name as jrn_name,".
+ "j_debit, jr_internal,jr_id ".
+ " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ".
+ " left join jrn on jr_grpt_id=j_grpt".
+ " where j_qcode='".$qcode."' and ".$periode.
+ " order by j_date::date");
+ return $this->get_row_result($Res);
}
- /*!
- * \brief HtmlTable, display a HTML of a card for the asked period
- *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered one
- * \return none
- */
- function HtmlTableDetail($p_array=null,$op_let=0)
+ /*!
+ * \brief HtmlTable, display a HTML of a card for the asked period
+ *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered one
+ * \return none
+ */
+ function HtmlTableDetail($p_array=null,$op_let=0)
{
- if ( $p_array == null)
- $p_array=$_REQUEST;
+ if ( $p_array == null)
+ $p_array=$_REQUEST;
- $name=$this->getName();
+ $name=$this->getName();
- list($array,$tot_deb,$tot_cred)=$this->get_row_date( $p_array['from_periode'],
- $p_array['to_periode'],
- $op_let
- );
+ list($array,$tot_deb,$tot_cred)=$this->get_row_date( $p_array['from_periode'],
+ $p_array['to_periode'],
+ $op_let
+ );
- if ( count($this->row ) == 0 )
- return;
- $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
+ if ( count($this->row ) == 0 )
+ return;
+ $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
- $rep="";
- $already_seen=array();
- echo ''.$this->id." ".$name.' ';
- echo "";
- echo "".
- " Code interne ".
- " Date ".
- " Description ".
- " Montant ".
- " Débit/Crédit ".
- " ";
+ $rep="";
+ $already_seen=array();
+ echo ''.$this->id." ".$name.' ';
+ echo "";
+ echo "".
+ " Code interne ".
+ " Date ".
+ " Description ".
+ " Montant ".
+ " Débit/Crédit ".
+ " ";
- foreach ( $this->row as $op ) {
- if ( in_array($op['jr_internal'],$already_seen) )
- continue;
- else
- $already_seen[]=$op['jr_internal'];
- echo "".
- "".$op['jr_internal']." ".
- "".$op['j_date']." ".
- "".h($op['description'])." ".
- ""." ".
- ""." ".
- " ";
- $ac=new Acc_Operation($this->cn);
- $ac->jr_id=$op['jr_id'];
- $ac->qcode=$qcode;
- echo $ac->display_jrnx_detail(1);
+ foreach ( $this->row as $op )
+ {
+ if ( in_array($op['jr_internal'],$already_seen) )
+ continue;
+ else
+ $already_seen[]=$op['jr_internal'];
+ echo "".
+ "".$op['jr_internal']." ".
+ "".$op['j_date']." ".
+ "".h($op['description'])." ".
+ ""." ".
+ ""." ".
+ " ";
+ $ac=new Acc_Operation($this->cn);
+ $ac->jr_id=$op['jr_id'];
+ $ac->qcode=$qcode;
+ echo $ac->display_jrnx_detail(1);
- }
- $solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde créditeur";
- $diff=round(abs($tot_deb-$tot_cred),2);
- echo "".
- "$solde_type".
- " $diff ".
- " ".
- "$tot_deb ".
- "$tot_cred ".
- " ";
+ }
+ $solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde créditeur";
+ $diff=round(abs($tot_deb-$tot_cred),2);
+ echo "".
+ "$solde_type".
+ " $diff ".
+ " ".
+ "$tot_deb ".
+ "$tot_cred ".
+ " ";
- echo "
";
+ echo "
";
- return;
+ return;
}
- /*!
- * \brief HtmlTable, display a HTML of a card for the asked period
- * \param $p_array default = null keys = from_periode, to_periode
- */
- function HtmlTable($p_array=null,$op_let=0)
+ /*!
+ * \brief HtmlTable, display a HTML of a card for the asked period
+ * \param $p_array default = null keys = from_periode, to_periode
+ */
+ function HtmlTable($p_array=null,$op_let=0)
{
- if ( $p_array == null)
- $p_array=$_REQUEST;
- $progress=0;
- $name=h($this->getName()).'['.$this->strAttribut(ATTR_DEF_QUICKCODE).']';
+ if ( $p_array == null)
+ $p_array=$_REQUEST;
+ $progress=0;
+ $name=h($this->getName()).'['.$this->strAttribut(ATTR_DEF_QUICKCODE).']';
- list($array,$tot_deb,$tot_cred)=$this->get_row_date( $p_array['from_periode'],
- $p_array['to_periode'],
- $op_let
- );
+ list($array,$tot_deb,$tot_cred)=$this->get_row_date( $p_array['from_periode'],
+ $p_array['to_periode'],
+ $op_let
+ );
- if ( count($this->row ) == 0 )
- return;
+ if ( count($this->row ) == 0 )
+ return;
- $rep="";
+ $rep="";
- echo ''." ".$name.' ';
- echo "";
- return;
+ return;
}
- /*!
- * \brief Display HTML Table Header (button)
- *
- * \return none
- */
- function HtmlTableHeader($p_array=null)
- {
- if ( $p_array == null)
- $p_array=$_REQUEST;
+ /*!
+ * \brief Display HTML Table Header (button)
+ *
+ * \return none
+ */
+ function HtmlTableHeader($p_array=null)
+ {
+ if ( $p_array == null)
+ $p_array=$_REQUEST;
- $hid=new IHidden();
- echo '';
- echo "
";
- echo '';
+ $hid=new IHidden();
+ echo '';
+ echo "
";
+ echo '';
- echo ''.
- HtmlInput::submit('bt_other',"Autre poste").
- dossier::hidden().
- $hid->input("type","poste").$hid->input('p_action','impress')." ";
- $str_ople=(isset($_REQUEST['ople']))?HtmlInput::hidden('ople',$_REQUEST['ople']):'';
+ echo ''.
+ HtmlInput::submit('bt_other',"Autre poste").
+ dossier::hidden().
+ $hid->input("type","poste").$hid->input('p_action','impress')." ";
+ $str_ople=(isset($_REQUEST['ople']))?HtmlInput::hidden('ople',$_REQUEST['ople']):'';
- echo ''.
- HtmlInput::submit('bt_pdf',"Export PDF").
- dossier::hidden().$str_ople.
- $hid->input("type","poste").
- $hid->input('p_action','impress').
- $hid->input("f_id",$this->id).
- dossier::hidden().
- $hid->input("from_periode",$p_array['from_periode']).
- $hid->input("to_periode",$p_array['to_periode']);
- if (isset($p_array['oper_detail']))
- echo $hid->input('oper_detail','on');
+ echo ''.
+ HtmlInput::submit('bt_pdf',"Export PDF").
+ dossier::hidden().$str_ople.
+ $hid->input("type","poste").
+ $hid->input('p_action','impress').
+ $hid->input("f_id",$this->id).
+ dossier::hidden().
+ $hid->input("from_periode",$p_array['from_periode']).
+ $hid->input("to_periode",$p_array['to_periode']);
+ if (isset($p_array['oper_detail']))
+ echo $hid->input('oper_detail','on');
- echo " ";
+ echo " ";
- echo ''.
- HtmlInput::submit('bt_csv',"Export CSV").
- dossier::hidden().$str_ople.
- $hid->input("type","poste").
- $hid->input('p_action','impress').
- $hid->input("f_id",$this->id).
- $hid->input("from_periode",$p_array['from_periode']).
- $hid->input("to_periode",$p_array['to_periode']);
- if (isset($p_array['oper_detail']))
- echo $hid->input('oper_detail','on');
+ echo ''.
+ HtmlInput::submit('bt_csv',"Export CSV").
+ dossier::hidden().$str_ople.
+ $hid->input("type","poste").
+ $hid->input('p_action','impress').
+ $hid->input("f_id",$this->id).
+ $hid->input("from_periode",$p_array['from_periode']).
+ $hid->input("to_periode",$p_array['to_periode']);
+ if (isset($p_array['oper_detail']))
+ echo $hid->input('oper_detail','on');
- echo " ";
- echo "
";
- echo '
';
+ echo "";
+ echo "
";
+ echo '
';
- }
- /*!
- * \brief give the balance of an card
- * \return
- * balance of the card
- *
- */
-function get_solde_detail($p_cond="") {
- if ( $this->id == 0 ) exit('fiche->id est nul');
- $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
+ }
+ /*!
+ * \brief give the balance of an card
+ * \return
+ * balance of the card
+ *
+ */
+ function get_solde_detail($p_cond="")
+ {
+ if ( $this->id == 0 ) exit('fiche->id est nul');
+ $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
- if ( $p_cond != "") $p_cond=" and ".$p_cond;
- $Res=$this->cn->exec_sql("select sum(deb) as sum_deb, sum(cred) as sum_cred from
- ( select j_poste,
- case when j_debit='t' then j_montant else 0 end as deb,
- case when j_debit='f' then j_montant else 0 end as cred
- from jrnx
- where
- j_qcode = ('$qcode'::text)
- $p_cond
- ) as m ");
- $Max=Database::num_row($Res);
- if ($Max==0) return 0;
- $r=Database::fetch_array($Res,0);
+ if ( $p_cond != "") $p_cond=" and ".$p_cond;
+ $Res=$this->cn->exec_sql("select sum(deb) as sum_deb, sum(cred) as sum_cred from
+ ( select j_poste,
+ case when j_debit='t' then j_montant else 0 end as deb,
+ case when j_debit='f' then j_montant else 0 end as cred
+ from jrnx
+ where
+ j_qcode = ('$qcode'::text)
+ $p_cond
+ ) as m ");
+ $Max=Database::num_row($Res);
+ if ($Max==0) return 0;
+ $r=Database::fetch_array($Res,0);
- return array('debit'=>$r['sum_deb'],
- 'credit'=>$r['sum_cred'],
- 'solde'=>abs($r['sum_deb']-$r['sum_cred']));
-}
-/*!\brief check if an attribute is empty
- *\param $p_attr the id of the attribut to check (ad_id)
- *\return return true is the attribute is empty or missing
- */
-function empty_attribute($p_attr) {
- $sql="select av_text
- from jnt_fic_att_value
- natural join fiche
- natural join attr_value
- left join attr_def using (ad_id) where f_id=".$this->id.
- " and ad_id = ".$p_attr.
- " order by ad_id";
- $res=$this->cn->exec_sql($sql);
- if ( Database::num_row($res) == 0 ) return true;
- $text=Database::fetch_result($res,0,0);
- return (strlen(trim($text)) > 0)?false:true;
+ return array('debit'=>$r['sum_deb'],
+ 'credit'=>$r['sum_cred'],
+ 'solde'=>abs($r['sum_deb']-$r['sum_cred']));
+ }
+ /*!\brief check if an attribute is empty
+ *\param $p_attr the id of the attribut to check (ad_id)
+ *\return return true is the attribute is empty or missing
+ */
+ function empty_attribute($p_attr)
+ {
+ $sql="select av_text
+ from jnt_fic_att_value
+ natural join fiche
+ natural join attr_value
+ left join attr_def using (ad_id) where f_id=".$this->id.
+ " and ad_id = ".$p_attr.
+ " order by ad_id";
+ $res=$this->cn->exec_sql($sql);
+ if ( Database::num_row($res) == 0 ) return true;
+ $text=Database::fetch_result($res,0,0);
+ return (strlen(trim($text)) > 0)?false:true;
-}
-/*! Summary
- * \brief show the default screen
- *
- * \param $p_search (filter)
- * \param $p_action show the action column
- * \param $p_sql SQL to filter the number of card must start with AND
- * \param $p_amount true : only cards with at least one operation default : false
- * \return: string to display
- */
-function Summary($p_search="",$p_action="",$p_sql="",$p_amount=false)
+ }
+ /*! Summary
+ * \brief show the default screen
+ *
+ * \param $p_search (filter)
+ * \param $p_action show the action column
+ * \param $p_sql SQL to filter the number of card must start with AND
+ * \param $p_amount true : only cards with at least one operation default : false
+ * \return: string to display
+ */
+ function Summary($p_search="",$p_action="",$p_sql="",$p_amount=false)
{
- $str_dossier=dossier::get();
- $p_search=FormatString($p_search);
- $script=$_SERVER['PHP_SELF'];
- // Creation of the nav bar
- // Get the max numberRow
- $filter_amount='';
- $User=new User($this->cn);
+ $str_dossier=dossier::get();
+ $p_search=FormatString($p_search);
+ $script=$_SERVER['PHP_SELF'];
+ // Creation of the nav bar
+ // Get the max numberRow
+ $filter_amount='';
+ $User=new User($this->cn);
- $filter_year=" j_tech_per in (select p_id from parm_periode ".
+ $filter_year=" j_tech_per in (select p_id from parm_periode ".
"where p_exercice='".$User->get_exercice()."')";
- if ( $p_amount) $filter_amount=' and f_id in (select f_id from jrnx where '.$filter_year.')';
+ if ( $p_amount) $filter_amount=' and f_id in (select f_id from jrnx where '.$filter_year.')';
- $all_tiers=$this->CountByDef($this->fiche_def_ref,$p_search,$p_sql.$filter_amount);
- // Get offset and page variable
- $offset=( isset ($_REQUEST['offset'] )) ?$_REQUEST['offset']:0;
- $page=(isset($_REQUEST['page']))?$_REQUEST['page']:1;
- $bar=jrn_navigation_bar($offset,$all_tiers,$_SESSION['g_pagesize'],$page);
-
- // set a filter ?
- $search=$p_sql;
+ $all_tiers=$this->CountByDef($this->fiche_def_ref,$p_search,$p_sql.$filter_amount);
+ // Get offset and page variable
+ $offset=( isset ($_REQUEST['offset'] )) ?$_REQUEST['offset']:0;
+ $page=(isset($_REQUEST['page']))?$_REQUEST['page']:1;
+ $bar=jrn_navigation_bar($offset,$all_tiers,$_SESSION['g_pagesize'],$page);
- $user=new User($this->cn);
- $exercice=$user->get_exercice();
- $tPeriode=new Periode($this->cn);
- list($max,$min)=$tPeriode->get_limit($exercice);
+ // set a filter ?
+ $search=$p_sql;
+
+ $user=new User($this->cn);
+ $exercice=$user->get_exercice();
+ $tPeriode=new Periode($this->cn);
+ list($max,$min)=$tPeriode->get_limit($exercice);
- if ( trim($p_search) != "" )
- {
- $search.=" and f_id in
-(select f_id from jnt_fic_att_value
- join fiche using (f_id)
- join attr_value using (jft_id)
- where
- ad_id=1 and av_text ~* '$p_search')";
- }
- // Get The result Array
- $step_tiers=$this->GetAll($offset,$search.$filter_amount,'name');
+ if ( trim($p_search) != "" )
+ {
+ $search.=" and f_id in
+ (select f_id from jnt_fic_att_value
+ join fiche using (f_id)
+ join attr_value using (jft_id)
+ where
+ ad_id=1 and av_text ~* '$p_search')";
+ }
+ // Get The result Array
+ $step_tiers=$this->GetAll($offset,$search.$filter_amount,'name');
- if ( $all_tiers == 0 || count($step_tiers)==0 ) return "";
- $r=$bar;
- $r.='
-
-'._('Quick Code').'
-'._('Nom').'
-'._('Adresse').'
-'._('Total débit').'
-'._('Total crédit').'
-'._('Solde').' ';
-$r.=' ';
- if ( sizeof ($step_tiers ) == 0 )
- return $r;
+ if ( $all_tiers == 0 || count($step_tiers)==0 ) return "";
+ $r=$bar;
+ $r.='
+
+ '._('Quick Code').'
+ '._('Nom').'
+ '._('Adresse').'
+ '._('Total débit').'
+ '._('Total crédit').'
+ '._('Solde').' ';
+ $r.=' ';
+ if ( sizeof ($step_tiers ) == 0 )
+ return $r;
- $i=0;
+ $i=0;
- foreach ($step_tiers as $tiers ) {
- $i++;$odd="";
- if ($i % 2 == 0 ) $odd='class="odd"';
- /* Filter on the default year */
+ foreach ($step_tiers as $tiers )
+ {
+ $i++;
+ $odd="";
+ if ($i % 2 == 0 ) $odd='class="odd"';
+ /* Filter on the default year */
- $amount=$tiers->get_solde_detail($filter_year);
+ $amount=$tiers->get_solde_detail($filter_year);
- /* skip the tiers without operation */
- if ( $p_amount && $amount['debit']==0 && $amount['credit'] == 0 && $amount['solde'] == 0 ) continue;
+ /* skip the tiers without operation */
+ if ( $p_amount && $amount['debit']==0 && $amount['credit'] == 0 && $amount['solde'] == 0 ) continue;
- $r.="";
- $e=sprintf(' ',
- $script,$p_action,$tiers->id,$str_dossier);
+ $r.="";
+ $e=sprintf(' ',
+ $script,$p_action,$tiers->id,$str_dossier);
- $r.=" $e".$tiers->strAttribut(ATTR_DEF_QUICKCODE)." ";
- $r.="".h($tiers->strAttribut(ATTR_DEF_NAME))." ";
- $r.="".h($tiers->strAttribut(ATTR_DEF_ADRESS).
- " ".$tiers->strAttribut(ATTR_DEF_CP).
- " ".$tiers->strAttribut(ATTR_DEF_PAYS)).
- " ";
+ $r.=" $e".$tiers->strAttribut(ATTR_DEF_QUICKCODE)." ";
+ $r.="".h($tiers->strAttribut(ATTR_DEF_NAME))." ";
+ $r.="".h($tiers->strAttribut(ATTR_DEF_ADRESS).
+ " ".$tiers->strAttribut(ATTR_DEF_CP).
+ " ".$tiers->strAttribut(ATTR_DEF_PAYS)).
+ " ";
- $r.=sprintf(' %15.2f€ ',$amount['debit']);
- $r.=sprintf(' %15.2f€ ',$amount['credit']);
- $r.=sprintf(' %15.2f€ ',$amount['solde']);
+ $r.=sprintf(' %15.2f€ ',$amount['debit']);
+ $r.=sprintf(' %15.2f€ ',$amount['credit']);
+ $r.=sprintf(' %15.2f€ ',$amount['solde']);
- $r.=" ";
+ $r.=" ";
- }
- $r.="
";
- $r.=$bar;
- return $r;
+ }
+ $r.="
";
+ $r.=$bar;
+ return $r;
}
-/*!
- * \brief get the fd_id of the card : fd_id, it set the attribute fd_id
- */
- function get_categorie()
- {
- if ( $this->id == 0 ) exit('class_fiche : f_id = 0 ');
- $sql='select fd_id from fiche where f_id='.$this->id;
- $R=$this->cn->get_value($sql);
- if ( $R == "" )
- $this->fd_id=0;
- else
- $this->fd_id=$R;
- }
-/*!
- ***************************************************
- * \brief Check if a fiche is used by a jrn
- * return 1 if the fiche is in the range otherwise 0, the quick_code
- * or the id must be set
- *
- *
- * \param $p_jrn journal_id
- * \param $p_type : deb or cred default empty
- *
- * \return 1 if the fiche is in the range otherwise < 1
- * -1 the card doesn't exist
- * -2 the ledger has no card to check
- *
- */
-function belong_ledger($p_jrn,$p_type="")
-{
- // check if we have a quick_code or a f_id
- if (($this->quick_code==null || $this->quick_code == "" )
- && $this->id == 0 ) {
- echo 'erreur ni quick_code ni f_id ne sont donnes';
- exit();
- }
-
- //retrieve the quick_code
- if ( $this->quick_code=="")
- $this->quick_code=$this->get_quick_code();
-
-
- if ( $this->quick_code==null)
- return -1;
-
- if ( $this->id == 0 )
- if ( $this->get_by_qcode(null,false) == 1)
- return -1;
-
- $get="";
- if ( $p_type == 'deb' ) {
- $get='jrn_def_fiche_deb';
- }
- if ( $p_type == 'cred' ) {
- $get='jrn_def_fiche_cred';
- }
- if ( $get != "" ) {
- $Res=$this->cn->exec_sql("select $get as fiche from jrn_def where jrn_def_id=$p_jrn");
- } else {
- // Get all the fiche type (deb and cred)
- $Res=$this->cn->exec_sql(" select jrn_def_fiche_cred as fiche
- from jrn_def where jrn_def_id=$p_jrn
- union
- select jrn_def_fiche_deb
- from jrn_def where jrn_def_id=$p_jrn"
- );
- }
- $Max=Database::num_row($Res);
- if ( $Max==0) {
- return -2;
- }
- /* convert the array to a string */
- $list=Database::fetch_all($Res);
- $str_list="";
- $comma='';
- foreach ($list as $row) {
- if ( $row['fiche'] != '' ) {
- $str_list.=$comma.$row['fiche'];
- $comma=',';
+ /*!
+ * \brief get the fd_id of the card : fd_id, it set the attribute fd_id
+ */
+ function get_categorie()
+ {
+ if ( $this->id == 0 ) exit('class_fiche : f_id = 0 ');
+ $sql='select fd_id from fiche where f_id='.$this->id;
+ $R=$this->cn->get_value($sql);
+ if ( $R == "" )
+ $this->fd_id=0;
+ else
+ $this->fd_id=$R;
}
- }
- // Normally Max must be == 1
+ /*!
+ ***************************************************
+ * \brief Check if a fiche is used by a jrn
+ * return 1 if the fiche is in the range otherwise 0, the quick_code
+ * or the id must be set
+ *
+ *
+ * \param $p_jrn journal_id
+ * \param $p_type : deb or cred default empty
+ *
+ * \return 1 if the fiche is in the range otherwise < 1
+ * -1 the card doesn't exist
+ * -2 the ledger has no card to check
+ *
+ */
+ function belong_ledger($p_jrn,$p_type="")
+ {
+ // check if we have a quick_code or a f_id
+ if (($this->quick_code==null || $this->quick_code == "" )
+ && $this->id == 0 )
+ {
+ echo 'erreur ni quick_code ni f_id ne sont donnes';
+ exit();
+ }
- if ( $str_list=="") {
- return -3;
- }
+ //retrieve the quick_code
+ if ( $this->quick_code=="")
+ $this->quick_code=$this->get_quick_code();
- $sql="select *
- from fiche
- where
- fd_id in (".$str_list.") and f_id= ".$this->id;
- $Res=$this->cn->exec_sql($sql);
- $Max=Database::num_row($Res);
- if ($Max==0 )
- return 0;
- else
- return 1;
-}
-/*!\brief get all the card from a categorie
- *\param $p_cn database connx
- *\param $pFd_id is the category id
- *\param $p_order for the sort, possible values is name_asc,name_desc or nothing
- *\return an array of card, but only the fiche->id is set
- */
-static function get_fiche_def($p_cn,$pFd_id,$p_order='') {
- switch ($p_order) {
- case 'name_asc':
- $sql='select f_id from fiche join vw_fiche_name using (f_id) where fd_id=$1 order by name asc';
- break;
- case 'name_desc':
- $sql='select f_id from fiche join vw_fiche_name using (f_id) where fd_id=$1 order by name desc';
- break;
- default:
- $sql='select f_id from fiche where fd_id=$1 ';
- }
- $array=$p_cn->get_array($sql,array($pFd_id));
- if ( empty ($array) ) return null;
- foreach ($array as $ret ) {
- $r[]=new Fiche($p_cn,$ret['f_id']);
- }
- return $r;
-}
-/*!\brief check if a card is used
- *\return return true is a card is used otherwise false
- */
-function is_used() {
- /* retrieve first the quickcode */
- $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
- $sql='select count(*) as c from jrnx where j_qcode=$1';
- $count=$this->cn->get_value($sql,array($qcode));
- if ( $count == 0 ) return false;
- return true;
-}
-/*\brief remove a card without verification */
- function delete() {
- // Remove from attr_value
- $Res=$this->cn->exec_sql("delete from attr_value
- where jft_id in (select jft_id
- from jnt_fic_att_value
- natural join fiche where f_id=".$this->id.")");
- // Remove from jnt_fic_att_value
- $Res=$this->cn->exec_sql("delete from jnt_fic_att_value where f_id=".$this->id);
+ if ( $this->quick_code==null)
+ return -1;
- // Remove from fiche
- $Res=$this->cn->exec_sql("delete from fiche where f_id=".$this->id);
+ if ( $this->id == 0 )
+ if ( $this->get_by_qcode(null,false) == 1)
+ return -1;
-}
- /*!\brief create the sql statement for retrieving all
- * the card
- *\return string with sql statement
- *\param $array contains the condition
-\verbatim
- [jrn] => 2
- [typecard] => cred / deb / filter or list
- [query] => string
-\endverbatim
- *\note the typecard cred, deb or filter must be used with jrn, the value of list means a list of fd_id
- *\see ajax_card.php cards.js
- */
- function build_sql($array) {
- if ( ! empty($array) ) extract($array);
- $and='';
- $filter_fd_id='true';
- $filter_query='';
- if ( isset($typecard)) {
- switch($typecard) {
- case 'cred':
- if ( ! isset($jrn)) throw ('Erreur pas de valeur pour jrn');
- $filter_jrn=$this->cn->make_list("select jrn_def_fiche_cred from jrn_Def where jrn_def_id=$1",array($jrn));
- $filter_fd_id=" fd_id in (".$filter_jrn.")";
- $and=" and ";
- break;
- case 'deb':
- if ( ! isset($jrn)) throw ('Erreur pas de valeur pour jrn');
- $filter_jrn=$this->cn->make_list("select jrn_def_fiche_deb from jrn_Def where jrn_def_id=$1",array($jrn));
- $filter_fd_id=" fd_id in (".$filter_jrn.")";
- $and=" and ";
- break;
- case 'filter':
- if ( ! isset($jrn)) throw ('Erreur pas de valeur pour jrn');
- $filter_jrn=$this->cn->make_list("select jrn_def_fiche_deb from jrn_Def where jrn_def_id=$1",array($jrn));
+ $get="";
+ if ( $p_type == 'deb' )
+ {
+ $get='jrn_def_fiche_deb';
+ }
+ if ( $p_type == 'cred' )
+ {
+ $get='jrn_def_fiche_cred';
+ }
+ if ( $get != "" )
+ {
+ $Res=$this->cn->exec_sql("select $get as fiche from jrn_def where jrn_def_id=$p_jrn");
+ }
+ else
+ {
+ // Get all the fiche type (deb and cred)
+ $Res=$this->cn->exec_sql(" select jrn_def_fiche_cred as fiche
+ from jrn_def where jrn_def_id=$p_jrn
+ union
+ select jrn_def_fiche_deb
+ from jrn_def where jrn_def_id=$p_jrn"
+ );
+ }
+ $Max=Database::num_row($Res);
+ if ( $Max==0)
+ {
+ return -2;
+ }
+ /* convert the array to a string */
+ $list=Database::fetch_all($Res);
+ $str_list="";
+ $comma='';
+ foreach ($list as $row)
+ {
+ if ( $row['fiche'] != '' )
+ {
+ $str_list.=$comma.$row['fiche'];
+ $comma=',';
+ }
+ }
+ // Normally Max must be == 1
- if ( trim($filter_jrn) !='')
- $fp1=" fd_id in (".$filter_jrn.")";
- else
- $fp1="fd_id < 0";
+ if ( $str_list=="")
+ {
+ return -3;
+ }
- $filter_jrn=$this->cn->make_list("select jrn_def_fiche_cred from jrn_Def where jrn_def_id=$1",array($jrn));
+ $sql="select *
+ from fiche
+ where
+ fd_id in (".$str_list.") and f_id= ".$this->id;
- if ( trim($filter_jrn) !='')
- $fp2=" fd_id in (".$filter_jrn.")";
- else
- $fp2="fd_id < 0";
+ $Res=$this->cn->exec_sql($sql);
+ $Max=Database::num_row($Res);
+ if ($Max==0 )
+ return 0;
+ else
+ return 1;
+ }
+ /*!\brief get all the card from a categorie
+ *\param $p_cn database connx
+ *\param $pFd_id is the category id
+ *\param $p_order for the sort, possible values is name_asc,name_desc or nothing
+ *\return an array of card, but only the fiche->id is set
+ */
+ static function get_fiche_def($p_cn,$pFd_id,$p_order='')
+ {
+ switch ($p_order)
+ {
+ case 'name_asc':
+ $sql='select f_id from fiche join vw_fiche_name using (f_id) where fd_id=$1 order by name asc';
+ break;
+ case 'name_desc':
+ $sql='select f_id from fiche join vw_fiche_name using (f_id) where fd_id=$1 order by name desc';
+ break;
+ default:
+ $sql='select f_id from fiche where fd_id=$1 ';
+ }
+ $array=$p_cn->get_array($sql,array($pFd_id));
+ if ( empty ($array) ) return null;
+ foreach ($array as $ret )
+ {
+ $r[]=new Fiche($p_cn,$ret['f_id']);
+ }
+ return $r;
+ }
+ /*!\brief check if a card is used
+ *\return return true is a card is used otherwise false
+ */
+ function is_used()
+ {
+ /* retrieve first the quickcode */
+ $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
+ $sql='select count(*) as c from jrnx where j_qcode=$1';
+ $count=$this->cn->get_value($sql,array($qcode));
+ if ( $count == 0 ) return false;
+ return true;
+ }
+ /*\brief remove a card without verification */
+ function delete()
+ {
+ // Remove from attr_value
+ $Res=$this->cn->exec_sql("delete from attr_value
+ where jft_id in (select jft_id
+ from jnt_fic_att_value
+ natural join fiche where f_id=".$this->id.")");
+ // Remove from jnt_fic_att_value
+ $Res=$this->cn->exec_sql("delete from jnt_fic_att_value where f_id=".$this->id);
- $filter_fd_id='('.$fp1.' or '.$fp2.')';
+ // Remove from fiche
+ $Res=$this->cn->exec_sql("delete from fiche where f_id=".$this->id);
- $and=" and ";
- break;
- case 'all':
- $filter_fd_id=' true';
- break;
- default:
- if ( trim($typecard) != '')
- $filter_fd_id=' fd_id in ('.$typecard.')';
- else
- $filter_fd_id=' fd_id < 0';
- }
- }
+ }
+ /*!\brief create the sql statement for retrieving all
+ * the card
+ *\return string with sql statement
+ *\param $array contains the condition
+ \verbatim
+ [jrn] => 2
+ [typecard] => cred / deb / filter or list
+ [query] => string
+ \endverbatim
+ *\note the typecard cred, deb or filter must be used with jrn, the value of list means a list of fd_id
+ *\see ajax_card.php cards.js
+ */
+ function build_sql($array)
+ {
+ if ( ! empty($array) ) extract($array);
+ $and='';
+ $filter_fd_id='true';
+ $filter_query='';
+ if ( isset($typecard))
+ {
+ switch($typecard)
+ {
+ case 'cred':
+ if ( ! isset($jrn)) throw ('Erreur pas de valeur pour jrn');
+ $filter_jrn=$this->cn->make_list("select jrn_def_fiche_cred from jrn_Def where jrn_def_id=$1",array($jrn));
+ $filter_fd_id=" fd_id in (".$filter_jrn.")";
+ $and=" and ";
+ break;
+ case 'deb':
+ if ( ! isset($jrn)) throw ('Erreur pas de valeur pour jrn');
+ $filter_jrn=$this->cn->make_list("select jrn_def_fiche_deb from jrn_Def where jrn_def_id=$1",array($jrn));
+ $filter_fd_id=" fd_id in (".$filter_jrn.")";
+ $and=" and ";
+ break;
+ case 'filter':
+ if ( ! isset($jrn)) throw ('Erreur pas de valeur pour jrn');
+ $filter_jrn=$this->cn->make_list("select jrn_def_fiche_deb from jrn_Def where jrn_def_id=$1",array($jrn));
- $and=" and ";
- if (isset($query)){
- $query=FormatString($query);
+ if ( trim($filter_jrn) !='')
+ $fp1=" fd_id in (".$filter_jrn.")";
+ else
+ $fp1="fd_id < 0";
- /**
- *@function
- *@todo FS#151 bad performance, to be changed with a prepare stmt
- */
- if (strlen(trim($query)) > 1)
- {
- $filter_query=$and."(vw_name ilike '%$query%' or quick_code ilike ('%$query%') or vw_description ilike '%$query%' or tva_num ilike '%$query%')";
- }
- else
- {
- $filter_query='';
- }
- }
- $sql="select * from vw_fiche_attr where ".$filter_fd_id.$filter_query;
- return $sql;
+ $filter_jrn=$this->cn->make_list("select jrn_def_fiche_cred from jrn_Def where jrn_def_id=$1",array($jrn));
- }
- /**
- *@brief move a card to another cat. The properties will changed
- * and be removed
- *@param $p_fdid the fd_id of destination
- */
- function move_to($p_fdid) {
- $this->cn->start();
- $this->cn->exec_sql('update fiche set fd_id=$1 where f_id=$2',array($p_fdid,$this->id));
- // add missing
- $this->cn->exec_sql('select fiche_attribut_synchro($1)',array($p_fdid));
- // add to the destination missing fields
- $this->cn->exec_sql("insert into jnt_fic_attr (fd_id,ad_id,jnt_order) select $1,ad_id,100 from jnt_fic_att_value where f_id=$2 and ad_id not in (select ad_id from jnt_fic_attr where fd_id=$3)",array($p_fdid,$this->id,$p_fdid));
- $this->cn->commit();
- }
+ if ( trim($filter_jrn) !='')
+ $fp2=" fd_id in (".$filter_jrn.")";
+ else
+ $fp2="fd_id < 0";
- static function test_me() {
- $cn=new Database(dossier::id());
- $a=new Fiche($cn);
- $select_cat=new ISelect('fd_id');
- $select_cat->value=$cn->make_array('select fd_id,fd_label from fiche_def where frd_id='.
- FICHE_TYPE_CLIENT);
- echo ' ';
- echo dossier::hidden();
- echo HtmlInput::hidden('test_select',$_GET['test_select']);
- echo 'Choix de la catégorie';
- echo $select_cat->input();
- echo HtmlInput::submit('go_card','Afficher');
- echo ' ';
- if ( isset ($_GET['go_card'])) {
- $empty=$a->toArray($_GET['fd_id']);
- print_r($empty);
- }
- }
+ $filter_fd_id='('.$fp1.' or '.$fp2.')';
+
+ $and=" and ";
+ break;
+ case 'all':
+ $filter_fd_id=' true';
+ break;
+ default:
+ if ( trim($typecard) != '')
+ $filter_fd_id=' fd_id in ('.$typecard.')';
+ else
+ $filter_fd_id=' fd_id < 0';
+ }
+ }
+
+ $and=" and ";
+ if (isset($query))
+ {
+ $query=FormatString($query);
+
+ /**
+ *@function
+ *@todo FS#151 bad performance, to be changed with a prepare stmt
+ */
+ if (strlen(trim($query)) > 1)
+ {
+ $filter_query=$and."(vw_name ilike '%$query%' or quick_code ilike ('%$query%') or vw_description ilike '%$query%' or tva_num ilike '%$query%')";
+ }
+ else
+ {
+ $filter_query='';
+ }
+ }
+ $sql="select * from vw_fiche_attr where ".$filter_fd_id.$filter_query;
+ return $sql;
+
+ }
+ /**
+ *@brief move a card to another cat. The properties will changed
+ * and be removed
+ *@param $p_fdid the fd_id of destination
+ */
+ function move_to($p_fdid)
+ {
+ $this->cn->start();
+ $this->cn->exec_sql('update fiche set fd_id=$1 where f_id=$2',array($p_fdid,$this->id));
+ // add missing
+ $this->cn->exec_sql('select fiche_attribut_synchro($1)',array($p_fdid));
+ // add to the destination missing fields
+ $this->cn->exec_sql("insert into jnt_fic_attr (fd_id,ad_id,jnt_order) select $1,ad_id,100 from jnt_fic_att_value where f_id=$2 and ad_id not in (select ad_id from jnt_fic_attr where fd_id=$3)",array($p_fdid,$this->id,$p_fdid));
+ $this->cn->commit();
+ }
+
+ static function test_me()
+ {
+ $cn=new Database(dossier::id());
+ $a=new Fiche($cn);
+ $select_cat=new ISelect('fd_id');
+ $select_cat->value=$cn->make_array('select fd_id,fd_label from fiche_def where frd_id='.
+ FICHE_TYPE_CLIENT);
+ echo ' ';
+ echo dossier::hidden();
+ echo HtmlInput::hidden('test_select',$_GET['test_select']);
+ echo 'Choix de la catégorie';
+ echo $select_cat->input();
+ echo HtmlInput::submit('go_card','Afficher');
+ echo ' ';
+ if ( isset ($_GET['go_card']))
+ {
+ $empty=$a->toArray($_GET['fd_id']);
+ print_r($empty);
+ }
+ }
}
?>
diff --git a/include/class_fiche_attr.php b/include/class_fiche_attr.php
index 63e5c5161..b0af48415 100644
--- a/include/class_fiche_attr.php
+++ b/include/class_fiche_attr.php
@@ -5,222 +5,251 @@
*
Example
@code
-
+
@endcode
*/
require_once('class_database.php');
require_once('ac_common.php');
-class Fiche_Attr
+class Fiche_Attr
{
- /* example private $variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0); */
-
- protected $variable=array("id"=>"ad_id","desc"=>"ad_text","type"=>"ad_type","size"=>"ad_size");
- function __construct ($p_cn,$p_id=0) {
+ /* example private $variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0); */
+
+ protected $variable=array("id"=>"ad_id","desc"=>"ad_text","type"=>"ad_type","size"=>"ad_size");
+ function __construct ($p_cn,$p_id=0)
+ {
$this->cn=$p_cn;
- if ( $p_id == 0 ) {
- /* Initialize an empty object */
+ if ( $p_id == 0 )
+ {
+ /* Initialize an empty object */
foreach ($this->variable as $key=>$value) $this->$value='';
- } else {
- /* load it */
- $this->ad_id=$p_id;
- $this->load();
- }
- }
- public function get_parameter($p_string) {
- if ( array_key_exists($p_string,$this->variable) ) {
- $idx=$this->variable[$p_string];
- return $this->$idx;
+ }
+ else
+ {
+ /* load it */
+ $this->ad_id=$p_id;
+ $this->load();
+ }
}
- else
- throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur attribut inexistant');
- }
- public function set_parameter($p_string,$p_value) {
- if ( array_key_exists($p_string,$this->variable) ) {
- $idx=$this->variable[$p_string];
- $this->$idx=$p_value;
+ public function get_parameter($p_string)
+ {
+ if ( array_key_exists($p_string,$this->variable) )
+ {
+ $idx=$this->variable[$p_string];
+ return $this->$idx;
+ }
+ else
+ throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur attribut inexistant');
}
- else
- throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur attribut inexistant');
- }
- public function get_info() { return var_export($this,true); }
- public function verify() {
- // Verify that the elt we want to add is correct
- /* verify only the datatype */
- if ( strlen(trim($this->ad_text))==0)
- throw new Exception('La description ne peut pas être vide',1);
- if ( strlen(trim($this->ad_type))==0)
- throw new Exception('Le type ne peut pas être vide',1);
- $this->ad_type=strtolower($this->ad_type);
- if ( in_array($this->ad_type,array('date','text','numeric','zone'))==false)
- throw new Exception('Le type doit être text, numeric ou date',1);
- if ( trim($this->ad_size)=='' || isNumber($this->ad_size)==0||$this->ad_size>22) {
- switch ($this->ad_type) {
- case 'text':
- $this->ad_size=22;
- break;
- case 'numeric':
- $this->ad_size=9;
- break;
- case 'date':
- $this->ad_size=8;
- break;
- case 'zone':
- $this->ad_size=22;
- break;
- default:
- $this->ad_size=22;
- }
+ public function set_parameter($p_string,$p_value)
+ {
+ if ( array_key_exists($p_string,$this->variable) )
+ {
+ $idx=$this->variable[$p_string];
+ $this->$idx=$p_value;
+ }
+ else
+ throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur attribut inexistant');
}
- }
- public function save() {
- /* please adapt */
- if ( $this->ad_id == 0 )
- $this->insert();
- else
- $this->update();
- }
- /**
- *@brief retrieve array of object thanks a condition
- *@param $cond condition (where clause)
- *@param $p_array array for the SQL stmt
- *@see Database::get_array
- *@return an empty array if nothing is found
- */
- public function seek($cond='',$p_array=null)
- {
- if ( $cond != '')
- $sql="select * from attr_def where $cond order by ad_text";
- else
- $sql="select * from attr_def order by ad_text";
+ public function get_info()
+ {
+ return var_export($this,true);
+ }
+ public function verify()
+ {
+ // Verify that the elt we want to add is correct
+ /* verify only the datatype */
+ if ( strlen(trim($this->ad_text))==0)
+ throw new Exception('La description ne peut pas être vide',1);
+ if ( strlen(trim($this->ad_type))==0)
+ throw new Exception('Le type ne peut pas être vide',1);
+ $this->ad_type=strtolower($this->ad_type);
+ if ( in_array($this->ad_type,array('date','text','numeric','zone'))==false)
+ throw new Exception('Le type doit être text, numeric ou date',1);
+ if ( trim($this->ad_size)=='' || isNumber($this->ad_size)==0||$this->ad_size>22)
+ {
+ switch ($this->ad_type)
+ {
+ case 'text':
+ $this->ad_size=22;
+ break;
+ case 'numeric':
+ $this->ad_size=9;
+ break;
+ case 'date':
+ $this->ad_size=8;
+ break;
+ case 'zone':
+ $this->ad_size=22;
+ break;
+ default:
+ $this->ad_size=22;
+ }
+ }
+ }
+ public function save()
+ {
+ /* please adapt */
+ if ( $this->ad_id == 0 )
+ $this->insert();
+ else
+ $this->update();
+ }
+ /**
+ *@brief retrieve array of object thanks a condition
+ *@param $cond condition (where clause)
+ *@param $p_array array for the SQL stmt
+ *@see Database::get_array
+ *@return an empty array if nothing is found
+ */
+ public function seek($cond='',$p_array=null)
+ {
+ if ( $cond != '')
+ $sql="select * from attr_def where $cond order by ad_text";
+ else
+ $sql="select * from attr_def order by ad_text";
- $aobj=array();
- $array= $this->cn->get_array($sql,$p_array);
- // map each row in a object
- $size=$this->cn->count();
- if ( $size == 0 ) return $aobj;
- for ($i=0;$i<$size;$i++) {
- $oobj=new Fiche_Attr ($this->cn);
- foreach ($array[$i] as $idx=>$value) { $oobj->$idx=$value; }
- $aobj[]=clone $oobj;
- }
- return $aobj;
- }
- public function insert() {
- $this->verify();
- /* please adapt */
- $sql="insert into attr_def(ad_text
-,ad_type,ad_size
-) values ($1
-,$2,$3
-) returning ad_id";
-
- $this->ad_id=$this->cn->get_value(
- $sql,
- array( $this->ad_text,$this->ad_type,$this->ad_size
- )
- );
+ $aobj=array();
+ $array= $this->cn->get_array($sql,$p_array);
+ // map each row in a object
+ $size=$this->cn->count();
+ if ( $size == 0 ) return $aobj;
+ for ($i=0;$i<$size;$i++)
+ {
+ $oobj=new Fiche_Attr ($this->cn);
+ foreach ($array[$i] as $idx=>$value)
+ {
+ $oobj->$idx=$value;
+ }
+ $aobj[]=clone $oobj;
+ }
+ return $aobj;
+ }
+ public function insert()
+ {
+ $this->verify();
+ /* please adapt */
+ $sql="insert into attr_def(ad_text
+ ,ad_type,ad_size
+ ) values ($1
+ ,$2,$3
+ ) returning ad_id";
- }
+ $this->ad_id=$this->cn->get_value(
+ $sql,
+ array( $this->ad_text,$this->ad_type,$this->ad_size
+ )
+ );
- public function update() {
- if ( $this->verify() != 0 ) return;
- if ( $this->ad_id < 9000) return;
- /* please adapt */
- $sql=" update attr_def set ad_text = $1
-,ad_type = $2,ad_size=$4
- where ad_id= $3";
- $res=$this->cn->exec_sql(
- $sql,
- array($this->ad_text
- ,$this->ad_type
- ,$this->ad_id,$this->ad_size)
- );
-
- }
-/**
- *@brief load a object
- *@return 0 on success -1 the object is not found
- */
- public function load() {
+ }
- $sql="select ad_text
-,ad_type
- from attr_def where ad_id=$1";
- /* please adapt */
- $res=$this->cn->get_array(
- $sql,
- array($this->ad_id)
- );
-
- if ( count($res) == 0 ) {
- /* Initialize an empty object */
- foreach ($this->variable as $key=>$value) $this->$key='';
+ public function update()
+ {
+ if ( $this->verify() != 0 ) return;
+ if ( $this->ad_id < 9000) return;
+ /* please adapt */
+ $sql=" update attr_def set ad_text = $1
+ ,ad_type = $2,ad_size=$4
+ where ad_id= $3";
+ $res=$this->cn->exec_sql(
+ $sql,
+ array($this->ad_text
+ ,$this->ad_type
+ ,$this->ad_id,$this->ad_size)
+ );
- return -1;
- }
- foreach ($res[0] as $idx=>$value) { $this->$idx=$value; }
- return 0;
- }
+ }
+ /**
+ *@brief load a object
+ *@return 0 on success -1 the object is not found
+ */
+ public function load()
+ {
- public function delete() {
- if ($this->ad_id < 9000) return;
- $sql=$this->cn->exec_sql("delete from attr_value where jft_id in (select jft_id from jnt_fic_att_value where ad_id=$1 )",
- array($this->ad_id));
- $sql="delete from jnt_fic_att_value where ad_id=$1";
- $res=$this->cn->exec_sql($sql,array($this->ad_id));
+ $sql="select ad_text
+ ,ad_type
+ from attr_def where ad_id=$1";
+ /* please adapt */
+ $res=$this->cn->get_array(
+ $sql,
+ array($this->ad_id)
+ );
- $sql="delete from jnt_fic_attr where ad_id=$1";
- $res=$this->cn->exec_sql($sql,array($this->ad_id));
+ if ( count($res) == 0 )
+ {
+ /* Initialize an empty object */
+ foreach ($this->variable as $key=>$value) $this->$key='';
- $sql="delete from attr_def where ad_id=$1";
- $res=$this->cn->exec_sql($sql,array($this->ad_id));
+ return -1;
+ }
+ foreach ($res[0] as $idx=>$value)
+ {
+ $this->$idx=$value;
+ }
+ return 0;
+ }
- }
- /**
- * Unit test for the class
- */
- static function test_me() {
- $cn=new Database(25);
-$cn->start();
- echo h2info('Test object vide');
- $obj=new Fiche_Attr($cn);
- var_dump($obj);
+ public function delete()
+ {
+ if ($this->ad_id < 9000) return;
+ $sql=$this->cn->exec_sql("delete from attr_value where jft_id in (select jft_id from jnt_fic_att_value where ad_id=$1 )",
+ array($this->ad_id));
+ $sql="delete from jnt_fic_att_value where ad_id=$1";
+ $res=$this->cn->exec_sql($sql,array($this->ad_id));
- echo h2info('Test object NON vide');
- $obj->set_parameter('j_id',3);
- $obj->load();
- var_dump($obj);
+ $sql="delete from jnt_fic_attr where ad_id=$1";
+ $res=$this->cn->exec_sql($sql,array($this->ad_id));
- echo h2info('Update');
- $obj->set_parameter('j_qcode','NOUVEAU CODE');
- $obj->save();
- $obj->load();
- var_dump($obj);
+ $sql="delete from attr_def where ad_id=$1";
+ $res=$this->cn->exec_sql($sql,array($this->ad_id));
- echo h2info('Insert');
- $obj->set_parameter('j_id',0);
- $obj->save();
- $obj->load();
- var_dump($obj);
+ }
+ /**
+ * Unit test for the class
+ */
+ static function test_me()
+ {
+ $cn=new Database(25);
+ $cn->start();
+ echo h2info('Test object vide');
+ $obj=new Fiche_Attr($cn);
+ var_dump($obj);
- echo h2info('Delete');
- $obj->delete();
- echo (($obj->load()==0)?'Trouve':'non trouve');
- var_dump($obj);
-$cn->rollback();
+ echo h2info('Test object NON vide');
+ $obj->set_parameter('j_id',3);
+ $obj->load();
+ var_dump($obj);
+
+ echo h2info('Update');
+ $obj->set_parameter('j_qcode','NOUVEAU CODE');
+ $obj->save();
+ $obj->load();
+ var_dump($obj);
+
+ echo h2info('Insert');
+ $obj->set_parameter('j_id',0);
+ $obj->save();
+ $obj->load();
+ var_dump($obj);
+
+ echo h2info('Delete');
+ $obj->delete();
+ echo (($obj->load()==0)?'Trouve':'non trouve');
+ var_dump($obj);
+ $cn->rollback();
+
+ }
+ /*!
+ *@brief used with a usort function, to sort an array of Attribut on the attribut_id (ad_id)
+ */
+ static function sort_by_id($o1,$o2)
+ {
+ if ( $o1->ad_id > $o2->ad_id ) return 1;
+ if ( $o1->ad_id == $o2->ad_id ) return 0;
+ return -1;
+ }
- }
-/*!
- *@brief used with a usort function, to sort an array of Attribut on the attribut_id (ad_id)
- */
- static function sort_by_id($o1,$o2) {
- if ( $o1->ad_id > $o2->ad_id ) return 1;
- if ( $o1->ad_id == $o2->ad_id ) return 0;
- return -1;
- }
-
}
//Fiche_Attr::test_me();
diff --git a/include/class_fiche_def.php b/include/class_fiche_def.php
index f3c0b5ff0..7c80bdcc5 100644
--- a/include/class_fiche_def.php
+++ b/include/class_fiche_def.php
@@ -1,4 +1,4 @@
-cn=$p_cn;
- $this->id=$p_id;
- }
-/*!\brief show the content of the form to create a new Fiche_Def_Ref
-*/
-function input ()
+class Fiche_Def
{
- $ref=$this->cn->get_array("select * from fiche_def_ref order by frd_text");
- $iradio=new IRadio();
- /* the accounting item */
- $class_base=new IPoste('class_base');
- $class_base->set_attribute('ipopup','ipop_account');
- $class_base->set_attribute('account','class_base');
- $class_base->set_attribute('label','acc_label');
- $f_class_base=$class_base->input();
- require_once ('template/fiche_def_input.php');
- return;
-}
-
-/*!
- * \brief Get attribut of a fiche_def
- *
- * \return string value of the attribute
- */
- function getAttribut() {
- $sql="select * from jnt_fic_attr ".
- " natural join attr_def where fd_id=".$this->id.
- " order by jnt_order";
-
- $Ret=$this->cn->exec_sql($sql);
-
- if ( ($Max=Database::num_row($Ret)) == 0 )
- return ;
- for ($i=0;$i < $Max;$i++) {
- $row=Database::fetch_array($Ret,$i);
- $t = new Fiche_Attr($this->cn);
- $t->ad_id=$row['ad_id'];
- $t->ad_text=$row['ad_text'];
- $t->jnt_order=$row['jnt_order'];
- $t->ad_size=$row['ad_size'];
- $t->ad_type=$row['ad_type'];
- $this->attribut[$i]=$t;
+ var $cn; // database connection
+ var $id; // id (fiche_def.fd_id
+ var $label; // fiche_def.fd_label
+ var $class_base; // fiche_def.fd_class_base
+ var $fiche_def; // fiche_def.frd_id = fiche_def_ref.frd_id
+ var $create_account; // fd_create_account: flag
+ var $all;
+ var $attribut; // get from attr_xxx tables
+ function __construct($p_cn,$p_id = 0)
+ {
+ $this->cn=$p_cn;
+ $this->id=$p_id;
}
- return $this->attribut;
- }
-
- /*!
- * \brief Get attribut of the fiche_def
- *
- */
- function Get() {
- if ( $this->id == 0 )
- return 0;
- /* $this->cn->exec_sql('select fiche_attribut_synchro($1)',
- array($this->id));
+ /*!\brief show the content of the form to create a new Fiche_Def_Ref
*/
- $sql="select * from fiche_def ".
- " where fd_id=".$this->id;
- $Ret=$this->cn->exec_sql($sql);
- if ( ($Max=Database::num_row($Ret)) == 0 )
- return ;
- $row=Database::fetch_array($Ret,0);
- $this->label=$row['fd_label'];
- $this->class_base=$row['fd_class_base'];
- $this->fiche_def=$row['frd_id'];
- $this->create_account=$row['fd_create_account'];
- }
-/*!
- **************************************************
- * \brief Get all the fiche_def
- *
- * \return an array of fiche_def object
- */
- function GetAll() {
- $sql="select * from fiche_def ";
-
- $Ret=$this->cn->exec_sql($sql);
- if ( ($Max=Database::num_row($Ret)) == 0 )
- return ;
-
- for ( $i = 0; $i < $Max;$i++) {
- $row=Database::fetch_array($Ret,$i);
- $this->all[$i]=new Fiche_Def($this->cn,$row['fd_id']);
- $this->all[$i]->label=$row['fd_label'];
- $this->all[$i]->class_base=$row['fd_class_base'];
- $this->all[$i]->fiche_def=$row['frd_id'];
- $this->all[$i]->create_account=$row['fd_create_account'];
- }
- }
-/*!
- **************************************************
- * \brief Check in vw_fiche_def if a fiche has
- * a attribut X
- *
- *
- * \param $p_attr attribut to check
- * \return true or false
- */
- function HasAttribute($p_attr) {
- return ($this->cn->count_sql("select * from vw_fiche_def where ad_id=$p_attr and fd_id=".$this->id)>0)?true:false;
-
- }
-/*!
- **************************************************
- * \brief Display a fiche_def object into a table
- *
- * \return HTML row
- */
- function Display()
- {
-
- $r=sprintf("%s ",$this->id);
- $r.=sprintf("%s ",$this->label);
- $r.=sprintf("%s ",$this->class_base);
- $r.=sprintf("%s ",$this->fiche_def);
- return $r;
- }
- /*!\brief Add a fiche category thanks the element from the array
- * you cannot add twice the same cat. name
- * table : insert into fiche_def
- * insert into attr_def
- *
- * \param $array array
- * index FICHE_REF
- * nom_mod
- * class_base
- */
- function Add($array)
- {
- foreach ( $array as $key=>$element ) {
- ${"p_$key"}=$element;
- }
- // Format correctly the name of the cat. of card
- $p_nom_mod=FormatString($p_nom_mod);
-
-
- // Name can't be empty
- if ( strlen(trim($p_nom_mod)) == 0 )
- return;
-
- // $p_FICHE_REF cannot be null !!! (== fiche_def_ref.frd_id
- if (! isset ($p_FICHE_REF) || strlen($p_FICHE_REF) == 0 ) {
- echo alert (_('Vous devez choisir une categorie'));
- return;
- }
- $fiche_Def_ref=new Fiche_Def_Ref($this->cn,$p_FICHE_REF);
- $fiche_Def_ref->Get();
-
- // build the sql request for fiche_def
- // and insert into fiche_def
- // if p_class_base is null get the default class base from
- // fiche_def_ref
- if ( FormatString($p_class_base) == null )
- { // p_class is null
- // So we take the default one
- $p_class_base=$fiche_Def_ref->frd_class_base;
- }
- /* check if the cat. name already exists */
- $sql="select count(*) from fiche_Def where upper(fd_label)=upper($1)";
- $count=$this->cn->get_value($sql,array(trim($p_nom_mod)));
-
- if ($count != 0 ) return -1;
- // Set the value of fiche_def.fd_create_account
- // automatic creation for 'poste comptable'
- if ( isset($p_create) && strlen(trim($p_class_base)) != 0)
- $p_create='true';
- else
- $p_create='false';
-
- // Class is valid ?
- if ( FormatString($p_class_base) != null || strpos(',',$p_class_base) != 0 ) {
- // p_class is a valid number
- $sql="insert into fiche_def(fd_label,fd_class_base,frd_id,fd_create_account)
- values ($1,$2,$3,$4) returning fd_id";
-
- $fd_id=$this->cn->get_value($sql,array($p_nom_mod,$p_class_base,$p_FICHE_REF,$p_create));
-
- // p_class must be added to tmp_pcmn if it is a single accounting
- if ( strpos(',',$p_class_base) ==0) {
- $sql="select account_add($1,$2)";
- $Res=$this->cn->exec_sql($sql,array($p_class_base,$p_nom_mod));
- }
-
- // Get the fd_id
- $fd_id=$this->cn->get_current_seq('s_fdef');
-
- // update jnt_fic_attr
- $sql=sprintf("insert into jnt_fic_attr(fd_id,ad_id,jnt_order)
- values (%d,%d,10)",$fd_id,ATTR_DEF_ACCOUNT);
- $Res=$this->cn->exec_sql($sql);
-
- } else {
- //There is no class base not even as default
- $sql=sprintf("insert into fiche_def(fd_label,frd_id,fd_create_account) values ('%s',%d,'%s') returning fd_id",
- $p_nom_mod,$p_FICHE_REF,$p_create);
-
- $this->id=$this->cn->get_value($sql);
-
- // Get the fd_id
- $fd_id=$this->cn->get_current_seq('s_fdef');
-
- }
-
- // Get the default attr_def from attr_min
- $def_attr=$this->get_attr_min($p_FICHE_REF);
-
- //if defaut attr not null
- // build the sql insert for the table attr_def
- if (sizeof($def_attr) != 0 ) {
- // insert all the mandatory fields into jnt_fiche_attr
- foreach ( $def_attr as $i=>$v) {
- $jnt_order=10;
- if ( $v['ad_id'] == ATTR_DEF_NAME )
- $jnt_order=0;
- $sql=sprintf("insert into jnt_fic_Attr(fd_id,ad_id,jnt_order)
- values (%d,%s,%d)",
- $fd_id,$v['ad_id'],$jnt_order);
- $this->cn->exec_sql($sql);
- }
- }
- $this->id=$fd_id;
- return 0;
-
- }//--------------end function Add ----------------------------
-/*!
- * \brief Get all the card where the fiche_def.fd_id is given in parameter
- * \param $step = 0 we don't use the offset, page_size,...
- * $step = 1 we use the jnr_bar_nav
- *
- * \return array of object fiche
- *\see fiche
- */
- function GetByType($step=0) {
- $sql="select *
- from
- fiche
- where fd_id=".$this->id;
-
- // we use jrn_navigation_bar
- if ($step == 1 && $_SESSION['g_pagesize'] != -1 )
- {
- $offset=(isset($_GET['offset']))?$_GET['offset']:0;
- $step=$_SESSION['g_pagesize'];
- $sql.=" offset $offset limit $step";
- }
-
- $Ret=$this->cn->exec_sql($sql);
- if ( ($Max=Database::num_row($Ret)) == 0 )
- return ;
- $all[0]=new Fiche($this->cn);
-
- for ($i=0;$i<$Max;$i++) {
- $row=Database::fetch_array($Ret,$i);
- $t=new Fiche($this->cn,$row['f_id']);
- $t->getAttribut();
- $all[$i]=$t;
-
- }
- return $all;
- }
-/*!
- * \brief Get all the card where the fiche_def.frd_id is given in parameter
- * \return array of fiche or null is nothing is found
- */
- function get_by_category($p_cat) {
- $sql="select f_id
- from
- fiche join fiche_def using(fd_id)
- where frd_id=$1";
-
- $Ret=$this->cn->exec_sql($sql,array($p_cat));
- if ( ($Max=Database::num_row($Ret)) == 0 )
- return null;
- $all[0]=new Fiche($this->cn);
-
- for ($i=0;$i<$Max;$i++) {
- $row=Database::fetch_array($Ret,$i);
- $t=new Fiche($this->cn,$row['f_id']);
- $t->getAttribut();
- $all[$i]=$t;
-
- }
- return $all;
- }
-
- /*!\brief list the card of a fd_id
- */
- function myList()
+ function input ()
{
- $this->Get();
- echo ''.$this->label.' ';
+ $ref=$this->cn->get_array("select * from fiche_def_ref order by frd_text");
+ $iradio=new IRadio();
+ /* the accounting item */
+ $class_base=new IPoste('class_base');
+ $class_base->set_attribute('ipopup','ipop_account');
+ $class_base->set_attribute('account','class_base');
+ $class_base->set_attribute('label','acc_label');
+ $f_class_base=$class_base->input();
+ require_once ('template/fiche_def_input.php');
+ return;
+ }
- $step=$_SESSION['g_pagesize'];
- $sql_limit="";
- $sql_offset="";
- $bar="";
- if ( $step != -1 ) {
+ /*!
+ * \brief Get attribut of a fiche_def
+ *
+ * \return string value of the attribute
+ */
+ function getAttribut()
+ {
+ $sql="select * from jnt_fic_attr ".
+ " natural join attr_def where fd_id=".$this->id.
+ " order by jnt_order";
- $page=(isset($_GET['page']))?$_GET['page']:1;
- $offset=(isset($_GET['offset']))?$_GET['offset']:0;
- $max_line=$this->cn->count_sql("select f_id,av_text from
- fiche join jnt_fic_att_value using (f_id)
- join attr_value using (jft_id)
- where fd_id='".$this->id."' and ad_id=".ATTR_DEF_NAME." order by f_id");
- $sql_limit=" limit ".$step;
- $sql_offset=" offset ".$offset;
- $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
- }
-
- // Get all name the cards of the select category
- // 1 for attr_def.ad_id is always the name
- $Res=$this->cn->exec_sql("select f_id,vw_name,quick_code from ".
- " vw_fiche_attr ".
- " where fd_id='".$this->id.
- "' order by f_id $sql_offset $sql_limit ");
- $Max=Database::num_row($Res);
- echo $bar;
- $str="";
- // save the url
- // with offet &offset=15&step=15&page=2&size=15
- if ( $_SESSION['g_pagesize'] != -1) {
- $str=sprintf("&offset=%s&step=%s&page=%s&size=%s",
- $offset,
- $step,
- $page,
- $max_line);
- }
-
-
- echo '';
- echo dossier::hidden();
- echo HtmlInput::hidden("fiche",$this->id);
- echo HtmlInput::submit('add','Ajout fiche');
- echo ' ';
- $str_dossier=dossier::get();
- echo '';
- for ( $i = 0; $i < $Max; $i++) {
- $l_line=Database::fetch_array($Res,$i);
- if ( $i%2 == 0)
- echo '';
- else
- echo ' ';
+ $Ret=$this->cn->exec_sql($sql);
- $span_mod=''.$l_line['quick_code'].' ';
-
- echo $span_mod.''.h($l_line['vw_name'])." ";
- echo ' ';
- }
- echo '
';
- echo '';
- echo dossier::hidden();
- echo HtmlInput::hidden("fiche",$this->id);
- echo HtmlInput::submit('add','Ajout fiche');
- echo ' ';
- echo $bar;
+ if ( ($Max=Database::num_row($Ret)) == 0 )
+ return ;
+ for ($i=0;$i < $Max;$i++)
+ {
+ $row=Database::fetch_array($Ret,$i);
+ $t = new Fiche_Attr($this->cn);
+ $t->ad_id=$row['ad_id'];
+ $t->ad_text=$row['ad_text'];
+ $t->jnt_order=$row['jnt_order'];
+ $t->ad_size=$row['ad_size'];
+ $t->ad_type=$row['ad_type'];
+ $this->attribut[$i]=$t;
+ }
+ return $this->attribut;
+ }
+
+ /*!
+ * \brief Get attribut of the fiche_def
+ *
+ */
+ function Get()
+ {
+ if ( $this->id == 0 )
+ return 0;
+ /* $this->cn->exec_sql('select fiche_attribut_synchro($1)',
+ array($this->id));
+ */
+ $sql="select * from fiche_def ".
+ " where fd_id=".$this->id;
+ $Ret=$this->cn->exec_sql($sql);
+ if ( ($Max=Database::num_row($Ret)) == 0 )
+ return ;
+ $row=Database::fetch_array($Ret,0);
+ $this->label=$row['fd_label'];
+ $this->class_base=$row['fd_class_base'];
+ $this->fiche_def=$row['frd_id'];
+ $this->create_account=$row['fd_create_account'];
+ }
+ /*!
+ **************************************************
+ * \brief Get all the fiche_def
+ *
+ * \return an array of fiche_def object
+ */
+ function GetAll()
+ {
+ $sql="select * from fiche_def ";
+
+ $Ret=$this->cn->exec_sql($sql);
+ if ( ($Max=Database::num_row($Ret)) == 0 )
+ return ;
+
+ for ( $i = 0; $i < $Max;$i++)
+ {
+ $row=Database::fetch_array($Ret,$i);
+ $this->all[$i]=new Fiche_Def($this->cn,$row['fd_id']);
+ $this->all[$i]->label=$row['fd_label'];
+ $this->all[$i]->class_base=$row['fd_class_base'];
+ $this->all[$i]->fiche_def=$row['frd_id'];
+ $this->all[$i]->create_account=$row['fd_create_account'];
+ }
+ }
+ /*!
+ **************************************************
+ * \brief Check in vw_fiche_def if a fiche has
+ * a attribut X
+ *
+ *
+ * \param $p_attr attribut to check
+ * \return true or false
+ */
+ function HasAttribute($p_attr)
+ {
+ return ($this->cn->count_sql("select * from vw_fiche_def where ad_id=$p_attr and fd_id=".$this->id)>0)?true:false;
}
- /*!\brief show input for the basic attribute : label, class_base, create_account
- * use only when we want to update
- *
- *\return HTML string with the form
- */
- function input_base() {
- $r="";
- $r.=_('Label');
- $label=new IText('label',$this->label);
- $r.=$label->input();
- $r.=' ';
- /* the accounting item */
- $class_base=new IPoste('class_base',$this->class_base);
- $class_base->set_attribute('ipopup','ipop_account');
- $class_base->set_attribute('account','class_base');
- $class_base->set_attribute('label','acc_label');
- $r.=_('Poste Comptable de base').' : ';
- $r.=$class_base->input();
- $r.=' ';
- /* auto Create */
- $ck=new ICheckBox('create');
- $ck->selected=($this->create_account=='f')?false:true;
- $r.=_('Chaque fiche aura automatiquement son propre poste comptable : ');
- $r.=$ck->input();
- return $r;
- }
- /*!\brief Display all the attribut of the fiche_def
- *\param $str give the action possible values are remove, empty
- */
- function DisplayAttribut($str="")
+ /*!
+ **************************************************
+ * \brief Display a fiche_def object into a table
+ *
+ * \return HTML row
+ */
+ function Display()
{
- if ( $this->id == 0 )
- return ;
- /* $this->cn->exec_sql('select fiche_attribut_synchro($1)',
- array($this->id));
- */
- $MaxLine=sizeof($this->attribut);
- $r="";
- return $r;
+ $r=sprintf("%s ",$this->id);
+ $r.=sprintf("%s ",$this->label);
+ $r.=sprintf("%s ",$this->class_base);
+ $r.=sprintf("%s ",$this->fiche_def);
+ return $r;
}
- /*!\brief Save the label of the fiche_def
- * \param $p_label label
- */
- function SaveLabel($p_label)
+ /*!\brief Add a fiche category thanks the element from the array
+ * you cannot add twice the same cat. name
+ * table : insert into fiche_def
+ * insert into attr_def
+ *
+ * \param $array array
+ * index FICHE_REF
+ * nom_mod
+ * class_base
+ */
+ function Add($array)
{
- if ( $this->id == 0 ) return;
- $p_label=FormatString($p_label);
- if (strlen(trim ($p_label)) == 0 ) {
- return;
- }
- $sql=sprintf("update fiche_def set fd_label='%s' ".
- "where fd_id=%d",
- $p_label,$this->id);
- $Res=$this->cn->exec_sql($sql);
-
+ foreach ( $array as $key=>$element )
+ {
+ ${"p_$key"}=$element;
+ }
+ // Format correctly the name of the cat. of card
+ $p_nom_mod=FormatString($p_nom_mod);
+
+
+ // Name can't be empty
+ if ( strlen(trim($p_nom_mod)) == 0 )
+ return;
+
+ // $p_FICHE_REF cannot be null !!! (== fiche_def_ref.frd_id
+ if (! isset ($p_FICHE_REF) || strlen($p_FICHE_REF) == 0 )
+ {
+ echo alert (_('Vous devez choisir une categorie'));
+ return;
+ }
+ $fiche_Def_ref=new Fiche_Def_Ref($this->cn,$p_FICHE_REF);
+ $fiche_Def_ref->Get();
+
+ // build the sql request for fiche_def
+ // and insert into fiche_def
+ // if p_class_base is null get the default class base from
+ // fiche_def_ref
+ if ( FormatString($p_class_base) == null )
+ { // p_class is null
+ // So we take the default one
+ $p_class_base=$fiche_Def_ref->frd_class_base;
+ }
+ /* check if the cat. name already exists */
+ $sql="select count(*) from fiche_Def where upper(fd_label)=upper($1)";
+ $count=$this->cn->get_value($sql,array(trim($p_nom_mod)));
+
+ if ($count != 0 ) return -1;
+ // Set the value of fiche_def.fd_create_account
+ // automatic creation for 'poste comptable'
+ if ( isset($p_create) && strlen(trim($p_class_base)) != 0)
+ $p_create='true';
+ else
+ $p_create='false';
+
+ // Class is valid ?
+ if ( FormatString($p_class_base) != null || strpos(',',$p_class_base) != 0 )
+ {
+ // p_class is a valid number
+ $sql="insert into fiche_def(fd_label,fd_class_base,frd_id,fd_create_account)
+ values ($1,$2,$3,$4) returning fd_id";
+
+ $fd_id=$this->cn->get_value($sql,array($p_nom_mod,$p_class_base,$p_FICHE_REF,$p_create));
+
+ // p_class must be added to tmp_pcmn if it is a single accounting
+ if ( strpos(',',$p_class_base) ==0)
+ {
+ $sql="select account_add($1,$2)";
+ $Res=$this->cn->exec_sql($sql,array($p_class_base,$p_nom_mod));
+ }
+
+ // Get the fd_id
+ $fd_id=$this->cn->get_current_seq('s_fdef');
+
+ // update jnt_fic_attr
+ $sql=sprintf("insert into jnt_fic_attr(fd_id,ad_id,jnt_order)
+ values (%d,%d,10)",$fd_id,ATTR_DEF_ACCOUNT);
+ $Res=$this->cn->exec_sql($sql);
+
+ }
+ else
+ {
+ //There is no class base not even as default
+ $sql=sprintf("insert into fiche_def(fd_label,frd_id,fd_create_account) values ('%s',%d,'%s') returning fd_id",
+ $p_nom_mod,$p_FICHE_REF,$p_create);
+
+ $this->id=$this->cn->get_value($sql);
+
+ // Get the fd_id
+ $fd_id=$this->cn->get_current_seq('s_fdef');
+
+ }
+
+ // Get the default attr_def from attr_min
+ $def_attr=$this->get_attr_min($p_FICHE_REF);
+
+ //if defaut attr not null
+ // build the sql insert for the table attr_def
+ if (sizeof($def_attr) != 0 )
+ {
+ // insert all the mandatory fields into jnt_fiche_attr
+ foreach ( $def_attr as $i=>$v)
+ {
+ $jnt_order=10;
+ if ( $v['ad_id'] == ATTR_DEF_NAME )
+ $jnt_order=0;
+ $sql=sprintf("insert into jnt_fic_Attr(fd_id,ad_id,jnt_order)
+ values (%d,%s,%d)",
+ $fd_id,$v['ad_id'],$jnt_order);
+ $this->cn->exec_sql($sql);
+ }
+ }
+ $this->id=$fd_id;
+ return 0;
+
+ }//--------------end function Add ----------------------------
+ /*!
+ * \brief Get all the card where the fiche_def.fd_id is given in parameter
+ * \param $step = 0 we don't use the offset, page_size,...
+ * $step = 1 we use the jnr_bar_nav
+ *
+ * \return array of object fiche
+ *\see fiche
+ */
+ function GetByType($step=0)
+ {
+ $sql="select *
+ from
+ fiche
+ where fd_id=".$this->id;
+
+ // we use jrn_navigation_bar
+ if ($step == 1 && $_SESSION['g_pagesize'] != -1 )
+ {
+ $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+ $step=$_SESSION['g_pagesize'];
+ $sql.=" offset $offset limit $step";
+ }
+
+ $Ret=$this->cn->exec_sql($sql);
+ if ( ($Max=Database::num_row($Ret)) == 0 )
+ return ;
+ $all[0]=new Fiche($this->cn);
+
+ for ($i=0;$i<$Max;$i++)
+ {
+ $row=Database::fetch_array($Ret,$i);
+ $t=new Fiche($this->cn,$row['f_id']);
+ $t->getAttribut();
+ $all[$i]=$t;
+
+ }
+ return $all;
}
- /*!\brief set the auto create accounting item for each card and
- * save it into the database
- * \param $p_label true or false
- */
- function set_autocreate($p_label)
+ /*!
+ * \brief Get all the card where the fiche_def.frd_id is given in parameter
+ * \return array of fiche or null is nothing is found
+ */
+ function get_by_category($p_cat)
{
- if ( $this->id == 0 ) return;
- if ($p_label==true)
- $t='t';
- if ($p_label==false)
- $t='f';
+ $sql="select f_id
+ from
+ fiche join fiche_def using(fd_id)
+ where frd_id=$1";
- $sql="update fiche_def set fd_create_account=$1 ".
- "where fd_id=$2";
+ $Ret=$this->cn->exec_sql($sql,array($p_cat));
+ if ( ($Max=Database::num_row($Ret)) == 0 )
+ return null;
+ $all[0]=new Fiche($this->cn);
- $Res=$this->cn->exec_sql($sql,array($t,$this->id));
-
+ for ($i=0;$i<$Max;$i++)
+ {
+ $row=Database::fetch_array($Ret,$i);
+ $t=new Fiche($this->cn,$row['f_id']);
+ $t->getAttribut();
+ $all[$i]=$t;
+
+ }
+ return $all;
}
- /*!\brief Save the class base
- * \param $p_label label
- */
- function save_class_base($p_label)
+
+ /*!\brief list the card of a fd_id
+ */
+ function myList()
{
- if ( $this->id == 0 ) return;
- $p_label=FormatString($p_label);
+ $this->Get();
+ echo ''.$this->label.' ';
- $sql="update fiche_def set fd_class_base=$1 ".
- "where fd_id=$2";
+ $step=$_SESSION['g_pagesize'];
+ $sql_limit="";
+ $sql_offset="";
+ $bar="";
+ if ( $step != -1 )
+ {
- $Res=$this->cn->exec_sql($sql,array($p_label,$this->id));
+ $page=(isset($_GET['page']))?$_GET['page']:1;
+ $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+ $max_line=$this->cn->count_sql("select f_id,av_text from
+ fiche join jnt_fic_att_value using (f_id)
+ join attr_value using (jft_id)
+ where fd_id='".$this->id."' and ad_id=".ATTR_DEF_NAME." order by f_id");
+ $sql_limit=" limit ".$step;
+ $sql_offset=" offset ".$offset;
+ $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
+ }
+
+ // Get all name the cards of the select category
+ // 1 for attr_def.ad_id is always the name
+ $Res=$this->cn->exec_sql("select f_id,vw_name,quick_code from ".
+ " vw_fiche_attr ".
+ " where fd_id='".$this->id.
+ "' order by f_id $sql_offset $sql_limit ");
+ $Max=Database::num_row($Res);
+ echo $bar;
+ $str="";
+ // save the url
+ // with offet &offset=15&step=15&page=2&size=15
+ if ( $_SESSION['g_pagesize'] != -1)
+ {
+ $str=sprintf("&offset=%s&step=%s&page=%s&size=%s",
+ $offset,
+ $step,
+ $page,
+ $max_line);
+ }
+
+
+ echo '';
+ echo dossier::hidden();
+ echo HtmlInput::hidden("fiche",$this->id);
+ echo HtmlInput::submit('add','Ajout fiche');
+ echo ' ';
+ $str_dossier=dossier::get();
+ echo '';
+ for ( $i = 0; $i < $Max; $i++)
+ {
+ $l_line=Database::fetch_array($Res,$i);
+ if ( $i%2 == 0)
+ echo '';
+ else
+ echo ' ';
+
+ $span_mod=''.$l_line['quick_code'].' ';
+
+ echo $span_mod.''.h($l_line['vw_name'])." ";
+ echo ' ';
+ }
+ echo '
';
+ echo '';
+ echo dossier::hidden();
+ echo HtmlInput::hidden("fiche",$this->id);
+ echo HtmlInput::submit('add','Ajout fiche');
+ echo ' ';
+ echo $bar;
+
+ }
+ /*!\brief show input for the basic attribute : label, class_base, create_account
+ * use only when we want to update
+ *
+ *\return HTML string with the form
+ */
+ function input_base()
+ {
+ $r="";
+ $r.=_('Label');
+ $label=new IText('label',$this->label);
+ $r.=$label->input();
+ $r.=' ';
+ /* the accounting item */
+ $class_base=new IPoste('class_base',$this->class_base);
+ $class_base->set_attribute('ipopup','ipop_account');
+ $class_base->set_attribute('account','class_base');
+ $class_base->set_attribute('label','acc_label');
+ $r.=_('Poste Comptable de base').' : ';
+ $r.=$class_base->input();
+ $r.=' ';
+ /* auto Create */
+ $ck=new ICheckBox('create');
+ $ck->selected=($this->create_account=='f')?false:true;
+ $r.=_('Chaque fiche aura automatiquement son propre poste comptable : ');
+ $r.=$ck->input();
+ return $r;
+ }
+ /*!\brief Display all the attribut of the fiche_def
+ *\param $str give the action possible values are remove, empty
+ */
+ function DisplayAttribut($str="")
+ {
+ if ( $this->id == 0 )
+ return ;
+ /* $this->cn->exec_sql('select fiche_attribut_synchro($1)',
+ array($this->id));
+ */
+ $MaxLine=sizeof($this->attribut);
+ $r="";
+ return $r;
+ }
+ /*!\brief Save the label of the fiche_def
+ * \param $p_label label
+ */
+ function SaveLabel($p_label)
+ {
+ if ( $this->id == 0 ) return;
+ $p_label=FormatString($p_label);
+ if (strlen(trim ($p_label)) == 0 )
+ {
+ return;
+ }
+ $sql=sprintf("update fiche_def set fd_label='%s' ".
+ "where fd_id=%d",
+ $p_label,$this->id);
+ $Res=$this->cn->exec_sql($sql);
+
+ }
+ /*!\brief set the auto create accounting item for each card and
+ * save it into the database
+ * \param $p_label true or false
+ */
+ function set_autocreate($p_label)
+ {
+ if ( $this->id == 0 ) return;
+ if ($p_label==true)
+ $t='t';
+ if ($p_label==false)
+ $t='f';
+
+ $sql="update fiche_def set fd_create_account=$1 ".
+ "where fd_id=$2";
+
+ $Res=$this->cn->exec_sql($sql,array($t,$this->id));
+
+ }
+ /*!\brief Save the class base
+ * \param $p_label label
+ */
+ function save_class_base($p_label)
+ {
+ if ( $this->id == 0 ) return;
+ $p_label=FormatString($p_label);
+
+ $sql="update fiche_def set fd_class_base=$1 ".
+ "where fd_id=$2";
+
+ $Res=$this->cn->exec_sql($sql,array($p_label,$this->id));
}
- /*!\brief insert a new attribut for this fiche_def
- * \param $p_ad_id id of the attribut
- */
- function InsertAttribut($p_ad_id)
+ /*!\brief insert a new attribut for this fiche_def
+ * \param $p_ad_id id of the attribut
+ */
+ function InsertAttribut($p_ad_id)
{
- if ( $this->id == 0 ) return;
- /* ORDER */
- $this->GetAttribut();
- $max=sizeof($this->attribut);
- // Insert a new attribute for the model
- // it means insert a row in jnt_fic_attr
- $sql=sprintf("insert into jnt_fic_attr (fd_id,ad_id,jnt_order) values (%d,%d,%d)",
- $this->id,$p_ad_id,$max);
- $Res=$this->cn->exec_sql($sql);
- // update all the existing card
-
+ if ( $this->id == 0 ) return;
+ /* ORDER */
+ $this->GetAttribut();
+ $max=sizeof($this->attribut);
+ // Insert a new attribute for the model
+ // it means insert a row in jnt_fic_attr
+ $sql=sprintf("insert into jnt_fic_attr (fd_id,ad_id,jnt_order) values (%d,%d,%d)",
+ $this->id,$p_ad_id,$max);
+ $Res=$this->cn->exec_sql($sql);
+ // update all the existing card
+
}
/*!\brief remove an attribut for this fiche_def
* \param array of ad_id to remove
* \remark you can't remove the attribut defined in attr_min
*/
- function RemoveAttribut($array)
- {
- foreach ($array as $ch)
- {
- $this->cn->start();
- $sql="delete from jnt_fic_attr where fd_id=".$this->id.
- " and ad_id=".$ch;
- $this->cn->exec_sql($sql);
+ function RemoveAttribut($array)
+ {
+ foreach ($array as $ch)
+ {
+ $this->cn->start();
+ $sql="delete from jnt_fic_attr where fd_id=".$this->id.
+ " and ad_id=".$ch;
+ $this->cn->exec_sql($sql);
- $sql="delete from attr_value where jft_id in ( select ".
- " jft_id from attr_value join jnt_fic_att_value using (jft_id) ".
- " join fiche using(f_id) ".
- " where ".
- "fd_id = ".$this->id." and ".
- "ad_id=".$ch.")";
- $this->cn->exec_sql($sql);
+ $sql="delete from attr_value where jft_id in ( select ".
+ " jft_id from attr_value join jnt_fic_att_value using (jft_id) ".
+ " join fiche using(f_id) ".
+ " where ".
+ "fd_id = ".$this->id." and ".
+ "ad_id=".$ch.")";
+ $this->cn->exec_sql($sql);
- $sql="delete from jnt_fic_att_value where jft_id in (".
- " select jft_id from jnt_fic_att_value join fiche using (f_id) ".
- " where ".
- " fd_id = ".$this->id." and ".
- " ad_id = ".$ch.")";
- $this->cn->exec_sql($sql);
- $this->cn->commit();
- }
- }
+ $sql="delete from jnt_fic_att_value where jft_id in (".
+ " select jft_id from jnt_fic_att_value join fiche using (f_id) ".
+ " where ".
+ " fd_id = ".$this->id." and ".
+ " ad_id = ".$ch.")";
+ $this->cn->exec_sql($sql);
+ $this->cn->commit();
+ }
+ }
- /*!\brief save the order of a card, update the column jnt_fic_attr.jnt_order
- *\param $p_array containing the order
- */
- function save_order($p_array) {
- extract($p_array);
- $this->GetAttribut();
- foreach ($this->attribut as $row){
- if ( $row->ad_id == 1 ) continue;
- if ( ${'jnt_order'.$row->ad_id} <= 0 ) continue;
- $sql='update jnt_fic_attr set jnt_order=$1 where fd_id=$2 and ad_id=$3';
- $this->cn->exec_sql($sql,array(${'jnt_order'.$row->ad_id},
- $this->id,
- $row->ad_id));
-
- }
- /* correct the order */
- $this->cn->exec_sql('select attribute_correct_order()');
- }
+ /*!\brief save the order of a card, update the column jnt_fic_attr.jnt_order
+ *\param $p_array containing the order
+ */
+ function save_order($p_array)
+ {
+ extract($p_array);
+ $this->GetAttribut();
+ foreach ($this->attribut as $row)
+ {
+ if ( $row->ad_id == 1 ) continue;
+ if ( ${'jnt_order'.$row->ad_id} <= 0 ) continue;
+ $sql='update jnt_fic_attr set jnt_order=$1 where fd_id=$2 and ad_id=$3';
+ $this->cn->exec_sql($sql,array(${'jnt_order'.$row->ad_id},
+ $this->id,
+ $row->ad_id));
+
+ }
+ /* correct the order */
+ $this->cn->exec_sql('select attribute_correct_order()');
+ }
- /*!\brief remove all the card from a categorie after having verify
- *that the card is not used and then remove also the category
- *\return the remains items, not equal to 0 if a card remains and
- *then the category is not removed
- */
- function remove() {
- $remain=0;
- /* get all the card */
- $aFiche=fiche::get_fiche_def($this->cn,$this->id);
- if ( $aFiche != null ) {
- /* check if the card is used */
- foreach ($aFiche as $fiche) {
+ /*!\brief remove all the card from a categorie after having verify
+ *that the card is not used and then remove also the category
+ *\return the remains items, not equal to 0 if a card remains and
+ *then the category is not removed
+ */
+ function remove()
+ {
+ $remain=0;
+ /* get all the card */
+ $aFiche=fiche::get_fiche_def($this->cn,$this->id);
+ if ( $aFiche != null )
+ {
+ /* check if the card is used */
+ foreach ($aFiche as $fiche)
+ {
- /* if the card is not used then remove it otherwise increment remains */
- if ( $fiche->is_used() == false ) {
- $fiche->delete();
- } else
- $remain++;
- }
- }
- /* if remains == 0 then remove cat */
- if ( $remain == 0 ) {
- $sql='delete from jnt_fic_attr where fd_id=$1';
- $this->cn->exec_sql($sql,array($this->id));
- $sql='delete from fiche_def where fd_id=$1';
- $this->cn->exec_sql($sql,array($this->id));
- }
+ /* if the card is not used then remove it otherwise increment remains */
+ if ( $fiche->is_used() == false )
+ {
+ $fiche->delete();
+ }
+ else
+ $remain++;
+ }
+ }
+ /* if remains == 0 then remove cat */
+ if ( $remain == 0 )
+ {
+ $sql='delete from jnt_fic_attr where fd_id=$1';
+ $this->cn->exec_sql($sql,array($this->id));
+ $sql='delete from fiche_def where fd_id=$1';
+ $this->cn->exec_sql($sql,array($this->id));
+ }
- return $remain;
+ return $remain;
- }
-/*!
- * \brief retrieve the mandatory field of the card model
- *
- * \param $p_fiche_def_ref
- * \return array of ad_id (attr_min.ad_id) and labels (attr_def.ad_text)
- */
-function get_attr_min($p_fiche_def_ref) {
+ }
+ /*!
+ * \brief retrieve the mandatory field of the card model
+ *
+ * \param $p_fiche_def_ref
+ * \return array of ad_id (attr_min.ad_id) and labels (attr_def.ad_text)
+ */
+ function get_attr_min($p_fiche_def_ref)
+ {
- // find the min attr for the fiche_def_ref
- $Sql="select ad_id,ad_text from attr_min natural join attr_def
- natural join fiche_def_ref
- where
- frd_id= $1";
- $Res=$this->cn->exec_sql($Sql,array($p_fiche_def_ref));
- $Num=Database::num_row($Res);
+ // find the min attr for the fiche_def_ref
+ $Sql="select ad_id,ad_text from attr_min natural join attr_def
+ natural join fiche_def_ref
+ where
+ frd_id= $1";
+ $Res=$this->cn->exec_sql($Sql,array($p_fiche_def_ref));
+ $Num=Database::num_row($Res);
- // test the number of returned rows
- if ($Num == 0 ) return null;
+ // test the number of returned rows
+ if ($Num == 0 ) return null;
- // Get Results & Store them in a array
- for ($i=0;$i<$Num;$i++) {
- $f=Database::fetch_array($Res,$i);
- $array[$i]['ad_id']=$f['ad_id'];
- $array[$i]['ad_text']=$f['ad_text'];
- }
- return $array;
-}
- /*!\brief count the number of fiche_def (category) which has the frd_id (type of category)
- *\param $p_frd_id is the frd_id in constant.php the FICHE_TYPE_
- *\return the number of cat. of card of the given type
- *\see constant.php
- */
-function count_category($p_frd_id) {
- $ret=$this->cn->count_sql("select fd_id from fiche_def where frd_id=$1",array($p_frd_id));
- return $ret;
-}
+ // Get Results & Store them in a array
+ for ($i=0;$i<$Num;$i++)
+ {
+ $f=Database::fetch_array($Res,$i);
+ $array[$i]['ad_id']=$f['ad_id'];
+ $array[$i]['ad_text']=$f['ad_text'];
+ }
+ return $array;
+ }
+ /*!\brief count the number of fiche_def (category) which has the frd_id (type of category)
+ *\param $p_frd_id is the frd_id in constant.php the FICHE_TYPE_
+ *\return the number of cat. of card of the given type
+ *\see constant.php
+ */
+ function count_category($p_frd_id)
+ {
+ $ret=$this->cn->count_sql("select fd_id from fiche_def where frd_id=$1",array($p_frd_id));
+ return $ret;
+ }
diff --git a/include/class_fiche_def_ref.php b/include/class_fiche_def_ref.php
index 53cba740c..6375f2d49 100644
--- a/include/class_fiche_def_ref.php
+++ b/include/class_fiche_def_ref.php
@@ -1,4 +1,4 @@
-db=$p_cn;
- $this->frd_id=$p_frd_id;
- $this->attribut=array('frd_id','frd_text','frd_class_base');
+ $this->db=$p_cn;
+ $this->frd_id=$p_frd_id;
+ $this->attribut=array('frd_id','frd_text','frd_class_base');
}
-/*!
- **************************************************
- * \brief Load all the fiche_def_ref data and
- * return an array of fiche_def_ref objects
- *
- * \return array
- */
- function LoadAll()
+ /*!
+ **************************************************
+ * \brief Load all the fiche_def_ref data and
+ * return an array of fiche_def_ref objects
+ *
+ * \return array
+ */
+ function LoadAll()
{
- $sql="select * from fiche_def_ref order by frd_id";
- $Res=$this->db->exec_sql($sql);
- $all=Database::fetch_all($Res);
- if ( $Res == false ) return array();
- $idx=0;
- $array=array();
- foreach ($all as $row)
- {
- $o=new Fiche_Def_Ref($this->db);
+ $sql="select * from fiche_def_ref order by frd_id";
+ $Res=$this->db->exec_sql($sql);
+ $all=Database::fetch_all($Res);
+ if ( $Res == false ) return array();
+ $idx=0;
+ $array=array();
+ foreach ($all as $row)
+ {
+ $o=new Fiche_Def_Ref($this->db);
- foreach ( $this->attribut as $value)
- {
- $o->$value=$row[$value];
- }
- $array[$idx]=$o;
- $idx++;
- }
- return $array;
+ foreach ( $this->attribut as $value)
+ {
+ $o->$value=$row[$value];
+ }
+ $array[$idx]=$o;
+ $idx++;
+ }
+ return $array;
}
-/*!
- **************************************************
- * \brief Display data between tag
- *
- * \return string
- */
- function Display()
+ /*!
+ **************************************************
+ * \brief Display data between tag
+ *
+ * \return string
+ */
+ function Display()
{
- $r="";
- foreach ( $this->attribut as $value)
- {
- $r.=" ".$this->$value.' ';
- }
- return $r;
+ $r="";
+ foreach ( $this->attribut as $value)
+ {
+ $r.="".$this->$value.' ';
+ }
+ return $r;
}
-/*!
- **************************************************
- * \brief Input Data between tag
- *
- * \return string
- */
- function Input()
+ /*!
+ **************************************************
+ * \brief Input Data between tag
+ *
+ * \return string
+ */
+ function Input()
{
- $r="";
- $h=new IHidden();
- $r.='Id :'.$h->input('frd_id',$this->frd_id).$this->frd_id." ";
- $w=new IText();
- $r.='Commentaire :'.$w->input('frd_text',$this->frd_text)." ";
- $t=new IText();
- $r.='Poste de base:'.$t->input('frd_class_base',$this->frd_class_base)." ";
+ $r="";
+ $h=new IHidden();
+ $r.='Id :'.$h->input('frd_id',$this->frd_id).$this->frd_id." ";
+ $w=new IText();
+ $r.='Commentaire :'.$w->input('frd_text',$this->frd_text)." ";
+ $t=new IText();
+ $r.='Poste de base:'.$t->input('frd_class_base',$this->frd_class_base)." ";
- return $r;
+ return $r;
}
-/*!
- **************************************************
- * \brief Store data into the database: update the
- * record
- *
- * -
- * \return none
- */
- function Save()
+ /*!
+ **************************************************
+ * \brief Store data into the database: update the
+ * record
+ *
+ * -
+ * \return none
+ */
+ function Save()
{
- $sql="update fiche_def_ref set frd_text=$1 ".
- " , frd_class_base=$2 ".
- " where frd_id= $3";
- $Res=$this->db->exec_sql($sql,array($this->frd_text,$this->frd_class_base,$this->frd_id));
+ $sql="update fiche_def_ref set frd_text=$1 ".
+ " , frd_class_base=$2 ".
+ " where frd_id= $3";
+ $Res=$this->db->exec_sql($sql,array($this->frd_text,$this->frd_class_base,$this->frd_id));
}
-/*!
- **************************************************
- * \brief Get the data with the p_code and complete
- * the current object
- *
- * \return none
- */
- function Get()
+ /*!
+ **************************************************
+ * \brief Get the data with the p_code and complete
+ * the current object
+ *
+ * \return none
+ */
+ function Get()
{
- $sql="select * from fiche_def_ref ".
- " where frd_id=".$this->frd_id;
- $Res=$this->db->exec_sql($sql);
- if ( Database::num_row($Res) == 0 ) return null;
- $r=Database::fetch_array($Res,0);
- $this->frd_text=$r['frd_text'];
- $this->frd_class_base=$r['frd_class_base'];
+ $sql="select * from fiche_def_ref ".
+ " where frd_id=".$this->frd_id;
+ $Res=$this->db->exec_sql($sql);
+ if ( Database::num_row($Res) == 0 ) return null;
+ $r=Database::fetch_array($Res,0);
+ $this->frd_text=$r['frd_text'];
+ $this->frd_class_base=$r['frd_class_base'];
}
}
diff --git a/include/class_forecast.php b/include/class_forecast.php
index a161afeb4..0f5b20bf6 100644
--- a/include/class_forecast.php
+++ b/include/class_forecast.php
@@ -28,102 +28,121 @@
*/
class Forecast
{
- private static $variable=array ("id"=>"f_id","name"=>"f_name");
- private $cn;
- /**
- * @brief constructor
- * @param $p_init Database object
- */
- function __construct ($p_init,$p_id=0) {
- $this->cn=$p_init;
- $this->f_id=$p_id;
- }
- public function get_parameter($p_string) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- return $this->$idx;
- }
- else
- exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
- }
- public function set_parameter($p_string,$p_value) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- $this->$idx=$p_value;
- }
- else
- exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
- }
- public function get_info() { return var_export(self::$variable,true); }
+ private static $variable=array ("id"=>"f_id","name"=>"f_name");
+ private $cn;
+ /**
+ * @brief constructor
+ * @param $p_init Database object
+ */
+ function __construct ($p_init,$p_id=0)
+ {
+ $this->cn=$p_init;
+ $this->f_id=$p_id;
+ }
+ public function get_parameter($p_string)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ return $this->$idx;
+ }
+ else
+ exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
+ }
+ public function set_parameter($p_string,$p_value)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ $this->$idx=$p_value;
+ }
+ else
+ exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
+ }
+ public function get_info()
+ {
+ return var_export(self::$variable,true);
+ }
- public function verify() {
- // Verify that the elt we want to add is correct
- // the f_name must be unique (case insensitive)
- if ( strlen(trim($this->f_name))==0) throw new Exception(_('Le nom ne peut pas être vide'));
- return 0;
- }
- public function save() {
- /* please adapt */
- if ( $this->get_parameter("id") == 0 )
- $this->insert();
- else
- $this->update();
- }
+ public function verify()
+ {
+ // Verify that the elt we want to add is correct
+ // the f_name must be unique (case insensitive)
+ if ( strlen(trim($this->f_name))==0) throw new Exception(_('Le nom ne peut pas être vide'));
+ return 0;
+ }
+ public function save()
+ {
+ /* please adapt */
+ if ( $this->get_parameter("id") == 0 )
+ $this->insert();
+ else
+ $this->update();
+ }
- public function insert() {
- if ( $this->verify() != 0 ) return;
- $sql="insert into forecast (f_name) ".
- " values ($1) returning f_id";
- $res=$this->cn->exec_sql(
- $sql,
- array($this->f_name)
- );
- $this->f_id=Database::fetch_result($res,0,0);
- }
+ public function insert()
+ {
+ if ( $this->verify() != 0 ) return;
+ $sql="insert into forecast (f_name) ".
+ " values ($1) returning f_id";
+ $res=$this->cn->exec_sql(
+ $sql,
+ array($this->f_name)
+ );
+ $this->f_id=Database::fetch_result($res,0,0);
+ }
- /**
- *@brief update the forecast table
- */
- public function update() {
- if ( $this->verify() != 0 ) return;
+ /**
+ *@brief update the forecast table
+ */
+ public function update()
+ {
+ if ( $this->verify() != 0 ) return;
- $sql="update forecast set f_name=$1 ".
- " where f_id = $2";
- $res=$this->cn->exec_sql(
- $sql,
- array($this->f_name, $this->f_id)
- );
+ $sql="update forecast set f_name=$1 ".
+ " where f_id = $2";
+ $res=$this->cn->exec_sql(
+ $sql,
+ array($this->f_name, $this->f_id)
+ );
- }
- /**
- *@brief load all the existing forecast
- *@param $p_cn is an Database object
- *@return array of f_id and f_name
- */
- public static function load_all($p_cn) {
- $sql="select f_id, f_name from forecast";
- $ret=$p_cn->get_array($sql);
- return $ret;
- }
- public function load() {
- $sql="select f_name from forecast where f_id=$1";
- $res=$this->cn->exec_sql(
- $sql,
- array($this->f_id)
- );
- if ( Database::num_row($res) == 0 ) return -1;
- $row=Database::fetch_array($res,0);
- foreach ($row as $idx=>$value) { $this->$idx=$value; }
- }
- public function delete() {
- $sql="delete from forecast where f_id=$1";
- $res=$this->cn->exec_sql($sql,array($this->f_id));
- }
- /**
- * @brief unit test
- */
- static function test_me() {
- }
+ }
+ /**
+ *@brief load all the existing forecast
+ *@param $p_cn is an Database object
+ *@return array of f_id and f_name
+ */
+ public static function load_all($p_cn)
+ {
+ $sql="select f_id, f_name from forecast";
+ $ret=$p_cn->get_array($sql);
+ return $ret;
+ }
+ public function load()
+ {
+ $sql="select f_name from forecast where f_id=$1";
+ $res=$this->cn->exec_sql(
+ $sql,
+ array($this->f_id)
+ );
+ if ( Database::num_row($res) == 0 ) return -1;
+ $row=Database::fetch_array($res,0);
+ foreach ($row as $idx=>$value)
+ {
+ $this->$idx=$value;
+ }
+
+ }
+ public function delete()
+ {
+ $sql="delete from forecast where f_id=$1";
+ $res=$this->cn->exec_sql($sql,array($this->f_id));
+ }
+ /**
+ * @brief unit test
+ */
+ static function test_me()
+ {}
}
?>
diff --git a/include/class_forecast_cat.php b/include/class_forecast_cat.php
index befda7649..e3f7239eb 100644
--- a/include/class_forecast_cat.php
+++ b/include/class_forecast_cat.php
@@ -33,120 +33,143 @@
*/
class Forecast_Cat
{
- /* example private $variable=array("val1"=>1,"val2"=>"Seconde valeur","val3"=>0); */
- private static $variable=array ("id"=>"fc_id","order"=>"fc_order","desc"=>"fc_desc","forecast"=>"f_id");
- private $cn;
- /**
- * @brief constructor
- * @param $p_init Database object
- */
- function __construct ($p_init,$p_id=0) {
- $this->cn=$p_init;
- $this->fc_id=$p_id;
- }
- public function get_parameter($p_string) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- return $this->$idx;
+ /* example private $variable=array("val1"=>1,"val2"=>"Seconde valeur","val3"=>0); */
+ private static $variable=array ("id"=>"fc_id","order"=>"fc_order","desc"=>"fc_desc","forecast"=>"f_id");
+ private $cn;
+ /**
+ * @brief constructor
+ * @param $p_init Database object
+ */
+ function __construct ($p_init,$p_id=0)
+ {
+ $this->cn=$p_init;
+ $this->fc_id=$p_id;
}
- else
- exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
- }
- public function set_parameter($p_string,$p_value) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- $this->$idx=$p_value;
+ public function get_parameter($p_string)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ return $this->$idx;
+ }
+ else
+ exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
}
- else
- exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
+ public function set_parameter($p_string,$p_value)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ $this->$idx=$p_value;
+ }
+ else
+ exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
- }
- public function get_info() { return var_export(self::$variable,true); }
- public function verify() {
- if (strlen(trim($this->fc_order))==0){
- $this->fc_order="1";
- }
- // Verify that the elt we want to add is correct
- // the f_name must be unique (case insensitive)
- return 0;
- }
- public function save() {
- if ( $this->get_parameter("id") == 0 )
- $this->insert();
- else
- $this->update();
- }
+ }
+ public function get_info()
+ {
+ return var_export(self::$variable,true);
+ }
+ public function verify()
+ {
+ if (strlen(trim($this->fc_order))==0)
+ {
+ $this->fc_order="1";
+ }
+ // Verify that the elt we want to add is correct
+ // the f_name must be unique (case insensitive)
+ return 0;
+ }
+ public function save()
+ {
+ if ( $this->get_parameter("id") == 0 )
+ $this->insert();
+ else
+ $this->update();
+ }
- public function insert() {
- if ( $this->verify() != 0 ) return;
+ public function insert()
+ {
+ if ( $this->verify() != 0 ) return;
- $sql="insert into forecast_cat (fc_desc,fc_order,f_id) ".
- " values ($1,$2,$3) returning fc_id";
- $res=$this->cn->exec_sql(
- $sql,
- array($this->fc_desc,$this->fc_order,$this->f_id)
- );
- $this->fc_id=Database::fetch_result($res,0,0);
- }
+ $sql="insert into forecast_cat (fc_desc,fc_order,f_id) ".
+ " values ($1,$2,$3) returning fc_id";
+ $res=$this->cn->exec_sql(
+ $sql,
+ array($this->fc_desc,$this->fc_order,$this->f_id)
+ );
+ $this->fc_id=Database::fetch_result($res,0,0);
+ }
- public function update() {
- if ( $this->verify() != 0 ) return;
+ public function update()
+ {
+ if ( $this->verify() != 0 ) return;
- $sql="update forecast_cat set fc_desc=$1,f_id=$2,fc_order=$3 ".
- " where fc_id = $4";
- $res=$this->cn->exec_sql(
- $sql,
- array($this->fc_desc,$this->f_id, $this->fc_order,$this->fc_id)
- );
- }
- /**
- *@brief Load all the cat. for a given forecast and return them into a array
- *@param $p_cn database connx
- *@param $p_id is the forecast id (f_id)
- *@return an array with all the data
- */
- public static function load_all($p_cn,$p_id) {
- $sql="select fc_id,fc_desc,fc_order from forecast_cat where f_id=$1";
+ $sql="update forecast_cat set fc_desc=$1,f_id=$2,fc_order=$3 ".
+ " where fc_id = $4";
+ $res=$this->cn->exec_sql(
+ $sql,
+ array($this->fc_desc,$this->f_id, $this->fc_order,$this->fc_id)
+ );
+ }
+ /**
+ *@brief Load all the cat. for a given forecast and return them into a array
+ *@param $p_cn database connx
+ *@param $p_id is the forecast id (f_id)
+ *@return an array with all the data
+ */
+ public static function load_all($p_cn,$p_id)
+ {
+ $sql="select fc_id,fc_desc,fc_order from forecast_cat where f_id=$1";
- $res=$p_cn->get_array($sql,array($p_id));
+ $res=$p_cn->get_array($sql,array($p_id));
- return $res;
- }
- public function load() {
+ return $res;
+ }
+ public function load()
+ {
- $sql="select fc_desc, f_id,fc_order from forecast_cat where fc_id=$1";
+ $sql="select fc_desc, f_id,fc_order from forecast_cat where fc_id=$1";
- $res=$this->cn->exec_sql(
- $sql,
- array($this->fc_id)
- );
+ $res=$this->cn->exec_sql(
+ $sql,
+ array($this->fc_id)
+ );
- if ( Database::num_row($res) == 0 ) return;
- $row=Database::fetch_array($res,0);
- foreach ($row as $idx=>$value) { $this->$idx=$value; }
- }
- /**
- *@brief Make a array for a ISelect of the available cat
- *@param $id is forecast::f_id
- *@return array for ISelect
- *@see ISelect
- */
- public function make_array($id) {
- $sql="select fc_id,fc_desc from forecast_cat where f_id=$id";
- $ret=$this->cn->make_array($sql);
- return $ret;
- }
- public function delete() {
- $sql="delete from forecast_cat where fc_id=$1";
- $res=$this->cn->exec_sql($sql,array($this->fc_id));
- }
- /**
- * @brief unit test
- */
- static function test_me() {
- }
+ if ( Database::num_row($res) == 0 ) return;
+ $row=Database::fetch_array($res,0);
+ foreach ($row as $idx=>$value)
+ {
+ $this->$idx=$value;
+ }
+
+ }
+ /**
+ *@brief Make a array for a ISelect of the available cat
+ *@param $id is forecast::f_id
+ *@return array for ISelect
+ *@see ISelect
+ */
+ public function make_array($id)
+ {
+ $sql="select fc_id,fc_desc from forecast_cat where f_id=$id";
+ $ret=$this->cn->make_array($sql);
+ return $ret;
+ }
+ public function delete()
+ {
+ $sql="delete from forecast_cat where fc_id=$1";
+ $res=$this->cn->exec_sql($sql,array($this->fc_id));
+ }
+ /**
+ * @brief unit test
+ */
+ static function test_me()
+ {}
}
- ?>
\ No newline at end of file
+?>
+?>
+?>
\ No newline at end of file
diff --git a/include/class_forecast_item.php b/include/class_forecast_item.php
index a79e89ef2..611a4af50 100644
--- a/include/class_forecast_item.php
+++ b/include/class_forecast_item.php
@@ -34,114 +34,134 @@
*/
class Forecast_Item
{
- /* example private $variable=array("val1"=>1,"val2"=>"Seconde valeur","val3"=>0); */
- private static $variable=array ("id"=>"fi_id","text"=>"fi_text","account"=>"fi_account",
- "card"=>"fi_card","order"=>"fi_order","cat_id"=>"fc_id","amount"=>"fi_amount","debit"=>"fi_debit","periode"=>"fi_pid");
- private $cn;
- /**
- * @brief constructor
- * @param $p_init Database object
- */
- function __construct ($p_init,$p_id=0) {
- $this->cn=$p_init;
- $this->fi_id=$p_id;
- }
- public function get_parameter($p_string) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- return $this->$idx;
+ /* example private $variable=array("val1"=>1,"val2"=>"Seconde valeur","val3"=>0); */
+ private static $variable=array ("id"=>"fi_id","text"=>"fi_text","account"=>"fi_account",
+ "card"=>"fi_card","order"=>"fi_order","cat_id"=>"fc_id","amount"=>"fi_amount","debit"=>"fi_debit","periode"=>"fi_pid");
+ private $cn;
+ /**
+ * @brief constructor
+ * @param $p_init Database object
+ */
+ function __construct ($p_init,$p_id=0)
+ {
+ $this->cn=$p_init;
+ $this->fi_id=$p_id;
}
- else
- exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
- }
- public function set_parameter($p_string,$p_value) {
- if ( array_key_exists($p_string,self::$variable) ) {
- $idx=self::$variable[$p_string];
- $this->$idx=$p_value;
+ public function get_parameter($p_string)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ return $this->$idx;
+ }
+ else
+ exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
}
- else
- exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
+ public function set_parameter($p_string,$p_value)
+ {
+ if ( array_key_exists($p_string,self::$variable) )
+ {
+ $idx=self::$variable[$p_string];
+ $this->$idx=$p_value;
+ }
+ else
+ exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
- }
- public function get_info() { return var_export(self::$variable,true); }
- public function verify() {
- // Verify that the elt we want to add is correct
- // the f_name must be unique (case insensitive)
- return 0;
- }
- public function save() {
- /* please adapt */
- if ( $this->get_parameter("id") == 0 )
- $this->insert();
- else
- $this->update();
- }
+ }
+ public function get_info()
+ {
+ return var_export(self::$variable,true);
+ }
+ public function verify()
+ {
+ // Verify that the elt we want to add is correct
+ // the f_name must be unique (case insensitive)
+ return 0;
+ }
+ public function save()
+ {
+ /* please adapt */
+ if ( $this->get_parameter("id") == 0 )
+ $this->insert();
+ else
+ $this->update();
+ }
- public function insert() {
- if ( $this->verify() != 0 ) return;
+ public function insert()
+ {
+ if ( $this->verify() != 0 ) return;
- $sql="INSERT INTO forecast_item(
+ $sql="INSERT INTO forecast_item(
fi_text, fi_account, fi_card, fi_order, fc_id, fi_amount,
- fi_debit,fi_pid)
- VALUES ($1, $2, $3, $4, $5, $6, $7,$8) returning fi_id;";
- $res=$this->cn->exec_sql(
- $sql,
- array($this->fi_text,$this->fi_account,$this->fi_card,$this->fi_order,$this->fc_id,$this->fi_amount,$this->fi_debit,$this->fi_pid)
- );
- $this->fi_id=Database::fetch_result($res,0,0);
- }
+ fi_debit,fi_pid)
+ VALUES ($1, $2, $3, $4, $5, $6, $7,$8) returning fi_id;";
+ $res=$this->cn->exec_sql(
+ $sql,
+ array($this->fi_text,$this->fi_account,$this->fi_card,$this->fi_order,$this->fc_id,$this->fi_amount,$this->fi_debit,$this->fi_pid)
+ );
+ $this->fi_id=Database::fetch_result($res,0,0);
+ }
- public function update() {
- if ( $this->verify() != 0 ) return;
+ public function update()
+ {
+ if ( $this->verify() != 0 ) return;
- $sql="UPDATE forecast_item
- SET fi_text=$1, fi_account=$2, fi_card=$3, fi_order=$4, fc_id=$5,
- fi_amount=$6, fi_debit=$7,fi_pid=$8
- WHERE fi_id=$9;";
- $res=$this->cn->exec_sql($sql,
- array($this->fi_text,
- $this->fi_account,
- $this->fi_card,
- $this->fi_order,
- $this->fc_id,
- $this->fi_amount,
- $this->fi_debit,
- $this->fi_pid,
- $this->fi_id)
- );
+ $sql="UPDATE forecast_item
+ SET fi_text=$1, fi_account=$2, fi_card=$3, fi_order=$4, fc_id=$5,
+ fi_amount=$6, fi_debit=$7,fi_pid=$8
+ WHERE fi_id=$9;";
+ $res=$this->cn->exec_sql($sql,
+ array($this->fi_text,
+ $this->fi_account,
+ $this->fi_card,
+ $this->fi_order,
+ $this->fc_id,
+ $this->fi_amount,
+ $this->fi_debit,
+ $this->fi_pid,
+ $this->fi_id)
+ );
- }
+ }
- public function load() {
+ public function load()
+ {
- $sql="SELECT fi_id, fi_text, fi_account, fi_card, fi_order, fc_id, fi_amount,
- fi_debit,fi_pid
- FROM forecast_item where fi_id=$1";
+ $sql="SELECT fi_id, fi_text, fi_account, fi_card, fi_order, fc_id, fi_amount,
+ fi_debit,fi_pid
+ FROM forecast_item where fi_id=$1";
- $res=$this->cn->exec_sql(
- $sql,
- array($this->fi_id)
- );
+ $res=$this->cn->exec_sql(
+ $sql,
+ array($this->fi_id)
+ );
- if ( Database::num_row($res) == 0 ) return;
- $row=Database::fetch_array($res,0);
- foreach ($row as $idx=>$value) { $this->$idx=$value; }
- }
+ if ( Database::num_row($res) == 0 ) return;
+ $row=Database::fetch_array($res,0);
+ foreach ($row as $idx=>$value)
+ {
+ $this->$idx=$value;
+ }
+
+ }
- public function delete() {
- $sql="delete from forecast_item where fi_id=$1";
- $res=$this->cn->exec_sql($sql,array($this->fi_id));
- }
- /**
- * @brief unit test
- */
- static function test_me() {
- }
+ public function delete()
+ {
+ $sql="delete from forecast_item where fi_id=$1";
+ $res=$this->cn->exec_sql($sql,array($this->fi_id));
+ }
+ /**
+ * @brief unit test
+ */
+ static function test_me()
+ {}
}
- ?>
\ No newline at end of file
+?>
+?>
+?>
\ No newline at end of file
diff --git a/include/class_gestion_purchase.php b/include/class_gestion_purchase.php
index 50189e60a..396882b51 100644
--- a/include/class_gestion_purchase.php
+++ b/include/class_gestion_purchase.php
@@ -20,7 +20,7 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*!\file
+/*!\file
* \brief Definition of the class gestion_purchase
*/
@@ -32,91 +32,95 @@ require_once ('class_gestion_table.php');
class gestion_purchase extends gestion_table
{
- var $qp_id; /*!< id */
- var $qp_internal; /*!< internal code */
- var $qp_fiche; /*!< card id (fiche.f_id) */
- var $qp_quantite; /*!< quantity */
- var $qp_price; /*!< quantity */
- var $qp_vat; /*!< vat amount */
- var $qp_vat_code; /*!< vat_code */
- var $qp_nd_amount; /*!< no deductible */
- var $qp_nd_tva; /*!< tva not deductible */
- var $qp_nd_tva_recup; /*!< tva ded via taxe */
- var $qp_supplier; /*!< supplier code (f_id) */
- var $qp_valid;
- var $j_id; /*!< jrnx.j_id
- */
- var $qp_dep_priv; /*!< private purchase */
- /*!\brief return an array of gestion_table, the object are
- * retrieved thanks the qs_internal
- */
- function get_list() {
- if ($this->qp_internal=="")
- exit (__FILE__.__LINE__." qs_internal est vide");
- $sql="select qp_id,
- qp_internal,
- qp_fiche,
- qp_quantite,
- qp_price,
- qp_vat,
- qp_vat_code,
- tva_rate,
- tva_label,
- qp_nd_amount,
- qp_nd_tva,
- qp_nd_tva_recup,
- qp_supplier,
- j_id,
- qp_dep_priv
- from quant_purchase left join tva_rate on (qp_vat_code=tva_id)
- where qp_internal='".$this->qp_internal."'";
- $ret=$this->db->exec_sql($sql);
- // $res contains all the line
- $res=Database::fetch_all($ret);
+ var $qp_id; /*!< id */
+ var $qp_internal; /*!< internal code */
+ var $qp_fiche; /*!< card id (fiche.f_id) */
+ var $qp_quantite; /*!< quantity */
+ var $qp_price; /*!< quantity */
+ var $qp_vat; /*!< vat amount */
+ var $qp_vat_code; /*!< vat_code */
+ var $qp_nd_amount; /*!< no deductible */
+ var $qp_nd_tva; /*!< tva not deductible */
+ var $qp_nd_tva_recup; /*!< tva ded via taxe */
+ var $qp_supplier; /*!< supplier code (f_id) */
+ var $qp_valid;
+ var $j_id; /*!< jrnx.j_id
+ */
+ var $qp_dep_priv; /*!< private purchase */
+ /*!\brief return an array of gestion_table, the object are
+ * retrieved thanks the qs_internal
+ */
+ function get_list()
+ {
+ if ($this->qp_internal=="")
+ exit (__FILE__.__LINE__." qs_internal est vide");
+ $sql="select qp_id,
+ qp_internal,
+ qp_fiche,
+ qp_quantite,
+ qp_price,
+ qp_vat,
+ qp_vat_code,
+ tva_rate,
+ tva_label,
+ qp_nd_amount,
+ qp_nd_tva,
+ qp_nd_tva_recup,
+ qp_supplier,
+ j_id,
+ qp_dep_priv
+ from quant_purchase left join tva_rate on (qp_vat_code=tva_id)
+ where qp_internal='".$this->qp_internal."'";
+ $ret=$this->db->exec_sql($sql);
+ // $res contains all the line
+ $res=Database::fetch_all($ret);
- if ( sizeof($res)==0) return null;
- $count=0;
- foreach ($res as $row) {
- $t_gestion_purchase=new gestion_purchase($this->db);
- foreach ($row as $idx=>$value)
- $t_gestion_purchase->$idx=$value;
- $array[$count]=clone $t_gestion_purchase;
- $count++;
- }
- return $array;
- }
- function search_by_jid($p_jid) {
- $res=$this->db->exec_sql("select qp_id from quant_purchase where j_id=".$p_jid);
+ if ( sizeof($res)==0) return null;
+ $count=0;
+ foreach ($res as $row)
+ {
+ $t_gestion_purchase=new gestion_purchase($this->db);
+ foreach ($row as $idx=>$value)
+ $t_gestion_purchase->$idx=$value;
+ $array[$count]=clone $t_gestion_purchase;
+ $count++;
+ }
+ return $array;
+ }
+ function search_by_jid($p_jid)
+ {
+ $res=$this->db->exec_sql("select qp_id from quant_purchase where j_id=".$p_jid);
- if ( Database::num_row($res) == 1)
- $this->qp_id=Database::fetch_result($res,0,0);
- else
- $this->qp_id=0;
- }
- function load() {
- $sql="select qp_id,
- qp_internal,
- qp_fiche,
- qp_quantite,
- qp_price,
- qp_vat,
- qp_vat_code,
- qp_nd_amount,
- qp_nd_tva,
- qp_nd_tva_recup,
- qp_supplier,
- j_id,
- qp_dep_priv
- from quant_purchase
- where qp_id=".$this->qp_id;
- $ret=$this->db->exec_sql($sql);
- // $res contains all the line
- $res=Database::fetch_all($ret);
+ if ( Database::num_row($res) == 1)
+ $this->qp_id=Database::fetch_result($res,0,0);
+ else
+ $this->qp_id=0;
+ }
+ function load()
+ {
+ $sql="select qp_id,
+ qp_internal,
+ qp_fiche,
+ qp_quantite,
+ qp_price,
+ qp_vat,
+ qp_vat_code,
+ qp_nd_amount,
+ qp_nd_tva,
+ qp_nd_tva_recup,
+ qp_supplier,
+ j_id,
+ qp_dep_priv
+ from quant_purchase
+ where qp_id=".$this->qp_id;
+ $ret=$this->db->exec_sql($sql);
+ // $res contains all the line
+ $res=Database::fetch_all($ret);
- if ( empty($res) ) return null;
- foreach ($res[0] as $idx=>$value)
- $this->$idx=$value;
+ if ( empty($res) ) return null;
+ foreach ($res[0] as $idx=>$value)
+ $this->$idx=$value;
- }
+ }
}
diff --git a/include/class_gestion_sold.php b/include/class_gestion_sold.php
index 1663dcaec..29c4f1f14 100644
--- a/include/class_gestion_sold.php
+++ b/include/class_gestion_sold.php
@@ -20,62 +20,64 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*!\file
+/*!\file
* \brief definition of the class gestion_sold
*/
- /*! \brief this object handles the table quant_sold
- *
- */
+/*! \brief this object handles the table quant_sold
+ *
+ */
require_once ('class_gestion_table.php');
class gestion_sold extends gestion_table
{
- var $qs_id; /*!< $qs_id primary key */
- var $qs_internal; /*!< qs_internal */
- var $qs_fiche; /*!< f_id code */
- var $qs_quantite; /*!< quantity of the card */
- var $qs_price; /*!< price */
- var $qs_vat; /*!< vat_amount */
- var $qs_vat_code; /*!< vat_code */
- var $qs_client; /*!< f_id of the customer */
- var $qs_valid; /*!< will not be used */
- var $j_id; /*!< jrnx.j_id */
- /*!\brief return an array of gestion_table, the object are
- * retrieved thanks the qs_internal
- */
- function get_list() {
- if ($this->qs_internal=="")
- exit (__FILE__.__LINE__." qs_internal est vide");
- $sql="select qs_id,
- qs_internal,
- qs_fiche,
- qs_quantite,
- qs_price,
- qs_vat,
- tva_label,
- tva_rate,
- qs_vat_code,
- qs_client,
- j_id
- from quant_sold left join tva_rate on (qs_vat_code=tva_id)
- where qs_internal='".$this->qs_internal."'";
- $ret=$this->db->exec_sql($sql);
- // $res contains all the line
- $res=Database::fetch_all($ret);
+ var $qs_id; /*!< $qs_id primary key */
+ var $qs_internal; /*!< qs_internal */
+ var $qs_fiche; /*!< f_id code */
+ var $qs_quantite; /*!< quantity of the card */
+ var $qs_price; /*!< price */
+ var $qs_vat; /*!< vat_amount */
+ var $qs_vat_code; /*!< vat_code */
+ var $qs_client; /*!< f_id of the customer */
+ var $qs_valid; /*!< will not be used */
+ var $j_id; /*!< jrnx.j_id */
+ /*!\brief return an array of gestion_table, the object are
+ * retrieved thanks the qs_internal
+ */
+ function get_list()
+ {
+ if ($this->qs_internal=="")
+ exit (__FILE__.__LINE__." qs_internal est vide");
+ $sql="select qs_id,
+ qs_internal,
+ qs_fiche,
+ qs_quantite,
+ qs_price,
+ qs_vat,
+ tva_label,
+ tva_rate,
+ qs_vat_code,
+ qs_client,
+ j_id
+ from quant_sold left join tva_rate on (qs_vat_code=tva_id)
+ where qs_internal='".$this->qs_internal."'";
+ $ret=$this->db->exec_sql($sql);
+ // $res contains all the line
+ $res=Database::fetch_all($ret);
- if ( sizeof($res)==0) return null;
- $count=0;
+ if ( sizeof($res)==0) return null;
+ $count=0;
- foreach ($res as $row) {
- $t_gestion_sold=new gestion_sold($this->db);
- foreach ($row as $idx=>$value)
- $t_gestion_sold->$idx=$value;
- $array[$count]=clone $t_gestion_sold;
- $count++;
- }
- return $array;
- }
+ foreach ($res as $row)
+ {
+ $t_gestion_sold=new gestion_sold($this->db);
+ foreach ($row as $idx=>$value)
+ $t_gestion_sold->$idx=$value;
+ $array[$count]=clone $t_gestion_sold;
+ $count++;
+ }
+ return $array;
+ }
}
diff --git a/include/class_gestion_table.php b/include/class_gestion_table.php
index 322541c1b..d80331198 100644
--- a/include/class_gestion_table.php
+++ b/include/class_gestion_table.php
@@ -20,18 +20,19 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*!\file
+/*!\file
* \brief definition of gestion_table
*/
-/*! \brief mother class for gestion
+/*! \brief mother class for gestion
*
*/
-class gestion_table
+class gestion_table
{
- var $db; /*!< $db database connection */
- /*!\brief contains only the dabase connx */
- function gestion_table($p_cn) {
- $this->db=$p_cn;
- }
+ var $db; /*!< $db database connection */
+ /*!\brief contains only the dabase connx */
+ function gestion_table($p_cn)
+ {
+ $this->db=$p_cn;
+ }
}
diff --git a/include/class_html_input.php b/include/class_html_input.php
index 21ced8217..16f9372ef 100755
--- a/include/class_html_input.php
+++ b/include/class_html_input.php
@@ -67,261 +67,291 @@
* it is the journal id. If empty, there is no link with a ledger
*
*/
-class HtmlInput {
+class HtmlInput
+{
- var $type; /*!< $type type of the widget */
- var $name; /*!< $name field NAME of the INPUT */
- var $value; /*!< $value what the INPUT contains */
- var $readOnly; /*!< $readonly true : we cannot change value */
- var $size; /*!< $size size of the input */
- var $selected; /*!< $selected for SELECT RADIO and CHECKBOX the selected value */
- var $table; /*!< $table =1 add the table tag */
- var $label; /*!< $label the question before the input */
- var $disabled; /*!< $disabled poss. value == true or nothing, to disable INPUT*/
- var $extra; /*!< $extra different usage, it depends of the $type */
- var $extra2; /*!< $extra2 different usage,
- it depends of the $type */
- var $javascript; /*!< $javascript is the javascript to add to the widget */
- var $ctrl; /*!<$ctrl is the control to update (see js_search_card_control) */
+ var $type; /*!< $type type of the widget */
+ var $name; /*!< $name field NAME of the INPUT */
+ var $value; /*!< $value what the INPUT contains */
+ var $readOnly; /*!< $readonly true : we cannot change value */
+ var $size; /*!< $size size of the input */
+ var $selected; /*!< $selected for SELECT RADIO and CHECKBOX the selected value */
+ var $table; /*!< $table =1 add the table tag */
+ var $label; /*!< $label the question before the input */
+ var $disabled; /*!< $disabled poss. value == true or nothing, to disable INPUT*/
+ var $extra; /*!< $extra different usage, it depends of the $type */
+ var $extra2; /*!< $extra2 different usage,
+ it depends of the $type */
+ var $javascript; /*!< $javascript is the javascript to add to the widget */
+ var $ctrl; /*!<$ctrl is the control to update (see js_search_card_control) */
- var $tabindex;
- function __construct($p_name="",$p_value="") {
- $this->name=$p_name;
- $this->readOnly=false;
- $this->size=20;
- $this->width=50;
- $this->heigh=20;
- $this->value=$p_value;
- $this->selected="";
- $this->table=0;
- $this->disabled=false;
- $this->javascript="";
- $this->extra2="all";
- $this->attribute=array();
-
- }
- function setReadOnly($p_read) {
- $this->readonly=$p_read;
- }
- /*!\brief set the extra javascript property for the INPUT field
- *\param $p_name name of the parameter
- *\param $p_value default value of this parameter
- */
- public function set_attribute($p_name,$p_value) {
- $this->attribute[]=array($p_name,$p_value);
- $this->$p_name=$p_value;
- }
- /**
- *@brief you can add attribute to this in javascript
- * this function is a wrapper and create a script (in js) to modify
- * "this" (in javascript) with the value of obj->attribute from PHP
- *@return return string with the javascript code
- */
- public function get_js_attr(){
- require_once('function_javascript.php');
- $attr="";
- if ( count($this->attribute) == 0) return "";
-
- /* Add properties at the widget */
- for ($i=0;$i< count($this->attribute);$i++){
- list($name,$value)=$this->attribute[$i];
- $tmp1=sprintf("$('%s').%s='%s';",
- $this->name,
- $name,
- $value);
- $attr.=$tmp1;
- }
- $attr=create_script($attr);
- return $attr;
- }
- /**
- * Make a JSON object, this method create a javascript object
- * with the attribute set, it returns a javascript string with the object
- * @param $p_name : name of the object, can be null. If the name is not null, return
- * $p_name={} otherwise only the object {}
- * @return javascript string with the object
- * @note: there is not check on the key->value, so you could need to escape
- * special char as quote, single-quote...
- * @code
-$a=new IButton()
-$a->set_attribute('prop','1');
-$a->set_attribute('prop','2');
-$a->set_attribute('prop','3');
-$string = $a->make_object('property');
-echo $string => property={'prop':'1','prop2':'2','prop3':'3'};
-$string = $a->make_object(null);
-echo $string => {'prop':'1','prop2':'2','prop3':'3'};
-@endcode
- */
- public function make_object($p_name=null) {
- $name=($p_name != null)?$p_name.'=':'';
- if ( count($this->attribute) == 0) return $name."{}";
- $ret=$name."{"; $and='';
-
- for ($i=0;$i< count($this->attribute);$i++){
- list($name,$value)=$this->attribute[$i];
- $tmp1=sprintf($and."'%s':'%s'",
- $name,
- $value);
- $ret.=$tmp1; $and=',';
- }
-
- $ret.='}';
- return $ret;
- }
- //#####################################################################
- /* Debug
- */
- function debug() {
- echo "Type ".$this->type." ";
- echo "name ".$this->name." ";
- echo "value". $this->value." ";
- $readonly=($this->readonly==false)?"false":"true";
- echo "read only".$readonly." ";
- }
- static function submit ($p_name,$p_value,$p_javascript="") {
-
- return ' ';
- }
- static function button ($p_name,$p_value,$p_javascript="") {
-
- return ' ';
- }
-
- static function reset ($p_value) {
- return ' ';
- }
- static function hidden($p_name,$p_value) {
- return ' ';
- }
-
- static function extension() {
- return self::hidden('plugin_code',$_REQUEST['plugin_code']);
- }
-
- /*!\brief create a button with a ref
- *\param $p_label the text
- *\param $p_value the location of the window,
- *\param $p_name the id of the span
- *\param $p_javascript javascript for this button
- *\return string with htmlcode
- */
- static function button_anchor($p_label,$p_value,$p_name="",$p_javascript="") {
- $r=sprintf(' %s ',
- $p_name,
- $p_value,
- $p_javascript,
- $p_label);
- return $r;
- }
- static function infobulle($p_comment){
- $r='? ';
- return $r;
- }
- static function warnbulle($p_comment){
- $r='XX ';
- return $r;
- }
- /**
- * return a string containing the html code for calling the modifyOperation
- */
- static function detail_op($p_jr_id,$p_mesg) {
- return sprintf('%s ',
- $p_jr_id,dossier::id(),$p_mesg);
- }
- /**
- * display a div with the history of the card
- */
- static function history_card($f_id,$p_mesg)
+ var $tabindex;
+ function __construct($p_name="",$p_value="")
{
- $view_history= sprintf('%s ',
- $f_id, dossier::id(), $p_mesg);
- return $view_history;
+ $this->name=$p_name;
+ $this->readOnly=false;
+ $this->size=20;
+ $this->width=50;
+ $this->heigh=20;
+ $this->value=$p_value;
+ $this->selected="";
+ $this->table=0;
+ $this->disabled=false;
+ $this->javascript="";
+ $this->extra2="all";
+ $this->attribute=array();
+
}
-
+ function setReadOnly($p_read)
+ {
+ $this->readonly=$p_read;
+ }
+ /*!\brief set the extra javascript property for the INPUT field
+ *\param $p_name name of the parameter
+ *\param $p_value default value of this parameter
+ */
+ public function set_attribute($p_name,$p_value)
+ {
+ $this->attribute[]=array($p_name,$p_value);
+ $this->$p_name=$p_value;
+ }
+ /**
+ *@brief you can add attribute to this in javascript
+ * this function is a wrapper and create a script (in js) to modify
+ * "this" (in javascript) with the value of obj->attribute from PHP
+ *@return return string with the javascript code
+ */
+ public function get_js_attr()
+ {
+ require_once('function_javascript.php');
+ $attr="";
+ if ( count($this->attribute) == 0) return "";
+
+ /* Add properties at the widget */
+ for ($i=0;$i< count($this->attribute);$i++)
+ {
+ list($name,$value)=$this->attribute[$i];
+ $tmp1=sprintf("$('%s').%s='%s';",
+ $this->name,
+ $name,
+ $value);
+ $attr.=$tmp1;
+ }
+ $attr=create_script($attr);
+ return $attr;
+ }
+ /**
+ * Make a JSON object, this method create a javascript object
+ * with the attribute set, it returns a javascript string with the object
+ * @param $p_name : name of the object, can be null. If the name is not null, return
+ * $p_name={} otherwise only the object {}
+ * @return javascript string with the object
+ * @note: there is not check on the key->value, so you could need to escape
+ * special char as quote, single-quote...
+ * @code
+ $a=new IButton()
+ $a->set_attribute('prop','1');
+ $a->set_attribute('prop','2');
+ $a->set_attribute('prop','3');
+ $string = $a->make_object('property');
+ echo $string => property={'prop':'1','prop2':'2','prop3':'3'};
+ $string = $a->make_object(null);
+ echo $string => {'prop':'1','prop2':'2','prop3':'3'};
+ @endcode
+ */
+ public function make_object($p_name=null)
+ {
+ $name=($p_name != null)?$p_name.'=':'';
+ if ( count($this->attribute) == 0) return $name."{}";
+ $ret=$name."{";
+ $and='';
+
+ for ($i=0;$i< count($this->attribute);$i++)
+ {
+ list($name,$value)=$this->attribute[$i];
+ $tmp1=sprintf($and."'%s':'%s'",
+ $name,
+ $value);
+ $ret.=$tmp1;
+ $and=',';
+ }
+
+ $ret.='}';
+ return $ret;
+ }
+ //#####################################################################
+ /* Debug
+ */
+ function debug()
+ {
+ echo "Type ".$this->type." ";
+ echo "name ".$this->name." ";
+ echo "value". $this->value." ";
+ $readonly=($this->readonly==false)?"false":"true";
+ echo "read only".$readonly." ";
+ }
+ static function submit ($p_name,$p_value,$p_javascript="")
+ {
+
+ return ' ';
+ }
+ static function button ($p_name,$p_value,$p_javascript="")
+ {
+
+ return ' ';
+ }
+
+ static function reset ($p_value)
+ {
+ return ' ';
+ }
+ static function hidden($p_name,$p_value)
+ {
+ return ' ';
+ }
+
+ static function extension()
+ {
+ return self::hidden('plugin_code',$_REQUEST['plugin_code']);
+ }
+
+ /*!\brief create a button with a ref
+ *\param $p_label the text
+ *\param $p_value the location of the window,
+ *\param $p_name the id of the span
+ *\param $p_javascript javascript for this button
+ *\return string with htmlcode
+ */
+ static function button_anchor($p_label,$p_value,$p_name="",$p_javascript="")
+ {
+ $r=sprintf(' %s ',
+ $p_name,
+ $p_value,
+ $p_javascript,
+ $p_label);
+ return $r;
+ }
+ static function infobulle($p_comment)
+ {
+ $r='? ';
+ return $r;
+ }
+ static function warnbulle($p_comment)
+ {
+ $r='XX ';
+ return $r;
+ }
+ /**
+ * return a string containing the html code for calling the modifyOperation
+ */
+ static function detail_op($p_jr_id,$p_mesg)
+ {
+ return sprintf('%s ',
+ $p_jr_id,dossier::id(),$p_mesg);
+ }
+ /**
+ * display a div with the history of the card
+ */
+ static function history_card($f_id,$p_mesg)
+ {
+ $view_history= sprintf('%s ',
+ $f_id, dossier::id(), $p_mesg);
+ return $view_history;
+ }
+
/**
* display a div with the history of the account
*/
- static function history_account($p_account,$p_mesg)
+ static function history_account($p_account,$p_mesg)
{
- $view_history= sprintf('%s ',
- $p_account, dossier::id(), $p_mesg);
- return $view_history;
+ $view_history= sprintf('%s ',
+ $p_account, dossier::id(), $p_mesg);
+ return $view_history;
}
- /**
- * 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_array is an array obtains thanks User::get_ledger
- *@param $selected is an array of checkbox
- *@note the choosen ledger are stored in the array r_jrn (_GET)
- */
- static function select_ledger($p_array,$p_selected) {
- ob_start();
- $ledger=new IButton('l');
- $ledger->label="choix des journaux";
- $ledger->javascript=" show_ledger_choice()";
- echo $ledger->input();
+ /**
+ * 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_array is an array obtains thanks User::get_ledger
+ *@param $selected is an array of checkbox
+ *@note the choosen ledger are stored in the array r_jrn (_GET)
+ */
+ static function select_ledger($p_array,$p_selected)
+ {
+ ob_start();
+ $ledger=new IButton('l');
+ $ledger->label="choix des journaux";
+ $ledger->javascript=" show_ledger_choice()";
+ echo $ledger->input();
- /* create a hidden div for the ledger */
- echo '';
- echo '
Choix des journaux ';
+ /* create a hidden div for the ledger */
+ echo '
';
+ echo '
Choix des journaux ';
- echo '
';
- for ($e=0;$eselected=true;}
- echo ''.$r->input().$row['jrn_def_name'].'('.$row['jrn_def_type'].') ';
+ echo '';
+ for ($e=0;$eselected=true;
+ }
+ echo ''.$r->input().$row['jrn_def_name'].'('.$row['jrn_def_type'].') ';
+ }
+ echo ' ';
+ $hide=new IButton('l');
+ $hide->label="Valider";
+ $hide->javascript=" hide_ledger_choice() ";
+ echo $hide->input();
+
+ echo ' ';
+ $ret=ob_get_contents();
+ ob_clean();
+ return $ret;
}
- echo '';
- $hide=new IButton('l');
- $hide->label="Valider";
- $hide->javascript=" hide_ledger_choice() ";
- echo $hide->input();
+ /**
+ *create a hidden plus button to select the cat of ledger
+ *@note the selected value is stored in the array p_cat
+ */
+ static function select_cat($array_cat)
+ {
+ ob_start();
+ $ledger=new IButton('l');
+ $ledger->label="Catégorie";
+ $ledger->javascript=" show_cat_choice()";
+ echo $ledger->input();
- echo '
';
- $ret=ob_get_contents();
- ob_clean();
- return $ret;
- }
- /**
- *create a hidden plus button to select the cat of ledger
- *@note the selected value is stored in the array p_cat
- */
- static function select_cat($array_cat) {
- ob_start();
- $ledger=new IButton('l');
- $ledger->label="Catégorie";
- $ledger->javascript=" show_cat_choice()";
- echo $ledger->input();
+ /* create a hidden div for the ledger */
+ echo '';
+ echo '
Choix des categories ';
+ $selected=(isset($_GET['r_cat']))?$_GET['r_cat']:null;
- /* create a hidden div for the ledger */
- echo '
';
- echo '
Choix des categories ';
- $selected=(isset($_GET['r_cat']))?$_GET['r_cat']:null;
+ echo '
';
+ for ($e=0;$e';
- for ($e=0;$eselected=true;
+ }
+ echo ''.$re->input().$row['name'].'('.$row['cat'].') ';
- if ( $selected != null && isset($selected[$e])) { $re->selected=true;}
- echo ''.$re->input().$row['name'].'('.$row['cat'].') ';
+ }
+ echo ' ';
+ $hide=new IButton('l');
+ $hide->label="Valider";
+ $hide->javascript=" hide_cat_choice() ";
+ echo $hide->input();
+ echo '
';
+ $r=ob_get_contents();
+ ob_clean();
+ return $r;
}
- echo '';
- $hide=new IButton('l');
- $hide->label="Valider";
- $hide->javascript=" hide_cat_choice() ";
- echo $hide->input();
-
- echo '
';
- $r=ob_get_contents();
- ob_clean();
- return $r;
- }
}
diff --git a/include/class_iaction.php b/include/class_iaction.php
index 6149d1222..b226cce70 100644
--- a/include/class_iaction.php
+++ b/include/class_iaction.php
@@ -20,43 +20,42 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*!\file
+/*!\file
* \brief Html Input show just a ref to an action
* create a button with a link, if you want to use a javascript
* value must be empty
*/
require_once('class_html_input.php');
- class IAction extends HtmlInput
+class IAction extends HtmlInput
{
- /*!\brief show the html input of the widget*/
- public function input($p_name="",$p_value="")
- {
- $this->name=($p_name=="")?$this->name:$p_name;
- $this->value=($p_value=="")?$this->value:$p_value;
- if ( $this->readOnly==true) return $this->display();
- $this->javascript= (!isset ($this->javascript))?"":$this->javascript;
- if ( $this->value !="")
- $r=sprintf(' %s ',
- $this->name,
- $this->value,
- $this->javascript,
- $this->label);
- else
+ /*!\brief show the html input of the widget*/
+ public function input($p_name="",$p_value="")
+ {
+ $this->name=($p_name=="")?$this->name:$p_name;
+ $this->value=($p_value=="")?$this->value:$p_value;
+ if ( $this->readOnly==true) return $this->display();
+ $this->javascript= (!isset ($this->javascript))?"":$this->javascript;
+ if ( $this->value !="")
+ $r=sprintf(' %s ',
+ $this->name,
+ $this->value,
+ $this->javascript,
+ $this->label);
+ else
$r=sprintf(' %s ',
- $this->name,
- $this->javascript,
- $this->label);
+ $this->name,
+ $this->javascript,
+ $this->label);
- return $r;
-
- }
- /*!\brief print in html the readonly value of the widget*/
- public function display()
- {
- return;
- }
- static public function test_me()
- {
-
- }
+ return $r;
+
+ }
+ /*!\brief print in html the readonly value of the widget*/
+ public function display()
+ {
+ return;
+ }
+ static public function test_me()
+ {
+ }
}
diff --git a/include/class_ibox.php b/include/class_ibox.php
index 8a1f4ba16..1369ce1bd 100644
--- a/include/class_ibox.php
+++ b/include/class_ibox.php
@@ -30,9 +30,9 @@ require_once('class_html_input.php');
/**
*@brief create a DIV and call an ajax function
\verbatim
-
+
exemple d'utilisation
-
+
$ibox=new ibox('id')
$ibox->html='loading';
$ibox->callback='ajax.php'; // uniquement fichier PHP (1)
@@ -48,90 +48,93 @@ $ibox->ajax_error='ajax_error' // fonction pour traiter les erreurs ajax
class IBox extends HtmlInput
{
- var $name; /*!< name name and id of the div */
- function __construct($p_name,$label)
- {
- $this->name=$p_name;
- $this->parameter='';
- $this->attribute=array();
- $this->drag=false;
- $this->blocking=true;
- $this->queryString='';
- $this->html='Un instant... ';
- $this->callback='';
- $this->label=$label;
- $this->handle_callback='refresh_box';
- $this->cssclass='';
- $this->style='';
- $this->ajax_success='success_box';
- $this->ajax_error='error_box';
- $this->onclick='show_box';
+ var $name; /*!< name name and id of the div */
+ function __construct($p_name,$label)
+ {
+ $this->name=$p_name;
+ $this->parameter='';
+ $this->attribute=array();
+ $this->drag=false;
+ $this->blocking=true;
+ $this->queryString='';
+ $this->html='Un instant... ';
+ $this->callback='';
+ $this->label=$label;
+ $this->handle_callback='refresh_box';
+ $this->cssclass='';
+ $this->style='';
+ $this->ajax_success='success_box';
+ $this->ajax_error='error_box';
+ $this->onclick='show_box';
- }
- /*!\brief set the attribute thanks javascript as the width, the position ...
- *\param $p_name attribute name valid value are id, cssclass and html
- *\param $p_val val of the attribute
- *\note add to the this->attribut, it will be used in input()
- */
- /* function set_attribute($p_name,$p_val) {
- $this->attribute[]=array($p_name,$p_val);
- }*/
- function set_dragguable($p_value){
- $this->drag=$p_value;
- }
+ }
+ /*!\brief set the attribute thanks javascript as the width, the position ...
+ *\param $p_name attribute name valid value are id, cssclass and html
+ *\param $p_val val of the attribute
+ *\note add to the this->attribut, it will be used in input()
+ */
+ /* function set_attribute($p_name,$p_val) {
+ $this->attribute[]=array($p_name,$p_val);
+ }*/
+ function set_dragguable($p_value)
+ {
+ $this->drag=$p_value;
+ }
- function input() {
- $r="";
- $this->set_attribute('id',$this->name);
- $this->set_attribute('html',$this->html);
- $this->set_attribute('cssclass',$this->cssclass);
- $this->set_attribute('style',$this->style);
- $this->set_attribute('js_success',$this->ajax_success);
- $this->set_attribute('js_error',$this->ajax_error);
- $this->set_attribute('qs',$this->queryString);
- $this->set_attribute('callback',$this->callback);
- $this->set_attribute('drag',$this->drag);
- $obj=$this->make_object();
- $obj=str_replace('"',""",$obj);
- $r=''.$this->label.' ';
+ function input()
+ {
+ $r="";
+ $this->set_attribute('id',$this->name);
+ $this->set_attribute('html',$this->html);
+ $this->set_attribute('cssclass',$this->cssclass);
+ $this->set_attribute('style',$this->style);
+ $this->set_attribute('js_success',$this->ajax_success);
+ $this->set_attribute('js_error',$this->ajax_error);
+ $this->set_attribute('qs',$this->queryString);
+ $this->set_attribute('callback',$this->callback);
+ $this->set_attribute('drag',$this->drag);
+ $obj=$this->make_object();
+ $obj=str_replace('"',""",$obj);
+ $r=''.$this->label.' ';
- return $r;
- }
+ return $r;
+ }
- static function test_me() {
- require_once('class_idate.php');
- echo js_include('prototype.js');
- echo js_include('scriptaculous.js');
- echo js_include('effects.js');
- echo js_include('dragdrop.js');
- echo js_include('scripts.js');
+ static function test_me()
+ {
+ require_once('class_idate.php');
+ echo js_include('prototype.js');
+ echo js_include('scriptaculous.js');
+ echo js_include('effects.js');
+ echo js_include('dragdrop.js');
+ echo js_include('scripts.js');
- // Simple box no ajax
- $simple=new IBox('alert1','click-moi');
- $simple->html="Attention !!!";
- $simple->style="background:red;border:1px solid rose;width:200;height:50px;";
- $simple->drag=false;
- echo $simple->input();
+ // Simple box no ajax
+ $simple=new IBox('alert1','click-moi');
+ $simple->html="Attention !!!";
+ $simple->style="background:red;border:1px solid rose;width:200;height:50px;";
+ $simple->drag=false;
+ echo $simple->input();
- // Dragguable
- echo '
';
- $drag=new IBox('drag','drag');
- $drag->cssclass="popup_border_title";
- $drag->html=" Drag me ";
- $drag->drag=true;
- echo $drag->input();
- // with ajax
- $ajax=new IBox('ajax','ajax');
- $ajax->cssclass="popup_content";
- $ajax->style="width:1;left:1";
- $ajax->queryString="?gDossier=48&op=sf&c=av_text5&q=58&ctl=drag";
- $ajax->callback="ajax_poste.php";
- echo $ajax->input();
- $reverse=new IBox('Extourne','Extourne');
- $reverse->set_attribute('drag',1);
- $reverse->style="padding:20;height:300;width:250;position:absolute;background:red;display:none";
+ // Dragguable
+ echo '
';
+ $drag=new IBox('drag','drag');
+ $drag->cssclass="popup_border_title";
+ $drag->html=" Drag me ";
+ $drag->drag=true;
+ echo $drag->input();
+ // with ajax
+ $ajax=new IBox('ajax','ajax');
+ $ajax->cssclass="popup_content";
+ $ajax->style="width:1;left:1";
+ $ajax->queryString="?gDossier=48&op=sf&c=av_text5&q=58&ctl=drag";
+ $ajax->callback="ajax_poste.php";
+ echo $ajax->input();
+ $reverse=new IBox('Extourne','Extourne');
+ $reverse->set_attribute('drag',1);
+ $reverse->style="padding:20;height:300;width:250;position:absolute;background:red;display:none";
- echo $reverse->input();
- var_dump($reverse);
- }
+ echo $reverse->input();
+ var_dump($reverse);
+ }
}
diff --git a/include/class_ibutton.php b/include/class_ibutton.php
index 0c595f6ea..51df7dc13 100644
--- a/include/class_ibutton.php
+++ b/include/class_ibutton.php
@@ -20,63 +20,66 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*!\file
+/*!\file
* \brief Html Input
*/
require_once('class_html_input.php');
- class IButton extends HtmlInput
+class IButton extends HtmlInput
{
- var $label;
- /*!\brief show the html input of the widget*/
- public function input($p_name=null,$p_value=null)
- {
- $this->name=($p_name==null)?$this->name:$p_name;
- $this->value=($p_value==null)?$this->value:$p_value;
- if ( $this->readOnly==true) return $this->display();
- $extra= ( isset($this->extra))?$this->extra:"";
+ var $label;
+ /*!\brief show the html input of the widget*/
+ public function input($p_name=null,$p_value=null)
+ {
+ $this->name=($p_name==null)?$this->name:$p_name;
+ $this->value=($p_value==null)?$this->value:$p_value;
+ if ( $this->readOnly==true) return $this->display();
+ $extra= ( isset($this->extra))?$this->extra:"";
- $r=' ';
- $attr=$this->get_js_attr();
- $r.=$attr;
- return $r;
+ $r=' ';
+ $attr=$this->get_js_attr();
+ $r.=$attr;
+ return $r;
- }
- /*!\brief print in html the readonly value of the widget*/
- public function display()
- {
- return "";
- }
- static function tooggle_checkbox($p_form) {
- $select_all=new IButton('select_all');
- $select_all->label=_('Inverser la sélection');
- $select_all->javascript="toggle_checkbox('$p_form')";
- return $select_all->input();
- }
- static function select_checkbox($p_form) {
- $select_all=new IButton('select_all');
- $select_all->label=_('Cocher tous');
- $select_all->javascript="select_checkbox('$p_form')";
- return $select_all->input();
- }
- static function unselect_checkbox($p_form) {
- $select_all=new IButton('select_all');
- $select_all->label=_('Décocher tous');
- $select_all->javascript="unselect_checkbox('$p_form')";
- return $select_all->input();
- }
- static function show_calc() {
- $calc=new IButton('shcalc');
- $calc->label=_('Calculatrice');
- $calc->javascript="show_calc()";
- return $calc->input();
+ }
+ /*!\brief print in html the readonly value of the widget*/
+ public function display()
+ {
+ return "";
+ }
+ static function tooggle_checkbox($p_form)
+ {
+ $select_all=new IButton('select_all');
+ $select_all->label=_('Inverser la sélection');
+ $select_all->javascript="toggle_checkbox('$p_form')";
+ return $select_all->input();
+ }
+ static function select_checkbox($p_form)
+ {
+ $select_all=new IButton('select_all');
+ $select_all->label=_('Cocher tous');
+ $select_all->javascript="select_checkbox('$p_form')";
+ return $select_all->input();
+ }
+ static function unselect_checkbox($p_form)
+ {
+ $select_all=new IButton('select_all');
+ $select_all->label=_('Décocher tous');
+ $select_all->javascript="unselect_checkbox('$p_form')";
+ return $select_all->input();
+ }
+ static function show_calc()
+ {
+ $calc=new IButton('shcalc');
+ $calc->label=_('Calculatrice');
+ $calc->javascript="show_calc()";
+ return $calc->input();
- }
- static public function test_me()
- {
-
- }
+ }
+ static public function test_me()
+ {
+ }
}
diff --git a/include/class_icard.php b/include/class_icard.php
index d1600f361..1238993d7 100644
--- a/include/class_icard.php
+++ b/include/class_icard.php
@@ -20,340 +20,364 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*!\file
+/*!\file
* \brief Input HTML for the card show buttons, in the file, you have to add JS_CARD
*
*/
- /*!
- * \brief Input HTML for the card show buttons, in the file, you have to add JS_CARD
- * How to use :
- * - label is the label in the button
- * - extra contents the type (all, deb or cred, a list of FD_ID between parent. or a SQL clause
- * - attribute are the attribute to set (via ajax). The ledger is either a attribute (jrn) or a
- * hidden field in the document, if none are set, there is no filter on the ledger
- *\note you must in a hidden field gDossier (dossier::hidden)
- *\see ajaxFid
- *\see card.js
- *\see fid.php
- *\see fid_card.php
- *\see ajax_card.php
- *
- * Set the hidden field or input field to be set by javascript with the function set_attribute
- * call the input method. After selecting a value the update_value function is called. If you need
- * to modify the queryString before the request is sent, you'll use the set_callback; the first
- * parameter is the INPUT field and the second the queryString, the function must returns a
- * queryString
- *\code
+/*!
+ * \brief Input HTML for the card show buttons, in the file, you have to add JS_CARD
+ * How to use :
+ * - label is the label in the button
+ * - extra contents the type (all, deb or cred, a list of FD_ID between parent. or a SQL clause
+ * - attribute are the attribute to set (via ajax). The ledger is either a attribute (jrn) or a
+ * hidden field in the document, if none are set, there is no filter on the ledger
+ *\note you must in a hidden field gDossier (dossier::hidden)
+ *\see ajaxFid
+ *\see card.js
+ *\see fid.php
+ *\see fid_card.php
+ *\see ajax_card.php
+ *
+ * Set the hidden field or input field to be set by javascript with the function set_attribute
+ * call the input method. After selecting a value the update_value function is called. If you need
+ * to modify the queryString before the request is sent, you'll use the set_callback; the first
+ * parameter is the INPUT field and the second the queryString, the function must returns a
+ * queryString
+ *\code
// insert all the javascript files
- echo js_include('prototype.js');
- echo js_include('scriptaculous.js');
- echo js_include('effects.js');
- echo js_include('controls.js');
-
+ echo js_include('prototype.js');
+ echo js_include('scriptaculous.js');
+ echo js_include('effects.js');
+ echo js_include('controls.js');
+
//
- $W1=new ICard();
- $W1->label="Client ".HtmlInput::infobulle(0) ;
- $W1->name="e_client";
- $W1->tabindex=3;
- $W1->value=$e_client;
- $W1->table=0;
+ $W1=new ICard();
+ $W1->label="Client ".HtmlInput::infobulle(0) ;
+ $W1->name="e_client";
+ $W1->tabindex=3;
+ $W1->value=$e_client;
+ $W1->table=0;
// If double click call the javascript fill_ipopcard
- $W1->set_dblclick("fill_ipopcard(this);");
-
+ $W1->set_dblclick("fill_ipopcard(this);");
+
// This attribute is mandatory, it is the name of the IPopup
- $W1->set_attribute('ipopup','ipopcard');
-
- // name of the field to update with the name of the card
- $W1->set_attribute('label','e_client_label');
-
- // Type of card : deb, cred,
- $W1->set_attribute('typecard','deb');
-
- $W1->extra='deb';
-
+ $W1->set_attribute('ipopup','ipopcard');
+
+ // name of the field to update with the name of the card
+ $W1->set_attribute('label','e_client_label');
+
+ // Type of card : deb, cred,
+ $W1->set_attribute('typecard','deb');
+
+ $W1->extra='deb';
+
// Add the callback function to filter the card on the jrn
- $W1->set_callback('filter_card');
-
+ $W1->set_callback('filter_card');
+
// when value selected in the autcomplete
- $W1->set_function('fill_data');
-
+ $W1->set_function('fill_data');
+
// when the data change
- $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
- $W1->name);
- $f_client_qcode=$W1->input();
- $client_label=new ISpan();
- $client_label->table=0;
- $f_client=$client_label->input("e_client_label",$e_client_label);
-
+ $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+ $W1->name);
+ $f_client_qcode=$W1->input();
+ $client_label=new ISpan();
+ $client_label->table=0;
+ $f_client=$client_label->input("e_client_label",$e_client_label);
+
// Search button for card
- $f_client_bt=$W1->search();
- * \endcode
+ $f_client_bt=$W1->search();
+* \endcode
For searching a card, you need a popup, the script card.js and set
the values for card, popup filter_card callback
@code
echo JS_CARD;
-
-
+
+
$search_card=new IPopup('ipop_card');
$search_card->title=_('Recherche de fiche');
$search_card->value='';
echo $search_card->input();
-
+
$card=new ICard('acc');
$card->name="acc";
$card->extra="all";
$card->set_attribute('popup','ipopcard');
$card->set_attribute('typecard','all');
$card->set_callback('filter_card');
-
+
echo $card->input();
echo $card->search();
// example 2
- $w=new ICard("av_text".$attr->ad_id);
- // filter on frd_id
- $sql=' select fd_id from fiche_def where frd_id in ('.FICHE_TYPE_CLIENT.','.FICHE_TYPE_FOURNISSEUR.','.FICHE_TYPE_ADM_TAX.')';
- $filter=$this->cn->make_list($sql);
- $w->set_attribute('ipopup','ipopcard');
- $w->set_attribute('typecard',$filter);
- $w->set_attribute('inp',"av_text".$attr->ad_id);
- $w->set_attribute('label',"av_text".$attr->ad_id."_label");
+$w=new ICard("av_text".$attr->ad_id);
+// filter on frd_id
+$sql=' select fd_id from fiche_def where frd_id in ('.FICHE_TYPE_CLIENT.','.FICHE_TYPE_FOURNISSEUR.','.FICHE_TYPE_ADM_TAX.')';
+$filter=$this->cn->make_list($sql);
+$w->set_attribute('ipopup','ipopcard');
+$w->set_attribute('typecard',$filter);
+$w->set_attribute('inp',"av_text".$attr->ad_id);
+$w->set_attribute('label',"av_text".$attr->ad_id."_label");
- $w->extra=$filter;
- $w->extra2=0;
- $label=new ISpan();
- $label->name="av_text".$attr->ad_id."_label";
- $msg.=td($w->search().$label->input());
+$w->extra=$filter;
+$w->extra2=0;
+$label=new ISpan();
+$label->name="av_text".$attr->ad_id."_label";
+$msg.=td($w->search().$label->input());
@endcode
- */
+*/
require_once('class_html_input.php');
require_once('function_javascript.php');
class ICard extends HtmlInput
{
- function __construct($name="",$value="") {
- parent::__construct($name,$value);
- $this->fct='update_value';
- $this->dblclick='';
- $this->callback='null';
- $this->javascript='';
- }
- /*!\brief set the javascript callback function
- * by default it is update_value called BEFORE the querystring is send
- *
- *\param $p_name callback function name
- */
- function set_callback($p_name) {
- $this->callback=$p_name;
- }
-
- /*!\brief set the javascript callback function
- * by default it is update_value called AFTER an item has been selected
- *\param $p_name callback function name
- */
- function set_function($p_name) {
- $this->fct=$p_name;
- }
- /*!\brief return the html string for creating the ipopup, this ipopup
- * can be used for adding, modifying or display a card
- *\param $p_name name of the ipopup, must be set after with set_attribute
-\code
- $f_add_button=new IButton('add_card');
- $f_add_button->label='Créer une nouvelle fiche';
- $f_add_button->set_attribute('ipopup','ipop_newcard');
- $f_add_button->set_attribute('filter',$this->get_all_fiche_def ());
- $f_add_button->javascript=" select_card_type(this);";
- $str_add_button=$f_add_button->input();
-
-\endcode
- *\return html string
- *\note must be one of first instruction on a new page, to avoid problem
- * of position with IE
- */
- static function ipopup($p_name) {
- $ip_card=new IPopup ($p_name);
- $ip_card->drag=true;
- $ip_card->set_width('45%');
- $ip_card->title='Fiche ';
- $ip_card->value='';
- return $ip_card->input();
- }
- /*!\brief set the extra javascript property for a double click on
- * INPUT field
- *\param $p_action action when a double click happens
- *\note the $p_action cannot contain a double quote
- */
- function set_dblclick($p_action) {
- $this->dblclick=$p_action;
- }
- /*!\brief show the html input of the widget*/
- public function input($p_name=null,$p_value=null)
- {
- if ( $p_name == null && $this->name == "")
- throw (new Exception('Le nom d une icard doit être donne'));
-
- $this->value=($p_value==null)?$this->value:$p_value;
- if ( $this->readOnly==true) return $this->display();
-
-
- $attr=$this->get_js_attr();
-
- $label='';
- if ( $this->dblclick != '') {
- $e=sprintf(' ondblclick="%s" ',
- $this->dblclick);
- $this->dblclick=$e;
+ function __construct($name="",$value="")
+ {
+ parent::__construct($name,$value);
+ $this->fct='update_value';
+ $this->dblclick='';
+ $this->callback='null';
+ $this->javascript='';
}
- $input=sprintf(' ',
- $this->name,
- $this->name,
- $this->value,
- $this->size,
- $this->dblclick,
- $this->javascript
- );
-
- $ind=sprintf('Un instant... '.
- ' ',
- $this->name);
-
- $div=sprintf('
',
- $this->name);
-
- $query=dossier::get().'&e='.urlencode($this->extra);
-
- $javascript=sprintf('try { new Ajax.Autocompleter("%s","%s_choices","fid_card.php?%s",'.
- '{paramName:"FID",minChars:1,indicator:null,'.
- 'callback:%s, '.
- ' afterUpdateElement:%s});} catch (e){alert(e.message);};',
- $this->name,$this->name,$query,
- $this->callback,
- $this->fct);
-
- $javascript=create_script($javascript.$this->dblclick);
-
- $r=$label.$input.$attr.$ind.$div.$javascript;
- if ( $this->table == 1 )
- $r=td($r);
- return $r;
-
- }
- /*!\brief print in html the readonly value of the widget*/
- public function display()
- {
- $r=sprintf(' ',
- $this->name,
- $this->value
- );
- $r.=''.$this->value.' ';
- return $r;
-
- }
- /**
- *@brief return a string containing the button for displaying
- * a search form. When clicking on the result, update the input text file
- * the common used attribute as
- * - jrn the ledger
- * - label the field to update
- * - name name of the input text
- * - price amount
- * - tvaid
- * - typecard (deb, cred, filter or list of value)
- * will be set
- * if ICard is in readOnly, the button disappears, so the return string is empty
-\code
- // search ipopup
-$search_card=new IPopup('ipop_card');
-$search_card->title=_('Recherche de fiche');
-$search_card->value='';
-echo $search_card->input();
-
-$a=new ICard('test');
-$a->search();
-
-\endcode
- *\see ajax_card.php
- *\note the ipopup id is hard coded : ipop_card
- *@return HTML string with the button
- */
- function search() {
- if ( $this->readOnly==true) return '';
-
- $button=new IButton($this->name.'_bt');
- $a="";
- foreach (array('typecard','jrn','label','price','tvaid') as $att) {
- if (isset($this->$att) )
- $a.="this.".$att."='".$this->$att."';";
+ /*!\brief set the javascript callback function
+ * by default it is update_value called BEFORE the querystring is send
+ *
+ *\param $p_name callback function name
+ */
+ function set_callback($p_name)
+ {
+ $this->callback=$p_name;
}
- if (isset($this->name))
- $a.="this.inp='".$this->name."';";
- $a.="this.popup='ipop_card';";
- $button->javascript=$a.' search_card(this)';
- return $button->input();
- }
+ /*!\brief set the javascript callback function
+ * by default it is update_value called AFTER an item has been selected
+ *\param $p_name callback function name
+ */
+ function set_function($p_name)
+ {
+ $this->fct=$p_name;
+ }
+ /*!\brief return the html string for creating the ipopup, this ipopup
+ * can be used for adding, modifying or display a card
+ *\param $p_name name of the ipopup, must be set after with set_attribute
+ \code
+ $f_add_button=new IButton('add_card');
+ $f_add_button->label='Créer une nouvelle fiche';
+ $f_add_button->set_attribute('ipopup','ipop_newcard');
+ $f_add_button->set_attribute('filter',$this->get_all_fiche_def ());
+ $f_add_button->javascript=" select_card_type(this);";
+ $str_add_button=$f_add_button->input();
- static public function test_me()
- {
- require_once('class_itext.php');
- $_SESSION['isValid']=1;
- $a=new ICard('testme');
- $a->extra="all";
- $a->set_attribute('label','ctl_label');
- $a->set_attribute('tvaid','ctl_tvaid');
- $a->set_attribute('price','ctl_price');
- $a->set_attribute('purchase','ctl_purchase');
- $a->set_attribute('type','all');
-echo <<
-
-
-
-
-
-
+
+ $attr=$this->get_js_attr();
+
+ $label='';
+ if ( $this->dblclick != '')
+ {
+ $e=sprintf(' ondblclick="%s" ',
+ $this->dblclick);
+ $this->dblclick=$e;
+ }
+ $input=sprintf(' ',
+ $this->name,
+ $this->name,
+ $this->value,
+ $this->size,
+ $this->dblclick,
+ $this->javascript
+ );
+
+ $ind=sprintf('Un instant... '.
+ ' ',
+ $this->name);
+
+ $div=sprintf('
',
+ $this->name);
+
+ $query=dossier::get().'&e='.urlencode($this->extra);
+
+ $javascript=sprintf('try { new Ajax.Autocompleter("%s","%s_choices","fid_card.php?%s",'.
+ '{paramName:"FID",minChars:1,indicator:null,'.
+ 'callback:%s, '.
+ ' afterUpdateElement:%s});} catch (e){alert(e.message);};',
+ $this->name,$this->name,$query,
+ $this->callback,
+ $this->fct);
+
+ $javascript=create_script($javascript.$this->dblclick);
+
+ $r=$label.$input.$attr.$ind.$div.$javascript;
+ if ( $this->table == 1 )
+ $r=td($r);
+ return $r;
+
+ }
+ /*!\brief print in html the readonly value of the widget*/
+ public function display()
+ {
+ $r=sprintf(' ',
+ $this->name,
+ $this->value
+ );
+ $r.=''.$this->value.' ';
+ return $r;
+
+ }
+ /**
+ *@brief return a string containing the button for displaying
+ * a search form. When clicking on the result, update the input text file
+ * the common used attribute as
+ * - jrn the ledger
+ * - label the field to update
+ * - name name of the input text
+ * - price amount
+ * - tvaid
+ * - typecard (deb, cred, filter or list of value)
+ * will be set
+ * if ICard is in readOnly, the button disappears, so the return string is empty
+ \code
+ // search ipopup
+ $search_card=new IPopup('ipop_card');
+ $search_card->title=_('Recherche de fiche');
+ $search_card->value='';
+ echo $search_card->input();
+
+ $a=new ICard('test');
+ $a->search();
+
+ \endcode
+ *\see ajax_card.php
+ *\note the ipopup id is hard coded : ipop_card
+ *@return HTML string with the button
+ */
+ function search()
+ {
+ if ( $this->readOnly==true) return '';
+
+ $button=new IButton($this->name.'_bt');
+ $a="";
+ foreach (array('typecard','jrn','label','price','tvaid') as $att)
+ {
+ if (isset($this->$att) )
+ $a.="this.".$att."='".$this->$att."';";
+ }
+ if (isset($this->name))
+ $a.="this.inp='".$this->name."';";
+ $a.="this.popup='ipop_card';";
+
+ $button->javascript=$a.' search_card(this)';
+ return $button->input();
+ }
+
+ static public function test_me()
+ {
+ require_once('class_itext.php');
+ $_SESSION['isValid']=1;
+ $a=new ICard('testme');
+ $a->extra="all";
+ $a->set_attribute('label','ctl_label');
+ $a->set_attribute('tvaid','ctl_tvaid');
+ $a->set_attribute('price','ctl_price');
+ $a->set_attribute('purchase','ctl_purchase');
+ $a->set_attribute('type','all');
+ echo <<
+
+
+
+
+
+
+
EOF;
- echo "";
- $l=new IText('ctl_label');
- $t=new IText('ctl_tvaid');
- $p=new IText('ctl_price');
- $b=new IText('ctl_purchase');
+ echo " ";
+ $l=new IText('ctl_label');
+ $t=new IText('ctl_tvaid');
+ $p=new IText('ctl_price');
+ $b=new IText('ctl_purchase');
- echo "Label ".$l->input().' ';
- echo "Tva id ".$t->input().' ';
- echo "Price ".$p->input().' ';
- echo "Purchase ".$b->input().' ';
+ echo "Label ".$l->input().' ';
+ echo "Tva id ".$t->input().' ';
+ echo "Price ".$p->input().' ';
+ echo "Purchase ".$b->input().' ';
- if ( isset($_REQUEST['test_select']) )
- echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
- $a->set_function('test_value');
- $a->javascript=' onchange="alert(\'onchange\');" onblur="alert(\'onblur\');" ';
- echo $a->input();
- echo dossier::hidden();
- echo HtmlInput::submit('Entree','entree');
- echo ' ';
-echo <<set_function('test_value');
+ $a->javascript=' onchange="alert(\'onchange\');" onblur="alert(\'onblur\');" ';
+ echo $a->input();
+ echo dossier::hidden();
+ echo HtmlInput::submit('Entree','entree');
+ echo '';
+ echo <<name=($p_name==null)?$this->name:$p_name;
- $this->value=($p_value==null)?$this->value:$p_value;
- if ( $this->readOnly==true) return $this->display();
-
- $check=( $this->selected==true )?"checked":"unchecked";
- $r=' disabled." ".$this->javascript.'>';
-
- $r=$r." $this->label";
-
- return $r;
-
-
- }
- /*!\brief print in html the readonly value of the widget*/
- public function display()
- {
- $check=( $this->selected==true )?"checked":"unchecked";
- $r=' ';
-
- return $r;
-
- }
- static public function test_me()
- {
-
- }
+ /*!\brief show the html input of the widget*/
+ public function input($p_name=null,$p_value=null)
+ {
+ $this->name=($p_name==null)?$this->name:$p_name;
+ $this->value=($p_value==null)?$this->value:$p_value;
+ if ( $this->readOnly==true) return $this->display();
+
+ $check=( $this->selected==true )?"checked":"unchecked";
+ $r=' disabled." ".$this->javascript.'>';
+
+ $r=$r." $this->label";
+
+ return $r;
+
+
+ }
+ /*!\brief print in html the readonly value of the widget*/
+ public function display()
+ {
+ $check=( $this->selected==true )?"checked":"unchecked";
+ $r=' ';
+
+ return $r;
+
+ }
+ static public function test_me()
+ {
+ }
}
diff --git a/include/class_iconcerned.php b/include/class_iconcerned.php
index 5e89f3768..b713fa128 100644
--- a/include/class_iconcerned.php
+++ b/include/class_iconcerned.php
@@ -20,46 +20,46 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*!\file
+/*!\file
* \brief Html Input
*/
require_once('class_html_input.php');
- class IConcerned extends HtmlInput
+class IConcerned extends HtmlInput
{
- /*!\brief show the html input of the widget*/
- public function input($p_name=null,$p_value=null)
- {
- $this->name=($p_name==null)?$this->name:$p_name;
- $this->value=($p_value==null)?$this->value:$p_value;
- if ( $this->readOnly==true) return $this->display();
- $td="";$etd="";
-
+ /*!\brief show the html input of the widget*/
+ public function input($p_name=null,$p_value=null)
+ {
+ $this->name=($p_name==null)?$this->name:$p_name;
+ $this->value=($p_value==null)?$this->value:$p_value;
+ if ( $this->readOnly==true) return $this->display();
+ $td="";
+ $etd="";
- $r=sprintf("$td
-
- $etd $td
-
- $etd",
- $this->name,
- $this->extra,
- $this->extra2,
- $this->name,
- $this->name,
- $this->value
- );
- return $r;
- }
- /*!\brief print in html the readonly value of the widget*/
- public function display()
- {
- $r=sprintf("%s ",$this->value);
- $r.=sprintf(' ', $this->name,$this->value);
- return $r;
- }
- static public function test_me()
- {
+ $r=sprintf("$td
+
+ $etd $td
+
+ $etd",
+ $this->name,
+ $this->extra,
+ $this->extra2,
+ $this->name,
+ $this->name,
+ $this->value
+ );
+ return $r;
+ }
+ /*!\brief print in html the readonly value of the widget*/
+ public function display()
+ {
+ $r=sprintf("%s ",$this->value);
+ $r.=sprintf(' ', $this->name,$this->value);
+ return $r;
- }
+ }
+ static public function test_me()
+ {
+ }
}
diff --git a/include/class_idate.php b/include/class_idate.php
index 558c88bc3..90e899eac 100644
--- a/include/class_idate.php
+++ b/include/class_idate.php
@@ -24,48 +24,47 @@
* \brief Html Input
*/
require_once('class_html_input.php');
- class IDate extends HtmlInput
+class IDate extends HtmlInput
{
- /*!\brief show the html input of the widget*/
- public function input($p_name=null,$p_value=null)
- {
- $this->name=($p_name==null)?$this->name:$p_name;
- $this->value=($p_value==null)?$this->value:$p_value;
- if ( $this->readOnly==true) return $this->display();
- $r=' '.
- ' ';
- $r.='
-';
- return $r;
+ /*!\brief show the html input of the widget*/
+ public function input($p_name=null,$p_value=null)
+ {
+ $this->name=($p_name==null)?$this->name:$p_name;
+ $this->value=($p_value==null)?$this->value:$p_value;
+ if ( $this->readOnly==true) return $this->display();
+ $r=' '.
+ ' ';
+ $r.='
+ ';
+ return $r;
- }
- /*!\brief print in html the readonly value of the widget*/
- public function display()
- {
- $r=" : ".$this->value;
- $r.=' name.'"'.
- ' value = "'.$this->value.'"> ';
- return $r;
+ }
+ /*!\brief print in html the readonly value of the widget*/
+ public function display()
+ {
+ $r=" : ".$this->value;
+ $r.=' name.'"'.
+ ' value = "'.$this->value.'"> ';
+ return $r;
- }
- static public function test_me()
- {
-
- }
+ }
+ static public function test_me()
+ {
+ }
}
diff --git a/include/class_ifile.php b/include/class_ifile.php
index 47c3acbcf..f40eb82fd 100644
--- a/include/class_ifile.php
+++ b/include/class_ifile.php
@@ -20,30 +20,28 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*!\file
+/*!\file
* \brief Html Input
*/
require_once('class_html_input.php');
- class IFile extends HtmlInput
+class IFile extends HtmlInput
{
- /*!\brief show the html input of the widget*/
- public function input($p_name=null,$p_value=null)
- {
- $this->name=($p_name==null)?$this->name:$p_name;
- $this->value=($p_value==null)?$this->value:$p_value;
- if ( $this->readOnly==true) return $this->display();
- $r=' ';
- return $r;
+ /*!\brief show the html input of the widget*/
+ public function input($p_name=null,$p_value=null)
+ {
+ $this->name=($p_name==null)?$this->name:$p_name;
+ $this->value=($p_value==null)?$this->value:$p_value;
+ if ( $this->readOnly==true) return $this->display();
+ $r=' ';
+ return $r;
- }
- /*!\brief print in html the readonly value of the widget*/
- public function display()
- {
+ }
+ /*!\brief print in html the readonly value of the widget*/
+ public function display()
+ {
-
- }
- static public function test_me()
- {
-
- }
+ }
+ static public function test_me()
+ {
+ }
}
diff --git a/include/class_ihidden.php b/include/class_ihidden.php
index 8e37d8534..cb4f5cb2b 100644
--- a/include/class_ihidden.php
+++ b/include/class_ihidden.php
@@ -20,23 +20,22 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*!\file
+/*!\file
* \brief Html Input
*/
require_once('class_html_input.php');
- class IHidden extends HtmlInput
+class IHidden extends HtmlInput
{
- /*!\brief show the html input of the widget*/
- public function input($p_name=null,$p_value=null)
- {
- $this->name=($p_name==null)?$this->name:$p_name;
- $this->value=($p_value==null)?$this->value:$p_value;
- $r=' ';
- return $r;
+ /*!\brief show the html input of the widget*/
+ public function input($p_name=null,$p_value=null)
+ {
+ $this->name=($p_name==null)?$this->name:$p_name;
+ $this->value=($p_value==null)?$this->value:$p_value;
+ $r=' ';
+ return $r;
- }
- static public function test_me()
- {
-
- }
+ }
+ static public function test_me()
+ {
+ }
}
diff --git a/include/class_inum.php b/include/class_inum.php
index a0fefc9aa..1ba06aaf9 100644
--- a/include/class_inum.php
+++ b/include/class_inum.php
@@ -24,7 +24,7 @@
* \brief for the numeric input text field
*/
require_once('class_itext.php');
-/*!\brief
+/*!\brief
* This class handles only the numeric input, the input will
* call a javascript
* to change comma to period and will round it (2 decimal)
@@ -32,30 +32,32 @@ require_once('class_itext.php');
*/
class INum extends IText
{
- function __construct($name='',$value='') {
- parent::__construct($name,$value);
- $this->javascript='onchange="format_number(this);"';
- $this->size=9;
- $this->style='style="text-align:right;border:1px solid blue;margin:2px"';
- }
- /*!\brief print in html the readonly value of the widget*/
- public function display()
- {
- $this->size=9;
- $readonly=" readonly ";$style='style="border:solid 1px blue;color:black;background:#EDEDED;text-align:right"';
- $this->value=str_replace('"','',$this->value);
- $r=' name.'" VALUE="'.$this->value.'" '.
- 'SIZE="'.$this->size.'" '.$this->javascript." $readonly $this->extra >";
-
- /* add tag for column if inside a table */
- if ( $this->table == 1 ) $r=''.$r.' ';
-
- return $r;
-
- }
-
+ function __construct($name='',$value='')
+ {
+ parent::__construct($name,$value);
+ $this->javascript='onchange="format_number(this);"';
+ $this->size=9;
+ $this->style='style="text-align:right;border:1px solid blue;margin:2px"';
+ }
+ /*!\brief print in html the readonly value of the widget*/
+ public function display()
+ {
+ $this->size=9;
+ $readonly=" readonly ";
+ $style='style="border:solid 1px blue;color:black;background:#EDEDED;text-align:right"';
+ $this->value=str_replace('"','',$this->value);
+ $r=' name.'" VALUE="'.$this->value.'" '.
+ 'SIZE="'.$this->size.'" '.$this->javascript." $readonly $this->extra >";
+
+ /* add tag for column if inside a table */
+ if ( $this->table == 1 ) $r=''.$r.' ';
+
+ return $r;
+
+ }
+
}
diff --git a/include/class_iperiod.php b/include/class_iperiod.php
index b326ad951..46276e3e9 100644
--- a/include/class_iperiod.php
+++ b/include/class_iperiod.php
@@ -20,131 +20,138 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*!\file
+/*!\file
* \brief Html Input
*/
- /*! \brief Generate the form for the periode
- * Data Members
- * - $cn connexion to the current folder
- * - $type the type of the periode OPEN CLOSE NOTCENTRALIZED or ALL, IT MUST BE SET
- * - $filter_year make a filter on the default exercice by default true
- * - $user if a filter_year is required then we need who is the user (object User)
- * - $show_end_date; $show_end_date is not set or false, do not show the end date default = true
- * - $show_start_date; $show_start_date is not set or false, do not show the start date default=true
- */
+/*! \brief Generate the form for the periode
+* Data Members
+ * - $cn connexion to the current folder
+ * - $type the type of the periode OPEN CLOSE NOTCENTRALIZED or ALL, IT MUST BE SET
+ * - $filter_year make a filter on the default exercice by default true
+ * - $user if a filter_year is required then we need who is the user (object User)
+ * - $show_end_date; $show_end_date is not set or false, do not show the end date default = true
+ * - $show_start_date; $show_start_date is not set or false, do not show the start date default=true
+*/
require_once('class_html_input.php');
- class IPeriod extends HtmlInput
+class IPeriod extends HtmlInput
{
- var $type; /*!< $type the type of the periode OPEN CLOSE NOTCENTRALIZED or ALL */
- var $cn; /*!< $cn is the database connection */
- var $show_end_date; /*!< $show_end_date is not set or false, do not show the end date */
- var $show_start_date; /*!< $show_start_date is not set or false, do not show the start date */
- var $filter_year; /*!< $filter_year make a filter on the default exercice by default yes */
- var $user; /*! $user if a filter is required then we need who is the user (object User)*/
- function __construct($p_name="",$p_value="") {
- $this->name=$p_name;
- $this->readOnly=false;
- $this->size=20;
- $this->width=50;
- $this->heigh=20;
- $this->value=$p_value;
- $this->selected="";
- $this->table=0;
- $this->disabled=false;
- $this->javascript="";
- $this->extra2="all";
- $this->show_start_date=true;
- $this->show_end_date=true;
+ var $type; /*!< $type the type of the periode OPEN CLOSE NOTCENTRALIZED or ALL */
+ var $cn; /*!< $cn is the database connection */
+ var $show_end_date; /*!< $show_end_date is not set or false, do not show the end date */
+ var $show_start_date; /*!< $show_start_date is not set or false, do not show the start date */
+ var $filter_year; /*!< $filter_year make a filter on the default exercice by default yes */
+ var $user; /*! $user if a filter is required then we need who is the user (object User)*/
+ function __construct($p_name="",$p_value="")
+ {
+ $this->name=$p_name;
+ $this->readOnly=false;
+ $this->size=20;
+ $this->width=50;
+ $this->heigh=20;
+ $this->value=$p_value;
+ $this->selected="";
+ $this->table=0;
+ $this->disabled=false;
+ $this->javascript="";
+ $this->extra2="all";
+ $this->show_start_date=true;
+ $this->show_end_date=true;
- }
- /*!
- * \brief show the input html for a periode
- * \return string containing html code for the HTML
- *
- *
- */
- public function input($p_name=null,$p_value=null)
- {
- foreach (array('type','cn') as $a){
- if ( ! isset ($this->$a) ) throw new Exception('Variable non définie [ '.$a.']');
- }
- $this->name=($p_name==null)?$this->name:$p_name;
- $this->value=($p_value==null)?$this->value:$p_value;
- if ( $this->readOnly==true) return $this->display();
+ }
+ /*!
+ * \brief show the input html for a periode
+ * \return string containing html code for the HTML
+ *
+ *
+ */
+ public function input($p_name=null,$p_value=null)
+ {
+ foreach (array('type','cn') as $a)
+ {
+ if ( ! isset ($this->$a) ) throw new Exception('Variable non définie [ '.$a.']');
+ }
+ $this->name=($p_name==null)?$this->name:$p_name;
+ $this->value=($p_value==null)?$this->value:$p_value;
+ if ( $this->readOnly==true) return $this->display();
- switch ($this->type) {
- case CLOSED:
- $sql_closed="where p_closed=true and p_central = false ";
- break;
- case OPEN:
- $sql_closed="where p_closed=false";
- break;
- case NOTCENTRALIZED:
- $sql_closed="where p_closed=true and p_central = false ";
- break;
- case ALL:
- $sql_closed="";
- break;
- default:
- throw new Exception("invalide p_type in ".__FILE__.':'.__LINE__);
- }
- $sql="select p_id,to_char(p_start,'DD.MM.YYYY') as p_start_string,
- to_char(p_end,'DD.MM.YYYY') as p_end_string
- from parm_periode
- $sql_closed ";
- /* Create a filter on the current exercice */
- if ( ! isset($this->filter_year) || (isset($this->filter_year) && $this->filter_year==true))
- {
- if (! isset($this->user) ) throw new Exception (__FILE__.':'.__LINE__.' user is not set');
- $cond='';
- if ($this->type == 'all' ) $cond=' where true ';
- $cond.=" and p_exercice='".$this->user->get_exercice()."'";
- }
- $sql.=" order by p_start,p_end";
- $Res=$this->cn->exec_sql($sql);
- $Max=$this->cn->size($Res);
- if ( $Max == 0 ) throw new Exception(_('Aucune periode trouvée'),1);
- $ret='javascript.'>';
- for ( $i = 0; $i < $Max;$i++) {
- $l_line=$this->cn->fetch($i);
- if ( $this->value==$l_line['p_id'] )
- $sel="SELECTED";
- else
- $sel="";
+ switch ($this->type)
+ {
+ case CLOSED:
+ $sql_closed="where p_closed=true and p_central = false ";
+ break;
+ case OPEN:
+ $sql_closed="where p_closed=false";
+ break;
+ case NOTCENTRALIZED:
+ $sql_closed="where p_closed=true and p_central = false ";
+ break;
+ case ALL:
+ $sql_closed="";
+ break;
+ default:
+ throw new Exception("invalide p_type in ".__FILE__.':'.__LINE__);
+ }
+ $sql="select p_id,to_char(p_start,'DD.MM.YYYY') as p_start_string,
+ to_char(p_end,'DD.MM.YYYY') as p_end_string
+ from parm_periode
+ $sql_closed ";
+ /* Create a filter on the current exercice */
+ if ( ! isset($this->filter_year) || (isset($this->filter_year) && $this->filter_year==true))
+ {
+ if (! isset($this->user) ) throw new Exception (__FILE__.':'.__LINE__.' user is not set');
+ $cond='';
+ if ($this->type == 'all' ) $cond=' where true ';
+ $cond.=" and p_exercice='".$this->user->get_exercice()."'";
+ }
+ $sql.=" order by p_start,p_end";
+ $Res=$this->cn->exec_sql($sql);
+ $Max=$this->cn->size($Res);
+ if ( $Max == 0 ) throw new Exception(_('Aucune periode trouvée'),1);
+ $ret='javascript.'>';
+ for ( $i = 0; $i < $Max;$i++)
+ {
+ $l_line=$this->cn->fetch($i);
+ if ( $this->value==$l_line['p_id'] )
+ $sel="SELECTED";
+ else
+ $sel="";
- if ( $this->show_start_date == true && $this->show_end_date==true )
- {
- $ret.=sprintf('%s - %s',$l_line['p_id']
- ,$sel
- ,$l_line['p_start_string']
- ,$l_line['p_end_string']);
- } else if ($this->show_start_date == true ) {
- $ret.=sprintf(' %s ',$l_line['p_id']
- ,$sel
- ,$l_line['p_start_string']
- );
- } else if ( $this->show_end_date == true ) {
- $ret.=sprintf(' %s ',$l_line['p_id']
- ,$sel
- ,$l_line['p_end_string']
- );
- }
+ if ( $this->show_start_date == true && $this->show_end_date==true )
+ {
+ $ret.=sprintf(' %s - %s',$l_line['p_id']
+ ,$sel
+ ,$l_line['p_start_string']
+ ,$l_line['p_end_string']);
+ }
+ else if ($this->show_start_date == true )
+ {
+ $ret.=sprintf(' %s ',$l_line['p_id']
+ ,$sel
+ ,$l_line['p_start_string']
+ );
+ }
+ else if ( $this->show_end_date == true )
+ {
+ $ret.=sprintf(' %s ',$l_line['p_id']
+ ,$sel
+ ,$l_line['p_end_string']
+ );
+ }
- }
- $ret.=" ";
- return $ret;
-
+ }
+ $ret.=" ";
+ return $ret;
- }
- /*!\brief print in html the readonly value of the widget*/
- public function display()
- {
- $r="not implemented ".__FILE__.":".__LINE__;
- return $r;
- }
- static public function test_me()
- {
+ }
+ /*!\brief print in html the readonly value of the widget*/
+ public function display()
+ {
+ $r="not implemented ".__FILE__.":".__LINE__;
+ return $r;
- }
+ }
+ static public function test_me()
+ {
+ }
}
diff --git a/include/class_ipopup.php b/include/class_ipopup.php
index 9a7ce93d8..cff8d4813 100644
--- a/include/class_ipopup.php
+++ b/include/class_ipopup.php
@@ -30,138 +30,160 @@ require_once('class_html_input.php');
class IPopup extends HtmlInput
{
- var $name; /*!< name name and id of the div */
- function __construct($p_name)
- {
- $this->name=$p_name;
- $this->parameter='';
- $this->attribute=array();
- $this->drag=false;
- $this->blocking=true;
- }
- function set_width($p_val) {
- $js=sprintf('$("%s'.'_border").style.width="%s";',
- $this->name,$p_val);
- $this->parameter.=$js;
-
- }
- function set_height($p_val) {
- $js=sprintf('$("%s'.'_border").style.height="%s";',
- $this->name,$p_val);
- $this->parameter.=$js;
-
- }
- /**
- *@brief set or not a blocking fond
- *@param $p_block if true if you want to avoid access to background,
- *accept true or false
- */
- function set_block($p_block) {
- $this->blocking=$p_block;
- }
-
- function set_zindex($p_val) {
- $js=sprintf('$("%s'.'_border").style.zIndex=%d;',
- $this->name,$p_val);
- $js=sprintf('$("%s'.'_content").style.zIndex=%d;',
- $this->name,$p_val);
- $this->parameter.=$js;
- }
- function set_dragguable($p_value){
- $this->drag=$p_value;
- }
- /*!\brief set the attribute thanks javascript as the width, the position ...
- *\param $p_name attribute name
- *\param $p_val val of the attribute
- *\note add to the this->attribut, it will be used in input()
- */
- function set_attribute($p_name,$p_val) {
- $this->attribute[]=array($p_name,$p_val);
- }
- /*!\brief set the title of a ipopup thanks javascript and php mode
- *\param title of the IPopup
- *\return html string with js script
- */
- function set_title($p_title) {
- $this->title=$p_title;
- $s=sprintf('$("%s_"+"title")="%s"',
- $this->name,$this->title);
- return create_script($s);
- }
- function input() {
- $r="";
- if ($this->blocking) {
- $r.=sprintf('";
+ var $name; /*!< name name and id of the div */
+ function __construct($p_name)
+ {
+ $this->name=$p_name;
+ $this->parameter='';
+ $this->attribute=array();
+ $this->drag=false;
+ $this->blocking=true;
}
- if ( isset($this->title) && trim($this->title) != "" ) {
- $r.=sprintf('';
}
@@ -145,31 +147,33 @@ if ( $low_action == "list" )
* Detail for a card, Suivi, Contact, Operation,... *
* cc stands for customer card
*----------------------------------------------------------------------*/
-if ( $low_action == 'detail') {
- /* Menu */
- require_once('client_card.inc.php');
- exit();
+if ( $low_action == 'detail')
+{
+ /* Menu */
+ require_once('client_card.inc.php');
+ exit();
}
if ( $low_action=="insert" )
{
- /* security : check if user can add card */
- if ( $User->check_action(FICADD) == 0 ) {
- alert('Vous ne pouvez pas ajouter de fiche');
- return;
- }
+ /* security : check if user can add card */
+ if ( $User->check_action(FICADD) == 0 )
+ {
+ alert('Vous ne pouvez pas ajouter de fiche');
+ return;
+ }
- $customer=new Customer($cn);
- $customer->Save($_REQUEST['fd_id']);
- echo '';
- echo "
";
- echo $customer->Display(true);
- echo "
";
- $retour=new IAction();
- $retour->label="Retour";
- $retour->value="?p_action=client&".dossier::get();
- echo $retour->input();
- echo '
';
+ $customer=new Customer($cn);
+ $customer->Save($_REQUEST['fd_id']);
+ echo '';
+ echo "
";
+ echo $customer->Display(true);
+ echo "
";
+ $retour=new IAction();
+ $retour->label="Retour";
+ $retour->value="?p_action=client&".dossier::get();
+ echo $retour->input();
+ echo '
';
}
diff --git a/include/client_card.inc.php b/include/client_card.inc.php
index 2a3147b11..1f115ce62 100644
--- a/include/client_card.inc.php
+++ b/include/client_card.inc.php
@@ -31,42 +31,43 @@ require_once('class_ipopup.php');
echo ICard::ipopup('ipopcard');
- /* $sub_action = sb = detail */
- /* $cn database conx */
+/* $sub_action = sb = detail */
+/* $cn database conx */
$return= HtmlInput::button_anchor('Retour','?p_action=client&'.$str_dossier);
$root="?p_action=client&sb=detail&f_id=".$_REQUEST["f_id"].'&'.$str_dossier;
$ss_action=( isset ($_REQUEST['sc'] ))? $_REQUEST['sc']: '';
-switch ($ss_action) {
+switch ($ss_action)
+{
case 'dc':
- $def=1;
- break;
+ $def=1;
+ break;
case 'sv': /* all the actions (mail,meeting...) */
- $def=2;
- break;
+ $def=2;
+ break;
case 'cn':
- $def=3;
- break;
+ $def=3;
+ break;
case 'op':
- $def=4;
- break;
+ $def=4;
+ break;
case 'let':
- $def=6;
- break;
+ $def=6;
+ break;
default:
- $def=1;
- $ss_action='dc';
+ $def=1;
+ $ss_action='dc';
}
$f=new Fiche($cn,$_REQUEST['f_id']);
echo '';
echo '';
echo '
';
@@ -79,55 +80,60 @@ echo '
';
//---------------------------------------------------------------------------
if ( $ss_action == 'dc' )
{
- require_once('detail_client.inc.php');
+ require_once('detail_client.inc.php');
}
//---------------------------------------------------------------------------
// Follow up : mail, bons de commande, livraison, rendez-vous...
//---------------------------------------------------------------------------
-if ( $ss_action == 'sv' ) {
- require_once('suivi_client.inc.php');
+if ( $ss_action == 'sv' )
+{
+ require_once('suivi_client.inc.php');
}
/*----------------------------------------------------------------------
* Operation all the operation of this customer
*
* ----------------------------------------------------------------------*/
-if ( $ss_action == 'op') {
- require_once('operation_client.inc.php');
+if ( $ss_action == 'op')
+{
+ require_once('operation_client.inc.php');
}
/*----------------------------------------------------------------------
* All the contact
*
*----------------------------------------------------------------------*/
-if ( $ss_action == 'cn') {
- echo '
';
- echo dossier::hidden();
- $f=new Fiche($cn,$_REQUEST['f_id']);
- $contact=new Contact($cn);
- $contact->company=$f->get_quick_code();
- echo $contact->summary();
+if ( $ss_action == 'cn')
+{
+ echo '
';
+ echo dossier::hidden();
+ $f=new Fiche($cn,$_REQUEST['f_id']);
+ $contact=new Contact($cn);
+ $contact->company=$f->get_quick_code();
+ echo $contact->summary();
- $sql=' select fd_id from fiche_def where frd_id='.FICHE_TYPE_CONTACT;
- $filter=$cn->make_list($sql);
- if ( empty ($filter)) {
- echo '';
- echo _("Vous devez aller dans fiche et créer une catégorie pour les contacts");
- echo ' ';
- exit();
- }
- /* Add button */
- $f_add_button=new IButton('add_card');
- $f_add_button->label=_('Créer une nouvelle fiche');
- $f_add_button->set_attribute('ipopup','ipopcard');
-
- $f_add_button->set_attribute('filter',$filter);
- $f_add_button->javascript=" select_card_type(this);";
+ $sql=' select fd_id from fiche_def where frd_id='.FICHE_TYPE_CONTACT;
+ $filter=$cn->make_list($sql);
+ if ( empty ($filter))
+ {
+ echo '';
+ echo _("Vous devez aller dans fiche et créer une catégorie pour les contacts");
+ echo ' ';
+ exit();
+ }
+ /* Add button */
+ $f_add_button=new IButton('add_card');
+ $f_add_button->label=_('Créer une nouvelle fiche');
+ $f_add_button->set_attribute('ipopup','ipopcard');
- echo $f_add_button->input();
- echo '
';
+ $f_add_button->set_attribute('filter',$filter);
+ $f_add_button->javascript=" select_card_type(this);";
+
+ echo $f_add_button->input();
+ echo '
';
}
/*----------------------------------------------------------------------------
* Lettering
*----------------------------------------------------------------------------*/
-if ( $def==6 ) {
- require_once('lettering.gestion.inc.php');
+if ( $def==6 )
+{
+ require_once('lettering.gestion.inc.php');
}
diff --git a/include/compta_ach.inc.php b/include/compta_ach.inc.php
index c67760de0..530259ff3 100644
--- a/include/compta_ach.inc.php
+++ b/include/compta_ach.inc.php
@@ -42,35 +42,36 @@ echo $pop_tva->input();
$p_action=(isset($_REQUEST['p_action']))?$_REQUEST['p_action']:'';
$cn=new Database(dossier::id());
- //menu = show a list of ledger
+//menu = show a list of ledger
$str_dossier=dossier::get();
$array=array(
- array('?p_action=ach&sa=n&'.$str_dossier,_('Nouvelle dépense'),_('Nouvel achat ou dépense'),1),
- array('?p_action=ach&sa=l&'.$str_dossier,_('Liste achat'),_('Liste des achats'),2),
- array('?p_action=ach&sa=lnp&'.$str_dossier,_('Liste dépenses non payées'),_('Liste des ventes non payées'),3),
- array('commercial.php?p_action=supplier&'.$str_dossier,_('Fournisseurs'),_('Fournisseurs')),
- array('?p_action=impress&type=jrn&'.$str_dossier,_('Impression'),_('Impression'))
- );
+ array('?p_action=ach&sa=n&'.$str_dossier,_('Nouvelle dépense'),_('Nouvel achat ou dépense'),1),
+ array('?p_action=ach&sa=l&'.$str_dossier,_('Liste achat'),_('Liste des achats'),2),
+ array('?p_action=ach&sa=lnp&'.$str_dossier,_('Liste dépenses non payées'),_('Liste des ventes non payées'),3),
+ array('commercial.php?p_action=supplier&'.$str_dossier,_('Fournisseurs'),_('Fournisseurs')),
+ array('?p_action=impress&type=jrn&'.$str_dossier,_('Impression'),_('Impression'))
+ );
$sa=(isset ($_REQUEST['sa']))?$_REQUEST['sa']:-1;
$def=1;
-switch ($sa) {
- case 'n':
- $def=1;
- $use_predef=0;
- break;
- case 'p':
- $def=1;
- $use_predef=1;
- break;
- case 'l':
- $def=2;
- break;
- case 'lnp':
- $def=3;
- break;
- }
+switch ($sa)
+{
+case 'n':
+ $def=1;
+ $use_predef=0;
+ break;
+case 'p':
+ $def=1;
+ $use_predef=1;
+ break;
+case 'l':
+ $def=2;
+ break;
+case 'lnp':
+ $def=3;
+ break;
+}
//if ( $_REQUEST['p_action'] == 'fournisseur') $def=5;
echo '
';
+ $bk_card=new Fiche($cn);
+ $bk_card->id=$Ledger->get_bank();
+ $filter_year=" j_tech_per in (select p_id from parm_periode where p_exercice='".$User->get_exercice()."')";
- /* get saldo for not reconcilied operations */
- $saldo_not_reconcilied=$bk_card->get_solde_detail($filter_year." and j_grpt in (select jr_grpt_id from jrn where trim(jr_pj_number) ='' or jr_pj_number is null)" );
+ /* get saldo for not reconcilied operations */
+ $saldo_not_reconcilied=$bk_card->get_solde_detail($filter_year." and j_grpt in (select jr_grpt_id from jrn where trim(jr_pj_number) ='' or jr_pj_number is null)" );
- /* get saldo for reconcilied operation */
- $saldo_reconcilied=$bk_card->get_solde_detail($filter_year." and j_grpt in (select jr_grpt_id from jrn where trim(jr_pj_number) != '' and jr_pj_number is not null)" );
+ /* get saldo for reconcilied operation */
+ $saldo_reconcilied=$bk_card->get_solde_detail($filter_year." and j_grpt in (select jr_grpt_id from jrn where trim(jr_pj_number) != '' and jr_pj_number is not null)" );
- /* solde compte */
- $saldo=$bk_card->get_solde_detail($filter_year);
+ /* solde compte */
+ $saldo=$bk_card->get_solde_detail($filter_year);
- echo '';
- echo '';
- echo td("Solde compte ");
- echo td(sprintf('%.2f',($saldo['debit']-$saldo['credit'])),' style="text-align:right"');
- echo ' ';
+ echo '';
+ echo '';
+ echo td("Solde compte ");
+ echo td(sprintf('%.2f',($saldo['debit']-$saldo['credit'])),' style="text-align:right"');
+ echo ' ';
- echo '';
- echo td("Solde non rapproché ");
- echo td(sprintf('%.2f',($saldo_not_reconcilied['debit']-$saldo_not_reconcilied['credit'])),' style="text-align:right"');
- echo ' ';
+ echo '';
+ echo td("Solde non rapproché ");
+ echo td(sprintf('%.2f',($saldo_not_reconcilied['debit']-$saldo_not_reconcilied['credit'])),' style="text-align:right"');
+ echo ' ';
- echo '';
- echo td("Solde rapproché ");
- echo td(sprintf('%.2f',($saldo_reconcilied['debit']-$saldo_reconcilied['credit'])),' style="text-align:right"');
- echo ' ';
+ echo '';
+ echo td("Solde rapproché ");
+ echo td(sprintf('%.2f',($saldo_reconcilied['debit']-$saldo_reconcilied['credit'])),' style="text-align:right"');
+ echo ' ';
- echo '';
- echo td("Total montant ");
- echo td(sprintf('%.2f',($tot_not_reconcilied)),' style="text-align:right"');
- echo ' ';
+ echo '';
+ echo td("Total montant ");
+ echo td(sprintf('%.2f',($tot_not_reconcilied)),' style="text-align:right"');
+ echo ' ';
- echo '
';
+ echo '
';
- echo HtmlInput::submit('save','Mettre à jour le n° de relevé banquaire');
- echo '';
- echo '';
- exit();
+ echo HtmlInput::submit('save','Mettre à jour le n° de relevé banquaire');
+ echo '';
+ echo '';
+ exit();
}
diff --git a/include/compta_ven.inc.php b/include/compta_ven.inc.php
index 65aa5f94a..e4ba21010 100644
--- a/include/compta_ven.inc.php
+++ b/include/compta_ven.inc.php
@@ -45,34 +45,35 @@ echo $pop_tva->input();
$p_action=(isset($_REQUEST['p_action']))?$_REQUEST['p_action']:'';
$gDossier=dossier::id();
$cn=new Database(dossier::id());
- //menu = show a list of ledger
+//menu = show a list of ledger
$str_dossier=dossier::get();
$array=array(
- array('?p_action=ven&sa=n&'.$str_dossier,_('Nouvelle vente'),_('Nouvelle vente'),1),
- array('?p_action=ven&sa=l&'.$str_dossier,_('Liste ventes'),_('Liste des ventes'),2),
- array('?p_action=ven&sa=lnp&'.$str_dossier,_('Liste vente non payées'),_('Liste des ventes non payées'),3),
- array('commercial.php?p_action=client&'.$str_dossier,_('Clients'),_('Clients')),
- array('?p_action=impress&type=jrn&'.$str_dossier,_('Impression'),_('Impression'))
- );
+ array('?p_action=ven&sa=n&'.$str_dossier,_('Nouvelle vente'),_('Nouvelle vente'),1),
+ array('?p_action=ven&sa=l&'.$str_dossier,_('Liste ventes'),_('Liste des ventes'),2),
+ array('?p_action=ven&sa=lnp&'.$str_dossier,_('Liste vente non payées'),_('Liste des ventes non payées'),3),
+ array('commercial.php?p_action=client&'.$str_dossier,_('Clients'),_('Clients')),
+ array('?p_action=impress&type=jrn&'.$str_dossier,_('Impression'),_('Impression'))
+ );
$sa=(isset ($_REQUEST['sa']))?$_REQUEST['sa']:-1;
$def=1;
-switch ($sa) {
- case 'n':
- $def=1;
- $use_predef=0;
- break;
- case 'p':
- $def=1;
- $use_predef=1;
- break;
- case 'l':
- $def=2;
- break;
- case 'lnp':
- $def=3;
- break;
- }
+switch ($sa)
+{
+case 'n':
+ $def=1;
+ $use_predef=0;
+ break;
+case 'p':
+ $def=1;
+ $use_predef=1;
+ break;
+case 'l':
+ $def=2;
+ break;
+case 'lnp':
+ $def=3;
+ break;
+}
echo '';
// First time in html
// after in pdf or cvs
//-----------------------------------------------------
-if ( isset( $_REQUEST['bt_html'] ) ) {
- if ( isDate($_REQUEST['from_periode'])==null || isDate($_REQUEST['to_periode'])==null){
- echo alert('Date malformée, désolée');
- exit();
- }
- require_once("class_acc_account_ledger.php");
- $go=0;
+if ( isset( $_REQUEST['bt_html'] ) )
+{
+ if ( isDate($_REQUEST['from_periode'])==null || isDate($_REQUEST['to_periode'])==null)
+ {
+ echo alert('Date malformée, désolée');
+ exit();
+ }
+ require_once("class_acc_account_ledger.php");
+ $go=0;
// we ask a poste_id
- if ( isset($_GET['poste_id']) && strlen(trim($_GET['poste_id'])) != 0 && isNumber($_GET['poste_id']) )
+ if ( isset($_GET['poste_id']) && strlen(trim($_GET['poste_id'])) != 0 && isNumber($_GET['poste_id']) )
{
- if ( isset ($_GET['poste_fille']) )
- {
- $parent=$_GET['poste_id'];
- $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text like '$parent%' order by pcm_val::text");
- $go=3;
- }
- // Check if the post is numeric and exists
- elseif ( $cn->count_sql('select * from tmp_pcmn where pcm_val=$1',array($_GET['poste_id'])) != 0 )
- {
- $Poste=new Acc_Account_Ledger($cn,$_GET['poste_id']);$go=1;
- }
+ if ( isset ($_GET['poste_fille']) )
+ {
+ $parent=$_GET['poste_id'];
+ $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text like '$parent%' order by pcm_val::text");
+ $go=3;
+ }
+ // Check if the post is numeric and exists
+ elseif ( $cn->count_sql('select * from tmp_pcmn where pcm_val=$1',array($_GET['poste_id'])) != 0 )
+ {
+ $Poste=new Acc_Account_Ledger($cn,$_GET['poste_id']);
+ $go=1;
+ }
}
- if ( strlen(trim($_GET['f_id'])) != 0 )
+ if ( strlen(trim($_GET['f_id'])) != 0 )
{
- require_once("class_fiche.php");
- // thanks the qcode we found the poste account
- $fiche=new Fiche($cn);
- $qcode=$fiche->get_by_qcode($_GET['f_id']);
- $p=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
- if ( $p != NOTFOUND) {
- $go=2;
- }
- }
-
- // A account is given
- if ( $go == 1)
- {
- echo '';
- if ( ! isset($_REQUEST['oper_detail']) ) {
- Acc_Account_Ledger::HtmlTableHeader();
- $Poste->HtmlTable(null,$_GET['ople']);
- echo Acc_Account_Ledger::HtmlTableHeader();
- } else {
- //----------------------------------------------------------------------
- // Detail
- //----------------------------------------------------------------------
- Acc_Account_Ledger::HtmlTableHeader();
- $Poste->get_row_date( $_GET['from_periode'], $_GET['to_periode'],$_GET['ople']);
- if ( empty($Poste->row)) exit();
- $Poste->load();
- echo '
';
- echo ''. $_GET['poste_id'].' '.h($Poste->label).' ';
- /* avoid duplicates */
- $old=array();
- foreach ($Poste->row as $detail) {
- if ( in_array($detail['jr_id'],$old) == TRUE ) continue;
- $old[]=$detail['jr_id'];
- echo ''.$detail['j_date'].' '.$detail['jr_internal'].h($detail['description']).' ';
-
- $op=new Acc_Operation($cn);
- $op->jr_id=$detail['jr_id'];
- $op->poste=$_GET['poste_id'];
- echo $op->display_jrnx_detail(1);
- }
- echo '
';
- echo Acc_Account_Ledger::HtmlTableHeader();
- }
- echo "
";
- exit;
- }
-
- // A QuickCode is given
- if ( $go == 2)
- {
- if ( ! isset($_REQUEST['oper_detail']) ) {
- echo '';
- $fiche->HtmlTableHeader();
- $fiche->HtmlTable(null,$_GET['ople']);
- $fiche->HtmlTableHeader();
- echo "
";
- } else {
- // Detail //
- echo '';
- $fiche->HtmlTableHeader();
- $fiche->HtmlTableDetail();
- $fiche->HtmlTableHeader();
-
- }
- exit;
- }
-
- // All the children account
- if ( $go == 3 )
- {
-
- if ( sizeof($a_poste) == 0 )
- exit;
- echo '
';
-
-
- if ( ! isset ($_REQUEST['oper_detail'])) {
- $Poste=new Acc_Account_Ledger($cn,$_GET['poste_id']);
- echo Acc_Account_Ledger::HtmlTableHeader();
-
- foreach ($a_poste as $poste_id )
- {
- $Poste=new Acc_Account_Ledger ($cn,$poste_id['pcm_val']);
- $Poste->HtmlTable(null,$_GET['ople']);
- }
- echo Acc_Account_Ledger::HtmlTableHeader();
- echo "
";
- } else {
- //----------------------------------------------------------------------
- // Detail
- //----------------------------------------------------------------------
- echo Acc_Account_Ledger::HtmlTableHeader();
- echo '
';
- foreach ($a_poste as $poste_id )
- {
- $Poste=new Acc_Account_Ledger ($cn,$poste_id['pcm_val']);
- $Poste->load();
- $Poste->get_row_date( $_GET['from_periode'], $_GET['to_periode']);
- if ( empty($Poste->row)) continue;
- echo ''. $poste_id['pcm_val'].' '.h($Poste->label).' ';
-
- $detail=$Poste->row[0];
-
- $old=array();
-
- foreach ($Poste->row as $detail) {
- /* avoid duplicates */
- if ( in_array($detail['jr_id'],$old) == TRUE ) continue;
- $old[]=$detail['jr_id'];
- echo ''. $detail['j_date'].' '.$detail['jr_internal'].' '.hb($detail['description']).' '.hi($detail['jr_pj_number']).' ';
-
- $op=new Acc_Operation($cn);
- $op->poste=$poste_id['pcm_val'];
-
- $op->jr_id=$detail['jr_id'];
- echo $op->display_jrnx_detail(1);
- }
- }
- echo '
';
- echo Acc_Account_Ledger::HtmlTableHeader();
- }
-
- exit;
+ require_once("class_fiche.php");
+ // thanks the qcode we found the poste account
+ $fiche=new Fiche($cn);
+ $qcode=$fiche->get_by_qcode($_GET['f_id']);
+ $p=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
+ if ( $p != NOTFOUND)
+ {
+ $go=2;
+ }
}
-}
+
+ // A account is given
+ if ( $go == 1)
+ {
+ echo '
';
+ if ( ! isset($_REQUEST['oper_detail']) )
+ {
+ Acc_Account_Ledger::HtmlTableHeader();
+ $Poste->HtmlTable(null,$_GET['ople']);
+ echo Acc_Account_Ledger::HtmlTableHeader();
+ }
+ else
+ {
+ //----------------------------------------------------------------------
+ // Detail
+ //----------------------------------------------------------------------
+ Acc_Account_Ledger::HtmlTableHeader();
+ $Poste->get_row_date( $_GET['from_periode'], $_GET['to_periode'],$_GET['ople']);
+ if ( empty($Poste->row)) exit();
+ $Poste->load();
+ echo '
';
+ echo ''. $_GET['poste_id'].' '.h($Poste->label).' ';
+ /* avoid duplicates */
+ $old=array();
+ foreach ($Poste->row as $detail)
+ {
+ if ( in_array($detail['jr_id'],$old) == TRUE ) continue;
+ $old[]=$detail['jr_id'];
+ echo ''.$detail['j_date'].' '.$detail['jr_internal'].h($detail['description']).' ';
+
+ $op=new Acc_Operation($cn);
+ $op->jr_id=$detail['jr_id'];
+ $op->poste=$_GET['poste_id'];
+ echo $op->display_jrnx_detail(1);
+ }
+ echo '
';
+ echo Acc_Account_Ledger::HtmlTableHeader();
+ }
+ echo "
";
+ exit;
+ }
+
+ // A QuickCode is given
+ if ( $go == 2)
+ {
+ if ( ! isset($_REQUEST['oper_detail']) )
+ {
+ echo '
';
+ $fiche->HtmlTableHeader();
+ $fiche->HtmlTable(null,$_GET['ople']);
+ $fiche->HtmlTableHeader();
+ echo "
";
+ }
+ else
+ {
+ // Detail //
+ echo '
';
+ $fiche->HtmlTableHeader();
+ $fiche->HtmlTableDetail();
+ $fiche->HtmlTableHeader();
+
+ }
+ exit;
+ }
+
+ // All the children account
+ if ( $go == 3 )
+ {
+
+ if ( sizeof($a_poste) == 0 )
+ exit;
+ echo '
';
+
+
+ if ( ! isset ($_REQUEST['oper_detail']))
+ {
+ $Poste=new Acc_Account_Ledger($cn,$_GET['poste_id']);
+ echo Acc_Account_Ledger::HtmlTableHeader();
+
+ foreach ($a_poste as $poste_id )
+ {
+ $Poste=new Acc_Account_Ledger ($cn,$poste_id['pcm_val']);
+ $Poste->HtmlTable(null,$_GET['ople']);
+ }
+ echo Acc_Account_Ledger::HtmlTableHeader();
+ echo "
";
+ }
+ else
+ {
+ //----------------------------------------------------------------------
+ // Detail
+ //----------------------------------------------------------------------
+ echo Acc_Account_Ledger::HtmlTableHeader();
+ echo '
';
+ foreach ($a_poste as $poste_id )
+ {
+ $Poste=new Acc_Account_Ledger ($cn,$poste_id['pcm_val']);
+ $Poste->load();
+ $Poste->get_row_date( $_GET['from_periode'], $_GET['to_periode']);
+ if ( empty($Poste->row)) continue;
+ echo ''. $poste_id['pcm_val'].' '.h($Poste->label).' ';
+
+ $detail=$Poste->row[0];
+
+ $old=array();
+
+ foreach ($Poste->row as $detail)
+ {
+ /* avoid duplicates */
+ if ( in_array($detail['jr_id'],$old) == TRUE ) continue;
+ $old[]=$detail['jr_id'];
+ echo ''. $detail['j_date'].' '.$detail['jr_internal'].' '.hb($detail['description']).' '.hi($detail['jr_pj_number']).' ';
+
+ $op=new Acc_Operation($cn);
+ $op->poste=$poste_id['pcm_val'];
+
+ $op->jr_id=$detail['jr_id'];
+ echo $op->display_jrnx_detail(1);
+ }
+ }
+ echo '
';
+ echo Acc_Account_Ledger::HtmlTableHeader();
+ }
+
+ exit;
+ }
+}
?>
diff --git a/include/impress_rapport.inc.php b/include/impress_rapport.inc.php
index 8abd3a983..be05dad91 100644
--- a/include/impress_rapport.inc.php
+++ b/include/impress_rapport.inc.php
@@ -1,4 +1,4 @@
-get_name();
- // step asked ?
- //--
+if ( isset( $_GET['bt_html'] ) )
+{
+ $Form=new Acc_Report($cn,$_GET['form_id']);
+ $Form->get_name();
+ // step asked ?
+ //--
- if ( $_GET['type_periode'] == 1 )
- $array=$Form->get_row( $_GET['from_date'],$_GET['to_date'], $_GET['type_periode']);
+ if ( $_GET['type_periode'] == 1 )
+ $array=$Form->get_row( $_GET['from_date'],$_GET['to_date'], $_GET['type_periode']);
- if ($_GET['type_periode'] == 0 && $_GET['p_step'] == 0 )
- $array=$Form->get_row( $_GET['from_periode'],$_GET['to_periode'], $_GET['type_periode']);
-
-
- if ($_GET['type_periode'] == 0 && $_GET['p_step'] == 1 ) {
- // step are asked
- //--
- for ($e=$_GET['from_periode'];$e<=$_GET['to_periode'];$e+=$_GET['p_step'])
- {
+ if ($_GET['type_periode'] == 0 && $_GET['p_step'] == 0 )
+ $array=$Form->get_row( $_GET['from_periode'],$_GET['to_periode'], $_GET['type_periode']);
- $periode=getPeriodeName($cn,$e);
- if ( $periode == null ) continue;
- $array[]=$Form->get_row($e,$e,$_GET['type_periode']);
- $periode_name[]=$periode;
- }
+
+ if ($_GET['type_periode'] == 0 && $_GET['p_step'] == 1 )
+ {
+ // step are asked
+ //--
+ for ($e=$_GET['from_periode'];$e<=$_GET['to_periode'];$e+=$_GET['p_step'])
+ {
+
+ $periode=getPeriodeName($cn,$e);
+ if ( $periode == null ) continue;
+ $array[]=$Form->get_row($e,$e,$_GET['type_periode']);
+ $periode_name[]=$periode;
+ }
}
- $rep="";
+ $rep="";
- $hid=new IHidden();
- echo '
';
- if ( $_GET['type_periode'] == 0) {
- $t=($_GET['from_periode']==$_GET['to_periode'])?"":" -> ".getPeriodeName($cn,$_GET['to_periode'],'p_end');
- echo '
'.$Form->id." ".$Form->name.
- " - ".getPeriodeName($cn,$_GET['from_periode'],'p_start').
- " ".$t.
- ' ';
- } else {
- echo '
'.$Form->id." ".$Form->name.
- ' Date :'.
- $_GET['from_date'].
- " au ".
- $_GET['to_date'].
- ' ';
- }
- echo '
';
- echo '';
- echo ''.
- dossier::hidden().
+ $hid=new IHidden();
+ echo '';
+ if ( $_GET['type_periode'] == 0)
+ {
+ $t=($_GET['from_periode']==$_GET['to_periode'])?"":" -> ".getPeriodeName($cn,$_GET['to_periode'],'p_end');
+ echo '
'.$Form->id." ".$Form->name.
+ " - ".getPeriodeName($cn,$_GET['from_periode'],'p_start').
+ " ".$t.
+ ' ';
+ }
+ else
+ {
+ echo '
'.$Form->id." ".$Form->name.
+ ' Date :'.
+ $_GET['from_date'].
+ " au ".
+ $_GET['to_date'].
+ ' ';
+ }
+ echo '
';
+ echo '';
+ echo ''.
+ dossier::hidden().
HtmlInput::submit('bt_other',"Autre Rapport").
$hid->input("type","rapport").$hid->input("p_action","impress")." ";
- echo ''.
+ echo ''.
HtmlInput::submit('bt_pdf',"Export PDF").
- dossier::hidden().
+ dossier::hidden().
$hid->input("type","rapport").
$hid->input("p_action","impress").
$hid->input("form_id",$Form->id);
- if ( isset($_GET['from_periode'])) echo $hid->input("from_periode",$_GET['from_periode']);
- if ( isset($_GET['to_periode'])) echo $hid->input("to_periode",$_GET['to_periode']);
- if (isset($_GET['p_step'])) echo $hid->input("p_step",$_GET['p_step']);
- if ( isset($_GET['from_date'])) echo $hid->input("from_date",$_GET['from_date']);
- if ( isset($_GET['to_date'])) echo $hid->input("to_date",$_GET['to_date']);
+ if ( isset($_GET['from_periode'])) echo $hid->input("from_periode",$_GET['from_periode']);
+ if ( isset($_GET['to_periode'])) echo $hid->input("to_periode",$_GET['to_periode']);
+ if (isset($_GET['p_step'])) echo $hid->input("p_step",$_GET['p_step']);
+ if ( isset($_GET['from_date'])) echo $hid->input("from_date",$_GET['from_date']);
+ if ( isset($_GET['to_date'])) echo $hid->input("to_date",$_GET['to_date']);
echo $hid->input("type_periode",$_GET['type_periode']);
- echo " ";
- echo ''.
+ echo " ";
+ echo ''.
HtmlInput::submit('bt_csv',"Export CSV").
dossier::hidden().
$hid->input("type","form").
$hid->input("p_action","impress").
$hid->input("form_id",$Form->id);
- if ( isset($_GET['from_periode'])) echo $hid->input("from_periode",$_GET['from_periode']);
- if ( isset($_GET['to_periode'])) echo $hid->input("to_periode",$_GET['to_periode']);
- if (isset($_GET['p_step'])) echo $hid->input("p_step",$_GET['p_step']);
- if ( isset($_GET['from_date'])) echo $hid->input("from_date",$_GET['from_date']);
- if ( isset($_GET['to_date'])) echo $hid->input("to_date",$_GET['to_date']);
- echo $hid->input("type_periode",$_GET['type_periode']);
+ if ( isset($_GET['from_periode'])) echo $hid->input("from_periode",$_GET['from_periode']);
+ if ( isset($_GET['to_periode'])) echo $hid->input("to_periode",$_GET['to_periode']);
+ if (isset($_GET['p_step'])) echo $hid->input("p_step",$_GET['p_step']);
+ if ( isset($_GET['from_date'])) echo $hid->input("from_date",$_GET['from_date']);
+ if ( isset($_GET['to_date'])) echo $hid->input("to_date",$_GET['to_date']);
+ echo $hid->input("type_periode",$_GET['type_periode']);
- echo " ";
+ echo " ";
- echo " ";
+ echo "";
- echo "
";
- if ( count($Form->row ) == 0 )
- exit;
- if ( $_GET['type_periode']==0 ) {
- if ( $_GET['p_step'] == 0)
- { // check the step
- // show tables
- ShowReportResult($Form->row);
- }
- else
- {
- $a=0;
- foreach ( $array as $e) {
- echo '
Periode : '.$periode_name[$a]." ";
- $a++;
- ShowReportResult($e);
- }
- }
+ echo "
";
+ if ( count($Form->row ) == 0 )
+ exit;
+ if ( $_GET['type_periode']==0 )
+ {
+ if ( $_GET['p_step'] == 0)
+ { // check the step
+ // show tables
+ ShowReportResult($Form->row);
+ }
+ else
+ {
+ $a=0;
+ foreach ( $array as $e)
+ {
+ echo '
Periode : '.$periode_name[$a]." ";
+ $a++;
+ ShowReportResult($e);
+ }
+ }
}
- else {
- ShowReportResult($Form->row);
- }
- echo "
";
- exit;
+ else
+ {
+ ShowReportResult($Form->row);
+ }
+ echo "
";
+ exit;
}
//-----------------------------------------------------
@@ -151,12 +159,13 @@ if ( isset( $_GET['bt_html'] ) ) {
//-----------------------------------------------------
require_once('class_database.php');
$ret=$cn->make_array("select fr_id,fr_label
- from formdef
- order by fr_label");
-if ( sizeof($ret) == 0 ) {
- echo "Aucun Rapport";
- return;
- }
+ from formdef
+ order by fr_label");
+if ( sizeof($ret) == 0 )
+{
+ echo "Aucun Rapport";
+ return;
+}
//-----------------------------------------------------
// Form
//-----------------------------------------------------
@@ -175,9 +184,9 @@ print $w->input("form_id",$ret);
print '';
//-- calendrier ou periode comptable
$aCal=array(
- array('value'=>0,'label'=>'Période comptable'),
- array('value'=>1,'label'=>'Calendrier')
- );
+ array('value'=>0,'label'=>'Période comptable'),
+ array('value'=>1,'label'=>'Calendrier')
+ );
$w->javascript=' onchange=enable_type_periode();';
echo '
';
@@ -206,9 +215,9 @@ echo td($date->input('to_date'));
echo ' ';
$aStep=array(
- array('value'=>0,'label'=>'Pas d\'étape'),
- array('value'=>1,'label'=>'1 mois')
- );
+ array('value'=>0,'label'=>'Pas d\'étape'),
+ array('value'=>1,'label'=>'1 mois')
+ );
echo '
';
echo td('Par étape de');
echo $w->input('p_step',$aStep);
@@ -227,25 +236,27 @@ echo '';
//-----------------------------------------------------
// Function
//-----------------------------------------------------
- function ShowReportResult($p_array) {
-
- echo '';
- echo "".
- " Description ".
- " montant ".
- " ";
- $i=0;
- foreach ( $p_array as $op ) {
- $i++;
- $class= ( $i % 2 == 0 )?' class="odd"':"";
-
- echo "".
- "".h($op['desc'])." ".
- "".sprintf("% 8.2f",$op['montant'])." ".
- " ";
- }
- echo "
";
+function ShowReportResult($p_array)
+{
- }
+ echo '';
+ echo "".
+ " Description ".
+ " montant ".
+ " ";
+ $i=0;
+ foreach ( $p_array as $op )
+ {
+ $i++;
+ $class= ( $i % 2 == 0 )?' class="odd"':"";
+
+ echo "".
+ "".h($op['desc'])." ".
+ "".sprintf("% 8.2f",$op['montant'])." ".
+ " ";
+ }
+ echo "
";
+
+}
?>
diff --git a/include/impress_rec.inc.php b/include/impress_rec.inc.php
index c283d6e22..34f3ca53e 100644
--- a/include/impress_rec.inc.php
+++ b/include/impress_rec.inc.php
@@ -34,7 +34,7 @@ echo load_all_script();
/**
*@file
*@todo add the export to PDF
- */
+ */
$aledger=$User->get_ledger('ALL',3);
echo '';
echo '
';
@@ -47,16 +47,20 @@ echo dossier::hidden().HtmlInput::hidden('p_action','impress').HtmlInput::hidden
echo 'Filtre par journal :'.HtmlInput::select_ledger($aledger,$r_jrn );
echo '
';
-$radio->selected=($choice==0)?true:false;$radio->value=0;
+$radio->selected=($choice==0)?true:false;
+$radio->value=0;
echo ''.$radio->input().'Opérations rapprochées'.' ';
-$radio->selected=($choice==1)?true:false;$radio->value=1;
+$radio->selected=($choice==1)?true:false;
+$radio->value=1;
echo ''.$radio->input().'Opérations rapprochées avec des montants différents'.' ';
-$radio->selected=($choice==2)?true:false;$radio->value=2;
+$radio->selected=($choice==2)?true:false;
+$radio->value=2;
echo ''.$radio->input().'Opérations rapprochées avec des montants identiques'.' ';
-$radio->selected=($choice==3)?true:false;$radio->value=3;
+$radio->selected=($choice==3)?true:false;
+$radio->value=3;
echo ''.$radio->input().'Opérations non rapprochées'.' ';
echo ''.HtmlInput::submit('vis',_('Visualisation')).' ';
@@ -70,22 +74,25 @@ if ( ! isset($_GET['vis'])) exit();
$a=new Acc_Reconciliation($cn);
$a->a_jrn=$r_jrn;
-switch ($choice) {
+switch ($choice)
+{
case 0:
- $array=$a->get_reconciled();
- break;
+ $array=$a->get_reconciled();
+ break;
case 1:
- $array=$a->get_reconciled_amount(false);
- break;
+ $array=$a->get_reconciled_amount(false);
+ break;
case 2:
- $array=$a->get_reconciled_amount(true);
- break;
+ $array=$a->get_reconciled_amount(true);
+ break;
case 3:
- $array=$a->get_not_reconciled();
- break;
+ $array=$a->get_not_reconciled();
+ break;
default:
- echo "Choix invalid";
- exit();
+ echo "Choix invalid";
+ exit();
}
require_once('template/impress_reconciliation.php');
+exit();
+exit();
exit();
\ No newline at end of file
diff --git a/include/impress_reconciliation.php b/include/impress_reconciliation.php
index 0753a8c9c..db4c3f60f 100644
--- a/include/impress_reconciliation.php
+++ b/include/impress_reconciliation.php
@@ -33,7 +33,7 @@ require_once ('class_acc_reconciliation.php');
/**
*@file
*@todo add the export to PDF
- */
+ */
$rjrn='';
$radio=new IRadio('choice');
echo ' ';
diff --git a/include/ing_be.inc.php b/include/ing_be.inc.php
index bda1e39e0..b78be0dee 100644
--- a/include/ing_be.inc.php
+++ b/include/ing_be.inc.php
@@ -1,4 +1,4 @@
-set_encoding('latin1');
-while (($data = fgetcsv($handle, 2000,'@')) !== FALSE) {
- $num = count($data);
- for ($c=0; $c < $num; $c++) {
-
- // first line is skipped
- if ( $row > 1 ) {
-
- $code=""; $date_exec=""; $date_valeur=""; $montant=""; $devise=""; $compte_ordre=""; $detail=""; $num_compte=""; $iduser="";
- list($num_compte, $code, $date_exec, $date_valeur, $montant, $devise, $montant2, $devise2, $rubriques, $detail, $zzz, $zzz, $date_comptable) = explode(";", $data[$c]);
-
- # Bug CSV ING : "424 au lieu de 424
-#"
- $code = str_replace("\"", "", $code);
-
- # Bug CSV ING : espace apres la date
- $date_exec = str_replace(" ", "", $date_exec);
- $date_valeur = str_replace(" ", "", $date_valeur);
- $date_exec = str_replace("\"", "", $date_exec);
- $date_valeur = str_replace("\"", "", $date_valeur);
- $montant = str_replace("\"", "", $montant);
- if ((myereg ("([0-9]{3})-([0-9]{7})-([0-9]{2})", $num_compte, $regs))){
- $num_compte = $regs[0];
- }
-
- // Si LTXXXXX ou LT XXXXX dans le détail
- if ((myereg ("LT+([0-9]{5})", $detail, $regs)) || (myereg ("LT+[ ]+([0-9]{5})", $detail, $regs))) {
- $iduser = $regs[1];
- }
-
- // Si XXXXXXXXXXXX
- if (myereg ("[0-9]{12}", $detail, $regs)){
- if($regs[0] != "000000000000") {
- $id = substr($regs[0], 2, 5);
- $longchiffre = substr($regs[0], 0, 10);
- $check = substr($regs[0], 10, 2);
- if (($longchiffre % 97) == $check) $iduser = $id;
- }
- }
-
- if($iduser != "" ) $poste_comptable = "400".$iduser;
- else $poste_comptable = "";
-
- list($jour,$mois,$annee) = explode("/", $date_valeur); $date_valeur = $annee."-".$mois."-".$jour;
- list($jour,$mois,$annee) = explode("/", $date_exec); $date_exec = $annee."-".$mois."-".$jour;
-
- $montant = str_replace(",", ".", $montant);
- $montant = str_replace("+", "", $montant);
-
- if($code < 10) $code = "000".$code;
- if($code >= 10 and $code < 100) $code = "00".$code;
- if($code >= 100) $code = "0".$code;
-
- $code = $annee."-".$code;
-
- $sql = "select * from import_tmp where code='".$code."' and num_compte='".$num_compte."'";
- $Res=$p_cn->exec_sql($sql);
- $Num=Database::num_row($Res);
-
- if($Num > 0) {
- echo "Opération FORTIS ".$code." déj&eagrave; importée. ";
- } else {
- //echo $code." ".$date_exec." ".$date_valeur." ".$montant." ".$devise." ".$compte_ordre." detail ".$num_compte." ".$poste_comptable." ";
- //$Sql="insert into import_tmp values ('$code','$date_exec','$date_valeur','$montant','$devise','".addslashes($compte_ordre)."','".addslashes($detail)."','$num_compte','$poste_comptable')";
- $Sql="insert into import_tmp (code,
- date_exec ,
- date_valeur,
- montant,
- devise,
- compte_ordre,
- detail,
- bq_account ,
- jrn,
- status)
- values ('$code',
- '$date_exec',
- '$date_exec',
- $montant,
- '$devise',
- '".addslashes($compte_ordre)."',
- '".addslashes($detail).$num_compte." ',
- '$p_bq_account',
- $p_jrn,
- 'n')";
- echo $sql;
- $Res=$p_cn->exec_sql($Sql);
- }
- }
+while (($data = fgetcsv($handle, 2000,'@')) !== FALSE)
+{
+ $num = count($data);
+ for ($c=0; $c < $num; $c++)
+ {
- } // for ($c=0;$c<$num;$c++)
- $row++;
+ // first line is skipped
+ if ( $row > 1 )
+ {
+
+ $code="";
+ $date_exec="";
+ $date_valeur="";
+ $montant="";
+ $devise="";
+ $compte_ordre="";
+ $detail="";
+ $num_compte="";
+ $iduser="";
+ list($num_compte, $code, $date_exec, $date_valeur, $montant, $devise, $montant2, $devise2, $rubriques, $detail, $zzz, $zzz, $date_comptable) = explode(";", $data[$c]);
+
+# Bug CSV ING : "424 au lieu de 424
+#"
+ $code = str_replace("\"", "", $code);
+
+# Bug CSV ING : espace apres la date
+ $date_exec = str_replace(" ", "", $date_exec);
+ $date_valeur = str_replace(" ", "", $date_valeur);
+ $date_exec = str_replace("\"", "", $date_exec);
+ $date_valeur = str_replace("\"", "", $date_valeur);
+ $montant = str_replace("\"", "", $montant);
+ if ((myereg ("([0-9]{3})-([0-9]{7})-([0-9]{2})", $num_compte, $regs)))
+ {
+ $num_compte = $regs[0];
+ }
+
+ // Si LTXXXXX ou LT XXXXX dans le détail
+ if ((myereg ("LT+([0-9]{5})", $detail, $regs)) || (myereg ("LT+[ ]+([0-9]{5})", $detail, $regs)))
+ {
+ $iduser = $regs[1];
+ }
+
+ // Si XXXXXXXXXXXX
+ if (myereg ("[0-9]{12}", $detail, $regs))
+ {
+ if($regs[0] != "000000000000")
+ {
+ $id = substr($regs[0], 2, 5);
+ $longchiffre = substr($regs[0], 0, 10);
+ $check = substr($regs[0], 10, 2);
+ if (($longchiffre % 97) == $check) $iduser = $id;
+ }
+ }
+
+ if($iduser != "" ) $poste_comptable = "400".$iduser;
+ else $poste_comptable = "";
+
+ list($jour,$mois,$annee) = explode("/", $date_valeur);
+ $date_valeur = $annee."-".$mois."-".$jour;
+ list($jour,$mois,$annee) = explode("/", $date_exec);
+ $date_exec = $annee."-".$mois."-".$jour;
+
+ $montant = str_replace(",", ".", $montant);
+ $montant = str_replace("+", "", $montant);
+
+ if($code < 10) $code = "000".$code;
+ if($code >= 10 and $code < 100) $code = "00".$code;
+ if($code >= 100) $code = "0".$code;
+
+ $code = $annee."-".$code;
+
+ $sql = "select * from import_tmp where code='".$code."' and num_compte='".$num_compte."'";
+ $Res=$p_cn->exec_sql($sql);
+ $Num=Database::num_row($Res);
+
+ if($Num > 0)
+ {
+ echo "Opération FORTIS ".$code." déj&eagrave; importée. ";
+ }
+ else
+ {
+ //echo $code." ".$date_exec." ".$date_valeur." ".$montant." ".$devise." ".$compte_ordre." detail ".$num_compte." ".$poste_comptable." ";
+ //$Sql="insert into import_tmp values ('$code','$date_exec','$date_valeur','$montant','$devise','".addslashes($compte_ordre)."','".addslashes($detail)."','$num_compte','$poste_comptable')";
+ $Sql="insert into import_tmp (code,
+ date_exec ,
+ date_valeur,
+ montant,
+ devise,
+ compte_ordre,
+ detail,
+ bq_account ,
+ jrn,
+ status)
+ values ('$code',
+ '$date_exec',
+ '$date_exec',
+ $montant,
+ '$devise',
+ '".addslashes($compte_ordre)."',
+ '".addslashes($detail).$num_compte." ',
+ '$p_bq_account',
+ $p_jrn,
+ 'n')";
+ echo $sql;
+ $Res=$p_cn->exec_sql($Sql);
+ }
+ }
+
+ } // for ($c=0;$c<$num;$c++)
+ $row++;
} // file is read
fclose($handle);
?>
diff --git a/include/keytrade_be.inc.php b/include/keytrade_be.inc.php
index 4b48f15be..34558c71b 100644
--- a/include/keytrade_be.inc.php
+++ b/include/keytrade_be.inc.php
@@ -1,4 +1,4 @@
-set_encoding('latin1');
-while (($data = fgetcsv($handle, 2000,"!")) !== FALSE) {
- $num = count($data);
- for ($c=0; $c < $num; $c++) {
- // skip the first line
- if ( $line < 1 )
- continue;
+while (($data = fgetcsv($handle, 2000,"!")) !== FALSE)
+{
+ $num = count($data);
+ for ($c=0; $c < $num; $c++)
+ {
+ // skip the first line
+ if ( $line < 1 )
+ continue;
//-----------------------------------------------------
// Parsing CSV comes here
//-----------------------------------------------------
- $row=explode(';',$data[$c]);
- if ( sizeof ($row) < 7 )
- continue;
+ $row=explode(';',$data[$c]);
+ if ( sizeof ($row) < 7 )
+ continue;
- // Your own bank account
- $compte_ordre='';
+ // Your own bank account
+ $compte_ordre='';
- // Execution date of the operation
- $date_exec=str_replace('/','-',$row[0]);
- // Operation reference, it must be unique, so we take the datum
- // the line number and a random number
- $r=rand(1,1000);
- $code=$date_exec.'-'.$line.$r;
- // Effective date of the operation
- $date_val=str_replace('/','-',$row[1]);
- // Third party bank account
- $num_compte=$row[2];
- //
- $detail=trim($row[3]);
- //
- $signe=trim($row[4]);
- //
- // remove first the thousand sep.
- $montant=str_replace('.','',$row[5]);
- // replace the coma by a period
- $montant=str_replace(',','.',$montant);
- // remove the sign
- //$montant=str_replace('+','',$montant);
- // use the sign
- if ($signe == '-')
- $montant='-'.$montant;
- // Curency used
- $devise=trim($row[6]);
+ // Execution date of the operation
+ $date_exec=str_replace('/','-',$row[0]);
+ // Operation reference, it must be unique, so we take the datum
+ // the line number and a random number
+ $r=rand(1,1000);
+ $code=$date_exec.'-'.$line.$r;
+ // Effective date of the operation
+ $date_val=str_replace('/','-',$row[1]);
+ // Third party bank account
+ $num_compte=$row[2];
+ //
+ $detail=trim($row[3]);
+ //
+ $signe=trim($row[4]);
+ //
+ // remove first the thousand sep.
+ $montant=str_replace('.','',$row[5]);
+ // replace the coma by a period
+ $montant=str_replace(',','.',$montant);
+ // remove the sign
+ //$montant=str_replace('+','',$montant);
+ // use the sign
+ if ($signe == '-')
+ $montant='-'.$montant;
+ // Curency used
+ $devise=trim($row[6]);
//----------------------------------------------------
// Skip dubbel impossible
//----------------------------------------------------
-echo "Ajout de $detail";
-echo " ";
+ echo "Ajout de $detail";
+ echo " ";
//-----------------------------------------------------
// insert into import_tmp
//-----------------------------------------------------
- $Sql="insert into import_tmp (code,
- date_exec ,
- date_valeur,
- montant,
- devise,
- num_compte,
- detail,
- bq_account ,
- jrn,
- status)
- values ('$code',
- to_date('$date_exec','DD-MM-YYYY'),
- to_date('$date_exec','DD-MM-YYYY'),
- $montant,
- '$devise',
- '".$num_compte."',
- '".addslashes($detail)." ',
- '$p_bq_account',
- $p_jrn,
- 'n')";
- try
- {
- $p_cn->exec_sql($Sql);
- }
+ $Sql="insert into import_tmp (code,
+ date_exec ,
+ date_valeur,
+ montant,
+ devise,
+ num_compte,
+ detail,
+ bq_account ,
+ jrn,
+ status)
+ values ('$code',
+ to_date('$date_exec','DD-MM-YYYY'),
+ to_date('$date_exec','DD-MM-YYYY'),
+ $montant,
+ '$devise',
+ '".$num_compte."',
+ '".addslashes($detail)." ',
+ '$p_bq_account',
+ $p_jrn,
+ 'n')";
+ try
+ {
+ $p_cn->exec_sql($Sql);
+ }
- catch(Exception $e)
- {
- echo(__FILE__.":".__LINE__." Erreur : ".$e->getCode()." msg ".$e->getMessage());
- rollback($p_cn);
- break;
- }
+ catch(Exception $e)
+ {
+ echo(__FILE__.":".__LINE__." Erreur : ".$e->getCode()." msg ".$e->getMessage());
+ rollback($p_cn);
+ break;
+ }
- } // for ($c=0;$c<$num;$c++)
- $line++;
+ } // for ($c=0;$c<$num;$c++)
+ $line++;
} // file is read
diff --git a/include/letter.inc.php b/include/letter.inc.php
index e0d686226..001203b4b 100644
--- a/include/letter.inc.php
+++ b/include/letter.inc.php
@@ -25,29 +25,32 @@
*/
echo JS_INFOBULLE;
$array=array(
- array('?'.dossier::get().'&p_action=let&sa=poste',_('Par poste'),
- _('Lettrage par poste'), 1),
- array('?'.dossier::get().'&p_action=let&sa=qc',_('Par fiche'),
- _('Lettrage par fiche'), 2)
- );
+ array('?'.dossier::get().'&p_action=let&sa=poste',_('Par poste'),
+ _('Lettrage par poste'), 1),
+ array('?'.dossier::get().'&p_action=let&sa=qc',_('Par fiche'),
+ _('Lettrage par fiche'), 2)
+ );
$sa=(isset($_REQUEST['sa']))?$_REQUEST['sa']:0;
-switch($sa){
+switch($sa)
+{
case 'poste':
- $subdef=1;
- break;
+ $subdef=1;
+ break;
case 'qc':
- $subdef=2;
- break;
+ $subdef=2;
+ break;
}
echo '';
-if ($sa == 'poste') {
- require_once('lettering.account.inc.php');
- exit;
+if ($sa == 'poste')
+{
+ require_once('lettering.account.inc.php');
+ exit;
}
-if ($sa=='qc') {
- require_once('lettering.card.inc.php');
- exit;
+if ($sa=='qc')
+{
+ require_once('lettering.card.inc.php');
+ exit;
}
diff --git a/include/lettering.account.inc.php b/include/lettering.account.inc.php
index a4720edf6..434e9ea05 100644
--- a/include/lettering.account.inc.php
+++ b/include/lettering.account.inc.php
@@ -53,8 +53,8 @@ $poste->set_attribute('account','acc');
if (isset($_GET['acc'])) $poste->value=$_GET['acc'];
$poste_span=new ISpan('account_label');
$r= td(_('Lettrage pour le poste comptable ')).
- td($poste->input()).
- td($poste_span->input());
+ td($poste->input()).
+ td($poste_span->input());
echo tr($r);
// limit of the year
$exercice=$User->get_exercice();
@@ -76,14 +76,14 @@ echo tr($r);
// type of lettering : all, lettered, not lettered
$sel=new ISelect('type_let');
$sel->value=array(
- array('value'=>0,'label'=>_('Toutes opérations')),
- array('value'=>1,'label'=>_('Opérations lettrées')),
- array('value'=>2,'label'=>_('Opérations NON lettrées'))
- );
+ array('value'=>0,'label'=>_('Toutes opérations')),
+ array('value'=>1,'label'=>_('Opérations lettrées')),
+ array('value'=>2,'label'=>_('Opérations NON lettrées'))
+ );
if (isset($_GET['type_let'])) $sel->selected=$_GET['type_let'];
$r= td("Filtre ").
- td($sel->input());
+ td($sel->input());
echo tr($r);
echo '
';
@@ -96,17 +96,19 @@ echo ' ';
//--------------------------------------------------------------------------------
// record the data
//--------------------------------------------------------------------------------
-if ( isset($_POST['record'])) {
- $letter=new Lettering_Account($cn);
- $letter->save($_POST);
+if ( isset($_POST['record']))
+{
+ $letter=new Lettering_Account($cn);
+ $letter->save($_POST);
}
//--------------------------------------------------------------------------------
// Show the result
//--------------------------------------------------------------------------------
echo '';
-if ( isDate($_GET['start']) == null || isDate($_GET['end']) == null ) {
- echo alert(_('Date malformée, désolé'));
- exit();
+if ( isDate($_GET['start']) == null || isDate($_GET['end']) == null )
+{
+ echo alert(_('Date malformée, désolé'));
+ exit();
}
$letter=new Lettering_Account($cn);
$letter->set_parameter('account',$_GET['acc']);
@@ -114,11 +116,11 @@ $letter->set_parameter('start',$_GET['start']);
$letter->set_parameter('end',$_GET['end']);
if ( $sel->selected == 0 )
- echo $letter->show_list('all');
+ echo $letter->show_list('all');
if ( $sel->selected == 1 )
- echo $letter->show_list('letter');
+ echo $letter->show_list('letter');
if ( $sel->selected == 2 )
- echo $letter->show_list('unletter');
+ echo $letter->show_list('unletter');
echo '
';
echo '';
diff --git a/include/lettering.card.inc.php b/include/lettering.card.inc.php
index 5b178f67f..883abc0d6 100644
--- a/include/lettering.card.inc.php
+++ b/include/lettering.card.inc.php
@@ -61,8 +61,8 @@ $poste->set_callback('filter_card');
if (isset($_GET['acc'])) $poste->value=strtoupper(trim($_GET['acc']));
$poste_span=new ISpan('account_label');
$r= td(_('Lettrage pour la fiche ')).
- td($poste->input().$poste->search()).
- td($poste_span->input());
+ td($poste->input().$poste->search()).
+ td($poste_span->input());
echo tr($r);
// limit of the year
$exercice=$User->get_exercice();
@@ -84,14 +84,14 @@ echo tr($r);
// type of lettering : all, lettered, not lettered
$sel=new ISelect('type_let');
$sel->value=array(
- array('value'=>0,'label'=>_('Toutes opérations')),
- array('value'=>1,'label'=>_('Opérations lettrées')),
- array('value'=>2,'label'=>_('Opérations NON lettrées'))
- );
+ array('value'=>0,'label'=>_('Toutes opérations')),
+ array('value'=>1,'label'=>_('Opérations lettrées')),
+ array('value'=>2,'label'=>_('Opérations NON lettrées'))
+ );
if (isset($_GET['type_let'])) $sel->selected=$_GET['type_let'];
$r= td("Filtre ").
- td($sel->input());
+ td($sel->input());
echo tr($r);
echo '
';
@@ -104,17 +104,19 @@ echo ' ';
//--------------------------------------------------------------------------------
// record the data
//--------------------------------------------------------------------------------
-if ( isset($_POST['record'])) {
- $letter=new Lettering_Account($cn);
- $letter->save($_POST);
+if ( isset($_POST['record']))
+{
+ $letter=new Lettering_Account($cn);
+ $letter->save($_POST);
}
//--------------------------------------------------------------------------------
// Show the result
//--------------------------------------------------------------------------------
echo '';
-if ( isDate($_GET['start']) == null || isDate($_GET['end']) == null ) {
- echo alert(_('Date malformée, désolé'));
- exit();
+if ( isDate($_GET['start']) == null || isDate($_GET['end']) == null )
+{
+ echo alert(_('Date malformée, désolé'));
+ exit();
}
$letter=new Lettering_Card($cn);
@@ -124,11 +126,11 @@ $letter->set_parameter('start',$_GET['start']);
$letter->set_parameter('end',$_GET['end']);
if ( $sel->selected == 0 )
- echo $letter->show_list('all');
+ echo $letter->show_list('all');
if ( $sel->selected == 1 )
- echo $letter->show_list('letter');
+ echo $letter->show_list('letter');
if ( $sel->selected == 2 )
- echo $letter->show_list('unletter');
+ echo $letter->show_list('unletter');
echo '
';
echo '';
diff --git a/include/lettering.gestion.inc.php b/include/lettering.gestion.inc.php
index 1df638bd0..e06a67db1 100644
--- a/include/lettering.gestion.inc.php
+++ b/include/lettering.gestion.inc.php
@@ -31,15 +31,15 @@ echo tr($r);
// type of lettering : all, lettered, not lettered
$sel=new ISelect('type_let');
$sel->value=array(
- array('value'=>0,'label'=>_('Toutes opérations')),
- array('value'=>1,'label'=>_('Opérations lettrées')),
- array('value'=>2,'label'=>_('Opérations NON lettrées'))
- );
+ array('value'=>0,'label'=>_('Toutes opérations')),
+ array('value'=>1,'label'=>_('Opérations lettrées')),
+ array('value'=>2,'label'=>_('Opérations NON lettrées'))
+ );
if (isset($_GET['type_let'])) $sel->selected=$_GET['type_let'];
else $sel->selected=1;
$r= td("Filtre ").
- td($sel->input());
+ td($sel->input());
echo tr($r);
echo '
';
@@ -52,16 +52,18 @@ echo ' ';
//--------------------------------------------------------------------------------
// record the data
//--------------------------------------------------------------------------------
-if ( isset($_POST['record'])) {
- $letter=new Lettering_Account($cn);
- $letter->save($_POST);
+if ( isset($_POST['record']))
+{
+ $letter=new Lettering_Account($cn);
+ $letter->save($_POST);
}
//--------------------------------------------------------------------------------
// Show the result
//--------------------------------------------------------------------------------
-if ( isDate($_GET['start']) == null || isDate($_GET['end']) == null ) {
- echo alert(_('Date malformée, désolé'));
- exit();
+if ( isDate($_GET['start']) == null || isDate($_GET['end']) == null )
+{
+ echo alert(_('Date malformée, désolé'));
+ exit();
}
echo '';
@@ -73,11 +75,11 @@ $letter->set_parameter('start',$start->value);
$letter->set_parameter('end',$end->value);
if ( $sel->selected == 0 )
- echo $letter->show_list('all');
+ echo $letter->show_list('all');
if ( $sel->selected == 1 )
- echo $letter->show_list('letter');
+ echo $letter->show_list('letter');
if ( $sel->selected == 2 )
- echo $letter->show_list('unletter');
+ echo $letter->show_list('unletter');
echo '
';
echo '';
diff --git a/include/modele.inc.php b/include/modele.inc.php
index 5fe6bea12..233ee1628 100644
--- a/include/modele.inc.php
+++ b/include/modele.inc.php
@@ -1,4 +1,4 @@
-get_value('select count(*) from modeledef where '.
- 'mod_name=$1 and mod_id !=$2',
- array(trim($name),$m)) == 0
- )
- {
+ isset($_POST['m']))
+{
+ if ( isset($_POST['name']) && isset($_POST['desc']))
+ {
+ extract($_POST);
+ $cn=new Database();
+ if ( strlen(trim($name)) !=0
+ && $cn->get_value('select count(*) from modeledef where '.
+ 'mod_name=$1 and mod_id !=$2',
+ array(trim($name),$m)) == 0
+ )
+ {
- $cn->exec_sql("update modeledef set mod_name=$1, ".
- " mod_desc=$2 where mod_id=$3 ",
- array(trim($name),trim($desc),$m));
-
-
- }
- }
- $sa="list";
- }
+ $cn->exec_sql("update modeledef set mod_name=$1, ".
+ " mod_desc=$2 where mod_id=$3 ",
+ array(trim($name),trim($desc),$m));
+
+
+ }
+ }
+ $sa="list";
+}
echo JS_CONFIRM;
$cn=new Database();
@@ -57,322 +59,346 @@ $cn=new Database();
// IF FMOD_NAME is posted then must add a template
-if ( isset ($_POST["FMOD_NAME"]) ) {
- $encoding=$cn->get_value("select encoding from pg_database where ".
- " datname='".domaine.'dossier'.FormatString($_POST["FMOD_DBID"])."'");
+if ( isset ($_POST["FMOD_NAME"]) )
+{
+ $encoding=$cn->get_value("select encoding from pg_database where ".
+ " datname='".domaine.'dossier'.FormatString($_POST["FMOD_DBID"])."'");
- if ( $encoding != 6 ) {
- alert('Désolé vous devez migrer ce modèle en unicode');
- echo '
la base de donnée '.
- domaine.'mod'.$_POST["FMOD_DBID"]." doit être migrée en unicode ";
- echo '
Pour le passer en unicode, faites-en un backup puis restaurez le fichier reçu ';
-
- echo HtmlInput::button_anchor('Retour','admin_repo.php?action=dossier_mgt');
- exit();
- }
-
- $mod_name=FormatString($_POST["FMOD_NAME"]);
- $mod_desc=FormatString($_POST["FMOD_DESC"]);
- if ( $mod_name != null) {
- $Res=$cn->exec_sql("insert into modeledef(mod_name,mod_desc)
- values ('".$mod_name."',".
- "'".$mod_desc."')");
-
- // get the mod_id
- $l_id=$cn->get_current_seq('s_modid');
- if ( $l_id != 0 ) {
- $Sql=sprintf("CREATE DATABASE %sMOD%d encoding='UTF8' TEMPLATE %sDOSSIER%s",domaine,$l_id,domaine,$_POST["FMOD_DBID"]);
- ob_start();
- if ( $cn->exec_sql($Sql)==false) {
- ob_end_clean();
- echo "
Base de donnée ".domaine."dossier".$_POST['FMOD_DBID']." est accèdée, déconnectez-vous en d'abord ";
- $Res=$cn->exec_sql("delete from modeledef where mod_id=".$l_id);
-
- exit;
- }
- }
- }// if $mod_name != null
-
- $cn_mod=new Database($l_id,'mod');
-
- // Clean some tables
-
- $Res=$cn_mod->exec_sql("select distinct jr_pj from jrn where jr_pj is not null ");
- if ( Database::num_row($Res) != 0 )
+ if ( $encoding != 6 )
{
- $a_lob=Database::fetch_all($Res);
- for($i=0;$i
lo_unlink($a_lob[$i]['jr_pj']);
+ alert('Désolé vous devez migrer ce modèle en unicode');
+ echo 'la base de donnée '.
+ domaine.'mod'.$_POST["FMOD_DBID"]." doit être migrée en unicode ";
+ echo ' Pour le passer en unicode, faites-en un backup puis restaurez le fichier reçu ';
+
+ echo HtmlInput::button_anchor('Retour','admin_repo.php?action=dossier_mgt');
+ exit();
}
-
- $Res=$cn_mod->exec_sql("truncate table centralized");
- $Res=$cn_mod->exec_sql("truncate table jrn cascade");
- $Res=$cn_mod->exec_sql("delete from del_jrn");
- $Res=$cn_mod->exec_sql("delete from del_jrnx");
- $Res=$cn_mod->exec_sql("truncate table jrnx cascade ");
- $Res=$cn_mod->exec_sql("delete from del_action");
- $Res=$cn_mod->exec_sql('delete from operation_analytique');
+ $mod_name=FormatString($_POST["FMOD_NAME"]);
+ $mod_desc=FormatString($_POST["FMOD_DESC"]);
+ if ( $mod_name != null)
+ {
+ $Res=$cn->exec_sql("insert into modeledef(mod_name,mod_desc)
+ values ('".$mod_name."',".
+ "'".$mod_desc."')");
- // TODO
+ // get the mod_id
+ $l_id=$cn->get_current_seq('s_modid');
+ if ( $l_id != 0 )
+ {
+ $Sql=sprintf("CREATE DATABASE %sMOD%d encoding='UTF8' TEMPLATE %sDOSSIER%s",domaine,$l_id,domaine,$_POST["FMOD_DBID"]);
+ ob_start();
+ if ( $cn->exec_sql($Sql)==false)
+ {
+ ob_end_clean();
+ echo " Base de donnée ".domaine."dossier".$_POST['FMOD_DBID']." est accèdée, déconnectez-vous en d'abord ";
+ $Res=$cn->exec_sql("delete from modeledef where mod_id=".$l_id);
- $Res=$cn_mod->exec_sql("truncate table import_tmp");
- // Reset the closed periode
- $Res=$cn_mod->exec_sql("update parm_periode set p_closed='f'");
- $Res=$cn_mod->exec_sql('delete from jrn_periode');
- $Res=$cn_mod->exec_sql(' insert into jrn_periode(p_id,jrn_def_id,status) '.
- ' select p_id,jrn_def_id,\'OP\' '.
- ' from '.
- ' parm_periode cross join jrn_def');
+ exit;
+ }
+ }
+ }// if $mod_name != null
- // Reset Sequence
- $a_seq=array('s_jrn','s_jrn_op','s_centralized','s_stock_goods','s_internal');
- foreach ($a_seq as $seq ) {
- $sql=sprintf("select setval('%s',1,false)",$seq);
+ $cn_mod=new Database($l_id,'mod');
+
+ // Clean some tables
+
+ $Res=$cn_mod->exec_sql("select distinct jr_pj from jrn where jr_pj is not null ");
+ if ( Database::num_row($Res) != 0 )
+ {
+ $a_lob=Database::fetch_all($Res);
+ for($i=0;$ilo_unlink($a_lob[$i]['jr_pj']);
+ }
+
+ $Res=$cn_mod->exec_sql("truncate table centralized");
+ $Res=$cn_mod->exec_sql("truncate table jrn cascade");
+ $Res=$cn_mod->exec_sql("delete from del_jrn");
+ $Res=$cn_mod->exec_sql("delete from del_jrnx");
+ $Res=$cn_mod->exec_sql("truncate table jrnx cascade ");
+ $Res=$cn_mod->exec_sql("delete from del_action");
+
+ $Res=$cn_mod->exec_sql('delete from operation_analytique');
+
+ // TODO
+
+ $Res=$cn_mod->exec_sql("truncate table import_tmp");
+ // Reset the closed periode
+ $Res=$cn_mod->exec_sql("update parm_periode set p_closed='f'");
+ $Res=$cn_mod->exec_sql('delete from jrn_periode');
+ $Res=$cn_mod->exec_sql(' insert into jrn_periode(p_id,jrn_def_id,status) '.
+ ' select p_id,jrn_def_id,\'OP\' '.
+ ' from '.
+ ' parm_periode cross join jrn_def');
+
+ // Reset Sequence
+ $a_seq=array('s_jrn','s_jrn_op','s_centralized','s_stock_goods','s_internal');
+ foreach ($a_seq as $seq )
+ {
+ $sql=sprintf("select setval('%s',1,false)",$seq);
+ $Res=$cn_mod->exec_sql($sql);
+ }
+ $sql="select jrn_def_id from jrn_def ";
$Res=$cn_mod->exec_sql($sql);
- }
- $sql="select jrn_def_id from jrn_def ";
- $Res=$cn_mod->exec_sql($sql);
- $Max=Database::num_row($Res);
- for ($seq=0;$seq<$Max;$seq++) {
- $row=Database::fetch_array($Res,$seq);
- /* if seq doesn't exist create it */
- if ( $cn_mod->exist_sequence('s_jrn_'.$row['jrn_def_id']) == false ) {
- $cn_mod->create_sequence('s_jrn_'.$row['jrn_def_id']);
- }
-
-
- $sql=sprintf ("select setval('s_jrn_%d',1,false)",$row['jrn_def_id']);
- $cn_mod->exec_sql($sql);
-
- $sql=sprintf ("select setval('s_jrn_pj%d',1,false)",$row['jrn_def_id']);
- $cn_mod->exec_sql($sql);
- $sql=sprintf ("select setval('jnt_letter_jl_id_seq',1,false)");
- $cn_mod->exec_sql($sql);
-
- }
- //---
- // Cleaning Action
- //--
- if ( isset($_POST['DOC'] ))
+ $Max=Database::num_row($Res);
+ for ($seq=0;$seq<$Max;$seq++)
{
- $Res=$cn_mod->exec_sql("delete from action_gestion");
- $Res=$cn_mod->exec_sql("delete from document");
+ $row=Database::fetch_array($Res,$seq);
+ /* if seq doesn't exist create it */
+ if ( $cn_mod->exist_sequence('s_jrn_'.$row['jrn_def_id']) == false )
+ {
+ $cn_mod->create_sequence('s_jrn_'.$row['jrn_def_id']);
+ }
+
+
+ $sql=sprintf ("select setval('s_jrn_%d',1,false)",$row['jrn_def_id']);
+ $cn_mod->exec_sql($sql);
+
+ $sql=sprintf ("select setval('s_jrn_pj%d',1,false)",$row['jrn_def_id']);
+ $cn_mod->exec_sql($sql);
+ $sql=sprintf ("select setval('jnt_letter_jl_id_seq',1,false)");
+ $cn_mod->exec_sql($sql);
- // Remove lob file
- $Res=$cn_mod->exec_sql("select distinct loid from pg_largeobject except select md_lob from document_modele");
- if ( Database::num_row($Res) != 0 )
- {
- $a_lob=Database::fetch_all($Res);
- //var_dump($a_lob);
- foreach ($a_lob as $lob) {
- $cn_mod->lo_unlink($lob['loid']);
- }
- }
}
- if ( isset($_POST['CARD']))
+ //---
+ // Cleaning Action
+ //--
+ if ( isset($_POST['DOC'] ))
{
- $Res=$cn_mod->exec_sql("delete from attr_value");
- $Res=$cn_mod->exec_sql("delete from jnt_fic_att_value");
- $Res=$cn_mod->exec_sql("delete from fiche");
- $Res=$cn_mod->exec_sql("delete from action_gestion");
- $Res=$cn_mod->exec_sql("delete from document");
- $Res=$cn_mod->exec_sql("delete from document_modele");
- $Res=$cn_mod->exec_sql("delete from op_predef");
+ $Res=$cn_mod->exec_sql("delete from action_gestion");
+ $Res=$cn_mod->exec_sql("delete from document");
- // Remove lob file
- $Res=$cn_mod->exec_sql("select distinct loid from pg_largeobject");
- if ( Database::num_row($Res) != 0 )
- {
- $a_lob=Database::fetch_all($Res);
- foreach ($a_lob as $lob)
- $cn_mod->lo_unlink($lob['loid']);
- }
-
-
+ // Remove lob file
+ $Res=$cn_mod->exec_sql("select distinct loid from pg_largeobject except select md_lob from document_modele");
+ if ( Database::num_row($Res) != 0 )
+ {
+ $a_lob=Database::fetch_all($Res);
+ //var_dump($a_lob);
+ foreach ($a_lob as $lob)
+ {
+ $cn_mod->lo_unlink($lob['loid']);
+ }
+ }
}
- if ( isset($_POST['CANAL'])) {
- $Res=$cn_mod->exec_sql('delete from poste_analytique');
- $Res=$cn_mod->exec_sql('delete from plan_analytique');
- }
-
- }
+ if ( isset($_POST['CARD']))
+ {
+ $Res=$cn_mod->exec_sql("delete from attr_value");
+ $Res=$cn_mod->exec_sql("delete from jnt_fic_att_value");
+ $Res=$cn_mod->exec_sql("delete from fiche");
+ $Res=$cn_mod->exec_sql("delete from action_gestion");
+ $Res=$cn_mod->exec_sql("delete from document");
+ $Res=$cn_mod->exec_sql("delete from document_modele");
+ $Res=$cn_mod->exec_sql("delete from op_predef");
+
+ // Remove lob file
+ $Res=$cn_mod->exec_sql("select distinct loid from pg_largeobject");
+ if ( Database::num_row($Res) != 0 )
+ {
+ $a_lob=Database::fetch_all($Res);
+ foreach ($a_lob as $lob)
+ $cn_mod->lo_unlink($lob['loid']);
+ }
+
+
+ }
+ if ( isset($_POST['CANAL']))
+ {
+ $Res=$cn_mod->exec_sql('delete from poste_analytique');
+ $Res=$cn_mod->exec_sql('delete from plan_analytique');
+ }
+
+}
// Show all available templates
-$Res=$cn->exec_sql("select mod_id,mod_name,mod_desc from
- modeledef order by mod_name");
+$Res=$cn->exec_sql("select mod_id,mod_name,mod_desc from
+ modeledef order by mod_name");
$count=Database::num_row($Res);
echo '';
echo "
Modèles ";
-if ( $sa=='list') {
- if ( $count == 0 ) {
- echo "No template available";
- } else {
-
+if ( $sa=='list')
+{
+ if ( $count == 0 )
+ {
+ echo "No template available";
+ }
+ else
+ {
- echo HtmlInput::button_anchor('Rafraîchir','admin_repo.php?action=modele_mgt');
- echo HtmlInput::button_anchor('Ajouter','admin_repo.php?action=modele_mgt&sa=add');
- echo '
';
- echo "Nom ".
- "Description ".
- " ".
- " ";
-
- for ($i=0;$i<$count;$i++) {
- $mod=Database::fetch_array($Res,$i);
- printf(''.
- '%d %s '.
- ' %s '.
- ' '.
- HtmlInput::button_anchor('Effacer','?action=modele_mgt&sa=del&m='.$mod['mod_id']).' '.
- ''.
- ''.HtmlInput::button_anchor('Modifie','?action=modele_mgt&sa=mod&m='.$mod['mod_id']).' '.
- ''.
- ''.HtmlInput::button_anchor('Backup','backup.php?action=backup&sa=b&t=m&d='
- .$mod['mod_id']).' '.
- ' ',
- $mod['mod_id'],
- $mod['mod_name'],
- $mod['mod_desc']);
-
- }// for
- echo "
";
- }// if count = 0
-echo "Si vous voulez récupérer toutes les adaptations d'un dossier ".
-" dans un autre dossier, vous pouvez en faire un modèle.".
-" Seules les fiches, la structure des journaux, les périodes,... seront reprises ".
-"et aucune donnée du dossier sur lequel le dossier est basé.";
- }
+ echo HtmlInput::button_anchor('Rafraîchir','admin_repo.php?action=modele_mgt');
+ echo HtmlInput::button_anchor('Ajouter','admin_repo.php?action=modele_mgt&sa=add');
+
+ echo '
';
+ echo "Nom ".
+ "Description ".
+ " ".
+ " ";
+
+ for ($i=0;$i<$count;$i++)
+ {
+ $mod=Database::fetch_array($Res,$i);
+ printf(''.
+ '%d %s '.
+ ' %s '.
+ ' '.
+ HtmlInput::button_anchor('Effacer','?action=modele_mgt&sa=del&m='.$mod['mod_id']).' '.
+ ''.
+ ''.HtmlInput::button_anchor('Modifie','?action=modele_mgt&sa=mod&m='.$mod['mod_id']).' '.
+ ''.
+ ''.HtmlInput::button_anchor('Backup','backup.php?action=backup&sa=b&t=m&d='
+ .$mod['mod_id']).' '.
+ ' ',
+ $mod['mod_id'],
+ $mod['mod_name'],
+ $mod['mod_desc']);
+
+ }// for
+ echo "
";
+ }// if count = 0
+ echo "Si vous voulez récupérer toutes les adaptations d'un dossier ".
+ " dans un autre dossier, vous pouvez en faire un modèle.".
+ " Seules les fiches, la structure des journaux, les périodes,... seront reprises ".
+ "et aucune donnée du dossier sur lequel le dossier est basé.";
+}
//---------------------------------------------------------------------------
// Add a template
//---------------------------------------------------------------------------
-if ( $sa == 'add') {
+if ( $sa == 'add')
+{
// Show All available folder
-$Res=$cn->exec_sql("select dos_id, dos_name,dos_description from ac_dossier
- order by dos_name");
-$count=Database::num_row($Res);
-$available="";
-if ( $count != 0 ) {
- $available='
';
- for ($i=0;$i<$count;$i++) {
- $db=Database::fetch_array($Res,$i);
- $available.=''.$db['dos_name'].':'.$db['dos_description'];
- }//for i
- $available.=' ';
- }//if count !=0
-?>
-
-
-
-
-
-
-';
- $name=$cn->get_value(
- "select mod_name from modeledef where ".
- " mod_id=$1",
- array($_GET['m']));
-
- $desc=$cn->get_value(
- "select mod_desc from modeledef where ".
- " mod_id=$1",
- array($_GET['m']));
- $wText=new IText();
- echo 'Nom : '.$wText->input('name',$name);
- $wDesc=new ITextArea();
- $wDesc->heigh=5;
- echo '
Description :
';
- echo $wDesc->input('desc',$desc);
- echo HtmlInput::hidden('m',$_GET['m']);
- echo HtmlInput::hidden('action','modele_mgt');
- echo '
';
- echo HtmlInput::button_anchor('Retour','?action=modele_mgt');
- echo HtmlInput::submit('upd','Modifie');
- echo '';
- }
-
-//---------------------------------------------------------------------------
-// action = del
-//---------------------------------------------------------------------------
-if ( $sa == 'del' ) {
- $cn=new Database();
- $name=$cn->get_value('select mod_name from modeledef where mod_id=$1',array($_REQUEST['m']));
- echo '
';
- echo HtmlInput::hidden('d',$_REQUEST['m']);
- echo HtmlInput::hidden('sa','remove');
- echo 'Etes vous sure et certain de vouloir effacer '.$name.' ??? ';
- $confirm=new ICheckBox();
- $confirm->name="p_confirm";
- echo 'Cochez la case si vous êtes sûr de vouloir effacer ce modèle';
- echo $confirm->input();
- echo HtmlInput::submit('remove','Effacer');
- echo HtmlInput::button_anchor('Retour','?action=modele_mgt');
- echo ' ';
- }
-//---------------------------------------------------------------------------
-// action = del
-//---------------------------------------------------------------------------
-if ( $sa == 'remove' ) {
- if ( ! isset ($_REQUEST['p_confirm'])) {
- echo('Désolé, vous n\'avez pas coché la case');
- echo HtmlInput::button_anchor('Retour','?action=modele_mgt');
- exit();
- }
-
- $cn=new Database();
- $msg="dossier";
- $name=$cn->get_value("select mod_name from modeledef where mod_id=$1",array($_REQUEST['m']));
- if ( strlen(trim($name)) == 0 )
- {
- echo "
$msg inexistant ";
- exit();
- }
- $sql="drop database ".domaine."mod".FormatString($_REQUEST['m']);
- ob_start();
- if ( $cn->exec_sql($sql)==false) {
- ob_end_clean();
-
- echo "
- Base de donnée ".domaine."mod".$_REQUEST['m']." est accèdée, déconnectez-vous d'abord ";
- exit;
- }
- ob_flush();
- $sql="delete from modeledef where mod_id=$1";
- $cn->exec_sql($sql,array($_REQUEST['m']));
- print '
';
- print "Voilà le modèle $name est effacé ";
- echo HtmlInput::button_anchor('Retour','?action=modele_mgt');
- }
- echo '
';
+ '
+
+
+
+
+
+ ';
+ $name=$cn->get_value(
+ "select mod_name from modeledef where ".
+ " mod_id=$1",
+ array($_GET['m']));
+
+ $desc=$cn->get_value(
+ "select mod_desc from modeledef where ".
+ " mod_id=$1",
+ array($_GET['m']));
+ $wText=new IText();
+ echo 'Nom : '.$wText->input('name',$name);
+ $wDesc=new ITextArea();
+ $wDesc->heigh=5;
+ echo ' Description : ';
+ echo $wDesc->input('desc',$desc);
+ echo HtmlInput::hidden('m',$_GET['m']);
+ echo HtmlInput::hidden('action','modele_mgt');
+ echo ' ';
+ echo HtmlInput::button_anchor('Retour','?action=modele_mgt');
+ echo HtmlInput::submit('upd','Modifie');
+ echo '';
+ }
+
+ //---------------------------------------------------------------------------
+ // action = del
+ //---------------------------------------------------------------------------
+ if ( $sa == 'del' )
+ {
+ $cn=new Database();
+ $name=$cn->get_value('select mod_name from modeledef where mod_id=$1',array($_REQUEST['m']));
+ echo '';
+ echo HtmlInput::hidden('d',$_REQUEST['m']);
+ echo HtmlInput::hidden('sa','remove');
+ echo 'Etes vous sure et certain de vouloir effacer '.$name.' ??? ';
+ $confirm=new ICheckBox();
+ $confirm->name="p_confirm";
+ echo 'Cochez la case si vous êtes sûr de vouloir effacer ce modèle';
+ echo $confirm->input();
+ echo HtmlInput::submit('remove','Effacer');
+ echo HtmlInput::button_anchor('Retour','?action=modele_mgt');
+ echo ' ';
+ }
+ //---------------------------------------------------------------------------
+ // action = del
+ //---------------------------------------------------------------------------
+ if ( $sa == 'remove' )
+ {
+ if ( ! isset ($_REQUEST['p_confirm']))
+ {
+ echo('Désolé, vous n\'avez pas coché la case');
+ echo HtmlInput::button_anchor('Retour','?action=modele_mgt');
+ exit();
+ }
+
+ $cn=new Database();
+ $msg="dossier";
+ $name=$cn->get_value("select mod_name from modeledef where mod_id=$1",array($_REQUEST['m']));
+ if ( strlen(trim($name)) == 0 )
+ {
+ echo " $msg inexistant ";
+ exit();
+ }
+ $sql="drop database ".domaine."mod".FormatString($_REQUEST['m']);
+ ob_start();
+ if ( $cn->exec_sql($sql)==false)
+ {
+ ob_end_clean();
+
+ echo "
+ Base de donnée ".domaine."mod".$_REQUEST['m']." est accèdée, déconnectez-vous d'abord ";
+ exit;
+ }
+ ob_flush();
+ $sql="delete from modeledef where mod_id=$1";
+ $cn->exec_sql($sql,array($_REQUEST['m']));
+ print '';
+ print "Voilà le modèle $name est effacé ";
+ echo HtmlInput::button_anchor('Retour','?action=modele_mgt');
+ }
+ echo ' ';
?>
diff --git a/include/opening.inc.php b/include/opening.inc.php
index 93799c27b..e97d584df 100644
--- a/include/opening.inc.php
+++ b/include/opening.inc.php
@@ -31,145 +31,156 @@ $User->Check();
$User->can_request(PAREO,1);
require_once("class_iselect.php");
require_once('class_acc_ledger.php');
-/* --------------------------------------------------
+/* --------------------------------------------------
* step 1 if nothing is asked we show the available folders
-*/
-if ($sa == '') {
- echo '';
- echo '
Etape 1 ';
+*/
+if ($sa == '')
+{
+ echo '';
+ echo '
Etape 1 ';
- echo 'Choississez le dossier où sont les soldes à importer';
- $avail=GetAvailableFolder($User->id,$User->Admin());
+ echo 'Choississez le dossier où sont les soldes à importer';
+ $avail=GetAvailableFolder($User->id,$User->Admin());
- if ( empty( $avail) ) { echo '*** Aucun dossier ***';exit();}
- echo '';
- echo HtmlInput::hidden('p_action','ouv');
- echo HtmlInput::hidden('sa','step2');
- echo dossier::hidden();
- $wAvail=new ISelect();
- /* compute select list */
- $array=array();
- $i=0;
- foreach ($avail as $r) {
- $array[$i]['value']=$r['dos_id'];
- $array[$i]['label']=$r['dos_name'];
- $i++;
- }
+ if ( empty( $avail) )
+ {
+ echo '*** Aucun dossier ***';
+ exit();
+ }
+ echo ' ';
+ echo HtmlInput::hidden('p_action','ouv');
+ echo HtmlInput::hidden('sa','step2');
+ echo dossier::hidden();
+ $wAvail=new ISelect();
+ /* compute select list */
+ $array=array();
+ $i=0;
+ foreach ($avail as $r)
+ {
+ $array[$i]['value']=$r['dos_id'];
+ $array[$i]['label']=$r['dos_name'];
+ $i++;
+ }
- $wAvail->value=$array;
- echo 'Choix du dossier :'.$wAvail->input('f');
- echo HtmlInput::submit('ok','Continuer');
+ $wAvail->value=$array;
+ echo 'Choix du dossier :'.$wAvail->input('f');
+ echo HtmlInput::submit('ok','Continuer');
- echo ' ';
- echo ' ';
- echo '';
- exit();
+ echo '';
+ echo '';
+ echo '
';
+ exit();
}
/* --------------------------------------------------
* Step 2 choose now the exercice of this folder
*/
$back='user_advanced.php?p_action=ouv&'.dossier::get();
-if ( $sa=='step2') {
- echo ''.
+if ( $sa=='step2')
+{
+ echo '
'.
'
Etape 2 '.
''.dossier::name($_REQUEST['f']).' '.
''.
' Choississez l\'exercice du dossier ';
- echo dossier::hidden();
- echo HtmlInput::hidden('p_action','ouv');
- echo HtmlInput::hidden('sa','step3');
- echo HtmlInput::hidden('f',$_REQUEST['f']);
- $cn=new Database($_REQUEST['f']);
- $periode=$cn->make_array("select distinct p_exercice,p_exercice from parm_periode order by p_exercice");
- $w=new ISelect();
- $w->table=0;
- $w->label='Periode';
- $w->readonly=false;
- $w->value=$periode;
- $w->name="p_periode";
- echo 'Période : '.$w->input();
- echo HtmlInput::submit('ok','Continuer');
- echo dossier::hidden();
- echo " ";
- echo HtmlInput::button_anchor('Retour',$back);
- exit(0);
+ echo dossier::hidden();
+ echo HtmlInput::hidden('p_action','ouv');
+ echo HtmlInput::hidden('sa','step3');
+ echo HtmlInput::hidden('f',$_REQUEST['f']);
+ $cn=new Database($_REQUEST['f']);
+ $periode=$cn->make_array("select distinct p_exercice,p_exercice from parm_periode order by p_exercice");
+ $w=new ISelect();
+ $w->table=0;
+ $w->label='Periode';
+ $w->readonly=false;
+ $w->value=$periode;
+ $w->name="p_periode";
+ echo 'Période : '.$w->input();
+ echo HtmlInput::submit('ok','Continuer');
+ echo dossier::hidden();
+ echo "";
+ echo HtmlInput::button_anchor('Retour',$back);
+ exit(0);
}
/* --------------------------------------------------
* select the ledger where we will import the data
*/
-if ( $sa == 'step3') {
- echo ''.
+if ( $sa == 'step3')
+{
+ echo '
'.
'
Etape 3 '.
''.dossier::name($_REQUEST['f']).' '.
''.
' Choississez le journal qui contiendra l\'opération d\'ouverture ';
- echo dossier::hidden();
- echo HtmlInput::hidden('p_action','ouv');
- echo HtmlInput::hidden('sa','step4');
- echo HtmlInput::hidden('f',$_REQUEST['f']);
- echo HtmlInput::hidden('p_periode',$_REQUEST['p_periode']);
- $wLedger=new ISelect();
- $User=new User(new Database(dossier::id()));
- $avail=$User->get_ledger('ODS');
- /* compute select list */
- $array=array();
- $i=0;
- foreach ($avail as $r) {
- $array[$i]['value']=$r['jrn_def_id'];
- $array[$i]['label']=$r['jrn_def_name'];
- $i++;
- }
- $wLedger->value=$array;
- echo $wLedger->input('p_jrn');
- echo HtmlInput::submit('ok','Continuer');
- echo dossier::hidden();
- echo " ";
- echo HtmlInput::button_anchor('Retour',$back);
- exit(0);
+ echo dossier::hidden();
+ echo HtmlInput::hidden('p_action','ouv');
+ echo HtmlInput::hidden('sa','step4');
+ echo HtmlInput::hidden('f',$_REQUEST['f']);
+ echo HtmlInput::hidden('p_periode',$_REQUEST['p_periode']);
+ $wLedger=new ISelect();
+ $User=new User(new Database(dossier::id()));
+ $avail=$User->get_ledger('ODS');
+ /* compute select list */
+ $array=array();
+ $i=0;
+ foreach ($avail as $r)
+ {
+ $array[$i]['value']=$r['jrn_def_id'];
+ $array[$i]['label']=$r['jrn_def_name'];
+ $i++;
+ }
+ $wLedger->value=$array;
+ echo $wLedger->input('p_jrn');
+ echo HtmlInput::submit('ok','Continuer');
+ echo dossier::hidden();
+ echo "";
+ echo HtmlInput::button_anchor('Retour',$back);
+ exit(0);
}
/* --------------------------------------------------
* Step 4 we import data from the selected folder and year and
* transform it into a misc operation
*/
-if ( $sa=='step4') {
- echo '';
- echo '
Dernière étape ';
- $cn_target=new Database($_REQUEST['f']);
- $saldo=new Acc_Ledger($cn_target,0);
- $array=$saldo->get_saldo_exercice($_REQUEST['p_periode']);
- /* we need to transform the array into a Acc_Ledger array */
- $result=array();
- $result['desc']='Ecriture d\'ouverture';
- $result['nb_item']=sizeof($array);
- $result['p_jrn']=$_REQUEST['p_jrn'];
- $idx=0;
+if ( $sa=='step4')
+{
+ echo '';
+ echo '
Dernière étape ';
+ $cn_target=new Database($_REQUEST['f']);
+ $saldo=new Acc_Ledger($cn_target,0);
+ $array=$saldo->get_saldo_exercice($_REQUEST['p_periode']);
+ /* we need to transform the array into a Acc_Ledger array */
+ $result=array();
+ $result['desc']='Ecriture d\'ouverture';
+ $result['nb_item']=sizeof($array);
+ $result['p_jrn']=$_REQUEST['p_jrn'];
+ $idx=0;
- foreach ($array as $row ) {
- $qcode='qc_'.$idx;
- $poste='poste'.$idx;
- $amount='amount'.$idx;
- $ck='ck'.$idx;
- $result[$qcode] = $row['j_qcode'];
- if ( trim($row['j_qcode'])=='')
- $result[$poste] = $row['j_poste'];
- $result[$amount] = abs($row['solde']);
- if ( $row['solde'] > 0 ) $result[$ck]='on';
- $idx++;
- }
- $cn=new Database(dossier::id());
- $User=new User($cn);
- $jrn=new Acc_Ledger($cn,$_REQUEST['p_jrn']);
- echo '';
- echo HtmlInput::hidden('p_action','quick_writing');
- echo dossier::hidden();
- echo HtmlInput::hidden('p_jrn',$_REQUEST['p_jrn']);
- echo $jrn->show_form($result,0);
- echo ' ';
- echo 'Ne corrigez pas encore, cliquez continuer pour passer à l\'étape suivante ';
- echo HtmlInput::submit('correct_it','Continuer');
- echo ' ';
- echo HtmlInput::button_anchor('Retour',$back);
+ foreach ($array as $row )
+ {
+ $qcode='qc_'.$idx;
+ $poste='poste'.$idx;
+ $amount='amount'.$idx;
+ $ck='ck'.$idx;
+ $result[$qcode] = $row['j_qcode'];
+ if ( trim($row['j_qcode'])=='')
+ $result[$poste] = $row['j_poste'];
+ $result[$amount] = abs($row['solde']);
+ if ( $row['solde'] > 0 ) $result[$ck]='on';
+ $idx++;
+ }
+ $cn=new Database(dossier::id());
+ $User=new User($cn);
+ $jrn=new Acc_Ledger($cn,$_REQUEST['p_jrn']);
+ echo '';
+ echo HtmlInput::hidden('p_action','quick_writing');
+ echo dossier::hidden();
+ echo HtmlInput::hidden('p_jrn',$_REQUEST['p_jrn']);
+ echo $jrn->show_form($result,0);
+ echo ' ';
+ echo 'Ne corrigez pas encore, cliquez continuer pour passer à l\'étape suivante ';
+ echo HtmlInput::submit('correct_it','Continuer');
+ echo ' ';
+ echo HtmlInput::button_anchor('Retour',$back);
- echo ' ';
+ echo ' ';
}
diff --git a/include/param_jrn_add.inc.php b/include/param_jrn_add.inc.php
index 7ce774064..66a3d35d9 100644
--- a/include/param_jrn_add.inc.php
+++ b/include/param_jrn_add.inc.php
@@ -51,77 +51,89 @@ include_once ("user_menu.php");
$User->can_request(PARJRN);
-if ( isset ($_POST["add"]) ) {
- if ( !isset($_POST["p_jrn_name"]) || ! isset($_POST["p_jrn_type"] )) {
- echo ''._('Un paramètre manque').' ';
- }
- else {
- /* if name already use we stop */
- if ( $cn->count_sql("select * from jrn_def where upper(jrn_def_name)=upper($1)",array($_POST['p_jrn_name'])) >0 ) {
-
- alert (_('Un journal de ce nom existe déjà'));
- } else {
-
- if (strlen(trim($_POST['p_jrn_deb_max_line'])) == 0 ||
- (string) (int)$_POST['p_jrn_deb_max_line'] != (string)$_POST['p_jrn_deb_max_line'] )
- $l_deb_max_line=1;
- else
- $l_deb_max_line=$_POST['p_jrn_deb_max_line'];
-
-
- $p_jrn_name=$_POST["p_jrn_name"];
- $p_jrn_class_deb=FormatString($_POST["p_jrn_class_deb"]);
- if (strlen(trim($p_jrn_name))==0) return;
- // compute the jrn_def.jrn_def_code
- $p_code=sprintf("%s-%02d",trim($_POST['p_jrn_type']),Acc_Ledger::next_number($cn,$_POST['p_jrn_type']));
- $p_jrn_fiche_deb="";
- $p_jrn_fiche_cred="";
-
- if ( isset ($_POST["FICHEDEB"])) {
- $p_jrn_fiche_deb=join(",",$_POST["FICHEDEB"]);
- }
- if ( isset ($_POST["FICHECRED"])) {
- $p_jrn_fiche_cred=join(",",$_POST["FICHECRED"]);
- }
- $l_cred_max_line=$l_deb_max_line;
- $cn->start();
- $bank=null;
- if (isset($_POST['bank'])) {
- $a=new Fiche($cn);
- $a->get_by_qcode(trim(strtoupper($_POST['bank'])),false);
- $bank=$a->id;
- if ($bank==0) $bank=null;
- }
- $nop=0;
- if (isset($_POST['numb_operation'])) {
- $nop=1;
- }
-
- if ($_POST['p_jrn_type']=='FIN' && $bank==null)
- {
- alert("Vous devez donner un compte en banque");
- } else {
-
- $Sql="insert into jrn_def(jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_deb_max_line,jrn_cred_max_line,
- jrn_def_type,jrn_def_fiche_deb,jrn_def_fiche_cred,jrn_def_code,jrn_def_pj_pref,jrn_def_bank,jrn_def_num_op)
- values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)";
- $sql_array=array(
- $p_jrn_name,$p_jrn_class_deb,$p_jrn_class_deb,
- $l_deb_max_line,$l_cred_max_line,$_POST['p_jrn_type'],
- $p_jrn_fiche_deb,$p_jrn_fiche_cred,
- $p_code,$_POST['jrn_def_pj_pref'],
- $bank,$nop);
- $Res=$cn->exec_sql($Sql,$sql_array);
- $ledger_id=$cn->get_current_seq('s_jrn_def');
- $Res=$cn->create_sequence('s_jrn_pj'.$ledger_id);
- $cn->commit();
- }
+if ( isset ($_POST["add"]) )
+{
+ if ( !isset($_POST["p_jrn_name"]) || ! isset($_POST["p_jrn_type"] ))
+ {
+ echo ''._('Un paramètre manque').' ';
}
- }
- echo '';
- exit();
+ else
+ {
+ /* if name already use we stop */
+ if ( $cn->count_sql("select * from jrn_def where upper(jrn_def_name)=upper($1)",array($_POST['p_jrn_name'])) >0 )
+ {
+
+ alert (_('Un journal de ce nom existe déjà'));
+ }
+ else
+ {
+
+ if (strlen(trim($_POST['p_jrn_deb_max_line'])) == 0 ||
+ (string) (int)$_POST['p_jrn_deb_max_line'] != (string)$_POST['p_jrn_deb_max_line'] )
+ $l_deb_max_line=1;
+ else
+ $l_deb_max_line=$_POST['p_jrn_deb_max_line'];
+
+
+ $p_jrn_name=$_POST["p_jrn_name"];
+ $p_jrn_class_deb=FormatString($_POST["p_jrn_class_deb"]);
+ if (strlen(trim($p_jrn_name))==0) return;
+ // compute the jrn_def.jrn_def_code
+ $p_code=sprintf("%s-%02d",trim($_POST['p_jrn_type']),Acc_Ledger::next_number($cn,$_POST['p_jrn_type']));
+ $p_jrn_fiche_deb="";
+ $p_jrn_fiche_cred="";
+
+ if ( isset ($_POST["FICHEDEB"]))
+ {
+ $p_jrn_fiche_deb=join(",",$_POST["FICHEDEB"]);
+ }
+ if ( isset ($_POST["FICHECRED"]))
+ {
+ $p_jrn_fiche_cred=join(",",$_POST["FICHECRED"]);
+ }
+ $l_cred_max_line=$l_deb_max_line;
+ $cn->start();
+ $bank=null;
+ if (isset($_POST['bank']))
+ {
+ $a=new Fiche($cn);
+ $a->get_by_qcode(trim(strtoupper($_POST['bank'])),false);
+ $bank=$a->id;
+ if ($bank==0) $bank=null;
+ }
+ $nop=0;
+ if (isset($_POST['numb_operation']))
+ {
+ $nop=1;
+ }
+
+ if ($_POST['p_jrn_type']=='FIN' && $bank==null)
+ {
+ alert("Vous devez donner un compte en banque");
+ }
+ else
+ {
+
+ $Sql="insert into jrn_def(jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_deb_max_line,jrn_cred_max_line,
+ jrn_def_type,jrn_def_fiche_deb,jrn_def_fiche_cred,jrn_def_code,jrn_def_pj_pref,jrn_def_bank,jrn_def_num_op)
+ values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)";
+ $sql_array=array(
+ $p_jrn_name,$p_jrn_class_deb,$p_jrn_class_deb,
+ $l_deb_max_line,$l_cred_max_line,$_POST['p_jrn_type'],
+ $p_jrn_fiche_deb,$p_jrn_fiche_cred,
+ $p_code,$_POST['jrn_def_pj_pref'],
+ $bank,$nop);
+ $Res=$cn->exec_sql($Sql,$sql_array);
+ $ledger_id=$cn->get_current_seq('s_jrn_def');
+ $Res=$cn->create_sequence('s_jrn_pj'.$ledger_id);
+ $cn->commit();
+ }
+ }
+ }
+ echo '';
+ exit();
}
echo '';
echo '';
/* Analyse ce qui est demandé */
/* Effacement d'une ligne */
-if (isset ($_GET['action'])) {
+if (isset ($_GET['action']))
+{
//-----------------------------------------------------
// Action == remove a line
- if ( $_GET['action']=="del" ) {
- if ( isset ($_GET['l']) ) {
- /* Ligne a enfant*/
- $R=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val_parent=$1",array($_GET['l']));
- if ( Database::num_row($R) != 0 ) {
- alert("Ne peut pas effacer le poste: d'autres postes en dépendent");
- } else {
- /* Vérifier que le poste n'est pas utilisé qq part dans les journaux */
- $Res=$cn->exec_sql("select * from jrnx where j_poste=$1",array($_GET['l']));
- if ( Database::num_row($Res) != 0 ) {
- alert("Ne peut pas effacer le poste: il est utilisé dans les journaux");
- }
- else {
- $Del=$cn->exec_sql("delete from tmp_pcmn where pcm_val=$1",array($_GET['l']));
- } // if Database::num_row
- } // if Database::num_row
- } // isset ($l)
- } //$action == del
+ if ( $_GET['action']=="del" )
+ {
+ if ( isset ($_GET['l']) )
+ {
+ /* Ligne a enfant*/
+ $R=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val_parent=$1",array($_GET['l']));
+ if ( Database::num_row($R) != 0 )
+ {
+ alert("Ne peut pas effacer le poste: d'autres postes en dépendent");
+ }
+ else
+ {
+ /* Vérifier que le poste n'est pas utilisé qq part dans les journaux */
+ $Res=$cn->exec_sql("select * from jrnx where j_poste=$1",array($_GET['l']));
+ if ( Database::num_row($Res) != 0 )
+ {
+ alert("Ne peut pas effacer le poste: il est utilisé dans les journaux");
+ }
+ else
+ {
+ $Del=$cn->exec_sql("delete from tmp_pcmn where pcm_val=$1",array($_GET['l']));
+ } // if Database::num_row
+ } // if Database::num_row
+ } // isset ($l)
+ } //$action == del
} // isset action
//----------------------------------------------------------------------
// Modification
//----------------------------------------------------------------------
-if ( isset ($_POST['update'])) {
+if ( isset ($_POST['update']))
+{
$p_val=trim($_POST["p_valu"]);
$p_lib=trim($_POST["p_libu"]);
$p_parent=trim($_POST["p_parentu"]);
@@ -128,79 +139,108 @@ if ( isset ($_POST['update'])) {
$acc->set_parameter('value',$p_val);
$acc->set_parameter('parent',$p_parent);
$acc->set_parameter('type',$p_type);
- // Check if the data are correct
- try {
- $acc->check() ;
- }catch (Exception $e) {
- $message="Valeurs invalides, pas de changement \n ".
- $e->getMessage();
- echo '';
+ // Check if the data are correct
+ try
+ {
+ $acc->check() ;
}
- if ( strlen ($p_val) != 0 && strlen ($p_lib) != 0 && strlen($old_line)!=0 ) {
- if (strlen ($p_val) == 1 ) {
- $p_parent=0;
- } else {
- if ( strlen($p_parent)==0 ) {
- $p_parent=substr($p_val,0,strlen($p_val)-1);
- }
- }
- /* Parent existe */
- $Ret=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val=$1",array($p_parent));
- if ( ($p_parent != 0 && Database::num_row($Ret) == 0) || $p_parent==$old_line ) {
- echo '';
- } else {
- try {
- $acc->update($old_line);
- } catch(Exception $e) {
- alert($e->getMessage());
- }
- }
- } else {
- echo '';
+ catch (Exception $e)
+ {
+ $message="Valeurs invalides, pas de changement \n ".
+ $e->getMessage();
+ echo '';
+ }
+ if ( strlen ($p_val) != 0 && strlen ($p_lib) != 0 && strlen($old_line)!=0 )
+ {
+ if (strlen ($p_val) == 1 )
+ {
+ $p_parent=0;
+ }
+ else
+ {
+ if ( strlen($p_parent)==0 )
+ {
+ $p_parent=substr($p_val,0,strlen($p_val)-1);
+ }
+ }
+ /* Parent existe */
+ $Ret=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val=$1",array($p_parent));
+ if ( ($p_parent != 0 && Database::num_row($Ret) == 0) || $p_parent==$old_line )
+ {
+ echo '';
+ }
+ else
+ {
+ try
+ {
+ $acc->update($old_line);
+ }
+ catch(Exception $e)
+ {
+ alert($e->getMessage());
+ }
+ }
+ }
+ else
+ {
+ echo '';
}
}
//-----------------------------------------------------
/* Ajout d'une ligne */
-if ( isset ( $_POST["Ajout"] ) ) {
- extract ($_POST);
- $p_val=trim($p_val);
- $p_parent=trim($p_parent);
-
- if ( isset ( $p_val) && isset ( $p_lib ) && isNumber($p_val) && isNumber($p_parent) ) {
+if ( isset ( $_POST["Ajout"] ) )
+{
+ extract ($_POST);
$p_val=trim($p_val);
- $p_parent=$_POST["p_parent"];
- if ( strlen ($p_val) != 0 && strlen ($p_lib) != 0 ) {
- if (strlen ($p_val) == 1 ) {
- $p_parent=0;
- } else {
- if ( strlen(trim($p_parent))==0 &&
- (string) $p_parent != (string)(int) $p_parent) {
- $p_parent=substr($p_val,0,strlen($p_val)-1);
- }
- }
- /* Parent existe */
- $Ret=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val=$1",array($p_parent));
- if ( $p_parent != 0 && Database::num_row($Ret) == 0 ) {
- alert(" Ne peut pas modifier; aucun poste parent");
- } else {
- // Check if the account already exists
-
- $Count=$cn->get_value("select count(*) from tmp_pcmn where pcm_val=$1",array($p_val));
- if ( $Count != 0 )
- {
- // Alert message account already exists
- alert(" Ce poste existe déjà ");
-
- } else
- {
- $Ret=$cn->exec_sql("insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values ($1,$2,$3,$4)",array($p_val,$p_lib,$p_parent,$p_type));
- }
- }
- } else {
- echo '
Valeurs invalides ';
+ $p_parent=trim($p_parent);
+
+ if ( isset ( $p_val) && isset ( $p_lib ) && isNumber($p_val) && isNumber($p_parent) )
+ {
+ $p_val=trim($p_val);
+ $p_parent=$_POST["p_parent"];
+ if ( strlen ($p_val) != 0 && strlen ($p_lib) != 0 )
+ {
+ if (strlen ($p_val) == 1 )
+ {
+ $p_parent=0;
+ }
+ else
+ {
+ if ( strlen(trim($p_parent))==0 &&
+ (string) $p_parent != (string)(int) $p_parent)
+ {
+ $p_parent=substr($p_val,0,strlen($p_val)-1);
+ }
+ }
+ /* Parent existe */
+ $Ret=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val=$1",array($p_parent));
+ if ( $p_parent != 0 && Database::num_row($Ret) == 0 )
+ {
+ alert(" Ne peut pas modifier; aucun poste parent");
+ }
+ else
+ {
+ // Check if the account already exists
+
+ $Count=$cn->get_value("select count(*) from tmp_pcmn where pcm_val=$1",array($p_val));
+ if ( $Count != 0 )
+ {
+ // Alert message account already exists
+ alert(" Ce poste existe déjà ");
+
+ }
+ else
+ {
+ $Ret=$cn->exec_sql("insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values ($1,$2,$3,$4)",array($p_val,$p_lib,$p_parent,$p_type));
+ }
+ }
+ }
+ else
+ {
+ echo ' Valeurs invalides ';
+ }
}
- }
}
$Ret=$cn->exec_sql("select pcm_val,pcm_lib,pcm_val_parent,pcm_type from tmp_pcmn where substr(pcm_val::text,1,1)='".$_SESSION['g_start']."' order by pcm_val::text");
@@ -209,63 +249,67 @@ $MaxRow=Database::num_row($Ret);
?>
-
-
-
- Classe
- Libellé
- Parent
- Type
-
-form(false);
+
+
+ Classe
+ Libellé
+ Parent
+ Type
+
+ form(false);
?>
-
-
-
+
+ ';
- } else {
- $td='';
- }
- echo " ";
- echo "$td";
- echo $A['pcm_val'];
- echo '';
- echo "$td";
- printf ("",
- $A['pcm_val'],
- FormatString($A['pcm_lib']),
- $A['pcm_val_parent'],
- $A['pcm_type'],
- dossier::id());
- echo h($A['pcm_lib']);
+ if ( $i%2 == 0 )
+ {
+ $td =' ';
+ }
+ else
+ {
+ $td=' ';
+ }
+ echo " ";
+ echo "$td";
+ echo $A['pcm_val'];
+ echo '';
+ echo "$td";
+ printf ("",
+ $A['pcm_val'],
+ FormatString($A['pcm_lib']),
+ $A['pcm_val_parent'],
+ $A['pcm_type'],
+ dossier::id());
+ echo h($A['pcm_lib']);
- echo $td;
- echo $A['pcm_val_parent'];
- echo '';
- echo "$td";
- echo $A['pcm_type'];
- echo "";
+ echo $td;
+ echo $A['pcm_val_parent'];
+ echo '';
+ echo "$td";
+ echo $A['pcm_type'];
+ echo "";
- echo $td;
- printf (' Delete ',$A['pcm_val'],$str_dossier);
- echo "";
+ echo $td;
+ printf ('Delete ',$A['pcm_val'],$str_dossier);
+ echo "";
-
- echo " ";
+
+ echo "";
}
echo "
";
echo "";
diff --git a/include/param_sec.inc.php b/include/param_sec.inc.php
index 7c6b0aec1..d16b34c80 100644
--- a/include/param_sec.inc.php
+++ b/include/param_sec.inc.php
@@ -42,204 +42,227 @@ include_once ("user_menu.php");
$cn_dossier=new Database($gDossier);
-if ( $User->check_action(PARSEC) == 0 ) {
- /* Cannot Access */
- NoAccess();
- exit -1;
- }
+if ( $User->check_action(PARSEC) == 0 )
+{
+ /* Cannot Access */
+ NoAccess();
+ exit -1;
+}
$cn=new Database();
/* Show all the users, included local admin */
$user_sql=$cn->exec_sql("select use_id,use_first_name,use_name,use_login,use_admin,priv_priv from ac_users natural join jnt_use_dos ".
- " join priv_user on (jnt_id=priv_jnt) where use_login != 'phpcompta' and dos_id=".$gDossier.' order by use_login,use_name');
+ " join priv_user on (jnt_id=priv_jnt) where use_login != 'phpcompta' and dos_id=".$gDossier.' order by use_login,use_name');
$MaxUser=Database::num_row($user_sql);
-if ( ! isset($_REQUEST['action'])) {
-echo '';
+if ( ! isset($_REQUEST['action']))
+{
+ echo '
';
-echo '
';
-for ($i = 0;$i < $MaxUser;$i++) {
- $l_line=Database::fetch_array($user_sql,$i);
- // echo '';
- if ( $i % 3 == 0 && $i != 0)
- echo " ";
- $str=($l_line['priv_priv'] == 'L')?'Local Admin':' ';
- $str=($l_line['priv_priv'] == 'P')?'Uniquement Extension':$str;
- $str=($l_line['priv_priv'] == 'R')?'Utilisateur Normal':$str;
- if ( $l_line['use_admin'] == 1 )
- $str=' Super Admin';
+ echo '';
+ for ($i = 0;$i < $MaxUser;$i++)
+ {
+ $l_line=Database::fetch_array($user_sql,$i);
+ // echo '';
+ if ( $i % 3 == 0 && $i != 0)
+ echo " ";
+ $str=($l_line['priv_priv'] == 'L')?'Local Admin':' ';
+ $str=($l_line['priv_priv'] == 'P')?'Uniquement Extension':$str;
+ $str=($l_line['priv_priv'] == 'R')?'Utilisateur Normal':$str;
+ if ( $l_line['use_admin'] == 1 )
+ $str=' Super Admin';
- printf ('%s %s ( %s )[%s] ',
- $l_line['use_id'],
- $l_line['use_first_name'],
- $l_line['use_name'],
- $l_line['use_login'],
- $str);
+ printf ('%s %s ( %s )[%s] ',
+ $l_line['use_id'],
+ $l_line['use_first_name'],
+ $l_line['use_name'],
+ $l_line['use_login'],
+ $str);
-}
-echo " ";
-echo '
';
+ }
+ echo " ";
+ echo '
';
}
$action="";
-if ( isset ($_GET["action"] )) {
- $action=$_GET["action"];
+if ( isset ($_GET["action"] ))
+{
+ $action=$_GET["action"];
}
//----------------------------------------------------------------------
// Action = save
//----------------------------------------------------------------------
-if ( isset($_POST['ok'])) {
+if ( isset($_POST['ok']))
+{
- $sec_User=new User($cn_dossier,$_POST['user_id']);
- /* Save first the ledger */
- $cn_dossier=new Database(dossier::id());
- $a=$cn_dossier->get_array('select jrn_def_id from jrn_def');
- foreach ($a as $key) {
- $id=$key['jrn_def_id'];
- $priv=sprintf("jrn_act%d",$id);
- $count=$cn_dossier->get_value('select count(*) from user_sec_jrn where uj_login=$1 '.
- ' and uj_jrn_id=$2',array($sec_User->login,$id));
- if ( $count == 0 )
- {
- $cn_dossier->exec_sql('insert into user_sec_jrn (uj_login,uj_jrn_id,uj_priv)'.
- ' values ($1,$2,$3)',
- array($sec_User->login,$id,$_POST[$priv]));
-
- } else {
- $cn_dossier->exec_sql('update user_sec_jrn set uj_priv=$1 where uj_login=$2 and uj_jrn_id=$3',
- array($_POST[$priv],$sec_User->login,$id));
- }
- }
- /* now save all the actions */
- $a=$cn_dossier->get_array('select ac_id from action');
+ $sec_User=new User($cn_dossier,$_POST['user_id']);
+ /* Save first the ledger */
+ $cn_dossier=new Database(dossier::id());
+ $a=$cn_dossier->get_array('select jrn_def_id from jrn_def');
+ foreach ($a as $key)
+ {
+ $id=$key['jrn_def_id'];
+ $priv=sprintf("jrn_act%d",$id);
+ $count=$cn_dossier->get_value('select count(*) from user_sec_jrn where uj_login=$1 '.
+ ' and uj_jrn_id=$2',array($sec_User->login,$id));
+ if ( $count == 0 )
+ {
+ $cn_dossier->exec_sql('insert into user_sec_jrn (uj_login,uj_jrn_id,uj_priv)'.
+ ' values ($1,$2,$3)',
+ array($sec_User->login,$id,$_POST[$priv]));
- foreach ($a as $key) {
- $id=$key['ac_id'];
- $priv=sprintf("action%d",$id);
- $count=$cn_dossier->get_value('select count(*) from user_sec_act where ua_login=$1 '.
- ' and ua_act_id=$2',array($sec_User->login,$id));
- if ( $_POST[$priv] == 1 && $count == 0)
- {
- $cn_dossier->exec_sql('insert into user_sec_act (ua_login,ua_act_id)'.
- ' values ($1,$2)',
- array($sec_User->login,$id));
-
- }
- if ($_POST[$priv] == 0 ){
- $cn_dossier->exec_sql('delete from user_sec_act where ua_login=$1 and ua_act_id=$2',
- array($sec_User->login,$id));
+ }
+ else
+ {
+ $cn_dossier->exec_sql('update user_sec_jrn set uj_priv=$1 where uj_login=$2 and uj_jrn_id=$3',
+ array($_POST[$priv],$sec_User->login,$id));
+ }
}
- }
-
+ /* now save all the actions */
+ $a=$cn_dossier->get_array('select ac_id from action');
+
+ foreach ($a as $key)
+ {
+ $id=$key['ac_id'];
+ $priv=sprintf("action%d",$id);
+ $count=$cn_dossier->get_value('select count(*) from user_sec_act where ua_login=$1 '.
+ ' and ua_act_id=$2',array($sec_User->login,$id));
+ if ( $_POST[$priv] == 1 && $count == 0)
+ {
+ $cn_dossier->exec_sql('insert into user_sec_act (ua_login,ua_act_id)'.
+ ' values ($1,$2)',
+ array($sec_User->login,$id));
+
+ }
+ if ($_POST[$priv] == 0 )
+ {
+ $cn_dossier->exec_sql('delete from user_sec_act where ua_login=$1 and ua_act_id=$2',
+ array($sec_User->login,$id));
+ }
+ }
+
}
-
-
+
+
//--------------------------------------------------------------------------------
-// Action == View detail for users
+// Action == View detail for users
//--------------------------------------------------------------------------------
-if ( $action == "view" ) {
- $l_Db=sprintf("dossier%d",$gDossier);
+if ( $action == "view" )
+{
+ $l_Db=sprintf("dossier%d",$gDossier);
- $cn=new Database();
- $User=new User($cn,$_GET['user_id']);
- $admin=0;
- $access=$User->get_folder_access($gDossier);
+ $cn=new Database();
+ $User=new User($cn,$_GET['user_id']);
+ $admin=0;
+ $access=$User->get_folder_access($gDossier);
- if ( $access == 'L') {
- $str='Local Admin';$admin=1;
- } elseif ($access=='R') {
- $str=' Utilisateur normal';
- } elseif ($access=='P') {
- $str=' Extension uniquement';
- }
+ if ( $access == 'L')
+ {
+ $str='Local Admin';
+ $admin=1;
+ }
+ elseif ($access=='R')
+ {
+ $str=' Utilisateur normal';
+ }
+ elseif ($access=='P')
+ {
+ $str=' Extension uniquement';
+ }
- if ( $User->admin==1 ) {
- $str=' Super Admin';$admin=1;
- }
+ if ( $User->admin==1 )
+ {
+ $str=' Super Admin';
+ $admin=1;
+ }
- echo '
'.h($User->first_name).' '.h($User->name).' '.hi($User->login)."($str) ";
-
+ echo '
'.h($User->first_name).' '.h($User->name).' '.hi($User->login)."($str) ";
- if ( $admin != 0 ) {
- echo '
Cet utilisateur est administrateur, il a tous les droits ';
- exit();
- }
- //
- // Check if the user can access that folder
- if ( $access == 'X' ){
- echo "
L'utilisateur n'a pas accès à ce dossier ";
- $action="";
- return;
- }
- //--------------------------------------------------------------------------------
- // Show access for journal
- //--------------------------------------------------------------------------------
+ if ( $admin != 0 )
+ {
+ echo '
Cet utilisateur est administrateur, il a tous les droits ';
+ exit();
+ }
+ //
+ // Check if the user can access that folder
+ if ( $access == 'X' )
+ {
+ echo "
L'utilisateur n'a pas accès à ce dossier ";
+ $action="";
+ return;
+ }
- $Res=$cn_dossier->exec_sql("select jrn_def_id,jrn_def_name from jrn_def ".
- " order by jrn_def_name");
- $sec_User=new User($cn_dossier,$_GET['user_id']);
+ //--------------------------------------------------------------------------------
+ // Show access for journal
+ //--------------------------------------------------------------------------------
- echo '
';
- $sHref=sprintf ('sec_pdf.php?p_action=sec&user_id=%s&'.$str_dossier ,
- $_GET ['user_id']
- );
+ $Res=$cn_dossier->exec_sql("select jrn_def_id,jrn_def_name from jrn_def ".
+ " order by jrn_def_name");
+ $sec_User=new User($cn_dossier,$_GET['user_id']);
- echo HtmlInput::button('Imprime','imprime',"onclick=\"window.open('".$sHref."');\"");
- echo HtmlInput::submit('ok','Sauve');
- echo HtmlInput::reset('Annule');
- echo HtmlInput::button_anchor('Retour à la liste','?p_action=sec&'.dossier::get(),'retour');
+ echo ' ';
+ $sHref=sprintf ('sec_pdf.php?p_action=sec&user_id=%s&'.$str_dossier ,
+ $_GET ['user_id']
+ );
- echo dossier::hidden();
- echo HtmlInput::hidden('action','sec');
- echo HtmlInput::hidden('user_id',$_GET['user_id']);
+ echo HtmlInput::button('Imprime','imprime',"onclick=\"window.open('".$sHref."');\"");
+ echo HtmlInput::submit('ok','Sauve');
+ echo HtmlInput::reset('Annule');
+ echo HtmlInput::button_anchor('Retour à la liste','?p_action=sec&'.dossier::get(),'retour');
- echo 'Journaux ';
- echo '';
- $MaxJrn=Database::num_row($Res);
- $jrn_priv=new ISelect();
- $array=array(
- array ('value'=>'R','label'=>'Uniquement lecture'),
- array ('value'=>'W','label'=>'Lecture et écriture'),
- // array ('value'=>'O','label'=>'Uniquement opérations prédéfinies'),
- array ('value'=>'X','label'=>'Aucun accès')
- );
+ echo dossier::hidden();
+ echo HtmlInput::hidden('action','sec');
+ echo HtmlInput::hidden('user_id',$_GET['user_id']);
- for ( $i =0 ; $i < $MaxJrn; $i++ ) {
- /* set the widget */
- $l_line=Database::fetch_array($Res,$i);
+ echo 'Journaux ';
+ echo '';
+ $MaxJrn=Database::num_row($Res);
+ $jrn_priv=new ISelect();
+ $array=array(
+ array ('value'=>'R','label'=>'Uniquement lecture'),
+ array ('value'=>'W','label'=>'Lecture et écriture'),
+ // array ('value'=>'O','label'=>'Uniquement opérations prédéfinies'),
+ array ('value'=>'X','label'=>'Aucun accès')
+ );
- echo ' ';
- if ( $i == 0 ) echo ' Journal ';else echo " ";
- echo " $l_line[jrn_def_name] ";
+ for ( $i =0 ; $i < $MaxJrn; $i++ )
+ {
+ /* set the widget */
+ $l_line=Database::fetch_array($Res,$i);
- $jrn_priv->name='jrn_act'.$l_line['jrn_def_id'];
- $jrn_priv->value=$array;
- $jrn_priv->selected=$sec_User->get_ledger_access($l_line['jrn_def_id']);
+ echo ' ';
+ if ( $i == 0 ) echo ' Journal ';
+ else echo " ";
+ echo " $l_line[jrn_def_name] ";
- echo '';
- echo $jrn_priv->input();
- echo ' ';
- echo ' ';
- }
- echo '
';
- echo ' ';
+ $jrn_priv->name='jrn_act'.$l_line['jrn_def_id'];
+ $jrn_priv->value=$array;
+ $jrn_priv->selected=$sec_User->get_ledger_access($l_line['jrn_def_id']);
- //**********************************************************************
- // Show Priv. for actions
- //**********************************************************************
- echo ' Actions ';
- include('template/security_list_action.php');
- echo ' ';
- echo HtmlInput::button('Imprime','imprime',"onclick=\"window.open('".$sHref."');\"");
- echo HtmlInput::submit('ok','Sauve');
- echo HtmlInput::reset('Annule');
- echo '';
-} // end of the form
+ echo '';
+ echo $jrn_priv->input();
+ echo ' ';
+ echo '';
+ }
+ echo '
';
+ echo ' ';
+
+ //**********************************************************************
+ // Show Priv. for actions
+ //**********************************************************************
+ echo ' Actions ';
+ include('template/security_list_action.php');
+ echo ' ';
+ echo HtmlInput::button('Imprime','imprime',"onclick=\"window.open('".$sHref."');\"");
+ echo HtmlInput::submit('ok','Sauve');
+ echo HtmlInput::reset('Annule');
+ echo ' ';
+} // end of the form
echo "
";
html_page_stop();
?>
diff --git a/include/payment_middle.inc.php b/include/payment_middle.inc.php
index c0e7065fc..4a6d3e525 100644
--- a/include/payment_middle.inc.php
+++ b/include/payment_middle.inc.php
@@ -23,7 +23,12 @@ require_once('class_acc_payment.php');
//---------------------------------------------------------------------------
// Common variable
-$td='
';$etd=' ';$tr='
';$etr=' ';$th='
';$eth=' ';
+$td='
';
+$etd=' ';
+$tr='
';
+$etr=' ';
+$th='
';
+$eth=' ';
/*!\file
* \brief payment mode
@@ -33,71 +38,76 @@ echo '
';
//----------------------------------------------------------------------
// change
-if ( $sb=='change') {
- if ( !isset($_GET['id'])) exit;
- $row=new Acc_Payment($cn,$_GET['id']);
- $row->load();
- $javascript="return confirm('"._('Vous confirmez')."')";
- echo '
';
- echo dossier::hidden();
- echo HtmlInput::hidden('p_jrn',0);
- echo HtmlInput::hidden('p_action','divers');
- echo HtmlInput::hidden('sa','mp');
- echo HtmlInput::hidden('sb','save');
- echo HtmlInput::hidden('mp_type',$row->get_parameter('type'));
- echo HtmlInput::hidden('mp_lib',$row->get_parameter('lib'));
+if ( $sb=='change')
+{
+ if ( !isset($_GET['id'])) exit;
+ $row=new Acc_Payment($cn,$_GET['id']);
+ $row->load();
+ $javascript="return confirm('"._('Vous confirmez')."')";
+ echo ' ';
+ echo dossier::hidden();
+ echo HtmlInput::hidden('p_jrn',0);
+ echo HtmlInput::hidden('p_action','divers');
+ echo HtmlInput::hidden('sa','mp');
+ echo HtmlInput::hidden('sb','save');
+ echo HtmlInput::hidden('mp_type',$row->get_parameter('type'));
+ echo HtmlInput::hidden('mp_lib',$row->get_parameter('lib'));
- echo $row->form();
- echo HtmlInput::submit('save',_('Sauve'));
- echo HtmlInput::submit('delete',_('Efface'));
- echo HtmlInput::button_anchor(_('Retour sans sauvez'),
- '?p_action=divers&sa=mp&'.dossier::get()
- );
- echo ' ';
- exit();
+ echo $row->form();
+ echo HtmlInput::submit('save',_('Sauve'));
+ echo HtmlInput::submit('delete',_('Efface'));
+ echo HtmlInput::button_anchor(_('Retour sans sauvez'),
+ '?p_action=divers&sa=mp&'.dossier::get()
+ );
+ echo '';
+ exit();
}
//----------------------------------------------------------------------
// Save the change
//
-if ( $sb=='save'){
- $row=new Acc_Payment($cn,$_POST ['id']);
- $row->from_array($_POST);
- $row->update();
+if ( $sb=='save')
+{
+ $row=new Acc_Payment($cn,$_POST ['id']);
+ $row->from_array($_POST);
+ $row->update();
}
//---------------------------------------------------------------------------
// Delete a card
//---------------------------------------------------------------------------
-if (isset($_POST['delete'])) {
- $row=new Acc_Payment($cn,$_POST['id']);
- $row->from_array($_POST);
- $row->delete();
+if (isset($_POST['delete']))
+{
+ $row=new Acc_Payment($cn,$_POST['id']);
+ $row->from_array($_POST);
+ $row->delete();
}
//---------------------------------------------------------------------------
// Show form to enter a new one
//---------------------------------------------------------------------------
-if ($sb=='ins') {
- $mp=new Acc_Payment($cn);
- $r=$mp->blank();
- echo '
';
- echo dossier::hidden().HtmlInput::hidden('sa',$_REQUEST['sa']).
+if ($sb=='ins')
+{
+ $mp=new Acc_Payment($cn);
+ $r=$mp->blank();
+ echo ' ';
+ echo dossier::hidden().HtmlInput::hidden('sa',$_REQUEST['sa']).
HtmlInput::hidden('p_action',$_REQUEST['p_action']).HtmlInput::hidden('sb','insert');
- echo $r;
- echo HtmlInput::submit('insert',_('Enregistre'));
- echo ' ';
- echo HtmlInput::button_anchor(_('Retour sans sauvez'),
- '?p_action=divers&sa=mp&'.dossier::get()
- );
+ echo $r;
+ echo HtmlInput::submit('insert',_('Enregistre'));
+ echo '';
+ echo HtmlInput::button_anchor(_('Retour sans sauvez'),
+ '?p_action=divers&sa=mp&'.dossier::get()
+ );
- exit();
+ exit();
}
//---------------------------------------------------------------------------
// Insert a new mod of payment
//---------------------------------------------------------------------------
-if ( $sb=='insert') {
- $row=new Acc_Payment($cn);
- $row->from_array($_POST);
- $row->insert();
+if ( $sb=='insert')
+{
+ $row=new Acc_Payment($cn);
+ $row->from_array($_POST);
+ $row->insert();
}
//----------------------------------------------------------------------
// LEDGER PURCHASE
@@ -110,20 +120,22 @@ $mp=new Acc_Payment($cn);
$mp->set_parameter('type','ACH');
$array=$mp->get_all();
/* if there are data show them in a table */
-if ( ! empty ($array)) {
- echo '
';
- echo $tr.$th._('Libellé').$eth.$th._('Type de fiche')
+if ( ! empty ($array))
+{
+ echo '';
+ echo $tr.$th._('Libellé').$eth.$th._('Type de fiche')
.$eth.$th._('enregistré dans le journal').$eth.
$th._(' Avec la fiche').$eth.$th.'Action'.$eth.$etr;
- foreach ($array as $row) {
- echo $tr;
- echo $row->row();
- echo $td.HtmlInput::button_anchor(_('Modifie'),'?p_action=divers&sa=mp&sb=change&'.dossier::get().
- '&id='.$row->get_parameter('id'));
- echo $etr;
+ foreach ($array as $row)
+ {
+ echo $tr;
+ echo $row->row();
+ echo $td.HtmlInput::button_anchor(_('Modifie'),'?p_action=divers&sa=mp&sb=change&'.dossier::get().
+ '&id='.$row->get_parameter('id'));
+ echo $etr;
- }
- echo '
';
+ }
+ echo '
';
}
echo '';
@@ -137,24 +149,28 @@ $mp=new Acc_Payment($cn);
$mp->set_parameter('type','VEN');
$array=$mp->get_all();
/* if there are data show them in a table */
-if ( ! empty ($array)) {
- echo '
';
- echo $tr.$th.'Libellé'.$eth.$th.'Type de fiche'
- .$eth.$th.'enregistré dans le journal'.$eth.
+if ( ! empty ($array))
+{
+ echo '';
+ echo $tr.$th.'Libellé'.$eth.$th.'Type de fiche'
+ .$eth.$th.'enregistré dans le journal'.$eth.
$th.' Avec la fiche'.$eth.$th.'Action'.$eth.$etr;
- foreach ($array as $row) {
- echo $tr;
- echo $row->row();
- echo $td.HtmlInput::button_anchor('Modifie','?p_action=divers&sa=mp&sb=change&'.dossier::get().
- '&id='.$row->get_parameter('id'));
- echo $etr;
+ foreach ($array as $row)
+ {
+ echo $tr;
+ echo $row->row();
+ echo $td.HtmlInput::button_anchor('Modifie','?p_action=divers&sa=mp&sb=change&'.dossier::get().
+ '&id='.$row->get_parameter('id'));
+ echo $etr;
- }
- echo '
';
+ }
+ echo '
';
}
echo '';
// Button to insert new one
echo HtmlInput::button_anchor(_('Ajout'),'?p_action=divers&sa=mp&sb=ins&'.dossier::get());
echo '
';
+?>
+?>
?>
\ No newline at end of file
diff --git a/include/periode.inc.php b/include/periode.inc.php
index df9ae92b6..d3899c2ff 100644
--- a/include/periode.inc.php
+++ b/include/periode.inc.php
@@ -1,4 +1,4 @@
-can_request(PARPER);
- foreach($_GET as $key=>$element)
+if ( $action=="change_per")
+{
+ $User->can_request(PARPER);
+ foreach($_GET as $key=>$element)
${"$key"}=$element;
- echo "
";
- // $choose="yes";
- echo HtmlInput::button_anchor(_('Retour'),'?p_action=periode&'.Dossier::get());
- exit();
+ echo "
";
+ // $choose="yes";
+ echo HtmlInput::button_anchor(_('Retour'),'?p_action=periode&'.Dossier::get());
+ exit();
}
-if ( isset ($_POST["conf_chg_per"] ) ) {
- $User->can_request(PARPER);
- extract($_POST);
+if ( isset ($_POST["conf_chg_per"] ) )
+{
+ $User->can_request(PARPER);
+ extract($_POST);
- if (isDate($p_date_start) == null ||
- isDate($p_date_end) == null ||
- strlen (trim($p_exercice)) == 0 ||
- (string) $p_exercice != (string)(int) $p_exercice)
- {
- alert(_('Valeurs invalides'));
- } else {
- $Res=$cn->exec_sql(" update parm_periode ".
- "set p_start=to_date('". $p_date_start."','DD.MM.YYYY'),".
- " p_end=to_date('". $p_date_end."','DD.MM.YYYY'),".
- " p_exercice='".$p_exercice."'".
- " where p_id=".$p_per);
+ if (isDate($p_date_start) == null ||
+ isDate($p_date_end) == null ||
+ strlen (trim($p_exercice)) == 0 ||
+ (string) $p_exercice != (string)(int) $p_exercice)
+ {
+ alert(_('Valeurs invalides'));
+ }
+ else
+ {
+ $Res=$cn->exec_sql(" update parm_periode ".
+ "set p_start=to_date('". $p_date_start."','DD.MM.YYYY'),".
+ " p_end=to_date('". $p_date_end."','DD.MM.YYYY'),".
+ " p_exercice='".$p_exercice."'".
+ " where p_id=".$p_per);
- }
- $choose="yes";
+ }
+ $choose="yes";
}
-if ( isset ($_POST["add_per"] )) {
- $User->can_request(PARPER,1);
- extract($_POST);
- $obj=new Periode($cn);
- if ( $obj->insert($p_date_start,$p_date_end,$p_exercice) == 1 ){
- alert(_('Valeurs invalides'));
- }
- $choose="yes";
+if ( isset ($_POST["add_per"] ))
+{
+ $User->can_request(PARPER,1);
+ extract($_POST);
+ $obj=new Periode($cn);
+ if ( $obj->insert($p_date_start,$p_date_end,$p_exercice) == 1 )
+ {
+ alert(_('Valeurs invalides'));
+ }
+ $choose="yes";
}
-if ( $action=="closed") {
- $User->can_request(PARCLO);
- $p_per=$_GET['p_per'];
- $per=new Periode($cn);
- $jrn_def_id=(isset($_GET['jrn_def_id']))?$_GET['jrn_def_id']:0;
- $per->set_jrn($jrn_def_id);
- $per->set_periode($p_per);
- $per->close();
- $choose="yes";
+if ( $action=="closed")
+{
+ $User->can_request(PARCLO);
+ $p_per=$_GET['p_per'];
+ $per=new Periode($cn);
+ $jrn_def_id=(isset($_GET['jrn_def_id']))?$_GET['jrn_def_id']:0;
+ $per->set_jrn($jrn_def_id);
+ $per->set_periode($p_per);
+ $per->close();
+ $choose="yes";
}
-if ( $action== "delete_per" ) {
- $User->can_request(PARPER);
- $p_per=$_GET["p_per"];
+if ( $action== "delete_per" )
+{
+ $User->can_request(PARPER);
+ $p_per=$_GET["p_per"];
// Check if the periode is not used
- if ( $cn->count_sql("select * from jrnx where j_tech_per=$p_per") != 0 ) {
- alert(' Désolé mais cette période est utilisée');
- } else
- {
- $Res=$cn->exec_sql("delete from parm_periode where p_id=$p_per");
- }
- $choose="yes";
+ if ( $cn->count_sql("select * from jrnx where j_tech_per=$p_per") != 0 )
+ {
+ alert(' Désolé mais cette période est utilisée');
+ }
+ else
+ {
+ $Res=$cn->exec_sql("delete from parm_periode where p_id=$p_per");
+ }
+ $choose="yes";
+}
+if ( $choose=="yes" )
+{
+ echo HtmlInput::button_anchor('Autre Journal ?','?choose=no&p_action=periode&gDossier='.dossier::id());
+ $per=new Periode($cn);
+ $jrn=(isset($_GET['jrn_def_id']))?$_GET['jrn_def_id']:0;
+ $per->set_jrn($jrn);
+
+ $per->display_form_periode();
+}
+else
+{
+ echo '
';
+ echo dossier::hidden();
+ $sel_jrn=$cn->make_array("select jrn_def_id, jrn_def_name from ".
+ " jrn_def order by jrn_def_name");
+ $sel_jrn[]=array('value'=>0,'label'=>'Global : periode pour tous les journaux');
+ $wSel=new ISelect();
+ $wSel->value=$sel_jrn;
+ $wSel->name='jrn_def_id';
+ echo "Choississez global ou uniquement le journal à fermer".$wSel->input();
+ echo HtmlInput::submit('choose','Valider');
+ echo HtmlInput::hidden('p_action','periode');
+ echo " ";
+ echo '
Pour ajouter, effacer ou modifier une période, il faut choisir global
';
}
-if ( $choose=="yes" ) {
- echo HtmlInput::button_anchor('Autre Journal ?','?choose=no&p_action=periode&gDossier='.dossier::id());
- $per=new Periode($cn);
- $jrn=(isset($_GET['jrn_def_id']))?$_GET['jrn_def_id']:0;
- $per->set_jrn($jrn);
-
- $per->display_form_periode();
- } else {
- echo '
';
- echo dossier::hidden();
- $sel_jrn=$cn->make_array("select jrn_def_id, jrn_def_name from ".
- " jrn_def order by jrn_def_name");
- $sel_jrn[]=array('value'=>0,'label'=>'Global : periode pour tous les journaux');
- $wSel=new ISelect();
- $wSel->value=$sel_jrn;
- $wSel->name='jrn_def_id';
- echo "Choississez global ou uniquement le journal à fermer".$wSel->input();
- echo HtmlInput::submit('choose','Valider');
- echo HtmlInput::hidden('p_action','periode');
- echo " ";
- echo '
Pour ajouter, effacer ou modifier une période, il faut choisir global
';
- }
echo '
';
?>
diff --git a/include/poste.inc.php b/include/poste.inc.php
index 5d137b5bc..d94c0ce96 100644
--- a/include/poste.inc.php
+++ b/include/poste.inc.php
@@ -1,4 +1,4 @@
-p_comment=$p_comment;
- $update->p_value=$p_value;
- $update->save();
+ extract($_POST);
+ $update=new Acc_Parm_Code($cn,$p_code);
+ $update->p_comment=$p_comment;
+ $update->p_value=$p_value;
+ $update->save();
}
$object=new Acc_Parm_Code($cn);
$all=$object->load_all();
echo '';
echo '
';
-for ($i=0;$i';
- echo $all[$i]->display();
- echo '';
- $w=new IHidden();
- $w->name='id';
- $w->value=$i;
- echo $w->input();
- echo HtmlInput::submit('mod','modifie');
- echo ' ';
- echo ' ';
- echo "";
+for ($i=0;$i';
+ echo $all[$i]->display();
+ echo '';
+ $w=new IHidden();
+ $w->name='id';
+ $w->value=$i;
+ echo $w->input();
+ echo HtmlInput::submit('mod','modifie');
+ echo ' ';
+ echo ' ';
+ echo "";
}
echo "
";
echo "
";
@@ -62,26 +63,27 @@ echo "";
// modifie
if ( isset ($_POST['mod'] ))
{
- echo '';
- echo IPoste::ipopup('ipop_account');
- echo '
';
- echo "Voulez-vous vraiment modifier ? ";
- echo '';
+ echo '';
+ echo IPoste::ipopup('ipop_account');
+ echo '
';
+ echo "Voulez-vous vraiment modifier ? ";
+ echo '';
- echo "";
- $id=$_POST['id'];
- echo $all[$id]->form();
- echo "
";
- $h=new IHidden();
- $h->name='p_action';
- $h->value='divers';;
- echo $h->input();
- echo HtmlInput::hidden('sa','poste');
- echo HtmlInput::submit('confirm_mod','Confirme');
- echo HtmlInput::submit('no','Cancel');
- echo " ";
- echo ' ';
- echo "
";
+ echo "";
+ $id=$_POST['id'];
+ echo $all[$id]->form();
+ echo "
";
+ $h=new IHidden();
+ $h->name='p_action';
+ $h->value='divers';
+ ;
+ echo $h->input();
+ echo HtmlInput::hidden('sa','poste');
+ echo HtmlInput::submit('confirm_mod','Confirme');
+ echo HtmlInput::submit('no','Cancel');
+ echo " ";
+ echo ' ';
+ echo "
";
-}
+}
echo '';
diff --git a/include/pref.inc.php b/include/pref.inc.php
index dda6f3ecb..a3e475b88 100644
--- a/include/pref.inc.php
+++ b/include/pref.inc.php
@@ -1,4 +1,4 @@
-';
// Change password
if ( isset($_POST['pass_1'])
- && strlen(trim($_POST['pass_1'])) != 0 ) {
- if ($_POST['pass_1'] != $_POST['pass_2'] ) {
- alert(_("Les mots de passe ne correspondent pas. Mot de passe inchangé"));
+ && strlen(trim($_POST['pass_1'])) != 0 )
+{
+ if ($_POST['pass_1'] != $_POST['pass_2'] )
+ {
+ alert(_("Les mots de passe ne correspondent pas. Mot de passe inchangé"));
}
- else {
- $Rep=new Database();
- $l_pass=md5($_POST['pass_1']);
- $Res=$Rep->exec_sql("update ac_users set use_pass='$l_pass' where use_login='".$_SESSION['g_user']."'");
- $pass=$_POST['pass_1'];
- $_SESSION['g_pass']=$_POST['pass_1'];
- $g_pass=$_POST['pass_1'];
- echo ""._('Mot de passe est modifiée')." ";
+ else
+ {
+ $Rep=new Database();
+ $l_pass=md5($_POST['pass_1']);
+ $Res=$Rep->exec_sql("update ac_users set use_pass='$l_pass' where use_login='".$_SESSION['g_user']."'");
+ $pass=$_POST['pass_1'];
+ $_SESSION['g_pass']=$_POST['pass_1'];
+ $g_pass=$_POST['pass_1'];
+ echo ""._('Mot de passe est modifiée')." ";
}
- }
+}
$url=$_SERVER['REQUEST_URI'];
-if ( ! isset ($_REQUEST['gDossier']) )
- {
- echo HtmlInput::button_anchor(_('Retour'),'user_login.php?');
- } else {
- echo ''._('Changez vos préférences').' ';
- }
+if ( ! isset ($_REQUEST['gDossier']) )
+{
+ echo HtmlInput::button_anchor(_('Retour'),'user_login.php?');
+}
+else
+{
+ echo ''._('Changez vos préférences').' ';
+}
?>
-
-
-
-
-Mot de passe :
-
-
-
-
-" METHOD="POST">
+
+
';
- echo ''._('Options pour la page d\'accueil').' ';
- echo _('Mini-Rapport : ');
- $rapport=new Acc_Report($cn);
- $aRapport=$rapport->make_array();
- $aRapport[]=array("value"=>0,"label"=>_('Aucun mini rapport'));
- $wRapport=new ISelect();
- $wRapport->name="minirap";
- $wRapport->selected=$User->get_mini_report();
- $wRapport->value=$aRapport;
- echo $wRapport->input();
- echo ''._('Le mini rapport est un rapport qui s\'affiche sur votre page d\'accueil').' ';
- echo '';
+if ( $inside_dossier )
+{
+ /* Pref for welcome page */
+ echo '';
+ echo ''._('Options pour la page d\'accueil').' ';
+ echo _('Mini-Rapport : ');
+ $rapport=new Acc_Report($cn);
+ $aRapport=$rapport->make_array();
+ $aRapport[]=array("value"=>0,"label"=>_('Aucun mini rapport'));
+ $wRapport=new ISelect();
+ $wRapport->name="minirap";
+ $wRapport->selected=$User->get_mini_report();
+ $wRapport->value=$aRapport;
+ echo $wRapport->input();
+ echo ''._('Le mini rapport est un rapport qui s\'affiche sur votre page d\'accueil').' ';
+ echo ' ';
}
echo '';
echo ''._('Langue').' ';
echo _('Selectionnez votre langue');
$aLang=array(array(_('Français'),'fr_FR.utf8'),
- array(_('Anglais'),'en_US.utf8'),
- array(_('Néerlandais'),'nl_NL.utf8'),
- );
+ array(_('Anglais'),'en_US.utf8'),
+ array(_('Néerlandais'),'nl_NL.utf8'),
+ );
echo '';
-for ($i =0;$i < count($aLang);$i++) {
- $sel="";
- if ( $aLang[$i][1]==$_SESSION['g_lang']) $sel=" selected ";
- printf('%s ',
- $aLang[$i][1],$sel,$aLang[$i][0]);
+for ($i =0;$i < count($aLang);$i++)
+{
+ $sel="";
+ if ( $aLang[$i][1]==$_SESSION['g_lang']) $sel=" selected ";
+ printf('%s ',
+ $aLang[$i][1],$sel,$aLang[$i][0]);
}
echo ' ';
@@ -216,12 +235,12 @@ echo '';
-if ( ! $inside_dossier )
+if ( ! $inside_dossier )
{
- echo HtmlInput::button_anchor(_('Retour'),'user_login.php?');
+ echo HtmlInput::button_anchor(_('Retour'),'user_login.php?');
}
-
+
echo "";
?>
diff --git a/include/preod.inc.php b/include/preod.inc.php
index 758e99c27..d2631ddf8 100644
--- a/include/preod.inc.php
+++ b/include/preod.inc.php
@@ -31,77 +31,84 @@ require_once('ac_common.php');
require_once('class_pre_operation.php');
$user=new User(new Database(dossier::id()));
$user->can_request(PARPREDE,1);
- echo '';
- echo '
';
- $sel=new ISelect();
- $sel->name="jrn";
- $sel->value=$cn->make_array("select jrn_def_id,jrn_def_name from ".
- " jrn_def order by jrn_def_name");
- // Show a list of ledger
- $sa=(isset($_REQUEST['sa']))?$_REQUEST['sa']:"";
+echo '';
+echo '
';
+$sel=new ISelect();
+$sel->name="jrn";
+$sel->value=$cn->make_array("select jrn_def_id,jrn_def_name from ".
+ " jrn_def order by jrn_def_name");
+// Show a list of ledger
+$sa=(isset($_REQUEST['sa']))?$_REQUEST['sa']:"";
$sel->selected=(isset($_REQUEST['jrn']))?$_REQUEST['jrn']:-1;
- echo 'Choississez un journal '.$sel->input();
+echo 'Choississez un journal '.$sel->input();
- echo dossier::hidden();
- $hid=new IHidden();
- echo $hid->input("sa","jrn");
- echo $hid->input("p_action","preod");
- echo ' ';
- echo HtmlInput::submit('Accepter','Accepter');
- echo ' ';
+echo dossier::hidden();
+$hid=new IHidden();
+echo $hid->input("sa","jrn");
+echo $hid->input("p_action","preod");
+echo '
';
+echo HtmlInput::submit('Accepter','Accepter');
+echo '';
- // if $_REQUEST[sa] == del delete the predefined operation
- if ( $sa == 'del') {
- $op=new Pre_operation($cn);
- $op->od_id=$_REQUEST['od_id'];
- $op->delete();
- $sa='jrn';
- }
+// if $_REQUEST[sa] == del delete the predefined operation
+if ( $sa == 'del')
+{
+ $op=new Pre_operation($cn);
+ $op->od_id=$_REQUEST['od_id'];
+ $op->delete();
+ $sa='jrn';
+}
- // if $_REQUEST[sa] == jrn show the predefined operation for this
- // ledger
- if ( $sa == 'jrn' ) {
- $op=new Pre_operation($cn);
- $op->set_jrn($_GET['jrn']);
- if ( isset($_GET['direct'])) {
- $op->od_direct='true';
- } else {
- $op->od_direct='false';
- }
- $array=$op->get_list_ledger();
- if ( empty($array) == true ) {
- echo "Aucun enregistrement";
- exit();
- }
+// if $_REQUEST[sa] == jrn show the predefined operation for this
+// ledger
+if ( $sa == 'jrn' )
+{
+ $op=new Pre_operation($cn);
+ $op->set_jrn($_GET['jrn']);
+ if ( isset($_GET['direct']))
+ {
+ $op->od_direct='true';
+ }
+ else
+ {
+ $op->od_direct='false';
+ }
+ $array=$op->get_list_ledger();
+ if ( empty($array) == true )
+ {
+ echo "Aucun enregistrement";
+ exit();
+ }
- echo '
';
- $count=0;
- foreach ($array as $row ) {
+ echo '';
+ $count=0;
+ foreach ($array as $row )
+ {
- if ( $count %2 == 0 )
- echo '';
- else
- echo ' ';
- echo ''.h($row['od_name']).' ';
- echo '';
- echo '';
- echo dossier::hidden();
- echo $hid->input("sa","del");
- echo $hid->input("p_action","preod");
- echo $hid->input("del","");
- echo $hid->input("od_id",$row['od_id']);
- echo $hid->input("jrn",$_GET['jrn']);
+ if ( $count %2 == 0 )
+ echo '';
+ else
+ echo ' ';
+ echo ''.h($row['od_name']).' ';
+ echo '';
+ echo '';
+ echo dossier::hidden();
+ echo $hid->input("sa","del");
+ echo $hid->input("p_action","preod");
+ echo $hid->input("del","");
+ echo $hid->input("od_id",$row['od_id']);
+ echo $hid->input("jrn",$_GET['jrn']);
- $b=' ';
- echo $b;
- echo ' ';
+ $b=' ';
+ echo $b;
+ echo '';
- echo ' ';
- echo ' ';
+ echo ' ';
+ echo ' ';
- }
- echo '
';
- }
- echo '';
+ }
+ echo '
';
+}
+echo '
';
?>
diff --git a/include/quick_writing.inc.php b/include/quick_writing.inc.php
index f277f7e2e..59fc82580 100644
--- a/include/quick_writing.inc.php
+++ b/include/quick_writing.inc.php
@@ -20,7 +20,7 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
-/*!\file
+/*!\file
*
*
* \brief to write directly into the ledgers,the stock and the tables
@@ -51,73 +51,76 @@ echo $pop_tva->input();
$cn=new Database(dossier::id());
$id=(isset ($_REQUEST['p_jrn']))?$_REQUEST['p_jrn']:-1;
/*!\brief show a form for quick_writing */
-function show_qw_menu($def=0) {
- echo '';
}
/*!\brief show a form for quick_writing */
-function show_direct_form($cn,$ledger,$p_array) {
- echo '';
+function show_direct_form($cn,$ledger,$p_array)
+{
+ echo '
';
- $id=(isset ($_REQUEST['p_jrn']))?$_REQUEST['p_jrn']:-1;
- echo JS_COMPUTE_DIRECT;
- echo Acc_Reconciliation::$javascript;
+ $id=(isset ($_REQUEST['p_jrn']))?$_REQUEST['p_jrn']:-1;
+ echo JS_COMPUTE_DIRECT;
+ echo Acc_Reconciliation::$javascript;
- // Show the predef operation
- // Don't forget the p_jrn
- echo '
';
- echo HtmlInput::hidden('p_action',$_REQUEST['p_action']);
- echo dossier::hidden();
- echo HtmlInput::hidden('p_jrn',$_REQUEST['p_jrn']);
- $op=new Pre_operation($cn);
- $op->p_jrn=$_REQUEST['p_jrn'];
- $op->od_direct='t';
- if ( $op->count() > 0 ) {
- echo _("Utilisez une operation ");
- echo $op->show_button();
- echo HtmlInput::submit('use_opd',_('Utilisez une operation'));
- }
- echo ' ';
-
+ // Show the predef operation
+ // Don't forget the p_jrn
+ echo '
';
+ echo HtmlInput::hidden('p_action',$_REQUEST['p_action']);
+ echo dossier::hidden();
+ echo HtmlInput::hidden('p_jrn',$_REQUEST['p_jrn']);
+ $op=new Pre_operation($cn);
+ $op->p_jrn=$_REQUEST['p_jrn'];
+ $op->od_direct='t';
+ if ( $op->count() > 0 )
+ {
+ echo _("Utilisez une operation ");
+ echo $op->show_button();
+ echo HtmlInput::submit('use_opd',_('Utilisez une operation'));
+ }
+ echo ' ';
- echo '
';
- echo dossier::hidden();
- echo HtmlInput::hidden('p_action',$_REQUEST['p_action']);
- echo $ledger->show_form($p_array);
+ echo ' ';
+ echo dossier::hidden();
+ echo HtmlInput::hidden('p_action',$_REQUEST['p_action']);
+
+ echo $ledger->show_form($p_array);
- echo HtmlInput::button('add',_('Ajout d\'une ligne'),'onClick="quick_writing_add_row()"');
+ echo HtmlInput::button('add',_('Ajout d\'une ligne'),'onClick="quick_writing_add_row()"');
- echo HtmlInput::submit('summary',_('Sauvez'));
- echo ''.
+ echo HtmlInput::submit('summary',_('Sauvez'));
+ echo '
'.
_('Débit').' = '.
_('Crédit').' = '.
_('Difference').' =
';
- echo '';
+ echo '';
- echo "";
+ echo "";
- echo create_script(" get_last_date()");
+ echo create_script(" get_last_date()");
- echo '
';
+ echo ' ';
}
@@ -127,23 +130,24 @@ $ledger->with_concerned=true;
// no ledger selected, propose one
// Only ODS
if ($id == -1 )
- {
+{
echo '
';
- // Vide
- echo '
';
- echo dossier::hidden();
- echo HtmlInput::hidden('p_action',$_REQUEST['p_action']);
- echo $ledger->select_ledger('ODS',3)->input();
- echo HtmlInput::submit('show_form',_('Choix du journal'));
- echo ' ';
- echo '';
- exit();
- }
-if ( $User->check_jrn($id) == 'X' ) {
- alert(_("L'acces a ce journal est interdit, \n contactez votre responsable"));
- exit();
- }
+ // Vide
+ echo '
';
+ echo dossier::hidden();
+ echo HtmlInput::hidden('p_action',$_REQUEST['p_action']);
+ echo $ledger->select_ledger('ODS',3)->input();
+ echo HtmlInput::submit('show_form',_('Choix du journal'));
+ echo ' ';
+ echo '
';
+ exit();
+}
+if ( $User->check_jrn($id) == 'X' )
+{
+ alert(_("L'acces a ce journal est interdit, \n contactez votre responsable"));
+ exit();
+}
echo '';
echo '
';
echo '
'._('Journal').' : '.$ledger->get_name().' ';
@@ -151,143 +155,161 @@ echo '';
$sa=( isset ($_REQUEST['sa']))?$_REQUEST['sa']:'';
//======================================================================
// See the ledger listing
-if ($sa == 'l' && $id != -1) {
- // Check privilege
+if ($sa == 'l' && $id != -1)
+{
+// Check privilege
- if ( $User->check_jrn($id) == 'X') {
- NoAccess();
- exit -1;
- }
- show_qw_menu(1);
- echo '
';
- $Ledger=new Acc_Ledger($cn,$id);
- $type=$Ledger->get_type();
- $href=basename($_SERVER['PHP_SELF']);
+ if ( $User->check_jrn($id) == 'X')
+ {
+ NoAccess();
+ exit -1;
+ }
+ show_qw_menu(1);
+ echo '
';
+ $Ledger=new Acc_Ledger($cn,$id);
+ $type=$Ledger->get_type();
+ $href=basename($_SERVER['PHP_SELF']);
- echo '
';
- echo HtmlInput::hidden("sa","l");
- echo HtmlInput::hidden("p_jrn",$id);
- echo HtmlInput::hidden("p_action","quick_writing");
- echo dossier::hidden();
- echo $Ledger->search_form($type,0);
- echo HtmlInput::submit("qwlist",_("Recherche"));
- echo ' ';
- $array=$_GET;
- list($sql,$where)=$Ledger->build_search_sql($array);
+ echo '';
+ echo HtmlInput::hidden("sa","l");
+ echo HtmlInput::hidden("p_jrn",$id);
+ echo HtmlInput::hidden("p_action","quick_writing");
+ echo dossier::hidden();
+ echo $Ledger->search_form($type,0);
+ echo HtmlInput::submit("qwlist",_("Recherche"));
+ echo ' ';
+ $array=$_GET;
+ list($sql,$where)=$Ledger->build_search_sql($array);
- $max_line=$cn->count_sql($sql);
+ $max_line=$cn->count_sql($sql);
- $step=$_SESSION['g_pagesize'];
- $page=(isset($_GET['offset']))?$_GET['page']:1;
- $offset=(isset($_GET['offset']))?$_GET['offset']:0;
- $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
+ $step=$_SESSION['g_pagesize'];
+ $page=(isset($_GET['offset']))?$_GET['page']:1;
+ $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+ $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
- echo $bar;
- list($count,$html)= $Ledger->list_operation($sql,$offset,0);
- echo $html;
- echo $bar;
- echo '';
- exit();
+ echo $bar;
+ list($count,$html)= $Ledger->list_operation($sql,$offset,0);
+ echo $html;
+ echo $bar;
+ echo '
';
+ exit();
}
//======================================================================
// User can write ?
// Write into the ledger
-if ( $User->check_jrn($id) == 'X' ) {
- alert(_("Vous ne pouvez pas accèder à ce journal, contactez votre responsable"));
- exit -1;
+if ( $User->check_jrn($id) == 'X' )
+{
+ alert(_("Vous ne pouvez pas accèder à ce journal, contactez votre responsable"));
+ exit -1;
}
-if ( $User->check_jrn($id)=='W' ) {
- if ( isset($_GET['show_form']) || isset($_POST['correct_it']) ) {
- $array=$_POST;
- $default_periode=$User->get_periode();
- /* check if the ledger is closed */
- if ( $ledger->is_closed($default_periode)==1) {
- echo '
'._('Désolé mais cette periode est fermee pour ce journal').' ';
- exit();
- }
- $periode=new Periode($cn);
- list($date,$devnull)=$periode->first_day($default_periode);
- $array['date']=$date;
- show_qw_menu();
- show_direct_form($cn,$ledger,$array);
- exit();
- }
+if ( $User->check_jrn($id)=='W' )
+{
+ if ( isset($_GET['show_form']) || isset($_POST['correct_it']) )
+ {
+ $array=$_POST;
+ $default_periode=$User->get_periode();
+ /* check if the ledger is closed */
+ if ( $ledger->is_closed($default_periode)==1)
+ {
+ echo '
'._('Désolé mais cette periode est fermee pour ce journal').' ';
+ exit();
+ }
+ $periode=new Periode($cn);
+ list($date,$devnull)=$periode->first_day($default_periode);
+ $array['date']=$date;
+ show_qw_menu();
+ show_direct_form($cn,$ledger,$array);
+ exit();
+ }
// reload with a predefined operation
//
-if ( isset ($_GET['use_opd'])) {
- $op=new Pre_op_advanced($cn);
- $p_post=null;
- if ( isset($_REQUEST['pre_def']) && $_REQUEST['pre_def'] != ''){
- $op->set_od_id($_REQUEST['pre_def']);
- //$op->p_jrn=$id;
-
- $p_post=$op->compute_array();
- }
- show_qw_menu();
- show_direct_form($cn,$ledger,$p_post);
+ if ( isset ($_GET['use_opd']))
+ {
+ $op=new Pre_op_advanced($cn);
+ $p_post=null;
+ if ( isset($_REQUEST['pre_def']) && $_REQUEST['pre_def'] != '')
+ {
+ $op->set_od_id($_REQUEST['pre_def']);
+ //$op->p_jrn=$id;
- exit();
-
- }
-if ( isset($_POST['summary'])) {
- try {
- $ledger->verify($_POST );
- } catch (Exception $e) {
- alert($e->getMessage());
- show_qw_menu();
- show_direct_form($cn,$ledger,$_POST);
- exit();
- }
+ $p_post=$op->compute_array();
+ }
+ show_qw_menu();
+ show_direct_form($cn,$ledger,$p_post);
- echo '
';
- echo $ledger->show_form($_POST,1);
- echo dossier::hidden();
- echo HtmlInput::hidden('p_action',$_REQUEST['p_action']);
-
- echo HtmlInput::submit('save_it',"Sauver",'onClick="return verify_ca();"');
- echo HtmlInput::submit('correct_it','Corriger');
-
- $chk=new ICheckBox();
- $chk->selected=false;
- echo "Sauvez l'opération ?";
- echo $chk->input('save_opd');
- echo ' ';
- exit();
-
- }
-if ( isset($_POST['save_it' ])) {
- $array=$_POST;
+ exit();
- try {
- $ledger->save($array);
- $jr_id=$cn->get_value('select jr_id from jrn where jr_internal=$1',array($ledger->internal));
+ }
+ if ( isset($_POST['summary']))
+ {
+ try
+ {
+ $ledger->verify($_POST );
+ }
+ catch (Exception $e)
+ {
+ alert($e->getMessage());
+ show_qw_menu();
+ show_direct_form($cn,$ledger,$_POST);
+ exit();
+ }
- echo '
Opération enregistrée Piece '.h($ledger->pj).' ';
- if ( strcmp($ledger->pj,$_POST['e_pj']) != 0 ) {
- echo '
'._('Attention numéro pièce existante, elle a du être adaptée').' ';
- }
- printf ('
%s ',
- $jr_id,dossier::id(),$ledger->internal);
+ echo '
';
+ echo $ledger->show_form($_POST,1);
+ echo dossier::hidden();
+ echo HtmlInput::hidden('p_action',$_REQUEST['p_action']);
- echo HtmlInput::button_anchor(_('Autre opération dans ce journal'),
- "?".dossier::get().
- '&show_form'.
- '&p_action=quick_writing&p_jrn='.
- $_REQUEST['p_jrn']);
-
- } catch (Exception $e) {
- alert ($e->getMessage());
- show_qw_menu();
- show_direct_form($cn,$ledger,$_POST);
- }
- exit();
- }
+ echo HtmlInput::submit('save_it',"Sauver",'onClick="return verify_ca();"');
+ echo HtmlInput::submit('correct_it','Corriger');
+
+ $chk=new ICheckBox();
+ $chk->selected=false;
+ echo "Sauvez l'opération ?";
+ echo $chk->input('save_opd');
+ echo ' ';
+ exit();
+
+ }
+ if ( isset($_POST['save_it' ]))
+ {
+ $array=$_POST;
+
+ try
+ {
+ $ledger->save($array);
+ $jr_id=$cn->get_value('select jr_id from jrn where jr_internal=$1',array($ledger->internal));
+
+ echo '
Opération enregistrée Piece '.h($ledger->pj).' ';
+ if ( strcmp($ledger->pj,$_POST['e_pj']) != 0 )
+ {
+ echo '
'._('Attention numéro pièce existante, elle a du être adaptée').' ';
+ }
+ printf ('
%s ',
+ $jr_id,dossier::id(),$ledger->internal);
+
+ echo HtmlInput::button_anchor(_('Autre opération dans ce journal'),
+ "?".dossier::get().
+ '&show_form'.
+ '&p_action=quick_writing&p_jrn='.
+ $_REQUEST['p_jrn']);
+
+ }
+ catch (Exception $e)
+ {
+ alert ($e->getMessage());
+ show_qw_menu();
+ show_direct_form($cn,$ledger,$_POST);
+ }
+ exit();
+ }
} // if check_jrn=='W'
-else {
- show_qw_menu();
+else
+{
+ show_qw_menu();
}
diff --git a/include/report.inc.php b/include/report.inc.php
index 83254b6ef..568b9e376 100644
--- a/include/report.inc.php
+++ b/include/report.inc.php
@@ -14,7 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
-
+
*/
/* $Revision: 1937 $ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
@@ -58,21 +58,25 @@ $cn=new Database($gDossier);
$rap=new Acc_Report($cn);
-if ( isset ($_POST["del_form"]) ) {
- $rap->id=$_POST['fr_id'];
- $rap->delete();
+if ( isset ($_POST["del_form"]) )
+{
+ $rap->id=$_POST['fr_id'];
+ $rap->delete();
}
-if ( isset ($_POST["record"] )) {
- $rap->from_array($_POST);
- $rap->save();
+if ( isset ($_POST["record"] ))
+{
+ $rap->from_array($_POST);
+ $rap->save();
}
-if ( isset($_POST['update'])) {
+if ( isset($_POST['update']))
+{
$rap->from_array($_POST);
$rap->save($_POST);
- }
-if ( isset($_POST['upload'])) {
- $rap->upload();
+}
+if ( isset($_POST['upload']))
+{
+ $rap->upload();
}
@@ -82,72 +86,75 @@ echo '';
-if ( isset($_POST['upload'])) {
+if ( isset($_POST['upload']))
+{
exit();
- }
-if ( isset ($_REQUEST["action"]) ) {
+}
+if ( isset ($_REQUEST["action"]) )
+{
- $action=$_REQUEST ["action"];
- $rap->id=(isset($_REQUEST ['fr_id']))?$_REQUEST['fr_id']:0;
+ $action=$_REQUEST ["action"];
+ $rap->id=(isset($_REQUEST ['fr_id']))?$_REQUEST['fr_id']:0;
- if ($action == "add" && ! isset($_REQUEST['fr_id']))
+ if ($action == "add" && ! isset($_REQUEST['fr_id']))
{
- echo '
';
- echo '
'._('Définition').' ';
- echo '';
- echo dossier::hidden();
- $rap->id=0;
- echo $rap->form(15);
-
- echo HtmlInput::submit("record",_("Sauve"));
- echo ' ';
- echo ''._("Les lignes vides seront effacées").' ';
- echo "";
- echo '
';
+ echo '
';
+ echo '
'._('Définition').' ';
+ echo '';
+ echo dossier::hidden();
+ $rap->id=0;
+ echo $rap->form(15);
- echo ' ';
- echo ' Importation ';
- echo dossier::hidden();
- $rap->id=0;
- $wUpload=new IFile();
- $wUpload->name='report';
- $wUpload->value='report_value';
- echo _('Importer ce rapport').' ';
- echo $wUpload->input();
- echo HtmlInput::submit("upload",_("Sauve"));
- echo ' ';
- echo ''._("Les lignes vides seront effacées").' ';
- echo "";
+ echo HtmlInput::submit("record",_("Sauve"));
+ echo '';
+ echo '
'._("Les lignes vides seront effacées").' ';
+ echo "
";
+ echo '
';
+
+ echo '
';
+ echo ' Importation ';
+ echo dossier::hidden();
+ $rap->id=0;
+ $wUpload=new IFile();
+ $wUpload->name='report';
+ $wUpload->value='report_value';
+ echo _('Importer ce rapport').' ';
+ echo $wUpload->input();
+ echo HtmlInput::submit("upload",_("Sauve"));
+ echo ' ';
+ echo ''._("Les lignes vides seront effacées").' ';
+ echo "";
}
- if ($action=="view" )
- {
- echo '
';
- $rap->id=$_REQUEST ['fr_id'];
- echo '
';
- $rap->load();
- echo $rap->form();
- echo HtmlInput::hidden("fr_id",$rap->id);
- echo HtmlInput::hidden("action","record");
- echo HtmlInput::submit("update",_("Mise a jour"));
- echo HtmlInput::submit("del_form",_("Effacement"));
- $w=new IButton();
- $w->name="export";
- $w->javascript="report_export('".$gDossier."','".$rap->id."')";
- $w->label='Export';
- echo $w->input();
- echo ' ';
- echo ' ';
- echo ''._("Les lignes vides seront effacées").' ';
- echo "";
- }
+ if ($action=="view" )
+ {
+ echo '
';
+ $rap->id=$_REQUEST ['fr_id'];
+ echo '
';
+ $rap->load();
+ echo $rap->form();
+ echo HtmlInput::hidden("fr_id",$rap->id);
+ echo HtmlInput::hidden("action","record");
+ echo HtmlInput::submit("update",_("Mise a jour"));
+ echo HtmlInput::submit("del_form",_("Effacement"));
+ $w=new IButton();
+ $w->name="export";
+ $w->javascript="report_export('".$gDossier."','".$rap->id."')";
+ $w->label='Export';
+ echo $w->input();
+ echo ' ';
+ echo ' ';
+ echo ''._("Les lignes vides seront effacées").' ';
+ echo "";
+ }
}
diff --git a/include/restore.inc.php b/include/restore.inc.php
index fd7a5c9c0..0d5f16075 100644
--- a/include/restore.inc.php
+++ b/include/restore.inc.php
@@ -26,170 +26,189 @@ require_once('class_ifile.php');
/*!\file
* \brief restaure a database
*/
-if ( isset ($_REQUEST['sa'] )) {
- if ( defined ('PG_PATH') )
- putenv("PATH=".PG_PATH);
+if ( isset ($_REQUEST['sa'] ))
+{
+ if ( defined ('PG_PATH') )
+ putenv("PATH=".PG_PATH);
- $cmd=escapeshellcmd (PG_RESTORE);
- putenv("PGPASSWORD=".phpcompta_password);
- putenv("PGUSER=".phpcompta_user);
- putenv("PGPORT=".phpcompta_psql_port);
- $retour='
'.HtmlInput::button_anchor("Retour","?action=restore");
- if ( ! isset($_REQUEST['t'])) {
- echo '
';
- echo ("Vous devez préciser s'il s'agit d'un modèle ou d'un dossier ");
- echo $retour;
- echo '
';
- exit();
- }
- if ( empty ($_FILES['file']['name']) ||
- strlen(trim($_FILES['file']['name']))==0
- ) {
- echo '
';
-
- echo ("Vous devez donner un fichier ");
- echo $retour;
- echo '
';
- exit();
- }
- //---------------------------------------------------------------------------
- // Restore a folder (dossier)
- if ( $_REQUEST['t']=='d') {
- ini_set('upload_max_filesize','25M');
- ini_set('post_max_size','25M');
- echo '
';
-
- $cn=new Database();
- $id=$cn->get_next_seq('dossier_id');
-
- if ( strlen(trim($_REQUEST['database'])) == 0 )
- $lname=$id." Restauration :".FormatString($_FILES['file']['name']);
- else
- $lname=$id." ".$_REQUEST['database'];
-
-
- $sql="insert into ac_dossier (dos_id,dos_name) values (".$id.",'".$lname."') ";
- $cn->start();
- try{
- $cn->get_value($sql);
-
-
- } catch ( Exception $e) {
- echo '
'."Echec de la restauration ".' ';
- $cn->rollback();
- exit();
+ $cmd=escapeshellcmd (PG_RESTORE);
+ putenv("PGPASSWORD=".phpcompta_password);
+ putenv("PGUSER=".phpcompta_user);
+ putenv("PGPORT=".phpcompta_psql_port);
+ $retour='
'.HtmlInput::button_anchor("Retour","?action=restore");
+ if ( ! isset($_REQUEST['t']))
+ {
+ echo '
';
+ echo ("Vous devez préciser s'il s'agit d'un modèle ou d'un dossier ");
+ echo $retour;
+ echo '
';
+ exit();
}
- $cn->commit();
- $name=domaine."dossier".$id;
- echo $name;
- $cn->exec_sql("create database ".$name." encoding='utf8'");
- $args=" --no-owner -d $name ".$_FILES['file']['tmp_name'];
+ if ( empty ($_FILES['file']['name']) ||
+ strlen(trim($_FILES['file']['name']))==0
+ )
+ {
+ echo '
';
- exec(PG_RESTORE.$args);
- $test=new Database($id);
- if ( $test->exist_table('version') ){
- echo '
Restauration réussie du dossier '.$lname.' ';
- $test->close();
- } else {
- $test->close();
- echo ' Problème lors de la restauration '.$lname.' ';
- $cn->exec_sql('delete from ac_dossier where dos_id=$1',array($id));
- $cn->exec_sql('drop database '.$name);
- exit();
+ echo ("Vous devez donner un fichier ");
+ echo $retour;
+ echo '';
+ exit();
}
- $new_cn=new Database($id);
+ //---------------------------------------------------------------------------
+ // Restore a folder (dossier)
+ if ( $_REQUEST['t']=='d')
+ {
+ ini_set('upload_max_filesize','25M');
+ ini_set('post_max_size','25M');
+ echo '
';
- $new_cn->apply_patch($name,0);
- echo ''.'Ne pas recharger la page, sinon votre base de données sera restaurée une fois de plus'.' ';
- echo $retour;
+ $cn=new Database();
+ $id=$cn->get_next_seq('dossier_id');
- echo '
';
- }
- //---------------------------------------------------------------------------
- // Restore a modele
+ if ( strlen(trim($_REQUEST['database'])) == 0 )
+ $lname=$id." Restauration :".FormatString($_FILES['file']['name']);
+ else
+ $lname=$id." ".$_REQUEST['database'];
- if ( $_REQUEST['t']=='m') {
- ini_set('upload_max_filesize','25M');
- ini_set('post_max_size','25M');
+ $sql="insert into ac_dossier (dos_id,dos_name) values (".$id.",'".$lname."') ";
+ $cn->start();
+ try
+ {
+ $cn->get_value($sql);
+
+
+ }
+ catch ( Exception $e)
+ {
+ echo '
'."Echec de la restauration ".' ';
+ $cn->rollback();
+ exit();
+ }
+ $cn->commit();
+ $name=domaine."dossier".$id;
+ echo $name;
+ $cn->exec_sql("create database ".$name." encoding='utf8'");
+ $args=" --no-owner -d $name ".$_FILES['file']['tmp_name'];
+
+ exec(PG_RESTORE.$args);
+ $test=new Database($id);
+ if ( $test->exist_table('version') )
+ {
+ echo '
Restauration réussie du dossier '.$lname.' ';
+ $test->close();
+ }
+ else
+ {
+ $test->close();
+ echo '
Problème lors de la restauration '.$lname.' ';
+ $cn->exec_sql('delete from ac_dossier where dos_id=$1',array($id));
+ $cn->exec_sql('drop database '.$name);
+ exit();
+ }
+ $new_cn=new Database($id);
+
+ $new_cn->apply_patch($name,0);
+ echo '
'.'Ne pas recharger la page, sinon votre base de données sera restaurée une fois de plus'.' ';
+ echo $retour;
+
+ echo '
';
+ }
+ //---------------------------------------------------------------------------
+ // Restore a modele
+
+ if ( $_REQUEST['t']=='m')
+ {
+ ini_set('upload_max_filesize','25M');
+ ini_set('post_max_size','25M');
+
+ echo '
';
+
+ $cn=new Database();
+ $id=$cn->get_next_seq('s_modid');
+
+ if ( strlen(trim($_REQUEST['database'])) == 0 )
+ $lname=$id." Restauration :".FormatString($_FILES['file']['name']);
+ else
+ $lname=$id." ".$_REQUEST['database'];
+
+
+ $sql="insert into modeledef (mod_id,mod_name) values (".$id.",'Restauration".$lname."') ";
+ $cn->start();
+ try
+ {
+ $cn->get_value($sql);
+
+ }
+ catch ( Exception $e)
+ {
+ echo ''."Echec de la restauration ".' ';
+ $cn->rollback();
+ exit();
+ }
+ $cn->commit();
+
+ $name=domaine."mod".$id;
+ $cn->exec_sql("create database ".$name." encoding='utf8'");
+ $args=" -d $name ".$_FILES['file']['tmp_name'];
+ $status=exec(PG_RESTORE.$args);
+
+ $test=new Database($id,'mod');
+ if ( $test->exist_table('version') )
+ {
+ echo '
Restauration réussie du dossier '.$lname.' ';
+ $test->close();
+ }
+ else
+ {
+ $test->close();
+ echo ' Problème lors de la restauration '.$lname.' ';
+ $cn->exec_sql('delete from modeledef where mod_id=$1',array($id));
+ $cn->exec_sql('drop database '.$name);
+ exit();
+ }
+
+ $new_cn=new Database($id,'mod');
+
+ $new_cn->apply_patch($name,0);
+
+ echo ''.'Ne pas recharger la page, sinon votre base de données sera restaurée une fois de plus'.' ';
+ echo $retour;
+
+ echo '';
+ }
+}
+else
+{
echo '
';
-
- $cn=new Database();
- $id=$cn->get_next_seq('s_modid');
-
- if ( strlen(trim($_REQUEST['database'])) == 0 )
- $lname=$id." Restauration :".FormatString($_FILES['file']['name']);
- else
- $lname=$id." ".$_REQUEST['database'];
-
-
- $sql="insert into modeledef (mod_id,mod_name) values (".$id.",'Restauration".$lname."') ";
- $cn->start();
- try{
- $cn->get_value($sql);
-
- } catch ( Exception $e) {
- echo ''."Echec de la restauration ".' ';
- $cn->rollback();
- exit();
- }
- $cn->commit();
-
- $name=domaine."mod".$id;
- $cn->exec_sql("create database ".$name." encoding='utf8'");
- $args=" -d $name ".$_FILES['file']['tmp_name'];
- $status=exec(PG_RESTORE.$args);
-
- $test=new Database($id,'mod');
- if ( $test->exist_table('version') ){
- echo '
Restauration réussie du dossier '.$lname.' ';
- $test->close();
- } else {
- $test->close();
- echo ' Problème lors de la restauration '.$lname.' ';
- $cn->exec_sql('delete from modeledef where mod_id=$1',array($id));
- $cn->exec_sql('drop database '.$name);
- exit();
- }
-
- $new_cn=new Database($id,'mod');
-
- $new_cn->apply_patch($name,0);
-
- echo ''.'Ne pas recharger la page, sinon votre base de données sera restaurée une fois de plus'.' ';
- echo $retour;
-
- echo '';
- }
- } else {
- echo '
';
- echo '
';
- echo HtmlInput::hidden('action','restore');
- echo HtmlInput::hidden('sa','r');
- echo '';
- echo ''."Nom de la base de donnée".' ';
- $wNom=new IText();
- $wNom->name="database";
- $wNom->size=12;
- echo ''.$wNom->input().' ';
- echo ''."Type de backup :".' ';
- $chk=new IRadio();
- $chk->name="t";
- $chk->value="d";
- echo ' '.$chk->input()."Dossier".' ';
- echo ' ';
- $chk->name="t";
- $chk->value="m";
- echo ''.$chk->input()."Modele".' ';
- echo '';
- $file=new IFile();
- $file->name="file";
- $file->value="mod";
- echo td('Fichier ').
+ echo '';
+ echo HtmlInput::hidden('action','restore');
+ echo HtmlInput::hidden('sa','r');
+ echo '';
+ echo ''."Nom de la base de donnée".' ';
+ $wNom=new IText();
+ $wNom->name="database";
+ $wNom->size=12;
+ echo ''.$wNom->input().' ';
+ echo ''."Type de backup :".' ';
+ $chk=new IRadio();
+ $chk->name="t";
+ $chk->value="d";
+ echo ' '.$chk->input()."Dossier".' ';
+ echo ' ';
+ $chk->name="t";
+ $chk->value="m";
+ echo ''.$chk->input()."Modele".' ';
+ echo '';
+ $file=new IFile();
+ $file->name="file";
+ $file->value="mod";
+ echo td('Fichier ').
td($file->input());
- echo ' ';
- echo '
';
- echo HtmlInput::submit("","Restauration");
- echo ' ';
- echo '';
- }
+ echo ' ';
+ echo '
';
+ echo HtmlInput::submit("","Restauration");
+ echo ' ';
+ echo '
';
+}
diff --git a/include/stock.inc.php b/include/stock.inc.php
index cbad77917..a6438e964 100644
--- a/include/stock.inc.php
+++ b/include/stock.inc.php
@@ -1,4 +1,4 @@
-Check();
$href=basename($_SERVER['PHP_SELF']);
if ($href=='compta.php')
{
- //Show the top menu
- include_once ("user_menu.php");
-
- // Show Menu Left
- $left_menu=ShowMenuAdvanced(5);
- //echo '