diff --git a/doc/INSTALL-fr.sgml b/doc/INSTALL-fr.sgml index 25e52c5fa..c044b9a2b 100644 --- a/doc/INSTALL-fr.sgml +++ b/doc/INSTALL-fr.sgml @@ -14,11 +14,11 @@ site savannah Avertissement -

Si vous installez sur Linux, l'installation d'apache, postgres et php peut se +

Si vous installez sur Linux, l'installation d'apache, postgres et php doit se faire avec les "packages" standards fournis; ces "packages" sont largement suffisants. Les explications -données ici sur l'installation de ces produits sont destinées à ceux -préfèrant le faire manuellement. En général vous pourrez l'installer assez facilement +données ici sur l'installation de ces produits sont destinées à des +utilisateurs avancés. En général vous pourrez l'installer assez facilement Il existe aussi un manuel d'installation exhaustif pour Debian, pleins d'informations utiles . @@ -32,6 +32,7 @@ Il est pr

Cependant, les configurations des différents produits sont importantes et devraient être lues avant d'appeler à l'aide. + Postgresql (version 8.0.1 minimum) @@ -106,7 +107,7 @@ Run-time Configuration.

Les paramètres que vous pouvez utiliser si vous avez une machine d'au moins 256 Mb: - Augmenter la zone mémoire pour les tri (dans postgres.conf) sort_mem = 8192; cette + Augmenter la zone mémoire pour les tri (dans postgres.conf) work_mem = 8192; cette zone mémoire est important car elle a trait à la mémoire utilisée pour les tris et les jointures! attention ce paramètre donne la consommation mémoire par session ! @@ -289,7 +290,6 @@ On suppose que postgresql est install Se connecter en tant que postgres et taper les commandes createuser -h localhost -d -P postgres phpcompta -createdb -h localhost -O phpcompta phpcompta Décompacter le package dans le répertoire de votre choix, et configurer Apache pour qu'il diff --git a/doc/header-file.txt b/doc/header-file.txt index 0df82c755..f0225f65e 100644 --- a/doc/header-file.txt +++ b/doc/header-file.txt @@ -1,4 +1,4 @@ -"; } // while (feof) fclose($hf); + if ( DEBUG=='false' ) ob_clean(); } /*! \brief loop to apply all the path to a folder or * a template @@ -162,15 +165,15 @@ function ExecuteScript($p_cn,$script) { */ function apply_patch($p_cn,$p_name) { - $MaxVersion=29; + $MaxVersion=30; for ( $i = 4;$i <= $MaxVersion;$i++) { - if ( DEBUG=='false' ) ob_start(); if ( GetVersion($p_cn) <= $i ) { echo "Patching ".$p_name. " from the version $i to the version ".GetVersion($p_cn)."


"; ExecuteScript($p_cn,'sql/patch/upgrade'.$i.'.sql'); + if ( DEBUG=='false' ) ob_start(); // specific for version 4 if ( $i == 4 ) { @@ -205,10 +208,29 @@ function apply_patch($p_cn,$p_name) AlterSequence($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=ExecSql($p_cn,$sql); + } + $sql="select jrn_def_id from jrn_def "; + $Res=ExecSql($p_cn,$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']); + ExecSql($p_cn,$sql); + } + + } - if ( DEBUG == 'false') ob_end_clean(); + if ( DEBUG == 'false') ob_clean(); + } } } //---------------------------------------------------------------------- @@ -381,7 +403,7 @@ if ($account == 0 ) { ExecuteScript($cn,"sql/account_repository/constraint.sql"); Commit($cn); - if ( DEBUG=='false') ob_end_clean(); + if ( DEBUG=='false') ob_clean(); echo "Creation of Modele1"; if ( DEBUG=='false') ob_start(); @@ -392,7 +414,7 @@ if ($account == 0 ) { ExecuteScript($cn,'sql/mod1/data.sql'); ExecuteScript($cn,'sql/mod1/constraint.sql'); Commit($cn); - if ( DEBUG=='false') ob_end_clean(); + if ( DEBUG=='false') ob_clean(); echo "Creation of Modele2"; ExecSql($cn,"create database ".domaine."mod2 encoding='latin1'"); @@ -404,7 +426,7 @@ if ($account == 0 ) { ExecuteScript($cn,'sql/mod2/constraint.sql'); Commit($cn); - if ( DEBUG=='false') ob_end_clean(); + if ( DEBUG=='false') ob_clean(); }// end if // Add a french accountancy model @@ -467,5 +489,6 @@ for ($e=0;$e < $MaxDossier;$e++) { } } - if (DEBUG=='false') ob_end_clean(); + if (DEBUG=='false') ob_clean(); echo "

Voilà tout est installé ;-)

"; +?> diff --git a/html/admin/sql/account_repository/data.sql b/html/admin/sql/account_repository/data.sql index 4cdc4da8b..f8ccc1b72 100644 --- a/html/admin/sql/account_repository/data.sql +++ b/html/admin/sql/account_repository/data.sql @@ -47,9 +47,6 @@ SELECT pg_catalog.setval('users_id', 5, true); -- Data for Name: ac_dossier; Type: TABLE DATA; Schema: public; Owner: phpcompta -- -INSERT INTO ac_dossier (dos_id, dos_name, dos_description, dos_jnt_user) VALUES (1, 'Demo', 'Base de données pour développement & démo', 0); - - -- -- Data for Name: ac_users; Type: TABLE DATA; Schema: public; Owner: phpcompta -- @@ -58,14 +55,6 @@ INSERT INTO ac_users (use_id, use_first_name, use_name, use_login, use_active, u INSERT INTO ac_users (use_id, use_first_name, use_name, use_login, use_active, use_pass, use_admin) VALUES (1, NULL, NULL, 'phpcompta', 1, 'b1cc88e1907cde80cb2595fa793b3da9', 1); --- --- Data for Name: jnt_use_dos; Type: TABLE DATA; Schema: public; Owner: phpcompta --- - -INSERT INTO jnt_use_dos (jnt_id, use_id, dos_id) VALUES (1, 1, 1); -INSERT INTO jnt_use_dos (jnt_id, use_id, dos_id) VALUES (13, 4, 1); - - -- -- Data for Name: modeledef; Type: TABLE DATA; Schema: public; Owner: phpcompta -- diff --git a/html/admin/sql/mod1/data.sql b/html/admin/sql/mod1/data.sql index 365159861..d2d356f01 100644 --- a/html/admin/sql/mod1/data.sql +++ b/html/admin/sql/mod1/data.sql @@ -1075,8 +1075,8 @@ INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_ INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_jrn_type) VALUES (14, 'Voir Impayés', 'Voir toutes les factures non payées', 'user_jrn.php', 'action=voir_jrn_non_paye', 'FR', 'ACH'); INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_jrn_type) VALUES (20, 'Nouveau', 'Encode un nouvel achat (matériel, marchandises, services et biens divers)', 'user_jrn.php', 'action=new&blank', 'FR', 'FIN'); INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_jrn_type) VALUES (22, 'Voir', 'Voir toutes les factures', 'user_jrn.php', 'action=voir_jrn', 'FR', 'FIN'); -INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_jrn_type) VALUES (30, 'Nouveau', NULL, 'user_jrn.php', 'action=new&blank', 'FR', 'OD '); -INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_jrn_type) VALUES (32, 'Voir', 'Voir toutes les factures', 'user_jrn.php', 'action=voir_jrn', 'FR', 'OD '); +INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_jrn_type) VALUES (30, 'Nouveau', NULL, 'user_jrn.php', 'action=new&blank', 'FR', 'ODS'); +INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_jrn_type) VALUES (32, 'Voir', 'Voir toutes les factures', 'user_jrn.php', 'action=voir_jrn', 'FR', 'ODS'); INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_jrn_type) VALUES (40, 'Soldes', 'Voir les soldes des comptes en banques', 'user_jrn.php', 'action=solde', 'FR', 'FIN'); @@ -1084,7 +1084,7 @@ INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_ -- Data for Name: jrn_def; Type: TABLE DATA; Schema: public; Owner: phpcompta -- -INSERT INTO jrn_def (jrn_def_id, jrn_def_name, jrn_def_class_deb, jrn_def_class_cred, jrn_def_fiche_deb, jrn_def_fiche_cred, jrn_deb_max_line, jrn_cred_max_line, jrn_def_ech, jrn_def_ech_lib, jrn_def_type, jrn_def_code) VALUES (4, 'Opération Diverses', NULL, NULL, NULL, NULL, 5, 5, false, NULL, 'OD ', 'OD-01'); +INSERT INTO jrn_def (jrn_def_id, jrn_def_name, jrn_def_class_deb, jrn_def_class_cred, jrn_def_fiche_deb, jrn_def_fiche_cred, jrn_deb_max_line, jrn_cred_max_line, jrn_def_ech, jrn_def_ech_lib, jrn_def_type, jrn_def_code) VALUES (4, 'Opération Diverses', NULL, NULL, NULL, NULL, 5, 5, false, NULL, 'ODS', 'ODS-01'); INSERT INTO jrn_def (jrn_def_id, jrn_def_name, jrn_def_class_deb, jrn_def_class_cred, jrn_def_fiche_deb, jrn_def_fiche_cred, jrn_deb_max_line, jrn_cred_max_line, jrn_def_ech, jrn_def_ech_lib, jrn_def_type, jrn_def_code) VALUES (1, 'Financier', '5* ', '5*', '3,2,4', '3,2,4', 5, 5, false, NULL, 'FIN', 'FIN-01'); INSERT INTO jrn_def (jrn_def_id, jrn_def_name, jrn_def_class_deb, jrn_def_class_cred, jrn_def_fiche_deb, jrn_def_fiche_cred, jrn_deb_max_line, jrn_cred_max_line, jrn_def_ech, jrn_def_ech_lib, jrn_def_type, jrn_def_code) VALUES (3, 'Achat', '6*', '4*', '5', '4', 1, 3, true, 'échéance', 'ACH', 'ACH-01'); INSERT INTO jrn_def (jrn_def_id, jrn_def_name, jrn_def_class_deb, jrn_def_class_cred, jrn_def_fiche_deb, jrn_def_fiche_cred, jrn_deb_max_line, jrn_cred_max_line, jrn_def_ech, jrn_def_ech_lib, jrn_def_type, jrn_def_code) VALUES (2, 'Vente', '4*', '7*', '2', '6', 2, 1, true, 'échéance', 'VEN', 'VEN-01'); @@ -1103,7 +1103,7 @@ INSERT INTO jrn_def (jrn_def_id, jrn_def_name, jrn_def_class_deb, jrn_def_class_ INSERT INTO jrn_type (jrn_type_id, jrn_desc) VALUES ('FIN', 'Financier'); INSERT INTO jrn_type (jrn_type_id, jrn_desc) VALUES ('VEN', 'Vente'); INSERT INTO jrn_type (jrn_type_id, jrn_desc) VALUES ('ACH', 'Achat'); -INSERT INTO jrn_type (jrn_type_id, jrn_desc) VALUES ('OD ', 'Opérations Diverses'); +INSERT INTO jrn_type (jrn_type_id, jrn_desc) VALUES ('ODS', 'Opérations Diverses'); -- diff --git a/html/admin/sql/mod2/data.sql b/html/admin/sql/mod2/data.sql index 6ed5d986d..31e2250cf 100644 --- a/html/admin/sql/mod2/data.sql +++ b/html/admin/sql/mod2/data.sql @@ -709,8 +709,8 @@ INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_ INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_jrn_type) VALUES (14, 'Voir Impayés', 'Voir toutes les factures non payées', 'user_jrn.php', 'action=voir_jrn_non_paye', 'FR', 'ACH'); INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_jrn_type) VALUES (20, 'Nouveau', 'Encode un nouvel achat (matériel, marchandises, services et biens divers)', 'user_jrn.php', 'action=new&blank', 'FR', 'FIN'); INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_jrn_type) VALUES (22, 'Voir', 'Voir toutes les factures', 'user_jrn.php', 'action=voir_jrn', 'FR', 'FIN'); -INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_jrn_type) VALUES (30, 'Nouveau', NULL, 'user_jrn.php', 'action=new&blank', 'FR', 'OD '); -INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_jrn_type) VALUES (32, 'Voir', 'Voir toutes les factures', 'user_jrn.php', 'action=voir_jrn', 'FR', 'OD '); +INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_jrn_type) VALUES (30, 'Nouveau', NULL, 'user_jrn.php', 'action=new&blank', 'FR', 'ODS'); +INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_jrn_type) VALUES (32, 'Voir', 'Voir toutes les factures', 'user_jrn.php', 'action=voir_jrn', 'FR', 'ODS'); INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_jrn_type) VALUES (40, 'Soldes', 'Voir les soldes des comptes en banques', 'user_jrn.php', 'action=solde', 'FR', 'FIN'); @@ -718,7 +718,7 @@ INSERT INTO jrn_action (ja_id, ja_name, ja_desc, ja_url, ja_action, ja_lang, ja_ -- Data for Name: jrn_def; Type: TABLE DATA; Schema: public; Owner: phpcompta -- -INSERT INTO jrn_def (jrn_def_id, jrn_def_name, jrn_def_class_deb, jrn_def_class_cred, jrn_def_fiche_deb, jrn_def_fiche_cred, jrn_deb_max_line, jrn_cred_max_line, jrn_def_ech, jrn_def_ech_lib, jrn_def_type, jrn_def_code) VALUES (4, 'Opération Diverses', NULL, NULL, NULL, NULL, 5, 5, false, NULL, 'OD ', 'OD-01'); +INSERT INTO jrn_def (jrn_def_id, jrn_def_name, jrn_def_class_deb, jrn_def_class_cred, jrn_def_fiche_deb, jrn_def_fiche_cred, jrn_deb_max_line, jrn_cred_max_line, jrn_def_ech, jrn_def_ech_lib, jrn_def_type, jrn_def_code) VALUES (4, 'Opération Diverses', NULL, NULL, NULL, NULL, 5, 5, false, NULL, 'ODS', 'ODS-01'); INSERT INTO jrn_def (jrn_def_id, jrn_def_name, jrn_def_class_deb, jrn_def_class_cred, jrn_def_fiche_deb, jrn_def_fiche_cred, jrn_deb_max_line, jrn_cred_max_line, jrn_def_ech, jrn_def_ech_lib, jrn_def_type, jrn_def_code) VALUES (1, 'Financier', '5* ', '5*', '3,2,4', '3,2,4', 5, 5, false, NULL, 'FIN', 'FIN-01'); INSERT INTO jrn_def (jrn_def_id, jrn_def_name, jrn_def_class_deb, jrn_def_class_cred, jrn_def_fiche_deb, jrn_def_fiche_cred, jrn_deb_max_line, jrn_cred_max_line, jrn_def_ech, jrn_def_ech_lib, jrn_def_type, jrn_def_code) VALUES (3, 'Achat', '6*', '4*', '5', '4', 1, 3, true, 'échéance', 'ACH', 'ACH-01'); INSERT INTO jrn_def (jrn_def_id, jrn_def_name, jrn_def_class_deb, jrn_def_class_cred, jrn_def_fiche_deb, jrn_def_fiche_cred, jrn_deb_max_line, jrn_cred_max_line, jrn_def_ech, jrn_def_ech_lib, jrn_def_type, jrn_def_code) VALUES (2, 'Vente', '4*', '7*', '2', '6', 2, 1, true, 'échéance', 'VEN', 'VEN-01'); @@ -737,7 +737,7 @@ INSERT INTO jrn_def (jrn_def_id, jrn_def_name, jrn_def_class_deb, jrn_def_class_ INSERT INTO jrn_type (jrn_type_id, jrn_desc) VALUES ('FIN', 'Financier'); INSERT INTO jrn_type (jrn_type_id, jrn_desc) VALUES ('VEN', 'Vente'); INSERT INTO jrn_type (jrn_type_id, jrn_desc) VALUES ('ACH', 'Achat'); -INSERT INTO jrn_type (jrn_type_id, jrn_desc) VALUES ('OD ', 'Opérations Diverses'); +INSERT INTO jrn_type (jrn_type_id, jrn_desc) VALUES ('ODS', 'Opérations Diverses'); -- diff --git a/html/admin/sql/patch/upgrade30.sql b/html/admin/sql/patch/upgrade30.sql new file mode 100644 index 000000000..cc11100b9 --- /dev/null +++ b/html/admin/sql/patch/upgrade30.sql @@ -0,0 +1,15 @@ +begin ; +alter table jrn_action drop constraint "$1"; +alter table jrn_def drop constraint "$1"; + +update jrn_action set ja_jrn_type='ODS' where ja_jrn_type='OD '; +update jrn_def set jrn_def_type='ODS' where jrn_def_type = 'OD '; +update jrn_type set jrn_type_id='ODS' where jrn_type_id ='OD '; + +alter table jrn_action add constraint "$1" foreign key (ja_jrn_type) references jrn_type(jrn_type_id); + +alter table jrn_def add constraint "$1" FOREIGN KEY (jrn_def_type) REFERENCES jrn_type(jrn_type_id); +update version set val=31; +commit; + +commit; diff --git a/html/annulation.php b/html/annulation.php index 20de97043..2fd5883f0 100644 --- a/html/annulation.php +++ b/html/annulation.php @@ -71,6 +71,10 @@ if ( isset ($_POST['annul']) ) {

Confirmation


+

Attention: l'effacement d'une opération peut rompre la séquence de la numérotation des factures surtout celles générées automatiquement, soyez très prudent quand vous effacez. La pièce jointe sera elle aussi effacée. + +

+

Voulez-vous vraiment annuler cette information soit par une remise à zéro des montants soit par son écriture inverse ? @@ -104,7 +108,7 @@ return; // Test if date is valid if ( isDate ($e_op_date) == null ) { - $msg='Invalid Date'; + $msg=' Date non valide'; echo ""; // set an incorrect pid to get out from here $p_id=-1; @@ -117,18 +121,23 @@ if ($p_id != -1 ) { // A // Periode fermée if ( PeriodeClosed ($cn,$userPref)=='t' ) { - $msg="Votre periode par defaut est fermee, changez vos preferences"; + $msg="Votre periode par defaut est fermee, changez vos préférences"; echo_error($msg); echo ""; // set an incorrect pid to get out from here $p_id=-1; } + if ( $p_id != -1 ) { //B // Test whether date of the operation is in a closed periode // get the period_id $period_id=getPeriodeFromDate($cn,$e_op_date); // Check the period_id - if ( PeriodeClosed($cn,$period_id) == 't' ){ + if ( PeriodeClosed($cn,$period_id) == 't' ) + { + try + { + // if the operation is in a closed or centralized period // the operation is voided thanks the opposite operation StartSql($cn); @@ -146,49 +155,98 @@ if ($p_id != -1 ) { // A from jrn where jr_grpt_id=".$_POST['p_id']; - $Res=ExecSql($cn,$sql); + $Res=ExecSql($cn,$sql,false); // Check return code - if ( $Res == false ) { Rollback($cn);exit(-1);} + if ( $Res == false) + throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]")); + // Make also the change into jrnx $sql= "insert into jrnx ( j_date,j_montant,j_poste,j_grpt, - j_jrn_def,j_debit,j_text,j_internal,j_tech_user,j_tech_per + j_jrn_def,j_debit,j_text,j_internal,j_tech_user,j_tech_per,j_qcode ) select now(),j_montant,j_poste,$grp_new, j_jrn_def,not (j_debit),j_text,'$p_internal','".$User->id."', - $userPref + $userPref,j_qcode from jrnx where j_grpt=".$_POST['p_id']; - $Res=ExecSql($cn,$sql); + $Res=ExecSql($cn,$sql,false); // Check return code - if ( $Res == false ) { Rollback($cn);exit(-1);} + 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_grpt_id=".$_POST['p_id']; - $Res=ExecSql($cn,$sql); + $Res=ExecSql($cn,$sql,false); // Check return code - if ( $Res == false ) { Rollback($cn);exit(-1);} + if ( $Res == false) + throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]")); + + + // Set the record to A (annulate) in quant_sold and quand_purchase + + + $Res=ExecSql($cn,"update quant_sold set ". + " qs_valid='A' where qs_internal='".$l_array['jr_internal']."'", + false); + + if ( $Res == false) + throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]")); + + + $Res=ExecSql($cn,"update quant_purchase set ". + " qp_valid='A' where qp_internal='".$l_array['jr_internal']."'", + false); + if ( $Res == false) + throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]")); + + + + + // Add a "concerned operation to bound these op.together // $Res=InsertRapt($cn,$seq,$l_array['jr_id']); // Check return code - if ( $Res == false ) { Rollback($cn);exit(-1);} + 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=".$_POST['p_id'].")"; - $Res=ExecSql($cn,$sql); + $Res=ExecSql($cn,$sql,false); // Check return code - if ( $Res == false ) { Rollback($cn);exit(-1);} + if ( $Res == false) + throw (new Exception(__FILE__.__LINE__."sql a echoue [ $sql ]")); + } + catch (Exception $e) + { + Rollback($cn); + $msg="Désolé mais il n a pas été possible d'annuler ". + "cette opération"; + echo ""; + + echo ''. + 'Erreur : '. + __FILE__.':'.__LINE__.' '. + $e->getMessage(); + echo '

'; + echo 'Postez ce message sur '. + ''. + 'le forum de www.phpcompta.org '. + '

'; + $p_id=-1; + exit(-1); + } Commit($cn); // close the window - echo '

Opération Annulée

'; + echo '

Opération Annulée

'; ?> "; + + echo ''. + 'Erreur : '. + __FILE__.':'.__LINE__.' '. + $e->getMessage(); + echo '

'; + echo 'Postez ce message sur '. + ''. + 'le forum de www.phpcompta.org '. + '

'; + $p_id=-1; + exit(-1); + } + Commit($cn); echo '

Opération Annulée

