diff --git a/contrib/comptabilite-francaise/copropriete/fr_plan_syndiccoprop.sql b/contrib/comptabilite-francaise/copropriete/fr_plan_syndiccoprop.sql new file mode 100644 index 000000000..0dd612dba --- /dev/null +++ b/contrib/comptabilite-francaise/copropriete/fr_plan_syndiccoprop.sql @@ -0,0 +1,133 @@ +-- +-- PostgreSQL database dump +-- Version 2008/02/10 09:19 +-- + +-- +-- Name: TABLE tmp_pcmn; Type: COMMENT; Schema: public; Owner: phpcompta +-- + +COMMENT ON TABLE tmp_pcmn IS 'Plan comptable - Syndicat des copropriétaires : strict'; + +-- +-- Data for Name: tmp_pcmn; Type: TABLE DATA; Schema: public; Owner: phpcompta +-- + +COPY tmp_pcmn (pcm_val, pcm_lib, pcm_val_parent) FROM stdin; +1 Classe 1 - Provisions, avances, subventions et emprunts 0 +10 Provisions et avances : 1 +102 Provisions pour travaux décidés 10 +103 Avances 10 +1031 Avances de trésorerie 103 +1032 Avances travaux au titre de l'article 18, 6e alinéa de la loi susvisée 103 +1033 Autres avances 103 +12 Solde en attente sur travaux et opérations exceptionnelles 1 +13 Subventions : 1 +131 Subventions accordées en instance de versement 13 +4 Classe 4 - Copropriétaires et tiers 0 +40 Fournisseurs : 4 +401 Factures parvenues 40 +408 Factures non parvenues 40 +409 Fournisseurs débiteurs 40 +42 Personnel : 4 +421 Rémunérations dues 42 +43 Sécurité sociale et autres organismes sociaux : 4 +431 Sécurité sociale 43 +432 Autres organismes sociaux 43 +44 Etat et collectivités territoriales : 4 +441 Etat et autres organismes - subventions à recevoir 44 +442 Etat - impôts et versements assimilés 44 +443 Collectivités territoriales - aides 44 +45 Collectivité des copropriétaires : 4 +450 Copropriétaire individualisé 45 +4501 Sur décision AG : Copropriétaire - budget prévisionnel 450 +4502 Sur décision AG : Copropriétaire - travaux de l'article 14-2 de la loi susvisée et opérations exceptionnelles 450 +4503 Sur décision AG : Copropriétaire - avances 450 +4504 Sur décision AG : Copropriétaire - emprunts 450 +459 Copropriétaire - créances douteuses 45 +46 Débiteurs et créditeurs divers : 4 +461 Débiteurs divers 46 +462 Créditeurs divers 46 +47 Compte d'attente : 4 +471 Compte en attente d'imputation débiteur 47 +472 Compte en attente d'imputation créditeur 47 +48 Compte de régularisation : 4 +486 Charges payées d'avance 48 +487 Produits encaissés d'avance 48 +49 Dépréciation des comptes de tiers : 4 +491 Copropriétaires 49 +492 Personnes autres que les copropriétaires 49 +5 Classe 5 - Comptes financiers 0 +50 Fonds placés : 5 +501 Compte à terme 50 +502 Autre compte 50 +51 Banques, ou fonds disponibles en banque pour le syndicat : 5 +512 Banques 51 +514 Chèques postaux 51 +53 Caisse. 5 +6 Classe 6 - Comptes de charges 0 +60 Achats de matières et fournitures : 6 +601 Eau 60 +602 Electricié 60 +603 Chauffage, énergie et combustibles 60 +604 Achats produits d'entretien et petits équipements 60 +605 Matériel 60 +606 Fournitures 60 +61 Services extérieurs : 6 +611 Nettoyage des locaux 5 +612 Locations immobiliéres 61 +613 Locations mobiliéres 61 +614 Contrats de maintenance 61 +615 Entretien et petites réparations 61 +616 Primes d'assurances 61 +62 Frais d'administration et honoraires : 6 +621 Rémunérations du syndic sur gestion copropriété 62 +6211 Rémunération du syndic 621 +6212 Débours 621 +6213 Frais postaux 621 +622 Autres honoraires du syndic 62 +6221 Honoraires travaux 622 +6222 Prestations particulières 622 +6223 Autres honoraires 622 +623 Rémunérations de tiers intervenants 62 +624 Frais du conseil syndical 62 +63 Impôts - taxes et versements assimilés : 6 +632 Taxe de balayage 63 +633 Taxe foncière 63 +634 Autres impôts et taxes 63 +64 Frais de personnel : 6 +641 Salaires 64 +642 Charges sociales et organismes sociaux 64 +643 Taxe sur les salaires 64 +644 Autres (médecine du travail, mutuelles, etc.) 64 +66 Charges financières des emprunts, agios ou autres : 6 +661 Remboursement d'annuités d'emprunt 66 +662 Autres charges financières et agios 66 +67 Charges pour travaux et opérations exceptionnelles : 6 +671 Travaux décidés par l'assemblée générale 67 +672 Travaux urgents 67 +673 Etudes techniques, diagnostic, consultation 67 +677 Pertes sur créances irrécouvrables 67 +678 Charges exceptionnelles 67 +68 Dotations aux dépréciations sur créances douteuses. 6 +7 Classe 7 - Comptes de produits 0 +70 Appels de fonds : 7 +701 Provisions sur opérations courantes 70 +702 Provisions sur travaux de l'article 14-2 et opérations exceptionnelles 70 +703 Avances 70 +704 Remboursements d'annuités d'emprunts 70 +71 Autres produits : 7 +711 Subventions 71 +712 Emprunts 71 +713 Indemnités d'assurances 71 +714 Produits divers (dont intérêts légaux dus par les copropriétaires) 71 +716 Produits financiers 71 +718 Produits exceptionnels 71 +78 Reprises de dépréciations sur créances douteuses. 7 +8 Comptes spéciaux 0 +9 Comptes analytique 0 +\. + +-- +-- PostgreSQL database dump complete +-- diff --git a/contrib/document_test/facture.odt b/contrib/document_test/facture.odt index 0132a5e63..460a0f33d 100644 Binary files a/contrib/document_test/facture.odt and b/contrib/document_test/facture.odt differ diff --git a/html/admin/setup.php b/html/admin/setup.php index caedcc798..ca5a0ce65 100644 --- a/html/admin/setup.php +++ b/html/admin/setup.php @@ -147,7 +147,7 @@ function ExecuteScript($p_cn,$script) { echo_debug('setup.php',__LINE__,"Execute sql $sql"); if ( ExecSql($p_cn,$sql,false) == false ) { Rollback($p_cn); - if ( DEBUG=='false' ) ob_clean(); + if ( DEBUG=='false' ) ob_end_clean(); print "ERROR : $sql"; exit(); } @@ -156,7 +156,7 @@ echo_debug('setup.php',__LINE__,"Execute sql $sql"); print "
"; } // while (feof) fclose($hf); - if ( DEBUG=='false' ) ob_clean(); + if ( DEBUG=='false' ) ob_end_clean(); } /*! \brief loop to apply all the path to a folder or * a template @@ -166,7 +166,7 @@ echo_debug('setup.php',__LINE__,"Execute sql $sql"); */ function apply_patch($p_cn,$p_name) { - $MaxVersion=36; + $MaxVersion=40; echo ''; @@ -415,7 +415,7 @@ if ($account == 0 ) { ExecuteScript($cn,"sql/account_repository/constraint.sql"); Commit($cn); - if ( DEBUG=='false') ob_clean(); + if ( DEBUG=='false') ob_end_clean(); echo "Creation of Modele1"; if ( DEBUG=='false') ob_start(); @@ -426,7 +426,7 @@ if ($account == 0 ) { ExecuteScript($cn,'sql/mod1/data.sql'); ExecuteScript($cn,'sql/mod1/constraint.sql'); Commit($cn); - if ( DEBUG=='false') ob_clean(); + if ( DEBUG=='false') ob_end_clean(); echo "Creation of Modele2"; ExecSql($cn,"create database ".domaine."mod2 encoding='latin1'"); @@ -438,7 +438,7 @@ if ($account == 0 ) { ExecuteScript($cn,'sql/mod1/constraint.sql'); Commit($cn); - if ( DEBUG=='false') ob_clean(); + if ( DEBUG=='false') ob_end_clean(); }// end if // Add a french accountancy model @@ -507,6 +507,6 @@ echo '
'; } } - if (DEBUG=='false') ob_clean(); + if (DEBUG=='false') ob_end_clean(); echo "

Voilà tout est installé ;-)

"; ?> diff --git a/html/admin/sql/patch/upgrade36.BE.sql b/html/admin/sql/patch/upgrade36.BE.sql index 8d1cb76d0..79f8c6b77 100644 --- a/html/admin/sql/patch/upgrade36.BE.sql +++ b/html/admin/sql/patch/upgrade36.BE.sql @@ -12,6 +12,7 @@ INSERT INTO parm_poste (p_value, p_type) VALUES (492, 'PAS'); INSERT INTO parm_poste (p_value, p_type) VALUES (493, 'PAS'); INSERT INTO parm_poste (p_value, p_type) VALUES (2409, 'ACTINV'); INSERT INTO parm_poste (p_value, p_type) VALUES (2, 'ACT'); +INSERT INTO parm_poste (p_value, p_type) VALUES (2409, 'ACTINV'); INSERT INTO parm_poste (p_value, p_type) VALUES (3, 'ACT'); INSERT INTO parm_poste (p_value, p_type) VALUES (5, 'ACT'); INSERT INTO parm_poste (p_value, p_type) VALUES (491, 'ACT'); diff --git a/html/admin/sql/patch/upgrade36.sql b/html/admin/sql/patch/upgrade36.sql index 218298598..9c2ef8200 100644 --- a/html/admin/sql/patch/upgrade36.sql +++ b/html/admin/sql/patch/upgrade36.sql @@ -223,13 +223,6 @@ CREATE SEQUENCE bud_card_bc_id_seq ALTER TABLE public.bud_card_bc_id_seq OWNER TO phpcompta; --- --- Name: bud_card_bc_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: phpcompta --- - -ALTER SEQUENCE bud_card_bc_id_seq OWNED BY bud_card.bc_id; - - -- -- Name: bc_id; Type: DEFAULT; Schema: public; Owner: phpcompta -- @@ -322,12 +315,6 @@ CREATE SEQUENCE bud_detail_bd_id_seq ALTER TABLE public.bud_detail_bd_id_seq OWNER TO phpcompta; --- --- Name: bud_detail_bd_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: phpcompta --- - -ALTER SEQUENCE bud_detail_bd_id_seq OWNED BY bud_detail.bd_id; - -- -- Name: bd_id; Type: DEFAULT; Schema: public; Owner: phpcompta @@ -424,13 +411,6 @@ CREATE SEQUENCE bud_detail_periode_bdp_id_seq ALTER TABLE public.bud_detail_periode_bdp_id_seq OWNER TO phpcompta; --- --- Name: bud_detail_periode_bdp_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: phpcompta --- - -ALTER SEQUENCE bud_detail_periode_bdp_id_seq OWNED BY bud_detail_periode.bdp_id; - - -- -- Name: bdp_id; Type: DEFAULT; Schema: public; Owner: phpcompta -- @@ -682,7 +662,7 @@ begin nLength:=length(str_value); while nLength > 0 loop n_value:=to_number(str_value,'99999999999999999999999999999'); - select into str_type p_type from parm_poste where p_value=n_value; + select p_type into str_type from parm_poste where p_value=n_value; if FOUND then return str_type; end if; diff --git a/html/admin/sql/patch/upgrade37.sql b/html/admin/sql/patch/upgrade37.sql new file mode 100644 index 000000000..bb6dd05f8 --- /dev/null +++ b/html/admin/sql/patch/upgrade37.sql @@ -0,0 +1,43 @@ +begin; + +CREATE OR REPLACE FUNCTION jrn_check_periode() + RETURNS "trigger" AS +$BODY$ +declare +bClosed bool; +str_status text; +ljr_tech_per jrn.jr_tech_per%TYPE; +ljr_def_id jrn.jr_def_id%TYPE; +lreturn jrn%ROWTYPE; +begin +if TG_OP='INSERT' then + ljr_tech_per :=NEW.jr_tech_per; + ljr_def_id :=NEW.jr_def_id; + lreturn :=NEW; +end if; + +if TG_OP='DELETE' then + ljr_tech_per :=OLD.jr_tech_per; + ljr_def_id :=OLD.jr_def_id; + lreturn :=OLD; +end if; + +select p_closed into bClosed from parm_periode + where p_id=ljr_tech_per; + +if bClosed = true then + raise exception 'Periode fermee'; +end if; + +select status into str_status from jrn_periode + where p_id =ljr_tech_per and jrn_def_id=ljr_def_id; + +if str_status <> 'OP' then + raise exception 'Periode fermee'; +end if; + +return lreturn; +end;$BODY$ + LANGUAGE 'plpgsql' VOLATILE; +update version set val=38; +commit; diff --git a/html/admin/sql/patch/upgrade38.sql b/html/admin/sql/patch/upgrade38.sql new file mode 100644 index 000000000..eb39eb6bb --- /dev/null +++ b/html/admin/sql/patch/upgrade38.sql @@ -0,0 +1,28 @@ +begin; +CREATE OR REPLACE FUNCTION find_pcm_type(pp_value "numeric") + RETURNS text AS +$BODY$ +declare + str_type text; + str_value text; + n_value numeric; + nLength integer; +begin + str_value:=trim(to_char(pp_value,'99999999999999999999999999999')); + nLength:=length(str_value); + while nLength > 0 loop + n_value:=to_number(str_value,'99999999999999999999999999999'); + select p_type into str_type from parm_poste where p_value=n_value; + if FOUND then + return str_type; + end if; + nLength:=nLength-1; + str_value:=substring(str_value from 1 for nLength); + end loop; +return 'CON'; +end; +$BODY$ + LANGUAGE 'plpgsql' VOLATILE; + +update version set val=39; +commit; diff --git a/html/admin/sql/patch/upgrade39.sql b/html/admin/sql/patch/upgrade39.sql new file mode 100644 index 000000000..d937f3e97 --- /dev/null +++ b/html/admin/sql/patch/upgrade39.sql @@ -0,0 +1,40 @@ +begin; +create table info_def ( + id_type text primary key, + id_description text null +); + +comment on table info_def is 'Contains the types of additionnal info we can add to a operation'; +create or replace function info_def_ins_upd() returns trigger +AS +$$ +declare + row_info_def info_def%ROWTYPE; + str_type text; +begin +row_info_def:=NEW; +str_type:=upper(trim(NEW.id_type)); +str_type:=replace(str_type,' ',''); +str_type:=replace(str_type,',',''); +str_type:=replace(str_type,';',''); +if length(str_type) =0 then + raise exception 'id_type cannot be null'; +end if; +row_info_def.id_type:=str_type; +return row_info_def; +end; +$$ language plpgsql; +create trigger info_def_ins_upd_t before insert or update on info_def for each row execute procedure info_def_ins_upd(); + +create table jrn_info ( + ji_id serial primary key, + jr_id integer not null, + id_type text not null, + ji_value text +); +alter table jrn_info add constraint fk_jrn foreign key (jr_id) references jrn(jr_id) on delete cascade on update cascade; +alter table jrn_info add constraint fk_info_def foreign key (id_type) references info_def(id_type) on delete cascade on update cascade; +insert into info_def values ('BON_COMMANDE','Numero de bon de commande') ,('OTHER','Info diverses'); +insert into attr_def values(30,'Numero de client'); +update version set val=40; +commit; diff --git a/html/admin/sql/patch/upgrade40.sql b/html/admin/sql/patch/upgrade40.sql new file mode 100644 index 000000000..47ec42da4 --- /dev/null +++ b/html/admin/sql/patch/upgrade40.sql @@ -0,0 +1,49 @@ +begin; + +insert into parm_code values ('DEP_PRIV',4890,'Depense a charge du gerant'); +insert into attr_def values (31,'Depense à charge du gérant (partie privée)'); +alter table quant_purchase add qp_dep_priv numeric(20,4) default 0.0; + +CREATE 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_dep_priv 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, + qp_dep_priv) + 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, + p_dep_priv); + return; +end; + $$ + LANGUAGE plpgsql; + +update version set val=41; +commit; diff --git a/html/annulation.php b/html/annulation.php index daf0aa46c..7471ac1d3 100644 --- a/html/annulation.php +++ b/html/annulation.php @@ -136,13 +136,15 @@ if ($p_id != -1 ) { // A 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); + $p=ExecSql($cn,"select jr_tech_per from jrn where jr_grpt_id=".$_REQUEST['jrn_op']); + $period_id=pg_fetch_result($p,0,0); // thanks jrn_op (jrn.jr_id) we find out the concerned ledger - $sql="select jr_def_id from jrn where jr_id=".$_REQUEST['jrn_op']; + + $sql="select jr_def_id from jrn where jr_grpt_id=".$_REQUEST['jrn_op']; $r=ExecSql($cn,$sql); $nJrn=pg_fetch_result($r,0,0); $per=new Periode($cn); - $per->set_jrn(nJrn); + $per->set_jrn($nJrn); $per->set_periode($period_id); // Check the period_id diff --git a/html/comptanalytic.php b/html/comptanalytic.php index 8fe1056ae..5ae193319 100644 --- a/html/comptanalytic.php +++ b/html/comptanalytic.php @@ -72,7 +72,7 @@ if ( isset ($_REQUEST['p_action'])) echo '
'; echo ShowItem(array( array('?p_action=ca_pa&'.$str_dossier,'Plan Analytique',"Plan Analytique",0), - array('?p_action=ca_od&'.$str_dossier,'Opérations Diverses',"Permet d'enregistrer des opérations sur la compta analytique",1), + array('?p_action=ca_od&'.$str_dossier,'Opérations Diverses',"Permet d'enregistrer des operations sur la compta analytique",1), array('?p_action=ca_groupe&'.$str_dossier,'Groupe','Regroupe les postes analytiques',3), array('?p_action=ca_imp&'.$str_dossier,'Impression',"impression de rapport",2) ), diff --git a/html/export_ouv.php b/html/export_ouv.php index 4613e2640..66457121c 100644 --- a/html/export_ouv.php +++ b/html/export_ouv.php @@ -56,8 +56,8 @@ $ret=get_array($cn,"select distinct j_poste::text from jrnx inner join tmp_pcmn on (pcm_val=j_poste) where j_tech_per >= ".$sql_from[0]['min']." and - j_tech_per <= ".$sql_to[0]['max']." and j_poste not like '7%' - and j_poste not like '6%' + j_tech_per <= ".$sql_to[0]['max']." and j_poste::text not like '7%' + and j_poste::text not like '6%' order by j_poste::text"); if ( $ret == null ) {echo 'Rien à exporter'; exit();} printf ("OUVERTURE\n"); diff --git a/html/fiche.php b/html/fiche.php index 4afcdfbfc..21bf7e636 100644 --- a/html/fiche.php +++ b/html/fiche.php @@ -222,7 +222,7 @@ if ( isset ( $_GET["action"]) ) { $sql="select distinct f_id,fd_id,av_text from fiche join jnt_fic_att_value using (f_id) join attr_value using (jft_id) where upper(av_text) like upper('%".FormatString($_GET["search_text"])."%') order by av_text,f_id"; - $all=getArray($cn,$sql); + $all=get_array($cn,$sql); // test on the size // if ( sizeof($all) != 0 ) diff --git a/html/fid.php b/html/fid.php index 78655f5a1..86009af80 100644 --- a/html/fid.php +++ b/html/fid.php @@ -24,7 +24,6 @@ * \brief Fid for the ajax request for cards */ -header("Content-type: text/xml charset=\"ISO8859-1\"",true); require_once ("constant.php"); require_once ("postgres.php"); @@ -77,23 +76,17 @@ if ( isset($_SESSION['isValid']) && $_SESSION['isValid'] == 1) $tva_id=$array[0]['tva_id']; // Check null - $name=($name==null)?" ":$name; - $sell=($sell==null)?" ":$sell; - $buy=($buy==null)?" ":$buy; - $tva_id=($tva_id==null)?" ":$tva_id; + $name=($name==null)?" ":str_replace('"','',$name); + $sell=($sell==null)?" ":str_replace('"','',$sell); + $buy=($buy==null)?" ":str_replace('"','',$buy); + $tva_id=($tva_id==null)?" ":str_replace('"','',$tva_id); - $a=''; - $a.=""; - $a.="".$name.""; - $a.="".$sell.""; - $a.="".$buy.""; - $a.="".$tva_id.""; - $a.=""; + $a='{"answer":"ok","name":"'.$name.'","sell":"'.$sell.'","buy":"'.$buy.'","tva_id":"'.$tva_id.'","ctl":"'.$_GET['ctl'].'"}'; } else - $a="not connected"; + $a='{"answer":"nok"}'; echo_debug("fid.php",__LINE__,"Answer is \n $a"); - +header("Content-type: text/html; charset: ISO8859-1",true); print $a; ?> diff --git a/html/index.php b/html/index.php index 8fb7d77c6..5be91c1f5 100644 --- a/html/index.php +++ b/html/index.php @@ -76,22 +76,18 @@ BODY { -Version 3.1.0 -
-

