Fix problem with card update (account)

This commit is contained in:
sparkyx 2004-04-06 16:02:28 +00:00
parent ca4e3d0759
commit afe4aa5092
7 changed files with 472 additions and 388 deletions

View file

@ -135,12 +135,12 @@ if ( isset ( $_POST['search']) ) {
$class="even";
else
$class="odd";
$text=FormatString($row['vw_name']);
$r.="<span class=\"$class\">";
$r.=sprintf ('<input type="button" onClick="'."SetData('%s','%s','%s','%s','%s','%s','%s')".'" value="select">',
$e_name,
$row['f_id'] ,
$row['vw_name'],
$text,
$row['vw_sell'],
$row['vw_buy'],
$row['tva_id'],

View file

@ -65,6 +65,7 @@ function AddFiche($p_cn,$p_type,$p_array) {
// First Get the attr of the fiche
$field=Get_attr_def($p_cn,$p_fd_id);
$flag=1;
// Create the Fiche
$Sql="insert into fiche (fd_id) values (".$p_fd_id.")";
@ -76,8 +77,64 @@ function AddFiche($p_cn,$p_type,$p_array) {
// Should we Create accounts for each cards
$create=GetCreateAccount($p_cn,$p_fd_id);
// Is a account given ?
for ( $i = 0; $i < $p_inc;$i++) {
//Except for the class base
if ( ${"p_ad_id$i"} == ATTR_DEF_ACCOUNT ) {
if (strlen (trim(${"p_av_text$i"})) == 0 or
isNumber(${"p_av_text$i"}) == 0 )
{
break;
}
// if account already exist do nothing in tmp_pcmn otherwise add it
if (CountSql($p_cn,"select pcm_val from tmp_pcmn where pcm_val=".${"p_av_text$i"}) == 0 )
{
$len=strlen(${"p_av_text$i"})-1;
// Mother account
$p_parent=substr(${"p_av_text$i"},0,$len);
while (CountSql($p_cn,"select pcm_val from tmp_pcmn where pcm_val=$p_parent") == 0 and
$len > 0 ) {
$len--;
$p_parent=substr(${"p_av_text$i"},0,$len);
}
// If no parent found
if ( $len <= 0 ) {
echo_error ("No parent found");
exit("No parent found for ".${"p_av_text$i"});
} // if $len == 0
$lib=FormatString($p_av_text0);
$sql=sprintf("insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent)
values (%s,'%s',%d)",
${"p_av_text$i"},
$lib,
$p_parent);
// Add if into tmp_pcmn
$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,${"p_av_text$i"});
$Res=ExecSql($p_cn,$Sql);
// If create == 0 we don't create automatically an account
$create=0;
}
} // for $i...
echo_debug ( " create = $create ");
if ( $create == 1) {
if ( $create == 1 ) {
// We create an account for each
// Get The Class Base
$base=GetBaseFiche($p_cn,$p_type);
@ -87,10 +144,12 @@ function AddFiche($p_cn,$p_type,$p_array) {
if ( $base !=null ) {
// if the class base is not null, create it in the tmp_pcmn
$num=GetNextFiche($p_cn,$base);
$lib=FormatString($p_av_text0);
$sql=sprintf("insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent)
values (%s,'%s',%d)",
$num,
$p_av_text0,
$lib,
$base);
echo_debug($sql);
$Res=ExecSql($p_cn,$sql);
@ -127,22 +186,26 @@ function AddFiche($p_cn,$p_type,$p_array) {
// test the vat rate
if ( ${"p_ad_id$i"} == ATTR_DEF_TVA ) {
// is a valid rate ?
if ( CountSql($p_cn,"select * from tva_rate where tva_id='".${"p_av_text$i"}."'") == 0 ) {
// the rate doesn't exist
${"p_av_text$i"}=1;
// warning
echo_error('invalid rate') ;
echo '<script>
// is a rate given
if ( strlen(trim(${"p_av_text$i"})) != 0 and
isNumber(${"p_av_text$i"}) == 1) {
// is a valid rate ?
if ( CountSql($p_cn,"select * from tva_rate where tva_id='".${"p_av_text$i"}."'") == 0 ) {
// the rate doesn't exist
${"p_av_text$i"}=1;
// warning
echo_error('invalid rate') ;
echo '<script>
alert("Attention tva invalid, valeur par défaut =1 ");
</script>';
}
}
}// if a rate is given
}
$text=FormatString(${"p_av_text$i"});
// 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"});
$l_jft_id,$text);
$Res=ExecSql($p_cn,$Sql);
}
@ -478,9 +541,9 @@ function UpdateFiche($p_cn,$p_array) {
$fd_ref=GetFicheDefRef($p_cn,$fiche);
// Update all the others data
for ( $i =0 ; $i < $max ; $i++) {
$text=FormatString( ${"av_text$i"});
$sql=sprintf("update attr_value set av_text='%s' where jft_id=%d",
${"av_text$i"},
$text,
${"jft_id$i"});
echo_debug($sql);
$Res=ExecSql($p_cn,$sql);
@ -514,9 +577,8 @@ function UpdateFiche($p_cn,$p_array) {
// No change if the account is already used
echo_error("Not possible to change the account, already used");
} else {
if ( CountSql($p_cn,"select * from tmp_pcmn where pcm_val=".$class) ==1) {
$Res=ExecSql($p_cn,"update tmp_pcmn set pcm_val=$class_old where pcm_val=$class");
} else // we have to insert
if ( CountSql($p_cn,"select * from tmp_pcmn where pcm_val=".$class) ==0)
// we have to insert
{
// First we must use a parent
$parent=GetParent($p_cn,$class);
@ -852,7 +914,8 @@ function Remove ($p_cn, $p_fid) {
return;
} else {
// Remove in PCMN
ExecSql($p_cn,"delete from tmp_pcmn where pcm_val=".$class);
if ( trim(strlen($class)) != 0 and isNumber($class) == 1)
ExecSql($p_cn,"delete from tmp_pcmn where pcm_val=".$class);
}
}

View file

@ -855,7 +855,33 @@ function FormAch($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p
$r.=$p_submit;
$r.="</DIV>";
$r.="</FORM>";
//TODO if view only show total
//if view only show total
if ( $view_only==true) {
$total=0;
$r.="<TABLE>";
$r.="<th>Nom</th>";
$r.="<th>total</th>";
for ( $i = 0; $i < $p_article;$i++) {
$march=${"e_march$i"};
if ( isNumber($march) ==1 and
isFicheOfJrn($p_cn,$p_jrn,$march,'deb')){
$a_fiche=GetFicheAttribut($p_cn, $march);
// compute some data
$tva=(isNumber($a_fiche['tva_rate']) == 0 )?0:$a_fiche['tva_rate'];
$total_row=${"e_march$i"."_buy"}*${"e_quant$i"}+${"e_march$i"."_buy"}*${"e_quant$i"}*$tva;
$r.="<TR>";
$r.="<TD>".$a_fiche['vw_name']."</td>";
// $r.="<TD>".$a_fiche['tva_label']."</td>";
$r.="<TD ".$total_row."</TD>";
$r.="</TR>";
$total+=$total_row;
}
}
$r.="<TR> <TD colspan=\"3\" align=\"center\"> Total =".$total."</TD></TR>";
$r.="</TABLE>";
}
return $r;
@ -894,6 +920,7 @@ function RecordAchat($p_cn,$p_array,$p_user,$p_jrn)
{
foreach ( $p_array as $v => $e)
{
echo_debug ("Record Achat $v ==> $e");
${"$v"}=$e;
}
@ -959,8 +986,9 @@ function RecordAchat($p_cn,$p_array,$p_user,$p_jrn)
}
}
echo_debug("echeance = $e_ech");
echo_debug("comment = $e_comment");
if ( ($amount+$sum_vat) != 0 ){
if ( InsertJrn($p_cn,$e_date,$e_ech,$p_jrn,"",$amount+$sum_vat,$seq,$periode) == false ) {
if ( InsertJrn($p_cn,$e_date,$e_ech,$p_jrn,$e_comment,$amount+$sum_vat,$seq,$periode) == false ) {
$Rollback($p_cn);exit("error __FILE__ __LINE__");
}
// Set Internal code and Comment

View file

@ -119,7 +119,7 @@ function GetTvaPoste($p_cn,$p_tva_id,$p_cred) {
/* function InsertJrnx($p_cn,$p_type,$p_user,$p_jrn,$p_poste,$p_date,$p_amount,$p_grpt,$p_periode);
/* function InsertJrnx($p_cn,$p_type,$p_user,$p_jrn,$p_poste,$p_date,$p_amount,$p_grpt,$p_periode
**************************************************
* Purpose : Insert into the table Jrn
*
@ -149,7 +149,6 @@ function InsertJrnx($p_cn,$p_type,$p_user,$p_jrn,$p_poste,$p_date,$p_amount,$p_g
$debit=($debit=='false')?'true':'false';
}
$sql=sprintf("insert into jrnx (j_date,j_montant, j_poste,j_grpt, j_jrn_def,j_debit,j_tech_user,j_tech_per)
values (to_date('%s','DD.MM.YYYY'),abs(%.2f),%d,%d,%d,%s,'%s',%d)",
$p_date,round($p_amount,2),$p_poste,$p_grpt,$p_jrn,$debit,$p_user,$p_periode);
@ -159,7 +158,7 @@ function InsertJrnx($p_cn,$p_type,$p_user,$p_jrn,$p_poste,$p_date,$p_amount,$p_g
return GetSequence($p_cn,'s_jrn_op');
}
/* function InsertJrn($p_cn,$p_date,$p_jrn,$p_comment,$p_amount,$p_grpt,$p_periode);
/* function InsertJrn($p_cn,$p_date,$p_jrn,$p_comment,$p_amount,$p_grpt,$p_periode
**************************************************
* Purpose : Insert into the table Jrnx
*
@ -170,6 +169,7 @@ function InsertJrnx($p_cn,$p_type,$p_user,$p_jrn,$p_poste,$p_date,$p_amount,$p_g
* - $p_poste the account
* - $p_amount amount to insert
* - $p_periode the concerned periode
* - $p_comment comment
* gen :
* - none
* return:
@ -179,7 +179,10 @@ function InsertJrnx($p_cn,$p_type,$p_user,$p_jrn,$p_poste,$p_date,$p_amount,$p_g
function InsertJrn($p_cn,$p_date,$p_echeance,$p_jrn,$p_comment,$p_amount,$p_grpt,$p_periode)
{
echo_debug ("InsertJrn param
p_date $p_date p_poste $p_comment p_amount $p_amount p_grpt = $p_grpt p_periode = $p_periode p_echeance = $p_echeance");
p_date $p_date p_poste $p_comment p_amount $p_amount p_grpt = $p_grpt p_periode = $p_periode p_echeance = $p_echeance
comment = $p_comment");
$p_comment=FormatString($p_comment);
if ( $p_echeance == "" or $p_echeance==null) {
$p_echeance='null';
} else {
@ -228,7 +231,7 @@ function ListJrn($p_cn,$p_jrn,$p_where="",$p_array=null)
from
jrn join jrn_def on jrn_def_id=jr_def_id
$p_where
order by jr_date";
order by jr_date desc";
}
if ( $p_array != null ) {
// Construction Query
@ -269,7 +272,7 @@ function ListJrn($p_cn,$p_jrn,$p_where="",$p_array=null)
if ( $l_s_internal != null ) {
$sql.=$l_and." jr_internal='$l_s_internal' ";
}
$sql.=" order by jr_date";
$sql.=" order by jr_date desc";
}// p_array != null
$Res=ExecSql($p_cn,$sql);

View file

@ -7,7 +7,7 @@
SET search_path = public, pg_catalog;
--
-- TOC entry 2 (OID 30851)
-- TOC entry 2 (OID 34004)
-- Name: users_id; Type: SEQUENCE; Schema: public; Owner: phpcompta
--
@ -20,7 +20,7 @@ CREATE SEQUENCE users_id
--
-- TOC entry 12 (OID 30853)
-- TOC entry 12 (OID 34006)
-- Name: ac_users; Type: TABLE; Schema: public; Owner: phpcompta
--
@ -39,7 +39,7 @@ CREATE TABLE ac_users (
--
-- TOC entry 13 (OID 30865)
-- TOC entry 13 (OID 34016)
-- Name: ac_dossier; Type: TABLE; Schema: public; Owner: phpcompta
--
@ -52,7 +52,7 @@ CREATE TABLE ac_dossier (
--
-- TOC entry 4 (OID 30872)
-- TOC entry 4 (OID 34023)
-- Name: seq_jnt_use_dos; Type: SEQUENCE; Schema: public; Owner: phpcompta
--
@ -65,7 +65,7 @@ CREATE SEQUENCE seq_jnt_use_dos
--
-- TOC entry 14 (OID 30874)
-- TOC entry 14 (OID 34025)
-- Name: jnt_use_dos; Type: TABLE; Schema: public; Owner: phpcompta
--
@ -77,7 +77,7 @@ CREATE TABLE jnt_use_dos (
--
-- TOC entry 15 (OID 30877)
-- TOC entry 15 (OID 34028)
-- Name: version; Type: TABLE; Schema: public; Owner: phpcompta
--
@ -87,7 +87,7 @@ CREATE TABLE "version" (
--
-- TOC entry 6 (OID 30879)
-- TOC entry 6 (OID 34030)
-- Name: seq_priv_user; Type: SEQUENCE; Schema: public; Owner: phpcompta
--
@ -100,7 +100,7 @@ CREATE SEQUENCE seq_priv_user
--
-- TOC entry 16 (OID 30881)
-- TOC entry 16 (OID 34032)
-- Name: priv_user; Type: TABLE; Schema: public; Owner: phpcompta
--
@ -112,7 +112,7 @@ CREATE TABLE priv_user (
--
-- TOC entry 17 (OID 30887)
-- TOC entry 17 (OID 34038)
-- Name: theme; Type: TABLE; Schema: public; Owner: phpcompta
--
@ -124,7 +124,7 @@ CREATE TABLE theme (
--
-- TOC entry 8 (OID 30892)
-- TOC entry 8 (OID 34043)
-- Name: s_modid; Type: SEQUENCE; Schema: public; Owner: phpcompta
--
@ -137,7 +137,7 @@ CREATE SEQUENCE s_modid
--
-- TOC entry 18 (OID 30894)
-- TOC entry 18 (OID 34045)
-- Name: modeledef; Type: TABLE; Schema: public; Owner: phpcompta
--
@ -149,7 +149,7 @@ CREATE TABLE modeledef (
--
-- TOC entry 10 (OID 33814)
-- TOC entry 10 (OID 34051)
-- Name: dossier_id; Type: SEQUENCE; Schema: public; Owner: phpcompta
--
@ -162,7 +162,7 @@ CREATE SEQUENCE dossier_id
--
-- Data for TOC entry 27 (OID 30853)
-- Data for TOC entry 27 (OID 34006)
-- Name: ac_users; Type: TABLE DATA; Schema: public; Owner: phpcompta
--
@ -171,7 +171,7 @@ INSERT INTO ac_users VALUES (1, NULL, NULL, 'phpcompta', 1, 'b1cc88e1907cde80cb2
--
-- Data for TOC entry 28 (OID 30865)
-- Data for TOC entry 28 (OID 34016)
-- Name: ac_dossier; Type: TABLE DATA; Schema: public; Owner: phpcompta
--
@ -179,7 +179,7 @@ INSERT INTO ac_dossier VALUES (1, 'Demo', 'Base de donn
--
-- Data for TOC entry 29 (OID 30874)
-- Data for TOC entry 29 (OID 34025)
-- Name: jnt_use_dos; Type: TABLE DATA; Schema: public; Owner: phpcompta
--
@ -193,10 +193,11 @@ INSERT INTO jnt_use_dos VALUES (15, 1, 8);
INSERT INTO jnt_use_dos VALUES (16, 1, 9);
INSERT INTO jnt_use_dos VALUES (17, 1, 10);
INSERT INTO jnt_use_dos VALUES (18, 1, 11);
INSERT INTO jnt_use_dos VALUES (19, 1, 3);
--
-- Data for TOC entry 30 (OID 30877)
-- Data for TOC entry 30 (OID 34028)
-- Name: version; Type: TABLE DATA; Schema: public; Owner: phpcompta
--
@ -204,7 +205,7 @@ INSERT INTO "version" VALUES (3);
--
-- Data for TOC entry 31 (OID 30881)
-- Data for TOC entry 31 (OID 34032)
-- Name: priv_user; Type: TABLE DATA; Schema: public; Owner: phpcompta
--
@ -220,7 +221,7 @@ INSERT INTO priv_user VALUES (9, 13, 'W');
--
-- Data for TOC entry 32 (OID 30887)
-- Data for TOC entry 32 (OID 34038)
-- Name: theme; Type: TABLE DATA; Schema: public; Owner: phpcompta
--
@ -231,7 +232,7 @@ INSERT INTO theme VALUES ('Light', 'style-light.css', NULL);
--
-- Data for TOC entry 33 (OID 30894)
-- Data for TOC entry 33 (OID 34045)
-- Name: modeledef; Type: TABLE DATA; Schema: public; Owner: phpcompta
--
@ -239,7 +240,7 @@ INSERT INTO modeledef VALUES (1, '(BE) Basique', 'Comptabilit
--
-- TOC entry 24 (OID 30926)
-- TOC entry 24 (OID 34081)
-- Name: fk_jnt_use_dos; Type: INDEX; Schema: public; Owner: phpcompta
--
@ -247,7 +248,7 @@ CREATE INDEX fk_jnt_use_dos ON jnt_use_dos USING btree (use_id);
--
-- TOC entry 23 (OID 30927)
-- TOC entry 23 (OID 34082)
-- Name: fk_jnt_dos_id; Type: INDEX; Schema: public; Owner: phpcompta
--
@ -255,7 +256,7 @@ CREATE INDEX fk_jnt_dos_id ON jnt_use_dos USING btree (dos_id);
--
-- TOC entry 19 (OID 30928)
-- TOC entry 19 (OID 34083)
-- Name: ac_users_pkey; Type: CONSTRAINT; Schema: public; Owner: phpcompta
--
@ -264,7 +265,7 @@ ALTER TABLE ONLY ac_users
--
-- TOC entry 20 (OID 30930)
-- TOC entry 20 (OID 34085)
-- Name: ac_users_use_login_key; Type: CONSTRAINT; Schema: public; Owner: phpcompta
--
@ -273,7 +274,7 @@ ALTER TABLE ONLY ac_users
--
-- TOC entry 22 (OID 30932)
-- TOC entry 22 (OID 34087)
-- Name: ac_dossier_pkey; Type: CONSTRAINT; Schema: public; Owner: phpcompta
--
@ -282,7 +283,7 @@ ALTER TABLE ONLY ac_dossier
--
-- TOC entry 21 (OID 30934)
-- TOC entry 21 (OID 34089)
-- Name: ac_dossier_dos_name_key; Type: CONSTRAINT; Schema: public; Owner: phpcompta
--
@ -291,7 +292,7 @@ ALTER TABLE ONLY ac_dossier
--
-- TOC entry 25 (OID 30936)
-- TOC entry 25 (OID 34091)
-- Name: jnt_use_dos_pkey; Type: CONSTRAINT; Schema: public; Owner: phpcompta
--
@ -300,7 +301,7 @@ ALTER TABLE ONLY jnt_use_dos
--
-- TOC entry 34 (OID 30938)
-- TOC entry 34 (OID 34093)
-- Name: $1; Type: CONSTRAINT; Schema: public; Owner: phpcompta
--
@ -309,7 +310,7 @@ ALTER TABLE ONLY jnt_use_dos
--
-- TOC entry 26 (OID 30942)
-- TOC entry 26 (OID 34097)
-- Name: modeledef_pkey; Type: CONSTRAINT; Schema: public; Owner: phpcompta
--
@ -318,7 +319,7 @@ ALTER TABLE ONLY modeledef
--
-- TOC entry 3 (OID 30851)
-- TOC entry 3 (OID 34004)
-- Name: users_id; Type: SEQUENCE SET; Schema: public; Owner: phpcompta
--
@ -326,15 +327,15 @@ SELECT pg_catalog.setval ('users_id', 4, true);
--
-- TOC entry 5 (OID 30872)
-- TOC entry 5 (OID 34023)
-- Name: seq_jnt_use_dos; Type: SEQUENCE SET; Schema: public; Owner: phpcompta
--
SELECT pg_catalog.setval ('seq_jnt_use_dos', 18, true);
SELECT pg_catalog.setval ('seq_jnt_use_dos', 19, true);
--
-- TOC entry 7 (OID 30879)
-- TOC entry 7 (OID 34030)
-- Name: seq_priv_user; Type: SEQUENCE SET; Schema: public; Owner: phpcompta
--
@ -342,7 +343,7 @@ SELECT pg_catalog.setval ('seq_priv_user', 9, true);
--
-- TOC entry 9 (OID 30892)
-- TOC entry 9 (OID 34043)
-- Name: s_modid; Type: SEQUENCE SET; Schema: public; Owner: phpcompta
--
@ -350,10 +351,10 @@ SELECT pg_catalog.setval ('s_modid', 1, false);
--
-- TOC entry 11 (OID 33814)
-- TOC entry 11 (OID 34051)
-- Name: dossier_id; Type: SEQUENCE SET; Schema: public; Owner: phpcompta
--
SELECT pg_catalog.setval ('dossier_id', 3, false);
SELECT pg_catalog.setval ('dossier_id', 3, true);

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff