';
echo '';
diff --git a/html/print_invoice.php b/html/print_invoice.php
new file mode 100644
index 000000000..9238978cf
--- /dev/null
+++ b/html/print_invoice.php
@@ -0,0 +1,137 @@
+
+
+/*
+ * This file is part of PhpCompta.
+ *
+ * PhpCompta is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * PhpCompta is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PhpCompta; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+/* received parameters
+ e_date element 01.01.2003
+ e_client element 3
+ nb_item element 2
+ e_march0 element 11
+ e_quant0 element 1
+ e_march1 element 6
+ e_quant1 element 2
+ e_comment invoice number
+*/
+// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
+// $Revision$
+
+ include_once("jrn.php");
+ include_once("ac_common.php");
+ include_once("postgres.php");
+ include_once("class.ezpdf.php");
+ include_once("impress_inc.php");
+ include_once("fiche_inc.php");
+ include_once("user_common.php");
+ echo_debug("imp pdf journaux");
+ $l_Db=sprintf("dossier%d",$g_dossier);
+ $cn=DbConnect($l_Db);
+foreach ($HTTP_POST_VARS as $key=>$element) {
+ ${"$key"}=$element;
+ echo_debug("key => $key element $element");
+}
+
+$amount=0.0;
+for ($i=0;$i<$nb_item;$i++) {
+ // store quantity & goods in array
+ $a_good[$i]=${"e_march$i"};
+ $a_quant[$i]=${"e_quant$i"};
+ $a_amount[$i]=GetFicheAttribut($cn,$a_good[$i],ATTR_DEF_PRIX_VENTE)*$a_quant[$i];
+ $amount+=$a_amount[$i];
+ $tva=GetTvaRate($cn,GetFicheAttribut($cn,$a_good[$i],ATTR_DEF_TVA));
+ // Prepare the array to print
+ $a_good_detail[]=array('id'=>$i+1,
+ 'name'=>GetFicheAttribut($cn,$a_good[$i],ATTR_DEF_NAME),
+ 'quantity'=>$a_quant[$i],
+ 'Unit' =>GetFicheAttribut($cn,$a_good[$i],ATTR_DEF_PRIX_VENTE),
+ 'Total HTVA' => $a_amount[$i],
+ 'tva'=>$tva['tva_label'],
+ 'Total' => $a_amount[$i]+$a_amount[$i]*$a_quant[$i]*$tva['tva_rate']);
+ }
+
+ $a_vat=ComputeVat($cn, $a_good,$a_quant,ATTR_DEF_PRIX_VENTE);
+ $sum_vat=0.0;
+ foreach ( $a_vat as $element => $t) {
+ echo_debug(" a_vat element $element t $t");
+ $sum_vat+=$t;
+ echo_debug("sum_vat = $sum_vat");
+ }
+
+ $ret="";
+ $pdf=& new Cezpdf('a4');
+ $pdf->selectFont('./addon/fonts/Helvetica.afm');
+ $pdf->ezSetCmMargins(2,2,2,2);
+ // Write the date
+ $pdf->ezText("Date : ".$e_date,10,array('justification'=>'right'));
+
+ // write the customer data
+ $info[0]=array('info'=>GetFicheAttribut($cn,$e_client,ATTR_DEF_NAME));
+ $info[1]=array('info'=>GetFicheAttribut($cn,$e_client,ATTR_DEF_ADRESS));
+ $info[2]=array('info'=>GetFicheAttribut($cn,$e_client,ATTR_DEF_CP));
+ $info[3]=array('info'=>GetFicheAttribut($cn,$e_client,ATTR_DEF_PAYS));
+ $pdf->ezSetDy(-50);
+ $pdf->ezTable($info, null, "Informations"
+ , array('width'=>200,'fontSize'=>12,'shaded'=>0,'xOrientation'=>'left','xPos'=>'right','showHeadings'=>0));
+
+ // Write the invoice number
+ $pdf->ezSetDy(-50);
+ $pdf->ezText ($e_comment,14,array('justification'=>'center'));
+
+ // Write the goods details
+ $pdf->ezSetDy(-50);
+ $pdf->ezTable($a_good_detail,null,'Detail invoice',
+ array('width'=>400,'cols'=>array(
+ 'quantity'=>array('justification'=>'right'),
+ 'Unit'=>array('justification'=>'right'),
+ 'Total HTVA'=>array('justification'=>'right'),
+ 'tva'=>array('justification'=>'right'),
+ 'Total'=>array('justification'=>'right')
+ )));
+
+
+ // Write the sum detail
+ $sum_detail[0] = array ('label'=>'Total HTVA ','amount'=>$amount);
+ $index=1;
+ foreach ( $a_vat as $element => $t) {
+ echo_debug(" a_vat element $element t $t");
+ $a_tva_sum=GetTvaRate($cn,$element);
+ $sum_detail[++$index]=array('label'=>"tva ". $a_tva_sum['tva_label'],'amount'=>$t);
+ }
+ $total=$amount+$sum_vat;
+ $sum_detail[++$index]=array('label'=>"Total", 'amount'=>$total);
+ $pdf->ezSetDy(-50);
+ $pdf->ezTable($sum_detail,null,'',
+ array('width'=>200,'showHeadings'=>0,'shaded'=>0,'cols'=>array('amount'=>array('justification'=>'right'))));
+
+
+// wRITE THE DATE LIMIT
+ $pdf->ezSetDy(-50);
+$pdf->ezText(" Limit date : ".$e_ech);
+
+
+
+// // Make a file of it
+// //$pdfcode=" I don't know whether the prob comes from the ezPdf or from Apache or from Mysql";
+// $pdfcode=$pdf->ezOutput();
+// $fp=fopen("invoice.pdf","wb+");
+// fwrite($fp,$pdfcode);
+// fclose ($fp);
+
+$pdf->ezStream();
+
+
+?>
diff --git a/html/show_tva.php b/html/show_tva.php
new file mode 100644
index 000000000..5c7516527
--- /dev/null
+++ b/html/show_tva.php
@@ -0,0 +1,51 @@
+
+/*
+ * This file is part of PhpCompta.
+ *
+ * PhpCompta is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * PhpCompta is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PhpCompta; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
+/* $Revision$ */
+
+include_once ("ac_common.php");
+html_page_start($g_UserProperty['use_theme']);
+include_once ("postgres.php");
+/* Admin. Dossier */
+CheckUser();
+
+if ( ! isset ( $g_dossier ) ) {
+ echo "You must choose a Dossier ";
+ phpinfo();
+ exit -2;
+}
+
+
+$l_Db=sprintf("dossier%d",$g_dossier);
+$condition="";
+$cn=DbConnect($l_Db);
+$Res=ExecSql($cn,"select * from tva_rate order by tva_rate desc");
+$Max=pg_NumRows($Res);
+echo "";
+for ($i=0;$i<$Max;$i++) {
+ $row=pg_fetch_array($Res,$i);
+ printf("%d %s %s ",
+ $row['tva_id'],
+ $row['tva_label'],
+ $row['tva_comment']);
+}
+echo '
';
+echo ' ';
+html_page_stop();
+?>
diff --git a/html/user_advanced.php b/html/user_advanced.php
new file mode 100644
index 000000000..7984529be
--- /dev/null
+++ b/html/user_advanced.php
@@ -0,0 +1,59 @@
+
+/*
+ * This file is part of WCOMPTA.
+ *
+ * PhpCompta is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * PhpCompta is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with WCOMPTA; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+// Auteur Dany De Bontridder ddebontridder@yahoo.fr
+include_once ("ac_common.php");
+/* $Revision$ */
+
+html_page_start($g_UserProperty['use_theme']);
+if ( ! isset ( $g_dossier ) ) {
+ echo "You must choose a Dossier ";
+ phpinfo();
+ exit -2;
+}
+include_once ("postgres.php");
+/* Admin. Dossier */
+CheckUser();
+
+include_once ("postgres.php");
+echo_debug ("user is $g_user");
+/* CheckUser */
+CheckUser();
+
+// We don't check permissions here in fact, permission are tested in the
+// functions
+
+// Show the top menus
+include_once ("user_menu.php");
+include_once ("top_menu_compta.php");
+ShowMenuCompta($g_dossier,$g_UserProperty);
+
+// Show the right menus
+ShowMenuComptaRight($g_dossier,$g_UserProperty);
+
+// Show the left menu
+$left_menu=ShowItem(array(
+ array('jrn_update.php','Journaux'),
+ array('central.php','Centralise'),
+ array('pcmn_update.php?p_start=1','Plan Comptable')),
+ 'V');
+echo '';
+
+?>
\ No newline at end of file
diff --git a/html/win_search_jrn.js b/html/win_search_jrn.js
index 6e256c005..2a0c3abb2 100644
--- a/html/win_search_jrn.js
+++ b/html/win_search_jrn.js
@@ -17,7 +17,7 @@
*/
function SearchJrn(p_sessid)
{
- var win=window.open('jrn_search.php?PHPSESSID='+p_sessid,'Cherche','toolbar=no,width=600,height=600,scrollbar');
+ var win=window.open('jrn_search.php?PHPSESSID='+p_sessid,'Cherche','toolbar=no,width=600,height=600,scrollbars=yes');
}
function GetIt(p_value) {
self.opener.SetIt(p_value);
diff --git a/include/ac_common.php b/include/ac_common.php
index d9b65ecd8..88a286f6d 100644
--- a/include/ac_common.php
+++ b/include/ac_common.php
@@ -110,7 +110,7 @@ function isDate ( $p_date) {
}// !ereg
return $p_date;
}
-/* function
+/* function formatDate($p_date)
* Purpose :
*
* parm :
diff --git a/include/constant.php b/include/constant.php
index fb3983c4b..ec52c40ac 100644
--- a/include/constant.php
+++ b/include/constant.php
@@ -84,10 +84,44 @@ define ("ALL_FICHE_DEF_REF", 1000);
// fixed value for attr_def data
define ("ATTR_DEF_ACCOUNT",5);
define ("ATTR_DEF_NAME",1);
-define ("ATTR_DEF_PRIX_ACHAT",6);
-define ("ATTR_DEF_PRIX_VENTE",7);
+define ("ATTR_DEF_PRIX_ACHAT",7);
+define ("ATTR_DEF_PRIX_VENTE",6);
define ("ATTR_DEF_TVA",2);
define ("FICHE_TYPE_CLIENT",9);
define ("FICHE_TYPE_VENTE",1);
+define ("ATTR_DEF_ADRESS",14);
+define ("ATTR_DEF_CP",15);
+define ("ATTR_DEF_PAYS",16);
+
+define ("JS_SEARCH_POSTE",""
+);
+define ("JS_SHOW_TVA",""
+);
+
+define ("JS_VIEW_JRN_DETAIL","");
+
+// Sql string
+define ("SQL_LIST_ALL_INVOICE","");
+define ("SQL_LIST_UNPAID_INVOICE"," where (jr_rapt is null or jr_rapt = '')");
+define ("SQL_LIST_UNPAID_INVOICE_DATE_LIMIT" ," where (jr_rapt is null or jr_rapt = '')
+ and to_date(to_char(jr_ech,'DD.MM.YYYY'),'DD.MM.YYYY') < to_date(to_char(now(),'DD.MM.YYYY'),'DD.MM.YYYY')");
?>
diff --git a/include/fiche_inc.php b/include/fiche_inc.php
index 408231e0b..976ad6227 100644
--- a/include/fiche_inc.php
+++ b/include/fiche_inc.php
@@ -19,7 +19,7 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
// $Revision$
-/* fucntion GetSqlFiche
+/* function GetSqlFiche
***************************************************
* purpose : return the sql string which match the p_type
* permit to have all the sql here
@@ -52,7 +52,7 @@ function GetSqlFiche($p_type) {
* - none
* return:
* - none
- *
+ * TODO ADD TEST FOR THE VAT RATE
*/
function AddFiche($p_cn,$p_type,$p_array) {
echo_debug(" AddFiche($p_cn,$p_type,$p_array) ");
@@ -160,7 +160,9 @@ function EncodeFiche($p_cn,$p_type,$p_array=null) {
$ch_li=' ';
echo ' ';
@@ -405,6 +430,7 @@ function ViewFicheDetail($p_cn,$p_id) {
* - nothing
*
*/
+//TODO ADD TEST FOR THE VAT RATE
function UpdateFiche($p_cn,$p_array) {
foreach ( $p_array as $key=> $element) {
echo_debug("$key => $element");
@@ -432,7 +458,7 @@ function UpdateFiche($p_cn,$p_array) {
}
// Update the PCMN if needed
$sql="select av_text from attr_value natural join jnt_fic_att_value
- where f_id=$fiche and ad_id=5";
+ where f_id=$fiche and ad_id=".ATTR_DEF_ACCOUNT;
$Res=ExecSql($p_cn,$sql);
if ( pg_NumRows($Res) != 0 ) {
@@ -463,12 +489,16 @@ function UpdateFiche($p_cn,$p_array) {
$class=$class_old;
} else // $class=""
{
+
+ echo_debug("new account ");
$class=$class_old;
- // First we must use a parent
- $parent=GetParent($p_cn,$class);
- $Res=ExecSql($p_cn,
- "insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent)
+ if ( CountSql($p_cn,"select * from tmp_pcmn where pcm_val=".$class) == 0 ) {
+ // First we must use a parent
+ $parent=GetParent($p_cn,$class);
+ $Res=ExecSql($p_cn,
+ "insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent)
values ($class,'$f_label',$parent)");
+ }
}
@@ -853,13 +883,11 @@ function getFicheDefName($p_cn,$p_id) {
* - p_cn connextion
* - j_jrn journal_id
* - $p_type : deb or cred
- * - $p_fiche_type : fiche_def_ref.frd_id to know what kind of card is asked
- * -> Sell, Customer...
* gen :
* - none
* return: array containing the fiche(f_id),fiche(f_label)
*/
-function GetFicheJrn($p_cn,$p_jrn,$p_type,$p_fiche_type)
+function GetFicheJrn($p_cn,$p_jrn,$p_type)
{
$get="";
if ( $p_type == 'deb' ) {
@@ -884,13 +912,14 @@ function GetFicheJrn($p_cn,$p_jrn,$p_type,$p_fiche_type)
echo_warning("No fiche");
return null;
}
+
$sql="select f_id,av_text as f_label
from fiche natural join jnt_fic_att_value
natural join attr_def
natural join attr_value
- natural join fiche_def_ref
+ natural join fiche_def
where ad_id=1 and
- fd_id in (".$list['fiche'].") and frd_id=$p_fiche_type order by f_label";
+ fd_id in (".$list['fiche'].") order by f_label";
$Res=ExecSql($p_cn,$sql);
$Max=pg_NumRows($Res);
@@ -1261,5 +1290,34 @@ function GetParent($p_cn,$p_val)
return $a;
}
}
+/* function getFicheAttribut
+ ***************************************************
+ * Purpose : retourne le tva
+ *
+ * parm :
+ * - p_cn connexion
+ * - p_id fiche id
+ * - attribut
+ * gen :
+ * - none
+ * return:
+ * - string avec nom fiche
+ */
+function getFicheAttribut($p_cn,$p_id,$p_attr) {
+ // Retrieve the attribute with the ad_id 1
+ // 1 is always the name
+ // TODO replace absolute value by defined value
+ $Res=ExecSql($p_cn,"select av_text from
+ attr_value
+ natural join jnt_fic_att_value
+ natural join fiche
+ where
+ f_id=$p_id and
+ ad_id=$p_attr");
+ if ( pg_NumRows($Res) == 0 ) return "Unknown";
+ $st=pg_fetch_array($Res,0);
+ return $st['av_text'];
+}
+
?>
diff --git a/include/form_input.php b/include/form_input.php
index a7f3c6669..fa8d0cc83 100644
--- a/include/form_input.php
+++ b/include/form_input.php
@@ -19,7 +19,8 @@
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/* $Revision$ */
include_once("preference.php");
-
+include_once("fiche_inc.php");
+include_once("user_common.php");
/* function InputType
* Purpose : Create the tag
*
@@ -38,9 +39,20 @@ include_once("preference.php");
function InputType($p_label,$p_type,$p_name,$p_value,$p_viewonly=false,$p_list=null)
{
// View only
- if ( $p_viewonly==false)
- return "$p_label $value ";
+ if ( $p_viewonly==true) {
+ if ( strlen($p_label) != 0) {
+ // name and value are set put the info in a hidden field
+ $hidden=(strlen($p_name) != 0) ?" ":"";
+ // return
+ return "$p_label $hidden $p_value ";
+ } else {
+ // name and value are set put the info in a hidden field
+ $hidden=(strlen($p_name) != 0) ?" ":"";
+
+ return "$p_value $hidden ";
+ }
+ }
// Input type == select
if ( strtolower($p_type)=="select" ) {
$r=" $p_label ";
@@ -48,7 +60,7 @@ function InputType($p_label,$p_type,$p_name,$p_value,$p_viewonly=false,$p_list=n
foreach ($p_list as $item) {
$selected="";
if ( $p_value == $item[0] ) {
- $selected="SELECTED";
+ $selected="SELECTED";
}
$r.=sprintf('%s',
$item[0],
@@ -68,6 +80,16 @@ function InputType($p_label,$p_type,$p_name,$p_value,$p_viewonly=false,$p_list=n
$p_value);
return $r;
}
+
+ // input type == HIDDEN
+ if ( strtolower($p_type)=="hidden") {
+ $r=sprintf(' ',
+ $p_type,
+ $p_name,
+ $p_value);
+ return $r;
+ }
+
}
/* function FormVente
@@ -80,52 +102,431 @@ function InputType($p_label,$p_type,$p_name,$p_value,$p_viewonly=false,$p_list=n
* - the "journal"
* - $p_user = $g_user
* - view_only if we cannot change it (no right or centralized op)
+ * - $p_article number of article
* gen :
* -
* return: string with the form
+ * TODO Add in parameters the infos about the company for making the invoice
*/
-function FormVente($p_cn,$p_jrn,$p_user,$p_array=null,$view_only=true)
+function FormVente($p_cn,$p_jrn,$p_user,$p_array=null,$view_only=true,$p_article=1)
{
- $userPref=GetUserPeriode($p_cn,$p_user);
+ if ( $p_array != null ) {
+ // array contains old value
+ foreach ( $p_array as $a=>$v) {
+ ${"$a"}=$v;
+ }
+ }
// The date
+ $userPref=GetUserPeriode($p_cn,$p_user);
list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$userPref);
-
- $op_date="01".substr($l_date_start,2,8);
+ $op_date=( ! isset($e_date) ) ? "01".substr($l_date_start,2,8):$e_date;
+ $e_ech=(isset($e_ech))?$e_ech:"";
+ // Save old value and set a new one
echo_debug("form_input.php.FormVentep_op_date is $op_date");
$r="";
if ( $view_only == false) {
- $r="";
return $r;
-}
\ No newline at end of file
+}
+
+/* function FormVenteView ($p_cn,$p_jrn,$p_user,$p_array,$p_number,$p_doc='html',$p_comment='')
+ **************************************************
+ * Purpose : Show the invoice before inserting it
+ * the database
+ *
+ * parm :
+ * - p_cn database connection
+ * - p_jrn journal
+ * - p_user
+ * - array of value
+ * - nb of item
+ * - p_doc type pdf or html
+ * gen :
+ * - none
+ * return:
+ * - string
+ * TODO Add test for the date
+ */
+
+function FormVenteView ($p_cn,$p_jrn,$p_user,$p_array,$p_number,$p_doc='html',$p_comment='')
+{
+// TODO Verify the invoice data if verif failed return null and resubmit
+ $r="";
+ $data="";
+ // Keep all the data if hidden
+ // and store the array in variables
+ foreach ($p_array as $name=>$content) {
+ $data.=InputType("","HIDDEN",$name,$content);
+ ${"$name"}=$content;
+ }
+ // Verify the date
+ if ( isDate($e_date) == null ) {
+ echo_error("Invalid date $e_date");
+ echo_debug("Invalid date $e_date");
+ echo "";
+ return null;
+ }
+// Verify the quantity
+for ($o = 0;$o < $p_number; $o++) {
+ if ( isNumber(${"e_quant$o"}) == 0 ) {
+ echo_debug("invalid quantity ".${"e_quant$o"});
+ echo_error("invalid quantity ".${"e_quant$o"});
+ echo "";
+ return null;
+ }
+}
+// Verify the ech
+if (strlen($e_ech) != 0 and isNumber($e_ech) == 0 and isDate ($e_ech) == null ) {
+ $msg="Echeance invalide";
+ echo_error($msg); echo_error($msg);
+ echo "";
+ return null;
+ }
+
+ // if ech is a number of days then compute date limit
+ if ( strlen($e_ech) != 0 and isNumber($e_ech) == 1) {
+ list($day,$month,$year)=explode(".",$e_date);
+ echo_debug(" date $e_date = $day.$month.$year");
+ $p_ech=date('d.m.Y',mktime(0,0,0,$month,$day+$e_ech,$year));
+ echo_debug("p_ech = $e_ech $p_ech");
+ $e_ech=$p_ech;
+ $data.=InputType("","HIDDEN","e_ech",$e_ech);
+ }
+
+// Verify the userperiode
+
+// userPref contient la periode par default
+ $userPref=GetUserPeriode($p_cn,$p_user);
+ list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$userPref);
+
+ // Date dans la periode active
+ echo_debug ("date start periode $l_date_start date fin periode $l_date_end date demandée $e_date");
+ if ( cmpDate($e_date,$l_date_start)<0 ||
+ cmpDate($e_date,$l_date_end)>0 )
+ {
+ $msg="Not in the active periode please change your preference";
+ echo_error($msg); echo_error($msg);
+ echo "";
+ return null;
+ }
+ // Periode fermée
+ if ( PeriodeClosed ($p_cn,$userPref)=='t' )
+ {
+ $msg="This periode is closed please change your preference";
+ echo_error($msg); echo_error($msg);
+ echo "";
+ return null;
+ }
+ // start table
+ $r.='';
+ // Show the Date
+ $r.="";
+ $r.=InputType("Date","text","",$e_date,true);
+ $r.=" ";
+ // Show the customer Name
+ $r.="";
+ $r.=InputType("Client","text","",getFicheName($p_cn,$e_client),true);
+ $r.=" ";
+
+ // show date limit
+ $r.="";
+ $r.=InputType("Date limite","text","",$e_ech,true);
+ $r.=" ";
+
+ $sum_with_vat=0.0;
+ $sum_march=0.0;
+ // show all article, price vat and sum
+ $r.="";
+ $r.="Article ";
+ $r.="quantité ";
+ $r.="prix unit. ";
+ $r.="taux tva ";
+ $r.="Montant HTVA ";
+ $r.="Montant TVA ";
+ $r.="Total ";
+ $r.=" ";
+ for ($i=0;$i<$p_number;$i++) {
+ $fiche_name=getFicheName($p_cn,${"e_march$i"});
+ $fiche_price=getFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_PRIX_VENTE);
+
+ $fiche_quant=${"e_quant$i"};
+
+ // No row if there is quantity
+ if ( $fiche_quant == 0.0 ) continue;
+ // VAT
+ $vat=getFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_TVA);
+
+ // vat label
+ // vat rate
+ $a_vat=GetTvaRate($p_cn,$vat);
+ if ( $a_vat == null ) {
+ $vat_label="unknown";
+ $vat_rate=0.0;
+ } else {
+ $vat_label=$a_vat['tva_label'];
+ $vat_rate=$a_vat['tva_rate'];
+ }
+
+ // Total card without vat
+ $fiche_sum=$fiche_price*$fiche_quant;
+ // Sum of invoice
+ $sum_march+=$fiche_sum;
+ // vat of the card
+ $fiche_amount_vat=$fiche_price*$fiche_quant*$vat_rate;
+ // value card + vat
+ $fiche_with_vat=$fiche_price*$fiche_quant*(1+$vat_rate);
+ // Sum of invoice vat
+ $sum_with_vat+=$fiche_with_vat;
+ // Show the data
+ $r.='';
+ $r.=''.$fiche_name.' ';
+ $r.=''.$fiche_quant.' ';
+ $r.=''.$fiche_price.' ';
+ $r.=" $vat_label ";
+ $r.=''.$fiche_sum.' ';
+ $r.=''.$fiche_amount_vat.' ';
+
+ $r.=''.$fiche_with_vat.' ';
+
+ $r.=" ";
+ }
+
+ // end table
+ $r.='
';
+ $r.='';
+ $r.="Total HTVA = $sum_march ";
+ $r.="Total = $sum_with_vat";
+ $r.="
";
+ if ( $p_doc == 'html' ) {
+ $r.='';
+ }
+if ( $p_doc == 'pdf' ) {
+ $r.='';
+
+ }
+ return $r;
+
+}
+
+/* function RecordInvoice
+ **************************************************
+ * Purpose : Record an invoice in the table jrn &
+ * jrnx
+ *
+ * parm :
+ * - $p_cn Database connection
+ * - $p_array contains all the invoice data
+ * e_date => e : 01.01.2003
+ * e_client => e : 3
+ * nb_item => e : 3
+ * e_march0 => e : 6
+ * e_quant0 => e : 0
+ * e_march1 => e : 6
+ * e_quant1 => e : 2
+ * e_march2 => e : 7
+ * e_quant2 => e : 3
+V : view_invoice => e : Voir cette facture
+V : record_invoice => e : Sauver
+ * - $p_user userid
+ * - $p_jrn current folder (journal)
+ * gen :
+ * - none
+ * return:
+ * true on success
+ */
+function RecordInvoice($p_cn,$p_array,$p_user,$p_jrn)
+{
+ foreach ( $p_array as $v => $e)
+ {
+ ${"$v"}=$e;
+ }
+ // Get the default period
+ $periode=GetUserPeriode($p_cn,$p_user);
+ $amount=0.0;
+ // Computing total customer
+ for ($i=0;$i<$nb_item;$i++) {
+ // store quantity & goods in array
+ $a_good[$i]=${"e_march$i"};
+ $a_quant[$i]=${"e_quant$i"};
+ $amount+=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_PRIX_VENTE)*$a_quant[$i];
+ }
+ $a_vat=ComputeVat($p_cn, $a_good,$a_quant,ATTR_DEF_PRIX_VENTE);
+ $sum_vat=0.0;
+ foreach ( $a_vat as $element => $t) {
+ echo_debug(" a_vat element $element t $t");
+ $sum_vat+=$t;
+ echo_debug("sum_vat = $sum_vat");
+ }
+ // First we add in jrnx
+
+ // Compute the j_grpt
+ $seq=GetNextId($p_cn,'j_grpt')+1;
+
+
+ // Debit = client
+ $poste=GetFicheAttribut($p_cn,$e_client,ATTR_DEF_ACCOUNT);
+ InsertJrnx($p_cn,'d',$p_user,$p_jrn,$poste,$e_date,$amount+$sum_vat,$seq,$periode);
+
+ // Credit = goods
+ for ( $i = 0; $i < $nb_item;$i++) {
+ $poste=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_ACCOUNT);
+
+ InsertJrnx($p_cn,'c',$p_user,$p_jrn,$poste,$e_date,$amount,$seq,$periode);
+ }
+ // Insert Vat
+ if (sizeof($a_vat) != 0 ) // no vat
+ {
+ foreach ($a_vat as $tva_id => $tva_amount ) {
+ $poste=GetTvaPoste($p_cn,$tva_id,'c');
+ InsertJrnx($p_cn,'c',$p_user,$p_jrn,$poste,$e_date,$tva_amount,$seq,$periode);
+ }
+ }
+echo_debug("echeance = $e_ech");
+ InsertJrn($p_cn,$e_date,$e_ech,$p_jrn,"Invoice",$amount+$sum_vat,$seq,$periode);
+ // Set Internal code and Comment
+ $comment=SetInternalCode($p_cn,$seq,$p_jrn)." client : ".GetFicheName($p_cn,$e_client);
+
+ // Update and set the invoice's comment
+ $Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq);
+ return $comment;
+}
+/* function FormAch($p_cn,$p_jrn,$p_user,$p_array=null,$view_only=true,$p_article=1)
+ * Purpose : Display the form for buying
+ * Used to show detail, encode a new invoice
+ * or update one
+ *
+ * parm :
+ * - p_array which can be empty
+ * - the "journal"
+ * - $p_user = $g_user
+ * - $p_submit contains the submit string
+ * - view_only if we cannot change it (no right or centralized op)
+ * - $p_article number of article
+ * gen :
+ * -
+ * return: string with the form
+ * TODO Add in parameters the infos about the company for making the invoice
+ */
+function FormAch($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p_article=1)
+{
+
+ if ( $p_array != null ) {
+ // array contains old value
+ foreach ( $p_array as $a=>$v) {
+ ${"$a"}=$v;
+ }
+ }
+ // The date
+ $userPref=GetUserPeriode($p_cn,$p_user);
+ list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$userPref);
+ $op_date=( ! isset($e_date) ) ? "01".substr($l_date_start,2,8):$e_date;
+
+ $e_ech=(isset($e_ech))?$e_ech:"";
+ // Save old value and set a new one
+ echo_debug("form_input.php.FormAch p_op_date is $op_date");
+ $r="";
+ if ( $view_only == false) {
+ $r="";
+
+ return $r;
+
+
+}
diff --git a/include/jrn.php b/include/jrn.php
index b42ba5592..fddd5fe30 100644
--- a/include/jrn.php
+++ b/include/jrn.php
@@ -67,7 +67,7 @@ function RecordJrn($p_dossier,$p_user,$p_jrn,$p_MaxDeb,$p_MaxCred,$p_array = nul
}
}
/* Get Jrn's properties */
- $l_line=GetJrnProp($p_dossier,$p_jrn);
+ $l_line=GetJrnProperty($cn,$p_jrn);
if ( $l_line == null ) return;
echo '
';
}
+/* function GetJrnProperty ($p_cn,$p_jrn)
+ * Purpose : Get the properties of a journal
+ *
+ * parm :
+ * - p_cn database connection
+ * - p_jrn the jrn id
+ * gen :
+ * - none
+ * return:
+ * - an array containing properties
+ *
+ */
+function GetJrnProperty($p_cn,$p_jrn)
+{
+ $Res=ExecSql($p_cn,"select jrn_Def_id,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_def_type,
+ jrn_deb_max_line,jrn_cred_max_line,jrn_def_ech,jrn_def_ech_lib,jrn_def_code,
+ jrn_def_fiche_deb,jrn_def_fiche_deb
+ from jrn_Def
+ where jrn_def_id=$p_jrn");
+ $Count=pg_NumRows($Res);
+ if ( $Count == 0 ) {
+ echo '';
@@ -78,7 +78,7 @@ function FormPeriode($p_cn,$l_default=0,$p_type=OPEN,$p_suff="")
$sql="select p_id,to_char(p_start,'DD.MM.YYYY') as p_start,
to_char(p_end,'DD.MM.YYYY') as p_end
from parm_periode where
- $sql_closed order by p_start";
+ $sql_closed order by p_exercice,p_start";
}
if ($p_type==OPEN) {
@@ -86,7 +86,7 @@ function FormPeriode($p_cn,$l_default=0,$p_type=OPEN,$p_suff="")
$sql="select p_id,to_char(p_start,'DD.MM.YYYY') as p_start,
to_char(p_end,'DD.MM.YYYY') as p_end
from parm_periode where
- $sql_closed order by p_start";
+ $sql_closed order by p_exercice,p_start";
}
if ($p_type==NOTCENTRALIZED) {
@@ -95,7 +95,7 @@ function FormPeriode($p_cn,$l_default=0,$p_type=OPEN,$p_suff="")
from parm_periode where
p_closed=true and p_id not in (
select c_periode from centralized)
- order by p_start";
+ order by p_exercice,p_start";
}
$Res=ExecSql($p_cn,$sql);
$Max=pg_NumRows($Res);
@@ -203,7 +203,7 @@ function GetPeriode($p_cn,$p_periode)
return pg_fetch_array($Res,0);
}
-/* function
+/* function PeriodeClosed($p_cn,$p_periode)
* Purpose :
*
* parm :
@@ -211,7 +211,7 @@ function GetPeriode($p_cn,$p_periode)
* gen :
* -
* return:
- * - array containing the start date & the end date
+ * - true if closed
*
*/
function PeriodeClosed($p_cn,$p_periode)
diff --git a/include/user_action_ven.php b/include/user_action_ven.php
index 21ca9f54b..c1613dc94 100644
--- a/include/user_action_ven.php
+++ b/include/user_action_ven.php
@@ -18,45 +18,122 @@
*/
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/* $Revision$ */
-if ( ! isset ($_GET['action']) ) {
+echo_debug("include user_action_ven.php");
+include_once("form_input.php");
+if ( ! isset ($_GET['action']) && ! isset ($_POST["action"]) ) {
return;
}
$dossier=sprintf("dossier%d",$g_dossier);
$cn=DbConnect($dossier);
-$action=$_GET['action'];
+$action=(isset($_GET['action']))?$_GET['action']:$_POST['action'];
if ( $action == 'insert_vente' ) {
// Check privilege
if ( CheckJrn($g_dossier,$g_user,$g_jrn) != 2 ) {
NoAccess();
exit -1;
}
-// Show an empyt form of invoice
- include_once("form_input.php");
- $form=FormVente($cn,$g_jrn,$g_user,'deb');
- echo '';
- echo $form;
- echo '
';
+
+ // Add item
+ if (isset($_POST["add_item"]) ) {
+ echo_debug("Add an item");
+ $nb_number=$_POST["nb_item"];
+ $nb_number++;
+
+ $form=FormVente($cn,$g_jrn,$g_user,$HTTP_POST_VARS,false,$nb_number);
+ echo '';
+ echo $form;
+ echo '
';
+
+ }
+
+ // We want to see the encoded invoice
+ if ( isset ($_POST["view_invoice"])) {
+ $nb_number=$_POST["nb_item"];
+ $form=FormVenteView($cn,$g_jrn,$g_user,$HTTP_POST_VARS,$nb_number);
+ // Check failed : invalid date or quantity
+ if ( $form== null) {
+ echo_error("Cannot validate ");
+ $form=FormVente($cn,$g_jrn,$g_user,$HTTP_POST_VARS,false,$nb_number);
+ }
+ echo '';
+ echo $form;
+ echo '
';
+
+ }
+
+ // We want a blank form
+ if ( isset($_GET["blank"]))
+ {
+ echo_debug("Blank form");
+ // Show an empty form of invoice
+ $form=FormVente($cn,$g_jrn,$g_user,null,false);
+ echo '';
+ echo $form;
+ echo '
';
+ }
+
}
-if ( $action == 'voir_vente' ) {
-// Show list of sell
-// Date - date of payment - Customer - amount
- $list=ListSell();
- echo '';
- echo $list;
- echo '
';
+
+
+ // Save the invoice
+if ( isset($_POST["record_invoice"])) {
+ // echo "RECORD INVOICE";
+ RecordInvoice($cn,$HTTP_POST_VARS,$g_user,$g_jrn);
}
-if ( $action == 'voir_vente_non_paye' ) {
+
+// Save and print the invoice
+if ( isset($_POST["record_and_print_invoice"])) {
+ // echo "RECORD AND PRINT INVOICE";
+ $comment=RecordInvoice($cn,$HTTP_POST_VARS,$g_user,$g_jrn);
+ $nb_number=$_POST["nb_item"];
+ $form=FormVenteView($cn,$g_jrn,$g_user,$HTTP_POST_VARS,$nb_number,'pdf',$comment);
+ echo '';
+ echo $form;
+ echo "
";
+}
+
+
+ if ( $action == 'voir_jrn' ) {
+ // Show list of sell
+ // Date - date of payment - Customer - amount
+ $sql=SQL_LIST_ALL_INVOICE." and jr_tech_per=".GetUserPeriode($cn,$g_user)." and jr_def_id=$g_jrn";
+ $list=ListJrn($cn,$g_jrn,$sql);
+ echo '';
+ echo $list;
+ echo '
';
+}
+if ( $action == 'voir_jrn_non_paye' ) {
// Show list of unpaid sell
// Date - date of payment - Customer - amount
- $list=ListSell('filtre');
- echo '';
+ $sql=SQL_LIST_UNPAID_INVOICE_DATE_LIMIT." and jr_def_id=$g_jrn";
+ $list=ListJrn($cn,$g_jrn,$sql);
+ $sql=SQL_LIST_UNPAID_INVOICE." and jr_def_id=$g_jrn";
+ $list2=ListJrn($cn,$g_jrn,$sql);
+ echo '
';
+ echo '
Echeance dépassée ';
echo $list;
+ echo ' Non Payée ';
+ echo $list2;
echo '';
}
-if ( $action == 'impress' ) {
-// Print list of sell or print the current invoice
-}
+// if ( $action == 'impress' ) {
+// // Print list of sell or print the current invoice
+// }
+
+//Search
if ( $action == 'search' ) {
+ // PhpSessid
+ $sessid=(isset ($_POST['PHPSESSID']))?$_POST['PHPSESSID']:$_GET['PHPSESSID'];
+
+
// display a search box
+ $search_box=u_ShowMenuRecherche($cn,$g_jrn,$sessid,$HTTP_POST_VARS);
+ echo '
';
+ echo $search_box;
+ // if nofirst is set then show result
+ if ( isset ($_GET['nofirst'] ) )
+ ViewJrn($g_dossier,$g_user,$g_jrn,$HTTP_POST_VARS);
+ echo '
';
}
-?>
\ No newline at end of file
+
+?>
diff --git a/include/user_common.php b/include/user_common.php
new file mode 100644
index 000000000..fb54b1ea4
--- /dev/null
+++ b/include/user_common.php
@@ -0,0 +1,274 @@
+
+/*
+ * This file is part of PhpCompta.
+ *
+ * PhpCompta is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * PhpCompta is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PhpCompta; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+/* $Revision$ */
+// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
+
+include_once("postgres.php");
+
+/* function GetTvaRate
+ **************************************************
+ * Purpose : Return the rate of the p_tva_id
+ *
+ * parm :
+ * - p_cn database connection
+ * - p_tva_id tva.tva_id
+ * gen :
+ * - none
+ * return:
+ * an array containing the rate and the label
+ * the tva rate or null if a problem occured
+ */
+
+function GetTvaRate($p_cn,$p_tva_id) {
+$Res=pg_exec($p_cn,"select tva_id,tva_rate,tva_label from tva_rate where tva_id=".$p_tva_id);
+if (pg_NumRows($Res) == 0 ) return null;
+
+$r=pg_fetch_array($Res,0);
+return $r;
+
+}
+/* function ComputeVat($p_cn, $a_good,$a_quant,$p_type);
+ **************************************************
+ * Purpose : Compute the vat,
+ * the fiche.f_id are in a_fiche
+ * the quantity in a_quant
+ *
+ *
+ * parm :
+ * - database connection
+ * - fiche
+ * - quantity
+ * - p_type ATTR_DEF_PRIX_VENTE ATTR_DEF_PRIX_ACHAT
+ * gen :
+ * -
+ * return: array
+ * a[tva_id] = amount vat
+ */
+function ComputeVat($p_cn, $a_fiche,$a_quant,$p_type) {
+echo_debug("ComputeVat $a_fiche $a_quant $p_type");
+// foreach goods
+for ( $i=0 ; $i < sizeof($a_fiche);$i++) {
+// Get the tva_id
+$tva_id=GetFicheAttribut($p_cn,$a_fiche[$i],ATTR_DEF_TVA);
+
+ // for each fiche find the tva_rate and tva_id
+ $a_vat=GetTvaRate($p_cn,$tva_id);
+
+ // Get the attribut price of the card(fiche)
+ $amount=GetFicheAttribut($p_cn,$a_fiche[$i],$p_type);
+
+ if ( $a_vat != null ) {
+ $a=$a_vat['tva_id'];
+ $vat_amount=$amount*$a_vat['tva_rate']*$a_quant[$i];
+ $r[$a]=isset ( $r[$a] )?$r[$a]+$vat_amount:$vat_amount;
+ } else {
+ echo_error("Not vat here in ComputeVat !");
+ return 0;
+ }
+ }
+ echo_debug(" return $r");
+ return $r;
+
+
+}
+
+
+
+/* function GetTvaPoste($p_cn,$tva_id,$p_type);
+ **************************************************
+ * Purpose : Get the account of tva_rate.tva_poste
+ * return the credit or the debit account
+ * parm : connection
+ * - tva_rate.tva_id
+ * type ( d or credit)
+ * gen :
+ * -
+ * return:
+ * return the credit or the debit account
+ * null if error
+ */
+function GetTvaPoste($p_cn,$p_tva_id,$p_cred) {
+ $Res=ExecSql($p_cn,"select tva_poste from tva_rate where tva_id=$p_tva_id");
+ if ( pg_NumRows($Res) == 0 ) return null;
+ $a=pg_fetch_array($Res,0);
+ list ($deb,$cred)=split(",",$a['tva_poste']);
+ if ( $p_cred=='c' ) return $cred;
+ if ($p_cred=='d') return $deb;
+ echo_error ("Invalid $p_cred in GetTvaRate");
+ return null;
+}
+
+
+
+
+/* function InsertJrnx($p_cn,$p_type,$p_user,$p_jrn,$p_poste,$p_date,$p_amount,$p_grpt,$p_periode);
+ **************************************************
+ * Purpose : Insert into the table Jrn
+ *
+ * parm :
+ * - $p_cn database connection
+ * - $p_type debit or credit
+ * - $p_user the current user
+ * - $p_jrn the current 'journal' (folder)
+ * - $p_poste the account
+ * - $p_date
+ * - $p_amount amount to insert
+ * - $p_periode the concerned periode
+ * gen :
+ * - none
+ * return:
+ * - nothing
+ */
+
+function InsertJrnx($p_cn,$p_type,$p_user,$p_jrn,$p_poste,$p_date,$p_amount,$p_grpt,$p_periode)
+{
+ echo_debug ("InsertJrnx param
+ type = $p_type p_user $p_user p_date $p_date p_poste $p_poste p_amount $p_amount p_grpt = $p_grpt p_periode = $p_periode");
+ $debit=($p_type=='c')?'false':'true';
+ $sql=sprintf("insert into jrnx (j_date,j_montant, j_poste,j_grpt, j_jrn_def,j_debit,j_tech_user,j_tech_per)
+ values (to_date('%s','DD.MM.YYYY'),%.2f,%d,%d,%d,%s,'%s',%d)",
+ $p_date,$p_amount,$p_poste,$p_grpt,$p_jrn,$debit,$p_user,$p_periode);
+ echo_debug("InsertJrnx $sql");
+ $Res=ExecSql($p_cn,$sql);
+
+}
+/* function InsertJrn($p_cn,$p_date,$p_jrn,$p_comment,$p_amount,$p_grpt,$p_periode);
+ **************************************************
+ * Purpose : Insert into the table Jrnx
+ *
+ * parm :
+ * - $p_cn database connection
+ * - $p_date date
+ * - $p_jrn the current 'journal' (folder)
+ * - $p_poste the account
+ * - $p_amount amount to insert
+ * - $p_periode the concerned periode
+ * gen :
+ * - none
+ * return:
+ * - nothing
+ */
+
+function InsertJrn($p_cn,$p_date,$p_echeance,$p_jrn,$p_comment,$p_amount,$p_grpt,$p_periode)
+{
+ echo_debug ("InsertJrn param
+ p_date $p_date p_poste $p_comment p_amount $p_amount p_grpt = $p_grpt p_periode = $p_periode p_echeance = $p_echeance");
+ if ( $p_echeance == "" or $p_echeance==null) {
+ $p_echeance='null';
+ } else {
+ $p_echeance=sprintf("to_date('%s','DD.MM.YYYY')",$p_echeance);
+ }
+ $sql=sprintf("insert into jrn (jr_def_id,jr_montant,jr_comment,jr_date,jr_ech,jr_grpt_id,jr_tech_per)
+ values ( %d,%.2f,'%s',to_date('%s','DD.MM.YYYY'),%s,%d,%d)",
+ $p_jrn, $p_amount,$p_comment,$p_date,$p_echeance,$p_grpt,$p_periode);
+ echo_debug("InsertJrn $sql");
+ $Res=ExecSql($p_cn,$sql);
+ return GetSequence($p_cn,'s_jrn');
+}
+/* function ListJrn($p_cn,$p_jrn,$p_wherel)
+ **************************************************
+ * Purpose : show all the lines of the asked jrn
+ *
+ * parm :
+ * - $p_cn database connection
+ * - $p_jrn jrn_id jrn.jrn_def_id
+ * - $p_sql the sql query (where clause)
+ * gen :
+ * - none
+ * return:
+ *
+ */
+function ListJrn($p_cn,$p_jrn,$p_where="")
+{
+ // TODO Show modify button but only for no centralized operations
+ //TODO add a print button but only if type of jrn is VEN !!
+
+$Res=ExecSql($p_cn,"select jr_id ,
+ jr_montant,
+ jr_comment,
+ jr_ech,
+ jr_date,
+ jr_grpt_id,
+ jr_rapt,
+ jr_internal,
+ jrn_def_id,
+ jrn_def_name,
+ jrn_def_ech,
+ jrn_def_type
+ from
+ jrn join jrn_def on jrn_def_id=jr_def_id
+ $p_where
+ order by jr_date");
+$r="";
+$r.=JS_VIEW_JRN_DETAIL;
+$Max=pg_NumRows($Res);
+if ($Max==0) return "No row selected";
+$r.="
";
+return $r;
+}
diff --git a/include/user_menu.php b/include/user_menu.php
index 52b106b7c..8093a7af6 100644
--- a/include/user_menu.php
+++ b/include/user_menu.php
@@ -80,7 +80,7 @@ function GetAvailableFolder($p_user,$p_admin)
$filter="and use_login='$p_user' ";
}
- $sql="select dos_id,dos_name,dos_description from ac_users
+ $sql="select distinct dos_id,dos_name,dos_description from ac_users
natural join jnt_use_dos
natural join ac_dossier
where use_active=1 ".$filter;
@@ -150,7 +150,7 @@ function u_ShowMenuCompta($p_dossier)
array("user_jrn.php?JRN_TYPE=FIN","Banque"),
array("user_jrn.php?JRN_TYPE=OD","Op. Diverses"),
array("fiche.php?p_dossier=$p_dossier","Fiche"),
- array("not_implemented.php","Avancé"),
+ array("user_advanced.php","Avancé"),
array("dossier_prefs.php","Paramètre")
);
@@ -303,6 +303,75 @@ function u_ShowMenuJrn($p_cn,$p_jrn_type)
$ret.='';
return $ret;
+}
+/* function u_ShowMenuRecherche ($p_cn,$p_jrn,$p_sessid,$p_array=null)
+ * Purpose :
+ *
+ * parm :
+ * - $p_cn database connection
+ * - $p_jrn jrn id
+ * - $p_array=null previous search
+ * gen :
+ * - none
+ * return:
+ * - none
+ *
+ */
+
+function u_ShowMenuRecherche($p_cn,$p_jrn,$p_sessid,$p_array=null)
+{
+ echo_debug("u_ShowMenuRecherche($p_cn,$p_jrn,$p_array)");
+ if ( $p_array != null ) {
+ foreach ( $p_array as $key=> $element) {
+ ${"p_$key"}=$element;
+ echo_debug("p_$key =$element;");
+ }
+ }
+
+ // Find the journal property
+ $JrnProperty=GetJrnProperty($p_cn,$p_jrn);
+
+ $opt='
<=';
+ $opt.=' <';
+ $opt.=' =';
+ $opt.=' >';
+ $opt.=' >=';
+ if ( ! isset ($p_date_start)) $p_date_start="";
+ if ( ! isset ($p_date_end)) $p_date_end="";
+ if ( ! isset ($p_mont_sel))$p_mont_sel="";
+ if ( ! isset ($p_s_comment))$p_s_comment="";
+ if ( ! isset ($p_s_montant)) $p_s_montant="";
+
+ if ( $p_mont_sel != "" ) $opt.=' '.$p_mont_sel;
+ $r="";
+
+ $r.= '';
+ $r.= "
Recherche ";
+ $r.= '
";
+ $r.= '
';
+
+ return $r;
+
}
?>
diff --git a/sql/ac_users.sql b/sql/ac_users.sql
index 68155137d..f20b40eed 100644
--- a/sql/ac_users.sql
+++ b/sql/ac_users.sql
@@ -32,7 +32,7 @@ create table ac_users (
primary key (use_id)
);
-insert into ac_users (use_login, use_active,use_pass,use_usertype,use_admin) values (user,1,
+insert into ac_users (use_login, use_active,use_pass,use_usertype,use_admin) values ('phpcompta',1,
'b1cc88e1907cde80cb2595fa793b3da9','compta',1);
diff --git a/sql/dos_pref.sql b/sql/dos_pref.sql
index abc889091..d29be7e51 100644
--- a/sql/dos_pref.sql
+++ b/sql/dos_pref.sql
@@ -50,3 +50,18 @@ insert into parm_periode (p_start,p_end,p_exercice) values ('01-10-2003','30-10
insert into parm_periode (p_start,p_end,p_exercice) values ('01-11-2003','30-11-2003','2003');
insert into parm_periode (p_start,p_end,p_exercice) values ('01-12-2003','31-12-2003','2003');
insert into parm_periode (p_start,p_exercice) values ('31-12-2003','2003');
+
+-- for the year 2004
+insert into parm_periode (p_start,p_end,p_exercice) values ('01-01-2004','31-01-2004','2004');
+insert into parm_periode (p_start,p_end,p_exercice) values ('01-02-2004','28-02-2004','2004');
+insert into parm_periode (p_start,p_end,p_exercice) values ('01-03-2004','31-03-2004','2004');
+insert into parm_periode (p_start,p_end,p_exercice) values ('01-04-2004','30-04-2004','2004');
+insert into parm_periode (p_start,p_end,p_exercice) values ('01-05-2004','31-05-2004','2004');
+insert into parm_periode (p_start,p_end,p_exercice) values ('01-06-2004','30-06-2004','2004');
+insert into parm_periode (p_start,p_end,p_exercice) values ('01-07-2004','31-07-2004','2004');
+insert into parm_periode (p_start,p_end,p_exercice) values ('01-08-2004','31-08-2004','2004');
+insert into parm_periode (p_start,p_end,p_exercice) values ('01-09-2004','30-09-2004','2004');
+insert into parm_periode (p_start,p_end,p_exercice) values ('01-10-2004','30-10-2004','2004');
+insert into parm_periode (p_start,p_end,p_exercice) values ('01-11-2004','30-11-2004','2004');
+insert into parm_periode (p_start,p_end,p_exercice) values ('01-12-2004','31-12-2004','2004');
+insert into parm_periode (p_start,p_exercice) values ('31-12-2004','2004');
diff --git a/sql/fiche.sql b/sql/fiche.sql
index 36aad2e95..b27475018 100644
--- a/sql/fiche.sql
+++ b/sql/fiche.sql
@@ -1,54 +1,223 @@
-/* $Revision$ */
-/*
- * This file is part of PhpCompta.
- *
- * PhpCompta is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * PhpCompta is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with PhpCompta; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-drop sequence s_isup;
+-- For the fiche dev only
+-- Create the sequence
+\echo recreate Sequence
+\echo try first to drop it, no worry about error messages
+
+\echo drop SEQUENCE s_fiche
+drop SEQUENCE s_fiche;
+\echo CREATE SEQUENCE s_fiche
+CREATE SEQUENCE s_fiche;
+\echo drop sequence s_fiche_def_ref
+drop sequence s_fiche_def_ref;
+\echo create sequence s_fiche_def_ref
+create sequence s_fiche_def_ref;
+\echo drop sequence s_fdef
drop sequence s_fdef;
-drop sequence s_idef;
-
-drop table isupp;
-drop table fiche ;
-drop table isupp_def ;
-drop table fichedef ;
-create sequence s_isup;
-
+\echo create sequence s_fdef
create sequence s_fdef;
-create sequence s_idef;
+\echo drop sequence s_attr_def;
+drop sequence s_attr_def;
+\echo drop sequence s_attr_def;
+drop sequence s_attr_def;
+\echo create sequence s_attr_def
+create sequence s_attr_def;
+\echo drop SEQUENCE s_jnt_fic_att_value
+drop SEQUENCE s_jnt_fic_att_value;
+\echo CREATE SEQUENCE s_jnt_fic_att_value
+CREATE SEQUENCE s_jnt_fic_att_value;
-create table fichedef (
- fd_id integer not null default nextval('s_fdef') primary key,
- fd_label text not null,
- fd_class_base text
-);
-create table fiche (
- f_id integer not null references tmp_pcmn(pcm_val) primary key,
- f_label text not null,
- f_fd_id integer
-);
-create table isupp_def (
- isd_id integer not null default nextval('s_idef') primary key,
- isd_label text,
- isd_fd_id integer references fichedef(fd_id),
- isd_form bool
+\echo Drop first the tables and after
+\echo recreate them
+\echo drop table fiche_def_ref
+drop table fiche_def_ref cascade;
+\echo CREATE TABLE fiche_def_ref
+CREATE TABLE fiche_def_ref (
+ frd_id integer DEFAULT nextval('s_fiche_def_ref'::text) primary key,
+ frd_text text,
+ frd_class_base integer default null
);
-create table isupp (
- is_id integer not null default nextval('s_isup') primary key,
- is_f_id integer references tmp_pcmn(pcm_val),
- is_isd_id integer references isupp_def(isd_id),
- is_value text
+\echo drop TABLE fiche_def
+drop TABLE fiche_def cascade;
+\echo CREATE TABLE fiche_def
+CREATE TABLE fiche_def (
+ fd_id integer DEFAULT nextval('s_fdef'::text) primary key,
+ fd_class_base integer,
+ fd_label text NOT NULL,
+ fd_create_account bool default false,
+ frd_id integer NOT NULL references fiche_def_ref(frd_id)
);
+
+\echo drop TABLE attr_value
+drop TABLE attr_value cascade;
+\echo CREATE TABLE attr_value
+CREATE TABLE attr_value (
+ jft_id integer references jnt_fic_att_value(jft_id),
+ av_text text
+);
+
+\echo drop TABLE attr_def
+drop TABLE attr_def cascade;
+\echo CREATE TABLE attr_def
+CREATE TABLE attr_def (
+ ad_id integer DEFAULT nextval('s_attr_def'::text) primary key,
+ ad_text text
+);
+
+\echo drop TABLE attr_min
+drop TABLE attr_min cascade;
+\echo CREATE TABLE attr_min
+CREATE TABLE attr_min (
+ frd_id integer references fiche_def_ref(frd_id),
+ ad_id integer references attr_def(ad_id)
+);
+
+\echo drop TABLE fiche
+drop TABLE fiche cascade;
+\echo CREATE TABLE fiche
+CREATE TABLE fiche (
+ f_id integer DEFAULT nextval('s_fiche'::text) primary key,
+ fd_id integer references fiche_def(fd_id)
+);
+
+
+
+\echo drop TABLE jnt_fic_att_value
+drop TABLE jnt_fic_att_value cascade;
+\echo CREATE TABLE jnt_fic_att_value
+CREATE TABLE jnt_fic_att_value (
+ jft_id integer DEFAULT nextval('s_jnt_fic_att_value'::text) primary key,
+ f_id integer references fiche(f_id),
+ ad_id integer references attr_def(ad_id)
+);
+\echo drop attr_value
+drop table attr_value;
+\echo create table attr_value
+create table attr_value (
+jft_id integer references jnt_fic_att_value(jft_id),
+av_text text);
+
+\echo drop table jnt_fic_attr
+drop table jnt_fic_attr
+;
+\echo create table jnt_fic_attr
+create table jnt_fic_attr (
+fd_id integer references fiche_def(fd_id),
+ad_id integer references attr_def(ad_id))
+;
+--
+-- PostgreSQL database dump
+--
+
+\connect - phpcompta
+
+SET search_path = public, pg_catalog;
+
+--
+-- Data for TOC entry 1 (OID 21236)
+-- Name: attr_def; Type: TABLE DATA; Schema: public; Owner: phpcompta
+--
+
+INSERT INTO attr_def VALUES (1, 'Nom');
+INSERT INTO attr_def VALUES (2, 'Taux TVA');
+INSERT INTO attr_def VALUES (3, 'Numéro de compte');
+INSERT INTO attr_def VALUES (4, 'Nom de la banque');
+INSERT INTO attr_def VALUES (5, 'Poste Comptable');
+INSERT INTO attr_def VALUES (6, 'Prix vente');
+INSERT INTO attr_def VALUES (7, 'Prix achat');
+INSERT INTO attr_def VALUES (8, 'Durée Amortissement');
+INSERT INTO attr_def VALUES (9, 'Description');
+INSERT INTO attr_def VALUES (10, 'Date début');
+INSERT INTO attr_def VALUES (11, 'Montant initial');
+INSERT INTO attr_def VALUES (12, 'Personne de contact ');
+INSERT INTO attr_def VALUES (13, 'numéro de tva ');
+INSERT INTO attr_def VALUES (14, 'Adresse ');
+INSERT INTO attr_def VALUES (15, 'code postale ');
+INSERT INTO attr_def VALUES (16, 'pays ');
+INSERT INTO attr_def VALUES (17, 'téléphone ');
+INSERT INTO attr_def VALUES (18, 'email ');
+
+
+--
+-- PostgreSQL database dump
+--
+
+\connect - phpcompta
+
+SET search_path = public, pg_catalog;
+
+--
+-- Data for TOC entry 1 (OID 21206)
+-- Name: fiche_def_ref; Type: TABLE DATA; Schema: public; Owner: phpcompta
+--
+
+INSERT INTO fiche_def_ref VALUES (1, 'Vente Service', 700);
+INSERT INTO fiche_def_ref VALUES (2, 'Marchandises achat ', 604);
+-- INSERT INTO fiche_def_ref VALUES (2, 'Marchandises Vente & Achat', 604,704);
+INSERT INTO fiche_def_ref VALUES (3, 'Achat Service et biens divers', 61);
+INSERT INTO fiche_def_ref VALUES (4, 'Banque', 5500);
+INSERT INTO fiche_def_ref VALUES (5, 'Prêt > a un an', 17);
+INSERT INTO fiche_def_ref VALUES (6, 'Prêt < a un an', 430);
+INSERT INTO fiche_def_ref VALUES (8, 'Fournisseurs', 440);
+INSERT INTO fiche_def_ref VALUES (9, 'Clients', 400);
+INSERT INTO fiche_def_ref VALUES (10, 'Salaire Administrateur', 6200);
+INSERT INTO fiche_def_ref VALUES (11, 'Salaire Ouvrier', 6203);
+INSERT INTO fiche_def_ref VALUES (12, 'Salaire Employé', 6202);
+INSERT INTO fiche_def_ref VALUES (13, 'Dépenses non admises', 674);
+INSERT INTO fiche_def_ref VALUES (7, 'Matériel à amortir', 24);
+
+INSERT INTO fiche_def_ref VALUES (14, 'Marchandises Vente ', 704);
+
+--
+-- PostgreSQL database dump
+--
+
+\connect - phpcompta
+
+SET search_path = public, pg_catalog;
+
+--
+-- Data for TOC entry 1 (OID 21244)
+-- Name: attr_min; Type: TABLE DATA; Schema: public; Owner: phpcompta
+--
+
+INSERT INTO attr_min VALUES (1, 1);
+INSERT INTO attr_min VALUES (1, 2);
+INSERT INTO attr_min VALUES (2, 1);
+INSERT INTO attr_min VALUES (2, 2);
+INSERT INTO attr_min VALUES (3, 1);
+INSERT INTO attr_min VALUES (3, 2);
+INSERT INTO attr_min VALUES (4, 1);
+INSERT INTO attr_min VALUES (4, 3);
+INSERT INTO attr_min VALUES (4, 4);
+INSERT INTO attr_min VALUES (4, 12);
+INSERT INTO attr_min VALUES (4, 13);
+INSERT INTO attr_min VALUES (4, 14);
+INSERT INTO attr_min VALUES (4, 15);
+INSERT INTO attr_min VALUES (4, 16);
+INSERT INTO attr_min VALUES (4, 17);
+INSERT INTO attr_min VALUES (4, 18);
+INSERT INTO attr_min VALUES (8, 1);
+INSERT INTO attr_min VALUES (8, 12);
+INSERT INTO attr_min VALUES (8, 13);
+INSERT INTO attr_min VALUES (8, 14);
+INSERT INTO attr_min VALUES (8, 15);
+INSERT INTO attr_min VALUES (8, 16);
+INSERT INTO attr_min VALUES (8, 17);
+INSERT INTO attr_min VALUES (8, 18);
+INSERT INTO attr_min VALUES (9, 1);
+INSERT INTO attr_min VALUES (9, 12);
+INSERT INTO attr_min VALUES (9, 13);
+INSERT INTO attr_min VALUES (9, 14);
+INSERT INTO attr_min VALUES (9, 15);
+INSERT INTO attr_min VALUES (9, 16);
+INSERT INTO attr_min VALUES (9, 17);
+INSERT INTO attr_min VALUES (9, 18);
+INSERT INTO attr_min VALUES (1, 6);
+INSERT INTO attr_min VALUES (1, 7);
+INSERT INTO attr_min VALUES (2, 6);
+INSERT INTO attr_min VALUES (2, 7);
+INSERT INTO attr_min VALUES (3, 7);
+INSERT INTO attr_min VALUES (14, 1);
+
+
diff --git a/sql/journal.sql b/sql/journal.sql
index f5a7ee11b..12320ed1c 100644
--- a/sql/journal.sql
+++ b/sql/journal.sql
@@ -55,7 +55,7 @@ insert into jrn_type values ('OD','Op
insert into jrn_def values (1,'Financier','5* ','5*',null,null,5,5,false,null,'FIN','FIN-01');
insert into jrn_def values (2,'Vente','7*','4*',null,null,1,3,true,'échéance','VEN','VEN-01');
-insert into jrn_def values (3,'Achat','6*','4*',1,3,true,'échéance','ACH','ACH-01');
+insert into jrn_def values (3,'Achat','6*','4*',null,null,1,3,true,'échéance','ACH','ACH-01');
insert into jrn_def values (4,'Opération Diverses',null,null,null,null,5,5,false,null,'OD','OD-01');
create sequence s_jrnx;
@@ -66,8 +66,9 @@ create table jrn (
jr_montant float not null,
jr_comment text ,
jr_date date ,
+ jr_ech date ,
jr_grpt_id integer not null,
- jr_rapt integer,
+ jr_rapt text,
jr_internal text,
jr_tech_date timestamp not null default now(),
jr_tech_per integer not null
diff --git a/sql/jrn_action.sql b/sql/jrn_action.sql
index c1c20894a..ebf5b75cc 100644
--- a/sql/jrn_action.sql
+++ b/sql/jrn_action.sql
@@ -27,18 +27,42 @@ create table jrn_action (
ja_lang text default 'FR',
ja_jrn_type char(3) references jrn_type(jrn_type_id)
);
-insert into jrn_action (ja_name,ja_desc,ja_url,ja_action,ja_jrn_type) VALUES (
- 'Nouvelle','Création d\'une facture','user_jrn.php','action=insert_vente','VEN'
-);
-insert into jrn_action (ja_name,ja_desc,ja_url,ja_action,ja_jrn_type) VALUES (
- 'Voir','Voir toutes les factures','user_jrn.php','action=voir_vente','VEN'
-);
-insert into jrn_action (ja_name,ja_desc,ja_url,ja_action,ja_jrn_type) VALUES (
- 'Voir Impayés','Voir toutes les factures non payées','user_jrn.php','action=voir_vente_non_paye','VEN'
-);
-insert into jrn_action (ja_name,ja_desc,ja_url,ja_action,ja_jrn_type) VALUES (
- 'Impression','Impression du journal','user_jrn.php','action=impress','VEN'
-);
-insert into jrn_action (ja_name,ja_desc,ja_url,ja_action,ja_jrn_type) VALUES (
- 'Recherche','Recherche dans le journal','user_jrn.php','action=search_ven','VEN'
-);
+
+--
+-- PostgreSQL database dump
+--
+
+\connect - phpcompta
+
+SET search_path = public, pg_catalog;
+
+--
+-- Data for TOC entry 1 (OID 17800)
+-- Name: jrn_action; Type: TABLE DATA; Schema: public; Owner: phpcompta
+--
+-- menu vente
+INSERT INTO jrn_action VALUES (2, 'Voir', 'Voir toutes les factures', 'user_jrn.php', 'action=voir_jrn', 'FR', 'VEN');
+INSERT INTO jrn_action VALUES (4, 'Voir Impayés', 'Voir toutes les factures non payées', 'user_jrn.php', 'action=voir_jrn_non_paye', 'FR', 'VEN');
+INSERT INTO jrn_action VALUES (6, 'Recherche', 'Recherche dans le journal', 'user_jrn.php', 'action=search', 'FR', 'VEN');
+INSERT INTO jrn_action VALUES (1, 'Nouvelle', 'Création d''une facture', 'user_jrn.php', 'action=insert_vente&blank', 'FR', 'VEN');
+INSERT INTO jrn_action VALUES (5, 'Impression', 'Impression du journal', 'impress.php', 'filter=1&action=viewpdf&type=jrn', 'FR', 'VEN');
+
+-- menu achat
+INSERT INTO jrn_action VALUES (10, 'Nouveau', 'Encode un nouvel achat (matériel, marchandises, services et biens divers)', 'user_jrn.php', 'action=new&blank', 'FR', 'ACH');
+INSERT INTO jrn_action VALUES (12, 'Voir', 'Voir toutes les factures', 'user_jrn.php', 'action=voir_jrn', 'FR', 'ACH');
+INSERT INTO jrn_action VALUES (14, 'Voir Impayés', 'Voir toutes les factures non payées', 'user_jrn.php', 'action=voir_jrn_non_paye', 'FR', 'ACH');
+INSERT INTO jrn_action VALUES (16, 'Impression', 'Impression du journal', 'impress.php', 'filter=1&action=viewpdf&type=jrn', 'FR', 'ACH');
+INSERT INTO jrn_action VALUES (18, 'Recherche', 'Recherche dans le journal', 'user_jrn.php', 'action=search', 'FR', 'ACH');
+
+-- menu banque
+INSERT INTO jrn_action VALUES (20, 'Nouveau', 'Encode un nouvel achat (matériel, marchandises, services et biens divers)', 'user_jrn.php', 'action=new&blank', 'FR', 'FIN');
+INSERT INTO jrn_action VALUES (22, 'Voir', 'Voir toutes les factures', 'user_jrn.php', 'action=voir_jrn', 'FR', 'FIN');
+INSERT INTO jrn_action VALUES (24, 'Impression', 'Impression du journal', 'impress.php', 'filter=1&action=viewpdf&type=jrn', 'FR', 'FIN');
+INSERT INTO jrn_action VALUES (26, 'Recherche', 'Recherche dans le journal', 'user_jrn.php', 'action=search', 'FR', 'FIN');
+
+-- Menu opérations diverses
+INSERT INTO jrn_action VALUES (30, 'Nouveau', null, 'user_jrn.php', 'action=new&blank', 'FR', 'OD');
+INSERT INTO jrn_action VALUES (32, 'Voir', 'Voir toutes les factures', 'user_jrn.php', 'action=voir_jrn', 'FR', 'OD');
+INSERT INTO jrn_action VALUES (34, 'Impression', 'Impression du journal', 'impress.php', 'filter=1&action=viewpdf&type=jrn', 'FR', 'OD');
+INSERT INTO jrn_action VALUES (36, 'Recherche', 'Recherche dans le journal', 'user_jrn.php', 'action=search', 'FR', 'OD');
+
diff --git a/sql/tva_rate.sql b/sql/tva_rate.sql
new file mode 100644
index 000000000..26a61280d
--- /dev/null
+++ b/sql/tva_rate.sql
@@ -0,0 +1,30 @@
+--
+-- PostgreSQL database dump
+--
+
+SET search_path = public, pg_catalog;
+
+--
+-- TOC entry 2 (OID 51704)
+-- Name: tva_rate; Type: TABLE; Schema: public; Owner: phpcompta
+--
+
+CREATE TABLE tva_rate (
+ tva_id integer NOT NULL,
+ tva_label text NOT NULL,
+ tva_rate double precision DEFAULT 0.0 NOT NULL,
+ tva_comment text,
+ tva_poste text
+);
+
+
+--
+-- Data for TOC entry 3 (OID 51704)
+-- Name: tva_rate; Type: TABLE DATA; Schema: public; Owner: phpcompta
+--
+
+INSERT INTO tva_rate VALUES (1, '21%', 0.21, 'Tva applicable à tout ce qui bien et service divers', '411,451');
+INSERT INTO tva_rate VALUES (3, '0%', 0, 'Tva applicable lors de vente/achat intracommunautaire', '411,451');
+INSERT INTO tva_rate VALUES (2, '6%', 0.06, 'Tva applicable aux journaux et livres', '411,451');
+
+