Il est conseillé de ne PAS utiliser Internet Explorer. -

- Vous pouvez utiliser un autre browser: firefox, mozilla, netscape, Konqueror, opera... -

-

- - Si vous avez envie de nous rejoindre, vous êtes les bienvenus - . -

-
- + +version 3.1.0 + +
+
+
+
Logo
+
+
- +
@@ -105,7 +101,9 @@ Version 3.1.0
+ +
diff --git a/html/jrn_csv.php b/html/jrn_csv.php index c3eaa4bb3..aed02bc4d 100644 --- a/html/jrn_csv.php +++ b/html/jrn_csv.php @@ -99,6 +99,15 @@ if ( $_GET['p_simple'] == 0 ) '"internal";'. '"montant";'. "\r\n"); + // set a filter for the FIN + $a_parm_code=get_array($cn,"select p_value from parm_code where p_code in ('BANQUE','COMPTE_COURANT','CAISSE')"); + $sql_fin="("; + $or=""; + foreach ($a_parm_code as $code) { + $sql_fin.="$or j_poste::text like '".$code['p_value']."%'"; + $or=" or "; + } + $sql_fin.=")"; foreach ($Row as $line) { @@ -113,7 +122,7 @@ if ( $_GET['p_simple'] == 0 ) // Get the jrn type if ( $line['jrn_def_type'] == 'FIN' ) { $positive = CountSql($cn,"select * from jrn inner join jrnx on jr_grpt_id=j_grpt ". - " where jr_id=".$line['jr_id']." and (j_poste like '55%' or j_poste like '57%' )". + " where jr_id=".$line['jr_id']." and $sql_fin ". " and j_debit='f'"); diff --git a/html/js/ajax_fiche.js b/html/js/ajax_fiche.js index 9cb4c6740..79169a78f 100644 --- a/html/js/ajax_fiche.js +++ b/html/js/ajax_fiche.js @@ -41,107 +41,79 @@ 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=""; - } - + if ( $(nSell) ) { $(nSell).value=""; } + if ( $(nBuy) ) { $(nBuy).value="";} + if ( $(nTva_id) ) { $(nTva_id).value="-1"; } + +} +function errorFid(request,json) { + alert('erreur : ajax 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 ajaxFid(p_ctl,p_deb,p_jrn){ - var ajaxRequest; // The variable that makes Ajax possible! -; - try{ - // Opera 8.0+, Firefox, Safari - ajaxRequest = new XMLHttpRequest(); - } catch (e){ - // Internet Explorer Browsers - try{ - ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); - } catch (e) { - try{ - ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); - } catch (e){ - // Something went wrong - alert("Your browser broke!"); - return false; - } - } - } - // Create a function that will receive data sent from the server - ajaxRequest.onreadystatechange = function(){ - if(ajaxRequest.readyState == 4){ - 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 ( 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=label; - nSell=p_ctl+"_sell"; - nBuy=p_ctl+"_buy"; - nTva_id=p_ctl+"_tva_id"; - - if ( document.getElementById(nSell) != null ) { - - document.getElementById(nSell).value=sell; - } - if ( document.getElementById(nBuy) != null ) { - - document.getElementById(nBuy).value=buy; - } - - if ( document.getElementById(nTva_id) != null ) { - - 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 { - var gDossier=document.getElementById('gDossier').value; - queryString="?FID="+document.getElementById(p_ctl).value; - queryString=queryString+"&d="+p_deb+"&j="+p_jrn+'&gDossier='+gDossier; - - ajaxRequest.open("GET", "fid.php"+queryString, true); - ajaxRequest.send(null); - } +function ajaxFid(p_ctl,p_deb,p_jrn) +{ + var gDossier=$('gDossier').value; + var ctl_value=$(p_ctl).value; + if ( trim(ctl_value)==0 ) { + nLabel=p_ctl+"_label"; + $(nLabel).value=""; + $(nLabel).innerHTML=""; + clean_Fid(p_ctl); + return; + } + queryString="?FID="+ctl_value; + queryString=queryString+"&d="+p_deb+"&j="+p_jrn+'&gDossier='+gDossier; + queryString=queryString+'&ctl='+p_ctl; + /* alert(queryString); */ + var action=new Ajax.Request ( + "fid.php", + { + method:'get', + parameters:queryString, + onFailure:errorFid, + onSuccess:successFid + } + + ); + } +/*!\brief callback function for ajax + * \param request : object request + * \param json : json answer */ +function successFid(request,json) { + var answer=request.responseText.evalJSON(true); -//--> \ No newline at end of file + var data=answer.name; + var sell=answer.sell; + var buy=answer.buy; + var tva_id=answer.tva_id; + var ctl=answer.ctl; + +/* alert('data:'+data+' sell:'+sell+' Tva id:'+tva_id); */ + + var toSet=ctl+'_label'; + if (trim(data) == "" ) { + $(toSet).innerHTML="Fiche Inconnue"; + $(toSet).style.color="red"; + clean_Fid(ctl); + } else { + var nSell=ctl+"_sell"; + var nBuy=ctl+"_buy"; + var nTva_id=ctl+"_tva_id"; + $(toSet).innerHTML=data; + $(toSet).style.color="black"; + if ( $(nTva_id) ) { + $(nTva_id).value=tva_id; + } + if ( $(nSell ) ) { + $(nSell).value=sell; + } + $(nBuy).value=buy; + + } +} +//--> diff --git a/html/js/scripts.js b/html/js/scripts.js index 6a5ff8915..db346d085 100644 --- a/html/js/scripts.js +++ b/html/js/scripts.js @@ -30,7 +30,6 @@ // Set the focus to the specified field, // and select it if requested by SelectIt - function GetID(ID) { if (document.all) { return document.all[ID]; @@ -92,14 +91,6 @@ function HandleSubmit(e) { return true; } } -/* - * Open the search screen - */ -function openRecherche(p_sessid,p_dossier,p_style) { - if ( p_style == 'E' ) { p_style="expert";} - var w=window.open("recherche.php?gDossier="+p_dossier+"&PHPSESSID="+p_sessid+'&'+p_style,'','statusbar=no,scrollbars=yes,toolbar=no'); - w.focus(); -} /*!\brief add a row for the CA * \param p_table_id diff --git a/html/modify_op.php b/html/modify_op.php index feacc62c0..41b9e7b4d 100644 --- a/html/modify_op.php +++ b/html/modify_op.php @@ -66,18 +66,18 @@ if ( ! isset ( $action )) { echo JS_VIEW_JRN_MODIFY; ?> "; + "; echo ' + + '; echo ""; diff --git a/include/action.inc.php b/include/action.inc.php index 5c40b3f70..9e07b2e68 100644 --- a/include/action.inc.php +++ b/include/action.inc.php @@ -1,3 +1,4 @@ + '; $retour=""; $h_url=""; if ( isset ($_REQUEST['url'])) { - $retour=sprintf('',urldecode($_REQUEST['url'])); + $retour=widget::button_href('Retour',urldecode($_REQUEST['url'])); $h_url=sprintf('',urldecode($_REQUEST['url'])); } //---------------------------------------------------------------------- diff --git a/include/bank.inc.php b/include/bank.inc.php index 00a5ef160..5cf306768 100644 --- a/include/bank.inc.php +++ b/include/bank.inc.php @@ -21,6 +21,7 @@ require_once('class_acc_ledger.php'); require_once('user_form_fin.php'); require_once('jrn.php'); +require_once('class_widget.php'); require_once("class_document.php"); require_once("class_fiche.php"); require_once("class_parm_code.php"); @@ -56,7 +57,7 @@ $h_url=""; if ( isset ($_REQUEST['url'])) { - $retour=sprintf('',urldecode($_REQUEST['url'])); + $retour=widget::button_href('Retour',urldecode($_REQUEST['url'])); $h_url=sprintf('',urldecode($_REQUEST['url'])); } @@ -85,8 +86,8 @@ if ( $sub_action == "solde" ) $vir_interne=new parm_code($cn,'VIREMENT_INTERNE'); $accountSql="select distinct pcm_val::text,pcm_lib from tmp_pcmn - where pcm_val like '".$banque->p_value."%' or pcm_val like '".$vir_interne->p_value."%' - or pcm_val like '".$caisse->p_value."%' + where pcm_val::text like '".$banque->p_value."%' or pcm_val::text like '".$vir_interne->p_value."%' + or pcm_val::text like '".$caisse->p_value."%' order by pcm_val::text"; $ResAccount=ExecSql($cn,$accountSql); echo '
'; diff --git a/include/bud_detail.inc.php b/include/bud_detail.inc.php index 36d6d12cc..62ba03464 100644 --- a/include/bud_detail.inc.php +++ b/include/bud_detail.inc.php @@ -28,7 +28,7 @@ require_once ('class_bud_hypo.php'); require_once ('class_anc_account.php'); echo '
'; -/*!\todo Check if there is Hypothesis */ + /* 1st possibility is not defined */ diff --git a/include/bud_synthese.inc.php b/include/bud_synthese.inc.php index 356c0802c..238b4423f 100644 --- a/include/bud_synthese.inc.php +++ b/include/bud_synthese.inc.php @@ -55,12 +55,24 @@ echo ShowItem(array( // echo '
'; -if ( $do=='po') +if ( $do=='po') { + if ($obj->size_analytic() == 0 ) { + echo '

Desole pas d\'hypothese definie avec un plan analytique

'; + exit(); + + } require_once ('bud_spo.inc.php'); +} + +if ( $do=='ga') { + if ($obj->size_analytic() == 0 ) { + echo '

Desole pas d\'hypothese definie avec un plan analytique

