diff --git a/html/compta.php b/html/compta.php index 9dceef5d0..31f959d16 100644 --- a/html/compta.php +++ b/html/compta.php @@ -28,7 +28,6 @@ if ( isset ( $dos ) ) { echo_debug("admin_dossier = $g_dossier "); } else { echo "You must choose a Dossier "; - // phpinfo(); exit -2; } include_once ("postgres.php"); diff --git a/html/enc_jrn.php b/html/enc_jrn.php index 3c4ee341c..69cd8d353 100644 --- a/html/enc_jrn.php +++ b/html/enc_jrn.php @@ -166,6 +166,10 @@ if ( isset($_POST['add_record']) ) { $Res=StartSql($cn); $seq=GetNextId($cn,'j_grpt')+1; $s_op=GetNextId($cn,'j_id')+1; + + // For the user profile we need the correct sequence id + AlterSequence($cn,'s_jrn_op',$s_op); + $tot_cred=0; $tot_deb=0; @@ -215,6 +219,7 @@ if ( isset($_POST['add_record']) ) { $p_rapt=""; if ( trim($p_rapt) != '' ) { $jrn_id=GetNextJrnId($cn,'jr_id')+1; + if ( ! isset ($p_ech) ) $p_ech=""; $l_date=isDate($p_ech); @@ -225,20 +230,25 @@ if ( isset($_POST['add_record']) ) { } $comment=FormatString($p_comment); $Sql=sprintf("insert into jrn(jr_id,jr_def_id,jr_comment,jr_date,jr_grpt_id, - jr_rapt,jr_montant,jr_tech_per) values(%s,%s,'%s',%s,%d,'%s',%f,%d)", + jr_rapt,jr_montant,jr_tech_per,jr_ech) values(%s,%s,'%s',to_date('%s','DD.MM.YYYY'),%d,'%s',%f,%d,'%s')", $jrn_id, $g_jrn, $comment, - $p_ech, + $p_op_date, $seq, $p_rapt, $tot_deb, - $userPref); + $userPref, + $p_ech); echo_debug($Sql); $Res=ExecSql($cn,$Sql); // $l_dest=GetRaptDest($cn,$p_rapt); if ($Res) - $internal=SetInternalCode($cn,$jrn_id,$g_jrn,$g_dossier); + $internal=SetInternalCode($cn,$seq,$g_jrn); + + // For the user profile we need the correct sequence id + AlterSequence($cn,'s_jrn',$jrn_id); + // TODO multiple rapt should be added $sql=sprintf("update jrn set jr_rapt='%s' where jr_internal='%s'",$internal,$p_rapt); echo_debug("add $sql"); $Res=ExecSql($cn,$sql); @@ -264,7 +274,7 @@ if ( isset($_POST['add_record']) ) { echo_debug("Sql $Sql"); $Res=ExecSql($cn,$Sql); if ($Res) - SetInternalCode($cn,$jrn_id,$g_jrn,$g_dossier); + SetInternalCode($cn,$seq,$g_jrn); } diff --git a/html/impress.php b/html/impress.php index 0f191db80..16796d68f 100644 --- a/html/impress.php +++ b/html/impress.php @@ -31,9 +31,12 @@ include ("check_priv.php"); include_once ("top_menu_compta.php"); ShowMenuCompta($g_dossier,$g_UserProperty); if ( isset ($g_jrn) ) { + echo_debug("g_jrn is set --> come from user_profile"); $p_id=$g_jrn; } else { - if (isset ($_GET["p_id"]) ) $p_id=$_GET["p_id"]; + if (isset ($_GET["p_id"]) ) { + $p_id=$_GET["p_id"]; + } } include_once("impress_inc.php"); @@ -45,7 +48,7 @@ if ( $g_UserProperty['use_admin'] == 0 ) { NoAccess(); } if ( isset ($_GET["type"])) { - if ( $type="jrn") { + if ( $type=="jrn") { $right=CheckJrn($g_dossier,$g_user,$p_id); if ($right == 0 ){ /* Cannot Access */ @@ -58,13 +61,37 @@ if ( $g_UserProperty['use_admin'] == 0 ) { $l_Db=sprintf("dossier%d",$g_dossier); $cn=DbConnect($l_Db); -ShowMenuJrnUserImp($cn,$g_user,$g_dossier); +// if the user has the profile compta show the left menu +if ( $g_UserProperty['use_usertype'] == 'compta') + ShowMenuJrnUserImp($cn,$g_user,$g_dossier); + +// if the user has the profile compta show the left menu +if ( $g_UserProperty['use_usertype'] == 'user') { + // Get the jrn_type_id + include_once('jrn.php'); + $JrnProp=GetJrnProp($g_dossier,$g_jrn); + $jrn_type=$JrnProp['jrn_def_type']; + + // Display available menus + ShowMenuJrnUser($g_dossier,$g_UserProperty,$jrn_type,$g_jrn); + + // display jrn's menu + include_once('user_menu.php'); + $menu_jrn=u_ShowMenuJrn($cn,$jrn_type); + echo '
'; + echo $menu_jrn; + echo '
'; +} // Menu for user's profile // Ask the period if ( isset ( $_GET["action"]) ) { + echo_debug(" action is set "); + $a_print=$HTTP_GET_VARS; + $a_print['p_id']=$p_id; echo '
'; - ViewImp($HTTP_GET_VARS,$cn); + echo '

Choississez la période

'; + ViewImp($a_print,$cn); echo '
'; }//if ( isset ( $_GET["action"] )) diff --git a/html/jrn_op_detail.php b/html/jrn_op_detail.php index 906e2f608..dbdfef3e6 100644 --- a/html/jrn_op_detail.php +++ b/html/jrn_op_detail.php @@ -44,28 +44,30 @@ foreach ($l_array as $key=>$element) { echo_debug("e_$key =$element"); } -echo '
Opération '.$l_array['jr_internal']."
"; +echo '
Opération '.$l_array['jr_internal']."
"; + +echo 'Date : '.$e_op_date; +echo '
'; +echo $e_comment; +echo '
'; - echo 'Date : '.$e_op_date; if ( isset ($e_ech) ) { echo "
Echeance $e_ech
"; } for ( $i = 0; $i < $max_deb;$i++) { $lib=GetPosteLibelle($g_dossier,${"e_class_deb$i"}); - echo '
'; + echo '
'; echo ${"e_class_deb$i"}." $lib "."".${"e_mont_deb$i"}.""; echo "
"; } for ( $i = 0; $i < $max_cred;$i++) { $lib=GetPosteLibelle($g_dossier,${"e_class_cred$i"}); - echo '
'; + echo '
'; echo ${"e_class_cred$i"}." $lib "."".${"e_mont_cred$i"}.""; echo '
'; } -echo "operation concernée $e_rapt"; -echo '
'; -echo $e_comment; -echo '
'; +echo "operation concernée $e_rapt

+"; ?> '; echo ''; 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 @@ +$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 @@ +"; +for ($i=0;$i<$Max;$i++) { + $row=pg_fetch_array($Res,$i); + printf("", + $row['tva_id'], + $row['tva_label'], + $row['tva_comment']); +} +echo '
%d%s%s
'; +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 @@ +'; +echo $left_menu; +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 '
'; echo ''; + $l_sessid=(isset ($_POST["PHPSESSID"]))?$_POST["PHPSESSID"]:$_GET["PHPSESSID"]; + echo JS_SHOW_TVA; echo ""; if ($p_array == null) { // Array is null so we display a blank form @@ -183,10 +185,20 @@ function EncodeFiche($p_cn,$p_type,$p_array=null) { // The number of the attribute $Hid=sprintf('', $i,$l_line['ad_id']); + + $but_search_poste=""; + // Javascript for searching the account + if ( $l_line ['ad_id'] == ATTR_DEF_ACCOUNT ) { + $but_search_poste=''; + } + // Javascript for showing the tva + if ( $l_line ['ad_id'] == ATTR_DEF_TVA ) { + $but_search_poste=''; + } // content of the attribute - printf ('', - $l_line['ad_text'], $i,$Hid); - } + printf ('', + $l_line['ad_text'], $i,$Hid,$but_search_poste); + } echo ''; echo '
%s %s
%s %s %s
'; echo ''; @@ -217,20 +229,33 @@ function EncodeFiche($p_cn,$p_type,$p_array=null) { for ($i=0;$i < $Max;$i++) { // fetch the data $l_line=pg_fetch_array($Res,$i); + // TODO if ad_id = ATTR_DEF_ACCOUNT SHOW BUTTON FOR SHOWING PCMN + // TODO if ad_id = ATTR_DEF_TVA SHOW BUTTON FOR SHOWING PCMN // Put also the class in a special variable // useful when we want to update the PCMN // TODO permit the update of TMP_PCMN + $but_search_poste=""; if ( $l_line['ad_id'] == ATTR_DEF_ACCOUNT ) { printf('', $l_line['av_text']); - + // Javascript for searching the account + + $but_search_poste=''; } + + // Javascript for showing the tva + if ( $l_line ['ad_id'] == ATTR_DEF_TVA ) { + $but_search_poste=''; + } + + + // in hidden we put the jft_id $Hid=sprintf('', $i,$l_line['jft_id']); - printf (' %s %s', - $l_line['ad_text'], $i, $l_line['av_text'],$Hid); + printf (' %s %s %s', + $l_line['ad_text'], $i, $l_line['av_text'],$Hid,$but_search_poste); } 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('
"; 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.=""; + $r.=""; + $r.=""; + $r.=""; + $r.=""; + $r.=""; + $r.=""; + $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.=''; + $r.=''; + $r.=''; + $r.=""; + $r.=''; + $r.=''; + + $r.=''; + + $r.=""; + } + + // end table + $r.='
Articlequantitéprix unit.taux tvaMontant HTVAMontant TVATotal
'.$fiche_name.''.$fiche_quant.''.$fiche_price.' $vat_label '.$fiche_sum.''.$fiche_amount_vat.''.$fiche_with_vat.'
'; + $r.='
'; + $r.="Total HTVA = $sum_march
"; + $r.="Total = $sum_with_vat"; + $r.="
"; + if ( $p_doc == 'html' ) { + $r.='
'; + $r.=$data; + $r.=''; + $r.=''; + $r.='
'; + } +if ( $p_doc == 'pdf' ) { + $r.='
'; + $r.=$data; + $r.=InputType("","HIDDEN","e_comment",$p_comment); + $r.=''; + $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="
"; + + } + $r.=''; + $r.=''.InputType("Date ","Text","e_date",$op_date,$view_only).''; + $r.=''.InputType("Echeance","Text","e_ech",$e_ech,$view_only).''; + include_once("fiche_inc.php"); + // Display the supplier + // TODO ADD BUTTON NEW SUPPLIER + $fiche=GetFicheJrn($p_cn,$p_jrn,'cred'); + + // Save old value and set a new one + $customer=( isset ($e_customer) )?$e_customer:""; + $r.=''.InputType("Fournisseur","SELECT","e_client",$customer,$view_only,$fiche).''; + $r.="
"; + // Record the current number of article + $r.=''; + $e_comment=(isset($e_comment))?$e_comment:""; + + + // Start the div for item to sell + $r.="
"; + $r.='

Articles

'; + $r.=''; + $fiche=GetFicheJrn($p_cn,$p_jrn,'deb'); +echo_debug("Cred Nombre d'enregistrement ".sizeof($fiche)); + for ($i=0;$i< $p_article;$i++) { + + $march=(isset(${"e_march$i"}))?${"e_march$i"}:""; + + $r.=''.InputType("Article","SELECT","e_march".$i,$march,$view_only,$fiche); + $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"0"; + $r.=InputType("Quantité","TEXT","e_quant".$i,$quant,$view_only); + $price=(isset(${"e_price$i"}))?${"e_price$i"}:"0"; + $r.=InputType("Prix","TEXT","e_price".$i,$price,$view_only); + $r.=''; + } + + $r.="
"; + $r.=$p_submit; + $r.="
"; + $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 '
'; echo '
'; @@ -572,6 +572,32 @@ function ViewRecord ($p_dossier,$p_jrn,$p_id,$p_MaxDeb,$p_MaxCred,$p_array) echo ' Ajouter'; 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 '

Paramètres journaux non trouvés

'; + return null; + } + return pg_fetch_array($Res,0); +} /* function GetJrnProp * Purpose : Get the properties of a journal * @@ -600,7 +626,7 @@ function GetJrnProp($p_dossier,$p_jrn) } return pg_fetch_array($Res,0); } -/* function +/* function GetNextId($p_cn,$p_name) * Purpose : * * parm : @@ -621,7 +647,7 @@ function GetNextId($p_cn,$p_name) { $l_res=pg_fetch_array($Res,0); return $l_res['result']; } -/* function +/* function GetNextJrnId($p_cn,$p_name) * Purpose : * * parm : @@ -658,6 +684,7 @@ function GetNextJrnId($p_cn,$p_name) { */ function ViewJrn($p_dossier,$p_user,$p_jrn,$p_array=null) { echo_debug("function ViewJrn($p_dossier,$p_user,$p_jrn,$p_array=null) "); + echo JS_VIEW_JRN_DETAIL; $db=sprintf("dossier%d",$p_dossier); $l_prop=GetJrnProp($p_dossier,$p_jrn); echo "

".$l_prop['jrn_def_name']."( ".$l_prop['jrn_def_code'].")"."

"; @@ -687,13 +714,13 @@ function ViewJrn($p_dossier,$p_user,$p_jrn,$p_array=null) { j_jrn_def=$p_jrn"; $l_and="and "; if ( ereg("^[0-9]+$", $l_s_montant) || ereg ("^[0-9]+\.[0-9]+$", $l_s_montant) ) { - $sql.=" and j_montant $l_mont_sel $l_s_montant"; + $sql.=" and jr_montant $l_mont_sel $l_s_montant"; } if ( isDate($l_date_start) != null ) { - $sql.=$l_and." j_date >='".$l_date_start."'"; + $sql.=$l_and." j_date >= to_date('".$l_date_start."','DD.MM.YYYY')"; } if ( isDate($l_date_end) != null ) { - $sql.=$l_and." j_date <='".$l_date_end."'"; + $sql.=$l_and." j_date <= to_date('".$l_date_end."','DD.MM.YYYY')"; } $l_s_comment=FormatString($l_s_comment); if ( $l_s_comment != null ) { @@ -822,6 +849,7 @@ function GetData ($p_cn,$p_grpt) { j_montant, j_id, jr_comment, + to_char(jr_ech,'DD.MM.YYYY') as jr_ech, to_char(jr_date,'DD.MM.YYYY') as jr_date, jr_rapt, jr_id,jr_internal from jrnx inner join jrn on j_grpt=jr_grpt_id where j_grpt=$p_grpt"); @@ -857,7 +885,7 @@ function GetData ($p_cn,$p_grpt) { } $l_array['jr_internal']=$l_line['jr_internal']; $l_array['comment']=$l_line['jr_comment']; - $l_array['ech']=$l_line['jr_date']; + $l_array['ech']=$l_line['jr_ech']; $l_array['rapt']=$l_line['jr_rapt']; $l_array['jr_id']=$l_line['jr_id']; } @@ -920,15 +948,17 @@ function GetRaptDest($p_cn,$p_rappt) { if ( strlen (trim ($l_line['jr_rapt'])) == 0 ) return -1; return $l_line['jr_rapt']; } -/* function - * Purpose : +/* function GetAmount + * Purpose : return the sum of jrn where + * the internal_code is the p_id * * parm : - * - + * - $p_cn database connection + * - p_id = jrn.jr_internal * gen : * - * return: - * - + * - number * */ function GetAmount($p_cn,$p_id) { @@ -1076,7 +1106,7 @@ function NextJrn($p_cn,$p_type) * * parm : * - $p_cn connection - * - $p_id id in jr_id + * - $p_grpt id in jr_grpt_id * - $p_jrn jrn id jrn_def_id * - $p_dossier dossier id * gen : @@ -1085,14 +1115,14 @@ function NextJrn($p_cn,$p_type) * - * */ -function SetInternalCode($p_cn,$p_id,$p_jrn,$p_dossier) +function SetInternalCode($p_cn,$p_grpt,$p_jrn) { $num=CountSql($p_cn,"select * from jrn where jr_def_id=$p_jrn"); - $atype=GetJrnProp($p_dossier,$p_jrn); + $atype=GetJrnProperty($p_cn,$p_jrn); $type=$atype['jrn_def_code']; - $internal_code=sprintf("%s-%08d",$type,$num); + $internal_code=sprintf("%s-%05d",$type,$num); $Res=ExecSql($p_cn,"update jrn set jr_internal='".$internal_code."' where ". - " jr_id = ".$p_id); + " jr_grpt_id = ".$p_grpt); return $internal_code; } diff --git a/include/preference.php b/include/preference.php index d9216f74b..1103ac757 100644 --- a/include/preference.php +++ b/include/preference.php @@ -39,7 +39,7 @@ function FormPeriodeMult($p_cn) $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 - order by p_start"; + order by p_exercice,p_start"; $Res=ExecSql($p_cn,$sql); $Max=pg_NumRows($Res); $ret=' %s', + "Détail",$row['jr_grpt_id'],$l_sessid,$row['jr_comment']); + $r.=""; + $r.=""; + + +// Amount + $r.=""; + $r.=$row['jr_montant']; + $r.=""; + +// Rapt + $r.=""; + $r.=''; + $r.=$row['jr_rapt']; + $r.=""; + $r.=""; +// TODO Add print + +// end row + $r.=""; + + } +$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='