'; ?> @@ -282,7 +402,7 @@ if ( $a != null ) { echo ' - + '; diff --git a/html/caisse.php b/html/caisse.php new file mode 100644 index 000000000..0d40b9667 --- /dev/null +++ b/html/caisse.php @@ -0,0 +1,54 @@ + + +'; + +for ($i=0;$i<10;$i++) + { + echo 'montant '; + echo ''; + echo '
'; + } + + + +for ($i=0; $i < 5;$i++) + { + echo ''; + } +?> + + + diff --git a/html/commercial.php b/html/commercial.php index 998b80ce1..9682b8f89 100644 --- a/html/commercial.php +++ b/html/commercial.php @@ -29,7 +29,7 @@ include_once ("ac_common.php"); require_once("constant.php"); include_once ("postgres.php"); - +echo JS_AJAX_FICHE; if ( isset ($_REQUEST['dos'] ) ) { $_SESSION['g_dossier']=$_REQUEST['dos']; @@ -65,7 +65,7 @@ if ( isset ( $_POST['p_size']) ) { html_page_start($_SESSION['g_theme'],"","richtext.js"); if ( ! isset ( $_SESSION['g_dossier'] ) ) { - echo "You must choose a Dossier "; + echo "Vous devez choisir un dossier "; exit -2; } @@ -77,6 +77,8 @@ echo '
+ + @@ -107,6 +109,8 @@ echo '
'; $cn=DbConnect($_SESSION['g_dossier']); $User->AccessRequest($cn,SEC_GESTION); echo JS_VIEW_JRN_MODIFY; +echo JS_AJAX_FICHE; + //----------------------------------------------------- // p_action == pref //----------------------------------------------------- @@ -138,7 +142,6 @@ if ( $p_action == 'suivi_courrier') //----------------------------------------------------- if ( $p_action == "facture" ) { - echo JS_AJAX_FICHE; require_once("facture.inc.php"); } //----------------------------------------------------- @@ -151,7 +154,6 @@ if ( $p_action == 'contact') // Expense if ( $p_action == 'depense') { - echo JS_AJAX_FICHE; require_once("depense.inc.php"); } //----------------------------------------------------- @@ -164,7 +166,6 @@ if ( $p_action == 'admin') // Banque if ( $p_action == 'bank') { - echo JS_AJAX_FICHE; require_once("bank.inc.php"); } //----------------------------------------------------- diff --git a/html/comptanalytic.php b/html/comptanalytic.php new file mode 100644 index 000000000..b3ebce944 --- /dev/null +++ b/html/comptanalytic.php @@ -0,0 +1,114 @@ +Check(); + + + +$g_name=GetDossierName($_SESSION['g_dossier']); +$_SESSION["g_name"]=$g_name; +html_page_start($_SESSION['g_theme']); + +//----------------------------------------------------------------- +//Header +echo '
'; +echo "

Analytique ".$_SESSION['g_name']." "; +echo '
+ + + + + + +

'; +//----------------------------------------------------------------- + +$def=-1; +if ( isset ($_REQUEST['p_action'])) + { + switch ($_REQUEST['p_action']) + { + case 'ca_pa': + $def=0; + break; + case 'ca_od': + $def=1; + break; + case 'ca_imp': + $def=2; + break; + } + } +echo ShowItem(array( + array('?p_action=ca_pa','Plan Analytique',"Plan Analytique",0), + array('?p_action=ca_od','Opérations Diverses',"Permet d'enregistrer des opérations sur la compta analytique",1), + array('?p_action=ca_imp','Impression',"impression de rapport",2) + ), + 'H',"mtitle","mtitle",$def,' width="100%"'); +echo '
'; + +if ( !isset($_REQUEST['p_action'])) + exit(); + +//--------------------------------------------------------------------------- +// p_action +//--------------------------------------------------------------------------- +// Plan Analytique +if ($_REQUEST['p_action'] == 'ca_pa' ) + { + require_once('ca_pa.inc.php'); + exit(); + } + +// Operations Diverses +if ($_REQUEST['p_action'] == 'ca_od' ) + { + require_once('ca_od.inc.php'); + exit(); + } + +// Impression +if ($_REQUEST['p_action'] == 'ca_imp' ) + { + require_once('ca_imp.inc.php'); + exit(); + } diff --git a/html/ecrit_ouv.php b/html/ecrit_ouv.php index 707e25e7c..3563c49d3 100644 --- a/html/ecrit_ouv.php +++ b/html/ecrit_ouv.php @@ -76,7 +76,8 @@ if ( isset ($_GET['export'])) { echo ""; exit(0); } -//----------------------------------------------------- IMPORT //////////////////////////////////////////// +//----------------------------------------------------- IMPORT +//////////////////////////////////////////// if ( isset ($_GET['import'])) { // show a form to upload the file // that form will parse the file, create an ods operation @@ -87,7 +88,7 @@ if ( isset ($_GET['import'])) {
name='p_jrn'; $x->value=$ods; diff --git a/html/fid.php b/html/fid.php index 81811b9ac..60b0db951 100644 --- a/html/fid.php +++ b/html/fid.php @@ -1,28 +1,61 @@ '; + $a.=""; + $a.="".$name.""; + $a.="".$sell.""; + $a.="".$buy.""; + $a.="".$tva_id.""; + $a.=""; + } else $a="not connected"; -echo_debug("fid.php",__LINE__,"Answer is $a"); +echo_debug("fid.php",__LINE__,"Answer is \n $a"); + print $a; -?> \ No newline at end of file +?> diff --git a/html/image/undefined.png b/html/image/undefined.png new file mode 100644 index 000000000..eea4fc777 Binary files /dev/null and b/html/image/undefined.png differ diff --git a/html/import.php b/html/import.php index ac2092051..8cc6b8c54 100644 --- a/html/import.php +++ b/html/import.php @@ -55,7 +55,7 @@ $cn=DbConnect($_SESSION['g_dossier']); echo ShowMenuAdvanced("import.php"); $User->AccessRequest($cn,IMP_BQE); - +echo JS_AJAX_FICHE; echo ''; diff --git a/html/index.php b/html/index.php index e4120d65f..0b4dd6f53 100644 --- a/html/index.php +++ b/html/index.php @@ -76,7 +76,7 @@ BODY { -Version 2.3.3-cvs +Version 3.0.0

Il est conseillé de ne PAS utiliser Internet Explorer.

diff --git a/html/jrn_csv.php b/html/jrn_csv.php index 8d2f25632..2309fc03b 100644 --- a/html/jrn_csv.php +++ b/html/jrn_csv.php @@ -47,7 +47,7 @@ if ( $User->CheckAction($cn,IMP) == 0 || $Jrn=new jrn($cn,$_GET['jrn_id']); $Jrn->GetName(); -$jrn_type=$Jrn->GetType(); +$jrn_type=$Jrn->get_type(); // Detailled printing //--- if ( $_GET['p_simple'] == 0 ) @@ -66,8 +66,9 @@ if ( $_GET['p_simple'] == 0 ) $desc=str_replace("","",$desc); $desc=str_replace("","",$desc); $desc=str_replace('"',"'",$desc); + $desc=str_replace(";",",",$desc); - printf("\"%s\"\t\"%s\"\t\"%s\"\t\"%s\"\t\"%s\"\t%8.4f\t%8.4f\n", + printf("\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";%8.4f;%8.4f\n", $op['j_id'], $op['internal'], $op['j_date'], @@ -89,11 +90,11 @@ if ( $_GET['p_simple'] == 0 ) //----------------------------------------------------- if ( $jrn_type == 'ODS' || $jrn_type == 'FIN' || $jrn_type=='GL') { - printf ('" operation; "'. - '"Date;"'. - '"commentaire;"'. - '"internal;"'. - '"montant;"'. + printf ('" operation";'. + '"Date";'. + '"commentaire";'. + '"internal";'. + '"montant";'. "\r\n"); foreach ($Row as $line) diff --git a/html/jrn_pdf.php b/html/jrn_pdf.php index ec352b093..956a0379b 100644 --- a/html/jrn_pdf.php +++ b/html/jrn_pdf.php @@ -65,13 +65,13 @@ $ret=""; // filter : 0 for Grand Livre otherwise 1 $filter=( $Jrn->id == 0)?0:1; -$jrn_type=$Jrn->GetType(); +$jrn_type=$Jrn->get_type(); echo_debug('jrn_pdf',__LINE__,'Jrn type '.$jrn_type); echo_debug('jrn_pdf',__LINE__,'p_simple = '.$_REQUEST['p_simple']); //---------------------------------------------------------------------- // Detailled Printing //--------------------------------------------------------------------- -if ( $Jrn->id==0 || $jrn_type=='FIN' || $jrn_type=='OD ' || $_REQUEST['p_simple']== 0 ) +if ( $Jrn->id==0 || $jrn_type=='FIN' || $jrn_type=='ODS' || $_REQUEST['p_simple']== 0 ) { $pdf=& new Cezpdf("A4"); $pdf->selectFont('./addon/fonts/Helvetica.afm'); diff --git a/html/jrn_search.php b/html/jrn_search.php index a05b63c95..1ac0a589c 100644 --- a/html/jrn_search.php +++ b/html/jrn_search.php @@ -93,10 +93,14 @@ if ( isset ($_GET["search"]) ) { $part=" and "; } - -$condition=$c_comment.$c_montant.$c_date.$c_internal; -echo_debug('jrn_search.php',__LINE__,"condition = $condition"); -} + $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; + echo_debug('jrn_search.php',__LINE__,"condition = $condition"); + } $condition=$condition." ".$part; // If the usr is admin he has all right @@ -109,6 +113,11 @@ if ( $User->admin != 1 ) {

'; +if (isset($paid)) + echo '
Uniquement les non opérations non payées
'; + else + echo '
Toutes les opérations
'; + echo ''; echo ''; if ( ! isset ($p_date)) $p_date=""; @@ -141,7 +150,7 @@ echo '
'; // if a search is asked otherwise don't show all the rows if ( isset ($_GET["search"]) ) { $sql="select j_id,to_char(j_date,'DD.MM.YYYY') as j_date, - j_montant,j_poste,j_debit,j_tech_per,jr_id,jr_comment,j_grpt,pcm_lib,jr_internal from jrnx inner join + j_montant,j_poste,j_debit,j_tech_per,jr_id,jr_comment,j_grpt,pcm_lib,jr_internal,jr_rapt from jrnx inner join jrn on jr_grpt_id=j_grpt inner join tmp_pcmn on j_poste=pcm_val ". " inner join user_sec_jrn on uj_jrn_id=j_jrn_def". $condition." order by jr_date,jr_id,j_debit desc"; @@ -194,7 +203,12 @@ if ( isset ($_GET["search"]) ) { echo $l_line['jr_internal']; echo ""; $l_id=$l_line['j_grpt']; - echo '
'; + if ( $l_line['jr_rapt'] == 'paid') + $lpay=" (Payé) "; + else + $lpay=""; + + echo ''; } if ( $l_line['j_debit'] == 't' ) { echo ''; diff --git a/html/js/ajax_fiche.js b/html/js/ajax_fiche.js index 321aada41..70ca2c983 100644 --- a/html/js/ajax_fiche.js +++ b/html/js/ajax_fiche.js @@ -24,6 +24,42 @@ * info from fiche * */ + +/*!\brief this function fills the data from fid.php, + * \param p_ctl the ctrl to fill + * \param p_deb if debit of credit + * \param p_jrn the ledger + */ +function trim(s) { + return s.replace(/^\s+/, '').replace(/\s+$/, ''); +} +/*!\brief clean the row (the label, price and vat) + * \param p_ctl the calling ctrl + */ +function clean_Fid(p_ctl) +{ + nSell=p_ctl+"_sell"; + nBuy=p_ctl+"_buy"; + nTva_id=p_ctl+"_tva_id"; + + if ( document.getElementById(nSell) != null ) { + document.getElementById(nSell).value=""; + } + if ( document.getElementById(nBuy) != null ) { + document.getElementById(nBuy).value=""; + } + + if ( document.getElementById(nTva_id) != null ) { + document.getElementById(nTva_id).value=""; + } + +} + +/*!\brief this function fills the data from fid.php, + * \param p_ctl the ctrl to fill + * \param p_deb if debit of credit + * \param p_jrn the ledger + */ function ajaxFid(p_ctl,p_deb,p_jrn){ var ajaxRequest; // The variable that makes Ajax possible! ; @@ -47,49 +83,61 @@ function ajaxFid(p_ctl,p_deb,p_jrn){ // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ - resp=String(ajaxRequest.responseText); - - a_resp=resp.split("/"); + if ( ajaxRequest.status == 200 ) { + + xmldoc = ajaxRequest.responseXML.documentElement; + data = xmldoc.getElementsByTagName('name'); + + label = data[0].firstChild.nodeValue; + sell = xmldoc.getElementsByTagName('sell')[0].firstChild.nodeValue; + buy = xmldoc.getElementsByTagName('buy')[0].firstChild.nodeValue; + tva_id = xmldoc.getElementsByTagName('tva_id')[0].firstChild.nodeValue; + toSet=p_ctl+"_label"; - if ( resp.length == 0 ) + + if ( trim(label) == "" ) { var ctl_toSet=document.getElementById(toSet); ctl_toSet.innerHTML="Fiche inconnue"; ctl_toSet.style.color='red'; + clean_Fid(p_ctl); } else { var ctl_toSet=document.getElementById(toSet); ctl_toSet.style.color='black'; - ctl_toSet.innerHTML=a_resp[0]; + ctl_toSet.innerHTML=label; nSell=p_ctl+"_sell"; nBuy=p_ctl+"_buy"; nTva_id=p_ctl+"_tva_id"; if ( document.getElementById(nSell) != null ) { - document.getElementById(nSell).value=a_resp[1]; + document.getElementById(nSell).value=sell; } if ( document.getElementById(nBuy) != null ) { - document.getElementById(nBuy).value=a_resp[2]; + document.getElementById(nBuy).value=buy; } if ( document.getElementById(nTva_id) != null ) { - document.getElementById(nTva_id).value=a_resp[3]; + document.getElementById(nTva_id).value=tva_id; } } + } } } if (document.getElementById(p_ctl).value.length == 0 ) { var toSet=p_ctl+"_label"; var ctl_toSet=document.getElementById(toSet); ctl_toSet.innerHTML=""; + // clean other fields + clean_Fid(p_ctl); } else { queryString="?FID="+document.getElementById(p_ctl).value; queryString=queryString+"&d="+p_deb+"&j="+p_jrn; - + ajaxRequest.open("GET", "fid.php"+queryString, true); ajaxRequest.send(null); } diff --git a/html/js/compute.js b/html/js/compute.js new file mode 100644 index 000000000..94feb2ecc --- /dev/null +++ b/html/js/compute.js @@ -0,0 +1,74 @@ +/* + * This file is part of PhpCompta. + * + * PhpCompta is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * PhpCompta is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with PhpCompta; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +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=document.getElementById('nb_item').value; + + for (var i=0;i + +'; - $r.=UpdateJrn($cn,$p_id); - $r.=''; - $r.="
"; - $r.="
"; - $r.="
"; - $r.=''; - $r.="      "; - $r.=''; - $r.=''; -// echo '
'; - echo $r; -// echo '
'; - } + echo_debug(__FILE__.":".__LINE__."Selected view is $view"); + + + $view='

Erreur vue inconnue

'; + + // show the detailled operation + if ( $p_view == 'S' ) + $view='
'; + else + $view=''; + + if ( $p_view == 'S' ) + $view.='
".$all->IOValue("p_Commune",$my->MY_COMMUNE,"Commune").""; echo "".$all->IOValue("p_pays",$my->MY_PAYS,"Pays").""; echo "".$all->IOValue("p_tva",$my->MY_TVA,"Numéro de Tva").""; - + echo "".$compta->IOValue("p_compta",$array,"Utilisation de la compta. analytique").""; echo "
'.$l_line['jr_comment'].'
'.$l_line['jr_comment'].$lpay.'
"; $submit=new widget("submit"); echo $submit->Submit("record_company","Enregistre"); diff --git a/html/poste_csv.php b/html/poste_csv.php index 2514611a7..e1dbb9271 100644 --- a/html/poste_csv.php +++ b/html/poste_csv.php @@ -55,7 +55,7 @@ foreach ($a_poste as $pos) if ( count($Poste->row ) == 0 ) continue; - echo '"Poste;"'. + echo '"Poste";'. "\"Code interne\";". "\"Date\";". "\"Description\";". diff --git a/html/poste_search.php b/html/poste_search.php index 00855643c..1ba85b0b1 100644 --- a/html/poste_search.php +++ b/html/poste_search.php @@ -23,7 +23,7 @@ * \brief Search a account in a popup window */ include_once ("ac_common.php"); -html_page_start($_SESSION['g_theme'],"onLoad='window.focus();'"); +html_page_start($_SESSION['g_theme'],'onLoad="window.focus();"'); include_once ("postgres.php"); include_once("jrn.php"); /* Admin. Dossier */ @@ -44,37 +44,31 @@ $c_class=""; $condition=""; $cn=DbConnect($_SESSION['g_dossier']); -if ( isset($_POST['search']) ) { +if ( isset($_GET['search']) ) { $c1=0; - foreach( $_POST as $key=>$element){ + foreach( $_GET as $key=>$element){ ${"$key"}=$element; } + $condition=""; if ( strlen(trim($p_comment)) != 0 ) { - $c_comment=" where upper(pcm_lib) like upper('%$p_comment%')"; - $c1=1; + $condition=" where (upper(pcm_lib) like upper('%$p_comment%') or ". + " pcm_val::text like '$p_comment%') "; } - if ( strlen(trim($p_class)) != 0 && - (string) $p_class == (int)(string) $p_class) { - if ($c1==1) - $clause=" and "; - else - $clause = " where "; - $c_class=sprintf(" %s pcm_val::text like '%s%%'",$clause,$p_class); - } - - - $condition=$c_comment.$c_class; } $url=""; -// Filter ??? -if ( isset($_GET['filter'])) { + +//-------------------------------------------------- +// Filter defined in the ledger's parameter +// +if ( isset($_GET['filter']) && $_GET['filter'] != 'all') { $url="?filter=1"; // There is a filter, the value of the filter is the journal id, we // have to find what account are available $SqlCred=""; + // Load the property - $l_line=GetJrnProp($cn,$_GET['p_jrn']); + $l_line=GetJrnProp($_SESSION['g_dossier'],$_GET['p_jrn']); if ( strlen(trim ($l_line['jrn_def_class_cred']) ) > 0 ) { $valid_cred=split(" ",$l_line['jrn_def_class_cred']); @@ -117,29 +111,29 @@ if ( isset($_GET['filter'])) { $condition .= ($SqlCred=="")?"":" and ( ".substr($SqlCred,0,strlen($SqlCred)-2)." ) "; } }// if (isset($_GET['filter'])) + + +// Control to update in the calling doc. if ( isset($_GET['p_ctl'])) { $p_ctl=$_GET['p_ctl']; } -if ( isset($_POST['p_ctl'])) { - $p_ctl=$_POST['p_ctl']; -} + echo_debug('poste_search.php',__LINE__,"condition = $condition"); -echo ''; +echo ''; if ( isset($p_ctl) ) { if ($p_ctl != 'not') echo ''; } echo ''; echo ''; -echo ''; +/* echo ''; */ +/* if ( ! isset ($p_class) ) $p_class=""; */ +/* $opt=" "; */ +/* echo ''; */ -if ( ! isset ($p_class) ) $p_class=""; -$opt=" "; -echo ''; - -echo ''; +echo ''; echo ''; if ( ! isset ($p_comment) ) $p_comment=""; echo ''; @@ -148,8 +142,8 @@ echo ''; echo ''; // if request search -if ( isset($_POST['search']) or isset($_GET['filter']) ) { - $Res=ExecSql($cn,"select * from tmp_pcmn $condition order by pcm_val::text"); +if ( isset($_GET['search']) or isset($_GET['filter']) ) { + $Res=ExecSql($cn,"select pcm_val,pcm_lib from tmp_pcmn $condition order by pcm_val::text"); $MaxLine=pg_NumRows($Res); if ( $MaxLine==0) { @@ -163,9 +157,11 @@ if ( isset($_POST['search']) or isset($_GET['filter']) ) { $l_line=pg_fetch_array($Res,$i); echo ""; // if p_ctl is set we need to be able to return the value - if (isset($p_ctl) and $p_ctl != 'not' ){ + if (isset($p_ctl) && $p_ctl != 'not' ){ echo ''; } echo ' - + diff --git a/html/quick_code_csv.php b/html/quick_code_csv.php index a647c851b..1e966e6cb 100644 --- a/html/quick_code_csv.php +++ b/html/quick_code_csv.php @@ -46,7 +46,7 @@ if ( count($Fiche->row ) == 0 ) echo "Aucune donnée"; return; } -echo '"Qcode;"'. +echo '"Qcode";'. "\"Code interne\";". "\"Date\";". "\"Description\";". diff --git a/html/recherche.php b/html/recherche.php index 3afdf5d46..6ea569218 100644 --- a/html/recherche.php +++ b/html/recherche.php @@ -33,6 +33,7 @@ if ( ! isset ( $_SESSION['g_dossier'] ) ) { echo "You must choose a Dossier "; exit -2; } + include_once ("postgres.php"); include_once ("check_priv.php"); /* Admin. Dossier */ @@ -54,6 +55,7 @@ echo ""; // Display search result //----------------------------------------------------- if ( isset ($_GET['viewsearch'])) { + // Navigation bar $step=$_SESSION['g_pagesize']; $page=(isset($_GET['offset']))?$_GET['page']:1; @@ -62,11 +64,15 @@ if ( isset ($_GET['viewsearch'])) { $array=null; else $array=$_GET; - + list($max_line,$a)=ListJrn($cn,0,"",$array,$offset,2); + $bar=jrn_navigation_bar($offset,$max_line,$step,$page); + echo '
'; + + echo $bar; echo $a; echo $bar; diff --git a/html/style.css b/html/style.css index 4c4d97642..e368f0500 100644 --- a/html/style.css +++ b/html/style.css @@ -1,306 +1,431 @@ /* */ + +/*input{ + font-size:0.9em; +} +*/ +/* */ diff --git a/html/test.php b/html/test.php index 9740e78dc..68740242b 100644 --- a/html/test.php +++ b/html/test.php @@ -11,7 +11,7 @@ h2.error { } --> -__LINE__ test has failed !!!"); +echo __FILE__.":".__LINE__; -} -if ( ($Res=ExecSql($a,"select * from ac_users") ) == false ) { - exit ("

__LINE__ test has failed !!!

"); -} else - print "Connect to database success
"; +require_once('class_plananalytic.php'); +$cn=DbConnect(14); +echo "

Plan analytique : test

"; +echo "clean"; +ExecSql($cn,"delete from plan_analytique"); -// Verify some PHP parameters -// magic_quotes_gpc = Off -// magic_quotes_runtime = Off -// magic_quotes_sybase = Off -// include_path -// register_global -foreach (array('magic_quotes_gpc','magic_quotes_runtime') as $a) { - - if ( ini_get($a) == false ) print $a.': Ok
'; - else { - print ("

$a has a bad value !!!

"); - } - -} -if ( ereg("\.\.\/include",ini_get('include_path')) == false ) - print ("

include_path incorrect !!!".ini_get('include_path')."

"); - else - print 'include_path : ok ('.ini_get('include_path').')
'; - -echo "

Congratulation : Test successfull

"; -?> - +$p=new PlanAnalytic($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; + +echo "

get

"; +$p->get(); +var_dump($p); +echo "

Update

"; +$p->name="Update "; +$p->description="c'est changé"; +$p->update(); +$p->get; +var_dump($p); +echo "

get_list

"; +$a=$p->get_list(); +var_dump($a); +echo "

delete

"; +$p->delete(); + +//-------------------------------------------------------------------------------- +require_once("class_poste_analytic.php"); +$o=new Poste_Analytique($cn); +echo "

Poste_Analytique

"; +echo "

get_list

"; +$ee=$o->get_list(); + +//var_dump($ee); +echo "

Add some

"; +$o->pa_id=$pa_id; +$o->name="test1"; +$o->add(); + + +$o->name="test2"; +$o->add(); + +$o->name="test3"; +$o->add(); + +$o->name="test4"; +$o->add(); + +$o->name="test5"; +$o->add(); + +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(); diff --git a/html/user_jrn.php b/html/user_jrn.php index 60eb4461c..615928902 100644 --- a/html/user_jrn.php +++ b/html/user_jrn.php @@ -37,7 +37,8 @@ $User=new cl_user($cn); $User->Check(); html_page_start($User->theme, - "OnLoad=\"SetFocus('e_date',0); AttachEvent(document, 'keydown', HandleSubmit, true);\" "); + "OnLoad=\"SetFocus('e_date',0);checkTotal();\" ", + "js/compute.js"); // Check if dossier set if ( ! isset ( $_SESSION['g_dossier'] ) ) { @@ -95,7 +96,7 @@ echo JS_AJAX_FICHE; if ( $jrn_type=='VEN' ) require('user_action_ven.php'); if ( $jrn_type=='ACH' ) require('user_action_ach.php'); if ( $jrn_type=='FIN' ) require('user_action_fin.php'); - if ( $jrn_type=='OD' ) require('user_action_ods.php'); + if ( $jrn_type=='ODS' ) require('user_action_ods.php'); } else diff --git a/html/user_login.php b/html/user_login.php index 435a4bfa5..06f2757ce 100644 --- a/html/user_login.php +++ b/html/user_login.php @@ -1,5 +1,3 @@ - - Check(); html_page_start($_SESSION['g_theme']); include_once("user_menu.php"); -$priv=($User->admin==1)?"Administrator":"User"; +if ( isset ($_SESSION['g_dossier'])) + unset ($_SESSION['g_dossier']); -echo '
Welcome '.$User->first_name.' '. - $User->name.',

your are an '. $priv.'
Please Select your folder

'; +$priv=($User->admin==1)?"Administrateur":"Utilisateur"; + +echo '
Bienvenue '.$User->first_name.' '. + $User->name.',

Vous êtes un '. $priv.'
Selectionnez votre dossier

'; // Show default menu (preference,...) // If admin show everything otherwise only the available dossier diff --git a/html/user_pref.php b/html/user_pref.php index 54c12417c..237dc2c7f 100644 --- a/html/user_pref.php +++ b/html/user_pref.php @@ -28,16 +28,34 @@ include_once ("postgres.php"); /* Admin. Dossier */ $Rep=DbConnect(); include_once ("class_user.php"); -$cn=DbConnect($_SESSION['g_dossier']); + +$cn=DbConnect(); + +/* if the dossier is not set then we have to connect to the + * account_repository database + */ + +if ( isset ($_SESSION['g_dossier'])) + { + $cn=DbConnect($_SESSION['g_dossier']); + } +else + { + $cn=DbConnect(); + } + + $User=new cl_user($cn); $User->Check(); + // Met a jour le theme utilisateur (style) -if ( isset ( $_POST['style_user']) ) { - $User->update_global_pref('THEME',$_POST['style_user']); - $_SESSION['g_theme']=$_POST['style_user']; - -} - +if ( isset ( $_POST['style_user']) ) + { + $User->update_global_pref('THEME',$_POST['style_user']); + $_SESSION['g_theme']=$_POST['style_user']; + + } + html_page_start($_SESSION['g_theme']); // Met a jour le pagesize @@ -51,12 +69,18 @@ if ( isset ( $_POST['p_size']) ) { // comta style include_once ("user_menu.php"); -if ( isset ($_SESSION['g_dossier']) ) { - if ( $_SESSION['g_dossier'] != 0 ) -echo '
'; - -echo ShowMenuCompta($_SESSION['g_dossier']); - echo "
"; +if ( isset ($_SESSION['g_dossier']) ) + { + if ( $_SESSION['g_dossier'] != 0 ) + { + echo '
'; + echo ShowMenuCompta($_SESSION['g_dossier']); + 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 3ed783562..c3416ea24 100644 --- a/include/ac_common.php +++ b/include/ac_common.php @@ -43,7 +43,7 @@ function echo_error ($p_log, $p_line="", $p_message="") { fclose($fdebug); echo_debug($p_log,$p_line,$p_message); } - + /*! * \brief Compare 2 dates * \param p_date @@ -218,7 +218,7 @@ function NoAccess($js=0) * \brief Fix the problem with the quote char for the database * * \param $p_string - * + * \todo replace par pg_escape_string !!! * \return a string which won't let strange char for the database */ function FormatString($p_string) @@ -249,23 +249,32 @@ function ShowItem($p_array,$p_dir='V',$class="mtitle",$class_ref="mtitle",$defau foreach ($p_array as $all=>$href){ $title=""; if ( isset ($href[2] )) - $title=$href[2]; + $title=$href[2]; $ret.='
'; } } //direction Horizontal else if ( $p_dir == 'H' ) { + $ret.=""; foreach ($p_array as $all=>$href){ $title=""; + + $set="A"; if ( isset ($href[2] )) - $title=$href[2]; - if ( $default== $href[0]) { - $ret.=''; + $title=$href[2]; + + if ( isset($href[3])) + $set=$href[3]; + + if ( $default=== $href[0]||$set===$default ) { + + $ret.=''; } else { - $ret.=''; + $ret.=''; } + } $ret.=""; } diff --git a/include/action.inc.php b/include/action.inc.php index de618c071..fc0ec2a5d 100644 --- a/include/action.inc.php +++ b/include/action.inc.php @@ -52,13 +52,16 @@ function ShowActionList($cn,$retour,$h_url) $w=new widget('js_search_only'); $w->name='qcode'; $w->value=$qcode; - $w->label='Quick Code'; + $w->label='Quick Code1'; $w->extra='4,9,14,16,8'; $w->table=0; - $sp= new widget("span"); - - echo $sp->IOValue("qcode_label","",$qcode); echo $w->IOValue(); + + + $sp= new widget("span"); + echo $sp->IOValue("qcode_label","",$qcode); + + ?>
@@ -67,8 +70,6 @@ function ShowActionList($cn,$retour,$h_url) -
diff --git a/include/argenta_be.inc.php b/include/argenta_be.inc.php index 4e88ba24e..ddab17c45 100644 --- a/include/argenta_be.inc.php +++ b/include/argenta_be.inc.php @@ -99,10 +99,19 @@ echo "
"; '$p_bq_account', $p_jrn, 'n')"; - if ( ExecSql($p_cn,$Sql) == false ) + try { - Rollback($p_cn); break; + ExecSql($p_cn,$Sql); } + + + catch(Exception $e) + { + echo_debug(__FILE__.":".__LINE__." Erreur : ".$e->getCode." msg ".$e->getMessage); + rollback($p_cn); + break; + } + } // for ($c=0;$c<$num;$c++) $line++; } // file is read diff --git a/include/ca_imp.inc.php b/include/ca_imp.inc.php new file mode 100644 index 000000000..9d08fc545 --- /dev/null +++ b/include/ca_imp.inc.php @@ -0,0 +1,29 @@ +get_list(); +echo '
'; +echo '
Poste Comptable Commence par Poste Comptable Commence par Libellé Libellé ou poste comptable contient
'; - echo ''; + $slabel=FormatString($l_line['pcm_lib']); + echo ''; echo ''; diff --git a/html/priv_user.php b/html/priv_user.php index 3f0036832..217fc9b58 100644 --- a/html/priv_user.php +++ b/html/priv_user.php @@ -222,7 +222,9 @@ foreach ( $Dossier as $rDossier) {
+ +
'.$href[1].'
'.$href[1].''.$href[1].''.$href[1].''.$href[1].'
'; +echo ''; +if ( isset ($_REQUEST['pa_id'])){ + $pa_id=$_REQUEST['pa_id']; + } else $pa_id=-1; +foreach ($m as $line) +{ + if ( $line['id'] == $pa_id ) { + echo ''; + + } else { + echo ''; + } +} +echo ''; +echo '
'. + $line['name']. + ''. + ' '. + $line['name']. + ''.'
'; +echo '
'; +if ( ! isset($_REQUEST['pa_id']) ) + exit(); +//---------------------------------------------------------------------- +// show the left menu +//---------------------------------------------------------------------- +echo ' +'; +//---------------------------------------------------------------------- +// the pa_id is set +// +//---------------------------------------------------------------------- +if ( isset($_GET['see'])) { + // Show the list for the period + // and exit + //----------------------------- + $a=new operation($cn); + $a->pa_id=$_REQUEST['pa_id']; + echo '
'; + echo $a->get_list(); + echo '
'; + exit(); + } +if ( isset($_POST['save'])) { + // record the operation and exit + // and exit + //----------------------------- + echo '
'. + 'Opération sauvée'; + $a=new groupop($cn); + $a->pa_id=$_POST['pa_id']; + $a->from_POST(); + $a->save(); + echo $a->show(); + echo '
'; + exit(); + } + +if ( isset($_GET['new'])) { + //show the form for entering a new operation + //------------------------------------------ + $a=new groupop($cn); + $a->pa_id=$_GET['pa_id']; + $wSubmit=new widget('hidden',"p_action","ca_od"); + $wSubmit->table=0; + echo '
'; + echo ''; + echo $wSubmit->IOValue(); + echo $a->form(); + echo $wSubmit->Submit("save","Sauver"); + echo ''; + + echo '
'; + exit(); + } + +?> +
diff --git a/include/ca_pa.inc.php b/include/ca_pa.inc.php new file mode 100644 index 000000000..6f562ee67 --- /dev/null +++ b/include/ca_pa.inc.php @@ -0,0 +1,299 @@ +isAppend() == true) + { + $ret.= '
'; + $ret.= '

Nouveau plan

'; + $ret.= '
'; + $ret.= $new->form(); + $wSa=new widget("HIDDEN","","sa","pa_write"); + $wSa->value="pa_write"; + $ret.= $wSa->IOValue(); + $ret.= $wAction->IOValue(); + $ret.= $wSa->Submit("submit","Enregistre"); + $ret.= '
'; + $ret.= '
'; + } + else + { + $ret.= '
'. + '

'. + "Maximum de plan analytique est atteint". + "

"; + } + } + // Add + if ( $sa == "pa_write") + { + $new=new PlanAnalytic($cn); + + + if ( $new->isAppend() == false) + { + $ret.= '

'. + "Maximum de plan analytique est atteint". + "

"; + } + else + { + $new=new PlanAnalytic($cn); + $new->name=$_POST['pa_name']; + $new->description=$_POST['pa_description']; + $new->add(); + } + } + // show the detail + if ( $sa == "pa_detail" ) + { + $new=new PlanAnalytic($cn,$_GET['pa_id']); + $wAction=new widget("hidden","","p_action","ca_pa"); + $wSa=new widget("HIDDEN","","sa","pa_update"); + + $new->get(); + + $ret.= '
'; + $ret.= '

Mise à jour

'; + $ret.= '
'; + $ret.= $new->form(); + $ret.= $wSa->IOValue(); + $ret.= $wAction->IOValue(); + $ret.= $wSa->Submit("submit","Enregistre"); + $ret.=sprintf(''. + '', + "?p_action=ca_pa&pa_id=".$_GET['pa_id']."&sa=pa_delete"); + + $ret.= '
'; + $ret.= '
'; + + } + // Update the PA + if ( $sa == "pa_update" ) + { + $new=new PlanAnalytic($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 Poste_analytique($cn); + $po->pa_id=$_REQUEST['pa_id']; + $wSa=new widget("hidden","sa","sa","po_write"); + $ret.='
'; + $ret.='
'; + $ret.=$po->form(); + $ret.=$wSa->IOValue(); + $ret.=$wSa->Submit("add","Ajout"); + $ret.="
"; + } + // record the poste + if ( $sa=="po_write") + { + // var_dump($_POST); + $po=new Poste_analytique($cn); + $po->fill_from_POST(); + $po->add(); + $sa="list"; + + } + /* delete pa */ + if ( $sa == "pa_delete") + { + $delete=new PlanAnalytic($cn,$_GET['pa_id']); + $delete->delete(); + } + /* po detail + * + */ + if ( $sa=="po_detail") + { + $wHidden=new widget('hidden','','sa','po_update'); + $po=new Poste_analytique($cn,$_GET['po_id']); + $po->get_by_id(); + $ret.='
'; + $ret.=''; + $ret.=$po->form(); + $ret.=$wHidden->IOValue(); + $ret.=''; + $ret.=sprintf(''. + '', + $po->id, + $_REQUEST['pa_id'] + ); + + $ret.=''; + $ret.='
'; + } + if ( $sa=="po_update") + { + $po=new Poste_analytique($cn); + $po->fill_from_POST(); + $po->update(); + $sa="list"; + } + if ( $sa=="po_delete") + { + $po=new Poste_analytique($cn,$_REQUEST['po_id']); + $po->delete(); + $sa="list"; + } + /* List poste */ + if ( $sa == "list" ) + { + $count=0; + + $new=new PlanAnalytic($cn,$_REQUEST['pa_id']); + $new->get(); + $array=$new->get_poste_analytique(); + $ret.='
'; + $ret.=''; + $ret.=""; + $ret.=""; + $class=""; + foreach ($array as $obj) + { + $count++; + if ( $count %2 == 0 ) + $class="even"; + else + $class="odd"; + + $ret.=""; + $ret.=""; + $ret.=""; + $ret.=""; + $ret.=""; + $ret.=""; + + } + $ret.="
Nom "; + $ret.=" Montant "; + $ret.=" Description "; + $ret.=" Plan A "; + $ret.="
". + ''. + $obj->name. + ''; + "".$obj->amount."".$obj->description."".$new->name."
"; + $ret.=sprintf(''. + '', + $_GET['pa_id'] + ); + $ret.='
'; + + } + + } + + +//--------------------------------------------------------------------------- +// Show lmenu +// +//--------------------------------------------------------------------------- +$obj=new PlanAnalytic($cn); +$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 +// +// +//--------------------------------------------------------------------------- + +echo $ret; diff --git a/include/cbc_be.inc.php b/include/cbc_be.inc.php index 5f92f94b5..e10477181 100644 --- a/include/cbc_be.inc.php +++ b/include/cbc_be.inc.php @@ -80,8 +80,13 @@ while (($data = fgetcsv($handle, 2000,'!@')) !== FALSE) { '$p_bq_account', $p_jrn, 'n')"; - if ( ExecSql($p_cn,$Sql) == false ) + try { + ExecSql($p_cn,$Sql) ; + } + catch(Exception $e) + { + echo_debug(__FILE__.":".__LINE__." Erreur : ".$e->getCode." msg ".$e->getMessage); Rollback($p_cn); break; } diff --git a/include/central_inc.php b/include/central_inc.php index bd952afc9..80be13925 100644 --- a/include/central_inc.php +++ b/include/central_inc.php @@ -61,21 +61,22 @@ $sql="insert into centralized( c_j_id, where j_tech_per =".$p_periode." order by j_date,j_grpt,j_debit desc "; - $Res=StartSql($p_cn); - $Res=ExecSql($p_cn,$sql); - if ($Res==false) { rollback($p_cn); EndSql($p_cn); return ERROR;} - $Res=ExecSql($p_cn,"update jrnx set j_centralized='t' where j_tech_per=".$p_periode); - if ($Res==false) { rollback($p_cn); EndSql($p_cn); return ERROR;} -// Set correctly the number of operation id (jr_opid) for each journal -// get the existing jrn_def_id -//-- - $Res = ExecSql($p_cn,"select jrn_def_id from jrn_def"); - $MaxJrn=pg_NumRows($Res); - // for each jrn_def_id - for ( $i=0; $i < $MaxJrn;$i++) { - $row=pg_fetch_array($Res,$i); - // get the op related to that jrn_def_id - $sql=sprintf("select jr_id from jrn + try + { + $Res=StartSql($p_cn); + $Res=ExecSql($p_cn,$sql); + $Res=ExecSql($p_cn,"update jrnx set j_centralized='t' where j_tech_per=".$p_periode); + + // Set correctly the number of operation id (jr_opid) for each journal + // get the existing jrn_def_id + //-- + $Res = ExecSql($p_cn,"select jrn_def_id from jrn_def"); + $MaxJrn=pg_NumRows($Res); + // for each jrn_def_id + for ( $i=0; $i < $MaxJrn;$i++) { + $row=pg_fetch_array($Res,$i); + // get the op related to that jrn_def_id + $sql=sprintf("select jr_id from jrn where jr_tech_per=%d and jr_def_id = %d @@ -84,60 +85,64 @@ $sql="insert into centralized( c_j_id, $row['jrn_def_id'] ); - $Res2=ExecSql($p_cn,$sql); - $MaxLine=pg_NumRows($Res2); - for ($e=0;$e < $MaxLine;$e++) { - // each line is updated with a sequence - $line=pg_fetch_array($Res2,$e); - $jr_id=$line['jr_id']; - $sql=sprintf ("update jrn set + $Res2=ExecSql($p_cn,$sql); + $MaxLine=pg_NumRows($Res2); + for ($e=0;$e < $MaxLine;$e++) { + // each line is updated with a sequence + $line=pg_fetch_array($Res2,$e); + $jr_id=$line['jr_id']; + $sql=sprintf ("update jrn set jr_opid = (select nextval('s_jrn_%d')) where jr_id =%d", - $row['jrn_def_id'], - $jr_id); - $Ret=ExecSql($p_cn,$sql); - if ($Res==false) { rollback($p_cn); EndSql($p_cn); return ERROR;} - } - } - // Put jr_c_opid in centralized - // for each jrn_def_id - // get the op related to that jrn_def_id - $sql=sprintf("select jr_id from jrn + $row['jrn_def_id'], + $jr_id); + $Ret=ExecSql($p_cn,$sql); + + } + } + // Put jr_c_opid in centralized + // for each jrn_def_id + // get the op related to that jrn_def_id + $sql=sprintf("select jr_id from jrn where jr_tech_per=%d order by jr_date,jr_grpt_id desc", - $p_periode - ); - - $Res2=ExecSql($p_cn,$sql); - $MaxLine=pg_NumRows($Res2); - for ($e=0;$e < $MaxLine;$e++) { - // each line is updated with a sequence - $line=pg_fetch_array($Res2,$e); - $jr_id=$line['jr_id']; - $sql=sprintf ("update jrn set + $p_periode + ); + + $Res2=ExecSql($p_cn,$sql); + $MaxLine=pg_NumRows($Res2); + for ($e=0;$e < $MaxLine;$e++) { + // each line is updated with a sequence + $line=pg_fetch_array($Res2,$e); + $jr_id=$line['jr_id']; + $sql=sprintf ("update jrn set jr_c_opid = (select nextval('s_central')) where jr_id =%d", - $jr_id); - $Ret=ExecSql($p_cn,$sql); - if ($Ret==false) { rollback($p_cn); EndSql($p_cn); return ERROR;} - } - // Set the order of the jrn - $Res=ExecSql($p_cn,"select c_id from centralized + $jr_id); + $Ret=ExecSql($p_cn,$sql); + } + // Set the order of the jrn + $Res=ExecSql($p_cn,"select c_id from centralized inner join jrn on c_grp = jr_grpt_id order by jr_c_opid, c_debit desc"); - for ( $e=0;$e < pg_NumRows($Res);$e++) { - $row=pg_fetch_array($Res,$e); - $sql=sprintf ("update centralized set + for ( $e=0;$e < pg_NumRows($Res);$e++) { + $row=pg_fetch_array($Res,$e); + $sql=sprintf ("update centralized set c_order = (select nextval('s_central_order')) where c_id = %d",$row['c_id']); - $Res2=ExecSql($p_cn,$sql); - if ($Res2==false) { rollback($p_cn); EndSql($p_cn); return ERROR;} + $Res2=ExecSql($p_cn,$sql); + } + ExecSql($p_cn,"update parm_periode set p_central=true where p_id=$p_periode"); } - if ( ExecSql($p_cn,"update parm_periode set p_central=true where p_id=$p_periode") == false) - { rollback($p_cn); EndSql($p_cn); return ERROR;} - + catch(Exception $e) + { + echo_debug(__FILE__.":".__LINE__." Erreur : ".$e->getCode." msg ".$e->getMessage); + rollback($p_cn); + return ERROR; + } + diff --git a/include/class_action.php b/include/class_action.php index 1552dfde3..102e9f0b4 100644 --- a/include/class_action.php +++ b/include/class_action.php @@ -93,9 +93,8 @@ class action * it is a new document * * \param $p_view if set to true the form will be in readonly mode - * \\param $p_gen true we show the tag for generating a doc - * \todo change this parameter by UPD : ag_ref and document type are read only, - * the other are writable, NEW: everything is writable, READ readonly mode + * \param $p_gen true we show the tag for generating a doc + * * \note update the reference number or the document type is not allowed * * @@ -108,25 +107,25 @@ class action if ( $p_view=='UPD') - { - $upd=true; - $readonly=false; - } + { + $upd=true; + $readonly=false; + } elseif ($p_view=="NEW") - { - $upd=false; - $readonly=false; - } + { + $upd=false; + $readonly=false; + } elseif ($p_view=='READ') - { - $upd=true; - $readonly=true; - } + { + $upd=true; + $readonly=true; + } else - { - exit('class_action'.__LINE__.'Action::Display error unknown parameter'.$p_view); - - } + { + exit('class_action'.__LINE__.'Action::Display error unknown parameter'.$p_view); + + } // Compute the widget // Date $date=new widget("text"); @@ -161,6 +160,7 @@ class action $desc->heigh=250; $desc->name="ag_comment"; $desc->readonly=$readonly; + /*!\todo Formatstring and urldecode ?? */ $desc->value=FormatString(urldecode($this->ag_comment)); // state @@ -209,7 +209,8 @@ class action $title=new widget("text"); $title->readonly=$readonly; $title->name="ag_title"; - $title->value=FormatString($this->ag_title); + // $title->value=FormatString($this->ag_title); + $title->value=$this->ag_title; $title->size=80; // ag_ref @@ -376,12 +377,12 @@ class action { echo_debug('class_action',__LINE__,'confirm() :'.var_export($_POST,true)); echo_debug('class_action',__LINE__,'confirm $this :'.var_export($this,true)); - /*! \todo add the hour */ + if ( isDate($this->ag_timestamp) == null ) - { - // if the date is invalid, default date is today - $this->ag_timestamp=date("d.m.Y"); - } + { + // if the date is invalid, default date is today + $this->ag_timestamp=date("d.m.Y"); + } // Compute the widget // Date $date=new widget("text"); @@ -652,7 +653,6 @@ class action */ function myList($p_filter="",$p_search="") { - /*!\todo idea to add a sort */ // for the sort $sort=""; $image_asc=''; diff --git a/include/class_customer.php b/include/class_customer.php index 829380882..a262070f8 100644 --- a/include/class_customer.php +++ b/include/class_customer.php @@ -37,12 +37,12 @@ require_once('user_common.php'); // class Customer extends fiche{ - var $poste; /*! \enum $poste poste comptable */ - var $name; /*! \enum $name name of the company */ - var $street; /*! \enum $street Street */ - var $country; /*! \enum $country Country */ - var $cp; /*! \enum $cp Zip code */ - var $vat_number; /*! \enum $vat_number vat number */ + var $poste; /*!< $poste poste comptable */ + var $name; /*!< $name name of the company */ + var $street; /*!< $street Street */ + var $country; /*!< $country Country */ + var $cp; /*!< $cp Zip code */ + var $vat_number; /*!< $vat_number vat number */ /*! \brief Constructor /* only a db connection is needed */ diff --git a/include/class_document.php b/include/class_document.php index 15f81973b..b97125936 100644 --- a/include/class_document.php +++ b/include/class_document.php @@ -20,6 +20,7 @@ // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr require_once('class_own.php'); require_once('class_poste.php'); +require_once('class_action.php'); /*! \file * \brief Class Document corresponds to the table document */ @@ -210,13 +211,13 @@ class Document // compute the regex if ( $p_type=='OOo') { - $regex="<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[0-9]*>>"; + $regex="<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*>>"; $lt="<"; $gt=">"; } else { - $regex="<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[0-9]*>>"; + $regex="<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*>>"; $lt="<"; $gt=">"; } diff --git a/include/class_document_modele.php b/include/class_document_modele.php index 1b8445222..c07abf8eb 100644 --- a/include/class_document_modele.php +++ b/include/class_document_modele.php @@ -105,71 +105,80 @@ class Document_modele { // if name is empty return immediately if ( trim(strlen($this->md_name))==0) return; - // Start transaction - StartSql($this->cn); - // Save data into the table invoice - // 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) + try { - - // insert into the table document_modele - $this->name=FormatString($this->md_name); - $this->md_id=NextSequence($this->cn,'document_modele_md_id_seq'); - $sql=sprintf("insert into document_modele(md_id,md_name,md_type) + // Start transaction + StartSql($this->cn); + // Save data into the table invoice + // 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->name=FormatString($this->md_name); + $this->md_id=NextSequence($this->cn,'document_modele_md_id_seq'); + $sql=sprintf("insert into document_modele(md_id,md_name,md_type) values (%d,'%s',%d)", - $this->md_id,$this->name,$this->md_type); - $Ret=ExecSql($this->cn,$sql); - // create the sequence for this modele of document - $this->md_sequence="document_".NextSequence($this->cn,"document_seq"); - // if start is not equal to 0 and he's a number than the user - // request a number change - echo_debug('class_document_modele',__LINE__, "this->start ".$this->start." a number ".isNumber($this->start)); - - if ( $this->start != 0 && isNumber($this->start) == 1 ) - { - $sql="alter sequence seq_doc_type_".$this->md_type." restart ".$this->start; - ExecSql($this->cn,$sql); + $this->md_id,$this->name,$this->md_type); + $Ret=ExecSql($this->cn,$sql); + // create the sequence for this modele of document + $this->md_sequence="document_".NextSequence($this->cn,"document_seq"); + // if start is not equal to 0 and he's a number than the user + // request a number change + echo_debug('class_document_modele',__LINE__, "this->start ".$this->start." a number ".isNumber($this->start)); + + if ( $this->start != 0 && isNumber($this->start) == 1 ) + { + $sql="alter sequence seq_doc_type_".$this->md_type." restart ".$this->start; + ExecSql($this->cn,$sql); + } + + } + // Save the file + $new_name=tempnam($_ENV['TMP'],'document_'); + echo_debug('class_document_modele.php',__LINE__,"new name=".$new_name); + if ( strlen ($_FILES['doc']['tmp_name']) != 0 ) + { + if (move_uploaded_file($_FILES['doc']['tmp_name'], + $new_name)) + { + // echo "Image saved"; + $oid= pg_lo_import($this->cn,$new_name); + if ( $oid == false ) + { + echo_error('class_document_modele.php',__LINE__,"cannot upload document"); + Rollback($cn); + return; + } + echo_debug('class_document_modele.php',__LINE__,"Loading document"); + // Remove old document + $ret=ExecSql($this->cn,"select md_lob from document_modele where md_id=".$this->md_id); + if (pg_num_rows($ret) != 0) + { + $r=pg_fetch_array($ret,0); + $old_oid=$r['md_lob']; + if (strlen($old_oid) != 0) + pg_lo_unlink($this->cn,$old_oid); + } + // Load new document + ExecSql($this->cn,"update document_modele set md_lob=".$oid.", md_mimetype='".$_FILES['doc']['type']."' ,md_filename='".$_FILES['doc']['name']."' where md_id=".$this->md_id); + Commit($this->cn); + } + else + { + echo "

Error

"; + Rollback($this->cn); + exit; + } } - } - // Save the file - $new_name=tempnam($_ENV['TMP'],'document_'); - echo_debug('class_document_modele.php',__LINE__,"new name=".$new_name); - if ( strlen ($_FILES['doc']['tmp_name']) != 0 ) + catch (Exception $e) { - if (move_uploaded_file($_FILES['doc']['tmp_name'], - $new_name)) - { - // echo "Image saved"; - $oid= pg_lo_import($this->cn,$new_name); - if ( $oid == false ) - { - echo_error('class_document_modele.php',__LINE__,"cannot upload document"); - Rollback($cn); - return; - } - echo_debug('class_document_modele.php',__LINE__,"Loading document"); - // Remove old document - $ret=ExecSql($this->cn,"select md_lob from document_modele where md_id=".$this->md_id); - if (pg_num_rows($ret) != 0) - { - $r=pg_fetch_array($ret,0); - $old_oid=$r['md_lob']; - if (strlen($old_oid) != 0) - pg_lo_unlink($this->cn,$old_oid); - } - // Load new document - ExecSql($this->cn,"update document_modele set md_lob=".$oid.", md_mimetype='".$_FILES['doc']['type']."' ,md_filename='".$_FILES['doc']['name']."' where md_id=".$this->md_id); - Commit($this->cn); - } - else - { - echo "

Error

"; - Rollback($this->cn); - exit; - } + echo_debug(__FILE__.":".__LINE__." Erreur : ".$e->getCode." msg ".$e->getMessage); + rollback($p_cn); + return ; } } /*! @@ -281,4 +290,4 @@ class Document_modele { } } -?> \ No newline at end of file +?> diff --git a/include/class_dossier.php b/include/class_dossier.php new file mode 100644 index 000000000..0297f70aa --- /dev/null +++ b/include/class_dossier.php @@ -0,0 +1,46 @@ +id=$_REQUEST['gDossier']; + } + function get() { + return $this->id; + } + function hidden { + return ''; + } +} diff --git a/include/class_fiche.php b/include/class_fiche.php index 4482a0876..f55b30d5c 100644 --- a/include/class_fiche.php +++ b/include/class_fiche.php @@ -37,12 +37,12 @@ require_once('class_widget.php'); // class fiche //----------------------------------------------------- class fiche { - var $cn; /*! \enum $cn database connection */ - var $id; /*! \enum $id fiche.f_id */ - var $fiche_def; /*! \enum $fiche_def fd_id */ - var $attribut; /*! \enum $attribut array of attribut object */ - var $fiche_def_ref; /*!\enum $fiche_def_ref Type of the card here always FICHE_TYPE_CONTACT */ - var $row; /*! \enum All the row from the ledgers */ + 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 */ function fiche($p_cn,$p_id=0) { $this->cn=$p_cn; $this->id=$p_id; @@ -51,7 +51,8 @@ class fiche { * \brief Retrieve a card thx his quick_code * complete the object * \param $p_qcode quick_code (ad_id=23) - * \param $p_all retrieve all the attribut of the card, possible value are true false + * \param $p_all retrieve all the attribut of the card, possible value + * are true, false retrieve only the f_id * \return 0 success 1 error not found */ @@ -423,101 +424,107 @@ class fiche { $this->id=$fiche_id; // first we create the card StartSql($this->cn); - $sql=sprintf("insert into fiche(f_id,fd_id)". - " values (%d,%d)", - $fiche_id,$p_fiche_def); - $Ret=ExecSql($this->cn,$sql); - // parse the $_POST array - foreach ($_POST as $name=>$value ) + try { - echo_debug ("class_fiche",__LINE__,"Name = $name value $value") ; - list ($id) = sscanf ($name,"av_text%d"); - if ( $id == null ) continue; - echo_debug("class_fiche",__LINE__,"add $id"); - - // Special traitement - // quickcode - if ( $id == ATTR_DEF_QUICKCODE) + $sql=sprintf("insert into fiche(f_id,fd_id)". + " values (%d,%d)", + $fiche_id,$p_fiche_def); + $Ret=ExecSql($this->cn,$sql); + // parse the $_POST array + foreach ($_POST as $name=>$value ) { - echo_debug("Modify ATTR_DEF_QUICKCODE"); - $sql=sprintf("select insert_quick_code(%d,'%s')", - $fiche_id,FormatString($value)); - ExecSql($this->cn,$sql); - continue; - } - // name - if ( $id == ATTR_DEF_NAME ) - { - echo_debug("Modify ATTR_DEF_NAME"); - if ( strlen(trim($value)) == 0 ) - $value="pas de nom"; + echo_debug ("class_fiche",__LINE__,"Name = $name value $value") ; + list ($id) = sscanf ($name,"av_text%d"); + if ( $id == null ) continue; + echo_debug("class_fiche",__LINE__,"add $id"); - } - // account - if ( $id == ATTR_DEF_ACCOUNT ) - { - echo_debug("insert ATTR_DEF_ACCOUNT"); - $v=FormatString($value); - ob_start(); - if ( - isNumber($v) == 1 - ) + // Special traitement + // quickcode + if ( $id == ATTR_DEF_QUICKCODE) { - $sql=sprintf("select account_insert(%d,%f)", - $this->id,$v); + echo_debug("Modify ATTR_DEF_QUICKCODE"); + $sql=sprintf("select insert_quick_code(%d,'%s')", + $fiche_id,FormatString($value)); + ExecSql($this->cn,$sql); + continue; } - else + // name + if ( $id == ATTR_DEF_NAME ) { - $sql=sprintf("select account_insert(%d,null)", - $this->id); + echo_debug("Modify ATTR_DEF_NAME"); + if ( strlen(trim($value)) == 0 ) + $value="pas de nom"; + } - $ret=ExecSql($this->cn,$sql,false); - ob_end_clean(); - if ( $ret == false ) { - echo ""; - Rollback($this->cn); - return; - } - continue; - } - // TVA - if ( $id == ATTR_DEF_TVA ) - { - echo_debug("Modify ATTR_DEF_TVA"); - // Verify if the rate exists, if not then do not update - if ( strlen(trim($value)) != 0 ) + // account + if ( $id == ATTR_DEF_ACCOUNT ) { - if ( CountSql($this->cn,"select * from tva_rate where tva_id=".$value) == 0) + echo_debug("insert ATTR_DEF_ACCOUNT"); + $v=FormatString($value); + try { + if ( + isNumber($v) == 1 + ) + { + $sql=sprintf("select account_insert(%d,%f)", + $this->id,$v); + } + else + { + $sql=sprintf("select account_insert(%d,null)", + $this->id); + } + ExecSql($this->cn,$sql,false); + } 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 ) + { + echo_debug("Modify ATTR_DEF_TVA"); + // Verify if the rate exists, if not then do not update + if ( strlen(trim($value)) != 0 ) { - echo_debug("class_fiche",__LINE__,"Tva invalide $value"); - continue; + if ( CountSql($this->cn,"select * from tva_rate where tva_id=".$value) == 0) + { + echo_debug("class_fiche",__LINE__,"Tva invalide $value"); + continue; + } } } - } - // The contact has a company attribut - if ( $id == ATTR_DEF_COMPANY ) - { - $exist=CountSql($this->cn,"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 ) + // The contact has a company attribut + if ( $id == ATTR_DEF_COMPANY ) { - $value=""; + $exist=CountSql($this->cn,"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)); + ExecSql($this->cn,$sql); } - // Normal traitement - $value2=FormatString($value); - - $sql=sprintf("select attribut_insert(%d,%d,'%s')", - $fiche_id,$id,trim($value2)); - ExecSql($this->cn,$sql); - } + } catch (Exception $e) + { + echo ''. + $e->getMessage(). + ''; + Rollback($this->cn); + return; + } Commit($this->cn); return; - - } @@ -527,136 +534,137 @@ class fiche { */ function update() { - // parse the $_POST array - foreach ($_POST as $name=>$value ) - { - echo_debug ("class_fiche",__LINE__,"Name = $name value $value") ; - list ($id) = sscanf ($name,"av_text%d"); - if ( $id == null ) continue; - echo_debug("class_fiche",__LINE__,"modify $id"); - - // 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=ExecSql($this->cn,$sql); - if ( pg_NumRows($Ret) != 1 ) { - // we need to insert this new attribut - echo_debug ("class_fiche ".__LINE__." adding id !!! "); - $jft_id=NextSequence($this->cn,'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); - - $ret2=ExecSql($this->cn,$sql2); - // insert a null value for this attribut - $sql3=sprintf("insert into attr_value(jft_id,av_text) values (%s,null)", - $jft_id); - $ret3=ExecSql($this->cn,$sql3); - } else - { + try { + StartSql($this->cn); + // parse the $_POST array + foreach ($_POST as $name=>$value ) + { + echo_debug ("class_fiche",__LINE__,"Name = $name value $value") ; + list ($id) = sscanf ($name,"av_text%d"); + if ( $id == null ) continue; + echo_debug("class_fiche",__LINE__,"modify $id"); + + // 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=ExecSql($this->cn,$sql); + if ( pg_NumRows($Ret) != 1 ) { + // we need to insert this new attribut + echo_debug ("class_fiche ".__LINE__." adding id !!! "); + $jft_id=NextSequence($this->cn,'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); + + $ret2=ExecSql($this->cn,$sql2); + // insert a null value for this attribut + $sql3=sprintf("insert into attr_value(jft_id,av_text) values (%s,null)", + $jft_id); + $ret3=ExecSql($this->cn,$sql3); + } else + { $tmp=pg_fetch_array($Ret,0); $jft_id=$tmp['jft_id']; - } - // Special traitement - // quickcode - if ( $id == ATTR_DEF_QUICKCODE) - { - echo_debug("Modify ATTR_DEF_QUICKCODE"); - $sql=sprintf("select update_quick_code(%d,'%s')", - $jft_id,FormatString($value)); - ExecSql($this->cn,$sql); - continue; + } + // Special traitement + // quickcode + if ( $id == ATTR_DEF_QUICKCODE) + { + echo_debug("Modify ATTR_DEF_QUICKCODE"); + $sql=sprintf("select update_quick_code(%d,'%s')", + $jft_id,FormatString($value)); + ExecSql($this->cn,$sql); + continue; } - // name - if ( $id == ATTR_DEF_NAME ) - { - echo_debug("Modify ATTR_DEF_NAME"); - echo_debug("Value = $v"); - if ( strlen(trim($value)) == 0 ) - continue; - - echo_debug("Value = $v"); + // name + if ( $id == ATTR_DEF_NAME ) + { + echo_debug("Modify ATTR_DEF_NAME"); + if ( strlen(trim($value)) == 0 ) + continue; + - } - - // account - if ( $id == ATTR_DEF_ACCOUNT ) - { - echo_debug("Modify ATTR_DEF_ACCOUNT"); - $v=FormatString($value); - echo_debug("Value = $v"); - if ( isNumber($v) == 1 ) - { - ob_start(); - - $sql=sprintf("select account_update(%d,%d)", - $this->id,$v); - $Ret=ExecSql($this->cn,$sql,false); - - ob_end_clean(); - if ( $Ret == false ) { - echo "Erreur : ce compte [$v] n'a pas de compte parent.". - "L'opération est annulée"; - Rollback($this->cn); - return; + } + + // account + if ( $id == ATTR_DEF_ACCOUNT ) + { + echo_debug("Modify ATTR_DEF_ACCOUNT"); + $v=FormatString($value); + echo_debug("Value = $v"); + if ( isNumber($v) == 1 ) + { + $sql=sprintf("select account_update(%d,%d)", + $this->id,$v); + try { + ExecSql($this->cn,$sql,false); + } catch (Exception $e) { + throw new Exception(__LINE__."Erreur : ce compte [$v] n'a pas de compte parent.". + "L'opération est annulée"); + } + + continue; } - continue; - } - if ( strlen (trim($v)) == 0 ) + if ( strlen (trim($v)) == 0 ) { + $sql=sprintf("select account_update(%d,null)", $this->id); - $Ret=ExecSql($this->cn,$sql,false); - - ob_end_clean(); - if ( $Ret == false ) { - echo "Erreur : ce compte [$v] n'a pas de compte parent.". - "L'opération est annulée"; - Rollback($this->cn); - return; + try { + $Ret=ExecSql($this->cn,$sql,false); + } catch (Exception $e) { + throw new Exception(__LINE__."Erreur : ce compte [$v] n'a pas de compte parent.". + "L'opération est annulée"); } - continue; continue; } } - // TVA - if ( $id == ATTR_DEF_TVA ) - { - echo_debug("Modify ATTR_DEF_TVA"); - // Verify if the rate exists, if not then do not update - if ( strlen(trim($value)) != 0 ) - { - if ( CountSql($this->cn,"select * from tva_rate where tva_id=".$value) == 0) - { - echo_debug("class_fiche",__LINE__,"Tva invalide $value"); - continue; - } - } - } - if ( $id == ATTR_DEF_COMPANY ) - { - $exist=CountSql($this->cn,"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) ". + // TVA + if ( $id == ATTR_DEF_TVA ) + { + echo_debug("Modify ATTR_DEF_TVA"); + // Verify if the rate exists, if not then do not update + if ( strlen(trim($value)) != 0 ) + { + if ( CountSql($this->cn,"select * from tva_rate where tva_id=".$value) == 0) + { + echo_debug("class_fiche",__LINE__,"Tva invalide $value"); + continue; + } + } + } + if ( $id == ATTR_DEF_COMPANY ) + { + $exist=CountSql($this->cn,"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é "; - } - } - - // Normal traitement - $value2=FormatString($value); - $sql=sprintf("update attr_value set av_text='%s' where jft_id=%d", - trim($value2),$jft_id); - ExecSql($this->cn,$sql); - } + " and av_text='".FormatString($value)."'"); + + + 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); + ExecSql($this->cn,$sql); + } + } catch (Exception $e ) { + echo ''. + $e->getMessage(). + ''; + Rollback($this->cn); + return; + } + Commit($this->cn); return; } - /*!\brief remove a card - */ + /*!\brief remove a card + */ function remove() { if ( $this->id==0 ) return; @@ -737,7 +745,8 @@ class fiche { { return fiche::GetByDef($this->fiche_def_ref,$p_offset,$p_search); } - /*!\brief retrieve the frd_id of the fiche + /*!\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() @@ -931,7 +940,5 @@ function GetSoldeDetail($p_cond="") { else $this->fd_id=$R; } - -} - +} ?> diff --git a/include/class_gestion_purchase.php b/include/class_gestion_purchase.php new file mode 100644 index 000000000..3e3fbf1ff --- /dev/null +++ b/include/class_gestion_purchase.php @@ -0,0 +1,82 @@ +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, + qp_nd_amount, + qp_nd_tva, + qp_nd_tva_recup, + qp_supplier, + j_id + from quant_purchase + where qp_internal='".$this->qp_internal."'"; + $ret=ExecSql($this->db,$sql); + // $res contains all the line + $res=pg_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; + } +} diff --git a/include/class_gestion_sold.php b/include/class_gestion_sold.php new file mode 100644 index 000000000..ed7c242fc --- /dev/null +++ b/include/class_gestion_sold.php @@ -0,0 +1,79 @@ +qs_internal=="") + exit (__FILE__.__LINE__." qs_internal est vide"); + $sql="select qs_id, + qs_internal, + qs_fiche, + qs_quantite, + qs_price, + qs_vat, + qs_vat_code, + qs_client, + j_id + from quant_sold + where qs_internal='".$this->qs_internal."'"; + $ret=ExecSql($this->db,$sql); + // $res contains all the line + $res=pg_fetch_all($ret); + + 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; + } +} diff --git a/include/class_gestion_table.php b/include/class_gestion_table.php new file mode 100644 index 000000000..9435dfa98 --- /dev/null +++ b/include/class_gestion_table.php @@ -0,0 +1,36 @@ +db=$p_cn; + } +} diff --git a/include/class_groupop.php b/include/class_groupop.php new file mode 100644 index 000000000..f6cb15eb5 --- /dev/null +++ b/include/class_groupop.php @@ -0,0 +1,185 @@ +db=$p_cn; + $this->id=$p_id; + $this->date=date("d.m.Y"); + $this->nMaxRow=10; + } + /*!\brief add several rows */ + function add() { + /*!\todo add a control to check that the amount are balanced if + not throw an exception + */ + foreach ($this->a_operation as $row) { + $row->add(); + } + } + /*!\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 widget("text","Date : ","pdate",$this->date); + $wDate->table=1; + $wDate->size=10; + $wDate->readonly=$p_readonly; + + $wDescription=new widget("text","Description","pdesc".$i); + $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; + } + + $wPa_id=new widget("hidden","","pa_id",$this->pa_id); + $ret=""; + $ret.=$wPa_id->IOValue(); + $ret.=''; + // $ret.="
"; + $ret.="".$wDate->IOValue().""; + $ret.=''. + '"; + + /* array of possible value for the select */ + $aPoste=make_array($this->db,"select po_id as value,po_name||':'||po_description as label". + " from poste_analytique ". + " where pa_id = ".$this->pa_id. + " order by po_name "); + + /* show 10 rows */ + $ret.="". + "". + "". + "". + "". + ""; + + for ($i = 0;$i < $this->nMaxRow;$i++) + { + // init variable + $wSelect=new widget("select","","pop".$i); + $wSelect->value=$aPoste; + $wSelect->table=1; + $wSelect->size=12; + $wSelect->readonly=$p_readonly; + + $wAmount=new widget("text","","pamount$i",0.0); + $wAmount->size=12; + $wAmount->table=1; + $wAmount->readonly=$p_readonly; + + $wDebit=new widget("checkbox","","pdeb$i"); + $wDebit->table=1; + $wDebit->readonly=$p_readonly; + 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.=$wSelect->IOValue(); + $ret.=""; + $ret.=$wAmount->IOValue(); + $ret.=$wDebit->IOValue(); + $ret.=""; + } + $ret.="
Description'. + $wDescription->IOValue()."
Poste MontantDébit
"; + return $ret; + } + /*!\brief fill row from $_POST data + * + */ + function from_POST() { + for ( $i = 0;$i <$this->nMaxRow;$i++) { + $p=new operation($this->db); + $p->po_id=$_POST["pop$i"]; + $p->oa_amount=$_POST["pamount$i"]; + + $p->oa_description=$_POST["pdesc"]; + $p->oa_date=$_POST['pdate']; + $p->j_id=0; + $p->oa_debit=(isset ($_POST["pdeb$i"]))?'t':'f'; + $p->oa_group=0; + $p->pa_id=$_POST['pa_id']; + $this->a_operation[]=clone $p; + } + } + /*!\brief save the group of operation but only if the amount is + balanced */ + function save() { + StartSql($this->db); + try { + $oa_group=NextSequence($this->db,'s_oa_group'); + for ($i=0;$i<$this->nMaxRow;$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(); + Rollback($p_cn); + exit(); + + } + Commit($this->db); + } + /*!\brief show the form */ + function show() { + return $this->form(1); + } +} diff --git a/include/class_jrn.php b/include/class_jrn.php index 4c7f07627..38a1013bb 100644 --- a/include/class_jrn.php +++ b/include/class_jrn.php @@ -27,6 +27,7 @@ class jrn { var $name; var $db; var $row; + var $type; function jrn ($p_cn,$p_id){ $this->id=$p_id; $this->db=$p_cn; @@ -36,7 +37,7 @@ class jrn { * \brief Return the type of a ledger (ACH,VEN,ODS or FIN) or GL * */ - function GetType() { + function get_type() { if ( $this->id==0 ) { $this->name=" Grand Livre "; $this->type="GL"; @@ -95,14 +96,15 @@ class jrn { $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:""; - - // Grand livre == 0 - if ( $this->id != 0 ) { - - if ( $cent=='off' ) { - echo_debug('class_jrn.php',__LINE__,"journaux non centralisé"); - // Journaux non centralisés - $Res=ExecSql($this->db,"select j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date, + // retrieve the type + $this->get_type(); + // Grand livre == 0 + if ( $this->id != 0 ) { + + if ( $cent=='off' ) { + echo_debug('class_jrn.php',__LINE__,"journaux non centralisé"); + // Journaux non centralisés + $Res=ExecSql($this->db,"select 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, @@ -168,7 +170,6 @@ class jrn { // Centralisé $Sql="select jr_c_opid as j_id, c_order as int_j_id, - c_j_id, to_char (c_date,'DD.MM.YYYY') as j_date , c_internal as jr_internal, @@ -177,10 +178,10 @@ class jrn { c_debit as j_debit, c_poste as poste, pcm_lib as description, - jr_comment||' ('||c_internal||')' as jr_comment, + jr_comment||' ('||c_internal||'/ PJ :'||jr_opid||')' as jr_comment, jr_montant, c_grp as grp, - c_comment||' ('||c_internal||')' as comment, + c_comment||' ('||c_internal||' '||jr_opid||')' as comment, c_rapt as oc, c_periode as periode from centralized left join jrn on ". @@ -200,16 +201,19 @@ class jrn { $case=""; $tot_deb=0; $tot_cred=0; + $row=pg_fetch_all($Res); for ($i=0;$i<$Max;$i++) { $fiche=new fiche($this->db); - $line=pg_fetch_array($Res,$i); + $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_amount']; echo_debug('class_jrn.php',__LINE__," GetRow : mont_Deb ".$mont_deb); echo_debug('class_jrn.php',__LINE__," GetRow : mont_cred ".$mont_cred); + /* Check first if there is a quickcode */ if ( strlen(trim($line['j_qcode'])) != 0 ) { @@ -220,13 +224,32 @@ class jrn { } if ( $case != $line['grp'] ) { $case=$line['grp']; + // for financial, we show if the amount is or not in negative + if ( $this->type=='FIN') { + echo_debug(__FILE__,__LINE__,"Journal FIN"); + $eMax=(($i+50) < $Max)?$i+50:$Max; + // check in $row if the BQE is in deb or cred + for ($e=$i;$e<$Max;$e++) { + echo_debug(__FILE__,__LINE__,$row[$e]); + if ( $row[$e]['grp'] != $case ) continue; + if ( strlen(trim($row[$e]['j_qcode'])) == 0 ) continue; + + $f=new fiche($this->db); + $f->GetByQCode($row[$e]['j_qcode'],false); + echo_debug(__FILE__,__LINE__,$f); + if ( $f->get_fiche_def_ref_id() == FICHE_TYPE_FIN ) { + $tot_op=($row[$e]['debit'] == 't')?$jr_montant:" - ".$jr_montant; + break; + } + } + } $array[]=array ( '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'=>''.$jr_montant.'', + 'cred_montant'=>''.$tot_op.'', 'description'=>''.$line['jr_comment'].'', 'poste' => $line['oc'], 'qcode' => $line['j_qcode'], @@ -340,7 +363,7 @@ class jrn { { return null; } - $type=$this->GetType(); + $type=$this->get_type(); // for type ACH and Ven we take more info if ( $type == 'ACH' || $type == 'VEN') { @@ -489,28 +512,28 @@ class jrn { list($tva_deb,$tva_cred)=split(',',$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'])); - echo_debug('class_jrn',__LINE__,'Montant TVA = '.$p_array['AMOUNT_TVA']); - $c++; - - $idx_tva++; - } + { + + // 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'])); + echo_debug('class_jrn',__LINE__,'Montant TVA = '.$p_array['AMOUNT_TVA']); + $c++; + + $idx_tva++; + } } - + // isDNA // If operation is reversed then amount are negatif @@ -524,11 +547,11 @@ class jrn { { foreach ($a_TVA as $tva) { - if ( $tva['tva_id'] == $linetva[1][0] ) - { - $a=$tva['tva_id']; - $a_tva_amount[$a]=$linetva[1][2]; - } + if ( $tva['tva_id'] == $linetva[1][0] ) + { + $a=$tva['tva_id']; + $a_tva_amount[$a]=$linetva[1][2]; + } } } foreach ($a_TVA as $line_tva) @@ -568,4 +591,43 @@ class jrn { 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 + * \param $p_cent 1 for a centralized period otherwise 0 + */ + function get_solde($p_from,$p_to,$p_cent) { + $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','j_tech_per'); + + if ( $this->id != 0 && $p_cent=='off') { + $ledger=" and j_jrn_def = ".$this->id; + } + + if ( $this->id != 0 && $p_cent=='on') { + $ledger=" and c_jrn_def = ".$this->id; + } + + // we ask for a specific ledger + if ( $p_cent == 'off') { + $sql='select j_montant as montant,j_debit as deb from jrnx where ' + .$periode.$ledger; + }else { + $sql='select c_montant as montant,c_debit as deb from centralized where ' + .$periode.$ledger; + } + $ret=ExecSql($this->db,$sql); + $array=pg_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; + } + } diff --git a/include/class_operation.php b/include/class_operation.php new file mode 100644 index 000000000..33d033f15 --- /dev/null +++ b/include/class_operation.php @@ -0,0 +1,243 @@ +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=NextSequence($this->db,'s_oa_group'); + } + + if ( $this->j_id == 0 ) { + $this->j_id="null"; + } + + + // we don't save null operations + if ( $this->oa_amount == 0 ) + return; + $sql='insert into operation_analytique ( + po_id, + pa_id, + oa_amount, + oa_description, + oa_debit, + oa_group, + j_id, + oa_date + ) values ('. + $this->po_id.",". + $this->pa_id.",". + $this->oa_amount.",". + "'".FormatString($this->description)."',". + "'".$this->oa_debit."',". + $this->oa_group.",". + $this->j_id.",". + "to_date('".$this->oa_date."','DD.MM.YYYY'))"; + + + ExecSql($this->db,$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=".$this->oa_id; + + ExecSql($this->db,$sql); + } + + /*!\brief update a row in the table operation_analytique + * \todo update + */ + function update() { + $sql="update operation_analytique set po_id=".$this->po_id." where oa_id=".$this->oa_id; + ExecSql($this->db,$sql); + } + + /*!\brief get a list of row from a certain periode + * \todo to be done + */ + function get_list($p_range="") { + + $sql="select oa_id,po_name,oa_description,". + "oa_debit,oa_date,oa_amount,oa_group,j_id ". + " from operation_analytique as B". + " join poste_analytique using(po_id) ". + "where B.pa_id=".$this->pa_id." and oa_amount <> 0.0 ". + " order by oa_date ,oa_group,oa_debit,oa_id"; + $RetSql=ExecSql($this->db,$sql); + + if ( pg_NumRows($RetSql) == 0 ) + return "Pas d'enregistrement trouvé"; + + $array=pg_fetch_all($RetSql); + + $ret.=""; + $count=0; + $group=0; + $oldgroup=0; + foreach ($array as $row) { + $group=$row['oa_group']; + if ( $group !=$oldgroup ) { + if ( $oldgroup!=0 ) + { + $ret.=''.$row['j_id'].''; + //! \todo add a delete and a detail button + // result must be displayed thanks ajax + $ret.=''; + + } + $ret.=''; + // $ret.=''; + $ret.=""; + + $ret.="". + ""; + + $oldgroup=$group; + } + $class=($count%2==0)?"odd":""; + $count++; + $cred= ( $row['oa_debit'] == 'f')?"CREDIT":"DEBIT"; + $ret.=""; + $ret.= "". + "". + "". + "". + + ""; + } + $ret.="

". + "Groupe id : ".$row['oa_group']. + "". + $row['oa_date']. + "". + $row['oa_description']. + "
". + $row['po_name']. + "". + $row['oa_description']. + "". + $row['oa_amount']. + "". + $cred. + "
"; + 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_operation_by_jid($p_jid) { + $sql="select oa_id, + po_id, + oa_amount, + oa_description, + oa_debit, + j_id, + oa_group, + oa_date, + pa_id + from operation_analytique + where + j_id=$p_jid"; + $ret=ExecSql($this->db,$sql); + $res=pg_fetch_all($ret); + echo_debug(__FILE__.":".__LINE__."count res is ",count($res)); + echo_debug(__FILE__.":".__LINE__," res =",$res); + if ( $res== false) return null; + + foreach ($res as $row) { + $a=new 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_operation_by_jid($this->j_id); + if ( $a == null ) { + // retrieve data from jrnx + $sql="select jr_date,j_amount,j_debit from jrnx ". + " join jrn using (jr_grpt_id = j_grpt) ". + "where j_id=".$this->j_id; + $res=ExecSql($this->db,$sql); + if (pg_NumRows($res) == 0 ) return; + $row=pg_fetch_array($res,0); + $this->oa_amount=$row['j_amount']; + $this->oa_date=$row['jr_date']; + $this->oa_debit=$row['j_debit']; + $this->add(); + } else { + foreach ($a as $row ) { + if ( $row->pa_id == $this->pa_id ) { + $row->po_id=$p_po_id; + $row->update(); + } + } + } + } +} diff --git a/include/class_own.php b/include/class_own.php index 59d436be6..f3b3d22f2 100644 --- a/include/class_own.php +++ b/include/class_own.php @@ -69,7 +69,8 @@ class Own { $this->UpdateRow('MY_PAYS'); $this->UpdateRow('MY_COMMUNE'); $this->UpdateRow('MY_FAX'); + $this->UpdateRow('MY_ANALYTIC'); } -} \ No newline at end of file +} diff --git a/include/class_plananalytic.php b/include/class_plananalytic.php new file mode 100644 index 000000000..f25b9f2ae --- /dev/null +++ b/include/class_plananalytic.php @@ -0,0 +1,158 @@ +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=ExecSql($this->db,$sql); + $array=pg_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= ExecSql($this->db,$sql); + if ( pg_NumRows($ret) == 0) + { + return; + } + $a= pg_fetch_array($ret,0); + $this->name=$a['pa_name']; + $this->description=$a['pa_description']; + + } + + function delete() + { + if ( $this->id == 0 ) return; + ExecSql($this->db,"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); + ExecSql($this->db,"update plan_analytique set pa_name='".$name."'". + ", pa_description='".$description."'". + " where pa_id=".$this->id); + } + + function add() + { + $name=FormatString($this->name); + if ( strlen($name) == 0) + return; + + $description=FormatString($this->description); + ExecSql($this->db,"insert into plan_analytique(pa_name,pa_description)". + " values (". + "'".$name."',". + "'".$description."')"); + $this->id=getSequence($this->db,'plan_analytique_pa_id_seq'); + + } + function form() + { + + $wName=new widget('TEXT','Nom','pa_name',$this->name); + $wName->table=1; + $wDescription=new widget('TEXT','Description','pa_description',$this->description); + $wDescription->table=1; + $wId=new widget("HIDDEN","pa_id",$this->id); + $ret=""; + $ret.=''.$wName->IOValue().''; + $ret.="".$wDescription->IOValue().""; + $ret.="
"; + $ret.=$wId->IOValue(); + return $ret; + } + function isAppend() + { + $count=getDbValue($this->db,"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=ExecSql($this->db,$sql); + $ret=array(); + if ( pg_NumRows($r) == 0 ) + return $ret; + + $all=pg_fetch_all($r); + foreach ($all as $line) + { + $obj=new Poste_analytique($this->db,$line['po_id']); + $obj->get_by_id(); + $ret[]=clone $obj; + } + return $ret; + } +} +?> diff --git a/include/class_poste_analytic.php b/include/class_poste_analytic.php new file mode 100644 index 000000000..aca223528 --- /dev/null +++ b/include/class_poste_analytic.php @@ -0,0 +1,249 @@ +db=$p_db; + $this->id=$p_id; + } + /*! \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 + from poste_analytique + where ". + $p_where; + + $ret=ExecSql($this->db,$sql); + if ( pg_NumRows($ret) == 0 )return null; + $line=pg_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']; + + + + } + 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; + + $sql="insert into poste_analytique ( + po_name , + pa_id, + po_amount, + po_description + ) values (". + "'".$this->name."',". + $this->pa_id.",". + $this->amount.",". + "'".$this->description."')"; + + ExecSql($this->db,$sql); + + } + function update() + { + + $this->format_data(); + if ( strlen($this->name) == 0) + return; + $sql="update poste_analytique ". + " set po_name='".$this->name."',". + " pa_id=".$this->pa_id.",". + " po_amount=".$this->amount.",". + " po_description='".$this->description."'". + " where po_id=".$this->id; + ExecSql($this->db,$sql); + + } + 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; + + $this->description=FormatString($this->description); + } + function delete() + { + $sql="delete from poste_analytique where po_id=".$this->id; + ExecSql($this->db,$sql); + } + /*! \brief return an array of object Poste_Analytique + * + */ + function get_list() + { + $sql="select po_id, + po_name , + pa_id, + po_amount, + po_description + from poste_analytique ". + " order by po_name"; + + $ex=ExecSql($this->db,$sql); + $ret=pg_fetch_all($ex); + if ( $ret == null ) + return null; + + $array=array(); + foreach ($ret as $line) + { + $objet=new Poste_Analytique($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']; + $array[]=clone $object; + } + + return $array; + } + function display_list() + { + $array=$this->get_list(); + + foreach ($array as $line) + { + echo $line->id." / ".$line->name." / ".$line->description."/". + $line->amount." / ".$line->pa_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."
"; + } + function form() + { + $wId=new widget("hidden","po_id","po_id",$this->id); + $wName=new widget("text","Nom","po_name",$this->name); + $wPa_id=new widget("hidden","pa_id","pa_id",$this->pa_id); + $wAmount=new widget("text","Montant","po_amount",$this->amount); + $wDescription=new widget("text","Description","po_description",$this->description); + + $pa=new PlanAnalytic($this->db,$this->pa_id); + $pa->get(); + $wPaName=new widget("text","Plan A.","",$pa->name); + $wPaName->table=1; + $wPaName->readonly=true; + + $wName->table=1; + $wPa_id->table=1; + $wAmount->table=1; + $wDescription->table=1; + + $r=$wId->IOValue(); + $r.=$wPa_id->IOValue(); + + $r.=""; + + $r.=""; + $r.=$wName->IOValue(); + $r.=""; + + $r.=""; + $r.=$wAmount->IOValue(); + $r.=""; + + + $r.=""; + $r.=$wDescription->IOValue(); + $r.=""; + + $r.=""; + $r.=$wPaName->IOValue(); + $r.=""; + + $r.="
"; + return $r; + + } + function fill_from_POST() + { + $this->name=$_POST['po_name']; + $this->description=$_POST['po_description']; + $this->pa_id=$_POST['pa_id']; + $this->amount=$_POST['po_amount']; + $this->id=$_POST['po_id']; + } +} +?> diff --git a/include/class_widget.php b/include/class_widget.php index 0d181079f..dcfada29b 100644 --- a/include/class_widget.php +++ b/include/class_widget.php @@ -38,7 +38,10 @@ * $type * - TEXT * - HIDDEN - * - SELECT + * - BUTTON in this->js you have the javascript code + * - SELECT the options are passed via this->value, this array is + * build thanks the make_array function, each array (of the + * array) aka row must contains a field value and a field label * - PASSWORD * - CHECKBOX * - RADIO @@ -52,6 +55,7 @@ * - JS_TVA open a popup window for the VAT * - JS_CONCERNED open a popup window for search a operation, if extra == 0 then * get the amount thx javascript + * * For JS_SEARCH_POST,JS_SEARCH or JS_SEARCH_ONLY * - $extra contains 'cred', 'deb', 'all' or a list of fiche_def_ref (frd_id) @@ -62,44 +66,36 @@ * */ class widget { - /*! \enum $type type of the input tag (text, select, files, js_search,...) - * \enum $name name of the input tag - * \enum $value value - * \enum $readonly if set to false cannot modify - * \enum $size size for the text type - * \enum $selected selected value for the radio or select - * \enum $table if we want to make a HTML table row the value is return with <TD> - * \enum $label text before the input tag - * \enum $disabled to disable the type - * \enum $extra depends of the input type - * \enum $extra2 depends of the input type - * \enum $tabindex the tabindex - * \brief - */ - var $type; /*! \enum $type type of the widget */ - var $name; /*! \enum $name field NAME of the INPUT */ - var $value; /*! \enum $value what the INPUT contains */ - var $readonly; /*! \enum $readonly true : we cannot change value */ - var $size; /*! \enum $size size of the input */ - var $selected; /*! \enum $selected for SELECT RADIO and CHECKBOX the selected value */ - var $table; /*! \enum $table =1 add the table tag */ - var $label; /*! \enum $label the question before the input */ - var $disabled; /*! \enum $disabled poss. value == true or nothing, to disable INPUT*/ - var $extra; /*! \enum $extra different usage, it depends of the $type */ - var $extra2; /*! \enum $extra2 different usage, it depends of the $type */ + 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; + var $tabindex; - function widget($p_type="") { + function widget($p_type="",$p_label="",$p_name="",$p_value="") { $this->type=$p_type; + $this->name=$p_name; $this->readonly=false; $this->size=20; $this->width=50; $this->heigh=20; - $this->value=""; + $this->value=$p_value; $this->selected=""; $this->table=0; - $this->label=""; + $this->label=$p_label; $this->disabled=false; + $this->javascript=""; + $this->extra2="all"; } function SetReadOnly($p_read) { $this->readonly=$p_read; @@ -124,7 +120,8 @@ class widget { $disabled = $this->disabled ? "DISABLED" : ""; if (strtoupper($this->type)=="TEXT") { if ( $this->readonly==false) { - $r="name\" NAME=\"$this->name\" VALUE=\"$this->value\" SIZE=\"$this->size\" ".$disabled.">"; + $r="name\" ". + " NAME=\"$this->name\" VALUE=\"$this->value\" SIZE=\"$this->size\" ".$this->javascript." ".$disabled.">"; } else { $r=sprintf('%s', $this->value,$this->name,$this->name,$this->value); } @@ -173,7 +170,7 @@ class widget { } if ( $this->table==1) { $r=" $r "; - if ( $this->label != "") $r=" $this->label".$r; + if ( $this->label != "") $r=" $this->label".$r; } return $r; } @@ -321,7 +318,8 @@ class widget { if ( $this->table==1) $r="$this->label$r"; return $r; } - // input type == js_search_poste => button search for the account + //---------------------------------------------------------------------- + // input type == js_search_poste => button search for the account if ( strtolower($this->type)=="js_search_poste") { $l_sessid=$_REQUEST['PHPSESSID']; @@ -332,13 +330,14 @@ class widget { %s - + ', $l_sessid, $this->name, $this->extra, $this->label, $this->name, + $this->name, $this->value ); @@ -383,7 +382,7 @@ class widget { %s - + ', $l_sessid, @@ -427,32 +426,41 @@ class widget { if ( $this->table==1) { $r=sprintf(' - + %s - ', - $l_sessid, - $this->extra, - $this->name, - $this->extra2, - $this->label, - $this->name, - $this->value - ); + ' NAME="%s" ID="%s" VALUE="%s" SIZE="8" onBlur="ajaxFid(\'%s\',\'%s\',\'%s\')">', + $l_sessid, + $this->extra, + $this->name, + $this->extra2, + $this->label, + $this->name, + $this->name, + $this->value, + $this->name, + $this->extra, //deb or cred + $this->extra2 //jrn + + ); } else { $r=sprintf(' - + %s ', - $l_sessid, - $this->extra, - $this->name, - $this->extra2, - $this->label, - $this->name, - $this->value + ' NAME="%s" ID="%s" VALUE="%s" SIZE="8" onBlur="ajaxFid(\'%s\',\'%s\',\'%s\')">', + $l_sessid, + $this->extra, + $this->name, + $this->extra2, + $this->label, + $this->name, + $this->name, + $this->value, + $this->name, + $this->extra, //deb or cred + $this->extra2 //jrn + ); } } else { @@ -523,16 +531,17 @@ class widget { $l_sessid=$_REQUEST['PHPSESSID']; $r=sprintf("$td - + %s $etd $td $etd", - $l_sessid, - $this->name, - $this->extra, - $this->label, - $this->name, - $this->value + $l_sessid, + $this->name, + $this->extra, + $this->extra2, + $this->label, + $this->name, + $this->value ); } else { $r=sprintf("$td%s %s",$this->label,$this->value); @@ -541,6 +550,17 @@ class widget { return $r; }// end js_concerned + //---------------------------------------------------------------------- + // BUTTON + //---------------------------------------------------------------------- + if ( strtolower($this->type)=="button") { + if ( $this->readonly==true) return ""; + $r='"; + return $r; + } return "INVALID WIDGET $this->type "; } //end function /* Debug diff --git a/include/constant.php b/include/constant.php index d444eedde..be8ba0673 100644 --- a/include/constant.php +++ b/include/constant.php @@ -27,7 +27,7 @@ $_ENV['TMP']="/tmp"; define ("phpcompta_password","dany"); define ("phpcompta_psql_port","5432"); define ("phpcompta_user","phpcompta"); -define ("domaine",""); +define ("domaine","rel240_"); define ("DEBUG","true"); @@ -179,6 +179,9 @@ define ("JS_CALC_LINE",'
' ); +define ("JS_COMPUTE_ODS", +""); + define ("JS_SHOW_TVA"," Mot de passe est modifié"; } } $url=$_SERVER['REQUEST_URI']; +if ( ! isset ($_SESSION['g_dossier']) ) + { + echo ''; + } ?> -

Password

+

Mot de passe

@@ -54,7 +60,6 @@ $url=$_SERVER['REQUEST_URI']; "; ?> -

Thème

+

Thème

@@ -90,29 +95,35 @@ $disp_style.=""; // Si utilise un dossier alors propose de changer // la periode par defaut -if ( isset ($_SESSION['g_dossier']) ) { - - include_once("preference.php"); - $msg=""; - - if ( isset ($_POST["sub_periode"] ) ) { - $periode=$_POST["periode"]; - $User->SetPeriode($periode); - echo_debug('pref.inc',__LINE__,"Periode returns ".PeriodeClosed($cn,$periode)); - } - - $l_user_per=$User->GetPeriode(); - // if periode is closed then warns the users - if ( PeriodeClosed($cn,$l_user_per)=='t') +if ( ! isset ($_SESSION['g_dossier']) ) { - $msg= '

Attention cette période est fermée, vous ne pourrez rien modifier dans le module comptable

'; + echo ''; } +else + { + include_once("preference.php"); + $msg=""; + $cn=DbConnect($_SESSION['g_dossier']); + if ( isset ($_POST["sub_periode"] ) ) + { + $periode=$_POST["periode"]; + $User->SetPeriode($periode); + echo_debug('pref.inc',__LINE__,"Periode returns ".PeriodeClosed($cn,$periode)); + } - $l_form_per=FormPeriode($cn,$l_user_per,ALL); + $l_user_per=$User->GetPeriode(); + // if periode is closed then warns the users + if ( PeriodeClosed($cn,$l_user_per)=='t') + { + $msg= '

Attention cette période est fermée, vous ne pourrez rien modifier dans le module comptable

'; + } + -?> -

Période

+ $l_form_per=FormPeriode($cn,$l_user_per,ALL); + + ?> +

Période

@@ -134,9 +145,9 @@ if ( isset ($_SESSION['g_dossier']) ) { "; // date $r.="'; + $w=new widget("checkbox"); + $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 widget("hidden"); + $h->name="set_jr_id".$row['jr_id']; + $r.=''; + if ( $row['jr_rapt']=='paid') + $amount_paid+=$row['jr_montant']; + else + $amount_unpaid+=$row['jr_montant']; } // Rapprochement @@ -658,7 +690,9 @@ $sort_echeance=""; $r.=''; $r.='"; + $r.=""; + if ( $p_paid != 0 ) { + $r.=""; + $r.=''; + $r.='"; + $r.=""; + $r.=""; + $r.=''; + $r.='"; + $r.=""; + } $r.="
$image_ascEch //internal code // button modify $r.=""; - // If url contains - $r.=sprintf('%s', - $row['jr_id'], $l_sessid, $p_jrn, $row['jr_internal']); + // If url contains + // + + $href=basename($_SERVER['PHP_SELF']); + echo_debug(__FILE__,__LINE__,"href = $href"); + switch ($href) + { + // user_jrn.php + case 'user_jrn.php': + $vue="E"; //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); + } + + $r.=sprintf('%s', + $row['jr_id'], $l_sessid, $p_jrn,$vue, $row['jr_internal']); $r.=""; @@ -640,14 +668,18 @@ $sort_echeance=" $image_ascEch // Show the paid column if p_paid is not null if ( $p_paid !=0 ) { - $w=new widget("checkbox"); - $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 widget("hidden"); - $h->name="set_jr_id".$row['jr_id']; - $r.=''.$w->IOValue().$h->IOValue().''.$w->IOValue().$h->IOValue().' $image_ascEch foreach ($a as $key => $element) { - $r.= " ".GetInternal($p_cn,$element).""; + $l_amount=getDbValue($p_cn,"select jr_montant from jrn ". + " where jr_id=$element"); + $r.= " ".GetInternal($p_cn,$element)." [ $l_amount € ]"; }//for }// if ( $a != null ) { $r.=""; @@ -694,9 +728,20 @@ $sort_echeance=" $image_ascEch $r.="
Total'.$tot."
Payé'.$amount_paid."
Non payé'.$amount_unpaid."
"; -return array ($count,$r); + return array ($count,$r); } @@ -876,7 +921,8 @@ function DeleteRapt($p_cn,$jr_id,$jr_id2) { * \return array if something is found or null */ function GetConcerned ($p_cn, $jr_id) { -$sql=" select jr_id as cn from jrn_rapt where jra_concerned=$jr_id + echo_debug(__FILE__.":".__LINE__."Get Concerned"); + $sql=" select jr_id as cn from jrn_rapt where jra_concerned=$jr_id union select jra_concerned as cn from jrn_rapt where jr_id=$jr_id"; $Res=ExecSql($p_cn,$sql); diff --git a/include/user_form_ach.php b/include/user_form_ach.php index 8915ec089..1b31f199f 100644 --- a/include/user_form_ach.php +++ b/include/user_form_ach.php @@ -28,7 +28,9 @@ require_once("preference.php"); require_once("fiche_inc.php"); require_once("user_common.php"); require_once("class_parm_code.php"); - +require_once ('class_plananalytic.php'); +require_once ('class_own.php'); +require_once ('class_operation.php'); /*! * \brief Display the form for a sell * Used to show detail, encode a new invoice @@ -466,12 +468,13 @@ function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number) * \param $p_periode * \param $p_array array of value * \param $p_number nb of item - *\param $piece == true we can upload a doc. + *\param $p_piece == true we can upload a doc. * */ function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$p_number,$p_piece=true) { + echo_debug(__FILE__.':'.__LINE__.'- FormAchView'); $r=""; $data=""; // Keep all the data if hidden @@ -481,7 +484,39 @@ function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$p_number,$p_pi $data.=$hidden->IOValue($name,$content); ${"$name"}=$content; } - + // Compute href + // $href=basename($_SERVER['PHP_SELF']); + $href=basename($_SERVER['PHP_SELF']); + switch ($href) + { + // user_jrn.php + case 'user_jrn.php': + $href="user_jrn.php?action=new&p_jrn=$p_jrn"; + break; + case 'commercial.php': + $href="commercial.php?p_action=depense&p_jrn=$p_jrn"; + break; + default: + echo_error('user_form_ach.php',__LINE__,'Erreur invalid request uri'); + exit (-1); + } + //---------------------------------------------------------------------- + // Compute the col head for CA + $head_ca=""; + $own = new Own($p_cn); + if ( $own->MY_ANALYTIC != "un" ) + { + $plan=new PlanAnalytic($p_cn); + $a_plan=$plan->get_list(); + foreach ($a_plan as $r_plan) + { + $head_ca.="".$r_plan['name'].""; + } + + } + //---------------------------------------------------------------------- + + $r.=''; // start table $r.=''; // Show the Date @@ -500,6 +535,7 @@ function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$p_number,$p_pi // Show desc $r.=""; $r.=""; + $r.=""; $sum_with_vat=0.0; @@ -513,14 +549,15 @@ function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$p_number,$p_pi $r.=""; $r.=""; $r.=""; + $r.=$head_ca; $r.=""; for ($i=0;$i<$p_number;$i++) { if ( trim(${"e_march$i"}) == "" ) - { - // no goods to sell - continue; - } + { + // no goods to sell + continue; + } // Get the name $fiche_name=getFicheName($p_cn,${"e_march$i"}); @@ -533,14 +570,16 @@ function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$p_number,$p_pi // If the price is not a number, retrieve the price from the database - if ( isNumber(${"e_march$i"."_buy"}) == 0 ) { - $fiche_price=getFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_PRIX_VENTE); - } else { - $fiche_price=${"e_march$i"."_buy"}; - } + if ( isNumber(${"e_march$i"."_buy"}) == 0 ) + { + $fiche_price=getFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_PRIX_VENTE); + } else + { + $fiche_price=${"e_march$i"."_buy"}; + } // round it $fiche_price=round($fiche_price,2); - + // get TVA Amount $tva_amount=round(${"e_march".$i."_tva_amount"},2); @@ -551,15 +590,15 @@ function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$p_number,$p_pi // vat rate $a_vat=GetTvaRate($p_cn,$vat); if ( $a_vat == null ) - { - $vat_label=""; - $vat_rate=0.0; - } + { + $vat_label=""; + $vat_rate=0.0; + } else - { - $vat_label=$a_vat['tva_label']; - $vat_rate=$a_vat['tva_rate']; - } + { + $vat_label=$a_vat['tva_label']; + $vat_rate=$a_vat['tva_rate']; + } // Total card without vat $fiche_sum=$fiche_price*$fiche_quant; @@ -567,20 +606,23 @@ function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$p_number,$p_pi $sum_march+=$fiche_sum; // vat of the card if ( $tva_amount == 0) - { - $fiche_amount_vat=round($fiche_price*$fiche_quant*$vat_rate,2); - // value card + vat - $fiche_with_vat=round($fiche_price*$fiche_quant,2)+$fiche_amount_vat; - } + { + $fiche_amount_vat=round($fiche_price*$fiche_quant*$vat_rate,2); + echo_debug(__FILE__.':'.__LINE__.'- Tva Amount is computed '.$fiche_amount_vat); + + // value card + vat + $fiche_with_vat=round($fiche_price*$fiche_quant,2)+$fiche_amount_vat; + } else - { - $fiche_amount_vat=$tva_amount; - // value card + vat - $fiche_with_vat=round($fiche_price*$fiche_quant,2)+$tva_amount_vat; - } + { + echo_debug(__FILE__.':'.__LINE__.'- Tva Amount is given '.$tva_amount); + $fiche_amount_vat=$tva_amount; + // value card + vat + $fiche_with_vat=round($fiche_price*$fiche_quant,2)+$tva_amount; + } // Sum of invoice vat $sum_with_vat+=$fiche_with_vat; - + echo_debug(__FILE__.':'.__LINE__.'- Sum_with_vat='.$fiche_with_vat); // Show the data $r.=''; $r.=''; @@ -591,7 +633,44 @@ function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$p_number,$p_pi $r.=''; $r.=''; + //---------------------------------------------------------------------- + // CA + //---------------------------------------------------------------------- + // to show a select list for the analytic + // if analytic is op (optionnel) there is a blank line + // encode the pa + + if ( $own->MY_ANALYTIC!='un') // use of AA + { + // for each plan + $plan=new PlanAnalytic($p_cn); + $a_plan=$plan->get_list(); + $null=($own->MY_ANALYTIC=='op')?1:0; + foreach ($a_plan as $r_plan) + { + $array=make_array($p_cn, + "select po_id as value,". + " po_name as label from poste_analytique ". + " where pa_id = ".$r_plan['id']. + " order by po_name",$null); + $select = new widget("select","","p_".$r_plan['id']."_".$i,$array); + $select->table=1; + + // view only or editable + if ( $p_piece ) { + $select->readonly=false; + } else { + $select->readonly=true; + $select->selected=${"p_".$r_plan['id']."_".$i}; + } + + $r.=$select->IOValue(); + + } + } + + //---------------------------------------------------------------------- $r.=""; } @@ -603,24 +682,7 @@ function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$p_number,$p_pi $r.=""; - // Compute href - // $href=basename($_SERVER['PHP_SELF']); - $href=basename($_SERVER['PHP_SELF']); - switch ($href) - { - // user_jrn.php - case 'user_jrn.php': - $href="user_jrn.php?action=new&p_jrn=$p_jrn"; - break; - case 'commercial.php': - $href="commercial.php?p_action=depense&p_jrn=$p_jrn"; - break; - default: - echo_error('user_form_ach.php',__LINE__,'Erreur invalid request uri'); - exit (-1); - } - - $r.=''; + // check for upload piece // Set correctly the REQUEST param for jrn_type $h=new widget('hidden'); @@ -687,6 +749,8 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) $amount=0.0; $amount_jrn=0.0; $sum_tva_nd=0.0; + // own + $own=new own($p_cn); // Computing total customer for ($i=0;$i<$nb_item;$i++) { // store quantity & goods in array @@ -698,16 +762,20 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) // check wether the price is set or no if ( isNumber(${"e_march$i"."_buy"}) == 0 ) { - if ( $a_good[$i] !="" ) { - // If the price is not set we have to find it from the database - $a_price[$i]=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_PRIX_VENTE); - } - } else { - // The price is valid - $a_price[$i]=${"e_march$i"."_buy"}; - } - $a_price[$i]=round($a_price[$i],2); + if ( $a_good[$i] !="" ) + { + // If the price is not set we have to find it from the database + $a_price[$i]=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_PRIX_VENTE); + } + } + else + { + // The price is valid + $a_price[$i]=${"e_march$i"."_buy"}; + } + $a_price[$i]=round($a_price[$i],2); + $cost=$a_price[$i]*$a_quant[$i]; $amount+=$cost; $amount_jrn+=$cost; @@ -719,143 +787,211 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) // Compute vat with ded echo_debug('user_form_achat.php',__LINE__,"Call ComputeTotalVat"); $a_vat=ComputeTotalVat($p_cn,$a_good,$a_quant,$a_price,$a_vat_good,$a_vat_amount,false); - - StartSql($p_cn); - - // Compute the j_grpt - $seq=NextSequence($p_cn,'s_grpt'); - - - - // Credit = goods - for ( $i = 0; $i < $nb_item;$i++) { - - $poste=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_ACCOUNT); - - // don't record operation of 0 - if ( $a_price[$i]*$a_quant[$i] == 0 ) continue; - - $amount=$a_price[$i]*$a_quant[$i]; - // Put the non deductible part into a special account - $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_DEPENSE_NON_DEDUCTIBLE); - echo_debug('user_form_ach.php',__LINE__,"value non ded : $non_dedu"); - if ( $non_dedu != null && strlen(trim($non_dedu)) != 0) - { - // if vat if given we use it to compute ND - $nd_amount=($a_vat_amount[$i]==0)?round($a_quant[$i]*$a_price[$i]*$non_dedu,2):round($a_vat_amount*$non_dedu,2); - - // save it - echo_debug('user_form_ach.php',__LINE__,"InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,'6740',$e_date,round($nd_amount,2),$seq,$periode);"); - $dna=new parm_code($p_cn,'DNA'); - $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$dna->p_value,$e_date,round($nd_amount,2),$seq,$periode); - if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");} - $amount=$amount-$nd_amount; - } - // Put the non deductible part into a special account - $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_TVA_NON_DEDUCTIBLE); - echo_debug('user_form_ach.php',__LINE__,"TVA value non ded : $non_dedu"); - if ( $non_dedu != null && strlen(trim($non_dedu)) != 0) - { - //We don't compute vat if it's given - $lvat=($a_vat_amount[$i]==0)?ComputeVat($p_cn, $a_good[$i],$a_quant[$i],$a_price[$i], - $a_vat_good[$i],$a_vat_amount[$i] ):$a_vat_amount[$i] -; - $ded_vat=($lvat != null )?$lvat*$non_dedu:0; - $ded_vat=round($ded_vat,2); - $sum_tva_nd+=$ded_vat; - - // compute the NDA TVA - $tva_dna=new parm_code($p_cn,'TVA_DNA'); - echo_debug('user_form_ach.php',__LINE__, - "InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,".$tva_dna->p_value.",$e_date,round($ded_vat,2),$seq,$periode);"); - - $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$tva_dna->p_value,$e_date,round($ded_vat,2),$seq,$periode); - if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");} - } + try { + StartSql($p_cn); - // Put the non deductible part into a special account - $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP); - echo_debug('user_form_ach.php',__LINE__,"TVA value non ded : $non_dedu"); - if ( $non_dedu != null && strlen(trim($non_dedu)) != 0 ) - { + // Compute the j_grpt + $seq=NextSequence($p_cn,'s_grpt'); + // Set Internal code and Comment + $internal=SetInternalCode($p_cn,$seq,$p_jrn); + + + + // Credit = goods + for ( $i = 0; $i < $nb_item;$i++) { + + // store not deductible and vat deductible via tax + $aNd_amount[$i]=0.0; + $aTva_ded_impot[$i]=0.0; + $aTva_ded_impot_recup[$i]=0.0; + + $poste=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_ACCOUNT); + + // don't record operation of 0 + if ( $a_price[$i]*$a_quant[$i] == 0 ) continue; + + $amount=$a_price[$i]*$a_quant[$i]; //We don't compute vat if it's given $lvat=($a_vat_amount[$i]==0)?ComputeVat($p_cn,$a_good[$i],$a_quant[$i],$a_price[$i], $a_vat_good[$i],$a_vat_amount[$i] ):$a_vat_amount[$i]; - $ded_vat=($lvat != null )?$lvat*$non_dedu:0; + // Put the non deductible part into a special account + $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_DEPENSE_NON_DEDUCTIBLE); + echo_debug('user_form_ach.php',__LINE__,"value non ded : $non_dedu"); + if ( $non_dedu != null && strlen(trim($non_dedu)) != 0) + { + // if vat if given we use it to compute ND + $nd_amount=($a_vat_amount[$i]==0)?round($a_quant[$i]*$a_price[$i]*$non_dedu,2):round($a_vat_amount*$non_dedu,2); + + // save it + echo_debug('user_form_ach.php',__LINE__,"InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,'6740',$e_date,round($nd_amount,2),$seq,$periode);"); + $dna=new parm_code($p_cn,'DNA'); + $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$dna->p_value,$e_date,round($nd_amount,2),$seq,$periode); + $amount=$amount-$nd_amount; + + // save the ND in an array (for the easy view) + $aNd_amount[$i]=$nd_amount; + } + // Put the non deductible part into a special account + $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_TVA_NON_DEDUCTIBLE); + echo_debug('user_form_ach.php',__LINE__,"TVA value non ded : $non_dedu"); + if ( $non_dedu != null && strlen(trim($non_dedu)) != 0) + { + $ded_vat=($lvat != null )?$lvat*$non_dedu:0; + $ded_vat=round($ded_vat,2); + $aTva_ded_impot[$i]=$ded_vat; + $sum_tva_nd+=$ded_vat; + + // compute the NDA TVA + $tva_dna=new parm_code($p_cn,'TVA_DNA'); + echo_debug('user_form_ach.php',__LINE__, + "InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,".$tva_dna->p_value.",$e_date,round($ded_vat,2),$seq,$periode);"); + + $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$tva_dna->p_value,$e_date,round($ded_vat,2),$seq,$periode); + } - $sum_tva_nd+=round($ded_vat,2); + // Put the non deductible part into a special account + $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP); + echo_debug('user_form_ach.php',__LINE__,"TVA value non ded : $non_dedu"); - // Save it - $tva_ded_impot=new parm_code($p_cn,'TVA_DED_IMPOT'); - echo_debug('user_form_ach.php',__LINE__, - "InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,".$tva_ded_impot->p_value.",$e_date,round($ded_vat,2),$seq,$periode);"); + if ( $non_dedu != null && strlen(trim($non_dedu)) != 0 ) + { + + $ded_vat=($lvat != null )?$lvat*$non_dedu:0; + + $sum_tva_nd+=round($ded_vat,2); + $aTva_ded_impot_recup[$i]=round($ded_vat,2); + + // Save it + $tva_ded_impot=new parm_code($p_cn,'TVA_DED_IMPOT'); + echo_debug('user_form_ach.php',__LINE__, + "InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,".$tva_ded_impot->p_value.",$e_date,round($ded_vat,2),$seq,$periode);"); + + $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$tva_ded_impot->p_value,$e_date,round($ded_vat,2),$seq,$periode); + } + - $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$tva_ded_impot->p_value,$e_date,round($ded_vat,2),$seq,$periode); - if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");} - } + + + // record into jrnx + echo_debug('user_form_ach.php',__LINE__,"InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($amount,2),$seq,$periode);"); + $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($amount,2),$seq,$periode,$a_good[$i]); + + /* \brief if the quantity is < 0 then the stock increase (return of + * material) + */ + $nNeg=($a_quant[$i]<0)?-1:1; + // always save quantity but in withStock we can find what card need a stock management + InsertStockGoods($p_cn,$j_id,$a_good[$i],$nNeg*$a_quant[$i],'d'); + echo_debug('user_form_ach.php',__LINE__,"value non ded : ".$a_good[$i]."is"); + if ( $own->MY_ANALYTIC != "un" ) + { + // for each item, insert into operation_analytique + $plan=new PlanAnalytic($p_cn); + $a_plan=$plan->get_list(); + foreach ($a_plan as $r_plan) + { + + if ( isset(${"p_".$r_plan['id']."_".$i})&& ${"p_".$r_plan['id']."_".$i} != -1) + { + + $op=new operation($p_cn); + $op->po_id=${"p_".$r_plan['id']."_".$i}; + $op->oa_group=$group; + $op->j_id=$j_id; + $op->pa_id=$r_plan['id']; + $op->oa_amount=round($a_price[$i]*$a_quant[$i],2); + $op->oa_debit=($op->oa_amount < 0 )?'f':'t'; + $op->oa_date=$e_date; + $op->add(); + } + } + } + //--------------------------------------------------------- + // insert into quant_purchase + //--------------------------------------------------------- + + echo_debug(__FILE__.":".__LINE__,"a_vat = ",$a_vat); + echo_debug(__FILE__.":".__LINE__."a_vat[$i] =",$a_vat[$i]); + //!\note + // $a_vat_good[$i] contains the tva_id + // $a_vat_amount[$i] contains the amount of vat + $vat_code=$a_vat_good[$i]; + $computed_vat=$lvat-$aNd_amount[$i]-$aTva_ded_impot[$i]-$aTva_ded_impot_recup[$i]; + + echo_debug('form_ach',__LINE__,"Insert into insert_quant_purchase"); + $r=ExecSql($p_cn,"select insert_quant_purchase ". + "('".$internal."'". + ",".$j_id. + ",'".$a_good[$i]."'". + ",".$a_quant[$i].",". + round($amount,2). + ",".$computed_vat. + ",".$vat_code. + ",".$aNd_amount[$i]. + ",".$aTva_ded_impot[$i]. + ",".$aTva_ded_impot_recup[$i]. + ",'".$e_client."')"); + + + + } // end loop + + // set up internal code for quant_purchase + // Insert Vat + $sum_tva=0.0; + if ( $a_vat != null ) // no vat + { + echo_debug('user_form_ach',__LINE__,'a_vat = '.var_export($a_vat,true)); + foreach ($a_vat as $tva_id => $e_tva_amount ) + { + echo_debug('user_form_ach',__LINE__," tva_amount = $e_tva_amount tva_id=$tva_id"); + $poste=GetTvaPoste($p_cn,$tva_id,'d'); + if ($e_tva_amount == 0 ) continue; + echo_debug('user_form_ach',__LINE__,"InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($e_tva_amount,2),$seq,$periode);"); + $r=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($e_tva_amount,2),$seq,$periode); + $sum_tva+=round($e_tva_amount,2); + } + } + echo_debug('user_form_ach.php',__LINE__,"echeance = $e_ech"); + echo_debug('user_form_ach.php',__LINE__,"sum_tva = $sum_tva"); + echo_debug('user_form_ach.php',__LINE__,"amount_jrn = $amount_jrn"); + echo_debug('user_form_ach.php',__LINE__,"sum_tva_nd = $sum_tva_nd"); + + // Debit = client + $poste=GetFicheAttribut($p_cn,$e_client,ATTR_DEF_ACCOUNT); + echo_debug('user_form_achat.php',__LINE__,"get e_client $e_client poste $poste"); + echo_debug('user_form_achat.php',__LINE__,"insert client"); + + $r=InsertJrnx($p_cn,'c',$p_user->id,$p_jrn,$poste,$e_date,round($amount_jrn+$sum_tva+$sum_tva_nd,2),$seq, + $periode,$e_client); + + + $r=InsertJrn($p_cn,$e_date,$e_ech,$p_jrn,"--",$seq,$periode); + + // Set Internal code and Comment + $Res=ExecSql($p_cn,"update jrn set jr_internal='".$internal."' where ". + " jr_grpt_id = ".$seq); + $comment=(FormatString($e_comm) == null )?$internal." Fournisseur : ".GetFicheName($p_cn,$e_client):FormatString($e_comm); - // record into jrnx - echo_debug('user_form_ach.php',__LINE__,"InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($amount,2),$seq,$periode);"); - $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($amount,2),$seq,$periode,$a_good[$i]); - if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");} - // always save quantity but in withStock we can find what card need a stock management - if ( InsertStockGoods($p_cn,$j_id,$a_good[$i],$a_quant[$i],'d') == false ) { - $Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");} - echo_debug('user_form_ach.php',__LINE__,"value non ded : ".$a_good[$i]."is"); + // Update and set the invoice's comment + $Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq); + if ( isset ($_FILES)) + save_upload_document($p_cn,$seq); + + } catch (Exception $e) { + echo ''. + 'Erreur dans l\'enregistrement '. + __FILE__.':'.__LINE__.' '. + $e->getMessage(); + Rollback($p_cn); + exit(); } - - - // Insert Vat - $sum_tva=0.0; - if ( $a_vat != null ) // no vat - { - echo_debug('user_form_ach',__LINE__,'a_vat = '.var_export($a_vat,true)); - foreach ($a_vat as $tva_id => $e_tva_amount ) - { - echo_debug('user_form_ach',__LINE__," tva_amount = $e_tva_amount tva_id=$tva_id"); - $poste=GetTvaPoste($p_cn,$tva_id,'d'); - if ($e_tva_amount == 0 ) continue; - echo_debug('user_form_ach',__LINE__,"InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($e_tva_amount,2),$seq,$periode);"); - $r=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($e_tva_amount,2),$seq,$periode); - if ( $r == false ) { Rollback($p_cn); exit(" Error 'user_form_ach.php' __LINE__");} - $sum_tva+=round($e_tva_amount,2); - } - } - echo_debug('user_form_ach.php',__LINE__,"echeance = $e_ech"); - echo_debug('user_form_ach.php',__LINE__,"sum_tva = $sum_tva"); - echo_debug('user_form_ach.php',__LINE__,"amount_jrn = $amount_jrn"); - echo_debug('user_form_ach.php',__LINE__,"sum_tva_nd = $sum_tva_nd"); - - // Debit = client - $poste=GetFicheAttribut($p_cn,$e_client,ATTR_DEF_ACCOUNT); - echo_debug('user_form_achat.php',__LINE__,"get e_client $e_client poste $poste"); - echo_debug('user_form_achat.php',__LINE__,"insert client"); - - $r=InsertJrnx($p_cn,'c',$p_user->id,$p_jrn,$poste,$e_date,round($amount_jrn+$sum_tva+$sum_tva_nd,2),$seq, - $periode,$e_client); - - if ( $r == false) { $Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");} - - $r=InsertJrn($p_cn,$e_date,$e_ech,$p_jrn,"--",$seq,$periode); - if ( $r == false ) { Rollback($p_cn); exit;} - // Set Internal code and Comment - $internal=SetInternalCode($p_cn,$seq,$p_jrn); - $comment=(FormatString($e_comm) == null )?$internal." Fournisseur : ".GetFicheName($p_cn,$e_client):FormatString($e_comm); - - // Update and set the invoice's comment - $Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq); - if ( $Res == false ) { Rollback($p_cn); exit(" Error 'user_form_ach.php' __LINE__"); }; - - if ( isset ($_FILES)) - save_upload_document($p_cn,$seq); - - Commit($p_cn); - + return array($internal,$comment); } diff --git a/include/user_form_fin.php b/include/user_form_fin.php index 4f7f123a9..75b46781c 100644 --- a/include/user_form_fin.php +++ b/include/user_form_fin.php @@ -279,6 +279,7 @@ function FormFin($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru $wConcerned->SetReadOnly($pview_only); $wConcerned->extra=0; $wConcerned->table=1; + $wConcerned->extra2='paid'; $r.=$wConcerned->IOValue("e_concerned".$i,${"e_concerned".$i}); $r.=''; // if not recorded the new amount must be recalculate @@ -312,6 +313,9 @@ $r.=""; // if view_only is true //Put the new saldo here (old saldo - operation) if ( $pview_only==true) { + $solde=round($solde,2); + $new_solde=round($new_solde,2); + // if not recorded the new amount must be recalculate if ( $p_save == false) { $r.=" Ancien Solde = ".$solde."
"; @@ -363,71 +367,85 @@ function RecordFin($p_cn,$p_array,$p_user,$p_jrn) { // Debit = banque $poste_bq=GetFicheAttribut($p_cn,$e_bank_account,ATTR_DEF_ACCOUNT); - StartSql($p_cn); - $amount=0.0; - // 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 ( ${"e_other$i"."_amount"} == 0 ) continue; - $poste=GetFicheAttribut($p_cn,${"e_other$i"},ATTR_DEF_ACCOUNT); + try + { + StartSql($p_cn); + $amount=0.0; + // 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 ( ${"e_other$i"."_amount"} == 0 ) continue; + $poste=GetFicheAttribut($p_cn,${"e_other$i"},ATTR_DEF_ACCOUNT); - // round it - ${"e_other$i"."_amount"}=round( ${"e_other$i"."_amount"},2); + // round it + ${"e_other$i"."_amount"}=round( ${"e_other$i"."_amount"},2); - $amount+=${"e_other$i"."_amount"}; - // Record a line for the bank - // Compute the j_grpt - $seq=NextSequence($p_cn,'s_grpt'); - - if ( InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste_bq,$e_date,round(${"e_other$i"."_amount"},2), - $seq,$periode,$e_bank_account) == false ) { - $Rollback($p_cn);exit("error 'user_form_fin.php' __LINE__"); - } + $amount+=${"e_other$i"."_amount"}; + // Record a line for the bank + // Compute the j_grpt + $seq=NextSequence($p_cn,'s_grpt'); + // Set Internal code and Comment + $internal=SetInternalCode($p_cn,$seq,$p_jrn); - // Record a line for the other account - if ( ($j_id=InsertJrnx($p_cn,'c',$p_user->id,$p_jrn,$poste,$e_date,round(${"e_other$i"."_amount"},2),$seq,$periode,${"e_other$i"})) == false ) - { $Rollback($p_cn);exit("error 'user_form_fin.php' __LINE__");} + InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste_bq,$e_date,round(${"e_other$i"."_amount"},2), + $seq,$periode,$e_bank_account) ; - echo_debug('user_form_fin.php',__LINE__," $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,".${"e_other$i"}."_amount".",$seq,$periode);"); - if ( ($jr_id=InsertJrn($p_cn,$e_date,'',$p_jrn,FormatString(${"e_other$i"."_comment"}), - $seq,$periode))==false) { - $Rollback($p_cn);exit("error 'user_form_fin.php' __LINE__");} + // Record a line for the other account + $j_id=InsertJrnx($p_cn,'c',$p_user->id,$p_jrn,$poste,$e_date, + round(${"e_other$i"."_amount"},2),$seq,$periode,${"e_other$i"}); + + echo_debug('user_form_fin.php',__LINE__," $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,".${"e_other$i"}."_amount".",$seq,$periode);"); + + $jr_id=InsertJrn($p_cn,$e_date,'',$p_jrn,FormatString(${"e_other$i"."_comment"}), + $seq,$periode); - if ( isNumber(${"e_concerned".$i}) == 1 ) { + if ( isNumber(${"e_concerned".$i}) == 1 ) { - InsertRapt($p_cn,$jr_id,${"e_concerned$i"}); - } + InsertRapt($p_cn,$jr_id,${"e_concerned$i"}); + } - // Set Internal code and Comment - $internal_code=SetInternalCode($p_cn,$seq,$p_jrn); - $comment=$internal_code." compte : ".GetFicheName($p_cn,$e_bank_account); - if ( FormatString(${"e_other$i"."_comment"}) == null ) { - // Update comment if comment is blank - $Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq); - } + // Set Internal code and Comment + $Res=ExecSql($p_cn,"update jrn set jr_internal='".$internal."' where ". + " jr_grpt_id = ".$seq); + + $comment=$internal_code." compte : ".GetFicheName($p_cn,$e_bank_account); + if ( FormatString(${"e_other$i"."_comment"}) == null ) { + // Update comment if comment is blank + $Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq); + } - if ( $i == 0 ) - { - // first record we upload the files and - // keep variable to update other row of jrn - if ( isset ($_FILES)) - $oid=save_upload_document($p_cn,$seq); - - } else { - if ( $oid != 0 ) + if ( $i == 0 ) { - ExecSql($p_cn,"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 + // first record we upload the files and + // keep variable to update other row of jrn + if ( isset ($_FILES)) + $oid=save_upload_document($p_cn,$seq); + } else { + if ( $oid != 0 ) + { + ExecSql($p_cn,"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 + } + catch (Exception $e) + { + echo ''. + 'Erreur dans l\'enregistrement '. + __FILE__.':'.__LINE__.' '. + $e->getMessage(); + Rollback($p_cn); + exit(); + + } Commit($p_cn); return $internal_code; } diff --git a/include/user_form_ods.php b/include/user_form_ods.php index 5c80c8fec..0c8a9da96 100644 --- a/include/user_form_ods.php +++ b/include/user_form_ods.php @@ -25,6 +25,9 @@ require_once("class_widget.php"); require_once("preference.php"); require_once("fiche_inc.php"); require_once("user_common.php"); +require_once ('class_plananalytic.php'); +require_once ('class_own.php'); +require_once ('class_operation.php'); /*! \file * \brief Functions for the ledger of misc. operation */ @@ -46,13 +49,14 @@ require_once("user_common.php"); */ function FormODS($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=true,$p_article=6,$p_saved=false) { - include_once("poste.php"); + include_once("poste.php"); if ( $p_array != null ) { // array contains old value foreach ( $p_array as $a=>$v) { ${"$a"}=$v; } } + // The date list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode); $flag=(isset($e_date))?1:0; @@ -70,9 +74,12 @@ function FormODS($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru // Save old value and set a new one $r=""; + if ( $pview_only == false) { $r.=JS_SEARCH_POSTE; + $r.=JS_COMPUTE_ODS; } + $r.="
"; $r.='
Description : $e_comm
Montant HTVAMontant TVATotal
'.$fiche_name.''.round($fiche_amount_vat,2).''.round($fiche_with_vat,2).'
'; // Date @@ -93,20 +100,29 @@ function FormODS($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru include_once("fiche_inc.php"); // Record the current number of article - $r.=''; + $r.=''; $e_comment=(isset($e_comment))?$e_comment:""; - // Start the div for item to encode $r.="
"; $r.='

Opérations Diverses

'; $r.='
'; $r.=""; - $r.=""; + if ( $pview_only == false) $r.=""; $r.=""; $r.=""; $r.=""; - $r.=""; + $r.=""; + if ( $own->MY_ANALYTIC != "un" ) + { + $plan=new PlanAnalytic($p_cn); + $a_plan=$plan->get_list(); + foreach ($a_plan as $r_plan) + { + $r.=""; + } + + } $r.=""; $sum_deb=0.0; $sum_cred=0.0; @@ -116,7 +132,7 @@ function FormODS($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru $account=(isset(${"e_account$i"}))?${"e_account$i"}:""; - $lib=""; + $lib=''; // If $account has a value if ( isNumber($account) == 1 ) { if ( CountSql($p_cn,"select * from tmp_pcmn where pcm_val=$account") == 0 ) { @@ -127,25 +143,25 @@ function FormODS($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru if ( $pview_only == true ) return null; } else { // retrieve the tva label and name - $lib=GetPosteLibelle($p_cn, $account,1); + $lib=''.GetPosteLibelle($p_cn, $account,1).''; } } ${"e_account$i"."_amount"}=(isset(${"e_account$i"."_amount"}))?abs(round(${"e_account$i"."_amount"},2)):0; if ( isNumber(${"e_account$i"."_amount"}) == 0 ) { if ( $pview_only==true) { - $msg="Montant invalide !!! "; - echo_error($msg); echo_error($msg); - echo ""; - return null; + $msg="Montant invalide !!! "; + echo_error($msg); + echo ""; + return null; } - ${"e_account$i"."_amount"}=0; + ${"e_account$i"."_amount"}=0; } // code // Do we need a filter ? $l_line=GetJrnProp($_SESSION['g_dossier'],$p_jrn); - if( strlen(trim ($l_line['jrn_def_class_cred']) ) > 0 or - strlen(trim ($l_line['jrn_def_class_deb']) ) > 0 ) { + if( strlen(trim ($l_line['jrn_def_class_cred']) ) > 0 || + strlen(trim ($l_line['jrn_def_class_deb']) ) > 0 ) { $filter=1; } else @@ -163,6 +179,8 @@ function FormODS($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru $wAmount=new widget("text"); $wAmount->table=1; $wAmount->SetReadOnly($pview_only); + $wAmount->javascript=' onChange="checkTotal()"'; + $r.=$wAmount->IOValue("e_account".$i."_amount",${"e_account$i"."_amount"}); @@ -172,14 +190,45 @@ function FormODS($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru $d_check=( ${"e_account$i"."_type"} == 'd' )?"CHECKED":""; $r.=''; - $r.=''; + // Add CA + //-------------------------------------------------- + if ( ereg("^7+",${"e_account$i"}) || + ereg("^6+",${"e_account$i"})) + { + + if ( $own->MY_ANALYTIC!='un') // use of AA + { + // for each plan + $plan=new PlanAnalytic($p_cn); + $a_plan=$plan->get_list(); + $null=($own->MY_ANALYTIC=='op')?1:0; + foreach ($a_plan as $r_plan) + { + $array=make_array($p_cn, + "select po_id as value,". + " po_name as label from poste_analytique ". + " where pa_id = ".$r_plan['id']. + " order by po_name",$null); + $select = new widget("select","","p_".$r_plan['id']."_".$i,$array); + $select->table=1; + if ( $p_saved ) { + $select->readonly=true; + $select->selected= ${"p_".$r_plan['id']."_".$i}; + } + $r.=$select->IOValue(); + + } + + } + } + } + $r.=''; + $r.=''; $sum_deb+=(${"e_account$i"."_type"}=='d')?${"e_account$i"."_amount"}:0; $sum_cred+=(${"e_account$i"."_type"}=='c')?${"e_account$i"."_amount"}:0; } // End for @@ -195,11 +244,18 @@ function FormODS($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru $r.="".$file->IOValue("pj","","Pièce justificative").""; $r.="
ComptePosteMontantCrédit ou déditCrédit ou débit".$r_plan['name']."
'; if ( $pview_only == false ) { - $r.=' Débit ou '; - $r.=' Crédit '; + $r.=' Débit ou '; + $r.=' Crédit '; }else { - $r.=(${"e_account$i"."_type"} == 'c' )?"Crédit":"Dédit"; + $r.=(${"e_account$i"."_type"} == 'c' )?"Crédit":"Débit"; $r.=''; - } - $r.='
"; $r.="
"; + } else { + $r.= '
+ Débit = + Crédit = + Difference = +
+ '; } // Set correctly the REQUEST param for jrn_type $h=new widget('hidden'); $h->name='jrn_type'; - $h->value='OD'; + $h->value='ODS'; $r.=$h->IOValue(); $r.=$p_submit; @@ -222,7 +278,14 @@ function FormODS($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru echo ""; return null; } - + /* if not view only then a javascript will compute and check the + total */ + if ( ! $pview_only ) { + // Start compute + $r.=''; + } return $r; @@ -259,38 +322,80 @@ function RecordODS($p_cn,$p_array,$p_user,$p_jrn) $sum_deb=0.0; $sum_cred=0.0; + $own=new own($p_cn); // Compute the j_grpt $seq=NextSequence($p_cn,'s_grpt'); - - StartSql($p_cn); - // store into the database - for ( $i = 0; $i < $nb_item;$i++) { - if ( isNumber(${"e_account$i"}) == 0 ) continue; - $sum_deb+=(${"e_account$i"."_type"}=='d')?round(${"e_account$i"."_amount"},2):0; - $sum_cred+=(${"e_account$i"."_type"}=='c')?round(${"e_account$i"."_amount"},2):0; - - if ( ${"e_account$i"."_amount"} == 0 ) continue; - ${"e_account$i"."_amount"}=round(${"e_account$i"."_amount"},2); - if ( ($j_id=InsertJrnx($p_cn,${"e_account$i"."_type"},$p_user->id,$p_jrn,${"e_account$i"},$e_date,${"e_account$i"."_amount"},$seq,$periode)) == false ) { - $Rollback($p_cn);exit("error 'user_form_ods.php' __LINE__");} - } - - if ( InsertJrn($p_cn,$e_date,"",$p_jrn,$e_comm,$seq,$periode) == false ) { - $Rollback($p_cn);exit("error 'user_form_ods.php' __LINE__");} - // Set Internal code and Comment - $internal_code=SetInternalCode($p_cn,$seq,$p_jrn); - if ( $e_comm=="" ) { - // Update comment if comment is blank - $Res=ExecSql($p_cn,"update jrn set jr_comment='".$internal_code."' where jr_grpt_id=".$seq); - } - if ( isset ($_FILES)) - save_upload_document($p_cn,$seq); + $internal=SetInternalCode($p_cn,$seq,$p_jrn); + try + { + StartSql($p_cn); + // store into the database + for ( $i = 0; $i < $nb_item;$i++) { + if ( isNumber(${"e_account$i"}) == 0 ) continue; + $sum_deb+=(${"e_account$i"."_type"}=='d')?round(${"e_account$i"."_amount"},2):0; + $sum_cred+=(${"e_account$i"."_type"}=='c')?round(${"e_account$i"."_amount"},2):0; + + if ( ${"e_account$i"."_amount"} == 0 ) continue; + ${"e_account$i"."_amount"}=round(${"e_account$i"."_amount"},2); + $j_id=InsertJrnx($p_cn,${"e_account$i"."_type"},$p_user->id,$p_jrn,${"e_account$i"},$e_date,${"e_account$i"."_amount"},$seq,$periode); + // insert into ca + if ( $own->MY_ANALYTIC != "un" ) + { + // for each item, insert into operation_analytique + $plan=new PlanAnalytic($p_cn); + $a_plan=$plan->get_list(); + foreach ($a_plan as $r_plan) + { + + if ( isset(${"p_".$r_plan['id']."_".$i})&& ${"p_".$r_plan['id']."_".$i} != -1) + { + + $op=new operation($p_cn); + $op->po_id=${"p_".$r_plan['id']."_".$i}; + $op->oa_group=$group; + $op->j_id=$j_id; + $op->pa_id=$r_plan['id']; + $op->oa_amount=${"e_account$i"."_amount"}; + $op->oa_debit=($op->oa_amount < 0 )?'f':'t'; + $op->oa_date=$e_date; + echo_debug(__FILE__.":".__LINE__,"saving ca ",$op); + $op->add(); + } + } + } + + + + } + InsertJrn($p_cn,$e_date,"",$p_jrn,$e_comm,$seq,$periode) ; + + // Set Internal code and Comment + // Set Internal code and Comment + $Res=ExecSql($p_cn,"update jrn set jr_internal='".$internal."' where ". + " jr_grpt_id = ".$seq); + + if ( $e_comm=="" ) { + // Update comment if comment is blank + $Res=ExecSql($p_cn,"update jrn set jr_comment='".$internal_code."' where jr_grpt_id=".$seq); + } + if ( isset ($_FILES)) + save_upload_document($p_cn,$seq); + } + catch (Exception $e) + { + echo ''. + 'Erreur dans l\'enregistrement '. + __FILE__.':'.__LINE__.' '. + $e->getMessage(); + Rollback($p_cn); + exit(); + } Commit($p_cn); return $internal_code; } -?> \ No newline at end of file +?> diff --git a/include/user_form_ven.php b/include/user_form_ven.php index 5b0419b53..352b426f9 100644 --- a/include/user_form_ven.php +++ b/include/user_form_ven.php @@ -26,6 +26,9 @@ require_once("class_widget.php"); require_once("preference.php"); require_once("fiche_inc.php"); require_once("user_common.php"); +require_once ("class_own.php"); +require_once ("class_plananalytic.php"); +require_once ('class_operation.php'); /*! FormVenInput * \brief Display the form for a sell * Used to show detail, encode a new invoice @@ -41,6 +44,7 @@ require_once("user_common.php"); */ function FormVenInput($p_cn,$p_jrn,$p_periode,$p_array=null,$pview_only=true,$p_article=1) { + if ( $p_array != null ) { // array contains old value foreach ( $p_array as $a=>$v) { @@ -221,7 +225,7 @@ function FormVenInput($p_cn,$p_jrn,$p_periode,$p_array=null,$pview_only=true,$p_ $Quantity->size=9; //$r.=InputType("","TEXT","e_quant".$i,$quant,$pview_only); $r.=$Quantity->IOValue("e_quant".$i,$quant); - $r.=''; + } @@ -396,8 +400,10 @@ for ($o = 0;$o < $p_number; $o++) { function FormVenteView ($p_cn,$p_jrn,$p_periode,$p_array,$p_number,$p_doc='form',$p_comment='') { + $r=""; $data=""; + $head_ca=""; // Keep all the data if hidden // and store the array in variables $hidden=new widget("hidden"); @@ -405,7 +411,39 @@ function FormVenteView ($p_cn,$p_jrn,$p_periode,$p_array,$p_number,$p_doc='form' $data.=$hidden->IOValue($name,$content); ${"$name"}=$content; } - + // Compute href + // $href=basename($_SERVER['PHP_SELF']); + $href=basename($_SERVER['PHP_SELF']); + switch ($href) + { + // user_jrn.php + case 'user_jrn.php': + $href="user_jrn.php?action=record&p_jrn=$p_jrn"; + break; + case 'commercial.php': + $href="commercial.php?p_action=facture&sa=record&p_jrn=$p_jrn"; + break; + default: + echo_error('user_form_ven.php',__LINE__,'Erreur invalid request uri'); + exit (-1); + } + //---------------------------------------------------------------------- + // Compute the col head for CA + $head_ca=""; + $own = new Own($p_cn); + if ( $own->MY_ANALYTIC != "un" ) + { + $plan=new PlanAnalytic($p_cn); + $a_plan=$plan->get_list(); + foreach ($a_plan as $r_plan) + { + $head_ca.="".$r_plan['name'].""; + } + + } + //---------------------------------------------------------------------- + + $r.=''; // start table $r.=''; // Show the Date @@ -437,6 +475,7 @@ function FormVenteView ($p_cn,$p_jrn,$p_periode,$p_array,$p_number,$p_doc='form' $r.=""; $r.=""; $r.=""; + $r.=$head_ca; $r.=""; for ($i=0;$i<$p_number;$i++) { if ( trim(${"e_march$i"}) == "" ) { @@ -498,7 +537,40 @@ function FormVenteView ($p_cn,$p_jrn,$p_periode,$p_array,$p_number,$p_doc='form' $r.=''; $r.=''; + + // to show a select list for the analytic + // if analytic is op (optionnel) there is a blank line + $own = new Own($p_cn); + // encode the pa + if ( $own->MY_ANALYTIC!='un') // use of AA + { + // for each plan + $plan=new PlanAnalytic($p_cn); + $a_plan=$plan->get_list(); + $null=($own->MY_ANALYTIC=='op')?1:0; + foreach ($a_plan as $r_plan) + { + $array=make_array($p_cn, + "select po_id as value,". + " po_name as label from poste_analytique ". + " where pa_id = ".$r_plan['id']. + " order by po_name",$null); + $select = new widget("select","","p_".$r_plan['id']."_".$i,$array); + $select->table=1; + // view only or editable + if ( $p_doc=="form" ) { + // editable + $select->readonly=false; + } else { + // view only + $select->readonly=true; + $select->selected=${"p_".$r_plan['id']."_".$i}; + } + $r.=$select->IOValue(); + } + } + $r.=""; } @@ -511,25 +583,9 @@ function FormVenteView ($p_cn,$p_jrn,$p_periode,$p_array,$p_number,$p_doc='form' $r.=""; if ( $p_doc == 'form' ) { - // Compute href - // $href=basename($_SERVER['PHP_SELF']); - $href=basename($_SERVER['PHP_SELF']); - switch ($href) - { - // user_jrn.php - case 'user_jrn.php': - $href="user_jrn.php?action=record&p_jrn=$p_jrn"; - break; - case 'commercial.php': - $href="commercial.php?p_action=facture&sa=record&p_jrn=$p_jrn"; - break; - default: - echo_error('user_form_ven.php',__LINE__,'Erreur invalid request uri'); - exit (-1); - } - $r.=''; + // check for upload piece $file=new widget("file"); @@ -613,6 +669,8 @@ function RecordInvoice($p_cn,$p_array,$p_user,$p_jrn) // Get the default period $periode=$p_user->GetPeriode(); $amount=0.0; + $own=new own($p_cn); + $group=NextSequence($p_cn,"s_oa_group"); // Computing total customer //-- @@ -655,80 +713,125 @@ function RecordInvoice($p_cn,$p_array,$p_user,$p_jrn) // Compute the j_grpt $seq=NextSequence($p_cn,'s_grpt'); + $internal=SetInternalCode($p_cn,$seq,$p_jrn); // Debit = client $poste=GetFicheAttribut($p_cn,$e_client,ATTR_DEF_ACCOUNT); - StartSql($p_cn); - $r=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($amount,2)+round($sum_vat,2),$seq,$periode,$e_client); - if ( $r == false) { $Rollback($p_cn);exit("error 'user_form_ven.php' __LINE__");} - - // Credit = goods - for ( $i = 0; $i < $nb_item;$i++) { - if ( $a_good[$i] == "" ) continue; - $poste=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_ACCOUNT); - - // don't record operation of 0 - if ( $a_price[$i]*$a_quant[$i] == 0 ) continue; - - // record into jrnx - $j_id=InsertJrnx($p_cn,'c',$p_user->id,$p_jrn,$poste,$e_date,round($a_price[$i]*$a_quant[$i],2),$seq,$periode,$a_good[$i]); - if ( $j_id == false) { $Rollback($p_cn);exit("error 'user_form_ven.php' __LINE__");} - // always save quantity but in withStock we can find what card need a stock management - if ( InsertStockGoods($p_cn,$j_id,$a_good[$i],$a_quant[$i],'c') == false ) { - $Rollback($p_cn);exit("error 'user_form_ven.php' __LINE__");} - } // end loop - - // Insert Vat - - if ( $a_vat_new != null ) // no vat - + try { - foreach ($a_vat_new as $tva_id => $tva_amount ) { - $poste=GetTvaPoste($p_cn,$tva_id,'c'); - if ($tva_amount == 0 ) continue; - $r=InsertJrnx($p_cn,'c',$p_user->id,$p_jrn,$poste,$e_date,round($tva_amount,2),$seq,$periode); - if ( $r == false ) { Rollback($p_cn); exit(" Error 'user_form_ven.php' __LINE__");} - - } - } - echo_debug('user_form_ven.php',__LINE__,"echeance = $e_ech"); - $r=InsertJrn($p_cn,$e_date,$e_ech,$p_jrn,"Invoice",$seq,$periode); - if ( $r == false ) { Rollback($p_cn); exit;} - // Set Internal code and Comment - $internal=SetInternalCode($p_cn,$seq,$p_jrn); - $comment=(FormatString($e_comm) == null )?$internal." client : ".GetFicheName($p_cn,$e_client):FormatString($e_comm); + StartSql($p_cn); + $r=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($amount,2)+round($sum_vat,2),$seq,$periode,$e_client); - // Update and set the invoice's comment - $Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq); - if ( $Res == false ) { Rollback($p_cn); exit(" Error 'user_form_ven.php' __LINE__"); }; - if ( isset ($_FILES)) { - if ( sizeof($_FILES) != 0 ) - save_upload_document($p_cn,$seq); - } - -// save the quantity, then we can make an invoice - for ( $i=0;$i < $nb_item;$i++) - { - // don't record operation of 0 - if ( $a_price[$i]*$a_quant[$i] == 0 ) continue; + // Credit = goods + for ( $i = 0; $i < $nb_item;$i++) { + if ( $a_good[$i] == "" ) continue; + $poste=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_ACCOUNT); + + // don't record operation of 0 + if ( $a_price[$i]*$a_quant[$i] == 0 ) continue; + + // record into jrnx + $j_id=InsertJrnx($p_cn,'c',$p_user->id,$p_jrn,$poste,$e_date,round($a_price[$i]*$a_quant[$i],2),$seq,$periode,$a_good[$i]); - // insert into the table quant_sold - // Note that negative value are also saved but not the vat ! - if ( $a_vat[$i] == -1) { - $computed_vat=0; - $vat_code="null"; - } else { + /* \brief if the quantity is < 0 then the stock increase (return of + * material) + */ + $nNeg=($a_quant[$i]<0)?-1:1; + + // always save quantity but in withStock we can find + // what card need a stock management + + InsertStockGoods($p_cn,$j_id,$a_good[$i],$nNeg*$a_quant[$i],'c') ; + if ( $own->MY_ANALYTIC != "un" ) + { + // for each item, insert into operation_analytique + $plan=new PlanAnalytic($p_cn); + $a_plan=$plan->get_list(); + foreach ($a_plan as $r_plan) + { + + if ( isset(${"p_".$r_plan['id']."_".$i})&& ${"p_".$r_plan['id']."_".$i} != -1) + { + + $op=new operation($p_cn); + $op->po_id=${"p_".$r_plan['id']."_".$i}; + $op->oa_group=$group; + $op->j_id=$j_id; + $op->pa_id=$r_plan['id']; + $op->oa_amount=round($a_price[$i]*$a_quant[$i],2); + $op->oa_debit=($op->oa_amount < 0 )?'t':'f'; + $op->oa_date=$e_date; + $op->add(); + } + } + } $computed_vat=ComputeVat($p_cn,$a_good[$i],$a_quant[$i],$a_price[$i],$a_vat[$i]); - $vat_code=$a_vat[$i]; - } - $r=ExecSql($p_cn,"select insert_quant_sold ". - "('".$internal."','".$a_good[$i]."',".$a_quant[$i].",".$a_price[$i]*$a_quant[$i]. - ",".$computed_vat. - ",".$vat_code.",'".$e_client."')"); - if ( $r == false ) { Rollback($p_cn); exit(" Error 'user_form_ven.php' __LINE__"); }; - } + + $r=ExecSql($p_cn,"select insert_quant_sold ". + "('".$internal."',".$j_id.",'".$a_good[$i] + ."',".$a_quant[$i].",".$a_price[$i]*$a_quant[$i]. + ",".$computed_vat. + ",".$a_vat[$i].",'".$e_client."')"); + + + } // end loop + + // Insert Vat + + if ( $a_vat_new != null ) // no vat + + { + foreach ($a_vat_new as $tva_id => $tva_amount ) { + $poste=GetTvaPoste($p_cn,$tva_id,'c'); + if ($tva_amount == 0 ) continue; + $r=InsertJrnx($p_cn,'c',$p_user->id,$p_jrn,$poste,$e_date,round($tva_amount,2),$seq,$periode); + } + } + echo_debug('user_form_ven.php',__LINE__,"echeance = $e_ech"); + $r=InsertJrn($p_cn,$e_date,$e_ech,$p_jrn,"Invoice",$seq,$periode); + + // Set Internal code and Comment + $Res=ExecSql($p_cn,"update jrn set jr_internal='".$internal."' where ". + " jr_grpt_id = ".$seq); + + $comment=(FormatString($e_comm) == null )?$internal." client : ".GetFicheName($p_cn,$e_client):FormatString($e_comm); + + // Update and set the invoice's comment + $Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq); + + if ( isset ($_FILES)) { + if ( sizeof($_FILES) != 0 ) + save_upload_document($p_cn,$seq); + } + + // save the quantity, then we can make an invoice + for ( $i=0;$i < $nb_item;$i++) + { + // don't record operation of 0 + if ( $a_price[$i]*$a_quant[$i] == 0 ) continue; + + // insert into the table quant_sold + // Note that negative value are also saved but not the vat ! + if ( $a_vat[$i] == -1) { + $computed_vat=0; + $vat_code="null"; + } else { + $computed_vat=ComputeVat($p_cn,$a_good[$i],$a_quant[$i],$a_price[$i],$a_vat[$i]); + $vat_code=$a_vat[$i]; + } + } + }//try + catch (Exception $e) + { + echo ''. + 'Erreur dans l\'enregistrement '. + __FILE__.':'.__LINE__.' '. + $e->getMessage(); + Rollback($p_cn); + exit(); + } Commit($p_cn); return array($internal,$comment); } diff --git a/include/user_menu.php b/include/user_menu.php index 28ae84d90..20421860e 100644 --- a/include/user_menu.php +++ b/include/user_menu.php @@ -48,6 +48,7 @@ function u_ShowDossier($p_user,$p_admin) $result.=""; } $result.=''; + $result.=''; $result.=''; $result.=""; $result.="
Montant HTVAMontant TVATotal
'.round($fiche_amount_vat,2).''.round($fiche_with_vat,2).'
Administration Aide Préférence Sortir
"; @@ -74,6 +75,12 @@ function u_ShowDossier($p_user,$p_admin) $result.=""; $result.="Paramètres"; $result.=""; + $result.=""; + $result.="Comptabilité analytique"; + $result.=""; + $result.=""; + $result.="Caisse Enregistreuse"; + $result.=""; $result.=""; } @@ -154,15 +161,21 @@ function ShowMenuCompta($p_dossier,$p_high="") if ( $p_high !== "" ) $default=$p_high; echo_debug('user_menu.php',__LINE__,'defaut is '.$default); - + if ( isset($_REQUEST['p_action'])) + { + if ( $_REQUEST['p_action']=='impress') + $default=5; + if ( $_REQUEST['p_action']=='fiche') + $default=6; + } $p_array=array( array("user_jrn.php?jrn_type=NONE" ,"Grand Livre"), array("user_jrn.php?jrn_type=VEN" ,"Entrée"), array("user_jrn.php?jrn_type=ACH","Dépense"), array("user_jrn.php?jrn_type=FIN","Financier"), - array("user_jrn.php?jrn_type=OD","Op. Diverses"), - array("compta.php?p_action=impress","Impression","Impression"), - array("compta.php?p_action=fiche","Fiche","Ajouter, modifier ou effacer des fiches"), + array("user_jrn.php?jrn_type=ODS","Op. Diverses"), + array("compta.php?p_action=impress","Impression","Impression",5), + array("compta.php?p_action=fiche","Fiche","Ajouter, modifier ou effacer des fiches",6), array("user_advanced.php","Avancé","Opérations délicates"), ); @@ -171,9 +184,11 @@ function ShowMenuCompta($p_dossier,$p_high="") $r="

Comptabilité ".$_SESSION['g_name']; $r.='
- + + + @@ -481,6 +496,8 @@ function u_ShowMenuRecherche($p_cn,$p_jrn,$p_sessid,$p_array=null) $r.= ""; $r.= ""; $r.=""; + if ( isset($p_expert)) + $r.=''; $r.= ""; @@ -529,7 +546,7 @@ function ShowJrn($p_menu="") array("user_jrn.php?jrn_type=VEN" ,"Entrée"), array("user_jrn.php?jrn_type=ACH","Dépense"), array("user_jrn.php?jrn_type=FIN","Financier"), - array("user_jrn.php?jrn_type=OD","Op. Diverses") + array("user_jrn.php?jrn_type=ODS","Op. Diverses") ); $result=ShowItem($p_array,'H',"cell","mtitle",$p_menu); return $result; @@ -582,14 +599,30 @@ function ShowMenuFiche($p_dossier) function MenuAdmin() { - $item=array (array("admin_repo.php?action=user_mgt","Utilisateurs"), - array("admin_repo.php?action=dossier_mgt","Dossiers"), - array("admin_repo.php?action=modele_mgt","Modèles"), + $def=-1; + if (isset($_REQUEST['UID'])) + $def=0; + if ( isset ($_REQUEST['action'])){ + switch ($_REQUEST['action']) { + case 'user_mgt': + $def=0; + break; + case 'dossier_mgt': + $def=1; + break; + case 'modele_mgt': + $def=2; + break; + } + } + $item=array (array("admin_repo.php?action=user_mgt","Utilisateurs",'Gestion des utilisateurs',0), + array("admin_repo.php?action=dossier_mgt","Dossiers",'Gestion des dossiers',1), + array("admin_repo.php?action=modele_mgt","Modèles",'Gestion des modèles',2), array("login.php","Accueil"), array("logout.php","Logout") ); - $menu=ShowItem($item,'H'); + $menu=ShowItem($item,'H',"mtitle","mtitle",$def); return $menu; } /*! @@ -693,6 +726,8 @@ function ShowMenuPcmn($p_start=1) echo '5 Actif'; echo '6 Charges'; echo '7 Produits'; + echo '8 Hors Comptabilité'; + echo '9 Hors Comptabilité'; echo ""; } /*! diff --git a/include/user_update.php b/include/user_update.php index 5d0adeea1..a57353512 100644 --- a/include/user_update.php +++ b/include/user_update.php @@ -20,6 +20,7 @@ /* $Revision$ */ /*! \file * \brief Check if still used + * \todo this file should be removed, and also the include in user_form_xxx */ if ( $action == 'update' ) { @@ -51,4 +52,4 @@ if ( isset($_POST['update_record']) ) { echo '
'; } // if update_record -?> \ No newline at end of file +?> diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh index dd28422f7..f12297512 100755 --- a/scripts/cleanup.sh +++ b/scripts/cleanup.sh @@ -1,6 +1,6 @@ #!/bin/bash # clean all phpcompta related DB. -DOMAIN="v232_" +DOMAIN="rel2331" dropdb -U phpcompta -h localhost ${DOMAIN}account_repository dropdb -U phpcompta -h localhost ${DOMAIN}dossier1 dropdb -U phpcompta -h localhost ${DOMAIN}dossier3 diff --git a/sql/upgrade.sql b/sql/upgrade.sql index e69de29bb..eaf20248c 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -0,0 +1,362 @@ +begin ; + +CREATE or replace FUNCTION insert_quant_sold( + p_internal text, + p_jid numeric, + p_fiche character varying, + p_quant numeric, + p_price numeric, + p_vat numeric, + p_vat_code integer, + p_client character varying) + RETURNS void + AS $$ +declare + fid_client integer; + fid_good integer; +begin + select f_id into fid_client from + attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(p_client); + select f_id into fid_good from + attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(p_fiche); + insert into quant_sold + (qs_internal,j_id,qs_fiche,qs_quantite,qs_price,qs_vat,qs_vat_code,qs_client,qs_valid) + values + (p_internal,p_jid,fid_good,p_quant,p_price,p_vat,p_vat_code,fid_client,'Y'); + return; +end; + $$ + LANGUAGE plpgsql; + + + +CREATE or REPLACE FUNCTION account_update(p_f_id integer, p_account poste_comptable) RETURNS integer + AS $$ +declare +nMax fiche.f_id%type; +nCount integer; +nParent tmp_pcmn.pcm_val_parent%type; +sName varchar; +nJft_id attr_value.jft_id%type; +begin + + if length(trim(p_account)) != 0 then + select count(*) into nCount from tmp_pcmn where pcm_val=p_account; + if nCount = 0 then + select av_text into sName from + attr_value join jnt_fic_att_value using (jft_id) + where + ad_id=1 and f_id=p_f_id; + nParent:=account_parent(p_account); + insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values (p_account,sName,nParent); + end if; + end if; + select jft_id into njft_id from jnt_fic_att_value where f_id=p_f_id and ad_id=5; + update attr_value set av_text=p_account where jft_id=njft_id; + +return njft_id; +end; +$$ + LANGUAGE plpgsql; + + + +CREATE TABLE quant_purchase ( + qp_id integer DEFAULT nextval(('s_quantity'::text)::regclass) NOT NULL, + qp_internal text NOT NULL, + j_id integer not null, + qp_fiche integer NOT NULL, + qp_quantite numeric(20,4) NOT NULL, + qp_price numeric(20,4), + qp_vat numeric(20,4) default 0.0, + qp_vat_code integer, + qp_nd_amount numeric(20,4) default 0.0, + qp_nd_tva numeric(20,4) default 0.0, + qp_nd_tva_recup numeric(20,4) default 0.0, + qp_supplier integer NOT NULL, + qp_valid char(1) default 'Y' not null +); +ALTER TABLE ONLY quant_purchase + ADD CONSTRAINT qp_id_pk PRIMARY KEY (qp_id); + +--- +truncate quant_sold; +alter table quant_sold ADD qs_valid char(1) ; +alter table quant_sold add j_id integer; +alter table quant_sold alter j_id set not null; + +update quant_sold set qs_valid='Y'; +alter table quant_sold alter qs_valid set default 'Y'; +alter table quant_sold alter qs_valid set not null; + + + +CREATE or replace FUNCTION insert_quant_purchase + (p_internal text, + p_j_id numeric, + p_fiche character varying, + p_quant numeric, + p_price numeric, + p_vat numeric, + p_vat_code integer, + p_nd_amount numeric, + p_nd_tva numeric, + p_nd_tva_recup numeric, + p_client character varying) RETURNS void + AS $$ +declare + fid_client integer; + fid_good integer; +begin + select f_id into fid_client from + attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(p_client); + select f_id into fid_good from + attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(p_fiche); + 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) + values + (p_internal, + p_j_id, + fid_good, + p_quant, + p_price, + p_vat, + p_vat_code, + p_nd_amount, + p_nd_tva, + p_nd_tva_recup, + fid_client); + return; +end; + $$ + LANGUAGE plpgsql; +insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values(8,'Comptes hors Compta',0); +insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values(9,'Comptes hors Compta',0); + +COMMENT ON TABLE parameter IS 'parameter of the company'; + +-- +-- Name: plan_analytique; Type: TABLE; Schema: public; Owner: phpcompta; Tablespace: +-- + +CREATE TABLE plan_analytique ( + pa_id integer NOT NULL, + pa_name text DEFAULT 'Sans Nom'::text NOT NULL, + pa_description text +); + +-- +-- Name: TABLE plan_analytique; Type: COMMENT; Schema: public; Owner: phpcompta +-- + +COMMENT ON TABLE plan_analytique IS 'Plan Analytique (max 5)'; + + +-- +-- Name: plan_analytique_pa_id_seq; Type: SEQUENCE; Schema: public; Owner: phpcompta +-- + +CREATE SEQUENCE plan_analytique_pa_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.plan_analytique_pa_id_seq OWNER TO phpcompta; + +-- +-- Name: plan_analytique_pa_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: phpcompta +-- + +ALTER SEQUENCE plan_analytique_pa_id_seq OWNED BY plan_analytique.pa_id; + + +-- +-- Name: pa_id; Type: DEFAULT; Schema: public; Owner: phpcompta +-- + +ALTER TABLE plan_analytique ALTER COLUMN pa_id SET DEFAULT nextval('plan_analytique_pa_id_seq'::regclass); + + +-- +-- Name: plan_analytique_pa_name_key; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace: +-- + +ALTER TABLE ONLY plan_analytique + ADD CONSTRAINT plan_analytique_pa_name_key UNIQUE (pa_name); + + +-- +-- Name: plan_analytique_pkey; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace: +-- + +ALTER TABLE ONLY plan_analytique + ADD CONSTRAINT plan_analytique_pkey PRIMARY KEY (pa_id); + + +-- Ajout table operation_analytique + +-- Ajout table poste_analytique +-- +-- Name: poste_analytique; Type: TABLE; Schema: public; Owner: phpcompta; Tablespace: +-- + +CREATE TABLE poste_analytique ( + po_id integer NOT NULL, + po_name text NOT NULL, + pa_id integer NOT NULL, + po_amount numeric(20,4) DEFAULT 0.0 NOT NULL, + po_description text +); + + +ALTER TABLE public.poste_analytique OWNER TO phpcompta; + +-- +-- Name: TABLE poste_analytique; Type: COMMENT; Schema: public; Owner: phpcompta +-- + +COMMENT ON TABLE poste_analytique IS 'Poste Analytique'; + + +-- +-- Name: poste_analytique_po_id_seq; Type: SEQUENCE; Schema: public; Owner: phpcompta +-- + +CREATE SEQUENCE poste_analytique_po_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.poste_analytique_po_id_seq OWNER TO phpcompta; + +-- +-- Name: poste_analytique_po_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: phpcompta +-- + +ALTER SEQUENCE poste_analytique_po_id_seq OWNED BY poste_analytique.po_id; + + +-- +-- Name: po_id; Type: DEFAULT; Schema: public; Owner: phpcompta +-- + +ALTER TABLE poste_analytique ALTER COLUMN po_id SET DEFAULT nextval('poste_analytique_po_id_seq'::regclass); + + +-- +-- Name: poste_analytique_pkey; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace: +-- + +ALTER TABLE ONLY poste_analytique + ADD CONSTRAINT poste_analytique_pkey PRIMARY KEY (po_id); + + +-- +-- Name: poste_analytique_pa_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: phpcompta +-- + +ALTER TABLE ONLY poste_analytique + ADD CONSTRAINT poste_analytique_pa_id_fkey FOREIGN KEY (pa_id) REFERENCES plan_analytique(pa_id) ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- Name: operation_analytique; Type: TABLE; Schema: public; Owner: phpcompta; Tablespace: +-- +create sequence s_oa_group; + +CREATE TABLE operation_analytique ( + oa_id integer NOT NULL, + po_id integer NOT NULL, + oa_amount numeric(20,4) NOT NULL, + oa_description text, + oa_debit boolean DEFAULT true NOT NULL, + j_id integer, + oa_group integer DEFAULT nextval('s_oa_group'::regclass) NOT NULL, + oa_date date NOT NULL +); + + +ALTER TABLE public.operation_analytique OWNER TO phpcompta; + +-- +-- Name: TABLE operation_analytique; Type: COMMENT; Schema: public; Owner: phpcompta +-- + +COMMENT ON TABLE operation_analytique IS 'History of the analytic account'; + + +-- +-- Name: historique_analytique_ha_id_seq; Type: SEQUENCE; Schema: public; Owner: phpcompta +-- + +CREATE SEQUENCE historique_analytique_ha_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.historique_analytique_ha_id_seq OWNER TO phpcompta; + +-- +-- Name: historique_analytique_ha_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: phpcompta +-- + +ALTER SEQUENCE historique_analytique_ha_id_seq OWNED BY operation_analytique.oa_id; + + +-- +-- Name: oa_id; Type: DEFAULT; Schema: public; Owner: phpcompta +-- + +ALTER TABLE operation_analytique ALTER COLUMN oa_id SET DEFAULT nextval('historique_analytique_ha_id_seq'::regclass); + + +-- +-- Name: historique_analytique_pkey; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace: +-- + +ALTER TABLE ONLY operation_analytique + ADD CONSTRAINT historique_analytique_pkey PRIMARY KEY (oa_id); + + +-- +-- Name: operation_analytique_j_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: phpcompta +-- + +ALTER TABLE ONLY operation_analytique + ADD CONSTRAINT operation_analytique_j_id_fkey FOREIGN KEY (j_id) REFERENCES jrnx(j_id) ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- Name: operation_analytique_po_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: phpcompta +-- + +ALTER TABLE ONLY operation_analytique + ADD CONSTRAINT operation_analytique_po_id_fkey FOREIGN KEY (po_id) REFERENCES poste_analytique(po_id) ON UPDATE CASCADE ON DELETE CASCADE; + +INSERT INTO parameter VALUES ('MY_ANALYTIC', null); + +alter table jrn add constraint ux_internal unique (jr_internal); + +alter table quant_sold add constraint fk_internal foreign key (qs_internal) references jrn (jr_internal) on delete cascade on update cascade; + +alter table quant_purchase add constraint fk_internal foreign key (qp_internal) references jrn (jr_internal) on delete cascade on update cascade; +commit; \ No newline at end of file