'; + exit(); + + } -if ( $do=='ga') require_once ('bud_sga.inc.php'); - +} if ( $do=='vglobal') require_once ('bud_svglobal.inc.php'); diff --git a/include/ca_pa.inc.php b/include/ca_pa.inc.php index 227dd64b2..5a47ccf8e 100644 --- a/include/ca_pa.inc.php +++ b/include/ca_pa.inc.php @@ -135,6 +135,7 @@ if ( isset($_REQUEST['sa'])) $ret.=$po->form(); $ret.=$wSa->IOValue(); $ret.=widget::submit("add","Ajout"); + $ret.=""; $ret.="
"; } // record the poste @@ -231,10 +232,7 @@ if ( isset($_REQUEST['sa'])) } $ret.=""; - $ret.=sprintf(''. - '', - $_GET['pa_id'] - ); + $ret.=widget::button_href('Ajout',"?p_action=ca_pa&sa=po_add&pa_id=".$_GET['pa_id']."&".$str_dossier); $ret.='
'; } diff --git a/include/class_acc_account_ledger.php b/include/class_acc_account_ledger.php index 6df553909..412950151 100644 --- a/include/class_acc_account_ledger.php +++ b/include/class_acc_account_ledger.php @@ -133,7 +133,7 @@ function get_solde($p_cond=" true ") { case when j_debit='f' then j_montant else 0 end as cred from jrnx join tmp_pcmn on j_poste=pcm_val where - j_poste like ('$this->id'::text) and + j_poste::text like ('$this->id'::text) and $p_cond ) as m "); $Max=pg_NumRows($Res); @@ -157,7 +157,7 @@ function get_solde_detail($p_cond="") { case when j_debit='f' then j_montant else 0 end as cred from jrnx join tmp_pcmn on j_poste=pcm_val where - j_poste like ('$this->id'::text) + j_poste::text like ('$this->id'::text) $p_cond ) as m "; @@ -327,7 +327,7 @@ function get_solde_detail($p_cond="") { if ( strlen (trim($item_cred))) { if ( strstr($item_cred,"*") == true ) { $item_cred=strtr($item_cred,"*","%"); - $SqlItem="$or pcm_val like '$item_cred'"; + $SqlItem="$or pcm_val::text like '$item_cred'"; $or=" or "; } else { $SqlItem="$or pcm_val = '$item_cred' "; diff --git a/include/class_acc_bilan.php b/include/class_acc_bilan.php index 2f7f4cf88..d5db1d4ad 100644 --- a/include/class_acc_bilan.php +++ b/include/class_acc_bilan.php @@ -229,7 +229,7 @@ class Acc_Bilan { function load(){ try { if ( $this->id=="") - throw new Exception("le formulaire id n'est pas donnée"); + throw new Exception("le formulaire id n'est pas donnee"); $sql="select b_name,b_file_template,b_file_form,lower(b_type) as b_type from bilan where". " b_id = ".$this->id; diff --git a/include/class_acc_jrn_info.php b/include/class_acc_jrn_info.php new file mode 100644 index 000000000..acf89d7ef --- /dev/null +++ b/include/class_acc_jrn_info.php @@ -0,0 +1,158 @@ +cn=$p_cn; + $this->ji_id=$p_ji_id; + } + function insert() { + if ( ! isset ($this->jr_id) || + ! isset ($this->ji_value) || + ! isset ($this->id_type ) ) + { + echo 'Appel incorrecte '.__FILE__.__LINE__; + var_dump($this); + exit(); + } + try { + $sql=ExecSqlParam( + $this->cn, + 'insert into jrn_info(jr_id,id_type,ji_value) values ($1,$2,$3)'. + ' returning ji_id ', + array ($this->jr_id,$this->id_type,$this->ji_value) + ); + $this->ji_id=pg_fetch_result($sql,0,0); + } catch (Exception $e) { + echo "Echec sauvegarde info additionnelles"; + throw $e; + } + } + function update() { + if ( ! isset ($this->jr_id) || + ! isset ($this->ji_value) || + ! isset ($this->jr_id ) ) + { + echo 'Appel incorrecte '.__FILE__.__LINE__; + var_dump($this); + exit(); + } + try { + $sql=ExecSqlParam( + $this->cn, + 'update jrn_info set jr_id=$1 ,id_type=$2,ji_value=$3 where ji_id=$4)'. + array ($this->jr_id,$this->id_type,$this->ji_value,$this->ji_id) + ); + } catch (Exception $e) { + Rollback($this->cn); + echo "Echec sauvegarde info additionnelles"; + throw $e; + } + } + function load() { + $sql="select jr_id,id_type,ji_value from jrn_info where ji_id=".$this->ji_id; + $r=ExecSql($this->cn,$sql); + if (pg_NumRows ($r) > 0 ) { + $this->from_array(pg_fetch_array($r,0)); + return 0; + }else { + return 1; + } + + } + function from_array($p_array) { + foreach ($p_array as $col=>$value) { + $this->$col=$value; + } + } + function set_id($p_ji_id) { + $this->$ji_id=$p_ji_id; + } + function set_jrn_id($p_id) { + $this->jr_id=$p_id; + } + function set_type($p_id) { + $this->id_type=$p_id; + } + function set_value($p_id) { + $this->ji_value=$p_id; + } + /*!\brief load all the jrn_info thanks the jr_id + * \return an array of object + */ + function load_all() { + if ( ! isset ($this->jr_id) ) { echo "jr_id is not set ".__FILE__.__LINE__;exit();} + + $sql="select ji_id from jrn_info where jr_id=".$this->jr_id; + $r=ExecSql($this->cn,$sql); + if (pg_NumRows($r) == 0 ) + return array(); + $array=pg_fetch_all($r); + $ret=array(); + foreach ($array as $row) { + $o=new Acc_Jrn_Info($this->cn,$row['ji_id']); + $o->load(); + $ret[]=clone $o; + } + return $ret; + } + function count() { + $sql="select ji_id from jrn_info where jr_id=".$this->jr_id; + return CountSql($this->cn,$sql); + } + function search_id_internal($p_internal) { + $sql="select jr_id from jrn where jr_internal='$p_internal'"; + $r=ExecSql($this->cn,$sql); + if (pg_NumRows($r) > 0 ) { + $this->jr_id=pg_fetch_result($r,0,0); + return $this->jr_id; + } else { + $this->jr_id=-1; + return $this->jr_id; + } + } + static function test_me() { + echo "Dossier = ".Dossier::id(); + $cn=DbConnect(Dossier::id()); + $a=new Acc_Jrn_Info($cn); + $a->jr_id=3; + $a->id_type='BON_COMMANDE'; + $a->ji_value='BON'; + var_dump($a); + $a->insert(); + + $a->set_jrn_id(7); + $a->set_type('OTHER'); + $a->set_value('Autre test'); + $a->insert(); + } +} diff --git a/include/class_acc_ledger.php b/include/class_acc_ledger.php index 6ffc75480..479f7b60d 100644 --- a/include/class_acc_ledger.php +++ b/include/class_acc_ledger.php @@ -123,8 +123,8 @@ class Acc_Ledger { if ( $this->id != 0 ) { if ( $cent=='off' ) { - echo_debug('class_acc_ledger.php',__LINE__,"journaux non centralisé"); - // Journaux non centralisés + echo_debug('class_acc_ledger.php',__LINE__,"journaux non centralise"); + // Journaux non centralises $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, @@ -141,8 +141,8 @@ class Acc_Ledger { " and ".$periode." order by j_date::date asc,jr_internal,j_debit desc ". $cond_limite); }else { - // Journaux centralisés - // echo'class_acc_ledger.php',__LINE__,"journaux centralisé"; + // Journaux centralises + // echo'class_acc_ledger.php',__LINE__,"journaux centralise"; $Sql="select jr_opid as j_id, c_order as int_j_id, to_char (c_date,'DD.MM.YYYY') as j_date , @@ -173,8 +173,8 @@ class Acc_Ledger { } else { // Grand Livre if ( $cent == 'off') { - echo_debug('class_acc_ledger.php',__LINE__,"Grand livre non centralisé"); - // Non centralisé + echo_debug('class_acc_ledger.php',__LINE__,"Grand livre non centralise"); + // Non centralise $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, @@ -190,8 +190,8 @@ class Acc_Ledger { $cond_limite); } else { - echo_debug('class_acc_ledger.php',__LINE__,"Grand livre centralisé"); - // Centralisé + echo_debug('class_acc_ledger.php',__LINE__,"Grand livre centralise"); + // Centralise $Sql="select jr_c_opid as j_id, c_order as int_j_id, c_j_id, @@ -334,7 +334,7 @@ class Acc_Ledger { // Non Centralise si cent=off //-- if ($cent=='off') - {// Non centralisé + {// Non centralise $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per'); @@ -361,7 +361,7 @@ class Acc_Ledger { $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:""; - //Centralisé + //Centralise //--- $id=($this->id == 0 ) ?"jr_c_opid as num":"jr_opid as num"; @@ -1254,7 +1254,7 @@ class Acc_Ledger { $op->p_jrn=$id; $op->od_direct='t'; if ($op->count() != 0 ) - echo widget::submit('use_opd','Utilisez une op.prédéfinie'); + echo widget::submit('use_opd','Utilisez une op.prédéfinie'); echo $op->show_button(); echo ''; exit(); diff --git a/include/class_action.php b/include/class_action.php index 4abc87fd3..8c80674a4 100644 --- a/include/class_action.php +++ b/include/class_action.php @@ -398,8 +398,8 @@ class action $str_type=$v[0]; if ( isset ($_REQUEST['url'])) { - $retour=sprintf('', - urldecode($_REQUEST['url'])); + $retour=widget::button_href('Retour',urldecode($_REQUEST['url'])); + $h_url=sprintf('',urldecode($_REQUEST['url'])); } else diff --git a/include/class_admin.php b/include/class_admin.php index 724a8f80c..c704d8cb1 100644 --- a/include/class_admin.php +++ b/include/class_admin.php @@ -101,7 +101,7 @@ class Admin extends fiche{ return $r; foreach ($step_admin as $admin ) { $r.=""; - $e=sprintf(' ', + $e=sprintf(' ', $script,$admin->id,$str_dossier,$url); $r.=" $e".$admin->strAttribut(ATTR_DEF_QUICKCODE).""; diff --git a/include/class_anc_account.php b/include/class_anc_account.php index c8db6ebff..c8ee246df 100644 --- a/include/class_anc_account.php +++ b/include/class_anc_account.php @@ -226,10 +226,15 @@ class Anc_Account $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); - $wGa_id=new widget("select","Groupe","ga_id"); - $wGa_id->value=make_array($this->db,"select ga_id,ga_id from groupe_analytique",1); - $wGa_id->selected=$this->ga_id; - $wGa_id->table=1; + $aGroup_analytic=make_array($this->db,"select ga_id,ga_id from groupe_analytique where pa_id=".$this->pa_id,1); + if ( count($aGroup_analytic) > 1 ) { + $wGa_id=new widget("select","Groupe","ga_id"); + $wGa_id->value=$aGroup_analytic; + $wGa_id->selected=$this->ga_id; + $wGa_id->table=1; + } else { + $wGa_id=new widget('span'); + } $pa=new Anc_Plan($this->db,$this->pa_id); $pa->get(); $wPaName=new widget("text","Plan A.","",$pa->name); diff --git a/include/class_anc_balance_double.php b/include/class_anc_balance_double.php index df0e042af..f763c1de6 100644 --- a/include/class_anc_balance_double.php +++ b/include/class_anc_balance_double.php @@ -204,7 +204,7 @@ class Anc_Balance_Double extends Anc_Print 'solde'=>'Solde', 'dc'=>'D/C'), 'Totaux', - array('shaded'=>1,'showHeadings'=>1,cols=>array + array('shaded'=>1,'showHeadings'=>1,'cols'=>array ('debit'=>array('justification'=>'right'), 'credit'=>array('justification'=>'right'), 'solde'=>array('justification'=>'right'), ) @@ -274,7 +274,7 @@ class Anc_Balance_Double extends Anc_Print $choose=new widget("button"); $choose->name="Choix Poste"; $choose->label="Recherche"; - $choose->javascript="onClick=search_ca('".$_REQUEST['PHPSESSID']."',".dossier::id().",'from_poste2','pa_id')"; + $choose->javascript="onClick=search_ca('".$_REQUEST['PHPSESSID']."',".dossier::id().",'from_poste2','pa_id2')"; $r.=$choose->IOValue(); $r.=" et le poste ".$poste->IOValue("to_poste2",$this->to_poste2); @@ -370,7 +370,7 @@ class Anc_Balance_Double extends Anc_Print $and=" and "; } if ( $filter_poste != "") - $filter_poste.=" where ".$filter_poste; + $filter_poste=" where ".$filter_poste; $sql=" select a_po_id , @@ -386,7 +386,7 @@ b.po_id as b_po_id, case when a.oa_debit='t' then a.oa_amount else 0 end as a_oa_amount_d, case when a.oa_debit='f' then a.oa_amount else 0 end as a_oa_amount_c from -operation_analytique as a join operation_analytique as b using (oa_group) +operation_analytique as a join operation_analytique as b using (j_id) where a.pa_id=". $this->pa_id." and b.pa_id=".$this->pa_id2." ".$this->set_sql_filter()." diff --git a/include/class_anc_group_operation.php b/include/class_anc_group_operation.php index 7af0720e0..f743b7412 100644 --- a/include/class_anc_group_operation.php +++ b/include/class_anc_group_operation.php @@ -174,12 +174,12 @@ class Anc_Group_Operation $p->oa_amount=$p_array["pamount$i"]; $p->oa_description=$p_array["pdesc"]; - $p->oa_date=$_POST['pdate']; + $p->oa_date=$p_array['pdate']; $p->j_id=0; $p->oa_debit=(isset ($p_array["pdeb$i"]))?'t':'f'; $p->oa_group=0; - $p->po_id=$_POST["pop$i"."plan".$idx]; + $p->po_id=$p_array["pop$i"."plan".$idx]; $p->pa_id=$idx; $this->a_operation[]=clone $p; } diff --git a/include/class_anc_plan.php b/include/class_anc_plan.php index 8e4b3b778..273bcdd12 100644 --- a/include/class_anc_plan.php +++ b/include/class_anc_plan.php @@ -209,7 +209,7 @@ class Anc_Plan var_dump($p); echo "

Update

"; $p->name="Update "; - $p->description="c'est changé"; + $p->description="c'est change"; $p->update(); $p->get(); var_dump($p); diff --git a/include/class_bud_hypo.php b/include/class_bud_hypo.php index b88d5ffb0..5963dd9d5 100644 --- a/include/class_bud_hypo.php +++ b/include/class_bud_hypo.php @@ -77,7 +77,7 @@ class Bud_Hypo { function add() { $bh_saldo=(isNumber($this->bh_saldo) == 1 ) ?$this->bh_saldo:0; $pa_id=($this->pa_id <= 0 )?null:$this->pa_id; - + if ( strlen(trim ($this->bh_name)) == 0 ) return; $sql="insert into bud_hypothese( bh_name,bh_saldo,bh_description,pa_id) ". " values ($1,$2,$3,$4) returning bh_id"; $array=array( @@ -90,6 +90,7 @@ class Bud_Hypo { $this->bh_id=pg_fetch_result($a,0,0); } function update() { + if ( strlen(trim ($this->bh_name)) == "" ) return; $bh_name=pg_escape_string($this->bh_name); $bh_saldo=(isNumber($this->bh_saldo) == 1 ) ?$this->bh_saldo:0; $bh_description=pg_escape_string($this->bh_description); @@ -174,6 +175,11 @@ class Bud_Hypo { $count=getDbValue($this->db,"select count(*) from bud_hypothese"); return $count; } + function size_analytic() { + $count=getDbValue($this->db,"select count(*) from bud_hypothese where pa_id is not null"); + return $count; + } + static function test_me() { $cn=DbConnect (dossier::id()); ExecSql($cn,"delete from bud_hypothese"); diff --git a/include/class_bud_synthese_acc.php b/include/class_bud_synthese_acc.php index a633ede01..d0348bd1e 100644 --- a/include/class_bud_synthese_acc.php +++ b/include/class_bud_synthese_acc.php @@ -59,7 +59,7 @@ class Bud_Synthese_Acc extends Bud_Synthese { /* 2nd Step */ if ( $this->bh_id == 0 ) - throw new Exception ("bh_id n'est pas sélectionné"); + throw new Exception ("bh_id n'est pas selectionne"); $hypo=new Bud_Hypo($this->cn); $hypo->bh_id=$this->bh_id; $hypo->load(); @@ -163,6 +163,8 @@ class Bud_Synthese_Acc extends Bud_Synthese { " join parm_periode using (p_id) ". " where bc_id=$1 and $per and pcm_val=$2 group by p_id,p_start order by p_start"); + if ( empty ($aBudCard)) + return; // foreach card get the detail per pcm_val and periode foreach ($aBudCard as $rBudCard) { $line=array(); @@ -232,10 +234,10 @@ class Bud_Synthese_Acc extends Bud_Synthese { function display_html($p_array) { $r=""; if (empty($p_array)) return; + $persql=sql_filter_per($this->cn,$this->from,$this->to,'p_id','p_id'); $per=get_array($this->cn,"select to_char(p_start,'MM.YYYY') as d". " from parm_periode ". - " where p_id between ".$this->from.' and '. - $this->to." order by p_start" ); + " where $persql"); $heading=" CE "; foreach( $per as $c) { $heading.=''.$c['d'].'';} diff --git a/include/class_bud_synthese_anc.php b/include/class_bud_synthese_anc.php index 6deca935f..7026ba96b 100644 --- a/include/class_bud_synthese_anc.php +++ b/include/class_bud_synthese_anc.php @@ -57,7 +57,7 @@ class Bud_Synthese_Anc extends Bud_Synthese { /* 2nd Step */ if ( $this->bh_id == 0 ) - throw new Exception ("bh_id n'est pas sélectionné"); + throw new Exception ("bh_id n'est pas selectionne"); $hypo=new Bud_Hypo($this->cn); $hypo->bh_id=$this->bh_id; $hypo->load(); @@ -112,7 +112,7 @@ class Bud_Synthese_Anc extends Bud_Synthese { [80] => 14.0000 ) - [acc_name] => Electricité + [acc_name] => Electricite [acc_amount] => 0 ) @@ -225,10 +225,11 @@ class Bud_Synthese_Anc extends Bud_Synthese { function display_html($p_array) { $r=""; if (empty($p_array)) return; + $persql=sql_filter_per($this->cn,$this->from,$this->to,'p_id','p_id'); $per=get_array($this->cn,"select to_char(p_start,'MM.YYYY') as d". " from parm_periode ". - " where p_id between ".$this->from.' and '. - $this->to." order by p_start" ); + " where $persql"); + $heading=" CE "; foreach( $per as $c) { $heading.=''.$c['d'].'';} $heading.="Total Unite"; diff --git a/include/class_bud_synthese_group.php b/include/class_bud_synthese_group.php index 7d57cd4f3..63a61f2cf 100644 --- a/include/class_bud_synthese_group.php +++ b/include/class_bud_synthese_group.php @@ -1,4 +1,3 @@ - bh_id == 0 ) - throw new Exception ("bh_id n'est pas sélectionné"); + throw new Exception ("bh_id n'est pas selectionne"); $hypo=new Bud_Hypo($this->cn); $hypo->bh_id=$this->bh_id; $hypo->load(); @@ -192,6 +191,9 @@ class Bud_Synthese_Group extends Bud_Synthese { $pcm_val=""; $old="XX"; $sub=array(); + if ( empty($res) ) + return; + foreach ($res as $row) { $pcm_val=$row['pcm_val']; @@ -375,11 +377,11 @@ Array function display_html($p_array) { $r=""; + $persql=sql_filter_per($this->cn,$this->from,$this->to,'p_id','p_id'); list ($head,$foot)=$this->head_foot($p_array); $per=get_array($this->cn,"select p_id,to_char(p_start,'MM.YYYY') as d". " from parm_periode ". - " where p_id between ".$this->from.' and '. - $this->to." order by p_start" ); + " where $persql"); $r.=''; $heading=""; foreach( $per as $c) { @@ -401,7 +403,8 @@ Array $r.=''; $r.=''; // content - + if ( empty($p_array)) + return; foreach ($p_array as $key => $value ){ $r.=''; $r.=''; diff --git a/include/class_bud_synthese_hypo.php b/include/class_bud_synthese_hypo.php index 1075676ee..f6b6c038e 100644 --- a/include/class_bud_synthese_hypo.php +++ b/include/class_bud_synthese_hypo.php @@ -87,7 +87,7 @@ Array [GROUPE1] => 81.7 [GROUPE3] => 28 [total_row] => 109.7 - [acc_name] => Electricité + [acc_name] => Electricite [acc_amount] => 0 ) diff --git a/include/class_customer.php b/include/class_customer.php index ac69ffaa2..9f23b0653 100644 --- a/include/class_customer.php +++ b/include/class_customer.php @@ -105,8 +105,8 @@ class Customer extends fiche{ jrnx as A join jrnx as B using (j_grpt) where - A.j_poste like '".$CUSTOMER."%' and - B.j_poste like '".$SOLD."%' + A.j_poste::text like '".$CUSTOMER."%' and + B.j_poste::text like '".$SOLD."%' $cond_sql "; diff --git a/include/class_document.php b/include/class_document.php index 427e93cd0..06da2fcd8 100644 --- a/include/class_document.php +++ b/include/class_document.php @@ -464,6 +464,9 @@ class Document * - [MY_TVA] * - [MY_STREET] * - [MY_NUMBER] + * - BON_COMMANDE + * - OTHER_INFO + * - CUST_NUM * * \param TAG * \return String which must replace the tag @@ -554,8 +557,7 @@ class Document case 'CUST_CP': $tiers=new fiche($this->db); -$qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST[ -'e_client']; + $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client']; $tiers->get_by_qcode($qcode,false); $r=$tiers->strAttribut(ATTR_DEF_CP); @@ -563,8 +565,7 @@ $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST[ case 'CUST_CITY': $tiers=new fiche($this->db); -$qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST[ -'e_client']; + $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client']; $tiers->get_by_qcode($qcode,false); $r=$tiers->strAttribut(ATTR_DEF_CITY); @@ -573,8 +574,7 @@ $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST[ case 'CUST_CO': $tiers=new fiche($this->db); -$qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST[ -'e_client']; + $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client']; $tiers->get_by_qcode($qcode,false); $r=$tiers->strAttribut(ATTR_DEF_PAYS); @@ -584,11 +584,17 @@ $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST[ case 'CUST_VAT': $tiers=new fiche($this->db); -$qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST[ -'e_client']; + $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client']; $tiers->get_by_qcode($qcode,false); $r=$tiers->strAttribut(ATTR_DEF_NUMTVA); break; + case 'CUST_NUM': + $tiers=new fiche($this->db); + $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client']; + $tiers->get_by_qcode($qcode,false); + $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER); + break; + // Marchandise in $_POST['e_march*'] // \see user_form_achat.php or user_form_ven.php case 'NUMBER': @@ -811,6 +817,19 @@ $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST[ $r=$sum; break; + case 'BON_COMMANDE': + if ( isset($_REQUEST['bon_comm'])) + return $_REQUEST['bon_comm']; + else + return ""; + break; + case 'OTHER_INFO': + if ( isset($_REQUEST['other_info'])) + return $_REQUEST['other_info']; + else + return ""; + break; + } return $r; diff --git a/include/class_dossier.php b/include/class_dossier.php index cd32a3894..3ad92d9bf 100644 --- a/include/class_dossier.php +++ b/include/class_dossier.php @@ -37,6 +37,7 @@ require_once('ac_common.php'); class dossier { + /*!\brief return the $_REQUEST['gDossier'] after a check */ static function id() { echo_debug(__FILE__,__LINE__,"id"); diff --git a/include/class_fiche.php b/include/class_fiche.php index d05171cbb..15e1e15f9 100644 --- a/include/class_fiche.php +++ b/include/class_fiche.php @@ -431,9 +431,13 @@ class fiche { * \brief insert a new record * * \param p_fiche_def fiche_def.fd_id + * \param p_array is the array containing the data */ - function insert($p_fiche_def) + function insert($p_fiche_def,$p_array=null) { + if ( $p_array == null) + $p_array=$_POST; + $fiche_id=NextSequence($this->cn,'s_fiche'); $this->id=$fiche_id; // first we create the card @@ -444,8 +448,8 @@ class fiche { " values (%d,%d)", $fiche_id,$p_fiche_def); $Ret=ExecSql($this->cn,$sql); - // parse the $_POST array - foreach ($_POST as $name=>$value ) + // parse the $p_array array + foreach ($p_array as $name=>$value ) { echo_debug ("class_fiche",__LINE__,"Name = $name value $value") ; list ($id) = sscanf ($name,"av_text%d"); @@ -471,8 +475,8 @@ class fiche { $exercice=$user->get_exercice(); if ( $exercice == 0 ) throw Exception ('Annee invalide erreur'); - $str_stock=sprintf('insert into stock_goods(f_id,sg_initial,sg_code,sg_type,sg_exercice) '. - ' values (%d,upper(\'%s\'),\'c\',\'%s\')', + $str_stock=sprintf('insert into stock_goods(f_id,sg_quantity,sg_comment,sg_code,sg_type,sg_exercice) '. + ' values (%d,0,\'%s\',upper(\'%s\'),\'d\',\'%s\')', $fiche_id, 'initial', FormatString($value), @@ -565,12 +569,15 @@ class fiche { /*!\brief update a card * \todo add a check to return an error and rollback operation */ - function update() + function update($p_array=null) { + if ( $p_array == null) + $p_array=$_POST; + try { StartSql($this->cn); - // parse the $_POST array - foreach ($_POST as $name=>$value ) + // parse the $p_array array + foreach ($p_array as $name=>$value ) { echo_debug ("class_fiche",__LINE__,"Name = $name value $value") ; list ($id) = sscanf ($name,"av_text%d"); @@ -619,19 +626,24 @@ class fiche { } if ( $id == ATTR_DEF_STOCK ) { $st=CountSql($this->cn,'select * from stock_goods where '. - " upper(sg_code)=upper('$value')"); + " f_id=".$this->id); if ( $st == 0 ) { $user=new User($this->cn); $exercice=$user->get_exercice(); if ( $exercice == 0 ) throw Exception ('Annee invalide erreur'); - $str_stock=sprintf('insert into stock_goods(f_id,sg_comment,sg_code,sg_type,sg_exercice) '. - ' values (%d,upper(\'%s\'),upper(\'%s\'),\'d\',%s)', - $this->id, - 'initial', - FormatString($value), - $exercice); - + $str_stock=sprintf('insert into stock_goods(f_id,sg_quantity,sg_comment,sg_code,sg_type,sg_exercice) '. + ' values (%d,0,\'%s\',upper(\'%s\'),\'d\',\'%s\')', + $this->id, + 'initial', + FormatString($value), + $exercice); + + ExecSql($this->cn,$str_stock); + }else { + $str_stock=sprintf("update stock_goods set sg_code=upper('%s') where f_id=%d", + FormatString($value), + $this->id); ExecSql($this->cn,$str_stock); } } @@ -876,12 +888,15 @@ class fiche { * * \return none */ - function HtmlTable() + function HtmlTable($p_array=null) { + if ( $p_array == null) + $p_array=$_POST; + $name=$this->getName(); - list($array,$tot_deb,$tot_cred)=$this->get_row( $_POST['from_periode'], - $_POST['to_periode'] + list($array,$tot_deb,$tot_cred)=$this->get_row( $p_array['from_periode'], + $p_array['to_periode'] ); if ( count($this->row ) == 0 ) @@ -928,8 +943,11 @@ class fiche { * * \return none */ - function HtmlTableHeader() + function HtmlTableHeader($p_array=null) { + if ( $p_array == null) + $p_array=$_POST; + $submit=new widget(); $hid=new widget("hidden"); echo '
'; @@ -948,8 +966,8 @@ class fiche { $hid->IOValue('p_action','impress'). $hid->IOValue("f_id",$this->id). dossier::hidden(). - $hid->IOValue("from_periode",$_POST['from_periode']). - $hid->IOValue("to_periode",$_POST['to_periode']); + $hid->IOValue("from_periode",$p_array['from_periode']). + $hid->IOValue("to_periode",$p_array['to_periode']); echo ""; echo '
"; echo "
CE
'.$key.'
'. @@ -958,8 +976,8 @@ class fiche { $hid->IOValue("type","poste"). $hid->IOValue('p_action','impress'). $hid->IOValue("f_id",$this->id). - $hid->IOValue("from_periode",$_POST['from_periode']). - $hid->IOValue("to_periode",$_POST['to_periode']); + $hid->IOValue("from_periode",$p_array['from_periode']). + $hid->IOValue("to_periode",$p_array['to_periode']); echo "
"; diff --git a/include/class_gestion_purchase.php b/include/class_gestion_purchase.php index 9fb475207..eb51ed160 100644 --- a/include/class_gestion_purchase.php +++ b/include/class_gestion_purchase.php @@ -43,7 +43,9 @@ class gestion_purchase extends gestion_table var $qp_nd_tva_recup; /*!< tva ded via taxe */ var $qp_supplier; /*!< supplier code (f_id) */ var $qp_valid; - var $j_id; /*!< jrnx.j_id */ + var $j_id; /*!< jrnx.j_id + */ + var $qp_dep_priv; /*!< private purchase */ /*!\brief return an array of gestion_table, the object are * retrieved thanks the qs_internal */ @@ -63,7 +65,8 @@ class gestion_purchase extends gestion_table qp_nd_tva, qp_nd_tva_recup, qp_supplier, - j_id + j_id, + qp_dep_priv from quant_purchase left join tva_rate on (qp_vat_code=tva_id) where qp_internal='".$this->qp_internal."'"; $ret=ExecSql($this->db,$sql); diff --git a/include/class_periode.php b/include/class_periode.php index 95fbbba0b..1b656cf0c 100644 --- a/include/class_periode.php +++ b/include/class_periode.php @@ -217,7 +217,7 @@ class Periode { echo ' '.$l_line['p_exercice'].''; if ( $l_line['status'] != 'OP' ) { - $closed=($l_line['status']=='CE')?'Centralisée':'Fermée'; + $closed=($l_line['status']=='CE')?'Centralisee':'Fermée'; } else { $closed=''; $closed.=' Cloturer'; diff --git a/include/class_user.php b/include/class_user.php index 703768d1a..fc11f2dc6 100644 --- a/include/class_user.php +++ b/include/class_user.php @@ -324,7 +324,7 @@ function load_global_pref() $line[$type]=$row['parameter_value'];; } // save array into g_ variable - $array_pref=array ('g_theme'=>'THEME','g_pagesize'=>'PAGESIZE'); + $array_pref=array ('g_theme'=>'THEME','g_pagesize'=>'PAGESIZE','g_topmenu'=>'TOPMENU'); foreach ($array_pref as $name=>$parameter ) { if ( ! isset ($line[$parameter]) ) { echo_debug("Missing pref : ".$parameter); @@ -349,7 +349,7 @@ function insert_default_global_pref($p_type="",$p_value="") { echo_debug('class_user.php',__LINE__,"parameter p_type $p_type p_value $p_value"); $default_parameter= array("THEME"=>"Light", - "PAGESIZE"=>"50"); + "PAGESIZE"=>"50",'TOPMENU'=>'SELECT'); $cn=Dbconnect(); $Sql="insert into user_global_pref(user_id,parameter_type,parameter_value) values ('%s','%s','%s')"; @@ -378,7 +378,7 @@ function insert_default_global_pref($p_type="",$p_value="") { */ function update_global_pref($p_type,$p_value="") { $default_parameter= array("THEME"=>"Light", - "PAGESIZE"=>"50"); + "PAGESIZE"=>"50",'TOPMENU'=>'SELECT'); $cn=Dbconnect(); $Sql="update user_global_pref set parameter_value='%s' where parameter_type='%s' and diff --git a/include/class_widget.php b/include/class_widget.php index 554a39813..afb7dbf51 100644 --- a/include/class_widget.php +++ b/include/class_widget.php @@ -129,7 +129,7 @@ class widget { $r='javascript." ".$disabled." $readonly $this->extra >"; + 'SIZE="'.$this->size.'" '.$this->javascript." ".$disabled." $readonly $this->extra >"; if ($this->table==1) { if ( $this->label != "") { @@ -657,9 +657,19 @@ class widget { return ''; } static function button_href($p_name,$p_value) { - return sprintf('', - $p_value, - $p_name); + $agent=$_SERVER['HTTP_USER_AGENT']; + + if ( strpos($agent,'MSIE') == 0 && + strpos ($agent,'Konqueror') ==0) + return sprintf('', + $p_value, + $p_name); + + return sprintf(' '. + ' %s', + $p_value, + $p_name); + } } diff --git a/include/client.inc.php b/include/client.inc.php index ce2324cba..fcd395b5d 100644 --- a/include/client.inc.php +++ b/include/client.inc.php @@ -46,8 +46,7 @@ if ( isset ($_POST['delete']) ) if ( $sub_action=="insert" ) { - $retour=sprintf('', - urldecode($_REQUEST['url'])); + $retour=widget::button_href("Retour", urldecode($_REQUEST['url'])); $customer=new Customer($cn); $customer->Save($_REQUEST['fd_id']); @@ -77,8 +76,8 @@ if ( $sub_action == "" ) if ( $sub_action=="blank") { - $retour=sprintf('', - "commercial.php?p_action=client&$str_dossier"); + $retour=widget::button_href('Retour','commercial.php?p_action=fournisseur&'.dossier::get()); + echo '
'; echo $retour; @@ -116,7 +115,6 @@ if ( $sub_action == "list" )
- +
@@ -148,8 +147,8 @@ if ( $sub_action == 'detail' ) $f_id=$_REQUEST['f_id']; echo '
'; $client=new Customer($cn,$f_id); - $retour=sprintf('', - urldecode($_REQUEST['url'])); + $retour=widget::button_href("Retour", urldecode($_REQUEST['url'])); + echo $retour; echo '
'; echo dossier::hidden(); diff --git a/include/constant.php b/include/constant.php index b413b7acc..08aea30ae 100644 --- a/include/constant.php +++ b/include/constant.php @@ -136,7 +136,8 @@ define ("ATTR_DEF_EMAIL",18); define ("ATTR_DEF_CITY",24); define ("ATTR_DEF_COMPANY",25); define ("ATTR_DEF_FAX",26); - +define ("ATTR_DEF_NUMBER_CUSTOMER",30); +define ("ATTR_DEF_DEP_PRIV",31); define ("FICHE_TYPE_CLIENT",9); define ("FICHE_TYPE_VENTE",1); diff --git a/include/contact.inc.php b/include/contact.inc.php index e16eb3bf6..d0b4a5ae3 100644 --- a/include/contact.inc.php +++ b/include/contact.inc.php @@ -36,7 +36,8 @@ $sub_action=(isset($_REQUEST['sa']))?$_REQUEST['sa']:""; // TODO add function for generating url, hidden tags... if ( isset ($_REQUEST['url'])) { - $retour=sprintf('',urldecode($_REQUEST['url'])); + $retour=widget::button_href('Retour',urldecode($_REQUEST['url'])); + $h_url=sprintf('',urldecode($_REQUEST['url'])); } else @@ -87,8 +88,8 @@ if ( $sub_action == "" ) //Display a blank card if ( $sub_action=="blank") { - $retour_action=sprintf('', - "commercial.php?p_action=contact&$str_dossier"); + $retour_action=widget::button_href('Retour', "commercial.php?p_action=contact&$str_dossier"); + echo '
'; echo $retour_action; diff --git a/include/depense.inc.php b/include/depense.inc.php index 33b2ae8eb..d3981e5e4 100644 --- a/include/depense.inc.php +++ b/include/depense.inc.php @@ -52,7 +52,8 @@ $h_url=""; if ( isset ($_REQUEST['url'])) { - $retour=sprintf('',urldecode($_REQUEST['url'])); + $retour=widget::button_href('Retour',urldecode($_REQUEST['url'])); + $h_url=sprintf('',urldecode($_REQUEST['url'])); } diff --git a/include/facture.inc.php b/include/facture.inc.php index 28c0b0b0f..6b682c986 100644 --- a/include/facture.inc.php +++ b/include/facture.inc.php @@ -24,6 +24,8 @@ require_once('jrn.php'); require_once("class_document.php"); require_once("class_fiche.php"); require_once("check_priv.php"); +require_once('class_acc_jrn_info.php'); + $tag_list='Liste'; $tag_list_sel='Liste'; $tag_unpaid='Non paye'; @@ -52,7 +54,8 @@ $h_url=""; if ( isset ($_REQUEST['url'])) { - $retour=sprintf('',urldecode($_REQUEST['url'])); + $retour=widget::button_href('Retour',urldecode($_REQUEST['url'])); + $h_url=sprintf('',urldecode($_REQUEST['url'])); } @@ -357,6 +360,19 @@ if ( isset($_POST['record_and_print_invoice'])) // Update the comment with invoice number $sql="update jrn set jr_comment='Facture ".$doc->d_number."' where jr_internal='$internal'"; ExecSql($cn,$sql); + /* Save the additional information into jrn_info */ + $obj=new Acc_Jrn_Info($cn); + $jr_id=$obj->search_id_internal($internal); + if (strlen(trim($_POST['bon_comm'] )) != 0 ) { + $obj->set_type('BON_COMMANDE'); + $obj->set_value($_POST['bon_comm']); + $obj->insert(); + } + if (strlen(trim($_POST['other_info'] )) != 0 ) { + $obj->set_type('OTHER'); + $obj->set_value($_POST['other_info']); + $obj->insert(); + } echo $str_file; } } else { diff --git a/include/fiche.inc.php b/include/fiche.inc.php index 549a04268..acc9a26ac 100644 --- a/include/fiche.inc.php +++ b/include/fiche.inc.php @@ -255,7 +255,7 @@ if ( isset ( $_GET["action"]) ) { $sql="select distinct f_id,fd_id,av_text from fiche join jnt_fic_att_value using (f_id) join attr_value using (jft_id) where upper(av_text) like upper('%".FormatString($_GET["search_text"])."%') order by av_text,f_id"; - $all=getArray($cn,$sql); + $all=get_array($cn,$sql); // test on the size // if ( sizeof($all) != 0 ) diff --git a/include/fiche_def.inc.php b/include/fiche_def.inc.php index fed2f7318..8f311bf52 100644 --- a/include/fiche_def.inc.php +++ b/include/fiche_def.inc.php @@ -56,7 +56,7 @@ echo ""; if ( isset ($_POST['mod']) ) { extract ($_POST); - echo '
'; + echo '
'; echo "Voulez-vous modifier ?
Attention, ne changer pas la signification de "; echo " ce poste, par exemple ne pas changer Client par fournisseur,
sinon le programme fonctionnera mal, utiliser uniquement des chiffres pour la classe de base ou rien
"; $idx=$_POST['idx']; diff --git a/include/import_inc.php b/include/import_inc.php index b70533e2b..126267d86 100644 --- a/include/import_inc.php +++ b/include/import_inc.php @@ -27,7 +27,7 @@ require_once('class_user.php'); require_once('class_widget.php'); require_once('class_fiche.php'); require_once('class_acc_ledger.php'); - +require_once('class_parm_code.php'); /*! ************************************************** * \brief Parse the file and insert the record @@ -389,7 +389,8 @@ $w=new widget("select"); $w->label='Journal'; echo $w->label." :".$w->IOValue('import_jrn',$jrn)."
"; // choose the bank account - $bq=make_array($p_cn,"select pcm_val,pcm_lib from tmp_pcmn where pcm_val like '550%'"); + $banque=new parm_code($p_cn,'BANQUE'); + $bq=make_array($p_cn,"select pcm_val,pcm_lib from tmp_pcmn where pcm_val::text like '".$banque->p_value."%'"); $w->label='Banque'; echo "Compte en banque :".$w->IOValue('import_bq',$bq)."
"; $format_csv=make_array($p_cn,"select include_file,name from format_csv_banque;"); diff --git a/include/impress_inc.php b/include/impress_inc.php index 00ca6cf31..3bec06932 100644 --- a/include/impress_inc.php +++ b/include/impress_inc.php @@ -584,7 +584,7 @@ function ParseFormula($p_cn,$p_label,$p_formula,$p_start,$p_end,$p_eval=true,$p_ "select p_exercice from parm_periode where p_id=$user_periode"); $sql_per="select to_char(p_start,'MM.YYYY') as start from parm_periode where ". " p_exercice='".$periode."' order by p_start"; - $ret=getArray($p_cn,$sql_per); + $ret=get_array($p_cn,$sql_per); $from=$ret[0]['start']; } @@ -650,7 +650,7 @@ function GetFormulaValue($p_cn,$p_label,$p_formula,$p_cond) $l_credit=0; // somme debit $Res=ExecSql($p_cn,"select sum (j_montant) as montant from - jrnx where $p_cond and j_debit='t' and j_poste like '$p_formula'"); + jrnx where $p_cond and j_debit='t' and j_poste::text like '$p_formula'"); if (pg_NumRows($Res)==0){ $l_debit=0; } else { @@ -659,7 +659,7 @@ function GetFormulaValue($p_cn,$p_label,$p_formula,$p_cond) } // somme credit $Res=ExecSql($p_cn,"select sum (j_montant) as montant from - jrnx where $p_cond and j_debit='f' and j_poste like '$p_formula'"); + jrnx where $p_cond and j_debit='f' and j_poste::text like '$p_formula'"); if (pg_NumRows($Res)==0) { $l_credit=0; } else { diff --git a/include/impress_jrn.inc.php b/include/impress_jrn.inc.php index a0ecfba31..b69aceeeb 100644 --- a/include/impress_jrn.inc.php +++ b/include/impress_jrn.inc.php @@ -126,6 +126,15 @@ require_once("class_acc_ledger.php"); /* "Pièce justificative". */ " montant". ""; + // set a filter for the FIN + $a_parm_code=get_array($cn,"select p_value from parm_code where p_code in ('BANQUE','COMPTE_COURANT','CAISSE')"); + $sql_fin="("; + $or=""; + foreach ($a_parm_code as $code) { + $sql_fin.="$or j_poste::text like '".$code['p_value']."%'"; + $or=" or "; + } + $sql_fin.=")"; foreach ($Row as $line) { @@ -140,7 +149,7 @@ require_once("class_acc_ledger.php"); // Get the jrn type if ( $line['jrn_def_type'] == 'FIN' ) { $positive = CountSql($cn,"select * from jrn inner join jrnx on jr_grpt_id=j_grpt ". - " where jr_id=".$line['jr_id']." and (j_poste like '55%' or j_poste like '57%' )". + " where jr_id=".$line['jr_id']." and $sql_fin ". " and j_debit='f'"); echo ""; diff --git a/include/impress_poste.inc.php b/include/impress_poste.inc.php index b91b057c0..ece12386b 100644 --- a/include/impress_poste.inc.php +++ b/include/impress_poste.inc.php @@ -94,7 +94,7 @@ if ( isset( $_POST['bt_html'] ) ) { if ( isset ($_POST['poste_fille']) ) { $parent=$_POST['poste_id']; - $a_poste=get_array($cn,"select pcm_val from tmp_pcmn where pcm_val like '$parent%' order by pcm_val::text"); + $a_poste=get_array($cn,"select pcm_val from tmp_pcmn where pcm_val::text like '$parent%' order by pcm_val::text"); $go=3; } // Check if the post is numeric and exists diff --git a/include/jrn.php b/include/jrn.php index 1e7a66d9c..859eff31c 100644 --- a/include/jrn.php +++ b/include/jrn.php @@ -30,6 +30,8 @@ require_once ('class_anc_plan.php'); require_once ('class_anc_operation.php'); require_once ('class_acc_ledger.php'); require_once ('class_acc_operation.php'); +require_once ('class_acc_jrn_info.php'); + /*! * \brief Display the form to UPDATE account operation in the expert view * @@ -143,11 +145,14 @@ function ShowOperationExpert($p_cn,$p_jr_id,$p_mode=1) if ( $content['jr_pj_name'] != "") $r.='Effacer PJ '; } - $r.="".sprintf('%s', - $content['jr_id'], - $content['jr_grpt_id'], - $str_dossier, - $content['jr_pj_name']).""; + $r.="".sprintf('%s', + $content['jr_id'], + $content['jr_grpt_id'], + $str_dossier, + $_REQUEST['PHPSESSID'], + $content['jr_pj_name'] + + ).""; $r.=""; if ( $p_mode == 1 ) { @@ -287,12 +292,14 @@ function ShowOperationUser($p_cn,$p_jr_id,$p_mode=1) $r.='Nom'; $r.='PU'; $r.='Quantité'; + $r.=' Dep. priv. '; $r.='tva'; - $r.='code tva'; - $r.='Non Ded.'; + $r.='tva'; + $r.='non ded.'; $r.='tva nd'; $r.='tva d impot'; - $r.='prix'; + $r.='total htva'; + $r.='total tvac'; $r.=''; $object=new gestion_purchase($p_cn); @@ -303,6 +310,7 @@ function ShowOperationUser($p_cn,$p_jr_id,$p_mode=1) $tot_nd=0.0; $tot_tva_nd=0.0; $tot_tva_nd_recup=0.0; + $tot_dep_priv=0.0; $i=0; $i_march=0; foreach ($array as $row) { @@ -314,20 +322,24 @@ function ShowOperationUser($p_cn,$p_jr_id,$p_mode=1) $tot_tva_nd+=$row->qp_nd_tva; $tot_tva_nd_recup+=$row->qp_nd_tva_recup; $tot_amount+=$row->qp_price; + $tot_dep_priv+=$row->qp_dep_priv; // $hid_jid=new widget("hidden","","p_jid_".$row->j_id,$row->j_id); $r.=($i%2==0)?"":''; $i++; $pu=0.0; - if ( $row->qp_price != 0.0 && $row->qp_price != 0 ) $pu=round($row->qp_price/$row->qp_quantite,2); + if ( $row->qp_price != 0.0 && $row->qp_price != 0 ) + $pu=round(($row->qp_nd_amount+$row->qp_price)/$row->qp_quantite,2); $r.=' '.$fiche->strAttribut(ATTR_DEF_NAME).''; $r.=''.$pu.''; $r.=''.$row->qp_quantite.''; + $r.=''.$row->qp_dep_priv.''; $r.=''.$row->qp_vat.''; - $r.=''.$row->qp_vat_code.''; - $r.=''.$row->qp_nd_amount.''; $r.=''.$row->tva_label.''; + $r.=''.$row->qp_nd_amount.''; + $r.=''.$row->qp_nd_tva.''; $r.=''.$row->qp_nd_tva_recup.''; - $r.=''.$row->qp_price.''; + $r.=''.sprintf("% 12.2f",$row->qp_price).''; + $r.=''.sprintf("% 12.2f",$row->qp_vat+$row->qp_nd_amount+$row->qp_nd_tva+$row->qp_nd_tva_recup+$row->qp_price).''; //-- add ca // @@ -347,26 +359,36 @@ function ShowOperationUser($p_cn,$p_jr_id,$p_mode=1) 'Total HTVA'. ''.sprintf('% 12.2f',$tot_amount)."". ""; + if ( $tot_tva != 0 ) $r.=''. 'Total TVA'. ''.sprintf('%12.2f',$tot_tva) ."". ""; + if ( $tot_nd !=0 ) $r.=''. 'Total nd '. ''.sprintf('%12.2f',$tot_nd)."". ""; + if ( $tot_tva_nd !=0 ) $r.=''. 'Total tva nd'. ''.sprintf('%12.2f',$tot_tva_nd)."". ""; + if ( $tot_tva_nd_recup !=0 ) $r.=''. 'Total tva nd recup. par impot'. ''.sprintf('%12.2f',$tot_tva_nd_recup)."". ""; + if ( $tot_dep_priv !=0 ) + $r.=''. + 'Total tva nd recup. par impot'. + ''.sprintf('%12.2f',$tot_dep_priv)."". + ""; + $r.=''. 'Total '. - ''.sprintf('%12.2f',$tot_amount+$tot_tva)."". + ''.sprintf('%12.2f',$tot_dep_priv+$tot_amount+$tot_tva+$tot_tva_nd_recup+$tot_nd+$tot_tva_nd)."". ""; $r.= ''; @@ -464,11 +486,31 @@ function ShowOperationUser($p_cn,$p_jr_id,$p_mode=1) //doc if ( $p_mode ==1 && $content['jr_pj_name'] != "") $r.='Effacer Pj '; - $r.="".sprintf('%s', + $r.="".sprintf('%s', $content['jr_id'], $content['jr_grpt_id'], + $_REQUEST['PHPSESSID'], $content['jr_pj_name']).""; $r.=""; + if ( $content['jrn_def_type'] == 'VEN' ) { + /* count the number of additionnal info */ + $acc_jrn_info=new Acc_Jrn_Info($p_cn); + $acc_jrn_info->set_jrn_id($p_jr_id); + + /* if additional info > 0 show them */ + if ( $acc_jrn_info->count() > 0 ) { + $array=$acc_jrn_info->load_all(); + foreach ($array as $row) { + if ( strpos($row->id_type,'BON_COMMANDE') ===0) { + $r.="Num bon de commande : ".$row->ji_value.'
'; + } + if ( strpos($row->id_type,'OTHER') ===0) { + $r.="Autre info : ".$row->ji_value.'
'; + } + + } + } + } $r.="
"; if ( $p_mode == 1 ) { $r.= ""; diff --git a/include/poste.inc.php b/include/poste.inc.php index eed35d007..02e756c7b 100644 --- a/include/poste.inc.php +++ b/include/poste.inc.php @@ -37,7 +37,7 @@ if ( isset( $_POST['confirm_mod'] ) ) $object=new parm_code($cn); $all=$object->LoadAll(); -echo '
'; +echo '
'; echo '
'; for ($i=0;$i'; @@ -58,7 +58,7 @@ echo ""; // modifie if ( isset ($_POST['mod'] )) { - echo '
'; + echo '
'; echo "Voulez-vous vraiment modifier ?"; echo ''; @@ -75,4 +75,4 @@ if ( isset ($_POST['mod'] )) echo ""; echo "
"; -} \ No newline at end of file +} diff --git a/include/postgres.php b/include/postgres.php index 1f7954d87..688cc9a39 100644 --- a/include/postgres.php +++ b/include/postgres.php @@ -98,7 +98,7 @@ function DbConnect($p_db=-1,$p_type='dossier') { $phpcompta_user=phpcompta_user; $password=phpcompta_password; $port=phpcompta_psql_port; - ob_start(); + ob_start(); $a=pg_connect("dbname=$l_dossier host=127.0.0.1 user='$phpcompta_user' password='$password' port=$port"); diff --git a/include/pref.inc.php b/include/pref.inc.php index 0c5919637..2e0156c70 100644 --- a/include/pref.inc.php +++ b/include/pref.inc.php @@ -21,6 +21,8 @@ /*!\brief this file is always included and then executed * it permits to change the user preferences */ +require_once('class_widget.php'); +require_once('class_user.php'); echo '
'; @@ -92,14 +94,30 @@ $disp_style.=""; update_global_pref('TOPMENU',$_POST['topmenu']); +} +$topmenu=new widget('select'); +$topmenu->name='topmenu'; +$topmenu->selected=$_SESSION['g_topmenu']; +$array=array( + array('value'=>'TEXT','label'=>'Texte'), + array('value'=>'SELECT','label'=>'Menu deroulant') + ); +$topmenu->value=$array; +echo '

Style de menu

'; +echo ''; +echo '
'; +echo $topmenu->IOValue(); +echo widget::submit('sub_topmenu','Sauver'); +echo ''; +echo '
'; // Si utilise un dossier alors propose de changer // la periode par defaut -if ( ! isset ($_REQUEST['gDossier']) ) - { - echo ''; - } -else +if ( isset ($_REQUEST['gDossier']) ) { include_once("preference.php"); @@ -132,7 +150,10 @@ else
+

Taille des pages

@@ -156,9 +177,13 @@ else
+'; + } + -"; ?> diff --git a/include/stock_inc.php b/include/stock_inc.php index 4421c619c..7c7d0ebeb 100644 --- a/include/stock_inc.php +++ b/include/stock_inc.php @@ -21,7 +21,7 @@ /*! \file * \brief Function for managing the stock */ - +require_once('class_fiche.php'); /*! ************************************************** @@ -123,7 +123,7 @@ $sql="select distinct f_id,av_text join jnt_fic_att_value using (f_id ) join attr_value using (jft_id) where - ad_id=".ATTR_DEF_NAME." + ad_id=".ATTR_DEF_STOCK." and sg_code='$p_sg_code' "; // Execute @@ -134,7 +134,8 @@ $sql="select distinct f_id,av_text for ( $i=0; $i<$M;$i++) { $r=pg_fetch_array($Res,$i); $a['f_id']=$r['f_id']; - $a['av_text']=$r['av_text']; + $fiche=new Fiche($p_cn,$r['f_id']); + $a['av_text']=$fiche->getName(); $result[$i]=$a; } diff --git a/include/supplier.inc.php b/include/supplier.inc.php index 991454f90..5a362af81 100644 --- a/include/supplier.inc.php +++ b/include/supplier.inc.php @@ -46,8 +46,7 @@ if ( isset ($_POST['delete']) ) // Add card if ( $sub_action=="insert" ) { - $retour=sprintf('', - urldecode($_REQUEST['url'])); + $retour=widget::button_href("Retour", urldecode($_REQUEST['url'])); $supplier=new Supplier($cn); $supplier->Save($_REQUEST['fd_id']); @@ -75,8 +74,7 @@ if ( $sub_action == "" ) //Display a blank card if ( $sub_action=="blank") { - $retour=sprintf('', - "commercial.php?p_action=fournisseur&".dossier::get()); + $retour=widget::button_href('Retour','commercial.php?p_action=fournisseur&'.dossier::get()); echo '
'; echo $retour; @@ -85,10 +83,11 @@ if ( $sub_action=="blank") echo ''; echo ''; echo ''; - echo ''; echo dossier::hidden(); echo $c->blank($_GET['fd_id']); echo ''; + echo ''; + echo ''; echo $retour; echo '
'; @@ -114,7 +113,6 @@ if ( $sub_action == "list" )
- +
@@ -148,8 +147,8 @@ if ( $sub_action == 'detail' ) $f_id=$_REQUEST['f_id']; echo '
'; $sup=new Supplier($cn,$f_id); - $retour=sprintf('', - urldecode($_REQUEST['url'])); + $retour=widget::button_href("Retour", urldecode($_REQUEST['url'])); + echo $retour; echo '
'; echo $sup->Display(false); diff --git a/include/tva.inc.php b/include/tva.inc.php index dc44a8e26..e864c8a11 100644 --- a/include/tva.inc.php +++ b/include/tva.inc.php @@ -255,6 +255,7 @@ if ( ! isset ($_POST['add'])
'; } +} + echo '
'; ?> diff --git a/include/user_action_ach.php b/include/user_action_ach.php index e8d60ef92..bbf136722 100644 --- a/include/user_action_ach.php +++ b/include/user_action_ach.php @@ -69,7 +69,7 @@ if ( $action=="use_opd" ) { echo $hid->IOValue("jrn_type","ACH"); if ($op->count() != 0 ) - echo widget::submit('use_opd','Utilisez une op.prédéfinie'); + echo widget::submit('use_opd','Utilisez une op.prédéfinie'); echo $op->show_button(); echo ''; @@ -118,7 +118,7 @@ if ( $action == 'new' ) { echo $hid->IOValue("jrn_type","ACH"); if ($op->count() != 0 ) - echo widget::submit('use_opd','Utilisez une op.prédéfinie'); + echo widget::submit('use_opd','Utilisez une op.prédéfinie'); echo $op->show_button(); echo ''; @@ -202,7 +202,7 @@ if ( $action == 'new' ) { list($internal,$comment)=RecordSell($cn,$_POST,$User,$_GET['p_jrn']); // submit button in the form - $submit='

Opération '.$internal.'

'; + $submit='

Opération '.$internal.'

'; $r=FormAchView($cn,$_GET['p_jrn'],$User->get_periode(),$_POST,"",$nb_number,false); echo '
'; echo $submit; diff --git a/include/user_action_fin.php b/include/user_action_fin.php index 16e14771b..640ceb51f 100644 --- a/include/user_action_fin.php +++ b/include/user_action_fin.php @@ -273,8 +273,8 @@ if ( $action == 'solde' ) { $vir_interne=new parm_code($cn,'VIREMENT_INTERNE'); $accountSql="select distinct pcm_val::text,pcm_lib from tmp_pcmn - where pcm_val like '".$banque->p_value."%' or pcm_val like '".$vir_interne->p_value."%' - or pcm_val like '".$caisse->p_value."%' + where pcm_val::text like '".$banque->p_value."%' or pcm_val::text like '".$vir_interne->p_value."%' + or pcm_val::text like '".$caisse->p_value."%' order by pcm_val::text"; $ResAccount=ExecSql($cn,$accountSql); echo '
'; diff --git a/include/user_common.php b/include/user_common.php index f82db5902..bbae4ad21 100644 --- a/include/user_common.php +++ b/include/user_common.php @@ -129,6 +129,30 @@ echo_debug('user_common.php',__LINE__,"ComputeTotalVat $a_fiche $a_quant $a_pric //variable containing the nd part // used when a card has both special rule for vat $nd1=0; + + $base=$a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx]; + $nd_amount3=0; + // if a part is not deductible then reduce vat_amount + $nd3=GetFicheAttribut($p_cn,$a_fiche[$idx],ATTR_DEF_DEP_PRIV); + if ( $nd3 != null && strlen(trim($nd3)) != 0 && $nd3 != 0 ) + { + // if tva amount is given we do not compute it + if ( $a_vat_amount != null && + $a_vat_amount[$idx] != 0 ) { + $nd_amount3=round($a_vat_amount[$idx]*$nd3,2); + $a_vat_amount[$idx]-=$nd_amount3; + } + else + $nd_amount3=round($a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx]*$nd3,2); + + $vat_amount=$vat_amount-$nd_amount3; + + $base=$base*$nd3; + // when using both vat, their sum cannot exceed 1, if = 1 then vat = 0 + $flag=false; + } + + // if a part is not deductible then reduce vat_amount $nd=GetFicheAttribut($p_cn,$a_fiche[$idx],ATTR_DEF_TVA_NON_DEDUCTIBLE); if ( $nd != null && strlen(trim($nd)) != 0 && $nd != 0 ) @@ -136,9 +160,9 @@ echo_debug('user_common.php',__LINE__,"ComputeTotalVat $a_fiche $a_quant $a_pric // if tva amount is given we do not compute it if ( $a_vat_amount != null && $a_vat_amount[$idx] != 0 ) - $nd_amount=round($vat_amount*$nd,2); + $nd_amount=round($a_vat_amount[$idx]*$nd,2); else - $nd_amount=round($a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx]*$nd,2); + $nd_amount=round($base*$nd,2); // problem with round @@ -159,7 +183,7 @@ echo_debug('user_common.php',__LINE__,"ComputeTotalVat $a_fiche $a_quant $a_pric $a_vat_amount[$idx] != 0 ) $nd_amount2=round($a_vat_amount[$idx]*$nd,2); else - $nd_amount2=round($a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx]*$nd,2); + $nd_amount2=round($base*$nd,2); $vat_amount=$vat_amount-$nd_amount2; // when using both vat, their sum cannot exceed 1, if = 1 then vat = 0 @@ -438,7 +462,7 @@ $sort_echeance=" $image_ascEch $sql_fin="("; $or=""; foreach ($a_parm_code as $code) { - $sql_fin.="$or j_poste like '".$code['p_value']."%'"; + $sql_fin.="$or j_poste::text like '".$code['p_value']."%'"; $or=" or "; } $sql_fin.=")"; @@ -545,7 +569,7 @@ $sort_echeance=" $image_ascEch $l_poste=FormatString($l_poste); if ( $l_poste != null ) { $sql.=$l_and." jr_grpt_id in (select j_grpt - from jrnx where j_poste like '$l_poste' ) "; + from jrnx where j_poste::text like '$l_poste' ) "; $l_and=" and "; } // Quick Code @@ -729,10 +753,11 @@ $sort_echeance=" $image_ascEch if ( $row['jr_pj_name'] != "") { $image=''; - $r.="".sprintf('%s', + $r.="".sprintf('%s', $p_jrn, $row['jr_grpt_id'], - $str_dossier, + $str_dossier, + $_REQUEST['PHPSESSID'], $image) .""; } diff --git a/include/user_form_ach.php b/include/user_form_ach.php index 0b11a47be..4c5533627 100644 --- a/include/user_form_ach.php +++ b/include/user_form_ach.php @@ -492,7 +492,7 @@ function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number) $per->set_jrn($p_jrn); $per->set_periode($p_periode); - // Periode fermé + // Periode ferme if ( $per->is_open() == 0) { $msg="Cette periode est fermee pour ce journal"; @@ -833,6 +833,8 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) $aNd_amount[$i]=0.0; $aTva_ded_impot[$i]=0.0; $aTva_ded_impot_recup[$i]=0.0; + $aDep_priv[$i]=0.0; + $poste=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_ACCOUNT); @@ -840,26 +842,51 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) 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]; - + //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]; + //---------------------------------------------------------------------- // 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; - } + { + // this doens't concern the vat + $nd_amount=round($a_quant[$i]*$a_price[$i]*$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_DEP_PRIV); + echo_debug('user_form_ach.php',__LINE__,"value non ded : $non_dedu"); + if ( $non_dedu != null && strlen(trim($non_dedu)) != 0) + { + // Remove also the vat + $nd_amount=round($a_quant[$i]*$a_price[$i]*$non_dedu,2); + $tva_nd=round($lvat*$non_dedu,2); + $nd_amount+=$tva_nd; + + // save it + $dna=new parm_code($p_cn,'DEP_PRIV'); + $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$dna->p_value,$e_date,round($nd_amount,2),$seq,$periode); + + // modify sum + $amount=$amount-$nd_amount+$tva_nd; + $lvat-=$tva_nd; + + $sum_tva_nd+=$tva_nd; + + // save the ND in an array (for the easy view) + $aDep_priv[$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"); @@ -877,27 +904,27 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$tva_dna->p_value,$e_date,round($ded_vat,2),$seq,$periode); } - + //---------------------------------------------------------------------- // 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 ) - { - - $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); - } + { + $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); + } + //---------------------------------------------------------------------- @@ -905,7 +932,7 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) 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 + /*! \brief if the quantity is < 0 then the stock increase (return of * material) */ $nNeg=($a_quant[$i]<0)?-1:1; @@ -924,53 +951,56 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) $op->oa_description=$comm; $op->save_form_plan($_POST,$i); } - //--------------------------------------------------------- - // 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]; - $qp_vat=($vat_code==-1)?0:$computed_vat; - - 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). - ",".$qp_vat. - ",".$vat_code. - ",".$aNd_amount[$i]. - ",".$aTva_ded_impot[$i]. - ",".$aTva_ded_impot_recup[$i]. - ",'".$e_client."')"); - - + //--------------------------------------------------------- + // 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]; + $computed_vat=$lvat-$aTva_ded_impot[$i]-$aTva_ded_impot_recup[$i]; + $qp_vat=($vat_code==-1)?0:$computed_vat; + + 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). + ",".$qp_vat. + ",".$vat_code. + ",".$aNd_amount[$i]. + ",".$aTva_ded_impot[$i]. + ",".$aTva_ded_impot_recup[$i]. + ",".$aDep_priv[$i]. + ",'".$e_client."')"); + + } // end loop - - // set up internal code for quant_purchase - + + // 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',__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"); + if ($e_tva_amount == 0 ) continue; + + $poste=GetTvaPoste($p_cn,$tva_id,'d'); + + $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"); @@ -984,14 +1014,14 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) $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 ". + $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); // Update and set the invoice's comment @@ -999,14 +1029,14 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) if ( isset ($_FILES)) save_upload_document($p_cn,$seq); - // Save the operation - if ( isset($_POST['opd_save']) && $_POST['opd_save']=='on' ){ - echo_debug(__FILE__.':'.__LINE__.'- ','save opd'); - $opd=new Pre_op_ach($p_cn); - $opd->get_post(); - $opd->save(); + // Save the operation + if ( isset($_POST['opd_save']) && $_POST['opd_save']=='on' ){ + echo_debug(__FILE__.':'.__LINE__.'- ','save opd'); + $opd=new Pre_op_ach($p_cn); + $opd->get_post(); + $opd->save(); echo_debug(__FILE__.':'.__LINE__.'- ',"opd = ",$opd); - } + } } catch (Exception $e) { echo ''. 'Erreur dans l\'enregistrement '. diff --git a/include/user_form_ven.php b/include/user_form_ven.php index d7bc0297c..ed9cc17d4 100644 --- a/include/user_form_ven.php +++ b/include/user_form_ven.php @@ -235,7 +235,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.=""; } @@ -336,8 +336,8 @@ function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number) // compare hidden value and computed if ( round($ca_amount-$hidden_amount,2) != 0 ) { - $msg="Montant CA est différent total marchandise"; - $msg.="montant encodé $ca_amount marchandise $hidden_amount"; + $msg="Montant CA est different total marchandise"; + $msg.="montant encode $ca_amount marchandise $hidden_amount"; echo ""; return null; @@ -644,15 +644,19 @@ function FormVenteView ($p_cn,$p_jrn,$p_periode,$p_array,$p_number,$p_doc='form' if ( CountSql($p_cn, "select md_id,md_name from document_modele where md_type=4") > 0 ) { - $r.='Générer une facture '; - // We propose to generate the invoice and some template - $doc_gen=new widget("select"); - $doc_gen->name="gen_doc"; - $doc_gen->value=make_array($p_cn, - "select md_id,md_name from document_modele where md_type=4"); - $r.=$doc_gen->IOValue(); - - $r.="
"; + $r.='
Génération de facture'; + $obj=new widget('TEXT'); + $r.='Numero de bon de commande : '.$obj->IOValue('bon_comm').'
'; + $r.='Autre information : '.$obj->IOValue('other_info').'
'; + + $r.='Générer une facture '; + // We propose to generate the invoice and some template + $doc_gen=new widget("select"); + $doc_gen->name="gen_doc"; + $doc_gen->value=make_array($p_cn, + "select md_id,md_name from document_modele where md_type=4"); + $r.=$doc_gen->IOValue().'
'; + $r.="
"; } } @@ -756,7 +760,7 @@ function RecordInvoice($p_cn,$p_array,$p_user,$p_jrn) // Compute the j_grpt $seq=NextSequence($p_cn,'s_grpt'); -$oJrn=new Acc_Ledger($p_cn,$p_jrn); + $oJrn=new Acc_Ledger($p_cn,$p_jrn); $internal=$oJrn->compute_internal_code($seq); echo_debug(__FILE__,__LINE__,"Dossier is ".dossier::id()); diff --git a/include/user_menu.php b/include/user_menu.php index 9f9ba1859..53c8854ea 100644 --- a/include/user_menu.php +++ b/include/user_menu.php @@ -192,26 +192,7 @@ function ShowMenuCompta($p_high="") $result=ShowItem($p_array,'H',"mtitle","mtitle",$default,' width="100%"'); $str_dossier=dossier::get(); $r=""; - /* - $r.='
'; - $r.="

Comptabilité ".dossier::name()."

"; - $r.='
'; - $r.='
'; - $r.=' - - - - - - - - - - -
'; - */ - // $r.='
'; - $r.=menu_tool(""); + $r.=menu_tool("compta"); $r.='
'; $r.=$result; $r.='
'; @@ -822,15 +803,32 @@ function ShowMenuImport(){ echo ""; } - +/*!\brief show the top menu to access the different modules in top + * \param $p_from from which module this function is called + * \return string +*/ function menu_tool($p_from) { + + if ( ! isset ($_REQUEST['gDossier'])) + return "" ; $r=""; +$r.=''; + + $r.= '
'; $r.= '
'; $r.= "

Commercial ".dossier::name()."

"; $r.= '
'; $r.= '
'; - + if ( $from == 'compta') $view='E'; + else $view='S'; + $agent=$_SERVER['HTTP_USER_AGENT']; $amodule=array( array('value'=>'pref','label'=>'Preference'), @@ -842,20 +840,47 @@ function menu_tool($p_from) { array('value'=>'home','label'=>'Accueil'), array('value'=>'logout','label'=>'Sortir') ); + if ( $_SESSION['g_topmenu'] == 'SELECT' ) { + $gDossier=dossier::id(); + $r.= '
'; + $w=new widget('select'); + $w->name='m'; + $w->value=$amodule; + $r.= ''; + $r.= ''; + $r.= dossier::hidden(); + $r.= ''; + $r.= '
'; - $gDossier=dossier::id(); - $r.= ''; - $w=new widget('select'); - $w->name='m'; - $w->value=$amodule; - $r.= ''; - $r.= ''; - $r.= dossier::hidden(); - $r.= ''; - $r.= '
'; - $r.= ''. - 'Recheche'.$w->IOValue().''.widget::submit('','Acces Direct').'
'; - $r.= ''; - $r.= ''; + $search="openRecherche('".$_REQUEST['PHPSESSID']."','".$gDossier."','".$view."');"; + $r.=''; + $r.='
'.$w->IOValue().''.widget::submit('','Acces Direct').'
'; + $r.= ''; + $r.= '
'; + } + if ( $_SESSION['g_topmenu'] == 'TEXT' ) { + $gDossier=dossier::id(); + $r.= ''; + foreach($amodule as $col ) { + $url="control.php?".dossier::get()."&m=".$col['value']; + if ( $p_from==$col['value']) { + $r.= ''; + + } else { + $r.= ''; + } + + } + $r.=''; + $r.= '
'; + $r.= ''. + 'Recheche'. + ''.$col['label'].''. + ''. + ''.$col['label'].''. + '
'; + $r.= '
'; + } + $r.= '
'; return $r; } diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh index 7dde70fb9..e31397a22 100755 --- a/scripts/cleanup.sh +++ b/scripts/cleanup.sh @@ -1,6 +1,6 @@ #!/bin/bash # clean all phpcompta related DB. -DOMAIN="f31" +DOMAIN="beta_" export PGPASSWORD="dany" export PGUSER="phpcompta" export PGHOST=localhost diff --git a/sql/upgrade.sql b/sql/upgrade.sql index e2e6d36c9..a33282acc 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -1,720 +1,48 @@ begin; -alter table import_tmp add n_montant numeric(20,4); -update import_tmp set n_montant=to_number(montant,'999999999.99'); -alter table import_tmp drop montant; -alter table import_tmp rename n_montant to montant; --- alter table import_tmp alter montant type numeric(20,4); -alter table import_tmp alter montant set default 0; -alter table import_tmp alter montant set not null; -alter table import_tmp alter code set not null; -alter table import_tmp alter date_exec set not null; -alter table import_tmp alter date_valeur set not null; -COMMENT ON TABLE import_tmp IS 'Table temporaire pour l''importation des banques en format CSV'; -COMMENT ON COLUMN import_tmp.status IS 'Status w waiting, d delete t transfert'; +-- insert into parm_code values ('DEP_PRIV',4890,'Depense à charge du gérant'); +-- insert into attr_def values (31,'Depense à charge du gérant (partie privée)'); +-- alter table quant_purchase add qp_dep_priv numeric(20,4) default 0.0; - -alter table poste_analytique add ga_id varchar (10); - - -CREATE or replace FUNCTION t_document_validate() RETURNS "trigger" +CREATE 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_dep_priv numeric , p_client character varying) RETURNS void AS $$ declare - lText text; - modified document%ROWTYPE; + fid_client integer; + fid_good integer; begin - modified:=NEW; - modified.d_filename:=replace(NEW.d_filename,' ','_'); - return modified; + 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, + qp_dep_priv) + 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, + p_dep_priv); + return; end; -$$ + $$ LANGUAGE plpgsql; - -CREATE or replace FUNCTION t_document_type_insert() RETURNS "trigger" - AS $$ -declare -nCounter integer; - BEGIN -select count(*) into nCounter from pg_class where relname='seq_doc_type_'||NEW.dt_id; -if nCounter = 0 then - execute 'create sequence seq_doc_type_'||NEW.dt_id; -end if; - RETURN NEW; - END; -$$ - LANGUAGE plpgsql; - -CREATE or replace FUNCTION t_document_modele_validate() RETURNS "trigger" - AS $$ -declare - lText text; - modified document_modele%ROWTYPE; -begin - modified:=NEW; - - modified.md_filename:=replace(NEW.md_filename,' ','_'); - return modified; -end; -$$ - LANGUAGE plpgsql; - - -CREATE TABLE groupe_analytique -( - ga_id varchar(10) NOT NULL, - pa_id int, - ga_description text, - CONSTRAINT pk_ga_id PRIMARY KEY (ga_id) -) ; - - -CREATE OR REPLACE FUNCTION group_analytic_ins_upd() - RETURNS "trigger" AS -$BODY$ -declare -name text; -begin -name:=upper(NEW.ga_id); -name:=trim(name); -name:=replace(name,' ',''); -NEW.ga_id:=name; -return NEW; -end;$BODY$ - LANGUAGE 'plpgsql' VOLATILE; - -CREATE OR REPLACE FUNCTION group_analytique_del() - RETURNS "trigger" AS -$BODY$ -begin -update poste_analytique set ga_id=null -where ga_id=OLD.ga_id; -return OLD; -end;$BODY$ - LANGUAGE 'plpgsql' VOLATILE; - -CREATE OR REPLACE FUNCTION poste_analytique_ins_upd() - RETURNS "trigger" AS -$BODY$declare -name text; -rCount record; - -begin -name:=upper(NEW.po_name); -name:=trim(name); -name:=replace(name,' ',''); -NEW.po_name:=name; - -if NEW.ga_id is NULL then -return NEW; -end if; - -if length(trim(NEW.ga_id)) = 0 then - NEW.ga_id:=NULL; - return NEW; -end if; -perform 'select ga_id from groupe_analytique where ga_id='||NEW.ga_id; -if NOT FOUND then - raise exception' Inexistent Group Analytic %',NEW.ga_id; -end if; -return NEW; -end;$BODY$ - LANGUAGE 'plpgsql' VOLATILE; - -CREATE OR REPLACE FUNCTION plan_analytic_ins_upd() - RETURNS "trigger" AS -$BODY$ -declare - name text; -begin - name:=upper(NEW.pa_name); - name:=trim(name); - name:=replace(name,' ',''); - NEW.pa_name:=name; -return NEW; -end; -$BODY$ - LANGUAGE 'plpgsql' VOLATILE; - -CREATE TRIGGER t_poste_analytique_ins_upd - BEFORE INSERT OR UPDATE - ON poste_analytique - FOR EACH ROW - EXECUTE PROCEDURE poste_analytique_ins_upd(); - -CREATE TRIGGER t_plan_analytique_ins_upd - BEFORE INSERT OR UPDATE - ON plan_analytique - FOR EACH ROW - EXECUTE PROCEDURE plan_analytic_ins_upd(); - -CREATE TRIGGER t_group_analytic_del - before DELETE - ON groupe_analytique - FOR EACH ROW - EXECUTE PROCEDURE group_analytique_del(); - -CREATE TRIGGER t_group_analytic_ins_upd - BEFORE INSERT OR UPDATE - ON groupe_analytique - FOR EACH ROW - EXECUTE PROCEDURE group_analytic_ins_upd(); - - -drop TRIGGER t_upper_pa_name on plan_analytique; -drop TRIGGER t_upper_po_name on poste_analytique; -drop function upper_pa_name(); -drop function upper_po_name(); - -CREATE TABLE bud_hypothese -( - bh_id int4 NOT NULL, - bh_name text NOT NULL, - bh_saldo numeric(20,4) DEFAULT 0, - bh_description text, - pa_id int4, - CONSTRAINT pk_bud_hypo PRIMARY KEY (bh_id), - CONSTRAINT fk_bud_hypo_pa_id FOREIGN KEY (pa_id) - REFERENCES plan_analytique (pa_id) MATCH SIMPLE - ON UPDATE CASCADE ON DELETE CASCADE -) -WITHOUT OIDS; - -create sequence seq_bud_hypothese_bh_id; - -alter table bud_hypothese alter bh_id set default nextval('seq_bud_hypothese_bh_id'); - --- --- Name: bud_card; Type: TABLE; Schema: public; Owner: phpcompta; Tablespace: --- - -CREATE TABLE bud_card ( - bc_id integer NOT NULL, - bc_code character varying(10) NOT NULL, - bc_description text, - bc_price_unit numeric(20,4) DEFAULT 0.0 NOT NULL, - bc_unit character varying(20), - bh_id integer -); --- --- Name: TABLE bud_card; Type: COMMENT; Schema: public; Owner: phpcompta --- - -COMMENT ON TABLE bud_card IS 'card for budget module'; - - --- --- Name: COLUMN bud_card.bh_id; Type: COMMENT; Schema: public; Owner: phpcompta --- - -COMMENT ON COLUMN bud_card.bh_id IS 'fk to bud_hypothese'; - - --- --- Name: bud_card_bc_id_seq; Type: SEQUENCE; Schema: public; Owner: phpcompta --- - -CREATE SEQUENCE bud_card_bc_id_seq - INCREMENT BY 1 - NO MAXVALUE - NO MINVALUE - CACHE 1; - - -ALTER TABLE public.bud_card_bc_id_seq OWNER TO phpcompta; - --- --- Name: bud_card_bc_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: phpcompta --- - -ALTER SEQUENCE bud_card_bc_id_seq OWNED BY bud_card.bc_id; - - --- --- Name: bc_id; Type: DEFAULT; Schema: public; Owner: phpcompta --- - -ALTER TABLE bud_card ALTER COLUMN bc_id SET DEFAULT nextval('bud_card_bc_id_seq'::regclass); - - --- --- Name: pk_bud_card_bc_id; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace: --- - -ALTER TABLE ONLY bud_card - ADD CONSTRAINT pk_bud_card_bc_id PRIMARY KEY (bc_id); - - --- --- Name: uq_bud_card_bc_code; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace: --- - -ALTER TABLE ONLY bud_card - ADD CONSTRAINT uq_bud_card_bc_code_bh_id UNIQUE (bc_code,bh_id); - -ALTER TABLE bud_card ADD CONSTRAINT fk_bud_hypo_bh_id FOREIGN KEY (bh_id) REFERENCES bud_hypothese (bh_id) - ON UPDATE CASCADE ON DELETE CASCADE; -CREATE INDEX fki_bud_hypo_bh_id ON bud_card(bh_id); -ALTER TABLE bud_card ALTER COLUMN bh_id SET NOT NULL; - - - --- --- Name: bud_detail; Type: TABLE; Schema: public; Owner: phpcompta; Tablespace: --- - -CREATE TABLE bud_detail ( - bd_id integer NOT NULL, - po_id integer, - bc_id integer, - bh_id integer, - pcm_val poste_comptable -); - - -ALTER TABLE public.bud_detail OWNER TO phpcompta; - --- --- Name: TABLE bud_detail; Type: COMMENT; Schema: public; Owner: phpcompta --- - -COMMENT ON TABLE bud_detail IS 'Detail for card '; - - --- --- Name: COLUMN bud_detail.bd_id; Type: COMMENT; Schema: public; Owner: phpcompta --- - -COMMENT ON COLUMN bud_detail.bd_id IS 'primary key'; - - --- --- Name: COLUMN bud_detail.po_id; Type: COMMENT; Schema: public; Owner: phpcompta --- - -COMMENT ON COLUMN bud_detail.po_id IS 'FK to poste_analytique'; - - --- --- Name: COLUMN bud_detail.bc_id; Type: COMMENT; Schema: public; Owner: phpcompta --- - -COMMENT ON COLUMN bud_detail.bc_id IS 'fk to bud_card'; - - --- --- Name: COLUMN bud_detail.pcm_val; Type: COMMENT; Schema: public; Owner: phpcompta --- - -COMMENT ON COLUMN bud_detail.pcm_val IS 'fk to tmp_pcmn'; - - --- --- Name: bud_detail_bd_id_seq; Type: SEQUENCE; Schema: public; Owner: phpcompta --- - -CREATE SEQUENCE bud_detail_bd_id_seq - INCREMENT BY 1 - NO MAXVALUE - NO MINVALUE - CACHE 1; - - -ALTER TABLE public.bud_detail_bd_id_seq OWNER TO phpcompta; - --- --- Name: bud_detail_bd_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: phpcompta --- - -ALTER SEQUENCE bud_detail_bd_id_seq OWNED BY bud_detail.bd_id; - - --- --- Name: bd_id; Type: DEFAULT; Schema: public; Owner: phpcompta --- - -ALTER TABLE bud_detail ALTER COLUMN bd_id SET DEFAULT nextval('bud_detail_bd_id_seq'::regclass); - - --- --- Name: pk_bud_detail; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace: --- - -ALTER TABLE ONLY bud_detail - ADD CONSTRAINT pk_bud_detail PRIMARY KEY (bd_id); - - --- --- Name: fki_bud_card; Type: INDEX; Schema: public; Owner: phpcompta; Tablespace: --- - -CREATE INDEX fki_bud_card ON bud_detail USING btree (bc_id); - - --- --- Name: fki_tmp_pcmn; Type: INDEX; Schema: public; Owner: phpcompta; Tablespace: --- - -CREATE INDEX fki_tmp_pcmn ON bud_detail USING btree (pcm_val); - - --- --- Name: fk_bud_card; Type: FK CONSTRAINT; Schema: public; Owner: phpcompta --- - -ALTER TABLE ONLY bud_detail - ADD CONSTRAINT fk_bud_card FOREIGN KEY (bc_id) REFERENCES bud_card(bc_id) ON UPDATE CASCADE ON DELETE CASCADE;; - -ALTER TABLE ONLY bud_detail - add constraint fk_bud_hypothese_not_null FOREIGN KEY (bh_id) REFERENCES bud_hypothese(bh_id) ON UPDATE CASCADE ON DELETE CASCADE;; - - --- --- Name: fk_tmp_pcmn; Type: FK CONSTRAINT; Schema: public; Owner: phpcompta --- - -ALTER TABLE ONLY bud_detail - ADD CONSTRAINT fk_tmp_pcmn FOREIGN KEY (pcm_val) REFERENCES tmp_pcmn(pcm_val) ON UPDATE CASCADE ON DELETE CASCADE; --- --- Name: bud_detail_periode; Type: TABLE; Schema: public; Owner: phpcompta; Tablespace: --- - -CREATE TABLE bud_detail_periode ( - bdp_id integer NOT NULL, - bdp_amount numeric(20,4) DEFAULT 0.0, - p_id integer NOT NULL, - bd_id integer -); - - -ALTER TABLE public.bud_detail_periode OWNER TO phpcompta; - --- --- Name: TABLE bud_detail_periode; Type: COMMENT; Schema: public; Owner: phpcompta --- - -COMMENT ON TABLE bud_detail_periode IS 'Module budget detail by periode'; - - --- --- Name: COLUMN bud_detail_periode.p_id; Type: COMMENT; Schema: public; Owner: phpcompta --- - -COMMENT ON COLUMN bud_detail_periode.p_id IS 'fk to parm_periode'; - - --- --- Name: COLUMN bud_detail_periode.bd_id; Type: COMMENT; Schema: public; Owner: phpcompta --- - -COMMENT ON COLUMN bud_detail_periode.bd_id IS 'fk to bud_detail'; - - --- --- Name: bud_detail_periode_bdp_id_seq; Type: SEQUENCE; Schema: public; Owner: phpcompta --- - -CREATE SEQUENCE bud_detail_periode_bdp_id_seq - START WITH 1 - INCREMENT BY 1 - NO MAXVALUE - NO MINVALUE - CACHE 1; - - -ALTER TABLE public.bud_detail_periode_bdp_id_seq OWNER TO phpcompta; - --- --- Name: bud_detail_periode_bdp_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: phpcompta --- - -ALTER SEQUENCE bud_detail_periode_bdp_id_seq OWNED BY bud_detail_periode.bdp_id; - - --- --- Name: bdp_id; Type: DEFAULT; Schema: public; Owner: phpcompta --- - -ALTER TABLE bud_detail_periode ALTER COLUMN bdp_id SET DEFAULT nextval('bud_detail_periode_bdp_id_seq'::regclass); - - --- --- Name: pk_budget_detail_period; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace: --- - -ALTER TABLE ONLY bud_detail_periode - ADD CONSTRAINT pk_budget_detail_period PRIMARY KEY (bdp_id); - - --- --- Name: fk_bud_detail_bd_id; Type: FK CONSTRAINT; Schema: public; Owner: phpcompta --- - -ALTER TABLE ONLY bud_detail_periode - ADD CONSTRAINT fk_bud_detail_bd_id FOREIGN KEY (bd_id) REFERENCES bud_detail(bd_id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- Name: fk_parm_periode; Type: FK CONSTRAINT; Schema: public; Owner: phpcompta --- - -ALTER TABLE ONLY bud_detail_periode - ADD CONSTRAINT fk_parm_periode FOREIGN KEY (p_id) REFERENCES parm_periode(p_id) ON UPDATE CASCADE ON DELETE CASCADE; - - - -CREATE OR REPLACE FUNCTION bud_detail_ins_upd() - RETURNS "trigger" AS -$BODY$declare -mline bud_detail%ROWTYPE; -begin -mline:=NEW; -if mline.po_id = -1 then - mline.po_id:=NULL; -end if; -return mline; -end;$BODY$ - LANGUAGE 'plpgsql' VOLATILE; - - -CREATE OR REPLACE FUNCTION bud_card_ins_upd() - RETURNS "trigger" AS -$BODY$declare - sCode text; -begin - -sCode:=trim(upper(NEW.bc_code)); -sCode:=replace(sCode,' ','_'); -sCode:=substr(sCode,1,10); -NEW.bc_code:=sCode; -return NEW; -end;$BODY$ - LANGUAGE 'plpgsql' VOLATILE; -ALTER FUNCTION bud_card_ins_upd() OWNER TO phpcompta; - --- --- Name: t_bud_card_ins_up; Type: TRIGGER; Schema: public; Owner: phpcompta --- - -CREATE TRIGGER t_bud_card_ins_up - BEFORE INSERT OR UPDATE ON bud_card - FOR EACH ROW - EXECUTE PROCEDURE bud_card_ins_upd(); - - --- --- Name: bud_hypothese_bh_id; Type: FK CONSTRAINT; Schema: public; Owner: phpcompta --- - -ALTER TABLE ONLY bud_card - ADD CONSTRAINT bud_hypothese_bh_id FOREIGN KEY (bh_id) REFERENCES bud_hypothese(bh_id) ON UPDATE CASCADE ON DELETE CASCADE; - - -CREATE TRIGGER t_bud_detail_ins_upd - BEFORE INSERT OR UPDATE - ON bud_detail - FOR EACH ROW - EXECUTE PROCEDURE bud_detail_ins_upd(); - - - -CREATE TABLE jrn_periode -( - jrn_def_id int4 NOT NULL, - p_id int4 NOT NULL, - status text, - CONSTRAINT jrn_periode_pk PRIMARY KEY (jrn_def_id, p_id), - CONSTRAINT jrn_per_jrn_def_id FOREIGN KEY (jrn_def_id) - REFERENCES jrn_def (jrn_def_id) MATCH SIMPLE - ON UPDATE CASCADE ON DELETE CASCADE, - CONSTRAINT jrn_periode_p_id FOREIGN KEY (p_id) - REFERENCES parm_periode (p_id) MATCH SIMPLE - ON UPDATE CASCADE ON DELETE CASCADE -); - -insert into jrn_periode(p_id,jrn_def_id,status) select p_id,jrn_def_id, - case when p_central='t' then 'CE' - when p_closed='t' then 'CL' - else 'OP' - end -from -parm_periode cross join jrn_def; - -CREATE OR REPLACE FUNCTION jrn_def_add() - RETURNS "trigger" AS -$BODY$begin -execute 'insert into jrn_periode(p_id,jrn_def_id,status) select p_id,'||NEW.jrn_def_id||', - case when p_central=true then ''CE'' - when p_closed=true then ''CL'' - else ''OP'' - end -from -parm_periode '; -return NEW; -end;$BODY$ - LANGUAGE 'plpgsql' VOLATILE; - -CREATE TRIGGER t_jrn_def_add_periode - AFTER INSERT - ON jrn_def - FOR EACH ROW - EXECUTE PROCEDURE jrn_def_add(); - -CREATE OR REPLACE FUNCTION jrn_check_periode() - RETURNS "trigger" AS -$BODY$ -declare -bClosed bool; -str_status text; -begin - -select p_closed into bClosed from parm_periode - where p_id=NEW.jr_tech_per; - -if bClosed = true then - raise exception 'Periode fermee'; -end if; - -select status into str_status from jrn_periode - where p_id =NEW.jr_tech_per and jrn_def_id=NEW.jr_def_id; - -if str_status <> 'OP' then - raise exception 'Periode fermee'; -end if; - -return NEW; -end;$BODY$ - LANGUAGE 'plpgsql' VOLATILE; - - -CREATE TRIGGER t_check_jrn - BEFORE INSERT OR DELETE - ON jrn - FOR EACH ROW - EXECUTE PROCEDURE jrn_check_periode(); - -drop TRIGGER tr_jrn_check_balance on jrn; - -CREATE OR REPLACE FUNCTION jrn_def_delete() - RETURNS "trigger" AS -$BODY$ -declare -nb numeric; -begin -select count(*) into nb from jrn where jr_def_id=OLD.jrn_def_id; - -if nb <> 0 then - raise exception 'EFFACEMENT INTERDIT: JOURNAL UTILISE'; -end if; -return OLD; -end;$BODY$ - LANGUAGE 'plpgsql' VOLATILE; - - -CREATE TRIGGER t_jrn_def_delete - BEFORE DELETE - ON jrn_def - FOR EACH ROW - EXECUTE PROCEDURE jrn_def_delete(); - -CREATE OR REPLACE FUNCTION proc_check_balance() - RETURNS "trigger" AS -$BODY$ -declare - diff numeric; - tt integer; -begin - if TG_OP = 'INSERT' or TG_OP='UPDATE' then - tt=NEW.jr_grpt_id; - diff:=check_balance(tt); - if diff != 0 then - raise exception 'balance error %',diff ; - end if; - return NEW; - end if; -end; -$BODY$ - LANGUAGE 'plpgsql' VOLATILE; - -CREATE TRIGGER t_check_balance - AFTER INSERT OR UPDATE - ON jrn - FOR EACH ROW - EXECUTE PROCEDURE proc_check_balance(); - -INSERT INTO "action" (ac_id, ac_description) VALUES (60, 'Module Budget'); -alter table tmp_pcmn add column pcm_type text; -ALTER TABLE tmp_pcmn ALTER COLUMN pcm_type set default NULL; - - -CREATE TABLE parm_poste ( - p_value poste_comptable NOT NULL, - p_type text NOT NULL -); - - --- --- Name: TABLE parm_poste; Type: COMMENT; Schema: public; Owner: postgres --- - -COMMENT ON TABLE parm_poste IS 'Contains data for finding is the type of the account (asset)'; - - --- --- Name: parm_poste_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: --- - -ALTER TABLE ONLY parm_poste - ADD CONSTRAINT parm_poste_pkey PRIMARY KEY (p_value); - - - -CREATE OR REPLACE FUNCTION find_pcm_type(pp_value "numeric") - RETURNS text AS -$BODY$ -declare - str_type text; - str_value text; - n_value numeric; - nLength integer; -begin - str_value:=trim(to_char(pp_value,'99999999999999999999999999999')); - nLength:=length(str_value); - while nLength > 0 loop - n_value:=to_number(str_value,'99999999999999999999999999999'); - select into str_type p_type from parm_poste where p_value=n_value; - if FOUND then - return str_type; - end if; - nLength:=nLength-1; - str_value:=substring(str_value from 1 for nLength); - end loop; -return 'CON'; -end; -$BODY$ - LANGUAGE 'plpgsql' VOLATILE; - -CREATE OR REPLACE FUNCTION tmp_pcmn_ins() - RETURNS "trigger" AS -$BODY$ -declare - r_record tmp_pcmn%ROWTYPE; -begin -r_record=NEW; -if length(trim(r_record.pcm_type))=0 or r_record.pcm_type is NULL then - r_record.pcm_type:=find_pcm_type(NEW.pcm_val); - return r_record; -end if; -return NEW; -end; -$BODY$ - LANGUAGE 'plpgsql' VOLATILE; - -CREATE TRIGGER t_tmp_pcmn_ins - BEFORE INSERT - ON tmp_pcmn - FOR EACH ROW - EXECUTE PROCEDURE tmp_pcmn_ins(); - -update tmp_pcmn set pcm_type=find_pcm_type(pcm_val); -commit; +commit;