svn+ssh://danydb@svn/svn/phpcompta/branches/rel430 ........ r2258 | danydb | 2008-12-18 23:21:00 +0100 (Thu, 18 Dec 2008) | 1 line Add debug ........ r2262 | danydb | 2008-12-19 22:38:25 +0100 (Fri, 19 Dec 2008) | 1 line Add a local admin ........ r2270 | danydb | 2008-12-21 20:11:26 +0100 (Sun, 21 Dec 2008) | 1 line Doc. remove the useless todo list ........ r2271 | danydb | 2008-12-22 21:18:46 +0100 (Mon, 22 Dec 2008) | 3 lines Remove obsolete functions insertRapt, deleteRapt and getconcerned Remove obsolete file user_update ........ r2272 | danydb | 2008-12-22 21:21:46 +0100 (Mon, 22 Dec 2008) | 2 lines Remove obsolete function isFicheOfJrn ........ r2273 | danydb | 2008-12-22 21:44:28 +0100 (Mon, 22 Dec 2008) | 1 line Improve Invoice : add the username ........ r2287 | danydb | 2009-01-13 21:37:07 +0100 (Tue, 13 Jan 2009) | 1 line Code cleaning replace GetConcerned by Acc_Reconciliation ........ r2288 | danydb | 2009-01-13 21:38:40 +0100 (Tue, 13 Jan 2009) | 1 line Add a comment on jrn operation ........ r2289 | danydb | 2009-01-13 21:40:13 +0100 (Tue, 13 Jan 2009) | 1 line Code cleaning : add comments to the code ........ r2290 | danydb | 2009-01-13 21:40:46 +0100 (Tue, 13 Jan 2009) | 1 line Code cleaning replace GetConcerned by Acc_Reconciliation ........ r2291 | danydb | 2009-01-13 21:41:35 +0100 (Tue, 13 Jan 2009) | 1 line Code cleaning replace GetConcerned by Acc_Reconciliation ........ r2292 | danydb | 2009-01-13 21:42:15 +0100 (Tue, 13 Jan 2009) | 1 line Add documentation about new tags ........ r2293 | danydb | 2009-01-13 21:43:22 +0100 (Tue, 13 Jan 2009) | 1 line Code cleaning start rewriting of the security part ........ r2294 | danydb | 2009-01-14 20:09:18 +0100 (Wed, 14 Jan 2009) | 1 line Improve : template of security + security code ........ r2295 | danydb | 2009-01-14 20:21:51 +0100 (Wed, 14 Jan 2009) | 1 line Improve security : add new variable ........ r2296 | danydb | 2009-01-14 20:39:58 +0100 (Wed, 14 Jan 2009) | 1 line Improve security : modify layout ........ r2297 | danydb | 2009-01-15 19:21:47 +0100 (Thu, 15 Jan 2009) | 1 line Improve security : user setting ........ r2299 | danydb | 2009-01-15 19:28:56 +0100 (Thu, 15 Jan 2009) | 2 lines Clean code : can_request doens't have a connx parameter ........ r2300 | danydb | 2009-01-16 19:12:47 +0100 (Fri, 16 Jan 2009) | 1 line Improve Ecriture directe libelle : new widget js_search_card_control ........ r2301 | danydb | 2009-01-16 22:29:39 +0100 (Fri, 16 Jan 2009) | 1 line Improve Quick Writing : remove span, and update the comment field ........ r2302 | danydb | 2009-01-16 23:01:24 +0100 (Fri, 16 Jan 2009) | 1 line Improve cosmetic : GL + remove the select topmenu ........ r2303 | danydb | 2009-01-19 08:41:09 +0100 (Mon, 19 Jan 2009) | 1 line Cosmetic : a inline ........ r2304 | danydb | 2009-01-20 23:03:59 +0100 (Tue, 20 Jan 2009) | 6 lines Code Cleaning Security : remove obsolete files & function Class_user : add new functions for the security Only the menu in text mode with a break line ........ r2305 | danydb | 2009-01-20 23:05:01 +0100 (Tue, 20 Jan 2009) | 1 line code cleaning rewriting of Security ........ r2306 | danydb | 2009-01-21 21:13:15 +0100 (Wed, 21 Jan 2009) | 1 line Security printing unicode and fix some bugs ........ r2309 | danydb | 2009-01-26 19:56:28 +0100 (Mon, 26 Jan 2009) | 1 line ADD : company without VAT ........ r2310 | danydb | 2009-01-26 23:33:14 +0100 (Mon, 26 Jan 2009) | 1 line Add : no vat for Purchase ledger ........ r2312 | danydb | 2009-01-28 19:57:30 +0100 (Wed, 28 Jan 2009) | 1 line Integration ........ r2313 | danydb | 2009-01-28 22:46:27 +0100 (Wed, 28 Jan 2009) | 1 line Work with or without VAT ........ r2314 | danydb | 2009-01-29 22:18:57 +0100 (Thu, 29 Jan 2009) | 2 lines Remove debug info ........ r2315 | danydb | 2009-01-29 23:23:14 +0100 (Thu, 29 Jan 2009) | 1 line ADD the possibility to enter a piece number ........ r2316 | danydb | 2009-01-31 23:20:00 +0100 (Sat, 31 Jan 2009) | 1 line Documentation ........ r2317 | danydb | 2009-02-04 20:14:54 +0100 (Wed, 04 Feb 2009) | 1 line Template for ledger ........ r2318 | danydb | 2009-02-05 15:52:58 +0100 (Thu, 05 Feb 2009) | 1 line Add PJ setting + default in Ledger, fix bug in listJrn ........ r2319 | danydb | 2009-02-05 17:09:56 +0100 (Thu, 05 Feb 2009) | 2 lines Search by PJ ........ r2320 | danydb | 2009-02-05 17:23:24 +0100 (Thu, 05 Feb 2009) | 1 line Finished with pj ........ r2321 | danydb | 2009-02-05 18:11:35 +0100 (Thu, 05 Feb 2009) | 1 line PJ is readonly ........ r2322 | danydb | 2009-02-05 20:10:34 +0100 (Thu, 05 Feb 2009) | 1 line Saldo : write the first saldo (ajax) ........ r2324 | danydb | 2009-02-06 00:07:50 +0100 (Fri, 06 Feb 2009) | 5 lines Add database script Cosmetic (menu) Fix Bug ........ r2325 | danydb | 2009-02-06 14:07:07 +0100 (Fri, 06 Feb 2009) | 1 line Improve Pj seq ........ r2326 | danydb | 2009-02-09 22:47:23 +0100 (Mon, 09 Feb 2009) | 6 lines Fix Bug privilege (compta_ven) Fix if the pj is empty do not increment the sequence (class_acc_operation) Fix remove PJ if pj is empty (modify_op.php) Cosmetic do not print PJ if pj is null or empty (listing) ........ r2327 | danydb | 2009-02-10 21:04:48 +0100 (Tue, 10 Feb 2009) | 5 lines Fix bug in PJ seq Fix bug in export jrn csv Improve avoid the removal of vat rate Add security for card ........ r2328 | danydb | 2009-02-12 20:26:36 +0100 (Thu, 12 Feb 2009) | 4 lines Cosmetic menu_tool Impression add tag PJ Cosmetic menu administration ........ r2329 | danydb | 2009-02-12 21:43:19 +0100 (Thu, 12 Feb 2009) | 5 lines filter the folder the local admin can access add a function check_dossier which must be implemented everywhere Printing with PJ NoAccess default = javascript ........ r2330 | danydb | 2009-02-14 18:11:49 +0100 (Sat, 14 Feb 2009) | 2 lines improve add libelle for balance csv ........ r2331 | danydb | 2009-02-14 19:10:56 +0100 (Sat, 14 Feb 2009) | 7 lines Balance csv add label Bug Financial ledger list BUG period access BUG stock access IMPROVE list ledger with PJ ........ r2332 | danydb | 2009-02-15 18:21:59 +0100 (Sun, 15 Feb 2009) | 1 line Bug order was not saved for report ........ r2333 | danydb | 2009-02-15 18:22:17 +0100 (Sun, 15 Feb 2009) | 1 line Add security for normal user ........ r2334 | danydb | 2009-02-15 18:23:24 +0100 (Sun, 15 Feb 2009) | 3 lines Bug forget to import class ........ r2335 | danydb | 2009-02-17 21:33:17 +0100 (Tue, 17 Feb 2009) | 5 lines Fix quick writing let write Fix card priv Remove button if no priv to add card or cancel an op ........ r2336 | danydb | 2009-02-19 21:01:36 +0100 (Thu, 19 Feb 2009) | 4 lines Check for CA common Bug with the repository ........ r2337 | danydb | 2009-02-19 21:50:35 +0100 (Thu, 19 Feb 2009) | 2 lines Test the parameter security part ........
712 lines
22 KiB
PHP
712 lines
22 KiB
PHP
<?php
|
|
/*
|
|
* 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
|
|
*/
|
|
|
|
|
|
/*!\todo remove the function
|
|
- GetTvaRate
|
|
*/
|
|
|
|
|
|
/* $Revision$ */
|
|
|
|
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
|
|
|
|
include_once("postgres.php");
|
|
require_once("class_document.php");
|
|
require_once("class_acc_operation.php");
|
|
/*! \file
|
|
* \brief Common functions
|
|
*/
|
|
/*!
|
|
**************************************************
|
|
*\brief Return the rate of the p_tva_id
|
|
*
|
|
*
|
|
* \param $p_cn database connection
|
|
* \param $p_tva_id tva.tva_id
|
|
*
|
|
* \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) {
|
|
// $p_tva_id is an empty string, returns 0
|
|
if (strlen(trim($p_tva_id))==0) return 0;
|
|
|
|
// Get vat info from the database
|
|
$Res=ExecSql($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;
|
|
|
|
}
|
|
|
|
/*!
|
|
*\brief show all the lines of the asked jrn, uses also the $_GET['o'] for the sort
|
|
*
|
|
*
|
|
* \param $p_cn database connection
|
|
* \param $p_jrn jrn_id jrn.jrn_def_id
|
|
* \param $p_where the sql query where clause
|
|
* \param $p_array param. for a search
|
|
* \param $p_value offset
|
|
* \param $p_paid value : 0 nothing is shown, 1 check box; 2 check_box disable
|
|
* \return array (entryCount,generatedHTML);
|
|
*
|
|
*/
|
|
function ListJrn($p_cn,$p_jrn,$p_where="",$p_array=null,$p_value=0,$p_paid=0)
|
|
{
|
|
$user=new User($p_cn);
|
|
// print_r("function ListJrn($p_cn,$p_jrn,$p_where='',$p_array=null,$p_value=0,$p_paid=0)");
|
|
echo_debug(__FILE__,__LINE__,"Entering into function ListJrn($p_cn,$p_jrn,$p_where='',$p_array=null,$p_value=0,$p_paid=0)");
|
|
$gDossier=dossier::id();
|
|
$amount_paid=0.0;
|
|
$amount_unpaid=0.0;
|
|
include_once("central_inc.php");
|
|
$limit=($_SESSION['g_pagesize']!=-1)?" LIMIT ".$_SESSION['g_pagesize']:"";
|
|
$offset=($_SESSION['g_pagesize']!=-1)?" OFFSET ".pg_escape_string($p_value):"";
|
|
$order=" order by jr_date_order asc,jr_internal asc";
|
|
// Sort
|
|
$url=CleanUrl();
|
|
$str_dossier=dossier::get();
|
|
$image_asc='<IMAGE SRC="image/down.png" border="0" >';
|
|
$image_desc='<IMAGE SRC="image/up.png" border="0">';
|
|
$image_sel_desc='<IMAGE SRC="image/select1.png">';
|
|
$image_sel_asc='<IMAGE SRC="image/select2.png">';
|
|
|
|
$sort_date="<th> <A class=\"mtitle\" HREF=\"?$url&o=da\">$image_asc</A>Date <A class=\"mtitle\" HREF=\"?$url&o=dd\">$image_desc</A></th>";
|
|
$sort_description="<th> <A class=\"mtitle\" HREF=\"?$url&o=ca\">$image_asc</A>Description <A class=\"mtitle\" HREF=\"?$url&o=cd\">$image_desc</A></th>";
|
|
$sort_amount="<th> <A class=\"mtitle\" HREF=\"?$url&o=ma\">$image_asc</A>Montant <A class=\"mtitle\" HREF=\"?$url&o=md\">$image_desc</A></th>";
|
|
$sort_echeance="<th> <A class=\"mtitle\" HREF=\"?$url&o=ea\">$image_asc</A>Echéance <A class=\"mtitle\" HREF=\"?$url&o=ed\">$image_desc</A> </th>";
|
|
|
|
$own=new Own($p_cn);
|
|
// if an order is asked
|
|
if ( isset ($_GET['o']) )
|
|
{
|
|
switch ($_GET['o'])
|
|
{
|
|
case 'da':
|
|
// date asc
|
|
$sort_date="<th>$image_sel_asc Date <A class=\"mtitle\" HREF=\"?$url&o=dd\">$image_desc</A></th>";
|
|
$order=" order by jr_date_order asc ";
|
|
break;
|
|
case 'dd':
|
|
$sort_date="<th> <A class=\"mtitle\" HREF=\"?$url&o=da\">$image_asc</A> Date $image_sel_desc</th>";
|
|
// date desc
|
|
$order=" order by jr_date_order desc ";
|
|
break;
|
|
case 'ma':
|
|
// montant asc
|
|
$sort_amount="<th> $image_sel_asc Montant <A class=\"mtitle\" HREF=\"?$url&o=md\">$image_desc</A></th>";
|
|
$order=" order by jr_montant asc ";
|
|
break;
|
|
case 'md':
|
|
// montant desc
|
|
$sort_amount="<th> <A class=\"mtitle\" HREF=\"?$url&o=ma\">$image_asc</A>Montant $image_sel_desc</th>";
|
|
$order=" order by jr_montant desc ";
|
|
break;
|
|
case 'ca':
|
|
// jr_comment asc
|
|
$sort_description="<th> $image_sel_asc Description <A class=\"mtitle\" HREF=\"?$url&o=cd\">$image_desc</A></th>";
|
|
$order=" order by jr_comment asc ";
|
|
break;
|
|
case 'cd':
|
|
// jr_comment desc
|
|
$sort_description="<th> <A class=\"mtitle\" HREF=\"?$url&o=ca\">$image_asc</A>Description $image_sel_desc</th>";
|
|
$order=" order by jr_comment desc ";
|
|
break;
|
|
case 'ea':
|
|
// jr_comment asc
|
|
$sort_echeance="<th> $image_sel_asc Echeance <A class=\"mtitle\" HREF=\"?$url&o=ed\">$image_desc</A></th>";
|
|
$order=" order by jr_ech asc ";
|
|
break;
|
|
case 'ed':
|
|
// jr_comment desc
|
|
$sort_echeance="<th> <A class=\"mtitle\" HREF=\"?$url&o=ea\">$image_asc</A> Echeance $image_sel_desc</th>";
|
|
$order=" order by jr_ech desc ";
|
|
break;
|
|
|
|
}
|
|
}
|
|
// set a filter for the FIN
|
|
$a_parm_code=get_array($p_cn,"select p_value from parm_code where p_code in ('BANQUE','COMPTE_COURANT','CAISSE')");
|
|
$sql_fin="(";
|
|
$or="";
|
|
foreach ($a_parm_code as $code) {
|
|
$sql_fin.="$or j_poste::text like '".$code['p_value']."%'";
|
|
$or=" or ";
|
|
}
|
|
$sql_fin.=")";
|
|
|
|
if ( $p_array == null ) {
|
|
$sql="select jr_id ,
|
|
jr_montant,
|
|
case when jr_pj_number is not null and jr_pj_number !=''
|
|
then '('||jr_pj_number||')'
|
|
else '' end ||' '||jr_comment as jr_comment,
|
|
to_char(jr_ech,'DD.MM.YYYY') as jr_ech,
|
|
to_char(jr_date,'DD.MM.YYYY') as jr_date,
|
|
jr_date as jr_date_order,
|
|
jr_grpt_id,
|
|
jr_rapt,
|
|
jr_internal,
|
|
jrn_def_id,
|
|
jrn_def_name,
|
|
jrn_def_ech,
|
|
jrn_def_type,
|
|
jr_valid,
|
|
jr_tech_per,
|
|
jr_pj_name,
|
|
p_closed
|
|
from
|
|
jrn
|
|
join jrn_def on jrn_def_id=jr_def_id
|
|
join parm_periode on p_id=jr_tech_per
|
|
$p_where
|
|
$order";
|
|
}
|
|
if ( $p_array != null ) {
|
|
// Construction Query
|
|
foreach ( $p_array as $key=>$element) {
|
|
${"l_$key"}=$element;
|
|
}
|
|
$sql="select jr_id ,
|
|
jr_montant,
|
|
case when jr_pj_number is not null and jr_pj_number !=''
|
|
then '('||jr_pj_number||')'
|
|
else '' end ||' '||jr_comment as jr_comment,
|
|
jr_ech,
|
|
to_char(jr_date,'DD.MM.YYYY') as jr_date,
|
|
jr_date as jr_date_order,
|
|
jr_grpt_id,
|
|
jr_rapt,
|
|
jr_internal,
|
|
jrn_def_id,
|
|
jrn_def_name,
|
|
jrn_def_ech,
|
|
jrn_def_type,
|
|
jr_valid,
|
|
jr_tech_per,
|
|
jr_pj_name,
|
|
p_closed
|
|
from
|
|
jrn join jrn_def on jrn_def_id=jr_def_id
|
|
join parm_periode on p_id=jr_tech_per
|
|
";
|
|
$jrn_sql=($p_jrn =0)?"1=1":"jrn_def_id=$p_jrn ";
|
|
$l_and=" where ";
|
|
// amount
|
|
// remove space
|
|
$l_s_montant=trim($l_s_montant);
|
|
// replace comma by dot
|
|
$l_s_montant=str_replace(',','.',$l_s_montant);
|
|
$l_st_montant=trim($l_st_montant);
|
|
// replace comma by dot
|
|
$l_st_montant=str_replace(',','.',$l_st_montant);
|
|
$done_comp=0;
|
|
echo_debug('user_common',__LINE__,"l_s_montant $l_s_montant");
|
|
/* -------------------------------------------------------------------------- */
|
|
/* if both amount are the same then we need to search into the detail
|
|
*/
|
|
/* -------------------------------------------------------------------------- */
|
|
if ( ( ereg("^[0-9]+$", $l_s_montant) || ereg ("^[0-9]+\.[0-9]+$", $l_s_montant)) &&
|
|
( ereg("^[0-9]+$", $l_st_montant) || ereg ("^[0-9]+\.[0-9]+$", $l_st_montant) )
|
|
)
|
|
{
|
|
if ( bccomp($l_s_montant,$l_st_montant,2) == 0 ) {
|
|
$sql .= $l_and. 'jr_grpt_id in ( select distinct j_grpt from jrnx where j_montant = '.$l_s_montant.')';
|
|
$l_and=" and ";
|
|
$done_comp=1;
|
|
|
|
}
|
|
|
|
}
|
|
/*------------------------------------------------------------------------------*
|
|
* If amount are different the range is about the total of the operation
|
|
*------------------------------------------------------------------------------*/
|
|
if ( $done_comp==0 && (ereg("^[0-9]+$", $l_s_montant) || ereg ("^[0-9]+\.[0-9]+$", $l_s_montant) ))
|
|
{
|
|
$sql.=$l_and." jr_montant >= $l_s_montant";
|
|
$l_and=" and ";
|
|
}
|
|
if ( $done_comp==0 && (ereg("^[0-9]+$", $l_st_montant) || ereg ("^[0-9]+\.[0-9]+$", $l_st_montant) ))
|
|
{
|
|
$sql.=$l_and." jr_montant <= $l_st_montant";
|
|
$l_and=" and ";
|
|
}
|
|
|
|
// date
|
|
if ( isDate($l_date_start) != null )
|
|
{
|
|
$sql.=$l_and." jr_date >= to_date('".$l_date_start."','DD.MM.YYYY')";
|
|
$l_and=" and ";
|
|
}
|
|
if ( isDate($l_date_end) != null ) {
|
|
$sql.=$l_and." jr_date <= to_date('".$l_date_end."','DD.MM.YYYY')";
|
|
$l_and=" and ";
|
|
}
|
|
// comment
|
|
$l_s_comment=FormatString($l_s_comment);
|
|
if ( $l_s_comment != null )
|
|
{
|
|
$sql.=$l_and." ( upper(jr_comment) like upper('%".$l_s_comment."%') or upper(jr_pj_number) like upper('%".$l_s_comment."%') )";
|
|
$l_and=" and ";
|
|
}
|
|
// internal
|
|
$l_s_internal=FormatString($l_s_internal);
|
|
if ( $l_s_internal != null ) {
|
|
$sql.=$l_and." jr_internal like upper('%$l_s_internal%') ";
|
|
$l_and=" and ";
|
|
}
|
|
// Poste
|
|
$l_poste=FormatString($l_poste);
|
|
if ( $l_poste != null ) {
|
|
$sql.=$l_and." jr_grpt_id in (select j_grpt
|
|
from jrnx where j_poste::text like '$l_poste' ) ";
|
|
$l_and=" and ";
|
|
}
|
|
// Quick Code
|
|
if ( $l_qcode != null )
|
|
{
|
|
$l_qcode=FormatString($l_qcode);
|
|
$sql.=$l_and." jr_grpt_id in ( select j_grpt from
|
|
jrnx where trim(j_qcode) = upper(trim('$l_qcode')))";
|
|
$l_and=" and ";
|
|
}
|
|
// if not admin check filter
|
|
$User=new User(DbConnect());
|
|
$User->Check();
|
|
$User->check_dossier(dossier::id());
|
|
|
|
if ( $User->admin == 0 && $User->is_local_admin()==0 )
|
|
{
|
|
$sql.=$l_and." jr_def_id in ( select uj_jrn_id ".
|
|
" from user_sec_jrn where ".
|
|
" uj_login='".$_SESSION['g_user']."'".
|
|
" and uj_priv in ('R','W'))";
|
|
}
|
|
$sql.=$order;
|
|
}// p_array != null
|
|
// Count
|
|
$count=CountSql($p_cn,$sql);
|
|
// Add the limit
|
|
$sql.=$limit.$offset;
|
|
|
|
// Execute SQL stmt
|
|
$Res=ExecSql($p_cn,$sql);
|
|
|
|
//starting from here we can refactor, so that instead of returning the generated HTML,
|
|
//this function returns a tree structure.
|
|
|
|
$r="";
|
|
|
|
$r.=JS_VIEW_JRN_CANCEL;
|
|
$r.=JS_VIEW_JRN_MODIFY;
|
|
|
|
$Max=pg_NumRows($Res);
|
|
|
|
//TODO: correct this message.
|
|
if ($Max==0) return array(0,"Aucun enregistrement trouvé");
|
|
|
|
$r.='<table style="width:100%;border:solid blue 2px ;border-style:outset;">';
|
|
$l_sessid=$_REQUEST['PHPSESSID'];
|
|
|
|
$r.="<tr class=\"even\">";
|
|
$r.="<th> Internal</th>";
|
|
$r.=$sort_date;
|
|
$r.=$sort_echeance;
|
|
$r.=$sort_description;
|
|
$r.=$sort_amount;
|
|
// if $p_paid is not equal to 0 then we have a paid column
|
|
if ( $p_paid != 0 )
|
|
{
|
|
$r.="<th> Payé</th>";
|
|
}
|
|
$r.="<th>Op. Concernée</th>";
|
|
$r.="<th>Document</th>";
|
|
$r.="</tr>";
|
|
// Total Amount
|
|
$tot=0.0;
|
|
$gDossier=dossier::id();
|
|
for ($i=0; $i < $Max;$i++) {
|
|
|
|
|
|
$row=pg_fetch_array($Res,$i);
|
|
|
|
if ( $i % 2 == 0 ) $tr='<TR class="odd">';
|
|
else $tr='<TR class="even">';
|
|
$r.=$tr;
|
|
//internal code
|
|
// button modify
|
|
$r.="<TD>";
|
|
// If url contains
|
|
//
|
|
|
|
$href=basename($_SERVER['PHP_SELF']);
|
|
echo_debug(__FILE__,__LINE__,"href = $href");
|
|
switch ($href)
|
|
{
|
|
// user_jrn.php
|
|
case 'compta.php':
|
|
$vue="E"; //Expert View
|
|
break;
|
|
case 'commercial.php':
|
|
$vue="S"; //Simple View
|
|
break;
|
|
case 'recherche.php':
|
|
$vue=(isset($_GET['expert']))?'E':'S';
|
|
break;
|
|
default:
|
|
echo_error('user_form_ach.php',__LINE__,'Erreur invalid request uri');
|
|
exit (-1);
|
|
}
|
|
//DEBUG
|
|
// $r.=$l_sessid;
|
|
$r.=sprintf('<A class="detail" HREF="javascript:modifyOperation(\'%s\',\'%s\',\'%s\',\'%s\',\'%s\')" >%s</A>',
|
|
$row['jr_id'], $l_sessid,$gDossier, $p_jrn,$vue, $row['jr_internal']);
|
|
$r.="</TD>";
|
|
// date
|
|
$r.="<TD>";
|
|
$r.=$row['jr_date'];
|
|
$r.="</TD>";
|
|
// echeance
|
|
$r.="<TD>";
|
|
$r.=$row['jr_ech'];
|
|
$r.="</TD>";
|
|
|
|
// comment
|
|
$r.="<TD>";
|
|
$r.=h($row['jr_comment']);
|
|
$r.="</TD>";
|
|
|
|
// Amount
|
|
// If the ledger is financial :
|
|
// the credit must be negative and written in red
|
|
$positive=0;
|
|
|
|
// Check ledger type :
|
|
if ( $row['jrn_def_type'] == 'FIN' )
|
|
{
|
|
$positive = CountSql($p_cn,"select * from jrn inner join jrnx on jr_grpt_id=j_grpt ".
|
|
" where jr_id=".$row['jr_id']." and $sql_fin ".
|
|
" and j_debit='f'");
|
|
}
|
|
$r.="<TD align=\"right\">";
|
|
|
|
$tot=($positive != 0)?$tot-$row['jr_montant']:$tot+$row['jr_montant'];
|
|
//STAN $positive always == 0
|
|
$r.=( $positive != 0 )?"<font color=\"red\"> - ".sprintf("%8.2f",$row['jr_montant'])."</font>":sprintf("%8.2f",$row['jr_montant']);
|
|
$r.="</TD>";
|
|
|
|
|
|
// Show the paid column if p_paid is not null
|
|
if ( $p_paid !=0 )
|
|
{
|
|
$w=new widget("checkbox");
|
|
$w->name="rd_paid".$row['jr_id'];
|
|
$w->selected=($row['jr_rapt']=='paid')?true:false;
|
|
// if p_paid == 2 then readonly
|
|
$w->readonly=( $p_paid == 2)?true:false;
|
|
$h=new widget("hidden");
|
|
$h->name="set_jr_id".$row['jr_id'];
|
|
$r.='<TD>'.$w->IOValue().$h->IOValue().'</TD>';
|
|
if ( $row['jr_rapt']=='paid')
|
|
$amount_paid+=$row['jr_montant'];
|
|
else
|
|
$amount_unpaid+=$row['jr_montant'];
|
|
}
|
|
|
|
// Rapprochement
|
|
$rec=new Acc_Reconciliation($p_cn);
|
|
$rec->set_jr_id($row['jr_id']);
|
|
$a=$rec->get();
|
|
$r.="<TD>";
|
|
if ( $a != null ) {
|
|
|
|
foreach ($a as $key => $element)
|
|
{
|
|
$operation=new Acc_Operation($p_cn);
|
|
$operation->jr_id=$element;
|
|
$l_amount=getDbValue($p_cn,"select jr_montant from jrn ".
|
|
" where jr_id=$element");
|
|
$r.= "<A class=\"detail\" HREF=\"javascript:modifyOperation('".$element."','".$l_sessid."',".$gDossier.")\" > ".$operation->get_internal()." [ $l_amount € ]</A>";
|
|
}//for
|
|
}// if ( $a != null ) {
|
|
$r.="</TD>";
|
|
|
|
if ( $row['jr_valid'] == 'f' ) {
|
|
$r.="<TD> Opération annulée</TD>";
|
|
} else if ( $own->MY_STRICT=='N' ) {
|
|
// all operations can be removed either by setting to 0 the amount
|
|
// or by writing the opposite operation if the period is closed
|
|
$r.="<TD>";
|
|
// cancel operation
|
|
if ( $user->check_action(GEOP)==1)
|
|
$r.=sprintf('<input TYPE="BUTTON" VALUE="%s" onClick="cancelOperation(\'%s\',\'%s\',%d,\'%s\')">',
|
|
"Annuler",$row['jr_grpt_id'],$l_sessid,$gDossier,$p_jrn);
|
|
$r.="</TD>";
|
|
} // else
|
|
//document
|
|
if ( $row['jr_pj_name'] != "")
|
|
{
|
|
$image='<IMG SRC="image/insert_table.gif" title="'.$row['jr_pj_name'].'" border="0">';
|
|
$r.="<TD>".sprintf('<A class="detail" HREF="show_pj.php?jrn=%s&jr_grpt_id=%s&%s&PHPSESSID=%s">%s</A>',
|
|
$p_jrn,
|
|
$row['jr_grpt_id'],
|
|
$str_dossier,
|
|
$_REQUEST['PHPSESSID'],
|
|
$image)
|
|
."</TD>";
|
|
}
|
|
else
|
|
$r.="<TD></TD>";
|
|
|
|
// end row
|
|
$r.="</tr>";
|
|
|
|
}
|
|
$amount_paid=round($amount_paid,4);
|
|
$amount_unpaid=round($amount_unpaid,4);
|
|
$tot=round($tot,4);
|
|
$r.="<TR>";
|
|
$r.='<TD COLSPAN="4">Total</TD>';
|
|
$r.='<TD ALIGN="RIGHT">'.$tot."</TD>";
|
|
$r.="</tr>";
|
|
if ( $p_paid != 0 ) {
|
|
$r.="<TR>";
|
|
$r.='<TD COLSPAN="4">Payé</TD>';
|
|
$r.='<TD ALIGN="RIGHT">'.$amount_paid."</TD>";
|
|
$r.="</tr>";
|
|
$r.="<TR>";
|
|
$r.='<TD COLSPAN="4">Non payé</TD>';
|
|
$r.='<TD ALIGN="RIGHT">'.$amount_unpaid."</TD>";
|
|
$r.="</tr>";
|
|
}
|
|
$r.="</table>";
|
|
|
|
return array ($count,$r);
|
|
}
|
|
|
|
|
|
|
|
/*! InsertStockGoods($p_cn,$j_id,$a_good[$i],$a_quant[$i],'c');
|
|
**************************************************
|
|
*\brief Insert data into stock_goods,
|
|
*
|
|
* \param $p_cn database connection
|
|
*
|
|
* \param $p_j_id the j_id
|
|
* \param $p_good the goods
|
|
* \param $p_quant quantity
|
|
* \param $p_type c for credit or d for debit
|
|
*
|
|
* \return none
|
|
* \note Link to jrn gives the date
|
|
*/
|
|
function InsertStockGoods($p_cn,$p_j_id,$p_good,$p_quant,$p_type)
|
|
{
|
|
echo_debug('user_common.php',__LINE__,"function InsertStockGoods($p_cn,$p_j_id,$p_good,$p_quant,$p_type)");
|
|
// Retrieve the good account for stock
|
|
$code=new fiche($p_cn);
|
|
$code->get_by_qcode($p_good);
|
|
$code_marchandise=$code->strAttribut(ATTR_DEF_STOCK);
|
|
$p_good=FormatString($p_good);
|
|
$sql="select f_id from vw_poste_qcode where j_qcode=upper('$p_good')";
|
|
$Res=ExecSql($p_cn,$sql);
|
|
$r=pg_fetch_array($Res,0);
|
|
$f_id=$r['f_id'];
|
|
$user=new User($p_cn);
|
|
$exercice=$user->get_exercice();
|
|
if ( $exercice == 0 ) throw Exception ('Annee invalide erreur');
|
|
|
|
|
|
$Res=ExecSql($p_cn,"insert into stock_goods (
|
|
j_id,
|
|
f_id,
|
|
sg_code,
|
|
sg_quantity,
|
|
sg_type,sg_exercice ) values (
|
|
$p_j_id,
|
|
$f_id,
|
|
'$code_marchandise',
|
|
$p_quant, '$p_type',$exercice)
|
|
");
|
|
return $Res;
|
|
}
|
|
|
|
|
|
/*! isValid ($p_cn, $p_grpt_id
|
|
**************************************************
|
|
*\brief test if a jrn op is valid
|
|
*
|
|
* \param $p_cn db
|
|
* \param $p_grpt_id
|
|
* \return:
|
|
* - 1 is valid
|
|
* - 0 is not valid
|
|
*/
|
|
function isValid ($p_cn,$p_grpt_id) {
|
|
$Res=ExecSql($p_cn,"select jr_valid from jrn where jr_grpt_id=$p_grpt_id");
|
|
|
|
if ( ( $M = pg_NumRows($Res)) == 0 ) return 0;
|
|
|
|
$a=pg_fetch_array($Res,0);
|
|
|
|
if ( $a['jr_valid'] == 't') return 1;
|
|
if ( $a['jr_valid'] == 'f') return 0;
|
|
|
|
echo_error ("Invalid result = ".$a['result']);
|
|
|
|
|
|
}
|
|
|
|
/*!
|
|
**************************************************
|
|
*\brief
|
|
* Create a navigation_bar (pagesize)
|
|
*
|
|
* \param $p_offset first record number
|
|
* \param $p_line total of returned row
|
|
* \param $p_size current g_pagesize user's preference
|
|
* \param $p_page number of the page where the user is
|
|
* \param $p_javascript javascript code to add
|
|
* \note example :
|
|
\verbatim
|
|
$step=$_SESSION['g_pagesize'];
|
|
$page=(isset($_GET['offset']))?$_GET['page']:1;
|
|
$offset=(isset($_GET['offset']))?$_GET['offset']:0;
|
|
|
|
list ($max_ligne,$list)=ListJrn($cn,$_GET['p_jrn'],$sql,null,$offset,1);
|
|
$bar=jrn_navigation_bar($offset,$max_ligne,$step,$page);
|
|
\endverbatim
|
|
* \return string with the nav. bar
|
|
*/
|
|
function jrn_navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1,$p_javascript="")
|
|
{
|
|
echo_debug('user_common',__LINE__,"function jrn_navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1)");
|
|
// if the pagesize is unlimited return ""
|
|
// in that case there is no nav. bar
|
|
if ( $_SESSION['g_pagesize'] == -1 ) return "";
|
|
if ( $p_size==0) {
|
|
$p_size= $_SESSION['g_pagesize'];
|
|
}
|
|
// if there is no row return an empty string
|
|
if ( $p_line == 0 ) return "";
|
|
|
|
// Clean url, cut away variable coming frm here
|
|
$url=cleanUrl();
|
|
// action to clean
|
|
$url=str_replace('&p_action=delete','',$url);
|
|
|
|
// compute max of page
|
|
$nb_page=($p_line-($p_line%$p_size))/$p_size;
|
|
echo_debug('user_common',__LINE__,"nb_page = $nb_page");
|
|
// if something remains
|
|
if ( $p_line % $p_size != 0 ) $nb_page+=1;
|
|
|
|
// if max page == 1 then return a empty string
|
|
if ( $nb_page == 1) return "";
|
|
|
|
// restore the sort
|
|
if ( isset($_GET['o']))
|
|
$url=$url.'&o='.$_GET['o'];
|
|
|
|
$r="";
|
|
// previous
|
|
if ($p_page !=1) {
|
|
$e=$p_page-1;
|
|
$step=$p_size;
|
|
$offset=($e-1)*$step;
|
|
|
|
$r='<A class="mtitle" href="'.$_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step".'" '.$p_javascript.'>';
|
|
//$r.="Précédent";
|
|
$r.='<INPUT TYPE="IMAGE" width="12" SRC="image/go-previous.png">';
|
|
$r.="</A> ";
|
|
}
|
|
//----------------------------------------------------------------------
|
|
// Create a partial bar
|
|
// if current page < 11 show 1 to 20
|
|
// otherwise show $p_page -10 to $p_page + 10
|
|
//----------------------------------------------------------------------
|
|
$start_bar=($p_page < 11 )?1:$p_page-10;
|
|
$end_bar =($p_page < 11 )?20:$p_page+10;
|
|
$end_bar =($end_bar > $nb_page )?$nb_page:$end_bar;
|
|
|
|
// Create the bar
|
|
for ($e=$start_bar;$e<=$end_bar;$e++) {
|
|
// do not included current page
|
|
if ( $e != $p_page ) {
|
|
$step=$p_size;
|
|
$offset=($e-1)*$step;
|
|
|
|
$go=$_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step";
|
|
|
|
$r.=sprintf('<A class="mtitle" HREF="%s" CLASS="one" %s >%d</A> ',$go,$p_javascript,$e);
|
|
} else {
|
|
$r.="<b> [ $e ] </b>";
|
|
} //else
|
|
} //for
|
|
// next
|
|
|
|
if ($p_page !=$nb_page) {
|
|
// If we are not at the last page show the button next
|
|
$e=$p_page+1;
|
|
$step=$p_size;
|
|
$offset=($e-1)*$step;
|
|
|
|
$r.=' <A class="mtitle" href="'.$_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step".'" '.$p_javascript.' >';
|
|
//$r.="Suivant";
|
|
$r.='<INPUT TYPE="IMAGE" width="12" SRC="image/go-next.png">';
|
|
$r.="</A>";
|
|
}
|
|
|
|
|
|
return $r;
|
|
}
|
|
|
|
/*!
|
|
* \brief Clean the url, remove the $_GET offset,step, page and size
|
|
* \param none
|
|
*
|
|
* \return the cleaned url
|
|
*/
|
|
|
|
function CleanUrl()
|
|
{
|
|
// Compute the url
|
|
$url="";
|
|
$and="";
|
|
$get=$_GET;
|
|
if ( isset ($get) ) {
|
|
foreach ($get as $name=>$value ) {
|
|
// we clean the parameter offset, step, page and size
|
|
if ( ! in_array($name,array('offset','step','page','size','s','o'))) {
|
|
$url.=$and.$name."=".$value;
|
|
$and="&";
|
|
}// if
|
|
}//foreach
|
|
}// if
|
|
return $url;
|
|
}
|
|
function get_redirect($p_string) {
|
|
echo '<HTML><head><META HTTP-EQUIV="REFRESH" content="0;url='.$p_string.'"></head><body> Connecting... </body></html>';
|
|
}
|
|
?>
|