diff --git a/include/ac_common.php b/include/ac_common.php
index 8e6b31e0f..d9b65ecd8 100644
--- a/include/ac_common.php
+++ b/include/ac_common.php
@@ -59,6 +59,27 @@ function cmpDate ($p_date,$p_date_oth) {
// si $p_date > $p_date_oth return > 0
return $l_mkdate-$l2_mkdate;
}
+/* function IsNumber
+ * purpose : check if the argument is a number
+ *
+ * parm : $p_int
+ *
+ * gen nothing
+ *
+ * return :
+ * 1 it's a number
+ * 0 it is not
+ */
+function isNumber($p_int) {
+ if ( strlen (trim($p_int)) == 0 ) return 0;
+ if (! ereg ("^[0-9]+$",$p_int) ) {
+ return 0;
+ } else {
+ return 1;
+ }// !ereg
+ return $p_date;
+}
+
/* function isDate
* Purpose : Verifie qu'une date est bien formaté
* en d.m.y et est valable
diff --git a/include/constant.php b/include/constant.php
index 2cc0ecc1c..fb3983c4b 100644
--- a/include/constant.php
+++ b/include/constant.php
@@ -77,4 +77,17 @@ define ("NOTCENTRALIZED",3);
define ("MENU_FACT",1);
define ("MENU_FICHE",2);
define ("MENU_PARAM",3);
+
+// for the fiche_inc.GetSqlFiche function
+define ("ALL_FICHE_DEF_REF", 1000);
+
+// fixed value for attr_def data
+define ("ATTR_DEF_ACCOUNT",5);
+define ("ATTR_DEF_NAME",1);
+define ("ATTR_DEF_PRIX_ACHAT",6);
+define ("ATTR_DEF_PRIX_VENTE",7);
+define ("ATTR_DEF_TVA",2);
+define ("FICHE_TYPE_CLIENT",9);
+define ("FICHE_TYPE_VENTE",1);
+
?>
diff --git a/include/fiche_inc.php b/include/fiche_inc.php
index aa5f38410..408231e0b 100644
--- a/include/fiche_inc.php
+++ b/include/fiche_inc.php
@@ -19,8 +19,29 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
// $Revision$
+/* fucntion GetSqlFiche
+ ***************************************************
+ * purpose : return the sql string which match the p_type
+ * permit to have all the sql here
+ * param : $p_type what sql select command u want
+ * return : string
+ */
+function GetSqlFiche($p_type) {
+ switch ($p_type ) {
+
+ // return all the existing fiche_def_ref
+ case ALL_FICHE_DEF_REF:
+ return "select frd_id, frd text from fiche_def_ref";
+
+ default:
+ echo_error("undefined type cannot return the corresponding select");
+ return null;
+ }
+
+}
/* function addFiche
+ ***************************************************
* Purpose : ajoute une nouvelle fiche
*
* parm :
@@ -35,41 +56,96 @@
*/
function AddFiche($p_cn,$p_type,$p_array) {
echo_debug(" AddFiche($p_cn,$p_type,$p_array) ");
-
+ // Push the array in element starting with p
+ //
foreach ($p_array as $key=>$element){
${"p_$key"}=$element;
echo_debug("p_$key=$element;");
}
- $base=GetBaseFiche($p_cn,$p_type);
- $num=GetNextFiche($p_cn,$base);
- $sql=sprintf("insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent)
+ // First Get the attr of the fiche
+ $field=Get_attr_def($p_cn,$p_fd_id);
+
+
+ // Create the Fiche
+ $Sql="insert into fiche (fd_id) values (".$p_fd_id.")";
+ $Res=ExecSql($p_cn,$Sql);
+
+ // Get is f_id (sequence)
+ $l_f_id=GetSequence($p_cn,'s_fiche');
+ // TODO If a class base if given, we should not create automatically
+ // The class
+
+ // Should we Create accounts for each cards
+ $create=GetCreateAccount($p_cn,$p_fd_id);
+
+ echo_debug ( " create = $create ");
+ if ( $create == 1) {
+ // We create an account for each
+ // Get The Class Base
+ $base=GetBaseFiche($p_cn,$p_type);
+
+ // If a specific post account is needed created it
+
+ if ( $base !=null ) {
+ // if the class base is not null, create it in the tmp_pcmn
+ $num=GetNextFiche($p_cn,$base);
+ $sql=sprintf("insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent)
values (%s,'%s',%d)",
- $num,
- $p_nom0,
- $base);
- echo_debug($sql);
- $Res=ExecSql($p_cn,$sql);
- $sql=sprintf("insert into fiche ( f_id,f_label,f_fd_id) values (%d,'%s',%d)",
- $num,$p_nom0,$p_type);
- $Res=ExecSql($p_cn,$sql);
- for ( $i = 1; $i < $p_inc;$i++) {
- $sql=sprintf("insert into isupp (is_f_id,is_isd_id,is_value) values (
- %d,%d,'%s')",
- $num, ${"p_isd_id$i"},${"p_nom$i"});
- echo_debug($sql);
- $Res=ExecSql($p_cn,$sql);
+ $num,
+ $p_av_text0,
+ $base);
+ echo_debug($sql);
+ $Res=ExecSql($p_cn,$sql);
+ // Add it the jnt table
+ // 5 is always for the account post
+ $Sql=sprintf("insert into jnt_fic_att_value (f_id,ad_id) values (%d,%d)",
+ $l_f_id,ATTR_DEF_ACCOUNT);
+ $Res=ExecSql($p_cn,$Sql);
+
+ // Get the jft_id sequence (s_jnt_fic_att_value)
+ $l_jft_id=GetSequence($p_cn,'s_jnt_fic_att_value');
+
+
+ // Add it the attr_value table
+ $Sql=sprintf("insert into attr_value(jft_id,av_text) values (%d,'%s')",
+ $l_jft_id,$num);
+ $Res=ExecSql($p_cn,$Sql);
+ }
+ }// end create accounts for each cards
+
+
+ // Add the others attribut in jnt_fic_att_value and after in attr_value
+ for ( $i = 0; $i < $p_inc;$i++) {
+ //Except for the class base
+ if ( ${"p_ad_id$i"} == ATTR_DEF_ACCOUNT ) continue;
+
+ // Add it the jnt table
+ $Sql=sprintf("insert into jnt_fic_att_value (f_id,ad_id) values (%d,%d)",
+ $l_f_id,${"p_ad_id$i"});
+ $Res=ExecSql($p_cn,$Sql);
+
+ // Get the jft_id sequence (s_jnt_fic_att_value)
+ $l_jft_id=GetSequence($p_cn,'s_jnt_fic_att_value');
+
+
+ // Add it the attr_value table
+ $Sql=sprintf("insert into attr_value(jft_id,av_text) values (%d,'%s')",
+ $l_jft_id,${"p_av_text$i"});
+ $Res=ExecSql($p_cn,$Sql);
+
}
}
/* function EncodeFiche
+ ***************************************************
* Purpose : Affiche les détails d'une fiche et propose
* de mettre à jour
* ou si array est a null, permet d'ajouter une
- * fiche
+ * fiche, to fill the attribute
*
* parm :
* - p_cn connexion
- * - p_type id du modele fichedef(fd_id) de la fiche SI array est null
+ * - p_type id du modele fiche_def(fd_id) de la fiche SI array est null
* sinon correspond au id d'une fiche fiche(f_id)
* gen :
* - none
@@ -87,21 +163,29 @@ function EncodeFiche($p_cn,$p_type,$p_array=null) {
echo "
";
if ($p_array == null) {
- echo '
'.getFicheName($p_cn,$p_type).'
';
+ // Array is null so we display a blank form
+ // echo '
'.getFicheName($p_cn,$p_type).'
';
+ echo '
New
';
$p_f_id="";
echo_debug("Array is null");
- $sql="select isd_id,isd_label from isupp_def where isd_fd_id=".$p_type;
+ // Find all the attribute of the existing cards
+ // --> Get_attr_def
+ $sql="select frd_id,ad_id,ad_text from fiche_def join jnt_fic_attr using (fd_id)
+ join attr_def using (ad_id) where fd_id=".$p_type." order by ad_id";
$Res=ExecSql($p_cn,$sql);
$Max=pg_NumRows($Res);
-
- echo '';
+ // Put the card modele id (fiche_def.fd_id)
+ echo '';
for ($i=0;$i < $Max;$i++) {
$l_line=pg_fetch_array($Res,$i);
- $Hid=sprintf('',
- $i,$l_line['isd_id']);
- printf ('
%s
%s
',
- $l_line['isd_label'], $i,$Hid);
+
+ // The number of the attribute
+ $Hid=sprintf('',
+ $i,$l_line['ad_id']);
+ // content of the attribute
+ printf ('
';
@@ -109,33 +193,45 @@ function EncodeFiche($p_cn,$p_type,$p_array=null) {
echo '';
echo '';
}else {
+ // Array is not null so we have to find the card's data from the database
+ // and display them
- $sql="select f_label,f_fd_id from fiche where f_id=".$p_type;
- $Res=ExecSql($p_cn,$sql);
- $Max=pg_NumRows($Res);
- if ( $Max == 0 ) return;
- $l_line=pg_fetch_array($Res,0);
- echo '
'.getFicheName($p_cn,$l_line['f_fd_id']).'
';
- printf(' ',
- $l_line['f_label']);
- echo '';
+ // Display the card name
+ $label=getFicheName($p_cn,$p_type);
+ echo '
'.$label.'
';
+
+ // Find all the data related to the card
+ $sql="select av_text,ad_id,ad_text,jft_id from attr_value
+ natural join attr_def
+ natural join jnt_fic_att_value
+ natural join fiche where f_id=$p_type";
- $sql="select isd_fd_id,isd_id,isd_label,is_value,is_id,is_f_id from isupp left join isupp_def on isd_id=is_isd_id where is_f_id=".$p_type;
-
$Res=ExecSql($p_cn,$sql);
$Max=pg_NumRows($Res);
echo_debug("Max ==== $Max");
- echo '';
+ echo '';
+ echo '';
echo '';
+
for ($i=0;$i < $Max;$i++) {
+ // fetch the data
$l_line=pg_fetch_array($Res,$i);
-
- $Hid=sprintf('',
- $i,$l_line['is_id']);
- printf ('
%s
%s
',
- $l_line['isd_label'], $i, $l_line['is_value'],$Hid);
+ // Put also the class in a special variable
+ // useful when we want to update the PCMN
+ // TODO permit the update of TMP_PCMN
+ if ( $l_line['ad_id'] == ATTR_DEF_ACCOUNT ) {
+ printf('',
+ $l_line['av_text']);
+
+ }
+ // in hidden we put the jft_id
+ $Hid=sprintf('',
+ $i,$l_line['jft_id']);
+ printf ('
%s
%s
',
+ $l_line['ad_text'], $i, $l_line['av_text'],$Hid);
+
}
echo '';
echo '';
@@ -145,6 +241,7 @@ function EncodeFiche($p_cn,$p_type,$p_array=null) {
}
/* function GetBaseFiche
+ ***************************************************
* Purpose : donne la classe comptable de base d'une fiche
*
* parm :
@@ -158,17 +255,40 @@ function EncodeFiche($p_cn,$p_type,$p_array=null) {
*/
function GetBaseFiche($p_cn,$p_type) {
$base=null;
- $Res=ExecSql($p_cn,"select fd_class_base from fichedef where fd_id=".$p_type);
- if ( pg_NumRows($Res) == 0 ) return;
+ $Res=ExecSql($p_cn,"select fd_class_base from fiche_def where fd_id=".$p_type);
+ if ( pg_NumRows($Res) == 0 ) return null;
$base=pg_fetch_array($Res,0);
return $base['fd_class_base'];
}
+
+/* function GetBaseFicheDefault
+ ***************************************************
+ * Purpose : Give the default accounts of fiche_def
+ *
+ *
+ * parm :
+ * - p_cn connexion
+ * - p_type fiche id
+ * gen :
+ * - none
+ * return:
+ * - return la classe id ou rien
+ *
+ */
+function GetBaseFicheDefault($p_cn,$p_type) {
+ $base=null;
+ $Res=ExecSql($p_cn,"select frd_class_base from fiche_def_ref where frd_id=".$p_type);
+ if ( pg_NumRows($Res) == 0 ) return null;
+ $base=pg_fetch_array($Res,0);
+ return $base['frd_class_base'];
+}
/* function ViewFiche
+ ***************************************************
* Purpose : Montre les fiches d'une rubrique
*
* parm :
* - p_cn connexion
- * - $p_type f_id
+ * - $p_type fiche_def.fd_id catg of card
* gen :
* - none
* return:
@@ -176,8 +296,13 @@ function GetBaseFiche($p_cn,$p_type) {
*
*/
function ViewFiche($p_cn,$p_type) {
- echo '
'.getFicheName($p_cn,$p_type).'
';
- $Res=ExecSql($p_cn,"select f_id,f_label from fiche where f_fd_id='".$p_type."' order by f_id");
+ echo '
'.getFicheDefName($p_cn,$p_type).'
';
+ // Get all name the cards of the select category
+ // 1 for attr_def.ad_id is always the name
+ $Res=ExecSql($p_cn,"select f_id,av_text from
+ fiche join jnt_fic_att_value using (f_id)
+ join attr_value using (jft_id)
+ where fd_id='".$p_type."' and ad_id=".ATTR_DEF_NAME." order by f_id");
$Max=pg_NumRows($Res);
for ( $i = 0; $i < $Max; $i++) {
@@ -191,7 +316,7 @@ function ViewFiche($p_cn,$p_type) {
if ( $i %2 == 0 )
$div='
';
- $Res=ExecSql($cn,"select fd_id,fd_label from fichedef order by fd_label");
+ $Res=ExecSql($cn,"select fd_id,fd_label from fiche_def order by fd_label");
$Max=pg_NumRows($Res);
for ( $i=0; $i < $Max;$i++) {
$l_line=pg_fetch_array($Res,$i);