From bade1f18bd6a74975deebc4a1684a07e2391d144 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Mon, 25 Jul 2005 20:56:42 +0000 Subject: [PATCH] Ajout listing assujetti tva (experimental) ajout parametre de la companie improve apparence de certaines table --- html/admin/setup.php | 16 ++- html/admin/sql/patch/upgrade5.sql | 96 +++++++++++++++++ html/dossier_prefs.php | 90 +++++++++++----- html/listing_client.php | 58 +++++++++++ html/user_impress.php | 6 +- include/class_customer.php | 160 +++++++++++++++++++++++++++++ include/class_own.php | 73 +++++++++++++ include/decla.BE.inc.php | 83 +++++++++++++++ include/impress_listing_client.php | 83 +++++++++++++++ include/impress_poste.php | 4 +- include/user_menu.php | 1 + 11 files changed, 641 insertions(+), 29 deletions(-) create mode 100644 html/admin/sql/patch/upgrade5.sql create mode 100644 html/listing_client.php create mode 100644 include/class_customer.php create mode 100644 include/class_own.php create mode 100644 include/decla.BE.inc.php create mode 100644 include/impress_listing_client.php diff --git a/html/admin/setup.php b/html/admin/setup.php index 78bc61b9a..2c039be55 100644 --- a/html/admin/setup.php +++ b/html/admin/setup.php @@ -251,8 +251,7 @@ if ($account == 0 ) { ExecuteScript($cn,'sql/mod1/schema.sql'); ExecuteScript($cn,'sql/mod1/data.sql'); -// $r=system("$psql -U phpcompta mod1 -f sql/mod1/schema.sql",$r); -// $r=system("$psql -U phpcompta mod1 -f sql/mod1/data.sql",$r); + ob_end_clean(); } @@ -290,7 +289,14 @@ for ($e=0;$e < $MaxDossier;$e++) { $sql=sprintf ("create sequence s_jrn_%d",$row['jrn_def_id']); ExecSql($db,$sql); } - } // version == 4 + } // version == 4 + //-- + // update to the version 5 + //-- + if ( GetVersion($db) == 5 ) { + ExecuteScript($db,'sql/patch/upgrade5.sql'); + } // version == 5 + } $Resdossier=ExecSql($cn,"select mod_id, mod_name from modeledef"); @@ -312,6 +318,10 @@ for ($e=0;$e < $MaxDossier;$e++) { ExecSql($db,$sql); } } // version == 4 + if ( GetVersion($db) == 5 ) { + ExecuteScript($db,'sql/patch/upgrade5.sql'); + } // version == 5 + } $cn=DbConnect(); if ( GetVersion($cn) <= 4 ) { diff --git a/html/admin/sql/patch/upgrade5.sql b/html/admin/sql/patch/upgrade5.sql new file mode 100644 index 000000000..1135886b2 --- /dev/null +++ b/html/admin/sql/patch/upgrade5.sql @@ -0,0 +1,96 @@ +-- create vw_client view +create view vw_client as +select a.f_id, +a.av_text as name, +b.av_text as tva_num,c.av_text as poste_comptable, +d.av_text as rue, +e.av_text as code_postal, +f.av_text as pays, +g.av_text as telephone, +h.av_text as email + from ( + select * from fiche join fiche_def using (fd_id) + join fiche_def_ref using (frd_id) + join jnt_fic_att_value using (f_id) join attr_value using (jft_id) where ad_id=1 ) a + left join ( + select * from fiche join fiche_def using (fd_id) + join fiche_def_ref using (frd_id) + join jnt_fic_att_value using (f_id) join attr_value using (jft_id) where ad_id=13 ) b using (f_id) + left join ( + select * from fiche join fiche_def using (fd_id) + join fiche_def_ref using (frd_id) + join jnt_fic_att_value using (f_id) + join attr_value using (jft_id) + where ad_id=5 ) c using (f_id) + left join ( + select * from fiche join fiche_def using (fd_id) + join fiche_def_ref using (frd_id) + join jnt_fic_att_value using (f_id) + join attr_value using (jft_id) + where ad_id=14 ) d using (f_id) + left join ( + select * from fiche join fiche_def using (fd_id) + join fiche_def_ref using (frd_id) + join jnt_fic_att_value using (f_id) + join attr_value using (jft_id) + where ad_id=15 ) e using (f_id) + left join ( + select * from fiche join fiche_def using (fd_id) + join fiche_def_ref using (frd_id) + join jnt_fic_att_value using (f_id) + join attr_value using (jft_id) + where ad_id=16 ) f using (f_id) + left join ( + select * from fiche join fiche_def using (fd_id) + join fiche_def_ref using (frd_id) + join jnt_fic_att_value using (f_id) + join attr_value using (jft_id) + where ad_id=17 ) g using (f_id) + left join ( + select * from fiche join fiche_def using (fd_id) + join fiche_def_ref using (frd_id) + join jnt_fic_att_value using (f_id) + join attr_value using (jft_id) + where ad_id=18 ) h using (f_id) +where a.frd_id=9; + +-- all the min attribut for card reference + +create view vw_fiche_min + as select frd_id, ad_id, ad_text, frd_text, frd_class_base + from + attr_min join attr_Def using (ad_id) + join fiche_Def_ref using (frd_id); +-- definition for card +create view vw_fiche_Def as + SELECT fd_id, + ad_id, + ad_text, + fd_class_base, + fd_label, + fd_create_account, + frd_id + FROM jnt_fic_attr + JOIN attr_def USING (ad_id) + JOIN fiche_def USING (fd_id); + +-- comments +comment on view vw_fiche_min is 'minimum attribut for reference card'; +comment on view vw_fiche_def is 'all the attributs for card family'; +comment on view vw_client is 'minimum attribut for the customer (frd_id=9)'; + +-- new table : parameter +create table parameter ( + pr_id text primary key, + pr_value text +); + +insert into parameter (pr_id) values ('MY_NAME'); +insert into parameter (pr_id) values ('MY_CP'); +insert into parameter (pr_id) values ('MY_COMMUNE'); +insert into parameter (pr_id) values ('MY_TVA'); +insert into parameter (pr_id) values ('MY_STREET'); +insert into parameter (pr_id) values ('MY_NUMMER'); + + +update version set val=6; \ No newline at end of file diff --git a/html/dossier_prefs.php b/html/dossier_prefs.php index 8dc29f6a9..151d2b808 100644 --- a/html/dossier_prefs.php +++ b/html/dossier_prefs.php @@ -33,7 +33,6 @@ $User=new cl_user($rep); $User->Check(); include("preference.php"); -// include_once ("top_menu_compta.php"); include_once("user_menu.php"); ShowMenuCompta($_SESSION['g_dossier']); @@ -64,7 +63,9 @@ if ( isset ($_POST['action']) ) { $action=$_POST['action']; } - +//////////////////////////////////////////////////////////////////////////////// +// Currency +//////////////////////////////////////////////////////////////////////////////// if ( $p_action == "change" ) { $p_mid=$_GET['p_mid']; $p_rate=$_GET['p_rate']; @@ -77,6 +78,36 @@ if ( $p_action == "change" ) { echo ' '; echo ''; } +if ( $action == "Change") { + $p_devise=$_POST['p_devise']; + $p_id=$_POST['p_id']; + $p_rate=$_POST['p_rate']; + $Res=ExecSql($cn,"update parm_money set pm_code='$p_devise',pm_rate=$p_rate where pm_id=$p_id"); + ShowDevise($cn); + +} +if ( $action == "Ajout") { + $p_devise=$_POST['p_devise']; + $p_rate=$_POST['p_rate']; + $Res=ExecSql($cn,"insert into parm_money ( pm_code,pm_rate) values ('$p_devise',$p_rate) "); + ShowDevise($cn); + +} + +if ( $p_action == "delete") { + $p_id=$_GET['p_mid']; + $Res=ExecSql($cn,"delete from parm_money where pm_id=$p_id"); + ShowDevise($cn); +} + + +if ( $p_action=="devise") { + ShowDevise($cn); +} + +//////////////////////////////////////////////////////////////////////////////// +// Periode +//////////////////////////////////////////////////////////////////////////////// if ( $p_action=="change_per") { foreach($HTTP_GET_VARS as $key=>$element) ${"$key"}=$element; @@ -136,27 +167,6 @@ if ( isset ($_POST["add_per"] )) { } echo_debug(__FILE__,__LINE__,"Action $action"); -if ( $action == "Change") { - $p_devise=$_POST['p_devise']; - $p_id=$_POST['p_id']; - $p_rate=$_POST['p_rate']; - $Res=ExecSql($cn,"update parm_money set pm_code='$p_devise',pm_rate=$p_rate where pm_id=$p_id"); - ShowDevise($cn); - -} -if ( $action == "Ajout") { - $p_devise=$_POST['p_devise']; - $p_rate=$_POST['p_rate']; - $Res=ExecSql($cn,"insert into parm_money ( pm_code,pm_rate) values ('$p_devise',$p_rate) "); - ShowDevise($cn); - -} - - - -if ( $p_action=="devise") { - ShowDevise($cn); -} if ( $p_action=="closed") { $p_per=$_GET['p_per']; $Res=ExecSql($cn,"update parm_periode set p_closed=true where p_id=$p_per"); @@ -178,7 +188,41 @@ if ( $p_action== "delete_per" ) { if ( $p_action == "periode" ) { ShowPeriode($cn); } +//////////////////////////////////////////////////////////////////////////////// +// Coord societe +//////////////////////////////////////////////////////////////////////////////// +if ( $p_action=='company') { + require_once("class_own.php"); + require_once("class_widget.php"); + if ( isset ($_POST['record_company'] )) { + $m=new Own($cn); + extract($_POST); + $m->MY_NAME=$p_name; + $m->MY_TVA=$p_tva; + $m->MY_STREET=$p_street; + $m->MY_NUMBER=$p_no; + $m->MY_CP=$p_cp; + $m->MY_COMMUNE=$p_Commune; + $m->Save(); + } + $my=new Own($cn); + $all=new widget("text"); + $all->table=1; + echo '
'; + echo ""; + echo "".$all->IOValue("p_name",$my->MY_NAME,"Nom société").""; + + echo "".$all->IOValue("p_tva",$my->MY_TVA,"Numéro de Tva").""; + echo "".$all->IOValue("p_street",$my->MY_STREET,"Rue ").""; + echo "".$all->IOValue("p_no",$my->MY_NUMBER,"Numéro").""; + echo "".$all->IOValue("p_cp",$my->MY_CP,"Code Postal").""; + echo "".$all->IOValue("p_Commune",$my->MY_COMMUNE,"Commune").""; + echo "
"; + $submit=new widget("submit"); + echo $submit->Submit("record_company","Enregistre"); + echo "
"; + } echo ""; diff --git a/html/listing_client.php b/html/listing_client.php new file mode 100644 index 000000000..4be6c6d43 --- /dev/null +++ b/html/listing_client.php @@ -0,0 +1,58 @@ +Check(); + +// TODO a specific level of security for the "bilan" ??? +// Change must be done here +if ( $User->admin == 0 ) { + if (CheckAction($_SESSION['g_dossier'],$_SESSION['g_user'],IMP) == 0 ){ + /* Cannot Access */ + NoAccess(); + } +} + +header('Content-type: application/bin'); +header('Content-Disposition: attachment;filename="declaration.bin"',FALSE); + +//////////////////////////////////////////////////////////////////////////////// +// Submit for a magnetic declaration +// Belgium only +//////////////////////////////////////////////////////////////////////////////// +if ( isset($_POST['bt_disk'])) { + require_once("class_customer.php"); + $customer=new Customer($cn); + $a_Res=$customer->VatListing($_POST['year']); + + require_once("decla.BE.inc.php"); + $a=MakeListingVat($cn,$a_Res,$_POST['year']); + echo "$a"; + return; + } +?> diff --git a/html/user_impress.php b/html/user_impress.php index 869dc03e1..db43506d3 100644 --- a/html/user_impress.php +++ b/html/user_impress.php @@ -47,7 +47,8 @@ $p_array=array(array ("user_impress.php?type=jrn","Journaux"), array("user_impress.php?type=fiche","Fiche"), array("user_impress.php?type=rapport","Rapport"), array('user_impress.php?type=bal','Balance des comptes'), - array("user_impress.php?type=bilan","Bilan") + array("user_impress.php?type=bilan","Bilan"), + array("user_impress.php?type=list_client","Liste Clients Assujettis") ); $default=( isset ($_GET['type']))?"user_impress.php?type=".$_GET['type']:""; $result=ShowItem($p_array,'H',"cell","mtitle",$default); @@ -87,6 +88,9 @@ $default=( isset ($_GET['type']))?$_GET['type']:""; case "fiche": include ("impress_fiche.php"); break; + case "list_client": + include ("impress_listing_client.php"); + break; } diff --git a/include/class_customer.php b/include/class_customer.php new file mode 100644 index 000000000..daacb5c85 --- /dev/null +++ b/include/class_customer.php @@ -0,0 +1,160 @@ +db=$p_cn; + } + // Get all info contains in the view + // thanks to the poste elt + function GetFromPoste($p_poste=0) { + $this->poste=($p_poste==0)?$this->poste:$p_poste; + $sql="select * from vw_client where poste_comptable=".$this->poste; + $Res=ExecSql($this->db,$sql); + if ( pg_NumRows($Res) == 0) return null; + // There is only _one_ row by customer + $row=pg_fetch_array($Res,0); + $this->name=$row['name']; + $this->id=$row['f_id']; + $this->street=$row['rue']; + $this->cp=$row['code_postal']; + $this->country=$row['pays']; + $this->vat_number=$row['tva_num']; + + } +/* function ListingVat + ************************************************** + * Purpose : Get all the info for making a vat listing + * for the vat administration + * + * parm : + * - periode + * + * return: + * + * - array + */ + function VatListing($p_year) { + $cond_sql=" and A.j_tech_per = B.j_tech_per + and A.j_tech_per= any (select p_id + from parm_periode + where + p_exercice='$p_year')"; + + // BASE ACCOUNT + // for belgium + // TODO : those values should be in a table because + // they are _national_ parameters + //----- + $SOLD="70"; + $CUSTOMER="400"; + $TVA="451"; + // Get all the sell operation + //---- + $sql="select j_grpt + from +jrnx as A + join jrnx as B using (j_grpt) +where + A.j_poste like '".$CUSTOMER."%' and + B.j_poste like '".$SOLD."%' + $cond_sql +"; + + $Res=ExecSql($this->db,$sql); + // Foreach operation + // where 7% or tva account are involved + // and store the result in an array (a_Res) + //--- + $a_Res=array(); + for ($i=0; $i < pg_NumRows($Res);$i++) { + // Get each row + //--- + $row1=pg_fetch_array($Res,$i); + + // select the customer + //---- + $Res2=ExecSql($this->db,"select j_poste,j_montant,j_debit from jrnx where j_grpt=".$row1['j_grpt']); + $a_row=array(); + // Store the result in the array + //--- + for ($e=0;$e < pg_NumRows($Res2);$e++) { + $a_row[]=pg_fetch_array($Res2,$e); + } + + // Seek the customer + //--- + foreach ($a_row as $e) { + if ( substr($e['j_poste'],0, strlen($CUSTOMER))==$CUSTOMER) { + $customer=$e['j_poste']; + // Retrieve name and vat number + $this->GetFromPoste($customer); + $a_Res[$customer]['name']=$this->name; + $a_Res[$customer]['vat_number']=$this->vat_number; + break; + + } + }// foreach $a + // Store the amount in the array + //--- + foreach ($a_row as $e) { + $amount=0; + $tva=0; + if ( substr($e['j_poste'],0, strlen($SOLD))==$SOLD) { + $amount=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1; + } + if ( substr($e['j_poste'],0, strlen($TVA))==$TVA) { + $tva=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1; + } + // store sold + //--- + $a_Res[$customer]['amount']=(isset($a_Res[$customer]['amount']))?$a_Res[$customer]['amount']:0; + $a_Res[$customer]['amount']+=$amount; + + // store vat + //--- + $a_Res[$customer]['tva']=(isset($a_Res[$customer]['tva']))?$a_Res[$customer]['tva']:0; + $a_Res[$customer]['tva']+=$tva; + + // store customef info + //--- + $a_Res[$customer]['customer']=$customer; + }// foreach $a + + } + return $a_Res; + } +} + +?> \ No newline at end of file diff --git a/include/class_own.php b/include/class_own.php new file mode 100644 index 000000000..eaab86391 --- /dev/null +++ b/include/class_own.php @@ -0,0 +1,73 @@ +db=$p_cn; + $Res=ExecSql($p_cn,"select * from parameter where pr_id like 'MY_%'"); + for ($i = 0;$i < pg_NumRows($Res);$i++) { + $row=pg_fetch_array($Res,$i); + $key=$row['pr_id']; + $elt=$row['pr_value']; + // store value here + $this->{"$key"}=$elt; + } + + } +/* function UpdateRow + ************************************************** + * Purpose : Update a row + * + * parm : + * - give the attribut name + * gen : + * - none + * return: + * -none + */ + function UpdateRow($p_attr) { + $value=FormatString($this->{"$p_attr"}); + $Res=ExecSql($this->db,"update parameter set pr_value='$value' where pr_id='$p_attr'"); + } + +/* function Save + ************************************************** + * Purpose : save data + * + * parm : + * - none + * gen : + * - none + * return: + * - nothing + */ + function Save() { + $this->UpdateRow('MY_NAME'); + $this->UpdateRow('MY_TVA'); + $this->UpdateRow('MY_STREET'); + $this->UpdateRow('MY_NUMBER'); + $this->UpdateRow('MY_CP'); + $this->UpdateRow('MY_COMMUNE'); + + } + +} \ No newline at end of file diff --git a/include/decla.BE.inc.php b/include/decla.BE.inc.php new file mode 100644 index 000000000..8b2dc774a --- /dev/null +++ b/include/decla.BE.inc.php @@ -0,0 +1,83 @@ +MY_NAME); + $b=$my->MY_STREET.",".$my->MY_NUMBER; + $a.=sprintf("% 24s",$b); + $b=$my->MY_CP." ".$my->MY_COMMUNE; + $a.=sprintf("% 27s",$b); + $a.="BE"; + $a.=sprintf("%9s",$my->MY_TVA); + // special zone + $a.=sprintf("% 20s",' '); + // + $a.="E"; + $a.=$p_year; + $a.="\n"; + // customer record + $rec_id=0; + $tot_amount=0; + $tot_tva=0; + foreach ($p_array as $client) { + if ( strlen(trim($client['tva'])) != 0 ) { + $rec_id++; + $a.=sprintf("%06d",$rec_id); + $a.=sprintf("% 32s",$client['name']); + $a.=str_repeat(" ",51); + $a.=sprintf("BE%s",$client['vat_number']); + $a.=sprintf("%010d",$client['amount']*100); + $a.=sprintf("%010d",$client['tva']*100); + $a.=str_repeat(" ",10); + $a.="\n"; + $tot_amount=+$client['amount']*100; + $tot_tva+=$client['tva']*100; + } + } + //Last Record + $a.="999999"; + $a.=sprintf("%016d",$tot_amount); + $a.=sprintf("%016d",$tot_tva); + $a.=str_repeat(" ",51); + $a.="BE"; + $a.=$my->MY_TVA; + $a.=str_repeat(" ",28); + $a.="\n"; + return $a; +} \ No newline at end of file diff --git a/include/impress_listing_client.php b/include/impress_listing_client.php new file mode 100644 index 000000000..3224739d3 --- /dev/null +++ b/include/impress_listing_client.php @@ -0,0 +1,83 @@ +VatListing($_POST['year']); + +echo " +
+ + + + + + + + + + +"; + foreach ($a_Res as $key=>$elt) { + echo "". + "". + "". + "". + "". + ""; + } + echo "
Nom Numéro TVA Montant HTVA Montant TVA
".$elt['name']."".$elt['vat_number']."".sprintf("% 8.2f",$elt['amount'])."".sprintf("% 8.2f",$elt['tva'])."
"; + echo "
"; + return; + } + +//////////////////////////////////////////////////////////////////////////////// +// Form +//////////////////////////////////////////////////////////////////////////////// +$w=new widget("select"); +$w->table=1; + +echo '
'; +echo '
'; +echo ''; + +print ''; +$year=make_array($cn,"select distinct p_exercice,p_exercice from parm_periode"); +$w->label="Année concernée"; +print $w->IOValue('year',$year); +print ""; +echo '
'; +print $w->Submit('bt_html','Impression'); + +echo '
'; + +echo '
'; + +?> diff --git a/include/impress_poste.php b/include/impress_poste.php index 0c82e1ac0..b43cb6117 100644 --- a/include/impress_poste.php +++ b/include/impress_poste.php @@ -37,7 +37,7 @@ include("class_poste.php"); $hid=new widget("hidden"); echo '
'; echo '

'.$Poste->id." ".$Poste->name.'

'; - echo ""; + echo "
"; echo ''; echo '
'. $submit->Submit('bt_other',"Autre poste"). @@ -66,7 +66,7 @@ include("class_poste.php"); if ( count($Poste->row ) == 0 ) exit; - echo ""; + echo "
"; echo "". "". "". diff --git a/include/user_menu.php b/include/user_menu.php index 0cafa2774..1c526148a 100644 --- a/include/user_menu.php +++ b/include/user_menu.php @@ -593,6 +593,7 @@ function ShowMenuParam() { $sub_menu=ShowItem(array( //('rapprt.php','Rapprochement'), + array('dossier_prefs.php?p_action=company','Paramètres sociétés'), array('dossier_prefs.php?p_action=devise','Devises'), array('dossier_prefs.php?p_action=periode','Période'), array('user_sec.php','Sécurité')
Code interne Date